aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/lm85.c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2008-10-17 11:51:14 -0400
committerJean Delvare <khali@mahadeva.delvare>2008-10-17 11:51:14 -0400
commit67712d01929295112b55fedd0b3c13f7d5c34f98 (patch)
tree8ed924c2e0451c2c531ca0a0d1e27ab966f1bec8 /drivers/hwmon/lm85.c
parent8a0795d9b8ce2247f9b34da81f8a229702c90f2d (diff)
hwmon: (lm85) Convert to a new-style i2c driver
The new-style lm85 driver implements the optional detect() callback to cover the use cases of the legacy driver. 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.c121
1 files changed, 64 insertions, 57 deletions
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
index 3a84dc863df0..4ee9388df983 100644
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -289,7 +289,6 @@ struct lm85_autofan {
289/* For each registered chip, we need to keep some data in memory. 289/* For each registered chip, we need to keep some data in memory.
290 The structure is dynamically allocated. */ 290 The structure is dynamically allocated. */
291struct lm85_data { 291struct lm85_data {
292 struct i2c_client client;
293 struct device *hwmon_dev; 292 struct device *hwmon_dev;
294 const int *freq_map; 293 const int *freq_map;
295 enum chips type; 294 enum chips type;
@@ -318,22 +317,40 @@ struct lm85_data {
318 struct lm85_zone zone[3]; 317 struct lm85_zone zone[3];
319}; 318};
320 319
321static int lm85_attach_adapter(struct i2c_adapter *adapter); 320static int lm85_detect(struct i2c_client *client, int kind,
322static int lm85_detect(struct i2c_adapter *adapter, int address, 321 struct i2c_board_info *info);
323 int kind); 322static int lm85_probe(struct i2c_client *client,
324static int lm85_detach_client(struct i2c_client *client); 323 const struct i2c_device_id *id);
324static int lm85_remove(struct i2c_client *client);
325 325
326static int lm85_read_value(struct i2c_client *client, u8 reg); 326static int lm85_read_value(struct i2c_client *client, u8 reg);
327static void lm85_write_value(struct i2c_client *client, u8 reg, int value); 327static void lm85_write_value(struct i2c_client *client, u8 reg, int value);
328static struct lm85_data *lm85_update_device(struct device *dev); 328static struct lm85_data *lm85_update_device(struct device *dev);
329 329
330 330
331static const struct i2c_device_id lm85_id[] = {
332 { "adm1027", adm1027 },
333 { "adt7463", adt7463 },
334 { "lm85", any_chip },
335 { "lm85b", lm85b },
336 { "lm85c", lm85c },
337 { "emc6d100", emc6d100 },
338 { "emc6d101", emc6d100 },
339 { "emc6d102", emc6d102 },
340 { }
341};
342MODULE_DEVICE_TABLE(i2c, lm85_id);
343
331static struct i2c_driver lm85_driver = { 344static struct i2c_driver lm85_driver = {
345 .class = I2C_CLASS_HWMON,
332 .driver = { 346 .driver = {
333 .name = "lm85", 347 .name = "lm85",
334 }, 348 },
335 .attach_adapter = lm85_attach_adapter, 349 .probe = lm85_probe,
336 .detach_client = lm85_detach_client, 350 .remove = lm85_remove,
351 .id_table = lm85_id,
352 .detect = lm85_detect,
353 .address_data = &addr_data,
337}; 354};
338 355
339 356
@@ -965,13 +982,6 @@ temp_auto(1);
965temp_auto(2); 982temp_auto(2);
966temp_auto(3); 983temp_auto(3);
967 984
968static int lm85_attach_adapter(struct i2c_adapter *adapter)
969{
970 if (!(adapter->class & I2C_CLASS_HWMON))
971 return 0;
972 return i2c_probe(adapter, &addr_data, lm85_detect);
973}
974
975static struct attribute *lm85_attributes[] = { 985static struct attribute *lm85_attributes[] = {
976 &sensor_dev_attr_fan1_input.dev_attr.attr, 986 &sensor_dev_attr_fan1_input.dev_attr.attr,
977 &sensor_dev_attr_fan2_input.dev_attr.attr, 987 &sensor_dev_attr_fan2_input.dev_attr.attr,
@@ -1111,30 +1121,19 @@ static void lm85_init_client(struct i2c_client *client)
1111 dev_warn(&client->dev, "Device is not ready\n"); 1121 dev_warn(&client->dev, "Device is not ready\n");
1112} 1122}
1113 1123
1114static int lm85_detect(struct i2c_adapter *adapter, int address, 1124/* Return 0 if detection is successful, -ENODEV otherwise */
1115 int kind) 1125static int lm85_detect(struct i2c_client *client, int kind,
1126 struct i2c_board_info *info)
1116{ 1127{
1117 struct i2c_client *client; 1128 struct i2c_adapter *adapter = client->adapter;
1118 struct lm85_data *data; 1129 int address = client->addr;
1119 int err = 0;
1120 const char *type_name; 1130 const char *type_name;
1121 1131
1122 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 1132 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
1123 /* We need to be able to do byte I/O */ 1133 /* We need to be able to do byte I/O */
1124 goto ERROR0; 1134 return -ENODEV;
1125 } 1135 }
1126 1136
1127 if (!(data = kzalloc(sizeof(struct lm85_data), GFP_KERNEL))) {
1128 err = -ENOMEM;
1129 goto ERROR0;
1130 }
1131
1132 client = &data->client;
1133 i2c_set_clientdata(client, data);
1134 client->addr = address;
1135 client->adapter = adapter;
1136 client->driver = &lm85_driver;
1137
1138 /* If auto-detecting, determine the chip type */ 1137 /* If auto-detecting, determine the chip type */
1139 if (kind < 0) { 1138 if (kind < 0) {
1140 int company = lm85_read_value(client, LM85_REG_COMPANY); 1139 int company = lm85_read_value(client, LM85_REG_COMPANY);
@@ -1148,7 +1147,7 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
1148 if ((verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC) { 1147 if ((verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC) {
1149 dev_dbg(&adapter->dev, "Autodetection failed: " 1148 dev_dbg(&adapter->dev, "Autodetection failed: "
1150 "unsupported version\n"); 1149 "unsupported version\n");
1151 goto ERROR1; 1150 return -ENODEV;
1152 } 1151 }
1153 kind = any_chip; 1152 kind = any_chip;
1154 1153
@@ -1186,50 +1185,62 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
1186 } else { 1185 } else {
1187 dev_dbg(&adapter->dev, "Autodetection failed: " 1186 dev_dbg(&adapter->dev, "Autodetection failed: "
1188 "unknown vendor\n"); 1187 "unknown vendor\n");
1189 goto ERROR1; 1188 return -ENODEV;
1190 } 1189 }
1191 } 1190 }
1192 1191
1193 /* Fill in the chip specific driver values */
1194 switch (kind) { 1192 switch (kind) {
1195 case lm85b: 1193 case lm85b:
1196 type_name = "lm85b"; 1194 type_name = "lm85b";
1197 data->freq_map = lm85_freq_map;
1198 break; 1195 break;
1199 case lm85c: 1196 case lm85c:
1200 type_name = "lm85c"; 1197 type_name = "lm85c";
1201 data->freq_map = lm85_freq_map;
1202 break; 1198 break;
1203 case adm1027: 1199 case adm1027:
1204 type_name = "adm1027"; 1200 type_name = "adm1027";
1205 data->freq_map = adm1027_freq_map;
1206 break; 1201 break;
1207 case adt7463: 1202 case adt7463:
1208 type_name = "adt7463"; 1203 type_name = "adt7463";
1209 data->freq_map = adm1027_freq_map;
1210 break; 1204 break;
1211 case emc6d100: 1205 case emc6d100:
1212 type_name = "emc6d100"; 1206 type_name = "emc6d100";
1213 data->freq_map = adm1027_freq_map;
1214 break; 1207 break;
1215 case emc6d102: 1208 case emc6d102:
1216 type_name = "emc6d102"; 1209 type_name = "emc6d102";
1217 data->freq_map = adm1027_freq_map;
1218 break; 1210 break;
1219 default: 1211 default:
1220 type_name = "lm85"; 1212 type_name = "lm85";
1221 data->freq_map = lm85_freq_map;
1222 } 1213 }
1223 strlcpy(client->name, type_name, I2C_NAME_SIZE); 1214 strlcpy(info->type, type_name, I2C_NAME_SIZE);
1215
1216 return 0;
1217}
1224 1218
1225 /* Fill in the remaining client fields */ 1219static int lm85_probe(struct i2c_client *client,
1226 data->type = kind; 1220 const struct i2c_device_id *id)
1221{
1222 struct lm85_data *data;
1223 int err;
1224
1225 data = kzalloc(sizeof(struct lm85_data), GFP_KERNEL);
1226 if (!data)
1227 return -ENOMEM;
1228
1229 i2c_set_clientdata(client, data);
1230 data->type = id->driver_data;
1227 mutex_init(&data->update_lock); 1231 mutex_init(&data->update_lock);
1228 1232
1229 /* Tell the I2C layer a new client has arrived */ 1233 /* Fill in the chip specific driver values */
1230 err = i2c_attach_client(client); 1234 switch (data->type) {
1231 if (err) 1235 case adm1027:
1232 goto ERROR1; 1236 case adt7463:
1237 case emc6d100:
1238 case emc6d102:
1239 data->freq_map = adm1027_freq_map;
1240 break;
1241 default:
1242 data->freq_map = lm85_freq_map;
1243 }
1233 1244
1234 /* Set the VRM version */ 1245 /* Set the VRM version */
1235 data->vrm = vid_which_vrm(); 1246 data->vrm = vid_which_vrm();
@@ -1240,18 +1251,18 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
1240 /* Register sysfs hooks */ 1251 /* Register sysfs hooks */
1241 err = sysfs_create_group(&client->dev.kobj, &lm85_group); 1252 err = sysfs_create_group(&client->dev.kobj, &lm85_group);
1242 if (err) 1253 if (err)
1243 goto ERROR2; 1254 goto ERROR1;
1244 1255
1245 /* The ADT7463 has an optional VRM 10 mode where pin 21 is used 1256 /* The ADT7463 has an optional VRM 10 mode where pin 21 is used
1246 as a sixth digital VID input rather than an analog input. */ 1257 as a sixth digital VID input rather than an analog input. */
1247 data->vid = lm85_read_value(client, LM85_REG_VID); 1258 data->vid = lm85_read_value(client, LM85_REG_VID);
1248 if (!(kind == adt7463 && (data->vid & 0x80))) 1259 if (!(data->type == adt7463 && (data->vid & 0x80)))
1249 if ((err = sysfs_create_group(&client->dev.kobj, 1260 if ((err = sysfs_create_group(&client->dev.kobj,
1250 &lm85_group_in4))) 1261 &lm85_group_in4)))
1251 goto ERROR3; 1262 goto ERROR3;
1252 1263
1253 /* The EMC6D100 has 3 additional voltage inputs */ 1264 /* The EMC6D100 has 3 additional voltage inputs */
1254 if (kind == emc6d100) 1265 if (data->type == emc6d100)
1255 if ((err = sysfs_create_group(&client->dev.kobj, 1266 if ((err = sysfs_create_group(&client->dev.kobj,
1256 &lm85_group_in567))) 1267 &lm85_group_in567)))
1257 goto ERROR3; 1268 goto ERROR3;
@@ -1268,17 +1279,14 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
1268 ERROR3: 1279 ERROR3:
1269 sysfs_remove_group(&client->dev.kobj, &lm85_group); 1280 sysfs_remove_group(&client->dev.kobj, &lm85_group);
1270 sysfs_remove_group(&client->dev.kobj, &lm85_group_in4); 1281 sysfs_remove_group(&client->dev.kobj, &lm85_group_in4);
1271 if (kind == emc6d100) 1282 if (data->type == emc6d100)
1272 sysfs_remove_group(&client->dev.kobj, &lm85_group_in567); 1283 sysfs_remove_group(&client->dev.kobj, &lm85_group_in567);
1273 ERROR2:
1274 i2c_detach_client(client);
1275 ERROR1: 1284 ERROR1:
1276 kfree(data); 1285 kfree(data);
1277 ERROR0:
1278 return err; 1286 return err;
1279} 1287}
1280 1288
1281static int lm85_detach_client(struct i2c_client *client) 1289static int lm85_remove(struct i2c_client *client)
1282{ 1290{
1283 struct lm85_data *data = i2c_get_clientdata(client); 1291 struct lm85_data *data = i2c_get_clientdata(client);
1284 hwmon_device_unregister(data->hwmon_dev); 1292 hwmon_device_unregister(data->hwmon_dev);
@@ -1286,7 +1294,6 @@ static int lm85_detach_client(struct i2c_client *client)
1286 sysfs_remove_group(&client->dev.kobj, &lm85_group_in4); 1294 sysfs_remove_group(&client->dev.kobj, &lm85_group_in4);
1287 if (data->type == emc6d100) 1295 if (data->type == emc6d100)
1288 sysfs_remove_group(&client->dev.kobj, &lm85_group_in567); 1296 sysfs_remove_group(&client->dev.kobj, &lm85_group_in567);
1289 i2c_detach_client(client);
1290 kfree(data); 1297 kfree(data);
1291 return 0; 1298 return 0;
1292} 1299}