]> git.sur5r.net Git - groeck-nct6775/blobdiff - nct6775.c
Update some NCT6779 registers
[groeck-nct6775] / nct6775.c
index 89ddf4d4ba36f54d38b04e8183b81859638a3da2..dc3382ab9e65210876a276b0e10aeaa6544cc944 100644 (file)
--- a/nct6775.c
+++ b/nct6775.c
@@ -54,6 +54,8 @@
 #include <linux/io.h>
 #include "lm75.h"
 
+#define TESTING
+
 enum kinds { nct6775, nct6776, nct6779 };
 
 /* used to set data->name = nct6775_device_names[data->sio_kind] */
@@ -169,6 +171,7 @@ static const u16 NCT6779_REG_IN[] = {
 };
 
 #define NCT6775_REG_VBAT               0x5D
+#define NCT6775_REG_DIODE              0x5E
 
 #define NCT6775_REG_FANDIV1            0x506
 #define NCT6775_REG_FANDIV2            0x507
@@ -178,10 +181,38 @@ static const u16 NCT6779_REG_IN[] = {
 static const u16 NCT6775_REG_ALARM[6] = { 0x459, 0x45A, 0x45B };
 static const u16 NCT6779_REG_ALARM[6] = { 0x459, 0x45A, 0x45B, 0x568 };
 
-#define NCT6775_REG_CASEOPEN           0x42
-
-static const u8 NCT6775_CASEOPEN_MASK[] = { 0x10, 0x00 };
-static const u8 NCT6776_CASEOPEN_MASK[] = { 0x10, 0x40 };
+/* 0..15 voltages, 16..23 fans, 24..31 temperatures */
+
+static const s8 NCT6775_ALARM_BITS[]
+       = { 0, 1, 2, 3, 8, 21, 20, 16,          /* in0.. in7 */
+           17, -1, -1, -1, -1, -1, -1,         /* in8..in14 */
+           -1,                                 /* unused */
+           6, 7, 11, 10, 23,                   /* fan1..fan5 */
+           -1, -1, -1,                         /* unused */
+           4, 5, 13, -1, -1, -1,               /* temp1..temp6 */
+           12, -1 };                           /* intrusion0, intrusion1 */
+
+static const s8 NCT6776_ALARM_BITS[]
+       = { 0, 1, 2, 3, 8, 21, 20, 16,          /* in0.. in7 */
+           17, -1, -1, -1, -1, -1, -1,         /* in8..in14 */
+           -1,                                 /* unused */
+           6, 7, 11, 10, 23,                   /* fan1..fan5 */
+           -1, -1, -1,                         /* unused */
+           4, 5, 13, -1, -1, -1,               /* temp1..temp6 */
+           12, 9 };                            /* intrusion0, intrusion1 */
+
+static const s8 NCT6779_ALARM_BITS[]
+       = { 0, 1, 2, 3, 8, 21, 20, 16,          /* in0.. in7 */
+           17, 24, 25, 26, 27, 28, 29,         /* in8..in14 */
+           -1,                                 /* unused */
+           6, 7, 11, 10, 23,                   /* fan1..fan5 */
+           -1, -1, -1,                         /* unused */
+           4, 5, 13, -1, -1, -1,               /* temp1..temp6 */
+           12, 9 };                            /* intrusion0, intrusion1 */
+
+#define FAN_ALARM_BASE         16
+#define TEMP_ALARM_BASE                24
+#define INTRUSION_ALARM_BASE   30
 
 static const u8 NCT6775_REG_CR_CASEOPEN_CLR[] = { 0xe6, 0xee };
 static const u8 NCT6775_CR_CASEOPEN_CLR_MASK[] = { 0x20, 0x01 };
@@ -195,6 +226,11 @@ static const u8 NCT6776_PWM_MODE_MASK[] = { 0x01, 0, 0 };
 
 /* Advanced Fan control, some values are common for all fans */
 
+static const u16 NCT6775_REG_FAN_PULSES[] = { 0x641, 0x642, 0x643, 0x644, 0 };
+static const u16 NCT6776_REG_FAN_PULSES[] = { 0x644, 0x645, 0x646, 0, 0 };
+static const u16 NCT6779_REG_FAN_PULSES[]
+       = { 0x644, 0x645, 0x646, 0x647, 0x648 };
+
 static const u16 NCT6775_REG_TARGET[] = { 0x101, 0x201, 0x301, 0x801, 0x901 };
 static const u16 NCT6775_REG_FAN_MODE[] = { 0x102, 0x202, 0x302, 0x802, 0x902 };
 static const u16 NCT6775_REG_FAN_STEP_DOWN_TIME[] = {
@@ -205,6 +241,9 @@ static const u16 NCT6775_REG_FAN_STOP_OUTPUT[] = {
        0x105, 0x205, 0x305, 0x805, 0x905 };
 static const u16 NCT6775_REG_FAN_START_OUTPUT[]
        = { 0x106, 0x206, 0x306, 0x806, 0x906 };
+static const u16 NCT6775_REG_FAN_MAX_OUTPUT[] = { 0x10a, 0x20a, 0x30a };
+static const u16 NCT6775_REG_FAN_STEP_OUTPUT[] = { 0x10b, 0x20b, 0x30b };
+
 static const u16 NCT6775_REG_FAN_STOP_TIME[]
        = { 0x107, 0x207, 0x307, 0x807, 0x907 };
 static const u16 NCT6775_REG_PWM[] = { 0x109, 0x209, 0x309, 0x809, 0x909 };
@@ -215,13 +254,14 @@ static const u16 NCT6775_REG_FAN[] = { 0x630, 0x632, 0x634, 0x636, 0x638 };
 static const u16 NCT6776_REG_FAN_MIN[] = { 0x63a, 0x63c, 0x63e, 0x640, 0x642};
 
 static const u16 NCT6779_REG_TOLERANCE_H[]
-       = { 0x10c, 0x20c, 0x30c, 0x40c, 0x50c };
+       = { 0x10c, 0x20c, 0x30c, 0x80c, 0x90c };
 
 static const u16 NCT6779_REG_FAN[] = { 0x4c0, 0x4c2, 0x4c4, 0x4c6, 0x4c8 };
 
 static const u16 NCT6775_REG_TEMP[]
        = { 0x27, 0x150, 0x250, 0x62b, 0x62c, 0x62d };
 static const u16 NCT6779_REG_TEMP[] = { 0x27, 0x150 };
+
 static const u16 NCT6775_REG_TEMP_CONFIG[]
        = { 0, 0x152, 0x252, 0x628, 0x629, 0x62A };
 static const u16 NCT6775_REG_TEMP_HYST[]
@@ -232,25 +272,28 @@ static const u16 NCT6775_REG_TEMP_OVER[]
 static const u16 NCT6775_REG_TEMP_SOURCE[]
        = { 0x621, 0x622, 0x623, 0x624, 0x625, 0x626 };
 
-static const u16 NCT6775_REG_TEMP_SEL[] 
+static const u16 NCT6775_REG_TEMP_SEL[]
        = { 0x100, 0x200, 0x300, 0x800, 0x900 };
 
-static const u16 NCT6775_REG_WEIGHT_TEMP_SEL[] 
+static const u16 NCT6775_REG_WEIGHT_TEMP_SEL[]
        = { 0x139, 0x239, 0x339, 0x839, 0x939 };
-static const u16 NCT6775_REG_WEIGHT_TEMP_STEP[] 
+static const u16 NCT6775_REG_WEIGHT_TEMP_STEP[]
        = { 0x13a, 0x23a, 0x33a, 0x83a, 0x93a };
-static const u16 NCT6775_REG_WEIGHT_TEMP_STEP_TOL[] 
+static const u16 NCT6775_REG_WEIGHT_TEMP_STEP_TOL[]
        = { 0x13b, 0x23b, 0x33b, 0x83b, 0x93b };
-static const u16 NCT6775_REG_WEIGHT_DUTY_STEP[] 
+static const u16 NCT6775_REG_WEIGHT_DUTY_STEP[]
        = { 0x13c, 0x23c, 0x33c, 0x83c, 0x93c };
-static const u16 NCT6775_REG_WEIGHT_TEMP_BASE[] 
+static const u16 NCT6775_REG_WEIGHT_TEMP_BASE[]
        = { 0x13d, 0x23d, 0x33d, 0x83d, 0x93d };
 
-static const u16 NCT6776_REG_WEIGHT_DUTY_BASE[] 
+static const u16 NCT6776_REG_WEIGHT_DUTY_BASE[]
        = { 0x13e, 0x23e, 0x33e, 0x83e, 0x93e };
 
 static const u16 NCT6775_REG_TEMP_OFFSET[] = { 0x454, 0x455, 0x456 };
 
+static const u16 NCT6779_REG_TEMP_OFFSET[]
+       = { 0x454, 0x455, 0x456, 0x44a, 0x44b, 0x44c };
+
 static const u16 NCT6776_REG_TEMP_CONFIG[11]
        = { 0x18, 0x152, 0x252, 0x628, 0x629, 0x62A };
 
@@ -356,26 +399,34 @@ static const char *const nct6779_temp_label[] = {
        "BYTE_TEMP"
 };
 
+static const u16 NCT6775_REG_TEMP_ALTERNATE[ARRAY_SIZE(nct6779_temp_label)]
+       = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x661, 0x662, 0x664 };
+
+static const u16 NCT6776_REG_TEMP_ALTERNATE[ARRAY_SIZE(nct6776_temp_label)]
+       = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x401, 0x402, 0x404 };
+
+static const u16 NCT6779_REG_TEMP_ALTERNATE[ARRAY_SIZE(nct6779_temp_label)]
+       = { 0x490, 0x491, 0x492, 0x493, 0x494, 0x495, 0, 0,
+           0, 0, 0, 0, 0, 0, 0, 0,
+           0, 0, 0x401, 0x402, 0x404 };
+
+#define NUM_TEMP       10      /* Max number of temp attribute sets w/ limits*/
+#define NUM_TEMP_FIXED 6       /* Max number of fixed temp attribute sets */
+
 #define NUM_REG_TEMP   ARRAY_SIZE(NCT6775_REG_TEMP)
 
 static inline int reg_to_pwm_enable(int pwm, int mode)
 {
        if (mode == 0 && pwm == 255)
                return 0;       /* off  */
-       if (mode == 3)          /* SmartFan III */
-               return 2;       /* convert to thermal cruise */
-       if (mode < 3)
-               return mode + 1;
-       return 4;               /* SmartFan IV */
+       return mode + 1;
 }
 
 static inline int pwm_enable_to_reg(int mode)
 {
        if (mode == 0)
                return 0;
-       if (mode < 4)
-               return mode - 1;
-       return 4;
+       return mode - 1;
 }
 
 /*
@@ -464,13 +515,17 @@ struct nct6775_data {
        struct device *hwmon_dev;
        struct mutex lock;
 
-       u16 reg_temp[3][NUM_REG_TEMP]; /* 0=temp, 1=temp_over, 2=temp_hyst */
-       u8 temp_src[NUM_REG_TEMP];
-       u16 reg_temp_config[NUM_REG_TEMP];
+       u16 reg_temp[3][NUM_TEMP]; /* 0=temp, 1=temp_over, 2=temp_hyst */
+       u8 temp_src[NUM_TEMP];
+       u16 reg_temp_config[NUM_TEMP];
        const char * const *temp_label;
+       int temp_label_num;
 
        u16 REG_CONFIG;
        u16 REG_VBAT;
+       u16 REG_DIODE;
+
+       const s8 *ALARM_BITS;
 
        const u16 *REG_VIN;
        const u16 *REG_IN_MINMAX[2];
@@ -484,9 +539,13 @@ struct nct6775_data {
        const u8 *REG_PWM_MODE;
        const u8 *PWM_MODE_MASK;
 
-       const u16 *REG_PWM[3];
+       const u16 *REG_PWM[7];  /* [0]=pwm, [1]=start_output, [2]=stop_output,
+                                * [3]=max_output, [4]=step_output,
+                                * [5]=weight_duty_step, [6]=weight_duty_base
+                                */
        const u16 *REG_PWM_READ;
 
+       const u16 *REG_TEMP_ALTERNATE;
        const u16 *REG_TEMP_MON;
        const u16 *REG_AUTO_TEMP;
        const u16 *REG_AUTO_PWM;
@@ -498,15 +557,11 @@ struct nct6775_data {
        const u16 *REG_TEMP_SEL[2];     /* pwm temp, 0=base, 1=weight */
 
        const u16 *REG_WEIGHT_TEMP[3];  /* 0=base, 1=hyst, 2=step */
-       const u16 *REG_WEIGHT_DUTY[2];  /* 0=step, 1=base */
 
        const u16 *REG_TEMP_OFFSET;
 
        const u16 *REG_ALARM;
 
-       u8 REG_CASEOPEN;
-       const u8 *CASEOPEN_MASK;
-
        unsigned int (*fan_from_reg)(u16 reg, unsigned int divreg);
        unsigned int (*fan_from_reg_min)(u16 reg, unsigned int divreg);
 
@@ -525,11 +580,12 @@ struct nct6775_data {
        u8 has_fan;             /* some fan inputs can be disabled */
        u8 has_fan_min;         /* some fans don't have min register */
        bool has_fan_div;
-       u8 temp_type[3];
-       s8 temp_offset[3];
-       s16 temp[3][NUM_REG_TEMP]; /* 0=temp, 1=temp_over, 2=temp_hyst */
+
+       u8 temp_fixed_num;      /* 3 or 6 */
+       u8 temp_type[NUM_TEMP_FIXED];
+       s8 temp_offset[NUM_TEMP_FIXED];
+       s16 temp[3][NUM_TEMP]; /* 0=temp, 1=temp_over, 2=temp_hyst */
        u64 alarms;
-       u8 caseopen;
 
        u8 pwm_num;     /* number of pwm */
 
@@ -538,10 +594,13 @@ struct nct6775_data {
                           * 1->manual
                           * 2->thermal cruise mode (also called SmartFan I)
                           * 3->fan speed cruise mode
-                          * 4->enhanced variable thermal cruise (also called
-                          *    SmartFan IV)
+                          * 4->SmartFan III
+                          * 5->enhanced variable thermal cruise (SmartFan IV)
                           */
-       u8 pwm[3][5];   /* [0]=pwm, [1]=fan_start_output, [2]=fan_stop_output */
+       u8 pwm[7][5];   /* [0]=pwm, [1]=start_output, [2]=stop_output,
+                        * [3]=max_output, [4]=step_output,
+                        * [5]=weight_duty_step, [6]=weight_duty_base
+                        */
        u8 target_temp[5];
        s16 pwm_temp[5];
        u8 tolerance[5][2];
@@ -555,17 +614,18 @@ struct nct6775_data {
 
        u8 pwm_temp_sel[2][5];
 
-       u8 pwm_weight_enable[5]; /* 0->off, 1->on */
+       bool pwm_sel_enable[2][5];/* 0->stop_val, 1->weight;
+                                  * false->off, true->on
+                                  */
        u8 weight_temp[3][5];   /* 0->temp_step, 1->temp_step_tol,
                                 * 2->temp_base
                                 */
-       u8 weight_duty[2][5];   /* 0->duty_step, 1->duty_base */
 
        u8 vid;
        u8 vrm;
 
        u16 have_temp;
-       u16 have_temp_offset;
+       u16 have_temp_fixed;
        u16 have_in;
 };
 
@@ -578,6 +638,16 @@ static bool is_word_sized(struct nct6775_data *data, u16 reg)
 {
        switch (data->kind) {
        case nct6775:
+               return (((reg & 0xff00) == 0x100 ||
+                   (reg & 0xff00) == 0x200) &&
+                  ((reg & 0x00ff) == 0x50 ||
+                   (reg & 0x00ff) == 0x53 ||
+                   (reg & 0x00ff) == 0x55)) ||
+                 (reg & 0xfff0) == 0x630 ||
+                 reg == 0x640 || reg == 0x642 ||
+                 reg == 0x662 ||
+                 ((reg & 0xfff0) == 0x650 && (reg & 0x000f) >= 0x06) ||
+                 reg == 0x73 || reg == 0x75 || reg == 0x77;
        case nct6776:
                return (((reg & 0xff00) == 0x100 ||
                    (reg & 0xff00) == 0x200) &&
@@ -585,12 +655,14 @@ static bool is_word_sized(struct nct6775_data *data, u16 reg)
                    (reg & 0x00ff) == 0x53 ||
                    (reg & 0x00ff) == 0x55)) ||
                  (reg & 0xfff0) == 0x630 ||
+                 reg == 0x402 ||
                  reg == 0x640 || reg == 0x642 ||
                  ((reg & 0xfff0) == 0x650 && (reg & 0x000f) >= 0x06) ||
                  reg == 0x73 || reg == 0x75 || reg == 0x77;
        case nct6779:
                return reg == 0x150 || reg == 0x153 || reg == 0x155 ||
                  ((reg & 0xfff0) == 0x4c0 && (reg & 0x000f) < 0x09) ||
+                 reg == 0x402 ||
                  reg == 0x63a || reg == 0x63c || reg == 0x63e ||
                  reg == 0x640 || reg == 0x642 ||
                  reg == 0x73 || reg == 0x75 || reg == 0x77 || reg == 0x79 ||
@@ -634,8 +706,7 @@ static u16 nct6775_read_value(struct nct6775_data *data, u16 reg)
        return res;
 }
 
-static int nct6775_write_value(struct nct6775_data *data, u16 reg,
-                                u16 value)
+static int nct6775_write_value(struct nct6775_data *data, u16 reg, u16 value)
 {
        int word_sized = is_word_sized(data, reg);
 
@@ -666,8 +737,7 @@ static u16 nct6775_read_temp(struct nct6775_data *data, u16 reg)
        return res;
 }
 
-static int nct6775_write_temp(struct nct6775_data *data, u16 reg,
-                                      u16 value)
+static int nct6775_write_temp(struct nct6775_data *data, u16 reg, u16 value)
 {
        if (!is_word_sized(data, reg))
                value >>= 8;
@@ -703,7 +773,7 @@ static void nct6775_write_fan_div(struct nct6775_data *data, int nr)
 }
 
 static void nct6775_write_fan_div_common(struct device *dev,
-                                          struct nct6775_data *data, int nr)
+                                        struct nct6775_data *data, int nr)
 {
        if (data->kind == nct6775)
                nct6775_write_fan_div(data, nr);
@@ -723,7 +793,7 @@ static void nct6775_update_fan_div(struct nct6775_data *data)
 }
 
 static void nct6775_update_fan_div_common(struct device *dev,
-                                           struct nct6775_data *data)
+                                         struct nct6775_data *data)
 {
        if (data->kind == nct6775)
                nct6775_update_fan_div(data);
@@ -746,9 +816,13 @@ static void nct6775_update_pwm(struct device *dev)
                data->pwm_mode[i] = duty_is_dc;
 
                fanmodecfg = nct6775_read_value(data, data->REG_FAN_MODE[i]);
-               for (j = 0; j < 3; j++)
-                       data->pwm[j][i]
-                         = nct6775_read_value(data, data->REG_PWM[j][i]);
+               for (j = 0; j < ARRAY_SIZE(data->REG_PWM); j++) {
+                       if (data->REG_PWM[j] && data->REG_PWM[j][i]) {
+                               data->pwm[j][i]
+                                 = nct6775_read_value(data,
+                                                      data->REG_PWM[j][i]);
+                       }
+               }
 
                data->pwm_enable[i] = reg_to_pwm_enable(data->pwm[0][i],
                                                        (fanmodecfg >> 4) & 7);
@@ -763,9 +837,12 @@ static void nct6775_update_pwm(struct device *dev)
                        nct6775_read_value(data,
                                        data->REG_CRITICAL_TEMP_TOLERANCE[i]);
 
-               data->pwm_weight_enable[i] =
+               data->pwm_sel_enable[0][i] =
+                       nct6775_read_value(data, data->REG_TEMP_SEL[0][i])
+                               & 0x80;
+               data->pwm_sel_enable[1][i] =
                        nct6775_read_value(data, data->REG_TEMP_SEL[1][i])
-                               & 0x80 ? 1 : 0;
+                               & 0x80;
 
                /* Weight data */
                for (j = 0; j < 2; j++) {
@@ -779,14 +856,6 @@ static void nct6775_update_pwm(struct device *dev)
                          = nct6775_read_value(data,
                                               data->REG_WEIGHT_TEMP[j][i]);
                }
-               /* Weight duty (pwm) data */
-               for (j = 0; j < 2; j++) {
-                       if (!data->REG_WEIGHT_DUTY[j])
-                               continue;
-                       data->weight_duty[j][i]
-                         = nct6775_read_value(data,
-                                              data->REG_WEIGHT_DUTY[j][i]);
-               }
        }
 }
 
@@ -917,7 +986,7 @@ static struct nct6775_data *nct6775_update_device(struct device *dev)
                nct6775_update_pwm_limits(dev);
 
                /* Measured temperatures and limits */
-               for (i = 0; i < NUM_REG_TEMP; i++) {
+               for (i = 0; i < NUM_TEMP; i++) {
                        if (!(data->have_temp & (1 << i)))
                                continue;
                        for (j = 0; j < 3; j++) {
@@ -926,7 +995,7 @@ static struct nct6775_data *nct6775_update_device(struct device *dev)
                                          = nct6775_read_temp(data,
                                                data->reg_temp[j][i]);
                        }
-                       if (!(data->have_temp_offset & (1 << i)))
+                       if (!(data->have_temp_fixed & (1 << i)))
                                continue;
                        data->temp_offset[i]
                          = nct6775_read_value(data, data->REG_TEMP_OFFSET[i]);
@@ -938,11 +1007,9 @@ static struct nct6775_data *nct6775_update_device(struct device *dev)
                        if (!data->REG_ALARM[i])
                                continue;
                        alarm = nct6775_read_value(data, data->REG_ALARM[i]);
-                       data->alarms |= (((u64)alarm) << (i << 3));
+                       data->alarms |= ((u64)alarm) << (i << 3);
                }
 
-               data->caseopen = nct6775_read_value(data, data->REG_CASEOPEN);
-
                data->last_updated = jiffies;
                data->valid = 1;
        }
@@ -984,12 +1051,12 @@ store_in_reg(struct device *dev, struct device_attribute *attr, const char *buf,
        return count;
 }
 
-static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
-                         char *buf)
+static ssize_t
+show_alarm(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct nct6775_data *data = nct6775_update_device(dev);
-       struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
-       int nr = sensor_attr->index;
+       struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+       int nr = data->ALARM_BITS[sattr->index];
        return sprintf(buf, "%u\n",
                       (unsigned int)((data->alarms >> nr) & 0x01));
 }
@@ -1014,17 +1081,17 @@ 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, 21);
-static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 20);
-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(in9_alarm, S_IRUGO, show_alarm, NULL, 24);
-static SENSOR_DEVICE_ATTR(in10_alarm, S_IRUGO, show_alarm, NULL, 25);
-static SENSOR_DEVICE_ATTR(in11_alarm, S_IRUGO, show_alarm, NULL, 26);
-static SENSOR_DEVICE_ATTR(in12_alarm, S_IRUGO, show_alarm, NULL, 27);
-static SENSOR_DEVICE_ATTR(in13_alarm, S_IRUGO, show_alarm, NULL, 28);
-static SENSOR_DEVICE_ATTR(in14_alarm, S_IRUGO, show_alarm, NULL, 29);
+static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 4);
+static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 5);
+static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 6);
+static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 7);
+static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 8);
+static SENSOR_DEVICE_ATTR(in9_alarm, S_IRUGO, show_alarm, NULL, 9);
+static SENSOR_DEVICE_ATTR(in10_alarm, S_IRUGO, show_alarm, NULL, 10);
+static SENSOR_DEVICE_ATTR(in11_alarm, S_IRUGO, show_alarm, NULL, 11);
+static SENSOR_DEVICE_ATTR(in12_alarm, S_IRUGO, show_alarm, NULL, 12);
+static SENSOR_DEVICE_ATTR(in13_alarm, S_IRUGO, show_alarm, NULL, 13);
+static SENSOR_DEVICE_ATTR(in14_alarm, S_IRUGO, show_alarm, NULL, 14);
 
 static SENSOR_DEVICE_ATTR_2(in0_min, S_IWUSR | S_IRUGO, show_in_reg,
                            store_in_reg, 0, 1);
@@ -1218,8 +1285,8 @@ static ssize_t
 show_fan(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct nct6775_data *data = nct6775_update_device(dev);
-       struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
-       int nr = sensor_attr->index;
+       struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+       int nr = sattr->index;
        return sprintf(buf, "%d\n", data->rpm[nr]);
 }
 
@@ -1227,20 +1294,19 @@ static ssize_t
 show_fan_min(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct nct6775_data *data = nct6775_update_device(dev);
-       struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
-       int nr = sensor_attr->index;
+       struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+       int nr = sattr->index;
        return sprintf(buf, "%d\n",
                       data->fan_from_reg_min(data->fan_min[nr],
                                              data->fan_div[nr]));
 }
 
 static ssize_t
-show_fan_div(struct device *dev, struct device_attribute *attr,
-            char *buf)
+show_fan_div(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct nct6775_data *data = nct6775_update_device(dev);
-       struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
-       int nr = sensor_attr->index;
+       struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+       int nr = sattr->index;
        return sprintf(buf, "%u\n", div_from_reg(data->fan_div[nr]));
 }
 
@@ -1249,8 +1315,8 @@ store_fan_min(struct device *dev, struct device_attribute *attr,
              const char *buf, size_t count)
 {
        struct nct6775_data *data = dev_get_drvdata(dev);
-       struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
-       int nr = sensor_attr->index;
+       struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+       int nr = sattr->index;
        unsigned long val;
        int err;
        unsigned int reg;
@@ -1333,6 +1399,7 @@ write_div:
                /* Give the chip time to sample a new speed value */
                data->last_updated = jiffies;
        }
+
 write_min:
        nct6775_write_value(data, data->REG_FAN_MIN[nr],
                              data->fan_min[nr]);
@@ -1350,11 +1417,11 @@ static struct sensor_device_attribute sda_fan_input[] = {
 };
 
 static struct sensor_device_attribute sda_fan_alarm[] = {
-       SENSOR_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6),
-       SENSOR_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7),
-       SENSOR_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11),
-       SENSOR_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 10),
-       SENSOR_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 23),
+       SENSOR_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, FAN_ALARM_BASE),
+       SENSOR_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, FAN_ALARM_BASE + 1),
+       SENSOR_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, FAN_ALARM_BASE + 2),
+       SENSOR_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, FAN_ALARM_BASE + 3),
+       SENSOR_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, FAN_ALARM_BASE + 4),
 };
 
 static struct sensor_device_attribute sda_fan_min[] = {
@@ -1382,8 +1449,8 @@ static ssize_t
 show_temp_label(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct nct6775_data *data = nct6775_update_device(dev);
-       struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
-       int nr = sensor_attr->index;
+       struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+       int nr = sattr->index;
        return sprintf(buf, "%s\n", data->temp_label[data->temp_src[nr]]);
 }
 
@@ -1425,9 +1492,9 @@ static ssize_t
 show_temp_offset(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct nct6775_data *data = nct6775_update_device(dev);
-       struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+       struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
 
-       return sprintf(buf, "%d\n", data->temp_offset[sensor_attr->index] * 1000);
+       return sprintf(buf, "%d\n", data->temp_offset[sattr->index] * 1000);
 }
 
 static ssize_t
@@ -1435,8 +1502,8 @@ store_temp_offset(struct device *dev, struct device_attribute *attr,
                  const char *buf, size_t count)
 {
        struct nct6775_data *data = dev_get_drvdata(dev);
-       struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
-       int nr = sensor_attr->index;
+       struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+       int nr = sattr->index;
        long val;
        int err;
 
@@ -1458,11 +1525,53 @@ static ssize_t
 show_temp_type(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct nct6775_data *data = nct6775_update_device(dev);
-       struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
-       int nr = sensor_attr->index;
+       struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+       int nr = sattr->index;
        return sprintf(buf, "%d\n", (int)data->temp_type[nr]);
 }
 
+static ssize_t
+store_temp_type(struct device *dev, struct device_attribute *attr,
+               const char *buf, size_t count)
+{
+       struct nct6775_data *data = nct6775_update_device(dev);
+       struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+       int nr = sattr->index;
+       unsigned long val;
+       int err;
+       u8 vbat, diode, bit;
+
+       err = kstrtoul(buf, 10, &val);
+       if (err < 0)
+               return err;
+
+       if (val != 1 && val != 3 && val != 4)
+               return -EINVAL;
+
+       mutex_lock(&data->update_lock);
+
+       data->temp_type[nr] = val;
+       vbat = nct6775_read_value(data, data->REG_VBAT) & ~(0x02 << nr);
+       diode = nct6775_read_value(data, data->REG_DIODE) & ~(0x02 << nr);
+       bit = 0x02 << nr;
+       switch (val) {
+       case 1: /* CPU diode (diode, current mode) */
+               vbat |= bit;
+               diode |= bit;
+               break;
+       case 3: /* diode, voltage mode */
+               vbat |= bit;
+               break;
+       case 4: /* thermistor */
+               break;
+       };
+       nct6775_write_value(data, data->REG_VBAT, vbat);
+       nct6775_write_value(data, data->REG_DIODE, diode);
+
+       mutex_unlock(&data->update_lock);
+       return count;
+}
+
 static struct sensor_device_attribute_2 sda_temp_input[] = {
        SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0),
        SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, 0),
@@ -1470,6 +1579,10 @@ static struct sensor_device_attribute_2 sda_temp_input[] = {
        SENSOR_ATTR_2(temp4_input, S_IRUGO, show_temp, NULL, 3, 0),
        SENSOR_ATTR_2(temp5_input, S_IRUGO, show_temp, NULL, 4, 0),
        SENSOR_ATTR_2(temp6_input, S_IRUGO, show_temp, NULL, 5, 0),
+       SENSOR_ATTR_2(temp7_input, S_IRUGO, show_temp, NULL, 6, 0),
+       SENSOR_ATTR_2(temp8_input, S_IRUGO, show_temp, NULL, 7, 0),
+       SENSOR_ATTR_2(temp9_input, S_IRUGO, show_temp, NULL, 8, 0),
+       SENSOR_ATTR_2(temp10_input, S_IRUGO, show_temp, NULL, 9, 0),
 };
 
 static struct sensor_device_attribute sda_temp_label[] = {
@@ -1479,6 +1592,10 @@ static struct sensor_device_attribute sda_temp_label[] = {
        SENSOR_ATTR(temp4_label, S_IRUGO, show_temp_label, NULL, 3),
        SENSOR_ATTR(temp5_label, S_IRUGO, show_temp_label, NULL, 4),
        SENSOR_ATTR(temp6_label, S_IRUGO, show_temp_label, NULL, 5),
+       SENSOR_ATTR(temp7_label, S_IRUGO, show_temp_label, NULL, 6),
+       SENSOR_ATTR(temp8_label, S_IRUGO, show_temp_label, NULL, 7),
+       SENSOR_ATTR(temp9_label, S_IRUGO, show_temp_label, NULL, 8),
+       SENSOR_ATTR(temp10_label, S_IRUGO, show_temp_label, NULL, 9),
 };
 
 static struct sensor_device_attribute_2 sda_temp_max[] = {
@@ -1494,6 +1611,14 @@ static struct sensor_device_attribute_2 sda_temp_max[] = {
                      4, 1),
        SENSOR_ATTR_2(temp6_max, S_IRUGO | S_IWUSR, show_temp, store_temp,
                      5, 1),
+       SENSOR_ATTR_2(temp7_max, S_IRUGO | S_IWUSR, show_temp, store_temp,
+                     6, 1),
+       SENSOR_ATTR_2(temp8_max, S_IRUGO | S_IWUSR, show_temp, store_temp,
+                     7, 1),
+       SENSOR_ATTR_2(temp9_max, S_IRUGO | S_IWUSR, show_temp, store_temp,
+                     8, 1),
+       SENSOR_ATTR_2(temp10_max, S_IRUGO | S_IWUSR, show_temp, store_temp,
+                     9, 1),
 };
 
 static struct sensor_device_attribute_2 sda_temp_max_hyst[] = {
@@ -1509,6 +1634,14 @@ static struct sensor_device_attribute_2 sda_temp_max_hyst[] = {
                      4, 2),
        SENSOR_ATTR_2(temp6_max_hyst, S_IRUGO | S_IWUSR, show_temp, store_temp,
                      5, 2),
+       SENSOR_ATTR_2(temp7_max_hyst, S_IRUGO | S_IWUSR, show_temp, store_temp,
+                     6, 2),
+       SENSOR_ATTR_2(temp8_max_hyst, S_IRUGO | S_IWUSR, show_temp, store_temp,
+                     7, 2),
+       SENSOR_ATTR_2(temp9_max_hyst, S_IRUGO | S_IWUSR, show_temp, store_temp,
+                     8, 2),
+       SENSOR_ATTR_2(temp9_max_hyst, S_IRUGO | S_IWUSR, show_temp, store_temp,
+                     9, 2),
 };
 
 static struct sensor_device_attribute sda_temp_offset[] = {
@@ -1518,27 +1651,53 @@ static struct sensor_device_attribute sda_temp_offset[] = {
                    store_temp_offset, 1),
        SENSOR_ATTR(temp3_offset, S_IRUGO | S_IWUSR, show_temp_offset,
                    store_temp_offset, 2),
+       SENSOR_ATTR(temp4_offset, S_IRUGO | S_IWUSR, show_temp_offset,
+                   store_temp_offset, 3),
+       SENSOR_ATTR(temp5_offset, S_IRUGO | S_IWUSR, show_temp_offset,
+                   store_temp_offset, 4),
+       SENSOR_ATTR(temp6_offset, S_IRUGO | S_IWUSR, show_temp_offset,
+                   store_temp_offset, 5),
 };
 
-static struct sensor_device_attribute sda_temp_alarm[] = {
-       SENSOR_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4),
-       SENSOR_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5),
-       SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13),
+static struct sensor_device_attribute sda_temp_type[] = {
+       SENSOR_ATTR(temp1_type, S_IRUGO | S_IWUSR, show_temp_type,
+                   store_temp_type, 0),
+       SENSOR_ATTR(temp2_type, S_IRUGO | S_IWUSR, show_temp_type,
+                   store_temp_type, 1),
+       SENSOR_ATTR(temp3_type, S_IRUGO | S_IWUSR, show_temp_type,
+                   store_temp_type, 2),
+       SENSOR_ATTR(temp4_type, S_IRUGO | S_IWUSR, show_temp_type,
+                   store_temp_type, 3),
+       SENSOR_ATTR(temp5_type, S_IRUGO | S_IWUSR, show_temp_type,
+                   store_temp_type, 4),
+       SENSOR_ATTR(temp6_type, S_IRUGO | S_IWUSR, show_temp_type,
+                   store_temp_type, 5),
 };
 
-static struct sensor_device_attribute sda_temp_type[] = {
-       SENSOR_ATTR(temp1_type, S_IRUGO, show_temp_type, NULL, 0),
-       SENSOR_ATTR(temp2_type, S_IRUGO, show_temp_type, NULL, 1),
-       SENSOR_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2),
+static struct sensor_device_attribute sda_temp_alarm[] = {
+       SENSOR_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL,
+                   TEMP_ALARM_BASE),
+       SENSOR_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL,
+                   TEMP_ALARM_BASE + 1),
+       SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL,
+                   TEMP_ALARM_BASE + 2),
+       SENSOR_ATTR(temp4_alarm, S_IRUGO, show_alarm, NULL,
+                   TEMP_ALARM_BASE + 3),
+       SENSOR_ATTR(temp5_alarm, S_IRUGO, show_alarm, NULL,
+                   TEMP_ALARM_BASE + 4),
+       SENSOR_ATTR(temp6_alarm, S_IRUGO, show_alarm, NULL,
+                   TEMP_ALARM_BASE + 5),
 };
 
+#define NUM_TEMP_ALARM ARRAY_SIZE(sda_temp_alarm)
+
 static ssize_t
 show_pwm_mode(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct nct6775_data *data = nct6775_update_device(dev);
-       struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+       struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
 
-       return sprintf(buf, "%d\n", !data->pwm_mode[sensor_attr->index]);
+       return sprintf(buf, "%d\n", !data->pwm_mode[sattr->index]);
 }
 
 static ssize_t
@@ -1546,8 +1705,8 @@ store_pwm_mode(struct device *dev, struct device_attribute *attr,
                        const char *buf, size_t count)
 {
        struct nct6775_data *data = dev_get_drvdata(dev);
-       struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
-       int nr = sensor_attr->index;
+       struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+       int nr = sattr->index;
        unsigned long val;
        int err;
        u8 reg;
@@ -1581,9 +1740,9 @@ static ssize_t
 show_pwm_enable(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct nct6775_data *data = nct6775_update_device(dev);
-       struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+       struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
 
-       return sprintf(buf, "%d\n", data->pwm_enable[sensor_attr->index]);
+       return sprintf(buf, "%d\n", data->pwm_enable[sattr->index]);
 }
 
 static ssize_t
@@ -1616,13 +1775,15 @@ store_pwm(struct device *dev, struct device_attribute *attr, const char *buf,
        int nr = sattr->nr;
        int index = sattr->index;
        unsigned long val;
+       int minval[7] = { 0, 1, 1, data->pwm[2][nr], 0, 0, 0 };
+       int maxval[7]
+         = { 255, 255, data->pwm[3][nr] ? : 255, 255, 255, 255, 255 };
        int err;
 
        err = kstrtoul(buf, 10, &val);
        if (err < 0)
                return err;
-       if (val > 255 || (index && val == 0))
-               return -EINVAL;
+       val = SENSORS_LIMIT(val, minval[index], maxval[index]);
 
        mutex_lock(&data->update_lock);
        data->pwm[index][nr] = val;
@@ -1660,8 +1821,8 @@ store_pwm_enable(struct device *dev, struct device_attribute *attr,
                 const char *buf, size_t count)
 {
        struct nct6775_data *data = dev_get_drvdata(dev);
-       struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
-       int nr = sensor_attr->index;
+       struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+       int nr = sattr->index;
        unsigned long val;
        int err;
        u16 reg;
@@ -1670,10 +1831,13 @@ store_pwm_enable(struct device *dev, struct device_attribute *attr,
        if (err < 0)
                return err;
 
-       if (val > 4)
+       if (val > 5)
                return -EINVAL;
 
-       if (val == 4 && check_trip_points(data, nr)) {
+       if (val == 4 && data->kind != nct6775)
+               return -EINVAL;
+
+       if (val == 5 && check_trip_points(data, nr)) {
                dev_err(dev, "Inconsistent trip points, not switching to SmartFan IV mode\n");
                dev_err(dev, "Adjust trip points and try again\n");
                return -EINVAL;
@@ -1690,7 +1854,7 @@ store_pwm_enable(struct device *dev, struct device_attribute *attr,
        }
        reg = nct6775_read_value(data, data->REG_FAN_MODE[nr]);
        reg &= 0x0f;
-       reg |= (pwm_enable_to_reg(val) << 4);
+       reg |= pwm_enable_to_reg(val) << 4;
        nct6775_write_value(data, data->REG_FAN_MODE[nr], reg);
        mutex_unlock(&data->update_lock);
        return count;
@@ -1727,11 +1891,6 @@ store_pwm_temp_sel(struct device *dev, struct device_attribute *attr,
        unsigned long val;
        int err;
        int reg;
-       static const int max_src[] = {
-           ARRAY_SIZE(nct6775_temp_label),
-           ARRAY_SIZE(nct6776_temp_label),
-           ARRAY_SIZE(nct6779_temp_label)
-       };
 
        err = kstrtoul(buf, 10, &val);
        if (err < 0)
@@ -1739,7 +1898,7 @@ store_pwm_temp_sel(struct device *dev, struct device_attribute *attr,
        if (val == 0 || val > 0x1f)
                return -EINVAL;
 
-       val = SENSORS_LIMIT(val, 1, max_src[data->kind]);
+       val = SENSORS_LIMIT(val, 1, data->temp_label_num - 1);
 
        if (!strlen(data->temp_label[val]))
                return -EINVAL;
@@ -1759,19 +1918,19 @@ static ssize_t
 show_target_temp(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct nct6775_data *data = nct6775_update_device(dev);
-       struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
+       struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
 
        return sprintf(buf, "%d\n",
-                      data->target_temp[sensor_attr->index] * 1000);
+                      data->target_temp[sattr->index] * 1000);
 }
 
 static ssize_t
 store_target_temp(struct device *dev, struct device_attribute *attr,
-                       const char *buf, size_t count)
+                 const char *buf, size_t count)
 {
        struct nct6775_data *data = dev_get_drvdata(dev);
-       struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
-       int nr = sensor_attr->index;
+       struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+       int nr = sattr->index;
        long val;
        int err;
 
@@ -1900,32 +2059,34 @@ static SENSOR_DEVICE_ATTR(pwm4_target, S_IWUSR | S_IRUGO, show_target_temp,
 static SENSOR_DEVICE_ATTR(pwm5_target, S_IWUSR | S_IRUGO, show_target_temp,
                          store_target_temp, 4);
 
-/* Monitored pwm temperatures */ 
-static SENSOR_DEVICE_ATTR(temp7_input, S_IRUGO, show_pwm_temp, NULL, 0);
-static SENSOR_DEVICE_ATTR(temp8_input, S_IRUGO, show_pwm_temp, NULL, 1);
-static SENSOR_DEVICE_ATTR(temp9_input, S_IRUGO, show_pwm_temp, NULL, 2);
-static SENSOR_DEVICE_ATTR(temp10_input, S_IRUGO, show_pwm_temp, NULL, 3);
-static SENSOR_DEVICE_ATTR(temp11_input, S_IRUGO, show_pwm_temp, NULL, 4);
+/* Monitored pwm temperatures */
+static SENSOR_DEVICE_ATTR(temp11_input, S_IRUGO, show_pwm_temp, NULL, 0);
+static SENSOR_DEVICE_ATTR(temp12_input, S_IRUGO, show_pwm_temp, NULL, 1);
+static SENSOR_DEVICE_ATTR(temp13_input, S_IRUGO, show_pwm_temp, NULL, 2);
+static SENSOR_DEVICE_ATTR(temp14_input, S_IRUGO, show_pwm_temp, NULL, 3);
+static SENSOR_DEVICE_ATTR(temp15_input, S_IRUGO, show_pwm_temp, NULL, 4);
 
 /* Smart Fan registers */
 
 static ssize_t
-show_pwm_weight_enable(struct device *dev, struct device_attribute *attr,
-                      char *buf)
+show_pwm_sel_enable(struct device *dev, struct device_attribute *attr,
+                   char *buf)
 {
        struct nct6775_data *data = nct6775_update_device(dev);
-       struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+       struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
 
-       return sprintf(buf, "%d\n", data->pwm_weight_enable[sattr->index]);
+       return sprintf(buf, "%d\n",
+                      data->pwm_sel_enable[sattr->index][sattr->nr]);
 }
 
 static ssize_t
-store_pwm_weight_enable(struct device *dev, struct device_attribute *attr,
-                       const char *buf, size_t count)
+store_pwm_sel_enable(struct device *dev, struct device_attribute *attr,
+                    const char *buf, size_t count)
 {
        struct nct6775_data *data = dev_get_drvdata(dev);
-       struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
-       int nr = sensor_attr->index;
+       struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
+       int nr = sattr->nr;
+       int index = sattr->index;
        unsigned long val;
        int err;
        u8 reg;
@@ -1938,12 +2099,12 @@ store_pwm_weight_enable(struct device *dev, struct device_attribute *attr,
                return -EINVAL;
 
        mutex_lock(&data->update_lock);
-       data->pwm_weight_enable[nr] = val;
-       reg = nct6775_read_value(data, data->REG_TEMP_SEL[1][nr]);
+       data->pwm_sel_enable[index][nr] = val;
+       reg = nct6775_read_value(data, data->REG_TEMP_SEL[index][nr]);
        reg &= 0x7f;
        if (val)
                reg |= 0x80;
-       nct6775_write_value(data, data->REG_TEMP_SEL[1][nr], reg);
+       nct6775_write_value(data, data->REG_TEMP_SEL[index][nr], reg);
        mutex_unlock(&data->update_lock);
        return count;
 }
@@ -1983,51 +2144,27 @@ store_weight_temp(struct device *dev, struct device_attribute *attr,
        return count;
 }
 
-static ssize_t
-show_weight_duty(struct device *dev, struct device_attribute *attr, char *buf)
-{
-       struct nct6775_data *data = nct6775_update_device(dev);
-       struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
-       int nr = sattr->nr;
-       int index = sattr->index;
-
-       return sprintf(buf, "%d\n", data->weight_duty[index][nr]);
-}
-
-static ssize_t
-store_weight_duty(struct device *dev, struct device_attribute *attr,
-                 const char *buf, size_t count)
-{
-       struct nct6775_data *data = dev_get_drvdata(dev);
-       struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
-       int nr = sattr->nr;
-       int index = sattr->index;
-       unsigned long val;
-       int err;
-
-       err = kstrtoul(buf, 10, &val);
-       if (err < 0)
-               return err;
-
-       val = SENSORS_LIMIT(val, 0, 255);
-
-       mutex_lock(&data->update_lock);
-       data->weight_duty[index][nr] = val;
-       nct6775_write_value(data, data->REG_WEIGHT_DUTY[index][nr], val);
-       mutex_unlock(&data->update_lock);
-       return count;
-}
-
-static SENSOR_DEVICE_ATTR(pwm1_weight_enable, S_IWUSR | S_IRUGO,
-                         show_pwm_weight_enable, store_pwm_weight_enable, 0);
-static SENSOR_DEVICE_ATTR(pwm2_weight_enable, S_IWUSR | S_IRUGO,
-                         show_pwm_weight_enable, store_pwm_weight_enable, 1);
-static SENSOR_DEVICE_ATTR(pwm3_weight_enable, S_IWUSR | S_IRUGO,
-                         show_pwm_weight_enable, store_pwm_weight_enable, 2);
-static SENSOR_DEVICE_ATTR(pwm4_weight_enable, S_IWUSR | S_IRUGO,
-                         show_pwm_weight_enable, store_pwm_weight_enable, 3);
-static SENSOR_DEVICE_ATTR(pwm5_weight_enable, S_IWUSR | S_IRUGO,
-                         show_pwm_weight_enable, store_pwm_weight_enable, 4);
+static SENSOR_DEVICE_ATTR_2(pwm1_stop_output_enable, S_IWUSR | S_IRUGO,
+                           show_pwm_sel_enable, store_pwm_sel_enable, 0, 0);
+static SENSOR_DEVICE_ATTR_2(pwm2_stop_output_enable, S_IWUSR | S_IRUGO,
+                           show_pwm_sel_enable, store_pwm_sel_enable, 1, 0);
+static SENSOR_DEVICE_ATTR_2(pwm3_stop_output_enable, S_IWUSR | S_IRUGO,
+                           show_pwm_sel_enable, store_pwm_sel_enable, 2, 0);
+static SENSOR_DEVICE_ATTR_2(pwm4_stop_output_enable, S_IWUSR | S_IRUGO,
+                           show_pwm_sel_enable, store_pwm_sel_enable, 3, 0);
+static SENSOR_DEVICE_ATTR_2(pwm5_stop_output_enable, S_IWUSR | S_IRUGO,
+                           show_pwm_sel_enable, store_pwm_sel_enable, 4, 0);
+
+static SENSOR_DEVICE_ATTR_2(pwm1_weight_enable, S_IWUSR | S_IRUGO,
+                           show_pwm_sel_enable, store_pwm_sel_enable, 0, 1);
+static SENSOR_DEVICE_ATTR_2(pwm2_weight_enable, S_IWUSR | S_IRUGO,
+                           show_pwm_sel_enable, store_pwm_sel_enable, 1, 1);
+static SENSOR_DEVICE_ATTR_2(pwm3_weight_enable, S_IWUSR | S_IRUGO,
+                           show_pwm_sel_enable, store_pwm_sel_enable, 2, 1);
+static SENSOR_DEVICE_ATTR_2(pwm4_weight_enable, S_IWUSR | S_IRUGO,
+                           show_pwm_sel_enable, store_pwm_sel_enable, 3, 1);
+static SENSOR_DEVICE_ATTR_2(pwm5_weight_enable, S_IWUSR | S_IRUGO,
+                           show_pwm_sel_enable, store_pwm_sel_enable, 4, 1);
 
 static SENSOR_DEVICE_ATTR_2(pwm1_weight_temp_sel, S_IWUSR | S_IRUGO,
                            show_pwm_temp_sel, store_pwm_temp_sel, 0, 1);
@@ -2074,28 +2211,28 @@ static SENSOR_DEVICE_ATTR_2(pwm5_weight_temp_step_base, S_IWUSR | S_IRUGO,
                            show_weight_temp, store_weight_temp, 4, 2);
 
 static SENSOR_DEVICE_ATTR_2(pwm1_weight_duty_step, S_IWUSR | S_IRUGO,
-                           show_weight_duty, store_weight_duty, 0, 0);
+                           show_pwm, store_pwm, 0, 5);
 static SENSOR_DEVICE_ATTR_2(pwm2_weight_duty_step, S_IWUSR | S_IRUGO,
-                           show_weight_duty, store_weight_duty, 1, 0);
+                           show_pwm, store_pwm, 1, 5);
 static SENSOR_DEVICE_ATTR_2(pwm3_weight_duty_step, S_IWUSR | S_IRUGO,
-                           show_weight_duty, store_weight_duty, 2, 0);
+                           show_pwm, store_pwm, 2, 5);
 static SENSOR_DEVICE_ATTR_2(pwm4_weight_duty_step, S_IWUSR | S_IRUGO,
-                           show_weight_duty, store_weight_duty, 3, 0);
+                           show_pwm, store_pwm, 3, 5);
 static SENSOR_DEVICE_ATTR_2(pwm5_weight_duty_step, S_IWUSR | S_IRUGO,
-                           show_weight_duty, store_weight_duty, 4, 0);
+                           show_pwm, store_pwm, 4, 5);
 
 /* duty_base is not supported on all chips */
 static struct sensor_device_attribute_2 sda_weight_duty_base[] = {
        SENSOR_ATTR_2(pwm1_weight_duty_base, S_IWUSR | S_IRUGO,
-                     show_weight_duty, store_weight_duty, 0, 1),
+                     show_pwm, store_pwm, 0, 6),
        SENSOR_ATTR_2(pwm2_weight_duty_base, S_IWUSR | S_IRUGO,
-                     show_weight_duty, store_weight_duty, 1, 1),
+                     show_pwm, store_pwm, 1, 6),
        SENSOR_ATTR_2(pwm3_weight_duty_base, S_IWUSR | S_IRUGO,
-                     show_weight_duty, store_weight_duty, 2, 1),
+                     show_pwm, store_pwm, 2, 6),
        SENSOR_ATTR_2(pwm4_weight_duty_base, S_IWUSR | S_IRUGO,
-                     show_weight_duty, store_weight_duty, 3, 1),
+                     show_pwm, store_pwm, 3, 6),
        SENSOR_ATTR_2(pwm5_weight_duty_base, S_IWUSR | S_IRUGO,
-                     show_weight_duty, store_weight_duty, 4, 1),
+                     show_pwm, store_pwm, 4, 6),
 };
 
 static ssize_t
@@ -2134,13 +2271,14 @@ store_fan_time(struct device *dev, struct device_attribute *attr,
        return count;
 }
 
-static ssize_t show_name(struct device *dev, struct device_attribute *attr,
-                        char *buf)
+static ssize_t
+show_name(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct nct6775_data *data = dev_get_drvdata(dev);
 
        return sprintf(buf, "%s\n", data->name);
 }
+
 static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
 
 static SENSOR_DEVICE_ATTR_2(pwm1_stop_time, S_IWUSR | S_IRUGO, show_fan_time,
@@ -2198,12 +2336,41 @@ static SENSOR_DEVICE_ATTR_2(pwm4_stop_output, S_IWUSR | S_IRUGO, show_pwm,
 static SENSOR_DEVICE_ATTR_2(pwm5_stop_output, S_IWUSR | S_IRUGO, show_pwm,
                            store_pwm, 4, 2);
 
-static struct attribute *nct6775_attributes_pwm[5][19] = {
+/* max_output is not supported on all chips */
+static struct sensor_device_attribute_2 sda_max_output[] = {
+       SENSOR_ATTR_2(pwm1_max_output, S_IWUSR | S_IRUGO, show_pwm, store_pwm,
+                     0, 3),
+       SENSOR_ATTR_2(pwm2_max_output, S_IWUSR | S_IRUGO, show_pwm, store_pwm,
+                     1, 3),
+       SENSOR_ATTR_2(pwm3_max_output, S_IWUSR | S_IRUGO, show_pwm, store_pwm,
+                     2, 3),
+       SENSOR_ATTR_2(pwm4_max_output, S_IWUSR | S_IRUGO, show_pwm, store_pwm,
+                     3, 3),
+       SENSOR_ATTR_2(pwm5_max_output, S_IWUSR | S_IRUGO, show_pwm, store_pwm,
+                     4, 3),
+};
+
+/* step_output is not supported on all chips */
+static struct sensor_device_attribute_2 sda_step_output[] = {
+       SENSOR_ATTR_2(pwm1_step_output, S_IWUSR | S_IRUGO, show_pwm, store_pwm,
+                     0, 4),
+       SENSOR_ATTR_2(pwm2_step_output, S_IWUSR | S_IRUGO, show_pwm, store_pwm,
+                     1, 4),
+       SENSOR_ATTR_2(pwm3_step_output, S_IWUSR | S_IRUGO, show_pwm, store_pwm,
+                     2, 4),
+       SENSOR_ATTR_2(pwm4_step_output, S_IWUSR | S_IRUGO, show_pwm, store_pwm,
+                     3, 4),
+       SENSOR_ATTR_2(pwm5_step_output, S_IWUSR | S_IRUGO, show_pwm, store_pwm,
+                     4, 4),
+};
+
+static struct attribute *nct6775_attributes_pwm[5][20] = {
        {
-               &sensor_dev_attr_temp7_input.dev_attr.attr,
+               &sensor_dev_attr_temp11_input.dev_attr.attr,
                &sensor_dev_attr_pwm1.dev_attr.attr,
                &sensor_dev_attr_pwm1_mode.dev_attr.attr,
                &sensor_dev_attr_pwm1_enable.dev_attr.attr,
+               &sensor_dev_attr_pwm1_stop_output_enable.dev_attr.attr,
                &sensor_dev_attr_pwm1_weight_enable.dev_attr.attr,
                &sensor_dev_attr_pwm1_temp_sel.dev_attr.attr,
                &sensor_dev_attr_pwm1_target.dev_attr.attr,
@@ -2220,10 +2387,11 @@ static struct attribute *nct6775_attributes_pwm[5][19] = {
                NULL
        },
        {
-               &sensor_dev_attr_temp8_input.dev_attr.attr,
+               &sensor_dev_attr_temp12_input.dev_attr.attr,
                &sensor_dev_attr_pwm2.dev_attr.attr,
                &sensor_dev_attr_pwm2_mode.dev_attr.attr,
                &sensor_dev_attr_pwm2_enable.dev_attr.attr,
+               &sensor_dev_attr_pwm2_stop_output_enable.dev_attr.attr,
                &sensor_dev_attr_pwm2_weight_enable.dev_attr.attr,
                &sensor_dev_attr_pwm2_temp_sel.dev_attr.attr,
                &sensor_dev_attr_pwm2_target.dev_attr.attr,
@@ -2240,10 +2408,11 @@ static struct attribute *nct6775_attributes_pwm[5][19] = {
                NULL
        },
        {
-               &sensor_dev_attr_temp9_input.dev_attr.attr,
+               &sensor_dev_attr_temp13_input.dev_attr.attr,
                &sensor_dev_attr_pwm3.dev_attr.attr,
                &sensor_dev_attr_pwm3_mode.dev_attr.attr,
                &sensor_dev_attr_pwm3_enable.dev_attr.attr,
+               &sensor_dev_attr_pwm3_stop_output_enable.dev_attr.attr,
                &sensor_dev_attr_pwm3_weight_enable.dev_attr.attr,
                &sensor_dev_attr_pwm3_temp_sel.dev_attr.attr,
                &sensor_dev_attr_pwm3_target.dev_attr.attr,
@@ -2260,10 +2429,11 @@ static struct attribute *nct6775_attributes_pwm[5][19] = {
                NULL
        },
        {
-               &sensor_dev_attr_temp10_input.dev_attr.attr,
+               &sensor_dev_attr_temp14_input.dev_attr.attr,
                &sensor_dev_attr_pwm4.dev_attr.attr,
                &sensor_dev_attr_pwm4_mode.dev_attr.attr,
                &sensor_dev_attr_pwm4_enable.dev_attr.attr,
+               &sensor_dev_attr_pwm4_stop_output_enable.dev_attr.attr,
                &sensor_dev_attr_pwm4_weight_enable.dev_attr.attr,
                &sensor_dev_attr_pwm4_temp_sel.dev_attr.attr,
                &sensor_dev_attr_pwm4_target.dev_attr.attr,
@@ -2280,10 +2450,11 @@ static struct attribute *nct6775_attributes_pwm[5][19] = {
                NULL
        },
        {
-               &sensor_dev_attr_temp11_input.dev_attr.attr,
+               &sensor_dev_attr_temp15_input.dev_attr.attr,
                &sensor_dev_attr_pwm5.dev_attr.attr,
                &sensor_dev_attr_pwm5_mode.dev_attr.attr,
                &sensor_dev_attr_pwm5_enable.dev_attr.attr,
+               &sensor_dev_attr_pwm5_stop_output_enable.dev_attr.attr,
                &sensor_dev_attr_pwm5_weight_enable.dev_attr.attr,
                &sensor_dev_attr_pwm5_temp_sel.dev_attr.attr,
                &sensor_dev_attr_pwm5_target.dev_attr.attr,
@@ -2309,8 +2480,8 @@ static const struct attribute_group nct6775_group_pwm[5] = {
        { .attrs = nct6775_attributes_pwm[4] },
 };
 
-static ssize_t show_auto_pwm(struct device *dev, struct device_attribute *attr,
-                            char *buf)
+static ssize_t
+show_auto_pwm(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct nct6775_data *data = nct6775_update_device(dev);
        struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
@@ -2318,8 +2489,9 @@ static ssize_t show_auto_pwm(struct device *dev, struct device_attribute *attr,
        return sprintf(buf, "%d\n", data->auto_pwm[sattr->nr][sattr->index]);
 }
 
-static ssize_t store_auto_pwm(struct device *dev, struct device_attribute *attr,
-                             const char *buf, size_t count)
+static ssize_t
+store_auto_pwm(struct device *dev, struct device_attribute *attr,
+              const char *buf, size_t count)
 {
        struct nct6775_data *data = dev_get_drvdata(dev);
        struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
@@ -2382,8 +2554,8 @@ static ssize_t store_auto_pwm(struct device *dev, struct device_attribute *attr,
        return count;
 }
 
-static ssize_t show_auto_temp(struct device *dev, struct device_attribute *attr,
-                             char *buf)
+static ssize_t
+show_auto_temp(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct nct6775_data *data = nct6775_update_device(dev);
        struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
@@ -2397,9 +2569,9 @@ static ssize_t show_auto_temp(struct device *dev, struct device_attribute *attr,
        return sprintf(buf, "%d\n", data->auto_temp[nr][point] * 1000);
 }
 
-static ssize_t store_auto_temp(struct device *dev,
-                              struct device_attribute *attr,
-                              const char *buf, size_t count)
+static ssize_t
+store_auto_temp(struct device *dev, struct device_attribute *attr,
+               const char *buf, size_t count)
 {
        struct nct6775_data *data = dev_get_drvdata(dev);
        struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
@@ -2655,27 +2827,18 @@ show_vid(struct device *dev, struct device_attribute *attr, char *buf)
        struct nct6775_data *data = dev_get_drvdata(dev);
        return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
 }
-static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
 
+static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
 
 /* Case open detection */
 
-static ssize_t
-show_caseopen(struct device *dev, struct device_attribute *attr, char *buf)
-{
-       struct nct6775_data *data = nct6775_update_device(dev);
-
-       return sprintf(buf, "%d\n",
-               !!(data->caseopen & to_sensor_dev_attr_2(attr)->index));
-}
-
 static ssize_t
 clear_caseopen(struct device *dev, struct device_attribute *attr,
-                       const char *buf, size_t count)
+              const char *buf, size_t count)
 {
        struct nct6775_data *data = dev_get_drvdata(dev);
        struct nct6775_sio_data *sio_data = dev->platform_data;
-       int nr = to_sensor_dev_attr(attr)->index;
+       int nr = to_sensor_dev_attr(attr)->index - INTRUSION_ALARM_BASE;
        unsigned long val;
        u8 reg;
 
@@ -2694,6 +2857,8 @@ clear_caseopen(struct device *dev, struct device_attribute *attr,
        reg = superio_inb(sio_data->sioreg, NCT6775_REG_CR_CASEOPEN_CLR[nr]);
        reg |= NCT6775_CR_CASEOPEN_CLR_MASK[nr];
        superio_outb(sio_data->sioreg, NCT6775_REG_CR_CASEOPEN_CLR[nr], reg);
+       reg &= ~NCT6775_CR_CASEOPEN_CLR_MASK[nr];
+       superio_outb(sio_data->sioreg, NCT6775_REG_CR_CASEOPEN_CLR[nr], reg);
        superio_exit(sio_data->sioreg);
 
        data->valid = 0;        /* Force cache refresh */
@@ -2704,10 +2869,10 @@ clear_caseopen(struct device *dev, struct device_attribute *attr,
 }
 
 static struct sensor_device_attribute sda_caseopen[] = {
-       SENSOR_ATTR(intrusion0_alarm, S_IWUSR | S_IRUGO, show_caseopen,
-                   clear_caseopen, 0),
-       SENSOR_ATTR(intrusion1_alarm, S_IWUSR | S_IRUGO, show_caseopen,
-                   clear_caseopen, 1),
+       SENSOR_ATTR(intrusion0_alarm, S_IWUSR | S_IRUGO, show_alarm,
+                   clear_caseopen, INTRUSION_ALARM_BASE),
+       SENSOR_ATTR(intrusion1_alarm, S_IWUSR | S_IRUGO, show_alarm,
+                   clear_caseopen, INTRUSION_ALARM_BASE + 1),
 };
 
 /*
@@ -2726,6 +2891,12 @@ static void nct6775_device_remove_files(struct device *dev)
        for (i = 0; i < data->pwm_num; i++)
                sysfs_remove_group(&dev->kobj, &nct6775_group_pwm[i]);
 
+       for (i = 0; i < ARRAY_SIZE(sda_max_output); i++)
+               device_remove_file(dev, &sda_max_output[i].dev_attr);
+
+       for (i = 0; i < ARRAY_SIZE(sda_step_output); i++)
+               device_remove_file(dev, &sda_max_output[i].dev_attr);
+
        for (i = 0; i < ARRAY_SIZE(sda_weight_duty_base); i++)
                device_remove_file(dev, &sda_weight_duty_base[i].dev_attr);
 
@@ -2741,18 +2912,20 @@ static void nct6775_device_remove_files(struct device *dev)
                device_remove_file(dev, &sda_fan_div[i].dev_attr);
                device_remove_file(dev, &sda_fan_min[i].dev_attr);
        }
-       for (i = 0; i < NUM_REG_TEMP; i++) {
+       for (i = 0; i < NUM_TEMP; i++) {
                if (!(data->have_temp & (1 << i)))
                        continue;
                device_remove_file(dev, &sda_temp_input[i].dev_attr);
                device_remove_file(dev, &sda_temp_label[i].dev_attr);
                device_remove_file(dev, &sda_temp_max[i].dev_attr);
                device_remove_file(dev, &sda_temp_max_hyst[i].dev_attr);
-               if (i > 2)
+               if (!(data->have_temp_fixed & (1 << i)))
                        continue;
-               device_remove_file(dev, &sda_temp_alarm[i].dev_attr);
                device_remove_file(dev, &sda_temp_type[i].dev_attr);
                device_remove_file(dev, &sda_temp_offset[i].dev_attr);
+               if (i >= NUM_TEMP_ALARM)
+                       continue;
+               device_remove_file(dev, &sda_temp_alarm[i].dev_attr);
        }
 
        device_remove_file(dev, &sda_caseopen[0].dev_attr);
@@ -2766,7 +2939,7 @@ static void nct6775_device_remove_files(struct device *dev)
 static inline void __devinit nct6775_init_device(struct nct6775_data *data)
 {
        int i;
-       u8 tmp;
+       u8 tmp, diode;
 
        /* Start monitoring if needed */
        if (data->REG_CONFIG) {
@@ -2776,7 +2949,7 @@ static inline void __devinit nct6775_init_device(struct nct6775_data *data)
        }
 
        /* Enable temperature sensors if needed */
-       for (i = 0; i < NUM_REG_TEMP; i++) {
+       for (i = 0; i < NUM_TEMP; i++) {
                if (!(data->have_temp & (1 << i)))
                        continue;
                if (!data->reg_temp_config[i])
@@ -2792,42 +2965,16 @@ static inline void __devinit nct6775_init_device(struct nct6775_data *data)
        if (!(tmp & 0x01))
                nct6775_write_value(data, data->REG_VBAT, tmp | 0x01);
 
-       for (i = 0; i < 3; i++) {
-               const char *label = NULL;
-
-               if (data->temp_label)
-                       label = data->temp_label[data->temp_src[i]];
-
-               /* Digital source overrides analog type */
-               if (label && strncmp(label, "PECI", 4) == 0)
-                       data->temp_type[i] = 6;
-               else if (label && strncmp(label, "AMD", 3) == 0)
-                       data->temp_type[i] = 5;
-               else if ((tmp & (0x02 << i)))
-                       data->temp_type[i] = 1; /* diode */
-               else
-                       data->temp_type[i] = 4; /* thermistor */
-       }
-}
+       diode = nct6775_read_value(data, data->REG_DIODE);
 
-static void w82627ehf_swap_tempreg(struct nct6775_data *data,
-                                  int r1, int r2)
-{
-       u16 tmp, i;
-
-       tmp = data->temp_src[r1];
-       data->temp_src[r1] = data->temp_src[r2];
-       data->temp_src[r2] = tmp;
-
-       for (i = 0; i < 3; i++) {
-               tmp = data->reg_temp[i][r1];
-               data->reg_temp[i][r1] = data->reg_temp[i][r2];
-               data->reg_temp[i][r2] = tmp;
+       for (i = 0; i < data->temp_fixed_num; i++) {
+               if (!(data->have_temp_fixed & (1 << i)))
+                       continue;
+               if ((tmp & (0x02 << i)))        /* diode */
+                       data->temp_type[i] = 3 - ((diode >> i) & 0x02);
+               else                            /* thermistor */
+                       data->temp_type[i] = 4;
        }
-
-       tmp = data->reg_temp_config[r1];
-       data->reg_temp_config[r1] = data->reg_temp_config[r2];
-       data->reg_temp_config[r2] = tmp;
 }
 
 static void __devinit
@@ -2898,8 +3045,8 @@ nct6775_check_fan_inputs(const struct nct6775_sio_data *sio_data,
        superio_exit(sio_data->sioreg);
 
        data->has_fan = data->has_fan_min = 0x03; /* fan1 and fan2 */
-       data->has_fan |= (fan3pin << 2);
-       data->has_fan_min |= (fan3min << 2);
+       data->has_fan |= fan3pin << 2;
+       data->has_fan_min |= fan3min << 2;
 
        data->has_fan |= (fan4pin << 3) | (fan5pin << 4);
        data->has_fan_min |= (fan4min << 3) | (fan5pin << 4);
@@ -2913,8 +3060,8 @@ static int __devinit nct6775_probe(struct platform_device *pdev)
        struct nct6775_sio_data *sio_data = dev->platform_data;
        struct nct6775_data *data;
        struct resource *res;
-       int i, err = 0;
-       int src, mask = 0;
+       int i, s, err = 0;
+       int src, mask, available;
        const u16 *reg_temp, *reg_temp_over, *reg_temp_hyst, *reg_temp_config;
 
        res = platform_get_resource(pdev, IORESOURCE_IO, 0);
@@ -2947,12 +3094,19 @@ static int __devinit nct6775_probe(struct platform_device *pdev)
                data->pwm_num = 3;
                data->auto_pwm_num = 6;
                data->has_fan_div = true;
+               data->temp_fixed_num = 3;
+
+               data->ALARM_BITS = NCT6775_ALARM_BITS;
 
                data->fan_from_reg = fan_from_reg16;
                data->fan_from_reg_min = fan_from_reg8;
 
+               data->temp_label = nct6775_temp_label;
+               data->temp_label_num = ARRAY_SIZE(nct6775_temp_label);
+
                data->REG_CONFIG = NCT6775_REG_CONFIG;
                data->REG_VBAT = NCT6775_REG_VBAT;
+               data->REG_DIODE = NCT6775_REG_DIODE;
                data->REG_VIN = NCT6775_REG_IN;
                data->REG_IN_MINMAX[0] = NCT6775_REG_IN_MIN;
                data->REG_IN_MINMAX[1] = NCT6775_REG_IN_MAX;
@@ -2966,9 +3120,13 @@ static int __devinit nct6775_probe(struct platform_device *pdev)
                data->REG_PWM[0] = NCT6775_REG_PWM;
                data->REG_PWM[1] = NCT6775_REG_FAN_START_OUTPUT;
                data->REG_PWM[2] = NCT6775_REG_FAN_STOP_OUTPUT;
+               data->REG_PWM[3] = NCT6775_REG_FAN_MAX_OUTPUT;
+               data->REG_PWM[4] = NCT6775_REG_FAN_STEP_OUTPUT;
+               data->REG_PWM[5] = NCT6775_REG_WEIGHT_DUTY_STEP;
                data->REG_PWM_READ = NCT6775_REG_PWM_READ;
                data->REG_PWM_MODE = NCT6775_REG_PWM_MODE;
                data->PWM_MODE_MASK = NCT6775_PWM_MODE_MASK;
+               data->REG_TEMP_ALTERNATE = NCT6775_REG_TEMP_ALTERNATE;
                data->REG_TEMP_MON = NCT6775_REG_TEMP_MON;
                data->REG_AUTO_TEMP = NCT6775_REG_AUTO_TEMP;
                data->REG_AUTO_PWM = NCT6775_REG_AUTO_PWM;
@@ -2982,10 +3140,7 @@ static int __devinit nct6775_probe(struct platform_device *pdev)
                data->REG_WEIGHT_TEMP[0] = NCT6775_REG_WEIGHT_TEMP_STEP;
                data->REG_WEIGHT_TEMP[1] = NCT6775_REG_WEIGHT_TEMP_STEP_TOL;
                data->REG_WEIGHT_TEMP[2] = NCT6775_REG_WEIGHT_TEMP_BASE;
-               data->REG_WEIGHT_DUTY[0] = NCT6775_REG_WEIGHT_DUTY_STEP;
                data->REG_ALARM = NCT6775_REG_ALARM;
-               data->REG_CASEOPEN = NCT6775_REG_CASEOPEN;
-               data->CASEOPEN_MASK = NCT6775_CASEOPEN_MASK;
 
                reg_temp = NCT6775_REG_TEMP;
                reg_temp_over = NCT6775_REG_TEMP_OVER;
@@ -2999,11 +3154,19 @@ static int __devinit nct6775_probe(struct platform_device *pdev)
                data->pwm_num = 3;
                data->auto_pwm_num = 4;
                data->has_fan_div = false;
+               data->temp_fixed_num = 3;
+
+               data->ALARM_BITS = NCT6776_ALARM_BITS;
+
                data->fan_from_reg = fan_from_reg13;
                data->fan_from_reg_min = fan_from_reg13;
 
+               data->temp_label = nct6776_temp_label;
+               data->temp_label_num = ARRAY_SIZE(nct6776_temp_label);
+
                data->REG_CONFIG = NCT6775_REG_CONFIG;
                data->REG_VBAT = NCT6775_REG_VBAT;
+               data->REG_DIODE = NCT6775_REG_DIODE;
                data->REG_VIN = NCT6775_REG_IN;
                data->REG_IN_MINMAX[0] = NCT6775_REG_IN_MIN;
                data->REG_IN_MINMAX[1] = NCT6775_REG_IN_MAX;
@@ -3017,9 +3180,12 @@ static int __devinit nct6775_probe(struct platform_device *pdev)
                data->REG_PWM[0] = NCT6775_REG_PWM;
                data->REG_PWM[1] = NCT6775_REG_FAN_START_OUTPUT;
                data->REG_PWM[2] = NCT6775_REG_FAN_STOP_OUTPUT;
+               data->REG_PWM[5] = NCT6775_REG_WEIGHT_DUTY_STEP;
+               data->REG_PWM[6] = NCT6776_REG_WEIGHT_DUTY_BASE;
                data->REG_PWM_READ = NCT6775_REG_PWM_READ;
                data->REG_PWM_MODE = NCT6776_REG_PWM_MODE;
                data->PWM_MODE_MASK = NCT6776_PWM_MODE_MASK;
+               data->REG_TEMP_ALTERNATE = NCT6776_REG_TEMP_ALTERNATE;
                data->REG_TEMP_MON = NCT6775_REG_TEMP_MON;
                data->REG_AUTO_TEMP = NCT6775_REG_AUTO_TEMP;
                data->REG_AUTO_PWM = NCT6775_REG_AUTO_PWM;
@@ -3033,11 +3199,7 @@ static int __devinit nct6775_probe(struct platform_device *pdev)
                data->REG_WEIGHT_TEMP[0] = NCT6775_REG_WEIGHT_TEMP_STEP;
                data->REG_WEIGHT_TEMP[1] = NCT6775_REG_WEIGHT_TEMP_STEP_TOL;
                data->REG_WEIGHT_TEMP[2] = NCT6775_REG_WEIGHT_TEMP_BASE;
-               data->REG_WEIGHT_DUTY[0] = NCT6775_REG_WEIGHT_DUTY_STEP;
-               data->REG_WEIGHT_DUTY[1] = NCT6776_REG_WEIGHT_DUTY_BASE;
                data->REG_ALARM = NCT6775_REG_ALARM;
-               data->REG_CASEOPEN = NCT6775_REG_CASEOPEN;
-               data->CASEOPEN_MASK = NCT6776_CASEOPEN_MASK;
 
                reg_temp = NCT6775_REG_TEMP;
                reg_temp_over = NCT6775_REG_TEMP_OVER;
@@ -3051,12 +3213,19 @@ static int __devinit nct6775_probe(struct platform_device *pdev)
                data->pwm_num = 5;
                data->auto_pwm_num = 4;
                data->has_fan_div = false;
+               data->temp_fixed_num = 6;
+
+               data->ALARM_BITS = NCT6779_ALARM_BITS;
 
                data->fan_from_reg = fan_from_reg13;
                data->fan_from_reg_min = fan_from_reg13;
 
+               data->temp_label = nct6779_temp_label;
+               data->temp_label_num = ARRAY_SIZE(nct6779_temp_label);
+
                data->REG_CONFIG = NCT6775_REG_CONFIG;
                data->REG_VBAT = NCT6775_REG_VBAT;
+               data->REG_DIODE = NCT6775_REG_DIODE;
                data->REG_VIN = NCT6779_REG_IN;
                data->REG_IN_MINMAX[0] = NCT6775_REG_IN_MIN;
                data->REG_IN_MINMAX[1] = NCT6775_REG_IN_MAX;
@@ -3070,27 +3239,26 @@ static int __devinit nct6775_probe(struct platform_device *pdev)
                data->REG_PWM[0] = NCT6775_REG_PWM;
                data->REG_PWM[1] = NCT6775_REG_FAN_START_OUTPUT;
                data->REG_PWM[2] = NCT6775_REG_FAN_STOP_OUTPUT;
+               data->REG_PWM[5] = NCT6775_REG_WEIGHT_DUTY_STEP;
+               data->REG_PWM[6] = NCT6776_REG_WEIGHT_DUTY_BASE;
                data->REG_PWM_READ = NCT6775_REG_PWM_READ;
                data->REG_PWM_MODE = NCT6776_REG_PWM_MODE;
                data->PWM_MODE_MASK = NCT6776_PWM_MODE_MASK;
+               data->REG_TEMP_ALTERNATE = NCT6779_REG_TEMP_ALTERNATE;
                data->REG_TEMP_MON = NCT6775_REG_TEMP_MON;
                data->REG_AUTO_TEMP = NCT6775_REG_AUTO_TEMP;
                data->REG_AUTO_PWM = NCT6775_REG_AUTO_PWM;
                data->REG_CRITICAL_TEMP = NCT6775_REG_CRITICAL_TEMP;
                data->REG_CRITICAL_TEMP_TOLERANCE
                  = NCT6775_REG_CRITICAL_TEMP_TOLERANCE;
-               data->REG_TEMP_OFFSET = NCT6775_REG_TEMP_OFFSET;
+               data->REG_TEMP_OFFSET = NCT6779_REG_TEMP_OFFSET;
                data->REG_TEMP_SOURCE = NCT6775_REG_TEMP_SOURCE;
                data->REG_TEMP_SEL[0] = NCT6775_REG_TEMP_SEL;
                data->REG_TEMP_SEL[1] = NCT6775_REG_WEIGHT_TEMP_SEL;
                data->REG_WEIGHT_TEMP[0] = NCT6775_REG_WEIGHT_TEMP_STEP;
                data->REG_WEIGHT_TEMP[1] = NCT6775_REG_WEIGHT_TEMP_STEP_TOL;
                data->REG_WEIGHT_TEMP[2] = NCT6775_REG_WEIGHT_TEMP_BASE;
-               data->REG_WEIGHT_DUTY[0] = NCT6775_REG_WEIGHT_DUTY_STEP;
-               data->REG_WEIGHT_DUTY[1] = NCT6776_REG_WEIGHT_DUTY_BASE;
                data->REG_ALARM = NCT6779_REG_ALARM;
-               data->REG_CASEOPEN = NCT6775_REG_CASEOPEN;
-               data->CASEOPEN_MASK = NCT6776_CASEOPEN_MASK;
 
                reg_temp = NCT6779_REG_TEMP;
                reg_temp_over = NCT6775_REG_TEMP_OVER;
@@ -3103,57 +3271,131 @@ static int __devinit nct6775_probe(struct platform_device *pdev)
                goto exit_release;
        }
 
-       /* Default to no temperature inputs, code below will adjust as needed */
        data->have_temp = 0;
 
+       /*
+        * On some boards, not all available temperature sources are monitored,
+        * even though some of the monitoring registers are unused.
+        * Get list of unused monitoring registers, then detect if any fan
+        * controls are configured to use unmonitored temperature sources.
+        * If so, assign the unmonitored temperature sources to available
+        * monitoring registers.
+        */
+       mask = 0;
+       available = 0;
        for (i = 0; i < NUM_REG_TEMP; i++) {
                if (reg_temp[i] == 0)
                        continue;
 
-               data->reg_temp[0][i] = reg_temp[i];
-               data->reg_temp[1][i] = reg_temp_over[i];
-               data->reg_temp[2][i] = reg_temp_hyst[i];
-               data->reg_temp_config[i] = reg_temp_config[i];
+               src = nct6775_read_value(data, data->REG_TEMP_SOURCE[i]) & 0x1f;
+               if (!src || (mask & (1 << src)))
+                       available |= 1 << i;
+
+               mask |= 1 << src;
+       }
+
+       /*
+        * Now find unmonitored temperature registers and enable monitoring
+        * if additional monitoring registers are available.
+        */
+       for (i = 0; i < ARRAY_SIZE(data->REG_TEMP_SEL) && available; i++) {
+               int j;
+
+               if (!data->REG_TEMP_SEL[i])
+                       continue;
+               for (j = 0; j < data->pwm_num && available; j++) {
+                       int index;
 
-               src = nct6775_read_value(data, data->REG_TEMP_SOURCE[i]);
-               src &= 0x1f;
+                       if (!data->REG_TEMP_SEL[i][j])
+                               continue;
+                       src = nct6775_read_value(data,
+                                                data->REG_TEMP_SEL[i][j]);
+                       src &= 0x1f;
+                       if (!src || (mask & (1 << src)))
+                               continue;
 
-               if (src && !(mask & (1 << src))) {
-                       data->have_temp |= 1 << i;
+                       index = __ffs(available);
+                       nct6775_write_value(data,
+                                           data->REG_TEMP_SOURCE[index],
+                                           src);
+                       available &= ~(1 << index);
                        mask |= 1 << src;
                }
+       }
 
-               data->temp_src[i] = src;
+       mask = 0;
+       s = NUM_TEMP_FIXED;     /* First dynamic temperature attribute */
+       for (i = 0; i < NUM_REG_TEMP; i++) {
+               if (reg_temp[i] == 0)
+                       continue;
 
-               /*
-                * Do some register swapping if index 0..2 don't
-                * point to SYSTIN(1), CPUIN(2), and AUXIN(3).
-                * Idea is to have the first three attributes
-                * report SYSTIN, CPUIN, and AUXIN if possible
-                * without overriding the basic system configuration.
-                * Do this only for the first six temperature sources;
-                * the remaining temperatures are fan control sources,
-                * and we don't want to touch those.
-                */
-               if (i > 0 && data->temp_src[0] != 1
-                           && data->temp_src[i] == 1)
-                               w82627ehf_swap_tempreg(data, 0, i);
-               if (i > 1 && data->temp_src[1] != 2
-                           && data->temp_src[i] == 2)
-                               w82627ehf_swap_tempreg(data, 1, i);
-               if (i > 2 && data->temp_src[2] != 3
-                           && data->temp_src[i] == 3)
-                               w82627ehf_swap_tempreg(data, 2, i);
+               src = nct6775_read_value(data, data->REG_TEMP_SOURCE[i]) & 0x1f;
+               if (!src || (mask & (1 << src)))
+                       continue;
+
+               mask |= 1 << src;
+
+               /* Use fixed index for SYSTIN(1), CPUTIN(2), AUXTIN(3) */
+               if (src <= data->temp_fixed_num) {
+                       data->have_temp |= 1 << (src - 1);
+                       data->have_temp_fixed |= 1 << (src - 1);
+                       data->reg_temp[0][src - 1] = reg_temp[i];
+                       data->reg_temp[1][src - 1] = reg_temp_over[i];
+                       data->reg_temp[2][src - 1] = reg_temp_hyst[i];
+                       data->reg_temp_config[src - 1] = reg_temp_config[i];
+                       data->temp_src[src - 1] = src;
+                       continue;
+               }
+
+               if (s >= NUM_TEMP)
+                       continue;
+
+               /* Use dynamic index for other sources */
+               data->have_temp |= 1 << s;
+               data->reg_temp[0][s] = reg_temp[i];
+               data->reg_temp[1][s] = reg_temp_over[i];
+               data->reg_temp[2][s] = reg_temp_hyst[i];
+               data->reg_temp_config[s] = reg_temp_config[i];
+
+               data->temp_src[s] = src;
+               s++;
        }
-       data->have_temp_offset = data->have_temp & 0x07;
-       for (i = 0; i < 3; i++) {
-               if (data->temp_src[i] > 3)
-                       data->have_temp_offset &= ~(1 << i);
+
+#ifdef TESTING
+       /*
+        * We may have alternate registers for some sensors.
+        * Go through the list and enable if possible.
+        * The temperature is already monitored if the respective bit in <mask>
+        * is set.
+        */
+       if (data->REG_TEMP_ALTERNATE) {
+               for (i = 0; i < data->temp_label_num; i++) {
+                       if (!data->REG_TEMP_ALTERNATE[i])
+                               continue;
+                       if (mask & (1 << (i + 1)))
+                               continue;
+                       if (i < data->temp_fixed_num) {
+                               if (data->have_temp & (1 << i))
+                                       continue;
+                               data->have_temp |= 1 << i;
+                               data->reg_temp[0][i] = data->REG_TEMP_ALTERNATE[i];
+                               data->temp_src[i] = i + 1;
+                               continue;
+                       }
+
+                       if (s >= NUM_TEMP)      /* Abort if no more space */
+                               break;
+
+                       data->have_temp |= 1 << s;
+                       data->reg_temp[0][s] = data->REG_TEMP_ALTERNATE[i];
+                       data->temp_src[s] = i + 1;
+                       s++;
+               }
        }
+#endif /* TESTING */
 
        switch (data->kind) {
        case nct6775:
-               data->temp_label = nct6775_temp_label;
                break;
        case nct6776:
                /*
@@ -3165,21 +3407,14 @@ static int __devinit nct6775_probe(struct platform_device *pdev)
                 * If that is the case, disable in6, which reports VIN3.
                 * Otherwise disable temp3.
                 */
-               if (data->temp_src[2] == 3) {
-                       u8 reg;
-
-                       if (data->reg_temp_config[2])
-                               reg = nct6775_read_value(data,
-                                       data->reg_temp_config[2]);
-                       else
-                               reg = 0; /* Assume AUXTIN is used */
-
+               if (data->have_temp & (1 << 2)) {
+                       u8 reg = nct6775_read_value(data,
+                                                   data->reg_temp_config[2]);
                        if (reg & 0x01)
                                data->have_temp &= ~(1 << 2);
                        else
                                data->have_in &= ~(1 << 6);
                }
-               data->temp_label = nct6776_temp_label;
                break;
        case nct6779:
                /*
@@ -3194,16 +3429,15 @@ static int __devinit nct6775_probe(struct platform_device *pdev)
                for (i = 0; i < ARRAY_SIZE(NCT6779_REG_TEMP); i++) {
                        if (!(data->have_temp & (1 << i)))
                                continue;
-                       if (data->temp_src[i] == 3)             /* AUXTIN0 */
+                       if (i == 2)                             /* AUXTIN0 */
                                data->have_in &= ~(1 << 6);     /* no VIN4 */
-                       if (data->temp_src[i] == 4)             /* AUXTIN1 */
+                       if (i == 3)                             /* AUXTIN1 */
                                data->have_in &= ~(1 << 10);    /* no VIN5 */
-                       if (data->temp_src[i] == 5)             /* AUXTIN2 */
+                       if (i == 4)                             /* AUXTIN2 */
                                data->have_in &= ~(1 << 11);    /* no VIN6 */
-                       if (data->temp_src[i] == 6)             /* AUXTIN0 */
+                       if (i == 5)                             /* AUXTIN3 */
                                data->have_in &= ~(1 << 14);    /* no VIN7 */
                }
-               data->temp_label = nct6779_temp_label;
                break;
        }
 
@@ -3258,7 +3492,19 @@ static int __devinit nct6775_probe(struct platform_device *pdev)
                if (err)
                        goto exit_remove;
 
-               if (data->REG_WEIGHT_DUTY[1]) {
+               if (data->REG_PWM[3]) {
+                       err = device_create_file(dev,
+                                       &sda_max_output[i].dev_attr);
+                       if (err)
+                               goto exit_remove;
+               }
+               if (data->REG_PWM[4]) {
+                       err = device_create_file(dev,
+                                       &sda_step_output[i].dev_attr);
+                       if (err)
+                               goto exit_remove;
+               }
+               if (data->REG_PWM[6]) {
                        err = device_create_file(dev,
                                        &sda_weight_duty_base[i].dev_attr);
                        if (err)
@@ -3312,7 +3558,7 @@ static int __devinit nct6775_probe(struct platform_device *pdev)
                }
        }
 
-       for (i = 0; i < NUM_REG_TEMP; i++) {
+       for (i = 0; i < NUM_TEMP; i++) {
                if (!(data->have_temp & (1 << i)))
                        continue;
                err = device_create_file(dev, &sda_temp_input[i].dev_attr);
@@ -3336,24 +3582,25 @@ static int __devinit nct6775_probe(struct platform_device *pdev)
                        if (err)
                                goto exit_remove;
                }
-               if (i > 2)
+               if (!(data->have_temp_fixed & (1 << i)))
                        continue;
-               err = device_create_file(dev, &sda_temp_alarm[i].dev_attr);
+               err = device_create_file(dev, &sda_temp_type[i].dev_attr);
                if (err)
                        goto exit_remove;
-               err = device_create_file(dev, &sda_temp_type[i].dev_attr);
+               err = device_create_file(dev,
+                                        &sda_temp_offset[i].dev_attr);
+               if (err)
+                       goto exit_remove;
+               if (i >= NUM_TEMP_ALARM ||
+                   data->ALARM_BITS[TEMP_ALARM_BASE + i] < 0)
+                       continue;
+               err = device_create_file(dev, &sda_temp_alarm[i].dev_attr);
                if (err)
                        goto exit_remove;
-               if (data->have_temp_offset & (1 << i)) {
-                       err = device_create_file(dev,
-                                                &sda_temp_offset[i].dev_attr);
-                       if (err)
-                               goto exit_remove;
-               }
        }
 
        for (i = 0; i < ARRAY_SIZE(sda_caseopen); i++) {
-               if (!data->CASEOPEN_MASK[i])
+               if (data->ALARM_BITS[INTRUSION_ALARM_BASE + i] < 0)
                        continue;
                err = device_create_file(dev, &sda_caseopen[i].dev_attr);
                if (err)