aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/adm1025.c
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@ingics.com>2014-07-03 09:49:27 -0400
committerGuenter Roeck <linux@roeck-us.net>2014-08-04 10:01:36 -0400
commitaab3f57a11723c75477f43d7a510c148f2269d16 (patch)
treea4ad8a38b8e02b5f1a7b047bf2763a4106b986f0 /drivers/hwmon/adm1025.c
parent851a7afa82c9cbbfa2f85151872a29db0a3f6cbf (diff)
hwmon: (adm1025) Convert to devm_hwmon_device_register_with_groups
Use ATTRIBUTE_GROUPS macro and devm_hwmon_device_register_with_groups() to simplify the code a bit. Signed-off-by: Axel Lin <axel.lin@ingics.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/adm1025.c')
-rw-r--r--drivers/hwmon/adm1025.c71
1 files changed, 23 insertions, 48 deletions
diff --git a/drivers/hwmon/adm1025.c b/drivers/hwmon/adm1025.c
index 0533c2c679f6..d3d0e8cf27b4 100644
--- a/drivers/hwmon/adm1025.c
+++ b/drivers/hwmon/adm1025.c
@@ -107,7 +107,8 @@ static const int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 };
107 */ 107 */
108 108
109struct adm1025_data { 109struct adm1025_data {
110 struct device *hwmon_dev; 110 struct i2c_client *client;
111 const struct attribute_group *groups[3];
111 struct mutex update_lock; 112 struct mutex update_lock;
112 char valid; /* zero until following fields are valid */ 113 char valid; /* zero until following fields are valid */
113 unsigned long last_updated; /* in jiffies */ 114 unsigned long last_updated; /* in jiffies */
@@ -125,8 +126,8 @@ struct adm1025_data {
125 126
126static struct adm1025_data *adm1025_update_device(struct device *dev) 127static struct adm1025_data *adm1025_update_device(struct device *dev)
127{ 128{
128 struct i2c_client *client = to_i2c_client(dev); 129 struct adm1025_data *data = dev_get_drvdata(dev);
129 struct adm1025_data *data = i2c_get_clientdata(client); 130 struct i2c_client *client = data->client;
130 131
131 mutex_lock(&data->update_lock); 132 mutex_lock(&data->update_lock);
132 133
@@ -227,8 +228,8 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
227 const char *buf, size_t count) 228 const char *buf, size_t count)
228{ 229{
229 int index = to_sensor_dev_attr(attr)->index; 230 int index = to_sensor_dev_attr(attr)->index;
230 struct i2c_client *client = to_i2c_client(dev); 231 struct adm1025_data *data = dev_get_drvdata(dev);
231 struct adm1025_data *data = i2c_get_clientdata(client); 232 struct i2c_client *client = data->client;
232 long val; 233 long val;
233 int err; 234 int err;
234 235
@@ -248,8 +249,8 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
248 const char *buf, size_t count) 249 const char *buf, size_t count)
249{ 250{
250 int index = to_sensor_dev_attr(attr)->index; 251 int index = to_sensor_dev_attr(attr)->index;
251 struct i2c_client *client = to_i2c_client(dev); 252 struct adm1025_data *data = dev_get_drvdata(dev);
252 struct adm1025_data *data = i2c_get_clientdata(client); 253 struct i2c_client *client = data->client;
253 long val; 254 long val;
254 int err; 255 int err;
255 256
@@ -283,8 +284,8 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
283 const char *buf, size_t count) 284 const char *buf, size_t count)
284{ 285{
285 int index = to_sensor_dev_attr(attr)->index; 286 int index = to_sensor_dev_attr(attr)->index;
286 struct i2c_client *client = to_i2c_client(dev); 287 struct adm1025_data *data = dev_get_drvdata(dev);
287 struct adm1025_data *data = i2c_get_clientdata(client); 288 struct i2c_client *client = data->client;
288 long val; 289 long val;
289 int err; 290 int err;
290 291
@@ -304,8 +305,8 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
304 const char *buf, size_t count) 305 const char *buf, size_t count)
305{ 306{
306 int index = to_sensor_dev_attr(attr)->index; 307 int index = to_sensor_dev_attr(attr)->index;
307 struct i2c_client *client = to_i2c_client(dev); 308 struct adm1025_data *data = dev_get_drvdata(dev);
308 struct adm1025_data *data = i2c_get_clientdata(client); 309 struct i2c_client *client = data->client;
309 long val; 310 long val;
310 int err; 311 int err;
311 312
@@ -525,57 +526,32 @@ static void adm1025_init_client(struct i2c_client *client)
525static int adm1025_probe(struct i2c_client *client, 526static int adm1025_probe(struct i2c_client *client,
526 const struct i2c_device_id *id) 527 const struct i2c_device_id *id)
527{ 528{
529 struct device *dev = &client->dev;
530 struct device *hwmon_dev;
528 struct adm1025_data *data; 531 struct adm1025_data *data;
529 int err;
530 u8 config; 532 u8 config;
531 533
532 data = devm_kzalloc(&client->dev, sizeof(struct adm1025_data), 534 data = devm_kzalloc(dev, sizeof(struct adm1025_data), GFP_KERNEL);
533 GFP_KERNEL);
534 if (!data) 535 if (!data)
535 return -ENOMEM; 536 return -ENOMEM;
536 537
537 i2c_set_clientdata(client, data); 538 i2c_set_clientdata(client, data);
539 data->client = client;
538 mutex_init(&data->update_lock); 540 mutex_init(&data->update_lock);
539 541
540 /* Initialize the ADM1025 chip */ 542 /* Initialize the ADM1025 chip */
541 adm1025_init_client(client); 543 adm1025_init_client(client);
542 544
543 /* Register sysfs hooks */ 545 /* sysfs hooks */
544 err = sysfs_create_group(&client->dev.kobj, &adm1025_group); 546 data->groups[0] = &adm1025_group;
545 if (err)
546 return err;
547
548 /* Pin 11 is either in4 (+12V) or VID4 */ 547 /* Pin 11 is either in4 (+12V) or VID4 */
549 config = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG); 548 config = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG);
550 if (!(config & 0x20)) { 549 if (!(config & 0x20))
551 err = sysfs_create_group(&client->dev.kobj, &adm1025_group_in4); 550 data->groups[1] = &adm1025_group_in4;
552 if (err)
553 goto exit_remove;
554 }
555
556 data->hwmon_dev = hwmon_device_register(&client->dev);
557 if (IS_ERR(data->hwmon_dev)) {
558 err = PTR_ERR(data->hwmon_dev);
559 goto exit_remove;
560 }
561
562 return 0;
563 551
564exit_remove: 552 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
565 sysfs_remove_group(&client->dev.kobj, &adm1025_group); 553 data, data->groups);
566 sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4); 554 return PTR_ERR_OR_ZERO(hwmon_dev);
567 return err;
568}
569
570static int adm1025_remove(struct i2c_client *client)
571{
572 struct adm1025_data *data = i2c_get_clientdata(client);
573
574 hwmon_device_unregister(data->hwmon_dev);
575 sysfs_remove_group(&client->dev.kobj, &adm1025_group);
576 sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4);
577
578 return 0;
579} 555}
580 556
581static const struct i2c_device_id adm1025_id[] = { 557static const struct i2c_device_id adm1025_id[] = {
@@ -591,7 +567,6 @@ static struct i2c_driver adm1025_driver = {
591 .name = "adm1025", 567 .name = "adm1025",
592 }, 568 },
593 .probe = adm1025_probe, 569 .probe = adm1025_probe,
594 .remove = adm1025_remove,
595 .id_table = adm1025_id, 570 .id_table = adm1025_id,
596 .detect = adm1025_detect, 571 .detect = adm1025_detect,
597 .address_list = normal_i2c, 572 .address_list = normal_i2c,