diff options
author | Guenter Roeck <linux@roeck-us.net> | 2014-04-12 13:35:29 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-05-21 19:02:25 -0400 |
commit | 9f1513bd55de0a8b4cc8c01a98aa9fb1bacd55e7 (patch) | |
tree | 7d3308fefd83ac2e4f69cd0eba6c1c0150097db4 /drivers/hwmon/max1619.c | |
parent | f83111964ed74c3b2cd0a7d6363afb17efd87623 (diff) |
hwmon: (max1619) Convert to use devm_hwmon_device_register_with_groups
Use devm_hwmon_device_register_with_groups API to attach attributes
to hwmon device, simplify code, and reduce code size.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/max1619.c')
-rw-r--r-- | drivers/hwmon/max1619.c | 53 |
1 files changed, 14 insertions, 39 deletions
diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c index 4125128898af..eda9cf599685 100644 --- a/drivers/hwmon/max1619.c +++ b/drivers/hwmon/max1619.c | |||
@@ -86,7 +86,7 @@ enum temp_index { | |||
86 | */ | 86 | */ |
87 | 87 | ||
88 | struct max1619_data { | 88 | struct max1619_data { |
89 | struct device *hwmon_dev; | 89 | struct i2c_client *client; |
90 | struct mutex update_lock; | 90 | struct mutex update_lock; |
91 | char valid; /* zero until following fields are valid */ | 91 | char valid; /* zero until following fields are valid */ |
92 | unsigned long last_updated; /* in jiffies */ | 92 | unsigned long last_updated; /* in jiffies */ |
@@ -114,8 +114,8 @@ static const u8 regs_write[t_num_regs] = { | |||
114 | 114 | ||
115 | static struct max1619_data *max1619_update_device(struct device *dev) | 115 | static struct max1619_data *max1619_update_device(struct device *dev) |
116 | { | 116 | { |
117 | struct i2c_client *client = to_i2c_client(dev); | 117 | struct max1619_data *data = dev_get_drvdata(dev); |
118 | struct max1619_data *data = i2c_get_clientdata(client); | 118 | struct i2c_client *client = data->client; |
119 | int config, i; | 119 | int config, i; |
120 | 120 | ||
121 | mutex_lock(&data->update_lock); | 121 | mutex_lock(&data->update_lock); |
@@ -158,8 +158,8 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *devattr, | |||
158 | const char *buf, size_t count) | 158 | const char *buf, size_t count) |
159 | { | 159 | { |
160 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 160 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
161 | struct i2c_client *client = to_i2c_client(dev); | 161 | struct max1619_data *data = dev_get_drvdata(dev); |
162 | struct max1619_data *data = i2c_get_clientdata(client); | 162 | struct i2c_client *client = data->client; |
163 | long val; | 163 | long val; |
164 | int err = kstrtol(buf, 10, &val); | 164 | int err = kstrtol(buf, 10, &val); |
165 | if (err) | 165 | if (err) |
@@ -205,7 +205,7 @@ static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2); | |||
205 | static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3); | 205 | static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3); |
206 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); | 206 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); |
207 | 207 | ||
208 | static struct attribute *max1619_attributes[] = { | 208 | static struct attribute *max1619_attrs[] = { |
209 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 209 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
210 | &sensor_dev_attr_temp2_input.dev_attr.attr, | 210 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
211 | &sensor_dev_attr_temp2_min.dev_attr.attr, | 211 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
@@ -220,10 +220,7 @@ static struct attribute *max1619_attributes[] = { | |||
220 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, | 220 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, |
221 | NULL | 221 | NULL |
222 | }; | 222 | }; |
223 | 223 | ATTRIBUTE_GROUPS(max1619); | |
224 | static const struct attribute_group max1619_group = { | ||
225 | .attrs = max1619_attributes, | ||
226 | }; | ||
227 | 224 | ||
228 | /* Return 0 if detection is successful, -ENODEV otherwise */ | 225 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
229 | static int max1619_detect(struct i2c_client *client, | 226 | static int max1619_detect(struct i2c_client *client, |
@@ -280,45 +277,24 @@ static int max1619_probe(struct i2c_client *new_client, | |||
280 | const struct i2c_device_id *id) | 277 | const struct i2c_device_id *id) |
281 | { | 278 | { |
282 | struct max1619_data *data; | 279 | struct max1619_data *data; |
283 | int err; | 280 | struct device *hwmon_dev; |
284 | 281 | ||
285 | data = devm_kzalloc(&new_client->dev, sizeof(struct max1619_data), | 282 | data = devm_kzalloc(&new_client->dev, sizeof(struct max1619_data), |
286 | GFP_KERNEL); | 283 | GFP_KERNEL); |
287 | if (!data) | 284 | if (!data) |
288 | return -ENOMEM; | 285 | return -ENOMEM; |
289 | 286 | ||
290 | i2c_set_clientdata(new_client, data); | 287 | data->client = new_client; |
291 | mutex_init(&data->update_lock); | 288 | mutex_init(&data->update_lock); |
292 | 289 | ||
293 | /* Initialize the MAX1619 chip */ | 290 | /* Initialize the MAX1619 chip */ |
294 | max1619_init_client(new_client); | 291 | max1619_init_client(new_client); |
295 | 292 | ||
296 | /* Register sysfs hooks */ | 293 | hwmon_dev = devm_hwmon_device_register_with_groups(&new_client->dev, |
297 | err = sysfs_create_group(&new_client->dev.kobj, &max1619_group); | 294 | new_client->name, |
298 | if (err) | 295 | data, |
299 | return err; | 296 | max1619_groups); |
300 | 297 | return PTR_ERR_OR_ZERO(hwmon_dev); | |
301 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | ||
302 | if (IS_ERR(data->hwmon_dev)) { | ||
303 | err = PTR_ERR(data->hwmon_dev); | ||
304 | goto exit_remove_files; | ||
305 | } | ||
306 | |||
307 | return 0; | ||
308 | |||
309 | exit_remove_files: | ||
310 | sysfs_remove_group(&new_client->dev.kobj, &max1619_group); | ||
311 | return err; | ||
312 | } | ||
313 | |||
314 | static int max1619_remove(struct i2c_client *client) | ||
315 | { | ||
316 | struct max1619_data *data = i2c_get_clientdata(client); | ||
317 | |||
318 | hwmon_device_unregister(data->hwmon_dev); | ||
319 | sysfs_remove_group(&client->dev.kobj, &max1619_group); | ||
320 | |||
321 | return 0; | ||
322 | } | 298 | } |
323 | 299 | ||
324 | static const struct i2c_device_id max1619_id[] = { | 300 | static const struct i2c_device_id max1619_id[] = { |
@@ -333,7 +309,6 @@ static struct i2c_driver max1619_driver = { | |||
333 | .name = "max1619", | 309 | .name = "max1619", |
334 | }, | 310 | }, |
335 | .probe = max1619_probe, | 311 | .probe = max1619_probe, |
336 | .remove = max1619_remove, | ||
337 | .id_table = max1619_id, | 312 | .id_table = max1619_id, |
338 | .detect = max1619_detect, | 313 | .detect = max1619_detect, |
339 | .address_list = normal_i2c, | 314 | .address_list = normal_i2c, |