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: IT8705F Super I/O chip w/LPC interface
14 * IT8712F Super I/O chip w/LPC interface
15 * IT8716F Super I/O chip w/LPC interface
16 * IT8718F Super I/O chip w/LPC interface
17 * IT8720F Super I/O chip w/LPC interface
18 * IT8726F Super I/O chip w/LPC interface
19 * Sis950 A clone of the IT8705F
21 * Copyright (C) 2001 Chris Gauthron
22 * Copyright (C) 2005-2010 Jean Delvare <khali@linux-fr.org>
24 * This program is free software; you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation; either version 2 of the License, or
27 * (at your option) any later version.
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with this program; if not, write to the Free Software
36 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
39 #include <linux/module.h>
40 #include <linux/init.h>
41 #include <linux/slab.h>
42 #include <linux/jiffies.h>
43 #include <linux/platform_device.h>
44 #include <linux/hwmon.h>
45 #include <linux/hwmon-sysfs.h>
46 #include <linux/hwmon-vid.h>
47 #include <linux/err.h>
48 #include <linux/mutex.h>
49 #include <linux/sysfs.h>
50 #include <linux/string.h>
51 #include <linux/dmi.h>
52 #include <linux/acpi.h>
55 #define DRVNAME "it87"
57 enum chips { it87, it8712, it8716, it8718, it8720 };
59 static unsigned short force_id;
60 module_param(force_id, ushort, 0);
61 MODULE_PARM_DESC(force_id, "Override the detected device ID");
63 static struct platform_device *pdev;
65 #define REG 0x2e /* The register to read/write */
66 #define DEV 0x07 /* Register: Logical device select */
67 #define VAL 0x2f /* The value to read/write */
68 #define PME 0x04 /* The device with the fan registers in it */
70 /* The device with the IT8718F/IT8720F VID value in it */
73 #define DEVID 0x20 /* Register: Device ID */
74 #define DEVREV 0x22 /* Register: Device Revision */
84 superio_outb(int reg, int val)
90 static int superio_inw(int reg)
101 superio_select(int ldn)
123 /* Logical device 4 registers */
124 #define IT8712F_DEVID 0x8712
125 #define IT8705F_DEVID 0x8705
126 #define IT8716F_DEVID 0x8716
127 #define IT8718F_DEVID 0x8718
128 #define IT8720F_DEVID 0x8720
129 #define IT8726F_DEVID 0x8726
130 #define IT87_ACT_REG 0x30
131 #define IT87_BASE_REG 0x60
133 /* Logical device 7 registers (IT8712F and later) */
134 #define IT87_SIO_GPIO3_REG 0x27
135 #define IT87_SIO_GPIO5_REG 0x29
136 #define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
137 #define IT87_SIO_VID_REG 0xfc /* VID value */
138 #define IT87_SIO_BEEP_PIN_REG 0xf6 /* Beep pin mapping */
140 /* Update battery voltage after every reading if true */
141 static int update_vbat;
143 /* Not all BIOSes properly configure the PWM registers */
144 static int fix_pwm_polarity;
146 /* Many IT87 constants specified below */
148 /* Length of ISA address segment */
149 #define IT87_EXTENT 8
151 /* Length of ISA address segment for Environmental Controller */
152 #define IT87_EC_EXTENT 2
154 /* Offset of EC registers from ISA base address */
155 #define IT87_EC_OFFSET 5
157 /* Where are the ISA address/data registers relative to the EC base address */
158 #define IT87_ADDR_REG_OFFSET 0
159 #define IT87_DATA_REG_OFFSET 1
161 /*----- The IT87 registers -----*/
163 #define IT87_REG_CONFIG 0x00
165 #define IT87_REG_ALARM1 0x01
166 #define IT87_REG_ALARM2 0x02
167 #define IT87_REG_ALARM3 0x03
169 /* The IT8718F and IT8720F have the VID value in a different register, in
170 Super-I/O configuration space. */
171 #define IT87_REG_VID 0x0a
172 /* The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b
173 for fan divisors. Later IT8712F revisions must use 16-bit tachometer
175 #define IT87_REG_FAN_DIV 0x0b
176 #define IT87_REG_FAN_16BIT 0x0c
178 /* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */
180 static const u8 IT87_REG_FAN[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82 };
181 static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86 };
182 static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83 };
183 static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 };
184 #define IT87_REG_FAN_MAIN_CTRL 0x13
185 #define IT87_REG_FAN_CTL 0x14
186 #define IT87_REG_PWM(nr) (0x15 + (nr))
188 #define IT87_REG_VIN(nr) (0x20 + (nr))
189 #define IT87_REG_TEMP(nr) (0x29 + (nr))
191 #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2)
192 #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2)
193 #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2)
194 #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2)
196 #define IT87_REG_VIN_ENABLE 0x50
197 #define IT87_REG_TEMP_ENABLE 0x51
198 #define IT87_REG_BEEP_ENABLE 0x5c
200 #define IT87_REG_CHIPID 0x58
202 #define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i))
203 #define IT87_REG_AUTO_PWM(nr, i) (0x65 + (nr) * 8 + (i))
206 struct it87_sio_data {
208 /* Values read from Super-I/O config space */
212 u8 internal; /* Internal sensors can be labeled */
213 /* Features skipped based on config or DMI */
219 /* For each registered chip, we need to keep some data in memory.
220 The structure is dynamically allocated. */
222 struct device *hwmon_dev;
228 struct mutex update_lock;
229 char valid; /* !=0 if following fields are valid */
230 unsigned long last_updated; /* In jiffies */
232 u8 in[9]; /* Register value */
233 u8 in_max[8]; /* Register value */
234 u8 in_min[8]; /* Register value */
235 u8 has_fan; /* Bitfield, fans enabled */
236 u16 fan[5]; /* Register values, possibly combined */
237 u16 fan_min[5]; /* Register values, possibly combined */
238 s8 temp[3]; /* Register value */
239 s8 temp_high[3]; /* Register value */
240 s8 temp_low[3]; /* Register value */
241 u8 sensor; /* Register value */
242 u8 fan_div[3]; /* Register encoding, shifted right */
243 u8 vid; /* Register encoding, combined */
245 u32 alarms; /* Register encoding, combined */
246 u8 beeps; /* Register encoding */
247 u8 fan_main_ctrl; /* Register value */
248 u8 fan_ctl; /* Register value */
250 /* The following 3 arrays correspond to the same registers. The
251 * meaning of bits 6-0 depends on the value of bit 7, and we want
252 * to preserve settings on mode changes, so we have to track all
253 * values separately. */
254 u8 pwm_ctrl[3]; /* Register value */
255 u8 pwm_duty[3]; /* Manual PWM value set by user (bit 6-0) */
256 u8 pwm_temp_map[3]; /* PWM to temp. chan. mapping (bits 1-0) */
258 /* Automatic fan speed control registers */
259 u8 auto_pwm[3][4]; /* [nr][3] is hard-coded */
260 s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */
263 #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8) / 16), 0, 255))
264 #define IN_FROM_REG(val) ((val) * 16)
266 static inline u8 FAN_TO_REG(long rpm, int div)
270 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
271 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1,
275 static inline u16 FAN16_TO_REG(long rpm)
279 return SENSORS_LIMIT((1350000 + rpm) / (rpm * 2), 1, 0xfffe);
282 #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \
283 1350000 / ((val) * (div)))
284 /* The divider is fixed to 2 in 16-bit mode */
285 #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
286 1350000 / ((val) * 2))
288 #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? (((val) - 500) / 1000) : \
289 ((val) + 500) / 1000), -128, 127))
290 #define TEMP_FROM_REG(val) ((val) * 1000)
292 #define PWM_TO_REG(val) ((val) >> 1)
293 #define PWM_FROM_REG(val) (((val) & 0x7f) << 1)
295 static int DIV_TO_REG(int val)
298 while (answer < 7 && (val >>= 1))
302 #define DIV_FROM_REG(val) (1 << (val))
304 static const unsigned int pwm_freq[8] = {
315 static inline int has_16bit_fans(const struct it87_data *data)
317 /* IT8705F Datasheet 0.4.1, 3h == Version G.
318 IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J.
319 These are the first revisions with 16bit tachometer support. */
320 return (data->type == it87 && data->revision >= 0x03)
321 || (data->type == it8712 && data->revision >= 0x08)
322 || data->type == it8716
323 || data->type == it8718
324 || data->type == it8720;
327 static inline int has_old_autopwm(const struct it87_data *data)
329 /* The old automatic fan speed control interface is implemented
330 by IT8705F chips up to revision F and IT8712F chips up to
332 return (data->type == it87 && data->revision < 0x03)
333 || (data->type == it8712 && data->revision < 0x08);
336 static int it87_probe(struct platform_device *pdev);
337 static int __devexit it87_remove(struct platform_device *pdev);
339 static int it87_read_value(struct it87_data *data, u8 reg);
340 static void it87_write_value(struct it87_data *data, u8 reg, u8 value);
341 static struct it87_data *it87_update_device(struct device *dev);
342 static int it87_check_pwm(struct device *dev);
343 static void it87_init_device(struct platform_device *pdev);
346 static struct platform_driver it87_driver = {
348 .owner = THIS_MODULE,
352 .remove = __devexit_p(it87_remove),
355 static ssize_t show_in(struct device *dev, struct device_attribute *attr,
358 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
359 int nr = sensor_attr->index;
361 struct it87_data *data = it87_update_device(dev);
362 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr]));
365 static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
368 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
369 int nr = sensor_attr->index;
371 struct it87_data *data = it87_update_device(dev);
372 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr]));
375 static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
378 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
379 int nr = sensor_attr->index;
381 struct it87_data *data = it87_update_device(dev);
382 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr]));
385 static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
386 const char *buf, size_t count)
388 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
389 int nr = sensor_attr->index;
391 struct it87_data *data = dev_get_drvdata(dev);
394 if (strict_strtoul(buf, 10, &val) < 0)
397 mutex_lock(&data->update_lock);
398 data->in_min[nr] = IN_TO_REG(val);
399 it87_write_value(data, IT87_REG_VIN_MIN(nr),
401 mutex_unlock(&data->update_lock);
404 static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
405 const char *buf, size_t count)
407 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
408 int nr = sensor_attr->index;
410 struct it87_data *data = dev_get_drvdata(dev);
413 if (strict_strtoul(buf, 10, &val) < 0)
416 mutex_lock(&data->update_lock);
417 data->in_max[nr] = IN_TO_REG(val);
418 it87_write_value(data, IT87_REG_VIN_MAX(nr),
420 mutex_unlock(&data->update_lock);
424 #define show_in_offset(offset) \
425 static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
426 show_in, NULL, offset);
428 #define limit_in_offset(offset) \
429 static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
430 show_in_min, set_in_min, offset); \
431 static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
432 show_in_max, set_in_max, offset);
453 static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
456 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
457 int nr = sensor_attr->index;
459 struct it87_data *data = it87_update_device(dev);
460 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr]));
462 static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
465 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
466 int nr = sensor_attr->index;
468 struct it87_data *data = it87_update_device(dev);
469 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr]));
471 static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
474 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
475 int nr = sensor_attr->index;
477 struct it87_data *data = it87_update_device(dev);
478 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[nr]));
480 static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
481 const char *buf, size_t count)
483 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
484 int nr = sensor_attr->index;
486 struct it87_data *data = dev_get_drvdata(dev);
489 if (strict_strtol(buf, 10, &val) < 0)
492 mutex_lock(&data->update_lock);
493 data->temp_high[nr] = TEMP_TO_REG(val);
494 it87_write_value(data, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]);
495 mutex_unlock(&data->update_lock);
498 static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
499 const char *buf, size_t count)
501 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
502 int nr = sensor_attr->index;
504 struct it87_data *data = dev_get_drvdata(dev);
507 if (strict_strtol(buf, 10, &val) < 0)
510 mutex_lock(&data->update_lock);
511 data->temp_low[nr] = TEMP_TO_REG(val);
512 it87_write_value(data, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]);
513 mutex_unlock(&data->update_lock);
516 #define show_temp_offset(offset) \
517 static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
518 show_temp, NULL, offset - 1); \
519 static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
520 show_temp_max, set_temp_max, offset - 1); \
521 static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
522 show_temp_min, set_temp_min, offset - 1);
528 static ssize_t show_sensor(struct device *dev, struct device_attribute *attr,
531 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
532 int nr = sensor_attr->index;
534 struct it87_data *data = it87_update_device(dev);
535 u8 reg = data->sensor; /* In case the value is updated while
539 return sprintf(buf, "3\n"); /* thermal diode */
541 return sprintf(buf, "4\n"); /* thermistor */
542 return sprintf(buf, "0\n"); /* disabled */
544 static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,
545 const char *buf, size_t count)
547 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
548 int nr = sensor_attr->index;
550 struct it87_data *data = dev_get_drvdata(dev);
554 if (strict_strtol(buf, 10, &val) < 0)
557 reg = it87_read_value(data, IT87_REG_TEMP_ENABLE);
560 if (val == 2) { /* backwards compatibility */
561 dev_warn(dev, "Sensor type 2 is deprecated, please use 4 "
565 /* 3 = thermal diode; 4 = thermistor; 0 = disabled */
573 mutex_lock(&data->update_lock);
575 it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor);
576 data->valid = 0; /* Force cache refresh */
577 mutex_unlock(&data->update_lock);
580 #define show_sensor_offset(offset) \
581 static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \
582 show_sensor, set_sensor, offset - 1);
584 show_sensor_offset(1);
585 show_sensor_offset(2);
586 show_sensor_offset(3);
590 static int pwm_mode(const struct it87_data *data, int nr)
592 int ctrl = data->fan_main_ctrl & (1 << nr);
594 if (ctrl == 0) /* Full speed */
596 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
598 else /* Manual mode */
602 static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
605 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
606 int nr = sensor_attr->index;
608 struct it87_data *data = it87_update_device(dev);
609 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
610 DIV_FROM_REG(data->fan_div[nr])));
612 static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
615 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
616 int nr = sensor_attr->index;
618 struct it87_data *data = it87_update_device(dev);
619 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
620 DIV_FROM_REG(data->fan_div[nr])));
622 static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
625 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
626 int nr = sensor_attr->index;
628 struct it87_data *data = it87_update_device(dev);
629 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
631 static ssize_t show_pwm_enable(struct device *dev,
632 struct device_attribute *attr, char *buf)
634 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
635 int nr = sensor_attr->index;
637 struct it87_data *data = it87_update_device(dev);
638 return sprintf(buf, "%d\n", pwm_mode(data, nr));
640 static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
643 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
644 int nr = sensor_attr->index;
646 struct it87_data *data = it87_update_device(dev);
647 return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm_duty[nr]));
649 static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
652 struct it87_data *data = it87_update_device(dev);
653 int index = (data->fan_ctl >> 4) & 0x07;
655 return sprintf(buf, "%u\n", pwm_freq[index]);
657 static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
658 const char *buf, size_t count)
660 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
661 int nr = sensor_attr->index;
663 struct it87_data *data = dev_get_drvdata(dev);
667 if (strict_strtol(buf, 10, &val) < 0)
670 mutex_lock(&data->update_lock);
671 reg = it87_read_value(data, IT87_REG_FAN_DIV);
674 data->fan_div[nr] = reg & 0x07;
677 data->fan_div[nr] = (reg >> 3) & 0x07;
680 data->fan_div[nr] = (reg & 0x40) ? 3 : 1;
684 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
685 it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]);
686 mutex_unlock(&data->update_lock);
689 static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
690 const char *buf, size_t count)
692 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
693 int nr = sensor_attr->index;
695 struct it87_data *data = dev_get_drvdata(dev);
700 if (strict_strtoul(buf, 10, &val) < 0)
703 mutex_lock(&data->update_lock);
704 old = it87_read_value(data, IT87_REG_FAN_DIV);
706 /* Save fan min limit */
707 min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]));
712 data->fan_div[nr] = DIV_TO_REG(val);
716 data->fan_div[nr] = 1;
718 data->fan_div[nr] = 3;
721 val |= (data->fan_div[0] & 0x07);
722 val |= (data->fan_div[1] & 0x07) << 3;
723 if (data->fan_div[2] == 3)
725 it87_write_value(data, IT87_REG_FAN_DIV, val);
727 /* Restore fan min limit */
728 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
729 it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]);
731 mutex_unlock(&data->update_lock);
735 /* Returns 0 if OK, -EINVAL otherwise */
736 static int check_trip_points(struct device *dev, int nr)
738 const struct it87_data *data = dev_get_drvdata(dev);
741 if (has_old_autopwm(data)) {
742 for (i = 0; i < 3; i++) {
743 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1])
746 for (i = 0; i < 2; i++) {
747 if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1])
753 dev_err(dev, "Inconsistent trip points, not switching to "
755 dev_err(dev, "Adjust the trip points and try again\n");
760 static ssize_t set_pwm_enable(struct device *dev,
761 struct device_attribute *attr, const char *buf, size_t count)
763 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
764 int nr = sensor_attr->index;
766 struct it87_data *data = dev_get_drvdata(dev);
769 if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 2)
772 /* Check trip points before switching to automatic mode */
774 if (check_trip_points(dev, nr) < 0)
778 mutex_lock(&data->update_lock);
782 /* make sure the fan is on when in on/off mode */
783 tmp = it87_read_value(data, IT87_REG_FAN_CTL);
784 it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr));
785 /* set on/off mode */
786 data->fan_main_ctrl &= ~(1 << nr);
787 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
788 data->fan_main_ctrl);
790 if (val == 1) /* Manual mode */
791 data->pwm_ctrl[nr] = data->pwm_duty[nr];
792 else /* Automatic mode */
793 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
794 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
795 /* set SmartGuardian mode */
796 data->fan_main_ctrl |= (1 << nr);
797 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
798 data->fan_main_ctrl);
801 mutex_unlock(&data->update_lock);
804 static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
805 const char *buf, size_t count)
807 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
808 int nr = sensor_attr->index;
810 struct it87_data *data = dev_get_drvdata(dev);
813 if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 255)
816 mutex_lock(&data->update_lock);
817 data->pwm_duty[nr] = PWM_TO_REG(val);
818 /* If we are in manual mode, write the duty cycle immediately;
819 * otherwise, just store it for later use. */
820 if (!(data->pwm_ctrl[nr] & 0x80)) {
821 data->pwm_ctrl[nr] = data->pwm_duty[nr];
822 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
824 mutex_unlock(&data->update_lock);
827 static ssize_t set_pwm_freq(struct device *dev,
828 struct device_attribute *attr, const char *buf, size_t count)
830 struct it87_data *data = dev_get_drvdata(dev);
834 if (strict_strtoul(buf, 10, &val) < 0)
837 /* Search for the nearest available frequency */
838 for (i = 0; i < 7; i++) {
839 if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2)
843 mutex_lock(&data->update_lock);
844 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f;
845 data->fan_ctl |= i << 4;
846 it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl);
847 mutex_unlock(&data->update_lock);
851 static ssize_t show_pwm_temp_map(struct device *dev,
852 struct device_attribute *attr, char *buf)
854 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
855 int nr = sensor_attr->index;
857 struct it87_data *data = it87_update_device(dev);
860 if (data->pwm_temp_map[nr] < 3)
861 map = 1 << data->pwm_temp_map[nr];
863 map = 0; /* Should never happen */
864 return sprintf(buf, "%d\n", map);
866 static ssize_t set_pwm_temp_map(struct device *dev,
867 struct device_attribute *attr, const char *buf, size_t count)
869 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
870 int nr = sensor_attr->index;
872 struct it87_data *data = dev_get_drvdata(dev);
876 /* This check can go away if we ever support automatic fan speed
877 control on newer chips. */
878 if (!has_old_autopwm(data)) {
879 dev_notice(dev, "Mapping change disabled for safety reasons\n");
883 if (strict_strtol(buf, 10, &val) < 0)
900 mutex_lock(&data->update_lock);
901 data->pwm_temp_map[nr] = reg;
902 /* If we are in automatic mode, write the temp mapping immediately;
903 * otherwise, just store it for later use. */
904 if (data->pwm_ctrl[nr] & 0x80) {
905 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
906 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
908 mutex_unlock(&data->update_lock);
912 static ssize_t show_auto_pwm(struct device *dev,
913 struct device_attribute *attr, char *buf)
915 struct it87_data *data = it87_update_device(dev);
916 struct sensor_device_attribute_2 *sensor_attr =
917 to_sensor_dev_attr_2(attr);
918 int nr = sensor_attr->nr;
919 int point = sensor_attr->index;
921 return sprintf(buf, "%d\n", PWM_FROM_REG(data->auto_pwm[nr][point]));
924 static ssize_t set_auto_pwm(struct device *dev,
925 struct device_attribute *attr, const char *buf, size_t count)
927 struct it87_data *data = dev_get_drvdata(dev);
928 struct sensor_device_attribute_2 *sensor_attr =
929 to_sensor_dev_attr_2(attr);
930 int nr = sensor_attr->nr;
931 int point = sensor_attr->index;
934 if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 255)
937 mutex_lock(&data->update_lock);
938 data->auto_pwm[nr][point] = PWM_TO_REG(val);
939 it87_write_value(data, IT87_REG_AUTO_PWM(nr, point),
940 data->auto_pwm[nr][point]);
941 mutex_unlock(&data->update_lock);
945 static ssize_t show_auto_temp(struct device *dev,
946 struct device_attribute *attr, char *buf)
948 struct it87_data *data = it87_update_device(dev);
949 struct sensor_device_attribute_2 *sensor_attr =
950 to_sensor_dev_attr_2(attr);
951 int nr = sensor_attr->nr;
952 int point = sensor_attr->index;
954 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->auto_temp[nr][point]));
957 static ssize_t set_auto_temp(struct device *dev,
958 struct device_attribute *attr, const char *buf, size_t count)
960 struct it87_data *data = dev_get_drvdata(dev);
961 struct sensor_device_attribute_2 *sensor_attr =
962 to_sensor_dev_attr_2(attr);
963 int nr = sensor_attr->nr;
964 int point = sensor_attr->index;
967 if (strict_strtol(buf, 10, &val) < 0 || val < -128000 || val > 127000)
970 mutex_lock(&data->update_lock);
971 data->auto_temp[nr][point] = TEMP_TO_REG(val);
972 it87_write_value(data, IT87_REG_AUTO_TEMP(nr, point),
973 data->auto_temp[nr][point]);
974 mutex_unlock(&data->update_lock);
978 #define show_fan_offset(offset) \
979 static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
980 show_fan, NULL, offset - 1); \
981 static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
982 show_fan_min, set_fan_min, offset - 1); \
983 static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
984 show_fan_div, set_fan_div, offset - 1);
990 #define show_pwm_offset(offset) \
991 static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
992 show_pwm_enable, set_pwm_enable, offset - 1); \
993 static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
994 show_pwm, set_pwm, offset - 1); \
995 static DEVICE_ATTR(pwm##offset##_freq, \
996 (offset == 1 ? S_IRUGO | S_IWUSR : S_IRUGO), \
997 show_pwm_freq, (offset == 1 ? set_pwm_freq : NULL)); \
998 static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels_temp, \
999 S_IRUGO | S_IWUSR, show_pwm_temp_map, set_pwm_temp_map, \
1001 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_pwm, \
1002 S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \
1004 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_pwm, \
1005 S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \
1007 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_pwm, \
1008 S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \
1010 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_pwm, \
1011 S_IRUGO, show_auto_pwm, NULL, offset - 1, 3); \
1012 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp, \
1013 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1015 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp_hyst, \
1016 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1018 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_temp, \
1019 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1021 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_temp, \
1022 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1024 static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_temp, \
1025 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1032 /* A different set of callbacks for 16-bit fans */
1033 static ssize_t show_fan16(struct device *dev, struct device_attribute *attr,
1036 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1037 int nr = sensor_attr->index;
1038 struct it87_data *data = it87_update_device(dev);
1039 return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan[nr]));
1042 static ssize_t show_fan16_min(struct device *dev, struct device_attribute *attr,
1045 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1046 int nr = sensor_attr->index;
1047 struct it87_data *data = it87_update_device(dev);
1048 return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan_min[nr]));
1051 static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr,
1052 const char *buf, size_t count)
1054 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1055 int nr = sensor_attr->index;
1056 struct it87_data *data = dev_get_drvdata(dev);
1059 if (strict_strtol(buf, 10, &val) < 0)
1062 mutex_lock(&data->update_lock);
1063 data->fan_min[nr] = FAN16_TO_REG(val);
1064 it87_write_value(data, IT87_REG_FAN_MIN[nr],
1065 data->fan_min[nr] & 0xff);
1066 it87_write_value(data, IT87_REG_FANX_MIN[nr],
1067 data->fan_min[nr] >> 8);
1068 mutex_unlock(&data->update_lock);
1072 /* We want to use the same sysfs file names as 8-bit fans, but we need
1073 different variable names, so we have to use SENSOR_ATTR instead of
1074 SENSOR_DEVICE_ATTR. */
1075 #define show_fan16_offset(offset) \
1076 static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \
1077 = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \
1078 show_fan16, NULL, offset - 1); \
1079 static struct sensor_device_attribute sensor_dev_attr_fan##offset##_min16 \
1080 = SENSOR_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
1081 show_fan16_min, set_fan16_min, offset - 1)
1083 show_fan16_offset(1);
1084 show_fan16_offset(2);
1085 show_fan16_offset(3);
1086 show_fan16_offset(4);
1087 show_fan16_offset(5);
1090 static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
1093 struct it87_data *data = it87_update_device(dev);
1094 return sprintf(buf, "%u\n", data->alarms);
1096 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
1098 static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
1101 int bitnr = to_sensor_dev_attr(attr)->index;
1102 struct it87_data *data = it87_update_device(dev);
1103 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
1105 static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8);
1106 static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9);
1107 static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10);
1108 static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11);
1109 static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12);
1110 static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13);
1111 static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14);
1112 static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15);
1113 static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0);
1114 static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1);
1115 static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2);
1116 static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3);
1117 static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6);
1118 static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16);
1119 static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17);
1120 static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18);
1122 static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
1125 int bitnr = to_sensor_dev_attr(attr)->index;
1126 struct it87_data *data = it87_update_device(dev);
1127 return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1);
1129 static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
1130 const char *buf, size_t count)
1132 int bitnr = to_sensor_dev_attr(attr)->index;
1133 struct it87_data *data = dev_get_drvdata(dev);
1136 if (strict_strtol(buf, 10, &val) < 0
1137 || (val != 0 && val != 1))
1140 mutex_lock(&data->update_lock);
1141 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
1143 data->beeps |= (1 << bitnr);
1145 data->beeps &= ~(1 << bitnr);
1146 it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps);
1147 mutex_unlock(&data->update_lock);
1151 static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
1152 show_beep, set_beep, 1);
1153 static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO, show_beep, NULL, 1);
1154 static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO, show_beep, NULL, 1);
1155 static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO, show_beep, NULL, 1);
1156 static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO, show_beep, NULL, 1);
1157 static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO, show_beep, NULL, 1);
1158 static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO, show_beep, NULL, 1);
1159 static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO, show_beep, NULL, 1);
1160 /* fanX_beep writability is set later */
1161 static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO, show_beep, set_beep, 0);
1162 static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0);
1163 static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0);
1164 static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0);
1165 static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0);
1166 static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
1167 show_beep, set_beep, 2);
1168 static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2);
1169 static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2);
1171 static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
1174 struct it87_data *data = dev_get_drvdata(dev);
1175 return sprintf(buf, "%u\n", data->vrm);
1177 static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
1178 const char *buf, size_t count)
1180 struct it87_data *data = dev_get_drvdata(dev);
1183 if (strict_strtoul(buf, 10, &val) < 0)
1190 static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
1192 static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
1195 struct it87_data *data = it87_update_device(dev);
1196 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
1198 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
1200 static ssize_t show_label(struct device *dev, struct device_attribute *attr,
1203 static const char *labels[] = {
1208 int nr = to_sensor_dev_attr(attr)->index;
1210 return sprintf(buf, "%s\n", labels[nr]);
1212 static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0);
1213 static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1);
1214 static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 2);
1216 static ssize_t show_name(struct device *dev, struct device_attribute
1217 *devattr, char *buf)
1219 struct it87_data *data = dev_get_drvdata(dev);
1220 return sprintf(buf, "%s\n", data->name);
1222 static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
1224 static struct attribute *it87_attributes[] = {
1225 &sensor_dev_attr_in0_input.dev_attr.attr,
1226 &sensor_dev_attr_in1_input.dev_attr.attr,
1227 &sensor_dev_attr_in2_input.dev_attr.attr,
1228 &sensor_dev_attr_in3_input.dev_attr.attr,
1229 &sensor_dev_attr_in4_input.dev_attr.attr,
1230 &sensor_dev_attr_in5_input.dev_attr.attr,
1231 &sensor_dev_attr_in6_input.dev_attr.attr,
1232 &sensor_dev_attr_in7_input.dev_attr.attr,
1233 &sensor_dev_attr_in8_input.dev_attr.attr,
1234 &sensor_dev_attr_in0_min.dev_attr.attr,
1235 &sensor_dev_attr_in1_min.dev_attr.attr,
1236 &sensor_dev_attr_in2_min.dev_attr.attr,
1237 &sensor_dev_attr_in3_min.dev_attr.attr,
1238 &sensor_dev_attr_in4_min.dev_attr.attr,
1239 &sensor_dev_attr_in5_min.dev_attr.attr,
1240 &sensor_dev_attr_in6_min.dev_attr.attr,
1241 &sensor_dev_attr_in7_min.dev_attr.attr,
1242 &sensor_dev_attr_in0_max.dev_attr.attr,
1243 &sensor_dev_attr_in1_max.dev_attr.attr,
1244 &sensor_dev_attr_in2_max.dev_attr.attr,
1245 &sensor_dev_attr_in3_max.dev_attr.attr,
1246 &sensor_dev_attr_in4_max.dev_attr.attr,
1247 &sensor_dev_attr_in5_max.dev_attr.attr,
1248 &sensor_dev_attr_in6_max.dev_attr.attr,
1249 &sensor_dev_attr_in7_max.dev_attr.attr,
1250 &sensor_dev_attr_in0_alarm.dev_attr.attr,
1251 &sensor_dev_attr_in1_alarm.dev_attr.attr,
1252 &sensor_dev_attr_in2_alarm.dev_attr.attr,
1253 &sensor_dev_attr_in3_alarm.dev_attr.attr,
1254 &sensor_dev_attr_in4_alarm.dev_attr.attr,
1255 &sensor_dev_attr_in5_alarm.dev_attr.attr,
1256 &sensor_dev_attr_in6_alarm.dev_attr.attr,
1257 &sensor_dev_attr_in7_alarm.dev_attr.attr,
1259 &sensor_dev_attr_temp1_input.dev_attr.attr,
1260 &sensor_dev_attr_temp2_input.dev_attr.attr,
1261 &sensor_dev_attr_temp3_input.dev_attr.attr,
1262 &sensor_dev_attr_temp1_max.dev_attr.attr,
1263 &sensor_dev_attr_temp2_max.dev_attr.attr,
1264 &sensor_dev_attr_temp3_max.dev_attr.attr,
1265 &sensor_dev_attr_temp1_min.dev_attr.attr,
1266 &sensor_dev_attr_temp2_min.dev_attr.attr,
1267 &sensor_dev_attr_temp3_min.dev_attr.attr,
1268 &sensor_dev_attr_temp1_type.dev_attr.attr,
1269 &sensor_dev_attr_temp2_type.dev_attr.attr,
1270 &sensor_dev_attr_temp3_type.dev_attr.attr,
1271 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
1272 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
1273 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
1275 &dev_attr_alarms.attr,
1276 &dev_attr_name.attr,
1280 static const struct attribute_group it87_group = {
1281 .attrs = it87_attributes,
1284 static struct attribute *it87_attributes_beep[] = {
1285 &sensor_dev_attr_in0_beep.dev_attr.attr,
1286 &sensor_dev_attr_in1_beep.dev_attr.attr,
1287 &sensor_dev_attr_in2_beep.dev_attr.attr,
1288 &sensor_dev_attr_in3_beep.dev_attr.attr,
1289 &sensor_dev_attr_in4_beep.dev_attr.attr,
1290 &sensor_dev_attr_in5_beep.dev_attr.attr,
1291 &sensor_dev_attr_in6_beep.dev_attr.attr,
1292 &sensor_dev_attr_in7_beep.dev_attr.attr,
1294 &sensor_dev_attr_temp1_beep.dev_attr.attr,
1295 &sensor_dev_attr_temp2_beep.dev_attr.attr,
1296 &sensor_dev_attr_temp3_beep.dev_attr.attr,
1300 static const struct attribute_group it87_group_beep = {
1301 .attrs = it87_attributes_beep,
1304 static struct attribute *it87_attributes_fan16[5][3+1] = { {
1305 &sensor_dev_attr_fan1_input16.dev_attr.attr,
1306 &sensor_dev_attr_fan1_min16.dev_attr.attr,
1307 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1310 &sensor_dev_attr_fan2_input16.dev_attr.attr,
1311 &sensor_dev_attr_fan2_min16.dev_attr.attr,
1312 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1315 &sensor_dev_attr_fan3_input16.dev_attr.attr,
1316 &sensor_dev_attr_fan3_min16.dev_attr.attr,
1317 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
1320 &sensor_dev_attr_fan4_input16.dev_attr.attr,
1321 &sensor_dev_attr_fan4_min16.dev_attr.attr,
1322 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
1325 &sensor_dev_attr_fan5_input16.dev_attr.attr,
1326 &sensor_dev_attr_fan5_min16.dev_attr.attr,
1327 &sensor_dev_attr_fan5_alarm.dev_attr.attr,
1331 static const struct attribute_group it87_group_fan16[5] = {
1332 { .attrs = it87_attributes_fan16[0] },
1333 { .attrs = it87_attributes_fan16[1] },
1334 { .attrs = it87_attributes_fan16[2] },
1335 { .attrs = it87_attributes_fan16[3] },
1336 { .attrs = it87_attributes_fan16[4] },
1339 static struct attribute *it87_attributes_fan[3][4+1] = { {
1340 &sensor_dev_attr_fan1_input.dev_attr.attr,
1341 &sensor_dev_attr_fan1_min.dev_attr.attr,
1342 &sensor_dev_attr_fan1_div.dev_attr.attr,
1343 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1346 &sensor_dev_attr_fan2_input.dev_attr.attr,
1347 &sensor_dev_attr_fan2_min.dev_attr.attr,
1348 &sensor_dev_attr_fan2_div.dev_attr.attr,
1349 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1352 &sensor_dev_attr_fan3_input.dev_attr.attr,
1353 &sensor_dev_attr_fan3_min.dev_attr.attr,
1354 &sensor_dev_attr_fan3_div.dev_attr.attr,
1355 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
1359 static const struct attribute_group it87_group_fan[3] = {
1360 { .attrs = it87_attributes_fan[0] },
1361 { .attrs = it87_attributes_fan[1] },
1362 { .attrs = it87_attributes_fan[2] },
1365 static const struct attribute_group *
1366 it87_get_fan_group(const struct it87_data *data)
1368 return has_16bit_fans(data) ? it87_group_fan16 : it87_group_fan;
1371 static struct attribute *it87_attributes_pwm[3][4+1] = { {
1372 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
1373 &sensor_dev_attr_pwm1.dev_attr.attr,
1374 &dev_attr_pwm1_freq.attr,
1375 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
1378 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1379 &sensor_dev_attr_pwm2.dev_attr.attr,
1380 &dev_attr_pwm2_freq.attr,
1381 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
1384 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
1385 &sensor_dev_attr_pwm3.dev_attr.attr,
1386 &dev_attr_pwm3_freq.attr,
1387 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
1391 static const struct attribute_group it87_group_pwm[3] = {
1392 { .attrs = it87_attributes_pwm[0] },
1393 { .attrs = it87_attributes_pwm[1] },
1394 { .attrs = it87_attributes_pwm[2] },
1397 static struct attribute *it87_attributes_autopwm[3][9+1] = { {
1398 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
1399 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
1400 &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr,
1401 &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr,
1402 &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
1403 &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr,
1404 &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr,
1405 &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr,
1406 &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr,
1409 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
1410 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
1411 &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr,
1412 &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr,
1413 &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr,
1414 &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr,
1415 &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr,
1416 &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr,
1417 &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr,
1420 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
1421 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
1422 &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr,
1423 &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr,
1424 &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr,
1425 &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr,
1426 &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr,
1427 &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr,
1428 &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr,
1432 static const struct attribute_group it87_group_autopwm[3] = {
1433 { .attrs = it87_attributes_autopwm[0] },
1434 { .attrs = it87_attributes_autopwm[1] },
1435 { .attrs = it87_attributes_autopwm[2] },
1438 static struct attribute *it87_attributes_fan_beep[] = {
1439 &sensor_dev_attr_fan1_beep.dev_attr.attr,
1440 &sensor_dev_attr_fan2_beep.dev_attr.attr,
1441 &sensor_dev_attr_fan3_beep.dev_attr.attr,
1442 &sensor_dev_attr_fan4_beep.dev_attr.attr,
1443 &sensor_dev_attr_fan5_beep.dev_attr.attr,
1446 static struct attribute *it87_attributes_vid[] = {
1448 &dev_attr_cpu0_vid.attr,
1452 static const struct attribute_group it87_group_vid = {
1453 .attrs = it87_attributes_vid,
1456 static struct attribute *it87_attributes_label[] = {
1457 &sensor_dev_attr_in3_label.dev_attr.attr,
1458 &sensor_dev_attr_in7_label.dev_attr.attr,
1459 &sensor_dev_attr_in8_label.dev_attr.attr,
1463 static const struct attribute_group it87_group_label = {
1464 .attrs = it87_attributes_vid,
1467 /* SuperIO detection - will change isa_address if a chip is found */
1468 static int __init it87_find(unsigned short *address,
1469 struct it87_sio_data *sio_data)
1473 const char *board_vendor, *board_name;
1476 chip_type = force_id ? force_id : superio_inw(DEVID);
1478 switch (chip_type) {
1480 sio_data->type = it87;
1483 sio_data->type = it8712;
1487 sio_data->type = it8716;
1490 sio_data->type = it8718;
1493 sio_data->type = it8720;
1495 case 0xffff: /* No device at all */
1498 pr_debug(DRVNAME ": Unsupported chip (DEVID=0x%x)\n",
1503 superio_select(PME);
1504 if (!(superio_inb(IT87_ACT_REG) & 0x01)) {
1505 pr_info("it87: Device not activated, skipping\n");
1509 *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1);
1510 if (*address == 0) {
1511 pr_info("it87: Base address not set, skipping\n");
1516 sio_data->revision = superio_inb(DEVREV) & 0x0f;
1517 pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n",
1518 chip_type, *address, sio_data->revision);
1520 /* in8 (Vbat) is always internal */
1521 sio_data->internal = (1 << 2);
1523 /* Read GPIO config and VID value from LDN 7 (GPIO) */
1524 if (sio_data->type == it87) {
1525 /* The IT8705F doesn't have VID pins at all */
1526 sio_data->skip_vid = 1;
1528 /* The IT8705F has a different LD number for GPIO */
1530 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
1534 superio_select(GPIO);
1535 /* We need at least 4 VID pins */
1536 reg = superio_inb(IT87_SIO_GPIO3_REG);
1538 pr_info("it87: VID is disabled (pins used for GPIO)\n");
1539 sio_data->skip_vid = 1;
1542 /* Check if fan3 is there or not */
1544 sio_data->skip_pwm |= (1 << 2);
1546 sio_data->skip_fan |= (1 << 2);
1548 /* Check if fan2 is there or not */
1549 reg = superio_inb(IT87_SIO_GPIO5_REG);
1551 sio_data->skip_pwm |= (1 << 1);
1553 sio_data->skip_fan |= (1 << 1);
1555 if ((sio_data->type == it8718 || sio_data->type == it8720)
1556 && !(sio_data->skip_vid))
1557 sio_data->vid_value = superio_inb(IT87_SIO_VID_REG);
1559 reg = superio_inb(IT87_SIO_PINX2_REG);
1561 * The IT8720F has no VIN7 pin, so VCCH should always be
1562 * routed internally to VIN7 with an internal divider.
1563 * Curiously, there still is a configuration bit to control
1564 * this, which means it can be set incorrectly. And even
1565 * more curiously, many boards out there are improperly
1566 * configured, even though the IT8720F datasheet claims
1567 * that the internal routing of VCCH to VIN7 is the default
1568 * setting. So we force the internal routing in this case.
1570 if (sio_data->type == it8720 && !(reg & (1 << 1))) {
1572 superio_outb(IT87_SIO_PINX2_REG, reg);
1573 pr_notice("it87: Routing internal VCCH to in7\n");
1576 sio_data->internal |= (1 << 0);
1578 sio_data->internal |= (1 << 1);
1580 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
1582 if (sio_data->beep_pin)
1583 pr_info("it87: Beeping is supported\n");
1585 /* Disable specific features based on DMI strings */
1586 board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
1587 board_name = dmi_get_system_info(DMI_BOARD_NAME);
1588 if (board_vendor && board_name) {
1589 if (strcmp(board_vendor, "nVIDIA") == 0
1590 && strcmp(board_name, "FN68PT") == 0) {
1591 /* On the Shuttle SN68PT, FAN_CTL2 is apparently not
1592 connected to a fan, but to something else. One user
1593 has reported instant system power-off when changing
1594 the PWM2 duty cycle, so we disable it.
1595 I use the board name string as the trigger in case
1596 the same board is ever used in other systems. */
1597 pr_info("it87: Disabling pwm2 due to "
1598 "hardware constraints\n");
1599 sio_data->skip_pwm = (1 << 1);
1608 static void it87_remove_files(struct device *dev)
1610 struct it87_data *data = platform_get_drvdata(pdev);
1611 struct it87_sio_data *sio_data = dev->platform_data;
1612 const struct attribute_group *fan_group = it87_get_fan_group(data);
1615 sysfs_remove_group(&dev->kobj, &it87_group);
1616 if (sio_data->beep_pin)
1617 sysfs_remove_group(&dev->kobj, &it87_group_beep);
1618 for (i = 0; i < 5; i++) {
1619 if (!(data->has_fan & (1 << i)))
1621 sysfs_remove_group(&dev->kobj, &fan_group[i]);
1622 if (sio_data->beep_pin)
1623 sysfs_remove_file(&dev->kobj,
1624 it87_attributes_fan_beep[i]);
1626 for (i = 0; i < 3; i++) {
1627 if (sio_data->skip_pwm & (1 << 0))
1629 sysfs_remove_group(&dev->kobj, &it87_group_pwm[i]);
1630 if (has_old_autopwm(data))
1631 sysfs_remove_group(&dev->kobj,
1632 &it87_group_autopwm[i]);
1634 if (!sio_data->skip_vid)
1635 sysfs_remove_group(&dev->kobj, &it87_group_vid);
1636 sysfs_remove_group(&dev->kobj, &it87_group_label);
1639 static int __devinit it87_probe(struct platform_device *pdev)
1641 struct it87_data *data;
1642 struct resource *res;
1643 struct device *dev = &pdev->dev;
1644 struct it87_sio_data *sio_data = dev->platform_data;
1645 const struct attribute_group *fan_group;
1647 int enable_pwm_interface;
1648 int fan_beep_need_rw;
1649 static const char *names[] = {
1657 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
1658 if (!request_region(res->start, IT87_EC_EXTENT, DRVNAME)) {
1659 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
1660 (unsigned long)res->start,
1661 (unsigned long)(res->start + IT87_EC_EXTENT - 1));
1666 data = kzalloc(sizeof(struct it87_data), GFP_KERNEL);
1672 data->addr = res->start;
1673 data->type = sio_data->type;
1674 data->revision = sio_data->revision;
1675 data->name = names[sio_data->type];
1677 /* Now, we do the remaining detection. */
1678 if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80)
1679 || it87_read_value(data, IT87_REG_CHIPID) != 0x90) {
1684 platform_set_drvdata(pdev, data);
1686 mutex_init(&data->update_lock);
1688 /* Check PWM configuration */
1689 enable_pwm_interface = it87_check_pwm(dev);
1691 /* Initialize the IT87 chip */
1692 it87_init_device(pdev);
1694 /* Register sysfs hooks */
1695 err = sysfs_create_group(&dev->kobj, &it87_group);
1699 if (sio_data->beep_pin) {
1700 err = sysfs_create_group(&dev->kobj, &it87_group_beep);
1705 /* Do not create fan files for disabled fans */
1706 fan_group = it87_get_fan_group(data);
1707 fan_beep_need_rw = 1;
1708 for (i = 0; i < 5; i++) {
1709 if (!(data->has_fan & (1 << i)))
1711 err = sysfs_create_group(&dev->kobj, &fan_group[i]);
1715 if (sio_data->beep_pin) {
1716 err = sysfs_create_file(&dev->kobj,
1717 it87_attributes_fan_beep[i]);
1720 if (!fan_beep_need_rw)
1723 /* As we have a single beep enable bit for all fans,
1724 * only the first enabled fan has a writable attribute
1726 if (sysfs_chmod_file(&dev->kobj,
1727 it87_attributes_fan_beep[i],
1729 dev_dbg(dev, "chmod +w fan%d_beep failed\n",
1731 fan_beep_need_rw = 0;
1735 if (enable_pwm_interface) {
1736 for (i = 0; i < 3; i++) {
1737 if (sio_data->skip_pwm & (1 << i))
1739 err = sysfs_create_group(&dev->kobj,
1740 &it87_group_pwm[i]);
1744 if (!has_old_autopwm(data))
1746 err = sysfs_create_group(&dev->kobj,
1747 &it87_group_autopwm[i]);
1753 if (!sio_data->skip_vid) {
1754 data->vrm = vid_which_vrm();
1755 /* VID reading from Super-I/O config space if available */
1756 data->vid = sio_data->vid_value;
1757 err = sysfs_create_group(&dev->kobj, &it87_group_vid);
1762 /* Export labels for internal sensors */
1763 for (i = 0; i < 3; i++) {
1764 if (!(sio_data->internal & (1 << i)))
1766 err = sysfs_create_file(&dev->kobj,
1767 it87_attributes_label[i]);
1772 data->hwmon_dev = hwmon_device_register(dev);
1773 if (IS_ERR(data->hwmon_dev)) {
1774 err = PTR_ERR(data->hwmon_dev);
1781 it87_remove_files(dev);
1783 platform_set_drvdata(pdev, NULL);
1786 release_region(res->start, IT87_EC_EXTENT);
1791 static int __devexit it87_remove(struct platform_device *pdev)
1793 struct it87_data *data = platform_get_drvdata(pdev);
1795 hwmon_device_unregister(data->hwmon_dev);
1796 it87_remove_files(&pdev->dev);
1798 release_region(data->addr, IT87_EC_EXTENT);
1799 platform_set_drvdata(pdev, NULL);
1805 /* Must be called with data->update_lock held, except during initialization.
1806 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1807 would slow down the IT87 access and should not be necessary. */
1808 static int it87_read_value(struct it87_data *data, u8 reg)
1810 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
1811 return inb_p(data->addr + IT87_DATA_REG_OFFSET);
1814 /* Must be called with data->update_lock held, except during initialization.
1815 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1816 would slow down the IT87 access and should not be necessary. */
1817 static void it87_write_value(struct it87_data *data, u8 reg, u8 value)
1819 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
1820 outb_p(value, data->addr + IT87_DATA_REG_OFFSET);
1823 /* Return 1 if and only if the PWM interface is safe to use */
1824 static int __devinit it87_check_pwm(struct device *dev)
1826 struct it87_data *data = dev_get_drvdata(dev);
1827 /* Some BIOSes fail to correctly configure the IT87 fans. All fans off
1828 * and polarity set to active low is sign that this is the case so we
1829 * disable pwm control to protect the user. */
1830 int tmp = it87_read_value(data, IT87_REG_FAN_CTL);
1831 if ((tmp & 0x87) == 0) {
1832 if (fix_pwm_polarity) {
1833 /* The user asks us to attempt a chip reconfiguration.
1834 * This means switching to active high polarity and
1835 * inverting all fan speed values. */
1839 for (i = 0; i < 3; i++)
1840 pwm[i] = it87_read_value(data,
1843 /* If any fan is in automatic pwm mode, the polarity
1844 * might be correct, as suspicious as it seems, so we
1845 * better don't change anything (but still disable the
1846 * PWM interface). */
1847 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
1848 dev_info(dev, "Reconfiguring PWM to "
1849 "active high polarity\n");
1850 it87_write_value(data, IT87_REG_FAN_CTL,
1852 for (i = 0; i < 3; i++)
1853 it87_write_value(data,
1859 dev_info(dev, "PWM configuration is "
1860 "too broken to be fixed\n");
1863 dev_info(dev, "Detected broken BIOS "
1864 "defaults, disabling PWM interface\n");
1866 } else if (fix_pwm_polarity) {
1867 dev_info(dev, "PWM configuration looks "
1868 "sane, won't touch\n");
1874 /* Called when we have found a new IT87. */
1875 static void __devinit it87_init_device(struct platform_device *pdev)
1877 struct it87_sio_data *sio_data = pdev->dev.platform_data;
1878 struct it87_data *data = platform_get_drvdata(pdev);
1882 /* For each PWM channel:
1883 * - If it is in automatic mode, setting to manual mode should set
1884 * the fan to full speed by default.
1885 * - If it is in manual mode, we need a mapping to temperature
1886 * channels to use when later setting to automatic mode later.
1887 * Use a 1:1 mapping by default (we are clueless.)
1888 * In both cases, the value can (and should) be changed by the user
1889 * prior to switching to a different mode. */
1890 for (i = 0; i < 3; i++) {
1891 data->pwm_temp_map[i] = i;
1892 data->pwm_duty[i] = 0x7f; /* Full speed */
1893 data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */
1896 /* Some chips seem to have default value 0xff for all limit
1897 * registers. For low voltage limits it makes no sense and triggers
1898 * alarms, so change to 0 instead. For high temperature limits, it
1899 * means -1 degree C, which surprisingly doesn't trigger an alarm,
1900 * but is still confusing, so change to 127 degrees C. */
1901 for (i = 0; i < 8; i++) {
1902 tmp = it87_read_value(data, IT87_REG_VIN_MIN(i));
1904 it87_write_value(data, IT87_REG_VIN_MIN(i), 0);
1906 for (i = 0; i < 3; i++) {
1907 tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i));
1909 it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127);
1912 /* Temperature channels are not forcibly enabled, as they can be
1913 * set to two different sensor types and we can't guess which one
1914 * is correct for a given system. These channels can be enabled at
1915 * run-time through the temp{1-3}_type sysfs accessors if needed. */
1917 /* Check if voltage monitors are reset manually or by some reason */
1918 tmp = it87_read_value(data, IT87_REG_VIN_ENABLE);
1919 if ((tmp & 0xff) == 0) {
1920 /* Enable all voltage monitors */
1921 it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff);
1924 /* Check if tachometers are reset manually or by some reason */
1925 mask = 0x70 & ~(sio_data->skip_fan << 4);
1926 data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL);
1927 if ((data->fan_main_ctrl & mask) == 0) {
1928 /* Enable all fan tachometers */
1929 data->fan_main_ctrl |= mask;
1930 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
1931 data->fan_main_ctrl);
1933 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
1935 /* Set tachometers to 16-bit mode if needed */
1936 if (has_16bit_fans(data)) {
1937 tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
1938 if (~tmp & 0x07 & data->has_fan) {
1940 "Setting fan1-3 to 16-bit mode\n");
1941 it87_write_value(data, IT87_REG_FAN_16BIT,
1944 /* IT8705F only supports three fans. */
1945 if (data->type != it87) {
1947 data->has_fan |= (1 << 3); /* fan4 enabled */
1949 data->has_fan |= (1 << 4); /* fan5 enabled */
1953 /* Fan input pins may be used for alternative functions */
1954 data->has_fan &= ~sio_data->skip_fan;
1956 /* Start monitoring */
1957 it87_write_value(data, IT87_REG_CONFIG,
1958 (it87_read_value(data, IT87_REG_CONFIG) & 0x36)
1959 | (update_vbat ? 0x41 : 0x01));
1962 static void it87_update_pwm_ctrl(struct it87_data *data, int nr)
1964 data->pwm_ctrl[nr] = it87_read_value(data, IT87_REG_PWM(nr));
1965 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
1966 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
1967 else /* Manual mode */
1968 data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f;
1970 if (has_old_autopwm(data)) {
1973 for (i = 0; i < 5 ; i++)
1974 data->auto_temp[nr][i] = it87_read_value(data,
1975 IT87_REG_AUTO_TEMP(nr, i));
1976 for (i = 0; i < 3 ; i++)
1977 data->auto_pwm[nr][i] = it87_read_value(data,
1978 IT87_REG_AUTO_PWM(nr, i));
1982 static struct it87_data *it87_update_device(struct device *dev)
1984 struct it87_data *data = dev_get_drvdata(dev);
1987 mutex_lock(&data->update_lock);
1989 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
1992 /* Cleared after each update, so reenable. Value
1993 returned by this read will be previous value */
1994 it87_write_value(data, IT87_REG_CONFIG,
1995 it87_read_value(data, IT87_REG_CONFIG) | 0x40);
1997 for (i = 0; i <= 7; i++) {
1999 it87_read_value(data, IT87_REG_VIN(i));
2001 it87_read_value(data, IT87_REG_VIN_MIN(i));
2003 it87_read_value(data, IT87_REG_VIN_MAX(i));
2005 /* in8 (battery) has no limit registers */
2006 data->in[8] = it87_read_value(data, IT87_REG_VIN(8));
2008 for (i = 0; i < 5; i++) {
2009 /* Skip disabled fans */
2010 if (!(data->has_fan & (1 << i)))
2014 it87_read_value(data, IT87_REG_FAN_MIN[i]);
2015 data->fan[i] = it87_read_value(data,
2017 /* Add high byte if in 16-bit mode */
2018 if (has_16bit_fans(data)) {
2019 data->fan[i] |= it87_read_value(data,
2020 IT87_REG_FANX[i]) << 8;
2021 data->fan_min[i] |= it87_read_value(data,
2022 IT87_REG_FANX_MIN[i]) << 8;
2025 for (i = 0; i < 3; i++) {
2027 it87_read_value(data, IT87_REG_TEMP(i));
2028 data->temp_high[i] =
2029 it87_read_value(data, IT87_REG_TEMP_HIGH(i));
2031 it87_read_value(data, IT87_REG_TEMP_LOW(i));
2034 /* Newer chips don't have clock dividers */
2035 if ((data->has_fan & 0x07) && !has_16bit_fans(data)) {
2036 i = it87_read_value(data, IT87_REG_FAN_DIV);
2037 data->fan_div[0] = i & 0x07;
2038 data->fan_div[1] = (i >> 3) & 0x07;
2039 data->fan_div[2] = (i & 0x40) ? 3 : 1;
2043 it87_read_value(data, IT87_REG_ALARM1) |
2044 (it87_read_value(data, IT87_REG_ALARM2) << 8) |
2045 (it87_read_value(data, IT87_REG_ALARM3) << 16);
2046 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
2048 data->fan_main_ctrl = it87_read_value(data,
2049 IT87_REG_FAN_MAIN_CTRL);
2050 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL);
2051 for (i = 0; i < 3; i++)
2052 it87_update_pwm_ctrl(data, i);
2054 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
2055 /* The 8705 does not have VID capability.
2056 The 8718 and the 8720 don't use IT87_REG_VID for the
2058 if (data->type == it8712 || data->type == it8716) {
2059 data->vid = it87_read_value(data, IT87_REG_VID);
2060 /* The older IT8712F revisions had only 5 VID pins,
2061 but we assume it is always safe to read 6 bits. */
2064 data->last_updated = jiffies;
2068 mutex_unlock(&data->update_lock);
2073 static int __init it87_device_add(unsigned short address,
2074 const struct it87_sio_data *sio_data)
2076 struct resource res = {
2077 .start = address + IT87_EC_OFFSET,
2078 .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1,
2080 .flags = IORESOURCE_IO,
2084 err = acpi_check_resource_conflict(&res);
2088 pdev = platform_device_alloc(DRVNAME, address);
2091 printk(KERN_ERR DRVNAME ": Device allocation failed\n");
2095 err = platform_device_add_resources(pdev, &res, 1);
2097 printk(KERN_ERR DRVNAME ": Device resource addition failed "
2099 goto exit_device_put;
2102 err = platform_device_add_data(pdev, sio_data,
2103 sizeof(struct it87_sio_data));
2105 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n");
2106 goto exit_device_put;
2109 err = platform_device_add(pdev);
2111 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
2113 goto exit_device_put;
2119 platform_device_put(pdev);
2124 static int __init sm_it87_init(void)
2127 unsigned short isa_address = 0;
2128 struct it87_sio_data sio_data;
2130 memset(&sio_data, 0, sizeof(struct it87_sio_data));
2131 err = it87_find(&isa_address, &sio_data);
2134 err = platform_driver_register(&it87_driver);
2138 err = it87_device_add(isa_address, &sio_data);
2140 platform_driver_unregister(&it87_driver);
2147 static void __exit sm_it87_exit(void)
2149 platform_device_unregister(pdev);
2150 platform_driver_unregister(&it87_driver);
2154 MODULE_AUTHOR("Chris Gauthron, "
2155 "Jean Delvare <khali@linux-fr.org>");
2156 MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F/8720F/8726F, SiS950 driver");
2157 module_param(update_vbat, bool, 0);
2158 MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
2159 module_param(fix_pwm_polarity, bool, 0);
2160 MODULE_PARM_DESC(fix_pwm_polarity,
2161 "Force PWM polarity to active high (DANGEROUS)");
2162 MODULE_LICENSE("GPL");
2164 module_init(sm_it87_init);
2165 module_exit(sm_it87_exit);