diff options
Diffstat (limited to 'drivers/hwmon/lm85.c')
-rw-r--r-- | drivers/hwmon/lm85.c | 352 |
1 files changed, 172 insertions, 180 deletions
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c index 12d446f54f97..3ff0285396fa 100644 --- a/drivers/hwmon/lm85.c +++ b/drivers/hwmon/lm85.c | |||
@@ -5,6 +5,7 @@ | |||
5 | Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com> | 5 | Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com> |
6 | Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de> | 6 | Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de> |
7 | Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com> | 7 | Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com> |
8 | Copyright (C) 2007, 2008 Jean Delvare <khali@linux-fr.org> | ||
8 | 9 | ||
9 | Chip details at <http://www.national.com/ds/LM/LM85.pdf> | 10 | Chip details at <http://www.national.com/ds/LM/LM85.pdf> |
10 | 11 | ||
@@ -173,40 +174,39 @@ static int RANGE_TO_REG(int range) | |||
173 | { | 174 | { |
174 | int i; | 175 | int i; |
175 | 176 | ||
176 | if (range >= lm85_range_map[15]) | ||
177 | return 15; | ||
178 | |||
179 | /* Find the closest match */ | 177 | /* Find the closest match */ |
180 | for (i = 14; i >= 0; --i) { | 178 | for (i = 0; i < 15; ++i) { |
181 | if (range >= lm85_range_map[i]) { | 179 | if (range <= (lm85_range_map[i] + lm85_range_map[i + 1]) / 2) |
182 | if ((lm85_range_map[i + 1] - range) < | 180 | break; |
183 | (range - lm85_range_map[i])) | ||
184 | return i + 1; | ||
185 | return i; | ||
186 | } | ||
187 | } | 181 | } |
188 | 182 | ||
189 | return 0; | 183 | return i; |
190 | } | 184 | } |
191 | #define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f] | 185 | #define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f] |
192 | 186 | ||
193 | /* These are the PWM frequency encodings */ | 187 | /* These are the PWM frequency encodings */ |
194 | static const int lm85_freq_map[] = { /* .1 Hz */ | 188 | static const int lm85_freq_map[8] = { /* 1 Hz */ |
195 | 100, 150, 230, 300, 380, 470, 620, 940 | 189 | 10, 15, 23, 30, 38, 47, 61, 94 |
190 | }; | ||
191 | static const int adm1027_freq_map[8] = { /* 1 Hz */ | ||
192 | 11, 15, 22, 29, 35, 44, 59, 88 | ||
196 | }; | 193 | }; |
197 | 194 | ||
198 | static int FREQ_TO_REG(int freq) | 195 | static int FREQ_TO_REG(const int *map, int freq) |
199 | { | 196 | { |
200 | int i; | 197 | int i; |
201 | 198 | ||
202 | if (freq >= lm85_freq_map[7]) | 199 | /* Find the closest match */ |
203 | return 7; | ||
204 | for (i = 0; i < 7; ++i) | 200 | for (i = 0; i < 7; ++i) |
205 | if (freq <= lm85_freq_map[i]) | 201 | if (freq <= (map[i] + map[i + 1]) / 2) |
206 | break; | 202 | break; |
207 | return i; | 203 | return i; |
208 | } | 204 | } |
209 | #define FREQ_FROM_REG(val) lm85_freq_map[(val) & 0x07] | 205 | |
206 | static int FREQ_FROM_REG(const int *map, u8 reg) | ||
207 | { | ||
208 | return map[reg & 0x07]; | ||
209 | } | ||
210 | 210 | ||
211 | /* Since we can't use strings, I'm abusing these numbers | 211 | /* Since we can't use strings, I'm abusing these numbers |
212 | * to stand in for the following meanings: | 212 | * to stand in for the following meanings: |
@@ -275,7 +275,6 @@ struct lm85_zone { | |||
275 | 275 | ||
276 | struct lm85_autofan { | 276 | struct lm85_autofan { |
277 | u8 config; /* Register value */ | 277 | u8 config; /* Register value */ |
278 | u8 freq; /* PWM frequency, encoded */ | ||
279 | u8 min_pwm; /* Minimum PWM value, encoded */ | 278 | u8 min_pwm; /* Minimum PWM value, encoded */ |
280 | u8 min_off; /* Min PWM or OFF below "limit", flag */ | 279 | u8 min_off; /* Min PWM or OFF below "limit", flag */ |
281 | }; | 280 | }; |
@@ -283,8 +282,8 @@ struct lm85_autofan { | |||
283 | /* For each registered chip, we need to keep some data in memory. | 282 | /* For each registered chip, we need to keep some data in memory. |
284 | The structure is dynamically allocated. */ | 283 | The structure is dynamically allocated. */ |
285 | struct lm85_data { | 284 | struct lm85_data { |
286 | struct i2c_client client; | ||
287 | struct device *hwmon_dev; | 285 | struct device *hwmon_dev; |
286 | const int *freq_map; | ||
288 | enum chips type; | 287 | enum chips type; |
289 | 288 | ||
290 | struct mutex update_lock; | 289 | struct mutex update_lock; |
@@ -301,6 +300,7 @@ struct lm85_data { | |||
301 | u16 fan[4]; /* Register value */ | 300 | u16 fan[4]; /* Register value */ |
302 | u16 fan_min[4]; /* Register value */ | 301 | u16 fan_min[4]; /* Register value */ |
303 | u8 pwm[3]; /* Register value */ | 302 | u8 pwm[3]; /* Register value */ |
303 | u8 pwm_freq[3]; /* Register encoding */ | ||
304 | u8 temp_ext[3]; /* Decoded values */ | 304 | u8 temp_ext[3]; /* Decoded values */ |
305 | u8 in_ext[8]; /* Decoded values */ | 305 | u8 in_ext[8]; /* Decoded values */ |
306 | u8 vid; /* Register value */ | 306 | u8 vid; /* Register value */ |
@@ -310,22 +310,40 @@ struct lm85_data { | |||
310 | struct lm85_zone zone[3]; | 310 | struct lm85_zone zone[3]; |
311 | }; | 311 | }; |
312 | 312 | ||
313 | static int lm85_attach_adapter(struct i2c_adapter *adapter); | 313 | static int lm85_detect(struct i2c_client *client, int kind, |
314 | static int lm85_detect(struct i2c_adapter *adapter, int address, | 314 | struct i2c_board_info *info); |
315 | int kind); | 315 | static int lm85_probe(struct i2c_client *client, |
316 | static int lm85_detach_client(struct i2c_client *client); | 316 | const struct i2c_device_id *id); |
317 | static int lm85_remove(struct i2c_client *client); | ||
317 | 318 | ||
318 | static int lm85_read_value(struct i2c_client *client, u8 reg); | 319 | static int lm85_read_value(struct i2c_client *client, u8 reg); |
319 | static void lm85_write_value(struct i2c_client *client, u8 reg, int value); | 320 | static void lm85_write_value(struct i2c_client *client, u8 reg, int value); |
320 | static struct lm85_data *lm85_update_device(struct device *dev); | 321 | static struct lm85_data *lm85_update_device(struct device *dev); |
321 | 322 | ||
322 | 323 | ||
324 | static const struct i2c_device_id lm85_id[] = { | ||
325 | { "adm1027", adm1027 }, | ||
326 | { "adt7463", adt7463 }, | ||
327 | { "lm85", any_chip }, | ||
328 | { "lm85b", lm85b }, | ||
329 | { "lm85c", lm85c }, | ||
330 | { "emc6d100", emc6d100 }, | ||
331 | { "emc6d101", emc6d100 }, | ||
332 | { "emc6d102", emc6d102 }, | ||
333 | { } | ||
334 | }; | ||
335 | MODULE_DEVICE_TABLE(i2c, lm85_id); | ||
336 | |||
323 | static struct i2c_driver lm85_driver = { | 337 | static struct i2c_driver lm85_driver = { |
338 | .class = I2C_CLASS_HWMON, | ||
324 | .driver = { | 339 | .driver = { |
325 | .name = "lm85", | 340 | .name = "lm85", |
326 | }, | 341 | }, |
327 | .attach_adapter = lm85_attach_adapter, | 342 | .probe = lm85_probe, |
328 | .detach_client = lm85_detach_client, | 343 | .remove = lm85_remove, |
344 | .id_table = lm85_id, | ||
345 | .detect = lm85_detect, | ||
346 | .address_data = &addr_data, | ||
329 | }; | 347 | }; |
330 | 348 | ||
331 | 349 | ||
@@ -528,11 +546,39 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute | |||
528 | return count; | 546 | return count; |
529 | } | 547 | } |
530 | 548 | ||
549 | static ssize_t show_pwm_freq(struct device *dev, | ||
550 | struct device_attribute *attr, char *buf) | ||
551 | { | ||
552 | int nr = to_sensor_dev_attr(attr)->index; | ||
553 | struct lm85_data *data = lm85_update_device(dev); | ||
554 | return sprintf(buf, "%d\n", FREQ_FROM_REG(data->freq_map, | ||
555 | data->pwm_freq[nr])); | ||
556 | } | ||
557 | |||
558 | static ssize_t set_pwm_freq(struct device *dev, | ||
559 | struct device_attribute *attr, const char *buf, size_t count) | ||
560 | { | ||
561 | int nr = to_sensor_dev_attr(attr)->index; | ||
562 | struct i2c_client *client = to_i2c_client(dev); | ||
563 | struct lm85_data *data = i2c_get_clientdata(client); | ||
564 | long val = simple_strtol(buf, NULL, 10); | ||
565 | |||
566 | mutex_lock(&data->update_lock); | ||
567 | data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map, val); | ||
568 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), | ||
569 | (data->zone[nr].range << 4) | ||
570 | | data->pwm_freq[nr]); | ||
571 | mutex_unlock(&data->update_lock); | ||
572 | return count; | ||
573 | } | ||
574 | |||
531 | #define show_pwm_reg(offset) \ | 575 | #define show_pwm_reg(offset) \ |
532 | static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ | 576 | static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ |
533 | show_pwm, set_pwm, offset - 1); \ | 577 | show_pwm, set_pwm, offset - 1); \ |
534 | static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ | 578 | static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ |
535 | show_pwm_enable, set_pwm_enable, offset - 1) | 579 | show_pwm_enable, set_pwm_enable, offset - 1); \ |
580 | static SENSOR_DEVICE_ATTR(pwm##offset##_freq, S_IRUGO | S_IWUSR, \ | ||
581 | show_pwm_freq, set_pwm_freq, offset - 1) | ||
536 | 582 | ||
537 | show_pwm_reg(1); | 583 | show_pwm_reg(1); |
538 | show_pwm_reg(2); | 584 | show_pwm_reg(2); |
@@ -761,31 +807,6 @@ static ssize_t set_pwm_auto_pwm_minctl(struct device *dev, | |||
761 | return count; | 807 | return count; |
762 | } | 808 | } |
763 | 809 | ||
764 | static ssize_t show_pwm_auto_pwm_freq(struct device *dev, | ||
765 | struct device_attribute *attr, char *buf) | ||
766 | { | ||
767 | int nr = to_sensor_dev_attr(attr)->index; | ||
768 | struct lm85_data *data = lm85_update_device(dev); | ||
769 | return sprintf(buf, "%d\n", FREQ_FROM_REG(data->autofan[nr].freq)); | ||
770 | } | ||
771 | |||
772 | static ssize_t set_pwm_auto_pwm_freq(struct device *dev, | ||
773 | struct device_attribute *attr, const char *buf, size_t count) | ||
774 | { | ||
775 | int nr = to_sensor_dev_attr(attr)->index; | ||
776 | struct i2c_client *client = to_i2c_client(dev); | ||
777 | struct lm85_data *data = i2c_get_clientdata(client); | ||
778 | long val = simple_strtol(buf, NULL, 10); | ||
779 | |||
780 | mutex_lock(&data->update_lock); | ||
781 | data->autofan[nr].freq = FREQ_TO_REG(val); | ||
782 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), | ||
783 | (data->zone[nr].range << 4) | ||
784 | | data->autofan[nr].freq); | ||
785 | mutex_unlock(&data->update_lock); | ||
786 | return count; | ||
787 | } | ||
788 | |||
789 | #define pwm_auto(offset) \ | 810 | #define pwm_auto(offset) \ |
790 | static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels, \ | 811 | static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels, \ |
791 | S_IRUGO | S_IWUSR, show_pwm_auto_channels, \ | 812 | S_IRUGO | S_IWUSR, show_pwm_auto_channels, \ |
@@ -795,10 +816,7 @@ static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_min, \ | |||
795 | set_pwm_auto_pwm_min, offset - 1); \ | 816 | set_pwm_auto_pwm_min, offset - 1); \ |
796 | static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_minctl, \ | 817 | static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_minctl, \ |
797 | S_IRUGO | S_IWUSR, show_pwm_auto_pwm_minctl, \ | 818 | S_IRUGO | S_IWUSR, show_pwm_auto_pwm_minctl, \ |
798 | set_pwm_auto_pwm_minctl, offset - 1); \ | 819 | set_pwm_auto_pwm_minctl, offset - 1) |
799 | static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_freq, \ | ||
800 | S_IRUGO | S_IWUSR, show_pwm_auto_pwm_freq, \ | ||
801 | set_pwm_auto_pwm_freq, offset - 1); | ||
802 | 820 | ||
803 | pwm_auto(1); | 821 | pwm_auto(1); |
804 | pwm_auto(2); | 822 | pwm_auto(2); |
@@ -867,7 +885,7 @@ static ssize_t set_temp_auto_temp_min(struct device *dev, | |||
867 | TEMP_FROM_REG(data->zone[nr].limit)); | 885 | TEMP_FROM_REG(data->zone[nr].limit)); |
868 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), | 886 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), |
869 | ((data->zone[nr].range & 0x0f) << 4) | 887 | ((data->zone[nr].range & 0x0f) << 4) |
870 | | (data->autofan[nr].freq & 0x07)); | 888 | | (data->pwm_freq[nr] & 0x07)); |
871 | 889 | ||
872 | /* Update temp_auto_hyst and temp_auto_off */ | 890 | /* Update temp_auto_hyst and temp_auto_off */ |
873 | data->zone[nr].hyst = HYST_TO_REG(TEMP_FROM_REG( | 891 | data->zone[nr].hyst = HYST_TO_REG(TEMP_FROM_REG( |
@@ -910,7 +928,7 @@ static ssize_t set_temp_auto_temp_max(struct device *dev, | |||
910 | val - min); | 928 | val - min); |
911 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), | 929 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), |
912 | ((data->zone[nr].range & 0x0f) << 4) | 930 | ((data->zone[nr].range & 0x0f) << 4) |
913 | | (data->autofan[nr].freq & 0x07)); | 931 | | (data->pwm_freq[nr] & 0x07)); |
914 | mutex_unlock(&data->update_lock); | 932 | mutex_unlock(&data->update_lock); |
915 | return count; | 933 | return count; |
916 | } | 934 | } |
@@ -957,13 +975,6 @@ temp_auto(1); | |||
957 | temp_auto(2); | 975 | temp_auto(2); |
958 | temp_auto(3); | 976 | temp_auto(3); |
959 | 977 | ||
960 | static int lm85_attach_adapter(struct i2c_adapter *adapter) | ||
961 | { | ||
962 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
963 | return 0; | ||
964 | return i2c_probe(adapter, &addr_data, lm85_detect); | ||
965 | } | ||
966 | |||
967 | static struct attribute *lm85_attributes[] = { | 978 | static struct attribute *lm85_attributes[] = { |
968 | &sensor_dev_attr_fan1_input.dev_attr.attr, | 979 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
969 | &sensor_dev_attr_fan2_input.dev_attr.attr, | 980 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
@@ -984,6 +995,9 @@ static struct attribute *lm85_attributes[] = { | |||
984 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, | 995 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, |
985 | &sensor_dev_attr_pwm2_enable.dev_attr.attr, | 996 | &sensor_dev_attr_pwm2_enable.dev_attr.attr, |
986 | &sensor_dev_attr_pwm3_enable.dev_attr.attr, | 997 | &sensor_dev_attr_pwm3_enable.dev_attr.attr, |
998 | &sensor_dev_attr_pwm1_freq.dev_attr.attr, | ||
999 | &sensor_dev_attr_pwm2_freq.dev_attr.attr, | ||
1000 | &sensor_dev_attr_pwm3_freq.dev_attr.attr, | ||
987 | 1001 | ||
988 | &sensor_dev_attr_in0_input.dev_attr.attr, | 1002 | &sensor_dev_attr_in0_input.dev_attr.attr, |
989 | &sensor_dev_attr_in1_input.dev_attr.attr, | 1003 | &sensor_dev_attr_in1_input.dev_attr.attr, |
@@ -1026,9 +1040,6 @@ static struct attribute *lm85_attributes[] = { | |||
1026 | &sensor_dev_attr_pwm1_auto_pwm_minctl.dev_attr.attr, | 1040 | &sensor_dev_attr_pwm1_auto_pwm_minctl.dev_attr.attr, |
1027 | &sensor_dev_attr_pwm2_auto_pwm_minctl.dev_attr.attr, | 1041 | &sensor_dev_attr_pwm2_auto_pwm_minctl.dev_attr.attr, |
1028 | &sensor_dev_attr_pwm3_auto_pwm_minctl.dev_attr.attr, | 1042 | &sensor_dev_attr_pwm3_auto_pwm_minctl.dev_attr.attr, |
1029 | &sensor_dev_attr_pwm1_auto_pwm_freq.dev_attr.attr, | ||
1030 | &sensor_dev_attr_pwm2_auto_pwm_freq.dev_attr.attr, | ||
1031 | &sensor_dev_attr_pwm3_auto_pwm_freq.dev_attr.attr, | ||
1032 | 1043 | ||
1033 | &sensor_dev_attr_temp1_auto_temp_off.dev_attr.attr, | 1044 | &sensor_dev_attr_temp1_auto_temp_off.dev_attr.attr, |
1034 | &sensor_dev_attr_temp2_auto_temp_off.dev_attr.attr, | 1045 | &sensor_dev_attr_temp2_auto_temp_off.dev_attr.attr, |
@@ -1103,109 +1114,74 @@ static void lm85_init_client(struct i2c_client *client) | |||
1103 | dev_warn(&client->dev, "Device is not ready\n"); | 1114 | dev_warn(&client->dev, "Device is not ready\n"); |
1104 | } | 1115 | } |
1105 | 1116 | ||
1106 | static int lm85_detect(struct i2c_adapter *adapter, int address, | 1117 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
1107 | int kind) | 1118 | static int lm85_detect(struct i2c_client *client, int kind, |
1119 | struct i2c_board_info *info) | ||
1108 | { | 1120 | { |
1109 | int company, verstep; | 1121 | struct i2c_adapter *adapter = client->adapter; |
1110 | struct i2c_client *client; | 1122 | int address = client->addr; |
1111 | struct lm85_data *data; | ||
1112 | int err = 0; | ||
1113 | const char *type_name; | 1123 | const char *type_name; |
1114 | 1124 | ||
1115 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 1125 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
1116 | /* We need to be able to do byte I/O */ | 1126 | /* We need to be able to do byte I/O */ |
1117 | goto ERROR0; | 1127 | return -ENODEV; |
1118 | } | 1128 | } |
1119 | 1129 | ||
1120 | /* OK. For now, we presume we have a valid client. We now create the | 1130 | /* If auto-detecting, determine the chip type */ |
1121 | client structure, even though we cannot fill it completely yet. | 1131 | if (kind < 0) { |
1122 | But it allows us to access lm85_{read,write}_value. */ | 1132 | int company = lm85_read_value(client, LM85_REG_COMPANY); |
1133 | int verstep = lm85_read_value(client, LM85_REG_VERSTEP); | ||
1123 | 1134 | ||
1124 | if (!(data = kzalloc(sizeof(struct lm85_data), GFP_KERNEL))) { | 1135 | dev_dbg(&adapter->dev, "Detecting device at 0x%02x with " |
1125 | err = -ENOMEM; | 1136 | "COMPANY: 0x%02x and VERSTEP: 0x%02x\n", |
1126 | goto ERROR0; | 1137 | address, company, verstep); |
1127 | } | ||
1128 | 1138 | ||
1129 | client = &data->client; | 1139 | /* All supported chips have the version in common */ |
1130 | i2c_set_clientdata(client, data); | 1140 | if ((verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC) { |
1131 | client->addr = address; | 1141 | dev_dbg(&adapter->dev, "Autodetection failed: " |
1132 | client->adapter = adapter; | 1142 | "unsupported version\n"); |
1133 | client->driver = &lm85_driver; | 1143 | return -ENODEV; |
1134 | 1144 | } | |
1135 | /* Now, we do the remaining detection. */ | 1145 | kind = any_chip; |
1136 | 1146 | ||
1137 | company = lm85_read_value(client, LM85_REG_COMPANY); | 1147 | /* Now, refine the detection */ |
1138 | verstep = lm85_read_value(client, LM85_REG_VERSTEP); | 1148 | if (company == LM85_COMPANY_NATIONAL) { |
1139 | 1149 | switch (verstep) { | |
1140 | dev_dbg(&adapter->dev, "Detecting device at %d,0x%02x with" | 1150 | case LM85_VERSTEP_LM85C: |
1141 | " COMPANY: 0x%02x and VERSTEP: 0x%02x\n", | 1151 | kind = lm85c; |
1142 | i2c_adapter_id(client->adapter), client->addr, | 1152 | break; |
1143 | company, verstep); | 1153 | case LM85_VERSTEP_LM85B: |
1144 | 1154 | kind = lm85b; | |
1145 | /* If auto-detecting, Determine the chip type. */ | 1155 | break; |
1146 | if (kind <= 0) { | 1156 | } |
1147 | dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x ...\n", | 1157 | } else if (company == LM85_COMPANY_ANALOG_DEV) { |
1148 | i2c_adapter_id(adapter), address); | 1158 | switch (verstep) { |
1149 | if (company == LM85_COMPANY_NATIONAL | 1159 | case LM85_VERSTEP_ADM1027: |
1150 | && verstep == LM85_VERSTEP_LM85C) { | 1160 | kind = adm1027; |
1151 | kind = lm85c; | 1161 | break; |
1152 | } else if (company == LM85_COMPANY_NATIONAL | 1162 | case LM85_VERSTEP_ADT7463: |
1153 | && verstep == LM85_VERSTEP_LM85B) { | 1163 | case LM85_VERSTEP_ADT7463C: |
1154 | kind = lm85b; | 1164 | kind = adt7463; |
1155 | } else if (company == LM85_COMPANY_NATIONAL | 1165 | break; |
1156 | && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { | 1166 | } |
1157 | dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x" | 1167 | } else if (company == LM85_COMPANY_SMSC) { |
1158 | " Defaulting to LM85.\n", verstep); | 1168 | switch (verstep) { |
1159 | kind = any_chip; | 1169 | case LM85_VERSTEP_EMC6D100_A0: |
1160 | } else if (company == LM85_COMPANY_ANALOG_DEV | 1170 | case LM85_VERSTEP_EMC6D100_A1: |
1161 | && verstep == LM85_VERSTEP_ADM1027) { | 1171 | /* Note: we can't tell a '100 from a '101 */ |
1162 | kind = adm1027; | 1172 | kind = emc6d100; |
1163 | } else if (company == LM85_COMPANY_ANALOG_DEV | 1173 | break; |
1164 | && (verstep == LM85_VERSTEP_ADT7463 | 1174 | case LM85_VERSTEP_EMC6D102: |
1165 | || verstep == LM85_VERSTEP_ADT7463C)) { | 1175 | kind = emc6d102; |
1166 | kind = adt7463; | 1176 | break; |
1167 | } else if (company == LM85_COMPANY_ANALOG_DEV | ||
1168 | && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { | ||
1169 | dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x" | ||
1170 | " Defaulting to Generic LM85.\n", verstep); | ||
1171 | kind = any_chip; | ||
1172 | } else if (company == LM85_COMPANY_SMSC | ||
1173 | && (verstep == LM85_VERSTEP_EMC6D100_A0 | ||
1174 | || verstep == LM85_VERSTEP_EMC6D100_A1)) { | ||
1175 | /* Unfortunately, we can't tell a '100 from a '101 | ||
1176 | * from the registers. Since a '101 is a '100 | ||
1177 | * in a package with fewer pins and therefore no | ||
1178 | * 3.3V, 1.5V or 1.8V inputs, perhaps if those | ||
1179 | * inputs read 0, then it's a '101. | ||
1180 | */ | ||
1181 | kind = emc6d100; | ||
1182 | } else if (company == LM85_COMPANY_SMSC | ||
1183 | && verstep == LM85_VERSTEP_EMC6D102) { | ||
1184 | kind = emc6d102; | ||
1185 | } else if (company == LM85_COMPANY_SMSC | ||
1186 | && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { | ||
1187 | dev_err(&adapter->dev, "lm85: Detected SMSC chip\n"); | ||
1188 | dev_err(&adapter->dev, "lm85: Unrecognized version/stepping 0x%02x" | ||
1189 | " Defaulting to Generic LM85.\n", verstep); | ||
1190 | kind = any_chip; | ||
1191 | } else if (kind == any_chip | ||
1192 | && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { | ||
1193 | dev_err(&adapter->dev, "Generic LM85 Version 6 detected\n"); | ||
1194 | /* Leave kind as "any_chip" */ | ||
1195 | } else { | ||
1196 | dev_dbg(&adapter->dev, "Autodetection failed\n"); | ||
1197 | /* Not an LM85... */ | ||
1198 | if (kind == any_chip) { /* User used force=x,y */ | ||
1199 | dev_err(&adapter->dev, "Generic LM85 Version 6 not" | ||
1200 | " found at %d,0x%02x. Try force_lm85c.\n", | ||
1201 | i2c_adapter_id(adapter), address); | ||
1202 | } | 1177 | } |
1203 | err = 0; | 1178 | } else { |
1204 | goto ERROR1; | 1179 | dev_dbg(&adapter->dev, "Autodetection failed: " |
1180 | "unknown vendor\n"); | ||
1181 | return -ENODEV; | ||
1205 | } | 1182 | } |
1206 | } | 1183 | } |
1207 | 1184 | ||
1208 | /* Fill in the chip specific driver values */ | ||
1209 | switch (kind) { | 1185 | switch (kind) { |
1210 | case lm85b: | 1186 | case lm85b: |
1211 | type_name = "lm85b"; | 1187 | type_name = "lm85b"; |
@@ -1228,16 +1204,36 @@ static int lm85_detect(struct i2c_adapter *adapter, int address, | |||
1228 | default: | 1204 | default: |
1229 | type_name = "lm85"; | 1205 | type_name = "lm85"; |
1230 | } | 1206 | } |
1231 | strlcpy(client->name, type_name, I2C_NAME_SIZE); | 1207 | strlcpy(info->type, type_name, I2C_NAME_SIZE); |
1208 | |||
1209 | return 0; | ||
1210 | } | ||
1232 | 1211 | ||
1233 | /* Fill in the remaining client fields */ | 1212 | static int lm85_probe(struct i2c_client *client, |
1234 | data->type = kind; | 1213 | const struct i2c_device_id *id) |
1214 | { | ||
1215 | struct lm85_data *data; | ||
1216 | int err; | ||
1217 | |||
1218 | data = kzalloc(sizeof(struct lm85_data), GFP_KERNEL); | ||
1219 | if (!data) | ||
1220 | return -ENOMEM; | ||
1221 | |||
1222 | i2c_set_clientdata(client, data); | ||
1223 | data->type = id->driver_data; | ||
1235 | mutex_init(&data->update_lock); | 1224 | mutex_init(&data->update_lock); |
1236 | 1225 | ||
1237 | /* Tell the I2C layer a new client has arrived */ | 1226 | /* Fill in the chip specific driver values */ |
1238 | err = i2c_attach_client(client); | 1227 | switch (data->type) { |
1239 | if (err) | 1228 | case adm1027: |
1240 | goto ERROR1; | 1229 | case adt7463: |
1230 | case emc6d100: | ||
1231 | case emc6d102: | ||
1232 | data->freq_map = adm1027_freq_map; | ||
1233 | break; | ||
1234 | default: | ||
1235 | data->freq_map = lm85_freq_map; | ||
1236 | } | ||
1241 | 1237 | ||
1242 | /* Set the VRM version */ | 1238 | /* Set the VRM version */ |
1243 | data->vrm = vid_which_vrm(); | 1239 | data->vrm = vid_which_vrm(); |
@@ -1248,45 +1244,42 @@ static int lm85_detect(struct i2c_adapter *adapter, int address, | |||
1248 | /* Register sysfs hooks */ | 1244 | /* Register sysfs hooks */ |
1249 | err = sysfs_create_group(&client->dev.kobj, &lm85_group); | 1245 | err = sysfs_create_group(&client->dev.kobj, &lm85_group); |
1250 | if (err) | 1246 | if (err) |
1251 | goto ERROR2; | 1247 | goto err_kfree; |
1252 | 1248 | ||
1253 | /* The ADT7463 has an optional VRM 10 mode where pin 21 is used | 1249 | /* The ADT7463 has an optional VRM 10 mode where pin 21 is used |
1254 | as a sixth digital VID input rather than an analog input. */ | 1250 | as a sixth digital VID input rather than an analog input. */ |
1255 | data->vid = lm85_read_value(client, LM85_REG_VID); | 1251 | data->vid = lm85_read_value(client, LM85_REG_VID); |
1256 | if (!(kind == adt7463 && (data->vid & 0x80))) | 1252 | if (!(data->type == adt7463 && (data->vid & 0x80))) |
1257 | if ((err = sysfs_create_group(&client->dev.kobj, | 1253 | if ((err = sysfs_create_group(&client->dev.kobj, |
1258 | &lm85_group_in4))) | 1254 | &lm85_group_in4))) |
1259 | goto ERROR3; | 1255 | goto err_remove_files; |
1260 | 1256 | ||
1261 | /* The EMC6D100 has 3 additional voltage inputs */ | 1257 | /* The EMC6D100 has 3 additional voltage inputs */ |
1262 | if (kind == emc6d100) | 1258 | if (data->type == emc6d100) |
1263 | if ((err = sysfs_create_group(&client->dev.kobj, | 1259 | if ((err = sysfs_create_group(&client->dev.kobj, |
1264 | &lm85_group_in567))) | 1260 | &lm85_group_in567))) |
1265 | goto ERROR3; | 1261 | goto err_remove_files; |
1266 | 1262 | ||
1267 | data->hwmon_dev = hwmon_device_register(&client->dev); | 1263 | data->hwmon_dev = hwmon_device_register(&client->dev); |
1268 | if (IS_ERR(data->hwmon_dev)) { | 1264 | if (IS_ERR(data->hwmon_dev)) { |
1269 | err = PTR_ERR(data->hwmon_dev); | 1265 | err = PTR_ERR(data->hwmon_dev); |
1270 | goto ERROR3; | 1266 | goto err_remove_files; |
1271 | } | 1267 | } |
1272 | 1268 | ||
1273 | return 0; | 1269 | return 0; |
1274 | 1270 | ||
1275 | /* Error out and cleanup code */ | 1271 | /* Error out and cleanup code */ |
1276 | ERROR3: | 1272 | err_remove_files: |
1277 | sysfs_remove_group(&client->dev.kobj, &lm85_group); | 1273 | sysfs_remove_group(&client->dev.kobj, &lm85_group); |
1278 | sysfs_remove_group(&client->dev.kobj, &lm85_group_in4); | 1274 | sysfs_remove_group(&client->dev.kobj, &lm85_group_in4); |
1279 | if (kind == emc6d100) | 1275 | if (data->type == emc6d100) |
1280 | sysfs_remove_group(&client->dev.kobj, &lm85_group_in567); | 1276 | sysfs_remove_group(&client->dev.kobj, &lm85_group_in567); |
1281 | ERROR2: | 1277 | err_kfree: |
1282 | i2c_detach_client(client); | ||
1283 | ERROR1: | ||
1284 | kfree(data); | 1278 | kfree(data); |
1285 | ERROR0: | ||
1286 | return err; | 1279 | return err; |
1287 | } | 1280 | } |
1288 | 1281 | ||
1289 | static int lm85_detach_client(struct i2c_client *client) | 1282 | static int lm85_remove(struct i2c_client *client) |
1290 | { | 1283 | { |
1291 | struct lm85_data *data = i2c_get_clientdata(client); | 1284 | struct lm85_data *data = i2c_get_clientdata(client); |
1292 | hwmon_device_unregister(data->hwmon_dev); | 1285 | hwmon_device_unregister(data->hwmon_dev); |
@@ -1294,7 +1287,6 @@ static int lm85_detach_client(struct i2c_client *client) | |||
1294 | sysfs_remove_group(&client->dev.kobj, &lm85_group_in4); | 1287 | sysfs_remove_group(&client->dev.kobj, &lm85_group_in4); |
1295 | if (data->type == emc6d100) | 1288 | if (data->type == emc6d100) |
1296 | sysfs_remove_group(&client->dev.kobj, &lm85_group_in567); | 1289 | sysfs_remove_group(&client->dev.kobj, &lm85_group_in567); |
1297 | i2c_detach_client(client); | ||
1298 | kfree(data); | 1290 | kfree(data); |
1299 | return 0; | 1291 | return 0; |
1300 | } | 1292 | } |
@@ -1481,7 +1473,7 @@ static struct lm85_data *lm85_update_device(struct device *dev) | |||
1481 | data->autofan[i].config = | 1473 | data->autofan[i].config = |
1482 | lm85_read_value(client, LM85_REG_AFAN_CONFIG(i)); | 1474 | lm85_read_value(client, LM85_REG_AFAN_CONFIG(i)); |
1483 | val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i)); | 1475 | val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i)); |
1484 | data->autofan[i].freq = val & 0x07; | 1476 | data->pwm_freq[i] = val & 0x07; |
1485 | data->zone[i].range = val >> 4; | 1477 | data->zone[i].range = val >> 4; |
1486 | data->autofan[i].min_pwm = | 1478 | data->autofan[i].min_pwm = |
1487 | lm85_read_value(client, LM85_REG_AFAN_MINPWM(i)); | 1479 | lm85_read_value(client, LM85_REG_AFAN_MINPWM(i)); |