diff options
author | Axel Lin <axel.lin@ingics.com> | 2014-07-08 21:20:41 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-09-22 14:14:52 -0400 |
commit | 4222eb5f2b4fe9a0f50b283ba25111c595723429 (patch) | |
tree | e9d7a2cef9151ee2e10b64aeaacf9ae89a654ab2 | |
parent | e7d275e7619510314dbb9207896bb12074d71c81 (diff) |
hwmon: (da9052) 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>
Tested-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r-- | drivers/hwmon/da9052-hwmon.c | 54 |
1 files changed, 9 insertions, 45 deletions
diff --git a/drivers/hwmon/da9052-hwmon.c b/drivers/hwmon/da9052-hwmon.c index d14ab3c45daa..692b3f34d88c 100644 --- a/drivers/hwmon/da9052-hwmon.c +++ b/drivers/hwmon/da9052-hwmon.c | |||
@@ -26,7 +26,6 @@ | |||
26 | 26 | ||
27 | struct da9052_hwmon { | 27 | struct da9052_hwmon { |
28 | struct da9052 *da9052; | 28 | struct da9052 *da9052; |
29 | struct device *class_device; | ||
30 | struct mutex hwmon_lock; | 29 | struct mutex hwmon_lock; |
31 | }; | 30 | }; |
32 | 31 | ||
@@ -190,13 +189,6 @@ static ssize_t da9052_read_vbbat(struct device *dev, | |||
190 | return sprintf(buf, "%d\n", vbbat_reg_to_mv(ret)); | 189 | return sprintf(buf, "%d\n", vbbat_reg_to_mv(ret)); |
191 | } | 190 | } |
192 | 191 | ||
193 | static ssize_t da9052_hwmon_show_name(struct device *dev, | ||
194 | struct device_attribute *devattr, | ||
195 | char *buf) | ||
196 | { | ||
197 | return sprintf(buf, "da9052\n"); | ||
198 | } | ||
199 | |||
200 | static ssize_t show_label(struct device *dev, | 192 | static ssize_t show_label(struct device *dev, |
201 | struct device_attribute *devattr, char *buf) | 193 | struct device_attribute *devattr, char *buf) |
202 | { | 194 | { |
@@ -243,10 +235,7 @@ static SENSOR_DEVICE_ATTR(temp8_input, S_IRUGO, da9052_read_tjunc, NULL, | |||
243 | static SENSOR_DEVICE_ATTR(temp8_label, S_IRUGO, show_label, NULL, | 235 | static SENSOR_DEVICE_ATTR(temp8_label, S_IRUGO, show_label, NULL, |
244 | DA9052_ADC_TJUNC); | 236 | DA9052_ADC_TJUNC); |
245 | 237 | ||
246 | static DEVICE_ATTR(name, S_IRUGO, da9052_hwmon_show_name, NULL); | 238 | static struct attribute *da9052_attrs[] = { |
247 | |||
248 | static struct attribute *da9052_attr[] = { | ||
249 | &dev_attr_name.attr, | ||
250 | &sensor_dev_attr_in0_input.dev_attr.attr, | 239 | &sensor_dev_attr_in0_input.dev_attr.attr, |
251 | &sensor_dev_attr_in0_label.dev_attr.attr, | 240 | &sensor_dev_attr_in0_label.dev_attr.attr, |
252 | &sensor_dev_attr_in3_input.dev_attr.attr, | 241 | &sensor_dev_attr_in3_input.dev_attr.attr, |
@@ -268,54 +257,29 @@ static struct attribute *da9052_attr[] = { | |||
268 | NULL | 257 | NULL |
269 | }; | 258 | }; |
270 | 259 | ||
271 | static const struct attribute_group da9052_attr_group = {.attrs = da9052_attr}; | 260 | ATTRIBUTE_GROUPS(da9052); |
272 | 261 | ||
273 | static int da9052_hwmon_probe(struct platform_device *pdev) | 262 | static int da9052_hwmon_probe(struct platform_device *pdev) |
274 | { | 263 | { |
264 | struct device *dev = &pdev->dev; | ||
275 | struct da9052_hwmon *hwmon; | 265 | struct da9052_hwmon *hwmon; |
276 | int ret; | 266 | struct device *hwmon_dev; |
277 | 267 | ||
278 | hwmon = devm_kzalloc(&pdev->dev, sizeof(struct da9052_hwmon), | 268 | hwmon = devm_kzalloc(dev, sizeof(struct da9052_hwmon), GFP_KERNEL); |
279 | GFP_KERNEL); | ||
280 | if (!hwmon) | 269 | if (!hwmon) |
281 | return -ENOMEM; | 270 | return -ENOMEM; |
282 | 271 | ||
283 | mutex_init(&hwmon->hwmon_lock); | 272 | mutex_init(&hwmon->hwmon_lock); |
284 | hwmon->da9052 = dev_get_drvdata(pdev->dev.parent); | 273 | hwmon->da9052 = dev_get_drvdata(pdev->dev.parent); |
285 | 274 | ||
286 | platform_set_drvdata(pdev, hwmon); | 275 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, "da9052", |
287 | 276 | hwmon, | |
288 | ret = sysfs_create_group(&pdev->dev.kobj, &da9052_attr_group); | 277 | da9052_groups); |
289 | if (ret) | 278 | return PTR_ERR_OR_ZERO(hwmon_dev); |
290 | goto err_mem; | ||
291 | |||
292 | hwmon->class_device = hwmon_device_register(&pdev->dev); | ||
293 | if (IS_ERR(hwmon->class_device)) { | ||
294 | ret = PTR_ERR(hwmon->class_device); | ||
295 | goto err_sysfs; | ||
296 | } | ||
297 | |||
298 | return 0; | ||
299 | |||
300 | err_sysfs: | ||
301 | sysfs_remove_group(&pdev->dev.kobj, &da9052_attr_group); | ||
302 | err_mem: | ||
303 | return ret; | ||
304 | } | ||
305 | |||
306 | static int da9052_hwmon_remove(struct platform_device *pdev) | ||
307 | { | ||
308 | struct da9052_hwmon *hwmon = platform_get_drvdata(pdev); | ||
309 | |||
310 | hwmon_device_unregister(hwmon->class_device); | ||
311 | sysfs_remove_group(&pdev->dev.kobj, &da9052_attr_group); | ||
312 | |||
313 | return 0; | ||
314 | } | 279 | } |
315 | 280 | ||
316 | static struct platform_driver da9052_hwmon_driver = { | 281 | static struct platform_driver da9052_hwmon_driver = { |
317 | .probe = da9052_hwmon_probe, | 282 | .probe = da9052_hwmon_probe, |
318 | .remove = da9052_hwmon_remove, | ||
319 | .driver = { | 283 | .driver = { |
320 | .name = "da9052-hwmon", | 284 | .name = "da9052-hwmon", |
321 | .owner = THIS_MODULE, | 285 | .owner = THIS_MODULE, |