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 * IT8628E Super I/O chip w/LPC interface
20 * IT8655E Super I/O chip w/LPC interface
21 * IT8665E Super I/O chip w/LPC interface
22 * IT8686E Super I/O chip w/LPC interface
23 * IT8705F Super I/O chip w/LPC interface
24 * IT8712F Super I/O chip w/LPC interface
25 * IT8716F Super I/O chip w/LPC interface
26 * IT8718F Super I/O chip w/LPC interface
27 * IT8720F Super I/O chip w/LPC interface
28 * IT8721F Super I/O chip w/LPC interface
29 * IT8726F Super I/O chip w/LPC interface
30 * IT8728F Super I/O chip w/LPC interface
31 * IT8732F Super I/O chip w/LPC interface
32 * IT8758E Super I/O chip w/LPC interface
33 * IT8771E Super I/O chip w/LPC interface
34 * IT8772E Super I/O chip w/LPC interface
35 * IT8781F Super I/O chip w/LPC interface
36 * IT8782F Super I/O chip w/LPC interface
37 * IT8783E/F Super I/O chip w/LPC interface
38 * IT8786E Super I/O chip w/LPC interface
39 * IT8790E Super I/O chip w/LPC interface
40 * IT8792E Super I/O chip w/LPC interface
41 * Sis950 A clone of the IT8705F
43 * Copyright (C) 2001 Chris Gauthron
44 * Copyright (C) 2005-2010 Jean Delvare <jdelvare@suse.de>
46 * This program is free software; you can redistribute it and/or modify
47 * it under the terms of the GNU General Public License as published by
48 * the Free Software Foundation; either version 2 of the License, or
49 * (at your option) any later version.
51 * This program is distributed in the hope that it will be useful,
52 * but WITHOUT ANY WARRANTY; without even the implied warranty of
53 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
54 * GNU General Public License for more details.
57 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
59 #include <linux/bitops.h>
60 #include <linux/module.h>
61 #include <linux/init.h>
62 #include <linux/slab.h>
63 #include <linux/jiffies.h>
64 #include <linux/platform_device.h>
65 #include <linux/hwmon.h>
66 #include <linux/hwmon-sysfs.h>
67 #include <linux/hwmon-vid.h>
68 #include <linux/err.h>
69 #include <linux/mutex.h>
70 #include <linux/sysfs.h>
71 #include <linux/string.h>
72 #include <linux/dmi.h>
73 #include <linux/acpi.h>
77 #define DRVNAME "it87"
79 /* Necessary API not (yet) exported in upstream kernel */
80 /* #define __IT87_USE_ACPI_MUTEX */
82 enum chips { it87, it8712, it8716, it8718, it8720, it8721, it8728, it8732,
83 it8771, it8772, it8781, it8782, it8783, it8786, it8790,
84 it8792, it8603, it8607, it8613, it8620, it8622, it8628, it8655,
87 static unsigned short force_id;
88 module_param(force_id, ushort, 0);
89 MODULE_PARM_DESC(force_id, "Override the detected device ID");
91 static struct platform_device *it87_pdev[2];
92 static bool it87_sio4e_broken;
93 #ifdef __IT87_USE_ACPI_MUTEX
94 static acpi_handle it87_acpi_sio_handle;
95 static char *it87_acpi_sio_mutex;
98 #define REG_2E 0x2e /* The register to read/write */
99 #define REG_4E 0x4e /* Secondary register to read/write */
101 #define DEV 0x07 /* Register: Logical device select */
102 #define PME 0x04 /* The device with the fan registers in it */
104 /* The device with the IT8718F/IT8720F VID value in it */
107 #define DEVID 0x20 /* Register: Device ID */
108 #define DEVREV 0x22 /* Register: Device Revision */
110 static inline void __superio_enter(int ioreg)
115 outb(ioreg == REG_4E ? 0xaa : 0x55, ioreg);
118 static inline int superio_inb(int ioreg, int reg)
123 val = inb(ioreg + 1);
124 if (it87_sio4e_broken && ioreg == 0x4e && val == 0xff) {
125 __superio_enter(ioreg);
127 val = inb(ioreg + 1);
128 pr_warn("Retry access 0x4e:0x%x -> 0x%x\n", reg, val);
134 static inline void superio_outb(int ioreg, int reg, int val)
137 outb(val, ioreg + 1);
140 static int superio_inw(int ioreg, int reg)
142 return (superio_inb(ioreg, reg) << 8) | superio_inb(ioreg, reg + 1);
145 static inline void superio_select(int ioreg, int ldn)
148 outb(ldn, ioreg + 1);
151 static inline int superio_enter(int ioreg)
153 #ifdef __IT87_USE_ACPI_MUTEX
154 if (it87_acpi_sio_mutex) {
157 status = acpi_acquire_mutex(NULL, it87_acpi_sio_mutex, 0x10);
158 if (ACPI_FAILURE(status)) {
159 pr_err("Failed to acquire ACPI mutex\n");
165 * Try to reserve ioreg and ioreg + 1 for exclusive access.
167 if (!request_muxed_region(ioreg, 2, DRVNAME))
170 __superio_enter(ioreg);
174 #ifdef __IT87_USE_ACPI_MUTEX
175 if (it87_acpi_sio_mutex)
176 acpi_release_mutex(it87_acpi_sio_handle, NULL);
181 static inline void superio_exit(int ioreg)
183 if (!it87_sio4e_broken || ioreg != 0x4e) {
185 outb(0x02, ioreg + 1);
187 release_region(ioreg, 2);
188 #ifdef __IT87_USE_ACPI_MUTEX
189 if (it87_acpi_sio_mutex)
190 acpi_release_mutex(it87_acpi_sio_handle, NULL);
194 /* Logical device 4 registers */
195 #define IT8712F_DEVID 0x8712
196 #define IT8705F_DEVID 0x8705
197 #define IT8716F_DEVID 0x8716
198 #define IT8718F_DEVID 0x8718
199 #define IT8720F_DEVID 0x8720
200 #define IT8721F_DEVID 0x8721
201 #define IT8726F_DEVID 0x8726
202 #define IT8728F_DEVID 0x8728
203 #define IT8732F_DEVID 0x8732
204 #define IT8792E_DEVID 0x8733
205 #define IT8771E_DEVID 0x8771
206 #define IT8772E_DEVID 0x8772
207 #define IT8781F_DEVID 0x8781
208 #define IT8782F_DEVID 0x8782
209 #define IT8783E_DEVID 0x8783
210 #define IT8786E_DEVID 0x8786
211 #define IT8790E_DEVID 0x8790
212 #define IT8603E_DEVID 0x8603
213 #define IT8607E_DEVID 0x8607
214 #define IT8613E_DEVID 0x8613
215 #define IT8620E_DEVID 0x8620
216 #define IT8622E_DEVID 0x8622
217 #define IT8623E_DEVID 0x8623
218 #define IT8628E_DEVID 0x8628
219 #define IT8655E_DEVID 0x8655
220 #define IT8665E_DEVID 0x8665
221 #define IT8686E_DEVID 0x8686
222 #define IT87_ACT_REG 0x30
223 #define IT87_BASE_REG 0x60
225 /* Logical device 7 registers (IT8712F and later) */
226 #define IT87_SIO_GPIO1_REG 0x25
227 #define IT87_SIO_GPIO2_REG 0x26
228 #define IT87_SIO_GPIO3_REG 0x27
229 #define IT87_SIO_GPIO4_REG 0x28
230 #define IT87_SIO_GPIO5_REG 0x29
231 #define IT87_SIO_GPIO9_REG 0xd3
232 #define IT87_SIO_PINX1_REG 0x2a /* Pin selection */
233 #define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
234 #define IT87_SIO_PINX4_REG 0x2d /* Pin selection */
235 #define IT87_SIO_SPI_REG 0xef /* SPI function pin select */
236 #define IT87_SIO_VID_REG 0xfc /* VID value */
237 #define IT87_SIO_BEEP_PIN_REG 0xf6 /* Beep pin mapping */
239 /* Update battery voltage after every reading if true */
240 static bool update_vbat;
242 /* Not all BIOSes properly configure the PWM registers */
243 static bool fix_pwm_polarity;
245 /* Many IT87 constants specified below */
247 /* Length of ISA address segment */
248 #define IT87_EXTENT 8
250 /* Length of ISA address segment for Environmental Controller */
251 #define IT87_EC_EXTENT 2
253 /* Offset of EC registers from ISA base address */
254 #define IT87_EC_OFFSET 5
256 /* Where are the ISA address/data registers relative to the EC base address */
257 #define IT87_ADDR_REG_OFFSET 0
258 #define IT87_DATA_REG_OFFSET 1
260 /*----- The IT87 registers -----*/
262 #define IT87_REG_CONFIG 0x00
264 #define IT87_REG_ALARM1 0x01
265 #define IT87_REG_ALARM2 0x02
266 #define IT87_REG_ALARM3 0x03
268 #define IT87_REG_BANK 0x06
271 * The IT8718F and IT8720F have the VID value in a different register, in
272 * Super-I/O configuration space.
274 #define IT87_REG_VID 0x0a
276 * The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b
277 * for fan divisors. Later IT8712F revisions must use 16-bit tachometer
280 #define IT87_REG_FAN_DIV 0x0b
281 #define IT87_REG_FAN_16BIT 0x0c
285 * - up to 13 voltage (0 to 7, battery, avcc, 10 to 12)
286 * - up to 6 temp (1 to 6)
287 * - up to 6 fan (1 to 6)
290 static const u8 IT87_REG_FAN[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82, 0x4c };
291 static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86, 0x4e };
292 static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83, 0x4d };
293 static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87, 0x4f };
295 static const u8 IT87_REG_FAN_8665[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82, 0x93 };
296 static const u8 IT87_REG_FAN_MIN_8665[] =
297 { 0x10, 0x11, 0x12, 0x84, 0x86, 0xb2 };
298 static const u8 IT87_REG_FANX_8665[] = { 0x18, 0x19, 0x1a, 0x81, 0x83, 0x94 };
299 static const u8 IT87_REG_FANX_MIN_8665[] =
300 { 0x1b, 0x1c, 0x1d, 0x85, 0x87, 0xb3 };
302 static const u8 IT87_REG_TEMP_OFFSET[] = { 0x56, 0x57, 0x59, 0x5a, 0x90, 0x91 };
304 static const u8 IT87_REG_TEMP_OFFSET_8686[] = { 0x56, 0x57, 0x59, 0x90, 0x91, 0x92 };
306 #define IT87_REG_FAN_MAIN_CTRL 0x13
307 #define IT87_REG_FAN_CTL 0x14
309 static const u8 IT87_REG_PWM[] = { 0x15, 0x16, 0x17, 0x7f, 0xa7, 0xaf };
310 static const u8 IT87_REG_PWM_8665[] = { 0x15, 0x16, 0x17, 0x1e, 0x1f, 0x92 };
312 static const u8 IT87_REG_PWM_DUTY[] = { 0x63, 0x6b, 0x73, 0x7b, 0xa3, 0xab };
314 static const u8 IT87_REG_VIN[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26,
315 0x27, 0x28, 0x2f, 0x2c, 0x2d, 0x2e };
317 #define IT87_REG_TEMP(nr) (0x29 + (nr))
319 #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2)
320 #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2)
322 static const u8 IT87_REG_TEMP_HIGH[] = { 0x40, 0x42, 0x44, 0x46, 0xb4, 0xb6 };
323 static const u8 IT87_REG_TEMP_LOW[] = { 0x41, 0x43, 0x45, 0x47, 0xb5, 0xb7 };
325 static const u8 IT87_REG_TEMP_HIGH_8686[] =
326 { 0x40, 0x42, 0x44, 0xb4, 0xb6, 0xb8 };
327 static const u8 IT87_REG_TEMP_LOW_8686[] =
328 { 0x41, 0x43, 0x45, 0xb5, 0xb7, 0xb9 };
330 #define IT87_REG_VIN_ENABLE 0x50
331 #define IT87_REG_TEMP_ENABLE 0x51
332 #define IT87_REG_TEMP_EXTRA 0x55
333 #define IT87_REG_BEEP_ENABLE 0x5c
335 #define IT87_REG_CHIPID 0x58
337 static const u8 IT87_REG_AUTO_BASE[] = { 0x60, 0x68, 0x70, 0x78, 0xa0, 0xa8 };
339 #define IT87_REG_AUTO_TEMP(nr, i) (IT87_REG_AUTO_BASE[nr] + (i))
340 #define IT87_REG_AUTO_PWM(nr, i) (IT87_REG_AUTO_BASE[nr] + 5 + (i))
342 #define IT87_REG_TEMP456_ENABLE 0x77
344 static const u16 IT87_REG_TEMP_SRC1[] = { 0x21d, 0x21e, 0x21f };
345 #define IT87_REG_TEMP_SRC2 0x23d
347 #define NUM_VIN ARRAY_SIZE(IT87_REG_VIN)
348 #define NUM_VIN_LIMIT 8
350 #define NUM_FAN ARRAY_SIZE(IT87_REG_FAN)
351 #define NUM_FAN_DIV 3
352 #define NUM_PWM ARRAY_SIZE(IT87_REG_PWM)
353 #define NUM_AUTO_PWM ARRAY_SIZE(IT87_REG_PWM)
355 struct it87_devices {
357 const char * const suffix;
364 #define FEAT_12MV_ADC BIT(0)
365 #define FEAT_NEWER_AUTOPWM BIT(1)
366 #define FEAT_OLD_AUTOPWM BIT(2)
367 #define FEAT_16BIT_FANS BIT(3)
368 #define FEAT_TEMP_OFFSET BIT(4)
369 #define FEAT_TEMP_PECI BIT(5)
370 #define FEAT_TEMP_OLD_PECI BIT(6)
371 #define FEAT_FAN16_CONFIG BIT(7) /* Need to enable 16-bit fans */
372 #define FEAT_FIVE_FANS BIT(8) /* Supports five fans */
373 #define FEAT_VID BIT(9) /* Set if chip supports VID */
374 #define FEAT_IN7_INTERNAL BIT(10) /* Set if in7 is internal */
375 #define FEAT_SIX_FANS BIT(11) /* Supports six fans */
376 #define FEAT_10_9MV_ADC BIT(12)
377 #define FEAT_AVCC3 BIT(13) /* Chip supports in9/AVCC3 */
378 #define FEAT_FIVE_PWM BIT(14) /* Chip supports 5 pwm chn */
379 #define FEAT_SIX_PWM BIT(15) /* Chip supports 6 pwm chn */
380 #define FEAT_PWM_FREQ2 BIT(16) /* Separate pwm freq 2 */
381 #define FEAT_SIX_TEMP BIT(17) /* Up to 6 temp sensors */
382 #define FEAT_VIN3_5V BIT(18) /* VIN3 connected to +5V */
383 #define FEAT_FOUR_FANS BIT(19) /* Supports four fans */
384 #define FEAT_FOUR_PWM BIT(20) /* Supports four fan controls */
385 #define FEAT_BANK_SEL BIT(21) /* Chip has multi-bank support */
386 #define FEAT_SCALING BIT(22) /* Internal voltage scaling */
387 #define FEAT_FANCTL_ONOFF BIT(23) /* chip has FAN_CTL ON/OFF */
388 #define FEAT_11MV_ADC BIT(24)
390 static const struct it87_devices it87_devices[] = {
394 .features = FEAT_OLD_AUTOPWM | FEAT_FANCTL_ONOFF,
395 /* may need to overwrite */
401 .features = FEAT_OLD_AUTOPWM | FEAT_VID | FEAT_FANCTL_ONOFF,
402 /* may need to overwrite */
408 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | FEAT_VID
409 | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS | FEAT_PWM_FREQ2
416 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | FEAT_VID
417 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS
418 | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
420 .old_peci_mask = 0x4,
425 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | FEAT_VID
426 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS
427 | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
429 .old_peci_mask = 0x4,
434 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
435 | FEAT_TEMP_OFFSET | FEAT_TEMP_OLD_PECI | FEAT_TEMP_PECI
436 | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS | FEAT_IN7_INTERNAL
437 | FEAT_PWM_FREQ2 | FEAT_SCALING | FEAT_FANCTL_ONOFF,
440 .old_peci_mask = 0x02, /* Actually reports PCH */
445 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
446 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_FIVE_FANS
447 | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2 | FEAT_SCALING
455 .features = FEAT_NEWER_AUTOPWM | FEAT_16BIT_FANS
456 | FEAT_TEMP_OFFSET | FEAT_TEMP_OLD_PECI | FEAT_TEMP_PECI
457 | FEAT_10_9MV_ADC | FEAT_IN7_INTERNAL | FEAT_FOUR_FANS
458 | FEAT_FOUR_PWM | FEAT_FANCTL_ONOFF,
461 .old_peci_mask = 0x02, /* Actually reports PCH */
466 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
467 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
468 | FEAT_PWM_FREQ2 | FEAT_SCALING | FEAT_FANCTL_ONOFF,
469 /* PECI: guesswork */
471 /* 16 bit fans (OHM) */
472 /* three fans, always 16 bit (guesswork) */
479 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
480 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
481 | FEAT_PWM_FREQ2 | FEAT_SCALING | FEAT_FANCTL_ONOFF,
482 /* PECI (coreboot) */
483 /* 12mV ADC (HWSensors4, OHM) */
484 /* 16 bit fans (HWSensors4, OHM) */
485 /* three fans, always 16 bit (datasheet) */
492 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
493 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2
496 .old_peci_mask = 0x4,
501 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
502 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2
505 .old_peci_mask = 0x4,
510 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
511 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2
514 .old_peci_mask = 0x4,
519 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
520 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
521 | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
528 .features = FEAT_NEWER_AUTOPWM | FEAT_10_9MV_ADC | FEAT_SCALING
529 | FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI
530 | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
537 .features = FEAT_NEWER_AUTOPWM | FEAT_10_9MV_ADC | FEAT_SCALING
538 | FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI
539 | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
546 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
547 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
548 | FEAT_AVCC3 | FEAT_PWM_FREQ2 | FEAT_SCALING,
555 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
556 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
557 | FEAT_AVCC3 | FEAT_PWM_FREQ2 | FEAT_SCALING
565 .features = FEAT_NEWER_AUTOPWM | FEAT_11MV_ADC | FEAT_16BIT_FANS
566 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_FIVE_FANS
567 | FEAT_FIVE_PWM | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2
568 | FEAT_AVCC3 | FEAT_SCALING,
575 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
576 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_SIX_FANS
577 | FEAT_IN7_INTERNAL | FEAT_SIX_PWM | FEAT_PWM_FREQ2
578 | FEAT_SIX_TEMP | FEAT_VIN3_5V | FEAT_SCALING
586 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
587 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_FIVE_FANS
588 | FEAT_FIVE_PWM | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2
589 | FEAT_AVCC3 | FEAT_VIN3_5V | FEAT_SCALING,
596 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
597 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_SIX_FANS
598 | FEAT_IN7_INTERNAL | FEAT_SIX_PWM | FEAT_PWM_FREQ2
599 | FEAT_SIX_TEMP | FEAT_SCALING | FEAT_AVCC3
607 .features = FEAT_NEWER_AUTOPWM | FEAT_16BIT_FANS
608 | FEAT_TEMP_OFFSET | FEAT_AVCC3
609 | FEAT_10_9MV_ADC | FEAT_IN7_INTERNAL | FEAT_BANK_SEL,
615 .features = FEAT_NEWER_AUTOPWM | FEAT_16BIT_FANS
616 | FEAT_TEMP_OFFSET | FEAT_AVCC3
617 | FEAT_10_9MV_ADC | FEAT_IN7_INTERNAL | FEAT_SIX_FANS
618 | FEAT_SIX_PWM | FEAT_BANK_SEL,
624 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
625 | FEAT_TEMP_OFFSET | FEAT_SIX_FANS
626 | FEAT_IN7_INTERNAL | FEAT_SIX_PWM | FEAT_PWM_FREQ2
627 | FEAT_SIX_TEMP | FEAT_BANK_SEL | FEAT_SCALING | FEAT_AVCC3,
632 #define has_16bit_fans(data) ((data)->features & FEAT_16BIT_FANS)
633 #define has_12mv_adc(data) ((data)->features & FEAT_12MV_ADC)
634 #define has_10_9mv_adc(data) ((data)->features & FEAT_10_9MV_ADC)
635 #define has_newer_autopwm(data) ((data)->features & FEAT_NEWER_AUTOPWM)
636 #define has_old_autopwm(data) ((data)->features & FEAT_OLD_AUTOPWM)
637 #define has_temp_offset(data) ((data)->features & FEAT_TEMP_OFFSET)
638 #define has_temp_peci(data, nr) (((data)->features & FEAT_TEMP_PECI) && \
639 ((data)->peci_mask & BIT(nr)))
640 #define has_temp_old_peci(data, nr) \
641 (((data)->features & FEAT_TEMP_OLD_PECI) && \
642 ((data)->old_peci_mask & BIT(nr)))
643 #define has_fan16_config(data) ((data)->features & FEAT_FAN16_CONFIG)
644 #define has_five_fans(data) ((data)->features & (FEAT_FIVE_FANS | \
646 #define has_vid(data) ((data)->features & FEAT_VID)
647 #define has_in7_internal(data) ((data)->features & FEAT_IN7_INTERNAL)
648 #define has_six_fans(data) ((data)->features & FEAT_SIX_FANS)
649 #define has_avcc3(data) ((data)->features & FEAT_AVCC3)
650 #define has_five_pwm(data) ((data)->features & (FEAT_FIVE_PWM \
652 #define has_six_pwm(data) ((data)->features & FEAT_SIX_PWM)
653 #define has_pwm_freq2(data) ((data)->features & FEAT_PWM_FREQ2)
654 #define has_six_temp(data) ((data)->features & FEAT_SIX_TEMP)
655 #define has_vin3_5v(data) ((data)->features & FEAT_VIN3_5V)
656 #define has_four_fans(data) ((data)->features & (FEAT_FOUR_FANS | \
659 #define has_four_pwm(data) ((data)->features & (FEAT_FOUR_PWM | \
662 #define has_bank_sel(data) ((data)->features & FEAT_BANK_SEL)
663 #define has_scaling(data) ((data)->features & FEAT_SCALING)
664 #define has_fanctl_onoff(data) ((data)->features & FEAT_FANCTL_ONOFF)
665 #define has_11mv_adc(data) ((data)->features & FEAT_11MV_ADC)
667 struct it87_sio_data {
669 /* Values read from Super-I/O config space */
673 u8 internal; /* Internal sensors can be labeled */
674 /* Features skipped based on config or DMI */
683 * For each registered chip, we need to keep some data in memory.
684 * The structure is dynamically allocated.
687 const struct attribute_group *groups[7];
696 const u8 *REG_FAN_MIN;
697 const u8 *REG_FANX_MIN;
701 const u8 *REG_TEMP_OFFSET;
702 const u8 *REG_TEMP_LOW;
703 const u8 *REG_TEMP_HIGH;
707 struct mutex update_lock;
708 char valid; /* !=0 if following fields are valid */
709 unsigned long last_updated; /* In jiffies */
711 u16 in_scaled; /* Internal voltage sensors are scaled */
712 u16 in_internal; /* Bitfield, internal sensors (for labels) */
713 u16 has_in; /* Bitfield, voltage sensors enabled */
714 u8 in[NUM_VIN][3]; /* [nr][0]=in, [1]=min, [2]=max */
715 u8 has_fan; /* Bitfield, fans enabled */
716 u16 fan[NUM_FAN][2]; /* Register values, [nr][0]=fan, [1]=min */
717 u8 has_temp; /* Bitfield, temp sensors enabled */
718 s8 temp[NUM_TEMP][4]; /* [nr][0]=temp, [1]=min, [2]=max, [3]=offset */
719 u8 num_temp_limit; /* Number of temp limit/offset registers */
720 u8 sensor; /* Register value (IT87_REG_TEMP_ENABLE) */
721 u8 extra; /* Register value (IT87_REG_TEMP_EXTRA) */
722 u8 fan_div[NUM_FAN_DIV];/* Register encoding, shifted right */
723 bool has_vid; /* True if VID supported */
724 u8 vid; /* Register encoding, combined */
726 u32 alarms; /* Register encoding, combined */
727 bool has_beep; /* true if beep supported */
728 u8 beeps; /* Register encoding */
729 u8 fan_main_ctrl; /* Register value */
730 u8 fan_ctl; /* Register value */
733 * The following 3 arrays correspond to the same registers up to
734 * the IT8720F. The meaning of bits 6-0 depends on the value of bit
735 * 7, and we want to preserve settings on mode changes, so we have
736 * to track all values separately.
737 * Starting with the IT8721F, the manual PWM duty cycles are stored
738 * in separate registers (8-bit values), so the separate tracking
739 * is no longer needed, but it is still done to keep the driver
742 u8 has_pwm; /* Bitfield, pwm control enabled */
743 u8 pwm_ctrl[NUM_PWM]; /* Register value */
744 u8 pwm_duty[NUM_PWM]; /* Manual PWM value set by user */
745 u8 pwm_temp_map[NUM_PWM];/* PWM to temp. chan. mapping (bits 1-0) */
747 /* Automatic fan speed control registers */
748 u8 auto_pwm[NUM_AUTO_PWM][4]; /* [nr][3] is hard-coded */
749 s8 auto_temp[NUM_AUTO_PWM][5]; /* [nr][0] is point1_temp_hyst */
752 static int adc_lsb(const struct it87_data *data, int nr)
756 if (has_12mv_adc(data))
758 else if (has_10_9mv_adc(data))
760 else if (has_11mv_adc(data))
764 if (data->in_scaled & BIT(nr))
769 static u8 in_to_reg(const struct it87_data *data, int nr, long val)
771 val = DIV_ROUND_CLOSEST(val * 10, adc_lsb(data, nr));
772 return clamp_val(val, 0, 255);
775 static int in_from_reg(const struct it87_data *data, int nr, int val)
777 return DIV_ROUND_CLOSEST(val * adc_lsb(data, nr), 10);
780 static inline u8 FAN_TO_REG(long rpm, int div)
784 rpm = clamp_val(rpm, 1, 1000000);
785 return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
788 static inline u16 FAN16_TO_REG(long rpm)
792 return clamp_val((1350000 + rpm) / (rpm * 2), 1, 0xfffe);
795 #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \
796 1350000 / ((val) * (div)))
797 /* The divider is fixed to 2 in 16-bit mode */
798 #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
799 1350000 / ((val) * 2))
801 #define TEMP_TO_REG(val) (clamp_val(((val) < 0 ? (((val) - 500) / 1000) : \
802 ((val) + 500) / 1000), -128, 127))
803 #define TEMP_FROM_REG(val) ((val) * 1000)
805 static u8 pwm_to_reg(const struct it87_data *data, long val)
807 if (has_newer_autopwm(data))
813 static int pwm_from_reg(const struct it87_data *data, u8 reg)
815 if (has_newer_autopwm(data))
818 return (reg & 0x7f) << 1;
821 static int DIV_TO_REG(int val)
825 while (answer < 7 && (val >>= 1))
830 #define DIV_FROM_REG(val) BIT(val)
833 * PWM base frequencies. The frequency has to be divided by either 128 or 256,
834 * depending on the chip type, to calculate the actual PWM frequency.
836 * Some of the chip datasheets suggest a base frequency of 51 kHz instead
837 * of 750 kHz for the slowest base frequency, resulting in a PWM frequency
838 * of 200 Hz. Sometimes both PWM frequency select registers are affected,
839 * sometimes just one. It is unknown if this is a datasheet error or real,
840 * so this is ignored for now.
842 static const unsigned int pwm_freq[8] = {
853 static int _it87_read_value(struct it87_data *data, u8 reg)
855 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
856 return inb_p(data->addr + IT87_DATA_REG_OFFSET);
859 static void _it87_write_value(struct it87_data *data, u8 reg, u8 value)
861 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
862 outb_p(value, data->addr + IT87_DATA_REG_OFFSET);
865 static void it87_set_bank(struct it87_data *data, u8 bank)
867 if (has_bank_sel(data) && bank != data->bank) {
868 u8 breg = _it87_read_value(data, IT87_REG_BANK);
873 _it87_write_value(data, IT87_REG_BANK, breg);
878 * Must be called with data->update_lock held, except during initialization.
879 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
880 * would slow down the IT87 access and should not be necessary.
882 static int it87_read_value(struct it87_data *data, u16 reg)
884 it87_set_bank(data, reg >> 8);
885 return _it87_read_value(data, reg & 0xff);
889 * Must be called with data->update_lock held, except during initialization.
890 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
891 * would slow down the IT87 access and should not be necessary.
893 static void it87_write_value(struct it87_data *data, u16 reg, u8 value)
895 it87_set_bank(data, reg >> 8);
896 _it87_write_value(data, reg & 0xff, value);
899 static void it87_update_pwm_ctrl(struct it87_data *data, int nr)
901 data->pwm_ctrl[nr] = it87_read_value(data, data->REG_PWM[nr]);
902 if (has_newer_autopwm(data)) {
903 if (data->type == it8613)
904 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x38;
906 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
907 data->pwm_duty[nr] = it87_read_value(data,
908 IT87_REG_PWM_DUTY[nr]);
910 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
911 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
912 else /* Manual mode */
913 data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f;
916 if (has_old_autopwm(data)) {
919 for (i = 0; i < 5 ; i++)
920 data->auto_temp[nr][i] = it87_read_value(data,
921 IT87_REG_AUTO_TEMP(nr, i));
922 for (i = 0; i < 3 ; i++)
923 data->auto_pwm[nr][i] = it87_read_value(data,
924 IT87_REG_AUTO_PWM(nr, i));
925 } else if (has_newer_autopwm(data)) {
929 * 0: temperature hysteresis (base + 5)
930 * 1: fan off temperature (base + 0)
931 * 2: fan start temperature (base + 1)
932 * 3: fan max temperature (base + 2)
934 data->auto_temp[nr][0] =
935 it87_read_value(data, IT87_REG_AUTO_TEMP(nr, 5));
937 for (i = 0; i < 3 ; i++)
938 data->auto_temp[nr][i + 1] =
939 it87_read_value(data,
940 IT87_REG_AUTO_TEMP(nr, i));
942 * 0: start pwm value (base + 3)
943 * 1: pwm slope (base + 4, 1/8th pwm)
945 data->auto_pwm[nr][0] =
946 it87_read_value(data, IT87_REG_AUTO_TEMP(nr, 3));
947 data->auto_pwm[nr][1] =
948 it87_read_value(data, IT87_REG_AUTO_TEMP(nr, 4));
952 static struct it87_data *it87_update_device(struct device *dev)
954 struct it87_data *data = dev_get_drvdata(dev);
957 mutex_lock(&data->update_lock);
959 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) ||
963 * Cleared after each update, so reenable. Value
964 * returned by this read will be previous value
966 it87_write_value(data, IT87_REG_CONFIG,
967 it87_read_value(data, IT87_REG_CONFIG) | 0x40);
969 for (i = 0; i < NUM_VIN; i++) {
970 if (!(data->has_in & BIT(i)))
974 it87_read_value(data, IT87_REG_VIN[i]);
976 /* VBAT and AVCC don't have limit registers */
977 if (i >= NUM_VIN_LIMIT)
981 it87_read_value(data, IT87_REG_VIN_MIN(i));
983 it87_read_value(data, IT87_REG_VIN_MAX(i));
986 for (i = 0; i < NUM_FAN; i++) {
987 /* Skip disabled fans */
988 if (!(data->has_fan & BIT(i)))
992 it87_read_value(data, data->REG_FAN_MIN[i]);
993 data->fan[i][0] = it87_read_value(data,
995 /* Add high byte if in 16-bit mode */
996 if (has_16bit_fans(data)) {
997 data->fan[i][0] |= it87_read_value(data,
998 data->REG_FANX[i]) << 8;
999 data->fan[i][1] |= it87_read_value(data,
1000 data->REG_FANX_MIN[i]) << 8;
1003 for (i = 0; i < NUM_TEMP; i++) {
1004 if (!(data->has_temp & BIT(i)))
1007 it87_read_value(data, IT87_REG_TEMP(i));
1009 if (i >= data->num_temp_limit)
1012 if (has_temp_offset(data))
1014 it87_read_value(data,
1015 data->REG_TEMP_OFFSET[i]);
1018 it87_read_value(data, data->REG_TEMP_LOW[i]);
1020 it87_read_value(data, data->REG_TEMP_HIGH[i]);
1023 /* Newer chips don't have clock dividers */
1024 if ((data->has_fan & 0x07) && !has_16bit_fans(data)) {
1025 i = it87_read_value(data, IT87_REG_FAN_DIV);
1026 data->fan_div[0] = i & 0x07;
1027 data->fan_div[1] = (i >> 3) & 0x07;
1028 data->fan_div[2] = (i & 0x40) ? 3 : 1;
1032 it87_read_value(data, IT87_REG_ALARM1) |
1033 (it87_read_value(data, IT87_REG_ALARM2) << 8) |
1034 (it87_read_value(data, IT87_REG_ALARM3) << 16);
1035 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
1037 data->fan_main_ctrl = it87_read_value(data,
1038 IT87_REG_FAN_MAIN_CTRL);
1039 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL);
1040 for (i = 0; i < NUM_PWM; i++) {
1041 if (!(data->has_pwm & BIT(i)))
1043 it87_update_pwm_ctrl(data, i);
1046 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
1047 data->extra = it87_read_value(data, IT87_REG_TEMP_EXTRA);
1049 * The IT8705F does not have VID capability.
1050 * The IT8718F and later don't use IT87_REG_VID for the
1053 if (data->type == it8712 || data->type == it8716) {
1054 data->vid = it87_read_value(data, IT87_REG_VID);
1056 * The older IT8712F revisions had only 5 VID pins,
1057 * but we assume it is always safe to read 6 bits.
1061 data->last_updated = jiffies;
1065 mutex_unlock(&data->update_lock);
1070 static ssize_t show_in(struct device *dev, struct device_attribute *attr,
1073 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1074 struct it87_data *data = it87_update_device(dev);
1075 int index = sattr->index;
1078 return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr][index]));
1081 static ssize_t set_in(struct device *dev, struct device_attribute *attr,
1082 const char *buf, size_t count)
1084 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1085 struct it87_data *data = dev_get_drvdata(dev);
1086 int index = sattr->index;
1090 if (kstrtoul(buf, 10, &val) < 0)
1093 mutex_lock(&data->update_lock);
1094 data->in[nr][index] = in_to_reg(data, nr, val);
1095 it87_write_value(data,
1096 index == 1 ? IT87_REG_VIN_MIN(nr)
1097 : IT87_REG_VIN_MAX(nr),
1098 data->in[nr][index]);
1099 mutex_unlock(&data->update_lock);
1103 static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0);
1104 static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_in, set_in,
1106 static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_in, set_in,
1109 static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 1, 0);
1110 static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_in, set_in,
1112 static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_in, set_in,
1115 static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 2, 0);
1116 static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_in, set_in,
1118 static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_in, set_in,
1121 static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 3, 0);
1122 static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_in, set_in,
1124 static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_in, set_in,
1127 static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 4, 0);
1128 static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_in, set_in,
1130 static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_in, set_in,
1133 static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 5, 0);
1134 static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_in, set_in,
1136 static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_in, set_in,
1139 static SENSOR_DEVICE_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 6, 0);
1140 static SENSOR_DEVICE_ATTR_2(in6_min, S_IRUGO | S_IWUSR, show_in, set_in,
1142 static SENSOR_DEVICE_ATTR_2(in6_max, S_IRUGO | S_IWUSR, show_in, set_in,
1145 static SENSOR_DEVICE_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 7, 0);
1146 static SENSOR_DEVICE_ATTR_2(in7_min, S_IRUGO | S_IWUSR, show_in, set_in,
1148 static SENSOR_DEVICE_ATTR_2(in7_max, S_IRUGO | S_IWUSR, show_in, set_in,
1151 static SENSOR_DEVICE_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 8, 0);
1152 static SENSOR_DEVICE_ATTR_2(in9_input, S_IRUGO, show_in, NULL, 9, 0);
1153 static SENSOR_DEVICE_ATTR_2(in10_input, S_IRUGO, show_in, NULL, 10, 0);
1154 static SENSOR_DEVICE_ATTR_2(in11_input, S_IRUGO, show_in, NULL, 11, 0);
1155 static SENSOR_DEVICE_ATTR_2(in12_input, S_IRUGO, show_in, NULL, 12, 0);
1157 /* Up to 6 temperatures */
1158 static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
1161 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1163 int index = sattr->index;
1164 struct it87_data *data = it87_update_device(dev);
1166 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr][index]));
1169 static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
1170 const char *buf, size_t count)
1172 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1174 int index = sattr->index;
1175 struct it87_data *data = dev_get_drvdata(dev);
1179 if (kstrtol(buf, 10, &val) < 0)
1182 mutex_lock(&data->update_lock);
1187 reg = data->REG_TEMP_LOW[nr];
1190 reg = data->REG_TEMP_HIGH[nr];
1193 regval = it87_read_value(data, IT87_REG_BEEP_ENABLE);
1194 if (!(regval & 0x80)) {
1196 it87_write_value(data, IT87_REG_BEEP_ENABLE, regval);
1199 reg = data->REG_TEMP_OFFSET[nr];
1203 data->temp[nr][index] = TEMP_TO_REG(val);
1204 it87_write_value(data, reg, data->temp[nr][index]);
1205 mutex_unlock(&data->update_lock);
1209 static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0);
1210 static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1212 static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1214 static SENSOR_DEVICE_ATTR_2(temp1_offset, S_IRUGO | S_IWUSR, show_temp,
1216 static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, 0);
1217 static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1219 static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1221 static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IRUGO | S_IWUSR, show_temp,
1223 static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 2, 0);
1224 static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1226 static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1228 static SENSOR_DEVICE_ATTR_2(temp3_offset, S_IRUGO | S_IWUSR, show_temp,
1230 static SENSOR_DEVICE_ATTR_2(temp4_input, S_IRUGO, show_temp, NULL, 3, 0);
1231 static SENSOR_DEVICE_ATTR_2(temp4_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1233 static SENSOR_DEVICE_ATTR_2(temp4_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1235 static SENSOR_DEVICE_ATTR_2(temp4_offset, S_IRUGO | S_IWUSR, show_temp,
1237 static SENSOR_DEVICE_ATTR_2(temp5_input, S_IRUGO, show_temp, NULL, 4, 0);
1238 static SENSOR_DEVICE_ATTR_2(temp5_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1240 static SENSOR_DEVICE_ATTR_2(temp5_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1242 static SENSOR_DEVICE_ATTR_2(temp5_offset, S_IRUGO | S_IWUSR, show_temp,
1244 static SENSOR_DEVICE_ATTR_2(temp6_input, S_IRUGO, show_temp, NULL, 5, 0);
1245 static SENSOR_DEVICE_ATTR_2(temp6_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1247 static SENSOR_DEVICE_ATTR_2(temp6_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1249 static SENSOR_DEVICE_ATTR_2(temp6_offset, S_IRUGO | S_IWUSR, show_temp,
1252 static int get_temp_type(struct it87_data *data, int index)
1257 if (has_bank_sel(data)) {
1258 int s1reg = IT87_REG_TEMP_SRC1[index/2] >> ((index % 2) * 4);
1261 src1 = (it87_read_value(data, s1reg) >> ((index % 2) * 4)) & 0x0f;
1262 src2 = it87_read_value(data, IT87_REG_TEMP_SRC2);
1264 switch (data->type) {
1272 if (index == 1 || index == 2 ||
1273 index == 4 || index == 5)
1277 if (index == 2 || index == 6)
1292 type = (src2 & BIT(index)) ? 6 : 5;
1295 type = (src2 & BIT(index)) ? 4 : 6;
1298 type = (src2 & BIT(index)) ? 5 : 0;
1311 reg = it87_read_value(data, IT87_REG_TEMP_ENABLE);
1312 extra = it87_read_value(data, IT87_REG_TEMP_EXTRA);
1314 if ((has_temp_peci(data, index) && (reg >> 6 == index + 1)) ||
1315 (has_temp_old_peci(data, index) && (extra & 0x80)))
1316 type = 6; /* Intel PECI */
1317 if (reg & BIT(index))
1318 type = 3; /* thermal diode */
1319 else if (reg & BIT(index + 3))
1320 type = 4; /* thermistor */
1325 static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr,
1328 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1329 struct it87_data *data = it87_update_device(dev);
1330 int type = get_temp_type(data, sensor_attr->index);
1332 return sprintf(buf, "%d\n", type);
1335 static ssize_t set_temp_type(struct device *dev, struct device_attribute *attr,
1336 const char *buf, size_t count)
1338 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1339 int nr = sensor_attr->index;
1341 struct it87_data *data = dev_get_drvdata(dev);
1345 if (kstrtol(buf, 10, &val) < 0)
1348 reg = it87_read_value(data, IT87_REG_TEMP_ENABLE);
1351 if (has_temp_peci(data, nr) && (reg >> 6 == nr + 1 || val == 6))
1353 extra = it87_read_value(data, IT87_REG_TEMP_EXTRA);
1354 if (has_temp_old_peci(data, nr) && ((extra & 0x80) || val == 6))
1356 if (val == 2) { /* backwards compatibility */
1358 "Sensor type 2 is deprecated, please use 4 instead\n");
1361 /* 3 = thermal diode; 4 = thermistor; 6 = Intel PECI; 0 = disabled */
1366 else if (has_temp_peci(data, nr) && val == 6)
1367 reg |= (nr + 1) << 6;
1368 else if (has_temp_old_peci(data, nr) && val == 6)
1373 mutex_lock(&data->update_lock);
1375 data->extra = extra;
1376 it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor);
1377 if (has_temp_old_peci(data, nr))
1378 it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra);
1379 data->valid = 0; /* Force cache refresh */
1380 mutex_unlock(&data->update_lock);
1384 static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR, show_temp_type,
1386 static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR, show_temp_type,
1388 static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR, show_temp_type,
1390 static SENSOR_DEVICE_ATTR(temp4_type, S_IRUGO | S_IWUSR, show_temp_type,
1392 static SENSOR_DEVICE_ATTR(temp5_type, S_IRUGO | S_IWUSR, show_temp_type,
1394 static SENSOR_DEVICE_ATTR(temp6_type, S_IRUGO | S_IWUSR, show_temp_type,
1399 static int pwm_mode(const struct it87_data *data, int nr)
1401 if (has_fanctl_onoff(data) && nr < 3 &&
1402 !(data->fan_main_ctrl & BIT(nr)))
1403 return 0; /* Full speed */
1404 if (data->pwm_ctrl[nr] & 0x80)
1405 return 2; /* Automatic mode */
1406 if ((!has_fanctl_onoff(data) || nr >= 3) &&
1407 data->pwm_duty[nr] == pwm_to_reg(data, 0xff))
1408 return 0; /* Full speed */
1410 return 1; /* Manual mode */
1413 static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
1416 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1418 int index = sattr->index;
1420 struct it87_data *data = it87_update_device(dev);
1422 speed = has_16bit_fans(data) ?
1423 FAN16_FROM_REG(data->fan[nr][index]) :
1424 FAN_FROM_REG(data->fan[nr][index],
1425 DIV_FROM_REG(data->fan_div[nr]));
1426 return sprintf(buf, "%d\n", speed);
1429 static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
1432 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1433 struct it87_data *data = it87_update_device(dev);
1434 int nr = sensor_attr->index;
1436 return sprintf(buf, "%lu\n", DIV_FROM_REG(data->fan_div[nr]));
1439 static ssize_t show_pwm_enable(struct device *dev,
1440 struct device_attribute *attr, char *buf)
1442 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1443 struct it87_data *data = it87_update_device(dev);
1444 int nr = sensor_attr->index;
1446 return sprintf(buf, "%d\n", pwm_mode(data, nr));
1449 static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
1452 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1453 struct it87_data *data = it87_update_device(dev);
1454 int nr = sensor_attr->index;
1456 return sprintf(buf, "%d\n",
1457 pwm_from_reg(data, data->pwm_duty[nr]));
1460 static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
1463 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1464 struct it87_data *data = it87_update_device(dev);
1465 int nr = sensor_attr->index;
1469 if (has_pwm_freq2(data) && nr == 1)
1470 index = (data->extra >> 4) & 0x07;
1472 index = (data->fan_ctl >> 4) & 0x07;
1474 freq = pwm_freq[index] / (has_newer_autopwm(data) ? 256 : 128);
1476 return sprintf(buf, "%u\n", freq);
1479 static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
1480 const char *buf, size_t count)
1482 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1484 int index = sattr->index;
1486 struct it87_data *data = dev_get_drvdata(dev);
1490 if (kstrtol(buf, 10, &val) < 0)
1493 mutex_lock(&data->update_lock);
1495 if (has_16bit_fans(data)) {
1496 data->fan[nr][index] = FAN16_TO_REG(val);
1497 it87_write_value(data, data->REG_FAN_MIN[nr],
1498 data->fan[nr][index] & 0xff);
1499 it87_write_value(data, data->REG_FANX_MIN[nr],
1500 data->fan[nr][index] >> 8);
1502 reg = it87_read_value(data, IT87_REG_FAN_DIV);
1505 data->fan_div[nr] = reg & 0x07;
1508 data->fan_div[nr] = (reg >> 3) & 0x07;
1511 data->fan_div[nr] = (reg & 0x40) ? 3 : 1;
1514 data->fan[nr][index] =
1515 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
1516 it87_write_value(data, data->REG_FAN_MIN[nr],
1517 data->fan[nr][index]);
1520 mutex_unlock(&data->update_lock);
1524 static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
1525 const char *buf, size_t count)
1527 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1528 struct it87_data *data = dev_get_drvdata(dev);
1529 int nr = sensor_attr->index;
1534 if (kstrtoul(buf, 10, &val) < 0)
1537 mutex_lock(&data->update_lock);
1538 old = it87_read_value(data, IT87_REG_FAN_DIV);
1540 /* Save fan min limit */
1541 min = FAN_FROM_REG(data->fan[nr][1], DIV_FROM_REG(data->fan_div[nr]));
1546 data->fan_div[nr] = DIV_TO_REG(val);
1550 data->fan_div[nr] = 1;
1552 data->fan_div[nr] = 3;
1555 val |= (data->fan_div[0] & 0x07);
1556 val |= (data->fan_div[1] & 0x07) << 3;
1557 if (data->fan_div[2] == 3)
1559 it87_write_value(data, IT87_REG_FAN_DIV, val);
1561 /* Restore fan min limit */
1562 data->fan[nr][1] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
1563 it87_write_value(data, data->REG_FAN_MIN[nr], data->fan[nr][1]);
1565 mutex_unlock(&data->update_lock);
1569 /* Returns 0 if OK, -EINVAL otherwise */
1570 static int check_trip_points(struct device *dev, int nr)
1572 const struct it87_data *data = dev_get_drvdata(dev);
1575 if (has_old_autopwm(data)) {
1576 for (i = 0; i < 3; i++) {
1577 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1])
1580 for (i = 0; i < 2; i++) {
1581 if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1])
1584 } else if (has_newer_autopwm(data)) {
1585 for (i = 1; i < 3; i++) {
1586 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1])
1593 "Inconsistent trip points, not switching to automatic mode\n");
1594 dev_err(dev, "Adjust the trip points and try again\n");
1599 static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr,
1600 const char *buf, size_t count)
1602 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1603 struct it87_data *data = dev_get_drvdata(dev);
1604 int nr = sensor_attr->index;
1607 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 2)
1610 /* Check trip points before switching to automatic mode */
1612 if (check_trip_points(dev, nr) < 0)
1616 mutex_lock(&data->update_lock);
1619 if (nr < 3 && has_fanctl_onoff(data)) {
1621 /* make sure the fan is on when in on/off mode */
1622 tmp = it87_read_value(data, IT87_REG_FAN_CTL);
1623 it87_write_value(data, IT87_REG_FAN_CTL, tmp | BIT(nr));
1624 /* set on/off mode */
1625 data->fan_main_ctrl &= ~BIT(nr);
1626 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
1627 data->fan_main_ctrl);
1631 /* No on/off mode, set maximum pwm value */
1632 data->pwm_duty[nr] = pwm_to_reg(data, 0xff);
1633 it87_write_value(data, IT87_REG_PWM_DUTY[nr],
1634 data->pwm_duty[nr]);
1635 /* and set manual mode */
1636 if (has_newer_autopwm(data)) {
1637 ctrl = (data->pwm_ctrl[nr] & 0x7c) |
1638 data->pwm_temp_map[nr];
1640 ctrl = data->pwm_duty[nr];
1642 data->pwm_ctrl[nr] = ctrl;
1643 it87_write_value(data, data->REG_PWM[nr], ctrl);
1648 if (has_newer_autopwm(data)) {
1649 ctrl = (data->pwm_ctrl[nr] & 0x7c) |
1650 data->pwm_temp_map[nr];
1654 ctrl = (val == 1 ? data->pwm_duty[nr] : 0x80);
1656 data->pwm_ctrl[nr] = ctrl;
1657 it87_write_value(data, data->REG_PWM[nr], ctrl);
1659 if (has_fanctl_onoff(data) && nr < 3) {
1660 /* set SmartGuardian mode */
1661 data->fan_main_ctrl |= BIT(nr);
1662 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
1663 data->fan_main_ctrl);
1667 mutex_unlock(&data->update_lock);
1671 static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1672 const char *buf, size_t count)
1674 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1675 struct it87_data *data = dev_get_drvdata(dev);
1676 int nr = sensor_attr->index;
1679 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
1682 mutex_lock(&data->update_lock);
1683 it87_update_pwm_ctrl(data, nr);
1684 if (has_newer_autopwm(data)) {
1686 * If we are in automatic mode, the PWM duty cycle register
1687 * is read-only so we can't write the value.
1689 if (data->pwm_ctrl[nr] & 0x80) {
1690 mutex_unlock(&data->update_lock);
1693 data->pwm_duty[nr] = pwm_to_reg(data, val);
1694 it87_write_value(data, IT87_REG_PWM_DUTY[nr],
1695 data->pwm_duty[nr]);
1697 data->pwm_duty[nr] = pwm_to_reg(data, val);
1699 * If we are in manual mode, write the duty cycle immediately;
1700 * otherwise, just store it for later use.
1702 if (!(data->pwm_ctrl[nr] & 0x80)) {
1703 data->pwm_ctrl[nr] = data->pwm_duty[nr];
1704 it87_write_value(data, data->REG_PWM[nr],
1705 data->pwm_ctrl[nr]);
1708 mutex_unlock(&data->update_lock);
1712 static ssize_t set_pwm_freq(struct device *dev, struct device_attribute *attr,
1713 const char *buf, size_t count)
1715 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1716 struct it87_data *data = dev_get_drvdata(dev);
1717 int nr = sensor_attr->index;
1721 if (kstrtoul(buf, 10, &val) < 0)
1724 val = clamp_val(val, 0, 1000000);
1725 val *= has_newer_autopwm(data) ? 256 : 128;
1727 /* Search for the nearest available frequency */
1728 for (i = 0; i < 7; i++) {
1729 if (val > (pwm_freq[i] + pwm_freq[i + 1]) / 2)
1733 mutex_lock(&data->update_lock);
1735 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f;
1736 data->fan_ctl |= i << 4;
1737 it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl);
1739 data->extra = it87_read_value(data, IT87_REG_TEMP_EXTRA) & 0x8f;
1740 data->extra |= i << 4;
1741 it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra);
1743 mutex_unlock(&data->update_lock);
1748 static ssize_t show_pwm_temp_map(struct device *dev,
1749 struct device_attribute *attr, char *buf)
1751 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1752 struct it87_data *data = it87_update_device(dev);
1753 int nr = sensor_attr->index;
1756 map = data->pwm_temp_map[nr];
1757 if (data->type == it8613) {
1760 map = 0; /* Should never happen */
1763 map = 0; /* Should never happen */
1764 if (nr >= 3) /* pwm channels 3..6 map to temp4..6 */
1768 return sprintf(buf, "%d\n", (int)BIT(map));
1771 static ssize_t set_pwm_temp_map(struct device *dev,
1772 struct device_attribute *attr, const char *buf,
1775 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1776 struct it87_data *data = dev_get_drvdata(dev);
1777 int nr = sensor_attr->index;
1781 if (kstrtol(buf, 10, &val) < 0)
1784 if (nr >= 3 && data->type != it8613)
1806 case BIT(5) | BIT(6):
1813 if (data->type == it8613)
1815 else if (reg > 0x02)
1818 mutex_lock(&data->update_lock);
1819 it87_update_pwm_ctrl(data, nr);
1820 data->pwm_temp_map[nr] = reg;
1822 * If we are in automatic mode, write the temp mapping immediately;
1823 * otherwise, just store it for later use.
1825 if (data->pwm_ctrl[nr] & 0x80) {
1826 data->pwm_ctrl[nr] = (data->pwm_ctrl[nr] & 0xfc) |
1827 data->pwm_temp_map[nr];
1828 it87_write_value(data, data->REG_PWM[nr], data->pwm_ctrl[nr]);
1830 mutex_unlock(&data->update_lock);
1834 static ssize_t show_auto_pwm(struct device *dev, struct device_attribute *attr,
1837 struct it87_data *data = it87_update_device(dev);
1838 struct sensor_device_attribute_2 *sensor_attr =
1839 to_sensor_dev_attr_2(attr);
1840 int nr = sensor_attr->nr;
1841 int point = sensor_attr->index;
1843 return sprintf(buf, "%d\n",
1844 pwm_from_reg(data, data->auto_pwm[nr][point]));
1847 static ssize_t set_auto_pwm(struct device *dev, struct device_attribute *attr,
1848 const char *buf, size_t count)
1850 struct it87_data *data = dev_get_drvdata(dev);
1851 struct sensor_device_attribute_2 *sensor_attr =
1852 to_sensor_dev_attr_2(attr);
1853 int nr = sensor_attr->nr;
1854 int point = sensor_attr->index;
1858 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
1861 mutex_lock(&data->update_lock);
1862 data->auto_pwm[nr][point] = pwm_to_reg(data, val);
1863 if (has_newer_autopwm(data))
1864 regaddr = IT87_REG_AUTO_TEMP(nr, 3);
1866 regaddr = IT87_REG_AUTO_PWM(nr, point);
1867 it87_write_value(data, regaddr, data->auto_pwm[nr][point]);
1868 mutex_unlock(&data->update_lock);
1872 static ssize_t show_auto_pwm_slope(struct device *dev,
1873 struct device_attribute *attr, char *buf)
1875 struct it87_data *data = it87_update_device(dev);
1876 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1877 int nr = sensor_attr->index;
1879 return sprintf(buf, "%d\n", data->auto_pwm[nr][1] & 0x7f);
1882 static ssize_t set_auto_pwm_slope(struct device *dev,
1883 struct device_attribute *attr,
1884 const char *buf, size_t count)
1886 struct it87_data *data = dev_get_drvdata(dev);
1887 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1888 int nr = sensor_attr->index;
1891 if (kstrtoul(buf, 10, &val) < 0 || val > 127)
1894 mutex_lock(&data->update_lock);
1895 data->auto_pwm[nr][1] = (data->auto_pwm[nr][1] & 0x80) | val;
1896 it87_write_value(data, IT87_REG_AUTO_TEMP(nr, 4),
1897 data->auto_pwm[nr][1]);
1898 mutex_unlock(&data->update_lock);
1902 static ssize_t show_auto_temp(struct device *dev, struct device_attribute *attr,
1905 struct it87_data *data = it87_update_device(dev);
1906 struct sensor_device_attribute_2 *sensor_attr =
1907 to_sensor_dev_attr_2(attr);
1908 int nr = sensor_attr->nr;
1909 int point = sensor_attr->index;
1912 if (has_old_autopwm(data) || point)
1913 reg = data->auto_temp[nr][point];
1915 reg = data->auto_temp[nr][1] - (data->auto_temp[nr][0] & 0x1f);
1917 return sprintf(buf, "%d\n", TEMP_FROM_REG(reg));
1920 static ssize_t set_auto_temp(struct device *dev, struct device_attribute *attr,
1921 const char *buf, size_t count)
1923 struct it87_data *data = dev_get_drvdata(dev);
1924 struct sensor_device_attribute_2 *sensor_attr =
1925 to_sensor_dev_attr_2(attr);
1926 int nr = sensor_attr->nr;
1927 int point = sensor_attr->index;
1931 if (kstrtol(buf, 10, &val) < 0 || val < -128000 || val > 127000)
1934 mutex_lock(&data->update_lock);
1935 if (has_newer_autopwm(data) && !point) {
1936 reg = data->auto_temp[nr][1] - TEMP_TO_REG(val);
1937 reg = clamp_val(reg, 0, 0x1f) | (data->auto_temp[nr][0] & 0xe0);
1938 data->auto_temp[nr][0] = reg;
1939 it87_write_value(data, IT87_REG_AUTO_TEMP(nr, 5), reg);
1941 reg = TEMP_TO_REG(val);
1942 data->auto_temp[nr][point] = reg;
1943 if (has_newer_autopwm(data))
1945 it87_write_value(data, IT87_REG_AUTO_TEMP(nr, point), reg);
1947 mutex_unlock(&data->update_lock);
1951 static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0);
1952 static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1954 static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, show_fan_div,
1957 static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 1, 0);
1958 static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1960 static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, show_fan_div,
1963 static SENSOR_DEVICE_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 2, 0);
1964 static SENSOR_DEVICE_ATTR_2(fan3_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1966 static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO | S_IWUSR, show_fan_div,
1969 static SENSOR_DEVICE_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 3, 0);
1970 static SENSOR_DEVICE_ATTR_2(fan4_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1973 static SENSOR_DEVICE_ATTR_2(fan5_input, S_IRUGO, show_fan, NULL, 4, 0);
1974 static SENSOR_DEVICE_ATTR_2(fan5_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1977 static SENSOR_DEVICE_ATTR_2(fan6_input, S_IRUGO, show_fan, NULL, 5, 0);
1978 static SENSOR_DEVICE_ATTR_2(fan6_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1981 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
1982 show_pwm_enable, set_pwm_enable, 0);
1983 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0);
1984 static SENSOR_DEVICE_ATTR(pwm1_freq, S_IRUGO | S_IWUSR, show_pwm_freq,
1986 static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IRUGO,
1987 show_pwm_temp_map, set_pwm_temp_map, 0);
1988 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR,
1989 show_auto_pwm, set_auto_pwm, 0, 0);
1990 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR,
1991 show_auto_pwm, set_auto_pwm, 0, 1);
1992 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR,
1993 show_auto_pwm, set_auto_pwm, 0, 2);
1994 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO,
1995 show_auto_pwm, NULL, 0, 3);
1996 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR,
1997 show_auto_temp, set_auto_temp, 0, 1);
1998 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1999 show_auto_temp, set_auto_temp, 0, 0);
2000 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR,
2001 show_auto_temp, set_auto_temp, 0, 2);
2002 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR,
2003 show_auto_temp, set_auto_temp, 0, 3);
2004 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR,
2005 show_auto_temp, set_auto_temp, 0, 4);
2006 static SENSOR_DEVICE_ATTR_2(pwm1_auto_start, S_IRUGO | S_IWUSR,
2007 show_auto_pwm, set_auto_pwm, 0, 0);
2008 static SENSOR_DEVICE_ATTR(pwm1_auto_slope, S_IRUGO | S_IWUSR,
2009 show_auto_pwm_slope, set_auto_pwm_slope, 0);
2011 static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR,
2012 show_pwm_enable, set_pwm_enable, 1);
2013 static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 1);
2014 static SENSOR_DEVICE_ATTR(pwm2_freq, S_IRUGO, show_pwm_freq, set_pwm_freq, 1);
2015 static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IRUGO,
2016 show_pwm_temp_map, set_pwm_temp_map, 1);
2017 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR,
2018 show_auto_pwm, set_auto_pwm, 1, 0);
2019 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO | S_IWUSR,
2020 show_auto_pwm, set_auto_pwm, 1, 1);
2021 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO | S_IWUSR,
2022 show_auto_pwm, set_auto_pwm, 1, 2);
2023 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO,
2024 show_auto_pwm, NULL, 1, 3);
2025 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR,
2026 show_auto_temp, set_auto_temp, 1, 1);
2027 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
2028 show_auto_temp, set_auto_temp, 1, 0);
2029 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR,
2030 show_auto_temp, set_auto_temp, 1, 2);
2031 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR,
2032 show_auto_temp, set_auto_temp, 1, 3);
2033 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_temp, S_IRUGO | S_IWUSR,
2034 show_auto_temp, set_auto_temp, 1, 4);
2035 static SENSOR_DEVICE_ATTR_2(pwm2_auto_start, S_IRUGO | S_IWUSR,
2036 show_auto_pwm, set_auto_pwm, 1, 0);
2037 static SENSOR_DEVICE_ATTR(pwm2_auto_slope, S_IRUGO | S_IWUSR,
2038 show_auto_pwm_slope, set_auto_pwm_slope, 1);
2040 static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR,
2041 show_pwm_enable, set_pwm_enable, 2);
2042 static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 2);
2043 static SENSOR_DEVICE_ATTR(pwm3_freq, S_IRUGO, show_pwm_freq, NULL, 2);
2044 static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IRUGO,
2045 show_pwm_temp_map, set_pwm_temp_map, 2);
2046 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO | S_IWUSR,
2047 show_auto_pwm, set_auto_pwm, 2, 0);
2048 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR,
2049 show_auto_pwm, set_auto_pwm, 2, 1);
2050 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO | S_IWUSR,
2051 show_auto_pwm, set_auto_pwm, 2, 2);
2052 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO,
2053 show_auto_pwm, NULL, 2, 3);
2054 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp, S_IRUGO | S_IWUSR,
2055 show_auto_temp, set_auto_temp, 2, 1);
2056 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
2057 show_auto_temp, set_auto_temp, 2, 0);
2058 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_temp, S_IRUGO | S_IWUSR,
2059 show_auto_temp, set_auto_temp, 2, 2);
2060 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_temp, S_IRUGO | S_IWUSR,
2061 show_auto_temp, set_auto_temp, 2, 3);
2062 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_temp, S_IRUGO | S_IWUSR,
2063 show_auto_temp, set_auto_temp, 2, 4);
2064 static SENSOR_DEVICE_ATTR_2(pwm3_auto_start, S_IRUGO | S_IWUSR,
2065 show_auto_pwm, set_auto_pwm, 2, 0);
2066 static SENSOR_DEVICE_ATTR(pwm3_auto_slope, S_IRUGO | S_IWUSR,
2067 show_auto_pwm_slope, set_auto_pwm_slope, 2);
2069 static SENSOR_DEVICE_ATTR(pwm4_enable, S_IRUGO | S_IWUSR,
2070 show_pwm_enable, set_pwm_enable, 3);
2071 static SENSOR_DEVICE_ATTR(pwm4, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 3);
2072 static SENSOR_DEVICE_ATTR(pwm4_freq, S_IRUGO, show_pwm_freq, NULL, 3);
2073 static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IRUGO,
2074 show_pwm_temp_map, set_pwm_temp_map, 3);
2075 static SENSOR_DEVICE_ATTR_2(pwm4_auto_point1_temp, S_IRUGO | S_IWUSR,
2076 show_auto_temp, set_auto_temp, 2, 1);
2077 static SENSOR_DEVICE_ATTR_2(pwm4_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
2078 show_auto_temp, set_auto_temp, 2, 0);
2079 static SENSOR_DEVICE_ATTR_2(pwm4_auto_point2_temp, S_IRUGO | S_IWUSR,
2080 show_auto_temp, set_auto_temp, 2, 2);
2081 static SENSOR_DEVICE_ATTR_2(pwm4_auto_point3_temp, S_IRUGO | S_IWUSR,
2082 show_auto_temp, set_auto_temp, 2, 3);
2083 static SENSOR_DEVICE_ATTR_2(pwm4_auto_start, S_IRUGO | S_IWUSR,
2084 show_auto_pwm, set_auto_pwm, 3, 0);
2085 static SENSOR_DEVICE_ATTR(pwm4_auto_slope, S_IRUGO | S_IWUSR,
2086 show_auto_pwm_slope, set_auto_pwm_slope, 3);
2088 static SENSOR_DEVICE_ATTR(pwm5_enable, S_IRUGO | S_IWUSR,
2089 show_pwm_enable, set_pwm_enable, 4);
2090 static SENSOR_DEVICE_ATTR(pwm5, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 4);
2091 static SENSOR_DEVICE_ATTR(pwm5_freq, S_IRUGO, show_pwm_freq, NULL, 4);
2092 static SENSOR_DEVICE_ATTR(pwm5_auto_channels_temp, S_IRUGO,
2093 show_pwm_temp_map, set_pwm_temp_map, 4);
2094 static SENSOR_DEVICE_ATTR_2(pwm5_auto_point1_temp, S_IRUGO | S_IWUSR,
2095 show_auto_temp, set_auto_temp, 2, 1);
2096 static SENSOR_DEVICE_ATTR_2(pwm5_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
2097 show_auto_temp, set_auto_temp, 2, 0);
2098 static SENSOR_DEVICE_ATTR_2(pwm5_auto_point2_temp, S_IRUGO | S_IWUSR,
2099 show_auto_temp, set_auto_temp, 2, 2);
2100 static SENSOR_DEVICE_ATTR_2(pwm5_auto_point3_temp, S_IRUGO | S_IWUSR,
2101 show_auto_temp, set_auto_temp, 2, 3);
2102 static SENSOR_DEVICE_ATTR_2(pwm5_auto_start, S_IRUGO | S_IWUSR,
2103 show_auto_pwm, set_auto_pwm, 4, 0);
2104 static SENSOR_DEVICE_ATTR(pwm5_auto_slope, S_IRUGO | S_IWUSR,
2105 show_auto_pwm_slope, set_auto_pwm_slope, 4);
2107 static SENSOR_DEVICE_ATTR(pwm6_enable, S_IRUGO | S_IWUSR,
2108 show_pwm_enable, set_pwm_enable, 5);
2109 static SENSOR_DEVICE_ATTR(pwm6, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 5);
2110 static SENSOR_DEVICE_ATTR(pwm6_freq, S_IRUGO, show_pwm_freq, NULL, 5);
2111 static SENSOR_DEVICE_ATTR(pwm6_auto_channels_temp, S_IRUGO,
2112 show_pwm_temp_map, set_pwm_temp_map, 5);
2113 static SENSOR_DEVICE_ATTR_2(pwm6_auto_point1_temp, S_IRUGO | S_IWUSR,
2114 show_auto_temp, set_auto_temp, 2, 1);
2115 static SENSOR_DEVICE_ATTR_2(pwm6_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
2116 show_auto_temp, set_auto_temp, 2, 0);
2117 static SENSOR_DEVICE_ATTR_2(pwm6_auto_point2_temp, S_IRUGO | S_IWUSR,
2118 show_auto_temp, set_auto_temp, 2, 2);
2119 static SENSOR_DEVICE_ATTR_2(pwm6_auto_point3_temp, S_IRUGO | S_IWUSR,
2120 show_auto_temp, set_auto_temp, 2, 3);
2121 static SENSOR_DEVICE_ATTR_2(pwm6_auto_start, S_IRUGO | S_IWUSR,
2122 show_auto_pwm, set_auto_pwm, 5, 0);
2123 static SENSOR_DEVICE_ATTR(pwm6_auto_slope, S_IRUGO | S_IWUSR,
2124 show_auto_pwm_slope, set_auto_pwm_slope, 5);
2127 static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
2130 struct it87_data *data = it87_update_device(dev);
2132 return sprintf(buf, "%u\n", data->alarms);
2134 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
2136 static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
2139 struct it87_data *data = it87_update_device(dev);
2140 int bitnr = to_sensor_dev_attr(attr)->index;
2142 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
2145 static ssize_t clear_intrusion(struct device *dev,
2146 struct device_attribute *attr, const char *buf,
2149 struct it87_data *data = dev_get_drvdata(dev);
2153 if (kstrtol(buf, 10, &val) < 0 || val != 0)
2156 mutex_lock(&data->update_lock);
2157 config = it87_read_value(data, IT87_REG_CONFIG);
2162 it87_write_value(data, IT87_REG_CONFIG, config);
2163 /* Invalidate cache to force re-read */
2166 mutex_unlock(&data->update_lock);
2171 static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8);
2172 static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9);
2173 static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10);
2174 static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11);
2175 static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12);
2176 static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13);
2177 static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14);
2178 static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15);
2179 static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0);
2180 static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1);
2181 static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2);
2182 static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3);
2183 static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6);
2184 static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_alarm, NULL, 7);
2185 static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16);
2186 static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17);
2187 static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18);
2188 static SENSOR_DEVICE_ATTR(temp4_alarm, S_IRUGO, show_alarm, NULL, 19);
2189 static SENSOR_DEVICE_ATTR(temp5_alarm, S_IRUGO, show_alarm, NULL, 20);
2190 static SENSOR_DEVICE_ATTR(temp6_alarm, S_IRUGO, show_alarm, NULL, 21);
2191 static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR,
2192 show_alarm, clear_intrusion, 4);
2194 static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
2197 struct it87_data *data = it87_update_device(dev);
2198 int bitnr = to_sensor_dev_attr(attr)->index;
2200 return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1);
2203 static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
2204 const char *buf, size_t count)
2206 int bitnr = to_sensor_dev_attr(attr)->index;
2207 struct it87_data *data = dev_get_drvdata(dev);
2210 if (kstrtol(buf, 10, &val) < 0 || (val != 0 && val != 1))
2213 mutex_lock(&data->update_lock);
2214 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
2216 data->beeps |= BIT(bitnr);
2218 data->beeps &= ~BIT(bitnr);
2219 it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps);
2220 mutex_unlock(&data->update_lock);
2224 static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
2225 show_beep, set_beep, 1);
2226 static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO, show_beep, NULL, 1);
2227 static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO, show_beep, NULL, 1);
2228 static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO, show_beep, NULL, 1);
2229 static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO, show_beep, NULL, 1);
2230 static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO, show_beep, NULL, 1);
2231 static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO, show_beep, NULL, 1);
2232 static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO, show_beep, NULL, 1);
2233 /* fanX_beep writability is set later */
2234 static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO, show_beep, set_beep, 0);
2235 static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0);
2236 static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0);
2237 static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0);
2238 static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0);
2239 static SENSOR_DEVICE_ATTR(fan6_beep, S_IRUGO, show_beep, set_beep, 0);
2240 static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
2241 show_beep, set_beep, 2);
2242 static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2);
2243 static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2);
2244 static SENSOR_DEVICE_ATTR(temp4_beep, S_IRUGO, show_beep, NULL, 2);
2245 static SENSOR_DEVICE_ATTR(temp5_beep, S_IRUGO, show_beep, NULL, 2);
2246 static SENSOR_DEVICE_ATTR(temp6_beep, S_IRUGO, show_beep, NULL, 2);
2248 static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
2251 struct it87_data *data = dev_get_drvdata(dev);
2253 return sprintf(buf, "%u\n", data->vrm);
2256 static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
2257 const char *buf, size_t count)
2259 struct it87_data *data = dev_get_drvdata(dev);
2262 if (kstrtoul(buf, 10, &val) < 0)
2269 static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
2271 static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
2274 struct it87_data *data = it87_update_device(dev);
2276 return sprintf(buf, "%ld\n", (long)vid_from_reg(data->vid, data->vrm));
2278 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
2280 static ssize_t show_label(struct device *dev, struct device_attribute *attr,
2283 static const char * const labels[] = {
2289 static const char * const labels_it8721[] = {
2295 struct it87_data *data = dev_get_drvdata(dev);
2296 int nr = to_sensor_dev_attr(attr)->index;
2299 if (has_vin3_5v(data) && nr == 0)
2301 else if (has_12mv_adc(data) || has_10_9mv_adc(data) ||
2303 label = labels_it8721[nr];
2307 return sprintf(buf, "%s\n", label);
2309 static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0);
2310 static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1);
2311 static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 2);
2313 static SENSOR_DEVICE_ATTR(in9_label, S_IRUGO, show_label, NULL, 3);
2315 static umode_t it87_in_is_visible(struct kobject *kobj,
2316 struct attribute *attr, int index)
2318 struct device *dev = container_of(kobj, struct device, kobj);
2319 struct it87_data *data = dev_get_drvdata(dev);
2320 int i = index / 5; /* voltage index */
2321 int a = index % 5; /* attribute index */
2323 if (index >= 40) { /* in8 and higher only have input attributes */
2328 if (!(data->has_in & BIT(i)))
2331 if (a == 4 && !data->has_beep)
2337 static struct attribute *it87_attributes_in[] = {
2338 &sensor_dev_attr_in0_input.dev_attr.attr,
2339 &sensor_dev_attr_in0_min.dev_attr.attr,
2340 &sensor_dev_attr_in0_max.dev_attr.attr,
2341 &sensor_dev_attr_in0_alarm.dev_attr.attr,
2342 &sensor_dev_attr_in0_beep.dev_attr.attr, /* 4 */
2344 &sensor_dev_attr_in1_input.dev_attr.attr,
2345 &sensor_dev_attr_in1_min.dev_attr.attr,
2346 &sensor_dev_attr_in1_max.dev_attr.attr,
2347 &sensor_dev_attr_in1_alarm.dev_attr.attr,
2348 &sensor_dev_attr_in1_beep.dev_attr.attr, /* 9 */
2350 &sensor_dev_attr_in2_input.dev_attr.attr,
2351 &sensor_dev_attr_in2_min.dev_attr.attr,
2352 &sensor_dev_attr_in2_max.dev_attr.attr,
2353 &sensor_dev_attr_in2_alarm.dev_attr.attr,
2354 &sensor_dev_attr_in2_beep.dev_attr.attr, /* 14 */
2356 &sensor_dev_attr_in3_input.dev_attr.attr,
2357 &sensor_dev_attr_in3_min.dev_attr.attr,
2358 &sensor_dev_attr_in3_max.dev_attr.attr,
2359 &sensor_dev_attr_in3_alarm.dev_attr.attr,
2360 &sensor_dev_attr_in3_beep.dev_attr.attr, /* 19 */
2362 &sensor_dev_attr_in4_input.dev_attr.attr,
2363 &sensor_dev_attr_in4_min.dev_attr.attr,
2364 &sensor_dev_attr_in4_max.dev_attr.attr,
2365 &sensor_dev_attr_in4_alarm.dev_attr.attr,
2366 &sensor_dev_attr_in4_beep.dev_attr.attr, /* 24 */
2368 &sensor_dev_attr_in5_input.dev_attr.attr,
2369 &sensor_dev_attr_in5_min.dev_attr.attr,
2370 &sensor_dev_attr_in5_max.dev_attr.attr,
2371 &sensor_dev_attr_in5_alarm.dev_attr.attr,
2372 &sensor_dev_attr_in5_beep.dev_attr.attr, /* 29 */
2374 &sensor_dev_attr_in6_input.dev_attr.attr,
2375 &sensor_dev_attr_in6_min.dev_attr.attr,
2376 &sensor_dev_attr_in6_max.dev_attr.attr,
2377 &sensor_dev_attr_in6_alarm.dev_attr.attr,
2378 &sensor_dev_attr_in6_beep.dev_attr.attr, /* 34 */
2380 &sensor_dev_attr_in7_input.dev_attr.attr,
2381 &sensor_dev_attr_in7_min.dev_attr.attr,
2382 &sensor_dev_attr_in7_max.dev_attr.attr,
2383 &sensor_dev_attr_in7_alarm.dev_attr.attr,
2384 &sensor_dev_attr_in7_beep.dev_attr.attr, /* 39 */
2386 &sensor_dev_attr_in8_input.dev_attr.attr, /* 40 */
2387 &sensor_dev_attr_in9_input.dev_attr.attr, /* 41 */
2388 &sensor_dev_attr_in10_input.dev_attr.attr, /* 42 */
2389 &sensor_dev_attr_in11_input.dev_attr.attr, /* 43 */
2390 &sensor_dev_attr_in12_input.dev_attr.attr, /* 44 */
2394 static const struct attribute_group it87_group_in = {
2395 .attrs = it87_attributes_in,
2396 .is_visible = it87_in_is_visible,
2399 static umode_t it87_temp_is_visible(struct kobject *kobj,
2400 struct attribute *attr, int index)
2402 struct device *dev = container_of(kobj, struct device, kobj);
2403 struct it87_data *data = dev_get_drvdata(dev);
2404 int i = index / 7; /* temperature index */
2405 int a = index % 7; /* attribute index */
2407 if (!(data->has_temp & BIT(i)))
2410 if (a && i >= data->num_temp_limit)
2414 int type = get_temp_type(data, i);
2418 if (has_bank_sel(data))
2423 if (a == 5 && !has_temp_offset(data))
2426 if (a == 6 && !data->has_beep)
2432 static struct attribute *it87_attributes_temp[] = {
2433 &sensor_dev_attr_temp1_input.dev_attr.attr,
2434 &sensor_dev_attr_temp1_max.dev_attr.attr,
2435 &sensor_dev_attr_temp1_min.dev_attr.attr,
2436 &sensor_dev_attr_temp1_type.dev_attr.attr, /* 3 */
2437 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
2438 &sensor_dev_attr_temp1_offset.dev_attr.attr, /* 5 */
2439 &sensor_dev_attr_temp1_beep.dev_attr.attr, /* 6 */
2441 &sensor_dev_attr_temp2_input.dev_attr.attr, /* 7 */
2442 &sensor_dev_attr_temp2_max.dev_attr.attr,
2443 &sensor_dev_attr_temp2_min.dev_attr.attr,
2444 &sensor_dev_attr_temp2_type.dev_attr.attr,
2445 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
2446 &sensor_dev_attr_temp2_offset.dev_attr.attr,
2447 &sensor_dev_attr_temp2_beep.dev_attr.attr,
2449 &sensor_dev_attr_temp3_input.dev_attr.attr, /* 14 */
2450 &sensor_dev_attr_temp3_max.dev_attr.attr,
2451 &sensor_dev_attr_temp3_min.dev_attr.attr,
2452 &sensor_dev_attr_temp3_type.dev_attr.attr,
2453 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
2454 &sensor_dev_attr_temp3_offset.dev_attr.attr,
2455 &sensor_dev_attr_temp3_beep.dev_attr.attr,
2457 &sensor_dev_attr_temp4_input.dev_attr.attr, /* 21 */
2458 &sensor_dev_attr_temp4_max.dev_attr.attr,
2459 &sensor_dev_attr_temp4_min.dev_attr.attr,
2460 &sensor_dev_attr_temp4_type.dev_attr.attr,
2461 &sensor_dev_attr_temp4_alarm.dev_attr.attr,
2462 &sensor_dev_attr_temp4_offset.dev_attr.attr,
2463 &sensor_dev_attr_temp4_beep.dev_attr.attr,
2465 &sensor_dev_attr_temp5_input.dev_attr.attr,
2466 &sensor_dev_attr_temp5_max.dev_attr.attr,
2467 &sensor_dev_attr_temp5_min.dev_attr.attr,
2468 &sensor_dev_attr_temp5_type.dev_attr.attr,
2469 &sensor_dev_attr_temp5_alarm.dev_attr.attr,
2470 &sensor_dev_attr_temp5_offset.dev_attr.attr,
2471 &sensor_dev_attr_temp5_beep.dev_attr.attr,
2473 &sensor_dev_attr_temp6_input.dev_attr.attr,
2474 &sensor_dev_attr_temp6_max.dev_attr.attr,
2475 &sensor_dev_attr_temp6_min.dev_attr.attr,
2476 &sensor_dev_attr_temp6_type.dev_attr.attr,
2477 &sensor_dev_attr_temp6_alarm.dev_attr.attr,
2478 &sensor_dev_attr_temp6_offset.dev_attr.attr,
2479 &sensor_dev_attr_temp6_beep.dev_attr.attr,
2483 static const struct attribute_group it87_group_temp = {
2484 .attrs = it87_attributes_temp,
2485 .is_visible = it87_temp_is_visible,
2488 static umode_t it87_is_visible(struct kobject *kobj,
2489 struct attribute *attr, int index)
2491 struct device *dev = container_of(kobj, struct device, kobj);
2492 struct it87_data *data = dev_get_drvdata(dev);
2494 if ((index == 2 || index == 3) && !data->has_vid)
2497 if (index > 3 && !(data->in_internal & BIT(index - 4)))
2503 static struct attribute *it87_attributes[] = {
2504 &dev_attr_alarms.attr,
2505 &sensor_dev_attr_intrusion0_alarm.dev_attr.attr,
2506 &dev_attr_vrm.attr, /* 2 */
2507 &dev_attr_cpu0_vid.attr, /* 3 */
2508 &sensor_dev_attr_in3_label.dev_attr.attr, /* 4 .. 7 */
2509 &sensor_dev_attr_in7_label.dev_attr.attr,
2510 &sensor_dev_attr_in8_label.dev_attr.attr,
2511 &sensor_dev_attr_in9_label.dev_attr.attr,
2515 static const struct attribute_group it87_group = {
2516 .attrs = it87_attributes,
2517 .is_visible = it87_is_visible,
2520 static umode_t it87_fan_is_visible(struct kobject *kobj,
2521 struct attribute *attr, int index)
2523 struct device *dev = container_of(kobj, struct device, kobj);
2524 struct it87_data *data = dev_get_drvdata(dev);
2525 int i = index / 5; /* fan index */
2526 int a = index % 5; /* attribute index */
2528 if (index >= 15) { /* fan 4..6 don't have divisor attributes */
2529 i = (index - 15) / 4 + 3;
2530 a = (index - 15) % 4;
2533 if (!(data->has_fan & BIT(i)))
2536 if (a == 3) { /* beep */
2537 if (!data->has_beep)
2539 /* first fan beep attribute is writable */
2540 if (i == __ffs(data->has_fan))
2541 return attr->mode | S_IWUSR;
2544 if (a == 4 && has_16bit_fans(data)) /* divisor */
2550 static struct attribute *it87_attributes_fan[] = {
2551 &sensor_dev_attr_fan1_input.dev_attr.attr,
2552 &sensor_dev_attr_fan1_min.dev_attr.attr,
2553 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
2554 &sensor_dev_attr_fan1_beep.dev_attr.attr, /* 3 */
2555 &sensor_dev_attr_fan1_div.dev_attr.attr, /* 4 */
2557 &sensor_dev_attr_fan2_input.dev_attr.attr,
2558 &sensor_dev_attr_fan2_min.dev_attr.attr,
2559 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
2560 &sensor_dev_attr_fan2_beep.dev_attr.attr,
2561 &sensor_dev_attr_fan2_div.dev_attr.attr, /* 9 */
2563 &sensor_dev_attr_fan3_input.dev_attr.attr,
2564 &sensor_dev_attr_fan3_min.dev_attr.attr,
2565 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
2566 &sensor_dev_attr_fan3_beep.dev_attr.attr,
2567 &sensor_dev_attr_fan3_div.dev_attr.attr, /* 14 */
2569 &sensor_dev_attr_fan4_input.dev_attr.attr, /* 15 */
2570 &sensor_dev_attr_fan4_min.dev_attr.attr,
2571 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
2572 &sensor_dev_attr_fan4_beep.dev_attr.attr,
2574 &sensor_dev_attr_fan5_input.dev_attr.attr, /* 19 */
2575 &sensor_dev_attr_fan5_min.dev_attr.attr,
2576 &sensor_dev_attr_fan5_alarm.dev_attr.attr,
2577 &sensor_dev_attr_fan5_beep.dev_attr.attr,
2579 &sensor_dev_attr_fan6_input.dev_attr.attr, /* 23 */
2580 &sensor_dev_attr_fan6_min.dev_attr.attr,
2581 &sensor_dev_attr_fan6_alarm.dev_attr.attr,
2582 &sensor_dev_attr_fan6_beep.dev_attr.attr,
2586 static const struct attribute_group it87_group_fan = {
2587 .attrs = it87_attributes_fan,
2588 .is_visible = it87_fan_is_visible,
2591 static umode_t it87_pwm_is_visible(struct kobject *kobj,
2592 struct attribute *attr, int index)
2594 struct device *dev = container_of(kobj, struct device, kobj);
2595 struct it87_data *data = dev_get_drvdata(dev);
2596 int i = index / 4; /* pwm index */
2597 int a = index % 4; /* attribute index */
2599 if (!(data->has_pwm & BIT(i)))
2602 /* pwmX_auto_channels_temp is only writable if auto pwm is supported */
2603 if (a == 3 && (has_old_autopwm(data) || has_newer_autopwm(data)))
2604 return attr->mode | S_IWUSR;
2606 /* pwm2_freq is writable if there are two pwm frequency selects */
2607 if (has_pwm_freq2(data) && i == 1 && a == 2)
2608 return attr->mode | S_IWUSR;
2613 static struct attribute *it87_attributes_pwm[] = {
2614 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
2615 &sensor_dev_attr_pwm1.dev_attr.attr,
2616 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
2617 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
2619 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
2620 &sensor_dev_attr_pwm2.dev_attr.attr,
2621 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
2622 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
2624 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
2625 &sensor_dev_attr_pwm3.dev_attr.attr,
2626 &sensor_dev_attr_pwm3_freq.dev_attr.attr,
2627 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
2629 &sensor_dev_attr_pwm4_enable.dev_attr.attr,
2630 &sensor_dev_attr_pwm4.dev_attr.attr,
2631 &sensor_dev_attr_pwm4_freq.dev_attr.attr,
2632 &sensor_dev_attr_pwm4_auto_channels_temp.dev_attr.attr,
2634 &sensor_dev_attr_pwm5_enable.dev_attr.attr,
2635 &sensor_dev_attr_pwm5.dev_attr.attr,
2636 &sensor_dev_attr_pwm5_freq.dev_attr.attr,
2637 &sensor_dev_attr_pwm5_auto_channels_temp.dev_attr.attr,
2639 &sensor_dev_attr_pwm6_enable.dev_attr.attr,
2640 &sensor_dev_attr_pwm6.dev_attr.attr,
2641 &sensor_dev_attr_pwm6_freq.dev_attr.attr,
2642 &sensor_dev_attr_pwm6_auto_channels_temp.dev_attr.attr,
2647 static const struct attribute_group it87_group_pwm = {
2648 .attrs = it87_attributes_pwm,
2649 .is_visible = it87_pwm_is_visible,
2652 static umode_t it87_auto_pwm_is_visible(struct kobject *kobj,
2653 struct attribute *attr, int index)
2655 struct device *dev = container_of(kobj, struct device, kobj);
2656 struct it87_data *data = dev_get_drvdata(dev);
2657 int i = index / 11; /* pwm index */
2658 int a = index % 11; /* attribute index */
2660 if (index >= 33) { /* pwm 4..6 */
2661 i = (index - 33) / 6 + 3;
2662 a = (index - 33) % 6 + 4;
2665 if (!(data->has_pwm & BIT(i)))
2668 if (has_newer_autopwm(data)) {
2669 if (a < 4) /* no auto point pwm */
2671 if (a == 8) /* no auto_point4 */
2674 if (has_old_autopwm(data)) {
2675 if (a >= 9) /* no pwm_auto_start, pwm_auto_slope */
2682 static struct attribute *it87_attributes_auto_pwm[] = {
2683 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
2684 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
2685 &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr,
2686 &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr,
2687 &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
2688 &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr,
2689 &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr,
2690 &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr,
2691 &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr,
2692 &sensor_dev_attr_pwm1_auto_start.dev_attr.attr,
2693 &sensor_dev_attr_pwm1_auto_slope.dev_attr.attr,
2695 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr, /* 11 */
2696 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
2697 &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr,
2698 &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr,
2699 &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr,
2700 &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr,
2701 &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr,
2702 &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr,
2703 &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr,
2704 &sensor_dev_attr_pwm2_auto_start.dev_attr.attr,
2705 &sensor_dev_attr_pwm2_auto_slope.dev_attr.attr,
2707 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr, /* 22 */
2708 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
2709 &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr,
2710 &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr,
2711 &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr,
2712 &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr,
2713 &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr,
2714 &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr,
2715 &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr,
2716 &sensor_dev_attr_pwm3_auto_start.dev_attr.attr,
2717 &sensor_dev_attr_pwm3_auto_slope.dev_attr.attr,
2719 &sensor_dev_attr_pwm4_auto_point1_temp.dev_attr.attr, /* 33 */
2720 &sensor_dev_attr_pwm4_auto_point1_temp_hyst.dev_attr.attr,
2721 &sensor_dev_attr_pwm4_auto_point2_temp.dev_attr.attr,
2722 &sensor_dev_attr_pwm4_auto_point3_temp.dev_attr.attr,
2723 &sensor_dev_attr_pwm4_auto_start.dev_attr.attr,
2724 &sensor_dev_attr_pwm4_auto_slope.dev_attr.attr,
2726 &sensor_dev_attr_pwm5_auto_point1_temp.dev_attr.attr,
2727 &sensor_dev_attr_pwm5_auto_point1_temp_hyst.dev_attr.attr,
2728 &sensor_dev_attr_pwm5_auto_point2_temp.dev_attr.attr,
2729 &sensor_dev_attr_pwm5_auto_point3_temp.dev_attr.attr,
2730 &sensor_dev_attr_pwm5_auto_start.dev_attr.attr,
2731 &sensor_dev_attr_pwm5_auto_slope.dev_attr.attr,
2733 &sensor_dev_attr_pwm6_auto_point1_temp.dev_attr.attr,
2734 &sensor_dev_attr_pwm6_auto_point1_temp_hyst.dev_attr.attr,
2735 &sensor_dev_attr_pwm6_auto_point2_temp.dev_attr.attr,
2736 &sensor_dev_attr_pwm6_auto_point3_temp.dev_attr.attr,
2737 &sensor_dev_attr_pwm6_auto_start.dev_attr.attr,
2738 &sensor_dev_attr_pwm6_auto_slope.dev_attr.attr,
2743 static const struct attribute_group it87_group_auto_pwm = {
2744 .attrs = it87_attributes_auto_pwm,
2745 .is_visible = it87_auto_pwm_is_visible,
2748 /* SuperIO detection - will change isa_address if a chip is found */
2749 static int __init it87_find(int sioaddr, unsigned short *address,
2750 struct it87_sio_data *sio_data)
2754 const struct it87_devices *config;
2756 err = superio_enter(sioaddr);
2761 chip_type = superio_inw(sioaddr, DEVID);
2762 if (chip_type == 0xffff)
2766 chip_type = force_id;
2768 switch (chip_type) {
2770 sio_data->type = it87;
2773 sio_data->type = it8712;
2777 sio_data->type = it8716;
2780 sio_data->type = it8718;
2783 sio_data->type = it8720;
2786 sio_data->type = it8721;
2789 sio_data->type = it8728;
2792 sio_data->type = it8732;
2795 sio_data->type = it8792;
2798 sio_data->type = it8771;
2801 sio_data->type = it8772;
2804 sio_data->type = it8781;
2807 sio_data->type = it8782;
2810 sio_data->type = it8783;
2813 sio_data->type = it8786;
2816 sio_data->type = it8790;
2820 sio_data->type = it8603;
2823 sio_data->type = it8607;
2826 sio_data->type = it8613;
2829 sio_data->type = it8620;
2832 sio_data->type = it8622;
2835 sio_data->type = it8628;
2838 sio_data->type = it8655;
2841 sio_data->type = it8665;
2844 sio_data->type = it8686;
2846 case 0xffff: /* No device at all */
2849 pr_debug("Unsupported chip (DEVID=0x%x)\n", chip_type);
2853 superio_select(sioaddr, PME);
2854 if (!(superio_inb(sioaddr, IT87_ACT_REG) & 0x01)) {
2855 pr_info("Device not activated, skipping\n");
2859 *address = superio_inw(sioaddr, IT87_BASE_REG) & ~(IT87_EXTENT - 1);
2860 if (*address == 0) {
2861 pr_info("Base address not set, skipping\n");
2866 sio_data->revision = superio_inb(sioaddr, DEVREV) & 0x0f;
2867 pr_info("Found IT%04x%s chip at 0x%x, revision %d\n", chip_type,
2868 it87_devices[sio_data->type].suffix,
2869 *address, sio_data->revision);
2871 config = &it87_devices[sio_data->type];
2873 /* in7 (VSB or VCCH5V) is always internal on some chips */
2874 if (has_in7_internal(config))
2875 sio_data->internal |= BIT(1);
2877 /* in8 (Vbat) is always internal */
2878 sio_data->internal |= BIT(2);
2880 /* in9 (AVCC3), always internal if supported */
2881 if (has_avcc3(config))
2882 sio_data->internal |= BIT(3); /* in9 is AVCC */
2884 sio_data->skip_in |= BIT(9);
2886 if (!has_four_pwm(config))
2887 sio_data->skip_pwm |= BIT(3) | BIT(4) | BIT(5);
2888 else if (!has_five_pwm(config))
2889 sio_data->skip_pwm |= BIT(4) | BIT(5);
2890 else if (!has_six_pwm(config))
2891 sio_data->skip_pwm |= BIT(5);
2893 if (!has_vid(config))
2894 sio_data->skip_vid = 1;
2896 /* Read GPIO config and VID value from LDN 7 (GPIO) */
2897 if (sio_data->type == it87) {
2898 /* The IT8705F has a different LD number for GPIO */
2899 superio_select(sioaddr, 5);
2900 sio_data->beep_pin = superio_inb(sioaddr,
2901 IT87_SIO_BEEP_PIN_REG) & 0x3f;
2902 } else if (sio_data->type == it8783) {
2903 int reg25, reg27, reg2a, reg2c, regef;
2905 superio_select(sioaddr, GPIO);
2907 reg25 = superio_inb(sioaddr, IT87_SIO_GPIO1_REG);
2908 reg27 = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
2909 reg2a = superio_inb(sioaddr, IT87_SIO_PINX1_REG);
2910 reg2c = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
2911 regef = superio_inb(sioaddr, IT87_SIO_SPI_REG);
2913 /* Check if fan3 is there or not */
2914 if ((reg27 & BIT(0)) || !(reg2c & BIT(2)))
2915 sio_data->skip_fan |= BIT(2);
2916 if ((reg25 & BIT(4)) ||
2917 (!(reg2a & BIT(1)) && (regef & BIT(0))))
2918 sio_data->skip_pwm |= BIT(2);
2920 /* Check if fan2 is there or not */
2922 sio_data->skip_fan |= BIT(1);
2924 sio_data->skip_pwm |= BIT(1);
2927 if ((reg27 & BIT(0)) || (reg2c & BIT(2)))
2928 sio_data->skip_in |= BIT(5); /* No VIN5 */
2932 sio_data->skip_in |= BIT(6); /* No VIN6 */
2936 * Does not depend on bit 2 of Reg2C, contrary to datasheet.
2938 if (reg27 & BIT(2)) {
2940 * The data sheet is a bit unclear regarding the
2941 * internal voltage divider for VCCH5V. It says
2942 * "This bit enables and switches VIN7 (pin 91) to the
2943 * internal voltage divider for VCCH5V".
2944 * This is different to other chips, where the internal
2945 * voltage divider would connect VIN7 to an internal
2946 * voltage source. Maybe that is the case here as well.
2948 * Since we don't know for sure, re-route it if that is
2949 * not the case, and ask the user to report if the
2950 * resulting voltage is sane.
2952 if (!(reg2c & BIT(1))) {
2954 superio_outb(sioaddr, IT87_SIO_PINX2_REG,
2956 pr_notice("Routing internal VCCH5V to in7.\n");
2958 pr_notice("in7 routed to internal voltage divider, with external pin disabled.\n");
2959 pr_notice("Please report if it displays a reasonable voltage.\n");
2963 sio_data->internal |= BIT(0);
2965 sio_data->internal |= BIT(1);
2967 sio_data->beep_pin = superio_inb(sioaddr,
2968 IT87_SIO_BEEP_PIN_REG) & 0x3f;
2969 } else if (sio_data->type == it8603 || sio_data->type == it8607) {
2972 superio_select(sioaddr, GPIO);
2974 reg27 = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
2976 /* Check if fan3 is there or not */
2978 sio_data->skip_pwm |= BIT(2);
2980 sio_data->skip_fan |= BIT(2);
2982 /* Check if fan2 is there or not */
2983 reg29 = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
2985 sio_data->skip_pwm |= BIT(1);
2987 sio_data->skip_fan |= BIT(1);
2989 if (sio_data->type == it8603) {
2990 sio_data->skip_in |= BIT(5); /* No VIN5 */
2991 sio_data->skip_in |= BIT(6); /* No VIN6 */
2994 sio_data->beep_pin = superio_inb(sioaddr,
2995 IT87_SIO_BEEP_PIN_REG) & 0x3f;
2996 } else if (sio_data->type == it8613) {
2997 int reg27, reg29, reg2a;
2999 superio_select(sioaddr, GPIO);
3001 /* Check for pwm3, fan3, pwm5, fan5 */
3002 reg27 = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3004 sio_data->skip_fan |= BIT(4);
3006 sio_data->skip_pwm |= BIT(4);
3008 sio_data->skip_pwm |= BIT(2);
3010 sio_data->skip_fan |= BIT(2);
3012 /* Check for pwm2, fan2 */
3013 reg29 = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3015 sio_data->skip_pwm |= BIT(1);
3017 sio_data->skip_fan |= BIT(1);
3019 /* Check for pwm4, fan4 */
3020 reg2a = superio_inb(sioaddr, IT87_SIO_PINX1_REG);
3021 if (!(reg2a & BIT(0)) || (reg29 & BIT(7))) {
3022 sio_data->skip_fan |= BIT(3);
3023 sio_data->skip_pwm |= BIT(3);
3026 sio_data->skip_pwm |= BIT(0); /* No pwm1 */
3027 sio_data->skip_fan |= BIT(0); /* No fan1 */
3028 sio_data->skip_in |= BIT(3); /* No VIN3 */
3029 sio_data->skip_in |= BIT(6); /* No VIN6 */
3031 sio_data->beep_pin = superio_inb(sioaddr,
3032 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3033 } else if (sio_data->type == it8620 || sio_data->type == it8628 ||
3034 sio_data->type == it8686) {
3037 superio_select(sioaddr, GPIO);
3039 /* Check for pwm5 */
3040 reg = superio_inb(sioaddr, IT87_SIO_GPIO1_REG);
3042 sio_data->skip_pwm |= BIT(4);
3044 /* Check for fan4, fan5 */
3045 reg = superio_inb(sioaddr, IT87_SIO_GPIO2_REG);
3046 if (!(reg & BIT(5)))
3047 sio_data->skip_fan |= BIT(3);
3048 if (!(reg & BIT(4)))
3049 sio_data->skip_fan |= BIT(4);
3051 /* Check for pwm3, fan3 */
3052 reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3054 sio_data->skip_pwm |= BIT(2);
3056 sio_data->skip_fan |= BIT(2);
3058 /* Check for pwm4 */
3059 reg = superio_inb(sioaddr, IT87_SIO_GPIO4_REG);
3061 sio_data->skip_pwm |= BIT(3);
3063 /* Check for pwm2, fan2 */
3064 reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3066 sio_data->skip_pwm |= BIT(1);
3068 sio_data->skip_fan |= BIT(1);
3069 /* Check for pwm6, fan6 */
3070 if (!(reg & BIT(7))) {
3071 sio_data->skip_pwm |= BIT(5);
3072 sio_data->skip_fan |= BIT(5);
3075 /* Check if AVCC is on VIN3 */
3076 reg = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
3078 /* For it8686, the bit just enables AVCC3 */
3079 if (sio_data->type != it8686)
3080 sio_data->internal |= BIT(0);
3082 sio_data->internal &= ~BIT(3);
3083 sio_data->skip_in |= BIT(9);
3086 sio_data->beep_pin = superio_inb(sioaddr,
3087 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3088 } else if (sio_data->type == it8622) {
3091 superio_select(sioaddr, GPIO);
3093 /* Check for pwm4, fan4 */
3094 reg = superio_inb(sioaddr, IT87_SIO_GPIO1_REG);
3096 sio_data->skip_fan |= BIT(3);
3098 sio_data->skip_pwm |= BIT(3);
3100 /* Check for pwm3, fan3, pwm5, fan5 */
3101 reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3103 sio_data->skip_pwm |= BIT(2);
3105 sio_data->skip_fan |= BIT(2);
3107 sio_data->skip_pwm |= BIT(4);
3109 sio_data->skip_fan |= BIT(4);
3111 /* Check for pwm2, fan2 */
3112 reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3114 sio_data->skip_pwm |= BIT(1);
3116 sio_data->skip_fan |= BIT(1);
3118 /* Check for AVCC */
3119 reg = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
3120 if (!(reg & BIT(0)))
3121 sio_data->skip_in |= BIT(9);
3123 sio_data->beep_pin = superio_inb(sioaddr,
3124 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3125 } else if (sio_data->type == it8732) {
3128 superio_select(sioaddr, GPIO);
3130 /* Check for pwm2, fan2 */
3131 reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3133 sio_data->skip_pwm |= BIT(1);
3135 sio_data->skip_fan |= BIT(1);
3137 /* Check for pwm3, fan3, fan4 */
3138 reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3140 sio_data->skip_pwm |= BIT(2);
3142 sio_data->skip_fan |= BIT(2);
3144 sio_data->skip_fan |= BIT(3);
3146 /* Check if AVCC is on VIN3 */
3147 reg = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
3149 sio_data->internal |= BIT(0);
3151 sio_data->beep_pin = superio_inb(sioaddr,
3152 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3153 } else if (sio_data->type == it8655) {
3156 superio_select(sioaddr, GPIO);
3158 /* Check for pwm2 */
3159 reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3161 sio_data->skip_pwm |= BIT(1);
3163 /* Check for fan2 */
3164 reg = superio_inb(sioaddr, IT87_SIO_PINX4_REG);
3166 sio_data->skip_fan |= BIT(1);
3168 /* Check for pwm3, fan3 */
3169 reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3171 sio_data->skip_pwm |= BIT(2);
3173 sio_data->skip_fan |= BIT(2);
3175 sio_data->beep_pin = superio_inb(sioaddr,
3176 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3177 } else if (sio_data->type == it8665) {
3180 superio_select(sioaddr, GPIO);
3182 /* Check for pwm2 */
3183 reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3185 sio_data->skip_pwm |= BIT(1);
3187 /* Check for fan2 */
3188 reg = superio_inb(sioaddr, IT87_SIO_PINX4_REG);
3190 sio_data->skip_fan |= BIT(1);
3192 /* Check for pwm3, fan3 */
3193 reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3195 sio_data->skip_pwm |= BIT(2);
3197 sio_data->skip_fan |= BIT(2);
3199 /* Check for pwm5, fan5 */
3200 reg = superio_inb(sioaddr, IT87_SIO_GPIO2_REG);
3202 sio_data->skip_pwm |= BIT(4);
3203 if (!(reg & BIT(4)))
3204 sio_data->skip_fan |= BIT(4);
3206 /* Check for pwm4, fan4, pwm6, fan6 */
3207 reg = superio_inb(sioaddr, IT87_SIO_GPIO9_REG);
3209 sio_data->skip_pwm |= BIT(3);
3211 sio_data->skip_fan |= BIT(3);
3213 sio_data->skip_pwm |= BIT(5);
3215 sio_data->skip_fan |= BIT(5);
3217 sio_data->beep_pin = superio_inb(sioaddr,
3218 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3223 superio_select(sioaddr, GPIO);
3225 /* Check for fan4, fan5 */
3226 if (has_five_fans(config)) {
3227 reg = superio_inb(sioaddr, IT87_SIO_GPIO2_REG);
3228 switch (sio_data->type) {
3231 sio_data->skip_fan |= BIT(3);
3233 sio_data->skip_fan |= BIT(4);
3238 if (!(reg & BIT(5)))
3239 sio_data->skip_fan |= BIT(3);
3240 if (!(reg & BIT(4)))
3241 sio_data->skip_fan |= BIT(4);
3248 reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3249 if (!sio_data->skip_vid) {
3250 /* We need at least 4 VID pins */
3252 pr_info("VID is disabled (pins used for GPIO)\n");
3253 sio_data->skip_vid = 1;
3257 /* Check if fan3 is there or not */
3259 sio_data->skip_pwm |= BIT(2);
3261 sio_data->skip_fan |= BIT(2);
3263 /* Check if fan2 is there or not */
3264 reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3266 sio_data->skip_pwm |= BIT(1);
3268 sio_data->skip_fan |= BIT(1);
3270 if ((sio_data->type == it8718 || sio_data->type == it8720) &&
3271 !(sio_data->skip_vid))
3272 sio_data->vid_value = superio_inb(sioaddr,
3275 reg = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
3277 uart6 = sio_data->type == it8782 && (reg & BIT(2));
3280 * The IT8720F has no VIN7 pin, so VCCH should always be
3281 * routed internally to VIN7 with an internal divider.
3282 * Curiously, there still is a configuration bit to control
3283 * this, which means it can be set incorrectly. And even
3284 * more curiously, many boards out there are improperly
3285 * configured, even though the IT8720F datasheet claims
3286 * that the internal routing of VCCH to VIN7 is the default
3287 * setting. So we force the internal routing in this case.
3289 * On IT8782F, VIN7 is multiplexed with one of the UART6 pins.
3290 * If UART6 is enabled, re-route VIN7 to the internal divider
3291 * if that is not already the case.
3293 if ((sio_data->type == it8720 || uart6) && !(reg & BIT(1))) {
3295 superio_outb(sioaddr, IT87_SIO_PINX2_REG, reg);
3296 pr_notice("Routing internal VCCH to in7\n");
3299 sio_data->internal |= BIT(0);
3301 sio_data->internal |= BIT(1);
3304 * On IT8782F, UART6 pins overlap with VIN5, VIN6, and VIN7.
3305 * While VIN7 can be routed to the internal voltage divider,
3306 * VIN5 and VIN6 are not available if UART6 is enabled.
3308 * Also, temp3 is not available if UART6 is enabled and TEMPIN3
3309 * is the temperature source. Since we can not read the
3310 * temperature source here, skip_temp is preliminary.
3313 sio_data->skip_in |= BIT(5) | BIT(6);
3314 sio_data->skip_temp |= BIT(2);
3317 sio_data->beep_pin = superio_inb(sioaddr,
3318 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3320 if (sio_data->beep_pin)
3321 pr_info("Beeping is supported\n");
3324 superio_exit(sioaddr);
3328 /* Called when we have found a new IT87. */
3329 static void it87_init_device(struct platform_device *pdev)
3331 struct it87_sio_data *sio_data = dev_get_platdata(&pdev->dev);
3332 struct it87_data *data = platform_get_drvdata(pdev);
3336 /* Initialize chip specific register pointers */
3337 switch (data->type) {
3339 data->REG_FAN = IT87_REG_FAN;
3340 data->REG_FANX = IT87_REG_FANX;
3341 data->REG_FAN_MIN = IT87_REG_FAN_MIN;
3342 data->REG_FANX_MIN = IT87_REG_FANX_MIN;
3343 data->REG_PWM = IT87_REG_PWM;
3344 data->REG_TEMP_OFFSET = IT87_REG_TEMP_OFFSET_8686;
3345 data->REG_TEMP_LOW = IT87_REG_TEMP_LOW_8686;
3346 data->REG_TEMP_HIGH = IT87_REG_TEMP_HIGH_8686;
3350 data->REG_FAN = IT87_REG_FAN_8665;
3351 data->REG_FANX = IT87_REG_FANX_8665;
3352 data->REG_FAN_MIN = IT87_REG_FAN_MIN_8665;
3353 data->REG_FANX_MIN = IT87_REG_FANX_MIN_8665;
3354 data->REG_PWM = IT87_REG_PWM_8665;
3355 data->REG_TEMP_OFFSET = IT87_REG_TEMP_OFFSET;
3356 data->REG_TEMP_LOW = IT87_REG_TEMP_LOW;
3357 data->REG_TEMP_HIGH = IT87_REG_TEMP_HIGH;
3360 data->REG_FAN = IT87_REG_FAN;
3361 data->REG_FANX = IT87_REG_FANX;
3362 data->REG_FAN_MIN = IT87_REG_FAN_MIN;
3363 data->REG_FANX_MIN = IT87_REG_FANX_MIN;
3364 data->REG_PWM = IT87_REG_PWM_8665;
3365 data->REG_TEMP_OFFSET = IT87_REG_TEMP_OFFSET;
3366 data->REG_TEMP_LOW = IT87_REG_TEMP_LOW;
3367 data->REG_TEMP_HIGH = IT87_REG_TEMP_HIGH;
3370 data->REG_FAN = IT87_REG_FAN;
3371 data->REG_FANX = IT87_REG_FANX;
3372 data->REG_FAN_MIN = IT87_REG_FAN_MIN;
3373 data->REG_FANX_MIN = IT87_REG_FANX_MIN;
3374 data->REG_PWM = IT87_REG_PWM_8665;
3375 data->REG_TEMP_OFFSET = IT87_REG_TEMP_OFFSET;
3376 data->REG_TEMP_LOW = IT87_REG_TEMP_LOW;
3377 data->REG_TEMP_HIGH = IT87_REG_TEMP_HIGH;
3380 data->REG_FAN = IT87_REG_FAN;
3381 data->REG_FANX = IT87_REG_FANX;
3382 data->REG_FAN_MIN = IT87_REG_FAN_MIN;
3383 data->REG_FANX_MIN = IT87_REG_FANX_MIN;
3384 data->REG_PWM = IT87_REG_PWM;
3385 data->REG_TEMP_OFFSET = IT87_REG_TEMP_OFFSET;
3386 data->REG_TEMP_LOW = IT87_REG_TEMP_LOW;
3387 data->REG_TEMP_HIGH = IT87_REG_TEMP_HIGH;
3392 * For each PWM channel:
3393 * - If it is in automatic mode, setting to manual mode should set
3394 * the fan to full speed by default.
3395 * - If it is in manual mode, we need a mapping to temperature
3396 * channels to use when later setting to automatic mode later.
3397 * Use a 1:1 mapping by default (we are clueless.)
3398 * In both cases, the value can (and should) be changed by the user
3399 * prior to switching to a different mode.
3400 * Note that this is no longer needed for the IT8721F and later, as
3401 * these have separate registers for the temperature mapping and the
3402 * manual duty cycle.
3404 for (i = 0; i < NUM_AUTO_PWM; i++) {
3405 data->pwm_temp_map[i] = i;
3406 data->pwm_duty[i] = 0x7f; /* Full speed */
3407 data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */
3411 * Some chips seem to have default value 0xff for all limit
3412 * registers. For low voltage limits it makes no sense and triggers
3413 * alarms, so change to 0 instead. For high temperature limits, it
3414 * means -1 degree C, which surprisingly doesn't trigger an alarm,
3415 * but is still confusing, so change to 127 degrees C.
3417 for (i = 0; i < NUM_VIN_LIMIT; i++) {
3418 tmp = it87_read_value(data, IT87_REG_VIN_MIN(i));
3420 it87_write_value(data, IT87_REG_VIN_MIN(i), 0);
3422 for (i = 0; i < data->num_temp_limit; i++) {
3423 tmp = it87_read_value(data, data->REG_TEMP_HIGH[i]);
3425 it87_write_value(data, data->REG_TEMP_HIGH[i], 127);
3429 * Temperature channels are not forcibly enabled, as they can be
3430 * set to two different sensor types and we can't guess which one
3431 * is correct for a given system. These channels can be enabled at
3432 * run-time through the temp{1-3}_type sysfs accessors if needed.
3435 /* Check if voltage monitors are reset manually or by some reason */
3436 tmp = it87_read_value(data, IT87_REG_VIN_ENABLE);
3437 if ((tmp & 0xff) == 0) {
3438 /* Enable all voltage monitors */
3439 it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff);
3442 /* Check if tachometers are reset manually or by some reason */
3443 mask = 0x70 & ~(sio_data->skip_fan << 4);
3444 data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL);
3445 if ((data->fan_main_ctrl & mask) == 0) {
3446 /* Enable all fan tachometers */
3447 data->fan_main_ctrl |= mask;
3448 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
3449 data->fan_main_ctrl);
3451 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
3453 tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
3455 /* Set tachometers to 16-bit mode if needed */
3456 if (has_fan16_config(data)) {
3457 if (~tmp & 0x07 & data->has_fan) {
3459 "Setting fan1-3 to 16-bit mode\n");
3460 it87_write_value(data, IT87_REG_FAN_16BIT,
3465 /* Check for additional fans */
3466 if (has_four_fans(data) && (tmp & BIT(4)))
3467 data->has_fan |= BIT(3); /* fan4 enabled */
3468 if (has_five_fans(data) && (tmp & BIT(5)))
3469 data->has_fan |= BIT(4); /* fan5 enabled */
3470 if (has_six_fans(data)) {
3471 switch (data->type) {
3476 data->has_fan |= BIT(5); /* fan6 enabled */
3479 tmp = it87_read_value(data, IT87_REG_FAN_DIV);
3481 data->has_fan |= BIT(5); /* fan6 enabled */
3488 /* Fan input pins may be used for alternative functions */
3489 data->has_fan &= ~sio_data->skip_fan;
3491 /* Check if pwm6 is enabled */
3492 if (has_six_pwm(data)) {
3493 switch (data->type) {
3496 tmp = it87_read_value(data, IT87_REG_FAN_DIV);
3497 if (!(tmp & BIT(3)))
3498 sio_data->skip_pwm |= BIT(5);
3505 /* Start monitoring */
3506 it87_write_value(data, IT87_REG_CONFIG,
3507 (it87_read_value(data, IT87_REG_CONFIG) & 0x3e)
3508 | (update_vbat ? 0x41 : 0x01));
3511 /* Return 1 if and only if the PWM interface is safe to use */
3512 static int it87_check_pwm(struct device *dev)
3514 struct it87_data *data = dev_get_drvdata(dev);
3516 * Some BIOSes fail to correctly configure the IT87 fans. All fans off
3517 * and polarity set to active low is sign that this is the case so we
3518 * disable pwm control to protect the user.
3520 int tmp = it87_read_value(data, IT87_REG_FAN_CTL);
3522 if ((tmp & 0x87) == 0) {
3523 if (fix_pwm_polarity) {
3525 * The user asks us to attempt a chip reconfiguration.
3526 * This means switching to active high polarity and
3527 * inverting all fan speed values.
3532 for (i = 0; i < ARRAY_SIZE(pwm); i++)
3533 pwm[i] = it87_read_value(data,
3537 * If any fan is in automatic pwm mode, the polarity
3538 * might be correct, as suspicious as it seems, so we
3539 * better don't change anything (but still disable the
3542 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
3544 "Reconfiguring PWM to active high polarity\n");
3545 it87_write_value(data, IT87_REG_FAN_CTL,
3547 for (i = 0; i < 3; i++)
3548 it87_write_value(data,
3555 "PWM configuration is too broken to be fixed\n");
3559 "Detected broken BIOS defaults, disabling PWM interface\n");
3561 } else if (fix_pwm_polarity) {
3563 "PWM configuration looks sane, won't touch\n");
3569 static int it87_probe(struct platform_device *pdev)
3571 struct it87_data *data;
3572 struct resource *res;
3573 struct device *dev = &pdev->dev;
3574 struct it87_sio_data *sio_data = dev_get_platdata(dev);
3575 int enable_pwm_interface;
3576 struct device *hwmon_dev;
3578 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
3579 if (!devm_request_region(&pdev->dev, res->start, IT87_EC_EXTENT,
3581 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
3582 (unsigned long)res->start,
3583 (unsigned long)(res->start + IT87_EC_EXTENT - 1));
3587 data = devm_kzalloc(&pdev->dev, sizeof(struct it87_data), GFP_KERNEL);
3591 data->addr = res->start;
3592 data->type = sio_data->type;
3593 data->features = it87_devices[sio_data->type].features;
3594 data->num_temp_limit = it87_devices[sio_data->type].num_temp_limit;
3595 data->peci_mask = it87_devices[sio_data->type].peci_mask;
3596 data->old_peci_mask = it87_devices[sio_data->type].old_peci_mask;
3600 * IT8705F Datasheet 0.4.1, 3h == Version G.
3601 * IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J.
3602 * These are the first revisions with 16-bit tachometer support.
3604 switch (data->type) {
3606 if (sio_data->revision >= 0x03) {
3607 data->features &= ~FEAT_OLD_AUTOPWM;
3608 data->features |= FEAT_FAN16_CONFIG | FEAT_16BIT_FANS;
3612 if (sio_data->revision >= 0x08) {
3613 data->features &= ~FEAT_OLD_AUTOPWM;
3614 data->features |= FEAT_FAN16_CONFIG | FEAT_16BIT_FANS |
3622 /* Now, we do the remaining detection. */
3623 if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80) ||
3624 it87_read_value(data, IT87_REG_CHIPID) != 0x90)
3627 platform_set_drvdata(pdev, data);
3629 mutex_init(&data->update_lock);
3631 /* Check PWM configuration */
3632 enable_pwm_interface = it87_check_pwm(dev);
3634 /* Starting with IT8721F, we handle scaling of internal voltages */
3635 if (has_scaling(data)) {
3636 if (sio_data->internal & BIT(0))
3637 data->in_scaled |= BIT(3); /* in3 is AVCC */
3638 if (sio_data->internal & BIT(1))
3639 data->in_scaled |= BIT(7); /* in7 is VSB */
3640 if (sio_data->internal & BIT(2))
3641 data->in_scaled |= BIT(8); /* in8 is Vbat */
3642 if (sio_data->internal & BIT(3))
3643 data->in_scaled |= BIT(9); /* in9 is AVCC */
3644 } else if (sio_data->type == it8781 || sio_data->type == it8782 ||
3645 sio_data->type == it8783) {
3646 if (sio_data->internal & BIT(0))
3647 data->in_scaled |= BIT(3); /* in3 is VCC5V */
3648 if (sio_data->internal & BIT(1))
3649 data->in_scaled |= BIT(7); /* in7 is VCCH5V */
3652 data->has_temp = 0x07;
3653 if (sio_data->skip_temp & BIT(2)) {
3654 if (sio_data->type == it8782 &&
3655 !(it87_read_value(data, IT87_REG_TEMP_EXTRA) & 0x80))
3656 data->has_temp &= ~BIT(2);
3659 data->in_internal = sio_data->internal;
3660 data->has_in = 0x3ff & ~sio_data->skip_in;
3662 if (has_six_temp(data)) {
3663 u8 reg = it87_read_value(data, IT87_REG_TEMP456_ENABLE);
3665 /* Check for additional temperature sensors */
3666 if ((reg & 0x03) >= 0x02)
3667 data->has_temp |= BIT(3);
3668 if (((reg >> 2) & 0x03) >= 0x02)
3669 data->has_temp |= BIT(4);
3670 if (((reg >> 4) & 0x03) >= 0x02)
3671 data->has_temp |= BIT(5);
3673 /* Check for additional voltage sensors */
3674 if ((reg & 0x03) == 0x01)
3675 data->has_in |= BIT(10);
3676 if (((reg >> 2) & 0x03) == 0x01)
3677 data->has_in |= BIT(11);
3678 if (((reg >> 4) & 0x03) == 0x01)
3679 data->has_in |= BIT(12);
3682 data->has_beep = !!sio_data->beep_pin;
3684 /* Initialize the IT87 chip */
3685 it87_init_device(pdev);
3687 if (!sio_data->skip_vid) {
3688 data->has_vid = true;
3689 data->vrm = vid_which_vrm();
3690 /* VID reading from Super-I/O config space if available */
3691 data->vid = sio_data->vid_value;
3694 /* Prepare for sysfs hooks */
3695 data->groups[0] = &it87_group;
3696 data->groups[1] = &it87_group_in;
3697 data->groups[2] = &it87_group_temp;
3698 data->groups[3] = &it87_group_fan;
3700 if (enable_pwm_interface) {
3701 data->has_pwm = BIT(ARRAY_SIZE(IT87_REG_PWM)) - 1;
3702 data->has_pwm &= ~sio_data->skip_pwm;
3704 data->groups[4] = &it87_group_pwm;
3705 if (has_old_autopwm(data) || has_newer_autopwm(data))
3706 data->groups[5] = &it87_group_auto_pwm;
3709 hwmon_dev = devm_hwmon_device_register_with_groups(dev,
3710 it87_devices[sio_data->type].name,
3711 data, data->groups);
3712 return PTR_ERR_OR_ZERO(hwmon_dev);
3715 static struct platform_driver it87_driver = {
3719 .probe = it87_probe,
3722 static int __init it87_device_add(int index, unsigned short address,
3723 const struct it87_sio_data *sio_data)
3725 struct platform_device *pdev;
3726 struct resource res = {
3727 .start = address + IT87_EC_OFFSET,
3728 .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1,
3730 .flags = IORESOURCE_IO,
3734 err = acpi_check_resource_conflict(&res);
3738 pdev = platform_device_alloc(DRVNAME, address);
3742 err = platform_device_add_resources(pdev, &res, 1);
3744 pr_err("Device resource addition failed (%d)\n", err);
3745 goto exit_device_put;
3748 err = platform_device_add_data(pdev, sio_data,
3749 sizeof(struct it87_sio_data));
3751 pr_err("Platform data allocation failed\n");
3752 goto exit_device_put;
3755 err = platform_device_add(pdev);
3757 pr_err("Device addition failed (%d)\n", err);
3758 goto exit_device_put;
3761 it87_pdev[index] = pdev;
3765 platform_device_put(pdev);
3769 struct it87_dmi_data {
3770 bool sio4e_broken; /* SIO accesses @ 0x4e are broken */
3771 char *sio_mutex; /* SIO ACPI mutex */
3772 u8 skip_pwm; /* pwm channels to skip for this board */
3776 * On Gigabyte AB350 and AX370 boards, accesses to the Super-IO chip
3777 * at address 0x4e/0x4f can result in a system hang.
3778 * Accesses to address 0x2e/0x2f need to be mutex protected.
3780 static struct it87_dmi_data gigabyte_ab350_gaming = {
3781 .sio4e_broken = true,
3782 .sio_mutex = "\\_SB.PCI0.SBRG.SIO1.MUT0",
3786 * On the Shuttle SN68PT, FAN_CTL2 is apparently not
3787 * connected to a fan, but to something else. One user
3788 * has reported instant system power-off when changing
3789 * the PWM2 duty cycle, so we disable it.
3790 * I use the board name string as the trigger in case
3791 * the same board is ever used in other systems.
3793 static struct it87_dmi_data nvidia_fn68pt = {
3797 static const struct dmi_system_id it87_dmi_table[] __initconst = {
3800 DMI_MATCH(DMI_SYS_VENDOR, "Gigabyte Technology Co., Ltd."),
3801 DMI_MATCH(DMI_BOARD_NAME, "AB350-Gaming-CF"),
3803 .driver_data = &gigabyte_ab350_gaming,
3807 DMI_MATCH(DMI_SYS_VENDOR, "Gigabyte Technology Co., Ltd."),
3808 DMI_MATCH(DMI_BOARD_NAME, "AB350-Gaming 3-CF"),
3810 .driver_data = &gigabyte_ab350_gaming,
3814 DMI_MATCH(DMI_SYS_VENDOR, "Gigabyte Technology Co., Ltd."),
3815 DMI_MATCH(DMI_BOARD_NAME, "AX370-Gaming K7"),
3817 .driver_data = &gigabyte_ab350_gaming,
3821 DMI_MATCH(DMI_BOARD_VENDOR, "nVIDIA"),
3822 DMI_MATCH(DMI_BOARD_NAME, "FN68PT"),
3824 .driver_data = &nvidia_fn68pt,
3829 static int __init sm_it87_init(void)
3831 const struct dmi_system_id *dmi = dmi_first_match(it87_dmi_table);
3832 struct it87_dmi_data *dmi_data = NULL;
3833 int sioaddr[2] = { REG_2E, REG_4E };
3834 struct it87_sio_data sio_data;
3835 unsigned short isa_address;
3840 dmi_data = dmi->driver_data;
3843 it87_sio4e_broken = dmi_data->sio4e_broken;
3844 #ifdef __IT87_USE_ACPI_MUTEX
3845 if (dmi_data->sio_mutex) {
3846 static acpi_status status;
3848 status = acpi_get_handle(NULL, dmi_data->sio_mutex,
3849 &it87_acpi_sio_handle);
3850 if (ACPI_SUCCESS(status)) {
3851 it87_acpi_sio_mutex = dmi_data->sio_mutex;
3852 pr_debug("Found ACPI SIO mutex %s\n",
3853 dmi_data->sio_mutex);
3855 pr_warn("ACPI SIO mutex %s not found\n",
3856 dmi_data->sio_mutex);
3859 #endif /* __IT87_USE_ACPI_MUTEX */
3862 err = platform_driver_register(&it87_driver);
3866 for (i = 0; i < ARRAY_SIZE(sioaddr); i++) {
3868 * Accessing the second Super-IO chi can result in board
3869 * hangs. Disable until we figure out what is going on.
3871 if (it87_sio4e_broken && sioaddr[i] == 0x4e)
3873 memset(&sio_data, 0, sizeof(struct it87_sio_data));
3875 err = it87_find(sioaddr[i], &isa_address, &sio_data);
3876 if (err || isa_address == 0)
3880 sio_data.skip_pwm |= dmi_data->skip_pwm;
3881 err = it87_device_add(i, isa_address, &sio_data);
3883 goto exit_dev_unregister;
3889 goto exit_unregister;
3893 exit_dev_unregister:
3894 /* NULL check handled by platform_device_unregister */
3895 platform_device_unregister(it87_pdev[0]);
3897 platform_driver_unregister(&it87_driver);
3901 static void __exit sm_it87_exit(void)
3903 /* NULL check handled by platform_device_unregister */
3904 platform_device_unregister(it87_pdev[1]);
3905 platform_device_unregister(it87_pdev[0]);
3906 platform_driver_unregister(&it87_driver);
3909 MODULE_AUTHOR("Chris Gauthron, Jean Delvare <jdelvare@suse.de>");
3910 MODULE_DESCRIPTION("IT8705F/IT871xF/IT872xF hardware monitoring driver");
3911 module_param(update_vbat, bool, 0);
3912 MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
3913 module_param(fix_pwm_polarity, bool, 0);
3914 MODULE_PARM_DESC(fix_pwm_polarity,
3915 "Force PWM polarity to active high (DANGEROUS)");
3916 MODULE_LICENSE("GPL");
3918 module_init(sm_it87_init);
3919 module_exit(sm_it87_exit);