diff options
author | Jean Delvare <khali@linux-fr.org> | 2009-12-09 14:35:57 -0500 |
---|---|---|
committer | Jean Delvare <khali@linux-fr.org> | 2009-12-09 14:35:57 -0500 |
commit | 52df6440a29123eed912183fe785bbe174ef14b9 (patch) | |
tree | 3a3b9f4110d21c2ec4f5711444dd9cec6fb3d32c | |
parent | a1fa4cdcc4abd4c02a81ab7052c16a342d29f060 (diff) |
hwmon: Clean up detect functions
As kind is now hard-coded to -1, there is room for code clean-ups.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Corentin Labbe <corentin.labbe@geomatys.fr>
Cc: "Mark M. Hoffman" <mhoffman@lightlink.com>
Cc: Juerg Haefliger <juergh@gmail.com>
Cc: Riku Voipio <riku.voipio@iki.fi>
Acked-by: "Hans J. Koch" <hjk@linutronix.de>
Cc: Rudolf Marek <r.marek@assembler.cz>
29 files changed, 393 insertions, 714 deletions
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c index ff7de40b6e35..fb5363985e21 100644 --- a/drivers/hwmon/adm1026.c +++ b/drivers/hwmon/adm1026.c | |||
@@ -1672,35 +1672,26 @@ static int adm1026_detect(struct i2c_client *client, int kind, | |||
1672 | i2c_adapter_id(client->adapter), client->addr, | 1672 | i2c_adapter_id(client->adapter), client->addr, |
1673 | company, verstep); | 1673 | company, verstep); |
1674 | 1674 | ||
1675 | /* If auto-detecting, Determine the chip type. */ | 1675 | /* Determine the chip type. */ |
1676 | if (kind <= 0) { | 1676 | dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x...\n", |
1677 | dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x " | 1677 | i2c_adapter_id(adapter), address); |
1678 | "...\n", i2c_adapter_id(adapter), address); | 1678 | if (company == ADM1026_COMPANY_ANALOG_DEV |
1679 | if (company == ADM1026_COMPANY_ANALOG_DEV | 1679 | && verstep == ADM1026_VERSTEP_ADM1026) { |
1680 | && verstep == ADM1026_VERSTEP_ADM1026) { | 1680 | /* Analog Devices ADM1026 */ |
1681 | kind = adm1026; | 1681 | } else if (company == ADM1026_COMPANY_ANALOG_DEV |
1682 | } else if (company == ADM1026_COMPANY_ANALOG_DEV | 1682 | && (verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) { |
1683 | && (verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) { | 1683 | dev_err(&adapter->dev, "Unrecognized stepping " |
1684 | dev_err(&adapter->dev, "Unrecognized stepping " | 1684 | "0x%02x. Defaulting to ADM1026.\n", verstep); |
1685 | "0x%02x. Defaulting to ADM1026.\n", verstep); | 1685 | } else if ((verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) { |
1686 | kind = adm1026; | 1686 | dev_err(&adapter->dev, "Found version/stepping " |
1687 | } else if ((verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) { | 1687 | "0x%02x. Assuming generic ADM1026.\n", |
1688 | dev_err(&adapter->dev, "Found version/stepping " | 1688 | verstep); |
1689 | "0x%02x. Assuming generic ADM1026.\n", | 1689 | } else { |
1690 | verstep); | 1690 | dev_dbg(&adapter->dev, "Autodetection failed\n"); |
1691 | kind = any_chip; | 1691 | /* Not an ADM1026... */ |
1692 | } else { | 1692 | return -ENODEV; |
1693 | dev_dbg(&adapter->dev, "Autodetection failed\n"); | ||
1694 | /* Not an ADM1026 ... */ | ||
1695 | if (kind == 0) { /* User used force=x,y */ | ||
1696 | dev_err(&adapter->dev, "Generic ADM1026 not " | ||
1697 | "found at %d,0x%02x. Try " | ||
1698 | "force_adm1026.\n", | ||
1699 | i2c_adapter_id(adapter), address); | ||
1700 | } | ||
1701 | return -ENODEV; | ||
1702 | } | ||
1703 | } | 1693 | } |
1694 | |||
1704 | strlcpy(info->type, "adm1026", I2C_NAME_SIZE); | 1695 | strlcpy(info->type, "adm1026", I2C_NAME_SIZE); |
1705 | 1696 | ||
1706 | return 0; | 1697 | return 0; |
diff --git a/drivers/hwmon/adm1029.c b/drivers/hwmon/adm1029.c index 36718150b475..4d7d8433c2f3 100644 --- a/drivers/hwmon/adm1029.c +++ b/drivers/hwmon/adm1029.c | |||
@@ -301,59 +301,36 @@ static int adm1029_detect(struct i2c_client *client, int kind, | |||
301 | struct i2c_board_info *info) | 301 | struct i2c_board_info *info) |
302 | { | 302 | { |
303 | struct i2c_adapter *adapter = client->adapter; | 303 | struct i2c_adapter *adapter = client->adapter; |
304 | u8 man_id, chip_id, temp_devices_installed, nb_fan_support; | ||
304 | 305 | ||
305 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 306 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
306 | return -ENODEV; | 307 | return -ENODEV; |
307 | 308 | ||
308 | /* Now we do the detection and identification. A negative kind | ||
309 | * means that the driver was loaded with no force parameter | ||
310 | * (default), so we must both detect and identify the chip | ||
311 | * (actually there is only one possible kind of chip for now, adm1029). | ||
312 | * A zero kind means that the driver was loaded with the force | ||
313 | * parameter, the detection step shall be skipped. A positive kind | ||
314 | * means that the driver was loaded with the force parameter and a | ||
315 | * given kind of chip is requested, so both the detection and the | ||
316 | * identification steps are skipped. */ | ||
317 | |||
318 | /* Default to an adm1029 if forced */ | ||
319 | if (kind == 0) | ||
320 | kind = adm1029; | ||
321 | |||
322 | /* ADM1029 doesn't have CHIP ID, check just MAN ID | 309 | /* ADM1029 doesn't have CHIP ID, check just MAN ID |
323 | * For better detection we check also ADM1029_TEMP_DEVICES_INSTALLED, | 310 | * For better detection we check also ADM1029_TEMP_DEVICES_INSTALLED, |
324 | * ADM1029_REG_NB_FAN_SUPPORT and compare it with possible values | 311 | * ADM1029_REG_NB_FAN_SUPPORT and compare it with possible values |
325 | * documented | 312 | * documented |
326 | */ | 313 | */ |
327 | 314 | ||
328 | if (kind <= 0) { /* identification */ | 315 | man_id = i2c_smbus_read_byte_data(client, ADM1029_REG_MAN_ID); |
329 | u8 man_id, chip_id, temp_devices_installed, nb_fan_support; | 316 | chip_id = i2c_smbus_read_byte_data(client, ADM1029_REG_CHIP_ID); |
330 | 317 | temp_devices_installed = i2c_smbus_read_byte_data(client, | |
331 | man_id = i2c_smbus_read_byte_data(client, ADM1029_REG_MAN_ID); | ||
332 | chip_id = i2c_smbus_read_byte_data(client, ADM1029_REG_CHIP_ID); | ||
333 | temp_devices_installed = i2c_smbus_read_byte_data(client, | ||
334 | ADM1029_REG_TEMP_DEVICES_INSTALLED); | 318 | ADM1029_REG_TEMP_DEVICES_INSTALLED); |
335 | nb_fan_support = i2c_smbus_read_byte_data(client, | 319 | nb_fan_support = i2c_smbus_read_byte_data(client, |
336 | ADM1029_REG_NB_FAN_SUPPORT); | 320 | ADM1029_REG_NB_FAN_SUPPORT); |
337 | /* 0x41 is Analog Devices */ | 321 | /* 0x41 is Analog Devices */ |
338 | if (man_id == 0x41 && (temp_devices_installed & 0xf9) == 0x01 | 322 | if (man_id != 0x41 || (temp_devices_installed & 0xf9) != 0x01 |
339 | && nb_fan_support == 0x03) { | 323 | || nb_fan_support != 0x03) |
340 | if ((chip_id & 0xF0) == 0x00) { | 324 | return -ENODEV; |
341 | kind = adm1029; | ||
342 | } else { | ||
343 | /* There are no "official" CHIP ID, so actually | ||
344 | * we use Major/Minor revision for that */ | ||
345 | printk(KERN_INFO | ||
346 | "adm1029: Unknown major revision %x, " | ||
347 | "please let us know\n", chip_id); | ||
348 | } | ||
349 | } | ||
350 | 325 | ||
351 | if (kind <= 0) { /* identification failed */ | 326 | if ((chip_id & 0xF0) != 0x00) { |
352 | pr_debug("adm1029: Unsupported chip (man_id=0x%02X, " | 327 | /* There are no "official" CHIP ID, so actually |
353 | "chip_id=0x%02X)\n", man_id, chip_id); | 328 | * we use Major/Minor revision for that */ |
354 | return -ENODEV; | 329 | pr_info("adm1029: Unknown major revision %x, " |
355 | } | 330 | "please let us know\n", chip_id); |
331 | return -ENODEV; | ||
356 | } | 332 | } |
333 | |||
357 | strlcpy(info->type, "adm1029", I2C_NAME_SIZE); | 334 | strlcpy(info->type, "adm1029", I2C_NAME_SIZE); |
358 | 335 | ||
359 | return 0; | 336 | return 0; |
diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c index 56905955352c..0e722175aae0 100644 --- a/drivers/hwmon/adm1031.c +++ b/drivers/hwmon/adm1031.c | |||
@@ -817,31 +817,19 @@ static int adm1031_detect(struct i2c_client *client, int kind, | |||
817 | struct i2c_board_info *info) | 817 | struct i2c_board_info *info) |
818 | { | 818 | { |
819 | struct i2c_adapter *adapter = client->adapter; | 819 | struct i2c_adapter *adapter = client->adapter; |
820 | const char *name = ""; | 820 | const char *name; |
821 | int id, co; | ||
821 | 822 | ||
822 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 823 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
823 | return -ENODEV; | 824 | return -ENODEV; |
824 | 825 | ||
825 | if (kind < 0) { | 826 | id = i2c_smbus_read_byte_data(client, 0x3d); |
826 | int id, co; | 827 | co = i2c_smbus_read_byte_data(client, 0x3e); |
827 | id = i2c_smbus_read_byte_data(client, 0x3d); | ||
828 | co = i2c_smbus_read_byte_data(client, 0x3e); | ||
829 | 828 | ||
830 | if (!((id == 0x31 || id == 0x30) && co == 0x41)) | 829 | if (!((id == 0x31 || id == 0x30) && co == 0x41)) |
831 | return -ENODEV; | 830 | return -ENODEV; |
832 | kind = (id == 0x30) ? adm1030 : adm1031; | 831 | name = (id == 0x30) ? "adm1030" : "adm1031"; |
833 | } | ||
834 | |||
835 | if (kind <= 0) | ||
836 | kind = adm1031; | ||
837 | 832 | ||
838 | /* Given the detected chip type, set the chip name and the | ||
839 | * auto fan control helper table. */ | ||
840 | if (kind == adm1030) { | ||
841 | name = "adm1030"; | ||
842 | } else if (kind == adm1031) { | ||
843 | name = "adm1031"; | ||
844 | } | ||
845 | strlcpy(info->type, name, I2C_NAME_SIZE); | 833 | strlcpy(info->type, name, I2C_NAME_SIZE); |
846 | 834 | ||
847 | return 0; | 835 | return 0; |
diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c index 2444b15f2e9d..20e0481cc206 100644 --- a/drivers/hwmon/adm9240.c +++ b/drivers/hwmon/adm9240.c | |||
@@ -556,51 +556,34 @@ static int adm9240_detect(struct i2c_client *new_client, int kind, | |||
556 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 556 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
557 | return -ENODEV; | 557 | return -ENODEV; |
558 | 558 | ||
559 | if (kind == 0) { | 559 | /* verify chip: reg address should match i2c address */ |
560 | kind = adm9240; | 560 | if (i2c_smbus_read_byte_data(new_client, ADM9240_REG_I2C_ADDR) |
561 | } | 561 | != address) { |
562 | 562 | dev_err(&adapter->dev, "detect fail: address match, 0x%02x\n", | |
563 | if (kind < 0) { | 563 | address); |
564 | 564 | return -ENODEV; | |
565 | /* verify chip: reg address should match i2c address */ | ||
566 | if (i2c_smbus_read_byte_data(new_client, ADM9240_REG_I2C_ADDR) | ||
567 | != address) { | ||
568 | dev_err(&adapter->dev, "detect fail: address match, " | ||
569 | "0x%02x\n", address); | ||
570 | return -ENODEV; | ||
571 | } | ||
572 | |||
573 | /* check known chip manufacturer */ | ||
574 | man_id = i2c_smbus_read_byte_data(new_client, | ||
575 | ADM9240_REG_MAN_ID); | ||
576 | if (man_id == 0x23) { | ||
577 | kind = adm9240; | ||
578 | } else if (man_id == 0xda) { | ||
579 | kind = ds1780; | ||
580 | } else if (man_id == 0x01) { | ||
581 | kind = lm81; | ||
582 | } else { | ||
583 | dev_err(&adapter->dev, "detect fail: unknown manuf, " | ||
584 | "0x%02x\n", man_id); | ||
585 | return -ENODEV; | ||
586 | } | ||
587 | |||
588 | /* successful detect, print chip info */ | ||
589 | die_rev = i2c_smbus_read_byte_data(new_client, | ||
590 | ADM9240_REG_DIE_REV); | ||
591 | dev_info(&adapter->dev, "found %s revision %u\n", | ||
592 | man_id == 0x23 ? "ADM9240" : | ||
593 | man_id == 0xda ? "DS1780" : "LM81", die_rev); | ||
594 | } | 565 | } |
595 | 566 | ||
596 | /* either forced or detected chip kind */ | 567 | /* check known chip manufacturer */ |
597 | if (kind == adm9240) { | 568 | man_id = i2c_smbus_read_byte_data(new_client, ADM9240_REG_MAN_ID); |
569 | if (man_id == 0x23) { | ||
598 | name = "adm9240"; | 570 | name = "adm9240"; |
599 | } else if (kind == ds1780) { | 571 | } else if (man_id == 0xda) { |
600 | name = "ds1780"; | 572 | name = "ds1780"; |
601 | } else if (kind == lm81) { | 573 | } else if (man_id == 0x01) { |
602 | name = "lm81"; | 574 | name = "lm81"; |
575 | } else { | ||
576 | dev_err(&adapter->dev, "detect fail: unknown manuf, 0x%02x\n", | ||
577 | man_id); | ||
578 | return -ENODEV; | ||
603 | } | 579 | } |
580 | |||
581 | /* successful detect, print chip info */ | ||
582 | die_rev = i2c_smbus_read_byte_data(new_client, ADM9240_REG_DIE_REV); | ||
583 | dev_info(&adapter->dev, "found %s revision %u\n", | ||
584 | man_id == 0x23 ? "ADM9240" : | ||
585 | man_id == 0xda ? "DS1780" : "LM81", die_rev); | ||
586 | |||
604 | strlcpy(info->type, name, I2C_NAME_SIZE); | 587 | strlcpy(info->type, name, I2C_NAME_SIZE); |
605 | 588 | ||
606 | return 0; | 589 | return 0; |
diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c index 5c39b4af1b23..451977bca7d6 100644 --- a/drivers/hwmon/ads7828.c +++ b/drivers/hwmon/ads7828.c | |||
@@ -191,6 +191,7 @@ static int ads7828_detect(struct i2c_client *client, int kind, | |||
191 | struct i2c_board_info *info) | 191 | struct i2c_board_info *info) |
192 | { | 192 | { |
193 | struct i2c_adapter *adapter = client->adapter; | 193 | struct i2c_adapter *adapter = client->adapter; |
194 | int ch; | ||
194 | 195 | ||
195 | /* Check we have a valid client */ | 196 | /* Check we have a valid client */ |
196 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA)) | 197 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA)) |
@@ -202,20 +203,17 @@ static int ads7828_detect(struct i2c_client *client, int kind, | |||
202 | - Read from the 8 channel addresses | 203 | - Read from the 8 channel addresses |
203 | - Check the top 4 bits of each result are not set (12 data bits) | 204 | - Check the top 4 bits of each result are not set (12 data bits) |
204 | */ | 205 | */ |
205 | if (kind < 0) { | 206 | for (ch = 0; ch < ADS7828_NCH; ch++) { |
206 | int ch; | 207 | u16 in_data; |
207 | for (ch = 0; ch < ADS7828_NCH; ch++) { | 208 | u8 cmd = channel_cmd_byte(ch); |
208 | u16 in_data; | 209 | in_data = ads7828_read_value(client, cmd); |
209 | u8 cmd = channel_cmd_byte(ch); | 210 | if (in_data & 0xF000) { |
210 | in_data = ads7828_read_value(client, cmd); | 211 | pr_debug("%s : Doesn't look like an ads7828 device\n", |
211 | if (in_data & 0xF000) { | 212 | __func__); |
212 | printk(KERN_DEBUG | 213 | return -ENODEV; |
213 | "%s : Doesn't look like an ads7828 device\n", | ||
214 | __func__); | ||
215 | return -ENODEV; | ||
216 | } | ||
217 | } | 214 | } |
218 | } | 215 | } |
216 | |||
219 | strlcpy(info->type, "ads7828", I2C_NAME_SIZE); | 217 | strlcpy(info->type, "ads7828", I2C_NAME_SIZE); |
220 | 218 | ||
221 | return 0; | 219 | return 0; |
diff --git a/drivers/hwmon/adt7462.c b/drivers/hwmon/adt7462.c index 1852f27bac51..f9c9562b6a94 100644 --- a/drivers/hwmon/adt7462.c +++ b/drivers/hwmon/adt7462.c | |||
@@ -1906,27 +1906,22 @@ static int adt7462_detect(struct i2c_client *client, int kind, | |||
1906 | struct i2c_board_info *info) | 1906 | struct i2c_board_info *info) |
1907 | { | 1907 | { |
1908 | struct i2c_adapter *adapter = client->adapter; | 1908 | struct i2c_adapter *adapter = client->adapter; |
1909 | int vendor, device, revision; | ||
1909 | 1910 | ||
1910 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 1911 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
1911 | return -ENODEV; | 1912 | return -ENODEV; |
1912 | 1913 | ||
1913 | if (kind <= 0) { | 1914 | vendor = i2c_smbus_read_byte_data(client, ADT7462_REG_VENDOR); |
1914 | int vendor, device, revision; | 1915 | if (vendor != ADT7462_VENDOR) |
1915 | 1916 | return -ENODEV; | |
1916 | vendor = i2c_smbus_read_byte_data(client, ADT7462_REG_VENDOR); | ||
1917 | if (vendor != ADT7462_VENDOR) | ||
1918 | return -ENODEV; | ||
1919 | 1917 | ||
1920 | device = i2c_smbus_read_byte_data(client, ADT7462_REG_DEVICE); | 1918 | device = i2c_smbus_read_byte_data(client, ADT7462_REG_DEVICE); |
1921 | if (device != ADT7462_DEVICE) | 1919 | if (device != ADT7462_DEVICE) |
1922 | return -ENODEV; | 1920 | return -ENODEV; |
1923 | 1921 | ||
1924 | revision = i2c_smbus_read_byte_data(client, | 1922 | revision = i2c_smbus_read_byte_data(client, ADT7462_REG_REVISION); |
1925 | ADT7462_REG_REVISION); | 1923 | if (revision != ADT7462_REVISION) |
1926 | if (revision != ADT7462_REVISION) | 1924 | return -ENODEV; |
1927 | return -ENODEV; | ||
1928 | } else | ||
1929 | dev_dbg(&adapter->dev, "detection forced\n"); | ||
1930 | 1925 | ||
1931 | strlcpy(info->type, "adt7462", I2C_NAME_SIZE); | 1926 | strlcpy(info->type, "adt7462", I2C_NAME_SIZE); |
1932 | 1927 | ||
diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c index 633e1a1e9d79..32b1750a6890 100644 --- a/drivers/hwmon/adt7470.c +++ b/drivers/hwmon/adt7470.c | |||
@@ -1229,27 +1229,22 @@ static int adt7470_detect(struct i2c_client *client, int kind, | |||
1229 | struct i2c_board_info *info) | 1229 | struct i2c_board_info *info) |
1230 | { | 1230 | { |
1231 | struct i2c_adapter *adapter = client->adapter; | 1231 | struct i2c_adapter *adapter = client->adapter; |
1232 | int vendor, device, revision; | ||
1232 | 1233 | ||
1233 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 1234 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
1234 | return -ENODEV; | 1235 | return -ENODEV; |
1235 | 1236 | ||
1236 | if (kind <= 0) { | 1237 | vendor = i2c_smbus_read_byte_data(client, ADT7470_REG_VENDOR); |
1237 | int vendor, device, revision; | 1238 | if (vendor != ADT7470_VENDOR) |
1238 | 1239 | return -ENODEV; | |
1239 | vendor = i2c_smbus_read_byte_data(client, ADT7470_REG_VENDOR); | ||
1240 | if (vendor != ADT7470_VENDOR) | ||
1241 | return -ENODEV; | ||
1242 | 1240 | ||
1243 | device = i2c_smbus_read_byte_data(client, ADT7470_REG_DEVICE); | 1241 | device = i2c_smbus_read_byte_data(client, ADT7470_REG_DEVICE); |
1244 | if (device != ADT7470_DEVICE) | 1242 | if (device != ADT7470_DEVICE) |
1245 | return -ENODEV; | 1243 | return -ENODEV; |
1246 | 1244 | ||
1247 | revision = i2c_smbus_read_byte_data(client, | 1245 | revision = i2c_smbus_read_byte_data(client, ADT7470_REG_REVISION); |
1248 | ADT7470_REG_REVISION); | 1246 | if (revision != ADT7470_REVISION) |
1249 | if (revision != ADT7470_REVISION) | 1247 | return -ENODEV; |
1250 | return -ENODEV; | ||
1251 | } else | ||
1252 | dev_dbg(&adapter->dev, "detection forced\n"); | ||
1253 | 1248 | ||
1254 | strlcpy(info->type, "adt7470", I2C_NAME_SIZE); | 1249 | strlcpy(info->type, "adt7470", I2C_NAME_SIZE); |
1255 | 1250 | ||
diff --git a/drivers/hwmon/adt7473.c b/drivers/hwmon/adt7473.c index 0a6ce2367b42..97ef50833f64 100644 --- a/drivers/hwmon/adt7473.c +++ b/drivers/hwmon/adt7473.c | |||
@@ -1090,27 +1090,22 @@ static int adt7473_detect(struct i2c_client *client, int kind, | |||
1090 | struct i2c_board_info *info) | 1090 | struct i2c_board_info *info) |
1091 | { | 1091 | { |
1092 | struct i2c_adapter *adapter = client->adapter; | 1092 | struct i2c_adapter *adapter = client->adapter; |
1093 | int vendor, device, revision; | ||
1093 | 1094 | ||
1094 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 1095 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
1095 | return -ENODEV; | 1096 | return -ENODEV; |
1096 | 1097 | ||
1097 | if (kind <= 0) { | 1098 | vendor = i2c_smbus_read_byte_data(client, ADT7473_REG_VENDOR); |
1098 | int vendor, device, revision; | 1099 | if (vendor != ADT7473_VENDOR) |
1099 | 1100 | return -ENODEV; | |
1100 | vendor = i2c_smbus_read_byte_data(client, ADT7473_REG_VENDOR); | ||
1101 | if (vendor != ADT7473_VENDOR) | ||
1102 | return -ENODEV; | ||
1103 | 1101 | ||
1104 | device = i2c_smbus_read_byte_data(client, ADT7473_REG_DEVICE); | 1102 | device = i2c_smbus_read_byte_data(client, ADT7473_REG_DEVICE); |
1105 | if (device != ADT7473_DEVICE) | 1103 | if (device != ADT7473_DEVICE) |
1106 | return -ENODEV; | 1104 | return -ENODEV; |
1107 | 1105 | ||
1108 | revision = i2c_smbus_read_byte_data(client, | 1106 | revision = i2c_smbus_read_byte_data(client, ADT7473_REG_REVISION); |
1109 | ADT7473_REG_REVISION); | 1107 | if (revision != ADT7473_REV_68 && revision != ADT7473_REV_69) |
1110 | if (revision != ADT7473_REV_68 && revision != ADT7473_REV_69) | 1108 | return -ENODEV; |
1111 | return -ENODEV; | ||
1112 | } else | ||
1113 | dev_dbg(&adapter->dev, "detection forced\n"); | ||
1114 | 1109 | ||
1115 | strlcpy(info->type, "adt7473", I2C_NAME_SIZE); | 1110 | strlcpy(info->type, "adt7473", I2C_NAME_SIZE); |
1116 | 1111 | ||
diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index b5a95193c694..41d3e38f9ce1 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c | |||
@@ -974,14 +974,12 @@ static int adt7475_detect(struct i2c_client *client, int kind, | |||
974 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 974 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
975 | return -ENODEV; | 975 | return -ENODEV; |
976 | 976 | ||
977 | if (kind <= 0) { | 977 | if (adt7475_read(REG_VENDID) != 0x41 || |
978 | if (adt7475_read(REG_VENDID) != 0x41 || | 978 | adt7475_read(REG_DEVID) != 0x75) { |
979 | adt7475_read(REG_DEVID) != 0x75) { | 979 | dev_err(&adapter->dev, |
980 | dev_err(&adapter->dev, | 980 | "Couldn't detect a adt7475 part at 0x%02x\n", |
981 | "Couldn't detect a adt7475 part at 0x%02x\n", | 981 | (unsigned int)client->addr); |
982 | (unsigned int)client->addr); | 982 | return -ENODEV; |
983 | return -ENODEV; | ||
984 | } | ||
985 | } | 983 | } |
986 | 984 | ||
987 | strlcpy(info->type, adt7475_id[0].name, I2C_NAME_SIZE); | 985 | strlcpy(info->type, adt7475_id[0].name, I2C_NAME_SIZE); |
diff --git a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c index 8acf82977e7b..480f80ea1fa0 100644 --- a/drivers/hwmon/asb100.c +++ b/drivers/hwmon/asb100.c | |||
@@ -701,6 +701,7 @@ static int asb100_detect(struct i2c_client *client, int kind, | |||
701 | struct i2c_board_info *info) | 701 | struct i2c_board_info *info) |
702 | { | 702 | { |
703 | struct i2c_adapter *adapter = client->adapter; | 703 | struct i2c_adapter *adapter = client->adapter; |
704 | int val1, val2; | ||
704 | 705 | ||
705 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 706 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
706 | pr_debug("asb100.o: detect failed, " | 707 | pr_debug("asb100.o: detect failed, " |
@@ -708,50 +709,30 @@ static int asb100_detect(struct i2c_client *client, int kind, | |||
708 | return -ENODEV; | 709 | return -ENODEV; |
709 | } | 710 | } |
710 | 711 | ||
711 | /* The chip may be stuck in some other bank than bank 0. This may | 712 | val1 = i2c_smbus_read_byte_data(client, ASB100_REG_BANK); |
712 | make reading other information impossible. Specify a force=... or | 713 | val2 = i2c_smbus_read_byte_data(client, ASB100_REG_CHIPMAN); |
713 | force_*=... parameter, and the chip will be reset to the right | ||
714 | bank. */ | ||
715 | if (kind < 0) { | ||
716 | |||
717 | int val1 = i2c_smbus_read_byte_data(client, ASB100_REG_BANK); | ||
718 | int val2 = i2c_smbus_read_byte_data(client, ASB100_REG_CHIPMAN); | ||
719 | |||
720 | /* If we're in bank 0 */ | ||
721 | if ((!(val1 & 0x07)) && | ||
722 | /* Check for ASB100 ID (low byte) */ | ||
723 | (((!(val1 & 0x80)) && (val2 != 0x94)) || | ||
724 | /* Check for ASB100 ID (high byte ) */ | ||
725 | ((val1 & 0x80) && (val2 != 0x06)))) { | ||
726 | pr_debug("asb100.o: detect failed, " | ||
727 | "bad chip id 0x%02x!\n", val2); | ||
728 | return -ENODEV; | ||
729 | } | ||
730 | 714 | ||
731 | } /* kind < 0 */ | 715 | /* If we're in bank 0 */ |
716 | if ((!(val1 & 0x07)) && | ||
717 | /* Check for ASB100 ID (low byte) */ | ||
718 | (((!(val1 & 0x80)) && (val2 != 0x94)) || | ||
719 | /* Check for ASB100 ID (high byte ) */ | ||
720 | ((val1 & 0x80) && (val2 != 0x06)))) { | ||
721 | pr_debug("asb100: detect failed, bad chip id 0x%02x!\n", val2); | ||
722 | return -ENODEV; | ||
723 | } | ||
732 | 724 | ||
733 | /* We have either had a force parameter, or we have already detected | 725 | /* Put it now into bank 0 and Vendor ID High Byte */ |
734 | Winbond. Put it now into bank 0 and Vendor ID High Byte */ | ||
735 | i2c_smbus_write_byte_data(client, ASB100_REG_BANK, | 726 | i2c_smbus_write_byte_data(client, ASB100_REG_BANK, |
736 | (i2c_smbus_read_byte_data(client, ASB100_REG_BANK) & 0x78) | 727 | (i2c_smbus_read_byte_data(client, ASB100_REG_BANK) & 0x78) |
737 | | 0x80); | 728 | | 0x80); |
738 | 729 | ||
739 | /* Determine the chip type. */ | 730 | /* Determine the chip type. */ |
740 | if (kind <= 0) { | 731 | val1 = i2c_smbus_read_byte_data(client, ASB100_REG_WCHIPID); |
741 | int val1 = i2c_smbus_read_byte_data(client, ASB100_REG_WCHIPID); | 732 | val2 = i2c_smbus_read_byte_data(client, ASB100_REG_CHIPMAN); |
742 | int val2 = i2c_smbus_read_byte_data(client, ASB100_REG_CHIPMAN); | 733 | |
743 | 734 | if (val1 != 0x31 || val2 != 0x06) | |
744 | if ((val1 == 0x31) && (val2 == 0x06)) | 735 | return -ENODEV; |
745 | kind = asb100; | ||
746 | else { | ||
747 | if (kind == 0) | ||
748 | dev_warn(&adapter->dev, "ignoring " | ||
749 | "'force' parameter for unknown chip " | ||
750 | "at adapter %d, address 0x%02x.\n", | ||
751 | i2c_adapter_id(adapter), client->addr); | ||
752 | return -ENODEV; | ||
753 | } | ||
754 | } | ||
755 | 736 | ||
756 | strlcpy(info->type, "asb100", I2C_NAME_SIZE); | 737 | strlcpy(info->type, "asb100", I2C_NAME_SIZE); |
757 | 738 | ||
diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c index 27d62574284f..4377bb0cc526 100644 --- a/drivers/hwmon/dme1737.c +++ b/drivers/hwmon/dme1737.c | |||
@@ -2220,33 +2220,23 @@ static int dme1737_i2c_detect(struct i2c_client *client, int kind, | |||
2220 | return -ENODEV; | 2220 | return -ENODEV; |
2221 | } | 2221 | } |
2222 | 2222 | ||
2223 | /* A negative kind means that the driver was loaded with no force | 2223 | company = i2c_smbus_read_byte_data(client, DME1737_REG_COMPANY); |
2224 | * parameter (default), so we must identify the chip. */ | 2224 | verstep = i2c_smbus_read_byte_data(client, DME1737_REG_VERSTEP); |
2225 | if (kind < 0) { | ||
2226 | company = i2c_smbus_read_byte_data(client, DME1737_REG_COMPANY); | ||
2227 | verstep = i2c_smbus_read_byte_data(client, DME1737_REG_VERSTEP); | ||
2228 | |||
2229 | if (company == DME1737_COMPANY_SMSC && | ||
2230 | (verstep & DME1737_VERSTEP_MASK) == DME1737_VERSTEP) { | ||
2231 | kind = dme1737; | ||
2232 | } else if (company == DME1737_COMPANY_SMSC && | ||
2233 | verstep == SCH5027_VERSTEP) { | ||
2234 | kind = sch5027; | ||
2235 | } else { | ||
2236 | return -ENODEV; | ||
2237 | } | ||
2238 | } | ||
2239 | 2225 | ||
2240 | if (kind == sch5027) { | 2226 | if (company == DME1737_COMPANY_SMSC && |
2227 | verstep == SCH5027_VERSTEP) { | ||
2241 | name = "sch5027"; | 2228 | name = "sch5027"; |
2242 | } else { | 2229 | |
2243 | kind = dme1737; | 2230 | } else if (company == DME1737_COMPANY_SMSC && |
2231 | (verstep & DME1737_VERSTEP_MASK) == DME1737_VERSTEP) { | ||
2244 | name = "dme1737"; | 2232 | name = "dme1737"; |
2233 | } else { | ||
2234 | return -ENODEV; | ||
2245 | } | 2235 | } |
2246 | 2236 | ||
2247 | dev_info(dev, "Found a %s chip at 0x%02x (rev 0x%02x).\n", | 2237 | dev_info(dev, "Found a %s chip at 0x%02x (rev 0x%02x).\n", |
2248 | kind == sch5027 ? "SCH5027" : "DME1737", client->addr, | 2238 | verstep == SCH5027_VERSTEP ? "SCH5027" : "DME1737", |
2249 | verstep); | 2239 | client->addr, verstep); |
2250 | strlcpy(info->type, name, I2C_NAME_SIZE); | 2240 | strlcpy(info->type, name, I2C_NAME_SIZE); |
2251 | 2241 | ||
2252 | return 0; | 2242 | return 0; |
diff --git a/drivers/hwmon/ds1621.c b/drivers/hwmon/ds1621.c index 53f88f511816..2a4c6a05b14f 100644 --- a/drivers/hwmon/ds1621.c +++ b/drivers/hwmon/ds1621.c | |||
@@ -237,20 +237,16 @@ static int ds1621_detect(struct i2c_client *client, int kind, | |||
237 | return -ENODEV; | 237 | return -ENODEV; |
238 | 238 | ||
239 | /* Now, we do the remaining detection. It is lousy. */ | 239 | /* Now, we do the remaining detection. It is lousy. */ |
240 | if (kind < 0) { | 240 | /* The NVB bit should be low if no EEPROM write has been requested |
241 | /* The NVB bit should be low if no EEPROM write has been | 241 | during the latest 10ms, which is highly improbable in our case. */ |
242 | requested during the latest 10ms, which is highly | 242 | conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF); |
243 | improbable in our case. */ | 243 | if (conf < 0 || conf & DS1621_REG_CONFIG_NVB) |
244 | conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF); | 244 | return -ENODEV; |
245 | if (conf < 0 || conf & DS1621_REG_CONFIG_NVB) | 245 | /* The 7 lowest bits of a temperature should always be 0. */ |
246 | for (i = 0; i < ARRAY_SIZE(DS1621_REG_TEMP); i++) { | ||
247 | temp = i2c_smbus_read_word_data(client, DS1621_REG_TEMP[i]); | ||
248 | if (temp < 0 || (temp & 0x7f00)) | ||
246 | return -ENODEV; | 249 | return -ENODEV; |
247 | /* The 7 lowest bits of a temperature should always be 0. */ | ||
248 | for (i = 0; i < ARRAY_SIZE(DS1621_REG_TEMP); i++) { | ||
249 | temp = i2c_smbus_read_word_data(client, | ||
250 | DS1621_REG_TEMP[i]); | ||
251 | if (temp < 0 || (temp & 0x7f00)) | ||
252 | return -ENODEV; | ||
253 | } | ||
254 | } | 250 | } |
255 | 251 | ||
256 | strlcpy(info->type, "ds1621", I2C_NAME_SIZE); | 252 | strlcpy(info->type, "ds1621", I2C_NAME_SIZE); |
diff --git a/drivers/hwmon/f75375s.c b/drivers/hwmon/f75375s.c index e2107e533ede..40dfbcd3f3f2 100644 --- a/drivers/hwmon/f75375s.c +++ b/drivers/hwmon/f75375s.c | |||
@@ -681,30 +681,20 @@ static int f75375_detect(struct i2c_client *client, int kind, | |||
681 | struct i2c_board_info *info) | 681 | struct i2c_board_info *info) |
682 | { | 682 | { |
683 | struct i2c_adapter *adapter = client->adapter; | 683 | struct i2c_adapter *adapter = client->adapter; |
684 | u8 version = 0; | 684 | u16 vendid, chipid; |
685 | const char *name = ""; | 685 | u8 version; |
686 | 686 | const char *name; | |
687 | if (kind < 0) { | ||
688 | u16 vendid = f75375_read16(client, F75375_REG_VENDOR); | ||
689 | u16 chipid = f75375_read16(client, F75375_CHIP_ID); | ||
690 | version = f75375_read8(client, F75375_REG_VERSION); | ||
691 | if (chipid == 0x0306 && vendid == 0x1934) { | ||
692 | kind = f75375; | ||
693 | } else if (chipid == 0x0204 && vendid == 0x1934) { | ||
694 | kind = f75373; | ||
695 | } else { | ||
696 | dev_err(&adapter->dev, | ||
697 | "failed,%02X,%02X,%02X\n", | ||
698 | chipid, version, vendid); | ||
699 | return -ENODEV; | ||
700 | } | ||
701 | } | ||
702 | 687 | ||
703 | if (kind == f75375) { | 688 | vendid = f75375_read16(client, F75375_REG_VENDOR); |
689 | chipid = f75375_read16(client, F75375_CHIP_ID); | ||
690 | if (chipid == 0x0306 && vendid == 0x1934) | ||
704 | name = "f75375"; | 691 | name = "f75375"; |
705 | } else if (kind == f75373) { | 692 | else if (chipid == 0x0204 && vendid == 0x1934) |
706 | name = "f75373"; | 693 | name = "f75373"; |
707 | } | 694 | else |
695 | return -ENODEV; | ||
696 | |||
697 | version = f75375_read8(client, F75375_REG_VERSION); | ||
708 | dev_info(&adapter->dev, "found %s version: %02X\n", name, version); | 698 | dev_info(&adapter->dev, "found %s version: %02X\n", name, version); |
709 | strlcpy(info->type, name, I2C_NAME_SIZE); | 699 | strlcpy(info->type, name, I2C_NAME_SIZE); |
710 | 700 | ||
diff --git a/drivers/hwmon/fschmd.c b/drivers/hwmon/fschmd.c index da1b1f9488af..281829cd1533 100644 --- a/drivers/hwmon/fschmd.c +++ b/drivers/hwmon/fschmd.c | |||
@@ -1000,43 +1000,38 @@ static void fschmd_dmi_decode(const struct dmi_header *header, void *dummy) | |||
1000 | } | 1000 | } |
1001 | } | 1001 | } |
1002 | 1002 | ||
1003 | static int fschmd_detect(struct i2c_client *client, int kind, | 1003 | static int fschmd_detect(struct i2c_client *client, int _kind, |
1004 | struct i2c_board_info *info) | 1004 | struct i2c_board_info *info) |
1005 | { | 1005 | { |
1006 | enum chips kind; | ||
1006 | struct i2c_adapter *adapter = client->adapter; | 1007 | struct i2c_adapter *adapter = client->adapter; |
1008 | char id[4]; | ||
1007 | 1009 | ||
1008 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 1010 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
1009 | return -ENODEV; | 1011 | return -ENODEV; |
1010 | 1012 | ||
1011 | /* Detect & Identify the chip */ | 1013 | /* Detect & Identify the chip */ |
1012 | if (kind <= 0) { | 1014 | id[0] = i2c_smbus_read_byte_data(client, FSCHMD_REG_IDENT_0); |
1013 | char id[4]; | 1015 | id[1] = i2c_smbus_read_byte_data(client, FSCHMD_REG_IDENT_1); |
1014 | 1016 | id[2] = i2c_smbus_read_byte_data(client, FSCHMD_REG_IDENT_2); | |
1015 | id[0] = i2c_smbus_read_byte_data(client, | 1017 | id[3] = '\0'; |
1016 | FSCHMD_REG_IDENT_0); | 1018 | |
1017 | id[1] = i2c_smbus_read_byte_data(client, | 1019 | if (!strcmp(id, "PEG")) |
1018 | FSCHMD_REG_IDENT_1); | 1020 | kind = fscpos; |
1019 | id[2] = i2c_smbus_read_byte_data(client, | 1021 | else if (!strcmp(id, "HER")) |
1020 | FSCHMD_REG_IDENT_2); | 1022 | kind = fscher; |
1021 | id[3] = '\0'; | 1023 | else if (!strcmp(id, "SCY")) |
1022 | 1024 | kind = fscscy; | |
1023 | if (!strcmp(id, "PEG")) | 1025 | else if (!strcmp(id, "HRC")) |
1024 | kind = fscpos; | 1026 | kind = fschrc; |
1025 | else if (!strcmp(id, "HER")) | 1027 | else if (!strcmp(id, "HMD")) |
1026 | kind = fscher; | 1028 | kind = fschmd; |
1027 | else if (!strcmp(id, "SCY")) | 1029 | else if (!strcmp(id, "HDS")) |
1028 | kind = fscscy; | 1030 | kind = fschds; |
1029 | else if (!strcmp(id, "HRC")) | 1031 | else if (!strcmp(id, "SYL")) |
1030 | kind = fschrc; | 1032 | kind = fscsyl; |
1031 | else if (!strcmp(id, "HMD")) | 1033 | else |
1032 | kind = fschmd; | 1034 | return -ENODEV; |
1033 | else if (!strcmp(id, "HDS")) | ||
1034 | kind = fschds; | ||
1035 | else if (!strcmp(id, "SYL")) | ||
1036 | kind = fscsyl; | ||
1037 | else | ||
1038 | return -ENODEV; | ||
1039 | } | ||
1040 | 1035 | ||
1041 | strlcpy(info->type, fschmd_id[kind - 1].name, I2C_NAME_SIZE); | 1036 | strlcpy(info->type, fschmd_id[kind - 1].name, I2C_NAME_SIZE); |
1042 | 1037 | ||
diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c index 7820df45d77a..1d69458aa0b6 100644 --- a/drivers/hwmon/gl518sm.c +++ b/drivers/hwmon/gl518sm.c | |||
@@ -488,36 +488,21 @@ static int gl518_detect(struct i2c_client *client, int kind, | |||
488 | struct i2c_board_info *info) | 488 | struct i2c_board_info *info) |
489 | { | 489 | { |
490 | struct i2c_adapter *adapter = client->adapter; | 490 | struct i2c_adapter *adapter = client->adapter; |
491 | int i; | 491 | int rev; |
492 | 492 | ||
493 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | | 493 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | |
494 | I2C_FUNC_SMBUS_WORD_DATA)) | 494 | I2C_FUNC_SMBUS_WORD_DATA)) |
495 | return -ENODEV; | 495 | return -ENODEV; |
496 | 496 | ||
497 | /* Now, we do the remaining detection. */ | 497 | /* Now, we do the remaining detection. */ |
498 | 498 | if ((gl518_read_value(client, GL518_REG_CHIP_ID) != 0x80) | |
499 | if (kind < 0) { | 499 | || (gl518_read_value(client, GL518_REG_CONF) & 0x80)) |
500 | if ((gl518_read_value(client, GL518_REG_CHIP_ID) != 0x80) | 500 | return -ENODEV; |
501 | || (gl518_read_value(client, GL518_REG_CONF) & 0x80)) | ||
502 | return -ENODEV; | ||
503 | } | ||
504 | 501 | ||
505 | /* Determine the chip type. */ | 502 | /* Determine the chip type. */ |
506 | if (kind <= 0) { | 503 | rev = gl518_read_value(client, GL518_REG_REVISION); |
507 | i = gl518_read_value(client, GL518_REG_REVISION); | 504 | if (rev != 0x00 && rev != 0x80) |
508 | if (i == 0x00) { | 505 | return -ENODEV; |
509 | kind = gl518sm_r00; | ||
510 | } else if (i == 0x80) { | ||
511 | kind = gl518sm_r80; | ||
512 | } else { | ||
513 | if (kind <= 0) | ||
514 | dev_info(&adapter->dev, | ||
515 | "Ignoring 'force' parameter for unknown " | ||
516 | "chip at adapter %d, address 0x%02x\n", | ||
517 | i2c_adapter_id(adapter), client->addr); | ||
518 | return -ENODEV; | ||
519 | } | ||
520 | } | ||
521 | 506 | ||
522 | strlcpy(info->type, "gl518sm", I2C_NAME_SIZE); | 507 | strlcpy(info->type, "gl518sm", I2C_NAME_SIZE); |
523 | 508 | ||
diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c index 19616f2242b0..92b5720ceaff 100644 --- a/drivers/hwmon/gl520sm.c +++ b/drivers/hwmon/gl520sm.c | |||
@@ -691,13 +691,11 @@ static int gl520_detect(struct i2c_client *client, int kind, | |||
691 | return -ENODEV; | 691 | return -ENODEV; |
692 | 692 | ||
693 | /* Determine the chip type. */ | 693 | /* Determine the chip type. */ |
694 | if (kind < 0) { | 694 | if ((gl520_read_value(client, GL520_REG_CHIP_ID) != 0x20) || |
695 | if ((gl520_read_value(client, GL520_REG_CHIP_ID) != 0x20) || | 695 | ((gl520_read_value(client, GL520_REG_REVISION) & 0x7f) != 0x00) || |
696 | ((gl520_read_value(client, GL520_REG_REVISION) & 0x7f) != 0x00) || | 696 | ((gl520_read_value(client, GL520_REG_CONF) & 0x80) != 0x00)) { |
697 | ((gl520_read_value(client, GL520_REG_CONF) & 0x80) != 0x00)) { | 697 | dev_dbg(&client->dev, "Unknown chip type, skipping\n"); |
698 | dev_dbg(&client->dev, "Unknown chip type, skipping\n"); | 698 | return -ENODEV; |
699 | return -ENODEV; | ||
700 | } | ||
701 | } | 699 | } |
702 | 700 | ||
703 | strlcpy(info->type, "gl520sm", I2C_NAME_SIZE); | 701 | strlcpy(info->type, "gl520sm", I2C_NAME_SIZE); |
diff --git a/drivers/hwmon/lm63.c b/drivers/hwmon/lm63.c index 3195a265f0e9..5da66ab04f74 100644 --- a/drivers/hwmon/lm63.c +++ b/drivers/hwmon/lm63.c | |||
@@ -427,40 +427,34 @@ static int lm63_detect(struct i2c_client *new_client, int kind, | |||
427 | struct i2c_board_info *info) | 427 | struct i2c_board_info *info) |
428 | { | 428 | { |
429 | struct i2c_adapter *adapter = new_client->adapter; | 429 | struct i2c_adapter *adapter = new_client->adapter; |
430 | u8 man_id, chip_id, reg_config1, reg_config2; | ||
431 | u8 reg_alert_status, reg_alert_mask; | ||
430 | 432 | ||
431 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 433 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
432 | return -ENODEV; | 434 | return -ENODEV; |
433 | 435 | ||
434 | if (kind < 0) { /* must identify */ | 436 | man_id = i2c_smbus_read_byte_data(new_client, LM63_REG_MAN_ID); |
435 | u8 man_id, chip_id, reg_config1, reg_config2; | 437 | chip_id = i2c_smbus_read_byte_data(new_client, LM63_REG_CHIP_ID); |
436 | u8 reg_alert_status, reg_alert_mask; | 438 | |
437 | 439 | reg_config1 = i2c_smbus_read_byte_data(new_client, | |
438 | man_id = i2c_smbus_read_byte_data(new_client, | 440 | LM63_REG_CONFIG1); |
439 | LM63_REG_MAN_ID); | 441 | reg_config2 = i2c_smbus_read_byte_data(new_client, |
440 | chip_id = i2c_smbus_read_byte_data(new_client, | 442 | LM63_REG_CONFIG2); |
441 | LM63_REG_CHIP_ID); | 443 | reg_alert_status = i2c_smbus_read_byte_data(new_client, |
442 | reg_config1 = i2c_smbus_read_byte_data(new_client, | 444 | LM63_REG_ALERT_STATUS); |
443 | LM63_REG_CONFIG1); | 445 | reg_alert_mask = i2c_smbus_read_byte_data(new_client, |
444 | reg_config2 = i2c_smbus_read_byte_data(new_client, | 446 | LM63_REG_ALERT_MASK); |
445 | LM63_REG_CONFIG2); | 447 | |
446 | reg_alert_status = i2c_smbus_read_byte_data(new_client, | 448 | if (man_id != 0x01 /* National Semiconductor */ |
447 | LM63_REG_ALERT_STATUS); | 449 | || chip_id != 0x41 /* LM63 */ |
448 | reg_alert_mask = i2c_smbus_read_byte_data(new_client, | 450 | || (reg_config1 & 0x18) != 0x00 |
449 | LM63_REG_ALERT_MASK); | 451 | || (reg_config2 & 0xF8) != 0x00 |
450 | 452 | || (reg_alert_status & 0x20) != 0x00 | |
451 | if (man_id == 0x01 /* National Semiconductor */ | 453 | || (reg_alert_mask & 0xA4) != 0xA4) { |
452 | && chip_id == 0x41 /* LM63 */ | 454 | dev_dbg(&adapter->dev, |
453 | && (reg_config1 & 0x18) == 0x00 | 455 | "Unsupported chip (man_id=0x%02X, chip_id=0x%02X)\n", |
454 | && (reg_config2 & 0xF8) == 0x00 | 456 | man_id, chip_id); |
455 | && (reg_alert_status & 0x20) == 0x00 | 457 | return -ENODEV; |
456 | && (reg_alert_mask & 0xA4) == 0xA4) { | ||
457 | kind = lm63; | ||
458 | } else { /* failed */ | ||
459 | dev_dbg(&adapter->dev, "Unsupported chip " | ||
460 | "(man_id=0x%02X, chip_id=0x%02X).\n", | ||
461 | man_id, chip_id); | ||
462 | return -ENODEV; | ||
463 | } | ||
464 | } | 458 | } |
465 | 459 | ||
466 | strlcpy(info->type, "lm63", I2C_NAME_SIZE); | 460 | strlcpy(info->type, "lm63", I2C_NAME_SIZE); |
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index 55bd87c15c9a..e392548cccb8 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c | |||
@@ -239,6 +239,7 @@ static int lm75_detect(struct i2c_client *new_client, int kind, | |||
239 | { | 239 | { |
240 | struct i2c_adapter *adapter = new_client->adapter; | 240 | struct i2c_adapter *adapter = new_client->adapter; |
241 | int i; | 241 | int i; |
242 | int cur, conf, hyst, os; | ||
242 | 243 | ||
243 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | | 244 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | |
244 | I2C_FUNC_SMBUS_WORD_DATA)) | 245 | I2C_FUNC_SMBUS_WORD_DATA)) |
@@ -251,40 +252,35 @@ static int lm75_detect(struct i2c_client *new_client, int kind, | |||
251 | The cycling+unused addresses combination is not tested, | 252 | The cycling+unused addresses combination is not tested, |
252 | since it would significantly slow the detection down and would | 253 | since it would significantly slow the detection down and would |
253 | hardly add any value. */ | 254 | hardly add any value. */ |
254 | if (kind < 0) { | ||
255 | int cur, conf, hyst, os; | ||
256 | |||
257 | /* Unused addresses */ | ||
258 | cur = i2c_smbus_read_word_data(new_client, 0); | ||
259 | conf = i2c_smbus_read_byte_data(new_client, 1); | ||
260 | hyst = i2c_smbus_read_word_data(new_client, 2); | ||
261 | if (i2c_smbus_read_word_data(new_client, 4) != hyst | ||
262 | || i2c_smbus_read_word_data(new_client, 5) != hyst | ||
263 | || i2c_smbus_read_word_data(new_client, 6) != hyst | ||
264 | || i2c_smbus_read_word_data(new_client, 7) != hyst) | ||
265 | return -ENODEV; | ||
266 | os = i2c_smbus_read_word_data(new_client, 3); | ||
267 | if (i2c_smbus_read_word_data(new_client, 4) != os | ||
268 | || i2c_smbus_read_word_data(new_client, 5) != os | ||
269 | || i2c_smbus_read_word_data(new_client, 6) != os | ||
270 | || i2c_smbus_read_word_data(new_client, 7) != os) | ||
271 | return -ENODEV; | ||
272 | 255 | ||
273 | /* Unused bits */ | 256 | /* Unused addresses */ |
274 | if (conf & 0xe0) | 257 | cur = i2c_smbus_read_word_data(new_client, 0); |
275 | return -ENODEV; | 258 | conf = i2c_smbus_read_byte_data(new_client, 1); |
259 | hyst = i2c_smbus_read_word_data(new_client, 2); | ||
260 | if (i2c_smbus_read_word_data(new_client, 4) != hyst | ||
261 | || i2c_smbus_read_word_data(new_client, 5) != hyst | ||
262 | || i2c_smbus_read_word_data(new_client, 6) != hyst | ||
263 | || i2c_smbus_read_word_data(new_client, 7) != hyst) | ||
264 | return -ENODEV; | ||
265 | os = i2c_smbus_read_word_data(new_client, 3); | ||
266 | if (i2c_smbus_read_word_data(new_client, 4) != os | ||
267 | || i2c_smbus_read_word_data(new_client, 5) != os | ||
268 | || i2c_smbus_read_word_data(new_client, 6) != os | ||
269 | || i2c_smbus_read_word_data(new_client, 7) != os) | ||
270 | return -ENODEV; | ||
276 | 271 | ||
277 | /* Addresses cycling */ | 272 | /* Unused bits */ |
278 | for (i = 8; i < 0xff; i += 8) | 273 | if (conf & 0xe0) |
279 | if (i2c_smbus_read_byte_data(new_client, i + 1) != conf | 274 | return -ENODEV; |
280 | || i2c_smbus_read_word_data(new_client, i + 2) != hyst | 275 | |
281 | || i2c_smbus_read_word_data(new_client, i + 3) != os) | 276 | /* Addresses cycling */ |
282 | return -ENODEV; | 277 | for (i = 8; i < 0xff; i += 8) { |
278 | if (i2c_smbus_read_byte_data(new_client, i + 1) != conf | ||
279 | || i2c_smbus_read_word_data(new_client, i + 2) != hyst | ||
280 | || i2c_smbus_read_word_data(new_client, i + 3) != os) | ||
281 | return -ENODEV; | ||
283 | } | 282 | } |
284 | 283 | ||
285 | /* NOTE: we treat "force=..." and "force_lm75=..." the same. | ||
286 | * Only new-style driver binding distinguishes chip types. | ||
287 | */ | ||
288 | strlcpy(info->type, "lm75", I2C_NAME_SIZE); | 284 | strlcpy(info->type, "lm75", I2C_NAME_SIZE); |
289 | 285 | ||
290 | return 0; | 286 | return 0; |
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c index f7e70163e016..5978291cebb3 100644 --- a/drivers/hwmon/lm78.c +++ b/drivers/hwmon/lm78.c | |||
@@ -576,52 +576,34 @@ static int lm78_i2c_detect(struct i2c_client *client, int kind, | |||
576 | if (isa) | 576 | if (isa) |
577 | mutex_lock(&isa->update_lock); | 577 | mutex_lock(&isa->update_lock); |
578 | 578 | ||
579 | if (kind < 0) { | 579 | if ((i2c_smbus_read_byte_data(client, LM78_REG_CONFIG) & 0x80) |
580 | if ((i2c_smbus_read_byte_data(client, LM78_REG_CONFIG) & 0x80) | 580 | || i2c_smbus_read_byte_data(client, LM78_REG_I2C_ADDR) != address) |
581 | || i2c_smbus_read_byte_data(client, LM78_REG_I2C_ADDR) | 581 | goto err_nodev; |
582 | != address) | 582 | |
583 | goto err_nodev; | 583 | /* Explicitly prevent the misdetection of Winbond chips */ |
584 | 584 | i = i2c_smbus_read_byte_data(client, 0x4f); | |
585 | /* Explicitly prevent the misdetection of Winbond chips */ | 585 | if (i == 0xa3 || i == 0x5c) |
586 | i = i2c_smbus_read_byte_data(client, 0x4f); | 586 | goto err_nodev; |
587 | if (i == 0xa3 || i == 0x5c) | ||
588 | goto err_nodev; | ||
589 | } | ||
590 | 587 | ||
591 | /* Determine the chip type. */ | 588 | /* Determine the chip type. */ |
592 | if (kind <= 0) { | 589 | i = i2c_smbus_read_byte_data(client, LM78_REG_CHIPID); |
593 | i = i2c_smbus_read_byte_data(client, LM78_REG_CHIPID); | 590 | if (i == 0x00 || i == 0x20 /* LM78 */ |
594 | if (i == 0x00 || i == 0x20 /* LM78 */ | 591 | || i == 0x40) /* LM78-J */ |
595 | || i == 0x40) /* LM78-J */ | 592 | client_name = "lm78"; |
596 | kind = lm78; | 593 | else if ((i & 0xfe) == 0xc0) |
597 | else if ((i & 0xfe) == 0xc0) | 594 | client_name = "lm79"; |
598 | kind = lm79; | 595 | else |
599 | else { | 596 | goto err_nodev; |
600 | if (kind == 0) | ||
601 | dev_warn(&adapter->dev, "Ignoring 'force' " | ||
602 | "parameter for unknown chip at " | ||
603 | "adapter %d, address 0x%02x\n", | ||
604 | i2c_adapter_id(adapter), address); | ||
605 | goto err_nodev; | ||
606 | } | ||
607 | 597 | ||
608 | if (lm78_alias_detect(client, i)) { | 598 | if (lm78_alias_detect(client, i)) { |
609 | dev_dbg(&adapter->dev, "Device at 0x%02x appears to " | 599 | dev_dbg(&adapter->dev, "Device at 0x%02x appears to " |
610 | "be the same as ISA device\n", address); | 600 | "be the same as ISA device\n", address); |
611 | goto err_nodev; | 601 | goto err_nodev; |
612 | } | ||
613 | } | 602 | } |
614 | 603 | ||
615 | if (isa) | 604 | if (isa) |
616 | mutex_unlock(&isa->update_lock); | 605 | mutex_unlock(&isa->update_lock); |
617 | 606 | ||
618 | switch (kind) { | ||
619 | case lm79: | ||
620 | client_name = "lm79"; | ||
621 | break; | ||
622 | default: | ||
623 | client_name = "lm78"; | ||
624 | } | ||
625 | strlcpy(info->type, client_name, I2C_NAME_SIZE); | 607 | strlcpy(info->type, client_name, I2C_NAME_SIZE); |
626 | 608 | ||
627 | return 0; | 609 | return 0; |
diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c index 2e4a3cea95f7..4929b1815eee 100644 --- a/drivers/hwmon/lm87.c +++ b/drivers/hwmon/lm87.c | |||
@@ -666,37 +666,32 @@ static int lm87_detect(struct i2c_client *new_client, int kind, | |||
666 | struct i2c_board_info *info) | 666 | struct i2c_board_info *info) |
667 | { | 667 | { |
668 | struct i2c_adapter *adapter = new_client->adapter; | 668 | struct i2c_adapter *adapter = new_client->adapter; |
669 | static const char *names[] = { "lm87", "adm1024" }; | 669 | const char *name; |
670 | u8 cid, rev; | ||
670 | 671 | ||
671 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 672 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
672 | return -ENODEV; | 673 | return -ENODEV; |
673 | 674 | ||
674 | /* Default to an LM87 if forced */ | 675 | if (lm87_read_value(new_client, LM87_REG_CONFIG) & 0x80) |
675 | if (kind == 0) | 676 | return -ENODEV; |
676 | kind = lm87; | ||
677 | 677 | ||
678 | /* Now, we do the remaining detection. */ | 678 | /* Now, we do the remaining detection. */ |
679 | if (kind < 0) { | 679 | cid = lm87_read_value(new_client, LM87_REG_COMPANY_ID); |
680 | u8 cid = lm87_read_value(new_client, LM87_REG_COMPANY_ID); | 680 | rev = lm87_read_value(new_client, LM87_REG_REVISION); |
681 | u8 rev = lm87_read_value(new_client, LM87_REG_REVISION); | 681 | |
682 | 682 | if (cid == 0x02 /* National Semiconductor */ | |
683 | if (cid == 0x02 /* National Semiconductor */ | 683 | && (rev >= 0x01 && rev <= 0x08)) |
684 | && (rev >= 0x01 && rev <= 0x08)) | 684 | name = "lm87"; |
685 | kind = lm87; | 685 | else if (cid == 0x41 /* Analog Devices */ |
686 | else if (cid == 0x41 /* Analog Devices */ | 686 | && (rev & 0xf0) == 0x10) |
687 | && (rev & 0xf0) == 0x10) | 687 | name = "adm1024"; |
688 | kind = adm1024; | 688 | else { |
689 | 689 | dev_dbg(&adapter->dev, "LM87 detection failed at 0x%02x\n", | |
690 | if (kind < 0 | 690 | new_client->addr); |
691 | || (lm87_read_value(new_client, LM87_REG_CONFIG) & 0x80)) { | 691 | return -ENODEV; |
692 | dev_dbg(&adapter->dev, | ||
693 | "LM87 detection failed at 0x%02x.\n", | ||
694 | new_client->addr); | ||
695 | return -ENODEV; | ||
696 | } | ||
697 | } | 692 | } |
698 | 693 | ||
699 | strlcpy(info->type, names[kind - 1], I2C_NAME_SIZE); | 694 | strlcpy(info->type, name, I2C_NAME_SIZE); |
700 | 695 | ||
701 | return 0; | 696 | return 0; |
702 | } | 697 | } |
diff --git a/drivers/hwmon/lm92.c b/drivers/hwmon/lm92.c index b2e00c5a7eec..47ac698709dc 100644 --- a/drivers/hwmon/lm92.c +++ b/drivers/hwmon/lm92.c | |||
@@ -323,31 +323,22 @@ static int lm92_detect(struct i2c_client *new_client, int kind, | |||
323 | struct i2c_board_info *info) | 323 | struct i2c_board_info *info) |
324 | { | 324 | { |
325 | struct i2c_adapter *adapter = new_client->adapter; | 325 | struct i2c_adapter *adapter = new_client->adapter; |
326 | u8 config; | ||
327 | u16 man_id; | ||
326 | 328 | ||
327 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | 329 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
328 | | I2C_FUNC_SMBUS_WORD_DATA)) | 330 | | I2C_FUNC_SMBUS_WORD_DATA)) |
329 | return -ENODEV; | 331 | return -ENODEV; |
330 | 332 | ||
331 | /* A negative kind means that the driver was loaded with no force | 333 | config = i2c_smbus_read_byte_data(new_client, LM92_REG_CONFIG); |
332 | parameter (default), so we must identify the chip. */ | 334 | man_id = i2c_smbus_read_word_data(new_client, LM92_REG_MAN_ID); |
333 | if (kind < 0) { | 335 | |
334 | u8 config = i2c_smbus_read_byte_data(new_client, | 336 | if ((config & 0xe0) == 0x00 && man_id == 0x0180) |
335 | LM92_REG_CONFIG); | 337 | pr_info("lm92: Found National Semiconductor LM92 chip\n"); |
336 | u16 man_id = i2c_smbus_read_word_data(new_client, | 338 | else if (max6635_check(new_client)) |
337 | LM92_REG_MAN_ID); | 339 | pr_info("lm92: Found Maxim MAX6635 chip\n"); |
338 | 340 | else | |
339 | if ((config & 0xe0) == 0x00 | 341 | return -ENODEV; |
340 | && man_id == 0x0180) { | ||
341 | pr_info("lm92: Found National Semiconductor LM92 chip\n"); | ||
342 | kind = lm92; | ||
343 | } else | ||
344 | if (max6635_check(new_client)) { | ||
345 | pr_info("lm92: Found Maxim MAX6635 chip\n"); | ||
346 | kind = lm92; /* No separate prefix */ | ||
347 | } | ||
348 | else | ||
349 | return -ENODEV; | ||
350 | } | ||
351 | 342 | ||
352 | strlcpy(info->type, "lm92", I2C_NAME_SIZE); | 343 | strlcpy(info->type, "lm92", I2C_NAME_SIZE); |
353 | 344 | ||
diff --git a/drivers/hwmon/lm93.c b/drivers/hwmon/lm93.c index fc36cadf36fb..495e7ce6f8a1 100644 --- a/drivers/hwmon/lm93.c +++ b/drivers/hwmon/lm93.c | |||
@@ -2505,34 +2505,24 @@ static int lm93_detect(struct i2c_client *client, int kind, | |||
2505 | struct i2c_board_info *info) | 2505 | struct i2c_board_info *info) |
2506 | { | 2506 | { |
2507 | struct i2c_adapter *adapter = client->adapter; | 2507 | struct i2c_adapter *adapter = client->adapter; |
2508 | int mfr, ver; | ||
2508 | 2509 | ||
2509 | if (!i2c_check_functionality(adapter, LM93_SMBUS_FUNC_MIN)) | 2510 | if (!i2c_check_functionality(adapter, LM93_SMBUS_FUNC_MIN)) |
2510 | return -ENODEV; | 2511 | return -ENODEV; |
2511 | 2512 | ||
2512 | /* detection */ | 2513 | /* detection */ |
2513 | if (kind < 0) { | 2514 | mfr = lm93_read_byte(client, LM93_REG_MFR_ID); |
2514 | int mfr = lm93_read_byte(client, LM93_REG_MFR_ID); | 2515 | if (mfr != 0x01) { |
2515 | 2516 | dev_dbg(&adapter->dev, | |
2516 | if (mfr != 0x01) { | 2517 | "detect failed, bad manufacturer id 0x%02x!\n", mfr); |
2517 | dev_dbg(&adapter->dev,"detect failed, " | 2518 | return -ENODEV; |
2518 | "bad manufacturer id 0x%02x!\n", mfr); | ||
2519 | return -ENODEV; | ||
2520 | } | ||
2521 | } | 2519 | } |
2522 | 2520 | ||
2523 | if (kind <= 0) { | 2521 | ver = lm93_read_byte(client, LM93_REG_VER); |
2524 | int ver = lm93_read_byte(client, LM93_REG_VER); | 2522 | if (ver != LM93_MFR_ID && ver != LM93_MFR_ID_PROTOTYPE) { |
2525 | 2523 | dev_dbg(&adapter->dev, | |
2526 | if ((ver == LM93_MFR_ID) || (ver == LM93_MFR_ID_PROTOTYPE)) { | 2524 | "detect failed, bad version id 0x%02x!\n", ver); |
2527 | kind = lm93; | 2525 | return -ENODEV; |
2528 | } else { | ||
2529 | dev_dbg(&adapter->dev,"detect failed, " | ||
2530 | "bad version id 0x%02x!\n", ver); | ||
2531 | if (kind == 0) | ||
2532 | dev_dbg(&adapter->dev, | ||
2533 | "(ignored 'force' parameter)\n"); | ||
2534 | return -ENODEV; | ||
2535 | } | ||
2536 | } | 2526 | } |
2537 | 2527 | ||
2538 | strlcpy(info->type, "lm93", I2C_NAME_SIZE); | 2528 | strlcpy(info->type, "lm93", I2C_NAME_SIZE); |
diff --git a/drivers/hwmon/lm95241.c b/drivers/hwmon/lm95241.c index e34f9e402a2c..906b896cf1d0 100644 --- a/drivers/hwmon/lm95241.c +++ b/drivers/hwmon/lm95241.c | |||
@@ -315,51 +315,23 @@ static int lm95241_detect(struct i2c_client *new_client, int kind, | |||
315 | { | 315 | { |
316 | struct i2c_adapter *adapter = new_client->adapter; | 316 | struct i2c_adapter *adapter = new_client->adapter; |
317 | int address = new_client->addr; | 317 | int address = new_client->addr; |
318 | const char *name = ""; | 318 | const char *name; |
319 | 319 | ||
320 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 320 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
321 | return -ENODEV; | 321 | return -ENODEV; |
322 | 322 | ||
323 | /* | 323 | if ((i2c_smbus_read_byte_data(new_client, LM95241_REG_R_MAN_ID) |
324 | * Now we do the remaining detection. A negative kind means that | 324 | == MANUFACTURER_ID) |
325 | * the driver was loaded with no force parameter (default), so we | 325 | && (i2c_smbus_read_byte_data(new_client, LM95241_REG_R_CHIP_ID) |
326 | * must both detect and identify the chip. A zero kind means that | 326 | >= DEFAULT_REVISION)) { |
327 | * the driver was loaded with the force parameter, the detection | 327 | name = "lm95241"; |
328 | * step shall be skipped. A positive kind means that the driver | 328 | } else { |
329 | * was loaded with the force parameter and a given kind of chip is | 329 | dev_dbg(&adapter->dev, "LM95241 detection failed at 0x%02x\n", |
330 | * requested, so both the detection and the identification steps | 330 | address); |
331 | * are skipped. | 331 | return -ENODEV; |
332 | */ | ||
333 | if (kind < 0) { /* detection */ | ||
334 | if ((i2c_smbus_read_byte_data(new_client, LM95241_REG_R_MAN_ID) | ||
335 | != MANUFACTURER_ID) | ||
336 | || (i2c_smbus_read_byte_data(new_client, LM95241_REG_R_CHIP_ID) | ||
337 | < DEFAULT_REVISION)) { | ||
338 | dev_dbg(&adapter->dev, | ||
339 | "LM95241 detection failed at 0x%02x.\n", | ||
340 | address); | ||
341 | return -ENODEV; | ||
342 | } | ||
343 | } | ||
344 | |||
345 | if (kind <= 0) { /* identification */ | ||
346 | if ((i2c_smbus_read_byte_data(new_client, LM95241_REG_R_MAN_ID) | ||
347 | == MANUFACTURER_ID) | ||
348 | && (i2c_smbus_read_byte_data(new_client, LM95241_REG_R_CHIP_ID) | ||
349 | >= DEFAULT_REVISION)) { | ||
350 | |||
351 | kind = lm95241; | ||
352 | |||
353 | if (kind <= 0) { /* identification failed */ | ||
354 | dev_info(&adapter->dev, "Unsupported chip\n"); | ||
355 | return -ENODEV; | ||
356 | } | ||
357 | } | ||
358 | } | 332 | } |
359 | 333 | ||
360 | /* Fill the i2c board info */ | 334 | /* Fill the i2c board info */ |
361 | if (kind == lm95241) | ||
362 | name = "lm95241"; | ||
363 | strlcpy(info->type, name, I2C_NAME_SIZE); | 335 | strlcpy(info->type, name, I2C_NAME_SIZE); |
364 | return 0; | 336 | return 0; |
365 | } | 337 | } |
diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c index 7897754f3a5c..7fcf5ff89e7f 100644 --- a/drivers/hwmon/max1619.c +++ b/drivers/hwmon/max1619.c | |||
@@ -226,58 +226,34 @@ static const struct attribute_group max1619_group = { | |||
226 | */ | 226 | */ |
227 | 227 | ||
228 | /* Return 0 if detection is successful, -ENODEV otherwise */ | 228 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
229 | static int max1619_detect(struct i2c_client *new_client, int kind, | 229 | static int max1619_detect(struct i2c_client *client, int kind, |
230 | struct i2c_board_info *info) | 230 | struct i2c_board_info *info) |
231 | { | 231 | { |
232 | struct i2c_adapter *adapter = new_client->adapter; | 232 | struct i2c_adapter *adapter = client->adapter; |
233 | u8 reg_config=0, reg_convrate=0, reg_status=0; | 233 | u8 reg_config, reg_convrate, reg_status, man_id, chip_id; |
234 | 234 | ||
235 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 235 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
236 | return -ENODEV; | 236 | return -ENODEV; |
237 | 237 | ||
238 | /* | 238 | /* detection */ |
239 | * Now we do the remaining detection. A negative kind means that | 239 | reg_config = i2c_smbus_read_byte_data(client, MAX1619_REG_R_CONFIG); |
240 | * the driver was loaded with no force parameter (default), so we | 240 | reg_convrate = i2c_smbus_read_byte_data(client, MAX1619_REG_R_CONVRATE); |
241 | * must both detect and identify the chip. A zero kind means that | 241 | reg_status = i2c_smbus_read_byte_data(client, MAX1619_REG_R_STATUS); |
242 | * the driver was loaded with the force parameter, the detection | 242 | if ((reg_config & 0x03) != 0x00 |
243 | * step shall be skipped. A positive kind means that the driver | 243 | || reg_convrate > 0x07 || (reg_status & 0x61) != 0x00) { |
244 | * was loaded with the force parameter and a given kind of chip is | 244 | dev_dbg(&adapter->dev, "MAX1619 detection failed at 0x%02x\n", |
245 | * requested, so both the detection and the identification steps | 245 | client->addr); |
246 | * are skipped. | 246 | return -ENODEV; |
247 | */ | ||
248 | if (kind < 0) { /* detection */ | ||
249 | reg_config = i2c_smbus_read_byte_data(new_client, | ||
250 | MAX1619_REG_R_CONFIG); | ||
251 | reg_convrate = i2c_smbus_read_byte_data(new_client, | ||
252 | MAX1619_REG_R_CONVRATE); | ||
253 | reg_status = i2c_smbus_read_byte_data(new_client, | ||
254 | MAX1619_REG_R_STATUS); | ||
255 | if ((reg_config & 0x03) != 0x00 | ||
256 | || reg_convrate > 0x07 || (reg_status & 0x61 ) !=0x00) { | ||
257 | dev_dbg(&adapter->dev, | ||
258 | "MAX1619 detection failed at 0x%02x.\n", | ||
259 | new_client->addr); | ||
260 | return -ENODEV; | ||
261 | } | ||
262 | } | 247 | } |
263 | 248 | ||
264 | if (kind <= 0) { /* identification */ | 249 | /* identification */ |
265 | u8 man_id, chip_id; | 250 | man_id = i2c_smbus_read_byte_data(client, MAX1619_REG_R_MAN_ID); |
266 | 251 | chip_id = i2c_smbus_read_byte_data(client, MAX1619_REG_R_CHIP_ID); | |
267 | man_id = i2c_smbus_read_byte_data(new_client, | 252 | if (man_id != 0x4D || chip_id != 0x04) { |
268 | MAX1619_REG_R_MAN_ID); | 253 | dev_info(&adapter->dev, |
269 | chip_id = i2c_smbus_read_byte_data(new_client, | 254 | "Unsupported chip (man_id=0x%02X, chip_id=0x%02X).\n", |
270 | MAX1619_REG_R_CHIP_ID); | 255 | man_id, chip_id); |
271 | 256 | return -ENODEV; | |
272 | if ((man_id == 0x4D) && (chip_id == 0x04)) | ||
273 | kind = max1619; | ||
274 | |||
275 | if (kind <= 0) { /* identification failed */ | ||
276 | dev_info(&adapter->dev, | ||
277 | "Unsupported chip (man_id=0x%02X, " | ||
278 | "chip_id=0x%02X).\n", man_id, chip_id); | ||
279 | return -ENODEV; | ||
280 | } | ||
281 | } | 257 | } |
282 | 258 | ||
283 | strlcpy(info->type, "max1619", I2C_NAME_SIZE); | 259 | strlcpy(info->type, "max1619", I2C_NAME_SIZE); |
diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c index 58f66be61b1f..1da561e0cb37 100644 --- a/drivers/hwmon/max6650.c +++ b/drivers/hwmon/max6650.c | |||
@@ -534,7 +534,7 @@ static int max6650_detect(struct i2c_client *client, int kind, | |||
534 | struct i2c_adapter *adapter = client->adapter; | 534 | struct i2c_adapter *adapter = client->adapter; |
535 | int address = client->addr; | 535 | int address = client->addr; |
536 | 536 | ||
537 | dev_dbg(&adapter->dev, "max6650_detect called, kind = %d\n", kind); | 537 | dev_dbg(&adapter->dev, "max6650_detect called\n"); |
538 | 538 | ||
539 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 539 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
540 | dev_dbg(&adapter->dev, "max6650: I2C bus doesn't support " | 540 | dev_dbg(&adapter->dev, "max6650: I2C bus doesn't support " |
@@ -542,23 +542,7 @@ static int max6650_detect(struct i2c_client *client, int kind, | |||
542 | return -ENODEV; | 542 | return -ENODEV; |
543 | } | 543 | } |
544 | 544 | ||
545 | /* | 545 | if (((i2c_smbus_read_byte_data(client, MAX6650_REG_CONFIG) & 0xC0) |
546 | * Now we do the remaining detection. A negative kind means that | ||
547 | * the driver was loaded with no force parameter (default), so we | ||
548 | * must both detect and identify the chip (actually there is only | ||
549 | * one possible kind of chip for now, max6650). A zero kind means that | ||
550 | * the driver was loaded with the force parameter, the detection | ||
551 | * step shall be skipped. A positive kind means that the driver | ||
552 | * was loaded with the force parameter and a given kind of chip is | ||
553 | * requested, so both the detection and the identification steps | ||
554 | * are skipped. | ||
555 | * | ||
556 | * Currently I can find no way to distinguish between a MAX6650 and | ||
557 | * a MAX6651. This driver has only been tried on the former. | ||
558 | */ | ||
559 | |||
560 | if ((kind < 0) && | ||
561 | ( (i2c_smbus_read_byte_data(client, MAX6650_REG_CONFIG) & 0xC0) | ||
562 | ||(i2c_smbus_read_byte_data(client, MAX6650_REG_GPIO_STAT) & 0xE0) | 546 | ||(i2c_smbus_read_byte_data(client, MAX6650_REG_GPIO_STAT) & 0xE0) |
563 | ||(i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM_EN) & 0xE0) | 547 | ||(i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM_EN) & 0xE0) |
564 | ||(i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM) & 0xE0) | 548 | ||(i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM) & 0xE0) |
diff --git a/drivers/hwmon/smsc47m192.c b/drivers/hwmon/smsc47m192.c index 8bb5cb532d4d..4d88c045781c 100644 --- a/drivers/hwmon/smsc47m192.c +++ b/drivers/hwmon/smsc47m192.c | |||
@@ -491,24 +491,22 @@ static int smsc47m192_detect(struct i2c_client *client, int kind, | |||
491 | return -ENODEV; | 491 | return -ENODEV; |
492 | 492 | ||
493 | /* Detection criteria from sensors_detect script */ | 493 | /* Detection criteria from sensors_detect script */ |
494 | if (kind < 0) { | 494 | version = i2c_smbus_read_byte_data(client, SMSC47M192_REG_VERSION); |
495 | if (i2c_smbus_read_byte_data(client, | 495 | if (i2c_smbus_read_byte_data(client, |
496 | SMSC47M192_REG_COMPANY_ID) == 0x55 | 496 | SMSC47M192_REG_COMPANY_ID) == 0x55 |
497 | && ((version = i2c_smbus_read_byte_data(client, | 497 | && (version & 0xf0) == 0x20 |
498 | SMSC47M192_REG_VERSION)) & 0xf0) == 0x20 | 498 | && (i2c_smbus_read_byte_data(client, |
499 | && (i2c_smbus_read_byte_data(client, | ||
500 | SMSC47M192_REG_VID) & 0x70) == 0x00 | 499 | SMSC47M192_REG_VID) & 0x70) == 0x00 |
501 | && (i2c_smbus_read_byte_data(client, | 500 | && (i2c_smbus_read_byte_data(client, |
502 | SMSC47M192_REG_VID4) & 0xfe) == 0x80) { | 501 | SMSC47M192_REG_VID4) & 0xfe) == 0x80) { |
503 | dev_info(&adapter->dev, | 502 | dev_info(&adapter->dev, |
504 | "found SMSC47M192 or compatible, " | 503 | "found SMSC47M192 or compatible, " |
505 | "version 2, stepping A%d\n", version & 0x0f); | 504 | "version 2, stepping A%d\n", version & 0x0f); |
506 | } else { | 505 | } else { |
507 | dev_dbg(&adapter->dev, | 506 | dev_dbg(&adapter->dev, |
508 | "SMSC47M192 detection failed at 0x%02x\n", | 507 | "SMSC47M192 detection failed at 0x%02x\n", |
509 | client->addr); | 508 | client->addr); |
510 | return -ENODEV; | 509 | return -ENODEV; |
511 | } | ||
512 | } | 510 | } |
513 | 511 | ||
514 | strlcpy(info->type, "smsc47m192", I2C_NAME_SIZE); | 512 | strlcpy(info->type, "smsc47m192", I2C_NAME_SIZE); |
diff --git a/drivers/hwmon/thmc50.c b/drivers/hwmon/thmc50.c index 7d97431e132f..1db9bc802f2b 100644 --- a/drivers/hwmon/thmc50.c +++ b/drivers/hwmon/thmc50.c | |||
@@ -289,7 +289,6 @@ static int thmc50_detect(struct i2c_client *client, int kind, | |||
289 | unsigned revision; | 289 | unsigned revision; |
290 | unsigned config; | 290 | unsigned config; |
291 | struct i2c_adapter *adapter = client->adapter; | 291 | struct i2c_adapter *adapter = client->adapter; |
292 | int err = 0; | ||
293 | const char *type_name; | 292 | const char *type_name; |
294 | 293 | ||
295 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 294 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
@@ -301,31 +300,13 @@ static int thmc50_detect(struct i2c_client *client, int kind, | |||
301 | pr_debug("thmc50: Probing for THMC50 at 0x%2X on bus %d\n", | 300 | pr_debug("thmc50: Probing for THMC50 at 0x%2X on bus %d\n", |
302 | client->addr, i2c_adapter_id(client->adapter)); | 301 | client->addr, i2c_adapter_id(client->adapter)); |
303 | 302 | ||
304 | /* Now, we do the remaining detection. */ | ||
305 | company = i2c_smbus_read_byte_data(client, THMC50_REG_COMPANY_ID); | 303 | company = i2c_smbus_read_byte_data(client, THMC50_REG_COMPANY_ID); |
306 | revision = i2c_smbus_read_byte_data(client, THMC50_REG_DIE_CODE); | 304 | revision = i2c_smbus_read_byte_data(client, THMC50_REG_DIE_CODE); |
307 | config = i2c_smbus_read_byte_data(client, THMC50_REG_CONF); | 305 | config = i2c_smbus_read_byte_data(client, THMC50_REG_CONF); |
306 | if (revision < 0xc0 || (config & 0x10)) | ||
307 | return -ENODEV; | ||
308 | 308 | ||
309 | if (kind == 0) | 309 | if (company == 0x41) { |
310 | kind = thmc50; | ||
311 | else if (kind < 0) { | ||
312 | err = -ENODEV; | ||
313 | if (revision >= 0xc0 && ((config & 0x10) == 0)) { | ||
314 | if (company == 0x49) { | ||
315 | kind = thmc50; | ||
316 | err = 0; | ||
317 | } else if (company == 0x41) { | ||
318 | kind = adm1022; | ||
319 | err = 0; | ||
320 | } | ||
321 | } | ||
322 | } | ||
323 | if (err == -ENODEV) { | ||
324 | pr_debug("thmc50: Detection of THMC50/ADM1022 failed\n"); | ||
325 | return err; | ||
326 | } | ||
327 | |||
328 | if (kind == adm1022) { | ||
329 | int id = i2c_adapter_id(client->adapter); | 310 | int id = i2c_adapter_id(client->adapter); |
330 | int i; | 311 | int i; |
331 | 312 | ||
@@ -340,9 +321,13 @@ static int thmc50_detect(struct i2c_client *client, int kind, | |||
340 | config); | 321 | config); |
341 | break; | 322 | break; |
342 | } | 323 | } |
343 | } else { | 324 | } else if (company == 0x49) { |
344 | type_name = "thmc50"; | 325 | type_name = "thmc50"; |
326 | } else { | ||
327 | pr_debug("thmc50: Detection of THMC50/ADM1022 failed\n"); | ||
328 | return -ENODEV; | ||
345 | } | 329 | } |
330 | |||
346 | pr_debug("thmc50: Detected %s (version %x, revision %x)\n", | 331 | pr_debug("thmc50: Detected %s (version %x, revision %x)\n", |
347 | type_name, (revision >> 4) - 0xc, revision & 0xf); | 332 | type_name, (revision >> 4) - 0xc, revision & 0xf); |
348 | 333 | ||
diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c index 47dd398f7258..80a2191bf127 100644 --- a/drivers/hwmon/w83793.c +++ b/drivers/hwmon/w83793.c | |||
@@ -1164,7 +1164,7 @@ ERROR_SC_0: | |||
1164 | static int w83793_detect(struct i2c_client *client, int kind, | 1164 | static int w83793_detect(struct i2c_client *client, int kind, |
1165 | struct i2c_board_info *info) | 1165 | struct i2c_board_info *info) |
1166 | { | 1166 | { |
1167 | u8 tmp, bank; | 1167 | u8 tmp, bank, chip_id; |
1168 | struct i2c_adapter *adapter = client->adapter; | 1168 | struct i2c_adapter *adapter = client->adapter; |
1169 | unsigned short address = client->addr; | 1169 | unsigned short address = client->addr; |
1170 | 1170 | ||
@@ -1174,44 +1174,27 @@ static int w83793_detect(struct i2c_client *client, int kind, | |||
1174 | 1174 | ||
1175 | bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL); | 1175 | bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL); |
1176 | 1176 | ||
1177 | if (kind < 0) { | 1177 | tmp = bank & 0x80 ? 0x5c : 0xa3; |
1178 | tmp = bank & 0x80 ? 0x5c : 0xa3; | 1178 | /* Check Winbond vendor ID */ |
1179 | /* Check Winbond vendor ID */ | 1179 | if (tmp != i2c_smbus_read_byte_data(client, W83793_REG_VENDORID)) { |
1180 | if (tmp != i2c_smbus_read_byte_data(client, | 1180 | pr_debug("w83793: Detection failed at check vendor id\n"); |
1181 | W83793_REG_VENDORID)) { | 1181 | return -ENODEV; |
1182 | pr_debug("w83793: Detection failed at check " | ||
1183 | "vendor id\n"); | ||
1184 | return -ENODEV; | ||
1185 | } | ||
1186 | |||
1187 | /* If Winbond chip, address of chip and W83793_REG_I2C_ADDR | ||
1188 | should match */ | ||
1189 | if ((bank & 0x07) == 0 | ||
1190 | && i2c_smbus_read_byte_data(client, W83793_REG_I2C_ADDR) != | ||
1191 | (address << 1)) { | ||
1192 | pr_debug("w83793: Detection failed at check " | ||
1193 | "i2c addr\n"); | ||
1194 | return -ENODEV; | ||
1195 | } | ||
1196 | |||
1197 | } | 1182 | } |
1198 | 1183 | ||
1199 | /* We have either had a force parameter, or we have already detected the | 1184 | /* If Winbond chip, address of chip and W83793_REG_I2C_ADDR |
1200 | Winbond. Determine the chip type now */ | 1185 | should match */ |
1201 | 1186 | if ((bank & 0x07) == 0 | |
1202 | if (kind <= 0) { | 1187 | && i2c_smbus_read_byte_data(client, W83793_REG_I2C_ADDR) != |
1203 | if (0x7b == i2c_smbus_read_byte_data(client, | 1188 | (address << 1)) { |
1204 | W83793_REG_CHIPID)) { | 1189 | pr_debug("w83793: Detection failed at check i2c addr\n"); |
1205 | kind = w83793; | 1190 | return -ENODEV; |
1206 | } else { | ||
1207 | if (kind == 0) | ||
1208 | dev_warn(&adapter->dev, "w83793: Ignoring " | ||
1209 | "'force' parameter for unknown chip " | ||
1210 | "at address 0x%02x\n", address); | ||
1211 | return -ENODEV; | ||
1212 | } | ||
1213 | } | 1191 | } |
1214 | 1192 | ||
1193 | /* Determine the chip type now */ | ||
1194 | chip_id = i2c_smbus_read_byte_data(client, W83793_REG_CHIPID); | ||
1195 | if (chip_id != 0x7b) | ||
1196 | return -ENODEV; | ||
1197 | |||
1215 | strlcpy(info->type, "w83793", I2C_NAME_SIZE); | 1198 | strlcpy(info->type, "w83793", I2C_NAME_SIZE); |
1216 | 1199 | ||
1217 | return 0; | 1200 | return 0; |
diff --git a/drivers/hwmon/w83l786ng.c b/drivers/hwmon/w83l786ng.c index badca769f350..27da7d2b15fb 100644 --- a/drivers/hwmon/w83l786ng.c +++ b/drivers/hwmon/w83l786ng.c | |||
@@ -590,53 +590,31 @@ w83l786ng_detect(struct i2c_client *client, int kind, | |||
590 | struct i2c_board_info *info) | 590 | struct i2c_board_info *info) |
591 | { | 591 | { |
592 | struct i2c_adapter *adapter = client->adapter; | 592 | struct i2c_adapter *adapter = client->adapter; |
593 | u16 man_id; | ||
594 | u8 chip_id; | ||
593 | 595 | ||
594 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 596 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
595 | return -ENODEV; | 597 | return -ENODEV; |
596 | } | 598 | } |
597 | 599 | ||
598 | /* | 600 | /* Detection */ |
599 | * Now we do the remaining detection. A negative kind means that | 601 | if ((w83l786ng_read_value(client, W83L786NG_REG_CONFIG) & 0x80)) { |
600 | * the driver was loaded with no force parameter (default), so we | 602 | dev_dbg(&adapter->dev, "W83L786NG detection failed at 0x%02x\n", |
601 | * must both detect and identify the chip (actually there is only | 603 | client->addr); |
602 | * one possible kind of chip for now, W83L786NG). A zero kind means | 604 | return -ENODEV; |
603 | * that the driver was loaded with the force parameter, the detection | ||
604 | * step shall be skipped. A positive kind means that the driver | ||
605 | * was loaded with the force parameter and a given kind of chip is | ||
606 | * requested, so both the detection and the identification steps | ||
607 | * are skipped. | ||
608 | */ | ||
609 | if (kind < 0) { /* detection */ | ||
610 | if (((w83l786ng_read_value(client, | ||
611 | W83L786NG_REG_CONFIG) & 0x80) != 0x00)) { | ||
612 | dev_dbg(&adapter->dev, | ||
613 | "W83L786NG detection failed at 0x%02x.\n", | ||
614 | client->addr); | ||
615 | return -ENODEV; | ||
616 | } | ||
617 | } | 605 | } |
618 | 606 | ||
619 | if (kind <= 0) { /* identification */ | 607 | /* Identification */ |
620 | u16 man_id; | 608 | man_id = (w83l786ng_read_value(client, W83L786NG_REG_MAN_ID1) << 8) + |
621 | u8 chip_id; | 609 | w83l786ng_read_value(client, W83L786NG_REG_MAN_ID2); |
622 | 610 | chip_id = w83l786ng_read_value(client, W83L786NG_REG_CHIP_ID); | |
623 | man_id = (w83l786ng_read_value(client, | ||
624 | W83L786NG_REG_MAN_ID1) << 8) + | ||
625 | w83l786ng_read_value(client, W83L786NG_REG_MAN_ID2); | ||
626 | chip_id = w83l786ng_read_value(client, W83L786NG_REG_CHIP_ID); | ||
627 | |||
628 | if (man_id == 0x5CA3) { /* Winbond */ | ||
629 | if (chip_id == 0x80) { /* W83L786NG */ | ||
630 | kind = w83l786ng; | ||
631 | } | ||
632 | } | ||
633 | 611 | ||
634 | if (kind <= 0) { /* identification failed */ | 612 | if (man_id != 0x5CA3 || /* Winbond */ |
635 | dev_info(&adapter->dev, | 613 | chip_id != 0x80) { /* W83L786NG */ |
636 | "Unsupported chip (man_id=0x%04X, " | 614 | dev_dbg(&adapter->dev, |
637 | "chip_id=0x%02X).\n", man_id, chip_id); | 615 | "Unsupported chip (man_id=0x%04X, chip_id=0x%02X)\n", |
638 | return -ENODEV; | 616 | man_id, chip_id); |
639 | } | 617 | return -ENODEV; |
640 | } | 618 | } |
641 | 619 | ||
642 | strlcpy(info->type, "w83l786ng", I2C_NAME_SIZE); | 620 | strlcpy(info->type, "w83l786ng", I2C_NAME_SIZE); |