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 struct platform_device
*pdev
;
47 #define DRVNAME "vt1211"
49 /* ---------------------------------------------------------------------
52 * The sensors are defined as follows.
54 * Sensor Voltage Mode Temp Mode Notes (from the datasheet)
55 * -------- ------------ --------- --------------------------
56 * Reading 1 temp1 Intel thermal diode
57 * Reading 3 temp2 Internal thermal diode
58 * UCH1/Reading2 in0 temp3 NTC type thermistor
59 * UCH2 in1 temp4 +2.5V
63 * 3.3V in5 Internal VDD (+3.3V)
65 * --------------------------------------------------------------------- */
67 /* Voltages (in) numbered 0-5 (ix) */
68 #define VT1211_REG_IN(ix) (0x21 + (ix))
69 #define VT1211_REG_IN_MIN(ix) ((ix) == 0 ? 0x3e : 0x2a + 2 * (ix))
70 #define VT1211_REG_IN_MAX(ix) ((ix) == 0 ? 0x3d : 0x29 + 2 * (ix))
72 /* Temperatures (temp) numbered 0-6 (ix) */
73 static u8 regtemp
[] = {0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25};
74 static u8 regtempmax
[] = {0x39, 0x1d, 0x3d, 0x2b, 0x2d, 0x2f, 0x31};
75 static u8 regtemphyst
[] = {0x3a, 0x1e, 0x3e, 0x2c, 0x2e, 0x30, 0x32};
77 /* Fans numbered 0-1 (ix) */
78 #define VT1211_REG_FAN(ix) (0x29 + (ix))
79 #define VT1211_REG_FAN_MIN(ix) (0x3b + (ix))
80 #define VT1211_REG_FAN_DIV 0x47
82 /* PWMs numbered 0-1 (ix) */
83 /* Auto points numbered 0-3 (ap) */
84 #define VT1211_REG_PWM(ix) (0x60 + (ix))
85 #define VT1211_REG_PWM_CLK 0x50
86 #define VT1211_REG_PWM_CTL 0x51
87 #define VT1211_REG_PWM_AUTO_TEMP(ap) (0x55 - (ap))
88 #define VT1211_REG_PWM_AUTO_PWM(ix, ap) (0x58 + 2 * (ix) - (ap))
90 /* Miscellaneous registers */
91 #define VT1211_REG_CONFIG 0x40
92 #define VT1211_REG_ALARM1 0x41
93 #define VT1211_REG_ALARM2 0x42
94 #define VT1211_REG_VID 0x45
95 #define VT1211_REG_UCH_CONFIG 0x4a
96 #define VT1211_REG_TEMP1_CONFIG 0x4b
97 #define VT1211_REG_TEMP2_CONFIG 0x4c
99 /* In, temp & fan alarm bits */
100 static const u8 bitalarmin
[] = {11, 0, 1, 3, 8, 2, 9};
101 static const u8 bitalarmtemp
[] = {4, 15, 11, 0, 1, 3, 8};
102 static const u8 bitalarmfan
[] = {6, 7};
104 /* ---------------------------------------------------------------------
105 * Data structures and manipulation thereof
106 * --------------------------------------------------------------------- */
111 struct device
*hwmon_dev
;
113 struct mutex update_lock
;
114 char valid
; /* !=0 if following fields are valid */
115 unsigned long last_updated
; /* In jiffies */
117 /* Register values */
132 u8 pwm_auto_pwm
[2][4];
133 u8 vid
; /* Read once at init time */
135 u8 uch_config
; /* Read once at init time */
140 #define ISVOLT(ix, uch_config) ((ix) > 4 ? 1 : \
141 !(((uch_config) >> ((ix) + 2)) & 1))
144 #define ISTEMP(ix, uch_config) ((ix) < 2 ? 1 : \
145 ((uch_config) >> (ix)) & 1)
147 /* in5 (ix = 5) is special. It's the internal 3.3V so it's scaled in the
148 driver according to the VT1211 BIOS porting guide */
149 #define IN_FROM_REG(ix, reg) ((reg) < 3 ? 0 : (ix) == 5 ? \
150 (((reg) - 3) * 15882 + 479) / 958 : \
151 (((reg) - 3) * 10000 + 479) / 958)
152 #define IN_TO_REG(ix, val) (SENSORS_LIMIT((ix) == 5 ? \
153 ((val) * 958 + 7941) / 15882 + 3 : \
154 ((val) * 958 + 5000) / 10000 + 3, 0, 255))
156 /* temp1 (ix = 0) is an intel thermal diode which is scaled in user space.
157 temp2 (ix = 1) is the internal temp diode so it's scaled in the driver
158 according to some measurements that I took on an EPIA M10000.
159 temp3-7 are thermistor based so the driver returns the voltage measured at
160 the pin (range 0V - 2.2V). */
161 #define TEMP_FROM_REG(ix, reg) ((ix) == 0 ? (reg) * 1000 : \
162 (ix) == 1 ? (reg) < 51 ? 0 : \
163 ((reg) - 51) * 1000 : \
164 ((253 - (reg)) * 2200 + 105) / 210)
165 #define TEMP_TO_REG(ix, val) SENSORS_LIMIT( \
166 ((ix) == 0 ? ((val) + 500) / 1000 : \
167 (ix) == 1 ? ((val) + 500) / 1000 + 51 : \
168 253 - ((val) * 210 + 1100) / 2200), 0, 255)
170 #define DIV_FROM_REG(reg) (1 << (reg))
172 #define RPM_FROM_REG(reg, div) (((reg) == 0) || ((reg) == 255) ? 0 : \
173 1310720 / (reg) / DIV_FROM_REG(div))
174 #define RPM_TO_REG(val, div) ((val) == 0 ? 255 : \
175 SENSORS_LIMIT((1310720 / (val) / \
176 DIV_FROM_REG(div)), 1, 254))
178 /* ---------------------------------------------------------------------
179 * Super-I/O constants and functions
180 * --------------------------------------------------------------------- */
182 /* Configuration index port registers
183 * The vt1211 can live at 2 different addresses so we need to probe both */
184 #define SIO_REG_CIP1 0x2e
185 #define SIO_REG_CIP2 0x4e
187 /* Configuration registers */
188 #define SIO_VT1211_LDN 0x07 /* logical device number */
189 #define SIO_VT1211_DEVID 0x20 /* device ID */
190 #define SIO_VT1211_DEVREV 0x21 /* device revision */
191 #define SIO_VT1211_ACTIVE 0x30 /* HW monitor active */
192 #define SIO_VT1211_BADDR 0x60 /* base I/O address */
193 #define SIO_VT1211_ID 0x3c /* VT1211 device ID */
195 /* VT1211 logical device numbers */
196 #define SIO_VT1211_LDN_HWMON 0x0b /* HW monitor */
198 static inline void superio_outb(int sio_cip
, int reg
, int val
)
201 outb(val
, sio_cip
+ 1);
204 static inline int superio_inb(int sio_cip
, int reg
)
207 return inb(sio_cip
+ 1);
210 static inline void superio_select(int sio_cip
, int ldn
)
212 outb(SIO_VT1211_LDN
, sio_cip
);
213 outb(ldn
, sio_cip
+ 1);
216 static inline void superio_enter(int sio_cip
)
222 static inline void superio_exit(int sio_cip
)
227 /* ---------------------------------------------------------------------
229 * --------------------------------------------------------------------- */
231 static inline u8
vt1211_read8(struct vt1211_data
*data
, u8 reg
)
233 return inb(data
->addr
+ reg
);
236 static inline void vt1211_write8(struct vt1211_data
*data
, u8 reg
, u8 val
)
238 outb(val
, data
->addr
+ reg
);
241 static struct vt1211_data
*vt1211_update_device(struct device
*dev
)
243 struct vt1211_data
*data
= dev_get_drvdata(dev
);
246 mutex_lock(&data
->update_lock
);
248 /* registers cache is refreshed after 1 second */
249 if (time_after(jiffies
, data
->last_updated
+ HZ
) || !data
->valid
) {
251 data
->vid
= vt1211_read8(data
, VT1211_REG_VID
) & 0x1f;
253 /* voltage (in) registers */
254 for (ix
= 0; ix
< ARRAY_SIZE(data
->in
); ix
++) {
255 if (ISVOLT(ix
, data
->uch_config
)) {
256 data
->in
[ix
] = vt1211_read8(data
,
258 data
->in_min
[ix
] = vt1211_read8(data
,
259 VT1211_REG_IN_MIN(ix
));
260 data
->in_max
[ix
] = vt1211_read8(data
,
261 VT1211_REG_IN_MAX(ix
));
266 for (ix
= 0; ix
< ARRAY_SIZE(data
->temp
); ix
++) {
267 if (ISTEMP(ix
, data
->uch_config
)) {
268 data
->temp
[ix
] = vt1211_read8(data
,
270 data
->temp_max
[ix
] = vt1211_read8(data
,
272 data
->temp_hyst
[ix
] = vt1211_read8(data
,
277 /* fan & pwm registers */
278 for (ix
= 0; ix
< ARRAY_SIZE(data
->fan
); ix
++) {
279 data
->fan
[ix
] = vt1211_read8(data
,
281 data
->fan_min
[ix
] = vt1211_read8(data
,
282 VT1211_REG_FAN_MIN(ix
));
283 data
->pwm
[ix
] = vt1211_read8(data
,
286 val
= vt1211_read8(data
, VT1211_REG_FAN_DIV
);
287 data
->fan_div
[0] = (val
>> 4) & 3;
288 data
->fan_div
[1] = (val
>> 6) & 3;
289 data
->fan_ctl
= val
& 0xf;
291 val
= vt1211_read8(data
, VT1211_REG_PWM_CTL
);
292 data
->pwm_ctl
[0] = val
& 0xf;
293 data
->pwm_ctl
[1] = (val
>> 4) & 0xf;
295 data
->pwm_clk
= vt1211_read8(data
, VT1211_REG_PWM_CLK
);
297 /* pwm & temp auto point registers */
298 data
->pwm_auto_pwm
[0][1] = vt1211_read8(data
,
299 VT1211_REG_PWM_AUTO_PWM(0, 1));
300 data
->pwm_auto_pwm
[0][2] = vt1211_read8(data
,
301 VT1211_REG_PWM_AUTO_PWM(0, 2));
302 data
->pwm_auto_pwm
[1][1] = vt1211_read8(data
,
303 VT1211_REG_PWM_AUTO_PWM(1, 1));
304 data
->pwm_auto_pwm
[1][2] = vt1211_read8(data
,
305 VT1211_REG_PWM_AUTO_PWM(1, 2));
306 for (ix
= 0; ix
< ARRAY_SIZE(data
->pwm_auto_temp
); ix
++) {
307 data
->pwm_auto_temp
[ix
] = vt1211_read8(data
,
308 VT1211_REG_PWM_AUTO_TEMP(ix
));
311 /* alarm registers */
312 data
->alarms
= (vt1211_read8(data
, VT1211_REG_ALARM2
) << 8) |
313 vt1211_read8(data
, VT1211_REG_ALARM1
);
315 data
->last_updated
= jiffies
;
319 mutex_unlock(&data
->update_lock
);
324 /* ---------------------------------------------------------------------
325 * Voltage sysfs interfaces
327 * --------------------------------------------------------------------- */
329 #define SHOW_IN_INPUT 0
330 #define SHOW_SET_IN_MIN 1
331 #define SHOW_SET_IN_MAX 2
332 #define SHOW_IN_ALARM 3
334 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*attr
,
337 struct vt1211_data
*data
= vt1211_update_device(dev
);
338 struct sensor_device_attribute_2
*sensor_attr_2
=
339 to_sensor_dev_attr_2(attr
);
340 int ix
= sensor_attr_2
->index
;
341 int fn
= sensor_attr_2
->nr
;
346 res
= IN_FROM_REG(ix
, data
->in
[ix
]);
348 case SHOW_SET_IN_MIN
:
349 res
= IN_FROM_REG(ix
, data
->in_min
[ix
]);
351 case SHOW_SET_IN_MAX
:
352 res
= IN_FROM_REG(ix
, data
->in_max
[ix
]);
355 res
= (data
->alarms
>> bitalarmin
[ix
]) & 1;
359 dev_dbg(dev
, "Unknown attr fetch (%d)\n", fn
);
362 return sprintf(buf
, "%d\n", res
);
365 static ssize_t
set_in(struct device
*dev
, struct device_attribute
*attr
,
366 const char *buf
, size_t count
)
368 struct vt1211_data
*data
= dev_get_drvdata(dev
);
369 struct sensor_device_attribute_2
*sensor_attr_2
=
370 to_sensor_dev_attr_2(attr
);
371 int ix
= sensor_attr_2
->index
;
372 int fn
= sensor_attr_2
->nr
;
373 long val
= simple_strtol(buf
, NULL
, 10);
375 mutex_lock(&data
->update_lock
);
377 case SHOW_SET_IN_MIN
:
378 data
->in_min
[ix
] = IN_TO_REG(ix
, val
);
379 vt1211_write8(data
, VT1211_REG_IN_MIN(ix
), data
->in_min
[ix
]);
381 case SHOW_SET_IN_MAX
:
382 data
->in_max
[ix
] = IN_TO_REG(ix
, val
);
383 vt1211_write8(data
, VT1211_REG_IN_MAX(ix
), data
->in_max
[ix
]);
386 dev_dbg(dev
, "Unknown attr fetch (%d)\n", fn
);
388 mutex_unlock(&data
->update_lock
);
393 /* ---------------------------------------------------------------------
394 * Temperature sysfs interfaces
396 * --------------------------------------------------------------------- */
398 #define SHOW_TEMP_INPUT 0
399 #define SHOW_SET_TEMP_MAX 1
400 #define SHOW_SET_TEMP_MAX_HYST 2
401 #define SHOW_TEMP_ALARM 3
403 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
*attr
,
406 struct vt1211_data
*data
= vt1211_update_device(dev
);
407 struct sensor_device_attribute_2
*sensor_attr_2
=
408 to_sensor_dev_attr_2(attr
);
409 int ix
= sensor_attr_2
->index
;
410 int fn
= sensor_attr_2
->nr
;
414 case SHOW_TEMP_INPUT
:
415 res
= TEMP_FROM_REG(ix
, data
->temp
[ix
]);
417 case SHOW_SET_TEMP_MAX
:
418 res
= TEMP_FROM_REG(ix
, data
->temp_max
[ix
]);
420 case SHOW_SET_TEMP_MAX_HYST
:
421 res
= TEMP_FROM_REG(ix
, data
->temp_hyst
[ix
]);
423 case SHOW_TEMP_ALARM
:
424 res
= (data
->alarms
>> bitalarmtemp
[ix
]) & 1;
428 dev_dbg(dev
, "Unknown attr fetch (%d)\n", fn
);
431 return sprintf(buf
, "%d\n", res
);
434 static ssize_t
set_temp(struct device
*dev
, struct device_attribute
*attr
,
435 const char *buf
, size_t count
)
437 struct vt1211_data
*data
= dev_get_drvdata(dev
);
438 struct sensor_device_attribute_2
*sensor_attr_2
=
439 to_sensor_dev_attr_2(attr
);
440 int ix
= sensor_attr_2
->index
;
441 int fn
= sensor_attr_2
->nr
;
442 long val
= simple_strtol(buf
, NULL
, 10);
444 mutex_lock(&data
->update_lock
);
446 case SHOW_SET_TEMP_MAX
:
447 data
->temp_max
[ix
] = TEMP_TO_REG(ix
, val
);
448 vt1211_write8(data
, regtempmax
[ix
],
451 case SHOW_SET_TEMP_MAX_HYST
:
452 data
->temp_hyst
[ix
] = TEMP_TO_REG(ix
, val
);
453 vt1211_write8(data
, regtemphyst
[ix
],
454 data
->temp_hyst
[ix
]);
457 dev_dbg(dev
, "Unknown attr fetch (%d)\n", fn
);
459 mutex_unlock(&data
->update_lock
);
464 /* ---------------------------------------------------------------------
465 * Fan sysfs interfaces
467 * --------------------------------------------------------------------- */
469 #define SHOW_FAN_INPUT 0
470 #define SHOW_SET_FAN_MIN 1
471 #define SHOW_SET_FAN_DIV 2
472 #define SHOW_FAN_ALARM 3
474 static ssize_t
show_fan(struct device
*dev
, struct device_attribute
*attr
,
477 struct vt1211_data
*data
= vt1211_update_device(dev
);
478 struct sensor_device_attribute_2
*sensor_attr_2
=
479 to_sensor_dev_attr_2(attr
);
480 int ix
= sensor_attr_2
->index
;
481 int fn
= sensor_attr_2
->nr
;
486 res
= RPM_FROM_REG(data
->fan
[ix
], data
->fan_div
[ix
]);
488 case SHOW_SET_FAN_MIN
:
489 res
= RPM_FROM_REG(data
->fan_min
[ix
], data
->fan_div
[ix
]);
491 case SHOW_SET_FAN_DIV
:
492 res
= DIV_FROM_REG(data
->fan_div
[ix
]);
495 res
= (data
->alarms
>> bitalarmfan
[ix
]) & 1;
499 dev_dbg(dev
, "Unknown attr fetch (%d)\n", fn
);
502 return sprintf(buf
, "%d\n", res
);
505 static ssize_t
set_fan(struct device
*dev
, struct device_attribute
*attr
,
506 const char *buf
, size_t count
)
508 struct vt1211_data
*data
= dev_get_drvdata(dev
);
509 struct sensor_device_attribute_2
*sensor_attr_2
=
510 to_sensor_dev_attr_2(attr
);
511 int ix
= sensor_attr_2
->index
;
512 int fn
= sensor_attr_2
->nr
;
513 long val
= simple_strtol(buf
, NULL
, 10);
516 mutex_lock(&data
->update_lock
);
518 /* sync the data cache */
519 reg
= vt1211_read8(data
, VT1211_REG_FAN_DIV
);
520 data
->fan_div
[0] = (reg
>> 4) & 3;
521 data
->fan_div
[1] = (reg
>> 6) & 3;
522 data
->fan_ctl
= reg
& 0xf;
525 case SHOW_SET_FAN_MIN
:
526 data
->fan_min
[ix
] = RPM_TO_REG(val
, data
->fan_div
[ix
]);
527 vt1211_write8(data
, VT1211_REG_FAN_MIN(ix
),
530 case SHOW_SET_FAN_DIV
:
532 case 1: data
->fan_div
[ix
] = 0; break;
533 case 2: data
->fan_div
[ix
] = 1; break;
534 case 4: data
->fan_div
[ix
] = 2; break;
535 case 8: data
->fan_div
[ix
] = 3; break;
538 dev_warn(dev
, "fan div value %ld not "
539 "supported. Choose one of 1, 2, "
543 vt1211_write8(data
, VT1211_REG_FAN_DIV
,
544 ((data
->fan_div
[1] << 6) |
545 (data
->fan_div
[0] << 4) |
549 dev_dbg(dev
, "Unknown attr fetch (%d)\n", fn
);
553 mutex_unlock(&data
->update_lock
);
557 /* ---------------------------------------------------------------------
558 * PWM sysfs interfaces
560 * --------------------------------------------------------------------- */
563 #define SHOW_SET_PWM_ENABLE 1
564 #define SHOW_SET_PWM_FREQ 2
565 #define SHOW_SET_PWM_AUTO_CHANNELS_TEMP 3
567 static ssize_t
show_pwm(struct device
*dev
, struct device_attribute
*attr
,
570 struct vt1211_data
*data
= vt1211_update_device(dev
);
571 struct sensor_device_attribute_2
*sensor_attr_2
=
572 to_sensor_dev_attr_2(attr
);
573 int ix
= sensor_attr_2
->index
;
574 int fn
= sensor_attr_2
->nr
;
581 case SHOW_SET_PWM_ENABLE
:
582 res
= ((data
->pwm_ctl
[ix
] >> 3) & 1) ? 2 : 0;
584 case SHOW_SET_PWM_FREQ
:
585 res
= 90000 >> (data
->pwm_clk
& 7);
587 case SHOW_SET_PWM_AUTO_CHANNELS_TEMP
:
588 res
= (data
->pwm_ctl
[ix
] & 7) + 1;
592 dev_dbg(dev
, "Unknown attr fetch (%d)\n", fn
);
595 return sprintf(buf
, "%d\n", res
);
598 static ssize_t
set_pwm(struct device
*dev
, struct device_attribute
*attr
,
599 const char *buf
, size_t count
)
601 struct vt1211_data
*data
= dev_get_drvdata(dev
);
602 struct sensor_device_attribute_2
*sensor_attr_2
=
603 to_sensor_dev_attr_2(attr
);
604 int ix
= sensor_attr_2
->index
;
605 int fn
= sensor_attr_2
->nr
;
606 long val
= simple_strtol(buf
, NULL
, 10);
609 mutex_lock(&data
->update_lock
);
612 case SHOW_SET_PWM_ENABLE
:
613 /* sync the data cache */
614 reg
= vt1211_read8(data
, VT1211_REG_FAN_DIV
);
615 data
->fan_div
[0] = (reg
>> 4) & 3;
616 data
->fan_div
[1] = (reg
>> 6) & 3;
617 data
->fan_ctl
= reg
& 0xf;
618 reg
= vt1211_read8(data
, VT1211_REG_PWM_CTL
);
619 data
->pwm_ctl
[0] = reg
& 0xf;
620 data
->pwm_ctl
[1] = (reg
>> 4) & 0xf;
623 data
->pwm_ctl
[ix
] &= 7;
624 /* disable SmartGuardian if both PWM outputs are
626 if ((data
->pwm_ctl
[ix
^ 1] & 1) == 0) {
627 data
->fan_ctl
&= 0xe;
631 data
->pwm_ctl
[ix
] |= 8;
636 dev_warn(dev
, "pwm mode %ld not supported. "
637 "Choose one of 0 or 2.\n", val
);
640 vt1211_write8(data
, VT1211_REG_PWM_CTL
,
641 ((data
->pwm_ctl
[1] << 4) |
643 vt1211_write8(data
, VT1211_REG_FAN_DIV
,
644 ((data
->fan_div
[1] << 6) |
645 (data
->fan_div
[0] << 4) |
648 case SHOW_SET_PWM_FREQ
:
649 val
= 135000 / SENSORS_LIMIT(val
, 135000 >> 7, 135000);
650 /* calculate tmp = log2(val) */
652 for (val
>>= 1; val
> 0; val
>>= 1) {
655 /* sync the data cache */
656 reg
= vt1211_read8(data
, VT1211_REG_PWM_CLK
);
657 data
->pwm_clk
= (reg
& 0xf8) | tmp
;
658 vt1211_write8(data
, VT1211_REG_PWM_CLK
, data
->pwm_clk
);
660 case SHOW_SET_PWM_AUTO_CHANNELS_TEMP
:
661 if ((val
< 1) || (val
> 7)) {
663 dev_warn(dev
, "temp channel %ld not supported. "
664 "Choose a value between 1 and 7.\n", val
);
667 if (!ISTEMP(val
- 1, data
->uch_config
)) {
669 dev_warn(dev
, "temp channel %ld is not available.\n",
673 /* sync the data cache */
674 reg
= vt1211_read8(data
, VT1211_REG_PWM_CTL
);
675 data
->pwm_ctl
[0] = reg
& 0xf;
676 data
->pwm_ctl
[1] = (reg
>> 4) & 0xf;
677 data
->pwm_ctl
[ix
] = (data
->pwm_ctl
[ix
] & 8) | (val
- 1);
678 vt1211_write8(data
, VT1211_REG_PWM_CTL
,
679 ((data
->pwm_ctl
[1] << 4) | data
->pwm_ctl
[0]));
682 dev_dbg(dev
, "Unknown attr fetch (%d)\n", fn
);
686 mutex_unlock(&data
->update_lock
);
690 /* ---------------------------------------------------------------------
691 * PWM auto point definitions
694 * --------------------------------------------------------------------- */
697 * pwm[ix+1]_auto_point[ap+1]_temp mapping table:
698 * Note that there is only a single set of temp auto points that controls both
699 * PWM controllers. We still create 2 sets of sysfs files to make it look
700 * more consistent even though they map to the same registers.
702 * ix ap : description
703 * -------------------
704 * 0 0 : pwm1/2 off temperature (pwm_auto_temp[0])
705 * 0 1 : pwm1/2 low speed temperature (pwm_auto_temp[1])
706 * 0 2 : pwm1/2 high speed temperature (pwm_auto_temp[2])
707 * 0 3 : pwm1/2 full speed temperature (pwm_auto_temp[3])
708 * 1 0 : pwm1/2 off temperature (pwm_auto_temp[0])
709 * 1 1 : pwm1/2 low speed temperature (pwm_auto_temp[1])
710 * 1 2 : pwm1/2 high speed temperature (pwm_auto_temp[2])
711 * 1 3 : pwm1/2 full speed temperature (pwm_auto_temp[3])
714 static ssize_t
show_pwm_auto_point_temp(struct device
*dev
,
715 struct device_attribute
*attr
,
718 struct vt1211_data
*data
= vt1211_update_device(dev
);
719 struct sensor_device_attribute_2
*sensor_attr_2
=
720 to_sensor_dev_attr_2(attr
);
721 int ix
= sensor_attr_2
->index
;
722 int ap
= sensor_attr_2
->nr
;
724 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->pwm_ctl
[ix
] & 7,
725 data
->pwm_auto_temp
[ap
]));
728 static ssize_t
set_pwm_auto_point_temp(struct device
*dev
,
729 struct device_attribute
*attr
,
730 const char *buf
, size_t count
)
732 struct vt1211_data
*data
= dev_get_drvdata(dev
);
733 struct sensor_device_attribute_2
*sensor_attr_2
=
734 to_sensor_dev_attr_2(attr
);
735 int ix
= sensor_attr_2
->index
;
736 int ap
= sensor_attr_2
->nr
;
737 long val
= simple_strtol(buf
, NULL
, 10);
740 mutex_lock(&data
->update_lock
);
742 /* sync the data cache */
743 reg
= vt1211_read8(data
, VT1211_REG_PWM_CTL
);
744 data
->pwm_ctl
[0] = reg
& 0xf;
745 data
->pwm_ctl
[1] = (reg
>> 4) & 0xf;
747 data
->pwm_auto_temp
[ap
] = TEMP_TO_REG(data
->pwm_ctl
[ix
] & 7, val
);
748 vt1211_write8(data
, VT1211_REG_PWM_AUTO_TEMP(ap
),
749 data
->pwm_auto_temp
[ap
]);
750 mutex_unlock(&data
->update_lock
);
756 * pwm[ix+1]_auto_point[ap+1]_pwm mapping table:
757 * Note that the PWM auto points 0 & 3 are hard-wired in the VT1211 and can't
760 * ix ap : description
761 * -------------------
762 * 0 0 : pwm1 off (pwm_auto_pwm[0][0], hard-wired to 0)
763 * 0 1 : pwm1 low speed duty cycle (pwm_auto_pwm[0][1])
764 * 0 2 : pwm1 high speed duty cycle (pwm_auto_pwm[0][2])
765 * 0 3 : pwm1 full speed (pwm_auto_pwm[0][3], hard-wired to 255)
766 * 1 0 : pwm2 off (pwm_auto_pwm[1][0], hard-wired to 0)
767 * 1 1 : pwm2 low speed duty cycle (pwm_auto_pwm[1][1])
768 * 1 2 : pwm2 high speed duty cycle (pwm_auto_pwm[1][2])
769 * 1 3 : pwm2 full speed (pwm_auto_pwm[1][3], hard-wired to 255)
772 static ssize_t
show_pwm_auto_point_pwm(struct device
*dev
,
773 struct device_attribute
*attr
,
776 struct vt1211_data
*data
= vt1211_update_device(dev
);
777 struct sensor_device_attribute_2
*sensor_attr_2
=
778 to_sensor_dev_attr_2(attr
);
779 int ix
= sensor_attr_2
->index
;
780 int ap
= sensor_attr_2
->nr
;
782 return sprintf(buf
, "%d\n", data
->pwm_auto_pwm
[ix
][ap
]);
785 static ssize_t
set_pwm_auto_point_pwm(struct device
*dev
,
786 struct device_attribute
*attr
,
787 const char *buf
, size_t count
)
789 struct vt1211_data
*data
= dev_get_drvdata(dev
);
790 struct sensor_device_attribute_2
*sensor_attr_2
=
791 to_sensor_dev_attr_2(attr
);
792 int ix
= sensor_attr_2
->index
;
793 int ap
= sensor_attr_2
->nr
;
794 long val
= simple_strtol(buf
, NULL
, 10);
796 if ((val
< 0) || (val
> 255)) {
797 dev_err(dev
, "pwm value %ld is out of range. "
798 "Choose a value between 0 and 255.\n" , val
);
802 mutex_lock(&data
->update_lock
);
803 data
->pwm_auto_pwm
[ix
][ap
] = val
;
804 vt1211_write8(data
, VT1211_REG_PWM_AUTO_PWM(ix
, ap
),
805 data
->pwm_auto_pwm
[ix
][ap
]);
806 mutex_unlock(&data
->update_lock
);
811 /* ---------------------------------------------------------------------
812 * Miscellaneous sysfs interfaces (VRM, VID, name, and (legacy) alarms)
813 * --------------------------------------------------------------------- */
815 static ssize_t
show_vrm(struct device
*dev
, struct device_attribute
*attr
,
818 struct vt1211_data
*data
= dev_get_drvdata(dev
);
820 return sprintf(buf
, "%d\n", data
->vrm
);
823 static ssize_t
set_vrm(struct device
*dev
, struct device_attribute
*attr
,
824 const char *buf
, size_t count
)
826 struct vt1211_data
*data
= dev_get_drvdata(dev
);
827 long val
= simple_strtol(buf
, NULL
, 10);
834 static ssize_t
show_vid(struct device
*dev
, struct device_attribute
*attr
,
837 struct vt1211_data
*data
= dev_get_drvdata(dev
);
839 return sprintf(buf
, "%d\n", vid_from_reg(data
->vid
, data
->vrm
));
842 static ssize_t
show_name(struct device
*dev
,
843 struct device_attribute
*attr
, char *buf
)
845 struct vt1211_data
*data
= dev_get_drvdata(dev
);
847 return sprintf(buf
, "%s\n", data
->name
);
850 static ssize_t
show_alarms(struct device
*dev
,
851 struct device_attribute
*attr
, char *buf
)
853 struct vt1211_data
*data
= vt1211_update_device(dev
);
855 return sprintf(buf
, "%d\n", data
->alarms
);
858 /* ---------------------------------------------------------------------
859 * Device attribute structs
860 * --------------------------------------------------------------------- */
862 #define SENSOR_ATTR_IN_INPUT(ix) \
863 SENSOR_ATTR_2(in##ix##_input, S_IRUGO, \
864 show_in, NULL, SHOW_IN_INPUT, ix)
866 static struct sensor_device_attribute_2 vt1211_sysfs_in_input
[] = {
867 SENSOR_ATTR_IN_INPUT(0),
868 SENSOR_ATTR_IN_INPUT(1),
869 SENSOR_ATTR_IN_INPUT(2),
870 SENSOR_ATTR_IN_INPUT(3),
871 SENSOR_ATTR_IN_INPUT(4),
872 SENSOR_ATTR_IN_INPUT(5),
875 #define SENSOR_ATTR_IN_MIN(ix) \
876 SENSOR_ATTR_2(in##ix##_min, S_IRUGO | S_IWUSR, \
877 show_in, set_in, SHOW_SET_IN_MIN, ix)
879 static struct sensor_device_attribute_2 vt1211_sysfs_in_min
[] = {
880 SENSOR_ATTR_IN_MIN(0),
881 SENSOR_ATTR_IN_MIN(1),
882 SENSOR_ATTR_IN_MIN(2),
883 SENSOR_ATTR_IN_MIN(3),
884 SENSOR_ATTR_IN_MIN(4),
885 SENSOR_ATTR_IN_MIN(5),
888 #define SENSOR_ATTR_IN_MAX(ix) \
889 SENSOR_ATTR_2(in##ix##_max, S_IRUGO | S_IWUSR, \
890 show_in, set_in, SHOW_SET_IN_MAX, ix)
892 static struct sensor_device_attribute_2 vt1211_sysfs_in_max
[] = {
893 SENSOR_ATTR_IN_MAX(0),
894 SENSOR_ATTR_IN_MAX(1),
895 SENSOR_ATTR_IN_MAX(2),
896 SENSOR_ATTR_IN_MAX(3),
897 SENSOR_ATTR_IN_MAX(4),
898 SENSOR_ATTR_IN_MAX(5),
901 #define SENSOR_ATTR_IN_ALARM(ix) \
902 SENSOR_ATTR_2(in##ix##_alarm, S_IRUGO, \
903 show_in, NULL, SHOW_IN_ALARM, ix)
905 static struct sensor_device_attribute_2 vt1211_sysfs_in_alarm
[] = {
906 SENSOR_ATTR_IN_ALARM(0),
907 SENSOR_ATTR_IN_ALARM(1),
908 SENSOR_ATTR_IN_ALARM(2),
909 SENSOR_ATTR_IN_ALARM(3),
910 SENSOR_ATTR_IN_ALARM(4),
911 SENSOR_ATTR_IN_ALARM(5),
914 #define SENSOR_ATTR_TEMP_INPUT(ix) \
915 SENSOR_ATTR_2(temp##ix##_input, S_IRUGO, \
916 show_temp, NULL, SHOW_TEMP_INPUT, ix-1)
918 static struct sensor_device_attribute_2 vt1211_sysfs_temp_input
[] = {
919 SENSOR_ATTR_TEMP_INPUT(1),
920 SENSOR_ATTR_TEMP_INPUT(2),
921 SENSOR_ATTR_TEMP_INPUT(3),
922 SENSOR_ATTR_TEMP_INPUT(4),
923 SENSOR_ATTR_TEMP_INPUT(5),
924 SENSOR_ATTR_TEMP_INPUT(6),
925 SENSOR_ATTR_TEMP_INPUT(7),
928 #define SENSOR_ATTR_TEMP_MAX(ix) \
929 SENSOR_ATTR_2(temp##ix##_max, S_IRUGO | S_IWUSR, \
930 show_temp, set_temp, SHOW_SET_TEMP_MAX, ix-1)
932 static struct sensor_device_attribute_2 vt1211_sysfs_temp_max
[] = {
933 SENSOR_ATTR_TEMP_MAX(1),
934 SENSOR_ATTR_TEMP_MAX(2),
935 SENSOR_ATTR_TEMP_MAX(3),
936 SENSOR_ATTR_TEMP_MAX(4),
937 SENSOR_ATTR_TEMP_MAX(5),
938 SENSOR_ATTR_TEMP_MAX(6),
939 SENSOR_ATTR_TEMP_MAX(7),
942 #define SENSOR_ATTR_TEMP_MAX_HYST(ix) \
943 SENSOR_ATTR_2(temp##ix##_max_hyst, S_IRUGO | S_IWUSR, \
944 show_temp, set_temp, SHOW_SET_TEMP_MAX_HYST, ix-1)
946 static struct sensor_device_attribute_2 vt1211_sysfs_temp_max_hyst
[] = {
947 SENSOR_ATTR_TEMP_MAX_HYST(1),
948 SENSOR_ATTR_TEMP_MAX_HYST(2),
949 SENSOR_ATTR_TEMP_MAX_HYST(3),
950 SENSOR_ATTR_TEMP_MAX_HYST(4),
951 SENSOR_ATTR_TEMP_MAX_HYST(5),
952 SENSOR_ATTR_TEMP_MAX_HYST(6),
953 SENSOR_ATTR_TEMP_MAX_HYST(7),
956 #define SENSOR_ATTR_TEMP_ALARM(ix) \
957 SENSOR_ATTR_2(temp##ix##_alarm, S_IRUGO, \
958 show_temp, NULL, SHOW_TEMP_ALARM, ix-1)
960 static struct sensor_device_attribute_2 vt1211_sysfs_temp_alarm
[] = {
961 SENSOR_ATTR_TEMP_ALARM(1),
962 SENSOR_ATTR_TEMP_ALARM(2),
963 SENSOR_ATTR_TEMP_ALARM(3),
964 SENSOR_ATTR_TEMP_ALARM(4),
965 SENSOR_ATTR_TEMP_ALARM(5),
966 SENSOR_ATTR_TEMP_ALARM(6),
967 SENSOR_ATTR_TEMP_ALARM(7),
970 #define SENSOR_ATTR_FAN(ix) \
971 SENSOR_ATTR_2(fan##ix##_input, S_IRUGO, \
972 show_fan, NULL, SHOW_FAN_INPUT, ix-1), \
973 SENSOR_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \
974 show_fan, set_fan, SHOW_SET_FAN_MIN, ix-1), \
975 SENSOR_ATTR_2(fan##ix##_div, S_IRUGO | S_IWUSR, \
976 show_fan, set_fan, SHOW_SET_FAN_DIV, ix-1), \
977 SENSOR_ATTR_2(fan##ix##_alarm, S_IRUGO, \
978 show_fan, NULL, SHOW_FAN_ALARM, ix-1)
980 #define SENSOR_ATTR_PWM(ix) \
981 SENSOR_ATTR_2(pwm##ix, S_IRUGO, \
982 show_pwm, NULL, SHOW_PWM, ix-1), \
983 SENSOR_ATTR_2(pwm##ix##_enable, S_IRUGO | S_IWUSR, \
984 show_pwm, set_pwm, SHOW_SET_PWM_ENABLE, ix-1), \
985 SENSOR_ATTR_2(pwm##ix##_auto_channels_temp, S_IRUGO | S_IWUSR, \
986 show_pwm, set_pwm, SHOW_SET_PWM_AUTO_CHANNELS_TEMP, ix-1)
988 #define SENSOR_ATTR_PWM_FREQ(ix) \
989 SENSOR_ATTR_2(pwm##ix##_freq, S_IRUGO | S_IWUSR, \
990 show_pwm, set_pwm, SHOW_SET_PWM_FREQ, ix-1)
992 #define SENSOR_ATTR_PWM_FREQ_RO(ix) \
993 SENSOR_ATTR_2(pwm##ix##_freq, S_IRUGO, \
994 show_pwm, NULL, SHOW_SET_PWM_FREQ, ix-1)
996 #define SENSOR_ATTR_PWM_AUTO_POINT_TEMP(ix, ap) \
997 SENSOR_ATTR_2(pwm##ix##_auto_point##ap##_temp, S_IRUGO | S_IWUSR, \
998 show_pwm_auto_point_temp, set_pwm_auto_point_temp, \
1001 #define SENSOR_ATTR_PWM_AUTO_POINT_TEMP_RO(ix, ap) \
1002 SENSOR_ATTR_2(pwm##ix##_auto_point##ap##_temp, S_IRUGO, \
1003 show_pwm_auto_point_temp, NULL, \
1006 #define SENSOR_ATTR_PWM_AUTO_POINT_PWM(ix, ap) \
1007 SENSOR_ATTR_2(pwm##ix##_auto_point##ap##_pwm, S_IRUGO | S_IWUSR, \
1008 show_pwm_auto_point_pwm, set_pwm_auto_point_pwm, \
1011 #define SENSOR_ATTR_PWM_AUTO_POINT_PWM_RO(ix, ap) \
1012 SENSOR_ATTR_2(pwm##ix##_auto_point##ap##_pwm, S_IRUGO, \
1013 show_pwm_auto_point_pwm, NULL, \
1016 static struct sensor_device_attribute_2 vt1211_sysfs_fan_pwm
[] = {
1021 SENSOR_ATTR_PWM_FREQ(1),
1022 SENSOR_ATTR_PWM_FREQ_RO(2),
1023 SENSOR_ATTR_PWM_AUTO_POINT_TEMP(1, 1),
1024 SENSOR_ATTR_PWM_AUTO_POINT_TEMP(1, 2),
1025 SENSOR_ATTR_PWM_AUTO_POINT_TEMP(1, 3),
1026 SENSOR_ATTR_PWM_AUTO_POINT_TEMP(1, 4),
1027 SENSOR_ATTR_PWM_AUTO_POINT_TEMP_RO(2, 1),
1028 SENSOR_ATTR_PWM_AUTO_POINT_TEMP_RO(2, 2),
1029 SENSOR_ATTR_PWM_AUTO_POINT_TEMP_RO(2, 3),
1030 SENSOR_ATTR_PWM_AUTO_POINT_TEMP_RO(2, 4),
1031 SENSOR_ATTR_PWM_AUTO_POINT_PWM_RO(1, 1),
1032 SENSOR_ATTR_PWM_AUTO_POINT_PWM(1, 2),
1033 SENSOR_ATTR_PWM_AUTO_POINT_PWM(1, 3),
1034 SENSOR_ATTR_PWM_AUTO_POINT_PWM_RO(1, 4),
1035 SENSOR_ATTR_PWM_AUTO_POINT_PWM_RO(2, 1),
1036 SENSOR_ATTR_PWM_AUTO_POINT_PWM(2, 2),
1037 SENSOR_ATTR_PWM_AUTO_POINT_PWM(2, 3),
1038 SENSOR_ATTR_PWM_AUTO_POINT_PWM_RO(2, 4),
1041 static struct device_attribute vt1211_sysfs_misc
[] = {
1042 __ATTR(vrm
, S_IRUGO
| S_IWUSR
, show_vrm
, set_vrm
),
1043 __ATTR(cpu0_vid
, S_IRUGO
, show_vid
, NULL
),
1044 __ATTR(name
, S_IRUGO
, show_name
, NULL
),
1045 __ATTR(alarms
, S_IRUGO
, show_alarms
, NULL
),
1048 /* ---------------------------------------------------------------------
1049 * Device registration and initialization
1050 * --------------------------------------------------------------------- */
1052 static void __devinit
vt1211_init_device(struct vt1211_data
*data
)
1055 data
->vrm
= vid_which_vrm();
1057 /* Read (and initialize) UCH config */
1058 data
->uch_config
= vt1211_read8(data
, VT1211_REG_UCH_CONFIG
);
1059 if (uch_config
> -1) {
1060 data
->uch_config
= (data
->uch_config
& 0x83) |
1062 vt1211_write8(data
, VT1211_REG_UCH_CONFIG
, data
->uch_config
);
1065 /* Initialize the interrupt mode (if request at module load time).
1066 * The VT1211 implements 3 different modes for clearing interrupts:
1067 * 0: Clear INT when status register is read. Regenerate INT as long
1068 * as temp stays above hysteresis limit.
1069 * 1: Clear INT when status register is read. DON'T regenerate INT
1070 * until temp falls below hysteresis limit and exceeds hot limit
1072 * 2: Clear INT when temp falls below max limit.
1074 * The driver only allows to force mode 0 since that's the only one
1075 * that makes sense for 'sensors' */
1076 if (int_mode
== 0) {
1077 vt1211_write8(data
, VT1211_REG_TEMP1_CONFIG
, 0);
1078 vt1211_write8(data
, VT1211_REG_TEMP2_CONFIG
, 0);
1081 /* Fill in some hard wired values into our data struct */
1082 data
->pwm_auto_pwm
[0][3] = 255;
1083 data
->pwm_auto_pwm
[1][3] = 255;
1086 static void vt1211_remove_sysfs(struct platform_device
*pdev
)
1088 struct device
*dev
= &pdev
->dev
;
1091 for (i
= 0; i
< ARRAY_SIZE(vt1211_sysfs_in_input
); i
++) {
1092 device_remove_file(dev
,
1093 &vt1211_sysfs_in_input
[i
].dev_attr
);
1094 device_remove_file(dev
,
1095 &vt1211_sysfs_in_min
[i
].dev_attr
);
1096 device_remove_file(dev
,
1097 &vt1211_sysfs_in_max
[i
].dev_attr
);
1098 device_remove_file(dev
,
1099 &vt1211_sysfs_in_alarm
[i
].dev_attr
);
1101 for (i
= 0; i
< ARRAY_SIZE(vt1211_sysfs_temp_input
); i
++) {
1102 device_remove_file(dev
,
1103 &vt1211_sysfs_temp_input
[i
].dev_attr
);
1104 device_remove_file(dev
,
1105 &vt1211_sysfs_temp_max
[i
].dev_attr
);
1106 device_remove_file(dev
,
1107 &vt1211_sysfs_temp_max_hyst
[i
].dev_attr
);
1108 device_remove_file(dev
,
1109 &vt1211_sysfs_temp_alarm
[i
].dev_attr
);
1111 for (i
= 0; i
< ARRAY_SIZE(vt1211_sysfs_fan_pwm
); i
++) {
1112 device_remove_file(dev
,
1113 &vt1211_sysfs_fan_pwm
[i
].dev_attr
);
1115 for (i
= 0; i
< ARRAY_SIZE(vt1211_sysfs_misc
); i
++) {
1116 device_remove_file(dev
, &vt1211_sysfs_misc
[i
]);
1120 static int __devinit
vt1211_probe(struct platform_device
*pdev
)
1122 struct device
*dev
= &pdev
->dev
;
1123 struct vt1211_data
*data
;
1124 struct resource
*res
;
1127 if (!(data
= kzalloc(sizeof(struct vt1211_data
), GFP_KERNEL
))) {
1129 dev_err(dev
, "Out of memory\n");
1133 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
1134 if (!request_region(res
->start
, res
->end
- res
->start
+ 1, DRVNAME
)) {
1136 dev_err(dev
, "Failed to request region 0x%lx-0x%lx\n",
1137 (unsigned long)res
->start
, (unsigned long)res
->end
);
1140 data
->addr
= res
->start
;
1141 data
->name
= DRVNAME
;
1142 mutex_init(&data
->update_lock
);
1144 platform_set_drvdata(pdev
, data
);
1146 /* Initialize the VT1211 chip */
1147 vt1211_init_device(data
);
1149 /* Create sysfs interface files */
1150 for (i
= 0; i
< ARRAY_SIZE(vt1211_sysfs_in_input
); i
++) {
1151 if (ISVOLT(i
, data
->uch_config
)) {
1152 if ((err
= device_create_file(dev
,
1153 &vt1211_sysfs_in_input
[i
].dev_attr
)) ||
1154 (err
= device_create_file(dev
,
1155 &vt1211_sysfs_in_min
[i
].dev_attr
)) ||
1156 (err
= device_create_file(dev
,
1157 &vt1211_sysfs_in_max
[i
].dev_attr
)) ||
1158 (err
= device_create_file(dev
,
1159 &vt1211_sysfs_in_alarm
[i
].dev_attr
))) {
1160 goto EXIT_DEV_REMOVE
;
1164 for (i
= 0; i
< ARRAY_SIZE(vt1211_sysfs_temp_input
); i
++) {
1165 if (ISTEMP(i
, data
->uch_config
)) {
1166 if ((err
= device_create_file(dev
,
1167 &vt1211_sysfs_temp_input
[i
].dev_attr
)) ||
1168 (err
= device_create_file(dev
,
1169 &vt1211_sysfs_temp_max
[i
].dev_attr
)) ||
1170 (err
= device_create_file(dev
,
1171 &vt1211_sysfs_temp_max_hyst
[i
].dev_attr
)) ||
1172 (err
= device_create_file(dev
,
1173 &vt1211_sysfs_temp_alarm
[i
].dev_attr
))) {
1174 goto EXIT_DEV_REMOVE
;
1178 for (i
= 0; i
< ARRAY_SIZE(vt1211_sysfs_fan_pwm
); i
++) {
1179 err
= device_create_file(dev
,
1180 &vt1211_sysfs_fan_pwm
[i
].dev_attr
);
1182 goto EXIT_DEV_REMOVE
;
1185 for (i
= 0; i
< ARRAY_SIZE(vt1211_sysfs_misc
); i
++) {
1186 err
= device_create_file(dev
,
1187 &vt1211_sysfs_misc
[i
]);
1189 goto EXIT_DEV_REMOVE
;
1193 /* Register device */
1194 data
->hwmon_dev
= hwmon_device_register(dev
);
1195 if (IS_ERR(data
->hwmon_dev
)) {
1196 err
= PTR_ERR(data
->hwmon_dev
);
1197 dev_err(dev
, "Class registration failed (%d)\n", err
);
1198 goto EXIT_DEV_REMOVE_SILENT
;
1204 dev_err(dev
, "Sysfs interface creation failed (%d)\n", err
);
1205 EXIT_DEV_REMOVE_SILENT
:
1206 vt1211_remove_sysfs(pdev
);
1207 release_region(res
->start
, res
->end
- res
->start
+ 1);
1209 platform_set_drvdata(pdev
, NULL
);
1215 static int __devexit
vt1211_remove(struct platform_device
*pdev
)
1217 struct vt1211_data
*data
= platform_get_drvdata(pdev
);
1218 struct resource
*res
;
1220 hwmon_device_unregister(data
->hwmon_dev
);
1221 vt1211_remove_sysfs(pdev
);
1222 platform_set_drvdata(pdev
, NULL
);
1225 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
1226 release_region(res
->start
, res
->end
- res
->start
+ 1);
1231 static struct platform_driver vt1211_driver
= {
1233 .owner
= THIS_MODULE
,
1236 .probe
= vt1211_probe
,
1237 .remove
= __devexit_p(vt1211_remove
),
1240 static int __init
vt1211_device_add(unsigned short address
)
1242 struct resource res
= {
1244 .end
= address
+ 0x7f,
1245 .flags
= IORESOURCE_IO
,
1249 pdev
= platform_device_alloc(DRVNAME
, address
);
1252 printk(KERN_ERR DRVNAME
": Device allocation failed (%d)\n",
1257 res
.name
= pdev
->name
;
1258 err
= platform_device_add_resources(pdev
, &res
, 1);
1260 printk(KERN_ERR DRVNAME
": Device resource addition failed "
1265 err
= platform_device_add(pdev
);
1267 printk(KERN_ERR DRVNAME
": Device addition failed (%d)\n",
1275 platform_device_put(pdev
);
1280 static int __init
vt1211_find(int sio_cip
, unsigned short *address
)
1284 superio_enter(sio_cip
);
1286 if (superio_inb(sio_cip
, SIO_VT1211_DEVID
) != SIO_VT1211_ID
) {
1290 superio_select(sio_cip
, SIO_VT1211_LDN_HWMON
);
1292 if ((superio_inb(sio_cip
, SIO_VT1211_ACTIVE
) & 1) == 0) {
1293 printk(KERN_WARNING DRVNAME
": HW monitor is disabled, "
1298 *address
= ((superio_inb(sio_cip
, SIO_VT1211_BADDR
) << 8) |
1299 (superio_inb(sio_cip
, SIO_VT1211_BADDR
+ 1))) & 0xff00;
1300 if (*address
== 0) {
1301 printk(KERN_WARNING DRVNAME
": Base address is not set, "
1307 printk(KERN_INFO DRVNAME
": Found VT1211 chip at 0x%04x, "
1308 "revision %u\n", *address
,
1309 superio_inb(sio_cip
, SIO_VT1211_DEVREV
));
1312 superio_exit(sio_cip
);
1316 static int __init
vt1211_init(void)
1319 unsigned short address
= 0;
1321 if ((err
= vt1211_find(SIO_REG_CIP1
, &address
)) &&
1322 (err
= vt1211_find(SIO_REG_CIP2
, &address
))) {
1326 if ((uch_config
< -1) || (uch_config
> 31)) {
1328 printk(KERN_WARNING DRVNAME
": Invalid UCH configuration %d. "
1329 "Choose a value between 0 and 31.\n", uch_config
);
1333 if ((int_mode
< -1) || (int_mode
> 0)) {
1335 printk(KERN_WARNING DRVNAME
": Invalid interrupt mode %d. "
1336 "Only mode 0 is supported.\n", int_mode
);
1340 err
= platform_driver_register(&vt1211_driver
);
1345 /* Sets global pdev as a side effect */
1346 err
= vt1211_device_add(address
);
1348 goto EXIT_DRV_UNREGISTER
;
1353 EXIT_DRV_UNREGISTER
:
1354 platform_driver_unregister(&vt1211_driver
);
1359 static void __exit
vt1211_exit(void)
1361 platform_device_unregister(pdev
);
1362 platform_driver_unregister(&vt1211_driver
);
1365 MODULE_AUTHOR("Juerg Haefliger <juergh@gmail.com>");
1366 MODULE_DESCRIPTION("VT1211 sensors");
1367 MODULE_LICENSE("GPL");
1369 module_init(vt1211_init
);
1370 module_exit(vt1211_exit
);