aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/Kconfig141
-rw-r--r--drivers/hwmon/Makefile9
-rw-r--r--drivers/hwmon/ad7414.c1
-rw-r--r--drivers/hwmon/ad7418.c1
-rw-r--r--drivers/hwmon/adcxx.c16
-rw-r--r--drivers/hwmon/adm1021.c87
-rw-r--r--drivers/hwmon/adm1025.c85
-rw-r--r--drivers/hwmon/adm1026.c58
-rw-r--r--drivers/hwmon/adm1029.c71
-rw-r--r--drivers/hwmon/adm1031.c35
-rw-r--r--drivers/hwmon/adm9240.c70
-rw-r--r--drivers/hwmon/ads7828.c35
-rw-r--r--drivers/hwmon/adt7411.c367
-rw-r--r--drivers/hwmon/adt7462.c41
-rw-r--r--drivers/hwmon/adt7470.c37
-rw-r--r--drivers/hwmon/adt7473.c1187
-rw-r--r--drivers/hwmon/adt7475.c542
-rw-r--r--drivers/hwmon/amc6821.c1115
-rw-r--r--drivers/hwmon/ams/ams-core.c11
-rw-r--r--drivers/hwmon/ams/ams-i2c.c2
-rw-r--r--drivers/hwmon/ams/ams-pmu.c2
-rw-r--r--drivers/hwmon/ams/ams.h1
-rw-r--r--drivers/hwmon/applesmc.c81
-rw-r--r--drivers/hwmon/asb100.c66
-rw-r--r--drivers/hwmon/asc7621.c1254
-rw-r--r--drivers/hwmon/asus_atk0110.c309
-rw-r--r--drivers/hwmon/atxp1.c12
-rw-r--r--drivers/hwmon/coretemp.c20
-rw-r--r--drivers/hwmon/dme1737.c42
-rw-r--r--drivers/hwmon/ds1621.c31
-rw-r--r--drivers/hwmon/f71882fg.c350
-rw-r--r--drivers/hwmon/f75375s.c42
-rw-r--r--drivers/hwmon/fschmd.c82
-rw-r--r--drivers/hwmon/g760a.c2
-rw-r--r--drivers/hwmon/gl518sm.c40
-rw-r--r--drivers/hwmon/gl520sm.c25
-rw-r--r--drivers/hwmon/hp_accel.c6
-rw-r--r--drivers/hwmon/i5k_amb.c1
-rw-r--r--drivers/hwmon/ibmaem.c1
-rw-r--r--drivers/hwmon/ibmpex.c1
-rw-r--r--drivers/hwmon/it87.c1012
-rw-r--r--drivers/hwmon/k10temp.c223
-rw-r--r--drivers/hwmon/k8temp.c2
-rw-r--r--drivers/hwmon/lis3lv02d.c231
-rw-r--r--drivers/hwmon/lis3lv02d.h51
-rw-r--r--drivers/hwmon/lis3lv02d_i2c.c183
-rw-r--r--drivers/hwmon/lm63.c69
-rw-r--r--drivers/hwmon/lm70.c1
-rw-r--r--drivers/hwmon/lm73.c201
-rw-r--r--drivers/hwmon/lm75.c70
-rw-r--r--drivers/hwmon/lm77.c92
-rw-r--r--drivers/hwmon/lm78.c90
-rw-r--r--drivers/hwmon/lm80.c13
-rw-r--r--drivers/hwmon/lm83.c93
-rw-r--r--drivers/hwmon/lm85.c173
-rw-r--r--drivers/hwmon/lm87.c53
-rw-r--r--drivers/hwmon/lm90.c327
-rw-r--r--drivers/hwmon/lm92.c40
-rw-r--r--drivers/hwmon/lm93.c42
-rw-r--r--drivers/hwmon/lm95241.c57
-rw-r--r--drivers/hwmon/max1111.c1
-rw-r--r--drivers/hwmon/max1619.c76
-rw-r--r--drivers/hwmon/max6650.c30
-rw-r--r--drivers/hwmon/mc13783-adc.c237
-rw-r--r--drivers/hwmon/pcf8591.c5
-rw-r--r--drivers/hwmon/s3c-hwmon.c4
-rw-r--r--drivers/hwmon/sht15.c18
-rw-r--r--drivers/hwmon/sis5595.c2
-rw-r--r--drivers/hwmon/smsc47m1.c153
-rw-r--r--drivers/hwmon/smsc47m192.c39
-rw-r--r--drivers/hwmon/thmc50.c45
-rw-r--r--drivers/hwmon/tmp401.c69
-rw-r--r--drivers/hwmon/tmp421.c74
-rw-r--r--drivers/hwmon/via-cputemp.c356
-rw-r--r--drivers/hwmon/via686a.c2
-rw-r--r--drivers/hwmon/vt8231.c5
-rw-r--r--drivers/hwmon/w83627ehf.c72
-rw-r--r--drivers/hwmon/w83627hf.c96
-rw-r--r--drivers/hwmon/w83781d.c167
-rw-r--r--drivers/hwmon/w83791d.c69
-rw-r--r--drivers/hwmon/w83792d.c70
-rw-r--r--drivers/hwmon/w83793.c544
-rw-r--r--drivers/hwmon/w83l785ts.c82
-rw-r--r--drivers/hwmon/w83l786ng.c66
-rw-r--r--drivers/hwmon/wm831x-hwmon.c1
85 files changed, 7891 insertions, 3694 deletions
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 700e93adeb33..9be8e1754a0b 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -170,6 +170,16 @@ config SENSORS_ADM9240
170 This driver can also be built as a module. If so, the module 170 This driver can also be built as a module. If so, the module
171 will be called adm9240. 171 will be called adm9240.
172 172
173config SENSORS_ADT7411
174 tristate "Analog Devices ADT7411"
175 depends on I2C && EXPERIMENTAL
176 help
177 If you say yes here you get support for the Analog Devices
178 ADT7411 voltage and temperature monitoring chip.
179
180 This driver can also be built as a module. If so, the module
181 will be called adt7411.
182
173config SENSORS_ADT7462 183config SENSORS_ADT7462
174 tristate "Analog Devices ADT7462" 184 tristate "Analog Devices ADT7462"
175 depends on I2C && EXPERIMENTAL 185 depends on I2C && EXPERIMENTAL
@@ -190,26 +200,31 @@ config SENSORS_ADT7470
190 This driver can also be built as a module. If so, the module 200 This driver can also be built as a module. If so, the module
191 will be called adt7470. 201 will be called adt7470.
192 202
193config SENSORS_ADT7473
194 tristate "Analog Devices ADT7473"
195 depends on I2C && EXPERIMENTAL
196 help
197 If you say yes here you get support for the Analog Devices
198 ADT7473 temperature monitoring chips.
199
200 This driver can also be built as a module. If so, the module
201 will be called adt7473.
202
203config SENSORS_ADT7475 203config SENSORS_ADT7475
204 tristate "Analog Devices ADT7475" 204 tristate "Analog Devices ADT7473, ADT7475, ADT7476 and ADT7490"
205 depends on I2C && EXPERIMENTAL 205 depends on I2C && EXPERIMENTAL
206 select HWMON_VID
206 help 207 help
207 If you say yes here you get support for the Analog Devices 208 If you say yes here you get support for the Analog Devices
208 ADT7475 hardware monitoring chips. 209 ADT7473, ADT7475, ADT7476 and ADT7490 hardware monitoring
210 chips.
209 211
210 This driver can also be build as a module. If so, the module 212 This driver can also be build as a module. If so, the module
211 will be called adt7475. 213 will be called adt7475.
212 214
215config SENSORS_ASC7621
216 tristate "Andigilog aSC7621"
217 depends on HWMON && I2C
218 help
219 If you say yes here you get support for the aSC7621
220 family of SMBus sensors chip found on most Intel X38, X48, X58,
221 945, 965 and 975 desktop boards. Currently supported chips:
222 aSC7621
223 aSC7621a
224
225 This driver can also be built as a module. If so, the module
226 will be called asc7621.
227
213config SENSORS_K8TEMP 228config SENSORS_K8TEMP
214 tristate "AMD Athlon64/FX or Opteron temperature sensor" 229 tristate "AMD Athlon64/FX or Opteron temperature sensor"
215 depends on X86 && PCI && EXPERIMENTAL 230 depends on X86 && PCI && EXPERIMENTAL
@@ -222,6 +237,18 @@ config SENSORS_K8TEMP
222 This driver can also be built as a module. If so, the module 237 This driver can also be built as a module. If so, the module
223 will be called k8temp. 238 will be called k8temp.
224 239
240config SENSORS_K10TEMP
241 tristate "AMD Phenom/Sempron/Turion/Opteron temperature sensor"
242 depends on X86 && PCI
243 help
244 If you say yes here you get support for the temperature
245 sensor(s) inside your CPU. Supported are later revisions of
246 the AMD Family 10h and all revisions of the AMD Family 11h
247 microarchitectures.
248
249 This driver can also be built as a module. If so, the module
250 will be called k10temp.
251
225config SENSORS_AMS 252config SENSORS_AMS
226 tristate "Apple Motion Sensor driver" 253 tristate "Apple Motion Sensor driver"
227 depends on PPC_PMAC && !PPC64 && INPUT && ((ADB_PMU && I2C = y) || (ADB_PMU && !I2C) || I2C) && EXPERIMENTAL 254 depends on PPC_PMAC && !PPC64 && INPUT && ((ADB_PMU && I2C = y) || (ADB_PMU && !I2C) || I2C) && EXPERIMENTAL
@@ -305,12 +332,12 @@ config SENSORS_F71805F
305 will be called f71805f. 332 will be called f71805f.
306 333
307config SENSORS_F71882FG 334config SENSORS_F71882FG
308 tristate "Fintek F71858FG, F71862FG, F71882FG and F8000" 335 tristate "Fintek F71858FG, F71862FG, F71882FG, F71889FG and F8000"
309 depends on EXPERIMENTAL 336 depends on EXPERIMENTAL
310 help 337 help
311 If you say yes here you get support for hardware monitoring 338 If you say yes here you get support for hardware monitoring
312 features of the Fintek F71858FG, F71862FG/71863FG, F71882FG/F71883FG 339 features of the Fintek F71858FG, F71862FG/71863FG, F71882FG/F71883FG,
313 and F8000 Super-I/O chips. 340 F71889FG and F8000 Super-I/O chips.
314 341
315 This driver can also be built as a module. If so, the module 342 This driver can also be built as a module. If so, the module
316 will be called f71882fg. 343 will be called f71882fg.
@@ -374,7 +401,7 @@ config SENSORS_GL520SM
374 401
375config SENSORS_CORETEMP 402config SENSORS_CORETEMP
376 tristate "Intel Core/Core2/Atom temperature sensor" 403 tristate "Intel Core/Core2/Atom temperature sensor"
377 depends on X86 && EXPERIMENTAL 404 depends on X86 && PCI && EXPERIMENTAL
378 help 405 help
379 If you say yes here you get support for the temperature 406 If you say yes here you get support for the temperature
380 sensor inside your CPU. Most of the family 6 CPUs 407 sensor inside your CPU. Most of the family 6 CPUs
@@ -442,6 +469,15 @@ config SENSORS_LM70
442 This driver can also be built as a module. If so, the module 469 This driver can also be built as a module. If so, the module
443 will be called lm70. 470 will be called lm70.
444 471
472config SENSORS_LM73
473 tristate "National Semiconductor LM73"
474 depends on I2C
475 help
476 If you say yes here you get support for National Semiconductor LM73
477 sensor chips.
478 This driver can also be built as a module. If so, the module
479 will be called lm73.
480
445config SENSORS_LM75 481config SENSORS_LM75
446 tristate "National Semiconductor LM75 and compatibles" 482 tristate "National Semiconductor LM75 and compatibles"
447 depends on I2C 483 depends on I2C
@@ -536,9 +572,10 @@ config SENSORS_LM90
536 depends on I2C 572 depends on I2C
537 help 573 help
538 If you say yes here you get support for National Semiconductor LM90, 574 If you say yes here you get support for National Semiconductor LM90,
539 LM86, LM89 and LM99, Analog Devices ADM1032 and ADT7461, and Maxim 575 LM86, LM89 and LM99, Analog Devices ADM1032 and ADT7461, Maxim
540 MAX6646, MAX6647, MAX6648, MAX6649, MAX6657, MAX6658, MAX6659, 576 MAX6646, MAX6647, MAX6648, MAX6649, MAX6657, MAX6658, MAX6659,
541 MAX6680, MAX6681 and MAX6692 sensor chips. 577 MAX6680, MAX6681 and MAX6692, and Winbond/Nuvoton W83L771AWG/ASG
578 sensor chips.
542 579
543 This driver can also be built as a module. If so, the module 580 This driver can also be built as a module. If so, the module
544 will be called lm90. 581 will be called lm90.
@@ -765,6 +802,16 @@ config SENSORS_ADS7828
765 This driver can also be built as a module. If so, the module 802 This driver can also be built as a module. If so, the module
766 will be called ads7828. 803 will be called ads7828.
767 804
805config SENSORS_AMC6821
806 tristate "Texas Instruments AMC6821"
807 depends on I2C && EXPERIMENTAL
808 help
809 If you say yes here you get support for the Texas Instruments
810 AMC6821 hardware monitoring chips.
811
812 This driver can also be build as a module. If so, the module
813 will be called amc6821.
814
768config SENSORS_THMC50 815config SENSORS_THMC50
769 tristate "Texas Instruments THMC50 / Analog Devices ADM1022" 816 tristate "Texas Instruments THMC50 / Analog Devices ADM1022"
770 depends on I2C && EXPERIMENTAL 817 depends on I2C && EXPERIMENTAL
@@ -795,6 +842,14 @@ config SENSORS_TMP421
795 This driver can also be built as a module. If so, the module 842 This driver can also be built as a module. If so, the module
796 will be called tmp421. 843 will be called tmp421.
797 844
845config SENSORS_VIA_CPUTEMP
846 tristate "VIA CPU temperature sensor"
847 depends on X86
848 help
849 If you say yes here you get support for the temperature
850 sensor inside your CPU. Supported are all known variants of
851 the VIA C7 and Nano.
852
798config SENSORS_VIA686A 853config SENSORS_VIA686A
799 tristate "VIA686A" 854 tristate "VIA686A"
800 depends on PCI 855 depends on PCI
@@ -841,7 +896,7 @@ config SENSORS_W83781D
841 896
842config SENSORS_W83791D 897config SENSORS_W83791D
843 tristate "Winbond W83791D" 898 tristate "Winbond W83791D"
844 depends on I2C && EXPERIMENTAL 899 depends on I2C
845 select HWMON_VID 900 select HWMON_VID
846 help 901 help
847 If you say yes here you get support for the Winbond W83791D chip. 902 If you say yes here you get support for the Winbond W83791D chip.
@@ -864,7 +919,8 @@ config SENSORS_W83793
864 select HWMON_VID 919 select HWMON_VID
865 help 920 help
866 If you say yes here you get support for the Winbond W83793 921 If you say yes here you get support for the Winbond W83793
867 hardware monitoring chip. 922 hardware monitoring chip, including support for the integrated
923 watchdog.
868 924
869 This driver can also be built as a module. If so, the module 925 This driver can also be built as a module. If so, the module
870 will be called w83793. 926 will be called w83793.
@@ -983,6 +1039,23 @@ config SENSORS_LIS3_SPI
983 will be called lis3lv02d and a specific module for the SPI transport 1039 will be called lis3lv02d and a specific module for the SPI transport
984 is called lis3lv02d_spi. 1040 is called lis3lv02d_spi.
985 1041
1042config SENSORS_LIS3_I2C
1043 tristate "STMicroeletronics LIS3LV02Dx three-axis digital accelerometer (I2C)"
1044 depends on I2C && INPUT
1045 select INPUT_POLLDEV
1046 default n
1047 help
1048 This driver provides support for the LIS3LV02Dx accelerometer connected
1049 via I2C. The accelerometer data is readable via
1050 /sys/devices/platform/lis3lv02d.
1051
1052 This driver also provides an absolute input class device, allowing
1053 the device to act as a pinball machine-esque joystick.
1054
1055 This driver can also be built as modules. If so, the core module
1056 will be called lis3lv02d and a specific module for the I2C transport
1057 is called lis3lv02d_i2c.
1058
986config SENSORS_APPLESMC 1059config SENSORS_APPLESMC
987 tristate "Apple SMC (Motion sensor, light sensor, keyboard backlight)" 1060 tristate "Apple SMC (Motion sensor, light sensor, keyboard backlight)"
988 depends on INPUT && X86 1061 depends on INPUT && X86
@@ -1008,6 +1081,12 @@ config SENSORS_APPLESMC
1008 Say Y here if you have an applicable laptop and want to experience 1081 Say Y here if you have an applicable laptop and want to experience
1009 the awesome power of applesmc. 1082 the awesome power of applesmc.
1010 1083
1084config SENSORS_MC13783_ADC
1085 tristate "Freescale MC13783 ADC"
1086 depends on MFD_MC13783
1087 help
1088 Support for the A/D converter on MC13783 PMIC.
1089
1011if ACPI 1090if ACPI
1012 1091
1013comment "ACPI drivers" 1092comment "ACPI drivers"
@@ -1025,25 +1104,27 @@ config SENSORS_ATK0110
1025 will be called asus_atk0110. 1104 will be called asus_atk0110.
1026 1105
1027config SENSORS_LIS3LV02D 1106config SENSORS_LIS3LV02D
1028 tristate "STMicroeletronics LIS3LV02Dx three-axis digital accelerometer" 1107 tristate "STMicroeletronics LIS3* three-axis digital accelerometer"
1029 depends on INPUT 1108 depends on INPUT
1030 select INPUT_POLLDEV 1109 select INPUT_POLLDEV
1031 select NEW_LEDS 1110 select NEW_LEDS
1032 select LEDS_CLASS 1111 select LEDS_CLASS
1033 default n 1112 default n
1034 help 1113 help
1035 This driver provides support for the LIS3LV02Dx accelerometer. In 1114 This driver provides support for the LIS3* accelerometers, such as the
1036 particular, it can be found in a number of HP laptops, which have the 1115 LIS3LV02DL or the LIS331DL. In particular, it can be found in a number
1037 "Mobile Data Protection System 3D" or "3D DriveGuard" feature. On such 1116 of HP laptops, which have the "Mobile Data Protection System 3D" or
1038 systems the driver should load automatically (via ACPI). The 1117 "3D DriveGuard" feature. On such systems the driver should load
1039 accelerometer might also be found in other systems, connected via SPI 1118 automatically (via ACPI alias). The accelerometer might also be found
1040 or I2C. The accelerometer data is readable via 1119 in other systems, connected via SPI or I2C. The accelerometer data is
1041 /sys/devices/platform/lis3lv02d. 1120 readable via /sys/devices/platform/lis3lv02d.
1042 1121
1043 This driver also provides an absolute input class device, allowing 1122 This driver also provides an absolute input class device, allowing
1044 the laptop to act as a pinball machine-esque joystick. On HP laptops, 1123 a laptop to act as a pinball machine-esque joystick. It provides also
1124 a misc device which can be used to detect free-fall. On HP laptops,
1045 if the led infrastructure is activated, support for a led indicating 1125 if the led infrastructure is activated, support for a led indicating
1046 disk protection will be provided as hp:red:hddprotection. 1126 disk protection will be provided as hp::hddprotect. For more
1127 information on the feature, refer to Documentation/hwmon/lis3lv02d.
1047 1128
1048 This driver can also be built as modules. If so, the core module 1129 This driver can also be built as modules. If so, the core module
1049 will be called lis3lv02d and a specific module for HP laptops will be 1130 will be called lis3lv02d and a specific module for HP laptops will be
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 9f46cb019cc6..4aa1a3d112ad 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -29,12 +29,13 @@ obj-$(CONFIG_SENSORS_ADM1029) += adm1029.o
29obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o 29obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o
30obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o 30obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o
31obj-$(CONFIG_SENSORS_ADS7828) += ads7828.o 31obj-$(CONFIG_SENSORS_ADS7828) += ads7828.o
32obj-$(CONFIG_SENSORS_ADT7411) += adt7411.o
32obj-$(CONFIG_SENSORS_ADT7462) += adt7462.o 33obj-$(CONFIG_SENSORS_ADT7462) += adt7462.o
33obj-$(CONFIG_SENSORS_ADT7470) += adt7470.o 34obj-$(CONFIG_SENSORS_ADT7470) += adt7470.o
34obj-$(CONFIG_SENSORS_ADT7473) += adt7473.o
35obj-$(CONFIG_SENSORS_ADT7475) += adt7475.o 35obj-$(CONFIG_SENSORS_ADT7475) += adt7475.o
36obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o 36obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o
37obj-$(CONFIG_SENSORS_AMS) += ams/ 37obj-$(CONFIG_SENSORS_AMS) += ams/
38obj-$(CONFIG_SENSORS_ASC7621) += asc7621.o
38obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o 39obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o
39obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o 40obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o
40obj-$(CONFIG_SENSORS_DME1737) += dme1737.o 41obj-$(CONFIG_SENSORS_DME1737) += dme1737.o
@@ -53,10 +54,13 @@ obj-$(CONFIG_SENSORS_IBMAEM) += ibmaem.o
53obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o 54obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o
54obj-$(CONFIG_SENSORS_IT87) += it87.o 55obj-$(CONFIG_SENSORS_IT87) += it87.o
55obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o 56obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o
57obj-$(CONFIG_SENSORS_K10TEMP) += k10temp.o
56obj-$(CONFIG_SENSORS_LIS3LV02D) += lis3lv02d.o hp_accel.o 58obj-$(CONFIG_SENSORS_LIS3LV02D) += lis3lv02d.o hp_accel.o
57obj-$(CONFIG_SENSORS_LIS3_SPI) += lis3lv02d.o lis3lv02d_spi.o 59obj-$(CONFIG_SENSORS_LIS3_SPI) += lis3lv02d.o lis3lv02d_spi.o
60obj-$(CONFIG_SENSORS_LIS3_I2C) += lis3lv02d.o lis3lv02d_i2c.o
58obj-$(CONFIG_SENSORS_LM63) += lm63.o 61obj-$(CONFIG_SENSORS_LM63) += lm63.o
59obj-$(CONFIG_SENSORS_LM70) += lm70.o 62obj-$(CONFIG_SENSORS_LM70) += lm70.o
63obj-$(CONFIG_SENSORS_LM73) += lm73.o
60obj-$(CONFIG_SENSORS_LM75) += lm75.o 64obj-$(CONFIG_SENSORS_LM75) += lm75.o
61obj-$(CONFIG_SENSORS_LM77) += lm77.o 65obj-$(CONFIG_SENSORS_LM77) += lm77.o
62obj-$(CONFIG_SENSORS_LM78) += lm78.o 66obj-$(CONFIG_SENSORS_LM78) += lm78.o
@@ -73,6 +77,7 @@ obj-$(CONFIG_SENSORS_LTC4245) += ltc4245.o
73obj-$(CONFIG_SENSORS_MAX1111) += max1111.o 77obj-$(CONFIG_SENSORS_MAX1111) += max1111.o
74obj-$(CONFIG_SENSORS_MAX1619) += max1619.o 78obj-$(CONFIG_SENSORS_MAX1619) += max1619.o
75obj-$(CONFIG_SENSORS_MAX6650) += max6650.o 79obj-$(CONFIG_SENSORS_MAX6650) += max6650.o
80obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
76obj-$(CONFIG_SENSORS_PC87360) += pc87360.o 81obj-$(CONFIG_SENSORS_PC87360) += pc87360.o
77obj-$(CONFIG_SENSORS_PC87427) += pc87427.o 82obj-$(CONFIG_SENSORS_PC87427) += pc87427.o
78obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o 83obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o
@@ -82,9 +87,11 @@ obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o
82obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o 87obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o
83obj-$(CONFIG_SENSORS_SMSC47M1) += smsc47m1.o 88obj-$(CONFIG_SENSORS_SMSC47M1) += smsc47m1.o
84obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o 89obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o
90obj-$(CONFIG_SENSORS_AMC6821) += amc6821.o
85obj-$(CONFIG_SENSORS_THMC50) += thmc50.o 91obj-$(CONFIG_SENSORS_THMC50) += thmc50.o
86obj-$(CONFIG_SENSORS_TMP401) += tmp401.o 92obj-$(CONFIG_SENSORS_TMP401) += tmp401.o
87obj-$(CONFIG_SENSORS_TMP421) += tmp421.o 93obj-$(CONFIG_SENSORS_TMP421) += tmp421.o
94obj-$(CONFIG_SENSORS_VIA_CPUTEMP)+= via-cputemp.o
88obj-$(CONFIG_SENSORS_VIA686A) += via686a.o 95obj-$(CONFIG_SENSORS_VIA686A) += via686a.o
89obj-$(CONFIG_SENSORS_VT1211) += vt1211.o 96obj-$(CONFIG_SENSORS_VT1211) += vt1211.o
90obj-$(CONFIG_SENSORS_VT8231) += vt8231.o 97obj-$(CONFIG_SENSORS_VT8231) += vt8231.o
diff --git a/drivers/hwmon/ad7414.c b/drivers/hwmon/ad7414.c
index bfda8c80ef24..1e4c21fc1a89 100644
--- a/drivers/hwmon/ad7414.c
+++ b/drivers/hwmon/ad7414.c
@@ -27,6 +27,7 @@
27#include <linux/err.h> 27#include <linux/err.h>
28#include <linux/mutex.h> 28#include <linux/mutex.h>
29#include <linux/sysfs.h> 29#include <linux/sysfs.h>
30#include <linux/slab.h>
30 31
31 32
32/* AD7414 registers */ 33/* AD7414 registers */
diff --git a/drivers/hwmon/ad7418.c b/drivers/hwmon/ad7418.c
index f97b5b356875..ffc781fec185 100644
--- a/drivers/hwmon/ad7418.c
+++ b/drivers/hwmon/ad7418.c
@@ -20,6 +20,7 @@
20#include <linux/err.h> 20#include <linux/err.h>
21#include <linux/mutex.h> 21#include <linux/mutex.h>
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/slab.h>
23 24
24#include "lm75.h" 25#include "lm75.h"
25 26
diff --git a/drivers/hwmon/adcxx.c b/drivers/hwmon/adcxx.c
index 5e9e095f1136..fbdc7655303b 100644
--- a/drivers/hwmon/adcxx.c
+++ b/drivers/hwmon/adcxx.c
@@ -37,6 +37,7 @@
37#include <linux/init.h> 37#include <linux/init.h>
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/kernel.h> 39#include <linux/kernel.h>
40#include <linux/slab.h>
40#include <linux/device.h> 41#include <linux/device.h>
41#include <linux/err.h> 42#include <linux/err.h>
42#include <linux/sysfs.h> 43#include <linux/sysfs.h>
@@ -62,18 +63,23 @@ static ssize_t adcxx_read(struct device *dev,
62 struct spi_device *spi = to_spi_device(dev); 63 struct spi_device *spi = to_spi_device(dev);
63 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 64 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
64 struct adcxx *adc = dev_get_drvdata(&spi->dev); 65 struct adcxx *adc = dev_get_drvdata(&spi->dev);
65 u8 tx_buf[2] = { attr->index << 3 }; /* other bits are don't care */ 66 u8 tx_buf[2];
66 u8 rx_buf[2]; 67 u8 rx_buf[2];
67 int status; 68 int status;
68 int value; 69 u32 value;
69 70
70 if (mutex_lock_interruptible(&adc->lock)) 71 if (mutex_lock_interruptible(&adc->lock))
71 return -ERESTARTSYS; 72 return -ERESTARTSYS;
72 73
73 status = spi_write_then_read(spi, tx_buf, sizeof(tx_buf), 74 if (adc->channels == 1) {
74 rx_buf, sizeof(rx_buf)); 75 status = spi_read(spi, rx_buf, sizeof(rx_buf));
76 } else {
77 tx_buf[0] = attr->index << 3; /* other bits are don't care */
78 status = spi_write_then_read(spi, tx_buf, sizeof(tx_buf),
79 rx_buf, sizeof(rx_buf));
80 }
75 if (status < 0) { 81 if (status < 0) {
76 dev_warn(dev, "spi_write_then_read failed with status %d\n", 82 dev_warn(dev, "SPI synch. transfer failed with status %d\n",
77 status); 83 status);
78 goto out; 84 goto out;
79 } 85 }
diff --git a/drivers/hwmon/adm1021.c b/drivers/hwmon/adm1021.c
index afc594318125..1ad0a885c5a5 100644
--- a/drivers/hwmon/adm1021.c
+++ b/drivers/hwmon/adm1021.c
@@ -34,9 +34,8 @@
34static const unsigned short normal_i2c[] = { 34static const unsigned short normal_i2c[] = {
35 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END }; 35 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END };
36 36
37/* Insmod parameters */ 37enum chips {
38I2C_CLIENT_INSMOD_8(adm1021, adm1023, max1617, max1617a, thmc10, lm84, gl523sm, 38 adm1021, adm1023, max1617, max1617a, thmc10, lm84, gl523sm, mc1066 };
39 mc1066);
40 39
41/* adm1021 constants specified below */ 40/* adm1021 constants specified below */
42 41
@@ -97,7 +96,7 @@ struct adm1021_data {
97 96
98static int adm1021_probe(struct i2c_client *client, 97static int adm1021_probe(struct i2c_client *client,
99 const struct i2c_device_id *id); 98 const struct i2c_device_id *id);
100static int adm1021_detect(struct i2c_client *client, int kind, 99static int adm1021_detect(struct i2c_client *client,
101 struct i2c_board_info *info); 100 struct i2c_board_info *info);
102static void adm1021_init_client(struct i2c_client *client); 101static void adm1021_init_client(struct i2c_client *client);
103static int adm1021_remove(struct i2c_client *client); 102static int adm1021_remove(struct i2c_client *client);
@@ -130,7 +129,7 @@ static struct i2c_driver adm1021_driver = {
130 .remove = adm1021_remove, 129 .remove = adm1021_remove,
131 .id_table = adm1021_id, 130 .id_table = adm1021_id,
132 .detect = adm1021_detect, 131 .detect = adm1021_detect,
133 .address_data = &addr_data, 132 .address_list = normal_i2c,
134}; 133};
135 134
136static ssize_t show_temp(struct device *dev, 135static ssize_t show_temp(struct device *dev,
@@ -284,13 +283,12 @@ static const struct attribute_group adm1021_group = {
284}; 283};
285 284
286/* Return 0 if detection is successful, -ENODEV otherwise */ 285/* Return 0 if detection is successful, -ENODEV otherwise */
287static int adm1021_detect(struct i2c_client *client, int kind, 286static int adm1021_detect(struct i2c_client *client,
288 struct i2c_board_info *info) 287 struct i2c_board_info *info)
289{ 288{
290 struct i2c_adapter *adapter = client->adapter; 289 struct i2c_adapter *adapter = client->adapter;
291 int i; 290 const char *type_name;
292 const char *type_name = ""; 291 int conv_rate, status, config, man_id, dev_id;
293 int conv_rate, status, config;
294 292
295 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 293 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
296 pr_debug("adm1021: detect failed, " 294 pr_debug("adm1021: detect failed, "
@@ -303,62 +301,37 @@ static int adm1021_detect(struct i2c_client *client, int kind,
303 ADM1021_REG_CONV_RATE_R); 301 ADM1021_REG_CONV_RATE_R);
304 config = i2c_smbus_read_byte_data(client, ADM1021_REG_CONFIG_R); 302 config = i2c_smbus_read_byte_data(client, ADM1021_REG_CONFIG_R);
305 303
306 /* Now, we do the remaining detection. */ 304 /* Check unused bits */
307 if (kind < 0) { 305 if ((status & 0x03) || (config & 0x3F) || (conv_rate & 0xF8)) {
308 if ((status & 0x03) != 0x00 || (config & 0x3F) != 0x00 306 pr_debug("adm1021: detect failed, chip not detected!\n");
309 || (conv_rate & 0xF8) != 0x00) { 307 return -ENODEV;
310 pr_debug("adm1021: detect failed, "
311 "chip not detected!\n");
312 return -ENODEV;
313 }
314 } 308 }
315 309
316 /* Determine the chip type. */ 310 /* Determine the chip type. */
317 if (kind <= 0) { 311 man_id = i2c_smbus_read_byte_data(client, ADM1021_REG_MAN_ID);
318 i = i2c_smbus_read_byte_data(client, ADM1021_REG_MAN_ID); 312 dev_id = i2c_smbus_read_byte_data(client, ADM1021_REG_DEV_ID);
319 if (i == 0x41)
320 if ((i2c_smbus_read_byte_data(client,
321 ADM1021_REG_DEV_ID) & 0xF0) == 0x30)
322 kind = adm1023;
323 else
324 kind = adm1021;
325 else if (i == 0x49)
326 kind = thmc10;
327 else if (i == 0x23)
328 kind = gl523sm;
329 else if ((i == 0x4d) &&
330 (i2c_smbus_read_byte_data(client,
331 ADM1021_REG_DEV_ID) == 0x01))
332 kind = max1617a;
333 else if (i == 0x54)
334 kind = mc1066;
335 /* LM84 Mfr ID in a different place, and it has more unused bits */
336 else if (conv_rate == 0x00
337 && (kind == 0 /* skip extra detection */
338 || ((config & 0x7F) == 0x00
339 && (status & 0xAB) == 0x00)))
340 kind = lm84;
341 else
342 kind = max1617;
343 }
344 313
345 if (kind == max1617) { 314 if (man_id == 0x4d && dev_id == 0x01)
346 type_name = "max1617";
347 } else if (kind == max1617a) {
348 type_name = "max1617a"; 315 type_name = "max1617a";
349 } else if (kind == adm1021) { 316 else if (man_id == 0x41) {
350 type_name = "adm1021"; 317 if ((dev_id & 0xF0) == 0x30)
351 } else if (kind == adm1023) { 318 type_name = "adm1023";
352 type_name = "adm1023"; 319 else
353 } else if (kind == thmc10) { 320 type_name = "adm1021";
321 } else if (man_id == 0x49)
354 type_name = "thmc10"; 322 type_name = "thmc10";
355 } else if (kind == lm84) { 323 else if (man_id == 0x23)
356 type_name = "lm84";
357 } else if (kind == gl523sm) {
358 type_name = "gl523sm"; 324 type_name = "gl523sm";
359 } else if (kind == mc1066) { 325 else if (man_id == 0x54)
360 type_name = "mc1066"; 326 type_name = "mc1066";
361 } 327 /* LM84 Mfr ID in a different place, and it has more unused bits */
328 else if (conv_rate == 0x00
329 && (config & 0x7F) == 0x00
330 && (status & 0xAB) == 0x00)
331 type_name = "lm84";
332 else
333 type_name = "max1617";
334
362 pr_debug("adm1021: Detected chip %s at adapter %d, address 0x%02x.\n", 335 pr_debug("adm1021: Detected chip %s at adapter %d, address 0x%02x.\n",
363 type_name, i2c_adapter_id(adapter), client->addr); 336 type_name, i2c_adapter_id(adapter), client->addr);
364 strlcpy(info->type, type_name, I2C_NAME_SIZE); 337 strlcpy(info->type, type_name, I2C_NAME_SIZE);
diff --git a/drivers/hwmon/adm1025.c b/drivers/hwmon/adm1025.c
index 4db04d603ec9..251b63165e2a 100644
--- a/drivers/hwmon/adm1025.c
+++ b/drivers/hwmon/adm1025.c
@@ -2,7 +2,7 @@
2 * adm1025.c 2 * adm1025.c
3 * 3 *
4 * Copyright (C) 2000 Chen-Yuan Wu <gwu@esoft.com> 4 * Copyright (C) 2000 Chen-Yuan Wu <gwu@esoft.com>
5 * Copyright (C) 2003-2008 Jean Delvare <khali@linux-fr.org> 5 * Copyright (C) 2003-2009 Jean Delvare <khali@linux-fr.org>
6 * 6 *
7 * The ADM1025 is a sensor chip made by Analog Devices. It reports up to 6 7 * The ADM1025 is a sensor chip made by Analog Devices. It reports up to 6
8 * voltages (including its own power source) and up to two temperatures 8 * voltages (including its own power source) and up to two temperatures
@@ -64,11 +64,7 @@
64 64
65static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; 65static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
66 66
67/* 67enum chips { adm1025, ne1619 };
68 * Insmod parameters
69 */
70
71I2C_CLIENT_INSMOD_2(adm1025, ne1619);
72 68
73/* 69/*
74 * The ADM1025 registers 70 * The ADM1025 registers
@@ -111,7 +107,7 @@ static const int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 };
111 107
112static int adm1025_probe(struct i2c_client *client, 108static int adm1025_probe(struct i2c_client *client,
113 const struct i2c_device_id *id); 109 const struct i2c_device_id *id);
114static int adm1025_detect(struct i2c_client *client, int kind, 110static int adm1025_detect(struct i2c_client *client,
115 struct i2c_board_info *info); 111 struct i2c_board_info *info);
116static void adm1025_init_client(struct i2c_client *client); 112static void adm1025_init_client(struct i2c_client *client);
117static int adm1025_remove(struct i2c_client *client); 113static int adm1025_remove(struct i2c_client *client);
@@ -137,7 +133,7 @@ static struct i2c_driver adm1025_driver = {
137 .remove = adm1025_remove, 133 .remove = adm1025_remove,
138 .id_table = adm1025_id, 134 .id_table = adm1025_id,
139 .detect = adm1025_detect, 135 .detect = adm1025_detect,
140 .address_data = &addr_data, 136 .address_list = normal_i2c,
141}; 137};
142 138
143/* 139/*
@@ -409,71 +405,38 @@ static const struct attribute_group adm1025_group_in4 = {
409}; 405};
410 406
411/* Return 0 if detection is successful, -ENODEV otherwise */ 407/* Return 0 if detection is successful, -ENODEV otherwise */
412static int adm1025_detect(struct i2c_client *client, int kind, 408static int adm1025_detect(struct i2c_client *client,
413 struct i2c_board_info *info) 409 struct i2c_board_info *info)
414{ 410{
415 struct i2c_adapter *adapter = client->adapter; 411 struct i2c_adapter *adapter = client->adapter;
416 const char *name = ""; 412 const char *name;
417 u8 config; 413 u8 man_id, chip_id;
418 414
419 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 415 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
420 return -ENODEV; 416 return -ENODEV;
421 417
422 /* 418 /* Check for unused bits */
423 * Now we do the remaining detection. A negative kind means that 419 if ((i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG) & 0x80)
424 * the driver was loaded with no force parameter (default), so we 420 || (i2c_smbus_read_byte_data(client, ADM1025_REG_STATUS1) & 0xC0)
425 * must both detect and identify the chip. A zero kind means that 421 || (i2c_smbus_read_byte_data(client, ADM1025_REG_STATUS2) & 0xBC)) {
426 * the driver was loaded with the force parameter, the detection 422 dev_dbg(&adapter->dev, "ADM1025 detection failed at 0x%02x\n",
427 * step shall be skipped. A positive kind means that the driver 423 client->addr);
428 * was loaded with the force parameter and a given kind of chip is 424 return -ENODEV;
429 * requested, so both the detection and the identification steps
430 * are skipped.
431 */
432 config = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG);
433 if (kind < 0) { /* detection */
434 if ((config & 0x80) != 0x00
435 || (i2c_smbus_read_byte_data(client,
436 ADM1025_REG_STATUS1) & 0xC0) != 0x00
437 || (i2c_smbus_read_byte_data(client,
438 ADM1025_REG_STATUS2) & 0xBC) != 0x00) {
439 dev_dbg(&adapter->dev,
440 "ADM1025 detection failed at 0x%02x.\n",
441 client->addr);
442 return -ENODEV;
443 }
444 } 425 }
445 426
446 if (kind <= 0) { /* identification */ 427 /* Identification */
447 u8 man_id, chip_id; 428 chip_id = i2c_smbus_read_byte_data(client, ADM1025_REG_CHIP_ID);
448 429 if ((chip_id & 0xF0) != 0x20)
449 man_id = i2c_smbus_read_byte_data(client, ADM1025_REG_MAN_ID); 430 return -ENODEV;
450 chip_id = i2c_smbus_read_byte_data(client, ADM1025_REG_CHIP_ID);
451
452 if (man_id == 0x41) { /* Analog Devices */
453 if ((chip_id & 0xF0) == 0x20) { /* ADM1025/ADM1025A */
454 kind = adm1025;
455 }
456 } else
457 if (man_id == 0xA1) { /* Philips */
458 if (client->addr != 0x2E
459 && (chip_id & 0xF0) == 0x20) { /* NE1619 */
460 kind = ne1619;
461 }
462 }
463
464 if (kind <= 0) { /* identification failed */
465 dev_info(&adapter->dev,
466 "Unsupported chip (man_id=0x%02X, "
467 "chip_id=0x%02X).\n", man_id, chip_id);
468 return -ENODEV;
469 }
470 }
471 431
472 if (kind == adm1025) { 432 man_id = i2c_smbus_read_byte_data(client, ADM1025_REG_MAN_ID);
433 if (man_id == 0x41)
473 name = "adm1025"; 434 name = "adm1025";
474 } else if (kind == ne1619) { 435 else if (man_id == 0xA1 && client->addr != 0x2E)
475 name = "ne1619"; 436 name = "ne1619";
476 } 437 else
438 return -ENODEV;
439
477 strlcpy(info->type, name, I2C_NAME_SIZE); 440 strlcpy(info->type, name, I2C_NAME_SIZE);
478 441
479 return 0; 442 return 0;
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c
index ff7de40b6e35..65335b268fa9 100644
--- a/drivers/hwmon/adm1026.c
+++ b/drivers/hwmon/adm1026.c
@@ -37,9 +37,6 @@
37/* Addresses to scan */ 37/* Addresses to scan */
38static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; 38static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
39 39
40/* Insmod parameters */
41I2C_CLIENT_INSMOD_1(adm1026);
42
43static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, 40static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
44 -1, -1, -1, -1, -1, -1, -1, -1 }; 41 -1, -1, -1, -1, -1, -1, -1, -1 };
45static int gpio_output[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, 42static int gpio_output[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -293,7 +290,7 @@ struct adm1026_data {
293 290
294static int adm1026_probe(struct i2c_client *client, 291static int adm1026_probe(struct i2c_client *client,
295 const struct i2c_device_id *id); 292 const struct i2c_device_id *id);
296static int adm1026_detect(struct i2c_client *client, int kind, 293static int adm1026_detect(struct i2c_client *client,
297 struct i2c_board_info *info); 294 struct i2c_board_info *info);
298static int adm1026_remove(struct i2c_client *client); 295static int adm1026_remove(struct i2c_client *client);
299static int adm1026_read_value(struct i2c_client *client, u8 reg); 296static int adm1026_read_value(struct i2c_client *client, u8 reg);
@@ -305,7 +302,7 @@ static void adm1026_init_client(struct i2c_client *client);
305 302
306 303
307static const struct i2c_device_id adm1026_id[] = { 304static const struct i2c_device_id adm1026_id[] = {
308 { "adm1026", adm1026 }, 305 { "adm1026", 0 },
309 { } 306 { }
310}; 307};
311MODULE_DEVICE_TABLE(i2c, adm1026_id); 308MODULE_DEVICE_TABLE(i2c, adm1026_id);
@@ -319,7 +316,7 @@ static struct i2c_driver adm1026_driver = {
319 .remove = adm1026_remove, 316 .remove = adm1026_remove,
320 .id_table = adm1026_id, 317 .id_table = adm1026_id,
321 .detect = adm1026_detect, 318 .detect = adm1026_detect,
322 .address_data = &addr_data, 319 .address_list = normal_i2c,
323}; 320};
324 321
325static int adm1026_read_value(struct i2c_client *client, u8 reg) 322static int adm1026_read_value(struct i2c_client *client, u8 reg)
@@ -1650,7 +1647,7 @@ static const struct attribute_group adm1026_group_in8_9 = {
1650}; 1647};
1651 1648
1652/* Return 0 if detection is successful, -ENODEV otherwise */ 1649/* Return 0 if detection is successful, -ENODEV otherwise */
1653static int adm1026_detect(struct i2c_client *client, int kind, 1650static int adm1026_detect(struct i2c_client *client,
1654 struct i2c_board_info *info) 1651 struct i2c_board_info *info)
1655{ 1652{
1656 struct i2c_adapter *adapter = client->adapter; 1653 struct i2c_adapter *adapter = client->adapter;
@@ -1672,35 +1669,26 @@ static int adm1026_detect(struct i2c_client *client, int kind,
1672 i2c_adapter_id(client->adapter), client->addr, 1669 i2c_adapter_id(client->adapter), client->addr,
1673 company, verstep); 1670 company, verstep);
1674 1671
1675 /* If auto-detecting, Determine the chip type. */ 1672 /* Determine the chip type. */
1676 if (kind <= 0) { 1673 dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x...\n",
1677 dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x " 1674 i2c_adapter_id(adapter), address);
1678 "...\n", i2c_adapter_id(adapter), address); 1675 if (company == ADM1026_COMPANY_ANALOG_DEV
1679 if (company == ADM1026_COMPANY_ANALOG_DEV 1676 && verstep == ADM1026_VERSTEP_ADM1026) {
1680 && verstep == ADM1026_VERSTEP_ADM1026) { 1677 /* Analog Devices ADM1026 */
1681 kind = adm1026; 1678 } else if (company == ADM1026_COMPANY_ANALOG_DEV
1682 } else if (company == ADM1026_COMPANY_ANALOG_DEV 1679 && (verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
1683 && (verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) { 1680 dev_err(&adapter->dev, "Unrecognized stepping "
1684 dev_err(&adapter->dev, "Unrecognized stepping " 1681 "0x%02x. Defaulting to ADM1026.\n", verstep);
1685 "0x%02x. Defaulting to ADM1026.\n", verstep); 1682 } else if ((verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
1686 kind = adm1026; 1683 dev_err(&adapter->dev, "Found version/stepping "
1687 } else if ((verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) { 1684 "0x%02x. Assuming generic ADM1026.\n",
1688 dev_err(&adapter->dev, "Found version/stepping " 1685 verstep);
1689 "0x%02x. Assuming generic ADM1026.\n", 1686 } else {
1690 verstep); 1687 dev_dbg(&adapter->dev, "Autodetection failed\n");
1691 kind = any_chip; 1688 /* Not an ADM1026... */
1692 } else { 1689 return -ENODEV;
1693 dev_dbg(&adapter->dev, "Autodetection failed\n");
1694 /* Not an ADM1026 ... */
1695 if (kind == 0) { /* User used force=x,y */
1696 dev_err(&adapter->dev, "Generic ADM1026 not "
1697 "found at %d,0x%02x. Try "
1698 "force_adm1026.\n",
1699 i2c_adapter_id(adapter), address);
1700 }
1701 return -ENODEV;
1702 }
1703 } 1690 }
1691
1704 strlcpy(info->type, "adm1026", I2C_NAME_SIZE); 1692 strlcpy(info->type, "adm1026", I2C_NAME_SIZE);
1705 1693
1706 return 0; 1694 return 0;
diff --git a/drivers/hwmon/adm1029.c b/drivers/hwmon/adm1029.c
index 36718150b475..0b8a3b145bd2 100644
--- a/drivers/hwmon/adm1029.c
+++ b/drivers/hwmon/adm1029.c
@@ -44,12 +44,6 @@ static const unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
44}; 44};
45 45
46/* 46/*
47 * Insmod parameters
48 */
49
50I2C_CLIENT_INSMOD_1(adm1029);
51
52/*
53 * The ADM1029 registers 47 * The ADM1029 registers
54 * Manufacturer ID is 0x41 for Analog Devices 48 * Manufacturer ID is 0x41 for Analog Devices
55 */ 49 */
@@ -117,7 +111,7 @@ static const u8 ADM1029_REG_FAN_DIV[] = {
117 111
118static int adm1029_probe(struct i2c_client *client, 112static int adm1029_probe(struct i2c_client *client,
119 const struct i2c_device_id *id); 113 const struct i2c_device_id *id);
120static int adm1029_detect(struct i2c_client *client, int kind, 114static int adm1029_detect(struct i2c_client *client,
121 struct i2c_board_info *info); 115 struct i2c_board_info *info);
122static int adm1029_remove(struct i2c_client *client); 116static int adm1029_remove(struct i2c_client *client);
123static struct adm1029_data *adm1029_update_device(struct device *dev); 117static struct adm1029_data *adm1029_update_device(struct device *dev);
@@ -128,7 +122,7 @@ static int adm1029_init_client(struct i2c_client *client);
128 */ 122 */
129 123
130static const struct i2c_device_id adm1029_id[] = { 124static const struct i2c_device_id adm1029_id[] = {
131 { "adm1029", adm1029 }, 125 { "adm1029", 0 },
132 { } 126 { }
133}; 127};
134MODULE_DEVICE_TABLE(i2c, adm1029_id); 128MODULE_DEVICE_TABLE(i2c, adm1029_id);
@@ -142,7 +136,7 @@ static struct i2c_driver adm1029_driver = {
142 .remove = adm1029_remove, 136 .remove = adm1029_remove,
143 .id_table = adm1029_id, 137 .id_table = adm1029_id,
144 .detect = adm1029_detect, 138 .detect = adm1029_detect,
145 .address_data = &addr_data, 139 .address_list = normal_i2c,
146}; 140};
147 141
148/* 142/*
@@ -297,63 +291,40 @@ static const struct attribute_group adm1029_group = {
297 */ 291 */
298 292
299/* Return 0 if detection is successful, -ENODEV otherwise */ 293/* Return 0 if detection is successful, -ENODEV otherwise */
300static int adm1029_detect(struct i2c_client *client, int kind, 294static int adm1029_detect(struct i2c_client *client,
301 struct i2c_board_info *info) 295 struct i2c_board_info *info)
302{ 296{
303 struct i2c_adapter *adapter = client->adapter; 297 struct i2c_adapter *adapter = client->adapter;
298 u8 man_id, chip_id, temp_devices_installed, nb_fan_support;
304 299
305 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 300 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
306 return -ENODEV; 301 return -ENODEV;
307 302
308 /* Now we do the detection and identification. A negative kind
309 * means that the driver was loaded with no force parameter
310 * (default), so we must both detect and identify the chip
311 * (actually there is only one possible kind of chip for now, adm1029).
312 * A zero kind means that the driver was loaded with the force
313 * parameter, the detection step shall be skipped. A positive kind
314 * means that the driver was loaded with the force parameter and a
315 * given kind of chip is requested, so both the detection and the
316 * identification steps are skipped. */
317
318 /* Default to an adm1029 if forced */
319 if (kind == 0)
320 kind = adm1029;
321
322 /* ADM1029 doesn't have CHIP ID, check just MAN ID 303 /* ADM1029 doesn't have CHIP ID, check just MAN ID
323 * For better detection we check also ADM1029_TEMP_DEVICES_INSTALLED, 304 * For better detection we check also ADM1029_TEMP_DEVICES_INSTALLED,
324 * ADM1029_REG_NB_FAN_SUPPORT and compare it with possible values 305 * ADM1029_REG_NB_FAN_SUPPORT and compare it with possible values
325 * documented 306 * documented
326 */ 307 */
327 308
328 if (kind <= 0) { /* identification */ 309 man_id = i2c_smbus_read_byte_data(client, ADM1029_REG_MAN_ID);
329 u8 man_id, chip_id, temp_devices_installed, nb_fan_support; 310 chip_id = i2c_smbus_read_byte_data(client, ADM1029_REG_CHIP_ID);
330 311 temp_devices_installed = i2c_smbus_read_byte_data(client,
331 man_id = i2c_smbus_read_byte_data(client, ADM1029_REG_MAN_ID);
332 chip_id = i2c_smbus_read_byte_data(client, ADM1029_REG_CHIP_ID);
333 temp_devices_installed = i2c_smbus_read_byte_data(client,
334 ADM1029_REG_TEMP_DEVICES_INSTALLED); 312 ADM1029_REG_TEMP_DEVICES_INSTALLED);
335 nb_fan_support = i2c_smbus_read_byte_data(client, 313 nb_fan_support = i2c_smbus_read_byte_data(client,
336 ADM1029_REG_NB_FAN_SUPPORT); 314 ADM1029_REG_NB_FAN_SUPPORT);
337 /* 0x41 is Analog Devices */ 315 /* 0x41 is Analog Devices */
338 if (man_id == 0x41 && (temp_devices_installed & 0xf9) == 0x01 316 if (man_id != 0x41 || (temp_devices_installed & 0xf9) != 0x01
339 && nb_fan_support == 0x03) { 317 || nb_fan_support != 0x03)
340 if ((chip_id & 0xF0) == 0x00) { 318 return -ENODEV;
341 kind = adm1029;
342 } else {
343 /* There are no "official" CHIP ID, so actually
344 * we use Major/Minor revision for that */
345 printk(KERN_INFO
346 "adm1029: Unknown major revision %x, "
347 "please let us know\n", chip_id);
348 }
349 }
350 319
351 if (kind <= 0) { /* identification failed */ 320 if ((chip_id & 0xF0) != 0x00) {
352 pr_debug("adm1029: Unsupported chip (man_id=0x%02X, " 321 /* There are no "official" CHIP ID, so actually
353 "chip_id=0x%02X)\n", man_id, chip_id); 322 * we use Major/Minor revision for that */
354 return -ENODEV; 323 pr_info("adm1029: Unknown major revision %x, "
355 } 324 "please let us know\n", chip_id);
325 return -ENODEV;
356 } 326 }
327
357 strlcpy(info->type, "adm1029", I2C_NAME_SIZE); 328 strlcpy(info->type, "adm1029", I2C_NAME_SIZE);
358 329
359 return 0; 330 return 0;
@@ -432,7 +403,7 @@ static int adm1029_remove(struct i2c_client *client)
432} 403}
433 404
434/* 405/*
435function that update the status of the chips (temperature for exemple) 406function that update the status of the chips (temperature for example)
436*/ 407*/
437static struct adm1029_data *adm1029_update_device(struct device *dev) 408static struct adm1029_data *adm1029_update_device(struct device *dev)
438{ 409{
diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c
index 56905955352c..1644b92e7cc4 100644
--- a/drivers/hwmon/adm1031.c
+++ b/drivers/hwmon/adm1031.c
@@ -64,8 +64,7 @@
64/* Addresses to scan */ 64/* Addresses to scan */
65static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; 65static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
66 66
67/* Insmod parameters */ 67enum chips { adm1030, adm1031 };
68I2C_CLIENT_INSMOD_2(adm1030, adm1031);
69 68
70typedef u8 auto_chan_table_t[8][2]; 69typedef u8 auto_chan_table_t[8][2];
71 70
@@ -102,7 +101,7 @@ struct adm1031_data {
102 101
103static int adm1031_probe(struct i2c_client *client, 102static int adm1031_probe(struct i2c_client *client,
104 const struct i2c_device_id *id); 103 const struct i2c_device_id *id);
105static int adm1031_detect(struct i2c_client *client, int kind, 104static int adm1031_detect(struct i2c_client *client,
106 struct i2c_board_info *info); 105 struct i2c_board_info *info);
107static void adm1031_init_client(struct i2c_client *client); 106static void adm1031_init_client(struct i2c_client *client);
108static int adm1031_remove(struct i2c_client *client); 107static int adm1031_remove(struct i2c_client *client);
@@ -125,7 +124,7 @@ static struct i2c_driver adm1031_driver = {
125 .remove = adm1031_remove, 124 .remove = adm1031_remove,
126 .id_table = adm1031_id, 125 .id_table = adm1031_id,
127 .detect = adm1031_detect, 126 .detect = adm1031_detect,
128 .address_data = &addr_data, 127 .address_list = normal_i2c,
129}; 128};
130 129
131static inline u8 adm1031_read_value(struct i2c_client *client, u8 reg) 130static inline u8 adm1031_read_value(struct i2c_client *client, u8 reg)
@@ -813,35 +812,23 @@ static const struct attribute_group adm1031_group_opt = {
813}; 812};
814 813
815/* Return 0 if detection is successful, -ENODEV otherwise */ 814/* Return 0 if detection is successful, -ENODEV otherwise */
816static int adm1031_detect(struct i2c_client *client, int kind, 815static int adm1031_detect(struct i2c_client *client,
817 struct i2c_board_info *info) 816 struct i2c_board_info *info)
818{ 817{
819 struct i2c_adapter *adapter = client->adapter; 818 struct i2c_adapter *adapter = client->adapter;
820 const char *name = ""; 819 const char *name;
820 int id, co;
821 821
822 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 822 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
823 return -ENODEV; 823 return -ENODEV;
824 824
825 if (kind < 0) { 825 id = i2c_smbus_read_byte_data(client, 0x3d);
826 int id, co; 826 co = i2c_smbus_read_byte_data(client, 0x3e);
827 id = i2c_smbus_read_byte_data(client, 0x3d);
828 co = i2c_smbus_read_byte_data(client, 0x3e);
829 827
830 if (!((id == 0x31 || id == 0x30) && co == 0x41)) 828 if (!((id == 0x31 || id == 0x30) && co == 0x41))
831 return -ENODEV; 829 return -ENODEV;
832 kind = (id == 0x30) ? adm1030 : adm1031; 830 name = (id == 0x30) ? "adm1030" : "adm1031";
833 }
834
835 if (kind <= 0)
836 kind = adm1031;
837 831
838 /* Given the detected chip type, set the chip name and the
839 * auto fan control helper table. */
840 if (kind == adm1030) {
841 name = "adm1030";
842 } else if (kind == adm1031) {
843 name = "adm1031";
844 }
845 strlcpy(info->type, name, I2C_NAME_SIZE); 832 strlcpy(info->type, name, I2C_NAME_SIZE);
846 833
847 return 0; 834 return 0;
diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c
index 2444b15f2e9d..0727ad250793 100644
--- a/drivers/hwmon/adm9240.c
+++ b/drivers/hwmon/adm9240.c
@@ -55,8 +55,7 @@
55static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, 55static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
56 I2C_CLIENT_END }; 56 I2C_CLIENT_END };
57 57
58/* Insmod parameters */ 58enum chips { adm9240, ds1780, lm81 };
59I2C_CLIENT_INSMOD_3(adm9240, ds1780, lm81);
60 59
61/* ADM9240 registers */ 60/* ADM9240 registers */
62#define ADM9240_REG_MAN_ID 0x3e 61#define ADM9240_REG_MAN_ID 0x3e
@@ -132,7 +131,7 @@ static inline unsigned int AOUT_FROM_REG(u8 reg)
132 131
133static int adm9240_probe(struct i2c_client *client, 132static int adm9240_probe(struct i2c_client *client,
134 const struct i2c_device_id *id); 133 const struct i2c_device_id *id);
135static int adm9240_detect(struct i2c_client *client, int kind, 134static int adm9240_detect(struct i2c_client *client,
136 struct i2c_board_info *info); 135 struct i2c_board_info *info);
137static void adm9240_init_client(struct i2c_client *client); 136static void adm9240_init_client(struct i2c_client *client);
138static int adm9240_remove(struct i2c_client *client); 137static int adm9240_remove(struct i2c_client *client);
@@ -156,7 +155,7 @@ static struct i2c_driver adm9240_driver = {
156 .remove = adm9240_remove, 155 .remove = adm9240_remove,
157 .id_table = adm9240_id, 156 .id_table = adm9240_id,
158 .detect = adm9240_detect, 157 .detect = adm9240_detect,
159 .address_data = &addr_data, 158 .address_list = normal_i2c,
160}; 159};
161 160
162/* per client data */ 161/* per client data */
@@ -545,7 +544,7 @@ static const struct attribute_group adm9240_group = {
545/*** sensor chip detect and driver install ***/ 544/*** sensor chip detect and driver install ***/
546 545
547/* Return 0 if detection is successful, -ENODEV otherwise */ 546/* Return 0 if detection is successful, -ENODEV otherwise */
548static int adm9240_detect(struct i2c_client *new_client, int kind, 547static int adm9240_detect(struct i2c_client *new_client,
549 struct i2c_board_info *info) 548 struct i2c_board_info *info)
550{ 549{
551 struct i2c_adapter *adapter = new_client->adapter; 550 struct i2c_adapter *adapter = new_client->adapter;
@@ -556,51 +555,34 @@ static int adm9240_detect(struct i2c_client *new_client, int kind,
556 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 555 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
557 return -ENODEV; 556 return -ENODEV;
558 557
559 if (kind == 0) { 558 /* verify chip: reg address should match i2c address */
560 kind = adm9240; 559 if (i2c_smbus_read_byte_data(new_client, ADM9240_REG_I2C_ADDR)
561 } 560 != address) {
562 561 dev_err(&adapter->dev, "detect fail: address match, 0x%02x\n",
563 if (kind < 0) { 562 address);
564 563 return -ENODEV;
565 /* verify chip: reg address should match i2c address */
566 if (i2c_smbus_read_byte_data(new_client, ADM9240_REG_I2C_ADDR)
567 != address) {
568 dev_err(&adapter->dev, "detect fail: address match, "
569 "0x%02x\n", address);
570 return -ENODEV;
571 }
572
573 /* check known chip manufacturer */
574 man_id = i2c_smbus_read_byte_data(new_client,
575 ADM9240_REG_MAN_ID);
576 if (man_id == 0x23) {
577 kind = adm9240;
578 } else if (man_id == 0xda) {
579 kind = ds1780;
580 } else if (man_id == 0x01) {
581 kind = lm81;
582 } else {
583 dev_err(&adapter->dev, "detect fail: unknown manuf, "
584 "0x%02x\n", man_id);
585 return -ENODEV;
586 }
587
588 /* successful detect, print chip info */
589 die_rev = i2c_smbus_read_byte_data(new_client,
590 ADM9240_REG_DIE_REV);
591 dev_info(&adapter->dev, "found %s revision %u\n",
592 man_id == 0x23 ? "ADM9240" :
593 man_id == 0xda ? "DS1780" : "LM81", die_rev);
594 } 564 }
595 565
596 /* either forced or detected chip kind */ 566 /* check known chip manufacturer */
597 if (kind == adm9240) { 567 man_id = i2c_smbus_read_byte_data(new_client, ADM9240_REG_MAN_ID);
568 if (man_id == 0x23) {
598 name = "adm9240"; 569 name = "adm9240";
599 } else if (kind == ds1780) { 570 } else if (man_id == 0xda) {
600 name = "ds1780"; 571 name = "ds1780";
601 } else if (kind == lm81) { 572 } else if (man_id == 0x01) {
602 name = "lm81"; 573 name = "lm81";
574 } else {
575 dev_err(&adapter->dev, "detect fail: unknown manuf, 0x%02x\n",
576 man_id);
577 return -ENODEV;
603 } 578 }
579
580 /* successful detect, print chip info */
581 die_rev = i2c_smbus_read_byte_data(new_client, ADM9240_REG_DIE_REV);
582 dev_info(&adapter->dev, "found %s revision %u\n",
583 man_id == 0x23 ? "ADM9240" :
584 man_id == 0xda ? "DS1780" : "LM81", die_rev);
585
604 strlcpy(info->type, name, I2C_NAME_SIZE); 586 strlcpy(info->type, name, I2C_NAME_SIZE);
605 587
606 return 0; 588 return 0;
diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c
index 5c39b4af1b23..aac85f3aed50 100644
--- a/drivers/hwmon/ads7828.c
+++ b/drivers/hwmon/ads7828.c
@@ -47,10 +47,7 @@
47static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 47static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b,
48 I2C_CLIENT_END }; 48 I2C_CLIENT_END };
49 49
50/* Insmod parameters */ 50/* Module parameters */
51I2C_CLIENT_INSMOD_1(ads7828);
52
53/* Other module parameters */
54static int se_input = 1; /* Default is SE, 0 == diff */ 51static int se_input = 1; /* Default is SE, 0 == diff */
55static int int_vref = 1; /* Default is internal ref ON */ 52static int int_vref = 1; /* Default is internal ref ON */
56static int vref_mv = ADS7828_INT_VREF_MV; /* set if vref != 2.5V */ 53static int vref_mv = ADS7828_INT_VREF_MV; /* set if vref != 2.5V */
@@ -72,7 +69,7 @@ struct ads7828_data {
72}; 69};
73 70
74/* Function declaration - necessary due to function dependencies */ 71/* Function declaration - necessary due to function dependencies */
75static int ads7828_detect(struct i2c_client *client, int kind, 72static int ads7828_detect(struct i2c_client *client,
76 struct i2c_board_info *info); 73 struct i2c_board_info *info);
77static int ads7828_probe(struct i2c_client *client, 74static int ads7828_probe(struct i2c_client *client,
78 const struct i2c_device_id *id); 75 const struct i2c_device_id *id);
@@ -168,7 +165,7 @@ static int ads7828_remove(struct i2c_client *client)
168} 165}
169 166
170static const struct i2c_device_id ads7828_id[] = { 167static const struct i2c_device_id ads7828_id[] = {
171 { "ads7828", ads7828 }, 168 { "ads7828", 0 },
172 { } 169 { }
173}; 170};
174MODULE_DEVICE_TABLE(i2c, ads7828_id); 171MODULE_DEVICE_TABLE(i2c, ads7828_id);
@@ -183,14 +180,15 @@ static struct i2c_driver ads7828_driver = {
183 .remove = ads7828_remove, 180 .remove = ads7828_remove,
184 .id_table = ads7828_id, 181 .id_table = ads7828_id,
185 .detect = ads7828_detect, 182 .detect = ads7828_detect,
186 .address_data = &addr_data, 183 .address_list = normal_i2c,
187}; 184};
188 185
189/* Return 0 if detection is successful, -ENODEV otherwise */ 186/* Return 0 if detection is successful, -ENODEV otherwise */
190static int ads7828_detect(struct i2c_client *client, int kind, 187static int ads7828_detect(struct i2c_client *client,
191 struct i2c_board_info *info) 188 struct i2c_board_info *info)
192{ 189{
193 struct i2c_adapter *adapter = client->adapter; 190 struct i2c_adapter *adapter = client->adapter;
191 int ch;
194 192
195 /* Check we have a valid client */ 193 /* Check we have a valid client */
196 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA)) 194 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA))
@@ -202,20 +200,17 @@ static int ads7828_detect(struct i2c_client *client, int kind,
202 - Read from the 8 channel addresses 200 - Read from the 8 channel addresses
203 - Check the top 4 bits of each result are not set (12 data bits) 201 - Check the top 4 bits of each result are not set (12 data bits)
204 */ 202 */
205 if (kind < 0) { 203 for (ch = 0; ch < ADS7828_NCH; ch++) {
206 int ch; 204 u16 in_data;
207 for (ch = 0; ch < ADS7828_NCH; ch++) { 205 u8 cmd = channel_cmd_byte(ch);
208 u16 in_data; 206 in_data = ads7828_read_value(client, cmd);
209 u8 cmd = channel_cmd_byte(ch); 207 if (in_data & 0xF000) {
210 in_data = ads7828_read_value(client, cmd); 208 pr_debug("%s : Doesn't look like an ads7828 device\n",
211 if (in_data & 0xF000) { 209 __func__);
212 printk(KERN_DEBUG 210 return -ENODEV;
213 "%s : Doesn't look like an ads7828 device\n",
214 __func__);
215 return -ENODEV;
216 }
217 } 211 }
218 } 212 }
213
219 strlcpy(info->type, "ads7828", I2C_NAME_SIZE); 214 strlcpy(info->type, "ads7828", I2C_NAME_SIZE);
220 215
221 return 0; 216 return 0;
diff --git a/drivers/hwmon/adt7411.c b/drivers/hwmon/adt7411.c
new file mode 100644
index 000000000000..4086c7257f91
--- /dev/null
+++ b/drivers/hwmon/adt7411.c
@@ -0,0 +1,367 @@
1/*
2 * Driver for the ADT7411 (I2C/SPI 8 channel 10 bit ADC & temperature-sensor)
3 *
4 * Copyright (C) 2008, 2010 Pengutronix
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 version 2 as
8 * published by the Free Software Foundation.
9 *
10 * TODO: SPI, support for external temperature sensor
11 * use power-down mode for suspend?, interrupt handling?
12 */
13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/err.h>
18#include <linux/delay.h>
19#include <linux/mutex.h>
20#include <linux/jiffies.h>
21#include <linux/i2c.h>
22#include <linux/hwmon.h>
23#include <linux/hwmon-sysfs.h>
24#include <linux/slab.h>
25
26#define ADT7411_REG_INT_TEMP_VDD_LSB 0x03
27#define ADT7411_REG_EXT_TEMP_AIN14_LSB 0x04
28#define ADT7411_REG_VDD_MSB 0x06
29#define ADT7411_REG_INT_TEMP_MSB 0x07
30#define ADT7411_REG_EXT_TEMP_AIN1_MSB 0x08
31
32#define ADT7411_REG_CFG1 0x18
33#define ADT7411_CFG1_START_MONITOR (1 << 0)
34
35#define ADT7411_REG_CFG2 0x19
36#define ADT7411_CFG2_DISABLE_AVG (1 << 5)
37
38#define ADT7411_REG_CFG3 0x1a
39#define ADT7411_CFG3_ADC_CLK_225 (1 << 0)
40#define ADT7411_CFG3_REF_VDD (1 << 4)
41
42#define ADT7411_REG_DEVICE_ID 0x4d
43#define ADT7411_REG_MANUFACTURER_ID 0x4e
44
45#define ADT7411_DEVICE_ID 0x2
46#define ADT7411_MANUFACTURER_ID 0x41
47
48static const unsigned short normal_i2c[] = { 0x48, 0x4a, 0x4b, I2C_CLIENT_END };
49
50struct adt7411_data {
51 struct mutex device_lock; /* for "atomic" device accesses */
52 struct mutex update_lock;
53 unsigned long next_update;
54 int vref_cached;
55 struct device *hwmon_dev;
56};
57
58/*
59 * When reading a register containing (up to 4) lsb, all associated
60 * msb-registers get locked by the hardware. After _one_ of those msb is read,
61 * _all_ are unlocked. In order to use this locking correctly, reading lsb/msb
62 * is protected here with a mutex, too.
63 */
64static int adt7411_read_10_bit(struct i2c_client *client, u8 lsb_reg,
65 u8 msb_reg, u8 lsb_shift)
66{
67 struct adt7411_data *data = i2c_get_clientdata(client);
68 int val, tmp;
69
70 mutex_lock(&data->device_lock);
71
72 val = i2c_smbus_read_byte_data(client, lsb_reg);
73 if (val < 0)
74 goto exit_unlock;
75
76 tmp = (val >> lsb_shift) & 3;
77 val = i2c_smbus_read_byte_data(client, msb_reg);
78
79 if (val >= 0)
80 val = (val << 2) | tmp;
81
82 exit_unlock:
83 mutex_unlock(&data->device_lock);
84
85 return val;
86}
87
88static int adt7411_modify_bit(struct i2c_client *client, u8 reg, u8 bit,
89 bool flag)
90{
91 struct adt7411_data *data = i2c_get_clientdata(client);
92 int ret, val;
93
94 mutex_lock(&data->device_lock);
95
96 ret = i2c_smbus_read_byte_data(client, reg);
97 if (ret < 0)
98 goto exit_unlock;
99
100 if (flag)
101 val = ret | bit;
102 else
103 val = ret & ~bit;
104
105 ret = i2c_smbus_write_byte_data(client, reg, val);
106
107 exit_unlock:
108 mutex_unlock(&data->device_lock);
109 return ret;
110}
111
112static ssize_t adt7411_show_vdd(struct device *dev,
113 struct device_attribute *attr, char *buf)
114{
115 struct i2c_client *client = to_i2c_client(dev);
116 int ret = adt7411_read_10_bit(client, ADT7411_REG_INT_TEMP_VDD_LSB,
117 ADT7411_REG_VDD_MSB, 2);
118
119 return ret < 0 ? ret : sprintf(buf, "%u\n", ret * 7000 / 1024);
120}
121
122static ssize_t adt7411_show_temp(struct device *dev,
123 struct device_attribute *attr, char *buf)
124{
125 struct i2c_client *client = to_i2c_client(dev);
126 int val = adt7411_read_10_bit(client, ADT7411_REG_INT_TEMP_VDD_LSB,
127 ADT7411_REG_INT_TEMP_MSB, 0);
128
129 if (val < 0)
130 return val;
131
132 val = val & 0x200 ? val - 0x400 : val; /* 10 bit signed */
133
134 return sprintf(buf, "%d\n", val * 250);
135}
136
137static ssize_t adt7411_show_input(struct device *dev,
138 struct device_attribute *attr, char *buf)
139{
140 int nr = to_sensor_dev_attr(attr)->index;
141 struct i2c_client *client = to_i2c_client(dev);
142 struct adt7411_data *data = i2c_get_clientdata(client);
143 int val;
144 u8 lsb_reg, lsb_shift;
145
146 mutex_lock(&data->update_lock);
147 if (time_after_eq(jiffies, data->next_update)) {
148 val = i2c_smbus_read_byte_data(client, ADT7411_REG_CFG3);
149 if (val < 0)
150 goto exit_unlock;
151
152 if (val & ADT7411_CFG3_REF_VDD) {
153 val = adt7411_read_10_bit(client,
154 ADT7411_REG_INT_TEMP_VDD_LSB,
155 ADT7411_REG_VDD_MSB, 2);
156 if (val < 0)
157 goto exit_unlock;
158
159 data->vref_cached = val * 7000 / 1024;
160 } else {
161 data->vref_cached = 2250;
162 }
163
164 data->next_update = jiffies + HZ;
165 }
166
167 lsb_reg = ADT7411_REG_EXT_TEMP_AIN14_LSB + (nr >> 2);
168 lsb_shift = 2 * (nr & 0x03);
169 val = adt7411_read_10_bit(client, lsb_reg,
170 ADT7411_REG_EXT_TEMP_AIN1_MSB + nr, lsb_shift);
171 if (val < 0)
172 goto exit_unlock;
173
174 val = sprintf(buf, "%u\n", val * data->vref_cached / 1024);
175 exit_unlock:
176 mutex_unlock(&data->update_lock);
177 return val;
178}
179
180static ssize_t adt7411_show_bit(struct device *dev,
181 struct device_attribute *attr, char *buf)
182{
183 struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr);
184 struct i2c_client *client = to_i2c_client(dev);
185 int ret = i2c_smbus_read_byte_data(client, attr2->index);
186
187 return ret < 0 ? ret : sprintf(buf, "%u\n", !!(ret & attr2->nr));
188}
189
190static ssize_t adt7411_set_bit(struct device *dev,
191 struct device_attribute *attr, const char *buf,
192 size_t count)
193{
194 struct sensor_device_attribute_2 *s_attr2 = to_sensor_dev_attr_2(attr);
195 struct i2c_client *client = to_i2c_client(dev);
196 struct adt7411_data *data = i2c_get_clientdata(client);
197 int ret;
198 unsigned long flag;
199
200 ret = strict_strtoul(buf, 0, &flag);
201 if (ret || flag > 1)
202 return -EINVAL;
203
204 ret = adt7411_modify_bit(client, s_attr2->index, s_attr2->nr, flag);
205
206 /* force update */
207 mutex_lock(&data->update_lock);
208 data->next_update = jiffies;
209 mutex_unlock(&data->update_lock);
210
211 return ret < 0 ? ret : count;
212}
213
214#define ADT7411_BIT_ATTR(__name, __reg, __bit) \
215 SENSOR_DEVICE_ATTR_2(__name, S_IRUGO | S_IWUSR, adt7411_show_bit, \
216 adt7411_set_bit, __bit, __reg)
217
218static DEVICE_ATTR(temp1_input, S_IRUGO, adt7411_show_temp, NULL);
219static DEVICE_ATTR(in0_input, S_IRUGO, adt7411_show_vdd, NULL);
220static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, adt7411_show_input, NULL, 0);
221static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, adt7411_show_input, NULL, 1);
222static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, adt7411_show_input, NULL, 2);
223static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, adt7411_show_input, NULL, 3);
224static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, adt7411_show_input, NULL, 4);
225static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, adt7411_show_input, NULL, 5);
226static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, adt7411_show_input, NULL, 6);
227static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, adt7411_show_input, NULL, 7);
228static ADT7411_BIT_ATTR(no_average, ADT7411_REG_CFG2, ADT7411_CFG2_DISABLE_AVG);
229static ADT7411_BIT_ATTR(fast_sampling, ADT7411_REG_CFG3, ADT7411_CFG3_ADC_CLK_225);
230static ADT7411_BIT_ATTR(adc_ref_vdd, ADT7411_REG_CFG3, ADT7411_CFG3_REF_VDD);
231
232static struct attribute *adt7411_attrs[] = {
233 &dev_attr_temp1_input.attr,
234 &dev_attr_in0_input.attr,
235 &sensor_dev_attr_in1_input.dev_attr.attr,
236 &sensor_dev_attr_in2_input.dev_attr.attr,
237 &sensor_dev_attr_in3_input.dev_attr.attr,
238 &sensor_dev_attr_in4_input.dev_attr.attr,
239 &sensor_dev_attr_in5_input.dev_attr.attr,
240 &sensor_dev_attr_in6_input.dev_attr.attr,
241 &sensor_dev_attr_in7_input.dev_attr.attr,
242 &sensor_dev_attr_in8_input.dev_attr.attr,
243 &sensor_dev_attr_no_average.dev_attr.attr,
244 &sensor_dev_attr_fast_sampling.dev_attr.attr,
245 &sensor_dev_attr_adc_ref_vdd.dev_attr.attr,
246 NULL
247};
248
249static const struct attribute_group adt7411_attr_grp = {
250 .attrs = adt7411_attrs,
251};
252
253static int adt7411_detect(struct i2c_client *client,
254 struct i2c_board_info *info)
255{
256 int val;
257
258 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
259 return -ENODEV;
260
261 val = i2c_smbus_read_byte_data(client, ADT7411_REG_MANUFACTURER_ID);
262 if (val < 0 || val != ADT7411_MANUFACTURER_ID) {
263 dev_dbg(&client->dev, "Wrong manufacturer ID. Got %d, "
264 "expected %d\n", val, ADT7411_MANUFACTURER_ID);
265 return -ENODEV;
266 }
267
268 val = i2c_smbus_read_byte_data(client, ADT7411_REG_DEVICE_ID);
269 if (val < 0 || val != ADT7411_DEVICE_ID) {
270 dev_dbg(&client->dev, "Wrong device ID. Got %d, "
271 "expected %d\n", val, ADT7411_DEVICE_ID);
272 return -ENODEV;
273 }
274
275 strlcpy(info->type, "adt7411", I2C_NAME_SIZE);
276
277 return 0;
278}
279
280static int __devinit adt7411_probe(struct i2c_client *client,
281 const struct i2c_device_id *id)
282{
283 struct adt7411_data *data;
284 int ret;
285
286 data = kzalloc(sizeof(*data), GFP_KERNEL);
287 if (!data)
288 return -ENOMEM;
289
290 i2c_set_clientdata(client, data);
291 mutex_init(&data->device_lock);
292 mutex_init(&data->update_lock);
293
294 ret = adt7411_modify_bit(client, ADT7411_REG_CFG1,
295 ADT7411_CFG1_START_MONITOR, 1);
296 if (ret < 0)
297 goto exit_free;
298
299 /* force update on first occasion */
300 data->next_update = jiffies;
301
302 ret = sysfs_create_group(&client->dev.kobj, &adt7411_attr_grp);
303 if (ret)
304 goto exit_free;
305
306 data->hwmon_dev = hwmon_device_register(&client->dev);
307 if (IS_ERR(data->hwmon_dev)) {
308 ret = PTR_ERR(data->hwmon_dev);
309 goto exit_remove;
310 }
311
312 dev_info(&client->dev, "successfully registered\n");
313
314 return 0;
315
316 exit_remove:
317 sysfs_remove_group(&client->dev.kobj, &adt7411_attr_grp);
318 exit_free:
319 i2c_set_clientdata(client, NULL);
320 kfree(data);
321 return ret;
322}
323
324static int __devexit adt7411_remove(struct i2c_client *client)
325{
326 struct adt7411_data *data = i2c_get_clientdata(client);
327
328 hwmon_device_unregister(data->hwmon_dev);
329 sysfs_remove_group(&client->dev.kobj, &adt7411_attr_grp);
330 i2c_set_clientdata(client, NULL);
331 kfree(data);
332 return 0;
333}
334
335static const struct i2c_device_id adt7411_id[] = {
336 { "adt7411", 0 },
337 { }
338};
339
340static struct i2c_driver adt7411_driver = {
341 .driver = {
342 .name = "adt7411",
343 },
344 .probe = adt7411_probe,
345 .remove = __devexit_p(adt7411_remove),
346 .id_table = adt7411_id,
347 .detect = adt7411_detect,
348 .address_list = normal_i2c,
349 .class = I2C_CLASS_HWMON,
350};
351
352static int __init sensors_adt7411_init(void)
353{
354 return i2c_add_driver(&adt7411_driver);
355}
356module_init(sensors_adt7411_init)
357
358static void __exit sensors_adt7411_exit(void)
359{
360 i2c_del_driver(&adt7411_driver);
361}
362module_exit(sensors_adt7411_exit)
363
364MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de> and "
365 "Wolfram Sang <w.sang@pengutronix.de>");
366MODULE_DESCRIPTION("ADT7411 driver");
367MODULE_LICENSE("GPL v2");
diff --git a/drivers/hwmon/adt7462.c b/drivers/hwmon/adt7462.c
index 1852f27bac51..2af0c7b6b4e4 100644
--- a/drivers/hwmon/adt7462.c
+++ b/drivers/hwmon/adt7462.c
@@ -28,13 +28,11 @@
28#include <linux/mutex.h> 28#include <linux/mutex.h>
29#include <linux/delay.h> 29#include <linux/delay.h>
30#include <linux/log2.h> 30#include <linux/log2.h>
31#include <linux/slab.h>
31 32
32/* Addresses to scan */ 33/* Addresses to scan */
33static const unsigned short normal_i2c[] = { 0x58, 0x5C, I2C_CLIENT_END }; 34static const unsigned short normal_i2c[] = { 0x58, 0x5C, I2C_CLIENT_END };
34 35
35/* Insmod parameters */
36I2C_CLIENT_INSMOD_1(adt7462);
37
38/* ADT7462 registers */ 36/* ADT7462 registers */
39#define ADT7462_REG_DEVICE 0x3D 37#define ADT7462_REG_DEVICE 0x3D
40#define ADT7462_REG_VENDOR 0x3E 38#define ADT7462_REG_VENDOR 0x3E
@@ -97,7 +95,7 @@ I2C_CLIENT_INSMOD_1(adt7462);
97#define ADT7462_PIN24_SHIFT 6 95#define ADT7462_PIN24_SHIFT 6
98#define ADT7462_PIN26_VOLT_INPUT 0x08 96#define ADT7462_PIN26_VOLT_INPUT 0x08
99#define ADT7462_PIN25_VOLT_INPUT 0x20 97#define ADT7462_PIN25_VOLT_INPUT 0x20
100#define ADT7462_PIN28_SHIFT 6 /* cfg3 */ 98#define ADT7462_PIN28_SHIFT 4 /* cfg3 */
101#define ADT7462_PIN28_VOLT 0x5 99#define ADT7462_PIN28_VOLT 0x5
102 100
103#define ADT7462_REG_ALARM1 0xB8 101#define ADT7462_REG_ALARM1 0xB8
@@ -182,7 +180,7 @@ I2C_CLIENT_INSMOD_1(adt7462);
182 * 180 *
183 * Some, but not all, of these voltages have low/high limits. 181 * Some, but not all, of these voltages have low/high limits.
184 */ 182 */
185#define ADT7462_VOLT_COUNT 12 183#define ADT7462_VOLT_COUNT 13
186 184
187#define ADT7462_VENDOR 0x41 185#define ADT7462_VENDOR 0x41
188#define ADT7462_DEVICE 0x62 186#define ADT7462_DEVICE 0x62
@@ -237,12 +235,12 @@ struct adt7462_data {
237 235
238static int adt7462_probe(struct i2c_client *client, 236static int adt7462_probe(struct i2c_client *client,
239 const struct i2c_device_id *id); 237 const struct i2c_device_id *id);
240static int adt7462_detect(struct i2c_client *client, int kind, 238static int adt7462_detect(struct i2c_client *client,
241 struct i2c_board_info *info); 239 struct i2c_board_info *info);
242static int adt7462_remove(struct i2c_client *client); 240static int adt7462_remove(struct i2c_client *client);
243 241
244static const struct i2c_device_id adt7462_id[] = { 242static const struct i2c_device_id adt7462_id[] = {
245 { "adt7462", adt7462 }, 243 { "adt7462", 0 },
246 { } 244 { }
247}; 245};
248MODULE_DEVICE_TABLE(i2c, adt7462_id); 246MODULE_DEVICE_TABLE(i2c, adt7462_id);
@@ -256,7 +254,7 @@ static struct i2c_driver adt7462_driver = {
256 .remove = adt7462_remove, 254 .remove = adt7462_remove,
257 .id_table = adt7462_id, 255 .id_table = adt7462_id,
258 .detect = adt7462_detect, 256 .detect = adt7462_detect,
259 .address_data = &addr_data, 257 .address_list = normal_i2c,
260}; 258};
261 259
262/* 260/*
@@ -1902,31 +1900,26 @@ static struct attribute *adt7462_attr[] =
1902}; 1900};
1903 1901
1904/* Return 0 if detection is successful, -ENODEV otherwise */ 1902/* Return 0 if detection is successful, -ENODEV otherwise */
1905static int adt7462_detect(struct i2c_client *client, int kind, 1903static int adt7462_detect(struct i2c_client *client,
1906 struct i2c_board_info *info) 1904 struct i2c_board_info *info)
1907{ 1905{
1908 struct i2c_adapter *adapter = client->adapter; 1906 struct i2c_adapter *adapter = client->adapter;
1907 int vendor, device, revision;
1909 1908
1910 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1909 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1911 return -ENODEV; 1910 return -ENODEV;
1912 1911
1913 if (kind <= 0) { 1912 vendor = i2c_smbus_read_byte_data(client, ADT7462_REG_VENDOR);
1914 int vendor, device, revision; 1913 if (vendor != ADT7462_VENDOR)
1915 1914 return -ENODEV;
1916 vendor = i2c_smbus_read_byte_data(client, ADT7462_REG_VENDOR);
1917 if (vendor != ADT7462_VENDOR)
1918 return -ENODEV;
1919 1915
1920 device = i2c_smbus_read_byte_data(client, ADT7462_REG_DEVICE); 1916 device = i2c_smbus_read_byte_data(client, ADT7462_REG_DEVICE);
1921 if (device != ADT7462_DEVICE) 1917 if (device != ADT7462_DEVICE)
1922 return -ENODEV; 1918 return -ENODEV;
1923 1919
1924 revision = i2c_smbus_read_byte_data(client, 1920 revision = i2c_smbus_read_byte_data(client, ADT7462_REG_REVISION);
1925 ADT7462_REG_REVISION); 1921 if (revision != ADT7462_REVISION)
1926 if (revision != ADT7462_REVISION) 1922 return -ENODEV;
1927 return -ENODEV;
1928 } else
1929 dev_dbg(&adapter->dev, "detection forced\n");
1930 1923
1931 strlcpy(info->type, "adt7462", I2C_NAME_SIZE); 1924 strlcpy(info->type, "adt7462", I2C_NAME_SIZE);
1932 1925
diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
index 633e1a1e9d79..9e775717abb7 100644
--- a/drivers/hwmon/adt7470.c
+++ b/drivers/hwmon/adt7470.c
@@ -29,13 +29,11 @@
29#include <linux/delay.h> 29#include <linux/delay.h>
30#include <linux/log2.h> 30#include <linux/log2.h>
31#include <linux/kthread.h> 31#include <linux/kthread.h>
32#include <linux/slab.h>
32 33
33/* Addresses to scan */ 34/* Addresses to scan */
34static const unsigned short normal_i2c[] = { 0x2C, 0x2E, 0x2F, I2C_CLIENT_END }; 35static const unsigned short normal_i2c[] = { 0x2C, 0x2E, 0x2F, I2C_CLIENT_END };
35 36
36/* Insmod parameters */
37I2C_CLIENT_INSMOD_1(adt7470);
38
39/* ADT7470 registers */ 37/* ADT7470 registers */
40#define ADT7470_REG_BASE_ADDR 0x20 38#define ADT7470_REG_BASE_ADDR 0x20
41#define ADT7470_REG_TEMP_BASE_ADDR 0x20 39#define ADT7470_REG_TEMP_BASE_ADDR 0x20
@@ -177,12 +175,12 @@ struct adt7470_data {
177 175
178static int adt7470_probe(struct i2c_client *client, 176static int adt7470_probe(struct i2c_client *client,
179 const struct i2c_device_id *id); 177 const struct i2c_device_id *id);
180static int adt7470_detect(struct i2c_client *client, int kind, 178static int adt7470_detect(struct i2c_client *client,
181 struct i2c_board_info *info); 179 struct i2c_board_info *info);
182static int adt7470_remove(struct i2c_client *client); 180static int adt7470_remove(struct i2c_client *client);
183 181
184static const struct i2c_device_id adt7470_id[] = { 182static const struct i2c_device_id adt7470_id[] = {
185 { "adt7470", adt7470 }, 183 { "adt7470", 0 },
186 { } 184 { }
187}; 185};
188MODULE_DEVICE_TABLE(i2c, adt7470_id); 186MODULE_DEVICE_TABLE(i2c, adt7470_id);
@@ -196,7 +194,7 @@ static struct i2c_driver adt7470_driver = {
196 .remove = adt7470_remove, 194 .remove = adt7470_remove,
197 .id_table = adt7470_id, 195 .id_table = adt7470_id,
198 .detect = adt7470_detect, 196 .detect = adt7470_detect,
199 .address_data = &addr_data, 197 .address_list = normal_i2c,
200}; 198};
201 199
202/* 200/*
@@ -1225,31 +1223,26 @@ static struct attribute *adt7470_attr[] =
1225}; 1223};
1226 1224
1227/* Return 0 if detection is successful, -ENODEV otherwise */ 1225/* Return 0 if detection is successful, -ENODEV otherwise */
1228static int adt7470_detect(struct i2c_client *client, int kind, 1226static int adt7470_detect(struct i2c_client *client,
1229 struct i2c_board_info *info) 1227 struct i2c_board_info *info)
1230{ 1228{
1231 struct i2c_adapter *adapter = client->adapter; 1229 struct i2c_adapter *adapter = client->adapter;
1230 int vendor, device, revision;
1232 1231
1233 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1232 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1234 return -ENODEV; 1233 return -ENODEV;
1235 1234
1236 if (kind <= 0) { 1235 vendor = i2c_smbus_read_byte_data(client, ADT7470_REG_VENDOR);
1237 int vendor, device, revision; 1236 if (vendor != ADT7470_VENDOR)
1238 1237 return -ENODEV;
1239 vendor = i2c_smbus_read_byte_data(client, ADT7470_REG_VENDOR);
1240 if (vendor != ADT7470_VENDOR)
1241 return -ENODEV;
1242 1238
1243 device = i2c_smbus_read_byte_data(client, ADT7470_REG_DEVICE); 1239 device = i2c_smbus_read_byte_data(client, ADT7470_REG_DEVICE);
1244 if (device != ADT7470_DEVICE) 1240 if (device != ADT7470_DEVICE)
1245 return -ENODEV; 1241 return -ENODEV;
1246 1242
1247 revision = i2c_smbus_read_byte_data(client, 1243 revision = i2c_smbus_read_byte_data(client, ADT7470_REG_REVISION);
1248 ADT7470_REG_REVISION); 1244 if (revision != ADT7470_REVISION)
1249 if (revision != ADT7470_REVISION) 1245 return -ENODEV;
1250 return -ENODEV;
1251 } else
1252 dev_dbg(&adapter->dev, "detection forced\n");
1253 1246
1254 strlcpy(info->type, "adt7470", I2C_NAME_SIZE); 1247 strlcpy(info->type, "adt7470", I2C_NAME_SIZE);
1255 1248
diff --git a/drivers/hwmon/adt7473.c b/drivers/hwmon/adt7473.c
deleted file mode 100644
index 0a6ce2367b42..000000000000
--- a/drivers/hwmon/adt7473.c
+++ /dev/null
@@ -1,1187 +0,0 @@
1/*
2 * A hwmon driver for the Analog Devices ADT7473
3 * Copyright (C) 2007 IBM
4 *
5 * Author: Darrick J. Wong <djwong@us.ibm.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#include <linux/module.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/mutex.h>
29#include <linux/delay.h>
30#include <linux/log2.h>
31
32/* Addresses to scan */
33static const unsigned short normal_i2c[] = { 0x2C, 0x2D, 0x2E, I2C_CLIENT_END };
34
35/* Insmod parameters */
36I2C_CLIENT_INSMOD_1(adt7473);
37
38/* ADT7473 registers */
39#define ADT7473_REG_BASE_ADDR 0x20
40
41#define ADT7473_REG_VOLT_BASE_ADDR 0x21
42#define ADT7473_REG_VOLT_MIN_BASE_ADDR 0x46
43
44#define ADT7473_REG_TEMP_BASE_ADDR 0x25
45#define ADT7473_REG_TEMP_LIMITS_BASE_ADDR 0x4E
46#define ADT7473_REG_TEMP_TMIN_BASE_ADDR 0x67
47#define ADT7473_REG_TEMP_TMAX_BASE_ADDR 0x6A
48
49#define ADT7473_REG_FAN_BASE_ADDR 0x28
50#define ADT7473_REG_FAN_MIN_BASE_ADDR 0x54
51
52#define ADT7473_REG_PWM_BASE_ADDR 0x30
53#define ADT7473_REG_PWM_MIN_BASE_ADDR 0x64
54#define ADT7473_REG_PWM_MAX_BASE_ADDR 0x38
55#define ADT7473_REG_PWM_BHVR_BASE_ADDR 0x5C
56#define ADT7473_PWM_BHVR_MASK 0xE0
57#define ADT7473_PWM_BHVR_SHIFT 5
58
59#define ADT7473_REG_CFG1 0x40
60#define ADT7473_CFG1_START 0x01
61#define ADT7473_CFG1_READY 0x04
62#define ADT7473_REG_CFG2 0x73
63#define ADT7473_REG_CFG3 0x78
64#define ADT7473_REG_CFG4 0x7D
65#define ADT7473_CFG4_MAX_DUTY_AT_OVT 0x08
66#define ADT7473_REG_CFG5 0x7C
67#define ADT7473_CFG5_TEMP_TWOS 0x01
68#define ADT7473_CFG5_TEMP_OFFSET 0x02
69
70#define ADT7473_REG_DEVICE 0x3D
71#define ADT7473_VENDOR 0x41
72#define ADT7473_REG_VENDOR 0x3E
73#define ADT7473_DEVICE 0x73
74#define ADT7473_REG_REVISION 0x3F
75#define ADT7473_REV_68 0x68
76#define ADT7473_REV_69 0x69
77
78#define ADT7473_REG_ALARM1 0x41
79#define ADT7473_VCCP_ALARM 0x02
80#define ADT7473_VCC_ALARM 0x04
81#define ADT7473_R1T_ALARM 0x10
82#define ADT7473_LT_ALARM 0x20
83#define ADT7473_R2T_ALARM 0x40
84#define ADT7473_OOL 0x80
85#define ADT7473_REG_ALARM2 0x42
86#define ADT7473_OVT_ALARM 0x02
87#define ADT7473_FAN1_ALARM 0x04
88#define ADT7473_FAN2_ALARM 0x08
89#define ADT7473_FAN3_ALARM 0x10
90#define ADT7473_FAN4_ALARM 0x20
91#define ADT7473_R1T_SHORT 0x40
92#define ADT7473_R2T_SHORT 0x80
93
94#define ALARM2(x) ((x) << 8)
95
96#define ADT7473_VOLT_COUNT 2
97#define ADT7473_REG_VOLT(x) (ADT7473_REG_VOLT_BASE_ADDR + (x))
98#define ADT7473_REG_VOLT_MIN(x) (ADT7473_REG_VOLT_MIN_BASE_ADDR + ((x) * 2))
99#define ADT7473_REG_VOLT_MAX(x) (ADT7473_REG_VOLT_MIN_BASE_ADDR + \
100 ((x) * 2) + 1)
101
102#define ADT7473_TEMP_COUNT 3
103#define ADT7473_REG_TEMP(x) (ADT7473_REG_TEMP_BASE_ADDR + (x))
104#define ADT7473_REG_TEMP_MIN(x) (ADT7473_REG_TEMP_LIMITS_BASE_ADDR + ((x) * 2))
105#define ADT7473_REG_TEMP_MAX(x) (ADT7473_REG_TEMP_LIMITS_BASE_ADDR + \
106 ((x) * 2) + 1)
107#define ADT7473_REG_TEMP_TMIN(x) (ADT7473_REG_TEMP_TMIN_BASE_ADDR + (x))
108#define ADT7473_REG_TEMP_TMAX(x) (ADT7473_REG_TEMP_TMAX_BASE_ADDR + (x))
109
110#define ADT7473_FAN_COUNT 4
111#define ADT7473_REG_FAN(x) (ADT7473_REG_FAN_BASE_ADDR + ((x) * 2))
112#define ADT7473_REG_FAN_MIN(x) (ADT7473_REG_FAN_MIN_BASE_ADDR + ((x) * 2))
113
114#define ADT7473_PWM_COUNT 3
115#define ADT7473_REG_PWM(x) (ADT7473_REG_PWM_BASE_ADDR + (x))
116#define ADT7473_REG_PWM_MAX(x) (ADT7473_REG_PWM_MAX_BASE_ADDR + (x))
117#define ADT7473_REG_PWM_MIN(x) (ADT7473_REG_PWM_MIN_BASE_ADDR + (x))
118#define ADT7473_REG_PWM_BHVR(x) (ADT7473_REG_PWM_BHVR_BASE_ADDR + (x))
119
120/* How often do we reread sensors values? (In jiffies) */
121#define SENSOR_REFRESH_INTERVAL (2 * HZ)
122
123/* How often do we reread sensor limit values? (In jiffies) */
124#define LIMIT_REFRESH_INTERVAL (60 * HZ)
125
126/* datasheet says to divide this number by the fan reading to get fan rpm */
127#define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x))
128#define FAN_RPM_TO_PERIOD FAN_PERIOD_TO_RPM
129#define FAN_PERIOD_INVALID 65535
130#define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID)
131
132struct adt7473_data {
133 struct device *hwmon_dev;
134 struct attribute_group attrs;
135 struct mutex lock;
136 char sensors_valid;
137 char limits_valid;
138 unsigned long sensors_last_updated; /* In jiffies */
139 unsigned long limits_last_updated; /* In jiffies */
140
141 u8 volt[ADT7473_VOLT_COUNT];
142 s8 volt_min[ADT7473_VOLT_COUNT];
143 s8 volt_max[ADT7473_VOLT_COUNT];
144
145 s8 temp[ADT7473_TEMP_COUNT];
146 s8 temp_min[ADT7473_TEMP_COUNT];
147 s8 temp_max[ADT7473_TEMP_COUNT];
148 s8 temp_tmin[ADT7473_TEMP_COUNT];
149 /* This is called the !THERM limit in the datasheet */
150 s8 temp_tmax[ADT7473_TEMP_COUNT];
151
152 u16 fan[ADT7473_FAN_COUNT];
153 u16 fan_min[ADT7473_FAN_COUNT];
154
155 u8 pwm[ADT7473_PWM_COUNT];
156 u8 pwm_max[ADT7473_PWM_COUNT];
157 u8 pwm_min[ADT7473_PWM_COUNT];
158 u8 pwm_behavior[ADT7473_PWM_COUNT];
159
160 u8 temp_twos_complement;
161 u8 temp_offset;
162
163 u16 alarm;
164 u8 max_duty_at_overheat;
165};
166
167static int adt7473_probe(struct i2c_client *client,
168 const struct i2c_device_id *id);
169static int adt7473_detect(struct i2c_client *client, int kind,
170 struct i2c_board_info *info);
171static int adt7473_remove(struct i2c_client *client);
172
173static const struct i2c_device_id adt7473_id[] = {
174 { "adt7473", adt7473 },
175 { }
176};
177MODULE_DEVICE_TABLE(i2c, adt7473_id);
178
179static struct i2c_driver adt7473_driver = {
180 .class = I2C_CLASS_HWMON,
181 .driver = {
182 .name = "adt7473",
183 },
184 .probe = adt7473_probe,
185 .remove = adt7473_remove,
186 .id_table = adt7473_id,
187 .detect = adt7473_detect,
188 .address_data = &addr_data,
189};
190
191/*
192 * 16-bit registers on the ADT7473 are low-byte first. The data sheet says
193 * that the low byte must be read before the high byte.
194 */
195static inline int adt7473_read_word_data(struct i2c_client *client, u8 reg)
196{
197 u16 foo;
198 foo = i2c_smbus_read_byte_data(client, reg);
199 foo |= ((u16)i2c_smbus_read_byte_data(client, reg + 1) << 8);
200 return foo;
201}
202
203static inline int adt7473_write_word_data(struct i2c_client *client, u8 reg,
204 u16 value)
205{
206 return i2c_smbus_write_byte_data(client, reg, value & 0xFF)
207 && i2c_smbus_write_byte_data(client, reg + 1, value >> 8);
208}
209
210static void adt7473_init_client(struct i2c_client *client)
211{
212 int reg = i2c_smbus_read_byte_data(client, ADT7473_REG_CFG1);
213
214 if (!(reg & ADT7473_CFG1_READY)) {
215 dev_err(&client->dev, "Chip not ready.\n");
216 } else {
217 /* start monitoring */
218 i2c_smbus_write_byte_data(client, ADT7473_REG_CFG1,
219 reg | ADT7473_CFG1_START);
220 }
221}
222
223static struct adt7473_data *adt7473_update_device(struct device *dev)
224{
225 struct i2c_client *client = to_i2c_client(dev);
226 struct adt7473_data *data = i2c_get_clientdata(client);
227 unsigned long local_jiffies = jiffies;
228 u8 cfg;
229 int i;
230
231 mutex_lock(&data->lock);
232 if (time_before(local_jiffies, data->sensors_last_updated +
233 SENSOR_REFRESH_INTERVAL)
234 && data->sensors_valid)
235 goto no_sensor_update;
236
237 for (i = 0; i < ADT7473_VOLT_COUNT; i++)
238 data->volt[i] = i2c_smbus_read_byte_data(client,
239 ADT7473_REG_VOLT(i));
240
241 /* Determine temperature encoding */
242 cfg = i2c_smbus_read_byte_data(client, ADT7473_REG_CFG5);
243 data->temp_twos_complement = (cfg & ADT7473_CFG5_TEMP_TWOS);
244
245 /*
246 * What does this do? it implies a variable temperature sensor
247 * offset, but the datasheet doesn't say anything about this bit
248 * and other parts of the datasheet imply that "offset64" mode
249 * means that you shift temp values by -64 if the above bit was set.
250 */
251 data->temp_offset = (cfg & ADT7473_CFG5_TEMP_OFFSET);
252
253 for (i = 0; i < ADT7473_TEMP_COUNT; i++)
254 data->temp[i] = i2c_smbus_read_byte_data(client,
255 ADT7473_REG_TEMP(i));
256
257 for (i = 0; i < ADT7473_FAN_COUNT; i++)
258 data->fan[i] = adt7473_read_word_data(client,
259 ADT7473_REG_FAN(i));
260
261 for (i = 0; i < ADT7473_PWM_COUNT; i++)
262 data->pwm[i] = i2c_smbus_read_byte_data(client,
263 ADT7473_REG_PWM(i));
264
265 data->alarm = i2c_smbus_read_byte_data(client, ADT7473_REG_ALARM1);
266 if (data->alarm & ADT7473_OOL)
267 data->alarm |= ALARM2(i2c_smbus_read_byte_data(client,
268 ADT7473_REG_ALARM2));
269
270 data->sensors_last_updated = local_jiffies;
271 data->sensors_valid = 1;
272
273no_sensor_update:
274 if (time_before(local_jiffies, data->limits_last_updated +
275 LIMIT_REFRESH_INTERVAL)
276 && data->limits_valid)
277 goto out;
278
279 for (i = 0; i < ADT7473_VOLT_COUNT; i++) {
280 data->volt_min[i] = i2c_smbus_read_byte_data(client,
281 ADT7473_REG_VOLT_MIN(i));
282 data->volt_max[i] = i2c_smbus_read_byte_data(client,
283 ADT7473_REG_VOLT_MAX(i));
284 }
285
286 for (i = 0; i < ADT7473_TEMP_COUNT; i++) {
287 data->temp_min[i] = i2c_smbus_read_byte_data(client,
288 ADT7473_REG_TEMP_MIN(i));
289 data->temp_max[i] = i2c_smbus_read_byte_data(client,
290 ADT7473_REG_TEMP_MAX(i));
291 data->temp_tmin[i] = i2c_smbus_read_byte_data(client,
292 ADT7473_REG_TEMP_TMIN(i));
293 data->temp_tmax[i] = i2c_smbus_read_byte_data(client,
294 ADT7473_REG_TEMP_TMAX(i));
295 }
296
297 for (i = 0; i < ADT7473_FAN_COUNT; i++)
298 data->fan_min[i] = adt7473_read_word_data(client,
299 ADT7473_REG_FAN_MIN(i));
300
301 for (i = 0; i < ADT7473_PWM_COUNT; i++) {
302 data->pwm_max[i] = i2c_smbus_read_byte_data(client,
303 ADT7473_REG_PWM_MAX(i));
304 data->pwm_min[i] = i2c_smbus_read_byte_data(client,
305 ADT7473_REG_PWM_MIN(i));
306 data->pwm_behavior[i] = i2c_smbus_read_byte_data(client,
307 ADT7473_REG_PWM_BHVR(i));
308 }
309
310 i = i2c_smbus_read_byte_data(client, ADT7473_REG_CFG4);
311 data->max_duty_at_overheat = !!(i & ADT7473_CFG4_MAX_DUTY_AT_OVT);
312
313 data->limits_last_updated = local_jiffies;
314 data->limits_valid = 1;
315
316out:
317 mutex_unlock(&data->lock);
318 return data;
319}
320
321/*
322 * Conversions
323 */
324
325/* IN are scaled acording to built-in resistors */
326static const int adt7473_scaling[] = { /* .001 Volts */
327 2250, 3300
328};
329#define SCALE(val, from, to) (((val) * (to) + ((from) / 2)) / (from))
330
331static int decode_volt(int volt_index, u8 raw)
332{
333 return SCALE(raw, 192, adt7473_scaling[volt_index]);
334}
335
336static u8 encode_volt(int volt_index, int cooked)
337{
338 int raw = SCALE(cooked, adt7473_scaling[volt_index], 192);
339 return SENSORS_LIMIT(raw, 0, 255);
340}
341
342static ssize_t show_volt_min(struct device *dev,
343 struct device_attribute *devattr,
344 char *buf)
345{
346 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
347 struct adt7473_data *data = adt7473_update_device(dev);
348 return sprintf(buf, "%d\n",
349 decode_volt(attr->index, data->volt_min[attr->index]));
350}
351
352static ssize_t set_volt_min(struct device *dev,
353 struct device_attribute *devattr,
354 const char *buf,
355 size_t count)
356{
357 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
358 struct i2c_client *client = to_i2c_client(dev);
359 struct adt7473_data *data = i2c_get_clientdata(client);
360 long volt;
361
362 if (strict_strtol(buf, 10, &volt))
363 return -EINVAL;
364
365 volt = encode_volt(attr->index, volt);
366
367 mutex_lock(&data->lock);
368 data->volt_min[attr->index] = volt;
369 i2c_smbus_write_byte_data(client, ADT7473_REG_VOLT_MIN(attr->index),
370 volt);
371 mutex_unlock(&data->lock);
372
373 return count;
374}
375
376static ssize_t show_volt_max(struct device *dev,
377 struct device_attribute *devattr,
378 char *buf)
379{
380 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
381 struct adt7473_data *data = adt7473_update_device(dev);
382 return sprintf(buf, "%d\n",
383 decode_volt(attr->index, data->volt_max[attr->index]));
384}
385
386static ssize_t set_volt_max(struct device *dev,
387 struct device_attribute *devattr,
388 const char *buf,
389 size_t count)
390{
391 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
392 struct i2c_client *client = to_i2c_client(dev);
393 struct adt7473_data *data = i2c_get_clientdata(client);
394 long volt;
395
396 if (strict_strtol(buf, 10, &volt))
397 return -EINVAL;
398
399 volt = encode_volt(attr->index, volt);
400
401 mutex_lock(&data->lock);
402 data->volt_max[attr->index] = volt;
403 i2c_smbus_write_byte_data(client, ADT7473_REG_VOLT_MAX(attr->index),
404 volt);
405 mutex_unlock(&data->lock);
406
407 return count;
408}
409
410static ssize_t show_volt(struct device *dev, struct device_attribute *devattr,
411 char *buf)
412{
413 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
414 struct adt7473_data *data = adt7473_update_device(dev);
415
416 return sprintf(buf, "%d\n",
417 decode_volt(attr->index, data->volt[attr->index]));
418}
419
420/*
421 * This chip can report temperature data either as a two's complement
422 * number in the range -128 to 127, or as an unsigned number that must
423 * be offset by 64.
424 */
425static int decode_temp(u8 twos_complement, u8 raw)
426{
427 return twos_complement ? (s8)raw : raw - 64;
428}
429
430static u8 encode_temp(u8 twos_complement, int cooked)
431{
432 u8 ret = twos_complement ? cooked & 0xFF : cooked + 64;
433 return SENSORS_LIMIT(ret, 0, 255);
434}
435
436static ssize_t show_temp_min(struct device *dev,
437 struct device_attribute *devattr,
438 char *buf)
439{
440 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
441 struct adt7473_data *data = adt7473_update_device(dev);
442 return sprintf(buf, "%d\n", 1000 * decode_temp(
443 data->temp_twos_complement,
444 data->temp_min[attr->index]));
445}
446
447static ssize_t set_temp_min(struct device *dev,
448 struct device_attribute *devattr,
449 const char *buf,
450 size_t count)
451{
452 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
453 struct i2c_client *client = to_i2c_client(dev);
454 struct adt7473_data *data = i2c_get_clientdata(client);
455 long temp;
456
457 if (strict_strtol(buf, 10, &temp))
458 return -EINVAL;
459
460 temp = DIV_ROUND_CLOSEST(temp, 1000);
461 temp = encode_temp(data->temp_twos_complement, temp);
462
463 mutex_lock(&data->lock);
464 data->temp_min[attr->index] = temp;
465 i2c_smbus_write_byte_data(client, ADT7473_REG_TEMP_MIN(attr->index),
466 temp);
467 mutex_unlock(&data->lock);
468
469 return count;
470}
471
472static ssize_t show_temp_max(struct device *dev,
473 struct device_attribute *devattr,
474 char *buf)
475{
476 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
477 struct adt7473_data *data = adt7473_update_device(dev);
478 return sprintf(buf, "%d\n", 1000 * decode_temp(
479 data->temp_twos_complement,
480 data->temp_max[attr->index]));
481}
482
483static ssize_t set_temp_max(struct device *dev,
484 struct device_attribute *devattr,
485 const char *buf,
486 size_t count)
487{
488 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
489 struct i2c_client *client = to_i2c_client(dev);
490 struct adt7473_data *data = i2c_get_clientdata(client);
491 long temp;
492
493 if (strict_strtol(buf, 10, &temp))
494 return -EINVAL;
495
496 temp = DIV_ROUND_CLOSEST(temp, 1000);
497 temp = encode_temp(data->temp_twos_complement, temp);
498
499 mutex_lock(&data->lock);
500 data->temp_max[attr->index] = temp;
501 i2c_smbus_write_byte_data(client, ADT7473_REG_TEMP_MAX(attr->index),
502 temp);
503 mutex_unlock(&data->lock);
504
505 return count;
506}
507
508static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
509 char *buf)
510{
511 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
512 struct adt7473_data *data = adt7473_update_device(dev);
513 return sprintf(buf, "%d\n", 1000 * decode_temp(
514 data->temp_twos_complement,
515 data->temp[attr->index]));
516}
517
518static ssize_t show_fan_min(struct device *dev,
519 struct device_attribute *devattr,
520 char *buf)
521{
522 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
523 struct adt7473_data *data = adt7473_update_device(dev);
524
525 if (FAN_DATA_VALID(data->fan_min[attr->index]))
526 return sprintf(buf, "%d\n",
527 FAN_PERIOD_TO_RPM(data->fan_min[attr->index]));
528 else
529 return sprintf(buf, "0\n");
530}
531
532static ssize_t set_fan_min(struct device *dev,
533 struct device_attribute *devattr,
534 const char *buf, size_t count)
535{
536 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
537 struct i2c_client *client = to_i2c_client(dev);
538 struct adt7473_data *data = i2c_get_clientdata(client);
539 long temp;
540
541 if (strict_strtol(buf, 10, &temp) || !temp)
542 return -EINVAL;
543
544 temp = FAN_RPM_TO_PERIOD(temp);
545 temp = SENSORS_LIMIT(temp, 1, 65534);
546
547 mutex_lock(&data->lock);
548 data->fan_min[attr->index] = temp;
549 adt7473_write_word_data(client, ADT7473_REG_FAN_MIN(attr->index), temp);
550 mutex_unlock(&data->lock);
551
552 return count;
553}
554
555static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
556 char *buf)
557{
558 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
559 struct adt7473_data *data = adt7473_update_device(dev);
560
561 if (FAN_DATA_VALID(data->fan[attr->index]))
562 return sprintf(buf, "%d\n",
563 FAN_PERIOD_TO_RPM(data->fan[attr->index]));
564 else
565 return sprintf(buf, "0\n");
566}
567
568static ssize_t show_max_duty_at_crit(struct device *dev,
569 struct device_attribute *devattr,
570 char *buf)
571{
572 struct adt7473_data *data = adt7473_update_device(dev);
573 return sprintf(buf, "%d\n", data->max_duty_at_overheat);
574}
575
576static ssize_t set_max_duty_at_crit(struct device *dev,
577 struct device_attribute *devattr,
578 const char *buf,
579 size_t count)
580{
581 u8 reg;
582 struct i2c_client *client = to_i2c_client(dev);
583 struct adt7473_data *data = i2c_get_clientdata(client);
584 long temp;
585
586 if (strict_strtol(buf, 10, &temp))
587 return -EINVAL;
588
589 mutex_lock(&data->lock);
590 data->max_duty_at_overheat = !!temp;
591 reg = i2c_smbus_read_byte_data(client, ADT7473_REG_CFG4);
592 if (temp)
593 reg |= ADT7473_CFG4_MAX_DUTY_AT_OVT;
594 else
595 reg &= ~ADT7473_CFG4_MAX_DUTY_AT_OVT;
596 i2c_smbus_write_byte_data(client, ADT7473_REG_CFG4, reg);
597 mutex_unlock(&data->lock);
598
599 return count;
600}
601
602static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
603 char *buf)
604{
605 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
606 struct adt7473_data *data = adt7473_update_device(dev);
607 return sprintf(buf, "%d\n", data->pwm[attr->index]);
608}
609
610static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr,
611 const char *buf, size_t count)
612{
613 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
614 struct i2c_client *client = to_i2c_client(dev);
615 struct adt7473_data *data = i2c_get_clientdata(client);
616 long temp;
617
618 if (strict_strtol(buf, 10, &temp))
619 return -EINVAL;
620
621 temp = SENSORS_LIMIT(temp, 0, 255);
622
623 mutex_lock(&data->lock);
624 data->pwm[attr->index] = temp;
625 i2c_smbus_write_byte_data(client, ADT7473_REG_PWM(attr->index), temp);
626 mutex_unlock(&data->lock);
627
628 return count;
629}
630
631static ssize_t show_pwm_max(struct device *dev,
632 struct device_attribute *devattr,
633 char *buf)
634{
635 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
636 struct adt7473_data *data = adt7473_update_device(dev);
637 return sprintf(buf, "%d\n", data->pwm_max[attr->index]);
638}
639
640static ssize_t set_pwm_max(struct device *dev,
641 struct device_attribute *devattr,
642 const char *buf,
643 size_t count)
644{
645 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
646 struct i2c_client *client = to_i2c_client(dev);
647 struct adt7473_data *data = i2c_get_clientdata(client);
648 long temp;
649
650 if (strict_strtol(buf, 10, &temp))
651 return -EINVAL;
652
653 temp = SENSORS_LIMIT(temp, 0, 255);
654
655 mutex_lock(&data->lock);
656 data->pwm_max[attr->index] = temp;
657 i2c_smbus_write_byte_data(client, ADT7473_REG_PWM_MAX(attr->index),
658 temp);
659 mutex_unlock(&data->lock);
660
661 return count;
662}
663
664static ssize_t show_pwm_min(struct device *dev,
665 struct device_attribute *devattr,
666 char *buf)
667{
668 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
669 struct adt7473_data *data = adt7473_update_device(dev);
670 return sprintf(buf, "%d\n", data->pwm_min[attr->index]);
671}
672
673static ssize_t set_pwm_min(struct device *dev,
674 struct device_attribute *devattr,
675 const char *buf,
676 size_t count)
677{
678 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
679 struct i2c_client *client = to_i2c_client(dev);
680 struct adt7473_data *data = i2c_get_clientdata(client);
681 long temp;
682
683 if (strict_strtol(buf, 10, &temp))
684 return -EINVAL;
685
686 temp = SENSORS_LIMIT(temp, 0, 255);
687
688 mutex_lock(&data->lock);
689 data->pwm_min[attr->index] = temp;
690 i2c_smbus_write_byte_data(client, ADT7473_REG_PWM_MIN(attr->index),
691 temp);
692 mutex_unlock(&data->lock);
693
694 return count;
695}
696
697static ssize_t show_temp_tmax(struct device *dev,
698 struct device_attribute *devattr,
699 char *buf)
700{
701 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
702 struct adt7473_data *data = adt7473_update_device(dev);
703 return sprintf(buf, "%d\n", 1000 * decode_temp(
704 data->temp_twos_complement,
705 data->temp_tmax[attr->index]));
706}
707
708static ssize_t set_temp_tmax(struct device *dev,
709 struct device_attribute *devattr,
710 const char *buf,
711 size_t count)
712{
713 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
714 struct i2c_client *client = to_i2c_client(dev);
715 struct adt7473_data *data = i2c_get_clientdata(client);
716 long temp;
717
718 if (strict_strtol(buf, 10, &temp))
719 return -EINVAL;
720
721 temp = DIV_ROUND_CLOSEST(temp, 1000);
722 temp = encode_temp(data->temp_twos_complement, temp);
723
724 mutex_lock(&data->lock);
725 data->temp_tmax[attr->index] = temp;
726 i2c_smbus_write_byte_data(client, ADT7473_REG_TEMP_TMAX(attr->index),
727 temp);
728 mutex_unlock(&data->lock);
729
730 return count;
731}
732
733static ssize_t show_temp_tmin(struct device *dev,
734 struct device_attribute *devattr,
735 char *buf)
736{
737 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
738 struct adt7473_data *data = adt7473_update_device(dev);
739 return sprintf(buf, "%d\n", 1000 * decode_temp(
740 data->temp_twos_complement,
741 data->temp_tmin[attr->index]));
742}
743
744static ssize_t set_temp_tmin(struct device *dev,
745 struct device_attribute *devattr,
746 const char *buf,
747 size_t count)
748{
749 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
750 struct i2c_client *client = to_i2c_client(dev);
751 struct adt7473_data *data = i2c_get_clientdata(client);
752 long temp;
753
754 if (strict_strtol(buf, 10, &temp))
755 return -EINVAL;
756
757 temp = DIV_ROUND_CLOSEST(temp, 1000);
758 temp = encode_temp(data->temp_twos_complement, temp);
759
760 mutex_lock(&data->lock);
761 data->temp_tmin[attr->index] = temp;
762 i2c_smbus_write_byte_data(client, ADT7473_REG_TEMP_TMIN(attr->index),
763 temp);
764 mutex_unlock(&data->lock);
765
766 return count;
767}
768
769static ssize_t show_pwm_enable(struct device *dev,
770 struct device_attribute *devattr,
771 char *buf)
772{
773 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
774 struct adt7473_data *data = adt7473_update_device(dev);
775
776 switch (data->pwm_behavior[attr->index] >> ADT7473_PWM_BHVR_SHIFT) {
777 case 3:
778 return sprintf(buf, "0\n");
779 case 7:
780 return sprintf(buf, "1\n");
781 default:
782 return sprintf(buf, "2\n");
783 }
784}
785
786static ssize_t set_pwm_enable(struct device *dev,
787 struct device_attribute *devattr,
788 const char *buf,
789 size_t count)
790{
791 u8 reg;
792 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
793 struct i2c_client *client = to_i2c_client(dev);
794 struct adt7473_data *data = i2c_get_clientdata(client);
795 long temp;
796
797 if (strict_strtol(buf, 10, &temp))
798 return -EINVAL;
799
800 switch (temp) {
801 case 0:
802 temp = 3;
803 break;
804 case 1:
805 temp = 7;
806 break;
807 case 2:
808 /* Enter automatic mode with fans off */
809 temp = 4;
810 break;
811 default:
812 return -EINVAL;
813 }
814
815 mutex_lock(&data->lock);
816 reg = i2c_smbus_read_byte_data(client,
817 ADT7473_REG_PWM_BHVR(attr->index));
818 reg = (temp << ADT7473_PWM_BHVR_SHIFT) |
819 (reg & ~ADT7473_PWM_BHVR_MASK);
820 i2c_smbus_write_byte_data(client, ADT7473_REG_PWM_BHVR(attr->index),
821 reg);
822 data->pwm_behavior[attr->index] = reg;
823 mutex_unlock(&data->lock);
824
825 return count;
826}
827
828static ssize_t show_pwm_auto_temp(struct device *dev,
829 struct device_attribute *devattr,
830 char *buf)
831{
832 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
833 struct adt7473_data *data = adt7473_update_device(dev);
834 int bhvr = data->pwm_behavior[attr->index] >> ADT7473_PWM_BHVR_SHIFT;
835
836 switch (bhvr) {
837 case 3:
838 case 4:
839 case 7:
840 return sprintf(buf, "0\n");
841 case 0:
842 case 1:
843 case 5:
844 case 6:
845 return sprintf(buf, "%d\n", bhvr + 1);
846 case 2:
847 return sprintf(buf, "4\n");
848 }
849 /* shouldn't ever get here */
850 BUG();
851}
852
853static ssize_t set_pwm_auto_temp(struct device *dev,
854 struct device_attribute *devattr,
855 const char *buf,
856 size_t count)
857{
858 u8 reg;
859 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
860 struct i2c_client *client = to_i2c_client(dev);
861 struct adt7473_data *data = i2c_get_clientdata(client);
862 long temp;
863
864 if (strict_strtol(buf, 10, &temp))
865 return -EINVAL;
866
867 switch (temp) {
868 case 1:
869 case 2:
870 case 6:
871 case 7:
872 temp--;
873 break;
874 case 0:
875 temp = 4;
876 break;
877 default:
878 return -EINVAL;
879 }
880
881 mutex_lock(&data->lock);
882 reg = i2c_smbus_read_byte_data(client,
883 ADT7473_REG_PWM_BHVR(attr->index));
884 reg = (temp << ADT7473_PWM_BHVR_SHIFT) |
885 (reg & ~ADT7473_PWM_BHVR_MASK);
886 i2c_smbus_write_byte_data(client, ADT7473_REG_PWM_BHVR(attr->index),
887 reg);
888 data->pwm_behavior[attr->index] = reg;
889 mutex_unlock(&data->lock);
890
891 return count;
892}
893
894static ssize_t show_alarm(struct device *dev,
895 struct device_attribute *devattr,
896 char *buf)
897{
898 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
899 struct adt7473_data *data = adt7473_update_device(dev);
900
901 if (data->alarm & attr->index)
902 return sprintf(buf, "1\n");
903 else
904 return sprintf(buf, "0\n");
905}
906
907
908static SENSOR_DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO, show_volt_max,
909 set_volt_max, 0);
910static SENSOR_DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO, show_volt_max,
911 set_volt_max, 1);
912
913static SENSOR_DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO, show_volt_min,
914 set_volt_min, 0);
915static SENSOR_DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO, show_volt_min,
916 set_volt_min, 1);
917
918static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_volt, NULL, 0);
919static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_volt, NULL, 1);
920
921static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL,
922 ADT7473_VCCP_ALARM);
923static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL,
924 ADT7473_VCC_ALARM);
925
926static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max,
927 set_temp_max, 0);
928static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_max,
929 set_temp_max, 1);
930static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_temp_max,
931 set_temp_max, 2);
932
933static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp_min,
934 set_temp_min, 0);
935static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp_min,
936 set_temp_min, 1);
937static SENSOR_DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, show_temp_min,
938 set_temp_min, 2);
939
940static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
941static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
942static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
943
944static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL,
945 ADT7473_R1T_ALARM | ALARM2(ADT7473_R1T_SHORT));
946static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL,
947 ADT7473_LT_ALARM);
948static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL,
949 ADT7473_R2T_ALARM | ALARM2(ADT7473_R2T_SHORT));
950
951static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min,
952 set_fan_min, 0);
953static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min,
954 set_fan_min, 1);
955static SENSOR_DEVICE_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min,
956 set_fan_min, 2);
957static SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO, show_fan_min,
958 set_fan_min, 3);
959
960static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
961static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1);
962static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2);
963static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3);
964
965static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL,
966 ALARM2(ADT7473_FAN1_ALARM));
967static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL,
968 ALARM2(ADT7473_FAN2_ALARM));
969static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL,
970 ALARM2(ADT7473_FAN3_ALARM));
971static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL,
972 ALARM2(ADT7473_FAN4_ALARM));
973
974static SENSOR_DEVICE_ATTR(pwm_use_point2_pwm_at_crit, S_IWUSR | S_IRUGO,
975 show_max_duty_at_crit, set_max_duty_at_crit, 0);
976
977static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 0);
978static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 1);
979static SENSOR_DEVICE_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2);
980
981static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IWUSR | S_IRUGO,
982 show_pwm_min, set_pwm_min, 0);
983static SENSOR_DEVICE_ATTR(pwm2_auto_point1_pwm, S_IWUSR | S_IRUGO,
984 show_pwm_min, set_pwm_min, 1);
985static SENSOR_DEVICE_ATTR(pwm3_auto_point1_pwm, S_IWUSR | S_IRUGO,
986 show_pwm_min, set_pwm_min, 2);
987
988static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IWUSR | S_IRUGO,
989 show_pwm_max, set_pwm_max, 0);
990static SENSOR_DEVICE_ATTR(pwm2_auto_point2_pwm, S_IWUSR | S_IRUGO,
991 show_pwm_max, set_pwm_max, 1);
992static SENSOR_DEVICE_ATTR(pwm3_auto_point2_pwm, S_IWUSR | S_IRUGO,
993 show_pwm_max, set_pwm_max, 2);
994
995static SENSOR_DEVICE_ATTR(temp1_auto_point1_temp, S_IWUSR | S_IRUGO,
996 show_temp_tmin, set_temp_tmin, 0);
997static SENSOR_DEVICE_ATTR(temp2_auto_point1_temp, S_IWUSR | S_IRUGO,
998 show_temp_tmin, set_temp_tmin, 1);
999static SENSOR_DEVICE_ATTR(temp3_auto_point1_temp, S_IWUSR | S_IRUGO,
1000 show_temp_tmin, set_temp_tmin, 2);
1001
1002static SENSOR_DEVICE_ATTR(temp1_auto_point2_temp, S_IWUSR | S_IRUGO,
1003 show_temp_tmax, set_temp_tmax, 0);
1004static SENSOR_DEVICE_ATTR(temp2_auto_point2_temp, S_IWUSR | S_IRUGO,
1005 show_temp_tmax, set_temp_tmax, 1);
1006static SENSOR_DEVICE_ATTR(temp3_auto_point2_temp, S_IWUSR | S_IRUGO,
1007 show_temp_tmax, set_temp_tmax, 2);
1008
1009static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
1010 set_pwm_enable, 0);
1011static SENSOR_DEVICE_ATTR(pwm2_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
1012 set_pwm_enable, 1);
1013static SENSOR_DEVICE_ATTR(pwm3_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
1014 set_pwm_enable, 2);
1015
1016static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IWUSR | S_IRUGO,
1017 show_pwm_auto_temp, set_pwm_auto_temp, 0);
1018static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IWUSR | S_IRUGO,
1019 show_pwm_auto_temp, set_pwm_auto_temp, 1);
1020static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IWUSR | S_IRUGO,
1021 show_pwm_auto_temp, set_pwm_auto_temp, 2);
1022
1023static struct attribute *adt7473_attr[] =
1024{
1025 &sensor_dev_attr_in1_max.dev_attr.attr,
1026 &sensor_dev_attr_in2_max.dev_attr.attr,
1027 &sensor_dev_attr_in1_min.dev_attr.attr,
1028 &sensor_dev_attr_in2_min.dev_attr.attr,
1029 &sensor_dev_attr_in1_input.dev_attr.attr,
1030 &sensor_dev_attr_in2_input.dev_attr.attr,
1031 &sensor_dev_attr_in1_alarm.dev_attr.attr,
1032 &sensor_dev_attr_in2_alarm.dev_attr.attr,
1033
1034 &sensor_dev_attr_temp1_max.dev_attr.attr,
1035 &sensor_dev_attr_temp2_max.dev_attr.attr,
1036 &sensor_dev_attr_temp3_max.dev_attr.attr,
1037 &sensor_dev_attr_temp1_min.dev_attr.attr,
1038 &sensor_dev_attr_temp2_min.dev_attr.attr,
1039 &sensor_dev_attr_temp3_min.dev_attr.attr,
1040 &sensor_dev_attr_temp1_input.dev_attr.attr,
1041 &sensor_dev_attr_temp2_input.dev_attr.attr,
1042 &sensor_dev_attr_temp3_input.dev_attr.attr,
1043 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
1044 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
1045 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
1046 &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr,
1047 &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr,
1048 &sensor_dev_attr_temp3_auto_point1_temp.dev_attr.attr,
1049 &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr,
1050 &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr,
1051 &sensor_dev_attr_temp3_auto_point2_temp.dev_attr.attr,
1052
1053 &sensor_dev_attr_fan1_min.dev_attr.attr,
1054 &sensor_dev_attr_fan2_min.dev_attr.attr,
1055 &sensor_dev_attr_fan3_min.dev_attr.attr,
1056 &sensor_dev_attr_fan4_min.dev_attr.attr,
1057 &sensor_dev_attr_fan1_input.dev_attr.attr,
1058 &sensor_dev_attr_fan2_input.dev_attr.attr,
1059 &sensor_dev_attr_fan3_input.dev_attr.attr,
1060 &sensor_dev_attr_fan4_input.dev_attr.attr,
1061 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1062 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1063 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
1064 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
1065
1066 &sensor_dev_attr_pwm_use_point2_pwm_at_crit.dev_attr.attr,
1067
1068 &sensor_dev_attr_pwm1.dev_attr.attr,
1069 &sensor_dev_attr_pwm2.dev_attr.attr,
1070 &sensor_dev_attr_pwm3.dev_attr.attr,
1071 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
1072 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
1073 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
1074 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
1075 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
1076 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
1077
1078 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
1079 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1080 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
1081 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
1082 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
1083 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
1084
1085 NULL
1086};
1087
1088/* Return 0 if detection is successful, -ENODEV otherwise */
1089static int adt7473_detect(struct i2c_client *client, int kind,
1090 struct i2c_board_info *info)
1091{
1092 struct i2c_adapter *adapter = client->adapter;
1093
1094 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1095 return -ENODEV;
1096
1097 if (kind <= 0) {
1098 int vendor, device, revision;
1099
1100 vendor = i2c_smbus_read_byte_data(client, ADT7473_REG_VENDOR);
1101 if (vendor != ADT7473_VENDOR)
1102 return -ENODEV;
1103
1104 device = i2c_smbus_read_byte_data(client, ADT7473_REG_DEVICE);
1105 if (device != ADT7473_DEVICE)
1106 return -ENODEV;
1107
1108 revision = i2c_smbus_read_byte_data(client,
1109 ADT7473_REG_REVISION);
1110 if (revision != ADT7473_REV_68 && revision != ADT7473_REV_69)
1111 return -ENODEV;
1112 } else
1113 dev_dbg(&adapter->dev, "detection forced\n");
1114
1115 strlcpy(info->type, "adt7473", I2C_NAME_SIZE);
1116
1117 return 0;
1118}
1119
1120static int adt7473_probe(struct i2c_client *client,
1121 const struct i2c_device_id *id)
1122{
1123 struct adt7473_data *data;
1124 int err;
1125
1126 data = kzalloc(sizeof(struct adt7473_data), GFP_KERNEL);
1127 if (!data) {
1128 err = -ENOMEM;
1129 goto exit;
1130 }
1131
1132 i2c_set_clientdata(client, data);
1133 mutex_init(&data->lock);
1134
1135 dev_info(&client->dev, "%s chip found\n", client->name);
1136
1137 /* Initialize the ADT7473 chip */
1138 adt7473_init_client(client);
1139
1140 /* Register sysfs hooks */
1141 data->attrs.attrs = adt7473_attr;
1142 err = sysfs_create_group(&client->dev.kobj, &data->attrs);
1143 if (err)
1144 goto exit_free;
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;
1150 }
1151
1152 return 0;
1153
1154exit_remove:
1155 sysfs_remove_group(&client->dev.kobj, &data->attrs);
1156exit_free:
1157 kfree(data);
1158exit:
1159 return err;
1160}
1161
1162static int adt7473_remove(struct i2c_client *client)
1163{
1164 struct adt7473_data *data = i2c_get_clientdata(client);
1165
1166 hwmon_device_unregister(data->hwmon_dev);
1167 sysfs_remove_group(&client->dev.kobj, &data->attrs);
1168 kfree(data);
1169 return 0;
1170}
1171
1172static int __init adt7473_init(void)
1173{
1174 return i2c_add_driver(&adt7473_driver);
1175}
1176
1177static void __exit adt7473_exit(void)
1178{
1179 i2c_del_driver(&adt7473_driver);
1180}
1181
1182MODULE_AUTHOR("Darrick J. Wong <djwong@us.ibm.com>");
1183MODULE_DESCRIPTION("ADT7473 driver");
1184MODULE_LICENSE("GPL");
1185
1186module_init(adt7473_init);
1187module_exit(adt7473_exit);
diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
index b5a95193c694..a0c385145686 100644
--- a/drivers/hwmon/adt7475.c
+++ b/drivers/hwmon/adt7475.c
@@ -3,7 +3,8 @@
3 * Copyright (C) 2007-2008, Advanced Micro Devices, Inc. 3 * Copyright (C) 2007-2008, Advanced Micro Devices, Inc.
4 * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net> 4 * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net>
5 * Copyright (C) 2008 Hans de Goede <hdegoede@redhat.com> 5 * Copyright (C) 2008 Hans de Goede <hdegoede@redhat.com>
6 6 * Copyright (C) 2009 Jean Delvare <khali@linux-fr.org>
7 *
7 * Derived from the lm83 driver by Jean Delvare 8 * Derived from the lm83 driver by Jean Delvare
8 * 9 *
9 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
@@ -17,6 +18,7 @@
17#include <linux/i2c.h> 18#include <linux/i2c.h>
18#include <linux/hwmon.h> 19#include <linux/hwmon.h>
19#include <linux/hwmon-sysfs.h> 20#include <linux/hwmon-sysfs.h>
21#include <linux/hwmon-vid.h>
20#include <linux/err.h> 22#include <linux/err.h>
21 23
22/* Indexes for the sysfs hooks */ 24/* Indexes for the sysfs hooks */
@@ -39,7 +41,12 @@
39 41
40/* 7475 Common Registers */ 42/* 7475 Common Registers */
41 43
42#define REG_VOLTAGE_BASE 0x21 44#define REG_DEVREV2 0x12 /* ADT7490 only */
45
46#define REG_VTT 0x1E /* ADT7490 only */
47#define REG_EXTEND3 0x1F /* ADT7490 only */
48
49#define REG_VOLTAGE_BASE 0x20
43#define REG_TEMP_BASE 0x25 50#define REG_TEMP_BASE 0x25
44#define REG_TACH_BASE 0x28 51#define REG_TACH_BASE 0x28
45#define REG_PWM_BASE 0x30 52#define REG_PWM_BASE 0x30
@@ -47,12 +54,15 @@
47 54
48#define REG_DEVID 0x3D 55#define REG_DEVID 0x3D
49#define REG_VENDID 0x3E 56#define REG_VENDID 0x3E
57#define REG_DEVID2 0x3F
50 58
51#define REG_STATUS1 0x41 59#define REG_STATUS1 0x41
52#define REG_STATUS2 0x42 60#define REG_STATUS2 0x42
53 61
54#define REG_VOLTAGE_MIN_BASE 0x46 62#define REG_VID 0x43 /* ADT7476 only */
55#define REG_VOLTAGE_MAX_BASE 0x47 63
64#define REG_VOLTAGE_MIN_BASE 0x44
65#define REG_VOLTAGE_MAX_BASE 0x45
56 66
57#define REG_TEMP_MIN_BASE 0x4E 67#define REG_TEMP_MIN_BASE 0x4E
58#define REG_TEMP_MAX_BASE 0x4F 68#define REG_TEMP_MAX_BASE 0x4F
@@ -73,16 +83,39 @@
73 83
74#define REG_TEMP_OFFSET_BASE 0x70 84#define REG_TEMP_OFFSET_BASE 0x70
75 85
86#define REG_CONFIG2 0x73
87
76#define REG_EXTEND1 0x76 88#define REG_EXTEND1 0x76
77#define REG_EXTEND2 0x77 89#define REG_EXTEND2 0x77
90
91#define REG_CONFIG3 0x78
78#define REG_CONFIG5 0x7C 92#define REG_CONFIG5 0x7C
93#define REG_CONFIG4 0x7D
94
95#define REG_STATUS4 0x81 /* ADT7490 only */
96
97#define REG_VTT_MIN 0x84 /* ADT7490 only */
98#define REG_VTT_MAX 0x86 /* ADT7490 only */
99
100#define VID_VIDSEL 0x80 /* ADT7476 only */
101
102#define CONFIG2_ATTN 0x20
103
104#define CONFIG3_SMBALERT 0x01
105#define CONFIG3_THERM 0x02
106
107#define CONFIG4_PINFUNC 0x03
108#define CONFIG4_MAXDUTY 0x08
109#define CONFIG4_ATTN_IN10 0x30
110#define CONFIG4_ATTN_IN43 0xC0
79 111
80#define CONFIG5_TWOSCOMP 0x01 112#define CONFIG5_TWOSCOMP 0x01
81#define CONFIG5_TEMPOFFSET 0x02 113#define CONFIG5_TEMPOFFSET 0x02
114#define CONFIG5_VIDGPIO 0x10 /* ADT7476 only */
82 115
83/* ADT7475 Settings */ 116/* ADT7475 Settings */
84 117
85#define ADT7475_VOLTAGE_COUNT 2 118#define ADT7475_VOLTAGE_COUNT 5 /* Not counting Vtt */
86#define ADT7475_TEMP_COUNT 3 119#define ADT7475_TEMP_COUNT 3
87#define ADT7475_TACH_COUNT 4 120#define ADT7475_TACH_COUNT 4
88#define ADT7475_PWM_COUNT 3 121#define ADT7475_PWM_COUNT 3
@@ -113,12 +146,15 @@
113#define TEMP_OFFSET_REG(idx) (REG_TEMP_OFFSET_BASE + (idx)) 146#define TEMP_OFFSET_REG(idx) (REG_TEMP_OFFSET_BASE + (idx))
114#define TEMP_TRANGE_REG(idx) (REG_TEMP_TRANGE_BASE + (idx)) 147#define TEMP_TRANGE_REG(idx) (REG_TEMP_TRANGE_BASE + (idx))
115 148
116static unsigned short normal_i2c[] = { 0x2e, I2C_CLIENT_END }; 149static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
117 150
118I2C_CLIENT_INSMOD_1(adt7475); 151enum chips { adt7473, adt7475, adt7476, adt7490 };
119 152
120static const struct i2c_device_id adt7475_id[] = { 153static const struct i2c_device_id adt7475_id[] = {
154 { "adt7473", adt7473 },
121 { "adt7475", adt7475 }, 155 { "adt7475", adt7475 },
156 { "adt7476", adt7476 },
157 { "adt7490", adt7490 },
122 { } 158 { }
123}; 159};
124MODULE_DEVICE_TABLE(i2c, adt7475_id); 160MODULE_DEVICE_TABLE(i2c, adt7475_id);
@@ -131,15 +167,24 @@ struct adt7475_data {
131 unsigned long limits_updated; 167 unsigned long limits_updated;
132 char valid; 168 char valid;
133 169
170 u8 config4;
134 u8 config5; 171 u8 config5;
135 u16 alarms; 172 u8 has_voltage;
136 u16 voltage[3][3]; 173 u8 bypass_attn; /* Bypass voltage attenuator */
174 u8 has_pwm2:1;
175 u8 has_fan4:1;
176 u8 has_vid:1;
177 u32 alarms;
178 u16 voltage[3][6];
137 u16 temp[7][3]; 179 u16 temp[7][3];
138 u16 tach[2][4]; 180 u16 tach[2][4];
139 u8 pwm[4][3]; 181 u8 pwm[4][3];
140 u8 range[3]; 182 u8 range[3];
141 u8 pwmctl[3]; 183 u8 pwmctl[3];
142 u8 pwmchan[3]; 184 u8 pwmchan[3];
185
186 u8 vid;
187 u8 vrm;
143}; 188};
144 189
145static struct i2c_driver adt7475_driver; 190static struct i2c_driver adt7475_driver;
@@ -196,26 +241,35 @@ static inline u16 rpm2tach(unsigned long rpm)
196 return SENSORS_LIMIT((90000 * 60) / rpm, 1, 0xFFFF); 241 return SENSORS_LIMIT((90000 * 60) / rpm, 1, 0xFFFF);
197} 242}
198 243
199static inline int reg2vcc(u16 reg) 244/* Scaling factors for voltage inputs, taken from the ADT7490 datasheet */
200{ 245static const int adt7473_in_scaling[ADT7475_VOLTAGE_COUNT + 1][2] = {
201 return (4296 * reg) / 1000; 246 { 45, 94 }, /* +2.5V */
202} 247 { 175, 525 }, /* Vccp */
248 { 68, 71 }, /* Vcc */
249 { 93, 47 }, /* +5V */
250 { 120, 20 }, /* +12V */
251 { 45, 45 }, /* Vtt */
252};
203 253
204static inline int reg2vccp(u16 reg) 254static inline int reg2volt(int channel, u16 reg, u8 bypass_attn)
205{ 255{
206 return (2929 * reg) / 1000; 256 const int *r = adt7473_in_scaling[channel];
207}
208 257
209static inline u16 vcc2reg(long vcc) 258 if (bypass_attn & (1 << channel))
210{ 259 return DIV_ROUND_CLOSEST(reg * 2250, 1024);
211 vcc = SENSORS_LIMIT(vcc, 0, 4396); 260 return DIV_ROUND_CLOSEST(reg * (r[0] + r[1]) * 2250, r[1] * 1024);
212 return (vcc * 1000) / 4296;
213} 261}
214 262
215static inline u16 vccp2reg(long vcc) 263static inline u16 volt2reg(int channel, long volt, u8 bypass_attn)
216{ 264{
217 vcc = SENSORS_LIMIT(vcc, 0, 2998); 265 const int *r = adt7473_in_scaling[channel];
218 return (vcc * 1000) / 2929; 266 long reg;
267
268 if (bypass_attn & (1 << channel))
269 reg = (volt * 1024) / 2250;
270 else
271 reg = (volt * r[1] * 1024) / ((r[0] + r[1]) * 2250);
272 return SENSORS_LIMIT(reg, 0, 1023) & (0xff << 2);
219} 273}
220 274
221static u16 adt7475_read_word(struct i2c_client *client, int reg) 275static u16 adt7475_read_word(struct i2c_client *client, int reg)
@@ -271,12 +325,11 @@ static ssize_t show_voltage(struct device *dev, struct device_attribute *attr,
271 switch (sattr->nr) { 325 switch (sattr->nr) {
272 case ALARM: 326 case ALARM:
273 return sprintf(buf, "%d\n", 327 return sprintf(buf, "%d\n",
274 (data->alarms >> (sattr->index + 1)) & 1); 328 (data->alarms >> sattr->index) & 1);
275 default: 329 default:
276 val = data->voltage[sattr->nr][sattr->index]; 330 val = data->voltage[sattr->nr][sattr->index];
277 return sprintf(buf, "%d\n", 331 return sprintf(buf, "%d\n",
278 sattr->index == 332 reg2volt(sattr->index, val, data->bypass_attn));
279 0 ? reg2vccp(val) : reg2vcc(val));
280 } 333 }
281} 334}
282 335
@@ -296,12 +349,19 @@ static ssize_t set_voltage(struct device *dev, struct device_attribute *attr,
296 mutex_lock(&data->lock); 349 mutex_lock(&data->lock);
297 350
298 data->voltage[sattr->nr][sattr->index] = 351 data->voltage[sattr->nr][sattr->index] =
299 sattr->index ? vcc2reg(val) : vccp2reg(val); 352 volt2reg(sattr->index, val, data->bypass_attn);
300 353
301 if (sattr->nr == MIN) 354 if (sattr->index < ADT7475_VOLTAGE_COUNT) {
302 reg = VOLTAGE_MIN_REG(sattr->index); 355 if (sattr->nr == MIN)
303 else 356 reg = VOLTAGE_MIN_REG(sattr->index);
304 reg = VOLTAGE_MAX_REG(sattr->index); 357 else
358 reg = VOLTAGE_MAX_REG(sattr->index);
359 } else {
360 if (sattr->nr == MIN)
361 reg = REG_VTT_MIN;
362 else
363 reg = REG_VTT_MAX;
364 }
305 365
306 i2c_smbus_write_byte_data(client, reg, 366 i2c_smbus_write_byte_data(client, reg,
307 data->voltage[sattr->nr][sattr->index] >> 2); 367 data->voltage[sattr->nr][sattr->index] >> 2);
@@ -778,18 +838,103 @@ static ssize_t set_pwmfreq(struct device *dev, struct device_attribute *attr,
778 return count; 838 return count;
779} 839}
780 840
781static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_voltage, NULL, INPUT, 0); 841static ssize_t show_pwm_at_crit(struct device *dev,
782static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_voltage, 842 struct device_attribute *devattr, char *buf)
843{
844 struct adt7475_data *data = adt7475_update_device(dev);
845 return sprintf(buf, "%d\n", !!(data->config4 & CONFIG4_MAXDUTY));
846}
847
848static ssize_t set_pwm_at_crit(struct device *dev,
849 struct device_attribute *devattr,
850 const char *buf, size_t count)
851{
852 struct i2c_client *client = to_i2c_client(dev);
853 struct adt7475_data *data = i2c_get_clientdata(client);
854 long val;
855
856 if (strict_strtol(buf, 10, &val))
857 return -EINVAL;
858 if (val != 0 && val != 1)
859 return -EINVAL;
860
861 mutex_lock(&data->lock);
862 data->config4 = i2c_smbus_read_byte_data(client, REG_CONFIG4);
863 if (val)
864 data->config4 |= CONFIG4_MAXDUTY;
865 else
866 data->config4 &= ~CONFIG4_MAXDUTY;
867 i2c_smbus_write_byte_data(client, REG_CONFIG4, data->config4);
868 mutex_unlock(&data->lock);
869
870 return count;
871}
872
873static ssize_t show_vrm(struct device *dev, struct device_attribute *devattr,
874 char *buf)
875{
876 struct adt7475_data *data = dev_get_drvdata(dev);
877 return sprintf(buf, "%d\n", (int)data->vrm);
878}
879
880static ssize_t set_vrm(struct device *dev, struct device_attribute *devattr,
881 const char *buf, size_t count)
882{
883 struct adt7475_data *data = dev_get_drvdata(dev);
884 long val;
885
886 if (strict_strtol(buf, 10, &val))
887 return -EINVAL;
888 if (val < 0 || val > 255)
889 return -EINVAL;
890 data->vrm = val;
891
892 return count;
893}
894
895static ssize_t show_vid(struct device *dev, struct device_attribute *devattr,
896 char *buf)
897{
898 struct adt7475_data *data = adt7475_update_device(dev);
899 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
900}
901
902static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_voltage, NULL, INPUT, 0);
903static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_voltage,
783 set_voltage, MAX, 0); 904 set_voltage, MAX, 0);
784static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_voltage, 905static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_voltage,
785 set_voltage, MIN, 0); 906 set_voltage, MIN, 0);
786static SENSOR_DEVICE_ATTR_2(in1_alarm, S_IRUGO, show_voltage, NULL, ALARM, 0); 907static SENSOR_DEVICE_ATTR_2(in0_alarm, S_IRUGO, show_voltage, NULL, ALARM, 0);
787static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_voltage, NULL, INPUT, 1); 908static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_voltage, NULL, INPUT, 1);
788static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_voltage, 909static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_voltage,
789 set_voltage, MAX, 1); 910 set_voltage, MAX, 1);
790static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_voltage, 911static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_voltage,
791 set_voltage, MIN, 1); 912 set_voltage, MIN, 1);
792static SENSOR_DEVICE_ATTR_2(in2_alarm, S_IRUGO, show_voltage, NULL, ALARM, 1); 913static SENSOR_DEVICE_ATTR_2(in1_alarm, S_IRUGO, show_voltage, NULL, ALARM, 1);
914static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_voltage, NULL, INPUT, 2);
915static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_voltage,
916 set_voltage, MAX, 2);
917static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_voltage,
918 set_voltage, MIN, 2);
919static SENSOR_DEVICE_ATTR_2(in2_alarm, S_IRUGO, show_voltage, NULL, ALARM, 2);
920static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_voltage, NULL, INPUT, 3);
921static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_voltage,
922 set_voltage, MAX, 3);
923static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_voltage,
924 set_voltage, MIN, 3);
925static SENSOR_DEVICE_ATTR_2(in3_alarm, S_IRUGO, show_voltage, NULL, ALARM, 3);
926static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_voltage, NULL, INPUT, 4);
927static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_voltage,
928 set_voltage, MAX, 4);
929static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_voltage,
930 set_voltage, MIN, 4);
931static SENSOR_DEVICE_ATTR_2(in4_alarm, S_IRUGO, show_voltage, NULL, ALARM, 8);
932static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_voltage, NULL, INPUT, 5);
933static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_voltage,
934 set_voltage, MAX, 5);
935static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_voltage,
936 set_voltage, MIN, 5);
937static SENSOR_DEVICE_ATTR_2(in5_alarm, S_IRUGO, show_voltage, NULL, ALARM, 31);
793static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, INPUT, 0); 938static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, INPUT, 0);
794static SENSOR_DEVICE_ATTR_2(temp1_alarm, S_IRUGO, show_temp, NULL, ALARM, 0); 939static SENSOR_DEVICE_ATTR_2(temp1_alarm, S_IRUGO, show_temp, NULL, ALARM, 0);
795static SENSOR_DEVICE_ATTR_2(temp1_fault, S_IRUGO, show_temp, NULL, FAULT, 0); 940static SENSOR_DEVICE_ATTR_2(temp1_fault, S_IRUGO, show_temp, NULL, FAULT, 0);
@@ -893,6 +1038,13 @@ static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO | S_IWUSR, show_pwm,
893static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR, show_pwm, 1038static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR, show_pwm,
894 set_pwm, MAX, 2); 1039 set_pwm, MAX, 2);
895 1040
1041/* Non-standard name, might need revisiting */
1042static DEVICE_ATTR(pwm_use_point2_pwm_at_crit, S_IWUSR | S_IRUGO,
1043 show_pwm_at_crit, set_pwm_at_crit);
1044
1045static DEVICE_ATTR(vrm, S_IWUSR | S_IRUGO, show_vrm, set_vrm);
1046static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
1047
896static struct attribute *adt7475_attrs[] = { 1048static struct attribute *adt7475_attrs[] = {
897 &sensor_dev_attr_in1_input.dev_attr.attr, 1049 &sensor_dev_attr_in1_input.dev_attr.attr,
898 &sensor_dev_attr_in1_max.dev_attr.attr, 1050 &sensor_dev_attr_in1_max.dev_attr.attr,
@@ -940,60 +1092,156 @@ static struct attribute *adt7475_attrs[] = {
940 &sensor_dev_attr_fan3_input.dev_attr.attr, 1092 &sensor_dev_attr_fan3_input.dev_attr.attr,
941 &sensor_dev_attr_fan3_min.dev_attr.attr, 1093 &sensor_dev_attr_fan3_min.dev_attr.attr,
942 &sensor_dev_attr_fan3_alarm.dev_attr.attr, 1094 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
943 &sensor_dev_attr_fan4_input.dev_attr.attr,
944 &sensor_dev_attr_fan4_min.dev_attr.attr,
945 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
946 &sensor_dev_attr_pwm1.dev_attr.attr, 1095 &sensor_dev_attr_pwm1.dev_attr.attr,
947 &sensor_dev_attr_pwm1_freq.dev_attr.attr, 1096 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
948 &sensor_dev_attr_pwm1_enable.dev_attr.attr, 1097 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
949 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr, 1098 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
950 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, 1099 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
951 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr, 1100 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
952 &sensor_dev_attr_pwm2.dev_attr.attr,
953 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
954 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
955 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
956 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
957 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
958 &sensor_dev_attr_pwm3.dev_attr.attr, 1101 &sensor_dev_attr_pwm3.dev_attr.attr,
959 &sensor_dev_attr_pwm3_freq.dev_attr.attr, 1102 &sensor_dev_attr_pwm3_freq.dev_attr.attr,
960 &sensor_dev_attr_pwm3_enable.dev_attr.attr, 1103 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
961 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr, 1104 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
962 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr, 1105 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
963 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr, 1106 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
1107 &dev_attr_pwm_use_point2_pwm_at_crit.attr,
964 NULL, 1108 NULL,
965}; 1109};
966 1110
967struct attribute_group adt7475_attr_group = { .attrs = adt7475_attrs }; 1111static struct attribute *fan4_attrs[] = {
1112 &sensor_dev_attr_fan4_input.dev_attr.attr,
1113 &sensor_dev_attr_fan4_min.dev_attr.attr,
1114 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
1115 NULL
1116};
1117
1118static struct attribute *pwm2_attrs[] = {
1119 &sensor_dev_attr_pwm2.dev_attr.attr,
1120 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
1121 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1122 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
1123 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
1124 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
1125 NULL
1126};
1127
1128static struct attribute *in0_attrs[] = {
1129 &sensor_dev_attr_in0_input.dev_attr.attr,
1130 &sensor_dev_attr_in0_max.dev_attr.attr,
1131 &sensor_dev_attr_in0_min.dev_attr.attr,
1132 &sensor_dev_attr_in0_alarm.dev_attr.attr,
1133 NULL
1134};
1135
1136static struct attribute *in3_attrs[] = {
1137 &sensor_dev_attr_in3_input.dev_attr.attr,
1138 &sensor_dev_attr_in3_max.dev_attr.attr,
1139 &sensor_dev_attr_in3_min.dev_attr.attr,
1140 &sensor_dev_attr_in3_alarm.dev_attr.attr,
1141 NULL
1142};
1143
1144static struct attribute *in4_attrs[] = {
1145 &sensor_dev_attr_in4_input.dev_attr.attr,
1146 &sensor_dev_attr_in4_max.dev_attr.attr,
1147 &sensor_dev_attr_in4_min.dev_attr.attr,
1148 &sensor_dev_attr_in4_alarm.dev_attr.attr,
1149 NULL
1150};
968 1151
969static int adt7475_detect(struct i2c_client *client, int kind, 1152static struct attribute *in5_attrs[] = {
1153 &sensor_dev_attr_in5_input.dev_attr.attr,
1154 &sensor_dev_attr_in5_max.dev_attr.attr,
1155 &sensor_dev_attr_in5_min.dev_attr.attr,
1156 &sensor_dev_attr_in5_alarm.dev_attr.attr,
1157 NULL
1158};
1159
1160static struct attribute *vid_attrs[] = {
1161 &dev_attr_cpu0_vid.attr,
1162 &dev_attr_vrm.attr,
1163 NULL
1164};
1165
1166static struct attribute_group adt7475_attr_group = { .attrs = adt7475_attrs };
1167static struct attribute_group fan4_attr_group = { .attrs = fan4_attrs };
1168static struct attribute_group pwm2_attr_group = { .attrs = pwm2_attrs };
1169static struct attribute_group in0_attr_group = { .attrs = in0_attrs };
1170static struct attribute_group in3_attr_group = { .attrs = in3_attrs };
1171static struct attribute_group in4_attr_group = { .attrs = in4_attrs };
1172static struct attribute_group in5_attr_group = { .attrs = in5_attrs };
1173static struct attribute_group vid_attr_group = { .attrs = vid_attrs };
1174
1175static int adt7475_detect(struct i2c_client *client,
970 struct i2c_board_info *info) 1176 struct i2c_board_info *info)
971{ 1177{
972 struct i2c_adapter *adapter = client->adapter; 1178 struct i2c_adapter *adapter = client->adapter;
1179 int vendid, devid, devid2;
1180 const char *name;
973 1181
974 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1182 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
975 return -ENODEV; 1183 return -ENODEV;
976 1184
977 if (kind <= 0) { 1185 vendid = adt7475_read(REG_VENDID);
978 if (adt7475_read(REG_VENDID) != 0x41 || 1186 devid2 = adt7475_read(REG_DEVID2);
979 adt7475_read(REG_DEVID) != 0x75) { 1187 if (vendid != 0x41 || /* Analog Devices */
980 dev_err(&adapter->dev, 1188 (devid2 & 0xf8) != 0x68)
981 "Couldn't detect a adt7475 part at 0x%02x\n", 1189 return -ENODEV;
982 (unsigned int)client->addr); 1190
983 return -ENODEV; 1191 devid = adt7475_read(REG_DEVID);
984 } 1192 if (devid == 0x73)
1193 name = "adt7473";
1194 else if (devid == 0x75 && client->addr == 0x2e)
1195 name = "adt7475";
1196 else if (devid == 0x76)
1197 name = "adt7476";
1198 else if ((devid2 & 0xfc) == 0x6c)
1199 name = "adt7490";
1200 else {
1201 dev_dbg(&adapter->dev,
1202 "Couldn't detect an ADT7473/75/76/90 part at "
1203 "0x%02x\n", (unsigned int)client->addr);
1204 return -ENODEV;
985 } 1205 }
986 1206
987 strlcpy(info->type, adt7475_id[0].name, I2C_NAME_SIZE); 1207 strlcpy(info->type, name, I2C_NAME_SIZE);
988 1208
989 return 0; 1209 return 0;
990} 1210}
991 1211
1212static void adt7475_remove_files(struct i2c_client *client,
1213 struct adt7475_data *data)
1214{
1215 sysfs_remove_group(&client->dev.kobj, &adt7475_attr_group);
1216 if (data->has_fan4)
1217 sysfs_remove_group(&client->dev.kobj, &fan4_attr_group);
1218 if (data->has_pwm2)
1219 sysfs_remove_group(&client->dev.kobj, &pwm2_attr_group);
1220 if (data->has_voltage & (1 << 0))
1221 sysfs_remove_group(&client->dev.kobj, &in0_attr_group);
1222 if (data->has_voltage & (1 << 3))
1223 sysfs_remove_group(&client->dev.kobj, &in3_attr_group);
1224 if (data->has_voltage & (1 << 4))
1225 sysfs_remove_group(&client->dev.kobj, &in4_attr_group);
1226 if (data->has_voltage & (1 << 5))
1227 sysfs_remove_group(&client->dev.kobj, &in5_attr_group);
1228 if (data->has_vid)
1229 sysfs_remove_group(&client->dev.kobj, &vid_attr_group);
1230}
1231
992static int adt7475_probe(struct i2c_client *client, 1232static int adt7475_probe(struct i2c_client *client,
993 const struct i2c_device_id *id) 1233 const struct i2c_device_id *id)
994{ 1234{
1235 static const char *names[] = {
1236 [adt7473] = "ADT7473",
1237 [adt7475] = "ADT7475",
1238 [adt7476] = "ADT7476",
1239 [adt7490] = "ADT7490",
1240 };
1241
995 struct adt7475_data *data; 1242 struct adt7475_data *data;
996 int i, ret = 0; 1243 int i, ret = 0, revision;
1244 u8 config2, config3;
997 1245
998 data = kzalloc(sizeof(*data), GFP_KERNEL); 1246 data = kzalloc(sizeof(*data), GFP_KERNEL);
999 if (data == NULL) 1247 if (data == NULL)
@@ -1002,6 +1250,70 @@ static int adt7475_probe(struct i2c_client *client,
1002 mutex_init(&data->lock); 1250 mutex_init(&data->lock);
1003 i2c_set_clientdata(client, data); 1251 i2c_set_clientdata(client, data);
1004 1252
1253 /* Initialize device-specific values */
1254 switch (id->driver_data) {
1255 case adt7476:
1256 data->has_voltage = 0x0e; /* in1 to in3 */
1257 revision = adt7475_read(REG_DEVID2) & 0x07;
1258 break;
1259 case adt7490:
1260 data->has_voltage = 0x3e; /* in1 to in5 */
1261 revision = adt7475_read(REG_DEVID2) & 0x03;
1262 if (revision == 0x03)
1263 revision += adt7475_read(REG_DEVREV2);
1264 break;
1265 default:
1266 data->has_voltage = 0x06; /* in1, in2 */
1267 revision = adt7475_read(REG_DEVID2) & 0x07;
1268 }
1269
1270 config3 = adt7475_read(REG_CONFIG3);
1271 /* Pin PWM2 may alternatively be used for ALERT output */
1272 if (!(config3 & CONFIG3_SMBALERT))
1273 data->has_pwm2 = 1;
1274 /* Meaning of this bit is inverted for the ADT7473-1 */
1275 if (id->driver_data == adt7473 && revision >= 1)
1276 data->has_pwm2 = !data->has_pwm2;
1277
1278 data->config4 = adt7475_read(REG_CONFIG4);
1279 /* Pin TACH4 may alternatively be used for THERM */
1280 if ((data->config4 & CONFIG4_PINFUNC) == 0x0)
1281 data->has_fan4 = 1;
1282
1283 /* THERM configuration is more complex on the ADT7476 and ADT7490,
1284 because 2 different pins (TACH4 and +2.5 Vin) can be used for
1285 this function */
1286 if (id->driver_data == adt7490) {
1287 if ((data->config4 & CONFIG4_PINFUNC) == 0x1 &&
1288 !(config3 & CONFIG3_THERM))
1289 data->has_fan4 = 1;
1290 }
1291 if (id->driver_data == adt7476 || id->driver_data == adt7490) {
1292 if (!(config3 & CONFIG3_THERM) ||
1293 (data->config4 & CONFIG4_PINFUNC) == 0x1)
1294 data->has_voltage |= (1 << 0); /* in0 */
1295 }
1296
1297 /* On the ADT7476, the +12V input pin may instead be used as VID5,
1298 and VID pins may alternatively be used as GPIO */
1299 if (id->driver_data == adt7476) {
1300 u8 vid = adt7475_read(REG_VID);
1301 if (!(vid & VID_VIDSEL))
1302 data->has_voltage |= (1 << 4); /* in4 */
1303
1304 data->has_vid = !(adt7475_read(REG_CONFIG5) & CONFIG5_VIDGPIO);
1305 }
1306
1307 /* Voltage attenuators can be bypassed, globally or individually */
1308 config2 = adt7475_read(REG_CONFIG2);
1309 if (config2 & CONFIG2_ATTN) {
1310 data->bypass_attn = (0x3 << 3) | 0x3;
1311 } else {
1312 data->bypass_attn = ((data->config4 & CONFIG4_ATTN_IN10) >> 4) |
1313 ((data->config4 & CONFIG4_ATTN_IN43) >> 3);
1314 }
1315 data->bypass_attn &= data->has_voltage;
1316
1005 /* Call adt7475_read_pwm for all pwm's as this will reprogram any 1317 /* Call adt7475_read_pwm for all pwm's as this will reprogram any
1006 pwm's which are disabled to manual mode with 0% duty cycle */ 1318 pwm's which are disabled to manual mode with 0% duty cycle */
1007 for (i = 0; i < ADT7475_PWM_COUNT; i++) 1319 for (i = 0; i < ADT7475_PWM_COUNT; i++)
@@ -1011,16 +1323,70 @@ static int adt7475_probe(struct i2c_client *client,
1011 if (ret) 1323 if (ret)
1012 goto efree; 1324 goto efree;
1013 1325
1326 /* Features that can be disabled individually */
1327 if (data->has_fan4) {
1328 ret = sysfs_create_group(&client->dev.kobj, &fan4_attr_group);
1329 if (ret)
1330 goto eremove;
1331 }
1332 if (data->has_pwm2) {
1333 ret = sysfs_create_group(&client->dev.kobj, &pwm2_attr_group);
1334 if (ret)
1335 goto eremove;
1336 }
1337 if (data->has_voltage & (1 << 0)) {
1338 ret = sysfs_create_group(&client->dev.kobj, &in0_attr_group);
1339 if (ret)
1340 goto eremove;
1341 }
1342 if (data->has_voltage & (1 << 3)) {
1343 ret = sysfs_create_group(&client->dev.kobj, &in3_attr_group);
1344 if (ret)
1345 goto eremove;
1346 }
1347 if (data->has_voltage & (1 << 4)) {
1348 ret = sysfs_create_group(&client->dev.kobj, &in4_attr_group);
1349 if (ret)
1350 goto eremove;
1351 }
1352 if (data->has_voltage & (1 << 5)) {
1353 ret = sysfs_create_group(&client->dev.kobj, &in5_attr_group);
1354 if (ret)
1355 goto eremove;
1356 }
1357 if (data->has_vid) {
1358 data->vrm = vid_which_vrm();
1359 ret = sysfs_create_group(&client->dev.kobj, &vid_attr_group);
1360 if (ret)
1361 goto eremove;
1362 }
1363
1014 data->hwmon_dev = hwmon_device_register(&client->dev); 1364 data->hwmon_dev = hwmon_device_register(&client->dev);
1015 if (IS_ERR(data->hwmon_dev)) { 1365 if (IS_ERR(data->hwmon_dev)) {
1016 ret = PTR_ERR(data->hwmon_dev); 1366 ret = PTR_ERR(data->hwmon_dev);
1017 goto eremove; 1367 goto eremove;
1018 } 1368 }
1019 1369
1370 dev_info(&client->dev, "%s device, revision %d\n",
1371 names[id->driver_data], revision);
1372 if ((data->has_voltage & 0x11) || data->has_fan4 || data->has_pwm2)
1373 dev_info(&client->dev, "Optional features:%s%s%s%s%s\n",
1374 (data->has_voltage & (1 << 0)) ? " in0" : "",
1375 (data->has_voltage & (1 << 4)) ? " in4" : "",
1376 data->has_fan4 ? " fan4" : "",
1377 data->has_pwm2 ? " pwm2" : "",
1378 data->has_vid ? " vid" : "");
1379 if (data->bypass_attn)
1380 dev_info(&client->dev, "Bypassing attenuators on:%s%s%s%s\n",
1381 (data->bypass_attn & (1 << 0)) ? " in0" : "",
1382 (data->bypass_attn & (1 << 1)) ? " in1" : "",
1383 (data->bypass_attn & (1 << 3)) ? " in3" : "",
1384 (data->bypass_attn & (1 << 4)) ? " in4" : "");
1385
1020 return 0; 1386 return 0;
1021 1387
1022eremove: 1388eremove:
1023 sysfs_remove_group(&client->dev.kobj, &adt7475_attr_group); 1389 adt7475_remove_files(client, data);
1024efree: 1390efree:
1025 kfree(data); 1391 kfree(data);
1026 return ret; 1392 return ret;
@@ -1031,7 +1397,7 @@ static int adt7475_remove(struct i2c_client *client)
1031 struct adt7475_data *data = i2c_get_clientdata(client); 1397 struct adt7475_data *data = i2c_get_clientdata(client);
1032 1398
1033 hwmon_device_unregister(data->hwmon_dev); 1399 hwmon_device_unregister(data->hwmon_dev);
1034 sysfs_remove_group(&client->dev.kobj, &adt7475_attr_group); 1400 adt7475_remove_files(client, data);
1035 kfree(data); 1401 kfree(data);
1036 1402
1037 return 0; 1403 return 0;
@@ -1046,7 +1412,7 @@ static struct i2c_driver adt7475_driver = {
1046 .remove = adt7475_remove, 1412 .remove = adt7475_remove,
1047 .id_table = adt7475_id, 1413 .id_table = adt7475_id,
1048 .detect = adt7475_detect, 1414 .detect = adt7475_detect,
1049 .address_data = &addr_data, 1415 .address_list = normal_i2c,
1050}; 1416};
1051 1417
1052static void adt7475_read_hystersis(struct i2c_client *client) 1418static void adt7475_read_hystersis(struct i2c_client *client)
@@ -1116,7 +1482,7 @@ static struct adt7475_data *adt7475_update_device(struct device *dev)
1116{ 1482{
1117 struct i2c_client *client = to_i2c_client(dev); 1483 struct i2c_client *client = to_i2c_client(dev);
1118 struct adt7475_data *data = i2c_get_clientdata(client); 1484 struct adt7475_data *data = i2c_get_clientdata(client);
1119 u8 ext; 1485 u16 ext;
1120 int i; 1486 int i;
1121 1487
1122 mutex_lock(&data->lock); 1488 mutex_lock(&data->lock);
@@ -1127,25 +1493,44 @@ static struct adt7475_data *adt7475_update_device(struct device *dev)
1127 data->alarms = adt7475_read(REG_STATUS2) << 8; 1493 data->alarms = adt7475_read(REG_STATUS2) << 8;
1128 data->alarms |= adt7475_read(REG_STATUS1); 1494 data->alarms |= adt7475_read(REG_STATUS1);
1129 1495
1130 ext = adt7475_read(REG_EXTEND1); 1496 ext = (adt7475_read(REG_EXTEND2) << 8) |
1131 for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) 1497 adt7475_read(REG_EXTEND1);
1498 for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) {
1499 if (!(data->has_voltage & (1 << i)))
1500 continue;
1132 data->voltage[INPUT][i] = 1501 data->voltage[INPUT][i] =
1133 (adt7475_read(VOLTAGE_REG(i)) << 2) | 1502 (adt7475_read(VOLTAGE_REG(i)) << 2) |
1134 ((ext >> ((i + 1) * 2)) & 3); 1503 ((ext >> (i * 2)) & 3);
1504 }
1135 1505
1136 ext = adt7475_read(REG_EXTEND2);
1137 for (i = 0; i < ADT7475_TEMP_COUNT; i++) 1506 for (i = 0; i < ADT7475_TEMP_COUNT; i++)
1138 data->temp[INPUT][i] = 1507 data->temp[INPUT][i] =
1139 (adt7475_read(TEMP_REG(i)) << 2) | 1508 (adt7475_read(TEMP_REG(i)) << 2) |
1140 ((ext >> ((i + 1) * 2)) & 3); 1509 ((ext >> ((i + 5) * 2)) & 3);
1141 1510
1142 for (i = 0; i < ADT7475_TACH_COUNT; i++) 1511 if (data->has_voltage & (1 << 5)) {
1512 data->alarms |= adt7475_read(REG_STATUS4) << 24;
1513 ext = adt7475_read(REG_EXTEND3);
1514 data->voltage[INPUT][5] = adt7475_read(REG_VTT) << 2 |
1515 ((ext >> 4) & 3);
1516 }
1517
1518 for (i = 0; i < ADT7475_TACH_COUNT; i++) {
1519 if (i == 3 && !data->has_fan4)
1520 continue;
1143 data->tach[INPUT][i] = 1521 data->tach[INPUT][i] =
1144 adt7475_read_word(client, TACH_REG(i)); 1522 adt7475_read_word(client, TACH_REG(i));
1523 }
1145 1524
1146 /* Updated by hw when in auto mode */ 1525 /* Updated by hw when in auto mode */
1147 for (i = 0; i < ADT7475_PWM_COUNT; i++) 1526 for (i = 0; i < ADT7475_PWM_COUNT; i++) {
1527 if (i == 1 && !data->has_pwm2)
1528 continue;
1148 data->pwm[INPUT][i] = adt7475_read(PWM_REG(i)); 1529 data->pwm[INPUT][i] = adt7475_read(PWM_REG(i));
1530 }
1531
1532 if (data->has_vid)
1533 data->vid = adt7475_read(REG_VID) & 0x3f;
1149 1534
1150 data->measure_updated = jiffies; 1535 data->measure_updated = jiffies;
1151 } 1536 }
@@ -1153,9 +1538,12 @@ static struct adt7475_data *adt7475_update_device(struct device *dev)
1153 /* Limits and settings, should never change update every 60 seconds */ 1538 /* Limits and settings, should never change update every 60 seconds */
1154 if (time_after(jiffies, data->limits_updated + HZ * 60) || 1539 if (time_after(jiffies, data->limits_updated + HZ * 60) ||
1155 !data->valid) { 1540 !data->valid) {
1541 data->config4 = adt7475_read(REG_CONFIG4);
1156 data->config5 = adt7475_read(REG_CONFIG5); 1542 data->config5 = adt7475_read(REG_CONFIG5);
1157 1543
1158 for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) { 1544 for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) {
1545 if (!(data->has_voltage & (1 << i)))
1546 continue;
1159 /* Adjust values so they match the input precision */ 1547 /* Adjust values so they match the input precision */
1160 data->voltage[MIN][i] = 1548 data->voltage[MIN][i] =
1161 adt7475_read(VOLTAGE_MIN_REG(i)) << 2; 1549 adt7475_read(VOLTAGE_MIN_REG(i)) << 2;
@@ -1163,6 +1551,11 @@ static struct adt7475_data *adt7475_update_device(struct device *dev)
1163 adt7475_read(VOLTAGE_MAX_REG(i)) << 2; 1551 adt7475_read(VOLTAGE_MAX_REG(i)) << 2;
1164 } 1552 }
1165 1553
1554 if (data->has_voltage & (1 << 5)) {
1555 data->voltage[MIN][5] = adt7475_read(REG_VTT_MIN) << 2;
1556 data->voltage[MAX][5] = adt7475_read(REG_VTT_MAX) << 2;
1557 }
1558
1166 for (i = 0; i < ADT7475_TEMP_COUNT; i++) { 1559 for (i = 0; i < ADT7475_TEMP_COUNT; i++) {
1167 /* Adjust values so they match the input precision */ 1560 /* Adjust values so they match the input precision */
1168 data->temp[MIN][i] = 1561 data->temp[MIN][i] =
@@ -1178,11 +1571,16 @@ static struct adt7475_data *adt7475_update_device(struct device *dev)
1178 } 1571 }
1179 adt7475_read_hystersis(client); 1572 adt7475_read_hystersis(client);
1180 1573
1181 for (i = 0; i < ADT7475_TACH_COUNT; i++) 1574 for (i = 0; i < ADT7475_TACH_COUNT; i++) {
1575 if (i == 3 && !data->has_fan4)
1576 continue;
1182 data->tach[MIN][i] = 1577 data->tach[MIN][i] =
1183 adt7475_read_word(client, TACH_MIN_REG(i)); 1578 adt7475_read_word(client, TACH_MIN_REG(i));
1579 }
1184 1580
1185 for (i = 0; i < ADT7475_PWM_COUNT; i++) { 1581 for (i = 0; i < ADT7475_PWM_COUNT; i++) {
1582 if (i == 1 && !data->has_pwm2)
1583 continue;
1186 data->pwm[MAX][i] = adt7475_read(PWM_MAX_REG(i)); 1584 data->pwm[MAX][i] = adt7475_read(PWM_MAX_REG(i));
1187 data->pwm[MIN][i] = adt7475_read(PWM_MIN_REG(i)); 1585 data->pwm[MIN][i] = adt7475_read(PWM_MIN_REG(i));
1188 /* Set the channel and control information */ 1586 /* Set the channel and control information */
diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c
new file mode 100644
index 000000000000..fa9708c2d723
--- /dev/null
+++ b/drivers/hwmon/amc6821.c
@@ -0,0 +1,1115 @@
1/*
2 amc6821.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (C) 2009 T. Mertelj <tomaz.mertelj@guest.arnes.si>
5
6 Based on max6650.c:
7 Copyright (C) 2007 Hans J. Koch <hjk@linutronix.de>
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22*/
23
24
25#include <linux/kernel.h> /* Needed for KERN_INFO */
26#include <linux/module.h>
27#include <linux/init.h>
28#include <linux/slab.h>
29#include <linux/jiffies.h>
30#include <linux/i2c.h>
31#include <linux/hwmon.h>
32#include <linux/hwmon-sysfs.h>
33#include <linux/err.h>
34#include <linux/mutex.h>
35
36
37/*
38 * Addresses to scan.
39 */
40
41static const unsigned short normal_i2c[] = {0x18, 0x19, 0x1a, 0x2c, 0x2d, 0x2e,
42 0x4c, 0x4d, 0x4e, I2C_CLIENT_END};
43
44
45
46/*
47 * Insmod parameters
48 */
49
50static int pwminv = 0; /*Inverted PWM output. */
51module_param(pwminv, int, S_IRUGO);
52
53static int init = 1; /*Power-on initialization.*/
54module_param(init, int, S_IRUGO);
55
56
57enum chips { amc6821 };
58
59#define AMC6821_REG_DEV_ID 0x3D
60#define AMC6821_REG_COMP_ID 0x3E
61#define AMC6821_REG_CONF1 0x00
62#define AMC6821_REG_CONF2 0x01
63#define AMC6821_REG_CONF3 0x3F
64#define AMC6821_REG_CONF4 0x04
65#define AMC6821_REG_STAT1 0x02
66#define AMC6821_REG_STAT2 0x03
67#define AMC6821_REG_TDATA_LOW 0x08
68#define AMC6821_REG_TDATA_HI 0x09
69#define AMC6821_REG_LTEMP_HI 0x0A
70#define AMC6821_REG_RTEMP_HI 0x0B
71#define AMC6821_REG_LTEMP_LIMIT_MIN 0x15
72#define AMC6821_REG_LTEMP_LIMIT_MAX 0x14
73#define AMC6821_REG_RTEMP_LIMIT_MIN 0x19
74#define AMC6821_REG_RTEMP_LIMIT_MAX 0x18
75#define AMC6821_REG_LTEMP_CRIT 0x1B
76#define AMC6821_REG_RTEMP_CRIT 0x1D
77#define AMC6821_REG_PSV_TEMP 0x1C
78#define AMC6821_REG_DCY 0x22
79#define AMC6821_REG_LTEMP_FAN_CTRL 0x24
80#define AMC6821_REG_RTEMP_FAN_CTRL 0x25
81#define AMC6821_REG_DCY_LOW_TEMP 0x21
82
83#define AMC6821_REG_TACH_LLIMITL 0x10
84#define AMC6821_REG_TACH_LLIMITH 0x11
85#define AMC6821_REG_TACH_HLIMITL 0x12
86#define AMC6821_REG_TACH_HLIMITH 0x13
87
88#define AMC6821_CONF1_START 0x01
89#define AMC6821_CONF1_FAN_INT_EN 0x02
90#define AMC6821_CONF1_FANIE 0x04
91#define AMC6821_CONF1_PWMINV 0x08
92#define AMC6821_CONF1_FAN_FAULT_EN 0x10
93#define AMC6821_CONF1_FDRC0 0x20
94#define AMC6821_CONF1_FDRC1 0x40
95#define AMC6821_CONF1_THERMOVIE 0x80
96
97#define AMC6821_CONF2_PWM_EN 0x01
98#define AMC6821_CONF2_TACH_MODE 0x02
99#define AMC6821_CONF2_TACH_EN 0x04
100#define AMC6821_CONF2_RTFIE 0x08
101#define AMC6821_CONF2_LTOIE 0x10
102#define AMC6821_CONF2_RTOIE 0x20
103#define AMC6821_CONF2_PSVIE 0x40
104#define AMC6821_CONF2_RST 0x80
105
106#define AMC6821_CONF3_THERM_FAN_EN 0x80
107#define AMC6821_CONF3_REV_MASK 0x0F
108
109#define AMC6821_CONF4_OVREN 0x10
110#define AMC6821_CONF4_TACH_FAST 0x20
111#define AMC6821_CONF4_PSPR 0x40
112#define AMC6821_CONF4_MODE 0x80
113
114#define AMC6821_STAT1_RPM_ALARM 0x01
115#define AMC6821_STAT1_FANS 0x02
116#define AMC6821_STAT1_RTH 0x04
117#define AMC6821_STAT1_RTL 0x08
118#define AMC6821_STAT1_R_THERM 0x10
119#define AMC6821_STAT1_RTF 0x20
120#define AMC6821_STAT1_LTH 0x40
121#define AMC6821_STAT1_LTL 0x80
122
123#define AMC6821_STAT2_RTC 0x08
124#define AMC6821_STAT2_LTC 0x10
125#define AMC6821_STAT2_LPSV 0x20
126#define AMC6821_STAT2_L_THERM 0x40
127#define AMC6821_STAT2_THERM_IN 0x80
128
129enum {IDX_TEMP1_INPUT = 0, IDX_TEMP1_MIN, IDX_TEMP1_MAX,
130 IDX_TEMP1_CRIT, IDX_TEMP2_INPUT, IDX_TEMP2_MIN,
131 IDX_TEMP2_MAX, IDX_TEMP2_CRIT,
132 TEMP_IDX_LEN, };
133
134static const u8 temp_reg[] = {AMC6821_REG_LTEMP_HI,
135 AMC6821_REG_LTEMP_LIMIT_MIN,
136 AMC6821_REG_LTEMP_LIMIT_MAX,
137 AMC6821_REG_LTEMP_CRIT,
138 AMC6821_REG_RTEMP_HI,
139 AMC6821_REG_RTEMP_LIMIT_MIN,
140 AMC6821_REG_RTEMP_LIMIT_MAX,
141 AMC6821_REG_RTEMP_CRIT, };
142
143enum {IDX_FAN1_INPUT = 0, IDX_FAN1_MIN, IDX_FAN1_MAX,
144 FAN1_IDX_LEN, };
145
146static const u8 fan_reg_low[] = {AMC6821_REG_TDATA_LOW,
147 AMC6821_REG_TACH_LLIMITL,
148 AMC6821_REG_TACH_HLIMITL, };
149
150
151static const u8 fan_reg_hi[] = {AMC6821_REG_TDATA_HI,
152 AMC6821_REG_TACH_LLIMITH,
153 AMC6821_REG_TACH_HLIMITH, };
154
155static int amc6821_probe(
156 struct i2c_client *client,
157 const struct i2c_device_id *id);
158static int amc6821_detect(
159 struct i2c_client *client,
160 struct i2c_board_info *info);
161static int amc6821_init_client(struct i2c_client *client);
162static int amc6821_remove(struct i2c_client *client);
163static struct amc6821_data *amc6821_update_device(struct device *dev);
164
165/*
166 * Driver data (common to all clients)
167 */
168
169static const struct i2c_device_id amc6821_id[] = {
170 { "amc6821", amc6821 },
171 { }
172};
173
174MODULE_DEVICE_TABLE(i2c, amc6821_id);
175
176static struct i2c_driver amc6821_driver = {
177 .class = I2C_CLASS_HWMON,
178 .driver = {
179 .name = "amc6821",
180 },
181 .probe = amc6821_probe,
182 .remove = amc6821_remove,
183 .id_table = amc6821_id,
184 .detect = amc6821_detect,
185 .address_list = normal_i2c,
186};
187
188
189/*
190 * Client data (each client gets its own)
191 */
192
193struct amc6821_data {
194 struct device *hwmon_dev;
195 struct mutex update_lock;
196 char valid; /* zero until following fields are valid */
197 unsigned long last_updated; /* in jiffies */
198
199 /* register values */
200 int temp[TEMP_IDX_LEN];
201
202 u16 fan[FAN1_IDX_LEN];
203 u8 fan1_div;
204
205 u8 pwm1;
206 u8 temp1_auto_point_temp[3];
207 u8 temp2_auto_point_temp[3];
208 u8 pwm1_auto_point_pwm[3];
209 u8 pwm1_enable;
210 u8 pwm1_auto_channels_temp;
211
212 u8 stat1;
213 u8 stat2;
214};
215
216
217static ssize_t get_temp(
218 struct device *dev,
219 struct device_attribute *devattr,
220 char *buf)
221{
222 struct amc6821_data *data = amc6821_update_device(dev);
223 int ix = to_sensor_dev_attr(devattr)->index;
224
225 return sprintf(buf, "%d\n", data->temp[ix] * 1000);
226}
227
228
229
230static ssize_t set_temp(
231 struct device *dev,
232 struct device_attribute *attr,
233 const char *buf,
234 size_t count)
235{
236 struct i2c_client *client = to_i2c_client(dev);
237 struct amc6821_data *data = i2c_get_clientdata(client);
238 int ix = to_sensor_dev_attr(attr)->index;
239 long val;
240
241 int ret = strict_strtol(buf, 10, &val);
242 if (ret)
243 return ret;
244 val = SENSORS_LIMIT(val / 1000, -128, 127);
245
246 mutex_lock(&data->update_lock);
247 data->temp[ix] = val;
248 if (i2c_smbus_write_byte_data(client, temp_reg[ix], data->temp[ix])) {
249 dev_err(&client->dev, "Register write error, aborting.\n");
250 count = -EIO;
251 }
252 mutex_unlock(&data->update_lock);
253 return count;
254}
255
256
257
258
259static ssize_t get_temp_alarm(
260 struct device *dev,
261 struct device_attribute *devattr,
262 char *buf)
263{
264 struct amc6821_data *data = amc6821_update_device(dev);
265 int ix = to_sensor_dev_attr(devattr)->index;
266 u8 flag;
267
268 switch (ix) {
269 case IDX_TEMP1_MIN:
270 flag = data->stat1 & AMC6821_STAT1_LTL;
271 break;
272 case IDX_TEMP1_MAX:
273 flag = data->stat1 & AMC6821_STAT1_LTH;
274 break;
275 case IDX_TEMP1_CRIT:
276 flag = data->stat2 & AMC6821_STAT2_LTC;
277 break;
278 case IDX_TEMP2_MIN:
279 flag = data->stat1 & AMC6821_STAT1_RTL;
280 break;
281 case IDX_TEMP2_MAX:
282 flag = data->stat1 & AMC6821_STAT1_RTH;
283 break;
284 case IDX_TEMP2_CRIT:
285 flag = data->stat2 & AMC6821_STAT2_RTC;
286 break;
287 default:
288 dev_dbg(dev, "Unknown attr->index (%d).\n", ix);
289 return -EINVAL;
290 }
291 if (flag)
292 return sprintf(buf, "1");
293 else
294 return sprintf(buf, "0");
295}
296
297
298
299
300static ssize_t get_temp2_fault(
301 struct device *dev,
302 struct device_attribute *devattr,
303 char *buf)
304{
305 struct amc6821_data *data = amc6821_update_device(dev);
306 if (data->stat1 & AMC6821_STAT1_RTF)
307 return sprintf(buf, "1");
308 else
309 return sprintf(buf, "0");
310}
311
312static ssize_t get_pwm1(
313 struct device *dev,
314 struct device_attribute *devattr,
315 char *buf)
316{
317 struct amc6821_data *data = amc6821_update_device(dev);
318 return sprintf(buf, "%d\n", data->pwm1);
319}
320
321static ssize_t set_pwm1(
322 struct device *dev,
323 struct device_attribute *devattr,
324 const char *buf,
325 size_t count)
326{
327 struct i2c_client *client = to_i2c_client(dev);
328 struct amc6821_data *data = i2c_get_clientdata(client);
329 long val;
330 int ret = strict_strtol(buf, 10, &val);
331 if (ret)
332 return ret;
333
334 mutex_lock(&data->update_lock);
335 data->pwm1 = SENSORS_LIMIT(val , 0, 255);
336 i2c_smbus_write_byte_data(client, AMC6821_REG_DCY, data->pwm1);
337 mutex_unlock(&data->update_lock);
338 return count;
339}
340
341static ssize_t get_pwm1_enable(
342 struct device *dev,
343 struct device_attribute *devattr,
344 char *buf)
345{
346 struct amc6821_data *data = amc6821_update_device(dev);
347 return sprintf(buf, "%d\n", data->pwm1_enable);
348}
349
350static ssize_t set_pwm1_enable(
351 struct device *dev,
352 struct device_attribute *attr,
353 const char *buf,
354 size_t count)
355{
356 struct i2c_client *client = to_i2c_client(dev);
357 struct amc6821_data *data = i2c_get_clientdata(client);
358 long val;
359 int config = strict_strtol(buf, 10, &val);
360 if (config)
361 return config;
362
363 config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF1);
364 if (config < 0) {
365 dev_err(&client->dev,
366 "Error reading configuration register, aborting.\n");
367 return -EIO;
368 }
369
370 switch (val) {
371 case 1:
372 config &= ~AMC6821_CONF1_FDRC0;
373 config &= ~AMC6821_CONF1_FDRC1;
374 break;
375 case 2:
376 config &= ~AMC6821_CONF1_FDRC0;
377 config |= AMC6821_CONF1_FDRC1;
378 break;
379 case 3:
380 config |= AMC6821_CONF1_FDRC0;
381 config |= AMC6821_CONF1_FDRC1;
382 break;
383 default:
384 return -EINVAL;
385 }
386 mutex_lock(&data->update_lock);
387 if (i2c_smbus_write_byte_data(client, AMC6821_REG_CONF1, config)) {
388 dev_err(&client->dev,
389 "Configuration register write error, aborting.\n");
390 count = -EIO;
391 }
392 mutex_unlock(&data->update_lock);
393 return count;
394}
395
396
397static ssize_t get_pwm1_auto_channels_temp(
398 struct device *dev,
399 struct device_attribute *devattr,
400 char *buf)
401{
402 struct amc6821_data *data = amc6821_update_device(dev);
403 return sprintf(buf, "%d\n", data->pwm1_auto_channels_temp);
404}
405
406
407static ssize_t get_temp_auto_point_temp(
408 struct device *dev,
409 struct device_attribute *devattr,
410 char *buf)
411{
412 int ix = to_sensor_dev_attr_2(devattr)->index;
413 int nr = to_sensor_dev_attr_2(devattr)->nr;
414 struct amc6821_data *data = amc6821_update_device(dev);
415 switch (nr) {
416 case 1:
417 return sprintf(buf, "%d\n",
418 data->temp1_auto_point_temp[ix] * 1000);
419 break;
420 case 2:
421 return sprintf(buf, "%d\n",
422 data->temp2_auto_point_temp[ix] * 1000);
423 break;
424 default:
425 dev_dbg(dev, "Unknown attr->nr (%d).\n", nr);
426 return -EINVAL;
427 }
428}
429
430
431static ssize_t get_pwm1_auto_point_pwm(
432 struct device *dev,
433 struct device_attribute *devattr,
434 char *buf)
435{
436 int ix = to_sensor_dev_attr(devattr)->index;
437 struct amc6821_data *data = amc6821_update_device(dev);
438 return sprintf(buf, "%d\n", data->pwm1_auto_point_pwm[ix]);
439}
440
441
442static inline ssize_t set_slope_register(struct i2c_client *client,
443 u8 reg,
444 u8 dpwm,
445 u8 *ptemp)
446{
447 int dt;
448 u8 tmp;
449
450 dt = ptemp[2]-ptemp[1];
451 for (tmp = 4; tmp > 0; tmp--) {
452 if (dt * (0x20 >> tmp) >= dpwm)
453 break;
454 }
455 tmp |= (ptemp[1] & 0x7C) << 1;
456 if (i2c_smbus_write_byte_data(client,
457 reg, tmp)) {
458 dev_err(&client->dev, "Register write error, aborting.\n");
459 return -EIO;
460 }
461 return 0;
462}
463
464
465
466static ssize_t set_temp_auto_point_temp(
467 struct device *dev,
468 struct device_attribute *attr,
469 const char *buf,
470 size_t count)
471{
472 struct i2c_client *client = to_i2c_client(dev);
473 struct amc6821_data *data = amc6821_update_device(dev);
474 int ix = to_sensor_dev_attr_2(attr)->index;
475 int nr = to_sensor_dev_attr_2(attr)->nr;
476 u8 *ptemp;
477 u8 reg;
478 int dpwm;
479 long val;
480 int ret = strict_strtol(buf, 10, &val);
481 if (ret)
482 return ret;
483
484 switch (nr) {
485 case 1:
486 ptemp = data->temp1_auto_point_temp;
487 reg = AMC6821_REG_LTEMP_FAN_CTRL;
488 break;
489 case 2:
490 ptemp = data->temp2_auto_point_temp;
491 reg = AMC6821_REG_RTEMP_FAN_CTRL;
492 break;
493 default:
494 dev_dbg(dev, "Unknown attr->nr (%d).\n", nr);
495 return -EINVAL;
496 }
497
498 data->valid = 0;
499 mutex_lock(&data->update_lock);
500 switch (ix) {
501 case 0:
502 ptemp[0] = SENSORS_LIMIT(val / 1000, 0,
503 data->temp1_auto_point_temp[1]);
504 ptemp[0] = SENSORS_LIMIT(ptemp[0], 0,
505 data->temp2_auto_point_temp[1]);
506 ptemp[0] = SENSORS_LIMIT(ptemp[0], 0, 63);
507 if (i2c_smbus_write_byte_data(
508 client,
509 AMC6821_REG_PSV_TEMP,
510 ptemp[0])) {
511 dev_err(&client->dev,
512 "Register write error, aborting.\n");
513 count = -EIO;
514 }
515 goto EXIT;
516 break;
517 case 1:
518 ptemp[1] = SENSORS_LIMIT(
519 val / 1000,
520 (ptemp[0] & 0x7C) + 4,
521 124);
522 ptemp[1] &= 0x7C;
523 ptemp[2] = SENSORS_LIMIT(
524 ptemp[2], ptemp[1] + 1,
525 255);
526 break;
527 case 2:
528 ptemp[2] = SENSORS_LIMIT(
529 val / 1000,
530 ptemp[1]+1,
531 255);
532 break;
533 default:
534 dev_dbg(dev, "Unknown attr->index (%d).\n", ix);
535 count = -EINVAL;
536 goto EXIT;
537 }
538 dpwm = data->pwm1_auto_point_pwm[2] - data->pwm1_auto_point_pwm[1];
539 if (set_slope_register(client, reg, dpwm, ptemp))
540 count = -EIO;
541
542EXIT:
543 mutex_unlock(&data->update_lock);
544 return count;
545}
546
547
548
549static ssize_t set_pwm1_auto_point_pwm(
550 struct device *dev,
551 struct device_attribute *attr,
552 const char *buf,
553 size_t count)
554{
555 struct i2c_client *client = to_i2c_client(dev);
556 struct amc6821_data *data = i2c_get_clientdata(client);
557 int dpwm;
558 long val;
559 int ret = strict_strtol(buf, 10, &val);
560 if (ret)
561 return ret;
562
563 mutex_lock(&data->update_lock);
564 data->pwm1_auto_point_pwm[1] = SENSORS_LIMIT(val, 0, 254);
565 if (i2c_smbus_write_byte_data(client, AMC6821_REG_DCY_LOW_TEMP,
566 data->pwm1_auto_point_pwm[1])) {
567 dev_err(&client->dev, "Register write error, aborting.\n");
568 count = -EIO;
569 goto EXIT;
570 }
571 dpwm = data->pwm1_auto_point_pwm[2] - data->pwm1_auto_point_pwm[1];
572 if (set_slope_register(client, AMC6821_REG_LTEMP_FAN_CTRL, dpwm,
573 data->temp1_auto_point_temp)) {
574 count = -EIO;
575 goto EXIT;
576 }
577 if (set_slope_register(client, AMC6821_REG_RTEMP_FAN_CTRL, dpwm,
578 data->temp2_auto_point_temp)) {
579 count = -EIO;
580 goto EXIT;
581 }
582
583EXIT:
584 data->valid = 0;
585 mutex_unlock(&data->update_lock);
586 return count;
587}
588
589static ssize_t get_fan(
590 struct device *dev,
591 struct device_attribute *devattr,
592 char *buf)
593{
594 struct amc6821_data *data = amc6821_update_device(dev);
595 int ix = to_sensor_dev_attr(devattr)->index;
596 if (0 == data->fan[ix])
597 return sprintf(buf, "0");
598 return sprintf(buf, "%d\n", (int)(6000000 / data->fan[ix]));
599}
600
601
602
603static ssize_t get_fan1_fault(
604 struct device *dev,
605 struct device_attribute *devattr,
606 char *buf)
607{
608 struct amc6821_data *data = amc6821_update_device(dev);
609 if (data->stat1 & AMC6821_STAT1_FANS)
610 return sprintf(buf, "1");
611 else
612 return sprintf(buf, "0");
613}
614
615
616
617static ssize_t set_fan(
618 struct device *dev,
619 struct device_attribute *attr,
620 const char *buf, size_t count)
621{
622 struct i2c_client *client = to_i2c_client(dev);
623 struct amc6821_data *data = i2c_get_clientdata(client);
624 long val;
625 int ix = to_sensor_dev_attr(attr)->index;
626 int ret = strict_strtol(buf, 10, &val);
627 if (ret)
628 return ret;
629 val = 1 > val ? 0xFFFF : 6000000/val;
630
631 mutex_lock(&data->update_lock);
632 data->fan[ix] = (u16) SENSORS_LIMIT(val, 1, 0xFFFF);
633 if (i2c_smbus_write_byte_data(client, fan_reg_low[ix],
634 data->fan[ix] & 0xFF)) {
635 dev_err(&client->dev, "Register write error, aborting.\n");
636 count = -EIO;
637 goto EXIT;
638 }
639 if (i2c_smbus_write_byte_data(client,
640 fan_reg_hi[ix], data->fan[ix] >> 8)) {
641 dev_err(&client->dev, "Register write error, aborting.\n");
642 count = -EIO;
643 }
644EXIT:
645 mutex_unlock(&data->update_lock);
646 return count;
647}
648
649
650
651static ssize_t get_fan1_div(
652 struct device *dev,
653 struct device_attribute *devattr,
654 char *buf)
655{
656 struct amc6821_data *data = amc6821_update_device(dev);
657 return sprintf(buf, "%d\n", data->fan1_div);
658}
659
660static ssize_t set_fan1_div(
661 struct device *dev,
662 struct device_attribute *attr,
663 const char *buf, size_t count)
664{
665 struct i2c_client *client = to_i2c_client(dev);
666 struct amc6821_data *data = i2c_get_clientdata(client);
667 long val;
668 int config = strict_strtol(buf, 10, &val);
669 if (config)
670 return config;
671
672 config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF4);
673 if (config < 0) {
674 dev_err(&client->dev,
675 "Error reading configuration register, aborting.\n");
676 return -EIO;
677 }
678 mutex_lock(&data->update_lock);
679 switch (val) {
680 case 2:
681 config &= ~AMC6821_CONF4_PSPR;
682 data->fan1_div = 2;
683 break;
684 case 4:
685 config |= AMC6821_CONF4_PSPR;
686 data->fan1_div = 4;
687 break;
688 default:
689 count = -EINVAL;
690 goto EXIT;
691 }
692 if (i2c_smbus_write_byte_data(client, AMC6821_REG_CONF4, config)) {
693 dev_err(&client->dev,
694 "Configuration register write error, aborting.\n");
695 count = -EIO;
696 }
697EXIT:
698 mutex_unlock(&data->update_lock);
699 return count;
700}
701
702
703
704static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO,
705 get_temp, NULL, IDX_TEMP1_INPUT);
706static SENSOR_DEVICE_ATTR(temp1_min, S_IRUGO | S_IWUSR, get_temp,
707 set_temp, IDX_TEMP1_MIN);
708static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, get_temp,
709 set_temp, IDX_TEMP1_MAX);
710static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO | S_IWUSR, get_temp,
711 set_temp, IDX_TEMP1_CRIT);
712static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO,
713 get_temp_alarm, NULL, IDX_TEMP1_MIN);
714static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO,
715 get_temp_alarm, NULL, IDX_TEMP1_MAX);
716static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO,
717 get_temp_alarm, NULL, IDX_TEMP1_CRIT);
718static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO | S_IWUSR,
719 get_temp, NULL, IDX_TEMP2_INPUT);
720static SENSOR_DEVICE_ATTR(temp2_min, S_IRUGO | S_IWUSR, get_temp,
721 set_temp, IDX_TEMP2_MIN);
722static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO | S_IWUSR, get_temp,
723 set_temp, IDX_TEMP2_MAX);
724static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO | S_IWUSR, get_temp,
725 set_temp, IDX_TEMP2_CRIT);
726static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO,
727 get_temp2_fault, NULL, 0);
728static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO,
729 get_temp_alarm, NULL, IDX_TEMP2_MIN);
730static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO,
731 get_temp_alarm, NULL, IDX_TEMP2_MAX);
732static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO,
733 get_temp_alarm, NULL, IDX_TEMP2_CRIT);
734static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, get_fan, NULL, IDX_FAN1_INPUT);
735static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO | S_IWUSR,
736 get_fan, set_fan, IDX_FAN1_MIN);
737static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO | S_IWUSR,
738 get_fan, set_fan, IDX_FAN1_MAX);
739static SENSOR_DEVICE_ATTR(fan1_fault, S_IRUGO, get_fan1_fault, NULL, 0);
740static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR,
741 get_fan1_div, set_fan1_div, 0);
742
743static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, get_pwm1, set_pwm1, 0);
744static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
745 get_pwm1_enable, set_pwm1_enable, 0);
746static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IRUGO,
747 get_pwm1_auto_point_pwm, NULL, 0);
748static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IWUSR | S_IRUGO,
749 get_pwm1_auto_point_pwm, set_pwm1_auto_point_pwm, 1);
750static SENSOR_DEVICE_ATTR(pwm1_auto_point3_pwm, S_IRUGO,
751 get_pwm1_auto_point_pwm, NULL, 2);
752static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IRUGO,
753 get_pwm1_auto_channels_temp, NULL, 0);
754static SENSOR_DEVICE_ATTR_2(temp1_auto_point1_temp, S_IRUGO,
755 get_temp_auto_point_temp, NULL, 1, 0);
756static SENSOR_DEVICE_ATTR_2(temp1_auto_point2_temp, S_IWUSR | S_IRUGO,
757 get_temp_auto_point_temp, set_temp_auto_point_temp, 1, 1);
758static SENSOR_DEVICE_ATTR_2(temp1_auto_point3_temp, S_IWUSR | S_IRUGO,
759 get_temp_auto_point_temp, set_temp_auto_point_temp, 1, 2);
760
761static SENSOR_DEVICE_ATTR_2(temp2_auto_point1_temp, S_IWUSR | S_IRUGO,
762 get_temp_auto_point_temp, set_temp_auto_point_temp, 2, 0);
763static SENSOR_DEVICE_ATTR_2(temp2_auto_point2_temp, S_IWUSR | S_IRUGO,
764 get_temp_auto_point_temp, set_temp_auto_point_temp, 2, 1);
765static SENSOR_DEVICE_ATTR_2(temp2_auto_point3_temp, S_IWUSR | S_IRUGO,
766 get_temp_auto_point_temp, set_temp_auto_point_temp, 2, 2);
767
768
769
770static struct attribute *amc6821_attrs[] = {
771 &sensor_dev_attr_temp1_input.dev_attr.attr,
772 &sensor_dev_attr_temp1_min.dev_attr.attr,
773 &sensor_dev_attr_temp1_max.dev_attr.attr,
774 &sensor_dev_attr_temp1_crit.dev_attr.attr,
775 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
776 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
777 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
778 &sensor_dev_attr_temp2_input.dev_attr.attr,
779 &sensor_dev_attr_temp2_min.dev_attr.attr,
780 &sensor_dev_attr_temp2_max.dev_attr.attr,
781 &sensor_dev_attr_temp2_crit.dev_attr.attr,
782 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
783 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
784 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
785 &sensor_dev_attr_temp2_fault.dev_attr.attr,
786 &sensor_dev_attr_fan1_input.dev_attr.attr,
787 &sensor_dev_attr_fan1_min.dev_attr.attr,
788 &sensor_dev_attr_fan1_max.dev_attr.attr,
789 &sensor_dev_attr_fan1_fault.dev_attr.attr,
790 &sensor_dev_attr_fan1_div.dev_attr.attr,
791 &sensor_dev_attr_pwm1.dev_attr.attr,
792 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
793 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
794 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
795 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
796 &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr,
797 &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr,
798 &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr,
799 &sensor_dev_attr_temp1_auto_point3_temp.dev_attr.attr,
800 &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr,
801 &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr,
802 &sensor_dev_attr_temp2_auto_point3_temp.dev_attr.attr,
803 NULL
804};
805
806static struct attribute_group amc6821_attr_grp = {
807 .attrs = amc6821_attrs,
808};
809
810
811
812/* Return 0 if detection is successful, -ENODEV otherwise */
813static int amc6821_detect(
814 struct i2c_client *client,
815 struct i2c_board_info *info)
816{
817 struct i2c_adapter *adapter = client->adapter;
818 int address = client->addr;
819 int dev_id, comp_id;
820
821 dev_dbg(&adapter->dev, "amc6821_detect called.\n");
822
823 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
824 dev_dbg(&adapter->dev,
825 "amc6821: I2C bus doesn't support byte mode, "
826 "skipping.\n");
827 return -ENODEV;
828 }
829
830 dev_id = i2c_smbus_read_byte_data(client, AMC6821_REG_DEV_ID);
831 comp_id = i2c_smbus_read_byte_data(client, AMC6821_REG_COMP_ID);
832 if (dev_id != 0x21 || comp_id != 0x49) {
833 dev_dbg(&adapter->dev,
834 "amc6821: detection failed at 0x%02x.\n",
835 address);
836 return -ENODEV;
837 }
838
839 /* Bit 7 of the address register is ignored, so we can check the
840 ID registers again */
841 dev_id = i2c_smbus_read_byte_data(client, 0x80 | AMC6821_REG_DEV_ID);
842 comp_id = i2c_smbus_read_byte_data(client, 0x80 | AMC6821_REG_COMP_ID);
843 if (dev_id != 0x21 || comp_id != 0x49) {
844 dev_dbg(&adapter->dev,
845 "amc6821: detection failed at 0x%02x.\n",
846 address);
847 return -ENODEV;
848 }
849
850 dev_info(&adapter->dev, "amc6821: chip found at 0x%02x.\n", address);
851 strlcpy(info->type, "amc6821", I2C_NAME_SIZE);
852
853 return 0;
854}
855
856static int amc6821_probe(
857 struct i2c_client *client,
858 const struct i2c_device_id *id)
859{
860 struct amc6821_data *data;
861 int err;
862
863 data = kzalloc(sizeof(struct amc6821_data), GFP_KERNEL);
864 if (!data) {
865 dev_err(&client->dev, "out of memory.\n");
866 return -ENOMEM;
867 }
868
869
870 i2c_set_clientdata(client, data);
871 mutex_init(&data->update_lock);
872
873 /*
874 * Initialize the amc6821 chip
875 */
876 err = amc6821_init_client(client);
877 if (err)
878 goto err_free;
879
880 err = sysfs_create_group(&client->dev.kobj, &amc6821_attr_grp);
881 if (err)
882 goto err_free;
883
884 data->hwmon_dev = hwmon_device_register(&client->dev);
885 if (!IS_ERR(data->hwmon_dev))
886 return 0;
887
888 err = PTR_ERR(data->hwmon_dev);
889 dev_err(&client->dev, "error registering hwmon device.\n");
890 sysfs_remove_group(&client->dev.kobj, &amc6821_attr_grp);
891err_free:
892 kfree(data);
893 return err;
894}
895
896static int amc6821_remove(struct i2c_client *client)
897{
898 struct amc6821_data *data = i2c_get_clientdata(client);
899
900 hwmon_device_unregister(data->hwmon_dev);
901 sysfs_remove_group(&client->dev.kobj, &amc6821_attr_grp);
902
903 kfree(data);
904
905 return 0;
906}
907
908
909static int amc6821_init_client(struct i2c_client *client)
910{
911 int config;
912 int err = -EIO;
913
914 if (init) {
915 config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF4);
916
917 if (config < 0) {
918 dev_err(&client->dev,
919 "Error reading configuration register, aborting.\n");
920 return err;
921 }
922
923 config |= AMC6821_CONF4_MODE;
924
925 if (i2c_smbus_write_byte_data(client, AMC6821_REG_CONF4,
926 config)) {
927 dev_err(&client->dev,
928 "Configuration register write error, aborting.\n");
929 return err;
930 }
931
932 config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF3);
933
934 if (config < 0) {
935 dev_err(&client->dev,
936 "Error reading configuration register, aborting.\n");
937 return err;
938 }
939
940 dev_info(&client->dev, "Revision %d\n", config & 0x0f);
941
942 config &= ~AMC6821_CONF3_THERM_FAN_EN;
943
944 if (i2c_smbus_write_byte_data(client, AMC6821_REG_CONF3,
945 config)) {
946 dev_err(&client->dev,
947 "Configuration register write error, aborting.\n");
948 return err;
949 }
950
951 config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF2);
952
953 if (config < 0) {
954 dev_err(&client->dev,
955 "Error reading configuration register, aborting.\n");
956 return err;
957 }
958
959 config &= ~AMC6821_CONF2_RTFIE;
960 config &= ~AMC6821_CONF2_LTOIE;
961 config &= ~AMC6821_CONF2_RTOIE;
962 if (i2c_smbus_write_byte_data(client,
963 AMC6821_REG_CONF2, config)) {
964 dev_err(&client->dev,
965 "Configuration register write error, aborting.\n");
966 return err;
967 }
968
969 config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF1);
970
971 if (config < 0) {
972 dev_err(&client->dev,
973 "Error reading configuration register, aborting.\n");
974 return err;
975 }
976
977 config &= ~AMC6821_CONF1_THERMOVIE;
978 config &= ~AMC6821_CONF1_FANIE;
979 config |= AMC6821_CONF1_START;
980 if (pwminv)
981 config |= AMC6821_CONF1_PWMINV;
982 else
983 config &= ~AMC6821_CONF1_PWMINV;
984
985 if (i2c_smbus_write_byte_data(
986 client, AMC6821_REG_CONF1, config)) {
987 dev_err(&client->dev,
988 "Configuration register write error, aborting.\n");
989 return err;
990 }
991 }
992 return 0;
993}
994
995
996static struct amc6821_data *amc6821_update_device(struct device *dev)
997{
998 struct i2c_client *client = to_i2c_client(dev);
999 struct amc6821_data *data = i2c_get_clientdata(client);
1000 int timeout = HZ;
1001 u8 reg;
1002 int i;
1003
1004 mutex_lock(&data->update_lock);
1005
1006 if (time_after(jiffies, data->last_updated + timeout) ||
1007 !data->valid) {
1008
1009 for (i = 0; i < TEMP_IDX_LEN; i++)
1010 data->temp[i] = i2c_smbus_read_byte_data(client,
1011 temp_reg[i]);
1012
1013 data->stat1 = i2c_smbus_read_byte_data(client,
1014 AMC6821_REG_STAT1);
1015 data->stat2 = i2c_smbus_read_byte_data(client,
1016 AMC6821_REG_STAT2);
1017
1018 data->pwm1 = i2c_smbus_read_byte_data(client,
1019 AMC6821_REG_DCY);
1020 for (i = 0; i < FAN1_IDX_LEN; i++) {
1021 data->fan[i] = i2c_smbus_read_byte_data(
1022 client,
1023 fan_reg_low[i]);
1024 data->fan[i] += i2c_smbus_read_byte_data(
1025 client,
1026 fan_reg_hi[i]) << 8;
1027 }
1028 data->fan1_div = i2c_smbus_read_byte_data(client,
1029 AMC6821_REG_CONF4);
1030 data->fan1_div = data->fan1_div & AMC6821_CONF4_PSPR ? 4 : 2;
1031
1032 data->pwm1_auto_point_pwm[0] = 0;
1033 data->pwm1_auto_point_pwm[2] = 255;
1034 data->pwm1_auto_point_pwm[1] = i2c_smbus_read_byte_data(client,
1035 AMC6821_REG_DCY_LOW_TEMP);
1036
1037 data->temp1_auto_point_temp[0] =
1038 i2c_smbus_read_byte_data(client,
1039 AMC6821_REG_PSV_TEMP);
1040 data->temp2_auto_point_temp[0] =
1041 data->temp1_auto_point_temp[0];
1042 reg = i2c_smbus_read_byte_data(client,
1043 AMC6821_REG_LTEMP_FAN_CTRL);
1044 data->temp1_auto_point_temp[1] = (reg & 0xF8) >> 1;
1045 reg &= 0x07;
1046 reg = 0x20 >> reg;
1047 if (reg > 0)
1048 data->temp1_auto_point_temp[2] =
1049 data->temp1_auto_point_temp[1] +
1050 (data->pwm1_auto_point_pwm[2] -
1051 data->pwm1_auto_point_pwm[1]) / reg;
1052 else
1053 data->temp1_auto_point_temp[2] = 255;
1054
1055 reg = i2c_smbus_read_byte_data(client,
1056 AMC6821_REG_RTEMP_FAN_CTRL);
1057 data->temp2_auto_point_temp[1] = (reg & 0xF8) >> 1;
1058 reg &= 0x07;
1059 reg = 0x20 >> reg;
1060 if (reg > 0)
1061 data->temp2_auto_point_temp[2] =
1062 data->temp2_auto_point_temp[1] +
1063 (data->pwm1_auto_point_pwm[2] -
1064 data->pwm1_auto_point_pwm[1]) / reg;
1065 else
1066 data->temp2_auto_point_temp[2] = 255;
1067
1068 reg = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF1);
1069 reg = (reg >> 5) & 0x3;
1070 switch (reg) {
1071 case 0: /*open loop: software sets pwm1*/
1072 data->pwm1_auto_channels_temp = 0;
1073 data->pwm1_enable = 1;
1074 break;
1075 case 2: /*closed loop: remote T (temp2)*/
1076 data->pwm1_auto_channels_temp = 2;
1077 data->pwm1_enable = 2;
1078 break;
1079 case 3: /*closed loop: local and remote T (temp2)*/
1080 data->pwm1_auto_channels_temp = 3;
1081 data->pwm1_enable = 3;
1082 break;
1083 case 1: /*semi-open loop: software sets rpm, chip controls pwm1,
1084 *currently not implemented
1085 */
1086 data->pwm1_auto_channels_temp = 0;
1087 data->pwm1_enable = 0;
1088 break;
1089 }
1090
1091 data->last_updated = jiffies;
1092 data->valid = 1;
1093 }
1094 mutex_unlock(&data->update_lock);
1095 return data;
1096}
1097
1098
1099static int __init amc6821_init(void)
1100{
1101 return i2c_add_driver(&amc6821_driver);
1102}
1103
1104static void __exit amc6821_exit(void)
1105{
1106 i2c_del_driver(&amc6821_driver);
1107}
1108
1109module_init(amc6821_init);
1110module_exit(amc6821_exit);
1111
1112
1113MODULE_LICENSE("GPL");
1114MODULE_AUTHOR("T. Mertelj <tomaz.mertelj@guest.arnes.si>");
1115MODULE_DESCRIPTION("Texas Instruments amc6821 hwmon driver");
diff --git a/drivers/hwmon/ams/ams-core.c b/drivers/hwmon/ams/ams-core.c
index 6c9ace1b76f6..2ad62c339cd2 100644
--- a/drivers/hwmon/ams/ams-core.c
+++ b/drivers/hwmon/ams/ams-core.c
@@ -213,7 +213,7 @@ int __init ams_init(void)
213 return -ENODEV; 213 return -ENODEV;
214} 214}
215 215
216void ams_exit(void) 216void ams_sensor_detach(void)
217{ 217{
218 /* Remove input device */ 218 /* Remove input device */
219 ams_input_exit(); 219 ams_input_exit();
@@ -221,9 +221,6 @@ void ams_exit(void)
221 /* Remove attributes */ 221 /* Remove attributes */
222 device_remove_file(&ams_info.of_dev->dev, &dev_attr_current); 222 device_remove_file(&ams_info.of_dev->dev, &dev_attr_current);
223 223
224 /* Shut down implementation */
225 ams_info.exit();
226
227 /* Flush interrupt worker 224 /* Flush interrupt worker
228 * 225 *
229 * We do this after ams_info.exit(), because an interrupt might 226 * We do this after ams_info.exit(), because an interrupt might
@@ -239,6 +236,12 @@ void ams_exit(void)
239 pmf_unregister_irq_client(&ams_freefall_client); 236 pmf_unregister_irq_client(&ams_freefall_client);
240} 237}
241 238
239static void __exit ams_exit(void)
240{
241 /* Shut down implementation */
242 ams_info.exit();
243}
244
242MODULE_AUTHOR("Stelian Pop, Michael Hanselmann"); 245MODULE_AUTHOR("Stelian Pop, Michael Hanselmann");
243MODULE_DESCRIPTION("Apple Motion Sensor driver"); 246MODULE_DESCRIPTION("Apple Motion Sensor driver");
244MODULE_LICENSE("GPL"); 247MODULE_LICENSE("GPL");
diff --git a/drivers/hwmon/ams/ams-i2c.c b/drivers/hwmon/ams/ams-i2c.c
index 2cbf8a6506c7..abeecd27b484 100644
--- a/drivers/hwmon/ams/ams-i2c.c
+++ b/drivers/hwmon/ams/ams-i2c.c
@@ -238,6 +238,8 @@ static int ams_i2c_probe(struct i2c_client *client,
238static int ams_i2c_remove(struct i2c_client *client) 238static int ams_i2c_remove(struct i2c_client *client)
239{ 239{
240 if (ams_info.has_device) { 240 if (ams_info.has_device) {
241 ams_sensor_detach();
242
241 /* Disable interrupts */ 243 /* Disable interrupts */
242 ams_i2c_set_irq(AMS_IRQ_ALL, 0); 244 ams_i2c_set_irq(AMS_IRQ_ALL, 0);
243 245
diff --git a/drivers/hwmon/ams/ams-pmu.c b/drivers/hwmon/ams/ams-pmu.c
index fb18b3d3162b..4f61b3ee1b08 100644
--- a/drivers/hwmon/ams/ams-pmu.c
+++ b/drivers/hwmon/ams/ams-pmu.c
@@ -133,6 +133,8 @@ static void ams_pmu_get_xyz(s8 *x, s8 *y, s8 *z)
133 133
134static void ams_pmu_exit(void) 134static void ams_pmu_exit(void)
135{ 135{
136 ams_sensor_detach();
137
136 /* Disable interrupts */ 138 /* Disable interrupts */
137 ams_pmu_set_irq(AMS_IRQ_ALL, 0); 139 ams_pmu_set_irq(AMS_IRQ_ALL, 0);
138 140
diff --git a/drivers/hwmon/ams/ams.h b/drivers/hwmon/ams/ams.h
index 5ed387b0bd9a..b28d7e27a031 100644
--- a/drivers/hwmon/ams/ams.h
+++ b/drivers/hwmon/ams/ams.h
@@ -61,6 +61,7 @@ extern struct ams ams_info;
61 61
62extern void ams_sensors(s8 *x, s8 *y, s8 *z); 62extern void ams_sensors(s8 *x, s8 *y, s8 *z);
63extern int ams_sensor_attach(void); 63extern int ams_sensor_attach(void);
64extern void ams_sensor_detach(void);
64 65
65extern int ams_pmu_init(struct device_node *np); 66extern int ams_pmu_init(struct device_node *np);
66extern int ams_i2c_init(struct device_node *np); 67extern int ams_i2c_init(struct device_node *np);
diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
index 7ea6a8f66056..f085c18d2905 100644
--- a/drivers/hwmon/applesmc.c
+++ b/drivers/hwmon/applesmc.c
@@ -142,6 +142,12 @@ static const char *temperature_sensors_sets[][41] = {
142 "TM1S", "TM2P", "TM2S", "TM3S", "TM8P", "TM8S", "TM9P", "TM9S", 142 "TM1S", "TM2P", "TM2S", "TM3S", "TM8P", "TM8S", "TM9P", "TM9S",
143 "TN0C", "TN0D", "TN0H", "TS0C", "Tp0C", "Tp1C", "Tv0S", "Tv1S", 143 "TN0C", "TN0D", "TN0H", "TS0C", "Tp0C", "Tp1C", "Tv0S", "Tv1S",
144 NULL }, 144 NULL },
145/* Set 17: iMac 9,1 */
146 { "TA0P", "TC0D", "TC0H", "TC0P", "TG0D", "TG0H", "TH0P", "TL0P",
147 "TN0D", "TN0H", "TN0P", "TO0P", "Tm0P", "Tp0P", NULL },
148/* Set 18: MacBook Pro 2,2 */
149 { "TB0T", "TC0D", "TC0P", "TG0H", "TG0P", "TG0T", "TM0P", "TTF0",
150 "Th0H", "Th1H", "Tm0P", "Ts0P", NULL },
145}; 151};
146 152
147/* List of keys used to read/write fan speeds */ 153/* List of keys used to read/write fan speeds */
@@ -189,6 +195,9 @@ static unsigned int applesmc_accelerometer;
189/* Indicates whether this computer has light sensors and keyboard backlight. */ 195/* Indicates whether this computer has light sensors and keyboard backlight. */
190static unsigned int applesmc_light; 196static unsigned int applesmc_light;
191 197
198/* The number of fans handled by the driver */
199static unsigned int fans_handled;
200
192/* Indicates which temperature sensors set to use. */ 201/* Indicates which temperature sensors set to use. */
193static unsigned int applesmc_temperature_set; 202static unsigned int applesmc_temperature_set;
194 203
@@ -518,7 +527,7 @@ static int applesmc_pm_restore(struct device *dev)
518 return applesmc_pm_resume(dev); 527 return applesmc_pm_resume(dev);
519} 528}
520 529
521static struct dev_pm_ops applesmc_pm_ops = { 530static const struct dev_pm_ops applesmc_pm_ops = {
522 .resume = applesmc_pm_resume, 531 .resume = applesmc_pm_resume,
523 .restore = applesmc_pm_restore, 532 .restore = applesmc_pm_restore,
524}; 533};
@@ -1350,6 +1359,10 @@ static __initdata struct dmi_match_data applesmc_dmi_data[] = {
1350 { .accelerometer = 1, .light = 1, .temperature_set = 15 }, 1359 { .accelerometer = 1, .light = 1, .temperature_set = 15 },
1351/* MacPro3,1: temperature set 16 */ 1360/* MacPro3,1: temperature set 16 */
1352 { .accelerometer = 0, .light = 0, .temperature_set = 16 }, 1361 { .accelerometer = 0, .light = 0, .temperature_set = 16 },
1362/* iMac 9,1: light sensor only, temperature set 17 */
1363 { .accelerometer = 0, .light = 0, .temperature_set = 17 },
1364/* MacBook Pro 2,2: accelerometer, backlight and temperature set 18 */
1365 { .accelerometer = 1, .light = 1, .temperature_set = 18 },
1353}; 1366};
1354 1367
1355/* Note that DMI_MATCH(...,"MacBook") will match "MacBookPro1,1". 1368/* Note that DMI_MATCH(...,"MacBook") will match "MacBookPro1,1".
@@ -1375,6 +1388,10 @@ static __initdata struct dmi_system_id applesmc_whitelist[] = {
1375 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1388 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1376 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro3") }, 1389 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro3") },
1377 &applesmc_dmi_data[9]}, 1390 &applesmc_dmi_data[9]},
1391 { applesmc_dmi_match, "Apple MacBook Pro 2,2", {
1392 DMI_MATCH(DMI_BOARD_VENDOR, "Apple Computer, Inc."),
1393 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro2,2") },
1394 &applesmc_dmi_data[18]},
1378 { applesmc_dmi_match, "Apple MacBook Pro", { 1395 { applesmc_dmi_match, "Apple MacBook Pro", {
1379 DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), 1396 DMI_MATCH(DMI_BOARD_VENDOR,"Apple"),
1380 DMI_MATCH(DMI_PRODUCT_NAME,"MacBookPro") }, 1397 DMI_MATCH(DMI_PRODUCT_NAME,"MacBookPro") },
@@ -1415,6 +1432,10 @@ static __initdata struct dmi_system_id applesmc_whitelist[] = {
1415 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1432 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1416 DMI_MATCH(DMI_PRODUCT_NAME, "MacPro") }, 1433 DMI_MATCH(DMI_PRODUCT_NAME, "MacPro") },
1417 &applesmc_dmi_data[4]}, 1434 &applesmc_dmi_data[4]},
1435 { applesmc_dmi_match, "Apple iMac 9,1", {
1436 DMI_MATCH(DMI_BOARD_VENDOR, "Apple Inc."),
1437 DMI_MATCH(DMI_PRODUCT_NAME, "iMac9,1") },
1438 &applesmc_dmi_data[17]},
1418 { applesmc_dmi_match, "Apple iMac 8", { 1439 { applesmc_dmi_match, "Apple iMac 8", {
1419 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1440 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1420 DMI_MATCH(DMI_PRODUCT_NAME, "iMac8") }, 1441 DMI_MATCH(DMI_PRODUCT_NAME, "iMac8") },
@@ -1474,39 +1495,24 @@ static int __init applesmc_init(void)
1474 1495
1475 /* create fan files */ 1496 /* create fan files */
1476 count = applesmc_get_fan_count(); 1497 count = applesmc_get_fan_count();
1477 if (count < 0) { 1498 if (count < 0)
1478 printk(KERN_ERR "applesmc: Cannot get the number of fans.\n"); 1499 printk(KERN_ERR "applesmc: Cannot get the number of fans.\n");
1479 } else { 1500 else
1480 printk(KERN_INFO "applesmc: %d fans found.\n", count); 1501 printk(KERN_INFO "applesmc: %d fans found.\n", count);
1481 1502
1482 switch (count) { 1503 if (count > 4) {
1483 default: 1504 count = 4;
1484 printk(KERN_WARNING "applesmc: More than 4 fans found," 1505 printk(KERN_WARNING "applesmc: More than 4 fans found,"
1485 " but at most 4 fans are supported" 1506 " but at most 4 fans are supported"
1486 " by the driver.\n"); 1507 " by the driver.\n");
1487 case 4: 1508 }
1488 ret = sysfs_create_group(&pdev->dev.kobj, 1509
1489 &fan_attribute_groups[3]); 1510 while (fans_handled < count) {
1490 if (ret) 1511 ret = sysfs_create_group(&pdev->dev.kobj,
1491 goto out_key_enumeration; 1512 &fan_attribute_groups[fans_handled]);
1492 case 3: 1513 if (ret)
1493 ret = sysfs_create_group(&pdev->dev.kobj, 1514 goto out_fans;
1494 &fan_attribute_groups[2]); 1515 fans_handled++;
1495 if (ret)
1496 goto out_key_enumeration;
1497 case 2:
1498 ret = sysfs_create_group(&pdev->dev.kobj,
1499 &fan_attribute_groups[1]);
1500 if (ret)
1501 goto out_key_enumeration;
1502 case 1:
1503 ret = sysfs_create_group(&pdev->dev.kobj,
1504 &fan_attribute_groups[0]);
1505 if (ret)
1506 goto out_fan_1;
1507 case 0:
1508 ;
1509 }
1510 } 1516 }
1511 1517
1512 for (i = 0; 1518 for (i = 0;
@@ -1575,10 +1581,10 @@ out_accelerometer:
1575 applesmc_release_accelerometer(); 1581 applesmc_release_accelerometer();
1576out_temperature: 1582out_temperature:
1577 sysfs_remove_group(&pdev->dev.kobj, &temperature_attributes_group); 1583 sysfs_remove_group(&pdev->dev.kobj, &temperature_attributes_group);
1578 sysfs_remove_group(&pdev->dev.kobj, &fan_attribute_groups[0]); 1584out_fans:
1579out_fan_1: 1585 while (fans_handled)
1580 sysfs_remove_group(&pdev->dev.kobj, &fan_attribute_groups[1]); 1586 sysfs_remove_group(&pdev->dev.kobj,
1581out_key_enumeration: 1587 &fan_attribute_groups[--fans_handled]);
1582 sysfs_remove_group(&pdev->dev.kobj, &key_enumeration_group); 1588 sysfs_remove_group(&pdev->dev.kobj, &key_enumeration_group);
1583out_name: 1589out_name:
1584 sysfs_remove_file(&pdev->dev.kobj, &dev_attr_name.attr); 1590 sysfs_remove_file(&pdev->dev.kobj, &dev_attr_name.attr);
@@ -1604,8 +1610,9 @@ static void __exit applesmc_exit(void)
1604 if (applesmc_accelerometer) 1610 if (applesmc_accelerometer)
1605 applesmc_release_accelerometer(); 1611 applesmc_release_accelerometer();
1606 sysfs_remove_group(&pdev->dev.kobj, &temperature_attributes_group); 1612 sysfs_remove_group(&pdev->dev.kobj, &temperature_attributes_group);
1607 sysfs_remove_group(&pdev->dev.kobj, &fan_attribute_groups[0]); 1613 while (fans_handled)
1608 sysfs_remove_group(&pdev->dev.kobj, &fan_attribute_groups[1]); 1614 sysfs_remove_group(&pdev->dev.kobj,
1615 &fan_attribute_groups[--fans_handled]);
1609 sysfs_remove_group(&pdev->dev.kobj, &key_enumeration_group); 1616 sysfs_remove_group(&pdev->dev.kobj, &key_enumeration_group);
1610 sysfs_remove_file(&pdev->dev.kobj, &dev_attr_name.attr); 1617 sysfs_remove_file(&pdev->dev.kobj, &dev_attr_name.attr);
1611 platform_device_unregister(pdev); 1618 platform_device_unregister(pdev);
diff --git a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c
index 8acf82977e7b..7dada559b3a1 100644
--- a/drivers/hwmon/asb100.c
+++ b/drivers/hwmon/asb100.c
@@ -51,9 +51,6 @@
51/* I2C addresses to scan */ 51/* I2C addresses to scan */
52static const unsigned short normal_i2c[] = { 0x2d, I2C_CLIENT_END }; 52static const unsigned short normal_i2c[] = { 0x2d, I2C_CLIENT_END };
53 53
54/* Insmod parameters */
55I2C_CLIENT_INSMOD_1(asb100);
56
57static unsigned short force_subclients[4]; 54static unsigned short force_subclients[4];
58module_param_array(force_subclients, short, NULL, 0); 55module_param_array(force_subclients, short, NULL, 0);
59MODULE_PARM_DESC(force_subclients, "List of subclient addresses: " 56MODULE_PARM_DESC(force_subclients, "List of subclient addresses: "
@@ -209,14 +206,14 @@ static void asb100_write_value(struct i2c_client *client, u16 reg, u16 val);
209 206
210static int asb100_probe(struct i2c_client *client, 207static int asb100_probe(struct i2c_client *client,
211 const struct i2c_device_id *id); 208 const struct i2c_device_id *id);
212static int asb100_detect(struct i2c_client *client, int kind, 209static int asb100_detect(struct i2c_client *client,
213 struct i2c_board_info *info); 210 struct i2c_board_info *info);
214static int asb100_remove(struct i2c_client *client); 211static int asb100_remove(struct i2c_client *client);
215static struct asb100_data *asb100_update_device(struct device *dev); 212static struct asb100_data *asb100_update_device(struct device *dev);
216static void asb100_init_client(struct i2c_client *client); 213static void asb100_init_client(struct i2c_client *client);
217 214
218static const struct i2c_device_id asb100_id[] = { 215static const struct i2c_device_id asb100_id[] = {
219 { "asb100", asb100 }, 216 { "asb100", 0 },
220 { } 217 { }
221}; 218};
222MODULE_DEVICE_TABLE(i2c, asb100_id); 219MODULE_DEVICE_TABLE(i2c, asb100_id);
@@ -230,7 +227,7 @@ static struct i2c_driver asb100_driver = {
230 .remove = asb100_remove, 227 .remove = asb100_remove,
231 .id_table = asb100_id, 228 .id_table = asb100_id,
232 .detect = asb100_detect, 229 .detect = asb100_detect,
233 .address_data = &addr_data, 230 .address_list = normal_i2c,
234}; 231};
235 232
236/* 7 Voltages */ 233/* 7 Voltages */
@@ -697,10 +694,11 @@ ERROR_SC_2:
697} 694}
698 695
699/* Return 0 if detection is successful, -ENODEV otherwise */ 696/* Return 0 if detection is successful, -ENODEV otherwise */
700static int asb100_detect(struct i2c_client *client, int kind, 697static int asb100_detect(struct i2c_client *client,
701 struct i2c_board_info *info) 698 struct i2c_board_info *info)
702{ 699{
703 struct i2c_adapter *adapter = client->adapter; 700 struct i2c_adapter *adapter = client->adapter;
701 int val1, val2;
704 702
705 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 703 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
706 pr_debug("asb100.o: detect failed, " 704 pr_debug("asb100.o: detect failed, "
@@ -708,50 +706,30 @@ static int asb100_detect(struct i2c_client *client, int kind,
708 return -ENODEV; 706 return -ENODEV;
709 } 707 }
710 708
711 /* The chip may be stuck in some other bank than bank 0. This may 709 val1 = i2c_smbus_read_byte_data(client, ASB100_REG_BANK);
712 make reading other information impossible. Specify a force=... or 710 val2 = i2c_smbus_read_byte_data(client, ASB100_REG_CHIPMAN);
713 force_*=... parameter, and the chip will be reset to the right
714 bank. */
715 if (kind < 0) {
716
717 int val1 = i2c_smbus_read_byte_data(client, ASB100_REG_BANK);
718 int val2 = i2c_smbus_read_byte_data(client, ASB100_REG_CHIPMAN);
719
720 /* If we're in bank 0 */
721 if ((!(val1 & 0x07)) &&
722 /* Check for ASB100 ID (low byte) */
723 (((!(val1 & 0x80)) && (val2 != 0x94)) ||
724 /* Check for ASB100 ID (high byte ) */
725 ((val1 & 0x80) && (val2 != 0x06)))) {
726 pr_debug("asb100.o: detect failed, "
727 "bad chip id 0x%02x!\n", val2);
728 return -ENODEV;
729 }
730 711
731 } /* kind < 0 */ 712 /* If we're in bank 0 */
713 if ((!(val1 & 0x07)) &&
714 /* Check for ASB100 ID (low byte) */
715 (((!(val1 & 0x80)) && (val2 != 0x94)) ||
716 /* Check for ASB100 ID (high byte ) */
717 ((val1 & 0x80) && (val2 != 0x06)))) {
718 pr_debug("asb100: detect failed, bad chip id 0x%02x!\n", val2);
719 return -ENODEV;
720 }
732 721
733 /* We have either had a force parameter, or we have already detected 722 /* Put it now into bank 0 and Vendor ID High Byte */
734 Winbond. Put it now into bank 0 and Vendor ID High Byte */
735 i2c_smbus_write_byte_data(client, ASB100_REG_BANK, 723 i2c_smbus_write_byte_data(client, ASB100_REG_BANK,
736 (i2c_smbus_read_byte_data(client, ASB100_REG_BANK) & 0x78) 724 (i2c_smbus_read_byte_data(client, ASB100_REG_BANK) & 0x78)
737 | 0x80); 725 | 0x80);
738 726
739 /* Determine the chip type. */ 727 /* Determine the chip type. */
740 if (kind <= 0) { 728 val1 = i2c_smbus_read_byte_data(client, ASB100_REG_WCHIPID);
741 int val1 = i2c_smbus_read_byte_data(client, ASB100_REG_WCHIPID); 729 val2 = i2c_smbus_read_byte_data(client, ASB100_REG_CHIPMAN);
742 int val2 = i2c_smbus_read_byte_data(client, ASB100_REG_CHIPMAN); 730
743 731 if (val1 != 0x31 || val2 != 0x06)
744 if ((val1 == 0x31) && (val2 == 0x06)) 732 return -ENODEV;
745 kind = asb100;
746 else {
747 if (kind == 0)
748 dev_warn(&adapter->dev, "ignoring "
749 "'force' parameter for unknown chip "
750 "at adapter %d, address 0x%02x.\n",
751 i2c_adapter_id(adapter), client->addr);
752 return -ENODEV;
753 }
754 }
755 733
756 strlcpy(info->type, "asb100", I2C_NAME_SIZE); 734 strlcpy(info->type, "asb100", I2C_NAME_SIZE);
757 735
diff --git a/drivers/hwmon/asc7621.c b/drivers/hwmon/asc7621.c
new file mode 100644
index 000000000000..0f388adc6187
--- /dev/null
+++ b/drivers/hwmon/asc7621.c
@@ -0,0 +1,1254 @@
1/*
2 * asc7621.c - Part of lm_sensors, Linux kernel modules for hardware monitoring
3 * Copyright (c) 2007, 2010 George Joseph <george.joseph@fairview5.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20#include <linux/module.h>
21#include <linux/init.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/mutex.h>
29
30/* Addresses to scan */
31static unsigned short normal_i2c[] = {
32 0x2c, 0x2d, 0x2e, I2C_CLIENT_END
33};
34
35enum asc7621_type {
36 asc7621,
37 asc7621a
38};
39
40#define INTERVAL_HIGH (HZ + HZ / 2)
41#define INTERVAL_LOW (1 * 60 * HZ)
42#define PRI_NONE 0
43#define PRI_LOW 1
44#define PRI_HIGH 2
45#define FIRST_CHIP asc7621
46#define LAST_CHIP asc7621a
47
48struct asc7621_chip {
49 char *name;
50 enum asc7621_type chip_type;
51 u8 company_reg;
52 u8 company_id;
53 u8 verstep_reg;
54 u8 verstep_id;
55 unsigned short *addresses;
56};
57
58static struct asc7621_chip asc7621_chips[] = {
59 {
60 .name = "asc7621",
61 .chip_type = asc7621,
62 .company_reg = 0x3e,
63 .company_id = 0x61,
64 .verstep_reg = 0x3f,
65 .verstep_id = 0x6c,
66 .addresses = normal_i2c,
67 },
68 {
69 .name = "asc7621a",
70 .chip_type = asc7621a,
71 .company_reg = 0x3e,
72 .company_id = 0x61,
73 .verstep_reg = 0x3f,
74 .verstep_id = 0x6d,
75 .addresses = normal_i2c,
76 },
77};
78
79/*
80 * Defines the highest register to be used, not the count.
81 * The actual count will probably be smaller because of gaps
82 * in the implementation (unused register locations).
83 * This define will safely set the array size of both the parameter
84 * and data arrays.
85 * This comes from the data sheet register description table.
86 */
87#define LAST_REGISTER 0xff
88
89struct asc7621_data {
90 struct i2c_client client;
91 struct device *class_dev;
92 struct mutex update_lock;
93 int valid; /* !=0 if following fields are valid */
94 unsigned long last_high_reading; /* In jiffies */
95 unsigned long last_low_reading; /* In jiffies */
96 /*
97 * Registers we care about occupy the corresponding index
98 * in the array. Registers we don't care about are left
99 * at 0.
100 */
101 u8 reg[LAST_REGISTER + 1];
102};
103
104/*
105 * Macro to get the parent asc7621_param structure
106 * from a sensor_device_attribute passed into the
107 * show/store functions.
108 */
109#define to_asc7621_param(_sda) \
110 container_of(_sda, struct asc7621_param, sda)
111
112/*
113 * Each parameter to be retrieved needs an asc7621_param structure
114 * allocated. It contains the sensor_device_attribute structure
115 * and the control info needed to retrieve the value from the register map.
116 */
117struct asc7621_param {
118 struct sensor_device_attribute sda;
119 u8 priority;
120 u8 msb[3];
121 u8 lsb[3];
122 u8 mask[3];
123 u8 shift[3];
124};
125
126/*
127 * This is the map that ultimately indicates whether we'll be
128 * retrieving a register value or not, and at what frequency.
129 */
130static u8 asc7621_register_priorities[255];
131
132static struct asc7621_data *asc7621_update_device(struct device *dev);
133
134static inline u8 read_byte(struct i2c_client *client, u8 reg)
135{
136 int res = i2c_smbus_read_byte_data(client, reg);
137 if (res < 0) {
138 dev_err(&client->dev,
139 "Unable to read from register 0x%02x.\n", reg);
140 return 0;
141 };
142 return res & 0xff;
143}
144
145static inline int write_byte(struct i2c_client *client, u8 reg, u8 data)
146{
147 int res = i2c_smbus_write_byte_data(client, reg, data);
148 if (res < 0) {
149 dev_err(&client->dev,
150 "Unable to write value 0x%02x to register 0x%02x.\n",
151 data, reg);
152 };
153 return res;
154}
155
156/*
157 * Data Handlers
158 * Each function handles the formatting, storage
159 * and retrieval of like parameters.
160 */
161
162#define SETUP_SHOW_data_param(d, a) \
163 struct sensor_device_attribute *sda = to_sensor_dev_attr(a); \
164 struct asc7621_data *data = asc7621_update_device(d); \
165 struct asc7621_param *param = to_asc7621_param(sda)
166
167#define SETUP_STORE_data_param(d, a) \
168 struct sensor_device_attribute *sda = to_sensor_dev_attr(a); \
169 struct i2c_client *client = to_i2c_client(d); \
170 struct asc7621_data *data = i2c_get_clientdata(client); \
171 struct asc7621_param *param = to_asc7621_param(sda)
172
173/*
174 * u8 is just what it sounds like...an unsigned byte with no
175 * special formatting.
176 */
177static ssize_t show_u8(struct device *dev, struct device_attribute *attr,
178 char *buf)
179{
180 SETUP_SHOW_data_param(dev, attr);
181
182 return sprintf(buf, "%u\n", data->reg[param->msb[0]]);
183}
184
185static ssize_t store_u8(struct device *dev, struct device_attribute *attr,
186 const char *buf, size_t count)
187{
188 SETUP_STORE_data_param(dev, attr);
189 long reqval;
190
191 if (strict_strtol(buf, 10, &reqval))
192 return -EINVAL;
193
194 reqval = SENSORS_LIMIT(reqval, 0, 255);
195
196 mutex_lock(&data->update_lock);
197 data->reg[param->msb[0]] = reqval;
198 write_byte(client, param->msb[0], reqval);
199 mutex_unlock(&data->update_lock);
200 return count;
201}
202
203/*
204 * Many of the config values occupy only a few bits of a register.
205 */
206static ssize_t show_bitmask(struct device *dev,
207 struct device_attribute *attr, char *buf)
208{
209 SETUP_SHOW_data_param(dev, attr);
210
211 return sprintf(buf, "%u\n",
212 (data->reg[param->msb[0]] >> param->
213 shift[0]) & param->mask[0]);
214}
215
216static ssize_t store_bitmask(struct device *dev,
217 struct device_attribute *attr,
218 const char *buf, size_t count)
219{
220 SETUP_STORE_data_param(dev, attr);
221 long reqval;
222 u8 currval;
223
224 if (strict_strtol(buf, 10, &reqval))
225 return -EINVAL;
226
227 reqval = SENSORS_LIMIT(reqval, 0, param->mask[0]);
228
229 reqval = (reqval & param->mask[0]) << param->shift[0];
230
231 mutex_lock(&data->update_lock);
232 currval = read_byte(client, param->msb[0]);
233 reqval |= (currval & ~(param->mask[0] << param->shift[0]));
234 data->reg[param->msb[0]] = reqval;
235 write_byte(client, param->msb[0], reqval);
236 mutex_unlock(&data->update_lock);
237 return count;
238}
239
240/*
241 * 16 bit fan rpm values
242 * reported by the device as the number of 11.111us periods (90khz)
243 * between full fan rotations. Therefore...
244 * RPM = (90000 * 60) / register value
245 */
246static ssize_t show_fan16(struct device *dev,
247 struct device_attribute *attr, char *buf)
248{
249 SETUP_SHOW_data_param(dev, attr);
250 u16 regval;
251
252 mutex_lock(&data->update_lock);
253 regval = (data->reg[param->msb[0]] << 8) | data->reg[param->lsb[0]];
254 mutex_unlock(&data->update_lock);
255
256 return sprintf(buf, "%u\n",
257 (regval == 0 ? -1 : (regval) ==
258 0xffff ? 0 : 5400000 / regval));
259}
260
261static ssize_t store_fan16(struct device *dev,
262 struct device_attribute *attr, const char *buf,
263 size_t count)
264{
265 SETUP_STORE_data_param(dev, attr);
266 long reqval;
267
268 if (strict_strtol(buf, 10, &reqval))
269 return -EINVAL;
270
271 /* If a minimum RPM of zero is requested, then we set the register to
272 0xffff. This value allows the fan to be stopped completely without
273 generating an alarm. */
274 reqval =
275 (reqval <= 0 ? 0xffff : SENSORS_LIMIT(5400000 / reqval, 0, 0xfffe));
276
277 mutex_lock(&data->update_lock);
278 data->reg[param->msb[0]] = (reqval >> 8) & 0xff;
279 data->reg[param->lsb[0]] = reqval & 0xff;
280 write_byte(client, param->msb[0], data->reg[param->msb[0]]);
281 write_byte(client, param->lsb[0], data->reg[param->lsb[0]]);
282 mutex_unlock(&data->update_lock);
283
284 return count;
285}
286
287/*
288 * Voltages are scaled in the device so that the nominal voltage
289 * is 3/4ths of the 0-255 range (i.e. 192).
290 * If all voltages are 'normal' then all voltage registers will
291 * read 0xC0.
292 *
293 * The data sheet provides us with the 3/4 scale value for each voltage
294 * which is stored in in_scaling. The sda->index parameter value provides
295 * the index into in_scaling.
296 *
297 * NOTE: The chip expects the first 2 inputs be 2.5 and 2.25 volts
298 * respectively. That doesn't mean that's what the motherboard provides. :)
299 */
300
301static int asc7621_in_scaling[] = {
302 2500, 2250, 3300, 5000, 12000
303};
304
305static ssize_t show_in10(struct device *dev, struct device_attribute *attr,
306 char *buf)
307{
308 SETUP_SHOW_data_param(dev, attr);
309 u16 regval;
310 u8 nr = sda->index;
311
312 mutex_lock(&data->update_lock);
313 regval = (data->reg[param->msb[0]] << 8) | (data->reg[param->lsb[0]]);
314 mutex_unlock(&data->update_lock);
315
316 /* The LSB value is a 2-bit scaling of the MSB's LSbit value. */
317 regval = (regval >> 6) * asc7621_in_scaling[nr] / (0xc0 << 2);
318
319 return sprintf(buf, "%u\n", regval);
320}
321
322/* 8 bit voltage values (the mins and maxs) */
323static ssize_t show_in8(struct device *dev, struct device_attribute *attr,
324 char *buf)
325{
326 SETUP_SHOW_data_param(dev, attr);
327 u8 nr = sda->index;
328
329 return sprintf(buf, "%u\n",
330 ((data->reg[param->msb[0]] *
331 asc7621_in_scaling[nr]) / 0xc0));
332}
333
334static ssize_t store_in8(struct device *dev, struct device_attribute *attr,
335 const char *buf, size_t count)
336{
337 SETUP_STORE_data_param(dev, attr);
338 long reqval;
339 u8 nr = sda->index;
340
341 if (strict_strtol(buf, 10, &reqval))
342 return -EINVAL;
343
344 reqval = SENSORS_LIMIT(reqval, 0, 0xffff);
345
346 reqval = reqval * 0xc0 / asc7621_in_scaling[nr];
347
348 reqval = SENSORS_LIMIT(reqval, 0, 0xff);
349
350 mutex_lock(&data->update_lock);
351 data->reg[param->msb[0]] = reqval;
352 write_byte(client, param->msb[0], reqval);
353 mutex_unlock(&data->update_lock);
354
355 return count;
356}
357
358static ssize_t show_temp8(struct device *dev,
359 struct device_attribute *attr, char *buf)
360{
361 SETUP_SHOW_data_param(dev, attr);
362
363 return sprintf(buf, "%d\n", ((s8) data->reg[param->msb[0]]) * 1000);
364}
365
366static ssize_t store_temp8(struct device *dev,
367 struct device_attribute *attr, const char *buf,
368 size_t count)
369{
370 SETUP_STORE_data_param(dev, attr);
371 long reqval;
372 s8 temp;
373
374 if (strict_strtol(buf, 10, &reqval))
375 return -EINVAL;
376
377 reqval = SENSORS_LIMIT(reqval, -127000, 127000);
378
379 temp = reqval / 1000;
380
381 mutex_lock(&data->update_lock);
382 data->reg[param->msb[0]] = temp;
383 write_byte(client, param->msb[0], temp);
384 mutex_unlock(&data->update_lock);
385 return count;
386}
387
388/*
389 * Temperatures that occupy 2 bytes always have the whole
390 * number of degrees in the MSB with some part of the LSB
391 * indicating fractional degrees.
392 */
393
394/* mmmmmmmm.llxxxxxx */
395static ssize_t show_temp10(struct device *dev,
396 struct device_attribute *attr, char *buf)
397{
398 SETUP_SHOW_data_param(dev, attr);
399 u8 msb, lsb;
400 int temp;
401
402 mutex_lock(&data->update_lock);
403 msb = data->reg[param->msb[0]];
404 lsb = (data->reg[param->lsb[0]] >> 6) & 0x03;
405 temp = (((s8) msb) * 1000) + (lsb * 250);
406 mutex_unlock(&data->update_lock);
407
408 return sprintf(buf, "%d\n", temp);
409}
410
411/* mmmmmm.ll */
412static ssize_t show_temp62(struct device *dev,
413 struct device_attribute *attr, char *buf)
414{
415 SETUP_SHOW_data_param(dev, attr);
416 u8 regval = data->reg[param->msb[0]];
417 int temp = ((s8) (regval & 0xfc) * 1000) + ((regval & 0x03) * 250);
418
419 return sprintf(buf, "%d\n", temp);
420}
421
422static ssize_t store_temp62(struct device *dev,
423 struct device_attribute *attr, const char *buf,
424 size_t count)
425{
426 SETUP_STORE_data_param(dev, attr);
427 long reqval, i, f;
428 s8 temp;
429
430 if (strict_strtol(buf, 10, &reqval))
431 return -EINVAL;
432
433 reqval = SENSORS_LIMIT(reqval, -32000, 31750);
434 i = reqval / 1000;
435 f = reqval - (i * 1000);
436 temp = i << 2;
437 temp |= f / 250;
438
439 mutex_lock(&data->update_lock);
440 data->reg[param->msb[0]] = temp;
441 write_byte(client, param->msb[0], temp);
442 mutex_unlock(&data->update_lock);
443 return count;
444}
445
446/*
447 * The aSC7621 doesn't provide an "auto_point2". Instead, you
448 * specify the auto_point1 and a range. To keep with the sysfs
449 * hwmon specs, we synthesize the auto_point_2 from them.
450 */
451
452static u32 asc7621_range_map[] = {
453 2000, 2500, 3330, 4000, 5000, 6670, 8000, 10000,
454 13330, 16000, 20000, 26670, 32000, 40000, 53330, 80000,
455};
456
457static ssize_t show_ap2_temp(struct device *dev,
458 struct device_attribute *attr, char *buf)
459{
460 SETUP_SHOW_data_param(dev, attr);
461 long auto_point1;
462 u8 regval;
463 int temp;
464
465 mutex_lock(&data->update_lock);
466 auto_point1 = ((s8) data->reg[param->msb[1]]) * 1000;
467 regval =
468 ((data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0]);
469 temp = auto_point1 + asc7621_range_map[SENSORS_LIMIT(regval, 0, 15)];
470 mutex_unlock(&data->update_lock);
471
472 return sprintf(buf, "%d\n", temp);
473
474}
475
476static ssize_t store_ap2_temp(struct device *dev,
477 struct device_attribute *attr,
478 const char *buf, size_t count)
479{
480 SETUP_STORE_data_param(dev, attr);
481 long reqval, auto_point1;
482 int i;
483 u8 currval, newval = 0;
484
485 if (strict_strtol(buf, 10, &reqval))
486 return -EINVAL;
487
488 mutex_lock(&data->update_lock);
489 auto_point1 = data->reg[param->msb[1]] * 1000;
490 reqval = SENSORS_LIMIT(reqval, auto_point1 + 2000, auto_point1 + 80000);
491
492 for (i = ARRAY_SIZE(asc7621_range_map) - 1; i >= 0; i--) {
493 if (reqval >= auto_point1 + asc7621_range_map[i]) {
494 newval = i;
495 break;
496 }
497 }
498
499 newval = (newval & param->mask[0]) << param->shift[0];
500 currval = read_byte(client, param->msb[0]);
501 newval |= (currval & ~(param->mask[0] << param->shift[0]));
502 data->reg[param->msb[0]] = newval;
503 write_byte(client, param->msb[0], newval);
504 mutex_unlock(&data->update_lock);
505 return count;
506}
507
508static ssize_t show_pwm_ac(struct device *dev,
509 struct device_attribute *attr, char *buf)
510{
511 SETUP_SHOW_data_param(dev, attr);
512 u8 config, altbit, regval;
513 u8 map[] = {
514 0x01, 0x02, 0x04, 0x1f, 0x00, 0x06, 0x07, 0x10,
515 0x08, 0x0f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f
516 };
517
518 mutex_lock(&data->update_lock);
519 config = (data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0];
520 altbit = (data->reg[param->msb[1]] >> param->shift[1]) & param->mask[1];
521 regval = config | (altbit << 3);
522 mutex_unlock(&data->update_lock);
523
524 return sprintf(buf, "%u\n", map[SENSORS_LIMIT(regval, 0, 15)]);
525}
526
527static ssize_t store_pwm_ac(struct device *dev,
528 struct device_attribute *attr,
529 const char *buf, size_t count)
530{
531 SETUP_STORE_data_param(dev, attr);
532 unsigned long reqval;
533 u8 currval, config, altbit, newval;
534 u16 map[] = {
535 0x04, 0x00, 0x01, 0xff, 0x02, 0xff, 0x05, 0x06,
536 0x08, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f,
537 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
538 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03,
539 };
540
541 if (strict_strtoul(buf, 10, &reqval))
542 return -EINVAL;
543
544 if (reqval > 31)
545 return -EINVAL;
546
547 reqval = map[reqval];
548 if (reqval == 0xff)
549 return -EINVAL;
550
551 config = reqval & 0x07;
552 altbit = (reqval >> 3) & 0x01;
553
554 config = (config & param->mask[0]) << param->shift[0];
555 altbit = (altbit & param->mask[1]) << param->shift[1];
556
557 mutex_lock(&data->update_lock);
558 currval = read_byte(client, param->msb[0]);
559 newval = config | (currval & ~(param->mask[0] << param->shift[0]));
560 newval = altbit | (newval & ~(param->mask[1] << param->shift[1]));
561 data->reg[param->msb[0]] = newval;
562 write_byte(client, param->msb[0], newval);
563 mutex_unlock(&data->update_lock);
564 return count;
565}
566
567static ssize_t show_pwm_enable(struct device *dev,
568 struct device_attribute *attr, char *buf)
569{
570 SETUP_SHOW_data_param(dev, attr);
571 u8 config, altbit, minoff, val, newval;
572
573 mutex_lock(&data->update_lock);
574 config = (data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0];
575 altbit = (data->reg[param->msb[1]] >> param->shift[1]) & param->mask[1];
576 minoff = (data->reg[param->msb[2]] >> param->shift[2]) & param->mask[2];
577 mutex_unlock(&data->update_lock);
578
579 val = config | (altbit << 3);
580 newval = 0;
581
582 if (val == 3 || val >= 10)
583 newval = 255;
584 else if (val == 4)
585 newval = 0;
586 else if (val == 7)
587 newval = 1;
588 else if (minoff == 1)
589 newval = 2;
590 else
591 newval = 3;
592
593 return sprintf(buf, "%u\n", newval);
594}
595
596static ssize_t store_pwm_enable(struct device *dev,
597 struct device_attribute *attr,
598 const char *buf, size_t count)
599{
600 SETUP_STORE_data_param(dev, attr);
601 long reqval;
602 u8 currval, config, altbit, newval, minoff = 255;
603
604 if (strict_strtol(buf, 10, &reqval))
605 return -EINVAL;
606
607 switch (reqval) {
608 case 0:
609 newval = 0x04;
610 break;
611 case 1:
612 newval = 0x07;
613 break;
614 case 2:
615 newval = 0x00;
616 minoff = 1;
617 break;
618 case 3:
619 newval = 0x00;
620 minoff = 0;
621 break;
622 case 255:
623 newval = 0x03;
624 break;
625 default:
626 return -EINVAL;
627 }
628
629 config = newval & 0x07;
630 altbit = (newval >> 3) & 0x01;
631
632 mutex_lock(&data->update_lock);
633 config = (config & param->mask[0]) << param->shift[0];
634 altbit = (altbit & param->mask[1]) << param->shift[1];
635 currval = read_byte(client, param->msb[0]);
636 newval = config | (currval & ~(param->mask[0] << param->shift[0]));
637 newval = altbit | (newval & ~(param->mask[1] << param->shift[1]));
638 data->reg[param->msb[0]] = newval;
639 write_byte(client, param->msb[0], newval);
640 if (minoff < 255) {
641 minoff = (minoff & param->mask[2]) << param->shift[2];
642 currval = read_byte(client, param->msb[2]);
643 newval =
644 minoff | (currval & ~(param->mask[2] << param->shift[2]));
645 data->reg[param->msb[2]] = newval;
646 write_byte(client, param->msb[2], newval);
647 }
648 mutex_unlock(&data->update_lock);
649 return count;
650}
651
652static u32 asc7621_pwm_freq_map[] = {
653 10, 15, 23, 30, 38, 47, 62, 94,
654 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000
655};
656
657static ssize_t show_pwm_freq(struct device *dev,
658 struct device_attribute *attr, char *buf)
659{
660 SETUP_SHOW_data_param(dev, attr);
661 u8 regval =
662 (data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0];
663
664 regval = SENSORS_LIMIT(regval, 0, 15);
665
666 return sprintf(buf, "%u\n", asc7621_pwm_freq_map[regval]);
667}
668
669static ssize_t store_pwm_freq(struct device *dev,
670 struct device_attribute *attr,
671 const char *buf, size_t count)
672{
673 SETUP_STORE_data_param(dev, attr);
674 unsigned long reqval;
675 u8 currval, newval = 255;
676 int i;
677
678 if (strict_strtoul(buf, 10, &reqval))
679 return -EINVAL;
680
681 for (i = 0; i < ARRAY_SIZE(asc7621_pwm_freq_map); i++) {
682 if (reqval == asc7621_pwm_freq_map[i]) {
683 newval = i;
684 break;
685 }
686 }
687 if (newval == 255)
688 return -EINVAL;
689
690 newval = (newval & param->mask[0]) << param->shift[0];
691
692 mutex_lock(&data->update_lock);
693 currval = read_byte(client, param->msb[0]);
694 newval |= (currval & ~(param->mask[0] << param->shift[0]));
695 data->reg[param->msb[0]] = newval;
696 write_byte(client, param->msb[0], newval);
697 mutex_unlock(&data->update_lock);
698 return count;
699}
700
701static u32 asc7621_pwm_auto_spinup_map[] = {
702 0, 100, 250, 400, 700, 1000, 2000, 4000
703};
704
705static ssize_t show_pwm_ast(struct device *dev,
706 struct device_attribute *attr, char *buf)
707{
708 SETUP_SHOW_data_param(dev, attr);
709 u8 regval =
710 (data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0];
711
712 regval = SENSORS_LIMIT(regval, 0, 7);
713
714 return sprintf(buf, "%u\n", asc7621_pwm_auto_spinup_map[regval]);
715
716}
717
718static ssize_t store_pwm_ast(struct device *dev,
719 struct device_attribute *attr,
720 const char *buf, size_t count)
721{
722 SETUP_STORE_data_param(dev, attr);
723 long reqval;
724 u8 currval, newval = 255;
725 u32 i;
726
727 if (strict_strtol(buf, 10, &reqval))
728 return -EINVAL;
729
730 for (i = 0; i < ARRAY_SIZE(asc7621_pwm_auto_spinup_map); i++) {
731 if (reqval == asc7621_pwm_auto_spinup_map[i]) {
732 newval = i;
733 break;
734 }
735 }
736 if (newval == 255)
737 return -EINVAL;
738
739 newval = (newval & param->mask[0]) << param->shift[0];
740
741 mutex_lock(&data->update_lock);
742 currval = read_byte(client, param->msb[0]);
743 newval |= (currval & ~(param->mask[0] << param->shift[0]));
744 data->reg[param->msb[0]] = newval;
745 write_byte(client, param->msb[0], newval);
746 mutex_unlock(&data->update_lock);
747 return count;
748}
749
750static u32 asc7621_temp_smoothing_time_map[] = {
751 35000, 17600, 11800, 7000, 4400, 3000, 1600, 800
752};
753
754static ssize_t show_temp_st(struct device *dev,
755 struct device_attribute *attr, char *buf)
756{
757 SETUP_SHOW_data_param(dev, attr);
758 u8 regval =
759 (data->reg[param->msb[0]] >> param->shift[0]) & param->mask[0];
760 regval = SENSORS_LIMIT(regval, 0, 7);
761
762 return sprintf(buf, "%u\n", asc7621_temp_smoothing_time_map[regval]);
763}
764
765static ssize_t store_temp_st(struct device *dev,
766 struct device_attribute *attr,
767 const char *buf, size_t count)
768{
769 SETUP_STORE_data_param(dev, attr);
770 long reqval;
771 u8 currval, newval = 255;
772 u32 i;
773
774 if (strict_strtol(buf, 10, &reqval))
775 return -EINVAL;
776
777 for (i = 0; i < ARRAY_SIZE(asc7621_temp_smoothing_time_map); i++) {
778 if (reqval == asc7621_temp_smoothing_time_map[i]) {
779 newval = i;
780 break;
781 }
782 }
783
784 if (newval == 255)
785 return -EINVAL;
786
787 newval = (newval & param->mask[0]) << param->shift[0];
788
789 mutex_lock(&data->update_lock);
790 currval = read_byte(client, param->msb[0]);
791 newval |= (currval & ~(param->mask[0] << param->shift[0]));
792 data->reg[param->msb[0]] = newval;
793 write_byte(client, param->msb[0], newval);
794 mutex_unlock(&data->update_lock);
795 return count;
796}
797
798/*
799 * End of data handlers
800 *
801 * These defines do nothing more than make the table easier
802 * to read when wrapped at column 80.
803 */
804
805/*
806 * Creates a variable length array inititalizer.
807 * VAA(1,3,5,7) would produce {1,3,5,7}
808 */
809#define VAA(args...) {args}
810
811#define PREAD(name, n, pri, rm, rl, m, s, r) \
812 {.sda = SENSOR_ATTR(name, S_IRUGO, show_##r, NULL, n), \
813 .priority = pri, .msb[0] = rm, .lsb[0] = rl, .mask[0] = m, \
814 .shift[0] = s,}
815
816#define PWRITE(name, n, pri, rm, rl, m, s, r) \
817 {.sda = SENSOR_ATTR(name, S_IRUGO | S_IWUSR, show_##r, store_##r, n), \
818 .priority = pri, .msb[0] = rm, .lsb[0] = rl, .mask[0] = m, \
819 .shift[0] = s,}
820
821/*
822 * PWRITEM assumes that the initializers for the .msb, .lsb, .mask and .shift
823 * were created using the VAA macro.
824 */
825#define PWRITEM(name, n, pri, rm, rl, m, s, r) \
826 {.sda = SENSOR_ATTR(name, S_IRUGO | S_IWUSR, show_##r, store_##r, n), \
827 .priority = pri, .msb = rm, .lsb = rl, .mask = m, .shift = s,}
828
829static struct asc7621_param asc7621_params[] = {
830 PREAD(in0_input, 0, PRI_HIGH, 0x20, 0x13, 0, 0, in10),
831 PREAD(in1_input, 1, PRI_HIGH, 0x21, 0x18, 0, 0, in10),
832 PREAD(in2_input, 2, PRI_HIGH, 0x22, 0x11, 0, 0, in10),
833 PREAD(in3_input, 3, PRI_HIGH, 0x23, 0x12, 0, 0, in10),
834 PREAD(in4_input, 4, PRI_HIGH, 0x24, 0x14, 0, 0, in10),
835
836 PWRITE(in0_min, 0, PRI_LOW, 0x44, 0, 0, 0, in8),
837 PWRITE(in1_min, 1, PRI_LOW, 0x46, 0, 0, 0, in8),
838 PWRITE(in2_min, 2, PRI_LOW, 0x48, 0, 0, 0, in8),
839 PWRITE(in3_min, 3, PRI_LOW, 0x4a, 0, 0, 0, in8),
840 PWRITE(in4_min, 4, PRI_LOW, 0x4c, 0, 0, 0, in8),
841
842 PWRITE(in0_max, 0, PRI_LOW, 0x45, 0, 0, 0, in8),
843 PWRITE(in1_max, 1, PRI_LOW, 0x47, 0, 0, 0, in8),
844 PWRITE(in2_max, 2, PRI_LOW, 0x49, 0, 0, 0, in8),
845 PWRITE(in3_max, 3, PRI_LOW, 0x4b, 0, 0, 0, in8),
846 PWRITE(in4_max, 4, PRI_LOW, 0x4d, 0, 0, 0, in8),
847
848 PREAD(in0_alarm, 0, PRI_HIGH, 0x41, 0, 0x01, 0, bitmask),
849 PREAD(in1_alarm, 1, PRI_HIGH, 0x41, 0, 0x01, 1, bitmask),
850 PREAD(in2_alarm, 2, PRI_HIGH, 0x41, 0, 0x01, 2, bitmask),
851 PREAD(in3_alarm, 3, PRI_HIGH, 0x41, 0, 0x01, 3, bitmask),
852 PREAD(in4_alarm, 4, PRI_HIGH, 0x42, 0, 0x01, 0, bitmask),
853
854 PREAD(fan1_input, 0, PRI_HIGH, 0x29, 0x28, 0, 0, fan16),
855 PREAD(fan2_input, 1, PRI_HIGH, 0x2b, 0x2a, 0, 0, fan16),
856 PREAD(fan3_input, 2, PRI_HIGH, 0x2d, 0x2c, 0, 0, fan16),
857 PREAD(fan4_input, 3, PRI_HIGH, 0x2f, 0x2e, 0, 0, fan16),
858
859 PWRITE(fan1_min, 0, PRI_LOW, 0x55, 0x54, 0, 0, fan16),
860 PWRITE(fan2_min, 1, PRI_LOW, 0x57, 0x56, 0, 0, fan16),
861 PWRITE(fan3_min, 2, PRI_LOW, 0x59, 0x58, 0, 0, fan16),
862 PWRITE(fan4_min, 3, PRI_LOW, 0x5b, 0x5a, 0, 0, fan16),
863
864 PREAD(fan1_alarm, 0, PRI_HIGH, 0x42, 0, 0x01, 2, bitmask),
865 PREAD(fan2_alarm, 1, PRI_HIGH, 0x42, 0, 0x01, 3, bitmask),
866 PREAD(fan3_alarm, 2, PRI_HIGH, 0x42, 0, 0x01, 4, bitmask),
867 PREAD(fan4_alarm, 3, PRI_HIGH, 0x42, 0, 0x01, 5, bitmask),
868
869 PREAD(temp1_input, 0, PRI_HIGH, 0x25, 0x10, 0, 0, temp10),
870 PREAD(temp2_input, 1, PRI_HIGH, 0x26, 0x15, 0, 0, temp10),
871 PREAD(temp3_input, 2, PRI_HIGH, 0x27, 0x16, 0, 0, temp10),
872 PREAD(temp4_input, 3, PRI_HIGH, 0x33, 0x17, 0, 0, temp10),
873 PREAD(temp5_input, 4, PRI_HIGH, 0xf7, 0xf6, 0, 0, temp10),
874 PREAD(temp6_input, 5, PRI_HIGH, 0xf9, 0xf8, 0, 0, temp10),
875 PREAD(temp7_input, 6, PRI_HIGH, 0xfb, 0xfa, 0, 0, temp10),
876 PREAD(temp8_input, 7, PRI_HIGH, 0xfd, 0xfc, 0, 0, temp10),
877
878 PWRITE(temp1_min, 0, PRI_LOW, 0x4e, 0, 0, 0, temp8),
879 PWRITE(temp2_min, 1, PRI_LOW, 0x50, 0, 0, 0, temp8),
880 PWRITE(temp3_min, 2, PRI_LOW, 0x52, 0, 0, 0, temp8),
881 PWRITE(temp4_min, 3, PRI_LOW, 0x34, 0, 0, 0, temp8),
882
883 PWRITE(temp1_max, 0, PRI_LOW, 0x4f, 0, 0, 0, temp8),
884 PWRITE(temp2_max, 1, PRI_LOW, 0x51, 0, 0, 0, temp8),
885 PWRITE(temp3_max, 2, PRI_LOW, 0x53, 0, 0, 0, temp8),
886 PWRITE(temp4_max, 3, PRI_LOW, 0x35, 0, 0, 0, temp8),
887
888 PREAD(temp1_alarm, 0, PRI_HIGH, 0x41, 0, 0x01, 4, bitmask),
889 PREAD(temp2_alarm, 1, PRI_HIGH, 0x41, 0, 0x01, 5, bitmask),
890 PREAD(temp3_alarm, 2, PRI_HIGH, 0x41, 0, 0x01, 6, bitmask),
891 PREAD(temp4_alarm, 3, PRI_HIGH, 0x43, 0, 0x01, 0, bitmask),
892
893 PWRITE(temp1_source, 0, PRI_LOW, 0x02, 0, 0x07, 4, bitmask),
894 PWRITE(temp2_source, 1, PRI_LOW, 0x02, 0, 0x07, 0, bitmask),
895 PWRITE(temp3_source, 2, PRI_LOW, 0x03, 0, 0x07, 4, bitmask),
896 PWRITE(temp4_source, 3, PRI_LOW, 0x03, 0, 0x07, 0, bitmask),
897
898 PWRITE(temp1_smoothing_enable, 0, PRI_LOW, 0x62, 0, 0x01, 3, bitmask),
899 PWRITE(temp2_smoothing_enable, 1, PRI_LOW, 0x63, 0, 0x01, 7, bitmask),
900 PWRITE(temp3_smoothing_enable, 2, PRI_LOW, 0x63, 0, 0x01, 3, bitmask),
901 PWRITE(temp4_smoothing_enable, 3, PRI_LOW, 0x3c, 0, 0x01, 3, bitmask),
902
903 PWRITE(temp1_smoothing_time, 0, PRI_LOW, 0x62, 0, 0x07, 0, temp_st),
904 PWRITE(temp2_smoothing_time, 1, PRI_LOW, 0x63, 0, 0x07, 4, temp_st),
905 PWRITE(temp3_smoothing_time, 2, PRI_LOW, 0x63, 0, 0x07, 0, temp_st),
906 PWRITE(temp4_smoothing_time, 3, PRI_LOW, 0x3c, 0, 0x07, 0, temp_st),
907
908 PWRITE(temp1_auto_point1_temp_hyst, 0, PRI_LOW, 0x6d, 0, 0x0f, 4,
909 bitmask),
910 PWRITE(temp2_auto_point1_temp_hyst, 1, PRI_LOW, 0x6d, 0, 0x0f, 0,
911 bitmask),
912 PWRITE(temp3_auto_point1_temp_hyst, 2, PRI_LOW, 0x6e, 0, 0x0f, 4,
913 bitmask),
914 PWRITE(temp4_auto_point1_temp_hyst, 3, PRI_LOW, 0x6e, 0, 0x0f, 0,
915 bitmask),
916
917 PREAD(temp1_auto_point2_temp_hyst, 0, PRI_LOW, 0x6d, 0, 0x0f, 4,
918 bitmask),
919 PREAD(temp2_auto_point2_temp_hyst, 1, PRI_LOW, 0x6d, 0, 0x0f, 0,
920 bitmask),
921 PREAD(temp3_auto_point2_temp_hyst, 2, PRI_LOW, 0x6e, 0, 0x0f, 4,
922 bitmask),
923 PREAD(temp4_auto_point2_temp_hyst, 3, PRI_LOW, 0x6e, 0, 0x0f, 0,
924 bitmask),
925
926 PWRITE(temp1_auto_point1_temp, 0, PRI_LOW, 0x67, 0, 0, 0, temp8),
927 PWRITE(temp2_auto_point1_temp, 1, PRI_LOW, 0x68, 0, 0, 0, temp8),
928 PWRITE(temp3_auto_point1_temp, 2, PRI_LOW, 0x69, 0, 0, 0, temp8),
929 PWRITE(temp4_auto_point1_temp, 3, PRI_LOW, 0x3b, 0, 0, 0, temp8),
930
931 PWRITEM(temp1_auto_point2_temp, 0, PRI_LOW, VAA(0x5f, 0x67), VAA(0),
932 VAA(0x0f), VAA(4), ap2_temp),
933 PWRITEM(temp2_auto_point2_temp, 1, PRI_LOW, VAA(0x60, 0x68), VAA(0),
934 VAA(0x0f), VAA(4), ap2_temp),
935 PWRITEM(temp3_auto_point2_temp, 2, PRI_LOW, VAA(0x61, 0x69), VAA(0),
936 VAA(0x0f), VAA(4), ap2_temp),
937 PWRITEM(temp4_auto_point2_temp, 3, PRI_LOW, VAA(0x3c, 0x3b), VAA(0),
938 VAA(0x0f), VAA(4), ap2_temp),
939
940 PWRITE(temp1_crit, 0, PRI_LOW, 0x6a, 0, 0, 0, temp8),
941 PWRITE(temp2_crit, 1, PRI_LOW, 0x6b, 0, 0, 0, temp8),
942 PWRITE(temp3_crit, 2, PRI_LOW, 0x6c, 0, 0, 0, temp8),
943 PWRITE(temp4_crit, 3, PRI_LOW, 0x3d, 0, 0, 0, temp8),
944
945 PWRITE(temp5_enable, 4, PRI_LOW, 0x0e, 0, 0x01, 0, bitmask),
946 PWRITE(temp6_enable, 5, PRI_LOW, 0x0e, 0, 0x01, 1, bitmask),
947 PWRITE(temp7_enable, 6, PRI_LOW, 0x0e, 0, 0x01, 2, bitmask),
948 PWRITE(temp8_enable, 7, PRI_LOW, 0x0e, 0, 0x01, 3, bitmask),
949
950 PWRITE(remote1_offset, 0, PRI_LOW, 0x1c, 0, 0, 0, temp62),
951 PWRITE(remote2_offset, 1, PRI_LOW, 0x1d, 0, 0, 0, temp62),
952
953 PWRITE(pwm1, 0, PRI_HIGH, 0x30, 0, 0, 0, u8),
954 PWRITE(pwm2, 1, PRI_HIGH, 0x31, 0, 0, 0, u8),
955 PWRITE(pwm3, 2, PRI_HIGH, 0x32, 0, 0, 0, u8),
956
957 PWRITE(pwm1_invert, 0, PRI_LOW, 0x5c, 0, 0x01, 4, bitmask),
958 PWRITE(pwm2_invert, 1, PRI_LOW, 0x5d, 0, 0x01, 4, bitmask),
959 PWRITE(pwm3_invert, 2, PRI_LOW, 0x5e, 0, 0x01, 4, bitmask),
960
961 PWRITEM(pwm1_enable, 0, PRI_LOW, VAA(0x5c, 0x5c, 0x62), VAA(0, 0, 0),
962 VAA(0x07, 0x01, 0x01), VAA(5, 3, 5), pwm_enable),
963 PWRITEM(pwm2_enable, 1, PRI_LOW, VAA(0x5d, 0x5d, 0x62), VAA(0, 0, 0),
964 VAA(0x07, 0x01, 0x01), VAA(5, 3, 6), pwm_enable),
965 PWRITEM(pwm3_enable, 2, PRI_LOW, VAA(0x5e, 0x5e, 0x62), VAA(0, 0, 0),
966 VAA(0x07, 0x01, 0x01), VAA(5, 3, 7), pwm_enable),
967
968 PWRITEM(pwm1_auto_channels, 0, PRI_LOW, VAA(0x5c, 0x5c), VAA(0, 0),
969 VAA(0x07, 0x01), VAA(5, 3), pwm_ac),
970 PWRITEM(pwm2_auto_channels, 1, PRI_LOW, VAA(0x5d, 0x5d), VAA(0, 0),
971 VAA(0x07, 0x01), VAA(5, 3), pwm_ac),
972 PWRITEM(pwm3_auto_channels, 2, PRI_LOW, VAA(0x5e, 0x5e), VAA(0, 0),
973 VAA(0x07, 0x01), VAA(5, 3), pwm_ac),
974
975 PWRITE(pwm1_auto_point1_pwm, 0, PRI_LOW, 0x64, 0, 0, 0, u8),
976 PWRITE(pwm2_auto_point1_pwm, 1, PRI_LOW, 0x65, 0, 0, 0, u8),
977 PWRITE(pwm3_auto_point1_pwm, 2, PRI_LOW, 0x66, 0, 0, 0, u8),
978
979 PWRITE(pwm1_auto_point2_pwm, 0, PRI_LOW, 0x38, 0, 0, 0, u8),
980 PWRITE(pwm2_auto_point2_pwm, 1, PRI_LOW, 0x39, 0, 0, 0, u8),
981 PWRITE(pwm3_auto_point2_pwm, 2, PRI_LOW, 0x3a, 0, 0, 0, u8),
982
983 PWRITE(pwm1_freq, 0, PRI_LOW, 0x5f, 0, 0x0f, 0, pwm_freq),
984 PWRITE(pwm2_freq, 1, PRI_LOW, 0x60, 0, 0x0f, 0, pwm_freq),
985 PWRITE(pwm3_freq, 2, PRI_LOW, 0x61, 0, 0x0f, 0, pwm_freq),
986
987 PREAD(pwm1_auto_zone_assigned, 0, PRI_LOW, 0, 0, 0x03, 2, bitmask),
988 PREAD(pwm2_auto_zone_assigned, 1, PRI_LOW, 0, 0, 0x03, 4, bitmask),
989 PREAD(pwm3_auto_zone_assigned, 2, PRI_LOW, 0, 0, 0x03, 6, bitmask),
990
991 PWRITE(pwm1_auto_spinup_time, 0, PRI_LOW, 0x5c, 0, 0x07, 0, pwm_ast),
992 PWRITE(pwm2_auto_spinup_time, 1, PRI_LOW, 0x5d, 0, 0x07, 0, pwm_ast),
993 PWRITE(pwm3_auto_spinup_time, 2, PRI_LOW, 0x5e, 0, 0x07, 0, pwm_ast),
994
995 PWRITE(peci_enable, 0, PRI_LOW, 0x40, 0, 0x01, 4, bitmask),
996 PWRITE(peci_avg, 0, PRI_LOW, 0x36, 0, 0x07, 0, bitmask),
997 PWRITE(peci_domain, 0, PRI_LOW, 0x36, 0, 0x01, 3, bitmask),
998 PWRITE(peci_legacy, 0, PRI_LOW, 0x36, 0, 0x01, 4, bitmask),
999 PWRITE(peci_diode, 0, PRI_LOW, 0x0e, 0, 0x07, 4, bitmask),
1000 PWRITE(peci_4domain, 0, PRI_LOW, 0x0e, 0, 0x01, 4, bitmask),
1001
1002};
1003
1004static struct asc7621_data *asc7621_update_device(struct device *dev)
1005{
1006 struct i2c_client *client = to_i2c_client(dev);
1007 struct asc7621_data *data = i2c_get_clientdata(client);
1008 int i;
1009
1010/*
1011 * The asc7621 chips guarantee consistent reads of multi-byte values
1012 * regardless of the order of the reads. No special logic is needed
1013 * so we can just read the registers in whatever order they appear
1014 * in the asc7621_params array.
1015 */
1016
1017 mutex_lock(&data->update_lock);
1018
1019 /* Read all the high priority registers */
1020
1021 if (!data->valid ||
1022 time_after(jiffies, data->last_high_reading + INTERVAL_HIGH)) {
1023
1024 for (i = 0; i < ARRAY_SIZE(asc7621_register_priorities); i++) {
1025 if (asc7621_register_priorities[i] == PRI_HIGH) {
1026 data->reg[i] =
1027 i2c_smbus_read_byte_data(client, i) & 0xff;
1028 }
1029 }
1030 data->last_high_reading = jiffies;
1031 }; /* last_reading */
1032
1033 /* Read all the low priority registers. */
1034
1035 if (!data->valid ||
1036 time_after(jiffies, data->last_low_reading + INTERVAL_LOW)) {
1037
1038 for (i = 0; i < ARRAY_SIZE(asc7621_params); i++) {
1039 if (asc7621_register_priorities[i] == PRI_LOW) {
1040 data->reg[i] =
1041 i2c_smbus_read_byte_data(client, i) & 0xff;
1042 }
1043 }
1044 data->last_low_reading = jiffies;
1045 }; /* last_reading */
1046
1047 data->valid = 1;
1048
1049 mutex_unlock(&data->update_lock);
1050
1051 return data;
1052}
1053
1054/*
1055 * Standard detection and initialization below
1056 *
1057 * Helper function that checks if an address is valid
1058 * for a particular chip.
1059 */
1060
1061static inline int valid_address_for_chip(int chip_type, int address)
1062{
1063 int i;
1064
1065 for (i = 0; asc7621_chips[chip_type].addresses[i] != I2C_CLIENT_END;
1066 i++) {
1067 if (asc7621_chips[chip_type].addresses[i] == address)
1068 return 1;
1069 }
1070 return 0;
1071}
1072
1073static void asc7621_init_client(struct i2c_client *client)
1074{
1075 int value;
1076
1077 /* Warn if part was not "READY" */
1078
1079 value = read_byte(client, 0x40);
1080
1081 if (value & 0x02) {
1082 dev_err(&client->dev,
1083 "Client (%d,0x%02x) config is locked.\n",
1084 i2c_adapter_id(client->adapter), client->addr);
1085 };
1086 if (!(value & 0x04)) {
1087 dev_err(&client->dev, "Client (%d,0x%02x) is not ready.\n",
1088 i2c_adapter_id(client->adapter), client->addr);
1089 };
1090
1091/*
1092 * Start monitoring
1093 *
1094 * Try to clear LOCK, Set START, save everything else
1095 */
1096 value = (value & ~0x02) | 0x01;
1097 write_byte(client, 0x40, value & 0xff);
1098
1099}
1100
1101static int
1102asc7621_probe(struct i2c_client *client, const struct i2c_device_id *id)
1103{
1104 struct asc7621_data *data;
1105 int i, err;
1106
1107 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1108 return -EIO;
1109
1110 data = kzalloc(sizeof(struct asc7621_data), GFP_KERNEL);
1111 if (data == NULL)
1112 return -ENOMEM;
1113
1114 i2c_set_clientdata(client, data);
1115 data->valid = 0;
1116 mutex_init(&data->update_lock);
1117
1118 /* Initialize the asc7621 chip */
1119 asc7621_init_client(client);
1120
1121 /* Create the sysfs entries */
1122 for (i = 0; i < ARRAY_SIZE(asc7621_params); i++) {
1123 err =
1124 device_create_file(&client->dev,
1125 &(asc7621_params[i].sda.dev_attr));
1126 if (err)
1127 goto exit_remove;
1128 }
1129
1130 data->class_dev = hwmon_device_register(&client->dev);
1131 if (IS_ERR(data->class_dev)) {
1132 err = PTR_ERR(data->class_dev);
1133 goto exit_remove;
1134 }
1135
1136 return 0;
1137
1138exit_remove:
1139 for (i = 0; i < ARRAY_SIZE(asc7621_params); i++) {
1140 device_remove_file(&client->dev,
1141 &(asc7621_params[i].sda.dev_attr));
1142 }
1143
1144 i2c_set_clientdata(client, NULL);
1145 kfree(data);
1146 return err;
1147}
1148
1149static int asc7621_detect(struct i2c_client *client,
1150 struct i2c_board_info *info)
1151{
1152 struct i2c_adapter *adapter = client->adapter;
1153 int company, verstep, chip_index;
1154 struct device *dev;
1155
1156 dev = &client->dev;
1157
1158 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1159 return -ENODEV;
1160
1161 for (chip_index = FIRST_CHIP; chip_index <= LAST_CHIP; chip_index++) {
1162
1163 if (!valid_address_for_chip(chip_index, client->addr))
1164 continue;
1165
1166 company = read_byte(client,
1167 asc7621_chips[chip_index].company_reg);
1168 verstep = read_byte(client,
1169 asc7621_chips[chip_index].verstep_reg);
1170
1171 if (company == asc7621_chips[chip_index].company_id &&
1172 verstep == asc7621_chips[chip_index].verstep_id) {
1173 strlcpy(client->name, asc7621_chips[chip_index].name,
1174 I2C_NAME_SIZE);
1175 strlcpy(info->type, asc7621_chips[chip_index].name,
1176 I2C_NAME_SIZE);
1177
1178 dev_info(&adapter->dev, "Matched %s\n",
1179 asc7621_chips[chip_index].name);
1180 return 0;
1181 }
1182 }
1183
1184 return -ENODEV;
1185}
1186
1187static int asc7621_remove(struct i2c_client *client)
1188{
1189 struct asc7621_data *data = i2c_get_clientdata(client);
1190 int i;
1191
1192 hwmon_device_unregister(data->class_dev);
1193
1194 for (i = 0; i < ARRAY_SIZE(asc7621_params); i++) {
1195 device_remove_file(&client->dev,
1196 &(asc7621_params[i].sda.dev_attr));
1197 }
1198
1199 i2c_set_clientdata(client, NULL);
1200 kfree(data);
1201 return 0;
1202}
1203
1204static const struct i2c_device_id asc7621_id[] = {
1205 {"asc7621", asc7621},
1206 {"asc7621a", asc7621a},
1207 {},
1208};
1209
1210MODULE_DEVICE_TABLE(i2c, asc7621_id);
1211
1212static struct i2c_driver asc7621_driver = {
1213 .class = I2C_CLASS_HWMON,
1214 .driver = {
1215 .name = "asc7621",
1216 },
1217 .probe = asc7621_probe,
1218 .remove = asc7621_remove,
1219 .id_table = asc7621_id,
1220 .detect = asc7621_detect,
1221 .address_list = normal_i2c,
1222};
1223
1224static int __init sm_asc7621_init(void)
1225{
1226 int i, j;
1227/*
1228 * Collect all the registers needed into a single array.
1229 * This way, if a register isn't actually used for anything,
1230 * we don't retrieve it.
1231 */
1232
1233 for (i = 0; i < ARRAY_SIZE(asc7621_params); i++) {
1234 for (j = 0; j < ARRAY_SIZE(asc7621_params[i].msb); j++)
1235 asc7621_register_priorities[asc7621_params[i].msb[j]] =
1236 asc7621_params[i].priority;
1237 for (j = 0; j < ARRAY_SIZE(asc7621_params[i].lsb); j++)
1238 asc7621_register_priorities[asc7621_params[i].lsb[j]] =
1239 asc7621_params[i].priority;
1240 }
1241 return i2c_add_driver(&asc7621_driver);
1242}
1243
1244static void __exit sm_asc7621_exit(void)
1245{
1246 i2c_del_driver(&asc7621_driver);
1247}
1248
1249MODULE_LICENSE("GPL");
1250MODULE_AUTHOR("George Joseph");
1251MODULE_DESCRIPTION("Andigilog aSC7621 and aSC7621a driver");
1252
1253module_init(sm_asc7621_init);
1254module_exit(sm_asc7621_exit);
diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
index 5a3ee00c0e7d..16c420240724 100644
--- a/drivers/hwmon/asus_atk0110.c
+++ b/drivers/hwmon/asus_atk0110.c
@@ -5,10 +5,12 @@
5 * See COPYING in the top level directory of the kernel tree. 5 * See COPYING in the top level directory of the kernel tree.
6 */ 6 */
7 7
8#include <linux/debugfs.h>
8#include <linux/kernel.h> 9#include <linux/kernel.h>
9#include <linux/hwmon.h> 10#include <linux/hwmon.h>
10#include <linux/list.h> 11#include <linux/list.h>
11#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/slab.h>
12 14
13#include <acpi/acpi.h> 15#include <acpi/acpi.h>
14#include <acpi/acpixf.h> 16#include <acpi/acpixf.h>
@@ -101,6 +103,11 @@ struct atk_data {
101 int temperature_count; 103 int temperature_count;
102 int fan_count; 104 int fan_count;
103 struct list_head sensor_list; 105 struct list_head sensor_list;
106
107 struct {
108 struct dentry *root;
109 u32 id;
110 } debugfs;
104}; 111};
105 112
106 113
@@ -624,6 +631,187 @@ static int atk_read_value(struct atk_sensor_data *sensor, u64 *value)
624 return err; 631 return err;
625} 632}
626 633
634#ifdef CONFIG_DEBUG_FS
635static int atk_debugfs_gitm_get(void *p, u64 *val)
636{
637 struct atk_data *data = p;
638 union acpi_object *ret;
639 struct atk_acpi_ret_buffer *buf;
640 int err = 0;
641
642 if (!data->read_handle)
643 return -ENODEV;
644
645 if (!data->debugfs.id)
646 return -EINVAL;
647
648 ret = atk_gitm(data, data->debugfs.id);
649 if (IS_ERR(ret))
650 return PTR_ERR(ret);
651
652 buf = (struct atk_acpi_ret_buffer *)ret->buffer.pointer;
653 if (buf->flags)
654 *val = buf->value;
655 else
656 err = -EIO;
657
658 return err;
659}
660
661DEFINE_SIMPLE_ATTRIBUTE(atk_debugfs_gitm,
662 atk_debugfs_gitm_get,
663 NULL,
664 "0x%08llx\n")
665
666static int atk_acpi_print(char *buf, size_t sz, union acpi_object *obj)
667{
668 int ret = 0;
669
670 switch (obj->type) {
671 case ACPI_TYPE_INTEGER:
672 ret = snprintf(buf, sz, "0x%08llx\n", obj->integer.value);
673 break;
674 case ACPI_TYPE_STRING:
675 ret = snprintf(buf, sz, "%s\n", obj->string.pointer);
676 break;
677 }
678
679 return ret;
680}
681
682static void atk_pack_print(char *buf, size_t sz, union acpi_object *pack)
683{
684 int ret;
685 int i;
686
687 for (i = 0; i < pack->package.count; i++) {
688 union acpi_object *obj = &pack->package.elements[i];
689
690 ret = atk_acpi_print(buf, sz, obj);
691 if (ret >= sz)
692 break;
693 buf += ret;
694 sz -= ret;
695 }
696}
697
698static int atk_debugfs_ggrp_open(struct inode *inode, struct file *file)
699{
700 struct atk_data *data = inode->i_private;
701 char *buf = NULL;
702 union acpi_object *ret;
703 u8 cls;
704 int i;
705
706 if (!data->enumerate_handle)
707 return -ENODEV;
708 if (!data->debugfs.id)
709 return -EINVAL;
710
711 cls = (data->debugfs.id & 0xff000000) >> 24;
712 ret = atk_ggrp(data, cls);
713 if (IS_ERR(ret))
714 return PTR_ERR(ret);
715
716 for (i = 0; i < ret->package.count; i++) {
717 union acpi_object *pack = &ret->package.elements[i];
718 union acpi_object *id;
719
720 if (pack->type != ACPI_TYPE_PACKAGE)
721 continue;
722 if (!pack->package.count)
723 continue;
724 id = &pack->package.elements[0];
725 if (id->integer.value == data->debugfs.id) {
726 /* Print the package */
727 buf = kzalloc(512, GFP_KERNEL);
728 if (!buf) {
729 ACPI_FREE(ret);
730 return -ENOMEM;
731 }
732 atk_pack_print(buf, 512, pack);
733 break;
734 }
735 }
736 ACPI_FREE(ret);
737
738 if (!buf)
739 return -EINVAL;
740
741 file->private_data = buf;
742
743 return nonseekable_open(inode, file);
744}
745
746static ssize_t atk_debugfs_ggrp_read(struct file *file, char __user *buf,
747 size_t count, loff_t *pos)
748{
749 char *str = file->private_data;
750 size_t len = strlen(str);
751
752 return simple_read_from_buffer(buf, count, pos, str, len);
753}
754
755static int atk_debugfs_ggrp_release(struct inode *inode, struct file *file)
756{
757 kfree(file->private_data);
758 return 0;
759}
760
761static const struct file_operations atk_debugfs_ggrp_fops = {
762 .read = atk_debugfs_ggrp_read,
763 .open = atk_debugfs_ggrp_open,
764 .release = atk_debugfs_ggrp_release,
765};
766
767static void atk_debugfs_init(struct atk_data *data)
768{
769 struct dentry *d;
770 struct dentry *f;
771
772 data->debugfs.id = 0;
773
774 d = debugfs_create_dir("asus_atk0110", NULL);
775 if (!d || IS_ERR(d))
776 return;
777
778 f = debugfs_create_x32("id", S_IRUSR | S_IWUSR, d, &data->debugfs.id);
779 if (!f || IS_ERR(f))
780 goto cleanup;
781
782 f = debugfs_create_file("gitm", S_IRUSR, d, data,
783 &atk_debugfs_gitm);
784 if (!f || IS_ERR(f))
785 goto cleanup;
786
787 f = debugfs_create_file("ggrp", S_IRUSR, d, data,
788 &atk_debugfs_ggrp_fops);
789 if (!f || IS_ERR(f))
790 goto cleanup;
791
792 data->debugfs.root = d;
793
794 return;
795cleanup:
796 debugfs_remove_recursive(d);
797}
798
799static void atk_debugfs_cleanup(struct atk_data *data)
800{
801 debugfs_remove_recursive(data->debugfs.root);
802}
803
804#else /* CONFIG_DEBUG_FS */
805
806static void atk_debugfs_init(struct atk_data *data)
807{
808}
809
810static void atk_debugfs_cleanup(struct atk_data *data)
811{
812}
813#endif
814
627static int atk_add_sensor(struct atk_data *data, union acpi_object *obj) 815static int atk_add_sensor(struct atk_data *data, union acpi_object *obj)
628{ 816{
629 struct device *dev = &data->acpi_dev->dev; 817 struct device *dev = &data->acpi_dev->dev;
@@ -981,15 +1169,19 @@ static int atk_create_files(struct atk_data *data)
981 int err; 1169 int err;
982 1170
983 list_for_each_entry(s, &data->sensor_list, list) { 1171 list_for_each_entry(s, &data->sensor_list, list) {
1172 sysfs_attr_init(&s->input_attr.attr);
984 err = device_create_file(data->hwmon_dev, &s->input_attr); 1173 err = device_create_file(data->hwmon_dev, &s->input_attr);
985 if (err) 1174 if (err)
986 return err; 1175 return err;
1176 sysfs_attr_init(&s->label_attr.attr);
987 err = device_create_file(data->hwmon_dev, &s->label_attr); 1177 err = device_create_file(data->hwmon_dev, &s->label_attr);
988 if (err) 1178 if (err)
989 return err; 1179 return err;
1180 sysfs_attr_init(&s->limit1_attr.attr);
990 err = device_create_file(data->hwmon_dev, &s->limit1_attr); 1181 err = device_create_file(data->hwmon_dev, &s->limit1_attr);
991 if (err) 1182 if (err)
992 return err; 1183 return err;
1184 sysfs_attr_init(&s->limit2_attr.attr);
993 err = device_create_file(data->hwmon_dev, &s->limit2_attr); 1185 err = device_create_file(data->hwmon_dev, &s->limit2_attr);
994 if (err) 1186 if (err)
995 return err; 1187 return err;
@@ -1047,76 +1239,75 @@ remove:
1047 return err; 1239 return err;
1048} 1240}
1049 1241
1050static int atk_check_old_if(struct atk_data *data) 1242static int atk_probe_if(struct atk_data *data)
1051{ 1243{
1052 struct device *dev = &data->acpi_dev->dev; 1244 struct device *dev = &data->acpi_dev->dev;
1053 acpi_handle ret; 1245 acpi_handle ret;
1054 acpi_status status; 1246 acpi_status status;
1247 int err = 0;
1055 1248
1056 /* RTMP: read temperature */ 1249 /* RTMP: read temperature */
1057 status = acpi_get_handle(data->atk_handle, METHOD_OLD_READ_TMP, &ret); 1250 status = acpi_get_handle(data->atk_handle, METHOD_OLD_READ_TMP, &ret);
1058 if (status != AE_OK) { 1251 if (ACPI_SUCCESS(status))
1252 data->rtmp_handle = ret;
1253 else
1059 dev_dbg(dev, "method " METHOD_OLD_READ_TMP " not found: %s\n", 1254 dev_dbg(dev, "method " METHOD_OLD_READ_TMP " not found: %s\n",
1060 acpi_format_exception(status)); 1255 acpi_format_exception(status));
1061 return -ENODEV;
1062 }
1063 data->rtmp_handle = ret;
1064 1256
1065 /* RVLT: read voltage */ 1257 /* RVLT: read voltage */
1066 status = acpi_get_handle(data->atk_handle, METHOD_OLD_READ_VLT, &ret); 1258 status = acpi_get_handle(data->atk_handle, METHOD_OLD_READ_VLT, &ret);
1067 if (status != AE_OK) { 1259 if (ACPI_SUCCESS(status))
1260 data->rvlt_handle = ret;
1261 else
1068 dev_dbg(dev, "method " METHOD_OLD_READ_VLT " not found: %s\n", 1262 dev_dbg(dev, "method " METHOD_OLD_READ_VLT " not found: %s\n",
1069 acpi_format_exception(status)); 1263 acpi_format_exception(status));
1070 return -ENODEV;
1071 }
1072 data->rvlt_handle = ret;
1073 1264
1074 /* RFAN: read fan status */ 1265 /* RFAN: read fan status */
1075 status = acpi_get_handle(data->atk_handle, METHOD_OLD_READ_FAN, &ret); 1266 status = acpi_get_handle(data->atk_handle, METHOD_OLD_READ_FAN, &ret);
1076 if (status != AE_OK) { 1267 if (ACPI_SUCCESS(status))
1268 data->rfan_handle = ret;
1269 else
1077 dev_dbg(dev, "method " METHOD_OLD_READ_FAN " not found: %s\n", 1270 dev_dbg(dev, "method " METHOD_OLD_READ_FAN " not found: %s\n",
1078 acpi_format_exception(status)); 1271 acpi_format_exception(status));
1079 return -ENODEV;
1080 }
1081 data->rfan_handle = ret;
1082
1083 return 0;
1084}
1085
1086static int atk_check_new_if(struct atk_data *data)
1087{
1088 struct device *dev = &data->acpi_dev->dev;
1089 acpi_handle ret;
1090 acpi_status status;
1091 1272
1092 /* Enumeration */ 1273 /* Enumeration */
1093 status = acpi_get_handle(data->atk_handle, METHOD_ENUMERATE, &ret); 1274 status = acpi_get_handle(data->atk_handle, METHOD_ENUMERATE, &ret);
1094 if (status != AE_OK) { 1275 if (ACPI_SUCCESS(status))
1276 data->enumerate_handle = ret;
1277 else
1095 dev_dbg(dev, "method " METHOD_ENUMERATE " not found: %s\n", 1278 dev_dbg(dev, "method " METHOD_ENUMERATE " not found: %s\n",
1096 acpi_format_exception(status)); 1279 acpi_format_exception(status));
1097 return -ENODEV;
1098 }
1099 data->enumerate_handle = ret;
1100 1280
1101 /* De-multiplexer (read) */ 1281 /* De-multiplexer (read) */
1102 status = acpi_get_handle(data->atk_handle, METHOD_READ, &ret); 1282 status = acpi_get_handle(data->atk_handle, METHOD_READ, &ret);
1103 if (status != AE_OK) { 1283 if (ACPI_SUCCESS(status))
1284 data->read_handle = ret;
1285 else
1104 dev_dbg(dev, "method " METHOD_READ " not found: %s\n", 1286 dev_dbg(dev, "method " METHOD_READ " not found: %s\n",
1105 acpi_format_exception(status)); 1287 acpi_format_exception(status));
1106 return -ENODEV;
1107 }
1108 data->read_handle = ret;
1109 1288
1110 /* De-multiplexer (write) */ 1289 /* De-multiplexer (write) */
1111 status = acpi_get_handle(data->atk_handle, METHOD_WRITE, &ret); 1290 status = acpi_get_handle(data->atk_handle, METHOD_WRITE, &ret);
1112 if (status != AE_OK) { 1291 if (ACPI_SUCCESS(status))
1113 dev_dbg(dev, "method " METHOD_READ " not found: %s\n", 1292 data->write_handle = ret;
1293 else
1294 dev_dbg(dev, "method " METHOD_WRITE " not found: %s\n",
1114 acpi_format_exception(status)); 1295 acpi_format_exception(status));
1115 return -ENODEV;
1116 }
1117 data->write_handle = ret;
1118 1296
1119 return 0; 1297 /* Check for hwmon methods: first check "old" style methods; note that
1298 * both may be present: in this case we stick to the old interface;
1299 * analysis of multiple DSDTs indicates that when both interfaces
1300 * are present the new one (GGRP/GITM) is not functional.
1301 */
1302 if (data->rtmp_handle && data->rvlt_handle && data->rfan_handle)
1303 data->old_interface = true;
1304 else if (data->enumerate_handle && data->read_handle &&
1305 data->write_handle)
1306 data->old_interface = false;
1307 else
1308 err = -ENODEV;
1309
1310 return err;
1120} 1311}
1121 1312
1122static int atk_add(struct acpi_device *device) 1313static int atk_add(struct acpi_device *device)
@@ -1143,40 +1334,30 @@ static int atk_add(struct acpi_device *device)
1143 &buf, ACPI_TYPE_PACKAGE); 1334 &buf, ACPI_TYPE_PACKAGE);
1144 if (ret != AE_OK) { 1335 if (ret != AE_OK) {
1145 dev_dbg(&device->dev, "atk: method MBIF not found\n"); 1336 dev_dbg(&device->dev, "atk: method MBIF not found\n");
1146 err = -ENODEV; 1337 } else {
1147 goto out; 1338 obj = buf.pointer;
1339 if (obj->package.count >= 2) {
1340 union acpi_object *id = &obj->package.elements[1];
1341 if (id->type == ACPI_TYPE_STRING)
1342 dev_dbg(&device->dev, "board ID = %s\n",
1343 id->string.pointer);
1344 }
1345 ACPI_FREE(buf.pointer);
1148 } 1346 }
1149 1347
1150 obj = buf.pointer; 1348 err = atk_probe_if(data);
1151 if (obj->package.count >= 2 && 1349 if (err) {
1152 obj->package.elements[1].type == ACPI_TYPE_STRING) { 1350 dev_err(&device->dev, "No usable hwmon interface detected\n");
1153 dev_dbg(&device->dev, "board ID = %s\n", 1351 goto out;
1154 obj->package.elements[1].string.pointer);
1155 } 1352 }
1156 ACPI_FREE(buf.pointer);
1157 1353
1158 /* Check for hwmon methods: first check "old" style methods; note that 1354 if (data->old_interface) {
1159 * both may be present: in this case we stick to the old interface;
1160 * analysis of multiple DSDTs indicates that when both interfaces
1161 * are present the new one (GGRP/GITM) is not functional.
1162 */
1163 err = atk_check_old_if(data);
1164 if (!err) {
1165 dev_dbg(&device->dev, "Using old hwmon interface\n"); 1355 dev_dbg(&device->dev, "Using old hwmon interface\n");
1166 data->old_interface = true; 1356 err = atk_enumerate_old_hwmon(data);
1167 } else { 1357 } else {
1168 err = atk_check_new_if(data);
1169 if (err)
1170 goto out;
1171
1172 dev_dbg(&device->dev, "Using new hwmon interface\n"); 1358 dev_dbg(&device->dev, "Using new hwmon interface\n");
1173 data->old_interface = false;
1174 }
1175
1176 if (data->old_interface)
1177 err = atk_enumerate_old_hwmon(data);
1178 else
1179 err = atk_enumerate_new_hwmon(data); 1359 err = atk_enumerate_new_hwmon(data);
1360 }
1180 if (err < 0) 1361 if (err < 0)
1181 goto out; 1362 goto out;
1182 if (err == 0) { 1363 if (err == 0) {
@@ -1190,6 +1371,8 @@ static int atk_add(struct acpi_device *device)
1190 if (err) 1371 if (err)
1191 goto cleanup; 1372 goto cleanup;
1192 1373
1374 atk_debugfs_init(data);
1375
1193 device->driver_data = data; 1376 device->driver_data = data;
1194 return 0; 1377 return 0;
1195cleanup: 1378cleanup:
@@ -1208,6 +1391,8 @@ static int atk_remove(struct acpi_device *device, int type)
1208 1391
1209 device->driver_data = NULL; 1392 device->driver_data = NULL;
1210 1393
1394 atk_debugfs_cleanup(data);
1395
1211 atk_remove_files(data); 1396 atk_remove_files(data);
1212 atk_free_sensors(data); 1397 atk_free_sensors(data);
1213 hwmon_device_unregister(data->hwmon_dev); 1398 hwmon_device_unregister(data->hwmon_dev);
diff --git a/drivers/hwmon/atxp1.c b/drivers/hwmon/atxp1.c
index d6b490d3e36f..33cc143b2069 100644
--- a/drivers/hwmon/atxp1.c
+++ b/drivers/hwmon/atxp1.c
@@ -28,6 +28,7 @@
28#include <linux/err.h> 28#include <linux/err.h>
29#include <linux/mutex.h> 29#include <linux/mutex.h>
30#include <linux/sysfs.h> 30#include <linux/sysfs.h>
31#include <linux/slab.h>
31 32
32MODULE_LICENSE("GPL"); 33MODULE_LICENSE("GPL");
33MODULE_DESCRIPTION("System voltages control via Attansic ATXP1"); 34MODULE_DESCRIPTION("System voltages control via Attansic ATXP1");
@@ -44,17 +45,14 @@ MODULE_AUTHOR("Sebastian Witt <se.witt@gmx.net>");
44 45
45static const unsigned short normal_i2c[] = { 0x37, 0x4e, I2C_CLIENT_END }; 46static const unsigned short normal_i2c[] = { 0x37, 0x4e, I2C_CLIENT_END };
46 47
47I2C_CLIENT_INSMOD_1(atxp1);
48
49static int atxp1_probe(struct i2c_client *client, 48static int atxp1_probe(struct i2c_client *client,
50 const struct i2c_device_id *id); 49 const struct i2c_device_id *id);
51static int atxp1_remove(struct i2c_client *client); 50static int atxp1_remove(struct i2c_client *client);
52static struct atxp1_data * atxp1_update_device(struct device *dev); 51static struct atxp1_data * atxp1_update_device(struct device *dev);
53static int atxp1_detect(struct i2c_client *client, int kind, 52static int atxp1_detect(struct i2c_client *client, struct i2c_board_info *info);
54 struct i2c_board_info *info);
55 53
56static const struct i2c_device_id atxp1_id[] = { 54static const struct i2c_device_id atxp1_id[] = {
57 { "atxp1", atxp1 }, 55 { "atxp1", 0 },
58 { } 56 { }
59}; 57};
60MODULE_DEVICE_TABLE(i2c, atxp1_id); 58MODULE_DEVICE_TABLE(i2c, atxp1_id);
@@ -68,7 +66,7 @@ static struct i2c_driver atxp1_driver = {
68 .remove = atxp1_remove, 66 .remove = atxp1_remove,
69 .id_table = atxp1_id, 67 .id_table = atxp1_id,
70 .detect = atxp1_detect, 68 .detect = atxp1_detect,
71 .address_data = &addr_data, 69 .address_list = normal_i2c,
72}; 70};
73 71
74struct atxp1_data { 72struct atxp1_data {
@@ -275,7 +273,7 @@ static const struct attribute_group atxp1_group = {
275 273
276 274
277/* Return 0 if detection is successful, -ENODEV otherwise */ 275/* Return 0 if detection is successful, -ENODEV otherwise */
278static int atxp1_detect(struct i2c_client *new_client, int kind, 276static int atxp1_detect(struct i2c_client *new_client,
279 struct i2c_board_info *info) 277 struct i2c_board_info *info)
280{ 278{
281 struct i2c_adapter *adapter = new_client->adapter; 279 struct i2c_adapter *adapter = new_client->adapter;
diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
index caef39cda8c8..e9b7fbc5a447 100644
--- a/drivers/hwmon/coretemp.c
+++ b/drivers/hwmon/coretemp.c
@@ -33,6 +33,7 @@
33#include <linux/list.h> 33#include <linux/list.h>
34#include <linux/platform_device.h> 34#include <linux/platform_device.h>
35#include <linux/cpu.h> 35#include <linux/cpu.h>
36#include <linux/pci.h>
36#include <asm/msr.h> 37#include <asm/msr.h>
37#include <asm/processor.h> 38#include <asm/processor.h>
38 39
@@ -161,6 +162,7 @@ static int __devinit adjust_tjmax(struct cpuinfo_x86 *c, u32 id, struct device *
161 int usemsr_ee = 1; 162 int usemsr_ee = 1;
162 int err; 163 int err;
163 u32 eax, edx; 164 u32 eax, edx;
165 struct pci_dev *host_bridge;
164 166
165 /* Early chips have no MSR for TjMax */ 167 /* Early chips have no MSR for TjMax */
166 168
@@ -168,11 +170,21 @@ static int __devinit adjust_tjmax(struct cpuinfo_x86 *c, u32 id, struct device *
168 usemsr_ee = 0; 170 usemsr_ee = 0;
169 } 171 }
170 172
171 /* Atoms seems to have TjMax at 90C */ 173 /* Atom CPUs */
172 174
173 if (c->x86_model == 0x1c) { 175 if (c->x86_model == 0x1c) {
174 usemsr_ee = 0; 176 usemsr_ee = 0;
175 tjmax = 90000; 177
178 host_bridge = pci_get_bus_and_slot(0, PCI_DEVFN(0, 0));
179
180 if (host_bridge && host_bridge->vendor == PCI_VENDOR_ID_INTEL
181 && (host_bridge->device == 0xa000 /* NM10 based nettop */
182 || host_bridge->device == 0xa010)) /* NM10 based netbook */
183 tjmax = 100000;
184 else
185 tjmax = 90000;
186
187 pci_dev_put(host_bridge);
176 } 188 }
177 189
178 if ((c->x86_model > 0xe) && (usemsr_ee)) { 190 if ((c->x86_model > 0xe) && (usemsr_ee)) {
@@ -216,7 +228,7 @@ static int __devinit adjust_tjmax(struct cpuinfo_x86 *c, u32 id, struct device *
216 if (err) { 228 if (err) {
217 dev_warn(dev, 229 dev_warn(dev,
218 "Unable to access MSR 0xEE, for Tjmax, left" 230 "Unable to access MSR 0xEE, for Tjmax, left"
219 " at default"); 231 " at default\n");
220 } else if (eax & 0x40000000) { 232 } else if (eax & 0x40000000) {
221 tjmax = tjmax_ee; 233 tjmax = tjmax_ee;
222 } 234 }
@@ -454,7 +466,7 @@ static int __init coretemp_init(void)
454 family 6 CPU */ 466 family 6 CPU */
455 if ((c->x86 == 0x6) && (c->x86_model > 0xf)) 467 if ((c->x86 == 0x6) && (c->x86_model > 0xf))
456 printk(KERN_WARNING DRVNAME ": Unknown CPU " 468 printk(KERN_WARNING DRVNAME ": Unknown CPU "
457 "model %x\n", c->x86_model); 469 "model 0x%x\n", c->x86_model);
458 continue; 470 continue;
459 } 471 }
460 472
diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c
index 27d62574284f..823dd28a902c 100644
--- a/drivers/hwmon/dme1737.c
+++ b/drivers/hwmon/dme1737.c
@@ -57,11 +57,7 @@ MODULE_PARM_DESC(probe_all_addr, "Include probing of non-standard LPC "
57/* Addresses to scan */ 57/* Addresses to scan */
58static const unsigned short normal_i2c[] = {0x2c, 0x2d, 0x2e, I2C_CLIENT_END}; 58static const unsigned short normal_i2c[] = {0x2c, 0x2d, 0x2e, I2C_CLIENT_END};
59 59
60/* Insmod parameters */ 60enum chips { dme1737, sch5027, sch311x };
61I2C_CLIENT_INSMOD_2(dme1737, sch5027);
62
63/* ISA chip types */
64enum isa_chips { sch311x = sch5027 + 1 };
65 61
66/* --------------------------------------------------------------------- 62/* ---------------------------------------------------------------------
67 * Registers 63 * Registers
@@ -2208,7 +2204,7 @@ exit:
2208} 2204}
2209 2205
2210/* Return 0 if detection is successful, -ENODEV otherwise */ 2206/* Return 0 if detection is successful, -ENODEV otherwise */
2211static int dme1737_i2c_detect(struct i2c_client *client, int kind, 2207static int dme1737_i2c_detect(struct i2c_client *client,
2212 struct i2c_board_info *info) 2208 struct i2c_board_info *info)
2213{ 2209{
2214 struct i2c_adapter *adapter = client->adapter; 2210 struct i2c_adapter *adapter = client->adapter;
@@ -2220,33 +2216,23 @@ static int dme1737_i2c_detect(struct i2c_client *client, int kind,
2220 return -ENODEV; 2216 return -ENODEV;
2221 } 2217 }
2222 2218
2223 /* A negative kind means that the driver was loaded with no force 2219 company = i2c_smbus_read_byte_data(client, DME1737_REG_COMPANY);
2224 * parameter (default), so we must identify the chip. */ 2220 verstep = i2c_smbus_read_byte_data(client, DME1737_REG_VERSTEP);
2225 if (kind < 0) {
2226 company = i2c_smbus_read_byte_data(client, DME1737_REG_COMPANY);
2227 verstep = i2c_smbus_read_byte_data(client, DME1737_REG_VERSTEP);
2228
2229 if (company == DME1737_COMPANY_SMSC &&
2230 (verstep & DME1737_VERSTEP_MASK) == DME1737_VERSTEP) {
2231 kind = dme1737;
2232 } else if (company == DME1737_COMPANY_SMSC &&
2233 verstep == SCH5027_VERSTEP) {
2234 kind = sch5027;
2235 } else {
2236 return -ENODEV;
2237 }
2238 }
2239 2221
2240 if (kind == sch5027) { 2222 if (company == DME1737_COMPANY_SMSC &&
2223 verstep == SCH5027_VERSTEP) {
2241 name = "sch5027"; 2224 name = "sch5027";
2242 } else { 2225
2243 kind = dme1737; 2226 } else if (company == DME1737_COMPANY_SMSC &&
2227 (verstep & DME1737_VERSTEP_MASK) == DME1737_VERSTEP) {
2244 name = "dme1737"; 2228 name = "dme1737";
2229 } else {
2230 return -ENODEV;
2245 } 2231 }
2246 2232
2247 dev_info(dev, "Found a %s chip at 0x%02x (rev 0x%02x).\n", 2233 dev_info(dev, "Found a %s chip at 0x%02x (rev 0x%02x).\n",
2248 kind == sch5027 ? "SCH5027" : "DME1737", client->addr, 2234 verstep == SCH5027_VERSTEP ? "SCH5027" : "DME1737",
2249 verstep); 2235 client->addr, verstep);
2250 strlcpy(info->type, name, I2C_NAME_SIZE); 2236 strlcpy(info->type, name, I2C_NAME_SIZE);
2251 2237
2252 return 0; 2238 return 0;
@@ -2328,7 +2314,7 @@ static struct i2c_driver dme1737_i2c_driver = {
2328 .remove = dme1737_i2c_remove, 2314 .remove = dme1737_i2c_remove,
2329 .id_table = dme1737_id, 2315 .id_table = dme1737_id,
2330 .detect = dme1737_i2c_detect, 2316 .detect = dme1737_i2c_detect,
2331 .address_data = &addr_data, 2317 .address_list = normal_i2c,
2332}; 2318};
2333 2319
2334/* --------------------------------------------------------------------- 2320/* ---------------------------------------------------------------------
diff --git a/drivers/hwmon/ds1621.c b/drivers/hwmon/ds1621.c
index 53f88f511816..e11363467a8d 100644
--- a/drivers/hwmon/ds1621.c
+++ b/drivers/hwmon/ds1621.c
@@ -38,7 +38,6 @@ static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
38 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; 38 0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
39 39
40/* Insmod parameters */ 40/* Insmod parameters */
41I2C_CLIENT_INSMOD_1(ds1621);
42static int polarity = -1; 41static int polarity = -1;
43module_param(polarity, int, 0); 42module_param(polarity, int, 0);
44MODULE_PARM_DESC(polarity, "Output's polarity: 0 = active high, 1 = active low"); 43MODULE_PARM_DESC(polarity, "Output's polarity: 0 = active high, 1 = active low");
@@ -224,7 +223,7 @@ static const struct attribute_group ds1621_group = {
224 223
225 224
226/* Return 0 if detection is successful, -ENODEV otherwise */ 225/* Return 0 if detection is successful, -ENODEV otherwise */
227static int ds1621_detect(struct i2c_client *client, int kind, 226static int ds1621_detect(struct i2c_client *client,
228 struct i2c_board_info *info) 227 struct i2c_board_info *info)
229{ 228{
230 struct i2c_adapter *adapter = client->adapter; 229 struct i2c_adapter *adapter = client->adapter;
@@ -237,20 +236,16 @@ static int ds1621_detect(struct i2c_client *client, int kind,
237 return -ENODEV; 236 return -ENODEV;
238 237
239 /* Now, we do the remaining detection. It is lousy. */ 238 /* Now, we do the remaining detection. It is lousy. */
240 if (kind < 0) { 239 /* The NVB bit should be low if no EEPROM write has been requested
241 /* The NVB bit should be low if no EEPROM write has been 240 during the latest 10ms, which is highly improbable in our case. */
242 requested during the latest 10ms, which is highly 241 conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF);
243 improbable in our case. */ 242 if (conf < 0 || conf & DS1621_REG_CONFIG_NVB)
244 conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF); 243 return -ENODEV;
245 if (conf < 0 || conf & DS1621_REG_CONFIG_NVB) 244 /* The 7 lowest bits of a temperature should always be 0. */
245 for (i = 0; i < ARRAY_SIZE(DS1621_REG_TEMP); i++) {
246 temp = i2c_smbus_read_word_data(client, DS1621_REG_TEMP[i]);
247 if (temp < 0 || (temp & 0x7f00))
246 return -ENODEV; 248 return -ENODEV;
247 /* The 7 lowest bits of a temperature should always be 0. */
248 for (i = 0; i < ARRAY_SIZE(DS1621_REG_TEMP); i++) {
249 temp = i2c_smbus_read_word_data(client,
250 DS1621_REG_TEMP[i]);
251 if (temp < 0 || (temp & 0x7f00))
252 return -ENODEV;
253 }
254 } 249 }
255 250
256 strlcpy(info->type, "ds1621", I2C_NAME_SIZE); 251 strlcpy(info->type, "ds1621", I2C_NAME_SIZE);
@@ -309,8 +304,8 @@ static int ds1621_remove(struct i2c_client *client)
309} 304}
310 305
311static const struct i2c_device_id ds1621_id[] = { 306static const struct i2c_device_id ds1621_id[] = {
312 { "ds1621", ds1621 }, 307 { "ds1621", 0 },
313 { "ds1625", ds1621 }, 308 { "ds1625", 0 },
314 { } 309 { }
315}; 310};
316MODULE_DEVICE_TABLE(i2c, ds1621_id); 311MODULE_DEVICE_TABLE(i2c, ds1621_id);
@@ -325,7 +320,7 @@ static struct i2c_driver ds1621_driver = {
325 .remove = ds1621_remove, 320 .remove = ds1621_remove,
326 .id_table = ds1621_id, 321 .id_table = ds1621_id,
327 .detect = ds1621_detect, 322 .detect = ds1621_detect,
328 .address_data = &addr_data, 323 .address_list = normal_i2c,
329}; 324};
330 325
331static int __init ds1621_init(void) 326static int __init ds1621_init(void)
diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c
index 4146105f1a57..a95fa4256caa 100644
--- a/drivers/hwmon/f71882fg.c
+++ b/drivers/hwmon/f71882fg.c
@@ -48,6 +48,7 @@
48#define SIO_F71858_ID 0x0507 /* Chipset ID */ 48#define SIO_F71858_ID 0x0507 /* Chipset ID */
49#define SIO_F71862_ID 0x0601 /* Chipset ID */ 49#define SIO_F71862_ID 0x0601 /* Chipset ID */
50#define SIO_F71882_ID 0x0541 /* Chipset ID */ 50#define SIO_F71882_ID 0x0541 /* Chipset ID */
51#define SIO_F71889_ID 0x0723 /* Chipset ID */
51#define SIO_F8000_ID 0x0581 /* Chipset ID */ 52#define SIO_F8000_ID 0x0581 /* Chipset ID */
52 53
53#define REGION_LENGTH 8 54#define REGION_LENGTH 8
@@ -95,12 +96,13 @@ static unsigned short force_id;
95module_param(force_id, ushort, 0); 96module_param(force_id, ushort, 0);
96MODULE_PARM_DESC(force_id, "Override the detected device ID"); 97MODULE_PARM_DESC(force_id, "Override the detected device ID");
97 98
98enum chips { f71858fg, f71862fg, f71882fg, f8000 }; 99enum chips { f71858fg, f71862fg, f71882fg, f71889fg, f8000 };
99 100
100static const char *f71882fg_names[] = { 101static const char *f71882fg_names[] = {
101 "f71858fg", 102 "f71858fg",
102 "f71862fg", 103 "f71862fg",
103 "f71882fg", 104 "f71882fg",
105 "f71889fg",
104 "f8000", 106 "f8000",
105}; 107};
106 108
@@ -155,7 +157,7 @@ struct f71882fg_data {
155 u8 pwm_auto_point_hyst[2]; 157 u8 pwm_auto_point_hyst[2];
156 u8 pwm_auto_point_mapping[4]; 158 u8 pwm_auto_point_mapping[4];
157 u8 pwm_auto_point_pwm[4][5]; 159 u8 pwm_auto_point_pwm[4][5];
158 u8 pwm_auto_point_temp[4][4]; 160 s8 pwm_auto_point_temp[4][4];
159}; 161};
160 162
161/* Sysfs in */ 163/* Sysfs in */
@@ -258,7 +260,9 @@ static struct platform_driver f71882fg_driver = {
258 260
259static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 261static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
260 262
261/* Temp and in attr for the f71858fg */ 263/* Temp and in attr for the f71858fg, the f71858fg is special as it
264 has its temperature indexes start at 0 (the others start at 1) and
265 it only has 3 voltage inputs */
262static struct sensor_device_attribute_2 f71858fg_in_temp_attr[] = { 266static struct sensor_device_attribute_2 f71858fg_in_temp_attr[] = {
263 SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0), 267 SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0),
264 SENSOR_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 0, 1), 268 SENSOR_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 0, 1),
@@ -302,8 +306,8 @@ static struct sensor_device_attribute_2 f71858fg_in_temp_attr[] = {
302 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2), 306 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
303}; 307};
304 308
305/* Temp and in attr common to both the f71862fg and f71882fg */ 309/* Temp and in attr common to the f71862fg, f71882fg and f71889fg */
306static struct sensor_device_attribute_2 f718x2fg_in_temp_attr[] = { 310static struct sensor_device_attribute_2 fxxxx_in_temp_attr[] = {
307 SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0), 311 SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0),
308 SENSOR_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 0, 1), 312 SENSOR_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 0, 1),
309 SENSOR_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 0, 2), 313 SENSOR_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 0, 2),
@@ -371,8 +375,8 @@ static struct sensor_device_attribute_2 f718x2fg_in_temp_attr[] = {
371 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 3), 375 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 3),
372}; 376};
373 377
374/* Temp and in attr found only on the f71882fg */ 378/* For models with in1 alarm capability */
375static struct sensor_device_attribute_2 f71882fg_in_temp_attr[] = { 379static struct sensor_device_attribute_2 fxxxx_in1_alarm_attr[] = {
376 SENSOR_ATTR_2(in1_max, S_IRUGO|S_IWUSR, show_in_max, store_in_max, 380 SENSOR_ATTR_2(in1_max, S_IRUGO|S_IWUSR, show_in_max, store_in_max,
377 0, 1), 381 0, 1),
378 SENSOR_ATTR_2(in1_beep, S_IRUGO|S_IWUSR, show_in_beep, store_in_beep, 382 SENSOR_ATTR_2(in1_beep, S_IRUGO|S_IWUSR, show_in_beep, store_in_beep,
@@ -383,6 +387,7 @@ static struct sensor_device_attribute_2 f71882fg_in_temp_attr[] = {
383/* Temp and in attr for the f8000 387/* Temp and in attr for the f8000
384 Note on the f8000 temp_ovt (crit) is used as max, and temp_high (max) 388 Note on the f8000 temp_ovt (crit) is used as max, and temp_high (max)
385 is used as hysteresis value to clear alarms 389 is used as hysteresis value to clear alarms
390 Also like the f71858fg its temperature indexes start at 0
386 */ 391 */
387static struct sensor_device_attribute_2 f8000_in_temp_attr[] = { 392static struct sensor_device_attribute_2 f8000_in_temp_attr[] = {
388 SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0), 393 SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0),
@@ -413,61 +418,70 @@ static struct sensor_device_attribute_2 f8000_in_temp_attr[] = {
413}; 418};
414 419
415/* Fan / PWM attr common to all models */ 420/* Fan / PWM attr common to all models */
416static struct sensor_device_attribute_2 fxxxx_fan_attr[] = { 421static struct sensor_device_attribute_2 fxxxx_fan_attr[4][6] = { {
417 SENSOR_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0), 422 SENSOR_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0),
418 SENSOR_ATTR_2(fan1_full_speed, S_IRUGO|S_IWUSR, 423 SENSOR_ATTR_2(fan1_full_speed, S_IRUGO|S_IWUSR,
419 show_fan_full_speed, 424 show_fan_full_speed,
420 store_fan_full_speed, 0, 0), 425 store_fan_full_speed, 0, 0),
421 SENSOR_ATTR_2(fan1_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 0), 426 SENSOR_ATTR_2(fan1_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 0),
422 SENSOR_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 0, 1),
423 SENSOR_ATTR_2(fan2_full_speed, S_IRUGO|S_IWUSR,
424 show_fan_full_speed,
425 store_fan_full_speed, 0, 1),
426 SENSOR_ATTR_2(fan2_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 1),
427 SENSOR_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 0, 2),
428 SENSOR_ATTR_2(fan3_full_speed, S_IRUGO|S_IWUSR,
429 show_fan_full_speed,
430 store_fan_full_speed, 0, 2),
431 SENSOR_ATTR_2(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 2),
432
433 SENSOR_ATTR_2(pwm1, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 0), 427 SENSOR_ATTR_2(pwm1, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 0),
434 SENSOR_ATTR_2(pwm1_enable, S_IRUGO|S_IWUSR, show_pwm_enable, 428 SENSOR_ATTR_2(pwm1_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
435 store_pwm_enable, 0, 0), 429 store_pwm_enable, 0, 0),
436 SENSOR_ATTR_2(pwm1_interpolate, S_IRUGO|S_IWUSR, 430 SENSOR_ATTR_2(pwm1_interpolate, S_IRUGO|S_IWUSR,
437 show_pwm_interpolate, store_pwm_interpolate, 0, 0), 431 show_pwm_interpolate, store_pwm_interpolate, 0, 0),
438 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR, 432}, {
439 show_pwm_auto_point_channel, 433 SENSOR_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 0, 1),
440 store_pwm_auto_point_channel, 0, 0), 434 SENSOR_ATTR_2(fan2_full_speed, S_IRUGO|S_IWUSR,
441 435 show_fan_full_speed,
436 store_fan_full_speed, 0, 1),
437 SENSOR_ATTR_2(fan2_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 1),
442 SENSOR_ATTR_2(pwm2, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 1), 438 SENSOR_ATTR_2(pwm2, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 1),
443 SENSOR_ATTR_2(pwm2_enable, S_IRUGO|S_IWUSR, show_pwm_enable, 439 SENSOR_ATTR_2(pwm2_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
444 store_pwm_enable, 0, 1), 440 store_pwm_enable, 0, 1),
445 SENSOR_ATTR_2(pwm2_interpolate, S_IRUGO|S_IWUSR, 441 SENSOR_ATTR_2(pwm2_interpolate, S_IRUGO|S_IWUSR,
446 show_pwm_interpolate, store_pwm_interpolate, 0, 1), 442 show_pwm_interpolate, store_pwm_interpolate, 0, 1),
447 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR, 443}, {
448 show_pwm_auto_point_channel, 444 SENSOR_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 0, 2),
449 store_pwm_auto_point_channel, 0, 1), 445 SENSOR_ATTR_2(fan3_full_speed, S_IRUGO|S_IWUSR,
450 446 show_fan_full_speed,
447 store_fan_full_speed, 0, 2),
448 SENSOR_ATTR_2(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 2),
451 SENSOR_ATTR_2(pwm3, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 2), 449 SENSOR_ATTR_2(pwm3, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 2),
452 SENSOR_ATTR_2(pwm3_enable, S_IRUGO|S_IWUSR, show_pwm_enable, 450 SENSOR_ATTR_2(pwm3_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
453 store_pwm_enable, 0, 2), 451 store_pwm_enable, 0, 2),
454 SENSOR_ATTR_2(pwm3_interpolate, S_IRUGO|S_IWUSR, 452 SENSOR_ATTR_2(pwm3_interpolate, S_IRUGO|S_IWUSR,
455 show_pwm_interpolate, store_pwm_interpolate, 0, 2), 453 show_pwm_interpolate, store_pwm_interpolate, 0, 2),
456 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR, 454}, {
457 show_pwm_auto_point_channel, 455 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
458 store_pwm_auto_point_channel, 0, 2), 456 SENSOR_ATTR_2(fan4_full_speed, S_IRUGO|S_IWUSR,
459}; 457 show_fan_full_speed,
458 store_fan_full_speed, 0, 3),
459 SENSOR_ATTR_2(fan4_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 3),
460 SENSOR_ATTR_2(pwm4, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 3),
461 SENSOR_ATTR_2(pwm4_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
462 store_pwm_enable, 0, 3),
463 SENSOR_ATTR_2(pwm4_interpolate, S_IRUGO|S_IWUSR,
464 show_pwm_interpolate, store_pwm_interpolate, 0, 3),
465} };
460 466
461/* Fan / PWM attr for the f71862fg, less pwms and less zones per pwm than the 467/* Attr for models which can beep on Fan alarm */
462 f71882fg */ 468static struct sensor_device_attribute_2 fxxxx_fan_beep_attr[] = {
463static struct sensor_device_attribute_2 f71862fg_fan_attr[] = {
464 SENSOR_ATTR_2(fan1_beep, S_IRUGO|S_IWUSR, show_fan_beep, 469 SENSOR_ATTR_2(fan1_beep, S_IRUGO|S_IWUSR, show_fan_beep,
465 store_fan_beep, 0, 0), 470 store_fan_beep, 0, 0),
466 SENSOR_ATTR_2(fan2_beep, S_IRUGO|S_IWUSR, show_fan_beep, 471 SENSOR_ATTR_2(fan2_beep, S_IRUGO|S_IWUSR, show_fan_beep,
467 store_fan_beep, 0, 1), 472 store_fan_beep, 0, 1),
468 SENSOR_ATTR_2(fan3_beep, S_IRUGO|S_IWUSR, show_fan_beep, 473 SENSOR_ATTR_2(fan3_beep, S_IRUGO|S_IWUSR, show_fan_beep,
469 store_fan_beep, 0, 2), 474 store_fan_beep, 0, 2),
475 SENSOR_ATTR_2(fan4_beep, S_IRUGO|S_IWUSR, show_fan_beep,
476 store_fan_beep, 0, 3),
477};
470 478
479/* PWM attr for the f71862fg, fewer pwms and fewer zones per pwm than the
480 f71858fg / f71882fg / f71889fg */
481static struct sensor_device_attribute_2 f71862fg_auto_pwm_attr[] = {
482 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
483 show_pwm_auto_point_channel,
484 store_pwm_auto_point_channel, 0, 0),
471 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR, 485 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
472 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, 486 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
473 1, 0), 487 1, 0),
@@ -487,6 +501,9 @@ static struct sensor_device_attribute_2 f71862fg_fan_attr[] = {
487 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO, 501 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
488 show_pwm_auto_point_temp_hyst, NULL, 3, 0), 502 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
489 503
504 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
505 show_pwm_auto_point_channel,
506 store_pwm_auto_point_channel, 0, 1),
490 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR, 507 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
491 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, 508 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
492 1, 1), 509 1, 1),
@@ -506,6 +523,9 @@ static struct sensor_device_attribute_2 f71862fg_fan_attr[] = {
506 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO, 523 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
507 show_pwm_auto_point_temp_hyst, NULL, 3, 1), 524 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
508 525
526 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
527 show_pwm_auto_point_channel,
528 store_pwm_auto_point_channel, 0, 2),
509 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR, 529 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
510 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, 530 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
511 1, 2), 531 1, 2),
@@ -526,8 +546,11 @@ static struct sensor_device_attribute_2 f71862fg_fan_attr[] = {
526 show_pwm_auto_point_temp_hyst, NULL, 3, 2), 546 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
527}; 547};
528 548
529/* Fan / PWM attr common to both the f71882fg and f71858fg */ 549/* PWM attr common to the f71858fg, f71882fg and f71889fg */
530static struct sensor_device_attribute_2 f71882fg_f71858fg_fan_attr[] = { 550static struct sensor_device_attribute_2 fxxxx_auto_pwm_attr[4][14] = { {
551 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
552 show_pwm_auto_point_channel,
553 store_pwm_auto_point_channel, 0, 0),
531 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR, 554 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
532 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, 555 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
533 0, 0), 556 0, 0),
@@ -565,7 +588,10 @@ static struct sensor_device_attribute_2 f71882fg_f71858fg_fan_attr[] = {
565 show_pwm_auto_point_temp_hyst, NULL, 2, 0), 588 show_pwm_auto_point_temp_hyst, NULL, 2, 0),
566 SENSOR_ATTR_2(pwm1_auto_point4_temp_hyst, S_IRUGO, 589 SENSOR_ATTR_2(pwm1_auto_point4_temp_hyst, S_IRUGO,
567 show_pwm_auto_point_temp_hyst, NULL, 3, 0), 590 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
568 591}, {
592 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
593 show_pwm_auto_point_channel,
594 store_pwm_auto_point_channel, 0, 1),
569 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR, 595 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
570 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, 596 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
571 0, 1), 597 0, 1),
@@ -603,7 +629,10 @@ static struct sensor_device_attribute_2 f71882fg_f71858fg_fan_attr[] = {
603 show_pwm_auto_point_temp_hyst, NULL, 2, 1), 629 show_pwm_auto_point_temp_hyst, NULL, 2, 1),
604 SENSOR_ATTR_2(pwm2_auto_point4_temp_hyst, S_IRUGO, 630 SENSOR_ATTR_2(pwm2_auto_point4_temp_hyst, S_IRUGO,
605 show_pwm_auto_point_temp_hyst, NULL, 3, 1), 631 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
606 632}, {
633 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
634 show_pwm_auto_point_channel,
635 store_pwm_auto_point_channel, 0, 2),
607 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR, 636 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
608 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, 637 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
609 0, 2), 638 0, 2),
@@ -641,30 +670,7 @@ static struct sensor_device_attribute_2 f71882fg_f71858fg_fan_attr[] = {
641 show_pwm_auto_point_temp_hyst, NULL, 2, 2), 670 show_pwm_auto_point_temp_hyst, NULL, 2, 2),
642 SENSOR_ATTR_2(pwm3_auto_point4_temp_hyst, S_IRUGO, 671 SENSOR_ATTR_2(pwm3_auto_point4_temp_hyst, S_IRUGO,
643 show_pwm_auto_point_temp_hyst, NULL, 3, 2), 672 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
644}; 673}, {
645
646/* Fan / PWM attr found on the f71882fg but not on the f71858fg */
647static struct sensor_device_attribute_2 f71882fg_fan_attr[] = {
648 SENSOR_ATTR_2(fan1_beep, S_IRUGO|S_IWUSR, show_fan_beep,
649 store_fan_beep, 0, 0),
650 SENSOR_ATTR_2(fan2_beep, S_IRUGO|S_IWUSR, show_fan_beep,
651 store_fan_beep, 0, 1),
652 SENSOR_ATTR_2(fan3_beep, S_IRUGO|S_IWUSR, show_fan_beep,
653 store_fan_beep, 0, 2),
654
655 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
656 SENSOR_ATTR_2(fan4_full_speed, S_IRUGO|S_IWUSR,
657 show_fan_full_speed,
658 store_fan_full_speed, 0, 3),
659 SENSOR_ATTR_2(fan4_beep, S_IRUGO|S_IWUSR, show_fan_beep,
660 store_fan_beep, 0, 3),
661 SENSOR_ATTR_2(fan4_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 3),
662
663 SENSOR_ATTR_2(pwm4, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 3),
664 SENSOR_ATTR_2(pwm4_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
665 store_pwm_enable, 0, 3),
666 SENSOR_ATTR_2(pwm4_interpolate, S_IRUGO|S_IWUSR,
667 show_pwm_interpolate, store_pwm_interpolate, 0, 3),
668 SENSOR_ATTR_2(pwm4_auto_channels_temp, S_IRUGO|S_IWUSR, 674 SENSOR_ATTR_2(pwm4_auto_channels_temp, S_IRUGO|S_IWUSR,
669 show_pwm_auto_point_channel, 675 show_pwm_auto_point_channel,
670 store_pwm_auto_point_channel, 0, 3), 676 store_pwm_auto_point_channel, 0, 3),
@@ -705,14 +711,20 @@ static struct sensor_device_attribute_2 f71882fg_fan_attr[] = {
705 show_pwm_auto_point_temp_hyst, NULL, 2, 3), 711 show_pwm_auto_point_temp_hyst, NULL, 2, 3),
706 SENSOR_ATTR_2(pwm4_auto_point4_temp_hyst, S_IRUGO, 712 SENSOR_ATTR_2(pwm4_auto_point4_temp_hyst, S_IRUGO,
707 show_pwm_auto_point_temp_hyst, NULL, 3, 3), 713 show_pwm_auto_point_temp_hyst, NULL, 3, 3),
708}; 714} };
709 715
710/* Fan / PWM attr for the f8000, zones mapped to temp instead of to pwm! 716/* Fan attr specific to the f8000 (4th fan input can only measure speed) */
711 Also the register block at offset A0 maps to TEMP1 (so our temp2, as the
712 F8000 starts counting temps at 0), B0 maps the TEMP2 and C0 maps to TEMP0 */
713static struct sensor_device_attribute_2 f8000_fan_attr[] = { 717static struct sensor_device_attribute_2 f8000_fan_attr[] = {
714 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3), 718 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
719};
715 720
721/* PWM attr for the f8000, zones mapped to temp instead of to pwm!
722 Also the register block at offset A0 maps to TEMP1 (so our temp2, as the
723 F8000 starts counting temps at 0), B0 maps the TEMP2 and C0 maps to TEMP0 */
724static struct sensor_device_attribute_2 f8000_auto_pwm_attr[] = {
725 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
726 show_pwm_auto_point_channel,
727 store_pwm_auto_point_channel, 0, 0),
716 SENSOR_ATTR_2(temp1_auto_point1_pwm, S_IRUGO|S_IWUSR, 728 SENSOR_ATTR_2(temp1_auto_point1_pwm, S_IRUGO|S_IWUSR,
717 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, 729 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
718 0, 2), 730 0, 2),
@@ -751,6 +763,9 @@ static struct sensor_device_attribute_2 f8000_fan_attr[] = {
751 SENSOR_ATTR_2(temp1_auto_point4_temp_hyst, S_IRUGO, 763 SENSOR_ATTR_2(temp1_auto_point4_temp_hyst, S_IRUGO,
752 show_pwm_auto_point_temp_hyst, NULL, 3, 2), 764 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
753 765
766 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
767 show_pwm_auto_point_channel,
768 store_pwm_auto_point_channel, 0, 1),
754 SENSOR_ATTR_2(temp2_auto_point1_pwm, S_IRUGO|S_IWUSR, 769 SENSOR_ATTR_2(temp2_auto_point1_pwm, S_IRUGO|S_IWUSR,
755 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, 770 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
756 0, 0), 771 0, 0),
@@ -789,6 +804,9 @@ static struct sensor_device_attribute_2 f8000_fan_attr[] = {
789 SENSOR_ATTR_2(temp2_auto_point4_temp_hyst, S_IRUGO, 804 SENSOR_ATTR_2(temp2_auto_point4_temp_hyst, S_IRUGO,
790 show_pwm_auto_point_temp_hyst, NULL, 3, 0), 805 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
791 806
807 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
808 show_pwm_auto_point_channel,
809 store_pwm_auto_point_channel, 0, 2),
792 SENSOR_ATTR_2(temp3_auto_point1_pwm, S_IRUGO|S_IWUSR, 810 SENSOR_ATTR_2(temp3_auto_point1_pwm, S_IRUGO|S_IWUSR,
793 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, 811 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
794 0, 1), 812 0, 1),
@@ -929,7 +947,7 @@ static struct f71882fg_data *f71882fg_update_device(struct device *dev)
929 /* Update once every 60 seconds */ 947 /* Update once every 60 seconds */
930 if ( time_after(jiffies, data->last_limits + 60 * HZ ) || 948 if ( time_after(jiffies, data->last_limits + 60 * HZ ) ||
931 !data->valid) { 949 !data->valid) {
932 if (data->type == f71882fg) { 950 if (data->type == f71882fg || data->type == f71889fg) {
933 data->in1_max = 951 data->in1_max =
934 f71882fg_read8(data, F71882FG_REG_IN1_HIGH); 952 f71882fg_read8(data, F71882FG_REG_IN1_HIGH);
935 data->in_beep = 953 data->in_beep =
@@ -951,7 +969,8 @@ static struct f71882fg_data *f71882fg_update_device(struct device *dev)
951 F71882FG_REG_TEMP_HYST(1)); 969 F71882FG_REG_TEMP_HYST(1));
952 } 970 }
953 971
954 if (data->type == f71862fg || data->type == f71882fg) { 972 if (data->type == f71862fg || data->type == f71882fg ||
973 data->type == f71889fg) {
955 data->fan_beep = f71882fg_read8(data, 974 data->fan_beep = f71882fg_read8(data,
956 F71882FG_REG_FAN_BEEP); 975 F71882FG_REG_FAN_BEEP);
957 data->temp_beep = f71882fg_read8(data, 976 data->temp_beep = f71882fg_read8(data,
@@ -961,15 +980,33 @@ static struct f71882fg_data *f71882fg_update_device(struct device *dev)
961 data->temp_type[2] = (reg & 0x04) ? 2 : 4; 980 data->temp_type[2] = (reg & 0x04) ? 2 : 4;
962 data->temp_type[3] = (reg & 0x08) ? 2 : 4; 981 data->temp_type[3] = (reg & 0x08) ? 2 : 4;
963 } 982 }
964 reg2 = f71882fg_read8(data, F71882FG_REG_PECI); 983 /* Determine temp index 1 sensor type */
965 if ((reg2 & 0x03) == 0x01) 984 if (data->type == f71889fg) {
966 data->temp_type[1] = 6 /* PECI */; 985 reg2 = f71882fg_read8(data, F71882FG_REG_START);
967 else if ((reg2 & 0x03) == 0x02) 986 switch ((reg2 & 0x60) >> 5) {
968 data->temp_type[1] = 5 /* AMDSI */; 987 case 0x00: /* BJT / Thermistor */
969 else if (data->type == f71862fg || data->type == f71882fg) 988 data->temp_type[1] = (reg & 0x02) ? 2 : 4;
970 data->temp_type[1] = (reg & 0x02) ? 2 : 4; 989 break;
971 else 990 case 0x01: /* AMDSI */
972 data->temp_type[1] = 2; /* Only supports BJT */ 991 data->temp_type[1] = 5;
992 break;
993 case 0x02: /* PECI */
994 case 0x03: /* Ibex Peak ?? Report as PECI for now */
995 data->temp_type[1] = 6;
996 break;
997 }
998 } else {
999 reg2 = f71882fg_read8(data, F71882FG_REG_PECI);
1000 if ((reg2 & 0x03) == 0x01)
1001 data->temp_type[1] = 6; /* PECI */
1002 else if ((reg2 & 0x03) == 0x02)
1003 data->temp_type[1] = 5; /* AMDSI */
1004 else if (data->type == f71862fg ||
1005 data->type == f71882fg)
1006 data->temp_type[1] = (reg & 0x02) ? 2 : 4;
1007 else /* f71858fg and f8000 only support BJT */
1008 data->temp_type[1] = 2;
1009 }
973 1010
974 data->pwm_enable = f71882fg_read8(data, 1011 data->pwm_enable = f71882fg_read8(data,
975 F71882FG_REG_PWM_ENABLE); 1012 F71882FG_REG_PWM_ENABLE);
@@ -1046,7 +1083,7 @@ static struct f71882fg_data *f71882fg_update_device(struct device *dev)
1046 if (data->type == f8000) 1083 if (data->type == f8000)
1047 data->fan[3] = f71882fg_read16(data, 1084 data->fan[3] = f71882fg_read16(data,
1048 F71882FG_REG_FAN(3)); 1085 F71882FG_REG_FAN(3));
1049 if (data->type == f71882fg) 1086 if (data->type == f71882fg || data->type == f71889fg)
1050 data->in_status = f71882fg_read8(data, 1087 data->in_status = f71882fg_read8(data,
1051 F71882FG_REG_IN_STATUS); 1088 F71882FG_REG_IN_STATUS);
1052 for (nr = 0; nr < nr_ins; nr++) 1089 for (nr = 0; nr < nr_ins; nr++)
@@ -1764,7 +1801,11 @@ static ssize_t store_pwm_auto_point_temp(struct device *dev,
1764 int pwm = to_sensor_dev_attr_2(devattr)->index; 1801 int pwm = to_sensor_dev_attr_2(devattr)->index;
1765 int point = to_sensor_dev_attr_2(devattr)->nr; 1802 int point = to_sensor_dev_attr_2(devattr)->nr;
1766 long val = simple_strtol(buf, NULL, 10) / 1000; 1803 long val = simple_strtol(buf, NULL, 10) / 1000;
1767 val = SENSORS_LIMIT(val, 0, 255); 1804
1805 if (data->type == f71889fg)
1806 val = SENSORS_LIMIT(val, -128, 127);
1807 else
1808 val = SENSORS_LIMIT(val, 0, 127);
1768 1809
1769 mutex_lock(&data->update_lock); 1810 mutex_lock(&data->update_lock);
1770 f71882fg_write8(data, F71882FG_REG_POINT_TEMP(pwm, point), val); 1811 f71882fg_write8(data, F71882FG_REG_POINT_TEMP(pwm, point), val);
@@ -1794,6 +1835,15 @@ static int __devinit f71882fg_create_sysfs_files(struct platform_device *pdev,
1794 return 0; 1835 return 0;
1795} 1836}
1796 1837
1838static void f71882fg_remove_sysfs_files(struct platform_device *pdev,
1839 struct sensor_device_attribute_2 *attr, int count)
1840{
1841 int i;
1842
1843 for (i = 0; i < count; i++)
1844 device_remove_file(&pdev->dev, &attr[i].dev_attr);
1845}
1846
1797static int __devinit f71882fg_probe(struct platform_device *pdev) 1847static int __devinit f71882fg_probe(struct platform_device *pdev)
1798{ 1848{
1799 struct f71882fg_data *data; 1849 struct f71882fg_data *data;
@@ -1846,16 +1896,17 @@ static int __devinit f71882fg_probe(struct platform_device *pdev)
1846 ARRAY_SIZE(f71858fg_in_temp_attr)); 1896 ARRAY_SIZE(f71858fg_in_temp_attr));
1847 break; 1897 break;
1848 case f71882fg: 1898 case f71882fg:
1899 case f71889fg:
1849 err = f71882fg_create_sysfs_files(pdev, 1900 err = f71882fg_create_sysfs_files(pdev,
1850 f71882fg_in_temp_attr, 1901 fxxxx_in1_alarm_attr,
1851 ARRAY_SIZE(f71882fg_in_temp_attr)); 1902 ARRAY_SIZE(fxxxx_in1_alarm_attr));
1852 if (err) 1903 if (err)
1853 goto exit_unregister_sysfs; 1904 goto exit_unregister_sysfs;
1854 /* fall through! */ 1905 /* fall through! */
1855 case f71862fg: 1906 case f71862fg:
1856 err = f71882fg_create_sysfs_files(pdev, 1907 err = f71882fg_create_sysfs_files(pdev,
1857 f718x2fg_in_temp_attr, 1908 fxxxx_in_temp_attr,
1858 ARRAY_SIZE(f718x2fg_in_temp_attr)); 1909 ARRAY_SIZE(fxxxx_in_temp_attr));
1859 break; 1910 break;
1860 case f8000: 1911 case f8000:
1861 err = f71882fg_create_sysfs_files(pdev, 1912 err = f71882fg_create_sysfs_files(pdev,
@@ -1883,6 +1934,7 @@ static int __devinit f71882fg_probe(struct platform_device *pdev)
1883 err = (data->pwm_enable & 0x15) != 0x15; 1934 err = (data->pwm_enable & 0x15) != 0x15;
1884 break; 1935 break;
1885 case f71882fg: 1936 case f71882fg:
1937 case f71889fg:
1886 err = 0; 1938 err = 0;
1887 break; 1939 break;
1888 case f8000: 1940 case f8000:
@@ -1897,34 +1949,55 @@ static int __devinit f71882fg_probe(struct platform_device *pdev)
1897 goto exit_unregister_sysfs; 1949 goto exit_unregister_sysfs;
1898 } 1950 }
1899 1951
1900 err = f71882fg_create_sysfs_files(pdev, fxxxx_fan_attr, 1952 err = f71882fg_create_sysfs_files(pdev, &fxxxx_fan_attr[0][0],
1901 ARRAY_SIZE(fxxxx_fan_attr)); 1953 ARRAY_SIZE(fxxxx_fan_attr[0]) * nr_fans);
1902 if (err) 1954 if (err)
1903 goto exit_unregister_sysfs; 1955 goto exit_unregister_sysfs;
1904 1956
1905 switch (data->type) { 1957 if (data->type == f71862fg || data->type == f71882fg ||
1906 case f71862fg: 1958 data->type == f71889fg) {
1907 err = f71882fg_create_sysfs_files(pdev,
1908 f71862fg_fan_attr,
1909 ARRAY_SIZE(f71862fg_fan_attr));
1910 break;
1911 case f71882fg:
1912 err = f71882fg_create_sysfs_files(pdev, 1959 err = f71882fg_create_sysfs_files(pdev,
1913 f71882fg_fan_attr, 1960 fxxxx_fan_beep_attr, nr_fans);
1914 ARRAY_SIZE(f71882fg_fan_attr));
1915 if (err) 1961 if (err)
1916 goto exit_unregister_sysfs; 1962 goto exit_unregister_sysfs;
1917 /* fall through! */ 1963 }
1918 case f71858fg: 1964
1965 switch (data->type) {
1966 case f71862fg:
1919 err = f71882fg_create_sysfs_files(pdev, 1967 err = f71882fg_create_sysfs_files(pdev,
1920 f71882fg_f71858fg_fan_attr, 1968 f71862fg_auto_pwm_attr,
1921 ARRAY_SIZE(f71882fg_f71858fg_fan_attr)); 1969 ARRAY_SIZE(f71862fg_auto_pwm_attr));
1922 break; 1970 break;
1923 case f8000: 1971 case f8000:
1924 err = f71882fg_create_sysfs_files(pdev, 1972 err = f71882fg_create_sysfs_files(pdev,
1925 f8000_fan_attr, 1973 f8000_fan_attr,
1926 ARRAY_SIZE(f8000_fan_attr)); 1974 ARRAY_SIZE(f8000_fan_attr));
1975 if (err)
1976 goto exit_unregister_sysfs;
1977 err = f71882fg_create_sysfs_files(pdev,
1978 f8000_auto_pwm_attr,
1979 ARRAY_SIZE(f8000_auto_pwm_attr));
1927 break; 1980 break;
1981 case f71889fg:
1982 for (i = 0; i < nr_fans; i++) {
1983 data->pwm_auto_point_mapping[i] =
1984 f71882fg_read8(data,
1985 F71882FG_REG_POINT_MAPPING(i));
1986 if (data->pwm_auto_point_mapping[i] & 0x80)
1987 break;
1988 }
1989 if (i != nr_fans) {
1990 dev_warn(&pdev->dev,
1991 "Auto pwm controlled by raw digital "
1992 "data, disabling pwm auto_point "
1993 "sysfs attributes\n");
1994 break;
1995 }
1996 /* fall through */
1997 default: /* f71858fg / f71882fg */
1998 err = f71882fg_create_sysfs_files(pdev,
1999 &fxxxx_auto_pwm_attr[0][0],
2000 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans);
1928 } 2001 }
1929 if (err) 2002 if (err)
1930 goto exit_unregister_sysfs; 2003 goto exit_unregister_sysfs;
@@ -1954,33 +2027,76 @@ exit_free:
1954 2027
1955static int f71882fg_remove(struct platform_device *pdev) 2028static int f71882fg_remove(struct platform_device *pdev)
1956{ 2029{
1957 int i;
1958 struct f71882fg_data *data = platform_get_drvdata(pdev); 2030 struct f71882fg_data *data = platform_get_drvdata(pdev);
2031 int nr_fans = (data->type == f71882fg) ? 4 : 3;
2032 u8 start_reg = f71882fg_read8(data, F71882FG_REG_START);
1959 2033
1960 platform_set_drvdata(pdev, NULL); 2034 platform_set_drvdata(pdev, NULL);
1961 if (data->hwmon_dev) 2035 if (data->hwmon_dev)
1962 hwmon_device_unregister(data->hwmon_dev); 2036 hwmon_device_unregister(data->hwmon_dev);
1963 2037
1964 /* Note we are not looping over all attr arrays we have as the ones
1965 below are supersets of the ones skipped. */
1966 device_remove_file(&pdev->dev, &dev_attr_name); 2038 device_remove_file(&pdev->dev, &dev_attr_name);
1967 2039
1968 for (i = 0; i < ARRAY_SIZE(f718x2fg_in_temp_attr); i++) 2040 if (start_reg & 0x01) {
1969 device_remove_file(&pdev->dev, 2041 switch (data->type) {
1970 &f718x2fg_in_temp_attr[i].dev_attr); 2042 case f71858fg:
1971 2043 if (data->temp_config & 0x10)
1972 for (i = 0; i < ARRAY_SIZE(f71882fg_in_temp_attr); i++) 2044 f71882fg_remove_sysfs_files(pdev,
1973 device_remove_file(&pdev->dev, 2045 f8000_in_temp_attr,
1974 &f71882fg_in_temp_attr[i].dev_attr); 2046 ARRAY_SIZE(f8000_in_temp_attr));
2047 else
2048 f71882fg_remove_sysfs_files(pdev,
2049 f71858fg_in_temp_attr,
2050 ARRAY_SIZE(f71858fg_in_temp_attr));
2051 break;
2052 case f71882fg:
2053 case f71889fg:
2054 f71882fg_remove_sysfs_files(pdev,
2055 fxxxx_in1_alarm_attr,
2056 ARRAY_SIZE(fxxxx_in1_alarm_attr));
2057 /* fall through! */
2058 case f71862fg:
2059 f71882fg_remove_sysfs_files(pdev,
2060 fxxxx_in_temp_attr,
2061 ARRAY_SIZE(fxxxx_in_temp_attr));
2062 break;
2063 case f8000:
2064 f71882fg_remove_sysfs_files(pdev,
2065 f8000_in_temp_attr,
2066 ARRAY_SIZE(f8000_in_temp_attr));
2067 break;
2068 }
2069 }
1975 2070
1976 for (i = 0; i < ARRAY_SIZE(fxxxx_fan_attr); i++) 2071 if (start_reg & 0x02) {
1977 device_remove_file(&pdev->dev, &fxxxx_fan_attr[i].dev_attr); 2072 f71882fg_remove_sysfs_files(pdev, &fxxxx_fan_attr[0][0],
2073 ARRAY_SIZE(fxxxx_fan_attr[0]) * nr_fans);
1978 2074
1979 for (i = 0; i < ARRAY_SIZE(f71882fg_fan_attr); i++) 2075 if (data->type == f71862fg || data->type == f71882fg ||
1980 device_remove_file(&pdev->dev, &f71882fg_fan_attr[i].dev_attr); 2076 data->type == f71889fg)
2077 f71882fg_remove_sysfs_files(pdev,
2078 fxxxx_fan_beep_attr, nr_fans);
1981 2079
1982 for (i = 0; i < ARRAY_SIZE(f8000_fan_attr); i++) 2080 switch (data->type) {
1983 device_remove_file(&pdev->dev, &f8000_fan_attr[i].dev_attr); 2081 case f71862fg:
2082 f71882fg_remove_sysfs_files(pdev,
2083 f71862fg_auto_pwm_attr,
2084 ARRAY_SIZE(f71862fg_auto_pwm_attr));
2085 break;
2086 case f8000:
2087 f71882fg_remove_sysfs_files(pdev,
2088 f8000_fan_attr,
2089 ARRAY_SIZE(f8000_fan_attr));
2090 f71882fg_remove_sysfs_files(pdev,
2091 f8000_auto_pwm_attr,
2092 ARRAY_SIZE(f8000_auto_pwm_attr));
2093 break;
2094 default: /* f71858fg / f71882fg / f71889fg */
2095 f71882fg_remove_sysfs_files(pdev,
2096 &fxxxx_auto_pwm_attr[0][0],
2097 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans);
2098 }
2099 }
1984 2100
1985 kfree(data); 2101 kfree(data);
1986 2102
@@ -2012,11 +2128,15 @@ static int __init f71882fg_find(int sioaddr, unsigned short *address,
2012 case SIO_F71882_ID: 2128 case SIO_F71882_ID:
2013 sio_data->type = f71882fg; 2129 sio_data->type = f71882fg;
2014 break; 2130 break;
2131 case SIO_F71889_ID:
2132 sio_data->type = f71889fg;
2133 break;
2015 case SIO_F8000_ID: 2134 case SIO_F8000_ID:
2016 sio_data->type = f8000; 2135 sio_data->type = f8000;
2017 break; 2136 break;
2018 default: 2137 default:
2019 printk(KERN_INFO DRVNAME ": Unsupported Fintek device\n"); 2138 printk(KERN_INFO DRVNAME ": Unsupported Fintek device: %04x\n",
2139 (unsigned int)devid);
2020 goto exit; 2140 goto exit;
2021 } 2141 }
2022 2142
diff --git a/drivers/hwmon/f75375s.c b/drivers/hwmon/f75375s.c
index e2107e533ede..bad2cf3ef4a4 100644
--- a/drivers/hwmon/f75375s.c
+++ b/drivers/hwmon/f75375s.c
@@ -35,12 +35,12 @@
35#include <linux/err.h> 35#include <linux/err.h>
36#include <linux/mutex.h> 36#include <linux/mutex.h>
37#include <linux/f75375s.h> 37#include <linux/f75375s.h>
38#include <linux/slab.h>
38 39
39/* Addresses to scan */ 40/* Addresses to scan */
40static const unsigned short normal_i2c[] = { 0x2d, 0x2e, I2C_CLIENT_END }; 41static const unsigned short normal_i2c[] = { 0x2d, 0x2e, I2C_CLIENT_END };
41 42
42/* Insmod parameters */ 43enum chips { f75373, f75375 };
43I2C_CLIENT_INSMOD_2(f75373, f75375);
44 44
45/* Fintek F75375 registers */ 45/* Fintek F75375 registers */
46#define F75375_REG_CONFIG0 0x0 46#define F75375_REG_CONFIG0 0x0
@@ -113,7 +113,7 @@ struct f75375_data {
113 s8 temp_max_hyst[2]; 113 s8 temp_max_hyst[2];
114}; 114};
115 115
116static int f75375_detect(struct i2c_client *client, int kind, 116static int f75375_detect(struct i2c_client *client,
117 struct i2c_board_info *info); 117 struct i2c_board_info *info);
118static int f75375_probe(struct i2c_client *client, 118static int f75375_probe(struct i2c_client *client,
119 const struct i2c_device_id *id); 119 const struct i2c_device_id *id);
@@ -135,7 +135,7 @@ static struct i2c_driver f75375_driver = {
135 .remove = f75375_remove, 135 .remove = f75375_remove,
136 .id_table = f75375_id, 136 .id_table = f75375_id,
137 .detect = f75375_detect, 137 .detect = f75375_detect,
138 .address_data = &addr_data, 138 .address_list = normal_i2c,
139}; 139};
140 140
141static inline int f75375_read8(struct i2c_client *client, u8 reg) 141static inline int f75375_read8(struct i2c_client *client, u8 reg)
@@ -677,34 +677,24 @@ static int f75375_remove(struct i2c_client *client)
677} 677}
678 678
679/* Return 0 if detection is successful, -ENODEV otherwise */ 679/* Return 0 if detection is successful, -ENODEV otherwise */
680static int f75375_detect(struct i2c_client *client, int kind, 680static int f75375_detect(struct i2c_client *client,
681 struct i2c_board_info *info) 681 struct i2c_board_info *info)
682{ 682{
683 struct i2c_adapter *adapter = client->adapter; 683 struct i2c_adapter *adapter = client->adapter;
684 u8 version = 0; 684 u16 vendid, chipid;
685 const char *name = ""; 685 u8 version;
686 686 const char *name;
687 if (kind < 0) {
688 u16 vendid = f75375_read16(client, F75375_REG_VENDOR);
689 u16 chipid = f75375_read16(client, F75375_CHIP_ID);
690 version = f75375_read8(client, F75375_REG_VERSION);
691 if (chipid == 0x0306 && vendid == 0x1934) {
692 kind = f75375;
693 } else if (chipid == 0x0204 && vendid == 0x1934) {
694 kind = f75373;
695 } else {
696 dev_err(&adapter->dev,
697 "failed,%02X,%02X,%02X\n",
698 chipid, version, vendid);
699 return -ENODEV;
700 }
701 }
702 687
703 if (kind == f75375) { 688 vendid = f75375_read16(client, F75375_REG_VENDOR);
689 chipid = f75375_read16(client, F75375_CHIP_ID);
690 if (chipid == 0x0306 && vendid == 0x1934)
704 name = "f75375"; 691 name = "f75375";
705 } else if (kind == f75373) { 692 else if (chipid == 0x0204 && vendid == 0x1934)
706 name = "f75373"; 693 name = "f75373";
707 } 694 else
695 return -ENODEV;
696
697 version = f75375_read8(client, F75375_REG_VERSION);
708 dev_info(&adapter->dev, "found %s version: %02X\n", name, version); 698 dev_info(&adapter->dev, "found %s version: %02X\n", name, version);
709 strlcpy(info->type, name, I2C_NAME_SIZE); 699 strlcpy(info->type, name, I2C_NAME_SIZE);
710 700
diff --git a/drivers/hwmon/fschmd.c b/drivers/hwmon/fschmd.c
index da1b1f9488af..0627f7a5b9b8 100644
--- a/drivers/hwmon/fschmd.c
+++ b/drivers/hwmon/fschmd.c
@@ -56,7 +56,8 @@ static int nowayout = WATCHDOG_NOWAYOUT;
56module_param(nowayout, int, 0); 56module_param(nowayout, int, 0);
57MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" 57MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
58 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); 58 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
59I2C_CLIENT_INSMOD_7(fscpos, fscher, fscscy, fschrc, fschmd, fschds, fscsyl); 59
60enum chips { fscpos, fscher, fscscy, fschrc, fschmd, fschds, fscsyl };
60 61
61/* 62/*
62 * The FSCHMD registers and other defines 63 * The FSCHMD registers and other defines
@@ -221,7 +222,7 @@ static const int FSCHMD_NO_TEMP_SENSORS[7] = { 3, 3, 4, 3, 5, 5, 11 };
221 222
222static int fschmd_probe(struct i2c_client *client, 223static int fschmd_probe(struct i2c_client *client,
223 const struct i2c_device_id *id); 224 const struct i2c_device_id *id);
224static int fschmd_detect(struct i2c_client *client, int kind, 225static int fschmd_detect(struct i2c_client *client,
225 struct i2c_board_info *info); 226 struct i2c_board_info *info);
226static int fschmd_remove(struct i2c_client *client); 227static int fschmd_remove(struct i2c_client *client);
227static struct fschmd_data *fschmd_update_device(struct device *dev); 228static struct fschmd_data *fschmd_update_device(struct device *dev);
@@ -251,7 +252,7 @@ static struct i2c_driver fschmd_driver = {
251 .remove = fschmd_remove, 252 .remove = fschmd_remove,
252 .id_table = fschmd_id, 253 .id_table = fschmd_id,
253 .detect = fschmd_detect, 254 .detect = fschmd_detect,
254 .address_data = &addr_data, 255 .address_list = normal_i2c,
255}; 256};
256 257
257/* 258/*
@@ -266,7 +267,7 @@ struct fschmd_data {
266 struct list_head list; /* member of the watchdog_data_list */ 267 struct list_head list; /* member of the watchdog_data_list */
267 struct kref kref; 268 struct kref kref;
268 struct miscdevice watchdog_miscdev; 269 struct miscdevice watchdog_miscdev;
269 int kind; 270 enum chips kind;
270 unsigned long watchdog_is_open; 271 unsigned long watchdog_is_open;
271 char watchdog_expect_close; 272 char watchdog_expect_close;
272 char watchdog_name[10]; /* must be unique to avoid sysfs conflict */ 273 char watchdog_name[10]; /* must be unique to avoid sysfs conflict */
@@ -324,8 +325,7 @@ static ssize_t show_in_value(struct device *dev,
324 int index = to_sensor_dev_attr(devattr)->index; 325 int index = to_sensor_dev_attr(devattr)->index;
325 struct fschmd_data *data = fschmd_update_device(dev); 326 struct fschmd_data *data = fschmd_update_device(dev);
326 327
327 /* fscher / fschrc - 1 as data->kind is an array index, not a chips */ 328 if (data->kind == fscher || data->kind >= fschrc)
328 if (data->kind == (fscher - 1) || data->kind >= (fschrc - 1))
329 return sprintf(buf, "%d\n", (data->volt[index] * dmi_vref * 329 return sprintf(buf, "%d\n", (data->volt[index] * dmi_vref *
330 dmi_mult[index]) / 255 + dmi_offset[index]); 330 dmi_mult[index]) / 255 + dmi_offset[index]);
331 else 331 else
@@ -491,7 +491,7 @@ static ssize_t show_pwm_auto_point1_pwm(struct device *dev,
491 int val = data->fan_min[index]; 491 int val = data->fan_min[index];
492 492
493 /* 0 = allow turning off (except on the syl), 1-255 = 50-100% */ 493 /* 0 = allow turning off (except on the syl), 1-255 = 50-100% */
494 if (val || data->kind == fscsyl - 1) 494 if (val || data->kind == fscsyl)
495 val = val / 2 + 128; 495 val = val / 2 + 128;
496 496
497 return sprintf(buf, "%d\n", val); 497 return sprintf(buf, "%d\n", val);
@@ -505,7 +505,7 @@ static ssize_t store_pwm_auto_point1_pwm(struct device *dev,
505 unsigned long v = simple_strtoul(buf, NULL, 10); 505 unsigned long v = simple_strtoul(buf, NULL, 10);
506 506
507 /* reg: 0 = allow turning off (except on the syl), 1-255 = 50-100% */ 507 /* reg: 0 = allow turning off (except on the syl), 1-255 = 50-100% */
508 if (v || data->kind == fscsyl - 1) { 508 if (v || data->kind == fscsyl) {
509 v = SENSORS_LIMIT(v, 128, 255); 509 v = SENSORS_LIMIT(v, 128, 255);
510 v = (v - 128) * 2 + 1; 510 v = (v - 128) * 2 + 1;
511 } 511 }
@@ -767,6 +767,7 @@ leave:
767static int watchdog_open(struct inode *inode, struct file *filp) 767static int watchdog_open(struct inode *inode, struct file *filp)
768{ 768{
769 struct fschmd_data *pos, *data = NULL; 769 struct fschmd_data *pos, *data = NULL;
770 int watchdog_is_open;
770 771
771 /* We get called from drivers/char/misc.c with misc_mtx hold, and we 772 /* We get called from drivers/char/misc.c with misc_mtx hold, and we
772 call misc_register() from fschmd_probe() with watchdog_data_mutex 773 call misc_register() from fschmd_probe() with watchdog_data_mutex
@@ -781,10 +782,12 @@ static int watchdog_open(struct inode *inode, struct file *filp)
781 } 782 }
782 } 783 }
783 /* Note we can never not have found data, so we don't check for this */ 784 /* Note we can never not have found data, so we don't check for this */
784 kref_get(&data->kref); 785 watchdog_is_open = test_and_set_bit(0, &data->watchdog_is_open);
786 if (!watchdog_is_open)
787 kref_get(&data->kref);
785 mutex_unlock(&watchdog_data_mutex); 788 mutex_unlock(&watchdog_data_mutex);
786 789
787 if (test_and_set_bit(0, &data->watchdog_is_open)) 790 if (watchdog_is_open)
788 return -EBUSY; 791 return -EBUSY;
789 792
790 /* Start the watchdog */ 793 /* Start the watchdog */
@@ -1000,45 +1003,40 @@ static void fschmd_dmi_decode(const struct dmi_header *header, void *dummy)
1000 } 1003 }
1001} 1004}
1002 1005
1003static int fschmd_detect(struct i2c_client *client, int kind, 1006static int fschmd_detect(struct i2c_client *client,
1004 struct i2c_board_info *info) 1007 struct i2c_board_info *info)
1005{ 1008{
1009 enum chips kind;
1006 struct i2c_adapter *adapter = client->adapter; 1010 struct i2c_adapter *adapter = client->adapter;
1011 char id[4];
1007 1012
1008 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1013 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1009 return -ENODEV; 1014 return -ENODEV;
1010 1015
1011 /* Detect & Identify the chip */ 1016 /* Detect & Identify the chip */
1012 if (kind <= 0) { 1017 id[0] = i2c_smbus_read_byte_data(client, FSCHMD_REG_IDENT_0);
1013 char id[4]; 1018 id[1] = i2c_smbus_read_byte_data(client, FSCHMD_REG_IDENT_1);
1014 1019 id[2] = i2c_smbus_read_byte_data(client, FSCHMD_REG_IDENT_2);
1015 id[0] = i2c_smbus_read_byte_data(client, 1020 id[3] = '\0';
1016 FSCHMD_REG_IDENT_0); 1021
1017 id[1] = i2c_smbus_read_byte_data(client, 1022 if (!strcmp(id, "PEG"))
1018 FSCHMD_REG_IDENT_1); 1023 kind = fscpos;
1019 id[2] = i2c_smbus_read_byte_data(client, 1024 else if (!strcmp(id, "HER"))
1020 FSCHMD_REG_IDENT_2); 1025 kind = fscher;
1021 id[3] = '\0'; 1026 else if (!strcmp(id, "SCY"))
1022 1027 kind = fscscy;
1023 if (!strcmp(id, "PEG")) 1028 else if (!strcmp(id, "HRC"))
1024 kind = fscpos; 1029 kind = fschrc;
1025 else if (!strcmp(id, "HER")) 1030 else if (!strcmp(id, "HMD"))
1026 kind = fscher; 1031 kind = fschmd;
1027 else if (!strcmp(id, "SCY")) 1032 else if (!strcmp(id, "HDS"))
1028 kind = fscscy; 1033 kind = fschds;
1029 else if (!strcmp(id, "HRC")) 1034 else if (!strcmp(id, "SYL"))
1030 kind = fschrc; 1035 kind = fscsyl;
1031 else if (!strcmp(id, "HMD")) 1036 else
1032 kind = fschmd; 1037 return -ENODEV;
1033 else if (!strcmp(id, "HDS"))
1034 kind = fschds;
1035 else if (!strcmp(id, "SYL"))
1036 kind = fscsyl;
1037 else
1038 return -ENODEV;
1039 }
1040 1038
1041 strlcpy(info->type, fschmd_id[kind - 1].name, I2C_NAME_SIZE); 1039 strlcpy(info->type, fschmd_id[kind].name, I2C_NAME_SIZE);
1042 1040
1043 return 0; 1041 return 0;
1044} 1042}
@@ -1066,6 +1064,7 @@ static int fschmd_probe(struct i2c_client *client,
1066 (where the client is found through a data ptr instead of the 1064 (where the client is found through a data ptr instead of the
1067 otherway around) */ 1065 otherway around) */
1068 data->client = client; 1066 data->client = client;
1067 data->kind = kind;
1069 1068
1070 if (kind == fscpos) { 1069 if (kind == fscpos) {
1071 /* The Poseidon has hardwired temp limits, fill these 1070 /* The Poseidon has hardwired temp limits, fill these
@@ -1086,9 +1085,6 @@ static int fschmd_probe(struct i2c_client *client,
1086 } 1085 }
1087 } 1086 }
1088 1087
1089 /* i2c kind goes from 1-6, we want from 0-5 to address arrays */
1090 data->kind = kind - 1;
1091
1092 /* Read in some never changing registers */ 1088 /* Read in some never changing registers */
1093 data->revision = i2c_smbus_read_byte_data(client, FSCHMD_REG_REVISION); 1089 data->revision = i2c_smbus_read_byte_data(client, FSCHMD_REG_REVISION);
1094 data->global_control = i2c_smbus_read_byte_data(client, 1090 data->global_control = i2c_smbus_read_byte_data(client,
diff --git a/drivers/hwmon/g760a.c b/drivers/hwmon/g760a.c
index 19c01a49f6be..09ea12e0a551 100644
--- a/drivers/hwmon/g760a.c
+++ b/drivers/hwmon/g760a.c
@@ -68,7 +68,7 @@ struct g760a_data {
68#define PWM_FROM_CNT(cnt) (0xff-(cnt)) 68#define PWM_FROM_CNT(cnt) (0xff-(cnt))
69#define PWM_TO_CNT(pwm) (0xff-(pwm)) 69#define PWM_TO_CNT(pwm) (0xff-(pwm))
70 70
71unsigned int rpm_from_cnt(u8 val, u32 clk, u16 div) 71static inline unsigned int rpm_from_cnt(u8 val, u32 clk, u16 div)
72{ 72{
73 return ((val == 0x00) ? 0 : ((clk*30)/(val*div))); 73 return ((val == 0x00) ? 0 : ((clk*30)/(val*div)));
74} 74}
diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c
index 7820df45d77a..e7ae5743e181 100644
--- a/drivers/hwmon/gl518sm.c
+++ b/drivers/hwmon/gl518sm.c
@@ -46,8 +46,7 @@
46/* Addresses to scan */ 46/* Addresses to scan */
47static const unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; 47static const unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
48 48
49/* Insmod parameters */ 49enum chips { gl518sm_r00, gl518sm_r80 };
50I2C_CLIENT_INSMOD_2(gl518sm_r00, gl518sm_r80);
51 50
52/* Many GL518 constants specified below */ 51/* Many GL518 constants specified below */
53 52
@@ -139,8 +138,7 @@ struct gl518_data {
139 138
140static int gl518_probe(struct i2c_client *client, 139static int gl518_probe(struct i2c_client *client,
141 const struct i2c_device_id *id); 140 const struct i2c_device_id *id);
142static int gl518_detect(struct i2c_client *client, int kind, 141static int gl518_detect(struct i2c_client *client, struct i2c_board_info *info);
143 struct i2c_board_info *info);
144static void gl518_init_client(struct i2c_client *client); 142static void gl518_init_client(struct i2c_client *client);
145static int gl518_remove(struct i2c_client *client); 143static int gl518_remove(struct i2c_client *client);
146static int gl518_read_value(struct i2c_client *client, u8 reg); 144static int gl518_read_value(struct i2c_client *client, u8 reg);
@@ -163,7 +161,7 @@ static struct i2c_driver gl518_driver = {
163 .remove = gl518_remove, 161 .remove = gl518_remove,
164 .id_table = gl518_id, 162 .id_table = gl518_id,
165 .detect = gl518_detect, 163 .detect = gl518_detect,
166 .address_data = &addr_data, 164 .address_list = normal_i2c,
167}; 165};
168 166
169/* 167/*
@@ -484,40 +482,24 @@ static const struct attribute_group gl518_group_r80 = {
484 */ 482 */
485 483
486/* Return 0 if detection is successful, -ENODEV otherwise */ 484/* Return 0 if detection is successful, -ENODEV otherwise */
487static int gl518_detect(struct i2c_client *client, int kind, 485static int gl518_detect(struct i2c_client *client, struct i2c_board_info *info)
488 struct i2c_board_info *info)
489{ 486{
490 struct i2c_adapter *adapter = client->adapter; 487 struct i2c_adapter *adapter = client->adapter;
491 int i; 488 int rev;
492 489
493 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | 490 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
494 I2C_FUNC_SMBUS_WORD_DATA)) 491 I2C_FUNC_SMBUS_WORD_DATA))
495 return -ENODEV; 492 return -ENODEV;
496 493
497 /* Now, we do the remaining detection. */ 494 /* Now, we do the remaining detection. */
498 495 if ((gl518_read_value(client, GL518_REG_CHIP_ID) != 0x80)
499 if (kind < 0) { 496 || (gl518_read_value(client, GL518_REG_CONF) & 0x80))
500 if ((gl518_read_value(client, GL518_REG_CHIP_ID) != 0x80) 497 return -ENODEV;
501 || (gl518_read_value(client, GL518_REG_CONF) & 0x80))
502 return -ENODEV;
503 }
504 498
505 /* Determine the chip type. */ 499 /* Determine the chip type. */
506 if (kind <= 0) { 500 rev = gl518_read_value(client, GL518_REG_REVISION);
507 i = gl518_read_value(client, GL518_REG_REVISION); 501 if (rev != 0x00 && rev != 0x80)
508 if (i == 0x00) { 502 return -ENODEV;
509 kind = gl518sm_r00;
510 } else if (i == 0x80) {
511 kind = gl518sm_r80;
512 } else {
513 if (kind <= 0)
514 dev_info(&adapter->dev,
515 "Ignoring 'force' parameter for unknown "
516 "chip at adapter %d, address 0x%02x\n",
517 i2c_adapter_id(adapter), client->addr);
518 return -ENODEV;
519 }
520 }
521 503
522 strlcpy(info->type, "gl518sm", I2C_NAME_SIZE); 504 strlcpy(info->type, "gl518sm", I2C_NAME_SIZE);
523 505
diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c
index 19616f2242b0..ec588026f0a9 100644
--- a/drivers/hwmon/gl520sm.c
+++ b/drivers/hwmon/gl520sm.c
@@ -41,9 +41,6 @@ MODULE_PARM_DESC(extra_sensor_type, "Type of extra sensor (0=autodetect, 1=tempe
41/* Addresses to scan */ 41/* Addresses to scan */
42static const unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; 42static const unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
43 43
44/* Insmod parameters */
45I2C_CLIENT_INSMOD_1(gl520sm);
46
47/* Many GL520 constants specified below 44/* Many GL520 constants specified below
48One of the inputs can be configured as either temp or voltage. 45One of the inputs can be configured as either temp or voltage.
49That's why _TEMP2 and _IN4 access the same register 46That's why _TEMP2 and _IN4 access the same register
@@ -81,8 +78,7 @@ static const u8 GL520_REG_TEMP_MAX_HYST[] = { 0x06, 0x18 };
81 78
82static int gl520_probe(struct i2c_client *client, 79static int gl520_probe(struct i2c_client *client,
83 const struct i2c_device_id *id); 80 const struct i2c_device_id *id);
84static int gl520_detect(struct i2c_client *client, int kind, 81static int gl520_detect(struct i2c_client *client, struct i2c_board_info *info);
85 struct i2c_board_info *info);
86static void gl520_init_client(struct i2c_client *client); 82static void gl520_init_client(struct i2c_client *client);
87static int gl520_remove(struct i2c_client *client); 83static int gl520_remove(struct i2c_client *client);
88static int gl520_read_value(struct i2c_client *client, u8 reg); 84static int gl520_read_value(struct i2c_client *client, u8 reg);
@@ -91,7 +87,7 @@ static struct gl520_data *gl520_update_device(struct device *dev);
91 87
92/* Driver data */ 88/* Driver data */
93static const struct i2c_device_id gl520_id[] = { 89static const struct i2c_device_id gl520_id[] = {
94 { "gl520sm", gl520sm }, 90 { "gl520sm", 0 },
95 { } 91 { }
96}; 92};
97MODULE_DEVICE_TABLE(i2c, gl520_id); 93MODULE_DEVICE_TABLE(i2c, gl520_id);
@@ -105,7 +101,7 @@ static struct i2c_driver gl520_driver = {
105 .remove = gl520_remove, 101 .remove = gl520_remove,
106 .id_table = gl520_id, 102 .id_table = gl520_id,
107 .detect = gl520_detect, 103 .detect = gl520_detect,
108 .address_data = &addr_data, 104 .address_list = normal_i2c,
109}; 105};
110 106
111/* Client data */ 107/* Client data */
@@ -681,8 +677,7 @@ static const struct attribute_group gl520_group_opt = {
681 */ 677 */
682 678
683/* Return 0 if detection is successful, -ENODEV otherwise */ 679/* Return 0 if detection is successful, -ENODEV otherwise */
684static int gl520_detect(struct i2c_client *client, int kind, 680static int gl520_detect(struct i2c_client *client, struct i2c_board_info *info)
685 struct i2c_board_info *info)
686{ 681{
687 struct i2c_adapter *adapter = client->adapter; 682 struct i2c_adapter *adapter = client->adapter;
688 683
@@ -691,13 +686,11 @@ static int gl520_detect(struct i2c_client *client, int kind,
691 return -ENODEV; 686 return -ENODEV;
692 687
693 /* Determine the chip type. */ 688 /* Determine the chip type. */
694 if (kind < 0) { 689 if ((gl520_read_value(client, GL520_REG_CHIP_ID) != 0x20) ||
695 if ((gl520_read_value(client, GL520_REG_CHIP_ID) != 0x20) || 690 ((gl520_read_value(client, GL520_REG_REVISION) & 0x7f) != 0x00) ||
696 ((gl520_read_value(client, GL520_REG_REVISION) & 0x7f) != 0x00) || 691 ((gl520_read_value(client, GL520_REG_CONF) & 0x80) != 0x00)) {
697 ((gl520_read_value(client, GL520_REG_CONF) & 0x80) != 0x00)) { 692 dev_dbg(&client->dev, "Unknown chip type, skipping\n");
698 dev_dbg(&client->dev, "Unknown chip type, skipping\n"); 693 return -ENODEV;
699 return -ENODEV;
700 }
701 } 694 }
702 695
703 strlcpy(info->type, "gl520sm", I2C_NAME_SIZE); 696 strlcpy(info->type, "gl520sm", I2C_NAME_SIZE);
diff --git a/drivers/hwmon/hp_accel.c b/drivers/hwmon/hp_accel.c
index be475e844c2a..7580f55e67e3 100644
--- a/drivers/hwmon/hp_accel.c
+++ b/drivers/hwmon/hp_accel.c
@@ -217,6 +217,10 @@ static struct dmi_system_id lis3lv02d_dmi_ids[] = {
217 AXIS_DMI_MATCH("DV7", "HP Pavilion dv7", x_inverted), 217 AXIS_DMI_MATCH("DV7", "HP Pavilion dv7", x_inverted),
218 AXIS_DMI_MATCH("HP8710", "HP Compaq 8710", y_inverted), 218 AXIS_DMI_MATCH("HP8710", "HP Compaq 8710", y_inverted),
219 AXIS_DMI_MATCH("HDX18", "HP HDX 18", x_inverted), 219 AXIS_DMI_MATCH("HDX18", "HP HDX 18", x_inverted),
220 AXIS_DMI_MATCH("HPB432x", "HP ProBook 432", xy_rotated_left),
221 AXIS_DMI_MATCH("HPB442x", "HP ProBook 442", xy_rotated_left),
222 AXIS_DMI_MATCH("HPB452x", "HP ProBook 452", y_inverted),
223 AXIS_DMI_MATCH("HPB522x", "HP ProBook 522", xy_swap),
220 { NULL, } 224 { NULL, }
221/* Laptop models without axis info (yet): 225/* Laptop models without axis info (yet):
222 * "NC6910" "HP Compaq 6910" 226 * "NC6910" "HP Compaq 6910"
@@ -324,8 +328,8 @@ static int lis3lv02d_remove(struct acpi_device *device, int type)
324 lis3lv02d_joystick_disable(); 328 lis3lv02d_joystick_disable();
325 lis3lv02d_poweroff(&lis3_dev); 329 lis3lv02d_poweroff(&lis3_dev);
326 330
327 flush_work(&hpled_led.work);
328 led_classdev_unregister(&hpled_led.led_classdev); 331 led_classdev_unregister(&hpled_led.led_classdev);
332 flush_work(&hpled_led.work);
329 333
330 return lis3lv02d_remove_fs(&lis3_dev); 334 return lis3lv02d_remove_fs(&lis3_dev);
331} 335}
diff --git a/drivers/hwmon/i5k_amb.c b/drivers/hwmon/i5k_amb.c
index 27d7f72a5f11..e880e2c3871d 100644
--- a/drivers/hwmon/i5k_amb.c
+++ b/drivers/hwmon/i5k_amb.c
@@ -30,6 +30,7 @@
30#include <linux/log2.h> 30#include <linux/log2.h>
31#include <linux/pci.h> 31#include <linux/pci.h>
32#include <linux/platform_device.h> 32#include <linux/platform_device.h>
33#include <linux/slab.h>
33 34
34#define DRVNAME "i5k_amb" 35#define DRVNAME "i5k_amb"
35 36
diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
index 405d3fb5d76f..eaee546af19a 100644
--- a/drivers/hwmon/ibmaem.c
+++ b/drivers/hwmon/ibmaem.c
@@ -29,6 +29,7 @@
29#include <linux/kdev_t.h> 29#include <linux/kdev_t.h>
30#include <linux/spinlock.h> 30#include <linux/spinlock.h>
31#include <linux/idr.h> 31#include <linux/idr.h>
32#include <linux/slab.h>
32#include <linux/sched.h> 33#include <linux/sched.h>
33#include <linux/platform_device.h> 34#include <linux/platform_device.h>
34#include <linux/math64.h> 35#include <linux/math64.h>
diff --git a/drivers/hwmon/ibmpex.c b/drivers/hwmon/ibmpex.c
index a36363312f2f..06d4eafcf76b 100644
--- a/drivers/hwmon/ibmpex.c
+++ b/drivers/hwmon/ibmpex.c
@@ -25,6 +25,7 @@
25#include <linux/hwmon-sysfs.h> 25#include <linux/hwmon-sysfs.h>
26#include <linux/jiffies.h> 26#include <linux/jiffies.h>
27#include <linux/mutex.h> 27#include <linux/mutex.h>
28#include <linux/slab.h>
28 29
29#define REFRESH_INTERVAL (2 * HZ) 30#define REFRESH_INTERVAL (2 * HZ)
30#define DRVNAME "ibmpex" 31#define DRVNAME "ibmpex"
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index a3749cb0f181..5be09c048c5f 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -1,40 +1,40 @@
1/* 1/*
2 it87.c - Part of lm_sensors, Linux kernel modules for hardware 2 * it87.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring. 3 * monitoring.
4 4 *
5 The IT8705F is an LPC-based Super I/O part that contains UARTs, a 5 * The IT8705F is an LPC-based Super I/O part that contains UARTs, a
6 parallel port, an IR port, a MIDI port, a floppy controller, etc., in 6 * parallel port, an IR port, a MIDI port, a floppy controller, etc., in
7 addition to an Environment Controller (Enhanced Hardware Monitor and 7 * addition to an Environment Controller (Enhanced Hardware Monitor and
8 Fan Controller) 8 * Fan Controller)
9 9 *
10 This driver supports only the Environment Controller in the IT8705F and 10 * This driver supports only the Environment Controller in the IT8705F and
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: IT8705F Super I/O chip w/LPC interface 13 * Supports: IT8705F Super I/O chip w/LPC interface
14 IT8712F Super I/O chip w/LPC interface 14 * IT8712F Super I/O chip w/LPC interface
15 IT8716F Super I/O chip w/LPC interface 15 * IT8716F Super I/O chip w/LPC interface
16 IT8718F Super I/O chip w/LPC interface 16 * IT8718F Super I/O chip w/LPC interface
17 IT8720F Super I/O chip w/LPC interface 17 * IT8720F Super I/O chip w/LPC interface
18 IT8726F Super I/O chip w/LPC interface 18 * IT8726F Super I/O chip w/LPC interface
19 Sis950 A clone of the IT8705F 19 * Sis950 A clone of the IT8705F
20 20 *
21 Copyright (C) 2001 Chris Gauthron 21 * Copyright (C) 2001 Chris Gauthron
22 Copyright (C) 2005-2007 Jean Delvare <khali@linux-fr.org> 22 * Copyright (C) 2005-2010 Jean Delvare <khali@linux-fr.org>
23 23 *
24 This program is free software; you can redistribute it and/or modify 24 * This program is free software; you can redistribute it and/or modify
25 it under the terms of the GNU General Public License as published by 25 * it under the terms of the GNU General Public License as published by
26 the Free Software Foundation; either version 2 of the License, or 26 * the Free Software Foundation; either version 2 of the License, or
27 (at your option) any later version. 27 * (at your option) any later version.
28 28 *
29 This program is distributed in the hope that it will be useful, 29 * This program is distributed in the hope that it will be useful,
30 but WITHOUT ANY WARRANTY; without even the implied warranty of 30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 GNU General Public License for more details. 32 * GNU General Public License for more details.
33 33 *
34 You should have received a copy of the GNU General Public License 34 * You should have received a copy of the GNU General Public License
35 along with this program; if not, write to the Free Software 35 * along with this program; if not, write to the Free Software
36 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 36 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
37*/ 37 */
38 38
39#include <linux/module.h> 39#include <linux/module.h>
40#include <linux/init.h> 40#include <linux/init.h>
@@ -124,8 +124,11 @@ superio_exit(void)
124#define IT87_BASE_REG 0x60 124#define IT87_BASE_REG 0x60
125 125
126/* Logical device 7 registers (IT8712F and later) */ 126/* Logical device 7 registers (IT8712F and later) */
127#define IT87_SIO_GPIO3_REG 0x27
128#define IT87_SIO_GPIO5_REG 0x29
127#define IT87_SIO_PINX2_REG 0x2c /* Pin selection */ 129#define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
128#define IT87_SIO_VID_REG 0xfc /* VID value */ 130#define IT87_SIO_VID_REG 0xfc /* VID value */
131#define IT87_SIO_BEEP_PIN_REG 0xf6 /* Beep pin mapping */
129 132
130/* Update battery voltage after every reading if true */ 133/* Update battery voltage after every reading if true */
131static int update_vbat; 134static int update_vbat;
@@ -185,9 +188,13 @@ static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 };
185 188
186#define IT87_REG_VIN_ENABLE 0x50 189#define IT87_REG_VIN_ENABLE 0x50
187#define IT87_REG_TEMP_ENABLE 0x51 190#define IT87_REG_TEMP_ENABLE 0x51
191#define IT87_REG_BEEP_ENABLE 0x5c
188 192
189#define IT87_REG_CHIPID 0x58 193#define IT87_REG_CHIPID 0x58
190 194
195#define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i))
196#define IT87_REG_AUTO_PWM(nr, i) (0x65 + (nr) * 8 + (i))
197
191#define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255)) 198#define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255))
192#define IN_FROM_REG(val) ((val) * 16) 199#define IN_FROM_REG(val) ((val) * 16)
193 200
@@ -244,7 +251,10 @@ struct it87_sio_data {
244 /* Values read from Super-I/O config space */ 251 /* Values read from Super-I/O config space */
245 u8 revision; 252 u8 revision;
246 u8 vid_value; 253 u8 vid_value;
247 /* Values set based on DMI strings */ 254 u8 beep_pin;
255 /* Features skipped based on config or DMI */
256 u8 skip_vid;
257 u8 skip_fan;
248 u8 skip_pwm; 258 u8 skip_pwm;
249}; 259};
250 260
@@ -275,9 +285,21 @@ struct it87_data {
275 u8 vid; /* Register encoding, combined */ 285 u8 vid; /* Register encoding, combined */
276 u8 vrm; 286 u8 vrm;
277 u32 alarms; /* Register encoding, combined */ 287 u32 alarms; /* Register encoding, combined */
288 u8 beeps; /* Register encoding */
278 u8 fan_main_ctrl; /* Register value */ 289 u8 fan_main_ctrl; /* Register value */
279 u8 fan_ctl; /* Register value */ 290 u8 fan_ctl; /* Register value */
280 u8 manual_pwm_ctl[3]; /* manual PWM value set by user */ 291
292 /* The following 3 arrays correspond to the same registers. The
293 * meaning of bits 6-0 depends on the value of bit 7, and we want
294 * to preserve settings on mode changes, so we have to track all
295 * values separately. */
296 u8 pwm_ctrl[3]; /* Register value */
297 u8 pwm_duty[3]; /* Manual PWM value set by user (bit 6-0) */
298 u8 pwm_temp_map[3]; /* PWM to temp. chan. mapping (bits 1-0) */
299
300 /* Automatic fan speed control registers */
301 u8 auto_pwm[3][4]; /* [nr][3] is hard-coded */
302 s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */
281}; 303};
282 304
283static inline int has_16bit_fans(const struct it87_data *data) 305static inline int has_16bit_fans(const struct it87_data *data)
@@ -292,6 +314,15 @@ static inline int has_16bit_fans(const struct it87_data *data)
292 || data->type == it8720; 314 || data->type == it8720;
293} 315}
294 316
317static inline int has_old_autopwm(const struct it87_data *data)
318{
319 /* The old automatic fan speed control interface is implemented
320 by IT8705F chips up to revision F and IT8712F chips up to
321 revision G. */
322 return (data->type == it87 && data->revision < 0x03)
323 || (data->type == it8712 && data->revision < 0x08);
324}
325
295static int it87_probe(struct platform_device *pdev); 326static int it87_probe(struct platform_device *pdev);
296static int __devexit it87_remove(struct platform_device *pdev); 327static int __devexit it87_remove(struct platform_device *pdev);
297 328
@@ -348,7 +379,10 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
348 int nr = sensor_attr->index; 379 int nr = sensor_attr->index;
349 380
350 struct it87_data *data = dev_get_drvdata(dev); 381 struct it87_data *data = dev_get_drvdata(dev);
351 unsigned long val = simple_strtoul(buf, NULL, 10); 382 unsigned long val;
383
384 if (strict_strtoul(buf, 10, &val) < 0)
385 return -EINVAL;
352 386
353 mutex_lock(&data->update_lock); 387 mutex_lock(&data->update_lock);
354 data->in_min[nr] = IN_TO_REG(val); 388 data->in_min[nr] = IN_TO_REG(val);
@@ -364,7 +398,10 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
364 int nr = sensor_attr->index; 398 int nr = sensor_attr->index;
365 399
366 struct it87_data *data = dev_get_drvdata(dev); 400 struct it87_data *data = dev_get_drvdata(dev);
367 unsigned long val = simple_strtoul(buf, NULL, 10); 401 unsigned long val;
402
403 if (strict_strtoul(buf, 10, &val) < 0)
404 return -EINVAL;
368 405
369 mutex_lock(&data->update_lock); 406 mutex_lock(&data->update_lock);
370 data->in_max[nr] = IN_TO_REG(val); 407 data->in_max[nr] = IN_TO_REG(val);
@@ -437,7 +474,10 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
437 int nr = sensor_attr->index; 474 int nr = sensor_attr->index;
438 475
439 struct it87_data *data = dev_get_drvdata(dev); 476 struct it87_data *data = dev_get_drvdata(dev);
440 int val = simple_strtol(buf, NULL, 10); 477 long val;
478
479 if (strict_strtol(buf, 10, &val) < 0)
480 return -EINVAL;
441 481
442 mutex_lock(&data->update_lock); 482 mutex_lock(&data->update_lock);
443 data->temp_high[nr] = TEMP_TO_REG(val); 483 data->temp_high[nr] = TEMP_TO_REG(val);
@@ -452,7 +492,10 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
452 int nr = sensor_attr->index; 492 int nr = sensor_attr->index;
453 493
454 struct it87_data *data = dev_get_drvdata(dev); 494 struct it87_data *data = dev_get_drvdata(dev);
455 int val = simple_strtol(buf, NULL, 10); 495 long val;
496
497 if (strict_strtol(buf, 10, &val) < 0)
498 return -EINVAL;
456 499
457 mutex_lock(&data->update_lock); 500 mutex_lock(&data->update_lock);
458 data->temp_low[nr] = TEMP_TO_REG(val); 501 data->temp_low[nr] = TEMP_TO_REG(val);
@@ -479,8 +522,9 @@ static ssize_t show_sensor(struct device *dev, struct device_attribute *attr,
479 int nr = sensor_attr->index; 522 int nr = sensor_attr->index;
480 523
481 struct it87_data *data = it87_update_device(dev); 524 struct it87_data *data = it87_update_device(dev);
482 u8 reg = data->sensor; /* In case the value is updated while we use it */ 525 u8 reg = data->sensor; /* In case the value is updated while
483 526 we use it */
527
484 if (reg & (1 << nr)) 528 if (reg & (1 << nr))
485 return sprintf(buf, "3\n"); /* thermal diode */ 529 return sprintf(buf, "3\n"); /* thermal diode */
486 if (reg & (8 << nr)) 530 if (reg & (8 << nr))
@@ -494,12 +538,15 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,
494 int nr = sensor_attr->index; 538 int nr = sensor_attr->index;
495 539
496 struct it87_data *data = dev_get_drvdata(dev); 540 struct it87_data *data = dev_get_drvdata(dev);
497 int val = simple_strtol(buf, NULL, 10); 541 long val;
542 u8 reg;
498 543
499 mutex_lock(&data->update_lock); 544 if (strict_strtol(buf, 10, &val) < 0)
545 return -EINVAL;
500 546
501 data->sensor &= ~(1 << nr); 547 reg = it87_read_value(data, IT87_REG_TEMP_ENABLE);
502 data->sensor &= ~(8 << nr); 548 reg &= ~(1 << nr);
549 reg &= ~(8 << nr);
503 if (val == 2) { /* backwards compatibility */ 550 if (val == 2) { /* backwards compatibility */
504 dev_warn(dev, "Sensor type 2 is deprecated, please use 4 " 551 dev_warn(dev, "Sensor type 2 is deprecated, please use 4 "
505 "instead\n"); 552 "instead\n");
@@ -507,14 +554,16 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,
507 } 554 }
508 /* 3 = thermal diode; 4 = thermistor; 0 = disabled */ 555 /* 3 = thermal diode; 4 = thermistor; 0 = disabled */
509 if (val == 3) 556 if (val == 3)
510 data->sensor |= 1 << nr; 557 reg |= 1 << nr;
511 else if (val == 4) 558 else if (val == 4)
512 data->sensor |= 8 << nr; 559 reg |= 8 << nr;
513 else if (val != 0) { 560 else if (val != 0)
514 mutex_unlock(&data->update_lock);
515 return -EINVAL; 561 return -EINVAL;
516 } 562
563 mutex_lock(&data->update_lock);
564 data->sensor = reg;
517 it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor); 565 it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor);
566 data->valid = 0; /* Force cache refresh */
518 mutex_unlock(&data->update_lock); 567 mutex_unlock(&data->update_lock);
519 return count; 568 return count;
520} 569}
@@ -527,6 +576,19 @@ show_sensor_offset(2);
527show_sensor_offset(3); 576show_sensor_offset(3);
528 577
529/* 3 Fans */ 578/* 3 Fans */
579
580static int pwm_mode(const struct it87_data *data, int nr)
581{
582 int ctrl = data->fan_main_ctrl & (1 << nr);
583
584 if (ctrl == 0) /* Full speed */
585 return 0;
586 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
587 return 2;
588 else /* Manual mode */
589 return 1;
590}
591
530static ssize_t show_fan(struct device *dev, struct device_attribute *attr, 592static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
531 char *buf) 593 char *buf)
532{ 594{
@@ -534,7 +596,7 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
534 int nr = sensor_attr->index; 596 int nr = sensor_attr->index;
535 597
536 struct it87_data *data = it87_update_device(dev); 598 struct it87_data *data = it87_update_device(dev);
537 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr], 599 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
538 DIV_FROM_REG(data->fan_div[nr]))); 600 DIV_FROM_REG(data->fan_div[nr])));
539} 601}
540static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, 602static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
@@ -544,8 +606,8 @@ static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
544 int nr = sensor_attr->index; 606 int nr = sensor_attr->index;
545 607
546 struct it87_data *data = it87_update_device(dev); 608 struct it87_data *data = it87_update_device(dev);
547 return sprintf(buf,"%d\n", 609 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
548 FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]))); 610 DIV_FROM_REG(data->fan_div[nr])));
549} 611}
550static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, 612static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
551 char *buf) 613 char *buf)
@@ -556,14 +618,14 @@ static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
556 struct it87_data *data = it87_update_device(dev); 618 struct it87_data *data = it87_update_device(dev);
557 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); 619 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
558} 620}
559static ssize_t show_pwm_enable(struct device *dev, struct device_attribute *attr, 621static ssize_t show_pwm_enable(struct device *dev,
560 char *buf) 622 struct device_attribute *attr, char *buf)
561{ 623{
562 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 624 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
563 int nr = sensor_attr->index; 625 int nr = sensor_attr->index;
564 626
565 struct it87_data *data = it87_update_device(dev); 627 struct it87_data *data = it87_update_device(dev);
566 return sprintf(buf,"%d\n", (data->fan_main_ctrl & (1 << nr)) ? 1 : 0); 628 return sprintf(buf, "%d\n", pwm_mode(data, nr));
567} 629}
568static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, 630static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
569 char *buf) 631 char *buf)
@@ -572,7 +634,7 @@ static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
572 int nr = sensor_attr->index; 634 int nr = sensor_attr->index;
573 635
574 struct it87_data *data = it87_update_device(dev); 636 struct it87_data *data = it87_update_device(dev);
575 return sprintf(buf,"%d\n", data->manual_pwm_ctl[nr]); 637 return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm_duty[nr]));
576} 638}
577static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr, 639static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
578 char *buf) 640 char *buf)
@@ -589,15 +651,24 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
589 int nr = sensor_attr->index; 651 int nr = sensor_attr->index;
590 652
591 struct it87_data *data = dev_get_drvdata(dev); 653 struct it87_data *data = dev_get_drvdata(dev);
592 int val = simple_strtol(buf, NULL, 10); 654 long val;
593 u8 reg; 655 u8 reg;
594 656
657 if (strict_strtol(buf, 10, &val) < 0)
658 return -EINVAL;
659
595 mutex_lock(&data->update_lock); 660 mutex_lock(&data->update_lock);
596 reg = it87_read_value(data, IT87_REG_FAN_DIV); 661 reg = it87_read_value(data, IT87_REG_FAN_DIV);
597 switch (nr) { 662 switch (nr) {
598 case 0: data->fan_div[nr] = reg & 0x07; break; 663 case 0:
599 case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break; 664 data->fan_div[nr] = reg & 0x07;
600 case 2: data->fan_div[nr] = (reg & 0x40) ? 3 : 1; break; 665 break;
666 case 1:
667 data->fan_div[nr] = (reg >> 3) & 0x07;
668 break;
669 case 2:
670 data->fan_div[nr] = (reg & 0x40) ? 3 : 1;
671 break;
601 } 672 }
602 673
603 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 674 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
@@ -612,10 +683,13 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
612 int nr = sensor_attr->index; 683 int nr = sensor_attr->index;
613 684
614 struct it87_data *data = dev_get_drvdata(dev); 685 struct it87_data *data = dev_get_drvdata(dev);
615 unsigned long val = simple_strtoul(buf, NULL, 10); 686 unsigned long val;
616 int min; 687 int min;
617 u8 old; 688 u8 old;
618 689
690 if (strict_strtoul(buf, 10, &val) < 0)
691 return -EINVAL;
692
619 mutex_lock(&data->update_lock); 693 mutex_lock(&data->update_lock);
620 old = it87_read_value(data, IT87_REG_FAN_DIV); 694 old = it87_read_value(data, IT87_REG_FAN_DIV);
621 695
@@ -647,6 +721,32 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
647 mutex_unlock(&data->update_lock); 721 mutex_unlock(&data->update_lock);
648 return count; 722 return count;
649} 723}
724
725/* Returns 0 if OK, -EINVAL otherwise */
726static int check_trip_points(struct device *dev, int nr)
727{
728 const struct it87_data *data = dev_get_drvdata(dev);
729 int i, err = 0;
730
731 if (has_old_autopwm(data)) {
732 for (i = 0; i < 3; i++) {
733 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1])
734 err = -EINVAL;
735 }
736 for (i = 0; i < 2; i++) {
737 if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1])
738 err = -EINVAL;
739 }
740 }
741
742 if (err) {
743 dev_err(dev, "Inconsistent trip points, not switching to "
744 "automatic mode\n");
745 dev_err(dev, "Adjust the trip points and try again\n");
746 }
747 return err;
748}
749
650static ssize_t set_pwm_enable(struct device *dev, 750static ssize_t set_pwm_enable(struct device *dev,
651 struct device_attribute *attr, const char *buf, size_t count) 751 struct device_attribute *attr, const char *buf, size_t count)
652{ 752{
@@ -654,7 +754,16 @@ static ssize_t set_pwm_enable(struct device *dev,
654 int nr = sensor_attr->index; 754 int nr = sensor_attr->index;
655 755
656 struct it87_data *data = dev_get_drvdata(dev); 756 struct it87_data *data = dev_get_drvdata(dev);
657 int val = simple_strtol(buf, NULL, 10); 757 long val;
758
759 if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 2)
760 return -EINVAL;
761
762 /* Check trip points before switching to automatic mode */
763 if (val == 2) {
764 if (check_trip_points(dev, nr) < 0)
765 return -EINVAL;
766 }
658 767
659 mutex_lock(&data->update_lock); 768 mutex_lock(&data->update_lock);
660 769
@@ -665,16 +774,18 @@ static ssize_t set_pwm_enable(struct device *dev,
665 it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr)); 774 it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr));
666 /* set on/off mode */ 775 /* set on/off mode */
667 data->fan_main_ctrl &= ~(1 << nr); 776 data->fan_main_ctrl &= ~(1 << nr);
668 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); 777 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
669 } else if (val == 1) { 778 data->fan_main_ctrl);
779 } else {
780 if (val == 1) /* Manual mode */
781 data->pwm_ctrl[nr] = data->pwm_duty[nr];
782 else /* Automatic mode */
783 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
784 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
670 /* set SmartGuardian mode */ 785 /* set SmartGuardian mode */
671 data->fan_main_ctrl |= (1 << nr); 786 data->fan_main_ctrl |= (1 << nr);
672 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); 787 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
673 /* set saved pwm value, clear FAN_CTLX PWM mode bit */ 788 data->fan_main_ctrl);
674 it87_write_value(data, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr]));
675 } else {
676 mutex_unlock(&data->update_lock);
677 return -EINVAL;
678 } 789 }
679 790
680 mutex_unlock(&data->update_lock); 791 mutex_unlock(&data->update_lock);
@@ -687,15 +798,19 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
687 int nr = sensor_attr->index; 798 int nr = sensor_attr->index;
688 799
689 struct it87_data *data = dev_get_drvdata(dev); 800 struct it87_data *data = dev_get_drvdata(dev);
690 int val = simple_strtol(buf, NULL, 10); 801 long val;
691 802
692 if (val < 0 || val > 255) 803 if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 255)
693 return -EINVAL; 804 return -EINVAL;
694 805
695 mutex_lock(&data->update_lock); 806 mutex_lock(&data->update_lock);
696 data->manual_pwm_ctl[nr] = val; 807 data->pwm_duty[nr] = PWM_TO_REG(val);
697 if (data->fan_main_ctrl & (1 << nr)) 808 /* If we are in manual mode, write the duty cycle immediately;
698 it87_write_value(data, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); 809 * otherwise, just store it for later use. */
810 if (!(data->pwm_ctrl[nr] & 0x80)) {
811 data->pwm_ctrl[nr] = data->pwm_duty[nr];
812 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
813 }
699 mutex_unlock(&data->update_lock); 814 mutex_unlock(&data->update_lock);
700 return count; 815 return count;
701} 816}
@@ -703,9 +818,12 @@ static ssize_t set_pwm_freq(struct device *dev,
703 struct device_attribute *attr, const char *buf, size_t count) 818 struct device_attribute *attr, const char *buf, size_t count)
704{ 819{
705 struct it87_data *data = dev_get_drvdata(dev); 820 struct it87_data *data = dev_get_drvdata(dev);
706 unsigned long val = simple_strtoul(buf, NULL, 10); 821 unsigned long val;
707 int i; 822 int i;
708 823
824 if (strict_strtoul(buf, 10, &val) < 0)
825 return -EINVAL;
826
709 /* Search for the nearest available frequency */ 827 /* Search for the nearest available frequency */
710 for (i = 0; i < 7; i++) { 828 for (i = 0; i < 7; i++) {
711 if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2) 829 if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2)
@@ -720,6 +838,132 @@ static ssize_t set_pwm_freq(struct device *dev,
720 838
721 return count; 839 return count;
722} 840}
841static ssize_t show_pwm_temp_map(struct device *dev,
842 struct device_attribute *attr, char *buf)
843{
844 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
845 int nr = sensor_attr->index;
846
847 struct it87_data *data = it87_update_device(dev);
848 int map;
849
850 if (data->pwm_temp_map[nr] < 3)
851 map = 1 << data->pwm_temp_map[nr];
852 else
853 map = 0; /* Should never happen */
854 return sprintf(buf, "%d\n", map);
855}
856static ssize_t set_pwm_temp_map(struct device *dev,
857 struct device_attribute *attr, const char *buf, size_t count)
858{
859 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
860 int nr = sensor_attr->index;
861
862 struct it87_data *data = dev_get_drvdata(dev);
863 long val;
864 u8 reg;
865
866 /* This check can go away if we ever support automatic fan speed
867 control on newer chips. */
868 if (!has_old_autopwm(data)) {
869 dev_notice(dev, "Mapping change disabled for safety reasons\n");
870 return -EINVAL;
871 }
872
873 if (strict_strtol(buf, 10, &val) < 0)
874 return -EINVAL;
875
876 switch (val) {
877 case (1 << 0):
878 reg = 0x00;
879 break;
880 case (1 << 1):
881 reg = 0x01;
882 break;
883 case (1 << 2):
884 reg = 0x02;
885 break;
886 default:
887 return -EINVAL;
888 }
889
890 mutex_lock(&data->update_lock);
891 data->pwm_temp_map[nr] = reg;
892 /* If we are in automatic mode, write the temp mapping immediately;
893 * otherwise, just store it for later use. */
894 if (data->pwm_ctrl[nr] & 0x80) {
895 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
896 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
897 }
898 mutex_unlock(&data->update_lock);
899 return count;
900}
901
902static ssize_t show_auto_pwm(struct device *dev,
903 struct device_attribute *attr, char *buf)
904{
905 struct it87_data *data = it87_update_device(dev);
906 struct sensor_device_attribute_2 *sensor_attr =
907 to_sensor_dev_attr_2(attr);
908 int nr = sensor_attr->nr;
909 int point = sensor_attr->index;
910
911 return sprintf(buf, "%d\n", PWM_FROM_REG(data->auto_pwm[nr][point]));
912}
913
914static ssize_t set_auto_pwm(struct device *dev,
915 struct device_attribute *attr, const char *buf, size_t count)
916{
917 struct it87_data *data = dev_get_drvdata(dev);
918 struct sensor_device_attribute_2 *sensor_attr =
919 to_sensor_dev_attr_2(attr);
920 int nr = sensor_attr->nr;
921 int point = sensor_attr->index;
922 long val;
923
924 if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 255)
925 return -EINVAL;
926
927 mutex_lock(&data->update_lock);
928 data->auto_pwm[nr][point] = PWM_TO_REG(val);
929 it87_write_value(data, IT87_REG_AUTO_PWM(nr, point),
930 data->auto_pwm[nr][point]);
931 mutex_unlock(&data->update_lock);
932 return count;
933}
934
935static ssize_t show_auto_temp(struct device *dev,
936 struct device_attribute *attr, char *buf)
937{
938 struct it87_data *data = it87_update_device(dev);
939 struct sensor_device_attribute_2 *sensor_attr =
940 to_sensor_dev_attr_2(attr);
941 int nr = sensor_attr->nr;
942 int point = sensor_attr->index;
943
944 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->auto_temp[nr][point]));
945}
946
947static ssize_t set_auto_temp(struct device *dev,
948 struct device_attribute *attr, const char *buf, size_t count)
949{
950 struct it87_data *data = dev_get_drvdata(dev);
951 struct sensor_device_attribute_2 *sensor_attr =
952 to_sensor_dev_attr_2(attr);
953 int nr = sensor_attr->nr;
954 int point = sensor_attr->index;
955 long val;
956
957 if (strict_strtol(buf, 10, &val) < 0 || val < -128000 || val > 127000)
958 return -EINVAL;
959
960 mutex_lock(&data->update_lock);
961 data->auto_temp[nr][point] = TEMP_TO_REG(val);
962 it87_write_value(data, IT87_REG_AUTO_TEMP(nr, point),
963 data->auto_temp[nr][point]);
964 mutex_unlock(&data->update_lock);
965 return count;
966}
723 967
724#define show_fan_offset(offset) \ 968#define show_fan_offset(offset) \
725static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ 969static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
@@ -740,7 +984,36 @@ static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
740 show_pwm, set_pwm, offset - 1); \ 984 show_pwm, set_pwm, offset - 1); \
741static DEVICE_ATTR(pwm##offset##_freq, \ 985static DEVICE_ATTR(pwm##offset##_freq, \
742 (offset == 1 ? S_IRUGO | S_IWUSR : S_IRUGO), \ 986 (offset == 1 ? S_IRUGO | S_IWUSR : S_IRUGO), \
743 show_pwm_freq, (offset == 1 ? set_pwm_freq : NULL)); 987 show_pwm_freq, (offset == 1 ? set_pwm_freq : NULL)); \
988static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels_temp, \
989 S_IRUGO | S_IWUSR, show_pwm_temp_map, set_pwm_temp_map, \
990 offset - 1); \
991static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_pwm, \
992 S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \
993 offset - 1, 0); \
994static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_pwm, \
995 S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \
996 offset - 1, 1); \
997static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_pwm, \
998 S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \
999 offset - 1, 2); \
1000static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_pwm, \
1001 S_IRUGO, show_auto_pwm, NULL, offset - 1, 3); \
1002static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp, \
1003 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1004 offset - 1, 1); \
1005static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp_hyst, \
1006 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1007 offset - 1, 0); \
1008static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_temp, \
1009 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1010 offset - 1, 2); \
1011static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_temp, \
1012 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1013 offset - 1, 3); \
1014static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_temp, \
1015 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1016 offset - 1, 4);
744 1017
745show_pwm_offset(1); 1018show_pwm_offset(1);
746show_pwm_offset(2); 1019show_pwm_offset(2);
@@ -771,7 +1044,10 @@ static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr,
771 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 1044 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
772 int nr = sensor_attr->index; 1045 int nr = sensor_attr->index;
773 struct it87_data *data = dev_get_drvdata(dev); 1046 struct it87_data *data = dev_get_drvdata(dev);
774 int val = simple_strtol(buf, NULL, 10); 1047 long val;
1048
1049 if (strict_strtol(buf, 10, &val) < 0)
1050 return -EINVAL;
775 1051
776 mutex_lock(&data->update_lock); 1052 mutex_lock(&data->update_lock);
777 data->fan_min[nr] = FAN16_TO_REG(val); 1053 data->fan_min[nr] = FAN16_TO_REG(val);
@@ -801,7 +1077,8 @@ show_fan16_offset(4);
801show_fan16_offset(5); 1077show_fan16_offset(5);
802 1078
803/* Alarms */ 1079/* Alarms */
804static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 1080static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
1081 char *buf)
805{ 1082{
806 struct it87_data *data = it87_update_device(dev); 1083 struct it87_data *data = it87_update_device(dev);
807 return sprintf(buf, "%u\n", data->alarms); 1084 return sprintf(buf, "%u\n", data->alarms);
@@ -832,27 +1109,78 @@ static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16);
832static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17); 1109static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17);
833static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18); 1110static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18);
834 1111
835static ssize_t 1112static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
836show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) 1113 char *buf)
1114{
1115 int bitnr = to_sensor_dev_attr(attr)->index;
1116 struct it87_data *data = it87_update_device(dev);
1117 return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1);
1118}
1119static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
1120 const char *buf, size_t count)
1121{
1122 int bitnr = to_sensor_dev_attr(attr)->index;
1123 struct it87_data *data = dev_get_drvdata(dev);
1124 long val;
1125
1126 if (strict_strtol(buf, 10, &val) < 0
1127 || (val != 0 && val != 1))
1128 return -EINVAL;
1129
1130 mutex_lock(&data->update_lock);
1131 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
1132 if (val)
1133 data->beeps |= (1 << bitnr);
1134 else
1135 data->beeps &= ~(1 << bitnr);
1136 it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps);
1137 mutex_unlock(&data->update_lock);
1138 return count;
1139}
1140
1141static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
1142 show_beep, set_beep, 1);
1143static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO, show_beep, NULL, 1);
1144static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO, show_beep, NULL, 1);
1145static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO, show_beep, NULL, 1);
1146static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO, show_beep, NULL, 1);
1147static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO, show_beep, NULL, 1);
1148static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO, show_beep, NULL, 1);
1149static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO, show_beep, NULL, 1);
1150/* fanX_beep writability is set later */
1151static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO, show_beep, set_beep, 0);
1152static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0);
1153static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0);
1154static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0);
1155static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0);
1156static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
1157 show_beep, set_beep, 2);
1158static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2);
1159static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2);
1160
1161static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
1162 char *buf)
837{ 1163{
838 struct it87_data *data = dev_get_drvdata(dev); 1164 struct it87_data *data = dev_get_drvdata(dev);
839 return sprintf(buf, "%u\n", data->vrm); 1165 return sprintf(buf, "%u\n", data->vrm);
840} 1166}
841static ssize_t 1167static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
842store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1168 const char *buf, size_t count)
843{ 1169{
844 struct it87_data *data = dev_get_drvdata(dev); 1170 struct it87_data *data = dev_get_drvdata(dev);
845 u32 val; 1171 unsigned long val;
1172
1173 if (strict_strtoul(buf, 10, &val) < 0)
1174 return -EINVAL;
846 1175
847 val = simple_strtoul(buf, NULL, 10);
848 data->vrm = val; 1176 data->vrm = val;
849 1177
850 return count; 1178 return count;
851} 1179}
852static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); 1180static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
853 1181
854static ssize_t 1182static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
855show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) 1183 char *buf)
856{ 1184{
857 struct it87_data *data = it87_update_device(dev); 1185 struct it87_data *data = it87_update_device(dev);
858 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); 1186 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
@@ -927,51 +1255,176 @@ static const struct attribute_group it87_group = {
927 .attrs = it87_attributes, 1255 .attrs = it87_attributes,
928}; 1256};
929 1257
930static struct attribute *it87_attributes_opt[] = { 1258static struct attribute *it87_attributes_beep[] = {
1259 &sensor_dev_attr_in0_beep.dev_attr.attr,
1260 &sensor_dev_attr_in1_beep.dev_attr.attr,
1261 &sensor_dev_attr_in2_beep.dev_attr.attr,
1262 &sensor_dev_attr_in3_beep.dev_attr.attr,
1263 &sensor_dev_attr_in4_beep.dev_attr.attr,
1264 &sensor_dev_attr_in5_beep.dev_attr.attr,
1265 &sensor_dev_attr_in6_beep.dev_attr.attr,
1266 &sensor_dev_attr_in7_beep.dev_attr.attr,
1267
1268 &sensor_dev_attr_temp1_beep.dev_attr.attr,
1269 &sensor_dev_attr_temp2_beep.dev_attr.attr,
1270 &sensor_dev_attr_temp3_beep.dev_attr.attr,
1271 NULL
1272};
1273
1274static const struct attribute_group it87_group_beep = {
1275 .attrs = it87_attributes_beep,
1276};
1277
1278static struct attribute *it87_attributes_fan16[5][3+1] = { {
931 &sensor_dev_attr_fan1_input16.dev_attr.attr, 1279 &sensor_dev_attr_fan1_input16.dev_attr.attr,
932 &sensor_dev_attr_fan1_min16.dev_attr.attr, 1280 &sensor_dev_attr_fan1_min16.dev_attr.attr,
1281 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1282 NULL
1283}, {
933 &sensor_dev_attr_fan2_input16.dev_attr.attr, 1284 &sensor_dev_attr_fan2_input16.dev_attr.attr,
934 &sensor_dev_attr_fan2_min16.dev_attr.attr, 1285 &sensor_dev_attr_fan2_min16.dev_attr.attr,
1286 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1287 NULL
1288}, {
935 &sensor_dev_attr_fan3_input16.dev_attr.attr, 1289 &sensor_dev_attr_fan3_input16.dev_attr.attr,
936 &sensor_dev_attr_fan3_min16.dev_attr.attr, 1290 &sensor_dev_attr_fan3_min16.dev_attr.attr,
1291 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
1292 NULL
1293}, {
937 &sensor_dev_attr_fan4_input16.dev_attr.attr, 1294 &sensor_dev_attr_fan4_input16.dev_attr.attr,
938 &sensor_dev_attr_fan4_min16.dev_attr.attr, 1295 &sensor_dev_attr_fan4_min16.dev_attr.attr,
1296 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
1297 NULL
1298}, {
939 &sensor_dev_attr_fan5_input16.dev_attr.attr, 1299 &sensor_dev_attr_fan5_input16.dev_attr.attr,
940 &sensor_dev_attr_fan5_min16.dev_attr.attr, 1300 &sensor_dev_attr_fan5_min16.dev_attr.attr,
1301 &sensor_dev_attr_fan5_alarm.dev_attr.attr,
1302 NULL
1303} };
1304
1305static const struct attribute_group it87_group_fan16[5] = {
1306 { .attrs = it87_attributes_fan16[0] },
1307 { .attrs = it87_attributes_fan16[1] },
1308 { .attrs = it87_attributes_fan16[2] },
1309 { .attrs = it87_attributes_fan16[3] },
1310 { .attrs = it87_attributes_fan16[4] },
1311};
941 1312
1313static struct attribute *it87_attributes_fan[3][4+1] = { {
942 &sensor_dev_attr_fan1_input.dev_attr.attr, 1314 &sensor_dev_attr_fan1_input.dev_attr.attr,
943 &sensor_dev_attr_fan1_min.dev_attr.attr, 1315 &sensor_dev_attr_fan1_min.dev_attr.attr,
944 &sensor_dev_attr_fan1_div.dev_attr.attr, 1316 &sensor_dev_attr_fan1_div.dev_attr.attr,
1317 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1318 NULL
1319}, {
945 &sensor_dev_attr_fan2_input.dev_attr.attr, 1320 &sensor_dev_attr_fan2_input.dev_attr.attr,
946 &sensor_dev_attr_fan2_min.dev_attr.attr, 1321 &sensor_dev_attr_fan2_min.dev_attr.attr,
947 &sensor_dev_attr_fan2_div.dev_attr.attr, 1322 &sensor_dev_attr_fan2_div.dev_attr.attr,
1323 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1324 NULL
1325}, {
948 &sensor_dev_attr_fan3_input.dev_attr.attr, 1326 &sensor_dev_attr_fan3_input.dev_attr.attr,
949 &sensor_dev_attr_fan3_min.dev_attr.attr, 1327 &sensor_dev_attr_fan3_min.dev_attr.attr,
950 &sensor_dev_attr_fan3_div.dev_attr.attr, 1328 &sensor_dev_attr_fan3_div.dev_attr.attr,
951
952 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
953 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
954 &sensor_dev_attr_fan3_alarm.dev_attr.attr, 1329 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
955 &sensor_dev_attr_fan4_alarm.dev_attr.attr, 1330 NULL
956 &sensor_dev_attr_fan5_alarm.dev_attr.attr, 1331} };
1332
1333static const struct attribute_group it87_group_fan[3] = {
1334 { .attrs = it87_attributes_fan[0] },
1335 { .attrs = it87_attributes_fan[1] },
1336 { .attrs = it87_attributes_fan[2] },
1337};
1338
1339static const struct attribute_group *
1340it87_get_fan_group(const struct it87_data *data)
1341{
1342 return has_16bit_fans(data) ? it87_group_fan16 : it87_group_fan;
1343}
957 1344
1345static struct attribute *it87_attributes_pwm[3][4+1] = { {
958 &sensor_dev_attr_pwm1_enable.dev_attr.attr, 1346 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
959 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
960 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
961 &sensor_dev_attr_pwm1.dev_attr.attr, 1347 &sensor_dev_attr_pwm1.dev_attr.attr,
962 &sensor_dev_attr_pwm2.dev_attr.attr,
963 &sensor_dev_attr_pwm3.dev_attr.attr,
964 &dev_attr_pwm1_freq.attr, 1348 &dev_attr_pwm1_freq.attr,
1349 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
1350 NULL
1351}, {
1352 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1353 &sensor_dev_attr_pwm2.dev_attr.attr,
965 &dev_attr_pwm2_freq.attr, 1354 &dev_attr_pwm2_freq.attr,
1355 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
1356 NULL
1357}, {
1358 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
1359 &sensor_dev_attr_pwm3.dev_attr.attr,
966 &dev_attr_pwm3_freq.attr, 1360 &dev_attr_pwm3_freq.attr,
1361 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
1362 NULL
1363} };
1364
1365static const struct attribute_group it87_group_pwm[3] = {
1366 { .attrs = it87_attributes_pwm[0] },
1367 { .attrs = it87_attributes_pwm[1] },
1368 { .attrs = it87_attributes_pwm[2] },
1369};
1370
1371static struct attribute *it87_attributes_autopwm[3][9+1] = { {
1372 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
1373 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
1374 &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr,
1375 &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr,
1376 &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
1377 &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr,
1378 &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr,
1379 &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr,
1380 &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr,
1381 NULL
1382}, {
1383 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
1384 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
1385 &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr,
1386 &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr,
1387 &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr,
1388 &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr,
1389 &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr,
1390 &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr,
1391 &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr,
1392 NULL
1393}, {
1394 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
1395 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
1396 &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr,
1397 &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr,
1398 &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr,
1399 &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr,
1400 &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr,
1401 &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr,
1402 &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr,
1403 NULL
1404} };
1405
1406static const struct attribute_group it87_group_autopwm[3] = {
1407 { .attrs = it87_attributes_autopwm[0] },
1408 { .attrs = it87_attributes_autopwm[1] },
1409 { .attrs = it87_attributes_autopwm[2] },
1410};
1411
1412static struct attribute *it87_attributes_fan_beep[] = {
1413 &sensor_dev_attr_fan1_beep.dev_attr.attr,
1414 &sensor_dev_attr_fan2_beep.dev_attr.attr,
1415 &sensor_dev_attr_fan3_beep.dev_attr.attr,
1416 &sensor_dev_attr_fan4_beep.dev_attr.attr,
1417 &sensor_dev_attr_fan5_beep.dev_attr.attr,
1418};
967 1419
1420static struct attribute *it87_attributes_vid[] = {
968 &dev_attr_vrm.attr, 1421 &dev_attr_vrm.attr,
969 &dev_attr_cpu0_vid.attr, 1422 &dev_attr_cpu0_vid.attr,
970 NULL 1423 NULL
971}; 1424};
972 1425
973static const struct attribute_group it87_group_opt = { 1426static const struct attribute_group it87_group_vid = {
974 .attrs = it87_attributes_opt, 1427 .attrs = it87_attributes_vid,
975}; 1428};
976 1429
977/* SuperIO detection - will change isa_address if a chip is found */ 1430/* SuperIO detection - will change isa_address if a chip is found */
@@ -1028,11 +1481,39 @@ static int __init it87_find(unsigned short *address,
1028 chip_type, *address, sio_data->revision); 1481 chip_type, *address, sio_data->revision);
1029 1482
1030 /* Read GPIO config and VID value from LDN 7 (GPIO) */ 1483 /* Read GPIO config and VID value from LDN 7 (GPIO) */
1031 if (sio_data->type != it87) { 1484 if (sio_data->type == it87) {
1485 /* The IT8705F doesn't have VID pins at all */
1486 sio_data->skip_vid = 1;
1487
1488 /* The IT8705F has a different LD number for GPIO */
1489 superio_select(5);
1490 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
1491 } else {
1032 int reg; 1492 int reg;
1033 1493
1034 superio_select(GPIO); 1494 superio_select(GPIO);
1035 if (sio_data->type == it8718 || sio_data->type == it8720) 1495 /* We need at least 4 VID pins */
1496 reg = superio_inb(IT87_SIO_GPIO3_REG);
1497 if (reg & 0x0f) {
1498 pr_info("it87: VID is disabled (pins used for GPIO)\n");
1499 sio_data->skip_vid = 1;
1500 }
1501
1502 /* Check if fan3 is there or not */
1503 if (reg & (1 << 6))
1504 sio_data->skip_pwm |= (1 << 2);
1505 if (reg & (1 << 7))
1506 sio_data->skip_fan |= (1 << 2);
1507
1508 /* Check if fan2 is there or not */
1509 reg = superio_inb(IT87_SIO_GPIO5_REG);
1510 if (reg & (1 << 1))
1511 sio_data->skip_pwm |= (1 << 1);
1512 if (reg & (1 << 2))
1513 sio_data->skip_fan |= (1 << 1);
1514
1515 if ((sio_data->type == it8718 || sio_data->type == it8720)
1516 && !(sio_data->skip_vid))
1036 sio_data->vid_value = superio_inb(IT87_SIO_VID_REG); 1517 sio_data->vid_value = superio_inb(IT87_SIO_VID_REG);
1037 1518
1038 reg = superio_inb(IT87_SIO_PINX2_REG); 1519 reg = superio_inb(IT87_SIO_PINX2_REG);
@@ -1040,7 +1521,11 @@ static int __init it87_find(unsigned short *address,
1040 pr_info("it87: in3 is VCC (+5V)\n"); 1521 pr_info("it87: in3 is VCC (+5V)\n");
1041 if (reg & (1 << 1)) 1522 if (reg & (1 << 1))
1042 pr_info("it87: in7 is VCCH (+5V Stand-By)\n"); 1523 pr_info("it87: in7 is VCCH (+5V Stand-By)\n");
1524
1525 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
1043 } 1526 }
1527 if (sio_data->beep_pin)
1528 pr_info("it87: Beeping is supported\n");
1044 1529
1045 /* Disable specific features based on DMI strings */ 1530 /* Disable specific features based on DMI strings */
1046 board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR); 1531 board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
@@ -1065,14 +1550,46 @@ exit:
1065 return err; 1550 return err;
1066} 1551}
1067 1552
1553static void it87_remove_files(struct device *dev)
1554{
1555 struct it87_data *data = platform_get_drvdata(pdev);
1556 struct it87_sio_data *sio_data = dev->platform_data;
1557 const struct attribute_group *fan_group = it87_get_fan_group(data);
1558 int i;
1559
1560 sysfs_remove_group(&dev->kobj, &it87_group);
1561 if (sio_data->beep_pin)
1562 sysfs_remove_group(&dev->kobj, &it87_group_beep);
1563 for (i = 0; i < 5; i++) {
1564 if (!(data->has_fan & (1 << i)))
1565 continue;
1566 sysfs_remove_group(&dev->kobj, &fan_group[i]);
1567 if (sio_data->beep_pin)
1568 sysfs_remove_file(&dev->kobj,
1569 it87_attributes_fan_beep[i]);
1570 }
1571 for (i = 0; i < 3; i++) {
1572 if (sio_data->skip_pwm & (1 << 0))
1573 continue;
1574 sysfs_remove_group(&dev->kobj, &it87_group_pwm[i]);
1575 if (has_old_autopwm(data))
1576 sysfs_remove_group(&dev->kobj,
1577 &it87_group_autopwm[i]);
1578 }
1579 if (!sio_data->skip_vid)
1580 sysfs_remove_group(&dev->kobj, &it87_group_vid);
1581}
1582
1068static int __devinit it87_probe(struct platform_device *pdev) 1583static int __devinit it87_probe(struct platform_device *pdev)
1069{ 1584{
1070 struct it87_data *data; 1585 struct it87_data *data;
1071 struct resource *res; 1586 struct resource *res;
1072 struct device *dev = &pdev->dev; 1587 struct device *dev = &pdev->dev;
1073 struct it87_sio_data *sio_data = dev->platform_data; 1588 struct it87_sio_data *sio_data = dev->platform_data;
1074 int err = 0; 1589 const struct attribute_group *fan_group;
1590 int err = 0, i;
1075 int enable_pwm_interface; 1591 int enable_pwm_interface;
1592 int fan_beep_need_rw;
1076 static const char *names[] = { 1593 static const char *names[] = {
1077 "it87", 1594 "it87",
1078 "it8712", 1595 "it8712",
@@ -1090,7 +1607,8 @@ static int __devinit it87_probe(struct platform_device *pdev)
1090 goto ERROR0; 1607 goto ERROR0;
1091 } 1608 }
1092 1609
1093 if (!(data = kzalloc(sizeof(struct it87_data), GFP_KERNEL))) { 1610 data = kzalloc(sizeof(struct it87_data), GFP_KERNEL);
1611 if (!data) {
1094 err = -ENOMEM; 1612 err = -ENOMEM;
1095 goto ERROR1; 1613 goto ERROR1;
1096 } 1614 }
@@ -1118,133 +1636,70 @@ static int __devinit it87_probe(struct platform_device *pdev)
1118 it87_init_device(pdev); 1636 it87_init_device(pdev);
1119 1637
1120 /* Register sysfs hooks */ 1638 /* Register sysfs hooks */
1121 if ((err = sysfs_create_group(&dev->kobj, &it87_group))) 1639 err = sysfs_create_group(&dev->kobj, &it87_group);
1640 if (err)
1122 goto ERROR2; 1641 goto ERROR2;
1123 1642
1643 if (sio_data->beep_pin) {
1644 err = sysfs_create_group(&dev->kobj, &it87_group_beep);
1645 if (err)
1646 goto ERROR4;
1647 }
1648
1124 /* Do not create fan files for disabled fans */ 1649 /* Do not create fan files for disabled fans */
1125 if (has_16bit_fans(data)) { 1650 fan_group = it87_get_fan_group(data);
1126 /* 16-bit tachometers */ 1651 fan_beep_need_rw = 1;
1127 if (data->has_fan & (1 << 0)) { 1652 for (i = 0; i < 5; i++) {
1128 if ((err = device_create_file(dev, 1653 if (!(data->has_fan & (1 << i)))
1129 &sensor_dev_attr_fan1_input16.dev_attr)) 1654 continue;
1130 || (err = device_create_file(dev, 1655 err = sysfs_create_group(&dev->kobj, &fan_group[i]);
1131 &sensor_dev_attr_fan1_min16.dev_attr)) 1656 if (err)
1132 || (err = device_create_file(dev, 1657 goto ERROR4;
1133 &sensor_dev_attr_fan1_alarm.dev_attr))) 1658
1134 goto ERROR4; 1659 if (sio_data->beep_pin) {
1135 } 1660 err = sysfs_create_file(&dev->kobj,
1136 if (data->has_fan & (1 << 1)) { 1661 it87_attributes_fan_beep[i]);
1137 if ((err = device_create_file(dev, 1662 if (err)
1138 &sensor_dev_attr_fan2_input16.dev_attr))
1139 || (err = device_create_file(dev,
1140 &sensor_dev_attr_fan2_min16.dev_attr))
1141 || (err = device_create_file(dev,
1142 &sensor_dev_attr_fan2_alarm.dev_attr)))
1143 goto ERROR4;
1144 }
1145 if (data->has_fan & (1 << 2)) {
1146 if ((err = device_create_file(dev,
1147 &sensor_dev_attr_fan3_input16.dev_attr))
1148 || (err = device_create_file(dev,
1149 &sensor_dev_attr_fan3_min16.dev_attr))
1150 || (err = device_create_file(dev,
1151 &sensor_dev_attr_fan3_alarm.dev_attr)))
1152 goto ERROR4;
1153 }
1154 if (data->has_fan & (1 << 3)) {
1155 if ((err = device_create_file(dev,
1156 &sensor_dev_attr_fan4_input16.dev_attr))
1157 || (err = device_create_file(dev,
1158 &sensor_dev_attr_fan4_min16.dev_attr))
1159 || (err = device_create_file(dev,
1160 &sensor_dev_attr_fan4_alarm.dev_attr)))
1161 goto ERROR4;
1162 }
1163 if (data->has_fan & (1 << 4)) {
1164 if ((err = device_create_file(dev,
1165 &sensor_dev_attr_fan5_input16.dev_attr))
1166 || (err = device_create_file(dev,
1167 &sensor_dev_attr_fan5_min16.dev_attr))
1168 || (err = device_create_file(dev,
1169 &sensor_dev_attr_fan5_alarm.dev_attr)))
1170 goto ERROR4;
1171 }
1172 } else {
1173 /* 8-bit tachometers with clock divider */
1174 if (data->has_fan & (1 << 0)) {
1175 if ((err = device_create_file(dev,
1176 &sensor_dev_attr_fan1_input.dev_attr))
1177 || (err = device_create_file(dev,
1178 &sensor_dev_attr_fan1_min.dev_attr))
1179 || (err = device_create_file(dev,
1180 &sensor_dev_attr_fan1_div.dev_attr))
1181 || (err = device_create_file(dev,
1182 &sensor_dev_attr_fan1_alarm.dev_attr)))
1183 goto ERROR4;
1184 }
1185 if (data->has_fan & (1 << 1)) {
1186 if ((err = device_create_file(dev,
1187 &sensor_dev_attr_fan2_input.dev_attr))
1188 || (err = device_create_file(dev,
1189 &sensor_dev_attr_fan2_min.dev_attr))
1190 || (err = device_create_file(dev,
1191 &sensor_dev_attr_fan2_div.dev_attr))
1192 || (err = device_create_file(dev,
1193 &sensor_dev_attr_fan2_alarm.dev_attr)))
1194 goto ERROR4;
1195 }
1196 if (data->has_fan & (1 << 2)) {
1197 if ((err = device_create_file(dev,
1198 &sensor_dev_attr_fan3_input.dev_attr))
1199 || (err = device_create_file(dev,
1200 &sensor_dev_attr_fan3_min.dev_attr))
1201 || (err = device_create_file(dev,
1202 &sensor_dev_attr_fan3_div.dev_attr))
1203 || (err = device_create_file(dev,
1204 &sensor_dev_attr_fan3_alarm.dev_attr)))
1205 goto ERROR4; 1663 goto ERROR4;
1664 if (!fan_beep_need_rw)
1665 continue;
1666
1667 /* As we have a single beep enable bit for all fans,
1668 * only the first enabled fan has a writable attribute
1669 * for it. */
1670 if (sysfs_chmod_file(&dev->kobj,
1671 it87_attributes_fan_beep[i],
1672 S_IRUGO | S_IWUSR))
1673 dev_dbg(dev, "chmod +w fan%d_beep failed\n",
1674 i + 1);
1675 fan_beep_need_rw = 0;
1206 } 1676 }
1207 } 1677 }
1208 1678
1209 if (enable_pwm_interface) { 1679 if (enable_pwm_interface) {
1210 if (!(sio_data->skip_pwm & (1 << 0))) { 1680 for (i = 0; i < 3; i++) {
1211 if ((err = device_create_file(dev, 1681 if (sio_data->skip_pwm & (1 << i))
1212 &sensor_dev_attr_pwm1_enable.dev_attr)) 1682 continue;
1213 || (err = device_create_file(dev, 1683 err = sysfs_create_group(&dev->kobj,
1214 &sensor_dev_attr_pwm1.dev_attr)) 1684 &it87_group_pwm[i]);
1215 || (err = device_create_file(dev, 1685 if (err)
1216 &dev_attr_pwm1_freq)))
1217 goto ERROR4;
1218 }
1219 if (!(sio_data->skip_pwm & (1 << 1))) {
1220 if ((err = device_create_file(dev,
1221 &sensor_dev_attr_pwm2_enable.dev_attr))
1222 || (err = device_create_file(dev,
1223 &sensor_dev_attr_pwm2.dev_attr))
1224 || (err = device_create_file(dev,
1225 &dev_attr_pwm2_freq)))
1226 goto ERROR4; 1686 goto ERROR4;
1227 } 1687
1228 if (!(sio_data->skip_pwm & (1 << 2))) { 1688 if (!has_old_autopwm(data))
1229 if ((err = device_create_file(dev, 1689 continue;
1230 &sensor_dev_attr_pwm3_enable.dev_attr)) 1690 err = sysfs_create_group(&dev->kobj,
1231 || (err = device_create_file(dev, 1691 &it87_group_autopwm[i]);
1232 &sensor_dev_attr_pwm3.dev_attr)) 1692 if (err)
1233 || (err = device_create_file(dev,
1234 &dev_attr_pwm3_freq)))
1235 goto ERROR4; 1693 goto ERROR4;
1236 } 1694 }
1237 } 1695 }
1238 1696
1239 if (data->type == it8712 || data->type == it8716 1697 if (!sio_data->skip_vid) {
1240 || data->type == it8718 || data->type == it8720) {
1241 data->vrm = vid_which_vrm(); 1698 data->vrm = vid_which_vrm();
1242 /* VID reading from Super-I/O config space if available */ 1699 /* VID reading from Super-I/O config space if available */
1243 data->vid = sio_data->vid_value; 1700 data->vid = sio_data->vid_value;
1244 if ((err = device_create_file(dev, 1701 err = sysfs_create_group(&dev->kobj, &it87_group_vid);
1245 &dev_attr_vrm)) 1702 if (err)
1246 || (err = device_create_file(dev,
1247 &dev_attr_cpu0_vid)))
1248 goto ERROR4; 1703 goto ERROR4;
1249 } 1704 }
1250 1705
@@ -1257,8 +1712,7 @@ static int __devinit it87_probe(struct platform_device *pdev)
1257 return 0; 1712 return 0;
1258 1713
1259ERROR4: 1714ERROR4:
1260 sysfs_remove_group(&dev->kobj, &it87_group); 1715 it87_remove_files(dev);
1261 sysfs_remove_group(&dev->kobj, &it87_group_opt);
1262ERROR2: 1716ERROR2:
1263 platform_set_drvdata(pdev, NULL); 1717 platform_set_drvdata(pdev, NULL);
1264 kfree(data); 1718 kfree(data);
@@ -1273,8 +1727,7 @@ static int __devexit it87_remove(struct platform_device *pdev)
1273 struct it87_data *data = platform_get_drvdata(pdev); 1727 struct it87_data *data = platform_get_drvdata(pdev);
1274 1728
1275 hwmon_device_unregister(data->hwmon_dev); 1729 hwmon_device_unregister(data->hwmon_dev);
1276 sysfs_remove_group(&pdev->dev.kobj, &it87_group); 1730 it87_remove_files(&pdev->dev);
1277 sysfs_remove_group(&pdev->dev.kobj, &it87_group_opt);
1278 1731
1279 release_region(data->addr, IT87_EC_EXTENT); 1732 release_region(data->addr, IT87_EC_EXTENT);
1280 platform_set_drvdata(pdev, NULL); 1733 platform_set_drvdata(pdev, NULL);
@@ -1355,18 +1808,23 @@ static int __devinit it87_check_pwm(struct device *dev)
1355/* Called when we have found a new IT87. */ 1808/* Called when we have found a new IT87. */
1356static void __devinit it87_init_device(struct platform_device *pdev) 1809static void __devinit it87_init_device(struct platform_device *pdev)
1357{ 1810{
1811 struct it87_sio_data *sio_data = pdev->dev.platform_data;
1358 struct it87_data *data = platform_get_drvdata(pdev); 1812 struct it87_data *data = platform_get_drvdata(pdev);
1359 int tmp, i; 1813 int tmp, i;
1360 1814 u8 mask;
1361 /* initialize to sane defaults: 1815
1362 * - if the chip is in manual pwm mode, this will be overwritten with 1816 /* For each PWM channel:
1363 * the actual settings on the chip (so in this case, initialization 1817 * - If it is in automatic mode, setting to manual mode should set
1364 * is not needed) 1818 * the fan to full speed by default.
1365 * - if in automatic or on/off mode, we could switch to manual mode, 1819 * - If it is in manual mode, we need a mapping to temperature
1366 * read the registers and set manual_pwm_ctl accordingly, but currently 1820 * channels to use when later setting to automatic mode later.
1367 * this is not implemented, so we initialize to something sane */ 1821 * Use a 1:1 mapping by default (we are clueless.)
1822 * In both cases, the value can (and should) be changed by the user
1823 * prior to switching to a different mode. */
1368 for (i = 0; i < 3; i++) { 1824 for (i = 0; i < 3; i++) {
1369 data->manual_pwm_ctl[i] = 0xff; 1825 data->pwm_temp_map[i] = i;
1826 data->pwm_duty[i] = 0x7f; /* Full speed */
1827 data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */
1370 } 1828 }
1371 1829
1372 /* Some chips seem to have default value 0xff for all limit 1830 /* Some chips seem to have default value 0xff for all limit
@@ -1385,14 +1843,10 @@ static void __devinit it87_init_device(struct platform_device *pdev)
1385 it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127); 1843 it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127);
1386 } 1844 }
1387 1845
1388 /* Check if temperature channels are reset manually or by some reason */ 1846 /* Temperature channels are not forcibly enabled, as they can be
1389 tmp = it87_read_value(data, IT87_REG_TEMP_ENABLE); 1847 * set to two different sensor types and we can't guess which one
1390 if ((tmp & 0x3f) == 0) { 1848 * is correct for a given system. These channels can be enabled at
1391 /* Temp1,Temp3=thermistor; Temp2=thermal diode */ 1849 * run-time through the temp{1-3}_type sysfs accessors if needed. */
1392 tmp = (tmp & 0xc0) | 0x2a;
1393 it87_write_value(data, IT87_REG_TEMP_ENABLE, tmp);
1394 }
1395 data->sensor = tmp;
1396 1850
1397 /* Check if voltage monitors are reset manually or by some reason */ 1851 /* Check if voltage monitors are reset manually or by some reason */
1398 tmp = it87_read_value(data, IT87_REG_VIN_ENABLE); 1852 tmp = it87_read_value(data, IT87_REG_VIN_ENABLE);
@@ -1402,11 +1856,13 @@ static void __devinit it87_init_device(struct platform_device *pdev)
1402 } 1856 }
1403 1857
1404 /* Check if tachometers are reset manually or by some reason */ 1858 /* Check if tachometers are reset manually or by some reason */
1859 mask = 0x70 & ~(sio_data->skip_fan << 4);
1405 data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL); 1860 data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL);
1406 if ((data->fan_main_ctrl & 0x70) == 0) { 1861 if ((data->fan_main_ctrl & mask) == 0) {
1407 /* Enable all fan tachometers */ 1862 /* Enable all fan tachometers */
1408 data->fan_main_ctrl |= 0x70; 1863 data->fan_main_ctrl |= mask;
1409 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); 1864 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
1865 data->fan_main_ctrl);
1410 } 1866 }
1411 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07; 1867 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
1412 1868
@@ -1428,23 +1884,8 @@ static void __devinit it87_init_device(struct platform_device *pdev)
1428 } 1884 }
1429 } 1885 }
1430 1886
1431 /* Set current fan mode registers and the default settings for the 1887 /* Fan input pins may be used for alternative functions */
1432 * other mode registers */ 1888 data->has_fan &= ~sio_data->skip_fan;
1433 for (i = 0; i < 3; i++) {
1434 if (data->fan_main_ctrl & (1 << i)) {
1435 /* pwm mode */
1436 tmp = it87_read_value(data, IT87_REG_PWM(i));
1437 if (tmp & 0x80) {
1438 /* automatic pwm - not yet implemented, but
1439 * leave the settings made by the BIOS alone
1440 * until a change is requested via the sysfs
1441 * interface */
1442 } else {
1443 /* manual pwm */
1444 data->manual_pwm_ctl[i] = PWM_FROM_REG(tmp);
1445 }
1446 }
1447 }
1448 1889
1449 /* Start monitoring */ 1890 /* Start monitoring */
1450 it87_write_value(data, IT87_REG_CONFIG, 1891 it87_write_value(data, IT87_REG_CONFIG,
@@ -1452,6 +1893,26 @@ static void __devinit it87_init_device(struct platform_device *pdev)
1452 | (update_vbat ? 0x41 : 0x01)); 1893 | (update_vbat ? 0x41 : 0x01));
1453} 1894}
1454 1895
1896static void it87_update_pwm_ctrl(struct it87_data *data, int nr)
1897{
1898 data->pwm_ctrl[nr] = it87_read_value(data, IT87_REG_PWM(nr));
1899 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
1900 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
1901 else /* Manual mode */
1902 data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f;
1903
1904 if (has_old_autopwm(data)) {
1905 int i;
1906
1907 for (i = 0; i < 5 ; i++)
1908 data->auto_temp[nr][i] = it87_read_value(data,
1909 IT87_REG_AUTO_TEMP(nr, i));
1910 for (i = 0; i < 3 ; i++)
1911 data->auto_pwm[nr][i] = it87_read_value(data,
1912 IT87_REG_AUTO_PWM(nr, i));
1913 }
1914}
1915
1455static struct it87_data *it87_update_device(struct device *dev) 1916static struct it87_data *it87_update_device(struct device *dev)
1456{ 1917{
1457 struct it87_data *data = dev_get_drvdata(dev); 1918 struct it87_data *data = dev_get_drvdata(dev);
@@ -1461,24 +1922,22 @@ static struct it87_data *it87_update_device(struct device *dev)
1461 1922
1462 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 1923 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
1463 || !data->valid) { 1924 || !data->valid) {
1464
1465 if (update_vbat) { 1925 if (update_vbat) {
1466 /* Cleared after each update, so reenable. Value 1926 /* Cleared after each update, so reenable. Value
1467 returned by this read will be previous value */ 1927 returned by this read will be previous value */
1468 it87_write_value(data, IT87_REG_CONFIG, 1928 it87_write_value(data, IT87_REG_CONFIG,
1469 it87_read_value(data, IT87_REG_CONFIG) | 0x40); 1929 it87_read_value(data, IT87_REG_CONFIG) | 0x40);
1470 } 1930 }
1471 for (i = 0; i <= 7; i++) { 1931 for (i = 0; i <= 7; i++) {
1472 data->in[i] = 1932 data->in[i] =
1473 it87_read_value(data, IT87_REG_VIN(i)); 1933 it87_read_value(data, IT87_REG_VIN(i));
1474 data->in_min[i] = 1934 data->in_min[i] =
1475 it87_read_value(data, IT87_REG_VIN_MIN(i)); 1935 it87_read_value(data, IT87_REG_VIN_MIN(i));
1476 data->in_max[i] = 1936 data->in_max[i] =
1477 it87_read_value(data, IT87_REG_VIN_MAX(i)); 1937 it87_read_value(data, IT87_REG_VIN_MAX(i));
1478 } 1938 }
1479 /* in8 (battery) has no limit registers */ 1939 /* in8 (battery) has no limit registers */
1480 data->in[8] = 1940 data->in[8] = it87_read_value(data, IT87_REG_VIN(8));
1481 it87_read_value(data, IT87_REG_VIN(8));
1482 1941
1483 for (i = 0; i < 5; i++) { 1942 for (i = 0; i < 5; i++) {
1484 /* Skip disabled fans */ 1943 /* Skip disabled fans */
@@ -1486,7 +1945,7 @@ static struct it87_data *it87_update_device(struct device *dev)
1486 continue; 1945 continue;
1487 1946
1488 data->fan_min[i] = 1947 data->fan_min[i] =
1489 it87_read_value(data, IT87_REG_FAN_MIN[i]); 1948 it87_read_value(data, IT87_REG_FAN_MIN[i]);
1490 data->fan[i] = it87_read_value(data, 1949 data->fan[i] = it87_read_value(data,
1491 IT87_REG_FAN[i]); 1950 IT87_REG_FAN[i]);
1492 /* Add high byte if in 16-bit mode */ 1951 /* Add high byte if in 16-bit mode */
@@ -1499,11 +1958,11 @@ static struct it87_data *it87_update_device(struct device *dev)
1499 } 1958 }
1500 for (i = 0; i < 3; i++) { 1959 for (i = 0; i < 3; i++) {
1501 data->temp[i] = 1960 data->temp[i] =
1502 it87_read_value(data, IT87_REG_TEMP(i)); 1961 it87_read_value(data, IT87_REG_TEMP(i));
1503 data->temp_high[i] = 1962 data->temp_high[i] =
1504 it87_read_value(data, IT87_REG_TEMP_HIGH(i)); 1963 it87_read_value(data, IT87_REG_TEMP_HIGH(i));
1505 data->temp_low[i] = 1964 data->temp_low[i] =
1506 it87_read_value(data, IT87_REG_TEMP_LOW(i)); 1965 it87_read_value(data, IT87_REG_TEMP_LOW(i));
1507 } 1966 }
1508 1967
1509 /* Newer chips don't have clock dividers */ 1968 /* Newer chips don't have clock dividers */
@@ -1518,9 +1977,13 @@ static struct it87_data *it87_update_device(struct device *dev)
1518 it87_read_value(data, IT87_REG_ALARM1) | 1977 it87_read_value(data, IT87_REG_ALARM1) |
1519 (it87_read_value(data, IT87_REG_ALARM2) << 8) | 1978 (it87_read_value(data, IT87_REG_ALARM2) << 8) |
1520 (it87_read_value(data, IT87_REG_ALARM3) << 16); 1979 (it87_read_value(data, IT87_REG_ALARM3) << 16);
1980 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
1981
1521 data->fan_main_ctrl = it87_read_value(data, 1982 data->fan_main_ctrl = it87_read_value(data,
1522 IT87_REG_FAN_MAIN_CTRL); 1983 IT87_REG_FAN_MAIN_CTRL);
1523 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL); 1984 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL);
1985 for (i = 0; i < 3; i++)
1986 it87_update_pwm_ctrl(data, i);
1524 1987
1525 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE); 1988 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
1526 /* The 8705 does not have VID capability. 1989 /* The 8705 does not have VID capability.
@@ -1595,7 +2058,7 @@ exit:
1595static int __init sm_it87_init(void) 2058static int __init sm_it87_init(void)
1596{ 2059{
1597 int err; 2060 int err;
1598 unsigned short isa_address=0; 2061 unsigned short isa_address = 0;
1599 struct it87_sio_data sio_data; 2062 struct it87_sio_data sio_data;
1600 2063
1601 memset(&sio_data, 0, sizeof(struct it87_sio_data)); 2064 memset(&sio_data, 0, sizeof(struct it87_sio_data));
@@ -1607,7 +2070,7 @@ static int __init sm_it87_init(void)
1607 return err; 2070 return err;
1608 2071
1609 err = it87_device_add(isa_address, &sio_data); 2072 err = it87_device_add(isa_address, &sio_data);
1610 if (err){ 2073 if (err) {
1611 platform_driver_unregister(&it87_driver); 2074 platform_driver_unregister(&it87_driver);
1612 return err; 2075 return err;
1613 } 2076 }
@@ -1628,7 +2091,8 @@ MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F/8720F/8726F, SiS950 driver");
1628module_param(update_vbat, bool, 0); 2091module_param(update_vbat, bool, 0);
1629MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); 2092MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
1630module_param(fix_pwm_polarity, bool, 0); 2093module_param(fix_pwm_polarity, bool, 0);
1631MODULE_PARM_DESC(fix_pwm_polarity, "Force PWM polarity to active high (DANGEROUS)"); 2094MODULE_PARM_DESC(fix_pwm_polarity,
2095 "Force PWM polarity to active high (DANGEROUS)");
1632MODULE_LICENSE("GPL"); 2096MODULE_LICENSE("GPL");
1633 2097
1634module_init(sm_it87_init); 2098module_init(sm_it87_init);
diff --git a/drivers/hwmon/k10temp.c b/drivers/hwmon/k10temp.c
new file mode 100644
index 000000000000..099a2138cdf6
--- /dev/null
+++ b/drivers/hwmon/k10temp.c
@@ -0,0 +1,223 @@
1/*
2 * k10temp.c - AMD Family 10h/11h processor hardware monitoring
3 *
4 * Copyright (c) 2009 Clemens Ladisch <clemens@ladisch.de>
5 *
6 *
7 * This driver is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This driver 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.
14 * See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this driver; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <linux/err.h>
21#include <linux/hwmon.h>
22#include <linux/hwmon-sysfs.h>
23#include <linux/init.h>
24#include <linux/module.h>
25#include <linux/pci.h>
26#include <asm/processor.h>
27
28MODULE_DESCRIPTION("AMD Family 10h/11h CPU core temperature monitor");
29MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
30MODULE_LICENSE("GPL");
31
32static bool force;
33module_param(force, bool, 0444);
34MODULE_PARM_DESC(force, "force loading on processors with erratum 319");
35
36/* CPUID function 0x80000001, ebx */
37#define CPUID_PKGTYPE_MASK 0xf0000000
38#define CPUID_PKGTYPE_F 0x00000000
39#define CPUID_PKGTYPE_AM2R2_AM3 0x10000000
40
41/* DRAM controller (PCI function 2) */
42#define REG_DCT0_CONFIG_HIGH 0x094
43#define DDR3_MODE 0x00000100
44
45/* miscellaneous (PCI function 3) */
46#define REG_HARDWARE_THERMAL_CONTROL 0x64
47#define HTC_ENABLE 0x00000001
48
49#define REG_REPORTED_TEMPERATURE 0xa4
50
51#define REG_NORTHBRIDGE_CAPABILITIES 0xe8
52#define NB_CAP_HTC 0x00000400
53
54static ssize_t show_temp(struct device *dev,
55 struct device_attribute *attr, char *buf)
56{
57 u32 regval;
58
59 pci_read_config_dword(to_pci_dev(dev),
60 REG_REPORTED_TEMPERATURE, &regval);
61 return sprintf(buf, "%u\n", (regval >> 21) * 125);
62}
63
64static ssize_t show_temp_max(struct device *dev,
65 struct device_attribute *attr, char *buf)
66{
67 return sprintf(buf, "%d\n", 70 * 1000);
68}
69
70static ssize_t show_temp_crit(struct device *dev,
71 struct device_attribute *devattr, char *buf)
72{
73 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
74 int show_hyst = attr->index;
75 u32 regval;
76 int value;
77
78 pci_read_config_dword(to_pci_dev(dev),
79 REG_HARDWARE_THERMAL_CONTROL, &regval);
80 value = ((regval >> 16) & 0x7f) * 500 + 52000;
81 if (show_hyst)
82 value -= ((regval >> 24) & 0xf) * 500;
83 return sprintf(buf, "%d\n", value);
84}
85
86static ssize_t show_name(struct device *dev,
87 struct device_attribute *attr, char *buf)
88{
89 return sprintf(buf, "k10temp\n");
90}
91
92static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL);
93static DEVICE_ATTR(temp1_max, S_IRUGO, show_temp_max, NULL);
94static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, show_temp_crit, NULL, 0);
95static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, show_temp_crit, NULL, 1);
96static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
97
98static bool __devinit has_erratum_319(struct pci_dev *pdev)
99{
100 u32 pkg_type, reg_dram_cfg;
101
102 if (boot_cpu_data.x86 != 0x10)
103 return false;
104
105 /*
106 * Erratum 319: The thermal sensor of Socket F/AM2+ processors
107 * may be unreliable.
108 */
109 pkg_type = cpuid_ebx(0x80000001) & CPUID_PKGTYPE_MASK;
110 if (pkg_type == CPUID_PKGTYPE_F)
111 return true;
112 if (pkg_type != CPUID_PKGTYPE_AM2R2_AM3)
113 return false;
114
115 /* Differentiate between AM2+ (bad) and AM3 (good) */
116 pci_bus_read_config_dword(pdev->bus,
117 PCI_DEVFN(PCI_SLOT(pdev->devfn), 2),
118 REG_DCT0_CONFIG_HIGH, &reg_dram_cfg);
119 return !(reg_dram_cfg & DDR3_MODE);
120}
121
122static int __devinit k10temp_probe(struct pci_dev *pdev,
123 const struct pci_device_id *id)
124{
125 struct device *hwmon_dev;
126 u32 reg_caps, reg_htc;
127 int unreliable = has_erratum_319(pdev);
128 int err;
129
130 if (unreliable && !force) {
131 dev_err(&pdev->dev,
132 "unreliable CPU thermal sensor; monitoring disabled\n");
133 err = -ENODEV;
134 goto exit;
135 }
136
137 err = device_create_file(&pdev->dev, &dev_attr_temp1_input);
138 if (err)
139 goto exit;
140 err = device_create_file(&pdev->dev, &dev_attr_temp1_max);
141 if (err)
142 goto exit_remove;
143
144 pci_read_config_dword(pdev, REG_NORTHBRIDGE_CAPABILITIES, &reg_caps);
145 pci_read_config_dword(pdev, REG_HARDWARE_THERMAL_CONTROL, &reg_htc);
146 if ((reg_caps & NB_CAP_HTC) && (reg_htc & HTC_ENABLE)) {
147 err = device_create_file(&pdev->dev,
148 &sensor_dev_attr_temp1_crit.dev_attr);
149 if (err)
150 goto exit_remove;
151 err = device_create_file(&pdev->dev,
152 &sensor_dev_attr_temp1_crit_hyst.dev_attr);
153 if (err)
154 goto exit_remove;
155 }
156
157 err = device_create_file(&pdev->dev, &dev_attr_name);
158 if (err)
159 goto exit_remove;
160
161 hwmon_dev = hwmon_device_register(&pdev->dev);
162 if (IS_ERR(hwmon_dev)) {
163 err = PTR_ERR(hwmon_dev);
164 goto exit_remove;
165 }
166 dev_set_drvdata(&pdev->dev, hwmon_dev);
167
168 if (unreliable && force)
169 dev_warn(&pdev->dev,
170 "unreliable CPU thermal sensor; check erratum 319\n");
171 return 0;
172
173exit_remove:
174 device_remove_file(&pdev->dev, &dev_attr_name);
175 device_remove_file(&pdev->dev, &dev_attr_temp1_input);
176 device_remove_file(&pdev->dev, &dev_attr_temp1_max);
177 device_remove_file(&pdev->dev,
178 &sensor_dev_attr_temp1_crit.dev_attr);
179 device_remove_file(&pdev->dev,
180 &sensor_dev_attr_temp1_crit_hyst.dev_attr);
181exit:
182 return err;
183}
184
185static void __devexit k10temp_remove(struct pci_dev *pdev)
186{
187 hwmon_device_unregister(dev_get_drvdata(&pdev->dev));
188 device_remove_file(&pdev->dev, &dev_attr_name);
189 device_remove_file(&pdev->dev, &dev_attr_temp1_input);
190 device_remove_file(&pdev->dev, &dev_attr_temp1_max);
191 device_remove_file(&pdev->dev,
192 &sensor_dev_attr_temp1_crit.dev_attr);
193 device_remove_file(&pdev->dev,
194 &sensor_dev_attr_temp1_crit_hyst.dev_attr);
195 dev_set_drvdata(&pdev->dev, NULL);
196}
197
198static const struct pci_device_id k10temp_id_table[] = {
199 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_10H_NB_MISC) },
200 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_11H_NB_MISC) },
201 {}
202};
203MODULE_DEVICE_TABLE(pci, k10temp_id_table);
204
205static struct pci_driver k10temp_driver = {
206 .name = "k10temp",
207 .id_table = k10temp_id_table,
208 .probe = k10temp_probe,
209 .remove = __devexit_p(k10temp_remove),
210};
211
212static int __init k10temp_init(void)
213{
214 return pci_register_driver(&k10temp_driver);
215}
216
217static void __exit k10temp_exit(void)
218{
219 pci_unregister_driver(&k10temp_driver);
220}
221
222module_init(k10temp_init)
223module_exit(k10temp_exit)
diff --git a/drivers/hwmon/k8temp.c b/drivers/hwmon/k8temp.c
index 1fe995111841..0ceb6d6200a3 100644
--- a/drivers/hwmon/k8temp.c
+++ b/drivers/hwmon/k8temp.c
@@ -136,7 +136,7 @@ static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 1, 0);
136static SENSOR_DEVICE_ATTR_2(temp4_input, S_IRUGO, show_temp, NULL, 1, 1); 136static SENSOR_DEVICE_ATTR_2(temp4_input, S_IRUGO, show_temp, NULL, 1, 1);
137static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 137static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
138 138
139static struct pci_device_id k8temp_ids[] = { 139static const struct pci_device_id k8temp_ids[] = {
140 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MISC) }, 140 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MISC) },
141 { 0 }, 141 { 0 },
142}; 142};
diff --git a/drivers/hwmon/lis3lv02d.c b/drivers/hwmon/lis3lv02d.c
index cf5afb9a10ab..b2f2277cad3c 100644
--- a/drivers/hwmon/lis3lv02d.c
+++ b/drivers/hwmon/lis3lv02d.c
@@ -43,13 +43,30 @@
43#define MDPS_POLL_INTERVAL 50 43#define MDPS_POLL_INTERVAL 50
44/* 44/*
45 * The sensor can also generate interrupts (DRDY) but it's pretty pointless 45 * The sensor can also generate interrupts (DRDY) but it's pretty pointless
46 * because their are generated even if the data do not change. So it's better 46 * because they are generated even if the data do not change. So it's better
47 * to keep the interrupt for the free-fall event. The values are updated at 47 * to keep the interrupt for the free-fall event. The values are updated at
48 * 40Hz (at the lowest frequency), but as it can be pretty time consuming on 48 * 40Hz (at the lowest frequency), but as it can be pretty time consuming on
49 * some low processor, we poll the sensor only at 20Hz... enough for the 49 * some low processor, we poll the sensor only at 20Hz... enough for the
50 * joystick. 50 * joystick.
51 */ 51 */
52 52
53#define LIS3_PWRON_DELAY_WAI_12B (5000)
54#define LIS3_PWRON_DELAY_WAI_8B (3000)
55
56/*
57 * LIS3LV02D spec says 1024 LSBs corresponds 1 G -> 1LSB is 1000/1024 mG
58 * LIS302D spec says: 18 mG / digit
59 * LIS3_ACCURACY is used to increase accuracy of the intermediate
60 * calculation results.
61 */
62#define LIS3_ACCURACY 1024
63/* Sensitivity values for -2G +2G scale */
64#define LIS3_SENSITIVITY_12B ((LIS3_ACCURACY * 1000) / 1024)
65#define LIS3_SENSITIVITY_8B (18 * LIS3_ACCURACY)
66
67#define LIS3_DEFAULT_FUZZ 3
68#define LIS3_DEFAULT_FLAT 3
69
53struct lis3lv02d lis3_dev = { 70struct lis3lv02d lis3_dev = {
54 .misc_wait = __WAIT_QUEUE_HEAD_INITIALIZER(lis3_dev.misc_wait), 71 .misc_wait = __WAIT_QUEUE_HEAD_INITIALIZER(lis3_dev.misc_wait),
55}; 72};
@@ -65,7 +82,7 @@ static s16 lis3lv02d_read_8(struct lis3lv02d *lis3, int reg)
65 return lo; 82 return lo;
66} 83}
67 84
68static s16 lis3lv02d_read_16(struct lis3lv02d *lis3, int reg) 85static s16 lis3lv02d_read_12(struct lis3lv02d *lis3, int reg)
69{ 86{
70 u8 lo, hi; 87 u8 lo, hi;
71 88
@@ -102,16 +119,106 @@ static inline int lis3lv02d_get_axis(s8 axis, int hw_values[3])
102static void lis3lv02d_get_xyz(struct lis3lv02d *lis3, int *x, int *y, int *z) 119static void lis3lv02d_get_xyz(struct lis3lv02d *lis3, int *x, int *y, int *z)
103{ 120{
104 int position[3]; 121 int position[3];
122 int i;
105 123
124 mutex_lock(&lis3->mutex);
106 position[0] = lis3->read_data(lis3, OUTX); 125 position[0] = lis3->read_data(lis3, OUTX);
107 position[1] = lis3->read_data(lis3, OUTY); 126 position[1] = lis3->read_data(lis3, OUTY);
108 position[2] = lis3->read_data(lis3, OUTZ); 127 position[2] = lis3->read_data(lis3, OUTZ);
128 mutex_unlock(&lis3->mutex);
129
130 for (i = 0; i < 3; i++)
131 position[i] = (position[i] * lis3->scale) / LIS3_ACCURACY;
109 132
110 *x = lis3lv02d_get_axis(lis3->ac.x, position); 133 *x = lis3lv02d_get_axis(lis3->ac.x, position);
111 *y = lis3lv02d_get_axis(lis3->ac.y, position); 134 *y = lis3lv02d_get_axis(lis3->ac.y, position);
112 *z = lis3lv02d_get_axis(lis3->ac.z, position); 135 *z = lis3lv02d_get_axis(lis3->ac.z, position);
113} 136}
114 137
138/* conversion btw sampling rate and the register values */
139static int lis3_12_rates[4] = {40, 160, 640, 2560};
140static int lis3_8_rates[2] = {100, 400};
141
142/* ODR is Output Data Rate */
143static int lis3lv02d_get_odr(void)
144{
145 u8 ctrl;
146 int shift;
147
148 lis3_dev.read(&lis3_dev, CTRL_REG1, &ctrl);
149 ctrl &= lis3_dev.odr_mask;
150 shift = ffs(lis3_dev.odr_mask) - 1;
151 return lis3_dev.odrs[(ctrl >> shift)];
152}
153
154static int lis3lv02d_set_odr(int rate)
155{
156 u8 ctrl;
157 int i, len, shift;
158
159 lis3_dev.read(&lis3_dev, CTRL_REG1, &ctrl);
160 ctrl &= ~lis3_dev.odr_mask;
161 len = 1 << hweight_long(lis3_dev.odr_mask); /* # of possible values */
162 shift = ffs(lis3_dev.odr_mask) - 1;
163
164 for (i = 0; i < len; i++)
165 if (lis3_dev.odrs[i] == rate) {
166 lis3_dev.write(&lis3_dev, CTRL_REG1,
167 ctrl | (i << shift));
168 return 0;
169 }
170 return -EINVAL;
171}
172
173static int lis3lv02d_selftest(struct lis3lv02d *lis3, s16 results[3])
174{
175 u8 reg;
176 s16 x, y, z;
177 u8 selftest;
178 int ret;
179
180 mutex_lock(&lis3->mutex);
181 if (lis3_dev.whoami == WAI_12B)
182 selftest = CTRL1_ST;
183 else
184 selftest = CTRL1_STP;
185
186 lis3->read(lis3, CTRL_REG1, &reg);
187 lis3->write(lis3, CTRL_REG1, (reg | selftest));
188 msleep(lis3->pwron_delay / lis3lv02d_get_odr());
189
190 /* Read directly to avoid axis remap */
191 x = lis3->read_data(lis3, OUTX);
192 y = lis3->read_data(lis3, OUTY);
193 z = lis3->read_data(lis3, OUTZ);
194
195 /* back to normal settings */
196 lis3->write(lis3, CTRL_REG1, reg);
197 msleep(lis3->pwron_delay / lis3lv02d_get_odr());
198
199 results[0] = x - lis3->read_data(lis3, OUTX);
200 results[1] = y - lis3->read_data(lis3, OUTY);
201 results[2] = z - lis3->read_data(lis3, OUTZ);
202
203 ret = 0;
204 if (lis3->pdata) {
205 int i;
206 for (i = 0; i < 3; i++) {
207 /* Check against selftest acceptance limits */
208 if ((results[i] < lis3->pdata->st_min_limits[i]) ||
209 (results[i] > lis3->pdata->st_max_limits[i])) {
210 ret = -EIO;
211 goto fail;
212 }
213 }
214 }
215
216 /* test passed */
217fail:
218 mutex_unlock(&lis3->mutex);
219 return ret;
220}
221
115void lis3lv02d_poweroff(struct lis3lv02d *lis3) 222void lis3lv02d_poweroff(struct lis3lv02d *lis3)
116{ 223{
117 /* disable X,Y,Z axis and power down */ 224 /* disable X,Y,Z axis and power down */
@@ -125,14 +232,19 @@ void lis3lv02d_poweron(struct lis3lv02d *lis3)
125 232
126 lis3->init(lis3); 233 lis3->init(lis3);
127 234
235 /* LIS3 power on delay is quite long */
236 msleep(lis3->pwron_delay / lis3lv02d_get_odr());
237
128 /* 238 /*
129 * Common configuration 239 * Common configuration
130 * BDU: LSB and MSB values are not updated until both have been read. 240 * BDU: (12 bits sensors only) LSB and MSB values are not updated until
131 * So the value read will always be correct. 241 * both have been read. So the value read will always be correct.
132 */ 242 */
133 lis3->read(lis3, CTRL_REG2, &reg); 243 if (lis3->whoami == WAI_12B) {
134 reg |= CTRL2_BDU; 244 lis3->read(lis3, CTRL_REG2, &reg);
135 lis3->write(lis3, CTRL_REG2, reg); 245 reg |= CTRL2_BDU;
246 lis3->write(lis3, CTRL_REG2, reg);
247 }
136} 248}
137EXPORT_SYMBOL_GPL(lis3lv02d_poweron); 249EXPORT_SYMBOL_GPL(lis3lv02d_poweron);
138 250
@@ -273,22 +385,17 @@ static void lis3lv02d_joystick_poll(struct input_polled_dev *pidev)
273 int x, y, z; 385 int x, y, z;
274 386
275 lis3lv02d_get_xyz(&lis3_dev, &x, &y, &z); 387 lis3lv02d_get_xyz(&lis3_dev, &x, &y, &z);
276 input_report_abs(pidev->input, ABS_X, x - lis3_dev.xcalib); 388 input_report_abs(pidev->input, ABS_X, x);
277 input_report_abs(pidev->input, ABS_Y, y - lis3_dev.ycalib); 389 input_report_abs(pidev->input, ABS_Y, y);
278 input_report_abs(pidev->input, ABS_Z, z - lis3_dev.zcalib); 390 input_report_abs(pidev->input, ABS_Z, z);
279} 391 input_sync(pidev->input);
280
281
282static inline void lis3lv02d_calibrate_joystick(void)
283{
284 lis3lv02d_get_xyz(&lis3_dev,
285 &lis3_dev.xcalib, &lis3_dev.ycalib, &lis3_dev.zcalib);
286} 392}
287 393
288int lis3lv02d_joystick_enable(void) 394int lis3lv02d_joystick_enable(void)
289{ 395{
290 struct input_dev *input_dev; 396 struct input_dev *input_dev;
291 int err; 397 int err;
398 int max_val, fuzz, flat;
292 399
293 if (lis3_dev.idev) 400 if (lis3_dev.idev)
294 return -EINVAL; 401 return -EINVAL;
@@ -301,8 +408,6 @@ int lis3lv02d_joystick_enable(void)
301 lis3_dev.idev->poll_interval = MDPS_POLL_INTERVAL; 408 lis3_dev.idev->poll_interval = MDPS_POLL_INTERVAL;
302 input_dev = lis3_dev.idev->input; 409 input_dev = lis3_dev.idev->input;
303 410
304 lis3lv02d_calibrate_joystick();
305
306 input_dev->name = "ST LIS3LV02DL Accelerometer"; 411 input_dev->name = "ST LIS3LV02DL Accelerometer";
307 input_dev->phys = DRIVER_NAME "/input0"; 412 input_dev->phys = DRIVER_NAME "/input0";
308 input_dev->id.bustype = BUS_HOST; 413 input_dev->id.bustype = BUS_HOST;
@@ -310,9 +415,12 @@ int lis3lv02d_joystick_enable(void)
310 input_dev->dev.parent = &lis3_dev.pdev->dev; 415 input_dev->dev.parent = &lis3_dev.pdev->dev;
311 416
312 set_bit(EV_ABS, input_dev->evbit); 417 set_bit(EV_ABS, input_dev->evbit);
313 input_set_abs_params(input_dev, ABS_X, -lis3_dev.mdps_max_val, lis3_dev.mdps_max_val, 3, 3); 418 max_val = (lis3_dev.mdps_max_val * lis3_dev.scale) / LIS3_ACCURACY;
314 input_set_abs_params(input_dev, ABS_Y, -lis3_dev.mdps_max_val, lis3_dev.mdps_max_val, 3, 3); 419 fuzz = (LIS3_DEFAULT_FUZZ * lis3_dev.scale) / LIS3_ACCURACY;
315 input_set_abs_params(input_dev, ABS_Z, -lis3_dev.mdps_max_val, lis3_dev.mdps_max_val, 3, 3); 420 flat = (LIS3_DEFAULT_FLAT * lis3_dev.scale) / LIS3_ACCURACY;
421 input_set_abs_params(input_dev, ABS_X, -max_val, max_val, fuzz, flat);
422 input_set_abs_params(input_dev, ABS_Y, -max_val, max_val, fuzz, flat);
423 input_set_abs_params(input_dev, ABS_Z, -max_val, max_val, fuzz, flat);
316 424
317 err = input_register_polled_device(lis3_dev.idev); 425 err = input_register_polled_device(lis3_dev.idev);
318 if (err) { 426 if (err) {
@@ -332,11 +440,23 @@ void lis3lv02d_joystick_disable(void)
332 if (lis3_dev.irq) 440 if (lis3_dev.irq)
333 misc_deregister(&lis3lv02d_misc_device); 441 misc_deregister(&lis3lv02d_misc_device);
334 input_unregister_polled_device(lis3_dev.idev); 442 input_unregister_polled_device(lis3_dev.idev);
443 input_free_polled_device(lis3_dev.idev);
335 lis3_dev.idev = NULL; 444 lis3_dev.idev = NULL;
336} 445}
337EXPORT_SYMBOL_GPL(lis3lv02d_joystick_disable); 446EXPORT_SYMBOL_GPL(lis3lv02d_joystick_disable);
338 447
339/* Sysfs stuff */ 448/* Sysfs stuff */
449static ssize_t lis3lv02d_selftest_show(struct device *dev,
450 struct device_attribute *attr, char *buf)
451{
452 int result;
453 s16 values[3];
454
455 result = lis3lv02d_selftest(&lis3_dev, values);
456 return sprintf(buf, "%s %d %d %d\n", result == 0 ? "OK" : "FAIL",
457 values[0], values[1], values[2]);
458}
459
340static ssize_t lis3lv02d_position_show(struct device *dev, 460static ssize_t lis3lv02d_position_show(struct device *dev,
341 struct device_attribute *attr, char *buf) 461 struct device_attribute *attr, char *buf)
342{ 462{
@@ -346,41 +466,35 @@ static ssize_t lis3lv02d_position_show(struct device *dev,
346 return sprintf(buf, "(%d,%d,%d)\n", x, y, z); 466 return sprintf(buf, "(%d,%d,%d)\n", x, y, z);
347} 467}
348 468
349static ssize_t lis3lv02d_calibrate_show(struct device *dev, 469static ssize_t lis3lv02d_rate_show(struct device *dev,
350 struct device_attribute *attr, char *buf) 470 struct device_attribute *attr, char *buf)
351{ 471{
352 return sprintf(buf, "(%d,%d,%d)\n", lis3_dev.xcalib, lis3_dev.ycalib, lis3_dev.zcalib); 472 return sprintf(buf, "%d\n", lis3lv02d_get_odr());
353} 473}
354 474
355static ssize_t lis3lv02d_calibrate_store(struct device *dev, 475static ssize_t lis3lv02d_rate_set(struct device *dev,
356 struct device_attribute *attr, 476 struct device_attribute *attr, const char *buf,
357 const char *buf, size_t count) 477 size_t count)
358{ 478{
359 lis3lv02d_calibrate_joystick(); 479 unsigned long rate;
360 return count;
361}
362 480
363/* conversion btw sampling rate and the register values */ 481 if (strict_strtoul(buf, 0, &rate))
364static int lis3lv02dl_df_val[4] = {40, 160, 640, 2560}; 482 return -EINVAL;
365static ssize_t lis3lv02d_rate_show(struct device *dev,
366 struct device_attribute *attr, char *buf)
367{
368 u8 ctrl;
369 int val;
370 483
371 lis3_dev.read(&lis3_dev, CTRL_REG1, &ctrl); 484 if (lis3lv02d_set_odr(rate))
372 val = (ctrl & (CTRL1_DF0 | CTRL1_DF1)) >> 4; 485 return -EINVAL;
373 return sprintf(buf, "%d\n", lis3lv02dl_df_val[val]); 486
487 return count;
374} 488}
375 489
490static DEVICE_ATTR(selftest, S_IRUSR, lis3lv02d_selftest_show, NULL);
376static DEVICE_ATTR(position, S_IRUGO, lis3lv02d_position_show, NULL); 491static DEVICE_ATTR(position, S_IRUGO, lis3lv02d_position_show, NULL);
377static DEVICE_ATTR(calibrate, S_IRUGO|S_IWUSR, lis3lv02d_calibrate_show, 492static DEVICE_ATTR(rate, S_IRUGO | S_IWUSR, lis3lv02d_rate_show,
378 lis3lv02d_calibrate_store); 493 lis3lv02d_rate_set);
379static DEVICE_ATTR(rate, S_IRUGO, lis3lv02d_rate_show, NULL);
380 494
381static struct attribute *lis3lv02d_attributes[] = { 495static struct attribute *lis3lv02d_attributes[] = {
496 &dev_attr_selftest.attr,
382 &dev_attr_position.attr, 497 &dev_attr_position.attr,
383 &dev_attr_calibrate.attr,
384 &dev_attr_rate.attr, 498 &dev_attr_rate.attr,
385 NULL 499 NULL
386}; 500};
@@ -409,22 +523,30 @@ EXPORT_SYMBOL_GPL(lis3lv02d_remove_fs);
409 523
410/* 524/*
411 * Initialise the accelerometer and the various subsystems. 525 * Initialise the accelerometer and the various subsystems.
412 * Should be rather independant of the bus system. 526 * Should be rather independent of the bus system.
413 */ 527 */
414int lis3lv02d_init_device(struct lis3lv02d *dev) 528int lis3lv02d_init_device(struct lis3lv02d *dev)
415{ 529{
416 dev->whoami = lis3lv02d_read_8(dev, WHO_AM_I); 530 dev->whoami = lis3lv02d_read_8(dev, WHO_AM_I);
417 531
418 switch (dev->whoami) { 532 switch (dev->whoami) {
419 case LIS_DOUBLE_ID: 533 case WAI_12B:
420 printk(KERN_INFO DRIVER_NAME ": 2-byte sensor found\n"); 534 printk(KERN_INFO DRIVER_NAME ": 12 bits sensor found\n");
421 dev->read_data = lis3lv02d_read_16; 535 dev->read_data = lis3lv02d_read_12;
422 dev->mdps_max_val = 2048; 536 dev->mdps_max_val = 2048;
537 dev->pwron_delay = LIS3_PWRON_DELAY_WAI_12B;
538 dev->odrs = lis3_12_rates;
539 dev->odr_mask = CTRL1_DF0 | CTRL1_DF1;
540 dev->scale = LIS3_SENSITIVITY_12B;
423 break; 541 break;
424 case LIS_SINGLE_ID: 542 case WAI_8B:
425 printk(KERN_INFO DRIVER_NAME ": 1-byte sensor found\n"); 543 printk(KERN_INFO DRIVER_NAME ": 8 bits sensor found\n");
426 dev->read_data = lis3lv02d_read_8; 544 dev->read_data = lis3lv02d_read_8;
427 dev->mdps_max_val = 128; 545 dev->mdps_max_val = 128;
546 dev->pwron_delay = LIS3_PWRON_DELAY_WAI_8B;
547 dev->odrs = lis3_8_rates;
548 dev->odr_mask = CTRL1_DR;
549 dev->scale = LIS3_SENSITIVITY_8B;
428 break; 550 break;
429 default: 551 default:
430 printk(KERN_ERR DRIVER_NAME 552 printk(KERN_ERR DRIVER_NAME
@@ -432,6 +554,8 @@ int lis3lv02d_init_device(struct lis3lv02d *dev)
432 return -EINVAL; 554 return -EINVAL;
433 } 555 }
434 556
557 mutex_init(&dev->mutex);
558
435 lis3lv02d_add_fs(dev); 559 lis3lv02d_add_fs(dev);
436 lis3lv02d_poweron(dev); 560 lis3lv02d_poweron(dev);
437 561
@@ -443,7 +567,7 @@ int lis3lv02d_init_device(struct lis3lv02d *dev)
443 if (dev->pdata) { 567 if (dev->pdata) {
444 struct lis3lv02d_platform_data *p = dev->pdata; 568 struct lis3lv02d_platform_data *p = dev->pdata;
445 569
446 if (p->click_flags && (dev->whoami == LIS_SINGLE_ID)) { 570 if (p->click_flags && (dev->whoami == WAI_8B)) {
447 dev->write(dev, CLICK_CFG, p->click_flags); 571 dev->write(dev, CLICK_CFG, p->click_flags);
448 dev->write(dev, CLICK_TIMELIMIT, p->click_time_limit); 572 dev->write(dev, CLICK_TIMELIMIT, p->click_time_limit);
449 dev->write(dev, CLICK_LATENCY, p->click_latency); 573 dev->write(dev, CLICK_LATENCY, p->click_latency);
@@ -454,7 +578,7 @@ int lis3lv02d_init_device(struct lis3lv02d *dev)
454 (p->click_thresh_y << 4)); 578 (p->click_thresh_y << 4));
455 } 579 }
456 580
457 if (p->wakeup_flags && (dev->whoami == LIS_SINGLE_ID)) { 581 if (p->wakeup_flags && (dev->whoami == WAI_8B)) {
458 dev->write(dev, FF_WU_CFG_1, p->wakeup_flags); 582 dev->write(dev, FF_WU_CFG_1, p->wakeup_flags);
459 dev->write(dev, FF_WU_THS_1, p->wakeup_thresh & 0x7f); 583 dev->write(dev, FF_WU_THS_1, p->wakeup_thresh & 0x7f);
460 /* default to 2.5ms for now */ 584 /* default to 2.5ms for now */
@@ -484,4 +608,3 @@ EXPORT_SYMBOL_GPL(lis3lv02d_init_device);
484MODULE_DESCRIPTION("ST LIS3LV02Dx three-axis digital accelerometer driver"); 608MODULE_DESCRIPTION("ST LIS3LV02Dx three-axis digital accelerometer driver");
485MODULE_AUTHOR("Yan Burman, Eric Piel, Pavel Machek"); 609MODULE_AUTHOR("Yan Burman, Eric Piel, Pavel Machek");
486MODULE_LICENSE("GPL"); 610MODULE_LICENSE("GPL");
487
diff --git a/drivers/hwmon/lis3lv02d.h b/drivers/hwmon/lis3lv02d.h
index 3e1ff46f72d3..e6a01f44709b 100644
--- a/drivers/hwmon/lis3lv02d.h
+++ b/drivers/hwmon/lis3lv02d.h
@@ -2,7 +2,7 @@
2 * lis3lv02d.h - ST LIS3LV02DL accelerometer driver 2 * lis3lv02d.h - ST LIS3LV02DL accelerometer driver
3 * 3 *
4 * Copyright (C) 2007-2008 Yan Burman 4 * Copyright (C) 2007-2008 Yan Burman
5 * Copyright (C) 2008 Eric Piel 5 * Copyright (C) 2008-2009 Eric Piel
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
@@ -22,20 +22,18 @@
22#include <linux/input-polldev.h> 22#include <linux/input-polldev.h>
23 23
24/* 24/*
25 * The actual chip is STMicroelectronics LIS3LV02DL or LIS3LV02DQ that seems to 25 * This driver tries to support the "digital" accelerometer chips from
26 * be connected via SPI. There exists also several similar chips (such as LIS302DL or 26 * STMicroelectronics such as LIS3LV02DL, LIS302DL, LIS3L02DQ, LIS331DL,
27 * LIS3L02DQ) and they have slightly different registers, but we can provide a 27 * LIS35DE, or LIS202DL. They are very similar in terms of programming, with
28 * common interface for all of them. 28 * almost the same registers. In addition to differing on physical properties,
29 * They can also be connected via I²C. 29 * they differ on the number of axes (2/3), precision (8/12 bits), and special
30 * features (freefall detection, click...). Unfortunately, not all the
31 * differences can be probed via a register.
32 * They can be connected either via I²C or SPI.
30 */ 33 */
31 34
32#include <linux/lis3lv02d.h> 35#include <linux/lis3lv02d.h>
33 36
34/* 2-byte registers */
35#define LIS_DOUBLE_ID 0x3A /* LIS3LV02D[LQ] */
36/* 1-byte registers */
37#define LIS_SINGLE_ID 0x3B /* LIS[32]02DL and others */
38
39enum lis3_reg { 37enum lis3_reg {
40 WHO_AM_I = 0x0F, 38 WHO_AM_I = 0x0F,
41 OFFSET_X = 0x16, 39 OFFSET_X = 0x16,
@@ -94,7 +92,13 @@ enum lis3lv02d_reg {
94 DD_THSE_H = 0x3F, 92 DD_THSE_H = 0x3F,
95}; 93};
96 94
97enum lis3lv02d_ctrl1 { 95enum lis3_who_am_i {
96 WAI_12B = 0x3A, /* 12 bits: LIS3LV02D[LQ]... */
97 WAI_8B = 0x3B, /* 8 bits: LIS[23]02D[LQ]... */
98 WAI_6B = 0x52, /* 6 bits: LIS331DLF - not supported */
99};
100
101enum lis3lv02d_ctrl1_12b {
98 CTRL1_Xen = 0x01, 102 CTRL1_Xen = 0x01,
99 CTRL1_Yen = 0x02, 103 CTRL1_Yen = 0x02,
100 CTRL1_Zen = 0x04, 104 CTRL1_Zen = 0x04,
@@ -104,6 +108,16 @@ enum lis3lv02d_ctrl1 {
104 CTRL1_PD0 = 0x40, 108 CTRL1_PD0 = 0x40,
105 CTRL1_PD1 = 0x80, 109 CTRL1_PD1 = 0x80,
106}; 110};
111
112/* Delta to ctrl1_12b version */
113enum lis3lv02d_ctrl1_8b {
114 CTRL1_STM = 0x08,
115 CTRL1_STP = 0x10,
116 CTRL1_FS = 0x20,
117 CTRL1_PD = 0x40,
118 CTRL1_DR = 0x80,
119};
120
107enum lis3lv02d_ctrl2 { 121enum lis3lv02d_ctrl2 {
108 CTRL2_DAS = 0x01, 122 CTRL2_DAS = 0x01,
109 CTRL2_SIM = 0x02, 123 CTRL2_SIM = 0x02,
@@ -194,16 +208,20 @@ struct lis3lv02d {
194 int (*write) (struct lis3lv02d *lis3, int reg, u8 val); 208 int (*write) (struct lis3lv02d *lis3, int reg, u8 val);
195 int (*read) (struct lis3lv02d *lis3, int reg, u8 *ret); 209 int (*read) (struct lis3lv02d *lis3, int reg, u8 *ret);
196 210
197 u8 whoami; /* 3Ah: 2-byte registries, 3Bh: 1-byte registries */ 211 int *odrs; /* Supported output data rates */
212 u8 odr_mask; /* ODR bit mask */
213 u8 whoami; /* indicates measurement precision */
198 s16 (*read_data) (struct lis3lv02d *lis3, int reg); 214 s16 (*read_data) (struct lis3lv02d *lis3, int reg);
199 int mdps_max_val; 215 int mdps_max_val;
216 int pwron_delay;
217 int scale; /*
218 * relationship between 1 LBS and mG
219 * (1/1000th of earth gravity)
220 */
200 221
201 struct input_polled_dev *idev; /* input device */ 222 struct input_polled_dev *idev; /* input device */
202 struct platform_device *pdev; /* platform device */ 223 struct platform_device *pdev; /* platform device */
203 atomic_t count; /* interrupt count after last read */ 224 atomic_t count; /* interrupt count after last read */
204 int xcalib; /* calibrated null value for x */
205 int ycalib; /* calibrated null value for y */
206 int zcalib; /* calibrated null value for z */
207 struct axis_conversion ac; /* hw -> logical axis */ 225 struct axis_conversion ac; /* hw -> logical axis */
208 226
209 u32 irq; /* IRQ number */ 227 u32 irq; /* IRQ number */
@@ -212,6 +230,7 @@ struct lis3lv02d {
212 unsigned long misc_opened; /* bit0: whether the device is open */ 230 unsigned long misc_opened; /* bit0: whether the device is open */
213 231
214 struct lis3lv02d_platform_data *pdata; /* for passing board config */ 232 struct lis3lv02d_platform_data *pdata; /* for passing board config */
233 struct mutex mutex; /* Serialize poll and selftest */
215}; 234};
216 235
217int lis3lv02d_init_device(struct lis3lv02d *lis3); 236int lis3lv02d_init_device(struct lis3lv02d *lis3);
diff --git a/drivers/hwmon/lis3lv02d_i2c.c b/drivers/hwmon/lis3lv02d_i2c.c
new file mode 100644
index 000000000000..dc1f5402c1d7
--- /dev/null
+++ b/drivers/hwmon/lis3lv02d_i2c.c
@@ -0,0 +1,183 @@
1/*
2 * drivers/hwmon/lis3lv02d_i2c.c
3 *
4 * Implements I2C interface for lis3lv02d (STMicroelectronics) accelerometer.
5 * Driver is based on corresponding SPI driver written by Daniel Mack
6 * (lis3lv02d_spi.c (C) 2009 Daniel Mack <daniel@caiaq.de> ).
7 *
8 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
9 *
10 * Contact: Samu Onkalo <samu.p.onkalo@nokia.com>
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * version 2 as published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 * 02110-1301 USA
25 */
26
27#include <linux/module.h>
28#include <linux/kernel.h>
29#include <linux/init.h>
30#include <linux/err.h>
31#include <linux/i2c.h>
32#include "lis3lv02d.h"
33
34#define DRV_NAME "lis3lv02d_i2c"
35
36static inline s32 lis3_i2c_write(struct lis3lv02d *lis3, int reg, u8 value)
37{
38 struct i2c_client *c = lis3->bus_priv;
39 return i2c_smbus_write_byte_data(c, reg, value);
40}
41
42static inline s32 lis3_i2c_read(struct lis3lv02d *lis3, int reg, u8 *v)
43{
44 struct i2c_client *c = lis3->bus_priv;
45 *v = i2c_smbus_read_byte_data(c, reg);
46 return 0;
47}
48
49static int lis3_i2c_init(struct lis3lv02d *lis3)
50{
51 u8 reg;
52 int ret;
53
54 /* power up the device */
55 ret = lis3->read(lis3, CTRL_REG1, &reg);
56 if (ret < 0)
57 return ret;
58
59 reg |= CTRL1_PD0;
60 return lis3->write(lis3, CTRL_REG1, reg);
61}
62
63/* Default axis mapping but it can be overwritten by platform data */
64static struct axis_conversion lis3lv02d_axis_map = { LIS3_DEV_X,
65 LIS3_DEV_Y,
66 LIS3_DEV_Z };
67
68static int __devinit lis3lv02d_i2c_probe(struct i2c_client *client,
69 const struct i2c_device_id *id)
70{
71 int ret = 0;
72 struct lis3lv02d_platform_data *pdata = client->dev.platform_data;
73
74 if (pdata) {
75 if (pdata->axis_x)
76 lis3lv02d_axis_map.x = pdata->axis_x;
77
78 if (pdata->axis_y)
79 lis3lv02d_axis_map.y = pdata->axis_y;
80
81 if (pdata->axis_z)
82 lis3lv02d_axis_map.z = pdata->axis_z;
83
84 if (pdata->setup_resources)
85 ret = pdata->setup_resources();
86
87 if (ret)
88 goto fail;
89 }
90
91 lis3_dev.pdata = pdata;
92 lis3_dev.bus_priv = client;
93 lis3_dev.init = lis3_i2c_init;
94 lis3_dev.read = lis3_i2c_read;
95 lis3_dev.write = lis3_i2c_write;
96 lis3_dev.irq = client->irq;
97 lis3_dev.ac = lis3lv02d_axis_map;
98
99 i2c_set_clientdata(client, &lis3_dev);
100 ret = lis3lv02d_init_device(&lis3_dev);
101fail:
102 return ret;
103}
104
105static int __devexit lis3lv02d_i2c_remove(struct i2c_client *client)
106{
107 struct lis3lv02d *lis3 = i2c_get_clientdata(client);
108 struct lis3lv02d_platform_data *pdata = client->dev.platform_data;
109
110 if (pdata && pdata->release_resources)
111 pdata->release_resources();
112
113 lis3lv02d_joystick_disable();
114 lis3lv02d_poweroff(lis3);
115
116 return lis3lv02d_remove_fs(&lis3_dev);
117}
118
119#ifdef CONFIG_PM
120static int lis3lv02d_i2c_suspend(struct i2c_client *client, pm_message_t mesg)
121{
122 struct lis3lv02d *lis3 = i2c_get_clientdata(client);
123
124 if (!lis3->pdata->wakeup_flags)
125 lis3lv02d_poweroff(lis3);
126 return 0;
127}
128
129static int lis3lv02d_i2c_resume(struct i2c_client *client)
130{
131 struct lis3lv02d *lis3 = i2c_get_clientdata(client);
132
133 if (!lis3->pdata->wakeup_flags)
134 lis3lv02d_poweron(lis3);
135 return 0;
136}
137
138static void lis3lv02d_i2c_shutdown(struct i2c_client *client)
139{
140 lis3lv02d_i2c_suspend(client, PMSG_SUSPEND);
141}
142#else
143#define lis3lv02d_i2c_suspend NULL
144#define lis3lv02d_i2c_resume NULL
145#define lis3lv02d_i2c_shutdown NULL
146#endif
147
148static const struct i2c_device_id lis3lv02d_id[] = {
149 {"lis3lv02d", 0 },
150 {}
151};
152
153MODULE_DEVICE_TABLE(i2c, lis3lv02d_id);
154
155static struct i2c_driver lis3lv02d_i2c_driver = {
156 .driver = {
157 .name = DRV_NAME,
158 .owner = THIS_MODULE,
159 },
160 .suspend = lis3lv02d_i2c_suspend,
161 .shutdown = lis3lv02d_i2c_shutdown,
162 .resume = lis3lv02d_i2c_resume,
163 .probe = lis3lv02d_i2c_probe,
164 .remove = __devexit_p(lis3lv02d_i2c_remove),
165 .id_table = lis3lv02d_id,
166};
167
168static int __init lis3lv02d_init(void)
169{
170 return i2c_add_driver(&lis3lv02d_i2c_driver);
171}
172
173static void __exit lis3lv02d_exit(void)
174{
175 i2c_del_driver(&lis3lv02d_i2c_driver);
176}
177
178MODULE_AUTHOR("Nokia Corporation");
179MODULE_DESCRIPTION("lis3lv02d I2C interface");
180MODULE_LICENSE("GPL");
181
182module_init(lis3lv02d_init);
183module_exit(lis3lv02d_exit);
diff --git a/drivers/hwmon/lm63.c b/drivers/hwmon/lm63.c
index 3195a265f0e9..bf81aff7051d 100644
--- a/drivers/hwmon/lm63.c
+++ b/drivers/hwmon/lm63.c
@@ -56,12 +56,6 @@
56static const unsigned short normal_i2c[] = { 0x4c, I2C_CLIENT_END }; 56static const unsigned short normal_i2c[] = { 0x4c, I2C_CLIENT_END };
57 57
58/* 58/*
59 * Insmod parameters
60 */
61
62I2C_CLIENT_INSMOD_1(lm63);
63
64/*
65 * The LM63 registers 59 * The LM63 registers
66 */ 60 */
67 61
@@ -134,8 +128,7 @@ static int lm63_remove(struct i2c_client *client);
134 128
135static struct lm63_data *lm63_update_device(struct device *dev); 129static struct lm63_data *lm63_update_device(struct device *dev);
136 130
137static int lm63_detect(struct i2c_client *client, int kind, 131static int lm63_detect(struct i2c_client *client, struct i2c_board_info *info);
138 struct i2c_board_info *info);
139static void lm63_init_client(struct i2c_client *client); 132static void lm63_init_client(struct i2c_client *client);
140 133
141/* 134/*
@@ -143,7 +136,7 @@ static void lm63_init_client(struct i2c_client *client);
143 */ 136 */
144 137
145static const struct i2c_device_id lm63_id[] = { 138static const struct i2c_device_id lm63_id[] = {
146 { "lm63", lm63 }, 139 { "lm63", 0 },
147 { } 140 { }
148}; 141};
149MODULE_DEVICE_TABLE(i2c, lm63_id); 142MODULE_DEVICE_TABLE(i2c, lm63_id);
@@ -157,7 +150,7 @@ static struct i2c_driver lm63_driver = {
157 .remove = lm63_remove, 150 .remove = lm63_remove,
158 .id_table = lm63_id, 151 .id_table = lm63_id,
159 .detect = lm63_detect, 152 .detect = lm63_detect,
160 .address_data = &addr_data, 153 .address_list = normal_i2c,
161}; 154};
162 155
163/* 156/*
@@ -423,44 +416,38 @@ static const struct attribute_group lm63_group_fan1 = {
423 */ 416 */
424 417
425/* Return 0 if detection is successful, -ENODEV otherwise */ 418/* Return 0 if detection is successful, -ENODEV otherwise */
426static int lm63_detect(struct i2c_client *new_client, int kind, 419static int lm63_detect(struct i2c_client *new_client,
427 struct i2c_board_info *info) 420 struct i2c_board_info *info)
428{ 421{
429 struct i2c_adapter *adapter = new_client->adapter; 422 struct i2c_adapter *adapter = new_client->adapter;
423 u8 man_id, chip_id, reg_config1, reg_config2;
424 u8 reg_alert_status, reg_alert_mask;
430 425
431 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 426 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
432 return -ENODEV; 427 return -ENODEV;
433 428
434 if (kind < 0) { /* must identify */ 429 man_id = i2c_smbus_read_byte_data(new_client, LM63_REG_MAN_ID);
435 u8 man_id, chip_id, reg_config1, reg_config2; 430 chip_id = i2c_smbus_read_byte_data(new_client, LM63_REG_CHIP_ID);
436 u8 reg_alert_status, reg_alert_mask; 431
437 432 reg_config1 = i2c_smbus_read_byte_data(new_client,
438 man_id = i2c_smbus_read_byte_data(new_client, 433 LM63_REG_CONFIG1);
439 LM63_REG_MAN_ID); 434 reg_config2 = i2c_smbus_read_byte_data(new_client,
440 chip_id = i2c_smbus_read_byte_data(new_client, 435 LM63_REG_CONFIG2);
441 LM63_REG_CHIP_ID); 436 reg_alert_status = i2c_smbus_read_byte_data(new_client,
442 reg_config1 = i2c_smbus_read_byte_data(new_client, 437 LM63_REG_ALERT_STATUS);
443 LM63_REG_CONFIG1); 438 reg_alert_mask = i2c_smbus_read_byte_data(new_client,
444 reg_config2 = i2c_smbus_read_byte_data(new_client, 439 LM63_REG_ALERT_MASK);
445 LM63_REG_CONFIG2); 440
446 reg_alert_status = i2c_smbus_read_byte_data(new_client, 441 if (man_id != 0x01 /* National Semiconductor */
447 LM63_REG_ALERT_STATUS); 442 || chip_id != 0x41 /* LM63 */
448 reg_alert_mask = i2c_smbus_read_byte_data(new_client, 443 || (reg_config1 & 0x18) != 0x00
449 LM63_REG_ALERT_MASK); 444 || (reg_config2 & 0xF8) != 0x00
450 445 || (reg_alert_status & 0x20) != 0x00
451 if (man_id == 0x01 /* National Semiconductor */ 446 || (reg_alert_mask & 0xA4) != 0xA4) {
452 && chip_id == 0x41 /* LM63 */ 447 dev_dbg(&adapter->dev,
453 && (reg_config1 & 0x18) == 0x00 448 "Unsupported chip (man_id=0x%02X, chip_id=0x%02X)\n",
454 && (reg_config2 & 0xF8) == 0x00 449 man_id, chip_id);
455 && (reg_alert_status & 0x20) == 0x00 450 return -ENODEV;
456 && (reg_alert_mask & 0xA4) == 0xA4) {
457 kind = lm63;
458 } else { /* failed */
459 dev_dbg(&adapter->dev, "Unsupported chip "
460 "(man_id=0x%02X, chip_id=0x%02X).\n",
461 man_id, chip_id);
462 return -ENODEV;
463 }
464 } 451 }
465 452
466 strlcpy(info->type, "lm63", I2C_NAME_SIZE); 453 strlcpy(info->type, "lm63", I2C_NAME_SIZE);
diff --git a/drivers/hwmon/lm70.c b/drivers/hwmon/lm70.c
index ab8a5d3c7690..fd108cfc05c7 100644
--- a/drivers/hwmon/lm70.c
+++ b/drivers/hwmon/lm70.c
@@ -34,6 +34,7 @@
34#include <linux/mutex.h> 34#include <linux/mutex.h>
35#include <linux/mod_devicetable.h> 35#include <linux/mod_devicetable.h>
36#include <linux/spi/spi.h> 36#include <linux/spi/spi.h>
37#include <linux/slab.h>
37 38
38 39
39#define DRVNAME "lm70" 40#define DRVNAME "lm70"
diff --git a/drivers/hwmon/lm73.c b/drivers/hwmon/lm73.c
new file mode 100644
index 000000000000..4d1b76bc8148
--- /dev/null
+++ b/drivers/hwmon/lm73.c
@@ -0,0 +1,201 @@
1/*
2 * LM73 Sensor driver
3 * Based on LM75
4 *
5 * Copyright (C) 2007, CenoSYS (www.cenosys.com).
6 * Copyright (C) 2009, Bollore telecom (www.bolloretelecom.eu).
7 *
8 * Guillaume Ligneul <guillaume.ligneul@gmail.com>
9 * Adrien Demarez <adrien.demarez@bolloretelecom.eu>
10 * Jeremy Laine <jeremy.laine@bolloretelecom.eu>
11 *
12 * This software program is licensed subject to the GNU General Public License
13 * (GPL).Version 2,June 1991, available at
14 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
15 */
16
17#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/i2c.h>
20#include <linux/hwmon.h>
21#include <linux/hwmon-sysfs.h>
22#include <linux/err.h>
23
24
25/* Addresses scanned */
26static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4c,
27 0x4d, 0x4e, I2C_CLIENT_END };
28
29/* LM73 registers */
30#define LM73_REG_INPUT 0x00
31#define LM73_REG_CONF 0x01
32#define LM73_REG_MAX 0x02
33#define LM73_REG_MIN 0x03
34#define LM73_REG_CTRL 0x04
35#define LM73_REG_ID 0x07
36
37#define LM73_ID 0x9001 /* or 0x190 after a swab16() */
38#define DRVNAME "lm73"
39#define LM73_TEMP_MIN (-40)
40#define LM73_TEMP_MAX 150
41
42/*-----------------------------------------------------------------------*/
43
44
45static ssize_t set_temp(struct device *dev, struct device_attribute *da,
46 const char *buf, size_t count)
47{
48 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
49 struct i2c_client *client = to_i2c_client(dev);
50 long temp;
51 short value;
52
53 int status = strict_strtol(buf, 10, &temp);
54 if (status < 0)
55 return status;
56
57 /* Write value */
58 value = (short) SENSORS_LIMIT(temp/250, (LM73_TEMP_MIN*4),
59 (LM73_TEMP_MAX*4)) << 5;
60 i2c_smbus_write_word_data(client, attr->index, swab16(value));
61 return count;
62}
63
64static ssize_t show_temp(struct device *dev, struct device_attribute *da,
65 char *buf)
66{
67 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
68 struct i2c_client *client = to_i2c_client(dev);
69 /* use integer division instead of equivalent right shift to
70 guarantee arithmetic shift and preserve the sign */
71 int temp = ((s16) (swab16(i2c_smbus_read_word_data(client,
72 attr->index)))*250) / 32;
73 return sprintf(buf, "%d\n", temp);
74}
75
76
77/*-----------------------------------------------------------------------*/
78
79/* sysfs attributes for hwmon */
80
81static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO,
82 show_temp, set_temp, LM73_REG_MAX);
83static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO,
84 show_temp, set_temp, LM73_REG_MIN);
85static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO,
86 show_temp, NULL, LM73_REG_INPUT);
87
88
89static struct attribute *lm73_attributes[] = {
90 &sensor_dev_attr_temp1_input.dev_attr.attr,
91 &sensor_dev_attr_temp1_max.dev_attr.attr,
92 &sensor_dev_attr_temp1_min.dev_attr.attr,
93
94 NULL
95};
96
97static const struct attribute_group lm73_group = {
98 .attrs = lm73_attributes,
99};
100
101/*-----------------------------------------------------------------------*/
102
103/* device probe and removal */
104
105static int
106lm73_probe(struct i2c_client *client, const struct i2c_device_id *id)
107{
108 struct device *hwmon_dev;
109 int status;
110
111 /* Register sysfs hooks */
112 status = sysfs_create_group(&client->dev.kobj, &lm73_group);
113 if (status)
114 return status;
115
116 hwmon_dev = hwmon_device_register(&client->dev);
117 if (IS_ERR(hwmon_dev)) {
118 status = PTR_ERR(hwmon_dev);
119 goto exit_remove;
120 }
121 i2c_set_clientdata(client, hwmon_dev);
122
123 dev_info(&client->dev, "%s: sensor '%s'\n",
124 dev_name(hwmon_dev), client->name);
125
126 return 0;
127
128exit_remove:
129 sysfs_remove_group(&client->dev.kobj, &lm73_group);
130 return status;
131}
132
133static int lm73_remove(struct i2c_client *client)
134{
135 struct device *hwmon_dev = i2c_get_clientdata(client);
136
137 hwmon_device_unregister(hwmon_dev);
138 sysfs_remove_group(&client->dev.kobj, &lm73_group);
139 i2c_set_clientdata(client, NULL);
140 return 0;
141}
142
143static const struct i2c_device_id lm73_ids[] = {
144 { "lm73", 0 },
145 { /* LIST END */ }
146};
147MODULE_DEVICE_TABLE(i2c, lm73_ids);
148
149/* Return 0 if detection is successful, -ENODEV otherwise */
150static int lm73_detect(struct i2c_client *new_client,
151 struct i2c_board_info *info)
152{
153 struct i2c_adapter *adapter = new_client->adapter;
154 u16 id;
155 u8 ctrl;
156
157 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
158 I2C_FUNC_SMBUS_WORD_DATA))
159 return -ENODEV;
160
161 /* Check device ID */
162 id = i2c_smbus_read_word_data(new_client, LM73_REG_ID);
163 ctrl = i2c_smbus_read_byte_data(new_client, LM73_REG_CTRL);
164 if ((id != LM73_ID) || (ctrl & 0x10))
165 return -ENODEV;
166
167 strlcpy(info->type, "lm73", I2C_NAME_SIZE);
168
169 return 0;
170}
171
172static struct i2c_driver lm73_driver = {
173 .class = I2C_CLASS_HWMON,
174 .driver = {
175 .name = "lm73",
176 },
177 .probe = lm73_probe,
178 .remove = lm73_remove,
179 .id_table = lm73_ids,
180 .detect = lm73_detect,
181 .address_list = normal_i2c,
182};
183
184/* module glue */
185
186static int __init sensors_lm73_init(void)
187{
188 return i2c_add_driver(&lm73_driver);
189}
190
191static void __exit sensors_lm73_exit(void)
192{
193 i2c_del_driver(&lm73_driver);
194}
195
196MODULE_AUTHOR("Guillaume Ligneul <guillaume.ligneul@gmail.com>");
197MODULE_DESCRIPTION("LM73 driver");
198MODULE_LICENSE("GPL");
199
200module_init(sensors_lm73_init);
201module_exit(sensors_lm73_exit);
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index 55bd87c15c9a..8ae2cfe2d827 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -32,15 +32,12 @@
32 32
33/* 33/*
34 * This driver handles the LM75 and compatible digital temperature sensors. 34 * This driver handles the LM75 and compatible digital temperature sensors.
35 * Only types which are _not_ listed in I2C_CLIENT_INSMOD_*() need to be
36 * listed here. We start at 9 since I2C_CLIENT_INSMOD_*() currently allow
37 * definition of up to 8 chip types (plus zero).
38 */ 35 */
39 36
40enum lm75_type { /* keep sorted in alphabetical order */ 37enum lm75_type { /* keep sorted in alphabetical order */
41 ds1775 = 9, 38 ds1775,
42 ds75, 39 ds75,
43 /* lm75 -- in I2C_CLIENT_INSMOD_1() */ 40 lm75,
44 lm75a, 41 lm75a,
45 max6625, 42 max6625,
46 max6626, 43 max6626,
@@ -58,9 +55,6 @@ enum lm75_type { /* keep sorted in alphabetical order */
58static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c, 55static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
59 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; 56 0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
60 57
61/* Insmod parameters */
62I2C_CLIENT_INSMOD_1(lm75);
63
64 58
65/* The LM75 registers */ 59/* The LM75 registers */
66#define LM75_REG_CONF 0x01 60#define LM75_REG_CONF 0x01
@@ -234,11 +228,12 @@ static const struct i2c_device_id lm75_ids[] = {
234MODULE_DEVICE_TABLE(i2c, lm75_ids); 228MODULE_DEVICE_TABLE(i2c, lm75_ids);
235 229
236/* Return 0 if detection is successful, -ENODEV otherwise */ 230/* Return 0 if detection is successful, -ENODEV otherwise */
237static int lm75_detect(struct i2c_client *new_client, int kind, 231static int lm75_detect(struct i2c_client *new_client,
238 struct i2c_board_info *info) 232 struct i2c_board_info *info)
239{ 233{
240 struct i2c_adapter *adapter = new_client->adapter; 234 struct i2c_adapter *adapter = new_client->adapter;
241 int i; 235 int i;
236 int cur, conf, hyst, os;
242 237
243 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | 238 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
244 I2C_FUNC_SMBUS_WORD_DATA)) 239 I2C_FUNC_SMBUS_WORD_DATA))
@@ -251,40 +246,35 @@ static int lm75_detect(struct i2c_client *new_client, int kind,
251 The cycling+unused addresses combination is not tested, 246 The cycling+unused addresses combination is not tested,
252 since it would significantly slow the detection down and would 247 since it would significantly slow the detection down and would
253 hardly add any value. */ 248 hardly add any value. */
254 if (kind < 0) {
255 int cur, conf, hyst, os;
256
257 /* Unused addresses */
258 cur = i2c_smbus_read_word_data(new_client, 0);
259 conf = i2c_smbus_read_byte_data(new_client, 1);
260 hyst = i2c_smbus_read_word_data(new_client, 2);
261 if (i2c_smbus_read_word_data(new_client, 4) != hyst
262 || i2c_smbus_read_word_data(new_client, 5) != hyst
263 || i2c_smbus_read_word_data(new_client, 6) != hyst
264 || i2c_smbus_read_word_data(new_client, 7) != hyst)
265 return -ENODEV;
266 os = i2c_smbus_read_word_data(new_client, 3);
267 if (i2c_smbus_read_word_data(new_client, 4) != os
268 || i2c_smbus_read_word_data(new_client, 5) != os
269 || i2c_smbus_read_word_data(new_client, 6) != os
270 || i2c_smbus_read_word_data(new_client, 7) != os)
271 return -ENODEV;
272 249
273 /* Unused bits */ 250 /* Unused addresses */
274 if (conf & 0xe0) 251 cur = i2c_smbus_read_word_data(new_client, 0);
275 return -ENODEV; 252 conf = i2c_smbus_read_byte_data(new_client, 1);
253 hyst = i2c_smbus_read_word_data(new_client, 2);
254 if (i2c_smbus_read_word_data(new_client, 4) != hyst
255 || i2c_smbus_read_word_data(new_client, 5) != hyst
256 || i2c_smbus_read_word_data(new_client, 6) != hyst
257 || i2c_smbus_read_word_data(new_client, 7) != hyst)
258 return -ENODEV;
259 os = i2c_smbus_read_word_data(new_client, 3);
260 if (i2c_smbus_read_word_data(new_client, 4) != os
261 || i2c_smbus_read_word_data(new_client, 5) != os
262 || i2c_smbus_read_word_data(new_client, 6) != os
263 || i2c_smbus_read_word_data(new_client, 7) != os)
264 return -ENODEV;
265
266 /* Unused bits */
267 if (conf & 0xe0)
268 return -ENODEV;
276 269
277 /* Addresses cycling */ 270 /* Addresses cycling */
278 for (i = 8; i < 0xff; i += 8) 271 for (i = 8; i < 0xff; i += 8) {
279 if (i2c_smbus_read_byte_data(new_client, i + 1) != conf 272 if (i2c_smbus_read_byte_data(new_client, i + 1) != conf
280 || i2c_smbus_read_word_data(new_client, i + 2) != hyst 273 || i2c_smbus_read_word_data(new_client, i + 2) != hyst
281 || i2c_smbus_read_word_data(new_client, i + 3) != os) 274 || i2c_smbus_read_word_data(new_client, i + 3) != os)
282 return -ENODEV; 275 return -ENODEV;
283 } 276 }
284 277
285 /* NOTE: we treat "force=..." and "force_lm75=..." the same.
286 * Only new-style driver binding distinguishes chip types.
287 */
288 strlcpy(info->type, "lm75", I2C_NAME_SIZE); 278 strlcpy(info->type, "lm75", I2C_NAME_SIZE);
289 279
290 return 0; 280 return 0;
@@ -299,7 +289,7 @@ static struct i2c_driver lm75_driver = {
299 .remove = lm75_remove, 289 .remove = lm75_remove,
300 .id_table = lm75_ids, 290 .id_table = lm75_ids,
301 .detect = lm75_detect, 291 .detect = lm75_detect,
302 .address_data = &addr_data, 292 .address_list = normal_i2c,
303}; 293};
304 294
305/*-----------------------------------------------------------------------*/ 295/*-----------------------------------------------------------------------*/
diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c
index 866b401ab6e8..b28a297be50c 100644
--- a/drivers/hwmon/lm77.c
+++ b/drivers/hwmon/lm77.c
@@ -39,9 +39,6 @@
39static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 39static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b,
40 I2C_CLIENT_END }; 40 I2C_CLIENT_END };
41 41
42/* Insmod parameters */
43I2C_CLIENT_INSMOD_1(lm77);
44
45/* The LM77 registers */ 42/* The LM77 registers */
46#define LM77_REG_TEMP 0x00 43#define LM77_REG_TEMP 0x00
47#define LM77_REG_CONF 0x01 44#define LM77_REG_CONF 0x01
@@ -66,8 +63,7 @@ struct lm77_data {
66 63
67static int lm77_probe(struct i2c_client *client, 64static int lm77_probe(struct i2c_client *client,
68 const struct i2c_device_id *id); 65 const struct i2c_device_id *id);
69static int lm77_detect(struct i2c_client *client, int kind, 66static int lm77_detect(struct i2c_client *client, struct i2c_board_info *info);
70 struct i2c_board_info *info);
71static void lm77_init_client(struct i2c_client *client); 67static void lm77_init_client(struct i2c_client *client);
72static int lm77_remove(struct i2c_client *client); 68static int lm77_remove(struct i2c_client *client);
73static u16 lm77_read_value(struct i2c_client *client, u8 reg); 69static u16 lm77_read_value(struct i2c_client *client, u8 reg);
@@ -77,7 +73,7 @@ static struct lm77_data *lm77_update_device(struct device *dev);
77 73
78 74
79static const struct i2c_device_id lm77_id[] = { 75static const struct i2c_device_id lm77_id[] = {
80 { "lm77", lm77 }, 76 { "lm77", 0 },
81 { } 77 { }
82}; 78};
83MODULE_DEVICE_TABLE(i2c, lm77_id); 79MODULE_DEVICE_TABLE(i2c, lm77_id);
@@ -92,7 +88,7 @@ static struct i2c_driver lm77_driver = {
92 .remove = lm77_remove, 88 .remove = lm77_remove,
93 .id_table = lm77_id, 89 .id_table = lm77_id,
94 .detect = lm77_detect, 90 .detect = lm77_detect,
95 .address_data = &addr_data, 91 .address_list = normal_i2c,
96}; 92};
97 93
98/* straight from the datasheet */ 94/* straight from the datasheet */
@@ -245,10 +241,11 @@ static const struct attribute_group lm77_group = {
245}; 241};
246 242
247/* Return 0 if detection is successful, -ENODEV otherwise */ 243/* Return 0 if detection is successful, -ENODEV otherwise */
248static int lm77_detect(struct i2c_client *new_client, int kind, 244static int lm77_detect(struct i2c_client *new_client,
249 struct i2c_board_info *info) 245 struct i2c_board_info *info)
250{ 246{
251 struct i2c_adapter *adapter = new_client->adapter; 247 struct i2c_adapter *adapter = new_client->adapter;
248 int i, cur, conf, hyst, crit, min, max;
252 249
253 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | 250 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
254 I2C_FUNC_SMBUS_WORD_DATA)) 251 I2C_FUNC_SMBUS_WORD_DATA))
@@ -265,51 +262,48 @@ static int lm77_detect(struct i2c_client *new_client, int kind,
265 4. registers cycling over 8-address boundaries 262 4. registers cycling over 8-address boundaries
266 263
267 Word-sized registers are high-byte first. */ 264 Word-sized registers are high-byte first. */
268 if (kind < 0) {
269 int i, cur, conf, hyst, crit, min, max;
270
271 /* addresses cycling */
272 cur = i2c_smbus_read_word_data(new_client, 0);
273 conf = i2c_smbus_read_byte_data(new_client, 1);
274 hyst = i2c_smbus_read_word_data(new_client, 2);
275 crit = i2c_smbus_read_word_data(new_client, 3);
276 min = i2c_smbus_read_word_data(new_client, 4);
277 max = i2c_smbus_read_word_data(new_client, 5);
278 for (i = 8; i <= 0xff; i += 8)
279 if (i2c_smbus_read_byte_data(new_client, i + 1) != conf
280 || i2c_smbus_read_word_data(new_client, i + 2) != hyst
281 || i2c_smbus_read_word_data(new_client, i + 3) != crit
282 || i2c_smbus_read_word_data(new_client, i + 4) != min
283 || i2c_smbus_read_word_data(new_client, i + 5) != max)
284 return -ENODEV;
285
286 /* sign bits */
287 if (((cur & 0x00f0) != 0xf0 && (cur & 0x00f0) != 0x0)
288 || ((hyst & 0x00f0) != 0xf0 && (hyst & 0x00f0) != 0x0)
289 || ((crit & 0x00f0) != 0xf0 && (crit & 0x00f0) != 0x0)
290 || ((min & 0x00f0) != 0xf0 && (min & 0x00f0) != 0x0)
291 || ((max & 0x00f0) != 0xf0 && (max & 0x00f0) != 0x0))
292 return -ENODEV;
293 265
294 /* unused bits */ 266 /* addresses cycling */
295 if (conf & 0xe0) 267 cur = i2c_smbus_read_word_data(new_client, 0);
268 conf = i2c_smbus_read_byte_data(new_client, 1);
269 hyst = i2c_smbus_read_word_data(new_client, 2);
270 crit = i2c_smbus_read_word_data(new_client, 3);
271 min = i2c_smbus_read_word_data(new_client, 4);
272 max = i2c_smbus_read_word_data(new_client, 5);
273 for (i = 8; i <= 0xff; i += 8) {
274 if (i2c_smbus_read_byte_data(new_client, i + 1) != conf
275 || i2c_smbus_read_word_data(new_client, i + 2) != hyst
276 || i2c_smbus_read_word_data(new_client, i + 3) != crit
277 || i2c_smbus_read_word_data(new_client, i + 4) != min
278 || i2c_smbus_read_word_data(new_client, i + 5) != max)
296 return -ENODEV; 279 return -ENODEV;
280 }
297 281
298 /* 0x06 and 0x07 return the last read value */ 282 /* sign bits */
299 cur = i2c_smbus_read_word_data(new_client, 0); 283 if (((cur & 0x00f0) != 0xf0 && (cur & 0x00f0) != 0x0)
300 if (i2c_smbus_read_word_data(new_client, 6) != cur 284 || ((hyst & 0x00f0) != 0xf0 && (hyst & 0x00f0) != 0x0)
301 || i2c_smbus_read_word_data(new_client, 7) != cur) 285 || ((crit & 0x00f0) != 0xf0 && (crit & 0x00f0) != 0x0)
302 return -ENODEV; 286 || ((min & 0x00f0) != 0xf0 && (min & 0x00f0) != 0x0)
303 hyst = i2c_smbus_read_word_data(new_client, 2); 287 || ((max & 0x00f0) != 0xf0 && (max & 0x00f0) != 0x0))
304 if (i2c_smbus_read_word_data(new_client, 6) != hyst 288 return -ENODEV;
305 || i2c_smbus_read_word_data(new_client, 7) != hyst)
306 return -ENODEV;
307 min = i2c_smbus_read_word_data(new_client, 4);
308 if (i2c_smbus_read_word_data(new_client, 6) != min
309 || i2c_smbus_read_word_data(new_client, 7) != min)
310 return -ENODEV;
311 289
312 } 290 /* unused bits */
291 if (conf & 0xe0)
292 return -ENODEV;
293
294 /* 0x06 and 0x07 return the last read value */
295 cur = i2c_smbus_read_word_data(new_client, 0);
296 if (i2c_smbus_read_word_data(new_client, 6) != cur
297 || i2c_smbus_read_word_data(new_client, 7) != cur)
298 return -ENODEV;
299 hyst = i2c_smbus_read_word_data(new_client, 2);
300 if (i2c_smbus_read_word_data(new_client, 6) != hyst
301 || i2c_smbus_read_word_data(new_client, 7) != hyst)
302 return -ENODEV;
303 min = i2c_smbus_read_word_data(new_client, 4);
304 if (i2c_smbus_read_word_data(new_client, 6) != min
305 || i2c_smbus_read_word_data(new_client, 7) != min)
306 return -ENODEV;
313 307
314 strlcpy(info->type, "lm77", I2C_NAME_SIZE); 308 strlcpy(info->type, "lm77", I2C_NAME_SIZE);
315 309
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
index f7e70163e016..72ff2c4e757d 100644
--- a/drivers/hwmon/lm78.c
+++ b/drivers/hwmon/lm78.c
@@ -41,8 +41,7 @@ static const unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
41 0x2e, 0x2f, I2C_CLIENT_END }; 41 0x2e, 0x2f, I2C_CLIENT_END };
42static unsigned short isa_address = 0x290; 42static unsigned short isa_address = 0x290;
43 43
44/* Insmod parameters */ 44enum chips { lm78, lm79 };
45I2C_CLIENT_INSMOD_2(lm78, lm79);
46 45
47/* Many LM78 constants specified below */ 46/* Many LM78 constants specified below */
48 47
@@ -142,7 +141,7 @@ struct lm78_data {
142}; 141};
143 142
144 143
145static int lm78_i2c_detect(struct i2c_client *client, int kind, 144static int lm78_i2c_detect(struct i2c_client *client,
146 struct i2c_board_info *info); 145 struct i2c_board_info *info);
147static int lm78_i2c_probe(struct i2c_client *client, 146static int lm78_i2c_probe(struct i2c_client *client,
148 const struct i2c_device_id *id); 147 const struct i2c_device_id *id);
@@ -173,7 +172,7 @@ static struct i2c_driver lm78_driver = {
173 .remove = lm78_i2c_remove, 172 .remove = lm78_i2c_remove,
174 .id_table = lm78_i2c_id, 173 .id_table = lm78_i2c_id,
175 .detect = lm78_i2c_detect, 174 .detect = lm78_i2c_detect,
176 .address_data = &addr_data, 175 .address_list = normal_i2c,
177}; 176};
178 177
179static struct platform_driver lm78_isa_driver = { 178static struct platform_driver lm78_isa_driver = {
@@ -558,7 +557,7 @@ static int lm78_alias_detect(struct i2c_client *client, u8 chipid)
558 return 1; 557 return 1;
559} 558}
560 559
561static int lm78_i2c_detect(struct i2c_client *client, int kind, 560static int lm78_i2c_detect(struct i2c_client *client,
562 struct i2c_board_info *info) 561 struct i2c_board_info *info)
563{ 562{
564 int i; 563 int i;
@@ -576,52 +575,34 @@ static int lm78_i2c_detect(struct i2c_client *client, int kind,
576 if (isa) 575 if (isa)
577 mutex_lock(&isa->update_lock); 576 mutex_lock(&isa->update_lock);
578 577
579 if (kind < 0) { 578 if ((i2c_smbus_read_byte_data(client, LM78_REG_CONFIG) & 0x80)
580 if ((i2c_smbus_read_byte_data(client, LM78_REG_CONFIG) & 0x80) 579 || i2c_smbus_read_byte_data(client, LM78_REG_I2C_ADDR) != address)
581 || i2c_smbus_read_byte_data(client, LM78_REG_I2C_ADDR) 580 goto err_nodev;
582 != address)
583 goto err_nodev;
584 581
585 /* Explicitly prevent the misdetection of Winbond chips */ 582 /* Explicitly prevent the misdetection of Winbond chips */
586 i = i2c_smbus_read_byte_data(client, 0x4f); 583 i = i2c_smbus_read_byte_data(client, 0x4f);
587 if (i == 0xa3 || i == 0x5c) 584 if (i == 0xa3 || i == 0x5c)
588 goto err_nodev; 585 goto err_nodev;
589 }
590 586
591 /* Determine the chip type. */ 587 /* Determine the chip type. */
592 if (kind <= 0) { 588 i = i2c_smbus_read_byte_data(client, LM78_REG_CHIPID);
593 i = i2c_smbus_read_byte_data(client, LM78_REG_CHIPID); 589 if (i == 0x00 || i == 0x20 /* LM78 */
594 if (i == 0x00 || i == 0x20 /* LM78 */ 590 || i == 0x40) /* LM78-J */
595 || i == 0x40) /* LM78-J */ 591 client_name = "lm78";
596 kind = lm78; 592 else if ((i & 0xfe) == 0xc0)
597 else if ((i & 0xfe) == 0xc0) 593 client_name = "lm79";
598 kind = lm79; 594 else
599 else { 595 goto err_nodev;
600 if (kind == 0)
601 dev_warn(&adapter->dev, "Ignoring 'force' "
602 "parameter for unknown chip at "
603 "adapter %d, address 0x%02x\n",
604 i2c_adapter_id(adapter), address);
605 goto err_nodev;
606 }
607 596
608 if (lm78_alias_detect(client, i)) { 597 if (lm78_alias_detect(client, i)) {
609 dev_dbg(&adapter->dev, "Device at 0x%02x appears to " 598 dev_dbg(&adapter->dev, "Device at 0x%02x appears to "
610 "be the same as ISA device\n", address); 599 "be the same as ISA device\n", address);
611 goto err_nodev; 600 goto err_nodev;
612 }
613 } 601 }
614 602
615 if (isa) 603 if (isa)
616 mutex_unlock(&isa->update_lock); 604 mutex_unlock(&isa->update_lock);
617 605
618 switch (kind) {
619 case lm79:
620 client_name = "lm79";
621 break;
622 default:
623 client_name = "lm78";
624 }
625 strlcpy(info->type, client_name, I2C_NAME_SIZE); 606 strlcpy(info->type, client_name, I2C_NAME_SIZE);
626 607
627 return 0; 608 return 0;
@@ -870,17 +851,16 @@ static struct lm78_data *lm78_update_device(struct device *dev)
870static int __init lm78_isa_found(unsigned short address) 851static int __init lm78_isa_found(unsigned short address)
871{ 852{
872 int val, save, found = 0; 853 int val, save, found = 0;
873 854 int port;
874 /* We have to request the region in two parts because some 855
875 boards declare base+4 to base+7 as a PNP device */ 856 /* Some boards declare base+0 to base+7 as a PNP device, some base+4
876 if (!request_region(address, 4, "lm78")) { 857 * to base+7 and some base+5 to base+6. So we better request each port
877 pr_debug("lm78: Failed to request low part of region\n"); 858 * individually for the probing phase. */
878 return 0; 859 for (port = address; port < address + LM78_EXTENT; port++) {
879 } 860 if (!request_region(port, 1, "lm78")) {
880 if (!request_region(address + 4, 4, "lm78")) { 861 pr_debug("lm78: Failed to request port 0x%x\n", port);
881 pr_debug("lm78: Failed to request high part of region\n"); 862 goto release;
882 release_region(address, 4); 863 }
883 return 0;
884 } 864 }
885 865
886#define REALLY_SLOW_IO 866#define REALLY_SLOW_IO
@@ -944,8 +924,8 @@ static int __init lm78_isa_found(unsigned short address)
944 val & 0x80 ? "LM79" : "LM78", (int)address); 924 val & 0x80 ? "LM79" : "LM78", (int)address);
945 925
946 release: 926 release:
947 release_region(address + 4, 4); 927 for (port--; port >= address; port--)
948 release_region(address, 4); 928 release_region(port, 1);
949 return found; 929 return found;
950} 930}
951 931
diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c
index bcffc1899403..18a0e6c5fe88 100644
--- a/drivers/hwmon/lm80.c
+++ b/drivers/hwmon/lm80.c
@@ -35,9 +35,6 @@
35static const unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 35static const unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
36 0x2e, 0x2f, I2C_CLIENT_END }; 36 0x2e, 0x2f, I2C_CLIENT_END };
37 37
38/* Insmod parameters */
39I2C_CLIENT_INSMOD_1(lm80);
40
41/* Many LM80 constants specified below */ 38/* Many LM80 constants specified below */
42 39
43/* The LM80 registers */ 40/* The LM80 registers */
@@ -133,8 +130,7 @@ struct lm80_data {
133 130
134static int lm80_probe(struct i2c_client *client, 131static int lm80_probe(struct i2c_client *client,
135 const struct i2c_device_id *id); 132 const struct i2c_device_id *id);
136static int lm80_detect(struct i2c_client *client, int kind, 133static int lm80_detect(struct i2c_client *client, struct i2c_board_info *info);
137 struct i2c_board_info *info);
138static void lm80_init_client(struct i2c_client *client); 134static void lm80_init_client(struct i2c_client *client);
139static int lm80_remove(struct i2c_client *client); 135static int lm80_remove(struct i2c_client *client);
140static struct lm80_data *lm80_update_device(struct device *dev); 136static struct lm80_data *lm80_update_device(struct device *dev);
@@ -146,7 +142,7 @@ static int lm80_write_value(struct i2c_client *client, u8 reg, u8 value);
146 */ 142 */
147 143
148static const struct i2c_device_id lm80_id[] = { 144static const struct i2c_device_id lm80_id[] = {
149 { "lm80", lm80 }, 145 { "lm80", 0 },
150 { } 146 { }
151}; 147};
152MODULE_DEVICE_TABLE(i2c, lm80_id); 148MODULE_DEVICE_TABLE(i2c, lm80_id);
@@ -160,7 +156,7 @@ static struct i2c_driver lm80_driver = {
160 .remove = lm80_remove, 156 .remove = lm80_remove,
161 .id_table = lm80_id, 157 .id_table = lm80_id,
162 .detect = lm80_detect, 158 .detect = lm80_detect,
163 .address_data = &addr_data, 159 .address_list = normal_i2c,
164}; 160};
165 161
166/* 162/*
@@ -447,8 +443,7 @@ static const struct attribute_group lm80_group = {
447}; 443};
448 444
449/* Return 0 if detection is successful, -ENODEV otherwise */ 445/* Return 0 if detection is successful, -ENODEV otherwise */
450static int lm80_detect(struct i2c_client *client, int kind, 446static int lm80_detect(struct i2c_client *client, struct i2c_board_info *info)
451 struct i2c_board_info *info)
452{ 447{
453 struct i2c_adapter *adapter = client->adapter; 448 struct i2c_adapter *adapter = client->adapter;
454 int i, cur; 449 int i, cur;
diff --git a/drivers/hwmon/lm83.c b/drivers/hwmon/lm83.c
index e59e2d1f080c..8290476aee4a 100644
--- a/drivers/hwmon/lm83.c
+++ b/drivers/hwmon/lm83.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * lm83.c - Part of lm_sensors, Linux kernel modules for hardware 2 * lm83.c - Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring 3 * monitoring
4 * Copyright (C) 2003-2008 Jean Delvare <khali@linux-fr.org> 4 * Copyright (C) 2003-2009 Jean Delvare <khali@linux-fr.org>
5 * 5 *
6 * Heavily inspired from the lm78, lm75 and adm1021 drivers. The LM83 is 6 * Heavily inspired from the lm78, lm75 and adm1021 drivers. The LM83 is
7 * a sensor chip made by National Semiconductor. It reports up to four 7 * a sensor chip made by National Semiconductor. It reports up to four
@@ -51,11 +51,7 @@
51static const unsigned short normal_i2c[] = { 51static const unsigned short normal_i2c[] = {
52 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END }; 52 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END };
53 53
54/* 54enum chips { lm83, lm82 };
55 * Insmod parameters
56 */
57
58I2C_CLIENT_INSMOD_2(lm83, lm82);
59 55
60/* 56/*
61 * The LM83 registers 57 * The LM83 registers
@@ -118,7 +114,7 @@ static const u8 LM83_REG_W_HIGH[] = {
118 * Functions declaration 114 * Functions declaration
119 */ 115 */
120 116
121static int lm83_detect(struct i2c_client *new_client, int kind, 117static int lm83_detect(struct i2c_client *new_client,
122 struct i2c_board_info *info); 118 struct i2c_board_info *info);
123static int lm83_probe(struct i2c_client *client, 119static int lm83_probe(struct i2c_client *client,
124 const struct i2c_device_id *id); 120 const struct i2c_device_id *id);
@@ -145,7 +141,7 @@ static struct i2c_driver lm83_driver = {
145 .remove = lm83_remove, 141 .remove = lm83_remove,
146 .id_table = lm83_id, 142 .id_table = lm83_id,
147 .detect = lm83_detect, 143 .detect = lm83_detect,
148 .address_data = &addr_data, 144 .address_list = normal_i2c,
149}; 145};
150 146
151/* 147/*
@@ -291,73 +287,44 @@ static const struct attribute_group lm83_group_opt = {
291 */ 287 */
292 288
293/* Return 0 if detection is successful, -ENODEV otherwise */ 289/* Return 0 if detection is successful, -ENODEV otherwise */
294static int lm83_detect(struct i2c_client *new_client, int kind, 290static int lm83_detect(struct i2c_client *new_client,
295 struct i2c_board_info *info) 291 struct i2c_board_info *info)
296{ 292{
297 struct i2c_adapter *adapter = new_client->adapter; 293 struct i2c_adapter *adapter = new_client->adapter;
298 const char *name = ""; 294 const char *name;
295 u8 man_id, chip_id;
299 296
300 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 297 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
301 return -ENODEV; 298 return -ENODEV;
302 299
303 /* Now we do the detection and identification. A negative kind 300 /* Detection */
304 * means that the driver was loaded with no force parameter 301 if ((i2c_smbus_read_byte_data(new_client, LM83_REG_R_STATUS1) & 0xA8) ||
305 * (default), so we must both detect and identify the chip 302 (i2c_smbus_read_byte_data(new_client, LM83_REG_R_STATUS2) & 0x48) ||
306 * (actually there is only one possible kind of chip for now, LM83). 303 (i2c_smbus_read_byte_data(new_client, LM83_REG_R_CONFIG) & 0x41)) {
307 * A zero kind means that the driver was loaded with the force 304 dev_dbg(&adapter->dev, "LM83 detection failed at 0x%02x\n",
308 * parameter, the detection step shall be skipped. A positive kind 305 new_client->addr);
309 * means that the driver was loaded with the force parameter and a 306 return -ENODEV;
310 * given kind of chip is requested, so both the detection and the
311 * identification steps are skipped. */
312
313 /* Default to an LM83 if forced */
314 if (kind == 0)
315 kind = lm83;
316
317 if (kind < 0) { /* detection */
318 if (((i2c_smbus_read_byte_data(new_client, LM83_REG_R_STATUS1)
319 & 0xA8) != 0x00) ||
320 ((i2c_smbus_read_byte_data(new_client, LM83_REG_R_STATUS2)
321 & 0x48) != 0x00) ||
322 ((i2c_smbus_read_byte_data(new_client, LM83_REG_R_CONFIG)
323 & 0x41) != 0x00)) {
324 dev_dbg(&adapter->dev,
325 "LM83 detection failed at 0x%02x.\n",
326 new_client->addr);
327 return -ENODEV;
328 }
329 } 307 }
330 308
331 if (kind <= 0) { /* identification */ 309 /* Identification */
332 u8 man_id, chip_id; 310 man_id = i2c_smbus_read_byte_data(new_client, LM83_REG_R_MAN_ID);
333 311 if (man_id != 0x01) /* National Semiconductor */
334 man_id = i2c_smbus_read_byte_data(new_client, 312 return -ENODEV;
335 LM83_REG_R_MAN_ID);
336 chip_id = i2c_smbus_read_byte_data(new_client,
337 LM83_REG_R_CHIP_ID);
338
339 if (man_id == 0x01) { /* National Semiconductor */
340 if (chip_id == 0x03) {
341 kind = lm83;
342 } else
343 if (chip_id == 0x01) {
344 kind = lm82;
345 }
346 }
347
348 if (kind <= 0) { /* identification failed */
349 dev_info(&adapter->dev,
350 "Unsupported chip (man_id=0x%02X, "
351 "chip_id=0x%02X).\n", man_id, chip_id);
352 return -ENODEV;
353 }
354 }
355 313
356 if (kind == lm83) { 314 chip_id = i2c_smbus_read_byte_data(new_client, LM83_REG_R_CHIP_ID);
315 switch (chip_id) {
316 case 0x03:
357 name = "lm83"; 317 name = "lm83";
358 } else 318 break;
359 if (kind == lm82) { 319 case 0x01:
360 name = "lm82"; 320 name = "lm82";
321 break;
322 default:
323 /* identification failed */
324 dev_info(&adapter->dev,
325 "Unsupported chip (man_id=0x%02X, chip_id=0x%02X)\n",
326 man_id, chip_id);
327 return -ENODEV;
361 } 328 }
362 329
363 strlcpy(info->type, name, I2C_NAME_SIZE); 330 strlcpy(info->type, name, I2C_NAME_SIZE);
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
index 6c53d987de10..b3841a615595 100644
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -5,7 +5,7 @@
5 Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com> 5 Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
6 Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de> 6 Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de>
7 Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com> 7 Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
8 Copyright (C) 2007, 2008 Jean Delvare <khali@linux-fr.org> 8 Copyright (C) 2007--2009 Jean Delvare <khali@linux-fr.org>
9 9
10 Chip details at <http://www.national.com/ds/LM/LM85.pdf> 10 Chip details at <http://www.national.com/ds/LM/LM85.pdf>
11 11
@@ -38,9 +38,11 @@
38/* Addresses to scan */ 38/* Addresses to scan */
39static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; 39static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
40 40
41/* Insmod parameters */ 41enum chips {
42I2C_CLIENT_INSMOD_7(lm85b, lm85c, adm1027, adt7463, adt7468, emc6d100, 42 any_chip, lm85b, lm85c,
43 emc6d102); 43 adm1027, adt7463, adt7468,
44 emc6d100, emc6d102
45};
44 46
45/* The LM85 registers */ 47/* The LM85 registers */
46 48
@@ -323,8 +325,7 @@ struct lm85_data {
323 struct lm85_zone zone[3]; 325 struct lm85_zone zone[3];
324}; 326};
325 327
326static int lm85_detect(struct i2c_client *client, int kind, 328static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info);
327 struct i2c_board_info *info);
328static int lm85_probe(struct i2c_client *client, 329static int lm85_probe(struct i2c_client *client,
329 const struct i2c_device_id *id); 330 const struct i2c_device_id *id);
330static int lm85_remove(struct i2c_client *client); 331static int lm85_remove(struct i2c_client *client);
@@ -357,7 +358,7 @@ static struct i2c_driver lm85_driver = {
357 .remove = lm85_remove, 358 .remove = lm85_remove,
358 .id_table = lm85_id, 359 .id_table = lm85_id,
359 .detect = lm85_detect, 360 .detect = lm85_detect,
360 .address_data = &addr_data, 361 .address_list = normal_i2c,
361}; 362};
362 363
363 364
@@ -1156,113 +1157,85 @@ static int lm85_is_fake(struct i2c_client *client)
1156} 1157}
1157 1158
1158/* Return 0 if detection is successful, -ENODEV otherwise */ 1159/* Return 0 if detection is successful, -ENODEV otherwise */
1159static int lm85_detect(struct i2c_client *client, int kind, 1160static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info)
1160 struct i2c_board_info *info)
1161{ 1161{
1162 struct i2c_adapter *adapter = client->adapter; 1162 struct i2c_adapter *adapter = client->adapter;
1163 int address = client->addr; 1163 int address = client->addr;
1164 const char *type_name; 1164 const char *type_name;
1165 int company, verstep;
1165 1166
1166 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 1167 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
1167 /* We need to be able to do byte I/O */ 1168 /* We need to be able to do byte I/O */
1168 return -ENODEV; 1169 return -ENODEV;
1169 } 1170 }
1170 1171
1171 /* If auto-detecting, determine the chip type */ 1172 /* Determine the chip type */
1172 if (kind < 0) { 1173 company = lm85_read_value(client, LM85_REG_COMPANY);
1173 int company = lm85_read_value(client, LM85_REG_COMPANY); 1174 verstep = lm85_read_value(client, LM85_REG_VERSTEP);
1174 int verstep = lm85_read_value(client, LM85_REG_VERSTEP); 1175
1175 1176 dev_dbg(&adapter->dev, "Detecting device at 0x%02x with "
1176 dev_dbg(&adapter->dev, "Detecting device at 0x%02x with " 1177 "COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
1177 "COMPANY: 0x%02x and VERSTEP: 0x%02x\n", 1178 address, company, verstep);
1178 address, company, verstep); 1179
1179 1180 /* All supported chips have the version in common */
1180 /* All supported chips have the version in common */ 1181 if ((verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC &&
1181 if ((verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC && 1182 (verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC2) {
1182 (verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC2) { 1183 dev_dbg(&adapter->dev,
1183 dev_dbg(&adapter->dev, "Autodetection failed: " 1184 "Autodetection failed: unsupported version\n");
1184 "unsupported version\n"); 1185 return -ENODEV;
1185 return -ENODEV; 1186 }
1186 } 1187 type_name = "lm85";
1187 kind = any_chip; 1188
1188 1189 /* Now, refine the detection */
1189 /* Now, refine the detection */ 1190 if (company == LM85_COMPANY_NATIONAL) {
1190 if (company == LM85_COMPANY_NATIONAL) { 1191 switch (verstep) {
1191 switch (verstep) { 1192 case LM85_VERSTEP_LM85C:
1192 case LM85_VERSTEP_LM85C: 1193 type_name = "lm85c";
1193 kind = lm85c; 1194 break;
1194 break; 1195 case LM85_VERSTEP_LM85B:
1195 case LM85_VERSTEP_LM85B: 1196 type_name = "lm85b";
1196 kind = lm85b; 1197 break;
1197 break; 1198 case LM85_VERSTEP_LM96000_1:
1198 case LM85_VERSTEP_LM96000_1: 1199 case LM85_VERSTEP_LM96000_2:
1199 case LM85_VERSTEP_LM96000_2: 1200 /* Check for Winbond WPCD377I */
1200 /* Check for Winbond WPCD377I */ 1201 if (lm85_is_fake(client)) {
1201 if (lm85_is_fake(client)) { 1202 dev_dbg(&adapter->dev,
1202 dev_dbg(&adapter->dev, 1203 "Found Winbond WPCD377I, ignoring\n");
1203 "Found Winbond WPCD377I, " 1204 return -ENODEV;
1204 "ignoring\n");
1205 return -ENODEV;
1206 }
1207 break;
1208 }
1209 } else if (company == LM85_COMPANY_ANALOG_DEV) {
1210 switch (verstep) {
1211 case LM85_VERSTEP_ADM1027:
1212 kind = adm1027;
1213 break;
1214 case LM85_VERSTEP_ADT7463:
1215 case LM85_VERSTEP_ADT7463C:
1216 kind = adt7463;
1217 break;
1218 case LM85_VERSTEP_ADT7468_1:
1219 case LM85_VERSTEP_ADT7468_2:
1220 kind = adt7468;
1221 break;
1222 }
1223 } else if (company == LM85_COMPANY_SMSC) {
1224 switch (verstep) {
1225 case LM85_VERSTEP_EMC6D100_A0:
1226 case LM85_VERSTEP_EMC6D100_A1:
1227 /* Note: we can't tell a '100 from a '101 */
1228 kind = emc6d100;
1229 break;
1230 case LM85_VERSTEP_EMC6D102:
1231 kind = emc6d102;
1232 break;
1233 } 1205 }
1234 } else { 1206 break;
1235 dev_dbg(&adapter->dev, "Autodetection failed: " 1207 }
1236 "unknown vendor\n"); 1208 } else if (company == LM85_COMPANY_ANALOG_DEV) {
1237 return -ENODEV; 1209 switch (verstep) {
1210 case LM85_VERSTEP_ADM1027:
1211 type_name = "adm1027";
1212 break;
1213 case LM85_VERSTEP_ADT7463:
1214 case LM85_VERSTEP_ADT7463C:
1215 type_name = "adt7463";
1216 break;
1217 case LM85_VERSTEP_ADT7468_1:
1218 case LM85_VERSTEP_ADT7468_2:
1219 type_name = "adt7468";
1220 break;
1221 }
1222 } else if (company == LM85_COMPANY_SMSC) {
1223 switch (verstep) {
1224 case LM85_VERSTEP_EMC6D100_A0:
1225 case LM85_VERSTEP_EMC6D100_A1:
1226 /* Note: we can't tell a '100 from a '101 */
1227 type_name = "emc6d100";
1228 break;
1229 case LM85_VERSTEP_EMC6D102:
1230 type_name = "emc6d102";
1231 break;
1238 } 1232 }
1233 } else {
1234 dev_dbg(&adapter->dev,
1235 "Autodetection failed: unknown vendor\n");
1236 return -ENODEV;
1239 } 1237 }
1240 1238
1241 switch (kind) {
1242 case lm85b:
1243 type_name = "lm85b";
1244 break;
1245 case lm85c:
1246 type_name = "lm85c";
1247 break;
1248 case adm1027:
1249 type_name = "adm1027";
1250 break;
1251 case adt7463:
1252 type_name = "adt7463";
1253 break;
1254 case adt7468:
1255 type_name = "adt7468";
1256 break;
1257 case emc6d100:
1258 type_name = "emc6d100";
1259 break;
1260 case emc6d102:
1261 type_name = "emc6d102";
1262 break;
1263 default:
1264 type_name = "lm85";
1265 }
1266 strlcpy(info->type, type_name, I2C_NAME_SIZE); 1239 strlcpy(info->type, type_name, I2C_NAME_SIZE);
1267 1240
1268 return 0; 1241 return 0;
diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c
index 2e4a3cea95f7..f1e6e7512ffa 100644
--- a/drivers/hwmon/lm87.c
+++ b/drivers/hwmon/lm87.c
@@ -74,11 +74,7 @@
74 74
75static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; 75static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
76 76
77/* 77enum chips { lm87, adm1024 };
78 * Insmod parameters
79 */
80
81I2C_CLIENT_INSMOD_2(lm87, adm1024);
82 78
83/* 79/*
84 * The LM87 registers 80 * The LM87 registers
@@ -158,7 +154,7 @@ static u8 LM87_REG_TEMP_LOW[3] = { 0x3A, 0x38, 0x2C };
158 154
159static int lm87_probe(struct i2c_client *client, 155static int lm87_probe(struct i2c_client *client,
160 const struct i2c_device_id *id); 156 const struct i2c_device_id *id);
161static int lm87_detect(struct i2c_client *new_client, int kind, 157static int lm87_detect(struct i2c_client *new_client,
162 struct i2c_board_info *info); 158 struct i2c_board_info *info);
163static void lm87_init_client(struct i2c_client *client); 159static void lm87_init_client(struct i2c_client *client);
164static int lm87_remove(struct i2c_client *client); 160static int lm87_remove(struct i2c_client *client);
@@ -184,7 +180,7 @@ static struct i2c_driver lm87_driver = {
184 .remove = lm87_remove, 180 .remove = lm87_remove,
185 .id_table = lm87_id, 181 .id_table = lm87_id,
186 .detect = lm87_detect, 182 .detect = lm87_detect,
187 .address_data = &addr_data, 183 .address_list = normal_i2c,
188}; 184};
189 185
190/* 186/*
@@ -662,41 +658,36 @@ static const struct attribute_group lm87_group_opt = {
662}; 658};
663 659
664/* Return 0 if detection is successful, -ENODEV otherwise */ 660/* Return 0 if detection is successful, -ENODEV otherwise */
665static int lm87_detect(struct i2c_client *new_client, int kind, 661static int lm87_detect(struct i2c_client *new_client,
666 struct i2c_board_info *info) 662 struct i2c_board_info *info)
667{ 663{
668 struct i2c_adapter *adapter = new_client->adapter; 664 struct i2c_adapter *adapter = new_client->adapter;
669 static const char *names[] = { "lm87", "adm1024" }; 665 const char *name;
666 u8 cid, rev;
670 667
671 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 668 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
672 return -ENODEV; 669 return -ENODEV;
673 670
674 /* Default to an LM87 if forced */ 671 if (lm87_read_value(new_client, LM87_REG_CONFIG) & 0x80)
675 if (kind == 0) 672 return -ENODEV;
676 kind = lm87;
677 673
678 /* Now, we do the remaining detection. */ 674 /* Now, we do the remaining detection. */
679 if (kind < 0) { 675 cid = lm87_read_value(new_client, LM87_REG_COMPANY_ID);
680 u8 cid = lm87_read_value(new_client, LM87_REG_COMPANY_ID); 676 rev = lm87_read_value(new_client, LM87_REG_REVISION);
681 u8 rev = lm87_read_value(new_client, LM87_REG_REVISION); 677
682 678 if (cid == 0x02 /* National Semiconductor */
683 if (cid == 0x02 /* National Semiconductor */ 679 && (rev >= 0x01 && rev <= 0x08))
684 && (rev >= 0x01 && rev <= 0x08)) 680 name = "lm87";
685 kind = lm87; 681 else if (cid == 0x41 /* Analog Devices */
686 else if (cid == 0x41 /* Analog Devices */ 682 && (rev & 0xf0) == 0x10)
687 && (rev & 0xf0) == 0x10) 683 name = "adm1024";
688 kind = adm1024; 684 else {
689 685 dev_dbg(&adapter->dev, "LM87 detection failed at 0x%02x\n",
690 if (kind < 0 686 new_client->addr);
691 || (lm87_read_value(new_client, LM87_REG_CONFIG) & 0x80)) { 687 return -ENODEV;
692 dev_dbg(&adapter->dev,
693 "LM87 detection failed at 0x%02x.\n",
694 new_client->addr);
695 return -ENODEV;
696 }
697 } 688 }
698 689
699 strlcpy(info->type, names[kind - 1], I2C_NAME_SIZE); 690 strlcpy(info->type, name, I2C_NAME_SIZE);
700 691
701 return 0; 692 return 0;
702} 693}
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index 1aff7575799d..7cc2708871ab 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * lm90.c - Part of lm_sensors, Linux kernel modules for hardware 2 * lm90.c - Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring 3 * monitoring
4 * Copyright (C) 2003-2008 Jean Delvare <khali@linux-fr.org> 4 * Copyright (C) 2003-2010 Jean Delvare <khali@linux-fr.org>
5 * 5 *
6 * Based on the lm83 driver. The LM90 is a sensor chip made by National 6 * Based on the lm83 driver. The LM90 is a sensor chip made by National
7 * Semiconductor. It reports up to two temperatures (its own plus up to 7 * Semiconductor. It reports up to two temperatures (its own plus up to
@@ -93,12 +93,8 @@
93static const unsigned short normal_i2c[] = { 93static const unsigned short normal_i2c[] = {
94 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END }; 94 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END };
95 95
96/* 96enum chips { lm90, adm1032, lm99, lm86, max6657, adt7461, max6680, max6646,
97 * Insmod parameters 97 w83l771 };
98 */
99
100I2C_CLIENT_INSMOD_8(lm90, adm1032, lm99, lm86, max6657, adt7461, max6680,
101 max6646);
102 98
103/* 99/*
104 * The LM90 registers 100 * The LM90 registers
@@ -152,11 +148,11 @@ I2C_CLIENT_INSMOD_8(lm90, adm1032, lm99, lm86, max6657, adt7461, max6680,
152 * Functions declaration 148 * Functions declaration
153 */ 149 */
154 150
155static int lm90_detect(struct i2c_client *client, int kind, 151static int lm90_detect(struct i2c_client *client, struct i2c_board_info *info);
156 struct i2c_board_info *info);
157static int lm90_probe(struct i2c_client *client, 152static int lm90_probe(struct i2c_client *client,
158 const struct i2c_device_id *id); 153 const struct i2c_device_id *id);
159static void lm90_init_client(struct i2c_client *client); 154static void lm90_init_client(struct i2c_client *client);
155static void lm90_alert(struct i2c_client *client, unsigned int flag);
160static int lm90_remove(struct i2c_client *client); 156static int lm90_remove(struct i2c_client *client);
161static struct lm90_data *lm90_update_device(struct device *dev); 157static struct lm90_data *lm90_update_device(struct device *dev);
162 158
@@ -179,6 +175,7 @@ static const struct i2c_device_id lm90_id[] = {
179 { "max6659", max6657 }, 175 { "max6659", max6657 },
180 { "max6680", max6680 }, 176 { "max6680", max6680 },
181 { "max6681", max6680 }, 177 { "max6681", max6680 },
178 { "w83l771", w83l771 },
182 { } 179 { }
183}; 180};
184MODULE_DEVICE_TABLE(i2c, lm90_id); 181MODULE_DEVICE_TABLE(i2c, lm90_id);
@@ -190,9 +187,10 @@ static struct i2c_driver lm90_driver = {
190 }, 187 },
191 .probe = lm90_probe, 188 .probe = lm90_probe,
192 .remove = lm90_remove, 189 .remove = lm90_remove,
190 .alert = lm90_alert,
193 .id_table = lm90_id, 191 .id_table = lm90_id,
194 .detect = lm90_detect, 192 .detect = lm90_detect,
195 .address_data = &addr_data, 193 .address_list = normal_i2c,
196}; 194};
197 195
198/* 196/*
@@ -207,6 +205,9 @@ struct lm90_data {
207 int kind; 205 int kind;
208 int flags; 206 int flags;
209 207
208 u8 config_orig; /* Original configuration register value */
209 u8 alert_alarms; /* Which alarm bits trigger ALERT# */
210
210 /* registers values */ 211 /* registers values */
211 s8 temp8[4]; /* 0: local low limit 212 s8 temp8[4]; /* 0: local low limit
212 1: local high limit 213 1: local high limit
@@ -656,159 +657,131 @@ static int lm90_read_reg(struct i2c_client* client, u8 reg, u8 *value)
656} 657}
657 658
658/* Return 0 if detection is successful, -ENODEV otherwise */ 659/* Return 0 if detection is successful, -ENODEV otherwise */
659static int lm90_detect(struct i2c_client *new_client, int kind, 660static int lm90_detect(struct i2c_client *new_client,
660 struct i2c_board_info *info) 661 struct i2c_board_info *info)
661{ 662{
662 struct i2c_adapter *adapter = new_client->adapter; 663 struct i2c_adapter *adapter = new_client->adapter;
663 int address = new_client->addr; 664 int address = new_client->addr;
664 const char *name = ""; 665 const char *name = NULL;
666 int man_id, chip_id, reg_config1, reg_convrate;
665 667
666 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 668 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
667 return -ENODEV; 669 return -ENODEV;
668 670
669 /* 671 /* detection and identification */
670 * Now we do the remaining detection. A negative kind means that 672 if ((man_id = i2c_smbus_read_byte_data(new_client,
671 * the driver was loaded with no force parameter (default), so we
672 * must both detect and identify the chip. A zero kind means that
673 * the driver was loaded with the force parameter, the detection
674 * step shall be skipped. A positive kind means that the driver
675 * was loaded with the force parameter and a given kind of chip is
676 * requested, so both the detection and the identification steps
677 * are skipped.
678 */
679
680 /* Default to an LM90 if forced */
681 if (kind == 0)
682 kind = lm90;
683
684 if (kind < 0) { /* detection and identification */
685 int man_id, chip_id, reg_config1, reg_convrate;
686
687 if ((man_id = i2c_smbus_read_byte_data(new_client,
688 LM90_REG_R_MAN_ID)) < 0 673 LM90_REG_R_MAN_ID)) < 0
689 || (chip_id = i2c_smbus_read_byte_data(new_client, 674 || (chip_id = i2c_smbus_read_byte_data(new_client,
690 LM90_REG_R_CHIP_ID)) < 0 675 LM90_REG_R_CHIP_ID)) < 0
691 || (reg_config1 = i2c_smbus_read_byte_data(new_client, 676 || (reg_config1 = i2c_smbus_read_byte_data(new_client,
692 LM90_REG_R_CONFIG1)) < 0 677 LM90_REG_R_CONFIG1)) < 0
693 || (reg_convrate = i2c_smbus_read_byte_data(new_client, 678 || (reg_convrate = i2c_smbus_read_byte_data(new_client,
694 LM90_REG_R_CONVRATE)) < 0) 679 LM90_REG_R_CONVRATE)) < 0)
680 return -ENODEV;
681
682 if ((address == 0x4C || address == 0x4D)
683 && man_id == 0x01) { /* National Semiconductor */
684 int reg_config2;
685
686 reg_config2 = i2c_smbus_read_byte_data(new_client,
687 LM90_REG_R_CONFIG2);
688 if (reg_config2 < 0)
695 return -ENODEV; 689 return -ENODEV;
696 690
697 if ((address == 0x4C || address == 0x4D) 691 if ((reg_config1 & 0x2A) == 0x00
698 && man_id == 0x01) { /* National Semiconductor */ 692 && (reg_config2 & 0xF8) == 0x00
699 int reg_config2; 693 && reg_convrate <= 0x09) {
700 694 if (address == 0x4C
701 if ((reg_config2 = i2c_smbus_read_byte_data(new_client, 695 && (chip_id & 0xF0) == 0x20) { /* LM90 */
702 LM90_REG_R_CONFIG2)) < 0) 696 name = "lm90";
703 return -ENODEV;
704
705 if ((reg_config1 & 0x2A) == 0x00
706 && (reg_config2 & 0xF8) == 0x00
707 && reg_convrate <= 0x09) {
708 if (address == 0x4C
709 && (chip_id & 0xF0) == 0x20) { /* LM90 */
710 kind = lm90;
711 } else
712 if ((chip_id & 0xF0) == 0x30) { /* LM89/LM99 */
713 kind = lm99;
714 dev_info(&adapter->dev,
715 "Assuming LM99 chip at "
716 "0x%02x\n", address);
717 dev_info(&adapter->dev,
718 "If it is an LM89, pass "
719 "force_lm86=%d,0x%02x when "
720 "loading the lm90 driver\n",
721 i2c_adapter_id(adapter),
722 address);
723 } else
724 if (address == 0x4C
725 && (chip_id & 0xF0) == 0x10) { /* LM86 */
726 kind = lm86;
727 }
728 }
729 } else
730 if ((address == 0x4C || address == 0x4D)
731 && man_id == 0x41) { /* Analog Devices */
732 if ((chip_id & 0xF0) == 0x40 /* ADM1032 */
733 && (reg_config1 & 0x3F) == 0x00
734 && reg_convrate <= 0x0A) {
735 kind = adm1032;
736 } else
737 if (chip_id == 0x51 /* ADT7461 */
738 && (reg_config1 & 0x1B) == 0x00
739 && reg_convrate <= 0x0A) {
740 kind = adt7461;
741 }
742 } else
743 if (man_id == 0x4D) { /* Maxim */
744 /*
745 * The MAX6657, MAX6658 and MAX6659 do NOT have a
746 * chip_id register. Reading from that address will
747 * return the last read value, which in our case is
748 * those of the man_id register. Likewise, the config1
749 * register seems to lack a low nibble, so the value
750 * will be those of the previous read, so in our case
751 * those of the man_id register.
752 */
753 if (chip_id == man_id
754 && (address == 0x4C || address == 0x4D)
755 && (reg_config1 & 0x1F) == (man_id & 0x0F)
756 && reg_convrate <= 0x09) {
757 kind = max6657;
758 } else 697 } else
759 /* The chip_id register of the MAX6680 and MAX6681 698 if ((chip_id & 0xF0) == 0x30) { /* LM89/LM99 */
760 * holds the revision of the chip. 699 name = "lm99";
761 * the lowest bit of the config1 register is unused 700 dev_info(&adapter->dev,
762 * and should return zero when read, so should the 701 "Assuming LM99 chip at 0x%02x\n",
763 * second to last bit of config1 (software reset) 702 address);
764 */ 703 dev_info(&adapter->dev,
765 if (chip_id == 0x01 704 "If it is an LM89, instantiate it "
766 && (reg_config1 & 0x03) == 0x00 705 "with the new_device sysfs "
767 && reg_convrate <= 0x07) { 706 "interface\n");
768 kind = max6680;
769 } else 707 } else
770 /* The chip_id register of the MAX6646/6647/6649 708 if (address == 0x4C
771 * holds the revision of the chip. 709 && (chip_id & 0xF0) == 0x10) { /* LM86 */
772 * The lowest 6 bits of the config1 register are 710 name = "lm86";
773 * unused and should return zero when read.
774 */
775 if (chip_id == 0x59
776 && (reg_config1 & 0x3f) == 0x00
777 && reg_convrate <= 0x07) {
778 kind = max6646;
779 } 711 }
780 } 712 }
781 713 } else
782 if (kind <= 0) { /* identification failed */ 714 if ((address == 0x4C || address == 0x4D)
783 dev_dbg(&adapter->dev, 715 && man_id == 0x41) { /* Analog Devices */
784 "Unsupported chip at 0x%02x (man_id=0x%02X, " 716 if ((chip_id & 0xF0) == 0x40 /* ADM1032 */
785 "chip_id=0x%02X)\n", address, man_id, chip_id); 717 && (reg_config1 & 0x3F) == 0x00
786 return -ENODEV; 718 && reg_convrate <= 0x0A) {
719 name = "adm1032";
720 /* The ADM1032 supports PEC, but only if combined
721 transactions are not used. */
722 if (i2c_check_functionality(adapter,
723 I2C_FUNC_SMBUS_BYTE))
724 info->flags |= I2C_CLIENT_PEC;
725 } else
726 if (chip_id == 0x51 /* ADT7461 */
727 && (reg_config1 & 0x1B) == 0x00
728 && reg_convrate <= 0x0A) {
729 name = "adt7461";
730 }
731 } else
732 if (man_id == 0x4D) { /* Maxim */
733 /*
734 * The MAX6657, MAX6658 and MAX6659 do NOT have a chip_id
735 * register. Reading from that address will return the last
736 * read value, which in our case is those of the man_id
737 * register. Likewise, the config1 register seems to lack a
738 * low nibble, so the value will be those of the previous
739 * read, so in our case those of the man_id register.
740 */
741 if (chip_id == man_id
742 && (address == 0x4C || address == 0x4D)
743 && (reg_config1 & 0x1F) == (man_id & 0x0F)
744 && reg_convrate <= 0x09) {
745 name = "max6657";
746 } else
747 /*
748 * The chip_id register of the MAX6680 and MAX6681 holds the
749 * revision of the chip. The lowest bit of the config1 register
750 * is unused and should return zero when read, so should the
751 * second to last bit of config1 (software reset).
752 */
753 if (chip_id == 0x01
754 && (reg_config1 & 0x03) == 0x00
755 && reg_convrate <= 0x07) {
756 name = "max6680";
757 } else
758 /*
759 * The chip_id register of the MAX6646/6647/6649 holds the
760 * revision of the chip. The lowest 6 bits of the config1
761 * register are unused and should return zero when read.
762 */
763 if (chip_id == 0x59
764 && (reg_config1 & 0x3f) == 0x00
765 && reg_convrate <= 0x07) {
766 name = "max6646";
767 }
768 } else
769 if (address == 0x4C
770 && man_id == 0x5C) { /* Winbond/Nuvoton */
771 if ((chip_id & 0xFE) == 0x10 /* W83L771AWG/ASG */
772 && (reg_config1 & 0x2A) == 0x00
773 && reg_convrate <= 0x08) {
774 name = "w83l771";
787 } 775 }
788 } 776 }
789 777
790 /* Fill the i2c board info */ 778 if (!name) { /* identification failed */
791 if (kind == lm90) { 779 dev_dbg(&adapter->dev,
792 name = "lm90"; 780 "Unsupported chip at 0x%02x (man_id=0x%02X, "
793 } else if (kind == adm1032) { 781 "chip_id=0x%02X)\n", address, man_id, chip_id);
794 name = "adm1032"; 782 return -ENODEV;
795 /* The ADM1032 supports PEC, but only if combined
796 transactions are not used. */
797 if (i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE))
798 info->flags |= I2C_CLIENT_PEC;
799 } else if (kind == lm99) {
800 name = "lm99";
801 } else if (kind == lm86) {
802 name = "lm86";
803 } else if (kind == max6657) {
804 name = "max6657";
805 } else if (kind == max6680) {
806 name = "max6680";
807 } else if (kind == adt7461) {
808 name = "adt7461";
809 } else if (kind == max6646) {
810 name = "max6646";
811 } 783 }
784
812 strlcpy(info->type, name, I2C_NAME_SIZE); 785 strlcpy(info->type, name, I2C_NAME_SIZE);
813 786
814 return 0; 787 return 0;
@@ -836,6 +809,19 @@ static int lm90_probe(struct i2c_client *new_client,
836 new_client->flags &= ~I2C_CLIENT_PEC; 809 new_client->flags &= ~I2C_CLIENT_PEC;
837 } 810 }
838 811
812 /* Different devices have different alarm bits triggering the
813 * ALERT# output */
814 switch (data->kind) {
815 case lm90:
816 case lm99:
817 case lm86:
818 data->alert_alarms = 0x7b;
819 break;
820 default:
821 data->alert_alarms = 0x7c;
822 break;
823 }
824
839 /* Initialize the LM90 chip */ 825 /* Initialize the LM90 chip */
840 lm90_init_client(new_client); 826 lm90_init_client(new_client);
841 827
@@ -872,7 +858,7 @@ exit:
872 858
873static void lm90_init_client(struct i2c_client *client) 859static void lm90_init_client(struct i2c_client *client)
874{ 860{
875 u8 config, config_orig; 861 u8 config;
876 struct lm90_data *data = i2c_get_clientdata(client); 862 struct lm90_data *data = i2c_get_clientdata(client);
877 863
878 /* 864 /*
@@ -884,7 +870,7 @@ static void lm90_init_client(struct i2c_client *client)
884 dev_warn(&client->dev, "Initialization failed!\n"); 870 dev_warn(&client->dev, "Initialization failed!\n");
885 return; 871 return;
886 } 872 }
887 config_orig = config; 873 data->config_orig = config;
888 874
889 /* Check Temperature Range Select */ 875 /* Check Temperature Range Select */
890 if (data->kind == adt7461) { 876 if (data->kind == adt7461) {
@@ -902,7 +888,7 @@ static void lm90_init_client(struct i2c_client *client)
902 } 888 }
903 889
904 config &= 0xBF; /* run */ 890 config &= 0xBF; /* run */
905 if (config != config_orig) /* Only write if changed */ 891 if (config != data->config_orig) /* Only write if changed */
906 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); 892 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config);
907} 893}
908 894
@@ -917,10 +903,46 @@ static int lm90_remove(struct i2c_client *client)
917 device_remove_file(&client->dev, 903 device_remove_file(&client->dev,
918 &sensor_dev_attr_temp2_offset.dev_attr); 904 &sensor_dev_attr_temp2_offset.dev_attr);
919 905
906 /* Restore initial configuration */
907 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
908 data->config_orig);
909
920 kfree(data); 910 kfree(data);
921 return 0; 911 return 0;
922} 912}
923 913
914static void lm90_alert(struct i2c_client *client, unsigned int flag)
915{
916 struct lm90_data *data = i2c_get_clientdata(client);
917 u8 config, alarms;
918
919 lm90_read_reg(client, LM90_REG_R_STATUS, &alarms);
920 if ((alarms & 0x7f) == 0) {
921 dev_info(&client->dev, "Everything OK\n");
922 } else {
923 if (alarms & 0x61)
924 dev_warn(&client->dev,
925 "temp%d out of range, please check!\n", 1);
926 if (alarms & 0x1a)
927 dev_warn(&client->dev,
928 "temp%d out of range, please check!\n", 2);
929 if (alarms & 0x04)
930 dev_warn(&client->dev,
931 "temp%d diode open, please check!\n", 2);
932
933 /* Disable ALERT# output, because these chips don't implement
934 SMBus alert correctly; they should only hold the alert line
935 low briefly. */
936 if ((data->kind == adm1032 || data->kind == adt7461)
937 && (alarms & data->alert_alarms)) {
938 dev_dbg(&client->dev, "Disabling ALERT#\n");
939 lm90_read_reg(client, LM90_REG_R_CONFIG1, &config);
940 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
941 config | 0x80);
942 }
943 }
944}
945
924static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value) 946static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value)
925{ 947{
926 int err; 948 int err;
@@ -1008,6 +1030,21 @@ static struct lm90_data *lm90_update_device(struct device *dev)
1008 } 1030 }
1009 lm90_read_reg(client, LM90_REG_R_STATUS, &data->alarms); 1031 lm90_read_reg(client, LM90_REG_R_STATUS, &data->alarms);
1010 1032
1033 /* Re-enable ALERT# output if it was originally enabled and
1034 * relevant alarms are all clear */
1035 if ((data->config_orig & 0x80) == 0
1036 && (data->alarms & data->alert_alarms) == 0) {
1037 u8 config;
1038
1039 lm90_read_reg(client, LM90_REG_R_CONFIG1, &config);
1040 if (config & 0x80) {
1041 dev_dbg(&client->dev, "Re-enabling ALERT#\n");
1042 i2c_smbus_write_byte_data(client,
1043 LM90_REG_W_CONFIG1,
1044 config & ~0x80);
1045 }
1046 }
1047
1011 data->last_updated = jiffies; 1048 data->last_updated = jiffies;
1012 data->valid = 1; 1049 data->valid = 1;
1013 } 1050 }
diff --git a/drivers/hwmon/lm92.c b/drivers/hwmon/lm92.c
index b2e00c5a7eec..7c31e6205f85 100644
--- a/drivers/hwmon/lm92.c
+++ b/drivers/hwmon/lm92.c
@@ -54,9 +54,6 @@
54static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 54static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b,
55 I2C_CLIENT_END }; 55 I2C_CLIENT_END };
56 56
57/* Insmod parameters */
58I2C_CLIENT_INSMOD_1(lm92);
59
60/* The LM92 registers */ 57/* The LM92 registers */
61#define LM92_REG_CONFIG 0x01 /* 8-bit, RW */ 58#define LM92_REG_CONFIG 0x01 /* 8-bit, RW */
62#define LM92_REG_TEMP 0x00 /* 16-bit, RO */ 59#define LM92_REG_TEMP 0x00 /* 16-bit, RO */
@@ -319,35 +316,26 @@ static const struct attribute_group lm92_group = {
319}; 316};
320 317
321/* Return 0 if detection is successful, -ENODEV otherwise */ 318/* Return 0 if detection is successful, -ENODEV otherwise */
322static int lm92_detect(struct i2c_client *new_client, int kind, 319static int lm92_detect(struct i2c_client *new_client,
323 struct i2c_board_info *info) 320 struct i2c_board_info *info)
324{ 321{
325 struct i2c_adapter *adapter = new_client->adapter; 322 struct i2c_adapter *adapter = new_client->adapter;
323 u8 config;
324 u16 man_id;
326 325
327 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA 326 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA
328 | I2C_FUNC_SMBUS_WORD_DATA)) 327 | I2C_FUNC_SMBUS_WORD_DATA))
329 return -ENODEV; 328 return -ENODEV;
330 329
331 /* A negative kind means that the driver was loaded with no force 330 config = i2c_smbus_read_byte_data(new_client, LM92_REG_CONFIG);
332 parameter (default), so we must identify the chip. */ 331 man_id = i2c_smbus_read_word_data(new_client, LM92_REG_MAN_ID);
333 if (kind < 0) { 332
334 u8 config = i2c_smbus_read_byte_data(new_client, 333 if ((config & 0xe0) == 0x00 && man_id == 0x0180)
335 LM92_REG_CONFIG); 334 pr_info("lm92: Found National Semiconductor LM92 chip\n");
336 u16 man_id = i2c_smbus_read_word_data(new_client, 335 else if (max6635_check(new_client))
337 LM92_REG_MAN_ID); 336 pr_info("lm92: Found Maxim MAX6635 chip\n");
338 337 else
339 if ((config & 0xe0) == 0x00 338 return -ENODEV;
340 && man_id == 0x0180) {
341 pr_info("lm92: Found National Semiconductor LM92 chip\n");
342 kind = lm92;
343 } else
344 if (max6635_check(new_client)) {
345 pr_info("lm92: Found Maxim MAX6635 chip\n");
346 kind = lm92; /* No separate prefix */
347 }
348 else
349 return -ENODEV;
350 }
351 339
352 strlcpy(info->type, "lm92", I2C_NAME_SIZE); 340 strlcpy(info->type, "lm92", I2C_NAME_SIZE);
353 341
@@ -410,7 +398,7 @@ static int lm92_remove(struct i2c_client *client)
410 */ 398 */
411 399
412static const struct i2c_device_id lm92_id[] = { 400static const struct i2c_device_id lm92_id[] = {
413 { "lm92", lm92 }, 401 { "lm92", 0 },
414 /* max6635 could be added here */ 402 /* max6635 could be added here */
415 { } 403 { }
416}; 404};
@@ -425,7 +413,7 @@ static struct i2c_driver lm92_driver = {
425 .remove = lm92_remove, 413 .remove = lm92_remove,
426 .id_table = lm92_id, 414 .id_table = lm92_id,
427 .detect = lm92_detect, 415 .detect = lm92_detect,
428 .address_data = &addr_data, 416 .address_list = normal_i2c,
429}; 417};
430 418
431static int __init sensors_lm92_init(void) 419static int __init sensors_lm92_init(void)
diff --git a/drivers/hwmon/lm93.c b/drivers/hwmon/lm93.c
index fc36cadf36fb..6669255aadcf 100644
--- a/drivers/hwmon/lm93.c
+++ b/drivers/hwmon/lm93.c
@@ -145,7 +145,6 @@
145static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; 145static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
146 146
147/* Insmod parameters */ 147/* Insmod parameters */
148I2C_CLIENT_INSMOD_1(lm93);
149 148
150static int disable_block; 149static int disable_block;
151module_param(disable_block, bool, 0); 150module_param(disable_block, bool, 0);
@@ -928,7 +927,7 @@ static void lm93_update_client_common(struct lm93_data *data,
928 data->prochot_interval = lm93_read_byte(client, 927 data->prochot_interval = lm93_read_byte(client,
929 LM93_REG_PROCHOT_INTERVAL); 928 LM93_REG_PROCHOT_INTERVAL);
930 929
931 /* Fan Boost Termperature registers */ 930 /* Fan Boost Temperature registers */
932 for (i = 0; i < 4; i++) 931 for (i = 0; i < 4; i++)
933 data->boost[i] = lm93_read_byte(client, LM93_REG_BOOST(i)); 932 data->boost[i] = lm93_read_byte(client, LM93_REG_BOOST(i));
934 933
@@ -2501,38 +2500,27 @@ static void lm93_init_client(struct i2c_client *client)
2501} 2500}
2502 2501
2503/* Return 0 if detection is successful, -ENODEV otherwise */ 2502/* Return 0 if detection is successful, -ENODEV otherwise */
2504static int lm93_detect(struct i2c_client *client, int kind, 2503static int lm93_detect(struct i2c_client *client, struct i2c_board_info *info)
2505 struct i2c_board_info *info)
2506{ 2504{
2507 struct i2c_adapter *adapter = client->adapter; 2505 struct i2c_adapter *adapter = client->adapter;
2506 int mfr, ver;
2508 2507
2509 if (!i2c_check_functionality(adapter, LM93_SMBUS_FUNC_MIN)) 2508 if (!i2c_check_functionality(adapter, LM93_SMBUS_FUNC_MIN))
2510 return -ENODEV; 2509 return -ENODEV;
2511 2510
2512 /* detection */ 2511 /* detection */
2513 if (kind < 0) { 2512 mfr = lm93_read_byte(client, LM93_REG_MFR_ID);
2514 int mfr = lm93_read_byte(client, LM93_REG_MFR_ID); 2513 if (mfr != 0x01) {
2515 2514 dev_dbg(&adapter->dev,
2516 if (mfr != 0x01) { 2515 "detect failed, bad manufacturer id 0x%02x!\n", mfr);
2517 dev_dbg(&adapter->dev,"detect failed, " 2516 return -ENODEV;
2518 "bad manufacturer id 0x%02x!\n", mfr);
2519 return -ENODEV;
2520 }
2521 } 2517 }
2522 2518
2523 if (kind <= 0) { 2519 ver = lm93_read_byte(client, LM93_REG_VER);
2524 int ver = lm93_read_byte(client, LM93_REG_VER); 2520 if (ver != LM93_MFR_ID && ver != LM93_MFR_ID_PROTOTYPE) {
2525 2521 dev_dbg(&adapter->dev,
2526 if ((ver == LM93_MFR_ID) || (ver == LM93_MFR_ID_PROTOTYPE)) { 2522 "detect failed, bad version id 0x%02x!\n", ver);
2527 kind = lm93; 2523 return -ENODEV;
2528 } else {
2529 dev_dbg(&adapter->dev,"detect failed, "
2530 "bad version id 0x%02x!\n", ver);
2531 if (kind == 0)
2532 dev_dbg(&adapter->dev,
2533 "(ignored 'force' parameter)\n");
2534 return -ENODEV;
2535 }
2536 } 2524 }
2537 2525
2538 strlcpy(info->type, "lm93", I2C_NAME_SIZE); 2526 strlcpy(info->type, "lm93", I2C_NAME_SIZE);
@@ -2613,7 +2601,7 @@ static int lm93_remove(struct i2c_client *client)
2613} 2601}
2614 2602
2615static const struct i2c_device_id lm93_id[] = { 2603static const struct i2c_device_id lm93_id[] = {
2616 { "lm93", lm93 }, 2604 { "lm93", 0 },
2617 { } 2605 { }
2618}; 2606};
2619MODULE_DEVICE_TABLE(i2c, lm93_id); 2607MODULE_DEVICE_TABLE(i2c, lm93_id);
@@ -2627,7 +2615,7 @@ static struct i2c_driver lm93_driver = {
2627 .remove = lm93_remove, 2615 .remove = lm93_remove,
2628 .id_table = lm93_id, 2616 .id_table = lm93_id,
2629 .detect = lm93_detect, 2617 .detect = lm93_detect,
2630 .address_data = &addr_data, 2618 .address_list = normal_i2c,
2631}; 2619};
2632 2620
2633static int __init lm93_init(void) 2621static int __init lm93_init(void)
diff --git a/drivers/hwmon/lm95241.c b/drivers/hwmon/lm95241.c
index e34f9e402a2c..8fc8eb8cba47 100644
--- a/drivers/hwmon/lm95241.c
+++ b/drivers/hwmon/lm95241.c
@@ -39,9 +39,6 @@
39static const unsigned short normal_i2c[] = { 39static const unsigned short normal_i2c[] = {
40 0x19, 0x2a, 0x2b, I2C_CLIENT_END}; 40 0x19, 0x2a, 0x2b, I2C_CLIENT_END};
41 41
42/* Insmod parameters */
43I2C_CLIENT_INSMOD_1(lm95241);
44
45/* LM95241 registers */ 42/* LM95241 registers */
46#define LM95241_REG_R_MAN_ID 0xFE 43#define LM95241_REG_R_MAN_ID 0xFE
47#define LM95241_REG_R_CHIP_ID 0xFF 44#define LM95241_REG_R_CHIP_ID 0xFF
@@ -310,56 +307,28 @@ static const struct attribute_group lm95241_group = {
310}; 307};
311 308
312/* Return 0 if detection is successful, -ENODEV otherwise */ 309/* Return 0 if detection is successful, -ENODEV otherwise */
313static int lm95241_detect(struct i2c_client *new_client, int kind, 310static int lm95241_detect(struct i2c_client *new_client,
314 struct i2c_board_info *info) 311 struct i2c_board_info *info)
315{ 312{
316 struct i2c_adapter *adapter = new_client->adapter; 313 struct i2c_adapter *adapter = new_client->adapter;
317 int address = new_client->addr; 314 int address = new_client->addr;
318 const char *name = ""; 315 const char *name;
319 316
320 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 317 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
321 return -ENODEV; 318 return -ENODEV;
322 319
323 /* 320 if ((i2c_smbus_read_byte_data(new_client, LM95241_REG_R_MAN_ID)
324 * Now we do the remaining detection. A negative kind means that 321 == MANUFACTURER_ID)
325 * the driver was loaded with no force parameter (default), so we 322 && (i2c_smbus_read_byte_data(new_client, LM95241_REG_R_CHIP_ID)
326 * must both detect and identify the chip. A zero kind means that 323 >= DEFAULT_REVISION)) {
327 * the driver was loaded with the force parameter, the detection 324 name = "lm95241";
328 * step shall be skipped. A positive kind means that the driver 325 } else {
329 * was loaded with the force parameter and a given kind of chip is 326 dev_dbg(&adapter->dev, "LM95241 detection failed at 0x%02x\n",
330 * requested, so both the detection and the identification steps 327 address);
331 * are skipped. 328 return -ENODEV;
332 */
333 if (kind < 0) { /* detection */
334 if ((i2c_smbus_read_byte_data(new_client, LM95241_REG_R_MAN_ID)
335 != MANUFACTURER_ID)
336 || (i2c_smbus_read_byte_data(new_client, LM95241_REG_R_CHIP_ID)
337 < DEFAULT_REVISION)) {
338 dev_dbg(&adapter->dev,
339 "LM95241 detection failed at 0x%02x.\n",
340 address);
341 return -ENODEV;
342 }
343 }
344
345 if (kind <= 0) { /* identification */
346 if ((i2c_smbus_read_byte_data(new_client, LM95241_REG_R_MAN_ID)
347 == MANUFACTURER_ID)
348 && (i2c_smbus_read_byte_data(new_client, LM95241_REG_R_CHIP_ID)
349 >= DEFAULT_REVISION)) {
350
351 kind = lm95241;
352
353 if (kind <= 0) { /* identification failed */
354 dev_info(&adapter->dev, "Unsupported chip\n");
355 return -ENODEV;
356 }
357 }
358 } 329 }
359 330
360 /* Fill the i2c board info */ 331 /* Fill the i2c board info */
361 if (kind == lm95241)
362 name = "lm95241";
363 strlcpy(info->type, name, I2C_NAME_SIZE); 332 strlcpy(info->type, name, I2C_NAME_SIZE);
364 return 0; 333 return 0;
365} 334}
@@ -474,7 +443,7 @@ static struct lm95241_data *lm95241_update_device(struct device *dev)
474 443
475/* Driver data (common to all clients) */ 444/* Driver data (common to all clients) */
476static const struct i2c_device_id lm95241_id[] = { 445static const struct i2c_device_id lm95241_id[] = {
477 { "lm95241", lm95241 }, 446 { "lm95241", 0 },
478 { } 447 { }
479}; 448};
480MODULE_DEVICE_TABLE(i2c, lm95241_id); 449MODULE_DEVICE_TABLE(i2c, lm95241_id);
@@ -488,7 +457,7 @@ static struct i2c_driver lm95241_driver = {
488 .remove = lm95241_remove, 457 .remove = lm95241_remove,
489 .id_table = lm95241_id, 458 .id_table = lm95241_id,
490 .detect = lm95241_detect, 459 .detect = lm95241_detect,
491 .address_data = &addr_data, 460 .address_list = normal_i2c,
492}; 461};
493 462
494static int __init sensors_lm95241_init(void) 463static int __init sensors_lm95241_init(void)
diff --git a/drivers/hwmon/max1111.c b/drivers/hwmon/max1111.c
index 9ac497271adf..12a54aa29776 100644
--- a/drivers/hwmon/max1111.c
+++ b/drivers/hwmon/max1111.c
@@ -20,6 +20,7 @@
20#include <linux/hwmon.h> 20#include <linux/hwmon.h>
21#include <linux/hwmon-sysfs.h> 21#include <linux/hwmon-sysfs.h>
22#include <linux/spi/spi.h> 22#include <linux/spi/spi.h>
23#include <linux/slab.h>
23 24
24#define MAX1111_TX_BUF_SIZE 1 25#define MAX1111_TX_BUF_SIZE 1
25#define MAX1111_RX_BUF_SIZE 2 26#define MAX1111_RX_BUF_SIZE 2
diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c
index 7897754f3a5c..022ded098100 100644
--- a/drivers/hwmon/max1619.c
+++ b/drivers/hwmon/max1619.c
@@ -41,12 +41,6 @@ static const unsigned short normal_i2c[] = {
41 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END }; 41 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END };
42 42
43/* 43/*
44 * Insmod parameters
45 */
46
47I2C_CLIENT_INSMOD_1(max1619);
48
49/*
50 * The MAX1619 registers 44 * The MAX1619 registers
51 */ 45 */
52 46
@@ -88,7 +82,7 @@ static int temp_to_reg(int val)
88 82
89static int max1619_probe(struct i2c_client *client, 83static int max1619_probe(struct i2c_client *client,
90 const struct i2c_device_id *id); 84 const struct i2c_device_id *id);
91static int max1619_detect(struct i2c_client *client, int kind, 85static int max1619_detect(struct i2c_client *client,
92 struct i2c_board_info *info); 86 struct i2c_board_info *info);
93static void max1619_init_client(struct i2c_client *client); 87static void max1619_init_client(struct i2c_client *client);
94static int max1619_remove(struct i2c_client *client); 88static int max1619_remove(struct i2c_client *client);
@@ -99,7 +93,7 @@ static struct max1619_data *max1619_update_device(struct device *dev);
99 */ 93 */
100 94
101static const struct i2c_device_id max1619_id[] = { 95static const struct i2c_device_id max1619_id[] = {
102 { "max1619", max1619 }, 96 { "max1619", 0 },
103 { } 97 { }
104}; 98};
105MODULE_DEVICE_TABLE(i2c, max1619_id); 99MODULE_DEVICE_TABLE(i2c, max1619_id);
@@ -113,7 +107,7 @@ static struct i2c_driver max1619_driver = {
113 .remove = max1619_remove, 107 .remove = max1619_remove,
114 .id_table = max1619_id, 108 .id_table = max1619_id,
115 .detect = max1619_detect, 109 .detect = max1619_detect,
116 .address_data = &addr_data, 110 .address_list = normal_i2c,
117}; 111};
118 112
119/* 113/*
@@ -226,58 +220,34 @@ static const struct attribute_group max1619_group = {
226 */ 220 */
227 221
228/* Return 0 if detection is successful, -ENODEV otherwise */ 222/* Return 0 if detection is successful, -ENODEV otherwise */
229static int max1619_detect(struct i2c_client *new_client, int kind, 223static int max1619_detect(struct i2c_client *client,
230 struct i2c_board_info *info) 224 struct i2c_board_info *info)
231{ 225{
232 struct i2c_adapter *adapter = new_client->adapter; 226 struct i2c_adapter *adapter = client->adapter;
233 u8 reg_config=0, reg_convrate=0, reg_status=0; 227 u8 reg_config, reg_convrate, reg_status, man_id, chip_id;
234 228
235 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 229 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
236 return -ENODEV; 230 return -ENODEV;
237 231
238 /* 232 /* detection */
239 * Now we do the remaining detection. A negative kind means that 233 reg_config = i2c_smbus_read_byte_data(client, MAX1619_REG_R_CONFIG);
240 * the driver was loaded with no force parameter (default), so we 234 reg_convrate = i2c_smbus_read_byte_data(client, MAX1619_REG_R_CONVRATE);
241 * must both detect and identify the chip. A zero kind means that 235 reg_status = i2c_smbus_read_byte_data(client, MAX1619_REG_R_STATUS);
242 * the driver was loaded with the force parameter, the detection 236 if ((reg_config & 0x03) != 0x00
243 * step shall be skipped. A positive kind means that the driver 237 || reg_convrate > 0x07 || (reg_status & 0x61) != 0x00) {
244 * was loaded with the force parameter and a given kind of chip is 238 dev_dbg(&adapter->dev, "MAX1619 detection failed at 0x%02x\n",
245 * requested, so both the detection and the identification steps 239 client->addr);
246 * are skipped. 240 return -ENODEV;
247 */
248 if (kind < 0) { /* detection */
249 reg_config = i2c_smbus_read_byte_data(new_client,
250 MAX1619_REG_R_CONFIG);
251 reg_convrate = i2c_smbus_read_byte_data(new_client,
252 MAX1619_REG_R_CONVRATE);
253 reg_status = i2c_smbus_read_byte_data(new_client,
254 MAX1619_REG_R_STATUS);
255 if ((reg_config & 0x03) != 0x00
256 || reg_convrate > 0x07 || (reg_status & 0x61 ) !=0x00) {
257 dev_dbg(&adapter->dev,
258 "MAX1619 detection failed at 0x%02x.\n",
259 new_client->addr);
260 return -ENODEV;
261 }
262 } 241 }
263 242
264 if (kind <= 0) { /* identification */ 243 /* identification */
265 u8 man_id, chip_id; 244 man_id = i2c_smbus_read_byte_data(client, MAX1619_REG_R_MAN_ID);
266 245 chip_id = i2c_smbus_read_byte_data(client, MAX1619_REG_R_CHIP_ID);
267 man_id = i2c_smbus_read_byte_data(new_client, 246 if (man_id != 0x4D || chip_id != 0x04) {
268 MAX1619_REG_R_MAN_ID); 247 dev_info(&adapter->dev,
269 chip_id = i2c_smbus_read_byte_data(new_client, 248 "Unsupported chip (man_id=0x%02X, chip_id=0x%02X).\n",
270 MAX1619_REG_R_CHIP_ID); 249 man_id, chip_id);
271 250 return -ENODEV;
272 if ((man_id == 0x4D) && (chip_id == 0x04))
273 kind = max1619;
274
275 if (kind <= 0) { /* identification failed */
276 dev_info(&adapter->dev,
277 "Unsupported chip (man_id=0x%02X, "
278 "chip_id=0x%02X).\n", man_id, chip_id);
279 return -ENODEV;
280 }
281 } 251 }
282 252
283 strlcpy(info->type, "max1619", I2C_NAME_SIZE); 253 strlcpy(info->type, "max1619", I2C_NAME_SIZE);
diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c
index 58f66be61b1f..a0160ee5caef 100644
--- a/drivers/hwmon/max6650.c
+++ b/drivers/hwmon/max6650.c
@@ -62,8 +62,6 @@ module_param(fan_voltage, int, S_IRUGO);
62module_param(prescaler, int, S_IRUGO); 62module_param(prescaler, int, S_IRUGO);
63module_param(clock, int, S_IRUGO); 63module_param(clock, int, S_IRUGO);
64 64
65I2C_CLIENT_INSMOD_1(max6650);
66
67/* 65/*
68 * MAX 6650/6651 registers 66 * MAX 6650/6651 registers
69 */ 67 */
@@ -116,7 +114,7 @@ I2C_CLIENT_INSMOD_1(max6650);
116 114
117static int max6650_probe(struct i2c_client *client, 115static int max6650_probe(struct i2c_client *client,
118 const struct i2c_device_id *id); 116 const struct i2c_device_id *id);
119static int max6650_detect(struct i2c_client *client, int kind, 117static int max6650_detect(struct i2c_client *client,
120 struct i2c_board_info *info); 118 struct i2c_board_info *info);
121static int max6650_init_client(struct i2c_client *client); 119static int max6650_init_client(struct i2c_client *client);
122static int max6650_remove(struct i2c_client *client); 120static int max6650_remove(struct i2c_client *client);
@@ -127,7 +125,7 @@ static struct max6650_data *max6650_update_device(struct device *dev);
127 */ 125 */
128 126
129static const struct i2c_device_id max6650_id[] = { 127static const struct i2c_device_id max6650_id[] = {
130 { "max6650", max6650 }, 128 { "max6650", 0 },
131 { } 129 { }
132}; 130};
133MODULE_DEVICE_TABLE(i2c, max6650_id); 131MODULE_DEVICE_TABLE(i2c, max6650_id);
@@ -141,7 +139,7 @@ static struct i2c_driver max6650_driver = {
141 .remove = max6650_remove, 139 .remove = max6650_remove,
142 .id_table = max6650_id, 140 .id_table = max6650_id,
143 .detect = max6650_detect, 141 .detect = max6650_detect,
144 .address_data = &addr_data, 142 .address_list = normal_i2c,
145}; 143};
146 144
147/* 145/*
@@ -528,13 +526,13 @@ static struct attribute_group max6650_attr_grp = {
528 */ 526 */
529 527
530/* Return 0 if detection is successful, -ENODEV otherwise */ 528/* Return 0 if detection is successful, -ENODEV otherwise */
531static int max6650_detect(struct i2c_client *client, int kind, 529static int max6650_detect(struct i2c_client *client,
532 struct i2c_board_info *info) 530 struct i2c_board_info *info)
533{ 531{
534 struct i2c_adapter *adapter = client->adapter; 532 struct i2c_adapter *adapter = client->adapter;
535 int address = client->addr; 533 int address = client->addr;
536 534
537 dev_dbg(&adapter->dev, "max6650_detect called, kind = %d\n", kind); 535 dev_dbg(&adapter->dev, "max6650_detect called\n");
538 536
539 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 537 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
540 dev_dbg(&adapter->dev, "max6650: I2C bus doesn't support " 538 dev_dbg(&adapter->dev, "max6650: I2C bus doesn't support "
@@ -542,23 +540,7 @@ static int max6650_detect(struct i2c_client *client, int kind,
542 return -ENODEV; 540 return -ENODEV;
543 } 541 }
544 542
545 /* 543 if (((i2c_smbus_read_byte_data(client, MAX6650_REG_CONFIG) & 0xC0)
546 * Now we do the remaining detection. A negative kind means that
547 * the driver was loaded with no force parameter (default), so we
548 * must both detect and identify the chip (actually there is only
549 * one possible kind of chip for now, max6650). A zero kind means that
550 * the driver was loaded with the force parameter, the detection
551 * step shall be skipped. A positive kind means that the driver
552 * was loaded with the force parameter and a given kind of chip is
553 * requested, so both the detection and the identification steps
554 * are skipped.
555 *
556 * Currently I can find no way to distinguish between a MAX6650 and
557 * a MAX6651. This driver has only been tried on the former.
558 */
559
560 if ((kind < 0) &&
561 ( (i2c_smbus_read_byte_data(client, MAX6650_REG_CONFIG) & 0xC0)
562 ||(i2c_smbus_read_byte_data(client, MAX6650_REG_GPIO_STAT) & 0xE0) 544 ||(i2c_smbus_read_byte_data(client, MAX6650_REG_GPIO_STAT) & 0xE0)
563 ||(i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM_EN) & 0xE0) 545 ||(i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM_EN) & 0xE0)
564 ||(i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM) & 0xE0) 546 ||(i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM) & 0xE0)
diff --git a/drivers/hwmon/mc13783-adc.c b/drivers/hwmon/mc13783-adc.c
new file mode 100644
index 000000000000..ce3c7bc81814
--- /dev/null
+++ b/drivers/hwmon/mc13783-adc.c
@@ -0,0 +1,237 @@
1/*
2 * Driver for the Freescale Semiconductor MC13783 adc.
3 *
4 * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
5 * Copyright (C) 2009 Sascha Hauer, Pengutronix
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
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 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 51
18 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <linux/mfd/mc13783-private.h>
22#include <linux/platform_device.h>
23#include <linux/hwmon-sysfs.h>
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/hwmon.h>
27#include <linux/slab.h>
28#include <linux/init.h>
29#include <linux/err.h>
30
31#define MC13783_ADC_NAME "mc13783-adc"
32
33struct mc13783_adc_priv {
34 struct mc13783 *mc13783;
35 struct device *hwmon_dev;
36};
37
38static ssize_t mc13783_adc_show_name(struct device *dev, struct device_attribute
39 *devattr, char *buf)
40{
41 return sprintf(buf, "mc13783_adc\n");
42}
43
44static int mc13783_adc_read(struct device *dev,
45 struct device_attribute *devattr, unsigned int *val)
46{
47 struct platform_device *pdev = to_platform_device(dev);
48 struct mc13783_adc_priv *priv = platform_get_drvdata(pdev);
49 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
50 unsigned int channel = attr->index;
51 unsigned int sample[4];
52 int ret;
53
54 ret = mc13783_adc_do_conversion(priv->mc13783,
55 MC13783_ADC_MODE_MULT_CHAN,
56 channel, sample);
57 if (ret)
58 return ret;
59
60 channel &= 0x7;
61
62 *val = (sample[channel % 4] >> (channel > 3 ? 14 : 2)) & 0x3ff;
63
64 return 0;
65}
66
67static ssize_t mc13783_adc_read_bp(struct device *dev,
68 struct device_attribute *devattr, char *buf)
69{
70 unsigned val;
71 int ret = mc13783_adc_read(dev, devattr, &val);
72
73 if (ret)
74 return ret;
75
76 /*
77 * BP (channel 2) reports with offset 2.4V to the actual value to fit
78 * the input range of the ADC. unit = 2.25mV = 9/4 mV.
79 */
80 val = DIV_ROUND_CLOSEST(val * 9, 4) + 2400;
81
82 return sprintf(buf, "%u\n", val);
83}
84
85static ssize_t mc13783_adc_read_gp(struct device *dev,
86 struct device_attribute *devattr, char *buf)
87{
88 unsigned val;
89 int ret = mc13783_adc_read(dev, devattr, &val);
90
91 if (ret)
92 return ret;
93
94 /*
95 * input range is [0, 2.3V], val has 10 bits, so each bit
96 * is worth 9/4 mV.
97 */
98 val = DIV_ROUND_CLOSEST(val * 9, 4);
99
100 return sprintf(buf, "%u\n", val);
101}
102
103static DEVICE_ATTR(name, S_IRUGO, mc13783_adc_show_name, NULL);
104static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, mc13783_adc_read_bp, NULL, 2);
105static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, mc13783_adc_read_gp, NULL, 5);
106static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, mc13783_adc_read_gp, NULL, 6);
107static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, mc13783_adc_read_gp, NULL, 7);
108static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, mc13783_adc_read_gp, NULL, 8);
109static SENSOR_DEVICE_ATTR(in9_input, S_IRUGO, mc13783_adc_read_gp, NULL, 9);
110static SENSOR_DEVICE_ATTR(in10_input, S_IRUGO, mc13783_adc_read_gp, NULL, 10);
111static SENSOR_DEVICE_ATTR(in11_input, S_IRUGO, mc13783_adc_read_gp, NULL, 11);
112static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, mc13783_adc_read_gp, NULL, 12);
113static SENSOR_DEVICE_ATTR(in13_input, S_IRUGO, mc13783_adc_read_gp, NULL, 13);
114static SENSOR_DEVICE_ATTR(in14_input, S_IRUGO, mc13783_adc_read_gp, NULL, 14);
115static SENSOR_DEVICE_ATTR(in15_input, S_IRUGO, mc13783_adc_read_gp, NULL, 15);
116
117static struct attribute *mc13783_attr[] = {
118 &dev_attr_name.attr,
119 &sensor_dev_attr_in2_input.dev_attr.attr,
120 &sensor_dev_attr_in5_input.dev_attr.attr,
121 &sensor_dev_attr_in6_input.dev_attr.attr,
122 &sensor_dev_attr_in7_input.dev_attr.attr,
123 &sensor_dev_attr_in8_input.dev_attr.attr,
124 &sensor_dev_attr_in9_input.dev_attr.attr,
125 &sensor_dev_attr_in10_input.dev_attr.attr,
126 &sensor_dev_attr_in11_input.dev_attr.attr,
127 NULL
128};
129
130static const struct attribute_group mc13783_group = {
131 .attrs = mc13783_attr,
132};
133
134/* last four channels may be occupied by the touchscreen */
135static struct attribute *mc13783_attr_ts[] = {
136 &sensor_dev_attr_in12_input.dev_attr.attr,
137 &sensor_dev_attr_in13_input.dev_attr.attr,
138 &sensor_dev_attr_in14_input.dev_attr.attr,
139 &sensor_dev_attr_in15_input.dev_attr.attr,
140 NULL
141};
142
143static const struct attribute_group mc13783_group_ts = {
144 .attrs = mc13783_attr_ts,
145};
146
147static int __init mc13783_adc_probe(struct platform_device *pdev)
148{
149 struct mc13783_adc_priv *priv;
150 int ret;
151
152 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
153 if (!priv)
154 return -ENOMEM;
155
156 priv->mc13783 = dev_get_drvdata(pdev->dev.parent);
157
158 platform_set_drvdata(pdev, priv);
159
160 /* Register sysfs hooks */
161 ret = sysfs_create_group(&pdev->dev.kobj, &mc13783_group);
162 if (ret)
163 goto out_err_create1;
164
165 if (!(priv->mc13783->flags & MC13783_USE_TOUCHSCREEN))
166 ret = sysfs_create_group(&pdev->dev.kobj, &mc13783_group_ts);
167 if (ret)
168 goto out_err_create2;
169
170 priv->hwmon_dev = hwmon_device_register(&pdev->dev);
171 if (IS_ERR(priv->hwmon_dev)) {
172 ret = PTR_ERR(priv->hwmon_dev);
173 dev_err(&pdev->dev,
174 "hwmon_device_register failed with %d.\n", ret);
175 goto out_err_register;
176 }
177
178
179 return 0;
180
181out_err_register:
182
183 if (!(priv->mc13783->flags & MC13783_USE_TOUCHSCREEN))
184 sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_ts);
185out_err_create2:
186
187 sysfs_remove_group(&pdev->dev.kobj, &mc13783_group);
188out_err_create1:
189
190 platform_set_drvdata(pdev, NULL);
191 kfree(priv);
192
193 return ret;
194}
195
196static int __devexit mc13783_adc_remove(struct platform_device *pdev)
197{
198 struct mc13783_adc_priv *priv = platform_get_drvdata(pdev);
199
200 hwmon_device_unregister(priv->hwmon_dev);
201
202 if (!(priv->mc13783->flags & MC13783_USE_TOUCHSCREEN))
203 sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_ts);
204
205 sysfs_remove_group(&pdev->dev.kobj, &mc13783_group);
206
207 platform_set_drvdata(pdev, NULL);
208 kfree(priv);
209
210 return 0;
211}
212
213static struct platform_driver mc13783_adc_driver = {
214 .remove = __devexit_p(mc13783_adc_remove),
215 .driver = {
216 .owner = THIS_MODULE,
217 .name = MC13783_ADC_NAME,
218 },
219};
220
221static int __init mc13783_adc_init(void)
222{
223 return platform_driver_probe(&mc13783_adc_driver, mc13783_adc_probe);
224}
225
226static void __exit mc13783_adc_exit(void)
227{
228 platform_driver_unregister(&mc13783_adc_driver);
229}
230
231module_init(mc13783_adc_init);
232module_exit(mc13783_adc_exit);
233
234MODULE_DESCRIPTION("MC13783 ADC driver");
235MODULE_AUTHOR("Luotao Fu <l.fu@pengutronix.de>");
236MODULE_LICENSE("GPL");
237MODULE_ALIAS("platform:" MC13783_ADC_NAME);
diff --git a/drivers/hwmon/pcf8591.c b/drivers/hwmon/pcf8591.c
index 1d7ffebd679d..d44787949851 100644
--- a/drivers/hwmon/pcf8591.c
+++ b/drivers/hwmon/pcf8591.c
@@ -29,7 +29,6 @@ static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
29 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; 29 0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
30 30
31/* Insmod parameters */ 31/* Insmod parameters */
32I2C_CLIENT_INSMOD_1(pcf8591);
33 32
34static int input_mode; 33static int input_mode;
35module_param(input_mode, int, 0); 34module_param(input_mode, int, 0);
@@ -169,7 +168,7 @@ static const struct attribute_group pcf8591_attr_group_opt = {
169 */ 168 */
170 169
171/* Return 0 if detection is successful, -ENODEV otherwise */ 170/* Return 0 if detection is successful, -ENODEV otherwise */
172static int pcf8591_detect(struct i2c_client *client, int kind, 171static int pcf8591_detect(struct i2c_client *client,
173 struct i2c_board_info *info) 172 struct i2c_board_info *info)
174{ 173{
175 struct i2c_adapter *adapter = client->adapter; 174 struct i2c_adapter *adapter = client->adapter;
@@ -299,7 +298,7 @@ static struct i2c_driver pcf8591_driver = {
299 298
300 .class = I2C_CLASS_HWMON, /* Nearest choice */ 299 .class = I2C_CLASS_HWMON, /* Nearest choice */
301 .detect = pcf8591_detect, 300 .detect = pcf8591_detect,
302 .address_data = &addr_data, 301 .address_list = normal_i2c,
303}; 302};
304 303
305static int __init pcf8591_init(void) 304static int __init pcf8591_init(void)
diff --git a/drivers/hwmon/s3c-hwmon.c b/drivers/hwmon/s3c-hwmon.c
index 71835412529f..3f3f9a47acfd 100644
--- a/drivers/hwmon/s3c-hwmon.c
+++ b/drivers/hwmon/s3c-hwmon.c
@@ -323,7 +323,7 @@ static int __devinit s3c_hwmon_probe(struct platform_device *dev)
323 } 323 }
324 324
325 for (i = 0; i < ARRAY_SIZE(pdata->in); i++) { 325 for (i = 0; i < ARRAY_SIZE(pdata->in); i++) {
326 struct s3c24xx_adc_hwmon_incfg *cfg = pdata->in[i]; 326 struct s3c_hwmon_chcfg *cfg = pdata->in[i];
327 327
328 if (!cfg) 328 if (!cfg)
329 continue; 329 continue;
@@ -333,7 +333,7 @@ static int __devinit s3c_hwmon_probe(struct platform_device *dev)
333 "channel %d multiplier too large\n", 333 "channel %d multiplier too large\n",
334 i); 334 i);
335 335
336 if (cfg->divider == 0) { 336 if (cfg->div == 0) {
337 dev_err(&dev->dev, "channel %d divider zero\n", i); 337 dev_err(&dev->dev, "channel %d divider zero\n", i);
338 continue; 338 continue;
339 } 339 }
diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
index ebe38b680ee3..a610e7880fb3 100644
--- a/drivers/hwmon/sht15.c
+++ b/drivers/hwmon/sht15.c
@@ -36,6 +36,7 @@
36#include <linux/err.h> 36#include <linux/err.h>
37#include <linux/sht15.h> 37#include <linux/sht15.h>
38#include <linux/regulator/consumer.h> 38#include <linux/regulator/consumer.h>
39#include <linux/slab.h>
39#include <asm/atomic.h> 40#include <asm/atomic.h>
40 41
41#define SHT15_MEASURE_TEMP 3 42#define SHT15_MEASURE_TEMP 3
@@ -302,13 +303,13 @@ error_ret:
302 **/ 303 **/
303static inline int sht15_calc_temp(struct sht15_data *data) 304static inline int sht15_calc_temp(struct sht15_data *data)
304{ 305{
305 int d1 = 0; 306 int d1 = temppoints[0].d1;
306 int i; 307 int i;
307 308
308 for (i = 1; i < ARRAY_SIZE(temppoints) - 1; i++) 309 for (i = ARRAY_SIZE(temppoints) - 1; i > 0; i--)
309 /* Find pointer to interpolate */ 310 /* Find pointer to interpolate */
310 if (data->supply_uV > temppoints[i - 1].vdd) { 311 if (data->supply_uV > temppoints[i - 1].vdd) {
311 d1 = (data->supply_uV/1000 - temppoints[i - 1].vdd) 312 d1 = (data->supply_uV - temppoints[i - 1].vdd)
312 * (temppoints[i].d1 - temppoints[i - 1].d1) 313 * (temppoints[i].d1 - temppoints[i - 1].d1)
313 / (temppoints[i].vdd - temppoints[i - 1].vdd) 314 / (temppoints[i].vdd - temppoints[i - 1].vdd)
314 + temppoints[i - 1].d1; 315 + temppoints[i - 1].d1;
@@ -332,12 +333,12 @@ static inline int sht15_calc_humid(struct sht15_data *data)
332 333
333 const int c1 = -4; 334 const int c1 = -4;
334 const int c2 = 40500; /* x 10 ^ -6 */ 335 const int c2 = 40500; /* x 10 ^ -6 */
335 const int c3 = 2800; /* x10 ^ -9 */ 336 const int c3 = -2800; /* x10 ^ -9 */
336 337
337 RHlinear = c1*1000 338 RHlinear = c1*1000
338 + c2 * data->val_humid/1000 339 + c2 * data->val_humid/1000
339 + (data->val_humid * data->val_humid * c3)/1000000; 340 + (data->val_humid * data->val_humid * c3)/1000000;
340 return (temp - 25000) * (10000 + 800 * data->val_humid) 341 return (temp - 25000) * (10000 + 80 * data->val_humid)
341 / 1000000 + RHlinear; 342 / 1000000 + RHlinear;
342} 343}
343 344
@@ -541,7 +542,12 @@ static int __devinit sht15_probe(struct platform_device *pdev)
541/* If a regulator is available, query what the supply voltage actually is!*/ 542/* If a regulator is available, query what the supply voltage actually is!*/
542 data->reg = regulator_get(data->dev, "vcc"); 543 data->reg = regulator_get(data->dev, "vcc");
543 if (!IS_ERR(data->reg)) { 544 if (!IS_ERR(data->reg)) {
544 data->supply_uV = regulator_get_voltage(data->reg); 545 int voltage;
546
547 voltage = regulator_get_voltage(data->reg);
548 if (voltage)
549 data->supply_uV = voltage;
550
545 regulator_enable(data->reg); 551 regulator_enable(data->reg);
546 /* setup a notifier block to update this if another device 552 /* setup a notifier block to update this if another device
547 * causes the voltage to change */ 553 * causes the voltage to change */
diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c
index 12f2e7086560..79c2931e3008 100644
--- a/drivers/hwmon/sis5595.c
+++ b/drivers/hwmon/sis5595.c
@@ -697,7 +697,7 @@ static struct sis5595_data *sis5595_update_device(struct device *dev)
697 return data; 697 return data;
698} 698}
699 699
700static struct pci_device_id sis5595_pci_ids[] = { 700static const struct pci_device_id sis5595_pci_ids[] = {
701 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) }, 701 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) },
702 { 0, } 702 { 0, }
703}; 703};
diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c
index 8ad50fdba00d..8fa462f2b570 100644
--- a/drivers/hwmon/smsc47m1.c
+++ b/drivers/hwmon/smsc47m1.c
@@ -136,11 +136,11 @@ struct smsc47m1_data {
136 136
137struct smsc47m1_sio_data { 137struct smsc47m1_sio_data {
138 enum chips type; 138 enum chips type;
139 u8 activate; /* Remember initial device state */
139}; 140};
140 141
141 142
142static int smsc47m1_probe(struct platform_device *pdev); 143static int __exit smsc47m1_remove(struct platform_device *pdev);
143static int __devexit smsc47m1_remove(struct platform_device *pdev);
144static struct smsc47m1_data *smsc47m1_update_device(struct device *dev, 144static struct smsc47m1_data *smsc47m1_update_device(struct device *dev,
145 int init); 145 int init);
146 146
@@ -160,8 +160,7 @@ static struct platform_driver smsc47m1_driver = {
160 .owner = THIS_MODULE, 160 .owner = THIS_MODULE,
161 .name = DRVNAME, 161 .name = DRVNAME,
162 }, 162 },
163 .probe = smsc47m1_probe, 163 .remove = __exit_p(smsc47m1_remove),
164 .remove = __devexit_p(smsc47m1_remove),
165}; 164};
166 165
167static ssize_t get_fan(struct device *dev, struct device_attribute 166static ssize_t get_fan(struct device *dev, struct device_attribute
@@ -470,24 +469,126 @@ static int __init smsc47m1_find(unsigned short *addr,
470 superio_select(); 469 superio_select();
471 *addr = (superio_inb(SUPERIO_REG_BASE) << 8) 470 *addr = (superio_inb(SUPERIO_REG_BASE) << 8)
472 | superio_inb(SUPERIO_REG_BASE + 1); 471 | superio_inb(SUPERIO_REG_BASE + 1);
473 val = superio_inb(SUPERIO_REG_ACT); 472 if (*addr == 0) {
474 if (*addr == 0 || (val & 0x01) == 0) { 473 pr_info(DRVNAME ": Device address not set, will not use\n");
475 pr_info(DRVNAME ": Device is disabled, will not use\n");
476 superio_exit(); 474 superio_exit();
477 return -ENODEV; 475 return -ENODEV;
478 } 476 }
479 477
478 /* Enable only if address is set (needed at least on the
479 * Compaq Presario S4000NX) */
480 sio_data->activate = superio_inb(SUPERIO_REG_ACT);
481 if ((sio_data->activate & 0x01) == 0) {
482 pr_info(DRVNAME ": Enabling device\n");
483 superio_outb(SUPERIO_REG_ACT, sio_data->activate | 0x01);
484 }
485
480 superio_exit(); 486 superio_exit();
481 return 0; 487 return 0;
482} 488}
483 489
484static int __devinit smsc47m1_probe(struct platform_device *pdev) 490/* Restore device to its initial state */
491static void smsc47m1_restore(const struct smsc47m1_sio_data *sio_data)
492{
493 if ((sio_data->activate & 0x01) == 0) {
494 superio_enter();
495 superio_select();
496
497 pr_info(DRVNAME ": Disabling device\n");
498 superio_outb(SUPERIO_REG_ACT, sio_data->activate);
499
500 superio_exit();
501 }
502}
503
504#define CHECK 1
505#define REQUEST 2
506#define RELEASE 3
507
508/*
509 * This function can be used to:
510 * - test for resource conflicts with ACPI
511 * - request the resources
512 * - release the resources
513 * We only allocate the I/O ports we really need, to minimize the risk of
514 * conflicts with ACPI or with other drivers.
515 */
516static int smsc47m1_handle_resources(unsigned short address, enum chips type,
517 int action, struct device *dev)
518{
519 static const u8 ports_m1[] = {
520 /* register, region length */
521 0x04, 1,
522 0x33, 4,
523 0x56, 7,
524 };
525
526 static const u8 ports_m2[] = {
527 /* register, region length */
528 0x04, 1,
529 0x09, 1,
530 0x2c, 2,
531 0x35, 4,
532 0x56, 7,
533 0x69, 4,
534 };
535
536 int i, ports_size, err;
537 const u8 *ports;
538
539 switch (type) {
540 case smsc47m1:
541 default:
542 ports = ports_m1;
543 ports_size = ARRAY_SIZE(ports_m1);
544 break;
545 case smsc47m2:
546 ports = ports_m2;
547 ports_size = ARRAY_SIZE(ports_m2);
548 break;
549 }
550
551 for (i = 0; i + 1 < ports_size; i += 2) {
552 unsigned short start = address + ports[i];
553 unsigned short len = ports[i + 1];
554
555 switch (action) {
556 case CHECK:
557 /* Only check for conflicts */
558 err = acpi_check_region(start, len, DRVNAME);
559 if (err)
560 return err;
561 break;
562 case REQUEST:
563 /* Request the resources */
564 if (!request_region(start, len, DRVNAME)) {
565 dev_err(dev, "Region 0x%hx-0x%hx already in "
566 "use!\n", start, start + len);
567
568 /* Undo all requests */
569 for (i -= 2; i >= 0; i -= 2)
570 release_region(address + ports[i],
571 ports[i + 1]);
572 return -EBUSY;
573 }
574 break;
575 case RELEASE:
576 /* Release the resources */
577 release_region(start, len);
578 break;
579 }
580 }
581
582 return 0;
583}
584
585static int __init smsc47m1_probe(struct platform_device *pdev)
485{ 586{
486 struct device *dev = &pdev->dev; 587 struct device *dev = &pdev->dev;
487 struct smsc47m1_sio_data *sio_data = dev->platform_data; 588 struct smsc47m1_sio_data *sio_data = dev->platform_data;
488 struct smsc47m1_data *data; 589 struct smsc47m1_data *data;
489 struct resource *res; 590 struct resource *res;
490 int err = 0; 591 int err;
491 int fan1, fan2, fan3, pwm1, pwm2, pwm3; 592 int fan1, fan2, fan3, pwm1, pwm2, pwm3;
492 593
493 static const char *names[] = { 594 static const char *names[] = {
@@ -496,12 +597,10 @@ static int __devinit smsc47m1_probe(struct platform_device *pdev)
496 }; 597 };
497 598
498 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 599 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
499 if (!request_region(res->start, SMSC_EXTENT, DRVNAME)) { 600 err = smsc47m1_handle_resources(res->start, sio_data->type,
500 dev_err(dev, "Region 0x%lx-0x%lx already in use!\n", 601 REQUEST, dev);
501 (unsigned long)res->start, 602 if (err < 0)
502 (unsigned long)res->end); 603 return err;
503 return -EBUSY;
504 }
505 604
506 if (!(data = kzalloc(sizeof(struct smsc47m1_data), GFP_KERNEL))) { 605 if (!(data = kzalloc(sizeof(struct smsc47m1_data), GFP_KERNEL))) {
507 err = -ENOMEM; 606 err = -ENOMEM;
@@ -637,11 +736,11 @@ error_free:
637 platform_set_drvdata(pdev, NULL); 736 platform_set_drvdata(pdev, NULL);
638 kfree(data); 737 kfree(data);
639error_release: 738error_release:
640 release_region(res->start, SMSC_EXTENT); 739 smsc47m1_handle_resources(res->start, sio_data->type, RELEASE, dev);
641 return err; 740 return err;
642} 741}
643 742
644static int __devexit smsc47m1_remove(struct platform_device *pdev) 743static int __exit smsc47m1_remove(struct platform_device *pdev)
645{ 744{
646 struct smsc47m1_data *data = platform_get_drvdata(pdev); 745 struct smsc47m1_data *data = platform_get_drvdata(pdev);
647 struct resource *res; 746 struct resource *res;
@@ -650,7 +749,7 @@ static int __devexit smsc47m1_remove(struct platform_device *pdev)
650 sysfs_remove_group(&pdev->dev.kobj, &smsc47m1_group); 749 sysfs_remove_group(&pdev->dev.kobj, &smsc47m1_group);
651 750
652 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 751 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
653 release_region(res->start, SMSC_EXTENT); 752 smsc47m1_handle_resources(res->start, data->type, RELEASE, &pdev->dev);
654 platform_set_drvdata(pdev, NULL); 753 platform_set_drvdata(pdev, NULL);
655 kfree(data); 754 kfree(data);
656 755
@@ -717,7 +816,7 @@ static int __init smsc47m1_device_add(unsigned short address,
717 }; 816 };
718 int err; 817 int err;
719 818
720 err = acpi_check_resource_conflict(&res); 819 err = smsc47m1_handle_resources(address, sio_data->type, CHECK, NULL);
721 if (err) 820 if (err)
722 goto exit; 821 goto exit;
723 822
@@ -766,27 +865,29 @@ static int __init sm_smsc47m1_init(void)
766 if (smsc47m1_find(&address, &sio_data)) 865 if (smsc47m1_find(&address, &sio_data))
767 return -ENODEV; 866 return -ENODEV;
768 867
769 err = platform_driver_register(&smsc47m1_driver); 868 /* Sets global pdev as a side effect */
869 err = smsc47m1_device_add(address, &sio_data);
770 if (err) 870 if (err)
771 goto exit; 871 goto exit;
772 872
773 /* Sets global pdev as a side effect */ 873 err = platform_driver_probe(&smsc47m1_driver, smsc47m1_probe);
774 err = smsc47m1_device_add(address, &sio_data);
775 if (err) 874 if (err)
776 goto exit_driver; 875 goto exit_device;
777 876
778 return 0; 877 return 0;
779 878
780exit_driver: 879exit_device:
781 platform_driver_unregister(&smsc47m1_driver); 880 platform_device_unregister(pdev);
881 smsc47m1_restore(&sio_data);
782exit: 882exit:
783 return err; 883 return err;
784} 884}
785 885
786static void __exit sm_smsc47m1_exit(void) 886static void __exit sm_smsc47m1_exit(void)
787{ 887{
788 platform_device_unregister(pdev);
789 platform_driver_unregister(&smsc47m1_driver); 888 platform_driver_unregister(&smsc47m1_driver);
889 smsc47m1_restore(pdev->dev.platform_data);
890 platform_device_unregister(pdev);
790} 891}
791 892
792MODULE_AUTHOR("Mark D. Studebaker <mdsxyz123@yahoo.com>"); 893MODULE_AUTHOR("Mark D. Studebaker <mdsxyz123@yahoo.com>");
diff --git a/drivers/hwmon/smsc47m192.c b/drivers/hwmon/smsc47m192.c
index 8bb5cb532d4d..40b26673d87f 100644
--- a/drivers/hwmon/smsc47m192.c
+++ b/drivers/hwmon/smsc47m192.c
@@ -36,9 +36,6 @@
36/* Addresses to scan */ 36/* Addresses to scan */
37static const unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; 37static const unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
38 38
39/* Insmod parameters */
40I2C_CLIENT_INSMOD_1(smsc47m192);
41
42/* SMSC47M192 registers */ 39/* SMSC47M192 registers */
43#define SMSC47M192_REG_IN(nr) ((nr)<6 ? (0x20 + (nr)) : \ 40#define SMSC47M192_REG_IN(nr) ((nr)<6 ? (0x20 + (nr)) : \
44 (0x50 + (nr) - 6)) 41 (0x50 + (nr) - 6))
@@ -115,13 +112,13 @@ struct smsc47m192_data {
115 112
116static int smsc47m192_probe(struct i2c_client *client, 113static int smsc47m192_probe(struct i2c_client *client,
117 const struct i2c_device_id *id); 114 const struct i2c_device_id *id);
118static int smsc47m192_detect(struct i2c_client *client, int kind, 115static int smsc47m192_detect(struct i2c_client *client,
119 struct i2c_board_info *info); 116 struct i2c_board_info *info);
120static int smsc47m192_remove(struct i2c_client *client); 117static int smsc47m192_remove(struct i2c_client *client);
121static struct smsc47m192_data *smsc47m192_update_device(struct device *dev); 118static struct smsc47m192_data *smsc47m192_update_device(struct device *dev);
122 119
123static const struct i2c_device_id smsc47m192_id[] = { 120static const struct i2c_device_id smsc47m192_id[] = {
124 { "smsc47m192", smsc47m192 }, 121 { "smsc47m192", 0 },
125 { } 122 { }
126}; 123};
127MODULE_DEVICE_TABLE(i2c, smsc47m192_id); 124MODULE_DEVICE_TABLE(i2c, smsc47m192_id);
@@ -135,7 +132,7 @@ static struct i2c_driver smsc47m192_driver = {
135 .remove = smsc47m192_remove, 132 .remove = smsc47m192_remove,
136 .id_table = smsc47m192_id, 133 .id_table = smsc47m192_id,
137 .detect = smsc47m192_detect, 134 .detect = smsc47m192_detect,
138 .address_data = &addr_data, 135 .address_list = normal_i2c,
139}; 136};
140 137
141/* Voltages */ 138/* Voltages */
@@ -481,7 +478,7 @@ static void smsc47m192_init_client(struct i2c_client *client)
481} 478}
482 479
483/* Return 0 if detection is successful, -ENODEV otherwise */ 480/* Return 0 if detection is successful, -ENODEV otherwise */
484static int smsc47m192_detect(struct i2c_client *client, int kind, 481static int smsc47m192_detect(struct i2c_client *client,
485 struct i2c_board_info *info) 482 struct i2c_board_info *info)
486{ 483{
487 struct i2c_adapter *adapter = client->adapter; 484 struct i2c_adapter *adapter = client->adapter;
@@ -491,24 +488,22 @@ static int smsc47m192_detect(struct i2c_client *client, int kind,
491 return -ENODEV; 488 return -ENODEV;
492 489
493 /* Detection criteria from sensors_detect script */ 490 /* Detection criteria from sensors_detect script */
494 if (kind < 0) { 491 version = i2c_smbus_read_byte_data(client, SMSC47M192_REG_VERSION);
495 if (i2c_smbus_read_byte_data(client, 492 if (i2c_smbus_read_byte_data(client,
496 SMSC47M192_REG_COMPANY_ID) == 0x55 493 SMSC47M192_REG_COMPANY_ID) == 0x55
497 && ((version = i2c_smbus_read_byte_data(client, 494 && (version & 0xf0) == 0x20
498 SMSC47M192_REG_VERSION)) & 0xf0) == 0x20 495 && (i2c_smbus_read_byte_data(client,
499 && (i2c_smbus_read_byte_data(client,
500 SMSC47M192_REG_VID) & 0x70) == 0x00 496 SMSC47M192_REG_VID) & 0x70) == 0x00
501 && (i2c_smbus_read_byte_data(client, 497 && (i2c_smbus_read_byte_data(client,
502 SMSC47M192_REG_VID4) & 0xfe) == 0x80) { 498 SMSC47M192_REG_VID4) & 0xfe) == 0x80) {
503 dev_info(&adapter->dev, 499 dev_info(&adapter->dev,
504 "found SMSC47M192 or compatible, " 500 "found SMSC47M192 or compatible, "
505 "version 2, stepping A%d\n", version & 0x0f); 501 "version 2, stepping A%d\n", version & 0x0f);
506 } else { 502 } else {
507 dev_dbg(&adapter->dev, 503 dev_dbg(&adapter->dev,
508 "SMSC47M192 detection failed at 0x%02x\n", 504 "SMSC47M192 detection failed at 0x%02x\n",
509 client->addr); 505 client->addr);
510 return -ENODEV; 506 return -ENODEV;
511 }
512 } 507 }
513 508
514 strlcpy(info->type, "smsc47m192", I2C_NAME_SIZE); 509 strlcpy(info->type, "smsc47m192", I2C_NAME_SIZE);
diff --git a/drivers/hwmon/thmc50.c b/drivers/hwmon/thmc50.c
index 7d97431e132f..7dfb4dec4c5f 100644
--- a/drivers/hwmon/thmc50.c
+++ b/drivers/hwmon/thmc50.c
@@ -35,8 +35,12 @@ MODULE_LICENSE("GPL");
35static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; 35static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
36 36
37/* Insmod parameters */ 37/* Insmod parameters */
38I2C_CLIENT_INSMOD_2(thmc50, adm1022); 38enum chips { thmc50, adm1022 };
39I2C_CLIENT_MODULE_PARM(adm1022_temp3, "List of adapter,address pairs " 39
40static unsigned short adm1022_temp3[16];
41static unsigned int adm1022_temp3_num;
42module_param_array(adm1022_temp3, ushort, &adm1022_temp3_num, 0);
43MODULE_PARM_DESC(adm1022_temp3, "List of adapter,address pairs "
40 "to enable 3rd temperature (ADM1022 only)"); 44 "to enable 3rd temperature (ADM1022 only)");
41 45
42/* Many THMC50 constants specified below */ 46/* Many THMC50 constants specified below */
@@ -80,7 +84,7 @@ struct thmc50_data {
80 u8 alarms; 84 u8 alarms;
81}; 85};
82 86
83static int thmc50_detect(struct i2c_client *client, int kind, 87static int thmc50_detect(struct i2c_client *client,
84 struct i2c_board_info *info); 88 struct i2c_board_info *info);
85static int thmc50_probe(struct i2c_client *client, 89static int thmc50_probe(struct i2c_client *client,
86 const struct i2c_device_id *id); 90 const struct i2c_device_id *id);
@@ -104,7 +108,7 @@ static struct i2c_driver thmc50_driver = {
104 .remove = thmc50_remove, 108 .remove = thmc50_remove,
105 .id_table = thmc50_id, 109 .id_table = thmc50_id,
106 .detect = thmc50_detect, 110 .detect = thmc50_detect,
107 .address_data = &addr_data, 111 .address_list = normal_i2c,
108}; 112};
109 113
110static ssize_t show_analog_out(struct device *dev, 114static ssize_t show_analog_out(struct device *dev,
@@ -282,14 +286,13 @@ static const struct attribute_group temp3_group = {
282}; 286};
283 287
284/* Return 0 if detection is successful, -ENODEV otherwise */ 288/* Return 0 if detection is successful, -ENODEV otherwise */
285static int thmc50_detect(struct i2c_client *client, int kind, 289static int thmc50_detect(struct i2c_client *client,
286 struct i2c_board_info *info) 290 struct i2c_board_info *info)
287{ 291{
288 unsigned company; 292 unsigned company;
289 unsigned revision; 293 unsigned revision;
290 unsigned config; 294 unsigned config;
291 struct i2c_adapter *adapter = client->adapter; 295 struct i2c_adapter *adapter = client->adapter;
292 int err = 0;
293 const char *type_name; 296 const char *type_name;
294 297
295 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 298 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
@@ -301,31 +304,13 @@ static int thmc50_detect(struct i2c_client *client, int kind,
301 pr_debug("thmc50: Probing for THMC50 at 0x%2X on bus %d\n", 304 pr_debug("thmc50: Probing for THMC50 at 0x%2X on bus %d\n",
302 client->addr, i2c_adapter_id(client->adapter)); 305 client->addr, i2c_adapter_id(client->adapter));
303 306
304 /* Now, we do the remaining detection. */
305 company = i2c_smbus_read_byte_data(client, THMC50_REG_COMPANY_ID); 307 company = i2c_smbus_read_byte_data(client, THMC50_REG_COMPANY_ID);
306 revision = i2c_smbus_read_byte_data(client, THMC50_REG_DIE_CODE); 308 revision = i2c_smbus_read_byte_data(client, THMC50_REG_DIE_CODE);
307 config = i2c_smbus_read_byte_data(client, THMC50_REG_CONF); 309 config = i2c_smbus_read_byte_data(client, THMC50_REG_CONF);
310 if (revision < 0xc0 || (config & 0x10))
311 return -ENODEV;
308 312
309 if (kind == 0) 313 if (company == 0x41) {
310 kind = thmc50;
311 else if (kind < 0) {
312 err = -ENODEV;
313 if (revision >= 0xc0 && ((config & 0x10) == 0)) {
314 if (company == 0x49) {
315 kind = thmc50;
316 err = 0;
317 } else if (company == 0x41) {
318 kind = adm1022;
319 err = 0;
320 }
321 }
322 }
323 if (err == -ENODEV) {
324 pr_debug("thmc50: Detection of THMC50/ADM1022 failed\n");
325 return err;
326 }
327
328 if (kind == adm1022) {
329 int id = i2c_adapter_id(client->adapter); 314 int id = i2c_adapter_id(client->adapter);
330 int i; 315 int i;
331 316
@@ -340,9 +325,13 @@ static int thmc50_detect(struct i2c_client *client, int kind,
340 config); 325 config);
341 break; 326 break;
342 } 327 }
343 } else { 328 } else if (company == 0x49) {
344 type_name = "thmc50"; 329 type_name = "thmc50";
330 } else {
331 pr_debug("thmc50: Detection of THMC50/ADM1022 failed\n");
332 return -ENODEV;
345 } 333 }
334
346 pr_debug("thmc50: Detected %s (version %x, revision %x)\n", 335 pr_debug("thmc50: Detected %s (version %x, revision %x)\n",
347 type_name, (revision >> 4) - 0xc, revision & 0xf); 336 type_name, (revision >> 4) - 0xc, revision & 0xf);
348 337
diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c
index 7b34f2cd08bb..d14a1af9f550 100644
--- a/drivers/hwmon/tmp401.c
+++ b/drivers/hwmon/tmp401.c
@@ -42,8 +42,7 @@
42/* Addresses to scan */ 42/* Addresses to scan */
43static const unsigned short normal_i2c[] = { 0x4c, I2C_CLIENT_END }; 43static const unsigned short normal_i2c[] = { 0x4c, I2C_CLIENT_END };
44 44
45/* Insmod parameters */ 45enum chips { tmp401, tmp411 };
46I2C_CLIENT_INSMOD_2(tmp401, tmp411);
47 46
48/* 47/*
49 * The TMP401 registers, note some registers have different addresses for 48 * The TMP401 registers, note some registers have different addresses for
@@ -98,7 +97,7 @@ static const u8 TMP411_TEMP_HIGHEST_LSB[2] = { 0x33, 0x37 };
98 97
99static int tmp401_probe(struct i2c_client *client, 98static int tmp401_probe(struct i2c_client *client,
100 const struct i2c_device_id *id); 99 const struct i2c_device_id *id);
101static int tmp401_detect(struct i2c_client *client, int kind, 100static int tmp401_detect(struct i2c_client *client,
102 struct i2c_board_info *info); 101 struct i2c_board_info *info);
103static int tmp401_remove(struct i2c_client *client); 102static int tmp401_remove(struct i2c_client *client);
104static struct tmp401_data *tmp401_update_device(struct device *dev); 103static struct tmp401_data *tmp401_update_device(struct device *dev);
@@ -123,7 +122,7 @@ static struct i2c_driver tmp401_driver = {
123 .remove = tmp401_remove, 122 .remove = tmp401_remove,
124 .id_table = tmp401_id, 123 .id_table = tmp401_id,
125 .detect = tmp401_detect, 124 .detect = tmp401_detect,
126 .address_data = &addr_data, 125 .address_list = normal_i2c,
127}; 126};
128 127
129/* 128/*
@@ -135,7 +134,7 @@ struct tmp401_data {
135 struct mutex update_lock; 134 struct mutex update_lock;
136 char valid; /* zero until following fields are valid */ 135 char valid; /* zero until following fields are valid */
137 unsigned long last_updated; /* in jiffies */ 136 unsigned long last_updated; /* in jiffies */
138 int kind; 137 enum chips kind;
139 138
140 /* register values */ 139 /* register values */
141 u8 status; 140 u8 status;
@@ -488,47 +487,44 @@ static void tmp401_init_client(struct i2c_client *client)
488 i2c_smbus_write_byte_data(client, TMP401_CONFIG_WRITE, config); 487 i2c_smbus_write_byte_data(client, TMP401_CONFIG_WRITE, config);
489} 488}
490 489
491static int tmp401_detect(struct i2c_client *client, int kind, 490static int tmp401_detect(struct i2c_client *client,
492 struct i2c_board_info *info) 491 struct i2c_board_info *info)
493{ 492{
493 enum chips kind;
494 struct i2c_adapter *adapter = client->adapter; 494 struct i2c_adapter *adapter = client->adapter;
495 u8 reg;
495 496
496 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 497 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
497 return -ENODEV; 498 return -ENODEV;
498 499
499 /* Detect and identify the chip */ 500 /* Detect and identify the chip */
500 if (kind <= 0) { 501 reg = i2c_smbus_read_byte_data(client, TMP401_MANUFACTURER_ID_REG);
501 u8 reg; 502 if (reg != TMP401_MANUFACTURER_ID)
502 503 return -ENODEV;
503 reg = i2c_smbus_read_byte_data(client,
504 TMP401_MANUFACTURER_ID_REG);
505 if (reg != TMP401_MANUFACTURER_ID)
506 return -ENODEV;
507
508 reg = i2c_smbus_read_byte_data(client, TMP401_DEVICE_ID_REG);
509
510 switch (reg) {
511 case TMP401_DEVICE_ID:
512 kind = tmp401;
513 break;
514 case TMP411_DEVICE_ID:
515 kind = tmp411;
516 break;
517 default:
518 return -ENODEV;
519 }
520 504
521 reg = i2c_smbus_read_byte_data(client, TMP401_CONFIG_READ); 505 reg = i2c_smbus_read_byte_data(client, TMP401_DEVICE_ID_REG);
522 if (reg & 0x1b)
523 return -ENODEV;
524 506
525 reg = i2c_smbus_read_byte_data(client, 507 switch (reg) {
526 TMP401_CONVERSION_RATE_READ); 508 case TMP401_DEVICE_ID:
527 /* Datasheet says: 0x1-0x6 */ 509 kind = tmp401;
528 if (reg > 15) 510 break;
529 return -ENODEV; 511 case TMP411_DEVICE_ID:
512 kind = tmp411;
513 break;
514 default:
515 return -ENODEV;
530 } 516 }
531 strlcpy(info->type, tmp401_id[kind - 1].name, I2C_NAME_SIZE); 517
518 reg = i2c_smbus_read_byte_data(client, TMP401_CONFIG_READ);
519 if (reg & 0x1b)
520 return -ENODEV;
521
522 reg = i2c_smbus_read_byte_data(client, TMP401_CONVERSION_RATE_READ);
523 /* Datasheet says: 0x1-0x6 */
524 if (reg > 15)
525 return -ENODEV;
526
527 strlcpy(info->type, tmp401_id[kind].name, I2C_NAME_SIZE);
532 528
533 return 0; 529 return 0;
534} 530}
@@ -576,8 +572,7 @@ static int tmp401_probe(struct i2c_client *client,
576 goto exit_remove; 572 goto exit_remove;
577 } 573 }
578 574
579 dev_info(&client->dev, "Detected TI %s chip\n", 575 dev_info(&client->dev, "Detected TI %s chip\n", names[data->kind]);
580 names[data->kind - 1]);
581 576
582 return 0; 577 return 0;
583 578
diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c
index 20924343431b..738c472ece27 100644
--- a/drivers/hwmon/tmp421.c
+++ b/drivers/hwmon/tmp421.c
@@ -39,8 +39,7 @@
39static unsigned short normal_i2c[] = { 0x2a, 0x4c, 0x4d, 0x4e, 0x4f, 39static unsigned short normal_i2c[] = { 0x2a, 0x4c, 0x4d, 0x4e, 0x4f,
40 I2C_CLIENT_END }; 40 I2C_CLIENT_END };
41 41
42/* Insmod parameters */ 42enum chips { tmp421, tmp422, tmp423 };
43I2C_CLIENT_INSMOD_3(tmp421, tmp422, tmp423);
44 43
45/* The TMP421 registers */ 44/* The TMP421 registers */
46#define TMP421_CONFIG_REG_1 0x09 45#define TMP421_CONFIG_REG_1 0x09
@@ -62,9 +61,9 @@ static const u8 TMP421_TEMP_LSB[4] = { 0x10, 0x11, 0x12, 0x13 };
62#define TMP423_DEVICE_ID 0x23 61#define TMP423_DEVICE_ID 0x23
63 62
64static const struct i2c_device_id tmp421_id[] = { 63static const struct i2c_device_id tmp421_id[] = {
65 { "tmp421", tmp421 }, 64 { "tmp421", 2 },
66 { "tmp422", tmp422 }, 65 { "tmp422", 3 },
67 { "tmp423", tmp423 }, 66 { "tmp423", 4 },
68 { } 67 { }
69}; 68};
70MODULE_DEVICE_TABLE(i2c, tmp421_id); 69MODULE_DEVICE_TABLE(i2c, tmp421_id);
@@ -74,21 +73,23 @@ struct tmp421_data {
74 struct mutex update_lock; 73 struct mutex update_lock;
75 char valid; 74 char valid;
76 unsigned long last_updated; 75 unsigned long last_updated;
77 int kind; 76 int channels;
78 u8 config; 77 u8 config;
79 s16 temp[4]; 78 s16 temp[4];
80}; 79};
81 80
82static int temp_from_s16(s16 reg) 81static int temp_from_s16(s16 reg)
83{ 82{
84 int temp = reg; 83 /* Mask out status bits */
84 int temp = reg & ~0xf;
85 85
86 return (temp * 1000 + 128) / 256; 86 return (temp * 1000 + 128) / 256;
87} 87}
88 88
89static int temp_from_u16(u16 reg) 89static int temp_from_u16(u16 reg)
90{ 90{
91 int temp = reg; 91 /* Mask out status bits */
92 int temp = reg & ~0xf;
92 93
93 /* Add offset for extended temperature range. */ 94 /* Add offset for extended temperature range. */
94 temp -= 64 * 256; 95 temp -= 64 * 256;
@@ -108,7 +109,7 @@ static struct tmp421_data *tmp421_update_device(struct device *dev)
108 data->config = i2c_smbus_read_byte_data(client, 109 data->config = i2c_smbus_read_byte_data(client,
109 TMP421_CONFIG_REG_1); 110 TMP421_CONFIG_REG_1);
110 111
111 for (i = 0; i <= data->kind; i++) { 112 for (i = 0; i < data->channels; i++) {
112 data->temp[i] = i2c_smbus_read_byte_data(client, 113 data->temp[i] = i2c_smbus_read_byte_data(client,
113 TMP421_TEMP_MSB[i]) << 8; 114 TMP421_TEMP_MSB[i]) << 8;
114 data->temp[i] |= i2c_smbus_read_byte_data(client, 115 data->temp[i] |= i2c_smbus_read_byte_data(client,
@@ -167,7 +168,7 @@ static mode_t tmp421_is_visible(struct kobject *kobj, struct attribute *a,
167 devattr = container_of(a, struct device_attribute, attr); 168 devattr = container_of(a, struct device_attribute, attr);
168 index = to_sensor_dev_attr(devattr)->index; 169 index = to_sensor_dev_attr(devattr)->index;
169 170
170 if (data->kind > index) 171 if (index < data->channels)
171 return a->mode; 172 return a->mode;
172 173
173 return 0; 174 return 0;
@@ -223,42 +224,39 @@ static int tmp421_init_client(struct i2c_client *client)
223 return 0; 224 return 0;
224} 225}
225 226
226static int tmp421_detect(struct i2c_client *client, int kind, 227static int tmp421_detect(struct i2c_client *client,
227 struct i2c_board_info *info) 228 struct i2c_board_info *info)
228{ 229{
230 enum chips kind;
229 struct i2c_adapter *adapter = client->adapter; 231 struct i2c_adapter *adapter = client->adapter;
230 const char *names[] = { "TMP421", "TMP422", "TMP423" }; 232 const char *names[] = { "TMP421", "TMP422", "TMP423" };
233 u8 reg;
231 234
232 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 235 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
233 return -ENODEV; 236 return -ENODEV;
234 237
235 if (kind <= 0) { 238 reg = i2c_smbus_read_byte_data(client, TMP421_MANUFACTURER_ID_REG);
236 u8 reg; 239 if (reg != TMP421_MANUFACTURER_ID)
237 240 return -ENODEV;
238 reg = i2c_smbus_read_byte_data(client, 241
239 TMP421_MANUFACTURER_ID_REG); 242 reg = i2c_smbus_read_byte_data(client, TMP421_DEVICE_ID_REG);
240 if (reg != TMP421_MANUFACTURER_ID) 243 switch (reg) {
241 return -ENODEV; 244 case TMP421_DEVICE_ID:
242 245 kind = tmp421;
243 reg = i2c_smbus_read_byte_data(client, 246 break;
244 TMP421_DEVICE_ID_REG); 247 case TMP422_DEVICE_ID:
245 switch (reg) { 248 kind = tmp422;
246 case TMP421_DEVICE_ID: 249 break;
247 kind = tmp421; 250 case TMP423_DEVICE_ID:
248 break; 251 kind = tmp423;
249 case TMP422_DEVICE_ID: 252 break;
250 kind = tmp422; 253 default:
251 break; 254 return -ENODEV;
252 case TMP423_DEVICE_ID:
253 kind = tmp423;
254 break;
255 default:
256 return -ENODEV;
257 }
258 } 255 }
259 strlcpy(info->type, tmp421_id[kind - 1].name, I2C_NAME_SIZE); 256
257 strlcpy(info->type, tmp421_id[kind].name, I2C_NAME_SIZE);
260 dev_info(&adapter->dev, "Detected TI %s chip at 0x%02x\n", 258 dev_info(&adapter->dev, "Detected TI %s chip at 0x%02x\n",
261 names[kind - 1], client->addr); 259 names[kind], client->addr);
262 260
263 return 0; 261 return 0;
264} 262}
@@ -275,7 +273,7 @@ static int tmp421_probe(struct i2c_client *client,
275 273
276 i2c_set_clientdata(client, data); 274 i2c_set_clientdata(client, data);
277 mutex_init(&data->update_lock); 275 mutex_init(&data->update_lock);
278 data->kind = id->driver_data; 276 data->channels = id->driver_data;
279 277
280 err = tmp421_init_client(client); 278 err = tmp421_init_client(client);
281 if (err) 279 if (err)
@@ -325,7 +323,7 @@ static struct i2c_driver tmp421_driver = {
325 .remove = tmp421_remove, 323 .remove = tmp421_remove,
326 .id_table = tmp421_id, 324 .id_table = tmp421_id,
327 .detect = tmp421_detect, 325 .detect = tmp421_detect,
328 .address_data = &addr_data, 326 .address_list = normal_i2c,
329}; 327};
330 328
331static int __init tmp421_init(void) 329static int __init tmp421_init(void)
diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
new file mode 100644
index 000000000000..7442cf754856
--- /dev/null
+++ b/drivers/hwmon/via-cputemp.c
@@ -0,0 +1,356 @@
1/*
2 * via-cputemp.c - Driver for VIA CPU core temperature monitoring
3 * Copyright (C) 2009 VIA Technologies, Inc.
4 *
5 * based on existing coretemp.c, which is
6 *
7 * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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., 51 Franklin Street, Fifth Floor, Boston, MA
21 * 02110-1301 USA.
22 */
23
24#include <linux/module.h>
25#include <linux/delay.h>
26#include <linux/init.h>
27#include <linux/slab.h>
28#include <linux/jiffies.h>
29#include <linux/hwmon.h>
30#include <linux/sysfs.h>
31#include <linux/hwmon-sysfs.h>
32#include <linux/err.h>
33#include <linux/mutex.h>
34#include <linux/list.h>
35#include <linux/platform_device.h>
36#include <linux/cpu.h>
37#include <asm/msr.h>
38#include <asm/processor.h>
39
40#define DRVNAME "via_cputemp"
41
42enum { SHOW_TEMP, SHOW_LABEL, SHOW_NAME } SHOW;
43
44/*
45 * Functions declaration
46 */
47
48struct via_cputemp_data {
49 struct device *hwmon_dev;
50 const char *name;
51 u32 id;
52 u32 msr;
53};
54
55/*
56 * Sysfs stuff
57 */
58
59static ssize_t show_name(struct device *dev, struct device_attribute
60 *devattr, char *buf)
61{
62 int ret;
63 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
64 struct via_cputemp_data *data = dev_get_drvdata(dev);
65
66 if (attr->index == SHOW_NAME)
67 ret = sprintf(buf, "%s\n", data->name);
68 else /* show label */
69 ret = sprintf(buf, "Core %d\n", data->id);
70 return ret;
71}
72
73static ssize_t show_temp(struct device *dev,
74 struct device_attribute *devattr, char *buf)
75{
76 struct via_cputemp_data *data = dev_get_drvdata(dev);
77 u32 eax, edx;
78 int err;
79
80 err = rdmsr_safe_on_cpu(data->id, data->msr, &eax, &edx);
81 if (err)
82 return -EAGAIN;
83
84 return sprintf(buf, "%lu\n", ((unsigned long)eax & 0xffffff) * 1000);
85}
86
87static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL,
88 SHOW_TEMP);
89static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, show_name, NULL, SHOW_LABEL);
90static SENSOR_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, SHOW_NAME);
91
92static struct attribute *via_cputemp_attributes[] = {
93 &sensor_dev_attr_name.dev_attr.attr,
94 &sensor_dev_attr_temp1_label.dev_attr.attr,
95 &sensor_dev_attr_temp1_input.dev_attr.attr,
96 NULL
97};
98
99static const struct attribute_group via_cputemp_group = {
100 .attrs = via_cputemp_attributes,
101};
102
103static int __devinit via_cputemp_probe(struct platform_device *pdev)
104{
105 struct via_cputemp_data *data;
106 struct cpuinfo_x86 *c = &cpu_data(pdev->id);
107 int err;
108 u32 eax, edx;
109
110 data = kzalloc(sizeof(struct via_cputemp_data), GFP_KERNEL);
111 if (!data) {
112 err = -ENOMEM;
113 dev_err(&pdev->dev, "Out of memory\n");
114 goto exit;
115 }
116
117 data->id = pdev->id;
118 data->name = "via_cputemp";
119
120 switch (c->x86_model) {
121 case 0xA:
122 /* C7 A */
123 case 0xD:
124 /* C7 D */
125 data->msr = 0x1169;
126 break;
127 case 0xF:
128 /* Nano */
129 data->msr = 0x1423;
130 break;
131 default:
132 err = -ENODEV;
133 goto exit_free;
134 }
135
136 /* test if we can access the TEMPERATURE MSR */
137 err = rdmsr_safe_on_cpu(data->id, data->msr, &eax, &edx);
138 if (err) {
139 dev_err(&pdev->dev,
140 "Unable to access TEMPERATURE MSR, giving up\n");
141 goto exit_free;
142 }
143
144 platform_set_drvdata(pdev, data);
145
146 err = sysfs_create_group(&pdev->dev.kobj, &via_cputemp_group);
147 if (err)
148 goto exit_free;
149
150 data->hwmon_dev = hwmon_device_register(&pdev->dev);
151 if (IS_ERR(data->hwmon_dev)) {
152 err = PTR_ERR(data->hwmon_dev);
153 dev_err(&pdev->dev, "Class registration failed (%d)\n",
154 err);
155 goto exit_remove;
156 }
157
158 return 0;
159
160exit_remove:
161 sysfs_remove_group(&pdev->dev.kobj, &via_cputemp_group);
162exit_free:
163 platform_set_drvdata(pdev, NULL);
164 kfree(data);
165exit:
166 return err;
167}
168
169static int __devexit via_cputemp_remove(struct platform_device *pdev)
170{
171 struct via_cputemp_data *data = platform_get_drvdata(pdev);
172
173 hwmon_device_unregister(data->hwmon_dev);
174 sysfs_remove_group(&pdev->dev.kobj, &via_cputemp_group);
175 platform_set_drvdata(pdev, NULL);
176 kfree(data);
177 return 0;
178}
179
180static struct platform_driver via_cputemp_driver = {
181 .driver = {
182 .owner = THIS_MODULE,
183 .name = DRVNAME,
184 },
185 .probe = via_cputemp_probe,
186 .remove = __devexit_p(via_cputemp_remove),
187};
188
189struct pdev_entry {
190 struct list_head list;
191 struct platform_device *pdev;
192 unsigned int cpu;
193};
194
195static LIST_HEAD(pdev_list);
196static DEFINE_MUTEX(pdev_list_mutex);
197
198static int __cpuinit via_cputemp_device_add(unsigned int cpu)
199{
200 int err;
201 struct platform_device *pdev;
202 struct pdev_entry *pdev_entry;
203
204 pdev = platform_device_alloc(DRVNAME, cpu);
205 if (!pdev) {
206 err = -ENOMEM;
207 printk(KERN_ERR DRVNAME ": Device allocation failed\n");
208 goto exit;
209 }
210
211 pdev_entry = kzalloc(sizeof(struct pdev_entry), GFP_KERNEL);
212 if (!pdev_entry) {
213 err = -ENOMEM;
214 goto exit_device_put;
215 }
216
217 err = platform_device_add(pdev);
218 if (err) {
219 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
220 err);
221 goto exit_device_free;
222 }
223
224 pdev_entry->pdev = pdev;
225 pdev_entry->cpu = cpu;
226 mutex_lock(&pdev_list_mutex);
227 list_add_tail(&pdev_entry->list, &pdev_list);
228 mutex_unlock(&pdev_list_mutex);
229
230 return 0;
231
232exit_device_free:
233 kfree(pdev_entry);
234exit_device_put:
235 platform_device_put(pdev);
236exit:
237 return err;
238}
239
240#ifdef CONFIG_HOTPLUG_CPU
241static void via_cputemp_device_remove(unsigned int cpu)
242{
243 struct pdev_entry *p, *n;
244 mutex_lock(&pdev_list_mutex);
245 list_for_each_entry_safe(p, n, &pdev_list, list) {
246 if (p->cpu == cpu) {
247 platform_device_unregister(p->pdev);
248 list_del(&p->list);
249 kfree(p);
250 }
251 }
252 mutex_unlock(&pdev_list_mutex);
253}
254
255static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
256 unsigned long action, void *hcpu)
257{
258 unsigned int cpu = (unsigned long) hcpu;
259
260 switch (action) {
261 case CPU_ONLINE:
262 case CPU_DOWN_FAILED:
263 via_cputemp_device_add(cpu);
264 break;
265 case CPU_DOWN_PREPARE:
266 via_cputemp_device_remove(cpu);
267 break;
268 }
269 return NOTIFY_OK;
270}
271
272static struct notifier_block via_cputemp_cpu_notifier __refdata = {
273 .notifier_call = via_cputemp_cpu_callback,
274};
275#endif /* !CONFIG_HOTPLUG_CPU */
276
277static int __init via_cputemp_init(void)
278{
279 int i, err;
280 struct pdev_entry *p, *n;
281
282 if (cpu_data(0).x86_vendor != X86_VENDOR_CENTAUR) {
283 printk(KERN_DEBUG DRVNAME ": Not a VIA CPU\n");
284 err = -ENODEV;
285 goto exit;
286 }
287
288 err = platform_driver_register(&via_cputemp_driver);
289 if (err)
290 goto exit;
291
292 for_each_online_cpu(i) {
293 struct cpuinfo_x86 *c = &cpu_data(i);
294
295 if (c->x86 != 6)
296 continue;
297
298 if (c->x86_model < 0x0a)
299 continue;
300
301 if (c->x86_model > 0x0f) {
302 printk(KERN_WARNING DRVNAME ": Unknown CPU "
303 "model 0x%x\n", c->x86_model);
304 continue;
305 }
306
307 err = via_cputemp_device_add(i);
308 if (err)
309 goto exit_devices_unreg;
310 }
311 if (list_empty(&pdev_list)) {
312 err = -ENODEV;
313 goto exit_driver_unreg;
314 }
315
316#ifdef CONFIG_HOTPLUG_CPU
317 register_hotcpu_notifier(&via_cputemp_cpu_notifier);
318#endif
319 return 0;
320
321exit_devices_unreg:
322 mutex_lock(&pdev_list_mutex);
323 list_for_each_entry_safe(p, n, &pdev_list, list) {
324 platform_device_unregister(p->pdev);
325 list_del(&p->list);
326 kfree(p);
327 }
328 mutex_unlock(&pdev_list_mutex);
329exit_driver_unreg:
330 platform_driver_unregister(&via_cputemp_driver);
331exit:
332 return err;
333}
334
335static void __exit via_cputemp_exit(void)
336{
337 struct pdev_entry *p, *n;
338#ifdef CONFIG_HOTPLUG_CPU
339 unregister_hotcpu_notifier(&via_cputemp_cpu_notifier);
340#endif
341 mutex_lock(&pdev_list_mutex);
342 list_for_each_entry_safe(p, n, &pdev_list, list) {
343 platform_device_unregister(p->pdev);
344 list_del(&p->list);
345 kfree(p);
346 }
347 mutex_unlock(&pdev_list_mutex);
348 platform_driver_unregister(&via_cputemp_driver);
349}
350
351MODULE_AUTHOR("Harald Welte <HaraldWelte@viatech.com>");
352MODULE_DESCRIPTION("VIA CPU temperature monitor");
353MODULE_LICENSE("GPL");
354
355module_init(via_cputemp_init)
356module_exit(via_cputemp_exit)
diff --git a/drivers/hwmon/via686a.c b/drivers/hwmon/via686a.c
index 39e82a492f26..f397ce7ad598 100644
--- a/drivers/hwmon/via686a.c
+++ b/drivers/hwmon/via686a.c
@@ -767,7 +767,7 @@ static struct via686a_data *via686a_update_device(struct device *dev)
767 return data; 767 return data;
768} 768}
769 769
770static struct pci_device_id via686a_pci_ids[] = { 770static const struct pci_device_id via686a_pci_ids[] = {
771 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4) }, 771 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4) },
772 { 0, } 772 { 0, }
773}; 773};
diff --git a/drivers/hwmon/vt8231.c b/drivers/hwmon/vt8231.c
index 470a1226ba2b..e6078c9f0e27 100644
--- a/drivers/hwmon/vt8231.c
+++ b/drivers/hwmon/vt8231.c
@@ -697,7 +697,7 @@ static struct platform_driver vt8231_driver = {
697 .remove = __devexit_p(vt8231_remove), 697 .remove = __devexit_p(vt8231_remove),
698}; 698};
699 699
700static struct pci_device_id vt8231_pci_ids[] = { 700static const struct pci_device_id vt8231_pci_ids[] = {
701 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4) }, 701 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4) },
702 { 0, } 702 { 0, }
703}; 703};
@@ -948,8 +948,7 @@ static int __devinit vt8231_pci_probe(struct pci_dev *dev,
948 948
949 address = val & ~(VT8231_EXTENT - 1); 949 address = val & ~(VT8231_EXTENT - 1);
950 if (address == 0) { 950 if (address == 0) {
951 dev_err(&dev->dev, "base address not set -\ 951 dev_err(&dev->dev, "base address not set - upgrade BIOS or use force_addr=0xaddr\n");
952 upgrade BIOS or use force_addr=0xaddr\n");
953 return -ENODEV; 952 return -ENODEV;
954 } 953 }
955 954
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index bb5e78748783..0dcaba9b7189 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -5,6 +5,7 @@
5 Copyright (C) 2006 Yuan Mu (Winbond), 5 Copyright (C) 2006 Yuan Mu (Winbond),
6 Rudolf Marek <r.marek@assembler.cz> 6 Rudolf Marek <r.marek@assembler.cz>
7 David Hubbard <david.c.hubbard@gmail.com> 7 David Hubbard <david.c.hubbard@gmail.com>
8 Daniel J Blueman <daniel.blueman@gmail.com>
8 9
9 Shamelessly ripped from the w83627hf driver 10 Shamelessly ripped from the w83627hf driver
10 Copyright (C) 2003 Mark Studebaker 11 Copyright (C) 2003 Mark Studebaker
@@ -177,12 +178,15 @@ static const u16 W83627EHF_REG_TEMP_CONFIG[] = { 0x152, 0x252 };
177#define W83627EHF_REG_ALARM3 0x45B 178#define W83627EHF_REG_ALARM3 0x45B
178 179
179/* SmartFan registers */ 180/* SmartFan registers */
181#define W83627EHF_REG_FAN_STEPUP_TIME 0x0f
182#define W83627EHF_REG_FAN_STEPDOWN_TIME 0x0e
183
180/* DC or PWM output fan configuration */ 184/* DC or PWM output fan configuration */
181static const u8 W83627EHF_REG_PWM_ENABLE[] = { 185static const u8 W83627EHF_REG_PWM_ENABLE[] = {
182 0x04, /* SYS FAN0 output mode and PWM mode */ 186 0x04, /* SYS FAN0 output mode and PWM mode */
183 0x04, /* CPU FAN0 output mode and PWM mode */ 187 0x04, /* CPU FAN0 output mode and PWM mode */
184 0x12, /* AUX FAN mode */ 188 0x12, /* AUX FAN mode */
185 0x62, /* CPU fan1 mode */ 189 0x62, /* CPU FAN1 mode */
186}; 190};
187 191
188static const u8 W83627EHF_PWM_MODE_SHIFT[] = { 0, 1, 0, 6 }; 192static const u8 W83627EHF_PWM_MODE_SHIFT[] = { 0, 1, 0, 6 };
@@ -193,10 +197,12 @@ static const u8 W83627EHF_REG_PWM[] = { 0x01, 0x03, 0x11, 0x61 };
193static const u8 W83627EHF_REG_TARGET[] = { 0x05, 0x06, 0x13, 0x63 }; 197static const u8 W83627EHF_REG_TARGET[] = { 0x05, 0x06, 0x13, 0x63 };
194static const u8 W83627EHF_REG_TOLERANCE[] = { 0x07, 0x07, 0x14, 0x62 }; 198static const u8 W83627EHF_REG_TOLERANCE[] = { 0x07, 0x07, 0x14, 0x62 };
195 199
196
197/* Advanced Fan control, some values are common for all fans */ 200/* Advanced Fan control, some values are common for all fans */
198static const u8 W83627EHF_REG_FAN_MIN_OUTPUT[] = { 0x08, 0x09, 0x15, 0x64 }; 201static const u8 W83627EHF_REG_FAN_START_OUTPUT[] = { 0x0a, 0x0b, 0x16, 0x65 };
199static const u8 W83627EHF_REG_FAN_STOP_TIME[] = { 0x0C, 0x0D, 0x17, 0x66 }; 202static const u8 W83627EHF_REG_FAN_STOP_OUTPUT[] = { 0x08, 0x09, 0x15, 0x64 };
203static const u8 W83627EHF_REG_FAN_STOP_TIME[] = { 0x0c, 0x0d, 0x17, 0x66 };
204static const u8 W83627EHF_REG_FAN_MAX_OUTPUT[] = { 0xff, 0x67, 0xff, 0x69 };
205static const u8 W83627EHF_REG_FAN_STEP_OUTPUT[] = { 0xff, 0x68, 0xff, 0x6a };
200 206
201/* 207/*
202 * Conversions 208 * Conversions
@@ -295,14 +301,19 @@ struct w83627ehf_data {
295 301
296 u8 pwm_mode[4]; /* 0->DC variable voltage, 1->PWM variable duty cycle */ 302 u8 pwm_mode[4]; /* 0->DC variable voltage, 1->PWM variable duty cycle */
297 u8 pwm_enable[4]; /* 1->manual 303 u8 pwm_enable[4]; /* 1->manual
298 2->thermal cruise (also called SmartFan I) */ 304 2->thermal cruise mode (also called SmartFan I)
305 3->fan speed cruise mode
306 4->variable thermal cruise (also called SmartFan III) */
299 u8 pwm_num; /* number of pwm */ 307 u8 pwm_num; /* number of pwm */
300 u8 pwm[4]; 308 u8 pwm[4];
301 u8 target_temp[4]; 309 u8 target_temp[4];
302 u8 tolerance[4]; 310 u8 tolerance[4];
303 311
304 u8 fan_min_output[4]; /* minimum fan speed */ 312 u8 fan_start_output[4]; /* minimum fan speed when spinning up */
305 u8 fan_stop_time[4]; 313 u8 fan_stop_output[4]; /* minimum fan speed when spinning down */
314 u8 fan_stop_time[4]; /* time at minimum before disabling fan */
315 u8 fan_max_output[4]; /* maximum fan speed */
316 u8 fan_step_output[4]; /* rate of change output value */
306 317
307 u8 vid; 318 u8 vid;
308 u8 vrm; 319 u8 vrm;
@@ -529,8 +540,10 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
529 & 3) + 1; 540 & 3) + 1;
530 data->pwm[i] = w83627ehf_read_value(data, 541 data->pwm[i] = w83627ehf_read_value(data,
531 W83627EHF_REG_PWM[i]); 542 W83627EHF_REG_PWM[i]);
532 data->fan_min_output[i] = w83627ehf_read_value(data, 543 data->fan_start_output[i] = w83627ehf_read_value(data,
533 W83627EHF_REG_FAN_MIN_OUTPUT[i]); 544 W83627EHF_REG_FAN_START_OUTPUT[i]);
545 data->fan_stop_output[i] = w83627ehf_read_value(data,
546 W83627EHF_REG_FAN_STOP_OUTPUT[i]);
534 data->fan_stop_time[i] = w83627ehf_read_value(data, 547 data->fan_stop_time[i] = w83627ehf_read_value(data,
535 W83627EHF_REG_FAN_STOP_TIME[i]); 548 W83627EHF_REG_FAN_STOP_TIME[i]);
536 data->target_temp[i] = 549 data->target_temp[i] =
@@ -976,7 +989,7 @@ store_pwm_enable(struct device *dev, struct device_attribute *attr,
976 u32 val = simple_strtoul(buf, NULL, 10); 989 u32 val = simple_strtoul(buf, NULL, 10);
977 u16 reg; 990 u16 reg;
978 991
979 if (!val || (val > 2)) /* only modes 1 and 2 are supported */ 992 if (!val || (val > 4))
980 return -EINVAL; 993 return -EINVAL;
981 mutex_lock(&data->update_lock); 994 mutex_lock(&data->update_lock);
982 reg = w83627ehf_read_value(data, W83627EHF_REG_PWM_ENABLE[nr]); 995 reg = w83627ehf_read_value(data, W83627EHF_REG_PWM_ENABLE[nr]);
@@ -1118,7 +1131,10 @@ store_##reg(struct device *dev, struct device_attribute *attr, \
1118 return count; \ 1131 return count; \
1119} 1132}
1120 1133
1121fan_functions(fan_min_output, FAN_MIN_OUTPUT) 1134fan_functions(fan_start_output, FAN_START_OUTPUT)
1135fan_functions(fan_stop_output, FAN_STOP_OUTPUT)
1136fan_functions(fan_max_output, FAN_MAX_OUTPUT)
1137fan_functions(fan_step_output, FAN_STEP_OUTPUT)
1122 1138
1123#define fan_time_functions(reg, REG) \ 1139#define fan_time_functions(reg, REG) \
1124static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ 1140static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
@@ -1161,8 +1177,14 @@ static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
1161static struct sensor_device_attribute sda_sf3_arrays_fan4[] = { 1177static struct sensor_device_attribute sda_sf3_arrays_fan4[] = {
1162 SENSOR_ATTR(pwm4_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time, 1178 SENSOR_ATTR(pwm4_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
1163 store_fan_stop_time, 3), 1179 store_fan_stop_time, 3),
1164 SENSOR_ATTR(pwm4_min_output, S_IWUSR | S_IRUGO, show_fan_min_output, 1180 SENSOR_ATTR(pwm4_start_output, S_IWUSR | S_IRUGO, show_fan_start_output,
1165 store_fan_min_output, 3), 1181 store_fan_start_output, 3),
1182 SENSOR_ATTR(pwm4_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output,
1183 store_fan_stop_output, 3),
1184 SENSOR_ATTR(pwm4_max_output, S_IWUSR | S_IRUGO, show_fan_max_output,
1185 store_fan_max_output, 3),
1186 SENSOR_ATTR(pwm4_step_output, S_IWUSR | S_IRUGO, show_fan_step_output,
1187 store_fan_step_output, 3),
1166}; 1188};
1167 1189
1168static struct sensor_device_attribute sda_sf3_arrays[] = { 1190static struct sensor_device_attribute sda_sf3_arrays[] = {
@@ -1172,12 +1194,24 @@ static struct sensor_device_attribute sda_sf3_arrays[] = {
1172 store_fan_stop_time, 1), 1194 store_fan_stop_time, 1),
1173 SENSOR_ATTR(pwm3_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time, 1195 SENSOR_ATTR(pwm3_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
1174 store_fan_stop_time, 2), 1196 store_fan_stop_time, 2),
1175 SENSOR_ATTR(pwm1_min_output, S_IWUSR | S_IRUGO, show_fan_min_output, 1197 SENSOR_ATTR(pwm1_start_output, S_IWUSR | S_IRUGO, show_fan_start_output,
1176 store_fan_min_output, 0), 1198 store_fan_start_output, 0),
1177 SENSOR_ATTR(pwm2_min_output, S_IWUSR | S_IRUGO, show_fan_min_output, 1199 SENSOR_ATTR(pwm2_start_output, S_IWUSR | S_IRUGO, show_fan_start_output,
1178 store_fan_min_output, 1), 1200 store_fan_start_output, 1),
1179 SENSOR_ATTR(pwm3_min_output, S_IWUSR | S_IRUGO, show_fan_min_output, 1201 SENSOR_ATTR(pwm3_start_output, S_IWUSR | S_IRUGO, show_fan_start_output,
1180 store_fan_min_output, 2), 1202 store_fan_start_output, 2),
1203 SENSOR_ATTR(pwm1_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output,
1204 store_fan_stop_output, 0),
1205 SENSOR_ATTR(pwm2_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output,
1206 store_fan_stop_output, 1),
1207 SENSOR_ATTR(pwm3_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output,
1208 store_fan_stop_output, 2),
1209
1210 /* pwm1 and pwm3 don't support max and step settings */
1211 SENSOR_ATTR(pwm2_max_output, S_IWUSR | S_IRUGO, show_fan_max_output,
1212 store_fan_max_output, 1),
1213 SENSOR_ATTR(pwm2_step_output, S_IWUSR | S_IRUGO, show_fan_step_output,
1214 store_fan_step_output, 1),
1181}; 1215};
1182 1216
1183static ssize_t 1217static ssize_t
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c
index 2be28ac4ede0..38e280523071 100644
--- a/drivers/hwmon/w83627hf.c
+++ b/drivers/hwmon/w83627hf.c
@@ -59,10 +59,11 @@ static struct platform_device *pdev;
59#define DRVNAME "w83627hf" 59#define DRVNAME "w83627hf"
60enum chips { w83627hf, w83627thf, w83697hf, w83637hf, w83687thf }; 60enum chips { w83627hf, w83627thf, w83697hf, w83637hf, w83687thf };
61 61
62static u16 force_addr; 62struct w83627hf_sio_data {
63module_param(force_addr, ushort, 0); 63 enum chips type;
64MODULE_PARM_DESC(force_addr, 64 int sioaddr;
65 "Initialize the base address of the sensors"); 65};
66
66static u8 force_i2c = 0x1f; 67static u8 force_i2c = 0x1f;
67module_param(force_i2c, byte, 0); 68module_param(force_i2c, byte, 0);
68MODULE_PARM_DESC(force_i2c, 69MODULE_PARM_DESC(force_i2c,
@@ -77,9 +78,7 @@ module_param(force_id, ushort, 0);
77MODULE_PARM_DESC(force_id, "Override the detected device ID"); 78MODULE_PARM_DESC(force_id, "Override the detected device ID");
78 79
79/* modified from kernel/include/traps.c */ 80/* modified from kernel/include/traps.c */
80static int REG; /* The register to read/write */
81#define DEV 0x07 /* Register: Logical device select */ 81#define DEV 0x07 /* Register: Logical device select */
82static int VAL; /* The value to read/write */
83 82
84/* logical device numbers for superio_select (below) */ 83/* logical device numbers for superio_select (below) */
85#define W83627HF_LD_FDC 0x00 84#define W83627HF_LD_FDC 0x00
@@ -109,37 +108,37 @@ static int VAL; /* The value to read/write */
109#define W83687THF_VID_DATA 0xF1 /* w83687thf only */ 108#define W83687THF_VID_DATA 0xF1 /* w83687thf only */
110 109
111static inline void 110static inline void
112superio_outb(int reg, int val) 111superio_outb(struct w83627hf_sio_data *sio, int reg, int val)
113{ 112{
114 outb(reg, REG); 113 outb(reg, sio->sioaddr);
115 outb(val, VAL); 114 outb(val, sio->sioaddr + 1);
116} 115}
117 116
118static inline int 117static inline int
119superio_inb(int reg) 118superio_inb(struct w83627hf_sio_data *sio, int reg)
120{ 119{
121 outb(reg, REG); 120 outb(reg, sio->sioaddr);
122 return inb(VAL); 121 return inb(sio->sioaddr + 1);
123} 122}
124 123
125static inline void 124static inline void
126superio_select(int ld) 125superio_select(struct w83627hf_sio_data *sio, int ld)
127{ 126{
128 outb(DEV, REG); 127 outb(DEV, sio->sioaddr);
129 outb(ld, VAL); 128 outb(ld, sio->sioaddr + 1);
130} 129}
131 130
132static inline void 131static inline void
133superio_enter(void) 132superio_enter(struct w83627hf_sio_data *sio)
134{ 133{
135 outb(0x87, REG); 134 outb(0x87, sio->sioaddr);
136 outb(0x87, REG); 135 outb(0x87, sio->sioaddr);
137} 136}
138 137
139static inline void 138static inline void
140superio_exit(void) 139superio_exit(struct w83627hf_sio_data *sio)
141{ 140{
142 outb(0xAA, REG); 141 outb(0xAA, sio->sioaddr);
143} 142}
144 143
145#define W627_DEVID 0x52 144#define W627_DEVID 0x52
@@ -380,10 +379,6 @@ struct w83627hf_data {
380 u8 vrm_ovt; /* Register value, 627THF/637HF/687THF only */ 379 u8 vrm_ovt; /* Register value, 627THF/637HF/687THF only */
381}; 380};
382 381
383struct w83627hf_sio_data {
384 enum chips type;
385};
386
387 382
388static int w83627hf_probe(struct platform_device *pdev); 383static int w83627hf_probe(struct platform_device *pdev);
389static int __devexit w83627hf_remove(struct platform_device *pdev); 384static int __devexit w83627hf_remove(struct platform_device *pdev);
@@ -1140,11 +1135,9 @@ static int __init w83627hf_find(int sioaddr, unsigned short *addr,
1140 "W83687THF", 1135 "W83687THF",
1141 }; 1136 };
1142 1137
1143 REG = sioaddr; 1138 sio_data->sioaddr = sioaddr;
1144 VAL = sioaddr + 1; 1139 superio_enter(sio_data);
1145 1140 val = force_id ? force_id : superio_inb(sio_data, DEVID);
1146 superio_enter();
1147 val = force_id ? force_id : superio_inb(DEVID);
1148 switch (val) { 1141 switch (val) {
1149 case W627_DEVID: 1142 case W627_DEVID:
1150 sio_data->type = w83627hf; 1143 sio_data->type = w83627hf;
@@ -1168,16 +1161,9 @@ static int __init w83627hf_find(int sioaddr, unsigned short *addr,
1168 goto exit; 1161 goto exit;
1169 } 1162 }
1170 1163
1171 superio_select(W83627HF_LD_HWM); 1164 superio_select(sio_data, W83627HF_LD_HWM);
1172 force_addr &= WINB_ALIGNMENT; 1165 val = (superio_inb(sio_data, WINB_BASE_REG) << 8) |
1173 if (force_addr) { 1166 superio_inb(sio_data, WINB_BASE_REG + 1);
1174 printk(KERN_WARNING DRVNAME ": Forcing address 0x%x\n",
1175 force_addr);
1176 superio_outb(WINB_BASE_REG, force_addr >> 8);
1177 superio_outb(WINB_BASE_REG + 1, force_addr & 0xff);
1178 }
1179 val = (superio_inb(WINB_BASE_REG) << 8) |
1180 superio_inb(WINB_BASE_REG + 1);
1181 *addr = val & WINB_ALIGNMENT; 1167 *addr = val & WINB_ALIGNMENT;
1182 if (*addr == 0) { 1168 if (*addr == 0) {
1183 printk(KERN_WARNING DRVNAME ": Base address not set, " 1169 printk(KERN_WARNING DRVNAME ": Base address not set, "
@@ -1185,10 +1171,10 @@ static int __init w83627hf_find(int sioaddr, unsigned short *addr,
1185 goto exit; 1171 goto exit;
1186 } 1172 }
1187 1173
1188 val = superio_inb(WINB_ACT_REG); 1174 val = superio_inb(sio_data, WINB_ACT_REG);
1189 if (!(val & 0x01)) { 1175 if (!(val & 0x01)) {
1190 printk(KERN_WARNING DRVNAME ": Enabling HWM logical device\n"); 1176 printk(KERN_WARNING DRVNAME ": Enabling HWM logical device\n");
1191 superio_outb(WINB_ACT_REG, val | 0x01); 1177 superio_outb(sio_data, WINB_ACT_REG, val | 0x01);
1192 } 1178 }
1193 1179
1194 err = 0; 1180 err = 0;
@@ -1196,7 +1182,7 @@ static int __init w83627hf_find(int sioaddr, unsigned short *addr,
1196 names[sio_data->type], *addr); 1182 names[sio_data->type], *addr);
1197 1183
1198 exit: 1184 exit:
1199 superio_exit(); 1185 superio_exit(sio_data);
1200 return err; 1186 return err;
1201} 1187}
1202 1188
@@ -1511,20 +1497,21 @@ static int w83627hf_read_value(struct w83627hf_data *data, u16 reg)
1511 1497
1512static int __devinit w83627thf_read_gpio5(struct platform_device *pdev) 1498static int __devinit w83627thf_read_gpio5(struct platform_device *pdev)
1513{ 1499{
1500 struct w83627hf_sio_data *sio_data = pdev->dev.platform_data;
1514 int res = 0xff, sel; 1501 int res = 0xff, sel;
1515 1502
1516 superio_enter(); 1503 superio_enter(sio_data);
1517 superio_select(W83627HF_LD_GPIO5); 1504 superio_select(sio_data, W83627HF_LD_GPIO5);
1518 1505
1519 /* Make sure these GPIO pins are enabled */ 1506 /* Make sure these GPIO pins are enabled */
1520 if (!(superio_inb(W83627THF_GPIO5_EN) & (1<<3))) { 1507 if (!(superio_inb(sio_data, W83627THF_GPIO5_EN) & (1<<3))) {
1521 dev_dbg(&pdev->dev, "GPIO5 disabled, no VID function\n"); 1508 dev_dbg(&pdev->dev, "GPIO5 disabled, no VID function\n");
1522 goto exit; 1509 goto exit;
1523 } 1510 }
1524 1511
1525 /* Make sure the pins are configured for input 1512 /* Make sure the pins are configured for input
1526 There must be at least five (VRM 9), and possibly 6 (VRM 10) */ 1513 There must be at least five (VRM 9), and possibly 6 (VRM 10) */
1527 sel = superio_inb(W83627THF_GPIO5_IOSR) & 0x3f; 1514 sel = superio_inb(sio_data, W83627THF_GPIO5_IOSR) & 0x3f;
1528 if ((sel & 0x1f) != 0x1f) { 1515 if ((sel & 0x1f) != 0x1f) {
1529 dev_dbg(&pdev->dev, "GPIO5 not configured for VID " 1516 dev_dbg(&pdev->dev, "GPIO5 not configured for VID "
1530 "function\n"); 1517 "function\n");
@@ -1532,37 +1519,38 @@ static int __devinit w83627thf_read_gpio5(struct platform_device *pdev)
1532 } 1519 }
1533 1520
1534 dev_info(&pdev->dev, "Reading VID from GPIO5\n"); 1521 dev_info(&pdev->dev, "Reading VID from GPIO5\n");
1535 res = superio_inb(W83627THF_GPIO5_DR) & sel; 1522 res = superio_inb(sio_data, W83627THF_GPIO5_DR) & sel;
1536 1523
1537exit: 1524exit:
1538 superio_exit(); 1525 superio_exit(sio_data);
1539 return res; 1526 return res;
1540} 1527}
1541 1528
1542static int __devinit w83687thf_read_vid(struct platform_device *pdev) 1529static int __devinit w83687thf_read_vid(struct platform_device *pdev)
1543{ 1530{
1531 struct w83627hf_sio_data *sio_data = pdev->dev.platform_data;
1544 int res = 0xff; 1532 int res = 0xff;
1545 1533
1546 superio_enter(); 1534 superio_enter(sio_data);
1547 superio_select(W83627HF_LD_HWM); 1535 superio_select(sio_data, W83627HF_LD_HWM);
1548 1536
1549 /* Make sure these GPIO pins are enabled */ 1537 /* Make sure these GPIO pins are enabled */
1550 if (!(superio_inb(W83687THF_VID_EN) & (1 << 2))) { 1538 if (!(superio_inb(sio_data, W83687THF_VID_EN) & (1 << 2))) {
1551 dev_dbg(&pdev->dev, "VID disabled, no VID function\n"); 1539 dev_dbg(&pdev->dev, "VID disabled, no VID function\n");
1552 goto exit; 1540 goto exit;
1553 } 1541 }
1554 1542
1555 /* Make sure the pins are configured for input */ 1543 /* Make sure the pins are configured for input */
1556 if (!(superio_inb(W83687THF_VID_CFG) & (1 << 4))) { 1544 if (!(superio_inb(sio_data, W83687THF_VID_CFG) & (1 << 4))) {
1557 dev_dbg(&pdev->dev, "VID configured as output, " 1545 dev_dbg(&pdev->dev, "VID configured as output, "
1558 "no VID function\n"); 1546 "no VID function\n");
1559 goto exit; 1547 goto exit;
1560 } 1548 }
1561 1549
1562 res = superio_inb(W83687THF_VID_DATA) & 0x3f; 1550 res = superio_inb(sio_data, W83687THF_VID_DATA) & 0x3f;
1563 1551
1564exit: 1552exit:
1565 superio_exit(); 1553 superio_exit(sio_data);
1566 return res; 1554 return res;
1567} 1555}
1568 1556
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index d27ed1bac002..32d4adee73db 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -56,9 +56,10 @@
56/* Addresses to scan */ 56/* Addresses to scan */
57static const unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 57static const unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
58 0x2e, 0x2f, I2C_CLIENT_END }; 58 0x2e, 0x2f, I2C_CLIENT_END };
59/* Insmod parameters */
60I2C_CLIENT_INSMOD_4(w83781d, w83782d, w83783s, as99127f);
61 59
60enum chips { w83781d, w83782d, w83783s, as99127f };
61
62/* Insmod parameters */
62static unsigned short force_subclients[4]; 63static unsigned short force_subclients[4];
63module_param_array(force_subclients, short, NULL, 0); 64module_param_array(force_subclients, short, NULL, 0);
64MODULE_PARM_DESC(force_subclients, "List of subclient addresses: " 65MODULE_PARM_DESC(force_subclients, "List of subclient addresses: "
@@ -1051,14 +1052,13 @@ w83781d_create_files(struct device *dev, int kind, int is_isa)
1051 1052
1052/* Return 0 if detection is successful, -ENODEV otherwise */ 1053/* Return 0 if detection is successful, -ENODEV otherwise */
1053static int 1054static int
1054w83781d_detect(struct i2c_client *client, int kind, 1055w83781d_detect(struct i2c_client *client, struct i2c_board_info *info)
1055 struct i2c_board_info *info)
1056{ 1056{
1057 int val1 = 0, val2; 1057 int val1, val2;
1058 struct w83781d_data *isa = w83781d_data_if_isa(); 1058 struct w83781d_data *isa = w83781d_data_if_isa();
1059 struct i2c_adapter *adapter = client->adapter; 1059 struct i2c_adapter *adapter = client->adapter;
1060 int address = client->addr; 1060 int address = client->addr;
1061 const char *client_name = ""; 1061 const char *client_name;
1062 enum vendor { winbond, asus } vendid; 1062 enum vendor { winbond, asus } vendid;
1063 1063
1064 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1064 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
@@ -1070,98 +1070,73 @@ w83781d_detect(struct i2c_client *client, int kind,
1070 if (isa) 1070 if (isa)
1071 mutex_lock(&isa->update_lock); 1071 mutex_lock(&isa->update_lock);
1072 1072
1073 /* The w8378?d may be stuck in some other bank than bank 0. This may 1073 if (i2c_smbus_read_byte_data(client, W83781D_REG_CONFIG) & 0x80) {
1074 make reading other information impossible. Specify a force=... or 1074 dev_dbg(&adapter->dev,
1075 force_*=... parameter, and the Winbond will be reset to the right 1075 "Detection of w83781d chip failed at step 3\n");
1076 bank. */ 1076 goto err_nodev;
1077 if (kind < 0) { 1077 }
1078 if (i2c_smbus_read_byte_data 1078
1079 (client, W83781D_REG_CONFIG) & 0x80) { 1079 val1 = i2c_smbus_read_byte_data(client, W83781D_REG_BANK);
1080 dev_dbg(&adapter->dev, "Detection of w83781d chip " 1080 val2 = i2c_smbus_read_byte_data(client, W83781D_REG_CHIPMAN);
1081 "failed at step 3\n"); 1081 /* Check for Winbond or Asus ID if in bank 0 */
1082 goto err_nodev; 1082 if (!(val1 & 0x07) &&
1083 } 1083 ((!(val1 & 0x80) && val2 != 0xa3 && val2 != 0xc3) ||
1084 val1 = i2c_smbus_read_byte_data(client, W83781D_REG_BANK); 1084 ( (val1 & 0x80) && val2 != 0x5c && val2 != 0x12))) {
1085 val2 = i2c_smbus_read_byte_data(client, W83781D_REG_CHIPMAN); 1085 dev_dbg(&adapter->dev,
1086 /* Check for Winbond or Asus ID if in bank 0 */ 1086 "Detection of w83781d chip failed at step 4\n");
1087 if ((!(val1 & 0x07)) && 1087 goto err_nodev;
1088 (((!(val1 & 0x80)) && (val2 != 0xa3) && (val2 != 0xc3)) 1088 }
1089 || ((val1 & 0x80) && (val2 != 0x5c) && (val2 != 0x12)))) { 1089 /* If Winbond SMBus, check address at 0x48.
1090 dev_dbg(&adapter->dev, "Detection of w83781d chip " 1090 Asus doesn't support, except for as99127f rev.2 */
1091 "failed at step 4\n"); 1091 if ((!(val1 & 0x80) && val2 == 0xa3) ||
1092 ( (val1 & 0x80) && val2 == 0x5c)) {
1093 if (i2c_smbus_read_byte_data(client, W83781D_REG_I2C_ADDR)
1094 != address) {
1095 dev_dbg(&adapter->dev,
1096 "Detection of w83781d chip failed at step 5\n");
1092 goto err_nodev; 1097 goto err_nodev;
1093 } 1098 }
1094 /* If Winbond SMBus, check address at 0x48.
1095 Asus doesn't support, except for as99127f rev.2 */
1096 if ((!(val1 & 0x80) && (val2 == 0xa3)) ||
1097 ((val1 & 0x80) && (val2 == 0x5c))) {
1098 if (i2c_smbus_read_byte_data
1099 (client, W83781D_REG_I2C_ADDR) != address) {
1100 dev_dbg(&adapter->dev, "Detection of w83781d "
1101 "chip failed at step 5\n");
1102 goto err_nodev;
1103 }
1104 }
1105 } 1099 }
1106 1100
1107 /* We have either had a force parameter, or we have already detected the 1101 /* Put it now into bank 0 and Vendor ID High Byte */
1108 Winbond. Put it now into bank 0 and Vendor ID High Byte */
1109 i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 1102 i2c_smbus_write_byte_data(client, W83781D_REG_BANK,
1110 (i2c_smbus_read_byte_data(client, W83781D_REG_BANK) 1103 (i2c_smbus_read_byte_data(client, W83781D_REG_BANK)
1111 & 0x78) | 0x80); 1104 & 0x78) | 0x80);
1112 1105
1113 /* Determine the chip type. */ 1106 /* Get the vendor ID */
1114 if (kind <= 0) { 1107 val2 = i2c_smbus_read_byte_data(client, W83781D_REG_CHIPMAN);
1115 /* get vendor ID */ 1108 if (val2 == 0x5c)
1116 val2 = i2c_smbus_read_byte_data(client, W83781D_REG_CHIPMAN); 1109 vendid = winbond;
1117 if (val2 == 0x5c) 1110 else if (val2 == 0x12)
1118 vendid = winbond; 1111 vendid = asus;
1119 else if (val2 == 0x12) 1112 else {
1120 vendid = asus; 1113 dev_dbg(&adapter->dev,
1121 else { 1114 "w83781d chip vendor is neither Winbond nor Asus\n");
1122 dev_dbg(&adapter->dev, "w83781d chip vendor is " 1115 goto err_nodev;
1123 "neither Winbond nor Asus\n");
1124 goto err_nodev;
1125 }
1126
1127 val1 = i2c_smbus_read_byte_data(client, W83781D_REG_WCHIPID);
1128 if ((val1 == 0x10 || val1 == 0x11) && vendid == winbond)
1129 kind = w83781d;
1130 else if (val1 == 0x30 && vendid == winbond)
1131 kind = w83782d;
1132 else if (val1 == 0x40 && vendid == winbond && address == 0x2d)
1133 kind = w83783s;
1134 else if (val1 == 0x31)
1135 kind = as99127f;
1136 else {
1137 if (kind == 0)
1138 dev_warn(&adapter->dev, "Ignoring 'force' "
1139 "parameter for unknown chip at "
1140 "address 0x%02x\n", address);
1141 goto err_nodev;
1142 }
1143
1144 if ((kind == w83781d || kind == w83782d)
1145 && w83781d_alias_detect(client, val1)) {
1146 dev_dbg(&adapter->dev, "Device at 0x%02x appears to "
1147 "be the same as ISA device\n", address);
1148 goto err_nodev;
1149 }
1150 } 1116 }
1151 1117
1152 if (isa) 1118 /* Determine the chip type. */
1153 mutex_unlock(&isa->update_lock); 1119 val1 = i2c_smbus_read_byte_data(client, W83781D_REG_WCHIPID);
1154 1120 if ((val1 == 0x10 || val1 == 0x11) && vendid == winbond)
1155 if (kind == w83781d) {
1156 client_name = "w83781d"; 1121 client_name = "w83781d";
1157 } else if (kind == w83782d) { 1122 else if (val1 == 0x30 && vendid == winbond)
1158 client_name = "w83782d"; 1123 client_name = "w83782d";
1159 } else if (kind == w83783s) { 1124 else if (val1 == 0x40 && vendid == winbond && address == 0x2d)
1160 client_name = "w83783s"; 1125 client_name = "w83783s";
1161 } else if (kind == as99127f) { 1126 else if (val1 == 0x31)
1162 client_name = "as99127f"; 1127 client_name = "as99127f";
1128 else
1129 goto err_nodev;
1130
1131 if (val1 <= 0x30 && w83781d_alias_detect(client, val1)) {
1132 dev_dbg(&adapter->dev, "Device at 0x%02x appears to "
1133 "be the same as ISA device\n", address);
1134 goto err_nodev;
1163 } 1135 }
1164 1136
1137 if (isa)
1138 mutex_unlock(&isa->update_lock);
1139
1165 strlcpy(info->type, client_name, I2C_NAME_SIZE); 1140 strlcpy(info->type, client_name, I2C_NAME_SIZE);
1166 1141
1167 return 0; 1142 return 0;
@@ -1562,7 +1537,7 @@ static struct i2c_driver w83781d_driver = {
1562 .remove = w83781d_remove, 1537 .remove = w83781d_remove,
1563 .id_table = w83781d_ids, 1538 .id_table = w83781d_ids,
1564 .detect = w83781d_detect, 1539 .detect = w83781d_detect,
1565 .address_data = &addr_data, 1540 .address_list = normal_i2c,
1566}; 1541};
1567 1542
1568/* 1543/*
@@ -1818,17 +1793,17 @@ static int __init
1818w83781d_isa_found(unsigned short address) 1793w83781d_isa_found(unsigned short address)
1819{ 1794{
1820 int val, save, found = 0; 1795 int val, save, found = 0;
1821 1796 int port;
1822 /* We have to request the region in two parts because some 1797
1823 boards declare base+4 to base+7 as a PNP device */ 1798 /* Some boards declare base+0 to base+7 as a PNP device, some base+4
1824 if (!request_region(address, 4, "w83781d")) { 1799 * to base+7 and some base+5 to base+6. So we better request each port
1825 pr_debug("w83781d: Failed to request low part of region\n"); 1800 * individually for the probing phase. */
1826 return 0; 1801 for (port = address; port < address + W83781D_EXTENT; port++) {
1827 } 1802 if (!request_region(port, 1, "w83781d")) {
1828 if (!request_region(address + 4, 4, "w83781d")) { 1803 pr_debug("w83781d: Failed to request port 0x%x\n",
1829 pr_debug("w83781d: Failed to request high part of region\n"); 1804 port);
1830 release_region(address, 4); 1805 goto release;
1831 return 0; 1806 }
1832 } 1807 }
1833 1808
1834#define REALLY_SLOW_IO 1809#define REALLY_SLOW_IO
@@ -1902,8 +1877,8 @@ w83781d_isa_found(unsigned short address)
1902 val == 0x30 ? "W83782D" : "W83781D", (int)address); 1877 val == 0x30 ? "W83782D" : "W83781D", (int)address);
1903 1878
1904 release: 1879 release:
1905 release_region(address + 4, 4); 1880 for (port--; port >= address; port--)
1906 release_region(address, 4); 1881 release_region(port, 1);
1907 return found; 1882 return found;
1908} 1883}
1909 1884
diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c
index 97851c5ba3a3..400a88bde278 100644
--- a/drivers/hwmon/w83791d.c
+++ b/drivers/hwmon/w83791d.c
@@ -52,7 +52,6 @@ static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
52 I2C_CLIENT_END }; 52 I2C_CLIENT_END };
53 53
54/* Insmod parameters */ 54/* Insmod parameters */
55I2C_CLIENT_INSMOD_1(w83791d);
56 55
57static unsigned short force_subclients[4]; 56static unsigned short force_subclients[4];
58module_param_array(force_subclients, short, NULL, 0); 57module_param_array(force_subclients, short, NULL, 0);
@@ -326,7 +325,7 @@ struct w83791d_data {
326 325
327static int w83791d_probe(struct i2c_client *client, 326static int w83791d_probe(struct i2c_client *client,
328 const struct i2c_device_id *id); 327 const struct i2c_device_id *id);
329static int w83791d_detect(struct i2c_client *client, int kind, 328static int w83791d_detect(struct i2c_client *client,
330 struct i2c_board_info *info); 329 struct i2c_board_info *info);
331static int w83791d_remove(struct i2c_client *client); 330static int w83791d_remove(struct i2c_client *client);
332 331
@@ -341,7 +340,7 @@ static void w83791d_print_debug(struct w83791d_data *data, struct device *dev);
341static void w83791d_init_client(struct i2c_client *client); 340static void w83791d_init_client(struct i2c_client *client);
342 341
343static const struct i2c_device_id w83791d_id[] = { 342static const struct i2c_device_id w83791d_id[] = {
344 { "w83791d", w83791d }, 343 { "w83791d", 0 },
345 { } 344 { }
346}; 345};
347MODULE_DEVICE_TABLE(i2c, w83791d_id); 346MODULE_DEVICE_TABLE(i2c, w83791d_id);
@@ -355,7 +354,7 @@ static struct i2c_driver w83791d_driver = {
355 .remove = w83791d_remove, 354 .remove = w83791d_remove,
356 .id_table = w83791d_id, 355 .id_table = w83791d_id,
357 .detect = w83791d_detect, 356 .detect = w83791d_detect,
358 .address_data = &addr_data, 357 .address_list = normal_i2c,
359}; 358};
360 359
361/* following are the sysfs callback functions */ 360/* following are the sysfs callback functions */
@@ -1259,7 +1258,7 @@ error_sc_0:
1259 1258
1260 1259
1261/* Return 0 if detection is successful, -ENODEV otherwise */ 1260/* Return 0 if detection is successful, -ENODEV otherwise */
1262static int w83791d_detect(struct i2c_client *client, int kind, 1261static int w83791d_detect(struct i2c_client *client,
1263 struct i2c_board_info *info) 1262 struct i2c_board_info *info)
1264{ 1263{
1265 struct i2c_adapter *adapter = client->adapter; 1264 struct i2c_adapter *adapter = client->adapter;
@@ -1270,56 +1269,32 @@ static int w83791d_detect(struct i2c_client *client, int kind,
1270 return -ENODEV; 1269 return -ENODEV;
1271 } 1270 }
1272 1271
1273 /* The w83791d may be stuck in some other bank than bank 0. This may 1272 if (w83791d_read(client, W83791D_REG_CONFIG) & 0x80)
1274 make reading other information impossible. Specify a force=... 1273 return -ENODEV;
1275 parameter, and the Winbond will be reset to the right bank. */ 1274
1276 if (kind < 0) { 1275 val1 = w83791d_read(client, W83791D_REG_BANK);
1277 if (w83791d_read(client, W83791D_REG_CONFIG) & 0x80) { 1276 val2 = w83791d_read(client, W83791D_REG_CHIPMAN);
1278 return -ENODEV; 1277 /* Check for Winbond ID if in bank 0 */
1279 } 1278 if (!(val1 & 0x07)) {
1280 val1 = w83791d_read(client, W83791D_REG_BANK); 1279 if ((!(val1 & 0x80) && val2 != 0xa3) ||
1281 val2 = w83791d_read(client, W83791D_REG_CHIPMAN); 1280 ( (val1 & 0x80) && val2 != 0x5c)) {
1282 /* Check for Winbond ID if in bank 0 */
1283 if (!(val1 & 0x07)) {
1284 /* yes it is Bank0 */
1285 if (((!(val1 & 0x80)) && (val2 != 0xa3)) ||
1286 ((val1 & 0x80) && (val2 != 0x5c))) {
1287 return -ENODEV;
1288 }
1289 }
1290 /* If Winbond chip, address of chip and W83791D_REG_I2C_ADDR
1291 should match */
1292 if (w83791d_read(client, W83791D_REG_I2C_ADDR) != address) {
1293 return -ENODEV; 1281 return -ENODEV;
1294 } 1282 }
1295 } 1283 }
1284 /* If Winbond chip, address of chip and W83791D_REG_I2C_ADDR
1285 should match */
1286 if (w83791d_read(client, W83791D_REG_I2C_ADDR) != address)
1287 return -ENODEV;
1296 1288
1297 /* We either have a force parameter or we have reason to 1289 /* We want bank 0 and Vendor ID high byte */
1298 believe it is a Winbond chip. Either way, we want bank 0 and
1299 Vendor ID high byte */
1300 val1 = w83791d_read(client, W83791D_REG_BANK) & 0x78; 1290 val1 = w83791d_read(client, W83791D_REG_BANK) & 0x78;
1301 w83791d_write(client, W83791D_REG_BANK, val1 | 0x80); 1291 w83791d_write(client, W83791D_REG_BANK, val1 | 0x80);
1302 1292
1303 /* Verify it is a Winbond w83791d */ 1293 /* Verify it is a Winbond w83791d */
1304 if (kind <= 0) { 1294 val1 = w83791d_read(client, W83791D_REG_WCHIPID);
1305 /* get vendor ID */ 1295 val2 = w83791d_read(client, W83791D_REG_CHIPMAN);
1306 val2 = w83791d_read(client, W83791D_REG_CHIPMAN); 1296 if (val1 != 0x71 || val2 != 0x5c)
1307 if (val2 != 0x5c) { /* the vendor is NOT Winbond */ 1297 return -ENODEV;
1308 return -ENODEV;
1309 }
1310 val1 = w83791d_read(client, W83791D_REG_WCHIPID);
1311 if (val1 == 0x71) {
1312 kind = w83791d;
1313 } else {
1314 if (kind == 0)
1315 dev_warn(&adapter->dev,
1316 "w83791d: Ignoring 'force' parameter "
1317 "for unknown chip at adapter %d, "
1318 "address 0x%02x\n",
1319 i2c_adapter_id(adapter), address);
1320 return -ENODEV;
1321 }
1322 }
1323 1298
1324 strlcpy(info->type, "w83791d", I2C_NAME_SIZE); 1299 strlcpy(info->type, "w83791d", I2C_NAME_SIZE);
1325 1300
diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c
index 2be16194ddf3..679718e6b017 100644
--- a/drivers/hwmon/w83792d.c
+++ b/drivers/hwmon/w83792d.c
@@ -50,7 +50,6 @@ static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
50 I2C_CLIENT_END }; 50 I2C_CLIENT_END };
51 51
52/* Insmod parameters */ 52/* Insmod parameters */
53I2C_CLIENT_INSMOD_1(w83792d);
54 53
55static unsigned short force_subclients[4]; 54static unsigned short force_subclients[4];
56module_param_array(force_subclients, short, NULL, 0); 55module_param_array(force_subclients, short, NULL, 0);
@@ -302,7 +301,7 @@ struct w83792d_data {
302 301
303static int w83792d_probe(struct i2c_client *client, 302static int w83792d_probe(struct i2c_client *client,
304 const struct i2c_device_id *id); 303 const struct i2c_device_id *id);
305static int w83792d_detect(struct i2c_client *client, int kind, 304static int w83792d_detect(struct i2c_client *client,
306 struct i2c_board_info *info); 305 struct i2c_board_info *info);
307static int w83792d_remove(struct i2c_client *client); 306static int w83792d_remove(struct i2c_client *client);
308static struct w83792d_data *w83792d_update_device(struct device *dev); 307static struct w83792d_data *w83792d_update_device(struct device *dev);
@@ -314,7 +313,7 @@ static void w83792d_print_debug(struct w83792d_data *data, struct device *dev);
314static void w83792d_init_client(struct i2c_client *client); 313static void w83792d_init_client(struct i2c_client *client);
315 314
316static const struct i2c_device_id w83792d_id[] = { 315static const struct i2c_device_id w83792d_id[] = {
317 { "w83792d", w83792d }, 316 { "w83792d", 0 },
318 { } 317 { }
319}; 318};
320MODULE_DEVICE_TABLE(i2c, w83792d_id); 319MODULE_DEVICE_TABLE(i2c, w83792d_id);
@@ -328,7 +327,7 @@ static struct i2c_driver w83792d_driver = {
328 .remove = w83792d_remove, 327 .remove = w83792d_remove,
329 .id_table = w83792d_id, 328 .id_table = w83792d_id,
330 .detect = w83792d_detect, 329 .detect = w83792d_detect,
331 .address_data = &addr_data, 330 .address_list = normal_i2c,
332}; 331};
333 332
334static inline long in_count_from_reg(int nr, struct w83792d_data *data) 333static inline long in_count_from_reg(int nr, struct w83792d_data *data)
@@ -1263,7 +1262,7 @@ static const struct attribute_group w83792d_group = {
1263 1262
1264/* Return 0 if detection is successful, -ENODEV otherwise */ 1263/* Return 0 if detection is successful, -ENODEV otherwise */
1265static int 1264static int
1266w83792d_detect(struct i2c_client *client, int kind, struct i2c_board_info *info) 1265w83792d_detect(struct i2c_client *client, struct i2c_board_info *info)
1267{ 1266{
1268 struct i2c_adapter *adapter = client->adapter; 1267 struct i2c_adapter *adapter = client->adapter;
1269 int val1, val2; 1268 int val1, val2;
@@ -1273,58 +1272,33 @@ w83792d_detect(struct i2c_client *client, int kind, struct i2c_board_info *info)
1273 return -ENODEV; 1272 return -ENODEV;
1274 } 1273 }
1275 1274
1276 /* The w83792d may be stuck in some other bank than bank 0. This may 1275 if (w83792d_read_value(client, W83792D_REG_CONFIG) & 0x80)
1277 make reading other information impossible. Specify a force=... or 1276 return -ENODEV;
1278 force_*=... parameter, and the Winbond will be reset to the right 1277
1279 bank. */ 1278 val1 = w83792d_read_value(client, W83792D_REG_BANK);
1280 if (kind < 0) { 1279 val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN);
1281 if (w83792d_read_value(client, W83792D_REG_CONFIG) & 0x80) { 1280 /* Check for Winbond ID if in bank 0 */
1282 return -ENODEV; 1281 if (!(val1 & 0x07)) { /* is Bank0 */
1283 } 1282 if ((!(val1 & 0x80) && val2 != 0xa3) ||
1284 val1 = w83792d_read_value(client, W83792D_REG_BANK); 1283 ( (val1 & 0x80) && val2 != 0x5c))
1285 val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN);
1286 /* Check for Winbond ID if in bank 0 */
1287 if (!(val1 & 0x07)) { /* is Bank0 */
1288 if (((!(val1 & 0x80)) && (val2 != 0xa3)) ||
1289 ((val1 & 0x80) && (val2 != 0x5c))) {
1290 return -ENODEV;
1291 }
1292 }
1293 /* If Winbond chip, address of chip and W83792D_REG_I2C_ADDR
1294 should match */
1295 if (w83792d_read_value(client,
1296 W83792D_REG_I2C_ADDR) != address) {
1297 return -ENODEV; 1284 return -ENODEV;
1298 }
1299 } 1285 }
1286 /* If Winbond chip, address of chip and W83792D_REG_I2C_ADDR
1287 should match */
1288 if (w83792d_read_value(client, W83792D_REG_I2C_ADDR) != address)
1289 return -ENODEV;
1300 1290
1301 /* We have either had a force parameter, or we have already detected the 1291 /* Put it now into bank 0 and Vendor ID High Byte */
1302 Winbond. Put it now into bank 0 and Vendor ID High Byte */
1303 w83792d_write_value(client, 1292 w83792d_write_value(client,
1304 W83792D_REG_BANK, 1293 W83792D_REG_BANK,
1305 (w83792d_read_value(client, 1294 (w83792d_read_value(client,
1306 W83792D_REG_BANK) & 0x78) | 0x80); 1295 W83792D_REG_BANK) & 0x78) | 0x80);
1307 1296
1308 /* Determine the chip type. */ 1297 /* Determine the chip type. */
1309 if (kind <= 0) { 1298 val1 = w83792d_read_value(client, W83792D_REG_WCHIPID);
1310 /* get vendor ID */ 1299 val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN);
1311 val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN); 1300 if (val1 != 0x7a || val2 != 0x5c)
1312 if (val2 != 0x5c) { /* the vendor is NOT Winbond */ 1301 return -ENODEV;
1313 return -ENODEV;
1314 }
1315 val1 = w83792d_read_value(client, W83792D_REG_WCHIPID);
1316 if (val1 == 0x7a) {
1317 kind = w83792d;
1318 } else {
1319 if (kind == 0)
1320 dev_warn(&adapter->dev,
1321 "w83792d: Ignoring 'force' parameter for"
1322 " unknown chip at adapter %d, address"
1323 " 0x%02x\n", i2c_adapter_id(adapter),
1324 address);
1325 return -ENODEV;
1326 }
1327 }
1328 1302
1329 strlcpy(info->type, "w83792d", I2C_NAME_SIZE); 1303 strlcpy(info->type, "w83792d", I2C_NAME_SIZE);
1330 1304
diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
index 47dd398f7258..612807d97155 100644
--- a/drivers/hwmon/w83793.c
+++ b/drivers/hwmon/w83793.c
@@ -3,6 +3,10 @@
3 Copyright (C) 2006 Winbond Electronics Corp. 3 Copyright (C) 2006 Winbond Electronics Corp.
4 Yuan Mu 4 Yuan Mu
5 Rudolf Marek <r.marek@assembler.cz> 5 Rudolf Marek <r.marek@assembler.cz>
6 Copyright (C) 2009-2010 Sven Anders <anders@anduras.de>, ANDURAS AG.
7 Watchdog driver part
8 (Based partially on fschmd driver,
9 Copyright 2007-2008 by Hans de Goede)
6 10
7 This program is free software; you can redistribute it and/or modify 11 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 12 it under the terms of the GNU General Public License as published by
@@ -35,13 +39,22 @@
35#include <linux/hwmon-sysfs.h> 39#include <linux/hwmon-sysfs.h>
36#include <linux/err.h> 40#include <linux/err.h>
37#include <linux/mutex.h> 41#include <linux/mutex.h>
42#include <linux/fs.h>
43#include <linux/watchdog.h>
44#include <linux/miscdevice.h>
45#include <linux/uaccess.h>
46#include <linux/kref.h>
47#include <linux/notifier.h>
48#include <linux/reboot.h>
49
50/* Default values */
51#define WATCHDOG_TIMEOUT 2 /* 2 minute default timeout */
38 52
39/* Addresses to scan */ 53/* Addresses to scan */
40static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, 54static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
41 I2C_CLIENT_END }; 55 I2C_CLIENT_END };
42 56
43/* Insmod parameters */ 57/* Insmod parameters */
44I2C_CLIENT_INSMOD_1(w83793);
45 58
46static unsigned short force_subclients[4]; 59static unsigned short force_subclients[4];
47module_param_array(force_subclients, short, NULL, 0); 60module_param_array(force_subclients, short, NULL, 0);
@@ -52,6 +65,18 @@ static int reset;
52module_param(reset, bool, 0); 65module_param(reset, bool, 0);
53MODULE_PARM_DESC(reset, "Set to 1 to reset chip, not recommended"); 66MODULE_PARM_DESC(reset, "Set to 1 to reset chip, not recommended");
54 67
68static int timeout = WATCHDOG_TIMEOUT; /* default timeout in minutes */
69module_param(timeout, int, 0);
70MODULE_PARM_DESC(timeout,
71 "Watchdog timeout in minutes. 2<= timeout <=255 (default="
72 __MODULE_STRING(WATCHDOG_TIMEOUT) ")");
73
74static int nowayout = WATCHDOG_NOWAYOUT;
75module_param(nowayout, int, 0);
76MODULE_PARM_DESC(nowayout,
77 "Watchdog cannot be stopped once started (default="
78 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
79
55/* 80/*
56 Address 0x00, 0x0d, 0x0e, 0x0f in all three banks are reserved 81 Address 0x00, 0x0d, 0x0e, 0x0f in all three banks are reserved
57 as ID, Bank Select registers 82 as ID, Bank Select registers
@@ -73,6 +98,11 @@ MODULE_PARM_DESC(reset, "Set to 1 to reset chip, not recommended");
73#define W83793_REG_VID_LATCHB 0x08 98#define W83793_REG_VID_LATCHB 0x08
74#define W83793_REG_VID_CTRL 0x59 99#define W83793_REG_VID_CTRL 0x59
75 100
101#define W83793_REG_WDT_LOCK 0x01
102#define W83793_REG_WDT_ENABLE 0x02
103#define W83793_REG_WDT_STATUS 0x03
104#define W83793_REG_WDT_TIMEOUT 0x04
105
76static u16 W83793_REG_TEMP_MODE[2] = { 0x5e, 0x5f }; 106static u16 W83793_REG_TEMP_MODE[2] = { 0x5e, 0x5f };
77 107
78#define TEMP_READ 0 108#define TEMP_READ 0
@@ -224,13 +254,42 @@ struct w83793_data {
224 u8 tolerance[3]; /* Temp tolerance(Smart Fan I/II) */ 254 u8 tolerance[3]; /* Temp tolerance(Smart Fan I/II) */
225 u8 sf2_pwm[6][7]; /* Smart FanII: Fan duty cycle */ 255 u8 sf2_pwm[6][7]; /* Smart FanII: Fan duty cycle */
226 u8 sf2_temp[6][7]; /* Smart FanII: Temp level point */ 256 u8 sf2_temp[6][7]; /* Smart FanII: Temp level point */
257
258 /* watchdog */
259 struct i2c_client *client;
260 struct mutex watchdog_lock;
261 struct list_head list; /* member of the watchdog_data_list */
262 struct kref kref;
263 struct miscdevice watchdog_miscdev;
264 unsigned long watchdog_is_open;
265 char watchdog_expect_close;
266 char watchdog_name[10]; /* must be unique to avoid sysfs conflict */
267 unsigned int watchdog_caused_reboot;
268 int watchdog_timeout; /* watchdog timeout in minutes */
227}; 269};
228 270
271/* Somewhat ugly :( global data pointer list with all devices, so that
272 we can find our device data as when using misc_register. There is no
273 other method to get to one's device data from the open file-op and
274 for usage in the reboot notifier callback. */
275static LIST_HEAD(watchdog_data_list);
276
277/* Note this lock not only protect list access, but also data.kref access */
278static DEFINE_MUTEX(watchdog_data_mutex);
279
280/* Release our data struct when we're detached from the i2c client *and* all
281 references to our watchdog device are released */
282static void w83793_release_resources(struct kref *ref)
283{
284 struct w83793_data *data = container_of(ref, struct w83793_data, kref);
285 kfree(data);
286}
287
229static u8 w83793_read_value(struct i2c_client *client, u16 reg); 288static u8 w83793_read_value(struct i2c_client *client, u16 reg);
230static int w83793_write_value(struct i2c_client *client, u16 reg, u8 value); 289static int w83793_write_value(struct i2c_client *client, u16 reg, u8 value);
231static int w83793_probe(struct i2c_client *client, 290static int w83793_probe(struct i2c_client *client,
232 const struct i2c_device_id *id); 291 const struct i2c_device_id *id);
233static int w83793_detect(struct i2c_client *client, int kind, 292static int w83793_detect(struct i2c_client *client,
234 struct i2c_board_info *info); 293 struct i2c_board_info *info);
235static int w83793_remove(struct i2c_client *client); 294static int w83793_remove(struct i2c_client *client);
236static void w83793_init_client(struct i2c_client *client); 295static void w83793_init_client(struct i2c_client *client);
@@ -238,7 +297,7 @@ static void w83793_update_nonvolatile(struct device *dev);
238static struct w83793_data *w83793_update_device(struct device *dev); 297static struct w83793_data *w83793_update_device(struct device *dev);
239 298
240static const struct i2c_device_id w83793_id[] = { 299static const struct i2c_device_id w83793_id[] = {
241 { "w83793", w83793 }, 300 { "w83793", 0 },
242 { } 301 { }
243}; 302};
244MODULE_DEVICE_TABLE(i2c, w83793_id); 303MODULE_DEVICE_TABLE(i2c, w83793_id);
@@ -252,7 +311,7 @@ static struct i2c_driver w83793_driver = {
252 .remove = w83793_remove, 311 .remove = w83793_remove,
253 .id_table = w83793_id, 312 .id_table = w83793_id,
254 .detect = w83793_detect, 313 .detect = w83793_detect,
255 .address_data = &addr_data, 314 .address_list = normal_i2c,
256}; 315};
257 316
258static ssize_t 317static ssize_t
@@ -1064,14 +1123,349 @@ static void w83793_init_client(struct i2c_client *client)
1064 /* Start monitoring */ 1123 /* Start monitoring */
1065 w83793_write_value(client, W83793_REG_CONFIG, 1124 w83793_write_value(client, W83793_REG_CONFIG,
1066 w83793_read_value(client, W83793_REG_CONFIG) | 0x01); 1125 w83793_read_value(client, W83793_REG_CONFIG) | 0x01);
1126}
1127
1128/*
1129 * Watchdog routines
1130 */
1131
1132static int watchdog_set_timeout(struct w83793_data *data, int timeout)
1133{
1134 int ret, mtimeout;
1135
1136 mtimeout = DIV_ROUND_UP(timeout, 60);
1137
1138 if (mtimeout > 255)
1139 return -EINVAL;
1067 1140
1141 mutex_lock(&data->watchdog_lock);
1142 if (!data->client) {
1143 ret = -ENODEV;
1144 goto leave;
1145 }
1146
1147 data->watchdog_timeout = mtimeout;
1148
1149 /* Set Timeout value (in Minutes) */
1150 w83793_write_value(data->client, W83793_REG_WDT_TIMEOUT,
1151 data->watchdog_timeout);
1152
1153 ret = mtimeout * 60;
1154
1155leave:
1156 mutex_unlock(&data->watchdog_lock);
1157 return ret;
1158}
1159
1160static int watchdog_get_timeout(struct w83793_data *data)
1161{
1162 int timeout;
1163
1164 mutex_lock(&data->watchdog_lock);
1165 timeout = data->watchdog_timeout * 60;
1166 mutex_unlock(&data->watchdog_lock);
1167
1168 return timeout;
1169}
1170
1171static int watchdog_trigger(struct w83793_data *data)
1172{
1173 int ret = 0;
1174
1175 mutex_lock(&data->watchdog_lock);
1176 if (!data->client) {
1177 ret = -ENODEV;
1178 goto leave;
1179 }
1180
1181 /* Set Timeout value (in Minutes) */
1182 w83793_write_value(data->client, W83793_REG_WDT_TIMEOUT,
1183 data->watchdog_timeout);
1184
1185leave:
1186 mutex_unlock(&data->watchdog_lock);
1187 return ret;
1188}
1189
1190static int watchdog_enable(struct w83793_data *data)
1191{
1192 int ret = 0;
1193
1194 mutex_lock(&data->watchdog_lock);
1195 if (!data->client) {
1196 ret = -ENODEV;
1197 goto leave;
1198 }
1199
1200 /* Set initial timeout */
1201 w83793_write_value(data->client, W83793_REG_WDT_TIMEOUT,
1202 data->watchdog_timeout);
1203
1204 /* Enable Soft Watchdog */
1205 w83793_write_value(data->client, W83793_REG_WDT_LOCK, 0x55);
1206
1207leave:
1208 mutex_unlock(&data->watchdog_lock);
1209 return ret;
1210}
1211
1212static int watchdog_disable(struct w83793_data *data)
1213{
1214 int ret = 0;
1215
1216 mutex_lock(&data->watchdog_lock);
1217 if (!data->client) {
1218 ret = -ENODEV;
1219 goto leave;
1220 }
1221
1222 /* Disable Soft Watchdog */
1223 w83793_write_value(data->client, W83793_REG_WDT_LOCK, 0xAA);
1224
1225leave:
1226 mutex_unlock(&data->watchdog_lock);
1227 return ret;
1228}
1229
1230static int watchdog_open(struct inode *inode, struct file *filp)
1231{
1232 struct w83793_data *pos, *data = NULL;
1233 int watchdog_is_open;
1234
1235 /* We get called from drivers/char/misc.c with misc_mtx hold, and we
1236 call misc_register() from w83793_probe() with watchdog_data_mutex
1237 hold, as misc_register() takes the misc_mtx lock, this is a possible
1238 deadlock, so we use mutex_trylock here. */
1239 if (!mutex_trylock(&watchdog_data_mutex))
1240 return -ERESTARTSYS;
1241 list_for_each_entry(pos, &watchdog_data_list, list) {
1242 if (pos->watchdog_miscdev.minor == iminor(inode)) {
1243 data = pos;
1244 break;
1245 }
1246 }
1247
1248 /* Check, if device is already open */
1249 watchdog_is_open = test_and_set_bit(0, &data->watchdog_is_open);
1250
1251 /* Increase data reference counter (if not already done).
1252 Note we can never not have found data, so we don't check for this */
1253 if (!watchdog_is_open)
1254 kref_get(&data->kref);
1255
1256 mutex_unlock(&watchdog_data_mutex);
1257
1258 /* Check, if device is already open and possibly issue error */
1259 if (watchdog_is_open)
1260 return -EBUSY;
1261
1262 /* Enable Soft Watchdog */
1263 watchdog_enable(data);
1264
1265 /* Store pointer to data into filp's private data */
1266 filp->private_data = data;
1267
1268 return nonseekable_open(inode, filp);
1269}
1270
1271static int watchdog_close(struct inode *inode, struct file *filp)
1272{
1273 struct w83793_data *data = filp->private_data;
1274
1275 if (data->watchdog_expect_close) {
1276 watchdog_disable(data);
1277 data->watchdog_expect_close = 0;
1278 } else {
1279 watchdog_trigger(data);
1280 dev_crit(&data->client->dev,
1281 "unexpected close, not stopping watchdog!\n");
1282 }
1283
1284 clear_bit(0, &data->watchdog_is_open);
1285
1286 /* Decrease data reference counter */
1287 mutex_lock(&watchdog_data_mutex);
1288 kref_put(&data->kref, w83793_release_resources);
1289 mutex_unlock(&watchdog_data_mutex);
1290
1291 return 0;
1068} 1292}
1069 1293
1294static ssize_t watchdog_write(struct file *filp, const char __user *buf,
1295 size_t count, loff_t *offset)
1296{
1297 ssize_t ret;
1298 struct w83793_data *data = filp->private_data;
1299
1300 if (count) {
1301 if (!nowayout) {
1302 size_t i;
1303
1304 /* Clear it in case it was set with a previous write */
1305 data->watchdog_expect_close = 0;
1306
1307 for (i = 0; i != count; i++) {
1308 char c;
1309 if (get_user(c, buf + i))
1310 return -EFAULT;
1311 if (c == 'V')
1312 data->watchdog_expect_close = 1;
1313 }
1314 }
1315 ret = watchdog_trigger(data);
1316 if (ret < 0)
1317 return ret;
1318 }
1319 return count;
1320}
1321
1322static int watchdog_ioctl(struct inode *inode, struct file *filp,
1323 unsigned int cmd, unsigned long arg)
1324{
1325 static struct watchdog_info ident = {
1326 .options = WDIOF_KEEPALIVEPING |
1327 WDIOF_SETTIMEOUT |
1328 WDIOF_CARDRESET,
1329 .identity = "w83793 watchdog"
1330 };
1331
1332 int val, ret = 0;
1333 struct w83793_data *data = filp->private_data;
1334
1335 switch (cmd) {
1336 case WDIOC_GETSUPPORT:
1337 if (!nowayout)
1338 ident.options |= WDIOF_MAGICCLOSE;
1339 if (copy_to_user((void __user *)arg, &ident, sizeof(ident)))
1340 ret = -EFAULT;
1341 break;
1342
1343 case WDIOC_GETSTATUS:
1344 val = data->watchdog_caused_reboot ? WDIOF_CARDRESET : 0;
1345 ret = put_user(val, (int __user *)arg);
1346 break;
1347
1348 case WDIOC_GETBOOTSTATUS:
1349 ret = put_user(0, (int __user *)arg);
1350 break;
1351
1352 case WDIOC_KEEPALIVE:
1353 ret = watchdog_trigger(data);
1354 break;
1355
1356 case WDIOC_GETTIMEOUT:
1357 val = watchdog_get_timeout(data);
1358 ret = put_user(val, (int __user *)arg);
1359 break;
1360
1361 case WDIOC_SETTIMEOUT:
1362 if (get_user(val, (int __user *)arg)) {
1363 ret = -EFAULT;
1364 break;
1365 }
1366 ret = watchdog_set_timeout(data, val);
1367 if (ret > 0)
1368 ret = put_user(ret, (int __user *)arg);
1369 break;
1370
1371 case WDIOC_SETOPTIONS:
1372 if (get_user(val, (int __user *)arg)) {
1373 ret = -EFAULT;
1374 break;
1375 }
1376
1377 if (val & WDIOS_DISABLECARD)
1378 ret = watchdog_disable(data);
1379 else if (val & WDIOS_ENABLECARD)
1380 ret = watchdog_enable(data);
1381 else
1382 ret = -EINVAL;
1383
1384 break;
1385 default:
1386 ret = -ENOTTY;
1387 }
1388
1389 return ret;
1390}
1391
1392static const struct file_operations watchdog_fops = {
1393 .owner = THIS_MODULE,
1394 .llseek = no_llseek,
1395 .open = watchdog_open,
1396 .release = watchdog_close,
1397 .write = watchdog_write,
1398 .ioctl = watchdog_ioctl,
1399};
1400
1401/*
1402 * Notifier for system down
1403 */
1404
1405static int watchdog_notify_sys(struct notifier_block *this, unsigned long code,
1406 void *unused)
1407{
1408 struct w83793_data *data = NULL;
1409
1410 if (code == SYS_DOWN || code == SYS_HALT) {
1411
1412 /* Disable each registered watchdog */
1413 mutex_lock(&watchdog_data_mutex);
1414 list_for_each_entry(data, &watchdog_data_list, list) {
1415 if (data->watchdog_miscdev.minor)
1416 watchdog_disable(data);
1417 }
1418 mutex_unlock(&watchdog_data_mutex);
1419 }
1420
1421 return NOTIFY_DONE;
1422}
1423
1424/*
1425 * The WDT needs to learn about soft shutdowns in order to
1426 * turn the timebomb registers off.
1427 */
1428
1429static struct notifier_block watchdog_notifier = {
1430 .notifier_call = watchdog_notify_sys,
1431};
1432
1433/*
1434 * Init / remove routines
1435 */
1436
1070static int w83793_remove(struct i2c_client *client) 1437static int w83793_remove(struct i2c_client *client)
1071{ 1438{
1072 struct w83793_data *data = i2c_get_clientdata(client); 1439 struct w83793_data *data = i2c_get_clientdata(client);
1073 struct device *dev = &client->dev; 1440 struct device *dev = &client->dev;
1074 int i; 1441 int i, tmp;
1442
1443 /* Unregister the watchdog (if registered) */
1444 if (data->watchdog_miscdev.minor) {
1445 misc_deregister(&data->watchdog_miscdev);
1446
1447 if (data->watchdog_is_open) {
1448 dev_warn(&client->dev,
1449 "i2c client detached with watchdog open! "
1450 "Stopping watchdog.\n");
1451 watchdog_disable(data);
1452 }
1453
1454 mutex_lock(&watchdog_data_mutex);
1455 list_del(&data->list);
1456 mutex_unlock(&watchdog_data_mutex);
1457
1458 /* Tell the watchdog code the client is gone */
1459 mutex_lock(&data->watchdog_lock);
1460 data->client = NULL;
1461 mutex_unlock(&data->watchdog_lock);
1462 }
1463
1464 /* Reset Configuration Register to Disable Watch Dog Registers */
1465 tmp = w83793_read_value(client, W83793_REG_CONFIG);
1466 w83793_write_value(client, W83793_REG_CONFIG, tmp & ~0x04);
1467
1468 unregister_reboot_notifier(&watchdog_notifier);
1075 1469
1076 hwmon_device_unregister(data->hwmon_dev); 1470 hwmon_device_unregister(data->hwmon_dev);
1077 1471
@@ -1100,7 +1494,10 @@ static int w83793_remove(struct i2c_client *client)
1100 if (data->lm75[1] != NULL) 1494 if (data->lm75[1] != NULL)
1101 i2c_unregister_device(data->lm75[1]); 1495 i2c_unregister_device(data->lm75[1]);
1102 1496
1103 kfree(data); 1497 /* Decrease data reference counter */
1498 mutex_lock(&watchdog_data_mutex);
1499 kref_put(&data->kref, w83793_release_resources);
1500 mutex_unlock(&watchdog_data_mutex);
1104 1501
1105 return 0; 1502 return 0;
1106} 1503}
@@ -1161,10 +1558,10 @@ ERROR_SC_0:
1161} 1558}
1162 1559
1163/* Return 0 if detection is successful, -ENODEV otherwise */ 1560/* Return 0 if detection is successful, -ENODEV otherwise */
1164static int w83793_detect(struct i2c_client *client, int kind, 1561static int w83793_detect(struct i2c_client *client,
1165 struct i2c_board_info *info) 1562 struct i2c_board_info *info)
1166{ 1563{
1167 u8 tmp, bank; 1564 u8 tmp, bank, chip_id;
1168 struct i2c_adapter *adapter = client->adapter; 1565 struct i2c_adapter *adapter = client->adapter;
1169 unsigned short address = client->addr; 1566 unsigned short address = client->addr;
1170 1567
@@ -1174,44 +1571,27 @@ static int w83793_detect(struct i2c_client *client, int kind,
1174 1571
1175 bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL); 1572 bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL);
1176 1573
1177 if (kind < 0) { 1574 tmp = bank & 0x80 ? 0x5c : 0xa3;
1178 tmp = bank & 0x80 ? 0x5c : 0xa3; 1575 /* Check Winbond vendor ID */
1179 /* Check Winbond vendor ID */ 1576 if (tmp != i2c_smbus_read_byte_data(client, W83793_REG_VENDORID)) {
1180 if (tmp != i2c_smbus_read_byte_data(client, 1577 pr_debug("w83793: Detection failed at check vendor id\n");
1181 W83793_REG_VENDORID)) { 1578 return -ENODEV;
1182 pr_debug("w83793: Detection failed at check "
1183 "vendor id\n");
1184 return -ENODEV;
1185 }
1186
1187 /* If Winbond chip, address of chip and W83793_REG_I2C_ADDR
1188 should match */
1189 if ((bank & 0x07) == 0
1190 && i2c_smbus_read_byte_data(client, W83793_REG_I2C_ADDR) !=
1191 (address << 1)) {
1192 pr_debug("w83793: Detection failed at check "
1193 "i2c addr\n");
1194 return -ENODEV;
1195 }
1196
1197 } 1579 }
1198 1580
1199 /* We have either had a force parameter, or we have already detected the 1581 /* If Winbond chip, address of chip and W83793_REG_I2C_ADDR
1200 Winbond. Determine the chip type now */ 1582 should match */
1201 1583 if ((bank & 0x07) == 0
1202 if (kind <= 0) { 1584 && i2c_smbus_read_byte_data(client, W83793_REG_I2C_ADDR) !=
1203 if (0x7b == i2c_smbus_read_byte_data(client, 1585 (address << 1)) {
1204 W83793_REG_CHIPID)) { 1586 pr_debug("w83793: Detection failed at check i2c addr\n");
1205 kind = w83793; 1587 return -ENODEV;
1206 } else {
1207 if (kind == 0)
1208 dev_warn(&adapter->dev, "w83793: Ignoring "
1209 "'force' parameter for unknown chip "
1210 "at address 0x%02x\n", address);
1211 return -ENODEV;
1212 }
1213 } 1588 }
1214 1589
1590 /* Determine the chip type now */
1591 chip_id = i2c_smbus_read_byte_data(client, W83793_REG_CHIPID);
1592 if (chip_id != 0x7b)
1593 return -ENODEV;
1594
1215 strlcpy(info->type, "w83793", I2C_NAME_SIZE); 1595 strlcpy(info->type, "w83793", I2C_NAME_SIZE);
1216 1596
1217 return 0; 1597 return 0;
@@ -1221,6 +1601,7 @@ static int w83793_probe(struct i2c_client *client,
1221 const struct i2c_device_id *id) 1601 const struct i2c_device_id *id)
1222{ 1602{
1223 struct device *dev = &client->dev; 1603 struct device *dev = &client->dev;
1604 const int watchdog_minors[] = { WATCHDOG_MINOR, 212, 213, 214, 215 };
1224 struct w83793_data *data; 1605 struct w83793_data *data;
1225 int i, tmp, val, err; 1606 int i, tmp, val, err;
1226 int files_fan = ARRAY_SIZE(w83793_left_fan) / 7; 1607 int files_fan = ARRAY_SIZE(w83793_left_fan) / 7;
@@ -1236,6 +1617,14 @@ static int w83793_probe(struct i2c_client *client,
1236 i2c_set_clientdata(client, data); 1617 i2c_set_clientdata(client, data);
1237 data->bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL); 1618 data->bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL);
1238 mutex_init(&data->update_lock); 1619 mutex_init(&data->update_lock);
1620 mutex_init(&data->watchdog_lock);
1621 INIT_LIST_HEAD(&data->list);
1622 kref_init(&data->kref);
1623
1624 /* Store client pointer in our data struct for watchdog usage
1625 (where the client is found through a data ptr instead of the
1626 otherway around) */
1627 data->client = client;
1239 1628
1240 err = w83793_detect_subclients(client); 1629 err = w83793_detect_subclients(client);
1241 if (err) 1630 if (err)
@@ -1398,8 +1787,77 @@ static int w83793_probe(struct i2c_client *client,
1398 goto exit_remove; 1787 goto exit_remove;
1399 } 1788 }
1400 1789
1790 /* Watchdog initialization */
1791
1792 /* Register boot notifier */
1793 err = register_reboot_notifier(&watchdog_notifier);
1794 if (err != 0) {
1795 dev_err(&client->dev,
1796 "cannot register reboot notifier (err=%d)\n", err);
1797 goto exit_devunreg;
1798 }
1799
1800 /* Enable Watchdog registers.
1801 Set Configuration Register to Enable Watch Dog Registers
1802 (Bit 2) = XXXX, X1XX. */
1803 tmp = w83793_read_value(client, W83793_REG_CONFIG);
1804 w83793_write_value(client, W83793_REG_CONFIG, tmp | 0x04);
1805
1806 /* Set the default watchdog timeout */
1807 data->watchdog_timeout = timeout;
1808
1809 /* Check, if last reboot was caused by watchdog */
1810 data->watchdog_caused_reboot =
1811 w83793_read_value(data->client, W83793_REG_WDT_STATUS) & 0x01;
1812
1813 /* Disable Soft Watchdog during initialiation */
1814 watchdog_disable(data);
1815
1816 /* We take the data_mutex lock early so that watchdog_open() cannot
1817 run when misc_register() has completed, but we've not yet added
1818 our data to the watchdog_data_list (and set the default timeout) */
1819 mutex_lock(&watchdog_data_mutex);
1820 for (i = 0; i < ARRAY_SIZE(watchdog_minors); i++) {
1821 /* Register our watchdog part */
1822 snprintf(data->watchdog_name, sizeof(data->watchdog_name),
1823 "watchdog%c", (i == 0) ? '\0' : ('0' + i));
1824 data->watchdog_miscdev.name = data->watchdog_name;
1825 data->watchdog_miscdev.fops = &watchdog_fops;
1826 data->watchdog_miscdev.minor = watchdog_minors[i];
1827
1828 err = misc_register(&data->watchdog_miscdev);
1829 if (err == -EBUSY)
1830 continue;
1831 if (err) {
1832 data->watchdog_miscdev.minor = 0;
1833 dev_err(&client->dev,
1834 "Registering watchdog chardev: %d\n", err);
1835 break;
1836 }
1837
1838 list_add(&data->list, &watchdog_data_list);
1839
1840 dev_info(&client->dev,
1841 "Registered watchdog chardev major 10, minor: %d\n",
1842 watchdog_minors[i]);
1843 break;
1844 }
1845 if (i == ARRAY_SIZE(watchdog_minors)) {
1846 data->watchdog_miscdev.minor = 0;
1847 dev_warn(&client->dev, "Couldn't register watchdog chardev "
1848 "(due to no free minor)\n");
1849 }
1850
1851 mutex_unlock(&watchdog_data_mutex);
1852
1401 return 0; 1853 return 0;
1402 1854
1855 /* Unregister hwmon device */
1856
1857exit_devunreg:
1858
1859 hwmon_device_unregister(data->hwmon_dev);
1860
1403 /* Unregister sysfs hooks */ 1861 /* Unregister sysfs hooks */
1404 1862
1405exit_remove: 1863exit_remove:
@@ -1646,7 +2104,7 @@ static void __exit sensors_w83793_exit(void)
1646 i2c_del_driver(&w83793_driver); 2104 i2c_del_driver(&w83793_driver);
1647} 2105}
1648 2106
1649MODULE_AUTHOR("Yuan Mu"); 2107MODULE_AUTHOR("Yuan Mu, Sven Anders");
1650MODULE_DESCRIPTION("w83793 driver"); 2108MODULE_DESCRIPTION("w83793 driver");
1651MODULE_LICENSE("GPL"); 2109MODULE_LICENSE("GPL");
1652 2110
diff --git a/drivers/hwmon/w83l785ts.c b/drivers/hwmon/w83l785ts.c
index ea295b9fc4f4..20781def65ed 100644
--- a/drivers/hwmon/w83l785ts.c
+++ b/drivers/hwmon/w83l785ts.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * w83l785ts.c - Part of lm_sensors, Linux kernel modules for hardware 2 * w83l785ts.c - Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring 3 * monitoring
4 * Copyright (C) 2003-2004 Jean Delvare <khali@linux-fr.org> 4 * Copyright (C) 2003-2009 Jean Delvare <khali@linux-fr.org>
5 * 5 *
6 * Inspired from the lm83 driver. The W83L785TS-S is a sensor chip made 6 * Inspired from the lm83 driver. The W83L785TS-S is a sensor chip made
7 * by Winbond. It reports a single external temperature with a 1 deg 7 * by Winbond. It reports a single external temperature with a 1 deg
@@ -52,12 +52,6 @@
52static const unsigned short normal_i2c[] = { 0x2e, I2C_CLIENT_END }; 52static const unsigned short normal_i2c[] = { 0x2e, I2C_CLIENT_END };
53 53
54/* 54/*
55 * Insmod parameters
56 */
57
58I2C_CLIENT_INSMOD_1(w83l785ts);
59
60/*
61 * The W83L785TS-S registers 55 * The W83L785TS-S registers
62 * Manufacturer ID is 0x5CA3 for Winbond. 56 * Manufacturer ID is 0x5CA3 for Winbond.
63 */ 57 */
@@ -83,7 +77,7 @@ I2C_CLIENT_INSMOD_1(w83l785ts);
83 77
84static int w83l785ts_probe(struct i2c_client *client, 78static int w83l785ts_probe(struct i2c_client *client,
85 const struct i2c_device_id *id); 79 const struct i2c_device_id *id);
86static int w83l785ts_detect(struct i2c_client *client, int kind, 80static int w83l785ts_detect(struct i2c_client *client,
87 struct i2c_board_info *info); 81 struct i2c_board_info *info);
88static int w83l785ts_remove(struct i2c_client *client); 82static int w83l785ts_remove(struct i2c_client *client);
89static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval); 83static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval);
@@ -94,7 +88,7 @@ static struct w83l785ts_data *w83l785ts_update_device(struct device *dev);
94 */ 88 */
95 89
96static const struct i2c_device_id w83l785ts_id[] = { 90static const struct i2c_device_id w83l785ts_id[] = {
97 { "w83l785ts", w83l785ts }, 91 { "w83l785ts", 0 },
98 { } 92 { }
99}; 93};
100MODULE_DEVICE_TABLE(i2c, w83l785ts_id); 94MODULE_DEVICE_TABLE(i2c, w83l785ts_id);
@@ -108,7 +102,7 @@ static struct i2c_driver w83l785ts_driver = {
108 .remove = w83l785ts_remove, 102 .remove = w83l785ts_remove,
109 .id_table = w83l785ts_id, 103 .id_table = w83l785ts_id,
110 .detect = w83l785ts_detect, 104 .detect = w83l785ts_detect,
111 .address_data = &addr_data, 105 .address_list = normal_i2c,
112}; 106};
113 107
114/* 108/*
@@ -146,60 +140,36 @@ static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, show_temp, NULL, 1);
146 */ 140 */
147 141
148/* Return 0 if detection is successful, -ENODEV otherwise */ 142/* Return 0 if detection is successful, -ENODEV otherwise */
149static int w83l785ts_detect(struct i2c_client *new_client, int kind, 143static int w83l785ts_detect(struct i2c_client *client,
150 struct i2c_board_info *info) 144 struct i2c_board_info *info)
151{ 145{
152 struct i2c_adapter *adapter = new_client->adapter; 146 struct i2c_adapter *adapter = client->adapter;
147 u16 man_id;
148 u8 chip_id;
153 149
154 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 150 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
155 return -ENODEV; 151 return -ENODEV;
156 152
157 /* 153 /* detection */
158 * Now we do the remaining detection. A negative kind means that 154 if ((w83l785ts_read_value(client, W83L785TS_REG_CONFIG, 0) & 0x80)
159 * the driver was loaded with no force parameter (default), so we 155 || (w83l785ts_read_value(client, W83L785TS_REG_TYPE, 0) & 0xFC)) {
160 * must both detect and identify the chip (actually there is only 156 dev_dbg(&adapter->dev,
161 * one possible kind of chip for now, W83L785TS-S). A zero kind means 157 "W83L785TS-S detection failed at 0x%02x\n",
162 * that the driver was loaded with the force parameter, the detection 158 client->addr);
163 * step shall be skipped. A positive kind means that the driver 159 return -ENODEV;
164 * was loaded with the force parameter and a given kind of chip is
165 * requested, so both the detection and the identification steps
166 * are skipped.
167 */
168 if (kind < 0) { /* detection */
169 if (((w83l785ts_read_value(new_client,
170 W83L785TS_REG_CONFIG, 0) & 0x80) != 0x00)
171 || ((w83l785ts_read_value(new_client,
172 W83L785TS_REG_TYPE, 0) & 0xFC) != 0x00)) {
173 dev_dbg(&adapter->dev,
174 "W83L785TS-S detection failed at 0x%02x.\n",
175 new_client->addr);
176 return -ENODEV;
177 }
178 } 160 }
179 161
180 if (kind <= 0) { /* identification */ 162 /* Identification */
181 u16 man_id; 163 man_id = (w83l785ts_read_value(client, W83L785TS_REG_MAN_ID1, 0) << 8)
182 u8 chip_id; 164 + w83l785ts_read_value(client, W83L785TS_REG_MAN_ID2, 0);
183 165 chip_id = w83l785ts_read_value(client, W83L785TS_REG_CHIP_ID, 0);
184 man_id = (w83l785ts_read_value(new_client, 166
185 W83L785TS_REG_MAN_ID1, 0) << 8) + 167 if (man_id != 0x5CA3 /* Winbond */
186 w83l785ts_read_value(new_client, 168 || chip_id != 0x70) { /* W83L785TS-S */
187 W83L785TS_REG_MAN_ID2, 0); 169 dev_dbg(&adapter->dev,
188 chip_id = w83l785ts_read_value(new_client, 170 "Unsupported chip (man_id=0x%04X, chip_id=0x%02X)\n",
189 W83L785TS_REG_CHIP_ID, 0); 171 man_id, chip_id);
190 172 return -ENODEV;
191 if (man_id == 0x5CA3) { /* Winbond */
192 if (chip_id == 0x70) { /* W83L785TS-S */
193 kind = w83l785ts;
194 }
195 }
196
197 if (kind <= 0) { /* identification failed */
198 dev_info(&adapter->dev,
199 "Unsupported chip (man_id=0x%04X, "
200 "chip_id=0x%02X).\n", man_id, chip_id);
201 return -ENODEV;
202 }
203 } 173 }
204 174
205 strlcpy(info->type, "w83l785ts", I2C_NAME_SIZE); 175 strlcpy(info->type, "w83l785ts", I2C_NAME_SIZE);
diff --git a/drivers/hwmon/w83l786ng.c b/drivers/hwmon/w83l786ng.c
index badca769f350..0254e181893d 100644
--- a/drivers/hwmon/w83l786ng.c
+++ b/drivers/hwmon/w83l786ng.c
@@ -38,7 +38,6 @@
38static const unsigned short normal_i2c[] = { 0x2e, 0x2f, I2C_CLIENT_END }; 38static const unsigned short normal_i2c[] = { 0x2e, 0x2f, I2C_CLIENT_END };
39 39
40/* Insmod parameters */ 40/* Insmod parameters */
41I2C_CLIENT_INSMOD_1(w83l786ng);
42 41
43static int reset; 42static int reset;
44module_param(reset, bool, 0); 43module_param(reset, bool, 0);
@@ -147,14 +146,14 @@ struct w83l786ng_data {
147 146
148static int w83l786ng_probe(struct i2c_client *client, 147static int w83l786ng_probe(struct i2c_client *client,
149 const struct i2c_device_id *id); 148 const struct i2c_device_id *id);
150static int w83l786ng_detect(struct i2c_client *client, int kind, 149static int w83l786ng_detect(struct i2c_client *client,
151 struct i2c_board_info *info); 150 struct i2c_board_info *info);
152static int w83l786ng_remove(struct i2c_client *client); 151static int w83l786ng_remove(struct i2c_client *client);
153static void w83l786ng_init_client(struct i2c_client *client); 152static void w83l786ng_init_client(struct i2c_client *client);
154static struct w83l786ng_data *w83l786ng_update_device(struct device *dev); 153static struct w83l786ng_data *w83l786ng_update_device(struct device *dev);
155 154
156static const struct i2c_device_id w83l786ng_id[] = { 155static const struct i2c_device_id w83l786ng_id[] = {
157 { "w83l786ng", w83l786ng }, 156 { "w83l786ng", 0 },
158 { } 157 { }
159}; 158};
160MODULE_DEVICE_TABLE(i2c, w83l786ng_id); 159MODULE_DEVICE_TABLE(i2c, w83l786ng_id);
@@ -168,7 +167,7 @@ static struct i2c_driver w83l786ng_driver = {
168 .remove = w83l786ng_remove, 167 .remove = w83l786ng_remove,
169 .id_table = w83l786ng_id, 168 .id_table = w83l786ng_id,
170 .detect = w83l786ng_detect, 169 .detect = w83l786ng_detect,
171 .address_data = &addr_data, 170 .address_list = normal_i2c,
172}; 171};
173 172
174static u8 173static u8
@@ -586,57 +585,34 @@ static const struct attribute_group w83l786ng_group = {
586}; 585};
587 586
588static int 587static int
589w83l786ng_detect(struct i2c_client *client, int kind, 588w83l786ng_detect(struct i2c_client *client, struct i2c_board_info *info)
590 struct i2c_board_info *info)
591{ 589{
592 struct i2c_adapter *adapter = client->adapter; 590 struct i2c_adapter *adapter = client->adapter;
591 u16 man_id;
592 u8 chip_id;
593 593
594 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 594 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
595 return -ENODEV; 595 return -ENODEV;
596 } 596 }
597 597
598 /* 598 /* Detection */
599 * Now we do the remaining detection. A negative kind means that 599 if ((w83l786ng_read_value(client, W83L786NG_REG_CONFIG) & 0x80)) {
600 * the driver was loaded with no force parameter (default), so we 600 dev_dbg(&adapter->dev, "W83L786NG detection failed at 0x%02x\n",
601 * must both detect and identify the chip (actually there is only 601 client->addr);
602 * one possible kind of chip for now, W83L786NG). A zero kind means 602 return -ENODEV;
603 * that the driver was loaded with the force parameter, the detection
604 * step shall be skipped. A positive kind means that the driver
605 * was loaded with the force parameter and a given kind of chip is
606 * requested, so both the detection and the identification steps
607 * are skipped.
608 */
609 if (kind < 0) { /* detection */
610 if (((w83l786ng_read_value(client,
611 W83L786NG_REG_CONFIG) & 0x80) != 0x00)) {
612 dev_dbg(&adapter->dev,
613 "W83L786NG detection failed at 0x%02x.\n",
614 client->addr);
615 return -ENODEV;
616 }
617 } 603 }
618 604
619 if (kind <= 0) { /* identification */ 605 /* Identification */
620 u16 man_id; 606 man_id = (w83l786ng_read_value(client, W83L786NG_REG_MAN_ID1) << 8) +
621 u8 chip_id; 607 w83l786ng_read_value(client, W83L786NG_REG_MAN_ID2);
622 608 chip_id = w83l786ng_read_value(client, W83L786NG_REG_CHIP_ID);
623 man_id = (w83l786ng_read_value(client,
624 W83L786NG_REG_MAN_ID1) << 8) +
625 w83l786ng_read_value(client, W83L786NG_REG_MAN_ID2);
626 chip_id = w83l786ng_read_value(client, W83L786NG_REG_CHIP_ID);
627
628 if (man_id == 0x5CA3) { /* Winbond */
629 if (chip_id == 0x80) { /* W83L786NG */
630 kind = w83l786ng;
631 }
632 }
633 609
634 if (kind <= 0) { /* identification failed */ 610 if (man_id != 0x5CA3 || /* Winbond */
635 dev_info(&adapter->dev, 611 chip_id != 0x80) { /* W83L786NG */
636 "Unsupported chip (man_id=0x%04X, " 612 dev_dbg(&adapter->dev,
637 "chip_id=0x%02X).\n", man_id, chip_id); 613 "Unsupported chip (man_id=0x%04X, chip_id=0x%02X)\n",
638 return -ENODEV; 614 man_id, chip_id);
639 } 615 return -ENODEV;
640 } 616 }
641 617
642 strlcpy(info->type, "w83l786ng", I2C_NAME_SIZE); 618 strlcpy(info->type, "w83l786ng", I2C_NAME_SIZE);
diff --git a/drivers/hwmon/wm831x-hwmon.c b/drivers/hwmon/wm831x-hwmon.c
index c16e9e74c356..97b1f834a471 100644
--- a/drivers/hwmon/wm831x-hwmon.c
+++ b/drivers/hwmon/wm831x-hwmon.c
@@ -24,6 +24,7 @@
24#include <linux/err.h> 24#include <linux/err.h>
25#include <linux/hwmon.h> 25#include <linux/hwmon.h>
26#include <linux/hwmon-sysfs.h> 26#include <linux/hwmon-sysfs.h>
27#include <linux/slab.h>
27 28
28#include <linux/mfd/wm831x/core.h> 29#include <linux/mfd/wm831x/core.h>
29#include <linux/mfd/wm831x/auxadc.h> 30#include <linux/mfd/wm831x/auxadc.h>