be2net: implement EEH pci error recovery handlers
[safe/jmp/linux-2.6] / drivers / hwmon / it87.c
index 41a90e5..0ffe84d 100644 (file)
@@ -2,15 +2,24 @@
     it87.c - Part of lm_sensors, Linux kernel modules for hardware
              monitoring.
 
+    The IT8705F is an LPC-based Super I/O part that contains UARTs, a
+    parallel port, an IR port, a MIDI port, a floppy controller, etc., in
+    addition to an Environment Controller (Enhanced Hardware Monitor and
+    Fan Controller)
+
+    This driver supports only the Environment Controller in the IT8705F and
+    similar parts.  The other devices are supported by different drivers.
+
     Supports: IT8705F  Super I/O chip w/LPC interface
               IT8712F  Super I/O chip w/LPC interface
               IT8716F  Super I/O chip w/LPC interface
               IT8718F  Super I/O chip w/LPC interface
+              IT8720F  Super I/O chip w/LPC interface
               IT8726F  Super I/O chip w/LPC interface
               Sis950   A clone of the IT8705F
 
-    Copyright (C) 2001 Chris Gauthron <chrisg@0-in.com> 
-    Copyright (C) 2005-2006 Jean Delvare <khali@linux-fr.org>
+    Copyright (C) 2001 Chris Gauthron
+    Copyright (C) 2005-2007 Jean Delvare <khali@linux-fr.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 #include <linux/err.h>
 #include <linux/mutex.h>
 #include <linux/sysfs.h>
-#include <asm/io.h>
+#include <linux/string.h>
+#include <linux/dmi.h>
+#include <linux/acpi.h>
+#include <linux/io.h>
 
 #define DRVNAME "it87"
 
-enum chips { it87, it8712, it8716, it8718 };
+enum chips { it87, it8712, it8716, it8718, it8720 };
+
+static unsigned short force_id;
+module_param(force_id, ushort, 0);
+MODULE_PARM_DESC(force_id, "Override the detected device ID");
 
 static struct platform_device *pdev;
 
@@ -50,7 +66,10 @@ static struct platform_device *pdev;
 #define        DEV     0x07    /* Register: Logical device select */
 #define        VAL     0x2f    /* The value to read/write */
 #define PME    0x04    /* The device with the fan registers in it */
-#define GPIO   0x07    /* The device with the IT8718F VID value in it */
+
+/* The device with the IT8718F/IT8720F VID value in it */
+#define GPIO   0x07
+
 #define        DEVID   0x20    /* Register: Device ID */
 #define        DEVREV  0x22    /* Register: Device Revision */
 
@@ -99,11 +118,14 @@ superio_exit(void)
 #define IT8705F_DEVID 0x8705
 #define IT8716F_DEVID 0x8716
 #define IT8718F_DEVID 0x8718
+#define IT8720F_DEVID 0x8720
 #define IT8726F_DEVID 0x8726
 #define IT87_ACT_REG  0x30
 #define IT87_BASE_REG 0x60
 
 /* Logical device 7 registers (IT8712F and later) */
+#define IT87_SIO_GPIO3_REG     0x27
+#define IT87_SIO_GPIO5_REG     0x29
 #define IT87_SIO_PINX2_REG     0x2c    /* Pin selection */
 #define IT87_SIO_VID_REG       0xfc    /* VID value */
 
@@ -118,9 +140,15 @@ static int fix_pwm_polarity;
 /* Length of ISA address segment */
 #define IT87_EXTENT 8
 
-/* Where are the ISA address/data registers relative to the base address */
-#define IT87_ADDR_REG_OFFSET 5
-#define IT87_DATA_REG_OFFSET 6
+/* Length of ISA address segment for Environmental Controller */
+#define IT87_EC_EXTENT 2
+
+/* Offset of EC registers from ISA base address */
+#define IT87_EC_OFFSET 5
+
+/* Where are the ISA address/data registers relative to the EC base address */
+#define IT87_ADDR_REG_OFFSET 0
+#define IT87_DATA_REG_OFFSET 1
 
 /*----- The IT87 registers -----*/
 
@@ -130,21 +158,21 @@ static int fix_pwm_polarity;
 #define IT87_REG_ALARM2        0x02
 #define IT87_REG_ALARM3        0x03
 
-/* The IT8718F has the VID value in a different register, in Super-I/O
-   configuration space. */
+/* The IT8718F and IT8720F have the VID value in a different register, in
+   Super-I/O configuration space. */
 #define IT87_REG_VID           0x0a
-/* Warning: register 0x0b is used for something completely different in
-   new chips/revisions. I suspect only 16-bit tachometer mode will work
-   for these. */
+/* The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b
+   for fan divisors. Later IT8712F revisions must use 16-bit tachometer
+   mode. */
 #define IT87_REG_FAN_DIV       0x0b
 #define IT87_REG_FAN_16BIT     0x0c
 
 /* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */
 
-#define IT87_REG_FAN(nr)       (0x0d + (nr))
-#define IT87_REG_FAN_MIN(nr)   (0x10 + (nr))
-#define IT87_REG_FANX(nr)      (0x18 + (nr))
-#define IT87_REG_FANX_MIN(nr)  (0x1b + (nr))
+static const u8 IT87_REG_FAN[]         = { 0x0d, 0x0e, 0x0f, 0x80, 0x82 };
+static const u8 IT87_REG_FAN_MIN[]     = { 0x10, 0x11, 0x12, 0x84, 0x86 };
+static const u8 IT87_REG_FANX[]                = { 0x18, 0x19, 0x1a, 0x81, 0x83 };
+static const u8 IT87_REG_FANX_MIN[]    = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 };
 #define IT87_REG_FAN_MAIN_CTRL 0x13
 #define IT87_REG_FAN_CTL       0x14
 #define IT87_REG_PWM(nr)       (0x15 + (nr))
@@ -187,7 +215,7 @@ static inline u16 FAN16_TO_REG(long rpm)
 
 #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\
                                        ((val)+500)/1000),-128,127))
-#define TEMP_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*1000)
+#define TEMP_FROM_REG(val) ((val) * 1000)
 
 #define PWM_TO_REG(val)   ((val) >> 1)
 #define PWM_FROM_REG(val) (((val)&0x7f) << 1)
@@ -216,7 +244,12 @@ static const unsigned int pwm_freq[8] = {
 struct it87_sio_data {
        enum chips type;
        /* Values read from Super-I/O config space */
+       u8 revision;
        u8 vid_value;
+       /* Features skipped based on config or DMI */
+       u8 skip_vid;
+       u8 skip_fan;
+       u8 skip_pwm;
 };
 
 /* For each registered chip, we need to keep some data in memory.
@@ -224,6 +257,7 @@ struct it87_sio_data {
 struct it87_data {
        struct device *hwmon_dev;
        enum chips type;
+       u8 revision;
 
        unsigned short addr;
        const char *name;
@@ -235,11 +269,11 @@ struct it87_data {
        u8 in_max[8];           /* Register value */
        u8 in_min[8];           /* Register value */
        u8 has_fan;             /* Bitfield, fans enabled */
-       u16 fan[3];             /* Register values, possibly combined */
-       u16 fan_min[3];         /* Register values, possibly combined */
-       u8 temp[3];             /* Register value */
-       u8 temp_high[3];        /* Register value */
-       u8 temp_low[3];         /* Register value */
+       u16 fan[5];             /* Register values, possibly combined */
+       u16 fan_min[5];         /* Register values, possibly combined */
+       s8 temp[3];             /* Register value */
+       s8 temp_high[3];        /* Register value */
+       s8 temp_low[3];         /* Register value */
        u8 sensor;              /* Register value */
        u8 fan_div[3];          /* Register encoding, shifted right */
        u8 vid;                 /* Register encoding, combined */
@@ -250,6 +284,17 @@ struct it87_data {
        u8 manual_pwm_ctl[3];   /* manual PWM value set by user */
 };
 
+static inline int has_16bit_fans(const struct it87_data *data)
+{
+       /* IT8705F Datasheet 0.4.1, 3h == Version G.
+          IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J.
+          These are the first revisions with 16bit tachometer support. */
+       return (data->type == it87 && data->revision >= 0x03)
+           || (data->type == it8712 && data->revision >= 0x08)
+           || data->type == it8716
+           || data->type == it8718
+           || data->type == it8720;
+}
 
 static int it87_probe(struct platform_device *pdev);
 static int __devexit it87_remove(struct platform_device *pdev);
@@ -443,7 +488,7 @@ static ssize_t show_sensor(struct device *dev, struct device_attribute *attr,
        if (reg & (1 << nr))
                return sprintf(buf, "3\n");  /* thermal diode */
        if (reg & (8 << nr))
-               return sprintf(buf, "2\n");  /* thermistor */
+               return sprintf(buf, "4\n");  /* thermistor */
        return sprintf(buf, "0\n");      /* disabled */
 }
 static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,
@@ -459,10 +504,15 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,
 
        data->sensor &= ~(1 << nr);
        data->sensor &= ~(8 << nr);
-       /* 3 = thermal diode; 2 = thermistor; 0 = disabled */
+       if (val == 2) { /* backwards compatibility */
+               dev_warn(dev, "Sensor type 2 is deprecated, please use 4 "
+                        "instead\n");
+               val = 4;
+       }
+       /* 3 = thermal diode; 4 = thermistor; 0 = disabled */
        if (val == 3)
            data->sensor |= 1 << nr;
-       else if (val == 2)
+       else if (val == 4)
            data->sensor |= 8 << nr;
        else if (val != 0) {
                mutex_unlock(&data->update_lock);
@@ -555,7 +605,7 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
        }
 
        data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
-       it87_write_value(data, IT87_REG_FAN_MIN(nr), data->fan_min[nr]);
+       it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]);
        mutex_unlock(&data->update_lock);
        return count;
 }
@@ -596,7 +646,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
 
        /* Restore fan min limit */
        data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
-       it87_write_value(data, IT87_REG_FAN_MIN(nr), data->fan_min[nr]);
+       it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]);
 
        mutex_unlock(&data->update_lock);
        return count;
@@ -729,9 +779,9 @@ static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr,
 
        mutex_lock(&data->update_lock);
        data->fan_min[nr] = FAN16_TO_REG(val);
-       it87_write_value(data, IT87_REG_FAN_MIN(nr),
+       it87_write_value(data, IT87_REG_FAN_MIN[nr],
                         data->fan_min[nr] & 0xff);
-       it87_write_value(data, IT87_REG_FANX_MIN(nr),
+       it87_write_value(data, IT87_REG_FANX_MIN[nr],
                         data->fan_min[nr] >> 8);
        mutex_unlock(&data->update_lock);
        return count;
@@ -751,6 +801,8 @@ static struct sensor_device_attribute sensor_dev_attr_fan##offset##_min16 \
 show_fan16_offset(1);
 show_fan16_offset(2);
 show_fan16_offset(3);
+show_fan16_offset(4);
+show_fan16_offset(5);
 
 /* Alarms */
 static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
@@ -760,10 +812,34 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch
 }
 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
 
+static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
+               char *buf)
+{
+       int bitnr = to_sensor_dev_attr(attr)->index;
+       struct it87_data *data = it87_update_device(dev);
+       return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
+}
+static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8);
+static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9);
+static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10);
+static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11);
+static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12);
+static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13);
+static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14);
+static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15);
+static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0);
+static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1);
+static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2);
+static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3);
+static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6);
+static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16);
+static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17);
+static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18);
+
 static ssize_t
 show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
 {
-       struct it87_data *data = it87_update_device(dev);
+       struct it87_data *data = dev_get_drvdata(dev);
        return sprintf(buf, "%u\n", data->vrm);
 }
 static ssize_t
@@ -821,6 +897,14 @@ static struct attribute *it87_attributes[] = {
        &sensor_dev_attr_in5_max.dev_attr.attr,
        &sensor_dev_attr_in6_max.dev_attr.attr,
        &sensor_dev_attr_in7_max.dev_attr.attr,
+       &sensor_dev_attr_in0_alarm.dev_attr.attr,
+       &sensor_dev_attr_in1_alarm.dev_attr.attr,
+       &sensor_dev_attr_in2_alarm.dev_attr.attr,
+       &sensor_dev_attr_in3_alarm.dev_attr.attr,
+       &sensor_dev_attr_in4_alarm.dev_attr.attr,
+       &sensor_dev_attr_in5_alarm.dev_attr.attr,
+       &sensor_dev_attr_in6_alarm.dev_attr.attr,
+       &sensor_dev_attr_in7_alarm.dev_attr.attr,
 
        &sensor_dev_attr_temp1_input.dev_attr.attr,
        &sensor_dev_attr_temp2_input.dev_attr.attr,
@@ -834,6 +918,9 @@ static struct attribute *it87_attributes[] = {
        &sensor_dev_attr_temp1_type.dev_attr.attr,
        &sensor_dev_attr_temp2_type.dev_attr.attr,
        &sensor_dev_attr_temp3_type.dev_attr.attr,
+       &sensor_dev_attr_temp1_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp2_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp3_alarm.dev_attr.attr,
 
        &dev_attr_alarms.attr,
        &dev_attr_name.attr,
@@ -851,6 +938,10 @@ static struct attribute *it87_attributes_opt[] = {
        &sensor_dev_attr_fan2_min16.dev_attr.attr,
        &sensor_dev_attr_fan3_input16.dev_attr.attr,
        &sensor_dev_attr_fan3_min16.dev_attr.attr,
+       &sensor_dev_attr_fan4_input16.dev_attr.attr,
+       &sensor_dev_attr_fan4_min16.dev_attr.attr,
+       &sensor_dev_attr_fan5_input16.dev_attr.attr,
+       &sensor_dev_attr_fan5_min16.dev_attr.attr,
 
        &sensor_dev_attr_fan1_input.dev_attr.attr,
        &sensor_dev_attr_fan1_min.dev_attr.attr,
@@ -862,12 +953,21 @@ static struct attribute *it87_attributes_opt[] = {
        &sensor_dev_attr_fan3_min.dev_attr.attr,
        &sensor_dev_attr_fan3_div.dev_attr.attr,
 
+       &sensor_dev_attr_fan1_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan2_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan3_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan4_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan5_alarm.dev_attr.attr,
+
        &sensor_dev_attr_pwm1_enable.dev_attr.attr,
        &sensor_dev_attr_pwm2_enable.dev_attr.attr,
        &sensor_dev_attr_pwm3_enable.dev_attr.attr,
        &sensor_dev_attr_pwm1.dev_attr.attr,
        &sensor_dev_attr_pwm2.dev_attr.attr,
        &sensor_dev_attr_pwm3.dev_attr.attr,
+       &dev_attr_pwm1_freq.attr,
+       &dev_attr_pwm2_freq.attr,
+       &dev_attr_pwm3_freq.attr,
 
        &dev_attr_vrm.attr,
        &dev_attr_cpu0_vid.attr,
@@ -884,9 +984,10 @@ static int __init it87_find(unsigned short *address,
 {
        int err = -ENODEV;
        u16 chip_type;
+       const char *board_vendor, *board_name;
 
        superio_enter();
-       chip_type = superio_inw(DEVID);
+       chip_type = force_id ? force_id : superio_inw(DEVID);
 
        switch (chip_type) {
        case IT8705F_DEVID:
@@ -902,6 +1003,9 @@ static int __init it87_find(unsigned short *address,
        case IT8718F_DEVID:
                sio_data->type = it8718;
                break;
+       case IT8720F_DEVID:
+               sio_data->type = it8720;
+               break;
        case 0xffff:    /* No device at all */
                goto exit;
        default:
@@ -923,15 +1027,40 @@ static int __init it87_find(unsigned short *address,
        }
 
        err = 0;
+       sio_data->revision = superio_inb(DEVREV) & 0x0f;
        pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n",
-               chip_type, *address, superio_inb(DEVREV) & 0x0f);
+               chip_type, *address, sio_data->revision);
 
        /* Read GPIO config and VID value from LDN 7 (GPIO) */
-       if (chip_type != IT8705F_DEVID) {
+       if (sio_data->type == it87) {
+               /* The IT8705F doesn't have VID pins at all */
+               sio_data->skip_vid = 1;
+       } else {
                int reg;
 
                superio_select(GPIO);
-               if (chip_type == it8718)
+               /* We need at least 4 VID pins */
+               reg = superio_inb(IT87_SIO_GPIO3_REG);
+               if (reg & 0x0f) {
+                       pr_info("it87: VID is disabled (pins used for GPIO)\n");
+                       sio_data->skip_vid = 1;
+               }
+
+               /* Check if fan3 is there or not */
+               if (reg & (1 << 6))
+                       sio_data->skip_pwm |= (1 << 2);
+               if (reg & (1 << 7))
+                       sio_data->skip_fan |= (1 << 2);
+
+               /* Check if fan2 is there or not */
+               reg = superio_inb(IT87_SIO_GPIO5_REG);
+               if (reg & (1 << 1))
+                       sio_data->skip_pwm |= (1 << 1);
+               if (reg & (1 << 2))
+                       sio_data->skip_fan |= (1 << 1);
+
+               if ((sio_data->type == it8718 || sio_data->type == it8720)
+                && !(sio_data->skip_vid))
                        sio_data->vid_value = superio_inb(IT87_SIO_VID_REG);
 
                reg = superio_inb(IT87_SIO_PINX2_REG);
@@ -941,6 +1070,24 @@ static int __init it87_find(unsigned short *address,
                        pr_info("it87: in7 is VCCH (+5V Stand-By)\n");
        }
 
+       /* Disable specific features based on DMI strings */
+       board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
+       board_name = dmi_get_system_info(DMI_BOARD_NAME);
+       if (board_vendor && board_name) {
+               if (strcmp(board_vendor, "nVIDIA") == 0
+                && strcmp(board_name, "FN68PT") == 0) {
+                       /* On the Shuttle SN68PT, FAN_CTL2 is apparently not
+                          connected to a fan, but to something else. One user
+                          has reported instant system power-off when changing
+                          the PWM2 duty cycle, so we disable it.
+                          I use the board name string as the trigger in case
+                          the same board is ever used in other systems. */
+                       pr_info("it87: Disabling pwm2 due to "
+                               "hardware constraints\n");
+                       sio_data->skip_pwm = (1 << 1);
+               }
+       }
+
 exit:
        superio_exit();
        return err;
@@ -959,13 +1106,14 @@ static int __devinit it87_probe(struct platform_device *pdev)
                "it8712",
                "it8716",
                "it8718",
+               "it8720",
        };
 
        res = platform_get_resource(pdev, IORESOURCE_IO, 0);
-       if (!request_region(res->start, IT87_EXTENT, DRVNAME)) {
+       if (!request_region(res->start, IT87_EC_EXTENT, DRVNAME)) {
                dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
                        (unsigned long)res->start,
-                       (unsigned long)(res->start + IT87_EXTENT - 1));
+                       (unsigned long)(res->start + IT87_EC_EXTENT - 1));
                err = -EBUSY;
                goto ERROR0;
        }
@@ -977,6 +1125,7 @@ static int __devinit it87_probe(struct platform_device *pdev)
 
        data->addr = res->start;
        data->type = sio_data->type;
+       data->revision = sio_data->revision;
        data->name = names[sio_data->type];
 
        /* Now, we do the remaining detection. */
@@ -1001,27 +1150,51 @@ static int __devinit it87_probe(struct platform_device *pdev)
                goto ERROR2;
 
        /* Do not create fan files for disabled fans */
-       if (data->type == it8716 || data->type == it8718) {
+       if (has_16bit_fans(data)) {
                /* 16-bit tachometers */
                if (data->has_fan & (1 << 0)) {
                        if ((err = device_create_file(dev,
                             &sensor_dev_attr_fan1_input16.dev_attr))
                         || (err = device_create_file(dev,
-                            &sensor_dev_attr_fan1_min16.dev_attr)))
+                            &sensor_dev_attr_fan1_min16.dev_attr))
+                        || (err = device_create_file(dev,
+                            &sensor_dev_attr_fan1_alarm.dev_attr)))
                                goto ERROR4;
                }
                if (data->has_fan & (1 << 1)) {
                        if ((err = device_create_file(dev,
                             &sensor_dev_attr_fan2_input16.dev_attr))
                         || (err = device_create_file(dev,
-                            &sensor_dev_attr_fan2_min16.dev_attr)))
+                            &sensor_dev_attr_fan2_min16.dev_attr))
+                        || (err = device_create_file(dev,
+                            &sensor_dev_attr_fan2_alarm.dev_attr)))
                                goto ERROR4;
                }
                if (data->has_fan & (1 << 2)) {
                        if ((err = device_create_file(dev,
                             &sensor_dev_attr_fan3_input16.dev_attr))
                         || (err = device_create_file(dev,
-                            &sensor_dev_attr_fan3_min16.dev_attr)))
+                            &sensor_dev_attr_fan3_min16.dev_attr))
+                        || (err = device_create_file(dev,
+                            &sensor_dev_attr_fan3_alarm.dev_attr)))
+                               goto ERROR4;
+               }
+               if (data->has_fan & (1 << 3)) {
+                       if ((err = device_create_file(dev,
+                            &sensor_dev_attr_fan4_input16.dev_attr))
+                        || (err = device_create_file(dev,
+                            &sensor_dev_attr_fan4_min16.dev_attr))
+                        || (err = device_create_file(dev,
+                            &sensor_dev_attr_fan4_alarm.dev_attr)))
+                               goto ERROR4;
+               }
+               if (data->has_fan & (1 << 4)) {
+                       if ((err = device_create_file(dev,
+                            &sensor_dev_attr_fan5_input16.dev_attr))
+                        || (err = device_create_file(dev,
+                            &sensor_dev_attr_fan5_min16.dev_attr))
+                        || (err = device_create_file(dev,
+                            &sensor_dev_attr_fan5_alarm.dev_attr)))
                                goto ERROR4;
                }
        } else {
@@ -1032,7 +1205,9 @@ static int __devinit it87_probe(struct platform_device *pdev)
                         || (err = device_create_file(dev,
                             &sensor_dev_attr_fan1_min.dev_attr))
                         || (err = device_create_file(dev,
-                            &sensor_dev_attr_fan1_div.dev_attr)))
+                            &sensor_dev_attr_fan1_div.dev_attr))
+                        || (err = device_create_file(dev,
+                            &sensor_dev_attr_fan1_alarm.dev_attr)))
                                goto ERROR4;
                }
                if (data->has_fan & (1 << 1)) {
@@ -1041,7 +1216,9 @@ static int __devinit it87_probe(struct platform_device *pdev)
                         || (err = device_create_file(dev,
                             &sensor_dev_attr_fan2_min.dev_attr))
                         || (err = device_create_file(dev,
-                            &sensor_dev_attr_fan2_div.dev_attr)))
+                            &sensor_dev_attr_fan2_div.dev_attr))
+                        || (err = device_create_file(dev,
+                            &sensor_dev_attr_fan2_alarm.dev_attr)))
                                goto ERROR4;
                }
                if (data->has_fan & (1 << 2)) {
@@ -1050,35 +1227,44 @@ static int __devinit it87_probe(struct platform_device *pdev)
                         || (err = device_create_file(dev,
                             &sensor_dev_attr_fan3_min.dev_attr))
                         || (err = device_create_file(dev,
-                            &sensor_dev_attr_fan3_div.dev_attr)))
+                            &sensor_dev_attr_fan3_div.dev_attr))
+                        || (err = device_create_file(dev,
+                            &sensor_dev_attr_fan3_alarm.dev_attr)))
                                goto ERROR4;
                }
        }
 
        if (enable_pwm_interface) {
-               if ((err = device_create_file(dev,
-                    &sensor_dev_attr_pwm1_enable.dev_attr))
-                || (err = device_create_file(dev,
-                    &sensor_dev_attr_pwm2_enable.dev_attr))
-                || (err = device_create_file(dev,
-                    &sensor_dev_attr_pwm3_enable.dev_attr))
-                || (err = device_create_file(dev,
-                    &sensor_dev_attr_pwm1.dev_attr))
-                || (err = device_create_file(dev,
-                    &sensor_dev_attr_pwm2.dev_attr))
-                || (err = device_create_file(dev,
-                    &sensor_dev_attr_pwm3.dev_attr))
-                || (err = device_create_file(dev,
-                    &dev_attr_pwm1_freq))
-                || (err = device_create_file(dev,
-                    &dev_attr_pwm2_freq))
-                || (err = device_create_file(dev,
-                    &dev_attr_pwm3_freq)))
-                       goto ERROR4;
+               if (!(sio_data->skip_pwm & (1 << 0))) {
+                       if ((err = device_create_file(dev,
+                            &sensor_dev_attr_pwm1_enable.dev_attr))
+                        || (err = device_create_file(dev,
+                            &sensor_dev_attr_pwm1.dev_attr))
+                        || (err = device_create_file(dev,
+                            &dev_attr_pwm1_freq)))
+                               goto ERROR4;
+               }
+               if (!(sio_data->skip_pwm & (1 << 1))) {
+                       if ((err = device_create_file(dev,
+                            &sensor_dev_attr_pwm2_enable.dev_attr))
+                        || (err = device_create_file(dev,
+                            &sensor_dev_attr_pwm2.dev_attr))
+                        || (err = device_create_file(dev,
+                            &dev_attr_pwm2_freq)))
+                               goto ERROR4;
+               }
+               if (!(sio_data->skip_pwm & (1 << 2))) {
+                       if ((err = device_create_file(dev,
+                            &sensor_dev_attr_pwm3_enable.dev_attr))
+                        || (err = device_create_file(dev,
+                            &sensor_dev_attr_pwm3.dev_attr))
+                        || (err = device_create_file(dev,
+                            &dev_attr_pwm3_freq)))
+                               goto ERROR4;
+               }
        }
 
-       if (data->type == it8712 || data->type == it8716
-        || data->type == it8718) {
+       if (!sio_data->skip_vid) {
                data->vrm = vid_which_vrm();
                /* VID reading from Super-I/O config space if available */
                data->vid = sio_data->vid_value;
@@ -1104,7 +1290,7 @@ ERROR2:
        platform_set_drvdata(pdev, NULL);
        kfree(data);
 ERROR1:
-       release_region(res->start, IT87_EXTENT);
+       release_region(res->start, IT87_EC_EXTENT);
 ERROR0:
        return err;
 }
@@ -1117,7 +1303,7 @@ static int __devexit it87_remove(struct platform_device *pdev)
        sysfs_remove_group(&pdev->dev.kobj, &it87_group);
        sysfs_remove_group(&pdev->dev.kobj, &it87_group_opt);
 
-       release_region(data->addr, IT87_EXTENT);
+       release_region(data->addr, IT87_EC_EXTENT);
        platform_set_drvdata(pdev, NULL);
        kfree(data);
 
@@ -1196,8 +1382,10 @@ static int __devinit it87_check_pwm(struct device *dev)
 /* Called when we have found a new IT87. */
 static void __devinit it87_init_device(struct platform_device *pdev)
 {
+       struct it87_sio_data *sio_data = pdev->dev.platform_data;
        struct it87_data *data = platform_get_drvdata(pdev);
        int tmp, i;
+       u8 mask;
 
        /* initialize to sane defaults:
         * - if the chip is in manual pwm mode, this will be overwritten with
@@ -1226,7 +1414,7 @@ static void __devinit it87_init_device(struct platform_device *pdev)
                        it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127);
        }
 
-       /* Check if temperature channnels are reset manually or by some reason */
+       /* Check if temperature channels are reset manually or by some reason */
        tmp = it87_read_value(data, IT87_REG_TEMP_ENABLE);
        if ((tmp & 0x3f) == 0) {
                /* Temp1,Temp3=thermistor; Temp2=thermal diode */
@@ -1243,16 +1431,17 @@ static void __devinit it87_init_device(struct platform_device *pdev)
        }
 
        /* Check if tachometers are reset manually or by some reason */
+       mask = 0x70 & ~(sio_data->skip_fan << 4);
        data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL);
-       if ((data->fan_main_ctrl & 0x70) == 0) {
+       if ((data->fan_main_ctrl & mask) == 0) {
                /* Enable all fan tachometers */
-               data->fan_main_ctrl |= 0x70;
+               data->fan_main_ctrl |= mask;
                it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
        }
        data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
 
        /* Set tachometers to 16-bit mode if needed */
-       if (data->type == it8716 || data->type == it8718) {
+       if (has_16bit_fans(data)) {
                tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
                if (~tmp & 0x07 & data->has_fan) {
                        dev_dbg(&pdev->dev,
@@ -1260,8 +1449,18 @@ static void __devinit it87_init_device(struct platform_device *pdev)
                        it87_write_value(data, IT87_REG_FAN_16BIT,
                                         tmp | 0x07);
                }
+               /* IT8705F only supports three fans. */
+               if (data->type != it87) {
+                       if (tmp & (1 << 4))
+                               data->has_fan |= (1 << 3); /* fan4 enabled */
+                       if (tmp & (1 << 5))
+                               data->has_fan |= (1 << 4); /* fan5 enabled */
+               }
        }
 
+       /* Fan input pins may be used for alternative functions */
+       data->has_fan &= ~sio_data->skip_fan;
+
        /* Set current fan mode registers and the default settings for the
         * other mode registers */
        for (i = 0; i < 3; i++) {
@@ -1314,21 +1513,21 @@ static struct it87_data *it87_update_device(struct device *dev)
                data->in[8] =
                    it87_read_value(data, IT87_REG_VIN(8));
 
-               for (i = 0; i < 3; i++) {
+               for (i = 0; i < 5; i++) {
                        /* Skip disabled fans */
                        if (!(data->has_fan & (1 << i)))
                                continue;
 
                        data->fan_min[i] =
-                           it87_read_value(data, IT87_REG_FAN_MIN(i));
+                           it87_read_value(data, IT87_REG_FAN_MIN[i]);
                        data->fan[i] = it87_read_value(data,
-                                      IT87_REG_FAN(i));
+                                      IT87_REG_FAN[i]);
                        /* Add high byte if in 16-bit mode */
-                       if (data->type == it8716 || data->type == it8718) {
+                       if (has_16bit_fans(data)) {
                                data->fan[i] |= it87_read_value(data,
-                                               IT87_REG_FANX(i)) << 8;
+                                               IT87_REG_FANX[i]) << 8;
                                data->fan_min[i] |= it87_read_value(data,
-                                               IT87_REG_FANX_MIN(i)) << 8;
+                                               IT87_REG_FANX_MIN[i]) << 8;
                        }
                }
                for (i = 0; i < 3; i++) {
@@ -1341,8 +1540,7 @@ static struct it87_data *it87_update_device(struct device *dev)
                }
 
                /* Newer chips don't have clock dividers */
-               if ((data->has_fan & 0x07) && data->type != it8716
-                && data->type != it8718) {
+               if ((data->has_fan & 0x07) && !has_16bit_fans(data)) {
                        i = it87_read_value(data, IT87_REG_FAN_DIV);
                        data->fan_div[0] = i & 0x07;
                        data->fan_div[1] = (i >> 3) & 0x07;
@@ -1358,7 +1556,9 @@ static struct it87_data *it87_update_device(struct device *dev)
                data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL);
 
                data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
-               /* The 8705 does not have VID capability */
+               /* The 8705 does not have VID capability.
+                  The 8718 and the 8720 don't use IT87_REG_VID for the
+                  same purpose. */
                if (data->type == it8712 || data->type == it8716) {
                        data->vid = it87_read_value(data, IT87_REG_VID);
                        /* The older IT8712F revisions had only 5 VID pins,
@@ -1378,13 +1578,17 @@ static int __init it87_device_add(unsigned short address,
                                  const struct it87_sio_data *sio_data)
 {
        struct resource res = {
-               .start  = address ,
-               .end    = address + IT87_EXTENT - 1,
+               .start  = address + IT87_EC_OFFSET,
+               .end    = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1,
                .name   = DRVNAME,
                .flags  = IORESOURCE_IO,
        };
        int err;
 
+       err = acpi_check_resource_conflict(&res);
+       if (err)
+               goto exit;
+
        pdev = platform_device_alloc(DRVNAME, address);
        if (!pdev) {
                err = -ENOMEM;
@@ -1427,6 +1631,7 @@ static int __init sm_it87_init(void)
        unsigned short isa_address=0;
        struct it87_sio_data sio_data;
 
+       memset(&sio_data, 0, sizeof(struct it87_sio_data));
        err = it87_find(&isa_address, &sio_data);
        if (err)
                return err;
@@ -1450,9 +1655,9 @@ static void __exit sm_it87_exit(void)
 }
 
 
-MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>, "
+MODULE_AUTHOR("Chris Gauthron, "
              "Jean Delvare <khali@linux-fr.org>");
-MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F/8726F, SiS950 driver");
+MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F/8720F/8726F, SiS950 driver");
 module_param(update_vbat, bool, 0);
 MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
 module_param(fix_pwm_polarity, bool, 0);