diff options
author | Guenter Roeck <guenter.roeck@ericsson.com> | 2010-10-28 14:31:43 -0400 |
---|---|---|
committer | Jean Delvare <khali@endymion.delvare> | 2010-10-28 14:31:43 -0400 |
commit | 15b66ab69051c014d0ba9f46f7081a8a7e6ad1c3 (patch) | |
tree | 70ce3b77f71d5cd340ece365c9331e9604a5bba8 /drivers/hwmon/lm90.c | |
parent | 06e1c0a2167d48442d0bd06373390886670aa6e5 (diff) |
hwmon: (lm90) Rearrange code to no longer require forward declarations
Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon/lm90.c')
-rw-r--r-- | drivers/hwmon/lm90.c | 523 |
1 files changed, 256 insertions, 267 deletions
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 366bb624e655..302d9eb9f275 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c | |||
@@ -164,21 +164,6 @@ enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, max6680, | |||
164 | #define LM90_HAVE_TEMP3 (1 << 6) /* 3rd temperature sensor */ | 164 | #define LM90_HAVE_TEMP3 (1 << 6) /* 3rd temperature sensor */ |
165 | 165 | ||
166 | /* | 166 | /* |
167 | * Functions declaration | ||
168 | */ | ||
169 | |||
170 | static int lm90_detect(struct i2c_client *client, struct i2c_board_info *info); | ||
171 | static int lm90_probe(struct i2c_client *client, | ||
172 | const struct i2c_device_id *id); | ||
173 | static void lm90_init_client(struct i2c_client *client); | ||
174 | static void lm90_alert(struct i2c_client *client, unsigned int flag); | ||
175 | static int lm90_remove(struct i2c_client *client); | ||
176 | static struct lm90_data *lm90_update_device(struct device *dev); | ||
177 | static inline void lm90_select_remote_channel(struct i2c_client *client, | ||
178 | struct lm90_data *data, | ||
179 | int channel); | ||
180 | |||
181 | /* | ||
182 | * Driver data (common to all clients) | 167 | * Driver data (common to all clients) |
183 | */ | 168 | */ |
184 | 169 | ||
@@ -204,19 +189,6 @@ static const struct i2c_device_id lm90_id[] = { | |||
204 | }; | 189 | }; |
205 | MODULE_DEVICE_TABLE(i2c, lm90_id); | 190 | MODULE_DEVICE_TABLE(i2c, lm90_id); |
206 | 191 | ||
207 | static struct i2c_driver lm90_driver = { | ||
208 | .class = I2C_CLASS_HWMON, | ||
209 | .driver = { | ||
210 | .name = "lm90", | ||
211 | }, | ||
212 | .probe = lm90_probe, | ||
213 | .remove = lm90_remove, | ||
214 | .alert = lm90_alert, | ||
215 | .id_table = lm90_id, | ||
216 | .detect = lm90_detect, | ||
217 | .address_list = normal_i2c, | ||
218 | }; | ||
219 | |||
220 | /* | 192 | /* |
221 | * Client data (each client gets its own) | 193 | * Client data (each client gets its own) |
222 | */ | 194 | */ |
@@ -256,6 +228,209 @@ struct lm90_data { | |||
256 | }; | 228 | }; |
257 | 229 | ||
258 | /* | 230 | /* |
231 | * Support functions | ||
232 | */ | ||
233 | |||
234 | /* | ||
235 | * The ADM1032 supports PEC but not on write byte transactions, so we need | ||
236 | * to explicitly ask for a transaction without PEC. | ||
237 | */ | ||
238 | static inline s32 adm1032_write_byte(struct i2c_client *client, u8 value) | ||
239 | { | ||
240 | return i2c_smbus_xfer(client->adapter, client->addr, | ||
241 | client->flags & ~I2C_CLIENT_PEC, | ||
242 | I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL); | ||
243 | } | ||
244 | |||
245 | /* | ||
246 | * It is assumed that client->update_lock is held (unless we are in | ||
247 | * detection or initialization steps). This matters when PEC is enabled, | ||
248 | * because we don't want the address pointer to change between the write | ||
249 | * byte and the read byte transactions. | ||
250 | */ | ||
251 | static int lm90_read_reg(struct i2c_client *client, u8 reg, u8 *value) | ||
252 | { | ||
253 | int err; | ||
254 | |||
255 | if (client->flags & I2C_CLIENT_PEC) { | ||
256 | err = adm1032_write_byte(client, reg); | ||
257 | if (err >= 0) | ||
258 | err = i2c_smbus_read_byte(client); | ||
259 | } else | ||
260 | err = i2c_smbus_read_byte_data(client, reg); | ||
261 | |||
262 | if (err < 0) { | ||
263 | dev_warn(&client->dev, "Register %#02x read failed (%d)\n", | ||
264 | reg, err); | ||
265 | return err; | ||
266 | } | ||
267 | *value = err; | ||
268 | |||
269 | return 0; | ||
270 | } | ||
271 | |||
272 | static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value) | ||
273 | { | ||
274 | int err; | ||
275 | u8 oldh, newh, l; | ||
276 | |||
277 | /* | ||
278 | * There is a trick here. We have to read two registers to have the | ||
279 | * sensor temperature, but we have to beware a conversion could occur | ||
280 | * inbetween the readings. The datasheet says we should either use | ||
281 | * the one-shot conversion register, which we don't want to do | ||
282 | * (disables hardware monitoring) or monitor the busy bit, which is | ||
283 | * impossible (we can't read the values and monitor that bit at the | ||
284 | * exact same time). So the solution used here is to read the high | ||
285 | * byte once, then the low byte, then the high byte again. If the new | ||
286 | * high byte matches the old one, then we have a valid reading. Else | ||
287 | * we have to read the low byte again, and now we believe we have a | ||
288 | * correct reading. | ||
289 | */ | ||
290 | if ((err = lm90_read_reg(client, regh, &oldh)) | ||
291 | || (err = lm90_read_reg(client, regl, &l)) | ||
292 | || (err = lm90_read_reg(client, regh, &newh))) | ||
293 | return err; | ||
294 | if (oldh != newh) { | ||
295 | err = lm90_read_reg(client, regl, &l); | ||
296 | if (err) | ||
297 | return err; | ||
298 | } | ||
299 | *value = (newh << 8) | l; | ||
300 | |||
301 | return 0; | ||
302 | } | ||
303 | |||
304 | /* | ||
305 | * client->update_lock must be held when calling this function (unless we are | ||
306 | * in detection or initialization steps), and while a remote channel other | ||
307 | * than channel 0 is selected. Also, calling code must make sure to re-select | ||
308 | * external channel 0 before releasing the lock. This is necessary because | ||
309 | * various registers have different meanings as a result of selecting a | ||
310 | * non-default remote channel. | ||
311 | */ | ||
312 | static inline void lm90_select_remote_channel(struct i2c_client *client, | ||
313 | struct lm90_data *data, | ||
314 | int channel) | ||
315 | { | ||
316 | u8 config; | ||
317 | |||
318 | if (data->kind == max6696) { | ||
319 | lm90_read_reg(client, LM90_REG_R_CONFIG1, &config); | ||
320 | config &= ~0x08; | ||
321 | if (channel) | ||
322 | config |= 0x08; | ||
323 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, | ||
324 | config); | ||
325 | } | ||
326 | } | ||
327 | |||
328 | static struct lm90_data *lm90_update_device(struct device *dev) | ||
329 | { | ||
330 | struct i2c_client *client = to_i2c_client(dev); | ||
331 | struct lm90_data *data = i2c_get_clientdata(client); | ||
332 | |||
333 | mutex_lock(&data->update_lock); | ||
334 | |||
335 | if (time_after(jiffies, data->last_updated + HZ / 2 + HZ / 10) | ||
336 | || !data->valid) { | ||
337 | u8 h, l; | ||
338 | u8 alarms; | ||
339 | |||
340 | dev_dbg(&client->dev, "Updating lm90 data.\n"); | ||
341 | lm90_read_reg(client, LM90_REG_R_LOCAL_LOW, &data->temp8[0]); | ||
342 | lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH, &data->temp8[1]); | ||
343 | lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT, &data->temp8[2]); | ||
344 | lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, &data->temp8[3]); | ||
345 | lm90_read_reg(client, LM90_REG_R_TCRIT_HYST, &data->temp_hyst); | ||
346 | |||
347 | if (data->flags & LM90_HAVE_LOCAL_EXT) { | ||
348 | lm90_read16(client, LM90_REG_R_LOCAL_TEMP, | ||
349 | MAX6657_REG_R_LOCAL_TEMPL, | ||
350 | &data->temp11[4]); | ||
351 | } else { | ||
352 | if (lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP, | ||
353 | &h) == 0) | ||
354 | data->temp11[4] = h << 8; | ||
355 | } | ||
356 | lm90_read16(client, LM90_REG_R_REMOTE_TEMPH, | ||
357 | LM90_REG_R_REMOTE_TEMPL, &data->temp11[0]); | ||
358 | |||
359 | if (lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h) == 0) { | ||
360 | data->temp11[1] = h << 8; | ||
361 | if ((data->flags & LM90_HAVE_REM_LIMIT_EXT) | ||
362 | && lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL, | ||
363 | &l) == 0) | ||
364 | data->temp11[1] |= l; | ||
365 | } | ||
366 | if (lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h) == 0) { | ||
367 | data->temp11[2] = h << 8; | ||
368 | if ((data->flags & LM90_HAVE_REM_LIMIT_EXT) | ||
369 | && lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL, | ||
370 | &l) == 0) | ||
371 | data->temp11[2] |= l; | ||
372 | } | ||
373 | |||
374 | if (data->flags & LM90_HAVE_OFFSET) { | ||
375 | if (lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSH, | ||
376 | &h) == 0 | ||
377 | && lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSL, | ||
378 | &l) == 0) | ||
379 | data->temp11[3] = (h << 8) | l; | ||
380 | } | ||
381 | if (data->flags & LM90_HAVE_EMERGENCY) { | ||
382 | lm90_read_reg(client, MAX6659_REG_R_LOCAL_EMERG, | ||
383 | &data->temp8[4]); | ||
384 | lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG, | ||
385 | &data->temp8[5]); | ||
386 | } | ||
387 | lm90_read_reg(client, LM90_REG_R_STATUS, &alarms); | ||
388 | data->alarms = alarms; /* save as 16 bit value */ | ||
389 | |||
390 | if (data->kind == max6696) { | ||
391 | lm90_select_remote_channel(client, data, 1); | ||
392 | lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, | ||
393 | &data->temp8[6]); | ||
394 | lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG, | ||
395 | &data->temp8[7]); | ||
396 | lm90_read16(client, LM90_REG_R_REMOTE_TEMPH, | ||
397 | LM90_REG_R_REMOTE_TEMPL, &data->temp11[5]); | ||
398 | if (!lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h)) | ||
399 | data->temp11[6] = h << 8; | ||
400 | if (!lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h)) | ||
401 | data->temp11[7] = h << 8; | ||
402 | lm90_select_remote_channel(client, data, 0); | ||
403 | |||
404 | if (!lm90_read_reg(client, MAX6696_REG_R_STATUS2, | ||
405 | &alarms)) | ||
406 | data->alarms |= alarms << 8; | ||
407 | } | ||
408 | |||
409 | /* Re-enable ALERT# output if it was originally enabled and | ||
410 | * relevant alarms are all clear */ | ||
411 | if ((data->config_orig & 0x80) == 0 | ||
412 | && (data->alarms & data->alert_alarms) == 0) { | ||
413 | u8 config; | ||
414 | |||
415 | lm90_read_reg(client, LM90_REG_R_CONFIG1, &config); | ||
416 | if (config & 0x80) { | ||
417 | dev_dbg(&client->dev, "Re-enabling ALERT#\n"); | ||
418 | i2c_smbus_write_byte_data(client, | ||
419 | LM90_REG_W_CONFIG1, | ||
420 | config & ~0x80); | ||
421 | } | ||
422 | } | ||
423 | |||
424 | data->last_updated = jiffies; | ||
425 | data->valid = 1; | ||
426 | } | ||
427 | |||
428 | mutex_unlock(&data->update_lock); | ||
429 | |||
430 | return data; | ||
431 | } | ||
432 | |||
433 | /* | ||
259 | * Conversions | 434 | * Conversions |
260 | * For local temperatures and limits, critical limits and the hysteresis | 435 | * For local temperatures and limits, critical limits and the hysteresis |
261 | * value, the LM90 uses signed 8-bit values with LSB = 1 degree Celsius. | 436 | * value, the LM90 uses signed 8-bit values with LSB = 1 degree Celsius. |
@@ -770,68 +945,6 @@ static DEVICE_ATTR(pec, S_IWUSR | S_IRUGO, show_pec, set_pec); | |||
770 | * Real code | 945 | * Real code |
771 | */ | 946 | */ |
772 | 947 | ||
773 | /* | ||
774 | * The ADM1032 supports PEC but not on write byte transactions, so we need | ||
775 | * to explicitly ask for a transaction without PEC. | ||
776 | */ | ||
777 | static inline s32 adm1032_write_byte(struct i2c_client *client, u8 value) | ||
778 | { | ||
779 | return i2c_smbus_xfer(client->adapter, client->addr, | ||
780 | client->flags & ~I2C_CLIENT_PEC, | ||
781 | I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL); | ||
782 | } | ||
783 | |||
784 | /* | ||
785 | * It is assumed that client->update_lock is held (unless we are in | ||
786 | * detection or initialization steps). This matters when PEC is enabled, | ||
787 | * because we don't want the address pointer to change between the write | ||
788 | * byte and the read byte transactions. | ||
789 | */ | ||
790 | static int lm90_read_reg(struct i2c_client *client, u8 reg, u8 *value) | ||
791 | { | ||
792 | int err; | ||
793 | |||
794 | if (client->flags & I2C_CLIENT_PEC) { | ||
795 | err = adm1032_write_byte(client, reg); | ||
796 | if (err >= 0) | ||
797 | err = i2c_smbus_read_byte(client); | ||
798 | } else | ||
799 | err = i2c_smbus_read_byte_data(client, reg); | ||
800 | |||
801 | if (err < 0) { | ||
802 | dev_warn(&client->dev, "Register %#02x read failed (%d)\n", | ||
803 | reg, err); | ||
804 | return err; | ||
805 | } | ||
806 | *value = err; | ||
807 | |||
808 | return 0; | ||
809 | } | ||
810 | |||
811 | /* | ||
812 | * client->update_lock must be held when calling this function (unless we are | ||
813 | * in detection or initialization steps), and while a remote channel other | ||
814 | * than channel 0 is selected. Also, calling code must make sure to re-select | ||
815 | * external channel 0 before releasing the lock. This is necessary because | ||
816 | * various registers have different meanings as a result of selecting a | ||
817 | * non-default remote channel. | ||
818 | */ | ||
819 | static inline void lm90_select_remote_channel(struct i2c_client *client, | ||
820 | struct lm90_data *data, | ||
821 | int channel) | ||
822 | { | ||
823 | u8 config; | ||
824 | |||
825 | if (data->kind == max6696) { | ||
826 | lm90_read_reg(client, LM90_REG_R_CONFIG1, &config); | ||
827 | config &= ~0x08; | ||
828 | if (channel) | ||
829 | config |= 0x08; | ||
830 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, | ||
831 | config); | ||
832 | } | ||
833 | } | ||
834 | |||
835 | /* Return 0 if detection is successful, -ENODEV otherwise */ | 948 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
836 | static int lm90_detect(struct i2c_client *new_client, | 949 | static int lm90_detect(struct i2c_client *new_client, |
837 | struct i2c_board_info *info) | 950 | struct i2c_board_info *info) |
@@ -1023,6 +1136,47 @@ static void lm90_remove_files(struct i2c_client *client, struct lm90_data *data) | |||
1023 | sysfs_remove_group(&client->dev.kobj, &lm90_group); | 1136 | sysfs_remove_group(&client->dev.kobj, &lm90_group); |
1024 | } | 1137 | } |
1025 | 1138 | ||
1139 | static void lm90_init_client(struct i2c_client *client) | ||
1140 | { | ||
1141 | u8 config; | ||
1142 | struct lm90_data *data = i2c_get_clientdata(client); | ||
1143 | |||
1144 | /* | ||
1145 | * Start the conversions. | ||
1146 | */ | ||
1147 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, | ||
1148 | 5); /* 2 Hz */ | ||
1149 | if (lm90_read_reg(client, LM90_REG_R_CONFIG1, &config) < 0) { | ||
1150 | dev_warn(&client->dev, "Initialization failed!\n"); | ||
1151 | return; | ||
1152 | } | ||
1153 | data->config_orig = config; | ||
1154 | |||
1155 | /* Check Temperature Range Select */ | ||
1156 | if (data->kind == adt7461) { | ||
1157 | if (config & 0x04) | ||
1158 | data->flags |= LM90_FLAG_ADT7461_EXT; | ||
1159 | } | ||
1160 | |||
1161 | /* | ||
1162 | * Put MAX6680/MAX8881 into extended resolution (bit 0x10, | ||
1163 | * 0.125 degree resolution) and range (0x08, extend range | ||
1164 | * to -64 degree) mode for the remote temperature sensor. | ||
1165 | */ | ||
1166 | if (data->kind == max6680) | ||
1167 | config |= 0x18; | ||
1168 | |||
1169 | /* | ||
1170 | * Select external channel 0 for max6695/96 | ||
1171 | */ | ||
1172 | if (data->kind == max6696) | ||
1173 | config &= ~0x08; | ||
1174 | |||
1175 | config &= 0xBF; /* run */ | ||
1176 | if (config != data->config_orig) /* Only write if changed */ | ||
1177 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); | ||
1178 | } | ||
1179 | |||
1026 | static int lm90_probe(struct i2c_client *new_client, | 1180 | static int lm90_probe(struct i2c_client *new_client, |
1027 | const struct i2c_device_id *id) | 1181 | const struct i2c_device_id *id) |
1028 | { | 1182 | { |
@@ -1134,47 +1288,6 @@ exit: | |||
1134 | return err; | 1288 | return err; |
1135 | } | 1289 | } |
1136 | 1290 | ||
1137 | static void lm90_init_client(struct i2c_client *client) | ||
1138 | { | ||
1139 | u8 config; | ||
1140 | struct lm90_data *data = i2c_get_clientdata(client); | ||
1141 | |||
1142 | /* | ||
1143 | * Start the conversions. | ||
1144 | */ | ||
1145 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, | ||
1146 | 5); /* 2 Hz */ | ||
1147 | if (lm90_read_reg(client, LM90_REG_R_CONFIG1, &config) < 0) { | ||
1148 | dev_warn(&client->dev, "Initialization failed!\n"); | ||
1149 | return; | ||
1150 | } | ||
1151 | data->config_orig = config; | ||
1152 | |||
1153 | /* Check Temperature Range Select */ | ||
1154 | if (data->kind == adt7461) { | ||
1155 | if (config & 0x04) | ||
1156 | data->flags |= LM90_FLAG_ADT7461_EXT; | ||
1157 | } | ||
1158 | |||
1159 | /* | ||
1160 | * Put MAX6680/MAX8881 into extended resolution (bit 0x10, | ||
1161 | * 0.125 degree resolution) and range (0x08, extend range | ||
1162 | * to -64 degree) mode for the remote temperature sensor. | ||
1163 | */ | ||
1164 | if (data->kind == max6680) | ||
1165 | config |= 0x18; | ||
1166 | |||
1167 | /* | ||
1168 | * Select external channel 0 for max6695/96 | ||
1169 | */ | ||
1170 | if (data->kind == max6696) | ||
1171 | config &= ~0x08; | ||
1172 | |||
1173 | config &= 0xBF; /* run */ | ||
1174 | if (config != data->config_orig) /* Only write if changed */ | ||
1175 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); | ||
1176 | } | ||
1177 | |||
1178 | static int lm90_remove(struct i2c_client *client) | 1291 | static int lm90_remove(struct i2c_client *client) |
1179 | { | 1292 | { |
1180 | struct lm90_data *data = i2c_get_clientdata(client); | 1293 | struct lm90_data *data = i2c_get_clientdata(client); |
@@ -1230,142 +1343,18 @@ static void lm90_alert(struct i2c_client *client, unsigned int flag) | |||
1230 | } | 1343 | } |
1231 | } | 1344 | } |
1232 | 1345 | ||
1233 | static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value) | 1346 | static struct i2c_driver lm90_driver = { |
1234 | { | 1347 | .class = I2C_CLASS_HWMON, |
1235 | int err; | 1348 | .driver = { |
1236 | u8 oldh, newh, l; | 1349 | .name = "lm90", |
1237 | 1350 | }, | |
1238 | /* | 1351 | .probe = lm90_probe, |
1239 | * There is a trick here. We have to read two registers to have the | 1352 | .remove = lm90_remove, |
1240 | * sensor temperature, but we have to beware a conversion could occur | 1353 | .alert = lm90_alert, |
1241 | * inbetween the readings. The datasheet says we should either use | 1354 | .id_table = lm90_id, |
1242 | * the one-shot conversion register, which we don't want to do | 1355 | .detect = lm90_detect, |
1243 | * (disables hardware monitoring) or monitor the busy bit, which is | 1356 | .address_list = normal_i2c, |
1244 | * impossible (we can't read the values and monitor that bit at the | 1357 | }; |
1245 | * exact same time). So the solution used here is to read the high | ||
1246 | * byte once, then the low byte, then the high byte again. If the new | ||
1247 | * high byte matches the old one, then we have a valid reading. Else | ||
1248 | * we have to read the low byte again, and now we believe we have a | ||
1249 | * correct reading. | ||
1250 | */ | ||
1251 | if ((err = lm90_read_reg(client, regh, &oldh)) | ||
1252 | || (err = lm90_read_reg(client, regl, &l)) | ||
1253 | || (err = lm90_read_reg(client, regh, &newh))) | ||
1254 | return err; | ||
1255 | if (oldh != newh) { | ||
1256 | err = lm90_read_reg(client, regl, &l); | ||
1257 | if (err) | ||
1258 | return err; | ||
1259 | } | ||
1260 | *value = (newh << 8) | l; | ||
1261 | |||
1262 | return 0; | ||
1263 | } | ||
1264 | |||
1265 | static struct lm90_data *lm90_update_device(struct device *dev) | ||
1266 | { | ||
1267 | struct i2c_client *client = to_i2c_client(dev); | ||
1268 | struct lm90_data *data = i2c_get_clientdata(client); | ||
1269 | |||
1270 | mutex_lock(&data->update_lock); | ||
1271 | |||
1272 | if (time_after(jiffies, data->last_updated + HZ / 2 + HZ / 10) | ||
1273 | || !data->valid) { | ||
1274 | u8 h, l; | ||
1275 | u8 alarms; | ||
1276 | |||
1277 | dev_dbg(&client->dev, "Updating lm90 data.\n"); | ||
1278 | lm90_read_reg(client, LM90_REG_R_LOCAL_LOW, &data->temp8[0]); | ||
1279 | lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH, &data->temp8[1]); | ||
1280 | lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT, &data->temp8[2]); | ||
1281 | lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, &data->temp8[3]); | ||
1282 | lm90_read_reg(client, LM90_REG_R_TCRIT_HYST, &data->temp_hyst); | ||
1283 | |||
1284 | if (data->flags & LM90_HAVE_LOCAL_EXT) { | ||
1285 | lm90_read16(client, LM90_REG_R_LOCAL_TEMP, | ||
1286 | MAX6657_REG_R_LOCAL_TEMPL, | ||
1287 | &data->temp11[4]); | ||
1288 | } else { | ||
1289 | if (lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP, | ||
1290 | &h) == 0) | ||
1291 | data->temp11[4] = h << 8; | ||
1292 | } | ||
1293 | lm90_read16(client, LM90_REG_R_REMOTE_TEMPH, | ||
1294 | LM90_REG_R_REMOTE_TEMPL, &data->temp11[0]); | ||
1295 | |||
1296 | if (lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h) == 0) { | ||
1297 | data->temp11[1] = h << 8; | ||
1298 | if ((data->flags & LM90_HAVE_REM_LIMIT_EXT) | ||
1299 | && lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL, | ||
1300 | &l) == 0) | ||
1301 | data->temp11[1] |= l; | ||
1302 | } | ||
1303 | if (lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h) == 0) { | ||
1304 | data->temp11[2] = h << 8; | ||
1305 | if ((data->flags & LM90_HAVE_REM_LIMIT_EXT) | ||
1306 | && lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL, | ||
1307 | &l) == 0) | ||
1308 | data->temp11[2] |= l; | ||
1309 | } | ||
1310 | |||
1311 | if (data->flags & LM90_HAVE_OFFSET) { | ||
1312 | if (lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSH, | ||
1313 | &h) == 0 | ||
1314 | && lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSL, | ||
1315 | &l) == 0) | ||
1316 | data->temp11[3] = (h << 8) | l; | ||
1317 | } | ||
1318 | if (data->flags & LM90_HAVE_EMERGENCY) { | ||
1319 | lm90_read_reg(client, MAX6659_REG_R_LOCAL_EMERG, | ||
1320 | &data->temp8[4]); | ||
1321 | lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG, | ||
1322 | &data->temp8[5]); | ||
1323 | } | ||
1324 | lm90_read_reg(client, LM90_REG_R_STATUS, &alarms); | ||
1325 | data->alarms = alarms; /* save as 16 bit value */ | ||
1326 | |||
1327 | if (data->kind == max6696) { | ||
1328 | lm90_select_remote_channel(client, data, 1); | ||
1329 | lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, | ||
1330 | &data->temp8[6]); | ||
1331 | lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG, | ||
1332 | &data->temp8[7]); | ||
1333 | lm90_read16(client, LM90_REG_R_REMOTE_TEMPH, | ||
1334 | LM90_REG_R_REMOTE_TEMPL, &data->temp11[5]); | ||
1335 | if (!lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h)) | ||
1336 | data->temp11[6] = h << 8; | ||
1337 | if (!lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h)) | ||
1338 | data->temp11[7] = h << 8; | ||
1339 | lm90_select_remote_channel(client, data, 0); | ||
1340 | |||
1341 | if (!lm90_read_reg(client, MAX6696_REG_R_STATUS2, | ||
1342 | &alarms)) | ||
1343 | data->alarms |= alarms << 8; | ||
1344 | } | ||
1345 | |||
1346 | /* Re-enable ALERT# output if it was originally enabled and | ||
1347 | * relevant alarms are all clear */ | ||
1348 | if ((data->config_orig & 0x80) == 0 | ||
1349 | && (data->alarms & data->alert_alarms) == 0) { | ||
1350 | u8 config; | ||
1351 | |||
1352 | lm90_read_reg(client, LM90_REG_R_CONFIG1, &config); | ||
1353 | if (config & 0x80) { | ||
1354 | dev_dbg(&client->dev, "Re-enabling ALERT#\n"); | ||
1355 | i2c_smbus_write_byte_data(client, | ||
1356 | LM90_REG_W_CONFIG1, | ||
1357 | config & ~0x80); | ||
1358 | } | ||
1359 | } | ||
1360 | |||
1361 | data->last_updated = jiffies; | ||
1362 | data->valid = 1; | ||
1363 | } | ||
1364 | |||
1365 | mutex_unlock(&data->update_lock); | ||
1366 | |||
1367 | return data; | ||
1368 | } | ||
1369 | 1358 | ||
1370 | static int __init sensors_lm90_init(void) | 1359 | static int __init sensors_lm90_init(void) |
1371 | { | 1360 | { |