aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2013-07-06 12:46:38 -0400
committerGuenter Roeck <linux@roeck-us.net>2013-10-13 19:16:27 -0400
commit9a85d53cfcf1d65c08033aac067f79d2cfee5ad7 (patch)
tree10ca33883484a075ec3dbbdefb9517c4c265ad5b /drivers
parent7258a12536da7f0db881b9ec9348f0d00a67e062 (diff)
hwmon: (ltc4245) Convert to use hwmon_device_register_with_groups
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/hwmon/ltc4245.c78
1 files changed, 24 insertions, 54 deletions
diff --git a/drivers/hwmon/ltc4245.c b/drivers/hwmon/ltc4245.c
index cdc1ecc6734d..d4172933ce4f 100644
--- a/drivers/hwmon/ltc4245.c
+++ b/drivers/hwmon/ltc4245.c
@@ -51,7 +51,9 @@ enum ltc4245_cmd {
51}; 51};
52 52
53struct ltc4245_data { 53struct ltc4245_data {
54 struct device *hwmon_dev; 54 struct i2c_client *client;
55
56 const struct attribute_group *groups[3];
55 57
56 struct mutex update_lock; 58 struct mutex update_lock;
57 bool valid; 59 bool valid;
@@ -77,8 +79,8 @@ struct ltc4245_data {
77 */ 79 */
78static void ltc4245_update_gpios(struct device *dev) 80static void ltc4245_update_gpios(struct device *dev)
79{ 81{
80 struct i2c_client *client = to_i2c_client(dev); 82 struct ltc4245_data *data = dev_get_drvdata(dev);
81 struct ltc4245_data *data = i2c_get_clientdata(client); 83 struct i2c_client *client = data->client;
82 u8 gpio_curr, gpio_next, gpio_reg; 84 u8 gpio_curr, gpio_next, gpio_reg;
83 int i; 85 int i;
84 86
@@ -130,8 +132,8 @@ static void ltc4245_update_gpios(struct device *dev)
130 132
131static struct ltc4245_data *ltc4245_update_device(struct device *dev) 133static struct ltc4245_data *ltc4245_update_device(struct device *dev)
132{ 134{
133 struct i2c_client *client = to_i2c_client(dev); 135 struct ltc4245_data *data = dev_get_drvdata(dev);
134 struct ltc4245_data *data = i2c_get_clientdata(client); 136 struct i2c_client *client = data->client;
135 s32 val; 137 s32 val;
136 int i; 138 int i;
137 139
@@ -455,41 +457,14 @@ static const struct attribute_group ltc4245_gpio_group = {
455 .attrs = ltc4245_gpio_attributes, 457 .attrs = ltc4245_gpio_attributes,
456}; 458};
457 459
458static int ltc4245_sysfs_create_groups(struct i2c_client *client) 460static void ltc4245_sysfs_add_groups(struct ltc4245_data *data)
459{ 461{
460 struct ltc4245_data *data = i2c_get_clientdata(client); 462 /* standard sysfs attributes */
461 struct device *dev = &client->dev; 463 data->groups[0] = &ltc4245_std_group;
462 int ret;
463
464 /* register the standard sysfs attributes */
465 ret = sysfs_create_group(&dev->kobj, &ltc4245_std_group);
466 if (ret) {
467 dev_err(dev, "unable to register standard attributes\n");
468 return ret;
469 }
470 464
471 /* if we're using the extra gpio support, register it's attributes */ 465 /* if we're using the extra gpio support, register it's attributes */
472 if (data->use_extra_gpios) {
473 ret = sysfs_create_group(&dev->kobj, &ltc4245_gpio_group);
474 if (ret) {
475 dev_err(dev, "unable to register gpio attributes\n");
476 sysfs_remove_group(&dev->kobj, &ltc4245_std_group);
477 return ret;
478 }
479 }
480
481 return 0;
482}
483
484static void ltc4245_sysfs_remove_groups(struct i2c_client *client)
485{
486 struct ltc4245_data *data = i2c_get_clientdata(client);
487 struct device *dev = &client->dev;
488
489 if (data->use_extra_gpios) 466 if (data->use_extra_gpios)
490 sysfs_remove_group(&dev->kobj, &ltc4245_gpio_group); 467 data->groups[1] = &ltc4245_gpio_group;
491
492 sysfs_remove_group(&dev->kobj, &ltc4245_std_group);
493} 468}
494 469
495static bool ltc4245_use_extra_gpios(struct i2c_client *client) 470static bool ltc4245_use_extra_gpios(struct i2c_client *client)
@@ -517,7 +492,7 @@ static int ltc4245_probe(struct i2c_client *client,
517{ 492{
518 struct i2c_adapter *adapter = client->adapter; 493 struct i2c_adapter *adapter = client->adapter;
519 struct ltc4245_data *data; 494 struct ltc4245_data *data;
520 int ret; 495 struct device *hwmon_dev;
521 496
522 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 497 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
523 return -ENODEV; 498 return -ENODEV;
@@ -526,7 +501,7 @@ static int ltc4245_probe(struct i2c_client *client,
526 if (!data) 501 if (!data)
527 return -ENOMEM; 502 return -ENOMEM;
528 503
529 i2c_set_clientdata(client, data); 504 data->client = client;
530 mutex_init(&data->update_lock); 505 mutex_init(&data->update_lock);
531 data->use_extra_gpios = ltc4245_use_extra_gpios(client); 506 data->use_extra_gpios = ltc4245_use_extra_gpios(client);
532 507
@@ -534,30 +509,25 @@ static int ltc4245_probe(struct i2c_client *client,
534 i2c_smbus_write_byte_data(client, LTC4245_FAULT1, 0x00); 509 i2c_smbus_write_byte_data(client, LTC4245_FAULT1, 0x00);
535 i2c_smbus_write_byte_data(client, LTC4245_FAULT2, 0x00); 510 i2c_smbus_write_byte_data(client, LTC4245_FAULT2, 0x00);
536 511
537 /* Register sysfs hooks */ 512 /* Add sysfs hooks */
538 ret = ltc4245_sysfs_create_groups(client); 513 ltc4245_sysfs_add_groups(data);
539 if (ret)
540 return ret;
541 514
542 data->hwmon_dev = hwmon_device_register(&client->dev); 515 hwmon_dev = hwmon_device_register_with_groups(&client->dev,
543 if (IS_ERR(data->hwmon_dev)) { 516 client->name, data,
544 ret = PTR_ERR(data->hwmon_dev); 517 data->groups);
545 goto out_hwmon_device_register; 518 if (IS_ERR(hwmon_dev))
546 } 519 return PTR_ERR(hwmon_dev);
547 520
548 return 0; 521 i2c_set_clientdata(client, hwmon_dev);
549 522
550out_hwmon_device_register: 523 return 0;
551 ltc4245_sysfs_remove_groups(client);
552 return ret;
553} 524}
554 525
555static int ltc4245_remove(struct i2c_client *client) 526static int ltc4245_remove(struct i2c_client *client)
556{ 527{
557 struct ltc4245_data *data = i2c_get_clientdata(client); 528 struct device *hwmon_dev = i2c_get_clientdata(client);
558 529
559 hwmon_device_unregister(data->hwmon_dev); 530 hwmon_device_unregister(hwmon_dev);
560 ltc4245_sysfs_remove_groups(client);
561 531
562 return 0; 532 return 0;
563} 533}