]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/hwmon/w83781d.c
hwmon: (w83781d) Refactor beep enable handling
[linux-2.6-omap-h63xx.git] / drivers / hwmon / w83781d.c
index f85b48fea1c4700d566edd5413ed265ec4e382b9..136bec3fd64542f952e7325c17805ac306249e3a 100644 (file)
@@ -28,7 +28,6 @@
     as99127f   7       3       0       3       0x31    0x12c3  yes     no
     as99127f rev.2 (type_name = as99127f)      0x31    0x5ca3  yes     no
     w83781d    7       3       0       3       0x10-1  0x5ca3  yes     yes
-    w83627hf   9       3       2       3       0x21    0x5ca3  yes     yes(LPC)
     w83782d    9       3       2-4     3       0x30    0x5ca3  yes     yes
     w83783s    5-6     3       2       1-2     0x40    0x5ca3  yes     no
 
 static struct platform_device *pdev;
 
 /* Addresses to scan */
-static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25,
-                                       0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
-                                       0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END };
+static const unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
+                                               0x2e, 0x2f, I2C_CLIENT_END };
 static unsigned short isa_address = 0x290;
 
 /* Insmod parameters */
-I2C_CLIENT_INSMOD_5(w83781d, w83782d, w83783s, w83627hf, as99127f);
+I2C_CLIENT_INSMOD_4(w83781d, w83782d, w83783s, as99127f);
 I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: "
                    "{bus, clientaddr, subclientaddr1, subclientaddr2}");
 
@@ -114,7 +112,7 @@ MODULE_PARM_DESC(init, "Set to zero to bypass chip initialization");
 #define W83781D_REG_ALARM1             0x41
 #define W83781D_REG_ALARM2             0x42
 
-/* Real-time status (W83782D, W83783S, W83627HF) */
+/* Real-time status (W83782D, W83783S) */
 #define W83782D_REG_ALARM1             0x459
 #define W83782D_REG_ALARM2             0x45A
 #define W83782D_REG_ALARM3             0x45B
@@ -153,10 +151,6 @@ static const u8 BIT_SCFG2[] = { 0x10, 0x20, 0x40 };
 
 #define W83781D_DEFAULT_BETA           3435
 
-/* RT Table registers */
-#define W83781D_REG_RT_IDX             0x50
-#define W83781D_REG_RT_VAL             0x51
-
 /* Conversions */
 #define IN_TO_REG(val)                 SENSORS_LIMIT(((val) + 8) / 16, 0, 255)
 #define IN_FROM_REG(val)               ((val) * 16)
@@ -184,9 +178,9 @@ FAN_FROM_REG(u8 val, int div)
 #define TEMP_FROM_REG(val)             ((val) * 1000)
 
 #define BEEP_MASK_FROM_REG(val,type)   ((type) == as99127f ? \
-                                        (val) ^ 0x7fff : (val))
+                                        (~(val)) & 0x7fff : (val) & 0xff7fff)
 #define BEEP_MASK_TO_REG(val,type)     ((type) == as99127f ? \
-                                        (~(val)) & 0x7fff : (val) & 0xffffff)
+                                        (~(val)) & 0x7fff : (val) & 0xff7fff)
 
 #define DIV_FROM_REG(val)              (1 << (val))
 
@@ -220,7 +214,7 @@ DIV_TO_REG(long val, enum chips type)
    the driver field to differentiate between I2C and ISA chips. */
 struct w83781d_data {
        struct i2c_client client;
-       struct class_device *class_dev;
+       struct device *hwmon_dev;
        struct mutex lock;
        enum chips type;
 
@@ -246,14 +240,11 @@ struct w83781d_data {
        u8 vid;                 /* Register encoding, combined */
        u32 alarms;             /* Register encoding, combined */
        u32 beep_mask;          /* Register encoding, combined */
-       u8 beep_enable;         /* Boolean */
        u8 pwm[4];              /* Register value */
        u8 pwm2_enable;         /* Boolean */
        u16 sens[3];            /* 782D/783S only.
                                   1 = pentium diode; 2 = 3904 diode;
-                                  3000-5000 = thermistor beta.
-                                  Default = 3435. 
-                                  Other Betas unimplemented */
+                                  4 = thermistor */
        u8 vrm;
 };
 
@@ -273,7 +264,6 @@ static struct i2c_driver w83781d_driver = {
        .driver = {
                .name = "w83781d",
        },
-       .id = I2C_DRIVERID_W83781D,
        .attach_adapter = w83781d_attach_adapter,
        .detach_client = w83781d_detach_client,
 };
@@ -410,7 +400,7 @@ static ssize_t store_temp_##reg (struct device *dev, \
        struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
        struct w83781d_data *data = dev_get_drvdata(dev); \
        int nr = attr->index; \
-       s32 val; \
+       long val; \
         \
        val = simple_strtol(buf, NULL, 10); \
         \
@@ -456,7 +446,7 @@ static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
 static ssize_t
 show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
 {
-       struct w83781d_data *data = w83781d_update_device(dev);
+       struct w83781d_data *data = dev_get_drvdata(dev);
        return sprintf(buf, "%ld\n", (long) data->vrm);
 }
 
@@ -483,16 +473,44 @@ show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
 
 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
 
-static ssize_t show_beep_mask (struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
+               char *buf)
 {
        struct w83781d_data *data = w83781d_update_device(dev);
-       return sprintf(buf, "%ld\n",
-                      (long)BEEP_MASK_FROM_REG(data->beep_mask, data->type));
+       int bitnr = to_sensor_dev_attr(attr)->index;
+       return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
 }
-static ssize_t show_beep_enable (struct device *dev, struct device_attribute *attr, char *buf)
+
+/* The W83781D has a single alarm bit for temp2 and temp3 */
+static ssize_t show_temp3_alarm(struct device *dev,
+               struct device_attribute *attr, char *buf)
 {
        struct w83781d_data *data = w83781d_update_device(dev);
-       return sprintf(buf, "%ld\n", (long)data->beep_enable);
+       int bitnr = (data->type == w83781d) ? 5 : 13;
+       return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
+}
+
+static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
+static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
+static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
+static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
+static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
+static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9);
+static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 10);
+static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 16);
+static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 17);
+static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6);
+static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7);
+static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11);
+static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
+static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
+static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_temp3_alarm, NULL, 0);
+
+static ssize_t show_beep_mask (struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct w83781d_data *data = w83781d_update_device(dev);
+       return sprintf(buf, "%ld\n",
+                      (long)BEEP_MASK_FROM_REG(data->beep_mask, data->type));
 }
 
 static ssize_t
@@ -505,12 +523,12 @@ store_beep_mask(struct device *dev, struct device_attribute *attr,
        val = simple_strtoul(buf, NULL, 10);
 
        mutex_lock(&data->update_lock);
-       data->beep_mask = BEEP_MASK_TO_REG(val, data->type);
+       data->beep_mask &= 0x8000; /* preserve beep enable */
+       data->beep_mask |= BEEP_MASK_TO_REG(val, data->type);
        w83781d_write_value(data, W83781D_REG_BEEP_INTS1,
                            data->beep_mask & 0xff);
        w83781d_write_value(data, W83781D_REG_BEEP_INTS2,
-                           ((data->beep_mask >> 8) & 0x7f)
-                           | data->beep_enable << 7);
+                           (data->beep_mask >> 8) & 0xff);
        if (data->type != w83781d && data->type != as99127f) {
                w83781d_write_value(data, W83781D_REG_BEEP_INTS3,
                                    ((data->beep_mask) >> 16) & 0xff);
@@ -520,31 +538,104 @@ store_beep_mask(struct device *dev, struct device_attribute *attr,
        return count;
 }
 
+static DEVICE_ATTR(beep_mask, S_IRUGO | S_IWUSR,
+               show_beep_mask, store_beep_mask);
+
+static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
+               char *buf)
+{
+       struct w83781d_data *data = w83781d_update_device(dev);
+       int bitnr = to_sensor_dev_attr(attr)->index;
+       return sprintf(buf, "%u\n", (data->beep_mask >> bitnr) & 1);
+}
+
 static ssize_t
-store_beep_enable(struct device *dev, struct device_attribute *attr,
+store_beep(struct device *dev, struct device_attribute *attr,
                const char *buf, size_t count)
 {
        struct w83781d_data *data = dev_get_drvdata(dev);
-       u32 val;
+       int bitnr = to_sensor_dev_attr(attr)->index;
+       unsigned long bit;
+       u8 reg;
 
-       val = simple_strtoul(buf, NULL, 10);
-       if (val != 0 && val != 1)
+       bit = simple_strtoul(buf, NULL, 10);
+       if (bit & ~1)
                return -EINVAL;
 
        mutex_lock(&data->update_lock);
-       data->beep_enable = val;
-       val = w83781d_read_value(data, W83781D_REG_BEEP_INTS2) & 0x7f;
-       val |= data->beep_enable << 7;
-       w83781d_write_value(data, W83781D_REG_BEEP_INTS2, val);
+       if (bit)
+               data->beep_mask |= (1 << bitnr);
+       else
+               data->beep_mask &= ~(1 << bitnr);
+
+       if (bitnr < 8) {
+               reg = w83781d_read_value(data, W83781D_REG_BEEP_INTS1);
+               if (bit)
+                       reg |= (1 << bitnr);
+               else
+                       reg &= ~(1 << bitnr);
+               w83781d_write_value(data, W83781D_REG_BEEP_INTS1, reg);
+       } else if (bitnr < 16) {
+               reg = w83781d_read_value(data, W83781D_REG_BEEP_INTS2);
+               if (bit)
+                       reg |= (1 << (bitnr - 8));
+               else
+                       reg &= ~(1 << (bitnr - 8));
+               w83781d_write_value(data, W83781D_REG_BEEP_INTS2, reg);
+       } else {
+               reg = w83781d_read_value(data, W83781D_REG_BEEP_INTS3);
+               if (bit)
+                       reg |= (1 << (bitnr - 16));
+               else
+                       reg &= ~(1 << (bitnr - 16));
+               w83781d_write_value(data, W83781D_REG_BEEP_INTS3, reg);
+       }
        mutex_unlock(&data->update_lock);
 
        return count;
 }
 
-static DEVICE_ATTR(beep_mask, S_IRUGO | S_IWUSR,
-               show_beep_mask, store_beep_mask);
-static DEVICE_ATTR(beep_enable, S_IRUGO | S_IWUSR,
-               show_beep_enable, store_beep_enable);
+/* The W83781D has a single beep bit for temp2 and temp3 */
+static ssize_t show_temp3_beep(struct device *dev,
+               struct device_attribute *attr, char *buf)
+{
+       struct w83781d_data *data = w83781d_update_device(dev);
+       int bitnr = (data->type == w83781d) ? 5 : 13;
+       return sprintf(buf, "%u\n", (data->beep_mask >> bitnr) & 1);
+}
+
+static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 0);
+static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 1);
+static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 2);
+static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 3);
+static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 8);
+static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 9);
+static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 10);
+static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 16);
+static SENSOR_DEVICE_ATTR(in8_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 17);
+static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 6);
+static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 7);
+static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 11);
+static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 4);
+static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 5);
+static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO,
+                       show_temp3_beep, store_beep, 13);
+static SENSOR_DEVICE_ATTR(beep_enable, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 15);
 
 static ssize_t
 show_fan_div(struct device *dev, struct device_attribute *da, char *buf)
@@ -571,7 +662,7 @@ store_fan_div(struct device *dev, struct device_attribute *da,
        unsigned long val = simple_strtoul(buf, NULL, 10);
 
        mutex_lock(&data->update_lock);
-       
+
        /* Save fan_min */
        min = FAN_FROM_REG(data->fan_min[nr],
                           DIV_FROM_REG(data->fan_div[nr]));
@@ -721,15 +812,19 @@ store_sensor(struct device *dev, struct device_attribute *da,
                                    tmp & ~BIT_SCFG2[nr]);
                data->sens[nr] = val;
                break;
-       case W83781D_DEFAULT_BETA:      /* thermistor */
+       case W83781D_DEFAULT_BETA:
+               dev_warn(dev, "Sensor type %d is deprecated, please use 4 "
+                        "instead\n", W83781D_DEFAULT_BETA);
+               /* fall through */
+       case 4:         /* thermistor */
                tmp = w83781d_read_value(data, W83781D_REG_SCFG1);
                w83781d_write_value(data, W83781D_REG_SCFG1,
                                    tmp & ~BIT_SCFG1[nr]);
                data->sens[nr] = val;
                break;
        default:
-               dev_err(dev, "Invalid sensor type %ld; must be 1, 2, or %d\n",
-                      (long) val, W83781D_DEFAULT_BETA);
+               dev_err(dev, "Invalid sensor type %ld; must be 1, 2, or 4\n",
+                      (long) val);
                break;
        }
 
@@ -740,9 +835,9 @@ store_sensor(struct device *dev, struct device_attribute *da,
 static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR,
        show_sensor, store_sensor, 0);
 static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR,
-       show_sensor, store_sensor, 0);
+       show_sensor, store_sensor, 1);
 static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR,
-       show_sensor, store_sensor, 0);
+       show_sensor, store_sensor, 2);
 
 /* I2C devices get this name attribute automatically, but for ISA devices
    we must create it by ourselves. */
@@ -834,8 +929,6 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind,
                client_name = "w83782d subclient";
        else if (kind == w83783s)
                client_name = "w83783s subclient";
-       else if (kind == w83627hf)
-               client_name = "w83627hf subclient";
        else if (kind == as99127f)
                client_name = "as99127f subclient";
 
@@ -875,17 +968,23 @@ ERROR_SC_0:
 #define IN_UNIT_ATTRS(X)                                       \
        &sensor_dev_attr_in##X##_input.dev_attr.attr,           \
        &sensor_dev_attr_in##X##_min.dev_attr.attr,             \
-       &sensor_dev_attr_in##X##_max.dev_attr.attr
+       &sensor_dev_attr_in##X##_max.dev_attr.attr,             \
+       &sensor_dev_attr_in##X##_alarm.dev_attr.attr,           \
+       &sensor_dev_attr_in##X##_beep.dev_attr.attr
 
 #define FAN_UNIT_ATTRS(X)                                      \
        &sensor_dev_attr_fan##X##_input.dev_attr.attr,          \
        &sensor_dev_attr_fan##X##_min.dev_attr.attr,            \
-       &sensor_dev_attr_fan##X##_div.dev_attr.attr
+       &sensor_dev_attr_fan##X##_div.dev_attr.attr,            \
+       &sensor_dev_attr_fan##X##_alarm.dev_attr.attr,          \
+       &sensor_dev_attr_fan##X##_beep.dev_attr.attr
 
 #define TEMP_UNIT_ATTRS(X)                                     \
        &sensor_dev_attr_temp##X##_input.dev_attr.attr,         \
        &sensor_dev_attr_temp##X##_max.dev_attr.attr,           \
-       &sensor_dev_attr_temp##X##_max_hyst.dev_attr.attr
+       &sensor_dev_attr_temp##X##_max_hyst.dev_attr.attr,      \
+       &sensor_dev_attr_temp##X##_alarm.dev_attr.attr,         \
+       &sensor_dev_attr_temp##X##_beep.dev_attr.attr
 
 static struct attribute* w83781d_attributes[] = {
        IN_UNIT_ATTRS(0),
@@ -903,7 +1002,7 @@ static struct attribute* w83781d_attributes[] = {
        &dev_attr_vrm.attr,
        &dev_attr_alarms.attr,
        &dev_attr_beep_mask.attr,
-       &dev_attr_beep_enable.attr,
+       &sensor_dev_attr_beep_enable.dev_attr.attr,
        NULL
 };
 static const struct attribute_group w83781d_group = {
@@ -944,7 +1043,11 @@ w83781d_create_files(struct device *dev, int kind, int is_isa)
                    || (err = device_create_file(dev,
                                &sensor_dev_attr_in1_min.dev_attr))
                    || (err = device_create_file(dev,
-                               &sensor_dev_attr_in1_max.dev_attr)))
+                               &sensor_dev_attr_in1_max.dev_attr))
+                   || (err = device_create_file(dev,
+                               &sensor_dev_attr_in1_alarm.dev_attr))
+                   || (err = device_create_file(dev,
+                               &sensor_dev_attr_in1_beep.dev_attr)))
                        return err;
        }
        if (kind != as99127f && kind != w83781d && kind != w83783s) {
@@ -954,12 +1057,20 @@ w83781d_create_files(struct device *dev, int kind, int is_isa)
                                &sensor_dev_attr_in7_min.dev_attr))
                    || (err = device_create_file(dev,
                                &sensor_dev_attr_in7_max.dev_attr))
+                   || (err = device_create_file(dev,
+                               &sensor_dev_attr_in7_alarm.dev_attr))
+                   || (err = device_create_file(dev,
+                               &sensor_dev_attr_in7_beep.dev_attr))
                    || (err = device_create_file(dev,
                                &sensor_dev_attr_in8_input.dev_attr))
                    || (err = device_create_file(dev,
                                &sensor_dev_attr_in8_min.dev_attr))
                    || (err = device_create_file(dev,
-                               &sensor_dev_attr_in8_max.dev_attr)))
+                               &sensor_dev_attr_in8_max.dev_attr))
+                   || (err = device_create_file(dev,
+                               &sensor_dev_attr_in8_alarm.dev_attr))
+                   || (err = device_create_file(dev,
+                               &sensor_dev_attr_in8_beep.dev_attr)))
                        return err;
        }
        if (kind != w83783s) {
@@ -968,8 +1079,20 @@ w83781d_create_files(struct device *dev, int kind, int is_isa)
                    || (err = device_create_file(dev,
                                &sensor_dev_attr_temp3_max.dev_attr))
                    || (err = device_create_file(dev,
-                               &sensor_dev_attr_temp3_max_hyst.dev_attr)))
+                               &sensor_dev_attr_temp3_max_hyst.dev_attr))
+                   || (err = device_create_file(dev,
+                               &sensor_dev_attr_temp3_alarm.dev_attr))
+                   || (err = device_create_file(dev,
+                               &sensor_dev_attr_temp3_beep.dev_attr)))
                        return err;
+
+               if (kind != w83781d) {
+                       err = sysfs_chmod_file(&dev->kobj,
+                               &sensor_dev_attr_temp3_alarm.dev_attr.attr,
+                               S_IRUGO | S_IWUSR);
+                       if (err)
+                               return err;
+               }
        }
 
        if (kind != w83781d && kind != as99127f) {
@@ -1109,9 +1232,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
                        kind = w83782d;
                else if (val1 == 0x40 && vendid == winbond && address == 0x2d)
                        kind = w83783s;
-               else if (val1 == 0x21 && vendid == winbond)
-                       kind = w83627hf;
-               else if (val1 == 0x31 && address >= 0x28)
+               else if (val1 == 0x31)
                        kind = as99127f;
                else {
                        if (kind == 0)
@@ -1129,8 +1250,6 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
                client_name = "w83782d";
        } else if (kind == w83783s) {
                client_name = "w83783s";
-       } else if (kind == w83627hf) {
-               client_name = "w83627hf";
        } else if (kind == as99127f) {
                client_name = "as99127f";
        }
@@ -1156,9 +1275,9 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
        if (err)
                goto ERROR4;
 
-       data->class_dev = hwmon_device_register(dev);
-       if (IS_ERR(data->class_dev)) {
-               err = PTR_ERR(data->class_dev);
+       data->hwmon_dev = hwmon_device_register(dev);
+       if (IS_ERR(data->hwmon_dev)) {
+               err = PTR_ERR(data->hwmon_dev);
                goto ERROR4;
        }
 
@@ -1192,7 +1311,7 @@ w83781d_detach_client(struct i2c_client *client)
 
        /* main client */
        if (data) {
-               hwmon_device_unregister(data->class_dev);
+               hwmon_device_unregister(data->hwmon_dev);
                sysfs_remove_group(&client->dev.kobj, &w83781d_group);
                sysfs_remove_group(&client->dev.kobj, &w83781d_group_opt);
        }
@@ -1221,7 +1340,8 @@ w83781d_isa_probe(struct platform_device *pdev)
 
        /* Reserve the ISA region */
        res = platform_get_resource(pdev, IORESOURCE_IO, 0);
-       if (!request_region(res->start, W83781D_EXTENT, "w83781d")) {
+       if (!request_region(res->start + W83781D_ADDR_REG_OFFSET, 2,
+                           "w83781d")) {
                err = -EBUSY;
                goto exit;
        }
@@ -1237,10 +1357,6 @@ w83781d_isa_probe(struct platform_device *pdev)
 
        reg = w83781d_read_value(data, W83781D_REG_WCHIPID);
        switch (reg) {
-       case 0x21:
-               data->type = w83627hf;
-               name = "w83627hf";
-               break;
        case 0x30:
                data->type = w83782d;
                name = "w83782d";
@@ -1259,9 +1375,9 @@ w83781d_isa_probe(struct platform_device *pdev)
        if (err)
                goto exit_remove_files;
 
-       data->class_dev = hwmon_device_register(&pdev->dev);
-       if (IS_ERR(data->class_dev)) {
-               err = PTR_ERR(data->class_dev);
+       data->hwmon_dev = hwmon_device_register(&pdev->dev);
+       if (IS_ERR(data->hwmon_dev)) {
+               err = PTR_ERR(data->hwmon_dev);
                goto exit_remove_files;
        }
 
@@ -1273,7 +1389,7 @@ w83781d_isa_probe(struct platform_device *pdev)
        device_remove_file(&pdev->dev, &dev_attr_name);
        kfree(data);
  exit_release_region:
-       release_region(res->start, W83781D_EXTENT);
+       release_region(res->start + W83781D_ADDR_REG_OFFSET, 2);
  exit:
        return err;
 }
@@ -1283,20 +1399,20 @@ w83781d_isa_remove(struct platform_device *pdev)
 {
        struct w83781d_data *data = platform_get_drvdata(pdev);
 
-       hwmon_device_unregister(data->class_dev);
+       hwmon_device_unregister(data->hwmon_dev);
        sysfs_remove_group(&pdev->dev.kobj, &w83781d_group);
        sysfs_remove_group(&pdev->dev.kobj, &w83781d_group_opt);
        device_remove_file(&pdev->dev, &dev_attr_name);
-       release_region(data->client.addr, W83781D_EXTENT);
+       release_region(data->client.addr + W83781D_ADDR_REG_OFFSET, 2);
        kfree(data);
 
        return 0;
 }
 
 /* The SMBus locks itself, usually, but nothing may access the Winbond between
-   bank switches. ISA access must always be locked explicitly! 
+   bank switches. ISA access must always be locked explicitly!
    We ignore the W83781D BUSY flag at this moment - it could lead to deadlocks,
-   would slow down the W83781D access and should not be necessary. 
+   would slow down the W83781D access and should not be necessary.
    There are some ugly typecasts here, but the good news is - they should
    nowhere else be necessary! */
 static int
@@ -1440,11 +1556,6 @@ w83781d_init_device(struct device *dev)
        int type = data->type;
        u8 tmp;
 
-       if (type == w83627hf)
-               dev_info(dev, "The W83627HF chip is better supported by the "
-                        "w83627hf driver, support will be dropped from the "
-                        "w83781d driver soon\n");
-
        if (reset && type != as99127f) { /* this resets registers we don't have
                                           documentation for on the as99127f */
                /* Resetting the chip has been the default for a long time,
@@ -1485,7 +1596,7 @@ w83781d_init_device(struct device *dev)
                tmp = w83781d_read_value(data, W83781D_REG_SCFG1);
                for (i = 1; i <= 3; i++) {
                        if (!(tmp & BIT_SCFG1[i - 1])) {
-                               data->sens[i - 1] = W83781D_DEFAULT_BETA;
+                               data->sens[i - 1] = 4;
                        } else {
                                if (w83781d_read_value
                                    (data,
@@ -1558,8 +1669,7 @@ static struct w83781d_data *w83781d_update_device(struct device *dev)
                            w83781d_read_value(data, W83781D_REG_IN_MIN(i));
                        data->in_max[i] =
                            w83781d_read_value(data, W83781D_REG_IN_MAX(i));
-                       if ((data->type != w83782d)
-                           && (data->type != w83627hf) && (i == 6))
+                       if ((data->type != w83782d) && (i == 6))
                                break;
                }
                for (i = 0; i < 3; i++) {
@@ -1617,7 +1727,7 @@ static struct w83781d_data *w83781d_update_device(struct device *dev)
                        data->fan_div[1] |= (i >> 4) & 0x04;
                        data->fan_div[2] |= (i >> 5) & 0x04;
                }
-               if ((data->type == w83782d) || (data->type == w83627hf)) {
+               if (data->type == w83782d) {
                        data->alarms = w83781d_read_value(data,
                                                W83782D_REG_ALARM1)
                                     | (w83781d_read_value(data,
@@ -1638,8 +1748,7 @@ static struct w83781d_data *w83781d_update_device(struct device *dev)
                                                W83781D_REG_ALARM2) << 8);
                }
                i = w83781d_read_value(data, W83781D_REG_BEEP_INTS2);
-               data->beep_enable = i >> 7;
-               data->beep_mask = ((i & 0x7f) << 8) +
+               data->beep_mask = (i << 8) +
                    w83781d_read_value(data, W83781D_REG_BEEP_INTS1);
                if ((data->type != w83781d) && (data->type != as99127f)) {
                        data->beep_mask |=
@@ -1661,8 +1770,17 @@ w83781d_isa_found(unsigned short address)
 {
        int val, save, found = 0;
 
-       if (!request_region(address, W83781D_EXTENT, "w83781d"))
+       /* We have to request the region in two parts because some
+          boards declare base+4 to base+7 as a PNP device */
+       if (!request_region(address, 4, "w83781d")) {
+               pr_debug("w83781d: Failed to request low part of region\n");
                return 0;
+       }
+       if (!request_region(address + 4, 4, "w83781d")) {
+               pr_debug("w83781d: Failed to request high part of region\n");
+               release_region(address, 4);
+               return 0;
+       }
 
 #define REALLY_SLOW_IO
        /* We need the timeouts for at least some W83781D-like
@@ -1727,17 +1845,16 @@ w83781d_isa_found(unsigned short address)
        outb_p(W83781D_REG_WCHIPID, address + W83781D_ADDR_REG_OFFSET);
        val = inb_p(address + W83781D_DATA_REG_OFFSET);
        if ((val & 0xfe) == 0x10        /* W83781D */
-        || val == 0x30                 /* W83782D */
-        || val == 0x21)                /* W83627HF */
+        || val == 0x30)                /* W83782D */
                found = 1;
 
        if (found)
                pr_info("w83781d: Found a %s chip at %#x\n",
-                       val == 0x21 ? "W83627HF" :
                        val == 0x30 ? "W83782D" : "W83781D", (int)address);
 
  release:
-       release_region(address, W83781D_EXTENT);
+       release_region(address + 4, 4);
+       release_region(address, 4);
        return found;
 }
 
@@ -1746,7 +1863,7 @@ w83781d_isa_device_add(unsigned short address)
 {
        struct resource res = {
                .start  = address,
-               .end    = address + W83781D_EXTENT,
+               .end    = address + W83781D_EXTENT - 1,
                .name   = "w83781d",
                .flags  = IORESOURCE_IO,
        };