aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2014-02-15 20:50:48 -0500
committerGuenter Roeck <linux@roeck-us.net>2014-03-03 11:01:04 -0500
commit5230551a26f9f4ab41929b81bf4de96a37eb0ae5 (patch)
tree8b7d5e02cf4d2b18a64b9af2b9ad97f1121f9718 /drivers/hwmon
parentc5a706697f79b2aa5a2000f8024602320e37658f (diff)
hwmon: (max1668) Convert to use devm_hwmon_device_register_with_groups
Simplify code, reduce code size, and attach hwmon attributes to hwmon device. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Reviewed-by: Jean Delvare <jdelvare@suse.de>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/max1668.c67
1 files changed, 18 insertions, 49 deletions
diff --git a/drivers/hwmon/max1668.c b/drivers/hwmon/max1668.c
index bbbe340332b9..e3ed0a5b6d94 100644
--- a/drivers/hwmon/max1668.c
+++ b/drivers/hwmon/max1668.c
@@ -66,7 +66,8 @@ MODULE_PARM_DESC(read_only, "Don't set any values, read only mode");
66enum chips { max1668, max1805, max1989 }; 66enum chips { max1668, max1805, max1989 };
67 67
68struct max1668_data { 68struct max1668_data {
69 struct device *hwmon_dev; 69 struct i2c_client *client;
70 const struct attribute_group *groups[3];
70 enum chips type; 71 enum chips type;
71 72
72 struct mutex update_lock; 73 struct mutex update_lock;
@@ -82,8 +83,8 @@ struct max1668_data {
82 83
83static struct max1668_data *max1668_update_device(struct device *dev) 84static struct max1668_data *max1668_update_device(struct device *dev)
84{ 85{
85 struct i2c_client *client = to_i2c_client(dev); 86 struct max1668_data *data = dev_get_drvdata(dev);
86 struct max1668_data *data = i2c_get_clientdata(client); 87 struct i2c_client *client = data->client;
87 struct max1668_data *ret = data; 88 struct max1668_data *ret = data;
88 s32 val; 89 s32 val;
89 int i; 90 int i;
@@ -205,8 +206,8 @@ static ssize_t set_temp_max(struct device *dev,
205 const char *buf, size_t count) 206 const char *buf, size_t count)
206{ 207{
207 int index = to_sensor_dev_attr(devattr)->index; 208 int index = to_sensor_dev_attr(devattr)->index;
208 struct i2c_client *client = to_i2c_client(dev); 209 struct max1668_data *data = dev_get_drvdata(dev);
209 struct max1668_data *data = i2c_get_clientdata(client); 210 struct i2c_client *client = data->client;
210 long temp; 211 long temp;
211 int ret; 212 int ret;
212 213
@@ -231,8 +232,8 @@ static ssize_t set_temp_min(struct device *dev,
231 const char *buf, size_t count) 232 const char *buf, size_t count)
232{ 233{
233 int index = to_sensor_dev_attr(devattr)->index; 234 int index = to_sensor_dev_attr(devattr)->index;
234 struct i2c_client *client = to_i2c_client(dev); 235 struct max1668_data *data = dev_get_drvdata(dev);
235 struct max1668_data *data = i2c_get_clientdata(client); 236 struct i2c_client *client = data->client;
236 long temp; 237 long temp;
237 int ret; 238 int ret;
238 239
@@ -407,60 +408,29 @@ static int max1668_probe(struct i2c_client *client,
407 const struct i2c_device_id *id) 408 const struct i2c_device_id *id)
408{ 409{
409 struct i2c_adapter *adapter = client->adapter; 410 struct i2c_adapter *adapter = client->adapter;
411 struct device *dev = &client->dev;
412 struct device *hwmon_dev;
410 struct max1668_data *data; 413 struct max1668_data *data;
411 int err;
412 414
413 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 415 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
414 return -ENODEV; 416 return -ENODEV;
415 417
416 data = devm_kzalloc(&client->dev, sizeof(struct max1668_data), 418 data = devm_kzalloc(dev, sizeof(struct max1668_data), GFP_KERNEL);
417 GFP_KERNEL);
418 if (!data) 419 if (!data)
419 return -ENOMEM; 420 return -ENOMEM;
420 421
421 i2c_set_clientdata(client, data); 422 data->client = client;
422 data->type = id->driver_data; 423 data->type = id->driver_data;
423 mutex_init(&data->update_lock); 424 mutex_init(&data->update_lock);
424 425
425 /* Register sysfs hooks */ 426 /* sysfs hooks */
426 err = sysfs_create_group(&client->dev.kobj, &max1668_group_common); 427 data->groups[0] = &max1668_group_common;
427 if (err)
428 return err;
429
430 if (data->type == max1668 || data->type == max1989) {
431 err = sysfs_create_group(&client->dev.kobj,
432 &max1668_group_unique);
433 if (err)
434 goto error_sysrem0;
435 }
436
437 data->hwmon_dev = hwmon_device_register(&client->dev);
438 if (IS_ERR(data->hwmon_dev)) {
439 err = PTR_ERR(data->hwmon_dev);
440 goto error_sysrem1;
441 }
442
443 return 0;
444
445error_sysrem1:
446 if (data->type == max1668 || data->type == max1989)
447 sysfs_remove_group(&client->dev.kobj, &max1668_group_unique);
448error_sysrem0:
449 sysfs_remove_group(&client->dev.kobj, &max1668_group_common);
450 return err;
451}
452
453static int max1668_remove(struct i2c_client *client)
454{
455 struct max1668_data *data = i2c_get_clientdata(client);
456
457 hwmon_device_unregister(data->hwmon_dev);
458 if (data->type == max1668 || data->type == max1989) 428 if (data->type == max1668 || data->type == max1989)
459 sysfs_remove_group(&client->dev.kobj, &max1668_group_unique); 429 data->groups[1] = &max1668_group_unique;
460 430
461 sysfs_remove_group(&client->dev.kobj, &max1668_group_common); 431 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
462 432 data, data->groups);
463 return 0; 433 return PTR_ERR_OR_ZERO(hwmon_dev);
464} 434}
465 435
466static const struct i2c_device_id max1668_id[] = { 436static const struct i2c_device_id max1668_id[] = {
@@ -478,7 +448,6 @@ static struct i2c_driver max1668_driver = {
478 .name = "max1668", 448 .name = "max1668",
479 }, 449 },
480 .probe = max1668_probe, 450 .probe = max1668_probe,
481 .remove = max1668_remove,
482 .id_table = max1668_id, 451 .id_table = max1668_id,
483 .detect = max1668_detect, 452 .detect = max1668_detect,
484 .address_list = max1668_addr_list, 453 .address_list = max1668_addr_list,