summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/tmp421.c
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2014-04-06 00:22:46 -0400
committerGuenter Roeck <linux@roeck-us.net>2014-05-21 19:02:20 -0400
commit276dac8039a70630e4dbf5c4c3b294c057e8cd42 (patch)
tree007c079f407d0871111490a0aa012f45dba758f6 /drivers/hwmon/tmp421.c
parentad9beea43f22f80217ac1850b0373718adce5fbc (diff)
hwmon: (tmp421) 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. Reviewed-by: Jean Delvare <jdelvare@suse.de> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/tmp421.c')
-rw-r--r--drivers/hwmon/tmp421.c47
1 files changed, 15 insertions, 32 deletions
diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c
index ae26b06fa819..7bab7a9bedc6 100644
--- a/drivers/hwmon/tmp421.c
+++ b/drivers/hwmon/tmp421.c
@@ -69,7 +69,7 @@ static const struct i2c_device_id tmp421_id[] = {
69MODULE_DEVICE_TABLE(i2c, tmp421_id); 69MODULE_DEVICE_TABLE(i2c, tmp421_id);
70 70
71struct tmp421_data { 71struct tmp421_data {
72 struct device *hwmon_dev; 72 struct i2c_client *client;
73 struct mutex update_lock; 73 struct mutex update_lock;
74 char valid; 74 char valid;
75 unsigned long last_updated; 75 unsigned long last_updated;
@@ -99,8 +99,8 @@ static int temp_from_u16(u16 reg)
99 99
100static struct tmp421_data *tmp421_update_device(struct device *dev) 100static struct tmp421_data *tmp421_update_device(struct device *dev)
101{ 101{
102 struct i2c_client *client = to_i2c_client(dev); 102 struct tmp421_data *data = dev_get_drvdata(dev);
103 struct tmp421_data *data = i2c_get_clientdata(client); 103 struct i2c_client *client = data->client;
104 int i; 104 int i;
105 105
106 mutex_lock(&data->update_lock); 106 mutex_lock(&data->update_lock);
@@ -198,6 +198,11 @@ static const struct attribute_group tmp421_group = {
198 .is_visible = tmp421_is_visible, 198 .is_visible = tmp421_is_visible,
199}; 199};
200 200
201static const struct attribute_group *tmp421_groups[] = {
202 &tmp421_group,
203 NULL
204};
205
201static int tmp421_init_client(struct i2c_client *client) 206static int tmp421_init_client(struct i2c_client *client)
202{ 207{
203 int config, config_orig; 208 int config, config_orig;
@@ -264,47 +269,26 @@ static int tmp421_detect(struct i2c_client *client,
264static int tmp421_probe(struct i2c_client *client, 269static int tmp421_probe(struct i2c_client *client,
265 const struct i2c_device_id *id) 270 const struct i2c_device_id *id)
266{ 271{
272 struct device *dev = &client->dev;
273 struct device *hwmon_dev;
267 struct tmp421_data *data; 274 struct tmp421_data *data;
268 int err; 275 int err;
269 276
270 data = devm_kzalloc(&client->dev, sizeof(struct tmp421_data), 277 data = devm_kzalloc(dev, sizeof(struct tmp421_data), GFP_KERNEL);
271 GFP_KERNEL);
272 if (!data) 278 if (!data)
273 return -ENOMEM; 279 return -ENOMEM;
274 280
275 i2c_set_clientdata(client, data);
276 mutex_init(&data->update_lock); 281 mutex_init(&data->update_lock);
277 data->channels = id->driver_data; 282 data->channels = id->driver_data;
283 data->client = client;
278 284
279 err = tmp421_init_client(client); 285 err = tmp421_init_client(client);
280 if (err) 286 if (err)
281 return err; 287 return err;
282 288
283 err = sysfs_create_group(&client->dev.kobj, &tmp421_group); 289 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
284 if (err) 290 data, tmp421_groups);
285 return err; 291 return PTR_ERR_OR_ZERO(hwmon_dev);
286
287 data->hwmon_dev = hwmon_device_register(&client->dev);
288 if (IS_ERR(data->hwmon_dev)) {
289 err = PTR_ERR(data->hwmon_dev);
290 data->hwmon_dev = NULL;
291 goto exit_remove;
292 }
293 return 0;
294
295exit_remove:
296 sysfs_remove_group(&client->dev.kobj, &tmp421_group);
297 return err;
298}
299
300static int tmp421_remove(struct i2c_client *client)
301{
302 struct tmp421_data *data = i2c_get_clientdata(client);
303
304 hwmon_device_unregister(data->hwmon_dev);
305 sysfs_remove_group(&client->dev.kobj, &tmp421_group);
306
307 return 0;
308} 292}
309 293
310static struct i2c_driver tmp421_driver = { 294static struct i2c_driver tmp421_driver = {
@@ -313,7 +297,6 @@ static struct i2c_driver tmp421_driver = {
313 .name = "tmp421", 297 .name = "tmp421",
314 }, 298 },
315 .probe = tmp421_probe, 299 .probe = tmp421_probe,
316 .remove = tmp421_remove,
317 .id_table = tmp421_id, 300 .id_table = tmp421_id,
318 .detect = tmp421_detect, 301 .detect = tmp421_detect,
319 .address_list = normal_i2c, 302 .address_list = normal_i2c,