]> git.sur5r.net Git - groeck-it87/blobdiff - it87.c
sync with Jean's generic version. Drop support for unknown/untested chips
[groeck-it87] / it87.c
diff --git a/it87.c b/it87.c
index 6e585f2fa4a6b73a1ffa7b844391c241e4df5124..551fbcc512b71c5d7e81b3c77a1b803a87393882 100644 (file)
--- a/it87.c
+++ b/it87.c
@@ -19,6 +19,7 @@
  *            IT8726F  Super I/O chip w/LPC interface
  *            IT8728F  Super I/O chip w/LPC interface
  *            IT8758E  Super I/O chip w/LPC interface
+ *            IT8782F  Super I/O chip w/LPC interface
  *            IT8783E/F Super I/O chip w/LPC interface
  *            Sis950   A clone of the IT8705F
  *
 #include <linux/dmi.h>
 #include <linux/acpi.h>
 #include <linux/io.h>
+#include <linux/version.h>
+
+#ifndef request_muxed_region
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 28)
+#define request_muxed_region(start,n,name)     __request_region(&ioport_resource, (start), (n), (name))
+#else
+#define IORESOURCE_MUXED       0x00400000
+#define request_muxed_region(start,n,name)     __request_region(&ioport_resource, (start), (n), (name), IORESOURCE_MUXED)
+#endif
+#endif
 
-#ifndef kstrtol
-#define kstrtol strict_strtol
+/* Red Hat EL5 includes backports of these functions, so we can't redefine
+ * our own. */
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 24)
+#if !(defined RHEL_MAJOR && RHEL_MAJOR == 5 && RHEL_MINOR >= 5)
+static inline int strict_strtoul(const char *cp, unsigned int base,
+                                 unsigned long *res)
+{
+       *res = simple_strtoul(cp, NULL, base);
+       return 0;
+}
+
+static inline int strict_strtol(const char *cp, unsigned int base, long *res)
+{
+       *res = simple_strtol(cp, NULL, base);
+       return 0;
+}
+#endif
 #endif
-#ifndef kstrtoul
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39)
 #define kstrtoul strict_strtoul
+#define kstrtol strict_strtol
 #endif
 
 #define DRVNAME "it87"
 
-enum chips { it87, it8712, it8716, it8718, it8720, it8721, it8728, it8783 };
+enum chips { it87, it8712, it8716, it8718, it8720, it8721, it8728, it8782,
+            it8783 };
 
 static unsigned short force_id;
 module_param(force_id, ushort, 0);
@@ -119,10 +148,8 @@ static inline int superio_enter(void)
        /*
         * Try to reserve REG and REG + 1 for exclusive access.
         */
-#ifdef request_muxed_region
        if (!request_muxed_region(REG, 2, DRVNAME))
                return -EBUSY;
-#endif
 
        outb(0x87, REG);
        outb(0x01, REG);
@@ -135,9 +162,7 @@ static inline void superio_exit(void)
 {
        outb(0x02, REG);
        outb(0x02, VAL);
-#ifdef request_muxed_region
        release_region(REG, 2);
-#endif
 }
 
 /* Logical device 4 registers */
@@ -149,6 +174,7 @@ static inline void superio_exit(void)
 #define IT8721F_DEVID 0x8721
 #define IT8726F_DEVID 0x8726
 #define IT8728F_DEVID 0x8728
+#define IT8782F_DEVID 0x8782
 #define IT8783E_DEVID 0x8783
 #define IT87_ACT_REG  0x30
 #define IT87_BASE_REG 0x60
@@ -226,6 +252,7 @@ static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 };
 
 #define IT87_REG_VIN_ENABLE    0x50
 #define IT87_REG_TEMP_ENABLE   0x51
+#define IT87_REG_TEMP_EXTRA    0x55
 #define IT87_REG_BEEP_ENABLE   0x5c
 
 #define IT87_REG_CHIPID        0x58
@@ -242,9 +269,11 @@ struct it87_sio_data {
        u8 beep_pin;
        u8 internal;    /* Internal sensors can be labeled */
        /* Features skipped based on config or DMI */
+       u16 skip_in;
        u8 skip_vid;
        u8 skip_fan;
        u8 skip_pwm;
+       u8 skip_temp;
 };
 
 /*
@@ -269,6 +298,7 @@ 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 has_temp;            /* Bitfield, temp sensors enabled */
        s8 temp[3];             /* Register value */
        s8 temp_high[3];        /* Register value */
        s8 temp_low[3];         /* Register value */
@@ -320,39 +350,23 @@ static inline int has_newer_autopwm(const struct it87_data *data)
            || data->type == it8728;
 }
 
-static u8 in_to_reg(const struct it87_data *data, int nr, long val)
+static int adc_lsb(const struct it87_data *data, int nr)
 {
-       long lsb;
-
-       if (has_12mv_adc(data)) {
-               if (data->in_scaled & (1 << nr))
-                       lsb = 24;
-               else
-                       lsb = 12;
-       } else {
-               if (data->in_scaled & (1 << nr))
-                       lsb = 32;
-               else
-                       lsb = 16;
-       }
+       int lsb = has_12mv_adc(data) ? 12 : 16;
+       if (data->in_scaled & (1 << nr))
+               lsb <<= 1;
+       return lsb;
+}
 
-       val = DIV_ROUND_CLOSEST(val, lsb);
+static u8 in_to_reg(const struct it87_data *data, int nr, long val)
+{
+       val = DIV_ROUND_CLOSEST(val, adc_lsb(data, nr));
        return SENSORS_LIMIT(val, 0, 255);
 }
 
 static int in_from_reg(const struct it87_data *data, int nr, int val)
 {
-       if (has_12mv_adc(data)) {
-               if (data->in_scaled & (1 << nr))
-                       return val * 24;
-               else
-                       return val * 12;
-       } else {
-               if (data->in_scaled & (1 << nr))
-                       return val * 32;
-               else
-                       return val * 16;
-       }
+       return val * adc_lsb(data, nr);
 }
 
 static inline u8 FAN_TO_REG(long rpm, int div)
@@ -432,6 +446,7 @@ static inline int has_16bit_fans(const struct it87_data *data)
            || data->type == it8720
            || data->type == it8721
            || data->type == it8728
+           || data->type == it8782
            || data->type == it8783;
 }
 
@@ -1394,57 +1409,103 @@ static ssize_t show_name(struct device *dev, struct device_attribute
 }
 static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
 
-static struct attribute *it87_attributes[] = {
+static struct attribute *it87_attributes_in[9][5] = {
+{
        &sensor_dev_attr_in0_input.dev_attr.attr,
-       &sensor_dev_attr_in1_input.dev_attr.attr,
-       &sensor_dev_attr_in2_input.dev_attr.attr,
-       &sensor_dev_attr_in3_input.dev_attr.attr,
-       &sensor_dev_attr_in4_input.dev_attr.attr,
-       &sensor_dev_attr_in5_input.dev_attr.attr,
-       &sensor_dev_attr_in6_input.dev_attr.attr,
-       &sensor_dev_attr_in7_input.dev_attr.attr,
-       &sensor_dev_attr_in8_input.dev_attr.attr,
        &sensor_dev_attr_in0_min.dev_attr.attr,
-       &sensor_dev_attr_in1_min.dev_attr.attr,
-       &sensor_dev_attr_in2_min.dev_attr.attr,
-       &sensor_dev_attr_in3_min.dev_attr.attr,
-       &sensor_dev_attr_in4_min.dev_attr.attr,
-       &sensor_dev_attr_in5_min.dev_attr.attr,
-       &sensor_dev_attr_in6_min.dev_attr.attr,
-       &sensor_dev_attr_in7_min.dev_attr.attr,
        &sensor_dev_attr_in0_max.dev_attr.attr,
-       &sensor_dev_attr_in1_max.dev_attr.attr,
-       &sensor_dev_attr_in2_max.dev_attr.attr,
-       &sensor_dev_attr_in3_max.dev_attr.attr,
-       &sensor_dev_attr_in4_max.dev_attr.attr,
-       &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,
+       NULL
+}, {
+       &sensor_dev_attr_in1_input.dev_attr.attr,
+       &sensor_dev_attr_in1_min.dev_attr.attr,
+       &sensor_dev_attr_in1_max.dev_attr.attr,
        &sensor_dev_attr_in1_alarm.dev_attr.attr,
+       NULL
+}, {
+       &sensor_dev_attr_in2_input.dev_attr.attr,
+       &sensor_dev_attr_in2_min.dev_attr.attr,
+       &sensor_dev_attr_in2_max.dev_attr.attr,
        &sensor_dev_attr_in2_alarm.dev_attr.attr,
+       NULL
+}, {
+       &sensor_dev_attr_in3_input.dev_attr.attr,
+       &sensor_dev_attr_in3_min.dev_attr.attr,
+       &sensor_dev_attr_in3_max.dev_attr.attr,
        &sensor_dev_attr_in3_alarm.dev_attr.attr,
+       NULL
+}, {
+       &sensor_dev_attr_in4_input.dev_attr.attr,
+       &sensor_dev_attr_in4_min.dev_attr.attr,
+       &sensor_dev_attr_in4_max.dev_attr.attr,
        &sensor_dev_attr_in4_alarm.dev_attr.attr,
+       NULL
+}, {
+       &sensor_dev_attr_in5_input.dev_attr.attr,
+       &sensor_dev_attr_in5_min.dev_attr.attr,
+       &sensor_dev_attr_in5_max.dev_attr.attr,
        &sensor_dev_attr_in5_alarm.dev_attr.attr,
+       NULL
+}, {
+       &sensor_dev_attr_in6_input.dev_attr.attr,
+       &sensor_dev_attr_in6_min.dev_attr.attr,
+       &sensor_dev_attr_in6_max.dev_attr.attr,
        &sensor_dev_attr_in6_alarm.dev_attr.attr,
+       NULL
+}, {
+       &sensor_dev_attr_in7_input.dev_attr.attr,
+       &sensor_dev_attr_in7_min.dev_attr.attr,
+       &sensor_dev_attr_in7_max.dev_attr.attr,
        &sensor_dev_attr_in7_alarm.dev_attr.attr,
+       NULL
+}, {
+       &sensor_dev_attr_in8_input.dev_attr.attr,
+       NULL
+} };
+
+static const struct attribute_group it87_group_in[9] = {
+       { .attrs = it87_attributes_in[0] },
+       { .attrs = it87_attributes_in[1] },
+       { .attrs = it87_attributes_in[2] },
+       { .attrs = it87_attributes_in[3] },
+       { .attrs = it87_attributes_in[4] },
+       { .attrs = it87_attributes_in[5] },
+       { .attrs = it87_attributes_in[6] },
+       { .attrs = it87_attributes_in[7] },
+       { .attrs = it87_attributes_in[8] },
+};
 
+static struct attribute *it87_attributes_temp[3][6] = {
+{
        &sensor_dev_attr_temp1_input.dev_attr.attr,
-       &sensor_dev_attr_temp2_input.dev_attr.attr,
-       &sensor_dev_attr_temp3_input.dev_attr.attr,
        &sensor_dev_attr_temp1_max.dev_attr.attr,
-       &sensor_dev_attr_temp2_max.dev_attr.attr,
-       &sensor_dev_attr_temp3_max.dev_attr.attr,
        &sensor_dev_attr_temp1_min.dev_attr.attr,
-       &sensor_dev_attr_temp2_min.dev_attr.attr,
-       &sensor_dev_attr_temp3_min.dev_attr.attr,
        &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,
+       NULL
+} , {
+       &sensor_dev_attr_temp2_input.dev_attr.attr,
+       &sensor_dev_attr_temp2_max.dev_attr.attr,
+       &sensor_dev_attr_temp2_min.dev_attr.attr,
+       &sensor_dev_attr_temp2_type.dev_attr.attr,
        &sensor_dev_attr_temp2_alarm.dev_attr.attr,
+       NULL
+} , {
+       &sensor_dev_attr_temp3_input.dev_attr.attr,
+       &sensor_dev_attr_temp3_max.dev_attr.attr,
+       &sensor_dev_attr_temp3_min.dev_attr.attr,
+       &sensor_dev_attr_temp3_type.dev_attr.attr,
        &sensor_dev_attr_temp3_alarm.dev_attr.attr,
+       NULL
+} };
 
+static const struct attribute_group it87_group_temp[3] = {
+       { .attrs = it87_attributes_temp[0] },
+       { .attrs = it87_attributes_temp[1] },
+       { .attrs = it87_attributes_temp[2] },
+};
+
+static struct attribute *it87_attributes[] = {
        &dev_attr_alarms.attr,
        &sensor_dev_attr_intrusion0_alarm.dev_attr.attr,
        &dev_attr_name.attr,
@@ -1455,7 +1516,7 @@ static const struct attribute_group it87_group = {
        .attrs = it87_attributes,
 };
 
-static struct attribute *it87_attributes_beep[] = {
+static struct attribute *it87_attributes_in_beep[] = {
        &sensor_dev_attr_in0_beep.dev_attr.attr,
        &sensor_dev_attr_in1_beep.dev_attr.attr,
        &sensor_dev_attr_in2_beep.dev_attr.attr,
@@ -1464,15 +1525,13 @@ static struct attribute *it87_attributes_beep[] = {
        &sensor_dev_attr_in5_beep.dev_attr.attr,
        &sensor_dev_attr_in6_beep.dev_attr.attr,
        &sensor_dev_attr_in7_beep.dev_attr.attr,
+       NULL
+};
 
+static struct attribute *it87_attributes_temp_beep[] = {
        &sensor_dev_attr_temp1_beep.dev_attr.attr,
        &sensor_dev_attr_temp2_beep.dev_attr.attr,
        &sensor_dev_attr_temp3_beep.dev_attr.attr,
-       NULL
-};
-
-static const struct attribute_group it87_group_beep = {
-       .attrs = it87_attributes_beep,
 };
 
 static struct attribute *it87_attributes_fan16[5][3+1] = { {
@@ -1676,6 +1735,9 @@ static int __init it87_find(unsigned short *address,
        case IT8728F_DEVID:
                sio_data->type = it8728;
                break;
+       case IT8782F_DEVID:
+               sio_data->type = it8782;
+               break;
        case IT8783E_DEVID:
                sio_data->type = it8783;
                break;
@@ -1742,23 +1804,37 @@ static int __init it87_find(unsigned short *address,
 
                /* VIN5 */
                if ((reg27 & (1 << 0)) || (reg2C & (1 << 2)))
-                       ; /* No VIN5 */
+                       sio_data->skip_in |= (1 << 5); /* No VIN5 */
 
                /* VIN6 */
-               if ((reg27 & (1 << 1)) || (reg2C & (1 << 2)))
-                       ; /* No VIN6 */
+               if (reg27 & (1 << 1))
+                       sio_data->skip_in |= (1 << 6); /* No VIN6 */
 
-               /* VIN7 */
-               if ((reg27 & (1 << 2)) || (reg2C & (1 << 2))) {
+               /*
+                * VIN7
+                * Does not depend on bit 2 of Reg2C, contrary to datasheet.
+                */
+               if (reg27 & (1 << 2)) {
                        /*
-                        * If the external VIN7 pin is disabled, route it to the
-                        * internal VCCH5V if that is not already done.
+                        * The data sheet is a bit unclear regarding the
+                        * internal voltage divider for VCCH5V. It says
+                        * "This bit enables and switches VIN7 (pin 91) to the
+                        * internal voltage divider for VCCH5V".
+                        * This is different to other chips, where the internal
+                        * voltage divider would connect VIN7 to an internal
+                        * voltage source. Maybe that is the case here as well.
+                        *
+                        * Since we don't know for sure, re-route it if that is
+                        * not the case, and ask the user to report if the
+                        * resulting voltage is sane.
                         */
                        if (!(reg2C & (1 << 1))) {
                                reg2C |= (1 << 1);
                                superio_outb(IT87_SIO_PINX2_REG, reg2C);
-                               pr_notice("Routing internal VCCH to in7\n");
+                               pr_notice("Routing internal VCCH5V to in7.\n");
                        }
+                       pr_notice("in7 routed to internal voltage divider, with external pin disabled.\n");
+                       pr_notice("Please report if it displays a reasonable voltage.\n");
                }
 
                if (reg2C & (1 << 0))
@@ -1770,13 +1846,15 @@ static int __init it87_find(unsigned short *address,
 
        } else {
                int reg;
+               bool uart6;
 
                superio_select(GPIO);
 
                reg = superio_inb(IT87_SIO_GPIO3_REG);
-               if (sio_data->type == it8721 || sio_data->type == it8728) {
+               if (sio_data->type == it8721 || sio_data->type == it8728 ||
+                   sio_data->type == it8782) {
                        /*
-                        * The IT8721F/IT8758E/IT8783E/F don't have VID pins
+                        * IT8721F/IT8758E, and IT8782F don't have VID pins
                         * at all, not sure about the IT8728F.
                         */
                        sio_data->skip_vid = 1;
@@ -1806,6 +1884,9 @@ static int __init it87_find(unsigned short *address,
                        sio_data->vid_value = superio_inb(IT87_SIO_VID_REG);
 
                reg = superio_inb(IT87_SIO_PINX2_REG);
+
+               uart6 = sio_data->type == it8782 && (reg & (1 << 2));
+
                /*
                 * The IT8720F has no VIN7 pin, so VCCH should always be
                 * routed internally to VIN7 with an internal divider.
@@ -1815,8 +1896,12 @@ static int __init it87_find(unsigned short *address,
                 * configured, even though the IT8720F datasheet claims
                 * that the internal routing of VCCH to VIN7 is the default
                 * setting. So we force the internal routing in this case.
+                *
+                * On IT8782F, VIN7 is multiplexed with one of the UART6 pins.
+                * If UART6 is enabled, re-route VIN7 to the internal divider
+                * if that is not already the case.
                 */
-               if (sio_data->type == it8720 && !(reg & (1 << 1))) {
+               if ((sio_data->type == it8720 || uart6) && !(reg & (1 << 1))) {
                        reg |= (1 << 1);
                        superio_outb(IT87_SIO_PINX2_REG, reg);
                        pr_notice("Routing internal VCCH to in7\n");
@@ -1827,6 +1912,20 @@ static int __init it87_find(unsigned short *address,
                    sio_data->type == it8728)
                        sio_data->internal |= (1 << 1);
 
+               /*
+                * On IT8782F, UART6 pins overlap with VIN5, VIN6, and VIN7.
+                * While VIN7 can be routed to the internal voltage divider,
+                * VIN5 and VIN6 are not available if UART6 is enabled.
+                *
+                * Also, temp3 is not available if UART6 is enabled and TEMPIN3
+                * is the temperature source. Since we can not read the
+                * temperature source here, skip_temp is preliminary.
+                */
+               if (uart6) {
+                       sio_data->skip_in |= (1 << 5) | (1 << 6);
+                       sio_data->skip_temp |= (1 << 2);
+               }
+
                sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
        }
        if (sio_data->beep_pin)
@@ -1864,8 +1963,22 @@ static void it87_remove_files(struct device *dev)
        int i;
 
        sysfs_remove_group(&dev->kobj, &it87_group);
-       if (sio_data->beep_pin)
-               sysfs_remove_group(&dev->kobj, &it87_group_beep);
+       for (i = 0; i < 9; i++) {
+               if (sio_data->skip_in & (1 << i))
+                       continue;
+               sysfs_remove_group(&dev->kobj, &it87_group_in[i]);
+               if (it87_attributes_in_beep[i])
+                       sysfs_remove_file(&dev->kobj,
+                                         it87_attributes_in_beep[i]);
+       }
+       for (i = 0; i < 3; i++) {
+               if (!(data->has_temp & (1 << i)))
+                       continue;
+               sysfs_remove_group(&dev->kobj, &it87_group_temp[i]);
+               if (sio_data->beep_pin)
+                       sysfs_remove_file(&dev->kobj,
+                                         it87_attributes_temp_beep[i]);
+       }
        for (i = 0; i < 5; i++) {
                if (!(data->has_fan & (1 << i)))
                        continue;
@@ -1905,23 +2018,22 @@ static int __devinit it87_probe(struct platform_device *pdev)
                "it8720",
                "it8721",
                "it8728",
+               "it8782",
                "it8783",
        };
 
        res = platform_get_resource(pdev, IORESOURCE_IO, 0);
-       if (!request_region(res->start, IT87_EC_EXTENT, DRVNAME)) {
+       if (!devm_request_region(&pdev->dev, 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_EC_EXTENT - 1));
-               err = -EBUSY;
-               goto ERROR0;
+               return -EBUSY;
        }
 
-       data = kzalloc(sizeof(struct it87_data), GFP_KERNEL);
-       if (!data) {
-               err = -ENOMEM;
-               goto ERROR1;
-       }
+       data = devm_kzalloc(&pdev->dev, sizeof(struct it87_data), GFP_KERNEL);
+       if (!data)
+               return -ENOMEM;
 
        data->addr = res->start;
        data->type = sio_data->type;
@@ -1930,10 +2042,8 @@ static int __devinit it87_probe(struct platform_device *pdev)
 
        /* Now, we do the remaining detection. */
        if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80)
-        || it87_read_value(data, IT87_REG_CHIPID) != 0x90) {
-               err = -ENODEV;
-               goto ERROR2;
-       }
+        || it87_read_value(data, IT87_REG_CHIPID) != 0x90)
+               return -ENODEV;
 
        platform_set_drvdata(pdev, data);
 
@@ -1950,25 +2060,54 @@ static int __devinit it87_probe(struct platform_device *pdev)
                        data->in_scaled |= (1 << 7);    /* in7 is VSB */
                if (sio_data->internal & (1 << 2))
                        data->in_scaled |= (1 << 8);    /* in8 is Vbat */
-       } else if (sio_data->type == it8783) {
+       } else if (sio_data->type == it8782 || sio_data->type == it8783) {
                if (sio_data->internal & (1 << 0))
                        data->in_scaled |= (1 << 3);    /* in3 is VCC5V */
                if (sio_data->internal & (1 << 1))
                        data->in_scaled |= (1 << 7);    /* in7 is VCCH5V */
        }
 
+       data->has_temp = 0x07;
+       if (sio_data->skip_temp & (1 << 2)) {
+               if (sio_data->type == it8782
+                   && !(it87_read_value(data, IT87_REG_TEMP_EXTRA) & 0x80))
+                       data->has_temp &= ~(1 << 2);
+       }
+
        /* Initialize the IT87 chip */
        it87_init_device(pdev);
 
        /* Register sysfs hooks */
        err = sysfs_create_group(&dev->kobj, &it87_group);
        if (err)
-               goto ERROR2;
+               return err;
 
-       if (sio_data->beep_pin) {
-               err = sysfs_create_group(&dev->kobj, &it87_group_beep);
+       for (i = 0; i < 9; i++) {
+               if (sio_data->skip_in & (1 << i))
+                       continue;
+               err = sysfs_create_group(&dev->kobj, &it87_group_in[i]);
                if (err)
                        goto ERROR4;
+               if (sio_data->beep_pin && it87_attributes_in_beep[i]) {
+                       err = sysfs_create_file(&dev->kobj,
+                                               it87_attributes_in_beep[i]);
+                       if (err)
+                               goto ERROR4;
+               }
+       }
+
+       for (i = 0; i < 3; i++) {
+               if (!(data->has_temp & (1 << i)))
+                       continue;
+               err = sysfs_create_group(&dev->kobj, &it87_group_temp[i]);
+               if (err)
+                       goto ERROR4;
+               if (sio_data->beep_pin) {
+                       err = sysfs_create_file(&dev->kobj,
+                                               it87_attributes_temp_beep[i]);
+                       if (err)
+                               goto ERROR4;
+               }
        }
 
        /* Do not create fan files for disabled fans */
@@ -2050,12 +2189,6 @@ static int __devinit it87_probe(struct platform_device *pdev)
 
 ERROR4:
        it87_remove_files(dev);
-ERROR2:
-       platform_set_drvdata(pdev, NULL);
-       kfree(data);
-ERROR1:
-       release_region(res->start, IT87_EC_EXTENT);
-ERROR0:
        return err;
 }
 
@@ -2066,10 +2199,6 @@ static int __devexit it87_remove(struct platform_device *pdev)
        hwmon_device_unregister(data->hwmon_dev);
        it87_remove_files(&pdev->dev);
 
-       release_region(data->addr, IT87_EC_EXTENT);
-       platform_set_drvdata(pdev, NULL);
-       kfree(data);
-
        return 0;
 }
 
@@ -2231,8 +2360,9 @@ 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) {
+               /* IT8705F, IT8782F, and IT8783E/F only support three fans. */
+               if (data->type != it87 && data->type != it8782 &&
+                   data->type != it8783) {
                        if (tmp & (1 << 4))
                                data->has_fan |= (1 << 3); /* fan4 enabled */
                        if (tmp & (1 << 5))
@@ -2321,6 +2451,8 @@ static struct it87_data *it87_update_device(struct device *dev)
                        }
                }
                for (i = 0; i < 3; i++) {
+                       if (!(data->has_temp & (1 << i)))
+                               continue;
                        data->temp[i] =
                                it87_read_value(data, IT87_REG_TEMP(i));
                        data->temp_high[i] =