aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2013-09-04 19:24:09 -0400
committerGuenter Roeck <linux@roeck-us.net>2013-10-18 12:11:52 -0400
commitf3643ac7ffd8bf9a3b0bac8e207529d01bebf269 (patch)
treeb1cba38a8ec5718190ab611f4f45007ec6e3c963
parent468bf0e395363c12a41f508cc202b8d33f201807 (diff)
hwmon: (tmp401) Convert to use devm_hwmon_device_register_with_groups
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r--drivers/hwmon/tmp401.c92
1 files changed, 28 insertions, 64 deletions
diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c
index dfe6d9527efb..7fa6e7d0b9b6 100644
--- a/drivers/hwmon/tmp401.c
+++ b/drivers/hwmon/tmp401.c
@@ -155,7 +155,8 @@ MODULE_DEVICE_TABLE(i2c, tmp401_id);
155 */ 155 */
156 156
157struct tmp401_data { 157struct tmp401_data {
158 struct device *hwmon_dev; 158 struct i2c_client *client;
159 const struct attribute_group *groups[3];
159 struct mutex update_lock; 160 struct mutex update_lock;
160 char valid; /* zero until following fields are valid */ 161 char valid; /* zero until following fields are valid */
161 unsigned long last_updated; /* in jiffies */ 162 unsigned long last_updated; /* in jiffies */
@@ -231,8 +232,8 @@ static int tmp401_update_device_reg16(struct i2c_client *client,
231 232
232static struct tmp401_data *tmp401_update_device(struct device *dev) 233static struct tmp401_data *tmp401_update_device(struct device *dev)
233{ 234{
234 struct i2c_client *client = to_i2c_client(dev); 235 struct tmp401_data *data = dev_get_drvdata(dev);
235 struct tmp401_data *data = i2c_get_clientdata(client); 236 struct i2c_client *client = data->client;
236 struct tmp401_data *ret = data; 237 struct tmp401_data *ret = data;
237 int i, val; 238 int i, val;
238 unsigned long next_update; 239 unsigned long next_update;
@@ -350,15 +351,12 @@ static ssize_t store_temp(struct device *dev, struct device_attribute *devattr,
350{ 351{
351 int nr = to_sensor_dev_attr_2(devattr)->nr; 352 int nr = to_sensor_dev_attr_2(devattr)->nr;
352 int index = to_sensor_dev_attr_2(devattr)->index; 353 int index = to_sensor_dev_attr_2(devattr)->index;
353 struct i2c_client *client = to_i2c_client(dev); 354 struct tmp401_data *data = dev_get_drvdata(dev);
354 struct tmp401_data *data = tmp401_update_device(dev); 355 struct i2c_client *client = data->client;
355 long val; 356 long val;
356 u16 reg; 357 u16 reg;
357 u8 regaddr; 358 u8 regaddr;
358 359
359 if (IS_ERR(data))
360 return PTR_ERR(data);
361
362 if (kstrtol(buf, 10, &val)) 360 if (kstrtol(buf, 10, &val))
363 return -EINVAL; 361 return -EINVAL;
364 362
@@ -405,7 +403,7 @@ static ssize_t store_temp_crit_hyst(struct device *dev, struct device_attribute
405 val = clamp_val(val, temp - 255000, temp); 403 val = clamp_val(val, temp - 255000, temp);
406 reg = ((temp - val) + 500) / 1000; 404 reg = ((temp - val) + 500) / 1000;
407 405
408 i2c_smbus_write_byte_data(to_i2c_client(dev), TMP401_TEMP_CRIT_HYST, 406 i2c_smbus_write_byte_data(data->client, TMP401_TEMP_CRIT_HYST,
409 reg); 407 reg);
410 408
411 data->temp_crit_hyst = reg; 409 data->temp_crit_hyst = reg;
@@ -423,8 +421,8 @@ static ssize_t store_temp_crit_hyst(struct device *dev, struct device_attribute
423static ssize_t reset_temp_history(struct device *dev, 421static ssize_t reset_temp_history(struct device *dev,
424 struct device_attribute *devattr, const char *buf, size_t count) 422 struct device_attribute *devattr, const char *buf, size_t count)
425{ 423{
426 struct i2c_client *client = to_i2c_client(dev); 424 struct tmp401_data *data = dev_get_drvdata(dev);
427 struct tmp401_data *data = i2c_get_clientdata(client); 425 struct i2c_client *client = data->client;
428 long val; 426 long val;
429 427
430 if (kstrtol(buf, 10, &val)) 428 if (kstrtol(buf, 10, &val))
@@ -447,8 +445,7 @@ static ssize_t reset_temp_history(struct device *dev,
447static ssize_t show_update_interval(struct device *dev, 445static ssize_t show_update_interval(struct device *dev,
448 struct device_attribute *attr, char *buf) 446 struct device_attribute *attr, char *buf)
449{ 447{
450 struct i2c_client *client = to_i2c_client(dev); 448 struct tmp401_data *data = dev_get_drvdata(dev);
451 struct tmp401_data *data = i2c_get_clientdata(client);
452 449
453 return sprintf(buf, "%u\n", data->update_interval); 450 return sprintf(buf, "%u\n", data->update_interval);
454} 451}
@@ -457,8 +454,8 @@ static ssize_t set_update_interval(struct device *dev,
457 struct device_attribute *attr, 454 struct device_attribute *attr,
458 const char *buf, size_t count) 455 const char *buf, size_t count)
459{ 456{
460 struct i2c_client *client = to_i2c_client(dev); 457 struct tmp401_data *data = dev_get_drvdata(dev);
461 struct tmp401_data *data = i2c_get_clientdata(client); 458 struct i2c_client *client = data->client;
462 unsigned long val; 459 unsigned long val;
463 int err, rate; 460 int err, rate;
464 461
@@ -616,10 +613,10 @@ static const struct attribute_group tmp432_group = {
616 * Begin non sysfs callback code (aka Real code) 613 * Begin non sysfs callback code (aka Real code)
617 */ 614 */
618 615
619static void tmp401_init_client(struct i2c_client *client) 616static void tmp401_init_client(struct tmp401_data *data,
617 struct i2c_client *client)
620{ 618{
621 int config, config_orig; 619 int config, config_orig;
622 struct tmp401_data *data = i2c_get_clientdata(client);
623 620
624 /* Set the conversion rate to 2 Hz */ 621 /* Set the conversion rate to 2 Hz */
625 i2c_smbus_write_byte_data(client, TMP401_CONVERSION_RATE_WRITE, 5); 622 i2c_smbus_write_byte_data(client, TMP401_CONVERSION_RATE_WRITE, 5);
@@ -705,77 +702,45 @@ static int tmp401_detect(struct i2c_client *client,
705 return 0; 702 return 0;
706} 703}
707 704
708static int tmp401_remove(struct i2c_client *client)
709{
710 struct device *dev = &client->dev;
711 struct tmp401_data *data = i2c_get_clientdata(client);
712
713 if (data->hwmon_dev)
714 hwmon_device_unregister(data->hwmon_dev);
715
716 sysfs_remove_group(&dev->kobj, &tmp401_group);
717
718 if (data->kind == tmp411)
719 sysfs_remove_group(&dev->kobj, &tmp411_group);
720
721 if (data->kind == tmp432)
722 sysfs_remove_group(&dev->kobj, &tmp432_group);
723
724 return 0;
725}
726
727static int tmp401_probe(struct i2c_client *client, 705static int tmp401_probe(struct i2c_client *client,
728 const struct i2c_device_id *id) 706 const struct i2c_device_id *id)
729{ 707{
708 const char *names[] = { "TMP401", "TMP411", "TMP431", "TMP432" };
730 struct device *dev = &client->dev; 709 struct device *dev = &client->dev;
731 int err; 710 struct device *hwmon_dev;
732 struct tmp401_data *data; 711 struct tmp401_data *data;
733 const char *names[] = { "TMP401", "TMP411", "TMP431", "TMP432" }; 712 int groups = 0;
734 713
735 data = devm_kzalloc(dev, sizeof(struct tmp401_data), GFP_KERNEL); 714 data = devm_kzalloc(dev, sizeof(struct tmp401_data), GFP_KERNEL);
736 if (!data) 715 if (!data)
737 return -ENOMEM; 716 return -ENOMEM;
738 717
739 i2c_set_clientdata(client, data); 718 data->client = client;
740 mutex_init(&data->update_lock); 719 mutex_init(&data->update_lock);
741 data->kind = id->driver_data; 720 data->kind = id->driver_data;
742 721
743 /* Initialize the TMP401 chip */ 722 /* Initialize the TMP401 chip */
744 tmp401_init_client(client); 723 tmp401_init_client(data, client);
745 724
746 /* Register sysfs hooks */ 725 /* Register sysfs hooks */
747 err = sysfs_create_group(&dev->kobj, &tmp401_group); 726 data->groups[groups++] = &tmp401_group;
748 if (err)
749 return err;
750 727
751 /* Register additional tmp411 sysfs hooks */ 728 /* Register additional tmp411 sysfs hooks */
752 if (data->kind == tmp411) { 729 if (data->kind == tmp411)
753 err = sysfs_create_group(&dev->kobj, &tmp411_group); 730 data->groups[groups++] = &tmp411_group;
754 if (err)
755 goto exit_remove;
756 }
757 731
758 /* Register additional tmp432 sysfs hooks */ 732 /* Register additional tmp432 sysfs hooks */
759 if (data->kind == tmp432) { 733 if (data->kind == tmp432)
760 err = sysfs_create_group(&dev->kobj, &tmp432_group); 734 data->groups[groups++] = &tmp432_group;
761 if (err)
762 goto exit_remove;
763 }
764 735
765 data->hwmon_dev = hwmon_device_register(dev); 736 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
766 if (IS_ERR(data->hwmon_dev)) { 737 data, data->groups);
767 err = PTR_ERR(data->hwmon_dev); 738 if (IS_ERR(hwmon_dev))
768 data->hwmon_dev = NULL; 739 return PTR_ERR(hwmon_dev);
769 goto exit_remove;
770 }
771 740
772 dev_info(dev, "Detected TI %s chip\n", names[data->kind]); 741 dev_info(dev, "Detected TI %s chip\n", names[data->kind]);
773 742
774 return 0; 743 return 0;
775
776exit_remove:
777 tmp401_remove(client);
778 return err;
779} 744}
780 745
781static struct i2c_driver tmp401_driver = { 746static struct i2c_driver tmp401_driver = {
@@ -784,7 +749,6 @@ static struct i2c_driver tmp401_driver = {
784 .name = "tmp401", 749 .name = "tmp401",
785 }, 750 },
786 .probe = tmp401_probe, 751 .probe = tmp401_probe,
787 .remove = tmp401_remove,
788 .id_table = tmp401_id, 752 .id_table = tmp401_id,
789 .detect = tmp401_detect, 753 .detect = tmp401_detect,
790 .address_list = normal_i2c, 754 .address_list = normal_i2c,