diff options
Diffstat (limited to 'drivers/hwmon/sis5595.c')
-rw-r--r-- | drivers/hwmon/sis5595.c | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c index 8be5189d9bd9..4db0dd871eee 100644 --- a/drivers/hwmon/sis5595.c +++ b/drivers/hwmon/sis5595.c | |||
@@ -60,6 +60,7 @@ | |||
60 | #include <linux/err.h> | 60 | #include <linux/err.h> |
61 | #include <linux/init.h> | 61 | #include <linux/init.h> |
62 | #include <linux/jiffies.h> | 62 | #include <linux/jiffies.h> |
63 | #include <linux/mutex.h> | ||
63 | #include <asm/io.h> | 64 | #include <asm/io.h> |
64 | 65 | ||
65 | 66 | ||
@@ -167,9 +168,9 @@ static inline u8 DIV_TO_REG(int val) | |||
167 | struct sis5595_data { | 168 | struct sis5595_data { |
168 | struct i2c_client client; | 169 | struct i2c_client client; |
169 | struct class_device *class_dev; | 170 | struct class_device *class_dev; |
170 | struct semaphore lock; | 171 | struct mutex lock; |
171 | 172 | ||
172 | struct semaphore update_lock; | 173 | struct mutex update_lock; |
173 | char valid; /* !=0 if following fields are valid */ | 174 | char valid; /* !=0 if following fields are valid */ |
174 | unsigned long last_updated; /* In jiffies */ | 175 | unsigned long last_updated; /* In jiffies */ |
175 | char maxins; /* == 3 if temp enabled, otherwise == 4 */ | 176 | 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 | struct sis5595_data *data = i2c_get_clientdata(client); | 232 | struct sis5595_data *data = i2c_get_clientdata(client); |
232 | unsigned long val = simple_strtoul(buf, NULL, 10); | 233 | unsigned long val = simple_strtoul(buf, NULL, 10); |
233 | 234 | ||
234 | down(&data->update_lock); | 235 | mutex_lock(&data->update_lock); |
235 | data->in_min[nr] = IN_TO_REG(val); | 236 | data->in_min[nr] = IN_TO_REG(val); |
236 | sis5595_write_value(client, SIS5595_REG_IN_MIN(nr), data->in_min[nr]); | 237 | sis5595_write_value(client, SIS5595_REG_IN_MIN(nr), data->in_min[nr]); |
237 | up(&data->update_lock); | 238 | mutex_unlock(&data->update_lock); |
238 | return count; | 239 | return count; |
239 | } | 240 | } |
240 | 241 | ||
@@ -245,10 +246,10 @@ static ssize_t set_in_max(struct device *dev, const char *buf, | |||
245 | struct sis5595_data *data = i2c_get_clientdata(client); | 246 | struct sis5595_data *data = i2c_get_clientdata(client); |
246 | unsigned long val = simple_strtoul(buf, NULL, 10); | 247 | unsigned long val = simple_strtoul(buf, NULL, 10); |
247 | 248 | ||
248 | down(&data->update_lock); | 249 | mutex_lock(&data->update_lock); |
249 | data->in_max[nr] = IN_TO_REG(val); | 250 | data->in_max[nr] = IN_TO_REG(val); |
250 | sis5595_write_value(client, SIS5595_REG_IN_MAX(nr), data->in_max[nr]); | 251 | sis5595_write_value(client, SIS5595_REG_IN_MAX(nr), data->in_max[nr]); |
251 | up(&data->update_lock); | 252 | mutex_unlock(&data->update_lock); |
252 | return count; | 253 | return count; |
253 | } | 254 | } |
254 | 255 | ||
@@ -310,10 +311,10 @@ static ssize_t set_temp_over(struct device *dev, struct device_attribute *attr, | |||
310 | struct sis5595_data *data = i2c_get_clientdata(client); | 311 | struct sis5595_data *data = i2c_get_clientdata(client); |
311 | long val = simple_strtol(buf, NULL, 10); | 312 | long val = simple_strtol(buf, NULL, 10); |
312 | 313 | ||
313 | down(&data->update_lock); | 314 | mutex_lock(&data->update_lock); |
314 | data->temp_over = TEMP_TO_REG(val); | 315 | data->temp_over = TEMP_TO_REG(val); |
315 | sis5595_write_value(client, SIS5595_REG_TEMP_OVER, data->temp_over); | 316 | sis5595_write_value(client, SIS5595_REG_TEMP_OVER, data->temp_over); |
316 | up(&data->update_lock); | 317 | mutex_unlock(&data->update_lock); |
317 | return count; | 318 | return count; |
318 | } | 319 | } |
319 | 320 | ||
@@ -329,10 +330,10 @@ static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *attr, | |||
329 | struct sis5595_data *data = i2c_get_clientdata(client); | 330 | struct sis5595_data *data = i2c_get_clientdata(client); |
330 | long val = simple_strtol(buf, NULL, 10); | 331 | long val = simple_strtol(buf, NULL, 10); |
331 | 332 | ||
332 | down(&data->update_lock); | 333 | mutex_lock(&data->update_lock); |
333 | data->temp_hyst = TEMP_TO_REG(val); | 334 | data->temp_hyst = TEMP_TO_REG(val); |
334 | sis5595_write_value(client, SIS5595_REG_TEMP_HYST, data->temp_hyst); | 335 | sis5595_write_value(client, SIS5595_REG_TEMP_HYST, data->temp_hyst); |
335 | up(&data->update_lock); | 336 | mutex_unlock(&data->update_lock); |
336 | return count; | 337 | return count; |
337 | } | 338 | } |
338 | 339 | ||
@@ -364,10 +365,10 @@ static ssize_t set_fan_min(struct device *dev, const char *buf, | |||
364 | struct sis5595_data *data = i2c_get_clientdata(client); | 365 | struct sis5595_data *data = i2c_get_clientdata(client); |
365 | unsigned long val = simple_strtoul(buf, NULL, 10); | 366 | unsigned long val = simple_strtoul(buf, NULL, 10); |
366 | 367 | ||
367 | down(&data->update_lock); | 368 | mutex_lock(&data->update_lock); |
368 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); | 369 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); |
369 | sis5595_write_value(client, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); | 370 | sis5595_write_value(client, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); |
370 | up(&data->update_lock); | 371 | mutex_unlock(&data->update_lock); |
371 | return count; | 372 | return count; |
372 | } | 373 | } |
373 | 374 | ||
@@ -390,7 +391,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, | |||
390 | unsigned long val = simple_strtoul(buf, NULL, 10); | 391 | unsigned long val = simple_strtoul(buf, NULL, 10); |
391 | int reg; | 392 | int reg; |
392 | 393 | ||
393 | down(&data->update_lock); | 394 | mutex_lock(&data->update_lock); |
394 | min = FAN_FROM_REG(data->fan_min[nr], | 395 | min = FAN_FROM_REG(data->fan_min[nr], |
395 | DIV_FROM_REG(data->fan_div[nr])); | 396 | DIV_FROM_REG(data->fan_div[nr])); |
396 | reg = sis5595_read_value(client, SIS5595_REG_FANDIV); | 397 | 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 | default: | 404 | default: |
404 | dev_err(&client->dev, "fan_div value %ld not " | 405 | dev_err(&client->dev, "fan_div value %ld not " |
405 | "supported. Choose one of 1, 2, 4 or 8!\n", val); | 406 | "supported. Choose one of 1, 2, 4 or 8!\n", val); |
406 | up(&data->update_lock); | 407 | mutex_unlock(&data->update_lock); |
407 | return -EINVAL; | 408 | return -EINVAL; |
408 | } | 409 | } |
409 | 410 | ||
@@ -419,7 +420,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, | |||
419 | data->fan_min[nr] = | 420 | data->fan_min[nr] = |
420 | FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); | 421 | FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); |
421 | sis5595_write_value(client, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); | 422 | sis5595_write_value(client, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); |
422 | up(&data->update_lock); | 423 | mutex_unlock(&data->update_lock); |
423 | return count; | 424 | return count; |
424 | } | 425 | } |
425 | 426 | ||
@@ -527,7 +528,7 @@ static int sis5595_detect(struct i2c_adapter *adapter) | |||
527 | 528 | ||
528 | new_client = &data->client; | 529 | new_client = &data->client; |
529 | new_client->addr = address; | 530 | new_client->addr = address; |
530 | init_MUTEX(&data->lock); | 531 | mutex_init(&data->lock); |
531 | i2c_set_clientdata(new_client, data); | 532 | i2c_set_clientdata(new_client, data); |
532 | new_client->adapter = adapter; | 533 | new_client->adapter = adapter; |
533 | new_client->driver = &sis5595_driver; | 534 | new_client->driver = &sis5595_driver; |
@@ -548,7 +549,7 @@ static int sis5595_detect(struct i2c_adapter *adapter) | |||
548 | strlcpy(new_client->name, "sis5595", I2C_NAME_SIZE); | 549 | strlcpy(new_client->name, "sis5595", I2C_NAME_SIZE); |
549 | 550 | ||
550 | data->valid = 0; | 551 | data->valid = 0; |
551 | init_MUTEX(&data->update_lock); | 552 | mutex_init(&data->update_lock); |
552 | 553 | ||
553 | /* Tell the I2C layer a new client has arrived */ | 554 | /* Tell the I2C layer a new client has arrived */ |
554 | if ((err = i2c_attach_client(new_client))) | 555 | if ((err = i2c_attach_client(new_client))) |
@@ -635,20 +636,20 @@ static int sis5595_read_value(struct i2c_client *client, u8 reg) | |||
635 | int res; | 636 | int res; |
636 | 637 | ||
637 | struct sis5595_data *data = i2c_get_clientdata(client); | 638 | struct sis5595_data *data = i2c_get_clientdata(client); |
638 | down(&data->lock); | 639 | mutex_lock(&data->lock); |
639 | outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET); | 640 | outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET); |
640 | res = inb_p(client->addr + SIS5595_DATA_REG_OFFSET); | 641 | res = inb_p(client->addr + SIS5595_DATA_REG_OFFSET); |
641 | up(&data->lock); | 642 | mutex_unlock(&data->lock); |
642 | return res; | 643 | return res; |
643 | } | 644 | } |
644 | 645 | ||
645 | static int sis5595_write_value(struct i2c_client *client, u8 reg, u8 value) | 646 | static int sis5595_write_value(struct i2c_client *client, u8 reg, u8 value) |
646 | { | 647 | { |
647 | struct sis5595_data *data = i2c_get_clientdata(client); | 648 | struct sis5595_data *data = i2c_get_clientdata(client); |
648 | down(&data->lock); | 649 | mutex_lock(&data->lock); |
649 | outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET); | 650 | outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET); |
650 | outb_p(value, client->addr + SIS5595_DATA_REG_OFFSET); | 651 | outb_p(value, client->addr + SIS5595_DATA_REG_OFFSET); |
651 | up(&data->lock); | 652 | mutex_unlock(&data->lock); |
652 | return 0; | 653 | return 0; |
653 | } | 654 | } |
654 | 655 | ||
@@ -667,7 +668,7 @@ static struct sis5595_data *sis5595_update_device(struct device *dev) | |||
667 | struct sis5595_data *data = i2c_get_clientdata(client); | 668 | struct sis5595_data *data = i2c_get_clientdata(client); |
668 | int i; | 669 | int i; |
669 | 670 | ||
670 | down(&data->update_lock); | 671 | mutex_lock(&data->update_lock); |
671 | 672 | ||
672 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) | 673 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) |
673 | || !data->valid) { | 674 | || !data->valid) { |
@@ -707,7 +708,7 @@ static struct sis5595_data *sis5595_update_device(struct device *dev) | |||
707 | data->valid = 1; | 708 | data->valid = 1; |
708 | } | 709 | } |
709 | 710 | ||
710 | up(&data->update_lock); | 711 | mutex_unlock(&data->update_lock); |
711 | 712 | ||
712 | return data; | 713 | return data; |
713 | } | 714 | } |