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 /drivers/hwmon/asb100.c | |
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>
Diffstat (limited to 'drivers/hwmon/asb100.c')
-rw-r--r-- | drivers/hwmon/asb100.c | 55 |
1 files changed, 18 insertions, 37 deletions
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 | ||