Commit 2fe28ab51d200121b9c39f9b34cf2d132fcf5de1
Committed by
Jean Delvare
1 parent
d216f6809e
Exists in
master
and in
6 other branches
hwmon: (lm63) Support extended lookup table of LM96163
The LM96163 has an extended lookup table with 12 entries instead of 8, add support for that. Signed-off-by: Jean Delvare <khali@linux-fr.org> Tested-by: Guenter Roeck <guenter.roeck@ericsson.com> Acked-by: Guenter Roeck <guenter.roeck@ericsson.com>
Showing 1 changed file with 62 additions and 7 deletions Inline Diff
drivers/hwmon/lm63.c
1 | /* | 1 | /* |
2 | * lm63.c - driver for the National Semiconductor LM63 temperature sensor | 2 | * lm63.c - driver for the National Semiconductor LM63 temperature sensor |
3 | * with integrated fan control | 3 | * with integrated fan control |
4 | * Copyright (C) 2004-2008 Jean Delvare <khali@linux-fr.org> | 4 | * Copyright (C) 2004-2008 Jean Delvare <khali@linux-fr.org> |
5 | * Based on the lm90 driver. | 5 | * Based on the lm90 driver. |
6 | * | 6 | * |
7 | * The LM63 is a sensor chip made by National Semiconductor. It measures | 7 | * The LM63 is a sensor chip made by National Semiconductor. It measures |
8 | * two temperatures (its own and one external one) and the speed of one | 8 | * two temperatures (its own and one external one) and the speed of one |
9 | * fan, those speed it can additionally control. Complete datasheet can be | 9 | * fan, those speed it can additionally control. Complete datasheet can be |
10 | * obtained from National's website at: | 10 | * obtained from National's website at: |
11 | * http://www.national.com/pf/LM/LM63.html | 11 | * http://www.national.com/pf/LM/LM63.html |
12 | * | 12 | * |
13 | * The LM63 is basically an LM86 with fan speed monitoring and control | 13 | * The LM63 is basically an LM86 with fan speed monitoring and control |
14 | * capabilities added. It misses some of the LM86 features though: | 14 | * capabilities added. It misses some of the LM86 features though: |
15 | * - No low limit for local temperature. | 15 | * - No low limit for local temperature. |
16 | * - No critical limit for local temperature. | 16 | * - No critical limit for local temperature. |
17 | * - Critical limit for remote temperature can be changed only once. We | 17 | * - Critical limit for remote temperature can be changed only once. We |
18 | * will consider that the critical limit is read-only. | 18 | * will consider that the critical limit is read-only. |
19 | * | 19 | * |
20 | * The datasheet isn't very clear about what the tachometer reading is. | 20 | * The datasheet isn't very clear about what the tachometer reading is. |
21 | * I had a explanation from National Semiconductor though. The two lower | 21 | * I had a explanation from National Semiconductor though. The two lower |
22 | * bits of the read value have to be masked out. The value is still 16 bit | 22 | * bits of the read value have to be masked out. The value is still 16 bit |
23 | * in width. | 23 | * in width. |
24 | * | 24 | * |
25 | * This program is free software; you can redistribute it and/or modify | 25 | * This program is free software; you can redistribute it and/or modify |
26 | * it under the terms of the GNU General Public License as published by | 26 | * it under the terms of the GNU General Public License as published by |
27 | * the Free Software Foundation; either version 2 of the License, or | 27 | * the Free Software Foundation; either version 2 of the License, or |
28 | * (at your option) any later version. | 28 | * (at your option) any later version. |
29 | * | 29 | * |
30 | * This program is distributed in the hope that it will be useful, | 30 | * This program is distributed in the hope that it will be useful, |
31 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 31 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
32 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 32 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
33 | * GNU General Public License for more details. | 33 | * GNU General Public License for more details. |
34 | * | 34 | * |
35 | * You should have received a copy of the GNU General Public License | 35 | * You should have received a copy of the GNU General Public License |
36 | * along with this program; if not, write to the Free Software | 36 | * along with this program; if not, write to the Free Software |
37 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 37 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
38 | */ | 38 | */ |
39 | 39 | ||
40 | #include <linux/module.h> | 40 | #include <linux/module.h> |
41 | #include <linux/init.h> | 41 | #include <linux/init.h> |
42 | #include <linux/slab.h> | 42 | #include <linux/slab.h> |
43 | #include <linux/jiffies.h> | 43 | #include <linux/jiffies.h> |
44 | #include <linux/i2c.h> | 44 | #include <linux/i2c.h> |
45 | #include <linux/hwmon-sysfs.h> | 45 | #include <linux/hwmon-sysfs.h> |
46 | #include <linux/hwmon.h> | 46 | #include <linux/hwmon.h> |
47 | #include <linux/err.h> | 47 | #include <linux/err.h> |
48 | #include <linux/mutex.h> | 48 | #include <linux/mutex.h> |
49 | #include <linux/sysfs.h> | 49 | #include <linux/sysfs.h> |
50 | #include <linux/types.h> | 50 | #include <linux/types.h> |
51 | 51 | ||
52 | /* | 52 | /* |
53 | * Addresses to scan | 53 | * Addresses to scan |
54 | * Address is fully defined internally and cannot be changed except for | 54 | * Address is fully defined internally and cannot be changed except for |
55 | * LM64 which has one pin dedicated to address selection. | 55 | * LM64 which has one pin dedicated to address selection. |
56 | * LM63 and LM96163 have address 0x4c. | 56 | * LM63 and LM96163 have address 0x4c. |
57 | * LM64 can have address 0x18 or 0x4e. | 57 | * LM64 can have address 0x18 or 0x4e. |
58 | */ | 58 | */ |
59 | 59 | ||
60 | static const unsigned short normal_i2c[] = { 0x18, 0x4c, 0x4e, I2C_CLIENT_END }; | 60 | static const unsigned short normal_i2c[] = { 0x18, 0x4c, 0x4e, I2C_CLIENT_END }; |
61 | 61 | ||
62 | /* | 62 | /* |
63 | * The LM63 registers | 63 | * The LM63 registers |
64 | */ | 64 | */ |
65 | 65 | ||
66 | #define LM63_REG_CONFIG1 0x03 | 66 | #define LM63_REG_CONFIG1 0x03 |
67 | #define LM63_REG_CONVRATE 0x04 | 67 | #define LM63_REG_CONVRATE 0x04 |
68 | #define LM63_REG_CONFIG2 0xBF | 68 | #define LM63_REG_CONFIG2 0xBF |
69 | #define LM63_REG_CONFIG_FAN 0x4A | 69 | #define LM63_REG_CONFIG_FAN 0x4A |
70 | 70 | ||
71 | #define LM63_REG_TACH_COUNT_MSB 0x47 | 71 | #define LM63_REG_TACH_COUNT_MSB 0x47 |
72 | #define LM63_REG_TACH_COUNT_LSB 0x46 | 72 | #define LM63_REG_TACH_COUNT_LSB 0x46 |
73 | #define LM63_REG_TACH_LIMIT_MSB 0x49 | 73 | #define LM63_REG_TACH_LIMIT_MSB 0x49 |
74 | #define LM63_REG_TACH_LIMIT_LSB 0x48 | 74 | #define LM63_REG_TACH_LIMIT_LSB 0x48 |
75 | 75 | ||
76 | #define LM63_REG_PWM_VALUE 0x4C | 76 | #define LM63_REG_PWM_VALUE 0x4C |
77 | #define LM63_REG_PWM_FREQ 0x4D | 77 | #define LM63_REG_PWM_FREQ 0x4D |
78 | #define LM63_REG_LUT_TEMP_HYST 0x4F | 78 | #define LM63_REG_LUT_TEMP_HYST 0x4F |
79 | #define LM63_REG_LUT_TEMP(nr) (0x50 + 2 * (nr)) | 79 | #define LM63_REG_LUT_TEMP(nr) (0x50 + 2 * (nr)) |
80 | #define LM63_REG_LUT_PWM(nr) (0x51 + 2 * (nr)) | 80 | #define LM63_REG_LUT_PWM(nr) (0x51 + 2 * (nr)) |
81 | 81 | ||
82 | #define LM63_REG_LOCAL_TEMP 0x00 | 82 | #define LM63_REG_LOCAL_TEMP 0x00 |
83 | #define LM63_REG_LOCAL_HIGH 0x05 | 83 | #define LM63_REG_LOCAL_HIGH 0x05 |
84 | 84 | ||
85 | #define LM63_REG_REMOTE_TEMP_MSB 0x01 | 85 | #define LM63_REG_REMOTE_TEMP_MSB 0x01 |
86 | #define LM63_REG_REMOTE_TEMP_LSB 0x10 | 86 | #define LM63_REG_REMOTE_TEMP_LSB 0x10 |
87 | #define LM63_REG_REMOTE_OFFSET_MSB 0x11 | 87 | #define LM63_REG_REMOTE_OFFSET_MSB 0x11 |
88 | #define LM63_REG_REMOTE_OFFSET_LSB 0x12 | 88 | #define LM63_REG_REMOTE_OFFSET_LSB 0x12 |
89 | #define LM63_REG_REMOTE_HIGH_MSB 0x07 | 89 | #define LM63_REG_REMOTE_HIGH_MSB 0x07 |
90 | #define LM63_REG_REMOTE_HIGH_LSB 0x13 | 90 | #define LM63_REG_REMOTE_HIGH_LSB 0x13 |
91 | #define LM63_REG_REMOTE_LOW_MSB 0x08 | 91 | #define LM63_REG_REMOTE_LOW_MSB 0x08 |
92 | #define LM63_REG_REMOTE_LOW_LSB 0x14 | 92 | #define LM63_REG_REMOTE_LOW_LSB 0x14 |
93 | #define LM63_REG_REMOTE_TCRIT 0x19 | 93 | #define LM63_REG_REMOTE_TCRIT 0x19 |
94 | #define LM63_REG_REMOTE_TCRIT_HYST 0x21 | 94 | #define LM63_REG_REMOTE_TCRIT_HYST 0x21 |
95 | 95 | ||
96 | #define LM63_REG_ALERT_STATUS 0x02 | 96 | #define LM63_REG_ALERT_STATUS 0x02 |
97 | #define LM63_REG_ALERT_MASK 0x16 | 97 | #define LM63_REG_ALERT_MASK 0x16 |
98 | 98 | ||
99 | #define LM63_REG_MAN_ID 0xFE | 99 | #define LM63_REG_MAN_ID 0xFE |
100 | #define LM63_REG_CHIP_ID 0xFF | 100 | #define LM63_REG_CHIP_ID 0xFF |
101 | 101 | ||
102 | #define LM96163_REG_TRUTHERM 0x30 | 102 | #define LM96163_REG_TRUTHERM 0x30 |
103 | #define LM96163_REG_REMOTE_TEMP_U_MSB 0x31 | 103 | #define LM96163_REG_REMOTE_TEMP_U_MSB 0x31 |
104 | #define LM96163_REG_REMOTE_TEMP_U_LSB 0x32 | 104 | #define LM96163_REG_REMOTE_TEMP_U_LSB 0x32 |
105 | #define LM96163_REG_CONFIG_ENHANCED 0x45 | 105 | #define LM96163_REG_CONFIG_ENHANCED 0x45 |
106 | 106 | ||
107 | #define LM63_MAX_CONVRATE 9 | 107 | #define LM63_MAX_CONVRATE 9 |
108 | 108 | ||
109 | #define LM63_MAX_CONVRATE_HZ 32 | 109 | #define LM63_MAX_CONVRATE_HZ 32 |
110 | #define LM96163_MAX_CONVRATE_HZ 26 | 110 | #define LM96163_MAX_CONVRATE_HZ 26 |
111 | 111 | ||
112 | /* | 112 | /* |
113 | * Conversions and various macros | 113 | * Conversions and various macros |
114 | * For tachometer counts, the LM63 uses 16-bit values. | 114 | * For tachometer counts, the LM63 uses 16-bit values. |
115 | * For local temperature and high limit, remote critical limit and hysteresis | 115 | * For local temperature and high limit, remote critical limit and hysteresis |
116 | * value, it uses signed 8-bit values with LSB = 1 degree Celsius. | 116 | * value, it uses signed 8-bit values with LSB = 1 degree Celsius. |
117 | * For remote temperature, low and high limits, it uses signed 11-bit values | 117 | * For remote temperature, low and high limits, it uses signed 11-bit values |
118 | * with LSB = 0.125 degree Celsius, left-justified in 16-bit registers. | 118 | * with LSB = 0.125 degree Celsius, left-justified in 16-bit registers. |
119 | * For LM64 the actual remote diode temperature is 16 degree Celsius higher | 119 | * For LM64 the actual remote diode temperature is 16 degree Celsius higher |
120 | * than the register reading. Remote temperature setpoints have to be | 120 | * than the register reading. Remote temperature setpoints have to be |
121 | * adapted accordingly. | 121 | * adapted accordingly. |
122 | */ | 122 | */ |
123 | 123 | ||
124 | #define FAN_FROM_REG(reg) ((reg) == 0xFFFC || (reg) == 0 ? 0 : \ | 124 | #define FAN_FROM_REG(reg) ((reg) == 0xFFFC || (reg) == 0 ? 0 : \ |
125 | 5400000 / (reg)) | 125 | 5400000 / (reg)) |
126 | #define FAN_TO_REG(val) ((val) <= 82 ? 0xFFFC : \ | 126 | #define FAN_TO_REG(val) ((val) <= 82 ? 0xFFFC : \ |
127 | (5400000 / (val)) & 0xFFFC) | 127 | (5400000 / (val)) & 0xFFFC) |
128 | #define TEMP8_FROM_REG(reg) ((reg) * 1000) | 128 | #define TEMP8_FROM_REG(reg) ((reg) * 1000) |
129 | #define TEMP8_TO_REG(val) ((val) <= -128000 ? -128 : \ | 129 | #define TEMP8_TO_REG(val) ((val) <= -128000 ? -128 : \ |
130 | (val) >= 127000 ? 127 : \ | 130 | (val) >= 127000 ? 127 : \ |
131 | (val) < 0 ? ((val) - 500) / 1000 : \ | 131 | (val) < 0 ? ((val) - 500) / 1000 : \ |
132 | ((val) + 500) / 1000) | 132 | ((val) + 500) / 1000) |
133 | #define TEMP8U_TO_REG(val) ((val) <= 0 ? 0 : \ | 133 | #define TEMP8U_TO_REG(val) ((val) <= 0 ? 0 : \ |
134 | (val) >= 255000 ? 255 : \ | 134 | (val) >= 255000 ? 255 : \ |
135 | ((val) + 500) / 1000) | 135 | ((val) + 500) / 1000) |
136 | #define TEMP11_FROM_REG(reg) ((reg) / 32 * 125) | 136 | #define TEMP11_FROM_REG(reg) ((reg) / 32 * 125) |
137 | #define TEMP11_TO_REG(val) ((val) <= -128000 ? 0x8000 : \ | 137 | #define TEMP11_TO_REG(val) ((val) <= -128000 ? 0x8000 : \ |
138 | (val) >= 127875 ? 0x7FE0 : \ | 138 | (val) >= 127875 ? 0x7FE0 : \ |
139 | (val) < 0 ? ((val) - 62) / 125 * 32 : \ | 139 | (val) < 0 ? ((val) - 62) / 125 * 32 : \ |
140 | ((val) + 62) / 125 * 32) | 140 | ((val) + 62) / 125 * 32) |
141 | #define TEMP11U_TO_REG(val) ((val) <= 0 ? 0 : \ | 141 | #define TEMP11U_TO_REG(val) ((val) <= 0 ? 0 : \ |
142 | (val) >= 255875 ? 0xFFE0 : \ | 142 | (val) >= 255875 ? 0xFFE0 : \ |
143 | ((val) + 62) / 125 * 32) | 143 | ((val) + 62) / 125 * 32) |
144 | #define HYST_TO_REG(val) ((val) <= 0 ? 0 : \ | 144 | #define HYST_TO_REG(val) ((val) <= 0 ? 0 : \ |
145 | (val) >= 127000 ? 127 : \ | 145 | (val) >= 127000 ? 127 : \ |
146 | ((val) + 500) / 1000) | 146 | ((val) + 500) / 1000) |
147 | 147 | ||
148 | #define UPDATE_INTERVAL(max, rate) \ | 148 | #define UPDATE_INTERVAL(max, rate) \ |
149 | ((1000 << (LM63_MAX_CONVRATE - (rate))) / (max)) | 149 | ((1000 << (LM63_MAX_CONVRATE - (rate))) / (max)) |
150 | 150 | ||
151 | /* | 151 | /* |
152 | * Functions declaration | 152 | * Functions declaration |
153 | */ | 153 | */ |
154 | 154 | ||
155 | static int lm63_probe(struct i2c_client *client, | 155 | static int lm63_probe(struct i2c_client *client, |
156 | const struct i2c_device_id *id); | 156 | const struct i2c_device_id *id); |
157 | static int lm63_remove(struct i2c_client *client); | 157 | static int lm63_remove(struct i2c_client *client); |
158 | 158 | ||
159 | static struct lm63_data *lm63_update_device(struct device *dev); | 159 | static struct lm63_data *lm63_update_device(struct device *dev); |
160 | 160 | ||
161 | static int lm63_detect(struct i2c_client *client, struct i2c_board_info *info); | 161 | static int lm63_detect(struct i2c_client *client, struct i2c_board_info *info); |
162 | static void lm63_init_client(struct i2c_client *client); | 162 | static void lm63_init_client(struct i2c_client *client); |
163 | 163 | ||
164 | enum chips { lm63, lm64, lm96163 }; | 164 | enum chips { lm63, lm64, lm96163 }; |
165 | 165 | ||
166 | /* | 166 | /* |
167 | * Driver data (common to all clients) | 167 | * Driver data (common to all clients) |
168 | */ | 168 | */ |
169 | 169 | ||
170 | static const struct i2c_device_id lm63_id[] = { | 170 | static const struct i2c_device_id lm63_id[] = { |
171 | { "lm63", lm63 }, | 171 | { "lm63", lm63 }, |
172 | { "lm64", lm64 }, | 172 | { "lm64", lm64 }, |
173 | { "lm96163", lm96163 }, | 173 | { "lm96163", lm96163 }, |
174 | { } | 174 | { } |
175 | }; | 175 | }; |
176 | MODULE_DEVICE_TABLE(i2c, lm63_id); | 176 | MODULE_DEVICE_TABLE(i2c, lm63_id); |
177 | 177 | ||
178 | static struct i2c_driver lm63_driver = { | 178 | static struct i2c_driver lm63_driver = { |
179 | .class = I2C_CLASS_HWMON, | 179 | .class = I2C_CLASS_HWMON, |
180 | .driver = { | 180 | .driver = { |
181 | .name = "lm63", | 181 | .name = "lm63", |
182 | }, | 182 | }, |
183 | .probe = lm63_probe, | 183 | .probe = lm63_probe, |
184 | .remove = lm63_remove, | 184 | .remove = lm63_remove, |
185 | .id_table = lm63_id, | 185 | .id_table = lm63_id, |
186 | .detect = lm63_detect, | 186 | .detect = lm63_detect, |
187 | .address_list = normal_i2c, | 187 | .address_list = normal_i2c, |
188 | }; | 188 | }; |
189 | 189 | ||
190 | /* | 190 | /* |
191 | * Client data (each client gets its own) | 191 | * Client data (each client gets its own) |
192 | */ | 192 | */ |
193 | 193 | ||
194 | struct lm63_data { | 194 | struct lm63_data { |
195 | struct device *hwmon_dev; | 195 | struct device *hwmon_dev; |
196 | struct mutex update_lock; | 196 | struct mutex update_lock; |
197 | char valid; /* zero until following fields are valid */ | 197 | char valid; /* zero until following fields are valid */ |
198 | char lut_valid; /* zero until lut fields are valid */ | 198 | char lut_valid; /* zero until lut fields are valid */ |
199 | unsigned long last_updated; /* in jiffies */ | 199 | unsigned long last_updated; /* in jiffies */ |
200 | unsigned long lut_last_updated; /* in jiffies */ | 200 | unsigned long lut_last_updated; /* in jiffies */ |
201 | enum chips kind; | 201 | enum chips kind; |
202 | int temp2_offset; | 202 | int temp2_offset; |
203 | 203 | ||
204 | int update_interval; /* in milliseconds */ | 204 | int update_interval; /* in milliseconds */ |
205 | int max_convrate_hz; | 205 | int max_convrate_hz; |
206 | int lut_size; /* 8 or 12 */ | ||
206 | 207 | ||
207 | /* registers values */ | 208 | /* registers values */ |
208 | u8 config, config_fan; | 209 | u8 config, config_fan; |
209 | u16 fan[2]; /* 0: input | 210 | u16 fan[2]; /* 0: input |
210 | 1: low limit */ | 211 | 1: low limit */ |
211 | u8 pwm1_freq; | 212 | u8 pwm1_freq; |
212 | u8 pwm1[9]; /* 0: current output | 213 | u8 pwm1[13]; /* 0: current output |
213 | 1-8: lookup table */ | 214 | 1-12: lookup table */ |
214 | s8 temp8[11]; /* 0: local input | 215 | s8 temp8[15]; /* 0: local input |
215 | 1: local high limit | 216 | 1: local high limit |
216 | 2: remote critical limit | 217 | 2: remote critical limit |
217 | 3-10: lookup table */ | 218 | 3-14: lookup table */ |
218 | s16 temp11[4]; /* 0: remote input | 219 | s16 temp11[4]; /* 0: remote input |
219 | 1: remote low limit | 220 | 1: remote low limit |
220 | 2: remote high limit | 221 | 2: remote high limit |
221 | 3: remote offset */ | 222 | 3: remote offset */ |
222 | u16 temp11u; /* remote input (unsigned) */ | 223 | u16 temp11u; /* remote input (unsigned) */ |
223 | u8 temp2_crit_hyst; | 224 | u8 temp2_crit_hyst; |
224 | u8 lut_temp_hyst; | 225 | u8 lut_temp_hyst; |
225 | u8 alarms; | 226 | u8 alarms; |
226 | bool pwm_highres; | 227 | bool pwm_highres; |
227 | bool lut_temp_highres; | 228 | bool lut_temp_highres; |
228 | bool remote_unsigned; /* true if unsigned remote upper limits */ | 229 | bool remote_unsigned; /* true if unsigned remote upper limits */ |
229 | bool trutherm; | 230 | bool trutherm; |
230 | }; | 231 | }; |
231 | 232 | ||
232 | static inline int temp8_from_reg(struct lm63_data *data, int nr) | 233 | static inline int temp8_from_reg(struct lm63_data *data, int nr) |
233 | { | 234 | { |
234 | if (data->remote_unsigned) | 235 | if (data->remote_unsigned) |
235 | return TEMP8_FROM_REG((u8)data->temp8[nr]); | 236 | return TEMP8_FROM_REG((u8)data->temp8[nr]); |
236 | return TEMP8_FROM_REG(data->temp8[nr]); | 237 | return TEMP8_FROM_REG(data->temp8[nr]); |
237 | } | 238 | } |
238 | 239 | ||
239 | static inline int lut_temp_from_reg(struct lm63_data *data, int nr) | 240 | static inline int lut_temp_from_reg(struct lm63_data *data, int nr) |
240 | { | 241 | { |
241 | return data->temp8[nr] * (data->lut_temp_highres ? 500 : 1000); | 242 | return data->temp8[nr] * (data->lut_temp_highres ? 500 : 1000); |
242 | } | 243 | } |
243 | 244 | ||
244 | /* | 245 | /* |
245 | * Sysfs callback functions and files | 246 | * Sysfs callback functions and files |
246 | */ | 247 | */ |
247 | 248 | ||
248 | static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, | 249 | static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, |
249 | char *buf) | 250 | char *buf) |
250 | { | 251 | { |
251 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 252 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
252 | struct lm63_data *data = lm63_update_device(dev); | 253 | struct lm63_data *data = lm63_update_device(dev); |
253 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[attr->index])); | 254 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[attr->index])); |
254 | } | 255 | } |
255 | 256 | ||
256 | static ssize_t set_fan(struct device *dev, struct device_attribute *dummy, | 257 | static ssize_t set_fan(struct device *dev, struct device_attribute *dummy, |
257 | const char *buf, size_t count) | 258 | const char *buf, size_t count) |
258 | { | 259 | { |
259 | struct i2c_client *client = to_i2c_client(dev); | 260 | struct i2c_client *client = to_i2c_client(dev); |
260 | struct lm63_data *data = i2c_get_clientdata(client); | 261 | struct lm63_data *data = i2c_get_clientdata(client); |
261 | unsigned long val; | 262 | unsigned long val; |
262 | int err; | 263 | int err; |
263 | 264 | ||
264 | err = kstrtoul(buf, 10, &val); | 265 | err = kstrtoul(buf, 10, &val); |
265 | if (err) | 266 | if (err) |
266 | return err; | 267 | return err; |
267 | 268 | ||
268 | mutex_lock(&data->update_lock); | 269 | mutex_lock(&data->update_lock); |
269 | data->fan[1] = FAN_TO_REG(val); | 270 | data->fan[1] = FAN_TO_REG(val); |
270 | i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_LSB, | 271 | i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_LSB, |
271 | data->fan[1] & 0xFF); | 272 | data->fan[1] & 0xFF); |
272 | i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_MSB, | 273 | i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_MSB, |
273 | data->fan[1] >> 8); | 274 | data->fan[1] >> 8); |
274 | mutex_unlock(&data->update_lock); | 275 | mutex_unlock(&data->update_lock); |
275 | return count; | 276 | return count; |
276 | } | 277 | } |
277 | 278 | ||
278 | static ssize_t show_pwm1(struct device *dev, struct device_attribute *devattr, | 279 | static ssize_t show_pwm1(struct device *dev, struct device_attribute *devattr, |
279 | char *buf) | 280 | char *buf) |
280 | { | 281 | { |
281 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 282 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
282 | struct lm63_data *data = lm63_update_device(dev); | 283 | struct lm63_data *data = lm63_update_device(dev); |
283 | int nr = attr->index; | 284 | int nr = attr->index; |
284 | int pwm; | 285 | int pwm; |
285 | 286 | ||
286 | if (data->pwm_highres) | 287 | if (data->pwm_highres) |
287 | pwm = data->pwm1[nr]; | 288 | pwm = data->pwm1[nr]; |
288 | else | 289 | else |
289 | pwm = data->pwm1[nr] >= 2 * data->pwm1_freq ? | 290 | pwm = data->pwm1[nr] >= 2 * data->pwm1_freq ? |
290 | 255 : (data->pwm1[nr] * 255 + data->pwm1_freq) / | 291 | 255 : (data->pwm1[nr] * 255 + data->pwm1_freq) / |
291 | (2 * data->pwm1_freq); | 292 | (2 * data->pwm1_freq); |
292 | 293 | ||
293 | return sprintf(buf, "%d\n", pwm); | 294 | return sprintf(buf, "%d\n", pwm); |
294 | } | 295 | } |
295 | 296 | ||
296 | static ssize_t set_pwm1(struct device *dev, struct device_attribute *dummy, | 297 | static ssize_t set_pwm1(struct device *dev, struct device_attribute *dummy, |
297 | const char *buf, size_t count) | 298 | const char *buf, size_t count) |
298 | { | 299 | { |
299 | struct i2c_client *client = to_i2c_client(dev); | 300 | struct i2c_client *client = to_i2c_client(dev); |
300 | struct lm63_data *data = i2c_get_clientdata(client); | 301 | struct lm63_data *data = i2c_get_clientdata(client); |
301 | unsigned long val; | 302 | unsigned long val; |
302 | int err; | 303 | int err; |
303 | 304 | ||
304 | if (!(data->config_fan & 0x20)) /* register is read-only */ | 305 | if (!(data->config_fan & 0x20)) /* register is read-only */ |
305 | return -EPERM; | 306 | return -EPERM; |
306 | 307 | ||
307 | err = kstrtoul(buf, 10, &val); | 308 | err = kstrtoul(buf, 10, &val); |
308 | if (err) | 309 | if (err) |
309 | return err; | 310 | return err; |
310 | 311 | ||
311 | val = SENSORS_LIMIT(val, 0, 255); | 312 | val = SENSORS_LIMIT(val, 0, 255); |
312 | mutex_lock(&data->update_lock); | 313 | mutex_lock(&data->update_lock); |
313 | data->pwm1[0] = data->pwm_highres ? val : | 314 | data->pwm1[0] = data->pwm_highres ? val : |
314 | (val * data->pwm1_freq * 2 + 127) / 255; | 315 | (val * data->pwm1_freq * 2 + 127) / 255; |
315 | i2c_smbus_write_byte_data(client, LM63_REG_PWM_VALUE, data->pwm1[0]); | 316 | i2c_smbus_write_byte_data(client, LM63_REG_PWM_VALUE, data->pwm1[0]); |
316 | mutex_unlock(&data->update_lock); | 317 | mutex_unlock(&data->update_lock); |
317 | return count; | 318 | return count; |
318 | } | 319 | } |
319 | 320 | ||
320 | static ssize_t show_pwm1_enable(struct device *dev, | 321 | static ssize_t show_pwm1_enable(struct device *dev, |
321 | struct device_attribute *dummy, char *buf) | 322 | struct device_attribute *dummy, char *buf) |
322 | { | 323 | { |
323 | struct lm63_data *data = lm63_update_device(dev); | 324 | struct lm63_data *data = lm63_update_device(dev); |
324 | return sprintf(buf, "%d\n", data->config_fan & 0x20 ? 1 : 2); | 325 | return sprintf(buf, "%d\n", data->config_fan & 0x20 ? 1 : 2); |
325 | } | 326 | } |
326 | 327 | ||
327 | /* | 328 | /* |
328 | * There are 8bit registers for both local(temp1) and remote(temp2) sensor. | 329 | * There are 8bit registers for both local(temp1) and remote(temp2) sensor. |
329 | * For remote sensor registers temp2_offset has to be considered, | 330 | * For remote sensor registers temp2_offset has to be considered, |
330 | * for local sensor it must not. | 331 | * for local sensor it must not. |
331 | * So we need separate 8bit accessors for local and remote sensor. | 332 | * So we need separate 8bit accessors for local and remote sensor. |
332 | */ | 333 | */ |
333 | static ssize_t show_local_temp8(struct device *dev, | 334 | static ssize_t show_local_temp8(struct device *dev, |
334 | struct device_attribute *devattr, | 335 | struct device_attribute *devattr, |
335 | char *buf) | 336 | char *buf) |
336 | { | 337 | { |
337 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 338 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
338 | struct lm63_data *data = lm63_update_device(dev); | 339 | struct lm63_data *data = lm63_update_device(dev); |
339 | return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->temp8[attr->index])); | 340 | return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->temp8[attr->index])); |
340 | } | 341 | } |
341 | 342 | ||
342 | static ssize_t show_remote_temp8(struct device *dev, | 343 | static ssize_t show_remote_temp8(struct device *dev, |
343 | struct device_attribute *devattr, | 344 | struct device_attribute *devattr, |
344 | char *buf) | 345 | char *buf) |
345 | { | 346 | { |
346 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 347 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
347 | struct lm63_data *data = lm63_update_device(dev); | 348 | struct lm63_data *data = lm63_update_device(dev); |
348 | return sprintf(buf, "%d\n", temp8_from_reg(data, attr->index) | 349 | return sprintf(buf, "%d\n", temp8_from_reg(data, attr->index) |
349 | + data->temp2_offset); | 350 | + data->temp2_offset); |
350 | } | 351 | } |
351 | 352 | ||
352 | static ssize_t show_lut_temp(struct device *dev, | 353 | static ssize_t show_lut_temp(struct device *dev, |
353 | struct device_attribute *devattr, | 354 | struct device_attribute *devattr, |
354 | char *buf) | 355 | char *buf) |
355 | { | 356 | { |
356 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 357 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
357 | struct lm63_data *data = lm63_update_device(dev); | 358 | struct lm63_data *data = lm63_update_device(dev); |
358 | return sprintf(buf, "%d\n", lut_temp_from_reg(data, attr->index) | 359 | return sprintf(buf, "%d\n", lut_temp_from_reg(data, attr->index) |
359 | + data->temp2_offset); | 360 | + data->temp2_offset); |
360 | } | 361 | } |
361 | 362 | ||
362 | static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr, | 363 | static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr, |
363 | const char *buf, size_t count) | 364 | const char *buf, size_t count) |
364 | { | 365 | { |
365 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 366 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
366 | struct i2c_client *client = to_i2c_client(dev); | 367 | struct i2c_client *client = to_i2c_client(dev); |
367 | struct lm63_data *data = i2c_get_clientdata(client); | 368 | struct lm63_data *data = i2c_get_clientdata(client); |
368 | int nr = attr->index; | 369 | int nr = attr->index; |
369 | int reg = nr == 2 ? LM63_REG_REMOTE_TCRIT : LM63_REG_LOCAL_HIGH; | 370 | int reg = nr == 2 ? LM63_REG_REMOTE_TCRIT : LM63_REG_LOCAL_HIGH; |
370 | long val; | 371 | long val; |
371 | int err; | 372 | int err; |
372 | int temp; | 373 | int temp; |
373 | 374 | ||
374 | err = kstrtol(buf, 10, &val); | 375 | err = kstrtol(buf, 10, &val); |
375 | if (err) | 376 | if (err) |
376 | return err; | 377 | return err; |
377 | 378 | ||
378 | mutex_lock(&data->update_lock); | 379 | mutex_lock(&data->update_lock); |
379 | if (nr == 2) { | 380 | if (nr == 2) { |
380 | if (data->remote_unsigned) | 381 | if (data->remote_unsigned) |
381 | temp = TEMP8U_TO_REG(val - data->temp2_offset); | 382 | temp = TEMP8U_TO_REG(val - data->temp2_offset); |
382 | else | 383 | else |
383 | temp = TEMP8_TO_REG(val - data->temp2_offset); | 384 | temp = TEMP8_TO_REG(val - data->temp2_offset); |
384 | } else { | 385 | } else { |
385 | temp = TEMP8_TO_REG(val); | 386 | temp = TEMP8_TO_REG(val); |
386 | } | 387 | } |
387 | data->temp8[nr] = temp; | 388 | data->temp8[nr] = temp; |
388 | i2c_smbus_write_byte_data(client, reg, temp); | 389 | i2c_smbus_write_byte_data(client, reg, temp); |
389 | mutex_unlock(&data->update_lock); | 390 | mutex_unlock(&data->update_lock); |
390 | return count; | 391 | return count; |
391 | } | 392 | } |
392 | 393 | ||
393 | static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr, | 394 | static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr, |
394 | char *buf) | 395 | char *buf) |
395 | { | 396 | { |
396 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 397 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
397 | struct lm63_data *data = lm63_update_device(dev); | 398 | struct lm63_data *data = lm63_update_device(dev); |
398 | int nr = attr->index; | 399 | int nr = attr->index; |
399 | int temp; | 400 | int temp; |
400 | 401 | ||
401 | if (!nr) { | 402 | if (!nr) { |
402 | /* | 403 | /* |
403 | * Use unsigned temperature unless its value is zero. | 404 | * Use unsigned temperature unless its value is zero. |
404 | * If it is zero, use signed temperature. | 405 | * If it is zero, use signed temperature. |
405 | */ | 406 | */ |
406 | if (data->temp11u) | 407 | if (data->temp11u) |
407 | temp = TEMP11_FROM_REG(data->temp11u); | 408 | temp = TEMP11_FROM_REG(data->temp11u); |
408 | else | 409 | else |
409 | temp = TEMP11_FROM_REG(data->temp11[nr]); | 410 | temp = TEMP11_FROM_REG(data->temp11[nr]); |
410 | } else { | 411 | } else { |
411 | if (data->remote_unsigned && nr == 2) | 412 | if (data->remote_unsigned && nr == 2) |
412 | temp = TEMP11_FROM_REG((u16)data->temp11[nr]); | 413 | temp = TEMP11_FROM_REG((u16)data->temp11[nr]); |
413 | else | 414 | else |
414 | temp = TEMP11_FROM_REG(data->temp11[nr]); | 415 | temp = TEMP11_FROM_REG(data->temp11[nr]); |
415 | } | 416 | } |
416 | return sprintf(buf, "%d\n", temp + data->temp2_offset); | 417 | return sprintf(buf, "%d\n", temp + data->temp2_offset); |
417 | } | 418 | } |
418 | 419 | ||
419 | static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, | 420 | static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, |
420 | const char *buf, size_t count) | 421 | const char *buf, size_t count) |
421 | { | 422 | { |
422 | static const u8 reg[6] = { | 423 | static const u8 reg[6] = { |
423 | LM63_REG_REMOTE_LOW_MSB, | 424 | LM63_REG_REMOTE_LOW_MSB, |
424 | LM63_REG_REMOTE_LOW_LSB, | 425 | LM63_REG_REMOTE_LOW_LSB, |
425 | LM63_REG_REMOTE_HIGH_MSB, | 426 | LM63_REG_REMOTE_HIGH_MSB, |
426 | LM63_REG_REMOTE_HIGH_LSB, | 427 | LM63_REG_REMOTE_HIGH_LSB, |
427 | LM63_REG_REMOTE_OFFSET_MSB, | 428 | LM63_REG_REMOTE_OFFSET_MSB, |
428 | LM63_REG_REMOTE_OFFSET_LSB, | 429 | LM63_REG_REMOTE_OFFSET_LSB, |
429 | }; | 430 | }; |
430 | 431 | ||
431 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 432 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
432 | struct i2c_client *client = to_i2c_client(dev); | 433 | struct i2c_client *client = to_i2c_client(dev); |
433 | struct lm63_data *data = i2c_get_clientdata(client); | 434 | struct lm63_data *data = i2c_get_clientdata(client); |
434 | long val; | 435 | long val; |
435 | int err; | 436 | int err; |
436 | int nr = attr->index; | 437 | int nr = attr->index; |
437 | 438 | ||
438 | err = kstrtol(buf, 10, &val); | 439 | err = kstrtol(buf, 10, &val); |
439 | if (err) | 440 | if (err) |
440 | return err; | 441 | return err; |
441 | 442 | ||
442 | mutex_lock(&data->update_lock); | 443 | mutex_lock(&data->update_lock); |
443 | if (data->remote_unsigned && nr == 2) | 444 | if (data->remote_unsigned && nr == 2) |
444 | data->temp11[nr] = TEMP11U_TO_REG(val - data->temp2_offset); | 445 | data->temp11[nr] = TEMP11U_TO_REG(val - data->temp2_offset); |
445 | else | 446 | else |
446 | data->temp11[nr] = TEMP11_TO_REG(val - data->temp2_offset); | 447 | data->temp11[nr] = TEMP11_TO_REG(val - data->temp2_offset); |
447 | 448 | ||
448 | i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2], | 449 | i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2], |
449 | data->temp11[nr] >> 8); | 450 | data->temp11[nr] >> 8); |
450 | i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1], | 451 | i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1], |
451 | data->temp11[nr] & 0xff); | 452 | data->temp11[nr] & 0xff); |
452 | mutex_unlock(&data->update_lock); | 453 | mutex_unlock(&data->update_lock); |
453 | return count; | 454 | return count; |
454 | } | 455 | } |
455 | 456 | ||
456 | /* | 457 | /* |
457 | * Hysteresis register holds a relative value, while we want to present | 458 | * Hysteresis register holds a relative value, while we want to present |
458 | * an absolute to user-space | 459 | * an absolute to user-space |
459 | */ | 460 | */ |
460 | static ssize_t show_temp2_crit_hyst(struct device *dev, | 461 | static ssize_t show_temp2_crit_hyst(struct device *dev, |
461 | struct device_attribute *dummy, char *buf) | 462 | struct device_attribute *dummy, char *buf) |
462 | { | 463 | { |
463 | struct lm63_data *data = lm63_update_device(dev); | 464 | struct lm63_data *data = lm63_update_device(dev); |
464 | return sprintf(buf, "%d\n", temp8_from_reg(data, 2) | 465 | return sprintf(buf, "%d\n", temp8_from_reg(data, 2) |
465 | + data->temp2_offset | 466 | + data->temp2_offset |
466 | - TEMP8_FROM_REG(data->temp2_crit_hyst)); | 467 | - TEMP8_FROM_REG(data->temp2_crit_hyst)); |
467 | } | 468 | } |
468 | 469 | ||
469 | static ssize_t show_lut_temp_hyst(struct device *dev, | 470 | static ssize_t show_lut_temp_hyst(struct device *dev, |
470 | struct device_attribute *devattr, char *buf) | 471 | struct device_attribute *devattr, char *buf) |
471 | { | 472 | { |
472 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 473 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
473 | struct lm63_data *data = lm63_update_device(dev); | 474 | struct lm63_data *data = lm63_update_device(dev); |
474 | 475 | ||
475 | return sprintf(buf, "%d\n", lut_temp_from_reg(data, attr->index) | 476 | return sprintf(buf, "%d\n", lut_temp_from_reg(data, attr->index) |
476 | + data->temp2_offset | 477 | + data->temp2_offset |
477 | - TEMP8_FROM_REG(data->lut_temp_hyst)); | 478 | - TEMP8_FROM_REG(data->lut_temp_hyst)); |
478 | } | 479 | } |
479 | 480 | ||
480 | /* | 481 | /* |
481 | * And now the other way around, user-space provides an absolute | 482 | * And now the other way around, user-space provides an absolute |
482 | * hysteresis value and we have to store a relative one | 483 | * hysteresis value and we have to store a relative one |
483 | */ | 484 | */ |
484 | static ssize_t set_temp2_crit_hyst(struct device *dev, | 485 | static ssize_t set_temp2_crit_hyst(struct device *dev, |
485 | struct device_attribute *dummy, | 486 | struct device_attribute *dummy, |
486 | const char *buf, size_t count) | 487 | const char *buf, size_t count) |
487 | { | 488 | { |
488 | struct i2c_client *client = to_i2c_client(dev); | 489 | struct i2c_client *client = to_i2c_client(dev); |
489 | struct lm63_data *data = i2c_get_clientdata(client); | 490 | struct lm63_data *data = i2c_get_clientdata(client); |
490 | long val; | 491 | long val; |
491 | int err; | 492 | int err; |
492 | long hyst; | 493 | long hyst; |
493 | 494 | ||
494 | err = kstrtol(buf, 10, &val); | 495 | err = kstrtol(buf, 10, &val); |
495 | if (err) | 496 | if (err) |
496 | return err; | 497 | return err; |
497 | 498 | ||
498 | mutex_lock(&data->update_lock); | 499 | mutex_lock(&data->update_lock); |
499 | hyst = temp8_from_reg(data, 2) + data->temp2_offset - val; | 500 | hyst = temp8_from_reg(data, 2) + data->temp2_offset - val; |
500 | i2c_smbus_write_byte_data(client, LM63_REG_REMOTE_TCRIT_HYST, | 501 | i2c_smbus_write_byte_data(client, LM63_REG_REMOTE_TCRIT_HYST, |
501 | HYST_TO_REG(hyst)); | 502 | HYST_TO_REG(hyst)); |
502 | mutex_unlock(&data->update_lock); | 503 | mutex_unlock(&data->update_lock); |
503 | return count; | 504 | return count; |
504 | } | 505 | } |
505 | 506 | ||
506 | /* | 507 | /* |
507 | * Set conversion rate. | 508 | * Set conversion rate. |
508 | * client->update_lock must be held when calling this function. | 509 | * client->update_lock must be held when calling this function. |
509 | */ | 510 | */ |
510 | static void lm63_set_convrate(struct i2c_client *client, struct lm63_data *data, | 511 | static void lm63_set_convrate(struct i2c_client *client, struct lm63_data *data, |
511 | unsigned int interval) | 512 | unsigned int interval) |
512 | { | 513 | { |
513 | int i; | 514 | int i; |
514 | unsigned int update_interval; | 515 | unsigned int update_interval; |
515 | 516 | ||
516 | /* Shift calculations to avoid rounding errors */ | 517 | /* Shift calculations to avoid rounding errors */ |
517 | interval <<= 6; | 518 | interval <<= 6; |
518 | 519 | ||
519 | /* find the nearest update rate */ | 520 | /* find the nearest update rate */ |
520 | update_interval = (1 << (LM63_MAX_CONVRATE + 6)) * 1000 | 521 | update_interval = (1 << (LM63_MAX_CONVRATE + 6)) * 1000 |
521 | / data->max_convrate_hz; | 522 | / data->max_convrate_hz; |
522 | for (i = 0; i < LM63_MAX_CONVRATE; i++, update_interval >>= 1) | 523 | for (i = 0; i < LM63_MAX_CONVRATE; i++, update_interval >>= 1) |
523 | if (interval >= update_interval * 3 / 4) | 524 | if (interval >= update_interval * 3 / 4) |
524 | break; | 525 | break; |
525 | 526 | ||
526 | i2c_smbus_write_byte_data(client, LM63_REG_CONVRATE, i); | 527 | i2c_smbus_write_byte_data(client, LM63_REG_CONVRATE, i); |
527 | data->update_interval = UPDATE_INTERVAL(data->max_convrate_hz, i); | 528 | data->update_interval = UPDATE_INTERVAL(data->max_convrate_hz, i); |
528 | } | 529 | } |
529 | 530 | ||
530 | static ssize_t show_update_interval(struct device *dev, | 531 | static ssize_t show_update_interval(struct device *dev, |
531 | struct device_attribute *attr, char *buf) | 532 | struct device_attribute *attr, char *buf) |
532 | { | 533 | { |
533 | struct lm63_data *data = dev_get_drvdata(dev); | 534 | struct lm63_data *data = dev_get_drvdata(dev); |
534 | 535 | ||
535 | return sprintf(buf, "%u\n", data->update_interval); | 536 | return sprintf(buf, "%u\n", data->update_interval); |
536 | } | 537 | } |
537 | 538 | ||
538 | static ssize_t set_update_interval(struct device *dev, | 539 | static ssize_t set_update_interval(struct device *dev, |
539 | struct device_attribute *attr, | 540 | struct device_attribute *attr, |
540 | const char *buf, size_t count) | 541 | const char *buf, size_t count) |
541 | { | 542 | { |
542 | struct i2c_client *client = to_i2c_client(dev); | 543 | struct i2c_client *client = to_i2c_client(dev); |
543 | struct lm63_data *data = i2c_get_clientdata(client); | 544 | struct lm63_data *data = i2c_get_clientdata(client); |
544 | unsigned long val; | 545 | unsigned long val; |
545 | int err; | 546 | int err; |
546 | 547 | ||
547 | err = kstrtoul(buf, 10, &val); | 548 | err = kstrtoul(buf, 10, &val); |
548 | if (err) | 549 | if (err) |
549 | return err; | 550 | return err; |
550 | 551 | ||
551 | mutex_lock(&data->update_lock); | 552 | mutex_lock(&data->update_lock); |
552 | lm63_set_convrate(client, data, SENSORS_LIMIT(val, 0, 100000)); | 553 | lm63_set_convrate(client, data, SENSORS_LIMIT(val, 0, 100000)); |
553 | mutex_unlock(&data->update_lock); | 554 | mutex_unlock(&data->update_lock); |
554 | 555 | ||
555 | return count; | 556 | return count; |
556 | } | 557 | } |
557 | 558 | ||
558 | static ssize_t show_type(struct device *dev, struct device_attribute *attr, | 559 | static ssize_t show_type(struct device *dev, struct device_attribute *attr, |
559 | char *buf) | 560 | char *buf) |
560 | { | 561 | { |
561 | struct i2c_client *client = to_i2c_client(dev); | 562 | struct i2c_client *client = to_i2c_client(dev); |
562 | struct lm63_data *data = i2c_get_clientdata(client); | 563 | struct lm63_data *data = i2c_get_clientdata(client); |
563 | 564 | ||
564 | return sprintf(buf, data->trutherm ? "1\n" : "2\n"); | 565 | return sprintf(buf, data->trutherm ? "1\n" : "2\n"); |
565 | } | 566 | } |
566 | 567 | ||
567 | static ssize_t set_type(struct device *dev, struct device_attribute *attr, | 568 | static ssize_t set_type(struct device *dev, struct device_attribute *attr, |
568 | const char *buf, size_t count) | 569 | const char *buf, size_t count) |
569 | { | 570 | { |
570 | struct i2c_client *client = to_i2c_client(dev); | 571 | struct i2c_client *client = to_i2c_client(dev); |
571 | struct lm63_data *data = i2c_get_clientdata(client); | 572 | struct lm63_data *data = i2c_get_clientdata(client); |
572 | unsigned long val; | 573 | unsigned long val; |
573 | int ret; | 574 | int ret; |
574 | u8 reg; | 575 | u8 reg; |
575 | 576 | ||
576 | ret = kstrtoul(buf, 10, &val); | 577 | ret = kstrtoul(buf, 10, &val); |
577 | if (ret < 0) | 578 | if (ret < 0) |
578 | return ret; | 579 | return ret; |
579 | if (val != 1 && val != 2) | 580 | if (val != 1 && val != 2) |
580 | return -EINVAL; | 581 | return -EINVAL; |
581 | 582 | ||
582 | mutex_lock(&data->update_lock); | 583 | mutex_lock(&data->update_lock); |
583 | data->trutherm = val == 1; | 584 | data->trutherm = val == 1; |
584 | reg = i2c_smbus_read_byte_data(client, LM96163_REG_TRUTHERM) & ~0x02; | 585 | reg = i2c_smbus_read_byte_data(client, LM96163_REG_TRUTHERM) & ~0x02; |
585 | i2c_smbus_write_byte_data(client, LM96163_REG_TRUTHERM, | 586 | i2c_smbus_write_byte_data(client, LM96163_REG_TRUTHERM, |
586 | reg | (data->trutherm ? 0x02 : 0x00)); | 587 | reg | (data->trutherm ? 0x02 : 0x00)); |
587 | data->valid = 0; | 588 | data->valid = 0; |
588 | mutex_unlock(&data->update_lock); | 589 | mutex_unlock(&data->update_lock); |
589 | 590 | ||
590 | return count; | 591 | return count; |
591 | } | 592 | } |
592 | 593 | ||
593 | static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy, | 594 | static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy, |
594 | char *buf) | 595 | char *buf) |
595 | { | 596 | { |
596 | struct lm63_data *data = lm63_update_device(dev); | 597 | struct lm63_data *data = lm63_update_device(dev); |
597 | return sprintf(buf, "%u\n", data->alarms); | 598 | return sprintf(buf, "%u\n", data->alarms); |
598 | } | 599 | } |
599 | 600 | ||
600 | static ssize_t show_alarm(struct device *dev, struct device_attribute *devattr, | 601 | static ssize_t show_alarm(struct device *dev, struct device_attribute *devattr, |
601 | char *buf) | 602 | char *buf) |
602 | { | 603 | { |
603 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 604 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
604 | struct lm63_data *data = lm63_update_device(dev); | 605 | struct lm63_data *data = lm63_update_device(dev); |
605 | int bitnr = attr->index; | 606 | int bitnr = attr->index; |
606 | 607 | ||
607 | return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); | 608 | return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); |
608 | } | 609 | } |
609 | 610 | ||
610 | static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0); | 611 | static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0); |
611 | static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan, | 612 | static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan, |
612 | set_fan, 1); | 613 | set_fan, 1); |
613 | 614 | ||
614 | static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm1, set_pwm1, 0); | 615 | static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm1, set_pwm1, 0); |
615 | static DEVICE_ATTR(pwm1_enable, S_IRUGO, show_pwm1_enable, NULL); | 616 | static DEVICE_ATTR(pwm1_enable, S_IRUGO, show_pwm1_enable, NULL); |
616 | static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IRUGO, show_pwm1, NULL, 1); | 617 | static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IRUGO, show_pwm1, NULL, 1); |
617 | static SENSOR_DEVICE_ATTR(pwm1_auto_point1_temp, S_IRUGO, | 618 | static SENSOR_DEVICE_ATTR(pwm1_auto_point1_temp, S_IRUGO, |
618 | show_lut_temp, NULL, 3); | 619 | show_lut_temp, NULL, 3); |
619 | static SENSOR_DEVICE_ATTR(pwm1_auto_point1_temp_hyst, S_IRUGO, | 620 | static SENSOR_DEVICE_ATTR(pwm1_auto_point1_temp_hyst, S_IRUGO, |
620 | show_lut_temp_hyst, NULL, 3); | 621 | show_lut_temp_hyst, NULL, 3); |
621 | static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IRUGO, show_pwm1, NULL, 2); | 622 | static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IRUGO, show_pwm1, NULL, 2); |
622 | static SENSOR_DEVICE_ATTR(pwm1_auto_point2_temp, S_IRUGO, | 623 | static SENSOR_DEVICE_ATTR(pwm1_auto_point2_temp, S_IRUGO, |
623 | show_lut_temp, NULL, 4); | 624 | show_lut_temp, NULL, 4); |
624 | static SENSOR_DEVICE_ATTR(pwm1_auto_point2_temp_hyst, S_IRUGO, | 625 | static SENSOR_DEVICE_ATTR(pwm1_auto_point2_temp_hyst, S_IRUGO, |
625 | show_lut_temp_hyst, NULL, 4); | 626 | show_lut_temp_hyst, NULL, 4); |
626 | static SENSOR_DEVICE_ATTR(pwm1_auto_point3_pwm, S_IRUGO, show_pwm1, NULL, 3); | 627 | static SENSOR_DEVICE_ATTR(pwm1_auto_point3_pwm, S_IRUGO, show_pwm1, NULL, 3); |
627 | static SENSOR_DEVICE_ATTR(pwm1_auto_point3_temp, S_IRUGO, | 628 | static SENSOR_DEVICE_ATTR(pwm1_auto_point3_temp, S_IRUGO, |
628 | show_lut_temp, NULL, 5); | 629 | show_lut_temp, NULL, 5); |
629 | static SENSOR_DEVICE_ATTR(pwm1_auto_point3_temp_hyst, S_IRUGO, | 630 | static SENSOR_DEVICE_ATTR(pwm1_auto_point3_temp_hyst, S_IRUGO, |
630 | show_lut_temp_hyst, NULL, 5); | 631 | show_lut_temp_hyst, NULL, 5); |
631 | static SENSOR_DEVICE_ATTR(pwm1_auto_point4_pwm, S_IRUGO, show_pwm1, NULL, 4); | 632 | static SENSOR_DEVICE_ATTR(pwm1_auto_point4_pwm, S_IRUGO, show_pwm1, NULL, 4); |
632 | static SENSOR_DEVICE_ATTR(pwm1_auto_point4_temp, S_IRUGO, | 633 | static SENSOR_DEVICE_ATTR(pwm1_auto_point4_temp, S_IRUGO, |
633 | show_lut_temp, NULL, 6); | 634 | show_lut_temp, NULL, 6); |
634 | static SENSOR_DEVICE_ATTR(pwm1_auto_point4_temp_hyst, S_IRUGO, | 635 | static SENSOR_DEVICE_ATTR(pwm1_auto_point4_temp_hyst, S_IRUGO, |
635 | show_lut_temp_hyst, NULL, 6); | 636 | show_lut_temp_hyst, NULL, 6); |
636 | static SENSOR_DEVICE_ATTR(pwm1_auto_point5_pwm, S_IRUGO, show_pwm1, NULL, 5); | 637 | static SENSOR_DEVICE_ATTR(pwm1_auto_point5_pwm, S_IRUGO, show_pwm1, NULL, 5); |
637 | static SENSOR_DEVICE_ATTR(pwm1_auto_point5_temp, S_IRUGO, | 638 | static SENSOR_DEVICE_ATTR(pwm1_auto_point5_temp, S_IRUGO, |
638 | show_lut_temp, NULL, 7); | 639 | show_lut_temp, NULL, 7); |
639 | static SENSOR_DEVICE_ATTR(pwm1_auto_point5_temp_hyst, S_IRUGO, | 640 | static SENSOR_DEVICE_ATTR(pwm1_auto_point5_temp_hyst, S_IRUGO, |
640 | show_lut_temp_hyst, NULL, 7); | 641 | show_lut_temp_hyst, NULL, 7); |
641 | static SENSOR_DEVICE_ATTR(pwm1_auto_point6_pwm, S_IRUGO, show_pwm1, NULL, 6); | 642 | static SENSOR_DEVICE_ATTR(pwm1_auto_point6_pwm, S_IRUGO, show_pwm1, NULL, 6); |
642 | static SENSOR_DEVICE_ATTR(pwm1_auto_point6_temp, S_IRUGO, | 643 | static SENSOR_DEVICE_ATTR(pwm1_auto_point6_temp, S_IRUGO, |
643 | show_lut_temp, NULL, 8); | 644 | show_lut_temp, NULL, 8); |
644 | static SENSOR_DEVICE_ATTR(pwm1_auto_point6_temp_hyst, S_IRUGO, | 645 | static SENSOR_DEVICE_ATTR(pwm1_auto_point6_temp_hyst, S_IRUGO, |
645 | show_lut_temp_hyst, NULL, 8); | 646 | show_lut_temp_hyst, NULL, 8); |
646 | static SENSOR_DEVICE_ATTR(pwm1_auto_point7_pwm, S_IRUGO, show_pwm1, NULL, 7); | 647 | static SENSOR_DEVICE_ATTR(pwm1_auto_point7_pwm, S_IRUGO, show_pwm1, NULL, 7); |
647 | static SENSOR_DEVICE_ATTR(pwm1_auto_point7_temp, S_IRUGO, | 648 | static SENSOR_DEVICE_ATTR(pwm1_auto_point7_temp, S_IRUGO, |
648 | show_lut_temp, NULL, 9); | 649 | show_lut_temp, NULL, 9); |
649 | static SENSOR_DEVICE_ATTR(pwm1_auto_point7_temp_hyst, S_IRUGO, | 650 | static SENSOR_DEVICE_ATTR(pwm1_auto_point7_temp_hyst, S_IRUGO, |
650 | show_lut_temp_hyst, NULL, 9); | 651 | show_lut_temp_hyst, NULL, 9); |
651 | static SENSOR_DEVICE_ATTR(pwm1_auto_point8_pwm, S_IRUGO, show_pwm1, NULL, 8); | 652 | static SENSOR_DEVICE_ATTR(pwm1_auto_point8_pwm, S_IRUGO, show_pwm1, NULL, 8); |
652 | static SENSOR_DEVICE_ATTR(pwm1_auto_point8_temp, S_IRUGO, | 653 | static SENSOR_DEVICE_ATTR(pwm1_auto_point8_temp, S_IRUGO, |
653 | show_lut_temp, NULL, 10); | 654 | show_lut_temp, NULL, 10); |
654 | static SENSOR_DEVICE_ATTR(pwm1_auto_point8_temp_hyst, S_IRUGO, | 655 | static SENSOR_DEVICE_ATTR(pwm1_auto_point8_temp_hyst, S_IRUGO, |
655 | show_lut_temp_hyst, NULL, 10); | 656 | show_lut_temp_hyst, NULL, 10); |
657 | static SENSOR_DEVICE_ATTR(pwm1_auto_point9_pwm, S_IRUGO, show_pwm1, NULL, 9); | ||
658 | static SENSOR_DEVICE_ATTR(pwm1_auto_point9_temp, S_IRUGO, | ||
659 | show_lut_temp, NULL, 11); | ||
660 | static SENSOR_DEVICE_ATTR(pwm1_auto_point9_temp_hyst, S_IRUGO, | ||
661 | show_lut_temp_hyst, NULL, 11); | ||
662 | static SENSOR_DEVICE_ATTR(pwm1_auto_point10_pwm, S_IRUGO, show_pwm1, NULL, 10); | ||
663 | static SENSOR_DEVICE_ATTR(pwm1_auto_point10_temp, S_IRUGO, | ||
664 | show_lut_temp, NULL, 12); | ||
665 | static SENSOR_DEVICE_ATTR(pwm1_auto_point10_temp_hyst, S_IRUGO, | ||
666 | show_lut_temp_hyst, NULL, 12); | ||
667 | static SENSOR_DEVICE_ATTR(pwm1_auto_point11_pwm, S_IRUGO, show_pwm1, NULL, 11); | ||
668 | static SENSOR_DEVICE_ATTR(pwm1_auto_point11_temp, S_IRUGO, | ||
669 | show_lut_temp, NULL, 13); | ||
670 | static SENSOR_DEVICE_ATTR(pwm1_auto_point11_temp_hyst, S_IRUGO, | ||
671 | show_lut_temp_hyst, NULL, 13); | ||
672 | static SENSOR_DEVICE_ATTR(pwm1_auto_point12_pwm, S_IRUGO, show_pwm1, NULL, 12); | ||
673 | static SENSOR_DEVICE_ATTR(pwm1_auto_point12_temp, S_IRUGO, | ||
674 | show_lut_temp, NULL, 14); | ||
675 | static SENSOR_DEVICE_ATTR(pwm1_auto_point12_temp_hyst, S_IRUGO, | ||
676 | show_lut_temp_hyst, NULL, 14); | ||
656 | 677 | ||
657 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_local_temp8, NULL, 0); | 678 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_local_temp8, NULL, 0); |
658 | static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_local_temp8, | 679 | static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_local_temp8, |
659 | set_temp8, 1); | 680 | set_temp8, 1); |
660 | 681 | ||
661 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0); | 682 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0); |
662 | static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp11, | 683 | static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp11, |
663 | set_temp11, 1); | 684 | set_temp11, 1); |
664 | static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp11, | 685 | static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp11, |
665 | set_temp11, 2); | 686 | set_temp11, 2); |
666 | static SENSOR_DEVICE_ATTR(temp2_offset, S_IWUSR | S_IRUGO, show_temp11, | 687 | static SENSOR_DEVICE_ATTR(temp2_offset, S_IWUSR | S_IRUGO, show_temp11, |
667 | set_temp11, 3); | 688 | set_temp11, 3); |
668 | static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, show_remote_temp8, | 689 | static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, show_remote_temp8, |
669 | set_temp8, 2); | 690 | set_temp8, 2); |
670 | static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp2_crit_hyst, | 691 | static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp2_crit_hyst, |
671 | set_temp2_crit_hyst); | 692 | set_temp2_crit_hyst); |
672 | 693 | ||
673 | static DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type, set_type); | 694 | static DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type, set_type); |
674 | 695 | ||
675 | /* Individual alarm files */ | 696 | /* Individual alarm files */ |
676 | static SENSOR_DEVICE_ATTR(fan1_min_alarm, S_IRUGO, show_alarm, NULL, 0); | 697 | static SENSOR_DEVICE_ATTR(fan1_min_alarm, S_IRUGO, show_alarm, NULL, 0); |
677 | static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1); | 698 | static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1); |
678 | static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2); | 699 | static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2); |
679 | static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3); | 700 | static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3); |
680 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); | 701 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); |
681 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); | 702 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); |
682 | /* Raw alarm file for compatibility */ | 703 | /* Raw alarm file for compatibility */ |
683 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); | 704 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
684 | 705 | ||
685 | static DEVICE_ATTR(update_interval, S_IRUGO | S_IWUSR, show_update_interval, | 706 | static DEVICE_ATTR(update_interval, S_IRUGO | S_IWUSR, show_update_interval, |
686 | set_update_interval); | 707 | set_update_interval); |
687 | 708 | ||
688 | static struct attribute *lm63_attributes[] = { | 709 | static struct attribute *lm63_attributes[] = { |
689 | &sensor_dev_attr_pwm1.dev_attr.attr, | 710 | &sensor_dev_attr_pwm1.dev_attr.attr, |
690 | &dev_attr_pwm1_enable.attr, | 711 | &dev_attr_pwm1_enable.attr, |
691 | &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, | 712 | &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, |
692 | &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr, | 713 | &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr, |
693 | &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr, | 714 | &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr, |
694 | &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr, | 715 | &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr, |
695 | &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr, | 716 | &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr, |
696 | &sensor_dev_attr_pwm1_auto_point2_temp_hyst.dev_attr.attr, | 717 | &sensor_dev_attr_pwm1_auto_point2_temp_hyst.dev_attr.attr, |
697 | &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr, | 718 | &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr, |
698 | &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr, | 719 | &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr, |
699 | &sensor_dev_attr_pwm1_auto_point3_temp_hyst.dev_attr.attr, | 720 | &sensor_dev_attr_pwm1_auto_point3_temp_hyst.dev_attr.attr, |
700 | &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr, | 721 | &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr, |
701 | &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr, | 722 | &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr, |
702 | &sensor_dev_attr_pwm1_auto_point4_temp_hyst.dev_attr.attr, | 723 | &sensor_dev_attr_pwm1_auto_point4_temp_hyst.dev_attr.attr, |
703 | &sensor_dev_attr_pwm1_auto_point5_pwm.dev_attr.attr, | 724 | &sensor_dev_attr_pwm1_auto_point5_pwm.dev_attr.attr, |
704 | &sensor_dev_attr_pwm1_auto_point5_temp.dev_attr.attr, | 725 | &sensor_dev_attr_pwm1_auto_point5_temp.dev_attr.attr, |
705 | &sensor_dev_attr_pwm1_auto_point5_temp_hyst.dev_attr.attr, | 726 | &sensor_dev_attr_pwm1_auto_point5_temp_hyst.dev_attr.attr, |
706 | &sensor_dev_attr_pwm1_auto_point6_pwm.dev_attr.attr, | 727 | &sensor_dev_attr_pwm1_auto_point6_pwm.dev_attr.attr, |
707 | &sensor_dev_attr_pwm1_auto_point6_temp.dev_attr.attr, | 728 | &sensor_dev_attr_pwm1_auto_point6_temp.dev_attr.attr, |
708 | &sensor_dev_attr_pwm1_auto_point6_temp_hyst.dev_attr.attr, | 729 | &sensor_dev_attr_pwm1_auto_point6_temp_hyst.dev_attr.attr, |
709 | &sensor_dev_attr_pwm1_auto_point7_pwm.dev_attr.attr, | 730 | &sensor_dev_attr_pwm1_auto_point7_pwm.dev_attr.attr, |
710 | &sensor_dev_attr_pwm1_auto_point7_temp.dev_attr.attr, | 731 | &sensor_dev_attr_pwm1_auto_point7_temp.dev_attr.attr, |
711 | &sensor_dev_attr_pwm1_auto_point7_temp_hyst.dev_attr.attr, | 732 | &sensor_dev_attr_pwm1_auto_point7_temp_hyst.dev_attr.attr, |
712 | &sensor_dev_attr_pwm1_auto_point8_pwm.dev_attr.attr, | 733 | &sensor_dev_attr_pwm1_auto_point8_pwm.dev_attr.attr, |
713 | &sensor_dev_attr_pwm1_auto_point8_temp.dev_attr.attr, | 734 | &sensor_dev_attr_pwm1_auto_point8_temp.dev_attr.attr, |
714 | &sensor_dev_attr_pwm1_auto_point8_temp_hyst.dev_attr.attr, | 735 | &sensor_dev_attr_pwm1_auto_point8_temp_hyst.dev_attr.attr, |
715 | 736 | ||
716 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 737 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
717 | &sensor_dev_attr_temp2_input.dev_attr.attr, | 738 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
718 | &sensor_dev_attr_temp2_min.dev_attr.attr, | 739 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
719 | &sensor_dev_attr_temp1_max.dev_attr.attr, | 740 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
720 | &sensor_dev_attr_temp2_max.dev_attr.attr, | 741 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
721 | &sensor_dev_attr_temp2_offset.dev_attr.attr, | 742 | &sensor_dev_attr_temp2_offset.dev_attr.attr, |
722 | &sensor_dev_attr_temp2_crit.dev_attr.attr, | 743 | &sensor_dev_attr_temp2_crit.dev_attr.attr, |
723 | &dev_attr_temp2_crit_hyst.attr, | 744 | &dev_attr_temp2_crit_hyst.attr, |
724 | 745 | ||
725 | &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, | 746 | &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, |
726 | &sensor_dev_attr_temp2_fault.dev_attr.attr, | 747 | &sensor_dev_attr_temp2_fault.dev_attr.attr, |
727 | &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, | 748 | &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, |
728 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, | 749 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, |
729 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, | 750 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, |
730 | &dev_attr_alarms.attr, | 751 | &dev_attr_alarms.attr, |
731 | &dev_attr_update_interval.attr, | 752 | &dev_attr_update_interval.attr, |
732 | NULL | 753 | NULL |
733 | }; | 754 | }; |
734 | 755 | ||
756 | static struct attribute *lm63_attributes_extra_lut[] = { | ||
757 | &sensor_dev_attr_pwm1_auto_point9_pwm.dev_attr.attr, | ||
758 | &sensor_dev_attr_pwm1_auto_point9_temp.dev_attr.attr, | ||
759 | &sensor_dev_attr_pwm1_auto_point9_temp_hyst.dev_attr.attr, | ||
760 | &sensor_dev_attr_pwm1_auto_point10_pwm.dev_attr.attr, | ||
761 | &sensor_dev_attr_pwm1_auto_point10_temp.dev_attr.attr, | ||
762 | &sensor_dev_attr_pwm1_auto_point10_temp_hyst.dev_attr.attr, | ||
763 | &sensor_dev_attr_pwm1_auto_point11_pwm.dev_attr.attr, | ||
764 | &sensor_dev_attr_pwm1_auto_point11_temp.dev_attr.attr, | ||
765 | &sensor_dev_attr_pwm1_auto_point11_temp_hyst.dev_attr.attr, | ||
766 | &sensor_dev_attr_pwm1_auto_point12_pwm.dev_attr.attr, | ||
767 | &sensor_dev_attr_pwm1_auto_point12_temp.dev_attr.attr, | ||
768 | &sensor_dev_attr_pwm1_auto_point12_temp_hyst.dev_attr.attr, | ||
769 | NULL | ||
770 | }; | ||
771 | |||
772 | static const struct attribute_group lm63_group_extra_lut = { | ||
773 | .attrs = lm63_attributes_extra_lut, | ||
774 | }; | ||
775 | |||
735 | /* | 776 | /* |
736 | * On LM63, temp2_crit can be set only once, which should be job | 777 | * On LM63, temp2_crit can be set only once, which should be job |
737 | * of the bootloader. | 778 | * of the bootloader. |
738 | * On LM64, temp2_crit can always be set. | 779 | * On LM64, temp2_crit can always be set. |
739 | * On LM96163, temp2_crit can be set if bit 1 of the configuration | 780 | * On LM96163, temp2_crit can be set if bit 1 of the configuration |
740 | * register is true. | 781 | * register is true. |
741 | */ | 782 | */ |
742 | static umode_t lm63_attribute_mode(struct kobject *kobj, | 783 | static umode_t lm63_attribute_mode(struct kobject *kobj, |
743 | struct attribute *attr, int index) | 784 | struct attribute *attr, int index) |
744 | { | 785 | { |
745 | struct device *dev = container_of(kobj, struct device, kobj); | 786 | struct device *dev = container_of(kobj, struct device, kobj); |
746 | struct i2c_client *client = to_i2c_client(dev); | 787 | struct i2c_client *client = to_i2c_client(dev); |
747 | struct lm63_data *data = i2c_get_clientdata(client); | 788 | struct lm63_data *data = i2c_get_clientdata(client); |
748 | 789 | ||
749 | if (attr == &sensor_dev_attr_temp2_crit.dev_attr.attr | 790 | if (attr == &sensor_dev_attr_temp2_crit.dev_attr.attr |
750 | && (data->kind == lm64 || | 791 | && (data->kind == lm64 || |
751 | (data->kind == lm96163 && (data->config & 0x02)))) | 792 | (data->kind == lm96163 && (data->config & 0x02)))) |
752 | return attr->mode | S_IWUSR; | 793 | return attr->mode | S_IWUSR; |
753 | 794 | ||
754 | return attr->mode; | 795 | return attr->mode; |
755 | } | 796 | } |
756 | 797 | ||
757 | static const struct attribute_group lm63_group = { | 798 | static const struct attribute_group lm63_group = { |
758 | .is_visible = lm63_attribute_mode, | 799 | .is_visible = lm63_attribute_mode, |
759 | .attrs = lm63_attributes, | 800 | .attrs = lm63_attributes, |
760 | }; | 801 | }; |
761 | 802 | ||
762 | static struct attribute *lm63_attributes_fan1[] = { | 803 | static struct attribute *lm63_attributes_fan1[] = { |
763 | &sensor_dev_attr_fan1_input.dev_attr.attr, | 804 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
764 | &sensor_dev_attr_fan1_min.dev_attr.attr, | 805 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
765 | 806 | ||
766 | &sensor_dev_attr_fan1_min_alarm.dev_attr.attr, | 807 | &sensor_dev_attr_fan1_min_alarm.dev_attr.attr, |
767 | NULL | 808 | NULL |
768 | }; | 809 | }; |
769 | 810 | ||
770 | static const struct attribute_group lm63_group_fan1 = { | 811 | static const struct attribute_group lm63_group_fan1 = { |
771 | .attrs = lm63_attributes_fan1, | 812 | .attrs = lm63_attributes_fan1, |
772 | }; | 813 | }; |
773 | 814 | ||
774 | /* | 815 | /* |
775 | * Real code | 816 | * Real code |
776 | */ | 817 | */ |
777 | 818 | ||
778 | /* Return 0 if detection is successful, -ENODEV otherwise */ | 819 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
779 | static int lm63_detect(struct i2c_client *new_client, | 820 | static int lm63_detect(struct i2c_client *new_client, |
780 | struct i2c_board_info *info) | 821 | struct i2c_board_info *info) |
781 | { | 822 | { |
782 | struct i2c_adapter *adapter = new_client->adapter; | 823 | struct i2c_adapter *adapter = new_client->adapter; |
783 | u8 man_id, chip_id, reg_config1, reg_config2; | 824 | u8 man_id, chip_id, reg_config1, reg_config2; |
784 | u8 reg_alert_status, reg_alert_mask; | 825 | u8 reg_alert_status, reg_alert_mask; |
785 | int address = new_client->addr; | 826 | int address = new_client->addr; |
786 | 827 | ||
787 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 828 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
788 | return -ENODEV; | 829 | return -ENODEV; |
789 | 830 | ||
790 | man_id = i2c_smbus_read_byte_data(new_client, LM63_REG_MAN_ID); | 831 | man_id = i2c_smbus_read_byte_data(new_client, LM63_REG_MAN_ID); |
791 | chip_id = i2c_smbus_read_byte_data(new_client, LM63_REG_CHIP_ID); | 832 | chip_id = i2c_smbus_read_byte_data(new_client, LM63_REG_CHIP_ID); |
792 | 833 | ||
793 | reg_config1 = i2c_smbus_read_byte_data(new_client, | 834 | reg_config1 = i2c_smbus_read_byte_data(new_client, |
794 | LM63_REG_CONFIG1); | 835 | LM63_REG_CONFIG1); |
795 | reg_config2 = i2c_smbus_read_byte_data(new_client, | 836 | reg_config2 = i2c_smbus_read_byte_data(new_client, |
796 | LM63_REG_CONFIG2); | 837 | LM63_REG_CONFIG2); |
797 | reg_alert_status = i2c_smbus_read_byte_data(new_client, | 838 | reg_alert_status = i2c_smbus_read_byte_data(new_client, |
798 | LM63_REG_ALERT_STATUS); | 839 | LM63_REG_ALERT_STATUS); |
799 | reg_alert_mask = i2c_smbus_read_byte_data(new_client, | 840 | reg_alert_mask = i2c_smbus_read_byte_data(new_client, |
800 | LM63_REG_ALERT_MASK); | 841 | LM63_REG_ALERT_MASK); |
801 | 842 | ||
802 | if (man_id != 0x01 /* National Semiconductor */ | 843 | if (man_id != 0x01 /* National Semiconductor */ |
803 | || (reg_config1 & 0x18) != 0x00 | 844 | || (reg_config1 & 0x18) != 0x00 |
804 | || (reg_config2 & 0xF8) != 0x00 | 845 | || (reg_config2 & 0xF8) != 0x00 |
805 | || (reg_alert_status & 0x20) != 0x00 | 846 | || (reg_alert_status & 0x20) != 0x00 |
806 | || (reg_alert_mask & 0xA4) != 0xA4) { | 847 | || (reg_alert_mask & 0xA4) != 0xA4) { |
807 | dev_dbg(&adapter->dev, | 848 | dev_dbg(&adapter->dev, |
808 | "Unsupported chip (man_id=0x%02X, chip_id=0x%02X)\n", | 849 | "Unsupported chip (man_id=0x%02X, chip_id=0x%02X)\n", |
809 | man_id, chip_id); | 850 | man_id, chip_id); |
810 | return -ENODEV; | 851 | return -ENODEV; |
811 | } | 852 | } |
812 | 853 | ||
813 | if (chip_id == 0x41 && address == 0x4c) | 854 | if (chip_id == 0x41 && address == 0x4c) |
814 | strlcpy(info->type, "lm63", I2C_NAME_SIZE); | 855 | strlcpy(info->type, "lm63", I2C_NAME_SIZE); |
815 | else if (chip_id == 0x51 && (address == 0x18 || address == 0x4e)) | 856 | else if (chip_id == 0x51 && (address == 0x18 || address == 0x4e)) |
816 | strlcpy(info->type, "lm64", I2C_NAME_SIZE); | 857 | strlcpy(info->type, "lm64", I2C_NAME_SIZE); |
817 | else if (chip_id == 0x49 && address == 0x4c) | 858 | else if (chip_id == 0x49 && address == 0x4c) |
818 | strlcpy(info->type, "lm96163", I2C_NAME_SIZE); | 859 | strlcpy(info->type, "lm96163", I2C_NAME_SIZE); |
819 | else | 860 | else |
820 | return -ENODEV; | 861 | return -ENODEV; |
821 | 862 | ||
822 | return 0; | 863 | return 0; |
823 | } | 864 | } |
824 | 865 | ||
825 | static int lm63_probe(struct i2c_client *new_client, | 866 | static int lm63_probe(struct i2c_client *new_client, |
826 | const struct i2c_device_id *id) | 867 | const struct i2c_device_id *id) |
827 | { | 868 | { |
828 | struct lm63_data *data; | 869 | struct lm63_data *data; |
829 | int err; | 870 | int err; |
830 | 871 | ||
831 | data = kzalloc(sizeof(struct lm63_data), GFP_KERNEL); | 872 | data = kzalloc(sizeof(struct lm63_data), GFP_KERNEL); |
832 | if (!data) { | 873 | if (!data) { |
833 | err = -ENOMEM; | 874 | err = -ENOMEM; |
834 | goto exit; | 875 | goto exit; |
835 | } | 876 | } |
836 | 877 | ||
837 | i2c_set_clientdata(new_client, data); | 878 | i2c_set_clientdata(new_client, data); |
838 | data->valid = 0; | 879 | data->valid = 0; |
839 | mutex_init(&data->update_lock); | 880 | mutex_init(&data->update_lock); |
840 | 881 | ||
841 | /* Set the device type */ | 882 | /* Set the device type */ |
842 | data->kind = id->driver_data; | 883 | data->kind = id->driver_data; |
843 | if (data->kind == lm64) | 884 | if (data->kind == lm64) |
844 | data->temp2_offset = 16000; | 885 | data->temp2_offset = 16000; |
845 | 886 | ||
846 | /* Initialize chip */ | 887 | /* Initialize chip */ |
847 | lm63_init_client(new_client); | 888 | lm63_init_client(new_client); |
848 | 889 | ||
849 | /* Register sysfs hooks */ | 890 | /* Register sysfs hooks */ |
850 | err = sysfs_create_group(&new_client->dev.kobj, &lm63_group); | 891 | err = sysfs_create_group(&new_client->dev.kobj, &lm63_group); |
851 | if (err) | 892 | if (err) |
852 | goto exit_free; | 893 | goto exit_free; |
853 | if (data->config & 0x04) { /* tachometer enabled */ | 894 | if (data->config & 0x04) { /* tachometer enabled */ |
854 | err = sysfs_create_group(&new_client->dev.kobj, | 895 | err = sysfs_create_group(&new_client->dev.kobj, |
855 | &lm63_group_fan1); | 896 | &lm63_group_fan1); |
856 | if (err) | 897 | if (err) |
857 | goto exit_remove_files; | 898 | goto exit_remove_files; |
858 | } | 899 | } |
859 | if (data->kind == lm96163) { | 900 | if (data->kind == lm96163) { |
860 | err = device_create_file(&new_client->dev, | 901 | err = device_create_file(&new_client->dev, |
861 | &dev_attr_temp2_type); | 902 | &dev_attr_temp2_type); |
862 | if (err) | 903 | if (err) |
863 | goto exit_remove_files; | 904 | goto exit_remove_files; |
905 | |||
906 | err = sysfs_create_group(&new_client->dev.kobj, | ||
907 | &lm63_group_extra_lut); | ||
908 | if (err) | ||
909 | goto exit_remove_files; | ||
864 | } | 910 | } |
865 | 911 | ||
866 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | 912 | data->hwmon_dev = hwmon_device_register(&new_client->dev); |
867 | if (IS_ERR(data->hwmon_dev)) { | 913 | if (IS_ERR(data->hwmon_dev)) { |
868 | err = PTR_ERR(data->hwmon_dev); | 914 | err = PTR_ERR(data->hwmon_dev); |
869 | goto exit_remove_files; | 915 | goto exit_remove_files; |
870 | } | 916 | } |
871 | 917 | ||
872 | return 0; | 918 | return 0; |
873 | 919 | ||
874 | exit_remove_files: | 920 | exit_remove_files: |
875 | device_remove_file(&new_client->dev, &dev_attr_temp2_type); | ||
876 | sysfs_remove_group(&new_client->dev.kobj, &lm63_group); | 921 | sysfs_remove_group(&new_client->dev.kobj, &lm63_group); |
877 | sysfs_remove_group(&new_client->dev.kobj, &lm63_group_fan1); | 922 | sysfs_remove_group(&new_client->dev.kobj, &lm63_group_fan1); |
923 | if (data->kind == lm96163) { | ||
924 | device_remove_file(&new_client->dev, &dev_attr_temp2_type); | ||
925 | sysfs_remove_group(&new_client->dev.kobj, | ||
926 | &lm63_group_extra_lut); | ||
927 | } | ||
878 | exit_free: | 928 | exit_free: |
879 | kfree(data); | 929 | kfree(data); |
880 | exit: | 930 | exit: |
881 | return err; | 931 | return err; |
882 | } | 932 | } |
883 | 933 | ||
884 | /* | 934 | /* |
885 | * Ideally we shouldn't have to initialize anything, since the BIOS | 935 | * Ideally we shouldn't have to initialize anything, since the BIOS |
886 | * should have taken care of everything | 936 | * should have taken care of everything |
887 | */ | 937 | */ |
888 | static void lm63_init_client(struct i2c_client *client) | 938 | static void lm63_init_client(struct i2c_client *client) |
889 | { | 939 | { |
890 | struct lm63_data *data = i2c_get_clientdata(client); | 940 | struct lm63_data *data = i2c_get_clientdata(client); |
891 | u8 convrate; | 941 | u8 convrate; |
892 | 942 | ||
893 | data->config = i2c_smbus_read_byte_data(client, LM63_REG_CONFIG1); | 943 | data->config = i2c_smbus_read_byte_data(client, LM63_REG_CONFIG1); |
894 | data->config_fan = i2c_smbus_read_byte_data(client, | 944 | data->config_fan = i2c_smbus_read_byte_data(client, |
895 | LM63_REG_CONFIG_FAN); | 945 | LM63_REG_CONFIG_FAN); |
896 | 946 | ||
897 | /* Start converting if needed */ | 947 | /* Start converting if needed */ |
898 | if (data->config & 0x40) { /* standby */ | 948 | if (data->config & 0x40) { /* standby */ |
899 | dev_dbg(&client->dev, "Switching to operational mode\n"); | 949 | dev_dbg(&client->dev, "Switching to operational mode\n"); |
900 | data->config &= 0xA7; | 950 | data->config &= 0xA7; |
901 | i2c_smbus_write_byte_data(client, LM63_REG_CONFIG1, | 951 | i2c_smbus_write_byte_data(client, LM63_REG_CONFIG1, |
902 | data->config); | 952 | data->config); |
903 | } | 953 | } |
904 | /* Tachometer is always enabled on LM64 */ | 954 | /* Tachometer is always enabled on LM64 */ |
905 | if (data->kind == lm64) | 955 | if (data->kind == lm64) |
906 | data->config |= 0x04; | 956 | data->config |= 0x04; |
907 | 957 | ||
908 | /* We may need pwm1_freq before ever updating the client data */ | 958 | /* We may need pwm1_freq before ever updating the client data */ |
909 | data->pwm1_freq = i2c_smbus_read_byte_data(client, LM63_REG_PWM_FREQ); | 959 | data->pwm1_freq = i2c_smbus_read_byte_data(client, LM63_REG_PWM_FREQ); |
910 | if (data->pwm1_freq == 0) | 960 | if (data->pwm1_freq == 0) |
911 | data->pwm1_freq = 1; | 961 | data->pwm1_freq = 1; |
912 | 962 | ||
913 | switch (data->kind) { | 963 | switch (data->kind) { |
914 | case lm63: | 964 | case lm63: |
915 | case lm64: | 965 | case lm64: |
916 | data->max_convrate_hz = LM63_MAX_CONVRATE_HZ; | 966 | data->max_convrate_hz = LM63_MAX_CONVRATE_HZ; |
967 | data->lut_size = 8; | ||
917 | break; | 968 | break; |
918 | case lm96163: | 969 | case lm96163: |
919 | data->max_convrate_hz = LM96163_MAX_CONVRATE_HZ; | 970 | data->max_convrate_hz = LM96163_MAX_CONVRATE_HZ; |
971 | data->lut_size = 12; | ||
920 | data->trutherm | 972 | data->trutherm |
921 | = i2c_smbus_read_byte_data(client, | 973 | = i2c_smbus_read_byte_data(client, |
922 | LM96163_REG_TRUTHERM) & 0x02; | 974 | LM96163_REG_TRUTHERM) & 0x02; |
923 | break; | 975 | break; |
924 | } | 976 | } |
925 | convrate = i2c_smbus_read_byte_data(client, LM63_REG_CONVRATE); | 977 | convrate = i2c_smbus_read_byte_data(client, LM63_REG_CONVRATE); |
926 | if (unlikely(convrate > LM63_MAX_CONVRATE)) | 978 | if (unlikely(convrate > LM63_MAX_CONVRATE)) |
927 | convrate = LM63_MAX_CONVRATE; | 979 | convrate = LM63_MAX_CONVRATE; |
928 | data->update_interval = UPDATE_INTERVAL(data->max_convrate_hz, | 980 | data->update_interval = UPDATE_INTERVAL(data->max_convrate_hz, |
929 | convrate); | 981 | convrate); |
930 | 982 | ||
931 | /* | 983 | /* |
932 | * For LM96163, check if high resolution PWM | 984 | * For LM96163, check if high resolution PWM |
933 | * and unsigned temperature format is enabled. | 985 | * and unsigned temperature format is enabled. |
934 | */ | 986 | */ |
935 | if (data->kind == lm96163) { | 987 | if (data->kind == lm96163) { |
936 | u8 config_enhanced | 988 | u8 config_enhanced |
937 | = i2c_smbus_read_byte_data(client, | 989 | = i2c_smbus_read_byte_data(client, |
938 | LM96163_REG_CONFIG_ENHANCED); | 990 | LM96163_REG_CONFIG_ENHANCED); |
939 | if (config_enhanced & 0x20) | 991 | if (config_enhanced & 0x20) |
940 | data->lut_temp_highres = true; | 992 | data->lut_temp_highres = true; |
941 | if ((config_enhanced & 0x10) | 993 | if ((config_enhanced & 0x10) |
942 | && !(data->config_fan & 0x08) && data->pwm1_freq == 8) | 994 | && !(data->config_fan & 0x08) && data->pwm1_freq == 8) |
943 | data->pwm_highres = true; | 995 | data->pwm_highres = true; |
944 | if (config_enhanced & 0x08) | 996 | if (config_enhanced & 0x08) |
945 | data->remote_unsigned = true; | 997 | data->remote_unsigned = true; |
946 | } | 998 | } |
947 | 999 | ||
948 | /* Show some debug info about the LM63 configuration */ | 1000 | /* Show some debug info about the LM63 configuration */ |
949 | if (data->kind == lm63) | 1001 | if (data->kind == lm63) |
950 | dev_dbg(&client->dev, "Alert/tach pin configured for %s\n", | 1002 | dev_dbg(&client->dev, "Alert/tach pin configured for %s\n", |
951 | (data->config & 0x04) ? "tachometer input" : | 1003 | (data->config & 0x04) ? "tachometer input" : |
952 | "alert output"); | 1004 | "alert output"); |
953 | dev_dbg(&client->dev, "PWM clock %s kHz, output frequency %u Hz\n", | 1005 | dev_dbg(&client->dev, "PWM clock %s kHz, output frequency %u Hz\n", |
954 | (data->config_fan & 0x08) ? "1.4" : "360", | 1006 | (data->config_fan & 0x08) ? "1.4" : "360", |
955 | ((data->config_fan & 0x08) ? 700 : 180000) / data->pwm1_freq); | 1007 | ((data->config_fan & 0x08) ? 700 : 180000) / data->pwm1_freq); |
956 | dev_dbg(&client->dev, "PWM output active %s, %s mode\n", | 1008 | dev_dbg(&client->dev, "PWM output active %s, %s mode\n", |
957 | (data->config_fan & 0x10) ? "low" : "high", | 1009 | (data->config_fan & 0x10) ? "low" : "high", |
958 | (data->config_fan & 0x20) ? "manual" : "auto"); | 1010 | (data->config_fan & 0x20) ? "manual" : "auto"); |
959 | } | 1011 | } |
960 | 1012 | ||
961 | static int lm63_remove(struct i2c_client *client) | 1013 | static int lm63_remove(struct i2c_client *client) |
962 | { | 1014 | { |
963 | struct lm63_data *data = i2c_get_clientdata(client); | 1015 | struct lm63_data *data = i2c_get_clientdata(client); |
964 | 1016 | ||
965 | hwmon_device_unregister(data->hwmon_dev); | 1017 | hwmon_device_unregister(data->hwmon_dev); |
966 | device_remove_file(&client->dev, &dev_attr_temp2_type); | ||
967 | sysfs_remove_group(&client->dev.kobj, &lm63_group); | 1018 | sysfs_remove_group(&client->dev.kobj, &lm63_group); |
968 | sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1); | 1019 | sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1); |
1020 | if (data->kind == lm96163) { | ||
1021 | device_remove_file(&client->dev, &dev_attr_temp2_type); | ||
1022 | sysfs_remove_group(&client->dev.kobj, &lm63_group_extra_lut); | ||
1023 | } | ||
969 | 1024 | ||
970 | kfree(data); | 1025 | kfree(data); |
971 | return 0; | 1026 | return 0; |
972 | } | 1027 | } |
973 | 1028 | ||
974 | static struct lm63_data *lm63_update_device(struct device *dev) | 1029 | static struct lm63_data *lm63_update_device(struct device *dev) |
975 | { | 1030 | { |
976 | struct i2c_client *client = to_i2c_client(dev); | 1031 | struct i2c_client *client = to_i2c_client(dev); |
977 | struct lm63_data *data = i2c_get_clientdata(client); | 1032 | struct lm63_data *data = i2c_get_clientdata(client); |
978 | unsigned long next_update; | 1033 | unsigned long next_update; |
979 | int i; | 1034 | int i; |
980 | 1035 | ||
981 | mutex_lock(&data->update_lock); | 1036 | mutex_lock(&data->update_lock); |
982 | 1037 | ||
983 | next_update = data->last_updated | 1038 | next_update = data->last_updated |
984 | + msecs_to_jiffies(data->update_interval) + 1; | 1039 | + msecs_to_jiffies(data->update_interval) + 1; |
985 | 1040 | ||
986 | if (time_after(jiffies, next_update) || !data->valid) { | 1041 | if (time_after(jiffies, next_update) || !data->valid) { |
987 | if (data->config & 0x04) { /* tachometer enabled */ | 1042 | if (data->config & 0x04) { /* tachometer enabled */ |
988 | /* order matters for fan1_input */ | 1043 | /* order matters for fan1_input */ |
989 | data->fan[0] = i2c_smbus_read_byte_data(client, | 1044 | data->fan[0] = i2c_smbus_read_byte_data(client, |
990 | LM63_REG_TACH_COUNT_LSB) & 0xFC; | 1045 | LM63_REG_TACH_COUNT_LSB) & 0xFC; |
991 | data->fan[0] |= i2c_smbus_read_byte_data(client, | 1046 | data->fan[0] |= i2c_smbus_read_byte_data(client, |
992 | LM63_REG_TACH_COUNT_MSB) << 8; | 1047 | LM63_REG_TACH_COUNT_MSB) << 8; |
993 | data->fan[1] = (i2c_smbus_read_byte_data(client, | 1048 | data->fan[1] = (i2c_smbus_read_byte_data(client, |
994 | LM63_REG_TACH_LIMIT_LSB) & 0xFC) | 1049 | LM63_REG_TACH_LIMIT_LSB) & 0xFC) |
995 | | (i2c_smbus_read_byte_data(client, | 1050 | | (i2c_smbus_read_byte_data(client, |
996 | LM63_REG_TACH_LIMIT_MSB) << 8); | 1051 | LM63_REG_TACH_LIMIT_MSB) << 8); |
997 | } | 1052 | } |
998 | 1053 | ||
999 | data->pwm1_freq = i2c_smbus_read_byte_data(client, | 1054 | data->pwm1_freq = i2c_smbus_read_byte_data(client, |
1000 | LM63_REG_PWM_FREQ); | 1055 | LM63_REG_PWM_FREQ); |
1001 | if (data->pwm1_freq == 0) | 1056 | if (data->pwm1_freq == 0) |
1002 | data->pwm1_freq = 1; | 1057 | data->pwm1_freq = 1; |
1003 | data->pwm1[0] = i2c_smbus_read_byte_data(client, | 1058 | data->pwm1[0] = i2c_smbus_read_byte_data(client, |
1004 | LM63_REG_PWM_VALUE); | 1059 | LM63_REG_PWM_VALUE); |
1005 | 1060 | ||
1006 | data->temp8[0] = i2c_smbus_read_byte_data(client, | 1061 | data->temp8[0] = i2c_smbus_read_byte_data(client, |
1007 | LM63_REG_LOCAL_TEMP); | 1062 | LM63_REG_LOCAL_TEMP); |
1008 | data->temp8[1] = i2c_smbus_read_byte_data(client, | 1063 | data->temp8[1] = i2c_smbus_read_byte_data(client, |
1009 | LM63_REG_LOCAL_HIGH); | 1064 | LM63_REG_LOCAL_HIGH); |
1010 | 1065 | ||
1011 | /* order matters for temp2_input */ | 1066 | /* order matters for temp2_input */ |
1012 | data->temp11[0] = i2c_smbus_read_byte_data(client, | 1067 | data->temp11[0] = i2c_smbus_read_byte_data(client, |
1013 | LM63_REG_REMOTE_TEMP_MSB) << 8; | 1068 | LM63_REG_REMOTE_TEMP_MSB) << 8; |
1014 | data->temp11[0] |= i2c_smbus_read_byte_data(client, | 1069 | data->temp11[0] |= i2c_smbus_read_byte_data(client, |
1015 | LM63_REG_REMOTE_TEMP_LSB); | 1070 | LM63_REG_REMOTE_TEMP_LSB); |
1016 | data->temp11[1] = (i2c_smbus_read_byte_data(client, | 1071 | data->temp11[1] = (i2c_smbus_read_byte_data(client, |
1017 | LM63_REG_REMOTE_LOW_MSB) << 8) | 1072 | LM63_REG_REMOTE_LOW_MSB) << 8) |
1018 | | i2c_smbus_read_byte_data(client, | 1073 | | i2c_smbus_read_byte_data(client, |
1019 | LM63_REG_REMOTE_LOW_LSB); | 1074 | LM63_REG_REMOTE_LOW_LSB); |
1020 | data->temp11[2] = (i2c_smbus_read_byte_data(client, | 1075 | data->temp11[2] = (i2c_smbus_read_byte_data(client, |
1021 | LM63_REG_REMOTE_HIGH_MSB) << 8) | 1076 | LM63_REG_REMOTE_HIGH_MSB) << 8) |
1022 | | i2c_smbus_read_byte_data(client, | 1077 | | i2c_smbus_read_byte_data(client, |
1023 | LM63_REG_REMOTE_HIGH_LSB); | 1078 | LM63_REG_REMOTE_HIGH_LSB); |
1024 | data->temp11[3] = (i2c_smbus_read_byte_data(client, | 1079 | data->temp11[3] = (i2c_smbus_read_byte_data(client, |
1025 | LM63_REG_REMOTE_OFFSET_MSB) << 8) | 1080 | LM63_REG_REMOTE_OFFSET_MSB) << 8) |
1026 | | i2c_smbus_read_byte_data(client, | 1081 | | i2c_smbus_read_byte_data(client, |
1027 | LM63_REG_REMOTE_OFFSET_LSB); | 1082 | LM63_REG_REMOTE_OFFSET_LSB); |
1028 | 1083 | ||
1029 | if (data->kind == lm96163) | 1084 | if (data->kind == lm96163) |
1030 | data->temp11u = (i2c_smbus_read_byte_data(client, | 1085 | data->temp11u = (i2c_smbus_read_byte_data(client, |
1031 | LM96163_REG_REMOTE_TEMP_U_MSB) << 8) | 1086 | LM96163_REG_REMOTE_TEMP_U_MSB) << 8) |
1032 | | i2c_smbus_read_byte_data(client, | 1087 | | i2c_smbus_read_byte_data(client, |
1033 | LM96163_REG_REMOTE_TEMP_U_LSB); | 1088 | LM96163_REG_REMOTE_TEMP_U_LSB); |
1034 | 1089 | ||
1035 | data->temp8[2] = i2c_smbus_read_byte_data(client, | 1090 | data->temp8[2] = i2c_smbus_read_byte_data(client, |
1036 | LM63_REG_REMOTE_TCRIT); | 1091 | LM63_REG_REMOTE_TCRIT); |
1037 | data->temp2_crit_hyst = i2c_smbus_read_byte_data(client, | 1092 | data->temp2_crit_hyst = i2c_smbus_read_byte_data(client, |
1038 | LM63_REG_REMOTE_TCRIT_HYST); | 1093 | LM63_REG_REMOTE_TCRIT_HYST); |
1039 | 1094 | ||
1040 | data->alarms = i2c_smbus_read_byte_data(client, | 1095 | data->alarms = i2c_smbus_read_byte_data(client, |
1041 | LM63_REG_ALERT_STATUS) & 0x7F; | 1096 | LM63_REG_ALERT_STATUS) & 0x7F; |
1042 | 1097 | ||
1043 | data->last_updated = jiffies; | 1098 | data->last_updated = jiffies; |
1044 | data->valid = 1; | 1099 | data->valid = 1; |
1045 | } | 1100 | } |
1046 | 1101 | ||
1047 | if (time_after(jiffies, data->lut_last_updated + 5 * HZ) || | 1102 | if (time_after(jiffies, data->lut_last_updated + 5 * HZ) || |
1048 | !data->lut_valid) { | 1103 | !data->lut_valid) { |
1049 | for (i = 0; i < 8; i++) { | 1104 | for (i = 0; i < data->lut_size; i++) { |
1050 | data->pwm1[1 + i] = i2c_smbus_read_byte_data(client, | 1105 | data->pwm1[1 + i] = i2c_smbus_read_byte_data(client, |
1051 | LM63_REG_LUT_PWM(i)); | 1106 | LM63_REG_LUT_PWM(i)); |
1052 | data->temp8[3 + i] = i2c_smbus_read_byte_data(client, | 1107 | data->temp8[3 + i] = i2c_smbus_read_byte_data(client, |
1053 | LM63_REG_LUT_TEMP(i)); | 1108 | LM63_REG_LUT_TEMP(i)); |
1054 | } | 1109 | } |
1055 | data->lut_temp_hyst = i2c_smbus_read_byte_data(client, | 1110 | data->lut_temp_hyst = i2c_smbus_read_byte_data(client, |
1056 | LM63_REG_LUT_TEMP_HYST); | 1111 | LM63_REG_LUT_TEMP_HYST); |
1057 | 1112 | ||
1058 | data->lut_last_updated = jiffies; | 1113 | data->lut_last_updated = jiffies; |
1059 | data->lut_valid = 1; | 1114 | data->lut_valid = 1; |
1060 | } | 1115 | } |
1061 | 1116 | ||
1062 | mutex_unlock(&data->update_lock); | 1117 | mutex_unlock(&data->update_lock); |
1063 | 1118 | ||
1064 | return data; | 1119 | return data; |
1065 | } | 1120 | } |
1066 | 1121 | ||
1067 | static int __init sensors_lm63_init(void) | 1122 | static int __init sensors_lm63_init(void) |
1068 | { | 1123 | { |
1069 | return i2c_add_driver(&lm63_driver); | 1124 | return i2c_add_driver(&lm63_driver); |
1070 | } | 1125 | } |
1071 | 1126 | ||
1072 | static void __exit sensors_lm63_exit(void) | 1127 | static void __exit sensors_lm63_exit(void) |
1073 | { | 1128 | { |
1074 | i2c_del_driver(&lm63_driver); | 1129 | i2c_del_driver(&lm63_driver); |
1075 | } | 1130 | } |
1076 | 1131 | ||
1077 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); | 1132 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); |
1078 | MODULE_DESCRIPTION("LM63 driver"); | 1133 | MODULE_DESCRIPTION("LM63 driver"); |
1079 | MODULE_LICENSE("GPL"); | 1134 | MODULE_LICENSE("GPL"); |
1080 | 1135 | ||
1081 | module_init(sensors_lm63_init); | 1136 | module_init(sensors_lm63_init); |