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 * IT8786E Super I/O chip w/LPC interface
30 * Sis950 A clone of the IT8705F
32 * Copyright (C) 2001 Chris Gauthron
33 * Copyright (C) 2005-2010 Jean Delvare <jdelvare@suse.de>
35 * This program is free software; you can redistribute it and/or modify
36 * it under the terms of the GNU General Public License as published by
37 * the Free Software Foundation; either version 2 of the License, or
38 * (at your option) any later version.
40 * This program is distributed in the hope that it will be useful,
41 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 * GNU General Public License for more details.
45 * You should have received a copy of the GNU General Public License
46 * along with this program; if not, write to the Free Software
47 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
50 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
52 #include <linux/module.h>
53 #include <linux/init.h>
54 #include <linux/slab.h>
55 #include <linux/jiffies.h>
56 #include <linux/platform_device.h>
57 #include <linux/hwmon.h>
58 #include <linux/hwmon-sysfs.h>
59 #include <linux/hwmon-vid.h>
60 #include <linux/err.h>
61 #include <linux/mutex.h>
62 #include <linux/sysfs.h>
63 #include <linux/string.h>
64 #include <linux/dmi.h>
65 #include <linux/acpi.h>
69 #define DRVNAME "it87"
71 enum chips { it87, it8712, it8716, it8718, it8720, it8721, it8728, it8771,
72 it8772, it8781, it8782, it8783, it8786, it8603 };
74 static unsigned short force_id;
75 module_param(force_id, ushort, 0);
76 MODULE_PARM_DESC(force_id, "Override the detected device ID");
78 static struct platform_device *pdev;
80 #define REG 0x2e /* The register to read/write */
81 #define DEV 0x07 /* Register: Logical device select */
82 #define VAL 0x2f /* The value to read/write */
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 reg)
97 static inline void superio_outb(int reg, int val)
103 static int superio_inw(int reg)
113 static inline void superio_select(int ldn)
119 static inline int superio_enter(void)
122 * Try to reserve REG and REG + 1 for exclusive access.
124 if (!request_muxed_region(REG, 2, DRVNAME))
134 static inline void superio_exit(void)
138 release_region(REG, 2);
141 /* Logical device 4 registers */
142 #define IT8712F_DEVID 0x8712
143 #define IT8705F_DEVID 0x8705
144 #define IT8716F_DEVID 0x8716
145 #define IT8718F_DEVID 0x8718
146 #define IT8720F_DEVID 0x8720
147 #define IT8721F_DEVID 0x8721
148 #define IT8726F_DEVID 0x8726
149 #define IT8728F_DEVID 0x8728
150 #define IT8771E_DEVID 0x8771
151 #define IT8772E_DEVID 0x8772
152 #define IT8781F_DEVID 0x8781
153 #define IT8782F_DEVID 0x8782
154 #define IT8783E_DEVID 0x8783
155 #define IT8786E_DEVID 0x8786
156 #define IT8603E_DEVID 0x8603
157 #define IT8623E_DEVID 0x8623
158 #define IT87_ACT_REG 0x30
159 #define IT87_BASE_REG 0x60
161 /* Logical device 7 registers (IT8712F and later) */
162 #define IT87_SIO_GPIO1_REG 0x25
163 #define IT87_SIO_GPIO3_REG 0x27
164 #define IT87_SIO_GPIO5_REG 0x29
165 #define IT87_SIO_PINX1_REG 0x2a /* Pin selection */
166 #define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
167 #define IT87_SIO_SPI_REG 0xef /* SPI function pin select */
168 #define IT87_SIO_VID_REG 0xfc /* VID value */
169 #define IT87_SIO_BEEP_PIN_REG 0xf6 /* Beep pin mapping */
171 /* Update battery voltage after every reading if true */
172 static bool update_vbat;
174 /* Not all BIOSes properly configure the PWM registers */
175 static bool fix_pwm_polarity;
177 /* Many IT87 constants specified below */
179 /* Length of ISA address segment */
180 #define IT87_EXTENT 8
182 /* Length of ISA address segment for Environmental Controller */
183 #define IT87_EC_EXTENT 2
185 /* Offset of EC registers from ISA base address */
186 #define IT87_EC_OFFSET 5
188 /* Where are the ISA address/data registers relative to the EC base address */
189 #define IT87_ADDR_REG_OFFSET 0
190 #define IT87_DATA_REG_OFFSET 1
192 /*----- The IT87 registers -----*/
194 #define IT87_REG_CONFIG 0x00
196 #define IT87_REG_ALARM1 0x01
197 #define IT87_REG_ALARM2 0x02
198 #define IT87_REG_ALARM3 0x03
201 * The IT8718F and IT8720F have the VID value in a different register, in
202 * Super-I/O configuration space.
204 #define IT87_REG_VID 0x0a
206 * The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b
207 * for fan divisors. Later IT8712F revisions must use 16-bit tachometer
210 #define IT87_REG_FAN_DIV 0x0b
211 #define IT87_REG_FAN_16BIT 0x0c
213 /* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */
215 static const u8 IT87_REG_FAN[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82 };
216 static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86 };
217 static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83 };
218 static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 };
219 static const u8 IT87_REG_TEMP_OFFSET[] = { 0x56, 0x57, 0x59 };
221 #define IT87_REG_FAN_MAIN_CTRL 0x13
222 #define IT87_REG_FAN_CTL 0x14
223 #define IT87_REG_PWM(nr) (0x15 + (nr))
224 #define IT87_REG_PWM_DUTY(nr) (0x63 + (nr) * 8)
226 #define IT87_REG_VIN(nr) (0x20 + (nr))
227 #define IT87_REG_TEMP(nr) (0x29 + (nr))
229 #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2)
230 #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2)
231 #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2)
232 #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2)
234 #define IT87_REG_VIN_ENABLE 0x50
235 #define IT87_REG_TEMP_ENABLE 0x51
236 #define IT87_REG_TEMP_EXTRA 0x55
237 #define IT87_REG_BEEP_ENABLE 0x5c
239 #define IT87_REG_CHIPID 0x58
241 #define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i))
242 #define IT87_REG_AUTO_PWM(nr, i) (0x65 + (nr) * 8 + (i))
244 struct it87_devices {
251 #define FEAT_12MV_ADC (1 << 0)
252 #define FEAT_NEWER_AUTOPWM (1 << 1)
253 #define FEAT_OLD_AUTOPWM (1 << 2)
254 #define FEAT_16BIT_FANS (1 << 3)
255 #define FEAT_TEMP_OFFSET (1 << 4)
256 #define FEAT_TEMP_PECI (1 << 5)
257 #define FEAT_TEMP_OLD_PECI (1 << 6)
258 #define FEAT_FAN16_CONFIG (1 << 7) /* Need to enable 16-bit fans */
259 #define FEAT_FIVE_FANS (1 << 8) /* Supports five fans */
260 #define FEAT_VID (1 << 9) /* Set if chip supports VID */
262 static const struct it87_devices it87_devices[] = {
265 .features = FEAT_OLD_AUTOPWM | FEAT_FAN16_CONFIG,
266 /* may need to overwrite */
270 .features = FEAT_OLD_AUTOPWM | FEAT_FAN16_CONFIG | FEAT_VID,
271 /* may need to overwrite */
275 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | FEAT_VID
276 | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS,
280 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | FEAT_VID
281 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS,
282 .old_peci_mask = 0x4,
286 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | FEAT_VID
287 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS,
288 .old_peci_mask = 0x4,
292 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
293 | FEAT_TEMP_OFFSET | FEAT_TEMP_OLD_PECI | FEAT_TEMP_PECI
294 | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS,
296 .old_peci_mask = 0x02, /* Actually reports PCH */
300 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
301 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_FIVE_FANS,
306 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
307 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI,
308 /* PECI: guesswork */
310 /* 16 bit fans (OHM) */
311 /* three fans, always 16 bit (guesswork) */
316 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
317 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI,
318 /* PECI (coreboot) */
319 /* 12mV ADC (HWSensors4, OHM) */
320 /* 16 bit fans (HWSensors4, OHM) */
321 /* three fans, always 16 bit (datasheet) */
326 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
327 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG,
328 .old_peci_mask = 0x4,
332 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
333 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG,
334 .old_peci_mask = 0x4,
338 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
339 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG,
340 .old_peci_mask = 0x4,
344 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
345 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI,
350 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
351 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI,
356 #define has_16bit_fans(data) ((data)->features & FEAT_16BIT_FANS)
357 #define has_12mv_adc(data) ((data)->features & FEAT_12MV_ADC)
358 #define has_newer_autopwm(data) ((data)->features & FEAT_NEWER_AUTOPWM)
359 #define has_old_autopwm(data) ((data)->features & FEAT_OLD_AUTOPWM)
360 #define has_temp_offset(data) ((data)->features & FEAT_TEMP_OFFSET)
361 #define has_temp_peci(data, nr) (((data)->features & FEAT_TEMP_PECI) && \
362 ((data)->peci_mask & (1 << nr)))
363 #define has_temp_old_peci(data, nr) \
364 (((data)->features & FEAT_TEMP_OLD_PECI) && \
365 ((data)->old_peci_mask & (1 << nr)))
366 #define has_fan16_config(data) (has_16bit_fans(data) && \
367 ((data)->features & FEAT_FAN16_CONFIG))
368 #define has_five_fans(data) ((data)->features & FEAT_FIVE_FANS)
369 #define has_vid(data) ((data)->features & FEAT_VID)
371 struct it87_sio_data {
373 /* Values read from Super-I/O config space */
377 u8 internal; /* Internal sensors can be labeled */
378 /* Features skipped based on config or DMI */
387 * For each registered chip, we need to keep some data in memory.
388 * The structure is dynamically allocated.
391 struct device *hwmon_dev;
399 struct mutex update_lock;
400 char valid; /* !=0 if following fields are valid */
401 unsigned long last_updated; /* In jiffies */
403 u16 in_scaled; /* Internal voltage sensors are scaled */
404 u8 in[10][3]; /* [nr][0]=in, [1]=min, [2]=max */
405 u8 has_fan; /* Bitfield, fans enabled */
406 u16 fan[5][2]; /* Register values, [nr][0]=fan, [1]=min */
407 u8 has_temp; /* Bitfield, temp sensors enabled */
408 s8 temp[3][4]; /* [nr][0]=temp, [1]=min, [2]=max, [3]=offset */
409 u8 sensor; /* Register value (IT87_REG_TEMP_ENABLE) */
410 u8 extra; /* Register value (IT87_REG_TEMP_EXTRA) */
411 u8 fan_div[3]; /* Register encoding, shifted right */
412 u8 vid; /* Register encoding, combined */
414 u32 alarms; /* Register encoding, combined */
415 u8 beeps; /* Register encoding */
416 u8 fan_main_ctrl; /* Register value */
417 u8 fan_ctl; /* Register value */
420 * The following 3 arrays correspond to the same registers up to
421 * the IT8720F. The meaning of bits 6-0 depends on the value of bit
422 * 7, and we want to preserve settings on mode changes, so we have
423 * to track all values separately.
424 * Starting with the IT8721F, the manual PWM duty cycles are stored
425 * in separate registers (8-bit values), so the separate tracking
426 * is no longer needed, but it is still done to keep the driver
429 u8 pwm_ctrl[3]; /* Register value */
430 u8 pwm_duty[3]; /* Manual PWM value set by user */
431 u8 pwm_temp_map[3]; /* PWM to temp. chan. mapping (bits 1-0) */
433 /* Automatic fan speed control registers */
434 u8 auto_pwm[3][4]; /* [nr][3] is hard-coded */
435 s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */
438 static int adc_lsb(const struct it87_data *data, int nr)
440 int lsb = has_12mv_adc(data) ? 12 : 16;
441 if (data->in_scaled & (1 << nr))
446 static u8 in_to_reg(const struct it87_data *data, int nr, long val)
448 val = DIV_ROUND_CLOSEST(val, adc_lsb(data, nr));
449 return clamp_val(val, 0, 255);
452 static int in_from_reg(const struct it87_data *data, int nr, int val)
454 return val * adc_lsb(data, nr);
457 static inline u8 FAN_TO_REG(long rpm, int div)
461 rpm = clamp_val(rpm, 1, 1000000);
462 return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
465 static inline u16 FAN16_TO_REG(long rpm)
469 return clamp_val((1350000 + rpm) / (rpm * 2), 1, 0xfffe);
472 #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \
473 1350000 / ((val) * (div)))
474 /* The divider is fixed to 2 in 16-bit mode */
475 #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
476 1350000 / ((val) * 2))
478 #define TEMP_TO_REG(val) (clamp_val(((val) < 0 ? (((val) - 500) / 1000) : \
479 ((val) + 500) / 1000), -128, 127))
480 #define TEMP_FROM_REG(val) ((val) * 1000)
482 static u8 pwm_to_reg(const struct it87_data *data, long val)
484 if (has_newer_autopwm(data))
490 static int pwm_from_reg(const struct it87_data *data, u8 reg)
492 if (has_newer_autopwm(data))
495 return (reg & 0x7f) << 1;
499 static int DIV_TO_REG(int val)
502 while (answer < 7 && (val >>= 1))
506 #define DIV_FROM_REG(val) (1 << (val))
508 static const unsigned int pwm_freq[8] = {
519 static int it87_probe(struct platform_device *pdev);
520 static int it87_remove(struct platform_device *pdev);
522 static int it87_read_value(struct it87_data *data, u8 reg);
523 static void it87_write_value(struct it87_data *data, u8 reg, u8 value);
524 static struct it87_data *it87_update_device(struct device *dev);
525 static int it87_check_pwm(struct device *dev);
526 static void it87_init_device(struct platform_device *pdev);
529 static struct platform_driver it87_driver = {
534 .remove = it87_remove,
537 static ssize_t show_in(struct device *dev, struct device_attribute *attr,
540 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
542 int index = sattr->index;
544 struct it87_data *data = it87_update_device(dev);
545 return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr][index]));
548 static ssize_t set_in(struct device *dev, struct device_attribute *attr,
549 const char *buf, size_t count)
551 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
553 int index = sattr->index;
555 struct it87_data *data = dev_get_drvdata(dev);
558 if (kstrtoul(buf, 10, &val) < 0)
561 mutex_lock(&data->update_lock);
562 data->in[nr][index] = in_to_reg(data, nr, val);
563 it87_write_value(data,
564 index == 1 ? IT87_REG_VIN_MIN(nr)
565 : IT87_REG_VIN_MAX(nr),
566 data->in[nr][index]);
567 mutex_unlock(&data->update_lock);
571 static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0);
572 static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_in, set_in,
574 static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_in, set_in,
577 static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 1, 0);
578 static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_in, set_in,
580 static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_in, set_in,
583 static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 2, 0);
584 static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_in, set_in,
586 static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_in, set_in,
589 static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 3, 0);
590 static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_in, set_in,
592 static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_in, set_in,
595 static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 4, 0);
596 static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_in, set_in,
598 static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_in, set_in,
601 static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 5, 0);
602 static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_in, set_in,
604 static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_in, set_in,
607 static SENSOR_DEVICE_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 6, 0);
608 static SENSOR_DEVICE_ATTR_2(in6_min, S_IRUGO | S_IWUSR, show_in, set_in,
610 static SENSOR_DEVICE_ATTR_2(in6_max, S_IRUGO | S_IWUSR, show_in, set_in,
613 static SENSOR_DEVICE_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 7, 0);
614 static SENSOR_DEVICE_ATTR_2(in7_min, S_IRUGO | S_IWUSR, show_in, set_in,
616 static SENSOR_DEVICE_ATTR_2(in7_max, S_IRUGO | S_IWUSR, show_in, set_in,
619 static SENSOR_DEVICE_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 8, 0);
620 static SENSOR_DEVICE_ATTR_2(in9_input, S_IRUGO, show_in, NULL, 9, 0);
623 static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
626 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
628 int index = sattr->index;
629 struct it87_data *data = it87_update_device(dev);
631 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr][index]));
634 static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
635 const char *buf, size_t count)
637 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
639 int index = sattr->index;
640 struct it87_data *data = dev_get_drvdata(dev);
644 if (kstrtol(buf, 10, &val) < 0)
647 mutex_lock(&data->update_lock);
652 reg = IT87_REG_TEMP_LOW(nr);
655 reg = IT87_REG_TEMP_HIGH(nr);
658 regval = it87_read_value(data, IT87_REG_BEEP_ENABLE);
659 if (!(regval & 0x80)) {
661 it87_write_value(data, IT87_REG_BEEP_ENABLE, regval);
664 reg = IT87_REG_TEMP_OFFSET[nr];
668 data->temp[nr][index] = TEMP_TO_REG(val);
669 it87_write_value(data, reg, data->temp[nr][index]);
670 mutex_unlock(&data->update_lock);
674 static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0);
675 static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
677 static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
679 static SENSOR_DEVICE_ATTR_2(temp1_offset, S_IRUGO | S_IWUSR, show_temp,
681 static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, 0);
682 static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
684 static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
686 static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IRUGO | S_IWUSR, show_temp,
688 static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 2, 0);
689 static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
691 static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
693 static SENSOR_DEVICE_ATTR_2(temp3_offset, S_IRUGO | S_IWUSR, show_temp,
696 static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr,
699 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
700 int nr = sensor_attr->index;
701 struct it87_data *data = it87_update_device(dev);
702 u8 reg = data->sensor; /* In case value is updated while used */
703 u8 extra = data->extra;
705 if ((has_temp_peci(data, nr) && (reg >> 6 == nr + 1))
706 || (has_temp_old_peci(data, nr) && (extra & 0x80)))
707 return sprintf(buf, "6\n"); /* Intel PECI */
709 return sprintf(buf, "3\n"); /* thermal diode */
711 return sprintf(buf, "4\n"); /* thermistor */
712 return sprintf(buf, "0\n"); /* disabled */
715 static ssize_t set_temp_type(struct device *dev, struct device_attribute *attr,
716 const char *buf, size_t count)
718 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
719 int nr = sensor_attr->index;
721 struct it87_data *data = dev_get_drvdata(dev);
725 if (kstrtol(buf, 10, &val) < 0)
728 reg = it87_read_value(data, IT87_REG_TEMP_ENABLE);
731 if (has_temp_peci(data, nr) && (reg >> 6 == nr + 1 || val == 6))
733 extra = it87_read_value(data, IT87_REG_TEMP_EXTRA);
734 if (has_temp_old_peci(data, nr) && ((extra & 0x80) || val == 6))
736 if (val == 2) { /* backwards compatibility */
738 "Sensor type 2 is deprecated, please use 4 instead\n");
741 /* 3 = thermal diode; 4 = thermistor; 6 = Intel PECI; 0 = disabled */
746 else if (has_temp_peci(data, nr) && val == 6)
747 reg |= (nr + 1) << 6;
748 else if (has_temp_old_peci(data, nr) && val == 6)
753 mutex_lock(&data->update_lock);
756 it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor);
757 if (has_temp_old_peci(data, nr))
758 it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra);
759 data->valid = 0; /* Force cache refresh */
760 mutex_unlock(&data->update_lock);
764 static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR, show_temp_type,
766 static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR, show_temp_type,
768 static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR, show_temp_type,
773 static int pwm_mode(const struct it87_data *data, int nr)
775 int ctrl = data->fan_main_ctrl & (1 << nr);
777 if (ctrl == 0 && data->type != it8603) /* Full speed */
779 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
781 else /* Manual mode */
785 static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
788 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
790 int index = sattr->index;
792 struct it87_data *data = it87_update_device(dev);
794 speed = has_16bit_fans(data) ?
795 FAN16_FROM_REG(data->fan[nr][index]) :
796 FAN_FROM_REG(data->fan[nr][index],
797 DIV_FROM_REG(data->fan_div[nr]));
798 return sprintf(buf, "%d\n", speed);
801 static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
804 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
805 int nr = sensor_attr->index;
807 struct it87_data *data = it87_update_device(dev);
808 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
810 static ssize_t show_pwm_enable(struct device *dev,
811 struct device_attribute *attr, char *buf)
813 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
814 int nr = sensor_attr->index;
816 struct it87_data *data = it87_update_device(dev);
817 return sprintf(buf, "%d\n", pwm_mode(data, nr));
819 static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
822 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
823 int nr = sensor_attr->index;
825 struct it87_data *data = it87_update_device(dev);
826 return sprintf(buf, "%d\n",
827 pwm_from_reg(data, data->pwm_duty[nr]));
829 static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
832 struct it87_data *data = it87_update_device(dev);
833 int index = (data->fan_ctl >> 4) & 0x07;
835 return sprintf(buf, "%u\n", pwm_freq[index]);
838 static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
839 const char *buf, size_t count)
841 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
843 int index = sattr->index;
845 struct it87_data *data = dev_get_drvdata(dev);
849 if (kstrtol(buf, 10, &val) < 0)
852 mutex_lock(&data->update_lock);
854 if (has_16bit_fans(data)) {
855 data->fan[nr][index] = FAN16_TO_REG(val);
856 it87_write_value(data, IT87_REG_FAN_MIN[nr],
857 data->fan[nr][index] & 0xff);
858 it87_write_value(data, IT87_REG_FANX_MIN[nr],
859 data->fan[nr][index] >> 8);
861 reg = it87_read_value(data, IT87_REG_FAN_DIV);
864 data->fan_div[nr] = reg & 0x07;
867 data->fan_div[nr] = (reg >> 3) & 0x07;
870 data->fan_div[nr] = (reg & 0x40) ? 3 : 1;
873 data->fan[nr][index] =
874 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
875 it87_write_value(data, IT87_REG_FAN_MIN[nr],
876 data->fan[nr][index]);
879 mutex_unlock(&data->update_lock);
883 static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
884 const char *buf, size_t count)
886 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
887 int nr = sensor_attr->index;
889 struct it87_data *data = dev_get_drvdata(dev);
894 if (kstrtoul(buf, 10, &val) < 0)
897 mutex_lock(&data->update_lock);
898 old = it87_read_value(data, IT87_REG_FAN_DIV);
900 /* Save fan min limit */
901 min = FAN_FROM_REG(data->fan[nr][1], DIV_FROM_REG(data->fan_div[nr]));
906 data->fan_div[nr] = DIV_TO_REG(val);
910 data->fan_div[nr] = 1;
912 data->fan_div[nr] = 3;
915 val |= (data->fan_div[0] & 0x07);
916 val |= (data->fan_div[1] & 0x07) << 3;
917 if (data->fan_div[2] == 3)
919 it87_write_value(data, IT87_REG_FAN_DIV, val);
921 /* Restore fan min limit */
922 data->fan[nr][1] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
923 it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan[nr][1]);
925 mutex_unlock(&data->update_lock);
929 /* Returns 0 if OK, -EINVAL otherwise */
930 static int check_trip_points(struct device *dev, int nr)
932 const struct it87_data *data = dev_get_drvdata(dev);
935 if (has_old_autopwm(data)) {
936 for (i = 0; i < 3; i++) {
937 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1])
940 for (i = 0; i < 2; i++) {
941 if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1])
948 "Inconsistent trip points, not switching to automatic mode\n");
949 dev_err(dev, "Adjust the trip points and try again\n");
954 static ssize_t set_pwm_enable(struct device *dev,
955 struct device_attribute *attr, const char *buf, size_t count)
957 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
958 int nr = sensor_attr->index;
960 struct it87_data *data = dev_get_drvdata(dev);
963 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 2)
966 /* Check trip points before switching to automatic mode */
968 if (check_trip_points(dev, nr) < 0)
972 /* IT8603E does not have on/off mode */
973 if (val == 0 && data->type == it8603)
976 mutex_lock(&data->update_lock);
980 /* make sure the fan is on when in on/off mode */
981 tmp = it87_read_value(data, IT87_REG_FAN_CTL);
982 it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr));
983 /* set on/off mode */
984 data->fan_main_ctrl &= ~(1 << nr);
985 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
986 data->fan_main_ctrl);
988 if (val == 1) /* Manual mode */
989 data->pwm_ctrl[nr] = has_newer_autopwm(data) ?
990 data->pwm_temp_map[nr] :
992 else /* Automatic mode */
993 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
994 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
996 if (data->type != it8603) {
997 /* set SmartGuardian mode */
998 data->fan_main_ctrl |= (1 << nr);
999 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
1000 data->fan_main_ctrl);
1004 mutex_unlock(&data->update_lock);
1007 static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1008 const char *buf, size_t count)
1010 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1011 int nr = sensor_attr->index;
1013 struct it87_data *data = dev_get_drvdata(dev);
1016 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
1019 mutex_lock(&data->update_lock);
1020 if (has_newer_autopwm(data)) {
1022 * If we are in automatic mode, the PWM duty cycle register
1023 * is read-only so we can't write the value.
1025 if (data->pwm_ctrl[nr] & 0x80) {
1026 mutex_unlock(&data->update_lock);
1029 data->pwm_duty[nr] = pwm_to_reg(data, val);
1030 it87_write_value(data, IT87_REG_PWM_DUTY(nr),
1031 data->pwm_duty[nr]);
1033 data->pwm_duty[nr] = pwm_to_reg(data, val);
1035 * If we are in manual mode, write the duty cycle immediately;
1036 * otherwise, just store it for later use.
1038 if (!(data->pwm_ctrl[nr] & 0x80)) {
1039 data->pwm_ctrl[nr] = data->pwm_duty[nr];
1040 it87_write_value(data, IT87_REG_PWM(nr),
1041 data->pwm_ctrl[nr]);
1044 mutex_unlock(&data->update_lock);
1047 static ssize_t set_pwm_freq(struct device *dev,
1048 struct device_attribute *attr, const char *buf, size_t count)
1050 struct it87_data *data = dev_get_drvdata(dev);
1054 if (kstrtoul(buf, 10, &val) < 0)
1057 /* Search for the nearest available frequency */
1058 for (i = 0; i < 7; i++) {
1059 if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2)
1063 mutex_lock(&data->update_lock);
1064 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f;
1065 data->fan_ctl |= i << 4;
1066 it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl);
1067 mutex_unlock(&data->update_lock);
1071 static ssize_t show_pwm_temp_map(struct device *dev,
1072 struct device_attribute *attr, char *buf)
1074 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1075 int nr = sensor_attr->index;
1077 struct it87_data *data = it87_update_device(dev);
1080 if (data->pwm_temp_map[nr] < 3)
1081 map = 1 << data->pwm_temp_map[nr];
1083 map = 0; /* Should never happen */
1084 return sprintf(buf, "%d\n", map);
1086 static ssize_t set_pwm_temp_map(struct device *dev,
1087 struct device_attribute *attr, const char *buf, size_t count)
1089 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1090 int nr = sensor_attr->index;
1092 struct it87_data *data = dev_get_drvdata(dev);
1097 * This check can go away if we ever support automatic fan speed
1098 * control on newer chips.
1100 if (!has_old_autopwm(data)) {
1101 dev_notice(dev, "Mapping change disabled for safety reasons\n");
1105 if (kstrtol(buf, 10, &val) < 0)
1122 mutex_lock(&data->update_lock);
1123 data->pwm_temp_map[nr] = reg;
1125 * If we are in automatic mode, write the temp mapping immediately;
1126 * otherwise, just store it for later use.
1128 if (data->pwm_ctrl[nr] & 0x80) {
1129 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
1130 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
1132 mutex_unlock(&data->update_lock);
1136 static ssize_t show_auto_pwm(struct device *dev,
1137 struct device_attribute *attr, char *buf)
1139 struct it87_data *data = it87_update_device(dev);
1140 struct sensor_device_attribute_2 *sensor_attr =
1141 to_sensor_dev_attr_2(attr);
1142 int nr = sensor_attr->nr;
1143 int point = sensor_attr->index;
1145 return sprintf(buf, "%d\n",
1146 pwm_from_reg(data, data->auto_pwm[nr][point]));
1149 static ssize_t set_auto_pwm(struct device *dev,
1150 struct device_attribute *attr, const char *buf, size_t count)
1152 struct it87_data *data = dev_get_drvdata(dev);
1153 struct sensor_device_attribute_2 *sensor_attr =
1154 to_sensor_dev_attr_2(attr);
1155 int nr = sensor_attr->nr;
1156 int point = sensor_attr->index;
1159 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
1162 mutex_lock(&data->update_lock);
1163 data->auto_pwm[nr][point] = pwm_to_reg(data, val);
1164 it87_write_value(data, IT87_REG_AUTO_PWM(nr, point),
1165 data->auto_pwm[nr][point]);
1166 mutex_unlock(&data->update_lock);
1170 static ssize_t show_auto_temp(struct device *dev,
1171 struct device_attribute *attr, char *buf)
1173 struct it87_data *data = it87_update_device(dev);
1174 struct sensor_device_attribute_2 *sensor_attr =
1175 to_sensor_dev_attr_2(attr);
1176 int nr = sensor_attr->nr;
1177 int point = sensor_attr->index;
1179 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->auto_temp[nr][point]));
1182 static ssize_t set_auto_temp(struct device *dev,
1183 struct device_attribute *attr, const char *buf, size_t count)
1185 struct it87_data *data = dev_get_drvdata(dev);
1186 struct sensor_device_attribute_2 *sensor_attr =
1187 to_sensor_dev_attr_2(attr);
1188 int nr = sensor_attr->nr;
1189 int point = sensor_attr->index;
1192 if (kstrtol(buf, 10, &val) < 0 || val < -128000 || val > 127000)
1195 mutex_lock(&data->update_lock);
1196 data->auto_temp[nr][point] = TEMP_TO_REG(val);
1197 it87_write_value(data, IT87_REG_AUTO_TEMP(nr, point),
1198 data->auto_temp[nr][point]);
1199 mutex_unlock(&data->update_lock);
1203 static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0);
1204 static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1206 static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, show_fan_div,
1209 static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 1, 0);
1210 static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1212 static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, show_fan_div,
1215 static SENSOR_DEVICE_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 2, 0);
1216 static SENSOR_DEVICE_ATTR_2(fan3_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1218 static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO | S_IWUSR, show_fan_div,
1221 static SENSOR_DEVICE_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 3, 0);
1222 static SENSOR_DEVICE_ATTR_2(fan4_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1225 static SENSOR_DEVICE_ATTR_2(fan5_input, S_IRUGO, show_fan, NULL, 4, 0);
1226 static SENSOR_DEVICE_ATTR_2(fan5_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1229 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
1230 show_pwm_enable, set_pwm_enable, 0);
1231 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0);
1232 static DEVICE_ATTR(pwm1_freq, S_IRUGO | S_IWUSR, show_pwm_freq, set_pwm_freq);
1233 static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IRUGO | S_IWUSR,
1234 show_pwm_temp_map, set_pwm_temp_map, 0);
1235 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR,
1236 show_auto_pwm, set_auto_pwm, 0, 0);
1237 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR,
1238 show_auto_pwm, set_auto_pwm, 0, 1);
1239 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR,
1240 show_auto_pwm, set_auto_pwm, 0, 2);
1241 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO,
1242 show_auto_pwm, NULL, 0, 3);
1243 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR,
1244 show_auto_temp, set_auto_temp, 0, 1);
1245 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1246 show_auto_temp, set_auto_temp, 0, 0);
1247 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR,
1248 show_auto_temp, set_auto_temp, 0, 2);
1249 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR,
1250 show_auto_temp, set_auto_temp, 0, 3);
1251 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR,
1252 show_auto_temp, set_auto_temp, 0, 4);
1254 static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR,
1255 show_pwm_enable, set_pwm_enable, 1);
1256 static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 1);
1257 static DEVICE_ATTR(pwm2_freq, S_IRUGO, show_pwm_freq, NULL);
1258 static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IRUGO | S_IWUSR,
1259 show_pwm_temp_map, set_pwm_temp_map, 1);
1260 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR,
1261 show_auto_pwm, set_auto_pwm, 1, 0);
1262 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO | S_IWUSR,
1263 show_auto_pwm, set_auto_pwm, 1, 1);
1264 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO | S_IWUSR,
1265 show_auto_pwm, set_auto_pwm, 1, 2);
1266 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO,
1267 show_auto_pwm, NULL, 1, 3);
1268 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR,
1269 show_auto_temp, set_auto_temp, 1, 1);
1270 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1271 show_auto_temp, set_auto_temp, 1, 0);
1272 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR,
1273 show_auto_temp, set_auto_temp, 1, 2);
1274 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR,
1275 show_auto_temp, set_auto_temp, 1, 3);
1276 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_temp, S_IRUGO | S_IWUSR,
1277 show_auto_temp, set_auto_temp, 1, 4);
1279 static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR,
1280 show_pwm_enable, set_pwm_enable, 2);
1281 static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 2);
1282 static DEVICE_ATTR(pwm3_freq, S_IRUGO, show_pwm_freq, NULL);
1283 static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IRUGO | S_IWUSR,
1284 show_pwm_temp_map, set_pwm_temp_map, 2);
1285 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO | S_IWUSR,
1286 show_auto_pwm, set_auto_pwm, 2, 0);
1287 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR,
1288 show_auto_pwm, set_auto_pwm, 2, 1);
1289 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO | S_IWUSR,
1290 show_auto_pwm, set_auto_pwm, 2, 2);
1291 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO,
1292 show_auto_pwm, NULL, 2, 3);
1293 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp, S_IRUGO | S_IWUSR,
1294 show_auto_temp, set_auto_temp, 2, 1);
1295 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1296 show_auto_temp, set_auto_temp, 2, 0);
1297 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_temp, S_IRUGO | S_IWUSR,
1298 show_auto_temp, set_auto_temp, 2, 2);
1299 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_temp, S_IRUGO | S_IWUSR,
1300 show_auto_temp, set_auto_temp, 2, 3);
1301 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_temp, S_IRUGO | S_IWUSR,
1302 show_auto_temp, set_auto_temp, 2, 4);
1305 static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
1308 struct it87_data *data = it87_update_device(dev);
1309 return sprintf(buf, "%u\n", data->alarms);
1311 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
1313 static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
1316 int bitnr = to_sensor_dev_attr(attr)->index;
1317 struct it87_data *data = it87_update_device(dev);
1318 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
1321 static ssize_t clear_intrusion(struct device *dev, struct device_attribute
1322 *attr, const char *buf, size_t count)
1324 struct it87_data *data = dev_get_drvdata(dev);
1328 if (kstrtol(buf, 10, &val) < 0 || val != 0)
1331 mutex_lock(&data->update_lock);
1332 config = it87_read_value(data, IT87_REG_CONFIG);
1337 it87_write_value(data, IT87_REG_CONFIG, config);
1338 /* Invalidate cache to force re-read */
1341 mutex_unlock(&data->update_lock);
1346 static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8);
1347 static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9);
1348 static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10);
1349 static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11);
1350 static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12);
1351 static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13);
1352 static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14);
1353 static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15);
1354 static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0);
1355 static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1);
1356 static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2);
1357 static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3);
1358 static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6);
1359 static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16);
1360 static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17);
1361 static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18);
1362 static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR,
1363 show_alarm, clear_intrusion, 4);
1365 static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
1368 int bitnr = to_sensor_dev_attr(attr)->index;
1369 struct it87_data *data = it87_update_device(dev);
1370 return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1);
1372 static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
1373 const char *buf, size_t count)
1375 int bitnr = to_sensor_dev_attr(attr)->index;
1376 struct it87_data *data = dev_get_drvdata(dev);
1379 if (kstrtol(buf, 10, &val) < 0
1380 || (val != 0 && val != 1))
1383 mutex_lock(&data->update_lock);
1384 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
1386 data->beeps |= (1 << bitnr);
1388 data->beeps &= ~(1 << bitnr);
1389 it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps);
1390 mutex_unlock(&data->update_lock);
1394 static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
1395 show_beep, set_beep, 1);
1396 static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO, show_beep, NULL, 1);
1397 static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO, show_beep, NULL, 1);
1398 static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO, show_beep, NULL, 1);
1399 static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO, show_beep, NULL, 1);
1400 static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO, show_beep, NULL, 1);
1401 static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO, show_beep, NULL, 1);
1402 static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO, show_beep, NULL, 1);
1403 /* fanX_beep writability is set later */
1404 static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO, show_beep, set_beep, 0);
1405 static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0);
1406 static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0);
1407 static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0);
1408 static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0);
1409 static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
1410 show_beep, set_beep, 2);
1411 static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2);
1412 static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2);
1414 static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
1417 struct it87_data *data = dev_get_drvdata(dev);
1418 return sprintf(buf, "%u\n", data->vrm);
1420 static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
1421 const char *buf, size_t count)
1423 struct it87_data *data = dev_get_drvdata(dev);
1426 if (kstrtoul(buf, 10, &val) < 0)
1433 static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
1435 static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
1438 struct it87_data *data = it87_update_device(dev);
1439 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
1441 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
1443 static ssize_t show_label(struct device *dev, struct device_attribute *attr,
1446 static const char * const labels[] = {
1451 static const char * const labels_it8721[] = {
1456 struct it87_data *data = dev_get_drvdata(dev);
1457 int nr = to_sensor_dev_attr(attr)->index;
1459 return sprintf(buf, "%s\n", has_12mv_adc(data) ? labels_it8721[nr]
1462 static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0);
1463 static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1);
1464 static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 2);
1465 /* special AVCC3 IT8603E in9 */
1466 static SENSOR_DEVICE_ATTR(in9_label, S_IRUGO, show_label, NULL, 0);
1468 static ssize_t show_name(struct device *dev, struct device_attribute
1469 *devattr, char *buf)
1471 struct it87_data *data = dev_get_drvdata(dev);
1472 return sprintf(buf, "%s\n", data->name);
1474 static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
1476 static struct attribute *it87_attributes_in[10][5] = {
1478 &sensor_dev_attr_in0_input.dev_attr.attr,
1479 &sensor_dev_attr_in0_min.dev_attr.attr,
1480 &sensor_dev_attr_in0_max.dev_attr.attr,
1481 &sensor_dev_attr_in0_alarm.dev_attr.attr,
1484 &sensor_dev_attr_in1_input.dev_attr.attr,
1485 &sensor_dev_attr_in1_min.dev_attr.attr,
1486 &sensor_dev_attr_in1_max.dev_attr.attr,
1487 &sensor_dev_attr_in1_alarm.dev_attr.attr,
1490 &sensor_dev_attr_in2_input.dev_attr.attr,
1491 &sensor_dev_attr_in2_min.dev_attr.attr,
1492 &sensor_dev_attr_in2_max.dev_attr.attr,
1493 &sensor_dev_attr_in2_alarm.dev_attr.attr,
1496 &sensor_dev_attr_in3_input.dev_attr.attr,
1497 &sensor_dev_attr_in3_min.dev_attr.attr,
1498 &sensor_dev_attr_in3_max.dev_attr.attr,
1499 &sensor_dev_attr_in3_alarm.dev_attr.attr,
1502 &sensor_dev_attr_in4_input.dev_attr.attr,
1503 &sensor_dev_attr_in4_min.dev_attr.attr,
1504 &sensor_dev_attr_in4_max.dev_attr.attr,
1505 &sensor_dev_attr_in4_alarm.dev_attr.attr,
1508 &sensor_dev_attr_in5_input.dev_attr.attr,
1509 &sensor_dev_attr_in5_min.dev_attr.attr,
1510 &sensor_dev_attr_in5_max.dev_attr.attr,
1511 &sensor_dev_attr_in5_alarm.dev_attr.attr,
1514 &sensor_dev_attr_in6_input.dev_attr.attr,
1515 &sensor_dev_attr_in6_min.dev_attr.attr,
1516 &sensor_dev_attr_in6_max.dev_attr.attr,
1517 &sensor_dev_attr_in6_alarm.dev_attr.attr,
1520 &sensor_dev_attr_in7_input.dev_attr.attr,
1521 &sensor_dev_attr_in7_min.dev_attr.attr,
1522 &sensor_dev_attr_in7_max.dev_attr.attr,
1523 &sensor_dev_attr_in7_alarm.dev_attr.attr,
1526 &sensor_dev_attr_in8_input.dev_attr.attr,
1529 &sensor_dev_attr_in9_input.dev_attr.attr,
1533 static const struct attribute_group it87_group_in[10] = {
1534 { .attrs = it87_attributes_in[0] },
1535 { .attrs = it87_attributes_in[1] },
1536 { .attrs = it87_attributes_in[2] },
1537 { .attrs = it87_attributes_in[3] },
1538 { .attrs = it87_attributes_in[4] },
1539 { .attrs = it87_attributes_in[5] },
1540 { .attrs = it87_attributes_in[6] },
1541 { .attrs = it87_attributes_in[7] },
1542 { .attrs = it87_attributes_in[8] },
1543 { .attrs = it87_attributes_in[9] },
1546 static struct attribute *it87_attributes_temp[3][6] = {
1548 &sensor_dev_attr_temp1_input.dev_attr.attr,
1549 &sensor_dev_attr_temp1_max.dev_attr.attr,
1550 &sensor_dev_attr_temp1_min.dev_attr.attr,
1551 &sensor_dev_attr_temp1_type.dev_attr.attr,
1552 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
1555 &sensor_dev_attr_temp2_input.dev_attr.attr,
1556 &sensor_dev_attr_temp2_max.dev_attr.attr,
1557 &sensor_dev_attr_temp2_min.dev_attr.attr,
1558 &sensor_dev_attr_temp2_type.dev_attr.attr,
1559 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
1562 &sensor_dev_attr_temp3_input.dev_attr.attr,
1563 &sensor_dev_attr_temp3_max.dev_attr.attr,
1564 &sensor_dev_attr_temp3_min.dev_attr.attr,
1565 &sensor_dev_attr_temp3_type.dev_attr.attr,
1566 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
1570 static const struct attribute_group it87_group_temp[3] = {
1571 { .attrs = it87_attributes_temp[0] },
1572 { .attrs = it87_attributes_temp[1] },
1573 { .attrs = it87_attributes_temp[2] },
1576 static struct attribute *it87_attributes_temp_offset[] = {
1577 &sensor_dev_attr_temp1_offset.dev_attr.attr,
1578 &sensor_dev_attr_temp2_offset.dev_attr.attr,
1579 &sensor_dev_attr_temp3_offset.dev_attr.attr,
1582 static struct attribute *it87_attributes[] = {
1583 &dev_attr_alarms.attr,
1584 &sensor_dev_attr_intrusion0_alarm.dev_attr.attr,
1585 &dev_attr_name.attr,
1589 static const struct attribute_group it87_group = {
1590 .attrs = it87_attributes,
1593 static struct attribute *it87_attributes_in_beep[] = {
1594 &sensor_dev_attr_in0_beep.dev_attr.attr,
1595 &sensor_dev_attr_in1_beep.dev_attr.attr,
1596 &sensor_dev_attr_in2_beep.dev_attr.attr,
1597 &sensor_dev_attr_in3_beep.dev_attr.attr,
1598 &sensor_dev_attr_in4_beep.dev_attr.attr,
1599 &sensor_dev_attr_in5_beep.dev_attr.attr,
1600 &sensor_dev_attr_in6_beep.dev_attr.attr,
1601 &sensor_dev_attr_in7_beep.dev_attr.attr,
1606 static struct attribute *it87_attributes_temp_beep[] = {
1607 &sensor_dev_attr_temp1_beep.dev_attr.attr,
1608 &sensor_dev_attr_temp2_beep.dev_attr.attr,
1609 &sensor_dev_attr_temp3_beep.dev_attr.attr,
1612 static struct attribute *it87_attributes_fan[5][3+1] = { {
1613 &sensor_dev_attr_fan1_input.dev_attr.attr,
1614 &sensor_dev_attr_fan1_min.dev_attr.attr,
1615 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1618 &sensor_dev_attr_fan2_input.dev_attr.attr,
1619 &sensor_dev_attr_fan2_min.dev_attr.attr,
1620 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1623 &sensor_dev_attr_fan3_input.dev_attr.attr,
1624 &sensor_dev_attr_fan3_min.dev_attr.attr,
1625 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
1628 &sensor_dev_attr_fan4_input.dev_attr.attr,
1629 &sensor_dev_attr_fan4_min.dev_attr.attr,
1630 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
1633 &sensor_dev_attr_fan5_input.dev_attr.attr,
1634 &sensor_dev_attr_fan5_min.dev_attr.attr,
1635 &sensor_dev_attr_fan5_alarm.dev_attr.attr,
1639 static const struct attribute_group it87_group_fan[5] = {
1640 { .attrs = it87_attributes_fan[0] },
1641 { .attrs = it87_attributes_fan[1] },
1642 { .attrs = it87_attributes_fan[2] },
1643 { .attrs = it87_attributes_fan[3] },
1644 { .attrs = it87_attributes_fan[4] },
1647 static const struct attribute *it87_attributes_fan_div[] = {
1648 &sensor_dev_attr_fan1_div.dev_attr.attr,
1649 &sensor_dev_attr_fan2_div.dev_attr.attr,
1650 &sensor_dev_attr_fan3_div.dev_attr.attr,
1653 static struct attribute *it87_attributes_pwm[3][4+1] = { {
1654 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
1655 &sensor_dev_attr_pwm1.dev_attr.attr,
1656 &dev_attr_pwm1_freq.attr,
1657 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
1660 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1661 &sensor_dev_attr_pwm2.dev_attr.attr,
1662 &dev_attr_pwm2_freq.attr,
1663 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
1666 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
1667 &sensor_dev_attr_pwm3.dev_attr.attr,
1668 &dev_attr_pwm3_freq.attr,
1669 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
1673 static const struct attribute_group it87_group_pwm[3] = {
1674 { .attrs = it87_attributes_pwm[0] },
1675 { .attrs = it87_attributes_pwm[1] },
1676 { .attrs = it87_attributes_pwm[2] },
1679 static struct attribute *it87_attributes_autopwm[3][9+1] = { {
1680 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
1681 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
1682 &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr,
1683 &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr,
1684 &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
1685 &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr,
1686 &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr,
1687 &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr,
1688 &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr,
1691 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
1692 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
1693 &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr,
1694 &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr,
1695 &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr,
1696 &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr,
1697 &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr,
1698 &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr,
1699 &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr,
1702 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
1703 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
1704 &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr,
1705 &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr,
1706 &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr,
1707 &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr,
1708 &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr,
1709 &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr,
1710 &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr,
1714 static const struct attribute_group it87_group_autopwm[3] = {
1715 { .attrs = it87_attributes_autopwm[0] },
1716 { .attrs = it87_attributes_autopwm[1] },
1717 { .attrs = it87_attributes_autopwm[2] },
1720 static struct attribute *it87_attributes_fan_beep[] = {
1721 &sensor_dev_attr_fan1_beep.dev_attr.attr,
1722 &sensor_dev_attr_fan2_beep.dev_attr.attr,
1723 &sensor_dev_attr_fan3_beep.dev_attr.attr,
1724 &sensor_dev_attr_fan4_beep.dev_attr.attr,
1725 &sensor_dev_attr_fan5_beep.dev_attr.attr,
1728 static struct attribute *it87_attributes_vid[] = {
1730 &dev_attr_cpu0_vid.attr,
1734 static const struct attribute_group it87_group_vid = {
1735 .attrs = it87_attributes_vid,
1738 static struct attribute *it87_attributes_label[] = {
1739 &sensor_dev_attr_in3_label.dev_attr.attr,
1740 &sensor_dev_attr_in7_label.dev_attr.attr,
1741 &sensor_dev_attr_in8_label.dev_attr.attr,
1742 &sensor_dev_attr_in9_label.dev_attr.attr,
1746 static const struct attribute_group it87_group_label = {
1747 .attrs = it87_attributes_label,
1750 /* SuperIO detection - will change isa_address if a chip is found */
1751 static int __init it87_find(unsigned short *address,
1752 struct it87_sio_data *sio_data)
1756 const char *board_vendor, *board_name;
1758 err = superio_enter();
1763 chip_type = force_id ? force_id : superio_inw(DEVID);
1765 switch (chip_type) {
1767 sio_data->type = it87;
1770 sio_data->type = it8712;
1774 sio_data->type = it8716;
1777 sio_data->type = it8718;
1780 sio_data->type = it8720;
1783 sio_data->type = it8721;
1786 sio_data->type = it8728;
1789 sio_data->type = it8771;
1792 sio_data->type = it8772;
1795 sio_data->type = it8781;
1798 sio_data->type = it8782;
1801 sio_data->type = it8783;
1804 sio_data->type = it8786;
1808 sio_data->type = it8603;
1810 case 0xffff: /* No device at all */
1813 pr_debug("Unsupported chip (DEVID=0x%x)\n", chip_type);
1817 superio_select(PME);
1818 if (!(superio_inb(IT87_ACT_REG) & 0x01)) {
1819 pr_info("Device not activated, skipping\n");
1823 *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1);
1824 if (*address == 0) {
1825 pr_info("Base address not set, skipping\n");
1830 sio_data->revision = superio_inb(DEVREV) & 0x0f;
1831 pr_info("Found IT%04x%c chip at 0x%x, revision %d\n", chip_type,
1832 chip_type == 0x8771 || chip_type == 0x8772 ||
1833 chip_type == 0x8603 || chip_type == 0x8786 ? 'E' : 'F', *address,
1834 sio_data->revision);
1836 /* in8 (Vbat) is always internal */
1837 sio_data->internal = (1 << 2);
1838 /* Only the IT8603E has in9 */
1839 if (sio_data->type != it8603)
1840 sio_data->skip_in |= (1 << 9);
1842 if (!(it87_devices[sio_data->type].features & FEAT_VID))
1843 sio_data->skip_vid = 1;
1845 /* Read GPIO config and VID value from LDN 7 (GPIO) */
1846 if (sio_data->type == it87) {
1847 /* The IT8705F has a different LD number for GPIO */
1849 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
1850 } else if (sio_data->type == it8783) {
1851 int reg25, reg27, reg2a, reg2c, regef;
1853 superio_select(GPIO);
1855 reg25 = superio_inb(IT87_SIO_GPIO1_REG);
1856 reg27 = superio_inb(IT87_SIO_GPIO3_REG);
1857 reg2a = superio_inb(IT87_SIO_PINX1_REG);
1858 reg2c = superio_inb(IT87_SIO_PINX2_REG);
1859 regef = superio_inb(IT87_SIO_SPI_REG);
1861 /* Check if fan3 is there or not */
1862 if ((reg27 & (1 << 0)) || !(reg2c & (1 << 2)))
1863 sio_data->skip_fan |= (1 << 2);
1864 if ((reg25 & (1 << 4))
1865 || (!(reg2a & (1 << 1)) && (regef & (1 << 0))))
1866 sio_data->skip_pwm |= (1 << 2);
1868 /* Check if fan2 is there or not */
1869 if (reg27 & (1 << 7))
1870 sio_data->skip_fan |= (1 << 1);
1871 if (reg27 & (1 << 3))
1872 sio_data->skip_pwm |= (1 << 1);
1875 if ((reg27 & (1 << 0)) || (reg2c & (1 << 2)))
1876 sio_data->skip_in |= (1 << 5); /* No VIN5 */
1879 if (reg27 & (1 << 1))
1880 sio_data->skip_in |= (1 << 6); /* No VIN6 */
1884 * Does not depend on bit 2 of Reg2C, contrary to datasheet.
1886 if (reg27 & (1 << 2)) {
1888 * The data sheet is a bit unclear regarding the
1889 * internal voltage divider for VCCH5V. It says
1890 * "This bit enables and switches VIN7 (pin 91) to the
1891 * internal voltage divider for VCCH5V".
1892 * This is different to other chips, where the internal
1893 * voltage divider would connect VIN7 to an internal
1894 * voltage source. Maybe that is the case here as well.
1896 * Since we don't know for sure, re-route it if that is
1897 * not the case, and ask the user to report if the
1898 * resulting voltage is sane.
1900 if (!(reg2c & (1 << 1))) {
1902 superio_outb(IT87_SIO_PINX2_REG, reg2c);
1903 pr_notice("Routing internal VCCH5V to in7.\n");
1905 pr_notice("in7 routed to internal voltage divider, with external pin disabled.\n");
1906 pr_notice("Please report if it displays a reasonable voltage.\n");
1909 if (reg2c & (1 << 0))
1910 sio_data->internal |= (1 << 0);
1911 if (reg2c & (1 << 1))
1912 sio_data->internal |= (1 << 1);
1914 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
1915 } else if (sio_data->type == it8603) {
1918 superio_select(GPIO);
1920 reg27 = superio_inb(IT87_SIO_GPIO3_REG);
1922 /* Check if fan3 is there or not */
1923 if (reg27 & (1 << 6))
1924 sio_data->skip_pwm |= (1 << 2);
1925 if (reg27 & (1 << 7))
1926 sio_data->skip_fan |= (1 << 2);
1928 /* Check if fan2 is there or not */
1929 reg29 = superio_inb(IT87_SIO_GPIO5_REG);
1930 if (reg29 & (1 << 1))
1931 sio_data->skip_pwm |= (1 << 1);
1932 if (reg29 & (1 << 2))
1933 sio_data->skip_fan |= (1 << 1);
1935 sio_data->skip_in |= (1 << 5); /* No VIN5 */
1936 sio_data->skip_in |= (1 << 6); /* No VIN6 */
1939 sio_data->skip_pwm |= (1 << 3);
1940 sio_data->skip_fan |= (1 << 3);
1942 sio_data->internal |= (1 << 1); /* in7 is VSB */
1943 sio_data->internal |= (1 << 3); /* in9 is AVCC */
1945 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
1950 superio_select(GPIO);
1952 reg = superio_inb(IT87_SIO_GPIO3_REG);
1953 if (!sio_data->skip_vid) {
1954 /* We need at least 4 VID pins */
1956 pr_info("VID is disabled (pins used for GPIO)\n");
1957 sio_data->skip_vid = 1;
1961 /* Check if fan3 is there or not */
1963 sio_data->skip_pwm |= (1 << 2);
1965 sio_data->skip_fan |= (1 << 2);
1967 /* Check if fan2 is there or not */
1968 reg = superio_inb(IT87_SIO_GPIO5_REG);
1970 sio_data->skip_pwm |= (1 << 1);
1972 sio_data->skip_fan |= (1 << 1);
1974 if (!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 || sio_data->type == it8786)
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);