aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/w83627hf.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/w83627hf.c')
-rw-r--r--drivers/hwmon/w83627hf.c701
1 files changed, 342 insertions, 359 deletions
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c
index a2ccf93521c1..996fc1ca3227 100644
--- a/drivers/hwmon/w83627hf.c
+++ b/drivers/hwmon/w83627hf.c
@@ -45,6 +45,7 @@
45#include <linux/jiffies.h> 45#include <linux/jiffies.h>
46#include <linux/platform_device.h> 46#include <linux/platform_device.h>
47#include <linux/hwmon.h> 47#include <linux/hwmon.h>
48#include <linux/hwmon-sysfs.h>
48#include <linux/hwmon-vid.h> 49#include <linux/hwmon-vid.h>
49#include <linux/err.h> 50#include <linux/err.h>
50#include <linux/mutex.h> 51#include <linux/mutex.h>
@@ -218,7 +219,7 @@ static const u8 regpwm_627hf[] = { W83627HF_REG_PWM1, W83627HF_REG_PWM2 };
218static const u8 regpwm[] = { W83627THF_REG_PWM1, W83627THF_REG_PWM2, 219static const u8 regpwm[] = { W83627THF_REG_PWM1, W83627THF_REG_PWM2,
219 W83627THF_REG_PWM3 }; 220 W83627THF_REG_PWM3 };
220#define W836X7HF_REG_PWM(type, nr) (((type) == w83627hf) ? \ 221#define W836X7HF_REG_PWM(type, nr) (((type) == w83627hf) ? \
221 regpwm_627hf[(nr) - 1] : regpwm[(nr) - 1]) 222 regpwm_627hf[nr] : regpwm[nr])
222 223
223#define W83627HF_REG_PWM_FREQ 0x5C /* Only for the 627HF */ 224#define W83627HF_REG_PWM_FREQ 0x5C /* Only for the 627HF */
224 225
@@ -400,72 +401,71 @@ static struct platform_driver w83627hf_driver = {
400 .remove = __devexit_p(w83627hf_remove), 401 .remove = __devexit_p(w83627hf_remove),
401}; 402};
402 403
403/* following are the sysfs callback functions */ 404static ssize_t
404#define show_in_reg(reg) \ 405show_in_input(struct device *dev, struct device_attribute *devattr, char *buf)
405static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ 406{
406{ \ 407 int nr = to_sensor_dev_attr(devattr)->index;
407 struct w83627hf_data *data = w83627hf_update_device(dev); \ 408 struct w83627hf_data *data = w83627hf_update_device(dev);
408 return sprintf(buf,"%ld\n", (long)IN_FROM_REG(data->reg[nr])); \ 409 return sprintf(buf, "%ld\n", (long)IN_FROM_REG(data->in[nr]));
409} 410}
410show_in_reg(in) 411static ssize_t
411show_in_reg(in_min) 412show_in_min(struct device *dev, struct device_attribute *devattr, char *buf)
412show_in_reg(in_max) 413{
413 414 int nr = to_sensor_dev_attr(devattr)->index;
414#define store_in_reg(REG, reg) \ 415 struct w83627hf_data *data = w83627hf_update_device(dev);
415static ssize_t \ 416 return sprintf(buf, "%ld\n", (long)IN_FROM_REG(data->in_min[nr]));
416store_in_##reg (struct device *dev, const char *buf, size_t count, int nr) \ 417}
417{ \ 418static ssize_t
418 struct w83627hf_data *data = dev_get_drvdata(dev); \ 419show_in_max(struct device *dev, struct device_attribute *devattr, char *buf)
419 u32 val; \ 420{
420 \ 421 int nr = to_sensor_dev_attr(devattr)->index;
421 val = simple_strtoul(buf, NULL, 10); \ 422 struct w83627hf_data *data = w83627hf_update_device(dev);
422 \ 423 return sprintf(buf, "%ld\n", (long)IN_FROM_REG(data->in_max[nr]));
423 mutex_lock(&data->update_lock); \
424 data->in_##reg[nr] = IN_TO_REG(val); \
425 w83627hf_write_value(data, W83781D_REG_IN_##REG(nr), \
426 data->in_##reg[nr]); \
427 \
428 mutex_unlock(&data->update_lock); \
429 return count; \
430} 424}
431store_in_reg(MIN, min) 425static ssize_t
432store_in_reg(MAX, max) 426store_in_min(struct device *dev, struct device_attribute *devattr,
427 const char *buf, size_t count)
428{
429 int nr = to_sensor_dev_attr(devattr)->index;
430 struct w83627hf_data *data = dev_get_drvdata(dev);
431 long val = simple_strtol(buf, NULL, 10);
433 432
434#define sysfs_in_offset(offset) \ 433 mutex_lock(&data->update_lock);
435static ssize_t \ 434 data->in_min[nr] = IN_TO_REG(val);
436show_regs_in_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 435 w83627hf_write_value(data, W83781D_REG_IN_MIN(nr), data->in_min[nr]);
437{ \ 436 mutex_unlock(&data->update_lock);
438 return show_in(dev, buf, offset); \ 437 return count;
439} \ 438}
440static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_regs_in_##offset, NULL); 439static ssize_t
440store_in_max(struct device *dev, struct device_attribute *devattr,
441 const char *buf, size_t count)
442{
443 int nr = to_sensor_dev_attr(devattr)->index;
444 struct w83627hf_data *data = dev_get_drvdata(dev);
445 long val = simple_strtol(buf, NULL, 10);
441 446
442#define sysfs_in_reg_offset(reg, offset) \ 447 mutex_lock(&data->update_lock);
443static ssize_t show_regs_in_##reg##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 448 data->in_max[nr] = IN_TO_REG(val);
444{ \ 449 w83627hf_write_value(data, W83781D_REG_IN_MAX(nr), data->in_max[nr]);
445 return show_in_##reg (dev, buf, offset); \ 450 mutex_unlock(&data->update_lock);
446} \ 451 return count;
447static ssize_t \ 452}
448store_regs_in_##reg##offset (struct device *dev, struct device_attribute *attr, \ 453#define sysfs_vin_decl(offset) \
449 const char *buf, size_t count) \ 454static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
450{ \ 455 show_in_input, NULL, offset); \
451 return store_in_##reg (dev, buf, count, offset); \ 456static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO|S_IWUSR, \
452} \ 457 show_in_min, store_in_min, offset); \
453static DEVICE_ATTR(in##offset##_##reg, S_IRUGO| S_IWUSR, \ 458static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO|S_IWUSR, \
454 show_regs_in_##reg##offset, store_regs_in_##reg##offset); 459 show_in_max, store_in_max, offset);
455 460
456#define sysfs_in_offsets(offset) \ 461sysfs_vin_decl(1);
457sysfs_in_offset(offset) \ 462sysfs_vin_decl(2);
458sysfs_in_reg_offset(min, offset) \ 463sysfs_vin_decl(3);
459sysfs_in_reg_offset(max, offset) 464sysfs_vin_decl(4);
460 465sysfs_vin_decl(5);
461sysfs_in_offsets(1); 466sysfs_vin_decl(6);
462sysfs_in_offsets(2); 467sysfs_vin_decl(7);
463sysfs_in_offsets(3); 468sysfs_vin_decl(8);
464sysfs_in_offsets(4);
465sysfs_in_offsets(5);
466sysfs_in_offsets(6);
467sysfs_in_offsets(7);
468sysfs_in_offsets(8);
469 469
470/* use a different set of functions for in0 */ 470/* use a different set of functions for in0 */
471static ssize_t show_in_0(struct w83627hf_data *data, char *buf, u8 reg) 471static ssize_t show_in_0(struct w83627hf_data *data, char *buf, u8 reg)
@@ -563,134 +563,148 @@ static DEVICE_ATTR(in0_min, S_IRUGO | S_IWUSR,
563static DEVICE_ATTR(in0_max, S_IRUGO | S_IWUSR, 563static DEVICE_ATTR(in0_max, S_IRUGO | S_IWUSR,
564 show_regs_in_max0, store_regs_in_max0); 564 show_regs_in_max0, store_regs_in_max0);
565 565
566#define show_fan_reg(reg) \ 566static ssize_t
567static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ 567show_fan_input(struct device *dev, struct device_attribute *devattr, char *buf)
568{ \ 568{
569 struct w83627hf_data *data = w83627hf_update_device(dev); \ 569 int nr = to_sensor_dev_attr(devattr)->index;
570 return sprintf(buf,"%ld\n", \ 570 struct w83627hf_data *data = w83627hf_update_device(dev);
571 FAN_FROM_REG(data->reg[nr-1], \ 571 return sprintf(buf, "%ld\n", FAN_FROM_REG(data->fan[nr],
572 (long)DIV_FROM_REG(data->fan_div[nr-1]))); \ 572 (long)DIV_FROM_REG(data->fan_div[nr])));
573}
574static ssize_t
575show_fan_min(struct device *dev, struct device_attribute *devattr, char *buf)
576{
577 int nr = to_sensor_dev_attr(devattr)->index;
578 struct w83627hf_data *data = w83627hf_update_device(dev);
579 return sprintf(buf, "%ld\n", FAN_FROM_REG(data->fan_min[nr],
580 (long)DIV_FROM_REG(data->fan_div[nr])));
573} 581}
574show_fan_reg(fan);
575show_fan_reg(fan_min);
576
577static ssize_t 582static ssize_t
578store_fan_min(struct device *dev, const char *buf, size_t count, int nr) 583store_fan_min(struct device *dev, struct device_attribute *devattr,
584 const char *buf, size_t count)
579{ 585{
586 int nr = to_sensor_dev_attr(devattr)->index;
580 struct w83627hf_data *data = dev_get_drvdata(dev); 587 struct w83627hf_data *data = dev_get_drvdata(dev);
581 u32 val; 588 u32 val = simple_strtoul(buf, NULL, 10);
582
583 val = simple_strtoul(buf, NULL, 10);
584 589
585 mutex_lock(&data->update_lock); 590 mutex_lock(&data->update_lock);
586 data->fan_min[nr - 1] = 591 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
587 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr - 1])); 592 w83627hf_write_value(data, W83781D_REG_FAN_MIN(nr+1),
588 w83627hf_write_value(data, W83781D_REG_FAN_MIN(nr), 593 data->fan_min[nr]);
589 data->fan_min[nr - 1]);
590 594
591 mutex_unlock(&data->update_lock); 595 mutex_unlock(&data->update_lock);
592 return count; 596 return count;
593} 597}
598#define sysfs_fan_decl(offset) \
599static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
600 show_fan_input, NULL, offset - 1); \
601static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
602 show_fan_min, store_fan_min, offset - 1);
594 603
595#define sysfs_fan_offset(offset) \ 604sysfs_fan_decl(1);
596static ssize_t show_regs_fan_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 605sysfs_fan_decl(2);
597{ \ 606sysfs_fan_decl(3);
598 return show_fan(dev, buf, offset); \
599} \
600static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_regs_fan_##offset, NULL);
601 607
602#define sysfs_fan_min_offset(offset) \ 608static ssize_t
603static ssize_t show_regs_fan_min##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 609show_temp(struct device *dev, struct device_attribute *devattr, char *buf)
604{ \ 610{
605 return show_fan_min(dev, buf, offset); \ 611 int nr = to_sensor_dev_attr(devattr)->index;
606} \ 612 struct w83627hf_data *data = w83627hf_update_device(dev);
607static ssize_t \ 613 if (nr >= 2) { /* TEMP2 and TEMP3 */
608store_regs_fan_min##offset (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ 614 return sprintf(buf, "%ld\n",
609{ \ 615 (long)LM75_TEMP_FROM_REG(data->temp_add[nr-2]));
610 return store_fan_min(dev, buf, count, offset); \ 616 } else { /* TEMP1 */
611} \ 617 return sprintf(buf, "%ld\n", (long)TEMP_FROM_REG(data->temp));
612static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ 618 }
613 show_regs_fan_min##offset, store_regs_fan_min##offset);
614
615sysfs_fan_offset(1);
616sysfs_fan_min_offset(1);
617sysfs_fan_offset(2);
618sysfs_fan_min_offset(2);
619sysfs_fan_offset(3);
620sysfs_fan_min_offset(3);
621
622#define show_temp_reg(reg) \
623static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
624{ \
625 struct w83627hf_data *data = w83627hf_update_device(dev); \
626 if (nr >= 2) { /* TEMP2 and TEMP3 */ \
627 return sprintf(buf,"%ld\n", \
628 (long)LM75_TEMP_FROM_REG(data->reg##_add[nr-2])); \
629 } else { /* TEMP1 */ \
630 return sprintf(buf,"%ld\n", (long)TEMP_FROM_REG(data->reg)); \
631 } \
632} 619}
633show_temp_reg(temp);
634show_temp_reg(temp_max);
635show_temp_reg(temp_max_hyst);
636 620
637#define store_temp_reg(REG, reg) \ 621static ssize_t
638static ssize_t \ 622show_temp_max(struct device *dev, struct device_attribute *devattr,
639store_temp_##reg (struct device *dev, const char *buf, size_t count, int nr) \ 623 char *buf)
640{ \ 624{
641 struct w83627hf_data *data = dev_get_drvdata(dev); \ 625 int nr = to_sensor_dev_attr(devattr)->index;
642 long val; \ 626 struct w83627hf_data *data = w83627hf_update_device(dev);
643 \ 627 if (nr >= 2) { /* TEMP2 and TEMP3 */
644 val = simple_strtol(buf, NULL, 10); \ 628 return sprintf(buf, "%ld\n",
645 \ 629 (long)LM75_TEMP_FROM_REG(data->temp_max_add[nr-2]));
646 mutex_lock(&data->update_lock); \ 630 } else { /* TEMP1 */
647 \ 631 return sprintf(buf, "%ld\n",
648 if (nr >= 2) { /* TEMP2 and TEMP3 */ \ 632 (long)TEMP_FROM_REG(data->temp_max));
649 data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \ 633 }
650 w83627hf_write_value(data, W83781D_REG_TEMP_##REG(nr), \
651 data->temp_##reg##_add[nr-2]); \
652 } else { /* TEMP1 */ \
653 data->temp_##reg = TEMP_TO_REG(val); \
654 w83627hf_write_value(data, W83781D_REG_TEMP_##REG(nr), \
655 data->temp_##reg); \
656 } \
657 \
658 mutex_unlock(&data->update_lock); \
659 return count; \
660} 634}
661store_temp_reg(OVER, max);
662store_temp_reg(HYST, max_hyst);
663 635
664#define sysfs_temp_offset(offset) \ 636static ssize_t
665static ssize_t \ 637show_temp_max_hyst(struct device *dev, struct device_attribute *devattr,
666show_regs_temp_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 638 char *buf)
667{ \ 639{
668 return show_temp(dev, buf, offset); \ 640 int nr = to_sensor_dev_attr(devattr)->index;
669} \ 641 struct w83627hf_data *data = w83627hf_update_device(dev);
670static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_regs_temp_##offset, NULL); 642 if (nr >= 2) { /* TEMP2 and TEMP3 */
643 return sprintf(buf, "%ld\n",
644 (long)LM75_TEMP_FROM_REG(data->temp_max_hyst_add[nr-2]));
645 } else { /* TEMP1 */
646 return sprintf(buf, "%ld\n",
647 (long)TEMP_FROM_REG(data->temp_max_hyst));
648 }
649}
671 650
672#define sysfs_temp_reg_offset(reg, offset) \ 651static ssize_t
673static ssize_t show_regs_temp_##reg##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 652store_temp_max(struct device *dev, struct device_attribute *devattr,
674{ \ 653 const char *buf, size_t count)
675 return show_temp_##reg (dev, buf, offset); \ 654{
676} \ 655 int nr = to_sensor_dev_attr(devattr)->index;
677static ssize_t \ 656 struct w83627hf_data *data = dev_get_drvdata(dev);
678store_regs_temp_##reg##offset (struct device *dev, struct device_attribute *attr, \ 657 long val = simple_strtol(buf, NULL, 10);
679 const char *buf, size_t count) \
680{ \
681 return store_temp_##reg (dev, buf, count, offset); \
682} \
683static DEVICE_ATTR(temp##offset##_##reg, S_IRUGO| S_IWUSR, \
684 show_regs_temp_##reg##offset, store_regs_temp_##reg##offset);
685 658
686#define sysfs_temp_offsets(offset) \ 659 mutex_lock(&data->update_lock);
687sysfs_temp_offset(offset) \
688sysfs_temp_reg_offset(max, offset) \
689sysfs_temp_reg_offset(max_hyst, offset)
690 660
691sysfs_temp_offsets(1); 661 if (nr >= 2) { /* TEMP2 and TEMP3 */
692sysfs_temp_offsets(2); 662 data->temp_max_add[nr-2] = LM75_TEMP_TO_REG(val);
693sysfs_temp_offsets(3); 663 w83627hf_write_value(data, W83781D_REG_TEMP_OVER(nr),
664 data->temp_max_add[nr-2]);
665 } else { /* TEMP1 */
666 data->temp_max = TEMP_TO_REG(val);
667 w83627hf_write_value(data, W83781D_REG_TEMP_OVER(nr),
668 data->temp_max);
669 }
670 mutex_unlock(&data->update_lock);
671 return count;
672}
673
674static ssize_t
675store_temp_max_hyst(struct device *dev, struct device_attribute *devattr,
676 const char *buf, size_t count)
677{
678 int nr = to_sensor_dev_attr(devattr)->index;
679 struct w83627hf_data *data = dev_get_drvdata(dev);
680 long val = simple_strtol(buf, NULL, 10);
681
682 mutex_lock(&data->update_lock);
683
684 if (nr >= 2) { /* TEMP2 and TEMP3 */
685 data->temp_max_hyst_add[nr-2] = LM75_TEMP_TO_REG(val);
686 w83627hf_write_value(data, W83781D_REG_TEMP_HYST(nr),
687 data->temp_max_hyst_add[nr-2]);
688 } else { /* TEMP1 */
689 data->temp_max_hyst = TEMP_TO_REG(val);
690 w83627hf_write_value(data, W83781D_REG_TEMP_HYST(nr),
691 data->temp_max_hyst);
692 }
693 mutex_unlock(&data->update_lock);
694 return count;
695}
696
697#define sysfs_temp_decl(offset) \
698static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
699 show_temp, NULL, offset); \
700static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO|S_IWUSR, \
701 show_temp_max, store_temp_max, offset); \
702static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO|S_IWUSR, \
703 show_temp_max_hyst, store_temp_max_hyst, offset);
704
705sysfs_temp_decl(1);
706sysfs_temp_decl(2);
707sysfs_temp_decl(3);
694 708
695static ssize_t 709static ssize_t
696show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) 710show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
@@ -788,20 +802,22 @@ sysfs_beep(ENABLE, enable);
788sysfs_beep(MASK, mask); 802sysfs_beep(MASK, mask);
789 803
790static ssize_t 804static ssize_t
791show_fan_div_reg(struct device *dev, char *buf, int nr) 805show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf)
792{ 806{
807 int nr = to_sensor_dev_attr(devattr)->index;
793 struct w83627hf_data *data = w83627hf_update_device(dev); 808 struct w83627hf_data *data = w83627hf_update_device(dev);
794 return sprintf(buf, "%ld\n", 809 return sprintf(buf, "%ld\n",
795 (long) DIV_FROM_REG(data->fan_div[nr - 1])); 810 (long) DIV_FROM_REG(data->fan_div[nr]));
796} 811}
797
798/* Note: we save and restore the fan minimum here, because its value is 812/* Note: we save and restore the fan minimum here, because its value is
799 determined in part by the fan divisor. This follows the principle of 813 determined in part by the fan divisor. This follows the principle of
800 least surprise; the user doesn't expect the fan minimum to change just 814 least surprise; the user doesn't expect the fan minimum to change just
801 because the divisor changed. */ 815 because the divisor changed. */
802static ssize_t 816static ssize_t
803store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr) 817store_fan_div(struct device *dev, struct device_attribute *devattr,
818 const char *buf, size_t count)
804{ 819{
820 int nr = to_sensor_dev_attr(devattr)->index;
805 struct w83627hf_data *data = dev_get_drvdata(dev); 821 struct w83627hf_data *data = dev_get_drvdata(dev);
806 unsigned long min; 822 unsigned long min;
807 u8 reg; 823 u8 reg;
@@ -833,92 +849,72 @@ store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr)
833 return count; 849 return count;
834} 850}
835 851
836#define sysfs_fan_div(offset) \ 852static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO|S_IWUSR,
837static ssize_t show_regs_fan_div_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 853 show_fan_div, store_fan_div, 0);
838{ \ 854static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO|S_IWUSR,
839 return show_fan_div_reg(dev, buf, offset); \ 855 show_fan_div, store_fan_div, 1);
840} \ 856static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO|S_IWUSR,
841static ssize_t \ 857 show_fan_div, store_fan_div, 2);
842store_regs_fan_div_##offset (struct device *dev, struct device_attribute *attr, \
843 const char *buf, size_t count) \
844{ \
845 return store_fan_div_reg(dev, buf, count, offset - 1); \
846} \
847static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
848 show_regs_fan_div_##offset, store_regs_fan_div_##offset);
849
850sysfs_fan_div(1);
851sysfs_fan_div(2);
852sysfs_fan_div(3);
853 858
854static ssize_t 859static ssize_t
855show_pwm_reg(struct device *dev, char *buf, int nr) 860show_pwm(struct device *dev, struct device_attribute *devattr, char *buf)
856{ 861{
862 int nr = to_sensor_dev_attr(devattr)->index;
857 struct w83627hf_data *data = w83627hf_update_device(dev); 863 struct w83627hf_data *data = w83627hf_update_device(dev);
858 return sprintf(buf, "%ld\n", (long) data->pwm[nr - 1]); 864 return sprintf(buf, "%ld\n", (long) data->pwm[nr]);
859} 865}
860 866
861static ssize_t 867static ssize_t
862store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr) 868store_pwm(struct device *dev, struct device_attribute *devattr,
869 const char *buf, size_t count)
863{ 870{
871 int nr = to_sensor_dev_attr(devattr)->index;
864 struct w83627hf_data *data = dev_get_drvdata(dev); 872 struct w83627hf_data *data = dev_get_drvdata(dev);
865 u32 val; 873 u32 val = simple_strtoul(buf, NULL, 10);
866
867 val = simple_strtoul(buf, NULL, 10);
868 874
869 mutex_lock(&data->update_lock); 875 mutex_lock(&data->update_lock);
870 876
871 if (data->type == w83627thf) { 877 if (data->type == w83627thf) {
872 /* bits 0-3 are reserved in 627THF */ 878 /* bits 0-3 are reserved in 627THF */
873 data->pwm[nr - 1] = PWM_TO_REG(val) & 0xf0; 879 data->pwm[nr] = PWM_TO_REG(val) & 0xf0;
874 w83627hf_write_value(data, 880 w83627hf_write_value(data,
875 W836X7HF_REG_PWM(data->type, nr), 881 W836X7HF_REG_PWM(data->type, nr),
876 data->pwm[nr - 1] | 882 data->pwm[nr] |
877 (w83627hf_read_value(data, 883 (w83627hf_read_value(data,
878 W836X7HF_REG_PWM(data->type, nr)) & 0x0f)); 884 W836X7HF_REG_PWM(data->type, nr)) & 0x0f));
879 } else { 885 } else {
880 data->pwm[nr - 1] = PWM_TO_REG(val); 886 data->pwm[nr] = PWM_TO_REG(val);
881 w83627hf_write_value(data, 887 w83627hf_write_value(data,
882 W836X7HF_REG_PWM(data->type, nr), 888 W836X7HF_REG_PWM(data->type, nr),
883 data->pwm[nr - 1]); 889 data->pwm[nr]);
884 } 890 }
885 891
886 mutex_unlock(&data->update_lock); 892 mutex_unlock(&data->update_lock);
887 return count; 893 return count;
888} 894}
889 895
890#define sysfs_pwm(offset) \ 896static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0);
891static ssize_t show_regs_pwm_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 897static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 1);
892{ \ 898static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 2);
893 return show_pwm_reg(dev, buf, offset); \
894} \
895static ssize_t \
896store_regs_pwm_##offset (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
897{ \
898 return store_pwm_reg(dev, buf, count, offset); \
899} \
900static DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
901 show_regs_pwm_##offset, store_regs_pwm_##offset);
902
903sysfs_pwm(1);
904sysfs_pwm(2);
905sysfs_pwm(3);
906 899
907static ssize_t 900static ssize_t
908show_pwm_freq_reg(struct device *dev, char *buf, int nr) 901show_pwm_freq(struct device *dev, struct device_attribute *devattr, char *buf)
909{ 902{
903 int nr = to_sensor_dev_attr(devattr)->index;
910 struct w83627hf_data *data = w83627hf_update_device(dev); 904 struct w83627hf_data *data = w83627hf_update_device(dev);
911 if (data->type == w83627hf) 905 if (data->type == w83627hf)
912 return sprintf(buf, "%ld\n", 906 return sprintf(buf, "%ld\n",
913 pwm_freq_from_reg_627hf(data->pwm_freq[nr - 1])); 907 pwm_freq_from_reg_627hf(data->pwm_freq[nr]));
914 else 908 else
915 return sprintf(buf, "%ld\n", 909 return sprintf(buf, "%ld\n",
916 pwm_freq_from_reg(data->pwm_freq[nr - 1])); 910 pwm_freq_from_reg(data->pwm_freq[nr]));
917} 911}
918 912
919static ssize_t 913static ssize_t
920store_pwm_freq_reg(struct device *dev, const char *buf, size_t count, int nr) 914store_pwm_freq(struct device *dev, struct device_attribute *devattr,
915 const char *buf, size_t count)
921{ 916{
917 int nr = to_sensor_dev_attr(devattr)->index;
922 struct w83627hf_data *data = dev_get_drvdata(dev); 918 struct w83627hf_data *data = dev_get_drvdata(dev);
923 static const u8 mask[]={0xF8, 0x8F}; 919 static const u8 mask[]={0xF8, 0x8F};
924 u32 val; 920 u32 val;
@@ -928,50 +924,42 @@ store_pwm_freq_reg(struct device *dev, const char *buf, size_t count, int nr)
928 mutex_lock(&data->update_lock); 924 mutex_lock(&data->update_lock);
929 925
930 if (data->type == w83627hf) { 926 if (data->type == w83627hf) {
931 data->pwm_freq[nr - 1] = pwm_freq_to_reg_627hf(val); 927 data->pwm_freq[nr] = pwm_freq_to_reg_627hf(val);
932 w83627hf_write_value(data, W83627HF_REG_PWM_FREQ, 928 w83627hf_write_value(data, W83627HF_REG_PWM_FREQ,
933 (data->pwm_freq[nr - 1] << ((nr - 1)*4)) | 929 (data->pwm_freq[nr] << (nr*4)) |
934 (w83627hf_read_value(data, 930 (w83627hf_read_value(data,
935 W83627HF_REG_PWM_FREQ) & mask[nr - 1])); 931 W83627HF_REG_PWM_FREQ) & mask[nr]));
936 } else { 932 } else {
937 data->pwm_freq[nr - 1] = pwm_freq_to_reg(val); 933 data->pwm_freq[nr] = pwm_freq_to_reg(val);
938 w83627hf_write_value(data, W83637HF_REG_PWM_FREQ[nr - 1], 934 w83627hf_write_value(data, W83637HF_REG_PWM_FREQ[nr],
939 data->pwm_freq[nr - 1]); 935 data->pwm_freq[nr]);
940 } 936 }
941 937
942 mutex_unlock(&data->update_lock); 938 mutex_unlock(&data->update_lock);
943 return count; 939 return count;
944} 940}
945 941
946#define sysfs_pwm_freq(offset) \ 942static SENSOR_DEVICE_ATTR(pwm1_freq, S_IRUGO|S_IWUSR,
947static ssize_t show_regs_pwm_freq_##offset(struct device *dev, \ 943 show_pwm_freq, store_pwm_freq, 0);
948 struct device_attribute *attr, char *buf) \ 944static SENSOR_DEVICE_ATTR(pwm2_freq, S_IRUGO|S_IWUSR,
949{ \ 945 show_pwm_freq, store_pwm_freq, 1);
950 return show_pwm_freq_reg(dev, buf, offset); \ 946static SENSOR_DEVICE_ATTR(pwm3_freq, S_IRUGO|S_IWUSR,
951} \ 947 show_pwm_freq, store_pwm_freq, 2);
952static ssize_t \
953store_regs_pwm_freq_##offset(struct device *dev, \
954 struct device_attribute *attr, const char *buf, size_t count) \
955{ \
956 return store_pwm_freq_reg(dev, buf, count, offset); \
957} \
958static DEVICE_ATTR(pwm##offset##_freq, S_IRUGO | S_IWUSR, \
959 show_regs_pwm_freq_##offset, store_regs_pwm_freq_##offset);
960
961sysfs_pwm_freq(1);
962sysfs_pwm_freq(2);
963sysfs_pwm_freq(3);
964 948
965static ssize_t 949static ssize_t
966show_sensor_reg(struct device *dev, char *buf, int nr) 950show_temp_type(struct device *dev, struct device_attribute *devattr,
951 char *buf)
967{ 952{
953 int nr = to_sensor_dev_attr(devattr)->index;
968 struct w83627hf_data *data = w83627hf_update_device(dev); 954 struct w83627hf_data *data = w83627hf_update_device(dev);
969 return sprintf(buf, "%ld\n", (long) data->sens[nr - 1]); 955 return sprintf(buf, "%ld\n", (long) data->sens[nr]);
970} 956}
971 957
972static ssize_t 958static ssize_t
973store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr) 959store_temp_type(struct device *dev, struct device_attribute *devattr,
960 const char *buf, size_t count)
974{ 961{
962 int nr = to_sensor_dev_attr(devattr)->index;
975 struct w83627hf_data *data = dev_get_drvdata(dev); 963 struct w83627hf_data *data = dev_get_drvdata(dev);
976 u32 val, tmp; 964 u32 val, tmp;
977 965
@@ -983,20 +971,20 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr)
983 case 1: /* PII/Celeron diode */ 971 case 1: /* PII/Celeron diode */
984 tmp = w83627hf_read_value(data, W83781D_REG_SCFG1); 972 tmp = w83627hf_read_value(data, W83781D_REG_SCFG1);
985 w83627hf_write_value(data, W83781D_REG_SCFG1, 973 w83627hf_write_value(data, W83781D_REG_SCFG1,
986 tmp | BIT_SCFG1[nr - 1]); 974 tmp | BIT_SCFG1[nr]);
987 tmp = w83627hf_read_value(data, W83781D_REG_SCFG2); 975 tmp = w83627hf_read_value(data, W83781D_REG_SCFG2);
988 w83627hf_write_value(data, W83781D_REG_SCFG2, 976 w83627hf_write_value(data, W83781D_REG_SCFG2,
989 tmp | BIT_SCFG2[nr - 1]); 977 tmp | BIT_SCFG2[nr]);
990 data->sens[nr - 1] = val; 978 data->sens[nr] = val;
991 break; 979 break;
992 case 2: /* 3904 */ 980 case 2: /* 3904 */
993 tmp = w83627hf_read_value(data, W83781D_REG_SCFG1); 981 tmp = w83627hf_read_value(data, W83781D_REG_SCFG1);
994 w83627hf_write_value(data, W83781D_REG_SCFG1, 982 w83627hf_write_value(data, W83781D_REG_SCFG1,
995 tmp | BIT_SCFG1[nr - 1]); 983 tmp | BIT_SCFG1[nr]);
996 tmp = w83627hf_read_value(data, W83781D_REG_SCFG2); 984 tmp = w83627hf_read_value(data, W83781D_REG_SCFG2);
997 w83627hf_write_value(data, W83781D_REG_SCFG2, 985 w83627hf_write_value(data, W83781D_REG_SCFG2,
998 tmp & ~BIT_SCFG2[nr - 1]); 986 tmp & ~BIT_SCFG2[nr]);
999 data->sens[nr - 1] = val; 987 data->sens[nr] = val;
1000 break; 988 break;
1001 case W83781D_DEFAULT_BETA: 989 case W83781D_DEFAULT_BETA:
1002 dev_warn(dev, "Sensor type %d is deprecated, please use 4 " 990 dev_warn(dev, "Sensor type %d is deprecated, please use 4 "
@@ -1005,8 +993,8 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr)
1005 case 4: /* thermistor */ 993 case 4: /* thermistor */
1006 tmp = w83627hf_read_value(data, W83781D_REG_SCFG1); 994 tmp = w83627hf_read_value(data, W83781D_REG_SCFG1);
1007 w83627hf_write_value(data, W83781D_REG_SCFG1, 995 w83627hf_write_value(data, W83781D_REG_SCFG1,
1008 tmp & ~BIT_SCFG1[nr - 1]); 996 tmp & ~BIT_SCFG1[nr]);
1009 data->sens[nr - 1] = val; 997 data->sens[nr] = val;
1010 break; 998 break;
1011 default: 999 default:
1012 dev_err(dev, 1000 dev_err(dev,
@@ -1019,25 +1007,16 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr)
1019 return count; 1007 return count;
1020} 1008}
1021 1009
1022#define sysfs_sensor(offset) \ 1010#define sysfs_temp_type(offset) \
1023static ssize_t show_regs_sensor_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 1011static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \
1024{ \ 1012 show_temp_type, store_temp_type, offset - 1);
1025 return show_sensor_reg(dev, buf, offset); \
1026} \
1027static ssize_t \
1028store_regs_sensor_##offset (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
1029{ \
1030 return store_sensor_reg(dev, buf, count, offset); \
1031} \
1032static DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \
1033 show_regs_sensor_##offset, store_regs_sensor_##offset);
1034 1013
1035sysfs_sensor(1); 1014sysfs_temp_type(1);
1036sysfs_sensor(2); 1015sysfs_temp_type(2);
1037sysfs_sensor(3); 1016sysfs_temp_type(3);
1038 1017
1039static ssize_t show_name(struct device *dev, struct device_attribute 1018static ssize_t
1040 *devattr, char *buf) 1019show_name(struct device *dev, struct device_attribute *devattr, char *buf)
1041{ 1020{
1042 struct w83627hf_data *data = dev_get_drvdata(dev); 1021 struct w83627hf_data *data = dev_get_drvdata(dev);
1043 1022
@@ -1119,49 +1098,44 @@ static int __init w83627hf_find(int sioaddr, unsigned short *addr,
1119 return err; 1098 return err;
1120} 1099}
1121 1100
1101#define VIN_UNIT_ATTRS(_X_) \
1102 &sensor_dev_attr_in##_X_##_input.dev_attr.attr, \
1103 &sensor_dev_attr_in##_X_##_min.dev_attr.attr, \
1104 &sensor_dev_attr_in##_X_##_max.dev_attr.attr
1105
1106#define FAN_UNIT_ATTRS(_X_) \
1107 &sensor_dev_attr_fan##_X_##_input.dev_attr.attr, \
1108 &sensor_dev_attr_fan##_X_##_min.dev_attr.attr, \
1109 &sensor_dev_attr_fan##_X_##_div.dev_attr.attr
1110
1111#define TEMP_UNIT_ATTRS(_X_) \
1112 &sensor_dev_attr_temp##_X_##_input.dev_attr.attr, \
1113 &sensor_dev_attr_temp##_X_##_max.dev_attr.attr, \
1114 &sensor_dev_attr_temp##_X_##_max_hyst.dev_attr.attr, \
1115 &sensor_dev_attr_temp##_X_##_type.dev_attr.attr
1116
1122static struct attribute *w83627hf_attributes[] = { 1117static struct attribute *w83627hf_attributes[] = {
1123 &dev_attr_in0_input.attr, 1118 &dev_attr_in0_input.attr,
1124 &dev_attr_in0_min.attr, 1119 &dev_attr_in0_min.attr,
1125 &dev_attr_in0_max.attr, 1120 &dev_attr_in0_max.attr,
1126 &dev_attr_in2_input.attr, 1121 VIN_UNIT_ATTRS(2),
1127 &dev_attr_in2_min.attr, 1122 VIN_UNIT_ATTRS(3),
1128 &dev_attr_in2_max.attr, 1123 VIN_UNIT_ATTRS(4),
1129 &dev_attr_in3_input.attr, 1124 VIN_UNIT_ATTRS(7),
1130 &dev_attr_in3_min.attr, 1125 VIN_UNIT_ATTRS(8),
1131 &dev_attr_in3_max.attr, 1126
1132 &dev_attr_in4_input.attr, 1127 FAN_UNIT_ATTRS(1),
1133 &dev_attr_in4_min.attr, 1128 FAN_UNIT_ATTRS(2),
1134 &dev_attr_in4_max.attr, 1129
1135 &dev_attr_in7_input.attr, 1130 TEMP_UNIT_ATTRS(1),
1136 &dev_attr_in7_min.attr, 1131 TEMP_UNIT_ATTRS(2),
1137 &dev_attr_in7_max.attr,
1138 &dev_attr_in8_input.attr,
1139 &dev_attr_in8_min.attr,
1140 &dev_attr_in8_max.attr,
1141
1142 &dev_attr_fan1_input.attr,
1143 &dev_attr_fan1_min.attr,
1144 &dev_attr_fan1_div.attr,
1145 &dev_attr_fan2_input.attr,
1146 &dev_attr_fan2_min.attr,
1147 &dev_attr_fan2_div.attr,
1148
1149 &dev_attr_temp1_input.attr,
1150 &dev_attr_temp1_max.attr,
1151 &dev_attr_temp1_max_hyst.attr,
1152 &dev_attr_temp1_type.attr,
1153 &dev_attr_temp2_input.attr,
1154 &dev_attr_temp2_max.attr,
1155 &dev_attr_temp2_max_hyst.attr,
1156 &dev_attr_temp2_type.attr,
1157 1132
1158 &dev_attr_alarms.attr, 1133 &dev_attr_alarms.attr,
1159 &dev_attr_beep_enable.attr, 1134 &dev_attr_beep_enable.attr,
1160 &dev_attr_beep_mask.attr, 1135 &dev_attr_beep_mask.attr,
1161 1136
1162 &dev_attr_pwm1.attr, 1137 &sensor_dev_attr_pwm1.dev_attr.attr,
1163 &dev_attr_pwm2.attr, 1138 &sensor_dev_attr_pwm2.dev_attr.attr,
1164
1165 &dev_attr_name.attr, 1139 &dev_attr_name.attr,
1166 NULL 1140 NULL
1167}; 1141};
@@ -1171,30 +1145,17 @@ static const struct attribute_group w83627hf_group = {
1171}; 1145};
1172 1146
1173static struct attribute *w83627hf_attributes_opt[] = { 1147static struct attribute *w83627hf_attributes_opt[] = {
1174 &dev_attr_in1_input.attr, 1148 VIN_UNIT_ATTRS(1),
1175 &dev_attr_in1_min.attr, 1149 VIN_UNIT_ATTRS(5),
1176 &dev_attr_in1_max.attr, 1150 VIN_UNIT_ATTRS(6),
1177 &dev_attr_in5_input.attr, 1151
1178 &dev_attr_in5_min.attr, 1152 FAN_UNIT_ATTRS(3),
1179 &dev_attr_in5_max.attr, 1153 TEMP_UNIT_ATTRS(3),
1180 &dev_attr_in6_input.attr, 1154 &sensor_dev_attr_pwm3.dev_attr.attr,
1181 &dev_attr_in6_min.attr, 1155
1182 &dev_attr_in6_max.attr, 1156 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
1183 1157 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
1184 &dev_attr_fan3_input.attr, 1158 &sensor_dev_attr_pwm3_freq.dev_attr.attr,
1185 &dev_attr_fan3_min.attr,
1186 &dev_attr_fan3_div.attr,
1187
1188 &dev_attr_temp3_input.attr,
1189 &dev_attr_temp3_max.attr,
1190 &dev_attr_temp3_max_hyst.attr,
1191 &dev_attr_temp3_type.attr,
1192
1193 &dev_attr_pwm3.attr,
1194
1195 &dev_attr_pwm1_freq.attr,
1196 &dev_attr_pwm2_freq.attr,
1197 &dev_attr_pwm3_freq.attr,
1198 NULL 1159 NULL
1199}; 1160};
1200 1161
@@ -1252,27 +1213,45 @@ static int __devinit w83627hf_probe(struct platform_device *pdev)
1252 1213
1253 /* Register chip-specific device attributes */ 1214 /* Register chip-specific device attributes */
1254 if (data->type == w83627hf || data->type == w83697hf) 1215 if (data->type == w83627hf || data->type == w83697hf)
1255 if ((err = device_create_file(dev, &dev_attr_in5_input)) 1216 if ((err = device_create_file(dev,
1256 || (err = device_create_file(dev, &dev_attr_in5_min)) 1217 &sensor_dev_attr_in5_input.dev_attr))
1257 || (err = device_create_file(dev, &dev_attr_in5_max)) 1218 || (err = device_create_file(dev,
1258 || (err = device_create_file(dev, &dev_attr_in6_input)) 1219 &sensor_dev_attr_in5_min.dev_attr))
1259 || (err = device_create_file(dev, &dev_attr_in6_min)) 1220 || (err = device_create_file(dev,
1260 || (err = device_create_file(dev, &dev_attr_in6_max)) 1221 &sensor_dev_attr_in5_max.dev_attr))
1261 || (err = device_create_file(dev, &dev_attr_pwm1_freq)) 1222 || (err = device_create_file(dev,
1262 || (err = device_create_file(dev, &dev_attr_pwm2_freq))) 1223 &sensor_dev_attr_in6_input.dev_attr))
1224 || (err = device_create_file(dev,
1225 &sensor_dev_attr_in6_min.dev_attr))
1226 || (err = device_create_file(dev,
1227 &sensor_dev_attr_in6_max.dev_attr))
1228 || (err = device_create_file(dev,
1229 &sensor_dev_attr_pwm1_freq.dev_attr))
1230 || (err = device_create_file(dev,
1231 &sensor_dev_attr_pwm2_freq.dev_attr)))
1263 goto ERROR4; 1232 goto ERROR4;
1264 1233
1265 if (data->type != w83697hf) 1234 if (data->type != w83697hf)
1266 if ((err = device_create_file(dev, &dev_attr_in1_input)) 1235 if ((err = device_create_file(dev,
1267 || (err = device_create_file(dev, &dev_attr_in1_min)) 1236 &sensor_dev_attr_in1_input.dev_attr))
1268 || (err = device_create_file(dev, &dev_attr_in1_max)) 1237 || (err = device_create_file(dev,
1269 || (err = device_create_file(dev, &dev_attr_fan3_input)) 1238 &sensor_dev_attr_in1_min.dev_attr))
1270 || (err = device_create_file(dev, &dev_attr_fan3_min)) 1239 || (err = device_create_file(dev,
1271 || (err = device_create_file(dev, &dev_attr_fan3_div)) 1240 &sensor_dev_attr_in1_max.dev_attr))
1272 || (err = device_create_file(dev, &dev_attr_temp3_input)) 1241 || (err = device_create_file(dev,
1273 || (err = device_create_file(dev, &dev_attr_temp3_max)) 1242 &sensor_dev_attr_fan3_input.dev_attr))
1274 || (err = device_create_file(dev, &dev_attr_temp3_max_hyst)) 1243 || (err = device_create_file(dev,
1275 || (err = device_create_file(dev, &dev_attr_temp3_type))) 1244 &sensor_dev_attr_fan3_min.dev_attr))
1245 || (err = device_create_file(dev,
1246 &sensor_dev_attr_fan3_div.dev_attr))
1247 || (err = device_create_file(dev,
1248 &sensor_dev_attr_temp3_input.dev_attr))
1249 || (err = device_create_file(dev,
1250 &sensor_dev_attr_temp3_max.dev_attr))
1251 || (err = device_create_file(dev,
1252 &sensor_dev_attr_temp3_max_hyst.dev_attr))
1253 || (err = device_create_file(dev,
1254 &sensor_dev_attr_temp3_type.dev_attr)))
1276 goto ERROR4; 1255 goto ERROR4;
1277 1256
1278 if (data->type != w83697hf && data->vid != 0xff) { 1257 if (data->type != w83697hf && data->vid != 0xff) {
@@ -1286,13 +1265,17 @@ static int __devinit w83627hf_probe(struct platform_device *pdev)
1286 1265
1287 if (data->type == w83627thf || data->type == w83637hf 1266 if (data->type == w83627thf || data->type == w83637hf
1288 || data->type == w83687thf) 1267 || data->type == w83687thf)
1289 if ((err = device_create_file(dev, &dev_attr_pwm3))) 1268 if ((err = device_create_file(dev,
1269 &sensor_dev_attr_pwm3.dev_attr)))
1290 goto ERROR4; 1270 goto ERROR4;
1291 1271
1292 if (data->type == w83637hf || data->type == w83687thf) 1272 if (data->type == w83637hf || data->type == w83687thf)
1293 if ((err = device_create_file(dev, &dev_attr_pwm1_freq)) 1273 if ((err = device_create_file(dev,
1294 || (err = device_create_file(dev, &dev_attr_pwm2_freq)) 1274 &sensor_dev_attr_pwm1_freq.dev_attr))
1295 || (err = device_create_file(dev, &dev_attr_pwm3_freq))) 1275 || (err = device_create_file(dev,
1276 &sensor_dev_attr_pwm2_freq.dev_attr))
1277 || (err = device_create_file(dev,
1278 &sensor_dev_attr_pwm3_freq.dev_attr)))
1296 goto ERROR4; 1279 goto ERROR4;
1297 1280
1298 data->hwmon_dev = hwmon_device_register(dev); 1281 data->hwmon_dev = hwmon_device_register(dev);
@@ -1588,15 +1571,15 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev)
1588 w83627hf_read_value(data, 1571 w83627hf_read_value(data,
1589 W83781D_REG_FAN_MIN(i)); 1572 W83781D_REG_FAN_MIN(i));
1590 } 1573 }
1591 for (i = 1; i <= 3; i++) { 1574 for (i = 0; i <= 2; i++) {
1592 u8 tmp = w83627hf_read_value(data, 1575 u8 tmp = w83627hf_read_value(data,
1593 W836X7HF_REG_PWM(data->type, i)); 1576 W836X7HF_REG_PWM(data->type, i));
1594 /* bits 0-3 are reserved in 627THF */ 1577 /* bits 0-3 are reserved in 627THF */
1595 if (data->type == w83627thf) 1578 if (data->type == w83627thf)
1596 tmp &= 0xf0; 1579 tmp &= 0xf0;
1597 data->pwm[i - 1] = tmp; 1580 data->pwm[i] = tmp;
1598 if(i == 2 && 1581 if (i == 1 &&
1599 (data->type == w83627hf || data->type == w83697hf)) 1582 (data->type == w83627hf || data->type == w83697hf))
1600 break; 1583 break;
1601 } 1584 }
1602 if (data->type == w83627hf) { 1585 if (data->type == w83627hf) {