diff options
author | Guenter Roeck <linux@roeck-us.net> | 2016-06-13 09:57:37 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2016-07-09 11:35:40 -0400 |
commit | 37ad04d7a9a5c8c066e2e17d960f6563e194e53a (patch) | |
tree | 10c4f17f5ec0da6c78825e186a96a1afc1e39290 | |
parent | 6e5f62b9e3651e619a6baee9e11f6d9c8e4fd657 (diff) |
hwmon: (lm90) Simplify read functions
Return both error code and register value as return code from
read functions, and always check for errors.
This reduces code size on x86_64 by more than 1k while at
the same time improving error resiliency.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r-- | drivers/hwmon/lm90.c | 308 |
1 files changed, 193 insertions, 115 deletions
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 9d733cb0504c..2a330bdbf1bc 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c | |||
@@ -171,7 +171,6 @@ enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, max6680, | |||
171 | 171 | ||
172 | #define SA56004_REG_R_LOCAL_TEMPL 0x22 | 172 | #define SA56004_REG_R_LOCAL_TEMPL 0x22 |
173 | 173 | ||
174 | #define LM90_DEF_CONVRATE_RVAL 6 /* Def conversion rate register value */ | ||
175 | #define LM90_MAX_CONVRATE_MS 16000 /* Maximum conversion rate in ms */ | 174 | #define LM90_MAX_CONVRATE_MS 16000 /* Maximum conversion rate in ms */ |
176 | 175 | ||
177 | /* TMP451 registers */ | 176 | /* TMP451 registers */ |
@@ -410,7 +409,7 @@ static inline s32 adm1032_write_byte(struct i2c_client *client, u8 value) | |||
410 | * because we don't want the address pointer to change between the write | 409 | * because we don't want the address pointer to change between the write |
411 | * byte and the read byte transactions. | 410 | * byte and the read byte transactions. |
412 | */ | 411 | */ |
413 | static int lm90_read_reg(struct i2c_client *client, u8 reg, u8 *value) | 412 | static int lm90_read_reg(struct i2c_client *client, u8 reg) |
414 | { | 413 | { |
415 | int err; | 414 | int err; |
416 | 415 | ||
@@ -421,20 +420,12 @@ static int lm90_read_reg(struct i2c_client *client, u8 reg, u8 *value) | |||
421 | } else | 420 | } else |
422 | err = i2c_smbus_read_byte_data(client, reg); | 421 | err = i2c_smbus_read_byte_data(client, reg); |
423 | 422 | ||
424 | if (err < 0) { | 423 | return err; |
425 | dev_warn(&client->dev, "Register %#02x read failed (%d)\n", | ||
426 | reg, err); | ||
427 | return err; | ||
428 | } | ||
429 | *value = err; | ||
430 | |||
431 | return 0; | ||
432 | } | 424 | } |
433 | 425 | ||
434 | static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value) | 426 | static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl) |
435 | { | 427 | { |
436 | int err; | 428 | int oldh, newh, l; |
437 | u8 oldh, newh, l; | ||
438 | 429 | ||
439 | /* | 430 | /* |
440 | * There is a trick here. We have to read two registers to have the | 431 | * There is a trick here. We have to read two registers to have the |
@@ -449,18 +440,21 @@ static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value) | |||
449 | * we have to read the low byte again, and now we believe we have a | 440 | * we have to read the low byte again, and now we believe we have a |
450 | * correct reading. | 441 | * correct reading. |
451 | */ | 442 | */ |
452 | if ((err = lm90_read_reg(client, regh, &oldh)) | 443 | oldh = lm90_read_reg(client, regh); |
453 | || (err = lm90_read_reg(client, regl, &l)) | 444 | if (oldh < 0) |
454 | || (err = lm90_read_reg(client, regh, &newh))) | 445 | return oldh; |
455 | return err; | 446 | l = lm90_read_reg(client, regl); |
447 | if (l < 0) | ||
448 | return l; | ||
449 | newh = lm90_read_reg(client, regh); | ||
450 | if (newh < 0) | ||
451 | return newh; | ||
456 | if (oldh != newh) { | 452 | if (oldh != newh) { |
457 | err = lm90_read_reg(client, regl, &l); | 453 | l = lm90_read_reg(client, regl); |
458 | if (err) | 454 | if (l < 0) |
459 | return err; | 455 | return l; |
460 | } | 456 | } |
461 | *value = (newh << 8) | l; | 457 | return (newh << 8) | l; |
462 | |||
463 | return 0; | ||
464 | } | 458 | } |
465 | 459 | ||
466 | /* | 460 | /* |
@@ -471,20 +465,23 @@ static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value) | |||
471 | * various registers have different meanings as a result of selecting a | 465 | * various registers have different meanings as a result of selecting a |
472 | * non-default remote channel. | 466 | * non-default remote channel. |
473 | */ | 467 | */ |
474 | static inline void lm90_select_remote_channel(struct i2c_client *client, | 468 | static inline int lm90_select_remote_channel(struct i2c_client *client, |
475 | struct lm90_data *data, | 469 | struct lm90_data *data, |
476 | int channel) | 470 | int channel) |
477 | { | 471 | { |
478 | u8 config; | 472 | int config; |
479 | 473 | ||
480 | if (data->kind == max6696) { | 474 | if (data->kind == max6696) { |
481 | lm90_read_reg(client, LM90_REG_R_CONFIG1, &config); | 475 | config = lm90_read_reg(client, LM90_REG_R_CONFIG1); |
476 | if (config < 0) | ||
477 | return config; | ||
482 | config &= ~0x08; | 478 | config &= ~0x08; |
483 | if (channel) | 479 | if (channel) |
484 | config |= 0x08; | 480 | config |= 0x08; |
485 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, | 481 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, |
486 | config); | 482 | config); |
487 | } | 483 | } |
484 | return 0; | ||
488 | } | 485 | } |
489 | 486 | ||
490 | /* | 487 | /* |
@@ -516,104 +513,153 @@ static struct lm90_data *lm90_update_device(struct device *dev) | |||
516 | struct lm90_data *data = dev_get_drvdata(dev); | 513 | struct lm90_data *data = dev_get_drvdata(dev); |
517 | struct i2c_client *client = data->client; | 514 | struct i2c_client *client = data->client; |
518 | unsigned long next_update; | 515 | unsigned long next_update; |
516 | int val = 0; | ||
519 | 517 | ||
520 | mutex_lock(&data->update_lock); | 518 | mutex_lock(&data->update_lock); |
521 | 519 | ||
522 | next_update = data->last_updated + | 520 | next_update = data->last_updated + |
523 | msecs_to_jiffies(data->update_interval); | 521 | msecs_to_jiffies(data->update_interval); |
524 | if (time_after(jiffies, next_update) || !data->valid) { | 522 | if (time_after(jiffies, next_update) || !data->valid) { |
525 | u8 h, l; | ||
526 | u8 alarms; | ||
527 | |||
528 | dev_dbg(&client->dev, "Updating lm90 data.\n"); | 523 | dev_dbg(&client->dev, "Updating lm90 data.\n"); |
529 | lm90_read_reg(client, LM90_REG_R_LOCAL_LOW, | 524 | val = lm90_read_reg(client, LM90_REG_R_LOCAL_LOW); |
530 | &data->temp8[LOCAL_LOW]); | 525 | if (val < 0) |
531 | lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH, | 526 | goto error; |
532 | &data->temp8[LOCAL_HIGH]); | 527 | data->temp8[LOCAL_LOW] = val; |
533 | lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT, | 528 | |
534 | &data->temp8[LOCAL_CRIT]); | 529 | val = lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH); |
535 | lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, | 530 | if (val < 0) |
536 | &data->temp8[REMOTE_CRIT]); | 531 | goto error; |
537 | lm90_read_reg(client, LM90_REG_R_TCRIT_HYST, &data->temp_hyst); | 532 | data->temp8[LOCAL_HIGH] = val; |
533 | |||
534 | val = lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT); | ||
535 | if (val < 0) | ||
536 | goto error; | ||
537 | data->temp8[LOCAL_CRIT] = val; | ||
538 | |||
539 | val = lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT); | ||
540 | if (val < 0) | ||
541 | goto error; | ||
542 | data->temp8[REMOTE_CRIT] = val; | ||
543 | val = lm90_read_reg(client, LM90_REG_R_TCRIT_HYST); | ||
544 | if (val < 0) | ||
545 | goto error; | ||
546 | data->temp_hyst = val; | ||
538 | 547 | ||
539 | if (data->reg_local_ext) { | 548 | if (data->reg_local_ext) { |
540 | lm90_read16(client, LM90_REG_R_LOCAL_TEMP, | 549 | val = lm90_read16(client, LM90_REG_R_LOCAL_TEMP, |
541 | data->reg_local_ext, | 550 | data->reg_local_ext); |
542 | &data->temp11[LOCAL_TEMP]); | 551 | if (val < 0) |
552 | goto error; | ||
553 | data->temp11[LOCAL_TEMP] = val; | ||
543 | } else { | 554 | } else { |
544 | if (lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP, | 555 | val = lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP); |
545 | &h) == 0) | 556 | if (val < 0) |
546 | data->temp11[LOCAL_TEMP] = h << 8; | 557 | goto error; |
558 | data->temp11[LOCAL_TEMP] = val << 8; | ||
547 | } | 559 | } |
548 | lm90_read16(client, LM90_REG_R_REMOTE_TEMPH, | 560 | val = lm90_read16(client, LM90_REG_R_REMOTE_TEMPH, |
549 | LM90_REG_R_REMOTE_TEMPL, | 561 | LM90_REG_R_REMOTE_TEMPL); |
550 | &data->temp11[REMOTE_TEMP]); | 562 | if (val < 0) |
551 | 563 | goto error; | |
552 | if (lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h) == 0) { | 564 | data->temp11[REMOTE_TEMP] = val; |
553 | data->temp11[REMOTE_LOW] = h << 8; | 565 | |
554 | if ((data->flags & LM90_HAVE_REM_LIMIT_EXT) | 566 | lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH); |
555 | && lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL, | 567 | if (val < 0) |
556 | &l) == 0) | 568 | goto error; |
557 | data->temp11[REMOTE_LOW] |= l; | 569 | data->temp11[REMOTE_LOW] = val << 8; |
570 | if (data->flags & LM90_HAVE_REM_LIMIT_EXT) { | ||
571 | val = lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL); | ||
572 | if (val < 0) | ||
573 | goto error; | ||
574 | data->temp11[REMOTE_LOW] |= val; | ||
558 | } | 575 | } |
559 | if (lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h) == 0) { | 576 | val = lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH); |
560 | data->temp11[REMOTE_HIGH] = h << 8; | 577 | if (val < 0) |
561 | if ((data->flags & LM90_HAVE_REM_LIMIT_EXT) | 578 | goto error; |
562 | && lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL, | 579 | data->temp11[REMOTE_HIGH] = val << 8; |
563 | &l) == 0) | 580 | if (data->flags & LM90_HAVE_REM_LIMIT_EXT) { |
564 | data->temp11[REMOTE_HIGH] |= l; | 581 | val = lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL); |
582 | if (val < 0) | ||
583 | goto error; | ||
584 | data->temp11[REMOTE_HIGH] |= val; | ||
565 | } | 585 | } |
566 | 586 | ||
567 | if (data->flags & LM90_HAVE_OFFSET) { | 587 | if (data->flags & LM90_HAVE_OFFSET) { |
568 | if (lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSH, | 588 | val = lm90_read16(client, LM90_REG_R_REMOTE_OFFSH, |
569 | &h) == 0 | 589 | LM90_REG_R_REMOTE_OFFSL); |
570 | && lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSL, | 590 | if (val < 0) |
571 | &l) == 0) | 591 | goto error; |
572 | data->temp11[REMOTE_OFFSET] = (h << 8) | l; | 592 | data->temp11[REMOTE_OFFSET] = val; |
573 | } | 593 | } |
574 | if (data->flags & LM90_HAVE_EMERGENCY) { | 594 | if (data->flags & LM90_HAVE_EMERGENCY) { |
575 | lm90_read_reg(client, MAX6659_REG_R_LOCAL_EMERG, | 595 | val = lm90_read_reg(client, MAX6659_REG_R_LOCAL_EMERG); |
576 | &data->temp8[LOCAL_EMERG]); | 596 | if (val < 0) |
577 | lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG, | 597 | goto error; |
578 | &data->temp8[REMOTE_EMERG]); | 598 | data->temp8[LOCAL_EMERG] = val; |
599 | val = lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG); | ||
600 | if (val < 0) | ||
601 | goto error; | ||
602 | data->temp8[REMOTE_EMERG] = val; | ||
579 | } | 603 | } |
580 | lm90_read_reg(client, LM90_REG_R_STATUS, &alarms); | 604 | val = lm90_read_reg(client, LM90_REG_R_STATUS); |
581 | data->alarms = alarms; /* save as 16 bit value */ | 605 | if (val < 0) |
606 | goto error; | ||
607 | data->alarms = val; /* lower 8 bit of alarms */ | ||
582 | 608 | ||
583 | if (data->kind == max6696) { | 609 | if (data->kind == max6696) { |
584 | lm90_select_remote_channel(client, data, 1); | 610 | val = lm90_select_remote_channel(client, data, 1); |
585 | lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, | 611 | if (val < 0) |
586 | &data->temp8[REMOTE2_CRIT]); | 612 | goto error; |
587 | lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG, | 613 | |
588 | &data->temp8[REMOTE2_EMERG]); | 614 | val = lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT); |
589 | lm90_read16(client, LM90_REG_R_REMOTE_TEMPH, | 615 | if (val < 0) |
590 | LM90_REG_R_REMOTE_TEMPL, | 616 | goto error; |
591 | &data->temp11[REMOTE2_TEMP]); | 617 | data->temp8[REMOTE2_CRIT] = val; |
592 | if (!lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h)) | 618 | |
593 | data->temp11[REMOTE2_LOW] = h << 8; | 619 | val = lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG); |
594 | if (!lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h)) | 620 | if (val < 0) |
595 | data->temp11[REMOTE2_HIGH] = h << 8; | 621 | goto error; |
622 | data->temp8[REMOTE2_EMERG] = val; | ||
623 | |||
624 | val = lm90_read16(client, LM90_REG_R_REMOTE_TEMPH, | ||
625 | LM90_REG_R_REMOTE_TEMPL); | ||
626 | if (val < 0) | ||
627 | goto error; | ||
628 | data->temp11[REMOTE2_TEMP] = val; | ||
629 | |||
630 | val = lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH); | ||
631 | if (val < 0) | ||
632 | goto error; | ||
633 | data->temp11[REMOTE2_LOW] = val << 8; | ||
634 | |||
635 | val = lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH); | ||
636 | if (val < 0) | ||
637 | goto error; | ||
638 | data->temp11[REMOTE2_HIGH] = val << 8; | ||
639 | |||
596 | lm90_select_remote_channel(client, data, 0); | 640 | lm90_select_remote_channel(client, data, 0); |
597 | 641 | ||
598 | if (!lm90_read_reg(client, MAX6696_REG_R_STATUS2, | 642 | val = lm90_read_reg(client, MAX6696_REG_R_STATUS2); |
599 | &alarms)) | 643 | if (val < 0) |
600 | data->alarms |= alarms << 8; | 644 | goto error; |
645 | data->alarms |= val << 8; | ||
601 | } | 646 | } |
602 | 647 | ||
603 | /* | 648 | /* |
604 | * Re-enable ALERT# output if it was originally enabled and | 649 | * Re-enable ALERT# output if it was originally enabled and |
605 | * relevant alarms are all clear | 650 | * relevant alarms are all clear |
606 | */ | 651 | */ |
607 | if ((data->config_orig & 0x80) == 0 | 652 | if (!(data->config_orig & 0x80) && |
608 | && (data->alarms & data->alert_alarms) == 0) { | 653 | !(data->alarms & data->alert_alarms)) { |
609 | u8 config; | 654 | val = lm90_read_reg(client, LM90_REG_R_CONFIG1); |
655 | if (val < 0) | ||
656 | goto error; | ||
610 | 657 | ||
611 | lm90_read_reg(client, LM90_REG_R_CONFIG1, &config); | 658 | if (val & 0x80) { |
612 | if (config & 0x80) { | ||
613 | dev_dbg(&client->dev, "Re-enabling ALERT#\n"); | 659 | dev_dbg(&client->dev, "Re-enabling ALERT#\n"); |
614 | i2c_smbus_write_byte_data(client, | 660 | i2c_smbus_write_byte_data(client, |
615 | LM90_REG_W_CONFIG1, | 661 | LM90_REG_W_CONFIG1, |
616 | config & ~0x80); | 662 | val & ~0x80); |
617 | } | 663 | } |
618 | } | 664 | } |
619 | 665 | ||
@@ -621,8 +667,12 @@ static struct lm90_data *lm90_update_device(struct device *dev) | |||
621 | data->valid = 1; | 667 | data->valid = 1; |
622 | } | 668 | } |
623 | 669 | ||
670 | error: | ||
624 | mutex_unlock(&data->update_lock); | 671 | mutex_unlock(&data->update_lock); |
625 | 672 | ||
673 | if (val < 0) | ||
674 | return ERR_PTR(val); | ||
675 | |||
626 | return data; | 676 | return data; |
627 | } | 677 | } |
628 | 678 | ||
@@ -764,6 +814,9 @@ static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr, | |||
764 | struct lm90_data *data = lm90_update_device(dev); | 814 | struct lm90_data *data = lm90_update_device(dev); |
765 | int temp; | 815 | int temp; |
766 | 816 | ||
817 | if (IS_ERR(data)) | ||
818 | return PTR_ERR(data); | ||
819 | |||
767 | if (data->kind == adt7461 || data->kind == tmp451) | 820 | if (data->kind == adt7461 || data->kind == tmp451) |
768 | temp = temp_from_u8_adt7461(data, data->temp8[attr->index]); | 821 | temp = temp_from_u8_adt7461(data, data->temp8[attr->index]); |
769 | else if (data->kind == max6646) | 822 | else if (data->kind == max6646) |
@@ -830,6 +883,9 @@ static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr, | |||
830 | struct lm90_data *data = lm90_update_device(dev); | 883 | struct lm90_data *data = lm90_update_device(dev); |
831 | int temp; | 884 | int temp; |
832 | 885 | ||
886 | if (IS_ERR(data)) | ||
887 | return PTR_ERR(data); | ||
888 | |||
833 | if (data->kind == adt7461 || data->kind == tmp451) | 889 | if (data->kind == adt7461 || data->kind == tmp451) |
834 | temp = temp_from_u16_adt7461(data, data->temp11[attr->index]); | 890 | temp = temp_from_u16_adt7461(data, data->temp11[attr->index]); |
835 | else if (data->kind == max6646) | 891 | else if (data->kind == max6646) |
@@ -905,6 +961,9 @@ static ssize_t show_temphyst(struct device *dev, | |||
905 | struct lm90_data *data = lm90_update_device(dev); | 961 | struct lm90_data *data = lm90_update_device(dev); |
906 | int temp; | 962 | int temp; |
907 | 963 | ||
964 | if (IS_ERR(data)) | ||
965 | return PTR_ERR(data); | ||
966 | |||
908 | if (data->kind == adt7461 || data->kind == tmp451) | 967 | if (data->kind == adt7461 || data->kind == tmp451) |
909 | temp = temp_from_u8_adt7461(data, data->temp8[attr->index]); | 968 | temp = temp_from_u8_adt7461(data, data->temp8[attr->index]); |
910 | else if (data->kind == max6646) | 969 | else if (data->kind == max6646) |
@@ -951,6 +1010,10 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy, | |||
951 | char *buf) | 1010 | char *buf) |
952 | { | 1011 | { |
953 | struct lm90_data *data = lm90_update_device(dev); | 1012 | struct lm90_data *data = lm90_update_device(dev); |
1013 | |||
1014 | if (IS_ERR(data)) | ||
1015 | return PTR_ERR(data); | ||
1016 | |||
954 | return sprintf(buf, "%d\n", data->alarms); | 1017 | return sprintf(buf, "%d\n", data->alarms); |
955 | } | 1018 | } |
956 | 1019 | ||
@@ -961,6 +1024,9 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute | |||
961 | struct lm90_data *data = lm90_update_device(dev); | 1024 | struct lm90_data *data = lm90_update_device(dev); |
962 | int bitnr = attr->index; | 1025 | int bitnr = attr->index; |
963 | 1026 | ||
1027 | if (IS_ERR(data)) | ||
1028 | return PTR_ERR(data); | ||
1029 | |||
964 | return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1); | 1030 | return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1); |
965 | } | 1031 | } |
966 | 1032 | ||
@@ -1414,24 +1480,22 @@ static void lm90_restore_conf(void *_data) | |||
1414 | data->config_orig); | 1480 | data->config_orig); |
1415 | } | 1481 | } |
1416 | 1482 | ||
1417 | static void lm90_init_client(struct i2c_client *client, struct lm90_data *data) | 1483 | static int lm90_init_client(struct i2c_client *client, struct lm90_data *data) |
1418 | { | 1484 | { |
1419 | u8 config, convrate; | 1485 | int config, convrate; |
1420 | 1486 | ||
1421 | if (lm90_read_reg(client, LM90_REG_R_CONVRATE, &convrate) < 0) { | 1487 | convrate = lm90_read_reg(client, LM90_REG_R_CONVRATE); |
1422 | dev_warn(&client->dev, "Failed to read convrate register!\n"); | 1488 | if (convrate < 0) |
1423 | convrate = LM90_DEF_CONVRATE_RVAL; | 1489 | return convrate; |
1424 | } | ||
1425 | data->convrate_orig = convrate; | 1490 | data->convrate_orig = convrate; |
1426 | 1491 | ||
1427 | /* | 1492 | /* |
1428 | * Start the conversions. | 1493 | * Start the conversions. |
1429 | */ | 1494 | */ |
1430 | lm90_set_convrate(client, data, 500); /* 500ms; 2Hz conversion rate */ | 1495 | lm90_set_convrate(client, data, 500); /* 500ms; 2Hz conversion rate */ |
1431 | if (lm90_read_reg(client, LM90_REG_R_CONFIG1, &config) < 0) { | 1496 | config = lm90_read_reg(client, LM90_REG_R_CONFIG1); |
1432 | dev_warn(&client->dev, "Initialization failed!\n"); | 1497 | if (config < 0) |
1433 | return; | 1498 | return config; |
1434 | } | ||
1435 | data->config_orig = config; | 1499 | data->config_orig = config; |
1436 | 1500 | ||
1437 | /* Check Temperature Range Select */ | 1501 | /* Check Temperature Range Select */ |
@@ -1459,17 +1523,24 @@ static void lm90_init_client(struct i2c_client *client, struct lm90_data *data) | |||
1459 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); | 1523 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); |
1460 | 1524 | ||
1461 | devm_add_action(&client->dev, lm90_restore_conf, data); | 1525 | devm_add_action(&client->dev, lm90_restore_conf, data); |
1526 | |||
1527 | return 0; | ||
1462 | } | 1528 | } |
1463 | 1529 | ||
1464 | static bool lm90_is_tripped(struct i2c_client *client, u16 *status) | 1530 | static bool lm90_is_tripped(struct i2c_client *client, u16 *status) |
1465 | { | 1531 | { |
1466 | struct lm90_data *data = i2c_get_clientdata(client); | 1532 | struct lm90_data *data = i2c_get_clientdata(client); |
1467 | u8 st, st2 = 0; | 1533 | int st, st2 = 0; |
1468 | 1534 | ||
1469 | lm90_read_reg(client, LM90_REG_R_STATUS, &st); | 1535 | st = lm90_read_reg(client, LM90_REG_R_STATUS); |
1536 | if (st < 0) | ||
1537 | return false; | ||
1470 | 1538 | ||
1471 | if (data->kind == max6696) | 1539 | if (data->kind == max6696) { |
1472 | lm90_read_reg(client, MAX6696_REG_R_STATUS2, &st2); | 1540 | st2 = lm90_read_reg(client, MAX6696_REG_R_STATUS2); |
1541 | if (st2 < 0) | ||
1542 | return false; | ||
1543 | } | ||
1473 | 1544 | ||
1474 | *status = st | (st2 << 8); | 1545 | *status = st | (st2 << 8); |
1475 | 1546 | ||
@@ -1571,7 +1642,11 @@ static int lm90_probe(struct i2c_client *client, | |||
1571 | data->max_convrate = lm90_params[data->kind].max_convrate; | 1642 | data->max_convrate = lm90_params[data->kind].max_convrate; |
1572 | 1643 | ||
1573 | /* Initialize the LM90 chip */ | 1644 | /* Initialize the LM90 chip */ |
1574 | lm90_init_client(client, data); | 1645 | err = lm90_init_client(client, data); |
1646 | if (err < 0) { | ||
1647 | dev_err(dev, "Failed to initialize device\n"); | ||
1648 | return err; | ||
1649 | } | ||
1575 | 1650 | ||
1576 | /* Register sysfs hooks */ | 1651 | /* Register sysfs hooks */ |
1577 | data->groups[groups++] = &lm90_group; | 1652 | data->groups[groups++] = &lm90_group; |
@@ -1627,13 +1702,16 @@ static void lm90_alert(struct i2c_client *client, unsigned int flag) | |||
1627 | */ | 1702 | */ |
1628 | struct lm90_data *data = i2c_get_clientdata(client); | 1703 | struct lm90_data *data = i2c_get_clientdata(client); |
1629 | 1704 | ||
1630 | if ((data->flags & LM90_HAVE_BROKEN_ALERT) | 1705 | if ((data->flags & LM90_HAVE_BROKEN_ALERT) && |
1631 | && (alarms & data->alert_alarms)) { | 1706 | (alarms & data->alert_alarms)) { |
1632 | u8 config; | 1707 | int config; |
1708 | |||
1633 | dev_dbg(&client->dev, "Disabling ALERT#\n"); | 1709 | dev_dbg(&client->dev, "Disabling ALERT#\n"); |
1634 | lm90_read_reg(client, LM90_REG_R_CONFIG1, &config); | 1710 | config = lm90_read_reg(client, LM90_REG_R_CONFIG1); |
1635 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, | 1711 | if (config >= 0) |
1636 | config | 0x80); | 1712 | i2c_smbus_write_byte_data(client, |
1713 | LM90_REG_W_CONFIG1, | ||
1714 | config | 0x80); | ||
1637 | } | 1715 | } |
1638 | } else { | 1716 | } else { |
1639 | dev_info(&client->dev, "Everything OK\n"); | 1717 | dev_info(&client->dev, "Everything OK\n"); |