parser: remove unnecessary strlen()
[safe/jmp/linux-2.6] / drivers / hwmon / adt7475.c
index 520773b..a0c3851 100644 (file)
@@ -3,7 +3,8 @@
  * Copyright (C) 2007-2008, Advanced Micro Devices, Inc.
  * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net>
  * Copyright (C) 2008 Hans de Goede <hdegoede@redhat.com>
-
+ * Copyright (C) 2009 Jean Delvare <khali@linux-fr.org>
+ *
  * Derived from the lm83 driver by Jean Delvare
  *
  * This program is free software; you can redistribute it and/or modify
@@ -17,6 +18,7 @@
 #include <linux/i2c.h>
 #include <linux/hwmon.h>
 #include <linux/hwmon-sysfs.h>
+#include <linux/hwmon-vid.h>
 #include <linux/err.h>
 
 /* Indexes for the sysfs hooks */
 
 /* 7475 Common Registers */
 
+#define REG_DEVREV2            0x12    /* ADT7490 only */
+
+#define REG_VTT                        0x1E    /* ADT7490 only */
+#define REG_EXTEND3            0x1F    /* ADT7490 only */
+
 #define REG_VOLTAGE_BASE       0x20
 #define REG_TEMP_BASE          0x25
 #define REG_TACH_BASE          0x28
@@ -52,6 +59,8 @@
 #define REG_STATUS1            0x41
 #define REG_STATUS2            0x42
 
+#define REG_VID                        0x43    /* ADT7476 only */
+
 #define REG_VOLTAGE_MIN_BASE   0x44
 #define REG_VOLTAGE_MAX_BASE   0x45
 
 
 #define REG_TEMP_OFFSET_BASE   0x70
 
+#define REG_CONFIG2            0x73
+
 #define REG_EXTEND1            0x76
 #define REG_EXTEND2            0x77
+
+#define REG_CONFIG3            0x78
 #define REG_CONFIG5            0x7C
 #define REG_CONFIG4            0x7D
 
+#define REG_STATUS4            0x81    /* ADT7490 only */
+
+#define REG_VTT_MIN            0x84    /* ADT7490 only */
+#define REG_VTT_MAX            0x86    /* ADT7490 only */
+
+#define VID_VIDSEL             0x80    /* ADT7476 only */
+
+#define CONFIG2_ATTN           0x20
+
+#define CONFIG3_SMBALERT       0x01
+#define CONFIG3_THERM          0x02
+
+#define CONFIG4_PINFUNC                0x03
 #define CONFIG4_MAXDUTY                0x08
+#define CONFIG4_ATTN_IN10      0x30
+#define CONFIG4_ATTN_IN43      0xC0
 
 #define CONFIG5_TWOSCOMP       0x01
 #define CONFIG5_TEMPOFFSET     0x02
+#define CONFIG5_VIDGPIO                0x10    /* ADT7476 only */
 
 /* ADT7475 Settings */
 
 
 static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
 
-I2C_CLIENT_INSMOD_2(adt7473, adt7475);
+enum chips { adt7473, adt7475, adt7476, adt7490 };
 
 static const struct i2c_device_id adt7475_id[] = {
        { "adt7473", adt7473 },
        { "adt7475", adt7475 },
+       { "adt7476", adt7476 },
+       { "adt7490", adt7490 },
        { }
 };
 MODULE_DEVICE_TABLE(i2c, adt7475_id);
@@ -139,7 +170,11 @@ struct adt7475_data {
        u8 config4;
        u8 config5;
        u8 has_voltage;
-       u16 alarms;
+       u8 bypass_attn;         /* Bypass voltage attenuator */
+       u8 has_pwm2:1;
+       u8 has_fan4:1;
+       u8 has_vid:1;
+       u32 alarms;
        u16 voltage[3][6];
        u16 temp[7][3];
        u16 tach[2][4];
@@ -147,6 +182,9 @@ struct adt7475_data {
        u8 range[3];
        u8 pwmctl[3];
        u8 pwmchan[3];
+
+       u8 vid;
+       u8 vrm;
 };
 
 static struct i2c_driver adt7475_driver;
@@ -213,19 +251,24 @@ static const int adt7473_in_scaling[ADT7475_VOLTAGE_COUNT + 1][2] = {
        { 45, 45 },     /* Vtt */
 };
 
-static inline int reg2volt(int channel, u16 reg)
+static inline int reg2volt(int channel, u16 reg, u8 bypass_attn)
 {
        const int *r = adt7473_in_scaling[channel];
 
+       if (bypass_attn & (1 << channel))
+               return DIV_ROUND_CLOSEST(reg * 2250, 1024);
        return DIV_ROUND_CLOSEST(reg * (r[0] + r[1]) * 2250, r[1] * 1024);
 }
 
-static inline u16 volt2reg(int channel, long volt)
+static inline u16 volt2reg(int channel, long volt, u8 bypass_attn)
 {
        const int *r = adt7473_in_scaling[channel];
        long reg;
 
-       reg = (volt * r[1] * 1024) / ((r[0] + r[1]) * 2250);
+       if (bypass_attn & (1 << channel))
+               reg = (volt * 1024) / 2250;
+       else
+               reg = (volt * r[1] * 1024) / ((r[0] + r[1]) * 2250);
        return SENSORS_LIMIT(reg, 0, 1023) & (0xff << 2);
 }
 
@@ -285,7 +328,8 @@ static ssize_t show_voltage(struct device *dev, struct device_attribute *attr,
                               (data->alarms >> sattr->index) & 1);
        default:
                val = data->voltage[sattr->nr][sattr->index];
-               return sprintf(buf, "%d\n", reg2volt(sattr->index, val));
+               return sprintf(buf, "%d\n",
+                              reg2volt(sattr->index, val, data->bypass_attn));
        }
 }
 
@@ -304,12 +348,20 @@ static ssize_t set_voltage(struct device *dev, struct device_attribute *attr,
 
        mutex_lock(&data->lock);
 
-       data->voltage[sattr->nr][sattr->index] = volt2reg(sattr->index, val);
+       data->voltage[sattr->nr][sattr->index] =
+                               volt2reg(sattr->index, val, data->bypass_attn);
 
-       if (sattr->nr == MIN)
-               reg = VOLTAGE_MIN_REG(sattr->index);
-       else
-               reg = VOLTAGE_MAX_REG(sattr->index);
+       if (sattr->index < ADT7475_VOLTAGE_COUNT) {
+               if (sattr->nr == MIN)
+                       reg = VOLTAGE_MIN_REG(sattr->index);
+               else
+                       reg = VOLTAGE_MAX_REG(sattr->index);
+       } else {
+               if (sattr->nr == MIN)
+                       reg = REG_VTT_MIN;
+               else
+                       reg = REG_VTT_MAX;
+       }
 
        i2c_smbus_write_byte_data(client, reg,
                                  data->voltage[sattr->nr][sattr->index] >> 2);
@@ -818,6 +870,41 @@ static ssize_t set_pwm_at_crit(struct device *dev,
        return count;
 }
 
+static ssize_t show_vrm(struct device *dev, struct device_attribute *devattr,
+                       char *buf)
+{
+       struct adt7475_data *data = dev_get_drvdata(dev);
+       return sprintf(buf, "%d\n", (int)data->vrm);
+}
+
+static ssize_t set_vrm(struct device *dev, struct device_attribute *devattr,
+                      const char *buf, size_t count)
+{
+       struct adt7475_data *data = dev_get_drvdata(dev);
+       long val;
+
+       if (strict_strtol(buf, 10, &val))
+               return -EINVAL;
+       if (val < 0 || val > 255)
+               return -EINVAL;
+       data->vrm = val;
+
+       return count;
+}
+
+static ssize_t show_vid(struct device *dev, struct device_attribute *devattr,
+                       char *buf)
+{
+       struct adt7475_data *data = adt7475_update_device(dev);
+       return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
+}
+
+static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_voltage, NULL, INPUT, 0);
+static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_voltage,
+                           set_voltage, MAX, 0);
+static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_voltage,
+                           set_voltage, MIN, 0);
+static SENSOR_DEVICE_ATTR_2(in0_alarm, S_IRUGO, show_voltage, NULL, ALARM, 0);
 static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_voltage, NULL, INPUT, 1);
 static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_voltage,
                            set_voltage, MAX, 1);
@@ -830,6 +917,24 @@ static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_voltage,
 static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_voltage,
                            set_voltage, MIN, 2);
 static SENSOR_DEVICE_ATTR_2(in2_alarm, S_IRUGO, show_voltage, NULL, ALARM, 2);
+static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_voltage, NULL, INPUT, 3);
+static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_voltage,
+                           set_voltage, MAX, 3);
+static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_voltage,
+                           set_voltage, MIN, 3);
+static SENSOR_DEVICE_ATTR_2(in3_alarm, S_IRUGO, show_voltage, NULL, ALARM, 3);
+static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_voltage, NULL, INPUT, 4);
+static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_voltage,
+                           set_voltage, MAX, 4);
+static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_voltage,
+                           set_voltage, MIN, 4);
+static SENSOR_DEVICE_ATTR_2(in4_alarm, S_IRUGO, show_voltage, NULL, ALARM, 8);
+static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_voltage, NULL, INPUT, 5);
+static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_voltage,
+                           set_voltage, MAX, 5);
+static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_voltage,
+                           set_voltage, MIN, 5);
+static SENSOR_DEVICE_ATTR_2(in5_alarm, S_IRUGO, show_voltage, NULL, ALARM, 31);
 static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, INPUT, 0);
 static SENSOR_DEVICE_ATTR_2(temp1_alarm, S_IRUGO, show_temp, NULL, ALARM, 0);
 static SENSOR_DEVICE_ATTR_2(temp1_fault, S_IRUGO, show_temp, NULL, FAULT, 0);
@@ -937,6 +1042,9 @@ static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR, show_pwm,
 static DEVICE_ATTR(pwm_use_point2_pwm_at_crit, S_IWUSR | S_IRUGO,
                   show_pwm_at_crit, set_pwm_at_crit);
 
+static DEVICE_ATTR(vrm, S_IWUSR | S_IRUGO, show_vrm, set_vrm);
+static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
+
 static struct attribute *adt7475_attrs[] = {
        &sensor_dev_attr_in1_input.dev_attr.attr,
        &sensor_dev_attr_in1_max.dev_attr.attr,
@@ -984,21 +1092,12 @@ static struct attribute *adt7475_attrs[] = {
        &sensor_dev_attr_fan3_input.dev_attr.attr,
        &sensor_dev_attr_fan3_min.dev_attr.attr,
        &sensor_dev_attr_fan3_alarm.dev_attr.attr,
-       &sensor_dev_attr_fan4_input.dev_attr.attr,
-       &sensor_dev_attr_fan4_min.dev_attr.attr,
-       &sensor_dev_attr_fan4_alarm.dev_attr.attr,
        &sensor_dev_attr_pwm1.dev_attr.attr,
        &sensor_dev_attr_pwm1_freq.dev_attr.attr,
        &sensor_dev_attr_pwm1_enable.dev_attr.attr,
        &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
        &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
        &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
-       &sensor_dev_attr_pwm2.dev_attr.attr,
-       &sensor_dev_attr_pwm2_freq.dev_attr.attr,
-       &sensor_dev_attr_pwm2_enable.dev_attr.attr,
-       &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
-       &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
-       &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
        &sensor_dev_attr_pwm3.dev_attr.attr,
        &sensor_dev_attr_pwm3_freq.dev_attr.attr,
        &sensor_dev_attr_pwm3_enable.dev_attr.attr,
@@ -1009,9 +1108,71 @@ static struct attribute *adt7475_attrs[] = {
        NULL,
 };
 
-static struct attribute_group adt7475_attr_group = { .attrs = adt7475_attrs };
+static struct attribute *fan4_attrs[] = {
+       &sensor_dev_attr_fan4_input.dev_attr.attr,
+       &sensor_dev_attr_fan4_min.dev_attr.attr,
+       &sensor_dev_attr_fan4_alarm.dev_attr.attr,
+       NULL
+};
+
+static struct attribute *pwm2_attrs[] = {
+       &sensor_dev_attr_pwm2.dev_attr.attr,
+       &sensor_dev_attr_pwm2_freq.dev_attr.attr,
+       &sensor_dev_attr_pwm2_enable.dev_attr.attr,
+       &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
+       &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
+       &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
+       NULL
+};
+
+static struct attribute *in0_attrs[] = {
+       &sensor_dev_attr_in0_input.dev_attr.attr,
+       &sensor_dev_attr_in0_max.dev_attr.attr,
+       &sensor_dev_attr_in0_min.dev_attr.attr,
+       &sensor_dev_attr_in0_alarm.dev_attr.attr,
+       NULL
+};
 
-static int adt7475_detect(struct i2c_client *client, int kind,
+static struct attribute *in3_attrs[] = {
+       &sensor_dev_attr_in3_input.dev_attr.attr,
+       &sensor_dev_attr_in3_max.dev_attr.attr,
+       &sensor_dev_attr_in3_min.dev_attr.attr,
+       &sensor_dev_attr_in3_alarm.dev_attr.attr,
+       NULL
+};
+
+static struct attribute *in4_attrs[] = {
+       &sensor_dev_attr_in4_input.dev_attr.attr,
+       &sensor_dev_attr_in4_max.dev_attr.attr,
+       &sensor_dev_attr_in4_min.dev_attr.attr,
+       &sensor_dev_attr_in4_alarm.dev_attr.attr,
+       NULL
+};
+
+static struct attribute *in5_attrs[] = {
+       &sensor_dev_attr_in5_input.dev_attr.attr,
+       &sensor_dev_attr_in5_max.dev_attr.attr,
+       &sensor_dev_attr_in5_min.dev_attr.attr,
+       &sensor_dev_attr_in5_alarm.dev_attr.attr,
+       NULL
+};
+
+static struct attribute *vid_attrs[] = {
+       &dev_attr_cpu0_vid.attr,
+       &dev_attr_vrm.attr,
+       NULL
+};
+
+static struct attribute_group adt7475_attr_group = { .attrs = adt7475_attrs };
+static struct attribute_group fan4_attr_group = { .attrs = fan4_attrs };
+static struct attribute_group pwm2_attr_group = { .attrs = pwm2_attrs };
+static struct attribute_group in0_attr_group = { .attrs = in0_attrs };
+static struct attribute_group in3_attr_group = { .attrs = in3_attrs };
+static struct attribute_group in4_attr_group = { .attrs = in4_attrs };
+static struct attribute_group in5_attr_group = { .attrs = in5_attrs };
+static struct attribute_group vid_attr_group = { .attrs = vid_attrs };
+
+static int adt7475_detect(struct i2c_client *client,
                          struct i2c_board_info *info)
 {
        struct i2c_adapter *adapter = client->adapter;
@@ -1032,9 +1193,13 @@ static int adt7475_detect(struct i2c_client *client, int kind,
                name = "adt7473";
        else if (devid == 0x75 && client->addr == 0x2e)
                name = "adt7475";
+       else if (devid == 0x76)
+               name = "adt7476";
+       else if ((devid2 & 0xfc) == 0x6c)
+               name = "adt7490";
        else {
                dev_dbg(&adapter->dev,
-                       "Couldn't detect an ADT7473 or ADT7475 part at "
+                       "Couldn't detect an ADT7473/75/76/90 part at "
                        "0x%02x\n", (unsigned int)client->addr);
                return -ENODEV;
        }
@@ -1044,11 +1209,39 @@ static int adt7475_detect(struct i2c_client *client, int kind,
        return 0;
 }
 
+static void adt7475_remove_files(struct i2c_client *client,
+                                struct adt7475_data *data)
+{
+       sysfs_remove_group(&client->dev.kobj, &adt7475_attr_group);
+       if (data->has_fan4)
+               sysfs_remove_group(&client->dev.kobj, &fan4_attr_group);
+       if (data->has_pwm2)
+               sysfs_remove_group(&client->dev.kobj, &pwm2_attr_group);
+       if (data->has_voltage & (1 << 0))
+               sysfs_remove_group(&client->dev.kobj, &in0_attr_group);
+       if (data->has_voltage & (1 << 3))
+               sysfs_remove_group(&client->dev.kobj, &in3_attr_group);
+       if (data->has_voltage & (1 << 4))
+               sysfs_remove_group(&client->dev.kobj, &in4_attr_group);
+       if (data->has_voltage & (1 << 5))
+               sysfs_remove_group(&client->dev.kobj, &in5_attr_group);
+       if (data->has_vid)
+               sysfs_remove_group(&client->dev.kobj, &vid_attr_group);
+}
+
 static int adt7475_probe(struct i2c_client *client,
                         const struct i2c_device_id *id)
 {
+       static const char *names[] = {
+               [adt7473] = "ADT7473",
+               [adt7475] = "ADT7475",
+               [adt7476] = "ADT7476",
+               [adt7490] = "ADT7490",
+       };
+
        struct adt7475_data *data;
-       int i, ret = 0;
+       int i, ret = 0, revision;
+       u8 config2, config3;
 
        data = kzalloc(sizeof(*data), GFP_KERNEL);
        if (data == NULL)
@@ -1059,10 +1252,68 @@ static int adt7475_probe(struct i2c_client *client,
 
        /* Initialize device-specific values */
        switch (id->driver_data) {
+       case adt7476:
+               data->has_voltage = 0x0e;       /* in1 to in3 */
+               revision = adt7475_read(REG_DEVID2) & 0x07;
+               break;
+       case adt7490:
+               data->has_voltage = 0x3e;       /* in1 to in5 */
+               revision = adt7475_read(REG_DEVID2) & 0x03;
+               if (revision == 0x03)
+                       revision += adt7475_read(REG_DEVREV2);
+               break;
        default:
                data->has_voltage = 0x06;       /* in1, in2 */
+               revision = adt7475_read(REG_DEVID2) & 0x07;
        }
 
+       config3 = adt7475_read(REG_CONFIG3);
+       /* Pin PWM2 may alternatively be used for ALERT output */
+       if (!(config3 & CONFIG3_SMBALERT))
+               data->has_pwm2 = 1;
+       /* Meaning of this bit is inverted for the ADT7473-1 */
+       if (id->driver_data == adt7473 && revision >= 1)
+               data->has_pwm2 = !data->has_pwm2;
+
+       data->config4 = adt7475_read(REG_CONFIG4);
+       /* Pin TACH4 may alternatively be used for THERM */
+       if ((data->config4 & CONFIG4_PINFUNC) == 0x0)
+               data->has_fan4 = 1;
+
+       /* THERM configuration is more complex on the ADT7476 and ADT7490,
+          because 2 different pins (TACH4 and +2.5 Vin) can be used for
+          this function */
+       if (id->driver_data == adt7490) {
+               if ((data->config4 & CONFIG4_PINFUNC) == 0x1 &&
+                   !(config3 & CONFIG3_THERM))
+                       data->has_fan4 = 1;
+       }
+       if (id->driver_data == adt7476 || id->driver_data == adt7490) {
+               if (!(config3 & CONFIG3_THERM) ||
+                   (data->config4 & CONFIG4_PINFUNC) == 0x1)
+                       data->has_voltage |= (1 << 0);          /* in0 */
+       }
+
+       /* On the ADT7476, the +12V input pin may instead be used as VID5,
+          and VID pins may alternatively be used as GPIO */
+       if (id->driver_data == adt7476) {
+               u8 vid = adt7475_read(REG_VID);
+               if (!(vid & VID_VIDSEL))
+                       data->has_voltage |= (1 << 4);          /* in4 */
+
+               data->has_vid = !(adt7475_read(REG_CONFIG5) & CONFIG5_VIDGPIO);
+       }
+
+       /* Voltage attenuators can be bypassed, globally or individually */
+       config2 = adt7475_read(REG_CONFIG2);
+       if (config2 & CONFIG2_ATTN) {
+               data->bypass_attn = (0x3 << 3) | 0x3;
+       } else {
+               data->bypass_attn = ((data->config4 & CONFIG4_ATTN_IN10) >> 4) |
+                                   ((data->config4 & CONFIG4_ATTN_IN43) >> 3);
+       }
+       data->bypass_attn &= data->has_voltage;
+
        /* Call adt7475_read_pwm for all pwm's as this will reprogram any
           pwm's which are disabled to manual mode with 0% duty cycle */
        for (i = 0; i < ADT7475_PWM_COUNT; i++)
@@ -1072,16 +1323,70 @@ static int adt7475_probe(struct i2c_client *client,
        if (ret)
                goto efree;
 
+       /* Features that can be disabled individually */
+       if (data->has_fan4) {
+               ret = sysfs_create_group(&client->dev.kobj, &fan4_attr_group);
+               if (ret)
+                       goto eremove;
+       }
+       if (data->has_pwm2) {
+               ret = sysfs_create_group(&client->dev.kobj, &pwm2_attr_group);
+               if (ret)
+                       goto eremove;
+       }
+       if (data->has_voltage & (1 << 0)) {
+               ret = sysfs_create_group(&client->dev.kobj, &in0_attr_group);
+               if (ret)
+                       goto eremove;
+       }
+       if (data->has_voltage & (1 << 3)) {
+               ret = sysfs_create_group(&client->dev.kobj, &in3_attr_group);
+               if (ret)
+                       goto eremove;
+       }
+       if (data->has_voltage & (1 << 4)) {
+               ret = sysfs_create_group(&client->dev.kobj, &in4_attr_group);
+               if (ret)
+                       goto eremove;
+       }
+       if (data->has_voltage & (1 << 5)) {
+               ret = sysfs_create_group(&client->dev.kobj, &in5_attr_group);
+               if (ret)
+                       goto eremove;
+       }
+       if (data->has_vid) {
+               data->vrm = vid_which_vrm();
+               ret = sysfs_create_group(&client->dev.kobj, &vid_attr_group);
+               if (ret)
+                       goto eremove;
+       }
+
        data->hwmon_dev = hwmon_device_register(&client->dev);
        if (IS_ERR(data->hwmon_dev)) {
                ret = PTR_ERR(data->hwmon_dev);
                goto eremove;
        }
 
+       dev_info(&client->dev, "%s device, revision %d\n",
+                names[id->driver_data], revision);
+       if ((data->has_voltage & 0x11) || data->has_fan4 || data->has_pwm2)
+               dev_info(&client->dev, "Optional features:%s%s%s%s%s\n",
+                        (data->has_voltage & (1 << 0)) ? " in0" : "",
+                        (data->has_voltage & (1 << 4)) ? " in4" : "",
+                        data->has_fan4 ? " fan4" : "",
+                        data->has_pwm2 ? " pwm2" : "",
+                        data->has_vid ? " vid" : "");
+       if (data->bypass_attn)
+               dev_info(&client->dev, "Bypassing attenuators on:%s%s%s%s\n",
+                        (data->bypass_attn & (1 << 0)) ? " in0" : "",
+                        (data->bypass_attn & (1 << 1)) ? " in1" : "",
+                        (data->bypass_attn & (1 << 3)) ? " in3" : "",
+                        (data->bypass_attn & (1 << 4)) ? " in4" : "");
+
        return 0;
 
 eremove:
-       sysfs_remove_group(&client->dev.kobj, &adt7475_attr_group);
+       adt7475_remove_files(client, data);
 efree:
        kfree(data);
        return ret;
@@ -1092,7 +1397,7 @@ static int adt7475_remove(struct i2c_client *client)
        struct adt7475_data *data = i2c_get_clientdata(client);
 
        hwmon_device_unregister(data->hwmon_dev);
-       sysfs_remove_group(&client->dev.kobj, &adt7475_attr_group);
+       adt7475_remove_files(client, data);
        kfree(data);
 
        return 0;
@@ -1107,7 +1412,7 @@ static struct i2c_driver adt7475_driver = {
        .remove         = adt7475_remove,
        .id_table       = adt7475_id,
        .detect         = adt7475_detect,
-       .address_data   = &addr_data,
+       .address_list   = normal_i2c,
 };
 
 static void adt7475_read_hystersis(struct i2c_client *client)
@@ -1177,7 +1482,7 @@ static struct adt7475_data *adt7475_update_device(struct device *dev)
 {
        struct i2c_client *client = to_i2c_client(dev);
        struct adt7475_data *data = i2c_get_clientdata(client);
-       u8 ext;
+       u16 ext;
        int i;
 
        mutex_lock(&data->lock);
@@ -1188,7 +1493,8 @@ static struct adt7475_data *adt7475_update_device(struct device *dev)
                data->alarms = adt7475_read(REG_STATUS2) << 8;
                data->alarms |= adt7475_read(REG_STATUS1);
 
-               ext = adt7475_read(REG_EXTEND1);
+               ext = (adt7475_read(REG_EXTEND2) << 8) |
+                       adt7475_read(REG_EXTEND1);
                for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) {
                        if (!(data->has_voltage & (1 << i)))
                                continue;
@@ -1197,19 +1503,34 @@ static struct adt7475_data *adt7475_update_device(struct device *dev)
                                ((ext >> (i * 2)) & 3);
                }
 
-               ext = adt7475_read(REG_EXTEND2);
                for (i = 0; i < ADT7475_TEMP_COUNT; i++)
                        data->temp[INPUT][i] =
                                (adt7475_read(TEMP_REG(i)) << 2) |
-                               ((ext >> ((i + 1) * 2)) & 3);
+                               ((ext >> ((i + 5) * 2)) & 3);
+
+               if (data->has_voltage & (1 << 5)) {
+                       data->alarms |= adt7475_read(REG_STATUS4) << 24;
+                       ext = adt7475_read(REG_EXTEND3);
+                       data->voltage[INPUT][5] = adt7475_read(REG_VTT) << 2 |
+                               ((ext >> 4) & 3);
+               }
 
-               for (i = 0; i < ADT7475_TACH_COUNT; i++)
+               for (i = 0; i < ADT7475_TACH_COUNT; i++) {
+                       if (i == 3 && !data->has_fan4)
+                               continue;
                        data->tach[INPUT][i] =
                                adt7475_read_word(client, TACH_REG(i));
+               }
 
                /* Updated by hw when in auto mode */
-               for (i = 0; i < ADT7475_PWM_COUNT; i++)
+               for (i = 0; i < ADT7475_PWM_COUNT; i++) {
+                       if (i == 1 && !data->has_pwm2)
+                               continue;
                        data->pwm[INPUT][i] = adt7475_read(PWM_REG(i));
+               }
+
+               if (data->has_vid)
+                       data->vid = adt7475_read(REG_VID) & 0x3f;
 
                data->measure_updated = jiffies;
        }
@@ -1230,6 +1551,11 @@ static struct adt7475_data *adt7475_update_device(struct device *dev)
                                adt7475_read(VOLTAGE_MAX_REG(i)) << 2;
                }
 
+               if (data->has_voltage & (1 << 5)) {
+                       data->voltage[MIN][5] = adt7475_read(REG_VTT_MIN) << 2;
+                       data->voltage[MAX][5] = adt7475_read(REG_VTT_MAX) << 2;
+               }
+
                for (i = 0; i < ADT7475_TEMP_COUNT; i++) {
                        /* Adjust values so they match the input precision */
                        data->temp[MIN][i] =
@@ -1245,11 +1571,16 @@ static struct adt7475_data *adt7475_update_device(struct device *dev)
                }
                adt7475_read_hystersis(client);
 
-               for (i = 0; i < ADT7475_TACH_COUNT; i++)
+               for (i = 0; i < ADT7475_TACH_COUNT; i++) {
+                       if (i == 3 && !data->has_fan4)
+                               continue;
                        data->tach[MIN][i] =
                                adt7475_read_word(client, TACH_MIN_REG(i));
+               }
 
                for (i = 0; i < ADT7475_PWM_COUNT; i++) {
+                       if (i == 1 && !data->has_pwm2)
+                               continue;
                        data->pwm[MAX][i] = adt7475_read(PWM_MAX_REG(i));
                        data->pwm[MIN][i] = adt7475_read(PWM_MIN_REG(i));
                        /* Set the channel and control information */