diff options
author | Guenter Roeck <linux@roeck-us.net> | 2014-04-12 15:46:34 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-05-21 19:02:26 -0400 |
commit | a0ac840d99fa7c2ebf5a3df0367992722a92ca65 (patch) | |
tree | b1d25e4ec103491c72b186b7b4d4ddd0cf673e74 /drivers/hwmon | |
parent | 41936370f13046b757e4f1051d11007e3b151e8e (diff) |
hwmon: (lm83) 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')
-rw-r--r-- | drivers/hwmon/lm83.c | 59 |
1 files changed, 16 insertions, 43 deletions
diff --git a/drivers/hwmon/lm83.c b/drivers/hwmon/lm83.c index f9fcc91d02ca..9e4d0e1d3c4b 100644 --- a/drivers/hwmon/lm83.c +++ b/drivers/hwmon/lm83.c | |||
@@ -111,7 +111,8 @@ static const u8 LM83_REG_W_HIGH[] = { | |||
111 | */ | 111 | */ |
112 | 112 | ||
113 | struct lm83_data { | 113 | struct lm83_data { |
114 | struct device *hwmon_dev; | 114 | struct i2c_client *client; |
115 | const struct attribute_group *groups[3]; | ||
115 | struct mutex update_lock; | 116 | struct mutex update_lock; |
116 | char valid; /* zero until following fields are valid */ | 117 | char valid; /* zero until following fields are valid */ |
117 | unsigned long last_updated; /* in jiffies */ | 118 | unsigned long last_updated; /* in jiffies */ |
@@ -125,8 +126,8 @@ struct lm83_data { | |||
125 | 126 | ||
126 | static struct lm83_data *lm83_update_device(struct device *dev) | 127 | static struct lm83_data *lm83_update_device(struct device *dev) |
127 | { | 128 | { |
128 | struct i2c_client *client = to_i2c_client(dev); | 129 | struct lm83_data *data = dev_get_drvdata(dev); |
129 | struct lm83_data *data = i2c_get_clientdata(client); | 130 | struct i2c_client *client = data->client; |
130 | 131 | ||
131 | mutex_lock(&data->update_lock); | 132 | mutex_lock(&data->update_lock); |
132 | 133 | ||
@@ -169,8 +170,8 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *devattr, | |||
169 | const char *buf, size_t count) | 170 | const char *buf, size_t count) |
170 | { | 171 | { |
171 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 172 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
172 | struct i2c_client *client = to_i2c_client(dev); | 173 | struct lm83_data *data = dev_get_drvdata(dev); |
173 | struct lm83_data *data = i2c_get_clientdata(client); | 174 | struct i2c_client *client = data->client; |
174 | long val; | 175 | long val; |
175 | int nr = attr->index; | 176 | int nr = attr->index; |
176 | int err; | 177 | int err; |
@@ -332,15 +333,15 @@ static int lm83_detect(struct i2c_client *new_client, | |||
332 | static int lm83_probe(struct i2c_client *new_client, | 333 | static int lm83_probe(struct i2c_client *new_client, |
333 | const struct i2c_device_id *id) | 334 | const struct i2c_device_id *id) |
334 | { | 335 | { |
336 | struct device *hwmon_dev; | ||
335 | struct lm83_data *data; | 337 | struct lm83_data *data; |
336 | int err; | ||
337 | 338 | ||
338 | data = devm_kzalloc(&new_client->dev, sizeof(struct lm83_data), | 339 | data = devm_kzalloc(&new_client->dev, sizeof(struct lm83_data), |
339 | GFP_KERNEL); | 340 | GFP_KERNEL); |
340 | if (!data) | 341 | if (!data) |
341 | return -ENOMEM; | 342 | return -ENOMEM; |
342 | 343 | ||
343 | i2c_set_clientdata(new_client, data); | 344 | data->client = new_client; |
344 | mutex_init(&data->update_lock); | 345 | mutex_init(&data->update_lock); |
345 | 346 | ||
346 | /* | 347 | /* |
@@ -349,41 +350,14 @@ static int lm83_probe(struct i2c_client *new_client, | |||
349 | * at the same register as the LM83 temp3 entry - so we | 350 | * at the same register as the LM83 temp3 entry - so we |
350 | * declare 1 and 3 common, and then 2 and 4 only for the LM83. | 351 | * declare 1 and 3 common, and then 2 and 4 only for the LM83. |
351 | */ | 352 | */ |
352 | 353 | data->groups[0] = &lm83_group; | |
353 | err = sysfs_create_group(&new_client->dev.kobj, &lm83_group); | 354 | if (id->driver_data == lm83) |
354 | if (err) | 355 | data->groups[1] = &lm83_group_opt; |
355 | return err; | 356 | |
356 | 357 | hwmon_dev = devm_hwmon_device_register_with_groups(&new_client->dev, | |
357 | if (id->driver_data == lm83) { | 358 | new_client->name, |
358 | err = sysfs_create_group(&new_client->dev.kobj, | 359 | data, data->groups); |
359 | &lm83_group_opt); | 360 | return PTR_ERR_OR_ZERO(hwmon_dev); |
360 | if (err) | ||
361 | goto exit_remove_files; | ||
362 | } | ||
363 | |||
364 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | ||
365 | if (IS_ERR(data->hwmon_dev)) { | ||
366 | err = PTR_ERR(data->hwmon_dev); | ||
367 | goto exit_remove_files; | ||
368 | } | ||
369 | |||
370 | return 0; | ||
371 | |||
372 | exit_remove_files: | ||
373 | sysfs_remove_group(&new_client->dev.kobj, &lm83_group); | ||
374 | sysfs_remove_group(&new_client->dev.kobj, &lm83_group_opt); | ||
375 | return err; | ||
376 | } | ||
377 | |||
378 | static int lm83_remove(struct i2c_client *client) | ||
379 | { | ||
380 | struct lm83_data *data = i2c_get_clientdata(client); | ||
381 | |||
382 | hwmon_device_unregister(data->hwmon_dev); | ||
383 | sysfs_remove_group(&client->dev.kobj, &lm83_group); | ||
384 | sysfs_remove_group(&client->dev.kobj, &lm83_group_opt); | ||
385 | |||
386 | return 0; | ||
387 | } | 361 | } |
388 | 362 | ||
389 | /* | 363 | /* |
@@ -403,7 +377,6 @@ static struct i2c_driver lm83_driver = { | |||
403 | .name = "lm83", | 377 | .name = "lm83", |
404 | }, | 378 | }, |
405 | .probe = lm83_probe, | 379 | .probe = lm83_probe, |
406 | .remove = lm83_remove, | ||
407 | .id_table = lm83_id, | 380 | .id_table = lm83_id, |
408 | .detect = lm83_detect, | 381 | .detect = lm83_detect, |
409 | .address_list = normal_i2c, | 382 | .address_list = normal_i2c, |