diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-11-12 00:44:34 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-11-12 00:44:34 -0500 |
commit | 7e238a2ecd117e16b154e1b0ed77906596600ff5 (patch) | |
tree | 37a1fc3d15ba9873f16efb21556f619fbea4b492 /drivers | |
parent | 66a173b926891023e34e78cb32f4681d19777e01 (diff) | |
parent | 26336c8a36c0a6a28b9ecf6f1bb8c8f5605d6a21 (diff) |
Merge tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging
Pull hwmon updates from Guenter Roeck:
"Introduce new hwmon API functions hwmon_device_register_with_groups
and devm_hwmon_device_register_with_groups, and convert several
drivers to use the new API.
Add support for EMC1404, EMC1424, LTC2977, LTC2978A, LM25063 to
existing drivers
Various cleanups in several drivers"
* tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: (49 commits)
hwmon: (w83793) Clean up a signedness issue
hwmon: (nct6775) Remove an unused variable
hwmon: (emc1403) Add support for EMC1404 and EMC1424
hwmon: (emc1403) Convert to use devm_hwmon_device_register_with_groups
hwmon: (pmbus/ltc2978): Add support for LTC2978A
hwmon: (pmbus/ltc2978): Add support for LTC2977
hwmon: (pmbus/lm25066) Add support for LM25063
hwmon: Correct some typos
hwmon: (gpio-fan) Include linux/of.h header
hwmon: (lm70) Remove redundant spi_set_drvdata
hwmon: (adcxx) Remove redundant spi_set_drvdata
hwmon: (jc42) fix coccinelle warnings
hwmon: (ltc4261) fix coccinelle warnings
hwmon: (lm95234) fix coccinelle warnings
hwmon: (max6697) fix coccinelle warnings
hwmon: (max6642 fix coccinelle warnings
hwmon: (ds1621) fix coccinelle warnings
hwmon: (nct6775) fix coccinelle warnings
hwmon: (jc42) Convert to use devm_hwmon_device_register_with_groups
hwmon: (ltc4261) Convert to use devm_hwmon_device_register_with_groups
...
Diffstat (limited to 'drivers')
36 files changed, 746 insertions, 871 deletions
diff --git a/drivers/hwmon/abituguru.c b/drivers/hwmon/abituguru.c index 2ebd6ce46108..9c8a6bab8228 100644 --- a/drivers/hwmon/abituguru.c +++ b/drivers/hwmon/abituguru.c | |||
@@ -164,7 +164,7 @@ static const u8 abituguru_bank2_max_threshold = 50; | |||
164 | static const int abituguru_pwm_settings_multiplier[5] = { 0, 1, 1, 1000, 1000 }; | 164 | static const int abituguru_pwm_settings_multiplier[5] = { 0, 1, 1, 1000, 1000 }; |
165 | /* | 165 | /* |
166 | * Min / Max allowed values for pwm_settings. Note: pwm1 (CPU fan) is a | 166 | * Min / Max allowed values for pwm_settings. Note: pwm1 (CPU fan) is a |
167 | * special case the minium allowed pwm% setting for this is 30% (77) on | 167 | * special case the minimum allowed pwm% setting for this is 30% (77) on |
168 | * some MB's this special case is handled in the code! | 168 | * some MB's this special case is handled in the code! |
169 | */ | 169 | */ |
170 | static const u8 abituguru_pwm_min[5] = { 0, 170, 170, 25, 25 }; | 170 | static const u8 abituguru_pwm_min[5] = { 0, 170, 170, 25, 25 }; |
@@ -517,7 +517,7 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data, | |||
517 | 517 | ||
518 | ABIT_UGURU_DEBUG(2, "testing bank1 sensor %d\n", (int)sensor_addr); | 518 | ABIT_UGURU_DEBUG(2, "testing bank1 sensor %d\n", (int)sensor_addr); |
519 | /* | 519 | /* |
520 | * Volt sensor test, enable volt low alarm, set min value ridicously | 520 | * Volt sensor test, enable volt low alarm, set min value ridiculously |
521 | * high, or vica versa if the reading is very high. If its a volt | 521 | * high, or vica versa if the reading is very high. If its a volt |
522 | * sensor this should always give us an alarm. | 522 | * sensor this should always give us an alarm. |
523 | */ | 523 | */ |
@@ -564,7 +564,7 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data, | |||
564 | 564 | ||
565 | /* | 565 | /* |
566 | * Temp sensor test, enable sensor as a temp sensor, set beep value | 566 | * Temp sensor test, enable sensor as a temp sensor, set beep value |
567 | * ridicously low (but not too low, otherwise uguru ignores it). | 567 | * ridiculously low (but not too low, otherwise uguru ignores it). |
568 | * If its a temp sensor this should always give us an alarm. | 568 | * If its a temp sensor this should always give us an alarm. |
569 | */ | 569 | */ |
570 | buf[0] = ABIT_UGURU_TEMP_HIGH_ALARM_ENABLE; | 570 | buf[0] = ABIT_UGURU_TEMP_HIGH_ALARM_ENABLE; |
diff --git a/drivers/hwmon/abituguru3.c b/drivers/hwmon/abituguru3.c index 0cac8c0b001a..4ae74aa8cdc1 100644 --- a/drivers/hwmon/abituguru3.c +++ b/drivers/hwmon/abituguru3.c | |||
@@ -176,7 +176,7 @@ struct abituguru3_data { | |||
176 | 176 | ||
177 | /* | 177 | /* |
178 | * The abituguru3 supports up to 48 sensors, and thus has registers | 178 | * The abituguru3 supports up to 48 sensors, and thus has registers |
179 | * sets for 48 sensors, for convienence reasons / simplicity of the | 179 | * sets for 48 sensors, for convenience reasons / simplicity of the |
180 | * code we always read and store all registers for all 48 sensors | 180 | * code we always read and store all registers for all 48 sensors |
181 | */ | 181 | */ |
182 | 182 | ||
diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c index a9e3d0152c0b..8d40da314a8e 100644 --- a/drivers/hwmon/acpi_power_meter.c +++ b/drivers/hwmon/acpi_power_meter.c | |||
@@ -381,8 +381,10 @@ static ssize_t show_str(struct device *dev, | |||
381 | val = resource->oem_info; | 381 | val = resource->oem_info; |
382 | break; | 382 | break; |
383 | default: | 383 | default: |
384 | BUG(); | 384 | WARN(1, "Implementation error: unexpected attribute index %d\n", |
385 | attr->index); | ||
385 | val = ""; | 386 | val = ""; |
387 | break; | ||
386 | } | 388 | } |
387 | 389 | ||
388 | return sprintf(buf, "%s\n", val); | 390 | return sprintf(buf, "%s\n", val); |
@@ -436,7 +438,9 @@ static ssize_t show_val(struct device *dev, | |||
436 | val = resource->trip[attr->index - 7] * 1000; | 438 | val = resource->trip[attr->index - 7] * 1000; |
437 | break; | 439 | break; |
438 | default: | 440 | default: |
439 | BUG(); | 441 | WARN(1, "Implementation error: unexpected attribute index %d\n", |
442 | attr->index); | ||
443 | break; | ||
440 | } | 444 | } |
441 | 445 | ||
442 | return sprintf(buf, "%llu\n", val); | 446 | return sprintf(buf, "%llu\n", val); |
@@ -855,7 +859,8 @@ static void acpi_power_meter_notify(struct acpi_device *device, u32 event) | |||
855 | dev_info(&device->dev, "Capping in progress.\n"); | 859 | dev_info(&device->dev, "Capping in progress.\n"); |
856 | break; | 860 | break; |
857 | default: | 861 | default: |
858 | BUG(); | 862 | WARN(1, "Unexpected event %d\n", event); |
863 | break; | ||
859 | } | 864 | } |
860 | mutex_unlock(&resource->lock); | 865 | mutex_unlock(&resource->lock); |
861 | 866 | ||
@@ -991,7 +996,7 @@ static int __init acpi_power_meter_init(void) | |||
991 | 996 | ||
992 | result = acpi_bus_register_driver(&acpi_power_meter_driver); | 997 | result = acpi_bus_register_driver(&acpi_power_meter_driver); |
993 | if (result < 0) | 998 | if (result < 0) |
994 | return -ENODEV; | 999 | return result; |
995 | 1000 | ||
996 | return 0; | 1001 | return 0; |
997 | } | 1002 | } |
diff --git a/drivers/hwmon/adcxx.c b/drivers/hwmon/adcxx.c index 751b1f0264a4..04c08c2f79b8 100644 --- a/drivers/hwmon/adcxx.c +++ b/drivers/hwmon/adcxx.c | |||
@@ -203,7 +203,6 @@ out_err: | |||
203 | for (i--; i >= 0; i--) | 203 | for (i--; i >= 0; i--) |
204 | device_remove_file(&spi->dev, &ad_input[i].dev_attr); | 204 | device_remove_file(&spi->dev, &ad_input[i].dev_attr); |
205 | 205 | ||
206 | spi_set_drvdata(spi, NULL); | ||
207 | mutex_unlock(&adc->lock); | 206 | mutex_unlock(&adc->lock); |
208 | return status; | 207 | return status; |
209 | } | 208 | } |
@@ -218,7 +217,6 @@ static int adcxx_remove(struct spi_device *spi) | |||
218 | for (i = 0; i < 3 + adc->channels; i++) | 217 | for (i = 0; i < 3 + adc->channels; i++) |
219 | device_remove_file(&spi->dev, &ad_input[i].dev_attr); | 218 | device_remove_file(&spi->dev, &ad_input[i].dev_attr); |
220 | 219 | ||
221 | spi_set_drvdata(spi, NULL); | ||
222 | mutex_unlock(&adc->lock); | 220 | mutex_unlock(&adc->lock); |
223 | 221 | ||
224 | return 0; | 222 | return 0; |
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c index 3a6d9ef1c16c..b3498acb9ab4 100644 --- a/drivers/hwmon/adm1026.c +++ b/drivers/hwmon/adm1026.c | |||
@@ -616,7 +616,7 @@ static struct adm1026_data *adm1026_update_device(struct device *dev) | |||
616 | data->gpio = gpio; | 616 | data->gpio = gpio; |
617 | 617 | ||
618 | data->last_reading = jiffies; | 618 | data->last_reading = jiffies; |
619 | }; /* last_reading */ | 619 | } /* last_reading */ |
620 | 620 | ||
621 | if (!data->valid || | 621 | if (!data->valid || |
622 | time_after(jiffies, data->last_config + ADM1026_CONFIG_INTERVAL)) { | 622 | time_after(jiffies, data->last_config + ADM1026_CONFIG_INTERVAL)) { |
@@ -700,7 +700,7 @@ static struct adm1026_data *adm1026_update_device(struct device *dev) | |||
700 | } | 700 | } |
701 | 701 | ||
702 | data->last_config = jiffies; | 702 | data->last_config = jiffies; |
703 | }; /* last_config */ | 703 | } /* last_config */ |
704 | 704 | ||
705 | data->valid = 1; | 705 | data->valid = 1; |
706 | mutex_unlock(&data->update_lock); | 706 | mutex_unlock(&data->update_lock); |
@@ -1791,7 +1791,7 @@ static int adm1026_detect(struct i2c_client *client, | |||
1791 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 1791 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
1792 | /* We need to be able to do byte I/O */ | 1792 | /* We need to be able to do byte I/O */ |
1793 | return -ENODEV; | 1793 | return -ENODEV; |
1794 | }; | 1794 | } |
1795 | 1795 | ||
1796 | /* Now, we do the remaining detection. */ | 1796 | /* Now, we do the remaining detection. */ |
1797 | 1797 | ||
diff --git a/drivers/hwmon/adt7462.c b/drivers/hwmon/adt7462.c index addb5a4d5064..562cc3881d33 100644 --- a/drivers/hwmon/adt7462.c +++ b/drivers/hwmon/adt7462.c | |||
@@ -700,7 +700,7 @@ static int find_trange_value(int trange) | |||
700 | if (trange_values[i] == trange) | 700 | if (trange_values[i] == trange) |
701 | return i; | 701 | return i; |
702 | 702 | ||
703 | return -ENODEV; | 703 | return -EINVAL; |
704 | } | 704 | } |
705 | 705 | ||
706 | static struct adt7462_data *adt7462_update_device(struct device *dev) | 706 | static struct adt7462_data *adt7462_update_device(struct device *dev) |
@@ -1294,9 +1294,8 @@ static ssize_t set_pwm_tmax(struct device *dev, | |||
1294 | /* trange = tmax - tmin */ | 1294 | /* trange = tmax - tmin */ |
1295 | tmin = (data->pwm_tmin[attr->index] - 64) * 1000; | 1295 | tmin = (data->pwm_tmin[attr->index] - 64) * 1000; |
1296 | trange_value = find_trange_value(trange - tmin); | 1296 | trange_value = find_trange_value(trange - tmin); |
1297 | |||
1298 | if (trange_value < 0) | 1297 | if (trange_value < 0) |
1299 | return -EINVAL; | 1298 | return trange_value; |
1300 | 1299 | ||
1301 | temp = trange_value << ADT7462_PWM_RANGE_SHIFT; | 1300 | temp = trange_value << ADT7462_PWM_RANGE_SHIFT; |
1302 | temp |= data->pwm_trange[attr->index] & ADT7462_PWM_HYST_MASK; | 1301 | temp |= data->pwm_trange[attr->index] & ADT7462_PWM_HYST_MASK; |
diff --git a/drivers/hwmon/asc7621.c b/drivers/hwmon/asc7621.c index 3ad9d849add2..8d9f2a0e8efe 100644 --- a/drivers/hwmon/asc7621.c +++ b/drivers/hwmon/asc7621.c | |||
@@ -138,7 +138,7 @@ static inline u8 read_byte(struct i2c_client *client, u8 reg) | |||
138 | dev_err(&client->dev, | 138 | dev_err(&client->dev, |
139 | "Unable to read from register 0x%02x.\n", reg); | 139 | "Unable to read from register 0x%02x.\n", reg); |
140 | return 0; | 140 | return 0; |
141 | }; | 141 | } |
142 | return res & 0xff; | 142 | return res & 0xff; |
143 | } | 143 | } |
144 | 144 | ||
@@ -149,7 +149,7 @@ static inline int write_byte(struct i2c_client *client, u8 reg, u8 data) | |||
149 | dev_err(&client->dev, | 149 | dev_err(&client->dev, |
150 | "Unable to write value 0x%02x to register 0x%02x.\n", | 150 | "Unable to write value 0x%02x to register 0x%02x.\n", |
151 | data, reg); | 151 | data, reg); |
152 | }; | 152 | } |
153 | return res; | 153 | return res; |
154 | } | 154 | } |
155 | 155 | ||
@@ -1030,7 +1030,7 @@ static struct asc7621_data *asc7621_update_device(struct device *dev) | |||
1030 | } | 1030 | } |
1031 | } | 1031 | } |
1032 | data->last_high_reading = jiffies; | 1032 | data->last_high_reading = jiffies; |
1033 | }; /* last_reading */ | 1033 | } /* last_reading */ |
1034 | 1034 | ||
1035 | /* Read all the low priority registers. */ | 1035 | /* Read all the low priority registers. */ |
1036 | 1036 | ||
@@ -1044,7 +1044,7 @@ static struct asc7621_data *asc7621_update_device(struct device *dev) | |||
1044 | } | 1044 | } |
1045 | } | 1045 | } |
1046 | data->last_low_reading = jiffies; | 1046 | data->last_low_reading = jiffies; |
1047 | }; /* last_reading */ | 1047 | } /* last_reading */ |
1048 | 1048 | ||
1049 | data->valid = 1; | 1049 | data->valid = 1; |
1050 | 1050 | ||
@@ -1084,11 +1084,11 @@ static void asc7621_init_client(struct i2c_client *client) | |||
1084 | dev_err(&client->dev, | 1084 | dev_err(&client->dev, |
1085 | "Client (%d,0x%02x) config is locked.\n", | 1085 | "Client (%d,0x%02x) config is locked.\n", |
1086 | i2c_adapter_id(client->adapter), client->addr); | 1086 | i2c_adapter_id(client->adapter), client->addr); |
1087 | }; | 1087 | } |
1088 | if (!(value & 0x04)) { | 1088 | if (!(value & 0x04)) { |
1089 | dev_err(&client->dev, "Client (%d,0x%02x) is not ready.\n", | 1089 | dev_err(&client->dev, "Client (%d,0x%02x) is not ready.\n", |
1090 | i2c_adapter_id(client->adapter), client->addr); | 1090 | i2c_adapter_id(client->adapter), client->addr); |
1091 | }; | 1091 | } |
1092 | 1092 | ||
1093 | /* | 1093 | /* |
1094 | * Start monitoring | 1094 | * Start monitoring |
diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c index b25c64302cbc..1d7ff46812c3 100644 --- a/drivers/hwmon/asus_atk0110.c +++ b/drivers/hwmon/asus_atk0110.c | |||
@@ -119,7 +119,7 @@ struct atk_data { | |||
119 | acpi_handle rtmp_handle; | 119 | acpi_handle rtmp_handle; |
120 | acpi_handle rvlt_handle; | 120 | acpi_handle rvlt_handle; |
121 | acpi_handle rfan_handle; | 121 | acpi_handle rfan_handle; |
122 | /* new inteface */ | 122 | /* new interface */ |
123 | acpi_handle enumerate_handle; | 123 | acpi_handle enumerate_handle; |
124 | acpi_handle read_handle; | 124 | acpi_handle read_handle; |
125 | acpi_handle write_handle; | 125 | acpi_handle write_handle; |
diff --git a/drivers/hwmon/atxp1.c b/drivers/hwmon/atxp1.c index aecb9ea7beb5..ddff02e3e66f 100644 --- a/drivers/hwmon/atxp1.c +++ b/drivers/hwmon/atxp1.c | |||
@@ -147,10 +147,9 @@ static ssize_t atxp1_storevcore(struct device *dev, | |||
147 | 147 | ||
148 | /* Calculate VID */ | 148 | /* Calculate VID */ |
149 | vid = vid_to_reg(vcore, data->vrm); | 149 | vid = vid_to_reg(vcore, data->vrm); |
150 | |||
151 | if (vid < 0) { | 150 | if (vid < 0) { |
152 | dev_err(dev, "VID calculation failed.\n"); | 151 | dev_err(dev, "VID calculation failed.\n"); |
153 | return -1; | 152 | return vid; |
154 | } | 153 | } |
155 | 154 | ||
156 | /* | 155 | /* |
diff --git a/drivers/hwmon/ds1621.c b/drivers/hwmon/ds1621.c index a26ba7a17c2b..872d76744e30 100644 --- a/drivers/hwmon/ds1621.c +++ b/drivers/hwmon/ds1621.c | |||
@@ -120,7 +120,7 @@ static const u8 DS1621_REG_TEMP[3] = { | |||
120 | 120 | ||
121 | /* Each client has this additional data */ | 121 | /* Each client has this additional data */ |
122 | struct ds1621_data { | 122 | struct ds1621_data { |
123 | struct device *hwmon_dev; | 123 | struct i2c_client *client; |
124 | struct mutex update_lock; | 124 | struct mutex update_lock; |
125 | char valid; /* !=0 if following fields are valid */ | 125 | char valid; /* !=0 if following fields are valid */ |
126 | unsigned long last_updated; /* In jiffies */ | 126 | unsigned long last_updated; /* In jiffies */ |
@@ -151,10 +151,10 @@ static inline u16 DS1621_TEMP_TO_REG(long temp, u8 zbits) | |||
151 | return temp; | 151 | return temp; |
152 | } | 152 | } |
153 | 153 | ||
154 | static void ds1621_init_client(struct i2c_client *client) | 154 | static void ds1621_init_client(struct ds1621_data *data, |
155 | struct i2c_client *client) | ||
155 | { | 156 | { |
156 | u8 conf, new_conf, sreg, resol; | 157 | u8 conf, new_conf, sreg, resol; |
157 | struct ds1621_data *data = i2c_get_clientdata(client); | ||
158 | 158 | ||
159 | new_conf = conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF); | 159 | new_conf = conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF); |
160 | /* switch to continuous conversion mode */ | 160 | /* switch to continuous conversion mode */ |
@@ -197,8 +197,8 @@ static void ds1621_init_client(struct i2c_client *client) | |||
197 | 197 | ||
198 | static struct ds1621_data *ds1621_update_client(struct device *dev) | 198 | static struct ds1621_data *ds1621_update_client(struct device *dev) |
199 | { | 199 | { |
200 | struct i2c_client *client = to_i2c_client(dev); | 200 | struct ds1621_data *data = dev_get_drvdata(dev); |
201 | struct ds1621_data *data = i2c_get_clientdata(client); | 201 | struct i2c_client *client = data->client; |
202 | u8 new_conf; | 202 | u8 new_conf; |
203 | 203 | ||
204 | mutex_lock(&data->update_lock); | 204 | mutex_lock(&data->update_lock); |
@@ -247,8 +247,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da, | |||
247 | const char *buf, size_t count) | 247 | const char *buf, size_t count) |
248 | { | 248 | { |
249 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | 249 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
250 | struct i2c_client *client = to_i2c_client(dev); | 250 | struct ds1621_data *data = dev_get_drvdata(dev); |
251 | struct ds1621_data *data = i2c_get_clientdata(client); | ||
252 | long val; | 251 | long val; |
253 | int err; | 252 | int err; |
254 | 253 | ||
@@ -258,7 +257,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da, | |||
258 | 257 | ||
259 | mutex_lock(&data->update_lock); | 258 | mutex_lock(&data->update_lock); |
260 | data->temp[attr->index] = DS1621_TEMP_TO_REG(val, data->zbits); | 259 | data->temp[attr->index] = DS1621_TEMP_TO_REG(val, data->zbits); |
261 | i2c_smbus_write_word_swapped(client, DS1621_REG_TEMP[attr->index], | 260 | i2c_smbus_write_word_swapped(data->client, DS1621_REG_TEMP[attr->index], |
262 | data->temp[attr->index]); | 261 | data->temp[attr->index]); |
263 | mutex_unlock(&data->update_lock); | 262 | mutex_unlock(&data->update_lock); |
264 | return count; | 263 | return count; |
@@ -282,16 +281,15 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute *da, | |||
282 | static ssize_t show_convrate(struct device *dev, struct device_attribute *da, | 281 | static ssize_t show_convrate(struct device *dev, struct device_attribute *da, |
283 | char *buf) | 282 | char *buf) |
284 | { | 283 | { |
285 | struct i2c_client *client = to_i2c_client(dev); | 284 | struct ds1621_data *data = dev_get_drvdata(dev); |
286 | struct ds1621_data *data = i2c_get_clientdata(client); | ||
287 | return scnprintf(buf, PAGE_SIZE, "%hu\n", data->update_interval); | 285 | return scnprintf(buf, PAGE_SIZE, "%hu\n", data->update_interval); |
288 | } | 286 | } |
289 | 287 | ||
290 | static ssize_t set_convrate(struct device *dev, struct device_attribute *da, | 288 | static ssize_t set_convrate(struct device *dev, struct device_attribute *da, |
291 | const char *buf, size_t count) | 289 | const char *buf, size_t count) |
292 | { | 290 | { |
293 | struct i2c_client *client = to_i2c_client(dev); | 291 | struct ds1621_data *data = dev_get_drvdata(dev); |
294 | struct ds1621_data *data = i2c_get_clientdata(client); | 292 | struct i2c_client *client = data->client; |
295 | unsigned long convrate; | 293 | unsigned long convrate; |
296 | s32 err; | 294 | s32 err; |
297 | int resol = 0; | 295 | int resol = 0; |
@@ -343,8 +341,7 @@ static umode_t ds1621_attribute_visible(struct kobject *kobj, | |||
343 | struct attribute *attr, int index) | 341 | struct attribute *attr, int index) |
344 | { | 342 | { |
345 | struct device *dev = container_of(kobj, struct device, kobj); | 343 | struct device *dev = container_of(kobj, struct device, kobj); |
346 | struct i2c_client *client = to_i2c_client(dev); | 344 | struct ds1621_data *data = dev_get_drvdata(dev); |
347 | struct ds1621_data *data = i2c_get_clientdata(client); | ||
348 | 345 | ||
349 | if (attr == &dev_attr_update_interval.attr) | 346 | if (attr == &dev_attr_update_interval.attr) |
350 | if (data->kind == ds1621 || data->kind == ds1625) | 347 | if (data->kind == ds1621 || data->kind == ds1625) |
@@ -357,52 +354,31 @@ static const struct attribute_group ds1621_group = { | |||
357 | .attrs = ds1621_attributes, | 354 | .attrs = ds1621_attributes, |
358 | .is_visible = ds1621_attribute_visible | 355 | .is_visible = ds1621_attribute_visible |
359 | }; | 356 | }; |
357 | __ATTRIBUTE_GROUPS(ds1621); | ||
360 | 358 | ||
361 | static int ds1621_probe(struct i2c_client *client, | 359 | static int ds1621_probe(struct i2c_client *client, |
362 | const struct i2c_device_id *id) | 360 | const struct i2c_device_id *id) |
363 | { | 361 | { |
364 | struct ds1621_data *data; | 362 | struct ds1621_data *data; |
365 | int err; | 363 | struct device *hwmon_dev; |
366 | 364 | ||
367 | data = devm_kzalloc(&client->dev, sizeof(struct ds1621_data), | 365 | data = devm_kzalloc(&client->dev, sizeof(struct ds1621_data), |
368 | GFP_KERNEL); | 366 | GFP_KERNEL); |
369 | if (!data) | 367 | if (!data) |
370 | return -ENOMEM; | 368 | return -ENOMEM; |
371 | 369 | ||
372 | i2c_set_clientdata(client, data); | ||
373 | mutex_init(&data->update_lock); | 370 | mutex_init(&data->update_lock); |
374 | 371 | ||
375 | data->kind = id->driver_data; | 372 | data->kind = id->driver_data; |
373 | data->client = client; | ||
376 | 374 | ||
377 | /* Initialize the DS1621 chip */ | 375 | /* Initialize the DS1621 chip */ |
378 | ds1621_init_client(client); | 376 | ds1621_init_client(data, client); |
379 | |||
380 | /* Register sysfs hooks */ | ||
381 | err = sysfs_create_group(&client->dev.kobj, &ds1621_group); | ||
382 | if (err) | ||
383 | return err; | ||
384 | |||
385 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
386 | if (IS_ERR(data->hwmon_dev)) { | ||
387 | err = PTR_ERR(data->hwmon_dev); | ||
388 | goto exit_remove_files; | ||
389 | } | ||
390 | |||
391 | return 0; | ||
392 | |||
393 | exit_remove_files: | ||
394 | sysfs_remove_group(&client->dev.kobj, &ds1621_group); | ||
395 | return err; | ||
396 | } | ||
397 | |||
398 | static int ds1621_remove(struct i2c_client *client) | ||
399 | { | ||
400 | struct ds1621_data *data = i2c_get_clientdata(client); | ||
401 | |||
402 | hwmon_device_unregister(data->hwmon_dev); | ||
403 | sysfs_remove_group(&client->dev.kobj, &ds1621_group); | ||
404 | 377 | ||
405 | return 0; | 378 | hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev, |
379 | client->name, data, | ||
380 | ds1621_groups); | ||
381 | return PTR_ERR_OR_ZERO(hwmon_dev); | ||
406 | } | 382 | } |
407 | 383 | ||
408 | static const struct i2c_device_id ds1621_id[] = { | 384 | static const struct i2c_device_id ds1621_id[] = { |
@@ -422,7 +398,6 @@ static struct i2c_driver ds1621_driver = { | |||
422 | .name = "ds1621", | 398 | .name = "ds1621", |
423 | }, | 399 | }, |
424 | .probe = ds1621_probe, | 400 | .probe = ds1621_probe, |
425 | .remove = ds1621_remove, | ||
426 | .id_table = ds1621_id, | 401 | .id_table = ds1621_id, |
427 | }; | 402 | }; |
428 | 403 | ||
diff --git a/drivers/hwmon/emc1403.c b/drivers/hwmon/emc1403.c index 142e1cb8dea7..90ec1173b8a1 100644 --- a/drivers/hwmon/emc1403.c +++ b/drivers/hwmon/emc1403.c | |||
@@ -21,7 +21,6 @@ | |||
21 | * | 21 | * |
22 | * TODO | 22 | * TODO |
23 | * - cache alarm and critical limit registers | 23 | * - cache alarm and critical limit registers |
24 | * - add emc1404 support | ||
25 | */ | 24 | */ |
26 | 25 | ||
27 | #include <linux/module.h> | 26 | #include <linux/module.h> |
@@ -40,7 +39,8 @@ | |||
40 | #define THERMAL_REVISION_REG 0xff | 39 | #define THERMAL_REVISION_REG 0xff |
41 | 40 | ||
42 | struct thermal_data { | 41 | struct thermal_data { |
43 | struct device *hwmon_dev; | 42 | struct i2c_client *client; |
43 | const struct attribute_group *groups[3]; | ||
44 | struct mutex mutex; | 44 | struct mutex mutex; |
45 | /* | 45 | /* |
46 | * Cache the hyst value so we don't keep re-reading it. In theory | 46 | * Cache the hyst value so we don't keep re-reading it. In theory |
@@ -53,10 +53,11 @@ struct thermal_data { | |||
53 | static ssize_t show_temp(struct device *dev, | 53 | static ssize_t show_temp(struct device *dev, |
54 | struct device_attribute *attr, char *buf) | 54 | struct device_attribute *attr, char *buf) |
55 | { | 55 | { |
56 | struct i2c_client *client = to_i2c_client(dev); | ||
57 | struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); | 56 | struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); |
58 | int retval = i2c_smbus_read_byte_data(client, sda->index); | 57 | struct thermal_data *data = dev_get_drvdata(dev); |
58 | int retval; | ||
59 | 59 | ||
60 | retval = i2c_smbus_read_byte_data(data->client, sda->index); | ||
60 | if (retval < 0) | 61 | if (retval < 0) |
61 | return retval; | 62 | return retval; |
62 | return sprintf(buf, "%d000\n", retval); | 63 | return sprintf(buf, "%d000\n", retval); |
@@ -65,27 +66,27 @@ static ssize_t show_temp(struct device *dev, | |||
65 | static ssize_t show_bit(struct device *dev, | 66 | static ssize_t show_bit(struct device *dev, |
66 | struct device_attribute *attr, char *buf) | 67 | struct device_attribute *attr, char *buf) |
67 | { | 68 | { |
68 | struct i2c_client *client = to_i2c_client(dev); | ||
69 | struct sensor_device_attribute_2 *sda = to_sensor_dev_attr_2(attr); | 69 | struct sensor_device_attribute_2 *sda = to_sensor_dev_attr_2(attr); |
70 | int retval = i2c_smbus_read_byte_data(client, sda->nr); | 70 | struct thermal_data *data = dev_get_drvdata(dev); |
71 | int retval; | ||
71 | 72 | ||
73 | retval = i2c_smbus_read_byte_data(data->client, sda->nr); | ||
72 | if (retval < 0) | 74 | if (retval < 0) |
73 | return retval; | 75 | return retval; |
74 | retval &= sda->index; | 76 | return sprintf(buf, "%d\n", !!(retval & sda->index)); |
75 | return sprintf(buf, "%d\n", retval ? 1 : 0); | ||
76 | } | 77 | } |
77 | 78 | ||
78 | static ssize_t store_temp(struct device *dev, | 79 | static ssize_t store_temp(struct device *dev, |
79 | struct device_attribute *attr, const char *buf, size_t count) | 80 | struct device_attribute *attr, const char *buf, size_t count) |
80 | { | 81 | { |
81 | struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); | 82 | struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); |
82 | struct i2c_client *client = to_i2c_client(dev); | 83 | struct thermal_data *data = dev_get_drvdata(dev); |
83 | unsigned long val; | 84 | unsigned long val; |
84 | int retval; | 85 | int retval; |
85 | 86 | ||
86 | if (kstrtoul(buf, 10, &val)) | 87 | if (kstrtoul(buf, 10, &val)) |
87 | return -EINVAL; | 88 | return -EINVAL; |
88 | retval = i2c_smbus_write_byte_data(client, sda->index, | 89 | retval = i2c_smbus_write_byte_data(data->client, sda->index, |
89 | DIV_ROUND_CLOSEST(val, 1000)); | 90 | DIV_ROUND_CLOSEST(val, 1000)); |
90 | if (retval < 0) | 91 | if (retval < 0) |
91 | return retval; | 92 | return retval; |
@@ -95,9 +96,9 @@ static ssize_t store_temp(struct device *dev, | |||
95 | static ssize_t store_bit(struct device *dev, | 96 | static ssize_t store_bit(struct device *dev, |
96 | struct device_attribute *attr, const char *buf, size_t count) | 97 | struct device_attribute *attr, const char *buf, size_t count) |
97 | { | 98 | { |
98 | struct i2c_client *client = to_i2c_client(dev); | ||
99 | struct thermal_data *data = i2c_get_clientdata(client); | ||
100 | struct sensor_device_attribute_2 *sda = to_sensor_dev_attr_2(attr); | 99 | struct sensor_device_attribute_2 *sda = to_sensor_dev_attr_2(attr); |
100 | struct thermal_data *data = dev_get_drvdata(dev); | ||
101 | struct i2c_client *client = data->client; | ||
101 | unsigned long val; | 102 | unsigned long val; |
102 | int retval; | 103 | int retval; |
103 | 104 | ||
@@ -124,9 +125,9 @@ fail: | |||
124 | static ssize_t show_hyst(struct device *dev, | 125 | static ssize_t show_hyst(struct device *dev, |
125 | struct device_attribute *attr, char *buf) | 126 | struct device_attribute *attr, char *buf) |
126 | { | 127 | { |
127 | struct i2c_client *client = to_i2c_client(dev); | ||
128 | struct thermal_data *data = i2c_get_clientdata(client); | ||
129 | struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); | 128 | struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); |
129 | struct thermal_data *data = dev_get_drvdata(dev); | ||
130 | struct i2c_client *client = data->client; | ||
130 | int retval; | 131 | int retval; |
131 | int hyst; | 132 | int hyst; |
132 | 133 | ||
@@ -147,9 +148,9 @@ static ssize_t show_hyst(struct device *dev, | |||
147 | static ssize_t store_hyst(struct device *dev, | 148 | static ssize_t store_hyst(struct device *dev, |
148 | struct device_attribute *attr, const char *buf, size_t count) | 149 | struct device_attribute *attr, const char *buf, size_t count) |
149 | { | 150 | { |
150 | struct i2c_client *client = to_i2c_client(dev); | ||
151 | struct thermal_data *data = i2c_get_clientdata(client); | ||
152 | struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); | 151 | struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); |
152 | struct thermal_data *data = dev_get_drvdata(dev); | ||
153 | struct i2c_client *client = data->client; | ||
153 | int retval; | 154 | int retval; |
154 | int hyst; | 155 | int hyst; |
155 | unsigned long val; | 156 | unsigned long val; |
@@ -232,10 +233,26 @@ static SENSOR_DEVICE_ATTR_2(temp3_crit_alarm, S_IRUGO, | |||
232 | static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO | S_IWUSR, | 233 | static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO | S_IWUSR, |
233 | show_hyst, store_hyst, 0x1A); | 234 | show_hyst, store_hyst, 0x1A); |
234 | 235 | ||
236 | static SENSOR_DEVICE_ATTR(temp4_min, S_IRUGO | S_IWUSR, | ||
237 | show_temp, store_temp, 0x2D); | ||
238 | static SENSOR_DEVICE_ATTR(temp4_max, S_IRUGO | S_IWUSR, | ||
239 | show_temp, store_temp, 0x2C); | ||
240 | static SENSOR_DEVICE_ATTR(temp4_crit, S_IRUGO | S_IWUSR, | ||
241 | show_temp, store_temp, 0x30); | ||
242 | static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 0x2A); | ||
243 | static SENSOR_DEVICE_ATTR_2(temp4_min_alarm, S_IRUGO, | ||
244 | show_bit, NULL, 0x36, 0x08); | ||
245 | static SENSOR_DEVICE_ATTR_2(temp4_max_alarm, S_IRUGO, | ||
246 | show_bit, NULL, 0x35, 0x08); | ||
247 | static SENSOR_DEVICE_ATTR_2(temp4_crit_alarm, S_IRUGO, | ||
248 | show_bit, NULL, 0x37, 0x08); | ||
249 | static SENSOR_DEVICE_ATTR(temp4_crit_hyst, S_IRUGO | S_IWUSR, | ||
250 | show_hyst, store_hyst, 0x30); | ||
251 | |||
235 | static SENSOR_DEVICE_ATTR_2(power_state, S_IRUGO | S_IWUSR, | 252 | static SENSOR_DEVICE_ATTR_2(power_state, S_IRUGO | S_IWUSR, |
236 | show_bit, store_bit, 0x03, 0x40); | 253 | show_bit, store_bit, 0x03, 0x40); |
237 | 254 | ||
238 | static struct attribute *mid_att_thermal[] = { | 255 | static struct attribute *emc1403_attrs[] = { |
239 | &sensor_dev_attr_temp1_min.dev_attr.attr, | 256 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
240 | &sensor_dev_attr_temp1_max.dev_attr.attr, | 257 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
241 | &sensor_dev_attr_temp1_crit.dev_attr.attr, | 258 | &sensor_dev_attr_temp1_crit.dev_attr.attr, |
@@ -264,8 +281,24 @@ static struct attribute *mid_att_thermal[] = { | |||
264 | NULL | 281 | NULL |
265 | }; | 282 | }; |
266 | 283 | ||
267 | static const struct attribute_group m_thermal_gr = { | 284 | static const struct attribute_group emc1403_group = { |
268 | .attrs = mid_att_thermal | 285 | .attrs = emc1403_attrs, |
286 | }; | ||
287 | |||
288 | static struct attribute *emc1404_attrs[] = { | ||
289 | &sensor_dev_attr_temp4_min.dev_attr.attr, | ||
290 | &sensor_dev_attr_temp4_max.dev_attr.attr, | ||
291 | &sensor_dev_attr_temp4_crit.dev_attr.attr, | ||
292 | &sensor_dev_attr_temp4_input.dev_attr.attr, | ||
293 | &sensor_dev_attr_temp4_min_alarm.dev_attr.attr, | ||
294 | &sensor_dev_attr_temp4_max_alarm.dev_attr.attr, | ||
295 | &sensor_dev_attr_temp4_crit_alarm.dev_attr.attr, | ||
296 | &sensor_dev_attr_temp4_crit_hyst.dev_attr.attr, | ||
297 | NULL | ||
298 | }; | ||
299 | |||
300 | static const struct attribute_group emc1404_group = { | ||
301 | .attrs = emc1404_attrs, | ||
269 | }; | 302 | }; |
270 | 303 | ||
271 | static int emc1403_detect(struct i2c_client *client, | 304 | static int emc1403_detect(struct i2c_client *client, |
@@ -286,10 +319,12 @@ static int emc1403_detect(struct i2c_client *client, | |||
286 | case 0x23: | 319 | case 0x23: |
287 | strlcpy(info->type, "emc1423", I2C_NAME_SIZE); | 320 | strlcpy(info->type, "emc1423", I2C_NAME_SIZE); |
288 | break; | 321 | break; |
289 | /* | 322 | case 0x25: |
290 | * Note: 0x25 is the 1404 which is very similar and this | 323 | strlcpy(info->type, "emc1404", I2C_NAME_SIZE); |
291 | * driver could be extended | 324 | break; |
292 | */ | 325 | case 0x27: |
326 | strlcpy(info->type, "emc1424", I2C_NAME_SIZE); | ||
327 | break; | ||
293 | default: | 328 | default: |
294 | return -ENODEV; | 329 | return -ENODEV; |
295 | } | 330 | } |
@@ -304,43 +339,29 @@ static int emc1403_detect(struct i2c_client *client, | |||
304 | static int emc1403_probe(struct i2c_client *client, | 339 | static int emc1403_probe(struct i2c_client *client, |
305 | const struct i2c_device_id *id) | 340 | const struct i2c_device_id *id) |
306 | { | 341 | { |
307 | int res; | ||
308 | struct thermal_data *data; | 342 | struct thermal_data *data; |
343 | struct device *hwmon_dev; | ||
309 | 344 | ||
310 | data = devm_kzalloc(&client->dev, sizeof(struct thermal_data), | 345 | data = devm_kzalloc(&client->dev, sizeof(struct thermal_data), |
311 | GFP_KERNEL); | 346 | GFP_KERNEL); |
312 | if (data == NULL) | 347 | if (data == NULL) |
313 | return -ENOMEM; | 348 | return -ENOMEM; |
314 | 349 | ||
315 | i2c_set_clientdata(client, data); | 350 | data->client = client; |
316 | mutex_init(&data->mutex); | 351 | mutex_init(&data->mutex); |
317 | data->hyst_valid = jiffies - 1; /* Expired */ | 352 | data->hyst_valid = jiffies - 1; /* Expired */ |
318 | 353 | ||
319 | res = sysfs_create_group(&client->dev.kobj, &m_thermal_gr); | 354 | data->groups[0] = &emc1403_group; |
320 | if (res) { | 355 | if (id->driver_data) |
321 | dev_warn(&client->dev, "create group failed\n"); | 356 | data->groups[1] = &emc1404_group; |
322 | return res; | ||
323 | } | ||
324 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
325 | if (IS_ERR(data->hwmon_dev)) { | ||
326 | res = PTR_ERR(data->hwmon_dev); | ||
327 | dev_warn(&client->dev, "register hwmon dev failed\n"); | ||
328 | goto thermal_error; | ||
329 | } | ||
330 | dev_info(&client->dev, "EMC1403 Thermal chip found\n"); | ||
331 | return 0; | ||
332 | |||
333 | thermal_error: | ||
334 | sysfs_remove_group(&client->dev.kobj, &m_thermal_gr); | ||
335 | return res; | ||
336 | } | ||
337 | 357 | ||
338 | static int emc1403_remove(struct i2c_client *client) | 358 | hwmon_dev = hwmon_device_register_with_groups(&client->dev, |
339 | { | 359 | client->name, data, |
340 | struct thermal_data *data = i2c_get_clientdata(client); | 360 | data->groups); |
361 | if (IS_ERR(hwmon_dev)) | ||
362 | return PTR_ERR(hwmon_dev); | ||
341 | 363 | ||
342 | hwmon_device_unregister(data->hwmon_dev); | 364 | dev_info(&client->dev, "%s Thermal chip found\n", id->name); |
343 | sysfs_remove_group(&client->dev.kobj, &m_thermal_gr); | ||
344 | return 0; | 365 | return 0; |
345 | } | 366 | } |
346 | 367 | ||
@@ -350,7 +371,9 @@ static const unsigned short emc1403_address_list[] = { | |||
350 | 371 | ||
351 | static const struct i2c_device_id emc1403_idtable[] = { | 372 | static const struct i2c_device_id emc1403_idtable[] = { |
352 | { "emc1403", 0 }, | 373 | { "emc1403", 0 }, |
374 | { "emc1404", 1 }, | ||
353 | { "emc1423", 0 }, | 375 | { "emc1423", 0 }, |
376 | { "emc1424", 1 }, | ||
354 | { } | 377 | { } |
355 | }; | 378 | }; |
356 | MODULE_DEVICE_TABLE(i2c, emc1403_idtable); | 379 | MODULE_DEVICE_TABLE(i2c, emc1403_idtable); |
@@ -362,7 +385,6 @@ static struct i2c_driver sensor_emc1403 = { | |||
362 | }, | 385 | }, |
363 | .detect = emc1403_detect, | 386 | .detect = emc1403_detect, |
364 | .probe = emc1403_probe, | 387 | .probe = emc1403_probe, |
365 | .remove = emc1403_remove, | ||
366 | .id_table = emc1403_idtable, | 388 | .id_table = emc1403_idtable, |
367 | .address_list = emc1403_address_list, | 389 | .address_list = emc1403_address_list, |
368 | }; | 390 | }; |
diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c index 31b221eeee6c..03d8592810bf 100644 --- a/drivers/hwmon/f71882fg.c +++ b/drivers/hwmon/f71882fg.c | |||
@@ -2420,7 +2420,6 @@ static int f71882fg_probe(struct platform_device *pdev) | |||
2420 | exit_unregister_sysfs: | 2420 | exit_unregister_sysfs: |
2421 | f71882fg_remove(pdev); /* Will unregister the sysfs files for us */ | 2421 | f71882fg_remove(pdev); /* Will unregister the sysfs files for us */ |
2422 | return err; /* f71882fg_remove() also frees our data */ | 2422 | return err; /* f71882fg_remove() also frees our data */ |
2423 | return err; | ||
2424 | } | 2423 | } |
2425 | 2424 | ||
2426 | static int f71882fg_remove(struct platform_device *pdev) | 2425 | static int f71882fg_remove(struct platform_device *pdev) |
diff --git a/drivers/hwmon/f75375s.c b/drivers/hwmon/f75375s.c index a837b94977f4..80c42bea90ed 100644 --- a/drivers/hwmon/f75375s.c +++ b/drivers/hwmon/f75375s.c | |||
@@ -275,7 +275,7 @@ static bool duty_mode_enabled(u8 pwm_enable) | |||
275 | case 3: /* Manual, speed mode */ | 275 | case 3: /* Manual, speed mode */ |
276 | return false; | 276 | return false; |
277 | default: | 277 | default: |
278 | BUG(); | 278 | WARN(1, "Unexpected pwm_enable value %d\n", pwm_enable); |
279 | return true; | 279 | return true; |
280 | } | 280 | } |
281 | } | 281 | } |
@@ -291,7 +291,7 @@ static bool auto_mode_enabled(u8 pwm_enable) | |||
291 | case 4: /* Auto, duty mode */ | 291 | case 4: /* Auto, duty mode */ |
292 | return true; | 292 | return true; |
293 | default: | 293 | default: |
294 | BUG(); | 294 | WARN(1, "Unexpected pwm_enable value %d\n", pwm_enable); |
295 | return false; | 295 | return false; |
296 | } | 296 | } |
297 | } | 297 | } |
diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c index b7d6a5704eb2..73181be5b30b 100644 --- a/drivers/hwmon/gpio-fan.c +++ b/drivers/hwmon/gpio-fan.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/hwmon.h> | 31 | #include <linux/hwmon.h> |
32 | #include <linux/gpio.h> | 32 | #include <linux/gpio.h> |
33 | #include <linux/gpio-fan.h> | 33 | #include <linux/gpio-fan.h> |
34 | #include <linux/of.h> | ||
34 | #include <linux/of_platform.h> | 35 | #include <linux/of_platform.h> |
35 | #include <linux/of_gpio.h> | 36 | #include <linux/of_gpio.h> |
36 | 37 | ||
@@ -169,7 +170,7 @@ static int get_fan_speed_index(struct gpio_fan_data *fan_data) | |||
169 | dev_warn(&fan_data->pdev->dev, | 170 | dev_warn(&fan_data->pdev->dev, |
170 | "missing speed array entry for GPIO value 0x%x\n", ctrl_val); | 171 | "missing speed array entry for GPIO value 0x%x\n", ctrl_val); |
171 | 172 | ||
172 | return -EINVAL; | 173 | return -ENODEV; |
173 | } | 174 | } |
174 | 175 | ||
175 | static int rpm_to_speed_index(struct gpio_fan_data *fan_data, int rpm) | 176 | static int rpm_to_speed_index(struct gpio_fan_data *fan_data, int rpm) |
@@ -309,12 +310,6 @@ exit_unlock: | |||
309 | return ret; | 310 | return ret; |
310 | } | 311 | } |
311 | 312 | ||
312 | static ssize_t show_name(struct device *dev, | ||
313 | struct device_attribute *attr, char *buf) | ||
314 | { | ||
315 | return sprintf(buf, "gpio-fan\n"); | ||
316 | } | ||
317 | |||
318 | static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm); | 313 | static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm); |
319 | static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, | 314 | static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, |
320 | show_pwm_enable, set_pwm_enable); | 315 | show_pwm_enable, set_pwm_enable); |
@@ -324,26 +319,23 @@ static DEVICE_ATTR(fan1_max, S_IRUGO, show_rpm_max, NULL); | |||
324 | static DEVICE_ATTR(fan1_input, S_IRUGO, show_rpm, NULL); | 319 | static DEVICE_ATTR(fan1_input, S_IRUGO, show_rpm, NULL); |
325 | static DEVICE_ATTR(fan1_target, S_IRUGO | S_IWUSR, show_rpm, set_rpm); | 320 | static DEVICE_ATTR(fan1_target, S_IRUGO | S_IWUSR, show_rpm, set_rpm); |
326 | 321 | ||
327 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | ||
328 | |||
329 | static umode_t gpio_fan_is_visible(struct kobject *kobj, | 322 | static umode_t gpio_fan_is_visible(struct kobject *kobj, |
330 | struct attribute *attr, int index) | 323 | struct attribute *attr, int index) |
331 | { | 324 | { |
332 | struct device *dev = container_of(kobj, struct device, kobj); | 325 | struct device *dev = container_of(kobj, struct device, kobj); |
333 | struct gpio_fan_data *data = dev_get_drvdata(dev); | 326 | struct gpio_fan_data *data = dev_get_drvdata(dev); |
334 | 327 | ||
335 | if (index == 1 && !data->alarm) | 328 | if (index == 0 && !data->alarm) |
336 | return 0; | 329 | return 0; |
337 | if (index > 1 && !data->ctrl) | 330 | if (index > 0 && !data->ctrl) |
338 | return 0; | 331 | return 0; |
339 | 332 | ||
340 | return attr->mode; | 333 | return attr->mode; |
341 | } | 334 | } |
342 | 335 | ||
343 | static struct attribute *gpio_fan_attributes[] = { | 336 | static struct attribute *gpio_fan_attributes[] = { |
344 | &dev_attr_name.attr, | 337 | &dev_attr_fan1_alarm.attr, /* 0 */ |
345 | &dev_attr_fan1_alarm.attr, /* 1 */ | 338 | &dev_attr_pwm1.attr, /* 1 */ |
346 | &dev_attr_pwm1.attr, /* 2 */ | ||
347 | &dev_attr_pwm1_enable.attr, | 339 | &dev_attr_pwm1_enable.attr, |
348 | &dev_attr_pwm1_mode.attr, | 340 | &dev_attr_pwm1_mode.attr, |
349 | &dev_attr_fan1_input.attr, | 341 | &dev_attr_fan1_input.attr, |
@@ -358,6 +350,11 @@ static const struct attribute_group gpio_fan_group = { | |||
358 | .is_visible = gpio_fan_is_visible, | 350 | .is_visible = gpio_fan_is_visible, |
359 | }; | 351 | }; |
360 | 352 | ||
353 | static const struct attribute_group *gpio_fan_groups[] = { | ||
354 | &gpio_fan_group, | ||
355 | NULL | ||
356 | }; | ||
357 | |||
361 | static int fan_ctrl_init(struct gpio_fan_data *fan_data, | 358 | static int fan_ctrl_init(struct gpio_fan_data *fan_data, |
362 | struct gpio_fan_platform_data *pdata) | 359 | struct gpio_fan_platform_data *pdata) |
363 | { | 360 | { |
@@ -384,7 +381,7 @@ static int fan_ctrl_init(struct gpio_fan_data *fan_data, | |||
384 | fan_data->pwm_enable = true; /* Enable manual fan speed control. */ | 381 | fan_data->pwm_enable = true; /* Enable manual fan speed control. */ |
385 | fan_data->speed_index = get_fan_speed_index(fan_data); | 382 | fan_data->speed_index = get_fan_speed_index(fan_data); |
386 | if (fan_data->speed_index < 0) | 383 | if (fan_data->speed_index < 0) |
387 | return -ENODEV; | 384 | return fan_data->speed_index; |
388 | 385 | ||
389 | return 0; | 386 | return 0; |
390 | } | 387 | } |
@@ -539,24 +536,16 @@ static int gpio_fan_probe(struct platform_device *pdev) | |||
539 | return err; | 536 | return err; |
540 | } | 537 | } |
541 | 538 | ||
542 | err = sysfs_create_group(&pdev->dev.kobj, &gpio_fan_group); | ||
543 | if (err) | ||
544 | return err; | ||
545 | |||
546 | /* Make this driver part of hwmon class. */ | 539 | /* Make this driver part of hwmon class. */ |
547 | fan_data->hwmon_dev = hwmon_device_register(&pdev->dev); | 540 | fan_data->hwmon_dev = hwmon_device_register_with_groups(&pdev->dev, |
548 | if (IS_ERR(fan_data->hwmon_dev)) { | 541 | "gpio-fan", fan_data, |
549 | err = PTR_ERR(fan_data->hwmon_dev); | 542 | gpio_fan_groups); |
550 | goto err_remove; | 543 | if (IS_ERR(fan_data->hwmon_dev)) |
551 | } | 544 | return PTR_ERR(fan_data->hwmon_dev); |
552 | 545 | ||
553 | dev_info(&pdev->dev, "GPIO fan initialized\n"); | 546 | dev_info(&pdev->dev, "GPIO fan initialized\n"); |
554 | 547 | ||
555 | return 0; | 548 | return 0; |
556 | |||
557 | err_remove: | ||
558 | sysfs_remove_group(&pdev->dev.kobj, &gpio_fan_group); | ||
559 | return err; | ||
560 | } | 549 | } |
561 | 550 | ||
562 | static int gpio_fan_remove(struct platform_device *pdev) | 551 | static int gpio_fan_remove(struct platform_device *pdev) |
@@ -564,7 +553,6 @@ static int gpio_fan_remove(struct platform_device *pdev) | |||
564 | struct gpio_fan_data *fan_data = platform_get_drvdata(pdev); | 553 | struct gpio_fan_data *fan_data = platform_get_drvdata(pdev); |
565 | 554 | ||
566 | hwmon_device_unregister(fan_data->hwmon_dev); | 555 | hwmon_device_unregister(fan_data->hwmon_dev); |
567 | sysfs_remove_group(&pdev->dev.kobj, &gpio_fan_group); | ||
568 | 556 | ||
569 | return 0; | 557 | return 0; |
570 | } | 558 | } |
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c index 646314f7c839..e176a43af63d 100644 --- a/drivers/hwmon/hwmon.c +++ b/drivers/hwmon/hwmon.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/device.h> | 16 | #include <linux/device.h> |
17 | #include <linux/err.h> | 17 | #include <linux/err.h> |
18 | #include <linux/slab.h> | ||
18 | #include <linux/kdev_t.h> | 19 | #include <linux/kdev_t.h> |
19 | #include <linux/idr.h> | 20 | #include <linux/idr.h> |
20 | #include <linux/hwmon.h> | 21 | #include <linux/hwmon.h> |
@@ -25,35 +26,122 @@ | |||
25 | #define HWMON_ID_PREFIX "hwmon" | 26 | #define HWMON_ID_PREFIX "hwmon" |
26 | #define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d" | 27 | #define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d" |
27 | 28 | ||
28 | static struct class *hwmon_class; | 29 | struct hwmon_device { |
30 | const char *name; | ||
31 | struct device dev; | ||
32 | }; | ||
33 | #define to_hwmon_device(d) container_of(d, struct hwmon_device, dev) | ||
34 | |||
35 | static ssize_t | ||
36 | show_name(struct device *dev, struct device_attribute *attr, char *buf) | ||
37 | { | ||
38 | return sprintf(buf, "%s\n", to_hwmon_device(dev)->name); | ||
39 | } | ||
40 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | ||
41 | |||
42 | static struct attribute *hwmon_dev_attrs[] = { | ||
43 | &dev_attr_name.attr, | ||
44 | NULL | ||
45 | }; | ||
46 | |||
47 | static umode_t hwmon_dev_name_is_visible(struct kobject *kobj, | ||
48 | struct attribute *attr, int n) | ||
49 | { | ||
50 | struct device *dev = container_of(kobj, struct device, kobj); | ||
51 | |||
52 | if (to_hwmon_device(dev)->name == NULL) | ||
53 | return 0; | ||
54 | |||
55 | return attr->mode; | ||
56 | } | ||
57 | |||
58 | static struct attribute_group hwmon_dev_attr_group = { | ||
59 | .attrs = hwmon_dev_attrs, | ||
60 | .is_visible = hwmon_dev_name_is_visible, | ||
61 | }; | ||
62 | |||
63 | static const struct attribute_group *hwmon_dev_attr_groups[] = { | ||
64 | &hwmon_dev_attr_group, | ||
65 | NULL | ||
66 | }; | ||
67 | |||
68 | static void hwmon_dev_release(struct device *dev) | ||
69 | { | ||
70 | kfree(to_hwmon_device(dev)); | ||
71 | } | ||
72 | |||
73 | static struct class hwmon_class = { | ||
74 | .name = "hwmon", | ||
75 | .owner = THIS_MODULE, | ||
76 | .dev_groups = hwmon_dev_attr_groups, | ||
77 | .dev_release = hwmon_dev_release, | ||
78 | }; | ||
29 | 79 | ||
30 | static DEFINE_IDA(hwmon_ida); | 80 | static DEFINE_IDA(hwmon_ida); |
31 | 81 | ||
32 | /** | 82 | /** |
33 | * hwmon_device_register - register w/ hwmon | 83 | * hwmon_device_register_with_groups - register w/ hwmon |
34 | * @dev: the device to register | 84 | * @dev: the parent device |
85 | * @name: hwmon name attribute | ||
86 | * @drvdata: driver data to attach to created device | ||
87 | * @groups: List of attribute groups to create | ||
35 | * | 88 | * |
36 | * hwmon_device_unregister() must be called when the device is no | 89 | * hwmon_device_unregister() must be called when the device is no |
37 | * longer needed. | 90 | * longer needed. |
38 | * | 91 | * |
39 | * Returns the pointer to the new device. | 92 | * Returns the pointer to the new device. |
40 | */ | 93 | */ |
41 | struct device *hwmon_device_register(struct device *dev) | 94 | struct device * |
95 | hwmon_device_register_with_groups(struct device *dev, const char *name, | ||
96 | void *drvdata, | ||
97 | const struct attribute_group **groups) | ||
42 | { | 98 | { |
43 | struct device *hwdev; | 99 | struct hwmon_device *hwdev; |
44 | int id; | 100 | int err, id; |
45 | 101 | ||
46 | id = ida_simple_get(&hwmon_ida, 0, 0, GFP_KERNEL); | 102 | id = ida_simple_get(&hwmon_ida, 0, 0, GFP_KERNEL); |
47 | if (id < 0) | 103 | if (id < 0) |
48 | return ERR_PTR(id); | 104 | return ERR_PTR(id); |
49 | 105 | ||
50 | hwdev = device_create(hwmon_class, dev, MKDEV(0, 0), NULL, | 106 | hwdev = kzalloc(sizeof(*hwdev), GFP_KERNEL); |
51 | HWMON_ID_FORMAT, id); | 107 | if (hwdev == NULL) { |
108 | err = -ENOMEM; | ||
109 | goto ida_remove; | ||
110 | } | ||
52 | 111 | ||
53 | if (IS_ERR(hwdev)) | 112 | hwdev->name = name; |
54 | ida_simple_remove(&hwmon_ida, id); | 113 | hwdev->dev.class = &hwmon_class; |
114 | hwdev->dev.parent = dev; | ||
115 | hwdev->dev.groups = groups; | ||
116 | hwdev->dev.of_node = dev ? dev->of_node : NULL; | ||
117 | dev_set_drvdata(&hwdev->dev, drvdata); | ||
118 | dev_set_name(&hwdev->dev, HWMON_ID_FORMAT, id); | ||
119 | err = device_register(&hwdev->dev); | ||
120 | if (err) | ||
121 | goto free; | ||
55 | 122 | ||
56 | return hwdev; | 123 | return &hwdev->dev; |
124 | |||
125 | free: | ||
126 | kfree(hwdev); | ||
127 | ida_remove: | ||
128 | ida_simple_remove(&hwmon_ida, id); | ||
129 | return ERR_PTR(err); | ||
130 | } | ||
131 | EXPORT_SYMBOL_GPL(hwmon_device_register_with_groups); | ||
132 | |||
133 | /** | ||
134 | * hwmon_device_register - register w/ hwmon | ||
135 | * @dev: the device to register | ||
136 | * | ||
137 | * hwmon_device_unregister() must be called when the device is no | ||
138 | * longer needed. | ||
139 | * | ||
140 | * Returns the pointer to the new device. | ||
141 | */ | ||
142 | struct device *hwmon_device_register(struct device *dev) | ||
143 | { | ||
144 | return hwmon_device_register_with_groups(dev, NULL, NULL, NULL); | ||
57 | } | 145 | } |
58 | EXPORT_SYMBOL_GPL(hwmon_device_register); | 146 | EXPORT_SYMBOL_GPL(hwmon_device_register); |
59 | 147 | ||
@@ -75,6 +163,69 @@ void hwmon_device_unregister(struct device *dev) | |||
75 | } | 163 | } |
76 | EXPORT_SYMBOL_GPL(hwmon_device_unregister); | 164 | EXPORT_SYMBOL_GPL(hwmon_device_unregister); |
77 | 165 | ||
166 | static void devm_hwmon_release(struct device *dev, void *res) | ||
167 | { | ||
168 | struct device *hwdev = *(struct device **)res; | ||
169 | |||
170 | hwmon_device_unregister(hwdev); | ||
171 | } | ||
172 | |||
173 | /** | ||
174 | * devm_hwmon_device_register_with_groups - register w/ hwmon | ||
175 | * @dev: the parent device | ||
176 | * @name: hwmon name attribute | ||
177 | * @drvdata: driver data to attach to created device | ||
178 | * @groups: List of attribute groups to create | ||
179 | * | ||
180 | * Returns the pointer to the new device. The new device is automatically | ||
181 | * unregistered with the parent device. | ||
182 | */ | ||
183 | struct device * | ||
184 | devm_hwmon_device_register_with_groups(struct device *dev, const char *name, | ||
185 | void *drvdata, | ||
186 | const struct attribute_group **groups) | ||
187 | { | ||
188 | struct device **ptr, *hwdev; | ||
189 | |||
190 | if (!dev) | ||
191 | return ERR_PTR(-EINVAL); | ||
192 | |||
193 | ptr = devres_alloc(devm_hwmon_release, sizeof(*ptr), GFP_KERNEL); | ||
194 | if (!ptr) | ||
195 | return ERR_PTR(-ENOMEM); | ||
196 | |||
197 | hwdev = hwmon_device_register_with_groups(dev, name, drvdata, groups); | ||
198 | if (IS_ERR(hwdev)) | ||
199 | goto error; | ||
200 | |||
201 | *ptr = hwdev; | ||
202 | devres_add(dev, ptr); | ||
203 | return hwdev; | ||
204 | |||
205 | error: | ||
206 | devres_free(ptr); | ||
207 | return hwdev; | ||
208 | } | ||
209 | EXPORT_SYMBOL_GPL(devm_hwmon_device_register_with_groups); | ||
210 | |||
211 | static int devm_hwmon_match(struct device *dev, void *res, void *data) | ||
212 | { | ||
213 | struct device **hwdev = res; | ||
214 | |||
215 | return *hwdev == data; | ||
216 | } | ||
217 | |||
218 | /** | ||
219 | * devm_hwmon_device_unregister - removes a previously registered hwmon device | ||
220 | * | ||
221 | * @dev: the parent device of the device to unregister | ||
222 | */ | ||
223 | void devm_hwmon_device_unregister(struct device *dev) | ||
224 | { | ||
225 | WARN_ON(devres_release(dev, devm_hwmon_release, devm_hwmon_match, dev)); | ||
226 | } | ||
227 | EXPORT_SYMBOL_GPL(devm_hwmon_device_unregister); | ||
228 | |||
78 | static void __init hwmon_pci_quirks(void) | 229 | static void __init hwmon_pci_quirks(void) |
79 | { | 230 | { |
80 | #if defined CONFIG_X86 && defined CONFIG_PCI | 231 | #if defined CONFIG_X86 && defined CONFIG_PCI |
@@ -105,19 +256,21 @@ static void __init hwmon_pci_quirks(void) | |||
105 | 256 | ||
106 | static int __init hwmon_init(void) | 257 | static int __init hwmon_init(void) |
107 | { | 258 | { |
259 | int err; | ||
260 | |||
108 | hwmon_pci_quirks(); | 261 | hwmon_pci_quirks(); |
109 | 262 | ||
110 | hwmon_class = class_create(THIS_MODULE, "hwmon"); | 263 | err = class_register(&hwmon_class); |
111 | if (IS_ERR(hwmon_class)) { | 264 | if (err) { |
112 | pr_err("couldn't create sysfs class\n"); | 265 | pr_err("couldn't register hwmon sysfs class\n"); |
113 | return PTR_ERR(hwmon_class); | 266 | return err; |
114 | } | 267 | } |
115 | return 0; | 268 | return 0; |
116 | } | 269 | } |
117 | 270 | ||
118 | static void __exit hwmon_exit(void) | 271 | static void __exit hwmon_exit(void) |
119 | { | 272 | { |
120 | class_destroy(hwmon_class); | 273 | class_unregister(&hwmon_class); |
121 | } | 274 | } |
122 | 275 | ||
123 | subsys_initcall(hwmon_init); | 276 | subsys_initcall(hwmon_init); |
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 | ||
65 | struct ina209_data { | 65 | struct 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 | ||
79 | static struct ina209_data *ina209_update_device(struct device *dev) | 79 | static 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, | |||
260 | static ssize_t ina209_show_interval(struct device *dev, | 260 | static 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; |
337 | abort: | 335 | abort: |
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 | */ |
460 | static struct attribute *ina209_attributes[] = { | 458 | static 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 | 499 | ATTRIBUTE_GROUPS(ina209); | |
502 | static const struct attribute_group ina209_group = { | ||
503 | .attrs = ina209_attributes, | ||
504 | }; | ||
505 | 500 | ||
506 | static void ina209_restore_conf(struct i2c_client *client, | 501 | static 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 | ||
597 | out_hwmon_device_register: | ||
598 | sysfs_remove_group(&client->dev.kobj, &ina209_group); | ||
599 | out_restore_conf: | 591 | out_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; |
diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c index 70a39a8ac016..93d26e8af3e2 100644 --- a/drivers/hwmon/ina2xx.c +++ b/drivers/hwmon/ina2xx.c | |||
@@ -78,7 +78,7 @@ struct ina2xx_config { | |||
78 | }; | 78 | }; |
79 | 79 | ||
80 | struct ina2xx_data { | 80 | struct ina2xx_data { |
81 | struct device *hwmon_dev; | 81 | struct i2c_client *client; |
82 | const struct ina2xx_config *config; | 82 | const struct ina2xx_config *config; |
83 | 83 | ||
84 | struct mutex update_lock; | 84 | struct mutex update_lock; |
@@ -112,8 +112,8 @@ static const struct ina2xx_config ina2xx_config[] = { | |||
112 | 112 | ||
113 | static struct ina2xx_data *ina2xx_update_device(struct device *dev) | 113 | static struct ina2xx_data *ina2xx_update_device(struct device *dev) |
114 | { | 114 | { |
115 | struct i2c_client *client = to_i2c_client(dev); | 115 | struct ina2xx_data *data = dev_get_drvdata(dev); |
116 | struct ina2xx_data *data = i2c_get_clientdata(client); | 116 | struct i2c_client *client = data->client; |
117 | struct ina2xx_data *ret = data; | 117 | struct ina2xx_data *ret = data; |
118 | 118 | ||
119 | mutex_lock(&data->update_lock); | 119 | mutex_lock(&data->update_lock); |
@@ -203,41 +203,39 @@ static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO, ina2xx_show_value, NULL, | |||
203 | INA2XX_POWER); | 203 | INA2XX_POWER); |
204 | 204 | ||
205 | /* pointers to created device attributes */ | 205 | /* pointers to created device attributes */ |
206 | static struct attribute *ina2xx_attributes[] = { | 206 | static struct attribute *ina2xx_attrs[] = { |
207 | &sensor_dev_attr_in0_input.dev_attr.attr, | 207 | &sensor_dev_attr_in0_input.dev_attr.attr, |
208 | &sensor_dev_attr_in1_input.dev_attr.attr, | 208 | &sensor_dev_attr_in1_input.dev_attr.attr, |
209 | &sensor_dev_attr_curr1_input.dev_attr.attr, | 209 | &sensor_dev_attr_curr1_input.dev_attr.attr, |
210 | &sensor_dev_attr_power1_input.dev_attr.attr, | 210 | &sensor_dev_attr_power1_input.dev_attr.attr, |
211 | NULL, | 211 | NULL, |
212 | }; | 212 | }; |
213 | 213 | ATTRIBUTE_GROUPS(ina2xx); | |
214 | static const struct attribute_group ina2xx_group = { | ||
215 | .attrs = ina2xx_attributes, | ||
216 | }; | ||
217 | 214 | ||
218 | static int ina2xx_probe(struct i2c_client *client, | 215 | static int ina2xx_probe(struct i2c_client *client, |
219 | const struct i2c_device_id *id) | 216 | const struct i2c_device_id *id) |
220 | { | 217 | { |
221 | struct i2c_adapter *adapter = client->adapter; | 218 | struct i2c_adapter *adapter = client->adapter; |
222 | struct ina2xx_data *data; | ||
223 | struct ina2xx_platform_data *pdata; | 219 | struct ina2xx_platform_data *pdata; |
224 | int ret; | 220 | struct device *dev = &client->dev; |
225 | u32 val; | 221 | struct ina2xx_data *data; |
222 | struct device *hwmon_dev; | ||
226 | long shunt = 10000; /* default shunt value 10mOhms */ | 223 | long shunt = 10000; /* default shunt value 10mOhms */ |
224 | u32 val; | ||
227 | 225 | ||
228 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) | 226 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) |
229 | return -ENODEV; | 227 | return -ENODEV; |
230 | 228 | ||
231 | data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); | 229 | data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); |
232 | if (!data) | 230 | if (!data) |
233 | return -ENOMEM; | 231 | return -ENOMEM; |
234 | 232 | ||
235 | if (dev_get_platdata(&client->dev)) { | 233 | if (dev_get_platdata(dev)) { |
236 | pdata = dev_get_platdata(&client->dev); | 234 | pdata = dev_get_platdata(dev); |
237 | shunt = pdata->shunt_uohms; | 235 | shunt = pdata->shunt_uohms; |
238 | } else if (!of_property_read_u32(client->dev.of_node, | 236 | } else if (!of_property_read_u32(dev->of_node, |
239 | "shunt-resistor", &val)) { | 237 | "shunt-resistor", &val)) { |
240 | shunt = val; | 238 | shunt = val; |
241 | } | 239 | } |
242 | 240 | ||
243 | if (shunt <= 0) | 241 | if (shunt <= 0) |
@@ -255,37 +253,18 @@ static int ina2xx_probe(struct i2c_client *client, | |||
255 | i2c_smbus_write_word_swapped(client, INA2XX_CALIBRATION, | 253 | i2c_smbus_write_word_swapped(client, INA2XX_CALIBRATION, |
256 | data->config->calibration_factor / shunt); | 254 | data->config->calibration_factor / shunt); |
257 | 255 | ||
258 | i2c_set_clientdata(client, data); | 256 | data->client = client; |
259 | mutex_init(&data->update_lock); | 257 | mutex_init(&data->update_lock); |
260 | 258 | ||
261 | ret = sysfs_create_group(&client->dev.kobj, &ina2xx_group); | 259 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
262 | if (ret) | 260 | data, ina2xx_groups); |
263 | return ret; | 261 | if (IS_ERR(hwmon_dev)) |
264 | 262 | return PTR_ERR(hwmon_dev); | |
265 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
266 | if (IS_ERR(data->hwmon_dev)) { | ||
267 | ret = PTR_ERR(data->hwmon_dev); | ||
268 | goto out_err_hwmon; | ||
269 | } | ||
270 | 263 | ||
271 | dev_info(&client->dev, "power monitor %s (Rshunt = %li uOhm)\n", | 264 | dev_info(dev, "power monitor %s (Rshunt = %li uOhm)\n", |
272 | id->name, shunt); | 265 | id->name, shunt); |
273 | 266 | ||
274 | return 0; | 267 | return 0; |
275 | |||
276 | out_err_hwmon: | ||
277 | sysfs_remove_group(&client->dev.kobj, &ina2xx_group); | ||
278 | return ret; | ||
279 | } | ||
280 | |||
281 | static int ina2xx_remove(struct i2c_client *client) | ||
282 | { | ||
283 | struct ina2xx_data *data = i2c_get_clientdata(client); | ||
284 | |||
285 | hwmon_device_unregister(data->hwmon_dev); | ||
286 | sysfs_remove_group(&client->dev.kobj, &ina2xx_group); | ||
287 | |||
288 | return 0; | ||
289 | } | 268 | } |
290 | 269 | ||
291 | static const struct i2c_device_id ina2xx_id[] = { | 270 | static const struct i2c_device_id ina2xx_id[] = { |
@@ -302,7 +281,6 @@ static struct i2c_driver ina2xx_driver = { | |||
302 | .name = "ina2xx", | 281 | .name = "ina2xx", |
303 | }, | 282 | }, |
304 | .probe = ina2xx_probe, | 283 | .probe = ina2xx_probe, |
305 | .remove = ina2xx_remove, | ||
306 | .id_table = ina2xx_id, | 284 | .id_table = ina2xx_id, |
307 | }; | 285 | }; |
308 | 286 | ||
diff --git a/drivers/hwmon/jc42.c b/drivers/hwmon/jc42.c index 4a58f130fd4e..6013611e4f21 100644 --- a/drivers/hwmon/jc42.c +++ b/drivers/hwmon/jc42.c | |||
@@ -163,7 +163,7 @@ static struct jc42_chips jc42_chips[] = { | |||
163 | 163 | ||
164 | /* Each client has this additional data */ | 164 | /* Each client has this additional data */ |
165 | struct jc42_data { | 165 | struct jc42_data { |
166 | struct device *hwmon_dev; | 166 | struct i2c_client *client; |
167 | struct mutex update_lock; /* protect register access */ | 167 | struct mutex update_lock; /* protect register access */ |
168 | bool extended; /* true if extended range supported */ | 168 | bool extended; /* true if extended range supported */ |
169 | bool valid; | 169 | bool valid; |
@@ -193,21 +193,21 @@ MODULE_DEVICE_TABLE(i2c, jc42_id); | |||
193 | 193 | ||
194 | static int jc42_suspend(struct device *dev) | 194 | static int jc42_suspend(struct device *dev) |
195 | { | 195 | { |
196 | struct i2c_client *client = to_i2c_client(dev); | 196 | struct jc42_data *data = dev_get_drvdata(dev); |
197 | struct jc42_data *data = i2c_get_clientdata(client); | ||
198 | 197 | ||
199 | data->config |= JC42_CFG_SHUTDOWN; | 198 | data->config |= JC42_CFG_SHUTDOWN; |
200 | i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, data->config); | 199 | i2c_smbus_write_word_swapped(data->client, JC42_REG_CONFIG, |
200 | data->config); | ||
201 | return 0; | 201 | return 0; |
202 | } | 202 | } |
203 | 203 | ||
204 | static int jc42_resume(struct device *dev) | 204 | static int jc42_resume(struct device *dev) |
205 | { | 205 | { |
206 | struct i2c_client *client = to_i2c_client(dev); | 206 | struct jc42_data *data = dev_get_drvdata(dev); |
207 | struct jc42_data *data = i2c_get_clientdata(client); | ||
208 | 207 | ||
209 | data->config &= ~JC42_CFG_SHUTDOWN; | 208 | data->config &= ~JC42_CFG_SHUTDOWN; |
210 | i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, data->config); | 209 | i2c_smbus_write_word_swapped(data->client, JC42_REG_CONFIG, |
210 | data->config); | ||
211 | return 0; | 211 | return 0; |
212 | } | 212 | } |
213 | 213 | ||
@@ -317,15 +317,14 @@ static ssize_t set_##value(struct device *dev, \ | |||
317 | struct device_attribute *attr, \ | 317 | struct device_attribute *attr, \ |
318 | const char *buf, size_t count) \ | 318 | const char *buf, size_t count) \ |
319 | { \ | 319 | { \ |
320 | struct i2c_client *client = to_i2c_client(dev); \ | 320 | struct jc42_data *data = dev_get_drvdata(dev); \ |
321 | struct jc42_data *data = i2c_get_clientdata(client); \ | ||
322 | int err, ret = count; \ | 321 | int err, ret = count; \ |
323 | long val; \ | 322 | long val; \ |
324 | if (kstrtol(buf, 10, &val) < 0) \ | 323 | if (kstrtol(buf, 10, &val) < 0) \ |
325 | return -EINVAL; \ | 324 | return -EINVAL; \ |
326 | mutex_lock(&data->update_lock); \ | 325 | mutex_lock(&data->update_lock); \ |
327 | data->value = jc42_temp_to_reg(val, data->extended); \ | 326 | data->value = jc42_temp_to_reg(val, data->extended); \ |
328 | err = i2c_smbus_write_word_swapped(client, reg, data->value); \ | 327 | err = i2c_smbus_write_word_swapped(data->client, reg, data->value); \ |
329 | if (err < 0) \ | 328 | if (err < 0) \ |
330 | ret = err; \ | 329 | ret = err; \ |
331 | mutex_unlock(&data->update_lock); \ | 330 | mutex_unlock(&data->update_lock); \ |
@@ -344,8 +343,7 @@ static ssize_t set_temp_crit_hyst(struct device *dev, | |||
344 | struct device_attribute *attr, | 343 | struct device_attribute *attr, |
345 | const char *buf, size_t count) | 344 | const char *buf, size_t count) |
346 | { | 345 | { |
347 | struct i2c_client *client = to_i2c_client(dev); | 346 | struct jc42_data *data = dev_get_drvdata(dev); |
348 | struct jc42_data *data = i2c_get_clientdata(client); | ||
349 | unsigned long val; | 347 | unsigned long val; |
350 | int diff, hyst; | 348 | int diff, hyst; |
351 | int err; | 349 | int err; |
@@ -368,7 +366,7 @@ static ssize_t set_temp_crit_hyst(struct device *dev, | |||
368 | mutex_lock(&data->update_lock); | 366 | mutex_lock(&data->update_lock); |
369 | data->config = (data->config & ~JC42_CFG_HYST_MASK) | 367 | data->config = (data->config & ~JC42_CFG_HYST_MASK) |
370 | | (hyst << JC42_CFG_HYST_SHIFT); | 368 | | (hyst << JC42_CFG_HYST_SHIFT); |
371 | err = i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, | 369 | err = i2c_smbus_write_word_swapped(data->client, JC42_REG_CONFIG, |
372 | data->config); | 370 | data->config); |
373 | if (err < 0) | 371 | if (err < 0) |
374 | ret = err; | 372 | ret = err; |
@@ -430,8 +428,7 @@ static umode_t jc42_attribute_mode(struct kobject *kobj, | |||
430 | struct attribute *attr, int index) | 428 | struct attribute *attr, int index) |
431 | { | 429 | { |
432 | struct device *dev = container_of(kobj, struct device, kobj); | 430 | struct device *dev = container_of(kobj, struct device, kobj); |
433 | struct i2c_client *client = to_i2c_client(dev); | 431 | struct jc42_data *data = dev_get_drvdata(dev); |
434 | struct jc42_data *data = i2c_get_clientdata(client); | ||
435 | unsigned int config = data->config; | 432 | unsigned int config = data->config; |
436 | bool readonly; | 433 | bool readonly; |
437 | 434 | ||
@@ -452,6 +449,7 @@ static const struct attribute_group jc42_group = { | |||
452 | .attrs = jc42_attributes, | 449 | .attrs = jc42_attributes, |
453 | .is_visible = jc42_attribute_mode, | 450 | .is_visible = jc42_attribute_mode, |
454 | }; | 451 | }; |
452 | __ATTRIBUTE_GROUPS(jc42); | ||
455 | 453 | ||
456 | /* Return 0 if detection is successful, -ENODEV otherwise */ | 454 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
457 | static int jc42_detect(struct i2c_client *client, struct i2c_board_info *info) | 455 | static int jc42_detect(struct i2c_client *client, struct i2c_board_info *info) |
@@ -487,14 +485,16 @@ static int jc42_detect(struct i2c_client *client, struct i2c_board_info *info) | |||
487 | 485 | ||
488 | static int jc42_probe(struct i2c_client *client, const struct i2c_device_id *id) | 486 | static int jc42_probe(struct i2c_client *client, const struct i2c_device_id *id) |
489 | { | 487 | { |
490 | struct jc42_data *data; | ||
491 | int config, cap, err; | ||
492 | struct device *dev = &client->dev; | 488 | struct device *dev = &client->dev; |
489 | struct device *hwmon_dev; | ||
490 | struct jc42_data *data; | ||
491 | int config, cap; | ||
493 | 492 | ||
494 | data = devm_kzalloc(dev, sizeof(struct jc42_data), GFP_KERNEL); | 493 | data = devm_kzalloc(dev, sizeof(struct jc42_data), GFP_KERNEL); |
495 | if (!data) | 494 | if (!data) |
496 | return -ENOMEM; | 495 | return -ENOMEM; |
497 | 496 | ||
497 | data->client = client; | ||
498 | i2c_set_clientdata(client, data); | 498 | i2c_set_clientdata(client, data); |
499 | mutex_init(&data->update_lock); | 499 | mutex_init(&data->update_lock); |
500 | 500 | ||
@@ -515,29 +515,15 @@ static int jc42_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
515 | } | 515 | } |
516 | data->config = config; | 516 | data->config = config; |
517 | 517 | ||
518 | /* Register sysfs hooks */ | 518 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
519 | err = sysfs_create_group(&dev->kobj, &jc42_group); | 519 | data, |
520 | if (err) | 520 | jc42_groups); |
521 | return err; | 521 | return PTR_ERR_OR_ZERO(hwmon_dev); |
522 | |||
523 | data->hwmon_dev = hwmon_device_register(dev); | ||
524 | if (IS_ERR(data->hwmon_dev)) { | ||
525 | err = PTR_ERR(data->hwmon_dev); | ||
526 | goto exit_remove; | ||
527 | } | ||
528 | |||
529 | return 0; | ||
530 | |||
531 | exit_remove: | ||
532 | sysfs_remove_group(&dev->kobj, &jc42_group); | ||
533 | return err; | ||
534 | } | 522 | } |
535 | 523 | ||
536 | static int jc42_remove(struct i2c_client *client) | 524 | static int jc42_remove(struct i2c_client *client) |
537 | { | 525 | { |
538 | struct jc42_data *data = i2c_get_clientdata(client); | 526 | struct jc42_data *data = i2c_get_clientdata(client); |
539 | hwmon_device_unregister(data->hwmon_dev); | ||
540 | sysfs_remove_group(&client->dev.kobj, &jc42_group); | ||
541 | 527 | ||
542 | /* Restore original configuration except hysteresis */ | 528 | /* Restore original configuration except hysteresis */ |
543 | if ((data->config & ~JC42_CFG_HYST_MASK) != | 529 | if ((data->config & ~JC42_CFG_HYST_MASK) != |
@@ -553,8 +539,8 @@ static int jc42_remove(struct i2c_client *client) | |||
553 | 539 | ||
554 | static struct jc42_data *jc42_update_device(struct device *dev) | 540 | static struct jc42_data *jc42_update_device(struct device *dev) |
555 | { | 541 | { |
556 | struct i2c_client *client = to_i2c_client(dev); | 542 | struct jc42_data *data = dev_get_drvdata(dev); |
557 | struct jc42_data *data = i2c_get_clientdata(client); | 543 | struct i2c_client *client = data->client; |
558 | struct jc42_data *ret = data; | 544 | struct jc42_data *ret = data; |
559 | int val; | 545 | int val; |
560 | 546 | ||
diff --git a/drivers/hwmon/lm70.c b/drivers/hwmon/lm70.c index 016efa26ba7c..505a59e100b0 100644 --- a/drivers/hwmon/lm70.c +++ b/drivers/hwmon/lm70.c | |||
@@ -174,7 +174,6 @@ out_dev_reg_failed: | |||
174 | out_dev_create_file_failed: | 174 | out_dev_create_file_failed: |
175 | device_remove_file(&spi->dev, &dev_attr_temp1_input); | 175 | device_remove_file(&spi->dev, &dev_attr_temp1_input); |
176 | out_dev_create_temp_file_failed: | 176 | out_dev_create_temp_file_failed: |
177 | spi_set_drvdata(spi, NULL); | ||
178 | return status; | 177 | return status; |
179 | } | 178 | } |
180 | 179 | ||
@@ -185,7 +184,6 @@ static int lm70_remove(struct spi_device *spi) | |||
185 | hwmon_device_unregister(p_lm70->hwmon_dev); | 184 | hwmon_device_unregister(p_lm70->hwmon_dev); |
186 | device_remove_file(&spi->dev, &dev_attr_temp1_input); | 185 | device_remove_file(&spi->dev, &dev_attr_temp1_input); |
187 | device_remove_file(&spi->dev, &dev_attr_name); | 186 | device_remove_file(&spi->dev, &dev_attr_name); |
188 | spi_set_drvdata(spi, NULL); | ||
189 | 187 | ||
190 | return 0; | 188 | return 0; |
191 | } | 189 | } |
diff --git a/drivers/hwmon/lm73.c b/drivers/hwmon/lm73.c index 9bde9644b102..9653bb870a47 100644 --- a/drivers/hwmon/lm73.c +++ b/drivers/hwmon/lm73.c | |||
@@ -55,7 +55,7 @@ static const unsigned short lm73_convrates[] = { | |||
55 | }; | 55 | }; |
56 | 56 | ||
57 | struct lm73_data { | 57 | struct lm73_data { |
58 | struct device *hwmon_dev; | 58 | struct i2c_client *client; |
59 | struct mutex lock; | 59 | struct mutex lock; |
60 | u8 ctrl; /* control register value */ | 60 | u8 ctrl; /* control register value */ |
61 | }; | 61 | }; |
@@ -66,7 +66,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da, | |||
66 | const char *buf, size_t count) | 66 | const char *buf, size_t count) |
67 | { | 67 | { |
68 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | 68 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
69 | struct i2c_client *client = to_i2c_client(dev); | 69 | struct lm73_data *data = dev_get_drvdata(dev); |
70 | long temp; | 70 | long temp; |
71 | short value; | 71 | short value; |
72 | s32 err; | 72 | s32 err; |
@@ -77,7 +77,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da, | |||
77 | 77 | ||
78 | /* Write value */ | 78 | /* Write value */ |
79 | value = clamp_val(temp / 250, LM73_TEMP_MIN, LM73_TEMP_MAX) << 5; | 79 | value = clamp_val(temp / 250, LM73_TEMP_MIN, LM73_TEMP_MAX) << 5; |
80 | err = i2c_smbus_write_word_swapped(client, attr->index, value); | 80 | err = i2c_smbus_write_word_swapped(data->client, attr->index, value); |
81 | return (err < 0) ? err : count; | 81 | return (err < 0) ? err : count; |
82 | } | 82 | } |
83 | 83 | ||
@@ -85,10 +85,10 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *da, | |||
85 | char *buf) | 85 | char *buf) |
86 | { | 86 | { |
87 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | 87 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
88 | struct i2c_client *client = to_i2c_client(dev); | 88 | struct lm73_data *data = dev_get_drvdata(dev); |
89 | int temp; | 89 | int temp; |
90 | 90 | ||
91 | s32 err = i2c_smbus_read_word_swapped(client, attr->index); | 91 | s32 err = i2c_smbus_read_word_swapped(data->client, attr->index); |
92 | if (err < 0) | 92 | if (err < 0) |
93 | return err; | 93 | return err; |
94 | 94 | ||
@@ -101,8 +101,7 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *da, | |||
101 | static ssize_t set_convrate(struct device *dev, struct device_attribute *da, | 101 | static ssize_t set_convrate(struct device *dev, struct device_attribute *da, |
102 | const char *buf, size_t count) | 102 | const char *buf, size_t count) |
103 | { | 103 | { |
104 | struct i2c_client *client = to_i2c_client(dev); | 104 | struct lm73_data *data = dev_get_drvdata(dev); |
105 | struct lm73_data *data = i2c_get_clientdata(client); | ||
106 | unsigned long convrate; | 105 | unsigned long convrate; |
107 | s32 err; | 106 | s32 err; |
108 | int res = 0; | 107 | int res = 0; |
@@ -124,7 +123,8 @@ static ssize_t set_convrate(struct device *dev, struct device_attribute *da, | |||
124 | mutex_lock(&data->lock); | 123 | mutex_lock(&data->lock); |
125 | data->ctrl &= LM73_CTRL_TO_MASK; | 124 | data->ctrl &= LM73_CTRL_TO_MASK; |
126 | data->ctrl |= res << LM73_CTRL_RES_SHIFT; | 125 | data->ctrl |= res << LM73_CTRL_RES_SHIFT; |
127 | err = i2c_smbus_write_byte_data(client, LM73_REG_CTRL, data->ctrl); | 126 | err = i2c_smbus_write_byte_data(data->client, LM73_REG_CTRL, |
127 | data->ctrl); | ||
128 | mutex_unlock(&data->lock); | 128 | mutex_unlock(&data->lock); |
129 | 129 | ||
130 | if (err < 0) | 130 | if (err < 0) |
@@ -136,8 +136,7 @@ static ssize_t set_convrate(struct device *dev, struct device_attribute *da, | |||
136 | static ssize_t show_convrate(struct device *dev, struct device_attribute *da, | 136 | static ssize_t show_convrate(struct device *dev, struct device_attribute *da, |
137 | char *buf) | 137 | char *buf) |
138 | { | 138 | { |
139 | struct i2c_client *client = to_i2c_client(dev); | 139 | struct lm73_data *data = dev_get_drvdata(dev); |
140 | struct lm73_data *data = i2c_get_clientdata(client); | ||
141 | int res; | 140 | int res; |
142 | 141 | ||
143 | res = (data->ctrl & LM73_CTRL_RES_MASK) >> LM73_CTRL_RES_SHIFT; | 142 | res = (data->ctrl & LM73_CTRL_RES_MASK) >> LM73_CTRL_RES_SHIFT; |
@@ -147,13 +146,12 @@ static ssize_t show_convrate(struct device *dev, struct device_attribute *da, | |||
147 | static ssize_t show_maxmin_alarm(struct device *dev, | 146 | static ssize_t show_maxmin_alarm(struct device *dev, |
148 | struct device_attribute *da, char *buf) | 147 | struct device_attribute *da, char *buf) |
149 | { | 148 | { |
150 | struct i2c_client *client = to_i2c_client(dev); | ||
151 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | 149 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
152 | struct lm73_data *data = i2c_get_clientdata(client); | 150 | struct lm73_data *data = dev_get_drvdata(dev); |
153 | s32 ctrl; | 151 | s32 ctrl; |
154 | 152 | ||
155 | mutex_lock(&data->lock); | 153 | mutex_lock(&data->lock); |
156 | ctrl = i2c_smbus_read_byte_data(client, LM73_REG_CTRL); | 154 | ctrl = i2c_smbus_read_byte_data(data->client, LM73_REG_CTRL); |
157 | if (ctrl < 0) | 155 | if (ctrl < 0) |
158 | goto abort; | 156 | goto abort; |
159 | data->ctrl = ctrl; | 157 | data->ctrl = ctrl; |
@@ -183,7 +181,7 @@ static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, | |||
183 | static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, | 181 | static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, |
184 | show_maxmin_alarm, NULL, LM73_CTRL_LO_SHIFT); | 182 | show_maxmin_alarm, NULL, LM73_CTRL_LO_SHIFT); |
185 | 183 | ||
186 | static struct attribute *lm73_attributes[] = { | 184 | static struct attribute *lm73_attrs[] = { |
187 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 185 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
188 | &sensor_dev_attr_temp1_max.dev_attr.attr, | 186 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
189 | &sensor_dev_attr_temp1_min.dev_attr.attr, | 187 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
@@ -192,10 +190,7 @@ static struct attribute *lm73_attributes[] = { | |||
192 | &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, | 190 | &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, |
193 | NULL | 191 | NULL |
194 | }; | 192 | }; |
195 | 193 | ATTRIBUTE_GROUPS(lm73); | |
196 | static const struct attribute_group lm73_group = { | ||
197 | .attrs = lm73_attributes, | ||
198 | }; | ||
199 | 194 | ||
200 | /*-----------------------------------------------------------------------*/ | 195 | /*-----------------------------------------------------------------------*/ |
201 | 196 | ||
@@ -204,16 +199,16 @@ static const struct attribute_group lm73_group = { | |||
204 | static int | 199 | static int |
205 | lm73_probe(struct i2c_client *client, const struct i2c_device_id *id) | 200 | lm73_probe(struct i2c_client *client, const struct i2c_device_id *id) |
206 | { | 201 | { |
207 | int status; | 202 | struct device *dev = &client->dev; |
203 | struct device *hwmon_dev; | ||
208 | struct lm73_data *data; | 204 | struct lm73_data *data; |
209 | int ctrl; | 205 | int ctrl; |
210 | 206 | ||
211 | data = devm_kzalloc(&client->dev, sizeof(struct lm73_data), | 207 | data = devm_kzalloc(dev, sizeof(struct lm73_data), GFP_KERNEL); |
212 | GFP_KERNEL); | ||
213 | if (!data) | 208 | if (!data) |
214 | return -ENOMEM; | 209 | return -ENOMEM; |
215 | 210 | ||
216 | i2c_set_clientdata(client, data); | 211 | data->client = client; |
217 | mutex_init(&data->lock); | 212 | mutex_init(&data->lock); |
218 | 213 | ||
219 | ctrl = i2c_smbus_read_byte_data(client, LM73_REG_CTRL); | 214 | ctrl = i2c_smbus_read_byte_data(client, LM73_REG_CTRL); |
@@ -221,33 +216,13 @@ lm73_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
221 | return ctrl; | 216 | return ctrl; |
222 | data->ctrl = ctrl; | 217 | data->ctrl = ctrl; |
223 | 218 | ||
224 | /* Register sysfs hooks */ | 219 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
225 | status = sysfs_create_group(&client->dev.kobj, &lm73_group); | 220 | data, lm73_groups); |
226 | if (status) | 221 | if (IS_ERR(hwmon_dev)) |
227 | return status; | 222 | return PTR_ERR(hwmon_dev); |
228 | |||
229 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
230 | if (IS_ERR(data->hwmon_dev)) { | ||
231 | status = PTR_ERR(data->hwmon_dev); | ||
232 | goto exit_remove; | ||
233 | } | ||
234 | 223 | ||
235 | dev_info(&client->dev, "%s: sensor '%s'\n", | 224 | dev_info(dev, "sensor '%s'\n", client->name); |
236 | dev_name(data->hwmon_dev), client->name); | ||
237 | |||
238 | return 0; | ||
239 | |||
240 | exit_remove: | ||
241 | sysfs_remove_group(&client->dev.kobj, &lm73_group); | ||
242 | return status; | ||
243 | } | ||
244 | |||
245 | static int lm73_remove(struct i2c_client *client) | ||
246 | { | ||
247 | struct lm73_data *data = i2c_get_clientdata(client); | ||
248 | 225 | ||
249 | hwmon_device_unregister(data->hwmon_dev); | ||
250 | sysfs_remove_group(&client->dev.kobj, &lm73_group); | ||
251 | return 0; | 226 | return 0; |
252 | } | 227 | } |
253 | 228 | ||
@@ -300,7 +275,6 @@ static struct i2c_driver lm73_driver = { | |||
300 | .name = "lm73", | 275 | .name = "lm73", |
301 | }, | 276 | }, |
302 | .probe = lm73_probe, | 277 | .probe = lm73_probe, |
303 | .remove = lm73_remove, | ||
304 | .id_table = lm73_ids, | 278 | .id_table = lm73_ids, |
305 | .detect = lm73_detect, | 279 | .detect = lm73_detect, |
306 | .address_list = normal_i2c, | 280 | .address_list = normal_i2c, |
diff --git a/drivers/hwmon/lm95234.c b/drivers/hwmon/lm95234.c index 307c9eaeeb9f..411202bdaf6b 100644 --- a/drivers/hwmon/lm95234.c +++ b/drivers/hwmon/lm95234.c | |||
@@ -57,7 +57,7 @@ static const unsigned short normal_i2c[] = { 0x18, 0x4d, 0x4e, I2C_CLIENT_END }; | |||
57 | 57 | ||
58 | /* Client data (each client gets its own) */ | 58 | /* Client data (each client gets its own) */ |
59 | struct lm95234_data { | 59 | struct lm95234_data { |
60 | struct device *hwmon_dev; | 60 | struct i2c_client *client; |
61 | struct mutex update_lock; | 61 | struct mutex update_lock; |
62 | unsigned long last_updated, interval; /* in jiffies */ | 62 | unsigned long last_updated, interval; /* in jiffies */ |
63 | bool valid; /* false until following fields are valid */ | 63 | bool valid; /* false until following fields are valid */ |
@@ -114,9 +114,9 @@ static u16 update_intervals[] = { 143, 364, 1000, 2500 }; | |||
114 | 114 | ||
115 | /* Fill value cache. Must be called with update lock held. */ | 115 | /* Fill value cache. Must be called with update lock held. */ |
116 | 116 | ||
117 | static int lm95234_fill_cache(struct i2c_client *client) | 117 | static int lm95234_fill_cache(struct lm95234_data *data, |
118 | struct i2c_client *client) | ||
118 | { | 119 | { |
119 | struct lm95234_data *data = i2c_get_clientdata(client); | ||
120 | int i, ret; | 120 | int i, ret; |
121 | 121 | ||
122 | ret = i2c_smbus_read_byte_data(client, LM95234_REG_CONVRATE); | 122 | ret = i2c_smbus_read_byte_data(client, LM95234_REG_CONVRATE); |
@@ -157,9 +157,9 @@ static int lm95234_fill_cache(struct i2c_client *client) | |||
157 | return 0; | 157 | return 0; |
158 | } | 158 | } |
159 | 159 | ||
160 | static int lm95234_update_device(struct i2c_client *client, | 160 | static int lm95234_update_device(struct lm95234_data *data) |
161 | struct lm95234_data *data) | ||
162 | { | 161 | { |
162 | struct i2c_client *client = data->client; | ||
163 | int ret; | 163 | int ret; |
164 | 164 | ||
165 | mutex_lock(&data->update_lock); | 165 | mutex_lock(&data->update_lock); |
@@ -169,7 +169,7 @@ static int lm95234_update_device(struct i2c_client *client, | |||
169 | int i; | 169 | int i; |
170 | 170 | ||
171 | if (!data->valid) { | 171 | if (!data->valid) { |
172 | ret = lm95234_fill_cache(client); | 172 | ret = lm95234_fill_cache(data, client); |
173 | if (ret < 0) | 173 | if (ret < 0) |
174 | goto abort; | 174 | goto abort; |
175 | } | 175 | } |
@@ -209,10 +209,9 @@ abort: | |||
209 | static ssize_t show_temp(struct device *dev, struct device_attribute *attr, | 209 | static ssize_t show_temp(struct device *dev, struct device_attribute *attr, |
210 | char *buf) | 210 | char *buf) |
211 | { | 211 | { |
212 | struct i2c_client *client = to_i2c_client(dev); | 212 | struct lm95234_data *data = dev_get_drvdata(dev); |
213 | struct lm95234_data *data = i2c_get_clientdata(client); | ||
214 | int index = to_sensor_dev_attr(attr)->index; | 213 | int index = to_sensor_dev_attr(attr)->index; |
215 | int ret = lm95234_update_device(client, data); | 214 | int ret = lm95234_update_device(data); |
216 | 215 | ||
217 | if (ret) | 216 | if (ret) |
218 | return ret; | 217 | return ret; |
@@ -224,10 +223,9 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *attr, | |||
224 | static ssize_t show_alarm(struct device *dev, | 223 | static ssize_t show_alarm(struct device *dev, |
225 | struct device_attribute *attr, char *buf) | 224 | struct device_attribute *attr, char *buf) |
226 | { | 225 | { |
227 | struct i2c_client *client = to_i2c_client(dev); | 226 | struct lm95234_data *data = dev_get_drvdata(dev); |
228 | struct lm95234_data *data = i2c_get_clientdata(client); | ||
229 | u32 mask = to_sensor_dev_attr(attr)->index; | 227 | u32 mask = to_sensor_dev_attr(attr)->index; |
230 | int ret = lm95234_update_device(client, data); | 228 | int ret = lm95234_update_device(data); |
231 | 229 | ||
232 | if (ret) | 230 | if (ret) |
233 | return ret; | 231 | return ret; |
@@ -238,10 +236,9 @@ static ssize_t show_alarm(struct device *dev, | |||
238 | static ssize_t show_type(struct device *dev, struct device_attribute *attr, | 236 | static ssize_t show_type(struct device *dev, struct device_attribute *attr, |
239 | char *buf) | 237 | char *buf) |
240 | { | 238 | { |
241 | struct i2c_client *client = to_i2c_client(dev); | 239 | struct lm95234_data *data = dev_get_drvdata(dev); |
242 | struct lm95234_data *data = i2c_get_clientdata(client); | ||
243 | u8 mask = to_sensor_dev_attr(attr)->index; | 240 | u8 mask = to_sensor_dev_attr(attr)->index; |
244 | int ret = lm95234_update_device(client, data); | 241 | int ret = lm95234_update_device(data); |
245 | 242 | ||
246 | if (ret) | 243 | if (ret) |
247 | return ret; | 244 | return ret; |
@@ -252,11 +249,10 @@ static ssize_t show_type(struct device *dev, struct device_attribute *attr, | |||
252 | static ssize_t set_type(struct device *dev, struct device_attribute *attr, | 249 | static ssize_t set_type(struct device *dev, struct device_attribute *attr, |
253 | const char *buf, size_t count) | 250 | const char *buf, size_t count) |
254 | { | 251 | { |
255 | struct i2c_client *client = to_i2c_client(dev); | 252 | struct lm95234_data *data = dev_get_drvdata(dev); |
256 | struct lm95234_data *data = i2c_get_clientdata(client); | ||
257 | unsigned long val; | 253 | unsigned long val; |
258 | u8 mask = to_sensor_dev_attr(attr)->index; | 254 | u8 mask = to_sensor_dev_attr(attr)->index; |
259 | int ret = lm95234_update_device(client, data); | 255 | int ret = lm95234_update_device(data); |
260 | 256 | ||
261 | if (ret) | 257 | if (ret) |
262 | return ret; | 258 | return ret; |
@@ -274,7 +270,7 @@ static ssize_t set_type(struct device *dev, struct device_attribute *attr, | |||
274 | else | 270 | else |
275 | data->sensor_type &= ~mask; | 271 | data->sensor_type &= ~mask; |
276 | data->valid = false; | 272 | data->valid = false; |
277 | i2c_smbus_write_byte_data(client, LM95234_REG_REM_MODEL, | 273 | i2c_smbus_write_byte_data(data->client, LM95234_REG_REM_MODEL, |
278 | data->sensor_type); | 274 | data->sensor_type); |
279 | mutex_unlock(&data->update_lock); | 275 | mutex_unlock(&data->update_lock); |
280 | 276 | ||
@@ -284,10 +280,9 @@ static ssize_t set_type(struct device *dev, struct device_attribute *attr, | |||
284 | static ssize_t show_tcrit2(struct device *dev, struct device_attribute *attr, | 280 | static ssize_t show_tcrit2(struct device *dev, struct device_attribute *attr, |
285 | char *buf) | 281 | char *buf) |
286 | { | 282 | { |
287 | struct i2c_client *client = to_i2c_client(dev); | 283 | struct lm95234_data *data = dev_get_drvdata(dev); |
288 | struct lm95234_data *data = i2c_get_clientdata(client); | ||
289 | int index = to_sensor_dev_attr(attr)->index; | 284 | int index = to_sensor_dev_attr(attr)->index; |
290 | int ret = lm95234_update_device(client, data); | 285 | int ret = lm95234_update_device(data); |
291 | 286 | ||
292 | if (ret) | 287 | if (ret) |
293 | return ret; | 288 | return ret; |
@@ -298,11 +293,10 @@ static ssize_t show_tcrit2(struct device *dev, struct device_attribute *attr, | |||
298 | static ssize_t set_tcrit2(struct device *dev, struct device_attribute *attr, | 293 | static ssize_t set_tcrit2(struct device *dev, struct device_attribute *attr, |
299 | const char *buf, size_t count) | 294 | const char *buf, size_t count) |
300 | { | 295 | { |
301 | struct i2c_client *client = to_i2c_client(dev); | 296 | struct lm95234_data *data = dev_get_drvdata(dev); |
302 | struct lm95234_data *data = i2c_get_clientdata(client); | ||
303 | int index = to_sensor_dev_attr(attr)->index; | 297 | int index = to_sensor_dev_attr(attr)->index; |
304 | long val; | 298 | long val; |
305 | int ret = lm95234_update_device(client, data); | 299 | int ret = lm95234_update_device(data); |
306 | 300 | ||
307 | if (ret) | 301 | if (ret) |
308 | return ret; | 302 | return ret; |
@@ -315,7 +309,7 @@ static ssize_t set_tcrit2(struct device *dev, struct device_attribute *attr, | |||
315 | 309 | ||
316 | mutex_lock(&data->update_lock); | 310 | mutex_lock(&data->update_lock); |
317 | data->tcrit2[index] = val; | 311 | data->tcrit2[index] = val; |
318 | i2c_smbus_write_byte_data(client, LM95234_REG_TCRIT2(index), val); | 312 | i2c_smbus_write_byte_data(data->client, LM95234_REG_TCRIT2(index), val); |
319 | mutex_unlock(&data->update_lock); | 313 | mutex_unlock(&data->update_lock); |
320 | 314 | ||
321 | return count; | 315 | return count; |
@@ -324,10 +318,9 @@ static ssize_t set_tcrit2(struct device *dev, struct device_attribute *attr, | |||
324 | static ssize_t show_tcrit2_hyst(struct device *dev, | 318 | static ssize_t show_tcrit2_hyst(struct device *dev, |
325 | struct device_attribute *attr, char *buf) | 319 | struct device_attribute *attr, char *buf) |
326 | { | 320 | { |
327 | struct i2c_client *client = to_i2c_client(dev); | 321 | struct lm95234_data *data = dev_get_drvdata(dev); |
328 | struct lm95234_data *data = i2c_get_clientdata(client); | ||
329 | int index = to_sensor_dev_attr(attr)->index; | 322 | int index = to_sensor_dev_attr(attr)->index; |
330 | int ret = lm95234_update_device(client, data); | 323 | int ret = lm95234_update_device(data); |
331 | 324 | ||
332 | if (ret) | 325 | if (ret) |
333 | return ret; | 326 | return ret; |
@@ -340,8 +333,7 @@ static ssize_t show_tcrit2_hyst(struct device *dev, | |||
340 | static ssize_t show_tcrit1(struct device *dev, struct device_attribute *attr, | 333 | static ssize_t show_tcrit1(struct device *dev, struct device_attribute *attr, |
341 | char *buf) | 334 | char *buf) |
342 | { | 335 | { |
343 | struct i2c_client *client = to_i2c_client(dev); | 336 | struct lm95234_data *data = dev_get_drvdata(dev); |
344 | struct lm95234_data *data = i2c_get_clientdata(client); | ||
345 | int index = to_sensor_dev_attr(attr)->index; | 337 | int index = to_sensor_dev_attr(attr)->index; |
346 | 338 | ||
347 | return sprintf(buf, "%u", data->tcrit1[index] * 1000); | 339 | return sprintf(buf, "%u", data->tcrit1[index] * 1000); |
@@ -350,11 +342,10 @@ static ssize_t show_tcrit1(struct device *dev, struct device_attribute *attr, | |||
350 | static ssize_t set_tcrit1(struct device *dev, struct device_attribute *attr, | 342 | static ssize_t set_tcrit1(struct device *dev, struct device_attribute *attr, |
351 | const char *buf, size_t count) | 343 | const char *buf, size_t count) |
352 | { | 344 | { |
353 | struct i2c_client *client = to_i2c_client(dev); | 345 | struct lm95234_data *data = dev_get_drvdata(dev); |
354 | struct lm95234_data *data = i2c_get_clientdata(client); | ||
355 | int index = to_sensor_dev_attr(attr)->index; | 346 | int index = to_sensor_dev_attr(attr)->index; |
347 | int ret = lm95234_update_device(data); | ||
356 | long val; | 348 | long val; |
357 | int ret = lm95234_update_device(client, data); | ||
358 | 349 | ||
359 | if (ret) | 350 | if (ret) |
360 | return ret; | 351 | return ret; |
@@ -367,7 +358,7 @@ static ssize_t set_tcrit1(struct device *dev, struct device_attribute *attr, | |||
367 | 358 | ||
368 | mutex_lock(&data->update_lock); | 359 | mutex_lock(&data->update_lock); |
369 | data->tcrit1[index] = val; | 360 | data->tcrit1[index] = val; |
370 | i2c_smbus_write_byte_data(client, LM95234_REG_TCRIT1(index), val); | 361 | i2c_smbus_write_byte_data(data->client, LM95234_REG_TCRIT1(index), val); |
371 | mutex_unlock(&data->update_lock); | 362 | mutex_unlock(&data->update_lock); |
372 | 363 | ||
373 | return count; | 364 | return count; |
@@ -376,10 +367,9 @@ static ssize_t set_tcrit1(struct device *dev, struct device_attribute *attr, | |||
376 | static ssize_t show_tcrit1_hyst(struct device *dev, | 367 | static ssize_t show_tcrit1_hyst(struct device *dev, |
377 | struct device_attribute *attr, char *buf) | 368 | struct device_attribute *attr, char *buf) |
378 | { | 369 | { |
379 | struct i2c_client *client = to_i2c_client(dev); | 370 | struct lm95234_data *data = dev_get_drvdata(dev); |
380 | struct lm95234_data *data = i2c_get_clientdata(client); | ||
381 | int index = to_sensor_dev_attr(attr)->index; | 371 | int index = to_sensor_dev_attr(attr)->index; |
382 | int ret = lm95234_update_device(client, data); | 372 | int ret = lm95234_update_device(data); |
383 | 373 | ||
384 | if (ret) | 374 | if (ret) |
385 | return ret; | 375 | return ret; |
@@ -393,11 +383,10 @@ static ssize_t set_tcrit1_hyst(struct device *dev, | |||
393 | struct device_attribute *attr, | 383 | struct device_attribute *attr, |
394 | const char *buf, size_t count) | 384 | const char *buf, size_t count) |
395 | { | 385 | { |
396 | struct i2c_client *client = to_i2c_client(dev); | 386 | struct lm95234_data *data = dev_get_drvdata(dev); |
397 | struct lm95234_data *data = i2c_get_clientdata(client); | ||
398 | int index = to_sensor_dev_attr(attr)->index; | 387 | int index = to_sensor_dev_attr(attr)->index; |
388 | int ret = lm95234_update_device(data); | ||
399 | long val; | 389 | long val; |
400 | int ret = lm95234_update_device(client, data); | ||
401 | 390 | ||
402 | if (ret) | 391 | if (ret) |
403 | return ret; | 392 | return ret; |
@@ -411,7 +400,7 @@ static ssize_t set_tcrit1_hyst(struct device *dev, | |||
411 | 400 | ||
412 | mutex_lock(&data->update_lock); | 401 | mutex_lock(&data->update_lock); |
413 | data->thyst = val; | 402 | data->thyst = val; |
414 | i2c_smbus_write_byte_data(client, LM95234_REG_TCRIT_HYST, val); | 403 | i2c_smbus_write_byte_data(data->client, LM95234_REG_TCRIT_HYST, val); |
415 | mutex_unlock(&data->update_lock); | 404 | mutex_unlock(&data->update_lock); |
416 | 405 | ||
417 | return count; | 406 | return count; |
@@ -420,10 +409,9 @@ static ssize_t set_tcrit1_hyst(struct device *dev, | |||
420 | static ssize_t show_offset(struct device *dev, struct device_attribute *attr, | 409 | static ssize_t show_offset(struct device *dev, struct device_attribute *attr, |
421 | char *buf) | 410 | char *buf) |
422 | { | 411 | { |
423 | struct i2c_client *client = to_i2c_client(dev); | 412 | struct lm95234_data *data = dev_get_drvdata(dev); |
424 | struct lm95234_data *data = i2c_get_clientdata(client); | ||
425 | int index = to_sensor_dev_attr(attr)->index; | 413 | int index = to_sensor_dev_attr(attr)->index; |
426 | int ret = lm95234_update_device(client, data); | 414 | int ret = lm95234_update_device(data); |
427 | 415 | ||
428 | if (ret) | 416 | if (ret) |
429 | return ret; | 417 | return ret; |
@@ -434,11 +422,10 @@ static ssize_t show_offset(struct device *dev, struct device_attribute *attr, | |||
434 | static ssize_t set_offset(struct device *dev, struct device_attribute *attr, | 422 | static ssize_t set_offset(struct device *dev, struct device_attribute *attr, |
435 | const char *buf, size_t count) | 423 | const char *buf, size_t count) |
436 | { | 424 | { |
437 | struct i2c_client *client = to_i2c_client(dev); | 425 | struct lm95234_data *data = dev_get_drvdata(dev); |
438 | struct lm95234_data *data = i2c_get_clientdata(client); | ||
439 | int index = to_sensor_dev_attr(attr)->index; | 426 | int index = to_sensor_dev_attr(attr)->index; |
427 | int ret = lm95234_update_device(data); | ||
440 | long val; | 428 | long val; |
441 | int ret = lm95234_update_device(client, data); | ||
442 | 429 | ||
443 | if (ret) | 430 | if (ret) |
444 | return ret; | 431 | return ret; |
@@ -452,7 +439,7 @@ static ssize_t set_offset(struct device *dev, struct device_attribute *attr, | |||
452 | 439 | ||
453 | mutex_lock(&data->update_lock); | 440 | mutex_lock(&data->update_lock); |
454 | data->toffset[index] = val; | 441 | data->toffset[index] = val; |
455 | i2c_smbus_write_byte_data(client, LM95234_REG_OFFSET(index), val); | 442 | i2c_smbus_write_byte_data(data->client, LM95234_REG_OFFSET(index), val); |
456 | mutex_unlock(&data->update_lock); | 443 | mutex_unlock(&data->update_lock); |
457 | 444 | ||
458 | return count; | 445 | return count; |
@@ -461,9 +448,8 @@ static ssize_t set_offset(struct device *dev, struct device_attribute *attr, | |||
461 | static ssize_t show_interval(struct device *dev, struct device_attribute *attr, | 448 | static ssize_t show_interval(struct device *dev, struct device_attribute *attr, |
462 | char *buf) | 449 | char *buf) |
463 | { | 450 | { |
464 | struct i2c_client *client = to_i2c_client(dev); | 451 | struct lm95234_data *data = dev_get_drvdata(dev); |
465 | struct lm95234_data *data = i2c_get_clientdata(client); | 452 | int ret = lm95234_update_device(data); |
466 | int ret = lm95234_update_device(client, data); | ||
467 | 453 | ||
468 | if (ret) | 454 | if (ret) |
469 | return ret; | 455 | return ret; |
@@ -475,11 +461,10 @@ static ssize_t show_interval(struct device *dev, struct device_attribute *attr, | |||
475 | static ssize_t set_interval(struct device *dev, struct device_attribute *attr, | 461 | static ssize_t set_interval(struct device *dev, struct device_attribute *attr, |
476 | const char *buf, size_t count) | 462 | const char *buf, size_t count) |
477 | { | 463 | { |
478 | struct i2c_client *client = to_i2c_client(dev); | 464 | struct lm95234_data *data = dev_get_drvdata(dev); |
479 | struct lm95234_data *data = i2c_get_clientdata(client); | 465 | int ret = lm95234_update_device(data); |
480 | unsigned long val; | 466 | unsigned long val; |
481 | u8 regval; | 467 | u8 regval; |
482 | int ret = lm95234_update_device(client, data); | ||
483 | 468 | ||
484 | if (ret) | 469 | if (ret) |
485 | return ret; | 470 | return ret; |
@@ -495,7 +480,7 @@ static ssize_t set_interval(struct device *dev, struct device_attribute *attr, | |||
495 | 480 | ||
496 | mutex_lock(&data->update_lock); | 481 | mutex_lock(&data->update_lock); |
497 | data->interval = msecs_to_jiffies(update_intervals[regval]); | 482 | data->interval = msecs_to_jiffies(update_intervals[regval]); |
498 | i2c_smbus_write_byte_data(client, LM95234_REG_CONVRATE, regval); | 483 | i2c_smbus_write_byte_data(data->client, LM95234_REG_CONVRATE, regval); |
499 | mutex_unlock(&data->update_lock); | 484 | mutex_unlock(&data->update_lock); |
500 | 485 | ||
501 | return count; | 486 | return count; |
@@ -579,7 +564,7 @@ static SENSOR_DEVICE_ATTR(temp5_offset, S_IWUSR | S_IRUGO, show_offset, | |||
579 | static DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, show_interval, | 564 | static DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, show_interval, |
580 | set_interval); | 565 | set_interval); |
581 | 566 | ||
582 | static struct attribute *lm95234_attributes[] = { | 567 | static struct attribute *lm95234_attrs[] = { |
583 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 568 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
584 | &sensor_dev_attr_temp2_input.dev_attr.attr, | 569 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
585 | &sensor_dev_attr_temp3_input.dev_attr.attr, | 570 | &sensor_dev_attr_temp3_input.dev_attr.attr, |
@@ -621,10 +606,7 @@ static struct attribute *lm95234_attributes[] = { | |||
621 | &dev_attr_update_interval.attr, | 606 | &dev_attr_update_interval.attr, |
622 | NULL | 607 | NULL |
623 | }; | 608 | }; |
624 | 609 | ATTRIBUTE_GROUPS(lm95234); | |
625 | static const struct attribute_group lm95234_group = { | ||
626 | .attrs = lm95234_attributes, | ||
627 | }; | ||
628 | 610 | ||
629 | static int lm95234_detect(struct i2c_client *client, | 611 | static int lm95234_detect(struct i2c_client *client, |
630 | struct i2c_board_info *info) | 612 | struct i2c_board_info *info) |
@@ -701,13 +683,14 @@ static int lm95234_probe(struct i2c_client *client, | |||
701 | { | 683 | { |
702 | struct device *dev = &client->dev; | 684 | struct device *dev = &client->dev; |
703 | struct lm95234_data *data; | 685 | struct lm95234_data *data; |
686 | struct device *hwmon_dev; | ||
704 | int err; | 687 | int err; |
705 | 688 | ||
706 | data = devm_kzalloc(dev, sizeof(struct lm95234_data), GFP_KERNEL); | 689 | data = devm_kzalloc(dev, sizeof(struct lm95234_data), GFP_KERNEL); |
707 | if (!data) | 690 | if (!data) |
708 | return -ENOMEM; | 691 | return -ENOMEM; |
709 | 692 | ||
710 | i2c_set_clientdata(client, data); | 693 | data->client = client; |
711 | mutex_init(&data->update_lock); | 694 | mutex_init(&data->update_lock); |
712 | 695 | ||
713 | /* Initialize the LM95234 chip */ | 696 | /* Initialize the LM95234 chip */ |
@@ -715,32 +698,10 @@ static int lm95234_probe(struct i2c_client *client, | |||
715 | if (err < 0) | 698 | if (err < 0) |
716 | return err; | 699 | return err; |
717 | 700 | ||
718 | /* Register sysfs hooks */ | 701 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
719 | err = sysfs_create_group(&dev->kobj, &lm95234_group); | 702 | data, |
720 | if (err) | 703 | lm95234_groups); |
721 | return err; | 704 | return PTR_ERR_OR_ZERO(hwmon_dev); |
722 | |||
723 | data->hwmon_dev = hwmon_device_register(dev); | ||
724 | if (IS_ERR(data->hwmon_dev)) { | ||
725 | err = PTR_ERR(data->hwmon_dev); | ||
726 | goto exit_remove_files; | ||
727 | } | ||
728 | |||
729 | return 0; | ||
730 | |||
731 | exit_remove_files: | ||
732 | sysfs_remove_group(&dev->kobj, &lm95234_group); | ||
733 | return err; | ||
734 | } | ||
735 | |||
736 | static int lm95234_remove(struct i2c_client *client) | ||
737 | { | ||
738 | struct lm95234_data *data = i2c_get_clientdata(client); | ||
739 | |||
740 | hwmon_device_unregister(data->hwmon_dev); | ||
741 | sysfs_remove_group(&client->dev.kobj, &lm95234_group); | ||
742 | |||
743 | return 0; | ||
744 | } | 705 | } |
745 | 706 | ||
746 | /* Driver data (common to all clients) */ | 707 | /* Driver data (common to all clients) */ |
@@ -756,7 +717,6 @@ static struct i2c_driver lm95234_driver = { | |||
756 | .name = DRVNAME, | 717 | .name = DRVNAME, |
757 | }, | 718 | }, |
758 | .probe = lm95234_probe, | 719 | .probe = lm95234_probe, |
759 | .remove = lm95234_remove, | ||
760 | .id_table = lm95234_id, | 720 | .id_table = lm95234_id, |
761 | .detect = lm95234_detect, | 721 | .detect = lm95234_detect, |
762 | .address_list = normal_i2c, | 722 | .address_list = normal_i2c, |
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 | ||
53 | struct ltc4245_data { | 53 | struct 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 | */ |
78 | static void ltc4245_update_gpios(struct device *dev) | 80 | static 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 | ||
131 | static struct ltc4245_data *ltc4245_update_device(struct device *dev) | 133 | static 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 | ||
458 | static int ltc4245_sysfs_create_groups(struct i2c_client *client) | 460 | static 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] = <c4245_std_group; |
462 | int ret; | ||
463 | |||
464 | /* register the standard sysfs attributes */ | ||
465 | ret = sysfs_create_group(&dev->kobj, <c4245_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, <c4245_gpio_group); | ||
474 | if (ret) { | ||
475 | dev_err(dev, "unable to register gpio attributes\n"); | ||
476 | sysfs_remove_group(&dev->kobj, <c4245_std_group); | ||
477 | return ret; | ||
478 | } | ||
479 | } | ||
480 | |||
481 | return 0; | ||
482 | } | ||
483 | |||
484 | static 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, <c4245_gpio_group); | 467 | data->groups[1] = <c4245_gpio_group; |
491 | |||
492 | sysfs_remove_group(&dev->kobj, <c4245_std_group); | ||
493 | } | 468 | } |
494 | 469 | ||
495 | static bool ltc4245_use_extra_gpios(struct i2c_client *client) | 470 | static 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 | ||
550 | out_hwmon_device_register: | 523 | return 0; |
551 | ltc4245_sysfs_remove_groups(client); | ||
552 | return ret; | ||
553 | } | 524 | } |
554 | 525 | ||
555 | static int ltc4245_remove(struct i2c_client *client) | 526 | static 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 | } |
diff --git a/drivers/hwmon/ltc4261.c b/drivers/hwmon/ltc4261.c index 487da58ec86c..0becd69842bb 100644 --- a/drivers/hwmon/ltc4261.c +++ b/drivers/hwmon/ltc4261.c | |||
@@ -55,7 +55,7 @@ | |||
55 | #define FAULT_OC (1<<2) | 55 | #define FAULT_OC (1<<2) |
56 | 56 | ||
57 | struct ltc4261_data { | 57 | struct ltc4261_data { |
58 | struct device *hwmon_dev; | 58 | struct i2c_client *client; |
59 | 59 | ||
60 | struct mutex update_lock; | 60 | struct mutex update_lock; |
61 | bool valid; | 61 | bool valid; |
@@ -67,8 +67,8 @@ struct ltc4261_data { | |||
67 | 67 | ||
68 | static struct ltc4261_data *ltc4261_update_device(struct device *dev) | 68 | static struct ltc4261_data *ltc4261_update_device(struct device *dev) |
69 | { | 69 | { |
70 | struct i2c_client *client = to_i2c_client(dev); | 70 | struct ltc4261_data *data = dev_get_drvdata(dev); |
71 | struct ltc4261_data *data = i2c_get_clientdata(client); | 71 | struct i2c_client *client = data->client; |
72 | struct ltc4261_data *ret = data; | 72 | struct ltc4261_data *ret = data; |
73 | 73 | ||
74 | mutex_lock(&data->update_lock); | 74 | mutex_lock(&data->update_lock); |
@@ -150,7 +150,6 @@ static ssize_t ltc4261_show_bool(struct device *dev, | |||
150 | struct device_attribute *da, char *buf) | 150 | struct device_attribute *da, char *buf) |
151 | { | 151 | { |
152 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | 152 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
153 | struct i2c_client *client = to_i2c_client(dev); | ||
154 | struct ltc4261_data *data = ltc4261_update_device(dev); | 153 | struct ltc4261_data *data = ltc4261_update_device(dev); |
155 | u8 fault; | 154 | u8 fault; |
156 | 155 | ||
@@ -159,7 +158,7 @@ static ssize_t ltc4261_show_bool(struct device *dev, | |||
159 | 158 | ||
160 | fault = data->regs[LTC4261_FAULT] & attr->index; | 159 | fault = data->regs[LTC4261_FAULT] & attr->index; |
161 | if (fault) /* Clear reported faults in chip register */ | 160 | if (fault) /* Clear reported faults in chip register */ |
162 | i2c_smbus_write_byte_data(client, LTC4261_FAULT, ~fault); | 161 | i2c_smbus_write_byte_data(data->client, LTC4261_FAULT, ~fault); |
163 | 162 | ||
164 | return snprintf(buf, PAGE_SIZE, "%d\n", fault ? 1 : 0); | 163 | return snprintf(buf, PAGE_SIZE, "%d\n", fault ? 1 : 0); |
165 | } | 164 | } |
@@ -197,7 +196,7 @@ static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, ltc4261_show_value, NULL, | |||
197 | static SENSOR_DEVICE_ATTR(curr1_max_alarm, S_IRUGO, ltc4261_show_bool, NULL, | 196 | static SENSOR_DEVICE_ATTR(curr1_max_alarm, S_IRUGO, ltc4261_show_bool, NULL, |
198 | FAULT_OC); | 197 | FAULT_OC); |
199 | 198 | ||
200 | static struct attribute *ltc4261_attributes[] = { | 199 | static struct attribute *ltc4261_attrs[] = { |
201 | &sensor_dev_attr_in1_input.dev_attr.attr, | 200 | &sensor_dev_attr_in1_input.dev_attr.attr, |
202 | &sensor_dev_attr_in1_min_alarm.dev_attr.attr, | 201 | &sensor_dev_attr_in1_min_alarm.dev_attr.attr, |
203 | &sensor_dev_attr_in1_max_alarm.dev_attr.attr, | 202 | &sensor_dev_attr_in1_max_alarm.dev_attr.attr, |
@@ -210,62 +209,38 @@ static struct attribute *ltc4261_attributes[] = { | |||
210 | 209 | ||
211 | NULL, | 210 | NULL, |
212 | }; | 211 | }; |
213 | 212 | ATTRIBUTE_GROUPS(ltc4261); | |
214 | static const struct attribute_group ltc4261_group = { | ||
215 | .attrs = ltc4261_attributes, | ||
216 | }; | ||
217 | 213 | ||
218 | static int ltc4261_probe(struct i2c_client *client, | 214 | static int ltc4261_probe(struct i2c_client *client, |
219 | const struct i2c_device_id *id) | 215 | const struct i2c_device_id *id) |
220 | { | 216 | { |
221 | struct i2c_adapter *adapter = client->adapter; | 217 | struct i2c_adapter *adapter = client->adapter; |
218 | struct device *dev = &client->dev; | ||
222 | struct ltc4261_data *data; | 219 | struct ltc4261_data *data; |
223 | int ret; | 220 | struct device *hwmon_dev; |
224 | 221 | ||
225 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 222 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
226 | return -ENODEV; | 223 | return -ENODEV; |
227 | 224 | ||
228 | if (i2c_smbus_read_byte_data(client, LTC4261_STATUS) < 0) { | 225 | if (i2c_smbus_read_byte_data(client, LTC4261_STATUS) < 0) { |
229 | dev_err(&client->dev, "Failed to read status register\n"); | 226 | dev_err(dev, "Failed to read status register\n"); |
230 | return -ENODEV; | 227 | return -ENODEV; |
231 | } | 228 | } |
232 | 229 | ||
233 | data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); | 230 | data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); |
234 | if (!data) | 231 | if (!data) |
235 | return -ENOMEM; | 232 | return -ENOMEM; |
236 | 233 | ||
237 | i2c_set_clientdata(client, data); | 234 | data->client = client; |
238 | mutex_init(&data->update_lock); | 235 | mutex_init(&data->update_lock); |
239 | 236 | ||
240 | /* Clear faults */ | 237 | /* Clear faults */ |
241 | i2c_smbus_write_byte_data(client, LTC4261_FAULT, 0x00); | 238 | i2c_smbus_write_byte_data(client, LTC4261_FAULT, 0x00); |
242 | 239 | ||
243 | /* Register sysfs hooks */ | 240 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
244 | ret = sysfs_create_group(&client->dev.kobj, <c4261_group); | 241 | data, |
245 | if (ret) | 242 | ltc4261_groups); |
246 | return ret; | 243 | return PTR_ERR_OR_ZERO(hwmon_dev); |
247 | |||
248 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
249 | if (IS_ERR(data->hwmon_dev)) { | ||
250 | ret = PTR_ERR(data->hwmon_dev); | ||
251 | goto out_hwmon_device_register; | ||
252 | } | ||
253 | |||
254 | return 0; | ||
255 | |||
256 | out_hwmon_device_register: | ||
257 | sysfs_remove_group(&client->dev.kobj, <c4261_group); | ||
258 | return ret; | ||
259 | } | ||
260 | |||
261 | static int ltc4261_remove(struct i2c_client *client) | ||
262 | { | ||
263 | struct ltc4261_data *data = i2c_get_clientdata(client); | ||
264 | |||
265 | hwmon_device_unregister(data->hwmon_dev); | ||
266 | sysfs_remove_group(&client->dev.kobj, <c4261_group); | ||
267 | |||
268 | return 0; | ||
269 | } | 244 | } |
270 | 245 | ||
271 | static const struct i2c_device_id ltc4261_id[] = { | 246 | static const struct i2c_device_id ltc4261_id[] = { |
@@ -281,7 +256,6 @@ static struct i2c_driver ltc4261_driver = { | |||
281 | .name = "ltc4261", | 256 | .name = "ltc4261", |
282 | }, | 257 | }, |
283 | .probe = ltc4261_probe, | 258 | .probe = ltc4261_probe, |
284 | .remove = ltc4261_remove, | ||
285 | .id_table = ltc4261_id, | 259 | .id_table = ltc4261_id, |
286 | }; | 260 | }; |
287 | 261 | ||
diff --git a/drivers/hwmon/max16065.c b/drivers/hwmon/max16065.c index 2fa2c02f5569..d4efc79d7b93 100644 --- a/drivers/hwmon/max16065.c +++ b/drivers/hwmon/max16065.c | |||
@@ -83,7 +83,8 @@ static const bool max16065_have_current[] = { | |||
83 | 83 | ||
84 | struct max16065_data { | 84 | struct max16065_data { |
85 | enum chips type; | 85 | enum chips type; |
86 | struct device *hwmon_dev; | 86 | struct i2c_client *client; |
87 | const struct attribute_group *groups[4]; | ||
87 | struct mutex update_lock; | 88 | struct mutex update_lock; |
88 | bool valid; | 89 | bool valid; |
89 | unsigned long last_updated; /* in jiffies */ | 90 | unsigned long last_updated; /* in jiffies */ |
@@ -144,8 +145,8 @@ static int max16065_read_adc(struct i2c_client *client, int reg) | |||
144 | 145 | ||
145 | static struct max16065_data *max16065_update_device(struct device *dev) | 146 | static struct max16065_data *max16065_update_device(struct device *dev) |
146 | { | 147 | { |
147 | struct i2c_client *client = to_i2c_client(dev); | 148 | struct max16065_data *data = dev_get_drvdata(dev); |
148 | struct max16065_data *data = i2c_get_clientdata(client); | 149 | struct i2c_client *client = data->client; |
149 | 150 | ||
150 | mutex_lock(&data->update_lock); | 151 | mutex_lock(&data->update_lock); |
151 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { | 152 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { |
@@ -186,7 +187,7 @@ static ssize_t max16065_show_alarm(struct device *dev, | |||
186 | 187 | ||
187 | val &= (1 << attr2->index); | 188 | val &= (1 << attr2->index); |
188 | if (val) | 189 | if (val) |
189 | i2c_smbus_write_byte_data(to_i2c_client(dev), | 190 | i2c_smbus_write_byte_data(data->client, |
190 | MAX16065_FAULT(attr2->nr), val); | 191 | MAX16065_FAULT(attr2->nr), val); |
191 | 192 | ||
192 | return snprintf(buf, PAGE_SIZE, "%d\n", !!val); | 193 | return snprintf(buf, PAGE_SIZE, "%d\n", !!val); |
@@ -223,8 +224,7 @@ static ssize_t max16065_set_limit(struct device *dev, | |||
223 | const char *buf, size_t count) | 224 | const char *buf, size_t count) |
224 | { | 225 | { |
225 | struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(da); | 226 | struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(da); |
226 | struct i2c_client *client = to_i2c_client(dev); | 227 | struct max16065_data *data = dev_get_drvdata(dev); |
227 | struct max16065_data *data = i2c_get_clientdata(client); | ||
228 | unsigned long val; | 228 | unsigned long val; |
229 | int err; | 229 | int err; |
230 | int limit; | 230 | int limit; |
@@ -238,7 +238,7 @@ static ssize_t max16065_set_limit(struct device *dev, | |||
238 | mutex_lock(&data->update_lock); | 238 | mutex_lock(&data->update_lock); |
239 | data->limit[attr2->nr][attr2->index] | 239 | data->limit[attr2->nr][attr2->index] |
240 | = LIMIT_TO_MV(limit, data->range[attr2->index]); | 240 | = LIMIT_TO_MV(limit, data->range[attr2->index]); |
241 | i2c_smbus_write_byte_data(client, | 241 | i2c_smbus_write_byte_data(data->client, |
242 | MAX16065_LIMIT(attr2->nr, attr2->index), | 242 | MAX16065_LIMIT(attr2->nr, attr2->index), |
243 | limit); | 243 | limit); |
244 | mutex_unlock(&data->update_lock); | 244 | mutex_unlock(&data->update_lock); |
@@ -250,8 +250,7 @@ static ssize_t max16065_show_limit(struct device *dev, | |||
250 | struct device_attribute *da, char *buf) | 250 | struct device_attribute *da, char *buf) |
251 | { | 251 | { |
252 | struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(da); | 252 | struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(da); |
253 | struct i2c_client *client = to_i2c_client(dev); | 253 | struct max16065_data *data = dev_get_drvdata(dev); |
254 | struct max16065_data *data = i2c_get_clientdata(client); | ||
255 | 254 | ||
256 | return snprintf(buf, PAGE_SIZE, "%d\n", | 255 | return snprintf(buf, PAGE_SIZE, "%d\n", |
257 | data->limit[attr2->nr][attr2->index]); | 256 | data->limit[attr2->nr][attr2->index]); |
@@ -516,8 +515,32 @@ static struct attribute *max16065_max_attributes[] = { | |||
516 | NULL | 515 | NULL |
517 | }; | 516 | }; |
518 | 517 | ||
518 | static umode_t max16065_basic_is_visible(struct kobject *kobj, | ||
519 | struct attribute *a, int n) | ||
520 | { | ||
521 | struct device *dev = container_of(kobj, struct device, kobj); | ||
522 | struct max16065_data *data = dev_get_drvdata(dev); | ||
523 | int index = n / 4; | ||
524 | |||
525 | if (index >= data->num_adc || !data->range[index]) | ||
526 | return 0; | ||
527 | return a->mode; | ||
528 | } | ||
529 | |||
530 | static umode_t max16065_secondary_is_visible(struct kobject *kobj, | ||
531 | struct attribute *a, int index) | ||
532 | { | ||
533 | struct device *dev = container_of(kobj, struct device, kobj); | ||
534 | struct max16065_data *data = dev_get_drvdata(dev); | ||
535 | |||
536 | if (index >= data->num_adc) | ||
537 | return 0; | ||
538 | return a->mode; | ||
539 | } | ||
540 | |||
519 | static const struct attribute_group max16065_basic_group = { | 541 | static const struct attribute_group max16065_basic_group = { |
520 | .attrs = max16065_basic_attributes, | 542 | .attrs = max16065_basic_attributes, |
543 | .is_visible = max16065_basic_is_visible, | ||
521 | }; | 544 | }; |
522 | 545 | ||
523 | static const struct attribute_group max16065_current_group = { | 546 | static const struct attribute_group max16065_current_group = { |
@@ -526,38 +549,35 @@ static const struct attribute_group max16065_current_group = { | |||
526 | 549 | ||
527 | static const struct attribute_group max16065_min_group = { | 550 | static const struct attribute_group max16065_min_group = { |
528 | .attrs = max16065_min_attributes, | 551 | .attrs = max16065_min_attributes, |
552 | .is_visible = max16065_secondary_is_visible, | ||
529 | }; | 553 | }; |
530 | 554 | ||
531 | static const struct attribute_group max16065_max_group = { | 555 | static const struct attribute_group max16065_max_group = { |
532 | .attrs = max16065_max_attributes, | 556 | .attrs = max16065_max_attributes, |
557 | .is_visible = max16065_secondary_is_visible, | ||
533 | }; | 558 | }; |
534 | 559 | ||
535 | static void max16065_cleanup(struct i2c_client *client) | ||
536 | { | ||
537 | sysfs_remove_group(&client->dev.kobj, &max16065_max_group); | ||
538 | sysfs_remove_group(&client->dev.kobj, &max16065_min_group); | ||
539 | sysfs_remove_group(&client->dev.kobj, &max16065_current_group); | ||
540 | sysfs_remove_group(&client->dev.kobj, &max16065_basic_group); | ||
541 | } | ||
542 | |||
543 | static int max16065_probe(struct i2c_client *client, | 560 | static int max16065_probe(struct i2c_client *client, |
544 | const struct i2c_device_id *id) | 561 | const struct i2c_device_id *id) |
545 | { | 562 | { |
546 | struct i2c_adapter *adapter = client->adapter; | 563 | struct i2c_adapter *adapter = client->adapter; |
547 | struct max16065_data *data; | 564 | struct max16065_data *data; |
548 | int i, j, val, ret; | 565 | struct device *dev = &client->dev; |
566 | struct device *hwmon_dev; | ||
567 | int i, j, val; | ||
549 | bool have_secondary; /* true if chip has secondary limits */ | 568 | bool have_secondary; /* true if chip has secondary limits */ |
550 | bool secondary_is_max = false; /* secondary limits reflect max */ | 569 | bool secondary_is_max = false; /* secondary limits reflect max */ |
570 | int groups = 0; | ||
551 | 571 | ||
552 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | 572 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
553 | | I2C_FUNC_SMBUS_READ_WORD_DATA)) | 573 | | I2C_FUNC_SMBUS_READ_WORD_DATA)) |
554 | return -ENODEV; | 574 | return -ENODEV; |
555 | 575 | ||
556 | data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); | 576 | data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); |
557 | if (unlikely(!data)) | 577 | if (unlikely(!data)) |
558 | return -ENOMEM; | 578 | return -ENOMEM; |
559 | 579 | ||
560 | i2c_set_clientdata(client, data); | 580 | data->client = client; |
561 | mutex_init(&data->update_lock); | 581 | mutex_init(&data->update_lock); |
562 | 582 | ||
563 | data->num_adc = max16065_num_adc[id->driver_data]; | 583 | data->num_adc = max16065_num_adc[id->driver_data]; |
@@ -596,38 +616,16 @@ static int max16065_probe(struct i2c_client *client, | |||
596 | } | 616 | } |
597 | } | 617 | } |
598 | 618 | ||
599 | /* Register sysfs hooks */ | 619 | /* sysfs hooks */ |
600 | for (i = 0; i < data->num_adc * 4; i++) { | 620 | data->groups[groups++] = &max16065_basic_group; |
601 | /* Do not create sysfs entry if channel is disabled */ | 621 | if (have_secondary) |
602 | if (!data->range[i / 4]) | 622 | data->groups[groups++] = secondary_is_max ? |
603 | continue; | 623 | &max16065_max_group : &max16065_min_group; |
604 | |||
605 | ret = sysfs_create_file(&client->dev.kobj, | ||
606 | max16065_basic_attributes[i]); | ||
607 | if (unlikely(ret)) | ||
608 | goto out; | ||
609 | } | ||
610 | |||
611 | if (have_secondary) { | ||
612 | struct attribute **attr = secondary_is_max ? | ||
613 | max16065_max_attributes : max16065_min_attributes; | ||
614 | |||
615 | for (i = 0; i < data->num_adc; i++) { | ||
616 | if (!data->range[i]) | ||
617 | continue; | ||
618 | |||
619 | ret = sysfs_create_file(&client->dev.kobj, attr[i]); | ||
620 | if (unlikely(ret)) | ||
621 | goto out; | ||
622 | } | ||
623 | } | ||
624 | 624 | ||
625 | if (data->have_current) { | 625 | if (data->have_current) { |
626 | val = i2c_smbus_read_byte_data(client, MAX16065_CURR_CONTROL); | 626 | val = i2c_smbus_read_byte_data(client, MAX16065_CURR_CONTROL); |
627 | if (unlikely(val < 0)) { | 627 | if (unlikely(val < 0)) |
628 | ret = val; | 628 | return val; |
629 | goto out; | ||
630 | } | ||
631 | if (val & MAX16065_CURR_ENABLE) { | 629 | if (val & MAX16065_CURR_ENABLE) { |
632 | /* | 630 | /* |
633 | * Current gain is 6, 12, 24, 48 based on values in | 631 | * Current gain is 6, 12, 24, 48 based on values in |
@@ -636,33 +634,16 @@ static int max16065_probe(struct i2c_client *client, | |||
636 | data->curr_gain = 6 << ((val >> 2) & 0x03); | 634 | data->curr_gain = 6 << ((val >> 2) & 0x03); |
637 | data->range[MAX16065_NUM_ADC] | 635 | data->range[MAX16065_NUM_ADC] |
638 | = max16065_csp_adc_range[(val >> 1) & 0x01]; | 636 | = max16065_csp_adc_range[(val >> 1) & 0x01]; |
639 | ret = sysfs_create_group(&client->dev.kobj, | 637 | data->groups[groups++] = &max16065_current_group; |
640 | &max16065_current_group); | ||
641 | if (unlikely(ret)) | ||
642 | goto out; | ||
643 | } else { | 638 | } else { |
644 | data->have_current = false; | 639 | data->have_current = false; |
645 | } | 640 | } |
646 | } | 641 | } |
647 | 642 | ||
648 | data->hwmon_dev = hwmon_device_register(&client->dev); | 643 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
649 | if (unlikely(IS_ERR(data->hwmon_dev))) { | 644 | data, data->groups); |
650 | ret = PTR_ERR(data->hwmon_dev); | 645 | if (unlikely(IS_ERR(hwmon_dev))) |
651 | goto out; | 646 | return PTR_ERR(hwmon_dev); |
652 | } | ||
653 | return 0; | ||
654 | |||
655 | out: | ||
656 | max16065_cleanup(client); | ||
657 | return ret; | ||
658 | } | ||
659 | |||
660 | static int max16065_remove(struct i2c_client *client) | ||
661 | { | ||
662 | struct max16065_data *data = i2c_get_clientdata(client); | ||
663 | |||
664 | hwmon_device_unregister(data->hwmon_dev); | ||
665 | max16065_cleanup(client); | ||
666 | 647 | ||
667 | return 0; | 648 | return 0; |
668 | } | 649 | } |
@@ -685,7 +666,6 @@ static struct i2c_driver max16065_driver = { | |||
685 | .name = "max16065", | 666 | .name = "max16065", |
686 | }, | 667 | }, |
687 | .probe = max16065_probe, | 668 | .probe = max16065_probe, |
688 | .remove = max16065_remove, | ||
689 | .id_table = max16065_id, | 669 | .id_table = max16065_id, |
690 | }; | 670 | }; |
691 | 671 | ||
diff --git a/drivers/hwmon/max6642.c b/drivers/hwmon/max6642.c index 57d58cd32206..8326fbd60150 100644 --- a/drivers/hwmon/max6642.c +++ b/drivers/hwmon/max6642.c | |||
@@ -87,7 +87,7 @@ static int temp_to_reg(int val) | |||
87 | */ | 87 | */ |
88 | 88 | ||
89 | struct max6642_data { | 89 | struct max6642_data { |
90 | struct device *hwmon_dev; | 90 | struct i2c_client *client; |
91 | struct mutex update_lock; | 91 | struct mutex update_lock; |
92 | bool valid; /* zero until following fields are valid */ | 92 | bool valid; /* zero until following fields are valid */ |
93 | unsigned long last_updated; /* in jiffies */ | 93 | unsigned long last_updated; /* in jiffies */ |
@@ -102,10 +102,10 @@ struct max6642_data { | |||
102 | * Real code | 102 | * Real code |
103 | */ | 103 | */ |
104 | 104 | ||
105 | static void max6642_init_client(struct i2c_client *client) | 105 | static void max6642_init_client(struct max6642_data *data, |
106 | struct i2c_client *client) | ||
106 | { | 107 | { |
107 | u8 config; | 108 | u8 config; |
108 | struct max6642_data *data = i2c_get_clientdata(client); | ||
109 | 109 | ||
110 | /* | 110 | /* |
111 | * Start the conversions. | 111 | * Start the conversions. |
@@ -168,14 +168,14 @@ static int max6642_detect(struct i2c_client *client, | |||
168 | 168 | ||
169 | static struct max6642_data *max6642_update_device(struct device *dev) | 169 | static struct max6642_data *max6642_update_device(struct device *dev) |
170 | { | 170 | { |
171 | struct i2c_client *client = to_i2c_client(dev); | 171 | struct max6642_data *data = dev_get_drvdata(dev); |
172 | struct max6642_data *data = i2c_get_clientdata(client); | 172 | struct i2c_client *client = data->client; |
173 | u16 val, tmp; | 173 | u16 val, tmp; |
174 | 174 | ||
175 | mutex_lock(&data->update_lock); | 175 | mutex_lock(&data->update_lock); |
176 | 176 | ||
177 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { | 177 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { |
178 | dev_dbg(&client->dev, "Updating max6642 data.\n"); | 178 | dev_dbg(dev, "Updating max6642 data.\n"); |
179 | val = i2c_smbus_read_byte_data(client, | 179 | val = i2c_smbus_read_byte_data(client, |
180 | MAX6642_REG_R_LOCAL_TEMPL); | 180 | MAX6642_REG_R_LOCAL_TEMPL); |
181 | tmp = (val >> 6) & 3; | 181 | tmp = (val >> 6) & 3; |
@@ -209,8 +209,8 @@ static struct max6642_data *max6642_update_device(struct device *dev) | |||
209 | static ssize_t show_temp_max10(struct device *dev, | 209 | static ssize_t show_temp_max10(struct device *dev, |
210 | struct device_attribute *dev_attr, char *buf) | 210 | struct device_attribute *dev_attr, char *buf) |
211 | { | 211 | { |
212 | struct max6642_data *data = max6642_update_device(dev); | ||
213 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); | 212 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); |
213 | struct max6642_data *data = max6642_update_device(dev); | ||
214 | 214 | ||
215 | return sprintf(buf, "%d\n", | 215 | return sprintf(buf, "%d\n", |
216 | temp_from_reg10(data->temp_input[attr->index])); | 216 | temp_from_reg10(data->temp_input[attr->index])); |
@@ -219,8 +219,8 @@ static ssize_t show_temp_max10(struct device *dev, | |||
219 | static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, | 219 | static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, |
220 | char *buf) | 220 | char *buf) |
221 | { | 221 | { |
222 | struct max6642_data *data = max6642_update_device(dev); | ||
223 | struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); | 222 | struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); |
223 | struct max6642_data *data = max6642_update_device(dev); | ||
224 | 224 | ||
225 | return sprintf(buf, "%d\n", temp_from_reg(data->temp_high[attr2->nr])); | 225 | return sprintf(buf, "%d\n", temp_from_reg(data->temp_high[attr2->nr])); |
226 | } | 226 | } |
@@ -228,11 +228,10 @@ static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, | |||
228 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | 228 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, |
229 | const char *buf, size_t count) | 229 | const char *buf, size_t count) |
230 | { | 230 | { |
231 | struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); | ||
232 | struct max6642_data *data = dev_get_drvdata(dev); | ||
231 | unsigned long val; | 233 | unsigned long val; |
232 | int err; | 234 | int err; |
233 | struct i2c_client *client = to_i2c_client(dev); | ||
234 | struct max6642_data *data = i2c_get_clientdata(client); | ||
235 | struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); | ||
236 | 235 | ||
237 | err = kstrtoul(buf, 10, &val); | 236 | err = kstrtoul(buf, 10, &val); |
238 | if (err < 0) | 237 | if (err < 0) |
@@ -240,7 +239,7 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
240 | 239 | ||
241 | mutex_lock(&data->update_lock); | 240 | mutex_lock(&data->update_lock); |
242 | data->temp_high[attr2->nr] = clamp_val(temp_to_reg(val), 0, 255); | 241 | data->temp_high[attr2->nr] = clamp_val(temp_to_reg(val), 0, 255); |
243 | i2c_smbus_write_byte_data(client, attr2->index, | 242 | i2c_smbus_write_byte_data(data->client, attr2->index, |
244 | data->temp_high[attr2->nr]); | 243 | data->temp_high[attr2->nr]); |
245 | mutex_unlock(&data->update_lock); | 244 | mutex_unlock(&data->update_lock); |
246 | return count; | 245 | return count; |
@@ -264,7 +263,7 @@ static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2); | |||
264 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); | 263 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); |
265 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); | 264 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); |
266 | 265 | ||
267 | static struct attribute *max6642_attributes[] = { | 266 | static struct attribute *max6642_attrs[] = { |
268 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 267 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
269 | &sensor_dev_attr_temp2_input.dev_attr.attr, | 268 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
270 | &sensor_dev_attr_temp1_max.dev_attr.attr, | 269 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
@@ -275,54 +274,29 @@ static struct attribute *max6642_attributes[] = { | |||
275 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, | 274 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, |
276 | NULL | 275 | NULL |
277 | }; | 276 | }; |
277 | ATTRIBUTE_GROUPS(max6642); | ||
278 | 278 | ||
279 | static const struct attribute_group max6642_group = { | 279 | static int max6642_probe(struct i2c_client *client, |
280 | .attrs = max6642_attributes, | ||
281 | }; | ||
282 | |||
283 | static int max6642_probe(struct i2c_client *new_client, | ||
284 | const struct i2c_device_id *id) | 280 | const struct i2c_device_id *id) |
285 | { | 281 | { |
282 | struct device *dev = &client->dev; | ||
286 | struct max6642_data *data; | 283 | struct max6642_data *data; |
287 | int err; | 284 | struct device *hwmon_dev; |
288 | 285 | ||
289 | data = devm_kzalloc(&new_client->dev, sizeof(struct max6642_data), | 286 | data = devm_kzalloc(dev, sizeof(struct max6642_data), GFP_KERNEL); |
290 | GFP_KERNEL); | ||
291 | if (!data) | 287 | if (!data) |
292 | return -ENOMEM; | 288 | return -ENOMEM; |
293 | 289 | ||
294 | i2c_set_clientdata(new_client, data); | 290 | data->client = client; |
295 | mutex_init(&data->update_lock); | 291 | mutex_init(&data->update_lock); |
296 | 292 | ||
297 | /* Initialize the MAX6642 chip */ | 293 | /* Initialize the MAX6642 chip */ |
298 | max6642_init_client(new_client); | 294 | max6642_init_client(data, client); |
299 | 295 | ||
300 | /* Register sysfs hooks */ | 296 | hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev, |
301 | err = sysfs_create_group(&new_client->dev.kobj, &max6642_group); | 297 | client->name, data, |
302 | if (err) | 298 | max6642_groups); |
303 | return err; | 299 | return PTR_ERR_OR_ZERO(hwmon_dev); |
304 | |||
305 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | ||
306 | if (IS_ERR(data->hwmon_dev)) { | ||
307 | err = PTR_ERR(data->hwmon_dev); | ||
308 | goto exit_remove_files; | ||
309 | } | ||
310 | |||
311 | return 0; | ||
312 | |||
313 | exit_remove_files: | ||
314 | sysfs_remove_group(&new_client->dev.kobj, &max6642_group); | ||
315 | return err; | ||
316 | } | ||
317 | |||
318 | static int max6642_remove(struct i2c_client *client) | ||
319 | { | ||
320 | struct max6642_data *data = i2c_get_clientdata(client); | ||
321 | |||
322 | hwmon_device_unregister(data->hwmon_dev); | ||
323 | sysfs_remove_group(&client->dev.kobj, &max6642_group); | ||
324 | |||
325 | return 0; | ||
326 | } | 300 | } |
327 | 301 | ||
328 | /* | 302 | /* |
@@ -341,7 +315,6 @@ static struct i2c_driver max6642_driver = { | |||
341 | .name = "max6642", | 315 | .name = "max6642", |
342 | }, | 316 | }, |
343 | .probe = max6642_probe, | 317 | .probe = max6642_probe, |
344 | .remove = max6642_remove, | ||
345 | .id_table = max6642_id, | 318 | .id_table = max6642_id, |
346 | .detect = max6642_detect, | 319 | .detect = max6642_detect, |
347 | .address_list = normal_i2c, | 320 | .address_list = normal_i2c, |
diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c index 3c16cbd4c002..0cafc390db4d 100644 --- a/drivers/hwmon/max6650.c +++ b/drivers/hwmon/max6650.c | |||
@@ -660,7 +660,7 @@ static int max6650_init_client(struct i2c_client *client) | |||
660 | /* | 660 | /* |
661 | * If mode is set to "full off", we change it to "open loop" and | 661 | * If mode is set to "full off", we change it to "open loop" and |
662 | * set DAC to 255, which has the same effect. We do this because | 662 | * set DAC to 255, which has the same effect. We do this because |
663 | * there's no "full off" mode defined in hwmon specifcations. | 663 | * there's no "full off" mode defined in hwmon specifications. |
664 | */ | 664 | */ |
665 | 665 | ||
666 | if ((config & MAX6650_CFG_MODE_MASK) == MAX6650_CFG_MODE_OFF) { | 666 | if ((config & MAX6650_CFG_MODE_MASK) == MAX6650_CFG_MODE_OFF) { |
diff --git a/drivers/hwmon/max6697.c b/drivers/hwmon/max6697.c index a41b5f3fc506..7fd3eaf817f4 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,39 +636,17 @@ 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) | ||
645 | return err; | ||
646 | |||
647 | err = sysfs_create_group(&client->dev.kobj, &max6697_group); | ||
648 | if (err) | 643 | if (err) |
649 | return err; | 644 | return err; |
650 | 645 | ||
651 | data->hwmon_dev = hwmon_device_register(dev); | 646 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
652 | if (IS_ERR(data->hwmon_dev)) { | 647 | data, |
653 | err = PTR_ERR(data->hwmon_dev); | 648 | max6697_groups); |
654 | goto error; | 649 | return PTR_ERR_OR_ZERO(hwmon_dev); |
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 | |||
671 | return 0; | ||
672 | } | 650 | } |
673 | 651 | ||
674 | static const struct i2c_device_id max6697_id[] = { | 652 | static const struct i2c_device_id max6697_id[] = { |
@@ -692,7 +670,6 @@ static struct i2c_driver max6697_driver = { | |||
692 | .name = "max6697", | 670 | .name = "max6697", |
693 | }, | 671 | }, |
694 | .probe = max6697_probe, | 672 | .probe = max6697_probe, |
695 | .remove = max6697_remove, | ||
696 | .id_table = max6697_id, | 673 | .id_table = max6697_id, |
697 | }; | 674 | }; |
698 | 675 | ||
diff --git a/drivers/hwmon/mc13783-adc.c b/drivers/hwmon/mc13783-adc.c index 982d8622c09b..ae00e60d856c 100644 --- a/drivers/hwmon/mc13783-adc.c +++ b/drivers/hwmon/mc13783-adc.c | |||
@@ -37,7 +37,7 @@ | |||
37 | struct mc13783_adc_priv { | 37 | struct mc13783_adc_priv { |
38 | struct mc13xxx *mc13xxx; | 38 | struct mc13xxx *mc13xxx; |
39 | struct device *hwmon_dev; | 39 | struct device *hwmon_dev; |
40 | char name[10]; | 40 | char name[PLATFORM_NAME_SIZE]; |
41 | }; | 41 | }; |
42 | 42 | ||
43 | static ssize_t mc13783_adc_show_name(struct device *dev, struct device_attribute | 43 | static ssize_t mc13783_adc_show_name(struct device *dev, struct device_attribute |
diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c index 6eb03ce2cff4..d17325db0ea3 100644 --- a/drivers/hwmon/nct6775.c +++ b/drivers/hwmon/nct6775.c | |||
@@ -724,11 +724,8 @@ struct nct6775_data { | |||
724 | enum kinds kind; | 724 | enum kinds kind; |
725 | const char *name; | 725 | const char *name; |
726 | 726 | ||
727 | struct device *hwmon_dev; | 727 | int num_attr_groups; |
728 | struct attribute_group *group_in; | 728 | const struct attribute_group *groups[6]; |
729 | struct attribute_group *group_fan; | ||
730 | struct attribute_group *group_temp; | ||
731 | struct attribute_group *group_pwm; | ||
732 | 729 | ||
733 | u16 reg_temp[5][NUM_TEMP]; /* 0=temp, 1=temp_over, 2=temp_hyst, | 730 | u16 reg_temp[5][NUM_TEMP]; /* 0=temp, 1=temp_over, 2=temp_hyst, |
734 | * 3=temp_crit, 4=temp_lcrit | 731 | * 3=temp_crit, 4=temp_lcrit |
@@ -942,7 +939,7 @@ nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg, | |||
942 | struct sensor_device_attribute_2 *a2; | 939 | struct sensor_device_attribute_2 *a2; |
943 | struct attribute **attrs; | 940 | struct attribute **attrs; |
944 | struct sensor_device_template **t; | 941 | struct sensor_device_template **t; |
945 | int err, i, j, count; | 942 | int i, count; |
946 | 943 | ||
947 | if (repeat <= 0) | 944 | if (repeat <= 0) |
948 | return ERR_PTR(-EINVAL); | 945 | return ERR_PTR(-EINVAL); |
@@ -973,7 +970,7 @@ nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg, | |||
973 | 970 | ||
974 | for (i = 0; i < repeat; i++) { | 971 | for (i = 0; i < repeat; i++) { |
975 | t = tg->templates; | 972 | t = tg->templates; |
976 | for (j = 0; *t != NULL; j++) { | 973 | while (*t != NULL) { |
977 | snprintf(su->name, sizeof(su->name), | 974 | snprintf(su->name, sizeof(su->name), |
978 | (*t)->dev_attr.attr.name, tg->base + i); | 975 | (*t)->dev_attr.attr.name, tg->base + i); |
979 | if ((*t)->s2) { | 976 | if ((*t)->s2) { |
@@ -1002,10 +999,6 @@ nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg, | |||
1002 | } | 999 | } |
1003 | } | 1000 | } |
1004 | 1001 | ||
1005 | err = sysfs_create_group(&dev->kobj, group); | ||
1006 | if (err) | ||
1007 | return ERR_PTR(-ENOMEM); | ||
1008 | |||
1009 | return group; | 1002 | return group; |
1010 | } | 1003 | } |
1011 | 1004 | ||
@@ -1457,7 +1450,8 @@ static struct nct6775_data *nct6775_update_device(struct device *dev) | |||
1457 | = nct6775_read_temp(data, | 1450 | = nct6775_read_temp(data, |
1458 | data->reg_temp[j][i]); | 1451 | data->reg_temp[j][i]); |
1459 | } | 1452 | } |
1460 | if (!(data->have_temp_fixed & (1 << i))) | 1453 | if (i >= NUM_TEMP_FIXED || |
1454 | !(data->have_temp_fixed & (1 << i))) | ||
1461 | continue; | 1455 | continue; |
1462 | data->temp_offset[i] | 1456 | data->temp_offset[i] |
1463 | = nct6775_read_value(data, data->REG_TEMP_OFFSET[i]); | 1457 | = nct6775_read_value(data, data->REG_TEMP_OFFSET[i]); |
@@ -1545,7 +1539,7 @@ static int find_temp_source(struct nct6775_data *data, int index, int count) | |||
1545 | if (src == source) | 1539 | if (src == source) |
1546 | return nr; | 1540 | return nr; |
1547 | } | 1541 | } |
1548 | return -1; | 1542 | return -ENODEV; |
1549 | } | 1543 | } |
1550 | 1544 | ||
1551 | static ssize_t | 1545 | static ssize_t |
@@ -1644,7 +1638,7 @@ store_temp_beep(struct device *dev, struct device_attribute *attr, | |||
1644 | 1638 | ||
1645 | nr = find_temp_source(data, sattr->index, data->num_temp_beeps); | 1639 | nr = find_temp_source(data, sattr->index, data->num_temp_beeps); |
1646 | if (nr < 0) | 1640 | if (nr < 0) |
1647 | return -ENODEV; | 1641 | return nr; |
1648 | 1642 | ||
1649 | bit = data->BEEP_BITS[nr + TEMP_ALARM_BASE]; | 1643 | bit = data->BEEP_BITS[nr + TEMP_ALARM_BASE]; |
1650 | regindex = bit >> 3; | 1644 | regindex = bit >> 3; |
@@ -2726,16 +2720,6 @@ store_fan_time(struct device *dev, struct device_attribute *attr, | |||
2726 | } | 2720 | } |
2727 | 2721 | ||
2728 | static ssize_t | 2722 | static ssize_t |
2729 | show_name(struct device *dev, struct device_attribute *attr, char *buf) | ||
2730 | { | ||
2731 | struct nct6775_data *data = dev_get_drvdata(dev); | ||
2732 | |||
2733 | return sprintf(buf, "%s\n", data->name); | ||
2734 | } | ||
2735 | |||
2736 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | ||
2737 | |||
2738 | static ssize_t | ||
2739 | show_auto_pwm(struct device *dev, struct device_attribute *attr, char *buf) | 2723 | show_auto_pwm(struct device *dev, struct device_attribute *attr, char *buf) |
2740 | { | 2724 | { |
2741 | struct nct6775_data *data = nct6775_update_device(dev); | 2725 | struct nct6775_data *data = nct6775_update_device(dev); |
@@ -3061,16 +3045,16 @@ static umode_t nct6775_other_is_visible(struct kobject *kobj, | |||
3061 | struct device *dev = container_of(kobj, struct device, kobj); | 3045 | struct device *dev = container_of(kobj, struct device, kobj); |
3062 | struct nct6775_data *data = dev_get_drvdata(dev); | 3046 | struct nct6775_data *data = dev_get_drvdata(dev); |
3063 | 3047 | ||
3064 | if (index == 1 && !data->have_vid) | 3048 | if (index == 0 && !data->have_vid) |
3065 | return 0; | 3049 | return 0; |
3066 | 3050 | ||
3067 | if (index == 2 || index == 3) { | 3051 | if (index == 1 || index == 2) { |
3068 | if (data->ALARM_BITS[INTRUSION_ALARM_BASE + index - 2] < 0) | 3052 | if (data->ALARM_BITS[INTRUSION_ALARM_BASE + index - 1] < 0) |
3069 | return 0; | 3053 | return 0; |
3070 | } | 3054 | } |
3071 | 3055 | ||
3072 | if (index == 4 || index == 5) { | 3056 | if (index == 3 || index == 4) { |
3073 | if (data->BEEP_BITS[INTRUSION_ALARM_BASE + index - 4] < 0) | 3057 | if (data->BEEP_BITS[INTRUSION_ALARM_BASE + index - 3] < 0) |
3074 | return 0; | 3058 | return 0; |
3075 | } | 3059 | } |
3076 | 3060 | ||
@@ -3083,13 +3067,12 @@ static umode_t nct6775_other_is_visible(struct kobject *kobj, | |||
3083 | * Any change in order or content must be matched. | 3067 | * Any change in order or content must be matched. |
3084 | */ | 3068 | */ |
3085 | static struct attribute *nct6775_attributes_other[] = { | 3069 | static struct attribute *nct6775_attributes_other[] = { |
3086 | &dev_attr_name.attr, | 3070 | &dev_attr_cpu0_vid.attr, /* 0 */ |
3087 | &dev_attr_cpu0_vid.attr, /* 1 */ | 3071 | &sensor_dev_attr_intrusion0_alarm.dev_attr.attr, /* 1 */ |
3088 | &sensor_dev_attr_intrusion0_alarm.dev_attr.attr, /* 2 */ | 3072 | &sensor_dev_attr_intrusion1_alarm.dev_attr.attr, /* 2 */ |
3089 | &sensor_dev_attr_intrusion1_alarm.dev_attr.attr, /* 3 */ | 3073 | &sensor_dev_attr_intrusion0_beep.dev_attr.attr, /* 3 */ |
3090 | &sensor_dev_attr_intrusion0_beep.dev_attr.attr, /* 4 */ | 3074 | &sensor_dev_attr_intrusion1_beep.dev_attr.attr, /* 4 */ |
3091 | &sensor_dev_attr_intrusion1_beep.dev_attr.attr, /* 5 */ | 3075 | &sensor_dev_attr_beep_enable.dev_attr.attr, /* 5 */ |
3092 | &sensor_dev_attr_beep_enable.dev_attr.attr, /* 6 */ | ||
3093 | 3076 | ||
3094 | NULL | 3077 | NULL |
3095 | }; | 3078 | }; |
@@ -3099,27 +3082,6 @@ static const struct attribute_group nct6775_group_other = { | |||
3099 | .is_visible = nct6775_other_is_visible, | 3082 | .is_visible = nct6775_other_is_visible, |
3100 | }; | 3083 | }; |
3101 | 3084 | ||
3102 | /* | ||
3103 | * Driver and device management | ||
3104 | */ | ||
3105 | |||
3106 | static void nct6775_device_remove_files(struct device *dev) | ||
3107 | { | ||
3108 | struct nct6775_data *data = dev_get_drvdata(dev); | ||
3109 | |||
3110 | if (data->group_pwm) | ||
3111 | sysfs_remove_group(&dev->kobj, data->group_pwm); | ||
3112 | if (data->group_in) | ||
3113 | sysfs_remove_group(&dev->kobj, data->group_in); | ||
3114 | if (data->group_fan) | ||
3115 | sysfs_remove_group(&dev->kobj, data->group_fan); | ||
3116 | if (data->group_temp) | ||
3117 | sysfs_remove_group(&dev->kobj, data->group_temp); | ||
3118 | |||
3119 | sysfs_remove_group(&dev->kobj, &nct6775_group_other); | ||
3120 | } | ||
3121 | |||
3122 | /* Get the monitoring functions started */ | ||
3123 | static inline void nct6775_init_device(struct nct6775_data *data) | 3085 | static inline void nct6775_init_device(struct nct6775_data *data) |
3124 | { | 3086 | { |
3125 | int i; | 3087 | int i; |
@@ -3296,6 +3258,7 @@ static int nct6775_probe(struct platform_device *pdev) | |||
3296 | int num_reg_temp; | 3258 | int num_reg_temp; |
3297 | u8 cr2a; | 3259 | u8 cr2a; |
3298 | struct attribute_group *group; | 3260 | struct attribute_group *group; |
3261 | struct device *hwmon_dev; | ||
3299 | 3262 | ||
3300 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | 3263 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
3301 | if (!devm_request_region(&pdev->dev, res->start, IOREGION_LENGTH, | 3264 | if (!devm_request_region(&pdev->dev, res->start, IOREGION_LENGTH, |
@@ -3870,61 +3833,36 @@ static int nct6775_probe(struct platform_device *pdev) | |||
3870 | /* Register sysfs hooks */ | 3833 | /* Register sysfs hooks */ |
3871 | group = nct6775_create_attr_group(dev, &nct6775_pwm_template_group, | 3834 | group = nct6775_create_attr_group(dev, &nct6775_pwm_template_group, |
3872 | data->pwm_num); | 3835 | data->pwm_num); |
3873 | if (IS_ERR(group)) { | 3836 | if (IS_ERR(group)) |
3874 | err = PTR_ERR(group); | 3837 | return PTR_ERR(group); |
3875 | goto exit_remove; | 3838 | |
3876 | } | 3839 | data->groups[data->num_attr_groups++] = group; |
3877 | data->group_pwm = group; | ||
3878 | 3840 | ||
3879 | group = nct6775_create_attr_group(dev, &nct6775_in_template_group, | 3841 | group = nct6775_create_attr_group(dev, &nct6775_in_template_group, |
3880 | fls(data->have_in)); | 3842 | fls(data->have_in)); |
3881 | if (IS_ERR(group)) { | 3843 | if (IS_ERR(group)) |
3882 | err = PTR_ERR(group); | 3844 | return PTR_ERR(group); |
3883 | goto exit_remove; | 3845 | |
3884 | } | 3846 | data->groups[data->num_attr_groups++] = group; |
3885 | data->group_in = group; | ||
3886 | 3847 | ||
3887 | group = nct6775_create_attr_group(dev, &nct6775_fan_template_group, | 3848 | group = nct6775_create_attr_group(dev, &nct6775_fan_template_group, |
3888 | fls(data->has_fan)); | 3849 | fls(data->has_fan)); |
3889 | if (IS_ERR(group)) { | 3850 | if (IS_ERR(group)) |
3890 | err = PTR_ERR(group); | 3851 | return PTR_ERR(group); |
3891 | goto exit_remove; | 3852 | |
3892 | } | 3853 | data->groups[data->num_attr_groups++] = group; |
3893 | data->group_fan = group; | ||
3894 | 3854 | ||
3895 | group = nct6775_create_attr_group(dev, &nct6775_temp_template_group, | 3855 | group = nct6775_create_attr_group(dev, &nct6775_temp_template_group, |
3896 | fls(data->have_temp)); | 3856 | fls(data->have_temp)); |
3897 | if (IS_ERR(group)) { | 3857 | if (IS_ERR(group)) |
3898 | err = PTR_ERR(group); | 3858 | return PTR_ERR(group); |
3899 | goto exit_remove; | ||
3900 | } | ||
3901 | data->group_temp = group; | ||
3902 | |||
3903 | err = sysfs_create_group(&dev->kobj, &nct6775_group_other); | ||
3904 | if (err) | ||
3905 | goto exit_remove; | ||
3906 | 3859 | ||
3907 | data->hwmon_dev = hwmon_device_register(dev); | 3860 | data->groups[data->num_attr_groups++] = group; |
3908 | if (IS_ERR(data->hwmon_dev)) { | 3861 | data->groups[data->num_attr_groups++] = &nct6775_group_other; |
3909 | err = PTR_ERR(data->hwmon_dev); | ||
3910 | goto exit_remove; | ||
3911 | } | ||
3912 | |||
3913 | return 0; | ||
3914 | |||
3915 | exit_remove: | ||
3916 | nct6775_device_remove_files(dev); | ||
3917 | return err; | ||
3918 | } | ||
3919 | |||
3920 | static int nct6775_remove(struct platform_device *pdev) | ||
3921 | { | ||
3922 | struct nct6775_data *data = platform_get_drvdata(pdev); | ||
3923 | 3862 | ||
3924 | hwmon_device_unregister(data->hwmon_dev); | 3863 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, data->name, |
3925 | nct6775_device_remove_files(&pdev->dev); | 3864 | data, data->groups); |
3926 | 3865 | return PTR_ERR_OR_ZERO(hwmon_dev); | |
3927 | return 0; | ||
3928 | } | 3866 | } |
3929 | 3867 | ||
3930 | #ifdef CONFIG_PM | 3868 | #ifdef CONFIG_PM |
@@ -4013,7 +3951,6 @@ static struct platform_driver nct6775_driver = { | |||
4013 | .pm = NCT6775_DEV_PM_OPS, | 3951 | .pm = NCT6775_DEV_PM_OPS, |
4014 | }, | 3952 | }, |
4015 | .probe = nct6775_probe, | 3953 | .probe = nct6775_probe, |
4016 | .remove = nct6775_remove, | ||
4017 | }; | 3954 | }; |
4018 | 3955 | ||
4019 | static const char * const nct6775_sio_names[] __initconst = { | 3956 | static const char * const nct6775_sio_names[] __initconst = { |
@@ -4101,7 +4038,7 @@ static int __init nct6775_find(int sioaddr, struct nct6775_sio_data *sio_data) | |||
4101 | /* | 4038 | /* |
4102 | * when Super-I/O functions move to a separate file, the Super-I/O | 4039 | * when Super-I/O functions move to a separate file, the Super-I/O |
4103 | * bus will manage the lifetime of the device and this module will only keep | 4040 | * bus will manage the lifetime of the device and this module will only keep |
4104 | * track of the nct6775 driver. But since we platform_device_alloc(), we | 4041 | * track of the nct6775 driver. But since we use platform_device_alloc(), we |
4105 | * must keep track of the device | 4042 | * must keep track of the device |
4106 | */ | 4043 | */ |
4107 | static struct platform_device *pdev[2]; | 4044 | static struct platform_device *pdev[2]; |
diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c index 6a9d6edaacb3..a26b1d1d9514 100644 --- a/drivers/hwmon/pmbus/lm25066.c +++ b/drivers/hwmon/pmbus/lm25066.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Hardware monitoring driver for LM25056 / LM25066 / LM5064 / LM5066 | 2 | * Hardware monitoring driver for LM25056 / LM25063 / LM25066 / LM5064 / LM5066 |
3 | * | 3 | * |
4 | * Copyright (c) 2011 Ericsson AB. | 4 | * Copyright (c) 2011 Ericsson AB. |
5 | * Copyright (c) 2013 Guenter Roeck | 5 | * Copyright (c) 2013 Guenter Roeck |
@@ -27,7 +27,7 @@ | |||
27 | #include <linux/i2c.h> | 27 | #include <linux/i2c.h> |
28 | #include "pmbus.h" | 28 | #include "pmbus.h" |
29 | 29 | ||
30 | enum chips { lm25056, lm25066, lm5064, lm5066 }; | 30 | enum chips { lm25056, lm25063, lm25066, lm5064, lm5066 }; |
31 | 31 | ||
32 | #define LM25066_READ_VAUX 0xd0 | 32 | #define LM25066_READ_VAUX 0xd0 |
33 | #define LM25066_MFR_READ_IIN 0xd1 | 33 | #define LM25066_MFR_READ_IIN 0xd1 |
@@ -52,6 +52,11 @@ enum chips { lm25056, lm25066, lm5064, lm5066 }; | |||
52 | #define LM25056_MFR_STS_VAUX_OV_WARN (1 << 1) | 52 | #define LM25056_MFR_STS_VAUX_OV_WARN (1 << 1) |
53 | #define LM25056_MFR_STS_VAUX_UV_WARN (1 << 0) | 53 | #define LM25056_MFR_STS_VAUX_UV_WARN (1 << 0) |
54 | 54 | ||
55 | /* LM25063 only */ | ||
56 | |||
57 | #define LM25063_READ_VOUT_MAX 0xe5 | ||
58 | #define LM25063_READ_VOUT_MIN 0xe6 | ||
59 | |||
55 | struct __coeff { | 60 | struct __coeff { |
56 | short m, b, R; | 61 | short m, b, R; |
57 | }; | 62 | }; |
@@ -59,7 +64,7 @@ struct __coeff { | |||
59 | #define PSC_CURRENT_IN_L (PSC_NUM_CLASSES) | 64 | #define PSC_CURRENT_IN_L (PSC_NUM_CLASSES) |
60 | #define PSC_POWER_L (PSC_NUM_CLASSES + 1) | 65 | #define PSC_POWER_L (PSC_NUM_CLASSES + 1) |
61 | 66 | ||
62 | static struct __coeff lm25066_coeff[4][PSC_NUM_CLASSES + 2] = { | 67 | static struct __coeff lm25066_coeff[5][PSC_NUM_CLASSES + 2] = { |
63 | [lm25056] = { | 68 | [lm25056] = { |
64 | [PSC_VOLTAGE_IN] = { | 69 | [PSC_VOLTAGE_IN] = { |
65 | .m = 16296, | 70 | .m = 16296, |
@@ -116,6 +121,36 @@ static struct __coeff lm25066_coeff[4][PSC_NUM_CLASSES + 2] = { | |||
116 | .m = 16, | 121 | .m = 16, |
117 | }, | 122 | }, |
118 | }, | 123 | }, |
124 | [lm25063] = { | ||
125 | [PSC_VOLTAGE_IN] = { | ||
126 | .m = 16000, | ||
127 | .R = -2, | ||
128 | }, | ||
129 | [PSC_VOLTAGE_OUT] = { | ||
130 | .m = 16000, | ||
131 | .R = -2, | ||
132 | }, | ||
133 | [PSC_CURRENT_IN] = { | ||
134 | .m = 10000, | ||
135 | .R = -2, | ||
136 | }, | ||
137 | [PSC_CURRENT_IN_L] = { | ||
138 | .m = 10000, | ||
139 | .R = -2, | ||
140 | }, | ||
141 | [PSC_POWER] = { | ||
142 | .m = 5000, | ||
143 | .R = -3, | ||
144 | }, | ||
145 | [PSC_POWER_L] = { | ||
146 | .m = 5000, | ||
147 | .R = -3, | ||
148 | }, | ||
149 | [PSC_TEMPERATURE] = { | ||
150 | .m = 15596, | ||
151 | .R = -3, | ||
152 | }, | ||
153 | }, | ||
119 | [lm5064] = { | 154 | [lm5064] = { |
120 | [PSC_VOLTAGE_IN] = { | 155 | [PSC_VOLTAGE_IN] = { |
121 | .m = 4611, | 156 | .m = 4611, |
@@ -178,6 +213,7 @@ static struct __coeff lm25066_coeff[4][PSC_NUM_CLASSES + 2] = { | |||
178 | 213 | ||
179 | struct lm25066_data { | 214 | struct lm25066_data { |
180 | int id; | 215 | int id; |
216 | u16 rlimit; /* Maximum register value */ | ||
181 | struct pmbus_driver_info info; | 217 | struct pmbus_driver_info info; |
182 | }; | 218 | }; |
183 | 219 | ||
@@ -200,6 +236,10 @@ static int lm25066_read_word_data(struct i2c_client *client, int page, int reg) | |||
200 | /* VIN: 6.14 mV VAUX: 293 uV LSB */ | 236 | /* VIN: 6.14 mV VAUX: 293 uV LSB */ |
201 | ret = DIV_ROUND_CLOSEST(ret * 293, 6140); | 237 | ret = DIV_ROUND_CLOSEST(ret * 293, 6140); |
202 | break; | 238 | break; |
239 | case lm25063: | ||
240 | /* VIN: 6.25 mV VAUX: 200.0 uV LSB */ | ||
241 | ret = DIV_ROUND_CLOSEST(ret * 20, 625); | ||
242 | break; | ||
203 | case lm25066: | 243 | case lm25066: |
204 | /* VIN: 4.54 mV VAUX: 283.2 uV LSB */ | 244 | /* VIN: 4.54 mV VAUX: 283.2 uV LSB */ |
205 | ret = DIV_ROUND_CLOSEST(ret * 2832, 45400); | 245 | ret = DIV_ROUND_CLOSEST(ret * 2832, 45400); |
@@ -253,6 +293,24 @@ static int lm25066_read_word_data(struct i2c_client *client, int page, int reg) | |||
253 | return ret; | 293 | return ret; |
254 | } | 294 | } |
255 | 295 | ||
296 | static int lm25063_read_word_data(struct i2c_client *client, int page, int reg) | ||
297 | { | ||
298 | int ret; | ||
299 | |||
300 | switch (reg) { | ||
301 | case PMBUS_VIRT_READ_VOUT_MAX: | ||
302 | ret = pmbus_read_word_data(client, 0, LM25063_READ_VOUT_MAX); | ||
303 | break; | ||
304 | case PMBUS_VIRT_READ_VOUT_MIN: | ||
305 | ret = pmbus_read_word_data(client, 0, LM25063_READ_VOUT_MIN); | ||
306 | break; | ||
307 | default: | ||
308 | ret = lm25066_read_word_data(client, page, reg); | ||
309 | break; | ||
310 | } | ||
311 | return ret; | ||
312 | } | ||
313 | |||
256 | static int lm25056_read_word_data(struct i2c_client *client, int page, int reg) | 314 | static int lm25056_read_word_data(struct i2c_client *client, int page, int reg) |
257 | { | 315 | { |
258 | int ret; | 316 | int ret; |
@@ -308,27 +366,34 @@ static int lm25056_read_byte_data(struct i2c_client *client, int page, int reg) | |||
308 | static int lm25066_write_word_data(struct i2c_client *client, int page, int reg, | 366 | static int lm25066_write_word_data(struct i2c_client *client, int page, int reg, |
309 | u16 word) | 367 | u16 word) |
310 | { | 368 | { |
369 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); | ||
370 | const struct lm25066_data *data = to_lm25066_data(info); | ||
311 | int ret; | 371 | int ret; |
312 | 372 | ||
313 | switch (reg) { | 373 | switch (reg) { |
374 | case PMBUS_POUT_OP_FAULT_LIMIT: | ||
375 | case PMBUS_POUT_OP_WARN_LIMIT: | ||
314 | case PMBUS_VOUT_UV_WARN_LIMIT: | 376 | case PMBUS_VOUT_UV_WARN_LIMIT: |
315 | case PMBUS_OT_FAULT_LIMIT: | 377 | case PMBUS_OT_FAULT_LIMIT: |
316 | case PMBUS_OT_WARN_LIMIT: | 378 | case PMBUS_OT_WARN_LIMIT: |
379 | case PMBUS_IIN_OC_FAULT_LIMIT: | ||
317 | case PMBUS_VIN_UV_WARN_LIMIT: | 380 | case PMBUS_VIN_UV_WARN_LIMIT: |
381 | case PMBUS_VIN_UV_FAULT_LIMIT: | ||
382 | case PMBUS_VIN_OV_FAULT_LIMIT: | ||
318 | case PMBUS_VIN_OV_WARN_LIMIT: | 383 | case PMBUS_VIN_OV_WARN_LIMIT: |
319 | word = ((s16)word < 0) ? 0 : clamp_val(word, 0, 0x0fff); | 384 | word = ((s16)word < 0) ? 0 : clamp_val(word, 0, data->rlimit); |
320 | ret = pmbus_write_word_data(client, 0, reg, word); | 385 | ret = pmbus_write_word_data(client, 0, reg, word); |
321 | pmbus_clear_cache(client); | 386 | pmbus_clear_cache(client); |
322 | break; | 387 | break; |
323 | case PMBUS_IIN_OC_WARN_LIMIT: | 388 | case PMBUS_IIN_OC_WARN_LIMIT: |
324 | word = ((s16)word < 0) ? 0 : clamp_val(word, 0, 0x0fff); | 389 | word = ((s16)word < 0) ? 0 : clamp_val(word, 0, data->rlimit); |
325 | ret = pmbus_write_word_data(client, 0, | 390 | ret = pmbus_write_word_data(client, 0, |
326 | LM25066_MFR_IIN_OC_WARN_LIMIT, | 391 | LM25066_MFR_IIN_OC_WARN_LIMIT, |
327 | word); | 392 | word); |
328 | pmbus_clear_cache(client); | 393 | pmbus_clear_cache(client); |
329 | break; | 394 | break; |
330 | case PMBUS_PIN_OP_WARN_LIMIT: | 395 | case PMBUS_PIN_OP_WARN_LIMIT: |
331 | word = ((s16)word < 0) ? 0 : clamp_val(word, 0, 0x0fff); | 396 | word = ((s16)word < 0) ? 0 : clamp_val(word, 0, data->rlimit); |
332 | ret = pmbus_write_word_data(client, 0, | 397 | ret = pmbus_write_word_data(client, 0, |
333 | LM25066_MFR_PIN_OP_WARN_LIMIT, | 398 | LM25066_MFR_PIN_OP_WARN_LIMIT, |
334 | word); | 399 | word); |
@@ -337,7 +402,7 @@ static int lm25066_write_word_data(struct i2c_client *client, int page, int reg, | |||
337 | case PMBUS_VIRT_VMON_UV_WARN_LIMIT: | 402 | case PMBUS_VIRT_VMON_UV_WARN_LIMIT: |
338 | /* Adjust from VIN coefficients (for LM25056) */ | 403 | /* Adjust from VIN coefficients (for LM25056) */ |
339 | word = DIV_ROUND_CLOSEST((int)word * 6140, 293); | 404 | word = DIV_ROUND_CLOSEST((int)word * 6140, 293); |
340 | word = ((s16)word < 0) ? 0 : clamp_val(word, 0, 0x0fff); | 405 | word = ((s16)word < 0) ? 0 : clamp_val(word, 0, data->rlimit); |
341 | ret = pmbus_write_word_data(client, 0, | 406 | ret = pmbus_write_word_data(client, 0, |
342 | LM25056_VAUX_UV_WARN_LIMIT, word); | 407 | LM25056_VAUX_UV_WARN_LIMIT, word); |
343 | pmbus_clear_cache(client); | 408 | pmbus_clear_cache(client); |
@@ -345,7 +410,7 @@ static int lm25066_write_word_data(struct i2c_client *client, int page, int reg, | |||
345 | case PMBUS_VIRT_VMON_OV_WARN_LIMIT: | 410 | case PMBUS_VIRT_VMON_OV_WARN_LIMIT: |
346 | /* Adjust from VIN coefficients (for LM25056) */ | 411 | /* Adjust from VIN coefficients (for LM25056) */ |
347 | word = DIV_ROUND_CLOSEST((int)word * 6140, 293); | 412 | word = DIV_ROUND_CLOSEST((int)word * 6140, 293); |
348 | word = ((s16)word < 0) ? 0 : clamp_val(word, 0, 0x0fff); | 413 | word = ((s16)word < 0) ? 0 : clamp_val(word, 0, data->rlimit); |
349 | ret = pmbus_write_word_data(client, 0, | 414 | ret = pmbus_write_word_data(client, 0, |
350 | LM25056_VAUX_OV_WARN_LIMIT, word); | 415 | LM25056_VAUX_OV_WARN_LIMIT, word); |
351 | pmbus_clear_cache(client); | 416 | pmbus_clear_cache(client); |
@@ -399,9 +464,16 @@ static int lm25066_probe(struct i2c_client *client, | |||
399 | info->func[0] |= PMBUS_HAVE_STATUS_VMON; | 464 | info->func[0] |= PMBUS_HAVE_STATUS_VMON; |
400 | info->read_word_data = lm25056_read_word_data; | 465 | info->read_word_data = lm25056_read_word_data; |
401 | info->read_byte_data = lm25056_read_byte_data; | 466 | info->read_byte_data = lm25056_read_byte_data; |
467 | data->rlimit = 0x0fff; | ||
468 | } else if (data->id == lm25063) { | ||
469 | info->func[0] |= PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | ||
470 | | PMBUS_HAVE_POUT; | ||
471 | info->read_word_data = lm25063_read_word_data; | ||
472 | data->rlimit = 0xffff; | ||
402 | } else { | 473 | } else { |
403 | info->func[0] |= PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT; | 474 | info->func[0] |= PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT; |
404 | info->read_word_data = lm25066_read_word_data; | 475 | info->read_word_data = lm25066_read_word_data; |
476 | data->rlimit = 0x0fff; | ||
405 | } | 477 | } |
406 | info->write_word_data = lm25066_write_word_data; | 478 | info->write_word_data = lm25066_write_word_data; |
407 | 479 | ||
@@ -432,6 +504,7 @@ static int lm25066_probe(struct i2c_client *client, | |||
432 | 504 | ||
433 | static const struct i2c_device_id lm25066_id[] = { | 505 | static const struct i2c_device_id lm25066_id[] = { |
434 | {"lm25056", lm25056}, | 506 | {"lm25056", lm25056}, |
507 | {"lm25063", lm25063}, | ||
435 | {"lm25066", lm25066}, | 508 | {"lm25066", lm25066}, |
436 | {"lm5064", lm5064}, | 509 | {"lm5064", lm5064}, |
437 | {"lm5066", lm5066}, | 510 | {"lm5066", lm5066}, |
@@ -453,5 +526,5 @@ static struct i2c_driver lm25066_driver = { | |||
453 | module_i2c_driver(lm25066_driver); | 526 | module_i2c_driver(lm25066_driver); |
454 | 527 | ||
455 | MODULE_AUTHOR("Guenter Roeck"); | 528 | MODULE_AUTHOR("Guenter Roeck"); |
456 | MODULE_DESCRIPTION("PMBus driver for LM25056/LM25066/LM5064/LM5066"); | 529 | MODULE_DESCRIPTION("PMBus driver for LM25066 and compatible chips"); |
457 | MODULE_LICENSE("GPL"); | 530 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/hwmon/pmbus/ltc2978.c b/drivers/hwmon/pmbus/ltc2978.c index 586a89ef9e0f..de3c152a1d9a 100644 --- a/drivers/hwmon/pmbus/ltc2978.c +++ b/drivers/hwmon/pmbus/ltc2978.c | |||
@@ -1,5 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * Hardware monitoring driver for LTC2974, LTC2978, LTC3880, and LTC3883 | 2 | * Hardware monitoring driver for LTC2974, LTC2977, LTC2978, LTC3880, |
3 | * and LTC3883 | ||
3 | * | 4 | * |
4 | * Copyright (c) 2011 Ericsson AB. | 5 | * Copyright (c) 2011 Ericsson AB. |
5 | * Copyright (c) 2013 Guenter Roeck | 6 | * Copyright (c) 2013 Guenter Roeck |
@@ -27,7 +28,7 @@ | |||
27 | #include <linux/i2c.h> | 28 | #include <linux/i2c.h> |
28 | #include "pmbus.h" | 29 | #include "pmbus.h" |
29 | 30 | ||
30 | enum chips { ltc2974, ltc2978, ltc3880, ltc3883 }; | 31 | enum chips { ltc2974, ltc2977, ltc2978, ltc3880, ltc3883 }; |
31 | 32 | ||
32 | /* Common for all chips */ | 33 | /* Common for all chips */ |
33 | #define LTC2978_MFR_VOUT_PEAK 0xdd | 34 | #define LTC2978_MFR_VOUT_PEAK 0xdd |
@@ -35,7 +36,7 @@ enum chips { ltc2974, ltc2978, ltc3880, ltc3883 }; | |||
35 | #define LTC2978_MFR_TEMPERATURE_PEAK 0xdf | 36 | #define LTC2978_MFR_TEMPERATURE_PEAK 0xdf |
36 | #define LTC2978_MFR_SPECIAL_ID 0xe7 | 37 | #define LTC2978_MFR_SPECIAL_ID 0xe7 |
37 | 38 | ||
38 | /* LTC2974 and LTC2978 */ | 39 | /* LTC2974, LCT2977, and LTC2978 */ |
39 | #define LTC2978_MFR_VOUT_MIN 0xfb | 40 | #define LTC2978_MFR_VOUT_MIN 0xfb |
40 | #define LTC2978_MFR_VIN_MIN 0xfc | 41 | #define LTC2978_MFR_VIN_MIN 0xfc |
41 | #define LTC2978_MFR_TEMPERATURE_MIN 0xfd | 42 | #define LTC2978_MFR_TEMPERATURE_MIN 0xfd |
@@ -53,8 +54,10 @@ enum chips { ltc2974, ltc2978, ltc3880, ltc3883 }; | |||
53 | #define LTC3883_MFR_IIN_PEAK 0xe1 | 54 | #define LTC3883_MFR_IIN_PEAK 0xe1 |
54 | 55 | ||
55 | #define LTC2974_ID 0x0212 | 56 | #define LTC2974_ID 0x0212 |
57 | #define LTC2977_ID 0x0130 | ||
56 | #define LTC2978_ID_REV1 0x0121 | 58 | #define LTC2978_ID_REV1 0x0121 |
57 | #define LTC2978_ID_REV2 0x0122 | 59 | #define LTC2978_ID_REV2 0x0122 |
60 | #define LTC2978A_ID 0x0124 | ||
58 | #define LTC3880_ID 0x4000 | 61 | #define LTC3880_ID 0x4000 |
59 | #define LTC3880_ID_MASK 0xff00 | 62 | #define LTC3880_ID_MASK 0xff00 |
60 | #define LTC3883_ID 0x4300 | 63 | #define LTC3883_ID 0x4300 |
@@ -363,6 +366,7 @@ static int ltc2978_write_word_data(struct i2c_client *client, int page, | |||
363 | 366 | ||
364 | static const struct i2c_device_id ltc2978_id[] = { | 367 | static const struct i2c_device_id ltc2978_id[] = { |
365 | {"ltc2974", ltc2974}, | 368 | {"ltc2974", ltc2974}, |
369 | {"ltc2977", ltc2977}, | ||
366 | {"ltc2978", ltc2978}, | 370 | {"ltc2978", ltc2978}, |
367 | {"ltc3880", ltc3880}, | 371 | {"ltc3880", ltc3880}, |
368 | {"ltc3883", ltc3883}, | 372 | {"ltc3883", ltc3883}, |
@@ -392,7 +396,10 @@ static int ltc2978_probe(struct i2c_client *client, | |||
392 | 396 | ||
393 | if (chip_id == LTC2974_ID) { | 397 | if (chip_id == LTC2974_ID) { |
394 | data->id = ltc2974; | 398 | data->id = ltc2974; |
395 | } else if (chip_id == LTC2978_ID_REV1 || chip_id == LTC2978_ID_REV2) { | 399 | } else if (chip_id == LTC2977_ID) { |
400 | data->id = ltc2977; | ||
401 | } else if (chip_id == LTC2978_ID_REV1 || chip_id == LTC2978_ID_REV2 || | ||
402 | chip_id == LTC2978A_ID) { | ||
396 | data->id = ltc2978; | 403 | data->id = ltc2978; |
397 | } else if ((chip_id & LTC3880_ID_MASK) == LTC3880_ID) { | 404 | } else if ((chip_id & LTC3880_ID_MASK) == LTC3880_ID) { |
398 | data->id = ltc3880; | 405 | data->id = ltc3880; |
@@ -438,6 +445,7 @@ static int ltc2978_probe(struct i2c_client *client, | |||
438 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT; | 445 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT; |
439 | } | 446 | } |
440 | break; | 447 | break; |
448 | case ltc2977: | ||
441 | case ltc2978: | 449 | case ltc2978: |
442 | info->read_word_data = ltc2978_read_word_data; | 450 | info->read_word_data = ltc2978_read_word_data; |
443 | info->pages = LTC2978_NUM_PAGES; | 451 | info->pages = LTC2978_NUM_PAGES; |
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index 9319fcf142d9..3cbf66e9d861 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c | |||
@@ -97,6 +97,7 @@ struct pmbus_data { | |||
97 | int max_attributes; | 97 | int max_attributes; |
98 | int num_attributes; | 98 | int num_attributes; |
99 | struct attribute_group group; | 99 | struct attribute_group group; |
100 | const struct attribute_group *groups[2]; | ||
100 | 101 | ||
101 | struct pmbus_sensor *sensors; | 102 | struct pmbus_sensor *sensors; |
102 | 103 | ||
@@ -156,7 +157,7 @@ EXPORT_SYMBOL_GPL(pmbus_write_byte); | |||
156 | 157 | ||
157 | /* | 158 | /* |
158 | * _pmbus_write_byte() is similar to pmbus_write_byte(), but checks if | 159 | * _pmbus_write_byte() is similar to pmbus_write_byte(), but checks if |
159 | * a device specific mapping funcion exists and calls it if necessary. | 160 | * a device specific mapping function exists and calls it if necessary. |
160 | */ | 161 | */ |
161 | static int _pmbus_write_byte(struct i2c_client *client, int page, u8 value) | 162 | static int _pmbus_write_byte(struct i2c_client *client, int page, u8 value) |
162 | { | 163 | { |
@@ -348,7 +349,7 @@ static struct _pmbus_status { | |||
348 | 349 | ||
349 | static struct pmbus_data *pmbus_update_device(struct device *dev) | 350 | static struct pmbus_data *pmbus_update_device(struct device *dev) |
350 | { | 351 | { |
351 | struct i2c_client *client = to_i2c_client(dev); | 352 | struct i2c_client *client = to_i2c_client(dev->parent); |
352 | struct pmbus_data *data = i2c_get_clientdata(client); | 353 | struct pmbus_data *data = i2c_get_clientdata(client); |
353 | const struct pmbus_driver_info *info = data->info; | 354 | const struct pmbus_driver_info *info = data->info; |
354 | struct pmbus_sensor *sensor; | 355 | struct pmbus_sensor *sensor; |
@@ -686,7 +687,7 @@ static int pmbus_get_boolean(struct pmbus_data *data, struct pmbus_boolean *b, | |||
686 | if (!s1 && !s2) { | 687 | if (!s1 && !s2) { |
687 | ret = !!regval; | 688 | ret = !!regval; |
688 | } else if (!s1 || !s2) { | 689 | } else if (!s1 || !s2) { |
689 | BUG(); | 690 | WARN(1, "Bad boolean descriptor %p: s1=%p, s2=%p\n", b, s1, s2); |
690 | return 0; | 691 | return 0; |
691 | } else { | 692 | } else { |
692 | long v1, v2; | 693 | long v1, v2; |
@@ -733,7 +734,7 @@ static ssize_t pmbus_set_sensor(struct device *dev, | |||
733 | struct device_attribute *devattr, | 734 | struct device_attribute *devattr, |
734 | const char *buf, size_t count) | 735 | const char *buf, size_t count) |
735 | { | 736 | { |
736 | struct i2c_client *client = to_i2c_client(dev); | 737 | struct i2c_client *client = to_i2c_client(dev->parent); |
737 | struct pmbus_data *data = i2c_get_clientdata(client); | 738 | struct pmbus_data *data = i2c_get_clientdata(client); |
738 | struct pmbus_sensor *sensor = to_pmbus_sensor(devattr); | 739 | struct pmbus_sensor *sensor = to_pmbus_sensor(devattr); |
739 | ssize_t rv = count; | 740 | ssize_t rv = count; |
@@ -1768,22 +1769,16 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id, | |||
1768 | goto out_kfree; | 1769 | goto out_kfree; |
1769 | } | 1770 | } |
1770 | 1771 | ||
1771 | /* Register sysfs hooks */ | 1772 | data->groups[0] = &data->group; |
1772 | ret = sysfs_create_group(&dev->kobj, &data->group); | 1773 | data->hwmon_dev = hwmon_device_register_with_groups(dev, client->name, |
1773 | if (ret) { | 1774 | data, data->groups); |
1774 | dev_err(dev, "Failed to create sysfs entries\n"); | ||
1775 | goto out_kfree; | ||
1776 | } | ||
1777 | data->hwmon_dev = hwmon_device_register(dev); | ||
1778 | if (IS_ERR(data->hwmon_dev)) { | 1775 | if (IS_ERR(data->hwmon_dev)) { |
1779 | ret = PTR_ERR(data->hwmon_dev); | 1776 | ret = PTR_ERR(data->hwmon_dev); |
1780 | dev_err(dev, "Failed to register hwmon device\n"); | 1777 | dev_err(dev, "Failed to register hwmon device\n"); |
1781 | goto out_hwmon_device_register; | 1778 | goto out_kfree; |
1782 | } | 1779 | } |
1783 | return 0; | 1780 | return 0; |
1784 | 1781 | ||
1785 | out_hwmon_device_register: | ||
1786 | sysfs_remove_group(&dev->kobj, &data->group); | ||
1787 | out_kfree: | 1782 | out_kfree: |
1788 | kfree(data->group.attrs); | 1783 | kfree(data->group.attrs); |
1789 | return ret; | 1784 | return ret; |
@@ -1794,7 +1789,6 @@ int pmbus_do_remove(struct i2c_client *client) | |||
1794 | { | 1789 | { |
1795 | struct pmbus_data *data = i2c_get_clientdata(client); | 1790 | struct pmbus_data *data = i2c_get_clientdata(client); |
1796 | hwmon_device_unregister(data->hwmon_dev); | 1791 | hwmon_device_unregister(data->hwmon_dev); |
1797 | sysfs_remove_group(&client->dev.kobj, &data->group); | ||
1798 | kfree(data->group.attrs); | 1792 | kfree(data->group.attrs); |
1799 | return 0; | 1793 | return 0; |
1800 | } | 1794 | } |
diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c index dfe6d9527efb..7fa6e7d0b9b6 100644 --- a/drivers/hwmon/tmp401.c +++ b/drivers/hwmon/tmp401.c | |||
@@ -155,7 +155,8 @@ MODULE_DEVICE_TABLE(i2c, tmp401_id); | |||
155 | */ | 155 | */ |
156 | 156 | ||
157 | struct tmp401_data { | 157 | struct tmp401_data { |
158 | struct device *hwmon_dev; | 158 | struct i2c_client *client; |
159 | const struct attribute_group *groups[3]; | ||
159 | struct mutex update_lock; | 160 | struct mutex update_lock; |
160 | char valid; /* zero until following fields are valid */ | 161 | char valid; /* zero until following fields are valid */ |
161 | unsigned long last_updated; /* in jiffies */ | 162 | unsigned long last_updated; /* in jiffies */ |
@@ -231,8 +232,8 @@ static int tmp401_update_device_reg16(struct i2c_client *client, | |||
231 | 232 | ||
232 | static struct tmp401_data *tmp401_update_device(struct device *dev) | 233 | static struct tmp401_data *tmp401_update_device(struct device *dev) |
233 | { | 234 | { |
234 | struct i2c_client *client = to_i2c_client(dev); | 235 | struct tmp401_data *data = dev_get_drvdata(dev); |
235 | struct tmp401_data *data = i2c_get_clientdata(client); | 236 | struct i2c_client *client = data->client; |
236 | struct tmp401_data *ret = data; | 237 | struct tmp401_data *ret = data; |
237 | int i, val; | 238 | int i, val; |
238 | unsigned long next_update; | 239 | unsigned long next_update; |
@@ -350,15 +351,12 @@ static ssize_t store_temp(struct device *dev, struct device_attribute *devattr, | |||
350 | { | 351 | { |
351 | int nr = to_sensor_dev_attr_2(devattr)->nr; | 352 | int nr = to_sensor_dev_attr_2(devattr)->nr; |
352 | int index = to_sensor_dev_attr_2(devattr)->index; | 353 | int index = to_sensor_dev_attr_2(devattr)->index; |
353 | struct i2c_client *client = to_i2c_client(dev); | 354 | struct tmp401_data *data = dev_get_drvdata(dev); |
354 | struct tmp401_data *data = tmp401_update_device(dev); | 355 | struct i2c_client *client = data->client; |
355 | long val; | 356 | long val; |
356 | u16 reg; | 357 | u16 reg; |
357 | u8 regaddr; | 358 | u8 regaddr; |
358 | 359 | ||
359 | if (IS_ERR(data)) | ||
360 | return PTR_ERR(data); | ||
361 | |||
362 | if (kstrtol(buf, 10, &val)) | 360 | if (kstrtol(buf, 10, &val)) |
363 | return -EINVAL; | 361 | return -EINVAL; |
364 | 362 | ||
@@ -405,7 +403,7 @@ static ssize_t store_temp_crit_hyst(struct device *dev, struct device_attribute | |||
405 | val = clamp_val(val, temp - 255000, temp); | 403 | val = clamp_val(val, temp - 255000, temp); |
406 | reg = ((temp - val) + 500) / 1000; | 404 | reg = ((temp - val) + 500) / 1000; |
407 | 405 | ||
408 | i2c_smbus_write_byte_data(to_i2c_client(dev), TMP401_TEMP_CRIT_HYST, | 406 | i2c_smbus_write_byte_data(data->client, TMP401_TEMP_CRIT_HYST, |
409 | reg); | 407 | reg); |
410 | 408 | ||
411 | data->temp_crit_hyst = reg; | 409 | data->temp_crit_hyst = reg; |
@@ -423,8 +421,8 @@ static ssize_t store_temp_crit_hyst(struct device *dev, struct device_attribute | |||
423 | static ssize_t reset_temp_history(struct device *dev, | 421 | static ssize_t reset_temp_history(struct device *dev, |
424 | struct device_attribute *devattr, const char *buf, size_t count) | 422 | struct device_attribute *devattr, const char *buf, size_t count) |
425 | { | 423 | { |
426 | struct i2c_client *client = to_i2c_client(dev); | 424 | struct tmp401_data *data = dev_get_drvdata(dev); |
427 | struct tmp401_data *data = i2c_get_clientdata(client); | 425 | struct i2c_client *client = data->client; |
428 | long val; | 426 | long val; |
429 | 427 | ||
430 | if (kstrtol(buf, 10, &val)) | 428 | if (kstrtol(buf, 10, &val)) |
@@ -447,8 +445,7 @@ static ssize_t reset_temp_history(struct device *dev, | |||
447 | static ssize_t show_update_interval(struct device *dev, | 445 | static ssize_t show_update_interval(struct device *dev, |
448 | struct device_attribute *attr, char *buf) | 446 | struct device_attribute *attr, char *buf) |
449 | { | 447 | { |
450 | struct i2c_client *client = to_i2c_client(dev); | 448 | struct tmp401_data *data = dev_get_drvdata(dev); |
451 | struct tmp401_data *data = i2c_get_clientdata(client); | ||
452 | 449 | ||
453 | return sprintf(buf, "%u\n", data->update_interval); | 450 | return sprintf(buf, "%u\n", data->update_interval); |
454 | } | 451 | } |
@@ -457,8 +454,8 @@ static ssize_t set_update_interval(struct device *dev, | |||
457 | struct device_attribute *attr, | 454 | struct device_attribute *attr, |
458 | const char *buf, size_t count) | 455 | const char *buf, size_t count) |
459 | { | 456 | { |
460 | struct i2c_client *client = to_i2c_client(dev); | 457 | struct tmp401_data *data = dev_get_drvdata(dev); |
461 | struct tmp401_data *data = i2c_get_clientdata(client); | 458 | struct i2c_client *client = data->client; |
462 | unsigned long val; | 459 | unsigned long val; |
463 | int err, rate; | 460 | int err, rate; |
464 | 461 | ||
@@ -616,10 +613,10 @@ static const struct attribute_group tmp432_group = { | |||
616 | * Begin non sysfs callback code (aka Real code) | 613 | * Begin non sysfs callback code (aka Real code) |
617 | */ | 614 | */ |
618 | 615 | ||
619 | static void tmp401_init_client(struct i2c_client *client) | 616 | static void tmp401_init_client(struct tmp401_data *data, |
617 | struct i2c_client *client) | ||
620 | { | 618 | { |
621 | int config, config_orig; | 619 | int config, config_orig; |
622 | struct tmp401_data *data = i2c_get_clientdata(client); | ||
623 | 620 | ||
624 | /* Set the conversion rate to 2 Hz */ | 621 | /* Set the conversion rate to 2 Hz */ |
625 | i2c_smbus_write_byte_data(client, TMP401_CONVERSION_RATE_WRITE, 5); | 622 | i2c_smbus_write_byte_data(client, TMP401_CONVERSION_RATE_WRITE, 5); |
@@ -705,77 +702,45 @@ static int tmp401_detect(struct i2c_client *client, | |||
705 | return 0; | 702 | return 0; |
706 | } | 703 | } |
707 | 704 | ||
708 | static int tmp401_remove(struct i2c_client *client) | ||
709 | { | ||
710 | struct device *dev = &client->dev; | ||
711 | struct tmp401_data *data = i2c_get_clientdata(client); | ||
712 | |||
713 | if (data->hwmon_dev) | ||
714 | hwmon_device_unregister(data->hwmon_dev); | ||
715 | |||
716 | sysfs_remove_group(&dev->kobj, &tmp401_group); | ||
717 | |||
718 | if (data->kind == tmp411) | ||
719 | sysfs_remove_group(&dev->kobj, &tmp411_group); | ||
720 | |||
721 | if (data->kind == tmp432) | ||
722 | sysfs_remove_group(&dev->kobj, &tmp432_group); | ||
723 | |||
724 | return 0; | ||
725 | } | ||
726 | |||
727 | static int tmp401_probe(struct i2c_client *client, | 705 | static int tmp401_probe(struct i2c_client *client, |
728 | const struct i2c_device_id *id) | 706 | const struct i2c_device_id *id) |
729 | { | 707 | { |
708 | const char *names[] = { "TMP401", "TMP411", "TMP431", "TMP432" }; | ||
730 | struct device *dev = &client->dev; | 709 | struct device *dev = &client->dev; |
731 | int err; | 710 | struct device *hwmon_dev; |
732 | struct tmp401_data *data; | 711 | struct tmp401_data *data; |
733 | const char *names[] = { "TMP401", "TMP411", "TMP431", "TMP432" }; | 712 | int groups = 0; |
734 | 713 | ||
735 | data = devm_kzalloc(dev, sizeof(struct tmp401_data), GFP_KERNEL); | 714 | data = devm_kzalloc(dev, sizeof(struct tmp401_data), GFP_KERNEL); |
736 | if (!data) | 715 | if (!data) |
737 | return -ENOMEM; | 716 | return -ENOMEM; |
738 | 717 | ||
739 | i2c_set_clientdata(client, data); | 718 | data->client = client; |
740 | mutex_init(&data->update_lock); | 719 | mutex_init(&data->update_lock); |
741 | data->kind = id->driver_data; | 720 | data->kind = id->driver_data; |
742 | 721 | ||
743 | /* Initialize the TMP401 chip */ | 722 | /* Initialize the TMP401 chip */ |
744 | tmp401_init_client(client); | 723 | tmp401_init_client(data, client); |
745 | 724 | ||
746 | /* Register sysfs hooks */ | 725 | /* Register sysfs hooks */ |
747 | err = sysfs_create_group(&dev->kobj, &tmp401_group); | 726 | data->groups[groups++] = &tmp401_group; |
748 | if (err) | ||
749 | return err; | ||
750 | 727 | ||
751 | /* Register additional tmp411 sysfs hooks */ | 728 | /* Register additional tmp411 sysfs hooks */ |
752 | if (data->kind == tmp411) { | 729 | if (data->kind == tmp411) |
753 | err = sysfs_create_group(&dev->kobj, &tmp411_group); | 730 | data->groups[groups++] = &tmp411_group; |
754 | if (err) | ||
755 | goto exit_remove; | ||
756 | } | ||
757 | 731 | ||
758 | /* Register additional tmp432 sysfs hooks */ | 732 | /* Register additional tmp432 sysfs hooks */ |
759 | if (data->kind == tmp432) { | 733 | if (data->kind == tmp432) |
760 | err = sysfs_create_group(&dev->kobj, &tmp432_group); | 734 | data->groups[groups++] = &tmp432_group; |
761 | if (err) | ||
762 | goto exit_remove; | ||
763 | } | ||
764 | 735 | ||
765 | data->hwmon_dev = hwmon_device_register(dev); | 736 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
766 | if (IS_ERR(data->hwmon_dev)) { | 737 | data, data->groups); |
767 | err = PTR_ERR(data->hwmon_dev); | 738 | if (IS_ERR(hwmon_dev)) |
768 | data->hwmon_dev = NULL; | 739 | return PTR_ERR(hwmon_dev); |
769 | goto exit_remove; | ||
770 | } | ||
771 | 740 | ||
772 | dev_info(dev, "Detected TI %s chip\n", names[data->kind]); | 741 | dev_info(dev, "Detected TI %s chip\n", names[data->kind]); |
773 | 742 | ||
774 | return 0; | 743 | return 0; |
775 | |||
776 | exit_remove: | ||
777 | tmp401_remove(client); | ||
778 | return err; | ||
779 | } | 744 | } |
780 | 745 | ||
781 | static struct i2c_driver tmp401_driver = { | 746 | static struct i2c_driver tmp401_driver = { |
@@ -784,7 +749,6 @@ static struct i2c_driver tmp401_driver = { | |||
784 | .name = "tmp401", | 749 | .name = "tmp401", |
785 | }, | 750 | }, |
786 | .probe = tmp401_probe, | 751 | .probe = tmp401_probe, |
787 | .remove = tmp401_remove, | ||
788 | .id_table = tmp401_id, | 752 | .id_table = tmp401_id, |
789 | .detect = tmp401_detect, | 753 | .detect = tmp401_detect, |
790 | .address_list = normal_i2c, | 754 | .address_list = normal_i2c, |
diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c index a3feee332e20..bdcf2dce5ec4 100644 --- a/drivers/hwmon/w83791d.c +++ b/drivers/hwmon/w83791d.c | |||
@@ -1043,7 +1043,7 @@ static struct sensor_device_attribute sda_temp_alarm[] = { | |||
1043 | SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13), | 1043 | SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13), |
1044 | }; | 1044 | }; |
1045 | 1045 | ||
1046 | /* get reatime status of all sensors items: voltage, temp, fan */ | 1046 | /* get realtime status of all sensors items: voltage, temp, fan */ |
1047 | static ssize_t show_alarms_reg(struct device *dev, | 1047 | static ssize_t show_alarms_reg(struct device *dev, |
1048 | struct device_attribute *attr, char *buf) | 1048 | struct device_attribute *attr, char *buf) |
1049 | { | 1049 | { |
diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c index 5febb43cb4c1..df585808adb6 100644 --- a/drivers/hwmon/w83792d.c +++ b/drivers/hwmon/w83792d.c | |||
@@ -579,7 +579,7 @@ static ssize_t store_temp23(struct device *dev, struct device_attribute *attr, | |||
579 | return count; | 579 | return count; |
580 | } | 580 | } |
581 | 581 | ||
582 | /* get reatime status of all sensors items: voltage, temp, fan */ | 582 | /* get realtime status of all sensors items: voltage, temp, fan */ |
583 | static ssize_t | 583 | static ssize_t |
584 | show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf) | 584 | show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf) |
585 | { | 585 | { |
diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c index b0c30a546ff2..9d63d71214ca 100644 --- a/drivers/hwmon/w83793.c +++ b/drivers/hwmon/w83793.c | |||
@@ -808,7 +808,7 @@ show_sf_ctrl(struct device *dev, struct device_attribute *attr, char *buf) | |||
808 | if (nr == TEMP_FAN_MAP) { | 808 | if (nr == TEMP_FAN_MAP) { |
809 | val = data->temp_fan_map[index]; | 809 | val = data->temp_fan_map[index]; |
810 | } else if (nr == TEMP_PWM_ENABLE) { | 810 | } else if (nr == TEMP_PWM_ENABLE) { |
811 | /* +2 to transfrom into 2 and 3 to conform with sysfs intf */ | 811 | /* +2 to transform into 2 and 3 to conform with sysfs intf */ |
812 | val = ((data->pwm_enable >> index) & 0x01) + 2; | 812 | val = ((data->pwm_enable >> index) & 0x01) + 2; |
813 | } else if (nr == TEMP_CRUISE) { | 813 | } else if (nr == TEMP_CRUISE) { |
814 | val = TEMP_FROM_REG(data->temp_cruise[index] & 0x7f); | 814 | val = TEMP_FROM_REG(data->temp_cruise[index] & 0x7f); |
@@ -1199,7 +1199,8 @@ static void w83793_init_client(struct i2c_client *client) | |||
1199 | 1199 | ||
1200 | static int watchdog_set_timeout(struct w83793_data *data, int timeout) | 1200 | static int watchdog_set_timeout(struct w83793_data *data, int timeout) |
1201 | { | 1201 | { |
1202 | int ret, mtimeout; | 1202 | unsigned int mtimeout; |
1203 | int ret; | ||
1203 | 1204 | ||
1204 | mtimeout = DIV_ROUND_UP(timeout, 60); | 1205 | mtimeout = DIV_ROUND_UP(timeout, 60); |
1205 | 1206 | ||