diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-17 16:15:55 -0500 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-17 16:15:55 -0500 |
commit | 8dea78da5cee153b8af9c07a2745f6c55057fe12 (patch) | |
tree | a8f4d49d63b1ecc92f2fddceba0655b2472c5bd9 /drivers/hwmon/vt8231.c | |
parent | 406089d01562f1e2bf9f089fd7637009ebaad589 (diff) |
Patched in Tegra support.
Diffstat (limited to 'drivers/hwmon/vt8231.c')
-rw-r--r-- | drivers/hwmon/vt8231.c | 317 |
1 files changed, 129 insertions, 188 deletions
diff --git a/drivers/hwmon/vt8231.c b/drivers/hwmon/vt8231.c index a56355cef18..db3b2e8d2a6 100644 --- a/drivers/hwmon/vt8231.c +++ b/drivers/hwmon/vt8231.c | |||
@@ -1,29 +1,28 @@ | |||
1 | /* | 1 | /* |
2 | * vt8231.c - Part of lm_sensors, Linux kernel modules | 2 | vt8231.c - Part of lm_sensors, Linux kernel modules |
3 | * for hardware monitoring | 3 | for hardware monitoring |
4 | * | ||
5 | * Copyright (c) 2005 Roger Lucas <vt8231@hiddenengine.co.uk> | ||
6 | * Copyright (c) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com> | ||
7 | * Aaron M. Marsh <amarsh@sdf.lonestar.org> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
22 | */ | ||
23 | 4 | ||
24 | /* | 5 | Copyright (c) 2005 Roger Lucas <vt8231@hiddenengine.co.uk> |
25 | * Supports VIA VT8231 South Bridge embedded sensors | 6 | Copyright (c) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com> |
26 | */ | 7 | Aaron M. Marsh <amarsh@sdf.lonestar.org> |
8 | |||
9 | This program is free software; you can redistribute it and/or modify | ||
10 | it under the terms of the GNU General Public License as published by | ||
11 | the Free Software Foundation; either version 2 of the License, or | ||
12 | (at your option) any later version. | ||
13 | |||
14 | This program is distributed in the hope that it will be useful, | ||
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | GNU General Public License for more details. | ||
18 | |||
19 | You should have received a copy of the GNU General Public License | ||
20 | along with this program; if not, write to the Free Software | ||
21 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
22 | */ | ||
23 | |||
24 | /* Supports VIA VT8231 South Bridge embedded sensors | ||
25 | */ | ||
27 | 26 | ||
28 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | 27 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
29 | 28 | ||
@@ -51,27 +50,26 @@ static struct platform_device *pdev; | |||
51 | #define VT8231_BASE_REG 0x70 | 50 | #define VT8231_BASE_REG 0x70 |
52 | #define VT8231_ENABLE_REG 0x74 | 51 | #define VT8231_ENABLE_REG 0x74 |
53 | 52 | ||
54 | /* | 53 | /* The VT8231 registers |
55 | * The VT8231 registers | 54 | |
56 | * | 55 | The reset value for the input channel configuration is used (Reg 0x4A=0x07) |
57 | * The reset value for the input channel configuration is used (Reg 0x4A=0x07) | 56 | which sets the selected inputs marked with '*' below if multiple options are |
58 | * which sets the selected inputs marked with '*' below if multiple options are | 57 | possible: |
59 | * possible: | 58 | |
60 | * | 59 | Voltage Mode Temperature Mode |
61 | * Voltage Mode Temperature Mode | 60 | Sensor Linux Id Linux Id VIA Id |
62 | * Sensor Linux Id Linux Id VIA Id | 61 | -------- -------- -------- ------ |
63 | * -------- -------- -------- ------ | 62 | CPU Diode N/A temp1 0 |
64 | * CPU Diode N/A temp1 0 | 63 | UIC1 in0 temp2 * 1 |
65 | * UIC1 in0 temp2 * 1 | 64 | UIC2 in1 * temp3 2 |
66 | * UIC2 in1 * temp3 2 | 65 | UIC3 in2 * temp4 3 |
67 | * UIC3 in2 * temp4 3 | 66 | UIC4 in3 * temp5 4 |
68 | * UIC4 in3 * temp5 4 | 67 | UIC5 in4 * temp6 5 |
69 | * UIC5 in4 * temp6 5 | 68 | 3.3V in5 N/A |
70 | * 3.3V in5 N/A | 69 | |
71 | * | 70 | Note that the BIOS may set the configuration register to a different value |
72 | * Note that the BIOS may set the configuration register to a different value | 71 | to match the motherboard configuration. |
73 | * to match the motherboard configuration. | 72 | */ |
74 | */ | ||
75 | 73 | ||
76 | /* fans numbered 0-1 */ | 74 | /* fans numbered 0-1 */ |
77 | #define VT8231_REG_FAN_MIN(nr) (0x3b + (nr)) | 75 | #define VT8231_REG_FAN_MIN(nr) (0x3b + (nr)) |
@@ -83,14 +81,13 @@ static const u8 regvolt[] = { 0x21, 0x22, 0x23, 0x24, 0x25, 0x26 }; | |||
83 | static const u8 regvoltmax[] = { 0x3d, 0x2b, 0x2d, 0x2f, 0x31, 0x33 }; | 81 | static const u8 regvoltmax[] = { 0x3d, 0x2b, 0x2d, 0x2f, 0x31, 0x33 }; |
84 | static const u8 regvoltmin[] = { 0x3e, 0x2c, 0x2e, 0x30, 0x32, 0x34 }; | 82 | static const u8 regvoltmin[] = { 0x3e, 0x2c, 0x2e, 0x30, 0x32, 0x34 }; |
85 | 83 | ||
86 | /* | 84 | /* Temperatures are numbered 1-6 according to the Linux kernel specification. |
87 | * Temperatures are numbered 1-6 according to the Linux kernel specification. | 85 | ** |
88 | * | 86 | ** In the VIA datasheet, however, the temperatures are numbered from zero. |
89 | * In the VIA datasheet, however, the temperatures are numbered from zero. | 87 | ** Since it is important that this driver can easily be compared to the VIA |
90 | * Since it is important that this driver can easily be compared to the VIA | 88 | ** datasheet, we will use the VIA numbering within this driver and map the |
91 | * datasheet, we will use the VIA numbering within this driver and map the | 89 | ** kernel sysfs device name to the VIA number in the sysfs callback. |
92 | * kernel sysfs device name to the VIA number in the sysfs callback. | 90 | */ |
93 | */ | ||
94 | 91 | ||
95 | #define VT8231_REG_TEMP_LOW01 0x49 | 92 | #define VT8231_REG_TEMP_LOW01 0x49 |
96 | #define VT8231_REG_TEMP_LOW25 0x4d | 93 | #define VT8231_REG_TEMP_LOW25 0x4d |
@@ -111,10 +108,9 @@ static const u8 regtempmin[] = { 0x3a, 0x3e, 0x2c, 0x2e, 0x30, 0x32 }; | |||
111 | #define VT8231_REG_TEMP1_CONFIG 0x4b | 108 | #define VT8231_REG_TEMP1_CONFIG 0x4b |
112 | #define VT8231_REG_TEMP2_CONFIG 0x4c | 109 | #define VT8231_REG_TEMP2_CONFIG 0x4c |
113 | 110 | ||
114 | /* | 111 | /* temps 0-5 as numbered in VIA datasheet - see later for mapping to Linux |
115 | * temps 0-5 as numbered in VIA datasheet - see later for mapping to Linux | 112 | ** numbering |
116 | * numbering | 113 | */ |
117 | */ | ||
118 | #define ISTEMP(i, ch_config) ((i) == 0 ? 1 : \ | 114 | #define ISTEMP(i, ch_config) ((i) == 0 ? 1 : \ |
119 | ((ch_config) >> ((i)+1)) & 0x01) | 115 | ((ch_config) >> ((i)+1)) & 0x01) |
120 | /* voltages 0-5 */ | 116 | /* voltages 0-5 */ |
@@ -123,26 +119,24 @@ static const u8 regtempmin[] = { 0x3a, 0x3e, 0x2c, 0x2e, 0x30, 0x32 }; | |||
123 | 119 | ||
124 | #define DIV_FROM_REG(val) (1 << (val)) | 120 | #define DIV_FROM_REG(val) (1 << (val)) |
125 | 121 | ||
126 | /* | 122 | /* NB The values returned here are NOT temperatures. The calibration curves |
127 | * NB The values returned here are NOT temperatures. The calibration curves | 123 | ** for the thermistor curves are board-specific and must go in the |
128 | * for the thermistor curves are board-specific and must go in the | 124 | ** sensors.conf file. Temperature sensors are actually ten bits, but the |
129 | * sensors.conf file. Temperature sensors are actually ten bits, but the | 125 | ** VIA datasheet only considers the 8 MSBs obtained from the regtemp[] |
130 | * VIA datasheet only considers the 8 MSBs obtained from the regtemp[] | 126 | ** register. The temperature value returned should have a magnitude of 3, |
131 | * register. The temperature value returned should have a magnitude of 3, | 127 | ** so we use the VIA scaling as the "true" scaling and use the remaining 2 |
132 | * so we use the VIA scaling as the "true" scaling and use the remaining 2 | 128 | ** LSBs as fractional precision. |
133 | * LSBs as fractional precision. | 129 | ** |
134 | * | 130 | ** All the on-chip hardware temperature comparisons for the alarms are only |
135 | * All the on-chip hardware temperature comparisons for the alarms are only | 131 | ** 8-bits wide, and compare against the 8 MSBs of the temperature. The bits |
136 | * 8-bits wide, and compare against the 8 MSBs of the temperature. The bits | 132 | ** in the registers VT8231_REG_TEMP_LOW01 and VT8231_REG_TEMP_LOW25 are |
137 | * in the registers VT8231_REG_TEMP_LOW01 and VT8231_REG_TEMP_LOW25 are | 133 | ** ignored. |
138 | * ignored. | 134 | */ |
139 | */ | 135 | |
140 | 136 | /******** FAN RPM CONVERSIONS ******** | |
141 | /* | 137 | ** This chip saturates back at 0, not at 255 like many the other chips. |
142 | ****** FAN RPM CONVERSIONS ******** | 138 | ** So, 0 means 0 RPM |
143 | * This chip saturates back at 0, not at 255 like many the other chips. | 139 | */ |
144 | * So, 0 means 0 RPM | ||
145 | */ | ||
146 | static inline u8 FAN_TO_REG(long rpm, int div) | 140 | static inline u8 FAN_TO_REG(long rpm, int div) |
147 | { | 141 | { |
148 | if (rpm == 0) | 142 | if (rpm == 0) |
@@ -176,7 +170,7 @@ struct vt8231_data { | |||
176 | 170 | ||
177 | static struct pci_dev *s_bridge; | 171 | static struct pci_dev *s_bridge; |
178 | static int vt8231_probe(struct platform_device *pdev); | 172 | static int vt8231_probe(struct platform_device *pdev); |
179 | static int vt8231_remove(struct platform_device *pdev); | 173 | static int __devexit vt8231_remove(struct platform_device *pdev); |
180 | static struct vt8231_data *vt8231_update_device(struct device *dev); | 174 | static struct vt8231_data *vt8231_update_device(struct device *dev); |
181 | static void vt8231_init_device(struct vt8231_data *data); | 175 | static void vt8231_init_device(struct vt8231_data *data); |
182 | 176 | ||
@@ -228,12 +222,7 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | |||
228 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 222 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
229 | int nr = sensor_attr->index; | 223 | int nr = sensor_attr->index; |
230 | struct vt8231_data *data = dev_get_drvdata(dev); | 224 | struct vt8231_data *data = dev_get_drvdata(dev); |
231 | unsigned long val; | 225 | unsigned long val = simple_strtoul(buf, NULL, 10); |
232 | int err; | ||
233 | |||
234 | err = kstrtoul(buf, 10, &val); | ||
235 | if (err) | ||
236 | return err; | ||
237 | 226 | ||
238 | mutex_lock(&data->update_lock); | 227 | mutex_lock(&data->update_lock); |
239 | data->in_min[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255); | 228 | data->in_min[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255); |
@@ -248,12 +237,7 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, | |||
248 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 237 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
249 | int nr = sensor_attr->index; | 238 | int nr = sensor_attr->index; |
250 | struct vt8231_data *data = dev_get_drvdata(dev); | 239 | struct vt8231_data *data = dev_get_drvdata(dev); |
251 | unsigned long val; | 240 | unsigned long val = simple_strtoul(buf, NULL, 10); |
252 | int err; | ||
253 | |||
254 | err = kstrtoul(buf, 10, &val); | ||
255 | if (err) | ||
256 | return err; | ||
257 | 241 | ||
258 | mutex_lock(&data->update_lock); | 242 | mutex_lock(&data->update_lock); |
259 | data->in_max[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255); | 243 | data->in_max[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255); |
@@ -294,12 +278,7 @@ static ssize_t set_in5_min(struct device *dev, struct device_attribute *attr, | |||
294 | const char *buf, size_t count) | 278 | const char *buf, size_t count) |
295 | { | 279 | { |
296 | struct vt8231_data *data = dev_get_drvdata(dev); | 280 | struct vt8231_data *data = dev_get_drvdata(dev); |
297 | unsigned long val; | 281 | unsigned long val = simple_strtoul(buf, NULL, 10); |
298 | int err; | ||
299 | |||
300 | err = kstrtoul(buf, 10, &val); | ||
301 | if (err) | ||
302 | return err; | ||
303 | 282 | ||
304 | mutex_lock(&data->update_lock); | 283 | mutex_lock(&data->update_lock); |
305 | data->in_min[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3, | 284 | data->in_min[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3, |
@@ -313,12 +292,7 @@ static ssize_t set_in5_max(struct device *dev, struct device_attribute *attr, | |||
313 | const char *buf, size_t count) | 292 | const char *buf, size_t count) |
314 | { | 293 | { |
315 | struct vt8231_data *data = dev_get_drvdata(dev); | 294 | struct vt8231_data *data = dev_get_drvdata(dev); |
316 | unsigned long val; | 295 | unsigned long val = simple_strtoul(buf, NULL, 10); |
317 | int err; | ||
318 | |||
319 | err = kstrtoul(buf, 10, &val); | ||
320 | if (err) | ||
321 | return err; | ||
322 | 296 | ||
323 | mutex_lock(&data->update_lock); | 297 | mutex_lock(&data->update_lock); |
324 | data->in_max[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3, | 298 | data->in_max[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3, |
@@ -372,12 +346,7 @@ static ssize_t set_temp0_max(struct device *dev, struct device_attribute *attr, | |||
372 | const char *buf, size_t count) | 346 | const char *buf, size_t count) |
373 | { | 347 | { |
374 | struct vt8231_data *data = dev_get_drvdata(dev); | 348 | struct vt8231_data *data = dev_get_drvdata(dev); |
375 | long val; | 349 | int val = simple_strtol(buf, NULL, 10); |
376 | int err; | ||
377 | |||
378 | err = kstrtol(buf, 10, &val); | ||
379 | if (err) | ||
380 | return err; | ||
381 | 350 | ||
382 | mutex_lock(&data->update_lock); | 351 | mutex_lock(&data->update_lock); |
383 | data->temp_max[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255); | 352 | data->temp_max[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255); |
@@ -389,12 +358,7 @@ static ssize_t set_temp0_min(struct device *dev, struct device_attribute *attr, | |||
389 | const char *buf, size_t count) | 358 | const char *buf, size_t count) |
390 | { | 359 | { |
391 | struct vt8231_data *data = dev_get_drvdata(dev); | 360 | struct vt8231_data *data = dev_get_drvdata(dev); |
392 | long val; | 361 | int val = simple_strtol(buf, NULL, 10); |
393 | int err; | ||
394 | |||
395 | err = kstrtol(buf, 10, &val); | ||
396 | if (err) | ||
397 | return err; | ||
398 | 362 | ||
399 | mutex_lock(&data->update_lock); | 363 | mutex_lock(&data->update_lock); |
400 | data->temp_min[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255); | 364 | data->temp_min[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255); |
@@ -436,12 +400,7 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
436 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 400 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
437 | int nr = sensor_attr->index; | 401 | int nr = sensor_attr->index; |
438 | struct vt8231_data *data = dev_get_drvdata(dev); | 402 | struct vt8231_data *data = dev_get_drvdata(dev); |
439 | long val; | 403 | int val = simple_strtol(buf, NULL, 10); |
440 | int err; | ||
441 | |||
442 | err = kstrtol(buf, 10, &val); | ||
443 | if (err) | ||
444 | return err; | ||
445 | 404 | ||
446 | mutex_lock(&data->update_lock); | 405 | mutex_lock(&data->update_lock); |
447 | data->temp_max[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255); | 406 | data->temp_max[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255); |
@@ -455,12 +414,7 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | |||
455 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 414 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
456 | int nr = sensor_attr->index; | 415 | int nr = sensor_attr->index; |
457 | struct vt8231_data *data = dev_get_drvdata(dev); | 416 | struct vt8231_data *data = dev_get_drvdata(dev); |
458 | long val; | 417 | int val = simple_strtol(buf, NULL, 10); |
459 | int err; | ||
460 | |||
461 | err = kstrtol(buf, 10, &val); | ||
462 | if (err) | ||
463 | return err; | ||
464 | 418 | ||
465 | mutex_lock(&data->update_lock); | 419 | mutex_lock(&data->update_lock); |
466 | data->temp_min[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255); | 420 | data->temp_min[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255); |
@@ -469,10 +423,9 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | |||
469 | return count; | 423 | return count; |
470 | } | 424 | } |
471 | 425 | ||
472 | /* | 426 | /* Note that these map the Linux temperature sensor numbering (1-6) to the VIA |
473 | * Note that these map the Linux temperature sensor numbering (1-6) to the VIA | 427 | ** temperature sensor numbering (0-5) |
474 | * temperature sensor numbering (0-5) | 428 | */ |
475 | */ | ||
476 | #define define_temperature_sysfs(offset) \ | 429 | #define define_temperature_sysfs(offset) \ |
477 | static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ | 430 | static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ |
478 | show_temp, NULL, offset - 1); \ | 431 | show_temp, NULL, offset - 1); \ |
@@ -483,8 +436,7 @@ static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \ | |||
483 | 436 | ||
484 | static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp0, NULL); | 437 | static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp0, NULL); |
485 | static DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, show_temp0_max, set_temp0_max); | 438 | static DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, show_temp0_max, set_temp0_max); |
486 | static DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp0_min, | 439 | static DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp0_min, set_temp0_min); |
487 | set_temp0_min); | ||
488 | 440 | ||
489 | define_temperature_sysfs(2); | 441 | define_temperature_sysfs(2); |
490 | define_temperature_sysfs(3); | 442 | define_temperature_sysfs(3); |
@@ -528,12 +480,7 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | |||
528 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 480 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
529 | int nr = sensor_attr->index; | 481 | int nr = sensor_attr->index; |
530 | struct vt8231_data *data = dev_get_drvdata(dev); | 482 | struct vt8231_data *data = dev_get_drvdata(dev); |
531 | unsigned long val; | 483 | int val = simple_strtoul(buf, NULL, 10); |
532 | int err; | ||
533 | |||
534 | err = kstrtoul(buf, 10, &val); | ||
535 | if (err) | ||
536 | return err; | ||
537 | 484 | ||
538 | mutex_lock(&data->update_lock); | 485 | mutex_lock(&data->update_lock); |
539 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); | 486 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); |
@@ -547,34 +494,21 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | |||
547 | { | 494 | { |
548 | struct vt8231_data *data = dev_get_drvdata(dev); | 495 | struct vt8231_data *data = dev_get_drvdata(dev); |
549 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 496 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
550 | unsigned long val; | 497 | unsigned long val = simple_strtoul(buf, NULL, 10); |
551 | int nr = sensor_attr->index; | 498 | int nr = sensor_attr->index; |
552 | int old = vt8231_read_value(data, VT8231_REG_FANDIV); | 499 | int old = vt8231_read_value(data, VT8231_REG_FANDIV); |
553 | long min = FAN_FROM_REG(data->fan_min[nr], | 500 | long min = FAN_FROM_REG(data->fan_min[nr], |
554 | DIV_FROM_REG(data->fan_div[nr])); | 501 | DIV_FROM_REG(data->fan_div[nr])); |
555 | int err; | ||
556 | |||
557 | err = kstrtoul(buf, 10, &val); | ||
558 | if (err) | ||
559 | return err; | ||
560 | 502 | ||
561 | mutex_lock(&data->update_lock); | 503 | mutex_lock(&data->update_lock); |
562 | switch (val) { | 504 | switch (val) { |
563 | case 1: | 505 | case 1: data->fan_div[nr] = 0; break; |
564 | data->fan_div[nr] = 0; | 506 | case 2: data->fan_div[nr] = 1; break; |
565 | break; | 507 | case 4: data->fan_div[nr] = 2; break; |
566 | case 2: | 508 | case 8: data->fan_div[nr] = 3; break; |
567 | data->fan_div[nr] = 1; | ||
568 | break; | ||
569 | case 4: | ||
570 | data->fan_div[nr] = 2; | ||
571 | break; | ||
572 | case 8: | ||
573 | data->fan_div[nr] = 3; | ||
574 | break; | ||
575 | default: | 509 | default: |
576 | dev_err(dev, "fan_div value %ld not supported. " | 510 | dev_err(dev, "fan_div value %ld not supported. " |
577 | "Choose one of 1, 2, 4 or 8!\n", val); | 511 | "Choose one of 1, 2, 4 or 8!\n", val); |
578 | mutex_unlock(&data->update_lock); | 512 | mutex_unlock(&data->update_lock); |
579 | return -EINVAL; | 513 | return -EINVAL; |
580 | } | 514 | } |
@@ -762,18 +696,18 @@ static struct platform_driver vt8231_driver = { | |||
762 | .name = "vt8231", | 696 | .name = "vt8231", |
763 | }, | 697 | }, |
764 | .probe = vt8231_probe, | 698 | .probe = vt8231_probe, |
765 | .remove = vt8231_remove, | 699 | .remove = __devexit_p(vt8231_remove), |
766 | }; | 700 | }; |
767 | 701 | ||
768 | static DEFINE_PCI_DEVICE_TABLE(vt8231_pci_ids) = { | 702 | static const struct pci_device_id vt8231_pci_ids[] = { |
769 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4) }, | 703 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4) }, |
770 | { 0, } | 704 | { 0, } |
771 | }; | 705 | }; |
772 | 706 | ||
773 | MODULE_DEVICE_TABLE(pci, vt8231_pci_ids); | 707 | MODULE_DEVICE_TABLE(pci, vt8231_pci_ids); |
774 | 708 | ||
775 | static int vt8231_pci_probe(struct pci_dev *dev, | 709 | static int __devinit vt8231_pci_probe(struct pci_dev *dev, |
776 | const struct pci_device_id *id); | 710 | const struct pci_device_id *id); |
777 | 711 | ||
778 | static struct pci_driver vt8231_pci_driver = { | 712 | static struct pci_driver vt8231_pci_driver = { |
779 | .name = "vt8231", | 713 | .name = "vt8231", |
@@ -789,16 +723,17 @@ static int vt8231_probe(struct platform_device *pdev) | |||
789 | 723 | ||
790 | /* Reserve the ISA region */ | 724 | /* Reserve the ISA region */ |
791 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | 725 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
792 | if (!devm_request_region(&pdev->dev, res->start, VT8231_EXTENT, | 726 | if (!request_region(res->start, VT8231_EXTENT, |
793 | vt8231_driver.driver.name)) { | 727 | vt8231_driver.driver.name)) { |
794 | dev_err(&pdev->dev, "Region 0x%lx-0x%lx already in use!\n", | 728 | dev_err(&pdev->dev, "Region 0x%lx-0x%lx already in use!\n", |
795 | (unsigned long)res->start, (unsigned long)res->end); | 729 | (unsigned long)res->start, (unsigned long)res->end); |
796 | return -ENODEV; | 730 | return -ENODEV; |
797 | } | 731 | } |
798 | 732 | ||
799 | data = devm_kzalloc(&pdev->dev, sizeof(struct vt8231_data), GFP_KERNEL); | 733 | if (!(data = kzalloc(sizeof(struct vt8231_data), GFP_KERNEL))) { |
800 | if (!data) | 734 | err = -ENOMEM; |
801 | return -ENOMEM; | 735 | goto exit_release; |
736 | } | ||
802 | 737 | ||
803 | platform_set_drvdata(pdev, data); | 738 | platform_set_drvdata(pdev, data); |
804 | data->addr = res->start; | 739 | data->addr = res->start; |
@@ -808,27 +743,24 @@ static int vt8231_probe(struct platform_device *pdev) | |||
808 | vt8231_init_device(data); | 743 | vt8231_init_device(data); |
809 | 744 | ||
810 | /* Register sysfs hooks */ | 745 | /* Register sysfs hooks */ |
811 | err = sysfs_create_group(&pdev->dev.kobj, &vt8231_group); | 746 | if ((err = sysfs_create_group(&pdev->dev.kobj, &vt8231_group))) |
812 | if (err) | 747 | goto exit_free; |
813 | return err; | ||
814 | 748 | ||
815 | /* Must update device information to find out the config field */ | 749 | /* Must update device information to find out the config field */ |
816 | data->uch_config = vt8231_read_value(data, VT8231_REG_UCH_CONFIG); | 750 | data->uch_config = vt8231_read_value(data, VT8231_REG_UCH_CONFIG); |
817 | 751 | ||
818 | for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++) { | 752 | for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++) { |
819 | if (ISTEMP(i, data->uch_config)) { | 753 | if (ISTEMP(i, data->uch_config)) { |
820 | err = sysfs_create_group(&pdev->dev.kobj, | 754 | if ((err = sysfs_create_group(&pdev->dev.kobj, |
821 | &vt8231_group_temps[i]); | 755 | &vt8231_group_temps[i]))) |
822 | if (err) | ||
823 | goto exit_remove_files; | 756 | goto exit_remove_files; |
824 | } | 757 | } |
825 | } | 758 | } |
826 | 759 | ||
827 | for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++) { | 760 | for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++) { |
828 | if (ISVOLT(i, data->uch_config)) { | 761 | if (ISVOLT(i, data->uch_config)) { |
829 | err = sysfs_create_group(&pdev->dev.kobj, | 762 | if ((err = sysfs_create_group(&pdev->dev.kobj, |
830 | &vt8231_group_volts[i]); | 763 | &vt8231_group_volts[i]))) |
831 | if (err) | ||
832 | goto exit_remove_files; | 764 | goto exit_remove_files; |
833 | } | 765 | } |
834 | } | 766 | } |
@@ -848,10 +780,17 @@ exit_remove_files: | |||
848 | sysfs_remove_group(&pdev->dev.kobj, &vt8231_group_temps[i]); | 780 | sysfs_remove_group(&pdev->dev.kobj, &vt8231_group_temps[i]); |
849 | 781 | ||
850 | sysfs_remove_group(&pdev->dev.kobj, &vt8231_group); | 782 | sysfs_remove_group(&pdev->dev.kobj, &vt8231_group); |
783 | |||
784 | exit_free: | ||
785 | platform_set_drvdata(pdev, NULL); | ||
786 | kfree(data); | ||
787 | |||
788 | exit_release: | ||
789 | release_region(res->start, VT8231_EXTENT); | ||
851 | return err; | 790 | return err; |
852 | } | 791 | } |
853 | 792 | ||
854 | static int vt8231_remove(struct platform_device *pdev) | 793 | static int __devexit vt8231_remove(struct platform_device *pdev) |
855 | { | 794 | { |
856 | struct vt8231_data *data = platform_get_drvdata(pdev); | 795 | struct vt8231_data *data = platform_get_drvdata(pdev); |
857 | int i; | 796 | int i; |
@@ -866,6 +805,9 @@ static int vt8231_remove(struct platform_device *pdev) | |||
866 | 805 | ||
867 | sysfs_remove_group(&pdev->dev.kobj, &vt8231_group); | 806 | sysfs_remove_group(&pdev->dev.kobj, &vt8231_group); |
868 | 807 | ||
808 | release_region(data->addr, VT8231_EXTENT); | ||
809 | platform_set_drvdata(pdev, NULL); | ||
810 | kfree(data); | ||
869 | return 0; | 811 | return 0; |
870 | } | 812 | } |
871 | 813 | ||
@@ -924,15 +866,17 @@ static struct vt8231_data *vt8231_update_device(struct device *dev) | |||
924 | (vt8231_read_value(data, VT8231_REG_ALARM2) << 8); | 866 | (vt8231_read_value(data, VT8231_REG_ALARM2) << 8); |
925 | 867 | ||
926 | /* Set alarm flags correctly */ | 868 | /* Set alarm flags correctly */ |
927 | if (!data->fan[0] && data->fan_min[0]) | 869 | if (!data->fan[0] && data->fan_min[0]) { |
928 | data->alarms |= 0x40; | 870 | data->alarms |= 0x40; |
929 | else if (data->fan[0] && !data->fan_min[0]) | 871 | } else if (data->fan[0] && !data->fan_min[0]) { |
930 | data->alarms &= ~0x40; | 872 | data->alarms &= ~0x40; |
873 | } | ||
931 | 874 | ||
932 | if (!data->fan[1] && data->fan_min[1]) | 875 | if (!data->fan[1] && data->fan_min[1]) { |
933 | data->alarms |= 0x80; | 876 | data->alarms |= 0x80; |
934 | else if (data->fan[1] && !data->fan_min[1]) | 877 | } else if (data->fan[1] && !data->fan_min[1]) { |
935 | data->alarms &= ~0x80; | 878 | data->alarms &= ~0x80; |
879 | } | ||
936 | 880 | ||
937 | data->last_updated = jiffies; | 881 | data->last_updated = jiffies; |
938 | data->valid = 1; | 882 | data->valid = 1; |
@@ -943,7 +887,7 @@ static struct vt8231_data *vt8231_update_device(struct device *dev) | |||
943 | return data; | 887 | return data; |
944 | } | 888 | } |
945 | 889 | ||
946 | static int vt8231_device_add(unsigned short address) | 890 | static int __devinit vt8231_device_add(unsigned short address) |
947 | { | 891 | { |
948 | struct resource res = { | 892 | struct resource res = { |
949 | .start = address, | 893 | .start = address, |
@@ -984,7 +928,7 @@ exit: | |||
984 | return err; | 928 | return err; |
985 | } | 929 | } |
986 | 930 | ||
987 | static int vt8231_pci_probe(struct pci_dev *dev, | 931 | static int __devinit vt8231_pci_probe(struct pci_dev *dev, |
988 | const struct pci_device_id *id) | 932 | const struct pci_device_id *id) |
989 | { | 933 | { |
990 | u16 address, val; | 934 | u16 address, val; |
@@ -1027,16 +971,13 @@ static int vt8231_pci_probe(struct pci_dev *dev, | |||
1027 | if (vt8231_device_add(address)) | 971 | if (vt8231_device_add(address)) |
1028 | goto exit_unregister; | 972 | goto exit_unregister; |
1029 | 973 | ||
1030 | /* | 974 | /* Always return failure here. This is to allow other drivers to bind |
1031 | * Always return failure here. This is to allow other drivers to bind | ||
1032 | * to this pci device. We don't really want to have control over the | 975 | * to this pci device. We don't really want to have control over the |
1033 | * pci device, we only wanted to read as few register values from it. | 976 | * pci device, we only wanted to read as few register values from it. |
1034 | */ | 977 | */ |
1035 | 978 | ||
1036 | /* | 979 | /* We do, however, mark ourselves as using the PCI device to stop it |
1037 | * We do, however, mark ourselves as using the PCI device to stop it | 980 | getting unloaded. */ |
1038 | * getting unloaded. | ||
1039 | */ | ||
1040 | s_bridge = pci_dev_get(dev); | 981 | s_bridge = pci_dev_get(dev); |
1041 | return -ENODEV; | 982 | return -ENODEV; |
1042 | 983 | ||