summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/amc6821.c
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@ingics.com>2014-06-28 22:33:34 -0400
committerGuenter Roeck <linux@roeck-us.net>2014-08-04 10:01:35 -0400
commit1276fae2a93142525580d6f6ab77105f4d7a0e09 (patch)
treee5b9e6aebbd1a4c02ce63246c632c17e5a47d7ea /drivers/hwmon/amc6821.c
parent28e6274d8fa67ecb468eaa219c45595384e3bda8 (diff)
hwmon: (amc6821) Convert to devm_hwmon_device_register_with_groups
Use ATTRIBUTE_GROUPS macro and 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>
Diffstat (limited to 'drivers/hwmon/amc6821.c')
-rw-r--r--drivers/hwmon/amc6821.c70
1 files changed, 25 insertions, 45 deletions
diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c
index 29c17fcc487b..12e851a5af48 100644
--- a/drivers/hwmon/amc6821.c
+++ b/drivers/hwmon/amc6821.c
@@ -152,7 +152,7 @@ static const u8 fan_reg_hi[] = {AMC6821_REG_TDATA_HI,
152 */ 152 */
153 153
154struct amc6821_data { 154struct amc6821_data {
155 struct device *hwmon_dev; 155 struct i2c_client *client;
156 struct mutex update_lock; 156 struct mutex update_lock;
157 char valid; /* zero until following fields are valid */ 157 char valid; /* zero until following fields are valid */
158 unsigned long last_updated; /* in jiffies */ 158 unsigned long last_updated; /* in jiffies */
@@ -176,8 +176,8 @@ struct amc6821_data {
176 176
177static struct amc6821_data *amc6821_update_device(struct device *dev) 177static struct amc6821_data *amc6821_update_device(struct device *dev)
178{ 178{
179 struct i2c_client *client = to_i2c_client(dev); 179 struct amc6821_data *data = dev_get_drvdata(dev);
180 struct amc6821_data *data = i2c_get_clientdata(client); 180 struct i2c_client *client = data->client;
181 int timeout = HZ; 181 int timeout = HZ;
182 u8 reg; 182 u8 reg;
183 int i; 183 int i;
@@ -294,8 +294,8 @@ static ssize_t set_temp(
294 const char *buf, 294 const char *buf,
295 size_t count) 295 size_t count)
296{ 296{
297 struct i2c_client *client = to_i2c_client(dev); 297 struct amc6821_data *data = dev_get_drvdata(dev);
298 struct amc6821_data *data = i2c_get_clientdata(client); 298 struct i2c_client *client = data->client;
299 int ix = to_sensor_dev_attr(attr)->index; 299 int ix = to_sensor_dev_attr(attr)->index;
300 long val; 300 long val;
301 301
@@ -379,8 +379,8 @@ static ssize_t set_pwm1(
379 const char *buf, 379 const char *buf,
380 size_t count) 380 size_t count)
381{ 381{
382 struct i2c_client *client = to_i2c_client(dev); 382 struct amc6821_data *data = dev_get_drvdata(dev);
383 struct amc6821_data *data = i2c_get_clientdata(client); 383 struct i2c_client *client = data->client;
384 long val; 384 long val;
385 int ret = kstrtol(buf, 10, &val); 385 int ret = kstrtol(buf, 10, &val);
386 if (ret) 386 if (ret)
@@ -408,8 +408,8 @@ static ssize_t set_pwm1_enable(
408 const char *buf, 408 const char *buf,
409 size_t count) 409 size_t count)
410{ 410{
411 struct i2c_client *client = to_i2c_client(dev); 411 struct amc6821_data *data = dev_get_drvdata(dev);
412 struct amc6821_data *data = i2c_get_clientdata(client); 412 struct i2c_client *client = data->client;
413 long val; 413 long val;
414 int config = kstrtol(buf, 10, &val); 414 int config = kstrtol(buf, 10, &val);
415 if (config) 415 if (config)
@@ -519,8 +519,8 @@ static ssize_t set_temp_auto_point_temp(
519 const char *buf, 519 const char *buf,
520 size_t count) 520 size_t count)
521{ 521{
522 struct i2c_client *client = to_i2c_client(dev);
523 struct amc6821_data *data = amc6821_update_device(dev); 522 struct amc6821_data *data = amc6821_update_device(dev);
523 struct i2c_client *client = data->client;
524 int ix = to_sensor_dev_attr_2(attr)->index; 524 int ix = to_sensor_dev_attr_2(attr)->index;
525 int nr = to_sensor_dev_attr_2(attr)->nr; 525 int nr = to_sensor_dev_attr_2(attr)->nr;
526 u8 *ptemp; 526 u8 *ptemp;
@@ -592,8 +592,8 @@ static ssize_t set_pwm1_auto_point_pwm(
592 const char *buf, 592 const char *buf,
593 size_t count) 593 size_t count)
594{ 594{
595 struct i2c_client *client = to_i2c_client(dev); 595 struct amc6821_data *data = dev_get_drvdata(dev);
596 struct amc6821_data *data = i2c_get_clientdata(client); 596 struct i2c_client *client = data->client;
597 int dpwm; 597 int dpwm;
598 long val; 598 long val;
599 int ret = kstrtol(buf, 10, &val); 599 int ret = kstrtol(buf, 10, &val);
@@ -655,8 +655,8 @@ static ssize_t set_fan(
655 struct device_attribute *attr, 655 struct device_attribute *attr,
656 const char *buf, size_t count) 656 const char *buf, size_t count)
657{ 657{
658 struct i2c_client *client = to_i2c_client(dev); 658 struct amc6821_data *data = dev_get_drvdata(dev);
659 struct amc6821_data *data = i2c_get_clientdata(client); 659 struct i2c_client *client = data->client;
660 long val; 660 long val;
661 int ix = to_sensor_dev_attr(attr)->index; 661 int ix = to_sensor_dev_attr(attr)->index;
662 int ret = kstrtol(buf, 10, &val); 662 int ret = kstrtol(buf, 10, &val);
@@ -696,8 +696,8 @@ static ssize_t set_fan1_div(
696 struct device_attribute *attr, 696 struct device_attribute *attr,
697 const char *buf, size_t count) 697 const char *buf, size_t count)
698{ 698{
699 struct i2c_client *client = to_i2c_client(dev); 699 struct amc6821_data *data = dev_get_drvdata(dev);
700 struct amc6821_data *data = i2c_get_clientdata(client); 700 struct i2c_client *client = data->client;
701 long val; 701 long val;
702 int config = kstrtol(buf, 10, &val); 702 int config = kstrtol(buf, 10, &val);
703 if (config) 703 if (config)
@@ -834,9 +834,7 @@ static struct attribute *amc6821_attrs[] = {
834 NULL 834 NULL
835}; 835};
836 836
837static struct attribute_group amc6821_attr_grp = { 837ATTRIBUTE_GROUPS(amc6821);
838 .attrs = amc6821_attrs,
839};
840 838
841/* Return 0 if detection is successful, -ENODEV otherwise */ 839/* Return 0 if detection is successful, -ENODEV otherwise */
842static int amc6821_detect( 840static int amc6821_detect(
@@ -973,15 +971,16 @@ static int amc6821_init_client(struct i2c_client *client)
973static int amc6821_probe(struct i2c_client *client, 971static int amc6821_probe(struct i2c_client *client,
974 const struct i2c_device_id *id) 972 const struct i2c_device_id *id)
975{ 973{
974 struct device *dev = &client->dev;
976 struct amc6821_data *data; 975 struct amc6821_data *data;
976 struct device *hwmon_dev;
977 int err; 977 int err;
978 978
979 data = devm_kzalloc(&client->dev, sizeof(struct amc6821_data), 979 data = devm_kzalloc(dev, sizeof(struct amc6821_data), GFP_KERNEL);
980 GFP_KERNEL);
981 if (!data) 980 if (!data)
982 return -ENOMEM; 981 return -ENOMEM;
983 982
984 i2c_set_clientdata(client, data); 983 data->client = client;
985 mutex_init(&data->update_lock); 984 mutex_init(&data->update_lock);
986 985
987 /* 986 /*
@@ -991,28 +990,10 @@ static int amc6821_probe(struct i2c_client *client,
991 if (err) 990 if (err)
992 return err; 991 return err;
993 992
994 err = sysfs_create_group(&client->dev.kobj, &amc6821_attr_grp); 993 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
995 if (err) 994 data,
996 return err; 995 amc6821_groups);
997 996 return PTR_ERR_OR_ZERO(hwmon_dev);
998 data->hwmon_dev = hwmon_device_register(&client->dev);
999 if (!IS_ERR(data->hwmon_dev))
1000 return 0;
1001
1002 err = PTR_ERR(data->hwmon_dev);
1003 dev_err(&client->dev, "error registering hwmon device.\n");
1004 sysfs_remove_group(&client->dev.kobj, &amc6821_attr_grp);
1005 return err;
1006}
1007
1008static int amc6821_remove(struct i2c_client *client)
1009{
1010 struct amc6821_data *data = i2c_get_clientdata(client);
1011
1012 hwmon_device_unregister(data->hwmon_dev);
1013 sysfs_remove_group(&client->dev.kobj, &amc6821_attr_grp);
1014
1015 return 0;
1016} 997}
1017 998
1018static const struct i2c_device_id amc6821_id[] = { 999static const struct i2c_device_id amc6821_id[] = {
@@ -1028,7 +1009,6 @@ static struct i2c_driver amc6821_driver = {
1028 .name = "amc6821", 1009 .name = "amc6821",
1029 }, 1010 },
1030 .probe = amc6821_probe, 1011 .probe = amc6821_probe,
1031 .remove = amc6821_remove,
1032 .id_table = amc6821_id, 1012 .id_table = amc6821_id,
1033 .detect = amc6821_detect, 1013 .detect = amc6821_detect,
1034 .address_list = normal_i2c, 1014 .address_list = normal_i2c,