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 * IT8721F Super I/O chip w/LPC interface
19 * IT8726F Super I/O chip w/LPC interface
20 * IT8728F Super I/O chip w/LPC interface
21 * IT8758E Super I/O chip w/LPC interface
22 * IT8782F Super I/O chip w/LPC interface
23 * IT8783E/F Super I/O chip w/LPC interface
24 * Sis950 A clone of the IT8705F
26 * Copyright (C) 2001 Chris Gauthron
27 * Copyright (C) 2005-2010 Jean Delvare <khali@linux-fr.org>
29 * This program is free software; you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License as published by
31 * the Free Software Foundation; either version 2 of the License, or
32 * (at your option) any later version.
34 * This program is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 * GNU General Public License for more details.
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
44 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
46 #include <linux/module.h>
47 #include <linux/init.h>
48 #include <linux/slab.h>
49 #include <linux/jiffies.h>
50 #include <linux/platform_device.h>
51 #include <linux/hwmon.h>
52 #include <linux/hwmon-sysfs.h>
53 #include <linux/hwmon-vid.h>
54 #include <linux/err.h>
55 #include <linux/mutex.h>
56 #include <linux/sysfs.h>
57 #include <linux/string.h>
58 #include <linux/dmi.h>
59 #include <linux/acpi.h>
62 #define DRVNAME "it87"
64 enum chips
{ it87
, it8712
, it8716
, it8718
, it8720
, it8721
, it8728
, it8782
,
67 static unsigned short force_id
;
68 module_param(force_id
, ushort
, 0);
69 MODULE_PARM_DESC(force_id
, "Override the detected device ID");
71 static struct platform_device
*pdev
;
73 #define REG 0x2e /* The register to read/write */
74 #define DEV 0x07 /* Register: Logical device select */
75 #define VAL 0x2f /* The value to read/write */
76 #define PME 0x04 /* The device with the fan registers in it */
78 /* The device with the IT8718F/IT8720F VID value in it */
81 #define DEVID 0x20 /* Register: Device ID */
82 #define DEVREV 0x22 /* Register: Device Revision */
84 static inline int superio_inb(int reg
)
90 static inline void superio_outb(int reg
, int val
)
96 static int superio_inw(int reg
)
106 static inline void superio_select(int ldn
)
112 static inline int superio_enter(void)
115 * Try to reserve REG and REG + 1 for exclusive access.
117 if (!request_muxed_region(REG
, 2, DRVNAME
))
127 static inline void superio_exit(void)
131 release_region(REG
, 2);
134 /* Logical device 4 registers */
135 #define IT8712F_DEVID 0x8712
136 #define IT8705F_DEVID 0x8705
137 #define IT8716F_DEVID 0x8716
138 #define IT8718F_DEVID 0x8718
139 #define IT8720F_DEVID 0x8720
140 #define IT8721F_DEVID 0x8721
141 #define IT8726F_DEVID 0x8726
142 #define IT8728F_DEVID 0x8728
143 #define IT8782F_DEVID 0x8782
144 #define IT8783E_DEVID 0x8783
145 #define IT87_ACT_REG 0x30
146 #define IT87_BASE_REG 0x60
148 /* Logical device 7 registers (IT8712F and later) */
149 #define IT87_SIO_GPIO1_REG 0x25
150 #define IT87_SIO_GPIO3_REG 0x27
151 #define IT87_SIO_GPIO5_REG 0x29
152 #define IT87_SIO_PINX1_REG 0x2a /* Pin selection */
153 #define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
154 #define IT87_SIO_SPI_REG 0xef /* SPI function pin select */
155 #define IT87_SIO_VID_REG 0xfc /* VID value */
156 #define IT87_SIO_BEEP_PIN_REG 0xf6 /* Beep pin mapping */
158 /* Update battery voltage after every reading if true */
159 static bool update_vbat
;
161 /* Not all BIOSes properly configure the PWM registers */
162 static bool fix_pwm_polarity
;
164 /* Many IT87 constants specified below */
166 /* Length of ISA address segment */
167 #define IT87_EXTENT 8
169 /* Length of ISA address segment for Environmental Controller */
170 #define IT87_EC_EXTENT 2
172 /* Offset of EC registers from ISA base address */
173 #define IT87_EC_OFFSET 5
175 /* Where are the ISA address/data registers relative to the EC base address */
176 #define IT87_ADDR_REG_OFFSET 0
177 #define IT87_DATA_REG_OFFSET 1
179 /*----- The IT87 registers -----*/
181 #define IT87_REG_CONFIG 0x00
183 #define IT87_REG_ALARM1 0x01
184 #define IT87_REG_ALARM2 0x02
185 #define IT87_REG_ALARM3 0x03
188 * The IT8718F and IT8720F have the VID value in a different register, in
189 * Super-I/O configuration space.
191 #define IT87_REG_VID 0x0a
193 * The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b
194 * for fan divisors. Later IT8712F revisions must use 16-bit tachometer
197 #define IT87_REG_FAN_DIV 0x0b
198 #define IT87_REG_FAN_16BIT 0x0c
200 /* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */
202 static const u8 IT87_REG_FAN
[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82 };
203 static const u8 IT87_REG_FAN_MIN
[] = { 0x10, 0x11, 0x12, 0x84, 0x86 };
204 static const u8 IT87_REG_FANX
[] = { 0x18, 0x19, 0x1a, 0x81, 0x83 };
205 static const u8 IT87_REG_FANX_MIN
[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 };
206 static const u8 IT87_REG_TEMP_OFFSET
[] = { 0x56, 0x57, 0x59 };
208 #define IT87_REG_FAN_MAIN_CTRL 0x13
209 #define IT87_REG_FAN_CTL 0x14
210 #define IT87_REG_PWM(nr) (0x15 + (nr))
211 #define IT87_REG_PWM_DUTY(nr) (0x63 + (nr) * 8)
213 #define IT87_REG_VIN(nr) (0x20 + (nr))
214 #define IT87_REG_TEMP(nr) (0x29 + (nr))
216 #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2)
217 #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2)
218 #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2)
219 #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2)
221 #define IT87_REG_VIN_ENABLE 0x50
222 #define IT87_REG_TEMP_ENABLE 0x51
223 #define IT87_REG_TEMP_EXTRA 0x55
224 #define IT87_REG_BEEP_ENABLE 0x5c
226 #define IT87_REG_CHIPID 0x58
228 #define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i))
229 #define IT87_REG_AUTO_PWM(nr, i) (0x65 + (nr) * 8 + (i))
231 struct it87_devices
{
238 #define FEAT_12MV_ADC (1 << 0)
239 #define FEAT_NEWER_AUTOPWM (1 << 1)
240 #define FEAT_OLD_AUTOPWM (1 << 2)
241 #define FEAT_16BIT_FANS (1 << 3)
242 #define FEAT_TEMP_OFFSET (1 << 4)
243 #define FEAT_TEMP_PECI (1 << 5)
244 #define FEAT_TEMP_OLD_PECI (1 << 6)
246 static const struct it87_devices it87_devices
[] = {
249 .features
= FEAT_OLD_AUTOPWM
, /* may need to overwrite */
253 .features
= FEAT_OLD_AUTOPWM
, /* may need to overwrite */
257 .features
= FEAT_16BIT_FANS
| FEAT_TEMP_OFFSET
,
261 .features
= FEAT_16BIT_FANS
| FEAT_TEMP_OFFSET
262 | FEAT_TEMP_OLD_PECI
,
263 .old_peci_mask
= 0x4,
267 .features
= FEAT_16BIT_FANS
| FEAT_TEMP_OFFSET
268 | FEAT_TEMP_OLD_PECI
,
269 .old_peci_mask
= 0x4,
273 .features
= FEAT_NEWER_AUTOPWM
| FEAT_12MV_ADC
| FEAT_16BIT_FANS
274 | FEAT_TEMP_OFFSET
| FEAT_TEMP_OLD_PECI
| FEAT_TEMP_PECI
,
276 .old_peci_mask
= 0x02, /* Actually reports PCH */
280 .features
= FEAT_NEWER_AUTOPWM
| FEAT_12MV_ADC
| FEAT_16BIT_FANS
281 | FEAT_TEMP_OFFSET
| FEAT_TEMP_PECI
,
286 .features
= FEAT_16BIT_FANS
| FEAT_TEMP_OFFSET
287 | FEAT_TEMP_OLD_PECI
,
288 .old_peci_mask
= 0x4,
292 .features
= FEAT_16BIT_FANS
| FEAT_TEMP_OFFSET
293 | FEAT_TEMP_OLD_PECI
,
294 .old_peci_mask
= 0x4,
298 #define has_16bit_fans(data) ((data)->features & FEAT_16BIT_FANS)
299 #define has_12mv_adc(data) ((data)->features & FEAT_12MV_ADC)
300 #define has_newer_autopwm(data) ((data)->features & FEAT_NEWER_AUTOPWM)
301 #define has_old_autopwm(data) ((data)->features & FEAT_OLD_AUTOPWM)
302 #define has_temp_offset(data) ((data)->features & FEAT_TEMP_OFFSET)
303 #define has_temp_peci(data, nr) (((data)->features & FEAT_TEMP_PECI) && \
304 ((data)->peci_mask & (1 << nr)))
305 #define has_temp_old_peci(data, nr) \
306 (((data)->features & FEAT_TEMP_OLD_PECI) && \
307 ((data)->old_peci_mask & (1 << nr)))
309 struct it87_sio_data
{
311 /* Values read from Super-I/O config space */
315 u8 internal
; /* Internal sensors can be labeled */
316 /* Features skipped based on config or DMI */
325 * For each registered chip, we need to keep some data in memory.
326 * The structure is dynamically allocated.
329 struct device
*hwmon_dev
;
337 struct mutex update_lock
;
338 char valid
; /* !=0 if following fields are valid */
339 unsigned long last_updated
; /* In jiffies */
341 u16 in_scaled
; /* Internal voltage sensors are scaled */
342 u8 in
[9][3]; /* [nr][0]=in, [1]=min, [2]=max */
343 u8 has_fan
; /* Bitfield, fans enabled */
344 u16 fan
[5][2]; /* Register values, [nr][0]=fan, [1]=min */
345 u8 has_temp
; /* Bitfield, temp sensors enabled */
346 s8 temp
[3][4]; /* [nr][0]=temp, [1]=min, [2]=max, [3]=offset */
347 u8 sensor
; /* Register value (IT87_REG_TEMP_ENABLE) */
348 u8 extra
; /* Register value (IT87_REG_TEMP_EXTRA) */
349 u8 fan_div
[3]; /* Register encoding, shifted right */
350 u8 vid
; /* Register encoding, combined */
352 u32 alarms
; /* Register encoding, combined */
353 u8 beeps
; /* Register encoding */
354 u8 fan_main_ctrl
; /* Register value */
355 u8 fan_ctl
; /* Register value */
358 * The following 3 arrays correspond to the same registers up to
359 * the IT8720F. The meaning of bits 6-0 depends on the value of bit
360 * 7, and we want to preserve settings on mode changes, so we have
361 * to track all values separately.
362 * Starting with the IT8721F, the manual PWM duty cycles are stored
363 * in separate registers (8-bit values), so the separate tracking
364 * is no longer needed, but it is still done to keep the driver
367 u8 pwm_ctrl
[3]; /* Register value */
368 u8 pwm_duty
[3]; /* Manual PWM value set by user */
369 u8 pwm_temp_map
[3]; /* PWM to temp. chan. mapping (bits 1-0) */
371 /* Automatic fan speed control registers */
372 u8 auto_pwm
[3][4]; /* [nr][3] is hard-coded */
373 s8 auto_temp
[3][5]; /* [nr][0] is point1_temp_hyst */
376 static int adc_lsb(const struct it87_data
*data
, int nr
)
378 int lsb
= has_12mv_adc(data
) ? 12 : 16;
379 if (data
->in_scaled
& (1 << nr
))
384 static u8
in_to_reg(const struct it87_data
*data
, int nr
, long val
)
386 val
= DIV_ROUND_CLOSEST(val
, adc_lsb(data
, nr
));
387 return SENSORS_LIMIT(val
, 0, 255);
390 static int in_from_reg(const struct it87_data
*data
, int nr
, int val
)
392 return val
* adc_lsb(data
, nr
);
395 static inline u8
FAN_TO_REG(long rpm
, int div
)
399 rpm
= SENSORS_LIMIT(rpm
, 1, 1000000);
400 return SENSORS_LIMIT((1350000 + rpm
* div
/ 2) / (rpm
* div
), 1,
404 static inline u16
FAN16_TO_REG(long rpm
)
408 return SENSORS_LIMIT((1350000 + rpm
) / (rpm
* 2), 1, 0xfffe);
411 #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \
412 1350000 / ((val) * (div)))
413 /* The divider is fixed to 2 in 16-bit mode */
414 #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
415 1350000 / ((val) * 2))
417 #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? (((val) - 500) / 1000) : \
418 ((val) + 500) / 1000), -128, 127))
419 #define TEMP_FROM_REG(val) ((val) * 1000)
421 static u8
pwm_to_reg(const struct it87_data
*data
, long val
)
423 if (has_newer_autopwm(data
))
429 static int pwm_from_reg(const struct it87_data
*data
, u8 reg
)
431 if (has_newer_autopwm(data
))
434 return (reg
& 0x7f) << 1;
438 static int DIV_TO_REG(int val
)
441 while (answer
< 7 && (val
>>= 1))
445 #define DIV_FROM_REG(val) (1 << (val))
447 static const unsigned int pwm_freq
[8] = {
458 static int it87_probe(struct platform_device
*pdev
);
459 static int it87_remove(struct platform_device
*pdev
);
461 static int it87_read_value(struct it87_data
*data
, u8 reg
);
462 static void it87_write_value(struct it87_data
*data
, u8 reg
, u8 value
);
463 static struct it87_data
*it87_update_device(struct device
*dev
);
464 static int it87_check_pwm(struct device
*dev
);
465 static void it87_init_device(struct platform_device
*pdev
);
468 static struct platform_driver it87_driver
= {
470 .owner
= THIS_MODULE
,
474 .remove
= it87_remove
,
477 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*attr
,
480 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
482 int index
= sattr
->index
;
484 struct it87_data
*data
= it87_update_device(dev
);
485 return sprintf(buf
, "%d\n", in_from_reg(data
, nr
, data
->in
[nr
][index
]));
488 static ssize_t
set_in(struct device
*dev
, struct device_attribute
*attr
,
489 const char *buf
, size_t count
)
491 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
493 int index
= sattr
->index
;
495 struct it87_data
*data
= dev_get_drvdata(dev
);
498 if (kstrtoul(buf
, 10, &val
) < 0)
501 mutex_lock(&data
->update_lock
);
502 data
->in
[nr
][index
] = in_to_reg(data
, nr
, val
);
503 it87_write_value(data
,
504 index
== 1 ? IT87_REG_VIN_MIN(nr
)
505 : IT87_REG_VIN_MAX(nr
),
506 data
->in
[nr
][index
]);
507 mutex_unlock(&data
->update_lock
);
511 static SENSOR_DEVICE_ATTR_2(in0_input
, S_IRUGO
, show_in
, NULL
, 0, 0);
512 static SENSOR_DEVICE_ATTR_2(in0_min
, S_IRUGO
| S_IWUSR
, show_in
, set_in
,
514 static SENSOR_DEVICE_ATTR_2(in0_max
, S_IRUGO
| S_IWUSR
, show_in
, set_in
,
517 static SENSOR_DEVICE_ATTR_2(in1_input
, S_IRUGO
, show_in
, NULL
, 1, 0);
518 static SENSOR_DEVICE_ATTR_2(in1_min
, S_IRUGO
| S_IWUSR
, show_in
, set_in
,
520 static SENSOR_DEVICE_ATTR_2(in1_max
, S_IRUGO
| S_IWUSR
, show_in
, set_in
,
523 static SENSOR_DEVICE_ATTR_2(in2_input
, S_IRUGO
, show_in
, NULL
, 2, 0);
524 static SENSOR_DEVICE_ATTR_2(in2_min
, S_IRUGO
| S_IWUSR
, show_in
, set_in
,
526 static SENSOR_DEVICE_ATTR_2(in2_max
, S_IRUGO
| S_IWUSR
, show_in
, set_in
,
529 static SENSOR_DEVICE_ATTR_2(in3_input
, S_IRUGO
, show_in
, NULL
, 3, 0);
530 static SENSOR_DEVICE_ATTR_2(in3_min
, S_IRUGO
| S_IWUSR
, show_in
, set_in
,
532 static SENSOR_DEVICE_ATTR_2(in3_max
, S_IRUGO
| S_IWUSR
, show_in
, set_in
,
535 static SENSOR_DEVICE_ATTR_2(in4_input
, S_IRUGO
, show_in
, NULL
, 4, 0);
536 static SENSOR_DEVICE_ATTR_2(in4_min
, S_IRUGO
| S_IWUSR
, show_in
, set_in
,
538 static SENSOR_DEVICE_ATTR_2(in4_max
, S_IRUGO
| S_IWUSR
, show_in
, set_in
,
541 static SENSOR_DEVICE_ATTR_2(in5_input
, S_IRUGO
, show_in
, NULL
, 5, 0);
542 static SENSOR_DEVICE_ATTR_2(in5_min
, S_IRUGO
| S_IWUSR
, show_in
, set_in
,
544 static SENSOR_DEVICE_ATTR_2(in5_max
, S_IRUGO
| S_IWUSR
, show_in
, set_in
,
547 static SENSOR_DEVICE_ATTR_2(in6_input
, S_IRUGO
, show_in
, NULL
, 6, 0);
548 static SENSOR_DEVICE_ATTR_2(in6_min
, S_IRUGO
| S_IWUSR
, show_in
, set_in
,
550 static SENSOR_DEVICE_ATTR_2(in6_max
, S_IRUGO
| S_IWUSR
, show_in
, set_in
,
553 static SENSOR_DEVICE_ATTR_2(in7_input
, S_IRUGO
, show_in
, NULL
, 7, 0);
554 static SENSOR_DEVICE_ATTR_2(in7_min
, S_IRUGO
| S_IWUSR
, show_in
, set_in
,
556 static SENSOR_DEVICE_ATTR_2(in7_max
, S_IRUGO
| S_IWUSR
, show_in
, set_in
,
559 static SENSOR_DEVICE_ATTR_2(in8_input
, S_IRUGO
, show_in
, NULL
, 8, 0);
562 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
*attr
,
565 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
567 int index
= sattr
->index
;
568 struct it87_data
*data
= it87_update_device(dev
);
570 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp
[nr
][index
]));
573 static ssize_t
set_temp(struct device
*dev
, struct device_attribute
*attr
,
574 const char *buf
, size_t count
)
576 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
578 int index
= sattr
->index
;
579 struct it87_data
*data
= dev_get_drvdata(dev
);
583 if (kstrtol(buf
, 10, &val
) < 0)
586 mutex_lock(&data
->update_lock
);
591 reg
= IT87_REG_TEMP_LOW(nr
);
594 reg
= IT87_REG_TEMP_HIGH(nr
);
597 regval
= it87_read_value(data
, IT87_REG_BEEP_ENABLE
);
598 if (!(regval
& 0x80)) {
600 it87_write_value(data
, IT87_REG_BEEP_ENABLE
, regval
);
603 reg
= IT87_REG_TEMP_OFFSET
[nr
];
607 data
->temp
[nr
][index
] = TEMP_TO_REG(val
);
608 it87_write_value(data
, reg
, data
->temp
[nr
][index
]);
609 mutex_unlock(&data
->update_lock
);
613 static SENSOR_DEVICE_ATTR_2(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0, 0);
614 static SENSOR_DEVICE_ATTR_2(temp1_min
, S_IRUGO
| S_IWUSR
, show_temp
, set_temp
,
616 static SENSOR_DEVICE_ATTR_2(temp1_max
, S_IRUGO
| S_IWUSR
, show_temp
, set_temp
,
618 static SENSOR_DEVICE_ATTR_2(temp1_offset
, S_IRUGO
| S_IWUSR
, show_temp
,
620 static SENSOR_DEVICE_ATTR_2(temp2_input
, S_IRUGO
, show_temp
, NULL
, 1, 0);
621 static SENSOR_DEVICE_ATTR_2(temp2_min
, S_IRUGO
| S_IWUSR
, show_temp
, set_temp
,
623 static SENSOR_DEVICE_ATTR_2(temp2_max
, S_IRUGO
| S_IWUSR
, show_temp
, set_temp
,
625 static SENSOR_DEVICE_ATTR_2(temp2_offset
, S_IRUGO
| S_IWUSR
, show_temp
,
627 static SENSOR_DEVICE_ATTR_2(temp3_input
, S_IRUGO
, show_temp
, NULL
, 2, 0);
628 static SENSOR_DEVICE_ATTR_2(temp3_min
, S_IRUGO
| S_IWUSR
, show_temp
, set_temp
,
630 static SENSOR_DEVICE_ATTR_2(temp3_max
, S_IRUGO
| S_IWUSR
, show_temp
, set_temp
,
632 static SENSOR_DEVICE_ATTR_2(temp3_offset
, S_IRUGO
| S_IWUSR
, show_temp
,
635 static ssize_t
show_temp_type(struct device
*dev
, struct device_attribute
*attr
,
638 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
639 int nr
= sensor_attr
->index
;
640 struct it87_data
*data
= it87_update_device(dev
);
641 u8 reg
= data
->sensor
; /* In case value is updated while used */
642 u8 extra
= data
->extra
;
644 if ((has_temp_peci(data
, nr
) && (reg
>> 6 == nr
+ 1))
645 || (has_temp_old_peci(data
, nr
) && (extra
& 0x80)))
646 return sprintf(buf
, "6\n"); /* Intel PECI */
648 return sprintf(buf
, "3\n"); /* thermal diode */
650 return sprintf(buf
, "4\n"); /* thermistor */
651 return sprintf(buf
, "0\n"); /* disabled */
654 static ssize_t
set_temp_type(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 (kstrtol(buf
, 10, &val
) < 0)
667 reg
= it87_read_value(data
, IT87_REG_TEMP_ENABLE
);
670 if (has_temp_peci(data
, nr
) && (reg
>> 6 == nr
+ 1 || val
== 6))
672 extra
= it87_read_value(data
, IT87_REG_TEMP_EXTRA
);
673 if (has_temp_old_peci(data
, nr
) && ((extra
& 0x80) || val
== 6))
675 if (val
== 2) { /* backwards compatibility */
677 "Sensor type 2 is deprecated, please use 4 instead\n");
680 /* 3 = thermal diode; 4 = thermistor; 6 = Intel PECI; 0 = disabled */
685 else if (has_temp_peci(data
, nr
) && val
== 6)
686 reg
|= (nr
+ 1) << 6;
687 else if (has_temp_old_peci(data
, nr
) && val
== 6)
692 mutex_lock(&data
->update_lock
);
695 it87_write_value(data
, IT87_REG_TEMP_ENABLE
, data
->sensor
);
696 if (has_temp_old_peci(data
, nr
))
697 it87_write_value(data
, IT87_REG_TEMP_EXTRA
, data
->extra
);
698 data
->valid
= 0; /* Force cache refresh */
699 mutex_unlock(&data
->update_lock
);
703 static SENSOR_DEVICE_ATTR(temp1_type
, S_IRUGO
| S_IWUSR
, show_temp_type
,
705 static SENSOR_DEVICE_ATTR(temp2_type
, S_IRUGO
| S_IWUSR
, show_temp_type
,
707 static SENSOR_DEVICE_ATTR(temp3_type
, S_IRUGO
| S_IWUSR
, show_temp_type
,
712 static int pwm_mode(const struct it87_data
*data
, int nr
)
714 int ctrl
= data
->fan_main_ctrl
& (1 << nr
);
716 if (ctrl
== 0) /* Full speed */
718 if (data
->pwm_ctrl
[nr
] & 0x80) /* Automatic mode */
720 else /* Manual mode */
724 static ssize_t
show_fan(struct device
*dev
, struct device_attribute
*attr
,
727 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
729 int index
= sattr
->index
;
731 struct it87_data
*data
= it87_update_device(dev
);
733 speed
= has_16bit_fans(data
) ?
734 FAN16_FROM_REG(data
->fan
[nr
][index
]) :
735 FAN_FROM_REG(data
->fan
[nr
][index
],
736 DIV_FROM_REG(data
->fan_div
[nr
]));
737 return sprintf(buf
, "%d\n", speed
);
740 static ssize_t
show_fan_div(struct device
*dev
, struct device_attribute
*attr
,
743 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
744 int nr
= sensor_attr
->index
;
746 struct it87_data
*data
= it87_update_device(dev
);
747 return sprintf(buf
, "%d\n", DIV_FROM_REG(data
->fan_div
[nr
]));
749 static ssize_t
show_pwm_enable(struct device
*dev
,
750 struct device_attribute
*attr
, char *buf
)
752 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
753 int nr
= sensor_attr
->index
;
755 struct it87_data
*data
= it87_update_device(dev
);
756 return sprintf(buf
, "%d\n", pwm_mode(data
, nr
));
758 static ssize_t
show_pwm(struct device
*dev
, struct device_attribute
*attr
,
761 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
762 int nr
= sensor_attr
->index
;
764 struct it87_data
*data
= it87_update_device(dev
);
765 return sprintf(buf
, "%d\n",
766 pwm_from_reg(data
, data
->pwm_duty
[nr
]));
768 static ssize_t
show_pwm_freq(struct device
*dev
, struct device_attribute
*attr
,
771 struct it87_data
*data
= it87_update_device(dev
);
772 int index
= (data
->fan_ctl
>> 4) & 0x07;
774 return sprintf(buf
, "%u\n", pwm_freq
[index
]);
777 static ssize_t
set_fan(struct device
*dev
, struct device_attribute
*attr
,
778 const char *buf
, size_t count
)
780 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
782 int index
= sattr
->index
;
784 struct it87_data
*data
= dev_get_drvdata(dev
);
788 if (kstrtol(buf
, 10, &val
) < 0)
791 mutex_lock(&data
->update_lock
);
793 if (has_16bit_fans(data
)) {
794 data
->fan
[nr
][index
] = FAN16_TO_REG(val
);
795 it87_write_value(data
, IT87_REG_FAN_MIN
[nr
],
796 data
->fan
[nr
][index
] & 0xff);
797 it87_write_value(data
, IT87_REG_FANX_MIN
[nr
],
798 data
->fan
[nr
][index
] >> 8);
800 reg
= it87_read_value(data
, IT87_REG_FAN_DIV
);
803 data
->fan_div
[nr
] = reg
& 0x07;
806 data
->fan_div
[nr
] = (reg
>> 3) & 0x07;
809 data
->fan_div
[nr
] = (reg
& 0x40) ? 3 : 1;
812 data
->fan
[nr
][index
] =
813 FAN_TO_REG(val
, DIV_FROM_REG(data
->fan_div
[nr
]));
814 it87_write_value(data
, IT87_REG_FAN_MIN
[nr
],
815 data
->fan
[nr
][index
]);
818 mutex_unlock(&data
->update_lock
);
822 static ssize_t
set_fan_div(struct device
*dev
, struct device_attribute
*attr
,
823 const char *buf
, size_t count
)
825 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
826 int nr
= sensor_attr
->index
;
828 struct it87_data
*data
= dev_get_drvdata(dev
);
833 if (kstrtoul(buf
, 10, &val
) < 0)
836 mutex_lock(&data
->update_lock
);
837 old
= it87_read_value(data
, IT87_REG_FAN_DIV
);
839 /* Save fan min limit */
840 min
= FAN_FROM_REG(data
->fan
[nr
][1], DIV_FROM_REG(data
->fan_div
[nr
]));
845 data
->fan_div
[nr
] = DIV_TO_REG(val
);
849 data
->fan_div
[nr
] = 1;
851 data
->fan_div
[nr
] = 3;
854 val
|= (data
->fan_div
[0] & 0x07);
855 val
|= (data
->fan_div
[1] & 0x07) << 3;
856 if (data
->fan_div
[2] == 3)
858 it87_write_value(data
, IT87_REG_FAN_DIV
, val
);
860 /* Restore fan min limit */
861 data
->fan
[nr
][1] = FAN_TO_REG(min
, DIV_FROM_REG(data
->fan_div
[nr
]));
862 it87_write_value(data
, IT87_REG_FAN_MIN
[nr
], data
->fan
[nr
][1]);
864 mutex_unlock(&data
->update_lock
);
868 /* Returns 0 if OK, -EINVAL otherwise */
869 static int check_trip_points(struct device
*dev
, int nr
)
871 const struct it87_data
*data
= dev_get_drvdata(dev
);
874 if (has_old_autopwm(data
)) {
875 for (i
= 0; i
< 3; i
++) {
876 if (data
->auto_temp
[nr
][i
] > data
->auto_temp
[nr
][i
+ 1])
879 for (i
= 0; i
< 2; i
++) {
880 if (data
->auto_pwm
[nr
][i
] > data
->auto_pwm
[nr
][i
+ 1])
887 "Inconsistent trip points, not switching to automatic mode\n");
888 dev_err(dev
, "Adjust the trip points and try again\n");
893 static ssize_t
set_pwm_enable(struct device
*dev
,
894 struct device_attribute
*attr
, const char *buf
, size_t count
)
896 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
897 int nr
= sensor_attr
->index
;
899 struct it87_data
*data
= dev_get_drvdata(dev
);
902 if (kstrtol(buf
, 10, &val
) < 0 || val
< 0 || val
> 2)
905 /* Check trip points before switching to automatic mode */
907 if (check_trip_points(dev
, nr
) < 0)
911 mutex_lock(&data
->update_lock
);
915 /* make sure the fan is on when in on/off mode */
916 tmp
= it87_read_value(data
, IT87_REG_FAN_CTL
);
917 it87_write_value(data
, IT87_REG_FAN_CTL
, tmp
| (1 << nr
));
918 /* set on/off mode */
919 data
->fan_main_ctrl
&= ~(1 << nr
);
920 it87_write_value(data
, IT87_REG_FAN_MAIN_CTRL
,
921 data
->fan_main_ctrl
);
923 if (val
== 1) /* Manual mode */
924 data
->pwm_ctrl
[nr
] = has_newer_autopwm(data
) ?
925 data
->pwm_temp_map
[nr
] :
927 else /* Automatic mode */
928 data
->pwm_ctrl
[nr
] = 0x80 | data
->pwm_temp_map
[nr
];
929 it87_write_value(data
, IT87_REG_PWM(nr
), data
->pwm_ctrl
[nr
]);
930 /* set SmartGuardian mode */
931 data
->fan_main_ctrl
|= (1 << nr
);
932 it87_write_value(data
, IT87_REG_FAN_MAIN_CTRL
,
933 data
->fan_main_ctrl
);
936 mutex_unlock(&data
->update_lock
);
939 static ssize_t
set_pwm(struct device
*dev
, struct device_attribute
*attr
,
940 const char *buf
, size_t count
)
942 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
943 int nr
= sensor_attr
->index
;
945 struct it87_data
*data
= dev_get_drvdata(dev
);
948 if (kstrtol(buf
, 10, &val
) < 0 || val
< 0 || val
> 255)
951 mutex_lock(&data
->update_lock
);
952 if (has_newer_autopwm(data
)) {
954 * If we are in automatic mode, the PWM duty cycle register
955 * is read-only so we can't write the value.
957 if (data
->pwm_ctrl
[nr
] & 0x80) {
958 mutex_unlock(&data
->update_lock
);
961 data
->pwm_duty
[nr
] = pwm_to_reg(data
, val
);
962 it87_write_value(data
, IT87_REG_PWM_DUTY(nr
),
965 data
->pwm_duty
[nr
] = pwm_to_reg(data
, val
);
967 * If we are in manual mode, write the duty cycle immediately;
968 * otherwise, just store it for later use.
970 if (!(data
->pwm_ctrl
[nr
] & 0x80)) {
971 data
->pwm_ctrl
[nr
] = data
->pwm_duty
[nr
];
972 it87_write_value(data
, IT87_REG_PWM(nr
),
976 mutex_unlock(&data
->update_lock
);
979 static ssize_t
set_pwm_freq(struct device
*dev
,
980 struct device_attribute
*attr
, const char *buf
, size_t count
)
982 struct it87_data
*data
= dev_get_drvdata(dev
);
986 if (kstrtoul(buf
, 10, &val
) < 0)
989 /* Search for the nearest available frequency */
990 for (i
= 0; i
< 7; i
++) {
991 if (val
> (pwm_freq
[i
] + pwm_freq
[i
+1]) / 2)
995 mutex_lock(&data
->update_lock
);
996 data
->fan_ctl
= it87_read_value(data
, IT87_REG_FAN_CTL
) & 0x8f;
997 data
->fan_ctl
|= i
<< 4;
998 it87_write_value(data
, IT87_REG_FAN_CTL
, data
->fan_ctl
);
999 mutex_unlock(&data
->update_lock
);
1003 static ssize_t
show_pwm_temp_map(struct device
*dev
,
1004 struct device_attribute
*attr
, char *buf
)
1006 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
1007 int nr
= sensor_attr
->index
;
1009 struct it87_data
*data
= it87_update_device(dev
);
1012 if (data
->pwm_temp_map
[nr
] < 3)
1013 map
= 1 << data
->pwm_temp_map
[nr
];
1015 map
= 0; /* Should never happen */
1016 return sprintf(buf
, "%d\n", map
);
1018 static ssize_t
set_pwm_temp_map(struct device
*dev
,
1019 struct device_attribute
*attr
, const char *buf
, size_t count
)
1021 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
1022 int nr
= sensor_attr
->index
;
1024 struct it87_data
*data
= dev_get_drvdata(dev
);
1029 * This check can go away if we ever support automatic fan speed
1030 * control on newer chips.
1032 if (!has_old_autopwm(data
)) {
1033 dev_notice(dev
, "Mapping change disabled for safety reasons\n");
1037 if (kstrtol(buf
, 10, &val
) < 0)
1054 mutex_lock(&data
->update_lock
);
1055 data
->pwm_temp_map
[nr
] = reg
;
1057 * If we are in automatic mode, write the temp mapping immediately;
1058 * otherwise, just store it for later use.
1060 if (data
->pwm_ctrl
[nr
] & 0x80) {
1061 data
->pwm_ctrl
[nr
] = 0x80 | data
->pwm_temp_map
[nr
];
1062 it87_write_value(data
, IT87_REG_PWM(nr
), data
->pwm_ctrl
[nr
]);
1064 mutex_unlock(&data
->update_lock
);
1068 static ssize_t
show_auto_pwm(struct device
*dev
,
1069 struct device_attribute
*attr
, char *buf
)
1071 struct it87_data
*data
= it87_update_device(dev
);
1072 struct sensor_device_attribute_2
*sensor_attr
=
1073 to_sensor_dev_attr_2(attr
);
1074 int nr
= sensor_attr
->nr
;
1075 int point
= sensor_attr
->index
;
1077 return sprintf(buf
, "%d\n",
1078 pwm_from_reg(data
, data
->auto_pwm
[nr
][point
]));
1081 static ssize_t
set_auto_pwm(struct device
*dev
,
1082 struct device_attribute
*attr
, const char *buf
, size_t count
)
1084 struct it87_data
*data
= dev_get_drvdata(dev
);
1085 struct sensor_device_attribute_2
*sensor_attr
=
1086 to_sensor_dev_attr_2(attr
);
1087 int nr
= sensor_attr
->nr
;
1088 int point
= sensor_attr
->index
;
1091 if (kstrtol(buf
, 10, &val
) < 0 || val
< 0 || val
> 255)
1094 mutex_lock(&data
->update_lock
);
1095 data
->auto_pwm
[nr
][point
] = pwm_to_reg(data
, val
);
1096 it87_write_value(data
, IT87_REG_AUTO_PWM(nr
, point
),
1097 data
->auto_pwm
[nr
][point
]);
1098 mutex_unlock(&data
->update_lock
);
1102 static ssize_t
show_auto_temp(struct device
*dev
,
1103 struct device_attribute
*attr
, char *buf
)
1105 struct it87_data
*data
= it87_update_device(dev
);
1106 struct sensor_device_attribute_2
*sensor_attr
=
1107 to_sensor_dev_attr_2(attr
);
1108 int nr
= sensor_attr
->nr
;
1109 int point
= sensor_attr
->index
;
1111 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->auto_temp
[nr
][point
]));
1114 static ssize_t
set_auto_temp(struct device
*dev
,
1115 struct device_attribute
*attr
, const char *buf
, size_t count
)
1117 struct it87_data
*data
= dev_get_drvdata(dev
);
1118 struct sensor_device_attribute_2
*sensor_attr
=
1119 to_sensor_dev_attr_2(attr
);
1120 int nr
= sensor_attr
->nr
;
1121 int point
= sensor_attr
->index
;
1124 if (kstrtol(buf
, 10, &val
) < 0 || val
< -128000 || val
> 127000)
1127 mutex_lock(&data
->update_lock
);
1128 data
->auto_temp
[nr
][point
] = TEMP_TO_REG(val
);
1129 it87_write_value(data
, IT87_REG_AUTO_TEMP(nr
, point
),
1130 data
->auto_temp
[nr
][point
]);
1131 mutex_unlock(&data
->update_lock
);
1135 static SENSOR_DEVICE_ATTR_2(fan1_input
, S_IRUGO
, show_fan
, NULL
, 0, 0);
1136 static SENSOR_DEVICE_ATTR_2(fan1_min
, S_IRUGO
| S_IWUSR
, show_fan
, set_fan
,
1138 static SENSOR_DEVICE_ATTR(fan1_div
, S_IRUGO
| S_IWUSR
, show_fan_div
,
1141 static SENSOR_DEVICE_ATTR_2(fan2_input
, S_IRUGO
, show_fan
, NULL
, 1, 0);
1142 static SENSOR_DEVICE_ATTR_2(fan2_min
, S_IRUGO
| S_IWUSR
, show_fan
, set_fan
,
1144 static SENSOR_DEVICE_ATTR(fan2_div
, S_IRUGO
| S_IWUSR
, show_fan_div
,
1147 static SENSOR_DEVICE_ATTR_2(fan3_input
, S_IRUGO
, show_fan
, NULL
, 2, 0);
1148 static SENSOR_DEVICE_ATTR_2(fan3_min
, S_IRUGO
| S_IWUSR
, show_fan
, set_fan
,
1150 static SENSOR_DEVICE_ATTR(fan3_div
, S_IRUGO
| S_IWUSR
, show_fan_div
,
1153 static SENSOR_DEVICE_ATTR_2(fan4_input
, S_IRUGO
, show_fan
, NULL
, 3, 0);
1154 static SENSOR_DEVICE_ATTR_2(fan4_min
, S_IRUGO
| S_IWUSR
, show_fan
, set_fan
,
1157 static SENSOR_DEVICE_ATTR_2(fan5_input
, S_IRUGO
, show_fan
, NULL
, 4, 0);
1158 static SENSOR_DEVICE_ATTR_2(fan5_min
, S_IRUGO
| S_IWUSR
, show_fan
, set_fan
,
1161 static SENSOR_DEVICE_ATTR(pwm1_enable
, S_IRUGO
| S_IWUSR
,
1162 show_pwm_enable
, set_pwm_enable
, 0);
1163 static SENSOR_DEVICE_ATTR(pwm1
, S_IRUGO
| S_IWUSR
, show_pwm
, set_pwm
, 0);
1164 static DEVICE_ATTR(pwm1_freq
, S_IRUGO
| S_IWUSR
, show_pwm_freq
, set_pwm_freq
);
1165 static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp
, S_IRUGO
| S_IWUSR
,
1166 show_pwm_temp_map
, set_pwm_temp_map
, 0);
1167 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_pwm
, S_IRUGO
| S_IWUSR
,
1168 show_auto_pwm
, set_auto_pwm
, 0, 0);
1169 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_pwm
, S_IRUGO
| S_IWUSR
,
1170 show_auto_pwm
, set_auto_pwm
, 0, 1);
1171 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_pwm
, S_IRUGO
| S_IWUSR
,
1172 show_auto_pwm
, set_auto_pwm
, 0, 2);
1173 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_pwm
, S_IRUGO
,
1174 show_auto_pwm
, NULL
, 0, 3);
1175 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp
, S_IRUGO
| S_IWUSR
,
1176 show_auto_temp
, set_auto_temp
, 0, 1);
1177 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp_hyst
, S_IRUGO
| S_IWUSR
,
1178 show_auto_temp
, set_auto_temp
, 0, 0);
1179 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp
, S_IRUGO
| S_IWUSR
,
1180 show_auto_temp
, set_auto_temp
, 0, 2);
1181 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp
, S_IRUGO
| S_IWUSR
,
1182 show_auto_temp
, set_auto_temp
, 0, 3);
1183 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp
, S_IRUGO
| S_IWUSR
,
1184 show_auto_temp
, set_auto_temp
, 0, 4);
1186 static SENSOR_DEVICE_ATTR(pwm2_enable
, S_IRUGO
| S_IWUSR
,
1187 show_pwm_enable
, set_pwm_enable
, 1);
1188 static SENSOR_DEVICE_ATTR(pwm2
, S_IRUGO
| S_IWUSR
, show_pwm
, set_pwm
, 1);
1189 static DEVICE_ATTR(pwm2_freq
, S_IRUGO
, show_pwm_freq
, NULL
);
1190 static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp
, S_IRUGO
| S_IWUSR
,
1191 show_pwm_temp_map
, set_pwm_temp_map
, 1);
1192 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_pwm
, S_IRUGO
| S_IWUSR
,
1193 show_auto_pwm
, set_auto_pwm
, 1, 0);
1194 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_pwm
, S_IRUGO
| S_IWUSR
,
1195 show_auto_pwm
, set_auto_pwm
, 1, 1);
1196 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_pwm
, S_IRUGO
| S_IWUSR
,
1197 show_auto_pwm
, set_auto_pwm
, 1, 2);
1198 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_pwm
, S_IRUGO
,
1199 show_auto_pwm
, NULL
, 1, 3);
1200 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp
, S_IRUGO
| S_IWUSR
,
1201 show_auto_temp
, set_auto_temp
, 1, 1);
1202 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp_hyst
, S_IRUGO
| S_IWUSR
,
1203 show_auto_temp
, set_auto_temp
, 1, 0);
1204 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp
, S_IRUGO
| S_IWUSR
,
1205 show_auto_temp
, set_auto_temp
, 1, 2);
1206 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp
, S_IRUGO
| S_IWUSR
,
1207 show_auto_temp
, set_auto_temp
, 1, 3);
1208 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_temp
, S_IRUGO
| S_IWUSR
,
1209 show_auto_temp
, set_auto_temp
, 1, 4);
1211 static SENSOR_DEVICE_ATTR(pwm3_enable
, S_IRUGO
| S_IWUSR
,
1212 show_pwm_enable
, set_pwm_enable
, 2);
1213 static SENSOR_DEVICE_ATTR(pwm3
, S_IRUGO
| S_IWUSR
, show_pwm
, set_pwm
, 2);
1214 static DEVICE_ATTR(pwm3_freq
, S_IRUGO
, show_pwm_freq
, NULL
);
1215 static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp
, S_IRUGO
| S_IWUSR
,
1216 show_pwm_temp_map
, set_pwm_temp_map
, 2);
1217 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_pwm
, S_IRUGO
| S_IWUSR
,
1218 show_auto_pwm
, set_auto_pwm
, 2, 0);
1219 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm
, S_IRUGO
| S_IWUSR
,
1220 show_auto_pwm
, set_auto_pwm
, 2, 1);
1221 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_pwm
, S_IRUGO
| S_IWUSR
,
1222 show_auto_pwm
, set_auto_pwm
, 2, 2);
1223 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_pwm
, S_IRUGO
,
1224 show_auto_pwm
, NULL
, 2, 3);
1225 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp
, S_IRUGO
| S_IWUSR
,
1226 show_auto_temp
, set_auto_temp
, 2, 1);
1227 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp_hyst
, S_IRUGO
| S_IWUSR
,
1228 show_auto_temp
, set_auto_temp
, 2, 0);
1229 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_temp
, S_IRUGO
| S_IWUSR
,
1230 show_auto_temp
, set_auto_temp
, 2, 2);
1231 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_temp
, S_IRUGO
| S_IWUSR
,
1232 show_auto_temp
, set_auto_temp
, 2, 3);
1233 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_temp
, S_IRUGO
| S_IWUSR
,
1234 show_auto_temp
, set_auto_temp
, 2, 4);
1237 static ssize_t
show_alarms(struct device
*dev
, struct device_attribute
*attr
,
1240 struct it87_data
*data
= it87_update_device(dev
);
1241 return sprintf(buf
, "%u\n", data
->alarms
);
1243 static DEVICE_ATTR(alarms
, S_IRUGO
, show_alarms
, NULL
);
1245 static ssize_t
show_alarm(struct device
*dev
, struct device_attribute
*attr
,
1248 int bitnr
= to_sensor_dev_attr(attr
)->index
;
1249 struct it87_data
*data
= it87_update_device(dev
);
1250 return sprintf(buf
, "%u\n", (data
->alarms
>> bitnr
) & 1);
1253 static ssize_t
clear_intrusion(struct device
*dev
, struct device_attribute
1254 *attr
, const char *buf
, size_t count
)
1256 struct it87_data
*data
= dev_get_drvdata(dev
);
1260 if (kstrtol(buf
, 10, &val
) < 0 || val
!= 0)
1263 mutex_lock(&data
->update_lock
);
1264 config
= it87_read_value(data
, IT87_REG_CONFIG
);
1269 it87_write_value(data
, IT87_REG_CONFIG
, config
);
1270 /* Invalidate cache to force re-read */
1273 mutex_unlock(&data
->update_lock
);
1278 static SENSOR_DEVICE_ATTR(in0_alarm
, S_IRUGO
, show_alarm
, NULL
, 8);
1279 static SENSOR_DEVICE_ATTR(in1_alarm
, S_IRUGO
, show_alarm
, NULL
, 9);
1280 static SENSOR_DEVICE_ATTR(in2_alarm
, S_IRUGO
, show_alarm
, NULL
, 10);
1281 static SENSOR_DEVICE_ATTR(in3_alarm
, S_IRUGO
, show_alarm
, NULL
, 11);
1282 static SENSOR_DEVICE_ATTR(in4_alarm
, S_IRUGO
, show_alarm
, NULL
, 12);
1283 static SENSOR_DEVICE_ATTR(in5_alarm
, S_IRUGO
, show_alarm
, NULL
, 13);
1284 static SENSOR_DEVICE_ATTR(in6_alarm
, S_IRUGO
, show_alarm
, NULL
, 14);
1285 static SENSOR_DEVICE_ATTR(in7_alarm
, S_IRUGO
, show_alarm
, NULL
, 15);
1286 static SENSOR_DEVICE_ATTR(fan1_alarm
, S_IRUGO
, show_alarm
, NULL
, 0);
1287 static SENSOR_DEVICE_ATTR(fan2_alarm
, S_IRUGO
, show_alarm
, NULL
, 1);
1288 static SENSOR_DEVICE_ATTR(fan3_alarm
, S_IRUGO
, show_alarm
, NULL
, 2);
1289 static SENSOR_DEVICE_ATTR(fan4_alarm
, S_IRUGO
, show_alarm
, NULL
, 3);
1290 static SENSOR_DEVICE_ATTR(fan5_alarm
, S_IRUGO
, show_alarm
, NULL
, 6);
1291 static SENSOR_DEVICE_ATTR(temp1_alarm
, S_IRUGO
, show_alarm
, NULL
, 16);
1292 static SENSOR_DEVICE_ATTR(temp2_alarm
, S_IRUGO
, show_alarm
, NULL
, 17);
1293 static SENSOR_DEVICE_ATTR(temp3_alarm
, S_IRUGO
, show_alarm
, NULL
, 18);
1294 static SENSOR_DEVICE_ATTR(intrusion0_alarm
, S_IRUGO
| S_IWUSR
,
1295 show_alarm
, clear_intrusion
, 4);
1297 static ssize_t
show_beep(struct device
*dev
, struct device_attribute
*attr
,
1300 int bitnr
= to_sensor_dev_attr(attr
)->index
;
1301 struct it87_data
*data
= it87_update_device(dev
);
1302 return sprintf(buf
, "%u\n", (data
->beeps
>> bitnr
) & 1);
1304 static ssize_t
set_beep(struct device
*dev
, struct device_attribute
*attr
,
1305 const char *buf
, size_t count
)
1307 int bitnr
= to_sensor_dev_attr(attr
)->index
;
1308 struct it87_data
*data
= dev_get_drvdata(dev
);
1311 if (kstrtol(buf
, 10, &val
) < 0
1312 || (val
!= 0 && val
!= 1))
1315 mutex_lock(&data
->update_lock
);
1316 data
->beeps
= it87_read_value(data
, IT87_REG_BEEP_ENABLE
);
1318 data
->beeps
|= (1 << bitnr
);
1320 data
->beeps
&= ~(1 << bitnr
);
1321 it87_write_value(data
, IT87_REG_BEEP_ENABLE
, data
->beeps
);
1322 mutex_unlock(&data
->update_lock
);
1326 static SENSOR_DEVICE_ATTR(in0_beep
, S_IRUGO
| S_IWUSR
,
1327 show_beep
, set_beep
, 1);
1328 static SENSOR_DEVICE_ATTR(in1_beep
, S_IRUGO
, show_beep
, NULL
, 1);
1329 static SENSOR_DEVICE_ATTR(in2_beep
, S_IRUGO
, show_beep
, NULL
, 1);
1330 static SENSOR_DEVICE_ATTR(in3_beep
, S_IRUGO
, show_beep
, NULL
, 1);
1331 static SENSOR_DEVICE_ATTR(in4_beep
, S_IRUGO
, show_beep
, NULL
, 1);
1332 static SENSOR_DEVICE_ATTR(in5_beep
, S_IRUGO
, show_beep
, NULL
, 1);
1333 static SENSOR_DEVICE_ATTR(in6_beep
, S_IRUGO
, show_beep
, NULL
, 1);
1334 static SENSOR_DEVICE_ATTR(in7_beep
, S_IRUGO
, show_beep
, NULL
, 1);
1335 /* fanX_beep writability is set later */
1336 static SENSOR_DEVICE_ATTR(fan1_beep
, S_IRUGO
, show_beep
, set_beep
, 0);
1337 static SENSOR_DEVICE_ATTR(fan2_beep
, S_IRUGO
, show_beep
, set_beep
, 0);
1338 static SENSOR_DEVICE_ATTR(fan3_beep
, S_IRUGO
, show_beep
, set_beep
, 0);
1339 static SENSOR_DEVICE_ATTR(fan4_beep
, S_IRUGO
, show_beep
, set_beep
, 0);
1340 static SENSOR_DEVICE_ATTR(fan5_beep
, S_IRUGO
, show_beep
, set_beep
, 0);
1341 static SENSOR_DEVICE_ATTR(temp1_beep
, S_IRUGO
| S_IWUSR
,
1342 show_beep
, set_beep
, 2);
1343 static SENSOR_DEVICE_ATTR(temp2_beep
, S_IRUGO
, show_beep
, NULL
, 2);
1344 static SENSOR_DEVICE_ATTR(temp3_beep
, S_IRUGO
, show_beep
, NULL
, 2);
1346 static ssize_t
show_vrm_reg(struct device
*dev
, struct device_attribute
*attr
,
1349 struct it87_data
*data
= dev_get_drvdata(dev
);
1350 return sprintf(buf
, "%u\n", data
->vrm
);
1352 static ssize_t
store_vrm_reg(struct device
*dev
, struct device_attribute
*attr
,
1353 const char *buf
, size_t count
)
1355 struct it87_data
*data
= dev_get_drvdata(dev
);
1358 if (kstrtoul(buf
, 10, &val
) < 0)
1365 static DEVICE_ATTR(vrm
, S_IRUGO
| S_IWUSR
, show_vrm_reg
, store_vrm_reg
);
1367 static ssize_t
show_vid_reg(struct device
*dev
, struct device_attribute
*attr
,
1370 struct it87_data
*data
= it87_update_device(dev
);
1371 return sprintf(buf
, "%ld\n", (long) vid_from_reg(data
->vid
, data
->vrm
));
1373 static DEVICE_ATTR(cpu0_vid
, S_IRUGO
, show_vid_reg
, NULL
);
1375 static ssize_t
show_label(struct device
*dev
, struct device_attribute
*attr
,
1378 static const char * const labels
[] = {
1383 static const char * const labels_it8721
[] = {
1388 struct it87_data
*data
= dev_get_drvdata(dev
);
1389 int nr
= to_sensor_dev_attr(attr
)->index
;
1391 return sprintf(buf
, "%s\n", has_12mv_adc(data
) ? labels_it8721
[nr
]
1394 static SENSOR_DEVICE_ATTR(in3_label
, S_IRUGO
, show_label
, NULL
, 0);
1395 static SENSOR_DEVICE_ATTR(in7_label
, S_IRUGO
, show_label
, NULL
, 1);
1396 static SENSOR_DEVICE_ATTR(in8_label
, S_IRUGO
, show_label
, NULL
, 2);
1398 static ssize_t
show_name(struct device
*dev
, struct device_attribute
1399 *devattr
, char *buf
)
1401 struct it87_data
*data
= dev_get_drvdata(dev
);
1402 return sprintf(buf
, "%s\n", data
->name
);
1404 static DEVICE_ATTR(name
, S_IRUGO
, show_name
, NULL
);
1406 static struct attribute
*it87_attributes_in
[9][5] = {
1408 &sensor_dev_attr_in0_input
.dev_attr
.attr
,
1409 &sensor_dev_attr_in0_min
.dev_attr
.attr
,
1410 &sensor_dev_attr_in0_max
.dev_attr
.attr
,
1411 &sensor_dev_attr_in0_alarm
.dev_attr
.attr
,
1414 &sensor_dev_attr_in1_input
.dev_attr
.attr
,
1415 &sensor_dev_attr_in1_min
.dev_attr
.attr
,
1416 &sensor_dev_attr_in1_max
.dev_attr
.attr
,
1417 &sensor_dev_attr_in1_alarm
.dev_attr
.attr
,
1420 &sensor_dev_attr_in2_input
.dev_attr
.attr
,
1421 &sensor_dev_attr_in2_min
.dev_attr
.attr
,
1422 &sensor_dev_attr_in2_max
.dev_attr
.attr
,
1423 &sensor_dev_attr_in2_alarm
.dev_attr
.attr
,
1426 &sensor_dev_attr_in3_input
.dev_attr
.attr
,
1427 &sensor_dev_attr_in3_min
.dev_attr
.attr
,
1428 &sensor_dev_attr_in3_max
.dev_attr
.attr
,
1429 &sensor_dev_attr_in3_alarm
.dev_attr
.attr
,
1432 &sensor_dev_attr_in4_input
.dev_attr
.attr
,
1433 &sensor_dev_attr_in4_min
.dev_attr
.attr
,
1434 &sensor_dev_attr_in4_max
.dev_attr
.attr
,
1435 &sensor_dev_attr_in4_alarm
.dev_attr
.attr
,
1438 &sensor_dev_attr_in5_input
.dev_attr
.attr
,
1439 &sensor_dev_attr_in5_min
.dev_attr
.attr
,
1440 &sensor_dev_attr_in5_max
.dev_attr
.attr
,
1441 &sensor_dev_attr_in5_alarm
.dev_attr
.attr
,
1444 &sensor_dev_attr_in6_input
.dev_attr
.attr
,
1445 &sensor_dev_attr_in6_min
.dev_attr
.attr
,
1446 &sensor_dev_attr_in6_max
.dev_attr
.attr
,
1447 &sensor_dev_attr_in6_alarm
.dev_attr
.attr
,
1450 &sensor_dev_attr_in7_input
.dev_attr
.attr
,
1451 &sensor_dev_attr_in7_min
.dev_attr
.attr
,
1452 &sensor_dev_attr_in7_max
.dev_attr
.attr
,
1453 &sensor_dev_attr_in7_alarm
.dev_attr
.attr
,
1456 &sensor_dev_attr_in8_input
.dev_attr
.attr
,
1460 static const struct attribute_group it87_group_in
[9] = {
1461 { .attrs
= it87_attributes_in
[0] },
1462 { .attrs
= it87_attributes_in
[1] },
1463 { .attrs
= it87_attributes_in
[2] },
1464 { .attrs
= it87_attributes_in
[3] },
1465 { .attrs
= it87_attributes_in
[4] },
1466 { .attrs
= it87_attributes_in
[5] },
1467 { .attrs
= it87_attributes_in
[6] },
1468 { .attrs
= it87_attributes_in
[7] },
1469 { .attrs
= it87_attributes_in
[8] },
1472 static struct attribute
*it87_attributes_temp
[3][6] = {
1474 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
1475 &sensor_dev_attr_temp1_max
.dev_attr
.attr
,
1476 &sensor_dev_attr_temp1_min
.dev_attr
.attr
,
1477 &sensor_dev_attr_temp1_type
.dev_attr
.attr
,
1478 &sensor_dev_attr_temp1_alarm
.dev_attr
.attr
,
1481 &sensor_dev_attr_temp2_input
.dev_attr
.attr
,
1482 &sensor_dev_attr_temp2_max
.dev_attr
.attr
,
1483 &sensor_dev_attr_temp2_min
.dev_attr
.attr
,
1484 &sensor_dev_attr_temp2_type
.dev_attr
.attr
,
1485 &sensor_dev_attr_temp2_alarm
.dev_attr
.attr
,
1488 &sensor_dev_attr_temp3_input
.dev_attr
.attr
,
1489 &sensor_dev_attr_temp3_max
.dev_attr
.attr
,
1490 &sensor_dev_attr_temp3_min
.dev_attr
.attr
,
1491 &sensor_dev_attr_temp3_type
.dev_attr
.attr
,
1492 &sensor_dev_attr_temp3_alarm
.dev_attr
.attr
,
1496 static const struct attribute_group it87_group_temp
[3] = {
1497 { .attrs
= it87_attributes_temp
[0] },
1498 { .attrs
= it87_attributes_temp
[1] },
1499 { .attrs
= it87_attributes_temp
[2] },
1502 static struct attribute
*it87_attributes_temp_offset
[] = {
1503 &sensor_dev_attr_temp1_offset
.dev_attr
.attr
,
1504 &sensor_dev_attr_temp2_offset
.dev_attr
.attr
,
1505 &sensor_dev_attr_temp3_offset
.dev_attr
.attr
,
1508 static struct attribute
*it87_attributes
[] = {
1509 &dev_attr_alarms
.attr
,
1510 &sensor_dev_attr_intrusion0_alarm
.dev_attr
.attr
,
1511 &dev_attr_name
.attr
,
1515 static const struct attribute_group it87_group
= {
1516 .attrs
= it87_attributes
,
1519 static struct attribute
*it87_attributes_in_beep
[] = {
1520 &sensor_dev_attr_in0_beep
.dev_attr
.attr
,
1521 &sensor_dev_attr_in1_beep
.dev_attr
.attr
,
1522 &sensor_dev_attr_in2_beep
.dev_attr
.attr
,
1523 &sensor_dev_attr_in3_beep
.dev_attr
.attr
,
1524 &sensor_dev_attr_in4_beep
.dev_attr
.attr
,
1525 &sensor_dev_attr_in5_beep
.dev_attr
.attr
,
1526 &sensor_dev_attr_in6_beep
.dev_attr
.attr
,
1527 &sensor_dev_attr_in7_beep
.dev_attr
.attr
,
1531 static struct attribute
*it87_attributes_temp_beep
[] = {
1532 &sensor_dev_attr_temp1_beep
.dev_attr
.attr
,
1533 &sensor_dev_attr_temp2_beep
.dev_attr
.attr
,
1534 &sensor_dev_attr_temp3_beep
.dev_attr
.attr
,
1537 static struct attribute
*it87_attributes_fan
[5][3+1] = { {
1538 &sensor_dev_attr_fan1_input
.dev_attr
.attr
,
1539 &sensor_dev_attr_fan1_min
.dev_attr
.attr
,
1540 &sensor_dev_attr_fan1_alarm
.dev_attr
.attr
,
1543 &sensor_dev_attr_fan2_input
.dev_attr
.attr
,
1544 &sensor_dev_attr_fan2_min
.dev_attr
.attr
,
1545 &sensor_dev_attr_fan2_alarm
.dev_attr
.attr
,
1548 &sensor_dev_attr_fan3_input
.dev_attr
.attr
,
1549 &sensor_dev_attr_fan3_min
.dev_attr
.attr
,
1550 &sensor_dev_attr_fan3_alarm
.dev_attr
.attr
,
1553 &sensor_dev_attr_fan4_input
.dev_attr
.attr
,
1554 &sensor_dev_attr_fan4_min
.dev_attr
.attr
,
1555 &sensor_dev_attr_fan4_alarm
.dev_attr
.attr
,
1558 &sensor_dev_attr_fan5_input
.dev_attr
.attr
,
1559 &sensor_dev_attr_fan5_min
.dev_attr
.attr
,
1560 &sensor_dev_attr_fan5_alarm
.dev_attr
.attr
,
1564 static const struct attribute_group it87_group_fan
[5] = {
1565 { .attrs
= it87_attributes_fan
[0] },
1566 { .attrs
= it87_attributes_fan
[1] },
1567 { .attrs
= it87_attributes_fan
[2] },
1568 { .attrs
= it87_attributes_fan
[3] },
1569 { .attrs
= it87_attributes_fan
[4] },
1572 static const struct attribute
*it87_attributes_fan_div
[] = {
1573 &sensor_dev_attr_fan1_div
.dev_attr
.attr
,
1574 &sensor_dev_attr_fan2_div
.dev_attr
.attr
,
1575 &sensor_dev_attr_fan3_div
.dev_attr
.attr
,
1578 static struct attribute
*it87_attributes_pwm
[3][4+1] = { {
1579 &sensor_dev_attr_pwm1_enable
.dev_attr
.attr
,
1580 &sensor_dev_attr_pwm1
.dev_attr
.attr
,
1581 &dev_attr_pwm1_freq
.attr
,
1582 &sensor_dev_attr_pwm1_auto_channels_temp
.dev_attr
.attr
,
1585 &sensor_dev_attr_pwm2_enable
.dev_attr
.attr
,
1586 &sensor_dev_attr_pwm2
.dev_attr
.attr
,
1587 &dev_attr_pwm2_freq
.attr
,
1588 &sensor_dev_attr_pwm2_auto_channels_temp
.dev_attr
.attr
,
1591 &sensor_dev_attr_pwm3_enable
.dev_attr
.attr
,
1592 &sensor_dev_attr_pwm3
.dev_attr
.attr
,
1593 &dev_attr_pwm3_freq
.attr
,
1594 &sensor_dev_attr_pwm3_auto_channels_temp
.dev_attr
.attr
,
1598 static const struct attribute_group it87_group_pwm
[3] = {
1599 { .attrs
= it87_attributes_pwm
[0] },
1600 { .attrs
= it87_attributes_pwm
[1] },
1601 { .attrs
= it87_attributes_pwm
[2] },
1604 static struct attribute
*it87_attributes_autopwm
[3][9+1] = { {
1605 &sensor_dev_attr_pwm1_auto_point1_pwm
.dev_attr
.attr
,
1606 &sensor_dev_attr_pwm1_auto_point2_pwm
.dev_attr
.attr
,
1607 &sensor_dev_attr_pwm1_auto_point3_pwm
.dev_attr
.attr
,
1608 &sensor_dev_attr_pwm1_auto_point4_pwm
.dev_attr
.attr
,
1609 &sensor_dev_attr_pwm1_auto_point1_temp
.dev_attr
.attr
,
1610 &sensor_dev_attr_pwm1_auto_point1_temp_hyst
.dev_attr
.attr
,
1611 &sensor_dev_attr_pwm1_auto_point2_temp
.dev_attr
.attr
,
1612 &sensor_dev_attr_pwm1_auto_point3_temp
.dev_attr
.attr
,
1613 &sensor_dev_attr_pwm1_auto_point4_temp
.dev_attr
.attr
,
1616 &sensor_dev_attr_pwm2_auto_point1_pwm
.dev_attr
.attr
,
1617 &sensor_dev_attr_pwm2_auto_point2_pwm
.dev_attr
.attr
,
1618 &sensor_dev_attr_pwm2_auto_point3_pwm
.dev_attr
.attr
,
1619 &sensor_dev_attr_pwm2_auto_point4_pwm
.dev_attr
.attr
,
1620 &sensor_dev_attr_pwm2_auto_point1_temp
.dev_attr
.attr
,
1621 &sensor_dev_attr_pwm2_auto_point1_temp_hyst
.dev_attr
.attr
,
1622 &sensor_dev_attr_pwm2_auto_point2_temp
.dev_attr
.attr
,
1623 &sensor_dev_attr_pwm2_auto_point3_temp
.dev_attr
.attr
,
1624 &sensor_dev_attr_pwm2_auto_point4_temp
.dev_attr
.attr
,
1627 &sensor_dev_attr_pwm3_auto_point1_pwm
.dev_attr
.attr
,
1628 &sensor_dev_attr_pwm3_auto_point2_pwm
.dev_attr
.attr
,
1629 &sensor_dev_attr_pwm3_auto_point3_pwm
.dev_attr
.attr
,
1630 &sensor_dev_attr_pwm3_auto_point4_pwm
.dev_attr
.attr
,
1631 &sensor_dev_attr_pwm3_auto_point1_temp
.dev_attr
.attr
,
1632 &sensor_dev_attr_pwm3_auto_point1_temp_hyst
.dev_attr
.attr
,
1633 &sensor_dev_attr_pwm3_auto_point2_temp
.dev_attr
.attr
,
1634 &sensor_dev_attr_pwm3_auto_point3_temp
.dev_attr
.attr
,
1635 &sensor_dev_attr_pwm3_auto_point4_temp
.dev_attr
.attr
,
1639 static const struct attribute_group it87_group_autopwm
[3] = {
1640 { .attrs
= it87_attributes_autopwm
[0] },
1641 { .attrs
= it87_attributes_autopwm
[1] },
1642 { .attrs
= it87_attributes_autopwm
[2] },
1645 static struct attribute
*it87_attributes_fan_beep
[] = {
1646 &sensor_dev_attr_fan1_beep
.dev_attr
.attr
,
1647 &sensor_dev_attr_fan2_beep
.dev_attr
.attr
,
1648 &sensor_dev_attr_fan3_beep
.dev_attr
.attr
,
1649 &sensor_dev_attr_fan4_beep
.dev_attr
.attr
,
1650 &sensor_dev_attr_fan5_beep
.dev_attr
.attr
,
1653 static struct attribute
*it87_attributes_vid
[] = {
1655 &dev_attr_cpu0_vid
.attr
,
1659 static const struct attribute_group it87_group_vid
= {
1660 .attrs
= it87_attributes_vid
,
1663 static struct attribute
*it87_attributes_label
[] = {
1664 &sensor_dev_attr_in3_label
.dev_attr
.attr
,
1665 &sensor_dev_attr_in7_label
.dev_attr
.attr
,
1666 &sensor_dev_attr_in8_label
.dev_attr
.attr
,
1670 static const struct attribute_group it87_group_label
= {
1671 .attrs
= it87_attributes_label
,
1674 /* SuperIO detection - will change isa_address if a chip is found */
1675 static int __init
it87_find(unsigned short *address
,
1676 struct it87_sio_data
*sio_data
)
1680 const char *board_vendor
, *board_name
;
1682 err
= superio_enter();
1687 chip_type
= force_id
? force_id
: superio_inw(DEVID
);
1689 switch (chip_type
) {
1691 sio_data
->type
= it87
;
1694 sio_data
->type
= it8712
;
1698 sio_data
->type
= it8716
;
1701 sio_data
->type
= it8718
;
1704 sio_data
->type
= it8720
;
1707 sio_data
->type
= it8721
;
1710 sio_data
->type
= it8728
;
1713 sio_data
->type
= it8782
;
1716 sio_data
->type
= it8783
;
1718 case 0xffff: /* No device at all */
1721 pr_debug("Unsupported chip (DEVID=0x%x)\n", chip_type
);
1725 superio_select(PME
);
1726 if (!(superio_inb(IT87_ACT_REG
) & 0x01)) {
1727 pr_info("Device not activated, skipping\n");
1731 *address
= superio_inw(IT87_BASE_REG
) & ~(IT87_EXTENT
- 1);
1732 if (*address
== 0) {
1733 pr_info("Base address not set, skipping\n");
1738 sio_data
->revision
= superio_inb(DEVREV
) & 0x0f;
1739 pr_info("Found IT%04xF chip at 0x%x, revision %d\n",
1740 chip_type
, *address
, sio_data
->revision
);
1742 /* in8 (Vbat) is always internal */
1743 sio_data
->internal
= (1 << 2);
1745 /* Read GPIO config and VID value from LDN 7 (GPIO) */
1746 if (sio_data
->type
== it87
) {
1747 /* The IT8705F doesn't have VID pins at all */
1748 sio_data
->skip_vid
= 1;
1750 /* The IT8705F has a different LD number for GPIO */
1752 sio_data
->beep_pin
= superio_inb(IT87_SIO_BEEP_PIN_REG
) & 0x3f;
1753 } else if (sio_data
->type
== it8783
) {
1754 int reg25
, reg27
, reg2A
, reg2C
, regEF
;
1756 sio_data
->skip_vid
= 1; /* No VID */
1758 superio_select(GPIO
);
1760 reg25
= superio_inb(IT87_SIO_GPIO1_REG
);
1761 reg27
= superio_inb(IT87_SIO_GPIO3_REG
);
1762 reg2A
= superio_inb(IT87_SIO_PINX1_REG
);
1763 reg2C
= superio_inb(IT87_SIO_PINX2_REG
);
1764 regEF
= superio_inb(IT87_SIO_SPI_REG
);
1766 /* Check if fan3 is there or not */
1767 if ((reg27
& (1 << 0)) || !(reg2C
& (1 << 2)))
1768 sio_data
->skip_fan
|= (1 << 2);
1769 if ((reg25
& (1 << 4))
1770 || (!(reg2A
& (1 << 1)) && (regEF
& (1 << 0))))
1771 sio_data
->skip_pwm
|= (1 << 2);
1773 /* Check if fan2 is there or not */
1774 if (reg27
& (1 << 7))
1775 sio_data
->skip_fan
|= (1 << 1);
1776 if (reg27
& (1 << 3))
1777 sio_data
->skip_pwm
|= (1 << 1);
1780 if ((reg27
& (1 << 0)) || (reg2C
& (1 << 2)))
1781 sio_data
->skip_in
|= (1 << 5); /* No VIN5 */
1784 if (reg27
& (1 << 1))
1785 sio_data
->skip_in
|= (1 << 6); /* No VIN6 */
1789 * Does not depend on bit 2 of Reg2C, contrary to datasheet.
1791 if (reg27
& (1 << 2)) {
1793 * The data sheet is a bit unclear regarding the
1794 * internal voltage divider for VCCH5V. It says
1795 * "This bit enables and switches VIN7 (pin 91) to the
1796 * internal voltage divider for VCCH5V".
1797 * This is different to other chips, where the internal
1798 * voltage divider would connect VIN7 to an internal
1799 * voltage source. Maybe that is the case here as well.
1801 * Since we don't know for sure, re-route it if that is
1802 * not the case, and ask the user to report if the
1803 * resulting voltage is sane.
1805 if (!(reg2C
& (1 << 1))) {
1807 superio_outb(IT87_SIO_PINX2_REG
, reg2C
);
1808 pr_notice("Routing internal VCCH5V to in7.\n");
1810 pr_notice("in7 routed to internal voltage divider, with external pin disabled.\n");
1811 pr_notice("Please report if it displays a reasonable voltage.\n");
1814 if (reg2C
& (1 << 0))
1815 sio_data
->internal
|= (1 << 0);
1816 if (reg2C
& (1 << 1))
1817 sio_data
->internal
|= (1 << 1);
1819 sio_data
->beep_pin
= superio_inb(IT87_SIO_BEEP_PIN_REG
) & 0x3f;
1825 superio_select(GPIO
);
1827 reg
= superio_inb(IT87_SIO_GPIO3_REG
);
1828 if (sio_data
->type
== it8721
|| sio_data
->type
== it8728
||
1829 sio_data
->type
== it8782
) {
1831 * IT8721F/IT8758E, and IT8782F don't have VID pins
1832 * at all, not sure about the IT8728F.
1834 sio_data
->skip_vid
= 1;
1836 /* We need at least 4 VID pins */
1838 pr_info("VID is disabled (pins used for GPIO)\n");
1839 sio_data
->skip_vid
= 1;
1843 /* Check if fan3 is there or not */
1845 sio_data
->skip_pwm
|= (1 << 2);
1847 sio_data
->skip_fan
|= (1 << 2);
1849 /* Check if fan2 is there or not */
1850 reg
= superio_inb(IT87_SIO_GPIO5_REG
);
1852 sio_data
->skip_pwm
|= (1 << 1);
1854 sio_data
->skip_fan
|= (1 << 1);
1856 if ((sio_data
->type
== it8718
|| sio_data
->type
== it8720
)
1857 && !(sio_data
->skip_vid
))
1858 sio_data
->vid_value
= superio_inb(IT87_SIO_VID_REG
);
1860 reg
= superio_inb(IT87_SIO_PINX2_REG
);
1862 uart6
= sio_data
->type
== it8782
&& (reg
& (1 << 2));
1865 * The IT8720F has no VIN7 pin, so VCCH should always be
1866 * routed internally to VIN7 with an internal divider.
1867 * Curiously, there still is a configuration bit to control
1868 * this, which means it can be set incorrectly. And even
1869 * more curiously, many boards out there are improperly
1870 * configured, even though the IT8720F datasheet claims
1871 * that the internal routing of VCCH to VIN7 is the default
1872 * setting. So we force the internal routing in this case.
1874 * On IT8782F, VIN7 is multiplexed with one of the UART6 pins.
1875 * If UART6 is enabled, re-route VIN7 to the internal divider
1876 * if that is not already the case.
1878 if ((sio_data
->type
== it8720
|| uart6
) && !(reg
& (1 << 1))) {
1880 superio_outb(IT87_SIO_PINX2_REG
, reg
);
1881 pr_notice("Routing internal VCCH to in7\n");
1884 sio_data
->internal
|= (1 << 0);
1885 if ((reg
& (1 << 1)) || sio_data
->type
== it8721
||
1886 sio_data
->type
== it8728
)
1887 sio_data
->internal
|= (1 << 1);
1890 * On IT8782F, UART6 pins overlap with VIN5, VIN6, and VIN7.
1891 * While VIN7 can be routed to the internal voltage divider,
1892 * VIN5 and VIN6 are not available if UART6 is enabled.
1894 * Also, temp3 is not available if UART6 is enabled and TEMPIN3
1895 * is the temperature source. Since we can not read the
1896 * temperature source here, skip_temp is preliminary.
1899 sio_data
->skip_in
|= (1 << 5) | (1 << 6);
1900 sio_data
->skip_temp
|= (1 << 2);
1903 sio_data
->beep_pin
= superio_inb(IT87_SIO_BEEP_PIN_REG
) & 0x3f;
1905 if (sio_data
->beep_pin
)
1906 pr_info("Beeping is supported\n");
1908 /* Disable specific features based on DMI strings */
1909 board_vendor
= dmi_get_system_info(DMI_BOARD_VENDOR
);
1910 board_name
= dmi_get_system_info(DMI_BOARD_NAME
);
1911 if (board_vendor
&& board_name
) {
1912 if (strcmp(board_vendor
, "nVIDIA") == 0
1913 && strcmp(board_name
, "FN68PT") == 0) {
1915 * On the Shuttle SN68PT, FAN_CTL2 is apparently not
1916 * connected to a fan, but to something else. One user
1917 * has reported instant system power-off when changing
1918 * the PWM2 duty cycle, so we disable it.
1919 * I use the board name string as the trigger in case
1920 * the same board is ever used in other systems.
1922 pr_info("Disabling pwm2 due to hardware constraints\n");
1923 sio_data
->skip_pwm
= (1 << 1);
1932 static void it87_remove_files(struct device
*dev
)
1934 struct it87_data
*data
= platform_get_drvdata(pdev
);
1935 struct it87_sio_data
*sio_data
= dev
->platform_data
;
1938 sysfs_remove_group(&dev
->kobj
, &it87_group
);
1939 for (i
= 0; i
< 9; i
++) {
1940 if (sio_data
->skip_in
& (1 << i
))
1942 sysfs_remove_group(&dev
->kobj
, &it87_group_in
[i
]);
1943 if (it87_attributes_in_beep
[i
])
1944 sysfs_remove_file(&dev
->kobj
,
1945 it87_attributes_in_beep
[i
]);
1947 for (i
= 0; i
< 3; i
++) {
1948 if (!(data
->has_temp
& (1 << i
)))
1950 sysfs_remove_group(&dev
->kobj
, &it87_group_temp
[i
]);
1951 if (has_temp_offset(data
))
1952 sysfs_remove_file(&dev
->kobj
,
1953 it87_attributes_temp_offset
[i
]);
1954 if (sio_data
->beep_pin
)
1955 sysfs_remove_file(&dev
->kobj
,
1956 it87_attributes_temp_beep
[i
]);
1958 for (i
= 0; i
< 5; i
++) {
1959 if (!(data
->has_fan
& (1 << i
)))
1961 sysfs_remove_group(&dev
->kobj
, &it87_group_fan
[i
]);
1962 if (sio_data
->beep_pin
)
1963 sysfs_remove_file(&dev
->kobj
,
1964 it87_attributes_fan_beep
[i
]);
1965 if (i
< 3 && !has_16bit_fans(data
))
1966 sysfs_remove_file(&dev
->kobj
,
1967 it87_attributes_fan_div
[i
]);
1969 for (i
= 0; i
< 3; i
++) {
1970 if (sio_data
->skip_pwm
& (1 << 0))
1972 sysfs_remove_group(&dev
->kobj
, &it87_group_pwm
[i
]);
1973 if (has_old_autopwm(data
))
1974 sysfs_remove_group(&dev
->kobj
,
1975 &it87_group_autopwm
[i
]);
1977 if (!sio_data
->skip_vid
)
1978 sysfs_remove_group(&dev
->kobj
, &it87_group_vid
);
1979 sysfs_remove_group(&dev
->kobj
, &it87_group_label
);
1982 static int it87_probe(struct platform_device
*pdev
)
1984 struct it87_data
*data
;
1985 struct resource
*res
;
1986 struct device
*dev
= &pdev
->dev
;
1987 struct it87_sio_data
*sio_data
= dev
->platform_data
;
1989 int enable_pwm_interface
;
1990 int fan_beep_need_rw
;
1992 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
1993 if (!devm_request_region(&pdev
->dev
, res
->start
, IT87_EC_EXTENT
,
1995 dev_err(dev
, "Failed to request region 0x%lx-0x%lx\n",
1996 (unsigned long)res
->start
,
1997 (unsigned long)(res
->start
+ IT87_EC_EXTENT
- 1));
2001 data
= devm_kzalloc(&pdev
->dev
, sizeof(struct it87_data
), GFP_KERNEL
);
2005 data
->addr
= res
->start
;
2006 data
->type
= sio_data
->type
;
2007 data
->features
= it87_devices
[sio_data
->type
].features
;
2008 data
->peci_mask
= it87_devices
[sio_data
->type
].peci_mask
;
2009 data
->old_peci_mask
= it87_devices
[sio_data
->type
].old_peci_mask
;
2010 data
->name
= it87_devices
[sio_data
->type
].name
;
2012 * IT8705F Datasheet 0.4.1, 3h == Version G.
2013 * IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J.
2014 * These are the first revisions with 16-bit tachometer support.
2016 switch (data
->type
) {
2018 if (sio_data
->revision
>= 0x03) {
2019 data
->features
&= ~FEAT_OLD_AUTOPWM
;
2020 data
->features
|= FEAT_16BIT_FANS
;
2024 if (sio_data
->revision
>= 0x08) {
2025 data
->features
&= ~FEAT_OLD_AUTOPWM
;
2026 data
->features
|= FEAT_16BIT_FANS
;
2033 /* Now, we do the remaining detection. */
2034 if ((it87_read_value(data
, IT87_REG_CONFIG
) & 0x80)
2035 || it87_read_value(data
, IT87_REG_CHIPID
) != 0x90)
2038 platform_set_drvdata(pdev
, data
);
2040 mutex_init(&data
->update_lock
);
2042 /* Check PWM configuration */
2043 enable_pwm_interface
= it87_check_pwm(dev
);
2045 /* Starting with IT8721F, we handle scaling of internal voltages */
2046 if (has_12mv_adc(data
)) {
2047 if (sio_data
->internal
& (1 << 0))
2048 data
->in_scaled
|= (1 << 3); /* in3 is AVCC */
2049 if (sio_data
->internal
& (1 << 1))
2050 data
->in_scaled
|= (1 << 7); /* in7 is VSB */
2051 if (sio_data
->internal
& (1 << 2))
2052 data
->in_scaled
|= (1 << 8); /* in8 is Vbat */
2053 } else if (sio_data
->type
== it8782
|| sio_data
->type
== it8783
) {
2054 if (sio_data
->internal
& (1 << 0))
2055 data
->in_scaled
|= (1 << 3); /* in3 is VCC5V */
2056 if (sio_data
->internal
& (1 << 1))
2057 data
->in_scaled
|= (1 << 7); /* in7 is VCCH5V */
2060 data
->has_temp
= 0x07;
2061 if (sio_data
->skip_temp
& (1 << 2)) {
2062 if (sio_data
->type
== it8782
2063 && !(it87_read_value(data
, IT87_REG_TEMP_EXTRA
) & 0x80))
2064 data
->has_temp
&= ~(1 << 2);
2067 /* Initialize the IT87 chip */
2068 it87_init_device(pdev
);
2070 /* Register sysfs hooks */
2071 err
= sysfs_create_group(&dev
->kobj
, &it87_group
);
2075 for (i
= 0; i
< 9; i
++) {
2076 if (sio_data
->skip_in
& (1 << i
))
2078 err
= sysfs_create_group(&dev
->kobj
, &it87_group_in
[i
]);
2081 if (sio_data
->beep_pin
&& it87_attributes_in_beep
[i
]) {
2082 err
= sysfs_create_file(&dev
->kobj
,
2083 it87_attributes_in_beep
[i
]);
2089 for (i
= 0; i
< 3; i
++) {
2090 if (!(data
->has_temp
& (1 << i
)))
2092 err
= sysfs_create_group(&dev
->kobj
, &it87_group_temp
[i
]);
2095 if (has_temp_offset(data
)) {
2096 err
= sysfs_create_file(&dev
->kobj
,
2097 it87_attributes_temp_offset
[i
]);
2101 if (sio_data
->beep_pin
) {
2102 err
= sysfs_create_file(&dev
->kobj
,
2103 it87_attributes_temp_beep
[i
]);
2109 /* Do not create fan files for disabled fans */
2110 fan_beep_need_rw
= 1;
2111 for (i
= 0; i
< 5; i
++) {
2112 if (!(data
->has_fan
& (1 << i
)))
2114 err
= sysfs_create_group(&dev
->kobj
, &it87_group_fan
[i
]);
2118 if (i
< 3 && !has_16bit_fans(data
)) {
2119 err
= sysfs_create_file(&dev
->kobj
,
2120 it87_attributes_fan_div
[i
]);
2125 if (sio_data
->beep_pin
) {
2126 err
= sysfs_create_file(&dev
->kobj
,
2127 it87_attributes_fan_beep
[i
]);
2130 if (!fan_beep_need_rw
)
2134 * As we have a single beep enable bit for all fans,
2135 * only the first enabled fan has a writable attribute
2138 if (sysfs_chmod_file(&dev
->kobj
,
2139 it87_attributes_fan_beep
[i
],
2141 dev_dbg(dev
, "chmod +w fan%d_beep failed\n",
2143 fan_beep_need_rw
= 0;
2147 if (enable_pwm_interface
) {
2148 for (i
= 0; i
< 3; i
++) {
2149 if (sio_data
->skip_pwm
& (1 << i
))
2151 err
= sysfs_create_group(&dev
->kobj
,
2152 &it87_group_pwm
[i
]);
2156 if (!has_old_autopwm(data
))
2158 err
= sysfs_create_group(&dev
->kobj
,
2159 &it87_group_autopwm
[i
]);
2165 if (!sio_data
->skip_vid
) {
2166 data
->vrm
= vid_which_vrm();
2167 /* VID reading from Super-I/O config space if available */
2168 data
->vid
= sio_data
->vid_value
;
2169 err
= sysfs_create_group(&dev
->kobj
, &it87_group_vid
);
2174 /* Export labels for internal sensors */
2175 for (i
= 0; i
< 3; i
++) {
2176 if (!(sio_data
->internal
& (1 << i
)))
2178 err
= sysfs_create_file(&dev
->kobj
,
2179 it87_attributes_label
[i
]);
2184 data
->hwmon_dev
= hwmon_device_register(dev
);
2185 if (IS_ERR(data
->hwmon_dev
)) {
2186 err
= PTR_ERR(data
->hwmon_dev
);
2193 it87_remove_files(dev
);
2197 static int it87_remove(struct platform_device
*pdev
)
2199 struct it87_data
*data
= platform_get_drvdata(pdev
);
2201 hwmon_device_unregister(data
->hwmon_dev
);
2202 it87_remove_files(&pdev
->dev
);
2208 * Must be called with data->update_lock held, except during initialization.
2209 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
2210 * would slow down the IT87 access and should not be necessary.
2212 static int it87_read_value(struct it87_data
*data
, u8 reg
)
2214 outb_p(reg
, data
->addr
+ IT87_ADDR_REG_OFFSET
);
2215 return inb_p(data
->addr
+ IT87_DATA_REG_OFFSET
);
2219 * Must be called with data->update_lock held, except during initialization.
2220 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
2221 * would slow down the IT87 access and should not be necessary.
2223 static void it87_write_value(struct it87_data
*data
, u8 reg
, u8 value
)
2225 outb_p(reg
, data
->addr
+ IT87_ADDR_REG_OFFSET
);
2226 outb_p(value
, data
->addr
+ IT87_DATA_REG_OFFSET
);
2229 /* Return 1 if and only if the PWM interface is safe to use */
2230 static int it87_check_pwm(struct device
*dev
)
2232 struct it87_data
*data
= dev_get_drvdata(dev
);
2234 * Some BIOSes fail to correctly configure the IT87 fans. All fans off
2235 * and polarity set to active low is sign that this is the case so we
2236 * disable pwm control to protect the user.
2238 int tmp
= it87_read_value(data
, IT87_REG_FAN_CTL
);
2239 if ((tmp
& 0x87) == 0) {
2240 if (fix_pwm_polarity
) {
2242 * The user asks us to attempt a chip reconfiguration.
2243 * This means switching to active high polarity and
2244 * inverting all fan speed values.
2249 for (i
= 0; i
< 3; i
++)
2250 pwm
[i
] = it87_read_value(data
,
2254 * If any fan is in automatic pwm mode, the polarity
2255 * might be correct, as suspicious as it seems, so we
2256 * better don't change anything (but still disable the
2259 if (!((pwm
[0] | pwm
[1] | pwm
[2]) & 0x80)) {
2261 "Reconfiguring PWM to active high polarity\n");
2262 it87_write_value(data
, IT87_REG_FAN_CTL
,
2264 for (i
= 0; i
< 3; i
++)
2265 it87_write_value(data
,
2272 "PWM configuration is too broken to be fixed\n");
2276 "Detected broken BIOS defaults, disabling PWM interface\n");
2278 } else if (fix_pwm_polarity
) {
2280 "PWM configuration looks sane, won't touch\n");
2286 /* Called when we have found a new IT87. */
2287 static void it87_init_device(struct platform_device
*pdev
)
2289 struct it87_sio_data
*sio_data
= pdev
->dev
.platform_data
;
2290 struct it87_data
*data
= platform_get_drvdata(pdev
);
2295 * For each PWM channel:
2296 * - If it is in automatic mode, setting to manual mode should set
2297 * the fan to full speed by default.
2298 * - If it is in manual mode, we need a mapping to temperature
2299 * channels to use when later setting to automatic mode later.
2300 * Use a 1:1 mapping by default (we are clueless.)
2301 * In both cases, the value can (and should) be changed by the user
2302 * prior to switching to a different mode.
2303 * Note that this is no longer needed for the IT8721F and later, as
2304 * these have separate registers for the temperature mapping and the
2305 * manual duty cycle.
2307 for (i
= 0; i
< 3; i
++) {
2308 data
->pwm_temp_map
[i
] = i
;
2309 data
->pwm_duty
[i
] = 0x7f; /* Full speed */
2310 data
->auto_pwm
[i
][3] = 0x7f; /* Full speed, hard-coded */
2314 * Some chips seem to have default value 0xff for all limit
2315 * registers. For low voltage limits it makes no sense and triggers
2316 * alarms, so change to 0 instead. For high temperature limits, it
2317 * means -1 degree C, which surprisingly doesn't trigger an alarm,
2318 * but is still confusing, so change to 127 degrees C.
2320 for (i
= 0; i
< 8; i
++) {
2321 tmp
= it87_read_value(data
, IT87_REG_VIN_MIN(i
));
2323 it87_write_value(data
, IT87_REG_VIN_MIN(i
), 0);
2325 for (i
= 0; i
< 3; i
++) {
2326 tmp
= it87_read_value(data
, IT87_REG_TEMP_HIGH(i
));
2328 it87_write_value(data
, IT87_REG_TEMP_HIGH(i
), 127);
2332 * Temperature channels are not forcibly enabled, as they can be
2333 * set to two different sensor types and we can't guess which one
2334 * is correct for a given system. These channels can be enabled at
2335 * run-time through the temp{1-3}_type sysfs accessors if needed.
2338 /* Check if voltage monitors are reset manually or by some reason */
2339 tmp
= it87_read_value(data
, IT87_REG_VIN_ENABLE
);
2340 if ((tmp
& 0xff) == 0) {
2341 /* Enable all voltage monitors */
2342 it87_write_value(data
, IT87_REG_VIN_ENABLE
, 0xff);
2345 /* Check if tachometers are reset manually or by some reason */
2346 mask
= 0x70 & ~(sio_data
->skip_fan
<< 4);
2347 data
->fan_main_ctrl
= it87_read_value(data
, IT87_REG_FAN_MAIN_CTRL
);
2348 if ((data
->fan_main_ctrl
& mask
) == 0) {
2349 /* Enable all fan tachometers */
2350 data
->fan_main_ctrl
|= mask
;
2351 it87_write_value(data
, IT87_REG_FAN_MAIN_CTRL
,
2352 data
->fan_main_ctrl
);
2354 data
->has_fan
= (data
->fan_main_ctrl
>> 4) & 0x07;
2356 /* Set tachometers to 16-bit mode if needed */
2357 if (has_16bit_fans(data
)) {
2358 tmp
= it87_read_value(data
, IT87_REG_FAN_16BIT
);
2359 if (~tmp
& 0x07 & data
->has_fan
) {
2361 "Setting fan1-3 to 16-bit mode\n");
2362 it87_write_value(data
, IT87_REG_FAN_16BIT
,
2365 /* IT8705F, IT8782F, and IT8783E/F only support three fans. */
2366 if (data
->type
!= it87
&& data
->type
!= it8782
&&
2367 data
->type
!= it8783
) {
2369 data
->has_fan
|= (1 << 3); /* fan4 enabled */
2371 data
->has_fan
|= (1 << 4); /* fan5 enabled */
2375 /* Fan input pins may be used for alternative functions */
2376 data
->has_fan
&= ~sio_data
->skip_fan
;
2378 /* Start monitoring */
2379 it87_write_value(data
, IT87_REG_CONFIG
,
2380 (it87_read_value(data
, IT87_REG_CONFIG
) & 0x3e)
2381 | (update_vbat
? 0x41 : 0x01));
2384 static void it87_update_pwm_ctrl(struct it87_data
*data
, int nr
)
2386 data
->pwm_ctrl
[nr
] = it87_read_value(data
, IT87_REG_PWM(nr
));
2387 if (has_newer_autopwm(data
)) {
2388 data
->pwm_temp_map
[nr
] = data
->pwm_ctrl
[nr
] & 0x03;
2389 data
->pwm_duty
[nr
] = it87_read_value(data
,
2390 IT87_REG_PWM_DUTY(nr
));
2392 if (data
->pwm_ctrl
[nr
] & 0x80) /* Automatic mode */
2393 data
->pwm_temp_map
[nr
] = data
->pwm_ctrl
[nr
] & 0x03;
2394 else /* Manual mode */
2395 data
->pwm_duty
[nr
] = data
->pwm_ctrl
[nr
] & 0x7f;
2398 if (has_old_autopwm(data
)) {
2401 for (i
= 0; i
< 5 ; i
++)
2402 data
->auto_temp
[nr
][i
] = it87_read_value(data
,
2403 IT87_REG_AUTO_TEMP(nr
, i
));
2404 for (i
= 0; i
< 3 ; i
++)
2405 data
->auto_pwm
[nr
][i
] = it87_read_value(data
,
2406 IT87_REG_AUTO_PWM(nr
, i
));
2410 static struct it87_data
*it87_update_device(struct device
*dev
)
2412 struct it87_data
*data
= dev_get_drvdata(dev
);
2415 mutex_lock(&data
->update_lock
);
2417 if (time_after(jiffies
, data
->last_updated
+ HZ
+ HZ
/ 2)
2421 * Cleared after each update, so reenable. Value
2422 * returned by this read will be previous value
2424 it87_write_value(data
, IT87_REG_CONFIG
,
2425 it87_read_value(data
, IT87_REG_CONFIG
) | 0x40);
2427 for (i
= 0; i
<= 7; i
++) {
2429 it87_read_value(data
, IT87_REG_VIN(i
));
2431 it87_read_value(data
, IT87_REG_VIN_MIN(i
));
2433 it87_read_value(data
, IT87_REG_VIN_MAX(i
));
2435 /* in8 (battery) has no limit registers */
2436 data
->in
[8][0] = it87_read_value(data
, IT87_REG_VIN(8));
2438 for (i
= 0; i
< 5; i
++) {
2439 /* Skip disabled fans */
2440 if (!(data
->has_fan
& (1 << i
)))
2444 it87_read_value(data
, IT87_REG_FAN_MIN
[i
]);
2445 data
->fan
[i
][0] = it87_read_value(data
,
2447 /* Add high byte if in 16-bit mode */
2448 if (has_16bit_fans(data
)) {
2449 data
->fan
[i
][0] |= it87_read_value(data
,
2450 IT87_REG_FANX
[i
]) << 8;
2451 data
->fan
[i
][1] |= it87_read_value(data
,
2452 IT87_REG_FANX_MIN
[i
]) << 8;
2455 for (i
= 0; i
< 3; i
++) {
2456 if (!(data
->has_temp
& (1 << i
)))
2459 it87_read_value(data
, IT87_REG_TEMP(i
));
2461 it87_read_value(data
, IT87_REG_TEMP_LOW(i
));
2463 it87_read_value(data
, IT87_REG_TEMP_HIGH(i
));
2464 if (has_temp_offset(data
))
2466 it87_read_value(data
,
2467 IT87_REG_TEMP_OFFSET
[i
]);
2470 /* Newer chips don't have clock dividers */
2471 if ((data
->has_fan
& 0x07) && !has_16bit_fans(data
)) {
2472 i
= it87_read_value(data
, IT87_REG_FAN_DIV
);
2473 data
->fan_div
[0] = i
& 0x07;
2474 data
->fan_div
[1] = (i
>> 3) & 0x07;
2475 data
->fan_div
[2] = (i
& 0x40) ? 3 : 1;
2479 it87_read_value(data
, IT87_REG_ALARM1
) |
2480 (it87_read_value(data
, IT87_REG_ALARM2
) << 8) |
2481 (it87_read_value(data
, IT87_REG_ALARM3
) << 16);
2482 data
->beeps
= it87_read_value(data
, IT87_REG_BEEP_ENABLE
);
2484 data
->fan_main_ctrl
= it87_read_value(data
,
2485 IT87_REG_FAN_MAIN_CTRL
);
2486 data
->fan_ctl
= it87_read_value(data
, IT87_REG_FAN_CTL
);
2487 for (i
= 0; i
< 3; i
++)
2488 it87_update_pwm_ctrl(data
, i
);
2490 data
->sensor
= it87_read_value(data
, IT87_REG_TEMP_ENABLE
);
2491 data
->extra
= it87_read_value(data
, IT87_REG_TEMP_EXTRA
);
2493 * The IT8705F does not have VID capability.
2494 * The IT8718F and later don't use IT87_REG_VID for the
2497 if (data
->type
== it8712
|| data
->type
== it8716
) {
2498 data
->vid
= it87_read_value(data
, IT87_REG_VID
);
2500 * The older IT8712F revisions had only 5 VID pins,
2501 * but we assume it is always safe to read 6 bits.
2505 data
->last_updated
= jiffies
;
2509 mutex_unlock(&data
->update_lock
);
2514 static int __init
it87_device_add(unsigned short address
,
2515 const struct it87_sio_data
*sio_data
)
2517 struct resource res
= {
2518 .start
= address
+ IT87_EC_OFFSET
,
2519 .end
= address
+ IT87_EC_OFFSET
+ IT87_EC_EXTENT
- 1,
2521 .flags
= IORESOURCE_IO
,
2525 err
= acpi_check_resource_conflict(&res
);
2529 pdev
= platform_device_alloc(DRVNAME
, address
);
2532 pr_err("Device allocation failed\n");
2536 err
= platform_device_add_resources(pdev
, &res
, 1);
2538 pr_err("Device resource addition failed (%d)\n", err
);
2539 goto exit_device_put
;
2542 err
= platform_device_add_data(pdev
, sio_data
,
2543 sizeof(struct it87_sio_data
));
2545 pr_err("Platform data allocation failed\n");
2546 goto exit_device_put
;
2549 err
= platform_device_add(pdev
);
2551 pr_err("Device addition failed (%d)\n", err
);
2552 goto exit_device_put
;
2558 platform_device_put(pdev
);
2563 static int __init
sm_it87_init(void)
2566 unsigned short isa_address
= 0;
2567 struct it87_sio_data sio_data
;
2569 memset(&sio_data
, 0, sizeof(struct it87_sio_data
));
2570 err
= it87_find(&isa_address
, &sio_data
);
2573 err
= platform_driver_register(&it87_driver
);
2577 err
= it87_device_add(isa_address
, &sio_data
);
2579 platform_driver_unregister(&it87_driver
);
2586 static void __exit
sm_it87_exit(void)
2588 platform_device_unregister(pdev
);
2589 platform_driver_unregister(&it87_driver
);
2593 MODULE_AUTHOR("Chris Gauthron, Jean Delvare <khali@linux-fr.org>");
2594 MODULE_DESCRIPTION("IT8705F/IT871xF/IT872xF hardware monitoring driver");
2595 module_param(update_vbat
, bool, 0);
2596 MODULE_PARM_DESC(update_vbat
, "Update vbat if set else return powerup value");
2597 module_param(fix_pwm_polarity
, bool, 0);
2598 MODULE_PARM_DESC(fix_pwm_polarity
,
2599 "Force PWM polarity to active high (DANGEROUS)");
2600 MODULE_LICENSE("GPL");
2602 module_init(sm_it87_init
);
2603 module_exit(sm_it87_exit
);