vserver 2.0 rc7
[linux-2.6.git] / drivers / i2c / chips / w83627hf.c
index 697cd43..b1da5ed 100644 (file)
@@ -40,6 +40,7 @@
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/slab.h>
+#include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/i2c-sensor.h>
 #include <linux/i2c-vid.h>
@@ -303,7 +304,6 @@ struct w83627hf_data {
        u32 beep_mask;          /* Register encoding, combined */
        u8 beep_enable;         /* Boolean */
        u8 pwm[3];              /* Register value */
-       u8 pwmenable[3];        /* bool */
        u16 sens[3];            /* 782D/783S only.
                                   1 = pentium diode; 2 = 3904 diode;
                                   3000-5000 = thermistor beta.
@@ -354,10 +354,13 @@ store_in_##reg (struct device *dev, const char *buf, size_t count, int nr) \
        u32 val; \
         \
        val = simple_strtoul(buf, NULL, 10); \
+        \
+       down(&data->update_lock); \
        data->in_##reg[nr] = IN_TO_REG(val); \
        w83627hf_write_value(client, W83781D_REG_IN_##REG(nr), \
                            data->in_##reg[nr]); \
         \
+       up(&data->update_lock); \
        return count; \
 }
 store_in_reg(MIN, min)
@@ -442,6 +445,9 @@ static ssize_t store_regs_in_min0(struct device *dev,
        u32 val;
 
        val = simple_strtoul(buf, NULL, 10);
+
+       down(&data->update_lock);
+       
        if ((data->vrm_ovt & 0x01) &&
                (w83627thf == data->type || w83637hf == data->type))
 
@@ -452,6 +458,7 @@ static ssize_t store_regs_in_min0(struct device *dev,
                data->in_min[0] = IN_TO_REG(val);
 
        w83627hf_write_value(client, W83781D_REG_IN_MIN(0), data->in_min[0]);
+       up(&data->update_lock);
        return count;
 }
 
@@ -463,6 +470,9 @@ static ssize_t store_regs_in_max0(struct device *dev,
        u32 val;
 
        val = simple_strtoul(buf, NULL, 10);
+
+       down(&data->update_lock);
+
        if ((data->vrm_ovt & 0x01) &&
                (w83627thf == data->type || w83637hf == data->type))
                
@@ -473,6 +483,7 @@ static ssize_t store_regs_in_max0(struct device *dev,
                data->in_max[0] = IN_TO_REG(val);
 
        w83627hf_write_value(client, W83781D_REG_IN_MAX(0), data->in_max[0]);
+       up(&data->update_lock);
        return count;
 }
 
@@ -508,11 +519,14 @@ store_fan_min(struct device *dev, const char *buf, size_t count, int nr)
        u32 val;
 
        val = simple_strtoul(buf, NULL, 10);
+
+       down(&data->update_lock);
        data->fan_min[nr - 1] =
            FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr - 1]));
        w83627hf_write_value(client, W83781D_REG_FAN_MIN(nr),
                            data->fan_min[nr - 1]);
 
+       up(&data->update_lock);
        return count;
 }
 
@@ -574,6 +588,8 @@ store_temp_##reg (struct device *dev, const char *buf, size_t count, int nr) \
         \
        val = simple_strtoul(buf, NULL, 10); \
         \
+       down(&data->update_lock); \
+        \
        if (nr >= 2) {  /* TEMP2 and TEMP3 */ \
                data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \
                w83627hf_write_value(client, W83781D_REG_TEMP_##REG(nr), \
@@ -584,6 +600,7 @@ store_temp_##reg (struct device *dev, const char *buf, size_t count, int nr) \
                        data->temp_##reg); \
        } \
         \
+       up(&data->update_lock); \
        return count; \
 }
 store_temp_reg(OVER, max);
@@ -692,6 +709,8 @@ store_beep_reg(struct device *dev, const char *buf, size_t count,
 
        val = simple_strtoul(buf, NULL, 10);
 
+       down(&data->update_lock);
+
        if (update_mask == BEEP_MASK) { /* We are storing beep_mask */
                data->beep_mask = BEEP_MASK_TO_REG(val);
                w83627hf_write_value(client, W83781D_REG_BEEP_INTS1,
@@ -708,6 +727,7 @@ store_beep_reg(struct device *dev, const char *buf, size_t count,
        w83627hf_write_value(client, W83781D_REG_BEEP_INTS2,
                            val2 | data->beep_enable << 7);
 
+       up(&data->update_lock);
        return count;
 }
 
@@ -752,12 +772,15 @@ store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr)
        struct w83627hf_data *data = i2c_get_clientdata(client);
        unsigned long min;
        u8 reg;
+       unsigned long val = simple_strtoul(buf, NULL, 10);
+
+       down(&data->update_lock);
 
        /* Save fan_min */
        min = FAN_FROM_REG(data->fan_min[nr],
                           DIV_FROM_REG(data->fan_div[nr]));
 
-       data->fan_div[nr] = DIV_TO_REG(simple_strtoul(buf, NULL, 10));
+       data->fan_div[nr] = DIV_TO_REG(val);
 
        reg = (w83627hf_read_value(client, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV)
               & (nr==0 ? 0xcf : 0x3f))
@@ -773,6 +796,7 @@ store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr)
        data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
        w83627hf_write_value(client, W83781D_REG_FAN_MIN(nr+1), data->fan_min[nr]);
 
+       up(&data->update_lock);
        return count;
 }
 
@@ -815,6 +839,8 @@ store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr)
 
        val = simple_strtoul(buf, NULL, 10);
 
+       down(&data->update_lock);
+
        if (data->type == w83627thf) {
                /* bits 0-3 are reserved  in 627THF */
                data->pwm[nr - 1] = PWM_TO_REG(val) & 0xf0;
@@ -830,6 +856,7 @@ store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr)
                                     data->pwm[nr - 1]);
        }
 
+       up(&data->update_lock);
        return count;
 }
 
@@ -871,6 +898,8 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr)
 
        val = simple_strtoul(buf, NULL, 10);
 
+       down(&data->update_lock);
+
        switch (val) {
        case 1:         /* PII/Celeron diode */
                tmp = w83627hf_read_value(client, W83781D_REG_SCFG1);
@@ -903,6 +932,7 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr)
                break;
        }
 
+       up(&data->update_lock);
        return count;
 }
 
@@ -1316,11 +1346,28 @@ static void w83627hf_init_client(struct i2c_client *client)
                        break;
        }
 
-       data->pwmenable[0] = 1;
-       data->pwmenable[1] = 1;
-       data->pwmenable[2] = 1;
-
        if(init) {
+               /* Enable temp2 */
+               tmp = w83627hf_read_value(client, W83781D_REG_TEMP2_CONFIG);
+               if (tmp & 0x01) {
+                       dev_warn(&client->dev, "Enabling temp2, readings "
+                                "might not make sense\n");
+                       w83627hf_write_value(client, W83781D_REG_TEMP2_CONFIG,
+                               tmp & 0xfe);
+               }
+
+               /* Enable temp3 */
+               if (type != w83697hf) {
+                       tmp = w83627hf_read_value(client,
+                               W83781D_REG_TEMP3_CONFIG);
+                       if (tmp & 0x01) {
+                               dev_warn(&client->dev, "Enabling temp3, "
+                                        "readings might not make sense\n");
+                               w83627hf_write_value(client,
+                                       W83781D_REG_TEMP3_CONFIG, tmp & 0xfe);
+                       }
+               }
+
                if (type == w83627hf) {
                        /* enable PWM2 control (can't hurt since PWM reg
                           should have been reset to 0xff) */
@@ -1350,8 +1397,8 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev)
 
        down(&data->update_lock);
 
-       if ((jiffies - data->last_updated > HZ + HZ / 2) ||
-           (jiffies < data->last_updated) || !data->valid) {
+       if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
+           || !data->valid) {
                for (i = 0; i <= 8; i++) {
                        /* skip missing sensors */
                        if (((data->type == w83697hf) && (i == 1)) ||