aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/lm90.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/lm90.c')
-rw-r--r--drivers/hwmon/lm90.c107
1 files changed, 53 insertions, 54 deletions
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index dad0f1074956..5acc12ae4e36 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -349,6 +349,22 @@ static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
349 * Real code 349 * Real code
350 */ 350 */
351 351
352static int lm90_read_reg(struct i2c_client* client, u8 reg, u8 *value)
353{
354 int err;
355
356 err = i2c_smbus_read_byte_data(client, reg);
357
358 if (err < 0) {
359 dev_warn(&client->dev, "Register %#02x read failed (%d)\n",
360 reg, err);
361 return err;
362 }
363 *value = err;
364
365 return 0;
366}
367
352static int lm90_attach_adapter(struct i2c_adapter *adapter) 368static int lm90_attach_adapter(struct i2c_adapter *adapter)
353{ 369{
354 if (!(adapter->class & I2C_CLASS_HWMON)) 370 if (!(adapter->class & I2C_CLASS_HWMON))
@@ -402,20 +418,22 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind)
402 if (kind < 0) { /* detection and identification */ 418 if (kind < 0) { /* detection and identification */
403 u8 man_id, chip_id, reg_config1, reg_convrate; 419 u8 man_id, chip_id, reg_config1, reg_convrate;
404 420
405 man_id = i2c_smbus_read_byte_data(new_client, 421 if (lm90_read_reg(new_client, LM90_REG_R_MAN_ID,
406 LM90_REG_R_MAN_ID); 422 &man_id) < 0
407 chip_id = i2c_smbus_read_byte_data(new_client, 423 || lm90_read_reg(new_client, LM90_REG_R_CHIP_ID,
408 LM90_REG_R_CHIP_ID); 424 &chip_id) < 0
409 reg_config1 = i2c_smbus_read_byte_data(new_client, 425 || lm90_read_reg(new_client, LM90_REG_R_CONFIG1,
410 LM90_REG_R_CONFIG1); 426 &reg_config1) < 0
411 reg_convrate = i2c_smbus_read_byte_data(new_client, 427 || lm90_read_reg(new_client, LM90_REG_R_CONVRATE,
412 LM90_REG_R_CONVRATE); 428 &reg_convrate) < 0)
429 goto exit_free;
413 430
414 if (man_id == 0x01) { /* National Semiconductor */ 431 if (man_id == 0x01) { /* National Semiconductor */
415 u8 reg_config2; 432 u8 reg_config2;
416 433
417 reg_config2 = i2c_smbus_read_byte_data(new_client, 434 if (lm90_read_reg(new_client, LM90_REG_R_CONFIG2,
418 LM90_REG_R_CONFIG2); 435 &reg_config2) < 0)
436 goto exit_free;
419 437
420 if ((reg_config1 & 0x2A) == 0x00 438 if ((reg_config1 & 0x2A) == 0x00
421 && (reg_config2 & 0xF8) == 0x00 439 && (reg_config2 & 0xF8) == 0x00
@@ -547,7 +565,10 @@ static void lm90_init_client(struct i2c_client *client)
547 */ 565 */
548 i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, 566 i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE,
549 5); /* 2 Hz */ 567 5); /* 2 Hz */
550 config = i2c_smbus_read_byte_data(client, LM90_REG_R_CONFIG1); 568 if (lm90_read_reg(client, LM90_REG_R_CONFIG1, &config) < 0) {
569 dev_warn(&client->dev, "Initialization failed!\n");
570 return;
571 }
551 if (config & 0x40) 572 if (config & 0x40)
552 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, 573 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
553 config & 0xBF); /* run */ 574 config & 0xBF); /* run */
@@ -575,21 +596,15 @@ static struct lm90_data *lm90_update_device(struct device *dev)
575 down(&data->update_lock); 596 down(&data->update_lock);
576 597
577 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { 598 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
578 u8 oldh, newh; 599 u8 oldh, newh, l;
579 600
580 dev_dbg(&client->dev, "Updating lm90 data.\n"); 601 dev_dbg(&client->dev, "Updating lm90 data.\n");
581 data->temp8[0] = i2c_smbus_read_byte_data(client, 602 lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP, &data->temp8[0]);
582 LM90_REG_R_LOCAL_TEMP); 603 lm90_read_reg(client, LM90_REG_R_LOCAL_LOW, &data->temp8[1]);
583 data->temp8[1] = i2c_smbus_read_byte_data(client, 604 lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH, &data->temp8[2]);
584 LM90_REG_R_LOCAL_LOW); 605 lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT, &data->temp8[3]);
585 data->temp8[2] = i2c_smbus_read_byte_data(client, 606 lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, &data->temp8[4]);
586 LM90_REG_R_LOCAL_HIGH); 607 lm90_read_reg(client, LM90_REG_R_TCRIT_HYST, &data->temp_hyst);
587 data->temp8[3] = i2c_smbus_read_byte_data(client,
588 LM90_REG_R_LOCAL_CRIT);
589 data->temp8[4] = i2c_smbus_read_byte_data(client,
590 LM90_REG_R_REMOTE_CRIT);
591 data->temp_hyst = i2c_smbus_read_byte_data(client,
592 LM90_REG_R_TCRIT_HYST);
593 608
594 /* 609 /*
595 * There is a trick here. We have to read two registers to 610 * There is a trick here. We have to read two registers to
@@ -605,36 +620,20 @@ static struct lm90_data *lm90_update_device(struct device *dev)
605 * then we have a valid reading. Else we have to read the low 620 * then we have a valid reading. Else we have to read the low
606 * byte again, and now we believe we have a correct reading. 621 * byte again, and now we believe we have a correct reading.
607 */ 622 */
608 oldh = i2c_smbus_read_byte_data(client, 623 if (lm90_read_reg(client, LM90_REG_R_REMOTE_TEMPH, &oldh) == 0
609 LM90_REG_R_REMOTE_TEMPH); 624 && lm90_read_reg(client, LM90_REG_R_REMOTE_TEMPL, &l) == 0
610 data->temp11[0] = i2c_smbus_read_byte_data(client, 625 && lm90_read_reg(client, LM90_REG_R_REMOTE_TEMPH, &newh) == 0
611 LM90_REG_R_REMOTE_TEMPL); 626 && (newh == oldh
612 newh = i2c_smbus_read_byte_data(client, 627 || lm90_read_reg(client, LM90_REG_R_REMOTE_TEMPL, &l) == 0))
613 LM90_REG_R_REMOTE_TEMPH); 628 data->temp11[0] = (newh << 8) | l;
614 if (newh != oldh) { 629
615 data->temp11[0] = i2c_smbus_read_byte_data(client, 630 if (lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &newh) == 0
616 LM90_REG_R_REMOTE_TEMPL); 631 && lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL, &l) == 0)
617#ifdef DEBUG 632 data->temp11[1] = (newh << 8) | l;
618 oldh = i2c_smbus_read_byte_data(client, 633 if (lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &newh) == 0
619 LM90_REG_R_REMOTE_TEMPH); 634 && lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL, &l) == 0)
620 /* oldh is actually newer */ 635 data->temp11[2] = (newh << 8) | l;
621 if (newh != oldh) 636 lm90_read_reg(client, LM90_REG_R_STATUS, &data->alarms);
622 dev_warn(&client->dev, "Remote temperature may be "
623 "wrong.\n");
624#endif
625 }
626 data->temp11[0] |= (newh << 8);
627
628 data->temp11[1] = (i2c_smbus_read_byte_data(client,
629 LM90_REG_R_REMOTE_LOWH) << 8) +
630 i2c_smbus_read_byte_data(client,
631 LM90_REG_R_REMOTE_LOWL);
632 data->temp11[2] = (i2c_smbus_read_byte_data(client,
633 LM90_REG_R_REMOTE_HIGHH) << 8) +
634 i2c_smbus_read_byte_data(client,
635 LM90_REG_R_REMOTE_HIGHL);
636 data->alarms = i2c_smbus_read_byte_data(client,
637 LM90_REG_R_STATUS);
638 637
639 data->last_updated = jiffies; 638 data->last_updated = jiffies;
640 data->valid = 1; 639 data->valid = 1;