diff options
Diffstat (limited to 'drivers/hwmon/w83781d.c')
-rw-r--r-- | drivers/hwmon/w83781d.c | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c index 64c1f8af5bb2..782117817526 100644 --- a/drivers/hwmon/w83781d.c +++ b/drivers/hwmon/w83781d.c | |||
@@ -42,6 +42,7 @@ | |||
42 | #include <linux/hwmon.h> | 42 | #include <linux/hwmon.h> |
43 | #include <linux/hwmon-vid.h> | 43 | #include <linux/hwmon-vid.h> |
44 | #include <linux/err.h> | 44 | #include <linux/err.h> |
45 | #include <linux/mutex.h> | ||
45 | #include <asm/io.h> | 46 | #include <asm/io.h> |
46 | #include "lm75.h" | 47 | #include "lm75.h" |
47 | 48 | ||
@@ -226,10 +227,10 @@ DIV_TO_REG(long val, enum chips type) | |||
226 | struct w83781d_data { | 227 | struct w83781d_data { |
227 | struct i2c_client client; | 228 | struct i2c_client client; |
228 | struct class_device *class_dev; | 229 | struct class_device *class_dev; |
229 | struct semaphore lock; | 230 | struct mutex lock; |
230 | enum chips type; | 231 | enum chips type; |
231 | 232 | ||
232 | struct semaphore update_lock; | 233 | struct mutex update_lock; |
233 | char valid; /* !=0 if following fields are valid */ | 234 | char valid; /* !=0 if following fields are valid */ |
234 | unsigned long last_updated; /* In jiffies */ | 235 | unsigned long last_updated; /* In jiffies */ |
235 | 236 | ||
@@ -311,11 +312,11 @@ static ssize_t store_in_##reg (struct device *dev, const char *buf, size_t count | |||
311 | \ | 312 | \ |
312 | val = simple_strtoul(buf, NULL, 10) / 10; \ | 313 | val = simple_strtoul(buf, NULL, 10) / 10; \ |
313 | \ | 314 | \ |
314 | down(&data->update_lock); \ | 315 | mutex_lock(&data->update_lock); \ |
315 | data->in_##reg[nr] = IN_TO_REG(val); \ | 316 | data->in_##reg[nr] = IN_TO_REG(val); \ |
316 | w83781d_write_value(client, W83781D_REG_IN_##REG(nr), data->in_##reg[nr]); \ | 317 | w83781d_write_value(client, W83781D_REG_IN_##REG(nr), data->in_##reg[nr]); \ |
317 | \ | 318 | \ |
318 | up(&data->update_lock); \ | 319 | mutex_unlock(&data->update_lock); \ |
319 | return count; \ | 320 | return count; \ |
320 | } | 321 | } |
321 | store_in_reg(MIN, min); | 322 | store_in_reg(MIN, min); |
@@ -381,13 +382,13 @@ store_fan_min(struct device *dev, const char *buf, size_t count, int nr) | |||
381 | 382 | ||
382 | val = simple_strtoul(buf, NULL, 10); | 383 | val = simple_strtoul(buf, NULL, 10); |
383 | 384 | ||
384 | down(&data->update_lock); | 385 | mutex_lock(&data->update_lock); |
385 | data->fan_min[nr - 1] = | 386 | data->fan_min[nr - 1] = |
386 | FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr - 1])); | 387 | FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr - 1])); |
387 | w83781d_write_value(client, W83781D_REG_FAN_MIN(nr), | 388 | w83781d_write_value(client, W83781D_REG_FAN_MIN(nr), |
388 | data->fan_min[nr - 1]); | 389 | data->fan_min[nr - 1]); |
389 | 390 | ||
390 | up(&data->update_lock); | 391 | mutex_unlock(&data->update_lock); |
391 | return count; | 392 | return count; |
392 | } | 393 | } |
393 | 394 | ||
@@ -446,7 +447,7 @@ static ssize_t store_temp_##reg (struct device *dev, const char *buf, size_t cou | |||
446 | \ | 447 | \ |
447 | val = simple_strtol(buf, NULL, 10); \ | 448 | val = simple_strtol(buf, NULL, 10); \ |
448 | \ | 449 | \ |
449 | down(&data->update_lock); \ | 450 | mutex_lock(&data->update_lock); \ |
450 | \ | 451 | \ |
451 | if (nr >= 2) { /* TEMP2 and TEMP3 */ \ | 452 | if (nr >= 2) { /* TEMP2 and TEMP3 */ \ |
452 | data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \ | 453 | 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 | data->temp_##reg); \ | 459 | data->temp_##reg); \ |
459 | } \ | 460 | } \ |
460 | \ | 461 | \ |
461 | up(&data->update_lock); \ | 462 | mutex_unlock(&data->update_lock); \ |
462 | return count; \ | 463 | return count; \ |
463 | } | 464 | } |
464 | store_temp_reg(OVER, max); | 465 | store_temp_reg(OVER, max); |
@@ -571,7 +572,7 @@ store_beep_reg(struct device *dev, const char *buf, size_t count, | |||
571 | 572 | ||
572 | val = simple_strtoul(buf, NULL, 10); | 573 | val = simple_strtoul(buf, NULL, 10); |
573 | 574 | ||
574 | down(&data->update_lock); | 575 | mutex_lock(&data->update_lock); |
575 | 576 | ||
576 | if (update_mask == BEEP_MASK) { /* We are storing beep_mask */ | 577 | if (update_mask == BEEP_MASK) { /* We are storing beep_mask */ |
577 | data->beep_mask = BEEP_MASK_TO_REG(val, data->type); | 578 | 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 | w83781d_write_value(client, W83781D_REG_BEEP_INTS2, | 593 | w83781d_write_value(client, W83781D_REG_BEEP_INTS2, |
593 | val2 | data->beep_enable << 7); | 594 | val2 | data->beep_enable << 7); |
594 | 595 | ||
595 | up(&data->update_lock); | 596 | mutex_unlock(&data->update_lock); |
596 | return count; | 597 | return count; |
597 | } | 598 | } |
598 | 599 | ||
@@ -637,7 +638,7 @@ store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr) | |||
637 | u8 reg; | 638 | u8 reg; |
638 | unsigned long val = simple_strtoul(buf, NULL, 10); | 639 | unsigned long val = simple_strtoul(buf, NULL, 10); |
639 | 640 | ||
640 | down(&data->update_lock); | 641 | mutex_lock(&data->update_lock); |
641 | 642 | ||
642 | /* Save fan_min */ | 643 | /* Save fan_min */ |
643 | min = FAN_FROM_REG(data->fan_min[nr], | 644 | 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 | data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); | 663 | data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); |
663 | w83781d_write_value(client, W83781D_REG_FAN_MIN(nr+1), data->fan_min[nr]); | 664 | w83781d_write_value(client, W83781D_REG_FAN_MIN(nr+1), data->fan_min[nr]); |
664 | 665 | ||
665 | up(&data->update_lock); | 666 | mutex_unlock(&data->update_lock); |
666 | return count; | 667 | return count; |
667 | } | 668 | } |
668 | 669 | ||
@@ -709,10 +710,10 @@ store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr) | |||
709 | 710 | ||
710 | val = simple_strtoul(buf, NULL, 10); | 711 | val = simple_strtoul(buf, NULL, 10); |
711 | 712 | ||
712 | down(&data->update_lock); | 713 | mutex_lock(&data->update_lock); |
713 | data->pwm[nr - 1] = PWM_TO_REG(val); | 714 | data->pwm[nr - 1] = PWM_TO_REG(val); |
714 | w83781d_write_value(client, W83781D_REG_PWM(nr), data->pwm[nr - 1]); | 715 | w83781d_write_value(client, W83781D_REG_PWM(nr), data->pwm[nr - 1]); |
715 | up(&data->update_lock); | 716 | mutex_unlock(&data->update_lock); |
716 | return count; | 717 | return count; |
717 | } | 718 | } |
718 | 719 | ||
@@ -725,7 +726,7 @@ store_pwmenable_reg(struct device *dev, const char *buf, size_t count, int nr) | |||
725 | 726 | ||
726 | val = simple_strtoul(buf, NULL, 10); | 727 | val = simple_strtoul(buf, NULL, 10); |
727 | 728 | ||
728 | down(&data->update_lock); | 729 | mutex_lock(&data->update_lock); |
729 | 730 | ||
730 | switch (val) { | 731 | switch (val) { |
731 | case 0: | 732 | case 0: |
@@ -742,11 +743,11 @@ store_pwmenable_reg(struct device *dev, const char *buf, size_t count, int nr) | |||
742 | break; | 743 | break; |
743 | 744 | ||
744 | default: | 745 | default: |
745 | up(&data->update_lock); | 746 | mutex_unlock(&data->update_lock); |
746 | return -EINVAL; | 747 | return -EINVAL; |
747 | } | 748 | } |
748 | 749 | ||
749 | up(&data->update_lock); | 750 | mutex_unlock(&data->update_lock); |
750 | return count; | 751 | return count; |
751 | } | 752 | } |
752 | 753 | ||
@@ -808,7 +809,7 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr) | |||
808 | 809 | ||
809 | val = simple_strtoul(buf, NULL, 10); | 810 | val = simple_strtoul(buf, NULL, 10); |
810 | 811 | ||
811 | down(&data->update_lock); | 812 | mutex_lock(&data->update_lock); |
812 | 813 | ||
813 | switch (val) { | 814 | switch (val) { |
814 | case 1: /* PII/Celeron diode */ | 815 | case 1: /* PII/Celeron diode */ |
@@ -841,7 +842,7 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr) | |||
841 | break; | 842 | break; |
842 | } | 843 | } |
843 | 844 | ||
844 | up(&data->update_lock); | 845 | mutex_unlock(&data->update_lock); |
845 | return count; | 846 | return count; |
846 | } | 847 | } |
847 | 848 | ||
@@ -1073,7 +1074,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1073 | new_client = &data->client; | 1074 | new_client = &data->client; |
1074 | i2c_set_clientdata(new_client, data); | 1075 | i2c_set_clientdata(new_client, data); |
1075 | new_client->addr = address; | 1076 | new_client->addr = address; |
1076 | init_MUTEX(&data->lock); | 1077 | mutex_init(&data->lock); |
1077 | new_client->adapter = adapter; | 1078 | new_client->adapter = adapter; |
1078 | new_client->driver = is_isa ? &w83781d_isa_driver : &w83781d_driver; | 1079 | new_client->driver = is_isa ? &w83781d_isa_driver : &w83781d_driver; |
1079 | new_client->flags = 0; | 1080 | new_client->flags = 0; |
@@ -1178,7 +1179,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind) | |||
1178 | data->type = kind; | 1179 | data->type = kind; |
1179 | 1180 | ||
1180 | data->valid = 0; | 1181 | data->valid = 0; |
1181 | init_MUTEX(&data->update_lock); | 1182 | mutex_init(&data->update_lock); |
1182 | 1183 | ||
1183 | /* Tell the I2C layer a new client has arrived */ | 1184 | /* Tell the I2C layer a new client has arrived */ |
1184 | if ((err = i2c_attach_client(new_client))) | 1185 | if ((err = i2c_attach_client(new_client))) |
@@ -1325,7 +1326,7 @@ w83781d_read_value(struct i2c_client *client, u16 reg) | |||
1325 | int res, word_sized, bank; | 1326 | int res, word_sized, bank; |
1326 | struct i2c_client *cl; | 1327 | struct i2c_client *cl; |
1327 | 1328 | ||
1328 | down(&data->lock); | 1329 | mutex_lock(&data->lock); |
1329 | if (i2c_is_isa_client(client)) { | 1330 | if (i2c_is_isa_client(client)) { |
1330 | word_sized = (((reg & 0xff00) == 0x100) | 1331 | word_sized = (((reg & 0xff00) == 0x100) |
1331 | || ((reg & 0xff00) == 0x200)) | 1332 | || ((reg & 0xff00) == 0x200)) |
@@ -1383,7 +1384,7 @@ w83781d_read_value(struct i2c_client *client, u16 reg) | |||
1383 | if (bank > 2) | 1384 | if (bank > 2) |
1384 | i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 0); | 1385 | i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 0); |
1385 | } | 1386 | } |
1386 | up(&data->lock); | 1387 | mutex_unlock(&data->lock); |
1387 | return res; | 1388 | return res; |
1388 | } | 1389 | } |
1389 | 1390 | ||
@@ -1394,7 +1395,7 @@ w83781d_write_value(struct i2c_client *client, u16 reg, u16 value) | |||
1394 | int word_sized, bank; | 1395 | int word_sized, bank; |
1395 | struct i2c_client *cl; | 1396 | struct i2c_client *cl; |
1396 | 1397 | ||
1397 | down(&data->lock); | 1398 | mutex_lock(&data->lock); |
1398 | if (i2c_is_isa_client(client)) { | 1399 | if (i2c_is_isa_client(client)) { |
1399 | word_sized = (((reg & 0xff00) == 0x100) | 1400 | word_sized = (((reg & 0xff00) == 0x100) |
1400 | || ((reg & 0xff00) == 0x200)) | 1401 | || ((reg & 0xff00) == 0x200)) |
@@ -1447,7 +1448,7 @@ w83781d_write_value(struct i2c_client *client, u16 reg, u16 value) | |||
1447 | if (bank > 2) | 1448 | if (bank > 2) |
1448 | i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 0); | 1449 | i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 0); |
1449 | } | 1450 | } |
1450 | up(&data->lock); | 1451 | mutex_unlock(&data->lock); |
1451 | return 0; | 1452 | return 0; |
1452 | } | 1453 | } |
1453 | 1454 | ||
@@ -1533,7 +1534,7 @@ static struct w83781d_data *w83781d_update_device(struct device *dev) | |||
1533 | struct w83781d_data *data = i2c_get_clientdata(client); | 1534 | struct w83781d_data *data = i2c_get_clientdata(client); |
1534 | int i; | 1535 | int i; |
1535 | 1536 | ||
1536 | down(&data->update_lock); | 1537 | mutex_lock(&data->update_lock); |
1537 | 1538 | ||
1538 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) | 1539 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) |
1539 | || !data->valid) { | 1540 | || !data->valid) { |
@@ -1641,7 +1642,7 @@ static struct w83781d_data *w83781d_update_device(struct device *dev) | |||
1641 | data->valid = 1; | 1642 | data->valid = 1; |
1642 | } | 1643 | } |
1643 | 1644 | ||
1644 | up(&data->update_lock); | 1645 | mutex_unlock(&data->update_lock); |
1645 | 1646 | ||
1646 | return data; | 1647 | return data; |
1647 | } | 1648 | } |