Commit 9a61bf63 authored by Ingo Molnar's avatar Ingo Molnar Committed by Greg Kroah-Hartman

[PATCH] hwmon: Semaphore to mutex conversions

convert drivers/hwmon/*.c semaphore use to mutexes.

the conversion was generated via scripts, and the result was validated
automatically via a script as well.

all affected hwmon drivers were build-tested.
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 3fb9a655
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
/* Addresses to scan */ /* Addresses to scan */
...@@ -92,7 +93,7 @@ struct adm1021_data { ...@@ -92,7 +93,7 @@ struct adm1021_data {
struct class_device *class_dev; struct class_device *class_dev;
enum chips type; enum chips type;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* !=0 if following fields are valid */ char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
...@@ -162,10 +163,10 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co ...@@ -162,10 +163,10 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co
struct adm1021_data *data = i2c_get_clientdata(client); \ struct adm1021_data *data = i2c_get_clientdata(client); \
int temp = simple_strtoul(buf, NULL, 10); \ int temp = simple_strtoul(buf, NULL, 10); \
\ \
down(&data->update_lock); \ mutex_lock(&data->update_lock); \
data->value = TEMP_TO_REG(temp); \ data->value = TEMP_TO_REG(temp); \
adm1021_write_value(client, reg, data->value); \ adm1021_write_value(client, reg, data->value); \
up(&data->update_lock); \ mutex_unlock(&data->update_lock); \
return count; \ return count; \
} }
set(temp_max, ADM1021_REG_TOS_W); set(temp_max, ADM1021_REG_TOS_W);
...@@ -275,7 +276,7 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -275,7 +276,7 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)
strlcpy(new_client->name, type_name, I2C_NAME_SIZE); strlcpy(new_client->name, type_name, I2C_NAME_SIZE);
data->type = kind; data->type = kind;
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
...@@ -351,7 +352,7 @@ static struct adm1021_data *adm1021_update_device(struct device *dev) ...@@ -351,7 +352,7 @@ static struct adm1021_data *adm1021_update_device(struct device *dev)
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct adm1021_data *data = i2c_get_clientdata(client); struct adm1021_data *data = i2c_get_clientdata(client);
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ + HZ / 2) if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|| !data->valid) { || !data->valid) {
...@@ -375,7 +376,7 @@ static struct adm1021_data *adm1021_update_device(struct device *dev) ...@@ -375,7 +376,7 @@ static struct adm1021_data *adm1021_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/hwmon-vid.h> #include <linux/hwmon-vid.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
/* /*
* Addresses to scan * Addresses to scan
...@@ -133,7 +134,7 @@ static struct i2c_driver adm1025_driver = { ...@@ -133,7 +134,7 @@ static struct i2c_driver adm1025_driver = {
struct adm1025_data { struct adm1025_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* zero until following fields are valid */ char valid; /* zero until following fields are valid */
unsigned long last_updated; /* in jiffies */ unsigned long last_updated; /* in jiffies */
...@@ -207,11 +208,11 @@ static ssize_t set_in##offset##_min(struct device *dev, struct device_attribute ...@@ -207,11 +208,11 @@ static ssize_t set_in##offset##_min(struct device *dev, struct device_attribute
struct adm1025_data *data = i2c_get_clientdata(client); \ struct adm1025_data *data = i2c_get_clientdata(client); \
long val = simple_strtol(buf, NULL, 10); \ long val = simple_strtol(buf, NULL, 10); \
\ \
down(&data->update_lock); \ mutex_lock(&data->update_lock); \
data->in_min[offset] = IN_TO_REG(val, in_scale[offset]); \ data->in_min[offset] = IN_TO_REG(val, in_scale[offset]); \
i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MIN(offset), \ i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MIN(offset), \
data->in_min[offset]); \ data->in_min[offset]); \
up(&data->update_lock); \ mutex_unlock(&data->update_lock); \
return count; \ return count; \
} \ } \
static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \ static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
...@@ -221,11 +222,11 @@ static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute ...@@ -221,11 +222,11 @@ static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute
struct adm1025_data *data = i2c_get_clientdata(client); \ struct adm1025_data *data = i2c_get_clientdata(client); \
long val = simple_strtol(buf, NULL, 10); \ long val = simple_strtol(buf, NULL, 10); \
\ \
down(&data->update_lock); \ mutex_lock(&data->update_lock); \
data->in_max[offset] = IN_TO_REG(val, in_scale[offset]); \ data->in_max[offset] = IN_TO_REG(val, in_scale[offset]); \
i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MAX(offset), \ i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MAX(offset), \
data->in_max[offset]); \ data->in_max[offset]); \
up(&data->update_lock); \ mutex_unlock(&data->update_lock); \
return count; \ return count; \
} \ } \
static DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \ static DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
...@@ -247,11 +248,11 @@ static ssize_t set_temp##offset##_min(struct device *dev, struct device_attribut ...@@ -247,11 +248,11 @@ static ssize_t set_temp##offset##_min(struct device *dev, struct device_attribut
struct adm1025_data *data = i2c_get_clientdata(client); \ struct adm1025_data *data = i2c_get_clientdata(client); \
long val = simple_strtol(buf, NULL, 10); \ long val = simple_strtol(buf, NULL, 10); \
\ \
down(&data->update_lock); \ mutex_lock(&data->update_lock); \
data->temp_min[offset-1] = TEMP_TO_REG(val); \ data->temp_min[offset-1] = TEMP_TO_REG(val); \
i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_LOW(offset-1), \ i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_LOW(offset-1), \
data->temp_min[offset-1]); \ data->temp_min[offset-1]); \
up(&data->update_lock); \ mutex_unlock(&data->update_lock); \
return count; \ return count; \
} \ } \
static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \ static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
...@@ -261,11 +262,11 @@ static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribut ...@@ -261,11 +262,11 @@ static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribut
struct adm1025_data *data = i2c_get_clientdata(client); \ struct adm1025_data *data = i2c_get_clientdata(client); \
long val = simple_strtol(buf, NULL, 10); \ long val = simple_strtol(buf, NULL, 10); \
\ \
down(&data->update_lock); \ mutex_lock(&data->update_lock); \
data->temp_max[offset-1] = TEMP_TO_REG(val); \ data->temp_max[offset-1] = TEMP_TO_REG(val); \
i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_HIGH(offset-1), \ i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_HIGH(offset-1), \
data->temp_max[offset-1]); \ data->temp_max[offset-1]); \
up(&data->update_lock); \ mutex_unlock(&data->update_lock); \
return count; \ return count; \
} \ } \
static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \ static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
...@@ -404,7 +405,7 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -404,7 +405,7 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
/* We can fill in the remaining client fields */ /* We can fill in the remaining client fields */
strlcpy(new_client->name, name, I2C_NAME_SIZE); strlcpy(new_client->name, name, I2C_NAME_SIZE);
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
...@@ -523,7 +524,7 @@ static struct adm1025_data *adm1025_update_device(struct device *dev) ...@@ -523,7 +524,7 @@ static struct adm1025_data *adm1025_update_device(struct device *dev)
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct adm1025_data *data = i2c_get_clientdata(client); struct adm1025_data *data = i2c_get_clientdata(client);
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
int i; int i;
...@@ -558,7 +559,7 @@ static struct adm1025_data *adm1025_update_device(struct device *dev) ...@@ -558,7 +559,7 @@ static struct adm1025_data *adm1025_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
This diff is collapsed.
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
/* Following macros takes channel parameter starting from 0 to 2 */ /* Following macros takes channel parameter starting from 0 to 2 */
#define ADM1031_REG_FAN_SPEED(nr) (0x08 + (nr)) #define ADM1031_REG_FAN_SPEED(nr) (0x08 + (nr))
...@@ -70,7 +71,7 @@ typedef u8 auto_chan_table_t[8][2]; ...@@ -70,7 +71,7 @@ typedef u8 auto_chan_table_t[8][2];
struct adm1031_data { struct adm1031_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore update_lock; struct mutex update_lock;
int chip_type; int chip_type;
char valid; /* !=0 if following fields are valid */ char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
...@@ -262,10 +263,10 @@ set_fan_auto_channel(struct device *dev, const char *buf, size_t count, int nr) ...@@ -262,10 +263,10 @@ set_fan_auto_channel(struct device *dev, const char *buf, size_t count, int nr)
old_fan_mode = data->conf1; old_fan_mode = data->conf1;
down(&data->update_lock); mutex_lock(&data->update_lock);
if ((ret = get_fan_auto_nearest(data, nr, val, data->conf1, &reg))) { if ((ret = get_fan_auto_nearest(data, nr, val, data->conf1, &reg))) {
up(&data->update_lock); mutex_unlock(&data->update_lock);
return ret; return ret;
} }
if (((data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1)) & ADM1031_CONF1_AUTO_MODE) ^ if (((data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1)) & ADM1031_CONF1_AUTO_MODE) ^
...@@ -288,7 +289,7 @@ set_fan_auto_channel(struct device *dev, const char *buf, size_t count, int nr) ...@@ -288,7 +289,7 @@ set_fan_auto_channel(struct device *dev, const char *buf, size_t count, int nr)
} }
data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1); data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1);
adm1031_write_value(client, ADM1031_REG_CONF1, data->conf1); adm1031_write_value(client, ADM1031_REG_CONF1, data->conf1);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -329,11 +330,11 @@ set_auto_temp_min(struct device *dev, const char *buf, size_t count, int nr) ...@@ -329,11 +330,11 @@ set_auto_temp_min(struct device *dev, const char *buf, size_t count, int nr)
struct adm1031_data *data = i2c_get_clientdata(client); struct adm1031_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); int val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->auto_temp[nr] = AUTO_TEMP_MIN_TO_REG(val, data->auto_temp[nr]); data->auto_temp[nr] = AUTO_TEMP_MIN_TO_REG(val, data->auto_temp[nr]);
adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr), adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr),
data->auto_temp[nr]); data->auto_temp[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t show_auto_temp_max(struct device *dev, char *buf, int nr) static ssize_t show_auto_temp_max(struct device *dev, char *buf, int nr)
...@@ -349,11 +350,11 @@ set_auto_temp_max(struct device *dev, const char *buf, size_t count, int nr) ...@@ -349,11 +350,11 @@ set_auto_temp_max(struct device *dev, const char *buf, size_t count, int nr)
struct adm1031_data *data = i2c_get_clientdata(client); struct adm1031_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); int val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_max[nr] = AUTO_TEMP_MAX_TO_REG(val, data->auto_temp[nr], data->pwm[nr]); data->temp_max[nr] = AUTO_TEMP_MAX_TO_REG(val, data->auto_temp[nr], data->pwm[nr]);
adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr), adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr),
data->temp_max[nr]); data->temp_max[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -405,11 +406,11 @@ set_pwm(struct device *dev, const char *buf, size_t count, int nr) ...@@ -405,11 +406,11 @@ set_pwm(struct device *dev, const char *buf, size_t count, int nr)
int val = simple_strtol(buf, NULL, 10); int val = simple_strtol(buf, NULL, 10);
int reg; int reg;
down(&data->update_lock); mutex_lock(&data->update_lock);
if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) && if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) &&
(((val>>4) & 0xf) != 5)) { (((val>>4) & 0xf) != 5)) {
/* In automatic mode, the only PWM accepted is 33% */ /* In automatic mode, the only PWM accepted is 33% */
up(&data->update_lock); mutex_unlock(&data->update_lock);
return -EINVAL; return -EINVAL;
} }
data->pwm[nr] = PWM_TO_REG(val); data->pwm[nr] = PWM_TO_REG(val);
...@@ -417,7 +418,7 @@ set_pwm(struct device *dev, const char *buf, size_t count, int nr) ...@@ -417,7 +418,7 @@ set_pwm(struct device *dev, const char *buf, size_t count, int nr)
adm1031_write_value(client, ADM1031_REG_PWM, adm1031_write_value(client, ADM1031_REG_PWM,
nr ? ((data->pwm[nr] << 4) & 0xf0) | (reg & 0xf) nr ? ((data->pwm[nr] << 4) & 0xf0) | (reg & 0xf)
: (data->pwm[nr] & 0xf) | (reg & 0xf0)); : (data->pwm[nr] & 0xf) | (reg & 0xf0));
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -511,7 +512,7 @@ set_fan_min(struct device *dev, const char *buf, size_t count, int nr) ...@@ -511,7 +512,7 @@ set_fan_min(struct device *dev, const char *buf, size_t count, int nr)
struct adm1031_data *data = i2c_get_clientdata(client); struct adm1031_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); int val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
if (val) { if (val) {
data->fan_min[nr] = data->fan_min[nr] =
FAN_TO_REG(val, FAN_DIV_FROM_REG(data->fan_div[nr])); FAN_TO_REG(val, FAN_DIV_FROM_REG(data->fan_div[nr]));
...@@ -519,7 +520,7 @@ set_fan_min(struct device *dev, const char *buf, size_t count, int nr) ...@@ -519,7 +520,7 @@ set_fan_min(struct device *dev, const char *buf, size_t count, int nr)
data->fan_min[nr] = 0xff; data->fan_min[nr] = 0xff;
} }
adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr), data->fan_min[nr]); adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr), data->fan_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t static ssize_t
...@@ -540,7 +541,7 @@ set_fan_div(struct device *dev, const char *buf, size_t count, int nr) ...@@ -540,7 +541,7 @@ set_fan_div(struct device *dev, const char *buf, size_t count, int nr)
if (tmp == 0xff) if (tmp == 0xff)
return -EINVAL; return -EINVAL;
down(&data->update_lock); mutex_lock(&data->update_lock);
old_div = FAN_DIV_FROM_REG(data->fan_div[nr]); old_div = FAN_DIV_FROM_REG(data->fan_div[nr]);
data->fan_div[nr] = (tmp & 0xC0) | (0x3f & data->fan_div[nr]); data->fan_div[nr] = (tmp & 0xC0) | (0x3f & data->fan_div[nr]);
new_min = data->fan_min[nr] * old_div / new_min = data->fan_min[nr] * old_div /
...@@ -553,7 +554,7 @@ set_fan_div(struct device *dev, const char *buf, size_t count, int nr) ...@@ -553,7 +554,7 @@ set_fan_div(struct device *dev, const char *buf, size_t count, int nr)
data->fan_div[nr]); data->fan_div[nr]);
adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr), adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr),
data->fan_min[nr]); data->fan_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -627,11 +628,11 @@ set_temp_min(struct device *dev, const char *buf, size_t count, int nr) ...@@ -627,11 +628,11 @@ set_temp_min(struct device *dev, const char *buf, size_t count, int nr)
val = simple_strtol(buf, NULL, 10); val = simple_strtol(buf, NULL, 10);
val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875); val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_min[nr] = TEMP_TO_REG(val); data->temp_min[nr] = TEMP_TO_REG(val);
adm1031_write_value(client, ADM1031_REG_TEMP_MIN(nr), adm1031_write_value(client, ADM1031_REG_TEMP_MIN(nr),
data->temp_min[nr]); data->temp_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t static ssize_t
...@@ -643,11 +644,11 @@ set_temp_max(struct device *dev, const char *buf, size_t count, int nr) ...@@ -643,11 +644,11 @@ set_temp_max(struct device *dev, const char *buf, size_t count, int nr)
val = simple_strtol(buf, NULL, 10); val = simple_strtol(buf, NULL, 10);
val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875); val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_max[nr] = TEMP_TO_REG(val); data->temp_max[nr] = TEMP_TO_REG(val);
adm1031_write_value(client, ADM1031_REG_TEMP_MAX(nr), adm1031_write_value(client, ADM1031_REG_TEMP_MAX(nr),
data->temp_max[nr]); data->temp_max[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t static ssize_t
...@@ -659,11 +660,11 @@ set_temp_crit(struct device *dev, const char *buf, size_t count, int nr) ...@@ -659,11 +660,11 @@ set_temp_crit(struct device *dev, const char *buf, size_t count, int nr)
val = simple_strtol(buf, NULL, 10); val = simple_strtol(buf, NULL, 10);
val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875); val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_crit[nr] = TEMP_TO_REG(val); data->temp_crit[nr] = TEMP_TO_REG(val);
adm1031_write_value(client, ADM1031_REG_TEMP_CRIT(nr), adm1031_write_value(client, ADM1031_REG_TEMP_CRIT(nr),
data->temp_crit[nr]); data->temp_crit[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -778,7 +779,7 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -778,7 +779,7 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
strlcpy(new_client->name, name, I2C_NAME_SIZE); strlcpy(new_client->name, name, I2C_NAME_SIZE);
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
...@@ -891,7 +892,7 @@ static struct adm1031_data *adm1031_update_device(struct device *dev) ...@@ -891,7 +892,7 @@ static struct adm1031_data *adm1031_update_device(struct device *dev)
struct adm1031_data *data = i2c_get_clientdata(client); struct adm1031_data *data = i2c_get_clientdata(client);
int chan; int chan;
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ + HZ / 2) if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|| !data->valid) { || !data->valid) {
...@@ -965,7 +966,7 @@ static struct adm1031_data *adm1031_update_device(struct device *dev) ...@@ -965,7 +966,7 @@ static struct adm1031_data *adm1031_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/hwmon-vid.h> #include <linux/hwmon-vid.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
/* Addresses to scan */ /* Addresses to scan */
static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
...@@ -150,7 +151,7 @@ struct adm9240_data { ...@@ -150,7 +151,7 @@ struct adm9240_data {
enum chips type; enum chips type;
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore update_lock; struct mutex update_lock;
char valid; char valid;
unsigned long last_updated_measure; unsigned long last_updated_measure;
unsigned long last_updated_config; unsigned long last_updated_config;
...@@ -195,11 +196,11 @@ static ssize_t set_max(struct device *dev, struct device_attribute *devattr, ...@@ -195,11 +196,11 @@ static ssize_t set_max(struct device *dev, struct device_attribute *devattr,
struct adm9240_data *data = i2c_get_clientdata(client); struct adm9240_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_max[attr->index] = TEMP_TO_REG(val); data->temp_max[attr->index] = TEMP_TO_REG(val);
i2c_smbus_write_byte_data(client, ADM9240_REG_TEMP_MAX(attr->index), i2c_smbus_write_byte_data(client, ADM9240_REG_TEMP_MAX(attr->index),
data->temp_max[attr->index]); data->temp_max[attr->index]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -246,11 +247,11 @@ static ssize_t set_in_min(struct device *dev, ...@@ -246,11 +247,11 @@ static ssize_t set_in_min(struct device *dev,
struct adm9240_data *data = i2c_get_clientdata(client); struct adm9240_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_min[attr->index] = IN_TO_REG(val, attr->index); data->in_min[attr->index] = IN_TO_REG(val, attr->index);
i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MIN(attr->index), i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MIN(attr->index),
data->in_min[attr->index]); data->in_min[attr->index]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -263,11 +264,11 @@ static ssize_t set_in_max(struct device *dev, ...@@ -263,11 +264,11 @@ static ssize_t set_in_max(struct device *dev,
struct adm9240_data *data = i2c_get_clientdata(client); struct adm9240_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_max[attr->index] = IN_TO_REG(val, attr->index); data->in_max[attr->index] = IN_TO_REG(val, attr->index);
i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MAX(attr->index), i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MAX(attr->index),
data->in_max[attr->index]); data->in_max[attr->index]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -350,7 +351,7 @@ static ssize_t set_fan_min(struct device *dev, ...@@ -350,7 +351,7 @@ static ssize_t set_fan_min(struct device *dev,
int nr = attr->index; int nr = attr->index;
u8 new_div; u8 new_div;
down(&data->update_lock); mutex_lock(&data->update_lock);
if (!val) { if (!val) {
data->fan_min[nr] = 255; data->fan_min[nr] = 255;
...@@ -390,7 +391,7 @@ static ssize_t set_fan_min(struct device *dev, ...@@ -390,7 +391,7 @@ static ssize_t set_fan_min(struct device *dev,
i2c_smbus_write_byte_data(client, ADM9240_REG_FAN_MIN(nr), i2c_smbus_write_byte_data(client, ADM9240_REG_FAN_MIN(nr),
data->fan_min[nr]); data->fan_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -439,10 +440,10 @@ static ssize_t set_aout(struct device *dev, ...@@ -439,10 +440,10 @@ static ssize_t set_aout(struct device *dev,
struct adm9240_data *data = i2c_get_clientdata(client); struct adm9240_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtol(buf, NULL, 10); unsigned long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->aout = AOUT_TO_REG(val); data->aout = AOUT_TO_REG(val);
i2c_smbus_write_byte_data(client, ADM9240_REG_ANALOG_OUT, data->aout); i2c_smbus_write_byte_data(client, ADM9240_REG_ANALOG_OUT, data->aout);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout); static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout);
...@@ -539,7 +540,7 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -539,7 +540,7 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind)
/* fill in the remaining client fields and attach */ /* fill in the remaining client fields and attach */
strlcpy(new_client->name, name, I2C_NAME_SIZE); strlcpy(new_client->name, name, I2C_NAME_SIZE);
data->type = kind; data->type = kind;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
goto exit_free; goto exit_free;
...@@ -691,7 +692,7 @@ static struct adm9240_data *adm9240_update_device(struct device *dev) ...@@ -691,7 +692,7 @@ static struct adm9240_data *adm9240_update_device(struct device *dev)
struct adm9240_data *data = i2c_get_clientdata(client); struct adm9240_data *data = i2c_get_clientdata(client);
int i; int i;
down(&data->update_lock); mutex_lock(&data->update_lock);
/* minimum measurement cycle: 1.75 seconds */ /* minimum measurement cycle: 1.75 seconds */
if (time_after(jiffies, data->last_updated_measure + (HZ * 7 / 4)) if (time_after(jiffies, data->last_updated_measure + (HZ * 7 / 4))
...@@ -771,7 +772,7 @@ static struct adm9240_data *adm9240_update_device(struct device *dev) ...@@ -771,7 +772,7 @@ static struct adm9240_data *adm9240_update_device(struct device *dev)
data->last_updated_config = jiffies; data->last_updated_config = jiffies;
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include <linux/err.h> #include <linux/err.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/jiffies.h> #include <linux/jiffies.h>
#include <linux/mutex.h>
#include "lm75.h" #include "lm75.h"
/* /*
...@@ -182,10 +183,10 @@ static u8 DIV_TO_REG(long val) ...@@ -182,10 +183,10 @@ static u8 DIV_TO_REG(long val)
struct asb100_data { struct asb100_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore lock; struct mutex lock;
enum chips type; enum chips type;
struct semaphore update_lock; struct mutex update_lock;
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
/* array of 2 pointers to subclients */ /* array of 2 pointers to subclients */
...@@ -245,11 +246,11 @@ static ssize_t set_in_##reg(struct device *dev, const char *buf, \ ...@@ -245,11 +246,11 @@ static ssize_t set_in_##reg(struct device *dev, const char *buf, \
struct asb100_data *data = i2c_get_clientdata(client); \ struct asb100_data *data = i2c_get_clientdata(client); \
unsigned long val = simple_strtoul(buf, NULL, 10); \ unsigned long val = simple_strtoul(buf, NULL, 10); \
\ \
down(&data->update_lock); \ mutex_lock(&data->update_lock); \
data->in_##reg[nr] = IN_TO_REG(val); \ data->in_##reg[nr] = IN_TO_REG(val); \
asb100_write_value(client, ASB100_REG_IN_##REG(nr), \ asb100_write_value(client, ASB100_REG_IN_##REG(nr), \
data->in_##reg[nr]); \ data->in_##reg[nr]); \
up(&data->update_lock); \ mutex_unlock(&data->update_lock); \
return count; \ return count; \
} }
...@@ -331,10 +332,10 @@ static ssize_t set_fan_min(struct device *dev, const char *buf, ...@@ -331,10 +332,10 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
struct asb100_data *data = i2c_get_clientdata(client); struct asb100_data *data = i2c_get_clientdata(client);
u32 val = simple_strtoul(buf, NULL, 10); u32 val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 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]); asb100_write_value(client, ASB100_REG_FAN_MIN(nr), data->fan_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -351,7 +352,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, ...@@ -351,7 +352,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
int reg; int reg;
down(&data->update_lock); mutex_lock(&data->update_lock);
min = FAN_FROM_REG(data->fan_min[nr], min = FAN_FROM_REG(data->fan_min[nr],
DIV_FROM_REG(data->fan_div[nr])); DIV_FROM_REG(data->fan_div[nr]));
...@@ -381,7 +382,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, ...@@ -381,7 +382,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[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]); asb100_write_value(client, ASB100_REG_FAN_MIN(nr), data->fan_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -461,7 +462,7 @@ static ssize_t set_##reg(struct device *dev, const char *buf, \ ...@@ -461,7 +462,7 @@ static ssize_t set_##reg(struct device *dev, const char *buf, \
struct asb100_data *data = i2c_get_clientdata(client); \ struct asb100_data *data = i2c_get_clientdata(client); \
unsigned long val = simple_strtoul(buf, NULL, 10); \ unsigned long val = simple_strtoul(buf, NULL, 10); \
\ \
down(&data->update_lock); \ mutex_lock(&data->update_lock); \
switch (nr) { \ switch (nr) { \
case 1: case 2: \ case 1: case 2: \
data->reg[nr] = LM75_TEMP_TO_REG(val); \ data->reg[nr] = LM75_TEMP_TO_REG(val); \
...@@ -472,7 +473,7 @@ static ssize_t set_##reg(struct device *dev, const char *buf, \ ...@@ -472,7 +473,7 @@ static ssize_t set_##reg(struct device *dev, const char *buf, \
} \ } \
asb100_write_value(client, ASB100_REG_TEMP_##REG(nr+1), \ asb100_write_value(client, ASB100_REG_TEMP_##REG(nr+1), \
data->reg[nr]); \ data->reg[nr]); \
up(&data->update_lock); \ mutex_unlock(&data->update_lock); \
return count; \ return count; \
} }
...@@ -574,11 +575,11 @@ static ssize_t set_pwm1(struct device *dev, struct device_attribute *attr, const ...@@ -574,11 +575,11 @@ static ssize_t set_pwm1(struct device *dev, struct device_attribute *attr, const
struct asb100_data *data = i2c_get_clientdata(client); struct asb100_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->pwm &= 0x80; /* keep the enable bit */ data->pwm &= 0x80; /* keep the enable bit */
data->pwm |= (0x0f & ASB100_PWM_TO_REG(val)); data->pwm |= (0x0f & ASB100_PWM_TO_REG(val));
asb100_write_value(client, ASB100_REG_PWM1, data->pwm); asb100_write_value(client, ASB100_REG_PWM1, data->pwm);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -595,11 +596,11 @@ static ssize_t set_pwm_enable1(struct device *dev, struct device_attribute *attr ...@@ -595,11 +596,11 @@ static ssize_t set_pwm_enable1(struct device *dev, struct device_attribute *attr
struct asb100_data *data = i2c_get_clientdata(client); struct asb100_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->pwm &= 0x0f; /* keep the duty cycle bits */ data->pwm &= 0x0f; /* keep the duty cycle bits */
data->pwm |= (val ? 0x80 : 0x00); data->pwm |= (val ? 0x80 : 0x00);
asb100_write_value(client, ASB100_REG_PWM1, data->pwm); asb100_write_value(client, ASB100_REG_PWM1, data->pwm);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -729,7 +730,7 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -729,7 +730,7 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
} }
new_client = &data->client; new_client = &data->client;
init_MUTEX(&data->lock); mutex_init(&data->lock);
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
new_client->adapter = adapter; new_client->adapter = adapter;
...@@ -789,7 +790,7 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -789,7 +790,7 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
data->type = kind; data->type = kind;
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
...@@ -885,7 +886,7 @@ static int asb100_read_value(struct i2c_client *client, u16 reg) ...@@ -885,7 +886,7 @@ static int asb100_read_value(struct i2c_client *client, u16 reg)
struct i2c_client *cl; struct i2c_client *cl;
int res, bank; int res, bank;
down(&data->lock); mutex_lock(&data->lock);
bank = (reg >> 8) & 0x0f; bank = (reg >> 8) & 0x0f;
if (bank > 2) if (bank > 2)
...@@ -919,7 +920,7 @@ static int asb100_read_value(struct i2c_client *client, u16 reg) ...@@ -919,7 +920,7 @@ static int asb100_read_value(struct i2c_client *client, u16 reg)
if (bank > 2) if (bank > 2)
i2c_smbus_write_byte_data(client, ASB100_REG_BANK, 0); i2c_smbus_write_byte_data(client, ASB100_REG_BANK, 0);
up(&data->lock); mutex_unlock(&data->lock);
return res; return res;
} }
...@@ -930,7 +931,7 @@ static void asb100_write_value(struct i2c_client *client, u16 reg, u16 value) ...@@ -930,7 +931,7 @@ static void asb100_write_value(struct i2c_client *client, u16 reg, u16 value)
struct i2c_client *cl; struct i2c_client *cl;
int bank; int bank;
down(&data->lock); mutex_lock(&data->lock);
bank = (reg >> 8) & 0x0f; bank = (reg >> 8) & 0x0f;
if (bank > 2) if (bank > 2)
...@@ -960,7 +961,7 @@ static void asb100_write_value(struct i2c_client *client, u16 reg, u16 value) ...@@ -960,7 +961,7 @@ static void asb100_write_value(struct i2c_client *client, u16 reg, u16 value)
if (bank > 2) if (bank > 2)
i2c_smbus_write_byte_data(client, ASB100_REG_BANK, 0); i2c_smbus_write_byte_data(client, ASB100_REG_BANK, 0);
up(&data->lock); mutex_unlock(&data->lock);
} }
static void asb100_init_client(struct i2c_client *client) static void asb100_init_client(struct i2c_client *client)
...@@ -984,7 +985,7 @@ static struct asb100_data *asb100_update_device(struct device *dev) ...@@ -984,7 +985,7 @@ static struct asb100_data *asb100_update_device(struct device *dev)
struct asb100_data *data = i2c_get_clientdata(client); struct asb100_data *data = i2c_get_clientdata(client);
int i; int i;
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ + HZ / 2) if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|| !data->valid) { || !data->valid) {
...@@ -1042,7 +1043,7 @@ static struct asb100_data *asb100_update_device(struct device *dev) ...@@ -1042,7 +1043,7 @@ static struct asb100_data *asb100_update_device(struct device *dev)
dev_dbg(&client->dev, "... device update complete\n"); dev_dbg(&client->dev, "... device update complete\n");
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/hwmon-vid.h> #include <linux/hwmon-vid.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("System voltages control via Attansic ATXP1"); MODULE_DESCRIPTION("System voltages control via Attansic ATXP1");
...@@ -60,7 +61,7 @@ static struct i2c_driver atxp1_driver = { ...@@ -60,7 +61,7 @@ static struct i2c_driver atxp1_driver = {
struct atxp1_data { struct atxp1_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore update_lock; struct mutex update_lock;
unsigned long last_updated; unsigned long last_updated;
u8 valid; u8 valid;
struct { struct {
...@@ -80,7 +81,7 @@ static struct atxp1_data * atxp1_update_device(struct device *dev) ...@@ -80,7 +81,7 @@ static struct atxp1_data * atxp1_update_device(struct device *dev)
client = to_i2c_client(dev); client = to_i2c_client(dev);
data = i2c_get_clientdata(client); data = i2c_get_clientdata(client);
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
...@@ -93,7 +94,7 @@ static struct atxp1_data * atxp1_update_device(struct device *dev) ...@@ -93,7 +94,7 @@ static struct atxp1_data * atxp1_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return(data); return(data);
} }
...@@ -309,7 +310,7 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -309,7 +310,7 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind)
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
err = i2c_attach_client(new_client); err = i2c_attach_client(new_client);
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
#include "lm75.h" #include "lm75.h"
/* Addresses to scan */ /* Addresses to scan */
...@@ -72,7 +73,7 @@ MODULE_PARM_DESC(polarity, "Output's polarity: 0 = active high, 1 = active low") ...@@ -72,7 +73,7 @@ MODULE_PARM_DESC(polarity, "Output's polarity: 0 = active high, 1 = active low")
struct ds1621_data { struct ds1621_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* !=0 if following fields are valid */ char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
...@@ -156,10 +157,10 @@ static ssize_t set_temp_##suffix(struct device *dev, struct device_attribute *at ...@@ -156,10 +157,10 @@ static ssize_t set_temp_##suffix(struct device *dev, struct device_attribute *at
struct ds1621_data *data = ds1621_update_client(dev); \ struct ds1621_data *data = ds1621_update_client(dev); \
u16 val = LM75_TEMP_TO_REG(simple_strtoul(buf, NULL, 10)); \ u16 val = LM75_TEMP_TO_REG(simple_strtoul(buf, NULL, 10)); \
\ \
down(&data->update_lock); \ mutex_lock(&data->update_lock); \
data->value = val; \ data->value = val; \
ds1621_write_value(client, reg, data->value); \ ds1621_write_value(client, reg, data->value); \
up(&data->update_lock); \ mutex_unlock(&data->update_lock); \
return count; \ return count; \
} }
...@@ -242,7 +243,7 @@ static int ds1621_detect(struct i2c_adapter *adapter, int address, ...@@ -242,7 +243,7 @@ static int ds1621_detect(struct i2c_adapter *adapter, int address,
/* Fill in remaining client fields and put it into the global list */ /* Fill in remaining client fields and put it into the global list */
strlcpy(new_client->name, "ds1621", I2C_NAME_SIZE); strlcpy(new_client->name, "ds1621", I2C_NAME_SIZE);
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
...@@ -297,7 +298,7 @@ static struct ds1621_data *ds1621_update_client(struct device *dev) ...@@ -297,7 +298,7 @@ static struct ds1621_data *ds1621_update_client(struct device *dev)
struct ds1621_data *data = i2c_get_clientdata(client); struct ds1621_data *data = i2c_get_clientdata(client);
u8 new_conf; u8 new_conf;
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ + HZ / 2) if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|| !data->valid) { || !data->valid) {
...@@ -327,7 +328,7 @@ static struct ds1621_data *ds1621_update_client(struct device *dev) ...@@ -327,7 +328,7 @@ static struct ds1621_data *ds1621_update_client(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
/* /*
* Addresses to scan * Addresses to scan
...@@ -133,7 +134,7 @@ static struct i2c_driver fscher_driver = { ...@@ -133,7 +134,7 @@ static struct i2c_driver fscher_driver = {
struct fscher_data { struct fscher_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* zero until following fields are valid */ char valid; /* zero until following fields are valid */
unsigned long last_updated; /* in jiffies */ unsigned long last_updated; /* in jiffies */
...@@ -332,7 +333,7 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -332,7 +333,7 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
* global list */ * global list */
strlcpy(new_client->name, "fscher", I2C_NAME_SIZE); strlcpy(new_client->name, "fscher", I2C_NAME_SIZE);
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
...@@ -417,7 +418,7 @@ static struct fscher_data *fscher_update_device(struct device *dev) ...@@ -417,7 +418,7 @@ static struct fscher_data *fscher_update_device(struct device *dev)
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct fscher_data *data = i2c_get_clientdata(client); struct fscher_data *data = i2c_get_clientdata(client);
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) { if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
...@@ -457,7 +458,7 @@ static struct fscher_data *fscher_update_device(struct device *dev) ...@@ -457,7 +458,7 @@ static struct fscher_data *fscher_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
...@@ -472,10 +473,10 @@ static ssize_t set_fan_status(struct i2c_client *client, struct fscher_data *dat ...@@ -472,10 +473,10 @@ static ssize_t set_fan_status(struct i2c_client *client, struct fscher_data *dat
/* bits 0..1, 3..7 reserved => mask with 0x04 */ /* bits 0..1, 3..7 reserved => mask with 0x04 */
unsigned long v = simple_strtoul(buf, NULL, 10) & 0x04; unsigned long v = simple_strtoul(buf, NULL, 10) & 0x04;
down(&data->update_lock); mutex_lock(&data->update_lock);
data->fan_status[FAN_INDEX_FROM_NUM(nr)] &= ~v; data->fan_status[FAN_INDEX_FROM_NUM(nr)] &= ~v;
fscher_write_value(client, reg, v); fscher_write_value(client, reg, v);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -490,10 +491,10 @@ static ssize_t set_pwm(struct i2c_client *client, struct fscher_data *data, ...@@ -490,10 +491,10 @@ static ssize_t set_pwm(struct i2c_client *client, struct fscher_data *data,
{ {
unsigned long v = simple_strtoul(buf, NULL, 10); unsigned long v = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->fan_min[FAN_INDEX_FROM_NUM(nr)] = v > 0xff ? 0xff : v; data->fan_min[FAN_INDEX_FROM_NUM(nr)] = v > 0xff ? 0xff : v;
fscher_write_value(client, reg, data->fan_min[FAN_INDEX_FROM_NUM(nr)]); fscher_write_value(client, reg, data->fan_min[FAN_INDEX_FROM_NUM(nr)]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -518,14 +519,14 @@ static ssize_t set_fan_div(struct i2c_client *client, struct fscher_data *data, ...@@ -518,14 +519,14 @@ static ssize_t set_fan_div(struct i2c_client *client, struct fscher_data *data,
return -EINVAL; return -EINVAL;
} }
down(&data->update_lock); mutex_lock(&data->update_lock);
/* bits 2..7 reserved => mask with 0x03 */ /* bits 2..7 reserved => mask with 0x03 */
data->fan_ripple[FAN_INDEX_FROM_NUM(nr)] &= ~0x03; data->fan_ripple[FAN_INDEX_FROM_NUM(nr)] &= ~0x03;
data->fan_ripple[FAN_INDEX_FROM_NUM(nr)] |= v; data->fan_ripple[FAN_INDEX_FROM_NUM(nr)] |= v;
fscher_write_value(client, reg, data->fan_ripple[FAN_INDEX_FROM_NUM(nr)]); fscher_write_value(client, reg, data->fan_ripple[FAN_INDEX_FROM_NUM(nr)]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -552,10 +553,10 @@ static ssize_t set_temp_status(struct i2c_client *client, struct fscher_data *da ...@@ -552,10 +553,10 @@ static ssize_t set_temp_status(struct i2c_client *client, struct fscher_data *da
/* bits 2..7 reserved, 0 read only => mask with 0x02 */ /* bits 2..7 reserved, 0 read only => mask with 0x02 */
unsigned long v = simple_strtoul(buf, NULL, 10) & 0x02; unsigned long v = simple_strtoul(buf, NULL, 10) & 0x02;
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_status[TEMP_INDEX_FROM_NUM(nr)] &= ~v; data->temp_status[TEMP_INDEX_FROM_NUM(nr)] &= ~v;
fscher_write_value(client, reg, v); fscher_write_value(client, reg, v);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -609,10 +610,10 @@ static ssize_t set_control(struct i2c_client *client, struct fscher_data *data, ...@@ -609,10 +610,10 @@ static ssize_t set_control(struct i2c_client *client, struct fscher_data *data,
/* bits 1..7 reserved => mask with 0x01 */ /* bits 1..7 reserved => mask with 0x01 */
unsigned long v = simple_strtoul(buf, NULL, 10) & 0x01; unsigned long v = simple_strtoul(buf, NULL, 10) & 0x01;
down(&data->update_lock); mutex_lock(&data->update_lock);
data->global_control &= ~v; data->global_control &= ~v;
fscher_write_value(client, reg, v); fscher_write_value(client, reg, v);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -631,11 +632,11 @@ static ssize_t set_watchdog_control(struct i2c_client *client, struct ...@@ -631,11 +632,11 @@ static ssize_t set_watchdog_control(struct i2c_client *client, struct
/* bits 0..3 reserved => mask with 0xf0 */ /* bits 0..3 reserved => mask with 0xf0 */
unsigned long v = simple_strtoul(buf, NULL, 10) & 0xf0; unsigned long v = simple_strtoul(buf, NULL, 10) & 0xf0;
down(&data->update_lock); mutex_lock(&data->update_lock);
data->watchdog[2] &= ~0xf0; data->watchdog[2] &= ~0xf0;
data->watchdog[2] |= v; data->watchdog[2] |= v;
fscher_write_value(client, reg, data->watchdog[2]); fscher_write_value(client, reg, data->watchdog[2]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -651,10 +652,10 @@ static ssize_t set_watchdog_status(struct i2c_client *client, struct fscher_data ...@@ -651,10 +652,10 @@ static ssize_t set_watchdog_status(struct i2c_client *client, struct fscher_data
/* bits 0, 2..7 reserved => mask with 0x02 */ /* bits 0, 2..7 reserved => mask with 0x02 */
unsigned long v = simple_strtoul(buf, NULL, 10) & 0x02; unsigned long v = simple_strtoul(buf, NULL, 10) & 0x02;
down(&data->update_lock); mutex_lock(&data->update_lock);
data->watchdog[1] &= ~v; data->watchdog[1] &= ~v;
fscher_write_value(client, reg, v); fscher_write_value(client, reg, v);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -669,10 +670,10 @@ static ssize_t set_watchdog_preset(struct i2c_client *client, struct fscher_data ...@@ -669,10 +670,10 @@ static ssize_t set_watchdog_preset(struct i2c_client *client, struct fscher_data
{ {
unsigned long v = simple_strtoul(buf, NULL, 10) & 0xff; unsigned long v = simple_strtoul(buf, NULL, 10) & 0xff;
down(&data->update_lock); mutex_lock(&data->update_lock);
data->watchdog[0] = v; data->watchdog[0] = v;
fscher_write_value(client, reg, data->watchdog[0]); fscher_write_value(client, reg, data->watchdog[0]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
/* /*
* Addresses to scan * Addresses to scan
...@@ -114,7 +115,7 @@ static struct i2c_driver fscpos_driver = { ...@@ -114,7 +115,7 @@ static struct i2c_driver fscpos_driver = {
struct fscpos_data { struct fscpos_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* 0 until following fields are valid */ char valid; /* 0 until following fields are valid */
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
...@@ -208,13 +209,13 @@ static ssize_t set_fan_ripple(struct i2c_client *client, struct fscpos_data ...@@ -208,13 +209,13 @@ static ssize_t set_fan_ripple(struct i2c_client *client, struct fscpos_data
return -EINVAL; return -EINVAL;
} }
down(&data->update_lock); mutex_lock(&data->update_lock);
/* bits 2..7 reserved => mask with 0x03 */ /* bits 2..7 reserved => mask with 0x03 */
data->fan_ripple[nr - 1] &= ~0x03; data->fan_ripple[nr - 1] &= ~0x03;
data->fan_ripple[nr - 1] |= v; data->fan_ripple[nr - 1] |= v;
fscpos_write_value(client, reg, data->fan_ripple[nr - 1]); fscpos_write_value(client, reg, data->fan_ripple[nr - 1]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -232,10 +233,10 @@ static ssize_t set_pwm(struct i2c_client *client, struct fscpos_data *data, ...@@ -232,10 +233,10 @@ static ssize_t set_pwm(struct i2c_client *client, struct fscpos_data *data,
if (v < 0) v = 0; if (v < 0) v = 0;
if (v > 255) v = 255; if (v > 255) v = 255;
down(&data->update_lock); mutex_lock(&data->update_lock);
data->pwm[nr - 1] = v; data->pwm[nr - 1] = v;
fscpos_write_value(client, reg, data->pwm[nr - 1]); fscpos_write_value(client, reg, data->pwm[nr - 1]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -278,11 +279,11 @@ static ssize_t set_wdog_control(struct i2c_client *client, struct fscpos_data ...@@ -278,11 +279,11 @@ static ssize_t set_wdog_control(struct i2c_client *client, struct fscpos_data
/* bits 0..3 reserved => mask with 0xf0 */ /* bits 0..3 reserved => mask with 0xf0 */
unsigned long v = simple_strtoul(buf, NULL, 10) & 0xf0; unsigned long v = simple_strtoul(buf, NULL, 10) & 0xf0;
down(&data->update_lock); mutex_lock(&data->update_lock);
data->wdog_control &= ~0xf0; data->wdog_control &= ~0xf0;
data->wdog_control |= v; data->wdog_control |= v;
fscpos_write_value(client, reg, data->wdog_control); fscpos_write_value(client, reg, data->wdog_control);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -304,10 +305,10 @@ static ssize_t set_wdog_state(struct i2c_client *client, struct fscpos_data ...@@ -304,10 +305,10 @@ static ssize_t set_wdog_state(struct i2c_client *client, struct fscpos_data
return -EINVAL; return -EINVAL;
} }
down(&data->update_lock); mutex_lock(&data->update_lock);
data->wdog_state &= ~v; data->wdog_state &= ~v;
fscpos_write_value(client, reg, v); fscpos_write_value(client, reg, v);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -321,10 +322,10 @@ static ssize_t set_wdog_preset(struct i2c_client *client, struct fscpos_data ...@@ -321,10 +322,10 @@ static ssize_t set_wdog_preset(struct i2c_client *client, struct fscpos_data
{ {
unsigned long v = simple_strtoul(buf, NULL, 10) & 0xff; unsigned long v = simple_strtoul(buf, NULL, 10) & 0xff;
down(&data->update_lock); mutex_lock(&data->update_lock);
data->wdog_preset = v; data->wdog_preset = v;
fscpos_write_value(client, reg, data->wdog_preset); fscpos_write_value(client, reg, data->wdog_preset);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -483,7 +484,7 @@ static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -483,7 +484,7 @@ static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind)
strlcpy(new_client->name, "fscpos", I2C_NAME_SIZE); strlcpy(new_client->name, "fscpos", I2C_NAME_SIZE);
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
...@@ -579,7 +580,7 @@ static struct fscpos_data *fscpos_update_device(struct device *dev) ...@@ -579,7 +580,7 @@ static struct fscpos_data *fscpos_update_device(struct device *dev)
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct fscpos_data *data = i2c_get_clientdata(client); struct fscpos_data *data = i2c_get_clientdata(client);
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) { if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
int i; int i;
...@@ -625,7 +626,7 @@ static struct fscpos_data *fscpos_update_device(struct device *dev) ...@@ -625,7 +626,7 @@ static struct fscpos_data *fscpos_update_device(struct device *dev)
data->last_updated = jiffies; data->last_updated = jiffies;
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
/* Addresses to scan */ /* Addresses to scan */
static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
...@@ -120,7 +121,7 @@ struct gl518_data { ...@@ -120,7 +121,7 @@ struct gl518_data {
struct class_device *class_dev; struct class_device *class_dev;
enum chips type; enum chips type;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* !=0 if following fields are valid */ char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
...@@ -212,10 +213,10 @@ static ssize_t set_##suffix(struct device *dev, struct device_attribute *attr, c ...@@ -212,10 +213,10 @@ static ssize_t set_##suffix(struct device *dev, struct device_attribute *attr, c
struct gl518_data *data = i2c_get_clientdata(client); \ struct gl518_data *data = i2c_get_clientdata(client); \
long val = simple_strtol(buf, NULL, 10); \ long val = simple_strtol(buf, NULL, 10); \
\ \
down(&data->update_lock); \ mutex_lock(&data->update_lock); \
data->value = type##_TO_REG(val); \ data->value = type##_TO_REG(val); \
gl518_write_value(client, reg, data->value); \ gl518_write_value(client, reg, data->value); \
up(&data->update_lock); \ mutex_unlock(&data->update_lock); \
return count; \ return count; \
} }
...@@ -228,12 +229,12 @@ static ssize_t set_##suffix(struct device *dev, struct device_attribute *attr, c ...@@ -228,12 +229,12 @@ static ssize_t set_##suffix(struct device *dev, struct device_attribute *attr, c
int regvalue; \ int regvalue; \
unsigned long val = simple_strtoul(buf, NULL, 10); \ unsigned long val = simple_strtoul(buf, NULL, 10); \
\ \
down(&data->update_lock); \ mutex_lock(&data->update_lock); \
regvalue = gl518_read_value(client, reg); \ regvalue = gl518_read_value(client, reg); \
data->value = type##_TO_REG(val); \ data->value = type##_TO_REG(val); \
regvalue = (regvalue & ~mask) | (data->value << shift); \ regvalue = (regvalue & ~mask) | (data->value << shift); \
gl518_write_value(client, reg, regvalue); \ gl518_write_value(client, reg, regvalue); \
up(&data->update_lock); \ mutex_unlock(&data->update_lock); \
return count; \ return count; \
} }
...@@ -265,7 +266,7 @@ static ssize_t set_fan_min1(struct device *dev, struct device_attribute *attr, c ...@@ -265,7 +266,7 @@ static ssize_t set_fan_min1(struct device *dev, struct device_attribute *attr, c
int regvalue; int regvalue;
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT); regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT);
data->fan_min[0] = FAN_TO_REG(val, data->fan_min[0] = FAN_TO_REG(val,
DIV_FROM_REG(data->fan_div[0])); DIV_FROM_REG(data->fan_div[0]));
...@@ -280,7 +281,7 @@ static ssize_t set_fan_min1(struct device *dev, struct device_attribute *attr, c ...@@ -280,7 +281,7 @@ static ssize_t set_fan_min1(struct device *dev, struct device_attribute *attr, c
data->beep_mask &= data->alarm_mask; data->beep_mask &= data->alarm_mask;
gl518_write_value(client, GL518_REG_ALARM, data->beep_mask); gl518_write_value(client, GL518_REG_ALARM, data->beep_mask);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -291,7 +292,7 @@ static ssize_t set_fan_min2(struct device *dev, struct device_attribute *attr, c ...@@ -291,7 +292,7 @@ static ssize_t set_fan_min2(struct device *dev, struct device_attribute *attr, c
int regvalue; int regvalue;
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT); regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT);
data->fan_min[1] = FAN_TO_REG(val, data->fan_min[1] = FAN_TO_REG(val,
DIV_FROM_REG(data->fan_div[1])); DIV_FROM_REG(data->fan_div[1]));
...@@ -306,7 +307,7 @@ static ssize_t set_fan_min2(struct device *dev, struct device_attribute *attr, c ...@@ -306,7 +307,7 @@ static ssize_t set_fan_min2(struct device *dev, struct device_attribute *attr, c
data->beep_mask &= data->alarm_mask; data->beep_mask &= data->alarm_mask;
gl518_write_value(client, GL518_REG_ALARM, data->beep_mask); gl518_write_value(client, GL518_REG_ALARM, data->beep_mask);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -407,7 +408,7 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -407,7 +408,7 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind)
strlcpy(new_client->name, "gl518sm", I2C_NAME_SIZE); strlcpy(new_client->name, "gl518sm", I2C_NAME_SIZE);
data->type = kind; data->type = kind;
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
...@@ -525,7 +526,7 @@ static struct gl518_data *gl518_update_device(struct device *dev) ...@@ -525,7 +526,7 @@ static struct gl518_data *gl518_update_device(struct device *dev)
struct gl518_data *data = i2c_get_clientdata(client); struct gl518_data *data = i2c_get_clientdata(client);
int val; int val;
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ + HZ / 2) if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|| !data->valid) { || !data->valid) {
...@@ -586,7 +587,7 @@ static struct gl518_data *gl518_update_device(struct device *dev) ...@@ -586,7 +587,7 @@ static struct gl518_data *gl518_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/hwmon-vid.h> #include <linux/hwmon-vid.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
/* Type of the extra sensor */ /* Type of the extra sensor */
static unsigned short extra_sensor_type; static unsigned short extra_sensor_type;
...@@ -121,7 +122,7 @@ static struct i2c_driver gl520_driver = { ...@@ -121,7 +122,7 @@ static struct i2c_driver gl520_driver = {
struct gl520_data { struct gl520_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* zero until the following fields are valid */ char valid; /* zero until the following fields are valid */
unsigned long last_updated; /* in jiffies */ unsigned long last_updated; /* in jiffies */
...@@ -303,7 +304,7 @@ static ssize_t set_in_min(struct i2c_client *client, struct gl520_data *data, co ...@@ -303,7 +304,7 @@ static ssize_t set_in_min(struct i2c_client *client, struct gl520_data *data, co
long v = simple_strtol(buf, NULL, 10); long v = simple_strtol(buf, NULL, 10);
u8 r; u8 r;
down(&data->update_lock); mutex_lock(&data->update_lock);
if (n == 0) if (n == 0)
r = VDD_TO_REG(v); r = VDD_TO_REG(v);
...@@ -317,7 +318,7 @@ static ssize_t set_in_min(struct i2c_client *client, struct gl520_data *data, co ...@@ -317,7 +318,7 @@ static ssize_t set_in_min(struct i2c_client *client, struct gl520_data *data, co
else else
gl520_write_value(client, reg, r); gl520_write_value(client, reg, r);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -331,7 +332,7 @@ static ssize_t set_in_max(struct i2c_client *client, struct gl520_data *data, co ...@@ -331,7 +332,7 @@ static ssize_t set_in_max(struct i2c_client *client, struct gl520_data *data, co
else else
r = IN_TO_REG(v); r = IN_TO_REG(v);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_max[n] = r; data->in_max[n] = r;
...@@ -340,7 +341,7 @@ static ssize_t set_in_max(struct i2c_client *client, struct gl520_data *data, co ...@@ -340,7 +341,7 @@ static ssize_t set_in_max(struct i2c_client *client, struct gl520_data *data, co
else else
gl520_write_value(client, reg, r); gl520_write_value(client, reg, r);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -373,7 +374,7 @@ static ssize_t set_fan_min(struct i2c_client *client, struct gl520_data *data, c ...@@ -373,7 +374,7 @@ static ssize_t set_fan_min(struct i2c_client *client, struct gl520_data *data, c
unsigned long v = simple_strtoul(buf, NULL, 10); unsigned long v = simple_strtoul(buf, NULL, 10);
u8 r; u8 r;
down(&data->update_lock); mutex_lock(&data->update_lock);
r = FAN_TO_REG(v, data->fan_div[n - 1]); r = FAN_TO_REG(v, data->fan_div[n - 1]);
data->fan_min[n - 1] = r; data->fan_min[n - 1] = r;
...@@ -390,7 +391,7 @@ static ssize_t set_fan_min(struct i2c_client *client, struct gl520_data *data, c ...@@ -390,7 +391,7 @@ static ssize_t set_fan_min(struct i2c_client *client, struct gl520_data *data, c
data->beep_mask &= data->alarm_mask; data->beep_mask &= data->alarm_mask;
gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask); gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -409,7 +410,7 @@ static ssize_t set_fan_div(struct i2c_client *client, struct gl520_data *data, c ...@@ -409,7 +410,7 @@ static ssize_t set_fan_div(struct i2c_client *client, struct gl520_data *data, c
return -EINVAL; return -EINVAL;
} }
down(&data->update_lock); mutex_lock(&data->update_lock);
data->fan_div[n - 1] = r; data->fan_div[n - 1] = r;
if (n == 1) if (n == 1)
...@@ -417,7 +418,7 @@ static ssize_t set_fan_div(struct i2c_client *client, struct gl520_data *data, c ...@@ -417,7 +418,7 @@ static ssize_t set_fan_div(struct i2c_client *client, struct gl520_data *data, c
else else
gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x30) | (r << 4)); gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x30) | (r << 4));
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -425,10 +426,10 @@ static ssize_t set_fan_off(struct i2c_client *client, struct gl520_data *data, c ...@@ -425,10 +426,10 @@ static ssize_t set_fan_off(struct i2c_client *client, struct gl520_data *data, c
{ {
u8 r = simple_strtoul(buf, NULL, 10)?1:0; u8 r = simple_strtoul(buf, NULL, 10)?1:0;
down(&data->update_lock); mutex_lock(&data->update_lock);
data->fan_off = r; data->fan_off = r;
gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x0c) | (r << 2)); gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x0c) | (r << 2));
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -454,10 +455,10 @@ static ssize_t set_temp_max(struct i2c_client *client, struct gl520_data *data, ...@@ -454,10 +455,10 @@ static ssize_t set_temp_max(struct i2c_client *client, struct gl520_data *data,
{ {
long v = simple_strtol(buf, NULL, 10); long v = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_max[n - 1] = TEMP_TO_REG(v);; data->temp_max[n - 1] = TEMP_TO_REG(v);;
gl520_write_value(client, reg, data->temp_max[n - 1]); gl520_write_value(client, reg, data->temp_max[n - 1]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -465,10 +466,10 @@ static ssize_t set_temp_max_hyst(struct i2c_client *client, struct gl520_data *d ...@@ -465,10 +466,10 @@ static ssize_t set_temp_max_hyst(struct i2c_client *client, struct gl520_data *d
{ {
long v = simple_strtol(buf, NULL, 10); long v = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_max_hyst[n - 1] = TEMP_TO_REG(v); data->temp_max_hyst[n - 1] = TEMP_TO_REG(v);
gl520_write_value(client, reg, data->temp_max_hyst[n - 1]); gl520_write_value(client, reg, data->temp_max_hyst[n - 1]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -491,10 +492,10 @@ static ssize_t set_beep_enable(struct i2c_client *client, struct gl520_data *dat ...@@ -491,10 +492,10 @@ static ssize_t set_beep_enable(struct i2c_client *client, struct gl520_data *dat
{ {
u8 r = simple_strtoul(buf, NULL, 10)?0:1; u8 r = simple_strtoul(buf, NULL, 10)?0:1;
down(&data->update_lock); mutex_lock(&data->update_lock);
data->beep_enable = !r; data->beep_enable = !r;
gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x04) | (r << 2)); gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x04) | (r << 2));
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -502,11 +503,11 @@ static ssize_t set_beep_mask(struct i2c_client *client, struct gl520_data *data, ...@@ -502,11 +503,11 @@ static ssize_t set_beep_mask(struct i2c_client *client, struct gl520_data *data,
{ {
u8 r = simple_strtoul(buf, NULL, 10); u8 r = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
r &= data->alarm_mask; r &= data->alarm_mask;
data->beep_mask = r; data->beep_mask = r;
gl520_write_value(client, reg, r); gl520_write_value(client, reg, r);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -561,7 +562,7 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -561,7 +562,7 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
/* Fill in the remaining client fields */ /* Fill in the remaining client fields */
strlcpy(new_client->name, "gl520sm", I2C_NAME_SIZE); strlcpy(new_client->name, "gl520sm", I2C_NAME_SIZE);
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
...@@ -685,7 +686,7 @@ static struct gl520_data *gl520_update_device(struct device *dev) ...@@ -685,7 +686,7 @@ static struct gl520_data *gl520_update_device(struct device *dev)
struct gl520_data *data = i2c_get_clientdata(client); struct gl520_data *data = i2c_get_clientdata(client);
int val; int val;
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) { if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
...@@ -750,7 +751,7 @@ static struct gl520_data *gl520_update_device(struct device *dev) ...@@ -750,7 +751,7 @@ static struct gl520_data *gl520_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/timer.h> #include <linux/timer.h>
#include <linux/dmi.h> #include <linux/dmi.h>
#include <linux/mutex.h>
#include <asm/io.h> #include <asm/io.h>
#define HDAPS_LOW_PORT 0x1600 /* first port used by hdaps */ #define HDAPS_LOW_PORT 0x1600 /* first port used by hdaps */
...@@ -70,10 +71,10 @@ static u8 km_activity; ...@@ -70,10 +71,10 @@ static u8 km_activity;
static int rest_x; static int rest_x;
static int rest_y; static int rest_y;
static DECLARE_MUTEX(hdaps_sem); static DEFINE_MUTEX(hdaps_mutex);
/* /*
* __get_latch - Get the value from a given port. Callers must hold hdaps_sem. * __get_latch - Get the value from a given port. Callers must hold hdaps_mutex.
*/ */
static inline u8 __get_latch(u16 port) static inline u8 __get_latch(u16 port)
{ {
...@@ -82,7 +83,7 @@ static inline u8 __get_latch(u16 port) ...@@ -82,7 +83,7 @@ static inline u8 __get_latch(u16 port)
/* /*
* __check_latch - Check a port latch for a given value. Returns zero if the * __check_latch - Check a port latch for a given value. Returns zero if the
* port contains the given value. Callers must hold hdaps_sem. * port contains the given value. Callers must hold hdaps_mutex.
*/ */
static inline int __check_latch(u16 port, u8 val) static inline int __check_latch(u16 port, u8 val)
{ {
...@@ -93,7 +94,7 @@ static inline int __check_latch(u16 port, u8 val) ...@@ -93,7 +94,7 @@ static inline int __check_latch(u16 port, u8 val)
/* /*
* __wait_latch - Wait up to 100us for a port latch to get a certain value, * __wait_latch - Wait up to 100us for a port latch to get a certain value,
* returning zero if the value is obtained. Callers must hold hdaps_sem. * returning zero if the value is obtained. Callers must hold hdaps_mutex.
*/ */
static int __wait_latch(u16 port, u8 val) static int __wait_latch(u16 port, u8 val)
{ {
...@@ -110,7 +111,7 @@ static int __wait_latch(u16 port, u8 val) ...@@ -110,7 +111,7 @@ static int __wait_latch(u16 port, u8 val)
/* /*
* __device_refresh - request a refresh from the accelerometer. Does not wait * __device_refresh - request a refresh from the accelerometer. Does not wait
* for refresh to complete. Callers must hold hdaps_sem. * for refresh to complete. Callers must hold hdaps_mutex.
*/ */
static void __device_refresh(void) static void __device_refresh(void)
{ {
...@@ -124,7 +125,7 @@ static void __device_refresh(void) ...@@ -124,7 +125,7 @@ static void __device_refresh(void)
/* /*
* __device_refresh_sync - request a synchronous refresh from the * __device_refresh_sync - request a synchronous refresh from the
* accelerometer. We wait for the refresh to complete. Returns zero if * accelerometer. We wait for the refresh to complete. Returns zero if
* successful and nonzero on error. Callers must hold hdaps_sem. * successful and nonzero on error. Callers must hold hdaps_mutex.
*/ */
static int __device_refresh_sync(void) static int __device_refresh_sync(void)
{ {
...@@ -134,7 +135,7 @@ static int __device_refresh_sync(void) ...@@ -134,7 +135,7 @@ static int __device_refresh_sync(void)
/* /*
* __device_complete - indicate to the accelerometer that we are done reading * __device_complete - indicate to the accelerometer that we are done reading
* data, and then initiate an async refresh. Callers must hold hdaps_sem. * data, and then initiate an async refresh. Callers must hold hdaps_mutex.
*/ */
static inline void __device_complete(void) static inline void __device_complete(void)
{ {
...@@ -152,7 +153,7 @@ static int hdaps_readb_one(unsigned int port, u8 *val) ...@@ -152,7 +153,7 @@ static int hdaps_readb_one(unsigned int port, u8 *val)
{ {
int ret; int ret;
down(&hdaps_sem); mutex_lock(&hdaps_mutex);
/* do a sync refresh -- we need to be sure that we read fresh data */ /* do a sync refresh -- we need to be sure that we read fresh data */
ret = __device_refresh_sync(); ret = __device_refresh_sync();
...@@ -163,7 +164,7 @@ static int hdaps_readb_one(unsigned int port, u8 *val) ...@@ -163,7 +164,7 @@ static int hdaps_readb_one(unsigned int port, u8 *val)
__device_complete(); __device_complete();
out: out:
up(&hdaps_sem); mutex_unlock(&hdaps_mutex);
return ret; return ret;
} }
...@@ -198,9 +199,9 @@ static int hdaps_read_pair(unsigned int port1, unsigned int port2, ...@@ -198,9 +199,9 @@ static int hdaps_read_pair(unsigned int port1, unsigned int port2,
{ {
int ret; int ret;
down(&hdaps_sem); mutex_lock(&hdaps_mutex);
ret = __hdaps_read_pair(port1, port2, val1, val2); ret = __hdaps_read_pair(port1, port2, val1, val2);
up(&hdaps_sem); mutex_unlock(&hdaps_mutex);
return ret; return ret;
} }
...@@ -213,7 +214,7 @@ static int hdaps_device_init(void) ...@@ -213,7 +214,7 @@ static int hdaps_device_init(void)
{ {
int total, ret = -ENXIO; int total, ret = -ENXIO;
down(&hdaps_sem); mutex_lock(&hdaps_mutex);
outb(0x13, 0x1610); outb(0x13, 0x1610);
outb(0x01, 0x161f); outb(0x01, 0x161f);
...@@ -279,7 +280,7 @@ static int hdaps_device_init(void) ...@@ -279,7 +280,7 @@ static int hdaps_device_init(void)
} }
out: out:
up(&hdaps_sem); mutex_unlock(&hdaps_mutex);
return ret; return ret;
} }
...@@ -313,7 +314,7 @@ static struct platform_driver hdaps_driver = { ...@@ -313,7 +314,7 @@ static struct platform_driver hdaps_driver = {
}; };
/* /*
* hdaps_calibrate - Set our "resting" values. Callers must hold hdaps_sem. * hdaps_calibrate - Set our "resting" values. Callers must hold hdaps_mutex.
*/ */
static void hdaps_calibrate(void) static void hdaps_calibrate(void)
{ {
...@@ -325,7 +326,7 @@ static void hdaps_mousedev_poll(unsigned long unused) ...@@ -325,7 +326,7 @@ static void hdaps_mousedev_poll(unsigned long unused)
int x, y; int x, y;
/* Cannot sleep. Try nonblockingly. If we fail, try again later. */ /* Cannot sleep. Try nonblockingly. If we fail, try again later. */
if (down_trylock(&hdaps_sem)) { if (!mutex_trylock(&hdaps_mutex)) {
mod_timer(&hdaps_timer,jiffies + HDAPS_POLL_PERIOD); mod_timer(&hdaps_timer,jiffies + HDAPS_POLL_PERIOD);
return; return;
} }
...@@ -340,7 +341,7 @@ static void hdaps_mousedev_poll(unsigned long unused) ...@@ -340,7 +341,7 @@ static void hdaps_mousedev_poll(unsigned long unused)
mod_timer(&hdaps_timer, jiffies + HDAPS_POLL_PERIOD); mod_timer(&hdaps_timer, jiffies + HDAPS_POLL_PERIOD);
out: out:
up(&hdaps_sem); mutex_unlock(&hdaps_mutex);
} }
...@@ -420,9 +421,9 @@ static ssize_t hdaps_calibrate_store(struct device *dev, ...@@ -420,9 +421,9 @@ static ssize_t hdaps_calibrate_store(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
down(&hdaps_sem); mutex_lock(&hdaps_mutex);
hdaps_calibrate(); hdaps_calibrate();
up(&hdaps_sem); mutex_unlock(&hdaps_mutex);
return count; return count;
} }
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include <linux/hwmon-sysfs.h> #include <linux/hwmon-sysfs.h>
#include <linux/hwmon-vid.h> #include <linux/hwmon-vid.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
#include <asm/io.h> #include <asm/io.h>
...@@ -194,10 +195,10 @@ static int DIV_TO_REG(int val) ...@@ -194,10 +195,10 @@ static int DIV_TO_REG(int val)
struct it87_data { struct it87_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore lock; struct mutex lock;
enum chips type; enum chips type;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* !=0 if following fields are valid */ char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
...@@ -290,11 +291,11 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, ...@@ -290,11 +291,11 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
struct it87_data *data = i2c_get_clientdata(client); struct it87_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_min[nr] = IN_TO_REG(val); data->in_min[nr] = IN_TO_REG(val);
it87_write_value(client, IT87_REG_VIN_MIN(nr), it87_write_value(client, IT87_REG_VIN_MIN(nr),
data->in_min[nr]); data->in_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
...@@ -307,11 +308,11 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, ...@@ -307,11 +308,11 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
struct it87_data *data = i2c_get_clientdata(client); struct it87_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_max[nr] = IN_TO_REG(val); data->in_max[nr] = IN_TO_REG(val);
it87_write_value(client, IT87_REG_VIN_MAX(nr), it87_write_value(client, IT87_REG_VIN_MAX(nr),
data->in_max[nr]); data->in_max[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -381,10 +382,10 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, ...@@ -381,10 +382,10 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
struct it87_data *data = i2c_get_clientdata(client); struct it87_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); int val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_high[nr] = TEMP_TO_REG(val); data->temp_high[nr] = TEMP_TO_REG(val);
it87_write_value(client, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]); it87_write_value(client, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
...@@ -397,10 +398,10 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, ...@@ -397,10 +398,10 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
struct it87_data *data = i2c_get_clientdata(client); struct it87_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); int val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_low[nr] = TEMP_TO_REG(val); data->temp_low[nr] = TEMP_TO_REG(val);
it87_write_value(client, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]); it87_write_value(client, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
#define show_temp_offset(offset) \ #define show_temp_offset(offset) \
...@@ -440,7 +441,7 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr, ...@@ -440,7 +441,7 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,
struct it87_data *data = i2c_get_clientdata(client); struct it87_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); int val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->sensor &= ~(1 << nr); data->sensor &= ~(1 << nr);
data->sensor &= ~(8 << nr); data->sensor &= ~(8 << nr);
...@@ -450,11 +451,11 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr, ...@@ -450,11 +451,11 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,
else if (val == 2) else if (val == 2)
data->sensor |= 8 << nr; data->sensor |= 8 << nr;
else if (val != 0) { else if (val != 0) {
up(&data->update_lock); mutex_unlock(&data->update_lock);
return -EINVAL; return -EINVAL;
} }
it87_write_value(client, IT87_REG_TEMP_ENABLE, data->sensor); it87_write_value(client, IT87_REG_TEMP_ENABLE, data->sensor);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
#define show_sensor_offset(offset) \ #define show_sensor_offset(offset) \
...@@ -524,7 +525,7 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, ...@@ -524,7 +525,7 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
int val = simple_strtol(buf, NULL, 10); int val = simple_strtol(buf, NULL, 10);
u8 reg = it87_read_value(client, IT87_REG_FAN_DIV); u8 reg = it87_read_value(client, IT87_REG_FAN_DIV);
down(&data->update_lock); mutex_lock(&data->update_lock);
switch (nr) { switch (nr) {
case 0: data->fan_div[nr] = reg & 0x07; break; case 0: data->fan_div[nr] = reg & 0x07; break;
case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break; case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break;
...@@ -533,7 +534,7 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, ...@@ -533,7 +534,7 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 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]); it87_write_value(client, IT87_REG_FAN_MIN(nr), data->fan_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
...@@ -548,7 +549,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, ...@@ -548,7 +549,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
int i, min[3]; int i, min[3];
u8 old; u8 old;
down(&data->update_lock); mutex_lock(&data->update_lock);
old = it87_read_value(client, IT87_REG_FAN_DIV); old = it87_read_value(client, IT87_REG_FAN_DIV);
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
...@@ -576,7 +577,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, ...@@ -576,7 +577,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
data->fan_min[i]=FAN_TO_REG(min[i], DIV_FROM_REG(data->fan_div[i])); 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]); it87_write_value(client, IT87_REG_FAN_MIN(i), data->fan_min[i]);
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t set_pwm_enable(struct device *dev, static ssize_t set_pwm_enable(struct device *dev,
...@@ -589,7 +590,7 @@ static ssize_t set_pwm_enable(struct device *dev, ...@@ -589,7 +590,7 @@ static ssize_t set_pwm_enable(struct device *dev,
struct it87_data *data = i2c_get_clientdata(client); struct it87_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); int val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
if (val == 0) { if (val == 0) {
int tmp; int tmp;
...@@ -606,11 +607,11 @@ static ssize_t set_pwm_enable(struct device *dev, ...@@ -606,11 +607,11 @@ static ssize_t set_pwm_enable(struct device *dev,
/* set saved pwm value, clear FAN_CTLX PWM mode bit */ /* 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])); it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr]));
} else { } else {
up(&data->update_lock); mutex_unlock(&data->update_lock);
return -EINVAL; return -EINVAL;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
...@@ -626,11 +627,11 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, ...@@ -626,11 +627,11 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
if (val < 0 || val > 255) if (val < 0 || val > 255)
return -EINVAL; return -EINVAL;
down(&data->update_lock); mutex_lock(&data->update_lock);
data->manual_pwm_ctl[nr] = val; data->manual_pwm_ctl[nr] = val;
if (data->fan_main_ctrl & (1 << nr)) if (data->fan_main_ctrl & (1 << nr))
it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr]));
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -776,7 +777,7 @@ static int it87_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -776,7 +777,7 @@ static int it87_detect(struct i2c_adapter *adapter, int address, int kind)
new_client = &data->client; new_client = &data->client;
if (is_isa) if (is_isa)
init_MUTEX(&data->lock); mutex_init(&data->lock);
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
new_client->adapter = adapter; new_client->adapter = adapter;
...@@ -823,7 +824,7 @@ static int it87_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -823,7 +824,7 @@ static int it87_detect(struct i2c_adapter *adapter, int address, int kind)
strlcpy(new_client->name, name, I2C_NAME_SIZE); strlcpy(new_client->name, name, I2C_NAME_SIZE);
data->type = kind; data->type = kind;
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
...@@ -950,10 +951,10 @@ static int it87_read_value(struct i2c_client *client, u8 reg) ...@@ -950,10 +951,10 @@ static int it87_read_value(struct i2c_client *client, u8 reg)
int res; int res;
if (i2c_is_isa_client(client)) { if (i2c_is_isa_client(client)) {
down(&data->lock); mutex_lock(&data->lock);
outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET);
res = inb_p(client->addr + IT87_DATA_REG_OFFSET); res = inb_p(client->addr + IT87_DATA_REG_OFFSET);
up(&data->lock); mutex_unlock(&data->lock);
return res; return res;
} else } else
return i2c_smbus_read_byte_data(client, reg); return i2c_smbus_read_byte_data(client, reg);
...@@ -969,10 +970,10 @@ static int it87_write_value(struct i2c_client *client, u8 reg, u8 value) ...@@ -969,10 +970,10 @@ static int it87_write_value(struct i2c_client *client, u8 reg, u8 value)
struct it87_data *data = i2c_get_clientdata(client); struct it87_data *data = i2c_get_clientdata(client);
if (i2c_is_isa_client(client)) { if (i2c_is_isa_client(client)) {
down(&data->lock); mutex_lock(&data->lock);
outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET);
outb_p(value, client->addr + IT87_DATA_REG_OFFSET); outb_p(value, client->addr + IT87_DATA_REG_OFFSET);
up(&data->lock); mutex_unlock(&data->lock);
return 0; return 0;
} else } else
return i2c_smbus_write_byte_data(client, reg, value); return i2c_smbus_write_byte_data(client, reg, value);
...@@ -1098,7 +1099,7 @@ static struct it87_data *it87_update_device(struct device *dev) ...@@ -1098,7 +1099,7 @@ static struct it87_data *it87_update_device(struct device *dev)
struct it87_data *data = i2c_get_clientdata(client); struct it87_data *data = i2c_get_clientdata(client);
int i; int i;
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ + HZ / 2) if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|| !data->valid) { || !data->valid) {
...@@ -1160,7 +1161,7 @@ static struct it87_data *it87_update_device(struct device *dev) ...@@ -1160,7 +1161,7 @@ static struct it87_data *it87_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <linux/hwmon-sysfs.h> #include <linux/hwmon-sysfs.h>
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
/* /*
* Addresses to scan * Addresses to scan
...@@ -153,7 +154,7 @@ static struct i2c_driver lm63_driver = { ...@@ -153,7 +154,7 @@ static struct i2c_driver lm63_driver = {
struct lm63_data { struct lm63_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* zero until following fields are valid */ char valid; /* zero until following fields are valid */
unsigned long last_updated; /* in jiffies */ unsigned long last_updated; /* in jiffies */
...@@ -192,13 +193,13 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *dummy, ...@@ -192,13 +193,13 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *dummy,
struct lm63_data *data = i2c_get_clientdata(client); struct lm63_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->fan[1] = FAN_TO_REG(val); data->fan[1] = FAN_TO_REG(val);
i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_LSB, i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_LSB,
data->fan[1] & 0xFF); data->fan[1] & 0xFF);
i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_MSB, i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_MSB,
data->fan[1] >> 8); data->fan[1] >> 8);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -222,12 +223,12 @@ static ssize_t set_pwm1(struct device *dev, struct device_attribute *dummy, ...@@ -222,12 +223,12 @@ static ssize_t set_pwm1(struct device *dev, struct device_attribute *dummy,
return -EPERM; return -EPERM;
val = simple_strtoul(buf, NULL, 10); val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->pwm1_value = val <= 0 ? 0 : data->pwm1_value = val <= 0 ? 0 :
val >= 255 ? 2 * data->pwm1_freq : val >= 255 ? 2 * data->pwm1_freq :
(val * data->pwm1_freq * 2 + 127) / 255; (val * data->pwm1_freq * 2 + 127) / 255;
i2c_smbus_write_byte_data(client, LM63_REG_PWM_VALUE, data->pwm1_value); i2c_smbus_write_byte_data(client, LM63_REG_PWM_VALUE, data->pwm1_value);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -253,10 +254,10 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *dummy, ...@@ -253,10 +254,10 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *dummy,
struct lm63_data *data = i2c_get_clientdata(client); struct lm63_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp8[1] = TEMP8_TO_REG(val); data->temp8[1] = TEMP8_TO_REG(val);
i2c_smbus_write_byte_data(client, LM63_REG_LOCAL_HIGH, data->temp8[1]); i2c_smbus_write_byte_data(client, LM63_REG_LOCAL_HIGH, data->temp8[1]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -284,13 +285,13 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, ...@@ -284,13 +285,13 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
int nr = attr->index; int nr = attr->index;
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp11[nr] = TEMP11_TO_REG(val); data->temp11[nr] = TEMP11_TO_REG(val);
i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2], i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2],
data->temp11[nr] >> 8); data->temp11[nr] >> 8);
i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1], i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1],
data->temp11[nr] & 0xff); data->temp11[nr] & 0xff);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -314,11 +315,11 @@ static ssize_t set_temp2_crit_hyst(struct device *dev, struct device_attribute * ...@@ -314,11 +315,11 @@ static ssize_t set_temp2_crit_hyst(struct device *dev, struct device_attribute *
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
long hyst; long hyst;
down(&data->update_lock); mutex_lock(&data->update_lock);
hyst = TEMP8_FROM_REG(data->temp8[2]) - val; hyst = TEMP8_FROM_REG(data->temp8[2]) - val;
i2c_smbus_write_byte_data(client, LM63_REG_REMOTE_TCRIT_HYST, i2c_smbus_write_byte_data(client, LM63_REG_REMOTE_TCRIT_HYST,
HYST_TO_REG(hyst)); HYST_TO_REG(hyst));
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -427,7 +428,7 @@ static int lm63_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -427,7 +428,7 @@ static int lm63_detect(struct i2c_adapter *adapter, int address, int kind)
strlcpy(new_client->name, "lm63", I2C_NAME_SIZE); strlcpy(new_client->name, "lm63", I2C_NAME_SIZE);
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
...@@ -530,7 +531,7 @@ static struct lm63_data *lm63_update_device(struct device *dev) ...@@ -530,7 +531,7 @@ static struct lm63_data *lm63_update_device(struct device *dev)
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct lm63_data *data = i2c_get_clientdata(client); struct lm63_data *data = i2c_get_clientdata(client);
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
if (data->config & 0x04) { /* tachometer enabled */ if (data->config & 0x04) { /* tachometer enabled */
...@@ -582,7 +583,7 @@ static struct lm63_data *lm63_update_device(struct device *dev) ...@@ -582,7 +583,7 @@ static struct lm63_data *lm63_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
#include "lm75.h" #include "lm75.h"
...@@ -47,7 +48,7 @@ I2C_CLIENT_INSMOD_1(lm75); ...@@ -47,7 +48,7 @@ I2C_CLIENT_INSMOD_1(lm75);
struct lm75_data { struct lm75_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* !=0 if following fields are valid */ char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
u16 temp_input; /* Register values */ u16 temp_input; /* Register values */
...@@ -91,10 +92,10 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co ...@@ -91,10 +92,10 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co
struct lm75_data *data = i2c_get_clientdata(client); \ struct lm75_data *data = i2c_get_clientdata(client); \
int temp = simple_strtoul(buf, NULL, 10); \ int temp = simple_strtoul(buf, NULL, 10); \
\ \
down(&data->update_lock); \ mutex_lock(&data->update_lock); \
data->value = LM75_TEMP_TO_REG(temp); \ data->value = LM75_TEMP_TO_REG(temp); \
lm75_write_value(client, reg, data->value); \ lm75_write_value(client, reg, data->value); \
up(&data->update_lock); \ mutex_unlock(&data->update_lock); \
return count; \ return count; \
} }
set(temp_max, LM75_REG_TEMP_OS); set(temp_max, LM75_REG_TEMP_OS);
...@@ -188,7 +189,7 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -188,7 +189,7 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
/* Fill in the remaining client fields and put it into the global list */ /* Fill in the remaining client fields and put it into the global list */
strlcpy(new_client->name, name, I2C_NAME_SIZE); strlcpy(new_client->name, name, I2C_NAME_SIZE);
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
...@@ -264,7 +265,7 @@ static struct lm75_data *lm75_update_device(struct device *dev) ...@@ -264,7 +265,7 @@ static struct lm75_data *lm75_update_device(struct device *dev)
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct lm75_data *data = i2c_get_clientdata(client); struct lm75_data *data = i2c_get_clientdata(client);
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ + HZ / 2) if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|| !data->valid) { || !data->valid) {
...@@ -277,7 +278,7 @@ static struct lm75_data *lm75_update_device(struct device *dev) ...@@ -277,7 +278,7 @@ static struct lm75_data *lm75_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
/* Addresses to scan */ /* Addresses to scan */
static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, I2C_CLIENT_END }; static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, I2C_CLIENT_END };
...@@ -51,7 +52,7 @@ I2C_CLIENT_INSMOD_1(lm77); ...@@ -51,7 +52,7 @@ I2C_CLIENT_INSMOD_1(lm77);
struct lm77_data { struct lm77_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore update_lock; struct mutex update_lock;
char valid; char valid;
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
int temp_input; /* Temperatures */ int temp_input; /* Temperatures */
...@@ -139,10 +140,10 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co ...@@ -139,10 +140,10 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co
struct lm77_data *data = i2c_get_clientdata(client); \ struct lm77_data *data = i2c_get_clientdata(client); \
long val = simple_strtoul(buf, NULL, 10); \ long val = simple_strtoul(buf, NULL, 10); \
\ \
down(&data->update_lock); \ mutex_lock(&data->update_lock); \
data->value = val; \ data->value = val; \
lm77_write_value(client, reg, LM77_TEMP_TO_REG(data->value)); \ lm77_write_value(client, reg, LM77_TEMP_TO_REG(data->value)); \
up(&data->update_lock); \ mutex_unlock(&data->update_lock); \
return count; \ return count; \
} }
...@@ -157,11 +158,11 @@ static ssize_t set_temp_crit_hyst(struct device *dev, struct device_attribute *a ...@@ -157,11 +158,11 @@ static ssize_t set_temp_crit_hyst(struct device *dev, struct device_attribute *a
struct lm77_data *data = i2c_get_clientdata(client); struct lm77_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_hyst = data->temp_crit - val; data->temp_hyst = data->temp_crit - val;
lm77_write_value(client, LM77_REG_TEMP_HYST, lm77_write_value(client, LM77_REG_TEMP_HYST,
LM77_TEMP_TO_REG(data->temp_hyst)); LM77_TEMP_TO_REG(data->temp_hyst));
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -173,7 +174,7 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr, ...@@ -173,7 +174,7 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
long val = simple_strtoul(buf, NULL, 10); long val = simple_strtoul(buf, NULL, 10);
int oldcrithyst; int oldcrithyst;
down(&data->update_lock); mutex_lock(&data->update_lock);
oldcrithyst = data->temp_crit - data->temp_hyst; oldcrithyst = data->temp_crit - data->temp_hyst;
data->temp_crit = val; data->temp_crit = val;
data->temp_hyst = data->temp_crit - oldcrithyst; data->temp_hyst = data->temp_crit - oldcrithyst;
...@@ -181,7 +182,7 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr, ...@@ -181,7 +182,7 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
LM77_TEMP_TO_REG(data->temp_crit)); LM77_TEMP_TO_REG(data->temp_crit));
lm77_write_value(client, LM77_REG_TEMP_HYST, lm77_write_value(client, LM77_REG_TEMP_HYST,
LM77_TEMP_TO_REG(data->temp_hyst)); LM77_TEMP_TO_REG(data->temp_hyst));
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -306,7 +307,7 @@ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -306,7 +307,7 @@ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind)
/* Fill in the remaining client fields and put it into the global list */ /* Fill in the remaining client fields and put it into the global list */
strlcpy(new_client->name, name, I2C_NAME_SIZE); strlcpy(new_client->name, name, I2C_NAME_SIZE);
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
...@@ -380,7 +381,7 @@ static struct lm77_data *lm77_update_device(struct device *dev) ...@@ -380,7 +381,7 @@ static struct lm77_data *lm77_update_device(struct device *dev)
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct lm77_data *data = i2c_get_clientdata(client); struct lm77_data *data = i2c_get_clientdata(client);
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ + HZ / 2) if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|| !data->valid) { || !data->valid) {
...@@ -406,7 +407,7 @@ static struct lm77_data *lm77_update_device(struct device *dev) ...@@ -406,7 +407,7 @@ static struct lm77_data *lm77_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/hwmon-vid.h> #include <linux/hwmon-vid.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
#include <asm/io.h> #include <asm/io.h>
/* Addresses to scan */ /* Addresses to scan */
...@@ -131,10 +132,10 @@ static inline int TEMP_FROM_REG(s8 val) ...@@ -131,10 +132,10 @@ static inline int TEMP_FROM_REG(s8 val)
struct lm78_data { struct lm78_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore lock; struct mutex lock;
enum chips type; enum chips type;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* !=0 if following fields are valid */ char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
...@@ -207,10 +208,10 @@ static ssize_t set_in_min(struct device *dev, const char *buf, ...@@ -207,10 +208,10 @@ static ssize_t set_in_min(struct device *dev, const char *buf,
struct lm78_data *data = i2c_get_clientdata(client); struct lm78_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_min[nr] = IN_TO_REG(val); data->in_min[nr] = IN_TO_REG(val);
lm78_write_value(client, LM78_REG_IN_MIN(nr), data->in_min[nr]); lm78_write_value(client, LM78_REG_IN_MIN(nr), data->in_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -221,10 +222,10 @@ static ssize_t set_in_max(struct device *dev, const char *buf, ...@@ -221,10 +222,10 @@ static ssize_t set_in_max(struct device *dev, const char *buf,
struct lm78_data *data = i2c_get_clientdata(client); struct lm78_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_max[nr] = IN_TO_REG(val); data->in_max[nr] = IN_TO_REG(val);
lm78_write_value(client, LM78_REG_IN_MAX(nr), data->in_max[nr]); lm78_write_value(client, LM78_REG_IN_MAX(nr), data->in_max[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -288,10 +289,10 @@ static ssize_t set_temp_over(struct device *dev, struct device_attribute *attr, ...@@ -288,10 +289,10 @@ static ssize_t set_temp_over(struct device *dev, struct device_attribute *attr,
struct lm78_data *data = i2c_get_clientdata(client); struct lm78_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_over = TEMP_TO_REG(val); data->temp_over = TEMP_TO_REG(val);
lm78_write_value(client, LM78_REG_TEMP_OVER, data->temp_over); lm78_write_value(client, LM78_REG_TEMP_OVER, data->temp_over);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -307,10 +308,10 @@ static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *attr, ...@@ -307,10 +308,10 @@ static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *attr,
struct lm78_data *data = i2c_get_clientdata(client); struct lm78_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_hyst = TEMP_TO_REG(val); data->temp_hyst = TEMP_TO_REG(val);
lm78_write_value(client, LM78_REG_TEMP_HYST, data->temp_hyst); lm78_write_value(client, LM78_REG_TEMP_HYST, data->temp_hyst);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -342,10 +343,10 @@ static ssize_t set_fan_min(struct device *dev, const char *buf, ...@@ -342,10 +343,10 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
struct lm78_data *data = i2c_get_clientdata(client); struct lm78_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
lm78_write_value(client, LM78_REG_FAN_MIN(nr), data->fan_min[nr]); lm78_write_value(client, LM78_REG_FAN_MIN(nr), data->fan_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -368,7 +369,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, ...@@ -368,7 +369,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
unsigned long min; unsigned long min;
u8 reg; u8 reg;
down(&data->update_lock); mutex_lock(&data->update_lock);
min = FAN_FROM_REG(data->fan_min[nr], min = FAN_FROM_REG(data->fan_min[nr],
DIV_FROM_REG(data->fan_div[nr])); DIV_FROM_REG(data->fan_div[nr]));
...@@ -380,7 +381,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, ...@@ -380,7 +381,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
default: default:
dev_err(&client->dev, "fan_div value %ld not " dev_err(&client->dev, "fan_div value %ld not "
"supported. Choose one of 1, 2, 4 or 8!\n", val); "supported. Choose one of 1, 2, 4 or 8!\n", val);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return -EINVAL; return -EINVAL;
} }
...@@ -398,7 +399,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, ...@@ -398,7 +399,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
data->fan_min[nr] = data->fan_min[nr] =
FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
lm78_write_value(client, LM78_REG_FAN_MIN(nr), data->fan_min[nr]); lm78_write_value(client, LM78_REG_FAN_MIN(nr), data->fan_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -548,7 +549,7 @@ static int lm78_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -548,7 +549,7 @@ static int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
new_client = &data->client; new_client = &data->client;
if (is_isa) if (is_isa)
init_MUTEX(&data->lock); mutex_init(&data->lock);
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
new_client->adapter = adapter; new_client->adapter = adapter;
...@@ -598,7 +599,7 @@ static int lm78_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -598,7 +599,7 @@ static int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
data->type = kind; data->type = kind;
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
...@@ -697,10 +698,10 @@ static int lm78_read_value(struct i2c_client *client, u8 reg) ...@@ -697,10 +698,10 @@ static int lm78_read_value(struct i2c_client *client, u8 reg)
int res; int res;
if (i2c_is_isa_client(client)) { if (i2c_is_isa_client(client)) {
struct lm78_data *data = i2c_get_clientdata(client); struct lm78_data *data = i2c_get_clientdata(client);
down(&data->lock); mutex_lock(&data->lock);
outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET); outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET);
res = inb_p(client->addr + LM78_DATA_REG_OFFSET); res = inb_p(client->addr + LM78_DATA_REG_OFFSET);
up(&data->lock); mutex_unlock(&data->lock);
return res; return res;
} else } else
return i2c_smbus_read_byte_data(client, reg); return i2c_smbus_read_byte_data(client, reg);
...@@ -717,10 +718,10 @@ static int lm78_write_value(struct i2c_client *client, u8 reg, u8 value) ...@@ -717,10 +718,10 @@ static int lm78_write_value(struct i2c_client *client, u8 reg, u8 value)
{ {
if (i2c_is_isa_client(client)) { if (i2c_is_isa_client(client)) {
struct lm78_data *data = i2c_get_clientdata(client); struct lm78_data *data = i2c_get_clientdata(client);
down(&data->lock); mutex_lock(&data->lock);
outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET); outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET);
outb_p(value, client->addr + LM78_DATA_REG_OFFSET); outb_p(value, client->addr + LM78_DATA_REG_OFFSET);
up(&data->lock); mutex_unlock(&data->lock);
return 0; return 0;
} else } else
return i2c_smbus_write_byte_data(client, reg, value); return i2c_smbus_write_byte_data(client, reg, value);
...@@ -742,7 +743,7 @@ static struct lm78_data *lm78_update_device(struct device *dev) ...@@ -742,7 +743,7 @@ static struct lm78_data *lm78_update_device(struct device *dev)
struct lm78_data *data = i2c_get_clientdata(client); struct lm78_data *data = i2c_get_clientdata(client);
int i; int i;
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ + HZ / 2) if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|| !data->valid) { || !data->valid) {
...@@ -786,7 +787,7 @@ static struct lm78_data *lm78_update_device(struct device *dev) ...@@ -786,7 +787,7 @@ static struct lm78_data *lm78_update_device(struct device *dev)
data->fan_div[2] = 1; data->fan_div[2] = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
/* Addresses to scan */ /* Addresses to scan */
static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c,
...@@ -108,7 +109,7 @@ static inline long TEMP_FROM_REG(u16 temp) ...@@ -108,7 +109,7 @@ static inline long TEMP_FROM_REG(u16 temp)
struct lm80_data { struct lm80_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* !=0 if following fields are valid */ char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
...@@ -191,10 +192,10 @@ static ssize_t set_in_##suffix(struct device *dev, struct device_attribute *attr ...@@ -191,10 +192,10 @@ static ssize_t set_in_##suffix(struct device *dev, struct device_attribute *attr
struct lm80_data *data = i2c_get_clientdata(client); \ struct lm80_data *data = i2c_get_clientdata(client); \
long val = simple_strtol(buf, NULL, 10); \ long val = simple_strtol(buf, NULL, 10); \
\ \
down(&data->update_lock);\ mutex_lock(&data->update_lock);\
data->value = IN_TO_REG(val); \ data->value = IN_TO_REG(val); \
lm80_write_value(client, reg, data->value); \ lm80_write_value(client, reg, data->value); \
up(&data->update_lock);\ mutex_unlock(&data->update_lock);\
return count; \ return count; \
} }
set_in(min0, in_min[0], LM80_REG_IN_MIN(0)); set_in(min0, in_min[0], LM80_REG_IN_MIN(0));
...@@ -241,10 +242,10 @@ static ssize_t set_fan_##suffix(struct device *dev, struct device_attribute *att ...@@ -241,10 +242,10 @@ static ssize_t set_fan_##suffix(struct device *dev, struct device_attribute *att
struct lm80_data *data = i2c_get_clientdata(client); \ struct lm80_data *data = i2c_get_clientdata(client); \
long val = simple_strtoul(buf, NULL, 10); \ long val = simple_strtoul(buf, NULL, 10); \
\ \
down(&data->update_lock);\ mutex_lock(&data->update_lock);\
data->value = FAN_TO_REG(val, DIV_FROM_REG(data->div)); \ data->value = FAN_TO_REG(val, DIV_FROM_REG(data->div)); \
lm80_write_value(client, reg, data->value); \ lm80_write_value(client, reg, data->value); \
up(&data->update_lock);\ mutex_unlock(&data->update_lock);\
return count; \ return count; \
} }
set_fan(min1, fan_min[0], LM80_REG_FAN_MIN(1), fan_div[0]); set_fan(min1, fan_min[0], LM80_REG_FAN_MIN(1), fan_div[0]);
...@@ -263,7 +264,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, ...@@ -263,7 +264,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
u8 reg; u8 reg;
/* Save fan_min */ /* Save fan_min */
down(&data->update_lock); mutex_lock(&data->update_lock);
min = FAN_FROM_REG(data->fan_min[nr], min = FAN_FROM_REG(data->fan_min[nr],
DIV_FROM_REG(data->fan_div[nr])); DIV_FROM_REG(data->fan_div[nr]));
...@@ -275,7 +276,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, ...@@ -275,7 +276,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
default: default:
dev_err(&client->dev, "fan_div value %ld not " dev_err(&client->dev, "fan_div value %ld not "
"supported. Choose one of 1, 2, 4 or 8!\n", val); "supported. Choose one of 1, 2, 4 or 8!\n", val);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return -EINVAL; return -EINVAL;
} }
...@@ -286,7 +287,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, ...@@ -286,7 +287,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
/* Restore fan_min */ /* Restore fan_min */
data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
lm80_write_value(client, LM80_REG_FAN_MIN(nr + 1), data->fan_min[nr]); lm80_write_value(client, LM80_REG_FAN_MIN(nr + 1), data->fan_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -325,10 +326,10 @@ static ssize_t set_temp_##suffix(struct device *dev, struct device_attribute *at ...@@ -325,10 +326,10 @@ static ssize_t set_temp_##suffix(struct device *dev, struct device_attribute *at
struct lm80_data *data = i2c_get_clientdata(client); \ struct lm80_data *data = i2c_get_clientdata(client); \
long val = simple_strtoul(buf, NULL, 10); \ long val = simple_strtoul(buf, NULL, 10); \
\ \
down(&data->update_lock); \ mutex_lock(&data->update_lock); \
data->value = TEMP_LIMIT_TO_REG(val); \ data->value = TEMP_LIMIT_TO_REG(val); \
lm80_write_value(client, reg, data->value); \ lm80_write_value(client, reg, data->value); \
up(&data->update_lock); \ mutex_unlock(&data->update_lock); \
return count; \ return count; \
} }
set_temp(hot_max, temp_hot_max, LM80_REG_TEMP_HOT_MAX); set_temp(hot_max, temp_hot_max, LM80_REG_TEMP_HOT_MAX);
...@@ -437,7 +438,7 @@ static int lm80_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -437,7 +438,7 @@ static int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
/* Fill in the remaining client fields and put it into the global list */ /* Fill in the remaining client fields and put it into the global list */
strlcpy(new_client->name, name, I2C_NAME_SIZE); strlcpy(new_client->name, name, I2C_NAME_SIZE);
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
...@@ -545,7 +546,7 @@ static struct lm80_data *lm80_update_device(struct device *dev) ...@@ -545,7 +546,7 @@ static struct lm80_data *lm80_update_device(struct device *dev)
struct lm80_data *data = i2c_get_clientdata(client); struct lm80_data *data = i2c_get_clientdata(client);
int i; int i;
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) { if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
dev_dbg(&client->dev, "Starting lm80 update\n"); dev_dbg(&client->dev, "Starting lm80 update\n");
...@@ -585,7 +586,7 @@ static struct lm80_data *lm80_update_device(struct device *dev) ...@@ -585,7 +586,7 @@ static struct lm80_data *lm80_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <linux/hwmon-sysfs.h> #include <linux/hwmon-sysfs.h>
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
/* /*
* Addresses to scan * Addresses to scan
...@@ -139,7 +140,7 @@ static struct i2c_driver lm83_driver = { ...@@ -139,7 +140,7 @@ static struct i2c_driver lm83_driver = {
struct lm83_data { struct lm83_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* zero until following fields are valid */ char valid; /* zero until following fields are valid */
unsigned long last_updated; /* in jiffies */ unsigned long last_updated; /* in jiffies */
...@@ -171,11 +172,11 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *devattr, ...@@ -171,11 +172,11 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *devattr,
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
int nr = attr->index; int nr = attr->index;
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp[nr] = TEMP_TO_REG(val); data->temp[nr] = TEMP_TO_REG(val);
i2c_smbus_write_byte_data(client, LM83_REG_W_HIGH[nr - 4], i2c_smbus_write_byte_data(client, LM83_REG_W_HIGH[nr - 4],
data->temp[nr]); data->temp[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -300,7 +301,7 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -300,7 +301,7 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind)
/* We can fill in the remaining client fields */ /* We can fill in the remaining client fields */
strlcpy(new_client->name, name, I2C_NAME_SIZE); strlcpy(new_client->name, name, I2C_NAME_SIZE);
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
...@@ -373,7 +374,7 @@ static struct lm83_data *lm83_update_device(struct device *dev) ...@@ -373,7 +374,7 @@ static struct lm83_data *lm83_update_device(struct device *dev)
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct lm83_data *data = i2c_get_clientdata(client); struct lm83_data *data = i2c_get_clientdata(client);
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
int nr; int nr;
...@@ -393,7 +394,7 @@ static struct lm83_data *lm83_update_device(struct device *dev) ...@@ -393,7 +394,7 @@ static struct lm83_data *lm83_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/hwmon-vid.h> #include <linux/hwmon-vid.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
/* Addresses to scan */ /* Addresses to scan */
static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
...@@ -331,10 +332,10 @@ struct lm85_autofan { ...@@ -331,10 +332,10 @@ struct lm85_autofan {
struct lm85_data { struct lm85_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore lock; struct mutex lock;
enum chips type; enum chips type;
struct semaphore update_lock; struct mutex update_lock;
int valid; /* !=0 if following fields are valid */ int valid; /* !=0 if following fields are valid */
unsigned long last_reading; /* In jiffies */ unsigned long last_reading; /* In jiffies */
unsigned long last_config; /* In jiffies */ unsigned long last_config; /* In jiffies */
...@@ -407,10 +408,10 @@ static ssize_t set_fan_min(struct device *dev, const char *buf, ...@@ -407,10 +408,10 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
struct lm85_data *data = i2c_get_clientdata(client); struct lm85_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->fan_min[nr] = FAN_TO_REG(val); data->fan_min[nr] = FAN_TO_REG(val);
lm85_write_value(client, LM85_REG_FAN_MIN(nr), data->fan_min[nr]); lm85_write_value(client, LM85_REG_FAN_MIN(nr), data->fan_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -499,10 +500,10 @@ static ssize_t set_pwm(struct device *dev, const char *buf, ...@@ -499,10 +500,10 @@ static ssize_t set_pwm(struct device *dev, const char *buf,
struct lm85_data *data = i2c_get_clientdata(client); struct lm85_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->pwm[nr] = PWM_TO_REG(val); data->pwm[nr] = PWM_TO_REG(val);
lm85_write_value(client, LM85_REG_PWM(nr), data->pwm[nr]); lm85_write_value(client, LM85_REG_PWM(nr), data->pwm[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t show_pwm_enable(struct device *dev, char *buf, int nr) static ssize_t show_pwm_enable(struct device *dev, char *buf, int nr)
...@@ -559,10 +560,10 @@ static ssize_t set_in_min(struct device *dev, const char *buf, ...@@ -559,10 +560,10 @@ static ssize_t set_in_min(struct device *dev, const char *buf,
struct lm85_data *data = i2c_get_clientdata(client); struct lm85_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_min[nr] = INS_TO_REG(nr, val); data->in_min[nr] = INS_TO_REG(nr, val);
lm85_write_value(client, LM85_REG_IN_MIN(nr), data->in_min[nr]); lm85_write_value(client, LM85_REG_IN_MIN(nr), data->in_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t show_in_max(struct device *dev, char *buf, int nr) static ssize_t show_in_max(struct device *dev, char *buf, int nr)
...@@ -577,10 +578,10 @@ static ssize_t set_in_max(struct device *dev, const char *buf, ...@@ -577,10 +578,10 @@ static ssize_t set_in_max(struct device *dev, const char *buf,
struct lm85_data *data = i2c_get_clientdata(client); struct lm85_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_max[nr] = INS_TO_REG(nr, val); data->in_max[nr] = INS_TO_REG(nr, val);
lm85_write_value(client, LM85_REG_IN_MAX(nr), data->in_max[nr]); lm85_write_value(client, LM85_REG_IN_MAX(nr), data->in_max[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
#define show_in_reg(offset) \ #define show_in_reg(offset) \
...@@ -640,10 +641,10 @@ static ssize_t set_temp_min(struct device *dev, const char *buf, ...@@ -640,10 +641,10 @@ static ssize_t set_temp_min(struct device *dev, const char *buf,
struct lm85_data *data = i2c_get_clientdata(client); struct lm85_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_min[nr] = TEMP_TO_REG(val); data->temp_min[nr] = TEMP_TO_REG(val);
lm85_write_value(client, LM85_REG_TEMP_MIN(nr), data->temp_min[nr]); lm85_write_value(client, LM85_REG_TEMP_MIN(nr), data->temp_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t show_temp_max(struct device *dev, char *buf, int nr) static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
...@@ -658,10 +659,10 @@ static ssize_t set_temp_max(struct device *dev, const char *buf, ...@@ -658,10 +659,10 @@ static ssize_t set_temp_max(struct device *dev, const char *buf,
struct lm85_data *data = i2c_get_clientdata(client); struct lm85_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_max[nr] = TEMP_TO_REG(val); data->temp_max[nr] = TEMP_TO_REG(val);
lm85_write_value(client, LM85_REG_TEMP_MAX(nr), data->temp_max[nr]); lm85_write_value(client, LM85_REG_TEMP_MAX(nr), data->temp_max[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
#define show_temp_reg(offset) \ #define show_temp_reg(offset) \
...@@ -713,12 +714,12 @@ static ssize_t set_pwm_auto_channels(struct device *dev, const char *buf, ...@@ -713,12 +714,12 @@ static ssize_t set_pwm_auto_channels(struct device *dev, const char *buf,
struct lm85_data *data = i2c_get_clientdata(client); struct lm85_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->autofan[nr].config = (data->autofan[nr].config & (~0xe0)) data->autofan[nr].config = (data->autofan[nr].config & (~0xe0))
| ZONE_TO_REG(val) ; | ZONE_TO_REG(val) ;
lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr), lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr),
data->autofan[nr].config); data->autofan[nr].config);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t show_pwm_auto_pwm_min(struct device *dev, char *buf, int nr) static ssize_t show_pwm_auto_pwm_min(struct device *dev, char *buf, int nr)
...@@ -733,11 +734,11 @@ static ssize_t set_pwm_auto_pwm_min(struct device *dev, const char *buf, ...@@ -733,11 +734,11 @@ static ssize_t set_pwm_auto_pwm_min(struct device *dev, const char *buf,
struct lm85_data *data = i2c_get_clientdata(client); struct lm85_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->autofan[nr].min_pwm = PWM_TO_REG(val); data->autofan[nr].min_pwm = PWM_TO_REG(val);
lm85_write_value(client, LM85_REG_AFAN_MINPWM(nr), lm85_write_value(client, LM85_REG_AFAN_MINPWM(nr),
data->autofan[nr].min_pwm); data->autofan[nr].min_pwm);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t show_pwm_auto_pwm_minctl(struct device *dev, char *buf, int nr) static ssize_t show_pwm_auto_pwm_minctl(struct device *dev, char *buf, int nr)
...@@ -752,7 +753,7 @@ static ssize_t set_pwm_auto_pwm_minctl(struct device *dev, const char *buf, ...@@ -752,7 +753,7 @@ static ssize_t set_pwm_auto_pwm_minctl(struct device *dev, const char *buf,
struct lm85_data *data = i2c_get_clientdata(client); struct lm85_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->autofan[nr].min_off = val; data->autofan[nr].min_off = val;
lm85_write_value(client, LM85_REG_AFAN_SPIKE1, data->smooth[0] lm85_write_value(client, LM85_REG_AFAN_SPIKE1, data->smooth[0]
| data->syncpwm3 | data->syncpwm3
...@@ -760,7 +761,7 @@ static ssize_t set_pwm_auto_pwm_minctl(struct device *dev, const char *buf, ...@@ -760,7 +761,7 @@ static ssize_t set_pwm_auto_pwm_minctl(struct device *dev, const char *buf,
| (data->autofan[1].min_off ? 0x40 : 0) | (data->autofan[1].min_off ? 0x40 : 0)
| (data->autofan[2].min_off ? 0x80 : 0) | (data->autofan[2].min_off ? 0x80 : 0)
); );
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t show_pwm_auto_pwm_freq(struct device *dev, char *buf, int nr) static ssize_t show_pwm_auto_pwm_freq(struct device *dev, char *buf, int nr)
...@@ -775,13 +776,13 @@ static ssize_t set_pwm_auto_pwm_freq(struct device *dev, const char *buf, ...@@ -775,13 +776,13 @@ static ssize_t set_pwm_auto_pwm_freq(struct device *dev, const char *buf,
struct lm85_data *data = i2c_get_clientdata(client); struct lm85_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->autofan[nr].freq = FREQ_TO_REG(val); data->autofan[nr].freq = FREQ_TO_REG(val);
lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
(data->zone[nr].range << 4) (data->zone[nr].range << 4)
| data->autofan[nr].freq | data->autofan[nr].freq
); );
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
#define pwm_auto(offset) \ #define pwm_auto(offset) \
...@@ -857,7 +858,7 @@ static ssize_t set_temp_auto_temp_off(struct device *dev, const char *buf, ...@@ -857,7 +858,7 @@ static ssize_t set_temp_auto_temp_off(struct device *dev, const char *buf,
int min; int min;
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
min = TEMP_FROM_REG(data->zone[nr].limit); min = TEMP_FROM_REG(data->zone[nr].limit);
data->zone[nr].off_desired = TEMP_TO_REG(val); data->zone[nr].off_desired = TEMP_TO_REG(val);
data->zone[nr].hyst = HYST_TO_REG(min - val); data->zone[nr].hyst = HYST_TO_REG(min - val);
...@@ -871,7 +872,7 @@ static ssize_t set_temp_auto_temp_off(struct device *dev, const char *buf, ...@@ -871,7 +872,7 @@ static ssize_t set_temp_auto_temp_off(struct device *dev, const char *buf,
(data->zone[2].hyst << 4) (data->zone[2].hyst << 4)
); );
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t show_temp_auto_temp_min(struct device *dev, char *buf, int nr) static ssize_t show_temp_auto_temp_min(struct device *dev, char *buf, int nr)
...@@ -886,7 +887,7 @@ static ssize_t set_temp_auto_temp_min(struct device *dev, const char *buf, ...@@ -886,7 +887,7 @@ static ssize_t set_temp_auto_temp_min(struct device *dev, const char *buf,
struct lm85_data *data = i2c_get_clientdata(client); struct lm85_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->zone[nr].limit = TEMP_TO_REG(val); data->zone[nr].limit = TEMP_TO_REG(val);
lm85_write_value(client, LM85_REG_AFAN_LIMIT(nr), lm85_write_value(client, LM85_REG_AFAN_LIMIT(nr),
data->zone[nr].limit); data->zone[nr].limit);
...@@ -913,7 +914,7 @@ static ssize_t set_temp_auto_temp_min(struct device *dev, const char *buf, ...@@ -913,7 +914,7 @@ static ssize_t set_temp_auto_temp_min(struct device *dev, const char *buf,
(data->zone[2].hyst << 4) (data->zone[2].hyst << 4)
); );
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t show_temp_auto_temp_max(struct device *dev, char *buf, int nr) static ssize_t show_temp_auto_temp_max(struct device *dev, char *buf, int nr)
...@@ -930,7 +931,7 @@ static ssize_t set_temp_auto_temp_max(struct device *dev, const char *buf, ...@@ -930,7 +931,7 @@ static ssize_t set_temp_auto_temp_max(struct device *dev, const char *buf,
int min; int min;
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
min = TEMP_FROM_REG(data->zone[nr].limit); min = TEMP_FROM_REG(data->zone[nr].limit);
data->zone[nr].max_desired = TEMP_TO_REG(val); data->zone[nr].max_desired = TEMP_TO_REG(val);
data->zone[nr].range = RANGE_TO_REG( data->zone[nr].range = RANGE_TO_REG(
...@@ -938,7 +939,7 @@ static ssize_t set_temp_auto_temp_max(struct device *dev, const char *buf, ...@@ -938,7 +939,7 @@ static ssize_t set_temp_auto_temp_max(struct device *dev, const char *buf,
lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
((data->zone[nr].range & 0x0f) << 4) ((data->zone[nr].range & 0x0f) << 4)
| (data->autofan[nr].freq & 0x07)); | (data->autofan[nr].freq & 0x07));
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t show_temp_auto_temp_crit(struct device *dev, char *buf, int nr) static ssize_t show_temp_auto_temp_crit(struct device *dev, char *buf, int nr)
...@@ -953,11 +954,11 @@ static ssize_t set_temp_auto_temp_crit(struct device *dev, const char *buf, ...@@ -953,11 +954,11 @@ static ssize_t set_temp_auto_temp_crit(struct device *dev, const char *buf,
struct lm85_data *data = i2c_get_clientdata(client); struct lm85_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->zone[nr].critical = TEMP_TO_REG(val); data->zone[nr].critical = TEMP_TO_REG(val);
lm85_write_value(client, LM85_REG_AFAN_CRITICAL(nr), lm85_write_value(client, LM85_REG_AFAN_CRITICAL(nr),
data->zone[nr].critical); data->zone[nr].critical);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
#define temp_auto(offset) \ #define temp_auto(offset) \
...@@ -1149,7 +1150,7 @@ static int lm85_detect(struct i2c_adapter *adapter, int address, ...@@ -1149,7 +1150,7 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
/* Fill in the remaining client fields */ /* Fill in the remaining client fields */
data->type = kind; data->type = kind;
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
...@@ -1368,7 +1369,7 @@ static struct lm85_data *lm85_update_device(struct device *dev) ...@@ -1368,7 +1369,7 @@ static struct lm85_data *lm85_update_device(struct device *dev)
struct lm85_data *data = i2c_get_clientdata(client); struct lm85_data *data = i2c_get_clientdata(client);
int i; int i;
down(&data->update_lock); mutex_lock(&data->update_lock);
if ( !data->valid || if ( !data->valid ||
time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL) ) { time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL) ) {
...@@ -1571,7 +1572,7 @@ static struct lm85_data *lm85_update_device(struct device *dev) ...@@ -1571,7 +1572,7 @@ static struct lm85_data *lm85_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -60,6 +60,7 @@ ...@@ -60,6 +60,7 @@
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/hwmon-vid.h> #include <linux/hwmon-vid.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
/* /*
* Addresses to scan * Addresses to scan
...@@ -176,7 +177,7 @@ static struct i2c_driver lm87_driver = { ...@@ -176,7 +177,7 @@ static struct i2c_driver lm87_driver = {
struct lm87_data { struct lm87_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* zero until following fields are valid */ char valid; /* zero until following fields are valid */
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
...@@ -253,11 +254,11 @@ static void set_in_min(struct device *dev, const char *buf, int nr) ...@@ -253,11 +254,11 @@ static void set_in_min(struct device *dev, const char *buf, int nr)
struct lm87_data *data = i2c_get_clientdata(client); struct lm87_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_min[nr] = IN_TO_REG(val, data->in_scale[nr]); data->in_min[nr] = IN_TO_REG(val, data->in_scale[nr]);
lm87_write_value(client, nr<6 ? LM87_REG_IN_MIN(nr) : lm87_write_value(client, nr<6 ? LM87_REG_IN_MIN(nr) :
LM87_REG_AIN_MIN(nr-6), data->in_min[nr]); LM87_REG_AIN_MIN(nr-6), data->in_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
} }
static void set_in_max(struct device *dev, const char *buf, int nr) static void set_in_max(struct device *dev, const char *buf, int nr)
...@@ -266,11 +267,11 @@ static void set_in_max(struct device *dev, const char *buf, int nr) ...@@ -266,11 +267,11 @@ static void set_in_max(struct device *dev, const char *buf, int nr)
struct lm87_data *data = i2c_get_clientdata(client); struct lm87_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_max[nr] = IN_TO_REG(val, data->in_scale[nr]); data->in_max[nr] = IN_TO_REG(val, data->in_scale[nr]);
lm87_write_value(client, nr<6 ? LM87_REG_IN_MAX(nr) : lm87_write_value(client, nr<6 ? LM87_REG_IN_MAX(nr) :
LM87_REG_AIN_MAX(nr-6), data->in_max[nr]); LM87_REG_AIN_MAX(nr-6), data->in_max[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
} }
#define set_in(offset) \ #define set_in(offset) \
...@@ -327,10 +328,10 @@ static void set_temp_low(struct device *dev, const char *buf, int nr) ...@@ -327,10 +328,10 @@ static void set_temp_low(struct device *dev, const char *buf, int nr)
struct lm87_data *data = i2c_get_clientdata(client); struct lm87_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_low[nr] = TEMP_TO_REG(val); data->temp_low[nr] = TEMP_TO_REG(val);
lm87_write_value(client, LM87_REG_TEMP_LOW[nr], data->temp_low[nr]); lm87_write_value(client, LM87_REG_TEMP_LOW[nr], data->temp_low[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
} }
static void set_temp_high(struct device *dev, const char *buf, int nr) static void set_temp_high(struct device *dev, const char *buf, int nr)
...@@ -339,10 +340,10 @@ static void set_temp_high(struct device *dev, const char *buf, int nr) ...@@ -339,10 +340,10 @@ static void set_temp_high(struct device *dev, const char *buf, int nr)
struct lm87_data *data = i2c_get_clientdata(client); struct lm87_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_high[nr] = TEMP_TO_REG(val); data->temp_high[nr] = TEMP_TO_REG(val);
lm87_write_value(client, LM87_REG_TEMP_HIGH[nr], data->temp_high[nr]); lm87_write_value(client, LM87_REG_TEMP_HIGH[nr], data->temp_high[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
} }
#define set_temp(offset) \ #define set_temp(offset) \
...@@ -411,11 +412,11 @@ static void set_fan_min(struct device *dev, const char *buf, int nr) ...@@ -411,11 +412,11 @@ static void set_fan_min(struct device *dev, const char *buf, int nr)
struct lm87_data *data = i2c_get_clientdata(client); struct lm87_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->fan_min[nr] = FAN_TO_REG(val, data->fan_min[nr] = FAN_TO_REG(val,
FAN_DIV_FROM_REG(data->fan_div[nr])); FAN_DIV_FROM_REG(data->fan_div[nr]));
lm87_write_value(client, LM87_REG_FAN_MIN(nr), data->fan_min[nr]); lm87_write_value(client, LM87_REG_FAN_MIN(nr), data->fan_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
} }
/* Note: we save and restore the fan minimum here, because its value is /* Note: we save and restore the fan minimum here, because its value is
...@@ -431,7 +432,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, ...@@ -431,7 +432,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
unsigned long min; unsigned long min;
u8 reg; u8 reg;
down(&data->update_lock); mutex_lock(&data->update_lock);
min = FAN_FROM_REG(data->fan_min[nr], min = FAN_FROM_REG(data->fan_min[nr],
FAN_DIV_FROM_REG(data->fan_div[nr])); FAN_DIV_FROM_REG(data->fan_div[nr]));
...@@ -441,7 +442,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, ...@@ -441,7 +442,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
case 4: data->fan_div[nr] = 2; break; case 4: data->fan_div[nr] = 2; break;
case 8: data->fan_div[nr] = 3; break; case 8: data->fan_div[nr] = 3; break;
default: default:
up(&data->update_lock); mutex_unlock(&data->update_lock);
return -EINVAL; return -EINVAL;
} }
...@@ -459,7 +460,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, ...@@ -459,7 +460,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
data->fan_min[nr] = FAN_TO_REG(min, val); data->fan_min[nr] = FAN_TO_REG(min, val);
lm87_write_value(client, LM87_REG_FAN_MIN(nr), lm87_write_value(client, LM87_REG_FAN_MIN(nr),
data->fan_min[nr]); data->fan_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -522,10 +523,10 @@ static ssize_t set_aout(struct device *dev, struct device_attribute *attr, const ...@@ -522,10 +523,10 @@ static ssize_t set_aout(struct device *dev, struct device_attribute *attr, const
struct lm87_data *data = i2c_get_clientdata(client); struct lm87_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->aout = AOUT_TO_REG(val); data->aout = AOUT_TO_REG(val);
lm87_write_value(client, LM87_REG_AOUT, data->aout); lm87_write_value(client, LM87_REG_AOUT, data->aout);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout); static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout);
...@@ -589,7 +590,7 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -589,7 +590,7 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind)
/* We can fill in the remaining client fields */ /* We can fill in the remaining client fields */
strlcpy(new_client->name, "lm87", I2C_NAME_SIZE); strlcpy(new_client->name, "lm87", I2C_NAME_SIZE);
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
...@@ -744,7 +745,7 @@ static struct lm87_data *lm87_update_device(struct device *dev) ...@@ -744,7 +745,7 @@ static struct lm87_data *lm87_update_device(struct device *dev)
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct lm87_data *data = i2c_get_clientdata(client); struct lm87_data *data = i2c_get_clientdata(client);
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
int i, j; int i, j;
...@@ -813,7 +814,7 @@ static struct lm87_data *lm87_update_device(struct device *dev) ...@@ -813,7 +814,7 @@ static struct lm87_data *lm87_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -78,6 +78,7 @@ ...@@ -78,6 +78,7 @@
#include <linux/hwmon-sysfs.h> #include <linux/hwmon-sysfs.h>
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
/* /*
* Addresses to scan * Addresses to scan
...@@ -201,7 +202,7 @@ static struct i2c_driver lm90_driver = { ...@@ -201,7 +202,7 @@ static struct i2c_driver lm90_driver = {
struct lm90_data { struct lm90_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* zero until following fields are valid */ char valid; /* zero until following fields are valid */
unsigned long last_updated; /* in jiffies */ unsigned long last_updated; /* in jiffies */
int kind; int kind;
...@@ -247,13 +248,13 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr, ...@@ -247,13 +248,13 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
int nr = attr->index; int nr = attr->index;
down(&data->update_lock); mutex_lock(&data->update_lock);
if (data->kind == adt7461) if (data->kind == adt7461)
data->temp8[nr] = TEMP1_TO_REG_ADT7461(val); data->temp8[nr] = TEMP1_TO_REG_ADT7461(val);
else else
data->temp8[nr] = TEMP1_TO_REG(val); data->temp8[nr] = TEMP1_TO_REG(val);
i2c_smbus_write_byte_data(client, reg[nr - 1], data->temp8[nr]); i2c_smbus_write_byte_data(client, reg[nr - 1], data->temp8[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -281,7 +282,7 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, ...@@ -281,7 +282,7 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
int nr = attr->index; int nr = attr->index;
down(&data->update_lock); mutex_lock(&data->update_lock);
if (data->kind == adt7461) if (data->kind == adt7461)
data->temp11[nr] = TEMP2_TO_REG_ADT7461(val); data->temp11[nr] = TEMP2_TO_REG_ADT7461(val);
else else
...@@ -290,7 +291,7 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, ...@@ -290,7 +291,7 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
data->temp11[nr] >> 8); data->temp11[nr] >> 8);
i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1], i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1],
data->temp11[nr] & 0xff); data->temp11[nr] & 0xff);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -311,11 +312,11 @@ static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy, ...@@ -311,11 +312,11 @@ static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy,
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
long hyst; long hyst;
down(&data->update_lock); mutex_lock(&data->update_lock);
hyst = TEMP1_FROM_REG(data->temp8[3]) - val; hyst = TEMP1_FROM_REG(data->temp8[3]) - val;
i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST, i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST,
HYST_TO_REG(hyst)); HYST_TO_REG(hyst));
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -558,7 +559,7 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -558,7 +559,7 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind)
strlcpy(new_client->name, name, I2C_NAME_SIZE); strlcpy(new_client->name, name, I2C_NAME_SIZE);
data->valid = 0; data->valid = 0;
data->kind = kind; data->kind = kind;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
...@@ -646,7 +647,7 @@ static struct lm90_data *lm90_update_device(struct device *dev) ...@@ -646,7 +647,7 @@ static struct lm90_data *lm90_update_device(struct device *dev)
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct lm90_data *data = i2c_get_clientdata(client); struct lm90_data *data = i2c_get_clientdata(client);
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
u8 oldh, newh, l; u8 oldh, newh, l;
...@@ -692,7 +693,7 @@ static struct lm90_data *lm90_update_device(struct device *dev) ...@@ -692,7 +693,7 @@ static struct lm90_data *lm90_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
/* The LM92 and MAX6635 have 2 two-state pins for address selection, /* The LM92 and MAX6635 have 2 two-state pins for address selection,
resulting in 4 possible addresses. */ resulting in 4 possible addresses. */
...@@ -96,7 +97,7 @@ static struct i2c_driver lm92_driver; ...@@ -96,7 +97,7 @@ static struct i2c_driver lm92_driver;
struct lm92_data { struct lm92_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* zero until following fields are valid */ char valid; /* zero until following fields are valid */
unsigned long last_updated; /* in jiffies */ unsigned long last_updated; /* in jiffies */
...@@ -114,7 +115,7 @@ static struct lm92_data *lm92_update_device(struct device *dev) ...@@ -114,7 +115,7 @@ static struct lm92_data *lm92_update_device(struct device *dev)
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct lm92_data *data = i2c_get_clientdata(client); struct lm92_data *data = i2c_get_clientdata(client);
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ) if (time_after(jiffies, data->last_updated + HZ)
|| !data->valid) { || !data->valid) {
...@@ -134,7 +135,7 @@ static struct lm92_data *lm92_update_device(struct device *dev) ...@@ -134,7 +135,7 @@ static struct lm92_data *lm92_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
...@@ -158,10 +159,10 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co ...@@ -158,10 +159,10 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co
struct lm92_data *data = i2c_get_clientdata(client); \ struct lm92_data *data = i2c_get_clientdata(client); \
long val = simple_strtol(buf, NULL, 10); \ long val = simple_strtol(buf, NULL, 10); \
\ \
down(&data->update_lock); \ mutex_lock(&data->update_lock); \
data->value = TEMP_TO_REG(val); \ data->value = TEMP_TO_REG(val); \
i2c_smbus_write_word_data(client, reg, swab16(data->value)); \ i2c_smbus_write_word_data(client, reg, swab16(data->value)); \
up(&data->update_lock); \ mutex_unlock(&data->update_lock); \
return count; \ return count; \
} }
set_temp(temp1_crit, LM92_REG_TEMP_CRIT); set_temp(temp1_crit, LM92_REG_TEMP_CRIT);
...@@ -194,11 +195,11 @@ static ssize_t set_temp1_crit_hyst(struct device *dev, struct device_attribute * ...@@ -194,11 +195,11 @@ static ssize_t set_temp1_crit_hyst(struct device *dev, struct device_attribute *
struct lm92_data *data = i2c_get_clientdata(client); struct lm92_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp1_hyst = TEMP_FROM_REG(data->temp1_crit) - val; data->temp1_hyst = TEMP_FROM_REG(data->temp1_crit) - val;
i2c_smbus_write_word_data(client, LM92_REG_TEMP_HYST, i2c_smbus_write_word_data(client, LM92_REG_TEMP_HYST,
swab16(TEMP_TO_REG(data->temp1_hyst))); swab16(TEMP_TO_REG(data->temp1_hyst)));
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -348,7 +349,7 @@ static int lm92_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -348,7 +349,7 @@ static int lm92_detect(struct i2c_adapter *adapter, int address, int kind)
/* Fill in the remaining client fields */ /* Fill in the remaining client fields */
strlcpy(new_client->name, name, I2C_NAME_SIZE); strlcpy(new_client->name, name, I2C_NAME_SIZE);
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the i2c subsystem a new client has arrived */ /* Tell the i2c subsystem a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a, static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a,
0x29, 0x2a, 0x2b, 0x29, 0x2a, 0x2b,
...@@ -104,7 +105,7 @@ static struct i2c_driver max1619_driver = { ...@@ -104,7 +105,7 @@ static struct i2c_driver max1619_driver = {
struct max1619_data { struct max1619_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* zero until following fields are valid */ char valid; /* zero until following fields are valid */
unsigned long last_updated; /* in jiffies */ unsigned long last_updated; /* in jiffies */
...@@ -141,10 +142,10 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co ...@@ -141,10 +142,10 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co
struct max1619_data *data = i2c_get_clientdata(client); \ struct max1619_data *data = i2c_get_clientdata(client); \
long val = simple_strtol(buf, NULL, 10); \ long val = simple_strtol(buf, NULL, 10); \
\ \
down(&data->update_lock); \ mutex_lock(&data->update_lock); \
data->value = TEMP_TO_REG(val); \ data->value = TEMP_TO_REG(val); \
i2c_smbus_write_byte_data(client, reg, data->value); \ i2c_smbus_write_byte_data(client, reg, data->value); \
up(&data->update_lock); \ mutex_unlock(&data->update_lock); \
return count; \ return count; \
} }
...@@ -262,7 +263,7 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -262,7 +263,7 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind)
/* We can fill in the remaining client fields */ /* We can fill in the remaining client fields */
strlcpy(new_client->name, name, I2C_NAME_SIZE); strlcpy(new_client->name, name, I2C_NAME_SIZE);
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
...@@ -330,7 +331,7 @@ static struct max1619_data *max1619_update_device(struct device *dev) ...@@ -330,7 +331,7 @@ static struct max1619_data *max1619_update_device(struct device *dev)
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct max1619_data *data = i2c_get_clientdata(client); struct max1619_data *data = i2c_get_clientdata(client);
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
dev_dbg(&client->dev, "Updating max1619 data.\n"); dev_dbg(&client->dev, "Updating max1619 data.\n");
...@@ -353,7 +354,7 @@ static struct max1619_data *max1619_update_device(struct device *dev) ...@@ -353,7 +354,7 @@ static struct max1619_data *max1619_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include <linux/hwmon-sysfs.h> #include <linux/hwmon-sysfs.h>
#include <linux/hwmon-vid.h> #include <linux/hwmon-vid.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
#include <asm/io.h> #include <asm/io.h>
static u8 devid; static u8 devid;
...@@ -183,8 +184,8 @@ static inline u8 PWM_TO_REG(int val, int inv) ...@@ -183,8 +184,8 @@ static inline u8 PWM_TO_REG(int val, int inv)
struct pc87360_data { struct pc87360_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore lock; struct mutex lock;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* !=0 if following fields are valid */ char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
...@@ -283,7 +284,7 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr, ...@@ -283,7 +284,7 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr,
struct pc87360_data *data = i2c_get_clientdata(client); struct pc87360_data *data = i2c_get_clientdata(client);
long fan_min = simple_strtol(buf, NULL, 10); long fan_min = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
fan_min = FAN_TO_REG(fan_min, FAN_DIV_FROM_REG(data->fan_status[attr->index])); fan_min = FAN_TO_REG(fan_min, FAN_DIV_FROM_REG(data->fan_status[attr->index]));
/* If it wouldn't fit, change clock divisor */ /* If it wouldn't fit, change clock divisor */
...@@ -300,7 +301,7 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr, ...@@ -300,7 +301,7 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr,
/* Write new divider, preserve alarm bits */ /* Write new divider, preserve alarm bits */
pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_STATUS(attr->index), pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_STATUS(attr->index),
data->fan_status[attr->index] & 0xF9); data->fan_status[attr->index] & 0xF9);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -343,12 +344,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, con ...@@ -343,12 +344,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, con
struct pc87360_data *data = i2c_get_clientdata(client); struct pc87360_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->pwm[attr->index] = PWM_TO_REG(val, data->pwm[attr->index] = PWM_TO_REG(val,
FAN_CONFIG_INVERT(data->fan_conf, attr->index)); FAN_CONFIG_INVERT(data->fan_conf, attr->index));
pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_PWM(attr->index), pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_PWM(attr->index),
data->pwm[attr->index]); data->pwm[attr->index]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -393,11 +394,11 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *devattr, ...@@ -393,11 +394,11 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *devattr,
struct pc87360_data *data = i2c_get_clientdata(client); struct pc87360_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_min[attr->index] = IN_TO_REG(val, data->in_vref); data->in_min[attr->index] = IN_TO_REG(val, data->in_vref);
pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_IN_MIN, pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_IN_MIN,
data->in_min[attr->index]); data->in_min[attr->index]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t set_in_max(struct device *dev, struct device_attribute *devattr, const char *buf, static ssize_t set_in_max(struct device *dev, struct device_attribute *devattr, const char *buf,
...@@ -408,12 +409,12 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *devattr, ...@@ -408,12 +409,12 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *devattr,
struct pc87360_data *data = i2c_get_clientdata(client); struct pc87360_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_max[attr->index] = IN_TO_REG(val, data->in_max[attr->index] = IN_TO_REG(val,
data->in_vref); data->in_vref);
pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_IN_MAX, pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_IN_MAX,
data->in_max[attr->index]); data->in_max[attr->index]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -512,11 +513,11 @@ static ssize_t set_therm_min(struct device *dev, struct device_attribute *devatt ...@@ -512,11 +513,11 @@ static ssize_t set_therm_min(struct device *dev, struct device_attribute *devatt
struct pc87360_data *data = i2c_get_clientdata(client); struct pc87360_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_min[attr->index] = IN_TO_REG(val, data->in_vref); data->in_min[attr->index] = IN_TO_REG(val, data->in_vref);
pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_MIN, pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_MIN,
data->in_min[attr->index]); data->in_min[attr->index]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t set_therm_max(struct device *dev, struct device_attribute *devattr, const char *buf, static ssize_t set_therm_max(struct device *dev, struct device_attribute *devattr, const char *buf,
...@@ -527,11 +528,11 @@ static ssize_t set_therm_max(struct device *dev, struct device_attribute *devatt ...@@ -527,11 +528,11 @@ static ssize_t set_therm_max(struct device *dev, struct device_attribute *devatt
struct pc87360_data *data = i2c_get_clientdata(client); struct pc87360_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_max[attr->index] = IN_TO_REG(val, data->in_vref); data->in_max[attr->index] = IN_TO_REG(val, data->in_vref);
pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_MAX, pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_MAX,
data->in_max[attr->index]); data->in_max[attr->index]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t set_therm_crit(struct device *dev, struct device_attribute *devattr, const char *buf, static ssize_t set_therm_crit(struct device *dev, struct device_attribute *devattr, const char *buf,
...@@ -542,11 +543,11 @@ static ssize_t set_therm_crit(struct device *dev, struct device_attribute *devat ...@@ -542,11 +543,11 @@ static ssize_t set_therm_crit(struct device *dev, struct device_attribute *devat
struct pc87360_data *data = i2c_get_clientdata(client); struct pc87360_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_crit[attr->index-11] = IN_TO_REG(val, data->in_vref); data->in_crit[attr->index-11] = IN_TO_REG(val, data->in_vref);
pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_CRIT, pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_CRIT,
data->in_crit[attr->index-11]); data->in_crit[attr->index-11]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -654,11 +655,11 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *devattr ...@@ -654,11 +655,11 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *devattr
struct pc87360_data *data = i2c_get_clientdata(client); struct pc87360_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_min[attr->index] = TEMP_TO_REG(val); data->temp_min[attr->index] = TEMP_TO_REG(val);
pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_MIN, pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_MIN,
data->temp_min[attr->index]); data->temp_min[attr->index]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t set_temp_max(struct device *dev, struct device_attribute *devattr, const char *buf, static ssize_t set_temp_max(struct device *dev, struct device_attribute *devattr, const char *buf,
...@@ -669,11 +670,11 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *devattr ...@@ -669,11 +670,11 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *devattr
struct pc87360_data *data = i2c_get_clientdata(client); struct pc87360_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_max[attr->index] = TEMP_TO_REG(val); data->temp_max[attr->index] = TEMP_TO_REG(val);
pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_MAX, pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_MAX,
data->temp_max[attr->index]); data->temp_max[attr->index]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t set_temp_crit(struct device *dev, struct device_attribute *devattr, const char *buf, static ssize_t set_temp_crit(struct device *dev, struct device_attribute *devattr, const char *buf,
...@@ -684,11 +685,11 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *devatt ...@@ -684,11 +685,11 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *devatt
struct pc87360_data *data = i2c_get_clientdata(client); struct pc87360_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_crit[attr->index] = TEMP_TO_REG(val); data->temp_crit[attr->index] = TEMP_TO_REG(val);
pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_CRIT, pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_CRIT,
data->temp_crit[attr->index]); data->temp_crit[attr->index]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -845,7 +846,7 @@ static int pc87360_detect(struct i2c_adapter *adapter) ...@@ -845,7 +846,7 @@ static int pc87360_detect(struct i2c_adapter *adapter)
dev = &client->dev; dev = &client->dev;
i2c_set_clientdata(client, data); i2c_set_clientdata(client, data);
client->addr = address; client->addr = address;
init_MUTEX(&data->lock); mutex_init(&data->lock);
client->adapter = adapter; client->adapter = adapter;
client->driver = &pc87360_driver; client->driver = &pc87360_driver;
client->flags = 0; client->flags = 0;
...@@ -878,7 +879,7 @@ static int pc87360_detect(struct i2c_adapter *adapter) ...@@ -878,7 +879,7 @@ static int pc87360_detect(struct i2c_adapter *adapter)
strlcpy(client->name, name, sizeof(client->name)); strlcpy(client->name, name, sizeof(client->name));
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
if (((data->address[i] = extra_isa[i])) if (((data->address[i] = extra_isa[i]))
...@@ -1027,11 +1028,11 @@ static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank, ...@@ -1027,11 +1028,11 @@ static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank,
{ {
int res; int res;
down(&(data->lock)); mutex_lock(&(data->lock));
if (bank != NO_BANK) if (bank != NO_BANK)
outb_p(bank, data->address[ldi] + PC87365_REG_BANK); outb_p(bank, data->address[ldi] + PC87365_REG_BANK);
res = inb_p(data->address[ldi] + reg); res = inb_p(data->address[ldi] + reg);
up(&(data->lock)); mutex_unlock(&(data->lock));
return res; return res;
} }
...@@ -1039,11 +1040,11 @@ static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank, ...@@ -1039,11 +1040,11 @@ static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank,
static void pc87360_write_value(struct pc87360_data *data, u8 ldi, u8 bank, static void pc87360_write_value(struct pc87360_data *data, u8 ldi, u8 bank,
u8 reg, u8 value) u8 reg, u8 value)
{ {
down(&(data->lock)); mutex_lock(&(data->lock));
if (bank != NO_BANK) if (bank != NO_BANK)
outb_p(bank, data->address[ldi] + PC87365_REG_BANK); outb_p(bank, data->address[ldi] + PC87365_REG_BANK);
outb_p(value, data->address[ldi] + reg); outb_p(value, data->address[ldi] + reg);
up(&(data->lock)); mutex_unlock(&(data->lock));
} }
static void pc87360_init_client(struct i2c_client *client, int use_thermistors) static void pc87360_init_client(struct i2c_client *client, int use_thermistors)
...@@ -1215,7 +1216,7 @@ static struct pc87360_data *pc87360_update_device(struct device *dev) ...@@ -1215,7 +1216,7 @@ static struct pc87360_data *pc87360_update_device(struct device *dev)
struct pc87360_data *data = i2c_get_clientdata(client); struct pc87360_data *data = i2c_get_clientdata(client);
u8 i; u8 i;
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
dev_dbg(&client->dev, "Data update\n"); dev_dbg(&client->dev, "Data update\n");
...@@ -1315,7 +1316,7 @@ static struct pc87360_data *pc87360_update_device(struct device *dev) ...@@ -1315,7 +1316,7 @@ static struct pc87360_data *pc87360_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -60,6 +60,7 @@ ...@@ -60,6 +60,7 @@
#include <linux/err.h> #include <linux/err.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/jiffies.h> #include <linux/jiffies.h>
#include <linux/mutex.h>
#include <asm/io.h> #include <asm/io.h>
...@@ -167,9 +168,9 @@ static inline u8 DIV_TO_REG(int val) ...@@ -167,9 +168,9 @@ static inline u8 DIV_TO_REG(int val)
struct sis5595_data { struct sis5595_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore lock; struct mutex lock;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* !=0 if following fields are valid */ char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
char maxins; /* == 3 if temp enabled, otherwise == 4 */ char maxins; /* == 3 if temp enabled, otherwise == 4 */
...@@ -231,10 +232,10 @@ static ssize_t set_in_min(struct device *dev, const char *buf, ...@@ -231,10 +232,10 @@ static ssize_t set_in_min(struct device *dev, const char *buf,
struct sis5595_data *data = i2c_get_clientdata(client); struct sis5595_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_min[nr] = IN_TO_REG(val); data->in_min[nr] = IN_TO_REG(val);
sis5595_write_value(client, SIS5595_REG_IN_MIN(nr), data->in_min[nr]); sis5595_write_value(client, SIS5595_REG_IN_MIN(nr), data->in_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -245,10 +246,10 @@ static ssize_t set_in_max(struct device *dev, const char *buf, ...@@ -245,10 +246,10 @@ static ssize_t set_in_max(struct device *dev, const char *buf,
struct sis5595_data *data = i2c_get_clientdata(client); struct sis5595_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_max[nr] = IN_TO_REG(val); data->in_max[nr] = IN_TO_REG(val);
sis5595_write_value(client, SIS5595_REG_IN_MAX(nr), data->in_max[nr]); sis5595_write_value(client, SIS5595_REG_IN_MAX(nr), data->in_max[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -310,10 +311,10 @@ static ssize_t set_temp_over(struct device *dev, struct device_attribute *attr, ...@@ -310,10 +311,10 @@ static ssize_t set_temp_over(struct device *dev, struct device_attribute *attr,
struct sis5595_data *data = i2c_get_clientdata(client); struct sis5595_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_over = TEMP_TO_REG(val); data->temp_over = TEMP_TO_REG(val);
sis5595_write_value(client, SIS5595_REG_TEMP_OVER, data->temp_over); sis5595_write_value(client, SIS5595_REG_TEMP_OVER, data->temp_over);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -329,10 +330,10 @@ static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *attr, ...@@ -329,10 +330,10 @@ static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *attr,
struct sis5595_data *data = i2c_get_clientdata(client); struct sis5595_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_hyst = TEMP_TO_REG(val); data->temp_hyst = TEMP_TO_REG(val);
sis5595_write_value(client, SIS5595_REG_TEMP_HYST, data->temp_hyst); sis5595_write_value(client, SIS5595_REG_TEMP_HYST, data->temp_hyst);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -364,10 +365,10 @@ static ssize_t set_fan_min(struct device *dev, const char *buf, ...@@ -364,10 +365,10 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
struct sis5595_data *data = i2c_get_clientdata(client); struct sis5595_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
sis5595_write_value(client, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); sis5595_write_value(client, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -390,7 +391,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, ...@@ -390,7 +391,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
int reg; int reg;
down(&data->update_lock); mutex_lock(&data->update_lock);
min = FAN_FROM_REG(data->fan_min[nr], min = FAN_FROM_REG(data->fan_min[nr],
DIV_FROM_REG(data->fan_div[nr])); DIV_FROM_REG(data->fan_div[nr]));
reg = sis5595_read_value(client, SIS5595_REG_FANDIV); reg = sis5595_read_value(client, SIS5595_REG_FANDIV);
...@@ -403,7 +404,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, ...@@ -403,7 +404,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
default: default:
dev_err(&client->dev, "fan_div value %ld not " dev_err(&client->dev, "fan_div value %ld not "
"supported. Choose one of 1, 2, 4 or 8!\n", val); "supported. Choose one of 1, 2, 4 or 8!\n", val);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return -EINVAL; return -EINVAL;
} }
...@@ -419,7 +420,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, ...@@ -419,7 +420,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
data->fan_min[nr] = data->fan_min[nr] =
FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
sis5595_write_value(client, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); sis5595_write_value(client, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -527,7 +528,7 @@ static int sis5595_detect(struct i2c_adapter *adapter) ...@@ -527,7 +528,7 @@ static int sis5595_detect(struct i2c_adapter *adapter)
new_client = &data->client; new_client = &data->client;
new_client->addr = address; new_client->addr = address;
init_MUTEX(&data->lock); mutex_init(&data->lock);
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->adapter = adapter; new_client->adapter = adapter;
new_client->driver = &sis5595_driver; new_client->driver = &sis5595_driver;
...@@ -548,7 +549,7 @@ static int sis5595_detect(struct i2c_adapter *adapter) ...@@ -548,7 +549,7 @@ static int sis5595_detect(struct i2c_adapter *adapter)
strlcpy(new_client->name, "sis5595", I2C_NAME_SIZE); strlcpy(new_client->name, "sis5595", I2C_NAME_SIZE);
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
...@@ -635,20 +636,20 @@ static int sis5595_read_value(struct i2c_client *client, u8 reg) ...@@ -635,20 +636,20 @@ static int sis5595_read_value(struct i2c_client *client, u8 reg)
int res; int res;
struct sis5595_data *data = i2c_get_clientdata(client); struct sis5595_data *data = i2c_get_clientdata(client);
down(&data->lock); mutex_lock(&data->lock);
outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET); outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET);
res = inb_p(client->addr + SIS5595_DATA_REG_OFFSET); res = inb_p(client->addr + SIS5595_DATA_REG_OFFSET);
up(&data->lock); mutex_unlock(&data->lock);
return res; return res;
} }
static int sis5595_write_value(struct i2c_client *client, u8 reg, u8 value) static int sis5595_write_value(struct i2c_client *client, u8 reg, u8 value)
{ {
struct sis5595_data *data = i2c_get_clientdata(client); struct sis5595_data *data = i2c_get_clientdata(client);
down(&data->lock); mutex_lock(&data->lock);
outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET); outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET);
outb_p(value, client->addr + SIS5595_DATA_REG_OFFSET); outb_p(value, client->addr + SIS5595_DATA_REG_OFFSET);
up(&data->lock); mutex_unlock(&data->lock);
return 0; return 0;
} }
...@@ -667,7 +668,7 @@ static struct sis5595_data *sis5595_update_device(struct device *dev) ...@@ -667,7 +668,7 @@ static struct sis5595_data *sis5595_update_device(struct device *dev)
struct sis5595_data *data = i2c_get_clientdata(client); struct sis5595_data *data = i2c_get_clientdata(client);
int i; int i;
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ + HZ / 2) if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|| !data->valid) { || !data->valid) {
...@@ -707,7 +708,7 @@ static struct sis5595_data *sis5595_update_device(struct device *dev) ...@@ -707,7 +708,7 @@ static struct sis5595_data *sis5595_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/mutex.h>
#include <asm/io.h> #include <asm/io.h>
/* Address is autodetected, there is no default value */ /* Address is autodetected, there is no default value */
...@@ -92,9 +93,9 @@ static u8 smsc47b397_reg_temp[] = {0x25, 0x26, 0x27, 0x80}; ...@@ -92,9 +93,9 @@ static u8 smsc47b397_reg_temp[] = {0x25, 0x26, 0x27, 0x80};
struct smsc47b397_data { struct smsc47b397_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore lock; struct mutex lock;
struct semaphore update_lock; struct mutex update_lock;
unsigned long last_updated; /* in jiffies */ unsigned long last_updated; /* in jiffies */
int valid; int valid;
...@@ -108,10 +109,10 @@ static int smsc47b397_read_value(struct i2c_client *client, u8 reg) ...@@ -108,10 +109,10 @@ static int smsc47b397_read_value(struct i2c_client *client, u8 reg)
struct smsc47b397_data *data = i2c_get_clientdata(client); struct smsc47b397_data *data = i2c_get_clientdata(client);
int res; int res;
down(&data->lock); mutex_lock(&data->lock);
outb(reg, client->addr); outb(reg, client->addr);
res = inb_p(client->addr + 1); res = inb_p(client->addr + 1);
up(&data->lock); mutex_unlock(&data->lock);
return res; return res;
} }
...@@ -121,7 +122,7 @@ static struct smsc47b397_data *smsc47b397_update_device(struct device *dev) ...@@ -121,7 +122,7 @@ static struct smsc47b397_data *smsc47b397_update_device(struct device *dev)
struct smsc47b397_data *data = i2c_get_clientdata(client); struct smsc47b397_data *data = i2c_get_clientdata(client);
int i; int i;
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
dev_dbg(&client->dev, "starting device update...\n"); dev_dbg(&client->dev, "starting device update...\n");
...@@ -144,7 +145,7 @@ static struct smsc47b397_data *smsc47b397_update_device(struct device *dev) ...@@ -144,7 +145,7 @@ static struct smsc47b397_data *smsc47b397_update_device(struct device *dev)
dev_dbg(&client->dev, "... device update complete\n"); dev_dbg(&client->dev, "... device update complete\n");
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
...@@ -254,14 +255,14 @@ static int smsc47b397_detect(struct i2c_adapter *adapter) ...@@ -254,14 +255,14 @@ static int smsc47b397_detect(struct i2c_adapter *adapter)
new_client = &data->client; new_client = &data->client;
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
init_MUTEX(&data->lock); mutex_init(&data->lock);
new_client->adapter = adapter; new_client->adapter = adapter;
new_client->driver = &smsc47b397_driver; new_client->driver = &smsc47b397_driver;
new_client->flags = 0; new_client->flags = 0;
strlcpy(new_client->name, "smsc47b397", I2C_NAME_SIZE); strlcpy(new_client->name, "smsc47b397", I2C_NAME_SIZE);
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
goto error_free; goto error_free;
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/mutex.h>
#include <asm/io.h> #include <asm/io.h>
/* Address is autodetected, there is no default value */ /* Address is autodetected, there is no default value */
...@@ -102,9 +103,9 @@ superio_exit(void) ...@@ -102,9 +103,9 @@ superio_exit(void)
struct smsc47m1_data { struct smsc47m1_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore lock; struct mutex lock;
struct semaphore update_lock; struct mutex update_lock;
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
u8 fan[2]; /* Register value */ u8 fan[2]; /* Register value */
...@@ -188,18 +189,18 @@ static ssize_t set_fan_min(struct device *dev, const char *buf, ...@@ -188,18 +189,18 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
struct smsc47m1_data *data = i2c_get_clientdata(client); struct smsc47m1_data *data = i2c_get_clientdata(client);
long rpmdiv, val = simple_strtol(buf, NULL, 10); long rpmdiv, val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
rpmdiv = val * DIV_FROM_REG(data->fan_div[nr]); rpmdiv = val * DIV_FROM_REG(data->fan_div[nr]);
if (983040 > 192 * rpmdiv || 2 * rpmdiv > 983040) { if (983040 > 192 * rpmdiv || 2 * rpmdiv > 983040) {
up(&data->update_lock); mutex_unlock(&data->update_lock);
return -EINVAL; return -EINVAL;
} }
data->fan_preload[nr] = 192 - ((983040 + rpmdiv / 2) / rpmdiv); data->fan_preload[nr] = 192 - ((983040 + rpmdiv / 2) / rpmdiv);
smsc47m1_write_value(client, SMSC47M1_REG_FAN_PRELOAD(nr), smsc47m1_write_value(client, SMSC47M1_REG_FAN_PRELOAD(nr),
data->fan_preload[nr]); data->fan_preload[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -220,14 +221,14 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, ...@@ -220,14 +221,14 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
if (new_div == old_div) /* No change */ if (new_div == old_div) /* No change */
return count; return count;
down(&data->update_lock); mutex_lock(&data->update_lock);
switch (new_div) { switch (new_div) {
case 1: data->fan_div[nr] = 0; break; case 1: data->fan_div[nr] = 0; break;
case 2: data->fan_div[nr] = 1; break; case 2: data->fan_div[nr] = 1; break;
case 4: data->fan_div[nr] = 2; break; case 4: data->fan_div[nr] = 2; break;
case 8: data->fan_div[nr] = 3; break; case 8: data->fan_div[nr] = 3; break;
default: default:
up(&data->update_lock); mutex_unlock(&data->update_lock);
return -EINVAL; return -EINVAL;
} }
...@@ -241,7 +242,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, ...@@ -241,7 +242,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
data->fan_preload[nr] = SENSORS_LIMIT(tmp, 0, 191); data->fan_preload[nr] = SENSORS_LIMIT(tmp, 0, 191);
smsc47m1_write_value(client, SMSC47M1_REG_FAN_PRELOAD(nr), smsc47m1_write_value(client, SMSC47M1_REG_FAN_PRELOAD(nr),
data->fan_preload[nr]); data->fan_preload[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -257,12 +258,12 @@ static ssize_t set_pwm(struct device *dev, const char *buf, ...@@ -257,12 +258,12 @@ static ssize_t set_pwm(struct device *dev, const char *buf,
if (val < 0 || val > 255) if (val < 0 || val > 255)
return -EINVAL; return -EINVAL;
down(&data->update_lock); mutex_lock(&data->update_lock);
data->pwm[nr] &= 0x81; /* Preserve additional bits */ data->pwm[nr] &= 0x81; /* Preserve additional bits */
data->pwm[nr] |= PWM_TO_REG(val); data->pwm[nr] |= PWM_TO_REG(val);
smsc47m1_write_value(client, SMSC47M1_REG_PWM(nr), smsc47m1_write_value(client, SMSC47M1_REG_PWM(nr),
data->pwm[nr]); data->pwm[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -278,12 +279,12 @@ static ssize_t set_pwm_en(struct device *dev, const char *buf, ...@@ -278,12 +279,12 @@ static ssize_t set_pwm_en(struct device *dev, const char *buf,
if (val != 0 && val != 1) if (val != 0 && val != 1)
return -EINVAL; return -EINVAL;
down(&data->update_lock); mutex_lock(&data->update_lock);
data->pwm[nr] &= 0xFE; /* preserve the other bits */ data->pwm[nr] &= 0xFE; /* preserve the other bits */
data->pwm[nr] |= !val; data->pwm[nr] |= !val;
smsc47m1_write_value(client, SMSC47M1_REG_PWM(nr), smsc47m1_write_value(client, SMSC47M1_REG_PWM(nr),
data->pwm[nr]); data->pwm[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -408,13 +409,13 @@ static int smsc47m1_detect(struct i2c_adapter *adapter) ...@@ -408,13 +409,13 @@ static int smsc47m1_detect(struct i2c_adapter *adapter)
new_client = &data->client; new_client = &data->client;
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
init_MUTEX(&data->lock); mutex_init(&data->lock);
new_client->adapter = adapter; new_client->adapter = adapter;
new_client->driver = &smsc47m1_driver; new_client->driver = &smsc47m1_driver;
new_client->flags = 0; new_client->flags = 0;
strlcpy(new_client->name, "smsc47m1", I2C_NAME_SIZE); strlcpy(new_client->name, "smsc47m1", I2C_NAME_SIZE);
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* If no function is properly configured, there's no point in /* If no function is properly configured, there's no point in
actually registering the chip. */ actually registering the chip. */
...@@ -512,17 +513,17 @@ static int smsc47m1_read_value(struct i2c_client *client, u8 reg) ...@@ -512,17 +513,17 @@ static int smsc47m1_read_value(struct i2c_client *client, u8 reg)
{ {
int res; int res;
down(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock); mutex_lock(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock);
res = inb_p(client->addr + reg); res = inb_p(client->addr + reg);
up(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock); mutex_unlock(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock);
return res; return res;
} }
static void smsc47m1_write_value(struct i2c_client *client, u8 reg, u8 value) static void smsc47m1_write_value(struct i2c_client *client, u8 reg, u8 value)
{ {
down(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock); mutex_lock(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock);
outb_p(value, client->addr + reg); outb_p(value, client->addr + reg);
up(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock); mutex_unlock(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock);
} }
static struct smsc47m1_data *smsc47m1_update_device(struct device *dev, static struct smsc47m1_data *smsc47m1_update_device(struct device *dev,
...@@ -531,7 +532,7 @@ static struct smsc47m1_data *smsc47m1_update_device(struct device *dev, ...@@ -531,7 +532,7 @@ static struct smsc47m1_data *smsc47m1_update_device(struct device *dev,
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct smsc47m1_data *data = i2c_get_clientdata(client); struct smsc47m1_data *data = i2c_get_clientdata(client);
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || init) { if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || init) {
int i; int i;
...@@ -558,7 +559,7 @@ static struct smsc47m1_data *smsc47m1_update_device(struct device *dev, ...@@ -558,7 +559,7 @@ static struct smsc47m1_data *smsc47m1_update_device(struct device *dev,
data->last_updated = jiffies; data->last_updated = jiffies;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/mutex.h>
#include <asm/io.h> #include <asm/io.h>
...@@ -296,7 +297,7 @@ static inline long TEMP_FROM_REG10(u16 val) ...@@ -296,7 +297,7 @@ static inline long TEMP_FROM_REG10(u16 val)
struct via686a_data { struct via686a_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* !=0 if following fields are valid */ char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
...@@ -355,11 +356,11 @@ static ssize_t set_in_min(struct device *dev, const char *buf, ...@@ -355,11 +356,11 @@ static ssize_t set_in_min(struct device *dev, const char *buf,
struct via686a_data *data = i2c_get_clientdata(client); struct via686a_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_min[nr] = IN_TO_REG(val, nr); data->in_min[nr] = IN_TO_REG(val, nr);
via686a_write_value(client, VIA686A_REG_IN_MIN(nr), via686a_write_value(client, VIA686A_REG_IN_MIN(nr),
data->in_min[nr]); data->in_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t set_in_max(struct device *dev, const char *buf, static ssize_t set_in_max(struct device *dev, const char *buf,
...@@ -368,11 +369,11 @@ static ssize_t set_in_max(struct device *dev, const char *buf, ...@@ -368,11 +369,11 @@ static ssize_t set_in_max(struct device *dev, const char *buf,
struct via686a_data *data = i2c_get_clientdata(client); struct via686a_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_max[nr] = IN_TO_REG(val, nr); data->in_max[nr] = IN_TO_REG(val, nr);
via686a_write_value(client, VIA686A_REG_IN_MAX(nr), via686a_write_value(client, VIA686A_REG_IN_MAX(nr),
data->in_max[nr]); data->in_max[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
#define show_in_offset(offset) \ #define show_in_offset(offset) \
...@@ -432,11 +433,11 @@ static ssize_t set_temp_over(struct device *dev, const char *buf, ...@@ -432,11 +433,11 @@ static ssize_t set_temp_over(struct device *dev, const char *buf,
struct via686a_data *data = i2c_get_clientdata(client); struct via686a_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); int val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_over[nr] = TEMP_TO_REG(val); data->temp_over[nr] = TEMP_TO_REG(val);
via686a_write_value(client, VIA686A_REG_TEMP_OVER[nr], via686a_write_value(client, VIA686A_REG_TEMP_OVER[nr],
data->temp_over[nr]); data->temp_over[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t set_temp_hyst(struct device *dev, const char *buf, static ssize_t set_temp_hyst(struct device *dev, const char *buf,
...@@ -445,11 +446,11 @@ static ssize_t set_temp_hyst(struct device *dev, const char *buf, ...@@ -445,11 +446,11 @@ static ssize_t set_temp_hyst(struct device *dev, const char *buf,
struct via686a_data *data = i2c_get_clientdata(client); struct via686a_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); int val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_hyst[nr] = TEMP_TO_REG(val); data->temp_hyst[nr] = TEMP_TO_REG(val);
via686a_write_value(client, VIA686A_REG_TEMP_HYST[nr], via686a_write_value(client, VIA686A_REG_TEMP_HYST[nr],
data->temp_hyst[nr]); data->temp_hyst[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
#define show_temp_offset(offset) \ #define show_temp_offset(offset) \
...@@ -508,10 +509,10 @@ static ssize_t set_fan_min(struct device *dev, const char *buf, ...@@ -508,10 +509,10 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
struct via686a_data *data = i2c_get_clientdata(client); struct via686a_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); int val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
via686a_write_value(client, VIA686A_REG_FAN_MIN(nr+1), data->fan_min[nr]); via686a_write_value(client, VIA686A_REG_FAN_MIN(nr+1), data->fan_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t set_fan_div(struct device *dev, const char *buf, static ssize_t set_fan_div(struct device *dev, const char *buf,
...@@ -521,12 +522,12 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, ...@@ -521,12 +522,12 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
int val = simple_strtol(buf, NULL, 10); int val = simple_strtol(buf, NULL, 10);
int old; int old;
down(&data->update_lock); mutex_lock(&data->update_lock);
old = via686a_read_value(client, VIA686A_REG_FANDIV); old = via686a_read_value(client, VIA686A_REG_FANDIV);
data->fan_div[nr] = DIV_TO_REG(val); data->fan_div[nr] = DIV_TO_REG(val);
old = (old & 0x0f) | (data->fan_div[1] << 6) | (data->fan_div[0] << 4); old = (old & 0x0f) | (data->fan_div[1] << 6) | (data->fan_div[0] << 4);
via686a_write_value(client, VIA686A_REG_FANDIV, old); via686a_write_value(client, VIA686A_REG_FANDIV, old);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -639,7 +640,7 @@ static int via686a_detect(struct i2c_adapter *adapter) ...@@ -639,7 +640,7 @@ static int via686a_detect(struct i2c_adapter *adapter)
strlcpy(new_client->name, client_name, I2C_NAME_SIZE); strlcpy(new_client->name, client_name, I2C_NAME_SIZE);
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
goto exit_free; goto exit_free;
...@@ -733,7 +734,7 @@ static struct via686a_data *via686a_update_device(struct device *dev) ...@@ -733,7 +734,7 @@ static struct via686a_data *via686a_update_device(struct device *dev)
struct via686a_data *data = i2c_get_clientdata(client); struct via686a_data *data = i2c_get_clientdata(client);
int i; int i;
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ + HZ / 2) if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|| !data->valid) { || !data->valid) {
...@@ -788,7 +789,7 @@ static struct via686a_data *via686a_update_device(struct device *dev) ...@@ -788,7 +789,7 @@ static struct via686a_data *via686a_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <linux/hwmon-sysfs.h> #include <linux/hwmon-sysfs.h>
#include <linux/hwmon-vid.h> #include <linux/hwmon-vid.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
#include <asm/io.h> #include <asm/io.h>
static int force_addr; static int force_addr;
...@@ -148,7 +149,7 @@ static inline u8 FAN_TO_REG(long rpm, int div) ...@@ -148,7 +149,7 @@ static inline u8 FAN_TO_REG(long rpm, int div)
struct vt8231_data { struct vt8231_data {
struct i2c_client client; struct i2c_client client;
struct semaphore update_lock; struct mutex update_lock;
struct class_device *class_dev; struct class_device *class_dev;
char valid; /* !=0 if following fields are valid */ char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
...@@ -223,10 +224,10 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, ...@@ -223,10 +224,10 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
struct vt8231_data *data = i2c_get_clientdata(client); struct vt8231_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_min[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255); data->in_min[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255);
vt8231_write_value(client, regvoltmin[nr], data->in_min[nr]); vt8231_write_value(client, regvoltmin[nr], data->in_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -239,10 +240,10 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, ...@@ -239,10 +240,10 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
struct vt8231_data *data = i2c_get_clientdata(client); struct vt8231_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_max[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255); data->in_max[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255);
vt8231_write_value(client, regvoltmax[nr], data->in_max[nr]); vt8231_write_value(client, regvoltmax[nr], data->in_max[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -281,11 +282,11 @@ static ssize_t set_in5_min(struct device *dev, struct device_attribute *attr, ...@@ -281,11 +282,11 @@ static ssize_t set_in5_min(struct device *dev, struct device_attribute *attr,
struct vt8231_data *data = i2c_get_clientdata(client); struct vt8231_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_min[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3, data->in_min[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3,
0, 255); 0, 255);
vt8231_write_value(client, regvoltmin[5], data->in_min[5]); vt8231_write_value(client, regvoltmin[5], data->in_min[5]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -296,11 +297,11 @@ static ssize_t set_in5_max(struct device *dev, struct device_attribute *attr, ...@@ -296,11 +297,11 @@ static ssize_t set_in5_max(struct device *dev, struct device_attribute *attr,
struct vt8231_data *data = i2c_get_clientdata(client); struct vt8231_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->in_max[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3, data->in_max[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3,
0, 255); 0, 255);
vt8231_write_value(client, regvoltmax[5], data->in_max[5]); vt8231_write_value(client, regvoltmax[5], data->in_max[5]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -351,10 +352,10 @@ static ssize_t set_temp0_max(struct device *dev, struct device_attribute *attr, ...@@ -351,10 +352,10 @@ static ssize_t set_temp0_max(struct device *dev, struct device_attribute *attr,
struct vt8231_data *data = i2c_get_clientdata(client); struct vt8231_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); int val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_max[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255); data->temp_max[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255);
vt8231_write_value(client, regtempmax[0], data->temp_max[0]); vt8231_write_value(client, regtempmax[0], data->temp_max[0]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t set_temp0_min(struct device *dev, struct device_attribute *attr, static ssize_t set_temp0_min(struct device *dev, struct device_attribute *attr,
...@@ -364,10 +365,10 @@ static ssize_t set_temp0_min(struct device *dev, struct device_attribute *attr, ...@@ -364,10 +365,10 @@ static ssize_t set_temp0_min(struct device *dev, struct device_attribute *attr,
struct vt8231_data *data = i2c_get_clientdata(client); struct vt8231_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); int val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_min[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255); data->temp_min[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255);
vt8231_write_value(client, regtempmin[0], data->temp_min[0]); vt8231_write_value(client, regtempmin[0], data->temp_min[0]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -407,10 +408,10 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, ...@@ -407,10 +408,10 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
struct vt8231_data *data = i2c_get_clientdata(client); struct vt8231_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); int val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_max[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255); data->temp_max[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255);
vt8231_write_value(client, regtempmax[nr], data->temp_max[nr]); vt8231_write_value(client, regtempmax[nr], data->temp_max[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
...@@ -422,10 +423,10 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, ...@@ -422,10 +423,10 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
struct vt8231_data *data = i2c_get_clientdata(client); struct vt8231_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); int val = simple_strtol(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_min[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255); data->temp_min[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255);
vt8231_write_value(client, regtempmin[nr], data->temp_min[nr]); vt8231_write_value(client, regtempmin[nr], data->temp_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -520,10 +521,10 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, ...@@ -520,10 +521,10 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
struct vt8231_data *data = i2c_get_clientdata(client); struct vt8231_data *data = i2c_get_clientdata(client);
int val = simple_strtoul(buf, NULL, 10); int val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
vt8231_write_value(client, VT8231_REG_FAN_MIN(nr), data->fan_min[nr]); vt8231_write_value(client, VT8231_REG_FAN_MIN(nr), data->fan_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -539,7 +540,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, ...@@ -539,7 +540,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
long min = FAN_FROM_REG(data->fan_min[nr], long min = FAN_FROM_REG(data->fan_min[nr],
DIV_FROM_REG(data->fan_div[nr])); DIV_FROM_REG(data->fan_div[nr]));
down(&data->update_lock); mutex_lock(&data->update_lock);
switch (val) { switch (val) {
case 1: data->fan_div[nr] = 0; break; case 1: data->fan_div[nr] = 0; break;
case 2: data->fan_div[nr] = 1; break; case 2: data->fan_div[nr] = 1; break;
...@@ -548,7 +549,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, ...@@ -548,7 +549,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
default: default:
dev_err(&client->dev, "fan_div value %ld not supported." dev_err(&client->dev, "fan_div value %ld not supported."
"Choose one of 1, 2, 4 or 8!\n", val); "Choose one of 1, 2, 4 or 8!\n", val);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return -EINVAL; return -EINVAL;
} }
...@@ -558,7 +559,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, ...@@ -558,7 +559,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
old = (old & 0x0f) | (data->fan_div[1] << 6) | (data->fan_div[0] << 4); old = (old & 0x0f) | (data->fan_div[1] << 6) | (data->fan_div[0] << 4);
vt8231_write_value(client, VT8231_REG_FANDIV, old); vt8231_write_value(client, VT8231_REG_FANDIV, old);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -660,7 +661,7 @@ int vt8231_detect(struct i2c_adapter *adapter) ...@@ -660,7 +661,7 @@ int vt8231_detect(struct i2c_adapter *adapter)
/* Fill in the remaining client fields and put into the global list */ /* Fill in the remaining client fields and put into the global list */
strlcpy(client->name, "vt8231", I2C_NAME_SIZE); strlcpy(client->name, "vt8231", I2C_NAME_SIZE);
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(client))) if ((err = i2c_attach_client(client)))
...@@ -745,7 +746,7 @@ static struct vt8231_data *vt8231_update_device(struct device *dev) ...@@ -745,7 +746,7 @@ static struct vt8231_data *vt8231_update_device(struct device *dev)
int i; int i;
u16 low; u16 low;
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ + HZ / 2) if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|| !data->valid) { || !data->valid) {
...@@ -804,7 +805,7 @@ static struct vt8231_data *vt8231_update_device(struct device *dev) ...@@ -804,7 +805,7 @@ static struct vt8231_data *vt8231_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include <linux/i2c-isa.h> #include <linux/i2c-isa.h>
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
#include <asm/io.h> #include <asm/io.h>
#include "lm75.h" #include "lm75.h"
...@@ -177,9 +178,9 @@ temp1_to_reg(int temp) ...@@ -177,9 +178,9 @@ temp1_to_reg(int temp)
struct w83627ehf_data { struct w83627ehf_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore lock; struct mutex lock;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* !=0 if following fields are valid */ char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
...@@ -230,7 +231,7 @@ static u16 w83627ehf_read_value(struct i2c_client *client, u16 reg) ...@@ -230,7 +231,7 @@ static u16 w83627ehf_read_value(struct i2c_client *client, u16 reg)
struct w83627ehf_data *data = i2c_get_clientdata(client); struct w83627ehf_data *data = i2c_get_clientdata(client);
int res, word_sized = is_word_sized(reg); int res, word_sized = is_word_sized(reg);
down(&data->lock); mutex_lock(&data->lock);
w83627ehf_set_bank(client, reg); w83627ehf_set_bank(client, reg);
outb_p(reg & 0xff, client->addr + ADDR_REG_OFFSET); outb_p(reg & 0xff, client->addr + ADDR_REG_OFFSET);
...@@ -242,7 +243,7 @@ static u16 w83627ehf_read_value(struct i2c_client *client, u16 reg) ...@@ -242,7 +243,7 @@ static u16 w83627ehf_read_value(struct i2c_client *client, u16 reg)
} }
w83627ehf_reset_bank(client, reg); w83627ehf_reset_bank(client, reg);
up(&data->lock); mutex_unlock(&data->lock);
return res; return res;
} }
...@@ -252,7 +253,7 @@ static int w83627ehf_write_value(struct i2c_client *client, u16 reg, u16 value) ...@@ -252,7 +253,7 @@ static int w83627ehf_write_value(struct i2c_client *client, u16 reg, u16 value)
struct w83627ehf_data *data = i2c_get_clientdata(client); struct w83627ehf_data *data = i2c_get_clientdata(client);
int word_sized = is_word_sized(reg); int word_sized = is_word_sized(reg);
down(&data->lock); mutex_lock(&data->lock);
w83627ehf_set_bank(client, reg); w83627ehf_set_bank(client, reg);
outb_p(reg & 0xff, client->addr + ADDR_REG_OFFSET); outb_p(reg & 0xff, client->addr + ADDR_REG_OFFSET);
...@@ -264,7 +265,7 @@ static int w83627ehf_write_value(struct i2c_client *client, u16 reg, u16 value) ...@@ -264,7 +265,7 @@ static int w83627ehf_write_value(struct i2c_client *client, u16 reg, u16 value)
outb_p(value & 0xff, client->addr + DATA_REG_OFFSET); outb_p(value & 0xff, client->addr + DATA_REG_OFFSET);
w83627ehf_reset_bank(client, reg); w83627ehf_reset_bank(client, reg);
up(&data->lock); mutex_unlock(&data->lock);
return 0; return 0;
} }
...@@ -322,7 +323,7 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev) ...@@ -322,7 +323,7 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
struct w83627ehf_data *data = i2c_get_clientdata(client); struct w83627ehf_data *data = i2c_get_clientdata(client);
int i; int i;
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ) if (time_after(jiffies, data->last_updated + HZ)
|| !data->valid) { || !data->valid) {
...@@ -397,7 +398,7 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev) ...@@ -397,7 +398,7 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
...@@ -434,7 +435,7 @@ store_fan_min(struct device *dev, const char *buf, size_t count, int nr) ...@@ -434,7 +435,7 @@ store_fan_min(struct device *dev, const char *buf, size_t count, int nr)
unsigned int reg; unsigned int reg;
u8 new_div; u8 new_div;
down(&data->update_lock); mutex_lock(&data->update_lock);
if (!val) { if (!val) {
/* No min limit, alarm disabled */ /* No min limit, alarm disabled */
data->fan_min[nr] = 255; data->fan_min[nr] = 255;
...@@ -482,7 +483,7 @@ store_fan_min(struct device *dev, const char *buf, size_t count, int nr) ...@@ -482,7 +483,7 @@ store_fan_min(struct device *dev, const char *buf, size_t count, int nr)
} }
w83627ehf_write_value(client, W83627EHF_REG_FAN_MIN[nr], w83627ehf_write_value(client, W83627EHF_REG_FAN_MIN[nr],
data->fan_min[nr]); data->fan_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -561,11 +562,11 @@ store_temp1_##reg(struct device *dev, struct device_attribute *attr, \ ...@@ -561,11 +562,11 @@ store_temp1_##reg(struct device *dev, struct device_attribute *attr, \
struct w83627ehf_data *data = i2c_get_clientdata(client); \ struct w83627ehf_data *data = i2c_get_clientdata(client); \
u32 val = simple_strtoul(buf, NULL, 10); \ u32 val = simple_strtoul(buf, NULL, 10); \
\ \
down(&data->update_lock); \ mutex_lock(&data->update_lock); \
data->temp1_##reg = temp1_to_reg(val); \ data->temp1_##reg = temp1_to_reg(val); \
w83627ehf_write_value(client, W83627EHF_REG_TEMP1_##REG, \ w83627ehf_write_value(client, W83627EHF_REG_TEMP1_##REG, \
data->temp1_##reg); \ data->temp1_##reg); \
up(&data->update_lock); \ mutex_unlock(&data->update_lock); \
return count; \ return count; \
} }
store_temp1_reg(OVER, max); store_temp1_reg(OVER, max);
...@@ -597,11 +598,11 @@ store_##reg (struct device *dev, const char *buf, size_t count, int nr) \ ...@@ -597,11 +598,11 @@ store_##reg (struct device *dev, const char *buf, size_t count, int nr) \
struct w83627ehf_data *data = i2c_get_clientdata(client); \ struct w83627ehf_data *data = i2c_get_clientdata(client); \
u32 val = simple_strtoul(buf, NULL, 10); \ u32 val = simple_strtoul(buf, NULL, 10); \
\ \
down(&data->update_lock); \ mutex_lock(&data->update_lock); \
data->reg[nr] = LM75_TEMP_TO_REG(val); \ data->reg[nr] = LM75_TEMP_TO_REG(val); \
w83627ehf_write_value(client, W83627EHF_REG_TEMP_##REG[nr], \ w83627ehf_write_value(client, W83627EHF_REG_TEMP_##REG[nr], \
data->reg[nr]); \ data->reg[nr]); \
up(&data->update_lock); \ mutex_unlock(&data->update_lock); \
return count; \ return count; \
} }
store_temp_reg(OVER, temp_max); store_temp_reg(OVER, temp_max);
...@@ -689,14 +690,14 @@ static int w83627ehf_detect(struct i2c_adapter *adapter) ...@@ -689,14 +690,14 @@ static int w83627ehf_detect(struct i2c_adapter *adapter)
client = &data->client; client = &data->client;
i2c_set_clientdata(client, data); i2c_set_clientdata(client, data);
client->addr = address; client->addr = address;
init_MUTEX(&data->lock); mutex_init(&data->lock);
client->adapter = adapter; client->adapter = adapter;
client->driver = &w83627ehf_driver; client->driver = &w83627ehf_driver;
client->flags = 0; client->flags = 0;
strlcpy(client->name, "w83627ehf", I2C_NAME_SIZE); strlcpy(client->name, "w83627ehf", I2C_NAME_SIZE);
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the i2c layer a new client has arrived */ /* Tell the i2c layer a new client has arrived */
if ((err = i2c_attach_client(client))) if ((err = i2c_attach_client(client)))
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/hwmon-vid.h> #include <linux/hwmon-vid.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
#include <asm/io.h> #include <asm/io.h>
#include "lm75.h" #include "lm75.h"
...@@ -285,10 +286,10 @@ static inline u8 DIV_TO_REG(long val) ...@@ -285,10 +286,10 @@ static inline u8 DIV_TO_REG(long val)
struct w83627hf_data { struct w83627hf_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore lock; struct mutex lock;
enum chips type; enum chips type;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* !=0 if following fields are valid */ char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
...@@ -360,12 +361,12 @@ store_in_##reg (struct device *dev, const char *buf, size_t count, int nr) \ ...@@ -360,12 +361,12 @@ store_in_##reg (struct device *dev, const char *buf, size_t count, int nr) \
\ \
val = simple_strtoul(buf, NULL, 10); \ val = simple_strtoul(buf, NULL, 10); \
\ \
down(&data->update_lock); \ mutex_lock(&data->update_lock); \
data->in_##reg[nr] = IN_TO_REG(val); \ data->in_##reg[nr] = IN_TO_REG(val); \
w83627hf_write_value(client, W83781D_REG_IN_##REG(nr), \ w83627hf_write_value(client, W83781D_REG_IN_##REG(nr), \
data->in_##reg[nr]); \ data->in_##reg[nr]); \
\ \
up(&data->update_lock); \ mutex_unlock(&data->update_lock); \
return count; \ return count; \
} }
store_in_reg(MIN, min) store_in_reg(MIN, min)
...@@ -451,7 +452,7 @@ static ssize_t store_regs_in_min0(struct device *dev, struct device_attribute *a ...@@ -451,7 +452,7 @@ static ssize_t store_regs_in_min0(struct device *dev, struct device_attribute *a
val = simple_strtoul(buf, NULL, 10); val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
if ((data->vrm_ovt & 0x01) && if ((data->vrm_ovt & 0x01) &&
(w83627thf == data->type || w83637hf == data->type)) (w83627thf == data->type || w83637hf == data->type))
...@@ -465,7 +466,7 @@ static ssize_t store_regs_in_min0(struct device *dev, struct device_attribute *a ...@@ -465,7 +466,7 @@ static ssize_t store_regs_in_min0(struct device *dev, struct device_attribute *a
data->in_min[0] = IN_TO_REG(val); data->in_min[0] = IN_TO_REG(val);
w83627hf_write_value(client, W83781D_REG_IN_MIN(0), data->in_min[0]); w83627hf_write_value(client, W83781D_REG_IN_MIN(0), data->in_min[0]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -478,7 +479,7 @@ static ssize_t store_regs_in_max0(struct device *dev, struct device_attribute *a ...@@ -478,7 +479,7 @@ static ssize_t store_regs_in_max0(struct device *dev, struct device_attribute *a
val = simple_strtoul(buf, NULL, 10); val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
if ((data->vrm_ovt & 0x01) && if ((data->vrm_ovt & 0x01) &&
(w83627thf == data->type || w83637hf == data->type)) (w83627thf == data->type || w83637hf == data->type))
...@@ -492,7 +493,7 @@ static ssize_t store_regs_in_max0(struct device *dev, struct device_attribute *a ...@@ -492,7 +493,7 @@ static ssize_t store_regs_in_max0(struct device *dev, struct device_attribute *a
data->in_max[0] = IN_TO_REG(val); data->in_max[0] = IN_TO_REG(val);
w83627hf_write_value(client, W83781D_REG_IN_MAX(0), data->in_max[0]); w83627hf_write_value(client, W83781D_REG_IN_MAX(0), data->in_max[0]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -529,13 +530,13 @@ store_fan_min(struct device *dev, const char *buf, size_t count, int nr) ...@@ -529,13 +530,13 @@ store_fan_min(struct device *dev, const char *buf, size_t count, int nr)
val = simple_strtoul(buf, NULL, 10); val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->fan_min[nr - 1] = data->fan_min[nr - 1] =
FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr - 1])); FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr - 1]));
w83627hf_write_value(client, W83781D_REG_FAN_MIN(nr), w83627hf_write_value(client, W83781D_REG_FAN_MIN(nr),
data->fan_min[nr - 1]); data->fan_min[nr - 1]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -597,7 +598,7 @@ store_temp_##reg (struct device *dev, const char *buf, size_t count, int nr) \ ...@@ -597,7 +598,7 @@ store_temp_##reg (struct device *dev, const char *buf, size_t count, int nr) \
\ \
val = simple_strtoul(buf, NULL, 10); \ val = simple_strtoul(buf, NULL, 10); \
\ \
down(&data->update_lock); \ mutex_lock(&data->update_lock); \
\ \
if (nr >= 2) { /* TEMP2 and TEMP3 */ \ if (nr >= 2) { /* TEMP2 and TEMP3 */ \
data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \ data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \
...@@ -609,7 +610,7 @@ store_temp_##reg (struct device *dev, const char *buf, size_t count, int nr) \ ...@@ -609,7 +610,7 @@ store_temp_##reg (struct device *dev, const char *buf, size_t count, int nr) \
data->temp_##reg); \ data->temp_##reg); \
} \ } \
\ \
up(&data->update_lock); \ mutex_unlock(&data->update_lock); \
return count; \ return count; \
} }
store_temp_reg(OVER, max); store_temp_reg(OVER, max);
...@@ -718,7 +719,7 @@ store_beep_reg(struct device *dev, const char *buf, size_t count, ...@@ -718,7 +719,7 @@ store_beep_reg(struct device *dev, const char *buf, size_t count,
val = simple_strtoul(buf, NULL, 10); val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
if (update_mask == BEEP_MASK) { /* We are storing beep_mask */ if (update_mask == BEEP_MASK) { /* We are storing beep_mask */
data->beep_mask = BEEP_MASK_TO_REG(val); data->beep_mask = BEEP_MASK_TO_REG(val);
...@@ -736,7 +737,7 @@ store_beep_reg(struct device *dev, const char *buf, size_t count, ...@@ -736,7 +737,7 @@ store_beep_reg(struct device *dev, const char *buf, size_t count,
w83627hf_write_value(client, W83781D_REG_BEEP_INTS2, w83627hf_write_value(client, W83781D_REG_BEEP_INTS2,
val2 | data->beep_enable << 7); val2 | data->beep_enable << 7);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -783,7 +784,7 @@ store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr) ...@@ -783,7 +784,7 @@ store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr)
u8 reg; u8 reg;
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
/* Save fan_min */ /* Save fan_min */
min = FAN_FROM_REG(data->fan_min[nr], min = FAN_FROM_REG(data->fan_min[nr],
...@@ -805,7 +806,7 @@ store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr) ...@@ -805,7 +806,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])); 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]); w83627hf_write_value(client, W83781D_REG_FAN_MIN(nr+1), data->fan_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -848,7 +849,7 @@ store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr) ...@@ -848,7 +849,7 @@ store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr)
val = simple_strtoul(buf, NULL, 10); val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
if (data->type == w83627thf) { if (data->type == w83627thf) {
/* bits 0-3 are reserved in 627THF */ /* bits 0-3 are reserved in 627THF */
...@@ -865,7 +866,7 @@ store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr) ...@@ -865,7 +866,7 @@ store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr)
data->pwm[nr - 1]); data->pwm[nr - 1]);
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -907,7 +908,7 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr) ...@@ -907,7 +908,7 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr)
val = simple_strtoul(buf, NULL, 10); val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
switch (val) { switch (val) {
case 1: /* PII/Celeron diode */ case 1: /* PII/Celeron diode */
...@@ -941,7 +942,7 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr) ...@@ -941,7 +942,7 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr)
break; break;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -1057,7 +1058,7 @@ static int w83627hf_detect(struct i2c_adapter *adapter) ...@@ -1057,7 +1058,7 @@ static int w83627hf_detect(struct i2c_adapter *adapter)
new_client = &data->client; new_client = &data->client;
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
init_MUTEX(&data->lock); mutex_init(&data->lock);
new_client->adapter = adapter; new_client->adapter = adapter;
new_client->driver = &w83627hf_driver; new_client->driver = &w83627hf_driver;
new_client->flags = 0; new_client->flags = 0;
...@@ -1077,7 +1078,7 @@ static int w83627hf_detect(struct i2c_adapter *adapter) ...@@ -1077,7 +1078,7 @@ static int w83627hf_detect(struct i2c_adapter *adapter)
strlcpy(new_client->name, client_name, I2C_NAME_SIZE); strlcpy(new_client->name, client_name, I2C_NAME_SIZE);
data->type = kind; data->type = kind;
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
...@@ -1187,7 +1188,7 @@ static int w83627hf_read_value(struct i2c_client *client, u16 reg) ...@@ -1187,7 +1188,7 @@ static int w83627hf_read_value(struct i2c_client *client, u16 reg)
struct w83627hf_data *data = i2c_get_clientdata(client); struct w83627hf_data *data = i2c_get_clientdata(client);
int res, word_sized; int res, word_sized;
down(&data->lock); mutex_lock(&data->lock);
word_sized = (((reg & 0xff00) == 0x100) word_sized = (((reg & 0xff00) == 0x100)
|| ((reg & 0xff00) == 0x200)) || ((reg & 0xff00) == 0x200))
&& (((reg & 0x00ff) == 0x50) && (((reg & 0x00ff) == 0x50)
...@@ -1213,7 +1214,7 @@ static int w83627hf_read_value(struct i2c_client *client, u16 reg) ...@@ -1213,7 +1214,7 @@ static int w83627hf_read_value(struct i2c_client *client, u16 reg)
client->addr + W83781D_ADDR_REG_OFFSET); client->addr + W83781D_ADDR_REG_OFFSET);
outb_p(0, client->addr + W83781D_DATA_REG_OFFSET); outb_p(0, client->addr + W83781D_DATA_REG_OFFSET);
} }
up(&data->lock); mutex_unlock(&data->lock);
return res; return res;
} }
...@@ -1252,7 +1253,7 @@ static int w83627hf_write_value(struct i2c_client *client, u16 reg, u16 value) ...@@ -1252,7 +1253,7 @@ static int w83627hf_write_value(struct i2c_client *client, u16 reg, u16 value)
struct w83627hf_data *data = i2c_get_clientdata(client); struct w83627hf_data *data = i2c_get_clientdata(client);
int word_sized; int word_sized;
down(&data->lock); mutex_lock(&data->lock);
word_sized = (((reg & 0xff00) == 0x100) word_sized = (((reg & 0xff00) == 0x100)
|| ((reg & 0xff00) == 0x200)) || ((reg & 0xff00) == 0x200))
&& (((reg & 0x00ff) == 0x53) && (((reg & 0x00ff) == 0x53)
...@@ -1277,7 +1278,7 @@ static int w83627hf_write_value(struct i2c_client *client, u16 reg, u16 value) ...@@ -1277,7 +1278,7 @@ static int w83627hf_write_value(struct i2c_client *client, u16 reg, u16 value)
client->addr + W83781D_ADDR_REG_OFFSET); client->addr + W83781D_ADDR_REG_OFFSET);
outb_p(0, client->addr + W83781D_DATA_REG_OFFSET); outb_p(0, client->addr + W83781D_DATA_REG_OFFSET);
} }
up(&data->lock); mutex_unlock(&data->lock);
return 0; return 0;
} }
...@@ -1387,7 +1388,7 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev) ...@@ -1387,7 +1388,7 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev)
struct w83627hf_data *data = i2c_get_clientdata(client); struct w83627hf_data *data = i2c_get_clientdata(client);
int i; int i;
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ + HZ / 2) if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|| !data->valid) { || !data->valid) {
...@@ -1470,7 +1471,7 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev) ...@@ -1470,7 +1471,7 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/hwmon-vid.h> #include <linux/hwmon-vid.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
#include <asm/io.h> #include <asm/io.h>
#include "lm75.h" #include "lm75.h"
...@@ -226,10 +227,10 @@ DIV_TO_REG(long val, enum chips type) ...@@ -226,10 +227,10 @@ DIV_TO_REG(long val, enum chips type)
struct w83781d_data { struct w83781d_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore lock; struct mutex lock;
enum chips type; enum chips type;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* !=0 if following fields are valid */ char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
...@@ -311,11 +312,11 @@ static ssize_t store_in_##reg (struct device *dev, const char *buf, size_t count ...@@ -311,11 +312,11 @@ static ssize_t store_in_##reg (struct device *dev, const char *buf, size_t count
\ \
val = simple_strtoul(buf, NULL, 10) / 10; \ val = simple_strtoul(buf, NULL, 10) / 10; \
\ \
down(&data->update_lock); \ mutex_lock(&data->update_lock); \
data->in_##reg[nr] = IN_TO_REG(val); \ data->in_##reg[nr] = IN_TO_REG(val); \
w83781d_write_value(client, W83781D_REG_IN_##REG(nr), data->in_##reg[nr]); \ w83781d_write_value(client, W83781D_REG_IN_##REG(nr), data->in_##reg[nr]); \
\ \
up(&data->update_lock); \ mutex_unlock(&data->update_lock); \
return count; \ return count; \
} }
store_in_reg(MIN, min); store_in_reg(MIN, min);
...@@ -381,13 +382,13 @@ store_fan_min(struct device *dev, const char *buf, size_t count, int nr) ...@@ -381,13 +382,13 @@ store_fan_min(struct device *dev, const char *buf, size_t count, int nr)
val = simple_strtoul(buf, NULL, 10); val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->fan_min[nr - 1] = data->fan_min[nr - 1] =
FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr - 1])); FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr - 1]));
w83781d_write_value(client, W83781D_REG_FAN_MIN(nr), w83781d_write_value(client, W83781D_REG_FAN_MIN(nr),
data->fan_min[nr - 1]); data->fan_min[nr - 1]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -446,7 +447,7 @@ static ssize_t store_temp_##reg (struct device *dev, const char *buf, size_t cou ...@@ -446,7 +447,7 @@ static ssize_t store_temp_##reg (struct device *dev, const char *buf, size_t cou
\ \
val = simple_strtol(buf, NULL, 10); \ val = simple_strtol(buf, NULL, 10); \
\ \
down(&data->update_lock); \ mutex_lock(&data->update_lock); \
\ \
if (nr >= 2) { /* TEMP2 and TEMP3 */ \ if (nr >= 2) { /* TEMP2 and TEMP3 */ \
data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \ data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \
...@@ -458,7 +459,7 @@ static ssize_t store_temp_##reg (struct device *dev, const char *buf, size_t cou ...@@ -458,7 +459,7 @@ static ssize_t store_temp_##reg (struct device *dev, const char *buf, size_t cou
data->temp_##reg); \ data->temp_##reg); \
} \ } \
\ \
up(&data->update_lock); \ mutex_unlock(&data->update_lock); \
return count; \ return count; \
} }
store_temp_reg(OVER, max); store_temp_reg(OVER, max);
...@@ -571,7 +572,7 @@ store_beep_reg(struct device *dev, const char *buf, size_t count, ...@@ -571,7 +572,7 @@ store_beep_reg(struct device *dev, const char *buf, size_t count,
val = simple_strtoul(buf, NULL, 10); val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
if (update_mask == BEEP_MASK) { /* We are storing beep_mask */ if (update_mask == BEEP_MASK) { /* We are storing beep_mask */
data->beep_mask = BEEP_MASK_TO_REG(val, data->type); data->beep_mask = BEEP_MASK_TO_REG(val, data->type);
...@@ -592,7 +593,7 @@ store_beep_reg(struct device *dev, const char *buf, size_t count, ...@@ -592,7 +593,7 @@ store_beep_reg(struct device *dev, const char *buf, size_t count,
w83781d_write_value(client, W83781D_REG_BEEP_INTS2, w83781d_write_value(client, W83781D_REG_BEEP_INTS2,
val2 | data->beep_enable << 7); val2 | data->beep_enable << 7);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -637,7 +638,7 @@ store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr) ...@@ -637,7 +638,7 @@ store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr)
u8 reg; u8 reg;
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
/* Save fan_min */ /* Save fan_min */
min = FAN_FROM_REG(data->fan_min[nr], min = FAN_FROM_REG(data->fan_min[nr],
...@@ -662,7 +663,7 @@ store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr) ...@@ -662,7 +663,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])); data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
w83781d_write_value(client, W83781D_REG_FAN_MIN(nr+1), data->fan_min[nr]); w83781d_write_value(client, W83781D_REG_FAN_MIN(nr+1), data->fan_min[nr]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -709,10 +710,10 @@ store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr) ...@@ -709,10 +710,10 @@ store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr)
val = simple_strtoul(buf, NULL, 10); val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
data->pwm[nr - 1] = PWM_TO_REG(val); data->pwm[nr - 1] = PWM_TO_REG(val);
w83781d_write_value(client, W83781D_REG_PWM(nr), data->pwm[nr - 1]); w83781d_write_value(client, W83781D_REG_PWM(nr), data->pwm[nr - 1]);
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -725,7 +726,7 @@ store_pwmenable_reg(struct device *dev, const char *buf, size_t count, int nr) ...@@ -725,7 +726,7 @@ store_pwmenable_reg(struct device *dev, const char *buf, size_t count, int nr)
val = simple_strtoul(buf, NULL, 10); val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
switch (val) { switch (val) {
case 0: case 0:
...@@ -742,11 +743,11 @@ store_pwmenable_reg(struct device *dev, const char *buf, size_t count, int nr) ...@@ -742,11 +743,11 @@ store_pwmenable_reg(struct device *dev, const char *buf, size_t count, int nr)
break; break;
default: default:
up(&data->update_lock); mutex_unlock(&data->update_lock);
return -EINVAL; return -EINVAL;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -808,7 +809,7 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr) ...@@ -808,7 +809,7 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr)
val = simple_strtoul(buf, NULL, 10); val = simple_strtoul(buf, NULL, 10);
down(&data->update_lock); mutex_lock(&data->update_lock);
switch (val) { switch (val) {
case 1: /* PII/Celeron diode */ case 1: /* PII/Celeron diode */
...@@ -841,7 +842,7 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr) ...@@ -841,7 +842,7 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr)
break; break;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -1073,7 +1074,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -1073,7 +1074,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
new_client = &data->client; new_client = &data->client;
i2c_set_clientdata(new_client, data); i2c_set_clientdata(new_client, data);
new_client->addr = address; new_client->addr = address;
init_MUTEX(&data->lock); mutex_init(&data->lock);
new_client->adapter = adapter; new_client->adapter = adapter;
new_client->driver = is_isa ? &w83781d_isa_driver : &w83781d_driver; new_client->driver = is_isa ? &w83781d_isa_driver : &w83781d_driver;
new_client->flags = 0; new_client->flags = 0;
...@@ -1178,7 +1179,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -1178,7 +1179,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
data->type = kind; data->type = kind;
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client))) if ((err = i2c_attach_client(new_client)))
...@@ -1325,7 +1326,7 @@ w83781d_read_value(struct i2c_client *client, u16 reg) ...@@ -1325,7 +1326,7 @@ w83781d_read_value(struct i2c_client *client, u16 reg)
int res, word_sized, bank; int res, word_sized, bank;
struct i2c_client *cl; struct i2c_client *cl;
down(&data->lock); mutex_lock(&data->lock);
if (i2c_is_isa_client(client)) { if (i2c_is_isa_client(client)) {
word_sized = (((reg & 0xff00) == 0x100) word_sized = (((reg & 0xff00) == 0x100)
|| ((reg & 0xff00) == 0x200)) || ((reg & 0xff00) == 0x200))
...@@ -1383,7 +1384,7 @@ w83781d_read_value(struct i2c_client *client, u16 reg) ...@@ -1383,7 +1384,7 @@ w83781d_read_value(struct i2c_client *client, u16 reg)
if (bank > 2) if (bank > 2)
i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 0); i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 0);
} }
up(&data->lock); mutex_unlock(&data->lock);
return res; return res;
} }
...@@ -1394,7 +1395,7 @@ w83781d_write_value(struct i2c_client *client, u16 reg, u16 value) ...@@ -1394,7 +1395,7 @@ w83781d_write_value(struct i2c_client *client, u16 reg, u16 value)
int word_sized, bank; int word_sized, bank;
struct i2c_client *cl; struct i2c_client *cl;
down(&data->lock); mutex_lock(&data->lock);
if (i2c_is_isa_client(client)) { if (i2c_is_isa_client(client)) {
word_sized = (((reg & 0xff00) == 0x100) word_sized = (((reg & 0xff00) == 0x100)
|| ((reg & 0xff00) == 0x200)) || ((reg & 0xff00) == 0x200))
...@@ -1447,7 +1448,7 @@ w83781d_write_value(struct i2c_client *client, u16 reg, u16 value) ...@@ -1447,7 +1448,7 @@ w83781d_write_value(struct i2c_client *client, u16 reg, u16 value)
if (bank > 2) if (bank > 2)
i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 0); i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 0);
} }
up(&data->lock); mutex_unlock(&data->lock);
return 0; return 0;
} }
...@@ -1533,7 +1534,7 @@ static struct w83781d_data *w83781d_update_device(struct device *dev) ...@@ -1533,7 +1534,7 @@ static struct w83781d_data *w83781d_update_device(struct device *dev)
struct w83781d_data *data = i2c_get_clientdata(client); struct w83781d_data *data = i2c_get_clientdata(client);
int i; int i;
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ + HZ / 2) if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|| !data->valid) { || !data->valid) {
...@@ -1641,7 +1642,7 @@ static struct w83781d_data *w83781d_update_device(struct device *dev) ...@@ -1641,7 +1642,7 @@ static struct w83781d_data *w83781d_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h> #include <linux/hwmon-sysfs.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
/* Addresses to scan */ /* Addresses to scan */
static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END }; static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END };
...@@ -271,7 +272,7 @@ struct w83792d_data { ...@@ -271,7 +272,7 @@ struct w83792d_data {
struct class_device *class_dev; struct class_device *class_dev;
enum chips type; enum chips type;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* !=0 if following fields are valid */ char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
...@@ -1222,7 +1223,7 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -1222,7 +1223,7 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind)
data->type = kind; data->type = kind;
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */ /* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(client))) if ((err = i2c_attach_client(client)))
...@@ -1373,7 +1374,7 @@ static struct w83792d_data *w83792d_update_device(struct device *dev) ...@@ -1373,7 +1374,7 @@ static struct w83792d_data *w83792d_update_device(struct device *dev)
int i, j; int i, j;
u8 reg_array_tmp[4], pwm_array_tmp[7], reg_tmp; u8 reg_array_tmp[4], pwm_array_tmp[7], reg_tmp;
down(&data->update_lock); mutex_lock(&data->update_lock);
if (time_after if (time_after
(jiffies - data->last_updated, (unsigned long) (HZ * 3)) (jiffies - data->last_updated, (unsigned long) (HZ * 3))
...@@ -1484,7 +1485,7 @@ static struct w83792d_data *w83792d_update_device(struct device *dev) ...@@ -1484,7 +1485,7 @@ static struct w83792d_data *w83792d_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
#ifdef DEBUG #ifdef DEBUG
w83792d_print_debug(data, dev); w83792d_print_debug(data, dev);
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h> #include <linux/hwmon-sysfs.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h>
/* How many retries on register read error */ /* How many retries on register read error */
#define MAX_RETRIES 5 #define MAX_RETRIES 5
...@@ -107,7 +108,7 @@ static struct i2c_driver w83l785ts_driver = { ...@@ -107,7 +108,7 @@ static struct i2c_driver w83l785ts_driver = {
struct w83l785ts_data { struct w83l785ts_data {
struct i2c_client client; struct i2c_client client;
struct class_device *class_dev; struct class_device *class_dev;
struct semaphore update_lock; struct mutex update_lock;
char valid; /* zero until following fields are valid */ char valid; /* zero until following fields are valid */
unsigned long last_updated; /* in jiffies */ unsigned long last_updated; /* in jiffies */
...@@ -221,7 +222,7 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -221,7 +222,7 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind)
/* We can fill in the remaining client fields. */ /* We can fill in the remaining client fields. */
strlcpy(new_client->name, "w83l785ts", I2C_NAME_SIZE); strlcpy(new_client->name, "w83l785ts", I2C_NAME_SIZE);
data->valid = 0; data->valid = 0;
init_MUTEX(&data->update_lock); mutex_init(&data->update_lock);
/* Default values in case the first read fails (unlikely). */ /* Default values in case the first read fails (unlikely). */
data->temp[1] = data->temp[0] = 0; data->temp[1] = data->temp[0] = 0;
...@@ -299,7 +300,7 @@ static struct w83l785ts_data *w83l785ts_update_device(struct device *dev) ...@@ -299,7 +300,7 @@ static struct w83l785ts_data *w83l785ts_update_device(struct device *dev)
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct w83l785ts_data *data = i2c_get_clientdata(client); struct w83l785ts_data *data = i2c_get_clientdata(client);
down(&data->update_lock); mutex_lock(&data->update_lock);
if (!data->valid || time_after(jiffies, data->last_updated + HZ * 2)) { if (!data->valid || time_after(jiffies, data->last_updated + HZ * 2)) {
dev_dbg(&client->dev, "Updating w83l785ts data.\n"); dev_dbg(&client->dev, "Updating w83l785ts data.\n");
...@@ -312,7 +313,7 @@ static struct w83l785ts_data *w83l785ts_update_device(struct device *dev) ...@@ -312,7 +313,7 @@ static struct w83l785ts_data *w83l785ts_update_device(struct device *dev)
data->valid = 1; data->valid = 1;
} }
up(&data->update_lock); mutex_unlock(&data->update_lock);
return data; return data;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment