diff options
author | Axel Lin <axel.lin@ingics.com> | 2014-06-17 11:10:55 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-08-04 10:01:34 -0400 |
commit | 9a70c97b218f5b78b3a265c3ba797b18fa36bd02 (patch) | |
tree | 860eac7a01f35bf9ceb3ff07a9720965906ea08d /drivers/hwmon/wm831x-hwmon.c | |
parent | f82b2c344994f23c003c967fb833d1a0d7b2527f (diff) |
hwmon: (wm831x) 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/wm831x-hwmon.c')
-rw-r--r-- | drivers/hwmon/wm831x-hwmon.c | 72 |
1 files changed, 11 insertions, 61 deletions
diff --git a/drivers/hwmon/wm831x-hwmon.c b/drivers/hwmon/wm831x-hwmon.c index df6ceaf8d58a..3e6a3195cd11 100644 --- a/drivers/hwmon/wm831x-hwmon.c +++ b/drivers/hwmon/wm831x-hwmon.c | |||
@@ -29,17 +29,6 @@ | |||
29 | #include <linux/mfd/wm831x/core.h> | 29 | #include <linux/mfd/wm831x/core.h> |
30 | #include <linux/mfd/wm831x/auxadc.h> | 30 | #include <linux/mfd/wm831x/auxadc.h> |
31 | 31 | ||
32 | struct wm831x_hwmon { | ||
33 | struct wm831x *wm831x; | ||
34 | struct device *classdev; | ||
35 | }; | ||
36 | |||
37 | static ssize_t show_name(struct device *dev, | ||
38 | struct device_attribute *attr, char *buf) | ||
39 | { | ||
40 | return sprintf(buf, "wm831x\n"); | ||
41 | } | ||
42 | |||
43 | static const char * const input_names[] = { | 32 | static const char * const input_names[] = { |
44 | [WM831X_AUX_SYSVDD] = "SYSVDD", | 33 | [WM831X_AUX_SYSVDD] = "SYSVDD", |
45 | [WM831X_AUX_USB] = "USB", | 34 | [WM831X_AUX_USB] = "USB", |
@@ -50,15 +39,14 @@ static const char * const input_names[] = { | |||
50 | [WM831X_AUX_BATT_TEMP] = "Battery", | 39 | [WM831X_AUX_BATT_TEMP] = "Battery", |
51 | }; | 40 | }; |
52 | 41 | ||
53 | |||
54 | static ssize_t show_voltage(struct device *dev, | 42 | static ssize_t show_voltage(struct device *dev, |
55 | struct device_attribute *attr, char *buf) | 43 | struct device_attribute *attr, char *buf) |
56 | { | 44 | { |
57 | struct wm831x_hwmon *hwmon = dev_get_drvdata(dev); | 45 | struct wm831x *wm831x = dev_get_drvdata(dev); |
58 | int channel = to_sensor_dev_attr(attr)->index; | 46 | int channel = to_sensor_dev_attr(attr)->index; |
59 | int ret; | 47 | int ret; |
60 | 48 | ||
61 | ret = wm831x_auxadc_read_uv(hwmon->wm831x, channel); | 49 | ret = wm831x_auxadc_read_uv(wm831x, channel); |
62 | if (ret < 0) | 50 | if (ret < 0) |
63 | return ret; | 51 | return ret; |
64 | 52 | ||
@@ -68,11 +56,11 @@ static ssize_t show_voltage(struct device *dev, | |||
68 | static ssize_t show_chip_temp(struct device *dev, | 56 | static ssize_t show_chip_temp(struct device *dev, |
69 | struct device_attribute *attr, char *buf) | 57 | struct device_attribute *attr, char *buf) |
70 | { | 58 | { |
71 | struct wm831x_hwmon *hwmon = dev_get_drvdata(dev); | 59 | struct wm831x *wm831x = dev_get_drvdata(dev); |
72 | int channel = to_sensor_dev_attr(attr)->index; | 60 | int channel = to_sensor_dev_attr(attr)->index; |
73 | int ret; | 61 | int ret; |
74 | 62 | ||
75 | ret = wm831x_auxadc_read(hwmon->wm831x, channel); | 63 | ret = wm831x_auxadc_read(wm831x, channel); |
76 | if (ret < 0) | 64 | if (ret < 0) |
77 | return ret; | 65 | return ret; |
78 | 66 | ||
@@ -100,8 +88,6 @@ static ssize_t show_label(struct device *dev, | |||
100 | static SENSOR_DEVICE_ATTR(in##id##_label, S_IRUGO, show_label, \ | 88 | static SENSOR_DEVICE_ATTR(in##id##_label, S_IRUGO, show_label, \ |
101 | NULL, name) | 89 | NULL, name) |
102 | 90 | ||
103 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | ||
104 | |||
105 | WM831X_VOLTAGE(0, WM831X_AUX_AUX1); | 91 | WM831X_VOLTAGE(0, WM831X_AUX_AUX1); |
106 | WM831X_VOLTAGE(1, WM831X_AUX_AUX2); | 92 | WM831X_VOLTAGE(1, WM831X_AUX_AUX2); |
107 | WM831X_VOLTAGE(2, WM831X_AUX_AUX3); | 93 | WM831X_VOLTAGE(2, WM831X_AUX_AUX3); |
@@ -126,9 +112,7 @@ static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_voltage, NULL, | |||
126 | static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, show_label, NULL, | 112 | static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, show_label, NULL, |
127 | WM831X_AUX_BATT_TEMP); | 113 | WM831X_AUX_BATT_TEMP); |
128 | 114 | ||
129 | static struct attribute *wm831x_attributes[] = { | 115 | static struct attribute *wm831x_attrs[] = { |
130 | &dev_attr_name.attr, | ||
131 | |||
132 | &sensor_dev_attr_in0_input.dev_attr.attr, | 116 | &sensor_dev_attr_in0_input.dev_attr.attr, |
133 | &sensor_dev_attr_in1_input.dev_attr.attr, | 117 | &sensor_dev_attr_in1_input.dev_attr.attr, |
134 | &sensor_dev_attr_in2_input.dev_attr.attr, | 118 | &sensor_dev_attr_in2_input.dev_attr.attr, |
@@ -153,55 +137,21 @@ static struct attribute *wm831x_attributes[] = { | |||
153 | NULL | 137 | NULL |
154 | }; | 138 | }; |
155 | 139 | ||
156 | static const struct attribute_group wm831x_attr_group = { | 140 | ATTRIBUTE_GROUPS(wm831x); |
157 | .attrs = wm831x_attributes, | ||
158 | }; | ||
159 | 141 | ||
160 | static int wm831x_hwmon_probe(struct platform_device *pdev) | 142 | static int wm831x_hwmon_probe(struct platform_device *pdev) |
161 | { | 143 | { |
162 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); | 144 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); |
163 | struct wm831x_hwmon *hwmon; | 145 | struct device *hwmon_dev; |
164 | int ret; | ||
165 | |||
166 | hwmon = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_hwmon), | ||
167 | GFP_KERNEL); | ||
168 | if (!hwmon) | ||
169 | return -ENOMEM; | ||
170 | |||
171 | hwmon->wm831x = wm831x; | ||
172 | |||
173 | ret = sysfs_create_group(&pdev->dev.kobj, &wm831x_attr_group); | ||
174 | if (ret) | ||
175 | return ret; | ||
176 | |||
177 | hwmon->classdev = hwmon_device_register(&pdev->dev); | ||
178 | if (IS_ERR(hwmon->classdev)) { | ||
179 | ret = PTR_ERR(hwmon->classdev); | ||
180 | goto err_sysfs; | ||
181 | } | ||
182 | |||
183 | platform_set_drvdata(pdev, hwmon); | ||
184 | |||
185 | return 0; | ||
186 | |||
187 | err_sysfs: | ||
188 | sysfs_remove_group(&pdev->dev.kobj, &wm831x_attr_group); | ||
189 | return ret; | ||
190 | } | ||
191 | |||
192 | static int wm831x_hwmon_remove(struct platform_device *pdev) | ||
193 | { | ||
194 | struct wm831x_hwmon *hwmon = platform_get_drvdata(pdev); | ||
195 | |||
196 | hwmon_device_unregister(hwmon->classdev); | ||
197 | sysfs_remove_group(&pdev->dev.kobj, &wm831x_attr_group); | ||
198 | 146 | ||
199 | return 0; | 147 | hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev, "wm831x", |
148 | wm831x, | ||
149 | wm831x_groups); | ||
150 | return PTR_ERR_OR_ZERO(hwmon_dev); | ||
200 | } | 151 | } |
201 | 152 | ||
202 | static struct platform_driver wm831x_hwmon_driver = { | 153 | static struct platform_driver wm831x_hwmon_driver = { |
203 | .probe = wm831x_hwmon_probe, | 154 | .probe = wm831x_hwmon_probe, |
204 | .remove = wm831x_hwmon_remove, | ||
205 | .driver = { | 155 | .driver = { |
206 | .name = "wm831x-hwmon", | 156 | .name = "wm831x-hwmon", |
207 | .owner = THIS_MODULE, | 157 | .owner = THIS_MODULE, |