aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2014-04-04 12:01:35 -0400
committerJean Delvare <jdelvare@suse.de>2014-04-04 12:01:35 -0400
commit1de8b250f6b243f78b5d01db56d2435448797e08 (patch)
tree59dadfb09dcf7f6dc5e35a37a5f6dddd1a5fde7b
parent084489e64cad50b2a3927abafc69b6fd72eb56bc (diff)
hwmon: (lm90) Convert to use hwmon_device_register_with_groups
Simplify code, reduce code size, and attach hwmon attributes to hwmon device. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Jean Delvare <jdelvare@suse.de>
-rw-r--r--drivers/hwmon/lm90.c39
1 files changed, 17 insertions, 22 deletions
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index 9ad7401f3b2c..c9ff08dbe10c 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -365,6 +365,7 @@ enum lm90_temp11_reg_index {
365 */ 365 */
366 366
367struct lm90_data { 367struct lm90_data {
368 struct i2c_client *client;
368 struct device *hwmon_dev; 369 struct device *hwmon_dev;
369 const struct attribute_group *groups[6]; 370 const struct attribute_group *groups[6];
370 struct mutex update_lock; 371 struct mutex update_lock;
@@ -514,8 +515,8 @@ static void lm90_set_convrate(struct i2c_client *client, struct lm90_data *data,
514 515
515static struct lm90_data *lm90_update_device(struct device *dev) 516static struct lm90_data *lm90_update_device(struct device *dev)
516{ 517{
517 struct i2c_client *client = to_i2c_client(dev); 518 struct lm90_data *data = dev_get_drvdata(dev);
518 struct lm90_data *data = i2c_get_clientdata(client); 519 struct i2c_client *client = data->client;
519 unsigned long next_update; 520 unsigned long next_update;
520 521
521 mutex_lock(&data->update_lock); 522 mutex_lock(&data->update_lock);
@@ -794,8 +795,8 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
794 }; 795 };
795 796
796 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 797 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
797 struct i2c_client *client = to_i2c_client(dev); 798 struct lm90_data *data = dev_get_drvdata(dev);
798 struct lm90_data *data = i2c_get_clientdata(client); 799 struct i2c_client *client = data->client;
799 int nr = attr->index; 800 int nr = attr->index;
800 long val; 801 long val;
801 int err; 802 int err;
@@ -861,8 +862,8 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
861 }; 862 };
862 863
863 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 864 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
864 struct i2c_client *client = to_i2c_client(dev); 865 struct lm90_data *data = dev_get_drvdata(dev);
865 struct lm90_data *data = i2c_get_clientdata(client); 866 struct i2c_client *client = data->client;
866 int nr = attr->nr; 867 int nr = attr->nr;
867 int index = attr->index; 868 int index = attr->index;
868 long val; 869 long val;
@@ -923,8 +924,8 @@ static ssize_t show_temphyst(struct device *dev,
923static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy, 924static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy,
924 const char *buf, size_t count) 925 const char *buf, size_t count)
925{ 926{
926 struct i2c_client *client = to_i2c_client(dev); 927 struct lm90_data *data = dev_get_drvdata(dev);
927 struct lm90_data *data = i2c_get_clientdata(client); 928 struct i2c_client *client = data->client;
928 long val; 929 long val;
929 int err; 930 int err;
930 int temp; 931 int temp;
@@ -977,8 +978,8 @@ static ssize_t set_update_interval(struct device *dev,
977 struct device_attribute *attr, 978 struct device_attribute *attr,
978 const char *buf, size_t count) 979 const char *buf, size_t count)
979{ 980{
980 struct i2c_client *client = to_i2c_client(dev); 981 struct lm90_data *data = dev_get_drvdata(dev);
981 struct lm90_data *data = i2c_get_clientdata(client); 982 struct i2c_client *client = data->client;
982 unsigned long val; 983 unsigned long val;
983 int err; 984 int err;
984 985
@@ -1412,10 +1413,9 @@ static void lm90_restore_conf(struct i2c_client *client, struct lm90_data *data)
1412 data->config_orig); 1413 data->config_orig);
1413} 1414}
1414 1415
1415static void lm90_init_client(struct i2c_client *client) 1416static void lm90_init_client(struct i2c_client *client, struct lm90_data *data)
1416{ 1417{
1417 u8 config, convrate; 1418 u8 config, convrate;
1418 struct lm90_data *data = i2c_get_clientdata(client);
1419 1419
1420 if (lm90_read_reg(client, LM90_REG_R_CONVRATE, &convrate) < 0) { 1420 if (lm90_read_reg(client, LM90_REG_R_CONVRATE, &convrate) < 0) {
1421 dev_warn(&client->dev, "Failed to read convrate register!\n"); 1421 dev_warn(&client->dev, "Failed to read convrate register!\n");
@@ -1530,6 +1530,7 @@ static int lm90_probe(struct i2c_client *client,
1530 if (!data) 1530 if (!data)
1531 return -ENOMEM; 1531 return -ENOMEM;
1532 1532
1533 data->client = client;
1533 i2c_set_clientdata(client, data); 1534 i2c_set_clientdata(client, data);
1534 mutex_init(&data->update_lock); 1535 mutex_init(&data->update_lock);
1535 1536
@@ -1556,7 +1557,7 @@ static int lm90_probe(struct i2c_client *client,
1556 data->max_convrate = lm90_params[data->kind].max_convrate; 1557 data->max_convrate = lm90_params[data->kind].max_convrate;
1557 1558
1558 /* Initialize the LM90 chip */ 1559 /* Initialize the LM90 chip */
1559 lm90_init_client(client); 1560 lm90_init_client(client, data);
1560 1561
1561 /* Register sysfs hooks */ 1562 /* Register sysfs hooks */
1562 data->groups[groups++] = &lm90_group; 1563 data->groups[groups++] = &lm90_group;
@@ -1579,14 +1580,11 @@ static int lm90_probe(struct i2c_client *client,
1579 goto exit_restore; 1580 goto exit_restore;
1580 } 1581 }
1581 1582
1582 err = sysfs_create_groups(&dev->kobj, data->groups); 1583 data->hwmon_dev = hwmon_device_register_with_groups(dev, client->name,
1583 if (err) 1584 data, data->groups);
1584 goto exit_remove_pec;
1585
1586 data->hwmon_dev = hwmon_device_register(dev);
1587 if (IS_ERR(data->hwmon_dev)) { 1585 if (IS_ERR(data->hwmon_dev)) {
1588 err = PTR_ERR(data->hwmon_dev); 1586 err = PTR_ERR(data->hwmon_dev);
1589 goto exit_remove_files; 1587 goto exit_remove_pec;
1590 } 1588 }
1591 1589
1592 if (client->irq) { 1590 if (client->irq) {
@@ -1605,8 +1603,6 @@ static int lm90_probe(struct i2c_client *client,
1605 1603
1606exit_unregister: 1604exit_unregister:
1607 hwmon_device_unregister(data->hwmon_dev); 1605 hwmon_device_unregister(data->hwmon_dev);
1608exit_remove_files:
1609 sysfs_remove_groups(&dev->kobj, data->groups);
1610exit_remove_pec: 1606exit_remove_pec:
1611 device_remove_file(dev, &dev_attr_pec); 1607 device_remove_file(dev, &dev_attr_pec);
1612exit_restore: 1608exit_restore:
@@ -1621,7 +1617,6 @@ static int lm90_remove(struct i2c_client *client)
1621 struct lm90_data *data = i2c_get_clientdata(client); 1617 struct lm90_data *data = i2c_get_clientdata(client);
1622 1618
1623 hwmon_device_unregister(data->hwmon_dev); 1619 hwmon_device_unregister(data->hwmon_dev);
1624 sysfs_remove_groups(&client->dev.kobj, data->groups);
1625 device_remove_file(&client->dev, &dev_attr_pec); 1620 device_remove_file(&client->dev, &dev_attr_pec);
1626 lm90_restore_conf(client, data); 1621 lm90_restore_conf(client, data);
1627 regulator_disable(data->regulator); 1622 regulator_disable(data->regulator);