diff options
author | Axel Lin <axel.lin@ingics.com> | 2014-07-17 07:06:08 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-08-04 10:01:39 -0400 |
commit | 86fd260e0b15d8718ab711f3fd802713e1bfbe89 (patch) | |
tree | 816301dac7d30dce5152c66f52a878cd159faa5e | |
parent | 9b38a66e1a6570b1aff2c1f892b567eded2b3b4e (diff) |
hwmon: (thmc50) Convert to devm_hwmon_device_register_with_groups
Use devm_hwmon_device_register_with_groups() to simplify the code a bit.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r-- | drivers/hwmon/thmc50.c | 78 |
1 files changed, 25 insertions, 53 deletions
diff --git a/drivers/hwmon/thmc50.c b/drivers/hwmon/thmc50.c index bb538dad479b..6a0ee903127e 100644 --- a/drivers/hwmon/thmc50.c +++ b/drivers/hwmon/thmc50.c | |||
@@ -68,7 +68,8 @@ static const u8 THMC50_REG_TEMP_DEFAULT[] = { 0x17, 0x18, 0x18 }; | |||
68 | 68 | ||
69 | /* Each client has this additional data */ | 69 | /* Each client has this additional data */ |
70 | struct thmc50_data { | 70 | struct thmc50_data { |
71 | struct device *hwmon_dev; | 71 | struct i2c_client *client; |
72 | const struct attribute_group *groups[3]; | ||
72 | 73 | ||
73 | struct mutex update_lock; | 74 | struct mutex update_lock; |
74 | enum chips type; | 75 | enum chips type; |
@@ -87,8 +88,8 @@ struct thmc50_data { | |||
87 | 88 | ||
88 | static struct thmc50_data *thmc50_update_device(struct device *dev) | 89 | static struct thmc50_data *thmc50_update_device(struct device *dev) |
89 | { | 90 | { |
90 | struct i2c_client *client = to_i2c_client(dev); | 91 | struct thmc50_data *data = dev_get_drvdata(dev); |
91 | struct thmc50_data *data = i2c_get_clientdata(client); | 92 | struct i2c_client *client = data->client; |
92 | int timeout = HZ / 5 + (data->type == thmc50 ? HZ : 0); | 93 | int timeout = HZ / 5 + (data->type == thmc50 ? HZ : 0); |
93 | 94 | ||
94 | mutex_lock(&data->update_lock); | 95 | mutex_lock(&data->update_lock); |
@@ -138,8 +139,8 @@ static ssize_t set_analog_out(struct device *dev, | |||
138 | struct device_attribute *attr, | 139 | struct device_attribute *attr, |
139 | const char *buf, size_t count) | 140 | const char *buf, size_t count) |
140 | { | 141 | { |
141 | struct i2c_client *client = to_i2c_client(dev); | 142 | struct thmc50_data *data = dev_get_drvdata(dev); |
142 | struct thmc50_data *data = i2c_get_clientdata(client); | 143 | struct i2c_client *client = data->client; |
143 | int config; | 144 | int config; |
144 | unsigned long tmp; | 145 | unsigned long tmp; |
145 | int err; | 146 | int err; |
@@ -192,8 +193,8 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | |||
192 | const char *buf, size_t count) | 193 | const char *buf, size_t count) |
193 | { | 194 | { |
194 | int nr = to_sensor_dev_attr(attr)->index; | 195 | int nr = to_sensor_dev_attr(attr)->index; |
195 | struct i2c_client *client = to_i2c_client(dev); | 196 | struct thmc50_data *data = dev_get_drvdata(dev); |
196 | struct thmc50_data *data = i2c_get_clientdata(client); | 197 | struct i2c_client *client = data->client; |
197 | long val; | 198 | long val; |
198 | int err; | 199 | int err; |
199 | 200 | ||
@@ -221,8 +222,8 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
221 | const char *buf, size_t count) | 222 | const char *buf, size_t count) |
222 | { | 223 | { |
223 | int nr = to_sensor_dev_attr(attr)->index; | 224 | int nr = to_sensor_dev_attr(attr)->index; |
224 | struct i2c_client *client = to_i2c_client(dev); | 225 | struct thmc50_data *data = dev_get_drvdata(dev); |
225 | struct thmc50_data *data = i2c_get_clientdata(client); | 226 | struct i2c_client *client = data->client; |
226 | long val; | 227 | long val; |
227 | int err; | 228 | int err; |
228 | 229 | ||
@@ -370,9 +371,9 @@ static int thmc50_detect(struct i2c_client *client, | |||
370 | return 0; | 371 | return 0; |
371 | } | 372 | } |
372 | 373 | ||
373 | static void thmc50_init_client(struct i2c_client *client) | 374 | static void thmc50_init_client(struct thmc50_data *data) |
374 | { | 375 | { |
375 | struct thmc50_data *data = i2c_get_clientdata(client); | 376 | struct i2c_client *client = data->client; |
376 | int config; | 377 | int config; |
377 | 378 | ||
378 | data->analog_out = i2c_smbus_read_byte_data(client, | 379 | data->analog_out = i2c_smbus_read_byte_data(client, |
@@ -393,59 +394,31 @@ static void thmc50_init_client(struct i2c_client *client) | |||
393 | static int thmc50_probe(struct i2c_client *client, | 394 | static int thmc50_probe(struct i2c_client *client, |
394 | const struct i2c_device_id *id) | 395 | const struct i2c_device_id *id) |
395 | { | 396 | { |
397 | struct device *dev = &client->dev; | ||
396 | struct thmc50_data *data; | 398 | struct thmc50_data *data; |
397 | int err; | 399 | struct device *hwmon_dev; |
400 | int idx = 0; | ||
398 | 401 | ||
399 | data = devm_kzalloc(&client->dev, sizeof(struct thmc50_data), | 402 | data = devm_kzalloc(dev, sizeof(struct thmc50_data), GFP_KERNEL); |
400 | GFP_KERNEL); | ||
401 | if (!data) | 403 | if (!data) |
402 | return -ENOMEM; | 404 | return -ENOMEM; |
403 | 405 | ||
404 | i2c_set_clientdata(client, data); | 406 | data->client = client; |
405 | data->type = id->driver_data; | 407 | data->type = id->driver_data; |
406 | mutex_init(&data->update_lock); | 408 | mutex_init(&data->update_lock); |
407 | 409 | ||
408 | thmc50_init_client(client); | 410 | thmc50_init_client(data); |
409 | 411 | ||
410 | /* Register sysfs hooks */ | 412 | /* sysfs hooks */ |
411 | err = sysfs_create_group(&client->dev.kobj, &thmc50_group); | 413 | data->groups[idx++] = &thmc50_group; |
412 | if (err) | ||
413 | return err; | ||
414 | |||
415 | /* Register ADM1022 sysfs hooks */ | ||
416 | if (data->has_temp3) { | ||
417 | err = sysfs_create_group(&client->dev.kobj, &temp3_group); | ||
418 | if (err) | ||
419 | goto exit_remove_sysfs_thmc50; | ||
420 | } | ||
421 | |||
422 | /* Register a new directory entry with module sensors */ | ||
423 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
424 | if (IS_ERR(data->hwmon_dev)) { | ||
425 | err = PTR_ERR(data->hwmon_dev); | ||
426 | goto exit_remove_sysfs; | ||
427 | } | ||
428 | 414 | ||
429 | return 0; | 415 | /* Register additional ADM1022 sysfs hooks */ |
430 | |||
431 | exit_remove_sysfs: | ||
432 | if (data->has_temp3) | ||
433 | sysfs_remove_group(&client->dev.kobj, &temp3_group); | ||
434 | exit_remove_sysfs_thmc50: | ||
435 | sysfs_remove_group(&client->dev.kobj, &thmc50_group); | ||
436 | return err; | ||
437 | } | ||
438 | |||
439 | static int thmc50_remove(struct i2c_client *client) | ||
440 | { | ||
441 | struct thmc50_data *data = i2c_get_clientdata(client); | ||
442 | |||
443 | hwmon_device_unregister(data->hwmon_dev); | ||
444 | sysfs_remove_group(&client->dev.kobj, &thmc50_group); | ||
445 | if (data->has_temp3) | 416 | if (data->has_temp3) |
446 | sysfs_remove_group(&client->dev.kobj, &temp3_group); | 417 | data->groups[idx++] = &temp3_group; |
447 | 418 | ||
448 | return 0; | 419 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
420 | data, data->groups); | ||
421 | return PTR_ERR_OR_ZERO(hwmon_dev); | ||
449 | } | 422 | } |
450 | 423 | ||
451 | static const struct i2c_device_id thmc50_id[] = { | 424 | static const struct i2c_device_id thmc50_id[] = { |
@@ -461,7 +434,6 @@ static struct i2c_driver thmc50_driver = { | |||
461 | .name = "thmc50", | 434 | .name = "thmc50", |
462 | }, | 435 | }, |
463 | .probe = thmc50_probe, | 436 | .probe = thmc50_probe, |
464 | .remove = thmc50_remove, | ||
465 | .id_table = thmc50_id, | 437 | .id_table = thmc50_id, |
466 | .detect = thmc50_detect, | 438 | .detect = thmc50_detect, |
467 | .address_list = normal_i2c, | 439 | .address_list = normal_i2c, |