diff options
author | Jean Delvare <khali@linux-fr.org> | 2009-12-09 14:35:53 -0500 |
---|---|---|
committer | Jean Delvare <khali@linux-fr.org> | 2009-12-09 14:35:53 -0500 |
commit | d42a2eb5ad9766fac96f27af93b1634e4ffde220 (patch) | |
tree | 38d0cab10aaf75aebcb41135fc59775175c0d074 /drivers/hwmon/lm85.c | |
parent | b57dc3940a70a2c2460b628567a3cc76efe725f2 (diff) |
hwmon: (lm85) Clean up detect function
As kind is now hard-coded to -1, there is room for code clean-ups.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon/lm85.c')
-rw-r--r-- | drivers/hwmon/lm85.c | 157 |
1 files changed, 65 insertions, 92 deletions
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c index 6c53d987de10..d56da2e74708 100644 --- a/drivers/hwmon/lm85.c +++ b/drivers/hwmon/lm85.c | |||
@@ -5,7 +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 | Copyright (C) 2007--2009 Jean Delvare <khali@linux-fr.org> |
9 | 9 | ||
10 | Chip details at <http://www.national.com/ds/LM/LM85.pdf> | 10 | Chip details at <http://www.national.com/ds/LM/LM85.pdf> |
11 | 11 | ||
@@ -1162,107 +1162,80 @@ static int lm85_detect(struct i2c_client *client, int kind, | |||
1162 | struct i2c_adapter *adapter = client->adapter; | 1162 | struct i2c_adapter *adapter = client->adapter; |
1163 | int address = client->addr; | 1163 | int address = client->addr; |
1164 | const char *type_name; | 1164 | const char *type_name; |
1165 | int company, verstep; | ||
1165 | 1166 | ||
1166 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 1167 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
1167 | /* We need to be able to do byte I/O */ | 1168 | /* We need to be able to do byte I/O */ |
1168 | return -ENODEV; | 1169 | return -ENODEV; |
1169 | } | 1170 | } |
1170 | 1171 | ||
1171 | /* If auto-detecting, determine the chip type */ | 1172 | /* Determine the chip type */ |
1172 | if (kind < 0) { | 1173 | company = lm85_read_value(client, LM85_REG_COMPANY); |
1173 | int company = lm85_read_value(client, LM85_REG_COMPANY); | 1174 | verstep = lm85_read_value(client, LM85_REG_VERSTEP); |
1174 | int verstep = lm85_read_value(client, LM85_REG_VERSTEP); | 1175 | |
1175 | 1176 | dev_dbg(&adapter->dev, "Detecting device at 0x%02x with " | |
1176 | dev_dbg(&adapter->dev, "Detecting device at 0x%02x with " | 1177 | "COMPANY: 0x%02x and VERSTEP: 0x%02x\n", |
1177 | "COMPANY: 0x%02x and VERSTEP: 0x%02x\n", | 1178 | address, company, verstep); |
1178 | address, company, verstep); | 1179 | |
1179 | 1180 | /* All supported chips have the version in common */ | |
1180 | /* All supported chips have the version in common */ | 1181 | if ((verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC && |
1181 | if ((verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC && | 1182 | (verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC2) { |
1182 | (verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC2) { | 1183 | dev_dbg(&adapter->dev, |
1183 | dev_dbg(&adapter->dev, "Autodetection failed: " | 1184 | "Autodetection failed: unsupported version\n"); |
1184 | "unsupported version\n"); | 1185 | return -ENODEV; |
1185 | return -ENODEV; | 1186 | } |
1186 | } | 1187 | type_name = "lm85"; |
1187 | kind = any_chip; | 1188 | |
1188 | 1189 | /* Now, refine the detection */ | |
1189 | /* Now, refine the detection */ | 1190 | if (company == LM85_COMPANY_NATIONAL) { |
1190 | if (company == LM85_COMPANY_NATIONAL) { | 1191 | switch (verstep) { |
1191 | switch (verstep) { | 1192 | case LM85_VERSTEP_LM85C: |
1192 | case LM85_VERSTEP_LM85C: | 1193 | type_name = "lm85c"; |
1193 | kind = lm85c; | 1194 | break; |
1194 | break; | 1195 | case LM85_VERSTEP_LM85B: |
1195 | case LM85_VERSTEP_LM85B: | 1196 | type_name = "lm85b"; |
1196 | kind = lm85b; | 1197 | break; |
1197 | break; | 1198 | case LM85_VERSTEP_LM96000_1: |
1198 | case LM85_VERSTEP_LM96000_1: | 1199 | case LM85_VERSTEP_LM96000_2: |
1199 | case LM85_VERSTEP_LM96000_2: | 1200 | /* Check for Winbond WPCD377I */ |
1200 | /* Check for Winbond WPCD377I */ | 1201 | if (lm85_is_fake(client)) { |
1201 | if (lm85_is_fake(client)) { | 1202 | dev_dbg(&adapter->dev, |
1202 | dev_dbg(&adapter->dev, | 1203 | "Found Winbond WPCD377I, ignoring\n"); |
1203 | "Found Winbond WPCD377I, " | 1204 | return -ENODEV; |
1204 | "ignoring\n"); | ||
1205 | return -ENODEV; | ||
1206 | } | ||
1207 | break; | ||
1208 | } | ||
1209 | } else if (company == LM85_COMPANY_ANALOG_DEV) { | ||
1210 | switch (verstep) { | ||
1211 | case LM85_VERSTEP_ADM1027: | ||
1212 | kind = adm1027; | ||
1213 | break; | ||
1214 | case LM85_VERSTEP_ADT7463: | ||
1215 | case LM85_VERSTEP_ADT7463C: | ||
1216 | kind = adt7463; | ||
1217 | break; | ||
1218 | case LM85_VERSTEP_ADT7468_1: | ||
1219 | case LM85_VERSTEP_ADT7468_2: | ||
1220 | kind = adt7468; | ||
1221 | break; | ||
1222 | } | ||
1223 | } else if (company == LM85_COMPANY_SMSC) { | ||
1224 | switch (verstep) { | ||
1225 | case LM85_VERSTEP_EMC6D100_A0: | ||
1226 | case LM85_VERSTEP_EMC6D100_A1: | ||
1227 | /* Note: we can't tell a '100 from a '101 */ | ||
1228 | kind = emc6d100; | ||
1229 | break; | ||
1230 | case LM85_VERSTEP_EMC6D102: | ||
1231 | kind = emc6d102; | ||
1232 | break; | ||
1233 | } | 1205 | } |
1234 | } else { | 1206 | break; |
1235 | dev_dbg(&adapter->dev, "Autodetection failed: " | 1207 | } |
1236 | "unknown vendor\n"); | 1208 | } else if (company == LM85_COMPANY_ANALOG_DEV) { |
1237 | return -ENODEV; | 1209 | switch (verstep) { |
1210 | case LM85_VERSTEP_ADM1027: | ||
1211 | type_name = "adm1027"; | ||
1212 | break; | ||
1213 | case LM85_VERSTEP_ADT7463: | ||
1214 | case LM85_VERSTEP_ADT7463C: | ||
1215 | type_name = "adt7463"; | ||
1216 | break; | ||
1217 | case LM85_VERSTEP_ADT7468_1: | ||
1218 | case LM85_VERSTEP_ADT7468_2: | ||
1219 | type_name = "adt7468"; | ||
1220 | break; | ||
1238 | } | 1221 | } |
1222 | } else if (company == LM85_COMPANY_SMSC) { | ||
1223 | switch (verstep) { | ||
1224 | case LM85_VERSTEP_EMC6D100_A0: | ||
1225 | case LM85_VERSTEP_EMC6D100_A1: | ||
1226 | /* Note: we can't tell a '100 from a '101 */ | ||
1227 | type_name = "emc6d100"; | ||
1228 | break; | ||
1229 | case LM85_VERSTEP_EMC6D102: | ||
1230 | type_name = "emc6d102"; | ||
1231 | break; | ||
1232 | } | ||
1233 | } else { | ||
1234 | dev_dbg(&adapter->dev, | ||
1235 | "Autodetection failed: unknown vendor\n"); | ||
1236 | return -ENODEV; | ||
1239 | } | 1237 | } |
1240 | 1238 | ||
1241 | switch (kind) { | ||
1242 | case lm85b: | ||
1243 | type_name = "lm85b"; | ||
1244 | break; | ||
1245 | case lm85c: | ||
1246 | type_name = "lm85c"; | ||
1247 | break; | ||
1248 | case adm1027: | ||
1249 | type_name = "adm1027"; | ||
1250 | break; | ||
1251 | case adt7463: | ||
1252 | type_name = "adt7463"; | ||
1253 | break; | ||
1254 | case adt7468: | ||
1255 | type_name = "adt7468"; | ||
1256 | break; | ||
1257 | case emc6d100: | ||
1258 | type_name = "emc6d100"; | ||
1259 | break; | ||
1260 | case emc6d102: | ||
1261 | type_name = "emc6d102"; | ||
1262 | break; | ||
1263 | default: | ||
1264 | type_name = "lm85"; | ||
1265 | } | ||
1266 | strlcpy(info->type, type_name, I2C_NAME_SIZE); | 1239 | strlcpy(info->type, type_name, I2C_NAME_SIZE); |
1267 | 1240 | ||
1268 | return 0; | 1241 | return 0; |