2 vt8231.c - Part of lm_sensors, Linux kernel modules
3 for hardware monitoring
5 <<<<<<< HEAD:drivers/hwmon/vt8231.c
6 Copyright (c) 2005 Roger Lucas <roger@planbit.co.uk>
8 Copyright (c) 2005 Roger Lucas <vt8231@hiddenengine.co.uk>
9 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/hwmon/vt8231.c
10 Copyright (c) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com>
11 Aaron M. Marsh <amarsh@sdf.lonestar.org>
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 /* Supports VIA VT8231 South Bridge embedded sensors
31 #include <linux/module.h>
32 #include <linux/init.h>
33 #include <linux/slab.h>
34 #include <linux/pci.h>
35 #include <linux/jiffies.h>
36 #include <linux/platform_device.h>
37 #include <linux/hwmon.h>
38 #include <linux/hwmon-sysfs.h>
39 #include <linux/hwmon-vid.h>
40 #include <linux/err.h>
41 #include <linux/mutex.h>
44 static int force_addr
;
45 module_param(force_addr
, int, 0);
46 MODULE_PARM_DESC(force_addr
, "Initialize the base address of the sensors");
48 static struct platform_device
*pdev
;
50 #define VT8231_EXTENT 0x80
51 #define VT8231_BASE_REG 0x70
52 #define VT8231_ENABLE_REG 0x74
54 /* The VT8231 registers
56 The reset value for the input channel configuration is used (Reg 0x4A=0x07)
57 which sets the selected inputs marked with '*' below if multiple options are
60 Voltage Mode Temperature Mode
61 Sensor Linux Id Linux Id VIA Id
62 -------- -------- -------- ------
71 Note that the BIOS may set the configuration register to a different value
72 to match the motherboard configuration.
75 /* fans numbered 0-1 */
76 #define VT8231_REG_FAN_MIN(nr) (0x3b + (nr))
77 #define VT8231_REG_FAN(nr) (0x29 + (nr))
79 /* Voltage inputs numbered 0-5 */
81 static const u8 regvolt
[] = { 0x21, 0x22, 0x23, 0x24, 0x25, 0x26 };
82 static const u8 regvoltmax
[] = { 0x3d, 0x2b, 0x2d, 0x2f, 0x31, 0x33 };
83 static const u8 regvoltmin
[] = { 0x3e, 0x2c, 0x2e, 0x30, 0x32, 0x34 };
85 /* Temperatures are numbered 1-6 according to the Linux kernel specification.
87 ** In the VIA datasheet, however, the temperatures are numbered from zero.
88 ** Since it is important that this driver can easily be compared to the VIA
89 ** datasheet, we will use the VIA numbering within this driver and map the
90 ** kernel sysfs device name to the VIA number in the sysfs callback.
93 #define VT8231_REG_TEMP_LOW01 0x49
94 #define VT8231_REG_TEMP_LOW25 0x4d
96 static const u8 regtemp
[] = { 0x1f, 0x21, 0x22, 0x23, 0x24, 0x25 };
97 static const u8 regtempmax
[] = { 0x39, 0x3d, 0x2b, 0x2d, 0x2f, 0x31 };
98 static const u8 regtempmin
[] = { 0x3a, 0x3e, 0x2c, 0x2e, 0x30, 0x32 };
100 #define TEMP_FROM_REG(reg) (((253 * 4 - (reg)) * 550 + 105) / 210)
101 #define TEMP_MAXMIN_FROM_REG(reg) (((253 - (reg)) * 2200 + 105) / 210)
102 #define TEMP_MAXMIN_TO_REG(val) (253 - ((val) * 210 + 1100) / 2200)
104 #define VT8231_REG_CONFIG 0x40
105 #define VT8231_REG_ALARM1 0x41
106 #define VT8231_REG_ALARM2 0x42
107 #define VT8231_REG_FANDIV 0x47
108 #define VT8231_REG_UCH_CONFIG 0x4a
109 #define VT8231_REG_TEMP1_CONFIG 0x4b
110 #define VT8231_REG_TEMP2_CONFIG 0x4c
112 /* temps 0-5 as numbered in VIA datasheet - see later for mapping to Linux
115 #define ISTEMP(i, ch_config) ((i) == 0 ? 1 : \
116 ((ch_config) >> ((i)+1)) & 0x01)
118 #define ISVOLT(i, ch_config) ((i) == 5 ? 1 : \
119 !(((ch_config) >> ((i)+2)) & 0x01))
121 #define DIV_FROM_REG(val) (1 << (val))
123 /* NB The values returned here are NOT temperatures. The calibration curves
124 ** for the thermistor curves are board-specific and must go in the
125 ** sensors.conf file. Temperature sensors are actually ten bits, but the
126 ** VIA datasheet only considers the 8 MSBs obtained from the regtemp[]
127 ** register. The temperature value returned should have a magnitude of 3,
128 ** so we use the VIA scaling as the "true" scaling and use the remaining 2
129 ** LSBs as fractional precision.
131 ** All the on-chip hardware temperature comparisons for the alarms are only
132 ** 8-bits wide, and compare against the 8 MSBs of the temperature. The bits
133 ** in the registers VT8231_REG_TEMP_LOW01 and VT8231_REG_TEMP_LOW25 are
137 /******** FAN RPM CONVERSIONS ********
138 ** This chip saturates back at 0, not at 255 like many the other chips.
141 static inline u8
FAN_TO_REG(long rpm
, int div
)
145 return SENSORS_LIMIT(1310720 / (rpm
* div
), 1, 255);
148 #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : 1310720 / ((val) * (div)))
154 struct mutex update_lock
;
155 struct device
*hwmon_dev
;
156 char valid
; /* !=0 if following fields are valid */
157 unsigned long last_updated
; /* In jiffies */
159 u8 in
[6]; /* Register value */
160 u8 in_max
[6]; /* Register value */
161 u8 in_min
[6]; /* Register value */
162 u16 temp
[6]; /* Register value 10 bit, right aligned */
163 u8 temp_max
[6]; /* Register value */
164 u8 temp_min
[6]; /* Register value */
165 u8 fan
[2]; /* Register value */
166 u8 fan_min
[2]; /* Register value */
167 u8 fan_div
[2]; /* Register encoding, shifted right */
168 u16 alarms
; /* Register encoding */
172 static struct pci_dev
*s_bridge
;
173 static int vt8231_probe(struct platform_device
*pdev
);
174 static int __devexit
vt8231_remove(struct platform_device
*pdev
);
175 static struct vt8231_data
*vt8231_update_device(struct device
*dev
);
176 static void vt8231_init_device(struct vt8231_data
*data
);
178 static inline int vt8231_read_value(struct vt8231_data
*data
, u8 reg
)
180 return inb_p(data
->addr
+ reg
);
183 static inline void vt8231_write_value(struct vt8231_data
*data
, u8 reg
,
186 outb_p(value
, data
->addr
+ reg
);
189 /* following are the sysfs callback functions */
190 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*attr
,
193 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
194 int nr
= sensor_attr
->index
;
195 struct vt8231_data
*data
= vt8231_update_device(dev
);
197 return sprintf(buf
, "%d\n", ((data
->in
[nr
] - 3) * 10000) / 958);
200 static ssize_t
show_in_min(struct device
*dev
, struct device_attribute
*attr
,
203 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
204 int nr
= sensor_attr
->index
;
205 struct vt8231_data
*data
= vt8231_update_device(dev
);
207 return sprintf(buf
, "%d\n", ((data
->in_min
[nr
] - 3) * 10000) / 958);
210 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
*attr
,
213 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
214 int nr
= sensor_attr
->index
;
215 struct vt8231_data
*data
= vt8231_update_device(dev
);
217 return sprintf(buf
, "%d\n", (((data
->in_max
[nr
] - 3) * 10000) / 958));
220 static ssize_t
set_in_min(struct device
*dev
, struct device_attribute
*attr
,
221 const char *buf
, size_t count
)
223 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
224 int nr
= sensor_attr
->index
;
225 struct vt8231_data
*data
= dev_get_drvdata(dev
);
226 unsigned long val
= simple_strtoul(buf
, NULL
, 10);
228 mutex_lock(&data
->update_lock
);
229 data
->in_min
[nr
] = SENSORS_LIMIT(((val
* 958) / 10000) + 3, 0, 255);
230 vt8231_write_value(data
, regvoltmin
[nr
], data
->in_min
[nr
]);
231 mutex_unlock(&data
->update_lock
);
235 static ssize_t
set_in_max(struct device
*dev
, struct device_attribute
*attr
,
236 const char *buf
, size_t count
)
238 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
239 int nr
= sensor_attr
->index
;
240 struct vt8231_data
*data
= dev_get_drvdata(dev
);
241 unsigned long val
= simple_strtoul(buf
, NULL
, 10);
243 mutex_lock(&data
->update_lock
);
244 data
->in_max
[nr
] = SENSORS_LIMIT(((val
* 958) / 10000) + 3, 0, 255);
245 vt8231_write_value(data
, regvoltmax
[nr
], data
->in_max
[nr
]);
246 mutex_unlock(&data
->update_lock
);
250 /* Special case for input 5 as this has 3.3V scaling built into the chip */
251 static ssize_t
show_in5(struct device
*dev
, struct device_attribute
*attr
,
254 struct vt8231_data
*data
= vt8231_update_device(dev
);
256 return sprintf(buf
, "%d\n",
257 (((data
->in
[5] - 3) * 10000 * 54) / (958 * 34)));
260 static ssize_t
show_in5_min(struct device
*dev
, struct device_attribute
*attr
,
263 struct vt8231_data
*data
= vt8231_update_device(dev
);
265 return sprintf(buf
, "%d\n",
266 (((data
->in_min
[5] - 3) * 10000 * 54) / (958 * 34)));
269 static ssize_t
show_in5_max(struct device
*dev
, struct device_attribute
*attr
,
272 struct vt8231_data
*data
= vt8231_update_device(dev
);
274 return sprintf(buf
, "%d\n",
275 (((data
->in_max
[5] - 3) * 10000 * 54) / (958 * 34)));
278 static ssize_t
set_in5_min(struct device
*dev
, struct device_attribute
*attr
,
279 const char *buf
, size_t count
)
281 struct vt8231_data
*data
= dev_get_drvdata(dev
);
282 unsigned long val
= simple_strtoul(buf
, NULL
, 10);
284 mutex_lock(&data
->update_lock
);
285 data
->in_min
[5] = SENSORS_LIMIT(((val
* 958 * 34) / (10000 * 54)) + 3,
287 vt8231_write_value(data
, regvoltmin
[5], data
->in_min
[5]);
288 mutex_unlock(&data
->update_lock
);
292 static ssize_t
set_in5_max(struct device
*dev
, struct device_attribute
*attr
,
293 const char *buf
, size_t count
)
295 struct vt8231_data
*data
= dev_get_drvdata(dev
);
296 unsigned long val
= simple_strtoul(buf
, NULL
, 10);
298 mutex_lock(&data
->update_lock
);
299 data
->in_max
[5] = SENSORS_LIMIT(((val
* 958 * 34) / (10000 * 54)) + 3,
301 vt8231_write_value(data
, regvoltmax
[5], data
->in_max
[5]);
302 mutex_unlock(&data
->update_lock
);
306 #define define_voltage_sysfs(offset) \
307 static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
308 show_in, NULL, offset); \
309 static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
310 show_in_min, set_in_min, offset); \
311 static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
312 show_in_max, set_in_max, offset)
314 define_voltage_sysfs(0);
315 define_voltage_sysfs(1);
316 define_voltage_sysfs(2);
317 define_voltage_sysfs(3);
318 define_voltage_sysfs(4);
320 static DEVICE_ATTR(in5_input
, S_IRUGO
, show_in5
, NULL
);
321 static DEVICE_ATTR(in5_min
, S_IRUGO
| S_IWUSR
, show_in5_min
, set_in5_min
);
322 static DEVICE_ATTR(in5_max
, S_IRUGO
| S_IWUSR
, show_in5_max
, set_in5_max
);
325 static ssize_t
show_temp0(struct device
*dev
, struct device_attribute
*attr
,
328 struct vt8231_data
*data
= vt8231_update_device(dev
);
329 return sprintf(buf
, "%d\n", data
->temp
[0] * 250);
332 static ssize_t
show_temp0_max(struct device
*dev
, struct device_attribute
*attr
,
335 struct vt8231_data
*data
= vt8231_update_device(dev
);
336 return sprintf(buf
, "%d\n", data
->temp_max
[0] * 1000);
339 static ssize_t
show_temp0_min(struct device
*dev
, struct device_attribute
*attr
,
342 struct vt8231_data
*data
= vt8231_update_device(dev
);
343 return sprintf(buf
, "%d\n", data
->temp_min
[0] * 1000);
346 static ssize_t
set_temp0_max(struct device
*dev
, struct device_attribute
*attr
,
347 const char *buf
, size_t count
)
349 struct vt8231_data
*data
= dev_get_drvdata(dev
);
350 int val
= simple_strtol(buf
, NULL
, 10);
352 mutex_lock(&data
->update_lock
);
353 data
->temp_max
[0] = SENSORS_LIMIT((val
+ 500) / 1000, 0, 255);
354 vt8231_write_value(data
, regtempmax
[0], data
->temp_max
[0]);
355 mutex_unlock(&data
->update_lock
);
358 static ssize_t
set_temp0_min(struct device
*dev
, struct device_attribute
*attr
,
359 const char *buf
, size_t count
)
361 struct vt8231_data
*data
= dev_get_drvdata(dev
);
362 int val
= simple_strtol(buf
, NULL
, 10);
364 mutex_lock(&data
->update_lock
);
365 data
->temp_min
[0] = SENSORS_LIMIT((val
+ 500) / 1000, 0, 255);
366 vt8231_write_value(data
, regtempmin
[0], data
->temp_min
[0]);
367 mutex_unlock(&data
->update_lock
);
371 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
*attr
,
374 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
375 int nr
= sensor_attr
->index
;
376 struct vt8231_data
*data
= vt8231_update_device(dev
);
377 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp
[nr
]));
380 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
*attr
,
383 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
384 int nr
= sensor_attr
->index
;
385 struct vt8231_data
*data
= vt8231_update_device(dev
);
386 return sprintf(buf
, "%d\n", TEMP_MAXMIN_FROM_REG(data
->temp_max
[nr
]));
389 static ssize_t
show_temp_min(struct device
*dev
, struct device_attribute
*attr
,
392 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
393 int nr
= sensor_attr
->index
;
394 struct vt8231_data
*data
= vt8231_update_device(dev
);
395 return sprintf(buf
, "%d\n", TEMP_MAXMIN_FROM_REG(data
->temp_min
[nr
]));
398 static ssize_t
set_temp_max(struct device
*dev
, struct device_attribute
*attr
,
399 const char *buf
, size_t count
)
401 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
402 int nr
= sensor_attr
->index
;
403 struct vt8231_data
*data
= dev_get_drvdata(dev
);
404 int val
= simple_strtol(buf
, NULL
, 10);
406 mutex_lock(&data
->update_lock
);
407 data
->temp_max
[nr
] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val
), 0, 255);
408 vt8231_write_value(data
, regtempmax
[nr
], data
->temp_max
[nr
]);
409 mutex_unlock(&data
->update_lock
);
412 static ssize_t
set_temp_min(struct device
*dev
, struct device_attribute
*attr
,
413 const char *buf
, size_t count
)
415 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
416 int nr
= sensor_attr
->index
;
417 struct vt8231_data
*data
= dev_get_drvdata(dev
);
418 int val
= simple_strtol(buf
, NULL
, 10);
420 mutex_lock(&data
->update_lock
);
421 data
->temp_min
[nr
] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val
), 0, 255);
422 vt8231_write_value(data
, regtempmin
[nr
], data
->temp_min
[nr
]);
423 mutex_unlock(&data
->update_lock
);
427 /* Note that these map the Linux temperature sensor numbering (1-6) to the VIA
428 ** temperature sensor numbering (0-5)
430 #define define_temperature_sysfs(offset) \
431 static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
432 show_temp, NULL, offset - 1); \
433 static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
434 show_temp_max, set_temp_max, offset - 1); \
435 static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \
436 show_temp_min, set_temp_min, offset - 1)
438 static DEVICE_ATTR(temp1_input
, S_IRUGO
, show_temp0
, NULL
);
439 static DEVICE_ATTR(temp1_max
, S_IRUGO
| S_IWUSR
, show_temp0_max
, set_temp0_max
);
440 static DEVICE_ATTR(temp1_max_hyst
, S_IRUGO
| S_IWUSR
, show_temp0_min
, set_temp0_min
);
442 define_temperature_sysfs(2);
443 define_temperature_sysfs(3);
444 define_temperature_sysfs(4);
445 define_temperature_sysfs(5);
446 define_temperature_sysfs(6);
449 static ssize_t
show_fan(struct device
*dev
, struct device_attribute
*attr
,
452 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
453 int nr
= sensor_attr
->index
;
454 struct vt8231_data
*data
= vt8231_update_device(dev
);
455 return sprintf(buf
, "%d\n", FAN_FROM_REG(data
->fan
[nr
],
456 DIV_FROM_REG(data
->fan_div
[nr
])));
459 static ssize_t
show_fan_min(struct device
*dev
, struct device_attribute
*attr
,
462 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
463 int nr
= sensor_attr
->index
;
464 struct vt8231_data
*data
= vt8231_update_device(dev
);
465 return sprintf(buf
, "%d\n", FAN_FROM_REG(data
->fan_min
[nr
],
466 DIV_FROM_REG(data
->fan_div
[nr
])));
469 static ssize_t
show_fan_div(struct device
*dev
, struct device_attribute
*attr
,
472 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
473 int nr
= sensor_attr
->index
;
474 struct vt8231_data
*data
= vt8231_update_device(dev
);
475 return sprintf(buf
, "%d\n", DIV_FROM_REG(data
->fan_div
[nr
]));
478 static ssize_t
set_fan_min(struct device
*dev
, struct device_attribute
*attr
,
479 const char *buf
, size_t count
)
481 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
482 int nr
= sensor_attr
->index
;
483 struct vt8231_data
*data
= dev_get_drvdata(dev
);
484 int val
= simple_strtoul(buf
, NULL
, 10);
486 mutex_lock(&data
->update_lock
);
487 data
->fan_min
[nr
] = FAN_TO_REG(val
, DIV_FROM_REG(data
->fan_div
[nr
]));
488 vt8231_write_value(data
, VT8231_REG_FAN_MIN(nr
), data
->fan_min
[nr
]);
489 mutex_unlock(&data
->update_lock
);
493 static ssize_t
set_fan_div(struct device
*dev
, struct device_attribute
*attr
,
494 const char *buf
, size_t count
)
496 struct vt8231_data
*data
= dev_get_drvdata(dev
);
497 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
498 unsigned long val
= simple_strtoul(buf
, NULL
, 10);
499 int nr
= sensor_attr
->index
;
500 int old
= vt8231_read_value(data
, VT8231_REG_FANDIV
);
501 long min
= FAN_FROM_REG(data
->fan_min
[nr
],
502 DIV_FROM_REG(data
->fan_div
[nr
]));
504 mutex_lock(&data
->update_lock
);
506 case 1: data
->fan_div
[nr
] = 0; break;
507 case 2: data
->fan_div
[nr
] = 1; break;
508 case 4: data
->fan_div
[nr
] = 2; break;
509 case 8: data
->fan_div
[nr
] = 3; break;
511 dev_err(dev
, "fan_div value %ld not supported. "
512 "Choose one of 1, 2, 4 or 8!\n", val
);
513 mutex_unlock(&data
->update_lock
);
517 /* Correct the fan minimum speed */
518 data
->fan_min
[nr
] = FAN_TO_REG(min
, DIV_FROM_REG(data
->fan_div
[nr
]));
519 vt8231_write_value(data
, VT8231_REG_FAN_MIN(nr
), data
->fan_min
[nr
]);
521 old
= (old
& 0x0f) | (data
->fan_div
[1] << 6) | (data
->fan_div
[0] << 4);
522 vt8231_write_value(data
, VT8231_REG_FANDIV
, old
);
523 mutex_unlock(&data
->update_lock
);
528 #define define_fan_sysfs(offset) \
529 static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
530 show_fan, NULL, offset - 1); \
531 static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
532 show_fan_div, set_fan_div, offset - 1); \
533 static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
534 show_fan_min, set_fan_min, offset - 1)
540 static ssize_t
show_alarms(struct device
*dev
, struct device_attribute
*attr
,
543 struct vt8231_data
*data
= vt8231_update_device(dev
);
544 return sprintf(buf
, "%d\n", data
->alarms
);
546 static DEVICE_ATTR(alarms
, S_IRUGO
, show_alarms
, NULL
);
548 <<<<<<< HEAD
:drivers
/hwmon
/vt8231
.c
550 static ssize_t
show_alarm(struct device
*dev
, struct device_attribute
*attr
,
553 int bitnr
= to_sensor_dev_attr(attr
)->index
;
554 struct vt8231_data
*data
= vt8231_update_device(dev
);
555 return sprintf(buf
, "%u\n", (data
->alarms
>> bitnr
) & 1);
557 static SENSOR_DEVICE_ATTR(temp1_alarm
, S_IRUGO
, show_alarm
, NULL
, 4);
558 static SENSOR_DEVICE_ATTR(temp2_alarm
, S_IRUGO
, show_alarm
, NULL
, 11);
559 static SENSOR_DEVICE_ATTR(temp3_alarm
, S_IRUGO
, show_alarm
, NULL
, 0);
560 static SENSOR_DEVICE_ATTR(temp4_alarm
, S_IRUGO
, show_alarm
, NULL
, 1);
561 static SENSOR_DEVICE_ATTR(temp5_alarm
, S_IRUGO
, show_alarm
, NULL
, 3);
562 static SENSOR_DEVICE_ATTR(temp6_alarm
, S_IRUGO
, show_alarm
, NULL
, 8);
563 static SENSOR_DEVICE_ATTR(in0_alarm
, S_IRUGO
, show_alarm
, NULL
, 11);
564 static SENSOR_DEVICE_ATTR(in1_alarm
, S_IRUGO
, show_alarm
, NULL
, 0);
565 static SENSOR_DEVICE_ATTR(in2_alarm
, S_IRUGO
, show_alarm
, NULL
, 1);
566 static SENSOR_DEVICE_ATTR(in3_alarm
, S_IRUGO
, show_alarm
, NULL
, 3);
567 static SENSOR_DEVICE_ATTR(in4_alarm
, S_IRUGO
, show_alarm
, NULL
, 8);
568 static SENSOR_DEVICE_ATTR(in5_alarm
, S_IRUGO
, show_alarm
, NULL
, 2);
569 static SENSOR_DEVICE_ATTR(fan1_alarm
, S_IRUGO
, show_alarm
, NULL
, 6);
570 static SENSOR_DEVICE_ATTR(fan2_alarm
, S_IRUGO
, show_alarm
, NULL
, 7);
572 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/hwmon
/vt8231
.c
573 static ssize_t
show_name(struct device
*dev
, struct device_attribute
576 struct vt8231_data
*data
= dev_get_drvdata(dev
);
577 return sprintf(buf
, "%s\n", data
->name
);
579 static DEVICE_ATTR(name
, S_IRUGO
, show_name
, NULL
);
581 <<<<<<< HEAD
:drivers
/hwmon
/vt8231
.c
582 static struct attribute
*vt8231_attributes_temps
[6][4] = {
584 static struct attribute
*vt8231_attributes_temps
[6][5] = {
585 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/hwmon
/vt8231
.c
587 &dev_attr_temp1_input
.attr
,
588 &dev_attr_temp1_max_hyst
.attr
,
589 &dev_attr_temp1_max
.attr
,
590 <<<<<<< HEAD
:drivers
/hwmon
/vt8231
.c
592 &sensor_dev_attr_temp1_alarm
.dev_attr
.attr
,
593 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/hwmon
/vt8231
.c
596 &sensor_dev_attr_temp2_input
.dev_attr
.attr
,
597 &sensor_dev_attr_temp2_max_hyst
.dev_attr
.attr
,
598 &sensor_dev_attr_temp2_max
.dev_attr
.attr
,
599 <<<<<<< HEAD
:drivers
/hwmon
/vt8231
.c
601 &sensor_dev_attr_temp2_alarm
.dev_attr
.attr
,
602 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/hwmon
/vt8231
.c
605 &sensor_dev_attr_temp3_input
.dev_attr
.attr
,
606 &sensor_dev_attr_temp3_max_hyst
.dev_attr
.attr
,
607 &sensor_dev_attr_temp3_max
.dev_attr
.attr
,
608 <<<<<<< HEAD
:drivers
/hwmon
/vt8231
.c
610 &sensor_dev_attr_temp3_alarm
.dev_attr
.attr
,
611 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/hwmon
/vt8231
.c
614 &sensor_dev_attr_temp4_input
.dev_attr
.attr
,
615 &sensor_dev_attr_temp4_max_hyst
.dev_attr
.attr
,
616 &sensor_dev_attr_temp4_max
.dev_attr
.attr
,
617 <<<<<<< HEAD
:drivers
/hwmon
/vt8231
.c
619 &sensor_dev_attr_temp4_alarm
.dev_attr
.attr
,
620 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/hwmon
/vt8231
.c
623 &sensor_dev_attr_temp5_input
.dev_attr
.attr
,
624 &sensor_dev_attr_temp5_max_hyst
.dev_attr
.attr
,
625 &sensor_dev_attr_temp5_max
.dev_attr
.attr
,
626 <<<<<<< HEAD
:drivers
/hwmon
/vt8231
.c
628 &sensor_dev_attr_temp5_alarm
.dev_attr
.attr
,
629 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/hwmon
/vt8231
.c
632 &sensor_dev_attr_temp6_input
.dev_attr
.attr
,
633 &sensor_dev_attr_temp6_max_hyst
.dev_attr
.attr
,
634 &sensor_dev_attr_temp6_max
.dev_attr
.attr
,
635 <<<<<<< HEAD
:drivers
/hwmon
/vt8231
.c
637 &sensor_dev_attr_temp6_alarm
.dev_attr
.attr
,
638 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/hwmon
/vt8231
.c
643 static const struct attribute_group vt8231_group_temps
[6] = {
644 { .attrs
= vt8231_attributes_temps
[0] },
645 { .attrs
= vt8231_attributes_temps
[1] },
646 { .attrs
= vt8231_attributes_temps
[2] },
647 { .attrs
= vt8231_attributes_temps
[3] },
648 { .attrs
= vt8231_attributes_temps
[4] },
649 { .attrs
= vt8231_attributes_temps
[5] },
652 <<<<<<< HEAD
:drivers
/hwmon
/vt8231
.c
653 static struct attribute
*vt8231_attributes_volts
[6][4] = {
655 static struct attribute
*vt8231_attributes_volts
[6][5] = {
656 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/hwmon
/vt8231
.c
658 &sensor_dev_attr_in0_input
.dev_attr
.attr
,
659 &sensor_dev_attr_in0_min
.dev_attr
.attr
,
660 &sensor_dev_attr_in0_max
.dev_attr
.attr
,
661 <<<<<<< HEAD
:drivers
/hwmon
/vt8231
.c
663 &sensor_dev_attr_in0_alarm
.dev_attr
.attr
,
664 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/hwmon
/vt8231
.c
667 &sensor_dev_attr_in1_input
.dev_attr
.attr
,
668 &sensor_dev_attr_in1_min
.dev_attr
.attr
,
669 &sensor_dev_attr_in1_max
.dev_attr
.attr
,
670 <<<<<<< HEAD
:drivers
/hwmon
/vt8231
.c
672 &sensor_dev_attr_in1_alarm
.dev_attr
.attr
,
673 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/hwmon
/vt8231
.c
676 &sensor_dev_attr_in2_input
.dev_attr
.attr
,
677 &sensor_dev_attr_in2_min
.dev_attr
.attr
,
678 &sensor_dev_attr_in2_max
.dev_attr
.attr
,
679 <<<<<<< HEAD
:drivers
/hwmon
/vt8231
.c
681 &sensor_dev_attr_in2_alarm
.dev_attr
.attr
,
682 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/hwmon
/vt8231
.c
685 &sensor_dev_attr_in3_input
.dev_attr
.attr
,
686 &sensor_dev_attr_in3_min
.dev_attr
.attr
,
687 &sensor_dev_attr_in3_max
.dev_attr
.attr
,
688 <<<<<<< HEAD
:drivers
/hwmon
/vt8231
.c
690 &sensor_dev_attr_in3_alarm
.dev_attr
.attr
,
691 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/hwmon
/vt8231
.c
694 &sensor_dev_attr_in4_input
.dev_attr
.attr
,
695 &sensor_dev_attr_in4_min
.dev_attr
.attr
,
696 &sensor_dev_attr_in4_max
.dev_attr
.attr
,
697 <<<<<<< HEAD
:drivers
/hwmon
/vt8231
.c
699 &sensor_dev_attr_in4_alarm
.dev_attr
.attr
,
700 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/hwmon
/vt8231
.c
703 &dev_attr_in5_input
.attr
,
704 &dev_attr_in5_min
.attr
,
705 &dev_attr_in5_max
.attr
,
706 <<<<<<< HEAD
:drivers
/hwmon
/vt8231
.c
708 &sensor_dev_attr_in5_alarm
.dev_attr
.attr
,
709 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/hwmon
/vt8231
.c
714 static const struct attribute_group vt8231_group_volts
[6] = {
715 { .attrs
= vt8231_attributes_volts
[0] },
716 { .attrs
= vt8231_attributes_volts
[1] },
717 { .attrs
= vt8231_attributes_volts
[2] },
718 { .attrs
= vt8231_attributes_volts
[3] },
719 { .attrs
= vt8231_attributes_volts
[4] },
720 { .attrs
= vt8231_attributes_volts
[5] },
723 static struct attribute
*vt8231_attributes
[] = {
724 &sensor_dev_attr_fan1_input
.dev_attr
.attr
,
725 &sensor_dev_attr_fan2_input
.dev_attr
.attr
,
726 &sensor_dev_attr_fan1_min
.dev_attr
.attr
,
727 &sensor_dev_attr_fan2_min
.dev_attr
.attr
,
728 &sensor_dev_attr_fan1_div
.dev_attr
.attr
,
729 &sensor_dev_attr_fan2_div
.dev_attr
.attr
,
730 <<<<<<< HEAD
:drivers
/hwmon
/vt8231
.c
732 &sensor_dev_attr_fan1_alarm
.dev_attr
.attr
,
733 &sensor_dev_attr_fan2_alarm
.dev_attr
.attr
,
734 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/hwmon
/vt8231
.c
735 &dev_attr_alarms
.attr
,
740 static const struct attribute_group vt8231_group
= {
741 .attrs
= vt8231_attributes
,
744 static struct platform_driver vt8231_driver
= {
746 .owner
= THIS_MODULE
,
749 .probe
= vt8231_probe
,
750 .remove
= __devexit_p(vt8231_remove
),
753 static struct pci_device_id vt8231_pci_ids
[] = {
754 { PCI_DEVICE(PCI_VENDOR_ID_VIA
, PCI_DEVICE_ID_VIA_8231_4
) },
758 MODULE_DEVICE_TABLE(pci
, vt8231_pci_ids
);
760 static int __devinit
vt8231_pci_probe(struct pci_dev
*dev
,
761 const struct pci_device_id
*id
);
763 static struct pci_driver vt8231_pci_driver
= {
765 .id_table
= vt8231_pci_ids
,
766 .probe
= vt8231_pci_probe
,
769 static int vt8231_probe(struct platform_device
*pdev
)
771 struct resource
*res
;
772 struct vt8231_data
*data
;
775 /* Reserve the ISA region */
776 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
777 if (!request_region(res
->start
, VT8231_EXTENT
,
778 vt8231_driver
.driver
.name
)) {
779 dev_err(&pdev
->dev
, "Region 0x%lx-0x%lx already in use!\n",
780 (unsigned long)res
->start
, (unsigned long)res
->end
);
784 if (!(data
= kzalloc(sizeof(struct vt8231_data
), GFP_KERNEL
))) {
789 platform_set_drvdata(pdev
, data
);
790 data
->addr
= res
->start
;
791 data
->name
= "vt8231";
793 mutex_init(&data
->update_lock
);
794 vt8231_init_device(data
);
796 /* Register sysfs hooks */
797 if ((err
= sysfs_create_group(&pdev
->dev
.kobj
, &vt8231_group
)))
800 /* Must update device information to find out the config field */
801 data
->uch_config
= vt8231_read_value(data
, VT8231_REG_UCH_CONFIG
);
803 for (i
= 0; i
< ARRAY_SIZE(vt8231_group_temps
); i
++) {
804 if (ISTEMP(i
, data
->uch_config
)) {
805 if ((err
= sysfs_create_group(&pdev
->dev
.kobj
,
806 &vt8231_group_temps
[i
])))
807 goto exit_remove_files
;
811 for (i
= 0; i
< ARRAY_SIZE(vt8231_group_volts
); i
++) {
812 if (ISVOLT(i
, data
->uch_config
)) {
813 if ((err
= sysfs_create_group(&pdev
->dev
.kobj
,
814 &vt8231_group_volts
[i
])))
815 goto exit_remove_files
;
819 data
->hwmon_dev
= hwmon_device_register(&pdev
->dev
);
820 if (IS_ERR(data
->hwmon_dev
)) {
821 err
= PTR_ERR(data
->hwmon_dev
);
822 goto exit_remove_files
;
827 for (i
= 0; i
< ARRAY_SIZE(vt8231_group_volts
); i
++)
828 sysfs_remove_group(&pdev
->dev
.kobj
, &vt8231_group_volts
[i
]);
830 for (i
= 0; i
< ARRAY_SIZE(vt8231_group_temps
); i
++)
831 sysfs_remove_group(&pdev
->dev
.kobj
, &vt8231_group_temps
[i
]);
833 sysfs_remove_group(&pdev
->dev
.kobj
, &vt8231_group
);
836 platform_set_drvdata(pdev
, NULL
);
840 release_region(res
->start
, VT8231_EXTENT
);
844 static int __devexit
vt8231_remove(struct platform_device
*pdev
)
846 struct vt8231_data
*data
= platform_get_drvdata(pdev
);
849 hwmon_device_unregister(data
->hwmon_dev
);
851 for (i
= 0; i
< ARRAY_SIZE(vt8231_group_volts
); i
++)
852 sysfs_remove_group(&pdev
->dev
.kobj
, &vt8231_group_volts
[i
]);
854 for (i
= 0; i
< ARRAY_SIZE(vt8231_group_temps
); i
++)
855 sysfs_remove_group(&pdev
->dev
.kobj
, &vt8231_group_temps
[i
]);
857 sysfs_remove_group(&pdev
->dev
.kobj
, &vt8231_group
);
859 release_region(data
->addr
, VT8231_EXTENT
);
860 platform_set_drvdata(pdev
, NULL
);
865 static void vt8231_init_device(struct vt8231_data
*data
)
867 vt8231_write_value(data
, VT8231_REG_TEMP1_CONFIG
, 0);
868 vt8231_write_value(data
, VT8231_REG_TEMP2_CONFIG
, 0);
871 static struct vt8231_data
*vt8231_update_device(struct device
*dev
)
873 struct vt8231_data
*data
= dev_get_drvdata(dev
);
877 mutex_lock(&data
->update_lock
);
879 if (time_after(jiffies
, data
->last_updated
+ HZ
+ HZ
/ 2)
881 for (i
= 0; i
< 6; i
++) {
882 if (ISVOLT(i
, data
->uch_config
)) {
883 data
->in
[i
] = vt8231_read_value(data
,
885 data
->in_min
[i
] = vt8231_read_value(data
,
887 data
->in_max
[i
] = vt8231_read_value(data
,
891 for (i
= 0; i
< 2; i
++) {
892 data
->fan
[i
] = vt8231_read_value(data
,
894 data
->fan_min
[i
] = vt8231_read_value(data
,
895 VT8231_REG_FAN_MIN(i
));
898 low
= vt8231_read_value(data
, VT8231_REG_TEMP_LOW01
);
899 low
= (low
>> 6) | ((low
& 0x30) >> 2)
900 | (vt8231_read_value(data
, VT8231_REG_TEMP_LOW25
) << 4);
901 for (i
= 0; i
< 6; i
++) {
902 if (ISTEMP(i
, data
->uch_config
)) {
903 data
->temp
[i
] = (vt8231_read_value(data
,
905 | ((low
>> (2 * i
)) & 0x03);
906 data
->temp_max
[i
] = vt8231_read_value(data
,
908 data
->temp_min
[i
] = vt8231_read_value(data
,
913 i
= vt8231_read_value(data
, VT8231_REG_FANDIV
);
914 data
->fan_div
[0] = (i
>> 4) & 0x03;
915 data
->fan_div
[1] = i
>> 6;
916 data
->alarms
= vt8231_read_value(data
, VT8231_REG_ALARM1
) |
917 (vt8231_read_value(data
, VT8231_REG_ALARM2
) << 8);
919 /* Set alarm flags correctly */
920 if (!data
->fan
[0] && data
->fan_min
[0]) {
921 data
->alarms
|= 0x40;
922 } else if (data
->fan
[0] && !data
->fan_min
[0]) {
923 data
->alarms
&= ~0x40;
926 if (!data
->fan
[1] && data
->fan_min
[1]) {
927 data
->alarms
|= 0x80;
928 } else if (data
->fan
[1] && !data
->fan_min
[1]) {
929 data
->alarms
&= ~0x80;
932 data
->last_updated
= jiffies
;
936 mutex_unlock(&data
->update_lock
);
941 static int __devinit
vt8231_device_add(unsigned short address
)
943 struct resource res
= {
945 .end
= address
+ VT8231_EXTENT
- 1,
947 .flags
= IORESOURCE_IO
,
951 pdev
= platform_device_alloc("vt8231", address
);
954 printk(KERN_ERR
"vt8231: Device allocation failed\n");
958 err
= platform_device_add_resources(pdev
, &res
, 1);
960 printk(KERN_ERR
"vt8231: Device resource addition failed "
962 goto exit_device_put
;
965 err
= platform_device_add(pdev
);
967 printk(KERN_ERR
"vt8231: Device addition failed (%d)\n",
969 goto exit_device_put
;
975 platform_device_put(pdev
);
980 static int __devinit
vt8231_pci_probe(struct pci_dev
*dev
,
981 const struct pci_device_id
*id
)
985 address
= force_addr
& 0xff00;
986 dev_warn(&dev
->dev
, "Forcing ISA address 0x%x\n",
989 if (PCIBIOS_SUCCESSFUL
!=
990 pci_write_config_word(dev
, VT8231_BASE_REG
, address
| 1))
994 if (PCIBIOS_SUCCESSFUL
!= pci_read_config_word(dev
, VT8231_BASE_REG
,
998 address
= val
& ~(VT8231_EXTENT
- 1);
1000 dev_err(&dev
->dev
, "base address not set -\
1001 upgrade BIOS or use force_addr=0xaddr\n");
1005 if (PCIBIOS_SUCCESSFUL
!= pci_read_config_word(dev
, VT8231_ENABLE_REG
,
1009 if (!(val
& 0x0001)) {
1010 dev_warn(&dev
->dev
, "enabling sensors\n");
1011 if (PCIBIOS_SUCCESSFUL
!=
1012 pci_write_config_word(dev
, VT8231_ENABLE_REG
,
1017 if (platform_driver_register(&vt8231_driver
))
1020 /* Sets global pdev as a side effect */
1021 if (vt8231_device_add(address
))
1022 goto exit_unregister
;
1024 /* Always return failure here. This is to allow other drivers to bind
1025 * to this pci device. We don't really want to have control over the
1026 * pci device, we only wanted to read as few register values from it.
1029 /* We do, however, mark ourselves as using the PCI device to stop it
1030 getting unloaded. */
1031 s_bridge
= pci_dev_get(dev
);
1035 platform_driver_unregister(&vt8231_driver
);
1040 static int __init
sm_vt8231_init(void)
1042 return pci_register_driver(&vt8231_pci_driver
);
1045 static void __exit
sm_vt8231_exit(void)
1047 pci_unregister_driver(&vt8231_pci_driver
);
1048 if (s_bridge
!= NULL
) {
1049 platform_device_unregister(pdev
);
1050 platform_driver_unregister(&vt8231_driver
);
1051 pci_dev_put(s_bridge
);
1056 <<<<<<< HEAD
:drivers
/hwmon
/vt8231
.c
1057 MODULE_AUTHOR("Roger Lucas <roger@planbit.co.uk>");
1059 MODULE_AUTHOR("Roger Lucas <vt8231@hiddenengine.co.uk>");
1060 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/hwmon
/vt8231
.c
1061 MODULE_DESCRIPTION("VT8231 sensors");
1062 MODULE_LICENSE("GPL");
1064 module_init(sm_vt8231_init
);
1065 module_exit(sm_vt8231_exit
);