diff options
Diffstat (limited to 'drivers/hwmon')
39 files changed, 2273 insertions, 1138 deletions
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 5ce43d8dfa98..bc196f49ec53 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig | |||
@@ -111,22 +111,6 @@ config SENSORS_AD7418 | |||
111 | This driver can also be built as a module. If so, the module | 111 | This driver can also be built as a module. If so, the module |
112 | will be called ad7418. | 112 | will be called ad7418. |
113 | 113 | ||
114 | config SENSORS_ADCXX | ||
115 | tristate "National Semiconductor ADCxxxSxxx" | ||
116 | depends on SPI_MASTER | ||
117 | help | ||
118 | If you say yes here you get support for the National Semiconductor | ||
119 | ADC<bb><c>S<sss> chip family, where | ||
120 | * bb is the resolution in number of bits (8, 10, 12) | ||
121 | * c is the number of channels (1, 2, 4, 8) | ||
122 | * sss is the maximum conversion speed (021 for 200 kSPS, 051 for 500 | ||
123 | kSPS and 101 for 1 MSPS) | ||
124 | |||
125 | Examples : ADC081S101, ADC124S501, ... | ||
126 | |||
127 | This driver can also be built as a module. If so, the module | ||
128 | will be called adcxx. | ||
129 | |||
130 | config SENSORS_ADM1021 | 114 | config SENSORS_ADM1021 |
131 | tristate "Analog Devices ADM1021 and compatibles" | 115 | tristate "Analog Devices ADM1021 and compatibles" |
132 | depends on I2C | 116 | depends on I2C |
@@ -296,8 +280,8 @@ config SENSORS_K10TEMP | |||
296 | If you say yes here you get support for the temperature | 280 | If you say yes here you get support for the temperature |
297 | sensor(s) inside your CPU. Supported are later revisions of | 281 | sensor(s) inside your CPU. Supported are later revisions of |
298 | the AMD Family 10h and all revisions of the AMD Family 11h, | 282 | the AMD Family 10h and all revisions of the AMD Family 11h, |
299 | 12h (Llano), 14h (Brazos), 15h (Bulldozer/Trinity) and | 283 | 12h (Llano), 14h (Brazos), 15h (Bulldozer/Trinity/Kaveri) and |
300 | 16h (Kabini) microarchitectures. | 284 | 16h (Kabini/Mullins) microarchitectures. |
301 | 285 | ||
302 | This driver can also be built as a module. If so, the module | 286 | This driver can also be built as a module. If so, the module |
303 | will be called k10temp. | 287 | will be called k10temp. |
@@ -312,6 +296,31 @@ config SENSORS_FAM15H_POWER | |||
312 | This driver can also be built as a module. If so, the module | 296 | This driver can also be built as a module. If so, the module |
313 | will be called fam15h_power. | 297 | will be called fam15h_power. |
314 | 298 | ||
299 | config SENSORS_APPLESMC | ||
300 | tristate "Apple SMC (Motion sensor, light sensor, keyboard backlight)" | ||
301 | depends on INPUT && X86 | ||
302 | select NEW_LEDS | ||
303 | select LEDS_CLASS | ||
304 | select INPUT_POLLDEV | ||
305 | default n | ||
306 | help | ||
307 | This driver provides support for the Apple System Management | ||
308 | Controller, which provides an accelerometer (Apple Sudden Motion | ||
309 | Sensor), light sensors, temperature sensors, keyboard backlight | ||
310 | control and fan control. | ||
311 | |||
312 | Only Intel-based Apple's computers are supported (MacBook Pro, | ||
313 | MacBook, MacMini). | ||
314 | |||
315 | Data from the different sensors, keyboard backlight control and fan | ||
316 | control are accessible via sysfs. | ||
317 | |||
318 | This driver also provides an absolute input class device, allowing | ||
319 | the laptop to act as a pinball machine-esque joystick. | ||
320 | |||
321 | Say Y here if you have an applicable laptop and want to experience | ||
322 | the awesome power of applesmc. | ||
323 | |||
315 | config SENSORS_ASB100 | 324 | config SENSORS_ASB100 |
316 | tristate "Asus ASB100 Bach" | 325 | tristate "Asus ASB100 Bach" |
317 | depends on X86 && I2C | 326 | depends on X86 && I2C |
@@ -435,6 +444,12 @@ config SENSORS_F75375S | |||
435 | This driver can also be built as a module. If so, the module | 444 | This driver can also be built as a module. If so, the module |
436 | will be called f75375s. | 445 | will be called f75375s. |
437 | 446 | ||
447 | config SENSORS_MC13783_ADC | ||
448 | tristate "Freescale MC13783/MC13892 ADC" | ||
449 | depends on MFD_MC13XXX | ||
450 | help | ||
451 | Support for the A/D converter on MC13783 and MC13892 PMIC. | ||
452 | |||
438 | config SENSORS_FSCHMD | 453 | config SENSORS_FSCHMD |
439 | tristate "Fujitsu Siemens Computers sensor chips" | 454 | tristate "Fujitsu Siemens Computers sensor chips" |
440 | depends on X86 && I2C | 455 | depends on X86 && I2C |
@@ -451,26 +466,6 @@ config SENSORS_FSCHMD | |||
451 | This driver can also be built as a module. If so, the module | 466 | This driver can also be built as a module. If so, the module |
452 | will be called fschmd. | 467 | will be called fschmd. |
453 | 468 | ||
454 | config SENSORS_G760A | ||
455 | tristate "GMT G760A" | ||
456 | depends on I2C | ||
457 | help | ||
458 | If you say yes here you get support for Global Mixed-mode | ||
459 | Technology Inc G760A fan speed PWM controller chips. | ||
460 | |||
461 | This driver can also be built as a module. If so, the module | ||
462 | will be called g760a. | ||
463 | |||
464 | config SENSORS_G762 | ||
465 | tristate "GMT G762 and G763" | ||
466 | depends on I2C | ||
467 | help | ||
468 | If you say yes here you get support for Global Mixed-mode | ||
469 | Technology Inc G762 and G763 fan speed PWM controller chips. | ||
470 | |||
471 | This driver can also be built as a module. If so, the module | ||
472 | will be called g762. | ||
473 | |||
474 | config SENSORS_GL518SM | 469 | config SENSORS_GL518SM |
475 | tristate "Genesys Logic GL518SM" | 470 | tristate "Genesys Logic GL518SM" |
476 | depends on I2C | 471 | depends on I2C |
@@ -492,6 +487,26 @@ config SENSORS_GL520SM | |||
492 | This driver can also be built as a module. If so, the module | 487 | This driver can also be built as a module. If so, the module |
493 | will be called gl520sm. | 488 | will be called gl520sm. |
494 | 489 | ||
490 | config SENSORS_G760A | ||
491 | tristate "GMT G760A" | ||
492 | depends on I2C | ||
493 | help | ||
494 | If you say yes here you get support for Global Mixed-mode | ||
495 | Technology Inc G760A fan speed PWM controller chips. | ||
496 | |||
497 | This driver can also be built as a module. If so, the module | ||
498 | will be called g760a. | ||
499 | |||
500 | config SENSORS_G762 | ||
501 | tristate "GMT G762 and G763" | ||
502 | depends on I2C | ||
503 | help | ||
504 | If you say yes here you get support for Global Mixed-mode | ||
505 | Technology Inc G762 and G763 fan speed PWM controller chips. | ||
506 | |||
507 | This driver can also be built as a module. If so, the module | ||
508 | will be called g762. | ||
509 | |||
495 | config SENSORS_GPIO_FAN | 510 | config SENSORS_GPIO_FAN |
496 | tristate "GPIO fan" | 511 | tristate "GPIO fan" |
497 | depends on GPIOLIB | 512 | depends on GPIOLIB |
@@ -511,24 +526,6 @@ config SENSORS_HIH6130 | |||
511 | This driver can also be built as a module. If so, the module | 526 | This driver can also be built as a module. If so, the module |
512 | will be called hih6130. | 527 | will be called hih6130. |
513 | 528 | ||
514 | config SENSORS_HTU21 | ||
515 | tristate "Measurement Specialties HTU21D humidity/temperature sensors" | ||
516 | depends on I2C | ||
517 | help | ||
518 | If you say yes here you get support for the Measurement Specialties | ||
519 | HTU21D humidity and temperature sensors. | ||
520 | |||
521 | This driver can also be built as a module. If so, the module | ||
522 | will be called htu21. | ||
523 | |||
524 | config SENSORS_CORETEMP | ||
525 | tristate "Intel Core/Core2/Atom temperature sensor" | ||
526 | depends on X86 | ||
527 | help | ||
528 | If you say yes here you get support for the temperature | ||
529 | sensor inside your CPU. Most of the family 6 CPUs | ||
530 | are supported. Check Documentation/hwmon/coretemp for details. | ||
531 | |||
532 | config SENSORS_IBMAEM | 529 | config SENSORS_IBMAEM |
533 | tristate "IBM Active Energy Manager temperature/power sensors and control" | 530 | tristate "IBM Active Energy Manager temperature/power sensors and control" |
534 | select IPMI_SI | 531 | select IPMI_SI |
@@ -566,6 +563,14 @@ config SENSORS_IIO_HWMON | |||
566 | for those channels specified in the map. This map can be provided | 563 | for those channels specified in the map. This map can be provided |
567 | either via platform data or the device tree bindings. | 564 | either via platform data or the device tree bindings. |
568 | 565 | ||
566 | config SENSORS_CORETEMP | ||
567 | tristate "Intel Core/Core2/Atom temperature sensor" | ||
568 | depends on X86 | ||
569 | help | ||
570 | If you say yes here you get support for the temperature | ||
571 | sensor inside your CPU. Most of the family 6 CPUs | ||
572 | are supported. Check Documentation/hwmon/coretemp for details. | ||
573 | |||
569 | config SENSORS_IT87 | 574 | config SENSORS_IT87 |
570 | tristate "ITE IT87xx and compatibles" | 575 | tristate "ITE IT87xx and compatibles" |
571 | depends on !PPC | 576 | depends on !PPC |
@@ -614,6 +619,219 @@ config SENSORS_LINEAGE | |||
614 | This driver can also be built as a module. If so, the module | 619 | This driver can also be built as a module. If so, the module |
615 | will be called lineage-pem. | 620 | will be called lineage-pem. |
616 | 621 | ||
622 | config SENSORS_LTC2945 | ||
623 | tristate "Linear Technology LTC2945" | ||
624 | depends on I2C | ||
625 | select REGMAP_I2C | ||
626 | default n | ||
627 | help | ||
628 | If you say yes here you get support for Linear Technology LTC2945 | ||
629 | I2C System Monitor. | ||
630 | |||
631 | This driver can also be built as a module. If so, the module will | ||
632 | be called ltc2945. | ||
633 | |||
634 | config SENSORS_LTC4151 | ||
635 | tristate "Linear Technology LTC4151" | ||
636 | depends on I2C | ||
637 | default n | ||
638 | help | ||
639 | If you say yes here you get support for Linear Technology LTC4151 | ||
640 | High Voltage I2C Current and Voltage Monitor interface. | ||
641 | |||
642 | This driver can also be built as a module. If so, the module will | ||
643 | be called ltc4151. | ||
644 | |||
645 | config SENSORS_LTC4215 | ||
646 | tristate "Linear Technology LTC4215" | ||
647 | depends on I2C | ||
648 | default n | ||
649 | help | ||
650 | If you say yes here you get support for Linear Technology LTC4215 | ||
651 | Hot Swap Controller I2C interface. | ||
652 | |||
653 | This driver can also be built as a module. If so, the module will | ||
654 | be called ltc4215. | ||
655 | |||
656 | config SENSORS_LTC4222 | ||
657 | tristate "Linear Technology LTC4222" | ||
658 | depends on I2C | ||
659 | select REGMAP_I2C | ||
660 | default n | ||
661 | help | ||
662 | If you say yes here you get support for Linear Technology LTC4222 | ||
663 | Dual Hot Swap Controller I2C interface. | ||
664 | |||
665 | This driver can also be built as a module. If so, the module will | ||
666 | be called ltc4222. | ||
667 | |||
668 | config SENSORS_LTC4245 | ||
669 | tristate "Linear Technology LTC4245" | ||
670 | depends on I2C | ||
671 | default n | ||
672 | help | ||
673 | If you say yes here you get support for Linear Technology LTC4245 | ||
674 | Multiple Supply Hot Swap Controller I2C interface. | ||
675 | |||
676 | This driver can also be built as a module. If so, the module will | ||
677 | be called ltc4245. | ||
678 | |||
679 | config SENSORS_LTC4260 | ||
680 | tristate "Linear Technology LTC4260" | ||
681 | depends on I2C | ||
682 | select REGMAP_I2C | ||
683 | default n | ||
684 | help | ||
685 | If you say yes here you get support for Linear Technology LTC4260 | ||
686 | Positive Voltage Hot Swap Controller I2C interface. | ||
687 | |||
688 | This driver can also be built as a module. If so, the module will | ||
689 | be called ltc4260. | ||
690 | |||
691 | config SENSORS_LTC4261 | ||
692 | tristate "Linear Technology LTC4261" | ||
693 | depends on I2C | ||
694 | default n | ||
695 | help | ||
696 | If you say yes here you get support for Linear Technology LTC4261 | ||
697 | Negative Voltage Hot Swap Controller I2C interface. | ||
698 | |||
699 | This driver can also be built as a module. If so, the module will | ||
700 | be called ltc4261. | ||
701 | |||
702 | config SENSORS_MAX1111 | ||
703 | tristate "Maxim MAX1111 Serial 8-bit ADC chip and compatibles" | ||
704 | depends on SPI_MASTER | ||
705 | help | ||
706 | Say y here to support Maxim's MAX1110, MAX1111, MAX1112, and MAX1113 | ||
707 | ADC chips. | ||
708 | |||
709 | This driver can also be built as a module. If so, the module | ||
710 | will be called max1111. | ||
711 | |||
712 | config SENSORS_MAX16065 | ||
713 | tristate "Maxim MAX16065 System Manager and compatibles" | ||
714 | depends on I2C | ||
715 | help | ||
716 | If you say yes here you get support for hardware monitoring | ||
717 | capabilities of the following Maxim System Manager chips. | ||
718 | MAX16065 | ||
719 | MAX16066 | ||
720 | MAX16067 | ||
721 | MAX16068 | ||
722 | MAX16070 | ||
723 | MAX16071 | ||
724 | |||
725 | This driver can also be built as a module. If so, the module | ||
726 | will be called max16065. | ||
727 | |||
728 | config SENSORS_MAX1619 | ||
729 | tristate "Maxim MAX1619 sensor chip" | ||
730 | depends on I2C | ||
731 | help | ||
732 | If you say yes here you get support for MAX1619 sensor chip. | ||
733 | |||
734 | This driver can also be built as a module. If so, the module | ||
735 | will be called max1619. | ||
736 | |||
737 | config SENSORS_MAX1668 | ||
738 | tristate "Maxim MAX1668 and compatibles" | ||
739 | depends on I2C | ||
740 | help | ||
741 | If you say yes here you get support for MAX1668, MAX1989 and | ||
742 | MAX1805 chips. | ||
743 | |||
744 | This driver can also be built as a module. If so, the module | ||
745 | will be called max1668. | ||
746 | |||
747 | config SENSORS_MAX197 | ||
748 | tristate "Maxim MAX197 and compatibles" | ||
749 | help | ||
750 | Support for the Maxim MAX197 A/D converter. | ||
751 | Support will include, but not be limited to, MAX197, and MAX199. | ||
752 | |||
753 | This driver can also be built as a module. If so, the module | ||
754 | will be called max197. | ||
755 | |||
756 | config SENSORS_MAX6639 | ||
757 | tristate "Maxim MAX6639 sensor chip" | ||
758 | depends on I2C | ||
759 | help | ||
760 | If you say yes here you get support for the MAX6639 | ||
761 | sensor chips. | ||
762 | |||
763 | This driver can also be built as a module. If so, the module | ||
764 | will be called max6639. | ||
765 | |||
766 | config SENSORS_MAX6642 | ||
767 | tristate "Maxim MAX6642 sensor chip" | ||
768 | depends on I2C | ||
769 | help | ||
770 | If you say yes here you get support for MAX6642 sensor chip. | ||
771 | MAX6642 is a SMBus-Compatible Remote/Local Temperature Sensor | ||
772 | with Overtemperature Alarm from Maxim. | ||
773 | |||
774 | This driver can also be built as a module. If so, the module | ||
775 | will be called max6642. | ||
776 | |||
777 | config SENSORS_MAX6650 | ||
778 | tristate "Maxim MAX6650 sensor chip" | ||
779 | depends on I2C | ||
780 | help | ||
781 | If you say yes here you get support for the MAX6650 / MAX6651 | ||
782 | sensor chips. | ||
783 | |||
784 | This driver can also be built as a module. If so, the module | ||
785 | will be called max6650. | ||
786 | |||
787 | config SENSORS_MAX6697 | ||
788 | tristate "Maxim MAX6697 and compatibles" | ||
789 | depends on I2C | ||
790 | help | ||
791 | If you say yes here you get support for MAX6581, MAX6602, MAX6622, | ||
792 | MAX6636, MAX6689, MAX6693, MAX6694, MAX6697, MAX6698, and MAX6699 | ||
793 | temperature sensor chips. | ||
794 | |||
795 | This driver can also be built as a module. If so, the module | ||
796 | will be called max6697. | ||
797 | |||
798 | config SENSORS_HTU21 | ||
799 | tristate "Measurement Specialties HTU21D humidity/temperature sensors" | ||
800 | depends on I2C | ||
801 | help | ||
802 | If you say yes here you get support for the Measurement Specialties | ||
803 | HTU21D humidity and temperature sensors. | ||
804 | |||
805 | This driver can also be built as a module. If so, the module | ||
806 | will be called htu21. | ||
807 | |||
808 | config SENSORS_MCP3021 | ||
809 | tristate "Microchip MCP3021 and compatibles" | ||
810 | depends on I2C | ||
811 | help | ||
812 | If you say yes here you get support for MCP3021 and MCP3221. | ||
813 | The MCP3021 is a A/D converter (ADC) with 10-bit and the MCP3221 | ||
814 | with 12-bit resolution. | ||
815 | |||
816 | This driver can also be built as a module. If so, the module | ||
817 | will be called mcp3021. | ||
818 | |||
819 | config SENSORS_ADCXX | ||
820 | tristate "National Semiconductor ADCxxxSxxx" | ||
821 | depends on SPI_MASTER | ||
822 | help | ||
823 | If you say yes here you get support for the National Semiconductor | ||
824 | ADC<bb><c>S<sss> chip family, where | ||
825 | * bb is the resolution in number of bits (8, 10, 12) | ||
826 | * c is the number of channels (1, 2, 4, 8) | ||
827 | * sss is the maximum conversion speed (021 for 200 kSPS, 051 for 500 | ||
828 | kSPS and 101 for 1 MSPS) | ||
829 | |||
830 | Examples : ADC081S101, ADC124S501, ... | ||
831 | |||
832 | This driver can also be built as a module. If so, the module | ||
833 | will be called adcxx. | ||
834 | |||
617 | config SENSORS_LM63 | 835 | config SENSORS_LM63 |
618 | tristate "National Semiconductor LM63 and compatibles" | 836 | tristate "National Semiconductor LM63 and compatibles" |
619 | depends on I2C | 837 | depends on I2C |
@@ -776,50 +994,6 @@ config SENSORS_LM93 | |||
776 | This driver can also be built as a module. If so, the module | 994 | This driver can also be built as a module. If so, the module |
777 | will be called lm93. | 995 | will be called lm93. |
778 | 996 | ||
779 | config SENSORS_LTC4151 | ||
780 | tristate "Linear Technology LTC4151" | ||
781 | depends on I2C | ||
782 | default n | ||
783 | help | ||
784 | If you say yes here you get support for Linear Technology LTC4151 | ||
785 | High Voltage I2C Current and Voltage Monitor interface. | ||
786 | |||
787 | This driver can also be built as a module. If so, the module will | ||
788 | be called ltc4151. | ||
789 | |||
790 | config SENSORS_LTC4215 | ||
791 | tristate "Linear Technology LTC4215" | ||
792 | depends on I2C | ||
793 | default n | ||
794 | help | ||
795 | If you say yes here you get support for Linear Technology LTC4215 | ||
796 | Hot Swap Controller I2C interface. | ||
797 | |||
798 | This driver can also be built as a module. If so, the module will | ||
799 | be called ltc4215. | ||
800 | |||
801 | config SENSORS_LTC4245 | ||
802 | tristate "Linear Technology LTC4245" | ||
803 | depends on I2C | ||
804 | default n | ||
805 | help | ||
806 | If you say yes here you get support for Linear Technology LTC4245 | ||
807 | Multiple Supply Hot Swap Controller I2C interface. | ||
808 | |||
809 | This driver can also be built as a module. If so, the module will | ||
810 | be called ltc4245. | ||
811 | |||
812 | config SENSORS_LTC4261 | ||
813 | tristate "Linear Technology LTC4261" | ||
814 | depends on I2C | ||
815 | default n | ||
816 | help | ||
817 | If you say yes here you get support for Linear Technology LTC4261 | ||
818 | Negative Voltage Hot Swap Controller I2C interface. | ||
819 | |||
820 | This driver can also be built as a module. If so, the module will | ||
821 | be called ltc4261. | ||
822 | |||
823 | config SENSORS_LM95234 | 997 | config SENSORS_LM95234 |
824 | tristate "National Semiconductor LM95234" | 998 | tristate "National Semiconductor LM95234" |
825 | depends on I2C | 999 | depends on I2C |
@@ -849,125 +1023,33 @@ config SENSORS_LM95245 | |||
849 | This driver can also be built as a module. If so, the module | 1023 | This driver can also be built as a module. If so, the module |
850 | will be called lm95245. | 1024 | will be called lm95245. |
851 | 1025 | ||
852 | config SENSORS_MAX1111 | 1026 | config SENSORS_PC87360 |
853 | tristate "Maxim MAX1111 Serial 8-bit ADC chip and compatibles" | 1027 | tristate "National Semiconductor PC87360 family" |
854 | depends on SPI_MASTER | 1028 | depends on !PPC |
855 | help | 1029 | select HWMON_VID |
856 | Say y here to support Maxim's MAX1110, MAX1111, MAX1112, and MAX1113 | ||
857 | ADC chips. | ||
858 | |||
859 | This driver can also be built as a module. If so, the module | ||
860 | will be called max1111. | ||
861 | |||
862 | config SENSORS_MAX16065 | ||
863 | tristate "Maxim MAX16065 System Manager and compatibles" | ||
864 | depends on I2C | ||
865 | help | ||
866 | If you say yes here you get support for hardware monitoring | ||
867 | capabilities of the following Maxim System Manager chips. | ||
868 | MAX16065 | ||
869 | MAX16066 | ||
870 | MAX16067 | ||
871 | MAX16068 | ||
872 | MAX16070 | ||
873 | MAX16071 | ||
874 | |||
875 | This driver can also be built as a module. If so, the module | ||
876 | will be called max16065. | ||
877 | |||
878 | config SENSORS_MAX1619 | ||
879 | tristate "Maxim MAX1619 sensor chip" | ||
880 | depends on I2C | ||
881 | help | ||
882 | If you say yes here you get support for MAX1619 sensor chip. | ||
883 | |||
884 | This driver can also be built as a module. If so, the module | ||
885 | will be called max1619. | ||
886 | |||
887 | config SENSORS_MAX1668 | ||
888 | tristate "Maxim MAX1668 and compatibles" | ||
889 | depends on I2C | ||
890 | help | ||
891 | If you say yes here you get support for MAX1668, MAX1989 and | ||
892 | MAX1805 chips. | ||
893 | |||
894 | This driver can also be built as a module. If so, the module | ||
895 | will be called max1668. | ||
896 | |||
897 | config SENSORS_MAX197 | ||
898 | tristate "Maxim MAX197 and compatibles" | ||
899 | help | ||
900 | Support for the Maxim MAX197 A/D converter. | ||
901 | Support will include, but not be limited to, MAX197, and MAX199. | ||
902 | |||
903 | This driver can also be built as a module. If so, the module | ||
904 | will be called max197. | ||
905 | |||
906 | config SENSORS_MAX6639 | ||
907 | tristate "Maxim MAX6639 sensor chip" | ||
908 | depends on I2C | ||
909 | help | ||
910 | If you say yes here you get support for the MAX6639 | ||
911 | sensor chips. | ||
912 | |||
913 | This driver can also be built as a module. If so, the module | ||
914 | will be called max6639. | ||
915 | |||
916 | config SENSORS_MAX6642 | ||
917 | tristate "Maxim MAX6642 sensor chip" | ||
918 | depends on I2C | ||
919 | help | ||
920 | If you say yes here you get support for MAX6642 sensor chip. | ||
921 | MAX6642 is a SMBus-Compatible Remote/Local Temperature Sensor | ||
922 | with Overtemperature Alarm from Maxim. | ||
923 | |||
924 | This driver can also be built as a module. If so, the module | ||
925 | will be called max6642. | ||
926 | |||
927 | config SENSORS_MAX6650 | ||
928 | tristate "Maxim MAX6650 sensor chip" | ||
929 | depends on I2C | ||
930 | help | ||
931 | If you say yes here you get support for the MAX6650 / MAX6651 | ||
932 | sensor chips. | ||
933 | |||
934 | This driver can also be built as a module. If so, the module | ||
935 | will be called max6650. | ||
936 | |||
937 | config SENSORS_MAX6697 | ||
938 | tristate "Maxim MAX6697 and compatibles" | ||
939 | depends on I2C | ||
940 | help | ||
941 | If you say yes here you get support for MAX6581, MAX6602, MAX6622, | ||
942 | MAX6636, MAX6689, MAX6693, MAX6694, MAX6697, MAX6698, and MAX6699 | ||
943 | temperature sensor chips. | ||
944 | |||
945 | This driver can also be built as a module. If so, the module | ||
946 | will be called max6697. | ||
947 | |||
948 | config SENSORS_MCP3021 | ||
949 | tristate "Microchip MCP3021 and compatibles" | ||
950 | depends on I2C | ||
951 | help | 1030 | help |
952 | If you say yes here you get support for MCP3021 and MCP3221. | 1031 | If you say yes here you get access to the hardware monitoring |
953 | The MCP3021 is a A/D converter (ADC) with 10-bit and the MCP3221 | 1032 | functions of the National Semiconductor PC8736x Super-I/O chips. |
954 | with 12-bit resolution. | 1033 | The PC87360, PC87363 and PC87364 only have fan monitoring and |
1034 | control. The PC87365 and PC87366 additionally have voltage and | ||
1035 | temperature monitoring. | ||
955 | 1036 | ||
956 | This driver can also be built as a module. If so, the module | 1037 | This driver can also be built as a module. If so, the module |
957 | will be called mcp3021. | 1038 | will be called pc87360. |
958 | 1039 | ||
959 | config SENSORS_NCT6775 | 1040 | config SENSORS_PC87427 |
960 | tristate "Nuvoton NCT6775F and compatibles" | 1041 | tristate "National Semiconductor PC87427" |
961 | depends on !PPC | 1042 | depends on !PPC |
962 | select HWMON_VID | ||
963 | help | 1043 | help |
964 | If you say yes here you get support for the hardware monitoring | 1044 | If you say yes here you get access to the hardware monitoring |
965 | functionality of the Nuvoton NCT6775F, NCT6776F, NCT6779D | 1045 | functions of the National Semiconductor PC87427 Super-I/O chip. |
966 | and compatible Super-I/O chips. This driver replaces the | 1046 | The chip has two distinct logical devices, one for fan speed |
967 | w83627ehf driver for NCT6775F and NCT6776F. | 1047 | monitoring and control, and one for voltage and temperature |
1048 | monitoring. Fan speed monitoring and control are supported, as | ||
1049 | well as temperature monitoring. Voltages aren't supported yet. | ||
968 | 1050 | ||
969 | This driver can also be built as a module. If so, the module | 1051 | This driver can also be built as a module. If so, the module |
970 | will be called nct6775. | 1052 | will be called pc87427. |
971 | 1053 | ||
972 | config SENSORS_NTC_THERMISTOR | 1054 | config SENSORS_NTC_THERMISTOR |
973 | tristate "NTC thermistor support" | 1055 | tristate "NTC thermistor support" |
@@ -983,33 +1065,18 @@ config SENSORS_NTC_THERMISTOR | |||
983 | This driver can also be built as a module. If so, the module | 1065 | This driver can also be built as a module. If so, the module |
984 | will be called ntc-thermistor. | 1066 | will be called ntc-thermistor. |
985 | 1067 | ||
986 | config SENSORS_PC87360 | 1068 | config SENSORS_NCT6775 |
987 | tristate "National Semiconductor PC87360 family" | 1069 | tristate "Nuvoton NCT6775F and compatibles" |
988 | depends on !PPC | 1070 | depends on !PPC |
989 | select HWMON_VID | 1071 | select HWMON_VID |
990 | help | 1072 | help |
991 | If you say yes here you get access to the hardware monitoring | 1073 | If you say yes here you get support for the hardware monitoring |
992 | functions of the National Semiconductor PC8736x Super-I/O chips. | 1074 | functionality of the Nuvoton NCT6775F, NCT6776F, NCT6779D |
993 | The PC87360, PC87363 and PC87364 only have fan monitoring and | 1075 | and compatible Super-I/O chips. This driver replaces the |
994 | control. The PC87365 and PC87366 additionally have voltage and | 1076 | w83627ehf driver for NCT6775F and NCT6776F. |
995 | temperature monitoring. | ||
996 | |||
997 | This driver can also be built as a module. If so, the module | ||
998 | will be called pc87360. | ||
999 | |||
1000 | config SENSORS_PC87427 | ||
1001 | tristate "National Semiconductor PC87427" | ||
1002 | depends on !PPC | ||
1003 | help | ||
1004 | If you say yes here you get access to the hardware monitoring | ||
1005 | functions of the National Semiconductor PC87427 Super-I/O chip. | ||
1006 | The chip has two distinct logical devices, one for fan speed | ||
1007 | monitoring and control, and one for voltage and temperature | ||
1008 | monitoring. Fan speed monitoring and control are supported, as | ||
1009 | well as temperature monitoring. Voltages aren't supported yet. | ||
1010 | 1077 | ||
1011 | This driver can also be built as a module. If so, the module | 1078 | This driver can also be built as a module. If so, the module |
1012 | will be called pc87427. | 1079 | will be called nct6775. |
1013 | 1080 | ||
1014 | config SENSORS_PCF8591 | 1081 | config SENSORS_PCF8591 |
1015 | tristate "Philips PCF8591 ADC/DAC" | 1082 | tristate "Philips PCF8591 ADC/DAC" |
@@ -1074,21 +1141,6 @@ config SENSORS_SIS5595 | |||
1074 | This driver can also be built as a module. If so, the module | 1141 | This driver can also be built as a module. If so, the module |
1075 | will be called sis5595. | 1142 | will be called sis5595. |
1076 | 1143 | ||
1077 | config SENSORS_SMM665 | ||
1078 | tristate "Summit Microelectronics SMM665" | ||
1079 | depends on I2C | ||
1080 | default n | ||
1081 | help | ||
1082 | If you say yes here you get support for the hardware monitoring | ||
1083 | features of the Summit Microelectronics SMM665/SMM665B Six-Channel | ||
1084 | Active DC Output Controller / Monitor. | ||
1085 | |||
1086 | Other supported chips are SMM465, SMM665C, SMM764, and SMM766. | ||
1087 | Support for those chips is untested. | ||
1088 | |||
1089 | This driver can also be built as a module. If so, the module will | ||
1090 | be called smm665. | ||
1091 | |||
1092 | config SENSORS_DME1737 | 1144 | config SENSORS_DME1737 |
1093 | tristate "SMSC DME1737, SCH311x and compatibles" | 1145 | tristate "SMSC DME1737, SCH311x and compatibles" |
1094 | depends on I2C && !PPC | 1146 | depends on I2C && !PPC |
@@ -1210,6 +1262,31 @@ config SENSORS_SCH5636 | |||
1210 | This driver can also be built as a module. If so, the module | 1262 | This driver can also be built as a module. If so, the module |
1211 | will be called sch5636. | 1263 | will be called sch5636. |
1212 | 1264 | ||
1265 | config SENSORS_SMM665 | ||
1266 | tristate "Summit Microelectronics SMM665" | ||
1267 | depends on I2C | ||
1268 | default n | ||
1269 | help | ||
1270 | If you say yes here you get support for the hardware monitoring | ||
1271 | features of the Summit Microelectronics SMM665/SMM665B Six-Channel | ||
1272 | Active DC Output Controller / Monitor. | ||
1273 | |||
1274 | Other supported chips are SMM465, SMM665C, SMM764, and SMM766. | ||
1275 | Support for those chips is untested. | ||
1276 | |||
1277 | This driver can also be built as a module. If so, the module will | ||
1278 | be called smm665. | ||
1279 | |||
1280 | config SENSORS_ADC128D818 | ||
1281 | tristate "Texas Instruments ADC128D818" | ||
1282 | depends on I2C | ||
1283 | help | ||
1284 | If you say yes here you get support for the Texas Instruments | ||
1285 | ADC128D818 System Monitor with Temperature Sensor chip. | ||
1286 | |||
1287 | This driver can also be built as a module. If so, the module | ||
1288 | will be called adc128d818. | ||
1289 | |||
1213 | config SENSORS_ADS1015 | 1290 | config SENSORS_ADS1015 |
1214 | tristate "Texas Instruments ADS1015" | 1291 | tristate "Texas Instruments ADS1015" |
1215 | depends on I2C | 1292 | depends on I2C |
@@ -1525,37 +1602,6 @@ config SENSORS_ULTRA45 | |||
1525 | This driver provides support for the Ultra45 workstation environmental | 1602 | This driver provides support for the Ultra45 workstation environmental |
1526 | sensors. | 1603 | sensors. |
1527 | 1604 | ||
1528 | config SENSORS_APPLESMC | ||
1529 | tristate "Apple SMC (Motion sensor, light sensor, keyboard backlight)" | ||
1530 | depends on INPUT && X86 | ||
1531 | select NEW_LEDS | ||
1532 | select LEDS_CLASS | ||
1533 | select INPUT_POLLDEV | ||
1534 | default n | ||
1535 | help | ||
1536 | This driver provides support for the Apple System Management | ||
1537 | Controller, which provides an accelerometer (Apple Sudden Motion | ||
1538 | Sensor), light sensors, temperature sensors, keyboard backlight | ||
1539 | control and fan control. | ||
1540 | |||
1541 | Only Intel-based Apple's computers are supported (MacBook Pro, | ||
1542 | MacBook, MacMini). | ||
1543 | |||
1544 | Data from the different sensors, keyboard backlight control and fan | ||
1545 | control are accessible via sysfs. | ||
1546 | |||
1547 | This driver also provides an absolute input class device, allowing | ||
1548 | the laptop to act as a pinball machine-esque joystick. | ||
1549 | |||
1550 | Say Y here if you have an applicable laptop and want to experience | ||
1551 | the awesome power of applesmc. | ||
1552 | |||
1553 | config SENSORS_MC13783_ADC | ||
1554 | tristate "Freescale MC13783/MC13892 ADC" | ||
1555 | depends on MFD_MC13XXX | ||
1556 | help | ||
1557 | Support for the A/D converter on MC13783 and MC13892 PMIC. | ||
1558 | |||
1559 | if ACPI | 1605 | if ACPI |
1560 | 1606 | ||
1561 | comment "ACPI drivers" | 1607 | comment "ACPI drivers" |
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index ec7cde06eb52..c48f9873ac73 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile | |||
@@ -25,6 +25,7 @@ obj-$(CONFIG_SENSORS_ABITUGURU3)+= abituguru3.o | |||
25 | obj-$(CONFIG_SENSORS_AD7314) += ad7314.o | 25 | obj-$(CONFIG_SENSORS_AD7314) += ad7314.o |
26 | obj-$(CONFIG_SENSORS_AD7414) += ad7414.o | 26 | obj-$(CONFIG_SENSORS_AD7414) += ad7414.o |
27 | obj-$(CONFIG_SENSORS_AD7418) += ad7418.o | 27 | obj-$(CONFIG_SENSORS_AD7418) += ad7418.o |
28 | obj-$(CONFIG_SENSORS_ADC128D818) += adc128d818.o | ||
28 | obj-$(CONFIG_SENSORS_ADCXX) += adcxx.o | 29 | obj-$(CONFIG_SENSORS_ADCXX) += adcxx.o |
29 | obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o | 30 | obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o |
30 | obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o | 31 | obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o |
@@ -95,9 +96,12 @@ obj-$(CONFIG_SENSORS_LM93) += lm93.o | |||
95 | obj-$(CONFIG_SENSORS_LM95234) += lm95234.o | 96 | obj-$(CONFIG_SENSORS_LM95234) += lm95234.o |
96 | obj-$(CONFIG_SENSORS_LM95241) += lm95241.o | 97 | obj-$(CONFIG_SENSORS_LM95241) += lm95241.o |
97 | obj-$(CONFIG_SENSORS_LM95245) += lm95245.o | 98 | obj-$(CONFIG_SENSORS_LM95245) += lm95245.o |
99 | obj-$(CONFIG_SENSORS_LTC2945) += ltc2945.o | ||
98 | obj-$(CONFIG_SENSORS_LTC4151) += ltc4151.o | 100 | obj-$(CONFIG_SENSORS_LTC4151) += ltc4151.o |
99 | obj-$(CONFIG_SENSORS_LTC4215) += ltc4215.o | 101 | obj-$(CONFIG_SENSORS_LTC4215) += ltc4215.o |
102 | obj-$(CONFIG_SENSORS_LTC4222) += ltc4222.o | ||
100 | obj-$(CONFIG_SENSORS_LTC4245) += ltc4245.o | 103 | obj-$(CONFIG_SENSORS_LTC4245) += ltc4245.o |
104 | obj-$(CONFIG_SENSORS_LTC4260) += ltc4260.o | ||
101 | obj-$(CONFIG_SENSORS_LTC4261) += ltc4261.o | 105 | obj-$(CONFIG_SENSORS_LTC4261) += ltc4261.o |
102 | obj-$(CONFIG_SENSORS_MAX1111) += max1111.o | 106 | obj-$(CONFIG_SENSORS_MAX1111) += max1111.o |
103 | obj-$(CONFIG_SENSORS_MAX16065) += max16065.o | 107 | obj-$(CONFIG_SENSORS_MAX16065) += max16065.o |
diff --git a/drivers/hwmon/adc128d818.c b/drivers/hwmon/adc128d818.c new file mode 100644 index 000000000000..5ffd81f19d01 --- /dev/null +++ b/drivers/hwmon/adc128d818.c | |||
@@ -0,0 +1,491 @@ | |||
1 | /* | ||
2 | * Driver for TI ADC128D818 System Monitor with Temperature Sensor | ||
3 | * | ||
4 | * Copyright (c) 2014 Guenter Roeck | ||
5 | * | ||
6 | * Derived from lm80.c | ||
7 | * Copyright (C) 1998, 1999 Frodo Looijaard <frodol@dds.nl> | ||
8 | * and Philip Edelbrock <phil@netroedge.com> | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License as published by | ||
12 | * the Free Software Foundation; either version 2 of the License, or | ||
13 | * (at your option) any later version. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | */ | ||
20 | |||
21 | #include <linux/module.h> | ||
22 | #include <linux/slab.h> | ||
23 | #include <linux/jiffies.h> | ||
24 | #include <linux/i2c.h> | ||
25 | #include <linux/hwmon.h> | ||
26 | #include <linux/hwmon-sysfs.h> | ||
27 | #include <linux/err.h> | ||
28 | #include <linux/regulator/consumer.h> | ||
29 | #include <linux/mutex.h> | ||
30 | |||
31 | /* Addresses to scan | ||
32 | * The chip also supports addresses 0x35..0x37. Don't scan those addresses | ||
33 | * since they are also used by some EEPROMs, which may result in false | ||
34 | * positives. | ||
35 | */ | ||
36 | static const unsigned short normal_i2c[] = { | ||
37 | 0x1d, 0x1e, 0x1f, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END }; | ||
38 | |||
39 | /* registers */ | ||
40 | #define ADC128_REG_IN_MAX(nr) (0x2a + (nr) * 2) | ||
41 | #define ADC128_REG_IN_MIN(nr) (0x2b + (nr) * 2) | ||
42 | #define ADC128_REG_IN(nr) (0x20 + (nr)) | ||
43 | |||
44 | #define ADC128_REG_TEMP 0x27 | ||
45 | #define ADC128_REG_TEMP_MAX 0x38 | ||
46 | #define ADC128_REG_TEMP_HYST 0x39 | ||
47 | |||
48 | #define ADC128_REG_CONFIG 0x00 | ||
49 | #define ADC128_REG_ALARM 0x01 | ||
50 | #define ADC128_REG_MASK 0x03 | ||
51 | #define ADC128_REG_CONV_RATE 0x07 | ||
52 | #define ADC128_REG_ONESHOT 0x09 | ||
53 | #define ADC128_REG_SHUTDOWN 0x0a | ||
54 | #define ADC128_REG_CONFIG_ADV 0x0b | ||
55 | #define ADC128_REG_BUSY_STATUS 0x0c | ||
56 | |||
57 | #define ADC128_REG_MAN_ID 0x3e | ||
58 | #define ADC128_REG_DEV_ID 0x3f | ||
59 | |||
60 | struct adc128_data { | ||
61 | struct i2c_client *client; | ||
62 | struct regulator *regulator; | ||
63 | int vref; /* Reference voltage in mV */ | ||
64 | struct mutex update_lock; | ||
65 | bool valid; /* true if following fields are valid */ | ||
66 | unsigned long last_updated; /* In jiffies */ | ||
67 | |||
68 | u16 in[3][7]; /* Register value, normalized to 12 bit | ||
69 | * 0: input voltage | ||
70 | * 1: min limit | ||
71 | * 2: max limit | ||
72 | */ | ||
73 | s16 temp[3]; /* Register value, normalized to 9 bit | ||
74 | * 0: sensor 1: limit 2: hyst | ||
75 | */ | ||
76 | u8 alarms; /* alarm register value */ | ||
77 | }; | ||
78 | |||
79 | static struct adc128_data *adc128_update_device(struct device *dev) | ||
80 | { | ||
81 | struct adc128_data *data = dev_get_drvdata(dev); | ||
82 | struct i2c_client *client = data->client; | ||
83 | struct adc128_data *ret = data; | ||
84 | int i, rv; | ||
85 | |||
86 | mutex_lock(&data->update_lock); | ||
87 | |||
88 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { | ||
89 | for (i = 0; i < 7; i++) { | ||
90 | rv = i2c_smbus_read_word_swapped(client, | ||
91 | ADC128_REG_IN(i)); | ||
92 | if (rv < 0) | ||
93 | goto abort; | ||
94 | data->in[0][i] = rv >> 4; | ||
95 | |||
96 | rv = i2c_smbus_read_byte_data(client, | ||
97 | ADC128_REG_IN_MIN(i)); | ||
98 | if (rv < 0) | ||
99 | goto abort; | ||
100 | data->in[1][i] = rv << 4; | ||
101 | |||
102 | rv = i2c_smbus_read_byte_data(client, | ||
103 | ADC128_REG_IN_MAX(i)); | ||
104 | if (rv < 0) | ||
105 | goto abort; | ||
106 | data->in[2][i] = rv << 4; | ||
107 | } | ||
108 | |||
109 | rv = i2c_smbus_read_word_swapped(client, ADC128_REG_TEMP); | ||
110 | if (rv < 0) | ||
111 | goto abort; | ||
112 | data->temp[0] = rv >> 7; | ||
113 | |||
114 | rv = i2c_smbus_read_byte_data(client, ADC128_REG_TEMP_MAX); | ||
115 | if (rv < 0) | ||
116 | goto abort; | ||
117 | data->temp[1] = rv << 1; | ||
118 | |||
119 | rv = i2c_smbus_read_byte_data(client, ADC128_REG_TEMP_HYST); | ||
120 | if (rv < 0) | ||
121 | goto abort; | ||
122 | data->temp[2] = rv << 1; | ||
123 | |||
124 | rv = i2c_smbus_read_byte_data(client, ADC128_REG_ALARM); | ||
125 | if (rv < 0) | ||
126 | goto abort; | ||
127 | data->alarms |= rv; | ||
128 | |||
129 | data->last_updated = jiffies; | ||
130 | data->valid = true; | ||
131 | } | ||
132 | goto done; | ||
133 | |||
134 | abort: | ||
135 | ret = ERR_PTR(rv); | ||
136 | data->valid = false; | ||
137 | done: | ||
138 | mutex_unlock(&data->update_lock); | ||
139 | return ret; | ||
140 | } | ||
141 | |||
142 | static ssize_t adc128_show_in(struct device *dev, struct device_attribute *attr, | ||
143 | char *buf) | ||
144 | { | ||
145 | struct adc128_data *data = adc128_update_device(dev); | ||
146 | int index = to_sensor_dev_attr_2(attr)->index; | ||
147 | int nr = to_sensor_dev_attr_2(attr)->nr; | ||
148 | int val; | ||
149 | |||
150 | if (IS_ERR(data)) | ||
151 | return PTR_ERR(data); | ||
152 | |||
153 | val = DIV_ROUND_CLOSEST(data->in[index][nr] * data->vref, 4095); | ||
154 | return sprintf(buf, "%d\n", val); | ||
155 | } | ||
156 | |||
157 | static ssize_t adc128_set_in(struct device *dev, struct device_attribute *attr, | ||
158 | const char *buf, size_t count) | ||
159 | { | ||
160 | struct adc128_data *data = dev_get_drvdata(dev); | ||
161 | int index = to_sensor_dev_attr_2(attr)->index; | ||
162 | int nr = to_sensor_dev_attr_2(attr)->nr; | ||
163 | u8 reg, regval; | ||
164 | long val; | ||
165 | int err; | ||
166 | |||
167 | err = kstrtol(buf, 10, &val); | ||
168 | if (err < 0) | ||
169 | return err; | ||
170 | |||
171 | mutex_lock(&data->update_lock); | ||
172 | /* 10 mV LSB on limit registers */ | ||
173 | regval = clamp_val(DIV_ROUND_CLOSEST(val, 10), 0, 255); | ||
174 | data->in[index][nr] = regval << 4; | ||
175 | reg = index == 1 ? ADC128_REG_IN_MIN(nr) : ADC128_REG_IN_MAX(nr); | ||
176 | i2c_smbus_write_byte_data(data->client, reg, regval); | ||
177 | mutex_unlock(&data->update_lock); | ||
178 | |||
179 | return count; | ||
180 | } | ||
181 | |||
182 | static ssize_t adc128_show_temp(struct device *dev, | ||
183 | struct device_attribute *attr, char *buf) | ||
184 | { | ||
185 | struct adc128_data *data = adc128_update_device(dev); | ||
186 | int index = to_sensor_dev_attr(attr)->index; | ||
187 | int temp; | ||
188 | |||
189 | if (IS_ERR(data)) | ||
190 | return PTR_ERR(data); | ||
191 | |||
192 | temp = (data->temp[index] << 7) >> 7; /* sign extend */ | ||
193 | return sprintf(buf, "%d\n", temp * 500);/* 0.5 degrees C resolution */ | ||
194 | } | ||
195 | |||
196 | static ssize_t adc128_set_temp(struct device *dev, | ||
197 | struct device_attribute *attr, | ||
198 | const char *buf, size_t count) | ||
199 | { | ||
200 | struct adc128_data *data = dev_get_drvdata(dev); | ||
201 | int index = to_sensor_dev_attr(attr)->index; | ||
202 | long val; | ||
203 | int err; | ||
204 | s8 regval; | ||
205 | |||
206 | err = kstrtol(buf, 10, &val); | ||
207 | if (err < 0) | ||
208 | return err; | ||
209 | |||
210 | mutex_lock(&data->update_lock); | ||
211 | regval = clamp_val(DIV_ROUND_CLOSEST(val, 1000), -128, 127); | ||
212 | data->temp[index] = regval << 1; | ||
213 | i2c_smbus_write_byte_data(data->client, | ||
214 | index == 1 ? ADC128_REG_TEMP_MAX | ||
215 | : ADC128_REG_TEMP_HYST, | ||
216 | regval); | ||
217 | mutex_unlock(&data->update_lock); | ||
218 | |||
219 | return count; | ||
220 | } | ||
221 | |||
222 | static ssize_t adc128_show_alarm(struct device *dev, | ||
223 | struct device_attribute *attr, char *buf) | ||
224 | { | ||
225 | struct adc128_data *data = adc128_update_device(dev); | ||
226 | int mask = 1 << to_sensor_dev_attr(attr)->index; | ||
227 | u8 alarms; | ||
228 | |||
229 | if (IS_ERR(data)) | ||
230 | return PTR_ERR(data); | ||
231 | |||
232 | /* | ||
233 | * Clear an alarm after reporting it to user space. If it is still | ||
234 | * active, the next update sequence will set the alarm bit again. | ||
235 | */ | ||
236 | alarms = data->alarms; | ||
237 | data->alarms &= ~mask; | ||
238 | |||
239 | return sprintf(buf, "%u\n", !!(alarms & mask)); | ||
240 | } | ||
241 | |||
242 | static SENSOR_DEVICE_ATTR_2(in0_input, S_IWUSR | S_IRUGO, | ||
243 | adc128_show_in, adc128_set_in, 0, 0); | ||
244 | static SENSOR_DEVICE_ATTR_2(in0_min, S_IWUSR | S_IRUGO, | ||
245 | adc128_show_in, adc128_set_in, 0, 1); | ||
246 | static SENSOR_DEVICE_ATTR_2(in0_max, S_IWUSR | S_IRUGO, | ||
247 | adc128_show_in, adc128_set_in, 0, 2); | ||
248 | |||
249 | static SENSOR_DEVICE_ATTR_2(in1_input, S_IWUSR | S_IRUGO, | ||
250 | adc128_show_in, adc128_set_in, 1, 0); | ||
251 | static SENSOR_DEVICE_ATTR_2(in1_min, S_IWUSR | S_IRUGO, | ||
252 | adc128_show_in, adc128_set_in, 1, 1); | ||
253 | static SENSOR_DEVICE_ATTR_2(in1_max, S_IWUSR | S_IRUGO, | ||
254 | adc128_show_in, adc128_set_in, 1, 2); | ||
255 | |||
256 | static SENSOR_DEVICE_ATTR_2(in2_input, S_IWUSR | S_IRUGO, | ||
257 | adc128_show_in, adc128_set_in, 2, 0); | ||
258 | static SENSOR_DEVICE_ATTR_2(in2_min, S_IWUSR | S_IRUGO, | ||
259 | adc128_show_in, adc128_set_in, 2, 1); | ||
260 | static SENSOR_DEVICE_ATTR_2(in2_max, S_IWUSR | S_IRUGO, | ||
261 | adc128_show_in, adc128_set_in, 2, 2); | ||
262 | |||
263 | static SENSOR_DEVICE_ATTR_2(in3_input, S_IWUSR | S_IRUGO, | ||
264 | adc128_show_in, adc128_set_in, 3, 0); | ||
265 | static SENSOR_DEVICE_ATTR_2(in3_min, S_IWUSR | S_IRUGO, | ||
266 | adc128_show_in, adc128_set_in, 3, 1); | ||
267 | static SENSOR_DEVICE_ATTR_2(in3_max, S_IWUSR | S_IRUGO, | ||
268 | adc128_show_in, adc128_set_in, 3, 2); | ||
269 | |||
270 | static SENSOR_DEVICE_ATTR_2(in4_input, S_IWUSR | S_IRUGO, | ||
271 | adc128_show_in, adc128_set_in, 4, 0); | ||
272 | static SENSOR_DEVICE_ATTR_2(in4_min, S_IWUSR | S_IRUGO, | ||
273 | adc128_show_in, adc128_set_in, 4, 1); | ||
274 | static SENSOR_DEVICE_ATTR_2(in4_max, S_IWUSR | S_IRUGO, | ||
275 | adc128_show_in, adc128_set_in, 4, 2); | ||
276 | |||
277 | static SENSOR_DEVICE_ATTR_2(in5_input, S_IWUSR | S_IRUGO, | ||
278 | adc128_show_in, adc128_set_in, 5, 0); | ||
279 | static SENSOR_DEVICE_ATTR_2(in5_min, S_IWUSR | S_IRUGO, | ||
280 | adc128_show_in, adc128_set_in, 5, 1); | ||
281 | static SENSOR_DEVICE_ATTR_2(in5_max, S_IWUSR | S_IRUGO, | ||
282 | adc128_show_in, adc128_set_in, 5, 2); | ||
283 | |||
284 | static SENSOR_DEVICE_ATTR_2(in6_input, S_IWUSR | S_IRUGO, | ||
285 | adc128_show_in, adc128_set_in, 6, 0); | ||
286 | static SENSOR_DEVICE_ATTR_2(in6_min, S_IWUSR | S_IRUGO, | ||
287 | adc128_show_in, adc128_set_in, 6, 1); | ||
288 | static SENSOR_DEVICE_ATTR_2(in6_max, S_IWUSR | S_IRUGO, | ||
289 | adc128_show_in, adc128_set_in, 6, 2); | ||
290 | |||
291 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, adc128_show_temp, NULL, 0); | ||
292 | static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, | ||
293 | adc128_show_temp, adc128_set_temp, 1); | ||
294 | static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO, | ||
295 | adc128_show_temp, adc128_set_temp, 2); | ||
296 | |||
297 | static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, adc128_show_alarm, NULL, 0); | ||
298 | static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, adc128_show_alarm, NULL, 1); | ||
299 | static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, adc128_show_alarm, NULL, 2); | ||
300 | static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, adc128_show_alarm, NULL, 3); | ||
301 | static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, adc128_show_alarm, NULL, 4); | ||
302 | static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, adc128_show_alarm, NULL, 5); | ||
303 | static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, adc128_show_alarm, NULL, 6); | ||
304 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, adc128_show_alarm, NULL, 7); | ||
305 | |||
306 | static struct attribute *adc128_attrs[] = { | ||
307 | &sensor_dev_attr_in0_min.dev_attr.attr, | ||
308 | &sensor_dev_attr_in1_min.dev_attr.attr, | ||
309 | &sensor_dev_attr_in2_min.dev_attr.attr, | ||
310 | &sensor_dev_attr_in3_min.dev_attr.attr, | ||
311 | &sensor_dev_attr_in4_min.dev_attr.attr, | ||
312 | &sensor_dev_attr_in5_min.dev_attr.attr, | ||
313 | &sensor_dev_attr_in6_min.dev_attr.attr, | ||
314 | &sensor_dev_attr_in0_max.dev_attr.attr, | ||
315 | &sensor_dev_attr_in1_max.dev_attr.attr, | ||
316 | &sensor_dev_attr_in2_max.dev_attr.attr, | ||
317 | &sensor_dev_attr_in3_max.dev_attr.attr, | ||
318 | &sensor_dev_attr_in4_max.dev_attr.attr, | ||
319 | &sensor_dev_attr_in5_max.dev_attr.attr, | ||
320 | &sensor_dev_attr_in6_max.dev_attr.attr, | ||
321 | &sensor_dev_attr_in0_input.dev_attr.attr, | ||
322 | &sensor_dev_attr_in1_input.dev_attr.attr, | ||
323 | &sensor_dev_attr_in2_input.dev_attr.attr, | ||
324 | &sensor_dev_attr_in3_input.dev_attr.attr, | ||
325 | &sensor_dev_attr_in4_input.dev_attr.attr, | ||
326 | &sensor_dev_attr_in5_input.dev_attr.attr, | ||
327 | &sensor_dev_attr_in6_input.dev_attr.attr, | ||
328 | &sensor_dev_attr_temp1_input.dev_attr.attr, | ||
329 | &sensor_dev_attr_temp1_max.dev_attr.attr, | ||
330 | &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, | ||
331 | &sensor_dev_attr_in0_alarm.dev_attr.attr, | ||
332 | &sensor_dev_attr_in1_alarm.dev_attr.attr, | ||
333 | &sensor_dev_attr_in2_alarm.dev_attr.attr, | ||
334 | &sensor_dev_attr_in3_alarm.dev_attr.attr, | ||
335 | &sensor_dev_attr_in4_alarm.dev_attr.attr, | ||
336 | &sensor_dev_attr_in5_alarm.dev_attr.attr, | ||
337 | &sensor_dev_attr_in6_alarm.dev_attr.attr, | ||
338 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, | ||
339 | NULL | ||
340 | }; | ||
341 | ATTRIBUTE_GROUPS(adc128); | ||
342 | |||
343 | static int adc128_detect(struct i2c_client *client, struct i2c_board_info *info) | ||
344 | { | ||
345 | int man_id, dev_id; | ||
346 | |||
347 | if (!i2c_check_functionality(client->adapter, | ||
348 | I2C_FUNC_SMBUS_BYTE_DATA | | ||
349 | I2C_FUNC_SMBUS_WORD_DATA)) | ||
350 | return -ENODEV; | ||
351 | |||
352 | man_id = i2c_smbus_read_byte_data(client, ADC128_REG_MAN_ID); | ||
353 | dev_id = i2c_smbus_read_byte_data(client, ADC128_REG_DEV_ID); | ||
354 | if (man_id != 0x01 || dev_id != 0x09) | ||
355 | return -ENODEV; | ||
356 | |||
357 | /* Check unused bits for confirmation */ | ||
358 | if (i2c_smbus_read_byte_data(client, ADC128_REG_CONFIG) & 0xf4) | ||
359 | return -ENODEV; | ||
360 | if (i2c_smbus_read_byte_data(client, ADC128_REG_CONV_RATE) & 0xfe) | ||
361 | return -ENODEV; | ||
362 | if (i2c_smbus_read_byte_data(client, ADC128_REG_ONESHOT) & 0xfe) | ||
363 | return -ENODEV; | ||
364 | if (i2c_smbus_read_byte_data(client, ADC128_REG_SHUTDOWN) & 0xfe) | ||
365 | return -ENODEV; | ||
366 | if (i2c_smbus_read_byte_data(client, ADC128_REG_CONFIG_ADV) & 0xf8) | ||
367 | return -ENODEV; | ||
368 | if (i2c_smbus_read_byte_data(client, ADC128_REG_BUSY_STATUS) & 0xfc) | ||
369 | return -ENODEV; | ||
370 | |||
371 | strlcpy(info->type, "adc128d818", I2C_NAME_SIZE); | ||
372 | |||
373 | return 0; | ||
374 | } | ||
375 | |||
376 | static int adc128_init_client(struct adc128_data *data) | ||
377 | { | ||
378 | struct i2c_client *client = data->client; | ||
379 | int err; | ||
380 | |||
381 | /* | ||
382 | * Reset chip to defaults. | ||
383 | * This makes most other initializations unnecessary. | ||
384 | */ | ||
385 | err = i2c_smbus_write_byte_data(client, ADC128_REG_CONFIG, 0x80); | ||
386 | if (err) | ||
387 | return err; | ||
388 | |||
389 | /* Start monitoring */ | ||
390 | err = i2c_smbus_write_byte_data(client, ADC128_REG_CONFIG, 0x01); | ||
391 | if (err) | ||
392 | return err; | ||
393 | |||
394 | /* If external vref is selected, configure the chip to use it */ | ||
395 | if (data->regulator) { | ||
396 | err = i2c_smbus_write_byte_data(client, | ||
397 | ADC128_REG_CONFIG_ADV, 0x01); | ||
398 | if (err) | ||
399 | return err; | ||
400 | } | ||
401 | |||
402 | return 0; | ||
403 | } | ||
404 | |||
405 | static int adc128_probe(struct i2c_client *client, | ||
406 | const struct i2c_device_id *id) | ||
407 | { | ||
408 | struct device *dev = &client->dev; | ||
409 | struct regulator *regulator; | ||
410 | struct device *hwmon_dev; | ||
411 | struct adc128_data *data; | ||
412 | int err, vref; | ||
413 | |||
414 | data = devm_kzalloc(dev, sizeof(struct adc128_data), GFP_KERNEL); | ||
415 | if (!data) | ||
416 | return -ENOMEM; | ||
417 | |||
418 | /* vref is optional. If specified, is used as chip reference voltage */ | ||
419 | regulator = devm_regulator_get_optional(dev, "vref"); | ||
420 | if (!IS_ERR(regulator)) { | ||
421 | data->regulator = regulator; | ||
422 | err = regulator_enable(regulator); | ||
423 | if (err < 0) | ||
424 | return err; | ||
425 | vref = regulator_get_voltage(regulator); | ||
426 | if (vref < 0) { | ||
427 | err = vref; | ||
428 | goto error; | ||
429 | } | ||
430 | data->vref = DIV_ROUND_CLOSEST(vref, 1000); | ||
431 | } else { | ||
432 | data->vref = 2560; /* 2.56V, in mV */ | ||
433 | } | ||
434 | |||
435 | data->client = client; | ||
436 | i2c_set_clientdata(client, data); | ||
437 | mutex_init(&data->update_lock); | ||
438 | |||
439 | /* Initialize the chip */ | ||
440 | err = adc128_init_client(data); | ||
441 | if (err < 0) | ||
442 | goto error; | ||
443 | |||
444 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, | ||
445 | data, adc128_groups); | ||
446 | if (IS_ERR(hwmon_dev)) { | ||
447 | err = PTR_ERR(hwmon_dev); | ||
448 | goto error; | ||
449 | } | ||
450 | |||
451 | return 0; | ||
452 | |||
453 | error: | ||
454 | if (data->regulator) | ||
455 | regulator_disable(data->regulator); | ||
456 | return err; | ||
457 | } | ||
458 | |||
459 | static int adc128_remove(struct i2c_client *client) | ||
460 | { | ||
461 | struct adc128_data *data = i2c_get_clientdata(client); | ||
462 | |||
463 | if (data->regulator) | ||
464 | regulator_disable(data->regulator); | ||
465 | |||
466 | return 0; | ||
467 | } | ||
468 | |||
469 | static const struct i2c_device_id adc128_id[] = { | ||
470 | { "adc128d818", 0 }, | ||
471 | { } | ||
472 | }; | ||
473 | MODULE_DEVICE_TABLE(i2c, adc128_id); | ||
474 | |||
475 | static struct i2c_driver adc128_driver = { | ||
476 | .class = I2C_CLASS_HWMON, | ||
477 | .driver = { | ||
478 | .name = "adc128d818", | ||
479 | }, | ||
480 | .probe = adc128_probe, | ||
481 | .remove = adc128_remove, | ||
482 | .id_table = adc128_id, | ||
483 | .detect = adc128_detect, | ||
484 | .address_list = normal_i2c, | ||
485 | }; | ||
486 | |||
487 | module_i2c_driver(adc128_driver); | ||
488 | |||
489 | MODULE_AUTHOR("Guenter Roeck"); | ||
490 | MODULE_DESCRIPTION("Driver for ADC128D818"); | ||
491 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/hwmon/adm1021.c b/drivers/hwmon/adm1021.c index 29dd9f746dfa..3eb4281689b5 100644 --- a/drivers/hwmon/adm1021.c +++ b/drivers/hwmon/adm1021.c | |||
@@ -79,9 +79,11 @@ enum chips { | |||
79 | 79 | ||
80 | /* Each client has this additional data */ | 80 | /* Each client has this additional data */ |
81 | struct adm1021_data { | 81 | struct adm1021_data { |
82 | struct device *hwmon_dev; | 82 | struct i2c_client *client; |
83 | enum chips type; | 83 | enum chips type; |
84 | 84 | ||
85 | const struct attribute_group *groups[3]; | ||
86 | |||
85 | struct mutex update_lock; | 87 | struct mutex update_lock; |
86 | char valid; /* !=0 if following fields are valid */ | 88 | char valid; /* !=0 if following fields are valid */ |
87 | char low_power; /* !=0 if device in low power mode */ | 89 | char low_power; /* !=0 if device in low power mode */ |
@@ -101,7 +103,6 @@ static int adm1021_probe(struct i2c_client *client, | |||
101 | static int adm1021_detect(struct i2c_client *client, | 103 | static int adm1021_detect(struct i2c_client *client, |
102 | struct i2c_board_info *info); | 104 | struct i2c_board_info *info); |
103 | static void adm1021_init_client(struct i2c_client *client); | 105 | static void adm1021_init_client(struct i2c_client *client); |
104 | static int adm1021_remove(struct i2c_client *client); | ||
105 | static struct adm1021_data *adm1021_update_device(struct device *dev); | 106 | static struct adm1021_data *adm1021_update_device(struct device *dev); |
106 | 107 | ||
107 | /* (amalysh) read only mode, otherwise any limit's writing confuse BIOS */ | 108 | /* (amalysh) read only mode, otherwise any limit's writing confuse BIOS */ |
@@ -128,7 +129,6 @@ static struct i2c_driver adm1021_driver = { | |||
128 | .name = "adm1021", | 129 | .name = "adm1021", |
129 | }, | 130 | }, |
130 | .probe = adm1021_probe, | 131 | .probe = adm1021_probe, |
131 | .remove = adm1021_remove, | ||
132 | .id_table = adm1021_id, | 132 | .id_table = adm1021_id, |
133 | .detect = adm1021_detect, | 133 | .detect = adm1021_detect, |
134 | .address_list = normal_i2c, | 134 | .address_list = normal_i2c, |
@@ -182,8 +182,8 @@ static ssize_t set_temp_max(struct device *dev, | |||
182 | const char *buf, size_t count) | 182 | const char *buf, size_t count) |
183 | { | 183 | { |
184 | int index = to_sensor_dev_attr(devattr)->index; | 184 | int index = to_sensor_dev_attr(devattr)->index; |
185 | struct i2c_client *client = to_i2c_client(dev); | 185 | struct adm1021_data *data = dev_get_drvdata(dev); |
186 | struct adm1021_data *data = i2c_get_clientdata(client); | 186 | struct i2c_client *client = data->client; |
187 | long temp; | 187 | long temp; |
188 | int err; | 188 | int err; |
189 | 189 | ||
@@ -207,8 +207,8 @@ static ssize_t set_temp_min(struct device *dev, | |||
207 | const char *buf, size_t count) | 207 | const char *buf, size_t count) |
208 | { | 208 | { |
209 | int index = to_sensor_dev_attr(devattr)->index; | 209 | int index = to_sensor_dev_attr(devattr)->index; |
210 | struct i2c_client *client = to_i2c_client(dev); | 210 | struct adm1021_data *data = dev_get_drvdata(dev); |
211 | struct adm1021_data *data = i2c_get_clientdata(client); | 211 | struct i2c_client *client = data->client; |
212 | long temp; | 212 | long temp; |
213 | int err; | 213 | int err; |
214 | 214 | ||
@@ -238,8 +238,8 @@ static ssize_t set_low_power(struct device *dev, | |||
238 | struct device_attribute *devattr, | 238 | struct device_attribute *devattr, |
239 | const char *buf, size_t count) | 239 | const char *buf, size_t count) |
240 | { | 240 | { |
241 | struct i2c_client *client = to_i2c_client(dev); | 241 | struct adm1021_data *data = dev_get_drvdata(dev); |
242 | struct adm1021_data *data = i2c_get_clientdata(client); | 242 | struct i2c_client *client = data->client; |
243 | char low_power; | 243 | char low_power; |
244 | unsigned long val; | 244 | unsigned long val; |
245 | int err; | 245 | int err; |
@@ -412,15 +412,15 @@ static int adm1021_detect(struct i2c_client *client, | |||
412 | static int adm1021_probe(struct i2c_client *client, | 412 | static int adm1021_probe(struct i2c_client *client, |
413 | const struct i2c_device_id *id) | 413 | const struct i2c_device_id *id) |
414 | { | 414 | { |
415 | struct device *dev = &client->dev; | ||
415 | struct adm1021_data *data; | 416 | struct adm1021_data *data; |
416 | int err; | 417 | struct device *hwmon_dev; |
417 | 418 | ||
418 | data = devm_kzalloc(&client->dev, sizeof(struct adm1021_data), | 419 | data = devm_kzalloc(dev, sizeof(struct adm1021_data), GFP_KERNEL); |
419 | GFP_KERNEL); | ||
420 | if (!data) | 420 | if (!data) |
421 | return -ENOMEM; | 421 | return -ENOMEM; |
422 | 422 | ||
423 | i2c_set_clientdata(client, data); | 423 | data->client = client; |
424 | data->type = id->driver_data; | 424 | data->type = id->driver_data; |
425 | mutex_init(&data->update_lock); | 425 | mutex_init(&data->update_lock); |
426 | 426 | ||
@@ -428,29 +428,14 @@ static int adm1021_probe(struct i2c_client *client, | |||
428 | if (data->type != lm84 && !read_only) | 428 | if (data->type != lm84 && !read_only) |
429 | adm1021_init_client(client); | 429 | adm1021_init_client(client); |
430 | 430 | ||
431 | /* Register sysfs hooks */ | 431 | data->groups[0] = &adm1021_group; |
432 | err = sysfs_create_group(&client->dev.kobj, &adm1021_group); | 432 | if (data->type != lm84) |
433 | if (err) | 433 | data->groups[1] = &adm1021_min_group; |
434 | return err; | ||
435 | |||
436 | if (data->type != lm84) { | ||
437 | err = sysfs_create_group(&client->dev.kobj, &adm1021_min_group); | ||
438 | if (err) | ||
439 | goto error; | ||
440 | } | ||
441 | 434 | ||
442 | data->hwmon_dev = hwmon_device_register(&client->dev); | 435 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
443 | if (IS_ERR(data->hwmon_dev)) { | 436 | data, data->groups); |
444 | err = PTR_ERR(data->hwmon_dev); | ||
445 | goto error; | ||
446 | } | ||
447 | 437 | ||
448 | return 0; | 438 | return PTR_ERR_OR_ZERO(hwmon_dev); |
449 | |||
450 | error: | ||
451 | sysfs_remove_group(&client->dev.kobj, &adm1021_min_group); | ||
452 | sysfs_remove_group(&client->dev.kobj, &adm1021_group); | ||
453 | return err; | ||
454 | } | 439 | } |
455 | 440 | ||
456 | static void adm1021_init_client(struct i2c_client *client) | 441 | static void adm1021_init_client(struct i2c_client *client) |
@@ -462,21 +447,10 @@ static void adm1021_init_client(struct i2c_client *client) | |||
462 | i2c_smbus_write_byte_data(client, ADM1021_REG_CONV_RATE_W, 0x04); | 447 | i2c_smbus_write_byte_data(client, ADM1021_REG_CONV_RATE_W, 0x04); |
463 | } | 448 | } |
464 | 449 | ||
465 | static int adm1021_remove(struct i2c_client *client) | ||
466 | { | ||
467 | struct adm1021_data *data = i2c_get_clientdata(client); | ||
468 | |||
469 | hwmon_device_unregister(data->hwmon_dev); | ||
470 | sysfs_remove_group(&client->dev.kobj, &adm1021_min_group); | ||
471 | sysfs_remove_group(&client->dev.kobj, &adm1021_group); | ||
472 | |||
473 | return 0; | ||
474 | } | ||
475 | |||
476 | static struct adm1021_data *adm1021_update_device(struct device *dev) | 450 | static struct adm1021_data *adm1021_update_device(struct device *dev) |
477 | { | 451 | { |
478 | struct i2c_client *client = to_i2c_client(dev); | 452 | struct adm1021_data *data = dev_get_drvdata(dev); |
479 | struct adm1021_data *data = i2c_get_clientdata(client); | 453 | struct i2c_client *client = data->client; |
480 | 454 | ||
481 | mutex_lock(&data->update_lock); | 455 | mutex_lock(&data->update_lock); |
482 | 456 | ||
@@ -484,7 +458,7 @@ static struct adm1021_data *adm1021_update_device(struct device *dev) | |||
484 | || !data->valid) { | 458 | || !data->valid) { |
485 | int i; | 459 | int i; |
486 | 460 | ||
487 | dev_dbg(&client->dev, "Starting adm1021 update\n"); | 461 | dev_dbg(dev, "Starting adm1021 update\n"); |
488 | 462 | ||
489 | for (i = 0; i < 2; i++) { | 463 | for (i = 0; i < 2; i++) { |
490 | data->temp[i] = 1000 * | 464 | data->temp[i] = 1000 * |
diff --git a/drivers/hwmon/asc7621.c b/drivers/hwmon/asc7621.c index 8d9f2a0e8efe..71463689d163 100644 --- a/drivers/hwmon/asc7621.c +++ b/drivers/hwmon/asc7621.c | |||
@@ -1115,7 +1115,6 @@ asc7621_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
1115 | return -ENOMEM; | 1115 | return -ENOMEM; |
1116 | 1116 | ||
1117 | i2c_set_clientdata(client, data); | 1117 | i2c_set_clientdata(client, data); |
1118 | data->valid = 0; | ||
1119 | mutex_init(&data->update_lock); | 1118 | mutex_init(&data->update_lock); |
1120 | 1119 | ||
1121 | /* Initialize the asc7621 chip */ | 1120 | /* Initialize the asc7621 chip */ |
diff --git a/drivers/hwmon/atxp1.c b/drivers/hwmon/atxp1.c index ddff02e3e66f..6edce42c61d5 100644 --- a/drivers/hwmon/atxp1.c +++ b/drivers/hwmon/atxp1.c | |||
@@ -353,8 +353,6 @@ static int atxp1_probe(struct i2c_client *new_client, | |||
353 | data->vrm = vid_which_vrm(); | 353 | data->vrm = vid_which_vrm(); |
354 | 354 | ||
355 | i2c_set_clientdata(new_client, data); | 355 | i2c_set_clientdata(new_client, data); |
356 | data->valid = 0; | ||
357 | |||
358 | mutex_init(&data->update_lock); | 356 | mutex_init(&data->update_lock); |
359 | 357 | ||
360 | /* Register sysfs hooks */ | 358 | /* Register sysfs hooks */ |
diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index bbb0b0d463f7..6d02e3b06375 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c | |||
@@ -94,6 +94,8 @@ struct temp_data { | |||
94 | bool valid; | 94 | bool valid; |
95 | struct sensor_device_attribute sd_attrs[TOTAL_ATTRS]; | 95 | struct sensor_device_attribute sd_attrs[TOTAL_ATTRS]; |
96 | char attr_name[TOTAL_ATTRS][CORETEMP_NAME_LENGTH]; | 96 | char attr_name[TOTAL_ATTRS][CORETEMP_NAME_LENGTH]; |
97 | struct attribute *attrs[TOTAL_ATTRS + 1]; | ||
98 | struct attribute_group attr_group; | ||
97 | struct mutex update_lock; | 99 | struct mutex update_lock; |
98 | }; | 100 | }; |
99 | 101 | ||
@@ -114,12 +116,6 @@ struct pdev_entry { | |||
114 | static LIST_HEAD(pdev_list); | 116 | static LIST_HEAD(pdev_list); |
115 | static DEFINE_MUTEX(pdev_list_mutex); | 117 | static DEFINE_MUTEX(pdev_list_mutex); |
116 | 118 | ||
117 | static ssize_t show_name(struct device *dev, | ||
118 | struct device_attribute *devattr, char *buf) | ||
119 | { | ||
120 | return sprintf(buf, "%s\n", DRVNAME); | ||
121 | } | ||
122 | |||
123 | static ssize_t show_label(struct device *dev, | 119 | static ssize_t show_label(struct device *dev, |
124 | struct device_attribute *devattr, char *buf) | 120 | struct device_attribute *devattr, char *buf) |
125 | { | 121 | { |
@@ -393,20 +389,10 @@ static int get_tjmax(struct cpuinfo_x86 *c, u32 id, struct device *dev) | |||
393 | return adjust_tjmax(c, id, dev); | 389 | return adjust_tjmax(c, id, dev); |
394 | } | 390 | } |
395 | 391 | ||
396 | static int create_name_attr(struct platform_data *pdata, | ||
397 | struct device *dev) | ||
398 | { | ||
399 | sysfs_attr_init(&pdata->name_attr.attr); | ||
400 | pdata->name_attr.attr.name = "name"; | ||
401 | pdata->name_attr.attr.mode = S_IRUGO; | ||
402 | pdata->name_attr.show = show_name; | ||
403 | return device_create_file(dev, &pdata->name_attr); | ||
404 | } | ||
405 | |||
406 | static int create_core_attrs(struct temp_data *tdata, struct device *dev, | 392 | static int create_core_attrs(struct temp_data *tdata, struct device *dev, |
407 | int attr_no) | 393 | int attr_no) |
408 | { | 394 | { |
409 | int err, i; | 395 | int i; |
410 | static ssize_t (*const rd_ptr[TOTAL_ATTRS]) (struct device *dev, | 396 | static ssize_t (*const rd_ptr[TOTAL_ATTRS]) (struct device *dev, |
411 | struct device_attribute *devattr, char *buf) = { | 397 | struct device_attribute *devattr, char *buf) = { |
412 | show_label, show_crit_alarm, show_temp, show_tjmax, | 398 | show_label, show_crit_alarm, show_temp, show_tjmax, |
@@ -424,16 +410,10 @@ static int create_core_attrs(struct temp_data *tdata, struct device *dev, | |||
424 | tdata->sd_attrs[i].dev_attr.attr.mode = S_IRUGO; | 410 | tdata->sd_attrs[i].dev_attr.attr.mode = S_IRUGO; |
425 | tdata->sd_attrs[i].dev_attr.show = rd_ptr[i]; | 411 | tdata->sd_attrs[i].dev_attr.show = rd_ptr[i]; |
426 | tdata->sd_attrs[i].index = attr_no; | 412 | tdata->sd_attrs[i].index = attr_no; |
427 | err = device_create_file(dev, &tdata->sd_attrs[i].dev_attr); | 413 | tdata->attrs[i] = &tdata->sd_attrs[i].dev_attr.attr; |
428 | if (err) | ||
429 | goto exit_free; | ||
430 | } | 414 | } |
431 | return 0; | 415 | tdata->attr_group.attrs = tdata->attrs; |
432 | 416 | return sysfs_create_group(&dev->kobj, &tdata->attr_group); | |
433 | exit_free: | ||
434 | while (--i >= 0) | ||
435 | device_remove_file(dev, &tdata->sd_attrs[i].dev_attr); | ||
436 | return err; | ||
437 | } | 417 | } |
438 | 418 | ||
439 | 419 | ||
@@ -548,7 +528,7 @@ static int create_core_data(struct platform_device *pdev, unsigned int cpu, | |||
548 | pdata->core_data[attr_no] = tdata; | 528 | pdata->core_data[attr_no] = tdata; |
549 | 529 | ||
550 | /* Create sysfs interfaces */ | 530 | /* Create sysfs interfaces */ |
551 | err = create_core_attrs(tdata, &pdev->dev, attr_no); | 531 | err = create_core_attrs(tdata, pdata->hwmon_dev, attr_no); |
552 | if (err) | 532 | if (err) |
553 | goto exit_free; | 533 | goto exit_free; |
554 | 534 | ||
@@ -573,14 +553,12 @@ static void coretemp_add_core(unsigned int cpu, int pkg_flag) | |||
573 | } | 553 | } |
574 | 554 | ||
575 | static void coretemp_remove_core(struct platform_data *pdata, | 555 | static void coretemp_remove_core(struct platform_data *pdata, |
576 | struct device *dev, int indx) | 556 | int indx) |
577 | { | 557 | { |
578 | int i; | ||
579 | struct temp_data *tdata = pdata->core_data[indx]; | 558 | struct temp_data *tdata = pdata->core_data[indx]; |
580 | 559 | ||
581 | /* Remove the sysfs attributes */ | 560 | /* Remove the sysfs attributes */ |
582 | for (i = 0; i < tdata->attr_size; i++) | 561 | sysfs_remove_group(&pdata->hwmon_dev->kobj, &tdata->attr_group); |
583 | device_remove_file(dev, &tdata->sd_attrs[i].dev_attr); | ||
584 | 562 | ||
585 | kfree(pdata->core_data[indx]); | 563 | kfree(pdata->core_data[indx]); |
586 | pdata->core_data[indx] = NULL; | 564 | pdata->core_data[indx] = NULL; |
@@ -588,34 +566,20 @@ static void coretemp_remove_core(struct platform_data *pdata, | |||
588 | 566 | ||
589 | static int coretemp_probe(struct platform_device *pdev) | 567 | static int coretemp_probe(struct platform_device *pdev) |
590 | { | 568 | { |
569 | struct device *dev = &pdev->dev; | ||
591 | struct platform_data *pdata; | 570 | struct platform_data *pdata; |
592 | int err; | ||
593 | 571 | ||
594 | /* Initialize the per-package data structures */ | 572 | /* Initialize the per-package data structures */ |
595 | pdata = kzalloc(sizeof(struct platform_data), GFP_KERNEL); | 573 | pdata = devm_kzalloc(dev, sizeof(struct platform_data), GFP_KERNEL); |
596 | if (!pdata) | 574 | if (!pdata) |
597 | return -ENOMEM; | 575 | return -ENOMEM; |
598 | 576 | ||
599 | err = create_name_attr(pdata, &pdev->dev); | ||
600 | if (err) | ||
601 | goto exit_free; | ||
602 | |||
603 | pdata->phys_proc_id = pdev->id; | 577 | pdata->phys_proc_id = pdev->id; |
604 | platform_set_drvdata(pdev, pdata); | 578 | platform_set_drvdata(pdev, pdata); |
605 | 579 | ||
606 | pdata->hwmon_dev = hwmon_device_register(&pdev->dev); | 580 | pdata->hwmon_dev = devm_hwmon_device_register_with_groups(dev, DRVNAME, |
607 | if (IS_ERR(pdata->hwmon_dev)) { | 581 | pdata, NULL); |
608 | err = PTR_ERR(pdata->hwmon_dev); | 582 | return PTR_ERR_OR_ZERO(pdata->hwmon_dev); |
609 | dev_err(&pdev->dev, "Class registration failed (%d)\n", err); | ||
610 | goto exit_name; | ||
611 | } | ||
612 | return 0; | ||
613 | |||
614 | exit_name: | ||
615 | device_remove_file(&pdev->dev, &pdata->name_attr); | ||
616 | exit_free: | ||
617 | kfree(pdata); | ||
618 | return err; | ||
619 | } | 583 | } |
620 | 584 | ||
621 | static int coretemp_remove(struct platform_device *pdev) | 585 | static int coretemp_remove(struct platform_device *pdev) |
@@ -625,11 +589,8 @@ static int coretemp_remove(struct platform_device *pdev) | |||
625 | 589 | ||
626 | for (i = MAX_CORE_DATA - 1; i >= 0; --i) | 590 | for (i = MAX_CORE_DATA - 1; i >= 0; --i) |
627 | if (pdata->core_data[i]) | 591 | if (pdata->core_data[i]) |
628 | coretemp_remove_core(pdata, &pdev->dev, i); | 592 | coretemp_remove_core(pdata, i); |
629 | 593 | ||
630 | device_remove_file(&pdev->dev, &pdata->name_attr); | ||
631 | hwmon_device_unregister(pdata->hwmon_dev); | ||
632 | kfree(pdata); | ||
633 | return 0; | 594 | return 0; |
634 | } | 595 | } |
635 | 596 | ||
@@ -777,7 +738,7 @@ static void put_core_offline(unsigned int cpu) | |||
777 | return; | 738 | return; |
778 | 739 | ||
779 | if (pdata->core_data[indx] && pdata->core_data[indx]->cpu == cpu) | 740 | if (pdata->core_data[indx] && pdata->core_data[indx]->cpu == cpu) |
780 | coretemp_remove_core(pdata, &pdev->dev, indx); | 741 | coretemp_remove_core(pdata, indx); |
781 | 742 | ||
782 | /* | 743 | /* |
783 | * If a HT sibling of a core is taken offline, but another HT sibling | 744 | * If a HT sibling of a core is taken offline, but another HT sibling |
@@ -849,20 +810,20 @@ static int __init coretemp_init(void) | |||
849 | if (err) | 810 | if (err) |
850 | goto exit; | 811 | goto exit; |
851 | 812 | ||
852 | get_online_cpus(); | 813 | cpu_notifier_register_begin(); |
853 | for_each_online_cpu(i) | 814 | for_each_online_cpu(i) |
854 | get_core_online(i); | 815 | get_core_online(i); |
855 | 816 | ||
856 | #ifndef CONFIG_HOTPLUG_CPU | 817 | #ifndef CONFIG_HOTPLUG_CPU |
857 | if (list_empty(&pdev_list)) { | 818 | if (list_empty(&pdev_list)) { |
858 | put_online_cpus(); | 819 | cpu_notifier_register_done(); |
859 | err = -ENODEV; | 820 | err = -ENODEV; |
860 | goto exit_driver_unreg; | 821 | goto exit_driver_unreg; |
861 | } | 822 | } |
862 | #endif | 823 | #endif |
863 | 824 | ||
864 | register_hotcpu_notifier(&coretemp_cpu_notifier); | 825 | __register_hotcpu_notifier(&coretemp_cpu_notifier); |
865 | put_online_cpus(); | 826 | cpu_notifier_register_done(); |
866 | return 0; | 827 | return 0; |
867 | 828 | ||
868 | #ifndef CONFIG_HOTPLUG_CPU | 829 | #ifndef CONFIG_HOTPLUG_CPU |
@@ -877,8 +838,8 @@ static void __exit coretemp_exit(void) | |||
877 | { | 838 | { |
878 | struct pdev_entry *p, *n; | 839 | struct pdev_entry *p, *n; |
879 | 840 | ||
880 | get_online_cpus(); | 841 | cpu_notifier_register_begin(); |
881 | unregister_hotcpu_notifier(&coretemp_cpu_notifier); | 842 | __unregister_hotcpu_notifier(&coretemp_cpu_notifier); |
882 | mutex_lock(&pdev_list_mutex); | 843 | mutex_lock(&pdev_list_mutex); |
883 | list_for_each_entry_safe(p, n, &pdev_list, list) { | 844 | list_for_each_entry_safe(p, n, &pdev_list, list) { |
884 | platform_device_unregister(p->pdev); | 845 | platform_device_unregister(p->pdev); |
@@ -886,7 +847,7 @@ static void __exit coretemp_exit(void) | |||
886 | kfree(p); | 847 | kfree(p); |
887 | } | 848 | } |
888 | mutex_unlock(&pdev_list_mutex); | 849 | mutex_unlock(&pdev_list_mutex); |
889 | put_online_cpus(); | 850 | cpu_notifier_register_done(); |
890 | platform_driver_unregister(&coretemp_driver); | 851 | platform_driver_unregister(&coretemp_driver); |
891 | } | 852 | } |
892 | 853 | ||
diff --git a/drivers/hwmon/emc2103.c b/drivers/hwmon/emc2103.c index 2c137b26acb4..fd892dd48e4c 100644 --- a/drivers/hwmon/emc2103.c +++ b/drivers/hwmon/emc2103.c | |||
@@ -349,7 +349,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *da, | |||
349 | dev_dbg(&client->dev, "reg 0x%02x, err %d\n", | 349 | dev_dbg(&client->dev, "reg 0x%02x, err %d\n", |
350 | REG_FAN_CONF1, status); | 350 | REG_FAN_CONF1, status); |
351 | mutex_unlock(&data->update_lock); | 351 | mutex_unlock(&data->update_lock); |
352 | return -EIO; | 352 | return status; |
353 | } | 353 | } |
354 | status &= 0x9F; | 354 | status &= 0x9F; |
355 | status |= (new_range_bits << 5); | 355 | status |= (new_range_bits << 5); |
diff --git a/drivers/hwmon/f71805f.c b/drivers/hwmon/f71805f.c index 1a8aa1265262..32f5132c4652 100644 --- a/drivers/hwmon/f71805f.c +++ b/drivers/hwmon/f71805f.c | |||
@@ -1648,7 +1648,7 @@ static void __exit f71805f_exit(void) | |||
1648 | platform_driver_unregister(&f71805f_driver); | 1648 | platform_driver_unregister(&f71805f_driver); |
1649 | } | 1649 | } |
1650 | 1650 | ||
1651 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr>"); | 1651 | MODULE_AUTHOR("Jean Delvare <jdelvare@suse.de>"); |
1652 | MODULE_LICENSE("GPL"); | 1652 | MODULE_LICENSE("GPL"); |
1653 | MODULE_DESCRIPTION("F71805F/F71872F hardware monitoring driver"); | 1653 | MODULE_DESCRIPTION("F71805F/F71872F hardware monitoring driver"); |
1654 | 1654 | ||
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c index e176a43af63d..a26c385a435b 100644 --- a/drivers/hwmon/hwmon.c +++ b/drivers/hwmon/hwmon.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/gfp.h> | 22 | #include <linux/gfp.h> |
23 | #include <linux/spinlock.h> | 23 | #include <linux/spinlock.h> |
24 | #include <linux/pci.h> | 24 | #include <linux/pci.h> |
25 | #include <linux/string.h> | ||
25 | 26 | ||
26 | #define HWMON_ID_PREFIX "hwmon" | 27 | #define HWMON_ID_PREFIX "hwmon" |
27 | #define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d" | 28 | #define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d" |
@@ -99,6 +100,10 @@ hwmon_device_register_with_groups(struct device *dev, const char *name, | |||
99 | struct hwmon_device *hwdev; | 100 | struct hwmon_device *hwdev; |
100 | int err, id; | 101 | int err, id; |
101 | 102 | ||
103 | /* Do not accept invalid characters in hwmon name attribute */ | ||
104 | if (name && (!strlen(name) || strpbrk(name, "-* \t\n"))) | ||
105 | return ERR_PTR(-EINVAL); | ||
106 | |||
102 | id = ida_simple_get(&hwmon_ida, 0, 0, GFP_KERNEL); | 107 | id = ida_simple_get(&hwmon_ida, 0, 0, GFP_KERNEL); |
103 | if (id < 0) | 108 | if (id < 0) |
104 | return ERR_PTR(id); | 109 | return ERR_PTR(id); |
diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c index 708081b68c6f..9fbb1b1fdff3 100644 --- a/drivers/hwmon/iio_hwmon.c +++ b/drivers/hwmon/iio_hwmon.c | |||
@@ -31,6 +31,7 @@ struct iio_hwmon_state { | |||
31 | int num_channels; | 31 | int num_channels; |
32 | struct device *hwmon_dev; | 32 | struct device *hwmon_dev; |
33 | struct attribute_group attr_group; | 33 | struct attribute_group attr_group; |
34 | const struct attribute_group *groups[2]; | ||
34 | struct attribute **attrs; | 35 | struct attribute **attrs; |
35 | }; | 36 | }; |
36 | 37 | ||
@@ -56,19 +57,6 @@ static ssize_t iio_hwmon_read_val(struct device *dev, | |||
56 | return sprintf(buf, "%d\n", result); | 57 | return sprintf(buf, "%d\n", result); |
57 | } | 58 | } |
58 | 59 | ||
59 | static ssize_t show_name(struct device *dev, struct device_attribute *attr, | ||
60 | char *buf) | ||
61 | { | ||
62 | const char *name = "iio_hwmon"; | ||
63 | |||
64 | if (dev->of_node && dev->of_node->name) | ||
65 | name = dev->of_node->name; | ||
66 | |||
67 | return sprintf(buf, "%s\n", name); | ||
68 | } | ||
69 | |||
70 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | ||
71 | |||
72 | static int iio_hwmon_probe(struct platform_device *pdev) | 60 | static int iio_hwmon_probe(struct platform_device *pdev) |
73 | { | 61 | { |
74 | struct device *dev = &pdev->dev; | 62 | struct device *dev = &pdev->dev; |
@@ -78,6 +66,10 @@ static int iio_hwmon_probe(struct platform_device *pdev) | |||
78 | int in_i = 1, temp_i = 1, curr_i = 1; | 66 | int in_i = 1, temp_i = 1, curr_i = 1; |
79 | enum iio_chan_type type; | 67 | enum iio_chan_type type; |
80 | struct iio_channel *channels; | 68 | struct iio_channel *channels; |
69 | const char *name = "iio_hwmon"; | ||
70 | |||
71 | if (dev->of_node && dev->of_node->name) | ||
72 | name = dev->of_node->name; | ||
81 | 73 | ||
82 | channels = iio_channel_get_all(dev); | 74 | channels = iio_channel_get_all(dev); |
83 | if (IS_ERR(channels)) | 75 | if (IS_ERR(channels)) |
@@ -96,7 +88,7 @@ static int iio_hwmon_probe(struct platform_device *pdev) | |||
96 | st->num_channels++; | 88 | st->num_channels++; |
97 | 89 | ||
98 | st->attrs = devm_kzalloc(dev, | 90 | st->attrs = devm_kzalloc(dev, |
99 | sizeof(*st->attrs) * (st->num_channels + 2), | 91 | sizeof(*st->attrs) * (st->num_channels + 1), |
100 | GFP_KERNEL); | 92 | GFP_KERNEL); |
101 | if (st->attrs == NULL) { | 93 | if (st->attrs == NULL) { |
102 | ret = -ENOMEM; | 94 | ret = -ENOMEM; |
@@ -144,22 +136,18 @@ static int iio_hwmon_probe(struct platform_device *pdev) | |||
144 | a->index = i; | 136 | a->index = i; |
145 | st->attrs[i] = &a->dev_attr.attr; | 137 | st->attrs[i] = &a->dev_attr.attr; |
146 | } | 138 | } |
147 | st->attrs[st->num_channels] = &dev_attr_name.attr; | ||
148 | st->attr_group.attrs = st->attrs; | ||
149 | platform_set_drvdata(pdev, st); | ||
150 | ret = sysfs_create_group(&dev->kobj, &st->attr_group); | ||
151 | if (ret < 0) | ||
152 | goto error_release_channels; | ||
153 | 139 | ||
154 | st->hwmon_dev = hwmon_device_register(dev); | 140 | st->attr_group.attrs = st->attrs; |
141 | st->groups[0] = &st->attr_group; | ||
142 | st->hwmon_dev = hwmon_device_register_with_groups(dev, name, st, | ||
143 | st->groups); | ||
155 | if (IS_ERR(st->hwmon_dev)) { | 144 | if (IS_ERR(st->hwmon_dev)) { |
156 | ret = PTR_ERR(st->hwmon_dev); | 145 | ret = PTR_ERR(st->hwmon_dev); |
157 | goto error_remove_group; | 146 | goto error_release_channels; |
158 | } | 147 | } |
148 | platform_set_drvdata(pdev, st); | ||
159 | return 0; | 149 | return 0; |
160 | 150 | ||
161 | error_remove_group: | ||
162 | sysfs_remove_group(&dev->kobj, &st->attr_group); | ||
163 | error_release_channels: | 151 | error_release_channels: |
164 | iio_channel_release_all(channels); | 152 | iio_channel_release_all(channels); |
165 | return ret; | 153 | return ret; |
@@ -170,7 +158,6 @@ static int iio_hwmon_remove(struct platform_device *pdev) | |||
170 | struct iio_hwmon_state *st = platform_get_drvdata(pdev); | 158 | struct iio_hwmon_state *st = platform_get_drvdata(pdev); |
171 | 159 | ||
172 | hwmon_device_unregister(st->hwmon_dev); | 160 | hwmon_device_unregister(st->hwmon_dev); |
173 | sysfs_remove_group(&pdev->dev.kobj, &st->attr_group); | ||
174 | iio_channel_release_all(st->channels); | 161 | iio_channel_release_all(st->channels); |
175 | 162 | ||
176 | return 0; | 163 | return 0; |
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c index 70749fc15a4f..a327fd3402a7 100644 --- a/drivers/hwmon/it87.c +++ b/drivers/hwmon/it87.c | |||
@@ -11,6 +11,7 @@ | |||
11 | * similar parts. The other devices are supported by different drivers. | 11 | * similar parts. The other devices are supported by different drivers. |
12 | * | 12 | * |
13 | * Supports: IT8603E Super I/O chip w/LPC interface | 13 | * Supports: IT8603E Super I/O chip w/LPC interface |
14 | * IT8623E Super I/O chip w/LPC interface | ||
14 | * IT8705F Super I/O chip w/LPC interface | 15 | * IT8705F Super I/O chip w/LPC interface |
15 | * IT8712F Super I/O chip w/LPC interface | 16 | * IT8712F Super I/O chip w/LPC interface |
16 | * IT8716F Super I/O chip w/LPC interface | 17 | * IT8716F Super I/O chip w/LPC interface |
@@ -147,7 +148,8 @@ static inline void superio_exit(void) | |||
147 | #define IT8772E_DEVID 0x8772 | 148 | #define IT8772E_DEVID 0x8772 |
148 | #define IT8782F_DEVID 0x8782 | 149 | #define IT8782F_DEVID 0x8782 |
149 | #define IT8783E_DEVID 0x8783 | 150 | #define IT8783E_DEVID 0x8783 |
150 | #define IT8306E_DEVID 0x8603 | 151 | #define IT8603E_DEVID 0x8603 |
152 | #define IT8623E_DEVID 0x8623 | ||
151 | #define IT87_ACT_REG 0x30 | 153 | #define IT87_ACT_REG 0x30 |
152 | #define IT87_BASE_REG 0x60 | 154 | #define IT87_BASE_REG 0x60 |
153 | 155 | ||
@@ -1431,7 +1433,7 @@ static ssize_t show_label(struct device *dev, struct device_attribute *attr, | |||
1431 | static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0); | 1433 | static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0); |
1432 | static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1); | 1434 | static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1); |
1433 | static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 2); | 1435 | static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 2); |
1434 | /* special AVCC3 IT8306E in9 */ | 1436 | /* special AVCC3 IT8603E in9 */ |
1435 | static SENSOR_DEVICE_ATTR(in9_label, S_IRUGO, show_label, NULL, 0); | 1437 | static SENSOR_DEVICE_ATTR(in9_label, S_IRUGO, show_label, NULL, 0); |
1436 | 1438 | ||
1437 | static ssize_t show_name(struct device *dev, struct device_attribute | 1439 | static ssize_t show_name(struct device *dev, struct device_attribute |
@@ -1766,7 +1768,8 @@ static int __init it87_find(unsigned short *address, | |||
1766 | case IT8783E_DEVID: | 1768 | case IT8783E_DEVID: |
1767 | sio_data->type = it8783; | 1769 | sio_data->type = it8783; |
1768 | break; | 1770 | break; |
1769 | case IT8306E_DEVID: | 1771 | case IT8603E_DEVID: |
1772 | case IT8623E_DEVID: | ||
1770 | sio_data->type = it8603; | 1773 | sio_data->type = it8603; |
1771 | break; | 1774 | break; |
1772 | case 0xffff: /* No device at all */ | 1775 | case 0xffff: /* No device at all */ |
diff --git a/drivers/hwmon/jz4740-hwmon.c b/drivers/hwmon/jz4740-hwmon.c index a183e488db78..7488e36809c8 100644 --- a/drivers/hwmon/jz4740-hwmon.c +++ b/drivers/hwmon/jz4740-hwmon.c | |||
@@ -28,7 +28,6 @@ | |||
28 | #include <linux/hwmon.h> | 28 | #include <linux/hwmon.h> |
29 | 29 | ||
30 | struct jz4740_hwmon { | 30 | struct jz4740_hwmon { |
31 | struct resource *mem; | ||
32 | void __iomem *base; | 31 | void __iomem *base; |
33 | 32 | ||
34 | int irq; | 33 | int irq; |
@@ -106,6 +105,7 @@ static int jz4740_hwmon_probe(struct platform_device *pdev) | |||
106 | { | 105 | { |
107 | int ret; | 106 | int ret; |
108 | struct jz4740_hwmon *hwmon; | 107 | struct jz4740_hwmon *hwmon; |
108 | struct resource *mem; | ||
109 | 109 | ||
110 | hwmon = devm_kzalloc(&pdev->dev, sizeof(*hwmon), GFP_KERNEL); | 110 | hwmon = devm_kzalloc(&pdev->dev, sizeof(*hwmon), GFP_KERNEL); |
111 | if (!hwmon) | 111 | if (!hwmon) |
@@ -120,25 +120,10 @@ static int jz4740_hwmon_probe(struct platform_device *pdev) | |||
120 | return hwmon->irq; | 120 | return hwmon->irq; |
121 | } | 121 | } |
122 | 122 | ||
123 | hwmon->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 123 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
124 | if (!hwmon->mem) { | 124 | hwmon->base = devm_ioremap_resource(&pdev->dev, mem); |
125 | dev_err(&pdev->dev, "Failed to get platform mmio resource\n"); | 125 | if (IS_ERR(hwmon->base)) |
126 | return -ENOENT; | 126 | return PTR_ERR(hwmon->base); |
127 | } | ||
128 | |||
129 | hwmon->mem = devm_request_mem_region(&pdev->dev, hwmon->mem->start, | ||
130 | resource_size(hwmon->mem), pdev->name); | ||
131 | if (!hwmon->mem) { | ||
132 | dev_err(&pdev->dev, "Failed to request mmio memory region\n"); | ||
133 | return -EBUSY; | ||
134 | } | ||
135 | |||
136 | hwmon->base = devm_ioremap_nocache(&pdev->dev, hwmon->mem->start, | ||
137 | resource_size(hwmon->mem)); | ||
138 | if (!hwmon->base) { | ||
139 | dev_err(&pdev->dev, "Failed to ioremap mmio memory\n"); | ||
140 | return -EBUSY; | ||
141 | } | ||
142 | 127 | ||
143 | init_completion(&hwmon->read_completion); | 128 | init_completion(&hwmon->read_completion); |
144 | mutex_init(&hwmon->lock); | 129 | mutex_init(&hwmon->lock); |
diff --git a/drivers/hwmon/k10temp.c b/drivers/hwmon/k10temp.c index baf375b5ab0d..f7b46f68ef43 100644 --- a/drivers/hwmon/k10temp.c +++ b/drivers/hwmon/k10temp.c | |||
@@ -212,6 +212,7 @@ static const struct pci_device_id k10temp_id_table[] = { | |||
212 | { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_M10H_F3) }, | 212 | { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_M10H_F3) }, |
213 | { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_M30H_NB_F3) }, | 213 | { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_M30H_NB_F3) }, |
214 | { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_NB_F3) }, | 214 | { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_NB_F3) }, |
215 | { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_M30H_NB_F3) }, | ||
215 | {} | 216 | {} |
216 | }; | 217 | }; |
217 | MODULE_DEVICE_TABLE(pci, k10temp_id_table); | 218 | MODULE_DEVICE_TABLE(pci, k10temp_id_table); |
diff --git a/drivers/hwmon/lm63.c b/drivers/hwmon/lm63.c index b4ad598feb6c..848b9611151f 100644 --- a/drivers/hwmon/lm63.c +++ b/drivers/hwmon/lm63.c | |||
@@ -155,8 +155,9 @@ enum chips { lm63, lm64, lm96163 }; | |||
155 | */ | 155 | */ |
156 | 156 | ||
157 | struct lm63_data { | 157 | struct lm63_data { |
158 | struct device *hwmon_dev; | 158 | struct i2c_client *client; |
159 | struct mutex update_lock; | 159 | struct mutex update_lock; |
160 | const struct attribute_group *groups[5]; | ||
160 | char valid; /* zero until following fields are valid */ | 161 | char valid; /* zero until following fields are valid */ |
161 | char lut_valid; /* zero until lut fields are valid */ | 162 | char lut_valid; /* zero until lut fields are valid */ |
162 | unsigned long last_updated; /* in jiffies */ | 163 | unsigned long last_updated; /* in jiffies */ |
@@ -218,9 +219,9 @@ static inline int lut_temp_to_reg(struct lm63_data *data, long val) | |||
218 | * Update the lookup table register cache. | 219 | * Update the lookup table register cache. |
219 | * client->update_lock must be held when calling this function. | 220 | * client->update_lock must be held when calling this function. |
220 | */ | 221 | */ |
221 | static void lm63_update_lut(struct i2c_client *client) | 222 | static void lm63_update_lut(struct lm63_data *data) |
222 | { | 223 | { |
223 | struct lm63_data *data = i2c_get_clientdata(client); | 224 | struct i2c_client *client = data->client; |
224 | int i; | 225 | int i; |
225 | 226 | ||
226 | if (time_after(jiffies, data->lut_last_updated + 5 * HZ) || | 227 | if (time_after(jiffies, data->lut_last_updated + 5 * HZ) || |
@@ -241,8 +242,8 @@ static void lm63_update_lut(struct i2c_client *client) | |||
241 | 242 | ||
242 | static struct lm63_data *lm63_update_device(struct device *dev) | 243 | static struct lm63_data *lm63_update_device(struct device *dev) |
243 | { | 244 | { |
244 | struct i2c_client *client = to_i2c_client(dev); | 245 | struct lm63_data *data = dev_get_drvdata(dev); |
245 | struct lm63_data *data = i2c_get_clientdata(client); | 246 | struct i2c_client *client = data->client; |
246 | unsigned long next_update; | 247 | unsigned long next_update; |
247 | 248 | ||
248 | mutex_lock(&data->update_lock); | 249 | mutex_lock(&data->update_lock); |
@@ -310,7 +311,7 @@ static struct lm63_data *lm63_update_device(struct device *dev) | |||
310 | data->valid = 1; | 311 | data->valid = 1; |
311 | } | 312 | } |
312 | 313 | ||
313 | lm63_update_lut(client); | 314 | lm63_update_lut(data); |
314 | 315 | ||
315 | mutex_unlock(&data->update_lock); | 316 | mutex_unlock(&data->update_lock); |
316 | 317 | ||
@@ -321,18 +322,17 @@ static struct lm63_data *lm63_update_device(struct device *dev) | |||
321 | * Trip points in the lookup table should be in ascending order for both | 322 | * Trip points in the lookup table should be in ascending order for both |
322 | * temperatures and PWM output values. | 323 | * temperatures and PWM output values. |
323 | */ | 324 | */ |
324 | static int lm63_lut_looks_bad(struct i2c_client *client) | 325 | static int lm63_lut_looks_bad(struct device *dev, struct lm63_data *data) |
325 | { | 326 | { |
326 | struct lm63_data *data = i2c_get_clientdata(client); | ||
327 | int i; | 327 | int i; |
328 | 328 | ||
329 | mutex_lock(&data->update_lock); | 329 | mutex_lock(&data->update_lock); |
330 | lm63_update_lut(client); | 330 | lm63_update_lut(data); |
331 | 331 | ||
332 | for (i = 1; i < data->lut_size; i++) { | 332 | for (i = 1; i < data->lut_size; i++) { |
333 | if (data->pwm1[1 + i - 1] > data->pwm1[1 + i] | 333 | if (data->pwm1[1 + i - 1] > data->pwm1[1 + i] |
334 | || data->temp8[3 + i - 1] > data->temp8[3 + i]) { | 334 | || data->temp8[3 + i - 1] > data->temp8[3 + i]) { |
335 | dev_warn(&client->dev, | 335 | dev_warn(dev, |
336 | "Lookup table doesn't look sane (check entries %d and %d)\n", | 336 | "Lookup table doesn't look sane (check entries %d and %d)\n", |
337 | i, i + 1); | 337 | i, i + 1); |
338 | break; | 338 | break; |
@@ -358,8 +358,8 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, | |||
358 | static ssize_t set_fan(struct device *dev, struct device_attribute *dummy, | 358 | static ssize_t set_fan(struct device *dev, struct device_attribute *dummy, |
359 | const char *buf, size_t count) | 359 | const char *buf, size_t count) |
360 | { | 360 | { |
361 | struct i2c_client *client = to_i2c_client(dev); | 361 | struct lm63_data *data = dev_get_drvdata(dev); |
362 | struct lm63_data *data = i2c_get_clientdata(client); | 362 | struct i2c_client *client = data->client; |
363 | unsigned long val; | 363 | unsigned long val; |
364 | int err; | 364 | int err; |
365 | 365 | ||
@@ -399,8 +399,8 @@ static ssize_t set_pwm1(struct device *dev, struct device_attribute *devattr, | |||
399 | const char *buf, size_t count) | 399 | const char *buf, size_t count) |
400 | { | 400 | { |
401 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 401 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
402 | struct i2c_client *client = to_i2c_client(dev); | 402 | struct lm63_data *data = dev_get_drvdata(dev); |
403 | struct lm63_data *data = i2c_get_clientdata(client); | 403 | struct i2c_client *client = data->client; |
404 | int nr = attr->index; | 404 | int nr = attr->index; |
405 | unsigned long val; | 405 | unsigned long val; |
406 | int err; | 406 | int err; |
@@ -435,8 +435,8 @@ static ssize_t set_pwm1_enable(struct device *dev, | |||
435 | struct device_attribute *dummy, | 435 | struct device_attribute *dummy, |
436 | const char *buf, size_t count) | 436 | const char *buf, size_t count) |
437 | { | 437 | { |
438 | struct i2c_client *client = to_i2c_client(dev); | 438 | struct lm63_data *data = dev_get_drvdata(dev); |
439 | struct lm63_data *data = i2c_get_clientdata(client); | 439 | struct i2c_client *client = data->client; |
440 | unsigned long val; | 440 | unsigned long val; |
441 | int err; | 441 | int err; |
442 | 442 | ||
@@ -450,7 +450,7 @@ static ssize_t set_pwm1_enable(struct device *dev, | |||
450 | * Only let the user switch to automatic mode if the lookup table | 450 | * Only let the user switch to automatic mode if the lookup table |
451 | * looks sane. | 451 | * looks sane. |
452 | */ | 452 | */ |
453 | if (val == 2 && lm63_lut_looks_bad(client)) | 453 | if (val == 2 && lm63_lut_looks_bad(dev, data)) |
454 | return -EPERM; | 454 | return -EPERM; |
455 | 455 | ||
456 | mutex_lock(&data->update_lock); | 456 | mutex_lock(&data->update_lock); |
@@ -461,7 +461,7 @@ static ssize_t set_pwm1_enable(struct device *dev, | |||
461 | else | 461 | else |
462 | data->config_fan &= ~0x20; | 462 | data->config_fan &= ~0x20; |
463 | i2c_smbus_write_byte_data(client, LM63_REG_CONFIG_FAN, | 463 | i2c_smbus_write_byte_data(client, LM63_REG_CONFIG_FAN, |
464 | data->config_fan); | 464 | data->config_fan); |
465 | mutex_unlock(&data->update_lock); | 465 | mutex_unlock(&data->update_lock); |
466 | return count; | 466 | return count; |
467 | } | 467 | } |
@@ -505,8 +505,8 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr, | |||
505 | const char *buf, size_t count) | 505 | const char *buf, size_t count) |
506 | { | 506 | { |
507 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 507 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
508 | struct i2c_client *client = to_i2c_client(dev); | 508 | struct lm63_data *data = dev_get_drvdata(dev); |
509 | struct lm63_data *data = i2c_get_clientdata(client); | 509 | struct i2c_client *client = data->client; |
510 | int nr = attr->index; | 510 | int nr = attr->index; |
511 | long val; | 511 | long val; |
512 | int err; | 512 | int err; |
@@ -579,8 +579,8 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, | |||
579 | }; | 579 | }; |
580 | 580 | ||
581 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 581 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
582 | struct i2c_client *client = to_i2c_client(dev); | 582 | struct lm63_data *data = dev_get_drvdata(dev); |
583 | struct lm63_data *data = i2c_get_clientdata(client); | 583 | struct i2c_client *client = data->client; |
584 | long val; | 584 | long val; |
585 | int err; | 585 | int err; |
586 | int nr = attr->index; | 586 | int nr = attr->index; |
@@ -635,8 +635,8 @@ static ssize_t set_temp2_crit_hyst(struct device *dev, | |||
635 | struct device_attribute *dummy, | 635 | struct device_attribute *dummy, |
636 | const char *buf, size_t count) | 636 | const char *buf, size_t count) |
637 | { | 637 | { |
638 | struct i2c_client *client = to_i2c_client(dev); | 638 | struct lm63_data *data = dev_get_drvdata(dev); |
639 | struct lm63_data *data = i2c_get_clientdata(client); | 639 | struct i2c_client *client = data->client; |
640 | long val; | 640 | long val; |
641 | int err; | 641 | int err; |
642 | long hyst; | 642 | long hyst; |
@@ -657,11 +657,11 @@ static ssize_t set_temp2_crit_hyst(struct device *dev, | |||
657 | * Set conversion rate. | 657 | * Set conversion rate. |
658 | * client->update_lock must be held when calling this function. | 658 | * client->update_lock must be held when calling this function. |
659 | */ | 659 | */ |
660 | static void lm63_set_convrate(struct i2c_client *client, struct lm63_data *data, | 660 | static void lm63_set_convrate(struct lm63_data *data, unsigned int interval) |
661 | unsigned int interval) | ||
662 | { | 661 | { |
663 | int i; | 662 | struct i2c_client *client = data->client; |
664 | unsigned int update_interval; | 663 | unsigned int update_interval; |
664 | int i; | ||
665 | 665 | ||
666 | /* Shift calculations to avoid rounding errors */ | 666 | /* Shift calculations to avoid rounding errors */ |
667 | interval <<= 6; | 667 | interval <<= 6; |
@@ -689,8 +689,7 @@ static ssize_t set_update_interval(struct device *dev, | |||
689 | struct device_attribute *attr, | 689 | struct device_attribute *attr, |
690 | const char *buf, size_t count) | 690 | const char *buf, size_t count) |
691 | { | 691 | { |
692 | struct i2c_client *client = to_i2c_client(dev); | 692 | struct lm63_data *data = dev_get_drvdata(dev); |
693 | struct lm63_data *data = i2c_get_clientdata(client); | ||
694 | unsigned long val; | 693 | unsigned long val; |
695 | int err; | 694 | int err; |
696 | 695 | ||
@@ -699,7 +698,7 @@ static ssize_t set_update_interval(struct device *dev, | |||
699 | return err; | 698 | return err; |
700 | 699 | ||
701 | mutex_lock(&data->update_lock); | 700 | mutex_lock(&data->update_lock); |
702 | lm63_set_convrate(client, data, clamp_val(val, 0, 100000)); | 701 | lm63_set_convrate(data, clamp_val(val, 0, 100000)); |
703 | mutex_unlock(&data->update_lock); | 702 | mutex_unlock(&data->update_lock); |
704 | 703 | ||
705 | return count; | 704 | return count; |
@@ -708,8 +707,7 @@ static ssize_t set_update_interval(struct device *dev, | |||
708 | static ssize_t show_type(struct device *dev, struct device_attribute *attr, | 707 | static ssize_t show_type(struct device *dev, struct device_attribute *attr, |
709 | char *buf) | 708 | char *buf) |
710 | { | 709 | { |
711 | struct i2c_client *client = to_i2c_client(dev); | 710 | struct lm63_data *data = dev_get_drvdata(dev); |
712 | struct lm63_data *data = i2c_get_clientdata(client); | ||
713 | 711 | ||
714 | return sprintf(buf, data->trutherm ? "1\n" : "2\n"); | 712 | return sprintf(buf, data->trutherm ? "1\n" : "2\n"); |
715 | } | 713 | } |
@@ -717,8 +715,8 @@ static ssize_t show_type(struct device *dev, struct device_attribute *attr, | |||
717 | static ssize_t set_type(struct device *dev, struct device_attribute *attr, | 715 | static ssize_t set_type(struct device *dev, struct device_attribute *attr, |
718 | const char *buf, size_t count) | 716 | const char *buf, size_t count) |
719 | { | 717 | { |
720 | struct i2c_client *client = to_i2c_client(dev); | 718 | struct lm63_data *data = dev_get_drvdata(dev); |
721 | struct lm63_data *data = i2c_get_clientdata(client); | 719 | struct i2c_client *client = data->client; |
722 | unsigned long val; | 720 | unsigned long val; |
723 | int ret; | 721 | int ret; |
724 | u8 reg; | 722 | u8 reg; |
@@ -915,6 +913,15 @@ static struct attribute *lm63_attributes[] = { | |||
915 | NULL | 913 | NULL |
916 | }; | 914 | }; |
917 | 915 | ||
916 | static struct attribute *lm63_attributes_temp2_type[] = { | ||
917 | &dev_attr_temp2_type.attr, | ||
918 | NULL | ||
919 | }; | ||
920 | |||
921 | static const struct attribute_group lm63_group_temp2_type = { | ||
922 | .attrs = lm63_attributes_temp2_type, | ||
923 | }; | ||
924 | |||
918 | static struct attribute *lm63_attributes_extra_lut[] = { | 925 | static struct attribute *lm63_attributes_extra_lut[] = { |
919 | &sensor_dev_attr_pwm1_auto_point9_pwm.dev_attr.attr, | 926 | &sensor_dev_attr_pwm1_auto_point9_pwm.dev_attr.attr, |
920 | &sensor_dev_attr_pwm1_auto_point9_temp.dev_attr.attr, | 927 | &sensor_dev_attr_pwm1_auto_point9_temp.dev_attr.attr, |
@@ -946,8 +953,7 @@ static umode_t lm63_attribute_mode(struct kobject *kobj, | |||
946 | struct attribute *attr, int index) | 953 | struct attribute *attr, int index) |
947 | { | 954 | { |
948 | struct device *dev = container_of(kobj, struct device, kobj); | 955 | struct device *dev = container_of(kobj, struct device, kobj); |
949 | struct i2c_client *client = to_i2c_client(dev); | 956 | struct lm63_data *data = dev_get_drvdata(dev); |
950 | struct lm63_data *data = i2c_get_clientdata(client); | ||
951 | 957 | ||
952 | if (attr == &sensor_dev_attr_temp2_crit.dev_attr.attr | 958 | if (attr == &sensor_dev_attr_temp2_crit.dev_attr.attr |
953 | && (data->kind == lm64 || | 959 | && (data->kind == lm64 || |
@@ -1026,9 +1032,10 @@ static int lm63_detect(struct i2c_client *client, | |||
1026 | * Ideally we shouldn't have to initialize anything, since the BIOS | 1032 | * Ideally we shouldn't have to initialize anything, since the BIOS |
1027 | * should have taken care of everything | 1033 | * should have taken care of everything |
1028 | */ | 1034 | */ |
1029 | static void lm63_init_client(struct i2c_client *client) | 1035 | static void lm63_init_client(struct lm63_data *data) |
1030 | { | 1036 | { |
1031 | struct lm63_data *data = i2c_get_clientdata(client); | 1037 | struct i2c_client *client = data->client; |
1038 | struct device *dev = &client->dev; | ||
1032 | u8 convrate; | 1039 | u8 convrate; |
1033 | 1040 | ||
1034 | data->config = i2c_smbus_read_byte_data(client, LM63_REG_CONFIG1); | 1041 | data->config = i2c_smbus_read_byte_data(client, LM63_REG_CONFIG1); |
@@ -1037,7 +1044,7 @@ static void lm63_init_client(struct i2c_client *client) | |||
1037 | 1044 | ||
1038 | /* Start converting if needed */ | 1045 | /* Start converting if needed */ |
1039 | if (data->config & 0x40) { /* standby */ | 1046 | if (data->config & 0x40) { /* standby */ |
1040 | dev_dbg(&client->dev, "Switching to operational mode\n"); | 1047 | dev_dbg(dev, "Switching to operational mode\n"); |
1041 | data->config &= 0xA7; | 1048 | data->config &= 0xA7; |
1042 | i2c_smbus_write_byte_data(client, LM63_REG_CONFIG1, | 1049 | i2c_smbus_write_byte_data(client, LM63_REG_CONFIG1, |
1043 | data->config); | 1050 | data->config); |
@@ -1090,13 +1097,13 @@ static void lm63_init_client(struct i2c_client *client) | |||
1090 | 1097 | ||
1091 | /* Show some debug info about the LM63 configuration */ | 1098 | /* Show some debug info about the LM63 configuration */ |
1092 | if (data->kind == lm63) | 1099 | if (data->kind == lm63) |
1093 | dev_dbg(&client->dev, "Alert/tach pin configured for %s\n", | 1100 | dev_dbg(dev, "Alert/tach pin configured for %s\n", |
1094 | (data->config & 0x04) ? "tachometer input" : | 1101 | (data->config & 0x04) ? "tachometer input" : |
1095 | "alert output"); | 1102 | "alert output"); |
1096 | dev_dbg(&client->dev, "PWM clock %s kHz, output frequency %u Hz\n", | 1103 | dev_dbg(dev, "PWM clock %s kHz, output frequency %u Hz\n", |
1097 | (data->config_fan & 0x08) ? "1.4" : "360", | 1104 | (data->config_fan & 0x08) ? "1.4" : "360", |
1098 | ((data->config_fan & 0x08) ? 700 : 180000) / data->pwm1_freq); | 1105 | ((data->config_fan & 0x08) ? 700 : 180000) / data->pwm1_freq); |
1099 | dev_dbg(&client->dev, "PWM output active %s, %s mode\n", | 1106 | dev_dbg(dev, "PWM output active %s, %s mode\n", |
1100 | (data->config_fan & 0x10) ? "low" : "high", | 1107 | (data->config_fan & 0x10) ? "low" : "high", |
1101 | (data->config_fan & 0x20) ? "manual" : "auto"); | 1108 | (data->config_fan & 0x20) ? "manual" : "auto"); |
1102 | } | 1109 | } |
@@ -1104,15 +1111,16 @@ static void lm63_init_client(struct i2c_client *client) | |||
1104 | static int lm63_probe(struct i2c_client *client, | 1111 | static int lm63_probe(struct i2c_client *client, |
1105 | const struct i2c_device_id *id) | 1112 | const struct i2c_device_id *id) |
1106 | { | 1113 | { |
1114 | struct device *dev = &client->dev; | ||
1115 | struct device *hwmon_dev; | ||
1107 | struct lm63_data *data; | 1116 | struct lm63_data *data; |
1108 | int err; | 1117 | int groups = 0; |
1109 | 1118 | ||
1110 | data = devm_kzalloc(&client->dev, sizeof(struct lm63_data), GFP_KERNEL); | 1119 | data = devm_kzalloc(dev, sizeof(struct lm63_data), GFP_KERNEL); |
1111 | if (!data) | 1120 | if (!data) |
1112 | return -ENOMEM; | 1121 | return -ENOMEM; |
1113 | 1122 | ||
1114 | i2c_set_clientdata(client, data); | 1123 | data->client = client; |
1115 | data->valid = 0; | ||
1116 | mutex_init(&data->update_lock); | 1124 | mutex_init(&data->update_lock); |
1117 | 1125 | ||
1118 | /* Set the device type */ | 1126 | /* Set the device type */ |
@@ -1121,59 +1129,21 @@ static int lm63_probe(struct i2c_client *client, | |||
1121 | data->temp2_offset = 16000; | 1129 | data->temp2_offset = 16000; |
1122 | 1130 | ||
1123 | /* Initialize chip */ | 1131 | /* Initialize chip */ |
1124 | lm63_init_client(client); | 1132 | lm63_init_client(data); |
1125 | 1133 | ||
1126 | /* Register sysfs hooks */ | 1134 | /* Register sysfs hooks */ |
1127 | err = sysfs_create_group(&client->dev.kobj, &lm63_group); | 1135 | data->groups[groups++] = &lm63_group; |
1128 | if (err) | 1136 | if (data->config & 0x04) /* tachometer enabled */ |
1129 | return err; | 1137 | data->groups[groups++] = &lm63_group_fan1; |
1130 | if (data->config & 0x04) { /* tachometer enabled */ | ||
1131 | err = sysfs_create_group(&client->dev.kobj, &lm63_group_fan1); | ||
1132 | if (err) | ||
1133 | goto exit_remove_files; | ||
1134 | } | ||
1135 | if (data->kind == lm96163) { | ||
1136 | err = device_create_file(&client->dev, &dev_attr_temp2_type); | ||
1137 | if (err) | ||
1138 | goto exit_remove_files; | ||
1139 | |||
1140 | err = sysfs_create_group(&client->dev.kobj, | ||
1141 | &lm63_group_extra_lut); | ||
1142 | if (err) | ||
1143 | goto exit_remove_files; | ||
1144 | } | ||
1145 | |||
1146 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
1147 | if (IS_ERR(data->hwmon_dev)) { | ||
1148 | err = PTR_ERR(data->hwmon_dev); | ||
1149 | goto exit_remove_files; | ||
1150 | } | ||
1151 | 1138 | ||
1152 | return 0; | ||
1153 | |||
1154 | exit_remove_files: | ||
1155 | sysfs_remove_group(&client->dev.kobj, &lm63_group); | ||
1156 | sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1); | ||
1157 | if (data->kind == lm96163) { | 1139 | if (data->kind == lm96163) { |
1158 | device_remove_file(&client->dev, &dev_attr_temp2_type); | 1140 | data->groups[groups++] = &lm63_group_temp2_type; |
1159 | sysfs_remove_group(&client->dev.kobj, &lm63_group_extra_lut); | 1141 | data->groups[groups++] = &lm63_group_extra_lut; |
1160 | } | 1142 | } |
1161 | return err; | ||
1162 | } | ||
1163 | |||
1164 | static int lm63_remove(struct i2c_client *client) | ||
1165 | { | ||
1166 | struct lm63_data *data = i2c_get_clientdata(client); | ||
1167 | 1143 | ||
1168 | hwmon_device_unregister(data->hwmon_dev); | 1144 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
1169 | sysfs_remove_group(&client->dev.kobj, &lm63_group); | 1145 | data, data->groups); |
1170 | sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1); | 1146 | return PTR_ERR_OR_ZERO(hwmon_dev); |
1171 | if (data->kind == lm96163) { | ||
1172 | device_remove_file(&client->dev, &dev_attr_temp2_type); | ||
1173 | sysfs_remove_group(&client->dev.kobj, &lm63_group_extra_lut); | ||
1174 | } | ||
1175 | |||
1176 | return 0; | ||
1177 | } | 1147 | } |
1178 | 1148 | ||
1179 | /* | 1149 | /* |
@@ -1194,7 +1164,6 @@ static struct i2c_driver lm63_driver = { | |||
1194 | .name = "lm63", | 1164 | .name = "lm63", |
1195 | }, | 1165 | }, |
1196 | .probe = lm63_probe, | 1166 | .probe = lm63_probe, |
1197 | .remove = lm63_remove, | ||
1198 | .id_table = lm63_id, | 1167 | .id_table = lm63_id, |
1199 | .detect = lm63_detect, | 1168 | .detect = lm63_detect, |
1200 | .address_list = normal_i2c, | 1169 | .address_list = normal_i2c, |
diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c index f17beb5e6dd6..502771c06fd9 100644 --- a/drivers/hwmon/lm77.c +++ b/drivers/hwmon/lm77.c | |||
@@ -348,7 +348,6 @@ static int lm77_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
348 | return -ENOMEM; | 348 | return -ENOMEM; |
349 | 349 | ||
350 | i2c_set_clientdata(client, data); | 350 | i2c_set_clientdata(client, data); |
351 | data->valid = 0; | ||
352 | mutex_init(&data->update_lock); | 351 | mutex_init(&data->update_lock); |
353 | 352 | ||
354 | /* Initialize the LM77 chip */ | 353 | /* Initialize the LM77 chip */ |
diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c index eba89aac3ece..bd0a1ebbf867 100644 --- a/drivers/hwmon/lm80.c +++ b/drivers/hwmon/lm80.c | |||
@@ -112,7 +112,7 @@ static inline long TEMP_FROM_REG(u16 temp) | |||
112 | */ | 112 | */ |
113 | 113 | ||
114 | struct lm80_data { | 114 | struct lm80_data { |
115 | struct device *hwmon_dev; | 115 | struct i2c_client *client; |
116 | struct mutex update_lock; | 116 | struct mutex update_lock; |
117 | char error; /* !=0 if error occurred during last update */ | 117 | char error; /* !=0 if error occurred during last update */ |
118 | char valid; /* !=0 if following fields are valid */ | 118 | char valid; /* !=0 if following fields are valid */ |
@@ -140,7 +140,6 @@ static int lm80_probe(struct i2c_client *client, | |||
140 | const struct i2c_device_id *id); | 140 | const struct i2c_device_id *id); |
141 | static int lm80_detect(struct i2c_client *client, struct i2c_board_info *info); | 141 | static int lm80_detect(struct i2c_client *client, struct i2c_board_info *info); |
142 | static void lm80_init_client(struct i2c_client *client); | 142 | static void lm80_init_client(struct i2c_client *client); |
143 | static int lm80_remove(struct i2c_client *client); | ||
144 | static struct lm80_data *lm80_update_device(struct device *dev); | 143 | static struct lm80_data *lm80_update_device(struct device *dev); |
145 | static int lm80_read_value(struct i2c_client *client, u8 reg); | 144 | static int lm80_read_value(struct i2c_client *client, u8 reg); |
146 | static int lm80_write_value(struct i2c_client *client, u8 reg, u8 value); | 145 | static int lm80_write_value(struct i2c_client *client, u8 reg, u8 value); |
@@ -162,7 +161,6 @@ static struct i2c_driver lm80_driver = { | |||
162 | .name = "lm80", | 161 | .name = "lm80", |
163 | }, | 162 | }, |
164 | .probe = lm80_probe, | 163 | .probe = lm80_probe, |
165 | .remove = lm80_remove, | ||
166 | .id_table = lm80_id, | 164 | .id_table = lm80_id, |
167 | .detect = lm80_detect, | 165 | .detect = lm80_detect, |
168 | .address_list = normal_i2c, | 166 | .address_list = normal_i2c, |
@@ -191,8 +189,8 @@ static ssize_t set_in_##suffix(struct device *dev, \ | |||
191 | struct device_attribute *attr, const char *buf, size_t count) \ | 189 | struct device_attribute *attr, const char *buf, size_t count) \ |
192 | { \ | 190 | { \ |
193 | int nr = to_sensor_dev_attr(attr)->index; \ | 191 | int nr = to_sensor_dev_attr(attr)->index; \ |
194 | struct i2c_client *client = to_i2c_client(dev); \ | 192 | struct lm80_data *data = dev_get_drvdata(dev); \ |
195 | struct lm80_data *data = i2c_get_clientdata(client); \ | 193 | struct i2c_client *client = data->client; \ |
196 | long val; \ | 194 | long val; \ |
197 | int err = kstrtol(buf, 10, &val); \ | 195 | int err = kstrtol(buf, 10, &val); \ |
198 | if (err < 0) \ | 196 | if (err < 0) \ |
@@ -235,8 +233,8 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | |||
235 | const char *buf, size_t count) | 233 | const char *buf, size_t count) |
236 | { | 234 | { |
237 | int nr = to_sensor_dev_attr(attr)->index; | 235 | int nr = to_sensor_dev_attr(attr)->index; |
238 | struct i2c_client *client = to_i2c_client(dev); | 236 | struct lm80_data *data = dev_get_drvdata(dev); |
239 | struct lm80_data *data = i2c_get_clientdata(client); | 237 | struct i2c_client *client = data->client; |
240 | unsigned long val; | 238 | unsigned long val; |
241 | int err = kstrtoul(buf, 10, &val); | 239 | int err = kstrtoul(buf, 10, &val); |
242 | if (err < 0) | 240 | if (err < 0) |
@@ -259,8 +257,8 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | |||
259 | const char *buf, size_t count) | 257 | const char *buf, size_t count) |
260 | { | 258 | { |
261 | int nr = to_sensor_dev_attr(attr)->index; | 259 | int nr = to_sensor_dev_attr(attr)->index; |
262 | struct i2c_client *client = to_i2c_client(dev); | 260 | struct lm80_data *data = dev_get_drvdata(dev); |
263 | struct lm80_data *data = i2c_get_clientdata(client); | 261 | struct i2c_client *client = data->client; |
264 | unsigned long min, val; | 262 | unsigned long min, val; |
265 | u8 reg; | 263 | u8 reg; |
266 | int err = kstrtoul(buf, 10, &val); | 264 | int err = kstrtoul(buf, 10, &val); |
@@ -286,7 +284,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | |||
286 | data->fan_div[nr] = 3; | 284 | data->fan_div[nr] = 3; |
287 | break; | 285 | break; |
288 | default: | 286 | default: |
289 | dev_err(&client->dev, | 287 | dev_err(dev, |
290 | "fan_div value %ld not supported. Choose one of 1, 2, 4 or 8!\n", | 288 | "fan_div value %ld not supported. Choose one of 1, 2, 4 or 8!\n", |
291 | val); | 289 | val); |
292 | mutex_unlock(&data->update_lock); | 290 | mutex_unlock(&data->update_lock); |
@@ -332,8 +330,8 @@ show_temp(os_hyst, temp_os_hyst); | |||
332 | static ssize_t set_temp_##suffix(struct device *dev, \ | 330 | static ssize_t set_temp_##suffix(struct device *dev, \ |
333 | struct device_attribute *attr, const char *buf, size_t count) \ | 331 | struct device_attribute *attr, const char *buf, size_t count) \ |
334 | { \ | 332 | { \ |
335 | struct i2c_client *client = to_i2c_client(dev); \ | 333 | struct lm80_data *data = dev_get_drvdata(dev); \ |
336 | struct lm80_data *data = i2c_get_clientdata(client); \ | 334 | struct i2c_client *client = data->client; \ |
337 | long val; \ | 335 | long val; \ |
338 | int err = kstrtol(buf, 10, &val); \ | 336 | int err = kstrtol(buf, 10, &val); \ |
339 | if (err < 0) \ | 337 | if (err < 0) \ |
@@ -440,7 +438,7 @@ static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 13); | |||
440 | * Real code | 438 | * Real code |
441 | */ | 439 | */ |
442 | 440 | ||
443 | static struct attribute *lm80_attributes[] = { | 441 | static struct attribute *lm80_attrs[] = { |
444 | &sensor_dev_attr_in0_min.dev_attr.attr, | 442 | &sensor_dev_attr_in0_min.dev_attr.attr, |
445 | &sensor_dev_attr_in1_min.dev_attr.attr, | 443 | &sensor_dev_attr_in1_min.dev_attr.attr, |
446 | &sensor_dev_attr_in2_min.dev_attr.attr, | 444 | &sensor_dev_attr_in2_min.dev_attr.attr, |
@@ -487,10 +485,7 @@ static struct attribute *lm80_attributes[] = { | |||
487 | &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, | 485 | &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, |
488 | NULL | 486 | NULL |
489 | }; | 487 | }; |
490 | 488 | ATTRIBUTE_GROUPS(lm80); | |
491 | static const struct attribute_group lm80_group = { | ||
492 | .attrs = lm80_attributes, | ||
493 | }; | ||
494 | 489 | ||
495 | /* Return 0 if detection is successful, -ENODEV otherwise */ | 490 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
496 | static int lm80_detect(struct i2c_client *client, struct i2c_board_info *info) | 491 | static int lm80_detect(struct i2c_client *client, struct i2c_board_info *info) |
@@ -541,14 +536,15 @@ static int lm80_detect(struct i2c_client *client, struct i2c_board_info *info) | |||
541 | static int lm80_probe(struct i2c_client *client, | 536 | static int lm80_probe(struct i2c_client *client, |
542 | const struct i2c_device_id *id) | 537 | const struct i2c_device_id *id) |
543 | { | 538 | { |
539 | struct device *dev = &client->dev; | ||
540 | struct device *hwmon_dev; | ||
544 | struct lm80_data *data; | 541 | struct lm80_data *data; |
545 | int err; | ||
546 | 542 | ||
547 | data = devm_kzalloc(&client->dev, sizeof(struct lm80_data), GFP_KERNEL); | 543 | data = devm_kzalloc(dev, sizeof(struct lm80_data), GFP_KERNEL); |
548 | if (!data) | 544 | if (!data) |
549 | return -ENOMEM; | 545 | return -ENOMEM; |
550 | 546 | ||
551 | i2c_set_clientdata(client, data); | 547 | data->client = client; |
552 | mutex_init(&data->update_lock); | 548 | mutex_init(&data->update_lock); |
553 | 549 | ||
554 | /* Initialize the LM80 chip */ | 550 | /* Initialize the LM80 chip */ |
@@ -558,32 +554,10 @@ static int lm80_probe(struct i2c_client *client, | |||
558 | data->fan_min[0] = lm80_read_value(client, LM80_REG_FAN_MIN(1)); | 554 | data->fan_min[0] = lm80_read_value(client, LM80_REG_FAN_MIN(1)); |
559 | data->fan_min[1] = lm80_read_value(client, LM80_REG_FAN_MIN(2)); | 555 | data->fan_min[1] = lm80_read_value(client, LM80_REG_FAN_MIN(2)); |
560 | 556 | ||
561 | /* Register sysfs hooks */ | 557 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
562 | err = sysfs_create_group(&client->dev.kobj, &lm80_group); | 558 | data, lm80_groups); |
563 | if (err) | ||
564 | return err; | ||
565 | |||
566 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
567 | if (IS_ERR(data->hwmon_dev)) { | ||
568 | err = PTR_ERR(data->hwmon_dev); | ||
569 | goto error_remove; | ||
570 | } | ||
571 | 559 | ||
572 | return 0; | 560 | return PTR_ERR_OR_ZERO(hwmon_dev); |
573 | |||
574 | error_remove: | ||
575 | sysfs_remove_group(&client->dev.kobj, &lm80_group); | ||
576 | return err; | ||
577 | } | ||
578 | |||
579 | static int lm80_remove(struct i2c_client *client) | ||
580 | { | ||
581 | struct lm80_data *data = i2c_get_clientdata(client); | ||
582 | |||
583 | hwmon_device_unregister(data->hwmon_dev); | ||
584 | sysfs_remove_group(&client->dev.kobj, &lm80_group); | ||
585 | |||
586 | return 0; | ||
587 | } | 561 | } |
588 | 562 | ||
589 | static int lm80_read_value(struct i2c_client *client, u8 reg) | 563 | static int lm80_read_value(struct i2c_client *client, u8 reg) |
@@ -614,8 +588,8 @@ static void lm80_init_client(struct i2c_client *client) | |||
614 | 588 | ||
615 | static struct lm80_data *lm80_update_device(struct device *dev) | 589 | static struct lm80_data *lm80_update_device(struct device *dev) |
616 | { | 590 | { |
617 | struct i2c_client *client = to_i2c_client(dev); | 591 | struct lm80_data *data = dev_get_drvdata(dev); |
618 | struct lm80_data *data = i2c_get_clientdata(client); | 592 | struct i2c_client *client = data->client; |
619 | int i; | 593 | int i; |
620 | int rv; | 594 | int rv; |
621 | int prev_rv; | 595 | int prev_rv; |
@@ -627,7 +601,7 @@ static struct lm80_data *lm80_update_device(struct device *dev) | |||
627 | lm80_init_client(client); | 601 | lm80_init_client(client); |
628 | 602 | ||
629 | if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) { | 603 | if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) { |
630 | dev_dbg(&client->dev, "Starting lm80 update\n"); | 604 | dev_dbg(dev, "Starting lm80 update\n"); |
631 | for (i = 0; i <= 6; i++) { | 605 | for (i = 0; i <= 6; i++) { |
632 | rv = lm80_read_value(client, LM80_REG_IN(i)); | 606 | rv = lm80_read_value(client, LM80_REG_IN(i)); |
633 | if (rv < 0) | 607 | if (rv < 0) |
diff --git a/drivers/hwmon/lm83.c b/drivers/hwmon/lm83.c index abd270243ba7..be02155788c3 100644 --- a/drivers/hwmon/lm83.c +++ b/drivers/hwmon/lm83.c | |||
@@ -349,7 +349,6 @@ static int lm83_probe(struct i2c_client *new_client, | |||
349 | return -ENOMEM; | 349 | return -ENOMEM; |
350 | 350 | ||
351 | i2c_set_clientdata(new_client, data); | 351 | i2c_set_clientdata(new_client, data); |
352 | data->valid = 0; | ||
353 | mutex_init(&data->update_lock); | 352 | mutex_init(&data->update_lock); |
354 | 353 | ||
355 | /* | 354 | /* |
diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c index 4c5f20231c1a..ba1d83d48056 100644 --- a/drivers/hwmon/lm87.c +++ b/drivers/hwmon/lm87.c | |||
@@ -903,7 +903,6 @@ static int lm87_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
903 | return -ENOMEM; | 903 | return -ENOMEM; |
904 | 904 | ||
905 | i2c_set_clientdata(client, data); | 905 | i2c_set_clientdata(client, data); |
906 | data->valid = 0; | ||
907 | mutex_init(&data->update_lock); | 906 | mutex_init(&data->update_lock); |
908 | 907 | ||
909 | /* Initialize the LM87 chip */ | 908 | /* Initialize the LM87 chip */ |
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 701e952ae523..c9ff08dbe10c 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c | |||
@@ -365,7 +365,9 @@ enum lm90_temp11_reg_index { | |||
365 | */ | 365 | */ |
366 | 366 | ||
367 | struct lm90_data { | 367 | struct lm90_data { |
368 | struct i2c_client *client; | ||
368 | struct device *hwmon_dev; | 369 | struct device *hwmon_dev; |
370 | const struct attribute_group *groups[6]; | ||
369 | struct mutex update_lock; | 371 | struct mutex update_lock; |
370 | struct regulator *regulator; | 372 | struct regulator *regulator; |
371 | char valid; /* zero until following fields are valid */ | 373 | char valid; /* zero until following fields are valid */ |
@@ -513,8 +515,8 @@ static void lm90_set_convrate(struct i2c_client *client, struct lm90_data *data, | |||
513 | 515 | ||
514 | static struct lm90_data *lm90_update_device(struct device *dev) | 516 | static struct lm90_data *lm90_update_device(struct device *dev) |
515 | { | 517 | { |
516 | struct i2c_client *client = to_i2c_client(dev); | 518 | struct lm90_data *data = dev_get_drvdata(dev); |
517 | struct lm90_data *data = i2c_get_clientdata(client); | 519 | struct i2c_client *client = data->client; |
518 | unsigned long next_update; | 520 | unsigned long next_update; |
519 | 521 | ||
520 | mutex_lock(&data->update_lock); | 522 | mutex_lock(&data->update_lock); |
@@ -793,8 +795,8 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr, | |||
793 | }; | 795 | }; |
794 | 796 | ||
795 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 797 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
796 | struct i2c_client *client = to_i2c_client(dev); | 798 | struct lm90_data *data = dev_get_drvdata(dev); |
797 | struct lm90_data *data = i2c_get_clientdata(client); | 799 | struct i2c_client *client = data->client; |
798 | int nr = attr->index; | 800 | int nr = attr->index; |
799 | long val; | 801 | long val; |
800 | int err; | 802 | int err; |
@@ -860,8 +862,8 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, | |||
860 | }; | 862 | }; |
861 | 863 | ||
862 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); | 864 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); |
863 | struct i2c_client *client = to_i2c_client(dev); | 865 | struct lm90_data *data = dev_get_drvdata(dev); |
864 | struct lm90_data *data = i2c_get_clientdata(client); | 866 | struct i2c_client *client = data->client; |
865 | int nr = attr->nr; | 867 | int nr = attr->nr; |
866 | int index = attr->index; | 868 | int index = attr->index; |
867 | long val; | 869 | long val; |
@@ -922,8 +924,8 @@ static ssize_t show_temphyst(struct device *dev, | |||
922 | static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy, | 924 | static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy, |
923 | const char *buf, size_t count) | 925 | const char *buf, size_t count) |
924 | { | 926 | { |
925 | struct i2c_client *client = to_i2c_client(dev); | 927 | struct lm90_data *data = dev_get_drvdata(dev); |
926 | struct lm90_data *data = i2c_get_clientdata(client); | 928 | struct i2c_client *client = data->client; |
927 | long val; | 929 | long val; |
928 | int err; | 930 | int err; |
929 | int temp; | 931 | int temp; |
@@ -976,8 +978,8 @@ static ssize_t set_update_interval(struct device *dev, | |||
976 | struct device_attribute *attr, | 978 | struct device_attribute *attr, |
977 | const char *buf, size_t count) | 979 | const char *buf, size_t count) |
978 | { | 980 | { |
979 | struct i2c_client *client = to_i2c_client(dev); | 981 | struct lm90_data *data = dev_get_drvdata(dev); |
980 | struct lm90_data *data = i2c_get_clientdata(client); | 982 | struct i2c_client *client = data->client; |
981 | unsigned long val; | 983 | unsigned long val; |
982 | int err; | 984 | int err; |
983 | 985 | ||
@@ -1057,6 +1059,15 @@ static const struct attribute_group lm90_group = { | |||
1057 | .attrs = lm90_attributes, | 1059 | .attrs = lm90_attributes, |
1058 | }; | 1060 | }; |
1059 | 1061 | ||
1062 | static struct attribute *lm90_temp2_offset_attributes[] = { | ||
1063 | &sensor_dev_attr_temp2_offset.dev_attr.attr, | ||
1064 | NULL | ||
1065 | }; | ||
1066 | |||
1067 | static const struct attribute_group lm90_temp2_offset_group = { | ||
1068 | .attrs = lm90_temp2_offset_attributes, | ||
1069 | }; | ||
1070 | |||
1060 | /* | 1071 | /* |
1061 | * Additional attributes for devices with emergency sensors | 1072 | * Additional attributes for devices with emergency sensors |
1062 | */ | 1073 | */ |
@@ -1393,22 +1404,6 @@ static int lm90_detect(struct i2c_client *client, | |||
1393 | return 0; | 1404 | return 0; |
1394 | } | 1405 | } |
1395 | 1406 | ||
1396 | static void lm90_remove_files(struct i2c_client *client, struct lm90_data *data) | ||
1397 | { | ||
1398 | struct device *dev = &client->dev; | ||
1399 | |||
1400 | if (data->flags & LM90_HAVE_TEMP3) | ||
1401 | sysfs_remove_group(&dev->kobj, &lm90_temp3_group); | ||
1402 | if (data->flags & LM90_HAVE_EMERGENCY_ALARM) | ||
1403 | sysfs_remove_group(&dev->kobj, &lm90_emergency_alarm_group); | ||
1404 | if (data->flags & LM90_HAVE_EMERGENCY) | ||
1405 | sysfs_remove_group(&dev->kobj, &lm90_emergency_group); | ||
1406 | if (data->flags & LM90_HAVE_OFFSET) | ||
1407 | device_remove_file(dev, &sensor_dev_attr_temp2_offset.dev_attr); | ||
1408 | device_remove_file(dev, &dev_attr_pec); | ||
1409 | sysfs_remove_group(&dev->kobj, &lm90_group); | ||
1410 | } | ||
1411 | |||
1412 | static void lm90_restore_conf(struct i2c_client *client, struct lm90_data *data) | 1407 | static void lm90_restore_conf(struct i2c_client *client, struct lm90_data *data) |
1413 | { | 1408 | { |
1414 | /* Restore initial configuration */ | 1409 | /* Restore initial configuration */ |
@@ -1418,10 +1413,9 @@ static void lm90_restore_conf(struct i2c_client *client, struct lm90_data *data) | |||
1418 | data->config_orig); | 1413 | data->config_orig); |
1419 | } | 1414 | } |
1420 | 1415 | ||
1421 | static void lm90_init_client(struct i2c_client *client) | 1416 | static void lm90_init_client(struct i2c_client *client, struct lm90_data *data) |
1422 | { | 1417 | { |
1423 | u8 config, convrate; | 1418 | u8 config, convrate; |
1424 | struct lm90_data *data = i2c_get_clientdata(client); | ||
1425 | 1419 | ||
1426 | if (lm90_read_reg(client, LM90_REG_R_CONVRATE, &convrate) < 0) { | 1420 | if (lm90_read_reg(client, LM90_REG_R_CONVRATE, &convrate) < 0) { |
1427 | dev_warn(&client->dev, "Failed to read convrate register!\n"); | 1421 | dev_warn(&client->dev, "Failed to read convrate register!\n"); |
@@ -1519,6 +1513,7 @@ static int lm90_probe(struct i2c_client *client, | |||
1519 | struct i2c_adapter *adapter = to_i2c_adapter(dev->parent); | 1513 | struct i2c_adapter *adapter = to_i2c_adapter(dev->parent); |
1520 | struct lm90_data *data; | 1514 | struct lm90_data *data; |
1521 | struct regulator *regulator; | 1515 | struct regulator *regulator; |
1516 | int groups = 0; | ||
1522 | int err; | 1517 | int err; |
1523 | 1518 | ||
1524 | regulator = devm_regulator_get(dev, "vcc"); | 1519 | regulator = devm_regulator_get(dev, "vcc"); |
@@ -1527,15 +1522,15 @@ static int lm90_probe(struct i2c_client *client, | |||
1527 | 1522 | ||
1528 | err = regulator_enable(regulator); | 1523 | err = regulator_enable(regulator); |
1529 | if (err < 0) { | 1524 | if (err < 0) { |
1530 | dev_err(&client->dev, | 1525 | dev_err(dev, "Failed to enable regulator: %d\n", err); |
1531 | "Failed to enable regulator: %d\n", err); | ||
1532 | return err; | 1526 | return err; |
1533 | } | 1527 | } |
1534 | 1528 | ||
1535 | data = devm_kzalloc(&client->dev, sizeof(struct lm90_data), GFP_KERNEL); | 1529 | data = devm_kzalloc(dev, sizeof(struct lm90_data), GFP_KERNEL); |
1536 | if (!data) | 1530 | if (!data) |
1537 | return -ENOMEM; | 1531 | return -ENOMEM; |
1538 | 1532 | ||
1533 | data->client = client; | ||
1539 | i2c_set_clientdata(client, data); | 1534 | i2c_set_clientdata(client, data); |
1540 | mutex_init(&data->update_lock); | 1535 | mutex_init(&data->update_lock); |
1541 | 1536 | ||
@@ -1562,44 +1557,34 @@ static int lm90_probe(struct i2c_client *client, | |||
1562 | data->max_convrate = lm90_params[data->kind].max_convrate; | 1557 | data->max_convrate = lm90_params[data->kind].max_convrate; |
1563 | 1558 | ||
1564 | /* Initialize the LM90 chip */ | 1559 | /* Initialize the LM90 chip */ |
1565 | lm90_init_client(client); | 1560 | lm90_init_client(client, data); |
1566 | 1561 | ||
1567 | /* Register sysfs hooks */ | 1562 | /* Register sysfs hooks */ |
1568 | err = sysfs_create_group(&dev->kobj, &lm90_group); | 1563 | data->groups[groups++] = &lm90_group; |
1569 | if (err) | 1564 | |
1570 | goto exit_restore; | 1565 | if (data->flags & LM90_HAVE_OFFSET) |
1566 | data->groups[groups++] = &lm90_temp2_offset_group; | ||
1567 | |||
1568 | if (data->flags & LM90_HAVE_EMERGENCY) | ||
1569 | data->groups[groups++] = &lm90_emergency_group; | ||
1570 | |||
1571 | if (data->flags & LM90_HAVE_EMERGENCY_ALARM) | ||
1572 | data->groups[groups++] = &lm90_emergency_alarm_group; | ||
1573 | |||
1574 | if (data->flags & LM90_HAVE_TEMP3) | ||
1575 | data->groups[groups++] = &lm90_temp3_group; | ||
1576 | |||
1571 | if (client->flags & I2C_CLIENT_PEC) { | 1577 | if (client->flags & I2C_CLIENT_PEC) { |
1572 | err = device_create_file(dev, &dev_attr_pec); | 1578 | err = device_create_file(dev, &dev_attr_pec); |
1573 | if (err) | 1579 | if (err) |
1574 | goto exit_remove_files; | 1580 | goto exit_restore; |
1575 | } | ||
1576 | if (data->flags & LM90_HAVE_OFFSET) { | ||
1577 | err = device_create_file(dev, | ||
1578 | &sensor_dev_attr_temp2_offset.dev_attr); | ||
1579 | if (err) | ||
1580 | goto exit_remove_files; | ||
1581 | } | ||
1582 | if (data->flags & LM90_HAVE_EMERGENCY) { | ||
1583 | err = sysfs_create_group(&dev->kobj, &lm90_emergency_group); | ||
1584 | if (err) | ||
1585 | goto exit_remove_files; | ||
1586 | } | ||
1587 | if (data->flags & LM90_HAVE_EMERGENCY_ALARM) { | ||
1588 | err = sysfs_create_group(&dev->kobj, | ||
1589 | &lm90_emergency_alarm_group); | ||
1590 | if (err) | ||
1591 | goto exit_remove_files; | ||
1592 | } | ||
1593 | if (data->flags & LM90_HAVE_TEMP3) { | ||
1594 | err = sysfs_create_group(&dev->kobj, &lm90_temp3_group); | ||
1595 | if (err) | ||
1596 | goto exit_remove_files; | ||
1597 | } | 1581 | } |
1598 | 1582 | ||
1599 | data->hwmon_dev = hwmon_device_register(dev); | 1583 | data->hwmon_dev = hwmon_device_register_with_groups(dev, client->name, |
1584 | data, data->groups); | ||
1600 | if (IS_ERR(data->hwmon_dev)) { | 1585 | if (IS_ERR(data->hwmon_dev)) { |
1601 | err = PTR_ERR(data->hwmon_dev); | 1586 | err = PTR_ERR(data->hwmon_dev); |
1602 | goto exit_remove_files; | 1587 | goto exit_remove_pec; |
1603 | } | 1588 | } |
1604 | 1589 | ||
1605 | if (client->irq) { | 1590 | if (client->irq) { |
@@ -1618,8 +1603,8 @@ static int lm90_probe(struct i2c_client *client, | |||
1618 | 1603 | ||
1619 | exit_unregister: | 1604 | exit_unregister: |
1620 | hwmon_device_unregister(data->hwmon_dev); | 1605 | hwmon_device_unregister(data->hwmon_dev); |
1621 | exit_remove_files: | 1606 | exit_remove_pec: |
1622 | lm90_remove_files(client, data); | 1607 | device_remove_file(dev, &dev_attr_pec); |
1623 | exit_restore: | 1608 | exit_restore: |
1624 | lm90_restore_conf(client, data); | 1609 | lm90_restore_conf(client, data); |
1625 | regulator_disable(data->regulator); | 1610 | regulator_disable(data->regulator); |
@@ -1632,7 +1617,7 @@ static int lm90_remove(struct i2c_client *client) | |||
1632 | struct lm90_data *data = i2c_get_clientdata(client); | 1617 | struct lm90_data *data = i2c_get_clientdata(client); |
1633 | 1618 | ||
1634 | hwmon_device_unregister(data->hwmon_dev); | 1619 | hwmon_device_unregister(data->hwmon_dev); |
1635 | lm90_remove_files(client, data); | 1620 | device_remove_file(&client->dev, &dev_attr_pec); |
1636 | lm90_restore_conf(client, data); | 1621 | lm90_restore_conf(client, data); |
1637 | regulator_disable(data->regulator); | 1622 | regulator_disable(data->regulator); |
1638 | 1623 | ||
diff --git a/drivers/hwmon/lm92.c b/drivers/hwmon/lm92.c index 9d0e87a4f0cb..b9022db6511a 100644 --- a/drivers/hwmon/lm92.c +++ b/drivers/hwmon/lm92.c | |||
@@ -380,7 +380,6 @@ static int lm92_probe(struct i2c_client *new_client, | |||
380 | return -ENOMEM; | 380 | return -ENOMEM; |
381 | 381 | ||
382 | i2c_set_clientdata(new_client, data); | 382 | i2c_set_clientdata(new_client, data); |
383 | data->valid = 0; | ||
384 | mutex_init(&data->update_lock); | 383 | mutex_init(&data->update_lock); |
385 | 384 | ||
386 | /* Initialize the chipset */ | 385 | /* Initialize the chipset */ |
diff --git a/drivers/hwmon/lm93.c b/drivers/hwmon/lm93.c index 6f1c6c0dbaf5..adf23165a6a7 100644 --- a/drivers/hwmon/lm93.c +++ b/drivers/hwmon/lm93.c | |||
@@ -2754,7 +2754,6 @@ static int lm93_probe(struct i2c_client *client, | |||
2754 | i2c_set_clientdata(client, data); | 2754 | i2c_set_clientdata(client, data); |
2755 | 2755 | ||
2756 | /* housekeeping */ | 2756 | /* housekeeping */ |
2757 | data->valid = 0; | ||
2758 | data->update = update; | 2757 | data->update = update; |
2759 | mutex_init(&data->update_lock); | 2758 | mutex_init(&data->update_lock); |
2760 | 2759 | ||
diff --git a/drivers/hwmon/lm95241.c b/drivers/hwmon/lm95241.c index 4b68fb2a31d7..cdf19adaec79 100644 --- a/drivers/hwmon/lm95241.c +++ b/drivers/hwmon/lm95241.c | |||
@@ -89,7 +89,7 @@ static const u8 lm95241_reg_address[] = { | |||
89 | 89 | ||
90 | /* Client data (each client gets its own) */ | 90 | /* Client data (each client gets its own) */ |
91 | struct lm95241_data { | 91 | struct lm95241_data { |
92 | struct device *hwmon_dev; | 92 | struct i2c_client *client; |
93 | struct mutex update_lock; | 93 | struct mutex update_lock; |
94 | unsigned long last_updated, interval; /* in jiffies */ | 94 | unsigned long last_updated, interval; /* in jiffies */ |
95 | char valid; /* zero until following fields are valid */ | 95 | char valid; /* zero until following fields are valid */ |
@@ -113,8 +113,8 @@ static int temp_from_reg_unsigned(u8 val_h, u8 val_l) | |||
113 | 113 | ||
114 | static struct lm95241_data *lm95241_update_device(struct device *dev) | 114 | static struct lm95241_data *lm95241_update_device(struct device *dev) |
115 | { | 115 | { |
116 | struct i2c_client *client = to_i2c_client(dev); | 116 | struct lm95241_data *data = dev_get_drvdata(dev); |
117 | struct lm95241_data *data = i2c_get_clientdata(client); | 117 | struct i2c_client *client = data->client; |
118 | 118 | ||
119 | mutex_lock(&data->update_lock); | 119 | mutex_lock(&data->update_lock); |
120 | 120 | ||
@@ -122,7 +122,7 @@ static struct lm95241_data *lm95241_update_device(struct device *dev) | |||
122 | !data->valid) { | 122 | !data->valid) { |
123 | int i; | 123 | int i; |
124 | 124 | ||
125 | dev_dbg(&client->dev, "Updating lm95241 data.\n"); | 125 | dev_dbg(dev, "Updating lm95241 data.\n"); |
126 | for (i = 0; i < ARRAY_SIZE(lm95241_reg_address); i++) | 126 | for (i = 0; i < ARRAY_SIZE(lm95241_reg_address); i++) |
127 | data->temp[i] | 127 | data->temp[i] |
128 | = i2c_smbus_read_byte_data(client, | 128 | = i2c_smbus_read_byte_data(client, |
@@ -153,8 +153,7 @@ static ssize_t show_input(struct device *dev, struct device_attribute *attr, | |||
153 | static ssize_t show_type(struct device *dev, struct device_attribute *attr, | 153 | static ssize_t show_type(struct device *dev, struct device_attribute *attr, |
154 | char *buf) | 154 | char *buf) |
155 | { | 155 | { |
156 | struct i2c_client *client = to_i2c_client(dev); | 156 | struct lm95241_data *data = dev_get_drvdata(dev); |
157 | struct lm95241_data *data = i2c_get_clientdata(client); | ||
158 | 157 | ||
159 | return snprintf(buf, PAGE_SIZE - 1, | 158 | return snprintf(buf, PAGE_SIZE - 1, |
160 | data->model & to_sensor_dev_attr(attr)->index ? "1\n" : "2\n"); | 159 | data->model & to_sensor_dev_attr(attr)->index ? "1\n" : "2\n"); |
@@ -163,8 +162,8 @@ static ssize_t show_type(struct device *dev, struct device_attribute *attr, | |||
163 | static ssize_t set_type(struct device *dev, struct device_attribute *attr, | 162 | static ssize_t set_type(struct device *dev, struct device_attribute *attr, |
164 | const char *buf, size_t count) | 163 | const char *buf, size_t count) |
165 | { | 164 | { |
166 | struct i2c_client *client = to_i2c_client(dev); | 165 | struct lm95241_data *data = dev_get_drvdata(dev); |
167 | struct lm95241_data *data = i2c_get_clientdata(client); | 166 | struct i2c_client *client = data->client; |
168 | unsigned long val; | 167 | unsigned long val; |
169 | int shift; | 168 | int shift; |
170 | u8 mask = to_sensor_dev_attr(attr)->index; | 169 | u8 mask = to_sensor_dev_attr(attr)->index; |
@@ -201,8 +200,7 @@ static ssize_t set_type(struct device *dev, struct device_attribute *attr, | |||
201 | static ssize_t show_min(struct device *dev, struct device_attribute *attr, | 200 | static ssize_t show_min(struct device *dev, struct device_attribute *attr, |
202 | char *buf) | 201 | char *buf) |
203 | { | 202 | { |
204 | struct i2c_client *client = to_i2c_client(dev); | 203 | struct lm95241_data *data = dev_get_drvdata(dev); |
205 | struct lm95241_data *data = i2c_get_clientdata(client); | ||
206 | 204 | ||
207 | return snprintf(buf, PAGE_SIZE - 1, | 205 | return snprintf(buf, PAGE_SIZE - 1, |
208 | data->config & to_sensor_dev_attr(attr)->index ? | 206 | data->config & to_sensor_dev_attr(attr)->index ? |
@@ -212,8 +210,7 @@ static ssize_t show_min(struct device *dev, struct device_attribute *attr, | |||
212 | static ssize_t set_min(struct device *dev, struct device_attribute *attr, | 210 | static ssize_t set_min(struct device *dev, struct device_attribute *attr, |
213 | const char *buf, size_t count) | 211 | const char *buf, size_t count) |
214 | { | 212 | { |
215 | struct i2c_client *client = to_i2c_client(dev); | 213 | struct lm95241_data *data = dev_get_drvdata(dev); |
216 | struct lm95241_data *data = i2c_get_clientdata(client); | ||
217 | long val; | 214 | long val; |
218 | 215 | ||
219 | if (kstrtol(buf, 10, &val) < 0) | 216 | if (kstrtol(buf, 10, &val) < 0) |
@@ -229,7 +226,8 @@ static ssize_t set_min(struct device *dev, struct device_attribute *attr, | |||
229 | data->config &= ~to_sensor_dev_attr(attr)->index; | 226 | data->config &= ~to_sensor_dev_attr(attr)->index; |
230 | data->valid = 0; | 227 | data->valid = 0; |
231 | 228 | ||
232 | i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, data->config); | 229 | i2c_smbus_write_byte_data(data->client, LM95241_REG_RW_CONFIG, |
230 | data->config); | ||
233 | 231 | ||
234 | mutex_unlock(&data->update_lock); | 232 | mutex_unlock(&data->update_lock); |
235 | 233 | ||
@@ -239,8 +237,7 @@ static ssize_t set_min(struct device *dev, struct device_attribute *attr, | |||
239 | static ssize_t show_max(struct device *dev, struct device_attribute *attr, | 237 | static ssize_t show_max(struct device *dev, struct device_attribute *attr, |
240 | char *buf) | 238 | char *buf) |
241 | { | 239 | { |
242 | struct i2c_client *client = to_i2c_client(dev); | 240 | struct lm95241_data *data = dev_get_drvdata(dev); |
243 | struct lm95241_data *data = i2c_get_clientdata(client); | ||
244 | 241 | ||
245 | return snprintf(buf, PAGE_SIZE - 1, | 242 | return snprintf(buf, PAGE_SIZE - 1, |
246 | data->config & to_sensor_dev_attr(attr)->index ? | 243 | data->config & to_sensor_dev_attr(attr)->index ? |
@@ -250,8 +247,7 @@ static ssize_t show_max(struct device *dev, struct device_attribute *attr, | |||
250 | static ssize_t set_max(struct device *dev, struct device_attribute *attr, | 247 | static ssize_t set_max(struct device *dev, struct device_attribute *attr, |
251 | const char *buf, size_t count) | 248 | const char *buf, size_t count) |
252 | { | 249 | { |
253 | struct i2c_client *client = to_i2c_client(dev); | 250 | struct lm95241_data *data = dev_get_drvdata(dev); |
254 | struct lm95241_data *data = i2c_get_clientdata(client); | ||
255 | long val; | 251 | long val; |
256 | 252 | ||
257 | if (kstrtol(buf, 10, &val) < 0) | 253 | if (kstrtol(buf, 10, &val) < 0) |
@@ -267,7 +263,8 @@ static ssize_t set_max(struct device *dev, struct device_attribute *attr, | |||
267 | data->config &= ~to_sensor_dev_attr(attr)->index; | 263 | data->config &= ~to_sensor_dev_attr(attr)->index; |
268 | data->valid = 0; | 264 | data->valid = 0; |
269 | 265 | ||
270 | i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, data->config); | 266 | i2c_smbus_write_byte_data(data->client, LM95241_REG_RW_CONFIG, |
267 | data->config); | ||
271 | 268 | ||
272 | mutex_unlock(&data->update_lock); | 269 | mutex_unlock(&data->update_lock); |
273 | 270 | ||
@@ -286,8 +283,7 @@ static ssize_t show_interval(struct device *dev, struct device_attribute *attr, | |||
286 | static ssize_t set_interval(struct device *dev, struct device_attribute *attr, | 283 | static ssize_t set_interval(struct device *dev, struct device_attribute *attr, |
287 | const char *buf, size_t count) | 284 | const char *buf, size_t count) |
288 | { | 285 | { |
289 | struct i2c_client *client = to_i2c_client(dev); | 286 | struct lm95241_data *data = dev_get_drvdata(dev); |
290 | struct lm95241_data *data = i2c_get_clientdata(client); | ||
291 | unsigned long val; | 287 | unsigned long val; |
292 | 288 | ||
293 | if (kstrtoul(buf, 10, &val) < 0) | 289 | if (kstrtoul(buf, 10, &val) < 0) |
@@ -316,7 +312,7 @@ static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_max, set_max, | |||
316 | static DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, show_interval, | 312 | static DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, show_interval, |
317 | set_interval); | 313 | set_interval); |
318 | 314 | ||
319 | static struct attribute *lm95241_attributes[] = { | 315 | static struct attribute *lm95241_attrs[] = { |
320 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 316 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
321 | &sensor_dev_attr_temp2_input.dev_attr.attr, | 317 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
322 | &sensor_dev_attr_temp3_input.dev_attr.attr, | 318 | &sensor_dev_attr_temp3_input.dev_attr.attr, |
@@ -329,10 +325,7 @@ static struct attribute *lm95241_attributes[] = { | |||
329 | &dev_attr_update_interval.attr, | 325 | &dev_attr_update_interval.attr, |
330 | NULL | 326 | NULL |
331 | }; | 327 | }; |
332 | 328 | ATTRIBUTE_GROUPS(lm95241); | |
333 | static const struct attribute_group lm95241_group = { | ||
334 | .attrs = lm95241_attributes, | ||
335 | }; | ||
336 | 329 | ||
337 | /* Return 0 if detection is successful, -ENODEV otherwise */ | 330 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
338 | static int lm95241_detect(struct i2c_client *new_client, | 331 | static int lm95241_detect(struct i2c_client *new_client, |
@@ -366,14 +359,11 @@ static int lm95241_detect(struct i2c_client *new_client, | |||
366 | return 0; | 359 | return 0; |
367 | } | 360 | } |
368 | 361 | ||
369 | static void lm95241_init_client(struct i2c_client *client) | 362 | static void lm95241_init_client(struct i2c_client *client, |
363 | struct lm95241_data *data) | ||
370 | { | 364 | { |
371 | struct lm95241_data *data = i2c_get_clientdata(client); | ||
372 | |||
373 | data->interval = HZ; /* 1 sec default */ | 365 | data->interval = HZ; /* 1 sec default */ |
374 | data->valid = 0; | ||
375 | data->config = CFG_CR0076; | 366 | data->config = CFG_CR0076; |
376 | data->model = 0; | ||
377 | data->trutherm = (TT_OFF << TT1_SHIFT) | (TT_OFF << TT2_SHIFT); | 367 | data->trutherm = (TT_OFF << TT1_SHIFT) | (TT_OFF << TT2_SHIFT); |
378 | 368 | ||
379 | i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, data->config); | 369 | i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, data->config); |
@@ -385,49 +375,27 @@ static void lm95241_init_client(struct i2c_client *client) | |||
385 | data->model); | 375 | data->model); |
386 | } | 376 | } |
387 | 377 | ||
388 | static int lm95241_probe(struct i2c_client *new_client, | 378 | static int lm95241_probe(struct i2c_client *client, |
389 | const struct i2c_device_id *id) | 379 | const struct i2c_device_id *id) |
390 | { | 380 | { |
381 | struct device *dev = &client->dev; | ||
391 | struct lm95241_data *data; | 382 | struct lm95241_data *data; |
392 | int err; | 383 | struct device *hwmon_dev; |
393 | 384 | ||
394 | data = devm_kzalloc(&new_client->dev, sizeof(struct lm95241_data), | 385 | data = devm_kzalloc(dev, sizeof(struct lm95241_data), GFP_KERNEL); |
395 | GFP_KERNEL); | ||
396 | if (!data) | 386 | if (!data) |
397 | return -ENOMEM; | 387 | return -ENOMEM; |
398 | 388 | ||
399 | i2c_set_clientdata(new_client, data); | 389 | data->client = client; |
400 | mutex_init(&data->update_lock); | 390 | mutex_init(&data->update_lock); |
401 | 391 | ||
402 | /* Initialize the LM95241 chip */ | 392 | /* Initialize the LM95241 chip */ |
403 | lm95241_init_client(new_client); | 393 | lm95241_init_client(client, data); |
404 | 394 | ||
405 | /* Register sysfs hooks */ | 395 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
406 | err = sysfs_create_group(&new_client->dev.kobj, &lm95241_group); | 396 | data, |
407 | if (err) | 397 | lm95241_groups); |
408 | return err; | 398 | return PTR_ERR_OR_ZERO(hwmon_dev); |
409 | |||
410 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | ||
411 | if (IS_ERR(data->hwmon_dev)) { | ||
412 | err = PTR_ERR(data->hwmon_dev); | ||
413 | goto exit_remove_files; | ||
414 | } | ||
415 | |||
416 | return 0; | ||
417 | |||
418 | exit_remove_files: | ||
419 | sysfs_remove_group(&new_client->dev.kobj, &lm95241_group); | ||
420 | return err; | ||
421 | } | ||
422 | |||
423 | static int lm95241_remove(struct i2c_client *client) | ||
424 | { | ||
425 | struct lm95241_data *data = i2c_get_clientdata(client); | ||
426 | |||
427 | hwmon_device_unregister(data->hwmon_dev); | ||
428 | sysfs_remove_group(&client->dev.kobj, &lm95241_group); | ||
429 | |||
430 | return 0; | ||
431 | } | 399 | } |
432 | 400 | ||
433 | /* Driver data (common to all clients) */ | 401 | /* Driver data (common to all clients) */ |
@@ -444,7 +412,6 @@ static struct i2c_driver lm95241_driver = { | |||
444 | .name = DEVNAME, | 412 | .name = DEVNAME, |
445 | }, | 413 | }, |
446 | .probe = lm95241_probe, | 414 | .probe = lm95241_probe, |
447 | .remove = lm95241_remove, | ||
448 | .id_table = lm95241_id, | 415 | .id_table = lm95241_id, |
449 | .detect = lm95241_detect, | 416 | .detect = lm95241_detect, |
450 | .address_list = normal_i2c, | 417 | .address_list = normal_i2c, |
diff --git a/drivers/hwmon/lm95245.c b/drivers/hwmon/lm95245.c index a6c85f0ff8f3..0ae0dfdafdff 100644 --- a/drivers/hwmon/lm95245.c +++ b/drivers/hwmon/lm95245.c | |||
@@ -115,7 +115,7 @@ static const u8 lm95245_reg_address[] = { | |||
115 | 115 | ||
116 | /* Client data (each client gets its own) */ | 116 | /* Client data (each client gets its own) */ |
117 | struct lm95245_data { | 117 | struct lm95245_data { |
118 | struct device *hwmon_dev; | 118 | struct i2c_client *client; |
119 | struct mutex update_lock; | 119 | struct mutex update_lock; |
120 | unsigned long last_updated; /* in jiffies */ | 120 | unsigned long last_updated; /* in jiffies */ |
121 | unsigned long interval; /* in msecs */ | 121 | unsigned long interval; /* in msecs */ |
@@ -140,8 +140,8 @@ static int temp_from_reg_signed(u8 val_h, u8 val_l) | |||
140 | 140 | ||
141 | static struct lm95245_data *lm95245_update_device(struct device *dev) | 141 | static struct lm95245_data *lm95245_update_device(struct device *dev) |
142 | { | 142 | { |
143 | struct i2c_client *client = to_i2c_client(dev); | 143 | struct lm95245_data *data = dev_get_drvdata(dev); |
144 | struct lm95245_data *data = i2c_get_clientdata(client); | 144 | struct i2c_client *client = data->client; |
145 | 145 | ||
146 | mutex_lock(&data->update_lock); | 146 | mutex_lock(&data->update_lock); |
147 | 147 | ||
@@ -149,7 +149,6 @@ static struct lm95245_data *lm95245_update_device(struct device *dev) | |||
149 | + msecs_to_jiffies(data->interval)) || !data->valid) { | 149 | + msecs_to_jiffies(data->interval)) || !data->valid) { |
150 | int i; | 150 | int i; |
151 | 151 | ||
152 | dev_dbg(&client->dev, "Updating lm95245 data.\n"); | ||
153 | for (i = 0; i < ARRAY_SIZE(lm95245_reg_address); i++) | 152 | for (i = 0; i < ARRAY_SIZE(lm95245_reg_address); i++) |
154 | data->regs[i] | 153 | data->regs[i] |
155 | = i2c_smbus_read_byte_data(client, | 154 | = i2c_smbus_read_byte_data(client, |
@@ -249,9 +248,9 @@ static ssize_t show_limit(struct device *dev, struct device_attribute *attr, | |||
249 | static ssize_t set_limit(struct device *dev, struct device_attribute *attr, | 248 | static ssize_t set_limit(struct device *dev, struct device_attribute *attr, |
250 | const char *buf, size_t count) | 249 | const char *buf, size_t count) |
251 | { | 250 | { |
252 | struct i2c_client *client = to_i2c_client(dev); | 251 | struct lm95245_data *data = dev_get_drvdata(dev); |
253 | struct lm95245_data *data = i2c_get_clientdata(client); | ||
254 | int index = to_sensor_dev_attr(attr)->index; | 252 | int index = to_sensor_dev_attr(attr)->index; |
253 | struct i2c_client *client = data->client; | ||
255 | unsigned long val; | 254 | unsigned long val; |
256 | 255 | ||
257 | if (kstrtoul(buf, 10, &val) < 0) | 256 | if (kstrtoul(buf, 10, &val) < 0) |
@@ -272,27 +271,38 @@ static ssize_t set_limit(struct device *dev, struct device_attribute *attr, | |||
272 | return count; | 271 | return count; |
273 | } | 272 | } |
274 | 273 | ||
274 | static ssize_t show_crit_hyst(struct device *dev, struct device_attribute *attr, | ||
275 | char *buf) | ||
276 | { | ||
277 | struct lm95245_data *data = lm95245_update_device(dev); | ||
278 | int index = to_sensor_dev_attr(attr)->index; | ||
279 | int hyst = data->regs[index] - data->regs[8]; | ||
280 | |||
281 | return snprintf(buf, PAGE_SIZE - 1, "%d\n", hyst * 1000); | ||
282 | } | ||
283 | |||
275 | static ssize_t set_crit_hyst(struct device *dev, struct device_attribute *attr, | 284 | static ssize_t set_crit_hyst(struct device *dev, struct device_attribute *attr, |
276 | const char *buf, size_t count) | 285 | const char *buf, size_t count) |
277 | { | 286 | { |
278 | struct i2c_client *client = to_i2c_client(dev); | 287 | struct lm95245_data *data = dev_get_drvdata(dev); |
279 | struct lm95245_data *data = i2c_get_clientdata(client); | 288 | int index = to_sensor_dev_attr(attr)->index; |
289 | struct i2c_client *client = data->client; | ||
280 | unsigned long val; | 290 | unsigned long val; |
291 | int hyst, limit; | ||
281 | 292 | ||
282 | if (kstrtoul(buf, 10, &val) < 0) | 293 | if (kstrtoul(buf, 10, &val) < 0) |
283 | return -EINVAL; | 294 | return -EINVAL; |
284 | 295 | ||
285 | val /= 1000; | ||
286 | |||
287 | val = clamp_val(val, 0, 31); | ||
288 | |||
289 | mutex_lock(&data->update_lock); | 296 | mutex_lock(&data->update_lock); |
290 | 297 | ||
291 | data->valid = 0; | 298 | limit = i2c_smbus_read_byte_data(client, lm95245_reg_address[index]); |
299 | hyst = limit - val / 1000; | ||
300 | hyst = clamp_val(hyst, 0, 31); | ||
301 | data->regs[8] = hyst; | ||
292 | 302 | ||
293 | /* shared crit hysteresis */ | 303 | /* shared crit hysteresis */ |
294 | i2c_smbus_write_byte_data(client, LM95245_REG_RW_COMMON_HYSTERESIS, | 304 | i2c_smbus_write_byte_data(client, LM95245_REG_RW_COMMON_HYSTERESIS, |
295 | val); | 305 | hyst); |
296 | 306 | ||
297 | mutex_unlock(&data->update_lock); | 307 | mutex_unlock(&data->update_lock); |
298 | 308 | ||
@@ -302,8 +312,7 @@ static ssize_t set_crit_hyst(struct device *dev, struct device_attribute *attr, | |||
302 | static ssize_t show_type(struct device *dev, struct device_attribute *attr, | 312 | static ssize_t show_type(struct device *dev, struct device_attribute *attr, |
303 | char *buf) | 313 | char *buf) |
304 | { | 314 | { |
305 | struct i2c_client *client = to_i2c_client(dev); | 315 | struct lm95245_data *data = dev_get_drvdata(dev); |
306 | struct lm95245_data *data = i2c_get_clientdata(client); | ||
307 | 316 | ||
308 | return snprintf(buf, PAGE_SIZE - 1, | 317 | return snprintf(buf, PAGE_SIZE - 1, |
309 | data->config2 & CFG2_REMOTE_TT ? "1\n" : "2\n"); | 318 | data->config2 & CFG2_REMOTE_TT ? "1\n" : "2\n"); |
@@ -312,8 +321,8 @@ static ssize_t show_type(struct device *dev, struct device_attribute *attr, | |||
312 | static ssize_t set_type(struct device *dev, struct device_attribute *attr, | 321 | static ssize_t set_type(struct device *dev, struct device_attribute *attr, |
313 | const char *buf, size_t count) | 322 | const char *buf, size_t count) |
314 | { | 323 | { |
315 | struct i2c_client *client = to_i2c_client(dev); | 324 | struct lm95245_data *data = dev_get_drvdata(dev); |
316 | struct lm95245_data *data = i2c_get_clientdata(client); | 325 | struct i2c_client *client = data->client; |
317 | unsigned long val; | 326 | unsigned long val; |
318 | 327 | ||
319 | if (kstrtoul(buf, 10, &val) < 0) | 328 | if (kstrtoul(buf, 10, &val) < 0) |
@@ -359,8 +368,8 @@ static ssize_t show_interval(struct device *dev, struct device_attribute *attr, | |||
359 | static ssize_t set_interval(struct device *dev, struct device_attribute *attr, | 368 | static ssize_t set_interval(struct device *dev, struct device_attribute *attr, |
360 | const char *buf, size_t count) | 369 | const char *buf, size_t count) |
361 | { | 370 | { |
362 | struct i2c_client *client = to_i2c_client(dev); | 371 | struct lm95245_data *data = dev_get_drvdata(dev); |
363 | struct lm95245_data *data = i2c_get_clientdata(client); | 372 | struct i2c_client *client = data->client; |
364 | unsigned long val; | 373 | unsigned long val; |
365 | 374 | ||
366 | if (kstrtoul(buf, 10, &val) < 0) | 375 | if (kstrtoul(buf, 10, &val) < 0) |
@@ -378,16 +387,15 @@ static ssize_t set_interval(struct device *dev, struct device_attribute *attr, | |||
378 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_input, NULL, 0); | 387 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_input, NULL, 0); |
379 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_limit, | 388 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_limit, |
380 | set_limit, 6); | 389 | set_limit, 6); |
381 | static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_limit, | 390 | static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_crit_hyst, |
382 | set_crit_hyst, 8); | 391 | set_crit_hyst, 6); |
383 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, | 392 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, |
384 | STATUS1_LOC); | 393 | STATUS1_LOC); |
385 | 394 | ||
386 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_input, NULL, 2); | 395 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_input, NULL, 2); |
387 | static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_limit, | 396 | static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_limit, |
388 | set_limit, 7); | 397 | set_limit, 7); |
389 | static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_limit, | 398 | static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_crit_hyst, NULL, 7); |
390 | set_crit_hyst, 8); | ||
391 | static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, | 399 | static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, |
392 | STATUS1_RTCRIT); | 400 | STATUS1_RTCRIT); |
393 | static SENSOR_DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type, | 401 | static SENSOR_DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type, |
@@ -398,7 +406,7 @@ static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, | |||
398 | static DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, show_interval, | 406 | static DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, show_interval, |
399 | set_interval); | 407 | set_interval); |
400 | 408 | ||
401 | static struct attribute *lm95245_attributes[] = { | 409 | static struct attribute *lm95245_attrs[] = { |
402 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 410 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
403 | &sensor_dev_attr_temp1_crit.dev_attr.attr, | 411 | &sensor_dev_attr_temp1_crit.dev_attr.attr, |
404 | &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr, | 412 | &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr, |
@@ -412,10 +420,7 @@ static struct attribute *lm95245_attributes[] = { | |||
412 | &dev_attr_update_interval.attr, | 420 | &dev_attr_update_interval.attr, |
413 | NULL | 421 | NULL |
414 | }; | 422 | }; |
415 | 423 | ATTRIBUTE_GROUPS(lm95245); | |
416 | static const struct attribute_group lm95245_group = { | ||
417 | .attrs = lm95245_attributes, | ||
418 | }; | ||
419 | 424 | ||
420 | /* Return 0 if detection is successful, -ENODEV otherwise */ | 425 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
421 | static int lm95245_detect(struct i2c_client *new_client, | 426 | static int lm95245_detect(struct i2c_client *new_client, |
@@ -436,11 +441,9 @@ static int lm95245_detect(struct i2c_client *new_client, | |||
436 | return 0; | 441 | return 0; |
437 | } | 442 | } |
438 | 443 | ||
439 | static void lm95245_init_client(struct i2c_client *client) | 444 | static void lm95245_init_client(struct i2c_client *client, |
445 | struct lm95245_data *data) | ||
440 | { | 446 | { |
441 | struct lm95245_data *data = i2c_get_clientdata(client); | ||
442 | |||
443 | data->valid = 0; | ||
444 | data->interval = lm95245_read_conversion_rate(client); | 447 | data->interval = lm95245_read_conversion_rate(client); |
445 | 448 | ||
446 | data->config1 = i2c_smbus_read_byte_data(client, | 449 | data->config1 = i2c_smbus_read_byte_data(client, |
@@ -456,49 +459,27 @@ static void lm95245_init_client(struct i2c_client *client) | |||
456 | } | 459 | } |
457 | } | 460 | } |
458 | 461 | ||
459 | static int lm95245_probe(struct i2c_client *new_client, | 462 | static int lm95245_probe(struct i2c_client *client, |
460 | const struct i2c_device_id *id) | 463 | const struct i2c_device_id *id) |
461 | { | 464 | { |
465 | struct device *dev = &client->dev; | ||
462 | struct lm95245_data *data; | 466 | struct lm95245_data *data; |
463 | int err; | 467 | struct device *hwmon_dev; |
464 | 468 | ||
465 | data = devm_kzalloc(&new_client->dev, sizeof(struct lm95245_data), | 469 | data = devm_kzalloc(dev, sizeof(struct lm95245_data), GFP_KERNEL); |
466 | GFP_KERNEL); | ||
467 | if (!data) | 470 | if (!data) |
468 | return -ENOMEM; | 471 | return -ENOMEM; |
469 | 472 | ||
470 | i2c_set_clientdata(new_client, data); | 473 | data->client = client; |
471 | mutex_init(&data->update_lock); | 474 | mutex_init(&data->update_lock); |
472 | 475 | ||
473 | /* Initialize the LM95245 chip */ | 476 | /* Initialize the LM95245 chip */ |
474 | lm95245_init_client(new_client); | 477 | lm95245_init_client(client, data); |
475 | |||
476 | /* Register sysfs hooks */ | ||
477 | err = sysfs_create_group(&new_client->dev.kobj, &lm95245_group); | ||
478 | if (err) | ||
479 | return err; | ||
480 | |||
481 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | ||
482 | if (IS_ERR(data->hwmon_dev)) { | ||
483 | err = PTR_ERR(data->hwmon_dev); | ||
484 | goto exit_remove_files; | ||
485 | } | ||
486 | |||
487 | return 0; | ||
488 | |||
489 | exit_remove_files: | ||
490 | sysfs_remove_group(&new_client->dev.kobj, &lm95245_group); | ||
491 | return err; | ||
492 | } | ||
493 | 478 | ||
494 | static int lm95245_remove(struct i2c_client *client) | 479 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
495 | { | 480 | data, |
496 | struct lm95245_data *data = i2c_get_clientdata(client); | 481 | lm95245_groups); |
497 | 482 | return PTR_ERR_OR_ZERO(hwmon_dev); | |
498 | hwmon_device_unregister(data->hwmon_dev); | ||
499 | sysfs_remove_group(&client->dev.kobj, &lm95245_group); | ||
500 | |||
501 | return 0; | ||
502 | } | 483 | } |
503 | 484 | ||
504 | /* Driver data (common to all clients) */ | 485 | /* Driver data (common to all clients) */ |
@@ -514,7 +495,6 @@ static struct i2c_driver lm95245_driver = { | |||
514 | .name = DEVNAME, | 495 | .name = DEVNAME, |
515 | }, | 496 | }, |
516 | .probe = lm95245_probe, | 497 | .probe = lm95245_probe, |
517 | .remove = lm95245_remove, | ||
518 | .id_table = lm95245_id, | 498 | .id_table = lm95245_id, |
519 | .detect = lm95245_detect, | 499 | .detect = lm95245_detect, |
520 | .address_list = normal_i2c, | 500 | .address_list = normal_i2c, |
diff --git a/drivers/hwmon/ltc2945.c b/drivers/hwmon/ltc2945.c new file mode 100644 index 000000000000..c104cc32989d --- /dev/null +++ b/drivers/hwmon/ltc2945.c | |||
@@ -0,0 +1,519 @@ | |||
1 | /* | ||
2 | * Driver for Linear Technology LTC2945 I2C Power Monitor | ||
3 | * | ||
4 | * Copyright (c) 2014 Guenter Roeck | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | */ | ||
16 | |||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/err.h> | ||
20 | #include <linux/slab.h> | ||
21 | #include <linux/i2c.h> | ||
22 | #include <linux/hwmon.h> | ||
23 | #include <linux/hwmon-sysfs.h> | ||
24 | #include <linux/jiffies.h> | ||
25 | #include <linux/regmap.h> | ||
26 | |||
27 | /* chip registers */ | ||
28 | #define LTC2945_CONTROL 0x00 | ||
29 | #define LTC2945_ALERT 0x01 | ||
30 | #define LTC2945_STATUS 0x02 | ||
31 | #define LTC2945_FAULT 0x03 | ||
32 | #define LTC2945_POWER_H 0x05 | ||
33 | #define LTC2945_MAX_POWER_H 0x08 | ||
34 | #define LTC2945_MIN_POWER_H 0x0b | ||
35 | #define LTC2945_MAX_POWER_THRES_H 0x0e | ||
36 | #define LTC2945_MIN_POWER_THRES_H 0x11 | ||
37 | #define LTC2945_SENSE_H 0x14 | ||
38 | #define LTC2945_MAX_SENSE_H 0x16 | ||
39 | #define LTC2945_MIN_SENSE_H 0x18 | ||
40 | #define LTC2945_MAX_SENSE_THRES_H 0x1a | ||
41 | #define LTC2945_MIN_SENSE_THRES_H 0x1c | ||
42 | #define LTC2945_VIN_H 0x1e | ||
43 | #define LTC2945_MAX_VIN_H 0x20 | ||
44 | #define LTC2945_MIN_VIN_H 0x22 | ||
45 | #define LTC2945_MAX_VIN_THRES_H 0x24 | ||
46 | #define LTC2945_MIN_VIN_THRES_H 0x26 | ||
47 | #define LTC2945_ADIN_H 0x28 | ||
48 | #define LTC2945_MAX_ADIN_H 0x2a | ||
49 | #define LTC2945_MIN_ADIN_H 0x2c | ||
50 | #define LTC2945_MAX_ADIN_THRES_H 0x2e | ||
51 | #define LTC2945_MIN_ADIN_THRES_H 0x30 | ||
52 | #define LTC2945_MIN_ADIN_THRES_L 0x31 | ||
53 | |||
54 | /* Fault register bits */ | ||
55 | |||
56 | #define FAULT_ADIN_UV (1 << 0) | ||
57 | #define FAULT_ADIN_OV (1 << 1) | ||
58 | #define FAULT_VIN_UV (1 << 2) | ||
59 | #define FAULT_VIN_OV (1 << 3) | ||
60 | #define FAULT_SENSE_UV (1 << 4) | ||
61 | #define FAULT_SENSE_OV (1 << 5) | ||
62 | #define FAULT_POWER_UV (1 << 6) | ||
63 | #define FAULT_POWER_OV (1 << 7) | ||
64 | |||
65 | /* Control register bits */ | ||
66 | |||
67 | #define CONTROL_MULT_SELECT (1 << 0) | ||
68 | #define CONTROL_TEST_MODE (1 << 4) | ||
69 | |||
70 | static inline bool is_power_reg(u8 reg) | ||
71 | { | ||
72 | return reg < LTC2945_SENSE_H; | ||
73 | } | ||
74 | |||
75 | /* Return the value from the given register in uW, mV, or mA */ | ||
76 | static long long ltc2945_reg_to_val(struct device *dev, u8 reg) | ||
77 | { | ||
78 | struct regmap *regmap = dev_get_drvdata(dev); | ||
79 | unsigned int control; | ||
80 | u8 buf[3]; | ||
81 | long long val; | ||
82 | int ret; | ||
83 | |||
84 | ret = regmap_bulk_read(regmap, reg, buf, | ||
85 | is_power_reg(reg) ? 3 : 2); | ||
86 | if (ret < 0) | ||
87 | return ret; | ||
88 | |||
89 | if (is_power_reg(reg)) { | ||
90 | /* power */ | ||
91 | val = (buf[0] << 16) + (buf[1] << 8) + buf[2]; | ||
92 | } else { | ||
93 | /* current, voltage */ | ||
94 | val = (buf[0] << 4) + (buf[1] >> 4); | ||
95 | } | ||
96 | |||
97 | switch (reg) { | ||
98 | case LTC2945_POWER_H: | ||
99 | case LTC2945_MAX_POWER_H: | ||
100 | case LTC2945_MIN_POWER_H: | ||
101 | case LTC2945_MAX_POWER_THRES_H: | ||
102 | case LTC2945_MIN_POWER_THRES_H: | ||
103 | /* | ||
104 | * Convert to uW by assuming current is measured with | ||
105 | * an 1mOhm sense resistor, similar to current | ||
106 | * measurements. | ||
107 | * Control register bit 0 selects if voltage at SENSE+/VDD | ||
108 | * or voltage at ADIN is used to measure power. | ||
109 | */ | ||
110 | ret = regmap_read(regmap, LTC2945_CONTROL, &control); | ||
111 | if (ret < 0) | ||
112 | return ret; | ||
113 | if (control & CONTROL_MULT_SELECT) { | ||
114 | /* 25 mV * 25 uV = 0.625 uV resolution. */ | ||
115 | val *= 625LL; | ||
116 | } else { | ||
117 | /* 0.5 mV * 25 uV = 0.0125 uV resolution. */ | ||
118 | val = (val * 25LL) >> 1; | ||
119 | } | ||
120 | break; | ||
121 | case LTC2945_VIN_H: | ||
122 | case LTC2945_MAX_VIN_H: | ||
123 | case LTC2945_MIN_VIN_H: | ||
124 | case LTC2945_MAX_VIN_THRES_H: | ||
125 | case LTC2945_MIN_VIN_THRES_H: | ||
126 | /* 25 mV resolution. Convert to mV. */ | ||
127 | val *= 25; | ||
128 | break; | ||
129 | case LTC2945_ADIN_H: | ||
130 | case LTC2945_MAX_ADIN_H: | ||
131 | case LTC2945_MIN_ADIN_THRES_H: | ||
132 | case LTC2945_MAX_ADIN_THRES_H: | ||
133 | case LTC2945_MIN_ADIN_H: | ||
134 | /* 0.5mV resolution. Convert to mV. */ | ||
135 | val = val >> 1; | ||
136 | break; | ||
137 | case LTC2945_SENSE_H: | ||
138 | case LTC2945_MAX_SENSE_H: | ||
139 | case LTC2945_MIN_SENSE_H: | ||
140 | case LTC2945_MAX_SENSE_THRES_H: | ||
141 | case LTC2945_MIN_SENSE_THRES_H: | ||
142 | /* | ||
143 | * 25 uV resolution. Convert to current as measured with | ||
144 | * an 1 mOhm sense resistor, in mA. If a different sense | ||
145 | * resistor is installed, calculate the actual current by | ||
146 | * dividing the reported current by the sense resistor value | ||
147 | * in mOhm. | ||
148 | */ | ||
149 | val *= 25; | ||
150 | break; | ||
151 | default: | ||
152 | return -EINVAL; | ||
153 | } | ||
154 | return val; | ||
155 | } | ||
156 | |||
157 | static int ltc2945_val_to_reg(struct device *dev, u8 reg, | ||
158 | unsigned long val) | ||
159 | { | ||
160 | struct regmap *regmap = dev_get_drvdata(dev); | ||
161 | unsigned int control; | ||
162 | int ret; | ||
163 | |||
164 | switch (reg) { | ||
165 | case LTC2945_POWER_H: | ||
166 | case LTC2945_MAX_POWER_H: | ||
167 | case LTC2945_MIN_POWER_H: | ||
168 | case LTC2945_MAX_POWER_THRES_H: | ||
169 | case LTC2945_MIN_POWER_THRES_H: | ||
170 | /* | ||
171 | * Convert to register value by assuming current is measured | ||
172 | * with an 1mOhm sense resistor, similar to current | ||
173 | * measurements. | ||
174 | * Control register bit 0 selects if voltage at SENSE+/VDD | ||
175 | * or voltage at ADIN is used to measure power, which in turn | ||
176 | * determines register calculations. | ||
177 | */ | ||
178 | ret = regmap_read(regmap, LTC2945_CONTROL, &control); | ||
179 | if (ret < 0) | ||
180 | return ret; | ||
181 | if (control & CONTROL_MULT_SELECT) { | ||
182 | /* 25 mV * 25 uV = 0.625 uV resolution. */ | ||
183 | val = DIV_ROUND_CLOSEST(val, 625); | ||
184 | } else { | ||
185 | /* | ||
186 | * 0.5 mV * 25 uV = 0.0125 uV resolution. | ||
187 | * Divide first to avoid overflow; | ||
188 | * accept loss of accuracy. | ||
189 | */ | ||
190 | val = DIV_ROUND_CLOSEST(val, 25) * 2; | ||
191 | } | ||
192 | break; | ||
193 | case LTC2945_VIN_H: | ||
194 | case LTC2945_MAX_VIN_H: | ||
195 | case LTC2945_MIN_VIN_H: | ||
196 | case LTC2945_MAX_VIN_THRES_H: | ||
197 | case LTC2945_MIN_VIN_THRES_H: | ||
198 | /* 25 mV resolution. */ | ||
199 | val /= 25; | ||
200 | break; | ||
201 | case LTC2945_ADIN_H: | ||
202 | case LTC2945_MAX_ADIN_H: | ||
203 | case LTC2945_MIN_ADIN_THRES_H: | ||
204 | case LTC2945_MAX_ADIN_THRES_H: | ||
205 | case LTC2945_MIN_ADIN_H: | ||
206 | /* 0.5mV resolution. */ | ||
207 | val *= 2; | ||
208 | break; | ||
209 | case LTC2945_SENSE_H: | ||
210 | case LTC2945_MAX_SENSE_H: | ||
211 | case LTC2945_MIN_SENSE_H: | ||
212 | case LTC2945_MAX_SENSE_THRES_H: | ||
213 | case LTC2945_MIN_SENSE_THRES_H: | ||
214 | /* | ||
215 | * 25 uV resolution. Convert to current as measured with | ||
216 | * an 1 mOhm sense resistor, in mA. If a different sense | ||
217 | * resistor is installed, calculate the actual current by | ||
218 | * dividing the reported current by the sense resistor value | ||
219 | * in mOhm. | ||
220 | */ | ||
221 | val = DIV_ROUND_CLOSEST(val, 25); | ||
222 | break; | ||
223 | default: | ||
224 | return -EINVAL; | ||
225 | } | ||
226 | return val; | ||
227 | } | ||
228 | |||
229 | static ssize_t ltc2945_show_value(struct device *dev, | ||
230 | struct device_attribute *da, char *buf) | ||
231 | { | ||
232 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
233 | long long value; | ||
234 | |||
235 | value = ltc2945_reg_to_val(dev, attr->index); | ||
236 | if (value < 0) | ||
237 | return value; | ||
238 | return snprintf(buf, PAGE_SIZE, "%lld\n", value); | ||
239 | } | ||
240 | |||
241 | static ssize_t ltc2945_set_value(struct device *dev, | ||
242 | struct device_attribute *da, | ||
243 | const char *buf, size_t count) | ||
244 | { | ||
245 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
246 | struct regmap *regmap = dev_get_drvdata(dev); | ||
247 | u8 reg = attr->index; | ||
248 | unsigned long val; | ||
249 | u8 regbuf[3]; | ||
250 | int num_regs; | ||
251 | int regval; | ||
252 | int ret; | ||
253 | |||
254 | ret = kstrtoul(buf, 10, &val); | ||
255 | if (ret) | ||
256 | return ret; | ||
257 | |||
258 | /* convert to register value, then clamp and write result */ | ||
259 | regval = ltc2945_val_to_reg(dev, reg, val); | ||
260 | if (is_power_reg(reg)) { | ||
261 | regval = clamp_val(regval, 0, 0xffffff); | ||
262 | regbuf[0] = regval >> 16; | ||
263 | regbuf[1] = (regval >> 8) & 0xff; | ||
264 | regbuf[2] = regval; | ||
265 | num_regs = 3; | ||
266 | } else { | ||
267 | regval = clamp_val(regval, 0, 0xfff) << 4; | ||
268 | regbuf[0] = regval >> 8; | ||
269 | regbuf[1] = regval & 0xff; | ||
270 | num_regs = 2; | ||
271 | } | ||
272 | ret = regmap_bulk_write(regmap, reg, regbuf, num_regs); | ||
273 | return ret < 0 ? ret : count; | ||
274 | } | ||
275 | |||
276 | static ssize_t ltc2945_reset_history(struct device *dev, | ||
277 | struct device_attribute *da, | ||
278 | const char *buf, size_t count) | ||
279 | { | ||
280 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
281 | struct regmap *regmap = dev_get_drvdata(dev); | ||
282 | u8 reg = attr->index; | ||
283 | int num_regs = is_power_reg(reg) ? 3 : 2; | ||
284 | u8 buf_min[3] = { 0xff, 0xff, 0xff }; | ||
285 | u8 buf_max[3] = { 0, 0, 0 }; | ||
286 | unsigned long val; | ||
287 | int ret; | ||
288 | |||
289 | ret = kstrtoul(buf, 10, &val); | ||
290 | if (ret) | ||
291 | return ret; | ||
292 | if (val != 1) | ||
293 | return -EINVAL; | ||
294 | |||
295 | ret = regmap_update_bits(regmap, LTC2945_CONTROL, CONTROL_TEST_MODE, | ||
296 | CONTROL_TEST_MODE); | ||
297 | |||
298 | /* Reset minimum */ | ||
299 | ret = regmap_bulk_write(regmap, reg, buf_min, num_regs); | ||
300 | if (ret) | ||
301 | return ret; | ||
302 | |||
303 | switch (reg) { | ||
304 | case LTC2945_MIN_POWER_H: | ||
305 | reg = LTC2945_MAX_POWER_H; | ||
306 | break; | ||
307 | case LTC2945_MIN_SENSE_H: | ||
308 | reg = LTC2945_MAX_SENSE_H; | ||
309 | break; | ||
310 | case LTC2945_MIN_VIN_H: | ||
311 | reg = LTC2945_MAX_VIN_H; | ||
312 | break; | ||
313 | case LTC2945_MIN_ADIN_H: | ||
314 | reg = LTC2945_MAX_ADIN_H; | ||
315 | break; | ||
316 | default: | ||
317 | BUG(); | ||
318 | break; | ||
319 | } | ||
320 | /* Reset maximum */ | ||
321 | ret = regmap_bulk_write(regmap, reg, buf_max, num_regs); | ||
322 | |||
323 | /* Try resetting test mode even if there was an error */ | ||
324 | regmap_update_bits(regmap, LTC2945_CONTROL, CONTROL_TEST_MODE, 0); | ||
325 | |||
326 | return ret ? : count; | ||
327 | } | ||
328 | |||
329 | static ssize_t ltc2945_show_bool(struct device *dev, | ||
330 | struct device_attribute *da, char *buf) | ||
331 | { | ||
332 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
333 | struct regmap *regmap = dev_get_drvdata(dev); | ||
334 | unsigned int fault; | ||
335 | int ret; | ||
336 | |||
337 | ret = regmap_read(regmap, LTC2945_FAULT, &fault); | ||
338 | if (ret < 0) | ||
339 | return ret; | ||
340 | |||
341 | fault &= attr->index; | ||
342 | if (fault) /* Clear reported faults in chip register */ | ||
343 | regmap_update_bits(regmap, LTC2945_FAULT, attr->index, 0); | ||
344 | |||
345 | return snprintf(buf, PAGE_SIZE, "%d\n", !!fault); | ||
346 | } | ||
347 | |||
348 | /* Input voltages */ | ||
349 | |||
350 | static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, ltc2945_show_value, NULL, | ||
351 | LTC2945_VIN_H); | ||
352 | static SENSOR_DEVICE_ATTR(in1_min, S_IRUGO | S_IWUSR, ltc2945_show_value, | ||
353 | ltc2945_set_value, LTC2945_MIN_VIN_THRES_H); | ||
354 | static SENSOR_DEVICE_ATTR(in1_max, S_IRUGO | S_IWUSR, ltc2945_show_value, | ||
355 | ltc2945_set_value, LTC2945_MAX_VIN_THRES_H); | ||
356 | static SENSOR_DEVICE_ATTR(in1_lowest, S_IRUGO, ltc2945_show_value, NULL, | ||
357 | LTC2945_MIN_VIN_H); | ||
358 | static SENSOR_DEVICE_ATTR(in1_highest, S_IRUGO, ltc2945_show_value, NULL, | ||
359 | LTC2945_MAX_VIN_H); | ||
360 | static SENSOR_DEVICE_ATTR(in1_reset_history, S_IWUSR, NULL, | ||
361 | ltc2945_reset_history, LTC2945_MIN_VIN_H); | ||
362 | |||
363 | static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, ltc2945_show_value, NULL, | ||
364 | LTC2945_ADIN_H); | ||
365 | static SENSOR_DEVICE_ATTR(in2_min, S_IRUGO | S_IWUSR, ltc2945_show_value, | ||
366 | ltc2945_set_value, LTC2945_MIN_ADIN_THRES_H); | ||
367 | static SENSOR_DEVICE_ATTR(in2_max, S_IRUGO | S_IWUSR, ltc2945_show_value, | ||
368 | ltc2945_set_value, LTC2945_MAX_ADIN_THRES_H); | ||
369 | static SENSOR_DEVICE_ATTR(in2_lowest, S_IRUGO, ltc2945_show_value, NULL, | ||
370 | LTC2945_MIN_ADIN_H); | ||
371 | static SENSOR_DEVICE_ATTR(in2_highest, S_IRUGO, ltc2945_show_value, NULL, | ||
372 | LTC2945_MAX_ADIN_H); | ||
373 | static SENSOR_DEVICE_ATTR(in2_reset_history, S_IWUSR, NULL, | ||
374 | ltc2945_reset_history, LTC2945_MIN_ADIN_H); | ||
375 | |||
376 | /* Voltage alarms */ | ||
377 | |||
378 | static SENSOR_DEVICE_ATTR(in1_min_alarm, S_IRUGO, ltc2945_show_bool, NULL, | ||
379 | FAULT_VIN_UV); | ||
380 | static SENSOR_DEVICE_ATTR(in1_max_alarm, S_IRUGO, ltc2945_show_bool, NULL, | ||
381 | FAULT_VIN_OV); | ||
382 | static SENSOR_DEVICE_ATTR(in2_min_alarm, S_IRUGO, ltc2945_show_bool, NULL, | ||
383 | FAULT_ADIN_UV); | ||
384 | static SENSOR_DEVICE_ATTR(in2_max_alarm, S_IRUGO, ltc2945_show_bool, NULL, | ||
385 | FAULT_ADIN_OV); | ||
386 | |||
387 | /* Currents (via sense resistor) */ | ||
388 | |||
389 | static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, ltc2945_show_value, NULL, | ||
390 | LTC2945_SENSE_H); | ||
391 | static SENSOR_DEVICE_ATTR(curr1_min, S_IRUGO | S_IWUSR, ltc2945_show_value, | ||
392 | ltc2945_set_value, LTC2945_MIN_SENSE_THRES_H); | ||
393 | static SENSOR_DEVICE_ATTR(curr1_max, S_IRUGO | S_IWUSR, ltc2945_show_value, | ||
394 | ltc2945_set_value, LTC2945_MAX_SENSE_THRES_H); | ||
395 | static SENSOR_DEVICE_ATTR(curr1_lowest, S_IRUGO, ltc2945_show_value, NULL, | ||
396 | LTC2945_MIN_SENSE_H); | ||
397 | static SENSOR_DEVICE_ATTR(curr1_highest, S_IRUGO, ltc2945_show_value, NULL, | ||
398 | LTC2945_MAX_SENSE_H); | ||
399 | static SENSOR_DEVICE_ATTR(curr1_reset_history, S_IWUSR, NULL, | ||
400 | ltc2945_reset_history, LTC2945_MIN_SENSE_H); | ||
401 | |||
402 | /* Current alarms */ | ||
403 | |||
404 | static SENSOR_DEVICE_ATTR(curr1_min_alarm, S_IRUGO, ltc2945_show_bool, NULL, | ||
405 | FAULT_SENSE_UV); | ||
406 | static SENSOR_DEVICE_ATTR(curr1_max_alarm, S_IRUGO, ltc2945_show_bool, NULL, | ||
407 | FAULT_SENSE_OV); | ||
408 | |||
409 | /* Power */ | ||
410 | |||
411 | static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO, ltc2945_show_value, NULL, | ||
412 | LTC2945_POWER_H); | ||
413 | static SENSOR_DEVICE_ATTR(power1_min, S_IRUGO | S_IWUSR, ltc2945_show_value, | ||
414 | ltc2945_set_value, LTC2945_MIN_POWER_THRES_H); | ||
415 | static SENSOR_DEVICE_ATTR(power1_max, S_IRUGO | S_IWUSR, ltc2945_show_value, | ||
416 | ltc2945_set_value, LTC2945_MAX_POWER_THRES_H); | ||
417 | static SENSOR_DEVICE_ATTR(power1_input_lowest, S_IRUGO, ltc2945_show_value, | ||
418 | NULL, LTC2945_MIN_POWER_H); | ||
419 | static SENSOR_DEVICE_ATTR(power1_input_highest, S_IRUGO, ltc2945_show_value, | ||
420 | NULL, LTC2945_MAX_POWER_H); | ||
421 | static SENSOR_DEVICE_ATTR(power1_reset_history, S_IWUSR, NULL, | ||
422 | ltc2945_reset_history, LTC2945_MIN_POWER_H); | ||
423 | |||
424 | /* Power alarms */ | ||
425 | |||
426 | static SENSOR_DEVICE_ATTR(power1_min_alarm, S_IRUGO, ltc2945_show_bool, NULL, | ||
427 | FAULT_POWER_UV); | ||
428 | static SENSOR_DEVICE_ATTR(power1_max_alarm, S_IRUGO, ltc2945_show_bool, NULL, | ||
429 | FAULT_POWER_OV); | ||
430 | |||
431 | static struct attribute *ltc2945_attrs[] = { | ||
432 | &sensor_dev_attr_in1_input.dev_attr.attr, | ||
433 | &sensor_dev_attr_in1_min.dev_attr.attr, | ||
434 | &sensor_dev_attr_in1_max.dev_attr.attr, | ||
435 | &sensor_dev_attr_in1_lowest.dev_attr.attr, | ||
436 | &sensor_dev_attr_in1_highest.dev_attr.attr, | ||
437 | &sensor_dev_attr_in1_reset_history.dev_attr.attr, | ||
438 | &sensor_dev_attr_in1_min_alarm.dev_attr.attr, | ||
439 | &sensor_dev_attr_in1_max_alarm.dev_attr.attr, | ||
440 | |||
441 | &sensor_dev_attr_in2_input.dev_attr.attr, | ||
442 | &sensor_dev_attr_in2_min.dev_attr.attr, | ||
443 | &sensor_dev_attr_in2_max.dev_attr.attr, | ||
444 | &sensor_dev_attr_in2_lowest.dev_attr.attr, | ||
445 | &sensor_dev_attr_in2_highest.dev_attr.attr, | ||
446 | &sensor_dev_attr_in2_reset_history.dev_attr.attr, | ||
447 | &sensor_dev_attr_in2_min_alarm.dev_attr.attr, | ||
448 | &sensor_dev_attr_in2_max_alarm.dev_attr.attr, | ||
449 | |||
450 | &sensor_dev_attr_curr1_input.dev_attr.attr, | ||
451 | &sensor_dev_attr_curr1_min.dev_attr.attr, | ||
452 | &sensor_dev_attr_curr1_max.dev_attr.attr, | ||
453 | &sensor_dev_attr_curr1_lowest.dev_attr.attr, | ||
454 | &sensor_dev_attr_curr1_highest.dev_attr.attr, | ||
455 | &sensor_dev_attr_curr1_reset_history.dev_attr.attr, | ||
456 | &sensor_dev_attr_curr1_min_alarm.dev_attr.attr, | ||
457 | &sensor_dev_attr_curr1_max_alarm.dev_attr.attr, | ||
458 | |||
459 | &sensor_dev_attr_power1_input.dev_attr.attr, | ||
460 | &sensor_dev_attr_power1_min.dev_attr.attr, | ||
461 | &sensor_dev_attr_power1_max.dev_attr.attr, | ||
462 | &sensor_dev_attr_power1_input_lowest.dev_attr.attr, | ||
463 | &sensor_dev_attr_power1_input_highest.dev_attr.attr, | ||
464 | &sensor_dev_attr_power1_reset_history.dev_attr.attr, | ||
465 | &sensor_dev_attr_power1_min_alarm.dev_attr.attr, | ||
466 | &sensor_dev_attr_power1_max_alarm.dev_attr.attr, | ||
467 | |||
468 | NULL, | ||
469 | }; | ||
470 | ATTRIBUTE_GROUPS(ltc2945); | ||
471 | |||
472 | static struct regmap_config ltc2945_regmap_config = { | ||
473 | .reg_bits = 8, | ||
474 | .val_bits = 8, | ||
475 | .max_register = LTC2945_MIN_ADIN_THRES_L, | ||
476 | }; | ||
477 | |||
478 | static int ltc2945_probe(struct i2c_client *client, | ||
479 | const struct i2c_device_id *id) | ||
480 | { | ||
481 | struct device *dev = &client->dev; | ||
482 | struct device *hwmon_dev; | ||
483 | struct regmap *regmap; | ||
484 | |||
485 | regmap = devm_regmap_init_i2c(client, <c2945_regmap_config); | ||
486 | if (IS_ERR(regmap)) { | ||
487 | dev_err(dev, "failed to allocate register map\n"); | ||
488 | return PTR_ERR(regmap); | ||
489 | } | ||
490 | |||
491 | /* Clear faults */ | ||
492 | regmap_write(regmap, LTC2945_FAULT, 0x00); | ||
493 | |||
494 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, | ||
495 | regmap, | ||
496 | ltc2945_groups); | ||
497 | return PTR_ERR_OR_ZERO(hwmon_dev); | ||
498 | } | ||
499 | |||
500 | static const struct i2c_device_id ltc2945_id[] = { | ||
501 | {"ltc2945", 0}, | ||
502 | { } | ||
503 | }; | ||
504 | |||
505 | MODULE_DEVICE_TABLE(i2c, ltc2945_id); | ||
506 | |||
507 | static struct i2c_driver ltc2945_driver = { | ||
508 | .driver = { | ||
509 | .name = "ltc2945", | ||
510 | }, | ||
511 | .probe = ltc2945_probe, | ||
512 | .id_table = ltc2945_id, | ||
513 | }; | ||
514 | |||
515 | module_i2c_driver(ltc2945_driver); | ||
516 | |||
517 | MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>"); | ||
518 | MODULE_DESCRIPTION("LTC2945 driver"); | ||
519 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/hwmon/ltc4215.c b/drivers/hwmon/ltc4215.c index 8a142960d69e..c8a9bd9b050f 100644 --- a/drivers/hwmon/ltc4215.c +++ b/drivers/hwmon/ltc4215.c | |||
@@ -33,7 +33,7 @@ enum ltc4215_cmd { | |||
33 | }; | 33 | }; |
34 | 34 | ||
35 | struct ltc4215_data { | 35 | struct ltc4215_data { |
36 | struct device *hwmon_dev; | 36 | struct i2c_client *client; |
37 | 37 | ||
38 | struct mutex update_lock; | 38 | struct mutex update_lock; |
39 | bool valid; | 39 | bool valid; |
@@ -45,8 +45,8 @@ struct ltc4215_data { | |||
45 | 45 | ||
46 | static struct ltc4215_data *ltc4215_update_device(struct device *dev) | 46 | static struct ltc4215_data *ltc4215_update_device(struct device *dev) |
47 | { | 47 | { |
48 | struct i2c_client *client = to_i2c_client(dev); | 48 | struct ltc4215_data *data = dev_get_drvdata(dev); |
49 | struct ltc4215_data *data = i2c_get_clientdata(client); | 49 | struct i2c_client *client = data->client; |
50 | s32 val; | 50 | s32 val; |
51 | int i; | 51 | int i; |
52 | 52 | ||
@@ -214,7 +214,7 @@ static SENSOR_DEVICE_ATTR(in2_min_alarm, S_IRUGO, ltc4215_show_alarm, NULL, | |||
214 | * Finally, construct an array of pointers to members of the above objects, | 214 | * Finally, construct an array of pointers to members of the above objects, |
215 | * as required for sysfs_create_group() | 215 | * as required for sysfs_create_group() |
216 | */ | 216 | */ |
217 | static struct attribute *ltc4215_attributes[] = { | 217 | static struct attribute *ltc4215_attrs[] = { |
218 | &sensor_dev_attr_curr1_input.dev_attr.attr, | 218 | &sensor_dev_attr_curr1_input.dev_attr.attr, |
219 | &sensor_dev_attr_curr1_max_alarm.dev_attr.attr, | 219 | &sensor_dev_attr_curr1_max_alarm.dev_attr.attr, |
220 | 220 | ||
@@ -229,57 +229,33 @@ static struct attribute *ltc4215_attributes[] = { | |||
229 | 229 | ||
230 | NULL, | 230 | NULL, |
231 | }; | 231 | }; |
232 | 232 | ATTRIBUTE_GROUPS(ltc4215); | |
233 | static const struct attribute_group ltc4215_group = { | ||
234 | .attrs = ltc4215_attributes, | ||
235 | }; | ||
236 | 233 | ||
237 | static int ltc4215_probe(struct i2c_client *client, | 234 | static int ltc4215_probe(struct i2c_client *client, |
238 | const struct i2c_device_id *id) | 235 | const struct i2c_device_id *id) |
239 | { | 236 | { |
240 | struct i2c_adapter *adapter = client->adapter; | 237 | struct i2c_adapter *adapter = client->adapter; |
238 | struct device *dev = &client->dev; | ||
241 | struct ltc4215_data *data; | 239 | struct ltc4215_data *data; |
242 | int ret; | 240 | struct device *hwmon_dev; |
243 | 241 | ||
244 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 242 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
245 | return -ENODEV; | 243 | return -ENODEV; |
246 | 244 | ||
247 | data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); | 245 | data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); |
248 | if (!data) | 246 | if (!data) |
249 | return -ENOMEM; | 247 | return -ENOMEM; |
250 | 248 | ||
251 | i2c_set_clientdata(client, data); | 249 | data->client = client; |
252 | mutex_init(&data->update_lock); | 250 | mutex_init(&data->update_lock); |
253 | 251 | ||
254 | /* Initialize the LTC4215 chip */ | 252 | /* Initialize the LTC4215 chip */ |
255 | i2c_smbus_write_byte_data(client, LTC4215_FAULT, 0x00); | 253 | i2c_smbus_write_byte_data(client, LTC4215_FAULT, 0x00); |
256 | 254 | ||
257 | /* Register sysfs hooks */ | 255 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
258 | ret = sysfs_create_group(&client->dev.kobj, <c4215_group); | 256 | data, |
259 | if (ret) | 257 | ltc4215_groups); |
260 | return ret; | 258 | return PTR_ERR_OR_ZERO(hwmon_dev); |
261 | |||
262 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
263 | if (IS_ERR(data->hwmon_dev)) { | ||
264 | ret = PTR_ERR(data->hwmon_dev); | ||
265 | goto out_hwmon_device_register; | ||
266 | } | ||
267 | |||
268 | return 0; | ||
269 | |||
270 | out_hwmon_device_register: | ||
271 | sysfs_remove_group(&client->dev.kobj, <c4215_group); | ||
272 | return ret; | ||
273 | } | ||
274 | |||
275 | static int ltc4215_remove(struct i2c_client *client) | ||
276 | { | ||
277 | struct ltc4215_data *data = i2c_get_clientdata(client); | ||
278 | |||
279 | hwmon_device_unregister(data->hwmon_dev); | ||
280 | sysfs_remove_group(&client->dev.kobj, <c4215_group); | ||
281 | |||
282 | return 0; | ||
283 | } | 259 | } |
284 | 260 | ||
285 | static const struct i2c_device_id ltc4215_id[] = { | 261 | static const struct i2c_device_id ltc4215_id[] = { |
@@ -294,7 +270,6 @@ static struct i2c_driver ltc4215_driver = { | |||
294 | .name = "ltc4215", | 270 | .name = "ltc4215", |
295 | }, | 271 | }, |
296 | .probe = ltc4215_probe, | 272 | .probe = ltc4215_probe, |
297 | .remove = ltc4215_remove, | ||
298 | .id_table = ltc4215_id, | 273 | .id_table = ltc4215_id, |
299 | }; | 274 | }; |
300 | 275 | ||
diff --git a/drivers/hwmon/ltc4222.c b/drivers/hwmon/ltc4222.c new file mode 100644 index 000000000000..07c25653659f --- /dev/null +++ b/drivers/hwmon/ltc4222.c | |||
@@ -0,0 +1,237 @@ | |||
1 | /* | ||
2 | * Driver for Linear Technology LTC4222 Dual Hot Swap controller | ||
3 | * | ||
4 | * Copyright (c) 2014 Guenter Roeck | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | */ | ||
16 | |||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/err.h> | ||
20 | #include <linux/slab.h> | ||
21 | #include <linux/bitops.h> | ||
22 | #include <linux/i2c.h> | ||
23 | #include <linux/hwmon.h> | ||
24 | #include <linux/hwmon-sysfs.h> | ||
25 | #include <linux/jiffies.h> | ||
26 | #include <linux/regmap.h> | ||
27 | |||
28 | /* chip registers */ | ||
29 | |||
30 | #define LTC4222_CONTROL1 0xd0 | ||
31 | #define LTC4222_ALERT1 0xd1 | ||
32 | #define LTC4222_STATUS1 0xd2 | ||
33 | #define LTC4222_FAULT1 0xd3 | ||
34 | #define LTC4222_CONTROL2 0xd4 | ||
35 | #define LTC4222_ALERT2 0xd5 | ||
36 | #define LTC4222_STATUS2 0xd6 | ||
37 | #define LTC4222_FAULT2 0xd7 | ||
38 | #define LTC4222_SOURCE1 0xd8 | ||
39 | #define LTC4222_SOURCE2 0xda | ||
40 | #define LTC4222_ADIN1 0xdc | ||
41 | #define LTC4222_ADIN2 0xde | ||
42 | #define LTC4222_SENSE1 0xe0 | ||
43 | #define LTC4222_SENSE2 0xe2 | ||
44 | #define LTC4222_ADC_CONTROL 0xe4 | ||
45 | |||
46 | /* | ||
47 | * Fault register bits | ||
48 | */ | ||
49 | #define FAULT_OV BIT(0) | ||
50 | #define FAULT_UV BIT(1) | ||
51 | #define FAULT_OC BIT(2) | ||
52 | #define FAULT_POWER_BAD BIT(3) | ||
53 | #define FAULT_FET_BAD BIT(5) | ||
54 | |||
55 | /* Return the voltage from the given register in mV or mA */ | ||
56 | static int ltc4222_get_value(struct device *dev, u8 reg) | ||
57 | { | ||
58 | struct regmap *regmap = dev_get_drvdata(dev); | ||
59 | unsigned int val; | ||
60 | u8 buf[2]; | ||
61 | int ret; | ||
62 | |||
63 | ret = regmap_bulk_read(regmap, reg, buf, 2); | ||
64 | if (ret < 0) | ||
65 | return ret; | ||
66 | |||
67 | val = ((buf[0] << 8) + buf[1]) >> 6; | ||
68 | |||
69 | switch (reg) { | ||
70 | case LTC4222_ADIN1: | ||
71 | case LTC4222_ADIN2: | ||
72 | /* 1.25 mV resolution. Convert to mV. */ | ||
73 | val = DIV_ROUND_CLOSEST(val * 5, 4); | ||
74 | break; | ||
75 | case LTC4222_SOURCE1: | ||
76 | case LTC4222_SOURCE2: | ||
77 | /* 31.25 mV resolution. Convert to mV. */ | ||
78 | val = DIV_ROUND_CLOSEST(val * 125, 4); | ||
79 | break; | ||
80 | case LTC4222_SENSE1: | ||
81 | case LTC4222_SENSE2: | ||
82 | /* | ||
83 | * 62.5 uV resolution. Convert to current as measured with | ||
84 | * an 1 mOhm sense resistor, in mA. If a different sense | ||
85 | * resistor is installed, calculate the actual current by | ||
86 | * dividing the reported current by the sense resistor value | ||
87 | * in mOhm. | ||
88 | */ | ||
89 | val = DIV_ROUND_CLOSEST(val * 125, 2); | ||
90 | break; | ||
91 | default: | ||
92 | return -EINVAL; | ||
93 | } | ||
94 | return val; | ||
95 | } | ||
96 | |||
97 | static ssize_t ltc4222_show_value(struct device *dev, | ||
98 | struct device_attribute *da, char *buf) | ||
99 | { | ||
100 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
101 | int value; | ||
102 | |||
103 | value = ltc4222_get_value(dev, attr->index); | ||
104 | if (value < 0) | ||
105 | return value; | ||
106 | return snprintf(buf, PAGE_SIZE, "%d\n", value); | ||
107 | } | ||
108 | |||
109 | static ssize_t ltc4222_show_bool(struct device *dev, | ||
110 | struct device_attribute *da, char *buf) | ||
111 | { | ||
112 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(da); | ||
113 | struct regmap *regmap = dev_get_drvdata(dev); | ||
114 | unsigned int fault; | ||
115 | int ret; | ||
116 | |||
117 | ret = regmap_read(regmap, attr->nr, &fault); | ||
118 | if (ret < 0) | ||
119 | return ret; | ||
120 | fault &= attr->index; | ||
121 | if (fault) /* Clear reported faults in chip register */ | ||
122 | regmap_update_bits(regmap, attr->nr, attr->index, 0); | ||
123 | |||
124 | return snprintf(buf, PAGE_SIZE, "%d\n", !!fault); | ||
125 | } | ||
126 | |||
127 | /* Voltages */ | ||
128 | static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, ltc4222_show_value, NULL, | ||
129 | LTC4222_SOURCE1); | ||
130 | static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, ltc4222_show_value, NULL, | ||
131 | LTC4222_ADIN1); | ||
132 | static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, ltc4222_show_value, NULL, | ||
133 | LTC4222_SOURCE2); | ||
134 | static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, ltc4222_show_value, NULL, | ||
135 | LTC4222_ADIN2); | ||
136 | |||
137 | /* | ||
138 | * Voltage alarms | ||
139 | * UV/OV faults are associated with the input voltage, and power bad and fet | ||
140 | * faults are associated with the output voltage. | ||
141 | */ | ||
142 | static SENSOR_DEVICE_ATTR_2(in1_min_alarm, S_IRUGO, ltc4222_show_bool, NULL, | ||
143 | LTC4222_FAULT1, FAULT_UV); | ||
144 | static SENSOR_DEVICE_ATTR_2(in1_max_alarm, S_IRUGO, ltc4222_show_bool, NULL, | ||
145 | LTC4222_FAULT1, FAULT_OV); | ||
146 | static SENSOR_DEVICE_ATTR_2(in2_alarm, S_IRUGO, ltc4222_show_bool, NULL, | ||
147 | LTC4222_FAULT1, FAULT_POWER_BAD | FAULT_FET_BAD); | ||
148 | |||
149 | static SENSOR_DEVICE_ATTR_2(in3_min_alarm, S_IRUGO, ltc4222_show_bool, NULL, | ||
150 | LTC4222_FAULT2, FAULT_UV); | ||
151 | static SENSOR_DEVICE_ATTR_2(in3_max_alarm, S_IRUGO, ltc4222_show_bool, NULL, | ||
152 | LTC4222_FAULT2, FAULT_OV); | ||
153 | static SENSOR_DEVICE_ATTR_2(in4_alarm, S_IRUGO, ltc4222_show_bool, NULL, | ||
154 | LTC4222_FAULT2, FAULT_POWER_BAD | FAULT_FET_BAD); | ||
155 | |||
156 | /* Current (via sense resistor) */ | ||
157 | static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, ltc4222_show_value, NULL, | ||
158 | LTC4222_SENSE1); | ||
159 | static SENSOR_DEVICE_ATTR(curr2_input, S_IRUGO, ltc4222_show_value, NULL, | ||
160 | LTC4222_SENSE2); | ||
161 | |||
162 | /* Overcurrent alarm */ | ||
163 | static SENSOR_DEVICE_ATTR_2(curr1_max_alarm, S_IRUGO, ltc4222_show_bool, NULL, | ||
164 | LTC4222_FAULT1, FAULT_OC); | ||
165 | static SENSOR_DEVICE_ATTR_2(curr2_max_alarm, S_IRUGO, ltc4222_show_bool, NULL, | ||
166 | LTC4222_FAULT2, FAULT_OC); | ||
167 | |||
168 | static struct attribute *ltc4222_attrs[] = { | ||
169 | &sensor_dev_attr_in1_input.dev_attr.attr, | ||
170 | &sensor_dev_attr_in1_min_alarm.dev_attr.attr, | ||
171 | &sensor_dev_attr_in1_max_alarm.dev_attr.attr, | ||
172 | &sensor_dev_attr_in2_input.dev_attr.attr, | ||
173 | &sensor_dev_attr_in2_alarm.dev_attr.attr, | ||
174 | &sensor_dev_attr_in3_input.dev_attr.attr, | ||
175 | &sensor_dev_attr_in3_min_alarm.dev_attr.attr, | ||
176 | &sensor_dev_attr_in3_max_alarm.dev_attr.attr, | ||
177 | &sensor_dev_attr_in4_input.dev_attr.attr, | ||
178 | &sensor_dev_attr_in4_alarm.dev_attr.attr, | ||
179 | |||
180 | &sensor_dev_attr_curr1_input.dev_attr.attr, | ||
181 | &sensor_dev_attr_curr1_max_alarm.dev_attr.attr, | ||
182 | &sensor_dev_attr_curr2_input.dev_attr.attr, | ||
183 | &sensor_dev_attr_curr2_max_alarm.dev_attr.attr, | ||
184 | |||
185 | NULL, | ||
186 | }; | ||
187 | ATTRIBUTE_GROUPS(ltc4222); | ||
188 | |||
189 | static struct regmap_config ltc4222_regmap_config = { | ||
190 | .reg_bits = 8, | ||
191 | .val_bits = 8, | ||
192 | .max_register = LTC4222_ADC_CONTROL, | ||
193 | }; | ||
194 | |||
195 | static int ltc4222_probe(struct i2c_client *client, | ||
196 | const struct i2c_device_id *id) | ||
197 | { | ||
198 | struct device *dev = &client->dev; | ||
199 | struct device *hwmon_dev; | ||
200 | struct regmap *regmap; | ||
201 | |||
202 | regmap = devm_regmap_init_i2c(client, <c4222_regmap_config); | ||
203 | if (IS_ERR(regmap)) { | ||
204 | dev_err(dev, "failed to allocate register map\n"); | ||
205 | return PTR_ERR(regmap); | ||
206 | } | ||
207 | |||
208 | /* Clear faults */ | ||
209 | regmap_write(regmap, LTC4222_FAULT1, 0x00); | ||
210 | regmap_write(regmap, LTC4222_FAULT2, 0x00); | ||
211 | |||
212 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, | ||
213 | regmap, | ||
214 | ltc4222_groups); | ||
215 | return PTR_ERR_OR_ZERO(hwmon_dev); | ||
216 | } | ||
217 | |||
218 | static const struct i2c_device_id ltc4222_id[] = { | ||
219 | {"ltc4222", 0}, | ||
220 | { } | ||
221 | }; | ||
222 | |||
223 | MODULE_DEVICE_TABLE(i2c, ltc4222_id); | ||
224 | |||
225 | static struct i2c_driver ltc4222_driver = { | ||
226 | .driver = { | ||
227 | .name = "ltc4222", | ||
228 | }, | ||
229 | .probe = ltc4222_probe, | ||
230 | .id_table = ltc4222_id, | ||
231 | }; | ||
232 | |||
233 | module_i2c_driver(ltc4222_driver); | ||
234 | |||
235 | MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>"); | ||
236 | MODULE_DESCRIPTION("LTC4222 driver"); | ||
237 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/hwmon/ltc4245.c b/drivers/hwmon/ltc4245.c index d4172933ce4f..681b5b7b3c3b 100644 --- a/drivers/hwmon/ltc4245.c +++ b/drivers/hwmon/ltc4245.c | |||
@@ -95,7 +95,6 @@ static void ltc4245_update_gpios(struct device *dev) | |||
95 | * readings as stale by setting them to -EAGAIN | 95 | * readings as stale by setting them to -EAGAIN |
96 | */ | 96 | */ |
97 | if (time_after(jiffies, data->last_updated + 5 * HZ)) { | 97 | if (time_after(jiffies, data->last_updated + 5 * HZ)) { |
98 | dev_dbg(&client->dev, "Marking GPIOs invalid\n"); | ||
99 | for (i = 0; i < ARRAY_SIZE(data->gpios); i++) | 98 | for (i = 0; i < ARRAY_SIZE(data->gpios); i++) |
100 | data->gpios[i] = -EAGAIN; | 99 | data->gpios[i] = -EAGAIN; |
101 | } | 100 | } |
@@ -141,8 +140,6 @@ static struct ltc4245_data *ltc4245_update_device(struct device *dev) | |||
141 | 140 | ||
142 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { | 141 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { |
143 | 142 | ||
144 | dev_dbg(&client->dev, "Starting ltc4245 update\n"); | ||
145 | |||
146 | /* Read control registers -- 0x00 to 0x07 */ | 143 | /* Read control registers -- 0x00 to 0x07 */ |
147 | for (i = 0; i < ARRAY_SIZE(data->cregs); i++) { | 144 | for (i = 0; i < ARRAY_SIZE(data->cregs); i++) { |
148 | val = i2c_smbus_read_byte_data(client, i); | 145 | val = i2c_smbus_read_byte_data(client, i); |
@@ -470,19 +467,15 @@ static void ltc4245_sysfs_add_groups(struct ltc4245_data *data) | |||
470 | static bool ltc4245_use_extra_gpios(struct i2c_client *client) | 467 | static bool ltc4245_use_extra_gpios(struct i2c_client *client) |
471 | { | 468 | { |
472 | struct ltc4245_platform_data *pdata = dev_get_platdata(&client->dev); | 469 | struct ltc4245_platform_data *pdata = dev_get_platdata(&client->dev); |
473 | #ifdef CONFIG_OF | ||
474 | struct device_node *np = client->dev.of_node; | 470 | struct device_node *np = client->dev.of_node; |
475 | #endif | ||
476 | 471 | ||
477 | /* prefer platform data */ | 472 | /* prefer platform data */ |
478 | if (pdata) | 473 | if (pdata) |
479 | return pdata->use_extra_gpios; | 474 | return pdata->use_extra_gpios; |
480 | 475 | ||
481 | #ifdef CONFIG_OF | ||
482 | /* fallback on OF */ | 476 | /* fallback on OF */ |
483 | if (of_find_property(np, "ltc4245,use-extra-gpios", NULL)) | 477 | if (of_find_property(np, "ltc4245,use-extra-gpios", NULL)) |
484 | return true; | 478 | return true; |
485 | #endif | ||
486 | 479 | ||
487 | return false; | 480 | return false; |
488 | } | 481 | } |
@@ -512,24 +505,10 @@ static int ltc4245_probe(struct i2c_client *client, | |||
512 | /* Add sysfs hooks */ | 505 | /* Add sysfs hooks */ |
513 | ltc4245_sysfs_add_groups(data); | 506 | ltc4245_sysfs_add_groups(data); |
514 | 507 | ||
515 | hwmon_dev = hwmon_device_register_with_groups(&client->dev, | 508 | hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev, |
516 | client->name, data, | 509 | client->name, data, |
517 | data->groups); | 510 | data->groups); |
518 | if (IS_ERR(hwmon_dev)) | 511 | return PTR_ERR_OR_ZERO(hwmon_dev); |
519 | return PTR_ERR(hwmon_dev); | ||
520 | |||
521 | i2c_set_clientdata(client, hwmon_dev); | ||
522 | |||
523 | return 0; | ||
524 | } | ||
525 | |||
526 | static int ltc4245_remove(struct i2c_client *client) | ||
527 | { | ||
528 | struct device *hwmon_dev = i2c_get_clientdata(client); | ||
529 | |||
530 | hwmon_device_unregister(hwmon_dev); | ||
531 | |||
532 | return 0; | ||
533 | } | 512 | } |
534 | 513 | ||
535 | static const struct i2c_device_id ltc4245_id[] = { | 514 | static const struct i2c_device_id ltc4245_id[] = { |
@@ -544,7 +523,6 @@ static struct i2c_driver ltc4245_driver = { | |||
544 | .name = "ltc4245", | 523 | .name = "ltc4245", |
545 | }, | 524 | }, |
546 | .probe = ltc4245_probe, | 525 | .probe = ltc4245_probe, |
547 | .remove = ltc4245_remove, | ||
548 | .id_table = ltc4245_id, | 526 | .id_table = ltc4245_id, |
549 | }; | 527 | }; |
550 | 528 | ||
diff --git a/drivers/hwmon/ltc4260.c b/drivers/hwmon/ltc4260.c new file mode 100644 index 000000000000..453a250d9df5 --- /dev/null +++ b/drivers/hwmon/ltc4260.c | |||
@@ -0,0 +1,200 @@ | |||
1 | /* | ||
2 | * Driver for Linear Technology LTC4260 I2C Positive Voltage Hot Swap Controller | ||
3 | * | ||
4 | * Copyright (c) 2014 Guenter Roeck | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | */ | ||
16 | |||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/err.h> | ||
20 | #include <linux/slab.h> | ||
21 | #include <linux/i2c.h> | ||
22 | #include <linux/hwmon.h> | ||
23 | #include <linux/hwmon-sysfs.h> | ||
24 | #include <linux/jiffies.h> | ||
25 | #include <linux/regmap.h> | ||
26 | |||
27 | /* chip registers */ | ||
28 | #define LTC4260_CONTROL 0x00 | ||
29 | #define LTC4260_ALERT 0x01 | ||
30 | #define LTC4260_STATUS 0x02 | ||
31 | #define LTC4260_FAULT 0x03 | ||
32 | #define LTC4260_SENSE 0x04 | ||
33 | #define LTC4260_SOURCE 0x05 | ||
34 | #define LTC4260_ADIN 0x06 | ||
35 | |||
36 | /* | ||
37 | * Fault register bits | ||
38 | */ | ||
39 | #define FAULT_OV (1 << 0) | ||
40 | #define FAULT_UV (1 << 1) | ||
41 | #define FAULT_OC (1 << 2) | ||
42 | #define FAULT_POWER_BAD (1 << 3) | ||
43 | #define FAULT_FET_SHORT (1 << 5) | ||
44 | |||
45 | /* Return the voltage from the given register in mV or mA */ | ||
46 | static int ltc4260_get_value(struct device *dev, u8 reg) | ||
47 | { | ||
48 | struct regmap *regmap = dev_get_drvdata(dev); | ||
49 | unsigned int val; | ||
50 | int ret; | ||
51 | |||
52 | ret = regmap_read(regmap, reg, &val); | ||
53 | if (ret < 0) | ||
54 | return ret; | ||
55 | |||
56 | switch (reg) { | ||
57 | case LTC4260_ADIN: | ||
58 | /* 10 mV resolution. Convert to mV. */ | ||
59 | val = val * 10; | ||
60 | break; | ||
61 | case LTC4260_SOURCE: | ||
62 | /* 400 mV resolution. Convert to mV. */ | ||
63 | val = val * 400; | ||
64 | break; | ||
65 | case LTC4260_SENSE: | ||
66 | /* | ||
67 | * 300 uV resolution. Convert to current as measured with | ||
68 | * an 1 mOhm sense resistor, in mA. If a different sense | ||
69 | * resistor is installed, calculate the actual current by | ||
70 | * dividing the reported current by the sense resistor value | ||
71 | * in mOhm. | ||
72 | */ | ||
73 | val = val * 300; | ||
74 | break; | ||
75 | default: | ||
76 | return -EINVAL; | ||
77 | } | ||
78 | |||
79 | return val; | ||
80 | } | ||
81 | |||
82 | static ssize_t ltc4260_show_value(struct device *dev, | ||
83 | struct device_attribute *da, char *buf) | ||
84 | { | ||
85 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
86 | int value; | ||
87 | |||
88 | value = ltc4260_get_value(dev, attr->index); | ||
89 | if (value < 0) | ||
90 | return value; | ||
91 | return snprintf(buf, PAGE_SIZE, "%d\n", value); | ||
92 | } | ||
93 | |||
94 | static ssize_t ltc4260_show_bool(struct device *dev, | ||
95 | struct device_attribute *da, char *buf) | ||
96 | { | ||
97 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
98 | struct regmap *regmap = dev_get_drvdata(dev); | ||
99 | unsigned int fault; | ||
100 | int ret; | ||
101 | |||
102 | ret = regmap_read(regmap, LTC4260_FAULT, &fault); | ||
103 | if (ret < 0) | ||
104 | return ret; | ||
105 | |||
106 | fault &= attr->index; | ||
107 | if (fault) /* Clear reported faults in chip register */ | ||
108 | regmap_update_bits(regmap, LTC4260_FAULT, attr->index, 0); | ||
109 | |||
110 | return snprintf(buf, PAGE_SIZE, "%d\n", !!fault); | ||
111 | } | ||
112 | |||
113 | /* Voltages */ | ||
114 | static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, ltc4260_show_value, NULL, | ||
115 | LTC4260_SOURCE); | ||
116 | static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, ltc4260_show_value, NULL, | ||
117 | LTC4260_ADIN); | ||
118 | |||
119 | /* | ||
120 | * Voltage alarms | ||
121 | * UV/OV faults are associated with the input voltage, and the POWER BAD and | ||
122 | * FET SHORT faults are associated with the output voltage. | ||
123 | */ | ||
124 | static SENSOR_DEVICE_ATTR(in1_min_alarm, S_IRUGO, ltc4260_show_bool, NULL, | ||
125 | FAULT_UV); | ||
126 | static SENSOR_DEVICE_ATTR(in1_max_alarm, S_IRUGO, ltc4260_show_bool, NULL, | ||
127 | FAULT_OV); | ||
128 | static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, ltc4260_show_bool, NULL, | ||
129 | FAULT_POWER_BAD | FAULT_FET_SHORT); | ||
130 | |||
131 | /* Current (via sense resistor) */ | ||
132 | static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, ltc4260_show_value, NULL, | ||
133 | LTC4260_SENSE); | ||
134 | |||
135 | /* Overcurrent alarm */ | ||
136 | static SENSOR_DEVICE_ATTR(curr1_max_alarm, S_IRUGO, ltc4260_show_bool, NULL, | ||
137 | FAULT_OC); | ||
138 | |||
139 | static struct attribute *ltc4260_attrs[] = { | ||
140 | &sensor_dev_attr_in1_input.dev_attr.attr, | ||
141 | &sensor_dev_attr_in1_min_alarm.dev_attr.attr, | ||
142 | &sensor_dev_attr_in1_max_alarm.dev_attr.attr, | ||
143 | &sensor_dev_attr_in2_input.dev_attr.attr, | ||
144 | &sensor_dev_attr_in2_alarm.dev_attr.attr, | ||
145 | |||
146 | &sensor_dev_attr_curr1_input.dev_attr.attr, | ||
147 | &sensor_dev_attr_curr1_max_alarm.dev_attr.attr, | ||
148 | |||
149 | NULL, | ||
150 | }; | ||
151 | ATTRIBUTE_GROUPS(ltc4260); | ||
152 | |||
153 | static struct regmap_config ltc4260_regmap_config = { | ||
154 | .reg_bits = 8, | ||
155 | .val_bits = 8, | ||
156 | .max_register = LTC4260_ADIN, | ||
157 | }; | ||
158 | |||
159 | static int ltc4260_probe(struct i2c_client *client, | ||
160 | const struct i2c_device_id *id) | ||
161 | { | ||
162 | struct device *dev = &client->dev; | ||
163 | struct device *hwmon_dev; | ||
164 | struct regmap *regmap; | ||
165 | |||
166 | regmap = devm_regmap_init_i2c(client, <c4260_regmap_config); | ||
167 | if (IS_ERR(regmap)) { | ||
168 | dev_err(dev, "failed to allocate register map\n"); | ||
169 | return PTR_ERR(regmap); | ||
170 | } | ||
171 | |||
172 | /* Clear faults */ | ||
173 | regmap_write(regmap, LTC4260_FAULT, 0x00); | ||
174 | |||
175 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, | ||
176 | regmap, | ||
177 | ltc4260_groups); | ||
178 | return PTR_ERR_OR_ZERO(hwmon_dev); | ||
179 | } | ||
180 | |||
181 | static const struct i2c_device_id ltc4260_id[] = { | ||
182 | {"ltc4260", 0}, | ||
183 | { } | ||
184 | }; | ||
185 | |||
186 | MODULE_DEVICE_TABLE(i2c, ltc4260_id); | ||
187 | |||
188 | static struct i2c_driver ltc4260_driver = { | ||
189 | .driver = { | ||
190 | .name = "ltc4260", | ||
191 | }, | ||
192 | .probe = ltc4260_probe, | ||
193 | .id_table = ltc4260_id, | ||
194 | }; | ||
195 | |||
196 | module_i2c_driver(ltc4260_driver); | ||
197 | |||
198 | MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>"); | ||
199 | MODULE_DESCRIPTION("LTC4260 driver"); | ||
200 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c index 6638e997f83f..4c23afe113e2 100644 --- a/drivers/hwmon/max1619.c +++ b/drivers/hwmon/max1619.c | |||
@@ -273,7 +273,6 @@ static int max1619_probe(struct i2c_client *new_client, | |||
273 | return -ENOMEM; | 273 | return -ENOMEM; |
274 | 274 | ||
275 | i2c_set_clientdata(new_client, data); | 275 | i2c_set_clientdata(new_client, data); |
276 | data->valid = 0; | ||
277 | mutex_init(&data->update_lock); | 276 | mutex_init(&data->update_lock); |
278 | 277 | ||
279 | /* Initialize the MAX1619 chip */ | 278 | /* Initialize the MAX1619 chip */ |
diff --git a/drivers/hwmon/max1668.c b/drivers/hwmon/max1668.c index 029b65e6c589..e3ed0a5b6d94 100644 --- a/drivers/hwmon/max1668.c +++ b/drivers/hwmon/max1668.c | |||
@@ -66,7 +66,8 @@ MODULE_PARM_DESC(read_only, "Don't set any values, read only mode"); | |||
66 | enum chips { max1668, max1805, max1989 }; | 66 | enum chips { max1668, max1805, max1989 }; |
67 | 67 | ||
68 | struct max1668_data { | 68 | struct max1668_data { |
69 | struct device *hwmon_dev; | 69 | struct i2c_client *client; |
70 | const struct attribute_group *groups[3]; | ||
70 | enum chips type; | 71 | enum chips type; |
71 | 72 | ||
72 | struct mutex update_lock; | 73 | struct mutex update_lock; |
@@ -82,8 +83,8 @@ struct max1668_data { | |||
82 | 83 | ||
83 | static struct max1668_data *max1668_update_device(struct device *dev) | 84 | static struct max1668_data *max1668_update_device(struct device *dev) |
84 | { | 85 | { |
85 | struct i2c_client *client = to_i2c_client(dev); | 86 | struct max1668_data *data = dev_get_drvdata(dev); |
86 | struct max1668_data *data = i2c_get_clientdata(client); | 87 | struct i2c_client *client = data->client; |
87 | struct max1668_data *ret = data; | 88 | struct max1668_data *ret = data; |
88 | s32 val; | 89 | s32 val; |
89 | int i; | 90 | int i; |
@@ -205,8 +206,8 @@ static ssize_t set_temp_max(struct device *dev, | |||
205 | const char *buf, size_t count) | 206 | const char *buf, size_t count) |
206 | { | 207 | { |
207 | int index = to_sensor_dev_attr(devattr)->index; | 208 | int index = to_sensor_dev_attr(devattr)->index; |
208 | struct i2c_client *client = to_i2c_client(dev); | 209 | struct max1668_data *data = dev_get_drvdata(dev); |
209 | struct max1668_data *data = i2c_get_clientdata(client); | 210 | struct i2c_client *client = data->client; |
210 | long temp; | 211 | long temp; |
211 | int ret; | 212 | int ret; |
212 | 213 | ||
@@ -216,10 +217,11 @@ static ssize_t set_temp_max(struct device *dev, | |||
216 | 217 | ||
217 | mutex_lock(&data->update_lock); | 218 | mutex_lock(&data->update_lock); |
218 | data->temp_max[index] = clamp_val(temp/1000, -128, 127); | 219 | data->temp_max[index] = clamp_val(temp/1000, -128, 127); |
219 | if (i2c_smbus_write_byte_data(client, | 220 | ret = i2c_smbus_write_byte_data(client, |
220 | MAX1668_REG_LIMH_WR(index), | 221 | MAX1668_REG_LIMH_WR(index), |
221 | data->temp_max[index])) | 222 | data->temp_max[index]); |
222 | count = -EIO; | 223 | if (ret < 0) |
224 | count = ret; | ||
223 | mutex_unlock(&data->update_lock); | 225 | mutex_unlock(&data->update_lock); |
224 | 226 | ||
225 | return count; | 227 | return count; |
@@ -230,8 +232,8 @@ static ssize_t set_temp_min(struct device *dev, | |||
230 | const char *buf, size_t count) | 232 | const char *buf, size_t count) |
231 | { | 233 | { |
232 | int index = to_sensor_dev_attr(devattr)->index; | 234 | int index = to_sensor_dev_attr(devattr)->index; |
233 | struct i2c_client *client = to_i2c_client(dev); | 235 | struct max1668_data *data = dev_get_drvdata(dev); |
234 | struct max1668_data *data = i2c_get_clientdata(client); | 236 | struct i2c_client *client = data->client; |
235 | long temp; | 237 | long temp; |
236 | int ret; | 238 | int ret; |
237 | 239 | ||
@@ -241,10 +243,11 @@ static ssize_t set_temp_min(struct device *dev, | |||
241 | 243 | ||
242 | mutex_lock(&data->update_lock); | 244 | mutex_lock(&data->update_lock); |
243 | data->temp_min[index] = clamp_val(temp/1000, -128, 127); | 245 | data->temp_min[index] = clamp_val(temp/1000, -128, 127); |
244 | if (i2c_smbus_write_byte_data(client, | 246 | ret = i2c_smbus_write_byte_data(client, |
245 | MAX1668_REG_LIML_WR(index), | 247 | MAX1668_REG_LIML_WR(index), |
246 | data->temp_min[index])) | 248 | data->temp_min[index]); |
247 | count = -EIO; | 249 | if (ret < 0) |
250 | count = ret; | ||
248 | mutex_unlock(&data->update_lock); | 251 | mutex_unlock(&data->update_lock); |
249 | 252 | ||
250 | return count; | 253 | return count; |
@@ -405,60 +408,29 @@ static int max1668_probe(struct i2c_client *client, | |||
405 | const struct i2c_device_id *id) | 408 | const struct i2c_device_id *id) |
406 | { | 409 | { |
407 | struct i2c_adapter *adapter = client->adapter; | 410 | struct i2c_adapter *adapter = client->adapter; |
411 | struct device *dev = &client->dev; | ||
412 | struct device *hwmon_dev; | ||
408 | struct max1668_data *data; | 413 | struct max1668_data *data; |
409 | int err; | ||
410 | 414 | ||
411 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 415 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
412 | return -ENODEV; | 416 | return -ENODEV; |
413 | 417 | ||
414 | data = devm_kzalloc(&client->dev, sizeof(struct max1668_data), | 418 | data = devm_kzalloc(dev, sizeof(struct max1668_data), GFP_KERNEL); |
415 | GFP_KERNEL); | ||
416 | if (!data) | 419 | if (!data) |
417 | return -ENOMEM; | 420 | return -ENOMEM; |
418 | 421 | ||
419 | i2c_set_clientdata(client, data); | 422 | data->client = client; |
420 | data->type = id->driver_data; | 423 | data->type = id->driver_data; |
421 | mutex_init(&data->update_lock); | 424 | mutex_init(&data->update_lock); |
422 | 425 | ||
423 | /* Register sysfs hooks */ | 426 | /* sysfs hooks */ |
424 | err = sysfs_create_group(&client->dev.kobj, &max1668_group_common); | 427 | data->groups[0] = &max1668_group_common; |
425 | if (err) | ||
426 | return err; | ||
427 | |||
428 | if (data->type == max1668 || data->type == max1989) { | ||
429 | err = sysfs_create_group(&client->dev.kobj, | ||
430 | &max1668_group_unique); | ||
431 | if (err) | ||
432 | goto error_sysrem0; | ||
433 | } | ||
434 | |||
435 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
436 | if (IS_ERR(data->hwmon_dev)) { | ||
437 | err = PTR_ERR(data->hwmon_dev); | ||
438 | goto error_sysrem1; | ||
439 | } | ||
440 | |||
441 | return 0; | ||
442 | |||
443 | error_sysrem1: | ||
444 | if (data->type == max1668 || data->type == max1989) | 428 | if (data->type == max1668 || data->type == max1989) |
445 | sysfs_remove_group(&client->dev.kobj, &max1668_group_unique); | 429 | data->groups[1] = &max1668_group_unique; |
446 | error_sysrem0: | ||
447 | sysfs_remove_group(&client->dev.kobj, &max1668_group_common); | ||
448 | return err; | ||
449 | } | ||
450 | |||
451 | static int max1668_remove(struct i2c_client *client) | ||
452 | { | ||
453 | struct max1668_data *data = i2c_get_clientdata(client); | ||
454 | 430 | ||
455 | hwmon_device_unregister(data->hwmon_dev); | 431 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
456 | if (data->type == max1668 || data->type == max1989) | 432 | data, data->groups); |
457 | sysfs_remove_group(&client->dev.kobj, &max1668_group_unique); | 433 | return PTR_ERR_OR_ZERO(hwmon_dev); |
458 | |||
459 | sysfs_remove_group(&client->dev.kobj, &max1668_group_common); | ||
460 | |||
461 | return 0; | ||
462 | } | 434 | } |
463 | 435 | ||
464 | static const struct i2c_device_id max1668_id[] = { | 436 | static const struct i2c_device_id max1668_id[] = { |
@@ -476,7 +448,6 @@ static struct i2c_driver max1668_driver = { | |||
476 | .name = "max1668", | 448 | .name = "max1668", |
477 | }, | 449 | }, |
478 | .probe = max1668_probe, | 450 | .probe = max1668_probe, |
479 | .remove = max1668_remove, | ||
480 | .id_table = max1668_id, | 451 | .id_table = max1668_id, |
481 | .detect = max1668_detect, | 452 | .detect = max1668_detect, |
482 | .address_list = max1668_addr_list, | 453 | .address_list = max1668_addr_list, |
diff --git a/drivers/hwmon/max6639.c b/drivers/hwmon/max6639.c index 066e587a18a5..70650de2cbd1 100644 --- a/drivers/hwmon/max6639.c +++ b/drivers/hwmon/max6639.c | |||
@@ -80,7 +80,7 @@ static const int rpm_ranges[] = { 2000, 4000, 8000, 16000 }; | |||
80 | * Client data (each client gets its own) | 80 | * Client data (each client gets its own) |
81 | */ | 81 | */ |
82 | struct max6639_data { | 82 | struct max6639_data { |
83 | struct device *hwmon_dev; | 83 | struct i2c_client *client; |
84 | struct mutex update_lock; | 84 | struct mutex update_lock; |
85 | char valid; /* !=0 if following fields are valid */ | 85 | char valid; /* !=0 if following fields are valid */ |
86 | unsigned long last_updated; /* In jiffies */ | 86 | unsigned long last_updated; /* In jiffies */ |
@@ -104,8 +104,8 @@ struct max6639_data { | |||
104 | 104 | ||
105 | static struct max6639_data *max6639_update_device(struct device *dev) | 105 | static struct max6639_data *max6639_update_device(struct device *dev) |
106 | { | 106 | { |
107 | struct i2c_client *client = to_i2c_client(dev); | 107 | struct max6639_data *data = dev_get_drvdata(dev); |
108 | struct max6639_data *data = i2c_get_clientdata(client); | 108 | struct i2c_client *client = data->client; |
109 | struct max6639_data *ret = data; | 109 | struct max6639_data *ret = data; |
110 | int i; | 110 | int i; |
111 | int status_reg; | 111 | int status_reg; |
@@ -191,9 +191,8 @@ static ssize_t show_temp_fault(struct device *dev, | |||
191 | static ssize_t show_temp_max(struct device *dev, | 191 | static ssize_t show_temp_max(struct device *dev, |
192 | struct device_attribute *dev_attr, char *buf) | 192 | struct device_attribute *dev_attr, char *buf) |
193 | { | 193 | { |
194 | struct i2c_client *client = to_i2c_client(dev); | ||
195 | struct max6639_data *data = i2c_get_clientdata(client); | ||
196 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); | 194 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); |
195 | struct max6639_data *data = dev_get_drvdata(dev); | ||
197 | 196 | ||
198 | return sprintf(buf, "%d\n", (data->temp_therm[attr->index] * 1000)); | 197 | return sprintf(buf, "%d\n", (data->temp_therm[attr->index] * 1000)); |
199 | } | 198 | } |
@@ -202,9 +201,9 @@ static ssize_t set_temp_max(struct device *dev, | |||
202 | struct device_attribute *dev_attr, | 201 | struct device_attribute *dev_attr, |
203 | const char *buf, size_t count) | 202 | const char *buf, size_t count) |
204 | { | 203 | { |
205 | struct i2c_client *client = to_i2c_client(dev); | ||
206 | struct max6639_data *data = i2c_get_clientdata(client); | ||
207 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); | 204 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); |
205 | struct max6639_data *data = dev_get_drvdata(dev); | ||
206 | struct i2c_client *client = data->client; | ||
208 | unsigned long val; | 207 | unsigned long val; |
209 | int res; | 208 | int res; |
210 | 209 | ||
@@ -224,9 +223,8 @@ static ssize_t set_temp_max(struct device *dev, | |||
224 | static ssize_t show_temp_crit(struct device *dev, | 223 | static ssize_t show_temp_crit(struct device *dev, |
225 | struct device_attribute *dev_attr, char *buf) | 224 | struct device_attribute *dev_attr, char *buf) |
226 | { | 225 | { |
227 | struct i2c_client *client = to_i2c_client(dev); | ||
228 | struct max6639_data *data = i2c_get_clientdata(client); | ||
229 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); | 226 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); |
227 | struct max6639_data *data = dev_get_drvdata(dev); | ||
230 | 228 | ||
231 | return sprintf(buf, "%d\n", (data->temp_alert[attr->index] * 1000)); | 229 | return sprintf(buf, "%d\n", (data->temp_alert[attr->index] * 1000)); |
232 | } | 230 | } |
@@ -235,9 +233,9 @@ static ssize_t set_temp_crit(struct device *dev, | |||
235 | struct device_attribute *dev_attr, | 233 | struct device_attribute *dev_attr, |
236 | const char *buf, size_t count) | 234 | const char *buf, size_t count) |
237 | { | 235 | { |
238 | struct i2c_client *client = to_i2c_client(dev); | ||
239 | struct max6639_data *data = i2c_get_clientdata(client); | ||
240 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); | 236 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); |
237 | struct max6639_data *data = dev_get_drvdata(dev); | ||
238 | struct i2c_client *client = data->client; | ||
241 | unsigned long val; | 239 | unsigned long val; |
242 | int res; | 240 | int res; |
243 | 241 | ||
@@ -258,9 +256,8 @@ static ssize_t show_temp_emergency(struct device *dev, | |||
258 | struct device_attribute *dev_attr, | 256 | struct device_attribute *dev_attr, |
259 | char *buf) | 257 | char *buf) |
260 | { | 258 | { |
261 | struct i2c_client *client = to_i2c_client(dev); | ||
262 | struct max6639_data *data = i2c_get_clientdata(client); | ||
263 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); | 259 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); |
260 | struct max6639_data *data = dev_get_drvdata(dev); | ||
264 | 261 | ||
265 | return sprintf(buf, "%d\n", (data->temp_ot[attr->index] * 1000)); | 262 | return sprintf(buf, "%d\n", (data->temp_ot[attr->index] * 1000)); |
266 | } | 263 | } |
@@ -269,9 +266,9 @@ static ssize_t set_temp_emergency(struct device *dev, | |||
269 | struct device_attribute *dev_attr, | 266 | struct device_attribute *dev_attr, |
270 | const char *buf, size_t count) | 267 | const char *buf, size_t count) |
271 | { | 268 | { |
272 | struct i2c_client *client = to_i2c_client(dev); | ||
273 | struct max6639_data *data = i2c_get_clientdata(client); | ||
274 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); | 269 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); |
270 | struct max6639_data *data = dev_get_drvdata(dev); | ||
271 | struct i2c_client *client = data->client; | ||
275 | unsigned long val; | 272 | unsigned long val; |
276 | int res; | 273 | int res; |
277 | 274 | ||
@@ -291,9 +288,8 @@ static ssize_t set_temp_emergency(struct device *dev, | |||
291 | static ssize_t show_pwm(struct device *dev, | 288 | static ssize_t show_pwm(struct device *dev, |
292 | struct device_attribute *dev_attr, char *buf) | 289 | struct device_attribute *dev_attr, char *buf) |
293 | { | 290 | { |
294 | struct i2c_client *client = to_i2c_client(dev); | ||
295 | struct max6639_data *data = i2c_get_clientdata(client); | ||
296 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); | 291 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); |
292 | struct max6639_data *data = dev_get_drvdata(dev); | ||
297 | 293 | ||
298 | return sprintf(buf, "%d\n", data->pwm[attr->index] * 255 / 120); | 294 | return sprintf(buf, "%d\n", data->pwm[attr->index] * 255 / 120); |
299 | } | 295 | } |
@@ -302,9 +298,9 @@ static ssize_t set_pwm(struct device *dev, | |||
302 | struct device_attribute *dev_attr, | 298 | struct device_attribute *dev_attr, |
303 | const char *buf, size_t count) | 299 | const char *buf, size_t count) |
304 | { | 300 | { |
305 | struct i2c_client *client = to_i2c_client(dev); | ||
306 | struct max6639_data *data = i2c_get_clientdata(client); | ||
307 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); | 301 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); |
302 | struct max6639_data *data = dev_get_drvdata(dev); | ||
303 | struct i2c_client *client = data->client; | ||
308 | unsigned long val; | 304 | unsigned long val; |
309 | int res; | 305 | int res; |
310 | 306 | ||
@@ -378,7 +374,7 @@ static SENSOR_DEVICE_ATTR(temp1_emergency_alarm, S_IRUGO, show_alarm, NULL, 5); | |||
378 | static SENSOR_DEVICE_ATTR(temp2_emergency_alarm, S_IRUGO, show_alarm, NULL, 4); | 374 | static SENSOR_DEVICE_ATTR(temp2_emergency_alarm, S_IRUGO, show_alarm, NULL, 4); |
379 | 375 | ||
380 | 376 | ||
381 | static struct attribute *max6639_attributes[] = { | 377 | static struct attribute *max6639_attrs[] = { |
382 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 378 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
383 | &sensor_dev_attr_temp2_input.dev_attr.attr, | 379 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
384 | &sensor_dev_attr_temp1_fault.dev_attr.attr, | 380 | &sensor_dev_attr_temp1_fault.dev_attr.attr, |
@@ -403,10 +399,7 @@ static struct attribute *max6639_attributes[] = { | |||
403 | &sensor_dev_attr_temp2_emergency_alarm.dev_attr.attr, | 399 | &sensor_dev_attr_temp2_emergency_alarm.dev_attr.attr, |
404 | NULL | 400 | NULL |
405 | }; | 401 | }; |
406 | 402 | ATTRIBUTE_GROUPS(max6639); | |
407 | static const struct attribute_group max6639_group = { | ||
408 | .attrs = max6639_attributes, | ||
409 | }; | ||
410 | 403 | ||
411 | /* | 404 | /* |
412 | * returns respective index in rpm_ranges table | 405 | * returns respective index in rpm_ranges table |
@@ -424,9 +417,9 @@ static int rpm_range_to_reg(int range) | |||
424 | return 1; /* default: 4000 RPM */ | 417 | return 1; /* default: 4000 RPM */ |
425 | } | 418 | } |
426 | 419 | ||
427 | static int max6639_init_client(struct i2c_client *client) | 420 | static int max6639_init_client(struct i2c_client *client, |
421 | struct max6639_data *data) | ||
428 | { | 422 | { |
429 | struct max6639_data *data = i2c_get_clientdata(client); | ||
430 | struct max6639_platform_data *max6639_info = | 423 | struct max6639_platform_data *max6639_info = |
431 | dev_get_platdata(&client->dev); | 424 | dev_get_platdata(&client->dev); |
432 | int i; | 425 | int i; |
@@ -545,50 +538,27 @@ static int max6639_detect(struct i2c_client *client, | |||
545 | static int max6639_probe(struct i2c_client *client, | 538 | static int max6639_probe(struct i2c_client *client, |
546 | const struct i2c_device_id *id) | 539 | const struct i2c_device_id *id) |
547 | { | 540 | { |
541 | struct device *dev = &client->dev; | ||
548 | struct max6639_data *data; | 542 | struct max6639_data *data; |
543 | struct device *hwmon_dev; | ||
549 | int err; | 544 | int err; |
550 | 545 | ||
551 | data = devm_kzalloc(&client->dev, sizeof(struct max6639_data), | 546 | data = devm_kzalloc(dev, sizeof(struct max6639_data), GFP_KERNEL); |
552 | GFP_KERNEL); | ||
553 | if (!data) | 547 | if (!data) |
554 | return -ENOMEM; | 548 | return -ENOMEM; |
555 | 549 | ||
556 | i2c_set_clientdata(client, data); | 550 | data->client = client; |
557 | mutex_init(&data->update_lock); | 551 | mutex_init(&data->update_lock); |
558 | 552 | ||
559 | /* Initialize the max6639 chip */ | 553 | /* Initialize the max6639 chip */ |
560 | err = max6639_init_client(client); | 554 | err = max6639_init_client(client, data); |
561 | if (err < 0) | 555 | if (err < 0) |
562 | return err; | 556 | return err; |
563 | 557 | ||
564 | /* Register sysfs hooks */ | 558 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
565 | err = sysfs_create_group(&client->dev.kobj, &max6639_group); | 559 | data, |
566 | if (err) | 560 | max6639_groups); |
567 | return err; | 561 | return PTR_ERR_OR_ZERO(hwmon_dev); |
568 | |||
569 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
570 | if (IS_ERR(data->hwmon_dev)) { | ||
571 | err = PTR_ERR(data->hwmon_dev); | ||
572 | goto error_remove; | ||
573 | } | ||
574 | |||
575 | dev_info(&client->dev, "temperature sensor and fan control found\n"); | ||
576 | |||
577 | return 0; | ||
578 | |||
579 | error_remove: | ||
580 | sysfs_remove_group(&client->dev.kobj, &max6639_group); | ||
581 | return err; | ||
582 | } | ||
583 | |||
584 | static int max6639_remove(struct i2c_client *client) | ||
585 | { | ||
586 | struct max6639_data *data = i2c_get_clientdata(client); | ||
587 | |||
588 | hwmon_device_unregister(data->hwmon_dev); | ||
589 | sysfs_remove_group(&client->dev.kobj, &max6639_group); | ||
590 | |||
591 | return 0; | ||
592 | } | 562 | } |
593 | 563 | ||
594 | #ifdef CONFIG_PM_SLEEP | 564 | #ifdef CONFIG_PM_SLEEP |
@@ -622,9 +592,7 @@ static const struct i2c_device_id max6639_id[] = { | |||
622 | 592 | ||
623 | MODULE_DEVICE_TABLE(i2c, max6639_id); | 593 | MODULE_DEVICE_TABLE(i2c, max6639_id); |
624 | 594 | ||
625 | static const struct dev_pm_ops max6639_pm_ops = { | 595 | static SIMPLE_DEV_PM_OPS(max6639_pm_ops, max6639_suspend, max6639_resume); |
626 | SET_SYSTEM_SLEEP_PM_OPS(max6639_suspend, max6639_resume) | ||
627 | }; | ||
628 | 596 | ||
629 | static struct i2c_driver max6639_driver = { | 597 | static struct i2c_driver max6639_driver = { |
630 | .class = I2C_CLASS_HWMON, | 598 | .class = I2C_CLASS_HWMON, |
@@ -633,7 +601,6 @@ static struct i2c_driver max6639_driver = { | |||
633 | .pm = &max6639_pm_ops, | 601 | .pm = &max6639_pm_ops, |
634 | }, | 602 | }, |
635 | .probe = max6639_probe, | 603 | .probe = max6639_probe, |
636 | .remove = max6639_remove, | ||
637 | .id_table = max6639_id, | 604 | .id_table = max6639_id, |
638 | .detect = max6639_detect, | 605 | .detect = max6639_detect, |
639 | .address_list = normal_i2c, | 606 | .address_list = normal_i2c, |
diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c index 0cafc390db4d..162a520f4bd6 100644 --- a/drivers/hwmon/max6650.c +++ b/drivers/hwmon/max6650.c | |||
@@ -105,38 +105,13 @@ module_param(clock, int, S_IRUGO); | |||
105 | 105 | ||
106 | #define DIV_FROM_REG(reg) (1 << (reg & 7)) | 106 | #define DIV_FROM_REG(reg) (1 << (reg & 7)) |
107 | 107 | ||
108 | static int max6650_probe(struct i2c_client *client, | ||
109 | const struct i2c_device_id *id); | ||
110 | static int max6650_init_client(struct i2c_client *client); | ||
111 | static int max6650_remove(struct i2c_client *client); | ||
112 | static struct max6650_data *max6650_update_device(struct device *dev); | ||
113 | |||
114 | /* | ||
115 | * Driver data (common to all clients) | ||
116 | */ | ||
117 | |||
118 | static const struct i2c_device_id max6650_id[] = { | ||
119 | { "max6650", 1 }, | ||
120 | { "max6651", 4 }, | ||
121 | { } | ||
122 | }; | ||
123 | MODULE_DEVICE_TABLE(i2c, max6650_id); | ||
124 | |||
125 | static struct i2c_driver max6650_driver = { | ||
126 | .driver = { | ||
127 | .name = "max6650", | ||
128 | }, | ||
129 | .probe = max6650_probe, | ||
130 | .remove = max6650_remove, | ||
131 | .id_table = max6650_id, | ||
132 | }; | ||
133 | |||
134 | /* | 108 | /* |
135 | * Client data (each client gets its own) | 109 | * Client data (each client gets its own) |
136 | */ | 110 | */ |
137 | 111 | ||
138 | struct max6650_data { | 112 | struct max6650_data { |
139 | struct device *hwmon_dev; | 113 | struct i2c_client *client; |
114 | const struct attribute_group *groups[3]; | ||
140 | struct mutex update_lock; | 115 | struct mutex update_lock; |
141 | int nr_fans; | 116 | int nr_fans; |
142 | char valid; /* zero until following fields are valid */ | 117 | char valid; /* zero until following fields are valid */ |
@@ -151,6 +126,51 @@ struct max6650_data { | |||
151 | u8 alarm; | 126 | u8 alarm; |
152 | }; | 127 | }; |
153 | 128 | ||
129 | static const u8 tach_reg[] = { | ||
130 | MAX6650_REG_TACH0, | ||
131 | MAX6650_REG_TACH1, | ||
132 | MAX6650_REG_TACH2, | ||
133 | MAX6650_REG_TACH3, | ||
134 | }; | ||
135 | |||
136 | static struct max6650_data *max6650_update_device(struct device *dev) | ||
137 | { | ||
138 | struct max6650_data *data = dev_get_drvdata(dev); | ||
139 | struct i2c_client *client = data->client; | ||
140 | int i; | ||
141 | |||
142 | mutex_lock(&data->update_lock); | ||
143 | |||
144 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { | ||
145 | data->speed = i2c_smbus_read_byte_data(client, | ||
146 | MAX6650_REG_SPEED); | ||
147 | data->config = i2c_smbus_read_byte_data(client, | ||
148 | MAX6650_REG_CONFIG); | ||
149 | for (i = 0; i < data->nr_fans; i++) { | ||
150 | data->tach[i] = i2c_smbus_read_byte_data(client, | ||
151 | tach_reg[i]); | ||
152 | } | ||
153 | data->count = i2c_smbus_read_byte_data(client, | ||
154 | MAX6650_REG_COUNT); | ||
155 | data->dac = i2c_smbus_read_byte_data(client, MAX6650_REG_DAC); | ||
156 | |||
157 | /* | ||
158 | * Alarms are cleared on read in case the condition that | ||
159 | * caused the alarm is removed. Keep the value latched here | ||
160 | * for providing the register through different alarm files. | ||
161 | */ | ||
162 | data->alarm |= i2c_smbus_read_byte_data(client, | ||
163 | MAX6650_REG_ALARM); | ||
164 | |||
165 | data->last_updated = jiffies; | ||
166 | data->valid = 1; | ||
167 | } | ||
168 | |||
169 | mutex_unlock(&data->update_lock); | ||
170 | |||
171 | return data; | ||
172 | } | ||
173 | |||
154 | static ssize_t get_fan(struct device *dev, struct device_attribute *devattr, | 174 | static ssize_t get_fan(struct device *dev, struct device_attribute *devattr, |
155 | char *buf) | 175 | char *buf) |
156 | { | 176 | { |
@@ -235,8 +255,8 @@ static ssize_t get_target(struct device *dev, struct device_attribute *devattr, | |||
235 | static ssize_t set_target(struct device *dev, struct device_attribute *devattr, | 255 | static ssize_t set_target(struct device *dev, struct device_attribute *devattr, |
236 | const char *buf, size_t count) | 256 | const char *buf, size_t count) |
237 | { | 257 | { |
238 | struct i2c_client *client = to_i2c_client(dev); | 258 | struct max6650_data *data = dev_get_drvdata(dev); |
239 | struct max6650_data *data = i2c_get_clientdata(client); | 259 | struct i2c_client *client = data->client; |
240 | int kscale, ktach; | 260 | int kscale, ktach; |
241 | unsigned long rpm; | 261 | unsigned long rpm; |
242 | int err; | 262 | int err; |
@@ -304,8 +324,8 @@ static ssize_t get_pwm(struct device *dev, struct device_attribute *devattr, | |||
304 | static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, | 324 | static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, |
305 | const char *buf, size_t count) | 325 | const char *buf, size_t count) |
306 | { | 326 | { |
307 | struct i2c_client *client = to_i2c_client(dev); | 327 | struct max6650_data *data = dev_get_drvdata(dev); |
308 | struct max6650_data *data = i2c_get_clientdata(client); | 328 | struct i2c_client *client = data->client; |
309 | unsigned long pwm; | 329 | unsigned long pwm; |
310 | int err; | 330 | int err; |
311 | 331 | ||
@@ -350,8 +370,8 @@ static ssize_t get_enable(struct device *dev, struct device_attribute *devattr, | |||
350 | static ssize_t set_enable(struct device *dev, struct device_attribute *devattr, | 370 | static ssize_t set_enable(struct device *dev, struct device_attribute *devattr, |
351 | const char *buf, size_t count) | 371 | const char *buf, size_t count) |
352 | { | 372 | { |
353 | struct i2c_client *client = to_i2c_client(dev); | 373 | struct max6650_data *data = dev_get_drvdata(dev); |
354 | struct max6650_data *data = i2c_get_clientdata(client); | 374 | struct i2c_client *client = data->client; |
355 | int max6650_modes[3] = {0, 3, 2}; | 375 | int max6650_modes[3] = {0, 3, 2}; |
356 | unsigned long mode; | 376 | unsigned long mode; |
357 | int err; | 377 | int err; |
@@ -400,8 +420,8 @@ static ssize_t get_div(struct device *dev, struct device_attribute *devattr, | |||
400 | static ssize_t set_div(struct device *dev, struct device_attribute *devattr, | 420 | static ssize_t set_div(struct device *dev, struct device_attribute *devattr, |
401 | const char *buf, size_t count) | 421 | const char *buf, size_t count) |
402 | { | 422 | { |
403 | struct i2c_client *client = to_i2c_client(dev); | 423 | struct max6650_data *data = dev_get_drvdata(dev); |
404 | struct max6650_data *data = i2c_get_clientdata(client); | 424 | struct i2c_client *client = data->client; |
405 | unsigned long div; | 425 | unsigned long div; |
406 | int err; | 426 | int err; |
407 | 427 | ||
@@ -446,7 +466,7 @@ static ssize_t get_alarm(struct device *dev, struct device_attribute *devattr, | |||
446 | { | 466 | { |
447 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 467 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
448 | struct max6650_data *data = max6650_update_device(dev); | 468 | struct max6650_data *data = max6650_update_device(dev); |
449 | struct i2c_client *client = to_i2c_client(dev); | 469 | struct i2c_client *client = data->client; |
450 | int alarm = 0; | 470 | int alarm = 0; |
451 | 471 | ||
452 | if (data->alarm & attr->index) { | 472 | if (data->alarm & attr->index) { |
@@ -484,7 +504,8 @@ static umode_t max6650_attrs_visible(struct kobject *kobj, struct attribute *a, | |||
484 | int n) | 504 | int n) |
485 | { | 505 | { |
486 | struct device *dev = container_of(kobj, struct device, kobj); | 506 | struct device *dev = container_of(kobj, struct device, kobj); |
487 | struct i2c_client *client = to_i2c_client(dev); | 507 | struct max6650_data *data = dev_get_drvdata(dev); |
508 | struct i2c_client *client = data->client; | ||
488 | u8 alarm_en = i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM_EN); | 509 | u8 alarm_en = i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM_EN); |
489 | struct device_attribute *devattr; | 510 | struct device_attribute *devattr; |
490 | 511 | ||
@@ -519,7 +540,7 @@ static struct attribute *max6650_attrs[] = { | |||
519 | NULL | 540 | NULL |
520 | }; | 541 | }; |
521 | 542 | ||
522 | static struct attribute_group max6650_attr_grp = { | 543 | static const struct attribute_group max6650_group = { |
523 | .attrs = max6650_attrs, | 544 | .attrs = max6650_attrs, |
524 | .is_visible = max6650_attrs_visible, | 545 | .is_visible = max6650_attrs_visible, |
525 | }; | 546 | }; |
@@ -531,7 +552,7 @@ static struct attribute *max6651_attrs[] = { | |||
531 | NULL | 552 | NULL |
532 | }; | 553 | }; |
533 | 554 | ||
534 | static const struct attribute_group max6651_attr_grp = { | 555 | static const struct attribute_group max6651_group = { |
535 | .attrs = max6651_attrs, | 556 | .attrs = max6651_attrs, |
536 | }; | 557 | }; |
537 | 558 | ||
@@ -539,74 +560,17 @@ static const struct attribute_group max6651_attr_grp = { | |||
539 | * Real code | 560 | * Real code |
540 | */ | 561 | */ |
541 | 562 | ||
542 | static int max6650_probe(struct i2c_client *client, | 563 | static int max6650_init_client(struct max6650_data *data, |
543 | const struct i2c_device_id *id) | 564 | struct i2c_client *client) |
544 | { | ||
545 | struct max6650_data *data; | ||
546 | int err; | ||
547 | |||
548 | data = devm_kzalloc(&client->dev, sizeof(struct max6650_data), | ||
549 | GFP_KERNEL); | ||
550 | if (!data) { | ||
551 | dev_err(&client->dev, "out of memory.\n"); | ||
552 | return -ENOMEM; | ||
553 | } | ||
554 | |||
555 | i2c_set_clientdata(client, data); | ||
556 | mutex_init(&data->update_lock); | ||
557 | data->nr_fans = id->driver_data; | ||
558 | |||
559 | /* | ||
560 | * Initialize the max6650 chip | ||
561 | */ | ||
562 | err = max6650_init_client(client); | ||
563 | if (err) | ||
564 | return err; | ||
565 | |||
566 | err = sysfs_create_group(&client->dev.kobj, &max6650_attr_grp); | ||
567 | if (err) | ||
568 | return err; | ||
569 | /* 3 additional fan inputs for the MAX6651 */ | ||
570 | if (data->nr_fans == 4) { | ||
571 | err = sysfs_create_group(&client->dev.kobj, &max6651_attr_grp); | ||
572 | if (err) | ||
573 | goto err_remove; | ||
574 | } | ||
575 | |||
576 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
577 | if (!IS_ERR(data->hwmon_dev)) | ||
578 | return 0; | ||
579 | |||
580 | err = PTR_ERR(data->hwmon_dev); | ||
581 | dev_err(&client->dev, "error registering hwmon device.\n"); | ||
582 | if (data->nr_fans == 4) | ||
583 | sysfs_remove_group(&client->dev.kobj, &max6651_attr_grp); | ||
584 | err_remove: | ||
585 | sysfs_remove_group(&client->dev.kobj, &max6650_attr_grp); | ||
586 | return err; | ||
587 | } | ||
588 | |||
589 | static int max6650_remove(struct i2c_client *client) | ||
590 | { | 565 | { |
591 | struct max6650_data *data = i2c_get_clientdata(client); | 566 | struct device *dev = &client->dev; |
592 | |||
593 | hwmon_device_unregister(data->hwmon_dev); | ||
594 | if (data->nr_fans == 4) | ||
595 | sysfs_remove_group(&client->dev.kobj, &max6651_attr_grp); | ||
596 | sysfs_remove_group(&client->dev.kobj, &max6650_attr_grp); | ||
597 | return 0; | ||
598 | } | ||
599 | |||
600 | static int max6650_init_client(struct i2c_client *client) | ||
601 | { | ||
602 | struct max6650_data *data = i2c_get_clientdata(client); | ||
603 | int config; | 567 | int config; |
604 | int err = -EIO; | 568 | int err = -EIO; |
605 | 569 | ||
606 | config = i2c_smbus_read_byte_data(client, MAX6650_REG_CONFIG); | 570 | config = i2c_smbus_read_byte_data(client, MAX6650_REG_CONFIG); |
607 | 571 | ||
608 | if (config < 0) { | 572 | if (config < 0) { |
609 | dev_err(&client->dev, "Error reading config, aborting.\n"); | 573 | dev_err(dev, "Error reading config, aborting.\n"); |
610 | return err; | 574 | return err; |
611 | } | 575 | } |
612 | 576 | ||
@@ -620,11 +584,11 @@ static int max6650_init_client(struct i2c_client *client) | |||
620 | config |= MAX6650_CFG_V12; | 584 | config |= MAX6650_CFG_V12; |
621 | break; | 585 | break; |
622 | default: | 586 | default: |
623 | dev_err(&client->dev, "illegal value for fan_voltage (%d)\n", | 587 | dev_err(dev, "illegal value for fan_voltage (%d)\n", |
624 | fan_voltage); | 588 | fan_voltage); |
625 | } | 589 | } |
626 | 590 | ||
627 | dev_info(&client->dev, "Fan voltage is set to %dV.\n", | 591 | dev_info(dev, "Fan voltage is set to %dV.\n", |
628 | (config & MAX6650_CFG_V12) ? 12 : 5); | 592 | (config & MAX6650_CFG_V12) ? 12 : 5); |
629 | 593 | ||
630 | switch (prescaler) { | 594 | switch (prescaler) { |
@@ -650,11 +614,10 @@ static int max6650_init_client(struct i2c_client *client) | |||
650 | | MAX6650_CFG_PRESCALER_16; | 614 | | MAX6650_CFG_PRESCALER_16; |
651 | break; | 615 | break; |
652 | default: | 616 | default: |
653 | dev_err(&client->dev, "illegal value for prescaler (%d)\n", | 617 | dev_err(dev, "illegal value for prescaler (%d)\n", prescaler); |
654 | prescaler); | ||
655 | } | 618 | } |
656 | 619 | ||
657 | dev_info(&client->dev, "Prescaler is set to %d.\n", | 620 | dev_info(dev, "Prescaler is set to %d.\n", |
658 | 1 << (config & MAX6650_CFG_PRESCALER_MASK)); | 621 | 1 << (config & MAX6650_CFG_PRESCALER_MASK)); |
659 | 622 | ||
660 | /* | 623 | /* |
@@ -664,17 +627,17 @@ static int max6650_init_client(struct i2c_client *client) | |||
664 | */ | 627 | */ |
665 | 628 | ||
666 | if ((config & MAX6650_CFG_MODE_MASK) == MAX6650_CFG_MODE_OFF) { | 629 | if ((config & MAX6650_CFG_MODE_MASK) == MAX6650_CFG_MODE_OFF) { |
667 | dev_dbg(&client->dev, "Change mode to open loop, full off.\n"); | 630 | dev_dbg(dev, "Change mode to open loop, full off.\n"); |
668 | config = (config & ~MAX6650_CFG_MODE_MASK) | 631 | config = (config & ~MAX6650_CFG_MODE_MASK) |
669 | | MAX6650_CFG_MODE_OPEN_LOOP; | 632 | | MAX6650_CFG_MODE_OPEN_LOOP; |
670 | if (i2c_smbus_write_byte_data(client, MAX6650_REG_DAC, 255)) { | 633 | if (i2c_smbus_write_byte_data(client, MAX6650_REG_DAC, 255)) { |
671 | dev_err(&client->dev, "DAC write error, aborting.\n"); | 634 | dev_err(dev, "DAC write error, aborting.\n"); |
672 | return err; | 635 | return err; |
673 | } | 636 | } |
674 | } | 637 | } |
675 | 638 | ||
676 | if (i2c_smbus_write_byte_data(client, MAX6650_REG_CONFIG, config)) { | 639 | if (i2c_smbus_write_byte_data(client, MAX6650_REG_CONFIG, config)) { |
677 | dev_err(&client->dev, "Config write error, aborting.\n"); | 640 | dev_err(dev, "Config write error, aborting.\n"); |
678 | return err; | 641 | return err; |
679 | } | 642 | } |
680 | 643 | ||
@@ -684,51 +647,55 @@ static int max6650_init_client(struct i2c_client *client) | |||
684 | return 0; | 647 | return 0; |
685 | } | 648 | } |
686 | 649 | ||
687 | static const u8 tach_reg[] = { | 650 | static int max6650_probe(struct i2c_client *client, |
688 | MAX6650_REG_TACH0, | 651 | const struct i2c_device_id *id) |
689 | MAX6650_REG_TACH1, | ||
690 | MAX6650_REG_TACH2, | ||
691 | MAX6650_REG_TACH3, | ||
692 | }; | ||
693 | |||
694 | static struct max6650_data *max6650_update_device(struct device *dev) | ||
695 | { | 652 | { |
696 | int i; | 653 | struct device *dev = &client->dev; |
697 | struct i2c_client *client = to_i2c_client(dev); | 654 | struct max6650_data *data; |
698 | struct max6650_data *data = i2c_get_clientdata(client); | 655 | struct device *hwmon_dev; |
699 | 656 | int err; | |
700 | mutex_lock(&data->update_lock); | ||
701 | 657 | ||
702 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { | 658 | data = devm_kzalloc(dev, sizeof(struct max6650_data), GFP_KERNEL); |
703 | data->speed = i2c_smbus_read_byte_data(client, | 659 | if (!data) |
704 | MAX6650_REG_SPEED); | 660 | return -ENOMEM; |
705 | data->config = i2c_smbus_read_byte_data(client, | ||
706 | MAX6650_REG_CONFIG); | ||
707 | for (i = 0; i < data->nr_fans; i++) { | ||
708 | data->tach[i] = i2c_smbus_read_byte_data(client, | ||
709 | tach_reg[i]); | ||
710 | } | ||
711 | data->count = i2c_smbus_read_byte_data(client, | ||
712 | MAX6650_REG_COUNT); | ||
713 | data->dac = i2c_smbus_read_byte_data(client, MAX6650_REG_DAC); | ||
714 | 661 | ||
715 | /* | 662 | data->client = client; |
716 | * Alarms are cleared on read in case the condition that | 663 | mutex_init(&data->update_lock); |
717 | * caused the alarm is removed. Keep the value latched here | 664 | data->nr_fans = id->driver_data; |
718 | * for providing the register through different alarm files. | ||
719 | */ | ||
720 | data->alarm |= i2c_smbus_read_byte_data(client, | ||
721 | MAX6650_REG_ALARM); | ||
722 | 665 | ||
723 | data->last_updated = jiffies; | 666 | /* |
724 | data->valid = 1; | 667 | * Initialize the max6650 chip |
725 | } | 668 | */ |
669 | err = max6650_init_client(data, client); | ||
670 | if (err) | ||
671 | return err; | ||
726 | 672 | ||
727 | mutex_unlock(&data->update_lock); | 673 | data->groups[0] = &max6650_group; |
674 | /* 3 additional fan inputs for the MAX6651 */ | ||
675 | if (data->nr_fans == 4) | ||
676 | data->groups[1] = &max6651_group; | ||
728 | 677 | ||
729 | return data; | 678 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, |
679 | client->name, data, | ||
680 | data->groups); | ||
681 | return PTR_ERR_OR_ZERO(hwmon_dev); | ||
730 | } | 682 | } |
731 | 683 | ||
684 | static const struct i2c_device_id max6650_id[] = { | ||
685 | { "max6650", 1 }, | ||
686 | { "max6651", 4 }, | ||
687 | { } | ||
688 | }; | ||
689 | MODULE_DEVICE_TABLE(i2c, max6650_id); | ||
690 | |||
691 | static struct i2c_driver max6650_driver = { | ||
692 | .driver = { | ||
693 | .name = "max6650", | ||
694 | }, | ||
695 | .probe = max6650_probe, | ||
696 | .id_table = max6650_id, | ||
697 | }; | ||
698 | |||
732 | module_i2c_driver(max6650_driver); | 699 | module_i2c_driver(max6650_driver); |
733 | 700 | ||
734 | MODULE_AUTHOR("Hans J. Koch"); | 701 | MODULE_AUTHOR("Hans J. Koch"); |
diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c index 330fe117e219..988181e4cfcd 100644 --- a/drivers/hwmon/pc87360.c +++ b/drivers/hwmon/pc87360.c | |||
@@ -1225,7 +1225,7 @@ static int pc87360_probe(struct platform_device *pdev) | |||
1225 | int i; | 1225 | int i; |
1226 | struct pc87360_data *data; | 1226 | struct pc87360_data *data; |
1227 | int err = 0; | 1227 | int err = 0; |
1228 | const char *name = "pc87360"; | 1228 | const char *name; |
1229 | int use_thermistors = 0; | 1229 | int use_thermistors = 0; |
1230 | struct device *dev = &pdev->dev; | 1230 | struct device *dev = &pdev->dev; |
1231 | 1231 | ||
@@ -1233,13 +1233,14 @@ static int pc87360_probe(struct platform_device *pdev) | |||
1233 | if (!data) | 1233 | if (!data) |
1234 | return -ENOMEM; | 1234 | return -ENOMEM; |
1235 | 1235 | ||
1236 | data->fannr = 2; | ||
1237 | data->innr = 0; | ||
1238 | data->tempnr = 0; | ||
1239 | |||
1240 | switch (devid) { | 1236 | switch (devid) { |
1237 | default: | ||
1238 | name = "pc87360"; | ||
1239 | data->fannr = 2; | ||
1240 | break; | ||
1241 | case 0xe8: | 1241 | case 0xe8: |
1242 | name = "pc87363"; | 1242 | name = "pc87363"; |
1243 | data->fannr = 2; | ||
1243 | break; | 1244 | break; |
1244 | case 0xe4: | 1245 | case 0xe4: |
1245 | name = "pc87364"; | 1246 | name = "pc87364"; |
@@ -1260,7 +1261,6 @@ static int pc87360_probe(struct platform_device *pdev) | |||
1260 | } | 1261 | } |
1261 | 1262 | ||
1262 | data->name = name; | 1263 | data->name = name; |
1263 | data->valid = 0; | ||
1264 | mutex_init(&data->lock); | 1264 | mutex_init(&data->lock); |
1265 | mutex_init(&data->update_lock); | 1265 | mutex_init(&data->update_lock); |
1266 | platform_set_drvdata(pdev, data); | 1266 | platform_set_drvdata(pdev, data); |
diff --git a/drivers/hwmon/pmbus/ltc2978.c b/drivers/hwmon/pmbus/ltc2978.c index de3c152a1d9a..e24ed521051a 100644 --- a/drivers/hwmon/pmbus/ltc2978.c +++ b/drivers/hwmon/pmbus/ltc2978.c | |||
@@ -1,9 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * Hardware monitoring driver for LTC2974, LTC2977, LTC2978, LTC3880, | 2 | * Hardware monitoring driver for LTC2974, LTC2977, LTC2978, LTC3880, |
3 | * and LTC3883 | 3 | * LTC3883, and LTM4676 |
4 | * | 4 | * |
5 | * Copyright (c) 2011 Ericsson AB. | 5 | * Copyright (c) 2011 Ericsson AB. |
6 | * Copyright (c) 2013 Guenter Roeck | 6 | * Copyright (c) 2013, 2014 Guenter Roeck |
7 | * | 7 | * |
8 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
@@ -14,10 +14,6 @@ | |||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. | 16 | * GNU General Public License for more details. |
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
21 | */ | 17 | */ |
22 | 18 | ||
23 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
@@ -28,7 +24,7 @@ | |||
28 | #include <linux/i2c.h> | 24 | #include <linux/i2c.h> |
29 | #include "pmbus.h" | 25 | #include "pmbus.h" |
30 | 26 | ||
31 | enum chips { ltc2974, ltc2977, ltc2978, ltc3880, ltc3883 }; | 27 | enum chips { ltc2974, ltc2977, ltc2978, ltc3880, ltc3883, ltm4676 }; |
32 | 28 | ||
33 | /* Common for all chips */ | 29 | /* Common for all chips */ |
34 | #define LTC2978_MFR_VOUT_PEAK 0xdd | 30 | #define LTC2978_MFR_VOUT_PEAK 0xdd |
@@ -45,7 +41,7 @@ enum chips { ltc2974, ltc2977, ltc2978, ltc3880, ltc3883 }; | |||
45 | #define LTC2974_MFR_IOUT_PEAK 0xd7 | 41 | #define LTC2974_MFR_IOUT_PEAK 0xd7 |
46 | #define LTC2974_MFR_IOUT_MIN 0xd8 | 42 | #define LTC2974_MFR_IOUT_MIN 0xd8 |
47 | 43 | ||
48 | /* LTC3880 and LTC3883 */ | 44 | /* LTC3880, LTC3883, and LTM4676 */ |
49 | #define LTC3880_MFR_IOUT_PEAK 0xd7 | 45 | #define LTC3880_MFR_IOUT_PEAK 0xd7 |
50 | #define LTC3880_MFR_CLEAR_PEAKS 0xe3 | 46 | #define LTC3880_MFR_CLEAR_PEAKS 0xe3 |
51 | #define LTC3880_MFR_TEMPERATURE2_PEAK 0xf4 | 47 | #define LTC3880_MFR_TEMPERATURE2_PEAK 0xf4 |
@@ -53,7 +49,8 @@ enum chips { ltc2974, ltc2977, ltc2978, ltc3880, ltc3883 }; | |||
53 | /* LTC3883 only */ | 49 | /* LTC3883 only */ |
54 | #define LTC3883_MFR_IIN_PEAK 0xe1 | 50 | #define LTC3883_MFR_IIN_PEAK 0xe1 |
55 | 51 | ||
56 | #define LTC2974_ID 0x0212 | 52 | #define LTC2974_ID_REV1 0x0212 |
53 | #define LTC2974_ID_REV2 0x0213 | ||
57 | #define LTC2977_ID 0x0130 | 54 | #define LTC2977_ID 0x0130 |
58 | #define LTC2978_ID_REV1 0x0121 | 55 | #define LTC2978_ID_REV1 0x0121 |
59 | #define LTC2978_ID_REV2 0x0122 | 56 | #define LTC2978_ID_REV2 0x0122 |
@@ -62,6 +59,8 @@ enum chips { ltc2974, ltc2977, ltc2978, ltc3880, ltc3883 }; | |||
62 | #define LTC3880_ID_MASK 0xff00 | 59 | #define LTC3880_ID_MASK 0xff00 |
63 | #define LTC3883_ID 0x4300 | 60 | #define LTC3883_ID 0x4300 |
64 | #define LTC3883_ID_MASK 0xff00 | 61 | #define LTC3883_ID_MASK 0xff00 |
62 | #define LTM4676_ID 0x4480 /* datasheet claims 0x440X */ | ||
63 | #define LTM4676_ID_MASK 0xfff0 | ||
65 | 64 | ||
66 | #define LTC2974_NUM_PAGES 4 | 65 | #define LTC2974_NUM_PAGES 4 |
67 | #define LTC2978_NUM_PAGES 8 | 66 | #define LTC2978_NUM_PAGES 8 |
@@ -370,6 +369,7 @@ static const struct i2c_device_id ltc2978_id[] = { | |||
370 | {"ltc2978", ltc2978}, | 369 | {"ltc2978", ltc2978}, |
371 | {"ltc3880", ltc3880}, | 370 | {"ltc3880", ltc3880}, |
372 | {"ltc3883", ltc3883}, | 371 | {"ltc3883", ltc3883}, |
372 | {"ltm4676", ltm4676}, | ||
373 | {} | 373 | {} |
374 | }; | 374 | }; |
375 | MODULE_DEVICE_TABLE(i2c, ltc2978_id); | 375 | MODULE_DEVICE_TABLE(i2c, ltc2978_id); |
@@ -394,7 +394,7 @@ static int ltc2978_probe(struct i2c_client *client, | |||
394 | if (chip_id < 0) | 394 | if (chip_id < 0) |
395 | return chip_id; | 395 | return chip_id; |
396 | 396 | ||
397 | if (chip_id == LTC2974_ID) { | 397 | if (chip_id == LTC2974_ID_REV1 || chip_id == LTC2974_ID_REV2) { |
398 | data->id = ltc2974; | 398 | data->id = ltc2974; |
399 | } else if (chip_id == LTC2977_ID) { | 399 | } else if (chip_id == LTC2977_ID) { |
400 | data->id = ltc2977; | 400 | data->id = ltc2977; |
@@ -405,6 +405,8 @@ static int ltc2978_probe(struct i2c_client *client, | |||
405 | data->id = ltc3880; | 405 | data->id = ltc3880; |
406 | } else if ((chip_id & LTC3883_ID_MASK) == LTC3883_ID) { | 406 | } else if ((chip_id & LTC3883_ID_MASK) == LTC3883_ID) { |
407 | data->id = ltc3883; | 407 | data->id = ltc3883; |
408 | } else if ((chip_id & LTM4676_ID_MASK) == LTM4676_ID) { | ||
409 | data->id = ltm4676; | ||
408 | } else { | 410 | } else { |
409 | dev_err(&client->dev, "Unsupported chip ID 0x%x\n", chip_id); | 411 | dev_err(&client->dev, "Unsupported chip ID 0x%x\n", chip_id); |
410 | return -ENODEV; | 412 | return -ENODEV; |
@@ -458,6 +460,7 @@ static int ltc2978_probe(struct i2c_client *client, | |||
458 | } | 460 | } |
459 | break; | 461 | break; |
460 | case ltc3880: | 462 | case ltc3880: |
463 | case ltm4676: | ||
461 | info->read_word_data = ltc3880_read_word_data; | 464 | info->read_word_data = ltc3880_read_word_data; |
462 | info->pages = LTC3880_NUM_PAGES; | 465 | info->pages = LTC3880_NUM_PAGES; |
463 | info->func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_IIN | 466 | info->func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_IIN |
@@ -500,5 +503,5 @@ static struct i2c_driver ltc2978_driver = { | |||
500 | module_i2c_driver(ltc2978_driver); | 503 | module_i2c_driver(ltc2978_driver); |
501 | 504 | ||
502 | MODULE_AUTHOR("Guenter Roeck"); | 505 | MODULE_AUTHOR("Guenter Roeck"); |
503 | MODULE_DESCRIPTION("PMBus driver for LTC2974, LTC2978, LTC3880, and LTC3883"); | 506 | MODULE_DESCRIPTION("PMBus driver for LTC2974, LTC2978, LTC3880, LTC3883, and LTM4676"); |
504 | MODULE_LICENSE("GPL"); | 507 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/hwmon/smm665.c b/drivers/hwmon/smm665.c index d9e1b7de78da..4ef5802df6d8 100644 --- a/drivers/hwmon/smm665.c +++ b/drivers/hwmon/smm665.c | |||
@@ -222,7 +222,7 @@ static int smm665_read_adc(struct smm665_data *data, int adc) | |||
222 | rv = i2c_smbus_read_word_swapped(client, 0); | 222 | rv = i2c_smbus_read_word_swapped(client, 0); |
223 | if (rv < 0) { | 223 | if (rv < 0) { |
224 | dev_dbg(&client->dev, "Failed to read ADC value: error %d", rv); | 224 | dev_dbg(&client->dev, "Failed to read ADC value: error %d", rv); |
225 | return -1; | 225 | return rv; |
226 | } | 226 | } |
227 | /* | 227 | /* |
228 | * Validate/verify readback adc channel (in bit 11..14). | 228 | * Validate/verify readback adc channel (in bit 11..14). |
diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c index 38944e94f65f..8df43c51de2c 100644 --- a/drivers/hwmon/via-cputemp.c +++ b/drivers/hwmon/via-cputemp.c | |||
@@ -319,7 +319,7 @@ static int __init via_cputemp_init(void) | |||
319 | if (err) | 319 | if (err) |
320 | goto exit; | 320 | goto exit; |
321 | 321 | ||
322 | get_online_cpus(); | 322 | cpu_notifier_register_begin(); |
323 | for_each_online_cpu(i) { | 323 | for_each_online_cpu(i) { |
324 | struct cpuinfo_x86 *c = &cpu_data(i); | 324 | struct cpuinfo_x86 *c = &cpu_data(i); |
325 | 325 | ||
@@ -339,14 +339,14 @@ static int __init via_cputemp_init(void) | |||
339 | 339 | ||
340 | #ifndef CONFIG_HOTPLUG_CPU | 340 | #ifndef CONFIG_HOTPLUG_CPU |
341 | if (list_empty(&pdev_list)) { | 341 | if (list_empty(&pdev_list)) { |
342 | put_online_cpus(); | 342 | cpu_notifier_register_done(); |
343 | err = -ENODEV; | 343 | err = -ENODEV; |
344 | goto exit_driver_unreg; | 344 | goto exit_driver_unreg; |
345 | } | 345 | } |
346 | #endif | 346 | #endif |
347 | 347 | ||
348 | register_hotcpu_notifier(&via_cputemp_cpu_notifier); | 348 | __register_hotcpu_notifier(&via_cputemp_cpu_notifier); |
349 | put_online_cpus(); | 349 | cpu_notifier_register_done(); |
350 | return 0; | 350 | return 0; |
351 | 351 | ||
352 | #ifndef CONFIG_HOTPLUG_CPU | 352 | #ifndef CONFIG_HOTPLUG_CPU |
@@ -361,8 +361,8 @@ static void __exit via_cputemp_exit(void) | |||
361 | { | 361 | { |
362 | struct pdev_entry *p, *n; | 362 | struct pdev_entry *p, *n; |
363 | 363 | ||
364 | get_online_cpus(); | 364 | cpu_notifier_register_begin(); |
365 | unregister_hotcpu_notifier(&via_cputemp_cpu_notifier); | 365 | __unregister_hotcpu_notifier(&via_cputemp_cpu_notifier); |
366 | mutex_lock(&pdev_list_mutex); | 366 | mutex_lock(&pdev_list_mutex); |
367 | list_for_each_entry_safe(p, n, &pdev_list, list) { | 367 | list_for_each_entry_safe(p, n, &pdev_list, list) { |
368 | platform_device_unregister(p->pdev); | 368 | platform_device_unregister(p->pdev); |
@@ -370,7 +370,7 @@ static void __exit via_cputemp_exit(void) | |||
370 | kfree(p); | 370 | kfree(p); |
371 | } | 371 | } |
372 | mutex_unlock(&pdev_list_mutex); | 372 | mutex_unlock(&pdev_list_mutex); |
373 | put_online_cpus(); | 373 | cpu_notifier_register_done(); |
374 | platform_driver_unregister(&via_cputemp_driver); | 374 | platform_driver_unregister(&via_cputemp_driver); |
375 | } | 375 | } |
376 | 376 | ||
diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c index df585808adb6..4068db4d9580 100644 --- a/drivers/hwmon/w83792d.c +++ b/drivers/hwmon/w83792d.c | |||
@@ -1376,7 +1376,6 @@ w83792d_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
1376 | return -ENOMEM; | 1376 | return -ENOMEM; |
1377 | 1377 | ||
1378 | i2c_set_clientdata(client, data); | 1378 | i2c_set_clientdata(client, data); |
1379 | data->valid = 0; | ||
1380 | mutex_init(&data->update_lock); | 1379 | mutex_init(&data->update_lock); |
1381 | 1380 | ||
1382 | err = w83792d_detect_subclients(client); | 1381 | err = w83792d_detect_subclients(client); |
diff --git a/drivers/hwmon/w83l785ts.c b/drivers/hwmon/w83l785ts.c index 6384b268f590..ac3043122011 100644 --- a/drivers/hwmon/w83l785ts.c +++ b/drivers/hwmon/w83l785ts.c | |||
@@ -188,12 +188,8 @@ static int w83l785ts_probe(struct i2c_client *client, | |||
188 | return -ENOMEM; | 188 | return -ENOMEM; |
189 | 189 | ||
190 | i2c_set_clientdata(client, data); | 190 | i2c_set_clientdata(client, data); |
191 | data->valid = 0; | ||
192 | mutex_init(&data->update_lock); | 191 | mutex_init(&data->update_lock); |
193 | 192 | ||
194 | /* Default values in case the first read fails (unlikely). */ | ||
195 | data->temp[1] = data->temp[0] = 0; | ||
196 | |||
197 | /* | 193 | /* |
198 | * Initialize the W83L785TS chip | 194 | * Initialize the W83L785TS chip |
199 | * Nothing yet, assume it is already started. | 195 | * Nothing yet, assume it is already started. |