diff options
author | Guenter Roeck <linux@roeck-us.net> | 2013-12-01 22:33:16 -0500 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-03-03 11:01:03 -0500 |
commit | 4b49cca36ee9bb8e043cb76e23b1c2864e3bbc86 (patch) | |
tree | 43bd20754dee55439b139635cc51962046eadd2c /drivers/hwmon/iio_hwmon.c | |
parent | f809621e8c36c15e9caf248dabe441ac25507e62 (diff) |
hwmon: (iio_hwmon) Convert to use hwmon_device_register_with_groups
Simplify code and create name attribute automatically.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/iio_hwmon.c')
-rw-r--r-- | drivers/hwmon/iio_hwmon.c | 37 |
1 files changed, 12 insertions, 25 deletions
diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c index 708081b68c6f..9fbb1b1fdff3 100644 --- a/drivers/hwmon/iio_hwmon.c +++ b/drivers/hwmon/iio_hwmon.c | |||
@@ -31,6 +31,7 @@ struct iio_hwmon_state { | |||
31 | int num_channels; | 31 | int num_channels; |
32 | struct device *hwmon_dev; | 32 | struct device *hwmon_dev; |
33 | struct attribute_group attr_group; | 33 | struct attribute_group attr_group; |
34 | const struct attribute_group *groups[2]; | ||
34 | struct attribute **attrs; | 35 | struct attribute **attrs; |
35 | }; | 36 | }; |
36 | 37 | ||
@@ -56,19 +57,6 @@ static ssize_t iio_hwmon_read_val(struct device *dev, | |||
56 | return sprintf(buf, "%d\n", result); | 57 | return sprintf(buf, "%d\n", result); |
57 | } | 58 | } |
58 | 59 | ||
59 | static ssize_t show_name(struct device *dev, struct device_attribute *attr, | ||
60 | char *buf) | ||
61 | { | ||
62 | const char *name = "iio_hwmon"; | ||
63 | |||
64 | if (dev->of_node && dev->of_node->name) | ||
65 | name = dev->of_node->name; | ||
66 | |||
67 | return sprintf(buf, "%s\n", name); | ||
68 | } | ||
69 | |||
70 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | ||
71 | |||
72 | static int iio_hwmon_probe(struct platform_device *pdev) | 60 | static int iio_hwmon_probe(struct platform_device *pdev) |
73 | { | 61 | { |
74 | struct device *dev = &pdev->dev; | 62 | struct device *dev = &pdev->dev; |
@@ -78,6 +66,10 @@ static int iio_hwmon_probe(struct platform_device *pdev) | |||
78 | int in_i = 1, temp_i = 1, curr_i = 1; | 66 | int in_i = 1, temp_i = 1, curr_i = 1; |
79 | enum iio_chan_type type; | 67 | enum iio_chan_type type; |
80 | struct iio_channel *channels; | 68 | struct iio_channel *channels; |
69 | const char *name = "iio_hwmon"; | ||
70 | |||
71 | if (dev->of_node && dev->of_node->name) | ||
72 | name = dev->of_node->name; | ||
81 | 73 | ||
82 | channels = iio_channel_get_all(dev); | 74 | channels = iio_channel_get_all(dev); |
83 | if (IS_ERR(channels)) | 75 | if (IS_ERR(channels)) |
@@ -96,7 +88,7 @@ static int iio_hwmon_probe(struct platform_device *pdev) | |||
96 | st->num_channels++; | 88 | st->num_channels++; |
97 | 89 | ||
98 | st->attrs = devm_kzalloc(dev, | 90 | st->attrs = devm_kzalloc(dev, |
99 | sizeof(*st->attrs) * (st->num_channels + 2), | 91 | sizeof(*st->attrs) * (st->num_channels + 1), |
100 | GFP_KERNEL); | 92 | GFP_KERNEL); |
101 | if (st->attrs == NULL) { | 93 | if (st->attrs == NULL) { |
102 | ret = -ENOMEM; | 94 | ret = -ENOMEM; |
@@ -144,22 +136,18 @@ static int iio_hwmon_probe(struct platform_device *pdev) | |||
144 | a->index = i; | 136 | a->index = i; |
145 | st->attrs[i] = &a->dev_attr.attr; | 137 | st->attrs[i] = &a->dev_attr.attr; |
146 | } | 138 | } |
147 | st->attrs[st->num_channels] = &dev_attr_name.attr; | ||
148 | st->attr_group.attrs = st->attrs; | ||
149 | platform_set_drvdata(pdev, st); | ||
150 | ret = sysfs_create_group(&dev->kobj, &st->attr_group); | ||
151 | if (ret < 0) | ||
152 | goto error_release_channels; | ||
153 | 139 | ||
154 | st->hwmon_dev = hwmon_device_register(dev); | 140 | st->attr_group.attrs = st->attrs; |
141 | st->groups[0] = &st->attr_group; | ||
142 | st->hwmon_dev = hwmon_device_register_with_groups(dev, name, st, | ||
143 | st->groups); | ||
155 | if (IS_ERR(st->hwmon_dev)) { | 144 | if (IS_ERR(st->hwmon_dev)) { |
156 | ret = PTR_ERR(st->hwmon_dev); | 145 | ret = PTR_ERR(st->hwmon_dev); |
157 | goto error_remove_group; | 146 | goto error_release_channels; |
158 | } | 147 | } |
148 | platform_set_drvdata(pdev, st); | ||
159 | return 0; | 149 | return 0; |
160 | 150 | ||
161 | error_remove_group: | ||
162 | sysfs_remove_group(&dev->kobj, &st->attr_group); | ||
163 | error_release_channels: | 151 | error_release_channels: |
164 | iio_channel_release_all(channels); | 152 | iio_channel_release_all(channels); |
165 | return ret; | 153 | return ret; |
@@ -170,7 +158,6 @@ static int iio_hwmon_remove(struct platform_device *pdev) | |||
170 | struct iio_hwmon_state *st = platform_get_drvdata(pdev); | 158 | struct iio_hwmon_state *st = platform_get_drvdata(pdev); |
171 | 159 | ||
172 | hwmon_device_unregister(st->hwmon_dev); | 160 | hwmon_device_unregister(st->hwmon_dev); |
173 | sysfs_remove_group(&pdev->dev.kobj, &st->attr_group); | ||
174 | iio_channel_release_all(st->channels); | 161 | iio_channel_release_all(st->channels); |
175 | 162 | ||
176 | return 0; | 163 | return 0; |