aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/lm85.c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2008-10-17 11:51:13 -0400
committerJean Delvare <khali@mahadeva.delvare>2008-10-17 11:51:13 -0400
commit69fc1feba2d5856ff74dedb6ae9d8c490210825c (patch)
tree11fd5e34315dd86ca23fbf2eb18af24f4794032f /drivers/hwmon/lm85.c
parentdbee356262bb1c84cfa585530e33e7003534052a (diff)
hwmon: (lm85) Rework the device detection
Rework the device detection to make it clearer and faster in the general case (when a known device is found.) Signed-off-by: Jean Delvare <khali@linux-fr.org> Acked-by: Herbert Poetzl <herbert@13thfloor.at>
Diffstat (limited to 'drivers/hwmon/lm85.c')
-rw-r--r--drivers/hwmon/lm85.c123
1 files changed, 50 insertions, 73 deletions
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
index 12d446f54f97..3594a02f281b 100644
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -1106,7 +1106,6 @@ static void lm85_init_client(struct i2c_client *client)
1106static int lm85_detect(struct i2c_adapter *adapter, int address, 1106static int lm85_detect(struct i2c_adapter *adapter, int address,
1107 int kind) 1107 int kind)
1108{ 1108{
1109 int company, verstep;
1110 struct i2c_client *client; 1109 struct i2c_client *client;
1111 struct lm85_data *data; 1110 struct lm85_data *data;
1112 int err = 0; 1111 int err = 0;
@@ -1117,10 +1116,6 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
1117 goto ERROR0; 1116 goto ERROR0;
1118 } 1117 }
1119 1118
1120 /* OK. For now, we presume we have a valid client. We now create the
1121 client structure, even though we cannot fill it completely yet.
1122 But it allows us to access lm85_{read,write}_value. */
1123
1124 if (!(data = kzalloc(sizeof(struct lm85_data), GFP_KERNEL))) { 1119 if (!(data = kzalloc(sizeof(struct lm85_data), GFP_KERNEL))) {
1125 err = -ENOMEM; 1120 err = -ENOMEM;
1126 goto ERROR0; 1121 goto ERROR0;
@@ -1132,75 +1127,57 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
1132 client->adapter = adapter; 1127 client->adapter = adapter;
1133 client->driver = &lm85_driver; 1128 client->driver = &lm85_driver;
1134 1129
1135 /* Now, we do the remaining detection. */ 1130 /* If auto-detecting, determine the chip type */
1136 1131 if (kind < 0) {
1137 company = lm85_read_value(client, LM85_REG_COMPANY); 1132 int company = lm85_read_value(client, LM85_REG_COMPANY);
1138 verstep = lm85_read_value(client, LM85_REG_VERSTEP); 1133 int verstep = lm85_read_value(client, LM85_REG_VERSTEP);
1139 1134
1140 dev_dbg(&adapter->dev, "Detecting device at %d,0x%02x with" 1135 dev_dbg(&adapter->dev, "Detecting device at 0x%02x with "
1141 " COMPANY: 0x%02x and VERSTEP: 0x%02x\n", 1136 "COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
1142 i2c_adapter_id(client->adapter), client->addr, 1137 address, company, verstep);
1143 company, verstep); 1138
1144 1139 /* All supported chips have the version in common */
1145 /* If auto-detecting, Determine the chip type. */ 1140 if ((verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC) {
1146 if (kind <= 0) { 1141 dev_dbg(&adapter->dev, "Autodetection failed: "
1147 dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x ...\n", 1142 "unsupported version\n");
1148 i2c_adapter_id(adapter), address); 1143 goto ERROR1;
1149 if (company == LM85_COMPANY_NATIONAL 1144 }
1150 && verstep == LM85_VERSTEP_LM85C) { 1145 kind = any_chip;
1151 kind = lm85c; 1146
1152 } else if (company == LM85_COMPANY_NATIONAL 1147 /* Now, refine the detection */
1153 && verstep == LM85_VERSTEP_LM85B) { 1148 if (company == LM85_COMPANY_NATIONAL) {
1154 kind = lm85b; 1149 switch (verstep) {
1155 } else if (company == LM85_COMPANY_NATIONAL 1150 case LM85_VERSTEP_LM85C:
1156 && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { 1151 kind = lm85c;
1157 dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x" 1152 break;
1158 " Defaulting to LM85.\n", verstep); 1153 case LM85_VERSTEP_LM85B:
1159 kind = any_chip; 1154 kind = lm85b;
1160 } else if (company == LM85_COMPANY_ANALOG_DEV 1155 break;
1161 && verstep == LM85_VERSTEP_ADM1027) { 1156 }
1162 kind = adm1027; 1157 } else if (company == LM85_COMPANY_ANALOG_DEV) {
1163 } else if (company == LM85_COMPANY_ANALOG_DEV 1158 switch (verstep) {
1164 && (verstep == LM85_VERSTEP_ADT7463 1159 case LM85_VERSTEP_ADM1027:
1165 || verstep == LM85_VERSTEP_ADT7463C)) { 1160 kind = adm1027;
1166 kind = adt7463; 1161 break;
1167 } else if (company == LM85_COMPANY_ANALOG_DEV 1162 case LM85_VERSTEP_ADT7463:
1168 && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { 1163 case LM85_VERSTEP_ADT7463C:
1169 dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x" 1164 kind = adt7463;
1170 " Defaulting to Generic LM85.\n", verstep); 1165 break;
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 } 1166 }
1203 err = 0; 1167 } else if (company == LM85_COMPANY_SMSC) {
1168 switch (verstep) {
1169 case LM85_VERSTEP_EMC6D100_A0:
1170 case LM85_VERSTEP_EMC6D100_A1:
1171 /* Note: we can't tell a '100 from a '101 */
1172 kind = emc6d100;
1173 break;
1174 case LM85_VERSTEP_EMC6D102:
1175 kind = emc6d102;
1176 break;
1177 }
1178 } else {
1179 dev_dbg(&adapter->dev, "Autodetection failed: "
1180 "unknown vendor\n");
1204 goto ERROR1; 1181 goto ERROR1;
1205 } 1182 }
1206 } 1183 }