diff options
-rw-r--r-- | drivers/hwmon/adm1031.c | 101 |
1 files changed, 38 insertions, 63 deletions
diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c index 9f3cb80a17c7..a5818980dad7 100644 --- a/drivers/hwmon/adm1031.c +++ b/drivers/hwmon/adm1031.c | |||
@@ -74,7 +74,8 @@ typedef u8 auto_chan_table_t[8][2]; | |||
74 | 74 | ||
75 | /* Each client has this additional data */ | 75 | /* Each client has this additional data */ |
76 | struct adm1031_data { | 76 | struct adm1031_data { |
77 | struct device *hwmon_dev; | 77 | struct i2c_client *client; |
78 | const struct attribute_group *groups[3]; | ||
78 | struct mutex update_lock; | 79 | struct mutex update_lock; |
79 | int chip_type; | 80 | int chip_type; |
80 | char valid; /* !=0 if following fields are valid */ | 81 | char valid; /* !=0 if following fields are valid */ |
@@ -118,8 +119,8 @@ adm1031_write_value(struct i2c_client *client, u8 reg, unsigned int value) | |||
118 | 119 | ||
119 | static struct adm1031_data *adm1031_update_device(struct device *dev) | 120 | static struct adm1031_data *adm1031_update_device(struct device *dev) |
120 | { | 121 | { |
121 | struct i2c_client *client = to_i2c_client(dev); | 122 | struct adm1031_data *data = dev_get_drvdata(dev); |
122 | struct adm1031_data *data = i2c_get_clientdata(client); | 123 | struct i2c_client *client = data->client; |
123 | unsigned long next_update; | 124 | unsigned long next_update; |
124 | int chan; | 125 | int chan; |
125 | 126 | ||
@@ -342,8 +343,8 @@ static ssize_t | |||
342 | set_fan_auto_channel(struct device *dev, struct device_attribute *attr, | 343 | set_fan_auto_channel(struct device *dev, struct device_attribute *attr, |
343 | const char *buf, size_t count) | 344 | const char *buf, size_t count) |
344 | { | 345 | { |
345 | struct i2c_client *client = to_i2c_client(dev); | 346 | struct adm1031_data *data = dev_get_drvdata(dev); |
346 | struct adm1031_data *data = i2c_get_clientdata(client); | 347 | struct i2c_client *client = data->client; |
347 | int nr = to_sensor_dev_attr(attr)->index; | 348 | int nr = to_sensor_dev_attr(attr)->index; |
348 | long val; | 349 | long val; |
349 | u8 reg; | 350 | u8 reg; |
@@ -417,8 +418,8 @@ static ssize_t | |||
417 | set_auto_temp_min(struct device *dev, struct device_attribute *attr, | 418 | set_auto_temp_min(struct device *dev, struct device_attribute *attr, |
418 | const char *buf, size_t count) | 419 | const char *buf, size_t count) |
419 | { | 420 | { |
420 | struct i2c_client *client = to_i2c_client(dev); | 421 | struct adm1031_data *data = dev_get_drvdata(dev); |
421 | struct adm1031_data *data = i2c_get_clientdata(client); | 422 | struct i2c_client *client = data->client; |
422 | int nr = to_sensor_dev_attr(attr)->index; | 423 | int nr = to_sensor_dev_attr(attr)->index; |
423 | long val; | 424 | long val; |
424 | int ret; | 425 | int ret; |
@@ -447,8 +448,8 @@ static ssize_t | |||
447 | set_auto_temp_max(struct device *dev, struct device_attribute *attr, | 448 | set_auto_temp_max(struct device *dev, struct device_attribute *attr, |
448 | const char *buf, size_t count) | 449 | const char *buf, size_t count) |
449 | { | 450 | { |
450 | struct i2c_client *client = to_i2c_client(dev); | 451 | struct adm1031_data *data = dev_get_drvdata(dev); |
451 | struct adm1031_data *data = i2c_get_clientdata(client); | 452 | struct i2c_client *client = data->client; |
452 | int nr = to_sensor_dev_attr(attr)->index; | 453 | int nr = to_sensor_dev_attr(attr)->index; |
453 | long val; | 454 | long val; |
454 | int ret; | 455 | int ret; |
@@ -490,8 +491,8 @@ static ssize_t show_pwm(struct device *dev, | |||
490 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | 491 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, |
491 | const char *buf, size_t count) | 492 | const char *buf, size_t count) |
492 | { | 493 | { |
493 | struct i2c_client *client = to_i2c_client(dev); | 494 | struct adm1031_data *data = dev_get_drvdata(dev); |
494 | struct adm1031_data *data = i2c_get_clientdata(client); | 495 | struct i2c_client *client = data->client; |
495 | int nr = to_sensor_dev_attr(attr)->index; | 496 | int nr = to_sensor_dev_attr(attr)->index; |
496 | long val; | 497 | long val; |
497 | int ret, reg; | 498 | int ret, reg; |
@@ -603,8 +604,8 @@ static ssize_t show_fan_min(struct device *dev, | |||
603 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | 604 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, |
604 | const char *buf, size_t count) | 605 | const char *buf, size_t count) |
605 | { | 606 | { |
606 | struct i2c_client *client = to_i2c_client(dev); | 607 | struct adm1031_data *data = dev_get_drvdata(dev); |
607 | struct adm1031_data *data = i2c_get_clientdata(client); | 608 | struct i2c_client *client = data->client; |
608 | int nr = to_sensor_dev_attr(attr)->index; | 609 | int nr = to_sensor_dev_attr(attr)->index; |
609 | long val; | 610 | long val; |
610 | int ret; | 611 | int ret; |
@@ -627,8 +628,8 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | |||
627 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | 628 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, |
628 | const char *buf, size_t count) | 629 | const char *buf, size_t count) |
629 | { | 630 | { |
630 | struct i2c_client *client = to_i2c_client(dev); | 631 | struct adm1031_data *data = dev_get_drvdata(dev); |
631 | struct adm1031_data *data = i2c_get_clientdata(client); | 632 | struct i2c_client *client = data->client; |
632 | int nr = to_sensor_dev_attr(attr)->index; | 633 | int nr = to_sensor_dev_attr(attr)->index; |
633 | long val; | 634 | long val; |
634 | u8 tmp; | 635 | u8 tmp; |
@@ -729,8 +730,8 @@ static ssize_t set_temp_offset(struct device *dev, | |||
729 | struct device_attribute *attr, const char *buf, | 730 | struct device_attribute *attr, const char *buf, |
730 | size_t count) | 731 | size_t count) |
731 | { | 732 | { |
732 | struct i2c_client *client = to_i2c_client(dev); | 733 | struct adm1031_data *data = dev_get_drvdata(dev); |
733 | struct adm1031_data *data = i2c_get_clientdata(client); | 734 | struct i2c_client *client = data->client; |
734 | int nr = to_sensor_dev_attr(attr)->index; | 735 | int nr = to_sensor_dev_attr(attr)->index; |
735 | long val; | 736 | long val; |
736 | int ret; | 737 | int ret; |
@@ -750,8 +751,8 @@ static ssize_t set_temp_offset(struct device *dev, | |||
750 | static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | 751 | static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, |
751 | const char *buf, size_t count) | 752 | const char *buf, size_t count) |
752 | { | 753 | { |
753 | struct i2c_client *client = to_i2c_client(dev); | 754 | struct adm1031_data *data = dev_get_drvdata(dev); |
754 | struct adm1031_data *data = i2c_get_clientdata(client); | 755 | struct i2c_client *client = data->client; |
755 | int nr = to_sensor_dev_attr(attr)->index; | 756 | int nr = to_sensor_dev_attr(attr)->index; |
756 | long val; | 757 | long val; |
757 | int ret; | 758 | int ret; |
@@ -771,8 +772,8 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | |||
771 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | 772 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, |
772 | const char *buf, size_t count) | 773 | const char *buf, size_t count) |
773 | { | 774 | { |
774 | struct i2c_client *client = to_i2c_client(dev); | 775 | struct adm1031_data *data = dev_get_drvdata(dev); |
775 | struct adm1031_data *data = i2c_get_clientdata(client); | 776 | struct i2c_client *client = data->client; |
776 | int nr = to_sensor_dev_attr(attr)->index; | 777 | int nr = to_sensor_dev_attr(attr)->index; |
777 | long val; | 778 | long val; |
778 | int ret; | 779 | int ret; |
@@ -792,8 +793,8 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
792 | static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr, | 793 | static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr, |
793 | const char *buf, size_t count) | 794 | const char *buf, size_t count) |
794 | { | 795 | { |
795 | struct i2c_client *client = to_i2c_client(dev); | 796 | struct adm1031_data *data = dev_get_drvdata(dev); |
796 | struct adm1031_data *data = i2c_get_clientdata(client); | 797 | struct i2c_client *client = data->client; |
797 | int nr = to_sensor_dev_attr(attr)->index; | 798 | int nr = to_sensor_dev_attr(attr)->index; |
798 | long val; | 799 | long val; |
799 | int ret; | 800 | int ret; |
@@ -869,8 +870,7 @@ static const unsigned int update_intervals[] = { | |||
869 | static ssize_t show_update_interval(struct device *dev, | 870 | static ssize_t show_update_interval(struct device *dev, |
870 | struct device_attribute *attr, char *buf) | 871 | struct device_attribute *attr, char *buf) |
871 | { | 872 | { |
872 | struct i2c_client *client = to_i2c_client(dev); | 873 | struct adm1031_data *data = dev_get_drvdata(dev); |
873 | struct adm1031_data *data = i2c_get_clientdata(client); | ||
874 | 874 | ||
875 | return sprintf(buf, "%u\n", data->update_interval); | 875 | return sprintf(buf, "%u\n", data->update_interval); |
876 | } | 876 | } |
@@ -879,8 +879,8 @@ static ssize_t set_update_interval(struct device *dev, | |||
879 | struct device_attribute *attr, | 879 | struct device_attribute *attr, |
880 | const char *buf, size_t count) | 880 | const char *buf, size_t count) |
881 | { | 881 | { |
882 | struct i2c_client *client = to_i2c_client(dev); | 882 | struct adm1031_data *data = dev_get_drvdata(dev); |
883 | struct adm1031_data *data = i2c_get_clientdata(client); | 883 | struct i2c_client *client = data->client; |
884 | unsigned long val; | 884 | unsigned long val; |
885 | int i, err; | 885 | int i, err; |
886 | u8 reg; | 886 | u8 reg; |
@@ -1046,15 +1046,16 @@ static void adm1031_init_client(struct i2c_client *client) | |||
1046 | static int adm1031_probe(struct i2c_client *client, | 1046 | static int adm1031_probe(struct i2c_client *client, |
1047 | const struct i2c_device_id *id) | 1047 | const struct i2c_device_id *id) |
1048 | { | 1048 | { |
1049 | struct device *dev = &client->dev; | ||
1050 | struct device *hwmon_dev; | ||
1049 | struct adm1031_data *data; | 1051 | struct adm1031_data *data; |
1050 | int err; | ||
1051 | 1052 | ||
1052 | data = devm_kzalloc(&client->dev, sizeof(struct adm1031_data), | 1053 | data = devm_kzalloc(dev, sizeof(struct adm1031_data), GFP_KERNEL); |
1053 | GFP_KERNEL); | ||
1054 | if (!data) | 1054 | if (!data) |
1055 | return -ENOMEM; | 1055 | return -ENOMEM; |
1056 | 1056 | ||
1057 | i2c_set_clientdata(client, data); | 1057 | i2c_set_clientdata(client, data); |
1058 | data->client = client; | ||
1058 | data->chip_type = id->driver_data; | 1059 | data->chip_type = id->driver_data; |
1059 | mutex_init(&data->update_lock); | 1060 | mutex_init(&data->update_lock); |
1060 | 1061 | ||
@@ -1066,39 +1067,14 @@ static int adm1031_probe(struct i2c_client *client, | |||
1066 | /* Initialize the ADM1031 chip */ | 1067 | /* Initialize the ADM1031 chip */ |
1067 | adm1031_init_client(client); | 1068 | adm1031_init_client(client); |
1068 | 1069 | ||
1069 | /* Register sysfs hooks */ | 1070 | /* sysfs hooks */ |
1070 | err = sysfs_create_group(&client->dev.kobj, &adm1031_group); | 1071 | data->groups[0] = &adm1031_group; |
1071 | if (err) | 1072 | if (data->chip_type == adm1031) |
1072 | return err; | 1073 | data->groups[1] = &adm1031_group_opt; |
1073 | |||
1074 | if (data->chip_type == adm1031) { | ||
1075 | err = sysfs_create_group(&client->dev.kobj, &adm1031_group_opt); | ||
1076 | if (err) | ||
1077 | goto exit_remove; | ||
1078 | } | ||
1079 | |||
1080 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
1081 | if (IS_ERR(data->hwmon_dev)) { | ||
1082 | err = PTR_ERR(data->hwmon_dev); | ||
1083 | goto exit_remove; | ||
1084 | } | ||
1085 | 1074 | ||
1086 | return 0; | 1075 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
1087 | 1076 | data, data->groups); | |
1088 | exit_remove: | 1077 | return PTR_ERR_OR_ZERO(hwmon_dev); |
1089 | sysfs_remove_group(&client->dev.kobj, &adm1031_group); | ||
1090 | sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt); | ||
1091 | return err; | ||
1092 | } | ||
1093 | |||
1094 | static int adm1031_remove(struct i2c_client *client) | ||
1095 | { | ||
1096 | struct adm1031_data *data = i2c_get_clientdata(client); | ||
1097 | |||
1098 | hwmon_device_unregister(data->hwmon_dev); | ||
1099 | sysfs_remove_group(&client->dev.kobj, &adm1031_group); | ||
1100 | sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt); | ||
1101 | return 0; | ||
1102 | } | 1078 | } |
1103 | 1079 | ||
1104 | static const struct i2c_device_id adm1031_id[] = { | 1080 | static const struct i2c_device_id adm1031_id[] = { |
@@ -1114,7 +1090,6 @@ static struct i2c_driver adm1031_driver = { | |||
1114 | .name = "adm1031", | 1090 | .name = "adm1031", |
1115 | }, | 1091 | }, |
1116 | .probe = adm1031_probe, | 1092 | .probe = adm1031_probe, |
1117 | .remove = adm1031_remove, | ||
1118 | .id_table = adm1031_id, | 1093 | .id_table = adm1031_id, |
1119 | .detect = adm1031_detect, | 1094 | .detect = adm1031_detect, |
1120 | .address_list = normal_i2c, | 1095 | .address_list = normal_i2c, |