diff options
author | Axel Lin <axel.lin@ingics.com> | 2014-07-16 11:12:54 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-08-04 10:01:39 -0400 |
commit | 3048577609ef09859505ff2aaf7194a924202193 (patch) | |
tree | 8cce82e0ccf220790e01b72ebfe59ff6e284f958 /drivers/hwmon/adt7470.c | |
parent | 9027d933a91e1430ebcd9b9fb8da538cb40284ef (diff) |
hwmon: (adt7470) 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/adt7470.c')
-rw-r--r-- | drivers/hwmon/adt7470.c | 97 |
1 files changed, 42 insertions, 55 deletions
diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c index 7dfb1864c6e4..f5da39a68929 100644 --- a/drivers/hwmon/adt7470.c +++ b/drivers/hwmon/adt7470.c | |||
@@ -143,8 +143,7 @@ static const unsigned short normal_i2c[] = { 0x2C, 0x2E, 0x2F, I2C_CLIENT_END }; | |||
143 | #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) | 143 | #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) |
144 | 144 | ||
145 | struct adt7470_data { | 145 | struct adt7470_data { |
146 | struct device *hwmon_dev; | 146 | struct i2c_client *client; |
147 | struct attribute_group attrs; | ||
148 | struct mutex lock; | 147 | struct mutex lock; |
149 | char sensors_valid; | 148 | char sensors_valid; |
150 | char limits_valid; | 149 | char limits_valid; |
@@ -278,8 +277,8 @@ static int adt7470_update_thread(void *p) | |||
278 | 277 | ||
279 | static struct adt7470_data *adt7470_update_device(struct device *dev) | 278 | static struct adt7470_data *adt7470_update_device(struct device *dev) |
280 | { | 279 | { |
281 | struct i2c_client *client = to_i2c_client(dev); | 280 | struct adt7470_data *data = dev_get_drvdata(dev); |
282 | struct adt7470_data *data = i2c_get_clientdata(client); | 281 | struct i2c_client *client = data->client; |
283 | unsigned long local_jiffies = jiffies; | 282 | unsigned long local_jiffies = jiffies; |
284 | u8 cfg; | 283 | u8 cfg; |
285 | int i; | 284 | int i; |
@@ -409,8 +408,7 @@ static ssize_t set_auto_update_interval(struct device *dev, | |||
409 | const char *buf, | 408 | const char *buf, |
410 | size_t count) | 409 | size_t count) |
411 | { | 410 | { |
412 | struct i2c_client *client = to_i2c_client(dev); | 411 | struct adt7470_data *data = dev_get_drvdata(dev); |
413 | struct adt7470_data *data = i2c_get_clientdata(client); | ||
414 | long temp; | 412 | long temp; |
415 | 413 | ||
416 | if (kstrtol(buf, 10, &temp)) | 414 | if (kstrtol(buf, 10, &temp)) |
@@ -438,8 +436,7 @@ static ssize_t set_num_temp_sensors(struct device *dev, | |||
438 | const char *buf, | 436 | const char *buf, |
439 | size_t count) | 437 | size_t count) |
440 | { | 438 | { |
441 | struct i2c_client *client = to_i2c_client(dev); | 439 | struct adt7470_data *data = dev_get_drvdata(dev); |
442 | struct adt7470_data *data = i2c_get_clientdata(client); | ||
443 | long temp; | 440 | long temp; |
444 | 441 | ||
445 | if (kstrtol(buf, 10, &temp)) | 442 | if (kstrtol(buf, 10, &temp)) |
@@ -471,8 +468,8 @@ static ssize_t set_temp_min(struct device *dev, | |||
471 | size_t count) | 468 | size_t count) |
472 | { | 469 | { |
473 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 470 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
474 | struct i2c_client *client = to_i2c_client(dev); | 471 | struct adt7470_data *data = dev_get_drvdata(dev); |
475 | struct adt7470_data *data = i2c_get_clientdata(client); | 472 | struct i2c_client *client = data->client; |
476 | long temp; | 473 | long temp; |
477 | 474 | ||
478 | if (kstrtol(buf, 10, &temp)) | 475 | if (kstrtol(buf, 10, &temp)) |
@@ -505,8 +502,8 @@ static ssize_t set_temp_max(struct device *dev, | |||
505 | size_t count) | 502 | size_t count) |
506 | { | 503 | { |
507 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 504 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
508 | struct i2c_client *client = to_i2c_client(dev); | 505 | struct adt7470_data *data = dev_get_drvdata(dev); |
509 | struct adt7470_data *data = i2c_get_clientdata(client); | 506 | struct i2c_client *client = data->client; |
510 | long temp; | 507 | long temp; |
511 | 508 | ||
512 | if (kstrtol(buf, 10, &temp)) | 509 | if (kstrtol(buf, 10, &temp)) |
@@ -560,8 +557,8 @@ static ssize_t set_fan_max(struct device *dev, | |||
560 | const char *buf, size_t count) | 557 | const char *buf, size_t count) |
561 | { | 558 | { |
562 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 559 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
563 | struct i2c_client *client = to_i2c_client(dev); | 560 | struct adt7470_data *data = dev_get_drvdata(dev); |
564 | struct adt7470_data *data = i2c_get_clientdata(client); | 561 | struct i2c_client *client = data->client; |
565 | long temp; | 562 | long temp; |
566 | 563 | ||
567 | if (kstrtol(buf, 10, &temp) || !temp) | 564 | if (kstrtol(buf, 10, &temp) || !temp) |
@@ -597,8 +594,8 @@ static ssize_t set_fan_min(struct device *dev, | |||
597 | const char *buf, size_t count) | 594 | const char *buf, size_t count) |
598 | { | 595 | { |
599 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 596 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
600 | struct i2c_client *client = to_i2c_client(dev); | 597 | struct adt7470_data *data = dev_get_drvdata(dev); |
601 | struct adt7470_data *data = i2c_get_clientdata(client); | 598 | struct i2c_client *client = data->client; |
602 | long temp; | 599 | long temp; |
603 | 600 | ||
604 | if (kstrtol(buf, 10, &temp) || !temp) | 601 | if (kstrtol(buf, 10, &temp) || !temp) |
@@ -641,8 +638,8 @@ static ssize_t set_force_pwm_max(struct device *dev, | |||
641 | const char *buf, | 638 | const char *buf, |
642 | size_t count) | 639 | size_t count) |
643 | { | 640 | { |
644 | struct i2c_client *client = to_i2c_client(dev); | 641 | struct adt7470_data *data = dev_get_drvdata(dev); |
645 | struct adt7470_data *data = i2c_get_clientdata(client); | 642 | struct i2c_client *client = data->client; |
646 | long temp; | 643 | long temp; |
647 | u8 reg; | 644 | u8 reg; |
648 | 645 | ||
@@ -674,8 +671,8 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, | |||
674 | const char *buf, size_t count) | 671 | const char *buf, size_t count) |
675 | { | 672 | { |
676 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 673 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
677 | struct i2c_client *client = to_i2c_client(dev); | 674 | struct adt7470_data *data = dev_get_drvdata(dev); |
678 | struct adt7470_data *data = i2c_get_clientdata(client); | 675 | struct i2c_client *client = data->client; |
679 | long temp; | 676 | long temp; |
680 | 677 | ||
681 | if (kstrtol(buf, 10, &temp)) | 678 | if (kstrtol(buf, 10, &temp)) |
@@ -706,8 +703,8 @@ static ssize_t set_pwm_max(struct device *dev, | |||
706 | size_t count) | 703 | size_t count) |
707 | { | 704 | { |
708 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 705 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
709 | struct i2c_client *client = to_i2c_client(dev); | 706 | struct adt7470_data *data = dev_get_drvdata(dev); |
710 | struct adt7470_data *data = i2c_get_clientdata(client); | 707 | struct i2c_client *client = data->client; |
711 | long temp; | 708 | long temp; |
712 | 709 | ||
713 | if (kstrtol(buf, 10, &temp)) | 710 | if (kstrtol(buf, 10, &temp)) |
@@ -739,8 +736,8 @@ static ssize_t set_pwm_min(struct device *dev, | |||
739 | size_t count) | 736 | size_t count) |
740 | { | 737 | { |
741 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 738 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
742 | struct i2c_client *client = to_i2c_client(dev); | 739 | struct adt7470_data *data = dev_get_drvdata(dev); |
743 | struct adt7470_data *data = i2c_get_clientdata(client); | 740 | struct i2c_client *client = data->client; |
744 | long temp; | 741 | long temp; |
745 | 742 | ||
746 | if (kstrtol(buf, 10, &temp)) | 743 | if (kstrtol(buf, 10, &temp)) |
@@ -782,8 +779,8 @@ static ssize_t set_pwm_tmin(struct device *dev, | |||
782 | size_t count) | 779 | size_t count) |
783 | { | 780 | { |
784 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 781 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
785 | struct i2c_client *client = to_i2c_client(dev); | 782 | struct adt7470_data *data = dev_get_drvdata(dev); |
786 | struct adt7470_data *data = i2c_get_clientdata(client); | 783 | struct i2c_client *client = data->client; |
787 | long temp; | 784 | long temp; |
788 | 785 | ||
789 | if (kstrtol(buf, 10, &temp)) | 786 | if (kstrtol(buf, 10, &temp)) |
@@ -816,8 +813,8 @@ static ssize_t set_pwm_auto(struct device *dev, | |||
816 | size_t count) | 813 | size_t count) |
817 | { | 814 | { |
818 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 815 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
819 | struct i2c_client *client = to_i2c_client(dev); | 816 | struct adt7470_data *data = dev_get_drvdata(dev); |
820 | struct adt7470_data *data = i2c_get_clientdata(client); | 817 | struct i2c_client *client = data->client; |
821 | int pwm_auto_reg = ADT7470_REG_PWM_CFG(attr->index); | 818 | int pwm_auto_reg = ADT7470_REG_PWM_CFG(attr->index); |
822 | int pwm_auto_reg_mask; | 819 | int pwm_auto_reg_mask; |
823 | long temp; | 820 | long temp; |
@@ -877,8 +874,8 @@ static ssize_t set_pwm_auto_temp(struct device *dev, | |||
877 | size_t count) | 874 | size_t count) |
878 | { | 875 | { |
879 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 876 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
880 | struct i2c_client *client = to_i2c_client(dev); | 877 | struct adt7470_data *data = dev_get_drvdata(dev); |
881 | struct adt7470_data *data = i2c_get_clientdata(client); | 878 | struct i2c_client *client = data->client; |
882 | int pwm_auto_reg = ADT7470_REG_PWM_AUTO_TEMP(attr->index); | 879 | int pwm_auto_reg = ADT7470_REG_PWM_AUTO_TEMP(attr->index); |
883 | long temp; | 880 | long temp; |
884 | u8 reg; | 881 | u8 reg; |
@@ -1095,7 +1092,7 @@ static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IWUSR | S_IRUGO, | |||
1095 | static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO, | 1092 | static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO, |
1096 | show_pwm_auto_temp, set_pwm_auto_temp, 3); | 1093 | show_pwm_auto_temp, set_pwm_auto_temp, 3); |
1097 | 1094 | ||
1098 | static struct attribute *adt7470_attr[] = { | 1095 | static struct attribute *adt7470_attrs[] = { |
1099 | &dev_attr_alarm_mask.attr, | 1096 | &dev_attr_alarm_mask.attr, |
1100 | &dev_attr_num_temp_sensors.attr, | 1097 | &dev_attr_num_temp_sensors.attr, |
1101 | &dev_attr_auto_update_interval.attr, | 1098 | &dev_attr_auto_update_interval.attr, |
@@ -1187,6 +1184,8 @@ static struct attribute *adt7470_attr[] = { | |||
1187 | NULL | 1184 | NULL |
1188 | }; | 1185 | }; |
1189 | 1186 | ||
1187 | ATTRIBUTE_GROUPS(adt7470); | ||
1188 | |||
1190 | /* Return 0 if detection is successful, -ENODEV otherwise */ | 1189 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
1191 | static int adt7470_detect(struct i2c_client *client, | 1190 | static int adt7470_detect(struct i2c_client *client, |
1192 | struct i2c_board_info *info) | 1191 | struct i2c_board_info *info) |
@@ -1229,11 +1228,11 @@ static void adt7470_init_client(struct i2c_client *client) | |||
1229 | static int adt7470_probe(struct i2c_client *client, | 1228 | static int adt7470_probe(struct i2c_client *client, |
1230 | const struct i2c_device_id *id) | 1229 | const struct i2c_device_id *id) |
1231 | { | 1230 | { |
1231 | struct device *dev = &client->dev; | ||
1232 | struct adt7470_data *data; | 1232 | struct adt7470_data *data; |
1233 | int err; | 1233 | struct device *hwmon_dev; |
1234 | 1234 | ||
1235 | data = devm_kzalloc(&client->dev, sizeof(struct adt7470_data), | 1235 | data = devm_kzalloc(dev, sizeof(struct adt7470_data), GFP_KERNEL); |
1236 | GFP_KERNEL); | ||
1237 | if (!data) | 1236 | if (!data) |
1238 | return -ENOMEM; | 1237 | return -ENOMEM; |
1239 | 1238 | ||
@@ -1241,6 +1240,7 @@ static int adt7470_probe(struct i2c_client *client, | |||
1241 | data->auto_update_interval = AUTO_UPDATE_INTERVAL; | 1240 | data->auto_update_interval = AUTO_UPDATE_INTERVAL; |
1242 | 1241 | ||
1243 | i2c_set_clientdata(client, data); | 1242 | i2c_set_clientdata(client, data); |
1243 | data->client = client; | ||
1244 | mutex_init(&data->lock); | 1244 | mutex_init(&data->lock); |
1245 | 1245 | ||
1246 | dev_info(&client->dev, "%s chip found\n", client->name); | 1246 | dev_info(&client->dev, "%s chip found\n", client->name); |
@@ -1249,32 +1249,21 @@ static int adt7470_probe(struct i2c_client *client, | |||
1249 | adt7470_init_client(client); | 1249 | adt7470_init_client(client); |
1250 | 1250 | ||
1251 | /* Register sysfs hooks */ | 1251 | /* Register sysfs hooks */ |
1252 | data->attrs.attrs = adt7470_attr; | 1252 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
1253 | err = sysfs_create_group(&client->dev.kobj, &data->attrs); | 1253 | data, |
1254 | if (err) | 1254 | adt7470_groups); |
1255 | return err; | 1255 | |
1256 | 1256 | if (IS_ERR(hwmon_dev)) | |
1257 | data->hwmon_dev = hwmon_device_register(&client->dev); | 1257 | return PTR_ERR(hwmon_dev); |
1258 | if (IS_ERR(data->hwmon_dev)) { | ||
1259 | err = PTR_ERR(data->hwmon_dev); | ||
1260 | goto exit_remove; | ||
1261 | } | ||
1262 | 1258 | ||
1263 | init_completion(&data->auto_update_stop); | 1259 | init_completion(&data->auto_update_stop); |
1264 | data->auto_update = kthread_run(adt7470_update_thread, client, "%s", | 1260 | data->auto_update = kthread_run(adt7470_update_thread, client, "%s", |
1265 | dev_name(data->hwmon_dev)); | 1261 | dev_name(hwmon_dev)); |
1266 | if (IS_ERR(data->auto_update)) { | 1262 | if (IS_ERR(data->auto_update)) { |
1267 | err = PTR_ERR(data->auto_update); | 1263 | return PTR_ERR(data->auto_update); |
1268 | goto exit_unregister; | ||
1269 | } | 1264 | } |
1270 | 1265 | ||
1271 | return 0; | 1266 | return 0; |
1272 | |||
1273 | exit_unregister: | ||
1274 | hwmon_device_unregister(data->hwmon_dev); | ||
1275 | exit_remove: | ||
1276 | sysfs_remove_group(&client->dev.kobj, &data->attrs); | ||
1277 | return err; | ||
1278 | } | 1267 | } |
1279 | 1268 | ||
1280 | static int adt7470_remove(struct i2c_client *client) | 1269 | static int adt7470_remove(struct i2c_client *client) |
@@ -1283,8 +1272,6 @@ static int adt7470_remove(struct i2c_client *client) | |||
1283 | 1272 | ||
1284 | kthread_stop(data->auto_update); | 1273 | kthread_stop(data->auto_update); |
1285 | wait_for_completion(&data->auto_update_stop); | 1274 | wait_for_completion(&data->auto_update_stop); |
1286 | hwmon_device_unregister(data->hwmon_dev); | ||
1287 | sysfs_remove_group(&client->dev.kobj, &data->attrs); | ||
1288 | return 0; | 1275 | return 0; |
1289 | } | 1276 | } |
1290 | 1277 | ||