Merge branch 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelv...
[safe/jmp/linux-2.6] / drivers / hwmon / it87.c
index d70c6ec..1002bef 100644 (file)
@@ -1,40 +1,40 @@
 /*
   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
   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
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
-
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
-
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
*  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
*  Copyright (C) 2005-2010 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
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
+ *
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
+ *
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software
*  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
 
 #include <linux/module.h>
 #include <linux/init.h>
@@ -192,6 +192,9 @@ static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 };
 
 #define IT87_REG_CHIPID        0x58
 
+#define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i))
+#define IT87_REG_AUTO_PWM(nr, i)  (0x65 + (nr) * 8 + (i))
+
 #define IN_TO_REG(val)  (SENSORS_LIMIT((((val) + 8)/16),0,255))
 #define IN_FROM_REG(val) ((val) * 16)
 
@@ -293,6 +296,10 @@ struct it87_data {
        u8 pwm_ctrl[3];         /* Register value */
        u8 pwm_duty[3];         /* Manual PWM value set by user (bit 6-0) */
        u8 pwm_temp_map[3];     /* PWM to temp. chan. mapping (bits 1-0) */
+
+       /* Automatic fan speed control registers */
+       u8 auto_pwm[3][4];      /* [nr][3] is hard-coded */
+       s8 auto_temp[3][5];     /* [nr][0] is point1_temp_hyst */
 };
 
 static inline int has_16bit_fans(const struct it87_data *data)
@@ -307,6 +314,15 @@ static inline int has_16bit_fans(const struct it87_data *data)
            || data->type == it8720;
 }
 
+static inline int has_old_autopwm(const struct it87_data *data)
+{
+       /* The old automatic fan speed control interface is implemented
+          by IT8705F chips up to revision F and IT8712F chips up to
+          revision G. */
+       return (data->type == it87 && data->revision < 0x03)
+           || (data->type == it8712 && data->revision < 0x08);
+}
+
 static int it87_probe(struct platform_device *pdev);
 static int __devexit it87_remove(struct platform_device *pdev);
 
@@ -363,7 +379,10 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
        int nr = sensor_attr->index;
 
        struct it87_data *data = dev_get_drvdata(dev);
-       unsigned long val = simple_strtoul(buf, NULL, 10);
+       unsigned long val;
+
+       if (strict_strtoul(buf, 10, &val) < 0)
+               return -EINVAL;
 
        mutex_lock(&data->update_lock);
        data->in_min[nr] = IN_TO_REG(val);
@@ -379,7 +398,10 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
        int nr = sensor_attr->index;
 
        struct it87_data *data = dev_get_drvdata(dev);
-       unsigned long val = simple_strtoul(buf, NULL, 10);
+       unsigned long val;
+
+       if (strict_strtoul(buf, 10, &val) < 0)
+               return -EINVAL;
 
        mutex_lock(&data->update_lock);
        data->in_max[nr] = IN_TO_REG(val);
@@ -452,7 +474,10 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
        int nr = sensor_attr->index;
 
        struct it87_data *data = dev_get_drvdata(dev);
-       int val = simple_strtol(buf, NULL, 10);
+       long val;
+
+       if (strict_strtol(buf, 10, &val) < 0)
+               return -EINVAL;
 
        mutex_lock(&data->update_lock);
        data->temp_high[nr] = TEMP_TO_REG(val);
@@ -467,7 +492,10 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
        int nr = sensor_attr->index;
 
        struct it87_data *data = dev_get_drvdata(dev);
-       int val = simple_strtol(buf, NULL, 10);
+       long val;
+
+       if (strict_strtol(buf, 10, &val) < 0)
+               return -EINVAL;
 
        mutex_lock(&data->update_lock);
        data->temp_low[nr] = TEMP_TO_REG(val);
@@ -494,8 +522,9 @@ static ssize_t show_sensor(struct device *dev, struct device_attribute *attr,
        int nr = sensor_attr->index;
 
        struct it87_data *data = it87_update_device(dev);
-       u8 reg = data->sensor; /* In case the value is updated while we use it */
-       
+       u8 reg = data->sensor;          /* In case the value is updated while
+                                          we use it */
+
        if (reg & (1 << nr))
                return sprintf(buf, "3\n");  /* thermal diode */
        if (reg & (8 << nr))
@@ -509,7 +538,10 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,
        int nr = sensor_attr->index;
 
        struct it87_data *data = dev_get_drvdata(dev);
-       int val = simple_strtol(buf, NULL, 10);
+       long val;
+
+       if (strict_strtol(buf, 10, &val) < 0)
+               return -EINVAL;
 
        mutex_lock(&data->update_lock);
 
@@ -522,9 +554,9 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,
        }
        /* 3 = thermal diode; 4 = thermistor; 0 = disabled */
        if (val == 3)
-           data->sensor |= 1 << nr;
+               data->sensor |= 1 << nr;
        else if (val == 4)
-           data->sensor |= 8 << nr;
+               data->sensor |= 8 << nr;
        else if (val != 0) {
                mutex_unlock(&data->update_lock);
                return -EINVAL;
@@ -562,7 +594,7 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
        int nr = sensor_attr->index;
 
        struct it87_data *data = it87_update_device(dev);
-       return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr], 
+       return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
                                DIV_FROM_REG(data->fan_div[nr])));
 }
 static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
@@ -572,8 +604,8 @@ static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
        int nr = sensor_attr->index;
 
        struct it87_data *data = it87_update_device(dev);
-       return sprintf(buf,"%d\n",
-               FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])));
+       return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
+                               DIV_FROM_REG(data->fan_div[nr])));
 }
 static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
                char *buf)
@@ -584,8 +616,8 @@ static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
        struct it87_data *data = it87_update_device(dev);
        return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
 }
-static ssize_t show_pwm_enable(struct device *dev, struct device_attribute *attr,
-               char *buf)
+static ssize_t show_pwm_enable(struct device *dev,
+               struct device_attribute *attr, char *buf)
 {
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
@@ -617,15 +649,24 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
        int nr = sensor_attr->index;
 
        struct it87_data *data = dev_get_drvdata(dev);
-       int val = simple_strtol(buf, NULL, 10);
+       long val;
        u8 reg;
 
+       if (strict_strtol(buf, 10, &val) < 0)
+               return -EINVAL;
+
        mutex_lock(&data->update_lock);
        reg = it87_read_value(data, IT87_REG_FAN_DIV);
        switch (nr) {
-       case 0: data->fan_div[nr] = reg & 0x07; break;
-       case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break;
-       case 2: data->fan_div[nr] = (reg & 0x40) ? 3 : 1; break;
+       case 0:
+               data->fan_div[nr] = reg & 0x07;
+               break;
+       case 1:
+               data->fan_div[nr] = (reg >> 3) & 0x07;
+               break;
+       case 2:
+               data->fan_div[nr] = (reg & 0x40) ? 3 : 1;
+               break;
        }
 
        data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
@@ -640,10 +681,13 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
        int nr = sensor_attr->index;
 
        struct it87_data *data = dev_get_drvdata(dev);
-       unsigned long val = simple_strtoul(buf, NULL, 10);
+       unsigned long val;
        int min;
        u8 old;
 
+       if (strict_strtoul(buf, 10, &val) < 0)
+               return -EINVAL;
+
        mutex_lock(&data->update_lock);
        old = it87_read_value(data, IT87_REG_FAN_DIV);
 
@@ -675,6 +719,32 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
        mutex_unlock(&data->update_lock);
        return count;
 }
+
+/* Returns 0 if OK, -EINVAL otherwise */
+static int check_trip_points(struct device *dev, int nr)
+{
+       const struct it87_data *data = dev_get_drvdata(dev);
+       int i, err = 0;
+
+       if (has_old_autopwm(data)) {
+               for (i = 0; i < 3; i++) {
+                       if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1])
+                               err = -EINVAL;
+               }
+               for (i = 0; i < 2; i++) {
+                       if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1])
+                               err = -EINVAL;
+               }
+       }
+
+       if (err) {
+               dev_err(dev, "Inconsistent trip points, not switching to "
+                       "automatic mode\n");
+               dev_err(dev, "Adjust the trip points and try again\n");
+       }
+       return err;
+}
+
 static ssize_t set_pwm_enable(struct device *dev,
                struct device_attribute *attr, const char *buf, size_t count)
 {
@@ -682,11 +752,17 @@ static ssize_t set_pwm_enable(struct device *dev,
        int nr = sensor_attr->index;
 
        struct it87_data *data = dev_get_drvdata(dev);
-       int val = simple_strtol(buf, NULL, 10);
+       long val;
 
-       if (val < 0 || val > 2)
+       if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 2)
                return -EINVAL;
 
+       /* Check trip points before switching to automatic mode */
+       if (val == 2) {
+               if (check_trip_points(dev, nr) < 0)
+                       return -EINVAL;
+       }
+
        mutex_lock(&data->update_lock);
 
        if (val == 0) {
@@ -696,7 +772,8 @@ static ssize_t set_pwm_enable(struct device *dev,
                it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr));
                /* set on/off mode */
                data->fan_main_ctrl &= ~(1 << nr);
-               it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
+               it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
+                                data->fan_main_ctrl);
        } else {
                if (val == 1)                           /* Manual mode */
                        data->pwm_ctrl[nr] = data->pwm_duty[nr];
@@ -705,7 +782,8 @@ static ssize_t set_pwm_enable(struct device *dev,
                it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
                /* set SmartGuardian mode */
                data->fan_main_ctrl |= (1 << nr);
-               it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
+               it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
+                                data->fan_main_ctrl);
        }
 
        mutex_unlock(&data->update_lock);
@@ -718,9 +796,9 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
        int nr = sensor_attr->index;
 
        struct it87_data *data = dev_get_drvdata(dev);
-       int val = simple_strtol(buf, NULL, 10);
+       long val;
 
-       if (val < 0 || val > 255)
+       if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 255)
                return -EINVAL;
 
        mutex_lock(&data->update_lock);
@@ -738,9 +816,12 @@ static ssize_t set_pwm_freq(struct device *dev,
                struct device_attribute *attr, const char *buf, size_t count)
 {
        struct it87_data *data = dev_get_drvdata(dev);
-       unsigned long val = simple_strtoul(buf, NULL, 10);
+       unsigned long val;
        int i;
 
+       if (strict_strtoul(buf, 10, &val) < 0)
+               return -EINVAL;
+
        /* Search for the nearest available frequency */
        for (i = 0; i < 7; i++) {
                if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2)
@@ -780,6 +861,13 @@ static ssize_t set_pwm_temp_map(struct device *dev,
        long val;
        u8 reg;
 
+       /* This check can go away if we ever support automatic fan speed
+          control on newer chips. */
+       if (!has_old_autopwm(data)) {
+               dev_notice(dev, "Mapping change disabled for safety reasons\n");
+               return -EINVAL;
+       }
+
        if (strict_strtol(buf, 10, &val) < 0)
                return -EINVAL;
 
@@ -809,6 +897,72 @@ static ssize_t set_pwm_temp_map(struct device *dev,
        return count;
 }
 
+static ssize_t show_auto_pwm(struct device *dev,
+               struct device_attribute *attr, char *buf)
+{
+       struct it87_data *data = it87_update_device(dev);
+       struct sensor_device_attribute_2 *sensor_attr =
+                       to_sensor_dev_attr_2(attr);
+       int nr = sensor_attr->nr;
+       int point = sensor_attr->index;
+
+       return sprintf(buf, "%d\n", PWM_FROM_REG(data->auto_pwm[nr][point]));
+}
+
+static ssize_t set_auto_pwm(struct device *dev,
+               struct device_attribute *attr, const char *buf, size_t count)
+{
+       struct it87_data *data = dev_get_drvdata(dev);
+       struct sensor_device_attribute_2 *sensor_attr =
+                       to_sensor_dev_attr_2(attr);
+       int nr = sensor_attr->nr;
+       int point = sensor_attr->index;
+       long val;
+
+       if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 255)
+               return -EINVAL;
+
+       mutex_lock(&data->update_lock);
+       data->auto_pwm[nr][point] = PWM_TO_REG(val);
+       it87_write_value(data, IT87_REG_AUTO_PWM(nr, point),
+                        data->auto_pwm[nr][point]);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
+
+static ssize_t show_auto_temp(struct device *dev,
+               struct device_attribute *attr, char *buf)
+{
+       struct it87_data *data = it87_update_device(dev);
+       struct sensor_device_attribute_2 *sensor_attr =
+                       to_sensor_dev_attr_2(attr);
+       int nr = sensor_attr->nr;
+       int point = sensor_attr->index;
+
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->auto_temp[nr][point]));
+}
+
+static ssize_t set_auto_temp(struct device *dev,
+               struct device_attribute *attr, const char *buf, size_t count)
+{
+       struct it87_data *data = dev_get_drvdata(dev);
+       struct sensor_device_attribute_2 *sensor_attr =
+                       to_sensor_dev_attr_2(attr);
+       int nr = sensor_attr->nr;
+       int point = sensor_attr->index;
+       long val;
+
+       if (strict_strtol(buf, 10, &val) < 0 || val < -128000 || val > 127000)
+               return -EINVAL;
+
+       mutex_lock(&data->update_lock);
+       data->auto_temp[nr][point] = TEMP_TO_REG(val);
+       it87_write_value(data, IT87_REG_AUTO_TEMP(nr, point),
+                        data->auto_temp[nr][point]);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
+
 #define show_fan_offset(offset)                                        \
 static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO,                \
                show_fan, NULL, offset - 1);                    \
@@ -830,8 +984,34 @@ static DEVICE_ATTR(pwm##offset##_freq,                                     \
                (offset == 1 ? S_IRUGO | S_IWUSR : S_IRUGO),            \
                show_pwm_freq, (offset == 1 ? set_pwm_freq : NULL));    \
 static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels_temp,            \
-               S_IRUGO, show_pwm_temp_map, set_pwm_temp_map,           \
-               offset - 1);
+               S_IRUGO | S_IWUSR, show_pwm_temp_map, set_pwm_temp_map, \
+               offset - 1);                                            \
+static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_pwm,             \
+               S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm,         \
+               offset - 1, 0);                                         \
+static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_pwm,             \
+               S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm,         \
+               offset - 1, 1);                                         \
+static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_pwm,             \
+               S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm,         \
+               offset - 1, 2);                                         \
+static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_pwm,             \
+               S_IRUGO, show_auto_pwm, NULL, offset - 1, 3);           \
+static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp,            \
+               S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp,       \
+               offset - 1, 1);                                         \
+static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp_hyst,       \
+               S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp,       \
+               offset - 1, 0);                                         \
+static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_temp,            \
+               S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp,       \
+               offset - 1, 2);                                         \
+static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_temp,            \
+               S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp,       \
+               offset - 1, 3);                                         \
+static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_temp,            \
+               S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp,       \
+               offset - 1, 4);
 
 show_pwm_offset(1);
 show_pwm_offset(2);
@@ -862,7 +1042,10 @@ static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct it87_data *data = dev_get_drvdata(dev);
-       int val = simple_strtol(buf, NULL, 10);
+       long val;
+
+       if (strict_strtol(buf, 10, &val) < 0)
+               return -EINVAL;
 
        mutex_lock(&data->update_lock);
        data->fan_min[nr] = FAN16_TO_REG(val);
@@ -892,7 +1075,8 @@ show_fan16_offset(4);
 show_fan16_offset(5);
 
 /* Alarms */
-static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
+               char *buf)
 {
        struct it87_data *data = it87_update_device(dev);
        return sprintf(buf, "%u\n", data->alarms);
@@ -972,27 +1156,29 @@ static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
 static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2);
 static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2);
 
-static ssize_t
-show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
+               char *buf)
 {
        struct it87_data *data = dev_get_drvdata(dev);
        return sprintf(buf, "%u\n", data->vrm);
 }
-static ssize_t
-store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
+static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
+               const char *buf, size_t count)
 {
        struct it87_data *data = dev_get_drvdata(dev);
-       u32 val;
+       unsigned long val;
+
+       if (strict_strtoul(buf, 10, &val) < 0)
+               return -EINVAL;
 
-       val = simple_strtoul(buf, NULL, 10);
        data->vrm = val;
 
        return count;
 }
 static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
 
-static ssize_t
-show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
+               char *buf)
 {
        struct it87_data *data = it87_update_device(dev);
        return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
@@ -1180,6 +1366,47 @@ static const struct attribute_group it87_group_pwm[3] = {
        { .attrs = it87_attributes_pwm[2] },
 };
 
+static struct attribute *it87_attributes_autopwm[3][9+1] = { {
+       &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
+       &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
+       &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr,
+       &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr,
+       &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
+       &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr,
+       &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr,
+       &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr,
+       &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr,
+       NULL
+}, {
+       &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
+       &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
+       &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr,
+       &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr,
+       &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr,
+       &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr,
+       &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr,
+       &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr,
+       &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr,
+       NULL
+}, {
+       &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
+       &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
+       &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr,
+       &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr,
+       &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr,
+       &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr,
+       &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr,
+       &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr,
+       &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr,
+       NULL
+} };
+
+static const struct attribute_group it87_group_autopwm[3] = {
+       { .attrs = it87_attributes_autopwm[0] },
+       { .attrs = it87_attributes_autopwm[1] },
+       { .attrs = it87_attributes_autopwm[2] },
+};
+
 static struct attribute *it87_attributes_fan_beep[] = {
        &sensor_dev_attr_fan1_beep.dev_attr.attr,
        &sensor_dev_attr_fan2_beep.dev_attr.attr,
@@ -1343,6 +1570,9 @@ static void it87_remove_files(struct device *dev)
                if (sio_data->skip_pwm & (1 << 0))
                        continue;
                sysfs_remove_group(&dev->kobj, &it87_group_pwm[i]);
+               if (has_old_autopwm(data))
+                       sysfs_remove_group(&dev->kobj,
+                                          &it87_group_autopwm[i]);
        }
        if (!sio_data->skip_vid)
                sysfs_remove_group(&dev->kobj, &it87_group_vid);
@@ -1375,7 +1605,8 @@ static int __devinit it87_probe(struct platform_device *pdev)
                goto ERROR0;
        }
 
-       if (!(data = kzalloc(sizeof(struct it87_data), GFP_KERNEL))) {
+       data = kzalloc(sizeof(struct it87_data), GFP_KERNEL);
+       if (!data) {
                err = -ENOMEM;
                goto ERROR1;
        }
@@ -1403,7 +1634,8 @@ static int __devinit it87_probe(struct platform_device *pdev)
        it87_init_device(pdev);
 
        /* Register sysfs hooks */
-       if ((err = sysfs_create_group(&dev->kobj, &it87_group)))
+       err = sysfs_create_group(&dev->kobj, &it87_group);
+       if (err)
                goto ERROR2;
 
        if (sio_data->beep_pin) {
@@ -1450,6 +1682,13 @@ static int __devinit it87_probe(struct platform_device *pdev)
                                                 &it87_group_pwm[i]);
                        if (err)
                                goto ERROR4;
+
+                       if (!has_old_autopwm(data))
+                               continue;
+                       err = sysfs_create_group(&dev->kobj,
+                                                &it87_group_autopwm[i]);
+                       if (err)
+                               goto ERROR4;
                }
        }
 
@@ -1583,6 +1822,7 @@ static void __devinit it87_init_device(struct platform_device *pdev)
        for (i = 0; i < 3; i++) {
                data->pwm_temp_map[i] = i;
                data->pwm_duty[i] = 0x7f;       /* Full speed */
+               data->auto_pwm[i][3] = 0x7f;    /* Full speed, hard-coded */
        }
 
        /* Some chips seem to have default value 0xff for all limit
@@ -1623,7 +1863,8 @@ static void __devinit it87_init_device(struct platform_device *pdev)
        if ((data->fan_main_ctrl & mask) == 0) {
                /* Enable all fan tachometers */
                data->fan_main_ctrl |= mask;
-               it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
+               it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
+                                data->fan_main_ctrl);
        }
        data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
 
@@ -1661,6 +1902,17 @@ static void it87_update_pwm_ctrl(struct it87_data *data, int nr)
                data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
        else                            /* Manual mode */
                data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f;
+
+       if (has_old_autopwm(data)) {
+               int i;
+
+               for (i = 0; i < 5 ; i++)
+                       data->auto_temp[nr][i] = it87_read_value(data,
+                                               IT87_REG_AUTO_TEMP(nr, i));
+               for (i = 0; i < 3 ; i++)
+                       data->auto_pwm[nr][i] = it87_read_value(data,
+                                               IT87_REG_AUTO_PWM(nr, i));
+       }
 }
 
 static struct it87_data *it87_update_device(struct device *dev)
@@ -1672,24 +1924,22 @@ static struct it87_data *it87_update_device(struct device *dev)
 
        if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
            || !data->valid) {
-
                if (update_vbat) {
                        /* Cleared after each update, so reenable.  Value
-                         returned by this read will be previous value */       
+                          returned by this read will be previous value */
                        it87_write_value(data, IT87_REG_CONFIG,
-                          it87_read_value(data, IT87_REG_CONFIG) | 0x40);
+                               it87_read_value(data, IT87_REG_CONFIG) | 0x40);
                }
                for (i = 0; i <= 7; i++) {
                        data->in[i] =
-                           it87_read_value(data, IT87_REG_VIN(i));
+                               it87_read_value(data, IT87_REG_VIN(i));
                        data->in_min[i] =
-                           it87_read_value(data, IT87_REG_VIN_MIN(i));
+                               it87_read_value(data, IT87_REG_VIN_MIN(i));
                        data->in_max[i] =
-                           it87_read_value(data, IT87_REG_VIN_MAX(i));
+                               it87_read_value(data, IT87_REG_VIN_MAX(i));
                }
                /* in8 (battery) has no limit registers */
-               data->in[8] =
-                   it87_read_value(data, IT87_REG_VIN(8));
+               data->in[8] = it87_read_value(data, IT87_REG_VIN(8));
 
                for (i = 0; i < 5; i++) {
                        /* Skip disabled fans */
@@ -1697,7 +1947,7 @@ static struct it87_data *it87_update_device(struct device *dev)
                                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]);
                        /* Add high byte if in 16-bit mode */
@@ -1710,11 +1960,11 @@ static struct it87_data *it87_update_device(struct device *dev)
                }
                for (i = 0; i < 3; i++) {
                        data->temp[i] =
-                           it87_read_value(data, IT87_REG_TEMP(i));
+                               it87_read_value(data, IT87_REG_TEMP(i));
                        data->temp_high[i] =
-                           it87_read_value(data, IT87_REG_TEMP_HIGH(i));
+                               it87_read_value(data, IT87_REG_TEMP_HIGH(i));
                        data->temp_low[i] =
-                           it87_read_value(data, IT87_REG_TEMP_LOW(i));
+                               it87_read_value(data, IT87_REG_TEMP_LOW(i));
                }
 
                /* Newer chips don't have clock dividers */
@@ -1810,7 +2060,7 @@ exit:
 static int __init sm_it87_init(void)
 {
        int err;
-       unsigned short isa_address=0;
+       unsigned short isa_address = 0;
        struct it87_sio_data sio_data;
 
        memset(&sio_data, 0, sizeof(struct it87_sio_data));
@@ -1822,7 +2072,7 @@ static int __init sm_it87_init(void)
                return err;
 
        err = it87_device_add(isa_address, &sio_data);
-       if (err){
+       if (err) {
                platform_driver_unregister(&it87_driver);
                return err;
        }
@@ -1843,7 +2093,8 @@ 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);
-MODULE_PARM_DESC(fix_pwm_polarity, "Force PWM polarity to active high (DANGEROUS)");
+MODULE_PARM_DESC(fix_pwm_polarity,
+                "Force PWM polarity to active high (DANGEROUS)");
 MODULE_LICENSE("GPL");
 
 module_init(sm_it87_init);