aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/hwmon/w83793.c434
1 files changed, 253 insertions, 181 deletions
diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
index 742bf1355f3d..834e49d1827b 100644
--- a/drivers/hwmon/w83793.c
+++ b/drivers/hwmon/w83793.c
@@ -1,34 +1,34 @@
1/* 1/*
2 w83793.c - Linux kernel driver for hardware monitoring 2 * w83793.c - Linux kernel driver for hardware monitoring
3 Copyright (C) 2006 Winbond Electronics Corp. 3 * Copyright (C) 2006 Winbond Electronics Corp.
4 Yuan Mu 4 * Yuan Mu
5 Rudolf Marek <r.marek@assembler.cz> 5 * Rudolf Marek <r.marek@assembler.cz>
6 Copyright (C) 2009-2010 Sven Anders <anders@anduras.de>, ANDURAS AG. 6 * Copyright (C) 2009-2010 Sven Anders <anders@anduras.de>, ANDURAS AG.
7 Watchdog driver part 7 * Watchdog driver part
8 (Based partially on fschmd driver, 8 * (Based partially on fschmd driver,
9 Copyright 2007-2008 by Hans de Goede) 9 * Copyright 2007-2008 by Hans de Goede)
10 10 *
11 This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by 12 * it under the terms of the GNU General Public License as published by
13 the Free Software Foundation - version 2. 13 * the Free Software Foundation - version 2.
14 14 *
15 This program is distributed in the hope that it will be useful, 15 * This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details. 18 * GNU General Public License for more details.
19 19 *
20 You should have received a copy of the GNU General Public License 20 * You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software 21 * along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 02110-1301 USA. 23 * 02110-1301 USA.
24*/ 24 */
25 25
26/* 26/*
27 Supports following chips: 27 * Supports following chips:
28 28 *
29 Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA 29 * Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
30 w83793 10 12 8 6 0x7b 0x5ca3 yes no 30 * w83793 10 12 8 6 0x7b 0x5ca3 yes no
31*/ 31 */
32 32
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/init.h> 34#include <linux/init.h>
@@ -78,9 +78,9 @@ MODULE_PARM_DESC(nowayout,
78 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); 78 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
79 79
80/* 80/*
81 Address 0x00, 0x0d, 0x0e, 0x0f in all three banks are reserved 81 * Address 0x00, 0x0d, 0x0e, 0x0f in all three banks are reserved
82 as ID, Bank Select registers 82 * as ID, Bank Select registers
83*/ 83 */
84#define W83793_REG_BANKSEL 0x00 84#define W83793_REG_BANKSEL 0x00
85#define W83793_REG_VENDORID 0x0d 85#define W83793_REG_VENDORID 0x0d
86#define W83793_REG_CHIPID 0x0e 86#define W83793_REG_CHIPID 0x0e
@@ -110,8 +110,10 @@ static u16 W83793_REG_TEMP_MODE[2] = { 0x5e, 0x5f };
110#define TEMP_CRIT_HYST 2 110#define TEMP_CRIT_HYST 2
111#define TEMP_WARN 3 111#define TEMP_WARN 3
112#define TEMP_WARN_HYST 4 112#define TEMP_WARN_HYST 4
113/* only crit and crit_hyst affect real-time alarm status 113/*
114 current crit crit_hyst warn warn_hyst */ 114 * only crit and crit_hyst affect real-time alarm status
115 * current crit crit_hyst warn warn_hyst
116 */
115static u16 W83793_REG_TEMP[][5] = { 117static u16 W83793_REG_TEMP[][5] = {
116 {0x1c, 0x78, 0x79, 0x7a, 0x7b}, 118 {0x1c, 0x78, 0x79, 0x7a, 0x7b},
117 {0x1d, 0x7c, 0x7d, 0x7e, 0x7f}, 119 {0x1d, 0x7c, 0x7d, 0x7e, 0x7f},
@@ -218,7 +220,8 @@ struct w83793_data {
218 char valid; /* !=0 if following fields are valid */ 220 char valid; /* !=0 if following fields are valid */
219 unsigned long last_updated; /* In jiffies */ 221 unsigned long last_updated; /* In jiffies */
220 unsigned long last_nonvolatile; /* In jiffies, last time we update the 222 unsigned long last_nonvolatile; /* In jiffies, last time we update the
221 nonvolatile registers */ 223 * nonvolatile registers
224 */
222 225
223 u8 bank; 226 u8 bank;
224 u8 vrm; 227 u8 vrm;
@@ -233,7 +236,8 @@ struct w83793_data {
233 s8 temp[6][5]; /* current, crit, crit_hyst,warn, warn_hyst */ 236 s8 temp[6][5]; /* current, crit, crit_hyst,warn, warn_hyst */
234 u8 temp_low_bits; /* Additional resolution TD1-TD4 */ 237 u8 temp_low_bits; /* Additional resolution TD1-TD4 */
235 u8 temp_mode[2]; /* byte 0: Temp D1-D4 mode each has 2 bits 238 u8 temp_mode[2]; /* byte 0: Temp D1-D4 mode each has 2 bits
236 byte 1: Temp R1,R2 mode, each has 1 bit */ 239 * byte 1: Temp R1,R2 mode, each has 1 bit
240 */
237 u8 temp_critical; /* If reached all fan will be at full speed */ 241 u8 temp_critical; /* If reached all fan will be at full speed */
238 u8 temp_fan_map[6]; /* Temp controls which pwm fan, bit field */ 242 u8 temp_fan_map[6]; /* Temp controls which pwm fan, bit field */
239 243
@@ -268,17 +272,21 @@ struct w83793_data {
268 int watchdog_timeout; /* watchdog timeout in minutes */ 272 int watchdog_timeout; /* watchdog timeout in minutes */
269}; 273};
270 274
271/* Somewhat ugly :( global data pointer list with all devices, so that 275/*
272 we can find our device data as when using misc_register. There is no 276 * Somewhat ugly :( global data pointer list with all devices, so that
273 other method to get to one's device data from the open file-op and 277 * we can find our device data as when using misc_register. There is no
274 for usage in the reboot notifier callback. */ 278 * other method to get to one's device data from the open file-op and
279 * for usage in the reboot notifier callback.
280 */
275static LIST_HEAD(watchdog_data_list); 281static LIST_HEAD(watchdog_data_list);
276 282
277/* Note this lock not only protect list access, but also data.kref access */ 283/* Note this lock not only protect list access, but also data.kref access */
278static DEFINE_MUTEX(watchdog_data_mutex); 284static DEFINE_MUTEX(watchdog_data_mutex);
279 285
280/* Release our data struct when we're detached from the i2c client *and* all 286/*
281 references to our watchdog device are released */ 287 * Release our data struct when we're detached from the i2c client *and* all
288 * references to our watchdog device are released
289 */
282static void w83793_release_resources(struct kref *ref) 290static void w83793_release_resources(struct kref *ref)
283{ 291{
284 struct w83793_data *data = container_of(ref, struct w83793_data, kref); 292 struct w83793_data *data = container_of(ref, struct w83793_data, kref);
@@ -337,7 +345,14 @@ store_vrm(struct device *dev, struct device_attribute *attr,
337 const char *buf, size_t count) 345 const char *buf, size_t count)
338{ 346{
339 struct w83793_data *data = dev_get_drvdata(dev); 347 struct w83793_data *data = dev_get_drvdata(dev);
340 data->vrm = simple_strtoul(buf, NULL, 10); 348 unsigned long val;
349 int err;
350
351 err = kstrtoul(buf, 10, &val);
352 if (err)
353 return err;
354
355 data->vrm = val;
341 return count; 356 return count;
342} 357}
343 358
@@ -354,7 +369,7 @@ show_alarm_beep(struct device *dev, struct device_attribute *attr, char *buf)
354 int bit = sensor_attr->index & 0x07; 369 int bit = sensor_attr->index & 0x07;
355 u8 val; 370 u8 val;
356 371
357 if (ALARM_STATUS == nr) { 372 if (nr == ALARM_STATUS) {
358 val = (data->alarms[index] >> (bit)) & 1; 373 val = (data->alarms[index] >> (bit)) & 1;
359 } else { /* BEEP_ENABLE */ 374 } else { /* BEEP_ENABLE */
360 val = (data->beeps[index] >> (bit)) & 1; 375 val = (data->beeps[index] >> (bit)) & 1;
@@ -374,10 +389,14 @@ store_beep(struct device *dev, struct device_attribute *attr,
374 int index = sensor_attr->index >> 3; 389 int index = sensor_attr->index >> 3;
375 int shift = sensor_attr->index & 0x07; 390 int shift = sensor_attr->index & 0x07;
376 u8 beep_bit = 1 << shift; 391 u8 beep_bit = 1 << shift;
377 u8 val; 392 unsigned long val;
393 int err;
378 394
379 val = simple_strtoul(buf, NULL, 10); 395 err = kstrtoul(buf, 10, &val);
380 if (val != 0 && val != 1) 396 if (err)
397 return err;
398
399 if (val > 1)
381 return -EINVAL; 400 return -EINVAL;
382 401
383 mutex_lock(&data->update_lock); 402 mutex_lock(&data->update_lock);
@@ -403,9 +422,14 @@ store_beep_enable(struct device *dev, struct device_attribute *attr,
403{ 422{
404 struct i2c_client *client = to_i2c_client(dev); 423 struct i2c_client *client = to_i2c_client(dev);
405 struct w83793_data *data = i2c_get_clientdata(client); 424 struct w83793_data *data = i2c_get_clientdata(client);
406 u8 val = simple_strtoul(buf, NULL, 10); 425 unsigned long val;
426 int err;
427
428 err = kstrtoul(buf, 10, &val);
429 if (err)
430 return err;
407 431
408 if (val != 0 && val != 1) 432 if (val > 1)
409 return -EINVAL; 433 return -EINVAL;
410 434
411 mutex_lock(&data->update_lock); 435 mutex_lock(&data->update_lock);
@@ -449,8 +473,12 @@ store_chassis_clear(struct device *dev,
449 struct w83793_data *data = i2c_get_clientdata(client); 473 struct w83793_data *data = i2c_get_clientdata(client);
450 unsigned long val; 474 unsigned long val;
451 u8 reg; 475 u8 reg;
476 int err;
452 477
453 if (kstrtoul(buf, 10, &val) || val != 0) 478 err = kstrtoul(buf, 10, &val);
479 if (err)
480 return err;
481 if (val)
454 return -EINVAL; 482 return -EINVAL;
455 483
456 mutex_lock(&data->update_lock); 484 mutex_lock(&data->update_lock);
@@ -473,11 +501,10 @@ show_fan(struct device *dev, struct device_attribute *attr, char *buf)
473 struct w83793_data *data = w83793_update_device(dev); 501 struct w83793_data *data = w83793_update_device(dev);
474 u16 val; 502 u16 val;
475 503
476 if (FAN_INPUT == nr) { 504 if (nr == FAN_INPUT)
477 val = data->fan[index] & 0x0fff; 505 val = data->fan[index] & 0x0fff;
478 } else { 506 else
479 val = data->fan_min[index] & 0x0fff; 507 val = data->fan_min[index] & 0x0fff;
480 }
481 508
482 return sprintf(buf, "%lu\n", FAN_FROM_REG(val)); 509 return sprintf(buf, "%lu\n", FAN_FROM_REG(val));
483} 510}
@@ -491,7 +518,13 @@ store_fan_min(struct device *dev, struct device_attribute *attr,
491 int index = sensor_attr->index; 518 int index = sensor_attr->index;
492 struct i2c_client *client = to_i2c_client(dev); 519 struct i2c_client *client = to_i2c_client(dev);
493 struct w83793_data *data = i2c_get_clientdata(client); 520 struct w83793_data *data = i2c_get_clientdata(client);
494 u16 val = FAN_TO_REG(simple_strtoul(buf, NULL, 10)); 521 unsigned long val;
522 int err;
523
524 err = kstrtoul(buf, 10, &val);
525 if (err)
526 return err;
527 val = FAN_TO_REG(val);
495 528
496 mutex_lock(&data->update_lock); 529 mutex_lock(&data->update_lock);
497 data->fan_min[index] = val; 530 data->fan_min[index] = val;
@@ -513,7 +546,7 @@ show_pwm(struct device *dev, struct device_attribute *attr, char *buf)
513 int nr = sensor_attr->nr; 546 int nr = sensor_attr->nr;
514 int index = sensor_attr->index; 547 int index = sensor_attr->index;
515 548
516 if (PWM_STOP_TIME == nr) 549 if (nr == PWM_STOP_TIME)
517 val = TIME_FROM_REG(data->pwm_stop_time[index]); 550 val = TIME_FROM_REG(data->pwm_stop_time[index]);
518 else 551 else
519 val = (data->pwm[index][nr] & 0x3f) << 2; 552 val = (data->pwm[index][nr] & 0x3f) << 2;
@@ -531,17 +564,21 @@ store_pwm(struct device *dev, struct device_attribute *attr,
531 to_sensor_dev_attr_2(attr); 564 to_sensor_dev_attr_2(attr);
532 int nr = sensor_attr->nr; 565 int nr = sensor_attr->nr;
533 int index = sensor_attr->index; 566 int index = sensor_attr->index;
534 u8 val; 567 unsigned long val;
568 int err;
569
570 err = kstrtoul(buf, 10, &val);
571 if (err)
572 return err;
535 573
536 mutex_lock(&data->update_lock); 574 mutex_lock(&data->update_lock);
537 if (PWM_STOP_TIME == nr) { 575 if (nr == PWM_STOP_TIME) {
538 val = TIME_TO_REG(simple_strtoul(buf, NULL, 10)); 576 val = TIME_TO_REG(val);
539 data->pwm_stop_time[index] = val; 577 data->pwm_stop_time[index] = val;
540 w83793_write_value(client, W83793_REG_PWM_STOP_TIME(index), 578 w83793_write_value(client, W83793_REG_PWM_STOP_TIME(index),
541 val); 579 val);
542 } else { 580 } else {
543 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 0xff) 581 val = SENSORS_LIMIT(val, 0, 0xff) >> 2;
544 >> 2;
545 data->pwm[index][nr] = 582 data->pwm[index][nr] =
546 w83793_read_value(client, W83793_REG_PWM(index, nr)) & 0xc0; 583 w83793_read_value(client, W83793_REG_PWM(index, nr)) & 0xc0;
547 data->pwm[index][nr] |= val; 584 data->pwm[index][nr] |= val;
@@ -563,7 +600,7 @@ show_temp(struct device *dev, struct device_attribute *attr, char *buf)
563 struct w83793_data *data = w83793_update_device(dev); 600 struct w83793_data *data = w83793_update_device(dev);
564 long temp = TEMP_FROM_REG(data->temp[index][nr]); 601 long temp = TEMP_FROM_REG(data->temp[index][nr]);
565 602
566 if (TEMP_READ == nr && index < 4) { /* Only TD1-TD4 have low bits */ 603 if (nr == TEMP_READ && index < 4) { /* Only TD1-TD4 have low bits */
567 int low = ((data->temp_low_bits >> (index * 2)) & 0x03) * 250; 604 int low = ((data->temp_low_bits >> (index * 2)) & 0x03) * 250;
568 temp += temp > 0 ? low : -low; 605 temp += temp > 0 ? low : -low;
569 } 606 }
@@ -580,7 +617,12 @@ store_temp(struct device *dev, struct device_attribute *attr,
580 int index = sensor_attr->index; 617 int index = sensor_attr->index;
581 struct i2c_client *client = to_i2c_client(dev); 618 struct i2c_client *client = to_i2c_client(dev);
582 struct w83793_data *data = i2c_get_clientdata(client); 619 struct w83793_data *data = i2c_get_clientdata(client);
583 long tmp = simple_strtol(buf, NULL, 10); 620 long tmp;
621 int err;
622
623 err = kstrtol(buf, 10, &tmp);
624 if (err)
625 return err;
584 626
585 mutex_lock(&data->update_lock); 627 mutex_lock(&data->update_lock);
586 data->temp[index][nr] = TEMP_TO_REG(tmp, -128, 127); 628 data->temp[index][nr] = TEMP_TO_REG(tmp, -128, 127);
@@ -591,18 +633,18 @@ store_temp(struct device *dev, struct device_attribute *attr,
591} 633}
592 634
593/* 635/*
594 TD1-TD4 636 * TD1-TD4
595 each has 4 mode:(2 bits) 637 * each has 4 mode:(2 bits)
596 0: Stop monitor 638 * 0: Stop monitor
597 1: Use internal temp sensor(default) 639 * 1: Use internal temp sensor(default)
598 2: Reserved 640 * 2: Reserved
599 3: Use sensor in Intel CPU and get result by PECI 641 * 3: Use sensor in Intel CPU and get result by PECI
600 642 *
601 TR1-TR2 643 * TR1-TR2
602 each has 2 mode:(1 bit) 644 * each has 2 mode:(1 bit)
603 0: Disable temp sensor monitor 645 * 0: Disable temp sensor monitor
604 1: To enable temp sensors monitor 646 * 1: To enable temp sensors monitor
605*/ 647 */
606 648
607/* 0 disable, 6 PECI */ 649/* 0 disable, 6 PECI */
608static u8 TO_TEMP_MODE[] = { 0, 0, 0, 6 }; 650static u8 TO_TEMP_MODE[] = { 0, 0, 0, 6 };
@@ -622,11 +664,10 @@ show_temp_mode(struct device *dev, struct device_attribute *attr, char *buf)
622 tmp = (data->temp_mode[index] >> shift) & mask; 664 tmp = (data->temp_mode[index] >> shift) & mask;
623 665
624 /* for the internal sensor, found out if diode or thermistor */ 666 /* for the internal sensor, found out if diode or thermistor */
625 if (tmp == 1) { 667 if (tmp == 1)
626 tmp = index == 0 ? 3 : 4; 668 tmp = index == 0 ? 3 : 4;
627 } else { 669 else
628 tmp = TO_TEMP_MODE[tmp]; 670 tmp = TO_TEMP_MODE[tmp];
629 }
630 671
631 return sprintf(buf, "%d\n", tmp); 672 return sprintf(buf, "%d\n", tmp);
632} 673}
@@ -642,7 +683,12 @@ store_temp_mode(struct device *dev, struct device_attribute *attr,
642 int index = sensor_attr->index; 683 int index = sensor_attr->index;
643 u8 mask = (index < 4) ? 0x03 : 0x01; 684 u8 mask = (index < 4) ? 0x03 : 0x01;
644 u8 shift = (index < 4) ? (2 * index) : (index - 4); 685 u8 shift = (index < 4) ? (2 * index) : (index - 4);
645 u8 val = simple_strtoul(buf, NULL, 10); 686 unsigned long val;
687 int err;
688
689 err = kstrtoul(buf, 10, &val);
690 if (err)
691 return err;
646 692
647 /* transform the sysfs interface values into table above */ 693 /* transform the sysfs interface values into table above */
648 if ((val == 6) && (index < 4)) { 694 if ((val == 6) && (index < 4)) {
@@ -681,15 +727,14 @@ show_sf_setup(struct device *dev, struct device_attribute *attr, char *buf)
681 struct w83793_data *data = w83793_update_device(dev); 727 struct w83793_data *data = w83793_update_device(dev);
682 u32 val = 0; 728 u32 val = 0;
683 729
684 if (SETUP_PWM_DEFAULT == nr) { 730 if (nr == SETUP_PWM_DEFAULT)
685 val = (data->pwm_default & 0x3f) << 2; 731 val = (data->pwm_default & 0x3f) << 2;
686 } else if (SETUP_PWM_UPTIME == nr) { 732 else if (nr == SETUP_PWM_UPTIME)
687 val = TIME_FROM_REG(data->pwm_uptime); 733 val = TIME_FROM_REG(data->pwm_uptime);
688 } else if (SETUP_PWM_DOWNTIME == nr) { 734 else if (nr == SETUP_PWM_DOWNTIME)
689 val = TIME_FROM_REG(data->pwm_downtime); 735 val = TIME_FROM_REG(data->pwm_downtime);
690 } else if (SETUP_TEMP_CRITICAL == nr) { 736 else if (nr == SETUP_TEMP_CRITICAL)
691 val = TEMP_FROM_REG(data->temp_critical & 0x7f); 737 val = TEMP_FROM_REG(data->temp_critical & 0x7f);
692 }
693 738
694 return sprintf(buf, "%d\n", val); 739 return sprintf(buf, "%d\n", val);
695} 740}
@@ -703,31 +748,34 @@ store_sf_setup(struct device *dev, struct device_attribute *attr,
703 int nr = sensor_attr->nr; 748 int nr = sensor_attr->nr;
704 struct i2c_client *client = to_i2c_client(dev); 749 struct i2c_client *client = to_i2c_client(dev);
705 struct w83793_data *data = i2c_get_clientdata(client); 750 struct w83793_data *data = i2c_get_clientdata(client);
751 long val;
752 int err;
753
754 err = kstrtol(buf, 10, &val);
755 if (err)
756 return err;
706 757
707 mutex_lock(&data->update_lock); 758 mutex_lock(&data->update_lock);
708 if (SETUP_PWM_DEFAULT == nr) { 759 if (nr == SETUP_PWM_DEFAULT) {
709 data->pwm_default = 760 data->pwm_default =
710 w83793_read_value(client, W83793_REG_PWM_DEFAULT) & 0xc0; 761 w83793_read_value(client, W83793_REG_PWM_DEFAULT) & 0xc0;
711 data->pwm_default |= SENSORS_LIMIT(simple_strtoul(buf, NULL, 762 data->pwm_default |= SENSORS_LIMIT(val, 0, 0xff) >> 2;
712 10),
713 0, 0xff) >> 2;
714 w83793_write_value(client, W83793_REG_PWM_DEFAULT, 763 w83793_write_value(client, W83793_REG_PWM_DEFAULT,
715 data->pwm_default); 764 data->pwm_default);
716 } else if (SETUP_PWM_UPTIME == nr) { 765 } else if (nr == SETUP_PWM_UPTIME) {
717 data->pwm_uptime = TIME_TO_REG(simple_strtoul(buf, NULL, 10)); 766 data->pwm_uptime = TIME_TO_REG(val);
718 data->pwm_uptime += data->pwm_uptime == 0 ? 1 : 0; 767 data->pwm_uptime += data->pwm_uptime == 0 ? 1 : 0;
719 w83793_write_value(client, W83793_REG_PWM_UPTIME, 768 w83793_write_value(client, W83793_REG_PWM_UPTIME,
720 data->pwm_uptime); 769 data->pwm_uptime);
721 } else if (SETUP_PWM_DOWNTIME == nr) { 770 } else if (nr == SETUP_PWM_DOWNTIME) {
722 data->pwm_downtime = TIME_TO_REG(simple_strtoul(buf, NULL, 10)); 771 data->pwm_downtime = TIME_TO_REG(val);
723 data->pwm_downtime += data->pwm_downtime == 0 ? 1 : 0; 772 data->pwm_downtime += data->pwm_downtime == 0 ? 1 : 0;
724 w83793_write_value(client, W83793_REG_PWM_DOWNTIME, 773 w83793_write_value(client, W83793_REG_PWM_DOWNTIME,
725 data->pwm_downtime); 774 data->pwm_downtime);
726 } else { /* SETUP_TEMP_CRITICAL */ 775 } else { /* SETUP_TEMP_CRITICAL */
727 data->temp_critical = 776 data->temp_critical =
728 w83793_read_value(client, W83793_REG_TEMP_CRITICAL) & 0x80; 777 w83793_read_value(client, W83793_REG_TEMP_CRITICAL) & 0x80;
729 data->temp_critical |= TEMP_TO_REG(simple_strtol(buf, NULL, 10), 778 data->temp_critical |= TEMP_TO_REG(val, 0, 0x7f);
730 0, 0x7f);
731 w83793_write_value(client, W83793_REG_TEMP_CRITICAL, 779 w83793_write_value(client, W83793_REG_TEMP_CRITICAL,
732 data->temp_critical); 780 data->temp_critical);
733 } 781 }
@@ -737,31 +785,31 @@ store_sf_setup(struct device *dev, struct device_attribute *attr,
737} 785}
738 786
739/* 787/*
740 Temp SmartFan control 788 * Temp SmartFan control
741 TEMP_FAN_MAP 789 * TEMP_FAN_MAP
742 Temp channel control which pwm fan, bitfield, bit 0 indicate pwm1... 790 * Temp channel control which pwm fan, bitfield, bit 0 indicate pwm1...
743 It's possible two or more temp channels control the same fan, w83793 791 * It's possible two or more temp channels control the same fan, w83793
744 always prefers to pick the most critical request and applies it to 792 * always prefers to pick the most critical request and applies it to
745 the related Fan. 793 * the related Fan.
746 It's possible one fan is not in any mapping of 6 temp channels, this 794 * It's possible one fan is not in any mapping of 6 temp channels, this
747 means the fan is manual mode 795 * means the fan is manual mode
748 796 *
749 TEMP_PWM_ENABLE 797 * TEMP_PWM_ENABLE
750 Each temp channel has its own SmartFan mode, and temp channel 798 * Each temp channel has its own SmartFan mode, and temp channel
751 control fans that are set by TEMP_FAN_MAP 799 * control fans that are set by TEMP_FAN_MAP
752 0: SmartFanII mode 800 * 0: SmartFanII mode
753 1: Thermal Cruise Mode 801 * 1: Thermal Cruise Mode
754 802 *
755 TEMP_CRUISE 803 * TEMP_CRUISE
756 Target temperature in thermal cruise mode, w83793 will try to turn 804 * Target temperature in thermal cruise mode, w83793 will try to turn
757 fan speed to keep the temperature of target device around this 805 * fan speed to keep the temperature of target device around this
758 temperature. 806 * temperature.
759 807 *
760 TEMP_TOLERANCE 808 * TEMP_TOLERANCE
761 If Temp higher or lower than target with this tolerance, w83793 809 * If Temp higher or lower than target with this tolerance, w83793
762 will take actions to speed up or slow down the fan to keep the 810 * will take actions to speed up or slow down the fan to keep the
763 temperature within the tolerance range. 811 * temperature within the tolerance range.
764*/ 812 */
765 813
766#define TEMP_FAN_MAP 0 814#define TEMP_FAN_MAP 0
767#define TEMP_PWM_ENABLE 1 815#define TEMP_PWM_ENABLE 1
@@ -777,12 +825,12 @@ show_sf_ctrl(struct device *dev, struct device_attribute *attr, char *buf)
777 struct w83793_data *data = w83793_update_device(dev); 825 struct w83793_data *data = w83793_update_device(dev);
778 u32 val; 826 u32 val;
779 827
780 if (TEMP_FAN_MAP == nr) { 828 if (nr == TEMP_FAN_MAP) {
781 val = data->temp_fan_map[index]; 829 val = data->temp_fan_map[index];
782 } else if (TEMP_PWM_ENABLE == nr) { 830 } else if (nr == TEMP_PWM_ENABLE) {
783 /* +2 to transfrom into 2 and 3 to conform with sysfs intf */ 831 /* +2 to transfrom into 2 and 3 to conform with sysfs intf */
784 val = ((data->pwm_enable >> index) & 0x01) + 2; 832 val = ((data->pwm_enable >> index) & 0x01) + 2;
785 } else if (TEMP_CRUISE == nr) { 833 } else if (nr == TEMP_CRUISE) {
786 val = TEMP_FROM_REG(data->temp_cruise[index] & 0x7f); 834 val = TEMP_FROM_REG(data->temp_cruise[index] & 0x7f);
787 } else { /* TEMP_TOLERANCE */ 835 } else { /* TEMP_TOLERANCE */
788 val = data->tolerance[index >> 1] >> ((index & 0x01) ? 4 : 0); 836 val = data->tolerance[index >> 1] >> ((index & 0x01) ? 4 : 0);
@@ -801,16 +849,20 @@ store_sf_ctrl(struct device *dev, struct device_attribute *attr,
801 int index = sensor_attr->index; 849 int index = sensor_attr->index;
802 struct i2c_client *client = to_i2c_client(dev); 850 struct i2c_client *client = to_i2c_client(dev);
803 struct w83793_data *data = i2c_get_clientdata(client); 851 struct w83793_data *data = i2c_get_clientdata(client);
804 u32 val; 852 long val;
853 int err;
854
855 err = kstrtol(buf, 10, &val);
856 if (err)
857 return err;
805 858
806 mutex_lock(&data->update_lock); 859 mutex_lock(&data->update_lock);
807 if (TEMP_FAN_MAP == nr) { 860 if (nr == TEMP_FAN_MAP) {
808 val = simple_strtoul(buf, NULL, 10) & 0xff; 861 val = SENSORS_LIMIT(val, 0, 255);
809 w83793_write_value(client, W83793_REG_TEMP_FAN_MAP(index), val); 862 w83793_write_value(client, W83793_REG_TEMP_FAN_MAP(index), val);
810 data->temp_fan_map[index] = val; 863 data->temp_fan_map[index] = val;
811 } else if (TEMP_PWM_ENABLE == nr) { 864 } else if (nr == TEMP_PWM_ENABLE) {
812 val = simple_strtoul(buf, NULL, 10); 865 if (val == 2 || val == 3) {
813 if (2 == val || 3 == val) {
814 data->pwm_enable = 866 data->pwm_enable =
815 w83793_read_value(client, W83793_REG_PWM_ENABLE); 867 w83793_read_value(client, W83793_REG_PWM_ENABLE);
816 if (val - 2) 868 if (val - 2)
@@ -823,12 +875,11 @@ store_sf_ctrl(struct device *dev, struct device_attribute *attr,
823 mutex_unlock(&data->update_lock); 875 mutex_unlock(&data->update_lock);
824 return -EINVAL; 876 return -EINVAL;
825 } 877 }
826 } else if (TEMP_CRUISE == nr) { 878 } else if (nr == TEMP_CRUISE) {
827 data->temp_cruise[index] = 879 data->temp_cruise[index] =
828 w83793_read_value(client, W83793_REG_TEMP_CRUISE(index)); 880 w83793_read_value(client, W83793_REG_TEMP_CRUISE(index));
829 val = TEMP_TO_REG(simple_strtol(buf, NULL, 10), 0, 0x7f);
830 data->temp_cruise[index] &= 0x80; 881 data->temp_cruise[index] &= 0x80;
831 data->temp_cruise[index] |= val; 882 data->temp_cruise[index] |= TEMP_TO_REG(val, 0, 0x7f);
832 883
833 w83793_write_value(client, W83793_REG_TEMP_CRUISE(index), 884 w83793_write_value(client, W83793_REG_TEMP_CRUISE(index),
834 data->temp_cruise[index]); 885 data->temp_cruise[index]);
@@ -838,9 +889,8 @@ store_sf_ctrl(struct device *dev, struct device_attribute *attr,
838 data->tolerance[i] = 889 data->tolerance[i] =
839 w83793_read_value(client, W83793_REG_TEMP_TOL(i)); 890 w83793_read_value(client, W83793_REG_TEMP_TOL(i));
840 891
841 val = TEMP_TO_REG(simple_strtol(buf, NULL, 10), 0, 0x0f);
842 data->tolerance[i] &= ~(0x0f << shift); 892 data->tolerance[i] &= ~(0x0f << shift);
843 data->tolerance[i] |= val << shift; 893 data->tolerance[i] |= TEMP_TO_REG(val, 0, 0x0f) << shift;
844 w83793_write_value(client, W83793_REG_TEMP_TOL(i), 894 w83793_write_value(client, W83793_REG_TEMP_TOL(i),
845 data->tolerance[i]); 895 data->tolerance[i]);
846 } 896 }
@@ -871,7 +921,13 @@ store_sf2_pwm(struct device *dev, struct device_attribute *attr,
871 to_sensor_dev_attr_2(attr); 921 to_sensor_dev_attr_2(attr);
872 int nr = sensor_attr->nr; 922 int nr = sensor_attr->nr;
873 int index = sensor_attr->index; 923 int index = sensor_attr->index;
874 u8 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 0xff) >> 2; 924 unsigned long val;
925 int err;
926
927 err = kstrtoul(buf, 10, &val);
928 if (err)
929 return err;
930 val = SENSORS_LIMIT(val, 0, 0xff) >> 2;
875 931
876 mutex_lock(&data->update_lock); 932 mutex_lock(&data->update_lock);
877 data->sf2_pwm[index][nr] = 933 data->sf2_pwm[index][nr] =
@@ -906,7 +962,13 @@ store_sf2_temp(struct device *dev, struct device_attribute *attr,
906 to_sensor_dev_attr_2(attr); 962 to_sensor_dev_attr_2(attr);
907 int nr = sensor_attr->nr; 963 int nr = sensor_attr->nr;
908 int index = sensor_attr->index; 964 int index = sensor_attr->index;
909 u8 val = TEMP_TO_REG(simple_strtol(buf, NULL, 10), 0, 0x7f); 965 long val;
966 int err;
967
968 err = kstrtol(buf, 10, &val);
969 if (err)
970 return err;
971 val = TEMP_TO_REG(val, 0, 0x7f);
910 972
911 mutex_lock(&data->update_lock); 973 mutex_lock(&data->update_lock);
912 data->sf2_temp[index][nr] = 974 data->sf2_temp[index][nr] =
@@ -948,17 +1010,19 @@ store_in(struct device *dev, struct device_attribute *attr,
948 int index = sensor_attr->index; 1010 int index = sensor_attr->index;
949 struct i2c_client *client = to_i2c_client(dev); 1011 struct i2c_client *client = to_i2c_client(dev);
950 struct w83793_data *data = i2c_get_clientdata(client); 1012 struct w83793_data *data = i2c_get_clientdata(client);
951 u32 val; 1013 unsigned long val;
1014 int err;
1015
1016 err = kstrtoul(buf, 10, &val);
1017 if (err)
1018 return err;
1019 val = (val + scale_in[index] / 2) / scale_in[index];
952 1020
953 val =
954 (simple_strtoul(buf, NULL, 10) +
955 scale_in[index] / 2) / scale_in[index];
956 mutex_lock(&data->update_lock); 1021 mutex_lock(&data->update_lock);
957 if (index > 2) { 1022 if (index > 2) {
958 /* fix the limit values of 5VDD and 5VSB to ALARM mechanism */ 1023 /* fix the limit values of 5VDD and 5VSB to ALARM mechanism */
959 if (1 == nr || 2 == nr) { 1024 if (nr == 1 || nr == 2)
960 val -= scale_in_add[index] / scale_in[index]; 1025 val -= scale_in_add[index] / scale_in[index];
961 }
962 val = SENSORS_LIMIT(val, 0, 255); 1026 val = SENSORS_LIMIT(val, 0, 255);
963 } else { 1027 } else {
964 val = SENSORS_LIMIT(val, 0, 0x3FF); 1028 val = SENSORS_LIMIT(val, 0, 0x3FF);
@@ -1143,9 +1207,8 @@ static struct sensor_device_attribute_2 sda_single_files[] = {
1143 1207
1144static void w83793_init_client(struct i2c_client *client) 1208static void w83793_init_client(struct i2c_client *client)
1145{ 1209{
1146 if (reset) { 1210 if (reset)
1147 w83793_write_value(client, W83793_REG_CONFIG, 0x80); 1211 w83793_write_value(client, W83793_REG_CONFIG, 0x80);
1148 }
1149 1212
1150 /* Start monitoring */ 1213 /* Start monitoring */
1151 w83793_write_value(client, W83793_REG_CONFIG, 1214 w83793_write_value(client, W83793_REG_CONFIG,
@@ -1259,10 +1322,12 @@ static int watchdog_open(struct inode *inode, struct file *filp)
1259 struct w83793_data *pos, *data = NULL; 1322 struct w83793_data *pos, *data = NULL;
1260 int watchdog_is_open; 1323 int watchdog_is_open;
1261 1324
1262 /* We get called from drivers/char/misc.c with misc_mtx hold, and we 1325 /*
1263 call misc_register() from w83793_probe() with watchdog_data_mutex 1326 * We get called from drivers/char/misc.c with misc_mtx hold, and we
1264 hold, as misc_register() takes the misc_mtx lock, this is a possible 1327 * call misc_register() from w83793_probe() with watchdog_data_mutex
1265 deadlock, so we use mutex_trylock here. */ 1328 * hold, as misc_register() takes the misc_mtx lock, this is a possible
1329 * deadlock, so we use mutex_trylock here.
1330 */
1266 if (!mutex_trylock(&watchdog_data_mutex)) 1331 if (!mutex_trylock(&watchdog_data_mutex))
1267 return -ERESTARTSYS; 1332 return -ERESTARTSYS;
1268 list_for_each_entry(pos, &watchdog_data_list, list) { 1333 list_for_each_entry(pos, &watchdog_data_list, list) {
@@ -1275,8 +1340,10 @@ static int watchdog_open(struct inode *inode, struct file *filp)
1275 /* Check, if device is already open */ 1340 /* Check, if device is already open */
1276 watchdog_is_open = test_and_set_bit(0, &data->watchdog_is_open); 1341 watchdog_is_open = test_and_set_bit(0, &data->watchdog_is_open);
1277 1342
1278 /* Increase data reference counter (if not already done). 1343 /*
1279 Note we can never not have found data, so we don't check for this */ 1344 * Increase data reference counter (if not already done).
1345 * Note we can never not have found data, so we don't check for this
1346 */
1280 if (!watchdog_is_open) 1347 if (!watchdog_is_open)
1281 kref_get(&data->kref); 1348 kref_get(&data->kref);
1282 1349
@@ -1556,9 +1623,8 @@ w83793_detect_subclients(struct i2c_client *client)
1556 } 1623 }
1557 1624
1558 tmp = w83793_read_value(client, W83793_REG_I2C_SUBADDR); 1625 tmp = w83793_read_value(client, W83793_REG_I2C_SUBADDR);
1559 if (!(tmp & 0x08)) { 1626 if (!(tmp & 0x08))
1560 data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (tmp & 0x7)); 1627 data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (tmp & 0x7));
1561 }
1562 if (!(tmp & 0x80)) { 1628 if (!(tmp & 0x80)) {
1563 if ((data->lm75[0] != NULL) 1629 if ((data->lm75[0] != NULL)
1564 && ((tmp & 0x7) == ((tmp >> 4) & 0x7))) { 1630 && ((tmp & 0x7) == ((tmp >> 4) & 0x7))) {
@@ -1591,9 +1657,8 @@ static int w83793_detect(struct i2c_client *client,
1591 struct i2c_adapter *adapter = client->adapter; 1657 struct i2c_adapter *adapter = client->adapter;
1592 unsigned short address = client->addr; 1658 unsigned short address = client->addr;
1593 1659
1594 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 1660 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1595 return -ENODEV; 1661 return -ENODEV;
1596 }
1597 1662
1598 bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL); 1663 bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL);
1599 1664
@@ -1604,8 +1669,10 @@ static int w83793_detect(struct i2c_client *client,
1604 return -ENODEV; 1669 return -ENODEV;
1605 } 1670 }
1606 1671
1607 /* If Winbond chip, address of chip and W83793_REG_I2C_ADDR 1672 /*
1608 should match */ 1673 * If Winbond chip, address of chip and W83793_REG_I2C_ADDR
1674 * should match
1675 */
1609 if ((bank & 0x07) == 0 1676 if ((bank & 0x07) == 0
1610 && i2c_smbus_read_byte_data(client, W83793_REG_I2C_ADDR) != 1677 && i2c_smbus_read_byte_data(client, W83793_REG_I2C_ADDR) !=
1611 (address << 1)) { 1678 (address << 1)) {
@@ -1647,9 +1714,11 @@ static int w83793_probe(struct i2c_client *client,
1647 INIT_LIST_HEAD(&data->list); 1714 INIT_LIST_HEAD(&data->list);
1648 kref_init(&data->kref); 1715 kref_init(&data->kref);
1649 1716
1650 /* Store client pointer in our data struct for watchdog usage 1717 /*
1651 (where the client is found through a data ptr instead of the 1718 * Store client pointer in our data struct for watchdog usage
1652 otherway around) */ 1719 * (where the client is found through a data ptr instead of the
1720 * otherway around)
1721 */
1653 data->client = client; 1722 data->client = client;
1654 1723
1655 err = w83793_detect_subclients(client); 1724 err = w83793_detect_subclients(client);
@@ -1660,8 +1729,8 @@ static int w83793_probe(struct i2c_client *client,
1660 w83793_init_client(client); 1729 w83793_init_client(client);
1661 1730
1662 /* 1731 /*
1663 Only fan 1-5 has their own input pins, 1732 * Only fan 1-5 has their own input pins,
1664 Pwm 1-3 has their own pins 1733 * Pwm 1-3 has their own pins
1665 */ 1734 */
1666 data->has_fan = 0x1f; 1735 data->has_fan = 0x1f;
1667 data->has_pwm = 0x07; 1736 data->has_pwm = 0x07;
@@ -1723,7 +1792,7 @@ static int w83793_probe(struct i2c_client *client,
1723 } 1792 }
1724 1793
1725 /* check the temp1-6 mode, ignore former AMDSI selected inputs */ 1794 /* check the temp1-6 mode, ignore former AMDSI selected inputs */
1726 tmp = w83793_read_value(client,W83793_REG_TEMP_MODE[0]); 1795 tmp = w83793_read_value(client, W83793_REG_TEMP_MODE[0]);
1727 if (tmp & 0x01) 1796 if (tmp & 0x01)
1728 data->has_temp |= 0x01; 1797 data->has_temp |= 0x01;
1729 if (tmp & 0x04) 1798 if (tmp & 0x04)
@@ -1733,7 +1802,7 @@ static int w83793_probe(struct i2c_client *client,
1733 if (tmp & 0x40) 1802 if (tmp & 0x40)
1734 data->has_temp |= 0x08; 1803 data->has_temp |= 0x08;
1735 1804
1736 tmp = w83793_read_value(client,W83793_REG_TEMP_MODE[1]); 1805 tmp = w83793_read_value(client, W83793_REG_TEMP_MODE[1]);
1737 if (tmp & 0x01) 1806 if (tmp & 0x01)
1738 data->has_temp |= 0x10; 1807 data->has_temp |= 0x10;
1739 if (tmp & 0x02) 1808 if (tmp & 0x02)
@@ -1823,9 +1892,11 @@ static int w83793_probe(struct i2c_client *client,
1823 goto exit_devunreg; 1892 goto exit_devunreg;
1824 } 1893 }
1825 1894
1826 /* Enable Watchdog registers. 1895 /*
1827 Set Configuration Register to Enable Watch Dog Registers 1896 * Enable Watchdog registers.
1828 (Bit 2) = XXXX, X1XX. */ 1897 * Set Configuration Register to Enable Watch Dog Registers
1898 * (Bit 2) = XXXX, X1XX.
1899 */
1829 tmp = w83793_read_value(client, W83793_REG_CONFIG); 1900 tmp = w83793_read_value(client, W83793_REG_CONFIG);
1830 w83793_write_value(client, W83793_REG_CONFIG, tmp | 0x04); 1901 w83793_write_value(client, W83793_REG_CONFIG, tmp | 0x04);
1831 1902
@@ -1839,9 +1910,11 @@ static int w83793_probe(struct i2c_client *client,
1839 /* Disable Soft Watchdog during initialiation */ 1910 /* Disable Soft Watchdog during initialiation */
1840 watchdog_disable(data); 1911 watchdog_disable(data);
1841 1912
1842 /* We take the data_mutex lock early so that watchdog_open() cannot 1913 /*
1843 run when misc_register() has completed, but we've not yet added 1914 * We take the data_mutex lock early so that watchdog_open() cannot
1844 our data to the watchdog_data_list (and set the default timeout) */ 1915 * run when misc_register() has completed, but we've not yet added
1916 * our data to the watchdog_data_list (and set the default timeout)
1917 */
1845 mutex_lock(&watchdog_data_mutex); 1918 mutex_lock(&watchdog_data_mutex);
1846 for (i = 0; i < ARRAY_SIZE(watchdog_minors); i++) { 1919 for (i = 0; i < ARRAY_SIZE(watchdog_minors); i++) {
1847 /* Register our watchdog part */ 1920 /* Register our watchdog part */
@@ -1921,9 +1994,9 @@ static void w83793_update_nonvolatile(struct device *dev)
1921 struct w83793_data *data = i2c_get_clientdata(client); 1994 struct w83793_data *data = i2c_get_clientdata(client);
1922 int i, j; 1995 int i, j;
1923 /* 1996 /*
1924 They are somewhat "stable" registers, and to update them every time 1997 * They are somewhat "stable" registers, and to update them every time
1925 takes so much time, it's just not worthy. Update them in a long 1998 * takes so much time, it's just not worthy. Update them in a long
1926 interval to avoid exception. 1999 * interval to avoid exception.
1927 */ 2000 */
1928 if (!(time_after(jiffies, data->last_nonvolatile + HZ * 300) 2001 if (!(time_after(jiffies, data->last_nonvolatile + HZ * 300)
1929 || !data->valid)) 2002 || !data->valid))
@@ -1940,9 +2013,8 @@ static void w83793_update_nonvolatile(struct device *dev)
1940 2013
1941 for (i = 0; i < ARRAY_SIZE(data->fan_min); i++) { 2014 for (i = 0; i < ARRAY_SIZE(data->fan_min); i++) {
1942 /* Update the Fan measured value and limits */ 2015 /* Update the Fan measured value and limits */
1943 if (!(data->has_fan & (1 << i))) { 2016 if (!(data->has_fan & (1 << i)))
1944 continue; 2017 continue;
1945 }
1946 data->fan_min[i] = 2018 data->fan_min[i] =
1947 w83793_read_value(client, W83793_REG_FAN_MIN(i)) << 8; 2019 w83793_read_value(client, W83793_REG_FAN_MIN(i)) << 8;
1948 data->fan_min[i] |= 2020 data->fan_min[i] |=
@@ -1997,9 +2069,8 @@ static void w83793_update_nonvolatile(struct device *dev)
1997 w83793_read_value(client, W83793_REG_TEMP_CRITICAL); 2069 w83793_read_value(client, W83793_REG_TEMP_CRITICAL);
1998 data->beep_enable = w83793_read_value(client, W83793_REG_OVT_BEEP); 2070 data->beep_enable = w83793_read_value(client, W83793_REG_OVT_BEEP);
1999 2071
2000 for (i = 0; i < ARRAY_SIZE(data->beeps); i++) { 2072 for (i = 0; i < ARRAY_SIZE(data->beeps); i++)
2001 data->beeps[i] = w83793_read_value(client, W83793_REG_BEEP(i)); 2073 data->beeps[i] = w83793_read_value(client, W83793_REG_BEEP(i));
2002 }
2003 2074
2004 data->last_nonvolatile = jiffies; 2075 data->last_nonvolatile = jiffies;
2005} 2076}
@@ -2025,9 +2096,8 @@ static struct w83793_data *w83793_update_device(struct device *dev)
2025 w83793_read_value(client, W83793_REG_IN_LOW_BITS[IN_READ]); 2096 w83793_read_value(client, W83793_REG_IN_LOW_BITS[IN_READ]);
2026 2097
2027 for (i = 0; i < ARRAY_SIZE(data->fan); i++) { 2098 for (i = 0; i < ARRAY_SIZE(data->fan); i++) {
2028 if (!(data->has_fan & (1 << i))) { 2099 if (!(data->has_fan & (1 << i)))
2029 continue; 2100 continue;
2030 }
2031 data->fan[i] = 2101 data->fan[i] =
2032 w83793_read_value(client, W83793_REG_FAN(i)) << 8; 2102 w83793_read_value(client, W83793_REG_FAN(i)) << 8;
2033 data->fan[i] |= 2103 data->fan[i] |=
@@ -2067,8 +2137,10 @@ END:
2067 return data; 2137 return data;
2068} 2138}
2069 2139
2070/* Ignore the possibility that somebody change bank outside the driver 2140/*
2071 Must be called with data->update_lock held, except during initialization */ 2141 * Ignore the possibility that somebody change bank outside the driver
2142 * Must be called with data->update_lock held, except during initialization
2143 */
2072static u8 w83793_read_value(struct i2c_client *client, u16 reg) 2144static u8 w83793_read_value(struct i2c_client *client, u16 reg)
2073{ 2145{
2074 struct w83793_data *data = i2c_get_clientdata(client); 2146 struct w83793_data *data = i2c_get_clientdata(client);
@@ -2103,16 +2175,16 @@ static int w83793_write_value(struct i2c_client *client, u16 reg, u8 value)
2103 2175
2104 new_bank |= data->bank & 0xfc; 2176 new_bank |= data->bank & 0xfc;
2105 if (data->bank != new_bank) { 2177 if (data->bank != new_bank) {
2106 if ((res = i2c_smbus_write_byte_data 2178 res = i2c_smbus_write_byte_data(client, W83793_REG_BANKSEL,
2107 (client, W83793_REG_BANKSEL, new_bank)) >= 0) 2179 new_bank);
2108 data->bank = new_bank; 2180 if (res < 0) {
2109 else {
2110 dev_err(&client->dev, 2181 dev_err(&client->dev,
2111 "set bank to %d failed, fall back " 2182 "set bank to %d failed, fall back "
2112 "to bank %d, write reg 0x%x error\n", 2183 "to bank %d, write reg 0x%x error\n",
2113 new_bank, data->bank, reg); 2184 new_bank, data->bank, reg);
2114 goto END; 2185 goto END;
2115 } 2186 }
2187 data->bank = new_bank;
2116 } 2188 }
2117 2189
2118 res = i2c_smbus_write_byte_data(client, reg & 0xff, value); 2190 res = i2c_smbus_write_byte_data(client, reg & 0xff, value);