X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fi2c%2Fchips%2Fasb100.c;h=7f899002bc5493ca2cbbf1225dca003c6c63e6b3;hb=f7f1b0f1e2fbadeab12d24236000e778aa9b1ead;hp=e170b2a786b91513ef8384e2332067d0f88f8d66;hpb=c7b5ebbddf7bcd3651947760f423e3783bbe6573;p=linux-2.6.git diff --git a/drivers/i2c/chips/asb100.c b/drivers/i2c/chips/asb100.c index e170b2a78..7f899002b 100644 --- a/drivers/i2c/chips/asb100.c +++ b/drivers/i2c/chips/asb100.c @@ -36,17 +36,12 @@ asb100 7 3 1 4 0x31 0x0694 yes no */ -#include #include #include -#include -#include #include #include #include #include -#include -#include #include "lm75.h" /* @@ -56,12 +51,10 @@ #define ASB100_VERSION "1.0.0" /* I2C addresses to scan */ -static unsigned short normal_i2c[] = { I2C_CLIENT_END }; -static unsigned short normal_i2c_range[] = { 0x28, 0x2f, I2C_CLIENT_END }; +static unsigned short normal_i2c[] = { 0x2d, I2C_CLIENT_END }; /* ISA addresses to scan (none) */ static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; -static unsigned int normal_isa_range[] = { I2C_CLIENT_ISA_END }; /* Insmod parameters */ SENSORS_INSMOD_1(asb100); @@ -253,9 +246,12 @@ static ssize_t set_in_##reg(struct device *dev, const char *buf, \ struct i2c_client *client = to_i2c_client(dev); \ struct asb100_data *data = i2c_get_clientdata(client); \ unsigned long val = simple_strtoul(buf, NULL, 10); \ + \ + down(&data->update_lock); \ data->in_##reg[nr] = IN_TO_REG(val); \ asb100_write_value(client, ASB100_REG_IN_##REG(nr), \ data->in_##reg[nr]); \ + up(&data->update_lock); \ return count; \ } @@ -266,29 +262,29 @@ set_in_reg(MAX, max) static ssize_t \ show_in##offset (struct device *dev, char *buf) \ { \ - return show_in(dev, buf, 0x##offset); \ + return show_in(dev, buf, offset); \ } \ static DEVICE_ATTR(in##offset##_input, S_IRUGO, \ show_in##offset, NULL); \ static ssize_t \ show_in##offset##_min (struct device *dev, char *buf) \ { \ - return show_in_min(dev, buf, 0x##offset); \ + return show_in_min(dev, buf, offset); \ } \ static ssize_t \ show_in##offset##_max (struct device *dev, char *buf) \ { \ - return show_in_max(dev, buf, 0x##offset); \ + return show_in_max(dev, buf, offset); \ } \ static ssize_t set_in##offset##_min (struct device *dev, \ const char *buf, size_t count) \ { \ - return set_in_min(dev, buf, count, 0x##offset); \ + return set_in_min(dev, buf, count, offset); \ } \ static ssize_t set_in##offset##_max (struct device *dev, \ const char *buf, size_t count) \ { \ - return set_in_max(dev, buf, count, 0x##offset); \ + return set_in_max(dev, buf, count, offset); \ } \ static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ show_in##offset##_min, set_in##offset##_min); \ @@ -336,8 +332,11 @@ static ssize_t set_fan_min(struct device *dev, const char *buf, struct i2c_client *client = to_i2c_client(dev); struct asb100_data *data = i2c_get_clientdata(client); u32 val = simple_strtoul(buf, NULL, 10); + + down(&data->update_lock); data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); asb100_write_value(client, ASB100_REG_FAN_MIN(nr), data->fan_min[nr]); + up(&data->update_lock); return count; } @@ -350,11 +349,14 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, { struct i2c_client *client = to_i2c_client(dev); struct asb100_data *data = i2c_get_clientdata(client); - unsigned long min = FAN_FROM_REG(data->fan_min[nr], - DIV_FROM_REG(data->fan_div[nr])); + unsigned long min; unsigned long val = simple_strtoul(buf, NULL, 10); int reg; + down(&data->update_lock); + + min = FAN_FROM_REG(data->fan_min[nr], + DIV_FROM_REG(data->fan_div[nr])); data->fan_div[nr] = DIV_TO_REG(val); switch(nr) { @@ -380,6 +382,9 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); asb100_write_value(client, ASB100_REG_FAN_MIN(nr), data->fan_min[nr]); + + up(&data->update_lock); + return count; } @@ -457,6 +462,8 @@ static ssize_t set_##reg(struct device *dev, const char *buf, \ struct i2c_client *client = to_i2c_client(dev); \ struct asb100_data *data = i2c_get_clientdata(client); \ unsigned long val = simple_strtoul(buf, NULL, 10); \ + \ + down(&data->update_lock); \ switch (nr) { \ case 1: case 2: \ data->reg[nr] = LM75_TEMP_TO_REG(val); \ @@ -467,6 +474,7 @@ static ssize_t set_##reg(struct device *dev, const char *buf, \ } \ asb100_write_value(client, ASB100_REG_TEMP_##REG(nr+1), \ data->reg[nr]); \ + up(&data->update_lock); \ return count; \ } @@ -567,9 +575,12 @@ static ssize_t set_pwm1(struct device *dev, const char *buf, size_t count) struct i2c_client *client = to_i2c_client(dev); struct asb100_data *data = i2c_get_clientdata(client); unsigned long val = simple_strtoul(buf, NULL, 10); + + down(&data->update_lock); data->pwm &= 0x80; /* keep the enable bit */ data->pwm |= (0x0f & ASB100_PWM_TO_REG(val)); asb100_write_value(client, ASB100_REG_PWM1, data->pwm); + up(&data->update_lock); return count; } @@ -585,18 +596,21 @@ static ssize_t set_pwm_enable1(struct device *dev, const char *buf, struct i2c_client *client = to_i2c_client(dev); struct asb100_data *data = i2c_get_clientdata(client); unsigned long val = simple_strtoul(buf, NULL, 10); + + down(&data->update_lock); data->pwm &= 0x0f; /* keep the duty cycle bits */ data->pwm |= (val ? 0x80 : 0x00); asb100_write_value(client, ASB100_REG_PWM1, data->pwm); + up(&data->update_lock); return count; } -static DEVICE_ATTR(fan1_pwm, S_IRUGO | S_IWUSR, show_pwm1, set_pwm1); -static DEVICE_ATTR(fan1_pwm_enable, S_IRUGO | S_IWUSR, +static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm1, set_pwm1); +static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable1, set_pwm_enable1); #define device_create_file_pwm1(client) do { \ - device_create_file(&new_client->dev, &dev_attr_fan1_pwm); \ - device_create_file(&new_client->dev, &dev_attr_fan1_pwm_enable); \ + device_create_file(&new_client->dev, &dev_attr_pwm1); \ + device_create_file(&new_client->dev, &dev_attr_pwm1_enable); \ } while (0) /* This function is called when: @@ -972,8 +986,8 @@ static struct asb100_data *asb100_update_device(struct device *dev) down(&data->update_lock); - if (time_after(jiffies - data->last_updated, (unsigned long)(HZ+HZ/2)) - || time_before(jiffies, data->last_updated) || !data->valid) { + if (time_after(jiffies, data->last_updated + HZ + HZ / 2) + || !data->valid) { dev_dbg(&client->dev, "starting device update...\n");