mfd: Fix twl4030 warning
[safe/jmp/linux-2.6] / drivers / hwmon / it87.c
index d793cc0..0ffe84d 100644 (file)
@@ -14,6 +14,7 @@
               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
 
 #include <linux/sysfs.h>
 #include <linux/string.h>
 #include <linux/dmi.h>
-#include <asm/io.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);
@@ -64,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 */
 
@@ -113,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 */
 
@@ -150,8 +158,8 @@ 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
 /* The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b
    for fan divisors. Later IT8712F revisions must use 16-bit tachometer
@@ -207,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)
@@ -238,7 +246,9 @@ struct it87_sio_data {
        /* Values read from Super-I/O config space */
        u8 revision;
        u8 vid_value;
-       /* Values set based on DMI strings */
+       /* Features skipped based on config or DMI */
+       u8 skip_vid;
+       u8 skip_fan;
        u8 skip_pwm;
 };
 
@@ -261,9 +271,9 @@ struct it87_data {
        u8 has_fan;             /* Bitfield, fans enabled */
        u16 fan[5];             /* Register values, possibly combined */
        u16 fan_min[5];         /* Register values, possibly combined */
-       u8 temp[3];             /* Register value */
-       u8 temp_high[3];        /* Register value */
-       u8 temp_low[3];         /* Register value */
+       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 */
@@ -282,7 +292,8 @@ static inline int has_16bit_fans(const struct it87_data *data)
        return (data->type == it87 && data->revision >= 0x03)
            || (data->type == it8712 && data->revision >= 0x08)
            || data->type == it8716
-           || data->type == it8718;
+           || data->type == it8718
+           || data->type == it8720;
 }
 
 static int it87_probe(struct platform_device *pdev);
@@ -477,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,
@@ -493,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);
@@ -987,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:
@@ -1013,11 +1032,35 @@ static int __init it87_find(unsigned short *address,
                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);
@@ -1063,6 +1106,7 @@ static int __devinit it87_probe(struct platform_device *pdev)
                "it8712",
                "it8716",
                "it8718",
+               "it8720",
        };
 
        res = platform_get_resource(pdev, IORESOURCE_IO, 0);
@@ -1220,8 +1264,7 @@ static int __devinit it87_probe(struct platform_device *pdev)
                }
        }
 
-       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;
@@ -1339,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
@@ -1369,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 */
@@ -1386,10 +1431,11 @@ 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;
@@ -1412,6 +1458,9 @@ static void __devinit it87_init_device(struct platform_device *pdev)
                }
        }
 
+       /* 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++) {
@@ -1508,7 +1557,8 @@ static struct it87_data *it87_update_device(struct device *dev)
 
                data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
                /* The 8705 does not have VID capability.
-                  The 8718 does not use IT87_REG_VID for the same purpose. */
+                  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,
@@ -1535,6 +1585,10 @@ static int __init it87_device_add(unsigned short address,
        };
        int err;
 
+       err = acpi_check_resource_conflict(&res);
+       if (err)
+               goto exit;
+
        pdev = platform_device_alloc(DRVNAME, address);
        if (!pdev) {
                err = -ENOMEM;
@@ -1603,7 +1657,7 @@ static void __exit sm_it87_exit(void)
 
 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);