diff options
author | Jean Delvare <khali@linux-fr.org> | 2009-12-09 14:35:53 -0500 |
---|---|---|
committer | Jean Delvare <khali@linux-fr.org> | 2009-12-09 14:35:53 -0500 |
commit | 8f2fa77c53ba8c10696143c21b4111d449c85fb2 (patch) | |
tree | 288c5f0b58bbe69318658d405a71ea71c5d9b9f8 /drivers | |
parent | d42a2eb5ad9766fac96f27af93b1634e4ffde220 (diff) |
hwmon: (lm90) Clean up detect function
As kind is now hard-coded to -1, there is room for code clean-ups.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/hwmon/lm90.c | 228 |
1 files changed, 96 insertions, 132 deletions
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 1aff7575799..b7c905f50ed 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * lm90.c - Part of lm_sensors, Linux kernel modules for hardware | 2 | * lm90.c - Part of lm_sensors, Linux kernel modules for hardware |
3 | * monitoring | 3 | * monitoring |
4 | * Copyright (C) 2003-2008 Jean Delvare <khali@linux-fr.org> | 4 | * Copyright (C) 2003-2009 Jean Delvare <khali@linux-fr.org> |
5 | * | 5 | * |
6 | * Based on the lm83 driver. The LM90 is a sensor chip made by National | 6 | * Based on the lm83 driver. The LM90 is a sensor chip made by National |
7 | * Semiconductor. It reports up to two temperatures (its own plus up to | 7 | * Semiconductor. It reports up to two temperatures (its own plus up to |
@@ -661,154 +661,118 @@ static int lm90_detect(struct i2c_client *new_client, int kind, | |||
661 | { | 661 | { |
662 | struct i2c_adapter *adapter = new_client->adapter; | 662 | struct i2c_adapter *adapter = new_client->adapter; |
663 | int address = new_client->addr; | 663 | int address = new_client->addr; |
664 | const char *name = ""; | 664 | const char *name = NULL; |
665 | int man_id, chip_id, reg_config1, reg_convrate; | ||
665 | 666 | ||
666 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 667 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
667 | return -ENODEV; | 668 | return -ENODEV; |
668 | 669 | ||
669 | /* | 670 | /* detection and identification */ |
670 | * Now we do the remaining detection. A negative kind means that | 671 | if ((man_id = i2c_smbus_read_byte_data(new_client, |
671 | * the driver was loaded with no force parameter (default), so we | ||
672 | * must both detect and identify the chip. A zero kind means that | ||
673 | * the driver was loaded with the force parameter, the detection | ||
674 | * step shall be skipped. A positive kind means that the driver | ||
675 | * was loaded with the force parameter and a given kind of chip is | ||
676 | * requested, so both the detection and the identification steps | ||
677 | * are skipped. | ||
678 | */ | ||
679 | |||
680 | /* Default to an LM90 if forced */ | ||
681 | if (kind == 0) | ||
682 | kind = lm90; | ||
683 | |||
684 | if (kind < 0) { /* detection and identification */ | ||
685 | int man_id, chip_id, reg_config1, reg_convrate; | ||
686 | |||
687 | if ((man_id = i2c_smbus_read_byte_data(new_client, | ||
688 | LM90_REG_R_MAN_ID)) < 0 | 672 | LM90_REG_R_MAN_ID)) < 0 |
689 | || (chip_id = i2c_smbus_read_byte_data(new_client, | 673 | || (chip_id = i2c_smbus_read_byte_data(new_client, |
690 | LM90_REG_R_CHIP_ID)) < 0 | 674 | LM90_REG_R_CHIP_ID)) < 0 |
691 | || (reg_config1 = i2c_smbus_read_byte_data(new_client, | 675 | || (reg_config1 = i2c_smbus_read_byte_data(new_client, |
692 | LM90_REG_R_CONFIG1)) < 0 | 676 | LM90_REG_R_CONFIG1)) < 0 |
693 | || (reg_convrate = i2c_smbus_read_byte_data(new_client, | 677 | || (reg_convrate = i2c_smbus_read_byte_data(new_client, |
694 | LM90_REG_R_CONVRATE)) < 0) | 678 | LM90_REG_R_CONVRATE)) < 0) |
679 | return -ENODEV; | ||
680 | |||
681 | if ((address == 0x4C || address == 0x4D) | ||
682 | && man_id == 0x01) { /* National Semiconductor */ | ||
683 | int reg_config2; | ||
684 | |||
685 | reg_config2 = i2c_smbus_read_byte_data(new_client, | ||
686 | LM90_REG_R_CONFIG2); | ||
687 | if (reg_config2 < 0) | ||
695 | return -ENODEV; | 688 | return -ENODEV; |
696 | 689 | ||
697 | if ((address == 0x4C || address == 0x4D) | 690 | if ((reg_config1 & 0x2A) == 0x00 |
698 | && man_id == 0x01) { /* National Semiconductor */ | 691 | && (reg_config2 & 0xF8) == 0x00 |
699 | int reg_config2; | 692 | && reg_convrate <= 0x09) { |
700 | 693 | if (address == 0x4C | |
701 | if ((reg_config2 = i2c_smbus_read_byte_data(new_client, | 694 | && (chip_id & 0xF0) == 0x20) { /* LM90 */ |
702 | LM90_REG_R_CONFIG2)) < 0) | 695 | name = "lm90"; |
703 | return -ENODEV; | ||
704 | |||
705 | if ((reg_config1 & 0x2A) == 0x00 | ||
706 | && (reg_config2 & 0xF8) == 0x00 | ||
707 | && reg_convrate <= 0x09) { | ||
708 | if (address == 0x4C | ||
709 | && (chip_id & 0xF0) == 0x20) { /* LM90 */ | ||
710 | kind = lm90; | ||
711 | } else | ||
712 | if ((chip_id & 0xF0) == 0x30) { /* LM89/LM99 */ | ||
713 | kind = lm99; | ||
714 | dev_info(&adapter->dev, | ||
715 | "Assuming LM99 chip at " | ||
716 | "0x%02x\n", address); | ||
717 | dev_info(&adapter->dev, | ||
718 | "If it is an LM89, pass " | ||
719 | "force_lm86=%d,0x%02x when " | ||
720 | "loading the lm90 driver\n", | ||
721 | i2c_adapter_id(adapter), | ||
722 | address); | ||
723 | } else | ||
724 | if (address == 0x4C | ||
725 | && (chip_id & 0xF0) == 0x10) { /* LM86 */ | ||
726 | kind = lm86; | ||
727 | } | ||
728 | } | ||
729 | } else | ||
730 | if ((address == 0x4C || address == 0x4D) | ||
731 | && man_id == 0x41) { /* Analog Devices */ | ||
732 | if ((chip_id & 0xF0) == 0x40 /* ADM1032 */ | ||
733 | && (reg_config1 & 0x3F) == 0x00 | ||
734 | && reg_convrate <= 0x0A) { | ||
735 | kind = adm1032; | ||
736 | } else | ||
737 | if (chip_id == 0x51 /* ADT7461 */ | ||
738 | && (reg_config1 & 0x1B) == 0x00 | ||
739 | && reg_convrate <= 0x0A) { | ||
740 | kind = adt7461; | ||
741 | } | ||
742 | } else | ||
743 | if (man_id == 0x4D) { /* Maxim */ | ||
744 | /* | ||
745 | * The MAX6657, MAX6658 and MAX6659 do NOT have a | ||
746 | * chip_id register. Reading from that address will | ||
747 | * return the last read value, which in our case is | ||
748 | * those of the man_id register. Likewise, the config1 | ||
749 | * register seems to lack a low nibble, so the value | ||
750 | * will be those of the previous read, so in our case | ||
751 | * those of the man_id register. | ||
752 | */ | ||
753 | if (chip_id == man_id | ||
754 | && (address == 0x4C || address == 0x4D) | ||
755 | && (reg_config1 & 0x1F) == (man_id & 0x0F) | ||
756 | && reg_convrate <= 0x09) { | ||
757 | kind = max6657; | ||
758 | } else | 696 | } else |
759 | /* The chip_id register of the MAX6680 and MAX6681 | 697 | if ((chip_id & 0xF0) == 0x30) { /* LM89/LM99 */ |
760 | * holds the revision of the chip. | 698 | name = "lm99"; |
761 | * the lowest bit of the config1 register is unused | 699 | dev_info(&adapter->dev, |
762 | * and should return zero when read, so should the | 700 | "Assuming LM99 chip at 0x%02x\n", |
763 | * second to last bit of config1 (software reset) | 701 | address); |
764 | */ | 702 | dev_info(&adapter->dev, |
765 | if (chip_id == 0x01 | 703 | "If it is an LM89, instantiate it " |
766 | && (reg_config1 & 0x03) == 0x00 | 704 | "with the new_device sysfs " |
767 | && reg_convrate <= 0x07) { | 705 | "interface\n"); |
768 | kind = max6680; | ||
769 | } else | 706 | } else |
770 | /* The chip_id register of the MAX6646/6647/6649 | 707 | if (address == 0x4C |
771 | * holds the revision of the chip. | 708 | && (chip_id & 0xF0) == 0x10) { /* LM86 */ |
772 | * The lowest 6 bits of the config1 register are | 709 | name = "lm86"; |
773 | * unused and should return zero when read. | ||
774 | */ | ||
775 | if (chip_id == 0x59 | ||
776 | && (reg_config1 & 0x3f) == 0x00 | ||
777 | && reg_convrate <= 0x07) { | ||
778 | kind = max6646; | ||
779 | } | 710 | } |
780 | } | 711 | } |
781 | 712 | } else | |
782 | if (kind <= 0) { /* identification failed */ | 713 | if ((address == 0x4C || address == 0x4D) |
783 | dev_dbg(&adapter->dev, | 714 | && man_id == 0x41) { /* Analog Devices */ |
784 | "Unsupported chip at 0x%02x (man_id=0x%02X, " | 715 | if ((chip_id & 0xF0) == 0x40 /* ADM1032 */ |
785 | "chip_id=0x%02X)\n", address, man_id, chip_id); | 716 | && (reg_config1 & 0x3F) == 0x00 |
786 | return -ENODEV; | 717 | && reg_convrate <= 0x0A) { |
718 | name = "adm1032"; | ||
719 | /* The ADM1032 supports PEC, but only if combined | ||
720 | transactions are not used. */ | ||
721 | if (i2c_check_functionality(adapter, | ||
722 | I2C_FUNC_SMBUS_BYTE)) | ||
723 | info->flags |= I2C_CLIENT_PEC; | ||
724 | } else | ||
725 | if (chip_id == 0x51 /* ADT7461 */ | ||
726 | && (reg_config1 & 0x1B) == 0x00 | ||
727 | && reg_convrate <= 0x0A) { | ||
728 | name = "adt7461"; | ||
729 | } | ||
730 | } else | ||
731 | if (man_id == 0x4D) { /* Maxim */ | ||
732 | /* | ||
733 | * The MAX6657, MAX6658 and MAX6659 do NOT have a chip_id | ||
734 | * register. Reading from that address will return the last | ||
735 | * read value, which in our case is those of the man_id | ||
736 | * register. Likewise, the config1 register seems to lack a | ||
737 | * low nibble, so the value will be those of the previous | ||
738 | * read, so in our case those of the man_id register. | ||
739 | */ | ||
740 | if (chip_id == man_id | ||
741 | && (address == 0x4C || address == 0x4D) | ||
742 | && (reg_config1 & 0x1F) == (man_id & 0x0F) | ||
743 | && reg_convrate <= 0x09) { | ||
744 | name = "max6657"; | ||
745 | } else | ||
746 | /* | ||
747 | * The chip_id register of the MAX6680 and MAX6681 holds the | ||
748 | * revision of the chip. The lowest bit of the config1 register | ||
749 | * is unused and should return zero when read, so should the | ||
750 | * second to last bit of config1 (software reset). | ||
751 | */ | ||
752 | if (chip_id == 0x01 | ||
753 | && (reg_config1 & 0x03) == 0x00 | ||
754 | && reg_convrate <= 0x07) { | ||
755 | name = "max6680"; | ||
756 | } else | ||
757 | /* | ||
758 | * The chip_id register of the MAX6646/6647/6649 holds the | ||
759 | * revision of the chip. The lowest 6 bits of the config1 | ||
760 | * register are unused and should return zero when read. | ||
761 | */ | ||
762 | if (chip_id == 0x59 | ||
763 | && (reg_config1 & 0x3f) == 0x00 | ||
764 | && reg_convrate <= 0x07) { | ||
765 | name = "max6646"; | ||
787 | } | 766 | } |
788 | } | 767 | } |
789 | 768 | ||
790 | /* Fill the i2c board info */ | 769 | if (!name) { /* identification failed */ |
791 | if (kind == lm90) { | 770 | dev_dbg(&adapter->dev, |
792 | name = "lm90"; | 771 | "Unsupported chip at 0x%02x (man_id=0x%02X, " |
793 | } else if (kind == adm1032) { | 772 | "chip_id=0x%02X)\n", address, man_id, chip_id); |
794 | name = "adm1032"; | 773 | return -ENODEV; |
795 | /* The ADM1032 supports PEC, but only if combined | ||
796 | transactions are not used. */ | ||
797 | if (i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) | ||
798 | info->flags |= I2C_CLIENT_PEC; | ||
799 | } else if (kind == lm99) { | ||
800 | name = "lm99"; | ||
801 | } else if (kind == lm86) { | ||
802 | name = "lm86"; | ||
803 | } else if (kind == max6657) { | ||
804 | name = "max6657"; | ||
805 | } else if (kind == max6680) { | ||
806 | name = "max6680"; | ||
807 | } else if (kind == adt7461) { | ||
808 | name = "adt7461"; | ||
809 | } else if (kind == max6646) { | ||
810 | name = "max6646"; | ||
811 | } | 774 | } |
775 | |||
812 | strlcpy(info->type, name, I2C_NAME_SIZE); | 776 | strlcpy(info->type, name, I2C_NAME_SIZE); |
813 | 777 | ||
814 | return 0; | 778 | return 0; |