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.c327
1 files changed, 182 insertions, 145 deletions
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index 1aff7575799d..7cc2708871ab 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-2010 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
@@ -93,12 +93,8 @@
93static const unsigned short normal_i2c[] = { 93static const unsigned short normal_i2c[] = {
94 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END }; 94 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END };
95 95
96/* 96enum chips { lm90, adm1032, lm99, lm86, max6657, adt7461, max6680, max6646,
97 * Insmod parameters 97 w83l771 };
98 */
99
100I2C_CLIENT_INSMOD_8(lm90, adm1032, lm99, lm86, max6657, adt7461, max6680,
101 max6646);
102 98
103/* 99/*
104 * The LM90 registers 100 * The LM90 registers
@@ -152,11 +148,11 @@ I2C_CLIENT_INSMOD_8(lm90, adm1032, lm99, lm86, max6657, adt7461, max6680,
152 * Functions declaration 148 * Functions declaration
153 */ 149 */
154 150
155static int lm90_detect(struct i2c_client *client, int kind, 151static int lm90_detect(struct i2c_client *client, struct i2c_board_info *info);
156 struct i2c_board_info *info);
157static int lm90_probe(struct i2c_client *client, 152static int lm90_probe(struct i2c_client *client,
158 const struct i2c_device_id *id); 153 const struct i2c_device_id *id);
159static void lm90_init_client(struct i2c_client *client); 154static void lm90_init_client(struct i2c_client *client);
155static void lm90_alert(struct i2c_client *client, unsigned int flag);
160static int lm90_remove(struct i2c_client *client); 156static int lm90_remove(struct i2c_client *client);
161static struct lm90_data *lm90_update_device(struct device *dev); 157static struct lm90_data *lm90_update_device(struct device *dev);
162 158
@@ -179,6 +175,7 @@ static const struct i2c_device_id lm90_id[] = {
179 { "max6659", max6657 }, 175 { "max6659", max6657 },
180 { "max6680", max6680 }, 176 { "max6680", max6680 },
181 { "max6681", max6680 }, 177 { "max6681", max6680 },
178 { "w83l771", w83l771 },
182 { } 179 { }
183}; 180};
184MODULE_DEVICE_TABLE(i2c, lm90_id); 181MODULE_DEVICE_TABLE(i2c, lm90_id);
@@ -190,9 +187,10 @@ static struct i2c_driver lm90_driver = {
190 }, 187 },
191 .probe = lm90_probe, 188 .probe = lm90_probe,
192 .remove = lm90_remove, 189 .remove = lm90_remove,
190 .alert = lm90_alert,
193 .id_table = lm90_id, 191 .id_table = lm90_id,
194 .detect = lm90_detect, 192 .detect = lm90_detect,
195 .address_data = &addr_data, 193 .address_list = normal_i2c,
196}; 194};
197 195
198/* 196/*
@@ -207,6 +205,9 @@ struct lm90_data {
207 int kind; 205 int kind;
208 int flags; 206 int flags;
209 207
208 u8 config_orig; /* Original configuration register value */
209 u8 alert_alarms; /* Which alarm bits trigger ALERT# */
210
210 /* registers values */ 211 /* registers values */
211 s8 temp8[4]; /* 0: local low limit 212 s8 temp8[4]; /* 0: local low limit
212 1: local high limit 213 1: local high limit
@@ -656,159 +657,131 @@ static int lm90_read_reg(struct i2c_client* client, u8 reg, u8 *value)
656} 657}
657 658
658/* Return 0 if detection is successful, -ENODEV otherwise */ 659/* Return 0 if detection is successful, -ENODEV otherwise */
659static int lm90_detect(struct i2c_client *new_client, int kind, 660static int lm90_detect(struct i2c_client *new_client,
660 struct i2c_board_info *info) 661 struct i2c_board_info *info)
661{ 662{
662 struct i2c_adapter *adapter = new_client->adapter; 663 struct i2c_adapter *adapter = new_client->adapter;
663 int address = new_client->addr; 664 int address = new_client->addr;
664 const char *name = ""; 665 const char *name = NULL;
666 int man_id, chip_id, reg_config1, reg_convrate;
665 667
666 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 668 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
667 return -ENODEV; 669 return -ENODEV;
668 670
669 /* 671 /* detection and identification */
670 * Now we do the remaining detection. A negative kind means that 672 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 673 LM90_REG_R_MAN_ID)) < 0
689 || (chip_id = i2c_smbus_read_byte_data(new_client, 674 || (chip_id = i2c_smbus_read_byte_data(new_client,
690 LM90_REG_R_CHIP_ID)) < 0 675 LM90_REG_R_CHIP_ID)) < 0
691 || (reg_config1 = i2c_smbus_read_byte_data(new_client, 676 || (reg_config1 = i2c_smbus_read_byte_data(new_client,
692 LM90_REG_R_CONFIG1)) < 0 677 LM90_REG_R_CONFIG1)) < 0
693 || (reg_convrate = i2c_smbus_read_byte_data(new_client, 678 || (reg_convrate = i2c_smbus_read_byte_data(new_client,
694 LM90_REG_R_CONVRATE)) < 0) 679 LM90_REG_R_CONVRATE)) < 0)
680 return -ENODEV;
681
682 if ((address == 0x4C || address == 0x4D)
683 && man_id == 0x01) { /* National Semiconductor */
684 int reg_config2;
685
686 reg_config2 = i2c_smbus_read_byte_data(new_client,
687 LM90_REG_R_CONFIG2);
688 if (reg_config2 < 0)
695 return -ENODEV; 689 return -ENODEV;
696 690
697 if ((address == 0x4C || address == 0x4D) 691 if ((reg_config1 & 0x2A) == 0x00
698 && man_id == 0x01) { /* National Semiconductor */ 692 && (reg_config2 & 0xF8) == 0x00
699 int reg_config2; 693 && reg_convrate <= 0x09) {
700 694 if (address == 0x4C
701 if ((reg_config2 = i2c_smbus_read_byte_data(new_client, 695 && (chip_id & 0xF0) == 0x20) { /* LM90 */
702 LM90_REG_R_CONFIG2)) < 0) 696 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 697 } else
759 /* The chip_id register of the MAX6680 and MAX6681 698 if ((chip_id & 0xF0) == 0x30) { /* LM89/LM99 */
760 * holds the revision of the chip. 699 name = "lm99";
761 * the lowest bit of the config1 register is unused 700 dev_info(&adapter->dev,
762 * and should return zero when read, so should the 701 "Assuming LM99 chip at 0x%02x\n",
763 * second to last bit of config1 (software reset) 702 address);
764 */ 703 dev_info(&adapter->dev,
765 if (chip_id == 0x01 704 "If it is an LM89, instantiate it "
766 && (reg_config1 & 0x03) == 0x00 705 "with the new_device sysfs "
767 && reg_convrate <= 0x07) { 706 "interface\n");
768 kind = max6680;
769 } else 707 } else
770 /* The chip_id register of the MAX6646/6647/6649 708 if (address == 0x4C
771 * holds the revision of the chip. 709 && (chip_id & 0xF0) == 0x10) { /* LM86 */
772 * The lowest 6 bits of the config1 register are 710 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 } 711 }
780 } 712 }
781 713 } else
782 if (kind <= 0) { /* identification failed */ 714 if ((address == 0x4C || address == 0x4D)
783 dev_dbg(&adapter->dev, 715 && man_id == 0x41) { /* Analog Devices */
784 "Unsupported chip at 0x%02x (man_id=0x%02X, " 716 if ((chip_id & 0xF0) == 0x40 /* ADM1032 */
785 "chip_id=0x%02X)\n", address, man_id, chip_id); 717 && (reg_config1 & 0x3F) == 0x00
786 return -ENODEV; 718 && reg_convrate <= 0x0A) {
719 name = "adm1032";
720 /* The ADM1032 supports PEC, but only if combined
721 transactions are not used. */
722 if (i2c_check_functionality(adapter,
723 I2C_FUNC_SMBUS_BYTE))
724 info->flags |= I2C_CLIENT_PEC;
725 } else
726 if (chip_id == 0x51 /* ADT7461 */
727 && (reg_config1 & 0x1B) == 0x00
728 && reg_convrate <= 0x0A) {
729 name = "adt7461";
730 }
731 } else
732 if (man_id == 0x4D) { /* Maxim */
733 /*
734 * The MAX6657, MAX6658 and MAX6659 do NOT have a chip_id
735 * register. Reading from that address will return the last
736 * read value, which in our case is those of the man_id
737 * register. Likewise, the config1 register seems to lack a
738 * low nibble, so the value will be those of the previous
739 * read, so in our case those of the man_id register.
740 */
741 if (chip_id == man_id
742 && (address == 0x4C || address == 0x4D)
743 && (reg_config1 & 0x1F) == (man_id & 0x0F)
744 && reg_convrate <= 0x09) {
745 name = "max6657";
746 } else
747 /*
748 * The chip_id register of the MAX6680 and MAX6681 holds the
749 * revision of the chip. The lowest bit of the config1 register
750 * is unused and should return zero when read, so should the
751 * second to last bit of config1 (software reset).
752 */
753 if (chip_id == 0x01
754 && (reg_config1 & 0x03) == 0x00
755 && reg_convrate <= 0x07) {
756 name = "max6680";
757 } else
758 /*
759 * The chip_id register of the MAX6646/6647/6649 holds the
760 * revision of the chip. The lowest 6 bits of the config1
761 * register are unused and should return zero when read.
762 */
763 if (chip_id == 0x59
764 && (reg_config1 & 0x3f) == 0x00
765 && reg_convrate <= 0x07) {
766 name = "max6646";
767 }
768 } else
769 if (address == 0x4C
770 && man_id == 0x5C) { /* Winbond/Nuvoton */
771 if ((chip_id & 0xFE) == 0x10 /* W83L771AWG/ASG */
772 && (reg_config1 & 0x2A) == 0x00
773 && reg_convrate <= 0x08) {
774 name = "w83l771";
787 } 775 }
788 } 776 }
789 777
790 /* Fill the i2c board info */ 778 if (!name) { /* identification failed */
791 if (kind == lm90) { 779 dev_dbg(&adapter->dev,
792 name = "lm90"; 780 "Unsupported chip at 0x%02x (man_id=0x%02X, "
793 } else if (kind == adm1032) { 781 "chip_id=0x%02X)\n", address, man_id, chip_id);
794 name = "adm1032"; 782 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 } 783 }
784
812 strlcpy(info->type, name, I2C_NAME_SIZE); 785 strlcpy(info->type, name, I2C_NAME_SIZE);
813 786
814 return 0; 787 return 0;
@@ -836,6 +809,19 @@ static int lm90_probe(struct i2c_client *new_client,
836 new_client->flags &= ~I2C_CLIENT_PEC; 809 new_client->flags &= ~I2C_CLIENT_PEC;
837 } 810 }
838 811
812 /* Different devices have different alarm bits triggering the
813 * ALERT# output */
814 switch (data->kind) {
815 case lm90:
816 case lm99:
817 case lm86:
818 data->alert_alarms = 0x7b;
819 break;
820 default:
821 data->alert_alarms = 0x7c;
822 break;
823 }
824
839 /* Initialize the LM90 chip */ 825 /* Initialize the LM90 chip */
840 lm90_init_client(new_client); 826 lm90_init_client(new_client);
841 827
@@ -872,7 +858,7 @@ exit:
872 858
873static void lm90_init_client(struct i2c_client *client) 859static void lm90_init_client(struct i2c_client *client)
874{ 860{
875 u8 config, config_orig; 861 u8 config;
876 struct lm90_data *data = i2c_get_clientdata(client); 862 struct lm90_data *data = i2c_get_clientdata(client);
877 863
878 /* 864 /*
@@ -884,7 +870,7 @@ static void lm90_init_client(struct i2c_client *client)
884 dev_warn(&client->dev, "Initialization failed!\n"); 870 dev_warn(&client->dev, "Initialization failed!\n");
885 return; 871 return;
886 } 872 }
887 config_orig = config; 873 data->config_orig = config;
888 874
889 /* Check Temperature Range Select */ 875 /* Check Temperature Range Select */
890 if (data->kind == adt7461) { 876 if (data->kind == adt7461) {
@@ -902,7 +888,7 @@ static void lm90_init_client(struct i2c_client *client)
902 } 888 }
903 889
904 config &= 0xBF; /* run */ 890 config &= 0xBF; /* run */
905 if (config != config_orig) /* Only write if changed */ 891 if (config != data->config_orig) /* Only write if changed */
906 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); 892 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config);
907} 893}
908 894
@@ -917,10 +903,46 @@ static int lm90_remove(struct i2c_client *client)
917 device_remove_file(&client->dev, 903 device_remove_file(&client->dev,
918 &sensor_dev_attr_temp2_offset.dev_attr); 904 &sensor_dev_attr_temp2_offset.dev_attr);
919 905
906 /* Restore initial configuration */
907 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
908 data->config_orig);
909
920 kfree(data); 910 kfree(data);
921 return 0; 911 return 0;
922} 912}
923 913
914static void lm90_alert(struct i2c_client *client, unsigned int flag)
915{
916 struct lm90_data *data = i2c_get_clientdata(client);
917 u8 config, alarms;
918
919 lm90_read_reg(client, LM90_REG_R_STATUS, &alarms);
920 if ((alarms & 0x7f) == 0) {
921 dev_info(&client->dev, "Everything OK\n");
922 } else {
923 if (alarms & 0x61)
924 dev_warn(&client->dev,
925 "temp%d out of range, please check!\n", 1);
926 if (alarms & 0x1a)
927 dev_warn(&client->dev,
928 "temp%d out of range, please check!\n", 2);
929 if (alarms & 0x04)
930 dev_warn(&client->dev,
931 "temp%d diode open, please check!\n", 2);
932
933 /* Disable ALERT# output, because these chips don't implement
934 SMBus alert correctly; they should only hold the alert line
935 low briefly. */
936 if ((data->kind == adm1032 || data->kind == adt7461)
937 && (alarms & data->alert_alarms)) {
938 dev_dbg(&client->dev, "Disabling ALERT#\n");
939 lm90_read_reg(client, LM90_REG_R_CONFIG1, &config);
940 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
941 config | 0x80);
942 }
943 }
944}
945
924static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value) 946static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value)
925{ 947{
926 int err; 948 int err;
@@ -1008,6 +1030,21 @@ static struct lm90_data *lm90_update_device(struct device *dev)
1008 } 1030 }
1009 lm90_read_reg(client, LM90_REG_R_STATUS, &data->alarms); 1031 lm90_read_reg(client, LM90_REG_R_STATUS, &data->alarms);
1010 1032
1033 /* Re-enable ALERT# output if it was originally enabled and
1034 * relevant alarms are all clear */
1035 if ((data->config_orig & 0x80) == 0
1036 && (data->alarms & data->alert_alarms) == 0) {
1037 u8 config;
1038
1039 lm90_read_reg(client, LM90_REG_R_CONFIG1, &config);
1040 if (config & 0x80) {
1041 dev_dbg(&client->dev, "Re-enabling ALERT#\n");
1042 i2c_smbus_write_byte_data(client,
1043 LM90_REG_W_CONFIG1,
1044 config & ~0x80);
1045 }
1046 }
1047
1011 data->last_updated = jiffies; 1048 data->last_updated = jiffies;
1012 data->valid = 1; 1049 data->valid = 1;
1013 } 1050 }