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 * IT8623E Super I/O chip w/LPC interface
15 * IT8705F Super I/O chip w/LPC interface
16 * IT8712F Super I/O chip w/LPC interface
17 * IT8716F Super I/O chip w/LPC interface
18 * IT8718F Super I/O chip w/LPC interface
19 * IT8720F Super I/O chip w/LPC interface
20 * IT8721F Super I/O chip w/LPC interface
21 * IT8726F Super I/O chip w/LPC interface
22 * IT8728F Super I/O chip w/LPC interface
23 * IT8758E Super I/O chip w/LPC interface
24 * IT8771E Super I/O chip w/LPC interface
25 * IT8772E Super I/O chip w/LPC interface
26 * IT8781F Super I/O chip w/LPC interface
27 * IT8782F Super I/O chip w/LPC interface
28 * IT8783E/F Super I/O chip w/LPC interface
29 * Sis950 A clone of the IT8705F
31 * Copyright (C) 2001 Chris Gauthron
32 * Copyright (C) 2005-2010 Jean Delvare <jdelvare@suse.de>
34 * This program is free software; you can redistribute it and/or modify
35 * it under the terms of the GNU General Public License as published by
36 * the Free Software Foundation; either version 2 of the License, or
37 * (at your option) any later version.
39 * This program is distributed in the hope that it will be useful,
40 * but WITHOUT ANY WARRANTY; without even the implied warranty of
41 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42 * GNU General Public License for more details.
44 * You should have received a copy of the GNU General Public License
45 * along with this program; if not, write to the Free Software
46 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
49 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
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, it8603 };
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 *pdev;
79 #define REG 0x2e /* The register to read/write */
80 #define DEV 0x07 /* Register: Logical device select */
81 #define VAL 0x2f /* The value to read/write */
82 #define PME 0x04 /* The device with the fan registers in it */
84 /* The device with the IT8718F/IT8720F VID value in it */
87 #define DEVID 0x20 /* Register: Device ID */
88 #define DEVREV 0x22 /* Register: Device Revision */
90 static inline int superio_inb(int reg)
96 static inline void superio_outb(int reg, int val)
102 static int superio_inw(int reg)
112 static inline void superio_select(int ldn)
118 static inline int superio_enter(void)
121 * Try to reserve REG and REG + 1 for exclusive access.
123 if (!request_muxed_region(REG, 2, DRVNAME))
133 static inline void superio_exit(void)
137 release_region(REG, 2);
140 /* Logical device 4 registers */
141 #define IT8712F_DEVID 0x8712
142 #define IT8705F_DEVID 0x8705
143 #define IT8716F_DEVID 0x8716
144 #define IT8718F_DEVID 0x8718
145 #define IT8720F_DEVID 0x8720
146 #define IT8721F_DEVID 0x8721
147 #define IT8726F_DEVID 0x8726
148 #define IT8728F_DEVID 0x8728
149 #define IT8771E_DEVID 0x8771
150 #define IT8772E_DEVID 0x8772
151 #define IT8781F_DEVID 0x8781
152 #define IT8782F_DEVID 0x8782
153 #define IT8783E_DEVID 0x8783
154 #define IT8603E_DEVID 0x8603
155 #define IT8623E_DEVID 0x8623
156 #define IT87_ACT_REG 0x30
157 #define IT87_BASE_REG 0x60
159 /* Logical device 7 registers (IT8712F and later) */
160 #define IT87_SIO_GPIO1_REG 0x25
161 #define IT87_SIO_GPIO3_REG 0x27
162 #define IT87_SIO_GPIO5_REG 0x29
163 #define IT87_SIO_PINX1_REG 0x2a /* Pin selection */
164 #define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
165 #define IT87_SIO_SPI_REG 0xef /* SPI function pin select */
166 #define IT87_SIO_VID_REG 0xfc /* VID value */
167 #define IT87_SIO_BEEP_PIN_REG 0xf6 /* Beep pin mapping */
169 /* Update battery voltage after every reading if true */
170 static bool update_vbat;
172 /* Not all BIOSes properly configure the PWM registers */
173 static bool fix_pwm_polarity;
175 /* Many IT87 constants specified below */
177 /* Length of ISA address segment */
178 #define IT87_EXTENT 8
180 /* Length of ISA address segment for Environmental Controller */
181 #define IT87_EC_EXTENT 2
183 /* Offset of EC registers from ISA base address */
184 #define IT87_EC_OFFSET 5
186 /* Where are the ISA address/data registers relative to the EC base address */
187 #define IT87_ADDR_REG_OFFSET 0
188 #define IT87_DATA_REG_OFFSET 1
190 /*----- The IT87 registers -----*/
192 #define IT87_REG_CONFIG 0x00
194 #define IT87_REG_ALARM1 0x01
195 #define IT87_REG_ALARM2 0x02
196 #define IT87_REG_ALARM3 0x03
199 * The IT8718F and IT8720F have the VID value in a different register, in
200 * Super-I/O configuration space.
202 #define IT87_REG_VID 0x0a
204 * The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b
205 * for fan divisors. Later IT8712F revisions must use 16-bit tachometer
208 #define IT87_REG_FAN_DIV 0x0b
209 #define IT87_REG_FAN_16BIT 0x0c
211 /* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */
213 static const u8 IT87_REG_FAN[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82 };
214 static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86 };
215 static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83 };
216 static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 };
217 static const u8 IT87_REG_TEMP_OFFSET[] = { 0x56, 0x57, 0x59 };
219 #define IT87_REG_FAN_MAIN_CTRL 0x13
220 #define IT87_REG_FAN_CTL 0x14
221 #define IT87_REG_PWM(nr) (0x15 + (nr))
222 #define IT87_REG_PWM_DUTY(nr) (0x63 + (nr) * 8)
224 #define IT87_REG_VIN(nr) (0x20 + (nr))
225 #define IT87_REG_TEMP(nr) (0x29 + (nr))
227 #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2)
228 #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2)
229 #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2)
230 #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2)
232 #define IT87_REG_VIN_ENABLE 0x50
233 #define IT87_REG_TEMP_ENABLE 0x51
234 #define IT87_REG_TEMP_EXTRA 0x55
235 #define IT87_REG_BEEP_ENABLE 0x5c
237 #define IT87_REG_CHIPID 0x58
239 #define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i))
240 #define IT87_REG_AUTO_PWM(nr, i) (0x65 + (nr) * 8 + (i))
242 struct it87_devices {
249 #define FEAT_12MV_ADC (1 << 0)
250 #define FEAT_NEWER_AUTOPWM (1 << 1)
251 #define FEAT_OLD_AUTOPWM (1 << 2)
252 #define FEAT_16BIT_FANS (1 << 3)
253 #define FEAT_TEMP_OFFSET (1 << 4)
254 #define FEAT_TEMP_PECI (1 << 5)
255 #define FEAT_TEMP_OLD_PECI (1 << 6)
256 #define FEAT_FAN16_CONFIG (1 << 7) /* Need to enable 16-bit fans */
257 #define FEAT_FIVE_FANS (1 << 8) /* Supports five fans */
259 static const struct it87_devices it87_devices[] = {
262 .features = FEAT_OLD_AUTOPWM | FEAT_FAN16_CONFIG,
263 /* may need to overwrite */
267 .features = FEAT_OLD_AUTOPWM | FEAT_FAN16_CONFIG,
268 /* may need to overwrite */
272 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
273 | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS,
277 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
278 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS,
279 .old_peci_mask = 0x4,
283 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
284 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS,
285 .old_peci_mask = 0x4,
289 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
290 | FEAT_TEMP_OFFSET | FEAT_TEMP_OLD_PECI | FEAT_TEMP_PECI
291 | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS,
293 .old_peci_mask = 0x02, /* Actually reports PCH */
297 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
298 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_FIVE_FANS,
303 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
304 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI,
305 /* PECI: guesswork */
307 /* 16 bit fans (OHM) */
308 /* three fans, always 16 bit (guesswork) */
313 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
314 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI,
315 /* PECI (coreboot) */
316 /* 12mV ADC (HWSensors4, OHM) */
317 /* 16 bit fans (HWSensors4, OHM) */
318 /* three fans, always 16 bit (datasheet) */
323 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
324 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG,
325 .old_peci_mask = 0x4,
329 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
330 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG,
331 .old_peci_mask = 0x4,
335 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
336 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG,
337 .old_peci_mask = 0x4,
341 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
342 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI,
347 #define has_16bit_fans(data) ((data)->features & FEAT_16BIT_FANS)
348 #define has_12mv_adc(data) ((data)->features & FEAT_12MV_ADC)
349 #define has_newer_autopwm(data) ((data)->features & FEAT_NEWER_AUTOPWM)
350 #define has_old_autopwm(data) ((data)->features & FEAT_OLD_AUTOPWM)
351 #define has_temp_offset(data) ((data)->features & FEAT_TEMP_OFFSET)
352 #define has_temp_peci(data, nr) (((data)->features & FEAT_TEMP_PECI) && \
353 ((data)->peci_mask & (1 << nr)))
354 #define has_temp_old_peci(data, nr) \
355 (((data)->features & FEAT_TEMP_OLD_PECI) && \
356 ((data)->old_peci_mask & (1 << nr)))
357 #define has_fan16_config(data) (has_16bit_fans(data) && \
358 ((data)->features & FEAT_FAN16_CONFIG))
359 #define has_five_fans(data) ((data)->features & FEAT_FIVE_FANS)
361 struct it87_sio_data {
363 /* Values read from Super-I/O config space */
367 u8 internal; /* Internal sensors can be labeled */
368 /* Features skipped based on config or DMI */
377 * For each registered chip, we need to keep some data in memory.
378 * The structure is dynamically allocated.
381 struct device *hwmon_dev;
389 struct mutex update_lock;
390 char valid; /* !=0 if following fields are valid */
391 unsigned long last_updated; /* In jiffies */
393 u16 in_scaled; /* Internal voltage sensors are scaled */
394 u8 in[10][3]; /* [nr][0]=in, [1]=min, [2]=max */
395 u8 has_fan; /* Bitfield, fans enabled */
396 u16 fan[5][2]; /* Register values, [nr][0]=fan, [1]=min */
397 u8 has_temp; /* Bitfield, temp sensors enabled */
398 s8 temp[3][4]; /* [nr][0]=temp, [1]=min, [2]=max, [3]=offset */
399 u8 sensor; /* Register value (IT87_REG_TEMP_ENABLE) */
400 u8 extra; /* Register value (IT87_REG_TEMP_EXTRA) */
401 u8 fan_div[3]; /* Register encoding, shifted right */
402 u8 vid; /* Register encoding, combined */
404 u32 alarms; /* Register encoding, combined */
405 u8 beeps; /* Register encoding */
406 u8 fan_main_ctrl; /* Register value */
407 u8 fan_ctl; /* Register value */
410 * The following 3 arrays correspond to the same registers up to
411 * the IT8720F. The meaning of bits 6-0 depends on the value of bit
412 * 7, and we want to preserve settings on mode changes, so we have
413 * to track all values separately.
414 * Starting with the IT8721F, the manual PWM duty cycles are stored
415 * in separate registers (8-bit values), so the separate tracking
416 * is no longer needed, but it is still done to keep the driver
419 u8 pwm_ctrl[3]; /* Register value */
420 u8 pwm_duty[3]; /* Manual PWM value set by user */
421 u8 pwm_temp_map[3]; /* PWM to temp. chan. mapping (bits 1-0) */
423 /* Automatic fan speed control registers */
424 u8 auto_pwm[3][4]; /* [nr][3] is hard-coded */
425 s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */
428 static int adc_lsb(const struct it87_data *data, int nr)
430 int lsb = has_12mv_adc(data) ? 12 : 16;
431 if (data->in_scaled & (1 << nr))
436 static u8 in_to_reg(const struct it87_data *data, int nr, long val)
438 val = DIV_ROUND_CLOSEST(val, adc_lsb(data, nr));
439 return clamp_val(val, 0, 255);
442 static int in_from_reg(const struct it87_data *data, int nr, int val)
444 return val * adc_lsb(data, nr);
447 static inline u8 FAN_TO_REG(long rpm, int div)
451 rpm = clamp_val(rpm, 1, 1000000);
452 return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
455 static inline u16 FAN16_TO_REG(long rpm)
459 return clamp_val((1350000 + rpm) / (rpm * 2), 1, 0xfffe);
462 #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \
463 1350000 / ((val) * (div)))
464 /* The divider is fixed to 2 in 16-bit mode */
465 #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
466 1350000 / ((val) * 2))
468 #define TEMP_TO_REG(val) (clamp_val(((val) < 0 ? (((val) - 500) / 1000) : \
469 ((val) + 500) / 1000), -128, 127))
470 #define TEMP_FROM_REG(val) ((val) * 1000)
472 static u8 pwm_to_reg(const struct it87_data *data, long val)
474 if (has_newer_autopwm(data))
480 static int pwm_from_reg(const struct it87_data *data, u8 reg)
482 if (has_newer_autopwm(data))
485 return (reg & 0x7f) << 1;
489 static int DIV_TO_REG(int val)
492 while (answer < 7 && (val >>= 1))
496 #define DIV_FROM_REG(val) (1 << (val))
498 static const unsigned int pwm_freq[8] = {
509 static int it87_probe(struct platform_device *pdev);
510 static int it87_remove(struct platform_device *pdev);
512 static int it87_read_value(struct it87_data *data, u8 reg);
513 static void it87_write_value(struct it87_data *data, u8 reg, u8 value);
514 static struct it87_data *it87_update_device(struct device *dev);
515 static int it87_check_pwm(struct device *dev);
516 static void it87_init_device(struct platform_device *pdev);
519 static struct platform_driver it87_driver = {
524 .remove = it87_remove,
527 static ssize_t show_in(struct device *dev, struct device_attribute *attr,
530 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
532 int index = sattr->index;
534 struct it87_data *data = it87_update_device(dev);
535 return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr][index]));
538 static ssize_t set_in(struct device *dev, struct device_attribute *attr,
539 const char *buf, size_t count)
541 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
543 int index = sattr->index;
545 struct it87_data *data = dev_get_drvdata(dev);
548 if (kstrtoul(buf, 10, &val) < 0)
551 mutex_lock(&data->update_lock);
552 data->in[nr][index] = in_to_reg(data, nr, val);
553 it87_write_value(data,
554 index == 1 ? IT87_REG_VIN_MIN(nr)
555 : IT87_REG_VIN_MAX(nr),
556 data->in[nr][index]);
557 mutex_unlock(&data->update_lock);
561 static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0);
562 static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_in, set_in,
564 static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_in, set_in,
567 static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 1, 0);
568 static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_in, set_in,
570 static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_in, set_in,
573 static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 2, 0);
574 static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_in, set_in,
576 static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_in, set_in,
579 static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 3, 0);
580 static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_in, set_in,
582 static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_in, set_in,
585 static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 4, 0);
586 static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_in, set_in,
588 static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_in, set_in,
591 static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 5, 0);
592 static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_in, set_in,
594 static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_in, set_in,
597 static SENSOR_DEVICE_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 6, 0);
598 static SENSOR_DEVICE_ATTR_2(in6_min, S_IRUGO | S_IWUSR, show_in, set_in,
600 static SENSOR_DEVICE_ATTR_2(in6_max, S_IRUGO | S_IWUSR, show_in, set_in,
603 static SENSOR_DEVICE_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 7, 0);
604 static SENSOR_DEVICE_ATTR_2(in7_min, S_IRUGO | S_IWUSR, show_in, set_in,
606 static SENSOR_DEVICE_ATTR_2(in7_max, S_IRUGO | S_IWUSR, show_in, set_in,
609 static SENSOR_DEVICE_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 8, 0);
610 static SENSOR_DEVICE_ATTR_2(in9_input, S_IRUGO, show_in, NULL, 9, 0);
613 static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
616 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
618 int index = sattr->index;
619 struct it87_data *data = it87_update_device(dev);
621 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr][index]));
624 static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
625 const char *buf, size_t count)
627 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
629 int index = sattr->index;
630 struct it87_data *data = dev_get_drvdata(dev);
634 if (kstrtol(buf, 10, &val) < 0)
637 mutex_lock(&data->update_lock);
642 reg = IT87_REG_TEMP_LOW(nr);
645 reg = IT87_REG_TEMP_HIGH(nr);
648 regval = it87_read_value(data, IT87_REG_BEEP_ENABLE);
649 if (!(regval & 0x80)) {
651 it87_write_value(data, IT87_REG_BEEP_ENABLE, regval);
654 reg = IT87_REG_TEMP_OFFSET[nr];
658 data->temp[nr][index] = TEMP_TO_REG(val);
659 it87_write_value(data, reg, data->temp[nr][index]);
660 mutex_unlock(&data->update_lock);
664 static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0);
665 static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
667 static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
669 static SENSOR_DEVICE_ATTR_2(temp1_offset, S_IRUGO | S_IWUSR, show_temp,
671 static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, 0);
672 static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
674 static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
676 static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IRUGO | S_IWUSR, show_temp,
678 static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 2, 0);
679 static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
681 static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
683 static SENSOR_DEVICE_ATTR_2(temp3_offset, S_IRUGO | S_IWUSR, show_temp,
686 static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr,
689 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
690 int nr = sensor_attr->index;
691 struct it87_data *data = it87_update_device(dev);
692 u8 reg = data->sensor; /* In case value is updated while used */
693 u8 extra = data->extra;
695 if ((has_temp_peci(data, nr) && (reg >> 6 == nr + 1))
696 || (has_temp_old_peci(data, nr) && (extra & 0x80)))
697 return sprintf(buf, "6\n"); /* Intel PECI */
699 return sprintf(buf, "3\n"); /* thermal diode */
701 return sprintf(buf, "4\n"); /* thermistor */
702 return sprintf(buf, "0\n"); /* disabled */
705 static ssize_t set_temp_type(struct device *dev, struct device_attribute *attr,
706 const char *buf, size_t count)
708 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
709 int nr = sensor_attr->index;
711 struct it87_data *data = dev_get_drvdata(dev);
715 if (kstrtol(buf, 10, &val) < 0)
718 reg = it87_read_value(data, IT87_REG_TEMP_ENABLE);
721 if (has_temp_peci(data, nr) && (reg >> 6 == nr + 1 || val == 6))
723 extra = it87_read_value(data, IT87_REG_TEMP_EXTRA);
724 if (has_temp_old_peci(data, nr) && ((extra & 0x80) || val == 6))
726 if (val == 2) { /* backwards compatibility */
728 "Sensor type 2 is deprecated, please use 4 instead\n");
731 /* 3 = thermal diode; 4 = thermistor; 6 = Intel PECI; 0 = disabled */
736 else if (has_temp_peci(data, nr) && val == 6)
737 reg |= (nr + 1) << 6;
738 else if (has_temp_old_peci(data, nr) && val == 6)
743 mutex_lock(&data->update_lock);
746 it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor);
747 if (has_temp_old_peci(data, nr))
748 it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra);
749 data->valid = 0; /* Force cache refresh */
750 mutex_unlock(&data->update_lock);
754 static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR, show_temp_type,
756 static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR, show_temp_type,
758 static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR, show_temp_type,
763 static int pwm_mode(const struct it87_data *data, int nr)
765 int ctrl = data->fan_main_ctrl & (1 << nr);
767 if (ctrl == 0 && data->type != it8603) /* Full speed */
769 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
771 else /* Manual mode */
775 static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
778 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
780 int index = sattr->index;
782 struct it87_data *data = it87_update_device(dev);
784 speed = has_16bit_fans(data) ?
785 FAN16_FROM_REG(data->fan[nr][index]) :
786 FAN_FROM_REG(data->fan[nr][index],
787 DIV_FROM_REG(data->fan_div[nr]));
788 return sprintf(buf, "%d\n", speed);
791 static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
794 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
795 int nr = sensor_attr->index;
797 struct it87_data *data = it87_update_device(dev);
798 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
800 static ssize_t show_pwm_enable(struct device *dev,
801 struct device_attribute *attr, char *buf)
803 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
804 int nr = sensor_attr->index;
806 struct it87_data *data = it87_update_device(dev);
807 return sprintf(buf, "%d\n", pwm_mode(data, nr));
809 static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
812 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
813 int nr = sensor_attr->index;
815 struct it87_data *data = it87_update_device(dev);
816 return sprintf(buf, "%d\n",
817 pwm_from_reg(data, data->pwm_duty[nr]));
819 static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
822 struct it87_data *data = it87_update_device(dev);
823 int index = (data->fan_ctl >> 4) & 0x07;
825 return sprintf(buf, "%u\n", pwm_freq[index]);
828 static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
829 const char *buf, size_t count)
831 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
833 int index = sattr->index;
835 struct it87_data *data = dev_get_drvdata(dev);
839 if (kstrtol(buf, 10, &val) < 0)
842 mutex_lock(&data->update_lock);
844 if (has_16bit_fans(data)) {
845 data->fan[nr][index] = FAN16_TO_REG(val);
846 it87_write_value(data, IT87_REG_FAN_MIN[nr],
847 data->fan[nr][index] & 0xff);
848 it87_write_value(data, IT87_REG_FANX_MIN[nr],
849 data->fan[nr][index] >> 8);
851 reg = it87_read_value(data, IT87_REG_FAN_DIV);
854 data->fan_div[nr] = reg & 0x07;
857 data->fan_div[nr] = (reg >> 3) & 0x07;
860 data->fan_div[nr] = (reg & 0x40) ? 3 : 1;
863 data->fan[nr][index] =
864 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
865 it87_write_value(data, IT87_REG_FAN_MIN[nr],
866 data->fan[nr][index]);
869 mutex_unlock(&data->update_lock);
873 static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
874 const char *buf, size_t count)
876 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
877 int nr = sensor_attr->index;
879 struct it87_data *data = dev_get_drvdata(dev);
884 if (kstrtoul(buf, 10, &val) < 0)
887 mutex_lock(&data->update_lock);
888 old = it87_read_value(data, IT87_REG_FAN_DIV);
890 /* Save fan min limit */
891 min = FAN_FROM_REG(data->fan[nr][1], DIV_FROM_REG(data->fan_div[nr]));
896 data->fan_div[nr] = DIV_TO_REG(val);
900 data->fan_div[nr] = 1;
902 data->fan_div[nr] = 3;
905 val |= (data->fan_div[0] & 0x07);
906 val |= (data->fan_div[1] & 0x07) << 3;
907 if (data->fan_div[2] == 3)
909 it87_write_value(data, IT87_REG_FAN_DIV, val);
911 /* Restore fan min limit */
912 data->fan[nr][1] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
913 it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan[nr][1]);
915 mutex_unlock(&data->update_lock);
919 /* Returns 0 if OK, -EINVAL otherwise */
920 static int check_trip_points(struct device *dev, int nr)
922 const struct it87_data *data = dev_get_drvdata(dev);
925 if (has_old_autopwm(data)) {
926 for (i = 0; i < 3; i++) {
927 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1])
930 for (i = 0; i < 2; i++) {
931 if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1])
938 "Inconsistent trip points, not switching to automatic mode\n");
939 dev_err(dev, "Adjust the trip points and try again\n");
944 static ssize_t set_pwm_enable(struct device *dev,
945 struct device_attribute *attr, const char *buf, size_t count)
947 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
948 int nr = sensor_attr->index;
950 struct it87_data *data = dev_get_drvdata(dev);
953 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 2)
956 /* Check trip points before switching to automatic mode */
958 if (check_trip_points(dev, nr) < 0)
962 /* IT8603E does not have on/off mode */
963 if (val == 0 && data->type == it8603)
966 mutex_lock(&data->update_lock);
970 /* make sure the fan is on when in on/off mode */
971 tmp = it87_read_value(data, IT87_REG_FAN_CTL);
972 it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr));
973 /* set on/off mode */
974 data->fan_main_ctrl &= ~(1 << nr);
975 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
976 data->fan_main_ctrl);
978 if (val == 1) /* Manual mode */
979 data->pwm_ctrl[nr] = has_newer_autopwm(data) ?
980 data->pwm_temp_map[nr] :
982 else /* Automatic mode */
983 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
984 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
986 if (data->type != it8603) {
987 /* set SmartGuardian mode */
988 data->fan_main_ctrl |= (1 << nr);
989 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
990 data->fan_main_ctrl);
994 mutex_unlock(&data->update_lock);
997 static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
998 const char *buf, size_t count)
1000 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1001 int nr = sensor_attr->index;
1003 struct it87_data *data = dev_get_drvdata(dev);
1006 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
1009 mutex_lock(&data->update_lock);
1010 if (has_newer_autopwm(data)) {
1012 * If we are in automatic mode, the PWM duty cycle register
1013 * is read-only so we can't write the value.
1015 if (data->pwm_ctrl[nr] & 0x80) {
1016 mutex_unlock(&data->update_lock);
1019 data->pwm_duty[nr] = pwm_to_reg(data, val);
1020 it87_write_value(data, IT87_REG_PWM_DUTY(nr),
1021 data->pwm_duty[nr]);
1023 data->pwm_duty[nr] = pwm_to_reg(data, val);
1025 * If we are in manual mode, write the duty cycle immediately;
1026 * otherwise, just store it for later use.
1028 if (!(data->pwm_ctrl[nr] & 0x80)) {
1029 data->pwm_ctrl[nr] = data->pwm_duty[nr];
1030 it87_write_value(data, IT87_REG_PWM(nr),
1031 data->pwm_ctrl[nr]);
1034 mutex_unlock(&data->update_lock);
1037 static ssize_t set_pwm_freq(struct device *dev,
1038 struct device_attribute *attr, const char *buf, size_t count)
1040 struct it87_data *data = dev_get_drvdata(dev);
1044 if (kstrtoul(buf, 10, &val) < 0)
1047 /* Search for the nearest available frequency */
1048 for (i = 0; i < 7; i++) {
1049 if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2)
1053 mutex_lock(&data->update_lock);
1054 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f;
1055 data->fan_ctl |= i << 4;
1056 it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl);
1057 mutex_unlock(&data->update_lock);
1061 static ssize_t show_pwm_temp_map(struct device *dev,
1062 struct device_attribute *attr, char *buf)
1064 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1065 int nr = sensor_attr->index;
1067 struct it87_data *data = it87_update_device(dev);
1070 if (data->pwm_temp_map[nr] < 3)
1071 map = 1 << data->pwm_temp_map[nr];
1073 map = 0; /* Should never happen */
1074 return sprintf(buf, "%d\n", map);
1076 static ssize_t set_pwm_temp_map(struct device *dev,
1077 struct device_attribute *attr, const char *buf, size_t count)
1079 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1080 int nr = sensor_attr->index;
1082 struct it87_data *data = dev_get_drvdata(dev);
1087 * This check can go away if we ever support automatic fan speed
1088 * control on newer chips.
1090 if (!has_old_autopwm(data)) {
1091 dev_notice(dev, "Mapping change disabled for safety reasons\n");
1095 if (kstrtol(buf, 10, &val) < 0)
1112 mutex_lock(&data->update_lock);
1113 data->pwm_temp_map[nr] = reg;
1115 * If we are in automatic mode, write the temp mapping immediately;
1116 * otherwise, just store it for later use.
1118 if (data->pwm_ctrl[nr] & 0x80) {
1119 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
1120 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
1122 mutex_unlock(&data->update_lock);
1126 static ssize_t show_auto_pwm(struct device *dev,
1127 struct device_attribute *attr, char *buf)
1129 struct it87_data *data = it87_update_device(dev);
1130 struct sensor_device_attribute_2 *sensor_attr =
1131 to_sensor_dev_attr_2(attr);
1132 int nr = sensor_attr->nr;
1133 int point = sensor_attr->index;
1135 return sprintf(buf, "%d\n",
1136 pwm_from_reg(data, data->auto_pwm[nr][point]));
1139 static ssize_t set_auto_pwm(struct device *dev,
1140 struct device_attribute *attr, const char *buf, size_t count)
1142 struct it87_data *data = dev_get_drvdata(dev);
1143 struct sensor_device_attribute_2 *sensor_attr =
1144 to_sensor_dev_attr_2(attr);
1145 int nr = sensor_attr->nr;
1146 int point = sensor_attr->index;
1149 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
1152 mutex_lock(&data->update_lock);
1153 data->auto_pwm[nr][point] = pwm_to_reg(data, val);
1154 it87_write_value(data, IT87_REG_AUTO_PWM(nr, point),
1155 data->auto_pwm[nr][point]);
1156 mutex_unlock(&data->update_lock);
1160 static ssize_t show_auto_temp(struct device *dev,
1161 struct device_attribute *attr, char *buf)
1163 struct it87_data *data = it87_update_device(dev);
1164 struct sensor_device_attribute_2 *sensor_attr =
1165 to_sensor_dev_attr_2(attr);
1166 int nr = sensor_attr->nr;
1167 int point = sensor_attr->index;
1169 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->auto_temp[nr][point]));
1172 static ssize_t set_auto_temp(struct device *dev,
1173 struct device_attribute *attr, const char *buf, size_t count)
1175 struct it87_data *data = dev_get_drvdata(dev);
1176 struct sensor_device_attribute_2 *sensor_attr =
1177 to_sensor_dev_attr_2(attr);
1178 int nr = sensor_attr->nr;
1179 int point = sensor_attr->index;
1182 if (kstrtol(buf, 10, &val) < 0 || val < -128000 || val > 127000)
1185 mutex_lock(&data->update_lock);
1186 data->auto_temp[nr][point] = TEMP_TO_REG(val);
1187 it87_write_value(data, IT87_REG_AUTO_TEMP(nr, point),
1188 data->auto_temp[nr][point]);
1189 mutex_unlock(&data->update_lock);
1193 static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0);
1194 static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1196 static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, show_fan_div,
1199 static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 1, 0);
1200 static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1202 static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, show_fan_div,
1205 static SENSOR_DEVICE_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 2, 0);
1206 static SENSOR_DEVICE_ATTR_2(fan3_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1208 static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO | S_IWUSR, show_fan_div,
1211 static SENSOR_DEVICE_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 3, 0);
1212 static SENSOR_DEVICE_ATTR_2(fan4_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1215 static SENSOR_DEVICE_ATTR_2(fan5_input, S_IRUGO, show_fan, NULL, 4, 0);
1216 static SENSOR_DEVICE_ATTR_2(fan5_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1219 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
1220 show_pwm_enable, set_pwm_enable, 0);
1221 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0);
1222 static DEVICE_ATTR(pwm1_freq, S_IRUGO | S_IWUSR, show_pwm_freq, set_pwm_freq);
1223 static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IRUGO | S_IWUSR,
1224 show_pwm_temp_map, set_pwm_temp_map, 0);
1225 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR,
1226 show_auto_pwm, set_auto_pwm, 0, 0);
1227 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR,
1228 show_auto_pwm, set_auto_pwm, 0, 1);
1229 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR,
1230 show_auto_pwm, set_auto_pwm, 0, 2);
1231 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO,
1232 show_auto_pwm, NULL, 0, 3);
1233 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR,
1234 show_auto_temp, set_auto_temp, 0, 1);
1235 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1236 show_auto_temp, set_auto_temp, 0, 0);
1237 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR,
1238 show_auto_temp, set_auto_temp, 0, 2);
1239 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR,
1240 show_auto_temp, set_auto_temp, 0, 3);
1241 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR,
1242 show_auto_temp, set_auto_temp, 0, 4);
1244 static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR,
1245 show_pwm_enable, set_pwm_enable, 1);
1246 static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 1);
1247 static DEVICE_ATTR(pwm2_freq, S_IRUGO, show_pwm_freq, NULL);
1248 static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IRUGO | S_IWUSR,
1249 show_pwm_temp_map, set_pwm_temp_map, 1);
1250 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR,
1251 show_auto_pwm, set_auto_pwm, 1, 0);
1252 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO | S_IWUSR,
1253 show_auto_pwm, set_auto_pwm, 1, 1);
1254 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO | S_IWUSR,
1255 show_auto_pwm, set_auto_pwm, 1, 2);
1256 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO,
1257 show_auto_pwm, NULL, 1, 3);
1258 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR,
1259 show_auto_temp, set_auto_temp, 1, 1);
1260 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1261 show_auto_temp, set_auto_temp, 1, 0);
1262 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR,
1263 show_auto_temp, set_auto_temp, 1, 2);
1264 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR,
1265 show_auto_temp, set_auto_temp, 1, 3);
1266 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_temp, S_IRUGO | S_IWUSR,
1267 show_auto_temp, set_auto_temp, 1, 4);
1269 static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR,
1270 show_pwm_enable, set_pwm_enable, 2);
1271 static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 2);
1272 static DEVICE_ATTR(pwm3_freq, S_IRUGO, show_pwm_freq, NULL);
1273 static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IRUGO | S_IWUSR,
1274 show_pwm_temp_map, set_pwm_temp_map, 2);
1275 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO | S_IWUSR,
1276 show_auto_pwm, set_auto_pwm, 2, 0);
1277 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR,
1278 show_auto_pwm, set_auto_pwm, 2, 1);
1279 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO | S_IWUSR,
1280 show_auto_pwm, set_auto_pwm, 2, 2);
1281 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO,
1282 show_auto_pwm, NULL, 2, 3);
1283 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp, S_IRUGO | S_IWUSR,
1284 show_auto_temp, set_auto_temp, 2, 1);
1285 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1286 show_auto_temp, set_auto_temp, 2, 0);
1287 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_temp, S_IRUGO | S_IWUSR,
1288 show_auto_temp, set_auto_temp, 2, 2);
1289 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_temp, S_IRUGO | S_IWUSR,
1290 show_auto_temp, set_auto_temp, 2, 3);
1291 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_temp, S_IRUGO | S_IWUSR,
1292 show_auto_temp, set_auto_temp, 2, 4);
1295 static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
1298 struct it87_data *data = it87_update_device(dev);
1299 return sprintf(buf, "%u\n", data->alarms);
1301 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
1303 static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
1306 int bitnr = to_sensor_dev_attr(attr)->index;
1307 struct it87_data *data = it87_update_device(dev);
1308 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
1311 static ssize_t clear_intrusion(struct device *dev, struct device_attribute
1312 *attr, const char *buf, size_t count)
1314 struct it87_data *data = dev_get_drvdata(dev);
1318 if (kstrtol(buf, 10, &val) < 0 || val != 0)
1321 mutex_lock(&data->update_lock);
1322 config = it87_read_value(data, IT87_REG_CONFIG);
1327 it87_write_value(data, IT87_REG_CONFIG, config);
1328 /* Invalidate cache to force re-read */
1331 mutex_unlock(&data->update_lock);
1336 static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8);
1337 static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9);
1338 static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10);
1339 static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11);
1340 static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12);
1341 static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13);
1342 static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14);
1343 static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15);
1344 static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0);
1345 static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1);
1346 static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2);
1347 static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3);
1348 static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6);
1349 static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16);
1350 static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17);
1351 static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18);
1352 static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR,
1353 show_alarm, clear_intrusion, 4);
1355 static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
1358 int bitnr = to_sensor_dev_attr(attr)->index;
1359 struct it87_data *data = it87_update_device(dev);
1360 return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1);
1362 static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
1363 const char *buf, size_t count)
1365 int bitnr = to_sensor_dev_attr(attr)->index;
1366 struct it87_data *data = dev_get_drvdata(dev);
1369 if (kstrtol(buf, 10, &val) < 0
1370 || (val != 0 && val != 1))
1373 mutex_lock(&data->update_lock);
1374 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
1376 data->beeps |= (1 << bitnr);
1378 data->beeps &= ~(1 << bitnr);
1379 it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps);
1380 mutex_unlock(&data->update_lock);
1384 static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
1385 show_beep, set_beep, 1);
1386 static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO, show_beep, NULL, 1);
1387 static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO, show_beep, NULL, 1);
1388 static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO, show_beep, NULL, 1);
1389 static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO, show_beep, NULL, 1);
1390 static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO, show_beep, NULL, 1);
1391 static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO, show_beep, NULL, 1);
1392 static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO, show_beep, NULL, 1);
1393 /* fanX_beep writability is set later */
1394 static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO, show_beep, set_beep, 0);
1395 static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0);
1396 static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0);
1397 static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0);
1398 static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0);
1399 static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
1400 show_beep, set_beep, 2);
1401 static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2);
1402 static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2);
1404 static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
1407 struct it87_data *data = dev_get_drvdata(dev);
1408 return sprintf(buf, "%u\n", data->vrm);
1410 static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
1411 const char *buf, size_t count)
1413 struct it87_data *data = dev_get_drvdata(dev);
1416 if (kstrtoul(buf, 10, &val) < 0)
1423 static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
1425 static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
1428 struct it87_data *data = it87_update_device(dev);
1429 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
1431 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
1433 static ssize_t show_label(struct device *dev, struct device_attribute *attr,
1436 static const char * const labels[] = {
1441 static const char * const labels_it8721[] = {
1446 struct it87_data *data = dev_get_drvdata(dev);
1447 int nr = to_sensor_dev_attr(attr)->index;
1449 return sprintf(buf, "%s\n", has_12mv_adc(data) ? labels_it8721[nr]
1452 static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0);
1453 static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1);
1454 static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 2);
1455 /* special AVCC3 IT8603E in9 */
1456 static SENSOR_DEVICE_ATTR(in9_label, S_IRUGO, show_label, NULL, 0);
1458 static ssize_t show_name(struct device *dev, struct device_attribute
1459 *devattr, char *buf)
1461 struct it87_data *data = dev_get_drvdata(dev);
1462 return sprintf(buf, "%s\n", data->name);
1464 static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
1466 static struct attribute *it87_attributes_in[10][5] = {
1468 &sensor_dev_attr_in0_input.dev_attr.attr,
1469 &sensor_dev_attr_in0_min.dev_attr.attr,
1470 &sensor_dev_attr_in0_max.dev_attr.attr,
1471 &sensor_dev_attr_in0_alarm.dev_attr.attr,
1474 &sensor_dev_attr_in1_input.dev_attr.attr,
1475 &sensor_dev_attr_in1_min.dev_attr.attr,
1476 &sensor_dev_attr_in1_max.dev_attr.attr,
1477 &sensor_dev_attr_in1_alarm.dev_attr.attr,
1480 &sensor_dev_attr_in2_input.dev_attr.attr,
1481 &sensor_dev_attr_in2_min.dev_attr.attr,
1482 &sensor_dev_attr_in2_max.dev_attr.attr,
1483 &sensor_dev_attr_in2_alarm.dev_attr.attr,
1486 &sensor_dev_attr_in3_input.dev_attr.attr,
1487 &sensor_dev_attr_in3_min.dev_attr.attr,
1488 &sensor_dev_attr_in3_max.dev_attr.attr,
1489 &sensor_dev_attr_in3_alarm.dev_attr.attr,
1492 &sensor_dev_attr_in4_input.dev_attr.attr,
1493 &sensor_dev_attr_in4_min.dev_attr.attr,
1494 &sensor_dev_attr_in4_max.dev_attr.attr,
1495 &sensor_dev_attr_in4_alarm.dev_attr.attr,
1498 &sensor_dev_attr_in5_input.dev_attr.attr,
1499 &sensor_dev_attr_in5_min.dev_attr.attr,
1500 &sensor_dev_attr_in5_max.dev_attr.attr,
1501 &sensor_dev_attr_in5_alarm.dev_attr.attr,
1504 &sensor_dev_attr_in6_input.dev_attr.attr,
1505 &sensor_dev_attr_in6_min.dev_attr.attr,
1506 &sensor_dev_attr_in6_max.dev_attr.attr,
1507 &sensor_dev_attr_in6_alarm.dev_attr.attr,
1510 &sensor_dev_attr_in7_input.dev_attr.attr,
1511 &sensor_dev_attr_in7_min.dev_attr.attr,
1512 &sensor_dev_attr_in7_max.dev_attr.attr,
1513 &sensor_dev_attr_in7_alarm.dev_attr.attr,
1516 &sensor_dev_attr_in8_input.dev_attr.attr,
1519 &sensor_dev_attr_in9_input.dev_attr.attr,
1523 static const struct attribute_group it87_group_in[10] = {
1524 { .attrs = it87_attributes_in[0] },
1525 { .attrs = it87_attributes_in[1] },
1526 { .attrs = it87_attributes_in[2] },
1527 { .attrs = it87_attributes_in[3] },
1528 { .attrs = it87_attributes_in[4] },
1529 { .attrs = it87_attributes_in[5] },
1530 { .attrs = it87_attributes_in[6] },
1531 { .attrs = it87_attributes_in[7] },
1532 { .attrs = it87_attributes_in[8] },
1533 { .attrs = it87_attributes_in[9] },
1536 static struct attribute *it87_attributes_temp[3][6] = {
1538 &sensor_dev_attr_temp1_input.dev_attr.attr,
1539 &sensor_dev_attr_temp1_max.dev_attr.attr,
1540 &sensor_dev_attr_temp1_min.dev_attr.attr,
1541 &sensor_dev_attr_temp1_type.dev_attr.attr,
1542 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
1545 &sensor_dev_attr_temp2_input.dev_attr.attr,
1546 &sensor_dev_attr_temp2_max.dev_attr.attr,
1547 &sensor_dev_attr_temp2_min.dev_attr.attr,
1548 &sensor_dev_attr_temp2_type.dev_attr.attr,
1549 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
1552 &sensor_dev_attr_temp3_input.dev_attr.attr,
1553 &sensor_dev_attr_temp3_max.dev_attr.attr,
1554 &sensor_dev_attr_temp3_min.dev_attr.attr,
1555 &sensor_dev_attr_temp3_type.dev_attr.attr,
1556 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
1560 static const struct attribute_group it87_group_temp[3] = {
1561 { .attrs = it87_attributes_temp[0] },
1562 { .attrs = it87_attributes_temp[1] },
1563 { .attrs = it87_attributes_temp[2] },
1566 static struct attribute *it87_attributes_temp_offset[] = {
1567 &sensor_dev_attr_temp1_offset.dev_attr.attr,
1568 &sensor_dev_attr_temp2_offset.dev_attr.attr,
1569 &sensor_dev_attr_temp3_offset.dev_attr.attr,
1572 static struct attribute *it87_attributes[] = {
1573 &dev_attr_alarms.attr,
1574 &sensor_dev_attr_intrusion0_alarm.dev_attr.attr,
1575 &dev_attr_name.attr,
1579 static const struct attribute_group it87_group = {
1580 .attrs = it87_attributes,
1583 static struct attribute *it87_attributes_in_beep[] = {
1584 &sensor_dev_attr_in0_beep.dev_attr.attr,
1585 &sensor_dev_attr_in1_beep.dev_attr.attr,
1586 &sensor_dev_attr_in2_beep.dev_attr.attr,
1587 &sensor_dev_attr_in3_beep.dev_attr.attr,
1588 &sensor_dev_attr_in4_beep.dev_attr.attr,
1589 &sensor_dev_attr_in5_beep.dev_attr.attr,
1590 &sensor_dev_attr_in6_beep.dev_attr.attr,
1591 &sensor_dev_attr_in7_beep.dev_attr.attr,
1596 static struct attribute *it87_attributes_temp_beep[] = {
1597 &sensor_dev_attr_temp1_beep.dev_attr.attr,
1598 &sensor_dev_attr_temp2_beep.dev_attr.attr,
1599 &sensor_dev_attr_temp3_beep.dev_attr.attr,
1602 static struct attribute *it87_attributes_fan[5][3+1] = { {
1603 &sensor_dev_attr_fan1_input.dev_attr.attr,
1604 &sensor_dev_attr_fan1_min.dev_attr.attr,
1605 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1608 &sensor_dev_attr_fan2_input.dev_attr.attr,
1609 &sensor_dev_attr_fan2_min.dev_attr.attr,
1610 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1613 &sensor_dev_attr_fan3_input.dev_attr.attr,
1614 &sensor_dev_attr_fan3_min.dev_attr.attr,
1615 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
1618 &sensor_dev_attr_fan4_input.dev_attr.attr,
1619 &sensor_dev_attr_fan4_min.dev_attr.attr,
1620 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
1623 &sensor_dev_attr_fan5_input.dev_attr.attr,
1624 &sensor_dev_attr_fan5_min.dev_attr.attr,
1625 &sensor_dev_attr_fan5_alarm.dev_attr.attr,
1629 static const struct attribute_group it87_group_fan[5] = {
1630 { .attrs = it87_attributes_fan[0] },
1631 { .attrs = it87_attributes_fan[1] },
1632 { .attrs = it87_attributes_fan[2] },
1633 { .attrs = it87_attributes_fan[3] },
1634 { .attrs = it87_attributes_fan[4] },
1637 static const struct attribute *it87_attributes_fan_div[] = {
1638 &sensor_dev_attr_fan1_div.dev_attr.attr,
1639 &sensor_dev_attr_fan2_div.dev_attr.attr,
1640 &sensor_dev_attr_fan3_div.dev_attr.attr,
1643 static struct attribute *it87_attributes_pwm[3][4+1] = { {
1644 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
1645 &sensor_dev_attr_pwm1.dev_attr.attr,
1646 &dev_attr_pwm1_freq.attr,
1647 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
1650 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1651 &sensor_dev_attr_pwm2.dev_attr.attr,
1652 &dev_attr_pwm2_freq.attr,
1653 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
1656 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
1657 &sensor_dev_attr_pwm3.dev_attr.attr,
1658 &dev_attr_pwm3_freq.attr,
1659 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
1663 static const struct attribute_group it87_group_pwm[3] = {
1664 { .attrs = it87_attributes_pwm[0] },
1665 { .attrs = it87_attributes_pwm[1] },
1666 { .attrs = it87_attributes_pwm[2] },
1669 static struct attribute *it87_attributes_autopwm[3][9+1] = { {
1670 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
1671 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
1672 &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr,
1673 &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr,
1674 &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
1675 &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr,
1676 &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr,
1677 &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr,
1678 &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr,
1681 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
1682 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
1683 &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr,
1684 &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr,
1685 &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr,
1686 &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr,
1687 &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr,
1688 &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr,
1689 &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr,
1692 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
1693 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
1694 &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr,
1695 &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr,
1696 &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr,
1697 &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr,
1698 &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr,
1699 &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr,
1700 &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr,
1704 static const struct attribute_group it87_group_autopwm[3] = {
1705 { .attrs = it87_attributes_autopwm[0] },
1706 { .attrs = it87_attributes_autopwm[1] },
1707 { .attrs = it87_attributes_autopwm[2] },
1710 static struct attribute *it87_attributes_fan_beep[] = {
1711 &sensor_dev_attr_fan1_beep.dev_attr.attr,
1712 &sensor_dev_attr_fan2_beep.dev_attr.attr,
1713 &sensor_dev_attr_fan3_beep.dev_attr.attr,
1714 &sensor_dev_attr_fan4_beep.dev_attr.attr,
1715 &sensor_dev_attr_fan5_beep.dev_attr.attr,
1718 static struct attribute *it87_attributes_vid[] = {
1720 &dev_attr_cpu0_vid.attr,
1724 static const struct attribute_group it87_group_vid = {
1725 .attrs = it87_attributes_vid,
1728 static struct attribute *it87_attributes_label[] = {
1729 &sensor_dev_attr_in3_label.dev_attr.attr,
1730 &sensor_dev_attr_in7_label.dev_attr.attr,
1731 &sensor_dev_attr_in8_label.dev_attr.attr,
1732 &sensor_dev_attr_in9_label.dev_attr.attr,
1736 static const struct attribute_group it87_group_label = {
1737 .attrs = it87_attributes_label,
1740 /* SuperIO detection - will change isa_address if a chip is found */
1741 static int __init it87_find(unsigned short *address,
1742 struct it87_sio_data *sio_data)
1746 const char *board_vendor, *board_name;
1748 err = superio_enter();
1753 chip_type = force_id ? force_id : superio_inw(DEVID);
1755 switch (chip_type) {
1757 sio_data->type = it87;
1760 sio_data->type = it8712;
1764 sio_data->type = it8716;
1767 sio_data->type = it8718;
1770 sio_data->type = it8720;
1773 sio_data->type = it8721;
1776 sio_data->type = it8728;
1779 sio_data->type = it8771;
1782 sio_data->type = it8772;
1785 sio_data->type = it8781;
1788 sio_data->type = it8782;
1791 sio_data->type = it8783;
1795 sio_data->type = it8603;
1797 case 0xffff: /* No device at all */
1800 pr_debug("Unsupported chip (DEVID=0x%x)\n", chip_type);
1804 superio_select(PME);
1805 if (!(superio_inb(IT87_ACT_REG) & 0x01)) {
1806 pr_info("Device not activated, skipping\n");
1810 *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1);
1811 if (*address == 0) {
1812 pr_info("Base address not set, skipping\n");
1817 sio_data->revision = superio_inb(DEVREV) & 0x0f;
1818 pr_info("Found IT%04x%c chip at 0x%x, revision %d\n", chip_type,
1819 chip_type == 0x8771 || chip_type == 0x8772 ||
1820 chip_type == 0x8603 ? 'E' : 'F', *address,
1821 sio_data->revision);
1823 /* in8 (Vbat) is always internal */
1824 sio_data->internal = (1 << 2);
1825 /* Only the IT8603E has in9 */
1826 if (sio_data->type != it8603)
1827 sio_data->skip_in |= (1 << 9);
1829 /* Read GPIO config and VID value from LDN 7 (GPIO) */
1830 if (sio_data->type == it87) {
1831 /* The IT8705F doesn't have VID pins at all */
1832 sio_data->skip_vid = 1;
1834 /* The IT8705F has a different LD number for GPIO */
1836 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
1837 } else if (sio_data->type == it8783) {
1838 int reg25, reg27, reg2a, reg2c, regef;
1840 sio_data->skip_vid = 1; /* No VID */
1842 superio_select(GPIO);
1844 reg25 = superio_inb(IT87_SIO_GPIO1_REG);
1845 reg27 = superio_inb(IT87_SIO_GPIO3_REG);
1846 reg2a = superio_inb(IT87_SIO_PINX1_REG);
1847 reg2c = superio_inb(IT87_SIO_PINX2_REG);
1848 regef = superio_inb(IT87_SIO_SPI_REG);
1850 /* Check if fan3 is there or not */
1851 if ((reg27 & (1 << 0)) || !(reg2c & (1 << 2)))
1852 sio_data->skip_fan |= (1 << 2);
1853 if ((reg25 & (1 << 4))
1854 || (!(reg2a & (1 << 1)) && (regef & (1 << 0))))
1855 sio_data->skip_pwm |= (1 << 2);
1857 /* Check if fan2 is there or not */
1858 if (reg27 & (1 << 7))
1859 sio_data->skip_fan |= (1 << 1);
1860 if (reg27 & (1 << 3))
1861 sio_data->skip_pwm |= (1 << 1);
1864 if ((reg27 & (1 << 0)) || (reg2c & (1 << 2)))
1865 sio_data->skip_in |= (1 << 5); /* No VIN5 */
1868 if (reg27 & (1 << 1))
1869 sio_data->skip_in |= (1 << 6); /* No VIN6 */
1873 * Does not depend on bit 2 of Reg2C, contrary to datasheet.
1875 if (reg27 & (1 << 2)) {
1877 * The data sheet is a bit unclear regarding the
1878 * internal voltage divider for VCCH5V. It says
1879 * "This bit enables and switches VIN7 (pin 91) to the
1880 * internal voltage divider for VCCH5V".
1881 * This is different to other chips, where the internal
1882 * voltage divider would connect VIN7 to an internal
1883 * voltage source. Maybe that is the case here as well.
1885 * Since we don't know for sure, re-route it if that is
1886 * not the case, and ask the user to report if the
1887 * resulting voltage is sane.
1889 if (!(reg2c & (1 << 1))) {
1891 superio_outb(IT87_SIO_PINX2_REG, reg2c);
1892 pr_notice("Routing internal VCCH5V to in7.\n");
1894 pr_notice("in7 routed to internal voltage divider, with external pin disabled.\n");
1895 pr_notice("Please report if it displays a reasonable voltage.\n");
1898 if (reg2c & (1 << 0))
1899 sio_data->internal |= (1 << 0);
1900 if (reg2c & (1 << 1))
1901 sio_data->internal |= (1 << 1);
1903 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
1904 } else if (sio_data->type == it8603) {
1907 sio_data->skip_vid = 1; /* No VID */
1908 superio_select(GPIO);
1910 reg27 = superio_inb(IT87_SIO_GPIO3_REG);
1912 /* Check if fan3 is there or not */
1913 if (reg27 & (1 << 6))
1914 sio_data->skip_pwm |= (1 << 2);
1915 if (reg27 & (1 << 7))
1916 sio_data->skip_fan |= (1 << 2);
1918 /* Check if fan2 is there or not */
1919 reg29 = superio_inb(IT87_SIO_GPIO5_REG);
1920 if (reg29 & (1 << 1))
1921 sio_data->skip_pwm |= (1 << 1);
1922 if (reg29 & (1 << 2))
1923 sio_data->skip_fan |= (1 << 1);
1925 sio_data->skip_in |= (1 << 5); /* No VIN5 */
1926 sio_data->skip_in |= (1 << 6); /* No VIN6 */
1929 sio_data->skip_pwm |= (1 << 3);
1930 sio_data->skip_fan |= (1 << 3);
1932 sio_data->internal |= (1 << 1); /* in7 is VSB */
1933 sio_data->internal |= (1 << 3); /* in9 is AVCC */
1935 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
1940 superio_select(GPIO);
1942 reg = superio_inb(IT87_SIO_GPIO3_REG);
1943 if (sio_data->type == it8721 || sio_data->type == it8728 ||
1944 sio_data->type == it8771 || sio_data->type == it8772 ||
1945 sio_data->type == it8781 || sio_data->type == it8782) {
1947 * IT8721F/IT8758E, IT8728F, IT8772F, IT8781F, and
1948 * IT8782F don't have VID pins at all, not sure about
1951 sio_data->skip_vid = 1;
1953 /* We need at least 4 VID pins */
1955 pr_info("VID is disabled (pins used for GPIO)\n");
1956 sio_data->skip_vid = 1;
1960 /* Check if fan3 is there or not */
1962 sio_data->skip_pwm |= (1 << 2);
1964 sio_data->skip_fan |= (1 << 2);
1966 /* Check if fan2 is there or not */
1967 reg = superio_inb(IT87_SIO_GPIO5_REG);
1969 sio_data->skip_pwm |= (1 << 1);
1971 sio_data->skip_fan |= (1 << 1);
1973 if ((sio_data->type == it8718 || sio_data->type == it8720)
1974 && !(sio_data->skip_vid))
1975 sio_data->vid_value = superio_inb(IT87_SIO_VID_REG);
1977 reg = superio_inb(IT87_SIO_PINX2_REG);
1979 uart6 = sio_data->type == it8782 && (reg & (1 << 2));
1982 * The IT8720F has no VIN7 pin, so VCCH should always be
1983 * routed internally to VIN7 with an internal divider.
1984 * Curiously, there still is a configuration bit to control
1985 * this, which means it can be set incorrectly. And even
1986 * more curiously, many boards out there are improperly
1987 * configured, even though the IT8720F datasheet claims
1988 * that the internal routing of VCCH to VIN7 is the default
1989 * setting. So we force the internal routing in this case.
1991 * On IT8782F, VIN7 is multiplexed with one of the UART6 pins.
1992 * If UART6 is enabled, re-route VIN7 to the internal divider
1993 * if that is not already the case.
1995 if ((sio_data->type == it8720 || uart6) && !(reg & (1 << 1))) {
1997 superio_outb(IT87_SIO_PINX2_REG, reg);
1998 pr_notice("Routing internal VCCH to in7\n");
2001 sio_data->internal |= (1 << 0);
2002 if ((reg & (1 << 1)) || sio_data->type == it8721 ||
2003 sio_data->type == it8728 ||
2004 sio_data->type == it8771 ||
2005 sio_data->type == it8772)
2006 sio_data->internal |= (1 << 1);
2009 * On IT8782F, UART6 pins overlap with VIN5, VIN6, and VIN7.
2010 * While VIN7 can be routed to the internal voltage divider,
2011 * VIN5 and VIN6 are not available if UART6 is enabled.
2013 * Also, temp3 is not available if UART6 is enabled and TEMPIN3
2014 * is the temperature source. Since we can not read the
2015 * temperature source here, skip_temp is preliminary.
2018 sio_data->skip_in |= (1 << 5) | (1 << 6);
2019 sio_data->skip_temp |= (1 << 2);
2022 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
2024 if (sio_data->beep_pin)
2025 pr_info("Beeping is supported\n");
2027 /* Disable specific features based on DMI strings */
2028 board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
2029 board_name = dmi_get_system_info(DMI_BOARD_NAME);
2030 if (board_vendor && board_name) {
2031 if (strcmp(board_vendor, "nVIDIA") == 0
2032 && strcmp(board_name, "FN68PT") == 0) {
2034 * On the Shuttle SN68PT, FAN_CTL2 is apparently not
2035 * connected to a fan, but to something else. One user
2036 * has reported instant system power-off when changing
2037 * the PWM2 duty cycle, so we disable it.
2038 * I use the board name string as the trigger in case
2039 * the same board is ever used in other systems.
2041 pr_info("Disabling pwm2 due to hardware constraints\n");
2042 sio_data->skip_pwm = (1 << 1);
2051 static void it87_remove_files(struct device *dev)
2053 struct it87_data *data = platform_get_drvdata(pdev);
2054 struct it87_sio_data *sio_data = dev_get_platdata(dev);
2057 sysfs_remove_group(&dev->kobj, &it87_group);
2058 for (i = 0; i < 10; i++) {
2059 if (sio_data->skip_in & (1 << i))
2061 sysfs_remove_group(&dev->kobj, &it87_group_in[i]);
2062 if (it87_attributes_in_beep[i])
2063 sysfs_remove_file(&dev->kobj,
2064 it87_attributes_in_beep[i]);
2066 for (i = 0; i < 3; i++) {
2067 if (!(data->has_temp & (1 << i)))
2069 sysfs_remove_group(&dev->kobj, &it87_group_temp[i]);
2070 if (has_temp_offset(data))
2071 sysfs_remove_file(&dev->kobj,
2072 it87_attributes_temp_offset[i]);
2073 if (sio_data->beep_pin)
2074 sysfs_remove_file(&dev->kobj,
2075 it87_attributes_temp_beep[i]);
2077 for (i = 0; i < 5; i++) {
2078 if (!(data->has_fan & (1 << i)))
2080 sysfs_remove_group(&dev->kobj, &it87_group_fan[i]);
2081 if (sio_data->beep_pin)
2082 sysfs_remove_file(&dev->kobj,
2083 it87_attributes_fan_beep[i]);
2084 if (i < 3 && !has_16bit_fans(data))
2085 sysfs_remove_file(&dev->kobj,
2086 it87_attributes_fan_div[i]);
2088 for (i = 0; i < 3; i++) {
2089 if (sio_data->skip_pwm & (1 << 0))
2091 sysfs_remove_group(&dev->kobj, &it87_group_pwm[i]);
2092 if (has_old_autopwm(data))
2093 sysfs_remove_group(&dev->kobj,
2094 &it87_group_autopwm[i]);
2096 if (!sio_data->skip_vid)
2097 sysfs_remove_group(&dev->kobj, &it87_group_vid);
2098 sysfs_remove_group(&dev->kobj, &it87_group_label);
2101 static int it87_probe(struct platform_device *pdev)
2103 struct it87_data *data;
2104 struct resource *res;
2105 struct device *dev = &pdev->dev;
2106 struct it87_sio_data *sio_data = dev_get_platdata(dev);
2108 int enable_pwm_interface;
2109 int fan_beep_need_rw;
2111 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
2112 if (!devm_request_region(&pdev->dev, res->start, IT87_EC_EXTENT,
2114 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
2115 (unsigned long)res->start,
2116 (unsigned long)(res->start + IT87_EC_EXTENT - 1));
2120 data = devm_kzalloc(&pdev->dev, sizeof(struct it87_data), GFP_KERNEL);
2124 data->addr = res->start;
2125 data->type = sio_data->type;
2126 data->features = it87_devices[sio_data->type].features;
2127 data->peci_mask = it87_devices[sio_data->type].peci_mask;
2128 data->old_peci_mask = it87_devices[sio_data->type].old_peci_mask;
2129 data->name = it87_devices[sio_data->type].name;
2131 * IT8705F Datasheet 0.4.1, 3h == Version G.
2132 * IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J.
2133 * These are the first revisions with 16-bit tachometer support.
2135 switch (data->type) {
2137 if (sio_data->revision >= 0x03) {
2138 data->features &= ~FEAT_OLD_AUTOPWM;
2139 data->features |= FEAT_16BIT_FANS;
2143 if (sio_data->revision >= 0x08) {
2144 data->features &= ~FEAT_OLD_AUTOPWM;
2145 data->features |= FEAT_16BIT_FANS | FEAT_FIVE_FANS;
2152 /* Now, we do the remaining detection. */
2153 if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80)
2154 || it87_read_value(data, IT87_REG_CHIPID) != 0x90)
2157 platform_set_drvdata(pdev, data);
2159 mutex_init(&data->update_lock);
2161 /* Check PWM configuration */
2162 enable_pwm_interface = it87_check_pwm(dev);
2164 /* Starting with IT8721F, we handle scaling of internal voltages */
2165 if (has_12mv_adc(data)) {
2166 if (sio_data->internal & (1 << 0))
2167 data->in_scaled |= (1 << 3); /* in3 is AVCC */
2168 if (sio_data->internal & (1 << 1))
2169 data->in_scaled |= (1 << 7); /* in7 is VSB */
2170 if (sio_data->internal & (1 << 2))
2171 data->in_scaled |= (1 << 8); /* in8 is Vbat */
2172 if (sio_data->internal & (1 << 3))
2173 data->in_scaled |= (1 << 9); /* in9 is AVCC */
2174 } else if (sio_data->type == it8781 || sio_data->type == it8782 ||
2175 sio_data->type == it8783) {
2176 if (sio_data->internal & (1 << 0))
2177 data->in_scaled |= (1 << 3); /* in3 is VCC5V */
2178 if (sio_data->internal & (1 << 1))
2179 data->in_scaled |= (1 << 7); /* in7 is VCCH5V */
2182 data->has_temp = 0x07;
2183 if (sio_data->skip_temp & (1 << 2)) {
2184 if (sio_data->type == it8782
2185 && !(it87_read_value(data, IT87_REG_TEMP_EXTRA) & 0x80))
2186 data->has_temp &= ~(1 << 2);
2189 /* Initialize the IT87 chip */
2190 it87_init_device(pdev);
2192 /* Register sysfs hooks */
2193 err = sysfs_create_group(&dev->kobj, &it87_group);
2197 for (i = 0; i < 10; i++) {
2198 if (sio_data->skip_in & (1 << i))
2200 err = sysfs_create_group(&dev->kobj, &it87_group_in[i]);
2203 if (sio_data->beep_pin && it87_attributes_in_beep[i]) {
2204 err = sysfs_create_file(&dev->kobj,
2205 it87_attributes_in_beep[i]);
2211 for (i = 0; i < 3; i++) {
2212 if (!(data->has_temp & (1 << i)))
2214 err = sysfs_create_group(&dev->kobj, &it87_group_temp[i]);
2217 if (has_temp_offset(data)) {
2218 err = sysfs_create_file(&dev->kobj,
2219 it87_attributes_temp_offset[i]);
2223 if (sio_data->beep_pin) {
2224 err = sysfs_create_file(&dev->kobj,
2225 it87_attributes_temp_beep[i]);
2231 /* Do not create fan files for disabled fans */
2232 fan_beep_need_rw = 1;
2233 for (i = 0; i < 5; i++) {
2234 if (!(data->has_fan & (1 << i)))
2236 err = sysfs_create_group(&dev->kobj, &it87_group_fan[i]);
2240 if (i < 3 && !has_16bit_fans(data)) {
2241 err = sysfs_create_file(&dev->kobj,
2242 it87_attributes_fan_div[i]);
2247 if (sio_data->beep_pin) {
2248 err = sysfs_create_file(&dev->kobj,
2249 it87_attributes_fan_beep[i]);
2252 if (!fan_beep_need_rw)
2256 * As we have a single beep enable bit for all fans,
2257 * only the first enabled fan has a writable attribute
2260 if (sysfs_chmod_file(&dev->kobj,
2261 it87_attributes_fan_beep[i],
2263 dev_dbg(dev, "chmod +w fan%d_beep failed\n",
2265 fan_beep_need_rw = 0;
2269 if (enable_pwm_interface) {
2270 for (i = 0; i < 3; i++) {
2271 if (sio_data->skip_pwm & (1 << i))
2273 err = sysfs_create_group(&dev->kobj,
2274 &it87_group_pwm[i]);
2278 if (!has_old_autopwm(data))
2280 err = sysfs_create_group(&dev->kobj,
2281 &it87_group_autopwm[i]);
2287 if (!sio_data->skip_vid) {
2288 data->vrm = vid_which_vrm();
2289 /* VID reading from Super-I/O config space if available */
2290 data->vid = sio_data->vid_value;
2291 err = sysfs_create_group(&dev->kobj, &it87_group_vid);
2296 /* Export labels for internal sensors */
2297 for (i = 0; i < 4; i++) {
2298 if (!(sio_data->internal & (1 << i)))
2300 err = sysfs_create_file(&dev->kobj,
2301 it87_attributes_label[i]);
2306 data->hwmon_dev = hwmon_device_register(dev);
2307 if (IS_ERR(data->hwmon_dev)) {
2308 err = PTR_ERR(data->hwmon_dev);
2315 it87_remove_files(dev);
2319 static int it87_remove(struct platform_device *pdev)
2321 struct it87_data *data = platform_get_drvdata(pdev);
2323 hwmon_device_unregister(data->hwmon_dev);
2324 it87_remove_files(&pdev->dev);
2330 * Must be called with data->update_lock held, except during initialization.
2331 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
2332 * would slow down the IT87 access and should not be necessary.
2334 static int it87_read_value(struct it87_data *data, u8 reg)
2336 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
2337 return inb_p(data->addr + IT87_DATA_REG_OFFSET);
2341 * Must be called with data->update_lock held, except during initialization.
2342 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
2343 * would slow down the IT87 access and should not be necessary.
2345 static void it87_write_value(struct it87_data *data, u8 reg, u8 value)
2347 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
2348 outb_p(value, data->addr + IT87_DATA_REG_OFFSET);
2351 /* Return 1 if and only if the PWM interface is safe to use */
2352 static int it87_check_pwm(struct device *dev)
2354 struct it87_data *data = dev_get_drvdata(dev);
2356 * Some BIOSes fail to correctly configure the IT87 fans. All fans off
2357 * and polarity set to active low is sign that this is the case so we
2358 * disable pwm control to protect the user.
2360 int tmp = it87_read_value(data, IT87_REG_FAN_CTL);
2361 if ((tmp & 0x87) == 0) {
2362 if (fix_pwm_polarity) {
2364 * The user asks us to attempt a chip reconfiguration.
2365 * This means switching to active high polarity and
2366 * inverting all fan speed values.
2371 for (i = 0; i < 3; i++)
2372 pwm[i] = it87_read_value(data,
2376 * If any fan is in automatic pwm mode, the polarity
2377 * might be correct, as suspicious as it seems, so we
2378 * better don't change anything (but still disable the
2381 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
2383 "Reconfiguring PWM to active high polarity\n");
2384 it87_write_value(data, IT87_REG_FAN_CTL,
2386 for (i = 0; i < 3; i++)
2387 it87_write_value(data,
2394 "PWM configuration is too broken to be fixed\n");
2398 "Detected broken BIOS defaults, disabling PWM interface\n");
2400 } else if (fix_pwm_polarity) {
2402 "PWM configuration looks sane, won't touch\n");
2408 /* Called when we have found a new IT87. */
2409 static void it87_init_device(struct platform_device *pdev)
2411 struct it87_sio_data *sio_data = dev_get_platdata(&pdev->dev);
2412 struct it87_data *data = platform_get_drvdata(pdev);
2417 * For each PWM channel:
2418 * - If it is in automatic mode, setting to manual mode should set
2419 * the fan to full speed by default.
2420 * - If it is in manual mode, we need a mapping to temperature
2421 * channels to use when later setting to automatic mode later.
2422 * Use a 1:1 mapping by default (we are clueless.)
2423 * In both cases, the value can (and should) be changed by the user
2424 * prior to switching to a different mode.
2425 * Note that this is no longer needed for the IT8721F and later, as
2426 * these have separate registers for the temperature mapping and the
2427 * manual duty cycle.
2429 for (i = 0; i < 3; i++) {
2430 data->pwm_temp_map[i] = i;
2431 data->pwm_duty[i] = 0x7f; /* Full speed */
2432 data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */
2436 * Some chips seem to have default value 0xff for all limit
2437 * registers. For low voltage limits it makes no sense and triggers
2438 * alarms, so change to 0 instead. For high temperature limits, it
2439 * means -1 degree C, which surprisingly doesn't trigger an alarm,
2440 * but is still confusing, so change to 127 degrees C.
2442 for (i = 0; i < 8; i++) {
2443 tmp = it87_read_value(data, IT87_REG_VIN_MIN(i));
2445 it87_write_value(data, IT87_REG_VIN_MIN(i), 0);
2447 for (i = 0; i < 3; i++) {
2448 tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i));
2450 it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127);
2454 * Temperature channels are not forcibly enabled, as they can be
2455 * set to two different sensor types and we can't guess which one
2456 * is correct for a given system. These channels can be enabled at
2457 * run-time through the temp{1-3}_type sysfs accessors if needed.
2460 /* Check if voltage monitors are reset manually or by some reason */
2461 tmp = it87_read_value(data, IT87_REG_VIN_ENABLE);
2462 if ((tmp & 0xff) == 0) {
2463 /* Enable all voltage monitors */
2464 it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff);
2467 /* Check if tachometers are reset manually or by some reason */
2468 mask = 0x70 & ~(sio_data->skip_fan << 4);
2469 data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL);
2470 if ((data->fan_main_ctrl & mask) == 0) {
2471 /* Enable all fan tachometers */
2472 data->fan_main_ctrl |= mask;
2473 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
2474 data->fan_main_ctrl);
2476 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
2478 /* Set tachometers to 16-bit mode if needed. */
2479 if (has_fan16_config(data)) {
2480 tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
2481 if (~tmp & 0x07 & data->has_fan) {
2483 "Setting fan1-3 to 16-bit mode\n");
2484 it87_write_value(data, IT87_REG_FAN_16BIT,
2489 /* Check for additional fans */
2490 if (has_five_fans(data)) {
2491 tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
2493 data->has_fan |= (1 << 3); /* fan4 enabled */
2495 data->has_fan |= (1 << 4); /* fan5 enabled */
2498 /* Fan input pins may be used for alternative functions */
2499 data->has_fan &= ~sio_data->skip_fan;
2501 /* Start monitoring */
2502 it87_write_value(data, IT87_REG_CONFIG,
2503 (it87_read_value(data, IT87_REG_CONFIG) & 0x3e)
2504 | (update_vbat ? 0x41 : 0x01));
2507 static void it87_update_pwm_ctrl(struct it87_data *data, int nr)
2509 data->pwm_ctrl[nr] = it87_read_value(data, IT87_REG_PWM(nr));
2510 if (has_newer_autopwm(data)) {
2511 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
2512 data->pwm_duty[nr] = it87_read_value(data,
2513 IT87_REG_PWM_DUTY(nr));
2515 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
2516 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
2517 else /* Manual mode */
2518 data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f;
2521 if (has_old_autopwm(data)) {
2524 for (i = 0; i < 5 ; i++)
2525 data->auto_temp[nr][i] = it87_read_value(data,
2526 IT87_REG_AUTO_TEMP(nr, i));
2527 for (i = 0; i < 3 ; i++)
2528 data->auto_pwm[nr][i] = it87_read_value(data,
2529 IT87_REG_AUTO_PWM(nr, i));
2533 static struct it87_data *it87_update_device(struct device *dev)
2535 struct it87_data *data = dev_get_drvdata(dev);
2538 mutex_lock(&data->update_lock);
2540 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
2544 * Cleared after each update, so reenable. Value
2545 * returned by this read will be previous value
2547 it87_write_value(data, IT87_REG_CONFIG,
2548 it87_read_value(data, IT87_REG_CONFIG) | 0x40);
2550 for (i = 0; i <= 7; i++) {
2552 it87_read_value(data, IT87_REG_VIN(i));
2554 it87_read_value(data, IT87_REG_VIN_MIN(i));
2556 it87_read_value(data, IT87_REG_VIN_MAX(i));
2558 /* in8 (battery) has no limit registers */
2559 data->in[8][0] = it87_read_value(data, IT87_REG_VIN(8));
2560 if (data->type == it8603)
2561 data->in[9][0] = it87_read_value(data, 0x2f);
2563 for (i = 0; i < 5; i++) {
2564 /* Skip disabled fans */
2565 if (!(data->has_fan & (1 << i)))
2569 it87_read_value(data, IT87_REG_FAN_MIN[i]);
2570 data->fan[i][0] = it87_read_value(data,
2572 /* Add high byte if in 16-bit mode */
2573 if (has_16bit_fans(data)) {
2574 data->fan[i][0] |= it87_read_value(data,
2575 IT87_REG_FANX[i]) << 8;
2576 data->fan[i][1] |= it87_read_value(data,
2577 IT87_REG_FANX_MIN[i]) << 8;
2580 for (i = 0; i < 3; i++) {
2581 if (!(data->has_temp & (1 << i)))
2584 it87_read_value(data, IT87_REG_TEMP(i));
2586 it87_read_value(data, IT87_REG_TEMP_LOW(i));
2588 it87_read_value(data, IT87_REG_TEMP_HIGH(i));
2589 if (has_temp_offset(data))
2591 it87_read_value(data,
2592 IT87_REG_TEMP_OFFSET[i]);
2595 /* Newer chips don't have clock dividers */
2596 if ((data->has_fan & 0x07) && !has_16bit_fans(data)) {
2597 i = it87_read_value(data, IT87_REG_FAN_DIV);
2598 data->fan_div[0] = i & 0x07;
2599 data->fan_div[1] = (i >> 3) & 0x07;
2600 data->fan_div[2] = (i & 0x40) ? 3 : 1;
2604 it87_read_value(data, IT87_REG_ALARM1) |
2605 (it87_read_value(data, IT87_REG_ALARM2) << 8) |
2606 (it87_read_value(data, IT87_REG_ALARM3) << 16);
2607 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
2609 data->fan_main_ctrl = it87_read_value(data,
2610 IT87_REG_FAN_MAIN_CTRL);
2611 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL);
2612 for (i = 0; i < 3; i++)
2613 it87_update_pwm_ctrl(data, i);
2615 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
2616 data->extra = it87_read_value(data, IT87_REG_TEMP_EXTRA);
2618 * The IT8705F does not have VID capability.
2619 * The IT8718F and later don't use IT87_REG_VID for the
2622 if (data->type == it8712 || data->type == it8716) {
2623 data->vid = it87_read_value(data, IT87_REG_VID);
2625 * The older IT8712F revisions had only 5 VID pins,
2626 * but we assume it is always safe to read 6 bits.
2630 data->last_updated = jiffies;
2634 mutex_unlock(&data->update_lock);
2639 static int __init it87_device_add(unsigned short address,
2640 const struct it87_sio_data *sio_data)
2642 struct resource res = {
2643 .start = address + IT87_EC_OFFSET,
2644 .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1,
2646 .flags = IORESOURCE_IO,
2650 err = acpi_check_resource_conflict(&res);
2654 pdev = platform_device_alloc(DRVNAME, address);
2657 pr_err("Device allocation failed\n");
2661 err = platform_device_add_resources(pdev, &res, 1);
2663 pr_err("Device resource addition failed (%d)\n", err);
2664 goto exit_device_put;
2667 err = platform_device_add_data(pdev, sio_data,
2668 sizeof(struct it87_sio_data));
2670 pr_err("Platform data allocation failed\n");
2671 goto exit_device_put;
2674 err = platform_device_add(pdev);
2676 pr_err("Device addition failed (%d)\n", err);
2677 goto exit_device_put;
2683 platform_device_put(pdev);
2688 static int __init sm_it87_init(void)
2691 unsigned short isa_address = 0;
2692 struct it87_sio_data sio_data;
2694 memset(&sio_data, 0, sizeof(struct it87_sio_data));
2695 err = it87_find(&isa_address, &sio_data);
2698 err = platform_driver_register(&it87_driver);
2702 err = it87_device_add(isa_address, &sio_data);
2704 platform_driver_unregister(&it87_driver);
2711 static void __exit sm_it87_exit(void)
2713 platform_device_unregister(pdev);
2714 platform_driver_unregister(&it87_driver);
2718 MODULE_AUTHOR("Chris Gauthron, Jean Delvare <jdelvare@suse.de>");
2719 MODULE_DESCRIPTION("IT8705F/IT871xF/IT872xF hardware monitoring driver");
2720 module_param(update_vbat, bool, 0);
2721 MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
2722 module_param(fix_pwm_polarity, bool, 0);
2723 MODULE_PARM_DESC(fix_pwm_polarity,
2724 "Force PWM polarity to active high (DANGEROUS)");
2725 MODULE_LICENSE("GPL");
2727 module_init(sm_it87_init);
2728 module_exit(sm_it87_exit);