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 * IT8620E Super I/O chip w/LPC interface
15 * IT8623E Super I/O chip w/LPC interface
16 * IT8705F Super I/O chip w/LPC interface
17 * IT8712F Super I/O chip w/LPC interface
18 * IT8716F Super I/O chip w/LPC interface
19 * IT8718F Super I/O chip w/LPC interface
20 * IT8720F Super I/O chip w/LPC interface
21 * IT8721F Super I/O chip w/LPC interface
22 * IT8726F Super I/O chip w/LPC interface
23 * IT8728F Super I/O chip w/LPC interface
24 * IT8758E Super I/O chip w/LPC interface
25 * IT8771E Super I/O chip w/LPC interface
26 * IT8772E Super I/O chip w/LPC interface
27 * IT8781F Super I/O chip w/LPC interface
28 * IT8782F Super I/O chip w/LPC interface
29 * IT8783E/F Super I/O chip w/LPC interface
30 * IT8786E Super I/O chip w/LPC interface
31 * IT8790E Super I/O chip w/LPC interface
32 * Sis950 A clone of the IT8705F
34 * Copyright (C) 2001 Chris Gauthron
35 * Copyright (C) 2005-2010 Jean Delvare <jdelvare@suse.de>
37 * This program is free software; you can redistribute it and/or modify
38 * it under the terms of the GNU General Public License as published by
39 * the Free Software Foundation; either version 2 of the License, or
40 * (at your option) any later version.
42 * This program is distributed in the hope that it will be useful,
43 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 * GNU General Public License for more details.
48 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
50 #include <linux/bitops.h>
51 #include <linux/module.h>
52 #include <linux/init.h>
53 #include <linux/slab.h>
54 #include <linux/jiffies.h>
55 #include <linux/platform_device.h>
56 #include <linux/hwmon.h>
57 #include <linux/hwmon-sysfs.h>
58 #include <linux/hwmon-vid.h>
59 #include <linux/err.h>
60 #include <linux/mutex.h>
61 #include <linux/sysfs.h>
62 #include <linux/string.h>
63 #include <linux/dmi.h>
64 #include <linux/acpi.h>
68 #define DRVNAME "it87"
70 enum chips { it87, it8712, it8716, it8718, it8720, it8721, it8728, it8771,
71 it8772, it8781, it8782, it8783, it8786, it8790, it8603, it8620 };
73 static unsigned short force_id;
74 module_param(force_id, ushort, 0);
75 MODULE_PARM_DESC(force_id, "Override the detected device ID");
77 static struct platform_device *it87_pdev[2];
79 #define REG_2E 0x2e /* The register to read/write */
80 #define REG_4E 0x4e /* Secondary register to read/write */
82 #define DEV 0x07 /* Register: Logical device select */
83 #define PME 0x04 /* The device with the fan registers in it */
85 /* The device with the IT8718F/IT8720F VID value in it */
88 #define DEVID 0x20 /* Register: Device ID */
89 #define DEVREV 0x22 /* Register: Device Revision */
91 static inline int superio_inb(int ioreg, int reg)
94 return inb(ioreg + 1);
97 static inline void superio_outb(int ioreg, int reg, int val)
100 outb(val, ioreg + 1);
103 static int superio_inw(int ioreg, int reg)
108 val = inb(ioreg + 1) << 8;
110 val |= inb(ioreg + 1);
114 static inline void superio_select(int ioreg, int ldn)
117 outb(ldn, ioreg + 1);
120 static inline int superio_enter(int ioreg)
123 * Try to reserve ioreg and ioreg + 1 for exclusive access.
125 if (!request_muxed_region(ioreg, 2, DRVNAME))
131 outb(ioreg == REG_4E ? 0xaa : 0x55, ioreg);
135 static inline void superio_exit(int ioreg)
138 outb(0x02, ioreg + 1);
139 release_region(ioreg, 2);
142 /* Logical device 4 registers */
143 #define IT8712F_DEVID 0x8712
144 #define IT8705F_DEVID 0x8705
145 #define IT8716F_DEVID 0x8716
146 #define IT8718F_DEVID 0x8718
147 #define IT8720F_DEVID 0x8720
148 #define IT8721F_DEVID 0x8721
149 #define IT8726F_DEVID 0x8726
150 #define IT8728F_DEVID 0x8728
151 #define IT8771E_DEVID 0x8771
152 #define IT8772E_DEVID 0x8772
153 #define IT8781F_DEVID 0x8781
154 #define IT8782F_DEVID 0x8782
155 #define IT8783E_DEVID 0x8783
156 #define IT8786E_DEVID 0x8786
157 #define IT8790E_DEVID 0x8790
158 #define IT8603E_DEVID 0x8603
159 #define IT8620E_DEVID 0x8620
160 #define IT8623E_DEVID 0x8623
161 #define IT87_ACT_REG 0x30
162 #define IT87_BASE_REG 0x60
164 /* Logical device 7 registers (IT8712F and later) */
165 #define IT87_SIO_GPIO1_REG 0x25
166 #define IT87_SIO_GPIO2_REG 0x26
167 #define IT87_SIO_GPIO3_REG 0x27
168 #define IT87_SIO_GPIO4_REG 0x28
169 #define IT87_SIO_GPIO5_REG 0x29
170 #define IT87_SIO_PINX1_REG 0x2a /* Pin selection */
171 #define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
172 #define IT87_SIO_SPI_REG 0xef /* SPI function pin select */
173 #define IT87_SIO_VID_REG 0xfc /* VID value */
174 #define IT87_SIO_BEEP_PIN_REG 0xf6 /* Beep pin mapping */
176 /* Update battery voltage after every reading if true */
177 static bool update_vbat;
179 /* Not all BIOSes properly configure the PWM registers */
180 static bool fix_pwm_polarity;
182 /* Many IT87 constants specified below */
184 /* Length of ISA address segment */
185 #define IT87_EXTENT 8
187 /* Length of ISA address segment for Environmental Controller */
188 #define IT87_EC_EXTENT 2
190 /* Offset of EC registers from ISA base address */
191 #define IT87_EC_OFFSET 5
193 /* Where are the ISA address/data registers relative to the EC base address */
194 #define IT87_ADDR_REG_OFFSET 0
195 #define IT87_DATA_REG_OFFSET 1
197 /*----- The IT87 registers -----*/
199 #define IT87_REG_CONFIG 0x00
201 #define IT87_REG_ALARM1 0x01
202 #define IT87_REG_ALARM2 0x02
203 #define IT87_REG_ALARM3 0x03
206 * The IT8718F and IT8720F have the VID value in a different register, in
207 * Super-I/O configuration space.
209 #define IT87_REG_VID 0x0a
211 * The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b
212 * for fan divisors. Later IT8712F revisions must use 16-bit tachometer
215 #define IT87_REG_FAN_DIV 0x0b
216 #define IT87_REG_FAN_16BIT 0x0c
220 * - up to 13 voltage (0 to 7, battery, avcc, 10 to 12)
221 * - up to 6 temp (1 to 6)
222 * - up to 6 fan (1 to 6)
225 static const u8 IT87_REG_FAN[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82, 0x4c };
226 static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86, 0x4e };
227 static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83, 0x4d };
228 static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87, 0x4f };
229 static const u8 IT87_REG_TEMP_OFFSET[] = { 0x56, 0x57, 0x59 };
231 #define IT87_REG_FAN_MAIN_CTRL 0x13
232 #define IT87_REG_FAN_CTL 0x14
233 static const u8 IT87_REG_PWM[] = { 0x15, 0x16, 0x17, 0x7f, 0xa7, 0xaf };
234 static const u8 IT87_REG_PWM_DUTY[] = { 0x63, 0x6b, 0x73, 0x7b, 0xa3, 0xab };
236 static const u8 IT87_REG_VIN[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26,
237 0x27, 0x28, 0x2f, 0x2c, 0x2d, 0x2e };
239 #define IT87_REG_TEMP(nr) (0x29 + (nr))
241 #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2)
242 #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2)
243 #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2)
244 #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2)
246 #define IT87_REG_VIN_ENABLE 0x50
247 #define IT87_REG_TEMP_ENABLE 0x51
248 #define IT87_REG_TEMP_EXTRA 0x55
249 #define IT87_REG_BEEP_ENABLE 0x5c
251 #define IT87_REG_CHIPID 0x58
253 static const u8 IT87_REG_AUTO_BASE[] = { 0x60, 0x68, 0x70, 0x78, 0xa0, 0xa8 };
255 #define IT87_REG_AUTO_TEMP(nr, i) (IT87_REG_AUTO_BASE[nr] + (i))
256 #define IT87_REG_AUTO_PWM(nr, i) (IT87_REG_AUTO_BASE[nr] + 5 + (i))
258 #define IT87_REG_TEMP456_ENABLE 0x77
260 #define NUM_VIN ARRAY_SIZE(IT87_REG_VIN)
261 #define NUM_VIN_LIMIT 8
263 #define NUM_TEMP_OFFSET ARRAY_SIZE(IT87_REG_TEMP_OFFSET)
264 #define NUM_TEMP_LIMIT 3
265 #define NUM_FAN ARRAY_SIZE(IT87_REG_FAN)
266 #define NUM_FAN_DIV 3
267 #define NUM_PWM ARRAY_SIZE(IT87_REG_PWM)
268 #define NUM_AUTO_PWM ARRAY_SIZE(IT87_REG_PWM)
270 struct it87_devices {
272 const char * const suffix;
278 #define FEAT_12MV_ADC BIT(0)
279 #define FEAT_NEWER_AUTOPWM BIT(1)
280 #define FEAT_OLD_AUTOPWM BIT(2)
281 #define FEAT_16BIT_FANS BIT(3)
282 #define FEAT_TEMP_OFFSET BIT(4)
283 #define FEAT_TEMP_PECI BIT(5)
284 #define FEAT_TEMP_OLD_PECI BIT(6)
285 #define FEAT_FAN16_CONFIG BIT(7) /* Need to enable 16-bit fans */
286 #define FEAT_FIVE_FANS BIT(8) /* Supports five fans */
287 #define FEAT_VID BIT(9) /* Set if chip supports VID */
288 #define FEAT_IN7_INTERNAL BIT(10) /* Set if in7 is internal */
289 #define FEAT_SIX_FANS BIT(11) /* Supports six fans */
290 #define FEAT_AVCC3 BIT(12) /* Chip supports in9/AVCC3 */
291 #define FEAT_SIX_PWM BIT(13) /* Chip supports 6 pwm chn */
292 #define FEAT_PWM_FREQ2 BIT(14) /* Separate pwm freq 2 */
293 #define FEAT_SIX_TEMP BIT(15) /* Up to 6 temp sensors */
295 static const struct it87_devices it87_devices[] = {
299 .features = FEAT_OLD_AUTOPWM, /* may need to overwrite */
304 .features = FEAT_OLD_AUTOPWM | FEAT_VID,
305 /* may need to overwrite */
310 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | FEAT_VID
311 | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS | FEAT_PWM_FREQ2,
316 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | FEAT_VID
317 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS
319 .old_peci_mask = 0x4,
324 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | FEAT_VID
325 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS
327 .old_peci_mask = 0x4,
332 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
333 | FEAT_TEMP_OFFSET | FEAT_TEMP_OLD_PECI | FEAT_TEMP_PECI
334 | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS | FEAT_IN7_INTERNAL
337 .old_peci_mask = 0x02, /* Actually reports PCH */
342 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
343 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_FIVE_FANS
344 | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2,
350 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
351 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
353 /* PECI: guesswork */
355 /* 16 bit fans (OHM) */
356 /* three fans, always 16 bit (guesswork) */
362 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
363 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
365 /* PECI (coreboot) */
366 /* 12mV ADC (HWSensors4, OHM) */
367 /* 16 bit fans (HWSensors4, OHM) */
368 /* three fans, always 16 bit (datasheet) */
374 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
375 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2,
376 .old_peci_mask = 0x4,
381 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
382 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2,
383 .old_peci_mask = 0x4,
388 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
389 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2,
390 .old_peci_mask = 0x4,
395 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
396 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
403 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
404 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
411 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
412 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
413 | FEAT_AVCC3 | FEAT_PWM_FREQ2,
419 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
420 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_SIX_FANS
421 | FEAT_IN7_INTERNAL | FEAT_AVCC3 | FEAT_SIX_PWM
422 | FEAT_PWM_FREQ2 | FEAT_SIX_TEMP,
427 #define has_16bit_fans(data) ((data)->features & FEAT_16BIT_FANS)
428 #define has_12mv_adc(data) ((data)->features & FEAT_12MV_ADC)
429 #define has_newer_autopwm(data) ((data)->features & FEAT_NEWER_AUTOPWM)
430 #define has_old_autopwm(data) ((data)->features & FEAT_OLD_AUTOPWM)
431 #define has_temp_offset(data) ((data)->features & FEAT_TEMP_OFFSET)
432 #define has_temp_peci(data, nr) (((data)->features & FEAT_TEMP_PECI) && \
433 ((data)->peci_mask & BIT(nr)))
434 #define has_temp_old_peci(data, nr) \
435 (((data)->features & FEAT_TEMP_OLD_PECI) && \
436 ((data)->old_peci_mask & BIT(nr)))
437 #define has_fan16_config(data) ((data)->features & FEAT_FAN16_CONFIG)
438 #define has_five_fans(data) ((data)->features & (FEAT_FIVE_FANS | \
440 #define has_vid(data) ((data)->features & FEAT_VID)
441 #define has_in7_internal(data) ((data)->features & FEAT_IN7_INTERNAL)
442 #define has_six_fans(data) ((data)->features & FEAT_SIX_FANS)
443 #define has_avcc3(data) ((data)->features & FEAT_AVCC3)
444 #define has_six_pwm(data) ((data)->features & FEAT_SIX_PWM)
445 #define has_pwm_freq2(data) ((data)->features & FEAT_PWM_FREQ2)
446 #define has_six_temp(data) ((data)->features & FEAT_SIX_TEMP)
448 struct it87_sio_data {
450 /* Values read from Super-I/O config space */
454 u8 internal; /* Internal sensors can be labeled */
455 /* Features skipped based on config or DMI */
464 * For each registered chip, we need to keep some data in memory.
465 * The structure is dynamically allocated.
468 const struct attribute_group *groups[7];
476 struct mutex update_lock;
477 char valid; /* !=0 if following fields are valid */
478 unsigned long last_updated; /* In jiffies */
480 u16 in_scaled; /* Internal voltage sensors are scaled */
481 u16 in_internal; /* Bitfield, internal sensors (for labels) */
482 u16 has_in; /* Bitfield, voltage sensors enabled */
483 u8 in[NUM_VIN][3]; /* [nr][0]=in, [1]=min, [2]=max */
484 u8 has_fan; /* Bitfield, fans enabled */
485 u16 fan[NUM_FAN][2]; /* Register values, [nr][0]=fan, [1]=min */
486 u8 has_temp; /* Bitfield, temp sensors enabled */
487 s8 temp[NUM_TEMP][4]; /* [nr][0]=temp, [1]=min, [2]=max, [3]=offset */
488 u8 sensor; /* Register value (IT87_REG_TEMP_ENABLE) */
489 u8 extra; /* Register value (IT87_REG_TEMP_EXTRA) */
490 u8 fan_div[NUM_FAN_DIV];/* Register encoding, shifted right */
491 bool has_vid; /* True if VID supported */
492 u8 vid; /* Register encoding, combined */
494 u32 alarms; /* Register encoding, combined */
495 bool has_beep; /* true if beep supported */
496 u8 beeps; /* Register encoding */
497 u8 fan_main_ctrl; /* Register value */
498 u8 fan_ctl; /* Register value */
501 * The following 3 arrays correspond to the same registers up to
502 * the IT8720F. The meaning of bits 6-0 depends on the value of bit
503 * 7, and we want to preserve settings on mode changes, so we have
504 * to track all values separately.
505 * Starting with the IT8721F, the manual PWM duty cycles are stored
506 * in separate registers (8-bit values), so the separate tracking
507 * is no longer needed, but it is still done to keep the driver
510 u8 has_pwm; /* Bitfield, pwm control enabled */
511 u8 pwm_ctrl[NUM_PWM]; /* Register value */
512 u8 pwm_duty[NUM_PWM]; /* Manual PWM value set by user */
513 u8 pwm_temp_map[NUM_PWM];/* PWM to temp. chan. mapping (bits 1-0) */
515 /* Automatic fan speed control registers */
516 u8 auto_pwm[NUM_AUTO_PWM][4]; /* [nr][3] is hard-coded */
517 s8 auto_temp[NUM_AUTO_PWM][5]; /* [nr][0] is point1_temp_hyst */
520 static int adc_lsb(const struct it87_data *data, int nr)
522 int lsb = has_12mv_adc(data) ? 12 : 16;
524 if (data->in_scaled & BIT(nr))
529 static u8 in_to_reg(const struct it87_data *data, int nr, long val)
531 val = DIV_ROUND_CLOSEST(val, adc_lsb(data, nr));
532 return clamp_val(val, 0, 255);
535 static int in_from_reg(const struct it87_data *data, int nr, int val)
537 return val * adc_lsb(data, nr);
540 static inline u8 FAN_TO_REG(long rpm, int div)
544 rpm = clamp_val(rpm, 1, 1000000);
545 return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
548 static inline u16 FAN16_TO_REG(long rpm)
552 return clamp_val((1350000 + rpm) / (rpm * 2), 1, 0xfffe);
555 #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \
556 1350000 / ((val) * (div)))
557 /* The divider is fixed to 2 in 16-bit mode */
558 #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
559 1350000 / ((val) * 2))
561 #define TEMP_TO_REG(val) (clamp_val(((val) < 0 ? (((val) - 500) / 1000) : \
562 ((val) + 500) / 1000), -128, 127))
563 #define TEMP_FROM_REG(val) ((val) * 1000)
565 static u8 pwm_to_reg(const struct it87_data *data, long val)
567 if (has_newer_autopwm(data))
573 static int pwm_from_reg(const struct it87_data *data, u8 reg)
575 if (has_newer_autopwm(data))
578 return (reg & 0x7f) << 1;
581 static int DIV_TO_REG(int val)
585 while (answer < 7 && (val >>= 1))
590 #define DIV_FROM_REG(val) BIT(val)
593 * PWM base frequencies. The frequency has to be divided by either 128 or 256,
594 * depending on the chip type, to calculate the actual PWM frequency.
596 * Some of the chip datasheets suggest a base frequency of 51 kHz instead
597 * of 750 kHz for the slowest base frequency, resulting in a PWM frequency
598 * of 200 Hz. Sometimes both PWM frequency select registers are affected,
599 * sometimes just one. It is unknown if this is a datasheet error or real,
600 * so this is ignored for now.
602 static const unsigned int pwm_freq[8] = {
614 * Must be called with data->update_lock held, except during initialization.
615 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
616 * would slow down the IT87 access and should not be necessary.
618 static int it87_read_value(struct it87_data *data, u8 reg)
620 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
621 return inb_p(data->addr + IT87_DATA_REG_OFFSET);
625 * Must be called with data->update_lock held, except during initialization.
626 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
627 * would slow down the IT87 access and should not be necessary.
629 static void it87_write_value(struct it87_data *data, u8 reg, u8 value)
631 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
632 outb_p(value, data->addr + IT87_DATA_REG_OFFSET);
635 static void it87_update_pwm_ctrl(struct it87_data *data, int nr)
637 data->pwm_ctrl[nr] = it87_read_value(data, IT87_REG_PWM[nr]);
638 if (has_newer_autopwm(data)) {
639 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
640 data->pwm_duty[nr] = it87_read_value(data,
641 IT87_REG_PWM_DUTY[nr]);
643 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
644 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
645 else /* Manual mode */
646 data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f;
649 if (has_old_autopwm(data)) {
652 for (i = 0; i < 5 ; i++)
653 data->auto_temp[nr][i] = it87_read_value(data,
654 IT87_REG_AUTO_TEMP(nr, i));
655 for (i = 0; i < 3 ; i++)
656 data->auto_pwm[nr][i] = it87_read_value(data,
657 IT87_REG_AUTO_PWM(nr, i));
658 } else if (has_newer_autopwm(data)) {
662 * 0: temperature hysteresis (base + 5)
663 * 1: fan off temperature (base + 0)
664 * 2: fan start temperature (base + 1)
665 * 3: fan max temperature (base + 2)
667 data->auto_temp[nr][0] =
668 it87_read_value(data, IT87_REG_AUTO_TEMP(nr, 5));
670 for (i = 0; i < 3 ; i++)
671 data->auto_temp[nr][i + 1] =
672 it87_read_value(data,
673 IT87_REG_AUTO_TEMP(nr, i));
675 * 0: start pwm value (base + 3)
676 * 1: pwm slope (base + 4, 1/8th pwm)
678 data->auto_pwm[nr][0] =
679 it87_read_value(data, IT87_REG_AUTO_TEMP(nr, 3));
680 data->auto_pwm[nr][1] =
681 it87_read_value(data, IT87_REG_AUTO_TEMP(nr, 4));
685 static struct it87_data *it87_update_device(struct device *dev)
687 struct it87_data *data = dev_get_drvdata(dev);
690 mutex_lock(&data->update_lock);
692 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) ||
696 * Cleared after each update, so reenable. Value
697 * returned by this read will be previous value
699 it87_write_value(data, IT87_REG_CONFIG,
700 it87_read_value(data, IT87_REG_CONFIG) | 0x40);
702 for (i = 0; i < NUM_VIN; i++) {
703 if (!(data->has_in & BIT(i)))
707 it87_read_value(data, IT87_REG_VIN[i]);
709 /* VBAT and AVCC don't have limit registers */
710 if (i >= NUM_VIN_LIMIT)
714 it87_read_value(data, IT87_REG_VIN_MIN(i));
716 it87_read_value(data, IT87_REG_VIN_MAX(i));
719 for (i = 0; i < NUM_FAN; i++) {
720 /* Skip disabled fans */
721 if (!(data->has_fan & BIT(i)))
725 it87_read_value(data, IT87_REG_FAN_MIN[i]);
726 data->fan[i][0] = it87_read_value(data,
728 /* Add high byte if in 16-bit mode */
729 if (has_16bit_fans(data)) {
730 data->fan[i][0] |= it87_read_value(data,
731 IT87_REG_FANX[i]) << 8;
732 data->fan[i][1] |= it87_read_value(data,
733 IT87_REG_FANX_MIN[i]) << 8;
736 for (i = 0; i < NUM_TEMP; i++) {
737 if (!(data->has_temp & BIT(i)))
740 it87_read_value(data, IT87_REG_TEMP(i));
742 if (has_temp_offset(data) && i < NUM_TEMP_OFFSET)
744 it87_read_value(data,
745 IT87_REG_TEMP_OFFSET[i]);
747 if (i >= NUM_TEMP_LIMIT)
751 it87_read_value(data, IT87_REG_TEMP_LOW(i));
753 it87_read_value(data, IT87_REG_TEMP_HIGH(i));
756 /* Newer chips don't have clock dividers */
757 if ((data->has_fan & 0x07) && !has_16bit_fans(data)) {
758 i = it87_read_value(data, IT87_REG_FAN_DIV);
759 data->fan_div[0] = i & 0x07;
760 data->fan_div[1] = (i >> 3) & 0x07;
761 data->fan_div[2] = (i & 0x40) ? 3 : 1;
765 it87_read_value(data, IT87_REG_ALARM1) |
766 (it87_read_value(data, IT87_REG_ALARM2) << 8) |
767 (it87_read_value(data, IT87_REG_ALARM3) << 16);
768 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
770 data->fan_main_ctrl = it87_read_value(data,
771 IT87_REG_FAN_MAIN_CTRL);
772 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL);
773 for (i = 0; i < NUM_PWM; i++) {
774 if (!(data->has_pwm & BIT(i)))
776 it87_update_pwm_ctrl(data, i);
779 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
780 data->extra = it87_read_value(data, IT87_REG_TEMP_EXTRA);
782 * The IT8705F does not have VID capability.
783 * The IT8718F and later don't use IT87_REG_VID for the
786 if (data->type == it8712 || data->type == it8716) {
787 data->vid = it87_read_value(data, IT87_REG_VID);
789 * The older IT8712F revisions had only 5 VID pins,
790 * but we assume it is always safe to read 6 bits.
794 data->last_updated = jiffies;
798 mutex_unlock(&data->update_lock);
803 static ssize_t show_in(struct device *dev, struct device_attribute *attr,
806 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
807 struct it87_data *data = it87_update_device(dev);
808 int index = sattr->index;
811 return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr][index]));
814 static ssize_t set_in(struct device *dev, struct device_attribute *attr,
815 const char *buf, size_t count)
817 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
818 struct it87_data *data = dev_get_drvdata(dev);
819 int index = sattr->index;
823 if (kstrtoul(buf, 10, &val) < 0)
826 mutex_lock(&data->update_lock);
827 data->in[nr][index] = in_to_reg(data, nr, val);
828 it87_write_value(data,
829 index == 1 ? IT87_REG_VIN_MIN(nr)
830 : IT87_REG_VIN_MAX(nr),
831 data->in[nr][index]);
832 mutex_unlock(&data->update_lock);
836 static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0);
837 static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_in, set_in,
839 static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_in, set_in,
842 static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 1, 0);
843 static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_in, set_in,
845 static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_in, set_in,
848 static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 2, 0);
849 static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_in, set_in,
851 static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_in, set_in,
854 static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 3, 0);
855 static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_in, set_in,
857 static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_in, set_in,
860 static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 4, 0);
861 static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_in, set_in,
863 static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_in, set_in,
866 static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 5, 0);
867 static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_in, set_in,
869 static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_in, set_in,
872 static SENSOR_DEVICE_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 6, 0);
873 static SENSOR_DEVICE_ATTR_2(in6_min, S_IRUGO | S_IWUSR, show_in, set_in,
875 static SENSOR_DEVICE_ATTR_2(in6_max, S_IRUGO | S_IWUSR, show_in, set_in,
878 static SENSOR_DEVICE_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 7, 0);
879 static SENSOR_DEVICE_ATTR_2(in7_min, S_IRUGO | S_IWUSR, show_in, set_in,
881 static SENSOR_DEVICE_ATTR_2(in7_max, S_IRUGO | S_IWUSR, show_in, set_in,
884 static SENSOR_DEVICE_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 8, 0);
885 static SENSOR_DEVICE_ATTR_2(in9_input, S_IRUGO, show_in, NULL, 9, 0);
886 static SENSOR_DEVICE_ATTR_2(in10_input, S_IRUGO, show_in, NULL, 10, 0);
887 static SENSOR_DEVICE_ATTR_2(in11_input, S_IRUGO, show_in, NULL, 11, 0);
888 static SENSOR_DEVICE_ATTR_2(in12_input, S_IRUGO, show_in, NULL, 12, 0);
890 /* Up to 6 temperatures */
891 static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
894 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
896 int index = sattr->index;
897 struct it87_data *data = it87_update_device(dev);
899 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr][index]));
902 static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
903 const char *buf, size_t count)
905 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
907 int index = sattr->index;
908 struct it87_data *data = dev_get_drvdata(dev);
912 if (kstrtol(buf, 10, &val) < 0)
915 mutex_lock(&data->update_lock);
920 reg = IT87_REG_TEMP_LOW(nr);
923 reg = IT87_REG_TEMP_HIGH(nr);
926 regval = it87_read_value(data, IT87_REG_BEEP_ENABLE);
927 if (!(regval & 0x80)) {
929 it87_write_value(data, IT87_REG_BEEP_ENABLE, regval);
932 reg = IT87_REG_TEMP_OFFSET[nr];
936 data->temp[nr][index] = TEMP_TO_REG(val);
937 it87_write_value(data, reg, data->temp[nr][index]);
938 mutex_unlock(&data->update_lock);
942 static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0);
943 static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
945 static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
947 static SENSOR_DEVICE_ATTR_2(temp1_offset, S_IRUGO | S_IWUSR, show_temp,
949 static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, 0);
950 static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
952 static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
954 static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IRUGO | S_IWUSR, show_temp,
956 static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 2, 0);
957 static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
959 static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
961 static SENSOR_DEVICE_ATTR_2(temp3_offset, S_IRUGO | S_IWUSR, show_temp,
963 static SENSOR_DEVICE_ATTR_2(temp4_input, S_IRUGO, show_temp, NULL, 3, 0);
964 static SENSOR_DEVICE_ATTR_2(temp5_input, S_IRUGO, show_temp, NULL, 4, 0);
965 static SENSOR_DEVICE_ATTR_2(temp6_input, S_IRUGO, show_temp, NULL, 5, 0);
967 static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr,
970 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
971 int nr = sensor_attr->index;
972 struct it87_data *data = it87_update_device(dev);
973 u8 reg = data->sensor; /* In case value is updated while used */
974 u8 extra = data->extra;
976 if ((has_temp_peci(data, nr) && (reg >> 6 == nr + 1)) ||
977 (has_temp_old_peci(data, nr) && (extra & 0x80)))
978 return sprintf(buf, "6\n"); /* Intel PECI */
980 return sprintf(buf, "3\n"); /* thermal diode */
982 return sprintf(buf, "4\n"); /* thermistor */
983 return sprintf(buf, "0\n"); /* disabled */
986 static ssize_t set_temp_type(struct device *dev, struct device_attribute *attr,
987 const char *buf, size_t count)
989 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
990 int nr = sensor_attr->index;
992 struct it87_data *data = dev_get_drvdata(dev);
996 if (kstrtol(buf, 10, &val) < 0)
999 reg = it87_read_value(data, IT87_REG_TEMP_ENABLE);
1002 if (has_temp_peci(data, nr) && (reg >> 6 == nr + 1 || val == 6))
1004 extra = it87_read_value(data, IT87_REG_TEMP_EXTRA);
1005 if (has_temp_old_peci(data, nr) && ((extra & 0x80) || val == 6))
1007 if (val == 2) { /* backwards compatibility */
1009 "Sensor type 2 is deprecated, please use 4 instead\n");
1012 /* 3 = thermal diode; 4 = thermistor; 6 = Intel PECI; 0 = disabled */
1017 else if (has_temp_peci(data, nr) && val == 6)
1018 reg |= (nr + 1) << 6;
1019 else if (has_temp_old_peci(data, nr) && val == 6)
1024 mutex_lock(&data->update_lock);
1026 data->extra = extra;
1027 it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor);
1028 if (has_temp_old_peci(data, nr))
1029 it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra);
1030 data->valid = 0; /* Force cache refresh */
1031 mutex_unlock(&data->update_lock);
1035 static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR, show_temp_type,
1037 static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR, show_temp_type,
1039 static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR, show_temp_type,
1044 static int pwm_mode(const struct it87_data *data, int nr)
1046 if (data->type != it8603 && nr < 3 && !(data->fan_main_ctrl & BIT(nr)))
1047 return 0; /* Full speed */
1048 if (data->pwm_ctrl[nr] & 0x80) {
1049 return 2; /* Automatic mode */
1051 if ((data->type == it8603 || nr >= 3) &&
1052 data->pwm_duty[nr] == pwm_to_reg(data, 0xff))
1053 return 0; /* Full speed */
1054 return 1; /* Manual mode */
1058 static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
1061 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1063 int index = sattr->index;
1065 struct it87_data *data = it87_update_device(dev);
1067 speed = has_16bit_fans(data) ?
1068 FAN16_FROM_REG(data->fan[nr][index]) :
1069 FAN_FROM_REG(data->fan[nr][index],
1070 DIV_FROM_REG(data->fan_div[nr]));
1071 return sprintf(buf, "%d\n", speed);
1074 static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
1077 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1078 struct it87_data *data = it87_update_device(dev);
1079 int nr = sensor_attr->index;
1081 return sprintf(buf, "%lu\n", DIV_FROM_REG(data->fan_div[nr]));
1084 static ssize_t show_pwm_enable(struct device *dev,
1085 struct device_attribute *attr, char *buf)
1087 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1088 struct it87_data *data = it87_update_device(dev);
1089 int nr = sensor_attr->index;
1091 return sprintf(buf, "%d\n", pwm_mode(data, nr));
1094 static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
1097 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1098 struct it87_data *data = it87_update_device(dev);
1099 int nr = sensor_attr->index;
1101 return sprintf(buf, "%d\n",
1102 pwm_from_reg(data, data->pwm_duty[nr]));
1105 static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
1108 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1109 struct it87_data *data = it87_update_device(dev);
1110 int nr = sensor_attr->index;
1114 if (has_pwm_freq2(data) && nr == 1)
1115 index = (data->extra >> 4) & 0x07;
1117 index = (data->fan_ctl >> 4) & 0x07;
1119 freq = pwm_freq[index] / (has_newer_autopwm(data) ? 256 : 128);
1121 return sprintf(buf, "%u\n", freq);
1124 static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
1125 const char *buf, size_t count)
1127 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1129 int index = sattr->index;
1131 struct it87_data *data = dev_get_drvdata(dev);
1135 if (kstrtol(buf, 10, &val) < 0)
1138 mutex_lock(&data->update_lock);
1140 if (has_16bit_fans(data)) {
1141 data->fan[nr][index] = FAN16_TO_REG(val);
1142 it87_write_value(data, IT87_REG_FAN_MIN[nr],
1143 data->fan[nr][index] & 0xff);
1144 it87_write_value(data, IT87_REG_FANX_MIN[nr],
1145 data->fan[nr][index] >> 8);
1147 reg = it87_read_value(data, IT87_REG_FAN_DIV);
1150 data->fan_div[nr] = reg & 0x07;
1153 data->fan_div[nr] = (reg >> 3) & 0x07;
1156 data->fan_div[nr] = (reg & 0x40) ? 3 : 1;
1159 data->fan[nr][index] =
1160 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
1161 it87_write_value(data, IT87_REG_FAN_MIN[nr],
1162 data->fan[nr][index]);
1165 mutex_unlock(&data->update_lock);
1169 static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
1170 const char *buf, size_t count)
1172 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1173 struct it87_data *data = dev_get_drvdata(dev);
1174 int nr = sensor_attr->index;
1179 if (kstrtoul(buf, 10, &val) < 0)
1182 mutex_lock(&data->update_lock);
1183 old = it87_read_value(data, IT87_REG_FAN_DIV);
1185 /* Save fan min limit */
1186 min = FAN_FROM_REG(data->fan[nr][1], DIV_FROM_REG(data->fan_div[nr]));
1191 data->fan_div[nr] = DIV_TO_REG(val);
1195 data->fan_div[nr] = 1;
1197 data->fan_div[nr] = 3;
1200 val |= (data->fan_div[0] & 0x07);
1201 val |= (data->fan_div[1] & 0x07) << 3;
1202 if (data->fan_div[2] == 3)
1204 it87_write_value(data, IT87_REG_FAN_DIV, val);
1206 /* Restore fan min limit */
1207 data->fan[nr][1] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
1208 it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan[nr][1]);
1210 mutex_unlock(&data->update_lock);
1214 /* Returns 0 if OK, -EINVAL otherwise */
1215 static int check_trip_points(struct device *dev, int nr)
1217 const struct it87_data *data = dev_get_drvdata(dev);
1220 if (has_old_autopwm(data)) {
1221 for (i = 0; i < 3; i++) {
1222 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1])
1225 for (i = 0; i < 2; i++) {
1226 if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1])
1229 } else if (has_newer_autopwm(data)) {
1230 for (i = 1; i < 3; i++) {
1231 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1])
1238 "Inconsistent trip points, not switching to automatic mode\n");
1239 dev_err(dev, "Adjust the trip points and try again\n");
1244 static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr,
1245 const char *buf, size_t count)
1247 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1248 struct it87_data *data = dev_get_drvdata(dev);
1249 int nr = sensor_attr->index;
1252 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 2)
1255 /* Check trip points before switching to automatic mode */
1257 if (check_trip_points(dev, nr) < 0)
1261 mutex_lock(&data->update_lock);
1264 if (nr < 3 && data->type != it8603) {
1266 /* make sure the fan is on when in on/off mode */
1267 tmp = it87_read_value(data, IT87_REG_FAN_CTL);
1268 it87_write_value(data, IT87_REG_FAN_CTL, tmp | BIT(nr));
1269 /* set on/off mode */
1270 data->fan_main_ctrl &= ~BIT(nr);
1271 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
1272 data->fan_main_ctrl);
1274 /* No on/off mode, set maximum pwm value */
1275 data->pwm_duty[nr] = pwm_to_reg(data, 0xff);
1276 it87_write_value(data, IT87_REG_PWM_DUTY[nr],
1277 data->pwm_duty[nr]);
1278 /* and set manual mode */
1279 data->pwm_ctrl[nr] = has_newer_autopwm(data) ?
1280 data->pwm_temp_map[nr] :
1282 it87_write_value(data, IT87_REG_PWM[nr],
1283 data->pwm_ctrl[nr]);
1286 if (val == 1) /* Manual mode */
1287 data->pwm_ctrl[nr] = has_newer_autopwm(data) ?
1288 data->pwm_temp_map[nr] :
1290 else /* Automatic mode */
1291 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
1292 it87_write_value(data, IT87_REG_PWM[nr], data->pwm_ctrl[nr]);
1294 if (data->type != it8603 && nr < 3) {
1295 /* set SmartGuardian mode */
1296 data->fan_main_ctrl |= BIT(nr);
1297 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
1298 data->fan_main_ctrl);
1302 mutex_unlock(&data->update_lock);
1306 static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1307 const char *buf, size_t count)
1309 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1310 struct it87_data *data = dev_get_drvdata(dev);
1311 int nr = sensor_attr->index;
1314 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
1317 mutex_lock(&data->update_lock);
1318 if (has_newer_autopwm(data)) {
1320 * If we are in automatic mode, the PWM duty cycle register
1321 * is read-only so we can't write the value.
1323 if (data->pwm_ctrl[nr] & 0x80) {
1324 mutex_unlock(&data->update_lock);
1327 data->pwm_duty[nr] = pwm_to_reg(data, val);
1328 it87_write_value(data, IT87_REG_PWM_DUTY[nr],
1329 data->pwm_duty[nr]);
1331 data->pwm_duty[nr] = pwm_to_reg(data, val);
1333 * If we are in manual mode, write the duty cycle immediately;
1334 * otherwise, just store it for later use.
1336 if (!(data->pwm_ctrl[nr] & 0x80)) {
1337 data->pwm_ctrl[nr] = data->pwm_duty[nr];
1338 it87_write_value(data, IT87_REG_PWM[nr],
1339 data->pwm_ctrl[nr]);
1342 mutex_unlock(&data->update_lock);
1346 static ssize_t set_pwm_freq(struct device *dev, struct device_attribute *attr,
1347 const char *buf, size_t count)
1349 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1350 struct it87_data *data = dev_get_drvdata(dev);
1351 int nr = sensor_attr->index;
1355 if (kstrtoul(buf, 10, &val) < 0)
1358 val = clamp_val(val, 0, 1000000);
1359 val *= has_newer_autopwm(data) ? 256 : 128;
1361 /* Search for the nearest available frequency */
1362 for (i = 0; i < 7; i++) {
1363 if (val > (pwm_freq[i] + pwm_freq[i + 1]) / 2)
1367 mutex_lock(&data->update_lock);
1369 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f;
1370 data->fan_ctl |= i << 4;
1371 it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl);
1373 data->extra = it87_read_value(data, IT87_REG_TEMP_EXTRA) & 0x8f;
1374 data->extra |= i << 4;
1375 it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra);
1377 mutex_unlock(&data->update_lock);
1382 static ssize_t show_pwm_temp_map(struct device *dev,
1383 struct device_attribute *attr, char *buf)
1385 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1386 struct it87_data *data = it87_update_device(dev);
1387 int nr = sensor_attr->index;
1390 map = data->pwm_temp_map[nr];
1392 map = 0; /* Should never happen */
1393 if (nr >= 3) /* pwm channels 3..6 map to temp4..6 */
1396 return sprintf(buf, "%d\n", (int)BIT(map));
1399 static ssize_t set_pwm_temp_map(struct device *dev,
1400 struct device_attribute *attr, const char *buf,
1403 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1404 struct it87_data *data = dev_get_drvdata(dev);
1405 int nr = sensor_attr->index;
1409 if (kstrtol(buf, 10, &val) < 0)
1429 mutex_lock(&data->update_lock);
1430 data->pwm_temp_map[nr] = reg;
1432 * If we are in automatic mode, write the temp mapping immediately;
1433 * otherwise, just store it for later use.
1435 if (data->pwm_ctrl[nr] & 0x80) {
1436 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
1437 it87_write_value(data, IT87_REG_PWM[nr], data->pwm_ctrl[nr]);
1439 mutex_unlock(&data->update_lock);
1443 static ssize_t show_auto_pwm(struct device *dev, struct device_attribute *attr,
1446 struct it87_data *data = it87_update_device(dev);
1447 struct sensor_device_attribute_2 *sensor_attr =
1448 to_sensor_dev_attr_2(attr);
1449 int nr = sensor_attr->nr;
1450 int point = sensor_attr->index;
1452 return sprintf(buf, "%d\n",
1453 pwm_from_reg(data, data->auto_pwm[nr][point]));
1456 static ssize_t set_auto_pwm(struct device *dev, struct device_attribute *attr,
1457 const char *buf, size_t count)
1459 struct it87_data *data = dev_get_drvdata(dev);
1460 struct sensor_device_attribute_2 *sensor_attr =
1461 to_sensor_dev_attr_2(attr);
1462 int nr = sensor_attr->nr;
1463 int point = sensor_attr->index;
1467 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
1470 mutex_lock(&data->update_lock);
1471 data->auto_pwm[nr][point] = pwm_to_reg(data, val);
1472 if (has_newer_autopwm(data))
1473 regaddr = IT87_REG_AUTO_TEMP(nr, 3);
1475 regaddr = IT87_REG_AUTO_PWM(nr, point);
1476 it87_write_value(data, regaddr, data->auto_pwm[nr][point]);
1477 mutex_unlock(&data->update_lock);
1481 static ssize_t show_auto_pwm_slope(struct device *dev,
1482 struct device_attribute *attr, char *buf)
1484 struct it87_data *data = it87_update_device(dev);
1485 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1486 int nr = sensor_attr->index;
1488 return sprintf(buf, "%d\n", data->auto_pwm[nr][1] & 0x7f);
1491 static ssize_t set_auto_pwm_slope(struct device *dev,
1492 struct device_attribute *attr,
1493 const char *buf, size_t count)
1495 struct it87_data *data = dev_get_drvdata(dev);
1496 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1497 int nr = sensor_attr->index;
1500 if (kstrtoul(buf, 10, &val) < 0 || val > 127)
1503 mutex_lock(&data->update_lock);
1504 data->auto_pwm[nr][1] = (data->auto_pwm[nr][1] & 0x80) | val;
1505 it87_write_value(data, IT87_REG_AUTO_TEMP(nr, 4),
1506 data->auto_pwm[nr][1]);
1507 mutex_unlock(&data->update_lock);
1511 static ssize_t show_auto_temp(struct device *dev, struct device_attribute *attr,
1514 struct it87_data *data = it87_update_device(dev);
1515 struct sensor_device_attribute_2 *sensor_attr =
1516 to_sensor_dev_attr_2(attr);
1517 int nr = sensor_attr->nr;
1518 int point = sensor_attr->index;
1521 if (has_old_autopwm(data) || point)
1522 reg = data->auto_temp[nr][point];
1524 reg = data->auto_temp[nr][1] - (data->auto_temp[nr][0] & 0x1f);
1526 return sprintf(buf, "%d\n", TEMP_FROM_REG(reg));
1529 static ssize_t set_auto_temp(struct device *dev, struct device_attribute *attr,
1530 const char *buf, size_t count)
1532 struct it87_data *data = dev_get_drvdata(dev);
1533 struct sensor_device_attribute_2 *sensor_attr =
1534 to_sensor_dev_attr_2(attr);
1535 int nr = sensor_attr->nr;
1536 int point = sensor_attr->index;
1540 if (kstrtol(buf, 10, &val) < 0 || val < -128000 || val > 127000)
1543 mutex_lock(&data->update_lock);
1544 if (has_newer_autopwm(data) && !point) {
1545 reg = data->auto_temp[nr][1] - TEMP_TO_REG(val);
1546 reg = clamp_val(reg, 0, 0x1f) | (data->auto_temp[nr][0] & 0xe0);
1547 data->auto_temp[nr][0] = reg;
1548 it87_write_value(data, IT87_REG_AUTO_TEMP(nr, 5), reg);
1550 reg = TEMP_TO_REG(val);
1551 data->auto_temp[nr][point] = reg;
1552 if (has_newer_autopwm(data))
1554 it87_write_value(data, IT87_REG_AUTO_TEMP(nr, point), reg);
1556 mutex_unlock(&data->update_lock);
1560 static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0);
1561 static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1563 static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, show_fan_div,
1566 static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 1, 0);
1567 static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1569 static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, show_fan_div,
1572 static SENSOR_DEVICE_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 2, 0);
1573 static SENSOR_DEVICE_ATTR_2(fan3_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1575 static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO | S_IWUSR, show_fan_div,
1578 static SENSOR_DEVICE_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 3, 0);
1579 static SENSOR_DEVICE_ATTR_2(fan4_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1582 static SENSOR_DEVICE_ATTR_2(fan5_input, S_IRUGO, show_fan, NULL, 4, 0);
1583 static SENSOR_DEVICE_ATTR_2(fan5_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1586 static SENSOR_DEVICE_ATTR_2(fan6_input, S_IRUGO, show_fan, NULL, 5, 0);
1587 static SENSOR_DEVICE_ATTR_2(fan6_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1590 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
1591 show_pwm_enable, set_pwm_enable, 0);
1592 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0);
1593 static SENSOR_DEVICE_ATTR(pwm1_freq, S_IRUGO | S_IWUSR, show_pwm_freq,
1595 static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IRUGO,
1596 show_pwm_temp_map, set_pwm_temp_map, 0);
1597 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR,
1598 show_auto_pwm, set_auto_pwm, 0, 0);
1599 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR,
1600 show_auto_pwm, set_auto_pwm, 0, 1);
1601 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR,
1602 show_auto_pwm, set_auto_pwm, 0, 2);
1603 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO,
1604 show_auto_pwm, NULL, 0, 3);
1605 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR,
1606 show_auto_temp, set_auto_temp, 0, 1);
1607 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1608 show_auto_temp, set_auto_temp, 0, 0);
1609 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR,
1610 show_auto_temp, set_auto_temp, 0, 2);
1611 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR,
1612 show_auto_temp, set_auto_temp, 0, 3);
1613 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR,
1614 show_auto_temp, set_auto_temp, 0, 4);
1615 static SENSOR_DEVICE_ATTR_2(pwm1_auto_start, S_IRUGO | S_IWUSR,
1616 show_auto_pwm, set_auto_pwm, 0, 0);
1617 static SENSOR_DEVICE_ATTR(pwm1_auto_slope, S_IRUGO | S_IWUSR,
1618 show_auto_pwm_slope, set_auto_pwm_slope, 0);
1620 static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR,
1621 show_pwm_enable, set_pwm_enable, 1);
1622 static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 1);
1623 static SENSOR_DEVICE_ATTR(pwm2_freq, S_IRUGO, show_pwm_freq, set_pwm_freq, 1);
1624 static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IRUGO,
1625 show_pwm_temp_map, set_pwm_temp_map, 1);
1626 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR,
1627 show_auto_pwm, set_auto_pwm, 1, 0);
1628 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO | S_IWUSR,
1629 show_auto_pwm, set_auto_pwm, 1, 1);
1630 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO | S_IWUSR,
1631 show_auto_pwm, set_auto_pwm, 1, 2);
1632 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO,
1633 show_auto_pwm, NULL, 1, 3);
1634 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR,
1635 show_auto_temp, set_auto_temp, 1, 1);
1636 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1637 show_auto_temp, set_auto_temp, 1, 0);
1638 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR,
1639 show_auto_temp, set_auto_temp, 1, 2);
1640 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR,
1641 show_auto_temp, set_auto_temp, 1, 3);
1642 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_temp, S_IRUGO | S_IWUSR,
1643 show_auto_temp, set_auto_temp, 1, 4);
1644 static SENSOR_DEVICE_ATTR_2(pwm2_auto_start, S_IRUGO | S_IWUSR,
1645 show_auto_pwm, set_auto_pwm, 1, 0);
1646 static SENSOR_DEVICE_ATTR(pwm2_auto_slope, S_IRUGO | S_IWUSR,
1647 show_auto_pwm_slope, set_auto_pwm_slope, 1);
1649 static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR,
1650 show_pwm_enable, set_pwm_enable, 2);
1651 static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 2);
1652 static SENSOR_DEVICE_ATTR(pwm3_freq, S_IRUGO, show_pwm_freq, NULL, 2);
1653 static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IRUGO,
1654 show_pwm_temp_map, set_pwm_temp_map, 2);
1655 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO | S_IWUSR,
1656 show_auto_pwm, set_auto_pwm, 2, 0);
1657 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR,
1658 show_auto_pwm, set_auto_pwm, 2, 1);
1659 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO | S_IWUSR,
1660 show_auto_pwm, set_auto_pwm, 2, 2);
1661 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO,
1662 show_auto_pwm, NULL, 2, 3);
1663 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp, S_IRUGO | S_IWUSR,
1664 show_auto_temp, set_auto_temp, 2, 1);
1665 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1666 show_auto_temp, set_auto_temp, 2, 0);
1667 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_temp, S_IRUGO | S_IWUSR,
1668 show_auto_temp, set_auto_temp, 2, 2);
1669 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_temp, S_IRUGO | S_IWUSR,
1670 show_auto_temp, set_auto_temp, 2, 3);
1671 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_temp, S_IRUGO | S_IWUSR,
1672 show_auto_temp, set_auto_temp, 2, 4);
1673 static SENSOR_DEVICE_ATTR_2(pwm3_auto_start, S_IRUGO | S_IWUSR,
1674 show_auto_pwm, set_auto_pwm, 2, 0);
1675 static SENSOR_DEVICE_ATTR(pwm3_auto_slope, S_IRUGO | S_IWUSR,
1676 show_auto_pwm_slope, set_auto_pwm_slope, 2);
1678 static SENSOR_DEVICE_ATTR(pwm4_enable, S_IRUGO | S_IWUSR,
1679 show_pwm_enable, set_pwm_enable, 3);
1680 static SENSOR_DEVICE_ATTR(pwm4, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 3);
1681 static SENSOR_DEVICE_ATTR(pwm4_freq, S_IRUGO, show_pwm_freq, NULL, 3);
1682 static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IRUGO,
1683 show_pwm_temp_map, set_pwm_temp_map, 3);
1684 static SENSOR_DEVICE_ATTR_2(pwm4_auto_point1_temp, S_IRUGO | S_IWUSR,
1685 show_auto_temp, set_auto_temp, 2, 1);
1686 static SENSOR_DEVICE_ATTR_2(pwm4_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1687 show_auto_temp, set_auto_temp, 2, 0);
1688 static SENSOR_DEVICE_ATTR_2(pwm4_auto_point2_temp, S_IRUGO | S_IWUSR,
1689 show_auto_temp, set_auto_temp, 2, 2);
1690 static SENSOR_DEVICE_ATTR_2(pwm4_auto_point3_temp, S_IRUGO | S_IWUSR,
1691 show_auto_temp, set_auto_temp, 2, 3);
1692 static SENSOR_DEVICE_ATTR_2(pwm4_auto_start, S_IRUGO | S_IWUSR,
1693 show_auto_pwm, set_auto_pwm, 3, 0);
1694 static SENSOR_DEVICE_ATTR(pwm4_auto_slope, S_IRUGO | S_IWUSR,
1695 show_auto_pwm_slope, set_auto_pwm_slope, 3);
1697 static SENSOR_DEVICE_ATTR(pwm5_enable, S_IRUGO | S_IWUSR,
1698 show_pwm_enable, set_pwm_enable, 4);
1699 static SENSOR_DEVICE_ATTR(pwm5, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 4);
1700 static SENSOR_DEVICE_ATTR(pwm5_freq, S_IRUGO, show_pwm_freq, NULL, 4);
1701 static SENSOR_DEVICE_ATTR(pwm5_auto_channels_temp, S_IRUGO,
1702 show_pwm_temp_map, set_pwm_temp_map, 4);
1703 static SENSOR_DEVICE_ATTR_2(pwm5_auto_point1_temp, S_IRUGO | S_IWUSR,
1704 show_auto_temp, set_auto_temp, 2, 1);
1705 static SENSOR_DEVICE_ATTR_2(pwm5_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1706 show_auto_temp, set_auto_temp, 2, 0);
1707 static SENSOR_DEVICE_ATTR_2(pwm5_auto_point2_temp, S_IRUGO | S_IWUSR,
1708 show_auto_temp, set_auto_temp, 2, 2);
1709 static SENSOR_DEVICE_ATTR_2(pwm5_auto_point3_temp, S_IRUGO | S_IWUSR,
1710 show_auto_temp, set_auto_temp, 2, 3);
1711 static SENSOR_DEVICE_ATTR_2(pwm5_auto_start, S_IRUGO | S_IWUSR,
1712 show_auto_pwm, set_auto_pwm, 4, 0);
1713 static SENSOR_DEVICE_ATTR(pwm5_auto_slope, S_IRUGO | S_IWUSR,
1714 show_auto_pwm_slope, set_auto_pwm_slope, 4);
1716 static SENSOR_DEVICE_ATTR(pwm6_enable, S_IRUGO | S_IWUSR,
1717 show_pwm_enable, set_pwm_enable, 5);
1718 static SENSOR_DEVICE_ATTR(pwm6, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 5);
1719 static SENSOR_DEVICE_ATTR(pwm6_freq, S_IRUGO, show_pwm_freq, NULL, 5);
1720 static SENSOR_DEVICE_ATTR(pwm6_auto_channels_temp, S_IRUGO,
1721 show_pwm_temp_map, set_pwm_temp_map, 5);
1722 static SENSOR_DEVICE_ATTR_2(pwm6_auto_point1_temp, S_IRUGO | S_IWUSR,
1723 show_auto_temp, set_auto_temp, 2, 1);
1724 static SENSOR_DEVICE_ATTR_2(pwm6_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1725 show_auto_temp, set_auto_temp, 2, 0);
1726 static SENSOR_DEVICE_ATTR_2(pwm6_auto_point2_temp, S_IRUGO | S_IWUSR,
1727 show_auto_temp, set_auto_temp, 2, 2);
1728 static SENSOR_DEVICE_ATTR_2(pwm6_auto_point3_temp, S_IRUGO | S_IWUSR,
1729 show_auto_temp, set_auto_temp, 2, 3);
1730 static SENSOR_DEVICE_ATTR_2(pwm6_auto_start, S_IRUGO | S_IWUSR,
1731 show_auto_pwm, set_auto_pwm, 5, 0);
1732 static SENSOR_DEVICE_ATTR(pwm6_auto_slope, S_IRUGO | S_IWUSR,
1733 show_auto_pwm_slope, set_auto_pwm_slope, 5);
1736 static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
1739 struct it87_data *data = it87_update_device(dev);
1741 return sprintf(buf, "%u\n", data->alarms);
1743 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
1745 static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
1748 struct it87_data *data = it87_update_device(dev);
1749 int bitnr = to_sensor_dev_attr(attr)->index;
1751 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
1754 static ssize_t clear_intrusion(struct device *dev,
1755 struct device_attribute *attr, const char *buf,
1758 struct it87_data *data = dev_get_drvdata(dev);
1762 if (kstrtol(buf, 10, &val) < 0 || val != 0)
1765 mutex_lock(&data->update_lock);
1766 config = it87_read_value(data, IT87_REG_CONFIG);
1771 it87_write_value(data, IT87_REG_CONFIG, config);
1772 /* Invalidate cache to force re-read */
1775 mutex_unlock(&data->update_lock);
1780 static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8);
1781 static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9);
1782 static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10);
1783 static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11);
1784 static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12);
1785 static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13);
1786 static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14);
1787 static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15);
1788 static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0);
1789 static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1);
1790 static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2);
1791 static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3);
1792 static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6);
1793 static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_alarm, NULL, 7);
1794 static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16);
1795 static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17);
1796 static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18);
1797 static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR,
1798 show_alarm, clear_intrusion, 4);
1800 static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
1803 struct it87_data *data = it87_update_device(dev);
1804 int bitnr = to_sensor_dev_attr(attr)->index;
1806 return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1);
1809 static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
1810 const char *buf, size_t count)
1812 int bitnr = to_sensor_dev_attr(attr)->index;
1813 struct it87_data *data = dev_get_drvdata(dev);
1816 if (kstrtol(buf, 10, &val) < 0 || (val != 0 && val != 1))
1819 mutex_lock(&data->update_lock);
1820 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
1822 data->beeps |= BIT(bitnr);
1824 data->beeps &= ~BIT(bitnr);
1825 it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps);
1826 mutex_unlock(&data->update_lock);
1830 static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
1831 show_beep, set_beep, 1);
1832 static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO, show_beep, NULL, 1);
1833 static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO, show_beep, NULL, 1);
1834 static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO, show_beep, NULL, 1);
1835 static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO, show_beep, NULL, 1);
1836 static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO, show_beep, NULL, 1);
1837 static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO, show_beep, NULL, 1);
1838 static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO, show_beep, NULL, 1);
1839 /* fanX_beep writability is set later */
1840 static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO, show_beep, set_beep, 0);
1841 static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0);
1842 static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0);
1843 static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0);
1844 static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0);
1845 static SENSOR_DEVICE_ATTR(fan6_beep, S_IRUGO, show_beep, set_beep, 0);
1846 static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
1847 show_beep, set_beep, 2);
1848 static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2);
1849 static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2);
1851 static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
1854 struct it87_data *data = dev_get_drvdata(dev);
1856 return sprintf(buf, "%u\n", data->vrm);
1859 static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
1860 const char *buf, size_t count)
1862 struct it87_data *data = dev_get_drvdata(dev);
1865 if (kstrtoul(buf, 10, &val) < 0)
1872 static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
1874 static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
1877 struct it87_data *data = it87_update_device(dev);
1879 return sprintf(buf, "%ld\n", (long)vid_from_reg(data->vid, data->vrm));
1881 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
1883 static ssize_t show_label(struct device *dev, struct device_attribute *attr,
1886 static const char * const labels[] = {
1891 static const char * const labels_it8721[] = {
1896 struct it87_data *data = dev_get_drvdata(dev);
1897 int nr = to_sensor_dev_attr(attr)->index;
1899 return sprintf(buf, "%s\n", has_12mv_adc(data) ? labels_it8721[nr]
1902 static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0);
1903 static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1);
1904 static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 2);
1906 static SENSOR_DEVICE_ATTR(in9_label, S_IRUGO, show_label, NULL, 0);
1908 static umode_t it87_in_is_visible(struct kobject *kobj,
1909 struct attribute *attr, int index)
1911 struct device *dev = container_of(kobj, struct device, kobj);
1912 struct it87_data *data = dev_get_drvdata(dev);
1913 int i = index / 5; /* voltage index */
1914 int a = index % 5; /* attribute index */
1916 if (index >= 40) { /* in8 and higher only have input attributes */
1921 if (!(data->has_in & BIT(i)))
1924 if (a == 4 && !data->has_beep)
1930 static struct attribute *it87_attributes_in[] = {
1931 &sensor_dev_attr_in0_input.dev_attr.attr,
1932 &sensor_dev_attr_in0_min.dev_attr.attr,
1933 &sensor_dev_attr_in0_max.dev_attr.attr,
1934 &sensor_dev_attr_in0_alarm.dev_attr.attr,
1935 &sensor_dev_attr_in0_beep.dev_attr.attr, /* 4 */
1937 &sensor_dev_attr_in1_input.dev_attr.attr,
1938 &sensor_dev_attr_in1_min.dev_attr.attr,
1939 &sensor_dev_attr_in1_max.dev_attr.attr,
1940 &sensor_dev_attr_in1_alarm.dev_attr.attr,
1941 &sensor_dev_attr_in1_beep.dev_attr.attr, /* 9 */
1943 &sensor_dev_attr_in2_input.dev_attr.attr,
1944 &sensor_dev_attr_in2_min.dev_attr.attr,
1945 &sensor_dev_attr_in2_max.dev_attr.attr,
1946 &sensor_dev_attr_in2_alarm.dev_attr.attr,
1947 &sensor_dev_attr_in2_beep.dev_attr.attr, /* 14 */
1949 &sensor_dev_attr_in3_input.dev_attr.attr,
1950 &sensor_dev_attr_in3_min.dev_attr.attr,
1951 &sensor_dev_attr_in3_max.dev_attr.attr,
1952 &sensor_dev_attr_in3_alarm.dev_attr.attr,
1953 &sensor_dev_attr_in3_beep.dev_attr.attr, /* 19 */
1955 &sensor_dev_attr_in4_input.dev_attr.attr,
1956 &sensor_dev_attr_in4_min.dev_attr.attr,
1957 &sensor_dev_attr_in4_max.dev_attr.attr,
1958 &sensor_dev_attr_in4_alarm.dev_attr.attr,
1959 &sensor_dev_attr_in4_beep.dev_attr.attr, /* 24 */
1961 &sensor_dev_attr_in5_input.dev_attr.attr,
1962 &sensor_dev_attr_in5_min.dev_attr.attr,
1963 &sensor_dev_attr_in5_max.dev_attr.attr,
1964 &sensor_dev_attr_in5_alarm.dev_attr.attr,
1965 &sensor_dev_attr_in5_beep.dev_attr.attr, /* 29 */
1967 &sensor_dev_attr_in6_input.dev_attr.attr,
1968 &sensor_dev_attr_in6_min.dev_attr.attr,
1969 &sensor_dev_attr_in6_max.dev_attr.attr,
1970 &sensor_dev_attr_in6_alarm.dev_attr.attr,
1971 &sensor_dev_attr_in6_beep.dev_attr.attr, /* 34 */
1973 &sensor_dev_attr_in7_input.dev_attr.attr,
1974 &sensor_dev_attr_in7_min.dev_attr.attr,
1975 &sensor_dev_attr_in7_max.dev_attr.attr,
1976 &sensor_dev_attr_in7_alarm.dev_attr.attr,
1977 &sensor_dev_attr_in7_beep.dev_attr.attr, /* 39 */
1979 &sensor_dev_attr_in8_input.dev_attr.attr, /* 40 */
1980 &sensor_dev_attr_in9_input.dev_attr.attr, /* 41 */
1981 &sensor_dev_attr_in10_input.dev_attr.attr, /* 41 */
1982 &sensor_dev_attr_in11_input.dev_attr.attr, /* 41 */
1983 &sensor_dev_attr_in12_input.dev_attr.attr, /* 41 */
1986 static const struct attribute_group it87_group_in = {
1987 .attrs = it87_attributes_in,
1988 .is_visible = it87_in_is_visible,
1991 static umode_t it87_temp_is_visible(struct kobject *kobj,
1992 struct attribute *attr, int index)
1994 struct device *dev = container_of(kobj, struct device, kobj);
1995 struct it87_data *data = dev_get_drvdata(dev);
1996 int i = index / 7; /* temperature index */
1997 int a = index % 7; /* attribute index */
2004 if (!(data->has_temp & BIT(i)))
2007 if (a == 5 && !has_temp_offset(data))
2010 if (a == 6 && !data->has_beep)
2016 static struct attribute *it87_attributes_temp[] = {
2017 &sensor_dev_attr_temp1_input.dev_attr.attr,
2018 &sensor_dev_attr_temp1_max.dev_attr.attr,
2019 &sensor_dev_attr_temp1_min.dev_attr.attr,
2020 &sensor_dev_attr_temp1_type.dev_attr.attr,
2021 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
2022 &sensor_dev_attr_temp1_offset.dev_attr.attr, /* 5 */
2023 &sensor_dev_attr_temp1_beep.dev_attr.attr, /* 6 */
2025 &sensor_dev_attr_temp2_input.dev_attr.attr, /* 7 */
2026 &sensor_dev_attr_temp2_max.dev_attr.attr,
2027 &sensor_dev_attr_temp2_min.dev_attr.attr,
2028 &sensor_dev_attr_temp2_type.dev_attr.attr,
2029 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
2030 &sensor_dev_attr_temp2_offset.dev_attr.attr,
2031 &sensor_dev_attr_temp2_beep.dev_attr.attr,
2033 &sensor_dev_attr_temp3_input.dev_attr.attr, /* 14 */
2034 &sensor_dev_attr_temp3_max.dev_attr.attr,
2035 &sensor_dev_attr_temp3_min.dev_attr.attr,
2036 &sensor_dev_attr_temp3_type.dev_attr.attr,
2037 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
2038 &sensor_dev_attr_temp3_offset.dev_attr.attr,
2039 &sensor_dev_attr_temp3_beep.dev_attr.attr,
2041 &sensor_dev_attr_temp4_input.dev_attr.attr, /* 21 */
2042 &sensor_dev_attr_temp5_input.dev_attr.attr,
2043 &sensor_dev_attr_temp6_input.dev_attr.attr,
2047 static const struct attribute_group it87_group_temp = {
2048 .attrs = it87_attributes_temp,
2049 .is_visible = it87_temp_is_visible,
2052 static umode_t it87_is_visible(struct kobject *kobj,
2053 struct attribute *attr, int index)
2055 struct device *dev = container_of(kobj, struct device, kobj);
2056 struct it87_data *data = dev_get_drvdata(dev);
2058 if ((index == 2 || index == 3) && !data->has_vid)
2061 if (index > 3 && !(data->in_internal & BIT(index - 4)))
2067 static struct attribute *it87_attributes[] = {
2068 &dev_attr_alarms.attr,
2069 &sensor_dev_attr_intrusion0_alarm.dev_attr.attr,
2070 &dev_attr_vrm.attr, /* 2 */
2071 &dev_attr_cpu0_vid.attr, /* 3 */
2072 &sensor_dev_attr_in3_label.dev_attr.attr, /* 4 .. 7 */
2073 &sensor_dev_attr_in7_label.dev_attr.attr,
2074 &sensor_dev_attr_in8_label.dev_attr.attr,
2075 &sensor_dev_attr_in9_label.dev_attr.attr,
2079 static const struct attribute_group it87_group = {
2080 .attrs = it87_attributes,
2081 .is_visible = it87_is_visible,
2084 static umode_t it87_fan_is_visible(struct kobject *kobj,
2085 struct attribute *attr, int index)
2087 struct device *dev = container_of(kobj, struct device, kobj);
2088 struct it87_data *data = dev_get_drvdata(dev);
2089 int i = index / 5; /* fan index */
2090 int a = index % 5; /* attribute index */
2092 if (index >= 15) { /* fan 4..6 don't have divisor attributes */
2093 i = (index - 15) / 4 + 3;
2094 a = (index - 15) % 4;
2097 if (!(data->has_fan & BIT(i)))
2100 if (a == 3) { /* beep */
2101 if (!data->has_beep)
2103 /* first fan beep attribute is writable */
2104 if (i == __ffs(data->has_fan))
2105 return attr->mode | S_IWUSR;
2108 if (a == 4 && has_16bit_fans(data)) /* divisor */
2114 static struct attribute *it87_attributes_fan[] = {
2115 &sensor_dev_attr_fan1_input.dev_attr.attr,
2116 &sensor_dev_attr_fan1_min.dev_attr.attr,
2117 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
2118 &sensor_dev_attr_fan1_beep.dev_attr.attr, /* 3 */
2119 &sensor_dev_attr_fan1_div.dev_attr.attr, /* 4 */
2121 &sensor_dev_attr_fan2_input.dev_attr.attr,
2122 &sensor_dev_attr_fan2_min.dev_attr.attr,
2123 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
2124 &sensor_dev_attr_fan2_beep.dev_attr.attr,
2125 &sensor_dev_attr_fan2_div.dev_attr.attr, /* 9 */
2127 &sensor_dev_attr_fan3_input.dev_attr.attr,
2128 &sensor_dev_attr_fan3_min.dev_attr.attr,
2129 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
2130 &sensor_dev_attr_fan3_beep.dev_attr.attr,
2131 &sensor_dev_attr_fan3_div.dev_attr.attr, /* 14 */
2133 &sensor_dev_attr_fan4_input.dev_attr.attr, /* 15 */
2134 &sensor_dev_attr_fan4_min.dev_attr.attr,
2135 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
2136 &sensor_dev_attr_fan4_beep.dev_attr.attr,
2138 &sensor_dev_attr_fan5_input.dev_attr.attr, /* 19 */
2139 &sensor_dev_attr_fan5_min.dev_attr.attr,
2140 &sensor_dev_attr_fan5_alarm.dev_attr.attr,
2141 &sensor_dev_attr_fan5_beep.dev_attr.attr,
2143 &sensor_dev_attr_fan6_input.dev_attr.attr, /* 23 */
2144 &sensor_dev_attr_fan6_min.dev_attr.attr,
2145 &sensor_dev_attr_fan6_alarm.dev_attr.attr,
2146 &sensor_dev_attr_fan6_beep.dev_attr.attr,
2150 static const struct attribute_group it87_group_fan = {
2151 .attrs = it87_attributes_fan,
2152 .is_visible = it87_fan_is_visible,
2155 static umode_t it87_pwm_is_visible(struct kobject *kobj,
2156 struct attribute *attr, int index)
2158 struct device *dev = container_of(kobj, struct device, kobj);
2159 struct it87_data *data = dev_get_drvdata(dev);
2160 int i = index / 4; /* pwm index */
2161 int a = index % 4; /* attribute index */
2163 if (!(data->has_pwm & BIT(i)))
2166 /* pwmX_auto_channels_temp is only writable if auto pwm is supported */
2167 if (a == 3 && (has_old_autopwm(data) || has_newer_autopwm(data)))
2168 return attr->mode | S_IWUSR;
2170 /* pwm2_freq is writable if there are two pwm frequency selects */
2171 if (has_pwm_freq2(data) && i == 1 && a == 2)
2172 return attr->mode | S_IWUSR;
2177 static struct attribute *it87_attributes_pwm[] = {
2178 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
2179 &sensor_dev_attr_pwm1.dev_attr.attr,
2180 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
2181 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
2183 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
2184 &sensor_dev_attr_pwm2.dev_attr.attr,
2185 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
2186 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
2188 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
2189 &sensor_dev_attr_pwm3.dev_attr.attr,
2190 &sensor_dev_attr_pwm3_freq.dev_attr.attr,
2191 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
2193 &sensor_dev_attr_pwm4_enable.dev_attr.attr,
2194 &sensor_dev_attr_pwm4.dev_attr.attr,
2195 &sensor_dev_attr_pwm4_freq.dev_attr.attr,
2196 &sensor_dev_attr_pwm4_auto_channels_temp.dev_attr.attr,
2198 &sensor_dev_attr_pwm5_enable.dev_attr.attr,
2199 &sensor_dev_attr_pwm5.dev_attr.attr,
2200 &sensor_dev_attr_pwm5_freq.dev_attr.attr,
2201 &sensor_dev_attr_pwm5_auto_channels_temp.dev_attr.attr,
2203 &sensor_dev_attr_pwm6_enable.dev_attr.attr,
2204 &sensor_dev_attr_pwm6.dev_attr.attr,
2205 &sensor_dev_attr_pwm6_freq.dev_attr.attr,
2206 &sensor_dev_attr_pwm6_auto_channels_temp.dev_attr.attr,
2211 static const struct attribute_group it87_group_pwm = {
2212 .attrs = it87_attributes_pwm,
2213 .is_visible = it87_pwm_is_visible,
2216 static umode_t it87_auto_pwm_is_visible(struct kobject *kobj,
2217 struct attribute *attr, int index)
2219 struct device *dev = container_of(kobj, struct device, kobj);
2220 struct it87_data *data = dev_get_drvdata(dev);
2221 int i = index / 11; /* pwm index */
2222 int a = index % 11; /* attribute index */
2224 if (index >= 33) { /* pwm 4..6 */
2225 i = (index - 33) / 6 + 3;
2226 a = (index - 33) % 6 + 4;
2229 if (!(data->has_pwm & BIT(i)))
2232 if (has_newer_autopwm(data)) {
2233 if (a < 4) /* no auto point pwm */
2235 if (a == 8) /* no auto_point4 */
2238 if (has_old_autopwm(data)) {
2239 if (a >= 9) /* no pwm_auto_start, pwm_auto_slope */
2246 static struct attribute *it87_attributes_auto_pwm[] = {
2247 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
2248 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
2249 &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr,
2250 &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr,
2251 &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
2252 &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr,
2253 &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr,
2254 &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr,
2255 &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr,
2256 &sensor_dev_attr_pwm1_auto_start.dev_attr.attr,
2257 &sensor_dev_attr_pwm1_auto_slope.dev_attr.attr,
2259 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr, /* 11 */
2260 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
2261 &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr,
2262 &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr,
2263 &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr,
2264 &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr,
2265 &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr,
2266 &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr,
2267 &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr,
2268 &sensor_dev_attr_pwm2_auto_start.dev_attr.attr,
2269 &sensor_dev_attr_pwm2_auto_slope.dev_attr.attr,
2271 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr, /* 22 */
2272 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
2273 &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr,
2274 &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr,
2275 &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr,
2276 &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr,
2277 &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr,
2278 &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr,
2279 &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr,
2280 &sensor_dev_attr_pwm3_auto_start.dev_attr.attr,
2281 &sensor_dev_attr_pwm3_auto_slope.dev_attr.attr,
2283 &sensor_dev_attr_pwm4_auto_point1_temp.dev_attr.attr, /* 33 */
2284 &sensor_dev_attr_pwm4_auto_point1_temp_hyst.dev_attr.attr,
2285 &sensor_dev_attr_pwm4_auto_point2_temp.dev_attr.attr,
2286 &sensor_dev_attr_pwm4_auto_point3_temp.dev_attr.attr,
2287 &sensor_dev_attr_pwm4_auto_start.dev_attr.attr,
2288 &sensor_dev_attr_pwm4_auto_slope.dev_attr.attr,
2290 &sensor_dev_attr_pwm5_auto_point1_temp.dev_attr.attr,
2291 &sensor_dev_attr_pwm5_auto_point1_temp_hyst.dev_attr.attr,
2292 &sensor_dev_attr_pwm5_auto_point2_temp.dev_attr.attr,
2293 &sensor_dev_attr_pwm5_auto_point3_temp.dev_attr.attr,
2294 &sensor_dev_attr_pwm5_auto_start.dev_attr.attr,
2295 &sensor_dev_attr_pwm5_auto_slope.dev_attr.attr,
2297 &sensor_dev_attr_pwm6_auto_point1_temp.dev_attr.attr,
2298 &sensor_dev_attr_pwm6_auto_point1_temp_hyst.dev_attr.attr,
2299 &sensor_dev_attr_pwm6_auto_point2_temp.dev_attr.attr,
2300 &sensor_dev_attr_pwm6_auto_point3_temp.dev_attr.attr,
2301 &sensor_dev_attr_pwm6_auto_start.dev_attr.attr,
2302 &sensor_dev_attr_pwm6_auto_slope.dev_attr.attr,
2307 static const struct attribute_group it87_group_auto_pwm = {
2308 .attrs = it87_attributes_auto_pwm,
2309 .is_visible = it87_auto_pwm_is_visible,
2312 /* SuperIO detection - will change isa_address if a chip is found */
2313 static int __init it87_find(int sioaddr, unsigned short *address,
2314 struct it87_sio_data *sio_data)
2318 const char *board_vendor, *board_name;
2319 const struct it87_devices *config;
2321 err = superio_enter(sioaddr);
2326 chip_type = force_id ? force_id : superio_inw(sioaddr, DEVID);
2328 switch (chip_type) {
2330 sio_data->type = it87;
2333 sio_data->type = it8712;
2337 sio_data->type = it8716;
2340 sio_data->type = it8718;
2343 sio_data->type = it8720;
2346 sio_data->type = it8721;
2349 sio_data->type = it8728;
2352 sio_data->type = it8771;
2355 sio_data->type = it8772;
2358 sio_data->type = it8781;
2361 sio_data->type = it8782;
2364 sio_data->type = it8783;
2367 sio_data->type = it8786;
2370 sio_data->type = it8790;
2374 sio_data->type = it8603;
2377 sio_data->type = it8620;
2379 case 0xffff: /* No device at all */
2382 pr_debug("Unsupported chip (DEVID=0x%x)\n", chip_type);
2386 superio_select(sioaddr, PME);
2387 if (!(superio_inb(sioaddr, IT87_ACT_REG) & 0x01)) {
2388 pr_info("Device not activated, skipping\n");
2392 *address = superio_inw(sioaddr, IT87_BASE_REG) & ~(IT87_EXTENT - 1);
2393 if (*address == 0) {
2394 pr_info("Base address not set, skipping\n");
2399 sio_data->revision = superio_inb(sioaddr, DEVREV) & 0x0f;
2400 pr_info("Found IT%04x%s chip at 0x%x, revision %d\n", chip_type,
2401 it87_devices[sio_data->type].suffix,
2402 *address, sio_data->revision);
2404 config = &it87_devices[sio_data->type];
2406 /* in7 (VSB or VCCH5V) is always internal on some chips */
2407 if (has_in7_internal(config))
2408 sio_data->internal |= BIT(1);
2410 /* in8 (Vbat) is always internal */
2411 sio_data->internal |= BIT(2);
2413 /* in9 (AVCC3), always internal if supported */
2414 if (has_avcc3(config))
2415 sio_data->internal |= BIT(3); /* in9 is AVCC */
2417 sio_data->skip_in |= BIT(9);
2419 if (!has_six_pwm(config))
2420 sio_data->skip_pwm |= BIT(3) | BIT(4) | BIT(5);
2422 if (!has_vid(config))
2423 sio_data->skip_vid = 1;
2425 /* Read GPIO config and VID value from LDN 7 (GPIO) */
2426 if (sio_data->type == it87) {
2427 /* The IT8705F has a different LD number for GPIO */
2428 superio_select(sioaddr, 5);
2429 sio_data->beep_pin = superio_inb(sioaddr,
2430 IT87_SIO_BEEP_PIN_REG) & 0x3f;
2431 } else if (sio_data->type == it8783) {
2432 int reg25, reg27, reg2a, reg2c, regef;
2434 superio_select(sioaddr, GPIO);
2436 reg25 = superio_inb(sioaddr, IT87_SIO_GPIO1_REG);
2437 reg27 = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
2438 reg2a = superio_inb(sioaddr, IT87_SIO_PINX1_REG);
2439 reg2c = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
2440 regef = superio_inb(sioaddr, IT87_SIO_SPI_REG);
2442 /* Check if fan3 is there or not */
2443 if ((reg27 & BIT(0)) || !(reg2c & BIT(2)))
2444 sio_data->skip_fan |= BIT(2);
2445 if ((reg25 & BIT(4)) ||
2446 (!(reg2a & BIT(1)) && (regef & BIT(0))))
2447 sio_data->skip_pwm |= BIT(2);
2449 /* Check if fan2 is there or not */
2451 sio_data->skip_fan |= BIT(1);
2453 sio_data->skip_pwm |= BIT(1);
2456 if ((reg27 & BIT(0)) || (reg2c & BIT(2)))
2457 sio_data->skip_in |= BIT(5); /* No VIN5 */
2461 sio_data->skip_in |= BIT(6); /* No VIN6 */
2465 * Does not depend on bit 2 of Reg2C, contrary to datasheet.
2467 if (reg27 & BIT(2)) {
2469 * The data sheet is a bit unclear regarding the
2470 * internal voltage divider for VCCH5V. It says
2471 * "This bit enables and switches VIN7 (pin 91) to the
2472 * internal voltage divider for VCCH5V".
2473 * This is different to other chips, where the internal
2474 * voltage divider would connect VIN7 to an internal
2475 * voltage source. Maybe that is the case here as well.
2477 * Since we don't know for sure, re-route it if that is
2478 * not the case, and ask the user to report if the
2479 * resulting voltage is sane.
2481 if (!(reg2c & BIT(1))) {
2483 superio_outb(sioaddr, IT87_SIO_PINX2_REG,
2485 pr_notice("Routing internal VCCH5V to in7.\n");
2487 pr_notice("in7 routed to internal voltage divider, with external pin disabled.\n");
2488 pr_notice("Please report if it displays a reasonable voltage.\n");
2492 sio_data->internal |= BIT(0);
2494 sio_data->internal |= BIT(1);
2496 sio_data->beep_pin = superio_inb(sioaddr,
2497 IT87_SIO_BEEP_PIN_REG) & 0x3f;
2498 } else if (sio_data->type == it8603) {
2501 superio_select(sioaddr, GPIO);
2503 reg27 = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
2505 /* Check if fan3 is there or not */
2507 sio_data->skip_pwm |= BIT(2);
2509 sio_data->skip_fan |= BIT(2);
2511 /* Check if fan2 is there or not */
2512 reg29 = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
2514 sio_data->skip_pwm |= BIT(1);
2516 sio_data->skip_fan |= BIT(1);
2518 sio_data->skip_in |= BIT(5); /* No VIN5 */
2519 sio_data->skip_in |= BIT(6); /* No VIN6 */
2521 sio_data->beep_pin = superio_inb(sioaddr,
2522 IT87_SIO_BEEP_PIN_REG) & 0x3f;
2523 } else if (sio_data->type == it8620) {
2526 superio_select(sioaddr, GPIO);
2528 /* Check for pwm5 */
2529 reg = superio_inb(sioaddr, IT87_SIO_GPIO1_REG);
2531 sio_data->skip_pwm |= BIT(4);
2533 /* Check for fan4, fan5 */
2534 reg = superio_inb(sioaddr, IT87_SIO_GPIO2_REG);
2535 if (!(reg & BIT(5)))
2536 sio_data->skip_fan |= BIT(3);
2537 if (!(reg & BIT(4)))
2538 sio_data->skip_fan |= BIT(4);
2540 /* Check for pwm3, fan3 */
2541 reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
2543 sio_data->skip_pwm |= BIT(2);
2545 sio_data->skip_fan |= BIT(2);
2547 /* Check for pwm4 */
2548 reg = superio_inb(sioaddr, IT87_SIO_GPIO4_REG);
2549 if (!(reg & BIT(4)))
2550 sio_data->skip_pwm |= BIT(3);
2552 /* Check for pwm2, fan2 */
2553 reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
2555 sio_data->skip_pwm |= BIT(1);
2557 sio_data->skip_fan |= BIT(1);
2558 /* Check for pwm6, fan6 */
2559 if (!(reg & BIT(7))) {
2560 sio_data->skip_pwm |= BIT(5);
2561 sio_data->skip_fan |= BIT(5);
2564 sio_data->beep_pin = superio_inb(sioaddr,
2565 IT87_SIO_BEEP_PIN_REG) & 0x3f;
2570 superio_select(sioaddr, GPIO);
2572 /* Check for fan4, fan5 */
2573 if (has_five_fans(config)) {
2574 reg = superio_inb(sioaddr, IT87_SIO_GPIO2_REG);
2575 switch (sio_data->type) {
2578 sio_data->skip_fan |= BIT(3);
2580 sio_data->skip_fan |= BIT(4);
2585 if (!(reg & BIT(5)))
2586 sio_data->skip_fan |= BIT(3);
2587 if (!(reg & BIT(4)))
2588 sio_data->skip_fan |= BIT(4);
2595 reg = superio_inb(sioaddr, IT87_SIO_GPIO3_REG);
2596 if (!sio_data->skip_vid) {
2597 /* We need at least 4 VID pins */
2599 pr_info("VID is disabled (pins used for GPIO)\n");
2600 sio_data->skip_vid = 1;
2604 /* Check if fan3 is there or not */
2606 sio_data->skip_pwm |= BIT(2);
2608 sio_data->skip_fan |= BIT(2);
2610 /* Check if fan2 is there or not */
2611 reg = superio_inb(sioaddr, IT87_SIO_GPIO5_REG);
2613 sio_data->skip_pwm |= BIT(1);
2615 sio_data->skip_fan |= BIT(1);
2617 if ((sio_data->type == it8718 || sio_data->type == it8720) &&
2618 !(sio_data->skip_vid))
2619 sio_data->vid_value = superio_inb(sioaddr,
2622 reg = superio_inb(sioaddr, IT87_SIO_PINX2_REG);
2624 uart6 = sio_data->type == it8782 && (reg & BIT(2));
2627 * The IT8720F has no VIN7 pin, so VCCH should always be
2628 * routed internally to VIN7 with an internal divider.
2629 * Curiously, there still is a configuration bit to control
2630 * this, which means it can be set incorrectly. And even
2631 * more curiously, many boards out there are improperly
2632 * configured, even though the IT8720F datasheet claims
2633 * that the internal routing of VCCH to VIN7 is the default
2634 * setting. So we force the internal routing in this case.
2636 * On IT8782F, VIN7 is multiplexed with one of the UART6 pins.
2637 * If UART6 is enabled, re-route VIN7 to the internal divider
2638 * if that is not already the case.
2640 if ((sio_data->type == it8720 || uart6) && !(reg & BIT(1))) {
2642 superio_outb(sioaddr, IT87_SIO_PINX2_REG, reg);
2643 pr_notice("Routing internal VCCH to in7\n");
2646 sio_data->internal |= BIT(0);
2648 sio_data->internal |= BIT(1);
2651 * On IT8782F, UART6 pins overlap with VIN5, VIN6, and VIN7.
2652 * While VIN7 can be routed to the internal voltage divider,
2653 * VIN5 and VIN6 are not available if UART6 is enabled.
2655 * Also, temp3 is not available if UART6 is enabled and TEMPIN3
2656 * is the temperature source. Since we can not read the
2657 * temperature source here, skip_temp is preliminary.
2660 sio_data->skip_in |= BIT(5) | BIT(6);
2661 sio_data->skip_temp |= BIT(2);
2664 sio_data->beep_pin = superio_inb(sioaddr,
2665 IT87_SIO_BEEP_PIN_REG) & 0x3f;
2667 if (sio_data->beep_pin)
2668 pr_info("Beeping is supported\n");
2670 /* Disable specific features based on DMI strings */
2671 board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
2672 board_name = dmi_get_system_info(DMI_BOARD_NAME);
2673 if (board_vendor && board_name) {
2674 if (strcmp(board_vendor, "nVIDIA") == 0 &&
2675 strcmp(board_name, "FN68PT") == 0) {
2677 * On the Shuttle SN68PT, FAN_CTL2 is apparently not
2678 * connected to a fan, but to something else. One user
2679 * has reported instant system power-off when changing
2680 * the PWM2 duty cycle, so we disable it.
2681 * I use the board name string as the trigger in case
2682 * the same board is ever used in other systems.
2684 pr_info("Disabling pwm2 due to hardware constraints\n");
2685 sio_data->skip_pwm = BIT(1);
2690 superio_exit(sioaddr);
2694 /* Called when we have found a new IT87. */
2695 static void it87_init_device(struct platform_device *pdev)
2697 struct it87_sio_data *sio_data = dev_get_platdata(&pdev->dev);
2698 struct it87_data *data = platform_get_drvdata(pdev);
2703 * For each PWM channel:
2704 * - If it is in automatic mode, setting to manual mode should set
2705 * the fan to full speed by default.
2706 * - If it is in manual mode, we need a mapping to temperature
2707 * channels to use when later setting to automatic mode later.
2708 * Use a 1:1 mapping by default (we are clueless.)
2709 * In both cases, the value can (and should) be changed by the user
2710 * prior to switching to a different mode.
2711 * Note that this is no longer needed for the IT8721F and later, as
2712 * these have separate registers for the temperature mapping and the
2713 * manual duty cycle.
2715 for (i = 0; i < NUM_AUTO_PWM; i++) {
2716 data->pwm_temp_map[i] = i;
2717 data->pwm_duty[i] = 0x7f; /* Full speed */
2718 data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */
2722 * Some chips seem to have default value 0xff for all limit
2723 * registers. For low voltage limits it makes no sense and triggers
2724 * alarms, so change to 0 instead. For high temperature limits, it
2725 * means -1 degree C, which surprisingly doesn't trigger an alarm,
2726 * but is still confusing, so change to 127 degrees C.
2728 for (i = 0; i < NUM_VIN_LIMIT; i++) {
2729 tmp = it87_read_value(data, IT87_REG_VIN_MIN(i));
2731 it87_write_value(data, IT87_REG_VIN_MIN(i), 0);
2733 for (i = 0; i < NUM_TEMP_LIMIT; i++) {
2734 tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i));
2736 it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127);
2740 * Temperature channels are not forcibly enabled, as they can be
2741 * set to two different sensor types and we can't guess which one
2742 * is correct for a given system. These channels can be enabled at
2743 * run-time through the temp{1-3}_type sysfs accessors if needed.
2746 /* Check if voltage monitors are reset manually or by some reason */
2747 tmp = it87_read_value(data, IT87_REG_VIN_ENABLE);
2748 if ((tmp & 0xff) == 0) {
2749 /* Enable all voltage monitors */
2750 it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff);
2753 /* Check if tachometers are reset manually or by some reason */
2754 mask = 0x70 & ~(sio_data->skip_fan << 4);
2755 data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL);
2756 if ((data->fan_main_ctrl & mask) == 0) {
2757 /* Enable all fan tachometers */
2758 data->fan_main_ctrl |= mask;
2759 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
2760 data->fan_main_ctrl);
2762 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
2764 tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
2766 /* Set tachometers to 16-bit mode if needed */
2767 if (has_fan16_config(data)) {
2768 if (~tmp & 0x07 & data->has_fan) {
2770 "Setting fan1-3 to 16-bit mode\n");
2771 it87_write_value(data, IT87_REG_FAN_16BIT,
2776 /* Check for additional fans */
2777 if (has_five_fans(data)) {
2779 data->has_fan |= BIT(3); /* fan4 enabled */
2781 data->has_fan |= BIT(4); /* fan5 enabled */
2782 if (has_six_fans(data) && (tmp & BIT(2)))
2783 data->has_fan |= BIT(5); /* fan6 enabled */
2786 /* Fan input pins may be used for alternative functions */
2787 data->has_fan &= ~sio_data->skip_fan;
2789 /* Check if pwm5, pwm6 are enabled */
2790 if (has_six_pwm(data)) {
2791 /* The following code may be IT8620E specific */
2792 tmp = it87_read_value(data, IT87_REG_FAN_DIV);
2793 if ((tmp & 0xc0) == 0xc0)
2794 sio_data->skip_pwm |= BIT(4);
2795 if (!(tmp & BIT(3)))
2796 sio_data->skip_pwm |= BIT(5);
2799 /* Start monitoring */
2800 it87_write_value(data, IT87_REG_CONFIG,
2801 (it87_read_value(data, IT87_REG_CONFIG) & 0x3e)
2802 | (update_vbat ? 0x41 : 0x01));
2805 /* Return 1 if and only if the PWM interface is safe to use */
2806 static int it87_check_pwm(struct device *dev)
2808 struct it87_data *data = dev_get_drvdata(dev);
2810 * Some BIOSes fail to correctly configure the IT87 fans. All fans off
2811 * and polarity set to active low is sign that this is the case so we
2812 * disable pwm control to protect the user.
2814 int tmp = it87_read_value(data, IT87_REG_FAN_CTL);
2816 if ((tmp & 0x87) == 0) {
2817 if (fix_pwm_polarity) {
2819 * The user asks us to attempt a chip reconfiguration.
2820 * This means switching to active high polarity and
2821 * inverting all fan speed values.
2826 for (i = 0; i < ARRAY_SIZE(pwm); i++)
2827 pwm[i] = it87_read_value(data,
2831 * If any fan is in automatic pwm mode, the polarity
2832 * might be correct, as suspicious as it seems, so we
2833 * better don't change anything (but still disable the
2836 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
2838 "Reconfiguring PWM to active high polarity\n");
2839 it87_write_value(data, IT87_REG_FAN_CTL,
2841 for (i = 0; i < 3; i++)
2842 it87_write_value(data,
2849 "PWM configuration is too broken to be fixed\n");
2853 "Detected broken BIOS defaults, disabling PWM interface\n");
2855 } else if (fix_pwm_polarity) {
2857 "PWM configuration looks sane, won't touch\n");
2863 static int it87_probe(struct platform_device *pdev)
2865 struct it87_data *data;
2866 struct resource *res;
2867 struct device *dev = &pdev->dev;
2868 struct it87_sio_data *sio_data = dev_get_platdata(dev);
2869 int enable_pwm_interface;
2870 struct device *hwmon_dev;
2872 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
2873 if (!devm_request_region(&pdev->dev, res->start, IT87_EC_EXTENT,
2875 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
2876 (unsigned long)res->start,
2877 (unsigned long)(res->start + IT87_EC_EXTENT - 1));
2881 data = devm_kzalloc(&pdev->dev, sizeof(struct it87_data), GFP_KERNEL);
2885 data->addr = res->start;
2886 data->type = sio_data->type;
2887 data->features = it87_devices[sio_data->type].features;
2888 data->peci_mask = it87_devices[sio_data->type].peci_mask;
2889 data->old_peci_mask = it87_devices[sio_data->type].old_peci_mask;
2891 * IT8705F Datasheet 0.4.1, 3h == Version G.
2892 * IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J.
2893 * These are the first revisions with 16-bit tachometer support.
2895 switch (data->type) {
2897 if (sio_data->revision >= 0x03) {
2898 data->features &= ~FEAT_OLD_AUTOPWM;
2899 data->features |= FEAT_FAN16_CONFIG | FEAT_16BIT_FANS;
2903 if (sio_data->revision >= 0x08) {
2904 data->features &= ~FEAT_OLD_AUTOPWM;
2905 data->features |= FEAT_FAN16_CONFIG | FEAT_16BIT_FANS |
2913 /* Now, we do the remaining detection. */
2914 if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80) ||
2915 it87_read_value(data, IT87_REG_CHIPID) != 0x90)
2918 platform_set_drvdata(pdev, data);
2920 mutex_init(&data->update_lock);
2922 /* Check PWM configuration */
2923 enable_pwm_interface = it87_check_pwm(dev);
2925 /* Starting with IT8721F, we handle scaling of internal voltages */
2926 if (has_12mv_adc(data)) {
2927 if (sio_data->internal & BIT(0))
2928 data->in_scaled |= BIT(3); /* in3 is AVCC */
2929 if (sio_data->internal & BIT(1))
2930 data->in_scaled |= BIT(7); /* in7 is VSB */
2931 if (sio_data->internal & BIT(2))
2932 data->in_scaled |= BIT(8); /* in8 is Vbat */
2933 if (sio_data->internal & BIT(3))
2934 data->in_scaled |= BIT(9); /* in9 is AVCC */
2935 } else if (sio_data->type == it8781 || sio_data->type == it8782 ||
2936 sio_data->type == it8783) {
2937 if (sio_data->internal & BIT(0))
2938 data->in_scaled |= BIT(3); /* in3 is VCC5V */
2939 if (sio_data->internal & BIT(1))
2940 data->in_scaled |= BIT(7); /* in7 is VCCH5V */
2943 data->has_temp = 0x07;
2944 if (sio_data->skip_temp & BIT(2)) {
2945 if (sio_data->type == it8782 &&
2946 !(it87_read_value(data, IT87_REG_TEMP_EXTRA) & 0x80))
2947 data->has_temp &= ~BIT(2);
2950 data->in_internal = sio_data->internal;
2951 data->has_in = 0x3ff & ~sio_data->skip_in;
2953 if (has_six_temp(data)) {
2954 u8 reg = it87_read_value(data, IT87_REG_TEMP456_ENABLE);
2956 /* Check for additional temperature sensors */
2957 if ((reg & 0x03) >= 0x02)
2958 data->has_temp |= BIT(3);
2959 if (((reg >> 2) & 0x03) >= 0x02)
2960 data->has_temp |= BIT(4);
2961 if (((reg >> 4) & 0x03) >= 0x02)
2962 data->has_temp |= BIT(5);
2964 /* Check for additional voltage sensors */
2965 if ((reg & 0x03) == 0x01)
2966 data->has_in |= BIT(10);
2967 if (((reg >> 2) & 0x03) == 0x01)
2968 data->has_in |= BIT(11);
2969 if (((reg >> 4) & 0x03) == 0x01)
2970 data->has_in |= BIT(12);
2973 data->has_beep = !!sio_data->beep_pin;
2975 /* Initialize the IT87 chip */
2976 it87_init_device(pdev);
2978 if (!sio_data->skip_vid) {
2979 data->has_vid = true;
2980 data->vrm = vid_which_vrm();
2981 /* VID reading from Super-I/O config space if available */
2982 data->vid = sio_data->vid_value;
2985 /* Prepare for sysfs hooks */
2986 data->groups[0] = &it87_group;
2987 data->groups[1] = &it87_group_in;
2988 data->groups[2] = &it87_group_temp;
2989 data->groups[3] = &it87_group_fan;
2991 if (enable_pwm_interface) {
2992 data->has_pwm = BIT(ARRAY_SIZE(IT87_REG_PWM)) - 1;
2993 data->has_pwm &= ~sio_data->skip_pwm;
2995 data->groups[4] = &it87_group_pwm;
2996 if (has_old_autopwm(data) || has_newer_autopwm(data))
2997 data->groups[5] = &it87_group_auto_pwm;
3000 hwmon_dev = devm_hwmon_device_register_with_groups(dev,
3001 it87_devices[sio_data->type].name,
3002 data, data->groups);
3003 return PTR_ERR_OR_ZERO(hwmon_dev);
3006 static struct platform_driver it87_driver = {
3010 .probe = it87_probe,
3013 static int __init it87_device_add(int index, unsigned short address,
3014 const struct it87_sio_data *sio_data)
3016 struct platform_device *pdev;
3017 struct resource res = {
3018 .start = address + IT87_EC_OFFSET,
3019 .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1,
3021 .flags = IORESOURCE_IO,
3025 err = acpi_check_resource_conflict(&res);
3029 pdev = platform_device_alloc(DRVNAME, address);
3033 err = platform_device_add_resources(pdev, &res, 1);
3035 pr_err("Device resource addition failed (%d)\n", err);
3036 goto exit_device_put;
3039 err = platform_device_add_data(pdev, sio_data,
3040 sizeof(struct it87_sio_data));
3042 pr_err("Platform data allocation failed\n");
3043 goto exit_device_put;
3046 err = platform_device_add(pdev);
3048 pr_err("Device addition failed (%d)\n", err);
3049 goto exit_device_put;
3052 it87_pdev[index] = pdev;
3056 platform_device_put(pdev);
3060 static int __init sm_it87_init(void)
3062 int sioaddr[2] = { REG_2E, REG_4E };
3063 struct it87_sio_data sio_data;
3064 unsigned short isa_address;
3068 err = platform_driver_register(&it87_driver);
3072 for (i = 0; i < ARRAY_SIZE(sioaddr); i++) {
3073 memset(&sio_data, 0, sizeof(struct it87_sio_data));
3075 err = it87_find(sioaddr[i], &isa_address, &sio_data);
3076 if (err || isa_address == 0)
3079 err = it87_device_add(i, isa_address, &sio_data);
3081 goto exit_dev_unregister;
3087 goto exit_unregister;
3091 exit_dev_unregister:
3092 /* NULL check handled by platform_device_unregister */
3093 platform_device_unregister(it87_pdev[0]);
3095 platform_driver_unregister(&it87_driver);
3099 static void __exit sm_it87_exit(void)
3101 /* NULL check handled by platform_device_unregister */
3102 platform_device_unregister(it87_pdev[1]);
3103 platform_device_unregister(it87_pdev[0]);
3104 platform_driver_unregister(&it87_driver);
3107 MODULE_AUTHOR("Chris Gauthron, Jean Delvare <jdelvare@suse.de>");
3108 MODULE_DESCRIPTION("IT8705F/IT871xF/IT872xF hardware monitoring driver");
3109 module_param(update_vbat, bool, 0);
3110 MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
3111 module_param(fix_pwm_polarity, bool, 0);
3112 MODULE_PARM_DESC(fix_pwm_polarity,
3113 "Force PWM polarity to active high (DANGEROUS)");
3114 MODULE_LICENSE("GPL");
3116 module_init(sm_it87_init);
3117 module_exit(sm_it87_exit);