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;
330 u8 num_temp_map; /* Number of temperature sources for pwm */
335 #define FEAT_12MV_ADC BIT(0)
336 #define FEAT_NEWER_AUTOPWM BIT(1)
337 #define FEAT_OLD_AUTOPWM BIT(2)
338 #define FEAT_16BIT_FANS BIT(3)
339 #define FEAT_TEMP_PECI BIT(5)
340 #define FEAT_TEMP_OLD_PECI BIT(6)
341 #define FEAT_FAN16_CONFIG BIT(7) /* Need to enable 16-bit fans */
342 #define FEAT_FIVE_FANS BIT(8) /* Supports five fans */
343 #define FEAT_VID BIT(9) /* Set if chip supports VID */
344 #define FEAT_IN7_INTERNAL BIT(10) /* Set if in7 is internal */
345 #define FEAT_SIX_FANS BIT(11) /* Supports six fans */
346 #define FEAT_10_9MV_ADC BIT(12)
347 #define FEAT_AVCC3 BIT(13) /* Chip supports in9/AVCC3 */
348 #define FEAT_FIVE_PWM BIT(14) /* Chip supports 5 pwm chn */
349 #define FEAT_SIX_PWM BIT(15) /* Chip supports 6 pwm chn */
350 #define FEAT_PWM_FREQ2 BIT(16) /* Separate pwm freq 2 */
351 #define FEAT_SIX_TEMP BIT(17) /* Up to 6 temp sensors */
352 #define FEAT_VIN3_5V BIT(18) /* VIN3 connected to +5V */
353 #define FEAT_FOUR_FANS BIT(19) /* Supports four fans */
354 #define FEAT_FOUR_PWM BIT(20) /* Supports four fan controls */
355 #define FEAT_BANK_SEL BIT(21) /* Chip has multi-bank support */
356 #define FEAT_SCALING BIT(22) /* Internal voltage scaling */
357 #define FEAT_FANCTL_ONOFF BIT(23) /* chip has FAN_CTL ON/OFF */
358 #define FEAT_11MV_ADC BIT(24)
359 #define FEAT_NEW_TEMPMAP BIT(25) /* new temp input selection */
361 static const struct it87_devices it87_devices[] = {
365 .features = FEAT_OLD_AUTOPWM | FEAT_FANCTL_ONOFF,
366 /* may need to overwrite */
368 .num_temp_offset = 0,
374 .features = FEAT_OLD_AUTOPWM | FEAT_VID | FEAT_FANCTL_ONOFF,
375 /* may need to overwrite */
377 .num_temp_offset = 0,
383 .features = FEAT_16BIT_FANS | FEAT_VID
384 | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS | FEAT_PWM_FREQ2
387 .num_temp_offset = 3,
393 .features = FEAT_16BIT_FANS | FEAT_VID
394 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS
395 | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
397 .num_temp_offset = 3,
399 .old_peci_mask = 0x4,
404 .features = FEAT_16BIT_FANS | FEAT_VID
405 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS
406 | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
408 .num_temp_offset = 3,
410 .old_peci_mask = 0x4,
415 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
416 | FEAT_TEMP_OLD_PECI | FEAT_TEMP_PECI
417 | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS | FEAT_IN7_INTERNAL
418 | FEAT_PWM_FREQ2 | FEAT_SCALING | FEAT_FANCTL_ONOFF,
420 .num_temp_offset = 3,
423 .old_peci_mask = 0x02, /* Actually reports PCH */
428 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
429 | FEAT_TEMP_PECI | FEAT_FIVE_FANS
430 | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2 | FEAT_SCALING
433 .num_temp_offset = 3,
440 .features = FEAT_NEWER_AUTOPWM | FEAT_16BIT_FANS
441 | FEAT_TEMP_OLD_PECI | FEAT_TEMP_PECI
442 | FEAT_10_9MV_ADC | FEAT_IN7_INTERNAL | FEAT_FOUR_FANS
443 | FEAT_FOUR_PWM | FEAT_FANCTL_ONOFF,
445 .num_temp_offset = 3,
448 .old_peci_mask = 0x02, /* Actually reports PCH */
453 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
454 | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
455 | FEAT_PWM_FREQ2 | FEAT_SCALING | FEAT_FANCTL_ONOFF,
456 /* PECI: guesswork */
458 /* 16 bit fans (OHM) */
459 /* three fans, always 16 bit (guesswork) */
461 .num_temp_offset = 3,
468 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
469 | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
470 | FEAT_PWM_FREQ2 | FEAT_SCALING | FEAT_FANCTL_ONOFF,
471 /* PECI (coreboot) */
472 /* 12mV ADC (HWSensors4, OHM) */
473 /* 16 bit fans (HWSensors4, OHM) */
474 /* three fans, always 16 bit (datasheet) */
476 .num_temp_offset = 3,
483 .features = FEAT_16BIT_FANS
484 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2
487 .num_temp_offset = 3,
489 .old_peci_mask = 0x4,
494 .features = FEAT_16BIT_FANS
495 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2
498 .num_temp_offset = 3,
500 .old_peci_mask = 0x4,
505 .features = FEAT_16BIT_FANS
506 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2
509 .num_temp_offset = 3,
511 .old_peci_mask = 0x4,
516 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
517 | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
518 | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
520 .num_temp_offset = 3,
527 .features = FEAT_NEWER_AUTOPWM | FEAT_10_9MV_ADC | FEAT_SCALING
528 | FEAT_16BIT_FANS | FEAT_TEMP_PECI
529 | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
531 .num_temp_offset = 3,
538 .features = FEAT_NEWER_AUTOPWM | FEAT_10_9MV_ADC | FEAT_SCALING
539 | FEAT_16BIT_FANS | FEAT_TEMP_PECI
540 | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
542 .num_temp_offset = 3,
549 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
550 | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
551 | FEAT_AVCC3 | FEAT_PWM_FREQ2 | FEAT_SCALING,
553 .num_temp_offset = 3,
560 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
561 | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL | FEAT_NEW_TEMPMAP
562 | FEAT_AVCC3 | FEAT_PWM_FREQ2 | FEAT_SCALING
565 .num_temp_offset = 3,
572 .features = FEAT_NEWER_AUTOPWM | FEAT_11MV_ADC | FEAT_16BIT_FANS
573 | FEAT_TEMP_PECI | FEAT_FIVE_FANS
574 | FEAT_FIVE_PWM | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2
575 | FEAT_AVCC3 | FEAT_SCALING | FEAT_NEW_TEMPMAP,
577 .num_temp_offset = 6,
584 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
585 | FEAT_TEMP_PECI | FEAT_SIX_FANS
586 | FEAT_IN7_INTERNAL | FEAT_SIX_PWM | FEAT_PWM_FREQ2
587 | FEAT_SIX_TEMP | FEAT_VIN3_5V | FEAT_SCALING
590 .num_temp_offset = 3,
597 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
598 | FEAT_TEMP_PECI | FEAT_FIVE_FANS
599 | FEAT_FIVE_PWM | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2
600 | FEAT_AVCC3 | FEAT_VIN3_5V | FEAT_SCALING,
602 .num_temp_offset = 3,
609 .features = FEAT_NEWER_AUTOPWM | FEAT_16BIT_FANS
610 | FEAT_AVCC3 | FEAT_NEW_TEMPMAP
611 | FEAT_11MV_ADC | FEAT_IN7_INTERNAL | FEAT_SIX_FANS
612 | FEAT_SIX_PWM | FEAT_BANK_SEL | FEAT_SCALING,
614 .num_temp_offset = 6,
620 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
621 | FEAT_TEMP_PECI | FEAT_SIX_FANS
622 | FEAT_IN7_INTERNAL | FEAT_SIX_PWM | FEAT_PWM_FREQ2
623 | FEAT_SIX_TEMP | FEAT_SCALING | FEAT_AVCC3
626 .num_temp_offset = 3,
633 .features = FEAT_NEWER_AUTOPWM | FEAT_16BIT_FANS
634 | FEAT_AVCC3 | FEAT_NEW_TEMPMAP | FEAT_SCALING
635 | FEAT_10_9MV_ADC | FEAT_IN7_INTERNAL | FEAT_BANK_SEL,
637 .num_temp_offset = 6,
643 .features = FEAT_NEWER_AUTOPWM | FEAT_16BIT_FANS
644 | FEAT_AVCC3 | FEAT_NEW_TEMPMAP | FEAT_SCALING
645 | FEAT_10_9MV_ADC | FEAT_IN7_INTERNAL | FEAT_SIX_FANS
646 | FEAT_SIX_PWM | FEAT_BANK_SEL,
648 .num_temp_offset = 6,
654 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
655 | FEAT_SIX_FANS | FEAT_NEW_TEMPMAP
656 | FEAT_IN7_INTERNAL | FEAT_SIX_PWM | FEAT_PWM_FREQ2
657 | FEAT_SIX_TEMP | FEAT_BANK_SEL | FEAT_SCALING | FEAT_AVCC3,
659 .num_temp_offset = 6,
664 #define has_16bit_fans(data) ((data)->features & FEAT_16BIT_FANS)
665 #define has_12mv_adc(data) ((data)->features & FEAT_12MV_ADC)
666 #define has_10_9mv_adc(data) ((data)->features & FEAT_10_9MV_ADC)
667 #define has_newer_autopwm(data) ((data)->features & FEAT_NEWER_AUTOPWM)
668 #define has_old_autopwm(data) ((data)->features & FEAT_OLD_AUTOPWM)
669 #define has_temp_peci(data, nr) (((data)->features & FEAT_TEMP_PECI) && \
670 ((data)->peci_mask & BIT(nr)))
671 #define has_temp_old_peci(data, nr) \
672 (((data)->features & FEAT_TEMP_OLD_PECI) && \
673 ((data)->old_peci_mask & BIT(nr)))
674 #define has_fan16_config(data) ((data)->features & FEAT_FAN16_CONFIG)
675 #define has_five_fans(data) ((data)->features & (FEAT_FIVE_FANS | \
677 #define has_vid(data) ((data)->features & FEAT_VID)
678 #define has_in7_internal(data) ((data)->features & FEAT_IN7_INTERNAL)
679 #define has_six_fans(data) ((data)->features & FEAT_SIX_FANS)
680 #define has_avcc3(data) ((data)->features & FEAT_AVCC3)
681 #define has_five_pwm(data) ((data)->features & (FEAT_FIVE_PWM \
683 #define has_six_pwm(data) ((data)->features & FEAT_SIX_PWM)
684 #define has_pwm_freq2(data) ((data)->features & FEAT_PWM_FREQ2)
685 #define has_six_temp(data) ((data)->features & FEAT_SIX_TEMP)
686 #define has_vin3_5v(data) ((data)->features & FEAT_VIN3_5V)
687 #define has_four_fans(data) ((data)->features & (FEAT_FOUR_FANS | \
690 #define has_four_pwm(data) ((data)->features & (FEAT_FOUR_PWM | \
693 #define has_bank_sel(data) ((data)->features & FEAT_BANK_SEL)
694 #define has_scaling(data) ((data)->features & FEAT_SCALING)
695 #define has_fanctl_onoff(data) ((data)->features & FEAT_FANCTL_ONOFF)
696 #define has_11mv_adc(data) ((data)->features & FEAT_11MV_ADC)
697 #define has_new_tempmap(data) ((data)->features & FEAT_NEW_TEMPMAP)
699 struct it87_sio_data {
701 /* Values read from Super-I/O config space */
705 u8 internal; /* Internal sensors can be labeled */
706 /* Features skipped based on config or DMI */
715 * For each registered chip, we need to keep some data in memory.
716 * The structure is dynamically allocated.
719 const struct attribute_group *groups[7];
728 const u8 *REG_FAN_MIN;
729 const u8 *REG_FANX_MIN;
733 const u8 *REG_TEMP_OFFSET;
734 const u8 *REG_TEMP_LOW;
735 const u8 *REG_TEMP_HIGH;
739 struct mutex update_lock;
740 char valid; /* !=0 if following fields are valid */
741 unsigned long last_updated; /* In jiffies */
743 u16 in_scaled; /* Internal voltage sensors are scaled */
744 u16 in_internal; /* Bitfield, internal sensors (for labels) */
745 u16 has_in; /* Bitfield, voltage sensors enabled */
746 u8 in[NUM_VIN][3]; /* [nr][0]=in, [1]=min, [2]=max */
747 u8 has_fan; /* Bitfield, fans enabled */
748 u16 fan[NUM_FAN][2]; /* Register values, [nr][0]=fan, [1]=min */
749 u8 has_temp; /* Bitfield, temp sensors enabled */
750 s8 temp[NUM_TEMP][4]; /* [nr][0]=temp, [1]=min, [2]=max, [3]=offset */
751 u8 num_temp_limit; /* Number of temperature limit registers */
752 u8 num_temp_offset; /* Number of temperature offset registers */
753 u8 sensor; /* Register value (IT87_REG_TEMP_ENABLE) */
754 u8 extra; /* Register value (IT87_REG_TEMP_EXTRA) */
755 u8 fan_div[NUM_FAN_DIV];/* Register encoding, shifted right */
756 bool has_vid; /* True if VID supported */
757 u8 vid; /* Register encoding, combined */
759 u32 alarms; /* Register encoding, combined */
760 bool has_beep; /* true if beep supported */
761 u8 beeps; /* Register encoding */
762 u8 fan_main_ctrl; /* Register value */
763 u8 fan_ctl; /* Register value */
766 * The following 3 arrays correspond to the same registers up to
767 * the IT8720F. The meaning of bits 6-0 depends on the value of bit
768 * 7, and we want to preserve settings on mode changes, so we have
769 * to track all values separately.
770 * Starting with the IT8721F, the manual PWM duty cycles are stored
771 * in separate registers (8-bit values), so the separate tracking
772 * is no longer needed, but it is still done to keep the driver
775 u8 has_pwm; /* Bitfield, pwm control enabled */
776 u8 pwm_ctrl[NUM_PWM]; /* Register value */
777 u8 pwm_duty[NUM_PWM]; /* Manual PWM value set by user */
778 u8 pwm_temp_map[NUM_PWM];/* PWM to temp. chan. mapping (bits 1-0) */
779 u8 pwm_temp_map_mask; /* 0x03 for old, 0x07 for new temp map */
780 u8 pwm_temp_map_shift; /* 0 for old, 3 for new temp map */
781 u8 pwm_num_temp_map; /* from config data, 3..7 depending on chip */
783 /* Automatic fan speed control registers */
784 u8 auto_pwm[NUM_AUTO_PWM][4]; /* [nr][3] is hard-coded */
785 s8 auto_temp[NUM_AUTO_PWM][5]; /* [nr][0] is point1_temp_hyst */
788 static int adc_lsb(const struct it87_data *data, int nr)
792 if (has_12mv_adc(data))
794 else if (has_10_9mv_adc(data))
796 else if (has_11mv_adc(data))
800 if (data->in_scaled & BIT(nr))
805 static u8 in_to_reg(const struct it87_data *data, int nr, long val)
807 val = DIV_ROUND_CLOSEST(val * 10, adc_lsb(data, nr));
808 return clamp_val(val, 0, 255);
811 static int in_from_reg(const struct it87_data *data, int nr, int val)
813 return DIV_ROUND_CLOSEST(val * adc_lsb(data, nr), 10);
816 static inline u8 FAN_TO_REG(long rpm, int div)
820 rpm = clamp_val(rpm, 1, 1000000);
821 return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
824 static inline u16 FAN16_TO_REG(long rpm)
828 return clamp_val((1350000 + rpm) / (rpm * 2), 1, 0xfffe);
831 #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \
832 1350000 / ((val) * (div)))
833 /* The divider is fixed to 2 in 16-bit mode */
834 #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
835 1350000 / ((val) * 2))
837 #define TEMP_TO_REG(val) (clamp_val(((val) < 0 ? (((val) - 500) / 1000) : \
838 ((val) + 500) / 1000), -128, 127))
839 #define TEMP_FROM_REG(val) ((val) * 1000)
841 static u8 pwm_to_reg(const struct it87_data *data, long val)
843 if (has_newer_autopwm(data))
849 static int pwm_from_reg(const struct it87_data *data, u8 reg)
851 if (has_newer_autopwm(data))
854 return (reg & 0x7f) << 1;
857 static int DIV_TO_REG(int val)
861 while (answer < 7 && (val >>= 1))
866 #define DIV_FROM_REG(val) BIT(val)
868 static u8 temp_map_from_reg(const struct it87_data *data, u8 reg)
872 map = (reg >> data->pwm_temp_map_shift) & data->pwm_temp_map_mask;
873 if (map >= data->pwm_num_temp_map) /* map is 0-based */
879 static u8 temp_map_to_reg(const struct it87_data *data, int nr, u8 map)
881 u8 ctrl = data->pwm_ctrl[nr];
883 return (ctrl & ~(data->pwm_temp_map_mask << data->pwm_temp_map_shift)) |
884 (map << data->pwm_temp_map_shift);
888 * PWM base frequencies. The frequency has to be divided by either 128 or 256,
889 * depending on the chip type, to calculate the actual PWM frequency.
891 * Some of the chip datasheets suggest a base frequency of 51 kHz instead
892 * of 750 kHz for the slowest base frequency, resulting in a PWM frequency
893 * of 200 Hz. Sometimes both PWM frequency select registers are affected,
894 * sometimes just one. It is unknown if this is a datasheet error or real,
895 * so this is ignored for now.
897 static const unsigned int pwm_freq[8] = {
908 static int _it87_read_value(struct it87_data *data, u8 reg)
910 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
911 return inb_p(data->addr + IT87_DATA_REG_OFFSET);
914 static void _it87_write_value(struct it87_data *data, u8 reg, u8 value)
916 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
917 outb_p(value, data->addr + IT87_DATA_REG_OFFSET);
920 static void it87_set_bank(struct it87_data *data, u8 bank)
922 if (has_bank_sel(data) && bank != data->bank) {
923 u8 breg = _it87_read_value(data, IT87_REG_BANK);
928 _it87_write_value(data, IT87_REG_BANK, breg);
933 * Must be called with data->update_lock held, except during initialization.
934 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
935 * would slow down the IT87 access and should not be necessary.
937 static int it87_read_value(struct it87_data *data, u16 reg)
939 it87_set_bank(data, reg >> 8);
940 return _it87_read_value(data, reg & 0xff);
944 * Must be called with data->update_lock held, except during initialization.
945 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
946 * would slow down the IT87 access and should not be necessary.
948 static void it87_write_value(struct it87_data *data, u16 reg, u8 value)
950 it87_set_bank(data, reg >> 8);
951 _it87_write_value(data, reg & 0xff, value);
954 static void it87_update_pwm_ctrl(struct it87_data *data, int nr)
958 ctrl = it87_read_value(data, data->REG_PWM[nr]);
959 data->pwm_ctrl[nr] = ctrl;
960 if (has_newer_autopwm(data)) {
961 data->pwm_temp_map[nr] = temp_map_from_reg(data, ctrl);
962 data->pwm_duty[nr] = it87_read_value(data,
963 IT87_REG_PWM_DUTY[nr]);
965 if (ctrl & 0x80) /* Automatic mode */
966 data->pwm_temp_map[nr] = temp_map_from_reg(data, ctrl);
967 else /* Manual mode */
968 data->pwm_duty[nr] = ctrl & 0x7f;
971 if (has_old_autopwm(data)) {
974 for (i = 0; i < 5 ; i++)
975 data->auto_temp[nr][i] = it87_read_value(data,
976 IT87_REG_AUTO_TEMP(nr, i));
977 for (i = 0; i < 3 ; i++)
978 data->auto_pwm[nr][i] = it87_read_value(data,
979 IT87_REG_AUTO_PWM(nr, i));
980 } else if (has_newer_autopwm(data)) {
984 * 0: temperature hysteresis (base + 5)
985 * 1: fan off temperature (base + 0)
986 * 2: fan start temperature (base + 1)
987 * 3: fan max temperature (base + 2)
989 data->auto_temp[nr][0] =
990 it87_read_value(data, IT87_REG_AUTO_TEMP(nr, 5));
992 for (i = 0; i < 3 ; i++)
993 data->auto_temp[nr][i + 1] =
994 it87_read_value(data,
995 IT87_REG_AUTO_TEMP(nr, i));
997 * 0: start pwm value (base + 3)
998 * 1: pwm slope (base + 4, 1/8th pwm)
1000 data->auto_pwm[nr][0] =
1001 it87_read_value(data, IT87_REG_AUTO_TEMP(nr, 3));
1002 data->auto_pwm[nr][1] =
1003 it87_read_value(data, IT87_REG_AUTO_TEMP(nr, 4));
1007 static struct it87_data *it87_update_device(struct device *dev)
1009 struct it87_data *data = dev_get_drvdata(dev);
1012 mutex_lock(&data->update_lock);
1014 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) ||
1018 * Cleared after each update, so reenable. Value
1019 * returned by this read will be previous value
1021 it87_write_value(data, IT87_REG_CONFIG,
1022 it87_read_value(data, IT87_REG_CONFIG) | 0x40);
1024 for (i = 0; i < NUM_VIN; i++) {
1025 if (!(data->has_in & BIT(i)))
1029 it87_read_value(data, IT87_REG_VIN[i]);
1031 /* VBAT and AVCC don't have limit registers */
1032 if (i >= NUM_VIN_LIMIT)
1036 it87_read_value(data, IT87_REG_VIN_MIN(i));
1038 it87_read_value(data, IT87_REG_VIN_MAX(i));
1041 for (i = 0; i < NUM_FAN; i++) {
1042 /* Skip disabled fans */
1043 if (!(data->has_fan & BIT(i)))
1047 it87_read_value(data, data->REG_FAN_MIN[i]);
1048 data->fan[i][0] = it87_read_value(data,
1050 /* Add high byte if in 16-bit mode */
1051 if (has_16bit_fans(data)) {
1052 data->fan[i][0] |= it87_read_value(data,
1053 data->REG_FANX[i]) << 8;
1054 data->fan[i][1] |= it87_read_value(data,
1055 data->REG_FANX_MIN[i]) << 8;
1058 for (i = 0; i < NUM_TEMP; i++) {
1059 if (!(data->has_temp & BIT(i)))
1062 it87_read_value(data, IT87_REG_TEMP(i));
1064 if (i >= data->num_temp_limit)
1067 if (i < data->num_temp_offset)
1069 it87_read_value(data,
1070 data->REG_TEMP_OFFSET[i]);
1073 it87_read_value(data, data->REG_TEMP_LOW[i]);
1075 it87_read_value(data, data->REG_TEMP_HIGH[i]);
1078 /* Newer chips don't have clock dividers */
1079 if ((data->has_fan & 0x07) && !has_16bit_fans(data)) {
1080 i = it87_read_value(data, IT87_REG_FAN_DIV);
1081 data->fan_div[0] = i & 0x07;
1082 data->fan_div[1] = (i >> 3) & 0x07;
1083 data->fan_div[2] = (i & 0x40) ? 3 : 1;
1087 it87_read_value(data, IT87_REG_ALARM1) |
1088 (it87_read_value(data, IT87_REG_ALARM2) << 8) |
1089 (it87_read_value(data, IT87_REG_ALARM3) << 16);
1090 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
1092 data->fan_main_ctrl = it87_read_value(data,
1093 IT87_REG_FAN_MAIN_CTRL);
1094 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL);
1095 for (i = 0; i < NUM_PWM; i++) {
1096 if (!(data->has_pwm & BIT(i)))
1098 it87_update_pwm_ctrl(data, i);
1101 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
1102 data->extra = it87_read_value(data, IT87_REG_TEMP_EXTRA);
1104 * The IT8705F does not have VID capability.
1105 * The IT8718F and later don't use IT87_REG_VID for the
1108 if (data->type == it8712 || data->type == it8716) {
1109 data->vid = it87_read_value(data, IT87_REG_VID);
1111 * The older IT8712F revisions had only 5 VID pins,
1112 * but we assume it is always safe to read 6 bits.
1116 data->last_updated = jiffies;
1120 mutex_unlock(&data->update_lock);
1125 static ssize_t show_in(struct device *dev, struct device_attribute *attr,
1128 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1129 struct it87_data *data = it87_update_device(dev);
1130 int index = sattr->index;
1133 return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr][index]));
1136 static ssize_t set_in(struct device *dev, struct device_attribute *attr,
1137 const char *buf, size_t count)
1139 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1140 struct it87_data *data = dev_get_drvdata(dev);
1141 int index = sattr->index;
1145 if (kstrtoul(buf, 10, &val) < 0)
1148 mutex_lock(&data->update_lock);
1149 data->in[nr][index] = in_to_reg(data, nr, val);
1150 it87_write_value(data,
1151 index == 1 ? IT87_REG_VIN_MIN(nr)
1152 : IT87_REG_VIN_MAX(nr),
1153 data->in[nr][index]);
1154 mutex_unlock(&data->update_lock);
1158 static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0);
1159 static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_in, set_in,
1161 static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_in, set_in,
1164 static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 1, 0);
1165 static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_in, set_in,
1167 static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_in, set_in,
1170 static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 2, 0);
1171 static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_in, set_in,
1173 static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_in, set_in,
1176 static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 3, 0);
1177 static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_in, set_in,
1179 static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_in, set_in,
1182 static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 4, 0);
1183 static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_in, set_in,
1185 static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_in, set_in,
1188 static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 5, 0);
1189 static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_in, set_in,
1191 static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_in, set_in,
1194 static SENSOR_DEVICE_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 6, 0);
1195 static SENSOR_DEVICE_ATTR_2(in6_min, S_IRUGO | S_IWUSR, show_in, set_in,
1197 static SENSOR_DEVICE_ATTR_2(in6_max, S_IRUGO | S_IWUSR, show_in, set_in,
1200 static SENSOR_DEVICE_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 7, 0);
1201 static SENSOR_DEVICE_ATTR_2(in7_min, S_IRUGO | S_IWUSR, show_in, set_in,
1203 static SENSOR_DEVICE_ATTR_2(in7_max, S_IRUGO | S_IWUSR, show_in, set_in,
1206 static SENSOR_DEVICE_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 8, 0);
1207 static SENSOR_DEVICE_ATTR_2(in9_input, S_IRUGO, show_in, NULL, 9, 0);
1208 static SENSOR_DEVICE_ATTR_2(in10_input, S_IRUGO, show_in, NULL, 10, 0);
1209 static SENSOR_DEVICE_ATTR_2(in11_input, S_IRUGO, show_in, NULL, 11, 0);
1210 static SENSOR_DEVICE_ATTR_2(in12_input, S_IRUGO, show_in, NULL, 12, 0);
1212 /* Up to 6 temperatures */
1213 static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
1216 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1218 int index = sattr->index;
1219 struct it87_data *data = it87_update_device(dev);
1221 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr][index]));
1224 static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
1225 const char *buf, size_t count)
1227 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1229 int index = sattr->index;
1230 struct it87_data *data = dev_get_drvdata(dev);
1234 if (kstrtol(buf, 10, &val) < 0)
1237 mutex_lock(&data->update_lock);
1242 reg = data->REG_TEMP_LOW[nr];
1245 reg = data->REG_TEMP_HIGH[nr];
1248 regval = it87_read_value(data, IT87_REG_BEEP_ENABLE);
1249 if (!(regval & 0x80)) {
1251 it87_write_value(data, IT87_REG_BEEP_ENABLE, regval);
1254 reg = data->REG_TEMP_OFFSET[nr];
1258 data->temp[nr][index] = TEMP_TO_REG(val);
1259 it87_write_value(data, reg, data->temp[nr][index]);
1260 mutex_unlock(&data->update_lock);
1264 static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0);
1265 static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1267 static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1269 static SENSOR_DEVICE_ATTR_2(temp1_offset, S_IRUGO | S_IWUSR, show_temp,
1271 static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, 0);
1272 static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1274 static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1276 static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IRUGO | S_IWUSR, show_temp,
1278 static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 2, 0);
1279 static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1281 static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1283 static SENSOR_DEVICE_ATTR_2(temp3_offset, S_IRUGO | S_IWUSR, show_temp,
1285 static SENSOR_DEVICE_ATTR_2(temp4_input, S_IRUGO, show_temp, NULL, 3, 0);
1286 static SENSOR_DEVICE_ATTR_2(temp4_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1288 static SENSOR_DEVICE_ATTR_2(temp4_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1290 static SENSOR_DEVICE_ATTR_2(temp4_offset, S_IRUGO | S_IWUSR, show_temp,
1292 static SENSOR_DEVICE_ATTR_2(temp5_input, S_IRUGO, show_temp, NULL, 4, 0);
1293 static SENSOR_DEVICE_ATTR_2(temp5_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1295 static SENSOR_DEVICE_ATTR_2(temp5_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1297 static SENSOR_DEVICE_ATTR_2(temp5_offset, S_IRUGO | S_IWUSR, show_temp,
1299 static SENSOR_DEVICE_ATTR_2(temp6_input, S_IRUGO, show_temp, NULL, 5, 0);
1300 static SENSOR_DEVICE_ATTR_2(temp6_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1302 static SENSOR_DEVICE_ATTR_2(temp6_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1304 static SENSOR_DEVICE_ATTR_2(temp6_offset, S_IRUGO | S_IWUSR, show_temp,
1307 static int get_temp_type(struct it87_data *data, int index)
1312 if (has_bank_sel(data)) {
1313 int s1reg = IT87_REG_TEMP_SRC1[index/2] >> ((index % 2) * 4);
1316 src1 = (it87_read_value(data, s1reg) >> ((index % 2) * 4)) & 0x0f;
1317 src2 = it87_read_value(data, IT87_REG_TEMP_SRC2);
1319 switch (data->type) {
1327 if (index == 1 || index == 2 ||
1328 index == 4 || index == 5)
1332 if (index == 2 || index == 6)
1350 type = (src2 & BIT(index)) ? 6 : 5;
1353 type = (src2 & BIT(index)) ? 4 : 6;
1356 type = (src2 & BIT(index)) ? 5 : 0;
1369 reg = it87_read_value(data, IT87_REG_TEMP_ENABLE);
1370 extra = it87_read_value(data, IT87_REG_TEMP_EXTRA);
1372 if ((has_temp_peci(data, index) && (reg >> 6 == index + 1)) ||
1373 (has_temp_old_peci(data, index) && (extra & 0x80)))
1374 type = 6; /* Intel PECI */
1375 if (reg & BIT(index))
1376 type = 3; /* thermal diode */
1377 else if (reg & BIT(index + 3))
1378 type = 4; /* thermistor */
1383 static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr,
1386 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1387 struct it87_data *data = it87_update_device(dev);
1388 int type = get_temp_type(data, sensor_attr->index);
1390 return sprintf(buf, "%d\n", type);
1393 static ssize_t set_temp_type(struct device *dev, struct device_attribute *attr,
1394 const char *buf, size_t count)
1396 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1397 int nr = sensor_attr->index;
1399 struct it87_data *data = dev_get_drvdata(dev);
1403 if (kstrtol(buf, 10, &val) < 0)
1406 reg = it87_read_value(data, IT87_REG_TEMP_ENABLE);
1409 if (has_temp_peci(data, nr) && (reg >> 6 == nr + 1 || val == 6))
1411 extra = it87_read_value(data, IT87_REG_TEMP_EXTRA);
1412 if (has_temp_old_peci(data, nr) && ((extra & 0x80) || val == 6))
1414 if (val == 2) { /* backwards compatibility */
1416 "Sensor type 2 is deprecated, please use 4 instead\n");
1419 /* 3 = thermal diode; 4 = thermistor; 6 = Intel PECI; 0 = disabled */
1424 else if (has_temp_peci(data, nr) && val == 6)
1425 reg |= (nr + 1) << 6;
1426 else if (has_temp_old_peci(data, nr) && val == 6)
1431 mutex_lock(&data->update_lock);
1433 data->extra = extra;
1434 it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor);
1435 if (has_temp_old_peci(data, nr))
1436 it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra);
1437 data->valid = 0; /* Force cache refresh */
1438 mutex_unlock(&data->update_lock);
1442 static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR, show_temp_type,
1444 static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR, show_temp_type,
1446 static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR, show_temp_type,
1448 static SENSOR_DEVICE_ATTR(temp4_type, S_IRUGO | S_IWUSR, show_temp_type,
1450 static SENSOR_DEVICE_ATTR(temp5_type, S_IRUGO | S_IWUSR, show_temp_type,
1452 static SENSOR_DEVICE_ATTR(temp6_type, S_IRUGO | S_IWUSR, show_temp_type,
1457 static int pwm_mode(const struct it87_data *data, int nr)
1459 if (has_fanctl_onoff(data) && nr < 3 &&
1460 !(data->fan_main_ctrl & BIT(nr)))
1461 return 0; /* Full speed */
1462 if (data->pwm_ctrl[nr] & 0x80)
1463 return 2; /* Automatic mode */
1464 if ((!has_fanctl_onoff(data) || nr >= 3) &&
1465 data->pwm_duty[nr] == pwm_to_reg(data, 0xff))
1466 return 0; /* Full speed */
1468 return 1; /* Manual mode */
1471 static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
1474 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1476 int index = sattr->index;
1478 struct it87_data *data = it87_update_device(dev);
1480 speed = has_16bit_fans(data) ?
1481 FAN16_FROM_REG(data->fan[nr][index]) :
1482 FAN_FROM_REG(data->fan[nr][index],
1483 DIV_FROM_REG(data->fan_div[nr]));
1484 return sprintf(buf, "%d\n", speed);
1487 static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
1490 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1491 struct it87_data *data = it87_update_device(dev);
1492 int nr = sensor_attr->index;
1494 return sprintf(buf, "%lu\n", DIV_FROM_REG(data->fan_div[nr]));
1497 static ssize_t show_pwm_enable(struct device *dev,
1498 struct device_attribute *attr, char *buf)
1500 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1501 struct it87_data *data = it87_update_device(dev);
1502 int nr = sensor_attr->index;
1504 return sprintf(buf, "%d\n", pwm_mode(data, nr));
1507 static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
1510 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1511 struct it87_data *data = it87_update_device(dev);
1512 int nr = sensor_attr->index;
1514 return sprintf(buf, "%d\n",
1515 pwm_from_reg(data, data->pwm_duty[nr]));
1518 static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
1521 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1522 struct it87_data *data = it87_update_device(dev);
1523 int nr = sensor_attr->index;
1527 if (has_pwm_freq2(data) && nr == 1)
1528 index = (data->extra >> 4) & 0x07;
1530 index = (data->fan_ctl >> 4) & 0x07;
1532 freq = pwm_freq[index] / (has_newer_autopwm(data) ? 256 : 128);
1534 return sprintf(buf, "%u\n", freq);
1537 static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
1538 const char *buf, size_t count)
1540 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1542 int index = sattr->index;
1544 struct it87_data *data = dev_get_drvdata(dev);
1548 if (kstrtol(buf, 10, &val) < 0)
1551 mutex_lock(&data->update_lock);
1553 if (has_16bit_fans(data)) {
1554 data->fan[nr][index] = FAN16_TO_REG(val);
1555 it87_write_value(data, data->REG_FAN_MIN[nr],
1556 data->fan[nr][index] & 0xff);
1557 it87_write_value(data, data->REG_FANX_MIN[nr],
1558 data->fan[nr][index] >> 8);
1560 reg = it87_read_value(data, IT87_REG_FAN_DIV);
1563 data->fan_div[nr] = reg & 0x07;
1566 data->fan_div[nr] = (reg >> 3) & 0x07;
1569 data->fan_div[nr] = (reg & 0x40) ? 3 : 1;
1572 data->fan[nr][index] =
1573 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
1574 it87_write_value(data, data->REG_FAN_MIN[nr],
1575 data->fan[nr][index]);
1578 mutex_unlock(&data->update_lock);
1582 static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
1583 const char *buf, size_t count)
1585 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1586 struct it87_data *data = dev_get_drvdata(dev);
1587 int nr = sensor_attr->index;
1592 if (kstrtoul(buf, 10, &val) < 0)
1595 mutex_lock(&data->update_lock);
1596 old = it87_read_value(data, IT87_REG_FAN_DIV);
1598 /* Save fan min limit */
1599 min = FAN_FROM_REG(data->fan[nr][1], DIV_FROM_REG(data->fan_div[nr]));
1604 data->fan_div[nr] = DIV_TO_REG(val);
1608 data->fan_div[nr] = 1;
1610 data->fan_div[nr] = 3;
1613 val |= (data->fan_div[0] & 0x07);
1614 val |= (data->fan_div[1] & 0x07) << 3;
1615 if (data->fan_div[2] == 3)
1617 it87_write_value(data, IT87_REG_FAN_DIV, val);
1619 /* Restore fan min limit */
1620 data->fan[nr][1] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
1621 it87_write_value(data, data->REG_FAN_MIN[nr], data->fan[nr][1]);
1623 mutex_unlock(&data->update_lock);
1627 /* Returns 0 if OK, -EINVAL otherwise */
1628 static int check_trip_points(struct device *dev, int nr)
1630 const struct it87_data *data = dev_get_drvdata(dev);
1633 if (has_old_autopwm(data)) {
1634 for (i = 0; i < 3; i++) {
1635 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1])
1638 for (i = 0; i < 2; i++) {
1639 if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1])
1642 } else if (has_newer_autopwm(data)) {
1643 for (i = 1; i < 3; i++) {
1644 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1])
1651 "Inconsistent trip points, not switching to automatic mode\n");
1652 dev_err(dev, "Adjust the trip points and try again\n");
1657 static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr,
1658 const char *buf, size_t count)
1660 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1661 struct it87_data *data = dev_get_drvdata(dev);
1662 int nr = sensor_attr->index;
1665 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 2)
1668 /* Check trip points before switching to automatic mode */
1670 if (check_trip_points(dev, nr) < 0)
1674 mutex_lock(&data->update_lock);
1675 it87_update_pwm_ctrl(data, nr);
1678 if (nr < 3 && has_fanctl_onoff(data)) {
1680 /* make sure the fan is on when in on/off mode */
1681 tmp = it87_read_value(data, IT87_REG_FAN_CTL);
1682 it87_write_value(data, IT87_REG_FAN_CTL, tmp | BIT(nr));
1683 /* set on/off mode */
1684 data->fan_main_ctrl &= ~BIT(nr);
1685 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
1686 data->fan_main_ctrl);
1690 /* No on/off mode, set maximum pwm value */
1691 data->pwm_duty[nr] = pwm_to_reg(data, 0xff);
1692 it87_write_value(data, IT87_REG_PWM_DUTY[nr],
1693 data->pwm_duty[nr]);
1694 /* and set manual mode */
1695 if (has_newer_autopwm(data)) {
1696 ctrl = temp_map_to_reg(data, nr,
1697 data->pwm_temp_map[nr]);
1699 ctrl = data->pwm_duty[nr];
1701 data->pwm_ctrl[nr] = ctrl;
1702 it87_write_value(data, data->REG_PWM[nr], ctrl);
1707 if (has_newer_autopwm(data)) {
1708 ctrl = temp_map_to_reg(data, nr,
1709 data->pwm_temp_map[nr]);
1713 ctrl = (val == 1 ? data->pwm_duty[nr] : 0x80);
1715 data->pwm_ctrl[nr] = ctrl;
1716 it87_write_value(data, data->REG_PWM[nr], ctrl);
1718 if (has_fanctl_onoff(data) && nr < 3) {
1719 /* set SmartGuardian mode */
1720 data->fan_main_ctrl |= BIT(nr);
1721 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
1722 data->fan_main_ctrl);
1726 mutex_unlock(&data->update_lock);
1730 static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1731 const char *buf, size_t count)
1733 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1734 struct it87_data *data = dev_get_drvdata(dev);
1735 int nr = sensor_attr->index;
1738 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
1741 mutex_lock(&data->update_lock);
1742 it87_update_pwm_ctrl(data, nr);
1743 if (has_newer_autopwm(data)) {
1745 * If we are in automatic mode, the PWM duty cycle register
1746 * is read-only so we can't write the value.
1748 if (data->pwm_ctrl[nr] & 0x80) {
1749 mutex_unlock(&data->update_lock);
1752 data->pwm_duty[nr] = pwm_to_reg(data, val);
1753 it87_write_value(data, IT87_REG_PWM_DUTY[nr],
1754 data->pwm_duty[nr]);
1756 data->pwm_duty[nr] = pwm_to_reg(data, val);
1758 * If we are in manual mode, write the duty cycle immediately;
1759 * otherwise, just store it for later use.
1761 if (!(data->pwm_ctrl[nr] & 0x80)) {
1762 data->pwm_ctrl[nr] = data->pwm_duty[nr];
1763 it87_write_value(data, data->REG_PWM[nr],
1764 data->pwm_ctrl[nr]);
1767 mutex_unlock(&data->update_lock);
1771 static ssize_t set_pwm_freq(struct device *dev, struct device_attribute *attr,
1772 const char *buf, size_t count)
1774 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1775 struct it87_data *data = dev_get_drvdata(dev);
1776 int nr = sensor_attr->index;
1780 if (kstrtoul(buf, 10, &val) < 0)
1783 val = clamp_val(val, 0, 1000000);
1784 val *= has_newer_autopwm(data) ? 256 : 128;
1786 /* Search for the nearest available frequency */
1787 for (i = 0; i < 7; i++) {
1788 if (val > (pwm_freq[i] + pwm_freq[i + 1]) / 2)
1792 mutex_lock(&data->update_lock);
1794 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f;
1795 data->fan_ctl |= i << 4;
1796 it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl);
1798 data->extra = it87_read_value(data, IT87_REG_TEMP_EXTRA) & 0x8f;
1799 data->extra |= i << 4;
1800 it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra);
1802 mutex_unlock(&data->update_lock);
1807 static ssize_t show_pwm_temp_map(struct device *dev,
1808 struct device_attribute *attr, char *buf)
1810 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1811 struct it87_data *data = it87_update_device(dev);
1812 int nr = sensor_attr->index;
1814 return sprintf(buf, "%d\n", data->pwm_temp_map[nr] + 1);
1817 static ssize_t set_pwm_temp_map(struct device *dev,
1818 struct device_attribute *attr, const char *buf,
1821 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1822 struct it87_data *data = dev_get_drvdata(dev);
1823 int nr = sensor_attr->index;
1827 if (kstrtoul(buf, 10, &val) < 0)
1830 if (!val || val > data->pwm_num_temp_map)
1835 mutex_lock(&data->update_lock);
1836 it87_update_pwm_ctrl(data, nr);
1837 data->pwm_temp_map[nr] = map;
1839 * If we are in automatic mode, write the temp mapping immediately;
1840 * otherwise, just store it for later use.
1842 if (data->pwm_ctrl[nr] & 0x80) {
1843 data->pwm_ctrl[nr] = temp_map_to_reg(data, nr, map);
1844 it87_write_value(data, data->REG_PWM[nr], data->pwm_ctrl[nr]);
1846 mutex_unlock(&data->update_lock);
1850 static ssize_t show_auto_pwm(struct device *dev, struct device_attribute *attr,
1853 struct it87_data *data = it87_update_device(dev);
1854 struct sensor_device_attribute_2 *sensor_attr =
1855 to_sensor_dev_attr_2(attr);
1856 int nr = sensor_attr->nr;
1857 int point = sensor_attr->index;
1859 return sprintf(buf, "%d\n",
1860 pwm_from_reg(data, data->auto_pwm[nr][point]));
1863 static ssize_t set_auto_pwm(struct device *dev, struct device_attribute *attr,
1864 const char *buf, size_t count)
1866 struct it87_data *data = dev_get_drvdata(dev);
1867 struct sensor_device_attribute_2 *sensor_attr =
1868 to_sensor_dev_attr_2(attr);
1869 int nr = sensor_attr->nr;
1870 int point = sensor_attr->index;
1874 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
1877 mutex_lock(&data->update_lock);
1878 data->auto_pwm[nr][point] = pwm_to_reg(data, val);
1879 if (has_newer_autopwm(data))
1880 regaddr = IT87_REG_AUTO_TEMP(nr, 3);
1882 regaddr = IT87_REG_AUTO_PWM(nr, point);
1883 it87_write_value(data, regaddr, data->auto_pwm[nr][point]);
1884 mutex_unlock(&data->update_lock);
1888 static ssize_t show_auto_pwm_slope(struct device *dev,
1889 struct device_attribute *attr, char *buf)
1891 struct it87_data *data = it87_update_device(dev);
1892 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1893 int nr = sensor_attr->index;
1895 return sprintf(buf, "%d\n", data->auto_pwm[nr][1] & 0x7f);
1898 static ssize_t set_auto_pwm_slope(struct device *dev,
1899 struct device_attribute *attr,
1900 const char *buf, size_t count)
1902 struct it87_data *data = dev_get_drvdata(dev);
1903 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1904 int nr = sensor_attr->index;
1907 if (kstrtoul(buf, 10, &val) < 0 || val > 127)
1910 mutex_lock(&data->update_lock);
1911 data->auto_pwm[nr][1] = (data->auto_pwm[nr][1] & 0x80) | val;
1912 it87_write_value(data, IT87_REG_AUTO_TEMP(nr, 4),
1913 data->auto_pwm[nr][1]);
1914 mutex_unlock(&data->update_lock);
1918 static ssize_t show_auto_temp(struct device *dev, struct device_attribute *attr,
1921 struct it87_data *data = it87_update_device(dev);
1922 struct sensor_device_attribute_2 *sensor_attr =
1923 to_sensor_dev_attr_2(attr);
1924 int nr = sensor_attr->nr;
1925 int point = sensor_attr->index;
1928 if (has_old_autopwm(data) || point)
1929 reg = data->auto_temp[nr][point];
1931 reg = data->auto_temp[nr][1] - (data->auto_temp[nr][0] & 0x1f);
1933 return sprintf(buf, "%d\n", TEMP_FROM_REG(reg));
1936 static ssize_t set_auto_temp(struct device *dev, struct device_attribute *attr,
1937 const char *buf, size_t count)
1939 struct it87_data *data = dev_get_drvdata(dev);
1940 struct sensor_device_attribute_2 *sensor_attr =
1941 to_sensor_dev_attr_2(attr);
1942 int nr = sensor_attr->nr;
1943 int point = sensor_attr->index;
1947 if (kstrtol(buf, 10, &val) < 0 || val < -128000 || val > 127000)
1950 mutex_lock(&data->update_lock);
1951 if (has_newer_autopwm(data) && !point) {
1952 reg = data->auto_temp[nr][1] - TEMP_TO_REG(val);
1953 reg = clamp_val(reg, 0, 0x1f) | (data->auto_temp[nr][0] & 0xe0);
1954 data->auto_temp[nr][0] = reg;
1955 it87_write_value(data, IT87_REG_AUTO_TEMP(nr, 5), reg);
1957 reg = TEMP_TO_REG(val);
1958 data->auto_temp[nr][point] = reg;
1959 if (has_newer_autopwm(data))
1961 it87_write_value(data, IT87_REG_AUTO_TEMP(nr, point), reg);
1963 mutex_unlock(&data->update_lock);
1967 static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0);
1968 static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1970 static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, show_fan_div,
1973 static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 1, 0);
1974 static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1976 static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, show_fan_div,
1979 static SENSOR_DEVICE_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 2, 0);
1980 static SENSOR_DEVICE_ATTR_2(fan3_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1982 static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO | S_IWUSR, show_fan_div,
1985 static SENSOR_DEVICE_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 3, 0);
1986 static SENSOR_DEVICE_ATTR_2(fan4_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1989 static SENSOR_DEVICE_ATTR_2(fan5_input, S_IRUGO, show_fan, NULL, 4, 0);
1990 static SENSOR_DEVICE_ATTR_2(fan5_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1993 static SENSOR_DEVICE_ATTR_2(fan6_input, S_IRUGO, show_fan, NULL, 5, 0);
1994 static SENSOR_DEVICE_ATTR_2(fan6_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1997 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
1998 show_pwm_enable, set_pwm_enable, 0);
1999 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0);
2000 static SENSOR_DEVICE_ATTR(pwm1_freq, S_IRUGO | S_IWUSR, show_pwm_freq,
2002 static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IRUGO,
2003 show_pwm_temp_map, set_pwm_temp_map, 0);
2004 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR,
2005 show_auto_pwm, set_auto_pwm, 0, 0);
2006 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR,
2007 show_auto_pwm, set_auto_pwm, 0, 1);
2008 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR,
2009 show_auto_pwm, set_auto_pwm, 0, 2);
2010 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO,
2011 show_auto_pwm, NULL, 0, 3);
2012 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR,
2013 show_auto_temp, set_auto_temp, 0, 1);
2014 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
2015 show_auto_temp, set_auto_temp, 0, 0);
2016 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR,
2017 show_auto_temp, set_auto_temp, 0, 2);
2018 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR,
2019 show_auto_temp, set_auto_temp, 0, 3);
2020 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR,
2021 show_auto_temp, set_auto_temp, 0, 4);
2022 static SENSOR_DEVICE_ATTR_2(pwm1_auto_start, S_IRUGO | S_IWUSR,
2023 show_auto_pwm, set_auto_pwm, 0, 0);
2024 static SENSOR_DEVICE_ATTR(pwm1_auto_slope, S_IRUGO | S_IWUSR,
2025 show_auto_pwm_slope, set_auto_pwm_slope, 0);
2027 static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR,
2028 show_pwm_enable, set_pwm_enable, 1);
2029 static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 1);
2030 static SENSOR_DEVICE_ATTR(pwm2_freq, S_IRUGO, show_pwm_freq, set_pwm_freq, 1);
2031 static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IRUGO,
2032 show_pwm_temp_map, set_pwm_temp_map, 1);
2033 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR,
2034 show_auto_pwm, set_auto_pwm, 1, 0);
2035 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO | S_IWUSR,
2036 show_auto_pwm, set_auto_pwm, 1, 1);
2037 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO | S_IWUSR,
2038 show_auto_pwm, set_auto_pwm, 1, 2);
2039 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO,
2040 show_auto_pwm, NULL, 1, 3);
2041 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR,
2042 show_auto_temp, set_auto_temp, 1, 1);
2043 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
2044 show_auto_temp, set_auto_temp, 1, 0);
2045 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR,
2046 show_auto_temp, set_auto_temp, 1, 2);
2047 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR,
2048 show_auto_temp, set_auto_temp, 1, 3);
2049 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_temp, S_IRUGO | S_IWUSR,
2050 show_auto_temp, set_auto_temp, 1, 4);
2051 static SENSOR_DEVICE_ATTR_2(pwm2_auto_start, S_IRUGO | S_IWUSR,
2052 show_auto_pwm, set_auto_pwm, 1, 0);
2053 static SENSOR_DEVICE_ATTR(pwm2_auto_slope, S_IRUGO | S_IWUSR,
2054 show_auto_pwm_slope, set_auto_pwm_slope, 1);
2056 static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR,
2057 show_pwm_enable, set_pwm_enable, 2);
2058 static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 2);
2059 static SENSOR_DEVICE_ATTR(pwm3_freq, S_IRUGO, show_pwm_freq, NULL, 2);
2060 static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IRUGO,
2061 show_pwm_temp_map, set_pwm_temp_map, 2);
2062 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO | S_IWUSR,
2063 show_auto_pwm, set_auto_pwm, 2, 0);
2064 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR,
2065 show_auto_pwm, set_auto_pwm, 2, 1);
2066 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO | S_IWUSR,
2067 show_auto_pwm, set_auto_pwm, 2, 2);
2068 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO,
2069 show_auto_pwm, NULL, 2, 3);
2070 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp, S_IRUGO | S_IWUSR,
2071 show_auto_temp, set_auto_temp, 2, 1);
2072 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
2073 show_auto_temp, set_auto_temp, 2, 0);
2074 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_temp, S_IRUGO | S_IWUSR,
2075 show_auto_temp, set_auto_temp, 2, 2);
2076 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_temp, S_IRUGO | S_IWUSR,
2077 show_auto_temp, set_auto_temp, 2, 3);
2078 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_temp, S_IRUGO | S_IWUSR,
2079 show_auto_temp, set_auto_temp, 2, 4);
2080 static SENSOR_DEVICE_ATTR_2(pwm3_auto_start, S_IRUGO | S_IWUSR,
2081 show_auto_pwm, set_auto_pwm, 2, 0);
2082 static SENSOR_DEVICE_ATTR(pwm3_auto_slope, S_IRUGO | S_IWUSR,
2083 show_auto_pwm_slope, set_auto_pwm_slope, 2);
2085 static SENSOR_DEVICE_ATTR(pwm4_enable, S_IRUGO | S_IWUSR,
2086 show_pwm_enable, set_pwm_enable, 3);
2087 static SENSOR_DEVICE_ATTR(pwm4, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 3);
2088 static SENSOR_DEVICE_ATTR(pwm4_freq, S_IRUGO, show_pwm_freq, NULL, 3);
2089 static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IRUGO,
2090 show_pwm_temp_map, set_pwm_temp_map, 3);
2091 static SENSOR_DEVICE_ATTR_2(pwm4_auto_point1_temp, S_IRUGO | S_IWUSR,
2092 show_auto_temp, set_auto_temp, 2, 1);
2093 static SENSOR_DEVICE_ATTR_2(pwm4_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
2094 show_auto_temp, set_auto_temp, 2, 0);
2095 static SENSOR_DEVICE_ATTR_2(pwm4_auto_point2_temp, S_IRUGO | S_IWUSR,
2096 show_auto_temp, set_auto_temp, 2, 2);
2097 static SENSOR_DEVICE_ATTR_2(pwm4_auto_point3_temp, S_IRUGO | S_IWUSR,
2098 show_auto_temp, set_auto_temp, 2, 3);
2099 static SENSOR_DEVICE_ATTR_2(pwm4_auto_start, S_IRUGO | S_IWUSR,
2100 show_auto_pwm, set_auto_pwm, 3, 0);
2101 static SENSOR_DEVICE_ATTR(pwm4_auto_slope, S_IRUGO | S_IWUSR,
2102 show_auto_pwm_slope, set_auto_pwm_slope, 3);
2104 static SENSOR_DEVICE_ATTR(pwm5_enable, S_IRUGO | S_IWUSR,
2105 show_pwm_enable, set_pwm_enable, 4);
2106 static SENSOR_DEVICE_ATTR(pwm5, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 4);
2107 static SENSOR_DEVICE_ATTR(pwm5_freq, S_IRUGO, show_pwm_freq, NULL, 4);
2108 static SENSOR_DEVICE_ATTR(pwm5_auto_channels_temp, S_IRUGO,
2109 show_pwm_temp_map, set_pwm_temp_map, 4);
2110 static SENSOR_DEVICE_ATTR_2(pwm5_auto_point1_temp, S_IRUGO | S_IWUSR,
2111 show_auto_temp, set_auto_temp, 2, 1);
2112 static SENSOR_DEVICE_ATTR_2(pwm5_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
2113 show_auto_temp, set_auto_temp, 2, 0);
2114 static SENSOR_DEVICE_ATTR_2(pwm5_auto_point2_temp, S_IRUGO | S_IWUSR,
2115 show_auto_temp, set_auto_temp, 2, 2);
2116 static SENSOR_DEVICE_ATTR_2(pwm5_auto_point3_temp, S_IRUGO | S_IWUSR,
2117 show_auto_temp, set_auto_temp, 2, 3);
2118 static SENSOR_DEVICE_ATTR_2(pwm5_auto_start, S_IRUGO | S_IWUSR,
2119 show_auto_pwm, set_auto_pwm, 4, 0);
2120 static SENSOR_DEVICE_ATTR(pwm5_auto_slope, S_IRUGO | S_IWUSR,
2121 show_auto_pwm_slope, set_auto_pwm_slope, 4);
2123 static SENSOR_DEVICE_ATTR(pwm6_enable, S_IRUGO | S_IWUSR,
2124 show_pwm_enable, set_pwm_enable, 5);
2125 static SENSOR_DEVICE_ATTR(pwm6, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 5);
2126 static SENSOR_DEVICE_ATTR(pwm6_freq, S_IRUGO, show_pwm_freq, NULL, 5);
2127 static SENSOR_DEVICE_ATTR(pwm6_auto_channels_temp, S_IRUGO,
2128 show_pwm_temp_map, set_pwm_temp_map, 5);
2129 static SENSOR_DEVICE_ATTR_2(pwm6_auto_point1_temp, S_IRUGO | S_IWUSR,
2130 show_auto_temp, set_auto_temp, 2, 1);
2131 static SENSOR_DEVICE_ATTR_2(pwm6_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
2132 show_auto_temp, set_auto_temp, 2, 0);
2133 static SENSOR_DEVICE_ATTR_2(pwm6_auto_point2_temp, S_IRUGO | S_IWUSR,
2134 show_auto_temp, set_auto_temp, 2, 2);
2135 static SENSOR_DEVICE_ATTR_2(pwm6_auto_point3_temp, S_IRUGO | S_IWUSR,
2136 show_auto_temp, set_auto_temp, 2, 3);
2137 static SENSOR_DEVICE_ATTR_2(pwm6_auto_start, S_IRUGO | S_IWUSR,
2138 show_auto_pwm, set_auto_pwm, 5, 0);
2139 static SENSOR_DEVICE_ATTR(pwm6_auto_slope, S_IRUGO | S_IWUSR,
2140 show_auto_pwm_slope, set_auto_pwm_slope, 5);
2143 static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
2146 struct it87_data *data = it87_update_device(dev);
2148 return sprintf(buf, "%u\n", data->alarms);
2150 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
2152 static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
2155 struct it87_data *data = it87_update_device(dev);
2156 int bitnr = to_sensor_dev_attr(attr)->index;
2158 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
2161 static ssize_t clear_intrusion(struct device *dev,
2162 struct device_attribute *attr, const char *buf,
2165 struct it87_data *data = dev_get_drvdata(dev);
2169 if (kstrtol(buf, 10, &val) < 0 || val != 0)
2172 mutex_lock(&data->update_lock);
2173 config = it87_read_value(data, IT87_REG_CONFIG);
2178 it87_write_value(data, IT87_REG_CONFIG, config);
2179 /* Invalidate cache to force re-read */
2182 mutex_unlock(&data->update_lock);
2187 static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8);
2188 static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9);
2189 static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10);
2190 static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11);
2191 static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12);
2192 static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13);
2193 static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14);
2194 static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15);
2195 static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0);
2196 static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1);
2197 static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2);
2198 static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3);
2199 static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6);
2200 static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_alarm, NULL, 7);
2201 static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16);
2202 static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17);
2203 static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18);
2204 static SENSOR_DEVICE_ATTR(temp4_alarm, S_IRUGO, show_alarm, NULL, 19);
2205 static SENSOR_DEVICE_ATTR(temp5_alarm, S_IRUGO, show_alarm, NULL, 20);
2206 static SENSOR_DEVICE_ATTR(temp6_alarm, S_IRUGO, show_alarm, NULL, 21);
2207 static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR,
2208 show_alarm, clear_intrusion, 4);
2210 static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
2213 struct it87_data *data = it87_update_device(dev);
2214 int bitnr = to_sensor_dev_attr(attr)->index;
2216 return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1);
2219 static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
2220 const char *buf, size_t count)
2222 int bitnr = to_sensor_dev_attr(attr)->index;
2223 struct it87_data *data = dev_get_drvdata(dev);
2226 if (kstrtol(buf, 10, &val) < 0 || (val != 0 && val != 1))
2229 mutex_lock(&data->update_lock);
2230 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
2232 data->beeps |= BIT(bitnr);
2234 data->beeps &= ~BIT(bitnr);
2235 it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps);
2236 mutex_unlock(&data->update_lock);
2240 static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
2241 show_beep, set_beep, 1);
2242 static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO, show_beep, NULL, 1);
2243 static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO, show_beep, NULL, 1);
2244 static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO, show_beep, NULL, 1);
2245 static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO, show_beep, NULL, 1);
2246 static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO, show_beep, NULL, 1);
2247 static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO, show_beep, NULL, 1);
2248 static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO, show_beep, NULL, 1);
2249 /* fanX_beep writability is set later */
2250 static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO, show_beep, set_beep, 0);
2251 static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0);
2252 static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0);
2253 static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0);
2254 static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0);
2255 static SENSOR_DEVICE_ATTR(fan6_beep, S_IRUGO, show_beep, set_beep, 0);
2256 static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
2257 show_beep, set_beep, 2);
2258 static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2);
2259 static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2);
2260 static SENSOR_DEVICE_ATTR(temp4_beep, S_IRUGO, show_beep, NULL, 2);
2261 static SENSOR_DEVICE_ATTR(temp5_beep, S_IRUGO, show_beep, NULL, 2);
2262 static SENSOR_DEVICE_ATTR(temp6_beep, S_IRUGO, show_beep, NULL, 2);
2264 static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
2267 struct it87_data *data = dev_get_drvdata(dev);
2269 return sprintf(buf, "%u\n", data->vrm);
2272 static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
2273 const char *buf, size_t count)
2275 struct it87_data *data = dev_get_drvdata(dev);
2278 if (kstrtoul(buf, 10, &val) < 0)
2285 static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
2287 static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
2290 struct it87_data *data = it87_update_device(dev);
2292 return sprintf(buf, "%ld\n", (long)vid_from_reg(data->vid, data->vrm));
2294 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
2296 static ssize_t show_label(struct device *dev, struct device_attribute *attr,
2299 static const char * const labels[] = {
2305 static const char * const labels_it8721[] = {
2311 struct it87_data *data = dev_get_drvdata(dev);
2312 int nr = to_sensor_dev_attr(attr)->index;
2315 if (has_vin3_5v(data) && nr == 0)
2317 else if (has_12mv_adc(data) || has_10_9mv_adc(data) ||
2319 label = labels_it8721[nr];
2323 return sprintf(buf, "%s\n", label);
2325 static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0);
2326 static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1);
2327 static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 2);
2329 static SENSOR_DEVICE_ATTR(in9_label, S_IRUGO, show_label, NULL, 3);
2331 static umode_t it87_in_is_visible(struct kobject *kobj,
2332 struct attribute *attr, int index)
2334 struct device *dev = container_of(kobj, struct device, kobj);
2335 struct it87_data *data = dev_get_drvdata(dev);
2336 int i = index / 5; /* voltage index */
2337 int a = index % 5; /* attribute index */
2339 if (index >= 40) { /* in8 and higher only have input attributes */
2344 if (!(data->has_in & BIT(i)))
2347 if (a == 4 && !data->has_beep)
2353 static struct attribute *it87_attributes_in[] = {
2354 &sensor_dev_attr_in0_input.dev_attr.attr,
2355 &sensor_dev_attr_in0_min.dev_attr.attr,
2356 &sensor_dev_attr_in0_max.dev_attr.attr,
2357 &sensor_dev_attr_in0_alarm.dev_attr.attr,
2358 &sensor_dev_attr_in0_beep.dev_attr.attr, /* 4 */
2360 &sensor_dev_attr_in1_input.dev_attr.attr,
2361 &sensor_dev_attr_in1_min.dev_attr.attr,
2362 &sensor_dev_attr_in1_max.dev_attr.attr,
2363 &sensor_dev_attr_in1_alarm.dev_attr.attr,
2364 &sensor_dev_attr_in1_beep.dev_attr.attr, /* 9 */
2366 &sensor_dev_attr_in2_input.dev_attr.attr,
2367 &sensor_dev_attr_in2_min.dev_attr.attr,
2368 &sensor_dev_attr_in2_max.dev_attr.attr,
2369 &sensor_dev_attr_in2_alarm.dev_attr.attr,
2370 &sensor_dev_attr_in2_beep.dev_attr.attr, /* 14 */
2372 &sensor_dev_attr_in3_input.dev_attr.attr,
2373 &sensor_dev_attr_in3_min.dev_attr.attr,
2374 &sensor_dev_attr_in3_max.dev_attr.attr,
2375 &sensor_dev_attr_in3_alarm.dev_attr.attr,
2376 &sensor_dev_attr_in3_beep.dev_attr.attr, /* 19 */
2378 &sensor_dev_attr_in4_input.dev_attr.attr,
2379 &sensor_dev_attr_in4_min.dev_attr.attr,
2380 &sensor_dev_attr_in4_max.dev_attr.attr,
2381 &sensor_dev_attr_in4_alarm.dev_attr.attr,
2382 &sensor_dev_attr_in4_beep.dev_attr.attr, /* 24 */
2384 &sensor_dev_attr_in5_input.dev_attr.attr,
2385 &sensor_dev_attr_in5_min.dev_attr.attr,
2386 &sensor_dev_attr_in5_max.dev_attr.attr,
2387 &sensor_dev_attr_in5_alarm.dev_attr.attr,
2388 &sensor_dev_attr_in5_beep.dev_attr.attr, /* 29 */
2390 &sensor_dev_attr_in6_input.dev_attr.attr,
2391 &sensor_dev_attr_in6_min.dev_attr.attr,
2392 &sensor_dev_attr_in6_max.dev_attr.attr,
2393 &sensor_dev_attr_in6_alarm.dev_attr.attr,
2394 &sensor_dev_attr_in6_beep.dev_attr.attr, /* 34 */
2396 &sensor_dev_attr_in7_input.dev_attr.attr,
2397 &sensor_dev_attr_in7_min.dev_attr.attr,
2398 &sensor_dev_attr_in7_max.dev_attr.attr,
2399 &sensor_dev_attr_in7_alarm.dev_attr.attr,
2400 &sensor_dev_attr_in7_beep.dev_attr.attr, /* 39 */
2402 &sensor_dev_attr_in8_input.dev_attr.attr, /* 40 */
2403 &sensor_dev_attr_in9_input.dev_attr.attr, /* 41 */
2404 &sensor_dev_attr_in10_input.dev_attr.attr, /* 42 */
2405 &sensor_dev_attr_in11_input.dev_attr.attr, /* 43 */
2406 &sensor_dev_attr_in12_input.dev_attr.attr, /* 44 */
2410 static const struct attribute_group it87_group_in = {
2411 .attrs = it87_attributes_in,
2412 .is_visible = it87_in_is_visible,
2415 static umode_t it87_temp_is_visible(struct kobject *kobj,
2416 struct attribute *attr, int index)
2418 struct device *dev = container_of(kobj, struct device, kobj);
2419 struct it87_data *data = dev_get_drvdata(dev);
2420 int i = index / 7; /* temperature index */
2421 int a = index % 7; /* attribute index */
2423 if (!(data->has_temp & BIT(i)))
2426 if (a && i >= data->num_temp_limit)
2430 int type = get_temp_type(data, i);
2434 if (has_bank_sel(data))
2439 if (a == 5 && i >= data->num_temp_offset)
2442 if (a == 6 && !data->has_beep)
2448 static struct attribute *it87_attributes_temp[] = {
2449 &sensor_dev_attr_temp1_input.dev_attr.attr,
2450 &sensor_dev_attr_temp1_max.dev_attr.attr,
2451 &sensor_dev_attr_temp1_min.dev_attr.attr,
2452 &sensor_dev_attr_temp1_type.dev_attr.attr, /* 3 */
2453 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
2454 &sensor_dev_attr_temp1_offset.dev_attr.attr, /* 5 */
2455 &sensor_dev_attr_temp1_beep.dev_attr.attr, /* 6 */
2457 &sensor_dev_attr_temp2_input.dev_attr.attr, /* 7 */
2458 &sensor_dev_attr_temp2_max.dev_attr.attr,
2459 &sensor_dev_attr_temp2_min.dev_attr.attr,
2460 &sensor_dev_attr_temp2_type.dev_attr.attr,
2461 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
2462 &sensor_dev_attr_temp2_offset.dev_attr.attr,
2463 &sensor_dev_attr_temp2_beep.dev_attr.attr,
2465 &sensor_dev_attr_temp3_input.dev_attr.attr, /* 14 */
2466 &sensor_dev_attr_temp3_max.dev_attr.attr,
2467 &sensor_dev_attr_temp3_min.dev_attr.attr,
2468 &sensor_dev_attr_temp3_type.dev_attr.attr,
2469 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
2470 &sensor_dev_attr_temp3_offset.dev_attr.attr,
2471 &sensor_dev_attr_temp3_beep.dev_attr.attr,
2473 &sensor_dev_attr_temp4_input.dev_attr.attr, /* 21 */
2474 &sensor_dev_attr_temp4_max.dev_attr.attr,
2475 &sensor_dev_attr_temp4_min.dev_attr.attr,
2476 &sensor_dev_attr_temp4_type.dev_attr.attr,
2477 &sensor_dev_attr_temp4_alarm.dev_attr.attr,
2478 &sensor_dev_attr_temp4_offset.dev_attr.attr,
2479 &sensor_dev_attr_temp4_beep.dev_attr.attr,
2481 &sensor_dev_attr_temp5_input.dev_attr.attr,
2482 &sensor_dev_attr_temp5_max.dev_attr.attr,
2483 &sensor_dev_attr_temp5_min.dev_attr.attr,
2484 &sensor_dev_attr_temp5_type.dev_attr.attr,
2485 &sensor_dev_attr_temp5_alarm.dev_attr.attr,
2486 &sensor_dev_attr_temp5_offset.dev_attr.attr,
2487 &sensor_dev_attr_temp5_beep.dev_attr.attr,
2489 &sensor_dev_attr_temp6_input.dev_attr.attr,
2490 &sensor_dev_attr_temp6_max.dev_attr.attr,
2491 &sensor_dev_attr_temp6_min.dev_attr.attr,
2492 &sensor_dev_attr_temp6_type.dev_attr.attr,
2493 &sensor_dev_attr_temp6_alarm.dev_attr.attr,
2494 &sensor_dev_attr_temp6_offset.dev_attr.attr,
2495 &sensor_dev_attr_temp6_beep.dev_attr.attr,
2499 static const struct attribute_group it87_group_temp = {
2500 .attrs = it87_attributes_temp,
2501 .is_visible = it87_temp_is_visible,
2504 static umode_t it87_is_visible(struct kobject *kobj,
2505 struct attribute *attr, int index)
2507 struct device *dev = container_of(kobj, struct device, kobj);
2508 struct it87_data *data = dev_get_drvdata(dev);
2510 if ((index == 2 || index == 3) && !data->has_vid)
2513 if (index > 3 && !(data->in_internal & BIT(index - 4)))
2519 static struct attribute *it87_attributes[] = {
2520 &dev_attr_alarms.attr,
2521 &sensor_dev_attr_intrusion0_alarm.dev_attr.attr,
2522 &dev_attr_vrm.attr, /* 2 */
2523 &dev_attr_cpu0_vid.attr, /* 3 */
2524 &sensor_dev_attr_in3_label.dev_attr.attr, /* 4 .. 7 */
2525 &sensor_dev_attr_in7_label.dev_attr.attr,
2526 &sensor_dev_attr_in8_label.dev_attr.attr,
2527 &sensor_dev_attr_in9_label.dev_attr.attr,
2531 static const struct attribute_group it87_group = {
2532 .attrs = it87_attributes,
2533 .is_visible = it87_is_visible,
2536 static umode_t it87_fan_is_visible(struct kobject *kobj,
2537 struct attribute *attr, int index)
2539 struct device *dev = container_of(kobj, struct device, kobj);
2540 struct it87_data *data = dev_get_drvdata(dev);
2541 int i = index / 5; /* fan index */
2542 int a = index % 5; /* attribute index */
2544 if (index >= 15) { /* fan 4..6 don't have divisor attributes */
2545 i = (index - 15) / 4 + 3;
2546 a = (index - 15) % 4;
2549 if (!(data->has_fan & BIT(i)))
2552 if (a == 3) { /* beep */
2553 if (!data->has_beep)
2555 /* first fan beep attribute is writable */
2556 if (i == __ffs(data->has_fan))
2557 return attr->mode | S_IWUSR;
2560 if (a == 4 && has_16bit_fans(data)) /* divisor */
2566 static struct attribute *it87_attributes_fan[] = {
2567 &sensor_dev_attr_fan1_input.dev_attr.attr,
2568 &sensor_dev_attr_fan1_min.dev_attr.attr,
2569 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
2570 &sensor_dev_attr_fan1_beep.dev_attr.attr, /* 3 */
2571 &sensor_dev_attr_fan1_div.dev_attr.attr, /* 4 */
2573 &sensor_dev_attr_fan2_input.dev_attr.attr,
2574 &sensor_dev_attr_fan2_min.dev_attr.attr,
2575 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
2576 &sensor_dev_attr_fan2_beep.dev_attr.attr,
2577 &sensor_dev_attr_fan2_div.dev_attr.attr, /* 9 */
2579 &sensor_dev_attr_fan3_input.dev_attr.attr,
2580 &sensor_dev_attr_fan3_min.dev_attr.attr,
2581 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
2582 &sensor_dev_attr_fan3_beep.dev_attr.attr,
2583 &sensor_dev_attr_fan3_div.dev_attr.attr, /* 14 */
2585 &sensor_dev_attr_fan4_input.dev_attr.attr, /* 15 */
2586 &sensor_dev_attr_fan4_min.dev_attr.attr,
2587 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
2588 &sensor_dev_attr_fan4_beep.dev_attr.attr,
2590 &sensor_dev_attr_fan5_input.dev_attr.attr, /* 19 */
2591 &sensor_dev_attr_fan5_min.dev_attr.attr,
2592 &sensor_dev_attr_fan5_alarm.dev_attr.attr,
2593 &sensor_dev_attr_fan5_beep.dev_attr.attr,
2595 &sensor_dev_attr_fan6_input.dev_attr.attr, /* 23 */
2596 &sensor_dev_attr_fan6_min.dev_attr.attr,
2597 &sensor_dev_attr_fan6_alarm.dev_attr.attr,
2598 &sensor_dev_attr_fan6_beep.dev_attr.attr,
2602 static const struct attribute_group it87_group_fan = {
2603 .attrs = it87_attributes_fan,
2604 .is_visible = it87_fan_is_visible,
2607 static umode_t it87_pwm_is_visible(struct kobject *kobj,
2608 struct attribute *attr, int index)
2610 struct device *dev = container_of(kobj, struct device, kobj);
2611 struct it87_data *data = dev_get_drvdata(dev);
2612 int i = index / 4; /* pwm index */
2613 int a = index % 4; /* attribute index */
2615 if (!(data->has_pwm & BIT(i)))
2618 /* pwmX_auto_channels_temp is only writable if auto pwm is supported */
2619 if (a == 3 && (has_old_autopwm(data) || has_newer_autopwm(data)))
2620 return attr->mode | S_IWUSR;
2622 /* pwm2_freq is writable if there are two pwm frequency selects */
2623 if (has_pwm_freq2(data) && i == 1 && a == 2)
2624 return attr->mode | S_IWUSR;
2629 static struct attribute *it87_attributes_pwm[] = {
2630 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
2631 &sensor_dev_attr_pwm1.dev_attr.attr,
2632 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
2633 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
2635 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
2636 &sensor_dev_attr_pwm2.dev_attr.attr,
2637 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
2638 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
2640 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
2641 &sensor_dev_attr_pwm3.dev_attr.attr,
2642 &sensor_dev_attr_pwm3_freq.dev_attr.attr,
2643 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
2645 &sensor_dev_attr_pwm4_enable.dev_attr.attr,
2646 &sensor_dev_attr_pwm4.dev_attr.attr,
2647 &sensor_dev_attr_pwm4_freq.dev_attr.attr,
2648 &sensor_dev_attr_pwm4_auto_channels_temp.dev_attr.attr,
2650 &sensor_dev_attr_pwm5_enable.dev_attr.attr,
2651 &sensor_dev_attr_pwm5.dev_attr.attr,
2652 &sensor_dev_attr_pwm5_freq.dev_attr.attr,
2653 &sensor_dev_attr_pwm5_auto_channels_temp.dev_attr.attr,
2655 &sensor_dev_attr_pwm6_enable.dev_attr.attr,
2656 &sensor_dev_attr_pwm6.dev_attr.attr,
2657 &sensor_dev_attr_pwm6_freq.dev_attr.attr,
2658 &sensor_dev_attr_pwm6_auto_channels_temp.dev_attr.attr,
2663 static const struct attribute_group it87_group_pwm = {
2664 .attrs = it87_attributes_pwm,
2665 .is_visible = it87_pwm_is_visible,
2668 static umode_t it87_auto_pwm_is_visible(struct kobject *kobj,
2669 struct attribute *attr, int index)
2671 struct device *dev = container_of(kobj, struct device, kobj);
2672 struct it87_data *data = dev_get_drvdata(dev);
2673 int i = index / 11; /* pwm index */
2674 int a = index % 11; /* attribute index */
2676 if (index >= 33) { /* pwm 4..6 */
2677 i = (index - 33) / 6 + 3;
2678 a = (index - 33) % 6 + 4;
2681 if (!(data->has_pwm & BIT(i)))
2684 if (has_newer_autopwm(data)) {
2685 if (a < 4) /* no auto point pwm */
2687 if (a == 8) /* no auto_point4 */
2690 if (has_old_autopwm(data)) {
2691 if (a >= 9) /* no pwm_auto_start, pwm_auto_slope */
2698 static struct attribute *it87_attributes_auto_pwm[] = {
2699 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
2700 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
2701 &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr,
2702 &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr,
2703 &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
2704 &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr,
2705 &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr,
2706 &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr,
2707 &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr,
2708 &sensor_dev_attr_pwm1_auto_start.dev_attr.attr,
2709 &sensor_dev_attr_pwm1_auto_slope.dev_attr.attr,
2711 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr, /* 11 */
2712 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
2713 &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr,
2714 &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr,
2715 &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr,
2716 &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr,
2717 &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr,
2718 &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr,
2719 &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr,
2720 &sensor_dev_attr_pwm2_auto_start.dev_attr.attr,
2721 &sensor_dev_attr_pwm2_auto_slope.dev_attr.attr,
2723 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr, /* 22 */
2724 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
2725 &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr,
2726 &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr,
2727 &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr,
2728 &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr,
2729 &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr,
2730 &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr,
2731 &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr,
2732 &sensor_dev_attr_pwm3_auto_start.dev_attr.attr,
2733 &sensor_dev_attr_pwm3_auto_slope.dev_attr.attr,
2735 &sensor_dev_attr_pwm4_auto_point1_temp.dev_attr.attr, /* 33 */
2736 &sensor_dev_attr_pwm4_auto_point1_temp_hyst.dev_attr.attr,
2737 &sensor_dev_attr_pwm4_auto_point2_temp.dev_attr.attr,
2738 &sensor_dev_attr_pwm4_auto_point3_temp.dev_attr.attr,
2739 &sensor_dev_attr_pwm4_auto_start.dev_attr.attr,
2740 &sensor_dev_attr_pwm4_auto_slope.dev_attr.attr,
2742 &sensor_dev_attr_pwm5_auto_point1_temp.dev_attr.attr,
2743 &sensor_dev_attr_pwm5_auto_point1_temp_hyst.dev_attr.attr,
2744 &sensor_dev_attr_pwm5_auto_point2_temp.dev_attr.attr,
2745 &sensor_dev_attr_pwm5_auto_point3_temp.dev_attr.attr,
2746 &sensor_dev_attr_pwm5_auto_start.dev_attr.attr,
2747 &sensor_dev_attr_pwm5_auto_slope.dev_attr.attr,
2749 &sensor_dev_attr_pwm6_auto_point1_temp.dev_attr.attr,
2750 &sensor_dev_attr_pwm6_auto_point1_temp_hyst.dev_attr.attr,
2751 &sensor_dev_attr_pwm6_auto_point2_temp.dev_attr.attr,
2752 &sensor_dev_attr_pwm6_auto_point3_temp.dev_attr.attr,
2753 &sensor_dev_attr_pwm6_auto_start.dev_attr.attr,
2754 &sensor_dev_attr_pwm6_auto_slope.dev_attr.attr,
2759 static const struct attribute_group it87_group_auto_pwm = {
2760 .attrs = it87_attributes_auto_pwm,
2761 .is_visible = it87_auto_pwm_is_visible,
2764 /* SuperIO detection - will change isa_address if a chip is found */
2765 static int __init it87_find(int sioaddr, unsigned short *address,
2766 struct it87_sio_data *sio_data)
2768 const struct it87_devices *config;
2773 err = superio_enter(sioaddr);
2778 chip_type = superio_inw(sioaddr, DEVID);
2779 if (chip_type == 0xffff)
2783 chip_type = force_id;
2785 switch (chip_type) {
2787 sio_data->type = it87;
2790 sio_data->type = it8712;
2794 sio_data->type = it8716;
2797 sio_data->type = it8718;
2800 sio_data->type = it8720;
2803 sio_data->type = it8721;
2806 sio_data->type = it8728;
2809 sio_data->type = it8732;
2812 sio_data->type = it8792;
2814 * Disabling configuration mode on IT8792E can result in system
2815 * hang-ups and access failures to the Super-IO chip at the
2816 * second SIO address. Never exit configuration mode on this
2817 * chip to avoid the problem.
2822 sio_data->type = it8771;
2825 sio_data->type = it8772;
2828 sio_data->type = it8781;
2831 sio_data->type = it8782;
2834 sio_data->type = it8783;
2837 sio_data->type = it8786;
2840 sio_data->type = it8790;
2841 doexit = false; /* See IT8792E comment above */
2845 sio_data->type = it8603;
2848 sio_data->type = it8607;
2851 sio_data->type = it8613;
2854 sio_data->type = it8620;
2857 sio_data->type = it8622;
2860 sio_data->type = it8625;
2863 sio_data->type = it8628;
2866 sio_data->type = it8655;
2869 sio_data->type = it8665;
2872 sio_data->type = it8686;
2874 case 0xffff: /* No device at all */
2877 pr_debug("Unsupported chip (DEVID=0x%x)\n", chip_type);
2881 superio_select(sioaddr, PME);
2882 if (!(superio_inb(sioaddr, IT87_ACT_REG) & 0x01)) {
2883 pr_info("Device not activated, skipping\n");
2887 *address = superio_inw(sioaddr, IT87_BASE_REG) & ~(IT87_EXTENT - 1);
2888 if (*address == 0) {
2889 pr_info("Base address not set, skipping\n");
2894 sio_data->revision = superio_inb(sioaddr, DEVREV) & 0x0f;
2895 pr_info("Found IT%04x%s chip at 0x%x, revision %d\n", chip_type,
2896 it87_devices[sio_data->type].suffix,
2897 *address, sio_data->revision);
2899 config = &it87_devices[sio_data->type];
2901 /* in7 (VSB or VCCH5V) is always internal on some chips */
2902 if (has_in7_internal(config))
2903 sio_data->internal |= BIT(1);
2905 /* in8 (Vbat) is always internal */
2906 sio_data->internal |= BIT(2);
2908 /* in9 (AVCC3), always internal if supported */
2909 if (has_avcc3(config))
2910 sio_data->internal |= BIT(3); /* in9 is AVCC */
2912 sio_data->skip_in |= BIT(9);
2914 if (!has_four_pwm(config))
2915 sio_data->skip_pwm |= BIT(3) | BIT(4) | BIT(5);
2916 else if (!has_five_pwm(config))
2917 sio_data->skip_pwm |= BIT(4) | BIT(5);
2918 else if (!has_six_pwm(config))
2919 sio_data->skip_pwm |= BIT(5);
2921 if (!has_vid(config))
2922 sio_data->skip_vid = 1;
2924 /* Read GPIO config and VID value from LDN 7 (GPIO) */
2925 if (sio_data->type == it87) {
2926 /* The IT8705F has a different LD number for GPIO */
2927 superio_select(sioaddr, 5);
2928 sio_data->beep_pin = superio_inb(sioaddr,
2929 IT87_SIO_BEEP_PIN_REG) & 0x3f;
2930 } else if (sio_data->type == it8783) {
2931 int reg25, reg27, reg2a, reg2c, regef;
2933 superio_select(sioaddr, GPIO);
2935 reg25 = superio_inb(sioaddr, IT87_SIO_GPIO1_REG);
2936 reg27 = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
2937 reg2a = superio_inb(sioaddr, IT87_SIO_PINX1_REG);
2938 reg2c = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
2939 regef = superio_inb(sioaddr, IT87_SIO_SPI_REG);
2941 /* Check if fan3 is there or not */
2942 if ((reg27 & BIT(0)) || !(reg2c & BIT(2)))
2943 sio_data->skip_fan |= BIT(2);
2944 if ((reg25 & BIT(4)) ||
2945 (!(reg2a & BIT(1)) && (regef & BIT(0))))
2946 sio_data->skip_pwm |= BIT(2);
2948 /* Check if fan2 is there or not */
2950 sio_data->skip_fan |= BIT(1);
2952 sio_data->skip_pwm |= BIT(1);
2955 if ((reg27 & BIT(0)) || (reg2c & BIT(2)))
2956 sio_data->skip_in |= BIT(5); /* No VIN5 */
2960 sio_data->skip_in |= BIT(6); /* No VIN6 */
2964 * Does not depend on bit 2 of Reg2C, contrary to datasheet.
2966 if (reg27 & BIT(2)) {
2968 * The data sheet is a bit unclear regarding the
2969 * internal voltage divider for VCCH5V. It says
2970 * "This bit enables and switches VIN7 (pin 91) to the
2971 * internal voltage divider for VCCH5V".
2972 * This is different to other chips, where the internal
2973 * voltage divider would connect VIN7 to an internal
2974 * voltage source. Maybe that is the case here as well.
2976 * Since we don't know for sure, re-route it if that is
2977 * not the case, and ask the user to report if the
2978 * resulting voltage is sane.
2980 if (!(reg2c & BIT(1))) {
2982 superio_outb(sioaddr, IT87_SIO_PINX2_REG,
2984 pr_notice("Routing internal VCCH5V to in7.\n");
2986 pr_notice("in7 routed to internal voltage divider, with external pin disabled.\n");
2987 pr_notice("Please report if it displays a reasonable voltage.\n");
2991 sio_data->internal |= BIT(0);
2993 sio_data->internal |= BIT(1);
2995 sio_data->beep_pin = superio_inb(sioaddr,
2996 IT87_SIO_BEEP_PIN_REG) & 0x3f;
2997 } else if (sio_data->type == it8603 || sio_data->type == it8607) {
3000 superio_select(sioaddr, GPIO);
3002 reg27 = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3004 /* Check if fan3 is there or not */
3006 sio_data->skip_pwm |= BIT(2);
3008 sio_data->skip_fan |= BIT(2);
3010 /* Check if fan2 is there or not */
3011 reg29 = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3013 sio_data->skip_pwm |= BIT(1);
3015 sio_data->skip_fan |= BIT(1);
3017 switch (sio_data->type) {
3019 sio_data->skip_in |= BIT(5); /* No VIN5 */
3020 sio_data->skip_in |= BIT(6); /* No VIN6 */
3023 sio_data->skip_pwm |= BIT(0);/* No fan1 */
3024 sio_data->skip_fan |= BIT(0);
3029 sio_data->beep_pin = superio_inb(sioaddr,
3030 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3031 } else if (sio_data->type == it8613) {
3032 int reg27, reg29, reg2a;
3034 superio_select(sioaddr, GPIO);
3036 /* Check for pwm3, fan3, pwm5, fan5 */
3037 reg27 = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3039 sio_data->skip_fan |= BIT(4);
3041 sio_data->skip_pwm |= BIT(4);
3043 sio_data->skip_pwm |= BIT(2);
3045 sio_data->skip_fan |= BIT(2);
3047 /* Check for pwm2, fan2 */
3048 reg29 = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3050 sio_data->skip_pwm |= BIT(1);
3052 sio_data->skip_fan |= BIT(1);
3054 /* Check for pwm4, fan4 */
3055 reg2a = superio_inb(sioaddr, IT87_SIO_PINX1_REG);
3056 if (!(reg2a & BIT(0)) || (reg29 & BIT(7))) {
3057 sio_data->skip_fan |= BIT(3);
3058 sio_data->skip_pwm |= BIT(3);
3061 sio_data->skip_pwm |= BIT(0); /* No pwm1 */
3062 sio_data->skip_fan |= BIT(0); /* No fan1 */
3063 sio_data->skip_in |= BIT(3); /* No VIN3 */
3064 sio_data->skip_in |= BIT(6); /* No VIN6 */
3066 sio_data->beep_pin = superio_inb(sioaddr,
3067 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3068 } else if (sio_data->type == it8620 || sio_data->type == it8628 ||
3069 sio_data->type == it8686) {
3072 superio_select(sioaddr, GPIO);
3074 /* Check for pwm5 */
3075 reg = superio_inb(sioaddr, IT87_SIO_GPIO1_REG);
3077 sio_data->skip_pwm |= BIT(4);
3079 /* Check for fan4, fan5 */
3080 reg = superio_inb(sioaddr, IT87_SIO_GPIO2_REG);
3081 if (!(reg & BIT(5)))
3082 sio_data->skip_fan |= BIT(3);
3083 if (!(reg & BIT(4)))
3084 sio_data->skip_fan |= BIT(4);
3086 /* Check for pwm3, fan3 */
3087 reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3089 sio_data->skip_pwm |= BIT(2);
3091 sio_data->skip_fan |= BIT(2);
3093 /* Check for pwm4 */
3094 reg = superio_inb(sioaddr, IT87_SIO_GPIO4_REG);
3096 sio_data->skip_pwm |= BIT(3);
3098 /* Check for pwm2, fan2 */
3099 reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3101 sio_data->skip_pwm |= BIT(1);
3103 sio_data->skip_fan |= BIT(1);
3104 /* Check for pwm6, fan6 */
3105 if (!(reg & BIT(7))) {
3106 sio_data->skip_pwm |= BIT(5);
3107 sio_data->skip_fan |= BIT(5);
3110 /* Check if AVCC is on VIN3 */
3111 reg = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
3113 /* For it8686, the bit just enables AVCC3 */
3114 if (sio_data->type != it8686)
3115 sio_data->internal |= BIT(0);
3117 sio_data->internal &= ~BIT(3);
3118 sio_data->skip_in |= BIT(9);
3121 sio_data->beep_pin = superio_inb(sioaddr,
3122 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3123 } else if (sio_data->type == it8622) {
3126 superio_select(sioaddr, GPIO);
3128 /* Check for pwm4, fan4 */
3129 reg = superio_inb(sioaddr, IT87_SIO_GPIO1_REG);
3131 sio_data->skip_fan |= BIT(3);
3133 sio_data->skip_pwm |= BIT(3);
3135 /* Check for pwm3, fan3, pwm5, fan5 */
3136 reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3138 sio_data->skip_pwm |= BIT(2);
3140 sio_data->skip_fan |= BIT(2);
3142 sio_data->skip_pwm |= BIT(4);
3144 sio_data->skip_fan |= BIT(4);
3146 /* Check for pwm2, fan2 */
3147 reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3149 sio_data->skip_pwm |= BIT(1);
3151 sio_data->skip_fan |= BIT(1);
3153 /* Check for AVCC */
3154 reg = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
3155 if (!(reg & BIT(0)))
3156 sio_data->skip_in |= BIT(9);
3158 sio_data->beep_pin = superio_inb(sioaddr,
3159 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3160 } else if (sio_data->type == it8732) {
3163 superio_select(sioaddr, GPIO);
3165 /* Check for pwm2, fan2 */
3166 reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3168 sio_data->skip_pwm |= BIT(1);
3170 sio_data->skip_fan |= BIT(1);
3172 /* Check for pwm3, fan3, fan4 */
3173 reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3175 sio_data->skip_pwm |= BIT(2);
3177 sio_data->skip_fan |= BIT(2);
3179 sio_data->skip_fan |= BIT(3);
3181 /* Check if AVCC is on VIN3 */
3182 reg = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
3184 sio_data->internal |= BIT(0);
3186 sio_data->beep_pin = superio_inb(sioaddr,
3187 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3188 } else if (sio_data->type == it8655) {
3191 superio_select(sioaddr, GPIO);
3193 /* Check for pwm2 */
3194 reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3196 sio_data->skip_pwm |= BIT(1);
3198 /* Check for fan2 */
3199 reg = superio_inb(sioaddr, IT87_SIO_PINX4_REG);
3201 sio_data->skip_fan |= BIT(1);
3203 /* Check for pwm3, fan3 */
3204 reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3206 sio_data->skip_pwm |= BIT(2);
3208 sio_data->skip_fan |= BIT(2);
3210 sio_data->beep_pin = superio_inb(sioaddr,
3211 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3212 } else if (sio_data->type == it8665 || sio_data->type == it8625) {
3213 int reg27, reg29, reg2d, regd3;
3215 superio_select(sioaddr, GPIO);
3217 reg27 = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3218 reg29 = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3219 reg2d = superio_inb(sioaddr, IT87_SIO_PINX4_REG);
3220 regd3 = superio_inb(sioaddr, IT87_SIO_GPIO9_REG);
3222 /* Check for pwm2, fan2 */
3224 sio_data->skip_pwm |= BIT(1);
3226 sio_data->skip_fan |= BIT(1);
3228 /* Check for pwm3, fan3 */
3230 sio_data->skip_pwm |= BIT(2);
3232 sio_data->skip_fan |= BIT(2);
3234 /* Check for pwm4, fan4, pwm5, fan5 */
3235 if (sio_data->type == it8625) {
3236 int reg25 = superio_inb(sioaddr, IT87_SIO_GPIO1_REG);
3239 sio_data->skip_fan |= BIT(3);
3241 sio_data->skip_pwm |= BIT(3);
3243 sio_data->skip_pwm |= BIT(4);
3245 sio_data->skip_fan |= BIT(4);
3247 int reg26 = superio_inb(sioaddr, IT87_SIO_GPIO2_REG);
3250 sio_data->skip_pwm |= BIT(3);
3252 sio_data->skip_fan |= BIT(3);
3254 sio_data->skip_pwm |= BIT(4);
3255 if (!(reg26 & BIT(4)))
3256 sio_data->skip_fan |= BIT(4);
3259 /* Check for pwm6, fan6 */
3261 sio_data->skip_pwm |= BIT(5);
3263 sio_data->skip_fan |= BIT(5);
3265 sio_data->beep_pin = superio_inb(sioaddr,
3266 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3271 superio_select(sioaddr, GPIO);
3273 /* Check for fan4, fan5 */
3274 if (has_five_fans(config)) {
3275 reg = superio_inb(sioaddr, IT87_SIO_GPIO2_REG);
3276 switch (sio_data->type) {
3279 sio_data->skip_fan |= BIT(3);
3281 sio_data->skip_fan |= BIT(4);
3286 if (!(reg & BIT(5)))
3287 sio_data->skip_fan |= BIT(3);
3288 if (!(reg & BIT(4)))
3289 sio_data->skip_fan |= BIT(4);
3296 reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3297 if (!sio_data->skip_vid) {
3298 /* We need at least 4 VID pins */
3300 pr_info("VID is disabled (pins used for GPIO)\n");
3301 sio_data->skip_vid = 1;
3305 /* Check if fan3 is there or not */
3307 sio_data->skip_pwm |= BIT(2);
3309 sio_data->skip_fan |= BIT(2);
3311 /* Check if fan2 is there or not */
3312 reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3314 sio_data->skip_pwm |= BIT(1);
3316 sio_data->skip_fan |= BIT(1);
3318 if ((sio_data->type == it8718 || sio_data->type == it8720) &&
3319 !(sio_data->skip_vid))
3320 sio_data->vid_value = superio_inb(sioaddr,
3323 reg = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
3325 uart6 = sio_data->type == it8782 && (reg & BIT(2));
3328 * The IT8720F has no VIN7 pin, so VCCH should always be
3329 * routed internally to VIN7 with an internal divider.
3330 * Curiously, there still is a configuration bit to control
3331 * this, which means it can be set incorrectly. And even
3332 * more curiously, many boards out there are improperly
3333 * configured, even though the IT8720F datasheet claims
3334 * that the internal routing of VCCH to VIN7 is the default
3335 * setting. So we force the internal routing in this case.
3337 * On IT8782F, VIN7 is multiplexed with one of the UART6 pins.
3338 * If UART6 is enabled, re-route VIN7 to the internal divider
3339 * if that is not already the case.
3341 if ((sio_data->type == it8720 || uart6) && !(reg & BIT(1))) {
3343 superio_outb(sioaddr, IT87_SIO_PINX2_REG, reg);
3344 pr_notice("Routing internal VCCH to in7\n");
3347 sio_data->internal |= BIT(0);
3349 sio_data->internal |= BIT(1);
3352 * On IT8782F, UART6 pins overlap with VIN5, VIN6, and VIN7.
3353 * While VIN7 can be routed to the internal voltage divider,
3354 * VIN5 and VIN6 are not available if UART6 is enabled.
3356 * Also, temp3 is not available if UART6 is enabled and TEMPIN3
3357 * is the temperature source. Since we can not read the
3358 * temperature source here, skip_temp is preliminary.
3361 sio_data->skip_in |= BIT(5) | BIT(6);
3362 sio_data->skip_temp |= BIT(2);
3365 sio_data->beep_pin = superio_inb(sioaddr,
3366 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3368 if (sio_data->beep_pin)
3369 pr_info("Beeping is supported\n");
3372 superio_exit(sioaddr, doexit);
3376 static void it87_init_regs(struct platform_device *pdev)
3378 struct it87_data *data = platform_get_drvdata(pdev);
3380 /* Initialize chip specific register pointers */
3381 switch (data->type) {
3384 data->REG_FAN = IT87_REG_FAN;
3385 data->REG_FANX = IT87_REG_FANX;
3386 data->REG_FAN_MIN = IT87_REG_FAN_MIN;
3387 data->REG_FANX_MIN = IT87_REG_FANX_MIN;
3388 data->REG_PWM = IT87_REG_PWM;
3389 data->REG_TEMP_OFFSET = IT87_REG_TEMP_OFFSET_8686;
3390 data->REG_TEMP_LOW = IT87_REG_TEMP_LOW_8686;
3391 data->REG_TEMP_HIGH = IT87_REG_TEMP_HIGH_8686;
3396 data->REG_FAN = IT87_REG_FAN_8665;
3397 data->REG_FANX = IT87_REG_FANX_8665;
3398 data->REG_FAN_MIN = IT87_REG_FAN_MIN_8665;
3399 data->REG_FANX_MIN = IT87_REG_FANX_MIN_8665;
3400 data->REG_PWM = IT87_REG_PWM_8665;
3401 data->REG_TEMP_OFFSET = IT87_REG_TEMP_OFFSET;
3402 data->REG_TEMP_LOW = IT87_REG_TEMP_LOW;
3403 data->REG_TEMP_HIGH = IT87_REG_TEMP_HIGH;
3406 data->REG_FAN = IT87_REG_FAN;
3407 data->REG_FANX = IT87_REG_FANX;
3408 data->REG_FAN_MIN = IT87_REG_FAN_MIN;
3409 data->REG_FANX_MIN = IT87_REG_FANX_MIN;
3410 data->REG_PWM = IT87_REG_PWM_8665;
3411 data->REG_TEMP_OFFSET = IT87_REG_TEMP_OFFSET;
3412 data->REG_TEMP_LOW = IT87_REG_TEMP_LOW;
3413 data->REG_TEMP_HIGH = IT87_REG_TEMP_HIGH;
3416 data->REG_FAN = IT87_REG_FAN;
3417 data->REG_FANX = IT87_REG_FANX;
3418 data->REG_FAN_MIN = IT87_REG_FAN_MIN;
3419 data->REG_FANX_MIN = IT87_REG_FANX_MIN;
3420 data->REG_PWM = IT87_REG_PWM_8665;
3421 data->REG_TEMP_OFFSET = IT87_REG_TEMP_OFFSET;
3422 data->REG_TEMP_LOW = IT87_REG_TEMP_LOW;
3423 data->REG_TEMP_HIGH = IT87_REG_TEMP_HIGH;
3426 data->REG_FAN = IT87_REG_FAN;
3427 data->REG_FANX = IT87_REG_FANX;
3428 data->REG_FAN_MIN = IT87_REG_FAN_MIN;
3429 data->REG_FANX_MIN = IT87_REG_FANX_MIN;
3430 data->REG_PWM = IT87_REG_PWM;
3431 data->REG_TEMP_OFFSET = IT87_REG_TEMP_OFFSET;
3432 data->REG_TEMP_LOW = IT87_REG_TEMP_LOW;
3433 data->REG_TEMP_HIGH = IT87_REG_TEMP_HIGH;
3438 /* Called when we have found a new IT87. */
3439 static void it87_init_device(struct platform_device *pdev)
3441 struct it87_sio_data *sio_data = dev_get_platdata(&pdev->dev);
3442 struct it87_data *data = platform_get_drvdata(pdev);
3446 if (has_new_tempmap(data)) {
3447 data->pwm_temp_map_shift = 3;
3448 data->pwm_temp_map_mask = 0x07;
3450 data->pwm_temp_map_shift = 0;
3451 data->pwm_temp_map_mask = 0x03;
3455 * For each PWM channel:
3456 * - If it is in automatic mode, setting to manual mode should set
3457 * the fan to full speed by default.
3458 * - If it is in manual mode, we need a mapping to temperature
3459 * channels to use when later setting to automatic mode later.
3460 * Map to the first sensor by default (we are clueless.)
3461 * In both cases, the value can (and should) be changed by the user
3462 * prior to switching to a different mode.
3463 * Note that this is no longer needed for the IT8721F and later, as
3464 * these have separate registers for the temperature mapping and the
3465 * manual duty cycle.
3467 for (i = 0; i < NUM_AUTO_PWM; i++) {
3468 data->pwm_temp_map[i] = 0;
3469 data->pwm_duty[i] = 0x7f; /* Full speed */
3470 data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */
3474 * Some chips seem to have default value 0xff for all limit
3475 * registers. For low voltage limits it makes no sense and triggers
3476 * alarms, so change to 0 instead. For high temperature limits, it
3477 * means -1 degree C, which surprisingly doesn't trigger an alarm,
3478 * but is still confusing, so change to 127 degrees C.
3480 for (i = 0; i < NUM_VIN_LIMIT; i++) {
3481 tmp = it87_read_value(data, IT87_REG_VIN_MIN(i));
3483 it87_write_value(data, IT87_REG_VIN_MIN(i), 0);
3485 for (i = 0; i < data->num_temp_limit; i++) {
3486 tmp = it87_read_value(data, data->REG_TEMP_HIGH[i]);
3488 it87_write_value(data, data->REG_TEMP_HIGH[i], 127);
3492 * Temperature channels are not forcibly enabled, as they can be
3493 * set to two different sensor types and we can't guess which one
3494 * is correct for a given system. These channels can be enabled at
3495 * run-time through the temp{1-3}_type sysfs accessors if needed.
3498 /* Check if voltage monitors are reset manually or by some reason */
3499 tmp = it87_read_value(data, IT87_REG_VIN_ENABLE);
3500 if ((tmp & 0xff) == 0) {
3501 /* Enable all voltage monitors */
3502 it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff);
3505 /* Check if tachometers are reset manually or by some reason */
3506 mask = 0x70 & ~(sio_data->skip_fan << 4);
3507 data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL);
3508 if ((data->fan_main_ctrl & mask) == 0) {
3509 /* Enable all fan tachometers */
3510 data->fan_main_ctrl |= mask;
3511 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
3512 data->fan_main_ctrl);
3514 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
3516 tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
3518 /* Set tachometers to 16-bit mode if needed */
3519 if (has_fan16_config(data)) {
3520 if (~tmp & 0x07 & data->has_fan) {
3522 "Setting fan1-3 to 16-bit mode\n");
3523 it87_write_value(data, IT87_REG_FAN_16BIT,
3528 /* Check for additional fans */
3529 if (has_four_fans(data) && (tmp & BIT(4)))
3530 data->has_fan |= BIT(3); /* fan4 enabled */
3531 if (has_five_fans(data) && (tmp & BIT(5)))
3532 data->has_fan |= BIT(4); /* fan5 enabled */
3533 if (has_six_fans(data)) {
3534 switch (data->type) {
3539 data->has_fan |= BIT(5); /* fan6 enabled */
3543 tmp = it87_read_value(data, IT87_REG_FAN_DIV);
3545 data->has_fan |= BIT(5); /* fan6 enabled */
3552 /* Fan input pins may be used for alternative functions */
3553 data->has_fan &= ~sio_data->skip_fan;
3555 /* Check if pwm6 is enabled */
3556 if (has_six_pwm(data)) {
3557 switch (data->type) {
3560 tmp = it87_read_value(data, IT87_REG_FAN_DIV);
3561 if (!(tmp & BIT(3)))
3562 sio_data->skip_pwm |= BIT(5);
3569 /* Start monitoring */
3570 it87_write_value(data, IT87_REG_CONFIG,
3571 (it87_read_value(data, IT87_REG_CONFIG) & 0x3e)
3572 | (update_vbat ? 0x41 : 0x01));
3575 /* Return 1 if and only if the PWM interface is safe to use */
3576 static int it87_check_pwm(struct device *dev)
3578 struct it87_data *data = dev_get_drvdata(dev);
3580 * Some BIOSes fail to correctly configure the IT87 fans. All fans off
3581 * and polarity set to active low is sign that this is the case so we
3582 * disable pwm control to protect the user.
3584 int tmp = it87_read_value(data, IT87_REG_FAN_CTL);
3586 if ((tmp & 0x87) == 0) {
3587 if (fix_pwm_polarity) {
3589 * The user asks us to attempt a chip reconfiguration.
3590 * This means switching to active high polarity and
3591 * inverting all fan speed values.
3596 for (i = 0; i < ARRAY_SIZE(pwm); i++)
3597 pwm[i] = it87_read_value(data,
3601 * If any fan is in automatic pwm mode, the polarity
3602 * might be correct, as suspicious as it seems, so we
3603 * better don't change anything (but still disable the
3606 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
3608 "Reconfiguring PWM to active high polarity\n");
3609 it87_write_value(data, IT87_REG_FAN_CTL,
3611 for (i = 0; i < 3; i++)
3612 it87_write_value(data,
3619 "PWM configuration is too broken to be fixed\n");
3623 "Detected broken BIOS defaults, disabling PWM interface\n");
3625 } else if (fix_pwm_polarity) {
3627 "PWM configuration looks sane, won't touch\n");
3633 static int it87_probe(struct platform_device *pdev)
3635 struct it87_data *data;
3636 struct resource *res;
3637 struct device *dev = &pdev->dev;
3638 struct it87_sio_data *sio_data = dev_get_platdata(dev);
3639 int enable_pwm_interface;
3640 struct device *hwmon_dev;
3642 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
3643 if (!devm_request_region(&pdev->dev, res->start, IT87_EC_EXTENT,
3645 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
3646 (unsigned long)res->start,
3647 (unsigned long)(res->start + IT87_EC_EXTENT - 1));
3651 data = devm_kzalloc(&pdev->dev, sizeof(struct it87_data), GFP_KERNEL);
3655 data->addr = res->start;
3656 data->type = sio_data->type;
3657 data->features = it87_devices[sio_data->type].features;
3658 data->num_temp_limit = it87_devices[sio_data->type].num_temp_limit;
3659 data->num_temp_offset = it87_devices[sio_data->type].num_temp_offset;
3660 data->pwm_num_temp_map = it87_devices[sio_data->type].num_temp_map;
3661 data->peci_mask = it87_devices[sio_data->type].peci_mask;
3662 data->old_peci_mask = it87_devices[sio_data->type].old_peci_mask;
3666 * IT8705F Datasheet 0.4.1, 3h == Version G.
3667 * IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J.
3668 * These are the first revisions with 16-bit tachometer support.
3670 switch (data->type) {
3672 if (sio_data->revision >= 0x03) {
3673 data->features &= ~FEAT_OLD_AUTOPWM;
3674 data->features |= FEAT_FAN16_CONFIG | FEAT_16BIT_FANS;
3678 if (sio_data->revision >= 0x08) {
3679 data->features &= ~FEAT_OLD_AUTOPWM;
3680 data->features |= FEAT_FAN16_CONFIG | FEAT_16BIT_FANS |
3688 /* Now, we do the remaining detection. */
3689 if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80) ||
3690 it87_read_value(data, IT87_REG_CHIPID) != 0x90)
3693 platform_set_drvdata(pdev, data);
3695 mutex_init(&data->update_lock);
3697 /* Initialize register pointers */
3698 it87_init_regs(pdev);
3700 /* Check PWM configuration */
3701 enable_pwm_interface = it87_check_pwm(dev);
3703 /* Starting with IT8721F, we handle scaling of internal voltages */
3704 if (has_scaling(data)) {
3705 if (sio_data->internal & BIT(0))
3706 data->in_scaled |= BIT(3); /* in3 is AVCC */
3707 if (sio_data->internal & BIT(1))
3708 data->in_scaled |= BIT(7); /* in7 is VSB */
3709 if (sio_data->internal & BIT(2))
3710 data->in_scaled |= BIT(8); /* in8 is Vbat */
3711 if (sio_data->internal & BIT(3))
3712 data->in_scaled |= BIT(9); /* in9 is AVCC */
3713 } else if (sio_data->type == it8781 || sio_data->type == it8782 ||
3714 sio_data->type == it8783) {
3715 if (sio_data->internal & BIT(0))
3716 data->in_scaled |= BIT(3); /* in3 is VCC5V */
3717 if (sio_data->internal & BIT(1))
3718 data->in_scaled |= BIT(7); /* in7 is VCCH5V */
3721 data->has_temp = 0x07;
3722 if (sio_data->skip_temp & BIT(2)) {
3723 if (sio_data->type == it8782 &&
3724 !(it87_read_value(data, IT87_REG_TEMP_EXTRA) & 0x80))
3725 data->has_temp &= ~BIT(2);
3728 data->in_internal = sio_data->internal;
3729 data->has_in = 0x3ff & ~sio_data->skip_in;
3731 if (has_six_temp(data)) {
3732 u8 reg = it87_read_value(data, IT87_REG_TEMP456_ENABLE);
3734 /* Check for additional temperature sensors */
3735 if ((reg & 0x03) >= 0x02)
3736 data->has_temp |= BIT(3);
3737 if (((reg >> 2) & 0x03) >= 0x02)
3738 data->has_temp |= BIT(4);
3739 if (((reg >> 4) & 0x03) >= 0x02)
3740 data->has_temp |= BIT(5);
3742 /* Check for additional voltage sensors */
3743 if ((reg & 0x03) == 0x01)
3744 data->has_in |= BIT(10);
3745 if (((reg >> 2) & 0x03) == 0x01)
3746 data->has_in |= BIT(11);
3747 if (((reg >> 4) & 0x03) == 0x01)
3748 data->has_in |= BIT(12);
3751 data->has_beep = !!sio_data->beep_pin;
3753 /* Initialize the IT87 chip */
3754 it87_init_device(pdev);
3756 if (!sio_data->skip_vid) {
3757 data->has_vid = true;
3758 data->vrm = vid_which_vrm();
3759 /* VID reading from Super-I/O config space if available */
3760 data->vid = sio_data->vid_value;
3763 /* Prepare for sysfs hooks */
3764 data->groups[0] = &it87_group;
3765 data->groups[1] = &it87_group_in;
3766 data->groups[2] = &it87_group_temp;
3767 data->groups[3] = &it87_group_fan;
3769 if (enable_pwm_interface) {
3770 data->has_pwm = BIT(ARRAY_SIZE(IT87_REG_PWM)) - 1;
3771 data->has_pwm &= ~sio_data->skip_pwm;
3773 data->groups[4] = &it87_group_pwm;
3774 if (has_old_autopwm(data) || has_newer_autopwm(data))
3775 data->groups[5] = &it87_group_auto_pwm;
3778 hwmon_dev = devm_hwmon_device_register_with_groups(dev,
3779 it87_devices[sio_data->type].name,
3780 data, data->groups);
3781 return PTR_ERR_OR_ZERO(hwmon_dev);
3784 static struct platform_driver it87_driver = {
3788 .probe = it87_probe,
3791 static int __init it87_device_add(int index, unsigned short address,
3792 const struct it87_sio_data *sio_data)
3794 struct platform_device *pdev;
3795 struct resource res = {
3796 .start = address + IT87_EC_OFFSET,
3797 .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1,
3799 .flags = IORESOURCE_IO,
3803 err = acpi_check_resource_conflict(&res);
3807 pdev = platform_device_alloc(DRVNAME, address);
3811 err = platform_device_add_resources(pdev, &res, 1);
3813 pr_err("Device resource addition failed (%d)\n", err);
3814 goto exit_device_put;
3817 err = platform_device_add_data(pdev, sio_data,
3818 sizeof(struct it87_sio_data));
3820 pr_err("Platform data allocation failed\n");
3821 goto exit_device_put;
3824 err = platform_device_add(pdev);
3826 pr_err("Device addition failed (%d)\n", err);
3827 goto exit_device_put;
3830 it87_pdev[index] = pdev;
3834 platform_device_put(pdev);
3838 struct it87_dmi_data {
3839 bool sio2_force_config; /* force sio2 into configuration mode */
3840 u8 skip_pwm; /* pwm channels to skip for this board */
3844 * On various Gigabyte AM4 boards (AB350, AX370), the second Super-IO chip
3845 * (IT8792E) needs to be in configuration mode before accessing the first
3846 * due to a bug in IT8792E which otherwise results in LPC bus access errors.
3847 * This needs to be done before accessing the first Super-IO chip since
3848 * the second chip may have been accessed prior to loading this driver.
3850 * The problem is also reported to affect IT8795E, which is used on X299 boards
3851 * and has the same chip ID as IT9792E (0x8733). It also appears to affect
3852 * systems with IT8790E, which is used on some Z97X-Gaming boards as well as
3854 * DMI entries for those systems will be added as they become available and
3855 * as the problem is confirmed to affect those boards.
3857 static struct it87_dmi_data gigabyte_sio2_force = {
3858 .sio2_force_config = true,
3862 * On the Shuttle SN68PT, FAN_CTL2 is apparently not
3863 * connected to a fan, but to something else. One user
3864 * has reported instant system power-off when changing
3865 * the PWM2 duty cycle, so we disable it.
3866 * I use the board name string as the trigger in case
3867 * the same board is ever used in other systems.
3869 static struct it87_dmi_data nvidia_fn68pt = {
3873 static const struct dmi_system_id it87_dmi_table[] __initconst = {
3876 DMI_MATCH(DMI_SYS_VENDOR, "Gigabyte Technology Co., Ltd."),
3877 DMI_MATCH(DMI_BOARD_NAME, "AB350"),
3879 .driver_data = &gigabyte_sio2_force,
3883 DMI_MATCH(DMI_SYS_VENDOR, "Gigabyte Technology Co., Ltd."),
3884 DMI_MATCH(DMI_BOARD_NAME, "AX370"),
3886 .driver_data = &gigabyte_sio2_force,
3890 DMI_MATCH(DMI_SYS_VENDOR, "Gigabyte Technology Co., Ltd."),
3891 DMI_MATCH(DMI_BOARD_NAME, "Z97X-Gaming G1"),
3893 .driver_data = &gigabyte_sio2_force,
3897 DMI_MATCH(DMI_BOARD_VENDOR, "nVIDIA"),
3898 DMI_MATCH(DMI_BOARD_NAME, "FN68PT"),
3900 .driver_data = &nvidia_fn68pt,
3905 static int __init sm_it87_init(void)
3907 const struct dmi_system_id *dmi = dmi_first_match(it87_dmi_table);
3908 struct it87_dmi_data *dmi_data = NULL;
3909 int sioaddr[2] = { REG_2E, REG_4E };
3910 struct it87_sio_data sio_data;
3911 unsigned short isa_address;
3916 dmi_data = dmi->driver_data;
3918 err = platform_driver_register(&it87_driver);
3922 if (dmi_data && dmi_data->sio2_force_config)
3923 __superio_enter(REG_4E);
3925 for (i = 0; i < ARRAY_SIZE(sioaddr); i++) {
3926 memset(&sio_data, 0, sizeof(struct it87_sio_data));
3928 err = it87_find(sioaddr[i], &isa_address, &sio_data);
3929 if (err || isa_address == 0)
3933 sio_data.skip_pwm |= dmi_data->skip_pwm;
3934 err = it87_device_add(i, isa_address, &sio_data);
3936 goto exit_dev_unregister;
3942 goto exit_unregister;
3946 exit_dev_unregister:
3947 /* NULL check handled by platform_device_unregister */
3948 platform_device_unregister(it87_pdev[0]);
3950 platform_driver_unregister(&it87_driver);
3954 static void __exit sm_it87_exit(void)
3956 /* NULL check handled by platform_device_unregister */
3957 platform_device_unregister(it87_pdev[1]);
3958 platform_device_unregister(it87_pdev[0]);
3959 platform_driver_unregister(&it87_driver);
3962 MODULE_AUTHOR("Chris Gauthron, Jean Delvare <jdelvare@suse.de>");
3963 MODULE_DESCRIPTION("IT8705F/IT871xF/IT872xF hardware monitoring driver");
3964 module_param(update_vbat, bool, 0);
3965 MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
3966 module_param(fix_pwm_polarity, bool, 0);
3967 MODULE_PARM_DESC(fix_pwm_polarity,
3968 "Force PWM polarity to active high (DANGEROUS)");
3969 MODULE_LICENSE("GPL");
3971 module_init(sm_it87_init);
3972 module_exit(sm_it87_exit);