diff options
Diffstat (limited to 'drivers/hwmon/it87.c')
-rw-r--r-- | drivers/hwmon/it87.c | 61 |
1 files changed, 31 insertions, 30 deletions
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c index d7a9401600bb..122ff9cd75cb 100644 --- a/drivers/hwmon/it87.c +++ b/drivers/hwmon/it87.c | |||
@@ -41,6 +41,7 @@ | |||
41 | #include <linux/hwmon-sysfs.h> | 41 | #include <linux/hwmon-sysfs.h> |
42 | #include <linux/hwmon-vid.h> | 42 | #include <linux/hwmon-vid.h> |
43 | #include <linux/err.h> | 43 | #include <linux/err.h> |
44 | #include <linux/mutex.h> | ||
44 | #include <asm/io.h> | 45 | #include <asm/io.h> |
45 | 46 | ||
46 | 47 | ||
@@ -194,10 +195,10 @@ static int DIV_TO_REG(int val) | |||
194 | struct it87_data { | 195 | struct it87_data { |
195 | struct i2c_client client; | 196 | struct i2c_client client; |
196 | struct class_device *class_dev; | 197 | struct class_device *class_dev; |
197 | struct semaphore lock; | 198 | struct mutex lock; |
198 | enum chips type; | 199 | enum chips type; |
199 | 200 | ||
200 | struct semaphore update_lock; | 201 | struct mutex update_lock; |
201 | char valid; /* !=0 if following fields are valid */ | 202 | char valid; /* !=0 if following fields are valid */ |
202 | unsigned long last_updated; /* In jiffies */ | 203 | unsigned long last_updated; /* In jiffies */ |
203 | 204 | ||
@@ -290,11 +291,11 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | |||
290 | struct it87_data *data = i2c_get_clientdata(client); | 291 | struct it87_data *data = i2c_get_clientdata(client); |
291 | unsigned long val = simple_strtoul(buf, NULL, 10); | 292 | unsigned long val = simple_strtoul(buf, NULL, 10); |
292 | 293 | ||
293 | down(&data->update_lock); | 294 | mutex_lock(&data->update_lock); |
294 | data->in_min[nr] = IN_TO_REG(val); | 295 | data->in_min[nr] = IN_TO_REG(val); |
295 | it87_write_value(client, IT87_REG_VIN_MIN(nr), | 296 | it87_write_value(client, IT87_REG_VIN_MIN(nr), |
296 | data->in_min[nr]); | 297 | data->in_min[nr]); |
297 | up(&data->update_lock); | 298 | mutex_unlock(&data->update_lock); |
298 | return count; | 299 | return count; |
299 | } | 300 | } |
300 | static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, | 301 | 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 | struct it87_data *data = i2c_get_clientdata(client); | 308 | struct it87_data *data = i2c_get_clientdata(client); |
308 | unsigned long val = simple_strtoul(buf, NULL, 10); | 309 | unsigned long val = simple_strtoul(buf, NULL, 10); |
309 | 310 | ||
310 | down(&data->update_lock); | 311 | mutex_lock(&data->update_lock); |
311 | data->in_max[nr] = IN_TO_REG(val); | 312 | data->in_max[nr] = IN_TO_REG(val); |
312 | it87_write_value(client, IT87_REG_VIN_MAX(nr), | 313 | it87_write_value(client, IT87_REG_VIN_MAX(nr), |
313 | data->in_max[nr]); | 314 | data->in_max[nr]); |
314 | up(&data->update_lock); | 315 | mutex_unlock(&data->update_lock); |
315 | return count; | 316 | return count; |
316 | } | 317 | } |
317 | 318 | ||
@@ -381,10 +382,10 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
381 | struct it87_data *data = i2c_get_clientdata(client); | 382 | struct it87_data *data = i2c_get_clientdata(client); |
382 | int val = simple_strtol(buf, NULL, 10); | 383 | int val = simple_strtol(buf, NULL, 10); |
383 | 384 | ||
384 | down(&data->update_lock); | 385 | mutex_lock(&data->update_lock); |
385 | data->temp_high[nr] = TEMP_TO_REG(val); | 386 | data->temp_high[nr] = TEMP_TO_REG(val); |
386 | it87_write_value(client, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]); | 387 | it87_write_value(client, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]); |
387 | up(&data->update_lock); | 388 | mutex_unlock(&data->update_lock); |
388 | return count; | 389 | return count; |
389 | } | 390 | } |
390 | static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | 391 | 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 | struct it87_data *data = i2c_get_clientdata(client); | 398 | struct it87_data *data = i2c_get_clientdata(client); |
398 | int val = simple_strtol(buf, NULL, 10); | 399 | int val = simple_strtol(buf, NULL, 10); |
399 | 400 | ||
400 | down(&data->update_lock); | 401 | mutex_lock(&data->update_lock); |
401 | data->temp_low[nr] = TEMP_TO_REG(val); | 402 | data->temp_low[nr] = TEMP_TO_REG(val); |
402 | it87_write_value(client, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]); | 403 | it87_write_value(client, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]); |
403 | up(&data->update_lock); | 404 | mutex_unlock(&data->update_lock); |
404 | return count; | 405 | return count; |
405 | } | 406 | } |
406 | #define show_temp_offset(offset) \ | 407 | #define show_temp_offset(offset) \ |
@@ -440,7 +441,7 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr, | |||
440 | struct it87_data *data = i2c_get_clientdata(client); | 441 | struct it87_data *data = i2c_get_clientdata(client); |
441 | int val = simple_strtol(buf, NULL, 10); | 442 | int val = simple_strtol(buf, NULL, 10); |
442 | 443 | ||
443 | down(&data->update_lock); | 444 | mutex_lock(&data->update_lock); |
444 | 445 | ||
445 | data->sensor &= ~(1 << nr); | 446 | data->sensor &= ~(1 << nr); |
446 | data->sensor &= ~(8 << nr); | 447 | data->sensor &= ~(8 << nr); |
@@ -450,11 +451,11 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr, | |||
450 | else if (val == 2) | 451 | else if (val == 2) |
451 | data->sensor |= 8 << nr; | 452 | data->sensor |= 8 << nr; |
452 | else if (val != 0) { | 453 | else if (val != 0) { |
453 | up(&data->update_lock); | 454 | mutex_unlock(&data->update_lock); |
454 | return -EINVAL; | 455 | return -EINVAL; |
455 | } | 456 | } |
456 | it87_write_value(client, IT87_REG_TEMP_ENABLE, data->sensor); | 457 | it87_write_value(client, IT87_REG_TEMP_ENABLE, data->sensor); |
457 | up(&data->update_lock); | 458 | mutex_unlock(&data->update_lock); |
458 | return count; | 459 | return count; |
459 | } | 460 | } |
460 | #define show_sensor_offset(offset) \ | 461 | #define show_sensor_offset(offset) \ |
@@ -524,7 +525,7 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | |||
524 | int val = simple_strtol(buf, NULL, 10); | 525 | int val = simple_strtol(buf, NULL, 10); |
525 | u8 reg = it87_read_value(client, IT87_REG_FAN_DIV); | 526 | u8 reg = it87_read_value(client, IT87_REG_FAN_DIV); |
526 | 527 | ||
527 | down(&data->update_lock); | 528 | mutex_lock(&data->update_lock); |
528 | switch (nr) { | 529 | switch (nr) { |
529 | case 0: data->fan_div[nr] = reg & 0x07; break; | 530 | case 0: data->fan_div[nr] = reg & 0x07; break; |
530 | case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break; | 531 | 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 | 534 | ||
534 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); | 535 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); |
535 | it87_write_value(client, IT87_REG_FAN_MIN(nr), data->fan_min[nr]); | 536 | it87_write_value(client, IT87_REG_FAN_MIN(nr), data->fan_min[nr]); |
536 | up(&data->update_lock); | 537 | mutex_unlock(&data->update_lock); |
537 | return count; | 538 | return count; |
538 | } | 539 | } |
539 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | 540 | 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 | int i, min[3]; | 549 | int i, min[3]; |
549 | u8 old; | 550 | u8 old; |
550 | 551 | ||
551 | down(&data->update_lock); | 552 | mutex_lock(&data->update_lock); |
552 | old = it87_read_value(client, IT87_REG_FAN_DIV); | 553 | old = it87_read_value(client, IT87_REG_FAN_DIV); |
553 | 554 | ||
554 | for (i = 0; i < 3; i++) | 555 | for (i = 0; i < 3; i++) |
@@ -576,7 +577,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | |||
576 | data->fan_min[i]=FAN_TO_REG(min[i], DIV_FROM_REG(data->fan_div[i])); | 577 | data->fan_min[i]=FAN_TO_REG(min[i], DIV_FROM_REG(data->fan_div[i])); |
577 | it87_write_value(client, IT87_REG_FAN_MIN(i), data->fan_min[i]); | 578 | it87_write_value(client, IT87_REG_FAN_MIN(i), data->fan_min[i]); |
578 | } | 579 | } |
579 | up(&data->update_lock); | 580 | mutex_unlock(&data->update_lock); |
580 | return count; | 581 | return count; |
581 | } | 582 | } |
582 | static ssize_t set_pwm_enable(struct device *dev, | 583 | static ssize_t set_pwm_enable(struct device *dev, |
@@ -589,7 +590,7 @@ static ssize_t set_pwm_enable(struct device *dev, | |||
589 | struct it87_data *data = i2c_get_clientdata(client); | 590 | struct it87_data *data = i2c_get_clientdata(client); |
590 | int val = simple_strtol(buf, NULL, 10); | 591 | int val = simple_strtol(buf, NULL, 10); |
591 | 592 | ||
592 | down(&data->update_lock); | 593 | mutex_lock(&data->update_lock); |
593 | 594 | ||
594 | if (val == 0) { | 595 | if (val == 0) { |
595 | int tmp; | 596 | int tmp; |
@@ -606,11 +607,11 @@ static ssize_t set_pwm_enable(struct device *dev, | |||
606 | /* set saved pwm value, clear FAN_CTLX PWM mode bit */ | 607 | /* set saved pwm value, clear FAN_CTLX PWM mode bit */ |
607 | it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); | 608 | it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); |
608 | } else { | 609 | } else { |
609 | up(&data->update_lock); | 610 | mutex_unlock(&data->update_lock); |
610 | return -EINVAL; | 611 | return -EINVAL; |
611 | } | 612 | } |
612 | 613 | ||
613 | up(&data->update_lock); | 614 | mutex_unlock(&data->update_lock); |
614 | return count; | 615 | return count; |
615 | } | 616 | } |
616 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | 617 | 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 | if (val < 0 || val > 255) | 627 | if (val < 0 || val > 255) |
627 | return -EINVAL; | 628 | return -EINVAL; |
628 | 629 | ||
629 | down(&data->update_lock); | 630 | mutex_lock(&data->update_lock); |
630 | data->manual_pwm_ctl[nr] = val; | 631 | data->manual_pwm_ctl[nr] = val; |
631 | if (data->fan_main_ctrl & (1 << nr)) | 632 | if (data->fan_main_ctrl & (1 << nr)) |
632 | it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); | 633 | it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); |
633 | up(&data->update_lock); | 634 | mutex_unlock(&data->update_lock); |
634 | return count; | 635 | return count; |
635 | } | 636 | } |
636 | 637 | ||
@@ -776,7 +777,7 @@ static int it87_detect(struct i2c_adapter *adapter, int address, int kind) | |||
776 | 777 | ||
777 | new_client = &data->client; | 778 | new_client = &data->client; |
778 | if (is_isa) | 779 | if (is_isa) |
779 | init_MUTEX(&data->lock); | 780 | mutex_init(&data->lock); |
780 | i2c_set_clientdata(new_client, data); | 781 | i2c_set_clientdata(new_client, data); |
781 | new_client->addr = address; | 782 | new_client->addr = address; |
782 | new_client->adapter = adapter; | 783 | new_client->adapter = adapter; |
@@ -823,7 +824,7 @@ static int it87_detect(struct i2c_adapter *adapter, int address, int kind) | |||
823 | strlcpy(new_client->name, name, I2C_NAME_SIZE); | 824 | strlcpy(new_client->name, name, I2C_NAME_SIZE); |
824 | data->type = kind; | 825 | data->type = kind; |
825 | data->valid = 0; | 826 | data->valid = 0; |
826 | init_MUTEX(&data->update_lock); | 827 | mutex_init(&data->update_lock); |
827 | 828 | ||
828 | /* Tell the I2C layer a new client has arrived */ | 829 | /* Tell the I2C layer a new client has arrived */ |
829 | if ((err = i2c_attach_client(new_client))) | 830 | if ((err = i2c_attach_client(new_client))) |
@@ -950,10 +951,10 @@ static int it87_read_value(struct i2c_client *client, u8 reg) | |||
950 | 951 | ||
951 | int res; | 952 | int res; |
952 | if (i2c_is_isa_client(client)) { | 953 | if (i2c_is_isa_client(client)) { |
953 | down(&data->lock); | 954 | mutex_lock(&data->lock); |
954 | outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); | 955 | outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); |
955 | res = inb_p(client->addr + IT87_DATA_REG_OFFSET); | 956 | res = inb_p(client->addr + IT87_DATA_REG_OFFSET); |
956 | up(&data->lock); | 957 | mutex_unlock(&data->lock); |
957 | return res; | 958 | return res; |
958 | } else | 959 | } else |
959 | return i2c_smbus_read_byte_data(client, reg); | 960 | 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 | struct it87_data *data = i2c_get_clientdata(client); | 970 | struct it87_data *data = i2c_get_clientdata(client); |
970 | 971 | ||
971 | if (i2c_is_isa_client(client)) { | 972 | if (i2c_is_isa_client(client)) { |
972 | down(&data->lock); | 973 | mutex_lock(&data->lock); |
973 | outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); | 974 | outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); |
974 | outb_p(value, client->addr + IT87_DATA_REG_OFFSET); | 975 | outb_p(value, client->addr + IT87_DATA_REG_OFFSET); |
975 | up(&data->lock); | 976 | mutex_unlock(&data->lock); |
976 | return 0; | 977 | return 0; |
977 | } else | 978 | } else |
978 | return i2c_smbus_write_byte_data(client, reg, value); | 979 | return i2c_smbus_write_byte_data(client, reg, value); |
@@ -1098,7 +1099,7 @@ static struct it87_data *it87_update_device(struct device *dev) | |||
1098 | struct it87_data *data = i2c_get_clientdata(client); | 1099 | struct it87_data *data = i2c_get_clientdata(client); |
1099 | int i; | 1100 | int i; |
1100 | 1101 | ||
1101 | down(&data->update_lock); | 1102 | mutex_lock(&data->update_lock); |
1102 | 1103 | ||
1103 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) | 1104 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) |
1104 | || !data->valid) { | 1105 | || !data->valid) { |
@@ -1160,7 +1161,7 @@ static struct it87_data *it87_update_device(struct device *dev) | |||
1160 | data->valid = 1; | 1161 | data->valid = 1; |
1161 | } | 1162 | } |
1162 | 1163 | ||
1163 | up(&data->update_lock); | 1164 | mutex_unlock(&data->update_lock); |
1164 | 1165 | ||
1165 | return data; | 1166 | return data; |
1166 | } | 1167 | } |