aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/adm1031.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/adm1031.c')
-rw-r--r--drivers/hwmon/adm1031.c49
1 files changed, 25 insertions, 24 deletions
diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c
index d06397966081..3bf2da621aed 100644
--- a/drivers/hwmon/adm1031.c
+++ b/drivers/hwmon/adm1031.c
@@ -28,6 +28,7 @@
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/hwmon.h> 29#include <linux/hwmon.h>
30#include <linux/err.h> 30#include <linux/err.h>
31#include <linux/mutex.h>
31 32
32/* Following macros takes channel parameter starting from 0 to 2 */ 33/* Following macros takes channel parameter starting from 0 to 2 */
33#define ADM1031_REG_FAN_SPEED(nr) (0x08 + (nr)) 34#define ADM1031_REG_FAN_SPEED(nr) (0x08 + (nr))
@@ -70,7 +71,7 @@ typedef u8 auto_chan_table_t[8][2];
70struct adm1031_data { 71struct adm1031_data {
71 struct i2c_client client; 72 struct i2c_client client;
72 struct class_device *class_dev; 73 struct class_device *class_dev;
73 struct semaphore update_lock; 74 struct mutex update_lock;
74 int chip_type; 75 int chip_type;
75 char valid; /* !=0 if following fields are valid */ 76 char valid; /* !=0 if following fields are valid */
76 unsigned long last_updated; /* In jiffies */ 77 unsigned long last_updated; /* In jiffies */
@@ -262,10 +263,10 @@ set_fan_auto_channel(struct device *dev, const char *buf, size_t count, int nr)
262 263
263 old_fan_mode = data->conf1; 264 old_fan_mode = data->conf1;
264 265
265 down(&data->update_lock); 266 mutex_lock(&data->update_lock);
266 267
267 if ((ret = get_fan_auto_nearest(data, nr, val, data->conf1, &reg))) { 268 if ((ret = get_fan_auto_nearest(data, nr, val, data->conf1, &reg))) {
268 up(&data->update_lock); 269 mutex_unlock(&data->update_lock);
269 return ret; 270 return ret;
270 } 271 }
271 if (((data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1)) & ADM1031_CONF1_AUTO_MODE) ^ 272 if (((data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1)) & ADM1031_CONF1_AUTO_MODE) ^
@@ -288,7 +289,7 @@ set_fan_auto_channel(struct device *dev, const char *buf, size_t count, int nr)
288 } 289 }
289 data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1); 290 data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1);
290 adm1031_write_value(client, ADM1031_REG_CONF1, data->conf1); 291 adm1031_write_value(client, ADM1031_REG_CONF1, data->conf1);
291 up(&data->update_lock); 292 mutex_unlock(&data->update_lock);
292 return count; 293 return count;
293} 294}
294 295
@@ -329,11 +330,11 @@ set_auto_temp_min(struct device *dev, const char *buf, size_t count, int nr)
329 struct adm1031_data *data = i2c_get_clientdata(client); 330 struct adm1031_data *data = i2c_get_clientdata(client);
330 int val = simple_strtol(buf, NULL, 10); 331 int val = simple_strtol(buf, NULL, 10);
331 332
332 down(&data->update_lock); 333 mutex_lock(&data->update_lock);
333 data->auto_temp[nr] = AUTO_TEMP_MIN_TO_REG(val, data->auto_temp[nr]); 334 data->auto_temp[nr] = AUTO_TEMP_MIN_TO_REG(val, data->auto_temp[nr]);
334 adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr), 335 adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr),
335 data->auto_temp[nr]); 336 data->auto_temp[nr]);
336 up(&data->update_lock); 337 mutex_unlock(&data->update_lock);
337 return count; 338 return count;
338} 339}
339static ssize_t show_auto_temp_max(struct device *dev, char *buf, int nr) 340static ssize_t show_auto_temp_max(struct device *dev, char *buf, int nr)
@@ -349,11 +350,11 @@ set_auto_temp_max(struct device *dev, const char *buf, size_t count, int nr)
349 struct adm1031_data *data = i2c_get_clientdata(client); 350 struct adm1031_data *data = i2c_get_clientdata(client);
350 int val = simple_strtol(buf, NULL, 10); 351 int val = simple_strtol(buf, NULL, 10);
351 352
352 down(&data->update_lock); 353 mutex_lock(&data->update_lock);
353 data->temp_max[nr] = AUTO_TEMP_MAX_TO_REG(val, data->auto_temp[nr], data->pwm[nr]); 354 data->temp_max[nr] = AUTO_TEMP_MAX_TO_REG(val, data->auto_temp[nr], data->pwm[nr]);
354 adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr), 355 adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr),
355 data->temp_max[nr]); 356 data->temp_max[nr]);
356 up(&data->update_lock); 357 mutex_unlock(&data->update_lock);
357 return count; 358 return count;
358} 359}
359 360
@@ -405,11 +406,11 @@ set_pwm(struct device *dev, const char *buf, size_t count, int nr)
405 int val = simple_strtol(buf, NULL, 10); 406 int val = simple_strtol(buf, NULL, 10);
406 int reg; 407 int reg;
407 408
408 down(&data->update_lock); 409 mutex_lock(&data->update_lock);
409 if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) && 410 if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) &&
410 (((val>>4) & 0xf) != 5)) { 411 (((val>>4) & 0xf) != 5)) {
411 /* In automatic mode, the only PWM accepted is 33% */ 412 /* In automatic mode, the only PWM accepted is 33% */
412 up(&data->update_lock); 413 mutex_unlock(&data->update_lock);
413 return -EINVAL; 414 return -EINVAL;
414 } 415 }
415 data->pwm[nr] = PWM_TO_REG(val); 416 data->pwm[nr] = PWM_TO_REG(val);
@@ -417,7 +418,7 @@ set_pwm(struct device *dev, const char *buf, size_t count, int nr)
417 adm1031_write_value(client, ADM1031_REG_PWM, 418 adm1031_write_value(client, ADM1031_REG_PWM,
418 nr ? ((data->pwm[nr] << 4) & 0xf0) | (reg & 0xf) 419 nr ? ((data->pwm[nr] << 4) & 0xf0) | (reg & 0xf)
419 : (data->pwm[nr] & 0xf) | (reg & 0xf0)); 420 : (data->pwm[nr] & 0xf) | (reg & 0xf0));
420 up(&data->update_lock); 421 mutex_unlock(&data->update_lock);
421 return count; 422 return count;
422} 423}
423 424
@@ -511,7 +512,7 @@ set_fan_min(struct device *dev, const char *buf, size_t count, int nr)
511 struct adm1031_data *data = i2c_get_clientdata(client); 512 struct adm1031_data *data = i2c_get_clientdata(client);
512 int val = simple_strtol(buf, NULL, 10); 513 int val = simple_strtol(buf, NULL, 10);
513 514
514 down(&data->update_lock); 515 mutex_lock(&data->update_lock);
515 if (val) { 516 if (val) {
516 data->fan_min[nr] = 517 data->fan_min[nr] =
517 FAN_TO_REG(val, FAN_DIV_FROM_REG(data->fan_div[nr])); 518 FAN_TO_REG(val, FAN_DIV_FROM_REG(data->fan_div[nr]));
@@ -519,7 +520,7 @@ set_fan_min(struct device *dev, const char *buf, size_t count, int nr)
519 data->fan_min[nr] = 0xff; 520 data->fan_min[nr] = 0xff;
520 } 521 }
521 adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr), data->fan_min[nr]); 522 adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr), data->fan_min[nr]);
522 up(&data->update_lock); 523 mutex_unlock(&data->update_lock);
523 return count; 524 return count;
524} 525}
525static ssize_t 526static ssize_t
@@ -540,7 +541,7 @@ set_fan_div(struct device *dev, const char *buf, size_t count, int nr)
540 if (tmp == 0xff) 541 if (tmp == 0xff)
541 return -EINVAL; 542 return -EINVAL;
542 543
543 down(&data->update_lock); 544 mutex_lock(&data->update_lock);
544 old_div = FAN_DIV_FROM_REG(data->fan_div[nr]); 545 old_div = FAN_DIV_FROM_REG(data->fan_div[nr]);
545 data->fan_div[nr] = (tmp & 0xC0) | (0x3f & data->fan_div[nr]); 546 data->fan_div[nr] = (tmp & 0xC0) | (0x3f & data->fan_div[nr]);
546 new_min = data->fan_min[nr] * old_div / 547 new_min = data->fan_min[nr] * old_div /
@@ -553,7 +554,7 @@ set_fan_div(struct device *dev, const char *buf, size_t count, int nr)
553 data->fan_div[nr]); 554 data->fan_div[nr]);
554 adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr), 555 adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr),
555 data->fan_min[nr]); 556 data->fan_min[nr]);
556 up(&data->update_lock); 557 mutex_unlock(&data->update_lock);
557 return count; 558 return count;
558} 559}
559 560
@@ -627,11 +628,11 @@ set_temp_min(struct device *dev, const char *buf, size_t count, int nr)
627 628
628 val = simple_strtol(buf, NULL, 10); 629 val = simple_strtol(buf, NULL, 10);
629 val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875); 630 val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875);
630 down(&data->update_lock); 631 mutex_lock(&data->update_lock);
631 data->temp_min[nr] = TEMP_TO_REG(val); 632 data->temp_min[nr] = TEMP_TO_REG(val);
632 adm1031_write_value(client, ADM1031_REG_TEMP_MIN(nr), 633 adm1031_write_value(client, ADM1031_REG_TEMP_MIN(nr),
633 data->temp_min[nr]); 634 data->temp_min[nr]);
634 up(&data->update_lock); 635 mutex_unlock(&data->update_lock);
635 return count; 636 return count;
636} 637}
637static ssize_t 638static ssize_t
@@ -643,11 +644,11 @@ set_temp_max(struct device *dev, const char *buf, size_t count, int nr)
643 644
644 val = simple_strtol(buf, NULL, 10); 645 val = simple_strtol(buf, NULL, 10);
645 val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875); 646 val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875);
646 down(&data->update_lock); 647 mutex_lock(&data->update_lock);
647 data->temp_max[nr] = TEMP_TO_REG(val); 648 data->temp_max[nr] = TEMP_TO_REG(val);
648 adm1031_write_value(client, ADM1031_REG_TEMP_MAX(nr), 649 adm1031_write_value(client, ADM1031_REG_TEMP_MAX(nr),
649 data->temp_max[nr]); 650 data->temp_max[nr]);
650 up(&data->update_lock); 651 mutex_unlock(&data->update_lock);
651 return count; 652 return count;
652} 653}
653static ssize_t 654static ssize_t
@@ -659,11 +660,11 @@ set_temp_crit(struct device *dev, const char *buf, size_t count, int nr)
659 660
660 val = simple_strtol(buf, NULL, 10); 661 val = simple_strtol(buf, NULL, 10);
661 val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875); 662 val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875);
662 down(&data->update_lock); 663 mutex_lock(&data->update_lock);
663 data->temp_crit[nr] = TEMP_TO_REG(val); 664 data->temp_crit[nr] = TEMP_TO_REG(val);
664 adm1031_write_value(client, ADM1031_REG_TEMP_CRIT(nr), 665 adm1031_write_value(client, ADM1031_REG_TEMP_CRIT(nr),
665 data->temp_crit[nr]); 666 data->temp_crit[nr]);
666 up(&data->update_lock); 667 mutex_unlock(&data->update_lock);
667 return count; 668 return count;
668} 669}
669 670
@@ -778,7 +779,7 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
778 779
779 strlcpy(new_client->name, name, I2C_NAME_SIZE); 780 strlcpy(new_client->name, name, I2C_NAME_SIZE);
780 data->valid = 0; 781 data->valid = 0;
781 init_MUTEX(&data->update_lock); 782 mutex_init(&data->update_lock);
782 783
783 /* Tell the I2C layer a new client has arrived */ 784 /* Tell the I2C layer a new client has arrived */
784 if ((err = i2c_attach_client(new_client))) 785 if ((err = i2c_attach_client(new_client)))
@@ -891,7 +892,7 @@ static struct adm1031_data *adm1031_update_device(struct device *dev)
891 struct adm1031_data *data = i2c_get_clientdata(client); 892 struct adm1031_data *data = i2c_get_clientdata(client);
892 int chan; 893 int chan;
893 894
894 down(&data->update_lock); 895 mutex_lock(&data->update_lock);
895 896
896 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 897 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
897 || !data->valid) { 898 || !data->valid) {
@@ -965,7 +966,7 @@ static struct adm1031_data *adm1031_update_device(struct device *dev)
965 data->valid = 1; 966 data->valid = 1;
966 } 967 }
967 968
968 up(&data->update_lock); 969 mutex_unlock(&data->update_lock);
969 970
970 return data; 971 return data;
971} 972}