diff options
author | Axel Lin <axel.lin@ingics.com> | 2014-06-17 11:12:08 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-08-04 10:01:34 -0400 |
commit | b3aabd6db3700dfa6ab334c96cbf16c04929b8a2 (patch) | |
tree | b4702123521bf151ba716ad260961aa2987aa104 /drivers/hwmon/wm8350-hwmon.c | |
parent | 9a70c97b218f5b78b3a265c3ba797b18fa36bd02 (diff) |
hwmon: (wm8350) 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>
Acked-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/wm8350-hwmon.c')
-rw-r--r-- | drivers/hwmon/wm8350-hwmon.c | 50 |
1 files changed, 7 insertions, 43 deletions
diff --git a/drivers/hwmon/wm8350-hwmon.c b/drivers/hwmon/wm8350-hwmon.c index 64bf75c9442b..90e3d918e597 100644 --- a/drivers/hwmon/wm8350-hwmon.c +++ b/drivers/hwmon/wm8350-hwmon.c | |||
@@ -28,19 +28,12 @@ | |||
28 | #include <linux/mfd/wm8350/core.h> | 28 | #include <linux/mfd/wm8350/core.h> |
29 | #include <linux/mfd/wm8350/comparator.h> | 29 | #include <linux/mfd/wm8350/comparator.h> |
30 | 30 | ||
31 | static ssize_t show_name(struct device *dev, | ||
32 | struct device_attribute *attr, char *buf) | ||
33 | { | ||
34 | return sprintf(buf, "wm8350\n"); | ||
35 | } | ||
36 | |||
37 | static const char * const input_names[] = { | 31 | static const char * const input_names[] = { |
38 | [WM8350_AUXADC_USB] = "USB", | 32 | [WM8350_AUXADC_USB] = "USB", |
39 | [WM8350_AUXADC_LINE] = "Line", | 33 | [WM8350_AUXADC_LINE] = "Line", |
40 | [WM8350_AUXADC_BATT] = "Battery", | 34 | [WM8350_AUXADC_BATT] = "Battery", |
41 | }; | 35 | }; |
42 | 36 | ||
43 | |||
44 | static ssize_t show_voltage(struct device *dev, | 37 | static ssize_t show_voltage(struct device *dev, |
45 | struct device_attribute *attr, char *buf) | 38 | struct device_attribute *attr, char *buf) |
46 | { | 39 | { |
@@ -68,15 +61,11 @@ static ssize_t show_label(struct device *dev, | |||
68 | static SENSOR_DEVICE_ATTR(in##id##_label, S_IRUGO, show_label, \ | 61 | static SENSOR_DEVICE_ATTR(in##id##_label, S_IRUGO, show_label, \ |
69 | NULL, name) | 62 | NULL, name) |
70 | 63 | ||
71 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | ||
72 | |||
73 | WM8350_NAMED_VOLTAGE(0, WM8350_AUXADC_USB); | 64 | WM8350_NAMED_VOLTAGE(0, WM8350_AUXADC_USB); |
74 | WM8350_NAMED_VOLTAGE(1, WM8350_AUXADC_BATT); | 65 | WM8350_NAMED_VOLTAGE(1, WM8350_AUXADC_BATT); |
75 | WM8350_NAMED_VOLTAGE(2, WM8350_AUXADC_LINE); | 66 | WM8350_NAMED_VOLTAGE(2, WM8350_AUXADC_LINE); |
76 | 67 | ||
77 | static struct attribute *wm8350_attributes[] = { | 68 | static struct attribute *wm8350_attrs[] = { |
78 | &dev_attr_name.attr, | ||
79 | |||
80 | &sensor_dev_attr_in0_input.dev_attr.attr, | 69 | &sensor_dev_attr_in0_input.dev_attr.attr, |
81 | &sensor_dev_attr_in0_label.dev_attr.attr, | 70 | &sensor_dev_attr_in0_label.dev_attr.attr, |
82 | &sensor_dev_attr_in1_input.dev_attr.attr, | 71 | &sensor_dev_attr_in1_input.dev_attr.attr, |
@@ -87,46 +76,21 @@ static struct attribute *wm8350_attributes[] = { | |||
87 | NULL, | 76 | NULL, |
88 | }; | 77 | }; |
89 | 78 | ||
90 | static const struct attribute_group wm8350_attr_group = { | 79 | ATTRIBUTE_GROUPS(wm8350); |
91 | .attrs = wm8350_attributes, | ||
92 | }; | ||
93 | 80 | ||
94 | static int wm8350_hwmon_probe(struct platform_device *pdev) | 81 | static int wm8350_hwmon_probe(struct platform_device *pdev) |
95 | { | 82 | { |
96 | struct wm8350 *wm8350 = platform_get_drvdata(pdev); | 83 | struct wm8350 *wm8350 = platform_get_drvdata(pdev); |
97 | int ret; | 84 | struct device *hwmon_dev; |
98 | |||
99 | ret = sysfs_create_group(&pdev->dev.kobj, &wm8350_attr_group); | ||
100 | if (ret) | ||
101 | goto err; | ||
102 | |||
103 | wm8350->hwmon.classdev = hwmon_device_register(&pdev->dev); | ||
104 | if (IS_ERR(wm8350->hwmon.classdev)) { | ||
105 | ret = PTR_ERR(wm8350->hwmon.classdev); | ||
106 | goto err_group; | ||
107 | } | ||
108 | |||
109 | return 0; | ||
110 | |||
111 | err_group: | ||
112 | sysfs_remove_group(&pdev->dev.kobj, &wm8350_attr_group); | ||
113 | err: | ||
114 | return ret; | ||
115 | } | ||
116 | |||
117 | static int wm8350_hwmon_remove(struct platform_device *pdev) | ||
118 | { | ||
119 | struct wm8350 *wm8350 = platform_get_drvdata(pdev); | ||
120 | |||
121 | hwmon_device_unregister(wm8350->hwmon.classdev); | ||
122 | sysfs_remove_group(&pdev->dev.kobj, &wm8350_attr_group); | ||
123 | 85 | ||
124 | return 0; | 86 | hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev, "wm8350", |
87 | wm8350, | ||
88 | wm8350_groups); | ||
89 | return PTR_ERR_OR_ZERO(hwmon_dev); | ||
125 | } | 90 | } |
126 | 91 | ||
127 | static struct platform_driver wm8350_hwmon_driver = { | 92 | static struct platform_driver wm8350_hwmon_driver = { |
128 | .probe = wm8350_hwmon_probe, | 93 | .probe = wm8350_hwmon_probe, |
129 | .remove = wm8350_hwmon_remove, | ||
130 | .driver = { | 94 | .driver = { |
131 | .name = "wm8350-hwmon", | 95 | .name = "wm8350-hwmon", |
132 | .owner = THIS_MODULE, | 96 | .owner = THIS_MODULE, |