summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@ingics.com>2014-07-03 10:01:48 -0400
committerGuenter Roeck <linux@roeck-us.net>2014-08-04 10:01:37 -0400
commit715f69bef14e4139ff1e19bbc69e0cd07de0f4e9 (patch)
tree35d23f6b1b0ea1adfac8fe5de6d2adad90d7c784
parent8280325288176694a3c22e2f10fdab6d8de5bd99 (diff)
hwmon: (adm9240) 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>
-rw-r--r--drivers/hwmon/adm9240.c74
1 files changed, 26 insertions, 48 deletions
diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c
index 8235ae4cbeb5..98114cef1e43 100644
--- a/drivers/hwmon/adm9240.c
+++ b/drivers/hwmon/adm9240.c
@@ -132,7 +132,7 @@ static inline unsigned int AOUT_FROM_REG(u8 reg)
132 132
133/* per client data */ 133/* per client data */
134struct adm9240_data { 134struct adm9240_data {
135 struct device *hwmon_dev; 135 struct i2c_client *client;
136 struct mutex update_lock; 136 struct mutex update_lock;
137 char valid; 137 char valid;
138 unsigned long last_updated_measure; 138 unsigned long last_updated_measure;
@@ -170,8 +170,8 @@ static void adm9240_write_fan_div(struct i2c_client *client, int nr,
170 170
171static struct adm9240_data *adm9240_update_device(struct device *dev) 171static struct adm9240_data *adm9240_update_device(struct device *dev)
172{ 172{
173 struct i2c_client *client = to_i2c_client(dev); 173 struct adm9240_data *data = dev_get_drvdata(dev);
174 struct adm9240_data *data = i2c_get_clientdata(client); 174 struct i2c_client *client = data->client;
175 int i; 175 int i;
176 176
177 mutex_lock(&data->update_lock); 177 mutex_lock(&data->update_lock);
@@ -278,8 +278,8 @@ static ssize_t set_max(struct device *dev, struct device_attribute *devattr,
278 const char *buf, size_t count) 278 const char *buf, size_t count)
279{ 279{
280 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 280 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
281 struct i2c_client *client = to_i2c_client(dev); 281 struct adm9240_data *data = dev_get_drvdata(dev);
282 struct adm9240_data *data = i2c_get_clientdata(client); 282 struct i2c_client *client = data->client;
283 long val; 283 long val;
284 int err; 284 int err;
285 285
@@ -334,8 +334,8 @@ static ssize_t set_in_min(struct device *dev,
334 const char *buf, size_t count) 334 const char *buf, size_t count)
335{ 335{
336 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 336 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
337 struct i2c_client *client = to_i2c_client(dev); 337 struct adm9240_data *data = dev_get_drvdata(dev);
338 struct adm9240_data *data = i2c_get_clientdata(client); 338 struct i2c_client *client = data->client;
339 unsigned long val; 339 unsigned long val;
340 int err; 340 int err;
341 341
@@ -356,8 +356,8 @@ static ssize_t set_in_max(struct device *dev,
356 const char *buf, size_t count) 356 const char *buf, size_t count)
357{ 357{
358 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 358 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
359 struct i2c_client *client = to_i2c_client(dev); 359 struct adm9240_data *data = dev_get_drvdata(dev);
360 struct adm9240_data *data = i2c_get_clientdata(client); 360 struct i2c_client *client = data->client;
361 unsigned long val; 361 unsigned long val;
362 int err; 362 int err;
363 363
@@ -431,8 +431,8 @@ static ssize_t set_fan_min(struct device *dev,
431 const char *buf, size_t count) 431 const char *buf, size_t count)
432{ 432{
433 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 433 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
434 struct i2c_client *client = to_i2c_client(dev); 434 struct adm9240_data *data = dev_get_drvdata(dev);
435 struct adm9240_data *data = i2c_get_clientdata(client); 435 struct i2c_client *client = data->client;
436 int nr = attr->index; 436 int nr = attr->index;
437 u8 new_div; 437 u8 new_div;
438 unsigned long val; 438 unsigned long val;
@@ -544,8 +544,8 @@ static ssize_t set_aout(struct device *dev,
544 struct device_attribute *attr, 544 struct device_attribute *attr,
545 const char *buf, size_t count) 545 const char *buf, size_t count)
546{ 546{
547 struct i2c_client *client = to_i2c_client(dev); 547 struct adm9240_data *data = dev_get_drvdata(dev);
548 struct adm9240_data *data = i2c_get_clientdata(client); 548 struct i2c_client *client = data->client;
549 long val; 549 long val;
550 int err; 550 int err;
551 551
@@ -565,8 +565,8 @@ static ssize_t chassis_clear(struct device *dev,
565 struct device_attribute *attr, 565 struct device_attribute *attr,
566 const char *buf, size_t count) 566 const char *buf, size_t count)
567{ 567{
568 struct i2c_client *client = to_i2c_client(dev); 568 struct adm9240_data *data = dev_get_drvdata(dev);
569 struct adm9240_data *data = i2c_get_clientdata(client); 569 struct i2c_client *client = data->client;
570 unsigned long val; 570 unsigned long val;
571 571
572 if (kstrtoul(buf, 10, &val) || val != 0) 572 if (kstrtoul(buf, 10, &val) || val != 0)
@@ -583,7 +583,7 @@ static ssize_t chassis_clear(struct device *dev,
583static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR, show_alarm, 583static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR, show_alarm,
584 chassis_clear, 12); 584 chassis_clear, 12);
585 585
586static struct attribute *adm9240_attributes[] = { 586static struct attribute *adm9240_attrs[] = {
587 &sensor_dev_attr_in0_input.dev_attr.attr, 587 &sensor_dev_attr_in0_input.dev_attr.attr,
588 &sensor_dev_attr_in0_min.dev_attr.attr, 588 &sensor_dev_attr_in0_min.dev_attr.attr,
589 &sensor_dev_attr_in0_max.dev_attr.attr, 589 &sensor_dev_attr_in0_max.dev_attr.attr,
@@ -627,9 +627,7 @@ static struct attribute *adm9240_attributes[] = {
627 NULL 627 NULL
628}; 628};
629 629
630static const struct attribute_group adm9240_group = { 630ATTRIBUTE_GROUPS(adm9240);
631 .attrs = adm9240_attributes,
632};
633 631
634 632
635/*** sensor chip detect and driver install ***/ 633/*** sensor chip detect and driver install ***/
@@ -724,44 +722,25 @@ static void adm9240_init_client(struct i2c_client *client)
724static int adm9240_probe(struct i2c_client *new_client, 722static int adm9240_probe(struct i2c_client *new_client,
725 const struct i2c_device_id *id) 723 const struct i2c_device_id *id)
726{ 724{
725 struct device *dev = &new_client->dev;
726 struct device *hwmon_dev;
727 struct adm9240_data *data; 727 struct adm9240_data *data;
728 int err;
729 728
730 data = devm_kzalloc(&new_client->dev, sizeof(*data), GFP_KERNEL); 729 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
731 if (!data) 730 if (!data)
732 return -ENOMEM; 731 return -ENOMEM;
733 732
734 i2c_set_clientdata(new_client, data); 733 i2c_set_clientdata(new_client, data);
734 data->client = new_client;
735 mutex_init(&data->update_lock); 735 mutex_init(&data->update_lock);
736 736
737 adm9240_init_client(new_client); 737 adm9240_init_client(new_client);
738 738
739 /* populate sysfs filesystem */ 739 hwmon_dev = devm_hwmon_device_register_with_groups(dev,
740 err = sysfs_create_group(&new_client->dev.kobj, &adm9240_group); 740 new_client->name,
741 if (err) 741 data,
742 return err; 742 adm9240_groups);
743 743 return PTR_ERR_OR_ZERO(hwmon_dev);
744 data->hwmon_dev = hwmon_device_register(&new_client->dev);
745 if (IS_ERR(data->hwmon_dev)) {
746 err = PTR_ERR(data->hwmon_dev);
747 goto exit_remove;
748 }
749
750 return 0;
751
752exit_remove:
753 sysfs_remove_group(&new_client->dev.kobj, &adm9240_group);
754 return err;
755}
756
757static int adm9240_remove(struct i2c_client *client)
758{
759 struct adm9240_data *data = i2c_get_clientdata(client);
760
761 hwmon_device_unregister(data->hwmon_dev);
762 sysfs_remove_group(&client->dev.kobj, &adm9240_group);
763
764 return 0;
765} 744}
766 745
767static const struct i2c_device_id adm9240_id[] = { 746static const struct i2c_device_id adm9240_id[] = {
@@ -778,7 +757,6 @@ static struct i2c_driver adm9240_driver = {
778 .name = "adm9240", 757 .name = "adm9240",
779 }, 758 },
780 .probe = adm9240_probe, 759 .probe = adm9240_probe,
781 .remove = adm9240_remove,
782 .id_table = adm9240_id, 760 .id_table = adm9240_id,
783 .detect = adm9240_detect, 761 .detect = adm9240_detect,
784 .address_list = normal_i2c, 762 .address_list = normal_i2c,