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)
257 static const struct it87_devices it87_devices[] = {
260 .features = FEAT_OLD_AUTOPWM, /* may need to overwrite */
264 .features = FEAT_OLD_AUTOPWM, /* may need to overwrite */
268 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET,
272 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
273 | FEAT_TEMP_OLD_PECI,
274 .old_peci_mask = 0x4,
278 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
279 | FEAT_TEMP_OLD_PECI,
280 .old_peci_mask = 0x4,
284 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
285 | FEAT_TEMP_OFFSET | FEAT_TEMP_OLD_PECI | FEAT_TEMP_PECI,
287 .old_peci_mask = 0x02, /* Actually reports PCH */
291 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
292 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI,
297 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
298 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI,
299 /* PECI: guesswork */
301 /* 16 bit fans (OHM) */
306 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
307 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI,
308 /* PECI (coreboot) */
309 /* 12mV ADC (HWSensors4, OHM) */
310 /* 16 bit fans (HWSensors4, OHM) */
315 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
316 | FEAT_TEMP_OLD_PECI,
317 .old_peci_mask = 0x4,
321 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
322 | FEAT_TEMP_OLD_PECI,
323 .old_peci_mask = 0x4,
327 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
328 | FEAT_TEMP_OLD_PECI,
329 .old_peci_mask = 0x4,
333 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
334 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI,
339 #define has_16bit_fans(data) ((data)->features & FEAT_16BIT_FANS)
340 #define has_12mv_adc(data) ((data)->features & FEAT_12MV_ADC)
341 #define has_newer_autopwm(data) ((data)->features & FEAT_NEWER_AUTOPWM)
342 #define has_old_autopwm(data) ((data)->features & FEAT_OLD_AUTOPWM)
343 #define has_temp_offset(data) ((data)->features & FEAT_TEMP_OFFSET)
344 #define has_temp_peci(data, nr) (((data)->features & FEAT_TEMP_PECI) && \
345 ((data)->peci_mask & (1 << nr)))
346 #define has_temp_old_peci(data, nr) \
347 (((data)->features & FEAT_TEMP_OLD_PECI) && \
348 ((data)->old_peci_mask & (1 << nr)))
350 struct it87_sio_data {
352 /* Values read from Super-I/O config space */
356 u8 internal; /* Internal sensors can be labeled */
357 /* Features skipped based on config or DMI */
366 * For each registered chip, we need to keep some data in memory.
367 * The structure is dynamically allocated.
370 struct device *hwmon_dev;
378 struct mutex update_lock;
379 char valid; /* !=0 if following fields are valid */
380 unsigned long last_updated; /* In jiffies */
382 u16 in_scaled; /* Internal voltage sensors are scaled */
383 u8 in[10][3]; /* [nr][0]=in, [1]=min, [2]=max */
384 u8 has_fan; /* Bitfield, fans enabled */
385 u16 fan[5][2]; /* Register values, [nr][0]=fan, [1]=min */
386 u8 has_temp; /* Bitfield, temp sensors enabled */
387 s8 temp[3][4]; /* [nr][0]=temp, [1]=min, [2]=max, [3]=offset */
388 u8 sensor; /* Register value (IT87_REG_TEMP_ENABLE) */
389 u8 extra; /* Register value (IT87_REG_TEMP_EXTRA) */
390 u8 fan_div[3]; /* Register encoding, shifted right */
391 u8 vid; /* Register encoding, combined */
393 u32 alarms; /* Register encoding, combined */
394 u8 beeps; /* Register encoding */
395 u8 fan_main_ctrl; /* Register value */
396 u8 fan_ctl; /* Register value */
399 * The following 3 arrays correspond to the same registers up to
400 * the IT8720F. The meaning of bits 6-0 depends on the value of bit
401 * 7, and we want to preserve settings on mode changes, so we have
402 * to track all values separately.
403 * Starting with the IT8721F, the manual PWM duty cycles are stored
404 * in separate registers (8-bit values), so the separate tracking
405 * is no longer needed, but it is still done to keep the driver
408 u8 pwm_ctrl[3]; /* Register value */
409 u8 pwm_duty[3]; /* Manual PWM value set by user */
410 u8 pwm_temp_map[3]; /* PWM to temp. chan. mapping (bits 1-0) */
412 /* Automatic fan speed control registers */
413 u8 auto_pwm[3][4]; /* [nr][3] is hard-coded */
414 s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */
417 static int adc_lsb(const struct it87_data *data, int nr)
419 int lsb = has_12mv_adc(data) ? 12 : 16;
420 if (data->in_scaled & (1 << nr))
425 static u8 in_to_reg(const struct it87_data *data, int nr, long val)
427 val = DIV_ROUND_CLOSEST(val, adc_lsb(data, nr));
428 return clamp_val(val, 0, 255);
431 static int in_from_reg(const struct it87_data *data, int nr, int val)
433 return val * adc_lsb(data, nr);
436 static inline u8 FAN_TO_REG(long rpm, int div)
440 rpm = clamp_val(rpm, 1, 1000000);
441 return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
444 static inline u16 FAN16_TO_REG(long rpm)
448 return clamp_val((1350000 + rpm) / (rpm * 2), 1, 0xfffe);
451 #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \
452 1350000 / ((val) * (div)))
453 /* The divider is fixed to 2 in 16-bit mode */
454 #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
455 1350000 / ((val) * 2))
457 #define TEMP_TO_REG(val) (clamp_val(((val) < 0 ? (((val) - 500) / 1000) : \
458 ((val) + 500) / 1000), -128, 127))
459 #define TEMP_FROM_REG(val) ((val) * 1000)
461 static u8 pwm_to_reg(const struct it87_data *data, long val)
463 if (has_newer_autopwm(data))
469 static int pwm_from_reg(const struct it87_data *data, u8 reg)
471 if (has_newer_autopwm(data))
474 return (reg & 0x7f) << 1;
478 static int DIV_TO_REG(int val)
481 while (answer < 7 && (val >>= 1))
485 #define DIV_FROM_REG(val) (1 << (val))
487 static const unsigned int pwm_freq[8] = {
498 static int it87_probe(struct platform_device *pdev);
499 static int it87_remove(struct platform_device *pdev);
501 static int it87_read_value(struct it87_data *data, u8 reg);
502 static void it87_write_value(struct it87_data *data, u8 reg, u8 value);
503 static struct it87_data *it87_update_device(struct device *dev);
504 static int it87_check_pwm(struct device *dev);
505 static void it87_init_device(struct platform_device *pdev);
508 static struct platform_driver it87_driver = {
513 .remove = it87_remove,
516 static ssize_t show_in(struct device *dev, struct device_attribute *attr,
519 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
521 int index = sattr->index;
523 struct it87_data *data = it87_update_device(dev);
524 return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr][index]));
527 static ssize_t set_in(struct device *dev, struct device_attribute *attr,
528 const char *buf, size_t count)
530 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
532 int index = sattr->index;
534 struct it87_data *data = dev_get_drvdata(dev);
537 if (kstrtoul(buf, 10, &val) < 0)
540 mutex_lock(&data->update_lock);
541 data->in[nr][index] = in_to_reg(data, nr, val);
542 it87_write_value(data,
543 index == 1 ? IT87_REG_VIN_MIN(nr)
544 : IT87_REG_VIN_MAX(nr),
545 data->in[nr][index]);
546 mutex_unlock(&data->update_lock);
550 static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0);
551 static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_in, set_in,
553 static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_in, set_in,
556 static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 1, 0);
557 static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_in, set_in,
559 static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_in, set_in,
562 static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 2, 0);
563 static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_in, set_in,
565 static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_in, set_in,
568 static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 3, 0);
569 static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_in, set_in,
571 static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_in, set_in,
574 static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 4, 0);
575 static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_in, set_in,
577 static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_in, set_in,
580 static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 5, 0);
581 static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_in, set_in,
583 static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_in, set_in,
586 static SENSOR_DEVICE_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 6, 0);
587 static SENSOR_DEVICE_ATTR_2(in6_min, S_IRUGO | S_IWUSR, show_in, set_in,
589 static SENSOR_DEVICE_ATTR_2(in6_max, S_IRUGO | S_IWUSR, show_in, set_in,
592 static SENSOR_DEVICE_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 7, 0);
593 static SENSOR_DEVICE_ATTR_2(in7_min, S_IRUGO | S_IWUSR, show_in, set_in,
595 static SENSOR_DEVICE_ATTR_2(in7_max, S_IRUGO | S_IWUSR, show_in, set_in,
598 static SENSOR_DEVICE_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 8, 0);
599 static SENSOR_DEVICE_ATTR_2(in9_input, S_IRUGO, show_in, NULL, 9, 0);
602 static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
605 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
607 int index = sattr->index;
608 struct it87_data *data = it87_update_device(dev);
610 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr][index]));
613 static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
614 const char *buf, size_t count)
616 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
618 int index = sattr->index;
619 struct it87_data *data = dev_get_drvdata(dev);
623 if (kstrtol(buf, 10, &val) < 0)
626 mutex_lock(&data->update_lock);
631 reg = IT87_REG_TEMP_LOW(nr);
634 reg = IT87_REG_TEMP_HIGH(nr);
637 regval = it87_read_value(data, IT87_REG_BEEP_ENABLE);
638 if (!(regval & 0x80)) {
640 it87_write_value(data, IT87_REG_BEEP_ENABLE, regval);
643 reg = IT87_REG_TEMP_OFFSET[nr];
647 data->temp[nr][index] = TEMP_TO_REG(val);
648 it87_write_value(data, reg, data->temp[nr][index]);
649 mutex_unlock(&data->update_lock);
653 static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0);
654 static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
656 static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
658 static SENSOR_DEVICE_ATTR_2(temp1_offset, S_IRUGO | S_IWUSR, show_temp,
660 static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, 0);
661 static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
663 static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
665 static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IRUGO | S_IWUSR, show_temp,
667 static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 2, 0);
668 static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
670 static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
672 static SENSOR_DEVICE_ATTR_2(temp3_offset, S_IRUGO | S_IWUSR, show_temp,
675 static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr,
678 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
679 int nr = sensor_attr->index;
680 struct it87_data *data = it87_update_device(dev);
681 u8 reg = data->sensor; /* In case value is updated while used */
682 u8 extra = data->extra;
684 if ((has_temp_peci(data, nr) && (reg >> 6 == nr + 1))
685 || (has_temp_old_peci(data, nr) && (extra & 0x80)))
686 return sprintf(buf, "6\n"); /* Intel PECI */
688 return sprintf(buf, "3\n"); /* thermal diode */
690 return sprintf(buf, "4\n"); /* thermistor */
691 return sprintf(buf, "0\n"); /* disabled */
694 static ssize_t set_temp_type(struct device *dev, struct device_attribute *attr,
695 const char *buf, size_t count)
697 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
698 int nr = sensor_attr->index;
700 struct it87_data *data = dev_get_drvdata(dev);
704 if (kstrtol(buf, 10, &val) < 0)
707 reg = it87_read_value(data, IT87_REG_TEMP_ENABLE);
710 if (has_temp_peci(data, nr) && (reg >> 6 == nr + 1 || val == 6))
712 extra = it87_read_value(data, IT87_REG_TEMP_EXTRA);
713 if (has_temp_old_peci(data, nr) && ((extra & 0x80) || val == 6))
715 if (val == 2) { /* backwards compatibility */
717 "Sensor type 2 is deprecated, please use 4 instead\n");
720 /* 3 = thermal diode; 4 = thermistor; 6 = Intel PECI; 0 = disabled */
725 else if (has_temp_peci(data, nr) && val == 6)
726 reg |= (nr + 1) << 6;
727 else if (has_temp_old_peci(data, nr) && val == 6)
732 mutex_lock(&data->update_lock);
735 it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor);
736 if (has_temp_old_peci(data, nr))
737 it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra);
738 data->valid = 0; /* Force cache refresh */
739 mutex_unlock(&data->update_lock);
743 static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR, show_temp_type,
745 static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR, show_temp_type,
747 static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR, show_temp_type,
752 static int pwm_mode(const struct it87_data *data, int nr)
754 int ctrl = data->fan_main_ctrl & (1 << nr);
756 if (ctrl == 0 && data->type != it8603) /* Full speed */
758 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
760 else /* Manual mode */
764 static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
767 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
769 int index = sattr->index;
771 struct it87_data *data = it87_update_device(dev);
773 speed = has_16bit_fans(data) ?
774 FAN16_FROM_REG(data->fan[nr][index]) :
775 FAN_FROM_REG(data->fan[nr][index],
776 DIV_FROM_REG(data->fan_div[nr]));
777 return sprintf(buf, "%d\n", speed);
780 static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
783 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
784 int nr = sensor_attr->index;
786 struct it87_data *data = it87_update_device(dev);
787 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
789 static ssize_t show_pwm_enable(struct device *dev,
790 struct device_attribute *attr, char *buf)
792 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
793 int nr = sensor_attr->index;
795 struct it87_data *data = it87_update_device(dev);
796 return sprintf(buf, "%d\n", pwm_mode(data, nr));
798 static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
801 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
802 int nr = sensor_attr->index;
804 struct it87_data *data = it87_update_device(dev);
805 return sprintf(buf, "%d\n",
806 pwm_from_reg(data, data->pwm_duty[nr]));
808 static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
811 struct it87_data *data = it87_update_device(dev);
812 int index = (data->fan_ctl >> 4) & 0x07;
814 return sprintf(buf, "%u\n", pwm_freq[index]);
817 static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
818 const char *buf, size_t count)
820 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
822 int index = sattr->index;
824 struct it87_data *data = dev_get_drvdata(dev);
828 if (kstrtol(buf, 10, &val) < 0)
831 mutex_lock(&data->update_lock);
833 if (has_16bit_fans(data)) {
834 data->fan[nr][index] = FAN16_TO_REG(val);
835 it87_write_value(data, IT87_REG_FAN_MIN[nr],
836 data->fan[nr][index] & 0xff);
837 it87_write_value(data, IT87_REG_FANX_MIN[nr],
838 data->fan[nr][index] >> 8);
840 reg = it87_read_value(data, IT87_REG_FAN_DIV);
843 data->fan_div[nr] = reg & 0x07;
846 data->fan_div[nr] = (reg >> 3) & 0x07;
849 data->fan_div[nr] = (reg & 0x40) ? 3 : 1;
852 data->fan[nr][index] =
853 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
854 it87_write_value(data, IT87_REG_FAN_MIN[nr],
855 data->fan[nr][index]);
858 mutex_unlock(&data->update_lock);
862 static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
863 const char *buf, size_t count)
865 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
866 int nr = sensor_attr->index;
868 struct it87_data *data = dev_get_drvdata(dev);
873 if (kstrtoul(buf, 10, &val) < 0)
876 mutex_lock(&data->update_lock);
877 old = it87_read_value(data, IT87_REG_FAN_DIV);
879 /* Save fan min limit */
880 min = FAN_FROM_REG(data->fan[nr][1], DIV_FROM_REG(data->fan_div[nr]));
885 data->fan_div[nr] = DIV_TO_REG(val);
889 data->fan_div[nr] = 1;
891 data->fan_div[nr] = 3;
894 val |= (data->fan_div[0] & 0x07);
895 val |= (data->fan_div[1] & 0x07) << 3;
896 if (data->fan_div[2] == 3)
898 it87_write_value(data, IT87_REG_FAN_DIV, val);
900 /* Restore fan min limit */
901 data->fan[nr][1] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
902 it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan[nr][1]);
904 mutex_unlock(&data->update_lock);
908 /* Returns 0 if OK, -EINVAL otherwise */
909 static int check_trip_points(struct device *dev, int nr)
911 const struct it87_data *data = dev_get_drvdata(dev);
914 if (has_old_autopwm(data)) {
915 for (i = 0; i < 3; i++) {
916 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1])
919 for (i = 0; i < 2; i++) {
920 if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1])
927 "Inconsistent trip points, not switching to automatic mode\n");
928 dev_err(dev, "Adjust the trip points and try again\n");
933 static ssize_t set_pwm_enable(struct device *dev,
934 struct device_attribute *attr, const char *buf, size_t count)
936 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
937 int nr = sensor_attr->index;
939 struct it87_data *data = dev_get_drvdata(dev);
942 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 2)
945 /* Check trip points before switching to automatic mode */
947 if (check_trip_points(dev, nr) < 0)
951 /* IT8603E does not have on/off mode */
952 if (val == 0 && data->type == it8603)
955 mutex_lock(&data->update_lock);
959 /* make sure the fan is on when in on/off mode */
960 tmp = it87_read_value(data, IT87_REG_FAN_CTL);
961 it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr));
962 /* set on/off mode */
963 data->fan_main_ctrl &= ~(1 << nr);
964 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
965 data->fan_main_ctrl);
967 if (val == 1) /* Manual mode */
968 data->pwm_ctrl[nr] = has_newer_autopwm(data) ?
969 data->pwm_temp_map[nr] :
971 else /* Automatic mode */
972 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
973 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
975 if (data->type != it8603) {
976 /* set SmartGuardian mode */
977 data->fan_main_ctrl |= (1 << nr);
978 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
979 data->fan_main_ctrl);
983 mutex_unlock(&data->update_lock);
986 static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
987 const char *buf, size_t count)
989 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
990 int nr = sensor_attr->index;
992 struct it87_data *data = dev_get_drvdata(dev);
995 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
998 mutex_lock(&data->update_lock);
999 if (has_newer_autopwm(data)) {
1001 * If we are in automatic mode, the PWM duty cycle register
1002 * is read-only so we can't write the value.
1004 if (data->pwm_ctrl[nr] & 0x80) {
1005 mutex_unlock(&data->update_lock);
1008 data->pwm_duty[nr] = pwm_to_reg(data, val);
1009 it87_write_value(data, IT87_REG_PWM_DUTY(nr),
1010 data->pwm_duty[nr]);
1012 data->pwm_duty[nr] = pwm_to_reg(data, val);
1014 * If we are in manual mode, write the duty cycle immediately;
1015 * otherwise, just store it for later use.
1017 if (!(data->pwm_ctrl[nr] & 0x80)) {
1018 data->pwm_ctrl[nr] = data->pwm_duty[nr];
1019 it87_write_value(data, IT87_REG_PWM(nr),
1020 data->pwm_ctrl[nr]);
1023 mutex_unlock(&data->update_lock);
1026 static ssize_t set_pwm_freq(struct device *dev,
1027 struct device_attribute *attr, const char *buf, size_t count)
1029 struct it87_data *data = dev_get_drvdata(dev);
1033 if (kstrtoul(buf, 10, &val) < 0)
1036 /* Search for the nearest available frequency */
1037 for (i = 0; i < 7; i++) {
1038 if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2)
1042 mutex_lock(&data->update_lock);
1043 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f;
1044 data->fan_ctl |= i << 4;
1045 it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl);
1046 mutex_unlock(&data->update_lock);
1050 static ssize_t show_pwm_temp_map(struct device *dev,
1051 struct device_attribute *attr, char *buf)
1053 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1054 int nr = sensor_attr->index;
1056 struct it87_data *data = it87_update_device(dev);
1059 if (data->pwm_temp_map[nr] < 3)
1060 map = 1 << data->pwm_temp_map[nr];
1062 map = 0; /* Should never happen */
1063 return sprintf(buf, "%d\n", map);
1065 static ssize_t set_pwm_temp_map(struct device *dev,
1066 struct device_attribute *attr, const char *buf, size_t count)
1068 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1069 int nr = sensor_attr->index;
1071 struct it87_data *data = dev_get_drvdata(dev);
1076 * This check can go away if we ever support automatic fan speed
1077 * control on newer chips.
1079 if (!has_old_autopwm(data)) {
1080 dev_notice(dev, "Mapping change disabled for safety reasons\n");
1084 if (kstrtol(buf, 10, &val) < 0)
1101 mutex_lock(&data->update_lock);
1102 data->pwm_temp_map[nr] = reg;
1104 * If we are in automatic mode, write the temp mapping immediately;
1105 * otherwise, just store it for later use.
1107 if (data->pwm_ctrl[nr] & 0x80) {
1108 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
1109 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
1111 mutex_unlock(&data->update_lock);
1115 static ssize_t show_auto_pwm(struct device *dev,
1116 struct device_attribute *attr, char *buf)
1118 struct it87_data *data = it87_update_device(dev);
1119 struct sensor_device_attribute_2 *sensor_attr =
1120 to_sensor_dev_attr_2(attr);
1121 int nr = sensor_attr->nr;
1122 int point = sensor_attr->index;
1124 return sprintf(buf, "%d\n",
1125 pwm_from_reg(data, data->auto_pwm[nr][point]));
1128 static ssize_t set_auto_pwm(struct device *dev,
1129 struct device_attribute *attr, const char *buf, size_t count)
1131 struct it87_data *data = dev_get_drvdata(dev);
1132 struct sensor_device_attribute_2 *sensor_attr =
1133 to_sensor_dev_attr_2(attr);
1134 int nr = sensor_attr->nr;
1135 int point = sensor_attr->index;
1138 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
1141 mutex_lock(&data->update_lock);
1142 data->auto_pwm[nr][point] = pwm_to_reg(data, val);
1143 it87_write_value(data, IT87_REG_AUTO_PWM(nr, point),
1144 data->auto_pwm[nr][point]);
1145 mutex_unlock(&data->update_lock);
1149 static ssize_t show_auto_temp(struct device *dev,
1150 struct device_attribute *attr, char *buf)
1152 struct it87_data *data = it87_update_device(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;
1158 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->auto_temp[nr][point]));
1161 static ssize_t set_auto_temp(struct device *dev,
1162 struct device_attribute *attr, const char *buf, size_t count)
1164 struct it87_data *data = dev_get_drvdata(dev);
1165 struct sensor_device_attribute_2 *sensor_attr =
1166 to_sensor_dev_attr_2(attr);
1167 int nr = sensor_attr->nr;
1168 int point = sensor_attr->index;
1171 if (kstrtol(buf, 10, &val) < 0 || val < -128000 || val > 127000)
1174 mutex_lock(&data->update_lock);
1175 data->auto_temp[nr][point] = TEMP_TO_REG(val);
1176 it87_write_value(data, IT87_REG_AUTO_TEMP(nr, point),
1177 data->auto_temp[nr][point]);
1178 mutex_unlock(&data->update_lock);
1182 static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0);
1183 static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1185 static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, show_fan_div,
1188 static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 1, 0);
1189 static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1191 static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, show_fan_div,
1194 static SENSOR_DEVICE_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 2, 0);
1195 static SENSOR_DEVICE_ATTR_2(fan3_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1197 static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO | S_IWUSR, show_fan_div,
1200 static SENSOR_DEVICE_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 3, 0);
1201 static SENSOR_DEVICE_ATTR_2(fan4_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1204 static SENSOR_DEVICE_ATTR_2(fan5_input, S_IRUGO, show_fan, NULL, 4, 0);
1205 static SENSOR_DEVICE_ATTR_2(fan5_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1208 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
1209 show_pwm_enable, set_pwm_enable, 0);
1210 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0);
1211 static DEVICE_ATTR(pwm1_freq, S_IRUGO | S_IWUSR, show_pwm_freq, set_pwm_freq);
1212 static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IRUGO | S_IWUSR,
1213 show_pwm_temp_map, set_pwm_temp_map, 0);
1214 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR,
1215 show_auto_pwm, set_auto_pwm, 0, 0);
1216 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR,
1217 show_auto_pwm, set_auto_pwm, 0, 1);
1218 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR,
1219 show_auto_pwm, set_auto_pwm, 0, 2);
1220 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO,
1221 show_auto_pwm, NULL, 0, 3);
1222 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR,
1223 show_auto_temp, set_auto_temp, 0, 1);
1224 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1225 show_auto_temp, set_auto_temp, 0, 0);
1226 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR,
1227 show_auto_temp, set_auto_temp, 0, 2);
1228 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR,
1229 show_auto_temp, set_auto_temp, 0, 3);
1230 static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR,
1231 show_auto_temp, set_auto_temp, 0, 4);
1233 static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR,
1234 show_pwm_enable, set_pwm_enable, 1);
1235 static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 1);
1236 static DEVICE_ATTR(pwm2_freq, S_IRUGO, show_pwm_freq, NULL);
1237 static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IRUGO | S_IWUSR,
1238 show_pwm_temp_map, set_pwm_temp_map, 1);
1239 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR,
1240 show_auto_pwm, set_auto_pwm, 1, 0);
1241 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO | S_IWUSR,
1242 show_auto_pwm, set_auto_pwm, 1, 1);
1243 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO | S_IWUSR,
1244 show_auto_pwm, set_auto_pwm, 1, 2);
1245 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO,
1246 show_auto_pwm, NULL, 1, 3);
1247 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR,
1248 show_auto_temp, set_auto_temp, 1, 1);
1249 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1250 show_auto_temp, set_auto_temp, 1, 0);
1251 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR,
1252 show_auto_temp, set_auto_temp, 1, 2);
1253 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR,
1254 show_auto_temp, set_auto_temp, 1, 3);
1255 static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_temp, S_IRUGO | S_IWUSR,
1256 show_auto_temp, set_auto_temp, 1, 4);
1258 static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR,
1259 show_pwm_enable, set_pwm_enable, 2);
1260 static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 2);
1261 static DEVICE_ATTR(pwm3_freq, S_IRUGO, show_pwm_freq, NULL);
1262 static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IRUGO | S_IWUSR,
1263 show_pwm_temp_map, set_pwm_temp_map, 2);
1264 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO | S_IWUSR,
1265 show_auto_pwm, set_auto_pwm, 2, 0);
1266 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR,
1267 show_auto_pwm, set_auto_pwm, 2, 1);
1268 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO | S_IWUSR,
1269 show_auto_pwm, set_auto_pwm, 2, 2);
1270 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO,
1271 show_auto_pwm, NULL, 2, 3);
1272 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp, S_IRUGO | S_IWUSR,
1273 show_auto_temp, set_auto_temp, 2, 1);
1274 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1275 show_auto_temp, set_auto_temp, 2, 0);
1276 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_temp, S_IRUGO | S_IWUSR,
1277 show_auto_temp, set_auto_temp, 2, 2);
1278 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_temp, S_IRUGO | S_IWUSR,
1279 show_auto_temp, set_auto_temp, 2, 3);
1280 static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_temp, S_IRUGO | S_IWUSR,
1281 show_auto_temp, set_auto_temp, 2, 4);
1284 static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
1287 struct it87_data *data = it87_update_device(dev);
1288 return sprintf(buf, "%u\n", data->alarms);
1290 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
1292 static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
1295 int bitnr = to_sensor_dev_attr(attr)->index;
1296 struct it87_data *data = it87_update_device(dev);
1297 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
1300 static ssize_t clear_intrusion(struct device *dev, struct device_attribute
1301 *attr, const char *buf, size_t count)
1303 struct it87_data *data = dev_get_drvdata(dev);
1307 if (kstrtol(buf, 10, &val) < 0 || val != 0)
1310 mutex_lock(&data->update_lock);
1311 config = it87_read_value(data, IT87_REG_CONFIG);
1316 it87_write_value(data, IT87_REG_CONFIG, config);
1317 /* Invalidate cache to force re-read */
1320 mutex_unlock(&data->update_lock);
1325 static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8);
1326 static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9);
1327 static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10);
1328 static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11);
1329 static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12);
1330 static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13);
1331 static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14);
1332 static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15);
1333 static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0);
1334 static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1);
1335 static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2);
1336 static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3);
1337 static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6);
1338 static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16);
1339 static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17);
1340 static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18);
1341 static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR,
1342 show_alarm, clear_intrusion, 4);
1344 static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
1347 int bitnr = to_sensor_dev_attr(attr)->index;
1348 struct it87_data *data = it87_update_device(dev);
1349 return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1);
1351 static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
1352 const char *buf, size_t count)
1354 int bitnr = to_sensor_dev_attr(attr)->index;
1355 struct it87_data *data = dev_get_drvdata(dev);
1358 if (kstrtol(buf, 10, &val) < 0
1359 || (val != 0 && val != 1))
1362 mutex_lock(&data->update_lock);
1363 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
1365 data->beeps |= (1 << bitnr);
1367 data->beeps &= ~(1 << bitnr);
1368 it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps);
1369 mutex_unlock(&data->update_lock);
1373 static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
1374 show_beep, set_beep, 1);
1375 static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO, show_beep, NULL, 1);
1376 static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO, show_beep, NULL, 1);
1377 static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO, show_beep, NULL, 1);
1378 static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO, show_beep, NULL, 1);
1379 static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO, show_beep, NULL, 1);
1380 static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO, show_beep, NULL, 1);
1381 static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO, show_beep, NULL, 1);
1382 /* fanX_beep writability is set later */
1383 static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO, show_beep, set_beep, 0);
1384 static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0);
1385 static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0);
1386 static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0);
1387 static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0);
1388 static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
1389 show_beep, set_beep, 2);
1390 static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2);
1391 static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2);
1393 static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
1396 struct it87_data *data = dev_get_drvdata(dev);
1397 return sprintf(buf, "%u\n", data->vrm);
1399 static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
1400 const char *buf, size_t count)
1402 struct it87_data *data = dev_get_drvdata(dev);
1405 if (kstrtoul(buf, 10, &val) < 0)
1412 static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
1414 static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
1417 struct it87_data *data = it87_update_device(dev);
1418 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
1420 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
1422 static ssize_t show_label(struct device *dev, struct device_attribute *attr,
1425 static const char * const labels[] = {
1430 static const char * const labels_it8721[] = {
1435 struct it87_data *data = dev_get_drvdata(dev);
1436 int nr = to_sensor_dev_attr(attr)->index;
1438 return sprintf(buf, "%s\n", has_12mv_adc(data) ? labels_it8721[nr]
1441 static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0);
1442 static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1);
1443 static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 2);
1444 /* special AVCC3 IT8603E in9 */
1445 static SENSOR_DEVICE_ATTR(in9_label, S_IRUGO, show_label, NULL, 0);
1447 static ssize_t show_name(struct device *dev, struct device_attribute
1448 *devattr, char *buf)
1450 struct it87_data *data = dev_get_drvdata(dev);
1451 return sprintf(buf, "%s\n", data->name);
1453 static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
1455 static struct attribute *it87_attributes_in[10][5] = {
1457 &sensor_dev_attr_in0_input.dev_attr.attr,
1458 &sensor_dev_attr_in0_min.dev_attr.attr,
1459 &sensor_dev_attr_in0_max.dev_attr.attr,
1460 &sensor_dev_attr_in0_alarm.dev_attr.attr,
1463 &sensor_dev_attr_in1_input.dev_attr.attr,
1464 &sensor_dev_attr_in1_min.dev_attr.attr,
1465 &sensor_dev_attr_in1_max.dev_attr.attr,
1466 &sensor_dev_attr_in1_alarm.dev_attr.attr,
1469 &sensor_dev_attr_in2_input.dev_attr.attr,
1470 &sensor_dev_attr_in2_min.dev_attr.attr,
1471 &sensor_dev_attr_in2_max.dev_attr.attr,
1472 &sensor_dev_attr_in2_alarm.dev_attr.attr,
1475 &sensor_dev_attr_in3_input.dev_attr.attr,
1476 &sensor_dev_attr_in3_min.dev_attr.attr,
1477 &sensor_dev_attr_in3_max.dev_attr.attr,
1478 &sensor_dev_attr_in3_alarm.dev_attr.attr,
1481 &sensor_dev_attr_in4_input.dev_attr.attr,
1482 &sensor_dev_attr_in4_min.dev_attr.attr,
1483 &sensor_dev_attr_in4_max.dev_attr.attr,
1484 &sensor_dev_attr_in4_alarm.dev_attr.attr,
1487 &sensor_dev_attr_in5_input.dev_attr.attr,
1488 &sensor_dev_attr_in5_min.dev_attr.attr,
1489 &sensor_dev_attr_in5_max.dev_attr.attr,
1490 &sensor_dev_attr_in5_alarm.dev_attr.attr,
1493 &sensor_dev_attr_in6_input.dev_attr.attr,
1494 &sensor_dev_attr_in6_min.dev_attr.attr,
1495 &sensor_dev_attr_in6_max.dev_attr.attr,
1496 &sensor_dev_attr_in6_alarm.dev_attr.attr,
1499 &sensor_dev_attr_in7_input.dev_attr.attr,
1500 &sensor_dev_attr_in7_min.dev_attr.attr,
1501 &sensor_dev_attr_in7_max.dev_attr.attr,
1502 &sensor_dev_attr_in7_alarm.dev_attr.attr,
1505 &sensor_dev_attr_in8_input.dev_attr.attr,
1508 &sensor_dev_attr_in9_input.dev_attr.attr,
1512 static const struct attribute_group it87_group_in[10] = {
1513 { .attrs = it87_attributes_in[0] },
1514 { .attrs = it87_attributes_in[1] },
1515 { .attrs = it87_attributes_in[2] },
1516 { .attrs = it87_attributes_in[3] },
1517 { .attrs = it87_attributes_in[4] },
1518 { .attrs = it87_attributes_in[5] },
1519 { .attrs = it87_attributes_in[6] },
1520 { .attrs = it87_attributes_in[7] },
1521 { .attrs = it87_attributes_in[8] },
1522 { .attrs = it87_attributes_in[9] },
1525 static struct attribute *it87_attributes_temp[3][6] = {
1527 &sensor_dev_attr_temp1_input.dev_attr.attr,
1528 &sensor_dev_attr_temp1_max.dev_attr.attr,
1529 &sensor_dev_attr_temp1_min.dev_attr.attr,
1530 &sensor_dev_attr_temp1_type.dev_attr.attr,
1531 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
1534 &sensor_dev_attr_temp2_input.dev_attr.attr,
1535 &sensor_dev_attr_temp2_max.dev_attr.attr,
1536 &sensor_dev_attr_temp2_min.dev_attr.attr,
1537 &sensor_dev_attr_temp2_type.dev_attr.attr,
1538 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
1541 &sensor_dev_attr_temp3_input.dev_attr.attr,
1542 &sensor_dev_attr_temp3_max.dev_attr.attr,
1543 &sensor_dev_attr_temp3_min.dev_attr.attr,
1544 &sensor_dev_attr_temp3_type.dev_attr.attr,
1545 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
1549 static const struct attribute_group it87_group_temp[3] = {
1550 { .attrs = it87_attributes_temp[0] },
1551 { .attrs = it87_attributes_temp[1] },
1552 { .attrs = it87_attributes_temp[2] },
1555 static struct attribute *it87_attributes_temp_offset[] = {
1556 &sensor_dev_attr_temp1_offset.dev_attr.attr,
1557 &sensor_dev_attr_temp2_offset.dev_attr.attr,
1558 &sensor_dev_attr_temp3_offset.dev_attr.attr,
1561 static struct attribute *it87_attributes[] = {
1562 &dev_attr_alarms.attr,
1563 &sensor_dev_attr_intrusion0_alarm.dev_attr.attr,
1564 &dev_attr_name.attr,
1568 static const struct attribute_group it87_group = {
1569 .attrs = it87_attributes,
1572 static struct attribute *it87_attributes_in_beep[] = {
1573 &sensor_dev_attr_in0_beep.dev_attr.attr,
1574 &sensor_dev_attr_in1_beep.dev_attr.attr,
1575 &sensor_dev_attr_in2_beep.dev_attr.attr,
1576 &sensor_dev_attr_in3_beep.dev_attr.attr,
1577 &sensor_dev_attr_in4_beep.dev_attr.attr,
1578 &sensor_dev_attr_in5_beep.dev_attr.attr,
1579 &sensor_dev_attr_in6_beep.dev_attr.attr,
1580 &sensor_dev_attr_in7_beep.dev_attr.attr,
1585 static struct attribute *it87_attributes_temp_beep[] = {
1586 &sensor_dev_attr_temp1_beep.dev_attr.attr,
1587 &sensor_dev_attr_temp2_beep.dev_attr.attr,
1588 &sensor_dev_attr_temp3_beep.dev_attr.attr,
1591 static struct attribute *it87_attributes_fan[5][3+1] = { {
1592 &sensor_dev_attr_fan1_input.dev_attr.attr,
1593 &sensor_dev_attr_fan1_min.dev_attr.attr,
1594 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1597 &sensor_dev_attr_fan2_input.dev_attr.attr,
1598 &sensor_dev_attr_fan2_min.dev_attr.attr,
1599 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1602 &sensor_dev_attr_fan3_input.dev_attr.attr,
1603 &sensor_dev_attr_fan3_min.dev_attr.attr,
1604 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
1607 &sensor_dev_attr_fan4_input.dev_attr.attr,
1608 &sensor_dev_attr_fan4_min.dev_attr.attr,
1609 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
1612 &sensor_dev_attr_fan5_input.dev_attr.attr,
1613 &sensor_dev_attr_fan5_min.dev_attr.attr,
1614 &sensor_dev_attr_fan5_alarm.dev_attr.attr,
1618 static const struct attribute_group it87_group_fan[5] = {
1619 { .attrs = it87_attributes_fan[0] },
1620 { .attrs = it87_attributes_fan[1] },
1621 { .attrs = it87_attributes_fan[2] },
1622 { .attrs = it87_attributes_fan[3] },
1623 { .attrs = it87_attributes_fan[4] },
1626 static const struct attribute *it87_attributes_fan_div[] = {
1627 &sensor_dev_attr_fan1_div.dev_attr.attr,
1628 &sensor_dev_attr_fan2_div.dev_attr.attr,
1629 &sensor_dev_attr_fan3_div.dev_attr.attr,
1632 static struct attribute *it87_attributes_pwm[3][4+1] = { {
1633 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
1634 &sensor_dev_attr_pwm1.dev_attr.attr,
1635 &dev_attr_pwm1_freq.attr,
1636 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
1639 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1640 &sensor_dev_attr_pwm2.dev_attr.attr,
1641 &dev_attr_pwm2_freq.attr,
1642 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
1645 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
1646 &sensor_dev_attr_pwm3.dev_attr.attr,
1647 &dev_attr_pwm3_freq.attr,
1648 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
1652 static const struct attribute_group it87_group_pwm[3] = {
1653 { .attrs = it87_attributes_pwm[0] },
1654 { .attrs = it87_attributes_pwm[1] },
1655 { .attrs = it87_attributes_pwm[2] },
1658 static struct attribute *it87_attributes_autopwm[3][9+1] = { {
1659 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
1660 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
1661 &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr,
1662 &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr,
1663 &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
1664 &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr,
1665 &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr,
1666 &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr,
1667 &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr,
1670 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
1671 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
1672 &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr,
1673 &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr,
1674 &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr,
1675 &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr,
1676 &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr,
1677 &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr,
1678 &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr,
1681 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
1682 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
1683 &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr,
1684 &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr,
1685 &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr,
1686 &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr,
1687 &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr,
1688 &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr,
1689 &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr,
1693 static const struct attribute_group it87_group_autopwm[3] = {
1694 { .attrs = it87_attributes_autopwm[0] },
1695 { .attrs = it87_attributes_autopwm[1] },
1696 { .attrs = it87_attributes_autopwm[2] },
1699 static struct attribute *it87_attributes_fan_beep[] = {
1700 &sensor_dev_attr_fan1_beep.dev_attr.attr,
1701 &sensor_dev_attr_fan2_beep.dev_attr.attr,
1702 &sensor_dev_attr_fan3_beep.dev_attr.attr,
1703 &sensor_dev_attr_fan4_beep.dev_attr.attr,
1704 &sensor_dev_attr_fan5_beep.dev_attr.attr,
1707 static struct attribute *it87_attributes_vid[] = {
1709 &dev_attr_cpu0_vid.attr,
1713 static const struct attribute_group it87_group_vid = {
1714 .attrs = it87_attributes_vid,
1717 static struct attribute *it87_attributes_label[] = {
1718 &sensor_dev_attr_in3_label.dev_attr.attr,
1719 &sensor_dev_attr_in7_label.dev_attr.attr,
1720 &sensor_dev_attr_in8_label.dev_attr.attr,
1721 &sensor_dev_attr_in9_label.dev_attr.attr,
1725 static const struct attribute_group it87_group_label = {
1726 .attrs = it87_attributes_label,
1729 /* SuperIO detection - will change isa_address if a chip is found */
1730 static int __init it87_find(unsigned short *address,
1731 struct it87_sio_data *sio_data)
1735 const char *board_vendor, *board_name;
1737 err = superio_enter();
1742 chip_type = force_id ? force_id : superio_inw(DEVID);
1744 switch (chip_type) {
1746 sio_data->type = it87;
1749 sio_data->type = it8712;
1753 sio_data->type = it8716;
1756 sio_data->type = it8718;
1759 sio_data->type = it8720;
1762 sio_data->type = it8721;
1765 sio_data->type = it8728;
1768 sio_data->type = it8771;
1771 sio_data->type = it8772;
1774 sio_data->type = it8781;
1777 sio_data->type = it8782;
1780 sio_data->type = it8783;
1784 sio_data->type = it8603;
1786 case 0xffff: /* No device at all */
1789 pr_debug("Unsupported chip (DEVID=0x%x)\n", chip_type);
1793 superio_select(PME);
1794 if (!(superio_inb(IT87_ACT_REG) & 0x01)) {
1795 pr_info("Device not activated, skipping\n");
1799 *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1);
1800 if (*address == 0) {
1801 pr_info("Base address not set, skipping\n");
1806 sio_data->revision = superio_inb(DEVREV) & 0x0f;
1807 pr_info("Found IT%04x%c chip at 0x%x, revision %d\n", chip_type,
1808 chip_type == 0x8771 || chip_type == 0x8772 ||
1809 chip_type == 0x8603 ? 'E' : 'F', *address,
1810 sio_data->revision);
1812 /* in8 (Vbat) is always internal */
1813 sio_data->internal = (1 << 2);
1814 /* Only the IT8603E has in9 */
1815 if (sio_data->type != it8603)
1816 sio_data->skip_in |= (1 << 9);
1818 /* Read GPIO config and VID value from LDN 7 (GPIO) */
1819 if (sio_data->type == it87) {
1820 /* The IT8705F doesn't have VID pins at all */
1821 sio_data->skip_vid = 1;
1823 /* The IT8705F has a different LD number for GPIO */
1825 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
1826 } else if (sio_data->type == it8783) {
1827 int reg25, reg27, reg2a, reg2c, regef;
1829 sio_data->skip_vid = 1; /* No VID */
1831 superio_select(GPIO);
1833 reg25 = superio_inb(IT87_SIO_GPIO1_REG);
1834 reg27 = superio_inb(IT87_SIO_GPIO3_REG);
1835 reg2a = superio_inb(IT87_SIO_PINX1_REG);
1836 reg2c = superio_inb(IT87_SIO_PINX2_REG);
1837 regef = superio_inb(IT87_SIO_SPI_REG);
1839 /* Check if fan3 is there or not */
1840 if ((reg27 & (1 << 0)) || !(reg2c & (1 << 2)))
1841 sio_data->skip_fan |= (1 << 2);
1842 if ((reg25 & (1 << 4))
1843 || (!(reg2a & (1 << 1)) && (regef & (1 << 0))))
1844 sio_data->skip_pwm |= (1 << 2);
1846 /* Check if fan2 is there or not */
1847 if (reg27 & (1 << 7))
1848 sio_data->skip_fan |= (1 << 1);
1849 if (reg27 & (1 << 3))
1850 sio_data->skip_pwm |= (1 << 1);
1853 if ((reg27 & (1 << 0)) || (reg2c & (1 << 2)))
1854 sio_data->skip_in |= (1 << 5); /* No VIN5 */
1857 if (reg27 & (1 << 1))
1858 sio_data->skip_in |= (1 << 6); /* No VIN6 */
1862 * Does not depend on bit 2 of Reg2C, contrary to datasheet.
1864 if (reg27 & (1 << 2)) {
1866 * The data sheet is a bit unclear regarding the
1867 * internal voltage divider for VCCH5V. It says
1868 * "This bit enables and switches VIN7 (pin 91) to the
1869 * internal voltage divider for VCCH5V".
1870 * This is different to other chips, where the internal
1871 * voltage divider would connect VIN7 to an internal
1872 * voltage source. Maybe that is the case here as well.
1874 * Since we don't know for sure, re-route it if that is
1875 * not the case, and ask the user to report if the
1876 * resulting voltage is sane.
1878 if (!(reg2c & (1 << 1))) {
1880 superio_outb(IT87_SIO_PINX2_REG, reg2c);
1881 pr_notice("Routing internal VCCH5V to in7.\n");
1883 pr_notice("in7 routed to internal voltage divider, with external pin disabled.\n");
1884 pr_notice("Please report if it displays a reasonable voltage.\n");
1887 if (reg2c & (1 << 0))
1888 sio_data->internal |= (1 << 0);
1889 if (reg2c & (1 << 1))
1890 sio_data->internal |= (1 << 1);
1892 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
1893 } else if (sio_data->type == it8603) {
1896 sio_data->skip_vid = 1; /* No VID */
1897 superio_select(GPIO);
1899 reg27 = superio_inb(IT87_SIO_GPIO3_REG);
1901 /* Check if fan3 is there or not */
1902 if (reg27 & (1 << 6))
1903 sio_data->skip_pwm |= (1 << 2);
1904 if (reg27 & (1 << 7))
1905 sio_data->skip_fan |= (1 << 2);
1907 /* Check if fan2 is there or not */
1908 reg29 = superio_inb(IT87_SIO_GPIO5_REG);
1909 if (reg29 & (1 << 1))
1910 sio_data->skip_pwm |= (1 << 1);
1911 if (reg29 & (1 << 2))
1912 sio_data->skip_fan |= (1 << 1);
1914 sio_data->skip_in |= (1 << 5); /* No VIN5 */
1915 sio_data->skip_in |= (1 << 6); /* No VIN6 */
1918 sio_data->skip_pwm |= (1 << 3);
1919 sio_data->skip_fan |= (1 << 3);
1921 sio_data->internal |= (1 << 1); /* in7 is VSB */
1922 sio_data->internal |= (1 << 3); /* in9 is AVCC */
1924 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
1929 superio_select(GPIO);
1931 reg = superio_inb(IT87_SIO_GPIO3_REG);
1932 if (sio_data->type == it8721 || sio_data->type == it8728 ||
1933 sio_data->type == it8771 || sio_data->type == it8772 ||
1934 sio_data->type == it8781 || sio_data->type == it8782) {
1936 * IT8721F/IT8758E, IT8728F, IT8772F, IT8781F, and
1937 * IT8782F don't have VID pins at all, not sure about
1940 sio_data->skip_vid = 1;
1942 /* We need at least 4 VID pins */
1944 pr_info("VID is disabled (pins used for GPIO)\n");
1945 sio_data->skip_vid = 1;
1949 /* Check if fan3 is there or not */
1951 sio_data->skip_pwm |= (1 << 2);
1953 sio_data->skip_fan |= (1 << 2);
1955 /* Check if fan2 is there or not */
1956 reg = superio_inb(IT87_SIO_GPIO5_REG);
1958 sio_data->skip_pwm |= (1 << 1);
1960 sio_data->skip_fan |= (1 << 1);
1962 if ((sio_data->type == it8718 || sio_data->type == it8720)
1963 && !(sio_data->skip_vid))
1964 sio_data->vid_value = superio_inb(IT87_SIO_VID_REG);
1966 reg = superio_inb(IT87_SIO_PINX2_REG);
1968 uart6 = sio_data->type == it8782 && (reg & (1 << 2));
1971 * The IT8720F has no VIN7 pin, so VCCH should always be
1972 * routed internally to VIN7 with an internal divider.
1973 * Curiously, there still is a configuration bit to control
1974 * this, which means it can be set incorrectly. And even
1975 * more curiously, many boards out there are improperly
1976 * configured, even though the IT8720F datasheet claims
1977 * that the internal routing of VCCH to VIN7 is the default
1978 * setting. So we force the internal routing in this case.
1980 * On IT8782F, VIN7 is multiplexed with one of the UART6 pins.
1981 * If UART6 is enabled, re-route VIN7 to the internal divider
1982 * if that is not already the case.
1984 if ((sio_data->type == it8720 || uart6) && !(reg & (1 << 1))) {
1986 superio_outb(IT87_SIO_PINX2_REG, reg);
1987 pr_notice("Routing internal VCCH to in7\n");
1990 sio_data->internal |= (1 << 0);
1991 if ((reg & (1 << 1)) || sio_data->type == it8721 ||
1992 sio_data->type == it8728 ||
1993 sio_data->type == it8771 ||
1994 sio_data->type == it8772)
1995 sio_data->internal |= (1 << 1);
1998 * On IT8782F, UART6 pins overlap with VIN5, VIN6, and VIN7.
1999 * While VIN7 can be routed to the internal voltage divider,
2000 * VIN5 and VIN6 are not available if UART6 is enabled.
2002 * Also, temp3 is not available if UART6 is enabled and TEMPIN3
2003 * is the temperature source. Since we can not read the
2004 * temperature source here, skip_temp is preliminary.
2007 sio_data->skip_in |= (1 << 5) | (1 << 6);
2008 sio_data->skip_temp |= (1 << 2);
2011 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
2013 if (sio_data->beep_pin)
2014 pr_info("Beeping is supported\n");
2016 /* Disable specific features based on DMI strings */
2017 board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
2018 board_name = dmi_get_system_info(DMI_BOARD_NAME);
2019 if (board_vendor && board_name) {
2020 if (strcmp(board_vendor, "nVIDIA") == 0
2021 && strcmp(board_name, "FN68PT") == 0) {
2023 * On the Shuttle SN68PT, FAN_CTL2 is apparently not
2024 * connected to a fan, but to something else. One user
2025 * has reported instant system power-off when changing
2026 * the PWM2 duty cycle, so we disable it.
2027 * I use the board name string as the trigger in case
2028 * the same board is ever used in other systems.
2030 pr_info("Disabling pwm2 due to hardware constraints\n");
2031 sio_data->skip_pwm = (1 << 1);
2040 static void it87_remove_files(struct device *dev)
2042 struct it87_data *data = platform_get_drvdata(pdev);
2043 struct it87_sio_data *sio_data = dev_get_platdata(dev);
2046 sysfs_remove_group(&dev->kobj, &it87_group);
2047 for (i = 0; i < 10; i++) {
2048 if (sio_data->skip_in & (1 << i))
2050 sysfs_remove_group(&dev->kobj, &it87_group_in[i]);
2051 if (it87_attributes_in_beep[i])
2052 sysfs_remove_file(&dev->kobj,
2053 it87_attributes_in_beep[i]);
2055 for (i = 0; i < 3; i++) {
2056 if (!(data->has_temp & (1 << i)))
2058 sysfs_remove_group(&dev->kobj, &it87_group_temp[i]);
2059 if (has_temp_offset(data))
2060 sysfs_remove_file(&dev->kobj,
2061 it87_attributes_temp_offset[i]);
2062 if (sio_data->beep_pin)
2063 sysfs_remove_file(&dev->kobj,
2064 it87_attributes_temp_beep[i]);
2066 for (i = 0; i < 5; i++) {
2067 if (!(data->has_fan & (1 << i)))
2069 sysfs_remove_group(&dev->kobj, &it87_group_fan[i]);
2070 if (sio_data->beep_pin)
2071 sysfs_remove_file(&dev->kobj,
2072 it87_attributes_fan_beep[i]);
2073 if (i < 3 && !has_16bit_fans(data))
2074 sysfs_remove_file(&dev->kobj,
2075 it87_attributes_fan_div[i]);
2077 for (i = 0; i < 3; i++) {
2078 if (sio_data->skip_pwm & (1 << 0))
2080 sysfs_remove_group(&dev->kobj, &it87_group_pwm[i]);
2081 if (has_old_autopwm(data))
2082 sysfs_remove_group(&dev->kobj,
2083 &it87_group_autopwm[i]);
2085 if (!sio_data->skip_vid)
2086 sysfs_remove_group(&dev->kobj, &it87_group_vid);
2087 sysfs_remove_group(&dev->kobj, &it87_group_label);
2090 static int it87_probe(struct platform_device *pdev)
2092 struct it87_data *data;
2093 struct resource *res;
2094 struct device *dev = &pdev->dev;
2095 struct it87_sio_data *sio_data = dev_get_platdata(dev);
2097 int enable_pwm_interface;
2098 int fan_beep_need_rw;
2100 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
2101 if (!devm_request_region(&pdev->dev, res->start, IT87_EC_EXTENT,
2103 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
2104 (unsigned long)res->start,
2105 (unsigned long)(res->start + IT87_EC_EXTENT - 1));
2109 data = devm_kzalloc(&pdev->dev, sizeof(struct it87_data), GFP_KERNEL);
2113 data->addr = res->start;
2114 data->type = sio_data->type;
2115 data->features = it87_devices[sio_data->type].features;
2116 data->peci_mask = it87_devices[sio_data->type].peci_mask;
2117 data->old_peci_mask = it87_devices[sio_data->type].old_peci_mask;
2118 data->name = it87_devices[sio_data->type].name;
2120 * IT8705F Datasheet 0.4.1, 3h == Version G.
2121 * IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J.
2122 * These are the first revisions with 16-bit tachometer support.
2124 switch (data->type) {
2126 if (sio_data->revision >= 0x03) {
2127 data->features &= ~FEAT_OLD_AUTOPWM;
2128 data->features |= FEAT_16BIT_FANS;
2132 if (sio_data->revision >= 0x08) {
2133 data->features &= ~FEAT_OLD_AUTOPWM;
2134 data->features |= FEAT_16BIT_FANS;
2141 /* Now, we do the remaining detection. */
2142 if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80)
2143 || it87_read_value(data, IT87_REG_CHIPID) != 0x90)
2146 platform_set_drvdata(pdev, data);
2148 mutex_init(&data->update_lock);
2150 /* Check PWM configuration */
2151 enable_pwm_interface = it87_check_pwm(dev);
2153 /* Starting with IT8721F, we handle scaling of internal voltages */
2154 if (has_12mv_adc(data)) {
2155 if (sio_data->internal & (1 << 0))
2156 data->in_scaled |= (1 << 3); /* in3 is AVCC */
2157 if (sio_data->internal & (1 << 1))
2158 data->in_scaled |= (1 << 7); /* in7 is VSB */
2159 if (sio_data->internal & (1 << 2))
2160 data->in_scaled |= (1 << 8); /* in8 is Vbat */
2161 if (sio_data->internal & (1 << 3))
2162 data->in_scaled |= (1 << 9); /* in9 is AVCC */
2163 } else if (sio_data->type == it8781 || sio_data->type == it8782 ||
2164 sio_data->type == it8783) {
2165 if (sio_data->internal & (1 << 0))
2166 data->in_scaled |= (1 << 3); /* in3 is VCC5V */
2167 if (sio_data->internal & (1 << 1))
2168 data->in_scaled |= (1 << 7); /* in7 is VCCH5V */
2171 data->has_temp = 0x07;
2172 if (sio_data->skip_temp & (1 << 2)) {
2173 if (sio_data->type == it8782
2174 && !(it87_read_value(data, IT87_REG_TEMP_EXTRA) & 0x80))
2175 data->has_temp &= ~(1 << 2);
2178 /* Initialize the IT87 chip */
2179 it87_init_device(pdev);
2181 /* Register sysfs hooks */
2182 err = sysfs_create_group(&dev->kobj, &it87_group);
2186 for (i = 0; i < 10; i++) {
2187 if (sio_data->skip_in & (1 << i))
2189 err = sysfs_create_group(&dev->kobj, &it87_group_in[i]);
2192 if (sio_data->beep_pin && it87_attributes_in_beep[i]) {
2193 err = sysfs_create_file(&dev->kobj,
2194 it87_attributes_in_beep[i]);
2200 for (i = 0; i < 3; i++) {
2201 if (!(data->has_temp & (1 << i)))
2203 err = sysfs_create_group(&dev->kobj, &it87_group_temp[i]);
2206 if (has_temp_offset(data)) {
2207 err = sysfs_create_file(&dev->kobj,
2208 it87_attributes_temp_offset[i]);
2212 if (sio_data->beep_pin) {
2213 err = sysfs_create_file(&dev->kobj,
2214 it87_attributes_temp_beep[i]);
2220 /* Do not create fan files for disabled fans */
2221 fan_beep_need_rw = 1;
2222 for (i = 0; i < 5; i++) {
2223 if (!(data->has_fan & (1 << i)))
2225 err = sysfs_create_group(&dev->kobj, &it87_group_fan[i]);
2229 if (i < 3 && !has_16bit_fans(data)) {
2230 err = sysfs_create_file(&dev->kobj,
2231 it87_attributes_fan_div[i]);
2236 if (sio_data->beep_pin) {
2237 err = sysfs_create_file(&dev->kobj,
2238 it87_attributes_fan_beep[i]);
2241 if (!fan_beep_need_rw)
2245 * As we have a single beep enable bit for all fans,
2246 * only the first enabled fan has a writable attribute
2249 if (sysfs_chmod_file(&dev->kobj,
2250 it87_attributes_fan_beep[i],
2252 dev_dbg(dev, "chmod +w fan%d_beep failed\n",
2254 fan_beep_need_rw = 0;
2258 if (enable_pwm_interface) {
2259 for (i = 0; i < 3; i++) {
2260 if (sio_data->skip_pwm & (1 << i))
2262 err = sysfs_create_group(&dev->kobj,
2263 &it87_group_pwm[i]);
2267 if (!has_old_autopwm(data))
2269 err = sysfs_create_group(&dev->kobj,
2270 &it87_group_autopwm[i]);
2276 if (!sio_data->skip_vid) {
2277 data->vrm = vid_which_vrm();
2278 /* VID reading from Super-I/O config space if available */
2279 data->vid = sio_data->vid_value;
2280 err = sysfs_create_group(&dev->kobj, &it87_group_vid);
2285 /* Export labels for internal sensors */
2286 for (i = 0; i < 4; i++) {
2287 if (!(sio_data->internal & (1 << i)))
2289 err = sysfs_create_file(&dev->kobj,
2290 it87_attributes_label[i]);
2295 data->hwmon_dev = hwmon_device_register(dev);
2296 if (IS_ERR(data->hwmon_dev)) {
2297 err = PTR_ERR(data->hwmon_dev);
2304 it87_remove_files(dev);
2308 static int it87_remove(struct platform_device *pdev)
2310 struct it87_data *data = platform_get_drvdata(pdev);
2312 hwmon_device_unregister(data->hwmon_dev);
2313 it87_remove_files(&pdev->dev);
2319 * Must be called with data->update_lock held, except during initialization.
2320 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
2321 * would slow down the IT87 access and should not be necessary.
2323 static int it87_read_value(struct it87_data *data, u8 reg)
2325 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
2326 return inb_p(data->addr + IT87_DATA_REG_OFFSET);
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 void it87_write_value(struct it87_data *data, u8 reg, u8 value)
2336 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
2337 outb_p(value, data->addr + IT87_DATA_REG_OFFSET);
2340 /* Return 1 if and only if the PWM interface is safe to use */
2341 static int it87_check_pwm(struct device *dev)
2343 struct it87_data *data = dev_get_drvdata(dev);
2345 * Some BIOSes fail to correctly configure the IT87 fans. All fans off
2346 * and polarity set to active low is sign that this is the case so we
2347 * disable pwm control to protect the user.
2349 int tmp = it87_read_value(data, IT87_REG_FAN_CTL);
2350 if ((tmp & 0x87) == 0) {
2351 if (fix_pwm_polarity) {
2353 * The user asks us to attempt a chip reconfiguration.
2354 * This means switching to active high polarity and
2355 * inverting all fan speed values.
2360 for (i = 0; i < 3; i++)
2361 pwm[i] = it87_read_value(data,
2365 * If any fan is in automatic pwm mode, the polarity
2366 * might be correct, as suspicious as it seems, so we
2367 * better don't change anything (but still disable the
2370 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
2372 "Reconfiguring PWM to active high polarity\n");
2373 it87_write_value(data, IT87_REG_FAN_CTL,
2375 for (i = 0; i < 3; i++)
2376 it87_write_value(data,
2383 "PWM configuration is too broken to be fixed\n");
2387 "Detected broken BIOS defaults, disabling PWM interface\n");
2389 } else if (fix_pwm_polarity) {
2391 "PWM configuration looks sane, won't touch\n");
2397 /* Called when we have found a new IT87. */
2398 static void it87_init_device(struct platform_device *pdev)
2400 struct it87_sio_data *sio_data = dev_get_platdata(&pdev->dev);
2401 struct it87_data *data = platform_get_drvdata(pdev);
2406 * For each PWM channel:
2407 * - If it is in automatic mode, setting to manual mode should set
2408 * the fan to full speed by default.
2409 * - If it is in manual mode, we need a mapping to temperature
2410 * channels to use when later setting to automatic mode later.
2411 * Use a 1:1 mapping by default (we are clueless.)
2412 * In both cases, the value can (and should) be changed by the user
2413 * prior to switching to a different mode.
2414 * Note that this is no longer needed for the IT8721F and later, as
2415 * these have separate registers for the temperature mapping and the
2416 * manual duty cycle.
2418 for (i = 0; i < 3; i++) {
2419 data->pwm_temp_map[i] = i;
2420 data->pwm_duty[i] = 0x7f; /* Full speed */
2421 data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */
2425 * Some chips seem to have default value 0xff for all limit
2426 * registers. For low voltage limits it makes no sense and triggers
2427 * alarms, so change to 0 instead. For high temperature limits, it
2428 * means -1 degree C, which surprisingly doesn't trigger an alarm,
2429 * but is still confusing, so change to 127 degrees C.
2431 for (i = 0; i < 8; i++) {
2432 tmp = it87_read_value(data, IT87_REG_VIN_MIN(i));
2434 it87_write_value(data, IT87_REG_VIN_MIN(i), 0);
2436 for (i = 0; i < 3; i++) {
2437 tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i));
2439 it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127);
2443 * Temperature channels are not forcibly enabled, as they can be
2444 * set to two different sensor types and we can't guess which one
2445 * is correct for a given system. These channels can be enabled at
2446 * run-time through the temp{1-3}_type sysfs accessors if needed.
2449 /* Check if voltage monitors are reset manually or by some reason */
2450 tmp = it87_read_value(data, IT87_REG_VIN_ENABLE);
2451 if ((tmp & 0xff) == 0) {
2452 /* Enable all voltage monitors */
2453 it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff);
2456 /* Check if tachometers are reset manually or by some reason */
2457 mask = 0x70 & ~(sio_data->skip_fan << 4);
2458 data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL);
2459 if ((data->fan_main_ctrl & mask) == 0) {
2460 /* Enable all fan tachometers */
2461 data->fan_main_ctrl |= mask;
2462 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
2463 data->fan_main_ctrl);
2465 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
2467 /* Set tachometers to 16-bit mode if needed, IT8603E (and IT8728F?)
2468 * has it by default */
2469 if (has_16bit_fans(data) && data->type != it8603) {
2470 tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
2471 if (~tmp & 0x07 & data->has_fan) {
2473 "Setting fan1-3 to 16-bit mode\n");
2474 it87_write_value(data, IT87_REG_FAN_16BIT,
2478 * IT8705F, IT8781F, IT8782F, and IT8783E/F only support
2481 if (data->type != it87 && data->type != it8781 &&
2482 data->type != it8782 && data->type != it8783) {
2484 data->has_fan |= (1 << 3); /* fan4 enabled */
2486 data->has_fan |= (1 << 4); /* fan5 enabled */
2490 /* Fan input pins may be used for alternative functions */
2491 data->has_fan &= ~sio_data->skip_fan;
2493 /* Start monitoring */
2494 it87_write_value(data, IT87_REG_CONFIG,
2495 (it87_read_value(data, IT87_REG_CONFIG) & 0x3e)
2496 | (update_vbat ? 0x41 : 0x01));
2499 static void it87_update_pwm_ctrl(struct it87_data *data, int nr)
2501 data->pwm_ctrl[nr] = it87_read_value(data, IT87_REG_PWM(nr));
2502 if (has_newer_autopwm(data)) {
2503 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
2504 data->pwm_duty[nr] = it87_read_value(data,
2505 IT87_REG_PWM_DUTY(nr));
2507 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
2508 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
2509 else /* Manual mode */
2510 data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f;
2513 if (has_old_autopwm(data)) {
2516 for (i = 0; i < 5 ; i++)
2517 data->auto_temp[nr][i] = it87_read_value(data,
2518 IT87_REG_AUTO_TEMP(nr, i));
2519 for (i = 0; i < 3 ; i++)
2520 data->auto_pwm[nr][i] = it87_read_value(data,
2521 IT87_REG_AUTO_PWM(nr, i));
2525 static struct it87_data *it87_update_device(struct device *dev)
2527 struct it87_data *data = dev_get_drvdata(dev);
2530 mutex_lock(&data->update_lock);
2532 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
2536 * Cleared after each update, so reenable. Value
2537 * returned by this read will be previous value
2539 it87_write_value(data, IT87_REG_CONFIG,
2540 it87_read_value(data, IT87_REG_CONFIG) | 0x40);
2542 for (i = 0; i <= 7; i++) {
2544 it87_read_value(data, IT87_REG_VIN(i));
2546 it87_read_value(data, IT87_REG_VIN_MIN(i));
2548 it87_read_value(data, IT87_REG_VIN_MAX(i));
2550 /* in8 (battery) has no limit registers */
2551 data->in[8][0] = it87_read_value(data, IT87_REG_VIN(8));
2552 if (data->type == it8603)
2553 data->in[9][0] = it87_read_value(data, 0x2f);
2555 for (i = 0; i < 5; i++) {
2556 /* Skip disabled fans */
2557 if (!(data->has_fan & (1 << i)))
2561 it87_read_value(data, IT87_REG_FAN_MIN[i]);
2562 data->fan[i][0] = it87_read_value(data,
2564 /* Add high byte if in 16-bit mode */
2565 if (has_16bit_fans(data)) {
2566 data->fan[i][0] |= it87_read_value(data,
2567 IT87_REG_FANX[i]) << 8;
2568 data->fan[i][1] |= it87_read_value(data,
2569 IT87_REG_FANX_MIN[i]) << 8;
2572 for (i = 0; i < 3; i++) {
2573 if (!(data->has_temp & (1 << i)))
2576 it87_read_value(data, IT87_REG_TEMP(i));
2578 it87_read_value(data, IT87_REG_TEMP_LOW(i));
2580 it87_read_value(data, IT87_REG_TEMP_HIGH(i));
2581 if (has_temp_offset(data))
2583 it87_read_value(data,
2584 IT87_REG_TEMP_OFFSET[i]);
2587 /* Newer chips don't have clock dividers */
2588 if ((data->has_fan & 0x07) && !has_16bit_fans(data)) {
2589 i = it87_read_value(data, IT87_REG_FAN_DIV);
2590 data->fan_div[0] = i & 0x07;
2591 data->fan_div[1] = (i >> 3) & 0x07;
2592 data->fan_div[2] = (i & 0x40) ? 3 : 1;
2596 it87_read_value(data, IT87_REG_ALARM1) |
2597 (it87_read_value(data, IT87_REG_ALARM2) << 8) |
2598 (it87_read_value(data, IT87_REG_ALARM3) << 16);
2599 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
2601 data->fan_main_ctrl = it87_read_value(data,
2602 IT87_REG_FAN_MAIN_CTRL);
2603 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL);
2604 for (i = 0; i < 3; i++)
2605 it87_update_pwm_ctrl(data, i);
2607 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
2608 data->extra = it87_read_value(data, IT87_REG_TEMP_EXTRA);
2610 * The IT8705F does not have VID capability.
2611 * The IT8718F and later don't use IT87_REG_VID for the
2614 if (data->type == it8712 || data->type == it8716) {
2615 data->vid = it87_read_value(data, IT87_REG_VID);
2617 * The older IT8712F revisions had only 5 VID pins,
2618 * but we assume it is always safe to read 6 bits.
2622 data->last_updated = jiffies;
2626 mutex_unlock(&data->update_lock);
2631 static int __init it87_device_add(unsigned short address,
2632 const struct it87_sio_data *sio_data)
2634 struct resource res = {
2635 .start = address + IT87_EC_OFFSET,
2636 .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1,
2638 .flags = IORESOURCE_IO,
2642 err = acpi_check_resource_conflict(&res);
2646 pdev = platform_device_alloc(DRVNAME, address);
2649 pr_err("Device allocation failed\n");
2653 err = platform_device_add_resources(pdev, &res, 1);
2655 pr_err("Device resource addition failed (%d)\n", err);
2656 goto exit_device_put;
2659 err = platform_device_add_data(pdev, sio_data,
2660 sizeof(struct it87_sio_data));
2662 pr_err("Platform data allocation failed\n");
2663 goto exit_device_put;
2666 err = platform_device_add(pdev);
2668 pr_err("Device addition failed (%d)\n", err);
2669 goto exit_device_put;
2675 platform_device_put(pdev);
2680 static int __init sm_it87_init(void)
2683 unsigned short isa_address = 0;
2684 struct it87_sio_data sio_data;
2686 memset(&sio_data, 0, sizeof(struct it87_sio_data));
2687 err = it87_find(&isa_address, &sio_data);
2690 err = platform_driver_register(&it87_driver);
2694 err = it87_device_add(isa_address, &sio_data);
2696 platform_driver_unregister(&it87_driver);
2703 static void __exit sm_it87_exit(void)
2705 platform_device_unregister(pdev);
2706 platform_driver_unregister(&it87_driver);
2710 MODULE_AUTHOR("Chris Gauthron, Jean Delvare <jdelvare@suse.de>");
2711 MODULE_DESCRIPTION("IT8705F/IT871xF/IT872xF hardware monitoring driver");
2712 module_param(update_vbat, bool, 0);
2713 MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
2714 module_param(fix_pwm_polarity, bool, 0);
2715 MODULE_PARM_DESC(fix_pwm_polarity,
2716 "Force PWM polarity to active high (DANGEROUS)");
2717 MODULE_LICENSE("GPL");
2719 module_init(sm_it87_init);
2720 module_exit(sm_it87_exit);