2 * it87.c - Part of lm_sensors, Linux kernel modules for hardware
5 * The IT8705F is an LPC-based Super I/O part that contains UARTs, a
6 * parallel port, an IR port, a MIDI port, a floppy controller, etc., in
7 * addition to an Environment Controller (Enhanced Hardware Monitor and
10 * This driver supports only the Environment Controller in the IT8705F and
11 * similar parts. The other devices are supported by different drivers.
13 * Supports: IT8705F Super I/O chip w/LPC interface
14 * IT8712F Super I/O chip w/LPC interface
15 * IT8716F Super I/O chip w/LPC interface
16 * IT8718F Super I/O chip w/LPC interface
17 * IT8720F Super I/O chip w/LPC interface
18 * IT8726F Super I/O chip w/LPC interface
19 * Sis950 A clone of the IT8705F
21 * Copyright (C) 2001 Chris Gauthron
22 * Copyright (C) 2005-2010 Jean Delvare <khali@linux-fr.org>
24 * This program is free software; you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation; either version 2 of the License, or
27 * (at your option) any later version.
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with this program; if not, write to the Free Software
36 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
39 #include <linux/module.h>
40 #include <linux/init.h>
41 #include <linux/slab.h>
42 #include <linux/jiffies.h>
43 #include <linux/platform_device.h>
44 #include <linux/hwmon.h>
45 #include <linux/hwmon-sysfs.h>
46 #include <linux/hwmon-vid.h>
47 #include <linux/err.h>
48 #include <linux/mutex.h>
49 #include <linux/sysfs.h>
50 #include <linux/string.h>
51 #include <linux/dmi.h>
52 #include <linux/acpi.h>
55 #define DRVNAME "it87"
57 enum chips
{ it87
, it8712
, it8716
, it8718
, it8720
};
59 static unsigned short force_id
;
60 module_param(force_id
, ushort
, 0);
61 MODULE_PARM_DESC(force_id
, "Override the detected device ID");
63 static struct platform_device
*pdev
;
65 #define REG 0x2e /* The register to read/write */
66 #define DEV 0x07 /* Register: Logical device select */
67 #define VAL 0x2f /* The value to read/write */
68 #define PME 0x04 /* The device with the fan registers in it */
70 /* The device with the IT8718F/IT8720F VID value in it */
73 #define DEVID 0x20 /* Register: Device ID */
74 #define DEVREV 0x22 /* Register: Device Revision */
84 superio_outb(int reg
, int val
)
90 static int superio_inw(int reg
)
101 superio_select(int ldn
)
123 /* Logical device 4 registers */
124 #define IT8712F_DEVID 0x8712
125 #define IT8705F_DEVID 0x8705
126 #define IT8716F_DEVID 0x8716
127 #define IT8718F_DEVID 0x8718
128 #define IT8720F_DEVID 0x8720
129 #define IT8726F_DEVID 0x8726
130 #define IT87_ACT_REG 0x30
131 #define IT87_BASE_REG 0x60
133 /* Logical device 7 registers (IT8712F and later) */
134 #define IT87_SIO_GPIO3_REG 0x27
135 #define IT87_SIO_GPIO5_REG 0x29
136 #define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
137 #define IT87_SIO_VID_REG 0xfc /* VID value */
138 #define IT87_SIO_BEEP_PIN_REG 0xf6 /* Beep pin mapping */
140 /* Update battery voltage after every reading if true */
141 static int update_vbat
;
143 /* Not all BIOSes properly configure the PWM registers */
144 static int fix_pwm_polarity
;
146 /* Many IT87 constants specified below */
148 /* Length of ISA address segment */
149 #define IT87_EXTENT 8
151 /* Length of ISA address segment for Environmental Controller */
152 #define IT87_EC_EXTENT 2
154 /* Offset of EC registers from ISA base address */
155 #define IT87_EC_OFFSET 5
157 /* Where are the ISA address/data registers relative to the EC base address */
158 #define IT87_ADDR_REG_OFFSET 0
159 #define IT87_DATA_REG_OFFSET 1
161 /*----- The IT87 registers -----*/
163 #define IT87_REG_CONFIG 0x00
165 #define IT87_REG_ALARM1 0x01
166 #define IT87_REG_ALARM2 0x02
167 #define IT87_REG_ALARM3 0x03
169 /* The IT8718F and IT8720F have the VID value in a different register, in
170 Super-I/O configuration space. */
171 #define IT87_REG_VID 0x0a
172 /* The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b
173 for fan divisors. Later IT8712F revisions must use 16-bit tachometer
175 #define IT87_REG_FAN_DIV 0x0b
176 #define IT87_REG_FAN_16BIT 0x0c
178 /* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */
180 static const u8 IT87_REG_FAN
[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82 };
181 static const u8 IT87_REG_FAN_MIN
[] = { 0x10, 0x11, 0x12, 0x84, 0x86 };
182 static const u8 IT87_REG_FANX
[] = { 0x18, 0x19, 0x1a, 0x81, 0x83 };
183 static const u8 IT87_REG_FANX_MIN
[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 };
184 #define IT87_REG_FAN_MAIN_CTRL 0x13
185 #define IT87_REG_FAN_CTL 0x14
186 #define IT87_REG_PWM(nr) (0x15 + (nr))
188 #define IT87_REG_VIN(nr) (0x20 + (nr))
189 #define IT87_REG_TEMP(nr) (0x29 + (nr))
191 #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2)
192 #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2)
193 #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2)
194 #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2)
196 #define IT87_REG_VIN_ENABLE 0x50
197 #define IT87_REG_TEMP_ENABLE 0x51
198 #define IT87_REG_BEEP_ENABLE 0x5c
200 #define IT87_REG_CHIPID 0x58
202 #define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i))
203 #define IT87_REG_AUTO_PWM(nr, i) (0x65 + (nr) * 8 + (i))
205 #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255))
206 #define IN_FROM_REG(val) ((val) * 16)
208 static inline u8
FAN_TO_REG(long rpm
, int div
)
212 rpm
= SENSORS_LIMIT(rpm
, 1, 1000000);
213 return SENSORS_LIMIT((1350000 + rpm
* div
/ 2) / (rpm
* div
), 1,
217 static inline u16
FAN16_TO_REG(long rpm
)
221 return SENSORS_LIMIT((1350000 + rpm
) / (rpm
* 2), 1, 0xfffe);
224 #define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div)))
225 /* The divider is fixed to 2 in 16-bit mode */
226 #define FAN16_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:1350000/((val)*2))
228 #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\
229 ((val)+500)/1000),-128,127))
230 #define TEMP_FROM_REG(val) ((val) * 1000)
232 #define PWM_TO_REG(val) ((val) >> 1)
233 #define PWM_FROM_REG(val) (((val)&0x7f) << 1)
235 static int DIV_TO_REG(int val
)
238 while (answer
< 7 && (val
>>= 1))
242 #define DIV_FROM_REG(val) (1 << (val))
244 static const unsigned int pwm_freq
[8] = {
256 struct it87_sio_data
{
258 /* Values read from Super-I/O config space */
262 /* Features skipped based on config or DMI */
268 /* For each registered chip, we need to keep some data in memory.
269 The structure is dynamically allocated. */
271 struct device
*hwmon_dev
;
277 struct mutex update_lock
;
278 char valid
; /* !=0 if following fields are valid */
279 unsigned long last_updated
; /* In jiffies */
281 u8 in
[9]; /* Register value */
282 u8 in_max
[8]; /* Register value */
283 u8 in_min
[8]; /* Register value */
284 u8 has_fan
; /* Bitfield, fans enabled */
285 u16 fan
[5]; /* Register values, possibly combined */
286 u16 fan_min
[5]; /* Register values, possibly combined */
287 s8 temp
[3]; /* Register value */
288 s8 temp_high
[3]; /* Register value */
289 s8 temp_low
[3]; /* Register value */
290 u8 sensor
; /* Register value */
291 u8 fan_div
[3]; /* Register encoding, shifted right */
292 u8 vid
; /* Register encoding, combined */
294 u32 alarms
; /* Register encoding, combined */
295 u8 beeps
; /* Register encoding */
296 u8 fan_main_ctrl
; /* Register value */
297 u8 fan_ctl
; /* Register value */
299 /* The following 3 arrays correspond to the same registers. The
300 * meaning of bits 6-0 depends on the value of bit 7, and we want
301 * to preserve settings on mode changes, so we have to track all
302 * values separately. */
303 u8 pwm_ctrl
[3]; /* Register value */
304 u8 pwm_duty
[3]; /* Manual PWM value set by user (bit 6-0) */
305 u8 pwm_temp_map
[3]; /* PWM to temp. chan. mapping (bits 1-0) */
307 /* Automatic fan speed control registers */
308 u8 auto_pwm
[3][4]; /* [nr][3] is hard-coded */
309 s8 auto_temp
[3][5]; /* [nr][0] is point1_temp_hyst */
312 static inline int has_16bit_fans(const struct it87_data
*data
)
314 /* IT8705F Datasheet 0.4.1, 3h == Version G.
315 IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J.
316 These are the first revisions with 16bit tachometer support. */
317 return (data
->type
== it87
&& data
->revision
>= 0x03)
318 || (data
->type
== it8712
&& data
->revision
>= 0x08)
319 || data
->type
== it8716
320 || data
->type
== it8718
321 || data
->type
== it8720
;
324 static inline int has_old_autopwm(const struct it87_data
*data
)
326 /* The old automatic fan speed control interface is implemented
327 by IT8705F chips up to revision F and IT8712F chips up to
329 return (data
->type
== it87
&& data
->revision
< 0x03)
330 || (data
->type
== it8712
&& data
->revision
< 0x08);
333 static int it87_probe(struct platform_device
*pdev
);
334 static int __devexit
it87_remove(struct platform_device
*pdev
);
336 static int it87_read_value(struct it87_data
*data
, u8 reg
);
337 static void it87_write_value(struct it87_data
*data
, u8 reg
, u8 value
);
338 static struct it87_data
*it87_update_device(struct device
*dev
);
339 static int it87_check_pwm(struct device
*dev
);
340 static void it87_init_device(struct platform_device
*pdev
);
343 static struct platform_driver it87_driver
= {
345 .owner
= THIS_MODULE
,
349 .remove
= __devexit_p(it87_remove
),
352 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*attr
,
355 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
356 int nr
= sensor_attr
->index
;
358 struct it87_data
*data
= it87_update_device(dev
);
359 return sprintf(buf
, "%d\n", IN_FROM_REG(data
->in
[nr
]));
362 static ssize_t
show_in_min(struct device
*dev
, struct device_attribute
*attr
,
365 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
366 int nr
= sensor_attr
->index
;
368 struct it87_data
*data
= it87_update_device(dev
);
369 return sprintf(buf
, "%d\n", IN_FROM_REG(data
->in_min
[nr
]));
372 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
*attr
,
375 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
376 int nr
= sensor_attr
->index
;
378 struct it87_data
*data
= it87_update_device(dev
);
379 return sprintf(buf
, "%d\n", IN_FROM_REG(data
->in_max
[nr
]));
382 static ssize_t
set_in_min(struct device
*dev
, struct device_attribute
*attr
,
383 const char *buf
, size_t count
)
385 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
386 int nr
= sensor_attr
->index
;
388 struct it87_data
*data
= dev_get_drvdata(dev
);
391 if (strict_strtoul(buf
, 10, &val
) < 0)
394 mutex_lock(&data
->update_lock
);
395 data
->in_min
[nr
] = IN_TO_REG(val
);
396 it87_write_value(data
, IT87_REG_VIN_MIN(nr
),
398 mutex_unlock(&data
->update_lock
);
401 static ssize_t
set_in_max(struct device
*dev
, struct device_attribute
*attr
,
402 const char *buf
, size_t count
)
404 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
405 int nr
= sensor_attr
->index
;
407 struct it87_data
*data
= dev_get_drvdata(dev
);
410 if (strict_strtoul(buf
, 10, &val
) < 0)
413 mutex_lock(&data
->update_lock
);
414 data
->in_max
[nr
] = IN_TO_REG(val
);
415 it87_write_value(data
, IT87_REG_VIN_MAX(nr
),
417 mutex_unlock(&data
->update_lock
);
421 #define show_in_offset(offset) \
422 static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
423 show_in, NULL, offset);
425 #define limit_in_offset(offset) \
426 static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
427 show_in_min, set_in_min, offset); \
428 static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
429 show_in_max, set_in_max, offset);
450 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
*attr
,
453 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
454 int nr
= sensor_attr
->index
;
456 struct it87_data
*data
= it87_update_device(dev
);
457 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp
[nr
]));
459 static ssize_t
show_temp_max(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
;
465 struct it87_data
*data
= it87_update_device(dev
);
466 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_high
[nr
]));
468 static ssize_t
show_temp_min(struct device
*dev
, struct device_attribute
*attr
,
471 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
472 int nr
= sensor_attr
->index
;
474 struct it87_data
*data
= it87_update_device(dev
);
475 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_low
[nr
]));
477 static ssize_t
set_temp_max(struct device
*dev
, struct device_attribute
*attr
,
478 const char *buf
, size_t count
)
480 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
481 int nr
= sensor_attr
->index
;
483 struct it87_data
*data
= dev_get_drvdata(dev
);
486 if (strict_strtol(buf
, 10, &val
) < 0)
489 mutex_lock(&data
->update_lock
);
490 data
->temp_high
[nr
] = TEMP_TO_REG(val
);
491 it87_write_value(data
, IT87_REG_TEMP_HIGH(nr
), data
->temp_high
[nr
]);
492 mutex_unlock(&data
->update_lock
);
495 static ssize_t
set_temp_min(struct device
*dev
, struct device_attribute
*attr
,
496 const char *buf
, size_t count
)
498 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
499 int nr
= sensor_attr
->index
;
501 struct it87_data
*data
= dev_get_drvdata(dev
);
504 if (strict_strtol(buf
, 10, &val
) < 0)
507 mutex_lock(&data
->update_lock
);
508 data
->temp_low
[nr
] = TEMP_TO_REG(val
);
509 it87_write_value(data
, IT87_REG_TEMP_LOW(nr
), data
->temp_low
[nr
]);
510 mutex_unlock(&data
->update_lock
);
513 #define show_temp_offset(offset) \
514 static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
515 show_temp, NULL, offset - 1); \
516 static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
517 show_temp_max, set_temp_max, offset - 1); \
518 static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
519 show_temp_min, set_temp_min, offset - 1);
525 static ssize_t
show_sensor(struct device
*dev
, struct device_attribute
*attr
,
528 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
529 int nr
= sensor_attr
->index
;
531 struct it87_data
*data
= it87_update_device(dev
);
532 u8 reg
= data
->sensor
; /* In case the value is updated while
536 return sprintf(buf
, "3\n"); /* thermal diode */
538 return sprintf(buf
, "4\n"); /* thermistor */
539 return sprintf(buf
, "0\n"); /* disabled */
541 static ssize_t
set_sensor(struct device
*dev
, struct device_attribute
*attr
,
542 const char *buf
, size_t count
)
544 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
545 int nr
= sensor_attr
->index
;
547 struct it87_data
*data
= dev_get_drvdata(dev
);
551 if (strict_strtol(buf
, 10, &val
) < 0)
554 reg
= it87_read_value(data
, IT87_REG_TEMP_ENABLE
);
557 if (val
== 2) { /* backwards compatibility */
558 dev_warn(dev
, "Sensor type 2 is deprecated, please use 4 "
562 /* 3 = thermal diode; 4 = thermistor; 0 = disabled */
570 mutex_lock(&data
->update_lock
);
572 it87_write_value(data
, IT87_REG_TEMP_ENABLE
, data
->sensor
);
573 data
->valid
= 0; /* Force cache refresh */
574 mutex_unlock(&data
->update_lock
);
577 #define show_sensor_offset(offset) \
578 static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \
579 show_sensor, set_sensor, offset - 1);
581 show_sensor_offset(1);
582 show_sensor_offset(2);
583 show_sensor_offset(3);
587 static int pwm_mode(const struct it87_data
*data
, int nr
)
589 int ctrl
= data
->fan_main_ctrl
& (1 << nr
);
591 if (ctrl
== 0) /* Full speed */
593 if (data
->pwm_ctrl
[nr
] & 0x80) /* Automatic mode */
595 else /* Manual mode */
599 static ssize_t
show_fan(struct device
*dev
, struct device_attribute
*attr
,
602 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
603 int nr
= sensor_attr
->index
;
605 struct it87_data
*data
= it87_update_device(dev
);
606 return sprintf(buf
, "%d\n", FAN_FROM_REG(data
->fan
[nr
],
607 DIV_FROM_REG(data
->fan_div
[nr
])));
609 static ssize_t
show_fan_min(struct device
*dev
, struct device_attribute
*attr
,
612 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
613 int nr
= sensor_attr
->index
;
615 struct it87_data
*data
= it87_update_device(dev
);
616 return sprintf(buf
, "%d\n", FAN_FROM_REG(data
->fan_min
[nr
],
617 DIV_FROM_REG(data
->fan_div
[nr
])));
619 static ssize_t
show_fan_div(struct device
*dev
, struct device_attribute
*attr
,
622 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
623 int nr
= sensor_attr
->index
;
625 struct it87_data
*data
= it87_update_device(dev
);
626 return sprintf(buf
, "%d\n", DIV_FROM_REG(data
->fan_div
[nr
]));
628 static ssize_t
show_pwm_enable(struct device
*dev
,
629 struct device_attribute
*attr
, char *buf
)
631 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
632 int nr
= sensor_attr
->index
;
634 struct it87_data
*data
= it87_update_device(dev
);
635 return sprintf(buf
, "%d\n", pwm_mode(data
, nr
));
637 static ssize_t
show_pwm(struct device
*dev
, struct device_attribute
*attr
,
640 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
641 int nr
= sensor_attr
->index
;
643 struct it87_data
*data
= it87_update_device(dev
);
644 return sprintf(buf
, "%d\n", PWM_FROM_REG(data
->pwm_duty
[nr
]));
646 static ssize_t
show_pwm_freq(struct device
*dev
, struct device_attribute
*attr
,
649 struct it87_data
*data
= it87_update_device(dev
);
650 int index
= (data
->fan_ctl
>> 4) & 0x07;
652 return sprintf(buf
, "%u\n", pwm_freq
[index
]);
654 static ssize_t
set_fan_min(struct device
*dev
, struct device_attribute
*attr
,
655 const char *buf
, size_t count
)
657 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
658 int nr
= sensor_attr
->index
;
660 struct it87_data
*data
= dev_get_drvdata(dev
);
664 if (strict_strtol(buf
, 10, &val
) < 0)
667 mutex_lock(&data
->update_lock
);
668 reg
= it87_read_value(data
, IT87_REG_FAN_DIV
);
671 data
->fan_div
[nr
] = reg
& 0x07;
674 data
->fan_div
[nr
] = (reg
>> 3) & 0x07;
677 data
->fan_div
[nr
] = (reg
& 0x40) ? 3 : 1;
681 data
->fan_min
[nr
] = FAN_TO_REG(val
, DIV_FROM_REG(data
->fan_div
[nr
]));
682 it87_write_value(data
, IT87_REG_FAN_MIN
[nr
], data
->fan_min
[nr
]);
683 mutex_unlock(&data
->update_lock
);
686 static ssize_t
set_fan_div(struct device
*dev
, struct device_attribute
*attr
,
687 const char *buf
, size_t count
)
689 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
690 int nr
= sensor_attr
->index
;
692 struct it87_data
*data
= dev_get_drvdata(dev
);
697 if (strict_strtoul(buf
, 10, &val
) < 0)
700 mutex_lock(&data
->update_lock
);
701 old
= it87_read_value(data
, IT87_REG_FAN_DIV
);
703 /* Save fan min limit */
704 min
= FAN_FROM_REG(data
->fan_min
[nr
], DIV_FROM_REG(data
->fan_div
[nr
]));
709 data
->fan_div
[nr
] = DIV_TO_REG(val
);
713 data
->fan_div
[nr
] = 1;
715 data
->fan_div
[nr
] = 3;
718 val
|= (data
->fan_div
[0] & 0x07);
719 val
|= (data
->fan_div
[1] & 0x07) << 3;
720 if (data
->fan_div
[2] == 3)
722 it87_write_value(data
, IT87_REG_FAN_DIV
, val
);
724 /* Restore fan min limit */
725 data
->fan_min
[nr
] = FAN_TO_REG(min
, DIV_FROM_REG(data
->fan_div
[nr
]));
726 it87_write_value(data
, IT87_REG_FAN_MIN
[nr
], data
->fan_min
[nr
]);
728 mutex_unlock(&data
->update_lock
);
732 /* Returns 0 if OK, -EINVAL otherwise */
733 static int check_trip_points(struct device
*dev
, int nr
)
735 const struct it87_data
*data
= dev_get_drvdata(dev
);
738 if (has_old_autopwm(data
)) {
739 for (i
= 0; i
< 3; i
++) {
740 if (data
->auto_temp
[nr
][i
] > data
->auto_temp
[nr
][i
+ 1])
743 for (i
= 0; i
< 2; i
++) {
744 if (data
->auto_pwm
[nr
][i
] > data
->auto_pwm
[nr
][i
+ 1])
750 dev_err(dev
, "Inconsistent trip points, not switching to "
752 dev_err(dev
, "Adjust the trip points and try again\n");
757 static ssize_t
set_pwm_enable(struct device
*dev
,
758 struct device_attribute
*attr
, const char *buf
, size_t count
)
760 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
761 int nr
= sensor_attr
->index
;
763 struct it87_data
*data
= dev_get_drvdata(dev
);
766 if (strict_strtol(buf
, 10, &val
) < 0 || val
< 0 || val
> 2)
769 /* Check trip points before switching to automatic mode */
771 if (check_trip_points(dev
, nr
) < 0)
775 mutex_lock(&data
->update_lock
);
779 /* make sure the fan is on when in on/off mode */
780 tmp
= it87_read_value(data
, IT87_REG_FAN_CTL
);
781 it87_write_value(data
, IT87_REG_FAN_CTL
, tmp
| (1 << nr
));
782 /* set on/off mode */
783 data
->fan_main_ctrl
&= ~(1 << nr
);
784 it87_write_value(data
, IT87_REG_FAN_MAIN_CTRL
,
785 data
->fan_main_ctrl
);
787 if (val
== 1) /* Manual mode */
788 data
->pwm_ctrl
[nr
] = data
->pwm_duty
[nr
];
789 else /* Automatic mode */
790 data
->pwm_ctrl
[nr
] = 0x80 | data
->pwm_temp_map
[nr
];
791 it87_write_value(data
, IT87_REG_PWM(nr
), data
->pwm_ctrl
[nr
]);
792 /* set SmartGuardian mode */
793 data
->fan_main_ctrl
|= (1 << nr
);
794 it87_write_value(data
, IT87_REG_FAN_MAIN_CTRL
,
795 data
->fan_main_ctrl
);
798 mutex_unlock(&data
->update_lock
);
801 static ssize_t
set_pwm(struct device
*dev
, struct device_attribute
*attr
,
802 const char *buf
, size_t count
)
804 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
805 int nr
= sensor_attr
->index
;
807 struct it87_data
*data
= dev_get_drvdata(dev
);
810 if (strict_strtol(buf
, 10, &val
) < 0 || val
< 0 || val
> 255)
813 mutex_lock(&data
->update_lock
);
814 data
->pwm_duty
[nr
] = PWM_TO_REG(val
);
815 /* If we are in manual mode, write the duty cycle immediately;
816 * otherwise, just store it for later use. */
817 if (!(data
->pwm_ctrl
[nr
] & 0x80)) {
818 data
->pwm_ctrl
[nr
] = data
->pwm_duty
[nr
];
819 it87_write_value(data
, IT87_REG_PWM(nr
), data
->pwm_ctrl
[nr
]);
821 mutex_unlock(&data
->update_lock
);
824 static ssize_t
set_pwm_freq(struct device
*dev
,
825 struct device_attribute
*attr
, const char *buf
, size_t count
)
827 struct it87_data
*data
= dev_get_drvdata(dev
);
831 if (strict_strtoul(buf
, 10, &val
) < 0)
834 /* Search for the nearest available frequency */
835 for (i
= 0; i
< 7; i
++) {
836 if (val
> (pwm_freq
[i
] + pwm_freq
[i
+1]) / 2)
840 mutex_lock(&data
->update_lock
);
841 data
->fan_ctl
= it87_read_value(data
, IT87_REG_FAN_CTL
) & 0x8f;
842 data
->fan_ctl
|= i
<< 4;
843 it87_write_value(data
, IT87_REG_FAN_CTL
, data
->fan_ctl
);
844 mutex_unlock(&data
->update_lock
);
848 static ssize_t
show_pwm_temp_map(struct device
*dev
,
849 struct device_attribute
*attr
, char *buf
)
851 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
852 int nr
= sensor_attr
->index
;
854 struct it87_data
*data
= it87_update_device(dev
);
857 if (data
->pwm_temp_map
[nr
] < 3)
858 map
= 1 << data
->pwm_temp_map
[nr
];
860 map
= 0; /* Should never happen */
861 return sprintf(buf
, "%d\n", map
);
863 static ssize_t
set_pwm_temp_map(struct device
*dev
,
864 struct device_attribute
*attr
, const char *buf
, size_t count
)
866 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
867 int nr
= sensor_attr
->index
;
869 struct it87_data
*data
= dev_get_drvdata(dev
);
873 /* This check can go away if we ever support automatic fan speed
874 control on newer chips. */
875 if (!has_old_autopwm(data
)) {
876 dev_notice(dev
, "Mapping change disabled for safety reasons\n");
880 if (strict_strtol(buf
, 10, &val
) < 0)
897 mutex_lock(&data
->update_lock
);
898 data
->pwm_temp_map
[nr
] = reg
;
899 /* If we are in automatic mode, write the temp mapping immediately;
900 * otherwise, just store it for later use. */
901 if (data
->pwm_ctrl
[nr
] & 0x80) {
902 data
->pwm_ctrl
[nr
] = 0x80 | data
->pwm_temp_map
[nr
];
903 it87_write_value(data
, IT87_REG_PWM(nr
), data
->pwm_ctrl
[nr
]);
905 mutex_unlock(&data
->update_lock
);
909 static ssize_t
show_auto_pwm(struct device
*dev
,
910 struct device_attribute
*attr
, char *buf
)
912 struct it87_data
*data
= it87_update_device(dev
);
913 struct sensor_device_attribute_2
*sensor_attr
=
914 to_sensor_dev_attr_2(attr
);
915 int nr
= sensor_attr
->nr
;
916 int point
= sensor_attr
->index
;
918 return sprintf(buf
, "%d\n", PWM_FROM_REG(data
->auto_pwm
[nr
][point
]));
921 static ssize_t
set_auto_pwm(struct device
*dev
,
922 struct device_attribute
*attr
, const char *buf
, size_t count
)
924 struct it87_data
*data
= dev_get_drvdata(dev
);
925 struct sensor_device_attribute_2
*sensor_attr
=
926 to_sensor_dev_attr_2(attr
);
927 int nr
= sensor_attr
->nr
;
928 int point
= sensor_attr
->index
;
931 if (strict_strtol(buf
, 10, &val
) < 0 || val
< 0 || val
> 255)
934 mutex_lock(&data
->update_lock
);
935 data
->auto_pwm
[nr
][point
] = PWM_TO_REG(val
);
936 it87_write_value(data
, IT87_REG_AUTO_PWM(nr
, point
),
937 data
->auto_pwm
[nr
][point
]);
938 mutex_unlock(&data
->update_lock
);
942 static ssize_t
show_auto_temp(struct device
*dev
,
943 struct device_attribute
*attr
, char *buf
)
945 struct it87_data
*data
= it87_update_device(dev
);
946 struct sensor_device_attribute_2
*sensor_attr
=
947 to_sensor_dev_attr_2(attr
);
948 int nr
= sensor_attr
->nr
;
949 int point
= sensor_attr
->index
;
951 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->auto_temp
[nr
][point
]));
954 static ssize_t
set_auto_temp(struct device
*dev
,
955 struct device_attribute
*attr
, const char *buf
, size_t count
)
957 struct it87_data
*data
= dev_get_drvdata(dev
);
958 struct sensor_device_attribute_2
*sensor_attr
=
959 to_sensor_dev_attr_2(attr
);
960 int nr
= sensor_attr
->nr
;
961 int point
= sensor_attr
->index
;
964 if (strict_strtol(buf
, 10, &val
) < 0 || val
< -128000 || val
> 127000)
967 mutex_lock(&data
->update_lock
);
968 data
->auto_temp
[nr
][point
] = TEMP_TO_REG(val
);
969 it87_write_value(data
, IT87_REG_AUTO_TEMP(nr
, point
),
970 data
->auto_temp
[nr
][point
]);
971 mutex_unlock(&data
->update_lock
);
975 #define show_fan_offset(offset) \
976 static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
977 show_fan, NULL, offset - 1); \
978 static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
979 show_fan_min, set_fan_min, offset - 1); \
980 static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
981 show_fan_div, set_fan_div, offset - 1);
987 #define show_pwm_offset(offset) \
988 static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
989 show_pwm_enable, set_pwm_enable, offset - 1); \
990 static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
991 show_pwm, set_pwm, offset - 1); \
992 static DEVICE_ATTR(pwm##offset##_freq, \
993 (offset == 1 ? S_IRUGO | S_IWUSR : S_IRUGO), \
994 show_pwm_freq, (offset == 1 ? set_pwm_freq : NULL)); \
995 static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels_temp, \
996 S_IRUGO | S_IWUSR, show_pwm_temp_map, set_pwm_temp_map, \
998 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_pwm, \
999 S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \
1001 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_pwm, \
1002 S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \
1004 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_pwm, \
1005 S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \
1007 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_pwm, \
1008 S_IRUGO, show_auto_pwm, NULL, offset - 1, 3); \
1009 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp, \
1010 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1012 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp_hyst, \
1013 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1015 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_temp, \
1016 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1018 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_temp, \
1019 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1021 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_temp, \
1022 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1029 /* A different set of callbacks for 16-bit fans */
1030 static ssize_t
show_fan16(struct device
*dev
, struct device_attribute
*attr
,
1033 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
1034 int nr
= sensor_attr
->index
;
1035 struct it87_data
*data
= it87_update_device(dev
);
1036 return sprintf(buf
, "%d\n", FAN16_FROM_REG(data
->fan
[nr
]));
1039 static ssize_t
show_fan16_min(struct device
*dev
, struct device_attribute
*attr
,
1042 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
1043 int nr
= sensor_attr
->index
;
1044 struct it87_data
*data
= it87_update_device(dev
);
1045 return sprintf(buf
, "%d\n", FAN16_FROM_REG(data
->fan_min
[nr
]));
1048 static ssize_t
set_fan16_min(struct device
*dev
, struct device_attribute
*attr
,
1049 const char *buf
, size_t count
)
1051 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
1052 int nr
= sensor_attr
->index
;
1053 struct it87_data
*data
= dev_get_drvdata(dev
);
1056 if (strict_strtol(buf
, 10, &val
) < 0)
1059 mutex_lock(&data
->update_lock
);
1060 data
->fan_min
[nr
] = FAN16_TO_REG(val
);
1061 it87_write_value(data
, IT87_REG_FAN_MIN
[nr
],
1062 data
->fan_min
[nr
] & 0xff);
1063 it87_write_value(data
, IT87_REG_FANX_MIN
[nr
],
1064 data
->fan_min
[nr
] >> 8);
1065 mutex_unlock(&data
->update_lock
);
1069 /* We want to use the same sysfs file names as 8-bit fans, but we need
1070 different variable names, so we have to use SENSOR_ATTR instead of
1071 SENSOR_DEVICE_ATTR. */
1072 #define show_fan16_offset(offset) \
1073 static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \
1074 = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \
1075 show_fan16, NULL, offset - 1); \
1076 static struct sensor_device_attribute sensor_dev_attr_fan##offset##_min16 \
1077 = SENSOR_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
1078 show_fan16_min, set_fan16_min, offset - 1)
1080 show_fan16_offset(1);
1081 show_fan16_offset(2);
1082 show_fan16_offset(3);
1083 show_fan16_offset(4);
1084 show_fan16_offset(5);
1087 static ssize_t
show_alarms(struct device
*dev
, struct device_attribute
*attr
,
1090 struct it87_data
*data
= it87_update_device(dev
);
1091 return sprintf(buf
, "%u\n", data
->alarms
);
1093 static DEVICE_ATTR(alarms
, S_IRUGO
, show_alarms
, NULL
);
1095 static ssize_t
show_alarm(struct device
*dev
, struct device_attribute
*attr
,
1098 int bitnr
= to_sensor_dev_attr(attr
)->index
;
1099 struct it87_data
*data
= it87_update_device(dev
);
1100 return sprintf(buf
, "%u\n", (data
->alarms
>> bitnr
) & 1);
1102 static SENSOR_DEVICE_ATTR(in0_alarm
, S_IRUGO
, show_alarm
, NULL
, 8);
1103 static SENSOR_DEVICE_ATTR(in1_alarm
, S_IRUGO
, show_alarm
, NULL
, 9);
1104 static SENSOR_DEVICE_ATTR(in2_alarm
, S_IRUGO
, show_alarm
, NULL
, 10);
1105 static SENSOR_DEVICE_ATTR(in3_alarm
, S_IRUGO
, show_alarm
, NULL
, 11);
1106 static SENSOR_DEVICE_ATTR(in4_alarm
, S_IRUGO
, show_alarm
, NULL
, 12);
1107 static SENSOR_DEVICE_ATTR(in5_alarm
, S_IRUGO
, show_alarm
, NULL
, 13);
1108 static SENSOR_DEVICE_ATTR(in6_alarm
, S_IRUGO
, show_alarm
, NULL
, 14);
1109 static SENSOR_DEVICE_ATTR(in7_alarm
, S_IRUGO
, show_alarm
, NULL
, 15);
1110 static SENSOR_DEVICE_ATTR(fan1_alarm
, S_IRUGO
, show_alarm
, NULL
, 0);
1111 static SENSOR_DEVICE_ATTR(fan2_alarm
, S_IRUGO
, show_alarm
, NULL
, 1);
1112 static SENSOR_DEVICE_ATTR(fan3_alarm
, S_IRUGO
, show_alarm
, NULL
, 2);
1113 static SENSOR_DEVICE_ATTR(fan4_alarm
, S_IRUGO
, show_alarm
, NULL
, 3);
1114 static SENSOR_DEVICE_ATTR(fan5_alarm
, S_IRUGO
, show_alarm
, NULL
, 6);
1115 static SENSOR_DEVICE_ATTR(temp1_alarm
, S_IRUGO
, show_alarm
, NULL
, 16);
1116 static SENSOR_DEVICE_ATTR(temp2_alarm
, S_IRUGO
, show_alarm
, NULL
, 17);
1117 static SENSOR_DEVICE_ATTR(temp3_alarm
, S_IRUGO
, show_alarm
, NULL
, 18);
1119 static ssize_t
show_beep(struct device
*dev
, struct device_attribute
*attr
,
1122 int bitnr
= to_sensor_dev_attr(attr
)->index
;
1123 struct it87_data
*data
= it87_update_device(dev
);
1124 return sprintf(buf
, "%u\n", (data
->beeps
>> bitnr
) & 1);
1126 static ssize_t
set_beep(struct device
*dev
, struct device_attribute
*attr
,
1127 const char *buf
, size_t count
)
1129 int bitnr
= to_sensor_dev_attr(attr
)->index
;
1130 struct it87_data
*data
= dev_get_drvdata(dev
);
1133 if (strict_strtol(buf
, 10, &val
) < 0
1134 || (val
!= 0 && val
!= 1))
1137 mutex_lock(&data
->update_lock
);
1138 data
->beeps
= it87_read_value(data
, IT87_REG_BEEP_ENABLE
);
1140 data
->beeps
|= (1 << bitnr
);
1142 data
->beeps
&= ~(1 << bitnr
);
1143 it87_write_value(data
, IT87_REG_BEEP_ENABLE
, data
->beeps
);
1144 mutex_unlock(&data
->update_lock
);
1148 static SENSOR_DEVICE_ATTR(in0_beep
, S_IRUGO
| S_IWUSR
,
1149 show_beep
, set_beep
, 1);
1150 static SENSOR_DEVICE_ATTR(in1_beep
, S_IRUGO
, show_beep
, NULL
, 1);
1151 static SENSOR_DEVICE_ATTR(in2_beep
, S_IRUGO
, show_beep
, NULL
, 1);
1152 static SENSOR_DEVICE_ATTR(in3_beep
, S_IRUGO
, show_beep
, NULL
, 1);
1153 static SENSOR_DEVICE_ATTR(in4_beep
, S_IRUGO
, show_beep
, NULL
, 1);
1154 static SENSOR_DEVICE_ATTR(in5_beep
, S_IRUGO
, show_beep
, NULL
, 1);
1155 static SENSOR_DEVICE_ATTR(in6_beep
, S_IRUGO
, show_beep
, NULL
, 1);
1156 static SENSOR_DEVICE_ATTR(in7_beep
, S_IRUGO
, show_beep
, NULL
, 1);
1157 /* fanX_beep writability is set later */
1158 static SENSOR_DEVICE_ATTR(fan1_beep
, S_IRUGO
, show_beep
, set_beep
, 0);
1159 static SENSOR_DEVICE_ATTR(fan2_beep
, S_IRUGO
, show_beep
, set_beep
, 0);
1160 static SENSOR_DEVICE_ATTR(fan3_beep
, S_IRUGO
, show_beep
, set_beep
, 0);
1161 static SENSOR_DEVICE_ATTR(fan4_beep
, S_IRUGO
, show_beep
, set_beep
, 0);
1162 static SENSOR_DEVICE_ATTR(fan5_beep
, S_IRUGO
, show_beep
, set_beep
, 0);
1163 static SENSOR_DEVICE_ATTR(temp1_beep
, S_IRUGO
| S_IWUSR
,
1164 show_beep
, set_beep
, 2);
1165 static SENSOR_DEVICE_ATTR(temp2_beep
, S_IRUGO
, show_beep
, NULL
, 2);
1166 static SENSOR_DEVICE_ATTR(temp3_beep
, S_IRUGO
, show_beep
, NULL
, 2);
1168 static ssize_t
show_vrm_reg(struct device
*dev
, struct device_attribute
*attr
,
1171 struct it87_data
*data
= dev_get_drvdata(dev
);
1172 return sprintf(buf
, "%u\n", data
->vrm
);
1174 static ssize_t
store_vrm_reg(struct device
*dev
, struct device_attribute
*attr
,
1175 const char *buf
, size_t count
)
1177 struct it87_data
*data
= dev_get_drvdata(dev
);
1180 if (strict_strtoul(buf
, 10, &val
) < 0)
1187 static DEVICE_ATTR(vrm
, S_IRUGO
| S_IWUSR
, show_vrm_reg
, store_vrm_reg
);
1189 static ssize_t
show_vid_reg(struct device
*dev
, struct device_attribute
*attr
,
1192 struct it87_data
*data
= it87_update_device(dev
);
1193 return sprintf(buf
, "%ld\n", (long) vid_from_reg(data
->vid
, data
->vrm
));
1195 static DEVICE_ATTR(cpu0_vid
, S_IRUGO
, show_vid_reg
, NULL
);
1197 static ssize_t
show_name(struct device
*dev
, struct device_attribute
1198 *devattr
, char *buf
)
1200 struct it87_data
*data
= dev_get_drvdata(dev
);
1201 return sprintf(buf
, "%s\n", data
->name
);
1203 static DEVICE_ATTR(name
, S_IRUGO
, show_name
, NULL
);
1205 static struct attribute
*it87_attributes
[] = {
1206 &sensor_dev_attr_in0_input
.dev_attr
.attr
,
1207 &sensor_dev_attr_in1_input
.dev_attr
.attr
,
1208 &sensor_dev_attr_in2_input
.dev_attr
.attr
,
1209 &sensor_dev_attr_in3_input
.dev_attr
.attr
,
1210 &sensor_dev_attr_in4_input
.dev_attr
.attr
,
1211 &sensor_dev_attr_in5_input
.dev_attr
.attr
,
1212 &sensor_dev_attr_in6_input
.dev_attr
.attr
,
1213 &sensor_dev_attr_in7_input
.dev_attr
.attr
,
1214 &sensor_dev_attr_in8_input
.dev_attr
.attr
,
1215 &sensor_dev_attr_in0_min
.dev_attr
.attr
,
1216 &sensor_dev_attr_in1_min
.dev_attr
.attr
,
1217 &sensor_dev_attr_in2_min
.dev_attr
.attr
,
1218 &sensor_dev_attr_in3_min
.dev_attr
.attr
,
1219 &sensor_dev_attr_in4_min
.dev_attr
.attr
,
1220 &sensor_dev_attr_in5_min
.dev_attr
.attr
,
1221 &sensor_dev_attr_in6_min
.dev_attr
.attr
,
1222 &sensor_dev_attr_in7_min
.dev_attr
.attr
,
1223 &sensor_dev_attr_in0_max
.dev_attr
.attr
,
1224 &sensor_dev_attr_in1_max
.dev_attr
.attr
,
1225 &sensor_dev_attr_in2_max
.dev_attr
.attr
,
1226 &sensor_dev_attr_in3_max
.dev_attr
.attr
,
1227 &sensor_dev_attr_in4_max
.dev_attr
.attr
,
1228 &sensor_dev_attr_in5_max
.dev_attr
.attr
,
1229 &sensor_dev_attr_in6_max
.dev_attr
.attr
,
1230 &sensor_dev_attr_in7_max
.dev_attr
.attr
,
1231 &sensor_dev_attr_in0_alarm
.dev_attr
.attr
,
1232 &sensor_dev_attr_in1_alarm
.dev_attr
.attr
,
1233 &sensor_dev_attr_in2_alarm
.dev_attr
.attr
,
1234 &sensor_dev_attr_in3_alarm
.dev_attr
.attr
,
1235 &sensor_dev_attr_in4_alarm
.dev_attr
.attr
,
1236 &sensor_dev_attr_in5_alarm
.dev_attr
.attr
,
1237 &sensor_dev_attr_in6_alarm
.dev_attr
.attr
,
1238 &sensor_dev_attr_in7_alarm
.dev_attr
.attr
,
1240 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
1241 &sensor_dev_attr_temp2_input
.dev_attr
.attr
,
1242 &sensor_dev_attr_temp3_input
.dev_attr
.attr
,
1243 &sensor_dev_attr_temp1_max
.dev_attr
.attr
,
1244 &sensor_dev_attr_temp2_max
.dev_attr
.attr
,
1245 &sensor_dev_attr_temp3_max
.dev_attr
.attr
,
1246 &sensor_dev_attr_temp1_min
.dev_attr
.attr
,
1247 &sensor_dev_attr_temp2_min
.dev_attr
.attr
,
1248 &sensor_dev_attr_temp3_min
.dev_attr
.attr
,
1249 &sensor_dev_attr_temp1_type
.dev_attr
.attr
,
1250 &sensor_dev_attr_temp2_type
.dev_attr
.attr
,
1251 &sensor_dev_attr_temp3_type
.dev_attr
.attr
,
1252 &sensor_dev_attr_temp1_alarm
.dev_attr
.attr
,
1253 &sensor_dev_attr_temp2_alarm
.dev_attr
.attr
,
1254 &sensor_dev_attr_temp3_alarm
.dev_attr
.attr
,
1256 &dev_attr_alarms
.attr
,
1257 &dev_attr_name
.attr
,
1261 static const struct attribute_group it87_group
= {
1262 .attrs
= it87_attributes
,
1265 static struct attribute
*it87_attributes_beep
[] = {
1266 &sensor_dev_attr_in0_beep
.dev_attr
.attr
,
1267 &sensor_dev_attr_in1_beep
.dev_attr
.attr
,
1268 &sensor_dev_attr_in2_beep
.dev_attr
.attr
,
1269 &sensor_dev_attr_in3_beep
.dev_attr
.attr
,
1270 &sensor_dev_attr_in4_beep
.dev_attr
.attr
,
1271 &sensor_dev_attr_in5_beep
.dev_attr
.attr
,
1272 &sensor_dev_attr_in6_beep
.dev_attr
.attr
,
1273 &sensor_dev_attr_in7_beep
.dev_attr
.attr
,
1275 &sensor_dev_attr_temp1_beep
.dev_attr
.attr
,
1276 &sensor_dev_attr_temp2_beep
.dev_attr
.attr
,
1277 &sensor_dev_attr_temp3_beep
.dev_attr
.attr
,
1281 static const struct attribute_group it87_group_beep
= {
1282 .attrs
= it87_attributes_beep
,
1285 static struct attribute
*it87_attributes_fan16
[5][3+1] = { {
1286 &sensor_dev_attr_fan1_input16
.dev_attr
.attr
,
1287 &sensor_dev_attr_fan1_min16
.dev_attr
.attr
,
1288 &sensor_dev_attr_fan1_alarm
.dev_attr
.attr
,
1291 &sensor_dev_attr_fan2_input16
.dev_attr
.attr
,
1292 &sensor_dev_attr_fan2_min16
.dev_attr
.attr
,
1293 &sensor_dev_attr_fan2_alarm
.dev_attr
.attr
,
1296 &sensor_dev_attr_fan3_input16
.dev_attr
.attr
,
1297 &sensor_dev_attr_fan3_min16
.dev_attr
.attr
,
1298 &sensor_dev_attr_fan3_alarm
.dev_attr
.attr
,
1301 &sensor_dev_attr_fan4_input16
.dev_attr
.attr
,
1302 &sensor_dev_attr_fan4_min16
.dev_attr
.attr
,
1303 &sensor_dev_attr_fan4_alarm
.dev_attr
.attr
,
1306 &sensor_dev_attr_fan5_input16
.dev_attr
.attr
,
1307 &sensor_dev_attr_fan5_min16
.dev_attr
.attr
,
1308 &sensor_dev_attr_fan5_alarm
.dev_attr
.attr
,
1312 static const struct attribute_group it87_group_fan16
[5] = {
1313 { .attrs
= it87_attributes_fan16
[0] },
1314 { .attrs
= it87_attributes_fan16
[1] },
1315 { .attrs
= it87_attributes_fan16
[2] },
1316 { .attrs
= it87_attributes_fan16
[3] },
1317 { .attrs
= it87_attributes_fan16
[4] },
1320 static struct attribute
*it87_attributes_fan
[3][4+1] = { {
1321 &sensor_dev_attr_fan1_input
.dev_attr
.attr
,
1322 &sensor_dev_attr_fan1_min
.dev_attr
.attr
,
1323 &sensor_dev_attr_fan1_div
.dev_attr
.attr
,
1324 &sensor_dev_attr_fan1_alarm
.dev_attr
.attr
,
1327 &sensor_dev_attr_fan2_input
.dev_attr
.attr
,
1328 &sensor_dev_attr_fan2_min
.dev_attr
.attr
,
1329 &sensor_dev_attr_fan2_div
.dev_attr
.attr
,
1330 &sensor_dev_attr_fan2_alarm
.dev_attr
.attr
,
1333 &sensor_dev_attr_fan3_input
.dev_attr
.attr
,
1334 &sensor_dev_attr_fan3_min
.dev_attr
.attr
,
1335 &sensor_dev_attr_fan3_div
.dev_attr
.attr
,
1336 &sensor_dev_attr_fan3_alarm
.dev_attr
.attr
,
1340 static const struct attribute_group it87_group_fan
[3] = {
1341 { .attrs
= it87_attributes_fan
[0] },
1342 { .attrs
= it87_attributes_fan
[1] },
1343 { .attrs
= it87_attributes_fan
[2] },
1346 static const struct attribute_group
*
1347 it87_get_fan_group(const struct it87_data
*data
)
1349 return has_16bit_fans(data
) ? it87_group_fan16
: it87_group_fan
;
1352 static struct attribute
*it87_attributes_pwm
[3][4+1] = { {
1353 &sensor_dev_attr_pwm1_enable
.dev_attr
.attr
,
1354 &sensor_dev_attr_pwm1
.dev_attr
.attr
,
1355 &dev_attr_pwm1_freq
.attr
,
1356 &sensor_dev_attr_pwm1_auto_channels_temp
.dev_attr
.attr
,
1359 &sensor_dev_attr_pwm2_enable
.dev_attr
.attr
,
1360 &sensor_dev_attr_pwm2
.dev_attr
.attr
,
1361 &dev_attr_pwm2_freq
.attr
,
1362 &sensor_dev_attr_pwm2_auto_channels_temp
.dev_attr
.attr
,
1365 &sensor_dev_attr_pwm3_enable
.dev_attr
.attr
,
1366 &sensor_dev_attr_pwm3
.dev_attr
.attr
,
1367 &dev_attr_pwm3_freq
.attr
,
1368 &sensor_dev_attr_pwm3_auto_channels_temp
.dev_attr
.attr
,
1372 static const struct attribute_group it87_group_pwm
[3] = {
1373 { .attrs
= it87_attributes_pwm
[0] },
1374 { .attrs
= it87_attributes_pwm
[1] },
1375 { .attrs
= it87_attributes_pwm
[2] },
1378 static struct attribute
*it87_attributes_autopwm
[3][9+1] = { {
1379 &sensor_dev_attr_pwm1_auto_point1_pwm
.dev_attr
.attr
,
1380 &sensor_dev_attr_pwm1_auto_point2_pwm
.dev_attr
.attr
,
1381 &sensor_dev_attr_pwm1_auto_point3_pwm
.dev_attr
.attr
,
1382 &sensor_dev_attr_pwm1_auto_point4_pwm
.dev_attr
.attr
,
1383 &sensor_dev_attr_pwm1_auto_point1_temp
.dev_attr
.attr
,
1384 &sensor_dev_attr_pwm1_auto_point1_temp_hyst
.dev_attr
.attr
,
1385 &sensor_dev_attr_pwm1_auto_point2_temp
.dev_attr
.attr
,
1386 &sensor_dev_attr_pwm1_auto_point3_temp
.dev_attr
.attr
,
1387 &sensor_dev_attr_pwm1_auto_point4_temp
.dev_attr
.attr
,
1390 &sensor_dev_attr_pwm2_auto_point1_pwm
.dev_attr
.attr
,
1391 &sensor_dev_attr_pwm2_auto_point2_pwm
.dev_attr
.attr
,
1392 &sensor_dev_attr_pwm2_auto_point3_pwm
.dev_attr
.attr
,
1393 &sensor_dev_attr_pwm2_auto_point4_pwm
.dev_attr
.attr
,
1394 &sensor_dev_attr_pwm2_auto_point1_temp
.dev_attr
.attr
,
1395 &sensor_dev_attr_pwm2_auto_point1_temp_hyst
.dev_attr
.attr
,
1396 &sensor_dev_attr_pwm2_auto_point2_temp
.dev_attr
.attr
,
1397 &sensor_dev_attr_pwm2_auto_point3_temp
.dev_attr
.attr
,
1398 &sensor_dev_attr_pwm2_auto_point4_temp
.dev_attr
.attr
,
1401 &sensor_dev_attr_pwm3_auto_point1_pwm
.dev_attr
.attr
,
1402 &sensor_dev_attr_pwm3_auto_point2_pwm
.dev_attr
.attr
,
1403 &sensor_dev_attr_pwm3_auto_point3_pwm
.dev_attr
.attr
,
1404 &sensor_dev_attr_pwm3_auto_point4_pwm
.dev_attr
.attr
,
1405 &sensor_dev_attr_pwm3_auto_point1_temp
.dev_attr
.attr
,
1406 &sensor_dev_attr_pwm3_auto_point1_temp_hyst
.dev_attr
.attr
,
1407 &sensor_dev_attr_pwm3_auto_point2_temp
.dev_attr
.attr
,
1408 &sensor_dev_attr_pwm3_auto_point3_temp
.dev_attr
.attr
,
1409 &sensor_dev_attr_pwm3_auto_point4_temp
.dev_attr
.attr
,
1413 static const struct attribute_group it87_group_autopwm
[3] = {
1414 { .attrs
= it87_attributes_autopwm
[0] },
1415 { .attrs
= it87_attributes_autopwm
[1] },
1416 { .attrs
= it87_attributes_autopwm
[2] },
1419 static struct attribute
*it87_attributes_fan_beep
[] = {
1420 &sensor_dev_attr_fan1_beep
.dev_attr
.attr
,
1421 &sensor_dev_attr_fan2_beep
.dev_attr
.attr
,
1422 &sensor_dev_attr_fan3_beep
.dev_attr
.attr
,
1423 &sensor_dev_attr_fan4_beep
.dev_attr
.attr
,
1424 &sensor_dev_attr_fan5_beep
.dev_attr
.attr
,
1427 static struct attribute
*it87_attributes_vid
[] = {
1429 &dev_attr_cpu0_vid
.attr
,
1433 static const struct attribute_group it87_group_vid
= {
1434 .attrs
= it87_attributes_vid
,
1437 /* SuperIO detection - will change isa_address if a chip is found */
1438 static int __init
it87_find(unsigned short *address
,
1439 struct it87_sio_data
*sio_data
)
1443 const char *board_vendor
, *board_name
;
1446 chip_type
= force_id
? force_id
: superio_inw(DEVID
);
1448 switch (chip_type
) {
1450 sio_data
->type
= it87
;
1453 sio_data
->type
= it8712
;
1457 sio_data
->type
= it8716
;
1460 sio_data
->type
= it8718
;
1463 sio_data
->type
= it8720
;
1465 case 0xffff: /* No device at all */
1468 pr_debug(DRVNAME
": Unsupported chip (DEVID=0x%x)\n",
1473 superio_select(PME
);
1474 if (!(superio_inb(IT87_ACT_REG
) & 0x01)) {
1475 pr_info("it87: Device not activated, skipping\n");
1479 *address
= superio_inw(IT87_BASE_REG
) & ~(IT87_EXTENT
- 1);
1480 if (*address
== 0) {
1481 pr_info("it87: Base address not set, skipping\n");
1486 sio_data
->revision
= superio_inb(DEVREV
) & 0x0f;
1487 pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n",
1488 chip_type
, *address
, sio_data
->revision
);
1490 /* Read GPIO config and VID value from LDN 7 (GPIO) */
1491 if (sio_data
->type
== it87
) {
1492 /* The IT8705F doesn't have VID pins at all */
1493 sio_data
->skip_vid
= 1;
1495 /* The IT8705F has a different LD number for GPIO */
1497 sio_data
->beep_pin
= superio_inb(IT87_SIO_BEEP_PIN_REG
) & 0x3f;
1501 superio_select(GPIO
);
1502 /* We need at least 4 VID pins */
1503 reg
= superio_inb(IT87_SIO_GPIO3_REG
);
1505 pr_info("it87: VID is disabled (pins used for GPIO)\n");
1506 sio_data
->skip_vid
= 1;
1509 /* Check if fan3 is there or not */
1511 sio_data
->skip_pwm
|= (1 << 2);
1513 sio_data
->skip_fan
|= (1 << 2);
1515 /* Check if fan2 is there or not */
1516 reg
= superio_inb(IT87_SIO_GPIO5_REG
);
1518 sio_data
->skip_pwm
|= (1 << 1);
1520 sio_data
->skip_fan
|= (1 << 1);
1522 if ((sio_data
->type
== it8718
|| sio_data
->type
== it8720
)
1523 && !(sio_data
->skip_vid
))
1524 sio_data
->vid_value
= superio_inb(IT87_SIO_VID_REG
);
1526 reg
= superio_inb(IT87_SIO_PINX2_REG
);
1528 * The IT8720F has no VIN7 pin, so VCCH should always be
1529 * routed internally to VIN7 with an internal divider.
1530 * Curiously, there still is a configuration bit to control
1531 * this, which means it can be set incorrectly. And even
1532 * more curiously, many boards out there are improperly
1533 * configured, even though the IT8720F datasheet claims
1534 * that the internal routing of VCCH to VIN7 is the default
1535 * setting. So we force the internal routing in this case.
1537 if (sio_data
->type
== it8720
&& !(reg
& (1 << 1))) {
1539 superio_outb(IT87_SIO_PINX2_REG
, reg
);
1540 pr_notice("it87: Routing internal VCCH to in7\n");
1543 pr_info("it87: in3 is VCC (+5V)\n");
1545 pr_info("it87: in7 is VCCH (+5V Stand-By)\n");
1547 sio_data
->beep_pin
= superio_inb(IT87_SIO_BEEP_PIN_REG
) & 0x3f;
1549 if (sio_data
->beep_pin
)
1550 pr_info("it87: Beeping is supported\n");
1552 /* Disable specific features based on DMI strings */
1553 board_vendor
= dmi_get_system_info(DMI_BOARD_VENDOR
);
1554 board_name
= dmi_get_system_info(DMI_BOARD_NAME
);
1555 if (board_vendor
&& board_name
) {
1556 if (strcmp(board_vendor
, "nVIDIA") == 0
1557 && strcmp(board_name
, "FN68PT") == 0) {
1558 /* On the Shuttle SN68PT, FAN_CTL2 is apparently not
1559 connected to a fan, but to something else. One user
1560 has reported instant system power-off when changing
1561 the PWM2 duty cycle, so we disable it.
1562 I use the board name string as the trigger in case
1563 the same board is ever used in other systems. */
1564 pr_info("it87: Disabling pwm2 due to "
1565 "hardware constraints\n");
1566 sio_data
->skip_pwm
= (1 << 1);
1575 static void it87_remove_files(struct device
*dev
)
1577 struct it87_data
*data
= platform_get_drvdata(pdev
);
1578 struct it87_sio_data
*sio_data
= dev
->platform_data
;
1579 const struct attribute_group
*fan_group
= it87_get_fan_group(data
);
1582 sysfs_remove_group(&dev
->kobj
, &it87_group
);
1583 if (sio_data
->beep_pin
)
1584 sysfs_remove_group(&dev
->kobj
, &it87_group_beep
);
1585 for (i
= 0; i
< 5; i
++) {
1586 if (!(data
->has_fan
& (1 << i
)))
1588 sysfs_remove_group(&dev
->kobj
, &fan_group
[i
]);
1589 if (sio_data
->beep_pin
)
1590 sysfs_remove_file(&dev
->kobj
,
1591 it87_attributes_fan_beep
[i
]);
1593 for (i
= 0; i
< 3; i
++) {
1594 if (sio_data
->skip_pwm
& (1 << 0))
1596 sysfs_remove_group(&dev
->kobj
, &it87_group_pwm
[i
]);
1597 if (has_old_autopwm(data
))
1598 sysfs_remove_group(&dev
->kobj
,
1599 &it87_group_autopwm
[i
]);
1601 if (!sio_data
->skip_vid
)
1602 sysfs_remove_group(&dev
->kobj
, &it87_group_vid
);
1605 static int __devinit
it87_probe(struct platform_device
*pdev
)
1607 struct it87_data
*data
;
1608 struct resource
*res
;
1609 struct device
*dev
= &pdev
->dev
;
1610 struct it87_sio_data
*sio_data
= dev
->platform_data
;
1611 const struct attribute_group
*fan_group
;
1613 int enable_pwm_interface
;
1614 int fan_beep_need_rw
;
1615 static const char *names
[] = {
1623 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
1624 if (!request_region(res
->start
, IT87_EC_EXTENT
, DRVNAME
)) {
1625 dev_err(dev
, "Failed to request region 0x%lx-0x%lx\n",
1626 (unsigned long)res
->start
,
1627 (unsigned long)(res
->start
+ IT87_EC_EXTENT
- 1));
1632 data
= kzalloc(sizeof(struct it87_data
), GFP_KERNEL
);
1638 data
->addr
= res
->start
;
1639 data
->type
= sio_data
->type
;
1640 data
->revision
= sio_data
->revision
;
1641 data
->name
= names
[sio_data
->type
];
1643 /* Now, we do the remaining detection. */
1644 if ((it87_read_value(data
, IT87_REG_CONFIG
) & 0x80)
1645 || it87_read_value(data
, IT87_REG_CHIPID
) != 0x90) {
1650 platform_set_drvdata(pdev
, data
);
1652 mutex_init(&data
->update_lock
);
1654 /* Check PWM configuration */
1655 enable_pwm_interface
= it87_check_pwm(dev
);
1657 /* Initialize the IT87 chip */
1658 it87_init_device(pdev
);
1660 /* Register sysfs hooks */
1661 err
= sysfs_create_group(&dev
->kobj
, &it87_group
);
1665 if (sio_data
->beep_pin
) {
1666 err
= sysfs_create_group(&dev
->kobj
, &it87_group_beep
);
1671 /* Do not create fan files for disabled fans */
1672 fan_group
= it87_get_fan_group(data
);
1673 fan_beep_need_rw
= 1;
1674 for (i
= 0; i
< 5; i
++) {
1675 if (!(data
->has_fan
& (1 << i
)))
1677 err
= sysfs_create_group(&dev
->kobj
, &fan_group
[i
]);
1681 if (sio_data
->beep_pin
) {
1682 err
= sysfs_create_file(&dev
->kobj
,
1683 it87_attributes_fan_beep
[i
]);
1686 if (!fan_beep_need_rw
)
1689 /* As we have a single beep enable bit for all fans,
1690 * only the first enabled fan has a writable attribute
1692 if (sysfs_chmod_file(&dev
->kobj
,
1693 it87_attributes_fan_beep
[i
],
1695 dev_dbg(dev
, "chmod +w fan%d_beep failed\n",
1697 fan_beep_need_rw
= 0;
1701 if (enable_pwm_interface
) {
1702 for (i
= 0; i
< 3; i
++) {
1703 if (sio_data
->skip_pwm
& (1 << i
))
1705 err
= sysfs_create_group(&dev
->kobj
,
1706 &it87_group_pwm
[i
]);
1710 if (!has_old_autopwm(data
))
1712 err
= sysfs_create_group(&dev
->kobj
,
1713 &it87_group_autopwm
[i
]);
1719 if (!sio_data
->skip_vid
) {
1720 data
->vrm
= vid_which_vrm();
1721 /* VID reading from Super-I/O config space if available */
1722 data
->vid
= sio_data
->vid_value
;
1723 err
= sysfs_create_group(&dev
->kobj
, &it87_group_vid
);
1728 data
->hwmon_dev
= hwmon_device_register(dev
);
1729 if (IS_ERR(data
->hwmon_dev
)) {
1730 err
= PTR_ERR(data
->hwmon_dev
);
1737 it87_remove_files(dev
);
1739 platform_set_drvdata(pdev
, NULL
);
1742 release_region(res
->start
, IT87_EC_EXTENT
);
1747 static int __devexit
it87_remove(struct platform_device
*pdev
)
1749 struct it87_data
*data
= platform_get_drvdata(pdev
);
1751 hwmon_device_unregister(data
->hwmon_dev
);
1752 it87_remove_files(&pdev
->dev
);
1754 release_region(data
->addr
, IT87_EC_EXTENT
);
1755 platform_set_drvdata(pdev
, NULL
);
1761 /* Must be called with data->update_lock held, except during initialization.
1762 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1763 would slow down the IT87 access and should not be necessary. */
1764 static int it87_read_value(struct it87_data
*data
, u8 reg
)
1766 outb_p(reg
, data
->addr
+ IT87_ADDR_REG_OFFSET
);
1767 return inb_p(data
->addr
+ IT87_DATA_REG_OFFSET
);
1770 /* Must be called with data->update_lock held, except during initialization.
1771 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1772 would slow down the IT87 access and should not be necessary. */
1773 static void it87_write_value(struct it87_data
*data
, u8 reg
, u8 value
)
1775 outb_p(reg
, data
->addr
+ IT87_ADDR_REG_OFFSET
);
1776 outb_p(value
, data
->addr
+ IT87_DATA_REG_OFFSET
);
1779 /* Return 1 if and only if the PWM interface is safe to use */
1780 static int __devinit
it87_check_pwm(struct device
*dev
)
1782 struct it87_data
*data
= dev_get_drvdata(dev
);
1783 /* Some BIOSes fail to correctly configure the IT87 fans. All fans off
1784 * and polarity set to active low is sign that this is the case so we
1785 * disable pwm control to protect the user. */
1786 int tmp
= it87_read_value(data
, IT87_REG_FAN_CTL
);
1787 if ((tmp
& 0x87) == 0) {
1788 if (fix_pwm_polarity
) {
1789 /* The user asks us to attempt a chip reconfiguration.
1790 * This means switching to active high polarity and
1791 * inverting all fan speed values. */
1795 for (i
= 0; i
< 3; i
++)
1796 pwm
[i
] = it87_read_value(data
,
1799 /* If any fan is in automatic pwm mode, the polarity
1800 * might be correct, as suspicious as it seems, so we
1801 * better don't change anything (but still disable the
1802 * PWM interface). */
1803 if (!((pwm
[0] | pwm
[1] | pwm
[2]) & 0x80)) {
1804 dev_info(dev
, "Reconfiguring PWM to "
1805 "active high polarity\n");
1806 it87_write_value(data
, IT87_REG_FAN_CTL
,
1808 for (i
= 0; i
< 3; i
++)
1809 it87_write_value(data
,
1815 dev_info(dev
, "PWM configuration is "
1816 "too broken to be fixed\n");
1819 dev_info(dev
, "Detected broken BIOS "
1820 "defaults, disabling PWM interface\n");
1822 } else if (fix_pwm_polarity
) {
1823 dev_info(dev
, "PWM configuration looks "
1824 "sane, won't touch\n");
1830 /* Called when we have found a new IT87. */
1831 static void __devinit
it87_init_device(struct platform_device
*pdev
)
1833 struct it87_sio_data
*sio_data
= pdev
->dev
.platform_data
;
1834 struct it87_data
*data
= platform_get_drvdata(pdev
);
1838 /* For each PWM channel:
1839 * - If it is in automatic mode, setting to manual mode should set
1840 * the fan to full speed by default.
1841 * - If it is in manual mode, we need a mapping to temperature
1842 * channels to use when later setting to automatic mode later.
1843 * Use a 1:1 mapping by default (we are clueless.)
1844 * In both cases, the value can (and should) be changed by the user
1845 * prior to switching to a different mode. */
1846 for (i
= 0; i
< 3; i
++) {
1847 data
->pwm_temp_map
[i
] = i
;
1848 data
->pwm_duty
[i
] = 0x7f; /* Full speed */
1849 data
->auto_pwm
[i
][3] = 0x7f; /* Full speed, hard-coded */
1852 /* Some chips seem to have default value 0xff for all limit
1853 * registers. For low voltage limits it makes no sense and triggers
1854 * alarms, so change to 0 instead. For high temperature limits, it
1855 * means -1 degree C, which surprisingly doesn't trigger an alarm,
1856 * but is still confusing, so change to 127 degrees C. */
1857 for (i
= 0; i
< 8; i
++) {
1858 tmp
= it87_read_value(data
, IT87_REG_VIN_MIN(i
));
1860 it87_write_value(data
, IT87_REG_VIN_MIN(i
), 0);
1862 for (i
= 0; i
< 3; i
++) {
1863 tmp
= it87_read_value(data
, IT87_REG_TEMP_HIGH(i
));
1865 it87_write_value(data
, IT87_REG_TEMP_HIGH(i
), 127);
1868 /* Temperature channels are not forcibly enabled, as they can be
1869 * set to two different sensor types and we can't guess which one
1870 * is correct for a given system. These channels can be enabled at
1871 * run-time through the temp{1-3}_type sysfs accessors if needed. */
1873 /* Check if voltage monitors are reset manually or by some reason */
1874 tmp
= it87_read_value(data
, IT87_REG_VIN_ENABLE
);
1875 if ((tmp
& 0xff) == 0) {
1876 /* Enable all voltage monitors */
1877 it87_write_value(data
, IT87_REG_VIN_ENABLE
, 0xff);
1880 /* Check if tachometers are reset manually or by some reason */
1881 mask
= 0x70 & ~(sio_data
->skip_fan
<< 4);
1882 data
->fan_main_ctrl
= it87_read_value(data
, IT87_REG_FAN_MAIN_CTRL
);
1883 if ((data
->fan_main_ctrl
& mask
) == 0) {
1884 /* Enable all fan tachometers */
1885 data
->fan_main_ctrl
|= mask
;
1886 it87_write_value(data
, IT87_REG_FAN_MAIN_CTRL
,
1887 data
->fan_main_ctrl
);
1889 data
->has_fan
= (data
->fan_main_ctrl
>> 4) & 0x07;
1891 /* Set tachometers to 16-bit mode if needed */
1892 if (has_16bit_fans(data
)) {
1893 tmp
= it87_read_value(data
, IT87_REG_FAN_16BIT
);
1894 if (~tmp
& 0x07 & data
->has_fan
) {
1896 "Setting fan1-3 to 16-bit mode\n");
1897 it87_write_value(data
, IT87_REG_FAN_16BIT
,
1900 /* IT8705F only supports three fans. */
1901 if (data
->type
!= it87
) {
1903 data
->has_fan
|= (1 << 3); /* fan4 enabled */
1905 data
->has_fan
|= (1 << 4); /* fan5 enabled */
1909 /* Fan input pins may be used for alternative functions */
1910 data
->has_fan
&= ~sio_data
->skip_fan
;
1912 /* Start monitoring */
1913 it87_write_value(data
, IT87_REG_CONFIG
,
1914 (it87_read_value(data
, IT87_REG_CONFIG
) & 0x36)
1915 | (update_vbat
? 0x41 : 0x01));
1918 static void it87_update_pwm_ctrl(struct it87_data
*data
, int nr
)
1920 data
->pwm_ctrl
[nr
] = it87_read_value(data
, IT87_REG_PWM(nr
));
1921 if (data
->pwm_ctrl
[nr
] & 0x80) /* Automatic mode */
1922 data
->pwm_temp_map
[nr
] = data
->pwm_ctrl
[nr
] & 0x03;
1923 else /* Manual mode */
1924 data
->pwm_duty
[nr
] = data
->pwm_ctrl
[nr
] & 0x7f;
1926 if (has_old_autopwm(data
)) {
1929 for (i
= 0; i
< 5 ; i
++)
1930 data
->auto_temp
[nr
][i
] = it87_read_value(data
,
1931 IT87_REG_AUTO_TEMP(nr
, i
));
1932 for (i
= 0; i
< 3 ; i
++)
1933 data
->auto_pwm
[nr
][i
] = it87_read_value(data
,
1934 IT87_REG_AUTO_PWM(nr
, i
));
1938 static struct it87_data
*it87_update_device(struct device
*dev
)
1940 struct it87_data
*data
= dev_get_drvdata(dev
);
1943 mutex_lock(&data
->update_lock
);
1945 if (time_after(jiffies
, data
->last_updated
+ HZ
+ HZ
/ 2)
1948 /* Cleared after each update, so reenable. Value
1949 returned by this read will be previous value */
1950 it87_write_value(data
, IT87_REG_CONFIG
,
1951 it87_read_value(data
, IT87_REG_CONFIG
) | 0x40);
1953 for (i
= 0; i
<= 7; i
++) {
1955 it87_read_value(data
, IT87_REG_VIN(i
));
1957 it87_read_value(data
, IT87_REG_VIN_MIN(i
));
1959 it87_read_value(data
, IT87_REG_VIN_MAX(i
));
1961 /* in8 (battery) has no limit registers */
1962 data
->in
[8] = it87_read_value(data
, IT87_REG_VIN(8));
1964 for (i
= 0; i
< 5; i
++) {
1965 /* Skip disabled fans */
1966 if (!(data
->has_fan
& (1 << i
)))
1970 it87_read_value(data
, IT87_REG_FAN_MIN
[i
]);
1971 data
->fan
[i
] = it87_read_value(data
,
1973 /* Add high byte if in 16-bit mode */
1974 if (has_16bit_fans(data
)) {
1975 data
->fan
[i
] |= it87_read_value(data
,
1976 IT87_REG_FANX
[i
]) << 8;
1977 data
->fan_min
[i
] |= it87_read_value(data
,
1978 IT87_REG_FANX_MIN
[i
]) << 8;
1981 for (i
= 0; i
< 3; i
++) {
1983 it87_read_value(data
, IT87_REG_TEMP(i
));
1984 data
->temp_high
[i
] =
1985 it87_read_value(data
, IT87_REG_TEMP_HIGH(i
));
1987 it87_read_value(data
, IT87_REG_TEMP_LOW(i
));
1990 /* Newer chips don't have clock dividers */
1991 if ((data
->has_fan
& 0x07) && !has_16bit_fans(data
)) {
1992 i
= it87_read_value(data
, IT87_REG_FAN_DIV
);
1993 data
->fan_div
[0] = i
& 0x07;
1994 data
->fan_div
[1] = (i
>> 3) & 0x07;
1995 data
->fan_div
[2] = (i
& 0x40) ? 3 : 1;
1999 it87_read_value(data
, IT87_REG_ALARM1
) |
2000 (it87_read_value(data
, IT87_REG_ALARM2
) << 8) |
2001 (it87_read_value(data
, IT87_REG_ALARM3
) << 16);
2002 data
->beeps
= it87_read_value(data
, IT87_REG_BEEP_ENABLE
);
2004 data
->fan_main_ctrl
= it87_read_value(data
,
2005 IT87_REG_FAN_MAIN_CTRL
);
2006 data
->fan_ctl
= it87_read_value(data
, IT87_REG_FAN_CTL
);
2007 for (i
= 0; i
< 3; i
++)
2008 it87_update_pwm_ctrl(data
, i
);
2010 data
->sensor
= it87_read_value(data
, IT87_REG_TEMP_ENABLE
);
2011 /* The 8705 does not have VID capability.
2012 The 8718 and the 8720 don't use IT87_REG_VID for the
2014 if (data
->type
== it8712
|| data
->type
== it8716
) {
2015 data
->vid
= it87_read_value(data
, IT87_REG_VID
);
2016 /* The older IT8712F revisions had only 5 VID pins,
2017 but we assume it is always safe to read 6 bits. */
2020 data
->last_updated
= jiffies
;
2024 mutex_unlock(&data
->update_lock
);
2029 static int __init
it87_device_add(unsigned short address
,
2030 const struct it87_sio_data
*sio_data
)
2032 struct resource res
= {
2033 .start
= address
+ IT87_EC_OFFSET
,
2034 .end
= address
+ IT87_EC_OFFSET
+ IT87_EC_EXTENT
- 1,
2036 .flags
= IORESOURCE_IO
,
2040 err
= acpi_check_resource_conflict(&res
);
2044 pdev
= platform_device_alloc(DRVNAME
, address
);
2047 printk(KERN_ERR DRVNAME
": Device allocation failed\n");
2051 err
= platform_device_add_resources(pdev
, &res
, 1);
2053 printk(KERN_ERR DRVNAME
": Device resource addition failed "
2055 goto exit_device_put
;
2058 err
= platform_device_add_data(pdev
, sio_data
,
2059 sizeof(struct it87_sio_data
));
2061 printk(KERN_ERR DRVNAME
": Platform data allocation failed\n");
2062 goto exit_device_put
;
2065 err
= platform_device_add(pdev
);
2067 printk(KERN_ERR DRVNAME
": Device addition failed (%d)\n",
2069 goto exit_device_put
;
2075 platform_device_put(pdev
);
2080 static int __init
sm_it87_init(void)
2083 unsigned short isa_address
= 0;
2084 struct it87_sio_data sio_data
;
2086 memset(&sio_data
, 0, sizeof(struct it87_sio_data
));
2087 err
= it87_find(&isa_address
, &sio_data
);
2090 err
= platform_driver_register(&it87_driver
);
2094 err
= it87_device_add(isa_address
, &sio_data
);
2096 platform_driver_unregister(&it87_driver
);
2103 static void __exit
sm_it87_exit(void)
2105 platform_device_unregister(pdev
);
2106 platform_driver_unregister(&it87_driver
);
2110 MODULE_AUTHOR("Chris Gauthron, "
2111 "Jean Delvare <khali@linux-fr.org>");
2112 MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F/8720F/8726F, SiS950 driver");
2113 module_param(update_vbat
, bool, 0);
2114 MODULE_PARM_DESC(update_vbat
, "Update vbat if set else return powerup value");
2115 module_param(fix_pwm_polarity
, bool, 0);
2116 MODULE_PARM_DESC(fix_pwm_polarity
,
2117 "Force PWM polarity to active high (DANGEROUS)");
2118 MODULE_LICENSE("GPL");
2120 module_init(sm_it87_init
);
2121 module_exit(sm_it87_exit
);