diff options
author | Guenter Roeck <linux@roeck-us.net> | 2013-09-02 01:49:25 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2013-10-13 19:16:28 -0400 |
commit | 8d3735522fb192738d7161865d41688f10983613 (patch) | |
tree | 9cca72ebb3ea927eb7b355ce853d6dda1bb0d9fd /drivers/hwmon/max6697.c | |
parent | 3710263f136e629af1e4bae8df1c02b7fdec6260 (diff) |
hwmon: (max6697) Convert to use devm_hwmon_device_register_with_groups
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/max6697.c')
-rw-r--r-- | drivers/hwmon/max6697.c | 54 |
1 files changed, 17 insertions, 37 deletions
diff --git a/drivers/hwmon/max6697.c b/drivers/hwmon/max6697.c index a41b5f3fc506..0af910a479ab 100644 --- a/drivers/hwmon/max6697.c +++ b/drivers/hwmon/max6697.c | |||
@@ -77,7 +77,7 @@ struct max6697_chip_data { | |||
77 | }; | 77 | }; |
78 | 78 | ||
79 | struct max6697_data { | 79 | struct max6697_data { |
80 | struct device *hwmon_dev; | 80 | struct i2c_client *client; |
81 | 81 | ||
82 | enum chips type; | 82 | enum chips type; |
83 | const struct max6697_chip_data *chip; | 83 | const struct max6697_chip_data *chip; |
@@ -181,8 +181,8 @@ static const struct max6697_chip_data max6697_chip_data[] = { | |||
181 | 181 | ||
182 | static struct max6697_data *max6697_update_device(struct device *dev) | 182 | static struct max6697_data *max6697_update_device(struct device *dev) |
183 | { | 183 | { |
184 | struct i2c_client *client = to_i2c_client(dev); | 184 | struct max6697_data *data = dev_get_drvdata(dev); |
185 | struct max6697_data *data = i2c_get_clientdata(client); | 185 | struct i2c_client *client = data->client; |
186 | struct max6697_data *ret = data; | 186 | struct max6697_data *ret = data; |
187 | int val; | 187 | int val; |
188 | int i; | 188 | int i; |
@@ -303,8 +303,7 @@ static ssize_t set_temp(struct device *dev, | |||
303 | { | 303 | { |
304 | int nr = to_sensor_dev_attr_2(devattr)->nr; | 304 | int nr = to_sensor_dev_attr_2(devattr)->nr; |
305 | int index = to_sensor_dev_attr_2(devattr)->index; | 305 | int index = to_sensor_dev_attr_2(devattr)->index; |
306 | struct i2c_client *client = to_i2c_client(dev); | 306 | struct max6697_data *data = dev_get_drvdata(dev); |
307 | struct max6697_data *data = i2c_get_clientdata(client); | ||
308 | long temp; | 307 | long temp; |
309 | int ret; | 308 | int ret; |
310 | 309 | ||
@@ -316,7 +315,7 @@ static ssize_t set_temp(struct device *dev, | |||
316 | temp = DIV_ROUND_CLOSEST(temp, 1000) + data->temp_offset; | 315 | temp = DIV_ROUND_CLOSEST(temp, 1000) + data->temp_offset; |
317 | temp = clamp_val(temp, 0, data->type == max6581 ? 255 : 127); | 316 | temp = clamp_val(temp, 0, data->type == max6581 ? 255 : 127); |
318 | data->temp[nr][index] = temp; | 317 | data->temp[nr][index] = temp; |
319 | ret = i2c_smbus_write_byte_data(client, | 318 | ret = i2c_smbus_write_byte_data(data->client, |
320 | index == 2 ? MAX6697_REG_MAX[nr] | 319 | index == 2 ? MAX6697_REG_MAX[nr] |
321 | : MAX6697_REG_CRIT[nr], | 320 | : MAX6697_REG_CRIT[nr], |
322 | temp); | 321 | temp); |
@@ -405,8 +404,7 @@ static umode_t max6697_is_visible(struct kobject *kobj, struct attribute *attr, | |||
405 | int index) | 404 | int index) |
406 | { | 405 | { |
407 | struct device *dev = container_of(kobj, struct device, kobj); | 406 | struct device *dev = container_of(kobj, struct device, kobj); |
408 | struct i2c_client *client = to_i2c_client(dev); | 407 | struct max6697_data *data = dev_get_drvdata(dev); |
409 | struct max6697_data *data = i2c_get_clientdata(client); | ||
410 | const struct max6697_chip_data *chip = data->chip; | 408 | const struct max6697_chip_data *chip = data->chip; |
411 | int channel = index / 6; /* channel number */ | 409 | int channel = index / 6; /* channel number */ |
412 | int nr = index % 6; /* attribute index within channel */ | 410 | int nr = index % 6; /* attribute index within channel */ |
@@ -489,6 +487,7 @@ static struct attribute *max6697_attributes[] = { | |||
489 | static const struct attribute_group max6697_group = { | 487 | static const struct attribute_group max6697_group = { |
490 | .attrs = max6697_attributes, .is_visible = max6697_is_visible, | 488 | .attrs = max6697_attributes, .is_visible = max6697_is_visible, |
491 | }; | 489 | }; |
490 | __ATTRIBUTE_GROUPS(max6697); | ||
492 | 491 | ||
493 | static void max6697_get_config_of(struct device_node *node, | 492 | static void max6697_get_config_of(struct device_node *node, |
494 | struct max6697_platform_data *pdata) | 493 | struct max6697_platform_data *pdata) |
@@ -525,9 +524,9 @@ static void max6697_get_config_of(struct device_node *node, | |||
525 | } | 524 | } |
526 | } | 525 | } |
527 | 526 | ||
528 | static int max6697_init_chip(struct i2c_client *client) | 527 | static int max6697_init_chip(struct max6697_data *data, |
528 | struct i2c_client *client) | ||
529 | { | 529 | { |
530 | struct max6697_data *data = i2c_get_clientdata(client); | ||
531 | struct max6697_platform_data *pdata = dev_get_platdata(&client->dev); | 530 | struct max6697_platform_data *pdata = dev_get_platdata(&client->dev); |
532 | struct max6697_platform_data p; | 531 | struct max6697_platform_data p; |
533 | const struct max6697_chip_data *chip = data->chip; | 532 | const struct max6697_chip_data *chip = data->chip; |
@@ -625,6 +624,7 @@ static int max6697_probe(struct i2c_client *client, | |||
625 | struct i2c_adapter *adapter = client->adapter; | 624 | struct i2c_adapter *adapter = client->adapter; |
626 | struct device *dev = &client->dev; | 625 | struct device *dev = &client->dev; |
627 | struct max6697_data *data; | 626 | struct max6697_data *data; |
627 | struct device *hwmon_dev; | ||
628 | int err; | 628 | int err; |
629 | 629 | ||
630 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 630 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
@@ -636,37 +636,18 @@ static int max6697_probe(struct i2c_client *client, | |||
636 | 636 | ||
637 | data->type = id->driver_data; | 637 | data->type = id->driver_data; |
638 | data->chip = &max6697_chip_data[data->type]; | 638 | data->chip = &max6697_chip_data[data->type]; |
639 | 639 | data->client = client; | |
640 | i2c_set_clientdata(client, data); | ||
641 | mutex_init(&data->update_lock); | 640 | mutex_init(&data->update_lock); |
642 | 641 | ||
643 | err = max6697_init_chip(client); | 642 | err = max6697_init_chip(data, client); |
644 | if (err) | 643 | if (err) |
645 | return err; | 644 | return err; |
646 | 645 | ||
647 | err = sysfs_create_group(&client->dev.kobj, &max6697_group); | 646 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
648 | if (err) | 647 | data, |
649 | return err; | 648 | max6697_groups); |
650 | 649 | if (IS_ERR(hwmon_dev)) | |
651 | data->hwmon_dev = hwmon_device_register(dev); | 650 | return PTR_ERR(hwmon_dev); |
652 | if (IS_ERR(data->hwmon_dev)) { | ||
653 | err = PTR_ERR(data->hwmon_dev); | ||
654 | goto error; | ||
655 | } | ||
656 | |||
657 | return 0; | ||
658 | |||
659 | error: | ||
660 | sysfs_remove_group(&client->dev.kobj, &max6697_group); | ||
661 | return err; | ||
662 | } | ||
663 | |||
664 | static int max6697_remove(struct i2c_client *client) | ||
665 | { | ||
666 | struct max6697_data *data = i2c_get_clientdata(client); | ||
667 | |||
668 | hwmon_device_unregister(data->hwmon_dev); | ||
669 | sysfs_remove_group(&client->dev.kobj, &max6697_group); | ||
670 | 651 | ||
671 | return 0; | 652 | return 0; |
672 | } | 653 | } |
@@ -692,7 +673,6 @@ static struct i2c_driver max6697_driver = { | |||
692 | .name = "max6697", | 673 | .name = "max6697", |
693 | }, | 674 | }, |
694 | .probe = max6697_probe, | 675 | .probe = max6697_probe, |
695 | .remove = max6697_remove, | ||
696 | .id_table = max6697_id, | 676 | .id_table = max6697_id, |
697 | }; | 677 | }; |
698 | 678 | ||