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 IT8726F Super I/O chip w/LPC interface
18 Sis950 A clone of the IT8705F
20 Copyright (C) 2001 Chris Gauthron
21 Copyright (C) 2005-2006 Jean Delvare <khali@linux-fr.org>
23 This program is free software; you can redistribute it and/or modify
24 it under the terms of the GNU General Public License as published by
25 the Free Software Foundation; either version 2 of the License, or
26 (at your option) any later version.
28 This program is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 GNU General Public License for more details.
33 You should have received a copy of the GNU General Public License
34 along with this program; if not, write to the Free Software
35 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
38 #include <linux/module.h>
39 #include <linux/init.h>
40 #include <linux/slab.h>
41 #include <linux/jiffies.h>
42 #include <linux/platform_device.h>
43 #include <linux/hwmon.h>
44 #include <linux/hwmon-sysfs.h>
45 #include <linux/hwmon-vid.h>
46 #include <linux/err.h>
47 #include <linux/mutex.h>
48 #include <linux/sysfs.h>
51 #define DRVNAME "it87"
53 enum chips { it87, it8712, it8716, it8718 };
55 static unsigned short force_id;
56 module_param(force_id, ushort, 0);
57 MODULE_PARM_DESC(force_id, "Override the detected device ID");
59 static struct platform_device *pdev;
61 #define REG 0x2e /* The register to read/write */
62 #define DEV 0x07 /* Register: Logical device select */
63 #define VAL 0x2f /* The value to read/write */
64 #define PME 0x04 /* The device with the fan registers in it */
65 #define GPIO 0x07 /* The device with the IT8718F VID value in it */
66 #define DEVID 0x20 /* Register: Device ID */
67 #define DEVREV 0x22 /* Register: Device Revision */
76 static int superio_inw(int reg)
87 superio_select(int ldn)
109 /* Logical device 4 registers */
110 #define IT8712F_DEVID 0x8712
111 #define IT8705F_DEVID 0x8705
112 #define IT8716F_DEVID 0x8716
113 #define IT8718F_DEVID 0x8718
114 #define IT8726F_DEVID 0x8726
115 #define IT87_ACT_REG 0x30
116 #define IT87_BASE_REG 0x60
118 /* Logical device 7 registers (IT8712F and later) */
119 #define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
120 #define IT87_SIO_VID_REG 0xfc /* VID value */
122 /* Update battery voltage after every reading if true */
123 static int update_vbat;
125 /* Not all BIOSes properly configure the PWM registers */
126 static int fix_pwm_polarity;
128 /* Many IT87 constants specified below */
130 /* Length of ISA address segment */
131 #define IT87_EXTENT 8
133 /* Length of ISA address segment for Environmental Controller */
134 #define IT87_EC_EXTENT 2
136 /* Offset of EC registers from ISA base address */
137 #define IT87_EC_OFFSET 5
139 /* Where are the ISA address/data registers relative to the EC base address */
140 #define IT87_ADDR_REG_OFFSET 0
141 #define IT87_DATA_REG_OFFSET 1
143 /*----- The IT87 registers -----*/
145 #define IT87_REG_CONFIG 0x00
147 #define IT87_REG_ALARM1 0x01
148 #define IT87_REG_ALARM2 0x02
149 #define IT87_REG_ALARM3 0x03
151 /* The IT8718F has the VID value in a different register, in Super-I/O
152 configuration space. */
153 #define IT87_REG_VID 0x0a
154 /* Warning: register 0x0b is used for something completely different in
155 new chips/revisions. I suspect only 16-bit tachometer mode will work
157 #define IT87_REG_FAN_DIV 0x0b
158 #define IT87_REG_FAN_16BIT 0x0c
160 /* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */
162 static const u8 IT87_REG_FAN[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82 };
163 static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86 };
164 static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83 };
165 static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 };
166 #define IT87_REG_FAN_MAIN_CTRL 0x13
167 #define IT87_REG_FAN_CTL 0x14
168 #define IT87_REG_PWM(nr) (0x15 + (nr))
170 #define IT87_REG_VIN(nr) (0x20 + (nr))
171 #define IT87_REG_TEMP(nr) (0x29 + (nr))
173 #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2)
174 #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2)
175 #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2)
176 #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2)
178 #define IT87_REG_VIN_ENABLE 0x50
179 #define IT87_REG_TEMP_ENABLE 0x51
181 #define IT87_REG_CHIPID 0x58
183 #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255))
184 #define IN_FROM_REG(val) ((val) * 16)
186 static inline u8 FAN_TO_REG(long rpm, int div)
190 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
191 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1,
195 static inline u16 FAN16_TO_REG(long rpm)
199 return SENSORS_LIMIT((1350000 + rpm) / (rpm * 2), 1, 0xfffe);
202 #define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div)))
203 /* The divider is fixed to 2 in 16-bit mode */
204 #define FAN16_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:1350000/((val)*2))
206 #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\
207 ((val)+500)/1000),-128,127))
208 #define TEMP_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*1000)
210 #define PWM_TO_REG(val) ((val) >> 1)
211 #define PWM_FROM_REG(val) (((val)&0x7f) << 1)
213 static int DIV_TO_REG(int val)
216 while (answer < 7 && (val >>= 1))
220 #define DIV_FROM_REG(val) (1 << (val))
222 static const unsigned int pwm_freq[8] = {
234 struct it87_sio_data {
236 /* Values read from Super-I/O config space */
240 /* For each registered chip, we need to keep some data in memory.
241 The structure is dynamically allocated. */
243 struct device *hwmon_dev;
248 struct mutex update_lock;
249 char valid; /* !=0 if following fields are valid */
250 unsigned long last_updated; /* In jiffies */
252 u8 in[9]; /* Register value */
253 u8 in_max[8]; /* Register value */
254 u8 in_min[8]; /* Register value */
255 u8 has_fan; /* Bitfield, fans enabled */
256 u16 fan[5]; /* Register values, possibly combined */
257 u16 fan_min[5]; /* Register values, possibly combined */
258 u8 temp[3]; /* Register value */
259 u8 temp_high[3]; /* Register value */
260 u8 temp_low[3]; /* Register value */
261 u8 sensor; /* Register value */
262 u8 fan_div[3]; /* Register encoding, shifted right */
263 u8 vid; /* Register encoding, combined */
265 u32 alarms; /* Register encoding, combined */
266 u8 fan_main_ctrl; /* Register value */
267 u8 fan_ctl; /* Register value */
268 u8 manual_pwm_ctl[3]; /* manual PWM value set by user */
272 static int it87_probe(struct platform_device *pdev);
273 static int __devexit it87_remove(struct platform_device *pdev);
275 static int it87_read_value(struct it87_data *data, u8 reg);
276 static void it87_write_value(struct it87_data *data, u8 reg, u8 value);
277 static struct it87_data *it87_update_device(struct device *dev);
278 static int it87_check_pwm(struct device *dev);
279 static void it87_init_device(struct platform_device *pdev);
282 static struct platform_driver it87_driver = {
284 .owner = THIS_MODULE,
288 .remove = __devexit_p(it87_remove),
291 static ssize_t show_in(struct device *dev, struct device_attribute *attr,
294 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
295 int nr = sensor_attr->index;
297 struct it87_data *data = it87_update_device(dev);
298 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr]));
301 static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
304 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
305 int nr = sensor_attr->index;
307 struct it87_data *data = it87_update_device(dev);
308 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr]));
311 static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
314 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
315 int nr = sensor_attr->index;
317 struct it87_data *data = it87_update_device(dev);
318 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr]));
321 static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
322 const char *buf, size_t count)
324 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
325 int nr = sensor_attr->index;
327 struct it87_data *data = dev_get_drvdata(dev);
328 unsigned long val = simple_strtoul(buf, NULL, 10);
330 mutex_lock(&data->update_lock);
331 data->in_min[nr] = IN_TO_REG(val);
332 it87_write_value(data, IT87_REG_VIN_MIN(nr),
334 mutex_unlock(&data->update_lock);
337 static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
338 const char *buf, size_t count)
340 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
341 int nr = sensor_attr->index;
343 struct it87_data *data = dev_get_drvdata(dev);
344 unsigned long val = simple_strtoul(buf, NULL, 10);
346 mutex_lock(&data->update_lock);
347 data->in_max[nr] = IN_TO_REG(val);
348 it87_write_value(data, IT87_REG_VIN_MAX(nr),
350 mutex_unlock(&data->update_lock);
354 #define show_in_offset(offset) \
355 static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
356 show_in, NULL, offset);
358 #define limit_in_offset(offset) \
359 static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
360 show_in_min, set_in_min, offset); \
361 static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
362 show_in_max, set_in_max, offset);
383 static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
386 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
387 int nr = sensor_attr->index;
389 struct it87_data *data = it87_update_device(dev);
390 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr]));
392 static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
395 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
396 int nr = sensor_attr->index;
398 struct it87_data *data = it87_update_device(dev);
399 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr]));
401 static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
404 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
405 int nr = sensor_attr->index;
407 struct it87_data *data = it87_update_device(dev);
408 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[nr]));
410 static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
411 const char *buf, size_t count)
413 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
414 int nr = sensor_attr->index;
416 struct it87_data *data = dev_get_drvdata(dev);
417 int val = simple_strtol(buf, NULL, 10);
419 mutex_lock(&data->update_lock);
420 data->temp_high[nr] = TEMP_TO_REG(val);
421 it87_write_value(data, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]);
422 mutex_unlock(&data->update_lock);
425 static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
426 const char *buf, size_t count)
428 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
429 int nr = sensor_attr->index;
431 struct it87_data *data = dev_get_drvdata(dev);
432 int val = simple_strtol(buf, NULL, 10);
434 mutex_lock(&data->update_lock);
435 data->temp_low[nr] = TEMP_TO_REG(val);
436 it87_write_value(data, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]);
437 mutex_unlock(&data->update_lock);
440 #define show_temp_offset(offset) \
441 static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
442 show_temp, NULL, offset - 1); \
443 static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
444 show_temp_max, set_temp_max, offset - 1); \
445 static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
446 show_temp_min, set_temp_min, offset - 1);
452 static ssize_t show_sensor(struct device *dev, struct device_attribute *attr,
455 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
456 int nr = sensor_attr->index;
458 struct it87_data *data = it87_update_device(dev);
459 u8 reg = data->sensor; /* In case the value is updated while we use it */
462 return sprintf(buf, "3\n"); /* thermal diode */
464 return sprintf(buf, "2\n"); /* thermistor */
465 return sprintf(buf, "0\n"); /* disabled */
467 static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,
468 const char *buf, size_t count)
470 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
471 int nr = sensor_attr->index;
473 struct it87_data *data = dev_get_drvdata(dev);
474 int val = simple_strtol(buf, NULL, 10);
476 mutex_lock(&data->update_lock);
478 data->sensor &= ~(1 << nr);
479 data->sensor &= ~(8 << nr);
480 /* 3 = thermal diode; 2 = thermistor; 0 = disabled */
482 data->sensor |= 1 << nr;
484 data->sensor |= 8 << nr;
486 mutex_unlock(&data->update_lock);
489 it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor);
490 mutex_unlock(&data->update_lock);
493 #define show_sensor_offset(offset) \
494 static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \
495 show_sensor, set_sensor, offset - 1);
497 show_sensor_offset(1);
498 show_sensor_offset(2);
499 show_sensor_offset(3);
502 static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
505 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
506 int nr = sensor_attr->index;
508 struct it87_data *data = it87_update_device(dev);
509 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
510 DIV_FROM_REG(data->fan_div[nr])));
512 static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
515 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
516 int nr = sensor_attr->index;
518 struct it87_data *data = it87_update_device(dev);
519 return sprintf(buf,"%d\n",
520 FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])));
522 static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
525 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
526 int nr = sensor_attr->index;
528 struct it87_data *data = it87_update_device(dev);
529 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
531 static ssize_t show_pwm_enable(struct device *dev, struct device_attribute *attr,
534 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
535 int nr = sensor_attr->index;
537 struct it87_data *data = it87_update_device(dev);
538 return sprintf(buf,"%d\n", (data->fan_main_ctrl & (1 << nr)) ? 1 : 0);
540 static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
543 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
544 int nr = sensor_attr->index;
546 struct it87_data *data = it87_update_device(dev);
547 return sprintf(buf,"%d\n", data->manual_pwm_ctl[nr]);
549 static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
552 struct it87_data *data = it87_update_device(dev);
553 int index = (data->fan_ctl >> 4) & 0x07;
555 return sprintf(buf, "%u\n", pwm_freq[index]);
557 static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
558 const char *buf, size_t count)
560 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
561 int nr = sensor_attr->index;
563 struct it87_data *data = dev_get_drvdata(dev);
564 int val = simple_strtol(buf, NULL, 10);
567 mutex_lock(&data->update_lock);
568 reg = it87_read_value(data, IT87_REG_FAN_DIV);
570 case 0: data->fan_div[nr] = reg & 0x07; break;
571 case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break;
572 case 2: data->fan_div[nr] = (reg & 0x40) ? 3 : 1; break;
575 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
576 it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]);
577 mutex_unlock(&data->update_lock);
580 static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
581 const char *buf, size_t count)
583 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
584 int nr = sensor_attr->index;
586 struct it87_data *data = dev_get_drvdata(dev);
587 unsigned long val = simple_strtoul(buf, NULL, 10);
591 mutex_lock(&data->update_lock);
592 old = it87_read_value(data, IT87_REG_FAN_DIV);
594 /* Save fan min limit */
595 min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]));
600 data->fan_div[nr] = DIV_TO_REG(val);
604 data->fan_div[nr] = 1;
606 data->fan_div[nr] = 3;
609 val |= (data->fan_div[0] & 0x07);
610 val |= (data->fan_div[1] & 0x07) << 3;
611 if (data->fan_div[2] == 3)
613 it87_write_value(data, IT87_REG_FAN_DIV, val);
615 /* Restore fan min limit */
616 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
617 it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]);
619 mutex_unlock(&data->update_lock);
622 static ssize_t set_pwm_enable(struct device *dev,
623 struct device_attribute *attr, const char *buf, size_t count)
625 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
626 int nr = sensor_attr->index;
628 struct it87_data *data = dev_get_drvdata(dev);
629 int val = simple_strtol(buf, NULL, 10);
631 mutex_lock(&data->update_lock);
635 /* make sure the fan is on when in on/off mode */
636 tmp = it87_read_value(data, IT87_REG_FAN_CTL);
637 it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr));
638 /* set on/off mode */
639 data->fan_main_ctrl &= ~(1 << nr);
640 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
641 } else if (val == 1) {
642 /* set SmartGuardian mode */
643 data->fan_main_ctrl |= (1 << nr);
644 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
645 /* set saved pwm value, clear FAN_CTLX PWM mode bit */
646 it87_write_value(data, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr]));
648 mutex_unlock(&data->update_lock);
652 mutex_unlock(&data->update_lock);
655 static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
656 const char *buf, size_t count)
658 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
659 int nr = sensor_attr->index;
661 struct it87_data *data = dev_get_drvdata(dev);
662 int val = simple_strtol(buf, NULL, 10);
664 if (val < 0 || val > 255)
667 mutex_lock(&data->update_lock);
668 data->manual_pwm_ctl[nr] = val;
669 if (data->fan_main_ctrl & (1 << nr))
670 it87_write_value(data, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr]));
671 mutex_unlock(&data->update_lock);
674 static ssize_t set_pwm_freq(struct device *dev,
675 struct device_attribute *attr, const char *buf, size_t count)
677 struct it87_data *data = dev_get_drvdata(dev);
678 unsigned long val = simple_strtoul(buf, NULL, 10);
681 /* Search for the nearest available frequency */
682 for (i = 0; i < 7; i++) {
683 if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2)
687 mutex_lock(&data->update_lock);
688 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f;
689 data->fan_ctl |= i << 4;
690 it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl);
691 mutex_unlock(&data->update_lock);
696 #define show_fan_offset(offset) \
697 static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
698 show_fan, NULL, offset - 1); \
699 static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
700 show_fan_min, set_fan_min, offset - 1); \
701 static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
702 show_fan_div, set_fan_div, offset - 1);
708 #define show_pwm_offset(offset) \
709 static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
710 show_pwm_enable, set_pwm_enable, offset - 1); \
711 static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
712 show_pwm, set_pwm, offset - 1); \
713 static DEVICE_ATTR(pwm##offset##_freq, \
714 (offset == 1 ? S_IRUGO | S_IWUSR : S_IRUGO), \
715 show_pwm_freq, (offset == 1 ? set_pwm_freq : NULL));
721 /* A different set of callbacks for 16-bit fans */
722 static ssize_t show_fan16(struct device *dev, struct device_attribute *attr,
725 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
726 int nr = sensor_attr->index;
727 struct it87_data *data = it87_update_device(dev);
728 return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan[nr]));
731 static ssize_t show_fan16_min(struct device *dev, struct device_attribute *attr,
734 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
735 int nr = sensor_attr->index;
736 struct it87_data *data = it87_update_device(dev);
737 return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan_min[nr]));
740 static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr,
741 const char *buf, size_t count)
743 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
744 int nr = sensor_attr->index;
745 struct it87_data *data = dev_get_drvdata(dev);
746 int val = simple_strtol(buf, NULL, 10);
748 mutex_lock(&data->update_lock);
749 data->fan_min[nr] = FAN16_TO_REG(val);
750 it87_write_value(data, IT87_REG_FAN_MIN[nr],
751 data->fan_min[nr] & 0xff);
752 it87_write_value(data, IT87_REG_FANX_MIN[nr],
753 data->fan_min[nr] >> 8);
754 mutex_unlock(&data->update_lock);
758 /* We want to use the same sysfs file names as 8-bit fans, but we need
759 different variable names, so we have to use SENSOR_ATTR instead of
760 SENSOR_DEVICE_ATTR. */
761 #define show_fan16_offset(offset) \
762 static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \
763 = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \
764 show_fan16, NULL, offset - 1); \
765 static struct sensor_device_attribute sensor_dev_attr_fan##offset##_min16 \
766 = SENSOR_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
767 show_fan16_min, set_fan16_min, offset - 1)
769 show_fan16_offset(1);
770 show_fan16_offset(2);
771 show_fan16_offset(3);
772 show_fan16_offset(4);
773 show_fan16_offset(5);
776 static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
778 struct it87_data *data = it87_update_device(dev);
779 return sprintf(buf, "%u\n", data->alarms);
781 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
784 show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
786 struct it87_data *data = dev_get_drvdata(dev);
787 return sprintf(buf, "%u\n", data->vrm);
790 store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
792 struct it87_data *data = dev_get_drvdata(dev);
795 val = simple_strtoul(buf, NULL, 10);
800 static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
803 show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
805 struct it87_data *data = it87_update_device(dev);
806 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
808 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
810 static ssize_t show_name(struct device *dev, struct device_attribute
813 struct it87_data *data = dev_get_drvdata(dev);
814 return sprintf(buf, "%s\n", data->name);
816 static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
818 static struct attribute *it87_attributes[] = {
819 &sensor_dev_attr_in0_input.dev_attr.attr,
820 &sensor_dev_attr_in1_input.dev_attr.attr,
821 &sensor_dev_attr_in2_input.dev_attr.attr,
822 &sensor_dev_attr_in3_input.dev_attr.attr,
823 &sensor_dev_attr_in4_input.dev_attr.attr,
824 &sensor_dev_attr_in5_input.dev_attr.attr,
825 &sensor_dev_attr_in6_input.dev_attr.attr,
826 &sensor_dev_attr_in7_input.dev_attr.attr,
827 &sensor_dev_attr_in8_input.dev_attr.attr,
828 &sensor_dev_attr_in0_min.dev_attr.attr,
829 &sensor_dev_attr_in1_min.dev_attr.attr,
830 &sensor_dev_attr_in2_min.dev_attr.attr,
831 &sensor_dev_attr_in3_min.dev_attr.attr,
832 &sensor_dev_attr_in4_min.dev_attr.attr,
833 &sensor_dev_attr_in5_min.dev_attr.attr,
834 &sensor_dev_attr_in6_min.dev_attr.attr,
835 &sensor_dev_attr_in7_min.dev_attr.attr,
836 &sensor_dev_attr_in0_max.dev_attr.attr,
837 &sensor_dev_attr_in1_max.dev_attr.attr,
838 &sensor_dev_attr_in2_max.dev_attr.attr,
839 &sensor_dev_attr_in3_max.dev_attr.attr,
840 &sensor_dev_attr_in4_max.dev_attr.attr,
841 &sensor_dev_attr_in5_max.dev_attr.attr,
842 &sensor_dev_attr_in6_max.dev_attr.attr,
843 &sensor_dev_attr_in7_max.dev_attr.attr,
845 &sensor_dev_attr_temp1_input.dev_attr.attr,
846 &sensor_dev_attr_temp2_input.dev_attr.attr,
847 &sensor_dev_attr_temp3_input.dev_attr.attr,
848 &sensor_dev_attr_temp1_max.dev_attr.attr,
849 &sensor_dev_attr_temp2_max.dev_attr.attr,
850 &sensor_dev_attr_temp3_max.dev_attr.attr,
851 &sensor_dev_attr_temp1_min.dev_attr.attr,
852 &sensor_dev_attr_temp2_min.dev_attr.attr,
853 &sensor_dev_attr_temp3_min.dev_attr.attr,
854 &sensor_dev_attr_temp1_type.dev_attr.attr,
855 &sensor_dev_attr_temp2_type.dev_attr.attr,
856 &sensor_dev_attr_temp3_type.dev_attr.attr,
858 &dev_attr_alarms.attr,
863 static const struct attribute_group it87_group = {
864 .attrs = it87_attributes,
867 static struct attribute *it87_attributes_opt[] = {
868 &sensor_dev_attr_fan1_input16.dev_attr.attr,
869 &sensor_dev_attr_fan1_min16.dev_attr.attr,
870 &sensor_dev_attr_fan2_input16.dev_attr.attr,
871 &sensor_dev_attr_fan2_min16.dev_attr.attr,
872 &sensor_dev_attr_fan3_input16.dev_attr.attr,
873 &sensor_dev_attr_fan3_min16.dev_attr.attr,
874 &sensor_dev_attr_fan4_input16.dev_attr.attr,
875 &sensor_dev_attr_fan4_min16.dev_attr.attr,
876 &sensor_dev_attr_fan5_input16.dev_attr.attr,
877 &sensor_dev_attr_fan5_min16.dev_attr.attr,
879 &sensor_dev_attr_fan1_input.dev_attr.attr,
880 &sensor_dev_attr_fan1_min.dev_attr.attr,
881 &sensor_dev_attr_fan1_div.dev_attr.attr,
882 &sensor_dev_attr_fan2_input.dev_attr.attr,
883 &sensor_dev_attr_fan2_min.dev_attr.attr,
884 &sensor_dev_attr_fan2_div.dev_attr.attr,
885 &sensor_dev_attr_fan3_input.dev_attr.attr,
886 &sensor_dev_attr_fan3_min.dev_attr.attr,
887 &sensor_dev_attr_fan3_div.dev_attr.attr,
889 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
890 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
891 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
892 &sensor_dev_attr_pwm1.dev_attr.attr,
893 &sensor_dev_attr_pwm2.dev_attr.attr,
894 &sensor_dev_attr_pwm3.dev_attr.attr,
897 &dev_attr_cpu0_vid.attr,
901 static const struct attribute_group it87_group_opt = {
902 .attrs = it87_attributes_opt,
905 /* SuperIO detection - will change isa_address if a chip is found */
906 static int __init it87_find(unsigned short *address,
907 struct it87_sio_data *sio_data)
913 chip_type = force_id ? force_id : superio_inw(DEVID);
917 sio_data->type = it87;
920 sio_data->type = it8712;
924 sio_data->type = it8716;
927 sio_data->type = it8718;
929 case 0xffff: /* No device at all */
932 pr_debug(DRVNAME ": Unsupported chip (DEVID=0x%x)\n",
938 if (!(superio_inb(IT87_ACT_REG) & 0x01)) {
939 pr_info("it87: Device not activated, skipping\n");
943 *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1);
945 pr_info("it87: Base address not set, skipping\n");
950 pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n",
951 chip_type, *address, superio_inb(DEVREV) & 0x0f);
953 /* Read GPIO config and VID value from LDN 7 (GPIO) */
954 if (chip_type != IT8705F_DEVID) {
957 superio_select(GPIO);
958 if (chip_type == it8718)
959 sio_data->vid_value = superio_inb(IT87_SIO_VID_REG);
961 reg = superio_inb(IT87_SIO_PINX2_REG);
963 pr_info("it87: in3 is VCC (+5V)\n");
965 pr_info("it87: in7 is VCCH (+5V Stand-By)\n");
973 static int __devinit it87_probe(struct platform_device *pdev)
975 struct it87_data *data;
976 struct resource *res;
977 struct device *dev = &pdev->dev;
978 struct it87_sio_data *sio_data = dev->platform_data;
980 int enable_pwm_interface;
981 static const char *names[] = {
988 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
989 if (!request_region(res->start, IT87_EC_EXTENT, DRVNAME)) {
990 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
991 (unsigned long)res->start,
992 (unsigned long)(res->start + IT87_EC_EXTENT - 1));
997 if (!(data = kzalloc(sizeof(struct it87_data), GFP_KERNEL))) {
1002 data->addr = res->start;
1003 data->type = sio_data->type;
1004 data->name = names[sio_data->type];
1006 /* Now, we do the remaining detection. */
1007 if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80)
1008 || it87_read_value(data, IT87_REG_CHIPID) != 0x90) {
1013 platform_set_drvdata(pdev, data);
1015 mutex_init(&data->update_lock);
1017 /* Check PWM configuration */
1018 enable_pwm_interface = it87_check_pwm(dev);
1020 /* Initialize the IT87 chip */
1021 it87_init_device(pdev);
1023 /* Register sysfs hooks */
1024 if ((err = sysfs_create_group(&dev->kobj, &it87_group)))
1027 /* Do not create fan files for disabled fans */
1028 if (data->type == it8716 || data->type == it8718) {
1029 /* 16-bit tachometers */
1030 if (data->has_fan & (1 << 0)) {
1031 if ((err = device_create_file(dev,
1032 &sensor_dev_attr_fan1_input16.dev_attr))
1033 || (err = device_create_file(dev,
1034 &sensor_dev_attr_fan1_min16.dev_attr)))
1037 if (data->has_fan & (1 << 1)) {
1038 if ((err = device_create_file(dev,
1039 &sensor_dev_attr_fan2_input16.dev_attr))
1040 || (err = device_create_file(dev,
1041 &sensor_dev_attr_fan2_min16.dev_attr)))
1044 if (data->has_fan & (1 << 2)) {
1045 if ((err = device_create_file(dev,
1046 &sensor_dev_attr_fan3_input16.dev_attr))
1047 || (err = device_create_file(dev,
1048 &sensor_dev_attr_fan3_min16.dev_attr)))
1051 if (data->has_fan & (1 << 3)) {
1052 if ((err = device_create_file(dev,
1053 &sensor_dev_attr_fan4_input16.dev_attr))
1054 || (err = device_create_file(dev,
1055 &sensor_dev_attr_fan4_min16.dev_attr)))
1058 if (data->has_fan & (1 << 4)) {
1059 if ((err = device_create_file(dev,
1060 &sensor_dev_attr_fan5_input16.dev_attr))
1061 || (err = device_create_file(dev,
1062 &sensor_dev_attr_fan5_min16.dev_attr)))
1066 /* 8-bit tachometers with clock divider */
1067 if (data->has_fan & (1 << 0)) {
1068 if ((err = device_create_file(dev,
1069 &sensor_dev_attr_fan1_input.dev_attr))
1070 || (err = device_create_file(dev,
1071 &sensor_dev_attr_fan1_min.dev_attr))
1072 || (err = device_create_file(dev,
1073 &sensor_dev_attr_fan1_div.dev_attr)))
1076 if (data->has_fan & (1 << 1)) {
1077 if ((err = device_create_file(dev,
1078 &sensor_dev_attr_fan2_input.dev_attr))
1079 || (err = device_create_file(dev,
1080 &sensor_dev_attr_fan2_min.dev_attr))
1081 || (err = device_create_file(dev,
1082 &sensor_dev_attr_fan2_div.dev_attr)))
1085 if (data->has_fan & (1 << 2)) {
1086 if ((err = device_create_file(dev,
1087 &sensor_dev_attr_fan3_input.dev_attr))
1088 || (err = device_create_file(dev,
1089 &sensor_dev_attr_fan3_min.dev_attr))
1090 || (err = device_create_file(dev,
1091 &sensor_dev_attr_fan3_div.dev_attr)))
1096 if (enable_pwm_interface) {
1097 if ((err = device_create_file(dev,
1098 &sensor_dev_attr_pwm1_enable.dev_attr))
1099 || (err = device_create_file(dev,
1100 &sensor_dev_attr_pwm2_enable.dev_attr))
1101 || (err = device_create_file(dev,
1102 &sensor_dev_attr_pwm3_enable.dev_attr))
1103 || (err = device_create_file(dev,
1104 &sensor_dev_attr_pwm1.dev_attr))
1105 || (err = device_create_file(dev,
1106 &sensor_dev_attr_pwm2.dev_attr))
1107 || (err = device_create_file(dev,
1108 &sensor_dev_attr_pwm3.dev_attr))
1109 || (err = device_create_file(dev,
1110 &dev_attr_pwm1_freq))
1111 || (err = device_create_file(dev,
1112 &dev_attr_pwm2_freq))
1113 || (err = device_create_file(dev,
1114 &dev_attr_pwm3_freq)))
1118 if (data->type == it8712 || data->type == it8716
1119 || data->type == it8718) {
1120 data->vrm = vid_which_vrm();
1121 /* VID reading from Super-I/O config space if available */
1122 data->vid = sio_data->vid_value;
1123 if ((err = device_create_file(dev,
1125 || (err = device_create_file(dev,
1126 &dev_attr_cpu0_vid)))
1130 data->hwmon_dev = hwmon_device_register(dev);
1131 if (IS_ERR(data->hwmon_dev)) {
1132 err = PTR_ERR(data->hwmon_dev);
1139 sysfs_remove_group(&dev->kobj, &it87_group);
1140 sysfs_remove_group(&dev->kobj, &it87_group_opt);
1142 platform_set_drvdata(pdev, NULL);
1145 release_region(res->start, IT87_EC_EXTENT);
1150 static int __devexit it87_remove(struct platform_device *pdev)
1152 struct it87_data *data = platform_get_drvdata(pdev);
1154 hwmon_device_unregister(data->hwmon_dev);
1155 sysfs_remove_group(&pdev->dev.kobj, &it87_group);
1156 sysfs_remove_group(&pdev->dev.kobj, &it87_group_opt);
1158 release_region(data->addr, IT87_EC_EXTENT);
1159 platform_set_drvdata(pdev, NULL);
1165 /* Must be called with data->update_lock held, except during initialization.
1166 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1167 would slow down the IT87 access and should not be necessary. */
1168 static int it87_read_value(struct it87_data *data, u8 reg)
1170 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
1171 return inb_p(data->addr + IT87_DATA_REG_OFFSET);
1174 /* Must be called with data->update_lock held, except during initialization.
1175 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1176 would slow down the IT87 access and should not be necessary. */
1177 static void it87_write_value(struct it87_data *data, u8 reg, u8 value)
1179 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
1180 outb_p(value, data->addr + IT87_DATA_REG_OFFSET);
1183 /* Return 1 if and only if the PWM interface is safe to use */
1184 static int __devinit it87_check_pwm(struct device *dev)
1186 struct it87_data *data = dev_get_drvdata(dev);
1187 /* Some BIOSes fail to correctly configure the IT87 fans. All fans off
1188 * and polarity set to active low is sign that this is the case so we
1189 * disable pwm control to protect the user. */
1190 int tmp = it87_read_value(data, IT87_REG_FAN_CTL);
1191 if ((tmp & 0x87) == 0) {
1192 if (fix_pwm_polarity) {
1193 /* The user asks us to attempt a chip reconfiguration.
1194 * This means switching to active high polarity and
1195 * inverting all fan speed values. */
1199 for (i = 0; i < 3; i++)
1200 pwm[i] = it87_read_value(data,
1203 /* If any fan is in automatic pwm mode, the polarity
1204 * might be correct, as suspicious as it seems, so we
1205 * better don't change anything (but still disable the
1206 * PWM interface). */
1207 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
1208 dev_info(dev, "Reconfiguring PWM to "
1209 "active high polarity\n");
1210 it87_write_value(data, IT87_REG_FAN_CTL,
1212 for (i = 0; i < 3; i++)
1213 it87_write_value(data,
1219 dev_info(dev, "PWM configuration is "
1220 "too broken to be fixed\n");
1223 dev_info(dev, "Detected broken BIOS "
1224 "defaults, disabling PWM interface\n");
1226 } else if (fix_pwm_polarity) {
1227 dev_info(dev, "PWM configuration looks "
1228 "sane, won't touch\n");
1234 /* Called when we have found a new IT87. */
1235 static void __devinit it87_init_device(struct platform_device *pdev)
1237 struct it87_data *data = platform_get_drvdata(pdev);
1240 /* initialize to sane defaults:
1241 * - if the chip is in manual pwm mode, this will be overwritten with
1242 * the actual settings on the chip (so in this case, initialization
1244 * - if in automatic or on/off mode, we could switch to manual mode,
1245 * read the registers and set manual_pwm_ctl accordingly, but currently
1246 * this is not implemented, so we initialize to something sane */
1247 for (i = 0; i < 3; i++) {
1248 data->manual_pwm_ctl[i] = 0xff;
1251 /* Some chips seem to have default value 0xff for all limit
1252 * registers. For low voltage limits it makes no sense and triggers
1253 * alarms, so change to 0 instead. For high temperature limits, it
1254 * means -1 degree C, which surprisingly doesn't trigger an alarm,
1255 * but is still confusing, so change to 127 degrees C. */
1256 for (i = 0; i < 8; i++) {
1257 tmp = it87_read_value(data, IT87_REG_VIN_MIN(i));
1259 it87_write_value(data, IT87_REG_VIN_MIN(i), 0);
1261 for (i = 0; i < 3; i++) {
1262 tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i));
1264 it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127);
1267 /* Check if temperature channnels are reset manually or by some reason */
1268 tmp = it87_read_value(data, IT87_REG_TEMP_ENABLE);
1269 if ((tmp & 0x3f) == 0) {
1270 /* Temp1,Temp3=thermistor; Temp2=thermal diode */
1271 tmp = (tmp & 0xc0) | 0x2a;
1272 it87_write_value(data, IT87_REG_TEMP_ENABLE, tmp);
1276 /* Check if voltage monitors are reset manually or by some reason */
1277 tmp = it87_read_value(data, IT87_REG_VIN_ENABLE);
1278 if ((tmp & 0xff) == 0) {
1279 /* Enable all voltage monitors */
1280 it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff);
1283 /* Check if tachometers are reset manually or by some reason */
1284 data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL);
1285 if ((data->fan_main_ctrl & 0x70) == 0) {
1286 /* Enable all fan tachometers */
1287 data->fan_main_ctrl |= 0x70;
1288 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
1290 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
1292 /* Set tachometers to 16-bit mode if needed */
1293 if (data->type == it8716 || data->type == it8718) {
1294 tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
1295 if (~tmp & 0x07 & data->has_fan) {
1297 "Setting fan1-3 to 16-bit mode\n");
1298 it87_write_value(data, IT87_REG_FAN_16BIT,
1302 data->has_fan |= (1 << 3); /* fan4 enabled */
1304 data->has_fan |= (1 << 4); /* fan5 enabled */
1307 /* Set current fan mode registers and the default settings for the
1308 * other mode registers */
1309 for (i = 0; i < 3; i++) {
1310 if (data->fan_main_ctrl & (1 << i)) {
1312 tmp = it87_read_value(data, IT87_REG_PWM(i));
1314 /* automatic pwm - not yet implemented, but
1315 * leave the settings made by the BIOS alone
1316 * until a change is requested via the sysfs
1320 data->manual_pwm_ctl[i] = PWM_FROM_REG(tmp);
1325 /* Start monitoring */
1326 it87_write_value(data, IT87_REG_CONFIG,
1327 (it87_read_value(data, IT87_REG_CONFIG) & 0x36)
1328 | (update_vbat ? 0x41 : 0x01));
1331 static struct it87_data *it87_update_device(struct device *dev)
1333 struct it87_data *data = dev_get_drvdata(dev);
1336 mutex_lock(&data->update_lock);
1338 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
1342 /* Cleared after each update, so reenable. Value
1343 returned by this read will be previous value */
1344 it87_write_value(data, IT87_REG_CONFIG,
1345 it87_read_value(data, IT87_REG_CONFIG) | 0x40);
1347 for (i = 0; i <= 7; i++) {
1349 it87_read_value(data, IT87_REG_VIN(i));
1351 it87_read_value(data, IT87_REG_VIN_MIN(i));
1353 it87_read_value(data, IT87_REG_VIN_MAX(i));
1355 /* in8 (battery) has no limit registers */
1357 it87_read_value(data, IT87_REG_VIN(8));
1359 for (i = 0; i < 5; i++) {
1360 /* Skip disabled fans */
1361 if (!(data->has_fan & (1 << i)))
1365 it87_read_value(data, IT87_REG_FAN_MIN[i]);
1366 data->fan[i] = it87_read_value(data,
1368 /* Add high byte if in 16-bit mode */
1369 if (data->type == it8716 || data->type == it8718) {
1370 data->fan[i] |= it87_read_value(data,
1371 IT87_REG_FANX[i]) << 8;
1372 data->fan_min[i] |= it87_read_value(data,
1373 IT87_REG_FANX_MIN[i]) << 8;
1376 for (i = 0; i < 3; i++) {
1378 it87_read_value(data, IT87_REG_TEMP(i));
1379 data->temp_high[i] =
1380 it87_read_value(data, IT87_REG_TEMP_HIGH(i));
1382 it87_read_value(data, IT87_REG_TEMP_LOW(i));
1385 /* Newer chips don't have clock dividers */
1386 if ((data->has_fan & 0x07) && data->type != it8716
1387 && data->type != it8718) {
1388 i = it87_read_value(data, IT87_REG_FAN_DIV);
1389 data->fan_div[0] = i & 0x07;
1390 data->fan_div[1] = (i >> 3) & 0x07;
1391 data->fan_div[2] = (i & 0x40) ? 3 : 1;
1395 it87_read_value(data, IT87_REG_ALARM1) |
1396 (it87_read_value(data, IT87_REG_ALARM2) << 8) |
1397 (it87_read_value(data, IT87_REG_ALARM3) << 16);
1398 data->fan_main_ctrl = it87_read_value(data,
1399 IT87_REG_FAN_MAIN_CTRL);
1400 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL);
1402 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
1403 /* The 8705 does not have VID capability */
1404 if (data->type == it8712 || data->type == it8716) {
1405 data->vid = it87_read_value(data, IT87_REG_VID);
1406 /* The older IT8712F revisions had only 5 VID pins,
1407 but we assume it is always safe to read 6 bits. */
1410 data->last_updated = jiffies;
1414 mutex_unlock(&data->update_lock);
1419 static int __init it87_device_add(unsigned short address,
1420 const struct it87_sio_data *sio_data)
1422 struct resource res = {
1423 .start = address + IT87_EC_OFFSET,
1424 .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1,
1426 .flags = IORESOURCE_IO,
1430 pdev = platform_device_alloc(DRVNAME, address);
1433 printk(KERN_ERR DRVNAME ": Device allocation failed\n");
1437 err = platform_device_add_resources(pdev, &res, 1);
1439 printk(KERN_ERR DRVNAME ": Device resource addition failed "
1441 goto exit_device_put;
1444 err = platform_device_add_data(pdev, sio_data,
1445 sizeof(struct it87_sio_data));
1447 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n");
1448 goto exit_device_put;
1451 err = platform_device_add(pdev);
1453 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
1455 goto exit_device_put;
1461 platform_device_put(pdev);
1466 static int __init sm_it87_init(void)
1469 unsigned short isa_address=0;
1470 struct it87_sio_data sio_data;
1472 err = it87_find(&isa_address, &sio_data);
1475 err = platform_driver_register(&it87_driver);
1479 err = it87_device_add(isa_address, &sio_data);
1481 platform_driver_unregister(&it87_driver);
1488 static void __exit sm_it87_exit(void)
1490 platform_device_unregister(pdev);
1491 platform_driver_unregister(&it87_driver);
1495 MODULE_AUTHOR("Chris Gauthron, "
1496 "Jean Delvare <khali@linux-fr.org>");
1497 MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F/8726F, SiS950 driver");
1498 module_param(update_vbat, bool, 0);
1499 MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
1500 module_param(fix_pwm_polarity, bool, 0);
1501 MODULE_PARM_DESC(fix_pwm_polarity, "Force PWM polarity to active high (DANGEROUS)");
1502 MODULE_LICENSE("GPL");
1504 module_init(sm_it87_init);
1505 module_exit(sm_it87_exit);