diff options
author | Axel Lin <axel.lin@ingics.com> | 2014-07-02 21:50:13 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-08-04 10:01:36 -0400 |
commit | d1b9c3f50304376f365e305ff61c3ae9a358e2f9 (patch) | |
tree | 9b6c58bd522456b1a32d17d8437d0bb2cb22f452 /drivers/hwmon/gl520sm.c | |
parent | df51f2d7bc8bf99a7f9c29b2f334e412613c2efc (diff) |
hwmon: (gl520sm) 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/gl520sm.c')
-rw-r--r-- | drivers/hwmon/gl520sm.c | 96 |
1 files changed, 35 insertions, 61 deletions
diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c index 86c08a17210d..dee93ec87d02 100644 --- a/drivers/hwmon/gl520sm.c +++ b/drivers/hwmon/gl520sm.c | |||
@@ -75,7 +75,8 @@ static const u8 GL520_REG_TEMP_MAX_HYST[] = { 0x06, 0x18 }; | |||
75 | 75 | ||
76 | /* Client data */ | 76 | /* Client data */ |
77 | struct gl520_data { | 77 | struct gl520_data { |
78 | struct device *hwmon_dev; | 78 | struct i2c_client *client; |
79 | const struct attribute_group *groups[3]; | ||
79 | struct mutex update_lock; | 80 | struct mutex update_lock; |
80 | char valid; /* zero until the following fields are valid */ | 81 | char valid; /* zero until the following fields are valid */ |
81 | unsigned long last_updated; /* in jiffies */ | 82 | unsigned long last_updated; /* in jiffies */ |
@@ -121,8 +122,8 @@ static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value) | |||
121 | 122 | ||
122 | static struct gl520_data *gl520_update_device(struct device *dev) | 123 | static struct gl520_data *gl520_update_device(struct device *dev) |
123 | { | 124 | { |
124 | struct i2c_client *client = to_i2c_client(dev); | 125 | struct gl520_data *data = dev_get_drvdata(dev); |
125 | struct gl520_data *data = i2c_get_clientdata(client); | 126 | struct i2c_client *client = data->client; |
126 | int val, i; | 127 | int val, i; |
127 | 128 | ||
128 | mutex_lock(&data->update_lock); | 129 | mutex_lock(&data->update_lock); |
@@ -255,8 +256,8 @@ static ssize_t get_in_max(struct device *dev, struct device_attribute *attr, | |||
255 | static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | 256 | static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, |
256 | const char *buf, size_t count) | 257 | const char *buf, size_t count) |
257 | { | 258 | { |
258 | struct i2c_client *client = to_i2c_client(dev); | 259 | struct gl520_data *data = dev_get_drvdata(dev); |
259 | struct gl520_data *data = i2c_get_clientdata(client); | 260 | struct i2c_client *client = data->client; |
260 | int n = to_sensor_dev_attr(attr)->index; | 261 | int n = to_sensor_dev_attr(attr)->index; |
261 | u8 r; | 262 | u8 r; |
262 | long v; | 263 | long v; |
@@ -289,8 +290,8 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | |||
289 | static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, | 290 | static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, |
290 | const char *buf, size_t count) | 291 | const char *buf, size_t count) |
291 | { | 292 | { |
292 | struct i2c_client *client = to_i2c_client(dev); | 293 | struct gl520_data *data = dev_get_drvdata(dev); |
293 | struct gl520_data *data = i2c_get_clientdata(client); | 294 | struct i2c_client *client = data->client; |
294 | int n = to_sensor_dev_attr(attr)->index; | 295 | int n = to_sensor_dev_attr(attr)->index; |
295 | u8 r; | 296 | u8 r; |
296 | long v; | 297 | long v; |
@@ -390,8 +391,8 @@ static ssize_t get_fan_off(struct device *dev, struct device_attribute *attr, | |||
390 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | 391 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, |
391 | const char *buf, size_t count) | 392 | const char *buf, size_t count) |
392 | { | 393 | { |
393 | struct i2c_client *client = to_i2c_client(dev); | 394 | struct gl520_data *data = dev_get_drvdata(dev); |
394 | struct gl520_data *data = i2c_get_clientdata(client); | 395 | struct i2c_client *client = data->client; |
395 | int n = to_sensor_dev_attr(attr)->index; | 396 | int n = to_sensor_dev_attr(attr)->index; |
396 | u8 r; | 397 | u8 r; |
397 | unsigned long v; | 398 | unsigned long v; |
@@ -429,8 +430,8 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | |||
429 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | 430 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, |
430 | const char *buf, size_t count) | 431 | const char *buf, size_t count) |
431 | { | 432 | { |
432 | struct i2c_client *client = to_i2c_client(dev); | 433 | struct gl520_data *data = dev_get_drvdata(dev); |
433 | struct gl520_data *data = i2c_get_clientdata(client); | 434 | struct i2c_client *client = data->client; |
434 | int n = to_sensor_dev_attr(attr)->index; | 435 | int n = to_sensor_dev_attr(attr)->index; |
435 | u8 r; | 436 | u8 r; |
436 | unsigned long v; | 437 | unsigned long v; |
@@ -478,8 +479,8 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | |||
478 | static ssize_t set_fan_off(struct device *dev, struct device_attribute *attr, | 479 | static ssize_t set_fan_off(struct device *dev, struct device_attribute *attr, |
479 | const char *buf, size_t count) | 480 | const char *buf, size_t count) |
480 | { | 481 | { |
481 | struct i2c_client *client = to_i2c_client(dev); | 482 | struct gl520_data *data = dev_get_drvdata(dev); |
482 | struct gl520_data *data = i2c_get_clientdata(client); | 483 | struct i2c_client *client = data->client; |
483 | u8 r; | 484 | u8 r; |
484 | unsigned long v; | 485 | unsigned long v; |
485 | int err; | 486 | int err; |
@@ -546,8 +547,8 @@ static ssize_t get_temp_max_hyst(struct device *dev, | |||
546 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | 547 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, |
547 | const char *buf, size_t count) | 548 | const char *buf, size_t count) |
548 | { | 549 | { |
549 | struct i2c_client *client = to_i2c_client(dev); | 550 | struct gl520_data *data = dev_get_drvdata(dev); |
550 | struct gl520_data *data = i2c_get_clientdata(client); | 551 | struct i2c_client *client = data->client; |
551 | int n = to_sensor_dev_attr(attr)->index; | 552 | int n = to_sensor_dev_attr(attr)->index; |
552 | long v; | 553 | long v; |
553 | int err; | 554 | int err; |
@@ -566,8 +567,8 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
566 | static ssize_t set_temp_max_hyst(struct device *dev, struct device_attribute | 567 | static ssize_t set_temp_max_hyst(struct device *dev, struct device_attribute |
567 | *attr, const char *buf, size_t count) | 568 | *attr, const char *buf, size_t count) |
568 | { | 569 | { |
569 | struct i2c_client *client = to_i2c_client(dev); | 570 | struct gl520_data *data = dev_get_drvdata(dev); |
570 | struct gl520_data *data = i2c_get_clientdata(client); | 571 | struct i2c_client *client = data->client; |
571 | int n = to_sensor_dev_attr(attr)->index; | 572 | int n = to_sensor_dev_attr(attr)->index; |
572 | long v; | 573 | long v; |
573 | int err; | 574 | int err; |
@@ -619,8 +620,8 @@ static ssize_t get_beep_mask(struct device *dev, struct device_attribute *attr, | |||
619 | static ssize_t set_beep_enable(struct device *dev, struct device_attribute | 620 | static ssize_t set_beep_enable(struct device *dev, struct device_attribute |
620 | *attr, const char *buf, size_t count) | 621 | *attr, const char *buf, size_t count) |
621 | { | 622 | { |
622 | struct i2c_client *client = to_i2c_client(dev); | 623 | struct gl520_data *data = dev_get_drvdata(dev); |
623 | struct gl520_data *data = i2c_get_clientdata(client); | 624 | struct i2c_client *client = data->client; |
624 | u8 r; | 625 | u8 r; |
625 | unsigned long v; | 626 | unsigned long v; |
626 | int err; | 627 | int err; |
@@ -643,8 +644,8 @@ static ssize_t set_beep_enable(struct device *dev, struct device_attribute | |||
643 | static ssize_t set_beep_mask(struct device *dev, struct device_attribute *attr, | 644 | static ssize_t set_beep_mask(struct device *dev, struct device_attribute *attr, |
644 | const char *buf, size_t count) | 645 | const char *buf, size_t count) |
645 | { | 646 | { |
646 | struct i2c_client *client = to_i2c_client(dev); | 647 | struct gl520_data *data = dev_get_drvdata(dev); |
647 | struct gl520_data *data = i2c_get_clientdata(client); | 648 | struct i2c_client *client = data->client; |
648 | unsigned long r; | 649 | unsigned long r; |
649 | int err; | 650 | int err; |
650 | 651 | ||
@@ -697,8 +698,8 @@ static ssize_t get_beep(struct device *dev, struct device_attribute *attr, | |||
697 | static ssize_t set_beep(struct device *dev, struct device_attribute *attr, | 698 | static ssize_t set_beep(struct device *dev, struct device_attribute *attr, |
698 | const char *buf, size_t count) | 699 | const char *buf, size_t count) |
699 | { | 700 | { |
700 | struct i2c_client *client = to_i2c_client(dev); | 701 | struct gl520_data *data = dev_get_drvdata(dev); |
701 | struct gl520_data *data = i2c_get_clientdata(client); | 702 | struct i2c_client *client = data->client; |
702 | int bitnr = to_sensor_dev_attr(attr)->index; | 703 | int bitnr = to_sensor_dev_attr(attr)->index; |
703 | unsigned long bit; | 704 | unsigned long bit; |
704 | 705 | ||
@@ -877,58 +878,32 @@ static void gl520_init_client(struct i2c_client *client) | |||
877 | static int gl520_probe(struct i2c_client *client, | 878 | static int gl520_probe(struct i2c_client *client, |
878 | const struct i2c_device_id *id) | 879 | const struct i2c_device_id *id) |
879 | { | 880 | { |
881 | struct device *dev = &client->dev; | ||
882 | struct device *hwmon_dev; | ||
880 | struct gl520_data *data; | 883 | struct gl520_data *data; |
881 | int err; | ||
882 | 884 | ||
883 | data = devm_kzalloc(&client->dev, sizeof(struct gl520_data), | 885 | data = devm_kzalloc(dev, sizeof(struct gl520_data), GFP_KERNEL); |
884 | GFP_KERNEL); | ||
885 | if (!data) | 886 | if (!data) |
886 | return -ENOMEM; | 887 | return -ENOMEM; |
887 | 888 | ||
888 | i2c_set_clientdata(client, data); | 889 | i2c_set_clientdata(client, data); |
889 | mutex_init(&data->update_lock); | 890 | mutex_init(&data->update_lock); |
891 | data->client = client; | ||
890 | 892 | ||
891 | /* Initialize the GL520SM chip */ | 893 | /* Initialize the GL520SM chip */ |
892 | gl520_init_client(client); | 894 | gl520_init_client(client); |
893 | 895 | ||
894 | /* Register sysfs hooks */ | 896 | /* sysfs hooks */ |
895 | err = sysfs_create_group(&client->dev.kobj, &gl520_group); | 897 | data->groups[0] = &gl520_group; |
896 | if (err) | ||
897 | return err; | ||
898 | 898 | ||
899 | if (data->two_temps) | 899 | if (data->two_temps) |
900 | err = sysfs_create_group(&client->dev.kobj, &gl520_group_temp2); | 900 | data->groups[1] = &gl520_group_temp2; |
901 | else | 901 | else |
902 | err = sysfs_create_group(&client->dev.kobj, &gl520_group_in4); | 902 | data->groups[1] = &gl520_group_in4; |
903 | |||
904 | if (err) | ||
905 | goto exit_remove_files; | ||
906 | |||
907 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
908 | if (IS_ERR(data->hwmon_dev)) { | ||
909 | err = PTR_ERR(data->hwmon_dev); | ||
910 | goto exit_remove_files; | ||
911 | } | ||
912 | |||
913 | return 0; | ||
914 | 903 | ||
915 | exit_remove_files: | 904 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
916 | sysfs_remove_group(&client->dev.kobj, &gl520_group); | 905 | data, data->groups); |
917 | sysfs_remove_group(&client->dev.kobj, &gl520_group_in4); | 906 | return PTR_ERR_OR_ZERO(hwmon_dev); |
918 | sysfs_remove_group(&client->dev.kobj, &gl520_group_temp2); | ||
919 | return err; | ||
920 | } | ||
921 | |||
922 | static int gl520_remove(struct i2c_client *client) | ||
923 | { | ||
924 | struct gl520_data *data = i2c_get_clientdata(client); | ||
925 | |||
926 | hwmon_device_unregister(data->hwmon_dev); | ||
927 | sysfs_remove_group(&client->dev.kobj, &gl520_group); | ||
928 | sysfs_remove_group(&client->dev.kobj, &gl520_group_in4); | ||
929 | sysfs_remove_group(&client->dev.kobj, &gl520_group_temp2); | ||
930 | |||
931 | return 0; | ||
932 | } | 907 | } |
933 | 908 | ||
934 | static const struct i2c_device_id gl520_id[] = { | 909 | static const struct i2c_device_id gl520_id[] = { |
@@ -943,7 +918,6 @@ static struct i2c_driver gl520_driver = { | |||
943 | .name = "gl520sm", | 918 | .name = "gl520sm", |
944 | }, | 919 | }, |
945 | .probe = gl520_probe, | 920 | .probe = gl520_probe, |
946 | .remove = gl520_remove, | ||
947 | .id_table = gl520_id, | 921 | .id_table = gl520_id, |
948 | .detect = gl520_detect, | 922 | .detect = gl520_detect, |
949 | .address_list = normal_i2c, | 923 | .address_list = normal_i2c, |