aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@ingics.com>2014-06-24 21:39:51 -0400
committerGuenter Roeck <linux@roeck-us.net>2014-08-04 10:01:34 -0400
commit202e4851f8aa6bad39c7799dac93c6951d064c87 (patch)
treedd42cfc870243260dafa5b7c3bc1511ddf0d612f
parentbab711ae8c7ad40f080dc74cc1c664cfe56ceff3 (diff)
hwmon: (w83l786ng) 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> Acked-by: Kevin Lo <kevlo@kevlo.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r--drivers/hwmon/w83l786ng.c86
1 files changed, 29 insertions, 57 deletions
diff --git a/drivers/hwmon/w83l786ng.c b/drivers/hwmon/w83l786ng.c
index 6caf33a5508b..330299613d38 100644
--- a/drivers/hwmon/w83l786ng.c
+++ b/drivers/hwmon/w83l786ng.c
@@ -124,7 +124,7 @@ DIV_TO_REG(long val)
124} 124}
125 125
126struct w83l786ng_data { 126struct w83l786ng_data {
127 struct device *hwmon_dev; 127 struct i2c_client *client;
128 struct mutex update_lock; 128 struct mutex update_lock;
129 char valid; /* !=0 if following fields are valid */ 129 char valid; /* !=0 if following fields are valid */
130 unsigned long last_updated; /* In jiffies */ 130 unsigned long last_updated; /* In jiffies */
@@ -162,8 +162,8 @@ w83l786ng_write_value(struct i2c_client *client, u8 reg, u8 value)
162 162
163static struct w83l786ng_data *w83l786ng_update_device(struct device *dev) 163static struct w83l786ng_data *w83l786ng_update_device(struct device *dev)
164{ 164{
165 struct i2c_client *client = to_i2c_client(dev); 165 struct w83l786ng_data *data = dev_get_drvdata(dev);
166 struct w83l786ng_data *data = i2c_get_clientdata(client); 166 struct i2c_client *client = data->client;
167 int i, j; 167 int i, j;
168 u8 reg_tmp, pwmcfg; 168 u8 reg_tmp, pwmcfg;
169 169
@@ -252,8 +252,8 @@ store_in_##reg(struct device *dev, struct device_attribute *attr, \
252 const char *buf, size_t count) \ 252 const char *buf, size_t count) \
253{ \ 253{ \
254 int nr = to_sensor_dev_attr(attr)->index; \ 254 int nr = to_sensor_dev_attr(attr)->index; \
255 struct i2c_client *client = to_i2c_client(dev); \ 255 struct w83l786ng_data *data = dev_get_drvdata(dev); \
256 struct w83l786ng_data *data = i2c_get_clientdata(client); \ 256 struct i2c_client *client = data->client; \
257 unsigned long val; \ 257 unsigned long val; \
258 int err = kstrtoul(buf, 10, &val); \ 258 int err = kstrtoul(buf, 10, &val); \
259 if (err) \ 259 if (err) \
@@ -305,8 +305,8 @@ store_fan_min(struct device *dev, struct device_attribute *attr,
305 const char *buf, size_t count) 305 const char *buf, size_t count)
306{ 306{
307 int nr = to_sensor_dev_attr(attr)->index; 307 int nr = to_sensor_dev_attr(attr)->index;
308 struct i2c_client *client = to_i2c_client(dev); 308 struct w83l786ng_data *data = dev_get_drvdata(dev);
309 struct w83l786ng_data *data = i2c_get_clientdata(client); 309 struct i2c_client *client = data->client;
310 unsigned long val; 310 unsigned long val;
311 int err; 311 int err;
312 312
@@ -343,8 +343,8 @@ store_fan_div(struct device *dev, struct device_attribute *attr,
343 const char *buf, size_t count) 343 const char *buf, size_t count)
344{ 344{
345 int nr = to_sensor_dev_attr(attr)->index; 345 int nr = to_sensor_dev_attr(attr)->index;
346 struct i2c_client *client = to_i2c_client(dev); 346 struct w83l786ng_data *data = dev_get_drvdata(dev);
347 struct w83l786ng_data *data = i2c_get_clientdata(client); 347 struct i2c_client *client = data->client;
348 348
349 unsigned long min; 349 unsigned long min;
350 u8 tmp_fan_div; 350 u8 tmp_fan_div;
@@ -434,8 +434,8 @@ store_temp(struct device *dev, struct device_attribute *attr,
434 to_sensor_dev_attr_2(attr); 434 to_sensor_dev_attr_2(attr);
435 int nr = sensor_attr->nr; 435 int nr = sensor_attr->nr;
436 int index = sensor_attr->index; 436 int index = sensor_attr->index;
437 struct i2c_client *client = to_i2c_client(dev); 437 struct w83l786ng_data *data = dev_get_drvdata(dev);
438 struct w83l786ng_data *data = i2c_get_clientdata(client); 438 struct i2c_client *client = data->client;
439 long val; 439 long val;
440 int err; 440 int err;
441 441
@@ -489,8 +489,8 @@ store_pwm_mode(struct device *dev, struct device_attribute *attr,
489 const char *buf, size_t count) 489 const char *buf, size_t count)
490{ 490{
491 int nr = to_sensor_dev_attr(attr)->index; 491 int nr = to_sensor_dev_attr(attr)->index;
492 struct i2c_client *client = to_i2c_client(dev); 492 struct w83l786ng_data *data = dev_get_drvdata(dev);
493 struct w83l786ng_data *data = i2c_get_clientdata(client); 493 struct i2c_client *client = data->client;
494 u8 reg; 494 u8 reg;
495 unsigned long val; 495 unsigned long val;
496 int err; 496 int err;
@@ -517,8 +517,8 @@ store_pwm(struct device *dev, struct device_attribute *attr,
517 const char *buf, size_t count) 517 const char *buf, size_t count)
518{ 518{
519 int nr = to_sensor_dev_attr(attr)->index; 519 int nr = to_sensor_dev_attr(attr)->index;
520 struct i2c_client *client = to_i2c_client(dev); 520 struct w83l786ng_data *data = dev_get_drvdata(dev);
521 struct w83l786ng_data *data = i2c_get_clientdata(client); 521 struct i2c_client *client = data->client;
522 unsigned long val; 522 unsigned long val;
523 int err; 523 int err;
524 524
@@ -541,8 +541,8 @@ store_pwm_enable(struct device *dev, struct device_attribute *attr,
541 const char *buf, size_t count) 541 const char *buf, size_t count)
542{ 542{
543 int nr = to_sensor_dev_attr(attr)->index; 543 int nr = to_sensor_dev_attr(attr)->index;
544 struct i2c_client *client = to_i2c_client(dev); 544 struct w83l786ng_data *data = dev_get_drvdata(dev);
545 struct w83l786ng_data *data = i2c_get_clientdata(client); 545 struct i2c_client *client = data->client;
546 u8 reg; 546 u8 reg;
547 unsigned long val; 547 unsigned long val;
548 int err; 548 int err;
@@ -597,8 +597,8 @@ store_tolerance(struct device *dev, struct device_attribute *attr,
597 const char *buf, size_t count) 597 const char *buf, size_t count)
598{ 598{
599 int nr = to_sensor_dev_attr(attr)->index; 599 int nr = to_sensor_dev_attr(attr)->index;
600 struct i2c_client *client = to_i2c_client(dev); 600 struct w83l786ng_data *data = dev_get_drvdata(dev);
601 struct w83l786ng_data *data = i2c_get_clientdata(client); 601 struct i2c_client *client = data->client;
602 u8 tol_tmp, tol_mask; 602 u8 tol_tmp, tol_mask;
603 unsigned long val; 603 unsigned long val;
604 int err; 604 int err;
@@ -653,7 +653,7 @@ static struct sensor_device_attribute sda_tolerance[] = {
653#define TOLERANCE_UNIT_ATTRS(X) \ 653#define TOLERANCE_UNIT_ATTRS(X) \
654 &sda_tolerance[X].dev_attr.attr 654 &sda_tolerance[X].dev_attr.attr
655 655
656static struct attribute *w83l786ng_attributes[] = { 656static struct attribute *w83l786ng_attrs[] = {
657 IN_UNIT_ATTRS(0), 657 IN_UNIT_ATTRS(0),
658 IN_UNIT_ATTRS(1), 658 IN_UNIT_ATTRS(1),
659 IN_UNIT_ATTRS(2), 659 IN_UNIT_ATTRS(2),
@@ -668,9 +668,7 @@ static struct attribute *w83l786ng_attributes[] = {
668 NULL 668 NULL
669}; 669};
670 670
671static const struct attribute_group w83l786ng_group = { 671ATTRIBUTE_GROUPS(w83l786ng);
672 .attrs = w83l786ng_attributes,
673};
674 672
675static int 673static int
676w83l786ng_detect(struct i2c_client *client, struct i2c_board_info *info) 674w83l786ng_detect(struct i2c_client *client, struct i2c_board_info *info)
@@ -725,15 +723,15 @@ w83l786ng_probe(struct i2c_client *client, const struct i2c_device_id *id)
725{ 723{
726 struct device *dev = &client->dev; 724 struct device *dev = &client->dev;
727 struct w83l786ng_data *data; 725 struct w83l786ng_data *data;
728 int i, err = 0; 726 struct device *hwmon_dev;
727 int i;
729 u8 reg_tmp; 728 u8 reg_tmp;
730 729
731 data = devm_kzalloc(&client->dev, sizeof(struct w83l786ng_data), 730 data = devm_kzalloc(dev, sizeof(struct w83l786ng_data), GFP_KERNEL);
732 GFP_KERNEL);
733 if (!data) 731 if (!data)
734 return -ENOMEM; 732 return -ENOMEM;
735 733
736 i2c_set_clientdata(client, data); 734 data->client = client;
737 mutex_init(&data->update_lock); 735 mutex_init(&data->update_lock);
738 736
739 /* Initialize the chip */ 737 /* Initialize the chip */
@@ -750,35 +748,10 @@ w83l786ng_probe(struct i2c_client *client, const struct i2c_device_id *id)
750 data->fan_div[0] = reg_tmp & 0x07; 748 data->fan_div[0] = reg_tmp & 0x07;
751 data->fan_div[1] = (reg_tmp >> 4) & 0x07; 749 data->fan_div[1] = (reg_tmp >> 4) & 0x07;
752 750
753 /* Register sysfs hooks */ 751 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
754 err = sysfs_create_group(&client->dev.kobj, &w83l786ng_group); 752 data,
755 if (err) 753 w83l786ng_groups);
756 goto exit_remove; 754 return PTR_ERR_OR_ZERO(hwmon_dev);
757
758 data->hwmon_dev = hwmon_device_register(dev);
759 if (IS_ERR(data->hwmon_dev)) {
760 err = PTR_ERR(data->hwmon_dev);
761 goto exit_remove;
762 }
763
764 return 0;
765
766 /* Unregister sysfs hooks */
767
768exit_remove:
769 sysfs_remove_group(&client->dev.kobj, &w83l786ng_group);
770 return err;
771}
772
773static int
774w83l786ng_remove(struct i2c_client *client)
775{
776 struct w83l786ng_data *data = i2c_get_clientdata(client);
777
778 hwmon_device_unregister(data->hwmon_dev);
779 sysfs_remove_group(&client->dev.kobj, &w83l786ng_group);
780
781 return 0;
782} 755}
783 756
784static const struct i2c_device_id w83l786ng_id[] = { 757static const struct i2c_device_id w83l786ng_id[] = {
@@ -793,7 +766,6 @@ static struct i2c_driver w83l786ng_driver = {
793 .name = "w83l786ng", 766 .name = "w83l786ng",
794 }, 767 },
795 .probe = w83l786ng_probe, 768 .probe = w83l786ng_probe,
796 .remove = w83l786ng_remove,
797 .id_table = w83l786ng_id, 769 .id_table = w83l786ng_id,
798 .detect = w83l786ng_detect, 770 .detect = w83l786ng_detect,
799 .address_list = normal_i2c, 771 .address_list = normal_i2c,