2 * it87.c - Part of lm_sensors, Linux kernel modules for hardware
5 * The IT8705F is an LPC-based Super I/O part that contains UARTs, a
6 * parallel port, an IR port, a MIDI port, a floppy controller, etc., in
7 * addition to an Environment Controller (Enhanced Hardware Monitor and
10 * This driver supports only the Environment Controller in the IT8705F and
11 * similar parts. The other devices are supported by different drivers.
13 * Supports: IT8603E Super I/O chip w/LPC interface
14 * IT8607E Super I/O chip w/LPC interface
15 * IT8613E Super I/O chip w/LPC interface
16 * IT8620E Super I/O chip w/LPC interface
17 * IT8622E Super I/O chip w/LPC interface
18 * IT8623E Super I/O chip w/LPC interface
19 * IT8625E Super I/O chip w/LPC interface
20 * IT8628E Super I/O chip w/LPC interface
21 * IT8655E Super I/O chip w/LPC interface
22 * IT8665E Super I/O chip w/LPC interface
23 * IT8686E Super I/O chip w/LPC interface
24 * IT8705F Super I/O chip w/LPC interface
25 * IT8712F Super I/O chip w/LPC interface
26 * IT8716F Super I/O chip w/LPC interface
27 * IT8718F Super I/O chip w/LPC interface
28 * IT8720F Super I/O chip w/LPC interface
29 * IT8721F Super I/O chip w/LPC interface
30 * IT8726F Super I/O chip w/LPC interface
31 * IT8728F Super I/O chip w/LPC interface
32 * IT8732F Super I/O chip w/LPC interface
33 * IT8758E Super I/O chip w/LPC interface
34 * IT8771E Super I/O chip w/LPC interface
35 * IT8772E Super I/O chip w/LPC interface
36 * IT8781F Super I/O chip w/LPC interface
37 * IT8782F Super I/O chip w/LPC interface
38 * IT8783E/F Super I/O chip w/LPC interface
39 * IT8786E Super I/O chip w/LPC interface
40 * IT8790E Super I/O chip w/LPC interface
41 * IT8792E Super I/O chip w/LPC interface
42 * Sis950 A clone of the IT8705F
44 * Copyright (C) 2001 Chris Gauthron
45 * Copyright (C) 2005-2010 Jean Delvare <jdelvare@suse.de>
47 * This program is free software; you can redistribute it and/or modify
48 * it under the terms of the GNU General Public License as published by
49 * the Free Software Foundation; either version 2 of the License, or
50 * (at your option) any later version.
52 * This program is distributed in the hope that it will be useful,
53 * but WITHOUT ANY WARRANTY; without even the implied warranty of
54 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
55 * GNU General Public License for more details.
58 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
60 #include <linux/bitops.h>
61 #include <linux/module.h>
62 #include <linux/init.h>
63 #include <linux/slab.h>
64 #include <linux/jiffies.h>
65 #include <linux/platform_device.h>
66 #include <linux/hwmon.h>
67 #include <linux/hwmon-sysfs.h>
68 #include <linux/hwmon-vid.h>
69 #include <linux/err.h>
70 #include <linux/mutex.h>
71 #include <linux/sysfs.h>
72 #include <linux/string.h>
73 #include <linux/dmi.h>
74 #include <linux/acpi.h>
78 #define DRVNAME "it87"
80 /* Necessary API not (yet) exported in upstream kernel */
81 /* #define __IT87_USE_ACPI_MUTEX */
83 enum chips { it87, it8712, it8716, it8718, it8720, it8721, it8728, it8732,
84 it8771, it8772, it8781, it8782, it8783, it8786, it8790,
85 it8792, it8603, it8607, it8613, it8620, it8622, it8625, it8628,
86 it8655, it8665, it8686 };
88 static unsigned short force_id;
89 module_param(force_id, ushort, 0);
90 MODULE_PARM_DESC(force_id, "Override the detected device ID");
92 static struct platform_device *it87_pdev[2];
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);
128 static inline void superio_outb(int ioreg, int reg, int val)
131 outb(val, ioreg + 1);
134 static int superio_inw(int ioreg, int reg)
136 return (superio_inb(ioreg, reg) << 8) | superio_inb(ioreg, reg + 1);
139 static inline void superio_select(int ioreg, int ldn)
142 outb(ldn, ioreg + 1);
145 static inline int superio_enter(int ioreg)
147 #ifdef __IT87_USE_ACPI_MUTEX
148 if (it87_acpi_sio_mutex) {
151 status = acpi_acquire_mutex(NULL, it87_acpi_sio_mutex, 0x10);
152 if (ACPI_FAILURE(status)) {
153 pr_err("Failed to acquire ACPI mutex\n");
159 * Try to reserve ioreg and ioreg + 1 for exclusive access.
161 if (!request_muxed_region(ioreg, 2, DRVNAME))
164 __superio_enter(ioreg);
168 #ifdef __IT87_USE_ACPI_MUTEX
169 if (it87_acpi_sio_mutex)
170 acpi_release_mutex(it87_acpi_sio_handle, NULL);
175 static inline void superio_exit(int ioreg, bool doexit)
179 outb(0x02, ioreg + 1);
181 release_region(ioreg, 2);
182 #ifdef __IT87_USE_ACPI_MUTEX
183 if (it87_acpi_sio_mutex)
184 acpi_release_mutex(it87_acpi_sio_handle, NULL);
188 /* Logical device 4 registers */
189 #define IT8712F_DEVID 0x8712
190 #define IT8705F_DEVID 0x8705
191 #define IT8716F_DEVID 0x8716
192 #define IT8718F_DEVID 0x8718
193 #define IT8720F_DEVID 0x8720
194 #define IT8721F_DEVID 0x8721
195 #define IT8726F_DEVID 0x8726
196 #define IT8728F_DEVID 0x8728
197 #define IT8732F_DEVID 0x8732
198 #define IT8792E_DEVID 0x8733
199 #define IT8771E_DEVID 0x8771
200 #define IT8772E_DEVID 0x8772
201 #define IT8781F_DEVID 0x8781
202 #define IT8782F_DEVID 0x8782
203 #define IT8783E_DEVID 0x8783
204 #define IT8786E_DEVID 0x8786
205 #define IT8790E_DEVID 0x8790
206 #define IT8603E_DEVID 0x8603
207 #define IT8607E_DEVID 0x8607
208 #define IT8613E_DEVID 0x8613
209 #define IT8620E_DEVID 0x8620
210 #define IT8622E_DEVID 0x8622
211 #define IT8623E_DEVID 0x8623
212 #define IT8625E_DEVID 0x8625
213 #define IT8628E_DEVID 0x8628
214 #define IT8655E_DEVID 0x8655
215 #define IT8665E_DEVID 0x8665
216 #define IT8686E_DEVID 0x8686
217 #define IT87_ACT_REG 0x30
218 #define IT87_BASE_REG 0x60
220 /* Logical device 7 registers (IT8712F and later) */
221 #define IT87_SIO_GPIO1_REG 0x25
222 #define IT87_SIO_GPIO2_REG 0x26
223 #define IT87_SIO_GPIO3_REG 0x27
224 #define IT87_SIO_GPIO4_REG 0x28
225 #define IT87_SIO_GPIO5_REG 0x29
226 #define IT87_SIO_GPIO9_REG 0xd3
227 #define IT87_SIO_PINX1_REG 0x2a /* Pin selection */
228 #define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
229 #define IT87_SIO_PINX4_REG 0x2d /* Pin selection */
230 #define IT87_SIO_SPI_REG 0xef /* SPI function pin select */
231 #define IT87_SIO_VID_REG 0xfc /* VID value */
232 #define IT87_SIO_BEEP_PIN_REG 0xf6 /* Beep pin mapping */
234 /* Update battery voltage after every reading if true */
235 static bool update_vbat;
237 /* Not all BIOSes properly configure the PWM registers */
238 static bool fix_pwm_polarity;
240 /* Many IT87 constants specified below */
242 /* Length of ISA address segment */
243 #define IT87_EXTENT 8
245 /* Length of ISA address segment for Environmental Controller */
246 #define IT87_EC_EXTENT 2
248 /* Offset of EC registers from ISA base address */
249 #define IT87_EC_OFFSET 5
251 /* Where are the ISA address/data registers relative to the EC base address */
252 #define IT87_ADDR_REG_OFFSET 0
253 #define IT87_DATA_REG_OFFSET 1
255 /*----- The IT87 registers -----*/
257 #define IT87_REG_CONFIG 0x00
259 #define IT87_REG_ALARM1 0x01
260 #define IT87_REG_ALARM2 0x02
261 #define IT87_REG_ALARM3 0x03
263 #define IT87_REG_BANK 0x06
266 * The IT8718F and IT8720F have the VID value in a different register, in
267 * Super-I/O configuration space.
269 #define IT87_REG_VID 0x0a
271 * The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b
272 * for fan divisors. Later IT8712F revisions must use 16-bit tachometer
275 #define IT87_REG_FAN_DIV 0x0b
276 #define IT87_REG_FAN_16BIT 0x0c
280 * - up to 13 voltage (0 to 7, battery, avcc, 10 to 12)
281 * - up to 6 temp (1 to 6)
282 * - up to 6 fan (1 to 6)
285 static const u8 IT87_REG_FAN[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82, 0x4c };
286 static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86, 0x4e };
287 static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83, 0x4d };
288 static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87, 0x4f };
290 static const u8 IT87_REG_FAN_8665[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82, 0x93 };
291 static const u8 IT87_REG_FAN_MIN_8665[] =
292 { 0x10, 0x11, 0x12, 0x84, 0x86, 0xb2 };
293 static const u8 IT87_REG_FANX_8665[] = { 0x18, 0x19, 0x1a, 0x81, 0x83, 0x94 };
294 static const u8 IT87_REG_FANX_MIN_8665[] =
295 { 0x1b, 0x1c, 0x1d, 0x85, 0x87, 0xb3 };
297 static const u8 IT87_REG_TEMP_OFFSET[] = { 0x56, 0x57, 0x59, 0x5a, 0x90, 0x91 };
299 static const u8 IT87_REG_TEMP_OFFSET_8686[] = { 0x56, 0x57, 0x59, 0x90, 0x91, 0x92 };
301 #define IT87_REG_FAN_MAIN_CTRL 0x13
302 #define IT87_REG_FAN_CTL 0x14
304 static const u8 IT87_REG_PWM[] = { 0x15, 0x16, 0x17, 0x7f, 0xa7, 0xaf };
305 static const u8 IT87_REG_PWM_8665[] = { 0x15, 0x16, 0x17, 0x1e, 0x1f, 0x92 };
307 static const u8 IT87_REG_PWM_DUTY[] = { 0x63, 0x6b, 0x73, 0x7b, 0xa3, 0xab };
309 static const u8 IT87_REG_VIN[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26,
310 0x27, 0x28, 0x2f, 0x2c, 0x2d, 0x2e };
312 #define IT87_REG_TEMP(nr) (0x29 + (nr))
314 #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2)
315 #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2)
317 static const u8 IT87_REG_TEMP_HIGH[] = { 0x40, 0x42, 0x44, 0x46, 0xb4, 0xb6 };
318 static const u8 IT87_REG_TEMP_LOW[] = { 0x41, 0x43, 0x45, 0x47, 0xb5, 0xb7 };
320 static const u8 IT87_REG_TEMP_HIGH_8686[] =
321 { 0x40, 0x42, 0x44, 0xb4, 0xb6, 0xb8 };
322 static const u8 IT87_REG_TEMP_LOW_8686[] =
323 { 0x41, 0x43, 0x45, 0xb5, 0xb7, 0xb9 };
325 #define IT87_REG_VIN_ENABLE 0x50
326 #define IT87_REG_TEMP_ENABLE 0x51
327 #define IT87_REG_TEMP_EXTRA 0x55
328 #define IT87_REG_BEEP_ENABLE 0x5c
330 #define IT87_REG_CHIPID 0x58
332 static const u8 IT87_REG_AUTO_BASE[] = { 0x60, 0x68, 0x70, 0x78, 0xa0, 0xa8 };
334 #define IT87_REG_AUTO_TEMP(nr, i) (IT87_REG_AUTO_BASE[nr] + (i))
335 #define IT87_REG_AUTO_PWM(nr, i) (IT87_REG_AUTO_BASE[nr] + 5 + (i))
337 #define IT87_REG_TEMP456_ENABLE 0x77
339 static const u16 IT87_REG_TEMP_SRC1[] = { 0x21d, 0x21e, 0x21f };
340 #define IT87_REG_TEMP_SRC2 0x23d
342 #define NUM_VIN ARRAY_SIZE(IT87_REG_VIN)
343 #define NUM_VIN_LIMIT 8
345 #define NUM_FAN ARRAY_SIZE(IT87_REG_FAN)
346 #define NUM_FAN_DIV 3
347 #define NUM_PWM ARRAY_SIZE(IT87_REG_PWM)
348 #define NUM_AUTO_PWM ARRAY_SIZE(IT87_REG_PWM)
350 struct it87_devices {
352 const char * const suffix;
360 #define FEAT_12MV_ADC BIT(0)
361 #define FEAT_NEWER_AUTOPWM BIT(1)
362 #define FEAT_OLD_AUTOPWM BIT(2)
363 #define FEAT_16BIT_FANS BIT(3)
364 #define FEAT_TEMP_PECI BIT(5)
365 #define FEAT_TEMP_OLD_PECI BIT(6)
366 #define FEAT_FAN16_CONFIG BIT(7) /* Need to enable 16-bit fans */
367 #define FEAT_FIVE_FANS BIT(8) /* Supports five fans */
368 #define FEAT_VID BIT(9) /* Set if chip supports VID */
369 #define FEAT_IN7_INTERNAL BIT(10) /* Set if in7 is internal */
370 #define FEAT_SIX_FANS BIT(11) /* Supports six fans */
371 #define FEAT_10_9MV_ADC BIT(12)
372 #define FEAT_AVCC3 BIT(13) /* Chip supports in9/AVCC3 */
373 #define FEAT_FIVE_PWM BIT(14) /* Chip supports 5 pwm chn */
374 #define FEAT_SIX_PWM BIT(15) /* Chip supports 6 pwm chn */
375 #define FEAT_PWM_FREQ2 BIT(16) /* Separate pwm freq 2 */
376 #define FEAT_SIX_TEMP BIT(17) /* Up to 6 temp sensors */
377 #define FEAT_VIN3_5V BIT(18) /* VIN3 connected to +5V */
378 #define FEAT_FOUR_FANS BIT(19) /* Supports four fans */
379 #define FEAT_FOUR_PWM BIT(20) /* Supports four fan controls */
380 #define FEAT_BANK_SEL BIT(21) /* Chip has multi-bank support */
381 #define FEAT_SCALING BIT(22) /* Internal voltage scaling */
382 #define FEAT_FANCTL_ONOFF BIT(23) /* chip has FAN_CTL ON/OFF */
383 #define FEAT_11MV_ADC BIT(24)
384 #define FEAT_NEW_TEMPMAP BIT(25) /* new temp input selection */
386 static const struct it87_devices it87_devices[] = {
390 .features = FEAT_OLD_AUTOPWM | FEAT_FANCTL_ONOFF,
391 /* may need to overwrite */
393 .num_temp_offset = 0,
398 .features = FEAT_OLD_AUTOPWM | FEAT_VID | FEAT_FANCTL_ONOFF,
399 /* may need to overwrite */
401 .num_temp_offset = 0,
406 .features = FEAT_16BIT_FANS | FEAT_VID
407 | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS | FEAT_PWM_FREQ2
410 .num_temp_offset = 3,
415 .features = FEAT_16BIT_FANS | FEAT_VID
416 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS
417 | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
419 .num_temp_offset = 3,
420 .old_peci_mask = 0x4,
425 .features = FEAT_16BIT_FANS | FEAT_VID
426 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS
427 | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
429 .num_temp_offset = 3,
430 .old_peci_mask = 0x4,
435 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
436 | FEAT_TEMP_OLD_PECI | FEAT_TEMP_PECI
437 | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS | FEAT_IN7_INTERNAL
438 | FEAT_PWM_FREQ2 | FEAT_SCALING | FEAT_FANCTL_ONOFF,
440 .num_temp_offset = 3,
442 .old_peci_mask = 0x02, /* Actually reports PCH */
447 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
448 | FEAT_TEMP_PECI | FEAT_FIVE_FANS
449 | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2 | FEAT_SCALING
452 .num_temp_offset = 3,
458 .features = FEAT_NEWER_AUTOPWM | FEAT_16BIT_FANS
459 | FEAT_TEMP_OLD_PECI | FEAT_TEMP_PECI
460 | FEAT_10_9MV_ADC | FEAT_IN7_INTERNAL | FEAT_FOUR_FANS
461 | FEAT_FOUR_PWM | FEAT_FANCTL_ONOFF,
463 .num_temp_offset = 3,
465 .old_peci_mask = 0x02, /* Actually reports PCH */
470 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
471 | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
472 | FEAT_PWM_FREQ2 | FEAT_SCALING | FEAT_FANCTL_ONOFF,
473 /* PECI: guesswork */
475 /* 16 bit fans (OHM) */
476 /* three fans, always 16 bit (guesswork) */
478 .num_temp_offset = 3,
484 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
485 | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
486 | FEAT_PWM_FREQ2 | FEAT_SCALING | FEAT_FANCTL_ONOFF,
487 /* PECI (coreboot) */
488 /* 12mV ADC (HWSensors4, OHM) */
489 /* 16 bit fans (HWSensors4, OHM) */
490 /* three fans, always 16 bit (datasheet) */
492 .num_temp_offset = 3,
498 .features = FEAT_16BIT_FANS
499 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2
502 .num_temp_offset = 3,
503 .old_peci_mask = 0x4,
508 .features = FEAT_16BIT_FANS
509 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2
512 .num_temp_offset = 3,
513 .old_peci_mask = 0x4,
518 .features = FEAT_16BIT_FANS
519 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2
522 .num_temp_offset = 3,
523 .old_peci_mask = 0x4,
528 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
529 | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
530 | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
532 .num_temp_offset = 3,
538 .features = FEAT_NEWER_AUTOPWM | FEAT_10_9MV_ADC | FEAT_SCALING
539 | FEAT_16BIT_FANS | FEAT_TEMP_PECI
540 | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
542 .num_temp_offset = 3,
548 .features = FEAT_NEWER_AUTOPWM | FEAT_10_9MV_ADC | FEAT_SCALING
549 | FEAT_16BIT_FANS | FEAT_TEMP_PECI
550 | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
552 .num_temp_offset = 3,
558 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
559 | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
560 | FEAT_AVCC3 | FEAT_PWM_FREQ2 | FEAT_SCALING,
562 .num_temp_offset = 3,
568 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
569 | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
570 | FEAT_AVCC3 | FEAT_PWM_FREQ2 | FEAT_SCALING
573 .num_temp_offset = 3,
579 .features = FEAT_NEWER_AUTOPWM | FEAT_11MV_ADC | FEAT_16BIT_FANS
580 | FEAT_TEMP_PECI | FEAT_FIVE_FANS
581 | FEAT_FIVE_PWM | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2
582 | FEAT_AVCC3 | FEAT_SCALING | FEAT_NEW_TEMPMAP,
584 .num_temp_offset = 6,
590 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
591 | FEAT_TEMP_PECI | FEAT_SIX_FANS
592 | FEAT_IN7_INTERNAL | FEAT_SIX_PWM | FEAT_PWM_FREQ2
593 | FEAT_SIX_TEMP | FEAT_VIN3_5V | FEAT_SCALING
596 .num_temp_offset = 3,
602 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
603 | FEAT_TEMP_PECI | FEAT_FIVE_FANS
604 | FEAT_FIVE_PWM | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2
605 | FEAT_AVCC3 | FEAT_VIN3_5V | FEAT_SCALING,
607 .num_temp_offset = 3,
613 .features = FEAT_NEWER_AUTOPWM | FEAT_16BIT_FANS
614 | FEAT_AVCC3 | FEAT_NEW_TEMPMAP
615 | FEAT_11MV_ADC | FEAT_IN7_INTERNAL | FEAT_SIX_FANS
616 | FEAT_SIX_PWM | FEAT_BANK_SEL | FEAT_SCALING,
618 .num_temp_offset = 6,
623 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
624 | FEAT_TEMP_PECI | FEAT_SIX_FANS
625 | FEAT_IN7_INTERNAL | FEAT_SIX_PWM | FEAT_PWM_FREQ2
626 | FEAT_SIX_TEMP | FEAT_SCALING | FEAT_AVCC3
629 .num_temp_offset = 3,
635 .features = FEAT_NEWER_AUTOPWM | FEAT_16BIT_FANS
636 | FEAT_AVCC3 | FEAT_NEW_TEMPMAP
637 | FEAT_10_9MV_ADC | FEAT_IN7_INTERNAL | FEAT_BANK_SEL,
639 .num_temp_offset = 6,
644 .features = FEAT_NEWER_AUTOPWM | FEAT_16BIT_FANS
645 | FEAT_AVCC3 | FEAT_NEW_TEMPMAP
646 | FEAT_10_9MV_ADC | FEAT_IN7_INTERNAL | FEAT_SIX_FANS
647 | FEAT_SIX_PWM | FEAT_BANK_SEL,
649 .num_temp_offset = 6,
654 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
655 | FEAT_SIX_FANS | FEAT_NEW_TEMPMAP
656 | FEAT_IN7_INTERNAL | FEAT_SIX_PWM | FEAT_PWM_FREQ2
657 | FEAT_SIX_TEMP | FEAT_BANK_SEL | FEAT_SCALING | FEAT_AVCC3,
659 .num_temp_offset = 6,
663 #define has_16bit_fans(data) ((data)->features & FEAT_16BIT_FANS)
664 #define has_12mv_adc(data) ((data)->features & FEAT_12MV_ADC)
665 #define has_10_9mv_adc(data) ((data)->features & FEAT_10_9MV_ADC)
666 #define has_newer_autopwm(data) ((data)->features & FEAT_NEWER_AUTOPWM)
667 #define has_old_autopwm(data) ((data)->features & FEAT_OLD_AUTOPWM)
668 #define has_temp_peci(data, nr) (((data)->features & FEAT_TEMP_PECI) && \
669 ((data)->peci_mask & BIT(nr)))
670 #define has_temp_old_peci(data, nr) \
671 (((data)->features & FEAT_TEMP_OLD_PECI) && \
672 ((data)->old_peci_mask & BIT(nr)))
673 #define has_fan16_config(data) ((data)->features & FEAT_FAN16_CONFIG)
674 #define has_five_fans(data) ((data)->features & (FEAT_FIVE_FANS | \
676 #define has_vid(data) ((data)->features & FEAT_VID)
677 #define has_in7_internal(data) ((data)->features & FEAT_IN7_INTERNAL)
678 #define has_six_fans(data) ((data)->features & FEAT_SIX_FANS)
679 #define has_avcc3(data) ((data)->features & FEAT_AVCC3)
680 #define has_five_pwm(data) ((data)->features & (FEAT_FIVE_PWM \
682 #define has_six_pwm(data) ((data)->features & FEAT_SIX_PWM)
683 #define has_pwm_freq2(data) ((data)->features & FEAT_PWM_FREQ2)
684 #define has_six_temp(data) ((data)->features & FEAT_SIX_TEMP)
685 #define has_vin3_5v(data) ((data)->features & FEAT_VIN3_5V)
686 #define has_four_fans(data) ((data)->features & (FEAT_FOUR_FANS | \
689 #define has_four_pwm(data) ((data)->features & (FEAT_FOUR_PWM | \
692 #define has_bank_sel(data) ((data)->features & FEAT_BANK_SEL)
693 #define has_scaling(data) ((data)->features & FEAT_SCALING)
694 #define has_fanctl_onoff(data) ((data)->features & FEAT_FANCTL_ONOFF)
695 #define has_11mv_adc(data) ((data)->features & FEAT_11MV_ADC)
696 #define has_new_tempmap(data) ((data)->features & FEAT_NEW_TEMPMAP)
698 struct it87_sio_data {
700 /* Values read from Super-I/O config space */
704 u8 internal; /* Internal sensors can be labeled */
705 /* Features skipped based on config or DMI */
714 * For each registered chip, we need to keep some data in memory.
715 * The structure is dynamically allocated.
718 const struct attribute_group *groups[7];
727 const u8 *REG_FAN_MIN;
728 const u8 *REG_FANX_MIN;
732 const u8 *REG_TEMP_OFFSET;
733 const u8 *REG_TEMP_LOW;
734 const u8 *REG_TEMP_HIGH;
738 struct mutex update_lock;
739 char valid; /* !=0 if following fields are valid */
740 unsigned long last_updated; /* In jiffies */
742 u16 in_scaled; /* Internal voltage sensors are scaled */
743 u16 in_internal; /* Bitfield, internal sensors (for labels) */
744 u16 has_in; /* Bitfield, voltage sensors enabled */
745 u8 in[NUM_VIN][3]; /* [nr][0]=in, [1]=min, [2]=max */
746 u8 has_fan; /* Bitfield, fans enabled */
747 u16 fan[NUM_FAN][2]; /* Register values, [nr][0]=fan, [1]=min */
748 u8 has_temp; /* Bitfield, temp sensors enabled */
749 s8 temp[NUM_TEMP][4]; /* [nr][0]=temp, [1]=min, [2]=max, [3]=offset */
750 u8 num_temp_limit; /* Number of temperature limit registers */
751 u8 num_temp_offset; /* Number of temperature offset registers */
752 u8 sensor; /* Register value (IT87_REG_TEMP_ENABLE) */
753 u8 extra; /* Register value (IT87_REG_TEMP_EXTRA) */
754 u8 fan_div[NUM_FAN_DIV];/* Register encoding, shifted right */
755 bool has_vid; /* True if VID supported */
756 u8 vid; /* Register encoding, combined */
758 u32 alarms; /* Register encoding, combined */
759 bool has_beep; /* true if beep supported */
760 u8 beeps; /* Register encoding */
761 u8 fan_main_ctrl; /* Register value */
762 u8 fan_ctl; /* Register value */
765 * The following 3 arrays correspond to the same registers up to
766 * the IT8720F. The meaning of bits 6-0 depends on the value of bit
767 * 7, and we want to preserve settings on mode changes, so we have
768 * to track all values separately.
769 * Starting with the IT8721F, the manual PWM duty cycles are stored
770 * in separate registers (8-bit values), so the separate tracking
771 * is no longer needed, but it is still done to keep the driver
774 u8 has_pwm; /* Bitfield, pwm control enabled */
775 u8 pwm_ctrl[NUM_PWM]; /* Register value */
776 u8 pwm_duty[NUM_PWM]; /* Manual PWM value set by user */
777 u8 pwm_temp_map[NUM_PWM];/* PWM to temp. chan. mapping (bits 1-0) */
779 /* Automatic fan speed control registers */
780 u8 auto_pwm[NUM_AUTO_PWM][4]; /* [nr][3] is hard-coded */
781 s8 auto_temp[NUM_AUTO_PWM][5]; /* [nr][0] is point1_temp_hyst */
784 static int adc_lsb(const struct it87_data *data, int nr)
788 if (has_12mv_adc(data))
790 else if (has_10_9mv_adc(data))
792 else if (has_11mv_adc(data))
796 if (data->in_scaled & BIT(nr))
801 static u8 in_to_reg(const struct it87_data *data, int nr, long val)
803 val = DIV_ROUND_CLOSEST(val * 10, adc_lsb(data, nr));
804 return clamp_val(val, 0, 255);
807 static int in_from_reg(const struct it87_data *data, int nr, int val)
809 return DIV_ROUND_CLOSEST(val * adc_lsb(data, nr), 10);
812 static inline u8 FAN_TO_REG(long rpm, int div)
816 rpm = clamp_val(rpm, 1, 1000000);
817 return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
820 static inline u16 FAN16_TO_REG(long rpm)
824 return clamp_val((1350000 + rpm) / (rpm * 2), 1, 0xfffe);
827 #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \
828 1350000 / ((val) * (div)))
829 /* The divider is fixed to 2 in 16-bit mode */
830 #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
831 1350000 / ((val) * 2))
833 #define TEMP_TO_REG(val) (clamp_val(((val) < 0 ? (((val) - 500) / 1000) : \
834 ((val) + 500) / 1000), -128, 127))
835 #define TEMP_FROM_REG(val) ((val) * 1000)
837 static u8 pwm_to_reg(const struct it87_data *data, long val)
839 if (has_newer_autopwm(data))
845 static int pwm_from_reg(const struct it87_data *data, u8 reg)
847 if (has_newer_autopwm(data))
850 return (reg & 0x7f) << 1;
853 static int DIV_TO_REG(int val)
857 while (answer < 7 && (val >>= 1))
862 #define DIV_FROM_REG(val) BIT(val)
865 * PWM base frequencies. The frequency has to be divided by either 128 or 256,
866 * depending on the chip type, to calculate the actual PWM frequency.
868 * Some of the chip datasheets suggest a base frequency of 51 kHz instead
869 * of 750 kHz for the slowest base frequency, resulting in a PWM frequency
870 * of 200 Hz. Sometimes both PWM frequency select registers are affected,
871 * sometimes just one. It is unknown if this is a datasheet error or real,
872 * so this is ignored for now.
874 static const unsigned int pwm_freq[8] = {
885 static int _it87_read_value(struct it87_data *data, u8 reg)
887 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
888 return inb_p(data->addr + IT87_DATA_REG_OFFSET);
891 static void _it87_write_value(struct it87_data *data, u8 reg, u8 value)
893 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
894 outb_p(value, data->addr + IT87_DATA_REG_OFFSET);
897 static void it87_set_bank(struct it87_data *data, u8 bank)
899 if (has_bank_sel(data) && bank != data->bank) {
900 u8 breg = _it87_read_value(data, IT87_REG_BANK);
905 _it87_write_value(data, IT87_REG_BANK, breg);
910 * Must be called with data->update_lock held, except during initialization.
911 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
912 * would slow down the IT87 access and should not be necessary.
914 static int it87_read_value(struct it87_data *data, u16 reg)
916 it87_set_bank(data, reg >> 8);
917 return _it87_read_value(data, reg & 0xff);
921 * Must be called with data->update_lock held, except during initialization.
922 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
923 * would slow down the IT87 access and should not be necessary.
925 static void it87_write_value(struct it87_data *data, u16 reg, u8 value)
927 it87_set_bank(data, reg >> 8);
928 _it87_write_value(data, reg & 0xff, value);
931 static void it87_update_pwm_ctrl(struct it87_data *data, int nr)
933 data->pwm_ctrl[nr] = it87_read_value(data, data->REG_PWM[nr]);
934 if (has_newer_autopwm(data)) {
935 if (has_new_tempmap(data))
936 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x38;
938 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
939 data->pwm_duty[nr] = it87_read_value(data,
940 IT87_REG_PWM_DUTY[nr]);
942 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
943 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
944 else /* Manual mode */
945 data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f;
948 if (has_old_autopwm(data)) {
951 for (i = 0; i < 5 ; i++)
952 data->auto_temp[nr][i] = it87_read_value(data,
953 IT87_REG_AUTO_TEMP(nr, i));
954 for (i = 0; i < 3 ; i++)
955 data->auto_pwm[nr][i] = it87_read_value(data,
956 IT87_REG_AUTO_PWM(nr, i));
957 } else if (has_newer_autopwm(data)) {
961 * 0: temperature hysteresis (base + 5)
962 * 1: fan off temperature (base + 0)
963 * 2: fan start temperature (base + 1)
964 * 3: fan max temperature (base + 2)
966 data->auto_temp[nr][0] =
967 it87_read_value(data, IT87_REG_AUTO_TEMP(nr, 5));
969 for (i = 0; i < 3 ; i++)
970 data->auto_temp[nr][i + 1] =
971 it87_read_value(data,
972 IT87_REG_AUTO_TEMP(nr, i));
974 * 0: start pwm value (base + 3)
975 * 1: pwm slope (base + 4, 1/8th pwm)
977 data->auto_pwm[nr][0] =
978 it87_read_value(data, IT87_REG_AUTO_TEMP(nr, 3));
979 data->auto_pwm[nr][1] =
980 it87_read_value(data, IT87_REG_AUTO_TEMP(nr, 4));
984 static struct it87_data *it87_update_device(struct device *dev)
986 struct it87_data *data = dev_get_drvdata(dev);
989 mutex_lock(&data->update_lock);
991 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) ||
995 * Cleared after each update, so reenable. Value
996 * returned by this read will be previous value
998 it87_write_value(data, IT87_REG_CONFIG,
999 it87_read_value(data, IT87_REG_CONFIG) | 0x40);
1001 for (i = 0; i < NUM_VIN; i++) {
1002 if (!(data->has_in & BIT(i)))
1006 it87_read_value(data, IT87_REG_VIN[i]);
1008 /* VBAT and AVCC don't have limit registers */
1009 if (i >= NUM_VIN_LIMIT)
1013 it87_read_value(data, IT87_REG_VIN_MIN(i));
1015 it87_read_value(data, IT87_REG_VIN_MAX(i));
1018 for (i = 0; i < NUM_FAN; i++) {
1019 /* Skip disabled fans */
1020 if (!(data->has_fan & BIT(i)))
1024 it87_read_value(data, data->REG_FAN_MIN[i]);
1025 data->fan[i][0] = it87_read_value(data,
1027 /* Add high byte if in 16-bit mode */
1028 if (has_16bit_fans(data)) {
1029 data->fan[i][0] |= it87_read_value(data,
1030 data->REG_FANX[i]) << 8;
1031 data->fan[i][1] |= it87_read_value(data,
1032 data->REG_FANX_MIN[i]) << 8;
1035 for (i = 0; i < NUM_TEMP; i++) {
1036 if (!(data->has_temp & BIT(i)))
1039 it87_read_value(data, IT87_REG_TEMP(i));
1041 if (i >= data->num_temp_limit)
1044 if (i < data->num_temp_offset)
1046 it87_read_value(data,
1047 data->REG_TEMP_OFFSET[i]);
1050 it87_read_value(data, data->REG_TEMP_LOW[i]);
1052 it87_read_value(data, data->REG_TEMP_HIGH[i]);
1055 /* Newer chips don't have clock dividers */
1056 if ((data->has_fan & 0x07) && !has_16bit_fans(data)) {
1057 i = it87_read_value(data, IT87_REG_FAN_DIV);
1058 data->fan_div[0] = i & 0x07;
1059 data->fan_div[1] = (i >> 3) & 0x07;
1060 data->fan_div[2] = (i & 0x40) ? 3 : 1;
1064 it87_read_value(data, IT87_REG_ALARM1) |
1065 (it87_read_value(data, IT87_REG_ALARM2) << 8) |
1066 (it87_read_value(data, IT87_REG_ALARM3) << 16);
1067 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
1069 data->fan_main_ctrl = it87_read_value(data,
1070 IT87_REG_FAN_MAIN_CTRL);
1071 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL);
1072 for (i = 0; i < NUM_PWM; i++) {
1073 if (!(data->has_pwm & BIT(i)))
1075 it87_update_pwm_ctrl(data, i);
1078 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
1079 data->extra = it87_read_value(data, IT87_REG_TEMP_EXTRA);
1081 * The IT8705F does not have VID capability.
1082 * The IT8718F and later don't use IT87_REG_VID for the
1085 if (data->type == it8712 || data->type == it8716) {
1086 data->vid = it87_read_value(data, IT87_REG_VID);
1088 * The older IT8712F revisions had only 5 VID pins,
1089 * but we assume it is always safe to read 6 bits.
1093 data->last_updated = jiffies;
1097 mutex_unlock(&data->update_lock);
1102 static ssize_t show_in(struct device *dev, struct device_attribute *attr,
1105 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1106 struct it87_data *data = it87_update_device(dev);
1107 int index = sattr->index;
1110 return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr][index]));
1113 static ssize_t set_in(struct device *dev, struct device_attribute *attr,
1114 const char *buf, size_t count)
1116 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1117 struct it87_data *data = dev_get_drvdata(dev);
1118 int index = sattr->index;
1122 if (kstrtoul(buf, 10, &val) < 0)
1125 mutex_lock(&data->update_lock);
1126 data->in[nr][index] = in_to_reg(data, nr, val);
1127 it87_write_value(data,
1128 index == 1 ? IT87_REG_VIN_MIN(nr)
1129 : IT87_REG_VIN_MAX(nr),
1130 data->in[nr][index]);
1131 mutex_unlock(&data->update_lock);
1135 static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0);
1136 static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_in, set_in,
1138 static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_in, set_in,
1141 static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 1, 0);
1142 static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_in, set_in,
1144 static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_in, set_in,
1147 static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 2, 0);
1148 static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_in, set_in,
1150 static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_in, set_in,
1153 static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 3, 0);
1154 static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_in, set_in,
1156 static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_in, set_in,
1159 static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 4, 0);
1160 static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_in, set_in,
1162 static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_in, set_in,
1165 static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 5, 0);
1166 static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_in, set_in,
1168 static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_in, set_in,
1171 static SENSOR_DEVICE_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 6, 0);
1172 static SENSOR_DEVICE_ATTR_2(in6_min, S_IRUGO | S_IWUSR, show_in, set_in,
1174 static SENSOR_DEVICE_ATTR_2(in6_max, S_IRUGO | S_IWUSR, show_in, set_in,
1177 static SENSOR_DEVICE_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 7, 0);
1178 static SENSOR_DEVICE_ATTR_2(in7_min, S_IRUGO | S_IWUSR, show_in, set_in,
1180 static SENSOR_DEVICE_ATTR_2(in7_max, S_IRUGO | S_IWUSR, show_in, set_in,
1183 static SENSOR_DEVICE_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 8, 0);
1184 static SENSOR_DEVICE_ATTR_2(in9_input, S_IRUGO, show_in, NULL, 9, 0);
1185 static SENSOR_DEVICE_ATTR_2(in10_input, S_IRUGO, show_in, NULL, 10, 0);
1186 static SENSOR_DEVICE_ATTR_2(in11_input, S_IRUGO, show_in, NULL, 11, 0);
1187 static SENSOR_DEVICE_ATTR_2(in12_input, S_IRUGO, show_in, NULL, 12, 0);
1189 /* Up to 6 temperatures */
1190 static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
1193 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1195 int index = sattr->index;
1196 struct it87_data *data = it87_update_device(dev);
1198 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr][index]));
1201 static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
1202 const char *buf, size_t count)
1204 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1206 int index = sattr->index;
1207 struct it87_data *data = dev_get_drvdata(dev);
1211 if (kstrtol(buf, 10, &val) < 0)
1214 mutex_lock(&data->update_lock);
1219 reg = data->REG_TEMP_LOW[nr];
1222 reg = data->REG_TEMP_HIGH[nr];
1225 regval = it87_read_value(data, IT87_REG_BEEP_ENABLE);
1226 if (!(regval & 0x80)) {
1228 it87_write_value(data, IT87_REG_BEEP_ENABLE, regval);
1231 reg = data->REG_TEMP_OFFSET[nr];
1235 data->temp[nr][index] = TEMP_TO_REG(val);
1236 it87_write_value(data, reg, data->temp[nr][index]);
1237 mutex_unlock(&data->update_lock);
1241 static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0);
1242 static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1244 static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1246 static SENSOR_DEVICE_ATTR_2(temp1_offset, S_IRUGO | S_IWUSR, show_temp,
1248 static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, 0);
1249 static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1251 static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1253 static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IRUGO | S_IWUSR, show_temp,
1255 static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 2, 0);
1256 static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1258 static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1260 static SENSOR_DEVICE_ATTR_2(temp3_offset, S_IRUGO | S_IWUSR, show_temp,
1262 static SENSOR_DEVICE_ATTR_2(temp4_input, S_IRUGO, show_temp, NULL, 3, 0);
1263 static SENSOR_DEVICE_ATTR_2(temp4_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1265 static SENSOR_DEVICE_ATTR_2(temp4_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1267 static SENSOR_DEVICE_ATTR_2(temp4_offset, S_IRUGO | S_IWUSR, show_temp,
1269 static SENSOR_DEVICE_ATTR_2(temp5_input, S_IRUGO, show_temp, NULL, 4, 0);
1270 static SENSOR_DEVICE_ATTR_2(temp5_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1272 static SENSOR_DEVICE_ATTR_2(temp5_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1274 static SENSOR_DEVICE_ATTR_2(temp5_offset, S_IRUGO | S_IWUSR, show_temp,
1276 static SENSOR_DEVICE_ATTR_2(temp6_input, S_IRUGO, show_temp, NULL, 5, 0);
1277 static SENSOR_DEVICE_ATTR_2(temp6_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
1279 static SENSOR_DEVICE_ATTR_2(temp6_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
1281 static SENSOR_DEVICE_ATTR_2(temp6_offset, S_IRUGO | S_IWUSR, show_temp,
1284 static int get_temp_type(struct it87_data *data, int index)
1289 if (has_bank_sel(data)) {
1290 int s1reg = IT87_REG_TEMP_SRC1[index/2] >> ((index % 2) * 4);
1293 src1 = (it87_read_value(data, s1reg) >> ((index % 2) * 4)) & 0x0f;
1294 src2 = it87_read_value(data, IT87_REG_TEMP_SRC2);
1296 switch (data->type) {
1304 if (index == 1 || index == 2 ||
1305 index == 4 || index == 5)
1309 if (index == 2 || index == 6)
1327 type = (src2 & BIT(index)) ? 6 : 5;
1330 type = (src2 & BIT(index)) ? 4 : 6;
1333 type = (src2 & BIT(index)) ? 5 : 0;
1346 reg = it87_read_value(data, IT87_REG_TEMP_ENABLE);
1347 extra = it87_read_value(data, IT87_REG_TEMP_EXTRA);
1349 if ((has_temp_peci(data, index) && (reg >> 6 == index + 1)) ||
1350 (has_temp_old_peci(data, index) && (extra & 0x80)))
1351 type = 6; /* Intel PECI */
1352 if (reg & BIT(index))
1353 type = 3; /* thermal diode */
1354 else if (reg & BIT(index + 3))
1355 type = 4; /* thermistor */
1360 static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr,
1363 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1364 struct it87_data *data = it87_update_device(dev);
1365 int type = get_temp_type(data, sensor_attr->index);
1367 return sprintf(buf, "%d\n", type);
1370 static ssize_t set_temp_type(struct device *dev, struct device_attribute *attr,
1371 const char *buf, size_t count)
1373 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1374 int nr = sensor_attr->index;
1376 struct it87_data *data = dev_get_drvdata(dev);
1380 if (kstrtol(buf, 10, &val) < 0)
1383 reg = it87_read_value(data, IT87_REG_TEMP_ENABLE);
1386 if (has_temp_peci(data, nr) && (reg >> 6 == nr + 1 || val == 6))
1388 extra = it87_read_value(data, IT87_REG_TEMP_EXTRA);
1389 if (has_temp_old_peci(data, nr) && ((extra & 0x80) || val == 6))
1391 if (val == 2) { /* backwards compatibility */
1393 "Sensor type 2 is deprecated, please use 4 instead\n");
1396 /* 3 = thermal diode; 4 = thermistor; 6 = Intel PECI; 0 = disabled */
1401 else if (has_temp_peci(data, nr) && val == 6)
1402 reg |= (nr + 1) << 6;
1403 else if (has_temp_old_peci(data, nr) && val == 6)
1408 mutex_lock(&data->update_lock);
1410 data->extra = extra;
1411 it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor);
1412 if (has_temp_old_peci(data, nr))
1413 it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra);
1414 data->valid = 0; /* Force cache refresh */
1415 mutex_unlock(&data->update_lock);
1419 static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR, show_temp_type,
1421 static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR, show_temp_type,
1423 static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR, show_temp_type,
1425 static SENSOR_DEVICE_ATTR(temp4_type, S_IRUGO | S_IWUSR, show_temp_type,
1427 static SENSOR_DEVICE_ATTR(temp5_type, S_IRUGO | S_IWUSR, show_temp_type,
1429 static SENSOR_DEVICE_ATTR(temp6_type, S_IRUGO | S_IWUSR, show_temp_type,
1434 static int pwm_mode(const struct it87_data *data, int nr)
1436 if (has_fanctl_onoff(data) && nr < 3 &&
1437 !(data->fan_main_ctrl & BIT(nr)))
1438 return 0; /* Full speed */
1439 if (data->pwm_ctrl[nr] & 0x80)
1440 return 2; /* Automatic mode */
1441 if ((!has_fanctl_onoff(data) || nr >= 3) &&
1442 data->pwm_duty[nr] == pwm_to_reg(data, 0xff))
1443 return 0; /* Full speed */
1445 return 1; /* Manual mode */
1448 static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
1451 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1453 int index = sattr->index;
1455 struct it87_data *data = it87_update_device(dev);
1457 speed = has_16bit_fans(data) ?
1458 FAN16_FROM_REG(data->fan[nr][index]) :
1459 FAN_FROM_REG(data->fan[nr][index],
1460 DIV_FROM_REG(data->fan_div[nr]));
1461 return sprintf(buf, "%d\n", speed);
1464 static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
1467 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1468 struct it87_data *data = it87_update_device(dev);
1469 int nr = sensor_attr->index;
1471 return sprintf(buf, "%lu\n", DIV_FROM_REG(data->fan_div[nr]));
1474 static ssize_t show_pwm_enable(struct device *dev,
1475 struct device_attribute *attr, char *buf)
1477 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1478 struct it87_data *data = it87_update_device(dev);
1479 int nr = sensor_attr->index;
1481 return sprintf(buf, "%d\n", pwm_mode(data, nr));
1484 static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
1487 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1488 struct it87_data *data = it87_update_device(dev);
1489 int nr = sensor_attr->index;
1491 return sprintf(buf, "%d\n",
1492 pwm_from_reg(data, data->pwm_duty[nr]));
1495 static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
1498 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1499 struct it87_data *data = it87_update_device(dev);
1500 int nr = sensor_attr->index;
1504 if (has_pwm_freq2(data) && nr == 1)
1505 index = (data->extra >> 4) & 0x07;
1507 index = (data->fan_ctl >> 4) & 0x07;
1509 freq = pwm_freq[index] / (has_newer_autopwm(data) ? 256 : 128);
1511 return sprintf(buf, "%u\n", freq);
1514 static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
1515 const char *buf, size_t count)
1517 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1519 int index = sattr->index;
1521 struct it87_data *data = dev_get_drvdata(dev);
1525 if (kstrtol(buf, 10, &val) < 0)
1528 mutex_lock(&data->update_lock);
1530 if (has_16bit_fans(data)) {
1531 data->fan[nr][index] = FAN16_TO_REG(val);
1532 it87_write_value(data, data->REG_FAN_MIN[nr],
1533 data->fan[nr][index] & 0xff);
1534 it87_write_value(data, data->REG_FANX_MIN[nr],
1535 data->fan[nr][index] >> 8);
1537 reg = it87_read_value(data, IT87_REG_FAN_DIV);
1540 data->fan_div[nr] = reg & 0x07;
1543 data->fan_div[nr] = (reg >> 3) & 0x07;
1546 data->fan_div[nr] = (reg & 0x40) ? 3 : 1;
1549 data->fan[nr][index] =
1550 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
1551 it87_write_value(data, data->REG_FAN_MIN[nr],
1552 data->fan[nr][index]);
1555 mutex_unlock(&data->update_lock);
1559 static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
1560 const char *buf, size_t count)
1562 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1563 struct it87_data *data = dev_get_drvdata(dev);
1564 int nr = sensor_attr->index;
1569 if (kstrtoul(buf, 10, &val) < 0)
1572 mutex_lock(&data->update_lock);
1573 old = it87_read_value(data, IT87_REG_FAN_DIV);
1575 /* Save fan min limit */
1576 min = FAN_FROM_REG(data->fan[nr][1], DIV_FROM_REG(data->fan_div[nr]));
1581 data->fan_div[nr] = DIV_TO_REG(val);
1585 data->fan_div[nr] = 1;
1587 data->fan_div[nr] = 3;
1590 val |= (data->fan_div[0] & 0x07);
1591 val |= (data->fan_div[1] & 0x07) << 3;
1592 if (data->fan_div[2] == 3)
1594 it87_write_value(data, IT87_REG_FAN_DIV, val);
1596 /* Restore fan min limit */
1597 data->fan[nr][1] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
1598 it87_write_value(data, data->REG_FAN_MIN[nr], data->fan[nr][1]);
1600 mutex_unlock(&data->update_lock);
1604 /* Returns 0 if OK, -EINVAL otherwise */
1605 static int check_trip_points(struct device *dev, int nr)
1607 const struct it87_data *data = dev_get_drvdata(dev);
1610 if (has_old_autopwm(data)) {
1611 for (i = 0; i < 3; i++) {
1612 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1])
1615 for (i = 0; i < 2; i++) {
1616 if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1])
1619 } else if (has_newer_autopwm(data)) {
1620 for (i = 1; i < 3; i++) {
1621 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1])
1628 "Inconsistent trip points, not switching to automatic mode\n");
1629 dev_err(dev, "Adjust the trip points and try again\n");
1634 static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr,
1635 const char *buf, size_t count)
1637 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1638 struct it87_data *data = dev_get_drvdata(dev);
1639 int nr = sensor_attr->index;
1642 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 2)
1645 /* Check trip points before switching to automatic mode */
1647 if (check_trip_points(dev, nr) < 0)
1651 mutex_lock(&data->update_lock);
1654 if (nr < 3 && has_fanctl_onoff(data)) {
1656 /* make sure the fan is on when in on/off mode */
1657 tmp = it87_read_value(data, IT87_REG_FAN_CTL);
1658 it87_write_value(data, IT87_REG_FAN_CTL, tmp | BIT(nr));
1659 /* set on/off mode */
1660 data->fan_main_ctrl &= ~BIT(nr);
1661 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
1662 data->fan_main_ctrl);
1666 /* No on/off mode, set maximum pwm value */
1667 data->pwm_duty[nr] = pwm_to_reg(data, 0xff);
1668 it87_write_value(data, IT87_REG_PWM_DUTY[nr],
1669 data->pwm_duty[nr]);
1670 /* and set manual mode */
1671 if (has_newer_autopwm(data)) {
1672 ctrl = (data->pwm_ctrl[nr] & 0x7c) |
1673 data->pwm_temp_map[nr];
1675 ctrl = data->pwm_duty[nr];
1677 data->pwm_ctrl[nr] = ctrl;
1678 it87_write_value(data, data->REG_PWM[nr], ctrl);
1683 if (has_newer_autopwm(data)) {
1684 ctrl = (data->pwm_ctrl[nr] & 0x7c) |
1685 data->pwm_temp_map[nr];
1689 ctrl = (val == 1 ? data->pwm_duty[nr] : 0x80);
1691 data->pwm_ctrl[nr] = ctrl;
1692 it87_write_value(data, data->REG_PWM[nr], ctrl);
1694 if (has_fanctl_onoff(data) && nr < 3) {
1695 /* set SmartGuardian mode */
1696 data->fan_main_ctrl |= BIT(nr);
1697 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
1698 data->fan_main_ctrl);
1702 mutex_unlock(&data->update_lock);
1706 static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1707 const char *buf, size_t count)
1709 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1710 struct it87_data *data = dev_get_drvdata(dev);
1711 int nr = sensor_attr->index;
1714 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
1717 mutex_lock(&data->update_lock);
1718 it87_update_pwm_ctrl(data, nr);
1719 if (has_newer_autopwm(data)) {
1721 * If we are in automatic mode, the PWM duty cycle register
1722 * is read-only so we can't write the value.
1724 if (data->pwm_ctrl[nr] & 0x80) {
1725 mutex_unlock(&data->update_lock);
1728 data->pwm_duty[nr] = pwm_to_reg(data, val);
1729 it87_write_value(data, IT87_REG_PWM_DUTY[nr],
1730 data->pwm_duty[nr]);
1732 data->pwm_duty[nr] = pwm_to_reg(data, val);
1734 * If we are in manual mode, write the duty cycle immediately;
1735 * otherwise, just store it for later use.
1737 if (!(data->pwm_ctrl[nr] & 0x80)) {
1738 data->pwm_ctrl[nr] = data->pwm_duty[nr];
1739 it87_write_value(data, data->REG_PWM[nr],
1740 data->pwm_ctrl[nr]);
1743 mutex_unlock(&data->update_lock);
1747 static ssize_t set_pwm_freq(struct device *dev, struct device_attribute *attr,
1748 const char *buf, size_t count)
1750 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1751 struct it87_data *data = dev_get_drvdata(dev);
1752 int nr = sensor_attr->index;
1756 if (kstrtoul(buf, 10, &val) < 0)
1759 val = clamp_val(val, 0, 1000000);
1760 val *= has_newer_autopwm(data) ? 256 : 128;
1762 /* Search for the nearest available frequency */
1763 for (i = 0; i < 7; i++) {
1764 if (val > (pwm_freq[i] + pwm_freq[i + 1]) / 2)
1768 mutex_lock(&data->update_lock);
1770 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f;
1771 data->fan_ctl |= i << 4;
1772 it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl);
1774 data->extra = it87_read_value(data, IT87_REG_TEMP_EXTRA) & 0x8f;
1775 data->extra |= i << 4;
1776 it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra);
1778 mutex_unlock(&data->update_lock);
1783 static ssize_t show_pwm_temp_map(struct device *dev,
1784 struct device_attribute *attr, char *buf)
1786 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1787 struct it87_data *data = it87_update_device(dev);
1788 int nr = sensor_attr->index;
1791 map = data->pwm_temp_map[nr];
1792 if (has_new_tempmap(data)) {
1795 map = 0; /* Should never happen */
1798 map = 0; /* Should never happen */
1799 if (nr >= 3) /* pwm channels 3..6 map to temp4..6 */
1803 return sprintf(buf, "%d\n", (int)BIT(map));
1806 static ssize_t set_pwm_temp_map(struct device *dev,
1807 struct device_attribute *attr, const char *buf,
1810 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1811 struct it87_data *data = dev_get_drvdata(dev);
1812 int nr = sensor_attr->index;
1816 if (kstrtol(buf, 10, &val) < 0)
1819 if (nr >= 3 && !has_new_tempmap(data))
1848 if (has_new_tempmap(data))
1850 else if (reg > 0x02)
1853 mutex_lock(&data->update_lock);
1854 it87_update_pwm_ctrl(data, nr);
1855 data->pwm_temp_map[nr] = reg;
1857 * If we are in automatic mode, write the temp mapping immediately;
1858 * otherwise, just store it for later use.
1860 if (data->pwm_ctrl[nr] & 0x80) {
1861 u8 mask = has_new_tempmap(data) ? 0xc7 : 0xfc;
1863 data->pwm_ctrl[nr] = (data->pwm_ctrl[nr] & mask) |
1864 data->pwm_temp_map[nr];
1865 it87_write_value(data, data->REG_PWM[nr], data->pwm_ctrl[nr]);
1867 mutex_unlock(&data->update_lock);
1871 static ssize_t show_auto_pwm(struct device *dev, struct device_attribute *attr,
1874 struct it87_data *data = it87_update_device(dev);
1875 struct sensor_device_attribute_2 *sensor_attr =
1876 to_sensor_dev_attr_2(attr);
1877 int nr = sensor_attr->nr;
1878 int point = sensor_attr->index;
1880 return sprintf(buf, "%d\n",
1881 pwm_from_reg(data, data->auto_pwm[nr][point]));
1884 static ssize_t set_auto_pwm(struct device *dev, struct device_attribute *attr,
1885 const char *buf, size_t count)
1887 struct it87_data *data = dev_get_drvdata(dev);
1888 struct sensor_device_attribute_2 *sensor_attr =
1889 to_sensor_dev_attr_2(attr);
1890 int nr = sensor_attr->nr;
1891 int point = sensor_attr->index;
1895 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
1898 mutex_lock(&data->update_lock);
1899 data->auto_pwm[nr][point] = pwm_to_reg(data, val);
1900 if (has_newer_autopwm(data))
1901 regaddr = IT87_REG_AUTO_TEMP(nr, 3);
1903 regaddr = IT87_REG_AUTO_PWM(nr, point);
1904 it87_write_value(data, regaddr, data->auto_pwm[nr][point]);
1905 mutex_unlock(&data->update_lock);
1909 static ssize_t show_auto_pwm_slope(struct device *dev,
1910 struct device_attribute *attr, char *buf)
1912 struct it87_data *data = it87_update_device(dev);
1913 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1914 int nr = sensor_attr->index;
1916 return sprintf(buf, "%d\n", data->auto_pwm[nr][1] & 0x7f);
1919 static ssize_t set_auto_pwm_slope(struct device *dev,
1920 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 *sensor_attr = to_sensor_dev_attr(attr);
1925 int nr = sensor_attr->index;
1928 if (kstrtoul(buf, 10, &val) < 0 || val > 127)
1931 mutex_lock(&data->update_lock);
1932 data->auto_pwm[nr][1] = (data->auto_pwm[nr][1] & 0x80) | val;
1933 it87_write_value(data, IT87_REG_AUTO_TEMP(nr, 4),
1934 data->auto_pwm[nr][1]);
1935 mutex_unlock(&data->update_lock);
1939 static ssize_t show_auto_temp(struct device *dev, struct device_attribute *attr,
1942 struct it87_data *data = it87_update_device(dev);
1943 struct sensor_device_attribute_2 *sensor_attr =
1944 to_sensor_dev_attr_2(attr);
1945 int nr = sensor_attr->nr;
1946 int point = sensor_attr->index;
1949 if (has_old_autopwm(data) || point)
1950 reg = data->auto_temp[nr][point];
1952 reg = data->auto_temp[nr][1] - (data->auto_temp[nr][0] & 0x1f);
1954 return sprintf(buf, "%d\n", TEMP_FROM_REG(reg));
1957 static ssize_t set_auto_temp(struct device *dev, struct device_attribute *attr,
1958 const char *buf, size_t count)
1960 struct it87_data *data = dev_get_drvdata(dev);
1961 struct sensor_device_attribute_2 *sensor_attr =
1962 to_sensor_dev_attr_2(attr);
1963 int nr = sensor_attr->nr;
1964 int point = sensor_attr->index;
1968 if (kstrtol(buf, 10, &val) < 0 || val < -128000 || val > 127000)
1971 mutex_lock(&data->update_lock);
1972 if (has_newer_autopwm(data) && !point) {
1973 reg = data->auto_temp[nr][1] - TEMP_TO_REG(val);
1974 reg = clamp_val(reg, 0, 0x1f) | (data->auto_temp[nr][0] & 0xe0);
1975 data->auto_temp[nr][0] = reg;
1976 it87_write_value(data, IT87_REG_AUTO_TEMP(nr, 5), reg);
1978 reg = TEMP_TO_REG(val);
1979 data->auto_temp[nr][point] = reg;
1980 if (has_newer_autopwm(data))
1982 it87_write_value(data, IT87_REG_AUTO_TEMP(nr, point), reg);
1984 mutex_unlock(&data->update_lock);
1988 static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0);
1989 static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1991 static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, show_fan_div,
1994 static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 1, 0);
1995 static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1997 static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, show_fan_div,
2000 static SENSOR_DEVICE_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 2, 0);
2001 static SENSOR_DEVICE_ATTR_2(fan3_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
2003 static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO | S_IWUSR, show_fan_div,
2006 static SENSOR_DEVICE_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 3, 0);
2007 static SENSOR_DEVICE_ATTR_2(fan4_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
2010 static SENSOR_DEVICE_ATTR_2(fan5_input, S_IRUGO, show_fan, NULL, 4, 0);
2011 static SENSOR_DEVICE_ATTR_2(fan5_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
2014 static SENSOR_DEVICE_ATTR_2(fan6_input, S_IRUGO, show_fan, NULL, 5, 0);
2015 static SENSOR_DEVICE_ATTR_2(fan6_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
2018 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
2019 show_pwm_enable, set_pwm_enable, 0);
2020 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0);
2021 static SENSOR_DEVICE_ATTR(pwm1_freq, S_IRUGO | S_IWUSR, show_pwm_freq,
2023 static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IRUGO,
2024 show_pwm_temp_map, set_pwm_temp_map, 0);
2025 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR,
2026 show_auto_pwm, set_auto_pwm, 0, 0);
2027 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR,
2028 show_auto_pwm, set_auto_pwm, 0, 1);
2029 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR,
2030 show_auto_pwm, set_auto_pwm, 0, 2);
2031 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO,
2032 show_auto_pwm, NULL, 0, 3);
2033 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR,
2034 show_auto_temp, set_auto_temp, 0, 1);
2035 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
2036 show_auto_temp, set_auto_temp, 0, 0);
2037 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR,
2038 show_auto_temp, set_auto_temp, 0, 2);
2039 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR,
2040 show_auto_temp, set_auto_temp, 0, 3);
2041 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR,
2042 show_auto_temp, set_auto_temp, 0, 4);
2043 static SENSOR_DEVICE_ATTR_2(pwm1_auto_start, S_IRUGO | S_IWUSR,
2044 show_auto_pwm, set_auto_pwm, 0, 0);
2045 static SENSOR_DEVICE_ATTR(pwm1_auto_slope, S_IRUGO | S_IWUSR,
2046 show_auto_pwm_slope, set_auto_pwm_slope, 0);
2048 static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR,
2049 show_pwm_enable, set_pwm_enable, 1);
2050 static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 1);
2051 static SENSOR_DEVICE_ATTR(pwm2_freq, S_IRUGO, show_pwm_freq, set_pwm_freq, 1);
2052 static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IRUGO,
2053 show_pwm_temp_map, set_pwm_temp_map, 1);
2054 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR,
2055 show_auto_pwm, set_auto_pwm, 1, 0);
2056 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO | S_IWUSR,
2057 show_auto_pwm, set_auto_pwm, 1, 1);
2058 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO | S_IWUSR,
2059 show_auto_pwm, set_auto_pwm, 1, 2);
2060 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO,
2061 show_auto_pwm, NULL, 1, 3);
2062 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR,
2063 show_auto_temp, set_auto_temp, 1, 1);
2064 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
2065 show_auto_temp, set_auto_temp, 1, 0);
2066 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR,
2067 show_auto_temp, set_auto_temp, 1, 2);
2068 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR,
2069 show_auto_temp, set_auto_temp, 1, 3);
2070 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_temp, S_IRUGO | S_IWUSR,
2071 show_auto_temp, set_auto_temp, 1, 4);
2072 static SENSOR_DEVICE_ATTR_2(pwm2_auto_start, S_IRUGO | S_IWUSR,
2073 show_auto_pwm, set_auto_pwm, 1, 0);
2074 static SENSOR_DEVICE_ATTR(pwm2_auto_slope, S_IRUGO | S_IWUSR,
2075 show_auto_pwm_slope, set_auto_pwm_slope, 1);
2077 static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR,
2078 show_pwm_enable, set_pwm_enable, 2);
2079 static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 2);
2080 static SENSOR_DEVICE_ATTR(pwm3_freq, S_IRUGO, show_pwm_freq, NULL, 2);
2081 static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IRUGO,
2082 show_pwm_temp_map, set_pwm_temp_map, 2);
2083 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO | S_IWUSR,
2084 show_auto_pwm, set_auto_pwm, 2, 0);
2085 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR,
2086 show_auto_pwm, set_auto_pwm, 2, 1);
2087 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO | S_IWUSR,
2088 show_auto_pwm, set_auto_pwm, 2, 2);
2089 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO,
2090 show_auto_pwm, NULL, 2, 3);
2091 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp, S_IRUGO | S_IWUSR,
2092 show_auto_temp, set_auto_temp, 2, 1);
2093 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
2094 show_auto_temp, set_auto_temp, 2, 0);
2095 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_temp, S_IRUGO | S_IWUSR,
2096 show_auto_temp, set_auto_temp, 2, 2);
2097 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_temp, S_IRUGO | S_IWUSR,
2098 show_auto_temp, set_auto_temp, 2, 3);
2099 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_temp, S_IRUGO | S_IWUSR,
2100 show_auto_temp, set_auto_temp, 2, 4);
2101 static SENSOR_DEVICE_ATTR_2(pwm3_auto_start, S_IRUGO | S_IWUSR,
2102 show_auto_pwm, set_auto_pwm, 2, 0);
2103 static SENSOR_DEVICE_ATTR(pwm3_auto_slope, S_IRUGO | S_IWUSR,
2104 show_auto_pwm_slope, set_auto_pwm_slope, 2);
2106 static SENSOR_DEVICE_ATTR(pwm4_enable, S_IRUGO | S_IWUSR,
2107 show_pwm_enable, set_pwm_enable, 3);
2108 static SENSOR_DEVICE_ATTR(pwm4, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 3);
2109 static SENSOR_DEVICE_ATTR(pwm4_freq, S_IRUGO, show_pwm_freq, NULL, 3);
2110 static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IRUGO,
2111 show_pwm_temp_map, set_pwm_temp_map, 3);
2112 static SENSOR_DEVICE_ATTR_2(pwm4_auto_point1_temp, S_IRUGO | S_IWUSR,
2113 show_auto_temp, set_auto_temp, 2, 1);
2114 static SENSOR_DEVICE_ATTR_2(pwm4_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
2115 show_auto_temp, set_auto_temp, 2, 0);
2116 static SENSOR_DEVICE_ATTR_2(pwm4_auto_point2_temp, S_IRUGO | S_IWUSR,
2117 show_auto_temp, set_auto_temp, 2, 2);
2118 static SENSOR_DEVICE_ATTR_2(pwm4_auto_point3_temp, S_IRUGO | S_IWUSR,
2119 show_auto_temp, set_auto_temp, 2, 3);
2120 static SENSOR_DEVICE_ATTR_2(pwm4_auto_start, S_IRUGO | S_IWUSR,
2121 show_auto_pwm, set_auto_pwm, 3, 0);
2122 static SENSOR_DEVICE_ATTR(pwm4_auto_slope, S_IRUGO | S_IWUSR,
2123 show_auto_pwm_slope, set_auto_pwm_slope, 3);
2125 static SENSOR_DEVICE_ATTR(pwm5_enable, S_IRUGO | S_IWUSR,
2126 show_pwm_enable, set_pwm_enable, 4);
2127 static SENSOR_DEVICE_ATTR(pwm5, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 4);
2128 static SENSOR_DEVICE_ATTR(pwm5_freq, S_IRUGO, show_pwm_freq, NULL, 4);
2129 static SENSOR_DEVICE_ATTR(pwm5_auto_channels_temp, S_IRUGO,
2130 show_pwm_temp_map, set_pwm_temp_map, 4);
2131 static SENSOR_DEVICE_ATTR_2(pwm5_auto_point1_temp, S_IRUGO | S_IWUSR,
2132 show_auto_temp, set_auto_temp, 2, 1);
2133 static SENSOR_DEVICE_ATTR_2(pwm5_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
2134 show_auto_temp, set_auto_temp, 2, 0);
2135 static SENSOR_DEVICE_ATTR_2(pwm5_auto_point2_temp, S_IRUGO | S_IWUSR,
2136 show_auto_temp, set_auto_temp, 2, 2);
2137 static SENSOR_DEVICE_ATTR_2(pwm5_auto_point3_temp, S_IRUGO | S_IWUSR,
2138 show_auto_temp, set_auto_temp, 2, 3);
2139 static SENSOR_DEVICE_ATTR_2(pwm5_auto_start, S_IRUGO | S_IWUSR,
2140 show_auto_pwm, set_auto_pwm, 4, 0);
2141 static SENSOR_DEVICE_ATTR(pwm5_auto_slope, S_IRUGO | S_IWUSR,
2142 show_auto_pwm_slope, set_auto_pwm_slope, 4);
2144 static SENSOR_DEVICE_ATTR(pwm6_enable, S_IRUGO | S_IWUSR,
2145 show_pwm_enable, set_pwm_enable, 5);
2146 static SENSOR_DEVICE_ATTR(pwm6, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 5);
2147 static SENSOR_DEVICE_ATTR(pwm6_freq, S_IRUGO, show_pwm_freq, NULL, 5);
2148 static SENSOR_DEVICE_ATTR(pwm6_auto_channels_temp, S_IRUGO,
2149 show_pwm_temp_map, set_pwm_temp_map, 5);
2150 static SENSOR_DEVICE_ATTR_2(pwm6_auto_point1_temp, S_IRUGO | S_IWUSR,
2151 show_auto_temp, set_auto_temp, 2, 1);
2152 static SENSOR_DEVICE_ATTR_2(pwm6_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
2153 show_auto_temp, set_auto_temp, 2, 0);
2154 static SENSOR_DEVICE_ATTR_2(pwm6_auto_point2_temp, S_IRUGO | S_IWUSR,
2155 show_auto_temp, set_auto_temp, 2, 2);
2156 static SENSOR_DEVICE_ATTR_2(pwm6_auto_point3_temp, S_IRUGO | S_IWUSR,
2157 show_auto_temp, set_auto_temp, 2, 3);
2158 static SENSOR_DEVICE_ATTR_2(pwm6_auto_start, S_IRUGO | S_IWUSR,
2159 show_auto_pwm, set_auto_pwm, 5, 0);
2160 static SENSOR_DEVICE_ATTR(pwm6_auto_slope, S_IRUGO | S_IWUSR,
2161 show_auto_pwm_slope, set_auto_pwm_slope, 5);
2164 static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
2167 struct it87_data *data = it87_update_device(dev);
2169 return sprintf(buf, "%u\n", data->alarms);
2171 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
2173 static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
2176 struct it87_data *data = it87_update_device(dev);
2177 int bitnr = to_sensor_dev_attr(attr)->index;
2179 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
2182 static ssize_t clear_intrusion(struct device *dev,
2183 struct device_attribute *attr, const char *buf,
2186 struct it87_data *data = dev_get_drvdata(dev);
2190 if (kstrtol(buf, 10, &val) < 0 || val != 0)
2193 mutex_lock(&data->update_lock);
2194 config = it87_read_value(data, IT87_REG_CONFIG);
2199 it87_write_value(data, IT87_REG_CONFIG, config);
2200 /* Invalidate cache to force re-read */
2203 mutex_unlock(&data->update_lock);
2208 static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8);
2209 static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9);
2210 static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10);
2211 static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11);
2212 static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12);
2213 static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13);
2214 static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14);
2215 static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15);
2216 static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0);
2217 static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1);
2218 static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2);
2219 static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3);
2220 static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6);
2221 static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_alarm, NULL, 7);
2222 static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16);
2223 static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17);
2224 static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18);
2225 static SENSOR_DEVICE_ATTR(temp4_alarm, S_IRUGO, show_alarm, NULL, 19);
2226 static SENSOR_DEVICE_ATTR(temp5_alarm, S_IRUGO, show_alarm, NULL, 20);
2227 static SENSOR_DEVICE_ATTR(temp6_alarm, S_IRUGO, show_alarm, NULL, 21);
2228 static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR,
2229 show_alarm, clear_intrusion, 4);
2231 static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
2234 struct it87_data *data = it87_update_device(dev);
2235 int bitnr = to_sensor_dev_attr(attr)->index;
2237 return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1);
2240 static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
2241 const char *buf, size_t count)
2243 int bitnr = to_sensor_dev_attr(attr)->index;
2244 struct it87_data *data = dev_get_drvdata(dev);
2247 if (kstrtol(buf, 10, &val) < 0 || (val != 0 && val != 1))
2250 mutex_lock(&data->update_lock);
2251 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
2253 data->beeps |= BIT(bitnr);
2255 data->beeps &= ~BIT(bitnr);
2256 it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps);
2257 mutex_unlock(&data->update_lock);
2261 static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
2262 show_beep, set_beep, 1);
2263 static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO, show_beep, NULL, 1);
2264 static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO, show_beep, NULL, 1);
2265 static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO, show_beep, NULL, 1);
2266 static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO, show_beep, NULL, 1);
2267 static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO, show_beep, NULL, 1);
2268 static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO, show_beep, NULL, 1);
2269 static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO, show_beep, NULL, 1);
2270 /* fanX_beep writability is set later */
2271 static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO, show_beep, set_beep, 0);
2272 static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0);
2273 static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0);
2274 static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0);
2275 static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0);
2276 static SENSOR_DEVICE_ATTR(fan6_beep, S_IRUGO, show_beep, set_beep, 0);
2277 static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
2278 show_beep, set_beep, 2);
2279 static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2);
2280 static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2);
2281 static SENSOR_DEVICE_ATTR(temp4_beep, S_IRUGO, show_beep, NULL, 2);
2282 static SENSOR_DEVICE_ATTR(temp5_beep, S_IRUGO, show_beep, NULL, 2);
2283 static SENSOR_DEVICE_ATTR(temp6_beep, S_IRUGO, show_beep, NULL, 2);
2285 static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
2288 struct it87_data *data = dev_get_drvdata(dev);
2290 return sprintf(buf, "%u\n", data->vrm);
2293 static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
2294 const char *buf, size_t count)
2296 struct it87_data *data = dev_get_drvdata(dev);
2299 if (kstrtoul(buf, 10, &val) < 0)
2306 static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
2308 static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
2311 struct it87_data *data = it87_update_device(dev);
2313 return sprintf(buf, "%ld\n", (long)vid_from_reg(data->vid, data->vrm));
2315 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
2317 static ssize_t show_label(struct device *dev, struct device_attribute *attr,
2320 static const char * const labels[] = {
2326 static const char * const labels_it8721[] = {
2332 struct it87_data *data = dev_get_drvdata(dev);
2333 int nr = to_sensor_dev_attr(attr)->index;
2336 if (has_vin3_5v(data) && nr == 0)
2338 else if (has_12mv_adc(data) || has_10_9mv_adc(data) ||
2340 label = labels_it8721[nr];
2344 return sprintf(buf, "%s\n", label);
2346 static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0);
2347 static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1);
2348 static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 2);
2350 static SENSOR_DEVICE_ATTR(in9_label, S_IRUGO, show_label, NULL, 3);
2352 static umode_t it87_in_is_visible(struct kobject *kobj,
2353 struct attribute *attr, int index)
2355 struct device *dev = container_of(kobj, struct device, kobj);
2356 struct it87_data *data = dev_get_drvdata(dev);
2357 int i = index / 5; /* voltage index */
2358 int a = index % 5; /* attribute index */
2360 if (index >= 40) { /* in8 and higher only have input attributes */
2365 if (!(data->has_in & BIT(i)))
2368 if (a == 4 && !data->has_beep)
2374 static struct attribute *it87_attributes_in[] = {
2375 &sensor_dev_attr_in0_input.dev_attr.attr,
2376 &sensor_dev_attr_in0_min.dev_attr.attr,
2377 &sensor_dev_attr_in0_max.dev_attr.attr,
2378 &sensor_dev_attr_in0_alarm.dev_attr.attr,
2379 &sensor_dev_attr_in0_beep.dev_attr.attr, /* 4 */
2381 &sensor_dev_attr_in1_input.dev_attr.attr,
2382 &sensor_dev_attr_in1_min.dev_attr.attr,
2383 &sensor_dev_attr_in1_max.dev_attr.attr,
2384 &sensor_dev_attr_in1_alarm.dev_attr.attr,
2385 &sensor_dev_attr_in1_beep.dev_attr.attr, /* 9 */
2387 &sensor_dev_attr_in2_input.dev_attr.attr,
2388 &sensor_dev_attr_in2_min.dev_attr.attr,
2389 &sensor_dev_attr_in2_max.dev_attr.attr,
2390 &sensor_dev_attr_in2_alarm.dev_attr.attr,
2391 &sensor_dev_attr_in2_beep.dev_attr.attr, /* 14 */
2393 &sensor_dev_attr_in3_input.dev_attr.attr,
2394 &sensor_dev_attr_in3_min.dev_attr.attr,
2395 &sensor_dev_attr_in3_max.dev_attr.attr,
2396 &sensor_dev_attr_in3_alarm.dev_attr.attr,
2397 &sensor_dev_attr_in3_beep.dev_attr.attr, /* 19 */
2399 &sensor_dev_attr_in4_input.dev_attr.attr,
2400 &sensor_dev_attr_in4_min.dev_attr.attr,
2401 &sensor_dev_attr_in4_max.dev_attr.attr,
2402 &sensor_dev_attr_in4_alarm.dev_attr.attr,
2403 &sensor_dev_attr_in4_beep.dev_attr.attr, /* 24 */
2405 &sensor_dev_attr_in5_input.dev_attr.attr,
2406 &sensor_dev_attr_in5_min.dev_attr.attr,
2407 &sensor_dev_attr_in5_max.dev_attr.attr,
2408 &sensor_dev_attr_in5_alarm.dev_attr.attr,
2409 &sensor_dev_attr_in5_beep.dev_attr.attr, /* 29 */
2411 &sensor_dev_attr_in6_input.dev_attr.attr,
2412 &sensor_dev_attr_in6_min.dev_attr.attr,
2413 &sensor_dev_attr_in6_max.dev_attr.attr,
2414 &sensor_dev_attr_in6_alarm.dev_attr.attr,
2415 &sensor_dev_attr_in6_beep.dev_attr.attr, /* 34 */
2417 &sensor_dev_attr_in7_input.dev_attr.attr,
2418 &sensor_dev_attr_in7_min.dev_attr.attr,
2419 &sensor_dev_attr_in7_max.dev_attr.attr,
2420 &sensor_dev_attr_in7_alarm.dev_attr.attr,
2421 &sensor_dev_attr_in7_beep.dev_attr.attr, /* 39 */
2423 &sensor_dev_attr_in8_input.dev_attr.attr, /* 40 */
2424 &sensor_dev_attr_in9_input.dev_attr.attr, /* 41 */
2425 &sensor_dev_attr_in10_input.dev_attr.attr, /* 42 */
2426 &sensor_dev_attr_in11_input.dev_attr.attr, /* 43 */
2427 &sensor_dev_attr_in12_input.dev_attr.attr, /* 44 */
2431 static const struct attribute_group it87_group_in = {
2432 .attrs = it87_attributes_in,
2433 .is_visible = it87_in_is_visible,
2436 static umode_t it87_temp_is_visible(struct kobject *kobj,
2437 struct attribute *attr, int index)
2439 struct device *dev = container_of(kobj, struct device, kobj);
2440 struct it87_data *data = dev_get_drvdata(dev);
2441 int i = index / 7; /* temperature index */
2442 int a = index % 7; /* attribute index */
2444 if (!(data->has_temp & BIT(i)))
2447 if (a && i >= data->num_temp_limit)
2451 int type = get_temp_type(data, i);
2455 if (has_bank_sel(data))
2460 if (a == 5 && i >= data->num_temp_offset)
2463 if (a == 6 && !data->has_beep)
2469 static struct attribute *it87_attributes_temp[] = {
2470 &sensor_dev_attr_temp1_input.dev_attr.attr,
2471 &sensor_dev_attr_temp1_max.dev_attr.attr,
2472 &sensor_dev_attr_temp1_min.dev_attr.attr,
2473 &sensor_dev_attr_temp1_type.dev_attr.attr, /* 3 */
2474 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
2475 &sensor_dev_attr_temp1_offset.dev_attr.attr, /* 5 */
2476 &sensor_dev_attr_temp1_beep.dev_attr.attr, /* 6 */
2478 &sensor_dev_attr_temp2_input.dev_attr.attr, /* 7 */
2479 &sensor_dev_attr_temp2_max.dev_attr.attr,
2480 &sensor_dev_attr_temp2_min.dev_attr.attr,
2481 &sensor_dev_attr_temp2_type.dev_attr.attr,
2482 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
2483 &sensor_dev_attr_temp2_offset.dev_attr.attr,
2484 &sensor_dev_attr_temp2_beep.dev_attr.attr,
2486 &sensor_dev_attr_temp3_input.dev_attr.attr, /* 14 */
2487 &sensor_dev_attr_temp3_max.dev_attr.attr,
2488 &sensor_dev_attr_temp3_min.dev_attr.attr,
2489 &sensor_dev_attr_temp3_type.dev_attr.attr,
2490 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
2491 &sensor_dev_attr_temp3_offset.dev_attr.attr,
2492 &sensor_dev_attr_temp3_beep.dev_attr.attr,
2494 &sensor_dev_attr_temp4_input.dev_attr.attr, /* 21 */
2495 &sensor_dev_attr_temp4_max.dev_attr.attr,
2496 &sensor_dev_attr_temp4_min.dev_attr.attr,
2497 &sensor_dev_attr_temp4_type.dev_attr.attr,
2498 &sensor_dev_attr_temp4_alarm.dev_attr.attr,
2499 &sensor_dev_attr_temp4_offset.dev_attr.attr,
2500 &sensor_dev_attr_temp4_beep.dev_attr.attr,
2502 &sensor_dev_attr_temp5_input.dev_attr.attr,
2503 &sensor_dev_attr_temp5_max.dev_attr.attr,
2504 &sensor_dev_attr_temp5_min.dev_attr.attr,
2505 &sensor_dev_attr_temp5_type.dev_attr.attr,
2506 &sensor_dev_attr_temp5_alarm.dev_attr.attr,
2507 &sensor_dev_attr_temp5_offset.dev_attr.attr,
2508 &sensor_dev_attr_temp5_beep.dev_attr.attr,
2510 &sensor_dev_attr_temp6_input.dev_attr.attr,
2511 &sensor_dev_attr_temp6_max.dev_attr.attr,
2512 &sensor_dev_attr_temp6_min.dev_attr.attr,
2513 &sensor_dev_attr_temp6_type.dev_attr.attr,
2514 &sensor_dev_attr_temp6_alarm.dev_attr.attr,
2515 &sensor_dev_attr_temp6_offset.dev_attr.attr,
2516 &sensor_dev_attr_temp6_beep.dev_attr.attr,
2520 static const struct attribute_group it87_group_temp = {
2521 .attrs = it87_attributes_temp,
2522 .is_visible = it87_temp_is_visible,
2525 static umode_t it87_is_visible(struct kobject *kobj,
2526 struct attribute *attr, int index)
2528 struct device *dev = container_of(kobj, struct device, kobj);
2529 struct it87_data *data = dev_get_drvdata(dev);
2531 if ((index == 2 || index == 3) && !data->has_vid)
2534 if (index > 3 && !(data->in_internal & BIT(index - 4)))
2540 static struct attribute *it87_attributes[] = {
2541 &dev_attr_alarms.attr,
2542 &sensor_dev_attr_intrusion0_alarm.dev_attr.attr,
2543 &dev_attr_vrm.attr, /* 2 */
2544 &dev_attr_cpu0_vid.attr, /* 3 */
2545 &sensor_dev_attr_in3_label.dev_attr.attr, /* 4 .. 7 */
2546 &sensor_dev_attr_in7_label.dev_attr.attr,
2547 &sensor_dev_attr_in8_label.dev_attr.attr,
2548 &sensor_dev_attr_in9_label.dev_attr.attr,
2552 static const struct attribute_group it87_group = {
2553 .attrs = it87_attributes,
2554 .is_visible = it87_is_visible,
2557 static umode_t it87_fan_is_visible(struct kobject *kobj,
2558 struct attribute *attr, int index)
2560 struct device *dev = container_of(kobj, struct device, kobj);
2561 struct it87_data *data = dev_get_drvdata(dev);
2562 int i = index / 5; /* fan index */
2563 int a = index % 5; /* attribute index */
2565 if (index >= 15) { /* fan 4..6 don't have divisor attributes */
2566 i = (index - 15) / 4 + 3;
2567 a = (index - 15) % 4;
2570 if (!(data->has_fan & BIT(i)))
2573 if (a == 3) { /* beep */
2574 if (!data->has_beep)
2576 /* first fan beep attribute is writable */
2577 if (i == __ffs(data->has_fan))
2578 return attr->mode | S_IWUSR;
2581 if (a == 4 && has_16bit_fans(data)) /* divisor */
2587 static struct attribute *it87_attributes_fan[] = {
2588 &sensor_dev_attr_fan1_input.dev_attr.attr,
2589 &sensor_dev_attr_fan1_min.dev_attr.attr,
2590 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
2591 &sensor_dev_attr_fan1_beep.dev_attr.attr, /* 3 */
2592 &sensor_dev_attr_fan1_div.dev_attr.attr, /* 4 */
2594 &sensor_dev_attr_fan2_input.dev_attr.attr,
2595 &sensor_dev_attr_fan2_min.dev_attr.attr,
2596 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
2597 &sensor_dev_attr_fan2_beep.dev_attr.attr,
2598 &sensor_dev_attr_fan2_div.dev_attr.attr, /* 9 */
2600 &sensor_dev_attr_fan3_input.dev_attr.attr,
2601 &sensor_dev_attr_fan3_min.dev_attr.attr,
2602 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
2603 &sensor_dev_attr_fan3_beep.dev_attr.attr,
2604 &sensor_dev_attr_fan3_div.dev_attr.attr, /* 14 */
2606 &sensor_dev_attr_fan4_input.dev_attr.attr, /* 15 */
2607 &sensor_dev_attr_fan4_min.dev_attr.attr,
2608 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
2609 &sensor_dev_attr_fan4_beep.dev_attr.attr,
2611 &sensor_dev_attr_fan5_input.dev_attr.attr, /* 19 */
2612 &sensor_dev_attr_fan5_min.dev_attr.attr,
2613 &sensor_dev_attr_fan5_alarm.dev_attr.attr,
2614 &sensor_dev_attr_fan5_beep.dev_attr.attr,
2616 &sensor_dev_attr_fan6_input.dev_attr.attr, /* 23 */
2617 &sensor_dev_attr_fan6_min.dev_attr.attr,
2618 &sensor_dev_attr_fan6_alarm.dev_attr.attr,
2619 &sensor_dev_attr_fan6_beep.dev_attr.attr,
2623 static const struct attribute_group it87_group_fan = {
2624 .attrs = it87_attributes_fan,
2625 .is_visible = it87_fan_is_visible,
2628 static umode_t it87_pwm_is_visible(struct kobject *kobj,
2629 struct attribute *attr, int index)
2631 struct device *dev = container_of(kobj, struct device, kobj);
2632 struct it87_data *data = dev_get_drvdata(dev);
2633 int i = index / 4; /* pwm index */
2634 int a = index % 4; /* attribute index */
2636 if (!(data->has_pwm & BIT(i)))
2639 /* pwmX_auto_channels_temp is only writable if auto pwm is supported */
2640 if (a == 3 && (has_old_autopwm(data) || has_newer_autopwm(data)))
2641 return attr->mode | S_IWUSR;
2643 /* pwm2_freq is writable if there are two pwm frequency selects */
2644 if (has_pwm_freq2(data) && i == 1 && a == 2)
2645 return attr->mode | S_IWUSR;
2650 static struct attribute *it87_attributes_pwm[] = {
2651 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
2652 &sensor_dev_attr_pwm1.dev_attr.attr,
2653 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
2654 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
2656 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
2657 &sensor_dev_attr_pwm2.dev_attr.attr,
2658 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
2659 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
2661 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
2662 &sensor_dev_attr_pwm3.dev_attr.attr,
2663 &sensor_dev_attr_pwm3_freq.dev_attr.attr,
2664 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
2666 &sensor_dev_attr_pwm4_enable.dev_attr.attr,
2667 &sensor_dev_attr_pwm4.dev_attr.attr,
2668 &sensor_dev_attr_pwm4_freq.dev_attr.attr,
2669 &sensor_dev_attr_pwm4_auto_channels_temp.dev_attr.attr,
2671 &sensor_dev_attr_pwm5_enable.dev_attr.attr,
2672 &sensor_dev_attr_pwm5.dev_attr.attr,
2673 &sensor_dev_attr_pwm5_freq.dev_attr.attr,
2674 &sensor_dev_attr_pwm5_auto_channels_temp.dev_attr.attr,
2676 &sensor_dev_attr_pwm6_enable.dev_attr.attr,
2677 &sensor_dev_attr_pwm6.dev_attr.attr,
2678 &sensor_dev_attr_pwm6_freq.dev_attr.attr,
2679 &sensor_dev_attr_pwm6_auto_channels_temp.dev_attr.attr,
2684 static const struct attribute_group it87_group_pwm = {
2685 .attrs = it87_attributes_pwm,
2686 .is_visible = it87_pwm_is_visible,
2689 static umode_t it87_auto_pwm_is_visible(struct kobject *kobj,
2690 struct attribute *attr, int index)
2692 struct device *dev = container_of(kobj, struct device, kobj);
2693 struct it87_data *data = dev_get_drvdata(dev);
2694 int i = index / 11; /* pwm index */
2695 int a = index % 11; /* attribute index */
2697 if (index >= 33) { /* pwm 4..6 */
2698 i = (index - 33) / 6 + 3;
2699 a = (index - 33) % 6 + 4;
2702 if (!(data->has_pwm & BIT(i)))
2705 if (has_newer_autopwm(data)) {
2706 if (a < 4) /* no auto point pwm */
2708 if (a == 8) /* no auto_point4 */
2711 if (has_old_autopwm(data)) {
2712 if (a >= 9) /* no pwm_auto_start, pwm_auto_slope */
2719 static struct attribute *it87_attributes_auto_pwm[] = {
2720 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
2721 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
2722 &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr,
2723 &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr,
2724 &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
2725 &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr,
2726 &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr,
2727 &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr,
2728 &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr,
2729 &sensor_dev_attr_pwm1_auto_start.dev_attr.attr,
2730 &sensor_dev_attr_pwm1_auto_slope.dev_attr.attr,
2732 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr, /* 11 */
2733 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
2734 &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr,
2735 &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr,
2736 &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr,
2737 &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr,
2738 &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr,
2739 &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr,
2740 &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr,
2741 &sensor_dev_attr_pwm2_auto_start.dev_attr.attr,
2742 &sensor_dev_attr_pwm2_auto_slope.dev_attr.attr,
2744 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr, /* 22 */
2745 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
2746 &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr,
2747 &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr,
2748 &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr,
2749 &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr,
2750 &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr,
2751 &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr,
2752 &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr,
2753 &sensor_dev_attr_pwm3_auto_start.dev_attr.attr,
2754 &sensor_dev_attr_pwm3_auto_slope.dev_attr.attr,
2756 &sensor_dev_attr_pwm4_auto_point1_temp.dev_attr.attr, /* 33 */
2757 &sensor_dev_attr_pwm4_auto_point1_temp_hyst.dev_attr.attr,
2758 &sensor_dev_attr_pwm4_auto_point2_temp.dev_attr.attr,
2759 &sensor_dev_attr_pwm4_auto_point3_temp.dev_attr.attr,
2760 &sensor_dev_attr_pwm4_auto_start.dev_attr.attr,
2761 &sensor_dev_attr_pwm4_auto_slope.dev_attr.attr,
2763 &sensor_dev_attr_pwm5_auto_point1_temp.dev_attr.attr,
2764 &sensor_dev_attr_pwm5_auto_point1_temp_hyst.dev_attr.attr,
2765 &sensor_dev_attr_pwm5_auto_point2_temp.dev_attr.attr,
2766 &sensor_dev_attr_pwm5_auto_point3_temp.dev_attr.attr,
2767 &sensor_dev_attr_pwm5_auto_start.dev_attr.attr,
2768 &sensor_dev_attr_pwm5_auto_slope.dev_attr.attr,
2770 &sensor_dev_attr_pwm6_auto_point1_temp.dev_attr.attr,
2771 &sensor_dev_attr_pwm6_auto_point1_temp_hyst.dev_attr.attr,
2772 &sensor_dev_attr_pwm6_auto_point2_temp.dev_attr.attr,
2773 &sensor_dev_attr_pwm6_auto_point3_temp.dev_attr.attr,
2774 &sensor_dev_attr_pwm6_auto_start.dev_attr.attr,
2775 &sensor_dev_attr_pwm6_auto_slope.dev_attr.attr,
2780 static const struct attribute_group it87_group_auto_pwm = {
2781 .attrs = it87_attributes_auto_pwm,
2782 .is_visible = it87_auto_pwm_is_visible,
2785 /* SuperIO detection - will change isa_address if a chip is found */
2786 static int __init it87_find(int sioaddr, unsigned short *address,
2787 struct it87_sio_data *sio_data)
2789 const struct it87_devices *config;
2794 err = superio_enter(sioaddr);
2799 chip_type = superio_inw(sioaddr, DEVID);
2800 if (chip_type == 0xffff)
2804 chip_type = force_id;
2806 switch (chip_type) {
2808 sio_data->type = it87;
2811 sio_data->type = it8712;
2815 sio_data->type = it8716;
2818 sio_data->type = it8718;
2821 sio_data->type = it8720;
2824 sio_data->type = it8721;
2827 sio_data->type = it8728;
2830 sio_data->type = it8732;
2833 sio_data->type = it8792;
2835 * Disabling configuration mode on IT8792E can result in system
2836 * hang-ups and access failures to the Super-IO chip at the
2837 * second SIO address. Never exit configuration mode on this
2838 * chip to avoid the problem.
2843 sio_data->type = it8771;
2846 sio_data->type = it8772;
2849 sio_data->type = it8781;
2852 sio_data->type = it8782;
2855 sio_data->type = it8783;
2858 sio_data->type = it8786;
2861 sio_data->type = it8790;
2865 sio_data->type = it8603;
2868 sio_data->type = it8607;
2871 sio_data->type = it8613;
2874 sio_data->type = it8620;
2877 sio_data->type = it8622;
2880 sio_data->type = it8625;
2883 sio_data->type = it8628;
2886 sio_data->type = it8655;
2889 sio_data->type = it8665;
2892 sio_data->type = it8686;
2894 case 0xffff: /* No device at all */
2897 pr_debug("Unsupported chip (DEVID=0x%x)\n", chip_type);
2901 superio_select(sioaddr, PME);
2902 if (!(superio_inb(sioaddr, IT87_ACT_REG) & 0x01)) {
2903 pr_info("Device not activated, skipping\n");
2907 *address = superio_inw(sioaddr, IT87_BASE_REG) & ~(IT87_EXTENT - 1);
2908 if (*address == 0) {
2909 pr_info("Base address not set, skipping\n");
2914 sio_data->revision = superio_inb(sioaddr, DEVREV) & 0x0f;
2915 pr_info("Found IT%04x%s chip at 0x%x, revision %d\n", chip_type,
2916 it87_devices[sio_data->type].suffix,
2917 *address, sio_data->revision);
2919 config = &it87_devices[sio_data->type];
2921 /* in7 (VSB or VCCH5V) is always internal on some chips */
2922 if (has_in7_internal(config))
2923 sio_data->internal |= BIT(1);
2925 /* in8 (Vbat) is always internal */
2926 sio_data->internal |= BIT(2);
2928 /* in9 (AVCC3), always internal if supported */
2929 if (has_avcc3(config))
2930 sio_data->internal |= BIT(3); /* in9 is AVCC */
2932 sio_data->skip_in |= BIT(9);
2934 if (!has_four_pwm(config))
2935 sio_data->skip_pwm |= BIT(3) | BIT(4) | BIT(5);
2936 else if (!has_five_pwm(config))
2937 sio_data->skip_pwm |= BIT(4) | BIT(5);
2938 else if (!has_six_pwm(config))
2939 sio_data->skip_pwm |= BIT(5);
2941 if (!has_vid(config))
2942 sio_data->skip_vid = 1;
2944 /* Read GPIO config and VID value from LDN 7 (GPIO) */
2945 if (sio_data->type == it87) {
2946 /* The IT8705F has a different LD number for GPIO */
2947 superio_select(sioaddr, 5);
2948 sio_data->beep_pin = superio_inb(sioaddr,
2949 IT87_SIO_BEEP_PIN_REG) & 0x3f;
2950 } else if (sio_data->type == it8783) {
2951 int reg25, reg27, reg2a, reg2c, regef;
2953 superio_select(sioaddr, GPIO);
2955 reg25 = superio_inb(sioaddr, IT87_SIO_GPIO1_REG);
2956 reg27 = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
2957 reg2a = superio_inb(sioaddr, IT87_SIO_PINX1_REG);
2958 reg2c = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
2959 regef = superio_inb(sioaddr, IT87_SIO_SPI_REG);
2961 /* Check if fan3 is there or not */
2962 if ((reg27 & BIT(0)) || !(reg2c & BIT(2)))
2963 sio_data->skip_fan |= BIT(2);
2964 if ((reg25 & BIT(4)) ||
2965 (!(reg2a & BIT(1)) && (regef & BIT(0))))
2966 sio_data->skip_pwm |= BIT(2);
2968 /* Check if fan2 is there or not */
2970 sio_data->skip_fan |= BIT(1);
2972 sio_data->skip_pwm |= BIT(1);
2975 if ((reg27 & BIT(0)) || (reg2c & BIT(2)))
2976 sio_data->skip_in |= BIT(5); /* No VIN5 */
2980 sio_data->skip_in |= BIT(6); /* No VIN6 */
2984 * Does not depend on bit 2 of Reg2C, contrary to datasheet.
2986 if (reg27 & BIT(2)) {
2988 * The data sheet is a bit unclear regarding the
2989 * internal voltage divider for VCCH5V. It says
2990 * "This bit enables and switches VIN7 (pin 91) to the
2991 * internal voltage divider for VCCH5V".
2992 * This is different to other chips, where the internal
2993 * voltage divider would connect VIN7 to an internal
2994 * voltage source. Maybe that is the case here as well.
2996 * Since we don't know for sure, re-route it if that is
2997 * not the case, and ask the user to report if the
2998 * resulting voltage is sane.
3000 if (!(reg2c & BIT(1))) {
3002 superio_outb(sioaddr, IT87_SIO_PINX2_REG,
3004 pr_notice("Routing internal VCCH5V to in7.\n");
3006 pr_notice("in7 routed to internal voltage divider, with external pin disabled.\n");
3007 pr_notice("Please report if it displays a reasonable voltage.\n");
3011 sio_data->internal |= BIT(0);
3013 sio_data->internal |= BIT(1);
3015 sio_data->beep_pin = superio_inb(sioaddr,
3016 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3017 } else if (sio_data->type == it8603 || sio_data->type == it8607) {
3020 superio_select(sioaddr, GPIO);
3022 reg27 = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3024 /* Check if fan3 is there or not */
3026 sio_data->skip_pwm |= BIT(2);
3028 sio_data->skip_fan |= BIT(2);
3030 /* Check if fan2 is there or not */
3031 reg29 = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3033 sio_data->skip_pwm |= BIT(1);
3035 sio_data->skip_fan |= BIT(1);
3037 switch (sio_data->type) {
3039 sio_data->skip_in |= BIT(5); /* No VIN5 */
3040 sio_data->skip_in |= BIT(6); /* No VIN6 */
3043 sio_data->skip_pwm |= BIT(0);/* No fan1 */
3044 sio_data->skip_fan |= BIT(0);
3049 sio_data->beep_pin = superio_inb(sioaddr,
3050 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3051 } else if (sio_data->type == it8613) {
3052 int reg27, reg29, reg2a;
3054 superio_select(sioaddr, GPIO);
3056 /* Check for pwm3, fan3, pwm5, fan5 */
3057 reg27 = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3059 sio_data->skip_fan |= BIT(4);
3061 sio_data->skip_pwm |= BIT(4);
3063 sio_data->skip_pwm |= BIT(2);
3065 sio_data->skip_fan |= BIT(2);
3067 /* Check for pwm2, fan2 */
3068 reg29 = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3070 sio_data->skip_pwm |= BIT(1);
3072 sio_data->skip_fan |= BIT(1);
3074 /* Check for pwm4, fan4 */
3075 reg2a = superio_inb(sioaddr, IT87_SIO_PINX1_REG);
3076 if (!(reg2a & BIT(0)) || (reg29 & BIT(7))) {
3077 sio_data->skip_fan |= BIT(3);
3078 sio_data->skip_pwm |= BIT(3);
3081 sio_data->skip_pwm |= BIT(0); /* No pwm1 */
3082 sio_data->skip_fan |= BIT(0); /* No fan1 */
3083 sio_data->skip_in |= BIT(3); /* No VIN3 */
3084 sio_data->skip_in |= BIT(6); /* No VIN6 */
3086 sio_data->beep_pin = superio_inb(sioaddr,
3087 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3088 } else if (sio_data->type == it8620 || sio_data->type == it8628 ||
3089 sio_data->type == it8686) {
3092 superio_select(sioaddr, GPIO);
3094 /* Check for pwm5 */
3095 reg = superio_inb(sioaddr, IT87_SIO_GPIO1_REG);
3097 sio_data->skip_pwm |= BIT(4);
3099 /* Check for fan4, fan5 */
3100 reg = superio_inb(sioaddr, IT87_SIO_GPIO2_REG);
3101 if (!(reg & BIT(5)))
3102 sio_data->skip_fan |= BIT(3);
3103 if (!(reg & BIT(4)))
3104 sio_data->skip_fan |= BIT(4);
3106 /* Check for pwm3, fan3 */
3107 reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3109 sio_data->skip_pwm |= BIT(2);
3111 sio_data->skip_fan |= BIT(2);
3113 /* Check for pwm4 */
3114 reg = superio_inb(sioaddr, IT87_SIO_GPIO4_REG);
3116 sio_data->skip_pwm |= BIT(3);
3118 /* Check for pwm2, fan2 */
3119 reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3121 sio_data->skip_pwm |= BIT(1);
3123 sio_data->skip_fan |= BIT(1);
3124 /* Check for pwm6, fan6 */
3125 if (!(reg & BIT(7))) {
3126 sio_data->skip_pwm |= BIT(5);
3127 sio_data->skip_fan |= BIT(5);
3130 /* Check if AVCC is on VIN3 */
3131 reg = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
3133 /* For it8686, the bit just enables AVCC3 */
3134 if (sio_data->type != it8686)
3135 sio_data->internal |= BIT(0);
3137 sio_data->internal &= ~BIT(3);
3138 sio_data->skip_in |= BIT(9);
3141 sio_data->beep_pin = superio_inb(sioaddr,
3142 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3143 } else if (sio_data->type == it8622) {
3146 superio_select(sioaddr, GPIO);
3148 /* Check for pwm4, fan4 */
3149 reg = superio_inb(sioaddr, IT87_SIO_GPIO1_REG);
3151 sio_data->skip_fan |= BIT(3);
3153 sio_data->skip_pwm |= BIT(3);
3155 /* Check for pwm3, fan3, pwm5, fan5 */
3156 reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3158 sio_data->skip_pwm |= BIT(2);
3160 sio_data->skip_fan |= BIT(2);
3162 sio_data->skip_pwm |= BIT(4);
3164 sio_data->skip_fan |= BIT(4);
3166 /* Check for pwm2, fan2 */
3167 reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3169 sio_data->skip_pwm |= BIT(1);
3171 sio_data->skip_fan |= BIT(1);
3173 /* Check for AVCC */
3174 reg = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
3175 if (!(reg & BIT(0)))
3176 sio_data->skip_in |= BIT(9);
3178 sio_data->beep_pin = superio_inb(sioaddr,
3179 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3180 } else if (sio_data->type == it8732) {
3183 superio_select(sioaddr, GPIO);
3185 /* Check for pwm2, fan2 */
3186 reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3188 sio_data->skip_pwm |= BIT(1);
3190 sio_data->skip_fan |= BIT(1);
3192 /* Check for pwm3, fan3, fan4 */
3193 reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3195 sio_data->skip_pwm |= BIT(2);
3197 sio_data->skip_fan |= BIT(2);
3199 sio_data->skip_fan |= BIT(3);
3201 /* Check if AVCC is on VIN3 */
3202 reg = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
3204 sio_data->internal |= BIT(0);
3206 sio_data->beep_pin = superio_inb(sioaddr,
3207 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3208 } else if (sio_data->type == it8655) {
3211 superio_select(sioaddr, GPIO);
3213 /* Check for pwm2 */
3214 reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3216 sio_data->skip_pwm |= BIT(1);
3218 /* Check for fan2 */
3219 reg = superio_inb(sioaddr, IT87_SIO_PINX4_REG);
3221 sio_data->skip_fan |= BIT(1);
3223 /* Check for pwm3, fan3 */
3224 reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3226 sio_data->skip_pwm |= BIT(2);
3228 sio_data->skip_fan |= BIT(2);
3230 sio_data->beep_pin = superio_inb(sioaddr,
3231 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3232 } else if (sio_data->type == it8665 || sio_data->type == it8625) {
3233 int reg27, reg29, reg2d, regd3;
3235 superio_select(sioaddr, GPIO);
3237 reg27 = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3238 reg29 = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3239 reg2d = superio_inb(sioaddr, IT87_SIO_PINX4_REG);
3240 regd3 = superio_inb(sioaddr, IT87_SIO_GPIO9_REG);
3242 /* Check for pwm2, fan2 */
3244 sio_data->skip_pwm |= BIT(1);
3246 sio_data->skip_fan |= BIT(1);
3248 /* Check for pwm3, fan3 */
3250 sio_data->skip_pwm |= BIT(2);
3252 sio_data->skip_fan |= BIT(2);
3254 /* Check for pwm4, fan4, pwm5, fan5 */
3255 if (sio_data->type == it8625) {
3256 int reg25 = superio_inb(sioaddr, IT87_SIO_GPIO1_REG);
3259 sio_data->skip_fan |= BIT(3);
3261 sio_data->skip_pwm |= BIT(3);
3263 sio_data->skip_pwm |= BIT(4);
3265 sio_data->skip_fan |= BIT(4);
3267 int reg26 = superio_inb(sioaddr, IT87_SIO_GPIO2_REG);
3270 sio_data->skip_pwm |= BIT(3);
3272 sio_data->skip_fan |= BIT(3);
3274 sio_data->skip_pwm |= BIT(4);
3275 if (!(reg26 & BIT(4)))
3276 sio_data->skip_fan |= BIT(4);
3279 /* Check for pwm6, fan6 */
3281 sio_data->skip_pwm |= BIT(5);
3283 sio_data->skip_fan |= BIT(5);
3285 sio_data->beep_pin = superio_inb(sioaddr,
3286 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3291 superio_select(sioaddr, GPIO);
3293 /* Check for fan4, fan5 */
3294 if (has_five_fans(config)) {
3295 reg = superio_inb(sioaddr, IT87_SIO_GPIO2_REG);
3296 switch (sio_data->type) {
3299 sio_data->skip_fan |= BIT(3);
3301 sio_data->skip_fan |= BIT(4);
3306 if (!(reg & BIT(5)))
3307 sio_data->skip_fan |= BIT(3);
3308 if (!(reg & BIT(4)))
3309 sio_data->skip_fan |= BIT(4);
3316 reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
3317 if (!sio_data->skip_vid) {
3318 /* We need at least 4 VID pins */
3320 pr_info("VID is disabled (pins used for GPIO)\n");
3321 sio_data->skip_vid = 1;
3325 /* Check if fan3 is there or not */
3327 sio_data->skip_pwm |= BIT(2);
3329 sio_data->skip_fan |= BIT(2);
3331 /* Check if fan2 is there or not */
3332 reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
3334 sio_data->skip_pwm |= BIT(1);
3336 sio_data->skip_fan |= BIT(1);
3338 if ((sio_data->type == it8718 || sio_data->type == it8720) &&
3339 !(sio_data->skip_vid))
3340 sio_data->vid_value = superio_inb(sioaddr,
3343 reg = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
3345 uart6 = sio_data->type == it8782 && (reg & BIT(2));
3348 * The IT8720F has no VIN7 pin, so VCCH should always be
3349 * routed internally to VIN7 with an internal divider.
3350 * Curiously, there still is a configuration bit to control
3351 * this, which means it can be set incorrectly. And even
3352 * more curiously, many boards out there are improperly
3353 * configured, even though the IT8720F datasheet claims
3354 * that the internal routing of VCCH to VIN7 is the default
3355 * setting. So we force the internal routing in this case.
3357 * On IT8782F, VIN7 is multiplexed with one of the UART6 pins.
3358 * If UART6 is enabled, re-route VIN7 to the internal divider
3359 * if that is not already the case.
3361 if ((sio_data->type == it8720 || uart6) && !(reg & BIT(1))) {
3363 superio_outb(sioaddr, IT87_SIO_PINX2_REG, reg);
3364 pr_notice("Routing internal VCCH to in7\n");
3367 sio_data->internal |= BIT(0);
3369 sio_data->internal |= BIT(1);
3372 * On IT8782F, UART6 pins overlap with VIN5, VIN6, and VIN7.
3373 * While VIN7 can be routed to the internal voltage divider,
3374 * VIN5 and VIN6 are not available if UART6 is enabled.
3376 * Also, temp3 is not available if UART6 is enabled and TEMPIN3
3377 * is the temperature source. Since we can not read the
3378 * temperature source here, skip_temp is preliminary.
3381 sio_data->skip_in |= BIT(5) | BIT(6);
3382 sio_data->skip_temp |= BIT(2);
3385 sio_data->beep_pin = superio_inb(sioaddr,
3386 IT87_SIO_BEEP_PIN_REG) & 0x3f;
3388 if (sio_data->beep_pin)
3389 pr_info("Beeping is supported\n");
3392 superio_exit(sioaddr, doexit);
3396 static void it87_init_regs(struct platform_device *pdev)
3398 struct it87_data *data = platform_get_drvdata(pdev);
3400 /* Initialize chip specific register pointers */
3401 switch (data->type) {
3404 data->REG_FAN = IT87_REG_FAN;
3405 data->REG_FANX = IT87_REG_FANX;
3406 data->REG_FAN_MIN = IT87_REG_FAN_MIN;
3407 data->REG_FANX_MIN = IT87_REG_FANX_MIN;
3408 data->REG_PWM = IT87_REG_PWM;
3409 data->REG_TEMP_OFFSET = IT87_REG_TEMP_OFFSET_8686;
3410 data->REG_TEMP_LOW = IT87_REG_TEMP_LOW_8686;
3411 data->REG_TEMP_HIGH = IT87_REG_TEMP_HIGH_8686;
3416 data->REG_FAN = IT87_REG_FAN_8665;
3417 data->REG_FANX = IT87_REG_FANX_8665;
3418 data->REG_FAN_MIN = IT87_REG_FAN_MIN_8665;
3419 data->REG_FANX_MIN = IT87_REG_FANX_MIN_8665;
3420 data->REG_PWM = IT87_REG_PWM_8665;
3421 data->REG_TEMP_OFFSET = IT87_REG_TEMP_OFFSET;
3422 data->REG_TEMP_LOW = IT87_REG_TEMP_LOW;
3423 data->REG_TEMP_HIGH = IT87_REG_TEMP_HIGH;
3426 data->REG_FAN = IT87_REG_FAN;
3427 data->REG_FANX = IT87_REG_FANX;
3428 data->REG_FAN_MIN = IT87_REG_FAN_MIN;
3429 data->REG_FANX_MIN = IT87_REG_FANX_MIN;
3430 data->REG_PWM = IT87_REG_PWM_8665;
3431 data->REG_TEMP_OFFSET = IT87_REG_TEMP_OFFSET;
3432 data->REG_TEMP_LOW = IT87_REG_TEMP_LOW;
3433 data->REG_TEMP_HIGH = IT87_REG_TEMP_HIGH;
3436 data->REG_FAN = IT87_REG_FAN;
3437 data->REG_FANX = IT87_REG_FANX;
3438 data->REG_FAN_MIN = IT87_REG_FAN_MIN;
3439 data->REG_FANX_MIN = IT87_REG_FANX_MIN;
3440 data->REG_PWM = IT87_REG_PWM_8665;
3441 data->REG_TEMP_OFFSET = IT87_REG_TEMP_OFFSET;
3442 data->REG_TEMP_LOW = IT87_REG_TEMP_LOW;
3443 data->REG_TEMP_HIGH = IT87_REG_TEMP_HIGH;
3446 data->REG_FAN = IT87_REG_FAN;
3447 data->REG_FANX = IT87_REG_FANX;
3448 data->REG_FAN_MIN = IT87_REG_FAN_MIN;
3449 data->REG_FANX_MIN = IT87_REG_FANX_MIN;
3450 data->REG_PWM = IT87_REG_PWM;
3451 data->REG_TEMP_OFFSET = IT87_REG_TEMP_OFFSET;
3452 data->REG_TEMP_LOW = IT87_REG_TEMP_LOW;
3453 data->REG_TEMP_HIGH = IT87_REG_TEMP_HIGH;
3458 /* Called when we have found a new IT87. */
3459 static void it87_init_device(struct platform_device *pdev)
3461 struct it87_sio_data *sio_data = dev_get_platdata(&pdev->dev);
3462 struct it87_data *data = platform_get_drvdata(pdev);
3467 * For each PWM channel:
3468 * - If it is in automatic mode, setting to manual mode should set
3469 * the fan to full speed by default.
3470 * - If it is in manual mode, we need a mapping to temperature
3471 * channels to use when later setting to automatic mode later.
3472 * Use a 1:1 mapping by default (we are clueless.)
3473 * In both cases, the value can (and should) be changed by the user
3474 * prior to switching to a different mode.
3475 * Note that this is no longer needed for the IT8721F and later, as
3476 * these have separate registers for the temperature mapping and the
3477 * manual duty cycle.
3479 for (i = 0; i < NUM_AUTO_PWM; i++) {
3480 data->pwm_temp_map[i] = i;
3481 data->pwm_duty[i] = 0x7f; /* Full speed */
3482 data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */
3486 * Some chips seem to have default value 0xff for all limit
3487 * registers. For low voltage limits it makes no sense and triggers
3488 * alarms, so change to 0 instead. For high temperature limits, it
3489 * means -1 degree C, which surprisingly doesn't trigger an alarm,
3490 * but is still confusing, so change to 127 degrees C.
3492 for (i = 0; i < NUM_VIN_LIMIT; i++) {
3493 tmp = it87_read_value(data, IT87_REG_VIN_MIN(i));
3495 it87_write_value(data, IT87_REG_VIN_MIN(i), 0);
3497 for (i = 0; i < data->num_temp_limit; i++) {
3498 tmp = it87_read_value(data, data->REG_TEMP_HIGH[i]);
3500 it87_write_value(data, data->REG_TEMP_HIGH[i], 127);
3504 * Temperature channels are not forcibly enabled, as they can be
3505 * set to two different sensor types and we can't guess which one
3506 * is correct for a given system. These channels can be enabled at
3507 * run-time through the temp{1-3}_type sysfs accessors if needed.
3510 /* Check if voltage monitors are reset manually or by some reason */
3511 tmp = it87_read_value(data, IT87_REG_VIN_ENABLE);
3512 if ((tmp & 0xff) == 0) {
3513 /* Enable all voltage monitors */
3514 it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff);
3517 /* Check if tachometers are reset manually or by some reason */
3518 mask = 0x70 & ~(sio_data->skip_fan << 4);
3519 data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL);
3520 if ((data->fan_main_ctrl & mask) == 0) {
3521 /* Enable all fan tachometers */
3522 data->fan_main_ctrl |= mask;
3523 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
3524 data->fan_main_ctrl);
3526 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
3528 tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
3530 /* Set tachometers to 16-bit mode if needed */
3531 if (has_fan16_config(data)) {
3532 if (~tmp & 0x07 & data->has_fan) {
3534 "Setting fan1-3 to 16-bit mode\n");
3535 it87_write_value(data, IT87_REG_FAN_16BIT,
3540 /* Check for additional fans */
3541 if (has_four_fans(data) && (tmp & BIT(4)))
3542 data->has_fan |= BIT(3); /* fan4 enabled */
3543 if (has_five_fans(data) && (tmp & BIT(5)))
3544 data->has_fan |= BIT(4); /* fan5 enabled */
3545 if (has_six_fans(data)) {
3546 switch (data->type) {
3551 data->has_fan |= BIT(5); /* fan6 enabled */
3555 tmp = it87_read_value(data, IT87_REG_FAN_DIV);
3557 data->has_fan |= BIT(5); /* fan6 enabled */
3564 /* Fan input pins may be used for alternative functions */
3565 data->has_fan &= ~sio_data->skip_fan;
3567 /* Check if pwm6 is enabled */
3568 if (has_six_pwm(data)) {
3569 switch (data->type) {
3572 tmp = it87_read_value(data, IT87_REG_FAN_DIV);
3573 if (!(tmp & BIT(3)))
3574 sio_data->skip_pwm |= BIT(5);
3581 /* Start monitoring */
3582 it87_write_value(data, IT87_REG_CONFIG,
3583 (it87_read_value(data, IT87_REG_CONFIG) & 0x3e)
3584 | (update_vbat ? 0x41 : 0x01));
3587 /* Return 1 if and only if the PWM interface is safe to use */
3588 static int it87_check_pwm(struct device *dev)
3590 struct it87_data *data = dev_get_drvdata(dev);
3592 * Some BIOSes fail to correctly configure the IT87 fans. All fans off
3593 * and polarity set to active low is sign that this is the case so we
3594 * disable pwm control to protect the user.
3596 int tmp = it87_read_value(data, IT87_REG_FAN_CTL);
3598 if ((tmp & 0x87) == 0) {
3599 if (fix_pwm_polarity) {
3601 * The user asks us to attempt a chip reconfiguration.
3602 * This means switching to active high polarity and
3603 * inverting all fan speed values.
3608 for (i = 0; i < ARRAY_SIZE(pwm); i++)
3609 pwm[i] = it87_read_value(data,
3613 * If any fan is in automatic pwm mode, the polarity
3614 * might be correct, as suspicious as it seems, so we
3615 * better don't change anything (but still disable the
3618 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
3620 "Reconfiguring PWM to active high polarity\n");
3621 it87_write_value(data, IT87_REG_FAN_CTL,
3623 for (i = 0; i < 3; i++)
3624 it87_write_value(data,
3631 "PWM configuration is too broken to be fixed\n");
3635 "Detected broken BIOS defaults, disabling PWM interface\n");
3637 } else if (fix_pwm_polarity) {
3639 "PWM configuration looks sane, won't touch\n");
3645 static int it87_probe(struct platform_device *pdev)
3647 struct it87_data *data;
3648 struct resource *res;
3649 struct device *dev = &pdev->dev;
3650 struct it87_sio_data *sio_data = dev_get_platdata(dev);
3651 int enable_pwm_interface;
3652 struct device *hwmon_dev;
3654 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
3655 if (!devm_request_region(&pdev->dev, res->start, IT87_EC_EXTENT,
3657 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
3658 (unsigned long)res->start,
3659 (unsigned long)(res->start + IT87_EC_EXTENT - 1));
3663 data = devm_kzalloc(&pdev->dev, sizeof(struct it87_data), GFP_KERNEL);
3667 data->addr = res->start;
3668 data->type = sio_data->type;
3669 data->features = it87_devices[sio_data->type].features;
3670 data->num_temp_limit = it87_devices[sio_data->type].num_temp_limit;
3671 data->num_temp_offset = it87_devices[sio_data->type].num_temp_offset;
3672 data->peci_mask = it87_devices[sio_data->type].peci_mask;
3673 data->old_peci_mask = it87_devices[sio_data->type].old_peci_mask;
3677 * IT8705F Datasheet 0.4.1, 3h == Version G.
3678 * IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J.
3679 * These are the first revisions with 16-bit tachometer support.
3681 switch (data->type) {
3683 if (sio_data->revision >= 0x03) {
3684 data->features &= ~FEAT_OLD_AUTOPWM;
3685 data->features |= FEAT_FAN16_CONFIG | FEAT_16BIT_FANS;
3689 if (sio_data->revision >= 0x08) {
3690 data->features &= ~FEAT_OLD_AUTOPWM;
3691 data->features |= FEAT_FAN16_CONFIG | FEAT_16BIT_FANS |
3699 /* Now, we do the remaining detection. */
3700 if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80) ||
3701 it87_read_value(data, IT87_REG_CHIPID) != 0x90)
3704 platform_set_drvdata(pdev, data);
3706 mutex_init(&data->update_lock);
3708 /* Initialize register pointers */
3709 it87_init_regs(pdev);
3711 /* Check PWM configuration */
3712 enable_pwm_interface = it87_check_pwm(dev);
3714 /* Starting with IT8721F, we handle scaling of internal voltages */
3715 if (has_scaling(data)) {
3716 if (sio_data->internal & BIT(0))
3717 data->in_scaled |= BIT(3); /* in3 is AVCC */
3718 if (sio_data->internal & BIT(1))
3719 data->in_scaled |= BIT(7); /* in7 is VSB */
3720 if (sio_data->internal & BIT(2))
3721 data->in_scaled |= BIT(8); /* in8 is Vbat */
3722 if (sio_data->internal & BIT(3))
3723 data->in_scaled |= BIT(9); /* in9 is AVCC */
3724 } else if (sio_data->type == it8781 || sio_data->type == it8782 ||
3725 sio_data->type == it8783) {
3726 if (sio_data->internal & BIT(0))
3727 data->in_scaled |= BIT(3); /* in3 is VCC5V */
3728 if (sio_data->internal & BIT(1))
3729 data->in_scaled |= BIT(7); /* in7 is VCCH5V */
3732 data->has_temp = 0x07;
3733 if (sio_data->skip_temp & BIT(2)) {
3734 if (sio_data->type == it8782 &&
3735 !(it87_read_value(data, IT87_REG_TEMP_EXTRA) & 0x80))
3736 data->has_temp &= ~BIT(2);
3739 data->in_internal = sio_data->internal;
3740 data->has_in = 0x3ff & ~sio_data->skip_in;
3742 if (has_six_temp(data)) {
3743 u8 reg = it87_read_value(data, IT87_REG_TEMP456_ENABLE);
3745 /* Check for additional temperature sensors */
3746 if ((reg & 0x03) >= 0x02)
3747 data->has_temp |= BIT(3);
3748 if (((reg >> 2) & 0x03) >= 0x02)
3749 data->has_temp |= BIT(4);
3750 if (((reg >> 4) & 0x03) >= 0x02)
3751 data->has_temp |= BIT(5);
3753 /* Check for additional voltage sensors */
3754 if ((reg & 0x03) == 0x01)
3755 data->has_in |= BIT(10);
3756 if (((reg >> 2) & 0x03) == 0x01)
3757 data->has_in |= BIT(11);
3758 if (((reg >> 4) & 0x03) == 0x01)
3759 data->has_in |= BIT(12);
3762 data->has_beep = !!sio_data->beep_pin;
3764 /* Initialize the IT87 chip */
3765 it87_init_device(pdev);
3767 if (!sio_data->skip_vid) {
3768 data->has_vid = true;
3769 data->vrm = vid_which_vrm();
3770 /* VID reading from Super-I/O config space if available */
3771 data->vid = sio_data->vid_value;
3774 /* Prepare for sysfs hooks */
3775 data->groups[0] = &it87_group;
3776 data->groups[1] = &it87_group_in;
3777 data->groups[2] = &it87_group_temp;
3778 data->groups[3] = &it87_group_fan;
3780 if (enable_pwm_interface) {
3781 data->has_pwm = BIT(ARRAY_SIZE(IT87_REG_PWM)) - 1;
3782 data->has_pwm &= ~sio_data->skip_pwm;
3784 data->groups[4] = &it87_group_pwm;
3785 if (has_old_autopwm(data) || has_newer_autopwm(data))
3786 data->groups[5] = &it87_group_auto_pwm;
3789 hwmon_dev = devm_hwmon_device_register_with_groups(dev,
3790 it87_devices[sio_data->type].name,
3791 data, data->groups);
3792 return PTR_ERR_OR_ZERO(hwmon_dev);
3795 static struct platform_driver it87_driver = {
3799 .probe = it87_probe,
3802 static int __init it87_device_add(int index, unsigned short address,
3803 const struct it87_sio_data *sio_data)
3805 struct platform_device *pdev;
3806 struct resource res = {
3807 .start = address + IT87_EC_OFFSET,
3808 .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1,
3810 .flags = IORESOURCE_IO,
3814 err = acpi_check_resource_conflict(&res);
3818 pdev = platform_device_alloc(DRVNAME, address);
3822 err = platform_device_add_resources(pdev, &res, 1);
3824 pr_err("Device resource addition failed (%d)\n", err);
3825 goto exit_device_put;
3828 err = platform_device_add_data(pdev, sio_data,
3829 sizeof(struct it87_sio_data));
3831 pr_err("Platform data allocation failed\n");
3832 goto exit_device_put;
3835 err = platform_device_add(pdev);
3837 pr_err("Device addition failed (%d)\n", err);
3838 goto exit_device_put;
3841 it87_pdev[index] = pdev;
3845 platform_device_put(pdev);
3849 struct it87_dmi_data {
3850 char *sio_mutex; /* SIO ACPI mutex */
3851 u8 skip_pwm; /* pwm channels to skip for this board */
3855 * On Gigabyte AB350 and AX370 boards, accesses to the Super-IO chip
3856 * at address 0x2e/0x2f need to be mutex protected.
3858 static struct it87_dmi_data gigabyte_ab350_gaming = {
3859 .sio_mutex = "\\_SB.PCI0.SBRG.SIO1.MUT0",
3863 * On the Shuttle SN68PT, FAN_CTL2 is apparently not
3864 * connected to a fan, but to something else. One user
3865 * has reported instant system power-off when changing
3866 * the PWM2 duty cycle, so we disable it.
3867 * I use the board name string as the trigger in case
3868 * the same board is ever used in other systems.
3870 static struct it87_dmi_data nvidia_fn68pt = {
3874 static const struct dmi_system_id it87_dmi_table[] __initconst = {
3877 DMI_MATCH(DMI_SYS_VENDOR, "Gigabyte Technology Co., Ltd."),
3878 DMI_MATCH(DMI_BOARD_NAME, "AB350-Gaming-CF"),
3880 .driver_data = &gigabyte_ab350_gaming,
3884 DMI_MATCH(DMI_SYS_VENDOR, "Gigabyte Technology Co., Ltd."),
3885 DMI_MATCH(DMI_BOARD_NAME, "AB350-Gaming 3-CF"),
3887 .driver_data = &gigabyte_ab350_gaming,
3891 DMI_MATCH(DMI_SYS_VENDOR, "Gigabyte Technology Co., Ltd."),
3892 DMI_MATCH(DMI_BOARD_NAME, "AB350M-D3H-CF"),
3894 .driver_data = &gigabyte_ab350_gaming,
3898 DMI_MATCH(DMI_SYS_VENDOR, "Gigabyte Technology Co., Ltd."),
3899 DMI_MATCH(DMI_BOARD_NAME, "AX370-Gaming K7"),
3901 .driver_data = &gigabyte_ab350_gaming,
3905 DMI_MATCH(DMI_SYS_VENDOR, "Gigabyte Technology Co., Ltd."),
3906 DMI_MATCH(DMI_BOARD_NAME, "AX370-Gaming 5"),
3908 .driver_data = &gigabyte_ab350_gaming,
3912 DMI_MATCH(DMI_BOARD_VENDOR, "nVIDIA"),
3913 DMI_MATCH(DMI_BOARD_NAME, "FN68PT"),
3915 .driver_data = &nvidia_fn68pt,
3920 static int __init sm_it87_init(void)
3922 const struct dmi_system_id *dmi = dmi_first_match(it87_dmi_table);
3923 struct it87_dmi_data *dmi_data = NULL;
3924 int sioaddr[2] = { REG_2E, REG_4E };
3925 struct it87_sio_data sio_data;
3926 unsigned short isa_address;
3931 dmi_data = dmi->driver_data;
3934 #ifdef __IT87_USE_ACPI_MUTEX
3935 if (dmi_data->sio_mutex) {
3936 static acpi_status status;
3938 status = acpi_get_handle(NULL, dmi_data->sio_mutex,
3939 &it87_acpi_sio_handle);
3940 if (ACPI_SUCCESS(status)) {
3941 it87_acpi_sio_mutex = dmi_data->sio_mutex;
3942 pr_debug("Found ACPI SIO mutex %s\n",
3943 dmi_data->sio_mutex);
3945 pr_warn("ACPI SIO mutex %s not found\n",
3946 dmi_data->sio_mutex);
3949 #endif /* __IT87_USE_ACPI_MUTEX */
3952 err = platform_driver_register(&it87_driver);
3956 for (i = 0; i < ARRAY_SIZE(sioaddr); i++) {
3957 memset(&sio_data, 0, sizeof(struct it87_sio_data));
3959 err = it87_find(sioaddr[i], &isa_address, &sio_data);
3960 if (err || isa_address == 0)
3964 sio_data.skip_pwm |= dmi_data->skip_pwm;
3965 err = it87_device_add(i, isa_address, &sio_data);
3967 goto exit_dev_unregister;
3973 goto exit_unregister;
3977 exit_dev_unregister:
3978 /* NULL check handled by platform_device_unregister */
3979 platform_device_unregister(it87_pdev[0]);
3981 platform_driver_unregister(&it87_driver);
3985 static void __exit sm_it87_exit(void)
3987 /* NULL check handled by platform_device_unregister */
3988 platform_device_unregister(it87_pdev[1]);
3989 platform_device_unregister(it87_pdev[0]);
3990 platform_driver_unregister(&it87_driver);
3993 MODULE_AUTHOR("Chris Gauthron, Jean Delvare <jdelvare@suse.de>");
3994 MODULE_DESCRIPTION("IT8705F/IT871xF/IT872xF hardware monitoring driver");
3995 module_param(update_vbat, bool, 0);
3996 MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
3997 module_param(fix_pwm_polarity, bool, 0);
3998 MODULE_PARM_DESC(fix_pwm_polarity,
3999 "Force PWM polarity to active high (DANGEROUS)");
4000 MODULE_LICENSE("GPL");
4002 module_init(sm_it87_init);
4003 module_exit(sm_it87_exit);