diff options
author | Axel Lin <axel.lin@ingics.com> | 2014-07-19 10:52:40 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-08-04 10:01:40 -0400 |
commit | 9dd304f86b4b1921c0b7601b3e88a07b257fc2d2 (patch) | |
tree | e6b6c81bbf89dd8f0532c83b2993074602c13ac3 | |
parent | e70198acf84690b3d8ed5d1b924942c1dd85d20d (diff) |
hwmon: (emc2103) Convert to devm_hwmon_device_register_with_groups
Use 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/emc2103.c | 89 |
1 files changed, 26 insertions, 63 deletions
diff --git a/drivers/hwmon/emc2103.c b/drivers/hwmon/emc2103.c index 78002de46cb6..952fe692d764 100644 --- a/drivers/hwmon/emc2103.c +++ b/drivers/hwmon/emc2103.c | |||
@@ -66,7 +66,8 @@ struct temperature { | |||
66 | }; | 66 | }; |
67 | 67 | ||
68 | struct emc2103_data { | 68 | struct emc2103_data { |
69 | struct device *hwmon_dev; | 69 | struct i2c_client *client; |
70 | const struct attribute_group *groups[4]; | ||
70 | struct mutex update_lock; | 71 | struct mutex update_lock; |
71 | bool valid; /* registers are valid */ | 72 | bool valid; /* registers are valid */ |
72 | bool fan_rpm_control; | 73 | bool fan_rpm_control; |
@@ -146,8 +147,8 @@ static void read_fan_config_from_i2c(struct i2c_client *client) | |||
146 | 147 | ||
147 | static struct emc2103_data *emc2103_update_device(struct device *dev) | 148 | static struct emc2103_data *emc2103_update_device(struct device *dev) |
148 | { | 149 | { |
149 | struct i2c_client *client = to_i2c_client(dev); | 150 | struct emc2103_data *data = dev_get_drvdata(dev); |
150 | struct emc2103_data *data = i2c_get_clientdata(client); | 151 | struct i2c_client *client = data->client; |
151 | 152 | ||
152 | mutex_lock(&data->update_lock); | 153 | mutex_lock(&data->update_lock); |
153 | 154 | ||
@@ -242,8 +243,8 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *da, | |||
242 | const char *buf, size_t count) | 243 | const char *buf, size_t count) |
243 | { | 244 | { |
244 | int nr = to_sensor_dev_attr(da)->index; | 245 | int nr = to_sensor_dev_attr(da)->index; |
245 | struct i2c_client *client = to_i2c_client(dev); | 246 | struct emc2103_data *data = dev_get_drvdata(dev); |
246 | struct emc2103_data *data = i2c_get_clientdata(client); | 247 | struct i2c_client *client = data->client; |
247 | long val; | 248 | long val; |
248 | 249 | ||
249 | int result = kstrtol(buf, 10, &val); | 250 | int result = kstrtol(buf, 10, &val); |
@@ -264,8 +265,8 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *da, | |||
264 | const char *buf, size_t count) | 265 | const char *buf, size_t count) |
265 | { | 266 | { |
266 | int nr = to_sensor_dev_attr(da)->index; | 267 | int nr = to_sensor_dev_attr(da)->index; |
267 | struct i2c_client *client = to_i2c_client(dev); | 268 | struct emc2103_data *data = dev_get_drvdata(dev); |
268 | struct emc2103_data *data = i2c_get_clientdata(client); | 269 | struct i2c_client *client = data->client; |
269 | long val; | 270 | long val; |
270 | 271 | ||
271 | int result = kstrtol(buf, 10, &val); | 272 | int result = kstrtol(buf, 10, &val); |
@@ -310,7 +311,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *da, | |||
310 | const char *buf, size_t count) | 311 | const char *buf, size_t count) |
311 | { | 312 | { |
312 | struct emc2103_data *data = emc2103_update_device(dev); | 313 | struct emc2103_data *data = emc2103_update_device(dev); |
313 | struct i2c_client *client = to_i2c_client(dev); | 314 | struct i2c_client *client = data->client; |
314 | int new_range_bits, old_div = 8 / data->fan_multiplier; | 315 | int new_range_bits, old_div = 8 / data->fan_multiplier; |
315 | long new_div; | 316 | long new_div; |
316 | 317 | ||
@@ -385,7 +386,7 @@ static ssize_t set_fan_target(struct device *dev, struct device_attribute *da, | |||
385 | const char *buf, size_t count) | 386 | const char *buf, size_t count) |
386 | { | 387 | { |
387 | struct emc2103_data *data = emc2103_update_device(dev); | 388 | struct emc2103_data *data = emc2103_update_device(dev); |
388 | struct i2c_client *client = to_i2c_client(dev); | 389 | struct i2c_client *client = data->client; |
389 | unsigned long rpm_target; | 390 | unsigned long rpm_target; |
390 | 391 | ||
391 | int result = kstrtoul(buf, 10, &rpm_target); | 392 | int result = kstrtoul(buf, 10, &rpm_target); |
@@ -428,8 +429,8 @@ show_pwm_enable(struct device *dev, struct device_attribute *da, char *buf) | |||
428 | static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *da, | 429 | static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *da, |
429 | const char *buf, size_t count) | 430 | const char *buf, size_t count) |
430 | { | 431 | { |
431 | struct i2c_client *client = to_i2c_client(dev); | 432 | struct emc2103_data *data = dev_get_drvdata(dev); |
432 | struct emc2103_data *data = i2c_get_clientdata(client); | 433 | struct i2c_client *client = data->client; |
433 | long new_value; | 434 | long new_value; |
434 | u8 conf_reg; | 435 | u8 conf_reg; |
435 | 436 | ||
@@ -580,7 +581,8 @@ static int | |||
580 | emc2103_probe(struct i2c_client *client, const struct i2c_device_id *id) | 581 | emc2103_probe(struct i2c_client *client, const struct i2c_device_id *id) |
581 | { | 582 | { |
582 | struct emc2103_data *data; | 583 | struct emc2103_data *data; |
583 | int status; | 584 | struct device *hwmon_dev; |
585 | int status, idx = 0; | ||
584 | 586 | ||
585 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 587 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
586 | return -EIO; | 588 | return -EIO; |
@@ -591,6 +593,7 @@ emc2103_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
591 | return -ENOMEM; | 593 | return -ENOMEM; |
592 | 594 | ||
593 | i2c_set_clientdata(client, data); | 595 | i2c_set_clientdata(client, data); |
596 | data->client = client; | ||
594 | mutex_init(&data->update_lock); | 597 | mutex_init(&data->update_lock); |
595 | 598 | ||
596 | /* 2103-2 and 2103-4 have 3 external diodes, 2103-1 has 1 */ | 599 | /* 2103-2 and 2103-4 have 3 external diodes, 2103-1 has 1 */ |
@@ -624,60 +627,21 @@ emc2103_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
624 | } | 627 | } |
625 | } | 628 | } |
626 | 629 | ||
627 | /* Register sysfs hooks */ | 630 | /* sysfs hooks */ |
628 | status = sysfs_create_group(&client->dev.kobj, &emc2103_group); | 631 | data->groups[idx++] = &emc2103_group; |
629 | if (status) | ||
630 | return status; | ||
631 | |||
632 | if (data->temp_count >= 3) { | ||
633 | status = sysfs_create_group(&client->dev.kobj, | ||
634 | &emc2103_temp3_group); | ||
635 | if (status) | ||
636 | goto exit_remove; | ||
637 | } | ||
638 | |||
639 | if (data->temp_count == 4) { | ||
640 | status = sysfs_create_group(&client->dev.kobj, | ||
641 | &emc2103_temp4_group); | ||
642 | if (status) | ||
643 | goto exit_remove_temp3; | ||
644 | } | ||
645 | |||
646 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
647 | if (IS_ERR(data->hwmon_dev)) { | ||
648 | status = PTR_ERR(data->hwmon_dev); | ||
649 | goto exit_remove_temp4; | ||
650 | } | ||
651 | |||
652 | dev_info(&client->dev, "%s: sensor '%s'\n", | ||
653 | dev_name(data->hwmon_dev), client->name); | ||
654 | |||
655 | return 0; | ||
656 | |||
657 | exit_remove_temp4: | ||
658 | if (data->temp_count == 4) | ||
659 | sysfs_remove_group(&client->dev.kobj, &emc2103_temp4_group); | ||
660 | exit_remove_temp3: | ||
661 | if (data->temp_count >= 3) | 632 | if (data->temp_count >= 3) |
662 | sysfs_remove_group(&client->dev.kobj, &emc2103_temp3_group); | 633 | data->groups[idx++] = &emc2103_temp3_group; |
663 | exit_remove: | ||
664 | sysfs_remove_group(&client->dev.kobj, &emc2103_group); | ||
665 | return status; | ||
666 | } | ||
667 | |||
668 | static int emc2103_remove(struct i2c_client *client) | ||
669 | { | ||
670 | struct emc2103_data *data = i2c_get_clientdata(client); | ||
671 | |||
672 | hwmon_device_unregister(data->hwmon_dev); | ||
673 | |||
674 | if (data->temp_count == 4) | 634 | if (data->temp_count == 4) |
675 | sysfs_remove_group(&client->dev.kobj, &emc2103_temp4_group); | 635 | data->groups[idx++] = &emc2103_temp4_group; |
676 | 636 | ||
677 | if (data->temp_count >= 3) | 637 | hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev, |
678 | sysfs_remove_group(&client->dev.kobj, &emc2103_temp3_group); | 638 | client->name, data, |
639 | data->groups); | ||
640 | if (IS_ERR(hwmon_dev)) | ||
641 | return PTR_ERR(hwmon_dev); | ||
679 | 642 | ||
680 | sysfs_remove_group(&client->dev.kobj, &emc2103_group); | 643 | dev_info(&client->dev, "%s: sensor '%s'\n", |
644 | dev_name(hwmon_dev), client->name); | ||
681 | 645 | ||
682 | return 0; | 646 | return 0; |
683 | } | 647 | } |
@@ -717,7 +681,6 @@ static struct i2c_driver emc2103_driver = { | |||
717 | .name = "emc2103", | 681 | .name = "emc2103", |
718 | }, | 682 | }, |
719 | .probe = emc2103_probe, | 683 | .probe = emc2103_probe, |
720 | .remove = emc2103_remove, | ||
721 | .id_table = emc2103_ids, | 684 | .id_table = emc2103_ids, |
722 | .detect = emc2103_detect, | 685 | .detect = emc2103_detect, |
723 | .address_list = normal_i2c, | 686 | .address_list = normal_i2c, |