diff options
Diffstat (limited to 'drivers/i2c/chips/it87.c')
-rw-r--r-- | drivers/i2c/chips/it87.c | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/drivers/i2c/chips/it87.c b/drivers/i2c/chips/it87.c index bf02ba555a851..3d484a7aff127 100644 --- a/drivers/i2c/chips/it87.c +++ b/drivers/i2c/chips/it87.c @@ -265,9 +265,12 @@ static ssize_t set_in_min(struct device *dev, const char *buf, struct i2c_client *client = to_i2c_client(dev); struct it87_data *data = i2c_get_clientdata(client); unsigned long val = simple_strtoul(buf, NULL, 10); + + down(&data->update_lock); data->in_min[nr] = IN_TO_REG(val); it87_write_value(client, IT87_REG_VIN_MIN(nr), data->in_min[nr]); + up(&data->update_lock); return count; } static ssize_t set_in_max(struct device *dev, const char *buf, @@ -276,9 +279,12 @@ static ssize_t set_in_max(struct device *dev, const char *buf, struct i2c_client *client = to_i2c_client(dev); struct it87_data *data = i2c_get_clientdata(client); unsigned long val = simple_strtoul(buf, NULL, 10); + + down(&data->update_lock); data->in_max[nr] = IN_TO_REG(val); it87_write_value(client, IT87_REG_VIN_MAX(nr), data->in_max[nr]); + up(&data->update_lock); return count; } @@ -356,8 +362,11 @@ static ssize_t set_temp_max(struct device *dev, const char *buf, struct i2c_client *client = to_i2c_client(dev); struct it87_data *data = i2c_get_clientdata(client); int val = simple_strtol(buf, NULL, 10); + + down(&data->update_lock); data->temp_high[nr] = TEMP_TO_REG(val); it87_write_value(client, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]); + up(&data->update_lock); return count; } static ssize_t set_temp_min(struct device *dev, const char *buf, @@ -366,8 +375,11 @@ static ssize_t set_temp_min(struct device *dev, const char *buf, struct i2c_client *client = to_i2c_client(dev); struct it87_data *data = i2c_get_clientdata(client); int val = simple_strtol(buf, NULL, 10); + + down(&data->update_lock); data->temp_low[nr] = TEMP_TO_REG(val); it87_write_value(client, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]); + up(&data->update_lock); return count; } #define show_temp_offset(offset) \ @@ -408,9 +420,11 @@ show_temp_offset(3); static ssize_t show_sensor(struct device *dev, char *buf, int nr) { struct it87_data *data = it87_update_device(dev); - if (data->sensor & (1 << nr)) + u8 reg = data->sensor; /* In case the value is updated while we use it */ + + if (reg & (1 << nr)) return sprintf(buf, "3\n"); /* thermal diode */ - if (data->sensor & (8 << nr)) + if (reg & (8 << nr)) return sprintf(buf, "2\n"); /* thermistor */ return sprintf(buf, "0\n"); /* disabled */ } @@ -421,6 +435,8 @@ static ssize_t set_sensor(struct device *dev, const char *buf, struct it87_data *data = i2c_get_clientdata(client); int val = simple_strtol(buf, NULL, 10); + down(&data->update_lock); + data->sensor &= ~(1 << nr); data->sensor &= ~(8 << nr); /* 3 = thermal diode; 2 = thermistor; 0 = disabled */ @@ -428,9 +444,12 @@ static ssize_t set_sensor(struct device *dev, const char *buf, data->sensor |= 1 << nr; else if (val == 2) data->sensor |= 8 << nr; - else if (val != 0) + else if (val != 0) { + up(&data->update_lock); return -EINVAL; + } it87_write_value(client, IT87_REG_TEMP_ENABLE, data->sensor); + up(&data->update_lock); return count; } #define show_sensor_offset(offset) \ @@ -484,8 +503,11 @@ static ssize_t set_fan_min(struct device *dev, const char *buf, struct i2c_client *client = to_i2c_client(dev); struct it87_data *data = i2c_get_clientdata(client); int val = simple_strtol(buf, NULL, 10); + + down(&data->update_lock); data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); it87_write_value(client, IT87_REG_FAN_MIN(nr), data->fan_min[nr]); + up(&data->update_lock); return count; } static ssize_t set_fan_div(struct device *dev, const char *buf, @@ -495,7 +517,10 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, struct it87_data *data = i2c_get_clientdata(client); int val = simple_strtol(buf, NULL, 10); int i, min[3]; - u8 old = it87_read_value(client, IT87_REG_FAN_DIV); + u8 old; + + down(&data->update_lock); + old = it87_read_value(client, IT87_REG_FAN_DIV); for (i = 0; i < 3; i++) min[i] = FAN_FROM_REG(data->fan_min[i], DIV_FROM_REG(data->fan_div[i])); @@ -522,6 +547,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, data->fan_min[i]=FAN_TO_REG(min[i], DIV_FROM_REG(data->fan_div[i])); it87_write_value(client, IT87_REG_FAN_MIN(i), data->fan_min[i]); } + up(&data->update_lock); return count; } static ssize_t set_pwm_enable(struct device *dev, const char *buf, @@ -531,6 +557,8 @@ static ssize_t set_pwm_enable(struct device *dev, const char *buf, struct it87_data *data = i2c_get_clientdata(client); int val = simple_strtol(buf, NULL, 10); + down(&data->update_lock); + if (val == 0) { int tmp; /* make sure the fan is on when in on/off mode */ @@ -545,9 +573,12 @@ static ssize_t set_pwm_enable(struct device *dev, const char *buf, it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); /* set saved pwm value, clear FAN_CTLX PWM mode bit */ it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); - } else + } else { + up(&data->update_lock); return -EINVAL; + } + up(&data->update_lock); return count; } static ssize_t set_pwm(struct device *dev, const char *buf, @@ -560,10 +591,11 @@ static ssize_t set_pwm(struct device *dev, const char *buf, if (val < 0 || val > 255) return -EINVAL; + down(&data->update_lock); data->manual_pwm_ctl[nr] = val; if (data->fan_main_ctrl & (1 << nr)) it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); - + up(&data->update_lock); return count; } |