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: IT8603E Super I/O chip w/LPC interface
14 * IT8607E Super I/O chip w/LPC interface
15 * IT8613E Super I/O chip w/LPC interface
16 * IT8620E Super I/O chip w/LPC interface
17 * IT8622E Super I/O chip w/LPC interface
18 * IT8623E Super I/O chip w/LPC interface
19 * IT8625E Super I/O chip w/LPC interface
20 * IT8628E Super I/O chip w/LPC interface
21 * IT8655E Super I/O chip w/LPC interface
22 * IT8665E Super I/O chip w/LPC interface
23 * IT8686E Super I/O chip w/LPC interface
24 * IT8705F Super I/O chip w/LPC interface
25 * IT8712F Super I/O chip w/LPC interface
26 * IT8716F Super I/O chip w/LPC interface
27 * IT8718F Super I/O chip w/LPC interface
28 * IT8720F Super I/O chip w/LPC interface
29 * IT8721F Super I/O chip w/LPC interface
30 * IT8726F Super I/O chip w/LPC interface
31 * IT8728F Super I/O chip w/LPC interface
32 * IT8732F Super I/O chip w/LPC interface
33 * IT8758E Super I/O chip w/LPC interface
34 * IT8771E Super I/O chip w/LPC interface
35 * IT8772E Super I/O chip w/LPC interface
36 * IT8781F Super I/O chip w/LPC interface
37 * IT8782F Super I/O chip w/LPC interface
38 * IT8783E/F Super I/O chip w/LPC interface
39 * IT8786E Super I/O chip w/LPC interface
40 * IT8790E Super I/O chip w/LPC interface
41 * IT8792E Super I/O chip w/LPC interface
42 * Sis950 A clone of the IT8705F
44 * Copyright (C) 2001 Chris Gauthron
45 * Copyright (C) 2005-2010 Jean Delvare <jdelvare@suse.de>
47 * This program is free software; you can redistribute it and/or modify
48 * it under the terms of the GNU General Public License as published by
49 * the Free Software Foundation; either version 2 of the License, or
50 * (at your option) any later version.
52 * This program is distributed in the hope that it will be useful,
53 * but WITHOUT ANY WARRANTY; without even the implied warranty of
54 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
55 * GNU General Public License for more details.
58 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
60 #include <linux/bitops.h>
61 #include <linux/module.h>
62 #include <linux/init.h>
63 #include <linux/slab.h>
64 #include <linux/jiffies.h>
65 #include <linux/platform_device.h>
66 #include <linux/hwmon.h>
67 #include <linux/hwmon-sysfs.h>
68 #include <linux/hwmon-vid.h>
69 #include <linux/err.h>
70 #include <linux/mutex.h>
71 #include <linux/sysfs.h>
72 #include <linux/string.h>
73 #include <linux/dmi.h>
74 #include <linux/acpi.h>
78 #define DRVNAME "it87"
80 enum chips { it87, it8712, it8716, it8718, it8720, it8721, it8728, it8732,
81 it8771, it8772, it8781, it8782, it8783, it8786, it8790,
82 it8792, it8603, it8607, it8613, it8620, it8622, it8625, it8628,
83 it8655, it8665, it8686 };
85 static unsigned short force_id;
86 module_param(force_id, ushort, 0);
87 MODULE_PARM_DESC(force_id, "Override the detected device ID");
89 static struct platform_device *it87_pdev[2];
91 #define REG_2E 0x2e /* The register to read/write */
92 #define REG_4E 0x4e /* Secondary register to read/write */
94 #define DEV 0x07 /* Register: Logical device select */
95 #define PME 0x04 /* The device with the fan registers in it */
97 /* The device with the IT8718F/IT8720F VID value in it */
100 #define DEVID 0x20 /* Register: Device ID */
101 #define DEVREV 0x22 /* Register: Device Revision */
103 static inline void __superio_enter(int ioreg)
108 outb(ioreg == REG_4E ? 0xaa : 0x55, ioreg);
111 static inline int superio_inb(int ioreg, int reg)
116 val = inb(ioreg + 1);
121 static inline void superio_outb(int ioreg, int reg, int val)
124 outb(val, ioreg + 1);
127 static int superio_inw(int ioreg, int reg)
129 return (superio_inb(ioreg, reg) << 8) | superio_inb(ioreg, reg + 1);
132 static inline void superio_select(int ioreg, int ldn)
135 outb(ldn, ioreg + 1);
138 static inline int superio_enter(int ioreg)
141 * Try to reserve ioreg and ioreg + 1 for exclusive access.
143 if (!request_muxed_region(ioreg, 2, DRVNAME))
146 __superio_enter(ioreg);
153 static inline void superio_exit(int ioreg, bool doexit)
157 outb(0x02, ioreg + 1);
159 release_region(ioreg, 2);
162 /* Logical device 4 registers */
163 #define IT8712F_DEVID 0x8712
164 #define IT8705F_DEVID 0x8705
165 #define IT8716F_DEVID 0x8716
166 #define IT8718F_DEVID 0x8718
167 #define IT8720F_DEVID 0x8720
168 #define IT8721F_DEVID 0x8721
169 #define IT8726F_DEVID 0x8726
170 #define IT8728F_DEVID 0x8728
171 #define IT8732F_DEVID 0x8732
172 #define IT8792E_DEVID 0x8733
173 #define IT8771E_DEVID 0x8771
174 #define IT8772E_DEVID 0x8772
175 #define IT8781F_DEVID 0x8781
176 #define IT8782F_DEVID 0x8782
177 #define IT8783E_DEVID 0x8783
178 #define IT8786E_DEVID 0x8786
179 #define IT8790E_DEVID 0x8790
180 #define IT8603E_DEVID 0x8603
181 #define IT8607E_DEVID 0x8607
182 #define IT8613E_DEVID 0x8613
183 #define IT8620E_DEVID 0x8620
184 #define IT8622E_DEVID 0x8622
185 #define IT8623E_DEVID 0x8623
186 #define IT8625E_DEVID 0x8625
187 #define IT8628E_DEVID 0x8628
188 #define IT8655E_DEVID 0x8655
189 #define IT8665E_DEVID 0x8665
190 #define IT8686E_DEVID 0x8686
191 #define IT87_ACT_REG 0x30
192 #define IT87_BASE_REG 0x60
194 /* Logical device 7 registers (IT8712F and later) */
195 #define IT87_SIO_GPIO1_REG 0x25
196 #define IT87_SIO_GPIO2_REG 0x26
197 #define IT87_SIO_GPIO3_REG 0x27
198 #define IT87_SIO_GPIO4_REG 0x28
199 #define IT87_SIO_GPIO5_REG 0x29
200 #define IT87_SIO_GPIO9_REG 0xd3
201 #define IT87_SIO_PINX1_REG 0x2a /* Pin selection */
202 #define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
203 #define IT87_SIO_PINX4_REG 0x2d /* Pin selection */
204 #define IT87_SIO_SPI_REG 0xef /* SPI function pin select */
205 #define IT87_SIO_VID_REG 0xfc /* VID value */
206 #define IT87_SIO_BEEP_PIN_REG 0xf6 /* Beep pin mapping */
208 /* Update battery voltage after every reading if true */
209 static bool update_vbat;
211 /* Not all BIOSes properly configure the PWM registers */
212 static bool fix_pwm_polarity;
214 /* Many IT87 constants specified below */
216 /* Length of ISA address segment */
217 #define IT87_EXTENT 8
219 /* Length of ISA address segment for Environmental Controller */
220 #define IT87_EC_EXTENT 2
222 /* Offset of EC registers from ISA base address */
223 #define IT87_EC_OFFSET 5
225 /* Where are the ISA address/data registers relative to the EC base address */
226 #define IT87_ADDR_REG_OFFSET 0
227 #define IT87_DATA_REG_OFFSET 1
229 /*----- The IT87 registers -----*/
231 #define IT87_REG_CONFIG 0x00
233 #define IT87_REG_ALARM1 0x01
234 #define IT87_REG_ALARM2 0x02
235 #define IT87_REG_ALARM3 0x03
237 #define IT87_REG_BANK 0x06
240 * The IT8718F and IT8720F have the VID value in a different register, in
241 * Super-I/O configuration space.
243 #define IT87_REG_VID 0x0a
245 * The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b
246 * for fan divisors. Later IT8712F revisions must use 16-bit tachometer
249 #define IT87_REG_FAN_DIV 0x0b
250 #define IT87_REG_FAN_16BIT 0x0c
254 * - up to 13 voltage (0 to 7, battery, avcc, 10 to 12)
255 * - up to 6 temp (1 to 6)
256 * - up to 6 fan (1 to 6)
259 static const u8 IT87_REG_FAN[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82, 0x4c };
260 static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86, 0x4e };
261 static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83, 0x4d };
262 static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87, 0x4f };
264 static const u8 IT87_REG_FAN_8665[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82, 0x93 };
265 static const u8 IT87_REG_FAN_MIN_8665[] =
266 { 0x10, 0x11, 0x12, 0x84, 0x86, 0xb2 };
267 static const u8 IT87_REG_FANX_8665[] = { 0x18, 0x19, 0x1a, 0x81, 0x83, 0x94 };
268 static const u8 IT87_REG_FANX_MIN_8665[] =
269 { 0x1b, 0x1c, 0x1d, 0x85, 0x87, 0xb3 };
271 static const u8 IT87_REG_TEMP_OFFSET[] = { 0x56, 0x57, 0x59, 0x5a, 0x90, 0x91 };
273 static const u8 IT87_REG_TEMP_OFFSET_8686[] = { 0x56, 0x57, 0x59, 0x90, 0x91, 0x92 };
275 #define IT87_REG_FAN_MAIN_CTRL 0x13
276 #define IT87_REG_FAN_CTL 0x14
278 static const u8 IT87_REG_PWM[] = { 0x15, 0x16, 0x17, 0x7f, 0xa7, 0xaf };
279 static const u8 IT87_REG_PWM_8665[] = { 0x15, 0x16, 0x17, 0x1e, 0x1f, 0x92 };
281 static const u8 IT87_REG_PWM_DUTY[] = { 0x63, 0x6b, 0x73, 0x7b, 0xa3, 0xab };
283 static const u8 IT87_REG_VIN[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26,
284 0x27, 0x28, 0x2f, 0x2c, 0x2d, 0x2e };
286 #define IT87_REG_TEMP(nr) (0x29 + (nr))
288 #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2)
289 #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2)
291 static const u8 IT87_REG_TEMP_HIGH[] = { 0x40, 0x42, 0x44, 0x46, 0xb4, 0xb6 };
292 static const u8 IT87_REG_TEMP_LOW[] = { 0x41, 0x43, 0x45, 0x47, 0xb5, 0xb7 };
294 static const u8 IT87_REG_TEMP_HIGH_8686[] =
295 { 0x40, 0x42, 0x44, 0xb4, 0xb6, 0xb8 };
296 static const u8 IT87_REG_TEMP_LOW_8686[] =
297 { 0x41, 0x43, 0x45, 0xb5, 0xb7, 0xb9 };
299 #define IT87_REG_VIN_ENABLE 0x50
300 #define IT87_REG_TEMP_ENABLE 0x51
301 #define IT87_REG_TEMP_EXTRA 0x55
302 #define IT87_REG_BEEP_ENABLE 0x5c
304 #define IT87_REG_CHIPID 0x58
306 static const u8 IT87_REG_AUTO_BASE[] = { 0x60, 0x68, 0x70, 0x78, 0xa0, 0xa8 };
308 #define IT87_REG_AUTO_TEMP(nr, i) (IT87_REG_AUTO_BASE[nr] + (i))
309 #define IT87_REG_AUTO_PWM(nr, i) (IT87_REG_AUTO_BASE[nr] + 5 + (i))
311 #define IT87_REG_TEMP456_ENABLE 0x77
313 static const u16 IT87_REG_TEMP_SRC1[] = { 0x21d, 0x21e, 0x21f };
314 #define IT87_REG_TEMP_SRC2 0x23d
316 #define NUM_VIN ARRAY_SIZE(IT87_REG_VIN)
317 #define NUM_VIN_LIMIT 8
319 #define NUM_FAN ARRAY_SIZE(IT87_REG_FAN)
320 #define NUM_FAN_DIV 3
321 #define NUM_PWM ARRAY_SIZE(IT87_REG_PWM)
322 #define NUM_AUTO_PWM ARRAY_SIZE(IT87_REG_PWM)
324 struct it87_devices {
326 const char * const suffix;
334 #define FEAT_12MV_ADC BIT(0)
335 #define FEAT_NEWER_AUTOPWM BIT(1)
336 #define FEAT_OLD_AUTOPWM BIT(2)
337 #define FEAT_16BIT_FANS BIT(3)
338 #define FEAT_TEMP_PECI BIT(5)
339 #define FEAT_TEMP_OLD_PECI BIT(6)
340 #define FEAT_FAN16_CONFIG BIT(7) /* Need to enable 16-bit fans */
341 #define FEAT_FIVE_FANS BIT(8) /* Supports five fans */
342 #define FEAT_VID BIT(9) /* Set if chip supports VID */
343 #define FEAT_IN7_INTERNAL BIT(10) /* Set if in7 is internal */
344 #define FEAT_SIX_FANS BIT(11) /* Supports six fans */
345 #define FEAT_10_9MV_ADC BIT(12)
346 #define FEAT_AVCC3 BIT(13) /* Chip supports in9/AVCC3 */
347 #define FEAT_FIVE_PWM BIT(14) /* Chip supports 5 pwm chn */
348 #define FEAT_SIX_PWM BIT(15) /* Chip supports 6 pwm chn */
349 #define FEAT_PWM_FREQ2 BIT(16) /* Separate pwm freq 2 */
350 #define FEAT_SIX_TEMP BIT(17) /* Up to 6 temp sensors */
351 #define FEAT_VIN3_5V BIT(18) /* VIN3 connected to +5V */
352 #define FEAT_FOUR_FANS BIT(19) /* Supports four fans */
353 #define FEAT_FOUR_PWM BIT(20) /* Supports four fan controls */
354 #define FEAT_BANK_SEL BIT(21) /* Chip has multi-bank support */
355 #define FEAT_SCALING BIT(22) /* Internal voltage scaling */
356 #define FEAT_FANCTL_ONOFF BIT(23) /* chip has FAN_CTL ON/OFF */
357 #define FEAT_11MV_ADC BIT(24)
358 #define FEAT_NEW_TEMPMAP BIT(25) /* new temp input selection */
360 static const struct it87_devices it87_devices[] = {
364 .features = FEAT_OLD_AUTOPWM | FEAT_FANCTL_ONOFF,
365 /* may need to overwrite */
367 .num_temp_offset = 0,
372 .features = FEAT_OLD_AUTOPWM | FEAT_VID | FEAT_FANCTL_ONOFF,
373 /* may need to overwrite */
375 .num_temp_offset = 0,
380 .features = FEAT_16BIT_FANS | FEAT_VID
381 | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS | FEAT_PWM_FREQ2
384 .num_temp_offset = 3,
389 .features = FEAT_16BIT_FANS | FEAT_VID
390 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS
391 | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
393 .num_temp_offset = 3,
394 .old_peci_mask = 0x4,
399 .features = FEAT_16BIT_FANS | FEAT_VID
400 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS
401 | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
403 .num_temp_offset = 3,
404 .old_peci_mask = 0x4,
409 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
410 | FEAT_TEMP_OLD_PECI | FEAT_TEMP_PECI
411 | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS | FEAT_IN7_INTERNAL
412 | FEAT_PWM_FREQ2 | FEAT_SCALING | FEAT_FANCTL_ONOFF,
414 .num_temp_offset = 3,
416 .old_peci_mask = 0x02, /* Actually reports PCH */
421 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
422 | FEAT_TEMP_PECI | FEAT_FIVE_FANS
423 | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2 | FEAT_SCALING
426 .num_temp_offset = 3,
432 .features = FEAT_NEWER_AUTOPWM | FEAT_16BIT_FANS
433 | FEAT_TEMP_OLD_PECI | FEAT_TEMP_PECI
434 | FEAT_10_9MV_ADC | FEAT_IN7_INTERNAL | FEAT_FOUR_FANS
435 | FEAT_FOUR_PWM | FEAT_FANCTL_ONOFF,
437 .num_temp_offset = 3,
439 .old_peci_mask = 0x02, /* Actually reports PCH */
444 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
445 | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
446 | FEAT_PWM_FREQ2 | FEAT_SCALING | FEAT_FANCTL_ONOFF,
447 /* PECI: guesswork */
449 /* 16 bit fans (OHM) */
450 /* three fans, always 16 bit (guesswork) */
452 .num_temp_offset = 3,
458 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
459 | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
460 | FEAT_PWM_FREQ2 | FEAT_SCALING | FEAT_FANCTL_ONOFF,
461 /* PECI (coreboot) */
462 /* 12mV ADC (HWSensors4, OHM) */
463 /* 16 bit fans (HWSensors4, OHM) */
464 /* three fans, always 16 bit (datasheet) */
466 .num_temp_offset = 3,
472 .features = FEAT_16BIT_FANS
473 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2
476 .num_temp_offset = 3,
477 .old_peci_mask = 0x4,
482 .features = FEAT_16BIT_FANS
483 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2
486 .num_temp_offset = 3,
487 .old_peci_mask = 0x4,
492 .features = FEAT_16BIT_FANS
493 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2
496 .num_temp_offset = 3,
497 .old_peci_mask = 0x4,
502 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
503 | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
504 | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
506 .num_temp_offset = 3,
512 .features = FEAT_NEWER_AUTOPWM | FEAT_10_9MV_ADC | FEAT_SCALING
513 | FEAT_16BIT_FANS | FEAT_TEMP_PECI
514 | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
516 .num_temp_offset = 3,
522 .features = FEAT_NEWER_AUTOPWM | FEAT_10_9MV_ADC | FEAT_SCALING
523 | FEAT_16BIT_FANS | FEAT_TEMP_PECI
524 | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
526 .num_temp_offset = 3,
532 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
533 | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
534 | FEAT_AVCC3 | FEAT_PWM_FREQ2 | FEAT_SCALING,
536 .num_temp_offset = 3,
542 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
543 | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
544 | FEAT_AVCC3 | FEAT_PWM_FREQ2 | FEAT_SCALING
547 .num_temp_offset = 3,
553 .features = FEAT_NEWER_AUTOPWM | FEAT_11MV_ADC | FEAT_16BIT_FANS
554 | FEAT_TEMP_PECI | FEAT_FIVE_FANS
555 | FEAT_FIVE_PWM | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2
556 | FEAT_AVCC3 | FEAT_SCALING | FEAT_NEW_TEMPMAP,
558 .num_temp_offset = 6,
564 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
565 | FEAT_TEMP_PECI | FEAT_SIX_FANS
566 | FEAT_IN7_INTERNAL | FEAT_SIX_PWM | FEAT_PWM_FREQ2
567 | FEAT_SIX_TEMP | FEAT_VIN3_5V | FEAT_SCALING
570 .num_temp_offset = 3,
576 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
577 | FEAT_TEMP_PECI | FEAT_FIVE_FANS
578 | FEAT_FIVE_PWM | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2
579 | FEAT_AVCC3 | FEAT_VIN3_5V | FEAT_SCALING,
581 .num_temp_offset = 3,
587 .features = FEAT_NEWER_AUTOPWM | FEAT_16BIT_FANS
588 | FEAT_AVCC3 | FEAT_NEW_TEMPMAP
589 | FEAT_11MV_ADC | FEAT_IN7_INTERNAL | FEAT_SIX_FANS
590 | FEAT_SIX_PWM | FEAT_BANK_SEL | FEAT_SCALING,
592 .num_temp_offset = 6,
597 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
598 | FEAT_TEMP_PECI | FEAT_SIX_FANS
599 | FEAT_IN7_INTERNAL | FEAT_SIX_PWM | FEAT_PWM_FREQ2
600 | FEAT_SIX_TEMP | FEAT_SCALING | FEAT_AVCC3
603 .num_temp_offset = 3,
609 .features = FEAT_NEWER_AUTOPWM | FEAT_16BIT_FANS
610 | FEAT_AVCC3 | FEAT_NEW_TEMPMAP
611 | FEAT_10_9MV_ADC | FEAT_IN7_INTERNAL | FEAT_BANK_SEL,
613 .num_temp_offset = 6,
618 .features = FEAT_NEWER_AUTOPWM | FEAT_16BIT_FANS
619 | FEAT_AVCC3 | FEAT_NEW_TEMPMAP
620 | FEAT_10_9MV_ADC | FEAT_IN7_INTERNAL | FEAT_SIX_FANS
621 | FEAT_SIX_PWM | FEAT_BANK_SEL,
623 .num_temp_offset = 6,
628 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
629 | FEAT_SIX_FANS | FEAT_NEW_TEMPMAP
630 | FEAT_IN7_INTERNAL | FEAT_SIX_PWM | FEAT_PWM_FREQ2
631 | FEAT_SIX_TEMP | FEAT_BANK_SEL | FEAT_SCALING | FEAT_AVCC3,
633 .num_temp_offset = 6,
637 #define has_16bit_fans(data) ((data)->features & FEAT_16BIT_FANS)
638 #define has_12mv_adc(data) ((data)->features & FEAT_12MV_ADC)
639 #define has_10_9mv_adc(data) ((data)->features & FEAT_10_9MV_ADC)
640 #define has_newer_autopwm(data) ((data)->features & FEAT_NEWER_AUTOPWM)
641 #define has_old_autopwm(data) ((data)->features & FEAT_OLD_AUTOPWM)
642 #define has_temp_peci(data, nr) (((data)->features & FEAT_TEMP_PECI) && \
643 ((data)->peci_mask & BIT(nr)))
644 #define has_temp_old_peci(data, nr) \
645 (((data)->features & FEAT_TEMP_OLD_PECI) && \
646 ((data)->old_peci_mask & BIT(nr)))
647 #define has_fan16_config(data) ((data)->features & FEAT_FAN16_CONFIG)
648 #define has_five_fans(data) ((data)->features & (FEAT_FIVE_FANS | \
650 #define has_vid(data) ((data)->features & FEAT_VID)
651 #define has_in7_internal(data) ((data)->features & FEAT_IN7_INTERNAL)
652 #define has_six_fans(data) ((data)->features & FEAT_SIX_FANS)
653 #define has_avcc3(data) ((data)->features & FEAT_AVCC3)
654 #define has_five_pwm(data) ((data)->features & (FEAT_FIVE_PWM \
656 #define has_six_pwm(data) ((data)->features & FEAT_SIX_PWM)
657 #define has_pwm_freq2(data) ((data)->features & FEAT_PWM_FREQ2)
658 #define has_six_temp(data) ((data)->features & FEAT_SIX_TEMP)
659 #define has_vin3_5v(data) ((data)->features & FEAT_VIN3_5V)
660 #define has_four_fans(data) ((data)->features & (FEAT_FOUR_FANS | \
663 #define has_four_pwm(data) ((data)->features & (FEAT_FOUR_PWM | \
666 #define has_bank_sel(data) ((data)->features & FEAT_BANK_SEL)
667 #define has_scaling(data) ((data)->features & FEAT_SCALING)
668 #define has_fanctl_onoff(data) ((data)->features & FEAT_FANCTL_ONOFF)
669 #define has_11mv_adc(data) ((data)->features & FEAT_11MV_ADC)
670 #define has_new_tempmap(data) ((data)->features & FEAT_NEW_TEMPMAP)
672 struct it87_sio_data {
674 /* Values read from Super-I/O config space */
678 u8 internal; /* Internal sensors can be labeled */
679 /* Features skipped based on config or DMI */
688 * For each registered chip, we need to keep some data in memory.
689 * The structure is dynamically allocated.
692 const struct attribute_group *groups[7];
701 const u8 *REG_FAN_MIN;
702 const u8 *REG_FANX_MIN;
706 const u8 *REG_TEMP_OFFSET;
707 const u8 *REG_TEMP_LOW;
708 const u8 *REG_TEMP_HIGH;
712 struct mutex update_lock;
713 char valid; /* !=0 if following fields are valid */
714 unsigned long last_updated; /* In jiffies */
716 u16 in_scaled; /* Internal voltage sensors are scaled */
717 u16 in_internal; /* Bitfield, internal sensors (for labels) */
718 u16 has_in; /* Bitfield, voltage sensors enabled */
719 u8 in[NUM_VIN][3]; /* [nr][0]=in, [1]=min, [2]=max */
720 u8 has_fan; /* Bitfield, fans enabled */
721 u16 fan[NUM_FAN][2]; /* Register values, [nr][0]=fan, [1]=min */
722 u8 has_temp; /* Bitfield, temp sensors enabled */
723 s8 temp[NUM_TEMP][4]; /* [nr][0]=temp, [1]=min, [2]=max, [3]=offset */
724 u8 num_temp_limit; /* Number of temperature limit registers */
725 u8 num_temp_offset; /* Number of temperature offset registers */
726 u8 sensor; /* Register value (IT87_REG_TEMP_ENABLE) */
727 u8 extra; /* Register value (IT87_REG_TEMP_EXTRA) */
728 u8 fan_div[NUM_FAN_DIV];/* Register encoding, shifted right */
729 bool has_vid; /* True if VID supported */
730 u8 vid; /* Register encoding, combined */
732 u32 alarms; /* Register encoding, combined */
733 bool has_beep; /* true if beep supported */
734 u8 beeps; /* Register encoding */
735 u8 fan_main_ctrl; /* Register value */
736 u8 fan_ctl; /* Register value */
739 * The following 3 arrays correspond to the same registers up to
740 * the IT8720F. The meaning of bits 6-0 depends on the value of bit
741 * 7, and we want to preserve settings on mode changes, so we have
742 * to track all values separately.
743 * Starting with the IT8721F, the manual PWM duty cycles are stored
744 * in separate registers (8-bit values), so the separate tracking
745 * is no longer needed, but it is still done to keep the driver
748 u8 has_pwm; /* Bitfield, pwm control enabled */
749 u8 pwm_ctrl[NUM_PWM]; /* Register value */
750 u8 pwm_duty[NUM_PWM]; /* Manual PWM value set by user */
751 u8 pwm_temp_map[NUM_PWM];/* PWM to temp. chan. mapping (bits 1-0) */
753 /* Automatic fan speed control registers */
754 u8 auto_pwm[NUM_AUTO_PWM][4]; /* [nr][3] is hard-coded */
755 s8 auto_temp[NUM_AUTO_PWM][5]; /* [nr][0] is point1_temp_hyst */
758 static int adc_lsb(const struct it87_data *data, int nr)
762 if (has_12mv_adc(data))
764 else if (has_10_9mv_adc(data))
766 else if (has_11mv_adc(data))
770 if (data->in_scaled & BIT(nr))
775 static u8 in_to_reg(const struct it87_data *data, int nr, long val)
777 val = DIV_ROUND_CLOSEST(val * 10, adc_lsb(data, nr));
778 return clamp_val(val, 0, 255);
781 static int in_from_reg(const struct it87_data *data, int nr, int val)
783 return DIV_ROUND_CLOSEST(val * adc_lsb(data, nr), 10);
786 static inline u8 FAN_TO_REG(long rpm, int div)
790 rpm = clamp_val(rpm, 1, 1000000);
791 return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
794 static inline u16 FAN16_TO_REG(long rpm)
798 return clamp_val((1350000 + rpm) / (rpm * 2), 1, 0xfffe);
801 #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \
802 1350000 / ((val) * (div)))
803 /* The divider is fixed to 2 in 16-bit mode */
804 #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
805 1350000 / ((val) * 2))
807 #define TEMP_TO_REG(val) (clamp_val(((val) < 0 ? (((val) - 500) / 1000) : \
808 ((val) + 500) / 1000), -128, 127))
809 #define TEMP_FROM_REG(val) ((val) * 1000)
811 static u8 pwm_to_reg(const struct it87_data *data, long val)
813 if (has_newer_autopwm(data))
819 static int pwm_from_reg(const struct it87_data *data, u8 reg)
821 if (has_newer_autopwm(data))
824 return (reg & 0x7f) << 1;
827 static int DIV_TO_REG(int val)
831 while (answer < 7 && (val >>= 1))
836 #define DIV_FROM_REG(val) BIT(val)
839 * PWM base frequencies. The frequency has to be divided by either 128 or 256,
840 * depending on the chip type, to calculate the actual PWM frequency.
842 * Some of the chip datasheets suggest a base frequency of 51 kHz instead
843 * of 750 kHz for the slowest base frequency, resulting in a PWM frequency
844 * of 200 Hz. Sometimes both PWM frequency select registers are affected,
845 * sometimes just one. It is unknown if this is a datasheet error or real,
846 * so this is ignored for now.
848 static const unsigned int pwm_freq[8] = {
859 static int _it87_read_value(struct it87_data *data, u8 reg)
861 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
862 return inb_p(data->addr + IT87_DATA_REG_OFFSET);
865 static void _it87_write_value(struct it87_data *data, u8 reg, u8 value)
867 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
868 outb_p(value, data->addr + IT87_DATA_REG_OFFSET);
871 static void it87_set_bank(struct it87_data *data, u8 bank)
873 if (has_bank_sel(data) && bank != data->bank) {
874 u8 breg = _it87_read_value(data, IT87_REG_BANK);
879 _it87_write_value(data, IT87_REG_BANK, breg);
884 * Must be called with data->update_lock held, except during initialization.
885 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
886 * would slow down the IT87 access and should not be necessary.
888 static int it87_read_value(struct it87_data *data, u16 reg)
890 it87_set_bank(data, reg >> 8);
891 return _it87_read_value(data, reg & 0xff);
895 * Must be called with data->update_lock held, except during initialization.
896 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
897 * would slow down the IT87 access and should not be necessary.
899 static void it87_write_value(struct it87_data *data, u16 reg, u8 value)
901 it87_set_bank(data, reg >> 8);
902 _it87_write_value(data, reg & 0xff, value);
905 static void it87_update_pwm_ctrl(struct it87_data *data, int nr)
907 data->pwm_ctrl[nr] = it87_read_value(data, data->REG_PWM[nr]);
908 if (has_newer_autopwm(data)) {
909 if (has_new_tempmap(data))
910 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x38;
912 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
913 data->pwm_duty[nr] = it87_read_value(data,
914 IT87_REG_PWM_DUTY[nr]);
916 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
917 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
918 else /* Manual mode */
919 data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f;
922 if (has_old_autopwm(data)) {
925 for (i = 0; i < 5 ; i++)
926 data->auto_temp[nr][i] = it87_read_value(data,
927 IT87_REG_AUTO_TEMP(nr, i));
928 for (i = 0; i < 3 ; i++)
929 data->auto_pwm[nr][i] = it87_read_value(data,
930 IT87_REG_AUTO_PWM(nr, i));
931 } else if (has_newer_autopwm(data)) {
935 * 0: temperature hysteresis (base + 5)
936 * 1: fan off temperature (base + 0)
937 * 2: fan start temperature (base + 1)
938 * 3: fan max temperature (base + 2)
940 data->auto_temp[nr][0] =
941 it87_read_value(data, IT87_REG_AUTO_TEMP(nr, 5));
943 for (i = 0; i < 3 ; i++)
944 data->auto_temp[nr][i + 1] =
945 it87_read_value(data,
946 IT87_REG_AUTO_TEMP(nr, i));
948 * 0: start pwm value (base + 3)
949 * 1: pwm slope (base + 4, 1/8th pwm)
951 data->auto_pwm[nr][0] =
952 it87_read_value(data, IT87_REG_AUTO_TEMP(nr, 3));
953 data->auto_pwm[nr][1] =
954 it87_read_value(data, IT87_REG_AUTO_TEMP(nr, 4));
958 static struct it87_data *it87_update_device(struct device *dev)
960 struct it87_data *data = dev_get_drvdata(dev);
963 mutex_lock(&data->update_lock);
965 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) ||
969 * Cleared after each update, so reenable. Value
970 * returned by this read will be previous value
972 it87_write_value(data, IT87_REG_CONFIG,
973 it87_read_value(data, IT87_REG_CONFIG) | 0x40);
975 for (i = 0; i < NUM_VIN; i++) {
976 if (!(data->has_in & BIT(i)))
980 it87_read_value(data, IT87_REG_VIN[i]);
982 /* VBAT and AVCC don't have limit registers */
983 if (i >= NUM_VIN_LIMIT)
987 it87_read_value(data, IT87_REG_VIN_MIN(i));
989 it87_read_value(data, IT87_REG_VIN_MAX(i));
992 for (i = 0; i < NUM_FAN; i++) {
993 /* Skip disabled fans */
994 if (!(data->has_fan & BIT(i)))
998 it87_read_value(data, data->REG_FAN_MIN[i]);
999 data->fan[i][0] = it87_read_value(data,
1001 /* Add high byte if in 16-bit mode */
1002 if (has_16bit_fans(data)) {
1003 data->fan[i][0] |= it87_read_value(data,
1004 data->REG_FANX[i]) << 8;
1005 data->fan[i][1] |= it87_read_value(data,
1006 data->REG_FANX_MIN[i]) << 8;
1009 for (i = 0; i < NUM_TEMP; i++) {
1010 if (!(data->has_temp & BIT(i)))
1013 it87_read_value(data, IT87_REG_TEMP(i));
1015 if (i >= data->num_temp_limit)
1018 if (i < data->num_temp_offset)
1020 it87_read_value(data,
1021 data->REG_TEMP_OFFSET[i]);
1024 it87_read_value(data, data->REG_TEMP_LOW[i]);
1026 it87_read_value(data, data->REG_TEMP_HIGH[i]);
1029 /* Newer chips don't have clock dividers */
1030 if ((data->has_fan & 0x07) && !has_16bit_fans(data)) {
1031 i = it87_read_value(data, IT87_REG_FAN_DIV);
1032 data->fan_div[0] = i & 0x07;
1033 data->fan_div[1] = (i >> 3) & 0x07;
1034 data->fan_div[2] = (i & 0x40) ? 3 : 1;
1038 it87_read_value(data, IT87_REG_ALARM1) |
1039 (it87_read_value(data, IT87_REG_ALARM2) << 8) |
1040 (it87_read_value(data, IT87_REG_ALARM3) << 16);
1041 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
1043 data->fan_main_ctrl = it87_read_value(data,
1044 IT87_REG_FAN_MAIN_CTRL);
1045 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL);
1046 for (i = 0; i < NUM_PWM; i++) {
1047 if (!(data->has_pwm & BIT(i)))
1049 it87_update_pwm_ctrl(data, i);
1052 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
1053 data->extra = it87_read_value(data, IT87_REG_TEMP_EXTRA);
1055 * The IT8705F does not have VID capability.
1056 * The IT8718F and later don't use IT87_REG_VID for the
1059 if (data->type == it8712 || data->type == it8716) {
1060 data->vid = it87_read_value(data, IT87_REG_VID);
1062 * The older IT8712F revisions had only 5 VID pins,
1063 * but we assume it is always safe to read 6 bits.
1067 data->last_updated = jiffies;
1071 mutex_unlock(&data->update_lock);
1076 static ssize_t show_in(struct device *dev, struct device_attribute *attr,
1079 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1080 struct it87_data *data = it87_update_device(dev);
1081 int index = sattr->index;
1084 return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr][index]));
1087 static ssize_t set_in(struct device *dev, struct device_attribute *attr,
1088 const char *buf, size_t count)
1090 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1091 struct it87_data *data = dev_get_drvdata(dev);
1092 int index = sattr->index;
1096 if (kstrtoul(buf, 10, &val) < 0)
1099 mutex_lock(&data->update_lock);
1100 data->in[nr][index] = in_to_reg(data, nr, val);
1101 it87_write_value(data,
1102 index == 1 ? IT87_REG_VIN_MIN(nr)
1103 : IT87_REG_VIN_MAX(nr),
1104 data->in[nr][index]);
1105 mutex_unlock(&data->update_lock);
1109 static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0);
1110 static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_in, set_in,
1112 static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_in, set_in,
1115 static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 1, 0);
1116 static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_in, set_in,
1118 static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_in, set_in,
1121 static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 2, 0);
1122 static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_in, set_in,
1124 static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_in, set_in,
1127 static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 3, 0);
1128 static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_in, set_in,
1130 static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_in, set_in,
1133 static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 4, 0);
1134 static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_in, set_in,
1136 static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_in, set_in,
1139 static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 5, 0);
1140 static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_in, set_in,
1142 static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_in, set_in,
1145 static SENSOR_DEVICE_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 6, 0);
1146 static SENSOR_DEVICE_ATTR_2(in6_min, S_IRUGO | S_IWUSR, show_in, set_in,
1148 static SENSOR_DEVICE_ATTR_2(in6_max, S_IRUGO | S_IWUSR, show_in, set_in,
1151 static SENSOR_DEVICE_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 7, 0);
1152 static SENSOR_DEVICE_ATTR_2(in7_min, S_IRUGO | S_IWUSR, show_in, set_in,
1154 static SENSOR_DEVICE_ATTR_2(in7_max, S_IRUGO | S_IWUSR, show_in, set_in,
1157 static SENSOR_DEVICE_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 8, 0);
1158 static SENSOR_DEVICE_ATTR_2(in9_input, S_IRUGO, show_in, NULL, 9, 0);
1159 static SENSOR_DEVICE_ATTR_2(in10_input, S_IRUGO, show_in, NULL, 10, 0);
1160 static SENSOR_DEVICE_ATTR_2(in11_input, S_IRUGO, show_in, NULL, 11, 0);
1161 static SENSOR_DEVICE_ATTR_2(in12_input, S_IRUGO, show_in, NULL, 12, 0);
1163 /* Up to 6 temperatures */
1164 static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
1167 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1169 int index = sattr->index;
1170 struct it87_data *data = it87_update_device(dev);
1172 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr][index]));
1175 static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
1176 const char *buf, size_t count)
1178 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1180 int index = sattr->index;
1181 struct it87_data *data = dev_get_drvdata(dev);
1185 if (kstrtol(buf, 10, &val) < 0)
1188 mutex_lock(&data->update_lock);
1193 reg = data->REG_TEMP_LOW[nr];
1196 reg = data->REG_TEMP_HIGH[nr];
1199 regval = it87_read_value(data, IT87_REG_BEEP_ENABLE);
1200 if (!(regval & 0x80)) {
1202 it87_write_value(data, IT87_REG_BEEP_ENABLE, regval);
1205 reg = data->REG_TEMP_OFFSET[nr];
1209 data->temp[nr][index] = TEMP_TO_REG(val);
1210 it87_write_value(data, reg, data->temp[nr][index]);
1211 mutex_unlock(&data->update_lock);
1215 static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0);
1216 static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1218 static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1220 static SENSOR_DEVICE_ATTR_2(temp1_offset, S_IRUGO | S_IWUSR, show_temp,
1222 static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, 0);
1223 static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1225 static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1227 static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IRUGO | S_IWUSR, show_temp,
1229 static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 2, 0);
1230 static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1232 static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1234 static SENSOR_DEVICE_ATTR_2(temp3_offset, S_IRUGO | S_IWUSR, show_temp,
1236 static SENSOR_DEVICE_ATTR_2(temp4_input, S_IRUGO, show_temp, NULL, 3, 0);
1237 static SENSOR_DEVICE_ATTR_2(temp4_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1239 static SENSOR_DEVICE_ATTR_2(temp4_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1241 static SENSOR_DEVICE_ATTR_2(temp4_offset, S_IRUGO | S_IWUSR, show_temp,
1243 static SENSOR_DEVICE_ATTR_2(temp5_input, S_IRUGO, show_temp, NULL, 4, 0);
1244 static SENSOR_DEVICE_ATTR_2(temp5_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1246 static SENSOR_DEVICE_ATTR_2(temp5_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1248 static SENSOR_DEVICE_ATTR_2(temp5_offset, S_IRUGO | S_IWUSR, show_temp,
1250 static SENSOR_DEVICE_ATTR_2(temp6_input, S_IRUGO, show_temp, NULL, 5, 0);
1251 static SENSOR_DEVICE_ATTR_2(temp6_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1253 static SENSOR_DEVICE_ATTR_2(temp6_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1255 static SENSOR_DEVICE_ATTR_2(temp6_offset, S_IRUGO | S_IWUSR, show_temp,
1258 static int get_temp_type(struct it87_data *data, int index)
1263 if (has_bank_sel(data)) {
1264 int s1reg = IT87_REG_TEMP_SRC1[index/2] >> ((index % 2) * 4);
1267 src1 = (it87_read_value(data, s1reg) >> ((index % 2) * 4)) & 0x0f;
1268 src2 = it87_read_value(data, IT87_REG_TEMP_SRC2);
1270 switch (data->type) {
1278 if (index == 1 || index == 2 ||
1279 index == 4 || index == 5)
1283 if (index == 2 || index == 6)
1301 type = (src2 & BIT(index)) ? 6 : 5;
1304 type = (src2 & BIT(index)) ? 4 : 6;
1307 type = (src2 & BIT(index)) ? 5 : 0;
1320 reg = it87_read_value(data, IT87_REG_TEMP_ENABLE);
1321 extra = it87_read_value(data, IT87_REG_TEMP_EXTRA);
1323 if ((has_temp_peci(data, index) && (reg >> 6 == index + 1)) ||
1324 (has_temp_old_peci(data, index) && (extra & 0x80)))
1325 type = 6; /* Intel PECI */
1326 if (reg & BIT(index))
1327 type = 3; /* thermal diode */
1328 else if (reg & BIT(index + 3))
1329 type = 4; /* thermistor */
1334 static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr,
1337 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1338 struct it87_data *data = it87_update_device(dev);
1339 int type = get_temp_type(data, sensor_attr->index);
1341 return sprintf(buf, "%d\n", type);
1344 static ssize_t set_temp_type(struct device *dev, struct device_attribute *attr,
1345 const char *buf, size_t count)
1347 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1348 int nr = sensor_attr->index;
1350 struct it87_data *data = dev_get_drvdata(dev);
1354 if (kstrtol(buf, 10, &val) < 0)
1357 reg = it87_read_value(data, IT87_REG_TEMP_ENABLE);
1360 if (has_temp_peci(data, nr) && (reg >> 6 == nr + 1 || val == 6))
1362 extra = it87_read_value(data, IT87_REG_TEMP_EXTRA);
1363 if (has_temp_old_peci(data, nr) && ((extra & 0x80) || val == 6))
1365 if (val == 2) { /* backwards compatibility */
1367 "Sensor type 2 is deprecated, please use 4 instead\n");
1370 /* 3 = thermal diode; 4 = thermistor; 6 = Intel PECI; 0 = disabled */
1375 else if (has_temp_peci(data, nr) && val == 6)
1376 reg |= (nr + 1) << 6;
1377 else if (has_temp_old_peci(data, nr) && val == 6)
1382 mutex_lock(&data->update_lock);
1384 data->extra = extra;
1385 it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor);
1386 if (has_temp_old_peci(data, nr))
1387 it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra);
1388 data->valid = 0; /* Force cache refresh */
1389 mutex_unlock(&data->update_lock);
1393 static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR, show_temp_type,
1395 static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR, show_temp_type,
1397 static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR, show_temp_type,
1399 static SENSOR_DEVICE_ATTR(temp4_type, S_IRUGO | S_IWUSR, show_temp_type,
1401 static SENSOR_DEVICE_ATTR(temp5_type, S_IRUGO | S_IWUSR, show_temp_type,
1403 static SENSOR_DEVICE_ATTR(temp6_type, S_IRUGO | S_IWUSR, show_temp_type,
1408 static int pwm_mode(const struct it87_data *data, int nr)
1410 if (has_fanctl_onoff(data) && nr < 3 &&
1411 !(data->fan_main_ctrl & BIT(nr)))
1412 return 0; /* Full speed */
1413 if (data->pwm_ctrl[nr] & 0x80)
1414 return 2; /* Automatic mode */
1415 if ((!has_fanctl_onoff(data) || nr >= 3) &&
1416 data->pwm_duty[nr] == pwm_to_reg(data, 0xff))
1417 return 0; /* Full speed */
1419 return 1; /* Manual mode */
1422 static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
1425 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1427 int index = sattr->index;
1429 struct it87_data *data = it87_update_device(dev);
1431 speed = has_16bit_fans(data) ?
1432 FAN16_FROM_REG(data->fan[nr][index]) :
1433 FAN_FROM_REG(data->fan[nr][index],
1434 DIV_FROM_REG(data->fan_div[nr]));
1435 return sprintf(buf, "%d\n", speed);
1438 static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
1441 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1442 struct it87_data *data = it87_update_device(dev);
1443 int nr = sensor_attr->index;
1445 return sprintf(buf, "%lu\n", DIV_FROM_REG(data->fan_div[nr]));
1448 static ssize_t show_pwm_enable(struct device *dev,
1449 struct device_attribute *attr, char *buf)
1451 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1452 struct it87_data *data = it87_update_device(dev);
1453 int nr = sensor_attr->index;
1455 return sprintf(buf, "%d\n", pwm_mode(data, nr));
1458 static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
1461 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1462 struct it87_data *data = it87_update_device(dev);
1463 int nr = sensor_attr->index;
1465 return sprintf(buf, "%d\n",
1466 pwm_from_reg(data, data->pwm_duty[nr]));
1469 static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
1472 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1473 struct it87_data *data = it87_update_device(dev);
1474 int nr = sensor_attr->index;
1478 if (has_pwm_freq2(data) && nr == 1)
1479 index = (data->extra >> 4) & 0x07;
1481 index = (data->fan_ctl >> 4) & 0x07;
1483 freq = pwm_freq[index] / (has_newer_autopwm(data) ? 256 : 128);
1485 return sprintf(buf, "%u\n", freq);
1488 static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
1489 const char *buf, size_t count)
1491 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1493 int index = sattr->index;
1495 struct it87_data *data = dev_get_drvdata(dev);
1499 if (kstrtol(buf, 10, &val) < 0)
1502 mutex_lock(&data->update_lock);
1504 if (has_16bit_fans(data)) {
1505 data->fan[nr][index] = FAN16_TO_REG(val);
1506 it87_write_value(data, data->REG_FAN_MIN[nr],
1507 data->fan[nr][index] & 0xff);
1508 it87_write_value(data, data->REG_FANX_MIN[nr],
1509 data->fan[nr][index] >> 8);
1511 reg = it87_read_value(data, IT87_REG_FAN_DIV);
1514 data->fan_div[nr] = reg & 0x07;
1517 data->fan_div[nr] = (reg >> 3) & 0x07;
1520 data->fan_div[nr] = (reg & 0x40) ? 3 : 1;
1523 data->fan[nr][index] =
1524 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
1525 it87_write_value(data, data->REG_FAN_MIN[nr],
1526 data->fan[nr][index]);
1529 mutex_unlock(&data->update_lock);
1533 static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
1534 const char *buf, size_t count)
1536 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1537 struct it87_data *data = dev_get_drvdata(dev);
1538 int nr = sensor_attr->index;
1543 if (kstrtoul(buf, 10, &val) < 0)
1546 mutex_lock(&data->update_lock);
1547 old = it87_read_value(data, IT87_REG_FAN_DIV);
1549 /* Save fan min limit */
1550 min = FAN_FROM_REG(data->fan[nr][1], DIV_FROM_REG(data->fan_div[nr]));
1555 data->fan_div[nr] = DIV_TO_REG(val);
1559 data->fan_div[nr] = 1;
1561 data->fan_div[nr] = 3;
1564 val |= (data->fan_div[0] & 0x07);
1565 val |= (data->fan_div[1] & 0x07) << 3;
1566 if (data->fan_div[2] == 3)
1568 it87_write_value(data, IT87_REG_FAN_DIV, val);
1570 /* Restore fan min limit */
1571 data->fan[nr][1] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
1572 it87_write_value(data, data->REG_FAN_MIN[nr], data->fan[nr][1]);
1574 mutex_unlock(&data->update_lock);
1578 /* Returns 0 if OK, -EINVAL otherwise */
1579 static int check_trip_points(struct device *dev, int nr)
1581 const struct it87_data *data = dev_get_drvdata(dev);
1584 if (has_old_autopwm(data)) {
1585 for (i = 0; i < 3; i++) {
1586 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1])
1589 for (i = 0; i < 2; i++) {
1590 if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1])
1593 } else if (has_newer_autopwm(data)) {
1594 for (i = 1; i < 3; i++) {
1595 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1])
1602 "Inconsistent trip points, not switching to automatic mode\n");
1603 dev_err(dev, "Adjust the trip points and try again\n");
1608 static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr,
1609 const char *buf, size_t count)
1611 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1612 struct it87_data *data = dev_get_drvdata(dev);
1613 int nr = sensor_attr->index;
1616 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 2)
1619 /* Check trip points before switching to automatic mode */
1621 if (check_trip_points(dev, nr) < 0)
1625 mutex_lock(&data->update_lock);
1628 if (nr < 3 && has_fanctl_onoff(data)) {
1630 /* make sure the fan is on when in on/off mode */
1631 tmp = it87_read_value(data, IT87_REG_FAN_CTL);
1632 it87_write_value(data, IT87_REG_FAN_CTL, tmp | BIT(nr));
1633 /* set on/off mode */
1634 data->fan_main_ctrl &= ~BIT(nr);
1635 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
1636 data->fan_main_ctrl);
1640 /* No on/off mode, set maximum pwm value */
1641 data->pwm_duty[nr] = pwm_to_reg(data, 0xff);
1642 it87_write_value(data, IT87_REG_PWM_DUTY[nr],
1643 data->pwm_duty[nr]);
1644 /* and set manual mode */
1645 if (has_newer_autopwm(data)) {
1646 ctrl = (data->pwm_ctrl[nr] & 0x7c) |
1647 data->pwm_temp_map[nr];
1649 ctrl = data->pwm_duty[nr];
1651 data->pwm_ctrl[nr] = ctrl;
1652 it87_write_value(data, data->REG_PWM[nr], ctrl);
1657 if (has_newer_autopwm(data)) {
1658 ctrl = (data->pwm_ctrl[nr] & 0x7c) |
1659 data->pwm_temp_map[nr];
1663 ctrl = (val == 1 ? data->pwm_duty[nr] : 0x80);
1665 data->pwm_ctrl[nr] = ctrl;
1666 it87_write_value(data, data->REG_PWM[nr], ctrl);
1668 if (has_fanctl_onoff(data) && nr < 3) {
1669 /* set SmartGuardian mode */
1670 data->fan_main_ctrl |= BIT(nr);
1671 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
1672 data->fan_main_ctrl);
1676 mutex_unlock(&data->update_lock);
1680 static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1681 const char *buf, size_t count)
1683 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1684 struct it87_data *data = dev_get_drvdata(dev);
1685 int nr = sensor_attr->index;
1688 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
1691 mutex_lock(&data->update_lock);
1692 it87_update_pwm_ctrl(data, nr);
1693 if (has_newer_autopwm(data)) {
1695 * If we are in automatic mode, the PWM duty cycle register
1696 * is read-only so we can't write the value.
1698 if (data->pwm_ctrl[nr] & 0x80) {
1699 mutex_unlock(&data->update_lock);
1702 data->pwm_duty[nr] = pwm_to_reg(data, val);
1703 it87_write_value(data, IT87_REG_PWM_DUTY[nr],
1704 data->pwm_duty[nr]);
1706 data->pwm_duty[nr] = pwm_to_reg(data, val);
1708 * If we are in manual mode, write the duty cycle immediately;
1709 * otherwise, just store it for later use.
1711 if (!(data->pwm_ctrl[nr] & 0x80)) {
1712 data->pwm_ctrl[nr] = data->pwm_duty[nr];
1713 it87_write_value(data, data->REG_PWM[nr],
1714 data->pwm_ctrl[nr]);
1717 mutex_unlock(&data->update_lock);
1721 static ssize_t set_pwm_freq(struct device *dev, struct device_attribute *attr,
1722 const char *buf, size_t count)
1724 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1725 struct it87_data *data = dev_get_drvdata(dev);
1726 int nr = sensor_attr->index;
1730 if (kstrtoul(buf, 10, &val) < 0)
1733 val = clamp_val(val, 0, 1000000);
1734 val *= has_newer_autopwm(data) ? 256 : 128;
1736 /* Search for the nearest available frequency */
1737 for (i = 0; i < 7; i++) {
1738 if (val > (pwm_freq[i] + pwm_freq[i + 1]) / 2)
1742 mutex_lock(&data->update_lock);
1744 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f;
1745 data->fan_ctl |= i << 4;
1746 it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl);
1748 data->extra = it87_read_value(data, IT87_REG_TEMP_EXTRA) & 0x8f;
1749 data->extra |= i << 4;
1750 it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra);
1752 mutex_unlock(&data->update_lock);
1757 static ssize_t show_pwm_temp_map(struct device *dev,
1758 struct device_attribute *attr, char *buf)
1760 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1761 struct it87_data *data = it87_update_device(dev);
1762 int nr = sensor_attr->index;
1765 map = data->pwm_temp_map[nr];
1766 if (has_new_tempmap(data)) {
1769 map = 0; /* Should never happen */
1772 map = 0; /* Should never happen */
1773 if (nr >= 3) /* pwm channels 3..6 map to temp4..6 */
1777 return sprintf(buf, "%d\n", (int)BIT(map));
1780 static ssize_t set_pwm_temp_map(struct device *dev,
1781 struct device_attribute *attr, const char *buf,
1784 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1785 struct it87_data *data = dev_get_drvdata(dev);
1786 int nr = sensor_attr->index;
1790 if (kstrtol(buf, 10, &val) < 0)
1793 if (nr >= 3 && !has_new_tempmap(data))
1822 if (has_new_tempmap(data))
1824 else if (reg > 0x02)
1827 mutex_lock(&data->update_lock);
1828 it87_update_pwm_ctrl(data, nr);
1829 data->pwm_temp_map[nr] = reg;
1831 * If we are in automatic mode, write the temp mapping immediately;
1832 * otherwise, just store it for later use.
1834 if (data->pwm_ctrl[nr] & 0x80) {
1835 u8 mask = has_new_tempmap(data) ? 0xc7 : 0xfc;
1837 data->pwm_ctrl[nr] = (data->pwm_ctrl[nr] & mask) |
1838 data->pwm_temp_map[nr];
1839 it87_write_value(data, data->REG_PWM[nr], data->pwm_ctrl[nr]);
1841 mutex_unlock(&data->update_lock);
1845 static ssize_t show_auto_pwm(struct device *dev, struct device_attribute *attr,
1848 struct it87_data *data = it87_update_device(dev);
1849 struct sensor_device_attribute_2 *sensor_attr =
1850 to_sensor_dev_attr_2(attr);
1851 int nr = sensor_attr->nr;
1852 int point = sensor_attr->index;
1854 return sprintf(buf, "%d\n",
1855 pwm_from_reg(data, data->auto_pwm[nr][point]));
1858 static ssize_t set_auto_pwm(struct device *dev, struct device_attribute *attr,
1859 const char *buf, size_t count)
1861 struct it87_data *data = dev_get_drvdata(dev);
1862 struct sensor_device_attribute_2 *sensor_attr =
1863 to_sensor_dev_attr_2(attr);
1864 int nr = sensor_attr->nr;
1865 int point = sensor_attr->index;
1869 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
1872 mutex_lock(&data->update_lock);
1873 data->auto_pwm[nr][point] = pwm_to_reg(data, val);
1874 if (has_newer_autopwm(data))
1875 regaddr = IT87_REG_AUTO_TEMP(nr, 3);
1877 regaddr = IT87_REG_AUTO_PWM(nr, point);
1878 it87_write_value(data, regaddr, data->auto_pwm[nr][point]);
1879 mutex_unlock(&data->update_lock);
1883 static ssize_t show_auto_pwm_slope(struct device *dev,
1884 struct device_attribute *attr, char *buf)
1886 struct it87_data *data = it87_update_device(dev);
1887 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1888 int nr = sensor_attr->index;
1890 return sprintf(buf, "%d\n", data->auto_pwm[nr][1] & 0x7f);
1893 static ssize_t set_auto_pwm_slope(struct device *dev,
1894 struct device_attribute *attr,
1895 const char *buf, size_t count)
1897 struct it87_data *data = dev_get_drvdata(dev);
1898 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1899 int nr = sensor_attr->index;
1902 if (kstrtoul(buf, 10, &val) < 0 || val > 127)
1905 mutex_lock(&data->update_lock);
1906 data->auto_pwm[nr][1] = (data->auto_pwm[nr][1] & 0x80) | val;
1907 it87_write_value(data, IT87_REG_AUTO_TEMP(nr, 4),
1908 data->auto_pwm[nr][1]);
1909 mutex_unlock(&data->update_lock);
1913 static ssize_t show_auto_temp(struct device *dev, struct device_attribute *attr,
1916 struct it87_data *data = it87_update_device(dev);
1917 struct sensor_device_attribute_2 *sensor_attr =
1918 to_sensor_dev_attr_2(attr);
1919 int nr = sensor_attr->nr;
1920 int point = sensor_attr->index;
1923 if (has_old_autopwm(data) || point)
1924 reg = data->auto_temp[nr][point];
1926 reg = data->auto_temp[nr][1] - (data->auto_temp[nr][0] & 0x1f);
1928 return sprintf(buf, "%d\n", TEMP_FROM_REG(reg));
1931 static ssize_t set_auto_temp(struct device *dev, struct device_attribute *attr,
1932 const char *buf, size_t count)
1934 struct it87_data *data = dev_get_drvdata(dev);
1935 struct sensor_device_attribute_2 *sensor_attr =
1936 to_sensor_dev_attr_2(attr);
1937 int nr = sensor_attr->nr;
1938 int point = sensor_attr->index;
1942 if (kstrtol(buf, 10, &val) < 0 || val < -128000 || val > 127000)
1945 mutex_lock(&data->update_lock);
1946 if (has_newer_autopwm(data) && !point) {
1947 reg = data->auto_temp[nr][1] - TEMP_TO_REG(val);
1948 reg = clamp_val(reg, 0, 0x1f) | (data->auto_temp[nr][0] & 0xe0);
1949 data->auto_temp[nr][0] = reg;
1950 it87_write_value(data, IT87_REG_AUTO_TEMP(nr, 5), reg);
1952 reg = TEMP_TO_REG(val);
1953 data->auto_temp[nr][point] = reg;
1954 if (has_newer_autopwm(data))
1956 it87_write_value(data, IT87_REG_AUTO_TEMP(nr, point), reg);
1958 mutex_unlock(&data->update_lock);
1962 static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0);
1963 static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1965 static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, show_fan_div,
1968 static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 1, 0);
1969 static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1971 static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, show_fan_div,
1974 static SENSOR_DEVICE_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 2, 0);
1975 static SENSOR_DEVICE_ATTR_2(fan3_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1977 static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO | S_IWUSR, show_fan_div,
1980 static SENSOR_DEVICE_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 3, 0);
1981 static SENSOR_DEVICE_ATTR_2(fan4_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1984 static SENSOR_DEVICE_ATTR_2(fan5_input, S_IRUGO, show_fan, NULL, 4, 0);
1985 static SENSOR_DEVICE_ATTR_2(fan5_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1988 static SENSOR_DEVICE_ATTR_2(fan6_input, S_IRUGO, show_fan, NULL, 5, 0);
1989 static SENSOR_DEVICE_ATTR_2(fan6_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1992 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
1993 show_pwm_enable, set_pwm_enable, 0);
1994 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0);
1995 static SENSOR_DEVICE_ATTR(pwm1_freq, S_IRUGO | S_IWUSR, show_pwm_freq,
1997 static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IRUGO,
1998 show_pwm_temp_map, set_pwm_temp_map, 0);
1999 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR,
2000 show_auto_pwm, set_auto_pwm, 0, 0);
2001 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR,
2002 show_auto_pwm, set_auto_pwm, 0, 1);
2003 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR,
2004 show_auto_pwm, set_auto_pwm, 0, 2);
2005 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO,
2006 show_auto_pwm, NULL, 0, 3);
2007 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR,
2008 show_auto_temp, set_auto_temp, 0, 1);
2009 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
2010 show_auto_temp, set_auto_temp, 0, 0);
2011 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR,
2012 show_auto_temp, set_auto_temp, 0, 2);
2013 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR,
2014 show_auto_temp, set_auto_temp, 0, 3);
2015 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR,
2016 show_auto_temp, set_auto_temp, 0, 4);
2017 static SENSOR_DEVICE_ATTR_2(pwm1_auto_start, S_IRUGO | S_IWUSR,
2018 show_auto_pwm, set_auto_pwm, 0, 0);
2019 static SENSOR_DEVICE_ATTR(pwm1_auto_slope, S_IRUGO | S_IWUSR,
2020 show_auto_pwm_slope, set_auto_pwm_slope, 0);
2022 static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR,
2023 show_pwm_enable, set_pwm_enable, 1);
2024 static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 1);
2025 static SENSOR_DEVICE_ATTR(pwm2_freq, S_IRUGO, show_pwm_freq, set_pwm_freq, 1);
2026 static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IRUGO,
2027 show_pwm_temp_map, set_pwm_temp_map, 1);
2028 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR,
2029 show_auto_pwm, set_auto_pwm, 1, 0);
2030 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO | S_IWUSR,
2031 show_auto_pwm, set_auto_pwm, 1, 1);
2032 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO | S_IWUSR,
2033 show_auto_pwm, set_auto_pwm, 1, 2);
2034 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO,
2035 show_auto_pwm, NULL, 1, 3);
2036 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR,
2037 show_auto_temp, set_auto_temp, 1, 1);
2038 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
2039 show_auto_temp, set_auto_temp, 1, 0);
2040 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR,
2041 show_auto_temp, set_auto_temp, 1, 2);
2042 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR,
2043 show_auto_temp, set_auto_temp, 1, 3);
2044 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_temp, S_IRUGO | S_IWUSR,
2045 show_auto_temp, set_auto_temp, 1, 4);
2046 static SENSOR_DEVICE_ATTR_2(pwm2_auto_start, S_IRUGO | S_IWUSR,
2047 show_auto_pwm, set_auto_pwm, 1, 0);
2048 static SENSOR_DEVICE_ATTR(pwm2_auto_slope, S_IRUGO | S_IWUSR,
2049 show_auto_pwm_slope, set_auto_pwm_slope, 1);
2051 static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR,
2052 show_pwm_enable, set_pwm_enable, 2);
2053 static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 2);
2054 static SENSOR_DEVICE_ATTR(pwm3_freq, S_IRUGO, show_pwm_freq, NULL, 2);
2055 static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IRUGO,
2056 show_pwm_temp_map, set_pwm_temp_map, 2);
2057 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO | S_IWUSR,
2058 show_auto_pwm, set_auto_pwm, 2, 0);
2059 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR,
2060 show_auto_pwm, set_auto_pwm, 2, 1);
2061 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO | S_IWUSR,
2062 show_auto_pwm, set_auto_pwm, 2, 2);
2063 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO,
2064 show_auto_pwm, NULL, 2, 3);
2065 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp, S_IRUGO | S_IWUSR,
2066 show_auto_temp, set_auto_temp, 2, 1);
2067 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
2068 show_auto_temp, set_auto_temp, 2, 0);
2069 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_temp, S_IRUGO | S_IWUSR,
2070 show_auto_temp, set_auto_temp, 2, 2);
2071 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_temp, S_IRUGO | S_IWUSR,
2072 show_auto_temp, set_auto_temp, 2, 3);
2073 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_temp, S_IRUGO | S_IWUSR,
2074 show_auto_temp, set_auto_temp, 2, 4);
2075 static SENSOR_DEVICE_ATTR_2(pwm3_auto_start, S_IRUGO | S_IWUSR,
2076 show_auto_pwm, set_auto_pwm, 2, 0);
2077 static SENSOR_DEVICE_ATTR(pwm3_auto_slope, S_IRUGO | S_IWUSR,
2078 show_auto_pwm_slope, set_auto_pwm_slope, 2);
2080 static SENSOR_DEVICE_ATTR(pwm4_enable, S_IRUGO | S_IWUSR,
2081 show_pwm_enable, set_pwm_enable, 3);
2082 static SENSOR_DEVICE_ATTR(pwm4, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 3);
2083 static SENSOR_DEVICE_ATTR(pwm4_freq, S_IRUGO, show_pwm_freq, NULL, 3);
2084 static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IRUGO,
2085 show_pwm_temp_map, set_pwm_temp_map, 3);
2086 static SENSOR_DEVICE_ATTR_2(pwm4_auto_point1_temp, S_IRUGO | S_IWUSR,
2087 show_auto_temp, set_auto_temp, 2, 1);
2088 static SENSOR_DEVICE_ATTR_2(pwm4_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
2089 show_auto_temp, set_auto_temp, 2, 0);
2090 static SENSOR_DEVICE_ATTR_2(pwm4_auto_point2_temp, S_IRUGO | S_IWUSR,
2091 show_auto_temp, set_auto_temp, 2, 2);
2092 static SENSOR_DEVICE_ATTR_2(pwm4_auto_point3_temp, S_IRUGO | S_IWUSR,
2093 show_auto_temp, set_auto_temp, 2, 3);
2094 static SENSOR_DEVICE_ATTR_2(pwm4_auto_start, S_IRUGO | S_IWUSR,
2095 show_auto_pwm, set_auto_pwm, 3, 0);
2096 static SENSOR_DEVICE_ATTR(pwm4_auto_slope, S_IRUGO | S_IWUSR,
2097 show_auto_pwm_slope, set_auto_pwm_slope, 3);
2099 static SENSOR_DEVICE_ATTR(pwm5_enable, S_IRUGO | S_IWUSR,
2100 show_pwm_enable, set_pwm_enable, 4);
2101 static SENSOR_DEVICE_ATTR(pwm5, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 4);
2102 static SENSOR_DEVICE_ATTR(pwm5_freq, S_IRUGO, show_pwm_freq, NULL, 4);
2103 static SENSOR_DEVICE_ATTR(pwm5_auto_channels_temp, S_IRUGO,
2104 show_pwm_temp_map, set_pwm_temp_map, 4);
2105 static SENSOR_DEVICE_ATTR_2(pwm5_auto_point1_temp, S_IRUGO | S_IWUSR,
2106 show_auto_temp, set_auto_temp, 2, 1);
2107 static SENSOR_DEVICE_ATTR_2(pwm5_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
2108 show_auto_temp, set_auto_temp, 2, 0);
2109 static SENSOR_DEVICE_ATTR_2(pwm5_auto_point2_temp, S_IRUGO | S_IWUSR,
2110 show_auto_temp, set_auto_temp, 2, 2);
2111 static SENSOR_DEVICE_ATTR_2(pwm5_auto_point3_temp, S_IRUGO | S_IWUSR,
2112 show_auto_temp, set_auto_temp, 2, 3);
2113 static SENSOR_DEVICE_ATTR_2(pwm5_auto_start, S_IRUGO | S_IWUSR,
2114 show_auto_pwm, set_auto_pwm, 4, 0);
2115 static SENSOR_DEVICE_ATTR(pwm5_auto_slope, S_IRUGO | S_IWUSR,
2116 show_auto_pwm_slope, set_auto_pwm_slope, 4);
2118 static SENSOR_DEVICE_ATTR(pwm6_enable, S_IRUGO | S_IWUSR,
2119 show_pwm_enable, set_pwm_enable, 5);
2120 static SENSOR_DEVICE_ATTR(pwm6, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 5);
2121 static SENSOR_DEVICE_ATTR(pwm6_freq, S_IRUGO, show_pwm_freq, NULL, 5);
2122 static SENSOR_DEVICE_ATTR(pwm6_auto_channels_temp, S_IRUGO,
2123 show_pwm_temp_map, set_pwm_temp_map, 5);
2124 static SENSOR_DEVICE_ATTR_2(pwm6_auto_point1_temp, S_IRUGO | S_IWUSR,
2125 show_auto_temp, set_auto_temp, 2, 1);
2126 static SENSOR_DEVICE_ATTR_2(pwm6_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
2127 show_auto_temp, set_auto_temp, 2, 0);
2128 static SENSOR_DEVICE_ATTR_2(pwm6_auto_point2_temp, S_IRUGO | S_IWUSR,
2129 show_auto_temp, set_auto_temp, 2, 2);
2130 static SENSOR_DEVICE_ATTR_2(pwm6_auto_point3_temp, S_IRUGO | S_IWUSR,
2131 show_auto_temp, set_auto_temp, 2, 3);
2132 static SENSOR_DEVICE_ATTR_2(pwm6_auto_start, S_IRUGO | S_IWUSR,
2133 show_auto_pwm, set_auto_pwm, 5, 0);
2134 static SENSOR_DEVICE_ATTR(pwm6_auto_slope, S_IRUGO | S_IWUSR,
2135 show_auto_pwm_slope, set_auto_pwm_slope, 5);
2138 static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
2141 struct it87_data *data = it87_update_device(dev);
2143 return sprintf(buf, "%u\n", data->alarms);
2145 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
2147 static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
2150 struct it87_data *data = it87_update_device(dev);
2151 int bitnr = to_sensor_dev_attr(attr)->index;
2153 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
2156 static ssize_t clear_intrusion(struct device *dev,
2157 struct device_attribute *attr, const char *buf,
2160 struct it87_data *data = dev_get_drvdata(dev);
2164 if (kstrtol(buf, 10, &val) < 0 || val != 0)
2167 mutex_lock(&data->update_lock);
2168 config = it87_read_value(data, IT87_REG_CONFIG);
2173 it87_write_value(data, IT87_REG_CONFIG, config);
2174 /* Invalidate cache to force re-read */
2177 mutex_unlock(&data->update_lock);
2182 static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8);
2183 static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9);
2184 static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10);
2185 static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11);
2186 static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12);
2187 static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13);
2188 static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14);
2189 static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15);
2190 static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0);
2191 static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1);
2192 static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2);
2193 static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3);
2194 static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6);
2195 static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_alarm, NULL, 7);
2196 static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16);
2197 static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17);
2198 static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18);
2199 static SENSOR_DEVICE_ATTR(temp4_alarm, S_IRUGO, show_alarm, NULL, 19);
2200 static SENSOR_DEVICE_ATTR(temp5_alarm, S_IRUGO, show_alarm, NULL, 20);
2201 static SENSOR_DEVICE_ATTR(temp6_alarm, S_IRUGO, show_alarm, NULL, 21);
2202 static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR,
2203 show_alarm, clear_intrusion, 4);
2205 static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
2208 struct it87_data *data = it87_update_device(dev);
2209 int bitnr = to_sensor_dev_attr(attr)->index;
2211 return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1);
2214 static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
2215 const char *buf, size_t count)
2217 int bitnr = to_sensor_dev_attr(attr)->index;
2218 struct it87_data *data = dev_get_drvdata(dev);
2221 if (kstrtol(buf, 10, &val) < 0 || (val != 0 && val != 1))
2224 mutex_lock(&data->update_lock);
2225 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
2227 data->beeps |= BIT(bitnr);
2229 data->beeps &= ~BIT(bitnr);
2230 it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps);
2231 mutex_unlock(&data->update_lock);
2235 static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
2236 show_beep, set_beep, 1);
2237 static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO, show_beep, NULL, 1);
2238 static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO, show_beep, NULL, 1);
2239 static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO, show_beep, NULL, 1);
2240 static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO, show_beep, NULL, 1);
2241 static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO, show_beep, NULL, 1);
2242 static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO, show_beep, NULL, 1);
2243 static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO, show_beep, NULL, 1);
2244 /* fanX_beep writability is set later */
2245 static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO, show_beep, set_beep, 0);
2246 static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0);
2247 static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0);
2248 static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0);
2249 static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0);
2250 static SENSOR_DEVICE_ATTR(fan6_beep, S_IRUGO, show_beep, set_beep, 0);
2251 static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
2252 show_beep, set_beep, 2);
2253 static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2);
2254 static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2);
2255 static SENSOR_DEVICE_ATTR(temp4_beep, S_IRUGO, show_beep, NULL, 2);
2256 static SENSOR_DEVICE_ATTR(temp5_beep, S_IRUGO, show_beep, NULL, 2);
2257 static SENSOR_DEVICE_ATTR(temp6_beep, S_IRUGO, show_beep, NULL, 2);
2259 static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
2262 struct it87_data *data = dev_get_drvdata(dev);
2264 return sprintf(buf, "%u\n", data->vrm);
2267 static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
2268 const char *buf, size_t count)
2270 struct it87_data *data = dev_get_drvdata(dev);
2273 if (kstrtoul(buf, 10, &val) < 0)
2280 static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
2282 static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
2285 struct it87_data *data = it87_update_device(dev);
2287 return sprintf(buf, "%ld\n", (long)vid_from_reg(data->vid, data->vrm));
2289 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
2291 static ssize_t show_label(struct device *dev, struct device_attribute *attr,
2294 static const char * const labels[] = {
2300 static const char * const labels_it8721[] = {
2306 struct it87_data *data = dev_get_drvdata(dev);
2307 int nr = to_sensor_dev_attr(attr)->index;
2310 if (has_vin3_5v(data) && nr == 0)
2312 else if (has_12mv_adc(data) || has_10_9mv_adc(data) ||
2314 label = labels_it8721[nr];
2318 return sprintf(buf, "%s\n", label);
2320 static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0);
2321 static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1);
2322 static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 2);
2324 static SENSOR_DEVICE_ATTR(in9_label, S_IRUGO, show_label, NULL, 3);
2326 static umode_t it87_in_is_visible(struct kobject *kobj,
2327 struct attribute *attr, int index)
2329 struct device *dev = container_of(kobj, struct device, kobj);
2330 struct it87_data *data = dev_get_drvdata(dev);
2331 int i = index / 5; /* voltage index */
2332 int a = index % 5; /* attribute index */
2334 if (index >= 40) { /* in8 and higher only have input attributes */
2339 if (!(data->has_in & BIT(i)))
2342 if (a == 4 && !data->has_beep)
2348 static struct attribute *it87_attributes_in[] = {
2349 &sensor_dev_attr_in0_input.dev_attr.attr,
2350 &sensor_dev_attr_in0_min.dev_attr.attr,
2351 &sensor_dev_attr_in0_max.dev_attr.attr,
2352 &sensor_dev_attr_in0_alarm.dev_attr.attr,
2353 &sensor_dev_attr_in0_beep.dev_attr.attr, /* 4 */
2355 &sensor_dev_attr_in1_input.dev_attr.attr,
2356 &sensor_dev_attr_in1_min.dev_attr.attr,
2357 &sensor_dev_attr_in1_max.dev_attr.attr,
2358 &sensor_dev_attr_in1_alarm.dev_attr.attr,
2359 &sensor_dev_attr_in1_beep.dev_attr.attr, /* 9 */
2361 &sensor_dev_attr_in2_input.dev_attr.attr,
2362 &sensor_dev_attr_in2_min.dev_attr.attr,
2363 &sensor_dev_attr_in2_max.dev_attr.attr,
2364 &sensor_dev_attr_in2_alarm.dev_attr.attr,
2365 &sensor_dev_attr_in2_beep.dev_attr.attr, /* 14 */
2367 &sensor_dev_attr_in3_input.dev_attr.attr,
2368 &sensor_dev_attr_in3_min.dev_attr.attr,
2369 &sensor_dev_attr_in3_max.dev_attr.attr,
2370 &sensor_dev_attr_in3_alarm.dev_attr.attr,
2371 &sensor_dev_attr_in3_beep.dev_attr.attr, /* 19 */
2373 &sensor_dev_attr_in4_input.dev_attr.attr,
2374 &sensor_dev_attr_in4_min.dev_attr.attr,
2375 &sensor_dev_attr_in4_max.dev_attr.attr,
2376 &sensor_dev_attr_in4_alarm.dev_attr.attr,
2377 &sensor_dev_attr_in4_beep.dev_attr.attr, /* 24 */
2379 &sensor_dev_attr_in5_input.dev_attr.attr,
2380 &sensor_dev_attr_in5_min.dev_attr.attr,
2381 &sensor_dev_attr_in5_max.dev_attr.attr,
2382 &sensor_dev_attr_in5_alarm.dev_attr.attr,
2383 &sensor_dev_attr_in5_beep.dev_attr.attr, /* 29 */
2385 &sensor_dev_attr_in6_input.dev_attr.attr,
2386 &sensor_dev_attr_in6_min.dev_attr.attr,
2387 &sensor_dev_attr_in6_max.dev_attr.attr,
2388 &sensor_dev_attr_in6_alarm.dev_attr.attr,
2389 &sensor_dev_attr_in6_beep.dev_attr.attr, /* 34 */
2391 &sensor_dev_attr_in7_input.dev_attr.attr,
2392 &sensor_dev_attr_in7_min.dev_attr.attr,
2393 &sensor_dev_attr_in7_max.dev_attr.attr,
2394 &sensor_dev_attr_in7_alarm.dev_attr.attr,
2395 &sensor_dev_attr_in7_beep.dev_attr.attr, /* 39 */
2397 &sensor_dev_attr_in8_input.dev_attr.attr, /* 40 */
2398 &sensor_dev_attr_in9_input.dev_attr.attr, /* 41 */
2399 &sensor_dev_attr_in10_input.dev_attr.attr, /* 42 */
2400 &sensor_dev_attr_in11_input.dev_attr.attr, /* 43 */
2401 &sensor_dev_attr_in12_input.dev_attr.attr, /* 44 */
2405 static const struct attribute_group it87_group_in = {
2406 .attrs = it87_attributes_in,
2407 .is_visible = it87_in_is_visible,
2410 static umode_t it87_temp_is_visible(struct kobject *kobj,
2411 struct attribute *attr, int index)
2413 struct device *dev = container_of(kobj, struct device, kobj);
2414 struct it87_data *data = dev_get_drvdata(dev);
2415 int i = index / 7; /* temperature index */
2416 int a = index % 7; /* attribute index */
2418 if (!(data->has_temp & BIT(i)))
2421 if (a && i >= data->num_temp_limit)
2425 int type = get_temp_type(data, i);
2429 if (has_bank_sel(data))
2434 if (a == 5 && i >= data->num_temp_offset)
2437 if (a == 6 && !data->has_beep)
2443 static struct attribute *it87_attributes_temp[] = {
2444 &sensor_dev_attr_temp1_input.dev_attr.attr,
2445 &sensor_dev_attr_temp1_max.dev_attr.attr,
2446 &sensor_dev_attr_temp1_min.dev_attr.attr,
2447 &sensor_dev_attr_temp1_type.dev_attr.attr, /* 3 */
2448 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
2449 &sensor_dev_attr_temp1_offset.dev_attr.attr, /* 5 */
2450 &sensor_dev_attr_temp1_beep.dev_attr.attr, /* 6 */
2452 &sensor_dev_attr_temp2_input.dev_attr.attr, /* 7 */
2453 &sensor_dev_attr_temp2_max.dev_attr.attr,
2454 &sensor_dev_attr_temp2_min.dev_attr.attr,
2455 &sensor_dev_attr_temp2_type.dev_attr.attr,
2456 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
2457 &sensor_dev_attr_temp2_offset.dev_attr.attr,
2458 &sensor_dev_attr_temp2_beep.dev_attr.attr,
2460 &sensor_dev_attr_temp3_input.dev_attr.attr, /* 14 */
2461 &sensor_dev_attr_temp3_max.dev_attr.attr,
2462 &sensor_dev_attr_temp3_min.dev_attr.attr,
2463 &sensor_dev_attr_temp3_type.dev_attr.attr,
2464 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
2465 &sensor_dev_attr_temp3_offset.dev_attr.attr,
2466 &sensor_dev_attr_temp3_beep.dev_attr.attr,
2468 &sensor_dev_attr_temp4_input.dev_attr.attr, /* 21 */
2469 &sensor_dev_attr_temp4_max.dev_attr.attr,
2470 &sensor_dev_attr_temp4_min.dev_attr.attr,
2471 &sensor_dev_attr_temp4_type.dev_attr.attr,
2472 &sensor_dev_attr_temp4_alarm.dev_attr.attr,
2473 &sensor_dev_attr_temp4_offset.dev_attr.attr,
2474 &sensor_dev_attr_temp4_beep.dev_attr.attr,
2476 &sensor_dev_attr_temp5_input.dev_attr.attr,
2477 &sensor_dev_attr_temp5_max.dev_attr.attr,
2478 &sensor_dev_attr_temp5_min.dev_attr.attr,
2479 &sensor_dev_attr_temp5_type.dev_attr.attr,
2480 &sensor_dev_attr_temp5_alarm.dev_attr.attr,
2481 &sensor_dev_attr_temp5_offset.dev_attr.attr,
2482 &sensor_dev_attr_temp5_beep.dev_attr.attr,
2484 &sensor_dev_attr_temp6_input.dev_attr.attr,
2485 &sensor_dev_attr_temp6_max.dev_attr.attr,
2486 &sensor_dev_attr_temp6_min.dev_attr.attr,
2487 &sensor_dev_attr_temp6_type.dev_attr.attr,
2488 &sensor_dev_attr_temp6_alarm.dev_attr.attr,
2489 &sensor_dev_attr_temp6_offset.dev_attr.attr,
2490 &sensor_dev_attr_temp6_beep.dev_attr.attr,
2494 static const struct attribute_group it87_group_temp = {
2495 .attrs = it87_attributes_temp,
2496 .is_visible = it87_temp_is_visible,
2499 static umode_t it87_is_visible(struct kobject *kobj,
2500 struct attribute *attr, int index)
2502 struct device *dev = container_of(kobj, struct device, kobj);
2503 struct it87_data *data = dev_get_drvdata(dev);
2505 if ((index == 2 || index == 3) && !data->has_vid)
2508 if (index > 3 && !(data->in_internal & BIT(index - 4)))
2514 static struct attribute *it87_attributes[] = {
2515 &dev_attr_alarms.attr,
2516 &sensor_dev_attr_intrusion0_alarm.dev_attr.attr,
2517 &dev_attr_vrm.attr, /* 2 */
2518 &dev_attr_cpu0_vid.attr, /* 3 */
2519 &sensor_dev_attr_in3_label.dev_attr.attr, /* 4 .. 7 */
2520 &sensor_dev_attr_in7_label.dev_attr.attr,
2521 &sensor_dev_attr_in8_label.dev_attr.attr,
2522 &sensor_dev_attr_in9_label.dev_attr.attr,
2526 static const struct attribute_group it87_group = {
2527 .attrs = it87_attributes,
2528 .is_visible = it87_is_visible,
2531 static umode_t it87_fan_is_visible(struct kobject *kobj,
2532 struct attribute *attr, int index)
2534 struct device *dev = container_of(kobj, struct device, kobj);
2535 struct it87_data *data = dev_get_drvdata(dev);
2536 int i = index / 5; /* fan index */
2537 int a = index % 5; /* attribute index */
2539 if (index >= 15) { /* fan 4..6 don't have divisor attributes */
2540 i = (index - 15) / 4 + 3;
2541 a = (index - 15) % 4;
2544 if (!(data->has_fan & BIT(i)))
2547 if (a == 3) { /* beep */
2548 if (!data->has_beep)
2550 /* first fan beep attribute is writable */
2551 if (i == __ffs(data->has_fan))
2552 return attr->mode | S_IWUSR;
2555 if (a == 4 && has_16bit_fans(data)) /* divisor */
2561 static struct attribute *it87_attributes_fan[] = {
2562 &sensor_dev_attr_fan1_input.dev_attr.attr,
2563 &sensor_dev_attr_fan1_min.dev_attr.attr,
2564 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
2565 &sensor_dev_attr_fan1_beep.dev_attr.attr, /* 3 */
2566 &sensor_dev_attr_fan1_div.dev_attr.attr, /* 4 */
2568 &sensor_dev_attr_fan2_input.dev_attr.attr,
2569 &sensor_dev_attr_fan2_min.dev_attr.attr,
2570 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
2571 &sensor_dev_attr_fan2_beep.dev_attr.attr,
2572 &sensor_dev_attr_fan2_div.dev_attr.attr, /* 9 */
2574 &sensor_dev_attr_fan3_input.dev_attr.attr,
2575 &sensor_dev_attr_fan3_min.dev_attr.attr,
2576 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
2577 &sensor_dev_attr_fan3_beep.dev_attr.attr,
2578 &sensor_dev_attr_fan3_div.dev_attr.attr, /* 14 */
2580 &sensor_dev_attr_fan4_input.dev_attr.attr, /* 15 */
2581 &sensor_dev_attr_fan4_min.dev_attr.attr,
2582 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
2583 &sensor_dev_attr_fan4_beep.dev_attr.attr,
2585 &sensor_dev_attr_fan5_input.dev_attr.attr, /* 19 */
2586 &sensor_dev_attr_fan5_min.dev_attr.attr,
2587 &sensor_dev_attr_fan5_alarm.dev_attr.attr,
2588 &sensor_dev_attr_fan5_beep.dev_attr.attr,
2590 &sensor_dev_attr_fan6_input.dev_attr.attr, /* 23 */
2591 &sensor_dev_attr_fan6_min.dev_attr.attr,
2592 &sensor_dev_attr_fan6_alarm.dev_attr.attr,
2593 &sensor_dev_attr_fan6_beep.dev_attr.attr,
2597 static const struct attribute_group it87_group_fan = {
2598 .attrs = it87_attributes_fan,
2599 .is_visible = it87_fan_is_visible,
2602 static umode_t it87_pwm_is_visible(struct kobject *kobj,
2603 struct attribute *attr, int index)
2605 struct device *dev = container_of(kobj, struct device, kobj);
2606 struct it87_data *data = dev_get_drvdata(dev);
2607 int i = index / 4; /* pwm index */
2608 int a = index % 4; /* attribute index */
2610 if (!(data->has_pwm & BIT(i)))
2613 /* pwmX_auto_channels_temp is only writable if auto pwm is supported */
2614 if (a == 3 && (has_old_autopwm(data) || has_newer_autopwm(data)))
2615 return attr->mode | S_IWUSR;
2617 /* pwm2_freq is writable if there are two pwm frequency selects */
2618 if (has_pwm_freq2(data) && i == 1 && a == 2)
2619 return attr->mode | S_IWUSR;
2624 static struct attribute *it87_attributes_pwm[] = {
2625 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
2626 &sensor_dev_attr_pwm1.dev_attr.attr,
2627 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
2628 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
2630 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
2631 &sensor_dev_attr_pwm2.dev_attr.attr,
2632 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
2633 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
2635 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
2636 &sensor_dev_attr_pwm3.dev_attr.attr,
2637 &sensor_dev_attr_pwm3_freq.dev_attr.attr,
2638 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
2640 &sensor_dev_attr_pwm4_enable.dev_attr.attr,
2641 &sensor_dev_attr_pwm4.dev_attr.attr,
2642 &sensor_dev_attr_pwm4_freq.dev_attr.attr,
2643 &sensor_dev_attr_pwm4_auto_channels_temp.dev_attr.attr,
2645 &sensor_dev_attr_pwm5_enable.dev_attr.attr,
2646 &sensor_dev_attr_pwm5.dev_attr.attr,
2647 &sensor_dev_attr_pwm5_freq.dev_attr.attr,
2648 &sensor_dev_attr_pwm5_auto_channels_temp.dev_attr.attr,
2650 &sensor_dev_attr_pwm6_enable.dev_attr.attr,
2651 &sensor_dev_attr_pwm6.dev_attr.attr,
2652 &sensor_dev_attr_pwm6_freq.dev_attr.attr,
2653 &sensor_dev_attr_pwm6_auto_channels_temp.dev_attr.attr,
2658 static const struct attribute_group it87_group_pwm = {
2659 .attrs = it87_attributes_pwm,
2660 .is_visible = it87_pwm_is_visible,
2663 static umode_t it87_auto_pwm_is_visible(struct kobject *kobj,
2664 struct attribute *attr, int index)
2666 struct device *dev = container_of(kobj, struct device, kobj);
2667 struct it87_data *data = dev_get_drvdata(dev);
2668 int i = index / 11; /* pwm index */
2669 int a = index % 11; /* attribute index */
2671 if (index >= 33) { /* pwm 4..6 */
2672 i = (index - 33) / 6 + 3;
2673 a = (index - 33) % 6 + 4;
2676 if (!(data->has_pwm & BIT(i)))
2679 if (has_newer_autopwm(data)) {
2680 if (a < 4) /* no auto point pwm */
2682 if (a == 8) /* no auto_point4 */
2685 if (has_old_autopwm(data)) {
2686 if (a >= 9) /* no pwm_auto_start, pwm_auto_slope */
2693 static struct attribute *it87_attributes_auto_pwm[] = {
2694 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
2695 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
2696 &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr,
2697 &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr,
2698 &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
2699 &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr,
2700 &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr,
2701 &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr,
2702 &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr,
2703 &sensor_dev_attr_pwm1_auto_start.dev_attr.attr,
2704 &sensor_dev_attr_pwm1_auto_slope.dev_attr.attr,
2706 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr, /* 11 */
2707 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
2708 &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr,
2709 &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr,
2710 &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr,
2711 &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr,
2712 &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr,
2713 &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr,
2714 &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr,
2715 &sensor_dev_attr_pwm2_auto_start.dev_attr.attr,
2716 &sensor_dev_attr_pwm2_auto_slope.dev_attr.attr,
2718 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr, /* 22 */
2719 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
2720 &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr,
2721 &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr,
2722 &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr,
2723 &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr,
2724 &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr,
2725 &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr,
2726 &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr,
2727 &sensor_dev_attr_pwm3_auto_start.dev_attr.attr,
2728 &sensor_dev_attr_pwm3_auto_slope.dev_attr.attr,
2730 &sensor_dev_attr_pwm4_auto_point1_temp.dev_attr.attr, /* 33 */
2731 &sensor_dev_attr_pwm4_auto_point1_temp_hyst.dev_attr.attr,
2732 &sensor_dev_attr_pwm4_auto_point2_temp.dev_attr.attr,
2733 &sensor_dev_attr_pwm4_auto_point3_temp.dev_attr.attr,
2734 &sensor_dev_attr_pwm4_auto_start.dev_attr.attr,
2735 &sensor_dev_attr_pwm4_auto_slope.dev_attr.attr,
2737 &sensor_dev_attr_pwm5_auto_point1_temp.dev_attr.attr,
2738 &sensor_dev_attr_pwm5_auto_point1_temp_hyst.dev_attr.attr,
2739 &sensor_dev_attr_pwm5_auto_point2_temp.dev_attr.attr,
2740 &sensor_dev_attr_pwm5_auto_point3_temp.dev_attr.attr,
2741 &sensor_dev_attr_pwm5_auto_start.dev_attr.attr,
2742 &sensor_dev_attr_pwm5_auto_slope.dev_attr.attr,
2744 &sensor_dev_attr_pwm6_auto_point1_temp.dev_attr.attr,
2745 &sensor_dev_attr_pwm6_auto_point1_temp_hyst.dev_attr.attr,
2746 &sensor_dev_attr_pwm6_auto_point2_temp.dev_attr.attr,
2747 &sensor_dev_attr_pwm6_auto_point3_temp.dev_attr.attr,
2748 &sensor_dev_attr_pwm6_auto_start.dev_attr.attr,
2749 &sensor_dev_attr_pwm6_auto_slope.dev_attr.attr,
2754 static const struct attribute_group it87_group_auto_pwm = {
2755 .attrs = it87_attributes_auto_pwm,
2756 .is_visible = it87_auto_pwm_is_visible,
2759 /* SuperIO detection - will change isa_address if a chip is found */
2760 static int __init it87_find(int sioaddr, unsigned short *address,
2761 struct it87_sio_data *sio_data)
2763 const struct it87_devices *config;
2768 err = superio_enter(sioaddr);
2773 chip_type = superio_inw(sioaddr, DEVID);
2774 if (chip_type == 0xffff)
2778 chip_type = force_id;
2780 switch (chip_type) {
2782 sio_data->type = it87;
2785 sio_data->type = it8712;
2789 sio_data->type = it8716;
2792 sio_data->type = it8718;
2795 sio_data->type = it8720;
2798 sio_data->type = it8721;
2801 sio_data->type = it8728;
2804 sio_data->type = it8732;
2807 sio_data->type = it8792;
2809 * Disabling configuration mode on IT8792E can result in system
2810 * hang-ups and access failures to the Super-IO chip at the
2811 * second SIO address. Never exit configuration mode on this
2812 * chip to avoid the problem.
2817 sio_data->type = it8771;
2820 sio_data->type = it8772;
2823 sio_data->type = it8781;
2826 sio_data->type = it8782;
2829 sio_data->type = it8783;
2832 sio_data->type = it8786;
2835 sio_data->type = it8790;
2839 sio_data->type = it8603;
2842 sio_data->type = it8607;
2845 sio_data->type = it8613;
2848 sio_data->type = it8620;
2851 sio_data->type = it8622;
2854 sio_data->type = it8625;
2857 sio_data->type = it8628;
2860 sio_data->type = it8655;
2863 sio_data->type = it8665;
2866 sio_data->type = it8686;
2868 case 0xffff: /* No device at all */
2871 pr_debug("Unsupported chip (DEVID=0x%x)\n", chip_type);
2875 superio_select(sioaddr, PME);
2876 if (!(superio_inb(sioaddr, IT87_ACT_REG) & 0x01)) {
2877 pr_info("Device not activated, skipping\n");
2881 *address = superio_inw(sioaddr, IT87_BASE_REG) & ~(IT87_EXTENT - 1);
2882 if (*address == 0) {
2883 pr_info("Base address not set, skipping\n");
2888 sio_data->revision = superio_inb(sioaddr, DEVREV) & 0x0f;
2889 pr_info("Found IT%04x%s chip at 0x%x, revision %d\n", chip_type,
2890 it87_devices[sio_data->type].suffix,
2891 *address, sio_data->revision);
2893 config = &it87_devices[sio_data->type];
2895 /* in7 (VSB or VCCH5V) is always internal on some chips */
2896 if (has_in7_internal(config))
2897 sio_data->internal |= BIT(1);
2899 /* in8 (Vbat) is always internal */
2900 sio_data->internal |= BIT(2);
2902 /* in9 (AVCC3), always internal if supported */
2903 if (has_avcc3(config))
2904 sio_data->internal |= BIT(3); /* in9 is AVCC */
2906 sio_data->skip_in |= BIT(9);
2908 if (!has_four_pwm(config))
2909 sio_data->skip_pwm |= BIT(3) | BIT(4) | BIT(5);
2910 else if (!has_five_pwm(config))
2911 sio_data->skip_pwm |= BIT(4) | BIT(5);
2912 else if (!has_six_pwm(config))
2913 sio_data->skip_pwm |= BIT(5);
2915 if (!has_vid(config))
2916 sio_data->skip_vid = 1;
2918 /* Read GPIO config and VID value from LDN 7 (GPIO) */
2919 if (sio_data->type == it87) {
2920 /* The IT8705F has a different LD number for GPIO */
2921 superio_select(sioaddr, 5);
2922 sio_data->beep_pin = superio_inb(sioaddr,
2923 IT87_SIO_BEEP_PIN_REG) & 0x3f;
2924 } else if (sio_data->type == it8783) {
2925 int reg25, reg27, reg2a, reg2c, regef;
2927 superio_select(sioaddr, GPIO);
2929 reg25 = superio_inb(sioaddr, IT87_SIO_GPIO1_REG);
2930 reg27 = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
2931 reg2a = superio_inb(sioaddr, IT87_SIO_PINX1_REG);
2932 reg2c = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
2933 regef = superio_inb(sioaddr, IT87_SIO_SPI_REG);
2935 /* Check if fan3 is there or not */
2936 if ((reg27 & BIT(0)) || !(reg2c & BIT(2)))
2937 sio_data->skip_fan |= BIT(2);
2938 if ((reg25 & BIT(4)) ||
2939 (!(reg2a & BIT(1)) && (regef & BIT(0))))
2940 sio_data->skip_pwm |= BIT(2);
2942 /* Check if fan2 is there or not */
2944 sio_data->skip_fan |= BIT(1);
2946 sio_data->skip_pwm |= BIT(1);
2949 if ((reg27 & BIT(0)) || (reg2c & BIT(2)))
2950 sio_data->skip_in |= BIT(5); /* No VIN5 */
2954 sio_data->skip_in |= BIT(6); /* No VIN6 */
2958 * Does not depend on bit 2 of Reg2C, contrary to datasheet.
2960 if (reg27 & BIT(2)) {
2962 * The data sheet is a bit unclear regarding the
2963 * internal voltage divider for VCCH5V. It says
2964 * "This bit enables and switches VIN7 (pin 91) to the
2965 * internal voltage divider for VCCH5V".
2966 * This is different to other chips, where the internal
2967 * voltage divider would connect VIN7 to an internal
2968 * voltage source. Maybe that is the case here as well.
2970 * Since we don't know for sure, re-route it if that is
2971 * not the case, and ask the user to report if the
2972 * resulting voltage is sane.
2974 if (!(reg2c & BIT(1))) {
2976 superio_outb(sioaddr, IT87_SIO_PINX2_REG,
2978 pr_notice("Routing internal VCCH5V to in7.\n");
2980 pr_notice("in7 routed to internal voltage divider, with external pin disabled.\n");
2981 pr_notice("Please report if it displays a reasonable voltage.\n");
2985 sio_data->internal |= BIT(0);
2987 sio_data->internal |= BIT(1);
2989 sio_data->beep_pin = superio_inb(sioaddr,
2990 IT87_SIO_BEEP_PIN_REG) & 0x3f;
2991 } else if (sio_data->type == it8603 || sio_data->type == it8607) {
2994 superio_select(sioaddr, GPIO);
2996 reg27 = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
2998 /* Check if fan3 is there or not */
3000 sio_data->skip_pwm |= BIT(2);
3002 sio_data->skip_fan |= BIT(2);
3004 /* Check if fan2 is there or not */
3005 reg29 = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3007 sio_data->skip_pwm |= BIT(1);
3009 sio_data->skip_fan |= BIT(1);
3011 switch (sio_data->type) {
3013 sio_data->skip_in |= BIT(5); /* No VIN5 */
3014 sio_data->skip_in |= BIT(6); /* No VIN6 */
3017 sio_data->skip_pwm |= BIT(0);/* No fan1 */
3018 sio_data->skip_fan |= BIT(0);
3023 sio_data->beep_pin = superio_inb(sioaddr,
3024 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3025 } else if (sio_data->type == it8613) {
3026 int reg27, reg29, reg2a;
3028 superio_select(sioaddr, GPIO);
3030 /* Check for pwm3, fan3, pwm5, fan5 */
3031 reg27 = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3033 sio_data->skip_fan |= BIT(4);
3035 sio_data->skip_pwm |= BIT(4);
3037 sio_data->skip_pwm |= BIT(2);
3039 sio_data->skip_fan |= BIT(2);
3041 /* Check for pwm2, fan2 */
3042 reg29 = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3044 sio_data->skip_pwm |= BIT(1);
3046 sio_data->skip_fan |= BIT(1);
3048 /* Check for pwm4, fan4 */
3049 reg2a = superio_inb(sioaddr, IT87_SIO_PINX1_REG);
3050 if (!(reg2a & BIT(0)) || (reg29 & BIT(7))) {
3051 sio_data->skip_fan |= BIT(3);
3052 sio_data->skip_pwm |= BIT(3);
3055 sio_data->skip_pwm |= BIT(0); /* No pwm1 */
3056 sio_data->skip_fan |= BIT(0); /* No fan1 */
3057 sio_data->skip_in |= BIT(3); /* No VIN3 */
3058 sio_data->skip_in |= BIT(6); /* No VIN6 */
3060 sio_data->beep_pin = superio_inb(sioaddr,
3061 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3062 } else if (sio_data->type == it8620 || sio_data->type == it8628 ||
3063 sio_data->type == it8686) {
3066 superio_select(sioaddr, GPIO);
3068 /* Check for pwm5 */
3069 reg = superio_inb(sioaddr, IT87_SIO_GPIO1_REG);
3071 sio_data->skip_pwm |= BIT(4);
3073 /* Check for fan4, fan5 */
3074 reg = superio_inb(sioaddr, IT87_SIO_GPIO2_REG);
3075 if (!(reg & BIT(5)))
3076 sio_data->skip_fan |= BIT(3);
3077 if (!(reg & BIT(4)))
3078 sio_data->skip_fan |= BIT(4);
3080 /* Check for pwm3, fan3 */
3081 reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3083 sio_data->skip_pwm |= BIT(2);
3085 sio_data->skip_fan |= BIT(2);
3087 /* Check for pwm4 */
3088 reg = superio_inb(sioaddr, IT87_SIO_GPIO4_REG);
3090 sio_data->skip_pwm |= BIT(3);
3092 /* Check for pwm2, fan2 */
3093 reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3095 sio_data->skip_pwm |= BIT(1);
3097 sio_data->skip_fan |= BIT(1);
3098 /* Check for pwm6, fan6 */
3099 if (!(reg & BIT(7))) {
3100 sio_data->skip_pwm |= BIT(5);
3101 sio_data->skip_fan |= BIT(5);
3104 /* Check if AVCC is on VIN3 */
3105 reg = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
3107 /* For it8686, the bit just enables AVCC3 */
3108 if (sio_data->type != it8686)
3109 sio_data->internal |= BIT(0);
3111 sio_data->internal &= ~BIT(3);
3112 sio_data->skip_in |= BIT(9);
3115 sio_data->beep_pin = superio_inb(sioaddr,
3116 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3117 } else if (sio_data->type == it8622) {
3120 superio_select(sioaddr, GPIO);
3122 /* Check for pwm4, fan4 */
3123 reg = superio_inb(sioaddr, IT87_SIO_GPIO1_REG);
3125 sio_data->skip_fan |= BIT(3);
3127 sio_data->skip_pwm |= BIT(3);
3129 /* Check for pwm3, fan3, pwm5, fan5 */
3130 reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3132 sio_data->skip_pwm |= BIT(2);
3134 sio_data->skip_fan |= BIT(2);
3136 sio_data->skip_pwm |= BIT(4);
3138 sio_data->skip_fan |= BIT(4);
3140 /* Check for pwm2, fan2 */
3141 reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3143 sio_data->skip_pwm |= BIT(1);
3145 sio_data->skip_fan |= BIT(1);
3147 /* Check for AVCC */
3148 reg = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
3149 if (!(reg & BIT(0)))
3150 sio_data->skip_in |= BIT(9);
3152 sio_data->beep_pin = superio_inb(sioaddr,
3153 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3154 } else if (sio_data->type == it8732) {
3157 superio_select(sioaddr, GPIO);
3159 /* Check for pwm2, fan2 */
3160 reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3162 sio_data->skip_pwm |= BIT(1);
3164 sio_data->skip_fan |= BIT(1);
3166 /* Check for pwm3, fan3, fan4 */
3167 reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3169 sio_data->skip_pwm |= BIT(2);
3171 sio_data->skip_fan |= BIT(2);
3173 sio_data->skip_fan |= BIT(3);
3175 /* Check if AVCC is on VIN3 */
3176 reg = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
3178 sio_data->internal |= BIT(0);
3180 sio_data->beep_pin = superio_inb(sioaddr,
3181 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3182 } else if (sio_data->type == it8655) {
3185 superio_select(sioaddr, GPIO);
3187 /* Check for pwm2 */
3188 reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3190 sio_data->skip_pwm |= BIT(1);
3192 /* Check for fan2 */
3193 reg = superio_inb(sioaddr, IT87_SIO_PINX4_REG);
3195 sio_data->skip_fan |= BIT(1);
3197 /* Check for pwm3, fan3 */
3198 reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3200 sio_data->skip_pwm |= BIT(2);
3202 sio_data->skip_fan |= BIT(2);
3204 sio_data->beep_pin = superio_inb(sioaddr,
3205 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3206 } else if (sio_data->type == it8665 || sio_data->type == it8625) {
3207 int reg27, reg29, reg2d, regd3;
3209 superio_select(sioaddr, GPIO);
3211 reg27 = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3212 reg29 = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3213 reg2d = superio_inb(sioaddr, IT87_SIO_PINX4_REG);
3214 regd3 = superio_inb(sioaddr, IT87_SIO_GPIO9_REG);
3216 /* Check for pwm2, fan2 */
3218 sio_data->skip_pwm |= BIT(1);
3220 sio_data->skip_fan |= BIT(1);
3222 /* Check for pwm3, fan3 */
3224 sio_data->skip_pwm |= BIT(2);
3226 sio_data->skip_fan |= BIT(2);
3228 /* Check for pwm4, fan4, pwm5, fan5 */
3229 if (sio_data->type == it8625) {
3230 int reg25 = superio_inb(sioaddr, IT87_SIO_GPIO1_REG);
3233 sio_data->skip_fan |= BIT(3);
3235 sio_data->skip_pwm |= BIT(3);
3237 sio_data->skip_pwm |= BIT(4);
3239 sio_data->skip_fan |= BIT(4);
3241 int reg26 = superio_inb(sioaddr, IT87_SIO_GPIO2_REG);
3244 sio_data->skip_pwm |= BIT(3);
3246 sio_data->skip_fan |= BIT(3);
3248 sio_data->skip_pwm |= BIT(4);
3249 if (!(reg26 & BIT(4)))
3250 sio_data->skip_fan |= BIT(4);
3253 /* Check for pwm6, fan6 */
3255 sio_data->skip_pwm |= BIT(5);
3257 sio_data->skip_fan |= BIT(5);
3259 sio_data->beep_pin = superio_inb(sioaddr,
3260 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3265 superio_select(sioaddr, GPIO);
3267 /* Check for fan4, fan5 */
3268 if (has_five_fans(config)) {
3269 reg = superio_inb(sioaddr, IT87_SIO_GPIO2_REG);
3270 switch (sio_data->type) {
3273 sio_data->skip_fan |= BIT(3);
3275 sio_data->skip_fan |= BIT(4);
3280 if (!(reg & BIT(5)))
3281 sio_data->skip_fan |= BIT(3);
3282 if (!(reg & BIT(4)))
3283 sio_data->skip_fan |= BIT(4);
3290 reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3291 if (!sio_data->skip_vid) {
3292 /* We need at least 4 VID pins */
3294 pr_info("VID is disabled (pins used for GPIO)\n");
3295 sio_data->skip_vid = 1;
3299 /* Check if fan3 is there or not */
3301 sio_data->skip_pwm |= BIT(2);
3303 sio_data->skip_fan |= BIT(2);
3305 /* Check if fan2 is there or not */
3306 reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3308 sio_data->skip_pwm |= BIT(1);
3310 sio_data->skip_fan |= BIT(1);
3312 if ((sio_data->type == it8718 || sio_data->type == it8720) &&
3313 !(sio_data->skip_vid))
3314 sio_data->vid_value = superio_inb(sioaddr,
3317 reg = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
3319 uart6 = sio_data->type == it8782 && (reg & BIT(2));
3322 * The IT8720F has no VIN7 pin, so VCCH should always be
3323 * routed internally to VIN7 with an internal divider.
3324 * Curiously, there still is a configuration bit to control
3325 * this, which means it can be set incorrectly. And even
3326 * more curiously, many boards out there are improperly
3327 * configured, even though the IT8720F datasheet claims
3328 * that the internal routing of VCCH to VIN7 is the default
3329 * setting. So we force the internal routing in this case.
3331 * On IT8782F, VIN7 is multiplexed with one of the UART6 pins.
3332 * If UART6 is enabled, re-route VIN7 to the internal divider
3333 * if that is not already the case.
3335 if ((sio_data->type == it8720 || uart6) && !(reg & BIT(1))) {
3337 superio_outb(sioaddr, IT87_SIO_PINX2_REG, reg);
3338 pr_notice("Routing internal VCCH to in7\n");
3341 sio_data->internal |= BIT(0);
3343 sio_data->internal |= BIT(1);
3346 * On IT8782F, UART6 pins overlap with VIN5, VIN6, and VIN7.
3347 * While VIN7 can be routed to the internal voltage divider,
3348 * VIN5 and VIN6 are not available if UART6 is enabled.
3350 * Also, temp3 is not available if UART6 is enabled and TEMPIN3
3351 * is the temperature source. Since we can not read the
3352 * temperature source here, skip_temp is preliminary.
3355 sio_data->skip_in |= BIT(5) | BIT(6);
3356 sio_data->skip_temp |= BIT(2);
3359 sio_data->beep_pin = superio_inb(sioaddr,
3360 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3362 if (sio_data->beep_pin)
3363 pr_info("Beeping is supported\n");
3366 superio_exit(sioaddr, doexit);
3370 static void it87_init_regs(struct platform_device *pdev)
3372 struct it87_data *data = platform_get_drvdata(pdev);
3374 /* Initialize chip specific register pointers */
3375 switch (data->type) {
3378 data->REG_FAN = IT87_REG_FAN;
3379 data->REG_FANX = IT87_REG_FANX;
3380 data->REG_FAN_MIN = IT87_REG_FAN_MIN;
3381 data->REG_FANX_MIN = IT87_REG_FANX_MIN;
3382 data->REG_PWM = IT87_REG_PWM;
3383 data->REG_TEMP_OFFSET = IT87_REG_TEMP_OFFSET_8686;
3384 data->REG_TEMP_LOW = IT87_REG_TEMP_LOW_8686;
3385 data->REG_TEMP_HIGH = IT87_REG_TEMP_HIGH_8686;
3390 data->REG_FAN = IT87_REG_FAN_8665;
3391 data->REG_FANX = IT87_REG_FANX_8665;
3392 data->REG_FAN_MIN = IT87_REG_FAN_MIN_8665;
3393 data->REG_FANX_MIN = IT87_REG_FANX_MIN_8665;
3394 data->REG_PWM = IT87_REG_PWM_8665;
3395 data->REG_TEMP_OFFSET = IT87_REG_TEMP_OFFSET;
3396 data->REG_TEMP_LOW = IT87_REG_TEMP_LOW;
3397 data->REG_TEMP_HIGH = IT87_REG_TEMP_HIGH;
3400 data->REG_FAN = IT87_REG_FAN;
3401 data->REG_FANX = IT87_REG_FANX;
3402 data->REG_FAN_MIN = IT87_REG_FAN_MIN;
3403 data->REG_FANX_MIN = IT87_REG_FANX_MIN;
3404 data->REG_PWM = IT87_REG_PWM_8665;
3405 data->REG_TEMP_OFFSET = IT87_REG_TEMP_OFFSET;
3406 data->REG_TEMP_LOW = IT87_REG_TEMP_LOW;
3407 data->REG_TEMP_HIGH = IT87_REG_TEMP_HIGH;
3410 data->REG_FAN = IT87_REG_FAN;
3411 data->REG_FANX = IT87_REG_FANX;
3412 data->REG_FAN_MIN = IT87_REG_FAN_MIN;
3413 data->REG_FANX_MIN = IT87_REG_FANX_MIN;
3414 data->REG_PWM = IT87_REG_PWM_8665;
3415 data->REG_TEMP_OFFSET = IT87_REG_TEMP_OFFSET;
3416 data->REG_TEMP_LOW = IT87_REG_TEMP_LOW;
3417 data->REG_TEMP_HIGH = IT87_REG_TEMP_HIGH;
3420 data->REG_FAN = IT87_REG_FAN;
3421 data->REG_FANX = IT87_REG_FANX;
3422 data->REG_FAN_MIN = IT87_REG_FAN_MIN;
3423 data->REG_FANX_MIN = IT87_REG_FANX_MIN;
3424 data->REG_PWM = IT87_REG_PWM;
3425 data->REG_TEMP_OFFSET = IT87_REG_TEMP_OFFSET;
3426 data->REG_TEMP_LOW = IT87_REG_TEMP_LOW;
3427 data->REG_TEMP_HIGH = IT87_REG_TEMP_HIGH;
3432 /* Called when we have found a new IT87. */
3433 static void it87_init_device(struct platform_device *pdev)
3435 struct it87_sio_data *sio_data = dev_get_platdata(&pdev->dev);
3436 struct it87_data *data = platform_get_drvdata(pdev);
3441 * For each PWM channel:
3442 * - If it is in automatic mode, setting to manual mode should set
3443 * the fan to full speed by default.
3444 * - If it is in manual mode, we need a mapping to temperature
3445 * channels to use when later setting to automatic mode later.
3446 * Use a 1:1 mapping by default (we are clueless.)
3447 * In both cases, the value can (and should) be changed by the user
3448 * prior to switching to a different mode.
3449 * Note that this is no longer needed for the IT8721F and later, as
3450 * these have separate registers for the temperature mapping and the
3451 * manual duty cycle.
3453 for (i = 0; i < NUM_AUTO_PWM; i++) {
3454 data->pwm_temp_map[i] = i;
3455 data->pwm_duty[i] = 0x7f; /* Full speed */
3456 data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */
3460 * Some chips seem to have default value 0xff for all limit
3461 * registers. For low voltage limits it makes no sense and triggers
3462 * alarms, so change to 0 instead. For high temperature limits, it
3463 * means -1 degree C, which surprisingly doesn't trigger an alarm,
3464 * but is still confusing, so change to 127 degrees C.
3466 for (i = 0; i < NUM_VIN_LIMIT; i++) {
3467 tmp = it87_read_value(data, IT87_REG_VIN_MIN(i));
3469 it87_write_value(data, IT87_REG_VIN_MIN(i), 0);
3471 for (i = 0; i < data->num_temp_limit; i++) {
3472 tmp = it87_read_value(data, data->REG_TEMP_HIGH[i]);
3474 it87_write_value(data, data->REG_TEMP_HIGH[i], 127);
3478 * Temperature channels are not forcibly enabled, as they can be
3479 * set to two different sensor types and we can't guess which one
3480 * is correct for a given system. These channels can be enabled at
3481 * run-time through the temp{1-3}_type sysfs accessors if needed.
3484 /* Check if voltage monitors are reset manually or by some reason */
3485 tmp = it87_read_value(data, IT87_REG_VIN_ENABLE);
3486 if ((tmp & 0xff) == 0) {
3487 /* Enable all voltage monitors */
3488 it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff);
3491 /* Check if tachometers are reset manually or by some reason */
3492 mask = 0x70 & ~(sio_data->skip_fan << 4);
3493 data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL);
3494 if ((data->fan_main_ctrl & mask) == 0) {
3495 /* Enable all fan tachometers */
3496 data->fan_main_ctrl |= mask;
3497 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
3498 data->fan_main_ctrl);
3500 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
3502 tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
3504 /* Set tachometers to 16-bit mode if needed */
3505 if (has_fan16_config(data)) {
3506 if (~tmp & 0x07 & data->has_fan) {
3508 "Setting fan1-3 to 16-bit mode\n");
3509 it87_write_value(data, IT87_REG_FAN_16BIT,
3514 /* Check for additional fans */
3515 if (has_four_fans(data) && (tmp & BIT(4)))
3516 data->has_fan |= BIT(3); /* fan4 enabled */
3517 if (has_five_fans(data) && (tmp & BIT(5)))
3518 data->has_fan |= BIT(4); /* fan5 enabled */
3519 if (has_six_fans(data)) {
3520 switch (data->type) {
3525 data->has_fan |= BIT(5); /* fan6 enabled */
3529 tmp = it87_read_value(data, IT87_REG_FAN_DIV);
3531 data->has_fan |= BIT(5); /* fan6 enabled */
3538 /* Fan input pins may be used for alternative functions */
3539 data->has_fan &= ~sio_data->skip_fan;
3541 /* Check if pwm6 is enabled */
3542 if (has_six_pwm(data)) {
3543 switch (data->type) {
3546 tmp = it87_read_value(data, IT87_REG_FAN_DIV);
3547 if (!(tmp & BIT(3)))
3548 sio_data->skip_pwm |= BIT(5);
3555 /* Start monitoring */
3556 it87_write_value(data, IT87_REG_CONFIG,
3557 (it87_read_value(data, IT87_REG_CONFIG) & 0x3e)
3558 | (update_vbat ? 0x41 : 0x01));
3561 /* Return 1 if and only if the PWM interface is safe to use */
3562 static int it87_check_pwm(struct device *dev)
3564 struct it87_data *data = dev_get_drvdata(dev);
3566 * Some BIOSes fail to correctly configure the IT87 fans. All fans off
3567 * and polarity set to active low is sign that this is the case so we
3568 * disable pwm control to protect the user.
3570 int tmp = it87_read_value(data, IT87_REG_FAN_CTL);
3572 if ((tmp & 0x87) == 0) {
3573 if (fix_pwm_polarity) {
3575 * The user asks us to attempt a chip reconfiguration.
3576 * This means switching to active high polarity and
3577 * inverting all fan speed values.
3582 for (i = 0; i < ARRAY_SIZE(pwm); i++)
3583 pwm[i] = it87_read_value(data,
3587 * If any fan is in automatic pwm mode, the polarity
3588 * might be correct, as suspicious as it seems, so we
3589 * better don't change anything (but still disable the
3592 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
3594 "Reconfiguring PWM to active high polarity\n");
3595 it87_write_value(data, IT87_REG_FAN_CTL,
3597 for (i = 0; i < 3; i++)
3598 it87_write_value(data,
3605 "PWM configuration is too broken to be fixed\n");
3609 "Detected broken BIOS defaults, disabling PWM interface\n");
3611 } else if (fix_pwm_polarity) {
3613 "PWM configuration looks sane, won't touch\n");
3619 static int it87_probe(struct platform_device *pdev)
3621 struct it87_data *data;
3622 struct resource *res;
3623 struct device *dev = &pdev->dev;
3624 struct it87_sio_data *sio_data = dev_get_platdata(dev);
3625 int enable_pwm_interface;
3626 struct device *hwmon_dev;
3628 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
3629 if (!devm_request_region(&pdev->dev, res->start, IT87_EC_EXTENT,
3631 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
3632 (unsigned long)res->start,
3633 (unsigned long)(res->start + IT87_EC_EXTENT - 1));
3637 data = devm_kzalloc(&pdev->dev, sizeof(struct it87_data), GFP_KERNEL);
3641 data->addr = res->start;
3642 data->type = sio_data->type;
3643 data->features = it87_devices[sio_data->type].features;
3644 data->num_temp_limit = it87_devices[sio_data->type].num_temp_limit;
3645 data->num_temp_offset = it87_devices[sio_data->type].num_temp_offset;
3646 data->peci_mask = it87_devices[sio_data->type].peci_mask;
3647 data->old_peci_mask = it87_devices[sio_data->type].old_peci_mask;
3651 * IT8705F Datasheet 0.4.1, 3h == Version G.
3652 * IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J.
3653 * These are the first revisions with 16-bit tachometer support.
3655 switch (data->type) {
3657 if (sio_data->revision >= 0x03) {
3658 data->features &= ~FEAT_OLD_AUTOPWM;
3659 data->features |= FEAT_FAN16_CONFIG | FEAT_16BIT_FANS;
3663 if (sio_data->revision >= 0x08) {
3664 data->features &= ~FEAT_OLD_AUTOPWM;
3665 data->features |= FEAT_FAN16_CONFIG | FEAT_16BIT_FANS |
3673 /* Now, we do the remaining detection. */
3674 if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80) ||
3675 it87_read_value(data, IT87_REG_CHIPID) != 0x90)
3678 platform_set_drvdata(pdev, data);
3680 mutex_init(&data->update_lock);
3682 /* Initialize register pointers */
3683 it87_init_regs(pdev);
3685 /* Check PWM configuration */
3686 enable_pwm_interface = it87_check_pwm(dev);
3688 /* Starting with IT8721F, we handle scaling of internal voltages */
3689 if (has_scaling(data)) {
3690 if (sio_data->internal & BIT(0))
3691 data->in_scaled |= BIT(3); /* in3 is AVCC */
3692 if (sio_data->internal & BIT(1))
3693 data->in_scaled |= BIT(7); /* in7 is VSB */
3694 if (sio_data->internal & BIT(2))
3695 data->in_scaled |= BIT(8); /* in8 is Vbat */
3696 if (sio_data->internal & BIT(3))
3697 data->in_scaled |= BIT(9); /* in9 is AVCC */
3698 } else if (sio_data->type == it8781 || sio_data->type == it8782 ||
3699 sio_data->type == it8783) {
3700 if (sio_data->internal & BIT(0))
3701 data->in_scaled |= BIT(3); /* in3 is VCC5V */
3702 if (sio_data->internal & BIT(1))
3703 data->in_scaled |= BIT(7); /* in7 is VCCH5V */
3706 data->has_temp = 0x07;
3707 if (sio_data->skip_temp & BIT(2)) {
3708 if (sio_data->type == it8782 &&
3709 !(it87_read_value(data, IT87_REG_TEMP_EXTRA) & 0x80))
3710 data->has_temp &= ~BIT(2);
3713 data->in_internal = sio_data->internal;
3714 data->has_in = 0x3ff & ~sio_data->skip_in;
3716 if (has_six_temp(data)) {
3717 u8 reg = it87_read_value(data, IT87_REG_TEMP456_ENABLE);
3719 /* Check for additional temperature sensors */
3720 if ((reg & 0x03) >= 0x02)
3721 data->has_temp |= BIT(3);
3722 if (((reg >> 2) & 0x03) >= 0x02)
3723 data->has_temp |= BIT(4);
3724 if (((reg >> 4) & 0x03) >= 0x02)
3725 data->has_temp |= BIT(5);
3727 /* Check for additional voltage sensors */
3728 if ((reg & 0x03) == 0x01)
3729 data->has_in |= BIT(10);
3730 if (((reg >> 2) & 0x03) == 0x01)
3731 data->has_in |= BIT(11);
3732 if (((reg >> 4) & 0x03) == 0x01)
3733 data->has_in |= BIT(12);
3736 data->has_beep = !!sio_data->beep_pin;
3738 /* Initialize the IT87 chip */
3739 it87_init_device(pdev);
3741 if (!sio_data->skip_vid) {
3742 data->has_vid = true;
3743 data->vrm = vid_which_vrm();
3744 /* VID reading from Super-I/O config space if available */
3745 data->vid = sio_data->vid_value;
3748 /* Prepare for sysfs hooks */
3749 data->groups[0] = &it87_group;
3750 data->groups[1] = &it87_group_in;
3751 data->groups[2] = &it87_group_temp;
3752 data->groups[3] = &it87_group_fan;
3754 if (enable_pwm_interface) {
3755 data->has_pwm = BIT(ARRAY_SIZE(IT87_REG_PWM)) - 1;
3756 data->has_pwm &= ~sio_data->skip_pwm;
3758 data->groups[4] = &it87_group_pwm;
3759 if (has_old_autopwm(data) || has_newer_autopwm(data))
3760 data->groups[5] = &it87_group_auto_pwm;
3763 hwmon_dev = devm_hwmon_device_register_with_groups(dev,
3764 it87_devices[sio_data->type].name,
3765 data, data->groups);
3766 return PTR_ERR_OR_ZERO(hwmon_dev);
3769 static struct platform_driver it87_driver = {
3773 .probe = it87_probe,
3776 static int __init it87_device_add(int index, unsigned short address,
3777 const struct it87_sio_data *sio_data)
3779 struct platform_device *pdev;
3780 struct resource res = {
3781 .start = address + IT87_EC_OFFSET,
3782 .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1,
3784 .flags = IORESOURCE_IO,
3788 err = acpi_check_resource_conflict(&res);
3792 pdev = platform_device_alloc(DRVNAME, address);
3796 err = platform_device_add_resources(pdev, &res, 1);
3798 pr_err("Device resource addition failed (%d)\n", err);
3799 goto exit_device_put;
3802 err = platform_device_add_data(pdev, sio_data,
3803 sizeof(struct it87_sio_data));
3805 pr_err("Platform data allocation failed\n");
3806 goto exit_device_put;
3809 err = platform_device_add(pdev);
3811 pr_err("Device addition failed (%d)\n", err);
3812 goto exit_device_put;
3815 it87_pdev[index] = pdev;
3819 platform_device_put(pdev);
3823 struct it87_dmi_data {
3824 u8 skip_pwm; /* pwm channels to skip for this board */
3828 * On the Shuttle SN68PT, FAN_CTL2 is apparently not
3829 * connected to a fan, but to something else. One user
3830 * has reported instant system power-off when changing
3831 * the PWM2 duty cycle, so we disable it.
3832 * I use the board name string as the trigger in case
3833 * the same board is ever used in other systems.
3835 static struct it87_dmi_data nvidia_fn68pt = {
3839 static const struct dmi_system_id it87_dmi_table[] __initconst = {
3842 DMI_MATCH(DMI_BOARD_VENDOR, "nVIDIA"),
3843 DMI_MATCH(DMI_BOARD_NAME, "FN68PT"),
3845 .driver_data = &nvidia_fn68pt,
3850 static int __init sm_it87_init(void)
3852 const struct dmi_system_id *dmi = dmi_first_match(it87_dmi_table);
3853 struct it87_dmi_data *dmi_data = NULL;
3854 int sioaddr[2] = { REG_2E, REG_4E };
3855 struct it87_sio_data sio_data;
3856 unsigned short isa_address;
3861 dmi_data = dmi->driver_data;
3863 err = platform_driver_register(&it87_driver);
3867 for (i = 0; i < ARRAY_SIZE(sioaddr); i++) {
3868 memset(&sio_data, 0, sizeof(struct it87_sio_data));
3870 err = it87_find(sioaddr[i], &isa_address, &sio_data);
3871 if (err || isa_address == 0)
3875 sio_data.skip_pwm |= dmi_data->skip_pwm;
3876 err = it87_device_add(i, isa_address, &sio_data);
3878 goto exit_dev_unregister;
3884 goto exit_unregister;
3888 exit_dev_unregister:
3889 /* NULL check handled by platform_device_unregister */
3890 platform_device_unregister(it87_pdev[0]);
3892 platform_driver_unregister(&it87_driver);
3896 static void __exit sm_it87_exit(void)
3898 /* NULL check handled by platform_device_unregister */
3899 platform_device_unregister(it87_pdev[1]);
3900 platform_device_unregister(it87_pdev[0]);
3901 platform_driver_unregister(&it87_driver);
3904 MODULE_AUTHOR("Chris Gauthron, Jean Delvare <jdelvare@suse.de>");
3905 MODULE_DESCRIPTION("IT8705F/IT871xF/IT872xF hardware monitoring driver");
3906 module_param(update_vbat, bool, 0);
3907 MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
3908 module_param(fix_pwm_polarity, bool, 0);
3909 MODULE_PARM_DESC(fix_pwm_polarity,
3910 "Force PWM polarity to active high (DANGEROUS)");
3911 MODULE_LICENSE("GPL");
3913 module_init(sm_it87_init);
3914 module_exit(sm_it87_exit);