diff options
Diffstat (limited to 'drivers/hwmon/fscpos.c')
-rw-r--r-- | drivers/hwmon/fscpos.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/drivers/hwmon/fscpos.c b/drivers/hwmon/fscpos.c index 6d0146b57020..6dc4846b9eeb 100644 --- a/drivers/hwmon/fscpos.c +++ b/drivers/hwmon/fscpos.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <linux/init.h> | 37 | #include <linux/init.h> |
38 | #include <linux/hwmon.h> | 38 | #include <linux/hwmon.h> |
39 | #include <linux/err.h> | 39 | #include <linux/err.h> |
40 | #include <linux/mutex.h> | ||
40 | 41 | ||
41 | /* | 42 | /* |
42 | * Addresses to scan | 43 | * Addresses to scan |
@@ -89,8 +90,8 @@ static int fscpos_attach_adapter(struct i2c_adapter *adapter); | |||
89 | static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind); | 90 | static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind); |
90 | static int fscpos_detach_client(struct i2c_client *client); | 91 | static int fscpos_detach_client(struct i2c_client *client); |
91 | 92 | ||
92 | static int fscpos_read_value(struct i2c_client *client, u8 register); | 93 | static int fscpos_read_value(struct i2c_client *client, u8 reg); |
93 | static int fscpos_write_value(struct i2c_client *client, u8 register, u8 value); | 94 | static int fscpos_write_value(struct i2c_client *client, u8 reg, u8 value); |
94 | static struct fscpos_data *fscpos_update_device(struct device *dev); | 95 | static struct fscpos_data *fscpos_update_device(struct device *dev); |
95 | static void fscpos_init_client(struct i2c_client *client); | 96 | static void fscpos_init_client(struct i2c_client *client); |
96 | 97 | ||
@@ -114,7 +115,7 @@ static struct i2c_driver fscpos_driver = { | |||
114 | struct fscpos_data { | 115 | struct fscpos_data { |
115 | struct i2c_client client; | 116 | struct i2c_client client; |
116 | struct class_device *class_dev; | 117 | struct class_device *class_dev; |
117 | struct semaphore update_lock; | 118 | struct mutex update_lock; |
118 | char valid; /* 0 until following fields are valid */ | 119 | char valid; /* 0 until following fields are valid */ |
119 | unsigned long last_updated; /* In jiffies */ | 120 | unsigned long last_updated; /* In jiffies */ |
120 | 121 | ||
@@ -208,13 +209,13 @@ static ssize_t set_fan_ripple(struct i2c_client *client, struct fscpos_data | |||
208 | return -EINVAL; | 209 | return -EINVAL; |
209 | } | 210 | } |
210 | 211 | ||
211 | down(&data->update_lock); | 212 | mutex_lock(&data->update_lock); |
212 | /* bits 2..7 reserved => mask with 0x03 */ | 213 | /* bits 2..7 reserved => mask with 0x03 */ |
213 | data->fan_ripple[nr - 1] &= ~0x03; | 214 | data->fan_ripple[nr - 1] &= ~0x03; |
214 | data->fan_ripple[nr - 1] |= v; | 215 | data->fan_ripple[nr - 1] |= v; |
215 | 216 | ||
216 | fscpos_write_value(client, reg, data->fan_ripple[nr - 1]); | 217 | fscpos_write_value(client, reg, data->fan_ripple[nr - 1]); |
217 | up(&data->update_lock); | 218 | mutex_unlock(&data->update_lock); |
218 | return count; | 219 | return count; |
219 | } | 220 | } |
220 | 221 | ||
@@ -232,10 +233,10 @@ static ssize_t set_pwm(struct i2c_client *client, struct fscpos_data *data, | |||
232 | if (v < 0) v = 0; | 233 | if (v < 0) v = 0; |
233 | if (v > 255) v = 255; | 234 | if (v > 255) v = 255; |
234 | 235 | ||
235 | down(&data->update_lock); | 236 | mutex_lock(&data->update_lock); |
236 | data->pwm[nr - 1] = v; | 237 | data->pwm[nr - 1] = v; |
237 | fscpos_write_value(client, reg, data->pwm[nr - 1]); | 238 | fscpos_write_value(client, reg, data->pwm[nr - 1]); |
238 | up(&data->update_lock); | 239 | mutex_unlock(&data->update_lock); |
239 | return count; | 240 | return count; |
240 | } | 241 | } |
241 | 242 | ||
@@ -278,11 +279,11 @@ static ssize_t set_wdog_control(struct i2c_client *client, struct fscpos_data | |||
278 | /* bits 0..3 reserved => mask with 0xf0 */ | 279 | /* bits 0..3 reserved => mask with 0xf0 */ |
279 | unsigned long v = simple_strtoul(buf, NULL, 10) & 0xf0; | 280 | unsigned long v = simple_strtoul(buf, NULL, 10) & 0xf0; |
280 | 281 | ||
281 | down(&data->update_lock); | 282 | mutex_lock(&data->update_lock); |
282 | data->wdog_control &= ~0xf0; | 283 | data->wdog_control &= ~0xf0; |
283 | data->wdog_control |= v; | 284 | data->wdog_control |= v; |
284 | fscpos_write_value(client, reg, data->wdog_control); | 285 | fscpos_write_value(client, reg, data->wdog_control); |
285 | up(&data->update_lock); | 286 | mutex_unlock(&data->update_lock); |
286 | return count; | 287 | return count; |
287 | } | 288 | } |
288 | 289 | ||
@@ -304,10 +305,10 @@ static ssize_t set_wdog_state(struct i2c_client *client, struct fscpos_data | |||
304 | return -EINVAL; | 305 | return -EINVAL; |
305 | } | 306 | } |
306 | 307 | ||
307 | down(&data->update_lock); | 308 | mutex_lock(&data->update_lock); |
308 | data->wdog_state &= ~v; | 309 | data->wdog_state &= ~v; |
309 | fscpos_write_value(client, reg, v); | 310 | fscpos_write_value(client, reg, v); |
310 | up(&data->update_lock); | 311 | mutex_unlock(&data->update_lock); |
311 | return count; | 312 | return count; |
312 | } | 313 | } |
313 | 314 | ||
@@ -321,10 +322,10 @@ static ssize_t set_wdog_preset(struct i2c_client *client, struct fscpos_data | |||
321 | { | 322 | { |
322 | unsigned long v = simple_strtoul(buf, NULL, 10) & 0xff; | 323 | unsigned long v = simple_strtoul(buf, NULL, 10) & 0xff; |
323 | 324 | ||
324 | down(&data->update_lock); | 325 | mutex_lock(&data->update_lock); |
325 | data->wdog_preset = v; | 326 | data->wdog_preset = v; |
326 | fscpos_write_value(client, reg, data->wdog_preset); | 327 | fscpos_write_value(client, reg, data->wdog_preset); |
327 | up(&data->update_lock); | 328 | mutex_unlock(&data->update_lock); |
328 | return count; | 329 | return count; |
329 | } | 330 | } |
330 | 331 | ||
@@ -483,7 +484,7 @@ static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind) | |||
483 | strlcpy(new_client->name, "fscpos", I2C_NAME_SIZE); | 484 | strlcpy(new_client->name, "fscpos", I2C_NAME_SIZE); |
484 | 485 | ||
485 | data->valid = 0; | 486 | data->valid = 0; |
486 | init_MUTEX(&data->update_lock); | 487 | mutex_init(&data->update_lock); |
487 | 488 | ||
488 | /* Tell the I2C layer a new client has arrived */ | 489 | /* Tell the I2C layer a new client has arrived */ |
489 | if ((err = i2c_attach_client(new_client))) | 490 | if ((err = i2c_attach_client(new_client))) |
@@ -579,7 +580,7 @@ static struct fscpos_data *fscpos_update_device(struct device *dev) | |||
579 | struct i2c_client *client = to_i2c_client(dev); | 580 | struct i2c_client *client = to_i2c_client(dev); |
580 | struct fscpos_data *data = i2c_get_clientdata(client); | 581 | struct fscpos_data *data = i2c_get_clientdata(client); |
581 | 582 | ||
582 | down(&data->update_lock); | 583 | mutex_lock(&data->update_lock); |
583 | 584 | ||
584 | if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) { | 585 | if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) { |
585 | int i; | 586 | int i; |
@@ -625,7 +626,7 @@ static struct fscpos_data *fscpos_update_device(struct device *dev) | |||
625 | data->last_updated = jiffies; | 626 | data->last_updated = jiffies; |
626 | data->valid = 1; | 627 | data->valid = 1; |
627 | } | 628 | } |
628 | up(&data->update_lock); | 629 | mutex_unlock(&data->update_lock); |
629 | return data; | 630 | return data; |
630 | } | 631 | } |
631 | 632 | ||