aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2013-09-04 19:55:59 -0400
committerGuenter Roeck <linux@roeck-us.net>2013-10-18 12:11:57 -0400
commit89de734471c5381558b1e749e0b1b88b5b497708 (patch)
tree073a9b1eb33f6746a23d5d072970d38e74f4e4af
parent9d86bd6ba3ba2f254720e2916dfda64737974963 (diff)
hwmon: (ina209) Convert to use devm_hwmon_device_register_with_groups
Also use new macro ATTRIBUTE_GROUPS to declare attribute groups. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r--drivers/hwmon/ina209.c46
1 files changed, 18 insertions, 28 deletions
diff --git a/drivers/hwmon/ina209.c b/drivers/hwmon/ina209.c
index c6fdd5bd395e..5378fdefc1f7 100644
--- a/drivers/hwmon/ina209.c
+++ b/drivers/hwmon/ina209.c
@@ -63,7 +63,7 @@
63#define INA209_SHUNT_DEFAULT 10000 /* uOhm */ 63#define INA209_SHUNT_DEFAULT 10000 /* uOhm */
64 64
65struct ina209_data { 65struct ina209_data {
66 struct device *hwmon_dev; 66 struct i2c_client *client;
67 67
68 struct mutex update_lock; 68 struct mutex update_lock;
69 bool valid; 69 bool valid;
@@ -78,8 +78,8 @@ struct ina209_data {
78 78
79static struct ina209_data *ina209_update_device(struct device *dev) 79static struct ina209_data *ina209_update_device(struct device *dev)
80{ 80{
81 struct i2c_client *client = to_i2c_client(dev); 81 struct ina209_data *data = dev_get_drvdata(dev);
82 struct ina209_data *data = i2c_get_clientdata(client); 82 struct i2c_client *client = data->client;
83 struct ina209_data *ret = data; 83 struct ina209_data *ret = data;
84 s32 val; 84 s32 val;
85 int i; 85 int i;
@@ -234,7 +234,6 @@ static ssize_t ina209_set_interval(struct device *dev,
234 struct device_attribute *da, 234 struct device_attribute *da,
235 const char *buf, size_t count) 235 const char *buf, size_t count)
236{ 236{
237 struct i2c_client *client = to_i2c_client(dev);
238 struct ina209_data *data = ina209_update_device(dev); 237 struct ina209_data *data = ina209_update_device(dev);
239 long val; 238 long val;
240 u16 regval; 239 u16 regval;
@@ -250,7 +249,8 @@ static ssize_t ina209_set_interval(struct device *dev,
250 mutex_lock(&data->update_lock); 249 mutex_lock(&data->update_lock);
251 regval = ina209_reg_from_interval(data->regs[INA209_CONFIGURATION], 250 regval = ina209_reg_from_interval(data->regs[INA209_CONFIGURATION],
252 val); 251 val);
253 i2c_smbus_write_word_swapped(client, INA209_CONFIGURATION, regval); 252 i2c_smbus_write_word_swapped(data->client, INA209_CONFIGURATION,
253 regval);
254 data->regs[INA209_CONFIGURATION] = regval; 254 data->regs[INA209_CONFIGURATION] = regval;
255 data->update_interval = ina209_interval_from_reg(regval); 255 data->update_interval = ina209_interval_from_reg(regval);
256 mutex_unlock(&data->update_lock); 256 mutex_unlock(&data->update_lock);
@@ -260,8 +260,7 @@ static ssize_t ina209_set_interval(struct device *dev,
260static ssize_t ina209_show_interval(struct device *dev, 260static ssize_t ina209_show_interval(struct device *dev,
261 struct device_attribute *da, char *buf) 261 struct device_attribute *da, char *buf)
262{ 262{
263 struct i2c_client *client = to_i2c_client(dev); 263 struct ina209_data *data = dev_get_drvdata(dev);
264 struct ina209_data *data = i2c_get_clientdata(client);
265 264
266 return snprintf(buf, PAGE_SIZE, "%d\n", data->update_interval); 265 return snprintf(buf, PAGE_SIZE, "%d\n", data->update_interval);
267} 266}
@@ -285,9 +284,9 @@ static ssize_t ina209_reset_history(struct device *dev,
285 const char *buf, 284 const char *buf,
286 size_t count) 285 size_t count)
287{ 286{
288 struct i2c_client *client = to_i2c_client(dev);
289 struct ina209_data *data = i2c_get_clientdata(client);
290 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 287 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
288 struct ina209_data *data = dev_get_drvdata(dev);
289 struct i2c_client *client = data->client;
291 u32 mask = attr->index; 290 u32 mask = attr->index;
292 long val; 291 long val;
293 int i, ret; 292 int i, ret;
@@ -312,7 +311,6 @@ static ssize_t ina209_set_value(struct device *dev,
312 const char *buf, 311 const char *buf,
313 size_t count) 312 size_t count)
314{ 313{
315 struct i2c_client *client = to_i2c_client(dev);
316 struct ina209_data *data = ina209_update_device(dev); 314 struct ina209_data *data = ina209_update_device(dev);
317 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 315 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
318 int reg = attr->index; 316 int reg = attr->index;
@@ -332,7 +330,7 @@ static ssize_t ina209_set_value(struct device *dev,
332 count = ret; 330 count = ret;
333 goto abort; 331 goto abort;
334 } 332 }
335 i2c_smbus_write_word_swapped(client, reg, ret); 333 i2c_smbus_write_word_swapped(data->client, reg, ret);
336 data->regs[reg] = ret; 334 data->regs[reg] = ret;
337abort: 335abort:
338 mutex_unlock(&data->update_lock); 336 mutex_unlock(&data->update_lock);
@@ -457,7 +455,7 @@ static SENSOR_DEVICE_ATTR(update_interval, S_IRUGO | S_IWUSR,
457 * Finally, construct an array of pointers to members of the above objects, 455 * Finally, construct an array of pointers to members of the above objects,
458 * as required for sysfs_create_group() 456 * as required for sysfs_create_group()
459 */ 457 */
460static struct attribute *ina209_attributes[] = { 458static struct attribute *ina209_attrs[] = {
461 &sensor_dev_attr_in0_input.dev_attr.attr, 459 &sensor_dev_attr_in0_input.dev_attr.attr,
462 &sensor_dev_attr_in0_input_highest.dev_attr.attr, 460 &sensor_dev_attr_in0_input_highest.dev_attr.attr,
463 &sensor_dev_attr_in0_input_lowest.dev_attr.attr, 461 &sensor_dev_attr_in0_input_lowest.dev_attr.attr,
@@ -498,10 +496,7 @@ static struct attribute *ina209_attributes[] = {
498 496
499 NULL, 497 NULL,
500}; 498};
501 499ATTRIBUTE_GROUPS(ina209);
502static const struct attribute_group ina209_group = {
503 .attrs = ina209_attributes,
504};
505 500
506static void ina209_restore_conf(struct i2c_client *client, 501static void ina209_restore_conf(struct i2c_client *client,
507 struct ina209_data *data) 502 struct ina209_data *data)
@@ -565,6 +560,7 @@ static int ina209_probe(struct i2c_client *client,
565{ 560{
566 struct i2c_adapter *adapter = client->adapter; 561 struct i2c_adapter *adapter = client->adapter;
567 struct ina209_data *data; 562 struct ina209_data *data;
563 struct device *hwmon_dev;
568 int ret; 564 int ret;
569 565
570 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) 566 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA))
@@ -575,27 +571,23 @@ static int ina209_probe(struct i2c_client *client,
575 return -ENOMEM; 571 return -ENOMEM;
576 572
577 i2c_set_clientdata(client, data); 573 i2c_set_clientdata(client, data);
574 data->client = client;
578 mutex_init(&data->update_lock); 575 mutex_init(&data->update_lock);
579 576
580 ret = ina209_init_client(client, data); 577 ret = ina209_init_client(client, data);
581 if (ret) 578 if (ret)
582 return ret; 579 return ret;
583 580
584 /* Register sysfs hooks */ 581 hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev,
585 ret = sysfs_create_group(&client->dev.kobj, &ina209_group); 582 client->name,
586 if (ret) 583 data, ina209_groups);
584 if (IS_ERR(hwmon_dev)) {
585 ret = PTR_ERR(hwmon_dev);
587 goto out_restore_conf; 586 goto out_restore_conf;
588
589 data->hwmon_dev = hwmon_device_register(&client->dev);
590 if (IS_ERR(data->hwmon_dev)) {
591 ret = PTR_ERR(data->hwmon_dev);
592 goto out_hwmon_device_register;
593 } 587 }
594 588
595 return 0; 589 return 0;
596 590
597out_hwmon_device_register:
598 sysfs_remove_group(&client->dev.kobj, &ina209_group);
599out_restore_conf: 591out_restore_conf:
600 ina209_restore_conf(client, data); 592 ina209_restore_conf(client, data);
601 return ret; 593 return ret;
@@ -605,8 +597,6 @@ static int ina209_remove(struct i2c_client *client)
605{ 597{
606 struct ina209_data *data = i2c_get_clientdata(client); 598 struct ina209_data *data = i2c_get_clientdata(client);
607 599
608 hwmon_device_unregister(data->hwmon_dev);
609 sysfs_remove_group(&client->dev.kobj, &ina209_group);
610 ina209_restore_conf(client, data); 600 ina209_restore_conf(client, data);
611 601
612 return 0; 602 return 0;