diff options
author | Axel Lin <axel.lin@ingics.com> | 2014-07-02 08:31:21 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2016-06-27 21:58:03 -0400 |
commit | 68f86c75ca1eaf790907eb43c68f9f2996474116 (patch) | |
tree | 0cc5464060e29986ba96fb99745206a6a6709113 /drivers/hwmon/ads7871.c | |
parent | 699f279d998cf95809babc987abd4a409eada5b2 (diff) |
hwmon: (ads7871) 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.
The update_lock mutex is not used, so remove it.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/ads7871.c')
-rw-r--r-- | drivers/hwmon/ads7871.c | 65 |
1 files changed, 15 insertions, 50 deletions
diff --git a/drivers/hwmon/ads7871.c b/drivers/hwmon/ads7871.c index 4fd9e4de1972..59bd7b9e1772 100644 --- a/drivers/hwmon/ads7871.c +++ b/drivers/hwmon/ads7871.c | |||
@@ -66,14 +66,12 @@ | |||
66 | #include <linux/hwmon.h> | 66 | #include <linux/hwmon.h> |
67 | #include <linux/hwmon-sysfs.h> | 67 | #include <linux/hwmon-sysfs.h> |
68 | #include <linux/err.h> | 68 | #include <linux/err.h> |
69 | #include <linux/mutex.h> | ||
70 | #include <linux/delay.h> | 69 | #include <linux/delay.h> |
71 | 70 | ||
72 | #define DEVICE_NAME "ads7871" | 71 | #define DEVICE_NAME "ads7871" |
73 | 72 | ||
74 | struct ads7871_data { | 73 | struct ads7871_data { |
75 | struct device *hwmon_dev; | 74 | struct spi_device *spi; |
76 | struct mutex update_lock; | ||
77 | }; | 75 | }; |
78 | 76 | ||
79 | static int ads7871_read_reg8(struct spi_device *spi, int reg) | 77 | static int ads7871_read_reg8(struct spi_device *spi, int reg) |
@@ -101,7 +99,8 @@ static int ads7871_write_reg8(struct spi_device *spi, int reg, u8 val) | |||
101 | static ssize_t show_voltage(struct device *dev, | 99 | static ssize_t show_voltage(struct device *dev, |
102 | struct device_attribute *da, char *buf) | 100 | struct device_attribute *da, char *buf) |
103 | { | 101 | { |
104 | struct spi_device *spi = to_spi_device(dev); | 102 | struct ads7871_data *pdata = dev_get_drvdata(dev); |
103 | struct spi_device *spi = pdata->spi; | ||
105 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | 104 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
106 | int ret, val, i = 0; | 105 | int ret, val, i = 0; |
107 | uint8_t channel, mux_cnv; | 106 | uint8_t channel, mux_cnv; |
@@ -139,12 +138,6 @@ static ssize_t show_voltage(struct device *dev, | |||
139 | } | 138 | } |
140 | } | 139 | } |
141 | 140 | ||
142 | static ssize_t ads7871_show_name(struct device *dev, | ||
143 | struct device_attribute *devattr, char *buf) | ||
144 | { | ||
145 | return sprintf(buf, "%s\n", to_spi_device(dev)->modalias); | ||
146 | } | ||
147 | |||
148 | static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_voltage, NULL, 0); | 141 | static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_voltage, NULL, 0); |
149 | static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_voltage, NULL, 1); | 142 | static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_voltage, NULL, 1); |
150 | static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_voltage, NULL, 2); | 143 | static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_voltage, NULL, 2); |
@@ -154,9 +147,7 @@ static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_voltage, NULL, 5); | |||
154 | static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_voltage, NULL, 6); | 147 | static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_voltage, NULL, 6); |
155 | static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_voltage, NULL, 7); | 148 | static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_voltage, NULL, 7); |
156 | 149 | ||
157 | static DEVICE_ATTR(name, S_IRUGO, ads7871_show_name, NULL); | 150 | static struct attribute *ads7871_attrs[] = { |
158 | |||
159 | static struct attribute *ads7871_attributes[] = { | ||
160 | &sensor_dev_attr_in0_input.dev_attr.attr, | 151 | &sensor_dev_attr_in0_input.dev_attr.attr, |
161 | &sensor_dev_attr_in1_input.dev_attr.attr, | 152 | &sensor_dev_attr_in1_input.dev_attr.attr, |
162 | &sensor_dev_attr_in2_input.dev_attr.attr, | 153 | &sensor_dev_attr_in2_input.dev_attr.attr, |
@@ -165,21 +156,18 @@ static struct attribute *ads7871_attributes[] = { | |||
165 | &sensor_dev_attr_in5_input.dev_attr.attr, | 156 | &sensor_dev_attr_in5_input.dev_attr.attr, |
166 | &sensor_dev_attr_in6_input.dev_attr.attr, | 157 | &sensor_dev_attr_in6_input.dev_attr.attr, |
167 | &sensor_dev_attr_in7_input.dev_attr.attr, | 158 | &sensor_dev_attr_in7_input.dev_attr.attr, |
168 | &dev_attr_name.attr, | ||
169 | NULL | 159 | NULL |
170 | }; | 160 | }; |
171 | 161 | ||
172 | static const struct attribute_group ads7871_group = { | 162 | ATTRIBUTE_GROUPS(ads7871); |
173 | .attrs = ads7871_attributes, | ||
174 | }; | ||
175 | 163 | ||
176 | static int ads7871_probe(struct spi_device *spi) | 164 | static int ads7871_probe(struct spi_device *spi) |
177 | { | 165 | { |
178 | int ret, err; | 166 | struct device *dev = &spi->dev; |
167 | int ret; | ||
179 | uint8_t val; | 168 | uint8_t val; |
180 | struct ads7871_data *pdata; | 169 | struct ads7871_data *pdata; |
181 | 170 | struct device *hwmon_dev; | |
182 | dev_dbg(&spi->dev, "probe\n"); | ||
183 | 171 | ||
184 | /* Configure the SPI bus */ | 172 | /* Configure the SPI bus */ |
185 | spi->mode = (SPI_MODE_0); | 173 | spi->mode = (SPI_MODE_0); |
@@ -193,7 +181,7 @@ static int ads7871_probe(struct spi_device *spi) | |||
193 | ads7871_write_reg8(spi, REG_OSC_CONTROL, val); | 181 | ads7871_write_reg8(spi, REG_OSC_CONTROL, val); |
194 | ret = ads7871_read_reg8(spi, REG_OSC_CONTROL); | 182 | ret = ads7871_read_reg8(spi, REG_OSC_CONTROL); |
195 | 183 | ||
196 | dev_dbg(&spi->dev, "REG_OSC_CONTROL write:%x, read:%x\n", val, ret); | 184 | dev_dbg(dev, "REG_OSC_CONTROL write:%x, read:%x\n", val, ret); |
197 | /* | 185 | /* |
198 | * because there is no other error checking on an SPI bus | 186 | * because there is no other error checking on an SPI bus |
199 | * we need to make sure we really have a chip | 187 | * we need to make sure we really have a chip |
@@ -201,46 +189,23 @@ static int ads7871_probe(struct spi_device *spi) | |||
201 | if (val != ret) | 189 | if (val != ret) |
202 | return -ENODEV; | 190 | return -ENODEV; |
203 | 191 | ||
204 | pdata = devm_kzalloc(&spi->dev, sizeof(struct ads7871_data), | 192 | pdata = devm_kzalloc(dev, sizeof(struct ads7871_data), GFP_KERNEL); |
205 | GFP_KERNEL); | ||
206 | if (!pdata) | 193 | if (!pdata) |
207 | return -ENOMEM; | 194 | return -ENOMEM; |
208 | 195 | ||
209 | err = sysfs_create_group(&spi->dev.kobj, &ads7871_group); | 196 | pdata->spi = spi; |
210 | if (err < 0) | ||
211 | return err; | ||
212 | |||
213 | spi_set_drvdata(spi, pdata); | ||
214 | 197 | ||
215 | pdata->hwmon_dev = hwmon_device_register(&spi->dev); | 198 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, spi->modalias, |
216 | if (IS_ERR(pdata->hwmon_dev)) { | 199 | pdata, |
217 | err = PTR_ERR(pdata->hwmon_dev); | 200 | ads7871_groups); |
218 | goto error_remove; | 201 | return PTR_ERR_OR_ZERO(hwmon_dev); |
219 | } | ||
220 | |||
221 | return 0; | ||
222 | |||
223 | error_remove: | ||
224 | sysfs_remove_group(&spi->dev.kobj, &ads7871_group); | ||
225 | return err; | ||
226 | } | ||
227 | |||
228 | static int ads7871_remove(struct spi_device *spi) | ||
229 | { | ||
230 | struct ads7871_data *pdata = spi_get_drvdata(spi); | ||
231 | |||
232 | hwmon_device_unregister(pdata->hwmon_dev); | ||
233 | sysfs_remove_group(&spi->dev.kobj, &ads7871_group); | ||
234 | return 0; | ||
235 | } | 202 | } |
236 | 203 | ||
237 | static struct spi_driver ads7871_driver = { | 204 | static struct spi_driver ads7871_driver = { |
238 | .driver = { | 205 | .driver = { |
239 | .name = DEVICE_NAME, | 206 | .name = DEVICE_NAME, |
240 | }, | 207 | }, |
241 | |||
242 | .probe = ads7871_probe, | 208 | .probe = ads7871_probe, |
243 | .remove = ads7871_remove, | ||
244 | }; | 209 | }; |
245 | 210 | ||
246 | module_spi_driver(ads7871_driver); | 211 | module_spi_driver(ads7871_driver); |