diff options
Diffstat (limited to 'drivers/hwmon/lm77.c')
-rw-r--r-- | drivers/hwmon/lm77.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c index df9e02aaa70a..459cc977380a 100644 --- a/drivers/hwmon/lm77.c +++ b/drivers/hwmon/lm77.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/i2c.h> | 32 | #include <linux/i2c.h> |
33 | #include <linux/hwmon.h> | 33 | #include <linux/hwmon.h> |
34 | #include <linux/err.h> | 34 | #include <linux/err.h> |
35 | #include <linux/mutex.h> | ||
35 | 36 | ||
36 | /* Addresses to scan */ | 37 | /* Addresses to scan */ |
37 | static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, I2C_CLIENT_END }; | 38 | static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, I2C_CLIENT_END }; |
@@ -51,7 +52,7 @@ I2C_CLIENT_INSMOD_1(lm77); | |||
51 | struct lm77_data { | 52 | struct lm77_data { |
52 | struct i2c_client client; | 53 | struct i2c_client client; |
53 | struct class_device *class_dev; | 54 | struct class_device *class_dev; |
54 | struct semaphore update_lock; | 55 | struct mutex update_lock; |
55 | char valid; | 56 | char valid; |
56 | unsigned long last_updated; /* In jiffies */ | 57 | unsigned long last_updated; /* In jiffies */ |
57 | int temp_input; /* Temperatures */ | 58 | int temp_input; /* Temperatures */ |
@@ -139,10 +140,10 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co | |||
139 | struct lm77_data *data = i2c_get_clientdata(client); \ | 140 | struct lm77_data *data = i2c_get_clientdata(client); \ |
140 | long val = simple_strtoul(buf, NULL, 10); \ | 141 | long val = simple_strtoul(buf, NULL, 10); \ |
141 | \ | 142 | \ |
142 | down(&data->update_lock); \ | 143 | mutex_lock(&data->update_lock); \ |
143 | data->value = val; \ | 144 | data->value = val; \ |
144 | lm77_write_value(client, reg, LM77_TEMP_TO_REG(data->value)); \ | 145 | lm77_write_value(client, reg, LM77_TEMP_TO_REG(data->value)); \ |
145 | up(&data->update_lock); \ | 146 | mutex_unlock(&data->update_lock); \ |
146 | return count; \ | 147 | return count; \ |
147 | } | 148 | } |
148 | 149 | ||
@@ -157,11 +158,11 @@ static ssize_t set_temp_crit_hyst(struct device *dev, struct device_attribute *a | |||
157 | struct lm77_data *data = i2c_get_clientdata(client); | 158 | struct lm77_data *data = i2c_get_clientdata(client); |
158 | unsigned long val = simple_strtoul(buf, NULL, 10); | 159 | unsigned long val = simple_strtoul(buf, NULL, 10); |
159 | 160 | ||
160 | down(&data->update_lock); | 161 | mutex_lock(&data->update_lock); |
161 | data->temp_hyst = data->temp_crit - val; | 162 | data->temp_hyst = data->temp_crit - val; |
162 | lm77_write_value(client, LM77_REG_TEMP_HYST, | 163 | lm77_write_value(client, LM77_REG_TEMP_HYST, |
163 | LM77_TEMP_TO_REG(data->temp_hyst)); | 164 | LM77_TEMP_TO_REG(data->temp_hyst)); |
164 | up(&data->update_lock); | 165 | mutex_unlock(&data->update_lock); |
165 | return count; | 166 | return count; |
166 | } | 167 | } |
167 | 168 | ||
@@ -173,7 +174,7 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr, | |||
173 | long val = simple_strtoul(buf, NULL, 10); | 174 | long val = simple_strtoul(buf, NULL, 10); |
174 | int oldcrithyst; | 175 | int oldcrithyst; |
175 | 176 | ||
176 | down(&data->update_lock); | 177 | mutex_lock(&data->update_lock); |
177 | oldcrithyst = data->temp_crit - data->temp_hyst; | 178 | oldcrithyst = data->temp_crit - data->temp_hyst; |
178 | data->temp_crit = val; | 179 | data->temp_crit = val; |
179 | data->temp_hyst = data->temp_crit - oldcrithyst; | 180 | 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 | LM77_TEMP_TO_REG(data->temp_crit)); | 182 | LM77_TEMP_TO_REG(data->temp_crit)); |
182 | lm77_write_value(client, LM77_REG_TEMP_HYST, | 183 | lm77_write_value(client, LM77_REG_TEMP_HYST, |
183 | LM77_TEMP_TO_REG(data->temp_hyst)); | 184 | LM77_TEMP_TO_REG(data->temp_hyst)); |
184 | up(&data->update_lock); | 185 | mutex_unlock(&data->update_lock); |
185 | return count; | 186 | return count; |
186 | } | 187 | } |
187 | 188 | ||
@@ -306,7 +307,7 @@ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind) | |||
306 | /* Fill in the remaining client fields and put it into the global list */ | 307 | /* Fill in the remaining client fields and put it into the global list */ |
307 | strlcpy(new_client->name, name, I2C_NAME_SIZE); | 308 | strlcpy(new_client->name, name, I2C_NAME_SIZE); |
308 | data->valid = 0; | 309 | data->valid = 0; |
309 | init_MUTEX(&data->update_lock); | 310 | mutex_init(&data->update_lock); |
310 | 311 | ||
311 | /* Tell the I2C layer a new client has arrived */ | 312 | /* Tell the I2C layer a new client has arrived */ |
312 | if ((err = i2c_attach_client(new_client))) | 313 | if ((err = i2c_attach_client(new_client))) |
@@ -380,7 +381,7 @@ static struct lm77_data *lm77_update_device(struct device *dev) | |||
380 | struct i2c_client *client = to_i2c_client(dev); | 381 | struct i2c_client *client = to_i2c_client(dev); |
381 | struct lm77_data *data = i2c_get_clientdata(client); | 382 | struct lm77_data *data = i2c_get_clientdata(client); |
382 | 383 | ||
383 | down(&data->update_lock); | 384 | mutex_lock(&data->update_lock); |
384 | 385 | ||
385 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) | 386 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) |
386 | || !data->valid) { | 387 | || !data->valid) { |
@@ -406,7 +407,7 @@ static struct lm77_data *lm77_update_device(struct device *dev) | |||
406 | data->valid = 1; | 407 | data->valid = 1; |
407 | } | 408 | } |
408 | 409 | ||
409 | up(&data->update_lock); | 410 | mutex_unlock(&data->update_lock); |
410 | 411 | ||
411 | return data; | 412 | return data; |
412 | } | 413 | } |