2 * vt1211.c - driver for the VIA VT1211 Super-I/O chip integrated hardware
4 * Copyright (C) 2006 Juerg Haefliger <juergh@gmail.com>
6 * This driver is based on the driver for kernel 2.4 by Mark D. Studebaker
7 * and its port to kernel 2.6 by Lars Ekman.
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.
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.
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.
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/slab.h>
27 #include <linux/jiffies.h>
28 #include <linux/platform_device.h>
29 #include <linux/hwmon.h>
30 #include <linux/hwmon-sysfs.h>
31 #include <linux/hwmon-vid.h>
32 #include <linux/err.h>
33 #include <linux/mutex.h>
34 #include <linux/ioport.h>
37 static int uch_config = -1;
38 module_param(uch_config, int, 0);
39 MODULE_PARM_DESC(uch_config, "Initialize the universal channel configuration");
41 static int int_mode = -1;
42 module_param(int_mode, int, 0);
43 MODULE_PARM_DESC(int_mode, "Force the temperature interrupt mode");
45 static unsigned short force_id;
46 module_param(force_id, ushort, 0);
47 MODULE_PARM_DESC(force_id, "Override the detected device ID");
49 static struct platform_device *pdev;
51 #define DRVNAME "vt1211"
53 /* ---------------------------------------------------------------------
56 * The sensors are defined as follows.
58 * Sensor Voltage Mode Temp Mode Notes (from the datasheet)
59 * -------- ------------ --------- --------------------------
60 * Reading 1 temp1 Intel thermal diode
61 * Reading 3 temp2 Internal thermal diode
62 * UCH1/Reading2 in0 temp3 NTC type thermistor
63 * UCH2 in1 temp4 +2.5V
67 * 3.3V in5 Internal VDD (+3.3V)
69 * --------------------------------------------------------------------- */
71 /* Voltages (in) numbered 0-5 (ix) */
72 #define VT1211_REG_IN(ix) (0x21 + (ix))
73 #define VT1211_REG_IN_MIN(ix) ((ix) == 0 ? 0x3e : 0x2a + 2 * (ix))
74 #define VT1211_REG_IN_MAX(ix) ((ix) == 0 ? 0x3d : 0x29 + 2 * (ix))
76 /* Temperatures (temp) numbered 0-6 (ix) */
77 static u8 regtemp[] = {0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25};
78 static u8 regtempmax[] = {0x39, 0x1d, 0x3d, 0x2b, 0x2d, 0x2f, 0x31};
79 static u8 regtemphyst[] = {0x3a, 0x1e, 0x3e, 0x2c, 0x2e, 0x30, 0x32};
81 /* Fans numbered 0-1 (ix) */
82 #define VT1211_REG_FAN(ix) (0x29 + (ix))
83 #define VT1211_REG_FAN_MIN(ix) (0x3b + (ix))
84 #define VT1211_REG_FAN_DIV 0x47
86 /* PWMs numbered 0-1 (ix) */
87 /* Auto points numbered 0-3 (ap) */
88 #define VT1211_REG_PWM(ix) (0x60 + (ix))
89 #define VT1211_REG_PWM_CLK 0x50
90 #define VT1211_REG_PWM_CTL 0x51
91 #define VT1211_REG_PWM_AUTO_TEMP(ap) (0x55 - (ap))
92 #define VT1211_REG_PWM_AUTO_PWM(ix, ap) (0x58 + 2 * (ix) - (ap))
94 /* Miscellaneous registers */
95 #define VT1211_REG_CONFIG 0x40
96 #define VT1211_REG_ALARM1 0x41
97 #define VT1211_REG_ALARM2 0x42
98 #define VT1211_REG_VID 0x45
99 #define VT1211_REG_UCH_CONFIG 0x4a
100 #define VT1211_REG_TEMP1_CONFIG 0x4b
101 #define VT1211_REG_TEMP2_CONFIG 0x4c
103 /* In, temp & fan alarm bits */
104 static const u8 bitalarmin[] = {11, 0, 1, 3, 8, 2, 9};
105 static const u8 bitalarmtemp[] = {4, 15, 11, 0, 1, 3, 8};
106 static const u8 bitalarmfan[] = {6, 7};
108 /* ---------------------------------------------------------------------
109 * Data structures and manipulation thereof
110 * --------------------------------------------------------------------- */
115 struct device *hwmon_dev;
117 struct mutex update_lock;
118 char valid; /* !=0 if following fields are valid */
119 unsigned long last_updated; /* In jiffies */
121 /* Register values */
136 u8 pwm_auto_pwm[2][4];
137 u8 vid; /* Read once at init time */
139 u8 uch_config; /* Read once at init time */
144 #define ISVOLT(ix, uch_config) ((ix) > 4 ? 1 : \
145 !(((uch_config) >> ((ix) + 2)) & 1))
148 #define ISTEMP(ix, uch_config) ((ix) < 2 ? 1 : \
149 ((uch_config) >> (ix)) & 1)
151 /* in5 (ix = 5) is special. It's the internal 3.3V so it's scaled in the
152 driver according to the VT1211 BIOS porting guide */
153 #define IN_FROM_REG(ix, reg) ((reg) < 3 ? 0 : (ix) == 5 ? \
154 (((reg) - 3) * 15882 + 479) / 958 : \
155 (((reg) - 3) * 10000 + 479) / 958)
156 #define IN_TO_REG(ix, val) (SENSORS_LIMIT((ix) == 5 ? \
157 ((val) * 958 + 7941) / 15882 + 3 : \
158 ((val) * 958 + 5000) / 10000 + 3, 0, 255))
160 /* temp1 (ix = 0) is an intel thermal diode which is scaled in user space.
161 temp2 (ix = 1) is the internal temp diode so it's scaled in the driver
162 according to some measurements that I took on an EPIA M10000.
163 temp3-7 are thermistor based so the driver returns the voltage measured at
164 the pin (range 0V - 2.2V). */
165 #define TEMP_FROM_REG(ix, reg) ((ix) == 0 ? (reg) * 1000 : \
166 (ix) == 1 ? (reg) < 51 ? 0 : \
167 ((reg) - 51) * 1000 : \
168 ((253 - (reg)) * 2200 + 105) / 210)
169 #define TEMP_TO_REG(ix, val) SENSORS_LIMIT( \
170 ((ix) == 0 ? ((val) + 500) / 1000 : \
171 (ix) == 1 ? ((val) + 500) / 1000 + 51 : \
172 253 - ((val) * 210 + 1100) / 2200), 0, 255)
174 #define DIV_FROM_REG(reg) (1 << (reg))
176 #define RPM_FROM_REG(reg, div) (((reg) == 0) || ((reg) == 255) ? 0 : \
177 1310720 / (reg) / DIV_FROM_REG(div))
178 #define RPM_TO_REG(val, div) ((val) == 0 ? 255 : \
179 SENSORS_LIMIT((1310720 / (val) / \
180 DIV_FROM_REG(div)), 1, 254))
182 /* ---------------------------------------------------------------------
183 * Super-I/O constants and functions
184 * --------------------------------------------------------------------- */
186 /* Configuration index port registers
187 * The vt1211 can live at 2 different addresses so we need to probe both */
188 #define SIO_REG_CIP1 0x2e
189 #define SIO_REG_CIP2 0x4e
191 /* Configuration registers */
192 #define SIO_VT1211_LDN 0x07 /* logical device number */
193 #define SIO_VT1211_DEVID 0x20 /* device ID */
194 #define SIO_VT1211_DEVREV 0x21 /* device revision */
195 #define SIO_VT1211_ACTIVE 0x30 /* HW monitor active */
196 #define SIO_VT1211_BADDR 0x60 /* base I/O address */
197 #define SIO_VT1211_ID 0x3c /* VT1211 device ID */
199 /* VT1211 logical device numbers */
200 #define SIO_VT1211_LDN_HWMON 0x0b /* HW monitor */
202 static inline void superio_outb(int sio_cip, int reg, int val)
205 outb(val, sio_cip + 1);
208 static inline int superio_inb(int sio_cip, int reg)
211 return inb(sio_cip + 1);
214 static inline void superio_select(int sio_cip, int ldn)
216 outb(SIO_VT1211_LDN, sio_cip);
217 outb(ldn, sio_cip + 1);
220 static inline void superio_enter(int sio_cip)
226 static inline void superio_exit(int sio_cip)
231 /* ---------------------------------------------------------------------
233 * --------------------------------------------------------------------- */
235 static inline u8 vt1211_read8(struct vt1211_data *data, u8 reg)
237 return inb(data->addr + reg);
240 static inline void vt1211_write8(struct vt1211_data *data, u8 reg, u8 val)
242 outb(val, data->addr + reg);
245 static struct vt1211_data *vt1211_update_device(struct device *dev)
247 struct vt1211_data *data = dev_get_drvdata(dev);
250 mutex_lock(&data->update_lock);
252 /* registers cache is refreshed after 1 second */
253 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
255 data->vid = vt1211_read8(data, VT1211_REG_VID) & 0x1f;
257 /* voltage (in) registers */
258 for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) {
259 if (ISVOLT(ix, data->uch_config)) {
260 data->in[ix] = vt1211_read8(data,
262 data->in_min[ix] = vt1211_read8(data,
263 VT1211_REG_IN_MIN(ix));
264 data->in_max[ix] = vt1211_read8(data,
265 VT1211_REG_IN_MAX(ix));
270 for (ix = 0; ix < ARRAY_SIZE(data->temp); ix++) {
271 if (ISTEMP(ix, data->uch_config)) {
272 data->temp[ix] = vt1211_read8(data,
274 data->temp_max[ix] = vt1211_read8(data,
276 data->temp_hyst[ix] = vt1211_read8(data,
281 /* fan & pwm registers */
282 for (ix = 0; ix < ARRAY_SIZE(data->fan); ix++) {
283 data->fan[ix] = vt1211_read8(data,
285 data->fan_min[ix] = vt1211_read8(data,
286 VT1211_REG_FAN_MIN(ix));
287 data->pwm[ix] = vt1211_read8(data,
290 val = vt1211_read8(data, VT1211_REG_FAN_DIV);
291 data->fan_div[0] = (val >> 4) & 3;
292 data->fan_div[1] = (val >> 6) & 3;
293 data->fan_ctl = val & 0xf;
295 val = vt1211_read8(data, VT1211_REG_PWM_CTL);
296 data->pwm_ctl[0] = val & 0xf;
297 data->pwm_ctl[1] = (val >> 4) & 0xf;
299 data->pwm_clk = vt1211_read8(data, VT1211_REG_PWM_CLK);
301 /* pwm & temp auto point registers */
302 data->pwm_auto_pwm[0][1] = vt1211_read8(data,
303 VT1211_REG_PWM_AUTO_PWM(0, 1));
304 data->pwm_auto_pwm[0][2] = vt1211_read8(data,
305 VT1211_REG_PWM_AUTO_PWM(0, 2));
306 data->pwm_auto_pwm[1][1] = vt1211_read8(data,
307 VT1211_REG_PWM_AUTO_PWM(1, 1));
308 data->pwm_auto_pwm[1][2] = vt1211_read8(data,
309 VT1211_REG_PWM_AUTO_PWM(1, 2));
310 for (ix = 0; ix < ARRAY_SIZE(data->pwm_auto_temp); ix++) {
311 data->pwm_auto_temp[ix] = vt1211_read8(data,
312 VT1211_REG_PWM_AUTO_TEMP(ix));
315 /* alarm registers */
316 data->alarms = (vt1211_read8(data, VT1211_REG_ALARM2) << 8) |
317 vt1211_read8(data, VT1211_REG_ALARM1);
319 data->last_updated = jiffies;
323 mutex_unlock(&data->update_lock);
328 /* ---------------------------------------------------------------------
329 * Voltage sysfs interfaces
331 * --------------------------------------------------------------------- */
333 #define SHOW_IN_INPUT 0
334 #define SHOW_SET_IN_MIN 1
335 #define SHOW_SET_IN_MAX 2
336 #define SHOW_IN_ALARM 3
338 static ssize_t show_in(struct device *dev, struct device_attribute *attr,
341 struct vt1211_data *data = vt1211_update_device(dev);
342 struct sensor_device_attribute_2 *sensor_attr_2 =
343 to_sensor_dev_attr_2(attr);
344 int ix = sensor_attr_2->index;
345 int fn = sensor_attr_2->nr;
350 res = IN_FROM_REG(ix, data->in[ix]);
352 case SHOW_SET_IN_MIN:
353 res = IN_FROM_REG(ix, data->in_min[ix]);
355 case SHOW_SET_IN_MAX:
356 res = IN_FROM_REG(ix, data->in_max[ix]);
359 res = (data->alarms >> bitalarmin[ix]) & 1;
363 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
366 return sprintf(buf, "%d\n", res);
369 static ssize_t set_in(struct device *dev, struct device_attribute *attr,
370 const char *buf, size_t count)
372 struct vt1211_data *data = dev_get_drvdata(dev);
373 struct sensor_device_attribute_2 *sensor_attr_2 =
374 to_sensor_dev_attr_2(attr);
375 int ix = sensor_attr_2->index;
376 int fn = sensor_attr_2->nr;
377 long val = simple_strtol(buf, NULL, 10);
379 mutex_lock(&data->update_lock);
381 case SHOW_SET_IN_MIN:
382 data->in_min[ix] = IN_TO_REG(ix, val);
383 vt1211_write8(data, VT1211_REG_IN_MIN(ix), data->in_min[ix]);
385 case SHOW_SET_IN_MAX:
386 data->in_max[ix] = IN_TO_REG(ix, val);
387 vt1211_write8(data, VT1211_REG_IN_MAX(ix), data->in_max[ix]);
390 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
392 mutex_unlock(&data->update_lock);
397 /* ---------------------------------------------------------------------
398 * Temperature sysfs interfaces
400 * --------------------------------------------------------------------- */
402 #define SHOW_TEMP_INPUT 0
403 #define SHOW_SET_TEMP_MAX 1
404 #define SHOW_SET_TEMP_MAX_HYST 2
405 #define SHOW_TEMP_ALARM 3
407 static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
410 struct vt1211_data *data = vt1211_update_device(dev);
411 struct sensor_device_attribute_2 *sensor_attr_2 =
412 to_sensor_dev_attr_2(attr);
413 int ix = sensor_attr_2->index;
414 int fn = sensor_attr_2->nr;
418 case SHOW_TEMP_INPUT:
419 res = TEMP_FROM_REG(ix, data->temp[ix]);
421 case SHOW_SET_TEMP_MAX:
422 res = TEMP_FROM_REG(ix, data->temp_max[ix]);
424 case SHOW_SET_TEMP_MAX_HYST:
425 res = TEMP_FROM_REG(ix, data->temp_hyst[ix]);
427 case SHOW_TEMP_ALARM:
428 res = (data->alarms >> bitalarmtemp[ix]) & 1;
432 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
435 return sprintf(buf, "%d\n", res);
438 static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
439 const char *buf, size_t count)
441 struct vt1211_data *data = dev_get_drvdata(dev);
442 struct sensor_device_attribute_2 *sensor_attr_2 =
443 to_sensor_dev_attr_2(attr);
444 int ix = sensor_attr_2->index;
445 int fn = sensor_attr_2->nr;
446 long val = simple_strtol(buf, NULL, 10);
448 mutex_lock(&data->update_lock);
450 case SHOW_SET_TEMP_MAX:
451 data->temp_max[ix] = TEMP_TO_REG(ix, val);
452 vt1211_write8(data, regtempmax[ix],
455 case SHOW_SET_TEMP_MAX_HYST:
456 data->temp_hyst[ix] = TEMP_TO_REG(ix, val);
457 vt1211_write8(data, regtemphyst[ix],
458 data->temp_hyst[ix]);
461 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
463 mutex_unlock(&data->update_lock);
468 /* ---------------------------------------------------------------------
469 * Fan sysfs interfaces
471 * --------------------------------------------------------------------- */
473 #define SHOW_FAN_INPUT 0
474 #define SHOW_SET_FAN_MIN 1
475 #define SHOW_SET_FAN_DIV 2
476 #define SHOW_FAN_ALARM 3
478 static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
481 struct vt1211_data *data = vt1211_update_device(dev);
482 struct sensor_device_attribute_2 *sensor_attr_2 =
483 to_sensor_dev_attr_2(attr);
484 int ix = sensor_attr_2->index;
485 int fn = sensor_attr_2->nr;
490 res = RPM_FROM_REG(data->fan[ix], data->fan_div[ix]);
492 case SHOW_SET_FAN_MIN:
493 res = RPM_FROM_REG(data->fan_min[ix], data->fan_div[ix]);
495 case SHOW_SET_FAN_DIV:
496 res = DIV_FROM_REG(data->fan_div[ix]);
499 res = (data->alarms >> bitalarmfan[ix]) & 1;
503 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
506 return sprintf(buf, "%d\n", res);
509 static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
510 const char *buf, size_t count)
512 struct vt1211_data *data = dev_get_drvdata(dev);
513 struct sensor_device_attribute_2 *sensor_attr_2 =
514 to_sensor_dev_attr_2(attr);
515 int ix = sensor_attr_2->index;
516 int fn = sensor_attr_2->nr;
517 long val = simple_strtol(buf, NULL, 10);
520 mutex_lock(&data->update_lock);
522 /* sync the data cache */
523 reg = vt1211_read8(data, VT1211_REG_FAN_DIV);
524 data->fan_div[0] = (reg >> 4) & 3;
525 data->fan_div[1] = (reg >> 6) & 3;
526 data->fan_ctl = reg & 0xf;
529 case SHOW_SET_FAN_MIN:
530 data->fan_min[ix] = RPM_TO_REG(val, data->fan_div[ix]);
531 vt1211_write8(data, VT1211_REG_FAN_MIN(ix),
534 case SHOW_SET_FAN_DIV:
536 case 1: data->fan_div[ix] = 0; break;
537 case 2: data->fan_div[ix] = 1; break;
538 case 4: data->fan_div[ix] = 2; break;
539 case 8: data->fan_div[ix] = 3; break;
542 dev_warn(dev, "fan div value %ld not "
543 "supported. Choose one of 1, 2, "
547 vt1211_write8(data, VT1211_REG_FAN_DIV,
548 ((data->fan_div[1] << 6) |
549 (data->fan_div[0] << 4) |
553 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
557 mutex_unlock(&data->update_lock);
561 /* ---------------------------------------------------------------------
562 * PWM sysfs interfaces
564 * --------------------------------------------------------------------- */
567 #define SHOW_SET_PWM_ENABLE 1
568 #define SHOW_SET_PWM_FREQ 2
569 #define SHOW_SET_PWM_AUTO_CHANNELS_TEMP 3
571 static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
574 struct vt1211_data *data = vt1211_update_device(dev);
575 struct sensor_device_attribute_2 *sensor_attr_2 =
576 to_sensor_dev_attr_2(attr);
577 int ix = sensor_attr_2->index;
578 int fn = sensor_attr_2->nr;
585 case SHOW_SET_PWM_ENABLE:
586 res = ((data->pwm_ctl[ix] >> 3) & 1) ? 2 : 0;
588 case SHOW_SET_PWM_FREQ:
589 res = 90000 >> (data->pwm_clk & 7);
591 case SHOW_SET_PWM_AUTO_CHANNELS_TEMP:
592 res = (data->pwm_ctl[ix] & 7) + 1;
596 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
599 return sprintf(buf, "%d\n", res);
602 static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
603 const char *buf, size_t count)
605 struct vt1211_data *data = dev_get_drvdata(dev);
606 struct sensor_device_attribute_2 *sensor_attr_2 =
607 to_sensor_dev_attr_2(attr);
608 int ix = sensor_attr_2->index;
609 int fn = sensor_attr_2->nr;
610 long val = simple_strtol(buf, NULL, 10);
613 mutex_lock(&data->update_lock);
616 case SHOW_SET_PWM_ENABLE:
617 /* sync the data cache */
618 reg = vt1211_read8(data, VT1211_REG_FAN_DIV);
619 data->fan_div[0] = (reg >> 4) & 3;
620 data->fan_div[1] = (reg >> 6) & 3;
621 data->fan_ctl = reg & 0xf;
622 reg = vt1211_read8(data, VT1211_REG_PWM_CTL);
623 data->pwm_ctl[0] = reg & 0xf;
624 data->pwm_ctl[1] = (reg >> 4) & 0xf;
627 data->pwm_ctl[ix] &= 7;
628 /* disable SmartGuardian if both PWM outputs are
630 if ((data->pwm_ctl[ix ^ 1] & 1) == 0) {
631 data->fan_ctl &= 0xe;
635 data->pwm_ctl[ix] |= 8;
640 dev_warn(dev, "pwm mode %ld not supported. "
641 "Choose one of 0 or 2.\n", val);
644 vt1211_write8(data, VT1211_REG_PWM_CTL,
645 ((data->pwm_ctl[1] << 4) |
647 vt1211_write8(data, VT1211_REG_FAN_DIV,
648 ((data->fan_div[1] << 6) |
649 (data->fan_div[0] << 4) |
652 case SHOW_SET_PWM_FREQ:
653 val = 135000 / SENSORS_LIMIT(val, 135000 >> 7, 135000);
654 /* calculate tmp = log2(val) */
656 for (val >>= 1; val > 0; val >>= 1) {
659 /* sync the data cache */
660 reg = vt1211_read8(data, VT1211_REG_PWM_CLK);
661 data->pwm_clk = (reg & 0xf8) | tmp;
662 vt1211_write8(data, VT1211_REG_PWM_CLK, data->pwm_clk);
664 case SHOW_SET_PWM_AUTO_CHANNELS_TEMP:
665 if ((val < 1) || (val > 7)) {
667 dev_warn(dev, "temp channel %ld not supported. "
668 "Choose a value between 1 and 7.\n", val);
671 if (!ISTEMP(val - 1, data->uch_config)) {
673 dev_warn(dev, "temp channel %ld is not available.\n",
677 /* sync the data cache */
678 reg = vt1211_read8(data, VT1211_REG_PWM_CTL);
679 data->pwm_ctl[0] = reg & 0xf;
680 data->pwm_ctl[1] = (reg >> 4) & 0xf;
681 data->pwm_ctl[ix] = (data->pwm_ctl[ix] & 8) | (val - 1);
682 vt1211_write8(data, VT1211_REG_PWM_CTL,
683 ((data->pwm_ctl[1] << 4) | data->pwm_ctl[0]));
686 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
690 mutex_unlock(&data->update_lock);
694 /* ---------------------------------------------------------------------
695 * PWM auto point definitions
698 * --------------------------------------------------------------------- */
701 * pwm[ix+1]_auto_point[ap+1]_temp mapping table:
702 * Note that there is only a single set of temp auto points that controls both
703 * PWM controllers. We still create 2 sets of sysfs files to make it look
704 * more consistent even though they map to the same registers.
706 * ix ap : description
707 * -------------------
708 * 0 0 : pwm1/2 off temperature (pwm_auto_temp[0])
709 * 0 1 : pwm1/2 low speed temperature (pwm_auto_temp[1])
710 * 0 2 : pwm1/2 high speed temperature (pwm_auto_temp[2])
711 * 0 3 : pwm1/2 full speed temperature (pwm_auto_temp[3])
712 * 1 0 : pwm1/2 off temperature (pwm_auto_temp[0])
713 * 1 1 : pwm1/2 low speed temperature (pwm_auto_temp[1])
714 * 1 2 : pwm1/2 high speed temperature (pwm_auto_temp[2])
715 * 1 3 : pwm1/2 full speed temperature (pwm_auto_temp[3])
718 static ssize_t show_pwm_auto_point_temp(struct device *dev,
719 struct device_attribute *attr,
722 struct vt1211_data *data = vt1211_update_device(dev);
723 struct sensor_device_attribute_2 *sensor_attr_2 =
724 to_sensor_dev_attr_2(attr);
725 int ix = sensor_attr_2->index;
726 int ap = sensor_attr_2->nr;
728 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->pwm_ctl[ix] & 7,
729 data->pwm_auto_temp[ap]));
732 static ssize_t set_pwm_auto_point_temp(struct device *dev,
733 struct device_attribute *attr,
734 const char *buf, size_t count)
736 struct vt1211_data *data = dev_get_drvdata(dev);
737 struct sensor_device_attribute_2 *sensor_attr_2 =
738 to_sensor_dev_attr_2(attr);
739 int ix = sensor_attr_2->index;
740 int ap = sensor_attr_2->nr;
741 long val = simple_strtol(buf, NULL, 10);
744 mutex_lock(&data->update_lock);
746 /* sync the data cache */
747 reg = vt1211_read8(data, VT1211_REG_PWM_CTL);
748 data->pwm_ctl[0] = reg & 0xf;
749 data->pwm_ctl[1] = (reg >> 4) & 0xf;
751 data->pwm_auto_temp[ap] = TEMP_TO_REG(data->pwm_ctl[ix] & 7, val);
752 vt1211_write8(data, VT1211_REG_PWM_AUTO_TEMP(ap),
753 data->pwm_auto_temp[ap]);
754 mutex_unlock(&data->update_lock);
760 * pwm[ix+1]_auto_point[ap+1]_pwm mapping table:
761 * Note that the PWM auto points 0 & 3 are hard-wired in the VT1211 and can't
764 * ix ap : description
765 * -------------------
766 * 0 0 : pwm1 off (pwm_auto_pwm[0][0], hard-wired to 0)
767 * 0 1 : pwm1 low speed duty cycle (pwm_auto_pwm[0][1])
768 * 0 2 : pwm1 high speed duty cycle (pwm_auto_pwm[0][2])
769 * 0 3 : pwm1 full speed (pwm_auto_pwm[0][3], hard-wired to 255)
770 * 1 0 : pwm2 off (pwm_auto_pwm[1][0], hard-wired to 0)
771 * 1 1 : pwm2 low speed duty cycle (pwm_auto_pwm[1][1])
772 * 1 2 : pwm2 high speed duty cycle (pwm_auto_pwm[1][2])
773 * 1 3 : pwm2 full speed (pwm_auto_pwm[1][3], hard-wired to 255)
776 static ssize_t show_pwm_auto_point_pwm(struct device *dev,
777 struct device_attribute *attr,
780 struct vt1211_data *data = vt1211_update_device(dev);
781 struct sensor_device_attribute_2 *sensor_attr_2 =
782 to_sensor_dev_attr_2(attr);
783 int ix = sensor_attr_2->index;
784 int ap = sensor_attr_2->nr;
786 return sprintf(buf, "%d\n", data->pwm_auto_pwm[ix][ap]);
789 static ssize_t set_pwm_auto_point_pwm(struct device *dev,
790 struct device_attribute *attr,
791 const char *buf, size_t count)
793 struct vt1211_data *data = dev_get_drvdata(dev);
794 struct sensor_device_attribute_2 *sensor_attr_2 =
795 to_sensor_dev_attr_2(attr);
796 int ix = sensor_attr_2->index;
797 int ap = sensor_attr_2->nr;
798 long val = simple_strtol(buf, NULL, 10);
800 if ((val < 0) || (val > 255)) {
801 dev_err(dev, "pwm value %ld is out of range. "
802 "Choose a value between 0 and 255.\n" , val);
806 mutex_lock(&data->update_lock);
807 data->pwm_auto_pwm[ix][ap] = val;
808 vt1211_write8(data, VT1211_REG_PWM_AUTO_PWM(ix, ap),
809 data->pwm_auto_pwm[ix][ap]);
810 mutex_unlock(&data->update_lock);
815 /* ---------------------------------------------------------------------
816 * Miscellaneous sysfs interfaces (VRM, VID, name, and (legacy) alarms)
817 * --------------------------------------------------------------------- */
819 static ssize_t show_vrm(struct device *dev, struct device_attribute *attr,
822 struct vt1211_data *data = dev_get_drvdata(dev);
824 return sprintf(buf, "%d\n", data->vrm);
827 static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
828 const char *buf, size_t count)
830 struct vt1211_data *data = dev_get_drvdata(dev);
831 long val = simple_strtol(buf, NULL, 10);
838 static ssize_t show_vid(struct device *dev, struct device_attribute *attr,
841 struct vt1211_data *data = dev_get_drvdata(dev);
843 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
846 static ssize_t show_name(struct device *dev,
847 struct device_attribute *attr, char *buf)
849 struct vt1211_data *data = dev_get_drvdata(dev);
851 return sprintf(buf, "%s\n", data->name);
854 static ssize_t show_alarms(struct device *dev,
855 struct device_attribute *attr, char *buf)
857 struct vt1211_data *data = vt1211_update_device(dev);
859 return sprintf(buf, "%d\n", data->alarms);
862 /* ---------------------------------------------------------------------
863 * Device attribute structs
864 * --------------------------------------------------------------------- */
866 #define SENSOR_ATTR_IN_INPUT(ix) \
867 SENSOR_ATTR_2(in##ix##_input, S_IRUGO, \
868 show_in, NULL, SHOW_IN_INPUT, ix)
870 static struct sensor_device_attribute_2 vt1211_sysfs_in_input[] = {
871 SENSOR_ATTR_IN_INPUT(0),
872 SENSOR_ATTR_IN_INPUT(1),
873 SENSOR_ATTR_IN_INPUT(2),
874 SENSOR_ATTR_IN_INPUT(3),
875 SENSOR_ATTR_IN_INPUT(4),
876 SENSOR_ATTR_IN_INPUT(5),
879 #define SENSOR_ATTR_IN_MIN(ix) \
880 SENSOR_ATTR_2(in##ix##_min, S_IRUGO | S_IWUSR, \
881 show_in, set_in, SHOW_SET_IN_MIN, ix)
883 static struct sensor_device_attribute_2 vt1211_sysfs_in_min[] = {
884 SENSOR_ATTR_IN_MIN(0),
885 SENSOR_ATTR_IN_MIN(1),
886 SENSOR_ATTR_IN_MIN(2),
887 SENSOR_ATTR_IN_MIN(3),
888 SENSOR_ATTR_IN_MIN(4),
889 SENSOR_ATTR_IN_MIN(5),
892 #define SENSOR_ATTR_IN_MAX(ix) \
893 SENSOR_ATTR_2(in##ix##_max, S_IRUGO | S_IWUSR, \
894 show_in, set_in, SHOW_SET_IN_MAX, ix)
896 static struct sensor_device_attribute_2 vt1211_sysfs_in_max[] = {
897 SENSOR_ATTR_IN_MAX(0),
898 SENSOR_ATTR_IN_MAX(1),
899 SENSOR_ATTR_IN_MAX(2),
900 SENSOR_ATTR_IN_MAX(3),
901 SENSOR_ATTR_IN_MAX(4),
902 SENSOR_ATTR_IN_MAX(5),
905 #define SENSOR_ATTR_IN_ALARM(ix) \
906 SENSOR_ATTR_2(in##ix##_alarm, S_IRUGO, \
907 show_in, NULL, SHOW_IN_ALARM, ix)
909 static struct sensor_device_attribute_2 vt1211_sysfs_in_alarm[] = {
910 SENSOR_ATTR_IN_ALARM(0),
911 SENSOR_ATTR_IN_ALARM(1),
912 SENSOR_ATTR_IN_ALARM(2),
913 SENSOR_ATTR_IN_ALARM(3),
914 SENSOR_ATTR_IN_ALARM(4),
915 SENSOR_ATTR_IN_ALARM(5),
918 #define SENSOR_ATTR_TEMP_INPUT(ix) \
919 SENSOR_ATTR_2(temp##ix##_input, S_IRUGO, \
920 show_temp, NULL, SHOW_TEMP_INPUT, ix-1)
922 static struct sensor_device_attribute_2 vt1211_sysfs_temp_input[] = {
923 SENSOR_ATTR_TEMP_INPUT(1),
924 SENSOR_ATTR_TEMP_INPUT(2),
925 SENSOR_ATTR_TEMP_INPUT(3),
926 SENSOR_ATTR_TEMP_INPUT(4),
927 SENSOR_ATTR_TEMP_INPUT(5),
928 SENSOR_ATTR_TEMP_INPUT(6),
929 SENSOR_ATTR_TEMP_INPUT(7),
932 #define SENSOR_ATTR_TEMP_MAX(ix) \
933 SENSOR_ATTR_2(temp##ix##_max, S_IRUGO | S_IWUSR, \
934 show_temp, set_temp, SHOW_SET_TEMP_MAX, ix-1)
936 static struct sensor_device_attribute_2 vt1211_sysfs_temp_max[] = {
937 SENSOR_ATTR_TEMP_MAX(1),
938 SENSOR_ATTR_TEMP_MAX(2),
939 SENSOR_ATTR_TEMP_MAX(3),
940 SENSOR_ATTR_TEMP_MAX(4),
941 SENSOR_ATTR_TEMP_MAX(5),
942 SENSOR_ATTR_TEMP_MAX(6),
943 SENSOR_ATTR_TEMP_MAX(7),
946 #define SENSOR_ATTR_TEMP_MAX_HYST(ix) \
947 SENSOR_ATTR_2(temp##ix##_max_hyst, S_IRUGO | S_IWUSR, \
948 show_temp, set_temp, SHOW_SET_TEMP_MAX_HYST, ix-1)
950 static struct sensor_device_attribute_2 vt1211_sysfs_temp_max_hyst[] = {
951 SENSOR_ATTR_TEMP_MAX_HYST(1),
952 SENSOR_ATTR_TEMP_MAX_HYST(2),
953 SENSOR_ATTR_TEMP_MAX_HYST(3),
954 SENSOR_ATTR_TEMP_MAX_HYST(4),
955 SENSOR_ATTR_TEMP_MAX_HYST(5),
956 SENSOR_ATTR_TEMP_MAX_HYST(6),
957 SENSOR_ATTR_TEMP_MAX_HYST(7),
960 #define SENSOR_ATTR_TEMP_ALARM(ix) \
961 SENSOR_ATTR_2(temp##ix##_alarm, S_IRUGO, \
962 show_temp, NULL, SHOW_TEMP_ALARM, ix-1)
964 static struct sensor_device_attribute_2 vt1211_sysfs_temp_alarm[] = {
965 SENSOR_ATTR_TEMP_ALARM(1),
966 SENSOR_ATTR_TEMP_ALARM(2),
967 SENSOR_ATTR_TEMP_ALARM(3),
968 SENSOR_ATTR_TEMP_ALARM(4),
969 SENSOR_ATTR_TEMP_ALARM(5),
970 SENSOR_ATTR_TEMP_ALARM(6),
971 SENSOR_ATTR_TEMP_ALARM(7),
974 #define SENSOR_ATTR_FAN(ix) \
975 SENSOR_ATTR_2(fan##ix##_input, S_IRUGO, \
976 show_fan, NULL, SHOW_FAN_INPUT, ix-1), \
977 SENSOR_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \
978 show_fan, set_fan, SHOW_SET_FAN_MIN, ix-1), \
979 SENSOR_ATTR_2(fan##ix##_div, S_IRUGO | S_IWUSR, \
980 show_fan, set_fan, SHOW_SET_FAN_DIV, ix-1), \
981 SENSOR_ATTR_2(fan##ix##_alarm, S_IRUGO, \
982 show_fan, NULL, SHOW_FAN_ALARM, ix-1)
984 #define SENSOR_ATTR_PWM(ix) \
985 SENSOR_ATTR_2(pwm##ix, S_IRUGO, \
986 show_pwm, NULL, SHOW_PWM, ix-1), \
987 SENSOR_ATTR_2(pwm##ix##_enable, S_IRUGO | S_IWUSR, \
988 show_pwm, set_pwm, SHOW_SET_PWM_ENABLE, ix-1), \
989 SENSOR_ATTR_2(pwm##ix##_auto_channels_temp, S_IRUGO | S_IWUSR, \
990 show_pwm, set_pwm, SHOW_SET_PWM_AUTO_CHANNELS_TEMP, ix-1)
992 #define SENSOR_ATTR_PWM_FREQ(ix) \
993 SENSOR_ATTR_2(pwm##ix##_freq, S_IRUGO | S_IWUSR, \
994 show_pwm, set_pwm, SHOW_SET_PWM_FREQ, ix-1)
996 #define SENSOR_ATTR_PWM_FREQ_RO(ix) \
997 SENSOR_ATTR_2(pwm##ix##_freq, S_IRUGO, \
998 show_pwm, NULL, SHOW_SET_PWM_FREQ, ix-1)
1000 #define SENSOR_ATTR_PWM_AUTO_POINT_TEMP(ix, ap) \
1001 SENSOR_ATTR_2(pwm##ix##_auto_point##ap##_temp, S_IRUGO | S_IWUSR, \
1002 show_pwm_auto_point_temp, set_pwm_auto_point_temp, \
1005 #define SENSOR_ATTR_PWM_AUTO_POINT_TEMP_RO(ix, ap) \
1006 SENSOR_ATTR_2(pwm##ix##_auto_point##ap##_temp, S_IRUGO, \
1007 show_pwm_auto_point_temp, NULL, \
1010 #define SENSOR_ATTR_PWM_AUTO_POINT_PWM(ix, ap) \
1011 SENSOR_ATTR_2(pwm##ix##_auto_point##ap##_pwm, S_IRUGO | S_IWUSR, \
1012 show_pwm_auto_point_pwm, set_pwm_auto_point_pwm, \
1015 #define SENSOR_ATTR_PWM_AUTO_POINT_PWM_RO(ix, ap) \
1016 SENSOR_ATTR_2(pwm##ix##_auto_point##ap##_pwm, S_IRUGO, \
1017 show_pwm_auto_point_pwm, NULL, \
1020 static struct sensor_device_attribute_2 vt1211_sysfs_fan_pwm[] = {
1025 SENSOR_ATTR_PWM_FREQ(1),
1026 SENSOR_ATTR_PWM_FREQ_RO(2),
1027 SENSOR_ATTR_PWM_AUTO_POINT_TEMP(1, 1),
1028 SENSOR_ATTR_PWM_AUTO_POINT_TEMP(1, 2),
1029 SENSOR_ATTR_PWM_AUTO_POINT_TEMP(1, 3),
1030 SENSOR_ATTR_PWM_AUTO_POINT_TEMP(1, 4),
1031 SENSOR_ATTR_PWM_AUTO_POINT_TEMP_RO(2, 1),
1032 SENSOR_ATTR_PWM_AUTO_POINT_TEMP_RO(2, 2),
1033 SENSOR_ATTR_PWM_AUTO_POINT_TEMP_RO(2, 3),
1034 SENSOR_ATTR_PWM_AUTO_POINT_TEMP_RO(2, 4),
1035 SENSOR_ATTR_PWM_AUTO_POINT_PWM_RO(1, 1),
1036 SENSOR_ATTR_PWM_AUTO_POINT_PWM(1, 2),
1037 SENSOR_ATTR_PWM_AUTO_POINT_PWM(1, 3),
1038 SENSOR_ATTR_PWM_AUTO_POINT_PWM_RO(1, 4),
1039 SENSOR_ATTR_PWM_AUTO_POINT_PWM_RO(2, 1),
1040 SENSOR_ATTR_PWM_AUTO_POINT_PWM(2, 2),
1041 SENSOR_ATTR_PWM_AUTO_POINT_PWM(2, 3),
1042 SENSOR_ATTR_PWM_AUTO_POINT_PWM_RO(2, 4),
1045 static struct device_attribute vt1211_sysfs_misc[] = {
1046 __ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm),
1047 __ATTR(cpu0_vid, S_IRUGO, show_vid, NULL),
1048 __ATTR(name, S_IRUGO, show_name, NULL),
1049 __ATTR(alarms, S_IRUGO, show_alarms, NULL),
1052 /* ---------------------------------------------------------------------
1053 * Device registration and initialization
1054 * --------------------------------------------------------------------- */
1056 static void __devinit vt1211_init_device(struct vt1211_data *data)
1059 data->vrm = vid_which_vrm();
1061 /* Read (and initialize) UCH config */
1062 data->uch_config = vt1211_read8(data, VT1211_REG_UCH_CONFIG);
1063 if (uch_config > -1) {
1064 data->uch_config = (data->uch_config & 0x83) |
1066 vt1211_write8(data, VT1211_REG_UCH_CONFIG, data->uch_config);
1069 /* Initialize the interrupt mode (if request at module load time).
1070 * The VT1211 implements 3 different modes for clearing interrupts:
1071 * 0: Clear INT when status register is read. Regenerate INT as long
1072 * as temp stays above hysteresis limit.
1073 * 1: Clear INT when status register is read. DON'T regenerate INT
1074 * until temp falls below hysteresis limit and exceeds hot limit
1076 * 2: Clear INT when temp falls below max limit.
1078 * The driver only allows to force mode 0 since that's the only one
1079 * that makes sense for 'sensors' */
1080 if (int_mode == 0) {
1081 vt1211_write8(data, VT1211_REG_TEMP1_CONFIG, 0);
1082 vt1211_write8(data, VT1211_REG_TEMP2_CONFIG, 0);
1085 /* Fill in some hard wired values into our data struct */
1086 data->pwm_auto_pwm[0][3] = 255;
1087 data->pwm_auto_pwm[1][3] = 255;
1090 static void vt1211_remove_sysfs(struct platform_device *pdev)
1092 struct device *dev = &pdev->dev;
1095 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_in_input); i++) {
1096 device_remove_file(dev,
1097 &vt1211_sysfs_in_input[i].dev_attr);
1098 device_remove_file(dev,
1099 &vt1211_sysfs_in_min[i].dev_attr);
1100 device_remove_file(dev,
1101 &vt1211_sysfs_in_max[i].dev_attr);
1102 device_remove_file(dev,
1103 &vt1211_sysfs_in_alarm[i].dev_attr);
1105 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_temp_input); i++) {
1106 device_remove_file(dev,
1107 &vt1211_sysfs_temp_input[i].dev_attr);
1108 device_remove_file(dev,
1109 &vt1211_sysfs_temp_max[i].dev_attr);
1110 device_remove_file(dev,
1111 &vt1211_sysfs_temp_max_hyst[i].dev_attr);
1112 device_remove_file(dev,
1113 &vt1211_sysfs_temp_alarm[i].dev_attr);
1115 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_fan_pwm); i++) {
1116 device_remove_file(dev,
1117 &vt1211_sysfs_fan_pwm[i].dev_attr);
1119 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_misc); i++) {
1120 device_remove_file(dev, &vt1211_sysfs_misc[i]);
1124 static int __devinit vt1211_probe(struct platform_device *pdev)
1126 struct device *dev = &pdev->dev;
1127 struct vt1211_data *data;
1128 struct resource *res;
1131 if (!(data = kzalloc(sizeof(struct vt1211_data), GFP_KERNEL))) {
1133 dev_err(dev, "Out of memory\n");
1137 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
1138 if (!request_region(res->start, res->end - res->start + 1, DRVNAME)) {
1140 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
1141 (unsigned long)res->start, (unsigned long)res->end);
1144 data->addr = res->start;
1145 data->name = DRVNAME;
1146 mutex_init(&data->update_lock);
1148 platform_set_drvdata(pdev, data);
1150 /* Initialize the VT1211 chip */
1151 vt1211_init_device(data);
1153 /* Create sysfs interface files */
1154 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_in_input); i++) {
1155 if (ISVOLT(i, data->uch_config)) {
1156 if ((err = device_create_file(dev,
1157 &vt1211_sysfs_in_input[i].dev_attr)) ||
1158 (err = device_create_file(dev,
1159 &vt1211_sysfs_in_min[i].dev_attr)) ||
1160 (err = device_create_file(dev,
1161 &vt1211_sysfs_in_max[i].dev_attr)) ||
1162 (err = device_create_file(dev,
1163 &vt1211_sysfs_in_alarm[i].dev_attr))) {
1164 goto EXIT_DEV_REMOVE;
1168 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_temp_input); i++) {
1169 if (ISTEMP(i, data->uch_config)) {
1170 if ((err = device_create_file(dev,
1171 &vt1211_sysfs_temp_input[i].dev_attr)) ||
1172 (err = device_create_file(dev,
1173 &vt1211_sysfs_temp_max[i].dev_attr)) ||
1174 (err = device_create_file(dev,
1175 &vt1211_sysfs_temp_max_hyst[i].dev_attr)) ||
1176 (err = device_create_file(dev,
1177 &vt1211_sysfs_temp_alarm[i].dev_attr))) {
1178 goto EXIT_DEV_REMOVE;
1182 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_fan_pwm); i++) {
1183 err = device_create_file(dev,
1184 &vt1211_sysfs_fan_pwm[i].dev_attr);
1186 goto EXIT_DEV_REMOVE;
1189 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_misc); i++) {
1190 err = device_create_file(dev,
1191 &vt1211_sysfs_misc[i]);
1193 goto EXIT_DEV_REMOVE;
1197 /* Register device */
1198 data->hwmon_dev = hwmon_device_register(dev);
1199 if (IS_ERR(data->hwmon_dev)) {
1200 err = PTR_ERR(data->hwmon_dev);
1201 dev_err(dev, "Class registration failed (%d)\n", err);
1202 goto EXIT_DEV_REMOVE_SILENT;
1208 dev_err(dev, "Sysfs interface creation failed (%d)\n", err);
1209 EXIT_DEV_REMOVE_SILENT:
1210 vt1211_remove_sysfs(pdev);
1211 release_region(res->start, res->end - res->start + 1);
1213 platform_set_drvdata(pdev, NULL);
1219 static int __devexit vt1211_remove(struct platform_device *pdev)
1221 struct vt1211_data *data = platform_get_drvdata(pdev);
1222 struct resource *res;
1224 hwmon_device_unregister(data->hwmon_dev);
1225 vt1211_remove_sysfs(pdev);
1226 platform_set_drvdata(pdev, NULL);
1229 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
1230 release_region(res->start, res->end - res->start + 1);
1235 static struct platform_driver vt1211_driver = {
1237 .owner = THIS_MODULE,
1240 .probe = vt1211_probe,
1241 .remove = __devexit_p(vt1211_remove),
1244 static int __init vt1211_device_add(unsigned short address)
1246 struct resource res = {
1248 .end = address + 0x7f,
1249 .flags = IORESOURCE_IO,
1253 pdev = platform_device_alloc(DRVNAME, address);
1256 printk(KERN_ERR DRVNAME ": Device allocation failed (%d)\n",
1261 res.name = pdev->name;
1262 err = platform_device_add_resources(pdev, &res, 1);
1264 printk(KERN_ERR DRVNAME ": Device resource addition failed "
1269 err = platform_device_add(pdev);
1271 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
1279 platform_device_put(pdev);
1284 static int __init vt1211_find(int sio_cip, unsigned short *address)
1289 superio_enter(sio_cip);
1291 devid = force_id ? force_id : superio_inb(sio_cip, SIO_VT1211_DEVID);
1292 if (devid != SIO_VT1211_ID) {
1296 superio_select(sio_cip, SIO_VT1211_LDN_HWMON);
1298 if ((superio_inb(sio_cip, SIO_VT1211_ACTIVE) & 1) == 0) {
1299 printk(KERN_WARNING DRVNAME ": HW monitor is disabled, "
1304 *address = ((superio_inb(sio_cip, SIO_VT1211_BADDR) << 8) |
1305 (superio_inb(sio_cip, SIO_VT1211_BADDR + 1))) & 0xff00;
1306 if (*address == 0) {
1307 printk(KERN_WARNING DRVNAME ": Base address is not set, "
1313 printk(KERN_INFO DRVNAME ": Found VT1211 chip at 0x%04x, "
1314 "revision %u\n", *address,
1315 superio_inb(sio_cip, SIO_VT1211_DEVREV));
1318 superio_exit(sio_cip);
1322 static int __init vt1211_init(void)
1325 unsigned short address = 0;
1327 if ((err = vt1211_find(SIO_REG_CIP1, &address)) &&
1328 (err = vt1211_find(SIO_REG_CIP2, &address))) {
1332 if ((uch_config < -1) || (uch_config > 31)) {
1334 printk(KERN_WARNING DRVNAME ": Invalid UCH configuration %d. "
1335 "Choose a value between 0 and 31.\n", uch_config);
1339 if ((int_mode < -1) || (int_mode > 0)) {
1341 printk(KERN_WARNING DRVNAME ": Invalid interrupt mode %d. "
1342 "Only mode 0 is supported.\n", int_mode);
1346 err = platform_driver_register(&vt1211_driver);
1351 /* Sets global pdev as a side effect */
1352 err = vt1211_device_add(address);
1354 goto EXIT_DRV_UNREGISTER;
1359 EXIT_DRV_UNREGISTER:
1360 platform_driver_unregister(&vt1211_driver);
1365 static void __exit vt1211_exit(void)
1367 platform_device_unregister(pdev);
1368 platform_driver_unregister(&vt1211_driver);
1371 MODULE_AUTHOR("Juerg Haefliger <juergh@gmail.com>");
1372 MODULE_DESCRIPTION("VT1211 sensors");
1373 MODULE_LICENSE("GPL");
1375 module_init(vt1211_init);
1376 module_exit(vt1211_exit);