diff options
author | Guenter Roeck <linux@roeck-us.net> | 2013-03-28 00:23:10 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2013-04-21 11:26:41 -0400 |
commit | 14f2a6654dd42d60645071de26d17d0bced63a7d (patch) | |
tree | c30b46308280e4a1b99ed72bfc0c4e0edc2140ee /drivers/hwmon/tmp401.c | |
parent | b4e665c78023ee4e4821f8e602e3b403c49ef70f (diff) |
hwmon: (tmp401) Simplification and cleanup
Use two-dimensional array pointing to registers
Merge temperature and limit access functions into a single function
Return error codes from I2C reads
Use DIV_ROUND_CLOSEST for rounding operations and improve rounding
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon/tmp401.c')
-rw-r--r-- | drivers/hwmon/tmp401.c | 371 |
1 files changed, 137 insertions, 234 deletions
diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c index f9c492e35fe4..4d306b29ba71 100644 --- a/drivers/hwmon/tmp401.c +++ b/drivers/hwmon/tmp401.c | |||
@@ -58,21 +58,32 @@ enum chips { tmp401, tmp411, tmp431 }; | |||
58 | #define TMP401_MANUFACTURER_ID_REG 0xFE | 58 | #define TMP401_MANUFACTURER_ID_REG 0xFE |
59 | #define TMP401_DEVICE_ID_REG 0xFF | 59 | #define TMP401_DEVICE_ID_REG 0xFF |
60 | 60 | ||
61 | static const u8 TMP401_TEMP_MSB[2] = { 0x00, 0x01 }; | 61 | static const u8 TMP401_TEMP_MSB_READ[6][2] = { |
62 | static const u8 TMP401_TEMP_LSB[2] = { 0x15, 0x10 }; | 62 | { 0x00, 0x01 }, /* temp */ |
63 | static const u8 TMP401_TEMP_LOW_LIMIT_MSB_READ[2] = { 0x06, 0x08 }; | 63 | { 0x06, 0x08 }, /* low limit */ |
64 | static const u8 TMP401_TEMP_LOW_LIMIT_MSB_WRITE[2] = { 0x0C, 0x0E }; | 64 | { 0x05, 0x07 }, /* high limit */ |
65 | static const u8 TMP401_TEMP_LOW_LIMIT_LSB[2] = { 0x17, 0x14 }; | 65 | { 0x20, 0x19 }, /* therm (crit) limit */ |
66 | static const u8 TMP401_TEMP_HIGH_LIMIT_MSB_READ[2] = { 0x05, 0x07 }; | 66 | { 0x30, 0x34 }, /* lowest */ |
67 | static const u8 TMP401_TEMP_HIGH_LIMIT_MSB_WRITE[2] = { 0x0B, 0x0D }; | 67 | { 0x32, 0x36 }, /* highest */ |
68 | static const u8 TMP401_TEMP_HIGH_LIMIT_LSB[2] = { 0x16, 0x13 }; | 68 | }; |
69 | /* These are called the THERM limit / hysteresis / mask in the datasheet */ | 69 | |
70 | static const u8 TMP401_TEMP_CRIT_LIMIT[2] = { 0x20, 0x19 }; | 70 | static const u8 TMP401_TEMP_MSB_WRITE[6][2] = { |
71 | 71 | { 0, 0 }, /* temp (unused) */ | |
72 | static const u8 TMP411_TEMP_LOWEST_MSB[2] = { 0x30, 0x34 }; | 72 | { 0x0C, 0x0E }, /* low limit */ |
73 | static const u8 TMP411_TEMP_LOWEST_LSB[2] = { 0x31, 0x35 }; | 73 | { 0x0B, 0x0D }, /* high limit */ |
74 | static const u8 TMP411_TEMP_HIGHEST_MSB[2] = { 0x32, 0x36 }; | 74 | { 0x20, 0x19 }, /* therm (crit) limit */ |
75 | static const u8 TMP411_TEMP_HIGHEST_LSB[2] = { 0x33, 0x37 }; | 75 | { 0x30, 0x34 }, /* lowest */ |
76 | { 0x32, 0x36 }, /* highest */ | ||
77 | }; | ||
78 | |||
79 | static const u8 TMP401_TEMP_LSB[6][2] = { | ||
80 | { 0x15, 0x10 }, /* temp */ | ||
81 | { 0x17, 0x14 }, /* low limit */ | ||
82 | { 0x16, 0x13 }, /* high limit */ | ||
83 | { 0, 0 }, /* therm (crit) limit (unused) */ | ||
84 | { 0x31, 0x35 }, /* lowest */ | ||
85 | { 0x33, 0x37 }, /* highest */ | ||
86 | }; | ||
76 | 87 | ||
77 | /* Flags */ | 88 | /* Flags */ |
78 | #define TMP401_CONFIG_RANGE BIT(2) | 89 | #define TMP401_CONFIG_RANGE BIT(2) |
@@ -119,13 +130,8 @@ struct tmp401_data { | |||
119 | /* register values */ | 130 | /* register values */ |
120 | u8 status; | 131 | u8 status; |
121 | u8 config; | 132 | u8 config; |
122 | u16 temp[2]; | 133 | u16 temp[6][2]; |
123 | u16 temp_low[2]; | ||
124 | u16 temp_high[2]; | ||
125 | u8 temp_crit[2]; | ||
126 | u8 temp_crit_hyst; | 134 | u8 temp_crit_hyst; |
127 | u16 temp_lowest[2]; | ||
128 | u16 temp_highest[2]; | ||
129 | }; | 135 | }; |
130 | 136 | ||
131 | /* | 137 | /* |
@@ -139,31 +145,10 @@ static int tmp401_register_to_temp(u16 reg, u8 config) | |||
139 | if (config & TMP401_CONFIG_RANGE) | 145 | if (config & TMP401_CONFIG_RANGE) |
140 | temp -= 64 * 256; | 146 | temp -= 64 * 256; |
141 | 147 | ||
142 | return (temp * 625 + 80) / 160; | 148 | return DIV_ROUND_CLOSEST(temp * 125, 32); |
143 | } | ||
144 | |||
145 | static u16 tmp401_temp_to_register(long temp, u8 config) | ||
146 | { | ||
147 | if (config & TMP401_CONFIG_RANGE) { | ||
148 | temp = clamp_val(temp, -64000, 191000); | ||
149 | temp += 64000; | ||
150 | } else | ||
151 | temp = clamp_val(temp, 0, 127000); | ||
152 | |||
153 | return (temp * 160 + 312) / 625; | ||
154 | } | 149 | } |
155 | 150 | ||
156 | static int tmp401_crit_register_to_temp(u8 reg, u8 config) | 151 | static u16 tmp401_temp_to_register(long temp, u8 config, int zbits) |
157 | { | ||
158 | int temp = reg; | ||
159 | |||
160 | if (config & TMP401_CONFIG_RANGE) | ||
161 | temp -= 64; | ||
162 | |||
163 | return temp * 1000; | ||
164 | } | ||
165 | |||
166 | static u8 tmp401_crit_temp_to_register(long temp, u8 config) | ||
167 | { | 152 | { |
168 | if (config & TMP401_CONFIG_RANGE) { | 153 | if (config & TMP401_CONFIG_RANGE) { |
169 | temp = clamp_val(temp, -64000, 191000); | 154 | temp = clamp_val(temp, -64000, 191000); |
@@ -171,113 +156,93 @@ static u8 tmp401_crit_temp_to_register(long temp, u8 config) | |||
171 | } else | 156 | } else |
172 | temp = clamp_val(temp, 0, 127000); | 157 | temp = clamp_val(temp, 0, 127000); |
173 | 158 | ||
174 | return (temp + 500) / 1000; | 159 | return DIV_ROUND_CLOSEST(temp * (1 << (8 - zbits)), 1000) << zbits; |
175 | } | 160 | } |
176 | 161 | ||
177 | static struct tmp401_data *tmp401_update_device_reg16( | 162 | static int tmp401_update_device_reg16(struct i2c_client *client, |
178 | struct i2c_client *client, struct tmp401_data *data) | 163 | struct tmp401_data *data) |
179 | { | 164 | { |
180 | int i; | 165 | int i, j, val; |
181 | 166 | int num_regs = data->kind == tmp411 ? 6 : 4; | |
182 | for (i = 0; i < 2; i++) { | 167 | |
183 | /* | 168 | for (i = 0; i < 2; i++) { /* local / rem1 */ |
184 | * High byte must be read first immediately followed | 169 | for (j = 0; j < num_regs; j++) { /* temp / low / ... */ |
185 | * by the low byte | 170 | /* |
186 | */ | 171 | * High byte must be read first immediately followed |
187 | data->temp[i] = i2c_smbus_read_byte_data(client, | 172 | * by the low byte |
188 | TMP401_TEMP_MSB[i]) << 8; | 173 | */ |
189 | data->temp[i] |= i2c_smbus_read_byte_data(client, | 174 | val = i2c_smbus_read_byte_data(client, |
190 | TMP401_TEMP_LSB[i]); | 175 | TMP401_TEMP_MSB_READ[j][i]); |
191 | data->temp_low[i] = i2c_smbus_read_byte_data(client, | 176 | if (val < 0) |
192 | TMP401_TEMP_LOW_LIMIT_MSB_READ[i]) << 8; | 177 | return val; |
193 | data->temp_low[i] |= i2c_smbus_read_byte_data(client, | 178 | data->temp[j][i] = val << 8; |
194 | TMP401_TEMP_LOW_LIMIT_LSB[i]); | 179 | if (j == 3) /* crit is msb only */ |
195 | data->temp_high[i] = i2c_smbus_read_byte_data(client, | 180 | continue; |
196 | TMP401_TEMP_HIGH_LIMIT_MSB_READ[i]) << 8; | 181 | val = i2c_smbus_read_byte_data(client, |
197 | data->temp_high[i] |= i2c_smbus_read_byte_data(client, | 182 | TMP401_TEMP_LSB[j][i]); |
198 | TMP401_TEMP_HIGH_LIMIT_LSB[i]); | 183 | if (val < 0) |
199 | data->temp_crit[i] = i2c_smbus_read_byte_data(client, | 184 | return val; |
200 | TMP401_TEMP_CRIT_LIMIT[i]); | 185 | data->temp[j][i] |= val; |
201 | |||
202 | if (data->kind == tmp411) { | ||
203 | data->temp_lowest[i] = i2c_smbus_read_byte_data(client, | ||
204 | TMP411_TEMP_LOWEST_MSB[i]) << 8; | ||
205 | data->temp_lowest[i] |= i2c_smbus_read_byte_data( | ||
206 | client, TMP411_TEMP_LOWEST_LSB[i]); | ||
207 | |||
208 | data->temp_highest[i] = i2c_smbus_read_byte_data( | ||
209 | client, TMP411_TEMP_HIGHEST_MSB[i]) << 8; | ||
210 | data->temp_highest[i] |= i2c_smbus_read_byte_data( | ||
211 | client, TMP411_TEMP_HIGHEST_LSB[i]); | ||
212 | } | 186 | } |
213 | } | 187 | } |
214 | return data; | 188 | return 0; |
215 | } | 189 | } |
216 | 190 | ||
217 | static struct tmp401_data *tmp401_update_device(struct device *dev) | 191 | static struct tmp401_data *tmp401_update_device(struct device *dev) |
218 | { | 192 | { |
219 | struct i2c_client *client = to_i2c_client(dev); | 193 | struct i2c_client *client = to_i2c_client(dev); |
220 | struct tmp401_data *data = i2c_get_clientdata(client); | 194 | struct tmp401_data *data = i2c_get_clientdata(client); |
195 | struct tmp401_data *ret = data; | ||
196 | int val; | ||
221 | 197 | ||
222 | mutex_lock(&data->update_lock); | 198 | mutex_lock(&data->update_lock); |
223 | 199 | ||
224 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { | 200 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { |
225 | data->status = i2c_smbus_read_byte_data(client, TMP401_STATUS); | 201 | val = i2c_smbus_read_byte_data(client, TMP401_STATUS); |
226 | data->config = i2c_smbus_read_byte_data(client, | 202 | if (val < 0) { |
227 | TMP401_CONFIG_READ); | 203 | ret = ERR_PTR(val); |
228 | tmp401_update_device_reg16(client, data); | 204 | goto abort; |
229 | 205 | } | |
230 | data->temp_crit_hyst = i2c_smbus_read_byte_data(client, | 206 | data->status = val; |
231 | TMP401_TEMP_CRIT_HYST); | 207 | val = i2c_smbus_read_byte_data(client, TMP401_CONFIG_READ); |
208 | if (val < 0) { | ||
209 | ret = ERR_PTR(val); | ||
210 | goto abort; | ||
211 | } | ||
212 | data->config = val; | ||
213 | val = tmp401_update_device_reg16(client, data); | ||
214 | if (val < 0) { | ||
215 | ret = ERR_PTR(val); | ||
216 | goto abort; | ||
217 | } | ||
218 | val = i2c_smbus_read_byte_data(client, TMP401_TEMP_CRIT_HYST); | ||
219 | if (val < 0) { | ||
220 | ret = ERR_PTR(val); | ||
221 | goto abort; | ||
222 | } | ||
223 | data->temp_crit_hyst = val; | ||
232 | 224 | ||
233 | data->last_updated = jiffies; | 225 | data->last_updated = jiffies; |
234 | data->valid = 1; | 226 | data->valid = 1; |
235 | } | 227 | } |
236 | 228 | ||
229 | abort: | ||
237 | mutex_unlock(&data->update_lock); | 230 | mutex_unlock(&data->update_lock); |
238 | 231 | return ret; | |
239 | return data; | ||
240 | } | 232 | } |
241 | 233 | ||
242 | static ssize_t show_temp_value(struct device *dev, | 234 | static ssize_t show_temp(struct device *dev, |
243 | struct device_attribute *devattr, char *buf) | 235 | struct device_attribute *devattr, char *buf) |
244 | { | ||
245 | int index = to_sensor_dev_attr(devattr)->index; | ||
246 | struct tmp401_data *data = tmp401_update_device(dev); | ||
247 | |||
248 | return sprintf(buf, "%d\n", | ||
249 | tmp401_register_to_temp(data->temp[index], data->config)); | ||
250 | } | ||
251 | |||
252 | static ssize_t show_temp_min(struct device *dev, | ||
253 | struct device_attribute *devattr, char *buf) | ||
254 | { | ||
255 | int index = to_sensor_dev_attr(devattr)->index; | ||
256 | struct tmp401_data *data = tmp401_update_device(dev); | ||
257 | |||
258 | return sprintf(buf, "%d\n", | ||
259 | tmp401_register_to_temp(data->temp_low[index], data->config)); | ||
260 | } | ||
261 | |||
262 | static ssize_t show_temp_max(struct device *dev, | ||
263 | struct device_attribute *devattr, char *buf) | ||
264 | { | 236 | { |
265 | int index = to_sensor_dev_attr(devattr)->index; | 237 | int nr = to_sensor_dev_attr_2(devattr)->nr; |
238 | int index = to_sensor_dev_attr_2(devattr)->index; | ||
266 | struct tmp401_data *data = tmp401_update_device(dev); | 239 | struct tmp401_data *data = tmp401_update_device(dev); |
267 | 240 | ||
268 | return sprintf(buf, "%d\n", | 241 | if (IS_ERR(data)) |
269 | tmp401_register_to_temp(data->temp_high[index], data->config)); | 242 | return PTR_ERR(data); |
270 | } | ||
271 | |||
272 | static ssize_t show_temp_crit(struct device *dev, | ||
273 | struct device_attribute *devattr, char *buf) | ||
274 | { | ||
275 | int index = to_sensor_dev_attr(devattr)->index; | ||
276 | struct tmp401_data *data = tmp401_update_device(dev); | ||
277 | 243 | ||
278 | return sprintf(buf, "%d\n", | 244 | return sprintf(buf, "%d\n", |
279 | tmp401_crit_register_to_temp(data->temp_crit[index], | 245 | tmp401_register_to_temp(data->temp[nr][index], data->config)); |
280 | data->config)); | ||
281 | } | 246 | } |
282 | 247 | ||
283 | static ssize_t show_temp_crit_hyst(struct device *dev, | 248 | static ssize_t show_temp_crit_hyst(struct device *dev, |
@@ -286,122 +251,58 @@ static ssize_t show_temp_crit_hyst(struct device *dev, | |||
286 | int temp, index = to_sensor_dev_attr(devattr)->index; | 251 | int temp, index = to_sensor_dev_attr(devattr)->index; |
287 | struct tmp401_data *data = tmp401_update_device(dev); | 252 | struct tmp401_data *data = tmp401_update_device(dev); |
288 | 253 | ||
254 | if (IS_ERR(data)) | ||
255 | return PTR_ERR(data); | ||
256 | |||
289 | mutex_lock(&data->update_lock); | 257 | mutex_lock(&data->update_lock); |
290 | temp = tmp401_crit_register_to_temp(data->temp_crit[index], | 258 | temp = tmp401_register_to_temp(data->temp[3][index], data->config); |
291 | data->config); | ||
292 | temp -= data->temp_crit_hyst * 1000; | 259 | temp -= data->temp_crit_hyst * 1000; |
293 | mutex_unlock(&data->update_lock); | 260 | mutex_unlock(&data->update_lock); |
294 | 261 | ||
295 | return sprintf(buf, "%d\n", temp); | 262 | return sprintf(buf, "%d\n", temp); |
296 | } | 263 | } |
297 | 264 | ||
298 | static ssize_t show_temp_lowest(struct device *dev, | ||
299 | struct device_attribute *devattr, char *buf) | ||
300 | { | ||
301 | int index = to_sensor_dev_attr(devattr)->index; | ||
302 | struct tmp401_data *data = tmp401_update_device(dev); | ||
303 | |||
304 | return sprintf(buf, "%d\n", | ||
305 | tmp401_register_to_temp(data->temp_lowest[index], | ||
306 | data->config)); | ||
307 | } | ||
308 | |||
309 | static ssize_t show_temp_highest(struct device *dev, | ||
310 | struct device_attribute *devattr, char *buf) | ||
311 | { | ||
312 | int index = to_sensor_dev_attr(devattr)->index; | ||
313 | struct tmp401_data *data = tmp401_update_device(dev); | ||
314 | |||
315 | return sprintf(buf, "%d\n", | ||
316 | tmp401_register_to_temp(data->temp_highest[index], | ||
317 | data->config)); | ||
318 | } | ||
319 | |||
320 | static ssize_t show_status(struct device *dev, | 265 | static ssize_t show_status(struct device *dev, |
321 | struct device_attribute *devattr, char *buf) | 266 | struct device_attribute *devattr, char *buf) |
322 | { | 267 | { |
323 | int mask = to_sensor_dev_attr(devattr)->index; | 268 | int mask = to_sensor_dev_attr(devattr)->index; |
324 | struct tmp401_data *data = tmp401_update_device(dev); | 269 | struct tmp401_data *data = tmp401_update_device(dev); |
325 | 270 | ||
326 | if (data->status & mask) | 271 | if (IS_ERR(data)) |
327 | return sprintf(buf, "1\n"); | 272 | return PTR_ERR(data); |
328 | else | ||
329 | return sprintf(buf, "0\n"); | ||
330 | } | ||
331 | |||
332 | static ssize_t store_temp_min(struct device *dev, struct device_attribute | ||
333 | *devattr, const char *buf, size_t count) | ||
334 | { | ||
335 | int index = to_sensor_dev_attr(devattr)->index; | ||
336 | struct tmp401_data *data = tmp401_update_device(dev); | ||
337 | long val; | ||
338 | u16 reg; | ||
339 | |||
340 | if (kstrtol(buf, 10, &val)) | ||
341 | return -EINVAL; | ||
342 | |||
343 | reg = tmp401_temp_to_register(val, data->config); | ||
344 | |||
345 | mutex_lock(&data->update_lock); | ||
346 | |||
347 | i2c_smbus_write_byte_data(to_i2c_client(dev), | ||
348 | TMP401_TEMP_LOW_LIMIT_MSB_WRITE[index], reg >> 8); | ||
349 | i2c_smbus_write_byte_data(to_i2c_client(dev), | ||
350 | TMP401_TEMP_LOW_LIMIT_LSB[index], reg & 0xFF); | ||
351 | |||
352 | data->temp_low[index] = reg; | ||
353 | |||
354 | mutex_unlock(&data->update_lock); | ||
355 | 273 | ||
356 | return count; | 274 | return sprintf(buf, "%d\n", !!(data->status & mask)); |
357 | } | 275 | } |
358 | 276 | ||
359 | static ssize_t store_temp_max(struct device *dev, struct device_attribute | 277 | static ssize_t store_temp(struct device *dev, struct device_attribute *devattr, |
360 | *devattr, const char *buf, size_t count) | 278 | const char *buf, size_t count) |
361 | { | 279 | { |
362 | int index = to_sensor_dev_attr(devattr)->index; | 280 | int nr = to_sensor_dev_attr_2(devattr)->nr; |
281 | int index = to_sensor_dev_attr_2(devattr)->index; | ||
282 | struct i2c_client *client = to_i2c_client(dev); | ||
363 | struct tmp401_data *data = tmp401_update_device(dev); | 283 | struct tmp401_data *data = tmp401_update_device(dev); |
364 | long val; | 284 | long val; |
365 | u16 reg; | 285 | u16 reg; |
366 | 286 | ||
367 | if (kstrtol(buf, 10, &val)) | 287 | if (IS_ERR(data)) |
368 | return -EINVAL; | 288 | return PTR_ERR(data); |
369 | |||
370 | reg = tmp401_temp_to_register(val, data->config); | ||
371 | |||
372 | mutex_lock(&data->update_lock); | ||
373 | |||
374 | i2c_smbus_write_byte_data(to_i2c_client(dev), | ||
375 | TMP401_TEMP_HIGH_LIMIT_MSB_WRITE[index], reg >> 8); | ||
376 | i2c_smbus_write_byte_data(to_i2c_client(dev), | ||
377 | TMP401_TEMP_HIGH_LIMIT_LSB[index], reg & 0xFF); | ||
378 | |||
379 | data->temp_high[index] = reg; | ||
380 | |||
381 | mutex_unlock(&data->update_lock); | ||
382 | |||
383 | return count; | ||
384 | } | ||
385 | |||
386 | static ssize_t store_temp_crit(struct device *dev, struct device_attribute | ||
387 | *devattr, const char *buf, size_t count) | ||
388 | { | ||
389 | int index = to_sensor_dev_attr(devattr)->index; | ||
390 | struct tmp401_data *data = tmp401_update_device(dev); | ||
391 | long val; | ||
392 | u8 reg; | ||
393 | 289 | ||
394 | if (kstrtol(buf, 10, &val)) | 290 | if (kstrtol(buf, 10, &val)) |
395 | return -EINVAL; | 291 | return -EINVAL; |
396 | 292 | ||
397 | reg = tmp401_crit_temp_to_register(val, data->config); | 293 | reg = tmp401_temp_to_register(val, data->config, nr == 3 ? 8 : 4); |
398 | 294 | ||
399 | mutex_lock(&data->update_lock); | 295 | mutex_lock(&data->update_lock); |
400 | 296 | ||
401 | i2c_smbus_write_byte_data(to_i2c_client(dev), | 297 | i2c_smbus_write_byte_data(client, |
402 | TMP401_TEMP_CRIT_LIMIT[index], reg); | 298 | TMP401_TEMP_MSB_WRITE[nr][index], |
403 | 299 | reg >> 8); | |
404 | data->temp_crit[index] = reg; | 300 | if (nr != 3) { |
301 | i2c_smbus_write_byte_data(client, | ||
302 | TMP401_TEMP_LSB[nr][index], | ||
303 | reg & 0xFF); | ||
304 | } | ||
305 | data->temp[nr][index] = reg; | ||
405 | 306 | ||
406 | mutex_unlock(&data->update_lock); | 307 | mutex_unlock(&data->update_lock); |
407 | 308 | ||
@@ -416,6 +317,9 @@ static ssize_t store_temp_crit_hyst(struct device *dev, struct device_attribute | |||
416 | long val; | 317 | long val; |
417 | u8 reg; | 318 | u8 reg; |
418 | 319 | ||
320 | if (IS_ERR(data)) | ||
321 | return PTR_ERR(data); | ||
322 | |||
419 | if (kstrtol(buf, 10, &val)) | 323 | if (kstrtol(buf, 10, &val)) |
420 | return -EINVAL; | 324 | return -EINVAL; |
421 | 325 | ||
@@ -425,13 +329,12 @@ static ssize_t store_temp_crit_hyst(struct device *dev, struct device_attribute | |||
425 | val = clamp_val(val, 0, 127000); | 329 | val = clamp_val(val, 0, 127000); |
426 | 330 | ||
427 | mutex_lock(&data->update_lock); | 331 | mutex_lock(&data->update_lock); |
428 | temp = tmp401_crit_register_to_temp(data->temp_crit[index], | 332 | temp = tmp401_register_to_temp(data->temp[3][index], data->config); |
429 | data->config); | ||
430 | val = clamp_val(val, temp - 255000, temp); | 333 | val = clamp_val(val, temp - 255000, temp); |
431 | reg = ((temp - val) + 500) / 1000; | 334 | reg = ((temp - val) + 500) / 1000; |
432 | 335 | ||
433 | i2c_smbus_write_byte_data(to_i2c_client(dev), | 336 | i2c_smbus_write_byte_data(to_i2c_client(dev), TMP401_TEMP_CRIT_HYST, |
434 | TMP401_TEMP_CRIT_HYST, reg); | 337 | reg); |
435 | 338 | ||
436 | data->temp_crit_hyst = reg; | 339 | data->temp_crit_hyst = reg; |
437 | 340 | ||
@@ -460,18 +363,18 @@ static ssize_t reset_temp_history(struct device *dev, | |||
460 | return -EINVAL; | 363 | return -EINVAL; |
461 | } | 364 | } |
462 | i2c_smbus_write_byte_data(to_i2c_client(dev), | 365 | i2c_smbus_write_byte_data(to_i2c_client(dev), |
463 | TMP411_TEMP_LOWEST_MSB[0], val); | 366 | TMP401_TEMP_MSB_WRITE[5][0], val); |
464 | 367 | ||
465 | return count; | 368 | return count; |
466 | } | 369 | } |
467 | 370 | ||
468 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_value, NULL, 0); | 371 | static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0); |
469 | static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp_min, | 372 | static SENSOR_DEVICE_ATTR_2(temp1_min, S_IWUSR | S_IRUGO, show_temp, |
470 | store_temp_min, 0); | 373 | store_temp, 1, 0); |
471 | static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, | 374 | static SENSOR_DEVICE_ATTR_2(temp1_max, S_IWUSR | S_IRUGO, show_temp, |
472 | store_temp_max, 0); | 375 | store_temp, 2, 0); |
473 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp_crit, | 376 | static SENSOR_DEVICE_ATTR_2(temp1_crit, S_IWUSR | S_IRUGO, show_temp, |
474 | store_temp_crit, 0); | 377 | store_temp, 3, 0); |
475 | static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, | 378 | static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, |
476 | show_temp_crit_hyst, store_temp_crit_hyst, 0); | 379 | show_temp_crit_hyst, store_temp_crit_hyst, 0); |
477 | static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_status, NULL, | 380 | static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_status, NULL, |
@@ -480,13 +383,13 @@ static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_status, NULL, | |||
480 | TMP401_STATUS_LOCAL_HIGH); | 383 | TMP401_STATUS_LOCAL_HIGH); |
481 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_status, NULL, | 384 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_status, NULL, |
482 | TMP401_STATUS_LOCAL_CRIT); | 385 | TMP401_STATUS_LOCAL_CRIT); |
483 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp_value, NULL, 1); | 386 | static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1); |
484 | static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp_min, | 387 | static SENSOR_DEVICE_ATTR_2(temp2_min, S_IWUSR | S_IRUGO, show_temp, |
485 | store_temp_min, 1); | 388 | store_temp, 1, 1); |
486 | static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_max, | 389 | static SENSOR_DEVICE_ATTR_2(temp2_max, S_IWUSR | S_IRUGO, show_temp, |
487 | store_temp_max, 1); | 390 | store_temp, 2, 1); |
488 | static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp_crit, | 391 | static SENSOR_DEVICE_ATTR_2(temp2_crit, S_IWUSR | S_IRUGO, show_temp, |
489 | store_temp_crit, 1); | 392 | store_temp, 3, 1); |
490 | static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, | 393 | static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, |
491 | NULL, 1); | 394 | NULL, 1); |
492 | static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_status, NULL, | 395 | static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_status, NULL, |
@@ -532,10 +435,10 @@ static const struct attribute_group tmp401_group = { | |||
532 | * minimum and maximum register reset for both the local | 435 | * minimum and maximum register reset for both the local |
533 | * and remote channels. | 436 | * and remote channels. |
534 | */ | 437 | */ |
535 | static SENSOR_DEVICE_ATTR(temp1_highest, S_IRUGO, show_temp_highest, NULL, 0); | 438 | static SENSOR_DEVICE_ATTR_2(temp1_lowest, S_IRUGO, show_temp, NULL, 4, 0); |
536 | static SENSOR_DEVICE_ATTR(temp1_lowest, S_IRUGO, show_temp_lowest, NULL, 0); | 439 | static SENSOR_DEVICE_ATTR_2(temp1_highest, S_IRUGO, show_temp, NULL, 5, 0); |
537 | static SENSOR_DEVICE_ATTR(temp2_highest, S_IRUGO, show_temp_highest, NULL, 1); | 440 | static SENSOR_DEVICE_ATTR_2(temp2_lowest, S_IRUGO, show_temp, NULL, 4, 1); |
538 | static SENSOR_DEVICE_ATTR(temp2_lowest, S_IRUGO, show_temp_lowest, NULL, 1); | 441 | static SENSOR_DEVICE_ATTR_2(temp2_highest, S_IRUGO, show_temp, NULL, 5, 1); |
539 | static SENSOR_DEVICE_ATTR(temp_reset_history, S_IWUSR, NULL, reset_temp_history, | 442 | static SENSOR_DEVICE_ATTR(temp_reset_history, S_IWUSR, NULL, reset_temp_history, |
540 | 0); | 443 | 0); |
541 | 444 | ||