diff options
author | Axel Lin <axel.lin@ingics.com> | 2014-07-08 21:25:12 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-09-22 14:14:51 -0400 |
commit | e7d275e7619510314dbb9207896bb12074d71c81 (patch) | |
tree | 4163b90598737793e7dbd0f73fc03d18ddab8242 /drivers/hwmon/da9055-hwmon.c | |
parent | 8e35762fd5f2b074cff3e5c176c80008c70cc8f3 (diff) |
hwmon: (da9055) 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>
Diffstat (limited to 'drivers/hwmon/da9055-hwmon.c')
-rw-r--r-- | drivers/hwmon/da9055-hwmon.c | 52 |
1 files changed, 9 insertions, 43 deletions
diff --git a/drivers/hwmon/da9055-hwmon.c b/drivers/hwmon/da9055-hwmon.c index 35eb7738d711..9916a3fb4bb9 100644 --- a/drivers/hwmon/da9055-hwmon.c +++ b/drivers/hwmon/da9055-hwmon.c | |||
@@ -36,7 +36,6 @@ | |||
36 | 36 | ||
37 | struct da9055_hwmon { | 37 | struct da9055_hwmon { |
38 | struct da9055 *da9055; | 38 | struct da9055 *da9055; |
39 | struct device *class_device; | ||
40 | struct mutex hwmon_lock; | 39 | struct mutex hwmon_lock; |
41 | struct mutex irq_lock; | 40 | struct mutex irq_lock; |
42 | struct completion done; | 41 | struct completion done; |
@@ -200,13 +199,6 @@ static ssize_t da9055_read_tjunc(struct device *dev, | |||
200 | + 3076332, 10000)); | 199 | + 3076332, 10000)); |
201 | } | 200 | } |
202 | 201 | ||
203 | static ssize_t da9055_hwmon_show_name(struct device *dev, | ||
204 | struct device_attribute *devattr, | ||
205 | char *buf) | ||
206 | { | ||
207 | return sprintf(buf, "da9055\n"); | ||
208 | } | ||
209 | |||
210 | static ssize_t show_label(struct device *dev, | 202 | static ssize_t show_label(struct device *dev, |
211 | struct device_attribute *devattr, char *buf) | 203 | struct device_attribute *devattr, char *buf) |
212 | { | 204 | { |
@@ -236,10 +228,7 @@ static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, da9055_read_tjunc, NULL, | |||
236 | static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, show_label, NULL, | 228 | static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, show_label, NULL, |
237 | DA9055_ADC_TJUNC); | 229 | DA9055_ADC_TJUNC); |
238 | 230 | ||
239 | static DEVICE_ATTR(name, S_IRUGO, da9055_hwmon_show_name, NULL); | 231 | static struct attribute *da9055_attrs[] = { |
240 | |||
241 | static struct attribute *da9055_attr[] = { | ||
242 | &dev_attr_name.attr, | ||
243 | &sensor_dev_attr_in0_input.dev_attr.attr, | 232 | &sensor_dev_attr_in0_input.dev_attr.attr, |
244 | &sensor_dev_attr_in0_label.dev_attr.attr, | 233 | &sensor_dev_attr_in0_label.dev_attr.attr, |
245 | &sensor_dev_attr_in1_input.dev_attr.attr, | 234 | &sensor_dev_attr_in1_input.dev_attr.attr, |
@@ -254,15 +243,16 @@ static struct attribute *da9055_attr[] = { | |||
254 | NULL | 243 | NULL |
255 | }; | 244 | }; |
256 | 245 | ||
257 | static const struct attribute_group da9055_attr_group = {.attrs = da9055_attr}; | 246 | ATTRIBUTE_GROUPS(da9055); |
258 | 247 | ||
259 | static int da9055_hwmon_probe(struct platform_device *pdev) | 248 | static int da9055_hwmon_probe(struct platform_device *pdev) |
260 | { | 249 | { |
250 | struct device *dev = &pdev->dev; | ||
261 | struct da9055_hwmon *hwmon; | 251 | struct da9055_hwmon *hwmon; |
252 | struct device *hwmon_dev; | ||
262 | int hwmon_irq, ret; | 253 | int hwmon_irq, ret; |
263 | 254 | ||
264 | hwmon = devm_kzalloc(&pdev->dev, sizeof(struct da9055_hwmon), | 255 | hwmon = devm_kzalloc(dev, sizeof(struct da9055_hwmon), GFP_KERNEL); |
265 | GFP_KERNEL); | ||
266 | if (!hwmon) | 256 | if (!hwmon) |
267 | return -ENOMEM; | 257 | return -ENOMEM; |
268 | 258 | ||
@@ -272,8 +262,6 @@ static int da9055_hwmon_probe(struct platform_device *pdev) | |||
272 | init_completion(&hwmon->done); | 262 | init_completion(&hwmon->done); |
273 | hwmon->da9055 = dev_get_drvdata(pdev->dev.parent); | 263 | hwmon->da9055 = dev_get_drvdata(pdev->dev.parent); |
274 | 264 | ||
275 | platform_set_drvdata(pdev, hwmon); | ||
276 | |||
277 | hwmon_irq = platform_get_irq_byname(pdev, "HWMON"); | 265 | hwmon_irq = platform_get_irq_byname(pdev, "HWMON"); |
278 | if (hwmon_irq < 0) | 266 | if (hwmon_irq < 0) |
279 | return hwmon_irq; | 267 | return hwmon_irq; |
@@ -288,36 +276,14 @@ static int da9055_hwmon_probe(struct platform_device *pdev) | |||
288 | return ret; | 276 | return ret; |
289 | } | 277 | } |
290 | 278 | ||
291 | ret = sysfs_create_group(&pdev->dev.kobj, &da9055_attr_group); | 279 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, "da9055", |
292 | if (ret) | 280 | hwmon, |
293 | return ret; | 281 | da9055_groups); |
294 | 282 | return PTR_ERR_OR_ZERO(hwmon_dev); | |
295 | hwmon->class_device = hwmon_device_register(&pdev->dev); | ||
296 | if (IS_ERR(hwmon->class_device)) { | ||
297 | ret = PTR_ERR(hwmon->class_device); | ||
298 | goto err; | ||
299 | } | ||
300 | |||
301 | return 0; | ||
302 | |||
303 | err: | ||
304 | sysfs_remove_group(&pdev->dev.kobj, &da9055_attr_group); | ||
305 | return ret; | ||
306 | } | ||
307 | |||
308 | static int da9055_hwmon_remove(struct platform_device *pdev) | ||
309 | { | ||
310 | struct da9055_hwmon *hwmon = platform_get_drvdata(pdev); | ||
311 | |||
312 | sysfs_remove_group(&pdev->dev.kobj, &da9055_attr_group); | ||
313 | hwmon_device_unregister(hwmon->class_device); | ||
314 | |||
315 | return 0; | ||
316 | } | 283 | } |
317 | 284 | ||
318 | static struct platform_driver da9055_hwmon_driver = { | 285 | static struct platform_driver da9055_hwmon_driver = { |
319 | .probe = da9055_hwmon_probe, | 286 | .probe = da9055_hwmon_probe, |
320 | .remove = da9055_hwmon_remove, | ||
321 | .driver = { | 287 | .driver = { |
322 | .name = "da9055-hwmon", | 288 | .name = "da9055-hwmon", |
323 | .owner = THIS_MODULE, | 289 | .owner = THIS_MODULE, |