aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorPawel Moll <pawel.moll@arm.com>2014-06-12 10:14:33 -0400
committerGuenter Roeck <linux@roeck-us.net>2014-06-12 11:36:50 -0400
commit78cebd0889c7b8b92f43e7667efc16636b858c34 (patch)
treeae6678e21252841a29edfebd011297d19edc3fe0 /drivers/hwmon
parent8dea1b4e7726faf19b66d70f9f3737e85ef04a36 (diff)
hwmon: vexpress: Use devm helper for hwmon device registration
Use devm_hwmon_device_register_with_groups instead of the old-style manual attributes and hwmon device registration. Also, unroll the attribute group macros for better code readability. Signed-off-by: Pawel Moll <pawel.moll@arm.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/vexpress.c82
1 files changed, 28 insertions, 54 deletions
diff --git a/drivers/hwmon/vexpress.c b/drivers/hwmon/vexpress.c
index 611f34c7333d..c53619086f33 100644
--- a/drivers/hwmon/vexpress.c
+++ b/drivers/hwmon/vexpress.c
@@ -27,17 +27,8 @@
27struct vexpress_hwmon_data { 27struct vexpress_hwmon_data {
28 struct device *hwmon_dev; 28 struct device *hwmon_dev;
29 struct regmap *reg; 29 struct regmap *reg;
30 const char *name;
31}; 30};
32 31
33static ssize_t vexpress_hwmon_name_show(struct device *dev,
34 struct device_attribute *dev_attr, char *buffer)
35{
36 struct vexpress_hwmon_data *data = dev_get_drvdata(dev);
37
38 return sprintf(buffer, "%s\n", data->name);
39}
40
41static ssize_t vexpress_hwmon_label_show(struct device *dev, 32static ssize_t vexpress_hwmon_label_show(struct device *dev,
42 struct device_attribute *dev_attr, char *buffer) 33 struct device_attribute *dev_attr, char *buffer)
43{ 34{
@@ -95,16 +86,6 @@ static umode_t vexpress_hwmon_attr_is_visible(struct kobject *kobj,
95 return attr->mode; 86 return attr->mode;
96} 87}
97 88
98static DEVICE_ATTR(name, S_IRUGO, vexpress_hwmon_name_show, NULL);
99
100#define VEXPRESS_HWMON_ATTRS(_name, _label_attr, _input_attr) \
101struct attribute *vexpress_hwmon_attrs_##_name[] = { \
102 &dev_attr_name.attr, \
103 &dev_attr_##_label_attr.attr, \
104 &sensor_dev_attr_##_input_attr.dev_attr.attr, \
105 NULL \
106}
107
108struct vexpress_hwmon_type { 89struct vexpress_hwmon_type {
109 const char *name; 90 const char *name;
110 const struct attribute_group **attr_groups; 91 const struct attribute_group **attr_groups;
@@ -114,7 +95,11 @@ struct vexpress_hwmon_type {
114static DEVICE_ATTR(in1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); 95static DEVICE_ATTR(in1_label, S_IRUGO, vexpress_hwmon_label_show, NULL);
115static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, vexpress_hwmon_u32_show, 96static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, vexpress_hwmon_u32_show,
116 NULL, 1000); 97 NULL, 1000);
117static VEXPRESS_HWMON_ATTRS(volt, in1_label, in1_input); 98static struct attribute *vexpress_hwmon_attrs_volt[] = {
99 &dev_attr_in1_label.attr,
100 &sensor_dev_attr_in1_input.dev_attr.attr,
101 NULL
102};
118static struct attribute_group vexpress_hwmon_group_volt = { 103static struct attribute_group vexpress_hwmon_group_volt = {
119 .is_visible = vexpress_hwmon_attr_is_visible, 104 .is_visible = vexpress_hwmon_attr_is_visible,
120 .attrs = vexpress_hwmon_attrs_volt, 105 .attrs = vexpress_hwmon_attrs_volt,
@@ -131,7 +116,11 @@ static struct vexpress_hwmon_type vexpress_hwmon_volt = {
131static DEVICE_ATTR(curr1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); 116static DEVICE_ATTR(curr1_label, S_IRUGO, vexpress_hwmon_label_show, NULL);
132static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, vexpress_hwmon_u32_show, 117static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, vexpress_hwmon_u32_show,
133 NULL, 1000); 118 NULL, 1000);
134static VEXPRESS_HWMON_ATTRS(amp, curr1_label, curr1_input); 119static struct attribute *vexpress_hwmon_attrs_amp[] = {
120 &dev_attr_curr1_label.attr,
121 &sensor_dev_attr_curr1_input.dev_attr.attr,
122 NULL
123};
135static struct attribute_group vexpress_hwmon_group_amp = { 124static struct attribute_group vexpress_hwmon_group_amp = {
136 .is_visible = vexpress_hwmon_attr_is_visible, 125 .is_visible = vexpress_hwmon_attr_is_visible,
137 .attrs = vexpress_hwmon_attrs_amp, 126 .attrs = vexpress_hwmon_attrs_amp,
@@ -147,7 +136,11 @@ static struct vexpress_hwmon_type vexpress_hwmon_amp = {
147static DEVICE_ATTR(temp1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); 136static DEVICE_ATTR(temp1_label, S_IRUGO, vexpress_hwmon_label_show, NULL);
148static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, vexpress_hwmon_u32_show, 137static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, vexpress_hwmon_u32_show,
149 NULL, 1000); 138 NULL, 1000);
150static VEXPRESS_HWMON_ATTRS(temp, temp1_label, temp1_input); 139static struct attribute *vexpress_hwmon_attrs_temp[] = {
140 &dev_attr_temp1_label.attr,
141 &sensor_dev_attr_temp1_input.dev_attr.attr,
142 NULL
143};
151static struct attribute_group vexpress_hwmon_group_temp = { 144static struct attribute_group vexpress_hwmon_group_temp = {
152 .is_visible = vexpress_hwmon_attr_is_visible, 145 .is_visible = vexpress_hwmon_attr_is_visible,
153 .attrs = vexpress_hwmon_attrs_temp, 146 .attrs = vexpress_hwmon_attrs_temp,
@@ -163,7 +156,11 @@ static struct vexpress_hwmon_type vexpress_hwmon_temp = {
163static DEVICE_ATTR(power1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); 156static DEVICE_ATTR(power1_label, S_IRUGO, vexpress_hwmon_label_show, NULL);
164static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO, vexpress_hwmon_u32_show, 157static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO, vexpress_hwmon_u32_show,
165 NULL, 1); 158 NULL, 1);
166static VEXPRESS_HWMON_ATTRS(power, power1_label, power1_input); 159static struct attribute *vexpress_hwmon_attrs_power[] = {
160 &dev_attr_power1_label.attr,
161 &sensor_dev_attr_power1_input.dev_attr.attr,
162 NULL
163};
167static struct attribute_group vexpress_hwmon_group_power = { 164static struct attribute_group vexpress_hwmon_group_power = {
168 .is_visible = vexpress_hwmon_attr_is_visible, 165 .is_visible = vexpress_hwmon_attr_is_visible,
169 .attrs = vexpress_hwmon_attrs_power, 166 .attrs = vexpress_hwmon_attrs_power,
@@ -179,7 +176,11 @@ static struct vexpress_hwmon_type vexpress_hwmon_power = {
179static DEVICE_ATTR(energy1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); 176static DEVICE_ATTR(energy1_label, S_IRUGO, vexpress_hwmon_label_show, NULL);
180static SENSOR_DEVICE_ATTR(energy1_input, S_IRUGO, vexpress_hwmon_u64_show, 177static SENSOR_DEVICE_ATTR(energy1_input, S_IRUGO, vexpress_hwmon_u64_show,
181 NULL, 1); 178 NULL, 1);
182static VEXPRESS_HWMON_ATTRS(energy, energy1_label, energy1_input); 179static struct attribute *vexpress_hwmon_attrs_energy[] = {
180 &dev_attr_energy1_label.attr,
181 &sensor_dev_attr_energy1_input.dev_attr.attr,
182 NULL
183};
183static struct attribute_group vexpress_hwmon_group_energy = { 184static struct attribute_group vexpress_hwmon_group_energy = {
184 .is_visible = vexpress_hwmon_attr_is_visible, 185 .is_visible = vexpress_hwmon_attr_is_visible,
185 .attrs = vexpress_hwmon_attrs_energy, 186 .attrs = vexpress_hwmon_attrs_energy,
@@ -218,7 +219,6 @@ MODULE_DEVICE_TABLE(of, vexpress_hwmon_of_match);
218 219
219static int vexpress_hwmon_probe(struct platform_device *pdev) 220static int vexpress_hwmon_probe(struct platform_device *pdev)
220{ 221{
221 int err;
222 const struct of_device_id *match; 222 const struct of_device_id *match;
223 struct vexpress_hwmon_data *data; 223 struct vexpress_hwmon_data *data;
224 const struct vexpress_hwmon_type *type; 224 const struct vexpress_hwmon_type *type;
@@ -232,45 +232,19 @@ static int vexpress_hwmon_probe(struct platform_device *pdev)
232 if (!match) 232 if (!match)
233 return -ENODEV; 233 return -ENODEV;
234 type = match->data; 234 type = match->data;
235 data->name = type->name;
236 235
237 data->reg = devm_regmap_init_vexpress_config(&pdev->dev); 236 data->reg = devm_regmap_init_vexpress_config(&pdev->dev);
238 if (IS_ERR(data->reg)) 237 if (IS_ERR(data->reg))
239 return PTR_ERR(data->reg); 238 return PTR_ERR(data->reg);
240 239
241 err = sysfs_create_groups(&pdev->dev.kobj, type->attr_groups); 240 data->hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev,
242 if (err) 241 type->name, data, type->attr_groups);
243 goto error;
244
245 data->hwmon_dev = hwmon_device_register(&pdev->dev);
246 if (IS_ERR(data->hwmon_dev)) {
247 err = PTR_ERR(data->hwmon_dev);
248 goto error;
249 }
250
251 return 0;
252
253error:
254 sysfs_remove_group(&pdev->dev.kobj, match->data);
255 return err;
256}
257
258static int vexpress_hwmon_remove(struct platform_device *pdev)
259{
260 struct vexpress_hwmon_data *data = platform_get_drvdata(pdev);
261 const struct of_device_id *match;
262
263 hwmon_device_unregister(data->hwmon_dev);
264
265 match = of_match_device(vexpress_hwmon_of_match, &pdev->dev);
266 sysfs_remove_group(&pdev->dev.kobj, match->data);
267 242
268 return 0; 243 return PTR_ERR_OR_ZERO(data->hwmon_dev);
269} 244}
270 245
271static struct platform_driver vexpress_hwmon_driver = { 246static struct platform_driver vexpress_hwmon_driver = {
272 .probe = vexpress_hwmon_probe, 247 .probe = vexpress_hwmon_probe,
273 .remove = vexpress_hwmon_remove,
274 .driver = { 248 .driver = {
275 .name = DRVNAME, 249 .name = DRVNAME,
276 .owner = THIS_MODULE, 250 .owner = THIS_MODULE,