aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-03-21 13:37:25 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-03-21 13:37:25 -0400
commit31f6765266417c0d99f0e922fe82848a7c9c2ae9 (patch)
tree2d5914dac0a918baad37decd3845b8c206051420
parentd15d76448bb58c7832e954b6a8f1e301720b7866 (diff)
parent312869ec935ab3bb67b7ba641a7d11230555aff5 (diff)
Merge tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging
Pull hwmon changes for v3.4 from Guenter Roeck: "Mostly cleanup. No new drivers this time around, but support for several chips added to existing drivers: TPS40400, TPS40422, MTD040, MAX34446, ZL9101M, ZL9117M, and LM96080. Also, added watchdog support for SCH56xx, and additional attributes for a couple of drivers." * tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: (137 commits) hwmon: (sch56xx) Add support for the integrated watchdog (v2) hwmon: (w83627ehf) Add support for temperature offset registers hwmon: (jc42) Remove unnecessary device IDs hwmon: (zl6100) Add support for ZL9101M and ZL9117M hwmon: (adm1275) Add support for ADM1075 hwmon: (max34440) Add support for MAX34446 hwmon: (pmbus) Add more virtual registers hwmon: (pmbus) Add support for Lineage Power MDT040 hwmon: (pmbus) Add support for TI TPS40400 and TPS40422 hwmon: (max34440) Add support for 'lowest' output voltage attribute hwmon: (jc42) Convert to use devm_kzalloc hwmon: (max16065) Convert to use devm_kzalloc hwmon: (smm665) Convert to use devm_kzalloc hwmon: (ltc4261) Convert to use devm_kzalloc hwmon: (pmbus) Simplify remove functions hwmon: (pmbus) Convert pmbus drivers to use devm_kzalloc hwmon: (lineage-pem) Convert to use devm_kzalloc hwmon: (hwmon-vid) Fix checkpatch issues hwmon: (hwmon-vid) Add new entries to VRM model table hwmon: (lm80) Add detection of NatSemi/TI LM96080 ...
-rw-r--r--Documentation/hwmon/adm127530
-rw-r--r--Documentation/hwmon/jc4239
-rw-r--r--Documentation/hwmon/lm809
-rw-r--r--Documentation/hwmon/max3444030
-rw-r--r--Documentation/hwmon/pmbus9
-rw-r--r--Documentation/hwmon/sch56275
-rw-r--r--Documentation/hwmon/sch56363
-rw-r--r--Documentation/hwmon/zl61008
-rw-r--r--drivers/hwmon/Kconfig10
-rw-r--r--drivers/hwmon/abituguru.c584
-rw-r--r--drivers/hwmon/abituguru3.c267
-rw-r--r--drivers/hwmon/ad7314.c12
-rw-r--r--drivers/hwmon/ad7414.c21
-rw-r--r--drivers/hwmon/ad7418.c25
-rw-r--r--drivers/hwmon/adcxx.c13
-rw-r--r--drivers/hwmon/adm1021.c97
-rw-r--r--drivers/hwmon/adm1025.c76
-rw-r--r--drivers/hwmon/adm1026.c504
-rw-r--r--drivers/hwmon/adm1029.c47
-rw-r--r--drivers/hwmon/adm1031.c73
-rw-r--r--drivers/hwmon/adm9240.c86
-rw-r--r--drivers/hwmon/ads1015.c13
-rw-r--r--drivers/hwmon/ads7828.c59
-rw-r--r--drivers/hwmon/ads7871.c39
-rw-r--r--drivers/hwmon/adt7411.c14
-rw-r--r--drivers/hwmon/adt7462.c30
-rw-r--r--drivers/hwmon/adt7470.c19
-rw-r--r--drivers/hwmon/adt7475.c105
-rw-r--r--drivers/hwmon/amc6821.c74
-rw-r--r--drivers/hwmon/applesmc.c14
-rw-r--r--drivers/hwmon/asb100.c200
-rw-r--r--drivers/hwmon/asc7621.c8
-rw-r--r--drivers/hwmon/asus_atk0110.c18
-rw-r--r--drivers/hwmon/atxp1.c173
-rw-r--r--drivers/hwmon/coretemp.c4
-rw-r--r--drivers/hwmon/dme1737.c506
-rw-r--r--drivers/hwmon/ds1621.c93
-rw-r--r--drivers/hwmon/ds620.c13
-rw-r--r--drivers/hwmon/emc1403.c25
-rw-r--r--drivers/hwmon/emc2103.c63
-rw-r--r--drivers/hwmon/emc6w201.c12
-rw-r--r--drivers/hwmon/f71805f.c201
-rw-r--r--drivers/hwmon/f71882fg.c63
-rw-r--r--drivers/hwmon/f75375s.c13
-rw-r--r--drivers/hwmon/fschmd.c231
-rw-r--r--drivers/hwmon/g760a.c48
-rw-r--r--drivers/hwmon/gl518sm.c115
-rw-r--r--drivers/hwmon/gl520sm.c243
-rw-r--r--drivers/hwmon/hwmon-vid.c159
-rw-r--r--drivers/hwmon/hwmon.c25
-rw-r--r--drivers/hwmon/i5k_amb.c18
-rw-r--r--drivers/hwmon/ibmaem.c2
-rw-r--r--drivers/hwmon/it87.c176
-rw-r--r--drivers/hwmon/jc42.c97
-rw-r--r--drivers/hwmon/k10temp.c2
-rw-r--r--drivers/hwmon/k8temp.c17
-rw-r--r--drivers/hwmon/lineage-pem.c24
-rw-r--r--drivers/hwmon/lm63.c13
-rw-r--r--drivers/hwmon/lm70.c38
-rw-r--r--drivers/hwmon/lm73.c15
-rw-r--r--drivers/hwmon/lm75.c17
-rw-r--r--drivers/hwmon/lm77.c172
-rw-r--r--drivers/hwmon/lm78.c206
-rw-r--r--drivers/hwmon/lm80.c247
-rw-r--r--drivers/hwmon/lm83.c30
-rw-r--r--drivers/hwmon/lm85.c374
-rw-r--r--drivers/hwmon/lm87.c958
-rw-r--r--drivers/hwmon/lm90.c13
-rw-r--r--drivers/hwmon/lm92.c111
-rw-r--r--drivers/hwmon/lm93.c696
-rw-r--r--drivers/hwmon/lm95241.c13
-rw-r--r--drivers/hwmon/lm95245.c13
-rw-r--r--drivers/hwmon/ltc4151.c16
-rw-r--r--drivers/hwmon/ltc4215.c28
-rw-r--r--drivers/hwmon/ltc4245.c22
-rw-r--r--drivers/hwmon/ltc4261.c28
-rw-r--r--drivers/hwmon/max1111.c15
-rw-r--r--drivers/hwmon/max16065.c36
-rw-r--r--drivers/hwmon/max1619.c34
-rw-r--r--drivers/hwmon/max1668.c51
-rw-r--r--drivers/hwmon/max6639.c13
-rw-r--r--drivers/hwmon/max6642.c13
-rw-r--r--drivers/hwmon/max6650.c177
-rw-r--r--drivers/hwmon/pc87360.c602
-rw-r--r--drivers/hwmon/pc87427.c72
-rw-r--r--drivers/hwmon/pcf8591.c143
-rw-r--r--drivers/hwmon/pmbus/Kconfig17
-rw-r--r--drivers/hwmon/pmbus/adm1275.c124
-rw-r--r--drivers/hwmon/pmbus/lm25066.c46
-rw-r--r--drivers/hwmon/pmbus/ltc2978.c50
-rw-r--r--drivers/hwmon/pmbus/max16064.c20
-rw-r--r--drivers/hwmon/pmbus/max34440.c139
-rw-r--r--drivers/hwmon/pmbus/max8688.c20
-rw-r--r--drivers/hwmon/pmbus/pmbus.c40
-rw-r--r--drivers/hwmon/pmbus/pmbus.h57
-rw-r--r--drivers/hwmon/pmbus/pmbus_core.c87
-rw-r--r--drivers/hwmon/pmbus/ucd9000.c47
-rw-r--r--drivers/hwmon/pmbus/ucd9200.c43
-rw-r--r--drivers/hwmon/pmbus/zl6100.c44
-rw-r--r--drivers/hwmon/sch5627.c11
-rw-r--r--drivers/hwmon/sch5636.c11
-rw-r--r--drivers/hwmon/sch56xx-common.c519
-rw-r--r--drivers/hwmon/sch56xx-common.h10
-rw-r--r--drivers/hwmon/sht15.c2
-rw-r--r--drivers/hwmon/sht21.c23
-rw-r--r--drivers/hwmon/sis5595.c307
-rw-r--r--drivers/hwmon/smm665.c34
-rw-r--r--drivers/hwmon/smsc47b397.c64
-rw-r--r--drivers/hwmon/smsc47m1.c291
-rw-r--r--drivers/hwmon/smsc47m192.c145
-rw-r--r--drivers/hwmon/thmc50.c84
-rw-r--r--drivers/hwmon/tmp102.c12
-rw-r--r--drivers/hwmon/tmp401.c13
-rw-r--r--drivers/hwmon/tmp421.c13
-rw-r--r--drivers/hwmon/ultra45_env.c34
-rw-r--r--drivers/hwmon/via686a.c357
-rw-r--r--drivers/hwmon/vt1211.c389
-rw-r--r--drivers/hwmon/vt8231.c285
-rw-r--r--drivers/hwmon/w83627ehf.c261
-rw-r--r--drivers/hwmon/w83627hf.c272
-rw-r--r--drivers/hwmon/w83781d.c475
-rw-r--r--drivers/hwmon/w83791d.c331
-rw-r--r--drivers/hwmon/w83792d.c397
-rw-r--r--drivers/hwmon/w83793.c453
-rw-r--r--drivers/hwmon/w83795.c13
-rw-r--r--drivers/hwmon/w83l785ts.c30
-rw-r--r--drivers/hwmon/w83l786ng.c190
-rw-r--r--drivers/hwmon/wm831x-hwmon.c8
-rw-r--r--drivers/hwmon/wm8350-hwmon.c2
129 files changed, 8581 insertions, 6219 deletions
diff --git a/Documentation/hwmon/adm1275 b/Documentation/hwmon/adm1275
index e5f982c845fd..2cfa25667123 100644
--- a/Documentation/hwmon/adm1275
+++ b/Documentation/hwmon/adm1275
@@ -2,6 +2,10 @@ Kernel driver adm1275
2===================== 2=====================
3 3
4Supported chips: 4Supported chips:
5 * Analog Devices ADM1075
6 Prefix: 'adm1075'
7 Addresses scanned: -
8 Datasheet: www.analog.com/static/imported-files/data_sheets/ADM1075.pdf
5 * Analog Devices ADM1275 9 * Analog Devices ADM1275
6 Prefix: 'adm1275' 10 Prefix: 'adm1275'
7 Addresses scanned: - 11 Addresses scanned: -
@@ -17,13 +21,13 @@ Author: Guenter Roeck <guenter.roeck@ericsson.com>
17Description 21Description
18----------- 22-----------
19 23
20This driver supports hardware montoring for Analog Devices ADM1275 and ADM1276 24This driver supports hardware montoring for Analog Devices ADM1075, ADM1275,
21Hot-Swap Controller and Digital Power Monitor. 25and ADM1276 Hot-Swap Controller and Digital Power Monitor.
22 26
23ADM1275 and ADM1276 are hot-swap controllers that allow a circuit board to be 27ADM1075, ADM1275, and ADM1276 are hot-swap controllers that allow a circuit
24removed from or inserted into a live backplane. They also feature current and 28board to be removed from or inserted into a live backplane. They also feature
25voltage readback via an integrated 12-bit analog-to-digital converter (ADC), 29current and voltage readback via an integrated 12-bit analog-to-digital
26accessed using a PMBus interface. 30converter (ADC), accessed using a PMBus interface.
27 31
28The driver is a client driver to the core PMBus driver. Please see 32The driver is a client driver to the core PMBus driver. Please see
29Documentation/hwmon/pmbus for details on PMBus client drivers. 33Documentation/hwmon/pmbus for details on PMBus client drivers.
@@ -36,6 +40,10 @@ This driver does not auto-detect devices. You will have to instantiate the
36devices explicitly. Please see Documentation/i2c/instantiating-devices for 40devices explicitly. Please see Documentation/i2c/instantiating-devices for
37details. 41details.
38 42
43The ADM1075, unlike many other PMBus devices, does not support internal voltage
44or current scaling. Reported voltages, currents, and power are raw measurements,
45and will typically have to be scaled.
46
39 47
40Platform data support 48Platform data support
41--------------------- 49---------------------
@@ -51,7 +59,8 @@ The following attributes are supported. Limits are read-write, history reset
51attributes are write-only, all other attributes are read-only. 59attributes are write-only, all other attributes are read-only.
52 60
53in1_label "vin1" or "vout1" depending on chip variant and 61in1_label "vin1" or "vout1" depending on chip variant and
54 configuration. 62 configuration. On ADM1075, vout1 reports the voltage on
63 the VAUX pin.
55in1_input Measured voltage. 64in1_input Measured voltage.
56in1_min Minimum Voltage. 65in1_min Minimum Voltage.
57in1_max Maximum voltage. 66in1_max Maximum voltage.
@@ -74,3 +83,10 @@ curr1_crit Critical maximum current. Depending on the chip
74curr1_crit_alarm Critical current high alarm. 83curr1_crit_alarm Critical current high alarm.
75curr1_highest Historical maximum current. 84curr1_highest Historical maximum current.
76curr1_reset_history Write any value to reset history. 85curr1_reset_history Write any value to reset history.
86
87power1_label "pin1"
88power1_input Input power.
89power1_reset_history Write any value to reset history.
90
91 Power attributes are supported on ADM1075 and ADM1276
92 only.
diff --git a/Documentation/hwmon/jc42 b/Documentation/hwmon/jc42
index 52729a756c1b..66ecb9fc8246 100644
--- a/Documentation/hwmon/jc42
+++ b/Documentation/hwmon/jc42
@@ -3,71 +3,50 @@ Kernel driver jc42
3 3
4Supported chips: 4Supported chips:
5 * Analog Devices ADT7408 5 * Analog Devices ADT7408
6 Prefix: 'adt7408'
7 Addresses scanned: I2C 0x18 - 0x1f
8 Datasheets: 6 Datasheets:
9 http://www.analog.com/static/imported-files/data_sheets/ADT7408.pdf 7 http://www.analog.com/static/imported-files/data_sheets/ADT7408.pdf
10 * Atmel AT30TS00 8 * Atmel AT30TS00
11 Prefix: 'at30ts00'
12 Addresses scanned: I2C 0x18 - 0x1f
13 Datasheets: 9 Datasheets:
14 http://www.atmel.com/Images/doc8585.pdf 10 http://www.atmel.com/Images/doc8585.pdf
15 * IDT TSE2002B3, TSE2002GB2, TS3000B3, TS3000GB2 11 * IDT TSE2002B3, TSE2002GB2, TS3000B3, TS3000GB2
16 Prefix: 'tse2002', 'ts3000'
17 Addresses scanned: I2C 0x18 - 0x1f
18 Datasheets: 12 Datasheets:
19 http://www.idt.com/sites/default/files/documents/IDT_TSE2002B3C_DST_20100512_120303152056.pdf 13 http://www.idt.com/sites/default/files/documents/IDT_TSE2002B3C_DST_20100512_120303152056.pdf
20 http://www.idt.com/sites/default/files/documents/IDT_TSE2002GB2A1_DST_20111107_120303145914.pdf 14 http://www.idt.com/sites/default/files/documents/IDT_TSE2002GB2A1_DST_20111107_120303145914.pdf
21 http://www.idt.com/sites/default/files/documents/IDT_TS3000B3A_DST_20101129_120303152013.pdf 15 http://www.idt.com/sites/default/files/documents/IDT_TS3000B3A_DST_20101129_120303152013.pdf
22 http://www.idt.com/sites/default/files/documents/IDT_TS3000GB2A1_DST_20111104_120303151012.pdf 16 http://www.idt.com/sites/default/files/documents/IDT_TS3000GB2A1_DST_20111104_120303151012.pdf
23 * Maxim MAX6604 17 * Maxim MAX6604
24 Prefix: 'max6604'
25 Addresses scanned: I2C 0x18 - 0x1f
26 Datasheets: 18 Datasheets:
27 http://datasheets.maxim-ic.com/en/ds/MAX6604.pdf 19 http://datasheets.maxim-ic.com/en/ds/MAX6604.pdf
28 * Microchip MCP9804, MCP9805, MCP98242, MCP98243, MCP9843 20 * Microchip MCP9804, MCP9805, MCP98242, MCP98243, MCP9843
29 Prefixes: 'mcp9804', 'mcp9805', 'mcp98242', 'mcp98243', 'mcp9843'
30 Addresses scanned: I2C 0x18 - 0x1f
31 Datasheets: 21 Datasheets:
32 http://ww1.microchip.com/downloads/en/DeviceDoc/22203C.pdf 22 http://ww1.microchip.com/downloads/en/DeviceDoc/22203C.pdf
33 http://ww1.microchip.com/downloads/en/DeviceDoc/21977b.pdf 23 http://ww1.microchip.com/downloads/en/DeviceDoc/21977b.pdf
34 http://ww1.microchip.com/downloads/en/DeviceDoc/21996a.pdf 24 http://ww1.microchip.com/downloads/en/DeviceDoc/21996a.pdf
35 http://ww1.microchip.com/downloads/en/DeviceDoc/22153c.pdf 25 http://ww1.microchip.com/downloads/en/DeviceDoc/22153c.pdf
36 * NXP Semiconductors SE97, SE97B 26 * NXP Semiconductors SE97, SE97B, SE98, SE98A
37 Prefix: 'se97'
38 Addresses scanned: I2C 0x18 - 0x1f
39 Datasheets: 27 Datasheets:
40 http://www.nxp.com/documents/data_sheet/SE97.pdf 28 http://www.nxp.com/documents/data_sheet/SE97.pdf
41 http://www.nxp.com/documents/data_sheet/SE97B.pdf 29 http://www.nxp.com/documents/data_sheet/SE97B.pdf
42 * NXP Semiconductors SE98
43 Prefix: 'se98'
44 Addresses scanned: I2C 0x18 - 0x1f
45 Datasheets:
46 http://www.nxp.com/documents/data_sheet/SE98.pdf 30 http://www.nxp.com/documents/data_sheet/SE98.pdf
31 http://www.nxp.com/documents/data_sheet/SE98A.pdf
47 * ON Semiconductor CAT34TS02, CAT6095 32 * ON Semiconductor CAT34TS02, CAT6095
48 Prefix: 'cat34ts02', 'cat6095'
49 Addresses scanned: I2C 0x18 - 0x1f
50 Datasheet: 33 Datasheet:
51 http://www.onsemi.com/pub_link/Collateral/CAT34TS02-D.PDF 34 http://www.onsemi.com/pub_link/Collateral/CAT34TS02-D.PDF
52 http://www.onsemi.com/pub/Collateral/CAT6095-D.PDF 35 http://www.onsemi.com/pub/Collateral/CAT6095-D.PDF
53 * ST Microelectronics STTS424, STTS424E02 36 * ST Microelectronics STTS424, STTS424E02, STTS2002, STTS3000
54 Prefix: 'stts424'
55 Addresses scanned: I2C 0x18 - 0x1f
56 Datasheets:
57 http://www.st.com/stonline/products/literature/ds/13447/stts424.pdf
58 http://www.st.com/stonline/products/literature/ds/13448/stts424e02.pdf
59 * ST Microelectronics STTS2002, STTS3000
60 Prefix: 'stts2002', 'stts3000'
61 Addresses scanned: I2C 0x18 - 0x1f
62 Datasheets: 37 Datasheets:
38 http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATASHEET/CD00157556.pdf
39 http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATASHEET/CD00157558.pdf
63 http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATASHEET/CD00225278.pdf 40 http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATASHEET/CD00225278.pdf
64 http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATA_BRIEF/CD00270920.pdf 41 http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATA_BRIEF/CD00270920.pdf
65 * JEDEC JC 42.4 compliant temperature sensor chips 42 * JEDEC JC 42.4 compliant temperature sensor chips
66 Prefix: 'jc42'
67 Addresses scanned: I2C 0x18 - 0x1f
68 Datasheet: 43 Datasheet:
69 http://www.jedec.org/sites/default/files/docs/4_01_04R19.pdf 44 http://www.jedec.org/sites/default/files/docs/4_01_04R19.pdf
70 45
46 Common for all chips:
47 Prefix: 'jc42'
48 Addresses scanned: I2C 0x18 - 0x1f
49
71Author: 50Author:
72 Guenter Roeck <guenter.roeck@ericsson.com> 51 Guenter Roeck <guenter.roeck@ericsson.com>
73 52
diff --git a/Documentation/hwmon/lm80 b/Documentation/hwmon/lm80
index cb5b407ba3e6..a60b43efc32b 100644
--- a/Documentation/hwmon/lm80
+++ b/Documentation/hwmon/lm80
@@ -7,6 +7,11 @@ Supported chips:
7 Addresses scanned: I2C 0x28 - 0x2f 7 Addresses scanned: I2C 0x28 - 0x2f
8 Datasheet: Publicly available at the National Semiconductor website 8 Datasheet: Publicly available at the National Semiconductor website
9 http://www.national.com/ 9 http://www.national.com/
10 * National Semiconductor LM96080
11 Prefix: 'lm96080'
12 Addresses scanned: I2C 0x28 - 0x2f
13 Datasheet: Publicly available at the National Semiconductor website
14 http://www.national.com/
10 15
11Authors: 16Authors:
12 Frodo Looijaard <frodol@dds.nl>, 17 Frodo Looijaard <frodol@dds.nl>,
@@ -17,7 +22,9 @@ Description
17 22
18This driver implements support for the National Semiconductor LM80. 23This driver implements support for the National Semiconductor LM80.
19It is described as a 'Serial Interface ACPI-Compatible Microprocessor 24It is described as a 'Serial Interface ACPI-Compatible Microprocessor
20System Hardware Monitor'. 25System Hardware Monitor'. The LM96080 is a more recent incarnation,
26it is pin and register compatible, with a few additional features not
27yet supported by the driver.
21 28
22The LM80 implements one temperature sensor, two fan rotation speed sensors, 29The LM80 implements one temperature sensor, two fan rotation speed sensors,
23seven voltage sensors, alarms, and some miscellaneous stuff. 30seven voltage sensors, alarms, and some miscellaneous stuff.
diff --git a/Documentation/hwmon/max34440 b/Documentation/hwmon/max34440
index 19743919ea56..04482226db20 100644
--- a/Documentation/hwmon/max34440
+++ b/Documentation/hwmon/max34440
@@ -11,6 +11,11 @@ Supported chips:
11 Prefixes: 'max34441' 11 Prefixes: 'max34441'
12 Addresses scanned: - 12 Addresses scanned: -
13 Datasheet: http://datasheets.maxim-ic.com/en/ds/MAX34441.pdf 13 Datasheet: http://datasheets.maxim-ic.com/en/ds/MAX34441.pdf
14 * Maxim MAX34446
15 PMBus Power-Supply Data Logger
16 Prefixes: 'max34446'
17 Addresses scanned: -
18 Datasheet: http://datasheets.maxim-ic.com/en/ds/MAX34446.pdf
14 19
15Author: Guenter Roeck <guenter.roeck@ericsson.com> 20Author: Guenter Roeck <guenter.roeck@ericsson.com>
16 21
@@ -19,8 +24,8 @@ Description
19----------- 24-----------
20 25
21This driver supports hardware montoring for Maxim MAX34440 PMBus 6-Channel 26This driver supports hardware montoring for Maxim MAX34440 PMBus 6-Channel
22Power-Supply Manager and MAX34441 PMBus 5-Channel Power-Supply Manager 27Power-Supply Manager, MAX34441 PMBus 5-Channel Power-Supply Manager
23and Intelligent Fan Controller. 28and Intelligent Fan Controller, and MAX34446 PMBus Power-Supply Data Logger.
24 29
25The driver is a client driver to the core PMBus driver. Please see 30The driver is a client driver to the core PMBus driver. Please see
26Documentation/hwmon/pmbus for details on PMBus client drivers. 31Documentation/hwmon/pmbus for details on PMBus client drivers.
@@ -33,6 +38,13 @@ This driver does not auto-detect devices. You will have to instantiate the
33devices explicitly. Please see Documentation/i2c/instantiating-devices for 38devices explicitly. Please see Documentation/i2c/instantiating-devices for
34details. 39details.
35 40
41For MAX34446, the value of the currX_crit attribute determines if current or
42voltage measurement is enabled for a given channel. Voltage measurement is
43enabled if currX_crit is set to 0; current measurement is enabled if the
44attribute is set to a positive value. Power measurement is only enabled if
45channel 1 (3) is configured for voltage measurement, and channel 2 (4) is
46configured for current measurement.
47
36 48
37Platform data support 49Platform data support
38--------------------- 50---------------------
@@ -56,19 +68,31 @@ in[1-6]_min_alarm Voltage low alarm. From VOLTAGE_UV_WARNING status.
56in[1-6]_max_alarm Voltage high alarm. From VOLTAGE_OV_WARNING status. 68in[1-6]_max_alarm Voltage high alarm. From VOLTAGE_OV_WARNING status.
57in[1-6]_lcrit_alarm Voltage critical low alarm. From VOLTAGE_UV_FAULT status. 69in[1-6]_lcrit_alarm Voltage critical low alarm. From VOLTAGE_UV_FAULT status.
58in[1-6]_crit_alarm Voltage critical high alarm. From VOLTAGE_OV_FAULT status. 70in[1-6]_crit_alarm Voltage critical high alarm. From VOLTAGE_OV_FAULT status.
71in[1-6]_lowest Historical minimum voltage.
59in[1-6]_highest Historical maximum voltage. 72in[1-6]_highest Historical maximum voltage.
60in[1-6]_reset_history Write any value to reset history. 73in[1-6]_reset_history Write any value to reset history.
61 74
75 MAX34446 only supports in[1-4].
76
62curr[1-6]_label "iout[1-6]". 77curr[1-6]_label "iout[1-6]".
63curr[1-6]_input Measured current. From READ_IOUT register. 78curr[1-6]_input Measured current. From READ_IOUT register.
64curr[1-6]_max Maximum current. From IOUT_OC_WARN_LIMIT register. 79curr[1-6]_max Maximum current. From IOUT_OC_WARN_LIMIT register.
65curr[1-6]_crit Critical maximum current. From IOUT_OC_FAULT_LIMIT register. 80curr[1-6]_crit Critical maximum current. From IOUT_OC_FAULT_LIMIT register.
66curr[1-6]_max_alarm Current high alarm. From IOUT_OC_WARNING status. 81curr[1-6]_max_alarm Current high alarm. From IOUT_OC_WARNING status.
67curr[1-6]_crit_alarm Current critical high alarm. From IOUT_OC_FAULT status. 82curr[1-6]_crit_alarm Current critical high alarm. From IOUT_OC_FAULT status.
83curr[1-4]_average Historical average current (MAX34446 only).
68curr[1-6]_highest Historical maximum current. 84curr[1-6]_highest Historical maximum current.
69curr[1-6]_reset_history Write any value to reset history. 85curr[1-6]_reset_history Write any value to reset history.
70 86
71 in6 and curr6 attributes only exist for MAX34440. 87 in6 and curr6 attributes only exist for MAX34440.
88 MAX34446 only supports curr[1-4].
89
90power[1,3]_label "pout[1,3]"
91power[1,3]_input Measured power.
92power[1,3]_average Historical average power.
93power[1,3]_highest Historical maximum power.
94
95 Power attributes only exist for MAX34446.
72 96
73temp[1-8]_input Measured temperatures. From READ_TEMPERATURE_1 register. 97temp[1-8]_input Measured temperatures. From READ_TEMPERATURE_1 register.
74 temp1 is the chip's internal temperature. temp2..temp5 98 temp1 is the chip's internal temperature. temp2..temp5
@@ -79,7 +103,9 @@ temp[1-8]_max Maximum temperature. From OT_WARN_LIMIT register.
79temp[1-8]_crit Critical high temperature. From OT_FAULT_LIMIT register. 103temp[1-8]_crit Critical high temperature. From OT_FAULT_LIMIT register.
80temp[1-8]_max_alarm Temperature high alarm. 104temp[1-8]_max_alarm Temperature high alarm.
81temp[1-8]_crit_alarm Temperature critical high alarm. 105temp[1-8]_crit_alarm Temperature critical high alarm.
106temp[1-8]_average Historical average temperature (MAX34446 only).
82temp[1-8]_highest Historical maximum temperature. 107temp[1-8]_highest Historical maximum temperature.
83temp[1-8]_reset_history Write any value to reset history. 108temp[1-8]_reset_history Write any value to reset history.
84 109
85 temp7 and temp8 attributes only exist for MAX34440. 110 temp7 and temp8 attributes only exist for MAX34440.
111 MAX34446 only supports temp[1-3].
diff --git a/Documentation/hwmon/pmbus b/Documentation/hwmon/pmbus
index d28b591753d1..f90f99920cc5 100644
--- a/Documentation/hwmon/pmbus
+++ b/Documentation/hwmon/pmbus
@@ -15,13 +15,20 @@ Supported chips:
15 http://www.onsemi.com/pub_link/Collateral/NCP4200-D.PDF 15 http://www.onsemi.com/pub_link/Collateral/NCP4200-D.PDF
16 http://www.onsemi.com/pub_link/Collateral/JUNE%202009-%20REV.%200.PDF 16 http://www.onsemi.com/pub_link/Collateral/JUNE%202009-%20REV.%200.PDF
17 * Lineage Power 17 * Lineage Power
18 Prefixes: 'pdt003', 'pdt006', 'pdt012', 'udt020' 18 Prefixes: 'mdt040', 'pdt003', 'pdt006', 'pdt012', 'udt020'
19 Addresses scanned: - 19 Addresses scanned: -
20 Datasheets: 20 Datasheets:
21 http://www.lineagepower.com/oem/pdf/PDT003A0X.pdf 21 http://www.lineagepower.com/oem/pdf/PDT003A0X.pdf
22 http://www.lineagepower.com/oem/pdf/PDT006A0X.pdf 22 http://www.lineagepower.com/oem/pdf/PDT006A0X.pdf
23 http://www.lineagepower.com/oem/pdf/PDT012A0X.pdf 23 http://www.lineagepower.com/oem/pdf/PDT012A0X.pdf
24 http://www.lineagepower.com/oem/pdf/UDT020A0X.pdf 24 http://www.lineagepower.com/oem/pdf/UDT020A0X.pdf
25 http://www.lineagepower.com/oem/pdf/MDT040A0X.pdf
26 * Texas Instruments TPS40400, TPS40422
27 Prefixes: 'tps40400', 'tps40422'
28 Addresses scanned: -
29 Datasheets:
30 http://www.ti.com/lit/gpn/tps40400
31 http://www.ti.com/lit/gpn/tps40422
25 * Generic PMBus devices 32 * Generic PMBus devices
26 Prefix: 'pmbus' 33 Prefix: 'pmbus'
27 Addresses scanned: - 34 Addresses scanned: -
diff --git a/Documentation/hwmon/sch5627 b/Documentation/hwmon/sch5627
index 446a054e4912..0551d266c51c 100644
--- a/Documentation/hwmon/sch5627
+++ b/Documentation/hwmon/sch5627
@@ -16,6 +16,11 @@ Description
16SMSC SCH5627 Super I/O chips include complete hardware monitoring 16SMSC SCH5627 Super I/O chips include complete hardware monitoring
17capabilities. They can monitor up to 5 voltages, 4 fans and 8 temperatures. 17capabilities. They can monitor up to 5 voltages, 4 fans and 8 temperatures.
18 18
19The SMSC SCH5627 hardware monitoring part also contains an integrated
20watchdog. In order for this watchdog to function some motherboard specific
21initialization most be done by the BIOS, so if the watchdog is not enabled
22by the BIOS the sch5627 driver will not register a watchdog device.
23
19The hardware monitoring part of the SMSC SCH5627 is accessed by talking 24The hardware monitoring part of the SMSC SCH5627 is accessed by talking
20through an embedded microcontroller. An application note describing the 25through an embedded microcontroller. An application note describing the
21protocol for communicating with the microcontroller is available upon 26protocol for communicating with the microcontroller is available upon
diff --git a/Documentation/hwmon/sch5636 b/Documentation/hwmon/sch5636
index f83bd1c260f0..7b0a01da0717 100644
--- a/Documentation/hwmon/sch5636
+++ b/Documentation/hwmon/sch5636
@@ -26,6 +26,9 @@ temperatures. Note that the driver detects how many fan headers /
26temperature sensors are actually implemented on the motherboard, so you will 26temperature sensors are actually implemented on the motherboard, so you will
27likely see fewer temperature and fan inputs. 27likely see fewer temperature and fan inputs.
28 28
29The Fujitsu Theseus hwmon solution also contains an integrated watchdog.
30This watchdog is fully supported by the sch5636 driver.
31
29An application note describing the Theseus' registers, as well as an 32An application note describing the Theseus' registers, as well as an
30application note describing the protocol for communicating with the 33application note describing the protocol for communicating with the
31microcontroller is available upon request. Please mail me if you want a copy. 34microcontroller is available upon request. Please mail me if you want a copy.
diff --git a/Documentation/hwmon/zl6100 b/Documentation/hwmon/zl6100
index 98ebacbdd8d9..a995b41724fd 100644
--- a/Documentation/hwmon/zl6100
+++ b/Documentation/hwmon/zl6100
@@ -34,6 +34,14 @@ Supported chips:
34 Prefix: 'zl6105' 34 Prefix: 'zl6105'
35 Addresses scanned: - 35 Addresses scanned: -
36 Datasheet: http://www.intersil.com/data/fn/fn6906.pdf 36 Datasheet: http://www.intersil.com/data/fn/fn6906.pdf
37 * Intersil / Zilker Labs ZL9101M
38 Prefix: 'zl9101'
39 Addresses scanned: -
40 Datasheet: http://www.intersil.com/data/fn/fn7669.pdf
41 * Intersil / Zilker Labs ZL9117M
42 Prefix: 'zl9117'
43 Addresses scanned: -
44 Datasheet: http://www.intersil.com/data/fn/fn7914.pdf
37 * Ericsson BMR450, BMR451 45 * Ericsson BMR450, BMR451
38 Prefix: 'bmr450', 'bmr451' 46 Prefix: 'bmr450', 'bmr451'
39 Addresses scanned: - 47 Addresses scanned: -
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index dad895fec62a..811e6c47e7e6 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -598,11 +598,11 @@ config SENSORS_LM78
598 will be called lm78. 598 will be called lm78.
599 599
600config SENSORS_LM80 600config SENSORS_LM80
601 tristate "National Semiconductor LM80" 601 tristate "National Semiconductor LM80 and LM96080"
602 depends on I2C 602 depends on I2C
603 help 603 help
604 If you say yes here you get support for National Semiconductor 604 If you say yes here you get support for National Semiconductor
605 LM80 sensor chips. 605 LM80 and LM96080 sensor chips.
606 606
607 This driver can also be built as a module. If so, the module 607 This driver can also be built as a module. If so, the module
608 will be called lm80. 608 will be called lm80.
@@ -1028,7 +1028,8 @@ config SENSORS_SCH5627
1028 select SENSORS_SCH56XX_COMMON 1028 select SENSORS_SCH56XX_COMMON
1029 help 1029 help
1030 If you say yes here you get support for the hardware monitoring 1030 If you say yes here you get support for the hardware monitoring
1031 features of the SMSC SCH5627 Super-I/O chip. 1031 features of the SMSC SCH5627 Super-I/O chip including support for
1032 the integrated watchdog.
1032 1033
1033 This driver can also be built as a module. If so, the module 1034 This driver can also be built as a module. If so, the module
1034 will be called sch5627. 1035 will be called sch5627.
@@ -1044,7 +1045,8 @@ config SENSORS_SCH5636
1044 1045
1045 Currently this driver only supports the Fujitsu Theseus SCH5636 based 1046 Currently this driver only supports the Fujitsu Theseus SCH5636 based
1046 hwmon solution. Say yes here if you want support for the Fujitsu 1047 hwmon solution. Say yes here if you want support for the Fujitsu
1047 Theseus' hardware monitoring features. 1048 Theseus' hardware monitoring features including support for the
1049 integrated watchdog.
1048 1050
1049 This driver can also be built as a module. If so, the module 1051 This driver can also be built as a module. If so, the module
1050 will be called sch5636. 1052 will be called sch5636.
diff --git a/drivers/hwmon/abituguru.c b/drivers/hwmon/abituguru.c
index 3b728e8f169b..a72bf25601a4 100644
--- a/drivers/hwmon/abituguru.c
+++ b/drivers/hwmon/abituguru.c
@@ -1,25 +1,25 @@
1/* 1/*
2 abituguru.c Copyright (c) 2005-2006 Hans de Goede <hdegoede@redhat.com> 2 * abituguru.c Copyright (c) 2005-2006 Hans de Goede <hdegoede@redhat.com>
3 3 *
4 This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or 6 * the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version. 7 * (at your option) any later version.
8 8 *
9 This program is distributed in the hope that it will be useful, 9 * This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 * GNU General Public License for more details.
13 13 *
14 You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software 15 * along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17*/ 17 */
18/* 18/*
19 This driver supports the sensor part of the first and second revision of 19 * This driver supports the sensor part of the first and second revision of
20 the custom Abit uGuru chip found on Abit uGuru motherboards. Note: because 20 * the custom Abit uGuru chip found on Abit uGuru motherboards. Note: because
21 of lack of specs the CPU/RAM voltage & frequency control is not supported! 21 * of lack of specs the CPU/RAM voltage & frequency control is not supported!
22*/ 22 */
23 23
24#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 24#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25 25
@@ -44,8 +44,10 @@
44#define ABIT_UGURU_SENSOR_BANK2 0x26 /* fans */ 44#define ABIT_UGURU_SENSOR_BANK2 0x26 /* fans */
45/* max nr of sensors in bank1, a bank1 sensor can be in, temp or nc */ 45/* max nr of sensors in bank1, a bank1 sensor can be in, temp or nc */
46#define ABIT_UGURU_MAX_BANK1_SENSORS 16 46#define ABIT_UGURU_MAX_BANK1_SENSORS 16
47/* Warning if you increase one of the 2 MAX defines below to 10 or higher you 47/*
48 should adjust the belonging _NAMES_LENGTH macro for the 2 digit number! */ 48 * Warning if you increase one of the 2 MAX defines below to 10 or higher you
49 * should adjust the belonging _NAMES_LENGTH macro for the 2 digit number!
50 */
49/* max nr of sensors in bank2, currently mb's with max 6 fans are known */ 51/* max nr of sensors in bank2, currently mb's with max 6 fans are known */
50#define ABIT_UGURU_MAX_BANK2_SENSORS 6 52#define ABIT_UGURU_MAX_BANK2_SENSORS 6
51/* max nr of pwm outputs, currently mb's with max 5 pwm outputs are known */ 53/* max nr of pwm outputs, currently mb's with max 5 pwm outputs are known */
@@ -70,16 +72,22 @@
70#define ABIT_UGURU_IN_SENSOR 0 72#define ABIT_UGURU_IN_SENSOR 0
71#define ABIT_UGURU_TEMP_SENSOR 1 73#define ABIT_UGURU_TEMP_SENSOR 1
72#define ABIT_UGURU_NC 2 74#define ABIT_UGURU_NC 2
73/* In many cases we need to wait for the uGuru to reach a certain status, most 75/*
74 of the time it will reach this status within 30 - 90 ISA reads, and thus we 76 * In many cases we need to wait for the uGuru to reach a certain status, most
75 can best busy wait. This define gives the total amount of reads to try. */ 77 * of the time it will reach this status within 30 - 90 ISA reads, and thus we
78 * can best busy wait. This define gives the total amount of reads to try.
79 */
76#define ABIT_UGURU_WAIT_TIMEOUT 125 80#define ABIT_UGURU_WAIT_TIMEOUT 125
77/* However sometimes older versions of the uGuru seem to be distracted and they 81/*
78 do not respond for a long time. To handle this we sleep before each of the 82 * However sometimes older versions of the uGuru seem to be distracted and they
79 last ABIT_UGURU_WAIT_TIMEOUT_SLEEP tries. */ 83 * do not respond for a long time. To handle this we sleep before each of the
84 * last ABIT_UGURU_WAIT_TIMEOUT_SLEEP tries.
85 */
80#define ABIT_UGURU_WAIT_TIMEOUT_SLEEP 5 86#define ABIT_UGURU_WAIT_TIMEOUT_SLEEP 5
81/* Normally all expected status in abituguru_ready, are reported after the 87/*
82 first read, but sometimes not and we need to poll. */ 88 * Normally all expected status in abituguru_ready, are reported after the
89 * first read, but sometimes not and we need to poll.
90 */
83#define ABIT_UGURU_READY_TIMEOUT 5 91#define ABIT_UGURU_READY_TIMEOUT 5
84/* Maximum 3 retries on timedout reads/writes, delay 200 ms before retrying */ 92/* Maximum 3 retries on timedout reads/writes, delay 200 ms before retrying */
85#define ABIT_UGURU_MAX_RETRIES 3 93#define ABIT_UGURU_MAX_RETRIES 3
@@ -92,17 +100,25 @@
92 if (level <= verbose) \ 100 if (level <= verbose) \
93 printk(KERN_DEBUG ABIT_UGURU_NAME ": " format , ## arg) 101 printk(KERN_DEBUG ABIT_UGURU_NAME ": " format , ## arg)
94/* Macros to help calculate the sysfs_names array length */ 102/* Macros to help calculate the sysfs_names array length */
95/* sum of strlen of: in??_input\0, in??_{min,max}\0, in??_{min,max}_alarm\0, 103/*
96 in??_{min,max}_alarm_enable\0, in??_beep\0, in??_shutdown\0 */ 104 * sum of strlen of: in??_input\0, in??_{min,max}\0, in??_{min,max}_alarm\0,
105 * in??_{min,max}_alarm_enable\0, in??_beep\0, in??_shutdown\0
106 */
97#define ABITUGURU_IN_NAMES_LENGTH (11 + 2 * 9 + 2 * 15 + 2 * 22 + 10 + 14) 107#define ABITUGURU_IN_NAMES_LENGTH (11 + 2 * 9 + 2 * 15 + 2 * 22 + 10 + 14)
98/* sum of strlen of: temp??_input\0, temp??_max\0, temp??_crit\0, 108/*
99 temp??_alarm\0, temp??_alarm_enable\0, temp??_beep\0, temp??_shutdown\0 */ 109 * sum of strlen of: temp??_input\0, temp??_max\0, temp??_crit\0,
110 * temp??_alarm\0, temp??_alarm_enable\0, temp??_beep\0, temp??_shutdown\0
111 */
100#define ABITUGURU_TEMP_NAMES_LENGTH (13 + 11 + 12 + 13 + 20 + 12 + 16) 112#define ABITUGURU_TEMP_NAMES_LENGTH (13 + 11 + 12 + 13 + 20 + 12 + 16)
101/* sum of strlen of: fan?_input\0, fan?_min\0, fan?_alarm\0, 113/*
102 fan?_alarm_enable\0, fan?_beep\0, fan?_shutdown\0 */ 114 * sum of strlen of: fan?_input\0, fan?_min\0, fan?_alarm\0,
115 * fan?_alarm_enable\0, fan?_beep\0, fan?_shutdown\0
116 */
103#define ABITUGURU_FAN_NAMES_LENGTH (11 + 9 + 11 + 18 + 10 + 14) 117#define ABITUGURU_FAN_NAMES_LENGTH (11 + 9 + 11 + 18 + 10 + 14)
104/* sum of strlen of: pwm?_enable\0, pwm?_auto_channels_temp\0, 118/*
105 pwm?_auto_point{1,2}_pwm\0, pwm?_auto_point{1,2}_temp\0 */ 119 * sum of strlen of: pwm?_enable\0, pwm?_auto_channels_temp\0,
120 * pwm?_auto_point{1,2}_pwm\0, pwm?_auto_point{1,2}_temp\0
121 */
106#define ABITUGURU_PWM_NAMES_LENGTH (12 + 24 + 2 * 21 + 2 * 22) 122#define ABITUGURU_PWM_NAMES_LENGTH (12 + 24 + 2 * 21 + 2 * 22)
107/* IN_NAMES_LENGTH > TEMP_NAMES_LENGTH so assume all bank1 sensors are in */ 123/* IN_NAMES_LENGTH > TEMP_NAMES_LENGTH so assume all bank1 sensors are in */
108#define ABITUGURU_SYSFS_NAMES_LENGTH ( \ 124#define ABITUGURU_SYSFS_NAMES_LENGTH ( \
@@ -110,10 +126,12 @@
110 ABIT_UGURU_MAX_BANK2_SENSORS * ABITUGURU_FAN_NAMES_LENGTH + \ 126 ABIT_UGURU_MAX_BANK2_SENSORS * ABITUGURU_FAN_NAMES_LENGTH + \
111 ABIT_UGURU_MAX_PWMS * ABITUGURU_PWM_NAMES_LENGTH) 127 ABIT_UGURU_MAX_PWMS * ABITUGURU_PWM_NAMES_LENGTH)
112 128
113/* All the macros below are named identical to the oguru and oguru2 programs 129/*
114 reverse engineered by Olle Sandberg, hence the names might not be 100% 130 * All the macros below are named identical to the oguru and oguru2 programs
115 logical. I could come up with better names, but I prefer keeping the names 131 * reverse engineered by Olle Sandberg, hence the names might not be 100%
116 identical so that this driver can be compared with his work more easily. */ 132 * logical. I could come up with better names, but I prefer keeping the names
133 * identical so that this driver can be compared with his work more easily.
134 */
117/* Two i/o-ports are used by uGuru */ 135/* Two i/o-ports are used by uGuru */
118#define ABIT_UGURU_BASE 0x00E0 136#define ABIT_UGURU_BASE 0x00E0
119/* Used to tell uGuru what to read and to read the actual data */ 137/* Used to tell uGuru what to read and to read the actual data */
@@ -130,16 +148,22 @@
130/* Constants */ 148/* Constants */
131/* in (Volt) sensors go up to 3494 mV, temp to 255000 millidegrees Celsius */ 149/* in (Volt) sensors go up to 3494 mV, temp to 255000 millidegrees Celsius */
132static const int abituguru_bank1_max_value[2] = { 3494, 255000 }; 150static const int abituguru_bank1_max_value[2] = { 3494, 255000 };
133/* Min / Max allowed values for sensor2 (fan) alarm threshold, these values 151/*
134 correspond to 300-3000 RPM */ 152 * Min / Max allowed values for sensor2 (fan) alarm threshold, these values
153 * correspond to 300-3000 RPM
154 */
135static const u8 abituguru_bank2_min_threshold = 5; 155static const u8 abituguru_bank2_min_threshold = 5;
136static const u8 abituguru_bank2_max_threshold = 50; 156static const u8 abituguru_bank2_max_threshold = 50;
137/* Register 0 is a bitfield, 1 and 2 are pwm settings (255 = 100%), 3 and 4 157/*
138 are temperature trip points. */ 158 * Register 0 is a bitfield, 1 and 2 are pwm settings (255 = 100%), 3 and 4
159 * are temperature trip points.
160 */
139static const int abituguru_pwm_settings_multiplier[5] = { 0, 1, 1, 1000, 1000 }; 161static const int abituguru_pwm_settings_multiplier[5] = { 0, 1, 1, 1000, 1000 };
140/* Min / Max allowed values for pwm_settings. Note: pwm1 (CPU fan) is a 162/*
141 special case the minium allowed pwm% setting for this is 30% (77) on 163 * Min / Max allowed values for pwm_settings. Note: pwm1 (CPU fan) is a
142 some MB's this special case is handled in the code! */ 164 * special case the minium allowed pwm% setting for this is 30% (77) on
165 * some MB's this special case is handled in the code!
166 */
143static const u8 abituguru_pwm_min[5] = { 0, 170, 170, 25, 25 }; 167static const u8 abituguru_pwm_min[5] = { 0, 170, 170, 25, 25 };
144static const u8 abituguru_pwm_max[5] = { 0, 255, 255, 75, 75 }; 168static const u8 abituguru_pwm_max[5] = { 0, 255, 255, 75, 75 };
145 169
@@ -175,23 +199,29 @@ MODULE_PARM_DESC(verbose, "How verbose should the driver be? (0-3):\n"
175 " 3 + retryable error reporting"); 199 " 3 + retryable error reporting");
176 200
177 201
178/* For the Abit uGuru, we need to keep some data in memory. 202/*
179 The structure is dynamically allocated, at the same time when a new 203 * For the Abit uGuru, we need to keep some data in memory.
180 abituguru device is allocated. */ 204 * The structure is dynamically allocated, at the same time when a new
205 * abituguru device is allocated.
206 */
181struct abituguru_data { 207struct abituguru_data {
182 struct device *hwmon_dev; /* hwmon registered device */ 208 struct device *hwmon_dev; /* hwmon registered device */
183 struct mutex update_lock; /* protect access to data and uGuru */ 209 struct mutex update_lock; /* protect access to data and uGuru */
184 unsigned long last_updated; /* In jiffies */ 210 unsigned long last_updated; /* In jiffies */
185 unsigned short addr; /* uguru base address */ 211 unsigned short addr; /* uguru base address */
186 char uguru_ready; /* is the uguru in ready state? */ 212 char uguru_ready; /* is the uguru in ready state? */
187 unsigned char update_timeouts; /* number of update timeouts since last 213 unsigned char update_timeouts; /*
188 successful update */ 214 * number of update timeouts since last
189 215 * successful update
190 /* The sysfs attr and their names are generated automatically, for bank1 216 */
191 we cannot use a predefined array because we don't know beforehand 217
192 of a sensor is a volt or a temp sensor, for bank2 and the pwms its 218 /*
193 easier todo things the same way. For in sensors we have 9 (temp 7) 219 * The sysfs attr and their names are generated automatically, for bank1
194 sysfs entries per sensor, for bank2 and pwms 6. */ 220 * we cannot use a predefined array because we don't know beforehand
221 * of a sensor is a volt or a temp sensor, for bank2 and the pwms its
222 * easier todo things the same way. For in sensors we have 9 (temp 7)
223 * sysfs entries per sensor, for bank2 and pwms 6.
224 */
195 struct sensor_device_attribute_2 sysfs_attr[ 225 struct sensor_device_attribute_2 sysfs_attr[
196 ABIT_UGURU_MAX_BANK1_SENSORS * 9 + 226 ABIT_UGURU_MAX_BANK1_SENSORS * 9 +
197 ABIT_UGURU_MAX_BANK2_SENSORS * 6 + ABIT_UGURU_MAX_PWMS * 6]; 227 ABIT_UGURU_MAX_BANK2_SENSORS * 6 + ABIT_UGURU_MAX_PWMS * 6];
@@ -203,11 +233,15 @@ struct abituguru_data {
203 u8 bank1_sensors[2]; 233 u8 bank1_sensors[2];
204 u8 bank1_address[2][ABIT_UGURU_MAX_BANK1_SENSORS]; 234 u8 bank1_address[2][ABIT_UGURU_MAX_BANK1_SENSORS];
205 u8 bank1_value[ABIT_UGURU_MAX_BANK1_SENSORS]; 235 u8 bank1_value[ABIT_UGURU_MAX_BANK1_SENSORS];
206 /* This array holds 3 entries per sensor for the bank 1 sensor settings 236 /*
207 (flags, min, max for voltage / flags, warn, shutdown for temp). */ 237 * This array holds 3 entries per sensor for the bank 1 sensor settings
238 * (flags, min, max for voltage / flags, warn, shutdown for temp).
239 */
208 u8 bank1_settings[ABIT_UGURU_MAX_BANK1_SENSORS][3]; 240 u8 bank1_settings[ABIT_UGURU_MAX_BANK1_SENSORS][3];
209 /* Maximum value for each sensor used for scaling in mV/millidegrees 241 /*
210 Celsius. */ 242 * Maximum value for each sensor used for scaling in mV/millidegrees
243 * Celsius.
244 */
211 int bank1_max_value[ABIT_UGURU_MAX_BANK1_SENSORS]; 245 int bank1_max_value[ABIT_UGURU_MAX_BANK1_SENSORS];
212 246
213 /* Bank 2 data, ABIT_UGURU_MAX_BANK2_SENSORS entries for bank2 */ 247 /* Bank 2 data, ABIT_UGURU_MAX_BANK2_SENSORS entries for bank2 */
@@ -236,8 +270,10 @@ static int abituguru_wait(struct abituguru_data *data, u8 state)
236 timeout--; 270 timeout--;
237 if (timeout == 0) 271 if (timeout == 0)
238 return -EBUSY; 272 return -EBUSY;
239 /* sleep a bit before our last few tries, see the comment on 273 /*
240 this where ABIT_UGURU_WAIT_TIMEOUT_SLEEP is defined. */ 274 * sleep a bit before our last few tries, see the comment on
275 * this where ABIT_UGURU_WAIT_TIMEOUT_SLEEP is defined.
276 */
241 if (timeout <= ABIT_UGURU_WAIT_TIMEOUT_SLEEP) 277 if (timeout <= ABIT_UGURU_WAIT_TIMEOUT_SLEEP)
242 msleep(0); 278 msleep(0);
243 } 279 }
@@ -273,8 +309,10 @@ static int abituguru_ready(struct abituguru_data *data)
273 msleep(0); 309 msleep(0);
274 } 310 }
275 311
276 /* After this the ABIT_UGURU_DATA port should contain 312 /*
277 ABIT_UGURU_STATUS_INPUT */ 313 * After this the ABIT_UGURU_DATA port should contain
314 * ABIT_UGURU_STATUS_INPUT
315 */
278 timeout = ABIT_UGURU_READY_TIMEOUT; 316 timeout = ABIT_UGURU_READY_TIMEOUT;
279 while (inb_p(data->addr + ABIT_UGURU_DATA) != ABIT_UGURU_STATUS_INPUT) { 317 while (inb_p(data->addr + ABIT_UGURU_DATA) != ABIT_UGURU_STATUS_INPUT) {
280 timeout--; 318 timeout--;
@@ -290,27 +328,35 @@ static int abituguru_ready(struct abituguru_data *data)
290 return 0; 328 return 0;
291} 329}
292 330
293/* Send the bank and then sensor address to the uGuru for the next read/write 331/*
294 cycle. This function gets called as the first part of a read/write by 332 * Send the bank and then sensor address to the uGuru for the next read/write
295 abituguru_read and abituguru_write. This function should never be 333 * cycle. This function gets called as the first part of a read/write by
296 called by any other function. */ 334 * abituguru_read and abituguru_write. This function should never be
335 * called by any other function.
336 */
297static int abituguru_send_address(struct abituguru_data *data, 337static int abituguru_send_address(struct abituguru_data *data,
298 u8 bank_addr, u8 sensor_addr, int retries) 338 u8 bank_addr, u8 sensor_addr, int retries)
299{ 339{
300 /* assume the caller does error handling itself if it has not requested 340 /*
301 any retries, and thus be quiet. */ 341 * assume the caller does error handling itself if it has not requested
342 * any retries, and thus be quiet.
343 */
302 int report_errors = retries; 344 int report_errors = retries;
303 345
304 for (;;) { 346 for (;;) {
305 /* Make sure the uguru is ready and then send the bank address, 347 /*
306 after this the uguru is no longer "ready". */ 348 * Make sure the uguru is ready and then send the bank address,
349 * after this the uguru is no longer "ready".
350 */
307 if (abituguru_ready(data) != 0) 351 if (abituguru_ready(data) != 0)
308 return -EIO; 352 return -EIO;
309 outb(bank_addr, data->addr + ABIT_UGURU_DATA); 353 outb(bank_addr, data->addr + ABIT_UGURU_DATA);
310 data->uguru_ready = 0; 354 data->uguru_ready = 0;
311 355
312 /* Wait till the uguru is ABIT_UGURU_STATUS_INPUT state again 356 /*
313 and send the sensor addr */ 357 * Wait till the uguru is ABIT_UGURU_STATUS_INPUT state again
358 * and send the sensor addr
359 */
314 if (abituguru_wait(data, ABIT_UGURU_STATUS_INPUT)) { 360 if (abituguru_wait(data, ABIT_UGURU_STATUS_INPUT)) {
315 if (retries) { 361 if (retries) {
316 ABIT_UGURU_DEBUG(3, "timeout exceeded " 362 ABIT_UGURU_DEBUG(3, "timeout exceeded "
@@ -332,8 +378,10 @@ static int abituguru_send_address(struct abituguru_data *data,
332 } 378 }
333} 379}
334 380
335/* Read count bytes from sensor sensor_addr in bank bank_addr and store the 381/*
336 result in buf, retry the send address part of the read retries times. */ 382 * Read count bytes from sensor sensor_addr in bank bank_addr and store the
383 * result in buf, retry the send address part of the read retries times.
384 */
337static int abituguru_read(struct abituguru_data *data, 385static int abituguru_read(struct abituguru_data *data,
338 u8 bank_addr, u8 sensor_addr, u8 *buf, int count, int retries) 386 u8 bank_addr, u8 sensor_addr, u8 *buf, int count, int retries)
339{ 387{
@@ -362,13 +410,17 @@ static int abituguru_read(struct abituguru_data *data,
362 return i; 410 return i;
363} 411}
364 412
365/* Write count bytes from buf to sensor sensor_addr in bank bank_addr, the send 413/*
366 address part of the write is always retried ABIT_UGURU_MAX_RETRIES times. */ 414 * Write count bytes from buf to sensor sensor_addr in bank bank_addr, the send
415 * address part of the write is always retried ABIT_UGURU_MAX_RETRIES times.
416 */
367static int abituguru_write(struct abituguru_data *data, 417static int abituguru_write(struct abituguru_data *data,
368 u8 bank_addr, u8 sensor_addr, u8 *buf, int count) 418 u8 bank_addr, u8 sensor_addr, u8 *buf, int count)
369{ 419{
370 /* We use the ready timeout as we have to wait for 0xAC just like the 420 /*
371 ready function */ 421 * We use the ready timeout as we have to wait for 0xAC just like the
422 * ready function
423 */
372 int i, timeout = ABIT_UGURU_READY_TIMEOUT; 424 int i, timeout = ABIT_UGURU_READY_TIMEOUT;
373 425
374 /* Send the address */ 426 /* Send the address */
@@ -388,9 +440,11 @@ static int abituguru_write(struct abituguru_data *data,
388 outb(buf[i], data->addr + ABIT_UGURU_CMD); 440 outb(buf[i], data->addr + ABIT_UGURU_CMD);
389 } 441 }
390 442
391 /* Now we need to wait till the chip is ready to be read again, 443 /*
392 so that we can read 0xAC as confirmation that our write has 444 * Now we need to wait till the chip is ready to be read again,
393 succeeded. */ 445 * so that we can read 0xAC as confirmation that our write has
446 * succeeded.
447 */
394 if (abituguru_wait(data, ABIT_UGURU_STATUS_READ)) { 448 if (abituguru_wait(data, ABIT_UGURU_STATUS_READ)) {
395 ABIT_UGURU_DEBUG(1, "timeout exceeded waiting for read state " 449 ABIT_UGURU_DEBUG(1, "timeout exceeded waiting for read state "
396 "after write (bank: %d, sensor: %d)\n", (int)bank_addr, 450 "after write (bank: %d, sensor: %d)\n", (int)bank_addr,
@@ -416,12 +470,14 @@ static int abituguru_write(struct abituguru_data *data,
416 return i; 470 return i;
417} 471}
418 472
419/* Detect sensor type. Temp and Volt sensors are enabled with 473/*
420 different masks and will ignore enable masks not meant for them. 474 * Detect sensor type. Temp and Volt sensors are enabled with
421 This enables us to test what kind of sensor we're dealing with. 475 * different masks and will ignore enable masks not meant for them.
422 By setting the alarm thresholds so that we will always get an 476 * This enables us to test what kind of sensor we're dealing with.
423 alarm for sensor type X and then enabling the sensor as sensor type 477 * By setting the alarm thresholds so that we will always get an
424 X, if we then get an alarm it is a sensor of type X. */ 478 * alarm for sensor type X and then enabling the sensor as sensor type
479 * X, if we then get an alarm it is a sensor of type X.
480 */
425static int __devinit 481static int __devinit
426abituguru_detect_bank1_sensor_type(struct abituguru_data *data, 482abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
427 u8 sensor_addr) 483 u8 sensor_addr)
@@ -448,16 +504,20 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
448 pr_warn("bank1-sensor: %d reading (%d) too close to limits, " 504 pr_warn("bank1-sensor: %d reading (%d) too close to limits, "
449 "unable to determine sensor type, skipping sensor\n", 505 "unable to determine sensor type, skipping sensor\n",
450 (int)sensor_addr, (int)val); 506 (int)sensor_addr, (int)val);
451 /* assume no sensor is there for sensors for which we can't 507 /*
452 determine the sensor type because their reading is too close 508 * assume no sensor is there for sensors for which we can't
453 to their limits, this usually means no sensor is there. */ 509 * determine the sensor type because their reading is too close
510 * to their limits, this usually means no sensor is there.
511 */
454 return ABIT_UGURU_NC; 512 return ABIT_UGURU_NC;
455 } 513 }
456 514
457 ABIT_UGURU_DEBUG(2, "testing bank1 sensor %d\n", (int)sensor_addr); 515 ABIT_UGURU_DEBUG(2, "testing bank1 sensor %d\n", (int)sensor_addr);
458 /* Volt sensor test, enable volt low alarm, set min value ridicously 516 /*
459 high, or vica versa if the reading is very high. If its a volt 517 * Volt sensor test, enable volt low alarm, set min value ridicously
460 sensor this should always give us an alarm. */ 518 * high, or vica versa if the reading is very high. If its a volt
519 * sensor this should always give us an alarm.
520 */
461 if (val <= 240u) { 521 if (val <= 240u) {
462 buf[0] = ABIT_UGURU_VOLT_LOW_ALARM_ENABLE; 522 buf[0] = ABIT_UGURU_VOLT_LOW_ALARM_ENABLE;
463 buf[1] = 245; 523 buf[1] = 245;
@@ -473,8 +533,10 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
473 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, 533 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr,
474 buf, 3) != 3) 534 buf, 3) != 3)
475 goto abituguru_detect_bank1_sensor_type_exit; 535 goto abituguru_detect_bank1_sensor_type_exit;
476 /* Now we need 20 ms to give the uguru time to read the sensors 536 /*
477 and raise a voltage alarm */ 537 * Now we need 20 ms to give the uguru time to read the sensors
538 * and raise a voltage alarm
539 */
478 set_current_state(TASK_UNINTERRUPTIBLE); 540 set_current_state(TASK_UNINTERRUPTIBLE);
479 schedule_timeout(HZ/50); 541 schedule_timeout(HZ/50);
480 /* Check for alarm and check the alarm is a volt low alarm. */ 542 /* Check for alarm and check the alarm is a volt low alarm. */
@@ -497,17 +559,21 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
497 ABIT_UGURU_DEBUG(2, " alarm not raised during volt sensor " 559 ABIT_UGURU_DEBUG(2, " alarm not raised during volt sensor "
498 "test\n"); 560 "test\n");
499 561
500 /* Temp sensor test, enable sensor as a temp sensor, set beep value 562 /*
501 ridicously low (but not too low, otherwise uguru ignores it). 563 * Temp sensor test, enable sensor as a temp sensor, set beep value
502 If its a temp sensor this should always give us an alarm. */ 564 * ridicously low (but not too low, otherwise uguru ignores it).
565 * If its a temp sensor this should always give us an alarm.
566 */
503 buf[0] = ABIT_UGURU_TEMP_HIGH_ALARM_ENABLE; 567 buf[0] = ABIT_UGURU_TEMP_HIGH_ALARM_ENABLE;
504 buf[1] = 5; 568 buf[1] = 5;
505 buf[2] = 10; 569 buf[2] = 10;
506 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, 570 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr,
507 buf, 3) != 3) 571 buf, 3) != 3)
508 goto abituguru_detect_bank1_sensor_type_exit; 572 goto abituguru_detect_bank1_sensor_type_exit;
509 /* Now we need 50 ms to give the uguru time to read the sensors 573 /*
510 and raise a temp alarm */ 574 * Now we need 50 ms to give the uguru time to read the sensors
575 * and raise a temp alarm
576 */
511 set_current_state(TASK_UNINTERRUPTIBLE); 577 set_current_state(TASK_UNINTERRUPTIBLE);
512 schedule_timeout(HZ/20); 578 schedule_timeout(HZ/20);
513 /* Check for alarm and check the alarm is a temp high alarm. */ 579 /* Check for alarm and check the alarm is a temp high alarm. */
@@ -532,9 +598,11 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
532 598
533 ret = ABIT_UGURU_NC; 599 ret = ABIT_UGURU_NC;
534abituguru_detect_bank1_sensor_type_exit: 600abituguru_detect_bank1_sensor_type_exit:
535 /* Restore original settings, failing here is really BAD, it has been 601 /*
536 reported that some BIOS-es hang when entering the uGuru menu with 602 * Restore original settings, failing here is really BAD, it has been
537 invalid settings present in the uGuru, so we try this 3 times. */ 603 * reported that some BIOS-es hang when entering the uGuru menu with
604 * invalid settings present in the uGuru, so we try this 3 times.
605 */
538 for (i = 0; i < 3; i++) 606 for (i = 0; i < 3; i++)
539 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, 607 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2,
540 sensor_addr, data->bank1_settings[sensor_addr], 608 sensor_addr, data->bank1_settings[sensor_addr],
@@ -548,23 +616,25 @@ abituguru_detect_bank1_sensor_type_exit:
548 return ret; 616 return ret;
549} 617}
550 618
551/* These functions try to find out how many sensors there are in bank2 and how 619/*
552 many pwms there are. The purpose of this is to make sure that we don't give 620 * These functions try to find out how many sensors there are in bank2 and how
553 the user the possibility to change settings for non-existent sensors / pwm. 621 * many pwms there are. The purpose of this is to make sure that we don't give
554 The uGuru will happily read / write whatever memory happens to be after the 622 * the user the possibility to change settings for non-existent sensors / pwm.
555 memory storing the PWM settings when reading/writing to a PWM which is not 623 * The uGuru will happily read / write whatever memory happens to be after the
556 there. Notice even if we detect a PWM which doesn't exist we normally won't 624 * memory storing the PWM settings when reading/writing to a PWM which is not
557 write to it, unless the user tries to change the settings. 625 * there. Notice even if we detect a PWM which doesn't exist we normally won't
558 626 * write to it, unless the user tries to change the settings.
559 Although the uGuru allows reading (settings) from non existing bank2 627 *
560 sensors, my version of the uGuru does seem to stop writing to them, the 628 * Although the uGuru allows reading (settings) from non existing bank2
561 write function above aborts in this case with: 629 * sensors, my version of the uGuru does seem to stop writing to them, the
562 "CMD reg does not hold 0xAC after write" 630 * write function above aborts in this case with:
563 631 * "CMD reg does not hold 0xAC after write"
564 Notice these 2 tests are non destructive iow read-only tests, otherwise 632 *
565 they would defeat their purpose. Although for the bank2_sensors detection a 633 * Notice these 2 tests are non destructive iow read-only tests, otherwise
566 read/write test would be feasible because of the reaction above, I've 634 * they would defeat their purpose. Although for the bank2_sensors detection a
567 however opted to stay on the safe side. */ 635 * read/write test would be feasible because of the reaction above, I've
636 * however opted to stay on the safe side.
637 */
568static void __devinit 638static void __devinit
569abituguru_detect_no_bank2_sensors(struct abituguru_data *data) 639abituguru_detect_no_bank2_sensors(struct abituguru_data *data)
570{ 640{
@@ -580,12 +650,14 @@ abituguru_detect_no_bank2_sensors(struct abituguru_data *data)
580 650
581 ABIT_UGURU_DEBUG(2, "detecting number of fan sensors\n"); 651 ABIT_UGURU_DEBUG(2, "detecting number of fan sensors\n");
582 for (i = 0; i < ABIT_UGURU_MAX_BANK2_SENSORS; i++) { 652 for (i = 0; i < ABIT_UGURU_MAX_BANK2_SENSORS; i++) {
583 /* 0x89 are the known used bits: 653 /*
584 -0x80 enable shutdown 654 * 0x89 are the known used bits:
585 -0x08 enable beep 655 * -0x80 enable shutdown
586 -0x01 enable alarm 656 * -0x08 enable beep
587 All other bits should be 0, but on some motherboards 657 * -0x01 enable alarm
588 0x40 (bit 6) is also high for some of the fans?? */ 658 * All other bits should be 0, but on some motherboards
659 * 0x40 (bit 6) is also high for some of the fans??
660 */
589 if (data->bank2_settings[i][0] & ~0xC9) { 661 if (data->bank2_settings[i][0] & ~0xC9) {
590 ABIT_UGURU_DEBUG(2, " bank2 sensor %d does not seem " 662 ABIT_UGURU_DEBUG(2, " bank2 sensor %d does not seem "
591 "to be a fan sensor: settings[0] = %02X\n", 663 "to be a fan sensor: settings[0] = %02X\n",
@@ -633,9 +705,11 @@ abituguru_detect_no_pwms(struct abituguru_data *data)
633 705
634 ABIT_UGURU_DEBUG(2, "detecting number of PWM outputs\n"); 706 ABIT_UGURU_DEBUG(2, "detecting number of PWM outputs\n");
635 for (i = 0; i < ABIT_UGURU_MAX_PWMS; i++) { 707 for (i = 0; i < ABIT_UGURU_MAX_PWMS; i++) {
636 /* 0x80 is the enable bit and the low 708 /*
637 nibble is which temp sensor to use, 709 * 0x80 is the enable bit and the low
638 the other bits should be 0 */ 710 * nibble is which temp sensor to use,
711 * the other bits should be 0
712 */
639 if (data->pwm_settings[i][0] & ~0x8F) { 713 if (data->pwm_settings[i][0] & ~0x8F) {
640 ABIT_UGURU_DEBUG(2, " pwm channel %d does not seem " 714 ABIT_UGURU_DEBUG(2, " pwm channel %d does not seem "
641 "to be a pwm channel: settings[0] = %02X\n", 715 "to be a pwm channel: settings[0] = %02X\n",
@@ -643,8 +717,10 @@ abituguru_detect_no_pwms(struct abituguru_data *data)
643 break; 717 break;
644 } 718 }
645 719
646 /* the low nibble must correspond to one of the temp sensors 720 /*
647 we've found */ 721 * the low nibble must correspond to one of the temp sensors
722 * we've found
723 */
648 for (j = 0; j < data->bank1_sensors[ABIT_UGURU_TEMP_SENSOR]; 724 for (j = 0; j < data->bank1_sensors[ABIT_UGURU_TEMP_SENSOR];
649 j++) { 725 j++) {
650 if (data->bank1_address[ABIT_UGURU_TEMP_SENSOR][j] == 726 if (data->bank1_address[ABIT_UGURU_TEMP_SENSOR][j] ==
@@ -711,9 +787,11 @@ abituguru_detect_no_pwms_exit:
711 ABIT_UGURU_DEBUG(2, " found: %d PWM outputs\n", (int)data->pwms); 787 ABIT_UGURU_DEBUG(2, " found: %d PWM outputs\n", (int)data->pwms);
712} 788}
713 789
714/* Following are the sysfs callback functions. These functions expect: 790/*
715 sensor_device_attribute_2->index: sensor address/offset in the bank 791 * Following are the sysfs callback functions. These functions expect:
716 sensor_device_attribute_2->nr: register offset, bitmask or NA. */ 792 * sensor_device_attribute_2->index: sensor address/offset in the bank
793 * sensor_device_attribute_2->nr: register offset, bitmask or NA.
794 */
717static struct abituguru_data *abituguru_update_device(struct device *dev); 795static struct abituguru_data *abituguru_update_device(struct device *dev);
718 796
719static ssize_t show_bank1_value(struct device *dev, 797static ssize_t show_bank1_value(struct device *dev,
@@ -763,10 +841,18 @@ static ssize_t store_bank1_setting(struct device *dev, struct device_attribute
763{ 841{
764 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 842 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
765 struct abituguru_data *data = dev_get_drvdata(dev); 843 struct abituguru_data *data = dev_get_drvdata(dev);
766 u8 val = (simple_strtoul(buf, NULL, 10) * 255 + 844 unsigned long val;
767 data->bank1_max_value[attr->index]/2) / 845 ssize_t ret;
846
847 ret = kstrtoul(buf, 10, &val);
848 if (ret)
849 return ret;
850
851 ret = count;
852 val = (val * 255 + data->bank1_max_value[attr->index] / 2) /
768 data->bank1_max_value[attr->index]; 853 data->bank1_max_value[attr->index];
769 ssize_t ret = count; 854 if (val > 255)
855 return -EINVAL;
770 856
771 mutex_lock(&data->update_lock); 857 mutex_lock(&data->update_lock);
772 if (data->bank1_settings[attr->index][attr->nr] != val) { 858 if (data->bank1_settings[attr->index][attr->nr] != val) {
@@ -788,13 +874,19 @@ static ssize_t store_bank2_setting(struct device *dev, struct device_attribute
788{ 874{
789 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 875 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
790 struct abituguru_data *data = dev_get_drvdata(dev); 876 struct abituguru_data *data = dev_get_drvdata(dev);
791 u8 val = (simple_strtoul(buf, NULL, 10)*255 + ABIT_UGURU_FAN_MAX/2) / 877 unsigned long val;
792 ABIT_UGURU_FAN_MAX; 878 ssize_t ret;
793 ssize_t ret = count; 879
880 ret = kstrtoul(buf, 10, &val);
881 if (ret)
882 return ret;
883
884 ret = count;
885 val = (val * 255 + ABIT_UGURU_FAN_MAX / 2) / ABIT_UGURU_FAN_MAX;
794 886
795 /* this check can be done before taking the lock */ 887 /* this check can be done before taking the lock */
796 if ((val < abituguru_bank2_min_threshold) || 888 if (val < abituguru_bank2_min_threshold ||
797 (val > abituguru_bank2_max_threshold)) 889 val > abituguru_bank2_max_threshold)
798 return -EINVAL; 890 return -EINVAL;
799 891
800 mutex_lock(&data->update_lock); 892 mutex_lock(&data->update_lock);
@@ -819,11 +911,13 @@ static ssize_t show_bank1_alarm(struct device *dev,
819 struct abituguru_data *data = abituguru_update_device(dev); 911 struct abituguru_data *data = abituguru_update_device(dev);
820 if (!data) 912 if (!data)
821 return -EIO; 913 return -EIO;
822 /* See if the alarm bit for this sensor is set, and if the 914 /*
823 alarm matches the type of alarm we're looking for (for volt 915 * See if the alarm bit for this sensor is set, and if the
824 it can be either low or high). The type is stored in a few 916 * alarm matches the type of alarm we're looking for (for volt
825 readonly bits in the settings part of the relevant sensor. 917 * it can be either low or high). The type is stored in a few
826 The bitmask of the type is passed to us in attr->nr. */ 918 * readonly bits in the settings part of the relevant sensor.
919 * The bitmask of the type is passed to us in attr->nr.
920 */
827 if ((data->alarms[attr->index / 8] & (0x01 << (attr->index % 8))) && 921 if ((data->alarms[attr->index / 8] & (0x01 << (attr->index % 8))) &&
828 (data->bank1_settings[attr->index][0] & attr->nr)) 922 (data->bank1_settings[attr->index][0] & attr->nr))
829 return sprintf(buf, "1\n"); 923 return sprintf(buf, "1\n");
@@ -871,10 +965,15 @@ static ssize_t store_bank1_mask(struct device *dev,
871{ 965{
872 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 966 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
873 struct abituguru_data *data = dev_get_drvdata(dev); 967 struct abituguru_data *data = dev_get_drvdata(dev);
874 int mask = simple_strtoul(buf, NULL, 10); 968 ssize_t ret;
875 ssize_t ret = count;
876 u8 orig_val; 969 u8 orig_val;
970 unsigned long mask;
971
972 ret = kstrtoul(buf, 10, &mask);
973 if (ret)
974 return ret;
877 975
976 ret = count;
878 mutex_lock(&data->update_lock); 977 mutex_lock(&data->update_lock);
879 orig_val = data->bank1_settings[attr->index][0]; 978 orig_val = data->bank1_settings[attr->index][0];
880 979
@@ -899,10 +998,15 @@ static ssize_t store_bank2_mask(struct device *dev,
899{ 998{
900 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 999 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
901 struct abituguru_data *data = dev_get_drvdata(dev); 1000 struct abituguru_data *data = dev_get_drvdata(dev);
902 int mask = simple_strtoul(buf, NULL, 10); 1001 ssize_t ret;
903 ssize_t ret = count;
904 u8 orig_val; 1002 u8 orig_val;
1003 unsigned long mask;
905 1004
1005 ret = kstrtoul(buf, 10, &mask);
1006 if (ret)
1007 return ret;
1008
1009 ret = count;
906 mutex_lock(&data->update_lock); 1010 mutex_lock(&data->update_lock);
907 orig_val = data->bank2_settings[attr->index][0]; 1011 orig_val = data->bank2_settings[attr->index][0];
908 1012
@@ -937,10 +1041,17 @@ static ssize_t store_pwm_setting(struct device *dev, struct device_attribute
937{ 1041{
938 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 1042 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
939 struct abituguru_data *data = dev_get_drvdata(dev); 1043 struct abituguru_data *data = dev_get_drvdata(dev);
940 u8 min, val = (simple_strtoul(buf, NULL, 10) + 1044 u8 min;
941 abituguru_pwm_settings_multiplier[attr->nr]/2) / 1045 unsigned long val;
942 abituguru_pwm_settings_multiplier[attr->nr]; 1046 ssize_t ret;
943 ssize_t ret = count; 1047
1048 ret = kstrtoul(buf, 10, &val);
1049 if (ret)
1050 return ret;
1051
1052 ret = count;
1053 val = (val + abituguru_pwm_settings_multiplier[attr->nr] / 2) /
1054 abituguru_pwm_settings_multiplier[attr->nr];
944 1055
945 /* special case pwm1 min pwm% */ 1056 /* special case pwm1 min pwm% */
946 if ((attr->index == 0) && ((attr->nr == 1) || (attr->nr == 2))) 1057 if ((attr->index == 0) && ((attr->nr == 1) || (attr->nr == 2)))
@@ -949,7 +1060,7 @@ static ssize_t store_pwm_setting(struct device *dev, struct device_attribute
949 min = abituguru_pwm_min[attr->nr]; 1060 min = abituguru_pwm_min[attr->nr];
950 1061
951 /* this check can be done before taking the lock */ 1062 /* this check can be done before taking the lock */
952 if ((val < min) || (val > abituguru_pwm_max[attr->nr])) 1063 if (val < min || val > abituguru_pwm_max[attr->nr])
953 return -EINVAL; 1064 return -EINVAL;
954 1065
955 mutex_lock(&data->update_lock); 1066 mutex_lock(&data->update_lock);
@@ -981,8 +1092,10 @@ static ssize_t show_pwm_sensor(struct device *dev,
981 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 1092 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
982 struct abituguru_data *data = dev_get_drvdata(dev); 1093 struct abituguru_data *data = dev_get_drvdata(dev);
983 int i; 1094 int i;
984 /* We need to walk to the temp sensor addresses to find what 1095 /*
985 the userspace id of the configured temp sensor is. */ 1096 * We need to walk to the temp sensor addresses to find what
1097 * the userspace id of the configured temp sensor is.
1098 */
986 for (i = 0; i < data->bank1_sensors[ABIT_UGURU_TEMP_SENSOR]; i++) 1099 for (i = 0; i < data->bank1_sensors[ABIT_UGURU_TEMP_SENSOR]; i++)
987 if (data->bank1_address[ABIT_UGURU_TEMP_SENSOR][i] == 1100 if (data->bank1_address[ABIT_UGURU_TEMP_SENSOR][i] ==
988 (data->pwm_settings[attr->index][0] & 0x0F)) 1101 (data->pwm_settings[attr->index][0] & 0x0F))
@@ -996,27 +1109,32 @@ static ssize_t store_pwm_sensor(struct device *dev, struct device_attribute
996{ 1109{
997 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 1110 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
998 struct abituguru_data *data = dev_get_drvdata(dev); 1111 struct abituguru_data *data = dev_get_drvdata(dev);
999 unsigned long val = simple_strtoul(buf, NULL, 10) - 1; 1112 ssize_t ret;
1000 ssize_t ret = count; 1113 unsigned long val;
1114 u8 orig_val;
1115 u8 address;
1116
1117 ret = kstrtoul(buf, 10, &val);
1118 if (ret)
1119 return ret;
1001 1120
1121 if (val == 0 || val > data->bank1_sensors[ABIT_UGURU_TEMP_SENSOR])
1122 return -EINVAL;
1123
1124 val -= 1;
1125 ret = count;
1002 mutex_lock(&data->update_lock); 1126 mutex_lock(&data->update_lock);
1003 if (val < data->bank1_sensors[ABIT_UGURU_TEMP_SENSOR]) { 1127 orig_val = data->pwm_settings[attr->index][0];
1004 u8 orig_val = data->pwm_settings[attr->index][0]; 1128 address = data->bank1_address[ABIT_UGURU_TEMP_SENSOR][val];
1005 u8 address = data->bank1_address[ABIT_UGURU_TEMP_SENSOR][val]; 1129 data->pwm_settings[attr->index][0] &= 0xF0;
1006 data->pwm_settings[attr->index][0] &= 0xF0; 1130 data->pwm_settings[attr->index][0] |= address;
1007 data->pwm_settings[attr->index][0] |= address; 1131 if (data->pwm_settings[attr->index][0] != orig_val) {
1008 if (data->pwm_settings[attr->index][0] != orig_val) { 1132 if (abituguru_write(data, ABIT_UGURU_FAN_PWM + 1, attr->index,
1009 if (abituguru_write(data, ABIT_UGURU_FAN_PWM + 1, 1133 data->pwm_settings[attr->index], 5) < 1) {
1010 attr->index, 1134 data->pwm_settings[attr->index][0] = orig_val;
1011 data->pwm_settings[attr->index], 1135 ret = -EIO;
1012 5) < 1) {
1013 data->pwm_settings[attr->index][0] = orig_val;
1014 ret = -EIO;
1015 }
1016 } 1136 }
1017 } 1137 }
1018 else
1019 ret = -EINVAL;
1020 mutex_unlock(&data->update_lock); 1138 mutex_unlock(&data->update_lock);
1021 return ret; 1139 return ret;
1022} 1140}
@@ -1037,22 +1155,27 @@ static ssize_t store_pwm_enable(struct device *dev, struct device_attribute
1037{ 1155{
1038 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 1156 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
1039 struct abituguru_data *data = dev_get_drvdata(dev); 1157 struct abituguru_data *data = dev_get_drvdata(dev);
1040 u8 orig_val, user_val = simple_strtoul(buf, NULL, 10); 1158 u8 orig_val;
1041 ssize_t ret = count; 1159 ssize_t ret;
1160 unsigned long user_val;
1161
1162 ret = kstrtoul(buf, 10, &user_val);
1163 if (ret)
1164 return ret;
1042 1165
1166 ret = count;
1043 mutex_lock(&data->update_lock); 1167 mutex_lock(&data->update_lock);
1044 orig_val = data->pwm_settings[attr->index][0]; 1168 orig_val = data->pwm_settings[attr->index][0];
1045 switch (user_val) { 1169 switch (user_val) {
1046 case 0: 1170 case 0:
1047 data->pwm_settings[attr->index][0] &= 1171 data->pwm_settings[attr->index][0] &=
1048 ~ABIT_UGURU_FAN_PWM_ENABLE; 1172 ~ABIT_UGURU_FAN_PWM_ENABLE;
1049 break; 1173 break;
1050 case 2: 1174 case 2:
1051 data->pwm_settings[attr->index][0] |= 1175 data->pwm_settings[attr->index][0] |= ABIT_UGURU_FAN_PWM_ENABLE;
1052 ABIT_UGURU_FAN_PWM_ENABLE; 1176 break;
1053 break; 1177 default:
1054 default: 1178 ret = -EINVAL;
1055 ret = -EINVAL;
1056 } 1179 }
1057 if ((data->pwm_settings[attr->index][0] != orig_val) && 1180 if ((data->pwm_settings[attr->index][0] != orig_val) &&
1058 (abituguru_write(data, ABIT_UGURU_FAN_PWM + 1, 1181 (abituguru_write(data, ABIT_UGURU_FAN_PWM + 1,
@@ -1147,13 +1270,16 @@ static int __devinit abituguru_probe(struct platform_device *pdev)
1147 int i, j, used, sysfs_names_free, sysfs_attr_i, res = -ENODEV; 1270 int i, j, used, sysfs_names_free, sysfs_attr_i, res = -ENODEV;
1148 char *sysfs_filename; 1271 char *sysfs_filename;
1149 1272
1150 /* El weirdo probe order, to keep the sysfs order identical to the 1273 /*
1151 BIOS and window-appliction listing order. */ 1274 * El weirdo probe order, to keep the sysfs order identical to the
1275 * BIOS and window-appliction listing order.
1276 */
1152 const u8 probe_order[ABIT_UGURU_MAX_BANK1_SENSORS] = { 1277 const u8 probe_order[ABIT_UGURU_MAX_BANK1_SENSORS] = {
1153 0x00, 0x01, 0x03, 0x04, 0x0A, 0x08, 0x0E, 0x02, 1278 0x00, 0x01, 0x03, 0x04, 0x0A, 0x08, 0x0E, 0x02,
1154 0x09, 0x06, 0x05, 0x0B, 0x0F, 0x0D, 0x07, 0x0C }; 1279 0x09, 0x06, 0x05, 0x0B, 0x0F, 0x0D, 0x07, 0x0C };
1155 1280
1156 if (!(data = kzalloc(sizeof(struct abituguru_data), GFP_KERNEL))) 1281 data = kzalloc(sizeof(struct abituguru_data), GFP_KERNEL);
1282 if (!data)
1157 return -ENOMEM; 1283 return -ENOMEM;
1158 1284
1159 data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start; 1285 data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start;
@@ -1164,9 +1290,11 @@ static int __devinit abituguru_probe(struct platform_device *pdev)
1164 if (inb_p(data->addr + ABIT_UGURU_DATA) == ABIT_UGURU_STATUS_INPUT) 1290 if (inb_p(data->addr + ABIT_UGURU_DATA) == ABIT_UGURU_STATUS_INPUT)
1165 data->uguru_ready = 1; 1291 data->uguru_ready = 1;
1166 1292
1167 /* Completely read the uGuru this has 2 purposes: 1293 /*
1168 - testread / see if one really is there. 1294 * Completely read the uGuru this has 2 purposes:
1169 - make an in memory copy of all the uguru settings for future use. */ 1295 * - testread / see if one really is there.
1296 * - make an in memory copy of all the uguru settings for future use.
1297 */
1170 if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, 1298 if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0,
1171 data->alarms, 3, ABIT_UGURU_MAX_RETRIES) != 3) 1299 data->alarms, 3, ABIT_UGURU_MAX_RETRIES) != 3)
1172 goto abituguru_probe_error; 1300 goto abituguru_probe_error;
@@ -1181,11 +1309,13 @@ static int __devinit abituguru_probe(struct platform_device *pdev)
1181 ABIT_UGURU_MAX_RETRIES) != 3) 1309 ABIT_UGURU_MAX_RETRIES) != 3)
1182 goto abituguru_probe_error; 1310 goto abituguru_probe_error;
1183 } 1311 }
1184 /* Note: We don't know how many bank2 sensors / pwms there really are, 1312 /*
1185 but in order to "detect" this we need to read the maximum amount 1313 * Note: We don't know how many bank2 sensors / pwms there really are,
1186 anyways. If we read sensors/pwms not there we'll just read crap 1314 * but in order to "detect" this we need to read the maximum amount
1187 this can't hurt. We need the detection because we don't want 1315 * anyways. If we read sensors/pwms not there we'll just read crap
1188 unwanted writes, which will hurt! */ 1316 * this can't hurt. We need the detection because we don't want
1317 * unwanted writes, which will hurt!
1318 */
1189 for (i = 0; i < ABIT_UGURU_MAX_BANK2_SENSORS; i++) { 1319 for (i = 0; i < ABIT_UGURU_MAX_BANK2_SENSORS; i++) {
1190 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK2, i, 1320 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK2, i,
1191 &data->bank2_value[i], 1, 1321 &data->bank2_value[i], 1,
@@ -1332,24 +1462,26 @@ static struct abituguru_data *abituguru_update_device(struct device *dev)
1332 mutex_lock(&data->update_lock); 1462 mutex_lock(&data->update_lock);
1333 if (time_after(jiffies, data->last_updated + HZ)) { 1463 if (time_after(jiffies, data->last_updated + HZ)) {
1334 success = 0; 1464 success = 0;
1335 if ((err = abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, 1465 err = abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0,
1336 data->alarms, 3, 0)) != 3) 1466 data->alarms, 3, 0);
1467 if (err != 3)
1337 goto LEAVE_UPDATE; 1468 goto LEAVE_UPDATE;
1338 for (i = 0; i < ABIT_UGURU_MAX_BANK1_SENSORS; i++) { 1469 for (i = 0; i < ABIT_UGURU_MAX_BANK1_SENSORS; i++) {
1339 if ((err = abituguru_read(data, 1470 err = abituguru_read(data, ABIT_UGURU_SENSOR_BANK1,
1340 ABIT_UGURU_SENSOR_BANK1, i, 1471 i, &data->bank1_value[i], 1, 0);
1341 &data->bank1_value[i], 1, 0)) != 1) 1472 if (err != 1)
1342 goto LEAVE_UPDATE; 1473 goto LEAVE_UPDATE;
1343 if ((err = abituguru_read(data, 1474 err = abituguru_read(data, ABIT_UGURU_SENSOR_BANK1 + 1,
1344 ABIT_UGURU_SENSOR_BANK1 + 1, i, 1475 i, data->bank1_settings[i], 3, 0);
1345 data->bank1_settings[i], 3, 0)) != 3) 1476 if (err != 3)
1346 goto LEAVE_UPDATE; 1477 goto LEAVE_UPDATE;
1347 } 1478 }
1348 for (i = 0; i < data->bank2_sensors; i++) 1479 for (i = 0; i < data->bank2_sensors; i++) {
1349 if ((err = abituguru_read(data, 1480 err = abituguru_read(data, ABIT_UGURU_SENSOR_BANK2, i,
1350 ABIT_UGURU_SENSOR_BANK2, i, 1481 &data->bank2_value[i], 1, 0);
1351 &data->bank2_value[i], 1, 0)) != 1) 1482 if (err != 1)
1352 goto LEAVE_UPDATE; 1483 goto LEAVE_UPDATE;
1484 }
1353 /* success! */ 1485 /* success! */
1354 success = 1; 1486 success = 1;
1355 data->update_timeouts = 0; 1487 data->update_timeouts = 0;
@@ -1385,8 +1517,10 @@ LEAVE_UPDATE:
1385static int abituguru_suspend(struct platform_device *pdev, pm_message_t state) 1517static int abituguru_suspend(struct platform_device *pdev, pm_message_t state)
1386{ 1518{
1387 struct abituguru_data *data = platform_get_drvdata(pdev); 1519 struct abituguru_data *data = platform_get_drvdata(pdev);
1388 /* make sure all communications with the uguru are done and no new 1520 /*
1389 ones are started */ 1521 * make sure all communications with the uguru are done and no new
1522 * ones are started
1523 */
1390 mutex_lock(&data->update_lock); 1524 mutex_lock(&data->update_lock);
1391 return 0; 1525 return 0;
1392} 1526}
@@ -1418,12 +1552,14 @@ static struct platform_driver abituguru_driver = {
1418 1552
1419static int __init abituguru_detect(void) 1553static int __init abituguru_detect(void)
1420{ 1554{
1421 /* See if there is an uguru there. After a reboot uGuru will hold 0x00 1555 /*
1422 at DATA and 0xAC, when this driver has already been loaded once 1556 * See if there is an uguru there. After a reboot uGuru will hold 0x00
1423 DATA will hold 0x08. For most uGuru's CMD will hold 0xAC in either 1557 * at DATA and 0xAC, when this driver has already been loaded once
1424 scenario but some will hold 0x00. 1558 * DATA will hold 0x08. For most uGuru's CMD will hold 0xAC in either
1425 Some uGuru's initially hold 0x09 at DATA and will only hold 0x08 1559 * scenario but some will hold 0x00.
1426 after reading CMD first, so CMD must be read first! */ 1560 * Some uGuru's initially hold 0x09 at DATA and will only hold 0x08
1561 * after reading CMD first, so CMD must be read first!
1562 */
1427 u8 cmd_val = inb_p(ABIT_UGURU_BASE + ABIT_UGURU_CMD); 1563 u8 cmd_val = inb_p(ABIT_UGURU_BASE + ABIT_UGURU_CMD);
1428 u8 data_val = inb_p(ABIT_UGURU_BASE + ABIT_UGURU_DATA); 1564 u8 data_val = inb_p(ABIT_UGURU_BASE + ABIT_UGURU_DATA);
1429 if (((data_val == 0x00) || (data_val == 0x08)) && 1565 if (((data_val == 0x00) || (data_val == 0x08)) &&
diff --git a/drivers/hwmon/abituguru3.c b/drivers/hwmon/abituguru3.c
index 34a14a77e008..a5bc4287daa6 100644
--- a/drivers/hwmon/abituguru3.c
+++ b/drivers/hwmon/abituguru3.c
@@ -1,28 +1,28 @@
1/* 1/*
2 abituguru3.c 2 * abituguru3.c
3 3 *
4 Copyright (c) 2006-2008 Hans de Goede <hdegoede@redhat.com> 4 * Copyright (c) 2006-2008 Hans de Goede <hdegoede@redhat.com>
5 Copyright (c) 2008 Alistair John Strachan <alistair@devzero.co.uk> 5 * Copyright (c) 2008 Alistair John Strachan <alistair@devzero.co.uk>
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
9 the Free Software Foundation; either version 2 of the License, or 9 * the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 10 * (at your option) any later version.
11 11 *
12 This program is distributed in the hope that it will be useful, 12 * This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 15 * GNU General Public License for more details.
16 16 *
17 You should have received a copy of the GNU General Public License 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 18 * along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/ 20 */
21/* 21/*
22 This driver supports the sensor part of revision 3 of the custom Abit uGuru 22 * This driver supports the sensor part of revision 3 of the custom Abit uGuru
23 chip found on newer Abit uGuru motherboards. Note: because of lack of specs 23 * chip found on newer Abit uGuru motherboards. Note: because of lack of specs
24 only reading the sensors and their settings is supported. 24 * only reading the sensors and their settings is supported.
25*/ 25 */
26 26
27#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 27#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28 28
@@ -62,13 +62,17 @@
62#define ABIT_UGURU3_TEMP_SENSOR 1 62#define ABIT_UGURU3_TEMP_SENSOR 1
63#define ABIT_UGURU3_FAN_SENSOR 2 63#define ABIT_UGURU3_FAN_SENSOR 2
64 64
65/* Timeouts / Retries, if these turn out to need a lot of fiddling we could 65/*
66 convert them to params. Determined by trial and error. I assume this is 66 * Timeouts / Retries, if these turn out to need a lot of fiddling we could
67 cpu-speed independent, since the ISA-bus and not the CPU should be the 67 * convert them to params. Determined by trial and error. I assume this is
68 bottleneck. */ 68 * cpu-speed independent, since the ISA-bus and not the CPU should be the
69 * bottleneck.
70 */
69#define ABIT_UGURU3_WAIT_TIMEOUT 250 71#define ABIT_UGURU3_WAIT_TIMEOUT 250
70/* Normally the 0xAC at the end of synchronize() is reported after the 72/*
71 first read, but sometimes not and we need to poll */ 73 * Normally the 0xAC at the end of synchronize() is reported after the
74 * first read, but sometimes not and we need to poll
75 */
72#define ABIT_UGURU3_SYNCHRONIZE_TIMEOUT 5 76#define ABIT_UGURU3_SYNCHRONIZE_TIMEOUT 5
73/* utility macros */ 77/* utility macros */
74#define ABIT_UGURU3_NAME "abituguru3" 78#define ABIT_UGURU3_NAME "abituguru3"
@@ -78,32 +82,45 @@
78 82
79/* Macros to help calculate the sysfs_names array length */ 83/* Macros to help calculate the sysfs_names array length */
80#define ABIT_UGURU3_MAX_NO_SENSORS 26 84#define ABIT_UGURU3_MAX_NO_SENSORS 26
81/* sum of strlen +1 of: in??_input\0, in??_{min,max}\0, in??_{min,max}_alarm\0, 85/*
82 in??_{min,max}_alarm_enable\0, in??_beep\0, in??_shutdown\0, in??_label\0 */ 86 * sum of strlen +1 of: in??_input\0, in??_{min,max}\0, in??_{min,max}_alarm\0,
83#define ABIT_UGURU3_IN_NAMES_LENGTH (11 + 2 * 9 + 2 * 15 + 2 * 22 + 10 + 14 + 11) 87 * in??_{min,max}_alarm_enable\0, in??_beep\0, in??_shutdown\0, in??_label\0
84/* sum of strlen +1 of: temp??_input\0, temp??_max\0, temp??_crit\0, 88 */
85 temp??_alarm\0, temp??_alarm_enable\0, temp??_beep\0, temp??_shutdown\0, 89#define ABIT_UGURU3_IN_NAMES_LENGTH \
86 temp??_label\0 */ 90 (11 + 2 * 9 + 2 * 15 + 2 * 22 + 10 + 14 + 11)
91/*
92 * sum of strlen +1 of: temp??_input\0, temp??_max\0, temp??_crit\0,
93 * temp??_alarm\0, temp??_alarm_enable\0, temp??_beep\0, temp??_shutdown\0,
94 * temp??_label\0
95 */
87#define ABIT_UGURU3_TEMP_NAMES_LENGTH (13 + 11 + 12 + 13 + 20 + 12 + 16 + 13) 96#define ABIT_UGURU3_TEMP_NAMES_LENGTH (13 + 11 + 12 + 13 + 20 + 12 + 16 + 13)
88/* sum of strlen +1 of: fan??_input\0, fan??_min\0, fan??_alarm\0, 97/*
89 fan??_alarm_enable\0, fan??_beep\0, fan??_shutdown\0, fan??_label\0 */ 98 * sum of strlen +1 of: fan??_input\0, fan??_min\0, fan??_alarm\0,
99 * fan??_alarm_enable\0, fan??_beep\0, fan??_shutdown\0, fan??_label\0
100 */
90#define ABIT_UGURU3_FAN_NAMES_LENGTH (12 + 10 + 12 + 19 + 11 + 15 + 12) 101#define ABIT_UGURU3_FAN_NAMES_LENGTH (12 + 10 + 12 + 19 + 11 + 15 + 12)
91/* Worst case scenario 16 in sensors (longest names_length) and the rest 102/*
92 temp sensors (second longest names_length). */ 103 * Worst case scenario 16 in sensors (longest names_length) and the rest
104 * temp sensors (second longest names_length).
105 */
93#define ABIT_UGURU3_SYSFS_NAMES_LENGTH (16 * ABIT_UGURU3_IN_NAMES_LENGTH + \ 106#define ABIT_UGURU3_SYSFS_NAMES_LENGTH (16 * ABIT_UGURU3_IN_NAMES_LENGTH + \
94 (ABIT_UGURU3_MAX_NO_SENSORS - 16) * ABIT_UGURU3_TEMP_NAMES_LENGTH) 107 (ABIT_UGURU3_MAX_NO_SENSORS - 16) * ABIT_UGURU3_TEMP_NAMES_LENGTH)
95 108
96/* All the macros below are named identical to the openguru2 program 109/*
97 reverse engineered by Louis Kruger, hence the names might not be 100% 110 * All the macros below are named identical to the openguru2 program
98 logical. I could come up with better names, but I prefer keeping the names 111 * reverse engineered by Louis Kruger, hence the names might not be 100%
99 identical so that this driver can be compared with his work more easily. */ 112 * logical. I could come up with better names, but I prefer keeping the names
113 * identical so that this driver can be compared with his work more easily.
114 */
100/* Two i/o-ports are used by uGuru */ 115/* Two i/o-ports are used by uGuru */
101#define ABIT_UGURU3_BASE 0x00E0 116#define ABIT_UGURU3_BASE 0x00E0
102#define ABIT_UGURU3_CMD 0x00 117#define ABIT_UGURU3_CMD 0x00
103#define ABIT_UGURU3_DATA 0x04 118#define ABIT_UGURU3_DATA 0x04
104#define ABIT_UGURU3_REGION_LENGTH 5 119#define ABIT_UGURU3_REGION_LENGTH 5
105/* The wait_xxx functions return this on success and the last contents 120/*
106 of the DATA register (0-255) on failure. */ 121 * The wait_xxx functions return this on success and the last contents
122 * of the DATA register (0-255) on failure.
123 */
107#define ABIT_UGURU3_SUCCESS -1 124#define ABIT_UGURU3_SUCCESS -1
108/* uGuru status flags */ 125/* uGuru status flags */
109#define ABIT_UGURU3_STATUS_READY_FOR_READ 0x01 126#define ABIT_UGURU3_STATUS_READY_FOR_READ 0x01
@@ -112,7 +129,7 @@
112 129
113/* Structures */ 130/* Structures */
114struct abituguru3_sensor_info { 131struct abituguru3_sensor_info {
115 const char* name; 132 const char *name;
116 int port; 133 int port;
117 int type; 134 int type;
118 int multiplier; 135 int multiplier;
@@ -130,9 +147,11 @@ struct abituguru3_motherboard_info {
130 struct abituguru3_sensor_info sensors[ABIT_UGURU3_MAX_NO_SENSORS + 1]; 147 struct abituguru3_sensor_info sensors[ABIT_UGURU3_MAX_NO_SENSORS + 1];
131}; 148};
132 149
133/* For the Abit uGuru, we need to keep some data in memory. 150/*
134 The structure is dynamically allocated, at the same time when a new 151 * For the Abit uGuru, we need to keep some data in memory.
135 abituguru3 device is allocated. */ 152 * The structure is dynamically allocated, at the same time when a new
153 * abituguru3 device is allocated.
154 */
136struct abituguru3_data { 155struct abituguru3_data {
137 struct device *hwmon_dev; /* hwmon registered device */ 156 struct device *hwmon_dev; /* hwmon registered device */
138 struct mutex update_lock; /* protect access to data and uGuru */ 157 struct mutex update_lock; /* protect access to data and uGuru */
@@ -140,8 +159,10 @@ struct abituguru3_data {
140 char valid; /* !=0 if following fields are valid */ 159 char valid; /* !=0 if following fields are valid */
141 unsigned long last_updated; /* In jiffies */ 160 unsigned long last_updated; /* In jiffies */
142 161
143 /* For convenience the sysfs attr and their names are generated 162 /*
144 automatically. We have max 10 entries per sensor (for in sensors) */ 163 * For convenience the sysfs attr and their names are generated
164 * automatically. We have max 10 entries per sensor (for in sensors)
165 */
145 struct sensor_device_attribute_2 sysfs_attr[ABIT_UGURU3_MAX_NO_SENSORS 166 struct sensor_device_attribute_2 sysfs_attr[ABIT_UGURU3_MAX_NO_SENSORS
146 * 10]; 167 * 10];
147 168
@@ -151,9 +172,11 @@ struct abituguru3_data {
151 /* Pointer to the sensors info for the detected motherboard */ 172 /* Pointer to the sensors info for the detected motherboard */
152 const struct abituguru3_sensor_info *sensors; 173 const struct abituguru3_sensor_info *sensors;
153 174
154 /* The abituguru3 supports up to 48 sensors, and thus has registers 175 /*
155 sets for 48 sensors, for convienence reasons / simplicity of the 176 * The abituguru3 supports up to 48 sensors, and thus has registers
156 code we always read and store all registers for all 48 sensors */ 177 * sets for 48 sensors, for convienence reasons / simplicity of the
178 * code we always read and store all registers for all 48 sensors
179 */
157 180
158 /* Alarms for all 48 sensors (1 bit per sensor) */ 181 /* Alarms for all 48 sensors (1 bit per sensor) */
159 u8 alarms[48/8]; 182 u8 alarms[48/8];
@@ -161,9 +184,11 @@ struct abituguru3_data {
161 /* Value of all 48 sensors */ 184 /* Value of all 48 sensors */
162 u8 value[48]; 185 u8 value[48];
163 186
164 /* Settings of all 48 sensors, note in and temp sensors (the first 32 187 /*
165 sensors) have 3 bytes of settings, while fans only have 2 bytes, 188 * Settings of all 48 sensors, note in and temp sensors (the first 32
166 for convenience we use 3 bytes for all sensors */ 189 * sensors) have 3 bytes of settings, while fans only have 2 bytes,
190 * for convenience we use 3 bytes for all sensors
191 */
167 u8 settings[48][3]; 192 u8 settings[48][3];
168}; 193};
169 194
@@ -626,8 +651,10 @@ static int abituguru3_wait_while_busy(struct abituguru3_data *data)
626 timeout--; 651 timeout--;
627 if (timeout == 0) 652 if (timeout == 0)
628 return x; 653 return x;
629 /* sleep a bit before our last try, to give the uGuru3 one 654 /*
630 last chance to respond. */ 655 * sleep a bit before our last try, to give the uGuru3 one
656 * last chance to respond.
657 */
631 if (timeout == 1) 658 if (timeout == 1)
632 msleep(1); 659 msleep(1);
633 } 660 }
@@ -645,48 +672,57 @@ static int abituguru3_wait_for_read(struct abituguru3_data *data)
645 timeout--; 672 timeout--;
646 if (timeout == 0) 673 if (timeout == 0)
647 return x; 674 return x;
648 /* sleep a bit before our last try, to give the uGuru3 one 675 /*
649 last chance to respond. */ 676 * sleep a bit before our last try, to give the uGuru3 one
677 * last chance to respond.
678 */
650 if (timeout == 1) 679 if (timeout == 1)
651 msleep(1); 680 msleep(1);
652 } 681 }
653 return ABIT_UGURU3_SUCCESS; 682 return ABIT_UGURU3_SUCCESS;
654} 683}
655 684
656/* This synchronizes us with the uGuru3's protocol state machine, this 685/*
657 must be done before each command. */ 686 * This synchronizes us with the uGuru3's protocol state machine, this
687 * must be done before each command.
688 */
658static int abituguru3_synchronize(struct abituguru3_data *data) 689static int abituguru3_synchronize(struct abituguru3_data *data)
659{ 690{
660 int x, timeout = ABIT_UGURU3_SYNCHRONIZE_TIMEOUT; 691 int x, timeout = ABIT_UGURU3_SYNCHRONIZE_TIMEOUT;
661 692
662 if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 693 x = abituguru3_wait_while_busy(data);
694 if (x != ABIT_UGURU3_SUCCESS) {
663 ABIT_UGURU3_DEBUG("synchronize timeout during initial busy " 695 ABIT_UGURU3_DEBUG("synchronize timeout during initial busy "
664 "wait, status: 0x%02x\n", x); 696 "wait, status: 0x%02x\n", x);
665 return -EIO; 697 return -EIO;
666 } 698 }
667 699
668 outb(0x20, data->addr + ABIT_UGURU3_DATA); 700 outb(0x20, data->addr + ABIT_UGURU3_DATA);
669 if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 701 x = abituguru3_wait_while_busy(data);
702 if (x != ABIT_UGURU3_SUCCESS) {
670 ABIT_UGURU3_DEBUG("synchronize timeout after sending 0x20, " 703 ABIT_UGURU3_DEBUG("synchronize timeout after sending 0x20, "
671 "status: 0x%02x\n", x); 704 "status: 0x%02x\n", x);
672 return -EIO; 705 return -EIO;
673 } 706 }
674 707
675 outb(0x10, data->addr + ABIT_UGURU3_CMD); 708 outb(0x10, data->addr + ABIT_UGURU3_CMD);
676 if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 709 x = abituguru3_wait_while_busy(data);
710 if (x != ABIT_UGURU3_SUCCESS) {
677 ABIT_UGURU3_DEBUG("synchronize timeout after sending 0x10, " 711 ABIT_UGURU3_DEBUG("synchronize timeout after sending 0x10, "
678 "status: 0x%02x\n", x); 712 "status: 0x%02x\n", x);
679 return -EIO; 713 return -EIO;
680 } 714 }
681 715
682 outb(0x00, data->addr + ABIT_UGURU3_CMD); 716 outb(0x00, data->addr + ABIT_UGURU3_CMD);
683 if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 717 x = abituguru3_wait_while_busy(data);
718 if (x != ABIT_UGURU3_SUCCESS) {
684 ABIT_UGURU3_DEBUG("synchronize timeout after sending 0x00, " 719 ABIT_UGURU3_DEBUG("synchronize timeout after sending 0x00, "
685 "status: 0x%02x\n", x); 720 "status: 0x%02x\n", x);
686 return -EIO; 721 return -EIO;
687 } 722 }
688 723
689 if ((x = abituguru3_wait_for_read(data)) != ABIT_UGURU3_SUCCESS) { 724 x = abituguru3_wait_for_read(data);
725 if (x != ABIT_UGURU3_SUCCESS) {
690 ABIT_UGURU3_DEBUG("synchronize timeout waiting for read, " 726 ABIT_UGURU3_DEBUG("synchronize timeout waiting for read, "
691 "status: 0x%02x\n", x); 727 "status: 0x%02x\n", x);
692 return -EIO; 728 return -EIO;
@@ -705,18 +741,22 @@ static int abituguru3_synchronize(struct abituguru3_data *data)
705 return 0; 741 return 0;
706} 742}
707 743
708/* Read count bytes from sensor sensor_addr in bank bank_addr and store the 744/*
709 result in buf */ 745 * Read count bytes from sensor sensor_addr in bank bank_addr and store the
746 * result in buf
747 */
710static int abituguru3_read(struct abituguru3_data *data, u8 bank, u8 offset, 748static int abituguru3_read(struct abituguru3_data *data, u8 bank, u8 offset,
711 u8 count, u8 *buf) 749 u8 count, u8 *buf)
712{ 750{
713 int i, x; 751 int i, x;
714 752
715 if ((x = abituguru3_synchronize(data))) 753 x = abituguru3_synchronize(data);
754 if (x)
716 return x; 755 return x;
717 756
718 outb(0x1A, data->addr + ABIT_UGURU3_DATA); 757 outb(0x1A, data->addr + ABIT_UGURU3_DATA);
719 if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 758 x = abituguru3_wait_while_busy(data);
759 if (x != ABIT_UGURU3_SUCCESS) {
720 ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after " 760 ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after "
721 "sending 0x1A, status: 0x%02x\n", (unsigned int)bank, 761 "sending 0x1A, status: 0x%02x\n", (unsigned int)bank,
722 (unsigned int)offset, x); 762 (unsigned int)offset, x);
@@ -724,7 +764,8 @@ static int abituguru3_read(struct abituguru3_data *data, u8 bank, u8 offset,
724 } 764 }
725 765
726 outb(bank, data->addr + ABIT_UGURU3_CMD); 766 outb(bank, data->addr + ABIT_UGURU3_CMD);
727 if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 767 x = abituguru3_wait_while_busy(data);
768 if (x != ABIT_UGURU3_SUCCESS) {
728 ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after " 769 ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after "
729 "sending the bank, status: 0x%02x\n", 770 "sending the bank, status: 0x%02x\n",
730 (unsigned int)bank, (unsigned int)offset, x); 771 (unsigned int)bank, (unsigned int)offset, x);
@@ -732,7 +773,8 @@ static int abituguru3_read(struct abituguru3_data *data, u8 bank, u8 offset,
732 } 773 }
733 774
734 outb(offset, data->addr + ABIT_UGURU3_CMD); 775 outb(offset, data->addr + ABIT_UGURU3_CMD);
735 if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 776 x = abituguru3_wait_while_busy(data);
777 if (x != ABIT_UGURU3_SUCCESS) {
736 ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after " 778 ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after "
737 "sending the offset, status: 0x%02x\n", 779 "sending the offset, status: 0x%02x\n",
738 (unsigned int)bank, (unsigned int)offset, x); 780 (unsigned int)bank, (unsigned int)offset, x);
@@ -740,7 +782,8 @@ static int abituguru3_read(struct abituguru3_data *data, u8 bank, u8 offset,
740 } 782 }
741 783
742 outb(count, data->addr + ABIT_UGURU3_CMD); 784 outb(count, data->addr + ABIT_UGURU3_CMD);
743 if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { 785 x = abituguru3_wait_while_busy(data);
786 if (x != ABIT_UGURU3_SUCCESS) {
744 ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after " 787 ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after "
745 "sending the count, status: 0x%02x\n", 788 "sending the count, status: 0x%02x\n",
746 (unsigned int)bank, (unsigned int)offset, x); 789 (unsigned int)bank, (unsigned int)offset, x);
@@ -748,8 +791,8 @@ static int abituguru3_read(struct abituguru3_data *data, u8 bank, u8 offset,
748 } 791 }
749 792
750 for (i = 0; i < count; i++) { 793 for (i = 0; i < count; i++) {
751 if ((x = abituguru3_wait_for_read(data)) != 794 x = abituguru3_wait_for_read(data);
752 ABIT_UGURU3_SUCCESS) { 795 if (x != ABIT_UGURU3_SUCCESS) {
753 ABIT_UGURU3_DEBUG("timeout reading byte %d from " 796 ABIT_UGURU3_DEBUG("timeout reading byte %d from "
754 "0x%02x:0x%02x, status: 0x%02x\n", i, 797 "0x%02x:0x%02x, status: 0x%02x\n", i,
755 (unsigned int)bank, (unsigned int)offset, x); 798 (unsigned int)bank, (unsigned int)offset, x);
@@ -760,28 +803,34 @@ static int abituguru3_read(struct abituguru3_data *data, u8 bank, u8 offset,
760 return i; 803 return i;
761} 804}
762 805
763/* Sensor settings are stored 1 byte per offset with the bytes 806/*
764 placed add consecutive offsets. */ 807 * Sensor settings are stored 1 byte per offset with the bytes
808 * placed add consecutive offsets.
809 */
765static int abituguru3_read_increment_offset(struct abituguru3_data *data, 810static int abituguru3_read_increment_offset(struct abituguru3_data *data,
766 u8 bank, u8 offset, u8 count, 811 u8 bank, u8 offset, u8 count,
767 u8 *buf, int offset_count) 812 u8 *buf, int offset_count)
768{ 813{
769 int i, x; 814 int i, x;
770 815
771 for (i = 0; i < offset_count; i++) 816 for (i = 0; i < offset_count; i++) {
772 if ((x = abituguru3_read(data, bank, offset + i, count, 817 x = abituguru3_read(data, bank, offset + i, count,
773 buf + i * count)) != count) { 818 buf + i * count);
819 if (x != count) {
774 if (x < 0) 820 if (x < 0)
775 return x; 821 return x;
776 return i * count + x; 822 return i * count + x;
777 } 823 }
824 }
778 825
779 return i * count; 826 return i * count;
780} 827}
781 828
782/* Following are the sysfs callback functions. These functions expect: 829/*
783 sensor_device_attribute_2->index: index into the data->sensors array 830 * Following are the sysfs callback functions. These functions expect:
784 sensor_device_attribute_2->nr: register offset, bitmask or NA. */ 831 * sensor_device_attribute_2->index: index into the data->sensors array
832 * sensor_device_attribute_2->nr: register offset, bitmask or NA.
833 */
785static struct abituguru3_data *abituguru3_update_device(struct device *dev); 834static struct abituguru3_data *abituguru3_update_device(struct device *dev);
786 835
787static ssize_t show_value(struct device *dev, 836static ssize_t show_value(struct device *dev,
@@ -807,8 +856,10 @@ static ssize_t show_value(struct device *dev,
807 value = (value * sensor->multiplier) / sensor->divisor + 856 value = (value * sensor->multiplier) / sensor->divisor +
808 sensor->offset; 857 sensor->offset;
809 858
810 /* alternatively we could update the sensors settings struct for this, 859 /*
811 but then its contents would differ from the windows sw ini files */ 860 * alternatively we could update the sensors settings struct for this,
861 * but then its contents would differ from the windows sw ini files
862 */
812 if (sensor->type == ABIT_UGURU3_TEMP_SENSOR) 863 if (sensor->type == ABIT_UGURU3_TEMP_SENSOR)
813 value *= 1000; 864 value *= 1000;
814 865
@@ -827,10 +878,12 @@ static ssize_t show_alarm(struct device *dev,
827 878
828 port = data->sensors[attr->index].port; 879 port = data->sensors[attr->index].port;
829 880
830 /* See if the alarm bit for this sensor is set and if a bitmask is 881 /*
831 given in attr->nr also check if the alarm matches the type of alarm 882 * See if the alarm bit for this sensor is set and if a bitmask is
832 we're looking for (for volt it can be either low or high). The type 883 * given in attr->nr also check if the alarm matches the type of alarm
833 is stored in a few readonly bits in the settings of the sensor. */ 884 * we're looking for (for volt it can be either low or high). The type
885 * is stored in a few readonly bits in the settings of the sensor.
886 */
834 if ((data->alarms[port / 8] & (0x01 << (port % 8))) && 887 if ((data->alarms[port / 8] & (0x01 << (port % 8))) &&
835 (!attr->nr || (data->settings[port][0] & attr->nr))) 888 (!attr->nr || (data->settings[port][0] & attr->nr)))
836 return sprintf(buf, "1\n"); 889 return sprintf(buf, "1\n");
@@ -923,7 +976,8 @@ static int __devinit abituguru3_probe(struct platform_device *pdev)
923 u8 buf[2]; 976 u8 buf[2];
924 u16 id; 977 u16 id;
925 978
926 if (!(data = kzalloc(sizeof(struct abituguru3_data), GFP_KERNEL))) 979 data = kzalloc(sizeof(struct abituguru3_data), GFP_KERNEL);
980 if (!data)
927 return -ENOMEM; 981 return -ENOMEM;
928 982
929 data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start; 983 data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start;
@@ -931,10 +985,10 @@ static int __devinit abituguru3_probe(struct platform_device *pdev)
931 platform_set_drvdata(pdev, data); 985 platform_set_drvdata(pdev, data);
932 986
933 /* Read the motherboard ID */ 987 /* Read the motherboard ID */
934 if ((i = abituguru3_read(data, ABIT_UGURU3_MISC_BANK, 988 i = abituguru3_read(data, ABIT_UGURU3_MISC_BANK, ABIT_UGURU3_BOARD_ID,
935 ABIT_UGURU3_BOARD_ID, 2, buf)) != 2) { 989 2, buf);
990 if (i != 2)
936 goto abituguru3_probe_error; 991 goto abituguru3_probe_error;
937 }
938 992
939 /* Completely read the uGuru to see if one really is there */ 993 /* Completely read the uGuru to see if one really is there */
940 if (!abituguru3_update_device(&pdev->dev)) 994 if (!abituguru3_update_device(&pdev->dev))
@@ -1091,8 +1145,10 @@ LEAVE_UPDATE:
1091static int abituguru3_suspend(struct platform_device *pdev, pm_message_t state) 1145static int abituguru3_suspend(struct platform_device *pdev, pm_message_t state)
1092{ 1146{
1093 struct abituguru3_data *data = platform_get_drvdata(pdev); 1147 struct abituguru3_data *data = platform_get_drvdata(pdev);
1094 /* make sure all communications with the uguru3 are done and no new 1148 /*
1095 ones are started */ 1149 * make sure all communications with the uguru3 are done and no new
1150 * ones are started
1151 */
1096 mutex_lock(&data->update_lock); 1152 mutex_lock(&data->update_lock);
1097 return 0; 1153 return 0;
1098} 1154}
@@ -1134,7 +1190,8 @@ static int __init abituguru3_dmi_detect(void)
1134 if (!board_name) 1190 if (!board_name)
1135 return err; 1191 return err;
1136 1192
1137 /* At the moment, we don't care about the part of the vendor 1193 /*
1194 * At the moment, we don't care about the part of the vendor
1138 * DMI string contained in brackets. Truncate the string at 1195 * DMI string contained in brackets. Truncate the string at
1139 * the first occurrence of a bracket. Trim any trailing space 1196 * the first occurrence of a bracket. Trim any trailing space
1140 * from the substring. 1197 * from the substring.
@@ -1157,15 +1214,18 @@ static int __init abituguru3_dmi_detect(void)
1157 return 1; 1214 return 1;
1158} 1215}
1159 1216
1160/* FIXME: Manual detection should die eventually; we need to collect stable 1217/*
1218 * FIXME: Manual detection should die eventually; we need to collect stable
1161 * DMI model names first before we can rely entirely on CONFIG_DMI. 1219 * DMI model names first before we can rely entirely on CONFIG_DMI.
1162 */ 1220 */
1163 1221
1164static int __init abituguru3_detect(void) 1222static int __init abituguru3_detect(void)
1165{ 1223{
1166 /* See if there is an uguru3 there. An idle uGuru3 will hold 0x00 or 1224 /*
1167 0x08 at DATA and 0xAC at CMD. Sometimes the uGuru3 will hold 0x05 1225 * See if there is an uguru3 there. An idle uGuru3 will hold 0x00 or
1168 or 0x55 at CMD instead, why is unknown. */ 1226 * 0x08 at DATA and 0xAC at CMD. Sometimes the uGuru3 will hold 0x05
1227 * or 0x55 at CMD instead, why is unknown.
1228 */
1169 u8 data_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_DATA); 1229 u8 data_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_DATA);
1170 u8 cmd_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_CMD); 1230 u8 cmd_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_CMD);
1171 if (((data_val == 0x00) || (data_val == 0x08)) && 1231 if (((data_val == 0x00) || (data_val == 0x08)) &&
@@ -1197,7 +1257,8 @@ static int __init abituguru3_init(void)
1197 if (err < 0) 1257 if (err < 0)
1198 return err; 1258 return err;
1199 1259
1200 /* Fall back to manual detection if there was no exact 1260 /*
1261 * Fall back to manual detection if there was no exact
1201 * board name match, or force was specified. 1262 * board name match, or force was specified.
1202 */ 1263 */
1203 if (err > 0) { 1264 if (err > 0) {
diff --git a/drivers/hwmon/ad7314.c b/drivers/hwmon/ad7314.c
index 5d760f3d21c2..0e0cfcc36f8d 100644
--- a/drivers/hwmon/ad7314.c
+++ b/drivers/hwmon/ad7314.c
@@ -167,17 +167,7 @@ static struct spi_driver ad7314_driver = {
167 .id_table = ad7314_id, 167 .id_table = ad7314_id,
168}; 168};
169 169
170static __init int ad7314_init(void) 170module_spi_driver(ad7314_driver);
171{
172 return spi_register_driver(&ad7314_driver);
173}
174module_init(ad7314_init);
175
176static __exit void ad7314_exit(void)
177{
178 spi_unregister_driver(&ad7314_driver);
179}
180module_exit(ad7314_exit);
181 171
182MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>"); 172MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
183MODULE_DESCRIPTION("Analog Devices AD7314, ADT7301 and ADT7302 digital" 173MODULE_DESCRIPTION("Analog Devices AD7314, ADT7301 and ADT7302 digital"
diff --git a/drivers/hwmon/ad7414.c b/drivers/hwmon/ad7414.c
index df29a7fff9e7..06d2d60d1fd0 100644
--- a/drivers/hwmon/ad7414.c
+++ b/drivers/hwmon/ad7414.c
@@ -50,7 +50,8 @@ struct ad7414_data {
50/* REG: (0.25C/bit, two's complement) << 6 */ 50/* REG: (0.25C/bit, two's complement) << 6 */
51static inline int ad7414_temp_from_reg(s16 reg) 51static inline int ad7414_temp_from_reg(s16 reg)
52{ 52{
53 /* use integer division instead of equivalent right shift to 53 /*
54 * use integer division instead of equivalent right shift to
54 * guarantee arithmetic shift and preserve the sign 55 * guarantee arithmetic shift and preserve the sign
55 */ 56 */
56 return ((int)reg / 64) * 250; 57 return ((int)reg / 64) * 250;
@@ -130,7 +131,11 @@ static ssize_t set_max_min(struct device *dev,
130 struct ad7414_data *data = i2c_get_clientdata(client); 131 struct ad7414_data *data = i2c_get_clientdata(client);
131 int index = to_sensor_dev_attr(attr)->index; 132 int index = to_sensor_dev_attr(attr)->index;
132 u8 reg = AD7414_REG_LIMIT[index]; 133 u8 reg = AD7414_REG_LIMIT[index];
133 long temp = simple_strtol(buf, NULL, 10); 134 long temp;
135 int ret = kstrtol(buf, 10, &temp);
136
137 if (ret < 0)
138 return ret;
134 139
135 temp = SENSORS_LIMIT(temp, -40000, 85000); 140 temp = SENSORS_LIMIT(temp, -40000, 85000);
136 temp = (temp + (temp < 0 ? -500 : 500)) / 1000; 141 temp = (temp + (temp < 0 ? -500 : 500)) / 1000;
@@ -252,17 +257,7 @@ static struct i2c_driver ad7414_driver = {
252 .id_table = ad7414_id, 257 .id_table = ad7414_id,
253}; 258};
254 259
255static int __init ad7414_init(void) 260module_i2c_driver(ad7414_driver);
256{
257 return i2c_add_driver(&ad7414_driver);
258}
259module_init(ad7414_init);
260
261static void __exit ad7414_exit(void)
262{
263 i2c_del_driver(&ad7414_driver);
264}
265module_exit(ad7414_exit);
266 261
267MODULE_AUTHOR("Stefan Roese <sr at denx.de>, " 262MODULE_AUTHOR("Stefan Roese <sr at denx.de>, "
268 "Frank Edelhaeuser <frank.edelhaeuser at spansion.com>"); 263 "Frank Edelhaeuser <frank.edelhaeuser at spansion.com>");
diff --git a/drivers/hwmon/ad7418.c b/drivers/hwmon/ad7418.c
index 8cb718ce8237..a50a6bef16c4 100644
--- a/drivers/hwmon/ad7418.c
+++ b/drivers/hwmon/ad7418.c
@@ -167,7 +167,11 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *devattr,
167 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 167 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
168 struct i2c_client *client = to_i2c_client(dev); 168 struct i2c_client *client = to_i2c_client(dev);
169 struct ad7418_data *data = i2c_get_clientdata(client); 169 struct ad7418_data *data = i2c_get_clientdata(client);
170 long temp = simple_strtol(buf, NULL, 10); 170 long temp;
171 int ret = kstrtol(buf, 10, &temp);
172
173 if (ret < 0)
174 return ret;
171 175
172 mutex_lock(&data->lock); 176 mutex_lock(&data->lock);
173 data->temp[attr->index] = LM75_TEMP_TO_REG(temp); 177 data->temp[attr->index] = LM75_TEMP_TO_REG(temp);
@@ -228,7 +232,8 @@ static int ad7418_probe(struct i2c_client *client,
228 goto exit; 232 goto exit;
229 } 233 }
230 234
231 if (!(data = kzalloc(sizeof(struct ad7418_data), GFP_KERNEL))) { 235 data = kzalloc(sizeof(struct ad7418_data), GFP_KERNEL);
236 if (!data) {
232 err = -ENOMEM; 237 err = -ENOMEM;
233 goto exit; 238 goto exit;
234 } 239 }
@@ -261,7 +266,8 @@ static int ad7418_probe(struct i2c_client *client,
261 ad7418_init_client(client); 266 ad7418_init_client(client);
262 267
263 /* Register sysfs hooks */ 268 /* Register sysfs hooks */
264 if ((err = sysfs_create_group(&client->dev.kobj, &data->attrs))) 269 err = sysfs_create_group(&client->dev.kobj, &data->attrs);
270 if (err)
265 goto exit_free; 271 goto exit_free;
266 272
267 data->hwmon_dev = hwmon_device_register(&client->dev); 273 data->hwmon_dev = hwmon_device_register(&client->dev);
@@ -289,20 +295,9 @@ static int ad7418_remove(struct i2c_client *client)
289 return 0; 295 return 0;
290} 296}
291 297
292static int __init ad7418_init(void) 298module_i2c_driver(ad7418_driver);
293{
294 return i2c_add_driver(&ad7418_driver);
295}
296
297static void __exit ad7418_exit(void)
298{
299 i2c_del_driver(&ad7418_driver);
300}
301 299
302MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>"); 300MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
303MODULE_DESCRIPTION("AD7416/17/18 driver"); 301MODULE_DESCRIPTION("AD7416/17/18 driver");
304MODULE_LICENSE("GPL"); 302MODULE_LICENSE("GPL");
305MODULE_VERSION(DRV_VERSION); 303MODULE_VERSION(DRV_VERSION);
306
307module_init(ad7418_init);
308module_exit(ad7418_exit);
diff --git a/drivers/hwmon/adcxx.c b/drivers/hwmon/adcxx.c
index ceb24a365176..a3d3183454ad 100644
--- a/drivers/hwmon/adcxx.c
+++ b/drivers/hwmon/adcxx.c
@@ -248,18 +248,7 @@ static struct spi_driver adcxx_driver = {
248 .remove = __devexit_p(adcxx_remove), 248 .remove = __devexit_p(adcxx_remove),
249}; 249};
250 250
251static int __init init_adcxx(void) 251module_spi_driver(adcxx_driver);
252{
253 return spi_register_driver(&adcxx_driver);
254}
255
256static void __exit exit_adcxx(void)
257{
258 spi_unregister_driver(&adcxx_driver);
259}
260
261module_init(init_adcxx);
262module_exit(exit_adcxx);
263 252
264MODULE_AUTHOR("Marc Pignat"); 253MODULE_AUTHOR("Marc Pignat");
265MODULE_DESCRIPTION("National Semiconductor adcxx8sxxx Linux driver"); 254MODULE_DESCRIPTION("National Semiconductor adcxx8sxxx Linux driver");
diff --git a/drivers/hwmon/adm1021.c b/drivers/hwmon/adm1021.c
index 0158cc35cb2e..4394e7e99c46 100644
--- a/drivers/hwmon/adm1021.c
+++ b/drivers/hwmon/adm1021.c
@@ -1,23 +1,23 @@
1/* 1/*
2 adm1021.c - Part of lm_sensors, Linux kernel modules for hardware 2 * adm1021.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 * monitoring
4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> and 4 * Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> and
5 Philip Edelbrock <phil@netroedge.com> 5 * Philip Edelbrock <phil@netroedge.com>
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
9 the Free Software Foundation; either version 2 of the License, or 9 * the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 10 * (at your option) any later version.
11 11 *
12 This program is distributed in the hope that it will be useful, 12 * This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 15 * GNU General Public License for more details.
16 16 *
17 You should have received a copy of the GNU General Public License 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 18 * along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/ 20 */
21 21
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/init.h> 23#include <linux/init.h>
@@ -70,10 +70,12 @@ enum chips {
70 70
71/* Initial values */ 71/* Initial values */
72 72
73/* Note: Even though I left the low and high limits named os and hyst, 73/*
74they don't quite work like a thermostat the way the LM75 does. I.e., 74 * Note: Even though I left the low and high limits named os and hyst,
75a lower temp than THYST actually triggers an alarm instead of 75 * they don't quite work like a thermostat the way the LM75 does. I.e.,
76clearing it. Weird, ey? --Phil */ 76 * a lower temp than THYST actually triggers an alarm instead of
77 * clearing it. Weird, ey? --Phil
78 */
77 79
78/* Each client has this additional data */ 80/* Each client has this additional data */
79struct adm1021_data { 81struct adm1021_data {
@@ -182,7 +184,13 @@ static ssize_t set_temp_max(struct device *dev,
182 int index = to_sensor_dev_attr(devattr)->index; 184 int index = to_sensor_dev_attr(devattr)->index;
183 struct i2c_client *client = to_i2c_client(dev); 185 struct i2c_client *client = to_i2c_client(dev);
184 struct adm1021_data *data = i2c_get_clientdata(client); 186 struct adm1021_data *data = i2c_get_clientdata(client);
185 long temp = simple_strtol(buf, NULL, 10) / 1000; 187 long temp;
188 int err;
189
190 err = kstrtol(buf, 10, &temp);
191 if (err)
192 return err;
193 temp /= 1000;
186 194
187 mutex_lock(&data->update_lock); 195 mutex_lock(&data->update_lock);
188 data->temp_max[index] = SENSORS_LIMIT(temp, -128, 127); 196 data->temp_max[index] = SENSORS_LIMIT(temp, -128, 127);
@@ -201,7 +209,13 @@ static ssize_t set_temp_min(struct device *dev,
201 int index = to_sensor_dev_attr(devattr)->index; 209 int index = to_sensor_dev_attr(devattr)->index;
202 struct i2c_client *client = to_i2c_client(dev); 210 struct i2c_client *client = to_i2c_client(dev);
203 struct adm1021_data *data = i2c_get_clientdata(client); 211 struct adm1021_data *data = i2c_get_clientdata(client);
204 long temp = simple_strtol(buf, NULL, 10) / 1000; 212 long temp;
213 int err;
214
215 err = kstrtol(buf, 10, &temp);
216 if (err)
217 return err;
218 temp /= 1000;
205 219
206 mutex_lock(&data->update_lock); 220 mutex_lock(&data->update_lock);
207 data->temp_min[index] = SENSORS_LIMIT(temp, -128, 127); 221 data->temp_min[index] = SENSORS_LIMIT(temp, -128, 127);
@@ -226,7 +240,14 @@ static ssize_t set_low_power(struct device *dev,
226{ 240{
227 struct i2c_client *client = to_i2c_client(dev); 241 struct i2c_client *client = to_i2c_client(dev);
228 struct adm1021_data *data = i2c_get_clientdata(client); 242 struct adm1021_data *data = i2c_get_clientdata(client);
229 int low_power = simple_strtol(buf, NULL, 10) != 0; 243 char low_power;
244 unsigned long val;
245 int err;
246
247 err = kstrtoul(buf, 10, &val);
248 if (err)
249 return err;
250 low_power = val != 0;
230 251
231 mutex_lock(&data->update_lock); 252 mutex_lock(&data->update_lock);
232 if (low_power != data->low_power) { 253 if (low_power != data->low_power) {
@@ -361,7 +382,8 @@ static int adm1021_probe(struct i2c_client *client,
361 adm1021_init_client(client); 382 adm1021_init_client(client);
362 383
363 /* Register sysfs hooks */ 384 /* Register sysfs hooks */
364 if ((err = sysfs_create_group(&client->dev.kobj, &adm1021_group))) 385 err = sysfs_create_group(&client->dev.kobj, &adm1021_group);
386 if (err)
365 goto error1; 387 goto error1;
366 388
367 data->hwmon_dev = hwmon_device_register(&client->dev); 389 data->hwmon_dev = hwmon_device_register(&client->dev);
@@ -427,8 +449,10 @@ static struct adm1021_data *adm1021_update_device(struct device *dev)
427 data->alarms = i2c_smbus_read_byte_data(client, 449 data->alarms = i2c_smbus_read_byte_data(client,
428 ADM1021_REG_STATUS) & 0x7c; 450 ADM1021_REG_STATUS) & 0x7c;
429 if (data->type == adm1023) { 451 if (data->type == adm1023) {
430 /* The ADM1023 provides 3 extra bits of precision for 452 /*
431 * the remote sensor in extra registers. */ 453 * The ADM1023 provides 3 extra bits of precision for
454 * the remote sensor in extra registers.
455 */
432 data->temp[1] += 125 * (i2c_smbus_read_byte_data( 456 data->temp[1] += 125 * (i2c_smbus_read_byte_data(
433 client, ADM1023_REG_REM_TEMP_PREC) >> 5); 457 client, ADM1023_REG_REM_TEMP_PREC) >> 5);
434 data->temp_max[1] += 125 * (i2c_smbus_read_byte_data( 458 data->temp_max[1] += 125 * (i2c_smbus_read_byte_data(
@@ -451,23 +475,12 @@ static struct adm1021_data *adm1021_update_device(struct device *dev)
451 return data; 475 return data;
452} 476}
453 477
454static int __init sensors_adm1021_init(void) 478module_i2c_driver(adm1021_driver);
455{
456 return i2c_add_driver(&adm1021_driver);
457}
458
459static void __exit sensors_adm1021_exit(void)
460{
461 i2c_del_driver(&adm1021_driver);
462}
463 479
464MODULE_AUTHOR ("Frodo Looijaard <frodol@dds.nl> and " 480MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and "
465 "Philip Edelbrock <phil@netroedge.com>"); 481 "Philip Edelbrock <phil@netroedge.com>");
466MODULE_DESCRIPTION("adm1021 driver"); 482MODULE_DESCRIPTION("adm1021 driver");
467MODULE_LICENSE("GPL"); 483MODULE_LICENSE("GPL");
468 484
469module_param(read_only, bool, 0); 485module_param(read_only, bool, 0);
470MODULE_PARM_DESC(read_only, "Don't set any values, read only mode"); 486MODULE_PARM_DESC(read_only, "Don't set any values, read only mode");
471
472module_init(sensors_adm1021_init)
473module_exit(sensors_adm1021_exit)
diff --git a/drivers/hwmon/adm1025.c b/drivers/hwmon/adm1025.c
index 60befc0ee65f..b8557f9857d2 100644
--- a/drivers/hwmon/adm1025.c
+++ b/drivers/hwmon/adm1025.c
@@ -12,7 +12,7 @@
12 * resolution of about 0.5% of the nominal value). Temperature values are 12 * resolution of about 0.5% of the nominal value). Temperature values are
13 * reported with a 1 deg resolution and a 3 deg accuracy. Complete 13 * reported with a 1 deg resolution and a 3 deg accuracy. Complete
14 * datasheet can be obtained from Analog's website at: 14 * datasheet can be obtained from Analog's website at:
15 * http://www.onsemi.com/PowerSolutions/product.do?id=ADM1025 15 * http://www.onsemi.com/PowerSolutions/product.do?id=ADM1025
16 * 16 *
17 * This driver also supports the ADM1025A, which differs from the ADM1025 17 * This driver also supports the ADM1025A, which differs from the ADM1025
18 * only in that it has "open-drain VID inputs while the ADM1025 has 18 * only in that it has "open-drain VID inputs while the ADM1025 has
@@ -91,15 +91,16 @@ enum chips { adm1025, ne1619 };
91 91
92static const int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 }; 92static const int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 };
93 93
94#define IN_FROM_REG(reg,scale) (((reg) * (scale) + 96) / 192) 94#define IN_FROM_REG(reg, scale) (((reg) * (scale) + 96) / 192)
95#define IN_TO_REG(val,scale) ((val) <= 0 ? 0 : \ 95#define IN_TO_REG(val, scale) ((val) <= 0 ? 0 : \
96 (val) * 192 >= (scale) * 255 ? 255 : \ 96 (val) * 192 >= (scale) * 255 ? 255 : \
97 ((val) * 192 + (scale)/2) / (scale)) 97 ((val) * 192 + (scale) / 2) / (scale))
98 98
99#define TEMP_FROM_REG(reg) ((reg) * 1000) 99#define TEMP_FROM_REG(reg) ((reg) * 1000)
100#define TEMP_TO_REG(val) ((val) <= -127500 ? -128 : \ 100#define TEMP_TO_REG(val) ((val) <= -127500 ? -128 : \
101 (val) >= 126500 ? 127 : \ 101 (val) >= 126500 ? 127 : \
102 (((val) < 0 ? (val)-500 : (val)+500) / 1000)) 102 (((val) < 0 ? (val) - 500 : \
103 (val) + 500) / 1000))
103 104
104/* 105/*
105 * Functions declaration 106 * Functions declaration
@@ -218,7 +219,12 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
218 int index = to_sensor_dev_attr(attr)->index; 219 int index = to_sensor_dev_attr(attr)->index;
219 struct i2c_client *client = to_i2c_client(dev); 220 struct i2c_client *client = to_i2c_client(dev);
220 struct adm1025_data *data = i2c_get_clientdata(client); 221 struct adm1025_data *data = i2c_get_clientdata(client);
221 long val = simple_strtol(buf, NULL, 10); 222 long val;
223 int err;
224
225 err = kstrtol(buf, 10, &val);
226 if (err)
227 return err;
222 228
223 mutex_lock(&data->update_lock); 229 mutex_lock(&data->update_lock);
224 data->in_min[index] = IN_TO_REG(val, in_scale[index]); 230 data->in_min[index] = IN_TO_REG(val, in_scale[index]);
@@ -234,7 +240,12 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
234 int index = to_sensor_dev_attr(attr)->index; 240 int index = to_sensor_dev_attr(attr)->index;
235 struct i2c_client *client = to_i2c_client(dev); 241 struct i2c_client *client = to_i2c_client(dev);
236 struct adm1025_data *data = i2c_get_clientdata(client); 242 struct adm1025_data *data = i2c_get_clientdata(client);
237 long val = simple_strtol(buf, NULL, 10); 243 long val;
244 int err;
245
246 err = kstrtol(buf, 10, &val);
247 if (err)
248 return err;
238 249
239 mutex_lock(&data->update_lock); 250 mutex_lock(&data->update_lock);
240 data->in_max[index] = IN_TO_REG(val, in_scale[index]); 251 data->in_max[index] = IN_TO_REG(val, in_scale[index]);
@@ -264,7 +275,12 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
264 int index = to_sensor_dev_attr(attr)->index; 275 int index = to_sensor_dev_attr(attr)->index;
265 struct i2c_client *client = to_i2c_client(dev); 276 struct i2c_client *client = to_i2c_client(dev);
266 struct adm1025_data *data = i2c_get_clientdata(client); 277 struct adm1025_data *data = i2c_get_clientdata(client);
267 long val = simple_strtol(buf, NULL, 10); 278 long val;
279 int err;
280
281 err = kstrtol(buf, 10, &val);
282 if (err)
283 return err;
268 284
269 mutex_lock(&data->update_lock); 285 mutex_lock(&data->update_lock);
270 data->temp_min[index] = TEMP_TO_REG(val); 286 data->temp_min[index] = TEMP_TO_REG(val);
@@ -280,7 +296,12 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
280 int index = to_sensor_dev_attr(attr)->index; 296 int index = to_sensor_dev_attr(attr)->index;
281 struct i2c_client *client = to_i2c_client(dev); 297 struct i2c_client *client = to_i2c_client(dev);
282 struct adm1025_data *data = i2c_get_clientdata(client); 298 struct adm1025_data *data = i2c_get_clientdata(client);
283 long val = simple_strtol(buf, NULL, 10); 299 long val;
300 int err;
301
302 err = kstrtol(buf, 10, &val);
303 if (err)
304 return err;
284 305
285 mutex_lock(&data->update_lock); 306 mutex_lock(&data->update_lock);
286 data->temp_max[index] = TEMP_TO_REG(val); 307 data->temp_max[index] = TEMP_TO_REG(val);
@@ -343,7 +364,14 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
343 const char *buf, size_t count) 364 const char *buf, size_t count)
344{ 365{
345 struct adm1025_data *data = dev_get_drvdata(dev); 366 struct adm1025_data *data = dev_get_drvdata(dev);
346 data->vrm = simple_strtoul(buf, NULL, 10); 367 unsigned long val;
368 int err;
369
370 err = kstrtoul(buf, 10, &val);
371 if (err)
372 return err;
373
374 data->vrm = val;
347 return count; 375 return count;
348} 376}
349static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); 377static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
@@ -462,14 +490,15 @@ static int adm1025_probe(struct i2c_client *client,
462 adm1025_init_client(client); 490 adm1025_init_client(client);
463 491
464 /* Register sysfs hooks */ 492 /* Register sysfs hooks */
465 if ((err = sysfs_create_group(&client->dev.kobj, &adm1025_group))) 493 err = sysfs_create_group(&client->dev.kobj, &adm1025_group);
494 if (err)
466 goto exit_free; 495 goto exit_free;
467 496
468 /* Pin 11 is either in4 (+12V) or VID4 */ 497 /* Pin 11 is either in4 (+12V) or VID4 */
469 config = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG); 498 config = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG);
470 if (!(config & 0x20)) { 499 if (!(config & 0x20)) {
471 if ((err = sysfs_create_group(&client->dev.kobj, 500 err = sysfs_create_group(&client->dev.kobj, &adm1025_group_in4);
472 &adm1025_group_in4))) 501 if (err)
473 goto exit_remove; 502 goto exit_remove;
474 } 503 }
475 504
@@ -506,7 +535,7 @@ static void adm1025_init_client(struct i2c_client *client)
506 * setting yet, we better set the high limits to the max so that 535 * setting yet, we better set the high limits to the max so that
507 * no alarm triggers. 536 * no alarm triggers.
508 */ 537 */
509 for (i=0; i<6; i++) { 538 for (i = 0; i < 6; i++) {
510 reg = i2c_smbus_read_byte_data(client, 539 reg = i2c_smbus_read_byte_data(client,
511 ADM1025_REG_IN_MAX(i)); 540 ADM1025_REG_IN_MAX(i));
512 if (reg == 0) 541 if (reg == 0)
@@ -514,7 +543,7 @@ static void adm1025_init_client(struct i2c_client *client)
514 ADM1025_REG_IN_MAX(i), 543 ADM1025_REG_IN_MAX(i),
515 0xFF); 544 0xFF);
516 } 545 }
517 for (i=0; i<2; i++) { 546 for (i = 0; i < 2; i++) {
518 reg = i2c_smbus_read_byte_data(client, 547 reg = i2c_smbus_read_byte_data(client,
519 ADM1025_REG_TEMP_HIGH(i)); 548 ADM1025_REG_TEMP_HIGH(i));
520 if (reg == 0) 549 if (reg == 0)
@@ -555,7 +584,7 @@ static struct adm1025_data *adm1025_update_device(struct device *dev)
555 int i; 584 int i;
556 585
557 dev_dbg(&client->dev, "Updating data.\n"); 586 dev_dbg(&client->dev, "Updating data.\n");
558 for (i=0; i<6; i++) { 587 for (i = 0; i < 6; i++) {
559 data->in[i] = i2c_smbus_read_byte_data(client, 588 data->in[i] = i2c_smbus_read_byte_data(client,
560 ADM1025_REG_IN(i)); 589 ADM1025_REG_IN(i));
561 data->in_min[i] = i2c_smbus_read_byte_data(client, 590 data->in_min[i] = i2c_smbus_read_byte_data(client,
@@ -563,7 +592,7 @@ static struct adm1025_data *adm1025_update_device(struct device *dev)
563 data->in_max[i] = i2c_smbus_read_byte_data(client, 592 data->in_max[i] = i2c_smbus_read_byte_data(client,
564 ADM1025_REG_IN_MAX(i)); 593 ADM1025_REG_IN_MAX(i));
565 } 594 }
566 for (i=0; i<2; i++) { 595 for (i = 0; i < 2; i++) {
567 data->temp[i] = i2c_smbus_read_byte_data(client, 596 data->temp[i] = i2c_smbus_read_byte_data(client,
568 ADM1025_REG_TEMP(i)); 597 ADM1025_REG_TEMP(i));
569 data->temp_min[i] = i2c_smbus_read_byte_data(client, 598 data->temp_min[i] = i2c_smbus_read_byte_data(client,
@@ -589,19 +618,8 @@ static struct adm1025_data *adm1025_update_device(struct device *dev)
589 return data; 618 return data;
590} 619}
591 620
592static int __init sensors_adm1025_init(void) 621module_i2c_driver(adm1025_driver);
593{
594 return i2c_add_driver(&adm1025_driver);
595}
596
597static void __exit sensors_adm1025_exit(void)
598{
599 i2c_del_driver(&adm1025_driver);
600}
601 622
602MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); 623MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
603MODULE_DESCRIPTION("ADM1025 driver"); 624MODULE_DESCRIPTION("ADM1025 driver");
604MODULE_LICENSE("GPL"); 625MODULE_LICENSE("GPL");
605
606module_init(sensors_adm1025_init);
607module_exit(sensors_adm1025_exit);
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c
index 0531867484f4..1003219b9f90 100644
--- a/drivers/hwmon/adm1026.c
+++ b/drivers/hwmon/adm1026.c
@@ -1,27 +1,27 @@
1/* 1/*
2 adm1026.c - Part of lm_sensors, Linux kernel modules for hardware 2 * adm1026.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 * monitoring
4 Copyright (C) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com> 4 * Copyright (C) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
5 Copyright (C) 2004 Justin Thiessen <jthiessen@penguincomputing.com> 5 * Copyright (C) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
6 6 *
7 Chip details at: 7 * Chip details at:
8 8 *
9 <http://www.onsemi.com/PowerSolutions/product.do?id=ADM1026> 9 * <http://www.onsemi.com/PowerSolutions/product.do?id=ADM1026>
10 10 *
11 This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by 12 * it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or 13 * the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version. 14 * (at your option) any later version.
15 15 *
16 This program is distributed in the hope that it will be useful, 16 * This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details. 19 * GNU General Public License for more details.
20 20 *
21 You should have received a copy of the GNU General Public License 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 22 * along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24*/ 24 */
25 25
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/init.h> 27#include <linux/init.h>
@@ -90,7 +90,8 @@ MODULE_PARM_DESC(gpio_fan, "List of GPIO pins (0-7) to program as fan tachs");
90#define E2CFG_ROM 0x08 90#define E2CFG_ROM 0x08
91#define E2CFG_CLK_EXT 0x80 91#define E2CFG_CLK_EXT 0x80
92 92
93/* There are 10 general analog inputs and 7 dedicated inputs 93/*
94 * There are 10 general analog inputs and 7 dedicated inputs
94 * They are: 95 * They are:
95 * 0 - 9 = AIN0 - AIN9 96 * 0 - 9 = AIN0 - AIN9
96 * 10 = Vbat 97 * 10 = Vbat
@@ -117,7 +118,8 @@ static u16 ADM1026_REG_IN_MAX[] = {
117 0x43, 0x44, 0x45, 0x46, 0x47 118 0x43, 0x44, 0x45, 0x46, 0x47
118 }; 119 };
119 120
120/* Temperatures are: 121/*
122 * Temperatures are:
121 * 0 - Internal 123 * 0 - Internal
122 * 1 - External 1 124 * 1 - External 1
123 * 2 - External 2 125 * 2 - External 2
@@ -170,12 +172,14 @@ static u16 ADM1026_REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f };
170#define ADM1026_FAN_CONTROL_TEMP_RANGE 20 172#define ADM1026_FAN_CONTROL_TEMP_RANGE 20
171#define ADM1026_PWM_MAX 255 173#define ADM1026_PWM_MAX 255
172 174
173/* Conversions. Rounding and limit checking is only done on the TO_REG 175/*
176 * Conversions. Rounding and limit checking is only done on the TO_REG
174 * variants. Note that you should be a bit careful with which arguments 177 * variants. Note that you should be a bit careful with which arguments
175 * these macros are called: arguments may be evaluated more than once. 178 * these macros are called: arguments may be evaluated more than once.
176 */ 179 */
177 180
178/* IN are scaled according to built-in resistors. These are the 181/*
182 * IN are scaled according to built-in resistors. These are the
179 * voltages corresponding to 3/4 of full scale (192 or 0xc0) 183 * voltages corresponding to 3/4 of full scale (192 or 0xc0)
180 * NOTE: The -12V input needs an additional factor to account 184 * NOTE: The -12V input needs an additional factor to account
181 * for the Vref pullup resistor. 185 * for the Vref pullup resistor.
@@ -197,23 +201,25 @@ static int adm1026_scaling[] = { /* .001 Volts */
197 0, 255)) 201 0, 255))
198#define INS_FROM_REG(n, val) (SCALE(val, 192, adm1026_scaling[n])) 202#define INS_FROM_REG(n, val) (SCALE(val, 192, adm1026_scaling[n]))
199 203
200/* FAN speed is measured using 22.5kHz clock and counts for 2 pulses 204/*
205 * FAN speed is measured using 22.5kHz clock and counts for 2 pulses
201 * and we assume a 2 pulse-per-rev fan tach signal 206 * and we assume a 2 pulse-per-rev fan tach signal
202 * 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000 207 * 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000
203 */ 208 */
204#define FAN_TO_REG(val, div) ((val) <= 0 ? 0xff : \ 209#define FAN_TO_REG(val, div) ((val) <= 0 ? 0xff : \
205 SENSORS_LIMIT(1350000/((val)*(div)), 1, 254)) 210 SENSORS_LIMIT(1350000 / ((val) * (div)), \
206#define FAN_FROM_REG(val, div) ((val) == 0 ? -1:(val) == 0xff ? 0 : \ 211 1, 254))
207 1350000/((val)*(div))) 212#define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 0xff ? 0 : \
208#define DIV_FROM_REG(val) (1<<(val)) 213 1350000 / ((val) * (div)))
214#define DIV_FROM_REG(val) (1 << (val))
209#define DIV_TO_REG(val) ((val) >= 8 ? 3 : (val) >= 4 ? 2 : (val) >= 2 ? 1 : 0) 215#define DIV_TO_REG(val) ((val) >= 8 ? 3 : (val) >= 4 ? 2 : (val) >= 2 ? 1 : 0)
210 216
211/* Temperature is reported in 1 degC increments */ 217/* Temperature is reported in 1 degC increments */
212#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\ 218#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) + ((val) < 0 ? -500 : 500)) \
213 -127, 127)) 219 / 1000, -127, 127))
214#define TEMP_FROM_REG(val) ((val) * 1000) 220#define TEMP_FROM_REG(val) ((val) * 1000)
215#define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\ 221#define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val) + ((val) < 0 ? -500 : 500)) \
216 -127, 127)) 222 / 1000, -127, 127))
217#define OFFSET_FROM_REG(val) ((val) * 1000) 223#define OFFSET_FROM_REG(val) ((val) * 1000)
218 224
219#define PWM_TO_REG(val) (SENSORS_LIMIT(val, 0, 255)) 225#define PWM_TO_REG(val) (SENSORS_LIMIT(val, 0, 255))
@@ -222,14 +228,16 @@ static int adm1026_scaling[] = { /* .001 Volts */
222#define PWM_MIN_TO_REG(val) ((val) & 0xf0) 228#define PWM_MIN_TO_REG(val) ((val) & 0xf0)
223#define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4)) 229#define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4))
224 230
225/* Analog output is a voltage, and scaled to millivolts. The datasheet 231/*
232 * Analog output is a voltage, and scaled to millivolts. The datasheet
226 * indicates that the DAC could be used to drive the fans, but in our 233 * indicates that the DAC could be used to drive the fans, but in our
227 * example board (Arima HDAMA) it isn't connected to the fans at all. 234 * example board (Arima HDAMA) it isn't connected to the fans at all.
228 */ 235 */
229#define DAC_TO_REG(val) (SENSORS_LIMIT(((((val)*255)+500)/2500), 0, 255)) 236#define DAC_TO_REG(val) (SENSORS_LIMIT(((((val) * 255) + 500) / 2500), 0, 255))
230#define DAC_FROM_REG(val) (((val)*2500)/255) 237#define DAC_FROM_REG(val) (((val) * 2500) / 255)
231 238
232/* Chip sampling rates 239/*
240 * Chip sampling rates
233 * 241 *
234 * Some sensors are not updated more frequently than once per second 242 * Some sensors are not updated more frequently than once per second
235 * so it doesn't make sense to read them more often than that. 243 * so it doesn't make sense to read them more often than that.
@@ -243,11 +251,13 @@ static int adm1026_scaling[] = { /* .001 Volts */
243#define ADM1026_DATA_INTERVAL (1 * HZ) 251#define ADM1026_DATA_INTERVAL (1 * HZ)
244#define ADM1026_CONFIG_INTERVAL (5 * 60 * HZ) 252#define ADM1026_CONFIG_INTERVAL (5 * 60 * HZ)
245 253
246/* We allow for multiple chips in a single system. 254/*
255 * We allow for multiple chips in a single system.
247 * 256 *
248 * For each registered ADM1026, we need to keep state information 257 * For each registered ADM1026, we need to keep state information
249 * at client->data. The adm1026_data structure is dynamically 258 * at client->data. The adm1026_data structure is dynamically
250 * allocated, when a new client structure is allocated. */ 259 * allocated, when a new client structure is allocated.
260 */
251 261
252struct pwm_data { 262struct pwm_data {
253 u8 pwm; 263 u8 pwm;
@@ -388,17 +398,16 @@ static void adm1026_init_client(struct i2c_client *client)
388 dev_dbg(&client->dev, "THERM pin enabled. " 398 dev_dbg(&client->dev, "THERM pin enabled. "
389 "GPIO16 disabled.\n"); 399 "GPIO16 disabled.\n");
390 } 400 }
391 if (data->config3 & CFG3_VREF_250) { 401 if (data->config3 & CFG3_VREF_250)
392 dev_dbg(&client->dev, "Vref is 2.50 Volts.\n"); 402 dev_dbg(&client->dev, "Vref is 2.50 Volts.\n");
393 } else { 403 else
394 dev_dbg(&client->dev, "Vref is 1.82 Volts.\n"); 404 dev_dbg(&client->dev, "Vref is 1.82 Volts.\n");
395 }
396 /* Read and pick apart the existing GPIO configuration */ 405 /* Read and pick apart the existing GPIO configuration */
397 value = 0; 406 value = 0;
398 for (i = 0;i <= 15;++i) { 407 for (i = 0; i <= 15; ++i) {
399 if ((i & 0x03) == 0) { 408 if ((i & 0x03) == 0) {
400 value = adm1026_read_value(client, 409 value = adm1026_read_value(client,
401 ADM1026_REG_GPIO_CFG_0_3 + i/4); 410 ADM1026_REG_GPIO_CFG_0_3 + i / 4);
402 } 411 }
403 data->gpio_config[i] = value & 0x03; 412 data->gpio_config[i] = value & 0x03;
404 value >>= 2; 413 value >>= 2;
@@ -408,7 +417,8 @@ static void adm1026_init_client(struct i2c_client *client)
408 /* ... and then print it */ 417 /* ... and then print it */
409 adm1026_print_gpio(client); 418 adm1026_print_gpio(client);
410 419
411 /* If the user asks us to reprogram the GPIO config, then 420 /*
421 * If the user asks us to reprogram the GPIO config, then
412 * do it now. 422 * do it now.
413 */ 423 */
414 if (gpio_input[0] != -1 || gpio_output[0] != -1 424 if (gpio_input[0] != -1 || gpio_output[0] != -1
@@ -417,7 +427,8 @@ static void adm1026_init_client(struct i2c_client *client)
417 adm1026_fixup_gpio(client); 427 adm1026_fixup_gpio(client);
418 } 428 }
419 429
420 /* WE INTENTIONALLY make no changes to the limits, 430 /*
431 * WE INTENTIONALLY make no changes to the limits,
421 * offsets, pwms, fans and zones. If they were 432 * offsets, pwms, fans and zones. If they were
422 * configured, we don't want to mess with them. 433 * configured, we don't want to mess with them.
423 * If they weren't, the default is 100% PWM, no 434 * If they weren't, the default is 100% PWM, no
@@ -428,7 +439,7 @@ static void adm1026_init_client(struct i2c_client *client)
428 * without first setting a value for pwm1.auto_pwm_min 439 * without first setting a value for pwm1.auto_pwm_min
429 * will not result in potentially dangerous fan speed decrease. 440 * will not result in potentially dangerous fan speed decrease.
430 */ 441 */
431 data->pwm1.auto_pwm_min=255; 442 data->pwm1.auto_pwm_min = 255;
432 /* Start monitoring */ 443 /* Start monitoring */
433 value = adm1026_read_value(client, ADM1026_REG_CONFIG1); 444 value = adm1026_read_value(client, ADM1026_REG_CONFIG1);
434 /* Set MONITOR, clear interrupt acknowledge and s/w reset */ 445 /* Set MONITOR, clear interrupt acknowledge and s/w reset */
@@ -440,7 +451,7 @@ static void adm1026_init_client(struct i2c_client *client)
440 /* initialize fan_div[] to hardware defaults */ 451 /* initialize fan_div[] to hardware defaults */
441 value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3) | 452 value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3) |
442 (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7) << 8); 453 (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7) << 8);
443 for (i = 0;i <= 7;++i) { 454 for (i = 0; i <= 7; ++i) {
444 data->fan_div[i] = DIV_FROM_REG(value & 0x03); 455 data->fan_div[i] = DIV_FROM_REG(value & 0x03);
445 value >>= 2; 456 value >>= 2;
446 } 457 }
@@ -452,7 +463,7 @@ static void adm1026_print_gpio(struct i2c_client *client)
452 int i; 463 int i;
453 464
454 dev_dbg(&client->dev, "GPIO config is:\n"); 465 dev_dbg(&client->dev, "GPIO config is:\n");
455 for (i = 0;i <= 7;++i) { 466 for (i = 0; i <= 7; ++i) {
456 if (data->config2 & (1 << i)) { 467 if (data->config2 & (1 << i)) {
457 dev_dbg(&client->dev, "\t%sGP%s%d\n", 468 dev_dbg(&client->dev, "\t%sGP%s%d\n",
458 data->gpio_config[i] & 0x02 ? "" : "!", 469 data->gpio_config[i] & 0x02 ? "" : "!",
@@ -462,7 +473,7 @@ static void adm1026_print_gpio(struct i2c_client *client)
462 dev_dbg(&client->dev, "\tFAN%d\n", i); 473 dev_dbg(&client->dev, "\tFAN%d\n", i);
463 } 474 }
464 } 475 }
465 for (i = 8;i <= 15;++i) { 476 for (i = 8; i <= 15; ++i) {
466 dev_dbg(&client->dev, "\t%sGP%s%d\n", 477 dev_dbg(&client->dev, "\t%sGP%s%d\n",
467 data->gpio_config[i] & 0x02 ? "" : "!", 478 data->gpio_config[i] & 0x02 ? "" : "!",
468 data->gpio_config[i] & 0x01 ? "OUT" : "IN", 479 data->gpio_config[i] & 0x01 ? "OUT" : "IN",
@@ -485,52 +496,46 @@ static void adm1026_fixup_gpio(struct i2c_client *client)
485 int value; 496 int value;
486 497
487 /* Make the changes requested. */ 498 /* Make the changes requested. */
488 /* We may need to unlock/stop monitoring or soft-reset the 499 /*
500 * We may need to unlock/stop monitoring or soft-reset the
489 * chip before we can make changes. This hasn't been 501 * chip before we can make changes. This hasn't been
490 * tested much. FIXME 502 * tested much. FIXME
491 */ 503 */
492 504
493 /* Make outputs */ 505 /* Make outputs */
494 for (i = 0;i <= 16;++i) { 506 for (i = 0; i <= 16; ++i) {
495 if (gpio_output[i] >= 0 && gpio_output[i] <= 16) { 507 if (gpio_output[i] >= 0 && gpio_output[i] <= 16)
496 data->gpio_config[gpio_output[i]] |= 0x01; 508 data->gpio_config[gpio_output[i]] |= 0x01;
497 }
498 /* if GPIO0-7 is output, it isn't a FAN tach */ 509 /* if GPIO0-7 is output, it isn't a FAN tach */
499 if (gpio_output[i] >= 0 && gpio_output[i] <= 7) { 510 if (gpio_output[i] >= 0 && gpio_output[i] <= 7)
500 data->config2 |= 1 << gpio_output[i]; 511 data->config2 |= 1 << gpio_output[i];
501 }
502 } 512 }
503 513
504 /* Input overrides output */ 514 /* Input overrides output */
505 for (i = 0;i <= 16;++i) { 515 for (i = 0; i <= 16; ++i) {
506 if (gpio_input[i] >= 0 && gpio_input[i] <= 16) { 516 if (gpio_input[i] >= 0 && gpio_input[i] <= 16)
507 data->gpio_config[gpio_input[i]] &= ~ 0x01; 517 data->gpio_config[gpio_input[i]] &= ~0x01;
508 }
509 /* if GPIO0-7 is input, it isn't a FAN tach */ 518 /* if GPIO0-7 is input, it isn't a FAN tach */
510 if (gpio_input[i] >= 0 && gpio_input[i] <= 7) { 519 if (gpio_input[i] >= 0 && gpio_input[i] <= 7)
511 data->config2 |= 1 << gpio_input[i]; 520 data->config2 |= 1 << gpio_input[i];
512 }
513 } 521 }
514 522
515 /* Inverted */ 523 /* Inverted */
516 for (i = 0;i <= 16;++i) { 524 for (i = 0; i <= 16; ++i) {
517 if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16) { 525 if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16)
518 data->gpio_config[gpio_inverted[i]] &= ~ 0x02; 526 data->gpio_config[gpio_inverted[i]] &= ~0x02;
519 }
520 } 527 }
521 528
522 /* Normal overrides inverted */ 529 /* Normal overrides inverted */
523 for (i = 0;i <= 16;++i) { 530 for (i = 0; i <= 16; ++i) {
524 if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16) { 531 if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16)
525 data->gpio_config[gpio_normal[i]] |= 0x02; 532 data->gpio_config[gpio_normal[i]] |= 0x02;
526 }
527 } 533 }
528 534
529 /* Fan overrides input and output */ 535 /* Fan overrides input and output */
530 for (i = 0;i <= 7;++i) { 536 for (i = 0; i <= 7; ++i) {
531 if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7) { 537 if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7)
532 data->config2 &= ~(1 << gpio_fan[i]); 538 data->config2 &= ~(1 << gpio_fan[i]);
533 }
534 } 539 }
535 540
536 /* Write new configs to registers */ 541 /* Write new configs to registers */
@@ -538,7 +543,7 @@ static void adm1026_fixup_gpio(struct i2c_client *client)
538 data->config3 = (data->config3 & 0x3f) 543 data->config3 = (data->config3 & 0x3f)
539 | ((data->gpio_config[16] & 0x03) << 6); 544 | ((data->gpio_config[16] & 0x03) << 6);
540 adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3); 545 adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3);
541 for (i = 15, value = 0;i >= 0;--i) { 546 for (i = 15, value = 0; i >= 0; --i) {
542 value <<= 2; 547 value <<= 2;
543 value |= data->gpio_config[i] & 0x03; 548 value |= data->gpio_config[i] & 0x03;
544 if ((i & 0x03) == 0) { 549 if ((i & 0x03) == 0) {
@@ -563,22 +568,25 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
563 568
564 mutex_lock(&data->update_lock); 569 mutex_lock(&data->update_lock);
565 if (!data->valid 570 if (!data->valid
566 || time_after(jiffies, data->last_reading + ADM1026_DATA_INTERVAL)) { 571 || time_after(jiffies,
572 data->last_reading + ADM1026_DATA_INTERVAL)) {
567 /* Things that change quickly */ 573 /* Things that change quickly */
568 dev_dbg(&client->dev, "Reading sensor values\n"); 574 dev_dbg(&client->dev, "Reading sensor values\n");
569 for (i = 0;i <= 16;++i) { 575 for (i = 0; i <= 16; ++i) {
570 data->in[i] = 576 data->in[i] =
571 adm1026_read_value(client, ADM1026_REG_IN[i]); 577 adm1026_read_value(client, ADM1026_REG_IN[i]);
572 } 578 }
573 579
574 for (i = 0;i <= 7;++i) { 580 for (i = 0; i <= 7; ++i) {
575 data->fan[i] = 581 data->fan[i] =
576 adm1026_read_value(client, ADM1026_REG_FAN(i)); 582 adm1026_read_value(client, ADM1026_REG_FAN(i));
577 } 583 }
578 584
579 for (i = 0;i <= 2;++i) { 585 for (i = 0; i <= 2; ++i) {
580 /* NOTE: temp[] is s8 and we assume 2's complement 586 /*
581 * "conversion" in the assignment */ 587 * NOTE: temp[] is s8 and we assume 2's complement
588 * "conversion" in the assignment
589 */
582 data->temp[i] = 590 data->temp[i] =
583 adm1026_read_value(client, ADM1026_REG_TEMP[i]); 591 adm1026_read_value(client, ADM1026_REG_TEMP[i]);
584 } 592 }
@@ -614,7 +622,7 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
614 time_after(jiffies, data->last_config + ADM1026_CONFIG_INTERVAL)) { 622 time_after(jiffies, data->last_config + ADM1026_CONFIG_INTERVAL)) {
615 /* Things that don't change often */ 623 /* Things that don't change often */
616 dev_dbg(&client->dev, "Reading config values\n"); 624 dev_dbg(&client->dev, "Reading config values\n");
617 for (i = 0;i <= 16;++i) { 625 for (i = 0; i <= 16; ++i) {
618 data->in_min[i] = adm1026_read_value(client, 626 data->in_min[i] = adm1026_read_value(client,
619 ADM1026_REG_IN_MIN[i]); 627 ADM1026_REG_IN_MIN[i]);
620 data->in_max[i] = adm1026_read_value(client, 628 data->in_max[i] = adm1026_read_value(client,
@@ -624,7 +632,7 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
624 value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3) 632 value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3)
625 | (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7) 633 | (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7)
626 << 8); 634 << 8);
627 for (i = 0;i <= 7;++i) { 635 for (i = 0; i <= 7; ++i) {
628 data->fan_min[i] = adm1026_read_value(client, 636 data->fan_min[i] = adm1026_read_value(client,
629 ADM1026_REG_FAN_MIN(i)); 637 ADM1026_REG_FAN_MIN(i));
630 data->fan_div[i] = DIV_FROM_REG(value & 0x03); 638 data->fan_div[i] = DIV_FROM_REG(value & 0x03);
@@ -632,7 +640,8 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
632 } 640 }
633 641
634 for (i = 0; i <= 2; ++i) { 642 for (i = 0; i <= 2; ++i) {
635 /* NOTE: temp_xxx[] are s8 and we assume 2's 643 /*
644 * NOTE: temp_xxx[] are s8 and we assume 2's
636 * complement "conversion" in the assignment 645 * complement "conversion" in the assignment
637 */ 646 */
638 data->temp_min[i] = adm1026_read_value(client, 647 data->temp_min[i] = adm1026_read_value(client,
@@ -681,7 +690,7 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
681 data->gpio_config[16] = (data->config3 >> 6) & 0x03; 690 data->gpio_config[16] = (data->config3 >> 6) & 0x03;
682 691
683 value = 0; 692 value = 0;
684 for (i = 0;i <= 15;++i) { 693 for (i = 0; i <= 15; ++i) {
685 if ((i & 0x03) == 0) { 694 if ((i & 0x03) == 0) {
686 value = adm1026_read_value(client, 695 value = adm1026_read_value(client,
687 ADM1026_REG_GPIO_CFG_0_3 + i/4); 696 ADM1026_REG_GPIO_CFG_0_3 + i/4);
@@ -721,7 +730,12 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
721 int nr = sensor_attr->index; 730 int nr = sensor_attr->index;
722 struct i2c_client *client = to_i2c_client(dev); 731 struct i2c_client *client = to_i2c_client(dev);
723 struct adm1026_data *data = i2c_get_clientdata(client); 732 struct adm1026_data *data = i2c_get_clientdata(client);
724 int val = simple_strtol(buf, NULL, 10); 733 long val;
734 int err;
735
736 err = kstrtol(buf, 10, &val);
737 if (err)
738 return err;
725 739
726 mutex_lock(&data->update_lock); 740 mutex_lock(&data->update_lock);
727 data->in_min[nr] = INS_TO_REG(nr, val); 741 data->in_min[nr] = INS_TO_REG(nr, val);
@@ -744,7 +758,12 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
744 int nr = sensor_attr->index; 758 int nr = sensor_attr->index;
745 struct i2c_client *client = to_i2c_client(dev); 759 struct i2c_client *client = to_i2c_client(dev);
746 struct adm1026_data *data = i2c_get_clientdata(client); 760 struct adm1026_data *data = i2c_get_clientdata(client);
747 int val = simple_strtol(buf, NULL, 10); 761 long val;
762 int err;
763
764 err = kstrtol(buf, 10, &val);
765 if (err)
766 return err;
748 767
749 mutex_lock(&data->update_lock); 768 mutex_lock(&data->update_lock);
750 data->in_max[nr] = INS_TO_REG(nr, val); 769 data->in_max[nr] = INS_TO_REG(nr, val);
@@ -779,23 +798,31 @@ in_reg(13);
779in_reg(14); 798in_reg(14);
780in_reg(15); 799in_reg(15);
781 800
782static ssize_t show_in16(struct device *dev, struct device_attribute *attr, char *buf) 801static ssize_t show_in16(struct device *dev, struct device_attribute *attr,
802 char *buf)
783{ 803{
784 struct adm1026_data *data = adm1026_update_device(dev); 804 struct adm1026_data *data = adm1026_update_device(dev);
785 return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in[16]) - 805 return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in[16]) -
786 NEG12_OFFSET); 806 NEG12_OFFSET);
787} 807}
788static ssize_t show_in16_min(struct device *dev, struct device_attribute *attr, char *buf) 808static ssize_t show_in16_min(struct device *dev, struct device_attribute *attr,
809 char *buf)
789{ 810{
790 struct adm1026_data *data = adm1026_update_device(dev); 811 struct adm1026_data *data = adm1026_update_device(dev);
791 return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in_min[16]) 812 return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in_min[16])
792 - NEG12_OFFSET); 813 - NEG12_OFFSET);
793} 814}
794static ssize_t set_in16_min(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 815static ssize_t set_in16_min(struct device *dev, struct device_attribute *attr,
816 const char *buf, size_t count)
795{ 817{
796 struct i2c_client *client = to_i2c_client(dev); 818 struct i2c_client *client = to_i2c_client(dev);
797 struct adm1026_data *data = i2c_get_clientdata(client); 819 struct adm1026_data *data = i2c_get_clientdata(client);
798 int val = simple_strtol(buf, NULL, 10); 820 long val;
821 int err;
822
823 err = kstrtol(buf, 10, &val);
824 if (err)
825 return err;
799 826
800 mutex_lock(&data->update_lock); 827 mutex_lock(&data->update_lock);
801 data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET); 828 data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET);
@@ -803,17 +830,24 @@ static ssize_t set_in16_min(struct device *dev, struct device_attribute *attr, c
803 mutex_unlock(&data->update_lock); 830 mutex_unlock(&data->update_lock);
804 return count; 831 return count;
805} 832}
806static ssize_t show_in16_max(struct device *dev, struct device_attribute *attr, char *buf) 833static ssize_t show_in16_max(struct device *dev, struct device_attribute *attr,
834 char *buf)
807{ 835{
808 struct adm1026_data *data = adm1026_update_device(dev); 836 struct adm1026_data *data = adm1026_update_device(dev);
809 return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in_max[16]) 837 return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in_max[16])
810 - NEG12_OFFSET); 838 - NEG12_OFFSET);
811} 839}
812static ssize_t set_in16_max(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 840static ssize_t set_in16_max(struct device *dev, struct device_attribute *attr,
841 const char *buf, size_t count)
813{ 842{
814 struct i2c_client *client = to_i2c_client(dev); 843 struct i2c_client *client = to_i2c_client(dev);
815 struct adm1026_data *data = i2c_get_clientdata(client); 844 struct adm1026_data *data = i2c_get_clientdata(client);
816 int val = simple_strtol(buf, NULL, 10); 845 long val;
846 int err;
847
848 err = kstrtol(buf, 10, &val);
849 if (err)
850 return err;
817 851
818 mutex_lock(&data->update_lock); 852 mutex_lock(&data->update_lock);
819 data->in_max[16] = INS_TO_REG(16, val+NEG12_OFFSET); 853 data->in_max[16] = INS_TO_REG(16, val+NEG12_OFFSET);
@@ -823,10 +857,10 @@ static ssize_t set_in16_max(struct device *dev, struct device_attribute *attr, c
823} 857}
824 858
825static SENSOR_DEVICE_ATTR(in16_input, S_IRUGO, show_in16, NULL, 16); 859static SENSOR_DEVICE_ATTR(in16_input, S_IRUGO, show_in16, NULL, 16);
826static SENSOR_DEVICE_ATTR(in16_min, S_IRUGO | S_IWUSR, show_in16_min, set_in16_min, 16); 860static SENSOR_DEVICE_ATTR(in16_min, S_IRUGO | S_IWUSR, show_in16_min,
827static SENSOR_DEVICE_ATTR(in16_max, S_IRUGO | S_IWUSR, show_in16_max, set_in16_max, 16); 861 set_in16_min, 16);
828 862static SENSOR_DEVICE_ATTR(in16_max, S_IRUGO | S_IWUSR, show_in16_max,
829 863 set_in16_max, 16);
830 864
831 865
832/* Now add fan read/write functions */ 866/* Now add fan read/write functions */
@@ -856,7 +890,12 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
856 int nr = sensor_attr->index; 890 int nr = sensor_attr->index;
857 struct i2c_client *client = to_i2c_client(dev); 891 struct i2c_client *client = to_i2c_client(dev);
858 struct adm1026_data *data = i2c_get_clientdata(client); 892 struct adm1026_data *data = i2c_get_clientdata(client);
859 int val = simple_strtol(buf, NULL, 10); 893 long val;
894 int err;
895
896 err = kstrtol(buf, 10, &val);
897 if (err)
898 return err;
860 899
861 mutex_lock(&data->update_lock); 900 mutex_lock(&data->update_lock);
862 data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]); 901 data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]);
@@ -890,9 +929,8 @@ static void fixup_fan_min(struct device *dev, int fan, int old_div)
890 int new_div = data->fan_div[fan]; 929 int new_div = data->fan_div[fan];
891 930
892 /* 0 and 0xff are special. Don't adjust them */ 931 /* 0 and 0xff are special. Don't adjust them */
893 if (data->fan_min[fan] == 0 || data->fan_min[fan] == 0xff) { 932 if (data->fan_min[fan] == 0 || data->fan_min[fan] == 0xff)
894 return; 933 return;
895 }
896 934
897 new_min = data->fan_min[fan] * old_div / new_div; 935 new_min = data->fan_min[fan] * old_div / new_div;
898 new_min = SENSORS_LIMIT(new_min, 1, 254); 936 new_min = SENSORS_LIMIT(new_min, 1, 254);
@@ -916,9 +954,14 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
916 int nr = sensor_attr->index; 954 int nr = sensor_attr->index;
917 struct i2c_client *client = to_i2c_client(dev); 955 struct i2c_client *client = to_i2c_client(dev);
918 struct adm1026_data *data = i2c_get_clientdata(client); 956 struct adm1026_data *data = i2c_get_clientdata(client);
919 int val, orig_div, new_div; 957 long val;
958 int orig_div, new_div;
959 int err;
960
961 err = kstrtol(buf, 10, &val);
962 if (err)
963 return err;
920 964
921 val = simple_strtol(buf, NULL, 10);
922 new_div = DIV_TO_REG(val); 965 new_div = DIV_TO_REG(val);
923 966
924 mutex_lock(&data->update_lock); 967 mutex_lock(&data->update_lock);
@@ -939,9 +982,9 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
939 (DIV_TO_REG(data->fan_div[7]) << 6)); 982 (DIV_TO_REG(data->fan_div[7]) << 6));
940 } 983 }
941 984
942 if (data->fan_div[nr] != orig_div) { 985 if (data->fan_div[nr] != orig_div)
943 fixup_fan_min(dev, nr, orig_div); 986 fixup_fan_min(dev, nr, orig_div);
944 } 987
945 mutex_unlock(&data->update_lock); 988 mutex_unlock(&data->update_lock);
946 return count; 989 return count;
947} 990}
@@ -983,7 +1026,12 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
983 int nr = sensor_attr->index; 1026 int nr = sensor_attr->index;
984 struct i2c_client *client = to_i2c_client(dev); 1027 struct i2c_client *client = to_i2c_client(dev);
985 struct adm1026_data *data = i2c_get_clientdata(client); 1028 struct adm1026_data *data = i2c_get_clientdata(client);
986 int val = simple_strtol(buf, NULL, 10); 1029 long val;
1030 int err;
1031
1032 err = kstrtol(buf, 10, &val);
1033 if (err)
1034 return err;
987 1035
988 mutex_lock(&data->update_lock); 1036 mutex_lock(&data->update_lock);
989 data->temp_min[nr] = TEMP_TO_REG(val); 1037 data->temp_min[nr] = TEMP_TO_REG(val);
@@ -1007,7 +1055,12 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
1007 int nr = sensor_attr->index; 1055 int nr = sensor_attr->index;
1008 struct i2c_client *client = to_i2c_client(dev); 1056 struct i2c_client *client = to_i2c_client(dev);
1009 struct adm1026_data *data = i2c_get_clientdata(client); 1057 struct adm1026_data *data = i2c_get_clientdata(client);
1010 int val = simple_strtol(buf, NULL, 10); 1058 long val;
1059 int err;
1060
1061 err = kstrtol(buf, 10, &val);
1062 if (err)
1063 return err;
1011 1064
1012 mutex_lock(&data->update_lock); 1065 mutex_lock(&data->update_lock);
1013 data->temp_max[nr] = TEMP_TO_REG(val); 1066 data->temp_max[nr] = TEMP_TO_REG(val);
@@ -1046,7 +1099,12 @@ static ssize_t set_temp_offset(struct device *dev,
1046 int nr = sensor_attr->index; 1099 int nr = sensor_attr->index;
1047 struct i2c_client *client = to_i2c_client(dev); 1100 struct i2c_client *client = to_i2c_client(dev);
1048 struct adm1026_data *data = i2c_get_clientdata(client); 1101 struct adm1026_data *data = i2c_get_clientdata(client);
1049 int val = simple_strtol(buf, NULL, 10); 1102 long val;
1103 int err;
1104
1105 err = kstrtol(buf, 10, &val);
1106 if (err)
1107 return err;
1050 1108
1051 mutex_lock(&data->update_lock); 1109 mutex_lock(&data->update_lock);
1052 data->temp_offset[nr] = TEMP_TO_REG(val); 1110 data->temp_offset[nr] = TEMP_TO_REG(val);
@@ -1056,8 +1114,8 @@ static ssize_t set_temp_offset(struct device *dev,
1056 return count; 1114 return count;
1057} 1115}
1058 1116
1059#define temp_offset_reg(offset) \ 1117#define temp_offset_reg(offset) \
1060static SENSOR_DEVICE_ATTR(temp##offset##_offset, S_IRUGO | S_IWUSR, \ 1118static SENSOR_DEVICE_ATTR(temp##offset##_offset, S_IRUGO | S_IWUSR, \
1061 show_temp_offset, set_temp_offset, offset - 1); 1119 show_temp_offset, set_temp_offset, offset - 1);
1062 1120
1063temp_offset_reg(1); 1121temp_offset_reg(1);
@@ -1097,7 +1155,12 @@ static ssize_t set_temp_auto_point1_temp(struct device *dev,
1097 int nr = sensor_attr->index; 1155 int nr = sensor_attr->index;
1098 struct i2c_client *client = to_i2c_client(dev); 1156 struct i2c_client *client = to_i2c_client(dev);
1099 struct adm1026_data *data = i2c_get_clientdata(client); 1157 struct adm1026_data *data = i2c_get_clientdata(client);
1100 int val = simple_strtol(buf, NULL, 10); 1158 long val;
1159 int err;
1160
1161 err = kstrtol(buf, 10, &val);
1162 if (err)
1163 return err;
1101 1164
1102 mutex_lock(&data->update_lock); 1165 mutex_lock(&data->update_lock);
1103 data->temp_tmin[nr] = TEMP_TO_REG(val); 1166 data->temp_tmin[nr] = TEMP_TO_REG(val);
@@ -1131,15 +1194,21 @@ static ssize_t set_temp_crit_enable(struct device *dev,
1131{ 1194{
1132 struct i2c_client *client = to_i2c_client(dev); 1195 struct i2c_client *client = to_i2c_client(dev);
1133 struct adm1026_data *data = i2c_get_clientdata(client); 1196 struct adm1026_data *data = i2c_get_clientdata(client);
1134 int val = simple_strtol(buf, NULL, 10); 1197 unsigned long val;
1198 int err;
1199
1200 err = kstrtoul(buf, 10, &val);
1201 if (err)
1202 return err;
1203
1204 if (val > 1)
1205 return -EINVAL;
1206
1207 mutex_lock(&data->update_lock);
1208 data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4);
1209 adm1026_write_value(client, ADM1026_REG_CONFIG1, data->config1);
1210 mutex_unlock(&data->update_lock);
1135 1211
1136 if ((val == 1) || (val==0)) {
1137 mutex_lock(&data->update_lock);
1138 data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4);
1139 adm1026_write_value(client, ADM1026_REG_CONFIG1,
1140 data->config1);
1141 mutex_unlock(&data->update_lock);
1142 }
1143 return count; 1212 return count;
1144} 1213}
1145 1214
@@ -1166,7 +1235,12 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
1166 int nr = sensor_attr->index; 1235 int nr = sensor_attr->index;
1167 struct i2c_client *client = to_i2c_client(dev); 1236 struct i2c_client *client = to_i2c_client(dev);
1168 struct adm1026_data *data = i2c_get_clientdata(client); 1237 struct adm1026_data *data = i2c_get_clientdata(client);
1169 int val = simple_strtol(buf, NULL, 10); 1238 long val;
1239 int err;
1240
1241 err = kstrtol(buf, 10, &val);
1242 if (err)
1243 return err;
1170 1244
1171 mutex_lock(&data->update_lock); 1245 mutex_lock(&data->update_lock);
1172 data->temp_crit[nr] = TEMP_TO_REG(val); 1246 data->temp_crit[nr] = TEMP_TO_REG(val);
@@ -1184,17 +1258,24 @@ temp_crit_reg(1);
1184temp_crit_reg(2); 1258temp_crit_reg(2);
1185temp_crit_reg(3); 1259temp_crit_reg(3);
1186 1260
1187static ssize_t show_analog_out_reg(struct device *dev, struct device_attribute *attr, char *buf) 1261static ssize_t show_analog_out_reg(struct device *dev,
1262 struct device_attribute *attr, char *buf)
1188{ 1263{
1189 struct adm1026_data *data = adm1026_update_device(dev); 1264 struct adm1026_data *data = adm1026_update_device(dev);
1190 return sprintf(buf, "%d\n", DAC_FROM_REG(data->analog_out)); 1265 return sprintf(buf, "%d\n", DAC_FROM_REG(data->analog_out));
1191} 1266}
1192static ssize_t set_analog_out_reg(struct device *dev, struct device_attribute *attr, const char *buf, 1267static ssize_t set_analog_out_reg(struct device *dev,
1193 size_t count) 1268 struct device_attribute *attr,
1269 const char *buf, size_t count)
1194{ 1270{
1195 struct i2c_client *client = to_i2c_client(dev); 1271 struct i2c_client *client = to_i2c_client(dev);
1196 struct adm1026_data *data = i2c_get_clientdata(client); 1272 struct adm1026_data *data = i2c_get_clientdata(client);
1197 int val = simple_strtol(buf, NULL, 10); 1273 long val;
1274 int err;
1275
1276 err = kstrtol(buf, 10, &val);
1277 if (err)
1278 return err;
1198 1279
1199 mutex_lock(&data->update_lock); 1280 mutex_lock(&data->update_lock);
1200 data->analog_out = DAC_TO_REG(val); 1281 data->analog_out = DAC_TO_REG(val);
@@ -1206,7 +1287,8 @@ static ssize_t set_analog_out_reg(struct device *dev, struct device_attribute *a
1206static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg, 1287static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
1207 set_analog_out_reg); 1288 set_analog_out_reg);
1208 1289
1209static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) 1290static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
1291 char *buf)
1210{ 1292{
1211 struct adm1026_data *data = adm1026_update_device(dev); 1293 struct adm1026_data *data = adm1026_update_device(dev);
1212 int vid = (data->gpio >> 11) & 0x1f; 1294 int vid = (data->gpio >> 11) & 0x1f;
@@ -1214,25 +1296,35 @@ static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, c
1214 dev_dbg(dev, "Setting VID from GPIO11-15.\n"); 1296 dev_dbg(dev, "Setting VID from GPIO11-15.\n");
1215 return sprintf(buf, "%d\n", vid_from_reg(vid, data->vrm)); 1297 return sprintf(buf, "%d\n", vid_from_reg(vid, data->vrm));
1216} 1298}
1299
1217static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); 1300static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
1218 1301
1219static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) 1302static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
1303 char *buf)
1220{ 1304{
1221 struct adm1026_data *data = dev_get_drvdata(dev); 1305 struct adm1026_data *data = dev_get_drvdata(dev);
1222 return sprintf(buf, "%d\n", data->vrm); 1306 return sprintf(buf, "%d\n", data->vrm);
1223} 1307}
1224static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, 1308
1225 size_t count) 1309static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
1310 const char *buf, size_t count)
1226{ 1311{
1227 struct adm1026_data *data = dev_get_drvdata(dev); 1312 struct adm1026_data *data = dev_get_drvdata(dev);
1313 unsigned long val;
1314 int err;
1228 1315
1229 data->vrm = simple_strtol(buf, NULL, 10); 1316 err = kstrtoul(buf, 10, &val);
1317 if (err)
1318 return err;
1319
1320 data->vrm = val;
1230 return count; 1321 return count;
1231} 1322}
1232 1323
1233static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); 1324static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
1234 1325
1235static ssize_t show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf) 1326static ssize_t show_alarms_reg(struct device *dev,
1327 struct device_attribute *attr, char *buf)
1236{ 1328{
1237 struct adm1026_data *data = adm1026_update_device(dev); 1329 struct adm1026_data *data = adm1026_update_device(dev);
1238 return sprintf(buf, "%ld\n", data->alarms); 1330 return sprintf(buf, "%ld\n", data->alarms);
@@ -1277,18 +1369,24 @@ static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 24);
1277static SENSOR_DEVICE_ATTR(in10_alarm, S_IRUGO, show_alarm, NULL, 25); 1369static SENSOR_DEVICE_ATTR(in10_alarm, S_IRUGO, show_alarm, NULL, 25);
1278static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 26); 1370static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 26);
1279 1371
1280static ssize_t show_alarm_mask(struct device *dev, struct device_attribute *attr, char *buf) 1372static ssize_t show_alarm_mask(struct device *dev,
1373 struct device_attribute *attr, char *buf)
1281{ 1374{
1282 struct adm1026_data *data = adm1026_update_device(dev); 1375 struct adm1026_data *data = adm1026_update_device(dev);
1283 return sprintf(buf, "%ld\n", data->alarm_mask); 1376 return sprintf(buf, "%ld\n", data->alarm_mask);
1284} 1377}
1285static ssize_t set_alarm_mask(struct device *dev, struct device_attribute *attr, const char *buf, 1378static ssize_t set_alarm_mask(struct device *dev, struct device_attribute *attr,
1286 size_t count) 1379 const char *buf, size_t count)
1287{ 1380{
1288 struct i2c_client *client = to_i2c_client(dev); 1381 struct i2c_client *client = to_i2c_client(dev);
1289 struct adm1026_data *data = i2c_get_clientdata(client); 1382 struct adm1026_data *data = i2c_get_clientdata(client);
1290 int val = simple_strtol(buf, NULL, 10);
1291 unsigned long mask; 1383 unsigned long mask;
1384 long val;
1385 int err;
1386
1387 err = kstrtol(buf, 10, &val);
1388 if (err)
1389 return err;
1292 1390
1293 mutex_lock(&data->update_lock); 1391 mutex_lock(&data->update_lock);
1294 data->alarm_mask = val & 0x7fffffff; 1392 data->alarm_mask = val & 0x7fffffff;
@@ -1313,18 +1411,24 @@ static DEVICE_ATTR(alarm_mask, S_IRUGO | S_IWUSR, show_alarm_mask,
1313 set_alarm_mask); 1411 set_alarm_mask);
1314 1412
1315 1413
1316static ssize_t show_gpio(struct device *dev, struct device_attribute *attr, char *buf) 1414static ssize_t show_gpio(struct device *dev, struct device_attribute *attr,
1415 char *buf)
1317{ 1416{
1318 struct adm1026_data *data = adm1026_update_device(dev); 1417 struct adm1026_data *data = adm1026_update_device(dev);
1319 return sprintf(buf, "%ld\n", data->gpio); 1418 return sprintf(buf, "%ld\n", data->gpio);
1320} 1419}
1321static ssize_t set_gpio(struct device *dev, struct device_attribute *attr, const char *buf, 1420static ssize_t set_gpio(struct device *dev, struct device_attribute *attr,
1322 size_t count) 1421 const char *buf, size_t count)
1323{ 1422{
1324 struct i2c_client *client = to_i2c_client(dev); 1423 struct i2c_client *client = to_i2c_client(dev);
1325 struct adm1026_data *data = i2c_get_clientdata(client); 1424 struct adm1026_data *data = i2c_get_clientdata(client);
1326 int val = simple_strtol(buf, NULL, 10);
1327 long gpio; 1425 long gpio;
1426 long val;
1427 int err;
1428
1429 err = kstrtol(buf, 10, &val);
1430 if (err)
1431 return err;
1328 1432
1329 mutex_lock(&data->update_lock); 1433 mutex_lock(&data->update_lock);
1330 data->gpio = val & 0x1ffff; 1434 data->gpio = val & 0x1ffff;
@@ -1340,19 +1444,24 @@ static ssize_t set_gpio(struct device *dev, struct device_attribute *attr, const
1340 1444
1341static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio); 1445static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio);
1342 1446
1343 1447static ssize_t show_gpio_mask(struct device *dev, struct device_attribute *attr,
1344static ssize_t show_gpio_mask(struct device *dev, struct device_attribute *attr, char *buf) 1448 char *buf)
1345{ 1449{
1346 struct adm1026_data *data = adm1026_update_device(dev); 1450 struct adm1026_data *data = adm1026_update_device(dev);
1347 return sprintf(buf, "%ld\n", data->gpio_mask); 1451 return sprintf(buf, "%ld\n", data->gpio_mask);
1348} 1452}
1349static ssize_t set_gpio_mask(struct device *dev, struct device_attribute *attr, const char *buf, 1453static ssize_t set_gpio_mask(struct device *dev, struct device_attribute *attr,
1350 size_t count) 1454 const char *buf, size_t count)
1351{ 1455{
1352 struct i2c_client *client = to_i2c_client(dev); 1456 struct i2c_client *client = to_i2c_client(dev);
1353 struct adm1026_data *data = i2c_get_clientdata(client); 1457 struct adm1026_data *data = i2c_get_clientdata(client);
1354 int val = simple_strtol(buf, NULL, 10);
1355 long mask; 1458 long mask;
1459 long val;
1460 int err;
1461
1462 err = kstrtol(buf, 10, &val);
1463 if (err)
1464 return err;
1356 1465
1357 mutex_lock(&data->update_lock); 1466 mutex_lock(&data->update_lock);
1358 data->gpio_mask = val & 0x1ffff; 1467 data->gpio_mask = val & 0x1ffff;
@@ -1368,19 +1477,26 @@ static ssize_t set_gpio_mask(struct device *dev, struct device_attribute *attr,
1368 1477
1369static DEVICE_ATTR(gpio_mask, S_IRUGO | S_IWUSR, show_gpio_mask, set_gpio_mask); 1478static DEVICE_ATTR(gpio_mask, S_IRUGO | S_IWUSR, show_gpio_mask, set_gpio_mask);
1370 1479
1371static ssize_t show_pwm_reg(struct device *dev, struct device_attribute *attr, char *buf) 1480static ssize_t show_pwm_reg(struct device *dev, struct device_attribute *attr,
1481 char *buf)
1372{ 1482{
1373 struct adm1026_data *data = adm1026_update_device(dev); 1483 struct adm1026_data *data = adm1026_update_device(dev);
1374 return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm1.pwm)); 1484 return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm1.pwm));
1375} 1485}
1376static ssize_t set_pwm_reg(struct device *dev, struct device_attribute *attr, const char *buf, 1486
1377 size_t count) 1487static ssize_t set_pwm_reg(struct device *dev, struct device_attribute *attr,
1488 const char *buf, size_t count)
1378{ 1489{
1379 struct i2c_client *client = to_i2c_client(dev); 1490 struct i2c_client *client = to_i2c_client(dev);
1380 struct adm1026_data *data = i2c_get_clientdata(client); 1491 struct adm1026_data *data = i2c_get_clientdata(client);
1381 1492
1382 if (data->pwm1.enable == 1) { 1493 if (data->pwm1.enable == 1) {
1383 int val = simple_strtol(buf, NULL, 10); 1494 long val;
1495 int err;
1496
1497 err = kstrtol(buf, 10, &val);
1498 if (err)
1499 return err;
1384 1500
1385 mutex_lock(&data->update_lock); 1501 mutex_lock(&data->update_lock);
1386 data->pwm1.pwm = PWM_TO_REG(val); 1502 data->pwm1.pwm = PWM_TO_REG(val);
@@ -1389,17 +1505,26 @@ static ssize_t set_pwm_reg(struct device *dev, struct device_attribute *attr, co
1389 } 1505 }
1390 return count; 1506 return count;
1391} 1507}
1392static ssize_t show_auto_pwm_min(struct device *dev, struct device_attribute *attr, char *buf) 1508
1509static ssize_t show_auto_pwm_min(struct device *dev,
1510 struct device_attribute *attr, char *buf)
1393{ 1511{
1394 struct adm1026_data *data = adm1026_update_device(dev); 1512 struct adm1026_data *data = adm1026_update_device(dev);
1395 return sprintf(buf, "%d\n", data->pwm1.auto_pwm_min); 1513 return sprintf(buf, "%d\n", data->pwm1.auto_pwm_min);
1396} 1514}
1397static ssize_t set_auto_pwm_min(struct device *dev, struct device_attribute *attr, const char *buf, 1515
1398 size_t count) 1516static ssize_t set_auto_pwm_min(struct device *dev,
1517 struct device_attribute *attr, const char *buf,
1518 size_t count)
1399{ 1519{
1400 struct i2c_client *client = to_i2c_client(dev); 1520 struct i2c_client *client = to_i2c_client(dev);
1401 struct adm1026_data *data = i2c_get_clientdata(client); 1521 struct adm1026_data *data = i2c_get_clientdata(client);
1402 int val = simple_strtol(buf, NULL, 10); 1522 unsigned long val;
1523 int err;
1524
1525 err = kstrtoul(buf, 10, &val);
1526 if (err)
1527 return err;
1403 1528
1404 mutex_lock(&data->update_lock); 1529 mutex_lock(&data->update_lock);
1405 data->pwm1.auto_pwm_min = SENSORS_LIMIT(val, 0, 255); 1530 data->pwm1.auto_pwm_min = SENSORS_LIMIT(val, 0, 255);
@@ -1411,44 +1536,53 @@ static ssize_t set_auto_pwm_min(struct device *dev, struct device_attribute *att
1411 mutex_unlock(&data->update_lock); 1536 mutex_unlock(&data->update_lock);
1412 return count; 1537 return count;
1413} 1538}
1414static ssize_t show_auto_pwm_max(struct device *dev, struct device_attribute *attr, char *buf) 1539
1540static ssize_t show_auto_pwm_max(struct device *dev,
1541 struct device_attribute *attr, char *buf)
1415{ 1542{
1416 return sprintf(buf, "%d\n", ADM1026_PWM_MAX); 1543 return sprintf(buf, "%d\n", ADM1026_PWM_MAX);
1417} 1544}
1418static ssize_t show_pwm_enable(struct device *dev, struct device_attribute *attr, char *buf) 1545
1546static ssize_t show_pwm_enable(struct device *dev,
1547 struct device_attribute *attr, char *buf)
1419{ 1548{
1420 struct adm1026_data *data = adm1026_update_device(dev); 1549 struct adm1026_data *data = adm1026_update_device(dev);
1421 return sprintf(buf, "%d\n", data->pwm1.enable); 1550 return sprintf(buf, "%d\n", data->pwm1.enable);
1422} 1551}
1423static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr, const char *buf, 1552
1424 size_t count) 1553static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr,
1554 const char *buf, size_t count)
1425{ 1555{
1426 struct i2c_client *client = to_i2c_client(dev); 1556 struct i2c_client *client = to_i2c_client(dev);
1427 struct adm1026_data *data = i2c_get_clientdata(client); 1557 struct adm1026_data *data = i2c_get_clientdata(client);
1428 int val = simple_strtol(buf, NULL, 10);
1429 int old_enable; 1558 int old_enable;
1559 unsigned long val;
1560 int err;
1430 1561
1431 if ((val >= 0) && (val < 3)) { 1562 err = kstrtoul(buf, 10, &val);
1432 mutex_lock(&data->update_lock); 1563 if (err)
1433 old_enable = data->pwm1.enable; 1564 return err;
1434 data->pwm1.enable = val; 1565
1435 data->config1 = (data->config1 & ~CFG1_PWM_AFC) 1566 if (val >= 3)
1436 | ((val == 2) ? CFG1_PWM_AFC : 0); 1567 return -EINVAL;
1437 adm1026_write_value(client, ADM1026_REG_CONFIG1, 1568
1438 data->config1); 1569 mutex_lock(&data->update_lock);
1439 if (val == 2) { /* apply pwm1_auto_pwm_min to pwm1 */ 1570 old_enable = data->pwm1.enable;
1440 data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) | 1571 data->pwm1.enable = val;
1441 PWM_MIN_TO_REG(data->pwm1.auto_pwm_min)); 1572 data->config1 = (data->config1 & ~CFG1_PWM_AFC)
1442 adm1026_write_value(client, ADM1026_REG_PWM, 1573 | ((val == 2) ? CFG1_PWM_AFC : 0);
1443 data->pwm1.pwm); 1574 adm1026_write_value(client, ADM1026_REG_CONFIG1, data->config1);
1444 } else if (!((old_enable == 1) && (val == 1))) { 1575 if (val == 2) { /* apply pwm1_auto_pwm_min to pwm1 */
1445 /* set pwm to safe value */ 1576 data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
1446 data->pwm1.pwm = 255; 1577 PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
1447 adm1026_write_value(client, ADM1026_REG_PWM, 1578 adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
1448 data->pwm1.pwm); 1579 } else if (!((old_enable == 1) && (val == 1))) {
1449 } 1580 /* set pwm to safe value */
1450 mutex_unlock(&data->update_lock); 1581 data->pwm1.pwm = 255;
1582 adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
1451 } 1583 }
1584 mutex_unlock(&data->update_lock);
1585
1452 return count; 1586 return count;
1453} 1587}
1454 1588
@@ -1716,7 +1850,8 @@ static int adm1026_probe(struct i2c_client *client,
1716 adm1026_init_client(client); 1850 adm1026_init_client(client);
1717 1851
1718 /* Register sysfs hooks */ 1852 /* Register sysfs hooks */
1719 if ((err = sysfs_create_group(&client->dev.kobj, &adm1026_group))) 1853 err = sysfs_create_group(&client->dev.kobj, &adm1026_group);
1854 if (err)
1720 goto exitfree; 1855 goto exitfree;
1721 if (data->config1 & CFG1_AIN8_9) 1856 if (data->config1 & CFG1_AIN8_9)
1722 err = sysfs_create_group(&client->dev.kobj, 1857 err = sysfs_create_group(&client->dev.kobj,
@@ -1761,20 +1896,9 @@ static int adm1026_remove(struct i2c_client *client)
1761 return 0; 1896 return 0;
1762} 1897}
1763 1898
1764static int __init sm_adm1026_init(void) 1899module_i2c_driver(adm1026_driver);
1765{
1766 return i2c_add_driver(&adm1026_driver);
1767}
1768
1769static void __exit sm_adm1026_exit(void)
1770{
1771 i2c_del_driver(&adm1026_driver);
1772}
1773 1900
1774MODULE_LICENSE("GPL"); 1901MODULE_LICENSE("GPL");
1775MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, " 1902MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
1776 "Justin Thiessen <jthiessen@penguincomputing.com>"); 1903 "Justin Thiessen <jthiessen@penguincomputing.com>");
1777MODULE_DESCRIPTION("ADM1026 driver"); 1904MODULE_DESCRIPTION("ADM1026 driver");
1778
1779module_init(sm_adm1026_init);
1780module_exit(sm_adm1026_exit);
diff --git a/drivers/hwmon/adm1029.c b/drivers/hwmon/adm1029.c
index 0b8a3b145bd2..80cc465d8ac7 100644
--- a/drivers/hwmon/adm1029.c
+++ b/drivers/hwmon/adm1029.c
@@ -78,7 +78,7 @@ static const unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
78 78
79#define TEMP_FROM_REG(val) ((val) * 1000) 79#define TEMP_FROM_REG(val) ((val) * 1000)
80 80
81#define DIV_FROM_REG(val) ( 1 << (((val) >> 6) - 1)) 81#define DIV_FROM_REG(val) (1 << (((val) >> 6) - 1))
82 82
83/* Registers to be checked by adm1029_update_device() */ 83/* Registers to be checked by adm1029_update_device() */
84static const u8 ADM1029_REG_TEMP[] = { 84static const u8 ADM1029_REG_TEMP[] = {
@@ -200,8 +200,11 @@ static ssize_t set_fan_div(struct device *dev,
200 struct i2c_client *client = to_i2c_client(dev); 200 struct i2c_client *client = to_i2c_client(dev);
201 struct adm1029_data *data = i2c_get_clientdata(client); 201 struct adm1029_data *data = i2c_get_clientdata(client);
202 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 202 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
203 long val = simple_strtol(buf, NULL, 10);
204 u8 reg; 203 u8 reg;
204 long val;
205 int ret = kstrtol(buf, 10, &val);
206 if (ret < 0)
207 return ret;
205 208
206 mutex_lock(&data->update_lock); 209 mutex_lock(&data->update_lock);
207 210
@@ -237,9 +240,9 @@ static ssize_t set_fan_div(struct device *dev,
237} 240}
238 241
239/* 242/*
240Access rights on sysfs, S_IRUGO stand for Is Readable by User, Group and Others 243 * Access rights on sysfs. S_IRUGO: Is Readable by User, Group and Others
241 S_IWUSR stand for Is Writable by User 244 * S_IWUSR: Is Writable by User.
242*/ 245 */
243static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); 246static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
244static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1); 247static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
245static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2); 248static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
@@ -300,7 +303,8 @@ static int adm1029_detect(struct i2c_client *client,
300 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 303 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
301 return -ENODEV; 304 return -ENODEV;
302 305
303 /* ADM1029 doesn't have CHIP ID, check just MAN ID 306 /*
307 * ADM1029 doesn't have CHIP ID, check just MAN ID
304 * For better detection we check also ADM1029_TEMP_DEVICES_INSTALLED, 308 * For better detection we check also ADM1029_TEMP_DEVICES_INSTALLED,
305 * ADM1029_REG_NB_FAN_SUPPORT and compare it with possible values 309 * ADM1029_REG_NB_FAN_SUPPORT and compare it with possible values
306 * documented 310 * documented
@@ -318,8 +322,10 @@ static int adm1029_detect(struct i2c_client *client,
318 return -ENODEV; 322 return -ENODEV;
319 323
320 if ((chip_id & 0xF0) != 0x00) { 324 if ((chip_id & 0xF0) != 0x00) {
321 /* There are no "official" CHIP ID, so actually 325 /*
322 * we use Major/Minor revision for that */ 326 * There are no "official" CHIP ID, so actually
327 * we use Major/Minor revision for that
328 */
323 pr_info("adm1029: Unknown major revision %x, " 329 pr_info("adm1029: Unknown major revision %x, "
324 "please let us know\n", chip_id); 330 "please let us know\n", chip_id);
325 return -ENODEV; 331 return -ENODEV;
@@ -355,7 +361,8 @@ static int adm1029_probe(struct i2c_client *client,
355 } 361 }
356 362
357 /* Register sysfs hooks */ 363 /* Register sysfs hooks */
358 if ((err = sysfs_create_group(&client->dev.kobj, &adm1029_group))) 364 err = sysfs_create_group(&client->dev.kobj, &adm1029_group);
365 if (err)
359 goto exit_free; 366 goto exit_free;
360 367
361 data->hwmon_dev = hwmon_device_register(&client->dev); 368 data->hwmon_dev = hwmon_device_register(&client->dev);
@@ -403,8 +410,8 @@ static int adm1029_remove(struct i2c_client *client)
403} 410}
404 411
405/* 412/*
406function that update the status of the chips (temperature for example) 413 * function that update the status of the chips (temperature for example)
407*/ 414 */
408static struct adm1029_data *adm1029_update_device(struct device *dev) 415static struct adm1029_data *adm1029_update_device(struct device *dev)
409{ 416{
410 struct i2c_client *client = to_i2c_client(dev); 417 struct i2c_client *client = to_i2c_client(dev);
@@ -446,24 +453,8 @@ static struct adm1029_data *adm1029_update_device(struct device *dev)
446 return data; 453 return data;
447} 454}
448 455
449/* 456module_i2c_driver(adm1029_driver);
450 Common module stuff
451*/
452static int __init sensors_adm1029_init(void)
453{
454
455 return i2c_add_driver(&adm1029_driver);
456}
457
458static void __exit sensors_adm1029_exit(void)
459{
460
461 i2c_del_driver(&adm1029_driver);
462}
463 457
464MODULE_AUTHOR("Corentin LABBE <corentin.labbe@geomatys.fr>"); 458MODULE_AUTHOR("Corentin LABBE <corentin.labbe@geomatys.fr>");
465MODULE_DESCRIPTION("adm1029 driver"); 459MODULE_DESCRIPTION("adm1029 driver");
466MODULE_LICENSE("GPL v2"); 460MODULE_LICENSE("GPL v2");
467
468module_init(sensors_adm1029_init);
469module_exit(sensors_adm1029_exit);
diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c
index 97e2cfb0bc93..ff37363ea5bc 100644
--- a/drivers/hwmon/adm1031.c
+++ b/drivers/hwmon/adm1031.c
@@ -1,25 +1,25 @@
1/* 1/*
2 adm1031.c - Part of lm_sensors, Linux kernel modules for hardware 2 * adm1031.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 * monitoring
4 Based on lm75.c and lm85.c 4 * Based on lm75.c and lm85.c
5 Supports adm1030 / adm1031 5 * Supports adm1030 / adm1031
6 Copyright (C) 2004 Alexandre d'Alton <alex@alexdalton.org> 6 * Copyright (C) 2004 Alexandre d'Alton <alex@alexdalton.org>
7 Reworked by Jean Delvare <khali@linux-fr.org> 7 * Reworked by Jean Delvare <khali@linux-fr.org>
8 8 *
9 This program is free software; you can redistribute it and/or modify 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 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 11 * the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version. 12 * (at your option) any later version.
13 13 *
14 This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details. 17 * GNU General Public License for more details.
18 18 *
19 You should have received a copy of the GNU General Public License 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 20 * along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22*/ 22 */
23 23
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/init.h> 25#include <linux/init.h>
@@ -80,7 +80,8 @@ struct adm1031_data {
80 char valid; /* !=0 if following fields are valid */ 80 char valid; /* !=0 if following fields are valid */
81 unsigned long last_updated; /* In jiffies */ 81 unsigned long last_updated; /* In jiffies */
82 unsigned int update_interval; /* In milliseconds */ 82 unsigned int update_interval; /* In milliseconds */
83 /* The chan_select_table contains the possible configurations for 83 /*
84 * The chan_select_table contains the possible configurations for
84 * auto fan control. 85 * auto fan control.
85 */ 86 */
86 const auto_chan_table_t *chan_select_table; 87 const auto_chan_table_t *chan_select_table;
@@ -205,7 +206,8 @@ static int AUTO_TEMP_MAX_TO_REG(int val, int reg, int pwm)
205#define GET_FAN_AUTO_BITFIELD(data, idx) \ 206#define GET_FAN_AUTO_BITFIELD(data, idx) \
206 (*(data)->chan_select_table)[FAN_CHAN_FROM_REG((data)->conf1)][idx % 2] 207 (*(data)->chan_select_table)[FAN_CHAN_FROM_REG((data)->conf1)][idx % 2]
207 208
208/* The tables below contains the possible values for the auto fan 209/*
210 * The tables below contains the possible values for the auto fan
209 * control bitfields. the index in the table is the register value. 211 * control bitfields. the index in the table is the register value.
210 * MSb is the auto fan control enable bit, so the four first entries 212 * MSb is the auto fan control enable bit, so the four first entries
211 * in the table disables auto fan control when both bitfields are zero. 213 * in the table disables auto fan control when both bitfields are zero.
@@ -226,7 +228,8 @@ static const auto_chan_table_t auto_channel_select_table_adm1030 = {
226 { 3 /* 0b11 */ , 0 }, 228 { 3 /* 0b11 */ , 0 },
227}; 229};
228 230
229/* That function checks if a bitfield is valid and returns the other bitfield 231/*
232 * That function checks if a bitfield is valid and returns the other bitfield
230 * nearest match if no exact match where found. 233 * nearest match if no exact match where found.
231 */ 234 */
232static int 235static int
@@ -252,7 +255,8 @@ get_fan_auto_nearest(struct adm1031_data *data,
252 break; 255 break;
253 } else if (val == (*data->chan_select_table)[i][chan] && 256 } else if (val == (*data->chan_select_table)[i][chan] &&
254 first_match == -1) { 257 first_match == -1) {
255 /* Save the first match in case of an exact match has 258 /*
259 * Save the first match in case of an exact match has
256 * not been found 260 * not been found
257 */ 261 */
258 first_match = i; 262 first_match = i;
@@ -306,9 +310,11 @@ set_fan_auto_channel(struct device *dev, struct device_attribute *attr,
306 if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) ^ 310 if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) ^
307 (old_fan_mode & ADM1031_CONF1_AUTO_MODE)) { 311 (old_fan_mode & ADM1031_CONF1_AUTO_MODE)) {
308 if (data->conf1 & ADM1031_CONF1_AUTO_MODE) { 312 if (data->conf1 & ADM1031_CONF1_AUTO_MODE) {
309 /* Switch to Auto Fan Mode 313 /*
314 * Switch to Auto Fan Mode
310 * Save PWM registers 315 * Save PWM registers
311 * Set PWM registers to 33% Both */ 316 * Set PWM registers to 33% Both
317 */
312 data->old_pwm[0] = data->pwm[0]; 318 data->old_pwm[0] = data->pwm[0];
313 data->old_pwm[1] = data->pwm[1]; 319 data->old_pwm[1] = data->pwm[1];
314 adm1031_write_value(client, ADM1031_REG_PWM, 0x55); 320 adm1031_write_value(client, ADM1031_REG_PWM, 0x55);
@@ -1131,19 +1137,8 @@ static struct adm1031_data *adm1031_update_device(struct device *dev)
1131 return data; 1137 return data;
1132} 1138}
1133 1139
1134static int __init sensors_adm1031_init(void) 1140module_i2c_driver(adm1031_driver);
1135{
1136 return i2c_add_driver(&adm1031_driver);
1137}
1138
1139static void __exit sensors_adm1031_exit(void)
1140{
1141 i2c_del_driver(&adm1031_driver);
1142}
1143 1141
1144MODULE_AUTHOR("Alexandre d'Alton <alex@alexdalton.org>"); 1142MODULE_AUTHOR("Alexandre d'Alton <alex@alexdalton.org>");
1145MODULE_DESCRIPTION("ADM1031/ADM1030 driver"); 1143MODULE_DESCRIPTION("ADM1031/ADM1030 driver");
1146MODULE_LICENSE("GPL"); 1144MODULE_LICENSE("GPL");
1147
1148module_init(sensors_adm1031_init);
1149module_exit(sensors_adm1031_exit);
diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c
index 3f63f5f9741d..c3c2865a8967 100644
--- a/drivers/hwmon/adm9240.c
+++ b/drivers/hwmon/adm9240.c
@@ -1,12 +1,12 @@
1/* 1/*
2 * adm9240.c Part of lm_sensors, Linux kernel modules for hardware 2 * adm9240.c Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring 3 * monitoring
4 * 4 *
5 * Copyright (C) 1999 Frodo Looijaard <frodol@dds.nl> 5 * Copyright (C) 1999 Frodo Looijaard <frodol@dds.nl>
6 * Philip Edelbrock <phil@netroedge.com> 6 * Philip Edelbrock <phil@netroedge.com>
7 * Copyright (C) 2003 Michiel Rook <michiel@grendelproject.nl> 7 * Copyright (C) 2003 Michiel Rook <michiel@grendelproject.nl>
8 * Copyright (C) 2005 Grant Coady <gcoady.lk@gmail.com> with valuable 8 * Copyright (C) 2005 Grant Coady <gcoady.lk@gmail.com> with valuable
9 * guidance from Jean Delvare 9 * guidance from Jean Delvare
10 * 10 *
11 * Driver supports Analog Devices ADM9240 11 * Driver supports Analog Devices ADM9240
12 * Dallas Semiconductor DS1780 12 * Dallas Semiconductor DS1780
@@ -204,7 +204,12 @@ static ssize_t set_max(struct device *dev, struct device_attribute *devattr,
204 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 204 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
205 struct i2c_client *client = to_i2c_client(dev); 205 struct i2c_client *client = to_i2c_client(dev);
206 struct adm9240_data *data = i2c_get_clientdata(client); 206 struct adm9240_data *data = i2c_get_clientdata(client);
207 long val = simple_strtol(buf, NULL, 10); 207 long val;
208 int err;
209
210 err = kstrtol(buf, 10, &val);
211 if (err)
212 return err;
208 213
209 mutex_lock(&data->update_lock); 214 mutex_lock(&data->update_lock);
210 data->temp_max[attr->index] = TEMP_TO_REG(val); 215 data->temp_max[attr->index] = TEMP_TO_REG(val);
@@ -255,7 +260,12 @@ static ssize_t set_in_min(struct device *dev,
255 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 260 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
256 struct i2c_client *client = to_i2c_client(dev); 261 struct i2c_client *client = to_i2c_client(dev);
257 struct adm9240_data *data = i2c_get_clientdata(client); 262 struct adm9240_data *data = i2c_get_clientdata(client);
258 unsigned long val = simple_strtoul(buf, NULL, 10); 263 unsigned long val;
264 int err;
265
266 err = kstrtoul(buf, 10, &val);
267 if (err)
268 return err;
259 269
260 mutex_lock(&data->update_lock); 270 mutex_lock(&data->update_lock);
261 data->in_min[attr->index] = IN_TO_REG(val, attr->index); 271 data->in_min[attr->index] = IN_TO_REG(val, attr->index);
@@ -272,7 +282,12 @@ static ssize_t set_in_max(struct device *dev,
272 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 282 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
273 struct i2c_client *client = to_i2c_client(dev); 283 struct i2c_client *client = to_i2c_client(dev);
274 struct adm9240_data *data = i2c_get_clientdata(client); 284 struct adm9240_data *data = i2c_get_clientdata(client);
275 unsigned long val = simple_strtoul(buf, NULL, 10); 285 unsigned long val;
286 int err;
287
288 err = kstrtoul(buf, 10, &val);
289 if (err)
290 return err;
276 291
277 mutex_lock(&data->update_lock); 292 mutex_lock(&data->update_lock);
278 data->in_max[attr->index] = IN_TO_REG(val, attr->index); 293 data->in_max[attr->index] = IN_TO_REG(val, attr->index);
@@ -283,7 +298,7 @@ static ssize_t set_in_max(struct device *dev,
283} 298}
284 299
285#define vin(nr) \ 300#define vin(nr) \
286static SENSOR_DEVICE_ATTR(in##nr##_input, S_IRUGO, \ 301static SENSOR_DEVICE_ATTR(in##nr##_input, S_IRUGO, \
287 show_in, NULL, nr); \ 302 show_in, NULL, nr); \
288static SENSOR_DEVICE_ATTR(in##nr##_min, S_IRUGO | S_IWUSR, \ 303static SENSOR_DEVICE_ATTR(in##nr##_min, S_IRUGO | S_IWUSR, \
289 show_in_min, set_in_min, nr); \ 304 show_in_min, set_in_min, nr); \
@@ -357,9 +372,14 @@ static ssize_t set_fan_min(struct device *dev,
357 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 372 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
358 struct i2c_client *client = to_i2c_client(dev); 373 struct i2c_client *client = to_i2c_client(dev);
359 struct adm9240_data *data = i2c_get_clientdata(client); 374 struct adm9240_data *data = i2c_get_clientdata(client);
360 unsigned long val = simple_strtoul(buf, NULL, 10);
361 int nr = attr->index; 375 int nr = attr->index;
362 u8 new_div; 376 u8 new_div;
377 unsigned long val;
378 int err;
379
380 err = kstrtoul(buf, 10, &val);
381 if (err)
382 return err;
363 383
364 mutex_lock(&data->update_lock); 384 mutex_lock(&data->update_lock);
365 385
@@ -465,7 +485,12 @@ static ssize_t set_aout(struct device *dev,
465{ 485{
466 struct i2c_client *client = to_i2c_client(dev); 486 struct i2c_client *client = to_i2c_client(dev);
467 struct adm9240_data *data = i2c_get_clientdata(client); 487 struct adm9240_data *data = i2c_get_clientdata(client);
468 unsigned long val = simple_strtol(buf, NULL, 10); 488 long val;
489 int err;
490
491 err = kstrtol(buf, 10, &val);
492 if (err)
493 return err;
469 494
470 mutex_lock(&data->update_lock); 495 mutex_lock(&data->update_lock);
471 data->aout = AOUT_TO_REG(val); 496 data->aout = AOUT_TO_REG(val);
@@ -481,7 +506,12 @@ static ssize_t chassis_clear_legacy(struct device *dev,
481 const char *buf, size_t count) 506 const char *buf, size_t count)
482{ 507{
483 struct i2c_client *client = to_i2c_client(dev); 508 struct i2c_client *client = to_i2c_client(dev);
484 unsigned long val = simple_strtol(buf, NULL, 10); 509 long val;
510 int err;
511
512 err = kstrtol(buf, 10, &val);
513 if (err)
514 return err;
485 515
486 dev_warn(dev, "Attribute chassis_clear is deprecated, " 516 dev_warn(dev, "Attribute chassis_clear is deprecated, "
487 "use intrusion0_alarm instead\n"); 517 "use intrusion0_alarm instead\n");
@@ -632,7 +662,8 @@ static int adm9240_probe(struct i2c_client *new_client,
632 adm9240_init_client(new_client); 662 adm9240_init_client(new_client);
633 663
634 /* populate sysfs filesystem */ 664 /* populate sysfs filesystem */
635 if ((err = sysfs_create_group(&new_client->dev.kobj, &adm9240_group))) 665 err = sysfs_create_group(&new_client->dev.kobj, &adm9240_group);
666 if (err)
636 goto exit_free; 667 goto exit_free;
637 668
638 data->hwmon_dev = hwmon_device_register(&new_client->dev); 669 data->hwmon_dev = hwmon_device_register(&new_client->dev);
@@ -681,8 +712,7 @@ static void adm9240_init_client(struct i2c_client *client)
681 } else { /* cold start: open limits before starting chip */ 712 } else { /* cold start: open limits before starting chip */
682 int i; 713 int i;
683 714
684 for (i = 0; i < 6; i++) 715 for (i = 0; i < 6; i++) {
685 {
686 i2c_smbus_write_byte_data(client, 716 i2c_smbus_write_byte_data(client,
687 ADM9240_REG_IN_MIN(i), 0); 717 ADM9240_REG_IN_MIN(i), 0);
688 i2c_smbus_write_byte_data(client, 718 i2c_smbus_write_byte_data(client,
@@ -717,8 +747,7 @@ static struct adm9240_data *adm9240_update_device(struct device *dev)
717 if (time_after(jiffies, data->last_updated_measure + (HZ * 7 / 4)) 747 if (time_after(jiffies, data->last_updated_measure + (HZ * 7 / 4))
718 || !data->valid) { 748 || !data->valid) {
719 749
720 for (i = 0; i < 6; i++) /* read voltages */ 750 for (i = 0; i < 6; i++) { /* read voltages */
721 {
722 data->in[i] = i2c_smbus_read_byte_data(client, 751 data->in[i] = i2c_smbus_read_byte_data(client,
723 ADM9240_REG_IN(i)); 752 ADM9240_REG_IN(i));
724 } 753 }
@@ -727,16 +756,17 @@ static struct adm9240_data *adm9240_update_device(struct device *dev)
727 i2c_smbus_read_byte_data(client, 756 i2c_smbus_read_byte_data(client,
728 ADM9240_REG_INT(1)) << 8; 757 ADM9240_REG_INT(1)) << 8;
729 758
730 /* read temperature: assume temperature changes less than 759 /*
760 * read temperature: assume temperature changes less than
731 * 0.5'C per two measurement cycles thus ignore possible 761 * 0.5'C per two measurement cycles thus ignore possible
732 * but unlikely aliasing error on lsb reading. --Grant */ 762 * but unlikely aliasing error on lsb reading. --Grant
763 */
733 data->temp = ((i2c_smbus_read_byte_data(client, 764 data->temp = ((i2c_smbus_read_byte_data(client,
734 ADM9240_REG_TEMP) << 8) | 765 ADM9240_REG_TEMP) << 8) |
735 i2c_smbus_read_byte_data(client, 766 i2c_smbus_read_byte_data(client,
736 ADM9240_REG_TEMP_CONF)) / 128; 767 ADM9240_REG_TEMP_CONF)) / 128;
737 768
738 for (i = 0; i < 2; i++) /* read fans */ 769 for (i = 0; i < 2; i++) { /* read fans */
739 {
740 data->fan[i] = i2c_smbus_read_byte_data(client, 770 data->fan[i] = i2c_smbus_read_byte_data(client,
741 ADM9240_REG_FAN(i)); 771 ADM9240_REG_FAN(i));
742 772
@@ -760,15 +790,13 @@ static struct adm9240_data *adm9240_update_device(struct device *dev)
760 if (time_after(jiffies, data->last_updated_config + (HZ * 300)) 790 if (time_after(jiffies, data->last_updated_config + (HZ * 300))
761 || !data->valid) { 791 || !data->valid) {
762 792
763 for (i = 0; i < 6; i++) 793 for (i = 0; i < 6; i++) {
764 {
765 data->in_min[i] = i2c_smbus_read_byte_data(client, 794 data->in_min[i] = i2c_smbus_read_byte_data(client,
766 ADM9240_REG_IN_MIN(i)); 795 ADM9240_REG_IN_MIN(i));
767 data->in_max[i] = i2c_smbus_read_byte_data(client, 796 data->in_max[i] = i2c_smbus_read_byte_data(client,
768 ADM9240_REG_IN_MAX(i)); 797 ADM9240_REG_IN_MAX(i));
769 } 798 }
770 for (i = 0; i < 2; i++) 799 for (i = 0; i < 2; i++) {
771 {
772 data->fan_min[i] = i2c_smbus_read_byte_data(client, 800 data->fan_min[i] = i2c_smbus_read_byte_data(client,
773 ADM9240_REG_FAN_MIN(i)); 801 ADM9240_REG_FAN_MIN(i));
774 } 802 }
@@ -795,21 +823,9 @@ static struct adm9240_data *adm9240_update_device(struct device *dev)
795 return data; 823 return data;
796} 824}
797 825
798static int __init sensors_adm9240_init(void) 826module_i2c_driver(adm9240_driver);
799{
800 return i2c_add_driver(&adm9240_driver);
801}
802
803static void __exit sensors_adm9240_exit(void)
804{
805 i2c_del_driver(&adm9240_driver);
806}
807 827
808MODULE_AUTHOR("Michiel Rook <michiel@grendelproject.nl>, " 828MODULE_AUTHOR("Michiel Rook <michiel@grendelproject.nl>, "
809 "Grant Coady <gcoady.lk@gmail.com> and others"); 829 "Grant Coady <gcoady.lk@gmail.com> and others");
810MODULE_DESCRIPTION("ADM9240/DS1780/LM81 driver"); 830MODULE_DESCRIPTION("ADM9240/DS1780/LM81 driver");
811MODULE_LICENSE("GPL"); 831MODULE_LICENSE("GPL");
812
813module_init(sensors_adm9240_init);
814module_exit(sensors_adm9240_exit);
815
diff --git a/drivers/hwmon/ads1015.c b/drivers/hwmon/ads1015.c
index dd87ae96c262..7765e4f74ec5 100644
--- a/drivers/hwmon/ads1015.c
+++ b/drivers/hwmon/ads1015.c
@@ -305,19 +305,8 @@ static struct i2c_driver ads1015_driver = {
305 .id_table = ads1015_id, 305 .id_table = ads1015_id,
306}; 306};
307 307
308static int __init sensors_ads1015_init(void) 308module_i2c_driver(ads1015_driver);
309{
310 return i2c_add_driver(&ads1015_driver);
311}
312
313static void __exit sensors_ads1015_exit(void)
314{
315 i2c_del_driver(&ads1015_driver);
316}
317 309
318MODULE_AUTHOR("Dirk Eibach <eibach@gdsys.de>"); 310MODULE_AUTHOR("Dirk Eibach <eibach@gdsys.de>");
319MODULE_DESCRIPTION("ADS1015 driver"); 311MODULE_DESCRIPTION("ADS1015 driver");
320MODULE_LICENSE("GPL"); 312MODULE_LICENSE("GPL");
321
322module_init(sensors_ads1015_init);
323module_exit(sensors_ads1015_exit);
diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c
index ed60242d6a0a..bf3fdf495595 100644
--- a/drivers/hwmon/ads7828.c
+++ b/drivers/hwmon/ads7828.c
@@ -1,27 +1,27 @@
1/* 1/*
2 ads7828.c - lm_sensors driver for ads7828 12-bit 8-channel ADC 2 * ads7828.c - lm_sensors driver for ads7828 12-bit 8-channel ADC
3 (C) 2007 EADS Astrium 3 * (C) 2007 EADS Astrium
4 4 *
5 This driver is based on the lm75 and other lm_sensors/hwmon drivers 5 * This driver is based on the lm75 and other lm_sensors/hwmon drivers
6 6 *
7 Written by Steve Hardy <shardy@redhat.com> 7 * Written by Steve Hardy <shardy@redhat.com>
8 8 *
9 Datasheet available at: http://focus.ti.com/lit/ds/symlink/ads7828.pdf 9 * Datasheet available at: http://focus.ti.com/lit/ds/symlink/ads7828.pdf
10 10 *
11 This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by 12 * it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or 13 * the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version. 14 * (at your option) any later version.
15 15 *
16 This program is distributed in the hope that it will be useful, 16 * This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details. 19 * GNU General Public License for more details.
20 20 *
21 You should have received a copy of the GNU General Public License 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 22 * along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24*/ 24 */
25 25
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/init.h> 27#include <linux/init.h>
@@ -188,12 +188,13 @@ static int ads7828_detect(struct i2c_client *client,
188 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA)) 188 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA))
189 return -ENODEV; 189 return -ENODEV;
190 190
191 /* Now, we do the remaining detection. There is no identification 191 /*
192 dedicated register so attempt to sanity check using knowledge of 192 * Now, we do the remaining detection. There is no identification
193 the chip 193 * dedicated register so attempt to sanity check using knowledge of
194 - Read from the 8 channel addresses 194 * the chip
195 - Check the top 4 bits of each result are not set (12 data bits) 195 * - Read from the 8 channel addresses
196 */ 196 * - Check the top 4 bits of each result are not set (12 data bits)
197 */
197 for (ch = 0; ch < ADS7828_NCH; ch++) { 198 for (ch = 0; ch < ADS7828_NCH; ch++) {
198 u16 in_data; 199 u16 in_data;
199 u8 cmd = channel_cmd_byte(ch); 200 u8 cmd = channel_cmd_byte(ch);
diff --git a/drivers/hwmon/ads7871.c b/drivers/hwmon/ads7871.c
index 04450f8bf5da..e65c6e45d36b 100644
--- a/drivers/hwmon/ads7871.c
+++ b/drivers/hwmon/ads7871.c
@@ -34,9 +34,11 @@
34#define REG_SER_CONTROL 24 /*Serial Interface Control Register*/ 34#define REG_SER_CONTROL 24 /*Serial Interface Control Register*/
35#define REG_ID 31 /*ID Register*/ 35#define REG_ID 31 /*ID Register*/
36 36
37/*From figure 17 in the datasheet 37/*
38* These bits get ORed with the address to form 38 * From figure 17 in the datasheet
39* the instruction byte */ 39 * These bits get ORed with the address to form
40 * the instruction byte
41 */
40/*Instruction Bit masks*/ 42/*Instruction Bit masks*/
41#define INST_MODE_bm (1<<7) 43#define INST_MODE_bm (1<<7)
42#define INST_READ_bm (1<<6) 44#define INST_READ_bm (1<<6)
@@ -105,8 +107,10 @@ static ssize_t show_voltage(struct device *dev,
105 uint8_t channel, mux_cnv; 107 uint8_t channel, mux_cnv;
106 108
107 channel = attr->index; 109 channel = attr->index;
108 /*TODO: add support for conversions 110 /*
109 *other than single ended with a gain of 1*/ 111 * TODO: add support for conversions
112 * other than single ended with a gain of 1
113 */
110 /*MUX_M3_bm forces single ended*/ 114 /*MUX_M3_bm forces single ended*/
111 /*This is also where the gain of the PGA would be set*/ 115 /*This is also where the gain of the PGA would be set*/
112 ads7871_write_reg8(spi, REG_GAIN_MUX, 116 ads7871_write_reg8(spi, REG_GAIN_MUX,
@@ -114,8 +118,10 @@ static ssize_t show_voltage(struct device *dev,
114 118
115 ret = ads7871_read_reg8(spi, REG_GAIN_MUX); 119 ret = ads7871_read_reg8(spi, REG_GAIN_MUX);
116 mux_cnv = ((ret & MUX_CNV_bm)>>MUX_CNV_bv); 120 mux_cnv = ((ret & MUX_CNV_bm)>>MUX_CNV_bv);
117 /*on 400MHz arm9 platform the conversion 121 /*
118 *is already done when we do this test*/ 122 * on 400MHz arm9 platform the conversion
123 * is already done when we do this test
124 */
119 while ((i < 2) && mux_cnv) { 125 while ((i < 2) && mux_cnv) {
120 i++; 126 i++;
121 ret = ads7871_read_reg8(spi, REG_GAIN_MUX); 127 ret = ads7871_read_reg8(spi, REG_GAIN_MUX);
@@ -179,8 +185,10 @@ static int __devinit ads7871_probe(struct spi_device *spi)
179 ret = ads7871_read_reg8(spi, REG_OSC_CONTROL); 185 ret = ads7871_read_reg8(spi, REG_OSC_CONTROL);
180 186
181 dev_dbg(&spi->dev, "REG_OSC_CONTROL write:%x, read:%x\n", val, ret); 187 dev_dbg(&spi->dev, "REG_OSC_CONTROL write:%x, read:%x\n", val, ret);
182 /*because there is no other error checking on an SPI bus 188 /*
183 we need to make sure we really have a chip*/ 189 * because there is no other error checking on an SPI bus
190 * we need to make sure we really have a chip
191 */
184 if (val != ret) { 192 if (val != ret) {
185 err = -ENODEV; 193 err = -ENODEV;
186 goto exit; 194 goto exit;
@@ -234,18 +242,7 @@ static struct spi_driver ads7871_driver = {
234 .remove = __devexit_p(ads7871_remove), 242 .remove = __devexit_p(ads7871_remove),
235}; 243};
236 244
237static int __init ads7871_init(void) 245module_spi_driver(ads7871_driver);
238{
239 return spi_register_driver(&ads7871_driver);
240}
241
242static void __exit ads7871_exit(void)
243{
244 spi_unregister_driver(&ads7871_driver);
245}
246
247module_init(ads7871_init);
248module_exit(ads7871_exit);
249 246
250MODULE_AUTHOR("Paul Thomas <pthomas8589@gmail.com>"); 247MODULE_AUTHOR("Paul Thomas <pthomas8589@gmail.com>");
251MODULE_DESCRIPTION("TI ADS7871 A/D driver"); 248MODULE_DESCRIPTION("TI ADS7871 A/D driver");
diff --git a/drivers/hwmon/adt7411.c b/drivers/hwmon/adt7411.c
index 5b02f7a91018..71bacc56e138 100644
--- a/drivers/hwmon/adt7411.c
+++ b/drivers/hwmon/adt7411.c
@@ -8,7 +8,7 @@
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 * 9 *
10 * TODO: SPI, support for external temperature sensor 10 * TODO: SPI, support for external temperature sensor
11 * use power-down mode for suspend?, interrupt handling? 11 * use power-down mode for suspend?, interrupt handling?
12 */ 12 */
13 13
14#include <linux/kernel.h> 14#include <linux/kernel.h>
@@ -348,17 +348,7 @@ static struct i2c_driver adt7411_driver = {
348 .class = I2C_CLASS_HWMON, 348 .class = I2C_CLASS_HWMON,
349}; 349};
350 350
351static int __init sensors_adt7411_init(void) 351module_i2c_driver(adt7411_driver);
352{
353 return i2c_add_driver(&adt7411_driver);
354}
355module_init(sensors_adt7411_init)
356
357static void __exit sensors_adt7411_exit(void)
358{
359 i2c_del_driver(&adt7411_driver);
360}
361module_exit(sensors_adt7411_exit)
362 352
363MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de> and " 353MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de> and "
364 "Wolfram Sang <w.sang@pengutronix.de>"); 354 "Wolfram Sang <w.sang@pengutronix.de>");
diff --git a/drivers/hwmon/adt7462.c b/drivers/hwmon/adt7462.c
index 7a1494846cfd..339269f76e57 100644
--- a/drivers/hwmon/adt7462.c
+++ b/drivers/hwmon/adt7462.c
@@ -65,8 +65,8 @@ static const unsigned short normal_i2c[] = { 0x58, 0x5C, I2C_CLIENT_END };
65#define ADT7462_REG_PWM_TEMP_MIN_MAX_ADDR 0x5F 65#define ADT7462_REG_PWM_TEMP_MIN_MAX_ADDR 0x5F
66#define ADT7462_REG_PWM_TEMP_RANGE_BASE_ADDR 0x60 66#define ADT7462_REG_PWM_TEMP_RANGE_BASE_ADDR 0x60
67#define ADT7462_REG_PWM_TEMP_RANGE_MAX_ADDR 0x63 67#define ADT7462_REG_PWM_TEMP_RANGE_MAX_ADDR 0x63
68#define ADT7462_PWM_HYST_MASK 0x0F 68#define ADT7462_PWM_HYST_MASK 0x0F
69#define ADT7462_PWM_RANGE_MASK 0xF0 69#define ADT7462_PWM_RANGE_MASK 0xF0
70#define ADT7462_PWM_RANGE_SHIFT 4 70#define ADT7462_PWM_RANGE_SHIFT 4
71#define ADT7462_REG_PWM_CFG_BASE_ADDR 0x21 71#define ADT7462_REG_PWM_CFG_BASE_ADDR 0x21
72#define ADT7462_REG_PWM_CFG_MAX_ADDR 0x24 72#define ADT7462_REG_PWM_CFG_MAX_ADDR 0x24
@@ -85,7 +85,7 @@ static const unsigned short normal_i2c[] = { 0x58, 0x5C, I2C_CLIENT_END };
85#define ADT7462_PIN15_INPUT 0x20 85#define ADT7462_PIN15_INPUT 0x20
86#define ADT7462_PIN13_INPUT 0x40 86#define ADT7462_PIN13_INPUT 0x40
87#define ADT7462_PIN8_INPUT 0x80 87#define ADT7462_PIN8_INPUT 0x80
88#define ADT7462_PIN23_MASK 0x03 88#define ADT7462_PIN23_MASK 0x03
89#define ADT7462_PIN23_SHIFT 0 89#define ADT7462_PIN23_SHIFT 0
90#define ADT7462_PIN26_MASK 0x0C /* cfg2 */ 90#define ADT7462_PIN26_MASK 0x0C /* cfg2 */
91#define ADT7462_PIN26_SHIFT 2 91#define ADT7462_PIN26_SHIFT 2
@@ -99,7 +99,7 @@ static const unsigned short normal_i2c[] = { 0x58, 0x5C, I2C_CLIENT_END };
99#define ADT7462_PIN28_VOLT 0x5 99#define ADT7462_PIN28_VOLT 0x5
100 100
101#define ADT7462_REG_ALARM1 0xB8 101#define ADT7462_REG_ALARM1 0xB8
102#define ADT7462_LT_ALARM 0x02 102#define ADT7462_LT_ALARM 0x02
103#define ADT7462_R1T_ALARM 0x04 103#define ADT7462_R1T_ALARM 0x04
104#define ADT7462_R2T_ALARM 0x08 104#define ADT7462_R2T_ALARM 0x08
105#define ADT7462_R3T_ALARM 0x10 105#define ADT7462_R3T_ALARM 0x10
@@ -135,9 +135,9 @@ static const unsigned short normal_i2c[] = { 0x58, 0x5C, I2C_CLIENT_END };
135#define ADT7462_ALARM_FLAG_MASK 0x0F 135#define ADT7462_ALARM_FLAG_MASK 0x0F
136 136
137#define ADT7462_TEMP_COUNT 4 137#define ADT7462_TEMP_COUNT 4
138#define ADT7462_TEMP_REG(x) (ADT7462_REG_TEMP_BASE_ADDR + (x * 2)) 138#define ADT7462_TEMP_REG(x) (ADT7462_REG_TEMP_BASE_ADDR + ((x) * 2))
139#define ADT7462_TEMP_MIN_REG(x) (ADT7462_REG_MIN_TEMP_BASE_ADDR + (x)) 139#define ADT7462_TEMP_MIN_REG(x) (ADT7462_REG_MIN_TEMP_BASE_ADDR + (x))
140#define ADT7462_TEMP_MAX_REG(x) (ADT7462_REG_MAX_TEMP_BASE_ADDR + (x)) 140#define ADT7462_TEMP_MAX_REG(x) (ADT7462_REG_MAX_TEMP_BASE_ADDR + (x))
141#define TEMP_FRAC_OFFSET 6 141#define TEMP_FRAC_OFFSET 6
142 142
143#define ADT7462_FAN_COUNT 8 143#define ADT7462_FAN_COUNT 8
@@ -1727,8 +1727,7 @@ static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IWUSR | S_IRUGO,
1727static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO, 1727static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO,
1728 show_pwm_auto_temp, set_pwm_auto_temp, 3); 1728 show_pwm_auto_temp, set_pwm_auto_temp, 3);
1729 1729
1730static struct attribute *adt7462_attr[] = 1730static struct attribute *adt7462_attr[] = {
1731{
1732 &sensor_dev_attr_temp1_max.dev_attr.attr, 1731 &sensor_dev_attr_temp1_max.dev_attr.attr,
1733 &sensor_dev_attr_temp2_max.dev_attr.attr, 1732 &sensor_dev_attr_temp2_max.dev_attr.attr,
1734 &sensor_dev_attr_temp3_max.dev_attr.attr, 1733 &sensor_dev_attr_temp3_max.dev_attr.attr,
@@ -1975,19 +1974,8 @@ static int adt7462_remove(struct i2c_client *client)
1975 return 0; 1974 return 0;
1976} 1975}
1977 1976
1978static int __init adt7462_init(void) 1977module_i2c_driver(adt7462_driver);
1979{
1980 return i2c_add_driver(&adt7462_driver);
1981}
1982
1983static void __exit adt7462_exit(void)
1984{
1985 i2c_del_driver(&adt7462_driver);
1986}
1987 1978
1988MODULE_AUTHOR("Darrick J. Wong <djwong@us.ibm.com>"); 1979MODULE_AUTHOR("Darrick J. Wong <djwong@us.ibm.com>");
1989MODULE_DESCRIPTION("ADT7462 driver"); 1980MODULE_DESCRIPTION("ADT7462 driver");
1990MODULE_LICENSE("GPL"); 1981MODULE_LICENSE("GPL");
1991
1992module_init(adt7462_init);
1993module_exit(adt7462_exit);
diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
index 5e10c79f2dfd..54ec890521ff 100644
--- a/drivers/hwmon/adt7470.c
+++ b/drivers/hwmon/adt7470.c
@@ -1131,8 +1131,7 @@ static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IWUSR | S_IRUGO,
1131static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO, 1131static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO,
1132 show_pwm_auto_temp, set_pwm_auto_temp, 3); 1132 show_pwm_auto_temp, set_pwm_auto_temp, 3);
1133 1133
1134static struct attribute *adt7470_attr[] = 1134static struct attribute *adt7470_attr[] = {
1135{
1136 &dev_attr_alarm_mask.attr, 1135 &dev_attr_alarm_mask.attr,
1137 &dev_attr_num_temp_sensors.attr, 1136 &dev_attr_num_temp_sensors.attr,
1138 &dev_attr_auto_update_interval.attr, 1137 &dev_attr_auto_update_interval.attr,
@@ -1276,7 +1275,8 @@ static int adt7470_probe(struct i2c_client *client,
1276 1275
1277 /* Register sysfs hooks */ 1276 /* Register sysfs hooks */
1278 data->attrs.attrs = adt7470_attr; 1277 data->attrs.attrs = adt7470_attr;
1279 if ((err = sysfs_create_group(&client->dev.kobj, &data->attrs))) 1278 err = sysfs_create_group(&client->dev.kobj, &data->attrs);
1279 if (err)
1280 goto exit_free; 1280 goto exit_free;
1281 1281
1282 data->hwmon_dev = hwmon_device_register(&client->dev); 1282 data->hwmon_dev = hwmon_device_register(&client->dev);
@@ -1317,19 +1317,8 @@ static int adt7470_remove(struct i2c_client *client)
1317 return 0; 1317 return 0;
1318} 1318}
1319 1319
1320static int __init adt7470_init(void) 1320module_i2c_driver(adt7470_driver);
1321{
1322 return i2c_add_driver(&adt7470_driver);
1323}
1324
1325static void __exit adt7470_exit(void)
1326{
1327 i2c_del_driver(&adt7470_driver);
1328}
1329 1321
1330MODULE_AUTHOR("Darrick J. Wong <djwong@us.ibm.com>"); 1322MODULE_AUTHOR("Darrick J. Wong <djwong@us.ibm.com>");
1331MODULE_DESCRIPTION("ADT7470 driver"); 1323MODULE_DESCRIPTION("ADT7470 driver");
1332MODULE_LICENSE("GPL"); 1324MODULE_LICENSE("GPL");
1333
1334module_init(adt7470_init);
1335module_exit(adt7470_exit);
diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
index 7dab3547fee5..df29d13a5349 100644
--- a/drivers/hwmon/adt7475.c
+++ b/drivers/hwmon/adt7475.c
@@ -32,9 +32,10 @@
32#define THERM 5 32#define THERM 5
33#define HYSTERSIS 6 33#define HYSTERSIS 6
34 34
35/* These are unique identifiers for the sysfs functions - unlike the 35/*
36 numbers above, these are not also indexes into an array 36 * These are unique identifiers for the sysfs functions - unlike the
37*/ 37 * numbers above, these are not also indexes into an array
38 */
38 39
39#define ALARM 9 40#define ALARM 9
40#define FAULT 10 41#define FAULT 10
@@ -288,8 +289,10 @@ static void adt7475_write_word(struct i2c_client *client, int reg, u16 val)
288 i2c_smbus_write_byte_data(client, reg, val & 0xFF); 289 i2c_smbus_write_byte_data(client, reg, val & 0xFF);
289} 290}
290 291
291/* Find the nearest value in a table - used for pwm frequency and 292/*
292 auto temp range */ 293 * Find the nearest value in a table - used for pwm frequency and
294 * auto temp range
295 */
293static int find_nearest(long val, const int *array, int size) 296static int find_nearest(long val, const int *array, int size)
294{ 297{
295 int i; 298 int i;
@@ -385,16 +388,20 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
385 out = (out >> 4) & 0xF; 388 out = (out >> 4) & 0xF;
386 else 389 else
387 out = (out & 0xF); 390 out = (out & 0xF);
388 /* Show the value as an absolute number tied to 391 /*
389 * THERM */ 392 * Show the value as an absolute number tied to
393 * THERM
394 */
390 out = reg2temp(data, data->temp[THERM][sattr->index]) - 395 out = reg2temp(data, data->temp[THERM][sattr->index]) -
391 out * 1000; 396 out * 1000;
392 mutex_unlock(&data->lock); 397 mutex_unlock(&data->lock);
393 break; 398 break;
394 399
395 case OFFSET: 400 case OFFSET:
396 /* Offset is always 2's complement, regardless of the 401 /*
397 * setting in CONFIG5 */ 402 * Offset is always 2's complement, regardless of the
403 * setting in CONFIG5
404 */
398 mutex_lock(&data->lock); 405 mutex_lock(&data->lock);
399 out = (s8)data->temp[sattr->nr][sattr->index]; 406 out = (s8)data->temp[sattr->nr][sattr->index];
400 if (data->config5 & CONFIG5_TEMPOFFSET) 407 if (data->config5 & CONFIG5_TEMPOFFSET)
@@ -452,8 +459,10 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
452 break; 459 break;
453 460
454 case HYSTERSIS: 461 case HYSTERSIS:
455 /* The value will be given as an absolute value, turn it 462 /*
456 into an offset based on THERM */ 463 * The value will be given as an absolute value, turn it
464 * into an offset based on THERM
465 */
457 466
458 /* Read fresh THERM and HYSTERSIS values from the chip */ 467 /* Read fresh THERM and HYSTERSIS values from the chip */
459 data->temp[THERM][sattr->index] = 468 data->temp[THERM][sattr->index] =
@@ -478,8 +487,10 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
478 default: 487 default:
479 data->temp[sattr->nr][sattr->index] = temp2reg(data, val); 488 data->temp[sattr->nr][sattr->index] = temp2reg(data, val);
480 489
481 /* We maintain an extra 2 digits of precision for simplicity 490 /*
482 * - shift those back off before writing the value */ 491 * We maintain an extra 2 digits of precision for simplicity
492 * - shift those back off before writing the value
493 */
483 out = (u8) (data->temp[sattr->nr][sattr->index] >> 2); 494 out = (u8) (data->temp[sattr->nr][sattr->index] >> 2);
484 } 495 }
485 496
@@ -514,8 +525,10 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
514 return count; 525 return count;
515} 526}
516 527
517/* Table of autorange values - the user will write the value in millidegrees, 528/*
518 and we'll convert it */ 529 * Table of autorange values - the user will write the value in millidegrees,
530 * and we'll convert it
531 */
519static const int autorange_table[] = { 532static const int autorange_table[] = {
520 2000, 2500, 3330, 4000, 5000, 6670, 8000, 533 2000, 2500, 3330, 4000, 5000, 6670, 8000,
521 10000, 13330, 16000, 20000, 26670, 32000, 40000, 534 10000, 13330, 16000, 20000, 26670, 32000, 40000,
@@ -558,8 +571,10 @@ static ssize_t set_point2(struct device *dev, struct device_attribute *attr,
558 data->range[sattr->index] = 571 data->range[sattr->index] =
559 adt7475_read(TEMP_TRANGE_REG(sattr->index)); 572 adt7475_read(TEMP_TRANGE_REG(sattr->index));
560 573
561 /* The user will write an absolute value, so subtract the start point 574 /*
562 to figure the range */ 575 * The user will write an absolute value, so subtract the start point
576 * to figure the range
577 */
563 temp = reg2temp(data, data->temp[AUTOMIN][sattr->index]); 578 temp = reg2temp(data, data->temp[AUTOMIN][sattr->index]);
564 val = SENSORS_LIMIT(val, temp + autorange_table[0], 579 val = SENSORS_LIMIT(val, temp + autorange_table[0],
565 temp + autorange_table[ARRAY_SIZE(autorange_table) - 1]); 580 temp + autorange_table[ARRAY_SIZE(autorange_table) - 1]);
@@ -664,8 +679,10 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
664 data->pwm[CONTROL][sattr->index] = 679 data->pwm[CONTROL][sattr->index] =
665 adt7475_read(PWM_CONFIG_REG(sattr->index)); 680 adt7475_read(PWM_CONFIG_REG(sattr->index));
666 681
667 /* If we are not in manual mode, then we shouldn't allow 682 /*
668 * the user to set the pwm speed */ 683 * If we are not in manual mode, then we shouldn't allow
684 * the user to set the pwm speed
685 */
669 if (((data->pwm[CONTROL][sattr->index] >> 5) & 7) != 7) { 686 if (((data->pwm[CONTROL][sattr->index] >> 5) & 7) != 7) {
670 mutex_unlock(&data->lock); 687 mutex_unlock(&data->lock);
671 return count; 688 return count;
@@ -1232,7 +1249,7 @@ static void adt7475_remove_files(struct i2c_client *client,
1232static int adt7475_probe(struct i2c_client *client, 1249static int adt7475_probe(struct i2c_client *client,
1233 const struct i2c_device_id *id) 1250 const struct i2c_device_id *id)
1234{ 1251{
1235 static const char *names[] = { 1252 static const char * const names[] = {
1236 [adt7473] = "ADT7473", 1253 [adt7473] = "ADT7473",
1237 [adt7475] = "ADT7475", 1254 [adt7475] = "ADT7475",
1238 [adt7476] = "ADT7476", 1255 [adt7476] = "ADT7476",
@@ -1280,9 +1297,11 @@ static int adt7475_probe(struct i2c_client *client,
1280 if ((data->config4 & CONFIG4_PINFUNC) == 0x0) 1297 if ((data->config4 & CONFIG4_PINFUNC) == 0x0)
1281 data->has_fan4 = 1; 1298 data->has_fan4 = 1;
1282 1299
1283 /* THERM configuration is more complex on the ADT7476 and ADT7490, 1300 /*
1284 because 2 different pins (TACH4 and +2.5 Vin) can be used for 1301 * THERM configuration is more complex on the ADT7476 and ADT7490,
1285 this function */ 1302 * because 2 different pins (TACH4 and +2.5 Vin) can be used for
1303 * this function
1304 */
1286 if (id->driver_data == adt7490) { 1305 if (id->driver_data == adt7490) {
1287 if ((data->config4 & CONFIG4_PINFUNC) == 0x1 && 1306 if ((data->config4 & CONFIG4_PINFUNC) == 0x1 &&
1288 !(config3 & CONFIG3_THERM)) 1307 !(config3 & CONFIG3_THERM))
@@ -1294,8 +1313,10 @@ static int adt7475_probe(struct i2c_client *client,
1294 data->has_voltage |= (1 << 0); /* in0 */ 1313 data->has_voltage |= (1 << 0); /* in0 */
1295 } 1314 }
1296 1315
1297 /* On the ADT7476, the +12V input pin may instead be used as VID5, 1316 /*
1298 and VID pins may alternatively be used as GPIO */ 1317 * On the ADT7476, the +12V input pin may instead be used as VID5,
1318 * and VID pins may alternatively be used as GPIO
1319 */
1299 if (id->driver_data == adt7476) { 1320 if (id->driver_data == adt7476) {
1300 u8 vid = adt7475_read(REG_VID); 1321 u8 vid = adt7475_read(REG_VID);
1301 if (!(vid & VID_VIDSEL)) 1322 if (!(vid & VID_VIDSEL))
@@ -1314,8 +1335,10 @@ static int adt7475_probe(struct i2c_client *client,
1314 } 1335 }
1315 data->bypass_attn &= data->has_voltage; 1336 data->bypass_attn &= data->has_voltage;
1316 1337
1317 /* Call adt7475_read_pwm for all pwm's as this will reprogram any 1338 /*
1318 pwm's which are disabled to manual mode with 0% duty cycle */ 1339 * Call adt7475_read_pwm for all pwm's as this will reprogram any
1340 * pwm's which are disabled to manual mode with 0% duty cycle
1341 */
1319 for (i = 0; i < ADT7475_PWM_COUNT; i++) 1342 for (i = 0; i < ADT7475_PWM_COUNT; i++)
1320 adt7475_read_pwm(client, i); 1343 adt7475_read_pwm(client, i);
1321 1344
@@ -1431,8 +1454,10 @@ static void adt7475_read_pwm(struct i2c_client *client, int index)
1431 1454
1432 data->pwm[CONTROL][index] = adt7475_read(PWM_CONFIG_REG(index)); 1455 data->pwm[CONTROL][index] = adt7475_read(PWM_CONFIG_REG(index));
1433 1456
1434 /* Figure out the internal value for pwmctrl and pwmchan 1457 /*
1435 based on the current settings */ 1458 * Figure out the internal value for pwmctrl and pwmchan
1459 * based on the current settings
1460 */
1436 v = (data->pwm[CONTROL][index] >> 5) & 7; 1461 v = (data->pwm[CONTROL][index] >> 5) & 7;
1437 1462
1438 if (v == 3) 1463 if (v == 3)
@@ -1440,10 +1465,11 @@ static void adt7475_read_pwm(struct i2c_client *client, int index)
1440 else if (v == 7) 1465 else if (v == 7)
1441 data->pwmctl[index] = 1; 1466 data->pwmctl[index] = 1;
1442 else if (v == 4) { 1467 else if (v == 4) {
1443 /* The fan is disabled - we don't want to 1468 /*
1444 support that, so change to manual mode and 1469 * The fan is disabled - we don't want to
1445 set the duty cycle to 0 instead 1470 * support that, so change to manual mode and
1446 */ 1471 * set the duty cycle to 0 instead
1472 */
1447 data->pwm[INPUT][index] = 0; 1473 data->pwm[INPUT][index] = 0;
1448 data->pwm[CONTROL][index] &= ~0xE0; 1474 data->pwm[CONTROL][index] &= ~0xE0;
1449 data->pwm[CONTROL][index] |= (7 << 5); 1475 data->pwm[CONTROL][index] |= (7 << 5);
@@ -1600,19 +1626,8 @@ static struct adt7475_data *adt7475_update_device(struct device *dev)
1600 return data; 1626 return data;
1601} 1627}
1602 1628
1603static int __init sensors_adt7475_init(void) 1629module_i2c_driver(adt7475_driver);
1604{
1605 return i2c_add_driver(&adt7475_driver);
1606}
1607
1608static void __exit sensors_adt7475_exit(void)
1609{
1610 i2c_del_driver(&adt7475_driver);
1611}
1612 1630
1613MODULE_AUTHOR("Advanced Micro Devices, Inc"); 1631MODULE_AUTHOR("Advanced Micro Devices, Inc");
1614MODULE_DESCRIPTION("adt7475 driver"); 1632MODULE_DESCRIPTION("adt7475 driver");
1615MODULE_LICENSE("GPL"); 1633MODULE_LICENSE("GPL");
1616
1617module_init(sensors_adt7475_init);
1618module_exit(sensors_adt7475_exit);
diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c
index 89a6b9da0ec3..f600fa1f92e3 100644
--- a/drivers/hwmon/amc6821.c
+++ b/drivers/hwmon/amc6821.c
@@ -1,25 +1,25 @@
1/* 1/*
2 amc6821.c - Part of lm_sensors, Linux kernel modules for hardware 2 * amc6821.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 * monitoring
4 Copyright (C) 2009 T. Mertelj <tomaz.mertelj@guest.arnes.si> 4 * Copyright (C) 2009 T. Mertelj <tomaz.mertelj@guest.arnes.si>
5 5 *
6 Based on max6650.c: 6 * Based on max6650.c:
7 Copyright (C) 2007 Hans J. Koch <hjk@hansjkoch.de> 7 * Copyright (C) 2007 Hans J. Koch <hjk@hansjkoch.de>
8 8 *
9 This program is free software; you can redistribute it and/or modify 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 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 11 * the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version. 12 * (at your option) any later version.
13 13 *
14 This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details. 17 * GNU General Public License for more details.
18 18 *
19 You should have received a copy of the GNU General Public License 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 20 * along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22*/ 22 */
23 23
24 24
25#include <linux/kernel.h> /* Needed for KERN_INFO */ 25#include <linux/kernel.h> /* Needed for KERN_INFO */
@@ -47,7 +47,7 @@ static const unsigned short normal_i2c[] = {0x18, 0x19, 0x1a, 0x2c, 0x2d, 0x2e,
47 * Insmod parameters 47 * Insmod parameters
48 */ 48 */
49 49
50static int pwminv = 0; /*Inverted PWM output. */ 50static int pwminv; /*Inverted PWM output. */
51module_param(pwminv, int, S_IRUGO); 51module_param(pwminv, int, S_IRUGO);
52 52
53static int init = 1; /*Power-on initialization.*/ 53static int init = 1; /*Power-on initialization.*/
@@ -188,7 +188,7 @@ static struct i2c_driver amc6821_driver = {
188 188
189/* 189/*
190 * Client data (each client gets its own) 190 * Client data (each client gets its own)
191 */ 191 */
192 192
193struct amc6821_data { 193struct amc6821_data {
194 struct device *hwmon_dev; 194 struct device *hwmon_dev;
@@ -836,8 +836,10 @@ static int amc6821_detect(
836 return -ENODEV; 836 return -ENODEV;
837 } 837 }
838 838
839 /* Bit 7 of the address register is ignored, so we can check the 839 /*
840 ID registers again */ 840 * Bit 7 of the address register is ignored, so we can check the
841 * ID registers again
842 */
841 dev_id = i2c_smbus_read_byte_data(client, 0x80 | AMC6821_REG_DEV_ID); 843 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); 844 comp_id = i2c_smbus_read_byte_data(client, 0x80 | AMC6821_REG_COMP_ID);
843 if (dev_id != 0x21 || comp_id != 0x49) { 845 if (dev_id != 0x21 || comp_id != 0x49) {
@@ -1080,9 +1082,10 @@ static struct amc6821_data *amc6821_update_device(struct device *dev)
1080 data->pwm1_auto_channels_temp = 3; 1082 data->pwm1_auto_channels_temp = 3;
1081 data->pwm1_enable = 3; 1083 data->pwm1_enable = 3;
1082 break; 1084 break;
1083 case 1: /*semi-open loop: software sets rpm, chip controls pwm1, 1085 case 1: /*
1084 *currently not implemented 1086 * semi-open loop: software sets rpm, chip controls
1085 */ 1087 * pwm1, currently not implemented
1088 */
1086 data->pwm1_auto_channels_temp = 0; 1089 data->pwm1_auto_channels_temp = 0;
1087 data->pwm1_enable = 0; 1090 data->pwm1_enable = 0;
1088 break; 1091 break;
@@ -1095,20 +1098,7 @@ static struct amc6821_data *amc6821_update_device(struct device *dev)
1095 return data; 1098 return data;
1096} 1099}
1097 1100
1098 1101module_i2c_driver(amc6821_driver);
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 1102
1113MODULE_LICENSE("GPL"); 1103MODULE_LICENSE("GPL");
1114MODULE_AUTHOR("T. Mertelj <tomaz.mertelj@guest.arnes.si>"); 1104MODULE_AUTHOR("T. Mertelj <tomaz.mertelj@guest.arnes.si>");
diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
index b9895531240d..f082e48ab113 100644
--- a/drivers/hwmon/applesmc.c
+++ b/drivers/hwmon/applesmc.c
@@ -344,8 +344,10 @@ static int applesmc_get_lower_bound(unsigned int *lo, const char *key)
344 while (begin != end) { 344 while (begin != end) {
345 int middle = begin + (end - begin) / 2; 345 int middle = begin + (end - begin) / 2;
346 entry = applesmc_get_entry_by_index(middle); 346 entry = applesmc_get_entry_by_index(middle);
347 if (IS_ERR(entry)) 347 if (IS_ERR(entry)) {
348 *lo = 0;
348 return PTR_ERR(entry); 349 return PTR_ERR(entry);
350 }
349 if (strcmp(entry->key, key) < 0) 351 if (strcmp(entry->key, key) < 0)
350 begin = middle + 1; 352 begin = middle + 1;
351 else 353 else
@@ -364,8 +366,10 @@ static int applesmc_get_upper_bound(unsigned int *hi, const char *key)
364 while (begin != end) { 366 while (begin != end) {
365 int middle = begin + (end - begin) / 2; 367 int middle = begin + (end - begin) / 2;
366 entry = applesmc_get_entry_by_index(middle); 368 entry = applesmc_get_entry_by_index(middle);
367 if (IS_ERR(entry)) 369 if (IS_ERR(entry)) {
370 *hi = smcreg.key_count;
368 return PTR_ERR(entry); 371 return PTR_ERR(entry);
372 }
369 if (strcmp(key, entry->key) < 0) 373 if (strcmp(key, entry->key) < 0)
370 end = middle; 374 end = middle;
371 else 375 else
@@ -1189,8 +1193,10 @@ static int applesmc_dmi_match(const struct dmi_system_id *id)
1189 return 1; 1193 return 1;
1190} 1194}
1191 1195
1192/* Note that DMI_MATCH(...,"MacBook") will match "MacBookPro1,1". 1196/*
1193 * So we need to put "Apple MacBook Pro" before "Apple MacBook". */ 1197 * Note that DMI_MATCH(...,"MacBook") will match "MacBookPro1,1".
1198 * So we need to put "Apple MacBook Pro" before "Apple MacBook".
1199 */
1194static __initdata struct dmi_system_id applesmc_whitelist[] = { 1200static __initdata struct dmi_system_id applesmc_whitelist[] = {
1195 { applesmc_dmi_match, "Apple MacBook Air", { 1201 { applesmc_dmi_match, "Apple MacBook Air", {
1196 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1202 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
diff --git a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c
index d7bd1f3f2a31..4b8814deabb1 100644
--- a/drivers/hwmon/asb100.c
+++ b/drivers/hwmon/asb100.c
@@ -1,40 +1,40 @@
1/* 1/*
2 asb100.c - Part of lm_sensors, Linux kernel modules for hardware 2 * asb100.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 * monitoring
4 4 *
5 Copyright (C) 2004 Mark M. Hoffman <mhoffman@lightlink.com> 5 * Copyright (C) 2004 Mark M. Hoffman <mhoffman@lightlink.com>
6 6 *
7 (derived from w83781d.c) 7 * (derived from w83781d.c)
8 8 *
9 Copyright (C) 1998 - 2003 Frodo Looijaard <frodol@dds.nl>, 9 * Copyright (C) 1998 - 2003 Frodo Looijaard <frodol@dds.nl>,
10 Philip Edelbrock <phil@netroedge.com>, and 10 * Philip Edelbrock <phil@netroedge.com>, and
11 Mark Studebaker <mdsxyz123@yahoo.com> 11 * Mark Studebaker <mdsxyz123@yahoo.com>
12 12 *
13 This program is free software; you can redistribute it and/or modify 13 * This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by 14 * it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or 15 * the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version. 16 * (at your option) any later version.
17 17 *
18 This program is distributed in the hope that it will be useful, 18 * This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details. 21 * GNU General Public License for more details.
22 22 *
23 You should have received a copy of the GNU General Public License 23 * You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 24 * along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26*/ 26 */
27 27
28/* 28/*
29 This driver supports the hardware sensor chips: Asus ASB100 and 29 * This driver supports the hardware sensor chips: Asus ASB100 and
30 ASB100-A "BACH". 30 * ASB100-A "BACH".
31 31 *
32 ASB100-A supports pwm1, while plain ASB100 does not. There is no known 32 * ASB100-A supports pwm1, while plain ASB100 does not. There is no known
33 way for the driver to tell which one is there. 33 * way for the driver to tell which one is there.
34 34 *
35 Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA 35 * Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
36 asb100 7 3 1 4 0x31 0x0694 yes no 36 * asb100 7 3 1 4 0x31 0x0694 yes no
37*/ 37 */
38 38
39#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 39#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
40 40
@@ -99,15 +99,19 @@ static const u16 asb100_reg_temp_hyst[] = {0, 0x3a, 0x153, 0x253, 0x19};
99/* bit 7 -> enable, bits 0-3 -> duty cycle */ 99/* bit 7 -> enable, bits 0-3 -> duty cycle */
100#define ASB100_REG_PWM1 0x59 100#define ASB100_REG_PWM1 0x59
101 101
102/* CONVERSIONS 102/*
103 Rounding and limit checking is only done on the TO_REG variants. */ 103 * CONVERSIONS
104 * Rounding and limit checking is only done on the TO_REG variants.
105 */
104 106
105/* These constants are a guess, consistent w/ w83781d */ 107/* These constants are a guess, consistent w/ w83781d */
106#define ASB100_IN_MIN ( 0) 108#define ASB100_IN_MIN 0
107#define ASB100_IN_MAX (4080) 109#define ASB100_IN_MAX 4080
108 110
109/* IN: 1/1000 V (0V to 4.08V) 111/*
110 REG: 16mV/bit */ 112 * IN: 1/1000 V (0V to 4.08V)
113 * REG: 16mV/bit
114 */
111static u8 IN_TO_REG(unsigned val) 115static u8 IN_TO_REG(unsigned val)
112{ 116{
113 unsigned nval = SENSORS_LIMIT(val, ASB100_IN_MIN, ASB100_IN_MAX); 117 unsigned nval = SENSORS_LIMIT(val, ASB100_IN_MIN, ASB100_IN_MAX);
@@ -131,19 +135,21 @@ static u8 FAN_TO_REG(long rpm, int div)
131 135
132static int FAN_FROM_REG(u8 val, int div) 136static int FAN_FROM_REG(u8 val, int div)
133{ 137{
134 return val==0 ? -1 : val==255 ? 0 : 1350000/(val*div); 138 return val == 0 ? -1 : val == 255 ? 0 : 1350000 / (val * div);
135} 139}
136 140
137/* These constants are a guess, consistent w/ w83781d */ 141/* These constants are a guess, consistent w/ w83781d */
138#define ASB100_TEMP_MIN (-128000) 142#define ASB100_TEMP_MIN -128000
139#define ASB100_TEMP_MAX ( 127000) 143#define ASB100_TEMP_MAX 127000
140 144
141/* TEMP: 0.001C/bit (-128C to +127C) 145/*
142 REG: 1C/bit, two's complement */ 146 * TEMP: 0.001C/bit (-128C to +127C)
147 * REG: 1C/bit, two's complement
148 */
143static u8 TEMP_TO_REG(long temp) 149static u8 TEMP_TO_REG(long temp)
144{ 150{
145 int ntemp = SENSORS_LIMIT(temp, ASB100_TEMP_MIN, ASB100_TEMP_MAX); 151 int ntemp = SENSORS_LIMIT(temp, ASB100_TEMP_MIN, ASB100_TEMP_MAX);
146 ntemp += (ntemp<0 ? -500 : 500); 152 ntemp += (ntemp < 0 ? -500 : 500);
147 return (u8)(ntemp / 1000); 153 return (u8)(ntemp / 1000);
148} 154}
149 155
@@ -152,8 +158,10 @@ static int TEMP_FROM_REG(u8 reg)
152 return (s8)reg * 1000; 158 return (s8)reg * 1000;
153} 159}
154 160
155/* PWM: 0 - 255 per sensors documentation 161/*
156 REG: (6.25% duty cycle per bit) */ 162 * PWM: 0 - 255 per sensors documentation
163 * REG: (6.25% duty cycle per bit)
164 */
157static u8 ASB100_PWM_TO_REG(int pwm) 165static u8 ASB100_PWM_TO_REG(int pwm)
158{ 166{
159 pwm = SENSORS_LIMIT(pwm, 0, 255); 167 pwm = SENSORS_LIMIT(pwm, 0, 255);
@@ -167,16 +175,20 @@ static int ASB100_PWM_FROM_REG(u8 reg)
167 175
168#define DIV_FROM_REG(val) (1 << (val)) 176#define DIV_FROM_REG(val) (1 << (val))
169 177
170/* FAN DIV: 1, 2, 4, or 8 (defaults to 2) 178/*
171 REG: 0, 1, 2, or 3 (respectively) (defaults to 1) */ 179 * FAN DIV: 1, 2, 4, or 8 (defaults to 2)
180 * REG: 0, 1, 2, or 3 (respectively) (defaults to 1)
181 */
172static u8 DIV_TO_REG(long val) 182static u8 DIV_TO_REG(long val)
173{ 183{
174 return val==8 ? 3 : val==4 ? 2 : val==1 ? 0 : 1; 184 return val == 8 ? 3 : val == 4 ? 2 : val == 1 ? 0 : 1;
175} 185}
176 186
177/* For each registered client, we need to keep some data in memory. That 187/*
178 data is pointed to by client->data. The structure itself is 188 * For each registered client, we need to keep some data in memory. That
179 dynamically allocated, at the same time the client itself is allocated. */ 189 * data is pointed to by client->data. The structure itself is
190 * dynamically allocated, at the same time the client itself is allocated.
191 */
180struct asb100_data { 192struct asb100_data {
181 struct device *hwmon_dev; 193 struct device *hwmon_dev;
182 struct mutex lock; 194 struct mutex lock;
@@ -253,8 +265,10 @@ static ssize_t set_in_##reg(struct device *dev, struct device_attribute *attr, \
253 int nr = to_sensor_dev_attr(attr)->index; \ 265 int nr = to_sensor_dev_attr(attr)->index; \
254 struct i2c_client *client = to_i2c_client(dev); \ 266 struct i2c_client *client = to_i2c_client(dev); \
255 struct asb100_data *data = i2c_get_clientdata(client); \ 267 struct asb100_data *data = i2c_get_clientdata(client); \
256 unsigned long val = simple_strtoul(buf, NULL, 10); \ 268 unsigned long val; \
257 \ 269 int err = kstrtoul(buf, 10, &val); \
270 if (err) \
271 return err; \
258 mutex_lock(&data->update_lock); \ 272 mutex_lock(&data->update_lock); \
259 data->in_##reg[nr] = IN_TO_REG(val); \ 273 data->in_##reg[nr] = IN_TO_REG(val); \
260 asb100_write_value(client, ASB100_REG_IN_##REG(nr), \ 274 asb100_write_value(client, ASB100_REG_IN_##REG(nr), \
@@ -315,7 +329,12 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
315 int nr = to_sensor_dev_attr(attr)->index; 329 int nr = to_sensor_dev_attr(attr)->index;
316 struct i2c_client *client = to_i2c_client(dev); 330 struct i2c_client *client = to_i2c_client(dev);
317 struct asb100_data *data = i2c_get_clientdata(client); 331 struct asb100_data *data = i2c_get_clientdata(client);
318 u32 val = simple_strtoul(buf, NULL, 10); 332 unsigned long val;
333 int err;
334
335 err = kstrtoul(buf, 10, &val);
336 if (err)
337 return err;
319 338
320 mutex_lock(&data->update_lock); 339 mutex_lock(&data->update_lock);
321 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 340 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
@@ -324,10 +343,12 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
324 return count; 343 return count;
325} 344}
326 345
327/* Note: we save and restore the fan minimum here, because its value is 346/*
328 determined in part by the fan divisor. This follows the principle of 347 * Note: we save and restore the fan minimum here, because its value is
329 least surprise; the user doesn't expect the fan minimum to change just 348 * determined in part by the fan divisor. This follows the principle of
330 because the divisor changed. */ 349 * least surprise; the user doesn't expect the fan minimum to change just
350 * because the divisor changed.
351 */
331static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, 352static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
332 const char *buf, size_t count) 353 const char *buf, size_t count)
333{ 354{
@@ -335,8 +356,13 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
335 struct i2c_client *client = to_i2c_client(dev); 356 struct i2c_client *client = to_i2c_client(dev);
336 struct asb100_data *data = i2c_get_clientdata(client); 357 struct asb100_data *data = i2c_get_clientdata(client);
337 unsigned long min; 358 unsigned long min;
338 unsigned long val = simple_strtoul(buf, NULL, 10);
339 int reg; 359 int reg;
360 unsigned long val;
361 int err;
362
363 err = kstrtoul(buf, 10, &val);
364 if (err)
365 return err;
340 366
341 mutex_lock(&data->update_lock); 367 mutex_lock(&data->update_lock);
342 368
@@ -421,8 +447,10 @@ static ssize_t set_##reg(struct device *dev, struct device_attribute *attr, \
421 int nr = to_sensor_dev_attr(attr)->index; \ 447 int nr = to_sensor_dev_attr(attr)->index; \
422 struct i2c_client *client = to_i2c_client(dev); \ 448 struct i2c_client *client = to_i2c_client(dev); \
423 struct asb100_data *data = i2c_get_clientdata(client); \ 449 struct asb100_data *data = i2c_get_clientdata(client); \
424 long val = simple_strtol(buf, NULL, 10); \ 450 long val; \
425 \ 451 int err = kstrtol(buf, 10, &val); \
452 if (err) \
453 return err; \
426 mutex_lock(&data->update_lock); \ 454 mutex_lock(&data->update_lock); \
427 switch (nr) { \ 455 switch (nr) { \
428 case 1: case 2: \ 456 case 1: case 2: \
@@ -476,7 +504,13 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
476 const char *buf, size_t count) 504 const char *buf, size_t count)
477{ 505{
478 struct asb100_data *data = dev_get_drvdata(dev); 506 struct asb100_data *data = dev_get_drvdata(dev);
479 data->vrm = simple_strtoul(buf, NULL, 10); 507 unsigned long val;
508 int err;
509
510 err = kstrtoul(buf, 10, &val);
511 if (err)
512 return err;
513 data->vrm = val;
480 return count; 514 return count;
481} 515}
482 516
@@ -524,7 +558,12 @@ static ssize_t set_pwm1(struct device *dev, struct device_attribute *attr,
524{ 558{
525 struct i2c_client *client = to_i2c_client(dev); 559 struct i2c_client *client = to_i2c_client(dev);
526 struct asb100_data *data = i2c_get_clientdata(client); 560 struct asb100_data *data = i2c_get_clientdata(client);
527 unsigned long val = simple_strtoul(buf, NULL, 10); 561 unsigned long val;
562 int err;
563
564 err = kstrtoul(buf, 10, &val);
565 if (err)
566 return err;
528 567
529 mutex_lock(&data->update_lock); 568 mutex_lock(&data->update_lock);
530 data->pwm &= 0x80; /* keep the enable bit */ 569 data->pwm &= 0x80; /* keep the enable bit */
@@ -546,7 +585,12 @@ static ssize_t set_pwm_enable1(struct device *dev,
546{ 585{
547 struct i2c_client *client = to_i2c_client(dev); 586 struct i2c_client *client = to_i2c_client(dev);
548 struct asb100_data *data = i2c_get_clientdata(client); 587 struct asb100_data *data = i2c_get_clientdata(client);
549 unsigned long val = simple_strtoul(buf, NULL, 10); 588 unsigned long val;
589 int err;
590
591 err = kstrtoul(buf, 10, &val);
592 if (err)
593 return err;
550 594
551 mutex_lock(&data->update_lock); 595 mutex_lock(&data->update_lock);
552 data->pwm &= 0x0f; /* keep the duty cycle bits */ 596 data->pwm &= 0x0f; /* keep the duty cycle bits */
@@ -768,7 +812,8 @@ static int asb100_probe(struct i2c_client *client,
768 data->fan_min[2] = asb100_read_value(client, ASB100_REG_FAN_MIN(2)); 812 data->fan_min[2] = asb100_read_value(client, ASB100_REG_FAN_MIN(2));
769 813
770 /* Register sysfs hooks */ 814 /* Register sysfs hooks */
771 if ((err = sysfs_create_group(&client->dev.kobj, &asb100_group))) 815 err = sysfs_create_group(&client->dev.kobj, &asb100_group);
816 if (err)
772 goto ERROR3; 817 goto ERROR3;
773 818
774 data->hwmon_dev = hwmon_device_register(&client->dev); 819 data->hwmon_dev = hwmon_device_register(&client->dev);
@@ -805,8 +850,10 @@ static int asb100_remove(struct i2c_client *client)
805 return 0; 850 return 0;
806} 851}
807 852
808/* The SMBus locks itself, usually, but nothing may access the chip between 853/*
809 bank switches. */ 854 * The SMBus locks itself, usually, but nothing may access the chip between
855 * bank switches.
856 */
810static int asb100_read_value(struct i2c_client *client, u16 reg) 857static int asb100_read_value(struct i2c_client *client, u16 reg)
811{ 858{
812 struct asb100_data *data = i2c_get_clientdata(client); 859 struct asb100_data *data = i2c_get_clientdata(client);
@@ -971,19 +1018,8 @@ static struct asb100_data *asb100_update_device(struct device *dev)
971 return data; 1018 return data;
972} 1019}
973 1020
974static int __init asb100_init(void) 1021module_i2c_driver(asb100_driver);
975{
976 return i2c_add_driver(&asb100_driver);
977}
978
979static void __exit asb100_exit(void)
980{
981 i2c_del_driver(&asb100_driver);
982}
983 1022
984MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>"); 1023MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>");
985MODULE_DESCRIPTION("ASB100 Bach driver"); 1024MODULE_DESCRIPTION("ASB100 Bach driver");
986MODULE_LICENSE("GPL"); 1025MODULE_LICENSE("GPL");
987
988module_init(asb100_init);
989module_exit(asb100_exit);
diff --git a/drivers/hwmon/asc7621.c b/drivers/hwmon/asc7621.c
index 3efd32449982..7caa242915a6 100644
--- a/drivers/hwmon/asc7621.c
+++ b/drivers/hwmon/asc7621.c
@@ -268,9 +268,11 @@ static ssize_t store_fan16(struct device *dev,
268 if (kstrtol(buf, 10, &reqval)) 268 if (kstrtol(buf, 10, &reqval))
269 return -EINVAL; 269 return -EINVAL;
270 270
271 /* If a minimum RPM of zero is requested, then we set the register to 271 /*
272 0xffff. This value allows the fan to be stopped completely without 272 * If a minimum RPM of zero is requested, then we set the register to
273 generating an alarm. */ 273 * 0xffff. This value allows the fan to be stopped completely without
274 * generating an alarm.
275 */
274 reqval = 276 reqval =
275 (reqval <= 0 ? 0xffff : SENSORS_LIMIT(5400000 / reqval, 0, 0xfffe)); 277 (reqval <= 0 ? 0xffff : SENSORS_LIMIT(5400000 / reqval, 0, 0xfffe));
276 278
diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
index 00e98517f94c..351d1f4593e7 100644
--- a/drivers/hwmon/asus_atk0110.c
+++ b/drivers/hwmon/asus_atk0110.c
@@ -38,7 +38,8 @@ static const struct dmi_system_id __initconst atk_force_new_if[] = {
38 { } 38 { }
39}; 39};
40 40
41/* Minimum time between readings, enforced in order to avoid 41/*
42 * Minimum time between readings, enforced in order to avoid
42 * hogging the CPU. 43 * hogging the CPU.
43 */ 44 */
44#define CACHE_TIME HZ 45#define CACHE_TIME HZ
@@ -161,7 +162,8 @@ struct atk_sensor_data {
161 char const *acpi_name; 162 char const *acpi_name;
162}; 163};
163 164
164/* Return buffer format: 165/*
166 * Return buffer format:
165 * [0-3] "value" is valid flag 167 * [0-3] "value" is valid flag
166 * [4-7] value 168 * [4-7] value
167 * [8- ] unknown stuff on newer mobos 169 * [8- ] unknown stuff on newer mobos
@@ -310,7 +312,8 @@ static union acpi_object *atk_get_pack_member(struct atk_data *data,
310} 312}
311 313
312 314
313/* New package format is: 315/*
316 * New package format is:
314 * - flag (int) 317 * - flag (int)
315 * class - used for de-muxing the request to the correct GITn 318 * class - used for de-muxing the request to the correct GITn
316 * type (volt, temp, fan) 319 * type (volt, temp, fan)
@@ -613,7 +616,8 @@ static int atk_read_value_new(struct atk_sensor_data *sensor, u64 *value)
613 616
614 buf = (struct atk_acpi_ret_buffer *)obj->buffer.pointer; 617 buf = (struct atk_acpi_ret_buffer *)obj->buffer.pointer;
615 if (buf->flags == 0) { 618 if (buf->flags == 0) {
616 /* The reading is not valid, possible causes: 619 /*
620 * The reading is not valid, possible causes:
617 * - sensor failure 621 * - sensor failure
618 * - enumeration was FUBAR (and we didn't notice) 622 * - enumeration was FUBAR (and we didn't notice)
619 */ 623 */
@@ -1311,14 +1315,16 @@ static int atk_probe_if(struct atk_data *data)
1311 dev_dbg(dev, "method " METHOD_WRITE " not found: %s\n", 1315 dev_dbg(dev, "method " METHOD_WRITE " not found: %s\n",
1312 acpi_format_exception(status)); 1316 acpi_format_exception(status));
1313 1317
1314 /* Check for hwmon methods: first check "old" style methods; note that 1318 /*
1319 * Check for hwmon methods: first check "old" style methods; note that
1315 * both may be present: in this case we stick to the old interface; 1320 * both may be present: in this case we stick to the old interface;
1316 * analysis of multiple DSDTs indicates that when both interfaces 1321 * analysis of multiple DSDTs indicates that when both interfaces
1317 * are present the new one (GGRP/GITM) is not functional. 1322 * are present the new one (GGRP/GITM) is not functional.
1318 */ 1323 */
1319 if (new_if) 1324 if (new_if)
1320 dev_info(dev, "Overriding interface detection\n"); 1325 dev_info(dev, "Overriding interface detection\n");
1321 if (data->rtmp_handle && data->rvlt_handle && data->rfan_handle && !new_if) 1326 if (data->rtmp_handle &&
1327 data->rvlt_handle && data->rfan_handle && !new_if)
1322 data->old_interface = true; 1328 data->old_interface = true;
1323 else if (data->enumerate_handle && data->read_handle && 1329 else if (data->enumerate_handle && data->read_handle &&
1324 data->write_handle) 1330 data->write_handle)
diff --git a/drivers/hwmon/atxp1.c b/drivers/hwmon/atxp1.c
index 33cc143b2069..58af6aa93530 100644
--- a/drivers/hwmon/atxp1.c
+++ b/drivers/hwmon/atxp1.c
@@ -1,22 +1,22 @@
1/* 1/*
2 atxp1.c - kernel module for setting CPU VID and general purpose 2 * atxp1.c - kernel module for setting CPU VID and general purpose
3 I/Os using the Attansic ATXP1 chip. 3 * I/Os using the Attansic ATXP1 chip.
4 4 *
5 This program is free software; you can redistribute it and/or modify 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 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 7 * the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 * (at your option) any later version.
9 9 *
10 This program is distributed in the hope that it will be useful, 10 * This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 * GNU General Public License for more details.
14 14 *
15 You should have received a copy of the GNU General Public License 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 16 * along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 18 *
19*/ 19 */
20 20
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/init.h> 22#include <linux/init.h>
@@ -48,7 +48,7 @@ static const unsigned short normal_i2c[] = { 0x37, 0x4e, I2C_CLIENT_END };
48static int atxp1_probe(struct i2c_client *client, 48static int atxp1_probe(struct i2c_client *client,
49 const struct i2c_device_id *id); 49 const struct i2c_device_id *id);
50static int atxp1_remove(struct i2c_client *client); 50static int atxp1_remove(struct i2c_client *client);
51static struct atxp1_data * atxp1_update_device(struct device *dev); 51static struct atxp1_data *atxp1_update_device(struct device *dev);
52static int atxp1_detect(struct i2c_client *client, struct i2c_board_info *info); 52static int atxp1_detect(struct i2c_client *client, struct i2c_board_info *info);
53 53
54static const struct i2c_device_id atxp1_id[] = { 54static const struct i2c_device_id atxp1_id[] = {
@@ -83,7 +83,7 @@ struct atxp1_data {
83 u8 vrm; /* Detected CPU VRM */ 83 u8 vrm; /* Detected CPU VRM */
84}; 84};
85 85
86static struct atxp1_data * atxp1_update_device(struct device *dev) 86static struct atxp1_data *atxp1_update_device(struct device *dev)
87{ 87{
88 struct i2c_client *client; 88 struct i2c_client *client;
89 struct atxp1_data *data; 89 struct atxp1_data *data;
@@ -97,7 +97,8 @@ static struct atxp1_data * atxp1_update_device(struct device *dev)
97 97
98 /* Update local register data */ 98 /* Update local register data */
99 data->reg.vid = i2c_smbus_read_byte_data(client, ATXP1_VID); 99 data->reg.vid = i2c_smbus_read_byte_data(client, ATXP1_VID);
100 data->reg.cpu_vid = i2c_smbus_read_byte_data(client, ATXP1_CVID); 100 data->reg.cpu_vid = i2c_smbus_read_byte_data(client,
101 ATXP1_CVID);
101 data->reg.gpio1 = i2c_smbus_read_byte_data(client, ATXP1_GPIO1); 102 data->reg.gpio1 = i2c_smbus_read_byte_data(client, ATXP1_GPIO1);
102 data->reg.gpio2 = i2c_smbus_read_byte_data(client, ATXP1_GPIO2); 103 data->reg.gpio2 = i2c_smbus_read_byte_data(client, ATXP1_GPIO2);
103 104
@@ -106,33 +107,41 @@ static struct atxp1_data * atxp1_update_device(struct device *dev)
106 107
107 mutex_unlock(&data->update_lock); 108 mutex_unlock(&data->update_lock);
108 109
109 return(data); 110 return data;
110} 111}
111 112
112/* sys file functions for cpu0_vid */ 113/* sys file functions for cpu0_vid */
113static ssize_t atxp1_showvcore(struct device *dev, struct device_attribute *attr, char *buf) 114static ssize_t atxp1_showvcore(struct device *dev,
115 struct device_attribute *attr, char *buf)
114{ 116{
115 int size; 117 int size;
116 struct atxp1_data *data; 118 struct atxp1_data *data;
117 119
118 data = atxp1_update_device(dev); 120 data = atxp1_update_device(dev);
119 121
120 size = sprintf(buf, "%d\n", vid_from_reg(data->reg.vid & ATXP1_VIDMASK, data->vrm)); 122 size = sprintf(buf, "%d\n", vid_from_reg(data->reg.vid & ATXP1_VIDMASK,
123 data->vrm));
121 124
122 return size; 125 return size;
123} 126}
124 127
125static ssize_t atxp1_storevcore(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 128static ssize_t atxp1_storevcore(struct device *dev,
129 struct device_attribute *attr,
130 const char *buf, size_t count)
126{ 131{
127 struct atxp1_data *data; 132 struct atxp1_data *data;
128 struct i2c_client *client; 133 struct i2c_client *client;
129 int vid, cvid; 134 int vid, cvid;
130 unsigned int vcore; 135 unsigned long vcore;
136 int err;
131 137
132 client = to_i2c_client(dev); 138 client = to_i2c_client(dev);
133 data = atxp1_update_device(dev); 139 data = atxp1_update_device(dev);
134 140
135 vcore = simple_strtoul(buf, NULL, 10); 141 err = kstrtoul(buf, 10, &vcore);
142 if (err)
143 return err;
144
136 vcore /= 25; 145 vcore /= 25;
137 vcore *= 25; 146 vcore *= 25;
138 147
@@ -144,7 +153,10 @@ static ssize_t atxp1_storevcore(struct device *dev, struct device_attribute *att
144 return -1; 153 return -1;
145 } 154 }
146 155
147 /* If output enabled, use control register value. Otherwise original CPU VID */ 156 /*
157 * If output enabled, use control register value.
158 * Otherwise original CPU VID
159 */
148 if (data->reg.vid & ATXP1_VIDENA) 160 if (data->reg.vid & ATXP1_VIDENA)
149 cvid = data->reg.vid & ATXP1_VIDMASK; 161 cvid = data->reg.vid & ATXP1_VIDMASK;
150 else 162 else
@@ -154,18 +166,17 @@ static ssize_t atxp1_storevcore(struct device *dev, struct device_attribute *att
154 if (vid == cvid) 166 if (vid == cvid)
155 return count; 167 return count;
156 168
157 dev_dbg(dev, "Setting VCore to %d mV (0x%02x)\n", vcore, vid); 169 dev_dbg(dev, "Setting VCore to %d mV (0x%02x)\n", (int)vcore, vid);
158 170
159 /* Write every 25 mV step to increase stability */ 171 /* Write every 25 mV step to increase stability */
160 if (cvid > vid) { 172 if (cvid > vid) {
161 for (; cvid >= vid; cvid--) { 173 for (; cvid >= vid; cvid--)
162 i2c_smbus_write_byte_data(client, ATXP1_VID, cvid | ATXP1_VIDENA); 174 i2c_smbus_write_byte_data(client,
163 } 175 ATXP1_VID, cvid | ATXP1_VIDENA);
164 } 176 } else {
165 else { 177 for (; cvid <= vid; cvid++)
166 for (; cvid <= vid; cvid++) { 178 i2c_smbus_write_byte_data(client,
167 i2c_smbus_write_byte_data(client, ATXP1_VID, cvid | ATXP1_VIDENA); 179 ATXP1_VID, cvid | ATXP1_VIDENA);
168 }
169 } 180 }
170 181
171 data->valid = 0; 182 data->valid = 0;
@@ -173,13 +184,16 @@ static ssize_t atxp1_storevcore(struct device *dev, struct device_attribute *att
173 return count; 184 return count;
174} 185}
175 186
176/* CPU core reference voltage 187/*
177 unit: millivolt 188 * CPU core reference voltage
178*/ 189 * unit: millivolt
179static DEVICE_ATTR(cpu0_vid, S_IRUGO | S_IWUSR, atxp1_showvcore, atxp1_storevcore); 190 */
191static DEVICE_ATTR(cpu0_vid, S_IRUGO | S_IWUSR, atxp1_showvcore,
192 atxp1_storevcore);
180 193
181/* sys file functions for GPIO1 */ 194/* sys file functions for GPIO1 */
182static ssize_t atxp1_showgpio1(struct device *dev, struct device_attribute *attr, char *buf) 195static ssize_t atxp1_showgpio1(struct device *dev,
196 struct device_attribute *attr, char *buf)
183{ 197{
184 int size; 198 int size;
185 struct atxp1_data *data; 199 struct atxp1_data *data;
@@ -191,21 +205,26 @@ static ssize_t atxp1_showgpio1(struct device *dev, struct device_attribute *attr
191 return size; 205 return size;
192} 206}
193 207
194static ssize_t atxp1_storegpio1(struct device *dev, struct device_attribute *attr, const char*buf, size_t count) 208static ssize_t atxp1_storegpio1(struct device *dev,
209 struct device_attribute *attr, const char *buf,
210 size_t count)
195{ 211{
196 struct atxp1_data *data; 212 struct atxp1_data *data;
197 struct i2c_client *client; 213 struct i2c_client *client;
198 unsigned int value; 214 unsigned long value;
215 int err;
199 216
200 client = to_i2c_client(dev); 217 client = to_i2c_client(dev);
201 data = atxp1_update_device(dev); 218 data = atxp1_update_device(dev);
202 219
203 value = simple_strtoul(buf, NULL, 16); 220 err = kstrtoul(buf, 16, &value);
221 if (err)
222 return err;
204 223
205 value &= ATXP1_GPIO1MASK; 224 value &= ATXP1_GPIO1MASK;
206 225
207 if (value != (data->reg.gpio1 & ATXP1_GPIO1MASK)) { 226 if (value != (data->reg.gpio1 & ATXP1_GPIO1MASK)) {
208 dev_info(dev, "Writing 0x%x to GPIO1.\n", value); 227 dev_info(dev, "Writing 0x%x to GPIO1.\n", (unsigned int)value);
209 228
210 i2c_smbus_write_byte_data(client, ATXP1_GPIO1, value); 229 i2c_smbus_write_byte_data(client, ATXP1_GPIO1, value);
211 230
@@ -215,13 +234,15 @@ static ssize_t atxp1_storegpio1(struct device *dev, struct device_attribute *att
215 return count; 234 return count;
216} 235}
217 236
218/* GPIO1 data register 237/*
219 unit: Four bit as hex (e.g. 0x0f) 238 * GPIO1 data register
220*/ 239 * unit: Four bit as hex (e.g. 0x0f)
240 */
221static DEVICE_ATTR(gpio1, S_IRUGO | S_IWUSR, atxp1_showgpio1, atxp1_storegpio1); 241static DEVICE_ATTR(gpio1, S_IRUGO | S_IWUSR, atxp1_showgpio1, atxp1_storegpio1);
222 242
223/* sys file functions for GPIO2 */ 243/* sys file functions for GPIO2 */
224static ssize_t atxp1_showgpio2(struct device *dev, struct device_attribute *attr, char *buf) 244static ssize_t atxp1_showgpio2(struct device *dev,
245 struct device_attribute *attr, char *buf)
225{ 246{
226 int size; 247 int size;
227 struct atxp1_data *data; 248 struct atxp1_data *data;
@@ -233,19 +254,22 @@ static ssize_t atxp1_showgpio2(struct device *dev, struct device_attribute *attr
233 return size; 254 return size;
234} 255}
235 256
236static ssize_t atxp1_storegpio2(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 257static ssize_t atxp1_storegpio2(struct device *dev,
258 struct device_attribute *attr,
259 const char *buf, size_t count)
237{ 260{
238 struct atxp1_data *data; 261 struct atxp1_data *data = atxp1_update_device(dev);
239 struct i2c_client *client; 262 struct i2c_client *client = to_i2c_client(dev);
240 unsigned int value; 263 unsigned long value;
241 264 int err;
242 client = to_i2c_client(dev);
243 data = atxp1_update_device(dev);
244 265
245 value = simple_strtoul(buf, NULL, 16) & 0xff; 266 err = kstrtoul(buf, 16, &value);
267 if (err)
268 return err;
269 value &= 0xff;
246 270
247 if (value != data->reg.gpio2) { 271 if (value != data->reg.gpio2) {
248 dev_info(dev, "Writing 0x%x to GPIO1.\n", value); 272 dev_info(dev, "Writing 0x%x to GPIO1.\n", (unsigned int)value);
249 273
250 i2c_smbus_write_byte_data(client, ATXP1_GPIO2, value); 274 i2c_smbus_write_byte_data(client, ATXP1_GPIO2, value);
251 275
@@ -255,9 +279,10 @@ static ssize_t atxp1_storegpio2(struct device *dev, struct device_attribute *att
255 return count; 279 return count;
256} 280}
257 281
258/* GPIO2 data register 282/*
259 unit: Eight bit as hex (e.g. 0xff) 283 * GPIO2 data register
260*/ 284 * unit: Eight bit as hex (e.g. 0xff)
285 */
261static DEVICE_ATTR(gpio2, S_IRUGO | S_IWUSR, atxp1_showgpio2, atxp1_storegpio2); 286static DEVICE_ATTR(gpio2, S_IRUGO | S_IWUSR, atxp1_showgpio2, atxp1_storegpio2);
262 287
263static struct attribute *atxp1_attributes[] = { 288static struct attribute *atxp1_attributes[] = {
@@ -290,8 +315,10 @@ static int atxp1_detect(struct i2c_client *new_client,
290 (i2c_smbus_read_byte_data(new_client, 0xff) == 0))) 315 (i2c_smbus_read_byte_data(new_client, 0xff) == 0)))
291 return -ENODEV; 316 return -ENODEV;
292 317
293 /* No vendor ID, now checking if registers 0x10,0x11 (non-existent) 318 /*
294 * showing the same as register 0x00 */ 319 * No vendor ID, now checking if registers 0x10,0x11 (non-existent)
320 * showing the same as register 0x00
321 */
295 temp = i2c_smbus_read_byte_data(new_client, 0x00); 322 temp = i2c_smbus_read_byte_data(new_client, 0x00);
296 323
297 if (!((i2c_smbus_read_byte_data(new_client, 0x10) == temp) && 324 if (!((i2c_smbus_read_byte_data(new_client, 0x10) == temp) &&
@@ -333,7 +360,8 @@ static int atxp1_probe(struct i2c_client *new_client,
333 mutex_init(&data->update_lock); 360 mutex_init(&data->update_lock);
334 361
335 /* Register sysfs hooks */ 362 /* Register sysfs hooks */
336 if ((err = sysfs_create_group(&new_client->dev.kobj, &atxp1_group))) 363 err = sysfs_create_group(&new_client->dev.kobj, &atxp1_group);
364 if (err)
337 goto exit_free; 365 goto exit_free;
338 366
339 data->hwmon_dev = hwmon_device_register(&new_client->dev); 367 data->hwmon_dev = hwmon_device_register(&new_client->dev);
@@ -357,7 +385,7 @@ exit:
357 385
358static int atxp1_remove(struct i2c_client *client) 386static int atxp1_remove(struct i2c_client *client)
359{ 387{
360 struct atxp1_data * data = i2c_get_clientdata(client); 388 struct atxp1_data *data = i2c_get_clientdata(client);
361 389
362 hwmon_device_unregister(data->hwmon_dev); 390 hwmon_device_unregister(data->hwmon_dev);
363 sysfs_remove_group(&client->dev.kobj, &atxp1_group); 391 sysfs_remove_group(&client->dev.kobj, &atxp1_group);
@@ -367,15 +395,4 @@ static int atxp1_remove(struct i2c_client *client)
367 return 0; 395 return 0;
368}; 396};
369 397
370static int __init atxp1_init(void) 398module_i2c_driver(atxp1_driver);
371{
372 return i2c_add_driver(&atxp1_driver);
373};
374
375static void __exit atxp1_exit(void)
376{
377 i2c_del_driver(&atxp1_driver);
378};
379
380module_init(atxp1_init);
381module_exit(atxp1_exit);
diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
index 249ac460e3d9..0d3141fbbc20 100644
--- a/drivers/hwmon/coretemp.c
+++ b/drivers/hwmon/coretemp.c
@@ -58,8 +58,8 @@ MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius");
58#define TOTAL_ATTRS (MAX_CORE_ATTRS + 1) 58#define TOTAL_ATTRS (MAX_CORE_ATTRS + 1)
59#define MAX_CORE_DATA (NUM_REAL_CORES + BASE_SYSFS_ATTR_NO) 59#define MAX_CORE_DATA (NUM_REAL_CORES + BASE_SYSFS_ATTR_NO)
60 60
61#define TO_PHYS_ID(cpu) cpu_data(cpu).phys_proc_id 61#define TO_PHYS_ID(cpu) (cpu_data(cpu).phys_proc_id)
62#define TO_CORE_ID(cpu) cpu_data(cpu).cpu_core_id 62#define TO_CORE_ID(cpu) (cpu_data(cpu).cpu_core_id)
63#define TO_ATTR_NO(cpu) (TO_CORE_ID(cpu) + BASE_SYSFS_ATTR_NO) 63#define TO_ATTR_NO(cpu) (TO_CORE_ID(cpu) + BASE_SYSFS_ATTR_NO)
64 64
65#ifdef CONFIG_SMP 65#ifdef CONFIG_SMP
diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c
index ffb229af7861..e7c6a19f3b25 100644
--- a/drivers/hwmon/dme1737.c
+++ b/drivers/hwmon/dme1737.c
@@ -82,12 +82,12 @@ enum chips { dme1737, sch5027, sch311x, sch5127 };
82 * --------------------------------------------------------------------- */ 82 * --------------------------------------------------------------------- */
83 83
84/* Voltages (in) numbered 0-7 (ix) */ 84/* Voltages (in) numbered 0-7 (ix) */
85#define DME1737_REG_IN(ix) ((ix) < 5 ? 0x20 + (ix) : \ 85#define DME1737_REG_IN(ix) ((ix) < 5 ? 0x20 + (ix) : \
86 (ix) < 7 ? 0x94 + (ix) : \ 86 (ix) < 7 ? 0x94 + (ix) : \
87 0x1f) 87 0x1f)
88#define DME1737_REG_IN_MIN(ix) ((ix) < 5 ? 0x44 + (ix) * 2 \ 88#define DME1737_REG_IN_MIN(ix) ((ix) < 5 ? 0x44 + (ix) * 2 \
89 : 0x91 + (ix) * 2) 89 : 0x91 + (ix) * 2)
90#define DME1737_REG_IN_MAX(ix) ((ix) < 5 ? 0x45 + (ix) * 2 \ 90#define DME1737_REG_IN_MAX(ix) ((ix) < 5 ? 0x45 + (ix) * 2 \
91 : 0x92 + (ix) * 2) 91 : 0x92 + (ix) * 2)
92 92
93/* Temperatures (temp) numbered 0-2 (ix) */ 93/* Temperatures (temp) numbered 0-2 (ix) */
@@ -97,14 +97,16 @@ enum chips { dme1737, sch5027, sch311x, sch5127 };
97#define DME1737_REG_TEMP_OFFSET(ix) ((ix) == 0 ? 0x1f \ 97#define DME1737_REG_TEMP_OFFSET(ix) ((ix) == 0 ? 0x1f \
98 : 0x1c + (ix)) 98 : 0x1c + (ix))
99 99
100/* Voltage and temperature LSBs 100/*
101 * Voltage and temperature LSBs
101 * The LSBs (4 bits each) are stored in 5 registers with the following layouts: 102 * The LSBs (4 bits each) are stored in 5 registers with the following layouts:
102 * IN_TEMP_LSB(0) = [in5, in6] 103 * IN_TEMP_LSB(0) = [in5, in6]
103 * IN_TEMP_LSB(1) = [temp3, temp1] 104 * IN_TEMP_LSB(1) = [temp3, temp1]
104 * IN_TEMP_LSB(2) = [in4, temp2] 105 * IN_TEMP_LSB(2) = [in4, temp2]
105 * IN_TEMP_LSB(3) = [in3, in0] 106 * IN_TEMP_LSB(3) = [in3, in0]
106 * IN_TEMP_LSB(4) = [in2, in1] 107 * IN_TEMP_LSB(4) = [in2, in1]
107 * IN_TEMP_LSB(5) = [res, in7] */ 108 * IN_TEMP_LSB(5) = [res, in7]
109 */
108#define DME1737_REG_IN_TEMP_LSB(ix) (0x84 + (ix)) 110#define DME1737_REG_IN_TEMP_LSB(ix) (0x84 + (ix))
109static const u8 DME1737_REG_IN_LSB[] = {3, 4, 4, 3, 2, 0, 0, 5}; 111static const u8 DME1737_REG_IN_LSB[] = {3, 4, 4, 3, 2, 0, 0, 5};
110static const u8 DME1737_REG_IN_LSB_SHL[] = {4, 4, 0, 0, 0, 0, 4, 4}; 112static const u8 DME1737_REG_IN_LSB_SHL[] = {4, 4, 0, 0, 0, 0, 4, 4};
@@ -127,24 +129,30 @@ static const u8 DME1737_REG_TEMP_LSB_SHL[] = {4, 4, 0};
127#define DME1737_REG_PWM_MIN(ix) (0x64 + (ix)) /* only for pwm[0-2] */ 129#define DME1737_REG_PWM_MIN(ix) (0x64 + (ix)) /* only for pwm[0-2] */
128#define DME1737_REG_PWM_FREQ(ix) ((ix) < 3 ? 0x5f + (ix) \ 130#define DME1737_REG_PWM_FREQ(ix) ((ix) < 3 ? 0x5f + (ix) \
129 : 0xa3 + (ix)) 131 : 0xa3 + (ix))
130/* The layout of the ramp rate registers is different from the other pwm 132/*
133 * The layout of the ramp rate registers is different from the other pwm
131 * registers. The bits for the 3 PWMs are stored in 2 registers: 134 * registers. The bits for the 3 PWMs are stored in 2 registers:
132 * PWM_RR(0) = [OFF3, OFF2, OFF1, RES, RR1E, RR1-2, RR1-1, RR1-0] 135 * PWM_RR(0) = [OFF3, OFF2, OFF1, RES, RR1E, RR1-2, RR1-1, RR1-0]
133 * PWM_RR(1) = [RR2E, RR2-2, RR2-1, RR2-0, RR3E, RR3-2, RR3-1, RR3-0] */ 136 * PWM_RR(1) = [RR2E, RR2-2, RR2-1, RR2-0, RR3E, RR3-2, RR3-1, RR3-0]
137 */
134#define DME1737_REG_PWM_RR(ix) (0x62 + (ix)) /* only for pwm[0-2] */ 138#define DME1737_REG_PWM_RR(ix) (0x62 + (ix)) /* only for pwm[0-2] */
135 139
136/* Thermal zones 0-2 */ 140/* Thermal zones 0-2 */
137#define DME1737_REG_ZONE_LOW(ix) (0x67 + (ix)) 141#define DME1737_REG_ZONE_LOW(ix) (0x67 + (ix))
138#define DME1737_REG_ZONE_ABS(ix) (0x6a + (ix)) 142#define DME1737_REG_ZONE_ABS(ix) (0x6a + (ix))
139/* The layout of the hysteresis registers is different from the other zone 143/*
144 * The layout of the hysteresis registers is different from the other zone
140 * registers. The bits for the 3 zones are stored in 2 registers: 145 * registers. The bits for the 3 zones are stored in 2 registers:
141 * ZONE_HYST(0) = [H1-3, H1-2, H1-1, H1-0, H2-3, H2-2, H2-1, H2-0] 146 * ZONE_HYST(0) = [H1-3, H1-2, H1-1, H1-0, H2-3, H2-2, H2-1, H2-0]
142 * ZONE_HYST(1) = [H3-3, H3-2, H3-1, H3-0, RES, RES, RES, RES] */ 147 * ZONE_HYST(1) = [H3-3, H3-2, H3-1, H3-0, RES, RES, RES, RES]
148 */
143#define DME1737_REG_ZONE_HYST(ix) (0x6d + (ix)) 149#define DME1737_REG_ZONE_HYST(ix) (0x6d + (ix))
144 150
145/* Alarm registers and bit mapping 151/*
152 * Alarm registers and bit mapping
146 * The 3 8-bit alarm registers will be concatenated to a single 32-bit 153 * The 3 8-bit alarm registers will be concatenated to a single 32-bit
147 * alarm value [0, ALARM3, ALARM2, ALARM1]. */ 154 * alarm value [0, ALARM3, ALARM2, ALARM1].
155 */
148#define DME1737_REG_ALARM1 0x41 156#define DME1737_REG_ALARM1 0x41
149#define DME1737_REG_ALARM2 0x42 157#define DME1737_REG_ALARM2 0x42
150#define DME1737_REG_ALARM3 0x83 158#define DME1737_REG_ALARM3 0x83
@@ -257,9 +265,11 @@ static const int IN_NOMINAL_SCH5127[] = {2500, 2250, 3300, 1125, 1125, 3300,
257 (type) == sch5127 ? IN_NOMINAL_SCH5127 : \ 265 (type) == sch5127 ? IN_NOMINAL_SCH5127 : \
258 IN_NOMINAL_DME1737) 266 IN_NOMINAL_DME1737)
259 267
260/* Voltage input 268/*
269 * Voltage input
261 * Voltage inputs have 16 bits resolution, limit values have 8 bits 270 * Voltage inputs have 16 bits resolution, limit values have 8 bits
262 * resolution. */ 271 * resolution.
272 */
263static inline int IN_FROM_REG(int reg, int nominal, int res) 273static inline int IN_FROM_REG(int reg, int nominal, int res)
264{ 274{
265 return (reg * nominal + (3 << (res - 3))) / (3 << (res - 2)); 275 return (reg * nominal + (3 << (res - 3))) / (3 << (res - 2));
@@ -270,10 +280,12 @@ static inline int IN_TO_REG(int val, int nominal)
270 return SENSORS_LIMIT((val * 192 + nominal / 2) / nominal, 0, 255); 280 return SENSORS_LIMIT((val * 192 + nominal / 2) / nominal, 0, 255);
271} 281}
272 282
273/* Temperature input 283/*
284 * Temperature input
274 * The register values represent temperatures in 2's complement notation from 285 * The register values represent temperatures in 2's complement notation from
275 * -127 degrees C to +127 degrees C. Temp inputs have 16 bits resolution, limit 286 * -127 degrees C to +127 degrees C. Temp inputs have 16 bits resolution, limit
276 * values have 8 bits resolution. */ 287 * values have 8 bits resolution.
288 */
277static inline int TEMP_FROM_REG(int reg, int res) 289static inline int TEMP_FROM_REG(int reg, int res)
278{ 290{
279 return (reg * 1000) >> (res - 8); 291 return (reg * 1000) >> (res - 8);
@@ -300,18 +312,19 @@ static int TEMP_RANGE_TO_REG(int val, int reg)
300 int i; 312 int i;
301 313
302 for (i = 15; i > 0; i--) { 314 for (i = 15; i > 0; i--) {
303 if (val > (TEMP_RANGE[i] + TEMP_RANGE[i - 1] + 1) / 2) { 315 if (val > (TEMP_RANGE[i] + TEMP_RANGE[i - 1] + 1) / 2)
304 break; 316 break;
305 }
306 } 317 }
307 318
308 return (reg & 0x0f) | (i << 4); 319 return (reg & 0x0f) | (i << 4);
309} 320}
310 321
311/* Temperature hysteresis 322/*
323 * Temperature hysteresis
312 * Register layout: 324 * Register layout:
313 * reg[0] = [H1-3, H1-2, H1-1, H1-0, H2-3, H2-2, H2-1, H2-0] 325 * reg[0] = [H1-3, H1-2, H1-1, H1-0, H2-3, H2-2, H2-1, H2-0]
314 * reg[1] = [H3-3, H3-2, H3-1, H3-0, xxxx, xxxx, xxxx, xxxx] */ 326 * reg[1] = [H3-3, H3-2, H3-1, H3-0, xxxx, xxxx, xxxx, xxxx]
327 */
315static inline int TEMP_HYST_FROM_REG(int reg, int ix) 328static inline int TEMP_HYST_FROM_REG(int reg, int ix)
316{ 329{
317 return (((ix == 1) ? reg : reg >> 4) & 0x0f) * 1000; 330 return (((ix == 1) ? reg : reg >> 4) & 0x0f) * 1000;
@@ -327,11 +340,10 @@ static inline int TEMP_HYST_TO_REG(int val, int ix, int reg)
327/* Fan input RPM */ 340/* Fan input RPM */
328static inline int FAN_FROM_REG(int reg, int tpc) 341static inline int FAN_FROM_REG(int reg, int tpc)
329{ 342{
330 if (tpc) { 343 if (tpc)
331 return tpc * reg; 344 return tpc * reg;
332 } else { 345 else
333 return (reg == 0 || reg == 0xffff) ? 0 : 90000 * 60 / reg; 346 return (reg == 0 || reg == 0xffff) ? 0 : 90000 * 60 / reg;
334 }
335} 347}
336 348
337static inline int FAN_TO_REG(int val, int tpc) 349static inline int FAN_TO_REG(int val, int tpc)
@@ -344,17 +356,21 @@ static inline int FAN_TO_REG(int val, int tpc)
344 } 356 }
345} 357}
346 358
347/* Fan TPC (tach pulse count) 359/*
360 * Fan TPC (tach pulse count)
348 * Converts a register value to a TPC multiplier or returns 0 if the tachometer 361 * Converts a register value to a TPC multiplier or returns 0 if the tachometer
349 * is configured in legacy (non-tpc) mode */ 362 * is configured in legacy (non-tpc) mode
363 */
350static inline int FAN_TPC_FROM_REG(int reg) 364static inline int FAN_TPC_FROM_REG(int reg)
351{ 365{
352 return (reg & 0x20) ? 0 : 60 >> (reg & 0x03); 366 return (reg & 0x20) ? 0 : 60 >> (reg & 0x03);
353} 367}
354 368
355/* Fan type 369/*
370 * Fan type
356 * The type of a fan is expressed in number of pulses-per-revolution that it 371 * The type of a fan is expressed in number of pulses-per-revolution that it
357 * emits */ 372 * emits
373 */
358static inline int FAN_TYPE_FROM_REG(int reg) 374static inline int FAN_TYPE_FROM_REG(int reg)
359{ 375{
360 int edge = (reg >> 1) & 0x03; 376 int edge = (reg >> 1) & 0x03;
@@ -378,9 +394,8 @@ static int FAN_MAX_FROM_REG(int reg)
378 int i; 394 int i;
379 395
380 for (i = 10; i > 0; i--) { 396 for (i = 10; i > 0; i--) {
381 if (reg == FAN_MAX[i]) { 397 if (reg == FAN_MAX[i])
382 break; 398 break;
383 }
384 } 399 }
385 400
386 return 1000 + i * 500; 401 return 1000 + i * 500;
@@ -391,15 +406,15 @@ static int FAN_MAX_TO_REG(int val)
391 int i; 406 int i;
392 407
393 for (i = 10; i > 0; i--) { 408 for (i = 10; i > 0; i--) {
394 if (val > (1000 + (i - 1) * 500)) { 409 if (val > (1000 + (i - 1) * 500))
395 break; 410 break;
396 }
397 } 411 }
398 412
399 return FAN_MAX[i]; 413 return FAN_MAX[i];
400} 414}
401 415
402/* PWM enable 416/*
417 * PWM enable
403 * Register to enable mapping: 418 * Register to enable mapping:
404 * 000: 2 fan on zone 1 auto 419 * 000: 2 fan on zone 1 auto
405 * 001: 2 fan on zone 2 auto 420 * 001: 2 fan on zone 2 auto
@@ -408,7 +423,8 @@ static int FAN_MAX_TO_REG(int val)
408 * 100: -1 fan disabled 423 * 100: -1 fan disabled
409 * 101: 2 fan on hottest of zones 2,3 auto 424 * 101: 2 fan on hottest of zones 2,3 auto
410 * 110: 2 fan on hottest of zones 1,2,3 auto 425 * 110: 2 fan on hottest of zones 1,2,3 auto
411 * 111: 1 fan in manual mode */ 426 * 111: 1 fan in manual mode
427 */
412static inline int PWM_EN_FROM_REG(int reg) 428static inline int PWM_EN_FROM_REG(int reg)
413{ 429{
414 static const int en[] = {2, 2, 2, 0, -1, 2, 2, 1}; 430 static const int en[] = {2, 2, 2, 0, -1, 2, 2, 1};
@@ -423,7 +439,8 @@ static inline int PWM_EN_TO_REG(int val, int reg)
423 return (reg & 0x1f) | ((en & 0x07) << 5); 439 return (reg & 0x1f) | ((en & 0x07) << 5);
424} 440}
425 441
426/* PWM auto channels zone 442/*
443 * PWM auto channels zone
427 * Register to auto channels zone mapping (ACZ is a bitfield with bit x 444 * Register to auto channels zone mapping (ACZ is a bitfield with bit x
428 * corresponding to zone x+1): 445 * corresponding to zone x+1):
429 * 000: 001 fan on zone 1 auto 446 * 000: 001 fan on zone 1 auto
@@ -433,7 +450,8 @@ static inline int PWM_EN_TO_REG(int val, int reg)
433 * 100: 000 fan disabled 450 * 100: 000 fan disabled
434 * 101: 110 fan on hottest of zones 2,3 auto 451 * 101: 110 fan on hottest of zones 2,3 auto
435 * 110: 111 fan on hottest of zones 1,2,3 auto 452 * 110: 111 fan on hottest of zones 1,2,3 auto
436 * 111: 000 fan in manual mode */ 453 * 111: 000 fan in manual mode
454 */
437static inline int PWM_ACZ_FROM_REG(int reg) 455static inline int PWM_ACZ_FROM_REG(int reg)
438{ 456{
439 static const int acz[] = {1, 2, 4, 0, 0, 6, 7, 0}; 457 static const int acz[] = {1, 2, 4, 0, 0, 6, 7, 0};
@@ -468,19 +486,20 @@ static int PWM_FREQ_TO_REG(int val, int reg)
468 i = 11; 486 i = 11;
469 } else { 487 } else {
470 for (i = 9; i > 0; i--) { 488 for (i = 9; i > 0; i--) {
471 if (val > (PWM_FREQ[i] + PWM_FREQ[i - 1] + 1) / 2) { 489 if (val > (PWM_FREQ[i] + PWM_FREQ[i - 1] + 1) / 2)
472 break; 490 break;
473 }
474 } 491 }
475 } 492 }
476 493
477 return (reg & 0xf0) | i; 494 return (reg & 0xf0) | i;
478} 495}
479 496
480/* PWM ramp rate 497/*
498 * PWM ramp rate
481 * Register layout: 499 * Register layout:
482 * reg[0] = [OFF3, OFF2, OFF1, RES, RR1-E, RR1-2, RR1-1, RR1-0] 500 * reg[0] = [OFF3, OFF2, OFF1, RES, RR1-E, RR1-2, RR1-1, RR1-0]
483 * reg[1] = [RR2-E, RR2-2, RR2-1, RR2-0, RR3-E, RR3-2, RR3-1, RR3-0] */ 501 * reg[1] = [RR2-E, RR2-2, RR2-1, RR2-0, RR3-E, RR3-2, RR3-1, RR3-0]
502 */
484static const u8 PWM_RR[] = {206, 104, 69, 41, 26, 18, 10, 5}; 503static const u8 PWM_RR[] = {206, 104, 69, 41, 26, 18, 10, 5};
485 504
486static inline int PWM_RR_FROM_REG(int reg, int ix) 505static inline int PWM_RR_FROM_REG(int reg, int ix)
@@ -495,9 +514,8 @@ static int PWM_RR_TO_REG(int val, int ix, int reg)
495 int i; 514 int i;
496 515
497 for (i = 0; i < 7; i++) { 516 for (i = 0; i < 7; i++) {
498 if (val > (PWM_RR[i] + PWM_RR[i + 1] + 1) / 2) { 517 if (val > (PWM_RR[i] + PWM_RR[i + 1] + 1) / 2)
499 break; 518 break;
500 }
501 } 519 }
502 520
503 return (ix == 1) ? (reg & 0x8f) | (i << 4) : (reg & 0xf8) | i; 521 return (ix == 1) ? (reg & 0x8f) | (i << 4) : (reg & 0xf8) | i;
@@ -516,9 +534,11 @@ static inline int PWM_RR_EN_TO_REG(int val, int ix, int reg)
516 return val ? reg | en : reg & ~en; 534 return val ? reg | en : reg & ~en;
517} 535}
518 536
519/* PWM min/off 537/*
538 * PWM min/off
520 * The PWM min/off bits are part of the PMW ramp rate register 0 (see above for 539 * The PWM min/off bits are part of the PMW ramp rate register 0 (see above for
521 * the register layout). */ 540 * the register layout).
541 */
522static inline int PWM_OFF_FROM_REG(int reg, int ix) 542static inline int PWM_OFF_FROM_REG(int reg, int ix)
523{ 543{
524 return (reg >> (ix + 5)) & 0x01; 544 return (reg >> (ix + 5)) & 0x01;
@@ -604,12 +624,13 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
604 624
605 /* In (voltage) registers */ 625 /* In (voltage) registers */
606 for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) { 626 for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) {
607 /* Voltage inputs are stored as 16 bit values even 627 /*
628 * Voltage inputs are stored as 16 bit values even
608 * though they have only 12 bits resolution. This is 629 * though they have only 12 bits resolution. This is
609 * to make it consistent with the temp inputs. */ 630 * to make it consistent with the temp inputs.
610 if (ix == 7 && !(data->has_features & HAS_IN7)) { 631 */
632 if (ix == 7 && !(data->has_features & HAS_IN7))
611 continue; 633 continue;
612 }
613 data->in[ix] = dme1737_read(data, 634 data->in[ix] = dme1737_read(data,
614 DME1737_REG_IN(ix)) << 8; 635 DME1737_REG_IN(ix)) << 8;
615 data->in_min[ix] = dme1737_read(data, 636 data->in_min[ix] = dme1737_read(data,
@@ -620,11 +641,13 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
620 641
621 /* Temp registers */ 642 /* Temp registers */
622 for (ix = 0; ix < ARRAY_SIZE(data->temp); ix++) { 643 for (ix = 0; ix < ARRAY_SIZE(data->temp); ix++) {
623 /* Temp inputs are stored as 16 bit values even 644 /*
645 * Temp inputs are stored as 16 bit values even
624 * though they have only 12 bits resolution. This is 646 * though they have only 12 bits resolution. This is
625 * to take advantage of implicit conversions between 647 * to take advantage of implicit conversions between
626 * register values (2's complement) and temp values 648 * register values (2's complement) and temp values
627 * (signed decimal). */ 649 * (signed decimal).
650 */
628 data->temp[ix] = dme1737_read(data, 651 data->temp[ix] = dme1737_read(data,
629 DME1737_REG_TEMP(ix)) << 8; 652 DME1737_REG_TEMP(ix)) << 8;
630 data->temp_min[ix] = dme1737_read(data, 653 data->temp_min[ix] = dme1737_read(data,
@@ -637,21 +660,21 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
637 } 660 }
638 } 661 }
639 662
640 /* In and temp LSB registers 663 /*
664 * In and temp LSB registers
641 * The LSBs are latched when the MSBs are read, so the order in 665 * The LSBs are latched when the MSBs are read, so the order in
642 * which the registers are read (MSB first, then LSB) is 666 * which the registers are read (MSB first, then LSB) is
643 * important! */ 667 * important!
668 */
644 for (ix = 0; ix < ARRAY_SIZE(lsb); ix++) { 669 for (ix = 0; ix < ARRAY_SIZE(lsb); ix++) {
645 if (ix == 5 && !(data->has_features & HAS_IN7)) { 670 if (ix == 5 && !(data->has_features & HAS_IN7))
646 continue; 671 continue;
647 }
648 lsb[ix] = dme1737_read(data, 672 lsb[ix] = dme1737_read(data,
649 DME1737_REG_IN_TEMP_LSB(ix)); 673 DME1737_REG_IN_TEMP_LSB(ix));
650 } 674 }
651 for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) { 675 for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) {
652 if (ix == 7 && !(data->has_features & HAS_IN7)) { 676 if (ix == 7 && !(data->has_features & HAS_IN7))
653 continue; 677 continue;
654 }
655 data->in[ix] |= (lsb[DME1737_REG_IN_LSB[ix]] << 678 data->in[ix] |= (lsb[DME1737_REG_IN_LSB[ix]] <<
656 DME1737_REG_IN_LSB_SHL[ix]) & 0xf0; 679 DME1737_REG_IN_LSB_SHL[ix]) & 0xf0;
657 } 680 }
@@ -662,11 +685,12 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
662 685
663 /* Fan registers */ 686 /* Fan registers */
664 for (ix = 0; ix < ARRAY_SIZE(data->fan); ix++) { 687 for (ix = 0; ix < ARRAY_SIZE(data->fan); ix++) {
665 /* Skip reading registers if optional fans are not 688 /*
666 * present */ 689 * Skip reading registers if optional fans are not
667 if (!(data->has_features & HAS_FAN(ix))) { 690 * present
691 */
692 if (!(data->has_features & HAS_FAN(ix)))
668 continue; 693 continue;
669 }
670 data->fan[ix] = dme1737_read(data, 694 data->fan[ix] = dme1737_read(data,
671 DME1737_REG_FAN(ix)); 695 DME1737_REG_FAN(ix));
672 data->fan[ix] |= dme1737_read(data, 696 data->fan[ix] |= dme1737_read(data,
@@ -686,11 +710,12 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
686 710
687 /* PWM registers */ 711 /* PWM registers */
688 for (ix = 0; ix < ARRAY_SIZE(data->pwm); ix++) { 712 for (ix = 0; ix < ARRAY_SIZE(data->pwm); ix++) {
689 /* Skip reading registers if optional PWMs are not 713 /*
690 * present */ 714 * Skip reading registers if optional PWMs are not
691 if (!(data->has_features & HAS_PWM(ix))) { 715 * present
716 */
717 if (!(data->has_features & HAS_PWM(ix)))
692 continue; 718 continue;
693 }
694 data->pwm[ix] = dme1737_read(data, 719 data->pwm[ix] = dme1737_read(data,
695 DME1737_REG_PWM(ix)); 720 DME1737_REG_PWM(ix));
696 data->pwm_freq[ix] = dme1737_read(data, 721 data->pwm_freq[ix] = dme1737_read(data,
@@ -711,9 +736,8 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
711 /* Thermal zone registers */ 736 /* Thermal zone registers */
712 for (ix = 0; ix < ARRAY_SIZE(data->zone_low); ix++) { 737 for (ix = 0; ix < ARRAY_SIZE(data->zone_low); ix++) {
713 /* Skip reading registers if zone3 is not present */ 738 /* Skip reading registers if zone3 is not present */
714 if ((ix == 2) && !(data->has_features & HAS_ZONE3)) { 739 if ((ix == 2) && !(data->has_features & HAS_ZONE3))
715 continue; 740 continue;
716 }
717 /* sch5127 zone2 registers are special */ 741 /* sch5127 zone2 registers are special */
718 if ((ix == 1) && (data->type == sch5127)) { 742 if ((ix == 1) && (data->type == sch5127)) {
719 data->zone_low[1] = dme1737_read(data, 743 data->zone_low[1] = dme1737_read(data,
@@ -737,8 +761,10 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
737 /* Alarm registers */ 761 /* Alarm registers */
738 data->alarms = dme1737_read(data, 762 data->alarms = dme1737_read(data,
739 DME1737_REG_ALARM1); 763 DME1737_REG_ALARM1);
740 /* Bit 7 tells us if the other alarm registers are non-zero and 764 /*
741 * therefore also need to be read */ 765 * Bit 7 tells us if the other alarm registers are non-zero and
766 * therefore also need to be read
767 */
742 if (data->alarms & 0x80) { 768 if (data->alarms & 0x80) {
743 data->alarms |= dme1737_read(data, 769 data->alarms |= dme1737_read(data,
744 DME1737_REG_ALARM2) << 8; 770 DME1737_REG_ALARM2) << 8;
@@ -746,22 +772,18 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
746 DME1737_REG_ALARM3) << 16; 772 DME1737_REG_ALARM3) << 16;
747 } 773 }
748 774
749 /* The ISA chips require explicit clearing of alarm bits. 775 /*
776 * The ISA chips require explicit clearing of alarm bits.
750 * Don't worry, an alarm will come back if the condition 777 * Don't worry, an alarm will come back if the condition
751 * that causes it still exists */ 778 * that causes it still exists
779 */
752 if (!data->client) { 780 if (!data->client) {
753 if (data->alarms & 0xff0000) { 781 if (data->alarms & 0xff0000)
754 dme1737_write(data, DME1737_REG_ALARM3, 782 dme1737_write(data, DME1737_REG_ALARM3, 0xff);
755 0xff); 783 if (data->alarms & 0xff00)
756 } 784 dme1737_write(data, DME1737_REG_ALARM2, 0xff);
757 if (data->alarms & 0xff00) { 785 if (data->alarms & 0xff)
758 dme1737_write(data, DME1737_REG_ALARM2, 786 dme1737_write(data, DME1737_REG_ALARM1, 0xff);
759 0xff);
760 }
761 if (data->alarms & 0xff) {
762 dme1737_write(data, DME1737_REG_ALARM1,
763 0xff);
764 }
765 } 787 }
766 788
767 data->last_update = jiffies; 789 data->last_update = jiffies;
@@ -822,7 +844,12 @@ static ssize_t set_in(struct device *dev, struct device_attribute *attr,
822 *sensor_attr_2 = to_sensor_dev_attr_2(attr); 844 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
823 int ix = sensor_attr_2->index; 845 int ix = sensor_attr_2->index;
824 int fn = sensor_attr_2->nr; 846 int fn = sensor_attr_2->nr;
825 long val = simple_strtol(buf, NULL, 10); 847 long val;
848 int err;
849
850 err = kstrtol(buf, 10, &val);
851 if (err)
852 return err;
826 853
827 mutex_lock(&data->update_lock); 854 mutex_lock(&data->update_lock);
828 switch (fn) { 855 switch (fn) {
@@ -901,7 +928,12 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
901 *sensor_attr_2 = to_sensor_dev_attr_2(attr); 928 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
902 int ix = sensor_attr_2->index; 929 int ix = sensor_attr_2->index;
903 int fn = sensor_attr_2->nr; 930 int fn = sensor_attr_2->nr;
904 long val = simple_strtol(buf, NULL, 10); 931 long val;
932 int err;
933
934 err = kstrtol(buf, 10, &val);
935 if (err)
936 return err;
905 937
906 mutex_lock(&data->update_lock); 938 mutex_lock(&data->update_lock);
907 switch (fn) { 939 switch (fn) {
@@ -952,11 +984,10 @@ static ssize_t show_zone(struct device *dev, struct device_attribute *attr,
952 switch (fn) { 984 switch (fn) {
953 case SYS_ZONE_AUTO_CHANNELS_TEMP: 985 case SYS_ZONE_AUTO_CHANNELS_TEMP:
954 /* check config2 for non-standard temp-to-zone mapping */ 986 /* check config2 for non-standard temp-to-zone mapping */
955 if ((ix == 1) && (data->config2 & 0x02)) { 987 if ((ix == 1) && (data->config2 & 0x02))
956 res = 4; 988 res = 4;
957 } else { 989 else
958 res = 1 << ix; 990 res = 1 << ix;
959 }
960 break; 991 break;
961 case SYS_ZONE_AUTO_POINT1_TEMP_HYST: 992 case SYS_ZONE_AUTO_POINT1_TEMP_HYST:
962 res = TEMP_FROM_REG(data->zone_low[ix], 8) - 993 res = TEMP_FROM_REG(data->zone_low[ix], 8) -
@@ -989,7 +1020,12 @@ static ssize_t set_zone(struct device *dev, struct device_attribute *attr,
989 *sensor_attr_2 = to_sensor_dev_attr_2(attr); 1020 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
990 int ix = sensor_attr_2->index; 1021 int ix = sensor_attr_2->index;
991 int fn = sensor_attr_2->nr; 1022 int fn = sensor_attr_2->nr;
992 long val = simple_strtol(buf, NULL, 10); 1023 long val;
1024 int err;
1025
1026 err = kstrtol(buf, 10, &val);
1027 if (err)
1028 return err;
993 1029
994 mutex_lock(&data->update_lock); 1030 mutex_lock(&data->update_lock);
995 switch (fn) { 1031 switch (fn) {
@@ -1014,8 +1050,10 @@ static ssize_t set_zone(struct device *dev, struct device_attribute *attr,
1014 /* Refresh the cache */ 1050 /* Refresh the cache */
1015 data->zone_low[ix] = dme1737_read(data, 1051 data->zone_low[ix] = dme1737_read(data,
1016 DME1737_REG_ZONE_LOW(ix)); 1052 DME1737_REG_ZONE_LOW(ix));
1017 /* Modify the temp range value (which is stored in the upper 1053 /*
1018 * nibble of the pwm_freq register) */ 1054 * Modify the temp range value (which is stored in the upper
1055 * nibble of the pwm_freq register)
1056 */
1019 data->pwm_freq[ix] = TEMP_RANGE_TO_REG(val - 1057 data->pwm_freq[ix] = TEMP_RANGE_TO_REG(val -
1020 TEMP_FROM_REG(data->zone_low[ix], 8), 1058 TEMP_FROM_REG(data->zone_low[ix], 8),
1021 dme1737_read(data, 1059 dme1737_read(data,
@@ -1095,7 +1133,12 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
1095 *sensor_attr_2 = to_sensor_dev_attr_2(attr); 1133 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
1096 int ix = sensor_attr_2->index; 1134 int ix = sensor_attr_2->index;
1097 int fn = sensor_attr_2->nr; 1135 int fn = sensor_attr_2->nr;
1098 long val = simple_strtol(buf, NULL, 10); 1136 long val;
1137 int err;
1138
1139 err = kstrtol(buf, 10, &val);
1140 if (err)
1141 return err;
1099 1142
1100 mutex_lock(&data->update_lock); 1143 mutex_lock(&data->update_lock);
1101 switch (fn) { 1144 switch (fn) {
@@ -1170,21 +1213,19 @@ static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
1170 1213
1171 switch (fn) { 1214 switch (fn) {
1172 case SYS_PWM: 1215 case SYS_PWM:
1173 if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 0) { 1216 if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 0)
1174 res = 255; 1217 res = 255;
1175 } else { 1218 else
1176 res = data->pwm[ix]; 1219 res = data->pwm[ix];
1177 }
1178 break; 1220 break;
1179 case SYS_PWM_FREQ: 1221 case SYS_PWM_FREQ:
1180 res = PWM_FREQ_FROM_REG(data->pwm_freq[ix]); 1222 res = PWM_FREQ_FROM_REG(data->pwm_freq[ix]);
1181 break; 1223 break;
1182 case SYS_PWM_ENABLE: 1224 case SYS_PWM_ENABLE:
1183 if (ix >= 3) { 1225 if (ix >= 3)
1184 res = 1; /* pwm[5-6] hard-wired to manual mode */ 1226 res = 1; /* pwm[5-6] hard-wired to manual mode */
1185 } else { 1227 else
1186 res = PWM_EN_FROM_REG(data->pwm_config[ix]); 1228 res = PWM_EN_FROM_REG(data->pwm_config[ix]);
1187 }
1188 break; 1229 break;
1189 case SYS_PWM_RAMP_RATE: 1230 case SYS_PWM_RAMP_RATE:
1190 /* Only valid for pwm[1-3] */ 1231 /* Only valid for pwm[1-3] */
@@ -1192,19 +1233,17 @@ static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
1192 break; 1233 break;
1193 case SYS_PWM_AUTO_CHANNELS_ZONE: 1234 case SYS_PWM_AUTO_CHANNELS_ZONE:
1194 /* Only valid for pwm[1-3] */ 1235 /* Only valid for pwm[1-3] */
1195 if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) { 1236 if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2)
1196 res = PWM_ACZ_FROM_REG(data->pwm_config[ix]); 1237 res = PWM_ACZ_FROM_REG(data->pwm_config[ix]);
1197 } else { 1238 else
1198 res = data->pwm_acz[ix]; 1239 res = data->pwm_acz[ix];
1199 }
1200 break; 1240 break;
1201 case SYS_PWM_AUTO_PWM_MIN: 1241 case SYS_PWM_AUTO_PWM_MIN:
1202 /* Only valid for pwm[1-3] */ 1242 /* Only valid for pwm[1-3] */
1203 if (PWM_OFF_FROM_REG(data->pwm_rr[0], ix)) { 1243 if (PWM_OFF_FROM_REG(data->pwm_rr[0], ix))
1204 res = data->pwm_min[ix]; 1244 res = data->pwm_min[ix];
1205 } else { 1245 else
1206 res = 0; 1246 res = 0;
1207 }
1208 break; 1247 break;
1209 case SYS_PWM_AUTO_POINT1_PWM: 1248 case SYS_PWM_AUTO_POINT1_PWM:
1210 /* Only valid for pwm[1-3] */ 1249 /* Only valid for pwm[1-3] */
@@ -1233,7 +1272,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1233 *sensor_attr_2 = to_sensor_dev_attr_2(attr); 1272 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
1234 int ix = sensor_attr_2->index; 1273 int ix = sensor_attr_2->index;
1235 int fn = sensor_attr_2->nr; 1274 int fn = sensor_attr_2->nr;
1236 long val = simple_strtol(buf, NULL, 10); 1275 long val;
1276 int err;
1277
1278 err = kstrtol(buf, 10, &val);
1279 if (err)
1280 return err;
1237 1281
1238 mutex_lock(&data->update_lock); 1282 mutex_lock(&data->update_lock);
1239 switch (fn) { 1283 switch (fn) {
@@ -1307,8 +1351,10 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1307 /* Change permissions of pwm[ix] to read-only */ 1351 /* Change permissions of pwm[ix] to read-only */
1308 dme1737_chmod_file(dev, dme1737_pwm_chmod_attr[ix], 1352 dme1737_chmod_file(dev, dme1737_pwm_chmod_attr[ix],
1309 S_IRUGO); 1353 S_IRUGO);
1310 /* Turn on auto mode using the saved zone channel 1354 /*
1311 * assignment */ 1355 * Turn on auto mode using the saved zone channel
1356 * assignment
1357 */
1312 data->pwm_config[ix] = PWM_ACZ_TO_REG( 1358 data->pwm_config[ix] = PWM_ACZ_TO_REG(
1313 data->pwm_acz[ix], 1359 data->pwm_acz[ix],
1314 data->pwm_config[ix]); 1360 data->pwm_config[ix]);
@@ -1338,8 +1384,10 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1338 data->pwm_rr[ix > 0] = PWM_RR_TO_REG(val, ix, 1384 data->pwm_rr[ix > 0] = PWM_RR_TO_REG(val, ix,
1339 data->pwm_rr[ix > 0]); 1385 data->pwm_rr[ix > 0]);
1340 } 1386 }
1341 /* Enable/disable the feature only if the associated PWM 1387 /*
1342 * output is in automatic mode. */ 1388 * Enable/disable the feature only if the associated PWM
1389 * output is in automatic mode.
1390 */
1343 if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) { 1391 if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) {
1344 data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(val > 0, ix, 1392 data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(val > 0, ix,
1345 data->pwm_rr[ix > 0]); 1393 data->pwm_rr[ix > 0]);
@@ -1361,15 +1409,19 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1361 data->pwm_config[ix] = dme1737_read(data, 1409 data->pwm_config[ix] = dme1737_read(data,
1362 DME1737_REG_PWM_CONFIG(ix)); 1410 DME1737_REG_PWM_CONFIG(ix));
1363 if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) { 1411 if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) {
1364 /* PWM is already in auto mode so update the temp 1412 /*
1365 * channel assignment */ 1413 * PWM is already in auto mode so update the temp
1414 * channel assignment
1415 */
1366 data->pwm_config[ix] = PWM_ACZ_TO_REG(val, 1416 data->pwm_config[ix] = PWM_ACZ_TO_REG(val,
1367 data->pwm_config[ix]); 1417 data->pwm_config[ix]);
1368 dme1737_write(data, DME1737_REG_PWM_CONFIG(ix), 1418 dme1737_write(data, DME1737_REG_PWM_CONFIG(ix),
1369 data->pwm_config[ix]); 1419 data->pwm_config[ix]);
1370 } else { 1420 } else {
1371 /* PWM is not in auto mode so we save the temp 1421 /*
1372 * channel assignment for later use */ 1422 * PWM is not in auto mode so we save the temp
1423 * channel assignment for later use
1424 */
1373 data->pwm_acz[ix] = val; 1425 data->pwm_acz[ix] = val;
1374 } 1426 }
1375 break; 1427 break;
@@ -1378,10 +1430,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1378 /* Refresh the cache */ 1430 /* Refresh the cache */
1379 data->pwm_min[ix] = dme1737_read(data, 1431 data->pwm_min[ix] = dme1737_read(data,
1380 DME1737_REG_PWM_MIN(ix)); 1432 DME1737_REG_PWM_MIN(ix));
1381 /* There are only 2 values supported for the auto_pwm_min 1433 /*
1434 * There are only 2 values supported for the auto_pwm_min
1382 * value: 0 or auto_point1_pwm. So if the temperature drops 1435 * value: 0 or auto_point1_pwm. So if the temperature drops
1383 * below the auto_point1_temp_hyst value, the fan either turns 1436 * below the auto_point1_temp_hyst value, the fan either turns
1384 * off or runs at auto_point1_pwm duty-cycle. */ 1437 * off or runs at auto_point1_pwm duty-cycle.
1438 */
1385 if (val > ((data->pwm_min[ix] + 1) / 2)) { 1439 if (val > ((data->pwm_min[ix] + 1) / 2)) {
1386 data->pwm_rr[0] = PWM_OFF_TO_REG(1, ix, 1440 data->pwm_rr[0] = PWM_OFF_TO_REG(1, ix,
1387 dme1737_read(data, 1441 dme1737_read(data,
@@ -1426,7 +1480,12 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
1426 const char *buf, size_t count) 1480 const char *buf, size_t count)
1427{ 1481{
1428 struct dme1737_data *data = dev_get_drvdata(dev); 1482 struct dme1737_data *data = dev_get_drvdata(dev);
1429 long val = simple_strtol(buf, NULL, 10); 1483 long val;
1484 int err;
1485
1486 err = kstrtol(buf, 10, &val);
1487 if (err)
1488 return err;
1430 1489
1431 data->vrm = val; 1490 data->vrm = val;
1432 return count; 1491 return count;
@@ -1586,10 +1645,12 @@ static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
1586static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 1645static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
1587static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); /* for ISA devices */ 1646static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); /* for ISA devices */
1588 1647
1589/* This struct holds all the attributes that are always present and need to be 1648/*
1649 * This struct holds all the attributes that are always present and need to be
1590 * created unconditionally. The attributes that need modification of their 1650 * created unconditionally. The attributes that need modification of their
1591 * permissions are created read-only and write permissions are added or removed 1651 * permissions are created read-only and write permissions are added or removed
1592 * on the fly when required */ 1652 * on the fly when required
1653 */
1593static struct attribute *dme1737_attr[] = { 1654static struct attribute *dme1737_attr[] = {
1594 /* Voltages */ 1655 /* Voltages */
1595 &sensor_dev_attr_in0_input.dev_attr.attr, 1656 &sensor_dev_attr_in0_input.dev_attr.attr,
@@ -1652,9 +1713,11 @@ static const struct attribute_group dme1737_group = {
1652 .attrs = dme1737_attr, 1713 .attrs = dme1737_attr,
1653}; 1714};
1654 1715
1655/* The following struct holds temp offset attributes, which are not available 1716/*
1717 * The following struct holds temp offset attributes, which are not available
1656 * in all chips. The following chips support them: 1718 * in all chips. The following chips support them:
1657 * DME1737, SCH311x */ 1719 * DME1737, SCH311x
1720 */
1658static struct attribute *dme1737_temp_offset_attr[] = { 1721static struct attribute *dme1737_temp_offset_attr[] = {
1659 &sensor_dev_attr_temp1_offset.dev_attr.attr, 1722 &sensor_dev_attr_temp1_offset.dev_attr.attr,
1660 &sensor_dev_attr_temp2_offset.dev_attr.attr, 1723 &sensor_dev_attr_temp2_offset.dev_attr.attr,
@@ -1666,9 +1729,11 @@ static const struct attribute_group dme1737_temp_offset_group = {
1666 .attrs = dme1737_temp_offset_attr, 1729 .attrs = dme1737_temp_offset_attr,
1667}; 1730};
1668 1731
1669/* The following struct holds VID related attributes, which are not available 1732/*
1733 * The following struct holds VID related attributes, which are not available
1670 * in all chips. The following chips support them: 1734 * in all chips. The following chips support them:
1671 * DME1737 */ 1735 * DME1737
1736 */
1672static struct attribute *dme1737_vid_attr[] = { 1737static struct attribute *dme1737_vid_attr[] = {
1673 &dev_attr_vrm.attr, 1738 &dev_attr_vrm.attr,
1674 &dev_attr_cpu0_vid.attr, 1739 &dev_attr_cpu0_vid.attr,
@@ -1679,9 +1744,11 @@ static const struct attribute_group dme1737_vid_group = {
1679 .attrs = dme1737_vid_attr, 1744 .attrs = dme1737_vid_attr,
1680}; 1745};
1681 1746
1682/* The following struct holds temp zone 3 related attributes, which are not 1747/*
1748 * The following struct holds temp zone 3 related attributes, which are not
1683 * available in all chips. The following chips support them: 1749 * available in all chips. The following chips support them:
1684 * DME1737, SCH311x, SCH5027 */ 1750 * DME1737, SCH311x, SCH5027
1751 */
1685static struct attribute *dme1737_zone3_attr[] = { 1752static struct attribute *dme1737_zone3_attr[] = {
1686 &sensor_dev_attr_zone3_auto_point1_temp.dev_attr.attr, 1753 &sensor_dev_attr_zone3_auto_point1_temp.dev_attr.attr,
1687 &sensor_dev_attr_zone3_auto_point2_temp.dev_attr.attr, 1754 &sensor_dev_attr_zone3_auto_point2_temp.dev_attr.attr,
@@ -1695,9 +1762,11 @@ static const struct attribute_group dme1737_zone3_group = {
1695}; 1762};
1696 1763
1697 1764
1698/* The following struct holds temp zone hysteresis related attributes, which 1765/*
1766 * The following struct holds temp zone hysteresis related attributes, which
1699 * are not available in all chips. The following chips support them: 1767 * are not available in all chips. The following chips support them:
1700 * DME1737, SCH311x */ 1768 * DME1737, SCH311x
1769 */
1701static struct attribute *dme1737_zone_hyst_attr[] = { 1770static struct attribute *dme1737_zone_hyst_attr[] = {
1702 &sensor_dev_attr_zone1_auto_point1_temp_hyst.dev_attr.attr, 1771 &sensor_dev_attr_zone1_auto_point1_temp_hyst.dev_attr.attr,
1703 &sensor_dev_attr_zone2_auto_point1_temp_hyst.dev_attr.attr, 1772 &sensor_dev_attr_zone2_auto_point1_temp_hyst.dev_attr.attr,
@@ -1709,9 +1778,11 @@ static const struct attribute_group dme1737_zone_hyst_group = {
1709 .attrs = dme1737_zone_hyst_attr, 1778 .attrs = dme1737_zone_hyst_attr,
1710}; 1779};
1711 1780
1712/* The following struct holds voltage in7 related attributes, which 1781/*
1782 * The following struct holds voltage in7 related attributes, which
1713 * are not available in all chips. The following chips support them: 1783 * are not available in all chips. The following chips support them:
1714 * SCH5127 */ 1784 * SCH5127
1785 */
1715static struct attribute *dme1737_in7_attr[] = { 1786static struct attribute *dme1737_in7_attr[] = {
1716 &sensor_dev_attr_in7_input.dev_attr.attr, 1787 &sensor_dev_attr_in7_input.dev_attr.attr,
1717 &sensor_dev_attr_in7_min.dev_attr.attr, 1788 &sensor_dev_attr_in7_min.dev_attr.attr,
@@ -1724,9 +1795,11 @@ static const struct attribute_group dme1737_in7_group = {
1724 .attrs = dme1737_in7_attr, 1795 .attrs = dme1737_in7_attr,
1725}; 1796};
1726 1797
1727/* The following structs hold the PWM attributes, some of which are optional. 1798/*
1799 * The following structs hold the PWM attributes, some of which are optional.
1728 * Their creation depends on the chip configuration which is determined during 1800 * Their creation depends on the chip configuration which is determined during
1729 * module load. */ 1801 * module load.
1802 */
1730static struct attribute *dme1737_pwm1_attr[] = { 1803static struct attribute *dme1737_pwm1_attr[] = {
1731 &sensor_dev_attr_pwm1.dev_attr.attr, 1804 &sensor_dev_attr_pwm1.dev_attr.attr,
1732 &sensor_dev_attr_pwm1_freq.dev_attr.attr, 1805 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
@@ -1779,18 +1852,22 @@ static const struct attribute_group dme1737_pwm_group[] = {
1779 { .attrs = dme1737_pwm6_attr }, 1852 { .attrs = dme1737_pwm6_attr },
1780}; 1853};
1781 1854
1782/* The following struct holds auto PWM min attributes, which are not available 1855/*
1856 * The following struct holds auto PWM min attributes, which are not available
1783 * in all chips. Their creation depends on the chip type which is determined 1857 * in all chips. Their creation depends on the chip type which is determined
1784 * during module load. */ 1858 * during module load.
1859 */
1785static struct attribute *dme1737_auto_pwm_min_attr[] = { 1860static struct attribute *dme1737_auto_pwm_min_attr[] = {
1786 &sensor_dev_attr_pwm1_auto_pwm_min.dev_attr.attr, 1861 &sensor_dev_attr_pwm1_auto_pwm_min.dev_attr.attr,
1787 &sensor_dev_attr_pwm2_auto_pwm_min.dev_attr.attr, 1862 &sensor_dev_attr_pwm2_auto_pwm_min.dev_attr.attr,
1788 &sensor_dev_attr_pwm3_auto_pwm_min.dev_attr.attr, 1863 &sensor_dev_attr_pwm3_auto_pwm_min.dev_attr.attr,
1789}; 1864};
1790 1865
1791/* The following structs hold the fan attributes, some of which are optional. 1866/*
1867 * The following structs hold the fan attributes, some of which are optional.
1792 * Their creation depends on the chip configuration which is determined during 1868 * Their creation depends on the chip configuration which is determined during
1793 * module load. */ 1869 * module load.
1870 */
1794static struct attribute *dme1737_fan1_attr[] = { 1871static struct attribute *dme1737_fan1_attr[] = {
1795 &sensor_dev_attr_fan1_input.dev_attr.attr, 1872 &sensor_dev_attr_fan1_input.dev_attr.attr,
1796 &sensor_dev_attr_fan1_min.dev_attr.attr, 1873 &sensor_dev_attr_fan1_min.dev_attr.attr,
@@ -1843,8 +1920,10 @@ static const struct attribute_group dme1737_fan_group[] = {
1843 { .attrs = dme1737_fan6_attr }, 1920 { .attrs = dme1737_fan6_attr },
1844}; 1921};
1845 1922
1846/* The permissions of the following zone attributes are changed to read- 1923/*
1847 * writeable if the chip is *not* locked. Otherwise they stay read-only. */ 1924 * The permissions of the following zone attributes are changed to read-
1925 * writeable if the chip is *not* locked. Otherwise they stay read-only.
1926 */
1848static struct attribute *dme1737_zone_chmod_attr[] = { 1927static struct attribute *dme1737_zone_chmod_attr[] = {
1849 &sensor_dev_attr_zone1_auto_point1_temp.dev_attr.attr, 1928 &sensor_dev_attr_zone1_auto_point1_temp.dev_attr.attr,
1850 &sensor_dev_attr_zone1_auto_point2_temp.dev_attr.attr, 1929 &sensor_dev_attr_zone1_auto_point2_temp.dev_attr.attr,
@@ -1860,8 +1939,10 @@ static const struct attribute_group dme1737_zone_chmod_group = {
1860}; 1939};
1861 1940
1862 1941
1863/* The permissions of the following zone 3 attributes are changed to read- 1942/*
1864 * writeable if the chip is *not* locked. Otherwise they stay read-only. */ 1943 * The permissions of the following zone 3 attributes are changed to read-
1944 * writeable if the chip is *not* locked. Otherwise they stay read-only.
1945 */
1865static struct attribute *dme1737_zone3_chmod_attr[] = { 1946static struct attribute *dme1737_zone3_chmod_attr[] = {
1866 &sensor_dev_attr_zone3_auto_point1_temp.dev_attr.attr, 1947 &sensor_dev_attr_zone3_auto_point1_temp.dev_attr.attr,
1867 &sensor_dev_attr_zone3_auto_point2_temp.dev_attr.attr, 1948 &sensor_dev_attr_zone3_auto_point2_temp.dev_attr.attr,
@@ -1873,9 +1954,11 @@ static const struct attribute_group dme1737_zone3_chmod_group = {
1873 .attrs = dme1737_zone3_chmod_attr, 1954 .attrs = dme1737_zone3_chmod_attr,
1874}; 1955};
1875 1956
1876/* The permissions of the following PWM attributes are changed to read- 1957/*
1958 * The permissions of the following PWM attributes are changed to read-
1877 * writeable if the chip is *not* locked and the respective PWM is available. 1959 * writeable if the chip is *not* locked and the respective PWM is available.
1878 * Otherwise they stay read-only. */ 1960 * Otherwise they stay read-only.
1961 */
1879static struct attribute *dme1737_pwm1_chmod_attr[] = { 1962static struct attribute *dme1737_pwm1_chmod_attr[] = {
1880 &sensor_dev_attr_pwm1_freq.dev_attr.attr, 1963 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
1881 &sensor_dev_attr_pwm1_enable.dev_attr.attr, 1964 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
@@ -1920,8 +2003,10 @@ static const struct attribute_group dme1737_pwm_chmod_group[] = {
1920 { .attrs = dme1737_pwm6_chmod_attr }, 2003 { .attrs = dme1737_pwm6_chmod_attr },
1921}; 2004};
1922 2005
1923/* Pwm[1-3] are read-writeable if the associated pwm is in manual mode and the 2006/*
1924 * chip is not locked. Otherwise they are read-only. */ 2007 * Pwm[1-3] are read-writeable if the associated pwm is in manual mode and the
2008 * chip is not locked. Otherwise they are read-only.
2009 */
1925static struct attribute *dme1737_pwm_chmod_attr[] = { 2010static struct attribute *dme1737_pwm_chmod_attr[] = {
1926 &sensor_dev_attr_pwm1.dev_attr.attr, 2011 &sensor_dev_attr_pwm1.dev_attr.attr,
1927 &sensor_dev_attr_pwm2.dev_attr.attr, 2012 &sensor_dev_attr_pwm2.dev_attr.attr,
@@ -1975,9 +2060,8 @@ static void dme1737_chmod_group(struct device *dev,
1975{ 2060{
1976 struct attribute **attr; 2061 struct attribute **attr;
1977 2062
1978 for (attr = group->attrs; *attr; attr++) { 2063 for (attr = group->attrs; *attr; attr++)
1979 dme1737_chmod_file(dev, *attr, mode); 2064 dme1737_chmod_file(dev, *attr, mode);
1980 }
1981} 2065}
1982 2066
1983static void dme1737_remove_files(struct device *dev) 2067static void dme1737_remove_files(struct device *dev)
@@ -2003,26 +2087,20 @@ static void dme1737_remove_files(struct device *dev)
2003 } 2087 }
2004 } 2088 }
2005 2089
2006 if (data->has_features & HAS_TEMP_OFFSET) { 2090 if (data->has_features & HAS_TEMP_OFFSET)
2007 sysfs_remove_group(&dev->kobj, &dme1737_temp_offset_group); 2091 sysfs_remove_group(&dev->kobj, &dme1737_temp_offset_group);
2008 } 2092 if (data->has_features & HAS_VID)
2009 if (data->has_features & HAS_VID) {
2010 sysfs_remove_group(&dev->kobj, &dme1737_vid_group); 2093 sysfs_remove_group(&dev->kobj, &dme1737_vid_group);
2011 } 2094 if (data->has_features & HAS_ZONE3)
2012 if (data->has_features & HAS_ZONE3) {
2013 sysfs_remove_group(&dev->kobj, &dme1737_zone3_group); 2095 sysfs_remove_group(&dev->kobj, &dme1737_zone3_group);
2014 } 2096 if (data->has_features & HAS_ZONE_HYST)
2015 if (data->has_features & HAS_ZONE_HYST) {
2016 sysfs_remove_group(&dev->kobj, &dme1737_zone_hyst_group); 2097 sysfs_remove_group(&dev->kobj, &dme1737_zone_hyst_group);
2017 } 2098 if (data->has_features & HAS_IN7)
2018 if (data->has_features & HAS_IN7) {
2019 sysfs_remove_group(&dev->kobj, &dme1737_in7_group); 2099 sysfs_remove_group(&dev->kobj, &dme1737_in7_group);
2020 }
2021 sysfs_remove_group(&dev->kobj, &dme1737_group); 2100 sysfs_remove_group(&dev->kobj, &dme1737_group);
2022 2101
2023 if (!data->client) { 2102 if (!data->client)
2024 sysfs_remove_file(&dev->kobj, &dev_attr_name.attr); 2103 sysfs_remove_file(&dev->kobj, &dev_attr_name.attr);
2025 }
2026} 2104}
2027 2105
2028static int dme1737_create_files(struct device *dev) 2106static int dme1737_create_files(struct device *dev)
@@ -2033,48 +2111,41 @@ static int dme1737_create_files(struct device *dev)
2033 /* Create a name attribute for ISA devices */ 2111 /* Create a name attribute for ISA devices */
2034 if (!data->client) { 2112 if (!data->client) {
2035 err = sysfs_create_file(&dev->kobj, &dev_attr_name.attr); 2113 err = sysfs_create_file(&dev->kobj, &dev_attr_name.attr);
2036 if (err) { 2114 if (err)
2037 goto exit; 2115 goto exit;
2038 }
2039 } 2116 }
2040 2117
2041 /* Create standard sysfs attributes */ 2118 /* Create standard sysfs attributes */
2042 err = sysfs_create_group(&dev->kobj, &dme1737_group); 2119 err = sysfs_create_group(&dev->kobj, &dme1737_group);
2043 if (err) { 2120 if (err)
2044 goto exit_remove; 2121 goto exit_remove;
2045 }
2046 2122
2047 /* Create chip-dependent sysfs attributes */ 2123 /* Create chip-dependent sysfs attributes */
2048 if (data->has_features & HAS_TEMP_OFFSET) { 2124 if (data->has_features & HAS_TEMP_OFFSET) {
2049 err = sysfs_create_group(&dev->kobj, 2125 err = sysfs_create_group(&dev->kobj,
2050 &dme1737_temp_offset_group); 2126 &dme1737_temp_offset_group);
2051 if (err) { 2127 if (err)
2052 goto exit_remove; 2128 goto exit_remove;
2053 }
2054 } 2129 }
2055 if (data->has_features & HAS_VID) { 2130 if (data->has_features & HAS_VID) {
2056 err = sysfs_create_group(&dev->kobj, &dme1737_vid_group); 2131 err = sysfs_create_group(&dev->kobj, &dme1737_vid_group);
2057 if (err) { 2132 if (err)
2058 goto exit_remove; 2133 goto exit_remove;
2059 }
2060 } 2134 }
2061 if (data->has_features & HAS_ZONE3) { 2135 if (data->has_features & HAS_ZONE3) {
2062 err = sysfs_create_group(&dev->kobj, &dme1737_zone3_group); 2136 err = sysfs_create_group(&dev->kobj, &dme1737_zone3_group);
2063 if (err) { 2137 if (err)
2064 goto exit_remove; 2138 goto exit_remove;
2065 }
2066 } 2139 }
2067 if (data->has_features & HAS_ZONE_HYST) { 2140 if (data->has_features & HAS_ZONE_HYST) {
2068 err = sysfs_create_group(&dev->kobj, &dme1737_zone_hyst_group); 2141 err = sysfs_create_group(&dev->kobj, &dme1737_zone_hyst_group);
2069 if (err) { 2142 if (err)
2070 goto exit_remove; 2143 goto exit_remove;
2071 }
2072 } 2144 }
2073 if (data->has_features & HAS_IN7) { 2145 if (data->has_features & HAS_IN7) {
2074 err = sysfs_create_group(&dev->kobj, &dme1737_in7_group); 2146 err = sysfs_create_group(&dev->kobj, &dme1737_in7_group);
2075 if (err) { 2147 if (err)
2076 goto exit_remove; 2148 goto exit_remove;
2077 }
2078 } 2149 }
2079 2150
2080 /* Create fan sysfs attributes */ 2151 /* Create fan sysfs attributes */
@@ -2082,9 +2153,8 @@ static int dme1737_create_files(struct device *dev)
2082 if (data->has_features & HAS_FAN(ix)) { 2153 if (data->has_features & HAS_FAN(ix)) {
2083 err = sysfs_create_group(&dev->kobj, 2154 err = sysfs_create_group(&dev->kobj,
2084 &dme1737_fan_group[ix]); 2155 &dme1737_fan_group[ix]);
2085 if (err) { 2156 if (err)
2086 goto exit_remove; 2157 goto exit_remove;
2087 }
2088 } 2158 }
2089 } 2159 }
2090 2160
@@ -2093,21 +2163,21 @@ static int dme1737_create_files(struct device *dev)
2093 if (data->has_features & HAS_PWM(ix)) { 2163 if (data->has_features & HAS_PWM(ix)) {
2094 err = sysfs_create_group(&dev->kobj, 2164 err = sysfs_create_group(&dev->kobj,
2095 &dme1737_pwm_group[ix]); 2165 &dme1737_pwm_group[ix]);
2096 if (err) { 2166 if (err)
2097 goto exit_remove; 2167 goto exit_remove;
2098 }
2099 if ((data->has_features & HAS_PWM_MIN) && (ix < 3)) { 2168 if ((data->has_features & HAS_PWM_MIN) && (ix < 3)) {
2100 err = sysfs_create_file(&dev->kobj, 2169 err = sysfs_create_file(&dev->kobj,
2101 dme1737_auto_pwm_min_attr[ix]); 2170 dme1737_auto_pwm_min_attr[ix]);
2102 if (err) { 2171 if (err)
2103 goto exit_remove; 2172 goto exit_remove;
2104 }
2105 } 2173 }
2106 } 2174 }
2107 } 2175 }
2108 2176
2109 /* Inform if the device is locked. Otherwise change the permissions of 2177 /*
2110 * selected attributes from read-only to read-writeable. */ 2178 * Inform if the device is locked. Otherwise change the permissions of
2179 * selected attributes from read-only to read-writeable.
2180 */
2111 if (data->config & 0x02) { 2181 if (data->config & 0x02) {
2112 dev_info(dev, "Device is locked. Some attributes " 2182 dev_info(dev, "Device is locked. Some attributes "
2113 "will be read-only.\n"); 2183 "will be read-only.\n");
@@ -2194,26 +2264,30 @@ static int dme1737_init_device(struct device *dev)
2194 return -EFAULT; 2264 return -EFAULT;
2195 } 2265 }
2196 2266
2197 /* Determine which optional fan and pwm features are enabled (only 2267 /*
2198 * valid for I2C devices) */ 2268 * Determine which optional fan and pwm features are enabled (only
2269 * valid for I2C devices)
2270 */
2199 if (client) { /* I2C chip */ 2271 if (client) { /* I2C chip */
2200 data->config2 = dme1737_read(data, DME1737_REG_CONFIG2); 2272 data->config2 = dme1737_read(data, DME1737_REG_CONFIG2);
2201 /* Check if optional fan3 input is enabled */ 2273 /* Check if optional fan3 input is enabled */
2202 if (data->config2 & 0x04) { 2274 if (data->config2 & 0x04)
2203 data->has_features |= HAS_FAN(2); 2275 data->has_features |= HAS_FAN(2);
2204 }
2205 2276
2206 /* Fan4 and pwm3 are only available if the client's I2C address 2277 /*
2278 * Fan4 and pwm3 are only available if the client's I2C address
2207 * is the default 0x2e. Otherwise the I/Os associated with 2279 * is the default 0x2e. Otherwise the I/Os associated with
2208 * these functions are used for addr enable/select. */ 2280 * these functions are used for addr enable/select.
2209 if (client->addr == 0x2e) { 2281 */
2282 if (client->addr == 0x2e)
2210 data->has_features |= HAS_FAN(3) | HAS_PWM(2); 2283 data->has_features |= HAS_FAN(3) | HAS_PWM(2);
2211 }
2212 2284
2213 /* Determine which of the optional fan[5-6] and pwm[5-6] 2285 /*
2286 * Determine which of the optional fan[5-6] and pwm[5-6]
2214 * features are enabled. For this, we need to query the runtime 2287 * features are enabled. For this, we need to query the runtime
2215 * registers through the Super-IO LPC interface. Try both 2288 * registers through the Super-IO LPC interface. Try both
2216 * config ports 0x2e and 0x4e. */ 2289 * config ports 0x2e and 0x4e.
2290 */
2217 if (dme1737_i2c_get_features(0x2e, data) && 2291 if (dme1737_i2c_get_features(0x2e, data) &&
2218 dme1737_i2c_get_features(0x4e, data)) { 2292 dme1737_i2c_get_features(0x4e, data)) {
2219 dev_warn(dev, "Failed to query Super-IO for optional " 2293 dev_warn(dev, "Failed to query Super-IO for optional "
@@ -2271,9 +2345,11 @@ static int dme1737_init_device(struct device *dev)
2271 ((reg >> 4) & 0x03) + 1); 2345 ((reg >> 4) & 0x03) + 1);
2272 } 2346 }
2273 2347
2274 /* Switch pwm[1-3] to manual mode if they are currently disabled and 2348 /*
2349 * Switch pwm[1-3] to manual mode if they are currently disabled and
2275 * set the duty-cycles to 0% (which is identical to the PWMs being 2350 * set the duty-cycles to 0% (which is identical to the PWMs being
2276 * disabled). */ 2351 * disabled).
2352 */
2277 if (!(data->config & 0x02)) { 2353 if (!(data->config & 0x02)) {
2278 for (ix = 0; ix < 3; ix++) { 2354 for (ix = 0; ix < 3; ix++) {
2279 data->pwm_config[ix] = dme1737_read(data, 2355 data->pwm_config[ix] = dme1737_read(data,
@@ -2298,9 +2374,8 @@ static int dme1737_init_device(struct device *dev)
2298 data->pwm_acz[2] = 4; /* pwm3 -> zone3 */ 2374 data->pwm_acz[2] = 4; /* pwm3 -> zone3 */
2299 2375
2300 /* Set VRM */ 2376 /* Set VRM */
2301 if (data->has_features & HAS_VID) { 2377 if (data->has_features & HAS_VID)
2302 data->vrm = vid_which_vrm(); 2378 data->vrm = vid_which_vrm();
2303 }
2304 2379
2305 return 0; 2380 return 0;
2306} 2381}
@@ -2318,8 +2393,10 @@ static int dme1737_i2c_get_features(int sio_cip, struct dme1737_data *data)
2318 2393
2319 dme1737_sio_enter(sio_cip); 2394 dme1737_sio_enter(sio_cip);
2320 2395
2321 /* Check device ID 2396 /*
2322 * We currently know about two kinds of DME1737 and SCH5027. */ 2397 * Check device ID
2398 * We currently know about two kinds of DME1737 and SCH5027.
2399 */
2323 reg = force_id ? force_id : dme1737_sio_inb(sio_cip, 0x20); 2400 reg = force_id ? force_id : dme1737_sio_inb(sio_cip, 0x20);
2324 if (!(reg == DME1737_ID_1 || reg == DME1737_ID_2 || 2401 if (!(reg == DME1737_ID_1 || reg == DME1737_ID_2 ||
2325 reg == SCH5027_ID)) { 2402 reg == SCH5027_ID)) {
@@ -2338,21 +2415,19 @@ static int dme1737_i2c_get_features(int sio_cip, struct dme1737_data *data)
2338 goto exit; 2415 goto exit;
2339 } 2416 }
2340 2417
2341 /* Read the runtime registers to determine which optional features 2418 /*
2419 * Read the runtime registers to determine which optional features
2342 * are enabled and available. Bits [3:2] of registers 0x43-0x46 are set 2420 * are enabled and available. Bits [3:2] of registers 0x43-0x46 are set
2343 * to '10' if the respective feature is enabled. */ 2421 * to '10' if the respective feature is enabled.
2344 if ((inb(addr + 0x43) & 0x0c) == 0x08) { /* fan6 */ 2422 */
2423 if ((inb(addr + 0x43) & 0x0c) == 0x08) /* fan6 */
2345 data->has_features |= HAS_FAN(5); 2424 data->has_features |= HAS_FAN(5);
2346 } 2425 if ((inb(addr + 0x44) & 0x0c) == 0x08) /* pwm6 */
2347 if ((inb(addr + 0x44) & 0x0c) == 0x08) { /* pwm6 */
2348 data->has_features |= HAS_PWM(5); 2426 data->has_features |= HAS_PWM(5);
2349 } 2427 if ((inb(addr + 0x45) & 0x0c) == 0x08) /* fan5 */
2350 if ((inb(addr + 0x45) & 0x0c) == 0x08) { /* fan5 */
2351 data->has_features |= HAS_FAN(4); 2428 data->has_features |= HAS_FAN(4);
2352 } 2429 if ((inb(addr + 0x46) & 0x0c) == 0x08) /* pwm5 */
2353 if ((inb(addr + 0x46) & 0x0c) == 0x08) { /* pwm5 */
2354 data->has_features |= HAS_PWM(4); 2430 data->has_features |= HAS_PWM(4);
2355 }
2356 2431
2357exit: 2432exit:
2358 dme1737_sio_exit(sio_cip); 2433 dme1737_sio_exit(sio_cip);
@@ -2369,9 +2444,8 @@ static int dme1737_i2c_detect(struct i2c_client *client,
2369 u8 company, verstep = 0; 2444 u8 company, verstep = 0;
2370 const char *name; 2445 const char *name;
2371 2446
2372 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 2447 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
2373 return -ENODEV; 2448 return -ENODEV;
2374 }
2375 2449
2376 company = i2c_smbus_read_byte_data(client, DME1737_REG_COMPANY); 2450 company = i2c_smbus_read_byte_data(client, DME1737_REG_COMPANY);
2377 verstep = i2c_smbus_read_byte_data(client, DME1737_REG_VERSTEP); 2451 verstep = i2c_smbus_read_byte_data(client, DME1737_REG_VERSTEP);
@@ -2486,8 +2560,10 @@ static int __init dme1737_isa_detect(int sio_cip, unsigned short *addr)
2486 2560
2487 dme1737_sio_enter(sio_cip); 2561 dme1737_sio_enter(sio_cip);
2488 2562
2489 /* Check device ID 2563 /*
2490 * We currently know about SCH3112, SCH3114, SCH3116, and SCH5127 */ 2564 * Check device ID
2565 * We currently know about SCH3112, SCH3114, SCH3116, and SCH5127
2566 */
2491 reg = force_id ? force_id : dme1737_sio_inb(sio_cip, 0x20); 2567 reg = force_id ? force_id : dme1737_sio_inb(sio_cip, 0x20);
2492 if (!(reg == SCH3112_ID || reg == SCH3114_ID || reg == SCH3116_ID || 2568 if (!(reg == SCH3112_ID || reg == SCH3114_ID || reg == SCH3116_ID ||
2493 reg == SCH5127_ID)) { 2569 reg == SCH5127_ID)) {
@@ -2507,8 +2583,10 @@ static int __init dme1737_isa_detect(int sio_cip, unsigned short *addr)
2507 goto exit; 2583 goto exit;
2508 } 2584 }
2509 2585
2510 /* Access to the hwmon registers is through an index/data register 2586 /*
2511 * pair located at offset 0x70/0x71. */ 2587 * Access to the hwmon registers is through an index/data register
2588 * pair located at offset 0x70/0x71.
2589 */
2512 *addr = base_addr + 0x70; 2590 *addr = base_addr + 0x70;
2513 2591
2514exit: 2592exit:
@@ -2610,11 +2688,10 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev)
2610 } 2688 }
2611 } 2689 }
2612 2690
2613 if (data->type == sch5127) { 2691 if (data->type == sch5127)
2614 data->name = "sch5127"; 2692 data->name = "sch5127";
2615 } else { 2693 else
2616 data->name = "sch311x"; 2694 data->name = "sch311x";
2617 }
2618 2695
2619 /* Initialize the mutex */ 2696 /* Initialize the mutex */
2620 mutex_init(&data->update_lock); 2697 mutex_init(&data->update_lock);
@@ -2689,9 +2766,8 @@ static int __init dme1737_init(void)
2689 unsigned short addr; 2766 unsigned short addr;
2690 2767
2691 err = i2c_add_driver(&dme1737_i2c_driver); 2768 err = i2c_add_driver(&dme1737_i2c_driver);
2692 if (err) { 2769 if (err)
2693 goto exit; 2770 goto exit;
2694 }
2695 2771
2696 if (dme1737_isa_detect(0x2e, &addr) && 2772 if (dme1737_isa_detect(0x2e, &addr) &&
2697 dme1737_isa_detect(0x4e, &addr) && 2773 dme1737_isa_detect(0x4e, &addr) &&
@@ -2703,15 +2779,13 @@ static int __init dme1737_init(void)
2703 } 2779 }
2704 2780
2705 err = platform_driver_register(&dme1737_isa_driver); 2781 err = platform_driver_register(&dme1737_isa_driver);
2706 if (err) { 2782 if (err)
2707 goto exit_del_i2c_driver; 2783 goto exit_del_i2c_driver;
2708 }
2709 2784
2710 /* Sets global pdev as a side effect */ 2785 /* Sets global pdev as a side effect */
2711 err = dme1737_isa_device_add(addr); 2786 err = dme1737_isa_device_add(addr);
2712 if (err) { 2787 if (err)
2713 goto exit_del_isa_driver; 2788 goto exit_del_isa_driver;
2714 }
2715 2789
2716 return 0; 2790 return 0;
2717 2791
diff --git a/drivers/hwmon/ds1621.c b/drivers/hwmon/ds1621.c
index ef1ac996752e..f647a3307ebc 100644
--- a/drivers/hwmon/ds1621.c
+++ b/drivers/hwmon/ds1621.c
@@ -1,25 +1,25 @@
1/* 1/*
2 ds1621.c - Part of lm_sensors, Linux kernel modules for hardware 2 * ds1621.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 * monitoring
4 Christian W. Zuckschwerdt <zany@triq.net> 2000-11-23 4 * Christian W. Zuckschwerdt <zany@triq.net> 2000-11-23
5 based on lm75.c by Frodo Looijaard <frodol@dds.nl> 5 * based on lm75.c by Frodo Looijaard <frodol@dds.nl>
6 Ported to Linux 2.6 by Aurelien Jarno <aurelien@aurel32.net> with 6 * Ported to Linux 2.6 by Aurelien Jarno <aurelien@aurel32.net> with
7 the help of Jean Delvare <khali@linux-fr.org> 7 * the help of Jean Delvare <khali@linux-fr.org>
8 8 *
9 This program is free software; you can redistribute it and/or modify 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 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 11 * the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version. 12 * (at your option) any later version.
13 13 *
14 This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details. 17 * GNU General Public License for more details.
18 18 *
19 You should have received a copy of the GNU General Public License 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 20 * along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22*/ 22 */
23 23
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/init.h> 25#include <linux/init.h>
@@ -67,7 +67,7 @@ static const u8 DS1621_REG_TEMP[3] = {
67 67
68/* Conversions */ 68/* Conversions */
69#define ALARMS_FROM_REG(val) ((val) & \ 69#define ALARMS_FROM_REG(val) ((val) & \
70 (DS1621_ALARM_TEMP_HIGH | DS1621_ALARM_TEMP_LOW)) 70 (DS1621_ALARM_TEMP_HIGH | DS1621_ALARM_TEMP_LOW))
71 71
72/* Each client has this additional data */ 72/* Each client has this additional data */
73struct ds1621_data { 73struct ds1621_data {
@@ -93,10 +93,10 @@ static void ds1621_init_client(struct i2c_client *client)
93 new_conf &= ~DS1621_REG_CONFIG_POLARITY; 93 new_conf &= ~DS1621_REG_CONFIG_POLARITY;
94 else if (polarity == 1) 94 else if (polarity == 1)
95 new_conf |= DS1621_REG_CONFIG_POLARITY; 95 new_conf |= DS1621_REG_CONFIG_POLARITY;
96 96
97 if (conf != new_conf) 97 if (conf != new_conf)
98 i2c_smbus_write_byte_data(client, DS1621_REG_CONF, new_conf); 98 i2c_smbus_write_byte_data(client, DS1621_REG_CONF, new_conf);
99 99
100 /* start conversion */ 100 /* start conversion */
101 i2c_smbus_write_byte(client, DS1621_COM_START); 101 i2c_smbus_write_byte(client, DS1621_COM_START);
102} 102}
@@ -155,10 +155,15 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,
155 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 155 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
156 struct i2c_client *client = to_i2c_client(dev); 156 struct i2c_client *client = to_i2c_client(dev);
157 struct ds1621_data *data = i2c_get_clientdata(client); 157 struct ds1621_data *data = i2c_get_clientdata(client);
158 u16 val = LM75_TEMP_TO_REG(simple_strtol(buf, NULL, 10)); 158 long val;
159 int err;
160
161 err = kstrtol(buf, 10, &val);
162 if (err)
163 return err;
159 164
160 mutex_lock(&data->update_lock); 165 mutex_lock(&data->update_lock);
161 data->temp[attr->index] = val; 166 data->temp[attr->index] = LM75_TEMP_TO_REG(val);
162 i2c_smbus_write_word_swapped(client, DS1621_REG_TEMP[attr->index], 167 i2c_smbus_write_word_swapped(client, DS1621_REG_TEMP[attr->index],
163 data->temp[attr->index]); 168 data->temp[attr->index]);
164 mutex_unlock(&data->update_lock); 169 mutex_unlock(&data->update_lock);
@@ -212,14 +217,17 @@ static int ds1621_detect(struct i2c_client *client,
212 int conf, temp; 217 int conf, temp;
213 int i; 218 int i;
214 219
215 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA 220 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA
216 | I2C_FUNC_SMBUS_WORD_DATA 221 | I2C_FUNC_SMBUS_WORD_DATA
217 | I2C_FUNC_SMBUS_WRITE_BYTE)) 222 | I2C_FUNC_SMBUS_WRITE_BYTE))
218 return -ENODEV; 223 return -ENODEV;
219 224
220 /* Now, we do the remaining detection. It is lousy. */ 225 /*
221 /* The NVB bit should be low if no EEPROM write has been requested 226 * Now, we do the remaining detection. It is lousy.
222 during the latest 10ms, which is highly improbable in our case. */ 227 *
228 * The NVB bit should be low if no EEPROM write has been requested
229 * during the latest 10ms, which is highly improbable in our case.
230 */
223 conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF); 231 conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF);
224 if (conf < 0 || conf & DS1621_REG_CONFIG_NVB) 232 if (conf < 0 || conf & DS1621_REG_CONFIG_NVB)
225 return -ENODEV; 233 return -ENODEV;
@@ -254,7 +262,8 @@ static int ds1621_probe(struct i2c_client *client,
254 ds1621_init_client(client); 262 ds1621_init_client(client);
255 263
256 /* Register sysfs hooks */ 264 /* Register sysfs hooks */
257 if ((err = sysfs_create_group(&client->dev.kobj, &ds1621_group))) 265 err = sysfs_create_group(&client->dev.kobj, &ds1621_group);
266 if (err)
258 goto exit_free; 267 goto exit_free;
259 268
260 data->hwmon_dev = hwmon_device_register(&client->dev); 269 data->hwmon_dev = hwmon_device_register(&client->dev);
@@ -265,11 +274,11 @@ static int ds1621_probe(struct i2c_client *client,
265 274
266 return 0; 275 return 0;
267 276
268 exit_remove_files: 277 exit_remove_files:
269 sysfs_remove_group(&client->dev.kobj, &ds1621_group); 278 sysfs_remove_group(&client->dev.kobj, &ds1621_group);
270 exit_free: 279 exit_free:
271 kfree(data); 280 kfree(data);
272 exit: 281 exit:
273 return err; 282 return err;
274} 283}
275 284
@@ -305,20 +314,8 @@ static struct i2c_driver ds1621_driver = {
305 .address_list = normal_i2c, 314 .address_list = normal_i2c,
306}; 315};
307 316
308static int __init ds1621_init(void) 317module_i2c_driver(ds1621_driver);
309{
310 return i2c_add_driver(&ds1621_driver);
311}
312
313static void __exit ds1621_exit(void)
314{
315 i2c_del_driver(&ds1621_driver);
316}
317
318 318
319MODULE_AUTHOR("Christian W. Zuckschwerdt <zany@triq.net>"); 319MODULE_AUTHOR("Christian W. Zuckschwerdt <zany@triq.net>");
320MODULE_DESCRIPTION("DS1621 driver"); 320MODULE_DESCRIPTION("DS1621 driver");
321MODULE_LICENSE("GPL"); 321MODULE_LICENSE("GPL");
322
323module_init(ds1621_init);
324module_exit(ds1621_exit);
diff --git a/drivers/hwmon/ds620.c b/drivers/hwmon/ds620.c
index 300c3d4d67df..50663efad412 100644
--- a/drivers/hwmon/ds620.c
+++ b/drivers/hwmon/ds620.c
@@ -297,19 +297,8 @@ static struct i2c_driver ds620_driver = {
297 .id_table = ds620_id, 297 .id_table = ds620_id,
298}; 298};
299 299
300static int __init ds620_init(void) 300module_i2c_driver(ds620_driver);
301{
302 return i2c_add_driver(&ds620_driver);
303}
304
305static void __exit ds620_exit(void)
306{
307 i2c_del_driver(&ds620_driver);
308}
309 301
310MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>"); 302MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
311MODULE_DESCRIPTION("DS620 driver"); 303MODULE_DESCRIPTION("DS620 driver");
312MODULE_LICENSE("GPL"); 304MODULE_LICENSE("GPL");
313
314module_init(ds620_init);
315module_exit(ds620_exit);
diff --git a/drivers/hwmon/emc1403.c b/drivers/hwmon/emc1403.c
index 270ffab711cb..149dcb0e148f 100644
--- a/drivers/hwmon/emc1403.c
+++ b/drivers/hwmon/emc1403.c
@@ -41,8 +41,10 @@
41struct thermal_data { 41struct thermal_data {
42 struct device *hwmon_dev; 42 struct device *hwmon_dev;
43 struct mutex mutex; 43 struct mutex mutex;
44 /* Cache the hyst value so we don't keep re-reading it. In theory 44 /*
45 we could cache it forever as nobody else should be writing it. */ 45 * Cache the hyst value so we don't keep re-reading it. In theory
46 * we could cache it forever as nobody else should be writing it.
47 */
46 u8 cached_hyst; 48 u8 cached_hyst;
47 unsigned long hyst_valid; 49 unsigned long hyst_valid;
48}; 50};
@@ -283,8 +285,10 @@ static int emc1403_detect(struct i2c_client *client,
283 case 0x23: 285 case 0x23:
284 strlcpy(info->type, "emc1423", I2C_NAME_SIZE); 286 strlcpy(info->type, "emc1423", I2C_NAME_SIZE);
285 break; 287 break;
286 /* Note: 0x25 is the 1404 which is very similar and this 288 /*
287 driver could be extended */ 289 * Note: 0x25 is the 1404 which is very similar and this
290 * driver could be extended
291 */
288 default: 292 default:
289 return -ENODEV; 293 return -ENODEV;
290 } 294 }
@@ -366,18 +370,7 @@ static struct i2c_driver sensor_emc1403 = {
366 .address_list = emc1403_address_list, 370 .address_list = emc1403_address_list,
367}; 371};
368 372
369static int __init sensor_emc1403_init(void) 373module_i2c_driver(sensor_emc1403);
370{
371 return i2c_add_driver(&sensor_emc1403);
372}
373
374static void __exit sensor_emc1403_exit(void)
375{
376 i2c_del_driver(&sensor_emc1403);
377}
378
379module_init(sensor_emc1403_init);
380module_exit(sensor_emc1403_exit);
381 374
382MODULE_AUTHOR("Kalhan Trisal <kalhan.trisal@intel.com"); 375MODULE_AUTHOR("Kalhan Trisal <kalhan.trisal@intel.com");
383MODULE_DESCRIPTION("emc1403 Thermal Driver"); 376MODULE_DESCRIPTION("emc1403 Thermal Driver");
diff --git a/drivers/hwmon/emc2103.c b/drivers/hwmon/emc2103.c
index 865063914d76..9691f664c76e 100644
--- a/drivers/hwmon/emc2103.c
+++ b/drivers/hwmon/emc2103.c
@@ -1,21 +1,21 @@
1/* 1/*
2 emc2103.c - Support for SMSC EMC2103 2 * emc2103.c - Support for SMSC EMC2103
3 Copyright (c) 2010 SMSC 3 * Copyright (c) 2010 SMSC
4 4 *
5 This program is free software; you can redistribute it and/or modify 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 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 7 * the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 * (at your option) any later version.
9 9 *
10 This program is distributed in the hope that it will be useful, 10 * This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 * GNU General Public License for more details.
14 14 *
15 You should have received a copy of the GNU General Public License 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 16 * along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/ 18 */
19 19
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/init.h> 21#include <linux/init.h>
@@ -48,12 +48,14 @@ static const u8 REG_TEMP_MAX[4] = { 0x34, 0x30, 0x31, 0x32 };
48/* equation 4 from datasheet: rpm = (3932160 * multipler) / count */ 48/* equation 4 from datasheet: rpm = (3932160 * multipler) / count */
49#define FAN_RPM_FACTOR 3932160 49#define FAN_RPM_FACTOR 3932160
50 50
51/* 2103-2 and 2103-4's 3rd temperature sensor can be connected to two diodes 51/*
52 * 2103-2 and 2103-4's 3rd temperature sensor can be connected to two diodes
52 * in anti-parallel mode, and in this configuration both can be read 53 * in anti-parallel mode, and in this configuration both can be read
53 * independently (so we have 4 temperature inputs). The device can't 54 * independently (so we have 4 temperature inputs). The device can't
54 * detect if it's connected in this mode, so we have to manually enable 55 * detect if it's connected in this mode, so we have to manually enable
55 * it. Default is to leave the device in the state it's already in (-1). 56 * it. Default is to leave the device in the state it's already in (-1).
56 * This parameter allows APD mode to be optionally forced on or off */ 57 * This parameter allows APD mode to be optionally forced on or off
58 */
57static int apd = -1; 59static int apd = -1;
58module_param(apd, bint, 0); 60module_param(apd, bint, 0);
59MODULE_PARM_DESC(init, "Set to zero to disable anti-parallel diode mode"); 61MODULE_PARM_DESC(init, "Set to zero to disable anti-parallel diode mode");
@@ -302,10 +304,12 @@ show_fan_div(struct device *dev, struct device_attribute *da, char *buf)
302 return sprintf(buf, "%d\n", fan_div); 304 return sprintf(buf, "%d\n", fan_div);
303} 305}
304 306
305/* Note: we also update the fan target here, because its value is 307/*
306 determined in part by the fan clock divider. This follows the principle 308 * Note: we also update the fan target here, because its value is
307 of least surprise; the user doesn't expect the fan target to change just 309 * determined in part by the fan clock divider. This follows the principle
308 because the divider changed. */ 310 * of least surprise; the user doesn't expect the fan target to change just
311 * because the divider changed.
312 */
309static ssize_t set_fan_div(struct device *dev, struct device_attribute *da, 313static ssize_t set_fan_div(struct device *dev, struct device_attribute *da,
310 const char *buf, size_t count) 314 const char *buf, size_t count)
311{ 315{
@@ -722,19 +726,8 @@ static struct i2c_driver emc2103_driver = {
722 .address_list = normal_i2c, 726 .address_list = normal_i2c,
723}; 727};
724 728
725static int __init sensors_emc2103_init(void) 729module_i2c_driver(emc2103_driver);
726{
727 return i2c_add_driver(&emc2103_driver);
728}
729
730static void __exit sensors_emc2103_exit(void)
731{
732 i2c_del_driver(&emc2103_driver);
733}
734 730
735MODULE_AUTHOR("Steve Glendinning <steve.glendinning@smsc.com>"); 731MODULE_AUTHOR("Steve Glendinning <steve.glendinning@smsc.com>");
736MODULE_DESCRIPTION("SMSC EMC2103 hwmon driver"); 732MODULE_DESCRIPTION("SMSC EMC2103 hwmon driver");
737MODULE_LICENSE("GPL"); 733MODULE_LICENSE("GPL");
738
739module_init(sensors_emc2103_init);
740module_exit(sensors_emc2103_exit);
diff --git a/drivers/hwmon/emc6w201.c b/drivers/hwmon/emc6w201.c
index 6ebb9b738c9c..840f5112e602 100644
--- a/drivers/hwmon/emc6w201.c
+++ b/drivers/hwmon/emc6w201.c
@@ -552,17 +552,7 @@ static struct i2c_driver emc6w201_driver = {
552 .address_list = normal_i2c, 552 .address_list = normal_i2c,
553}; 553};
554 554
555static int __init sensors_emc6w201_init(void) 555module_i2c_driver(emc6w201_driver);
556{
557 return i2c_add_driver(&emc6w201_driver);
558}
559module_init(sensors_emc6w201_init);
560
561static void __exit sensors_emc6w201_exit(void)
562{
563 i2c_del_driver(&emc6w201_driver);
564}
565module_exit(sensors_emc6w201_exit);
566 556
567MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); 557MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
568MODULE_DESCRIPTION("SMSC EMC6W201 hardware monitoring driver"); 558MODULE_DESCRIPTION("SMSC EMC6W201 hardware monitoring driver");
diff --git a/drivers/hwmon/f71805f.c b/drivers/hwmon/f71805f.c
index 6dbfd3e516e4..3e4da620e9c7 100644
--- a/drivers/hwmon/f71805f.c
+++ b/drivers/hwmon/f71805f.c
@@ -202,7 +202,7 @@ struct f71805f_sio_data {
202 202
203static inline long in_from_reg(u8 reg) 203static inline long in_from_reg(u8 reg)
204{ 204{
205 return (reg * 8); 205 return reg * 8;
206} 206}
207 207
208/* The 2 least significant bits are not used */ 208/* The 2 least significant bits are not used */
@@ -212,13 +212,13 @@ static inline u8 in_to_reg(long val)
212 return 0; 212 return 0;
213 if (val >= 2016) 213 if (val >= 2016)
214 return 0xfc; 214 return 0xfc;
215 return (((val + 16) / 32) << 2); 215 return ((val + 16) / 32) << 2;
216} 216}
217 217
218/* in0 is downscaled by a factor 2 internally */ 218/* in0 is downscaled by a factor 2 internally */
219static inline long in0_from_reg(u8 reg) 219static inline long in0_from_reg(u8 reg)
220{ 220{
221 return (reg * 16); 221 return reg * 16;
222} 222}
223 223
224static inline u8 in0_to_reg(long val) 224static inline u8 in0_to_reg(long val)
@@ -227,7 +227,7 @@ static inline u8 in0_to_reg(long val)
227 return 0; 227 return 0;
228 if (val >= 4032) 228 if (val >= 4032)
229 return 0xfc; 229 return 0xfc;
230 return (((val + 32) / 64) << 2); 230 return ((val + 32) / 64) << 2;
231} 231}
232 232
233/* The 4 most significant bits are not used */ 233/* The 4 most significant bits are not used */
@@ -236,17 +236,19 @@ static inline long fan_from_reg(u16 reg)
236 reg &= 0xfff; 236 reg &= 0xfff;
237 if (!reg || reg == 0xfff) 237 if (!reg || reg == 0xfff)
238 return 0; 238 return 0;
239 return (1500000 / reg); 239 return 1500000 / reg;
240} 240}
241 241
242static inline u16 fan_to_reg(long rpm) 242static inline u16 fan_to_reg(long rpm)
243{ 243{
244 /* If the low limit is set below what the chip can measure, 244 /*
245 store the largest possible 12-bit value in the registers, 245 * If the low limit is set below what the chip can measure,
246 so that no alarm will ever trigger. */ 246 * store the largest possible 12-bit value in the registers,
247 * so that no alarm will ever trigger.
248 */
247 if (rpm < 367) 249 if (rpm < 367)
248 return 0xfff; 250 return 0xfff;
249 return (1500000 / rpm); 251 return 1500000 / rpm;
250} 252}
251 253
252static inline unsigned long pwm_freq_from_reg(u8 reg) 254static inline unsigned long pwm_freq_from_reg(u8 reg)
@@ -278,7 +280,7 @@ static inline int pwm_mode_from_reg(u8 reg)
278 280
279static inline long temp_from_reg(u8 reg) 281static inline long temp_from_reg(u8 reg)
280{ 282{
281 return (reg * 1000); 283 return reg * 1000;
282} 284}
283 285
284static inline u8 temp_to_reg(long val) 286static inline u8 temp_to_reg(long val)
@@ -308,9 +310,11 @@ static void f71805f_write8(struct f71805f_data *data, u8 reg, u8 val)
308 outb(val, data->addr + DATA_REG_OFFSET); 310 outb(val, data->addr + DATA_REG_OFFSET);
309} 311}
310 312
311/* It is important to read the MSB first, because doing so latches the 313/*
312 value of the LSB, so we are sure both bytes belong to the same value. 314 * It is important to read the MSB first, because doing so latches the
313 Must be called with data->update_lock held, except during initialization */ 315 * value of the LSB, so we are sure both bytes belong to the same value.
316 * Must be called with data->update_lock held, except during initialization
317 */
314static u16 f71805f_read16(struct f71805f_data *data, u8 reg) 318static u16 f71805f_read16(struct f71805f_data *data, u8 reg)
315{ 319{
316 u16 val; 320 u16 val;
@@ -455,7 +459,12 @@ static ssize_t set_in0_max(struct device *dev, struct device_attribute
455 struct f71805f_data *data = dev_get_drvdata(dev); 459 struct f71805f_data *data = dev_get_drvdata(dev);
456 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 460 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
457 int nr = attr->index; 461 int nr = attr->index;
458 long val = simple_strtol(buf, NULL, 10); 462 long val;
463 int err;
464
465 err = kstrtol(buf, 10, &val);
466 if (err)
467 return err;
459 468
460 mutex_lock(&data->update_lock); 469 mutex_lock(&data->update_lock);
461 data->in_high[nr] = in0_to_reg(val); 470 data->in_high[nr] = in0_to_reg(val);
@@ -471,7 +480,12 @@ static ssize_t set_in0_min(struct device *dev, struct device_attribute
471 struct f71805f_data *data = dev_get_drvdata(dev); 480 struct f71805f_data *data = dev_get_drvdata(dev);
472 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 481 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
473 int nr = attr->index; 482 int nr = attr->index;
474 long val = simple_strtol(buf, NULL, 10); 483 long val;
484 int err;
485
486 err = kstrtol(buf, 10, &val);
487 if (err)
488 return err;
475 489
476 mutex_lock(&data->update_lock); 490 mutex_lock(&data->update_lock);
477 data->in_low[nr] = in0_to_reg(val); 491 data->in_low[nr] = in0_to_reg(val);
@@ -517,7 +531,12 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute
517 struct f71805f_data *data = dev_get_drvdata(dev); 531 struct f71805f_data *data = dev_get_drvdata(dev);
518 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 532 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
519 int nr = attr->index; 533 int nr = attr->index;
520 long val = simple_strtol(buf, NULL, 10); 534 long val;
535 int err;
536
537 err = kstrtol(buf, 10, &val);
538 if (err)
539 return err;
521 540
522 mutex_lock(&data->update_lock); 541 mutex_lock(&data->update_lock);
523 data->in_high[nr] = in_to_reg(val); 542 data->in_high[nr] = in_to_reg(val);
@@ -533,7 +552,12 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute
533 struct f71805f_data *data = dev_get_drvdata(dev); 552 struct f71805f_data *data = dev_get_drvdata(dev);
534 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 553 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
535 int nr = attr->index; 554 int nr = attr->index;
536 long val = simple_strtol(buf, NULL, 10); 555 long val;
556 int err;
557
558 err = kstrtol(buf, 10, &val);
559 if (err)
560 return err;
537 561
538 mutex_lock(&data->update_lock); 562 mutex_lock(&data->update_lock);
539 data->in_low[nr] = in_to_reg(val); 563 data->in_low[nr] = in_to_reg(val);
@@ -579,7 +603,12 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute
579 struct f71805f_data *data = dev_get_drvdata(dev); 603 struct f71805f_data *data = dev_get_drvdata(dev);
580 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 604 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
581 int nr = attr->index; 605 int nr = attr->index;
582 long val = simple_strtol(buf, NULL, 10); 606 long val;
607 int err;
608
609 err = kstrtol(buf, 10, &val);
610 if (err)
611 return err;
583 612
584 mutex_lock(&data->update_lock); 613 mutex_lock(&data->update_lock);
585 data->fan_low[nr] = fan_to_reg(val); 614 data->fan_low[nr] = fan_to_reg(val);
@@ -595,7 +624,12 @@ static ssize_t set_fan_target(struct device *dev, struct device_attribute
595 struct f71805f_data *data = dev_get_drvdata(dev); 624 struct f71805f_data *data = dev_get_drvdata(dev);
596 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 625 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
597 int nr = attr->index; 626 int nr = attr->index;
598 long val = simple_strtol(buf, NULL, 10); 627 long val;
628 int err;
629
630 err = kstrtol(buf, 10, &val);
631 if (err)
632 return err;
599 633
600 mutex_lock(&data->update_lock); 634 mutex_lock(&data->update_lock);
601 data->fan_target[nr] = fan_to_reg(val); 635 data->fan_target[nr] = fan_to_reg(val);
@@ -664,7 +698,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr,
664 struct f71805f_data *data = dev_get_drvdata(dev); 698 struct f71805f_data *data = dev_get_drvdata(dev);
665 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 699 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
666 int nr = attr->index; 700 int nr = attr->index;
667 unsigned long val = simple_strtoul(buf, NULL, 10); 701 unsigned long val;
702 int err;
703
704 err = kstrtoul(buf, 10, &val);
705 if (err)
706 return err;
668 707
669 if (val > 255) 708 if (val > 255)
670 return -EINVAL; 709 return -EINVAL;
@@ -685,8 +724,13 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute
685 struct f71805f_data *data = dev_get_drvdata(dev); 724 struct f71805f_data *data = dev_get_drvdata(dev);
686 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 725 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
687 int nr = attr->index; 726 int nr = attr->index;
688 unsigned long val = simple_strtoul(buf, NULL, 10);
689 u8 reg; 727 u8 reg;
728 unsigned long val;
729 int err;
730
731 err = kstrtoul(buf, 10, &val);
732 if (err)
733 return err;
690 734
691 if (val < 1 || val > 3) 735 if (val < 1 || val > 3)
692 return -EINVAL; 736 return -EINVAL;
@@ -730,7 +774,12 @@ static ssize_t set_pwm_freq(struct device *dev, struct device_attribute
730 struct f71805f_data *data = dev_get_drvdata(dev); 774 struct f71805f_data *data = dev_get_drvdata(dev);
731 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 775 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
732 int nr = attr->index; 776 int nr = attr->index;
733 unsigned long val = simple_strtoul(buf, NULL, 10); 777 unsigned long val;
778 int err;
779
780 err = kstrtoul(buf, 10, &val);
781 if (err)
782 return err;
734 783
735 mutex_lock(&data->update_lock); 784 mutex_lock(&data->update_lock);
736 data->pwm_freq[nr] = pwm_freq_to_reg(val); 785 data->pwm_freq[nr] = pwm_freq_to_reg(val);
@@ -742,7 +791,7 @@ static ssize_t set_pwm_freq(struct device *dev, struct device_attribute
742 791
743static ssize_t show_pwm_auto_point_temp(struct device *dev, 792static ssize_t show_pwm_auto_point_temp(struct device *dev,
744 struct device_attribute *devattr, 793 struct device_attribute *devattr,
745 char* buf) 794 char *buf)
746{ 795{
747 struct f71805f_data *data = dev_get_drvdata(dev); 796 struct f71805f_data *data = dev_get_drvdata(dev);
748 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 797 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
@@ -755,13 +804,18 @@ static ssize_t show_pwm_auto_point_temp(struct device *dev,
755 804
756static ssize_t set_pwm_auto_point_temp(struct device *dev, 805static ssize_t set_pwm_auto_point_temp(struct device *dev,
757 struct device_attribute *devattr, 806 struct device_attribute *devattr,
758 const char* buf, size_t count) 807 const char *buf, size_t count)
759{ 808{
760 struct f71805f_data *data = dev_get_drvdata(dev); 809 struct f71805f_data *data = dev_get_drvdata(dev);
761 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 810 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
762 int pwmnr = attr->nr; 811 int pwmnr = attr->nr;
763 int apnr = attr->index; 812 int apnr = attr->index;
764 unsigned long val = simple_strtol(buf, NULL, 10); 813 unsigned long val;
814 int err;
815
816 err = kstrtoul(buf, 10, &val);
817 if (err)
818 return err;
765 819
766 mutex_lock(&data->update_lock); 820 mutex_lock(&data->update_lock);
767 data->auto_points[pwmnr].temp[apnr] = temp_to_reg(val); 821 data->auto_points[pwmnr].temp[apnr] = temp_to_reg(val);
@@ -774,7 +828,7 @@ static ssize_t set_pwm_auto_point_temp(struct device *dev,
774 828
775static ssize_t show_pwm_auto_point_fan(struct device *dev, 829static ssize_t show_pwm_auto_point_fan(struct device *dev,
776 struct device_attribute *devattr, 830 struct device_attribute *devattr,
777 char* buf) 831 char *buf)
778{ 832{
779 struct f71805f_data *data = dev_get_drvdata(dev); 833 struct f71805f_data *data = dev_get_drvdata(dev);
780 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 834 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
@@ -787,18 +841,23 @@ static ssize_t show_pwm_auto_point_fan(struct device *dev,
787 841
788static ssize_t set_pwm_auto_point_fan(struct device *dev, 842static ssize_t set_pwm_auto_point_fan(struct device *dev,
789 struct device_attribute *devattr, 843 struct device_attribute *devattr,
790 const char* buf, size_t count) 844 const char *buf, size_t count)
791{ 845{
792 struct f71805f_data *data = dev_get_drvdata(dev); 846 struct f71805f_data *data = dev_get_drvdata(dev);
793 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 847 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
794 int pwmnr = attr->nr; 848 int pwmnr = attr->nr;
795 int apnr = attr->index; 849 int apnr = attr->index;
796 unsigned long val = simple_strtoul(buf, NULL, 10); 850 unsigned long val;
851 int err;
852
853 err = kstrtoul(buf, 10, &val);
854 if (err)
855 return err;
797 856
798 mutex_lock(&data->update_lock); 857 mutex_lock(&data->update_lock);
799 data->auto_points[pwmnr].fan[apnr] = fan_to_reg(val); 858 data->auto_points[pwmnr].fan[apnr] = fan_to_reg(val);
800 f71805f_write16(data, F71805F_REG_PWM_AUTO_POINT_FAN(pwmnr, apnr), 859 f71805f_write16(data, F71805F_REG_PWM_AUTO_POINT_FAN(pwmnr, apnr),
801 data->auto_points[pwmnr].fan[apnr]); 860 data->auto_points[pwmnr].fan[apnr]);
802 mutex_unlock(&data->update_lock); 861 mutex_unlock(&data->update_lock);
803 862
804 return count; 863 return count;
@@ -851,7 +910,12 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute
851 struct f71805f_data *data = dev_get_drvdata(dev); 910 struct f71805f_data *data = dev_get_drvdata(dev);
852 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 911 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
853 int nr = attr->index; 912 int nr = attr->index;
854 long val = simple_strtol(buf, NULL, 10); 913 long val;
914 int err;
915
916 err = kstrtol(buf, 10, &val);
917 if (err)
918 return err;
855 919
856 mutex_lock(&data->update_lock); 920 mutex_lock(&data->update_lock);
857 data->temp_high[nr] = temp_to_reg(val); 921 data->temp_high[nr] = temp_to_reg(val);
@@ -867,7 +931,12 @@ static ssize_t set_temp_hyst(struct device *dev, struct device_attribute
867 struct f71805f_data *data = dev_get_drvdata(dev); 931 struct f71805f_data *data = dev_get_drvdata(dev);
868 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 932 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
869 int nr = attr->index; 933 int nr = attr->index;
870 long val = simple_strtol(buf, NULL, 10); 934 long val;
935 int err;
936
937 err = kstrtol(buf, 10, &val);
938 if (err)
939 return err;
871 940
872 mutex_lock(&data->update_lock); 941 mutex_lock(&data->update_lock);
873 data->temp_hyst[nr] = temp_to_reg(val); 942 data->temp_hyst[nr] = temp_to_reg(val);
@@ -920,9 +989,9 @@ static ssize_t show_name(struct device *dev, struct device_attribute
920} 989}
921 990
922static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_in0, NULL, 0); 991static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_in0, NULL, 0);
923static SENSOR_DEVICE_ATTR(in0_max, S_IRUGO| S_IWUSR, 992static SENSOR_DEVICE_ATTR(in0_max, S_IRUGO | S_IWUSR,
924 show_in0_max, set_in0_max, 0); 993 show_in0_max, set_in0_max, 0);
925static SENSOR_DEVICE_ATTR(in0_min, S_IRUGO| S_IWUSR, 994static SENSOR_DEVICE_ATTR(in0_min, S_IRUGO | S_IWUSR,
926 show_in0_min, set_in0_min, 0); 995 show_in0_min, set_in0_min, 0);
927static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in, NULL, 1); 996static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in, NULL, 1);
928static SENSOR_DEVICE_ATTR(in1_max, S_IRUGO | S_IWUSR, 997static SENSOR_DEVICE_ATTR(in1_max, S_IRUGO | S_IWUSR,
@@ -1010,8 +1079,10 @@ static SENSOR_DEVICE_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR,
1010 show_temp_hyst, set_temp_hyst, 2); 1079 show_temp_hyst, set_temp_hyst, 2);
1011static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2); 1080static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2);
1012 1081
1013/* pwm (value) files are created read-only, write permission is 1082/*
1014 then added or removed dynamically as needed */ 1083 * pwm (value) files are created read-only, write permission is
1084 * then added or removed dynamically as needed
1085 */
1015static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO, show_pwm, set_pwm, 0); 1086static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO, show_pwm, set_pwm, 0);
1016static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, 1087static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
1017 show_pwm_enable, set_pwm_enable, 0); 1088 show_pwm_enable, set_pwm_enable, 0);
@@ -1246,8 +1317,10 @@ static const struct attribute_group f71805f_group_optin[4] = {
1246 { .attrs = f71805f_attributes_optin[3] }, 1317 { .attrs = f71805f_attributes_optin[3] },
1247}; 1318};
1248 1319
1249/* We don't include pwm_freq files in the arrays above, because they must be 1320/*
1250 created conditionally (only if pwm_mode is 1 == PWM) */ 1321 * We don't include pwm_freq files in the arrays above, because they must be
1322 * created conditionally (only if pwm_mode is 1 == PWM)
1323 */
1251static struct attribute *f71805f_attributes_pwm_freq[] = { 1324static struct attribute *f71805f_attributes_pwm_freq[] = {
1252 &sensor_dev_attr_pwm1_freq.dev_attr.attr, 1325 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
1253 &sensor_dev_attr_pwm2_freq.dev_attr.attr, 1326 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
@@ -1282,13 +1355,17 @@ static void __devinit f71805f_init_device(struct f71805f_data *data)
1282 f71805f_write8(data, F71805F_REG_START, (reg | 0x01) & ~0x40); 1355 f71805f_write8(data, F71805F_REG_START, (reg | 0x01) & ~0x40);
1283 } 1356 }
1284 1357
1285 /* Fan monitoring can be disabled. If it is, we won't be polling 1358 /*
1286 the register values, and won't create the related sysfs files. */ 1359 * Fan monitoring can be disabled. If it is, we won't be polling
1360 * the register values, and won't create the related sysfs files.
1361 */
1287 for (i = 0; i < 3; i++) { 1362 for (i = 0; i < 3; i++) {
1288 data->fan_ctrl[i] = f71805f_read8(data, 1363 data->fan_ctrl[i] = f71805f_read8(data,
1289 F71805F_REG_FAN_CTRL(i)); 1364 F71805F_REG_FAN_CTRL(i));
1290 /* Clear latch full bit, else "speed mode" fan speed control 1365 /*
1291 doesn't work */ 1366 * Clear latch full bit, else "speed mode" fan speed control
1367 * doesn't work
1368 */
1292 if (data->fan_ctrl[i] & FAN_CTRL_LATCH_FULL) { 1369 if (data->fan_ctrl[i] & FAN_CTRL_LATCH_FULL) {
1293 data->fan_ctrl[i] &= ~FAN_CTRL_LATCH_FULL; 1370 data->fan_ctrl[i] &= ~FAN_CTRL_LATCH_FULL;
1294 f71805f_write8(data, F71805F_REG_FAN_CTRL(i), 1371 f71805f_write8(data, F71805F_REG_FAN_CTRL(i),
@@ -1304,12 +1381,13 @@ static int __devinit f71805f_probe(struct platform_device *pdev)
1304 struct resource *res; 1381 struct resource *res;
1305 int i, err; 1382 int i, err;
1306 1383
1307 static const char *names[] = { 1384 static const char * const names[] = {
1308 "f71805f", 1385 "f71805f",
1309 "f71872f", 1386 "f71872f",
1310 }; 1387 };
1311 1388
1312 if (!(data = kzalloc(sizeof(struct f71805f_data), GFP_KERNEL))) { 1389 data = kzalloc(sizeof(struct f71805f_data), GFP_KERNEL);
1390 if (!data) {
1313 err = -ENOMEM; 1391 err = -ENOMEM;
1314 pr_err("Out of memory\n"); 1392 pr_err("Out of memory\n");
1315 goto exit; 1393 goto exit;
@@ -1347,40 +1425,47 @@ static int __devinit f71805f_probe(struct platform_device *pdev)
1347 f71805f_init_device(data); 1425 f71805f_init_device(data);
1348 1426
1349 /* Register sysfs interface files */ 1427 /* Register sysfs interface files */
1350 if ((err = sysfs_create_group(&pdev->dev.kobj, &f71805f_group))) 1428 err = sysfs_create_group(&pdev->dev.kobj, &f71805f_group);
1429 if (err)
1351 goto exit_release_region; 1430 goto exit_release_region;
1352 if (data->has_in & (1 << 4)) { /* in4 */ 1431 if (data->has_in & (1 << 4)) { /* in4 */
1353 if ((err = sysfs_create_group(&pdev->dev.kobj, 1432 err = sysfs_create_group(&pdev->dev.kobj,
1354 &f71805f_group_optin[0]))) 1433 &f71805f_group_optin[0]);
1434 if (err)
1355 goto exit_remove_files; 1435 goto exit_remove_files;
1356 } 1436 }
1357 if (data->has_in & (1 << 8)) { /* in8 */ 1437 if (data->has_in & (1 << 8)) { /* in8 */
1358 if ((err = sysfs_create_group(&pdev->dev.kobj, 1438 err = sysfs_create_group(&pdev->dev.kobj,
1359 &f71805f_group_optin[1]))) 1439 &f71805f_group_optin[1]);
1440 if (err)
1360 goto exit_remove_files; 1441 goto exit_remove_files;
1361 } 1442 }
1362 if (data->has_in & (1 << 9)) { /* in9 (F71872F/FG only) */ 1443 if (data->has_in & (1 << 9)) { /* in9 (F71872F/FG only) */
1363 if ((err = sysfs_create_group(&pdev->dev.kobj, 1444 err = sysfs_create_group(&pdev->dev.kobj,
1364 &f71805f_group_optin[2]))) 1445 &f71805f_group_optin[2]);
1446 if (err)
1365 goto exit_remove_files; 1447 goto exit_remove_files;
1366 } 1448 }
1367 if (data->has_in & (1 << 10)) { /* in9 (F71872F/FG only) */ 1449 if (data->has_in & (1 << 10)) { /* in9 (F71872F/FG only) */
1368 if ((err = sysfs_create_group(&pdev->dev.kobj, 1450 err = sysfs_create_group(&pdev->dev.kobj,
1369 &f71805f_group_optin[3]))) 1451 &f71805f_group_optin[3]);
1452 if (err)
1370 goto exit_remove_files; 1453 goto exit_remove_files;
1371 } 1454 }
1372 for (i = 0; i < 3; i++) { 1455 for (i = 0; i < 3; i++) {
1373 /* If control mode is PWM, create pwm_freq file */ 1456 /* If control mode is PWM, create pwm_freq file */
1374 if (!(data->fan_ctrl[i] & FAN_CTRL_DC_MODE)) { 1457 if (!(data->fan_ctrl[i] & FAN_CTRL_DC_MODE)) {
1375 if ((err = sysfs_create_file(&pdev->dev.kobj, 1458 err = sysfs_create_file(&pdev->dev.kobj,
1376 f71805f_attributes_pwm_freq[i]))) 1459 f71805f_attributes_pwm_freq[i]);
1460 if (err)
1377 goto exit_remove_files; 1461 goto exit_remove_files;
1378 } 1462 }
1379 /* If PWM is in manual mode, add write permission */ 1463 /* If PWM is in manual mode, add write permission */
1380 if (data->fan_ctrl[i] & FAN_CTRL_MODE_MANUAL) { 1464 if (data->fan_ctrl[i] & FAN_CTRL_MODE_MANUAL) {
1381 if ((err = sysfs_chmod_file(&pdev->dev.kobj, 1465 err = sysfs_chmod_file(&pdev->dev.kobj,
1382 f71805f_attr_pwm[i], 1466 f71805f_attr_pwm[i],
1383 S_IRUGO | S_IWUSR))) { 1467 S_IRUGO | S_IWUSR);
1468 if (err) {
1384 dev_err(&pdev->dev, "chmod +w pwm%d failed\n", 1469 dev_err(&pdev->dev, "chmod +w pwm%d failed\n",
1385 i + 1); 1470 i + 1);
1386 goto exit_remove_files; 1471 goto exit_remove_files;
@@ -1495,7 +1580,7 @@ static int __init f71805f_find(int sioaddr, unsigned short *address,
1495 int err = -ENODEV; 1580 int err = -ENODEV;
1496 u16 devid; 1581 u16 devid;
1497 1582
1498 static const char *names[] = { 1583 static const char * const names[] = {
1499 "F71805F/FG", 1584 "F71805F/FG",
1500 "F71872F/FG or F71806F/FG", 1585 "F71872F/FG or F71806F/FG",
1501 }; 1586 };
diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c
index e50305819f01..6d1226365e30 100644
--- a/drivers/hwmon/f71882fg.c
+++ b/drivers/hwmon/f71882fg.c
@@ -112,7 +112,7 @@ MODULE_PARM_DESC(force_id, "Override the detected device ID");
112enum chips { f71808e, f71808a, f71858fg, f71862fg, f71869, f71869a, f71882fg, 112enum chips { f71808e, f71808a, f71858fg, f71862fg, f71869, f71869a, f71882fg,
113 f71889fg, f71889ed, f71889a, f8000, f81865f }; 113 f71889fg, f71889ed, f71889a, f8000, f81865f };
114 114
115static const char *f71882fg_names[] = { 115static const char *const f71882fg_names[] = {
116 "f71808e", 116 "f71808e",
117 "f71808a", 117 "f71808a",
118 "f71858fg", 118 "f71858fg",
@@ -252,9 +252,11 @@ struct f71882fg_data {
252 u16 fan_full_speed[4]; 252 u16 fan_full_speed[4];
253 u8 fan_status; 253 u8 fan_status;
254 u8 fan_beep; 254 u8 fan_beep;
255 /* Note: all models have max 3 temperature channels, but on some 255 /*
256 they are addressed as 0-2 and on others as 1-3, so for coding 256 * Note: all models have max 3 temperature channels, but on some
257 convenience we reserve space for 4 channels */ 257 * they are addressed as 0-2 and on others as 1-3, so for coding
258 * convenience we reserve space for 4 channels
259 */
258 u16 temp[4]; 260 u16 temp[4];
259 u8 temp_ovt[4]; 261 u8 temp_ovt[4];
260 u8 temp_high[4]; 262 u8 temp_high[4];
@@ -362,7 +364,7 @@ static ssize_t store_pwm_auto_point_temp(struct device *dev,
362static ssize_t show_name(struct device *dev, struct device_attribute *devattr, 364static ssize_t show_name(struct device *dev, struct device_attribute *devattr,
363 char *buf); 365 char *buf);
364 366
365static int __devinit f71882fg_probe(struct platform_device * pdev); 367static int __devinit f71882fg_probe(struct platform_device *pdev);
366static int f71882fg_remove(struct platform_device *pdev); 368static int f71882fg_remove(struct platform_device *pdev);
367 369
368static struct platform_driver f71882fg_driver = { 370static struct platform_driver f71882fg_driver = {
@@ -376,8 +378,10 @@ static struct platform_driver f71882fg_driver = {
376 378
377static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 379static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
378 380
379/* Temp attr for the f71858fg, the f71858fg is special as it has its 381/*
380 temperature indexes start at 0 (the others start at 1) */ 382 * Temp attr for the f71858fg, the f71858fg is special as it has its
383 * temperature indexes start at 0 (the others start at 1)
384 */
381static struct sensor_device_attribute_2 f71858fg_temp_attr[] = { 385static struct sensor_device_attribute_2 f71858fg_temp_attr[] = {
382 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0), 386 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0),
383 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max, 387 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max,
@@ -424,9 +428,11 @@ static struct sensor_device_attribute_2 fxxxx_temp_attr[3][9] = { {
424 store_temp_max, 0, 1), 428 store_temp_max, 0, 1),
425 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst, 429 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
426 store_temp_max_hyst, 0, 1), 430 store_temp_max_hyst, 0, 1),
427 /* Should really be temp1_max_alarm, but older versions did not handle 431 /*
428 the max and crit alarms separately and lm_sensors v2 depends on the 432 * Should really be temp1_max_alarm, but older versions did not handle
429 presence of temp#_alarm files. The same goes for temp2/3 _alarm. */ 433 * the max and crit alarms separately and lm_sensors v2 depends on the
434 * presence of temp#_alarm files. The same goes for temp2/3 _alarm.
435 */
430 SENSOR_ATTR_2(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 1), 436 SENSOR_ATTR_2(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 1),
431 SENSOR_ATTR_2(temp1_crit, S_IRUGO|S_IWUSR, show_temp_crit, 437 SENSOR_ATTR_2(temp1_crit, S_IRUGO|S_IWUSR, show_temp_crit,
432 store_temp_crit, 0, 1), 438 store_temp_crit, 0, 1),
@@ -485,10 +491,11 @@ static struct sensor_device_attribute_2 fxxxx_temp_beep_attr[3][2] = { {
485 store_temp_beep, 0, 7), 491 store_temp_beep, 0, 7),
486} }; 492} };
487 493
488/* Temp attr for the f8000 494/*
489 Note on the f8000 temp_ovt (crit) is used as max, and temp_high (max) 495 * Temp attr for the f8000
490 is used as hysteresis value to clear alarms 496 * Note on the f8000 temp_ovt (crit) is used as max, and temp_high (max)
491 Also like the f71858fg its temperature indexes start at 0 497 * is used as hysteresis value to clear alarms
498 * Also like the f71858fg its temperature indexes start at 0
492 */ 499 */
493static struct sensor_device_attribute_2 f8000_temp_attr[] = { 500static struct sensor_device_attribute_2 f8000_temp_attr[] = {
494 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0), 501 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0),
@@ -603,8 +610,10 @@ static struct sensor_device_attribute_2 fxxxx_fan_beep_attr[] = {
603 store_fan_beep, 0, 3), 610 store_fan_beep, 0, 3),
604}; 611};
605 612
606/* PWM attr for the f71862fg, fewer pwms and fewer zones per pwm than the 613/*
607 standard models */ 614 * PWM attr for the f71862fg, fewer pwms and fewer zones per pwm than the
615 * standard models
616 */
608static struct sensor_device_attribute_2 f71862fg_auto_pwm_attr[3][7] = { { 617static struct sensor_device_attribute_2 f71862fg_auto_pwm_attr[3][7] = { {
609 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR, 618 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
610 show_pwm_auto_point_channel, 619 show_pwm_auto_point_channel,
@@ -673,9 +682,11 @@ static struct sensor_device_attribute_2 f71862fg_auto_pwm_attr[3][7] = { {
673 show_pwm_auto_point_temp_hyst, NULL, 3, 2), 682 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
674} }; 683} };
675 684
676/* PWM attr for the f71808e/f71869, almost identical to the f71862fg, but the 685/*
677 pwm setting when the temperature is above the pwmX_auto_point1_temp can be 686 * PWM attr for the f71808e/f71869, almost identical to the f71862fg, but the
678 programmed instead of being hardcoded to 0xff */ 687 * pwm setting when the temperature is above the pwmX_auto_point1_temp can be
688 * programmed instead of being hardcoded to 0xff
689 */
679static struct sensor_device_attribute_2 f71869_auto_pwm_attr[3][8] = { { 690static struct sensor_device_attribute_2 f71869_auto_pwm_attr[3][8] = { {
680 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR, 691 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
681 show_pwm_auto_point_channel, 692 show_pwm_auto_point_channel,
@@ -925,9 +936,11 @@ static struct sensor_device_attribute_2 f8000_fan_attr[] = {
925 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3), 936 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
926}; 937};
927 938
928/* PWM attr for the f8000, zones mapped to temp instead of to pwm! 939/*
929 Also the register block at offset A0 maps to TEMP1 (so our temp2, as the 940 * PWM attr for the f8000, zones mapped to temp instead of to pwm!
930 F8000 starts counting temps at 0), B0 maps the TEMP2 and C0 maps to TEMP0 */ 941 * Also the register block at offset A0 maps to TEMP1 (so our temp2, as the
942 * F8000 starts counting temps at 0), B0 maps the TEMP2 and C0 maps to TEMP0
943 */
931static struct sensor_device_attribute_2 f8000_auto_pwm_attr[3][14] = { { 944static struct sensor_device_attribute_2 f8000_auto_pwm_attr[3][14] = { {
932 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR, 945 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
933 show_pwm_auto_point_channel, 946 show_pwm_auto_point_channel,
@@ -2295,8 +2308,10 @@ static int __devinit f71882fg_probe(struct platform_device *pdev)
2295 data->temp_config = 2308 data->temp_config =
2296 f71882fg_read8(data, F71882FG_REG_TEMP_CONFIG); 2309 f71882fg_read8(data, F71882FG_REG_TEMP_CONFIG);
2297 if (data->temp_config & 0x10) 2310 if (data->temp_config & 0x10)
2298 /* The f71858fg temperature alarms behave as 2311 /*
2299 the f8000 alarms in this mode */ 2312 * The f71858fg temperature alarms behave as
2313 * the f8000 alarms in this mode
2314 */
2300 err = f71882fg_create_sysfs_files(pdev, 2315 err = f71882fg_create_sysfs_files(pdev,
2301 f8000_temp_attr, 2316 f8000_temp_attr,
2302 ARRAY_SIZE(f8000_temp_attr)); 2317 ARRAY_SIZE(f8000_temp_attr));
diff --git a/drivers/hwmon/f75375s.c b/drivers/hwmon/f75375s.c
index 6aa5a9fad879..729499e75210 100644
--- a/drivers/hwmon/f75375s.c
+++ b/drivers/hwmon/f75375s.c
@@ -917,19 +917,8 @@ static int f75375_detect(struct i2c_client *client,
917 return 0; 917 return 0;
918} 918}
919 919
920static int __init sensors_f75375_init(void) 920module_i2c_driver(f75375_driver);
921{
922 return i2c_add_driver(&f75375_driver);
923}
924
925static void __exit sensors_f75375_exit(void)
926{
927 i2c_del_driver(&f75375_driver);
928}
929 921
930MODULE_AUTHOR("Riku Voipio"); 922MODULE_AUTHOR("Riku Voipio");
931MODULE_LICENSE("GPL"); 923MODULE_LICENSE("GPL");
932MODULE_DESCRIPTION("F75373/F75375/F75387 hardware monitoring driver"); 924MODULE_DESCRIPTION("F75373/F75375/F75387 hardware monitoring driver");
933
934module_init(sensors_f75375_init);
935module_exit(sensors_f75375_exit);
diff --git a/drivers/hwmon/fschmd.c b/drivers/hwmon/fschmd.c
index aa6d8b686f82..8305d29459bd 100644
--- a/drivers/hwmon/fschmd.c
+++ b/drivers/hwmon/fschmd.c
@@ -1,4 +1,5 @@
1/* fschmd.c 1/*
2 * fschmd.c
2 * 3 *
3 * Copyright (C) 2007 - 2009 Hans de Goede <hdegoede@redhat.com> 4 * Copyright (C) 2007 - 2009 Hans de Goede <hdegoede@redhat.com>
4 * 5 *
@@ -76,12 +77,12 @@ enum chips { fscpos, fscher, fscscy, fschrc, fschmd, fschds, fscsyl };
76#define FSCHMD_CONTROL_ALERT_LED 0x01 77#define FSCHMD_CONTROL_ALERT_LED 0x01
77 78
78/* watchdog */ 79/* watchdog */
79static const u8 FSCHMD_REG_WDOG_CONTROL[7] = 80static const u8 FSCHMD_REG_WDOG_CONTROL[7] = {
80 { 0x21, 0x21, 0x21, 0x21, 0x21, 0x28, 0x28 }; 81 0x21, 0x21, 0x21, 0x21, 0x21, 0x28, 0x28 };
81static const u8 FSCHMD_REG_WDOG_STATE[7] = 82static const u8 FSCHMD_REG_WDOG_STATE[7] = {
82 { 0x23, 0x23, 0x23, 0x23, 0x23, 0x29, 0x29 }; 83 0x23, 0x23, 0x23, 0x23, 0x23, 0x29, 0x29 };
83static const u8 FSCHMD_REG_WDOG_PRESET[7] = 84static const u8 FSCHMD_REG_WDOG_PRESET[7] = {
84 { 0x28, 0x28, 0x28, 0x28, 0x28, 0x2a, 0x2a }; 85 0x28, 0x28, 0x28, 0x28, 0x28, 0x2a, 0x2a };
85 86
86#define FSCHMD_WDOG_CONTROL_TRIGGER 0x10 87#define FSCHMD_WDOG_CONTROL_TRIGGER 0x10
87#define FSCHMD_WDOG_CONTROL_STARTED 0x10 /* the same as trigger */ 88#define FSCHMD_WDOG_CONTROL_STARTED 0x10 /* the same as trigger */
@@ -103,10 +104,12 @@ static const u8 FSCHMD_REG_VOLT[7][6] = {
103 104
104static const int FSCHMD_NO_VOLT_SENSORS[7] = { 3, 3, 3, 3, 3, 3, 6 }; 105static const int FSCHMD_NO_VOLT_SENSORS[7] = { 3, 3, 3, 3, 3, 3, 6 };
105 106
106/* minimum pwm at which the fan is driven (pwm can by increased depending on 107/*
107 the temp. Notice that for the scy some fans share there minimum speed. 108 * minimum pwm at which the fan is driven (pwm can by increased depending on
108 Also notice that with the scy the sensor order is different than with the 109 * the temp. Notice that for the scy some fans share there minimum speed.
109 other chips, this order was in the 2.4 driver and kept for consistency. */ 110 * Also notice that with the scy the sensor order is different than with the
111 * other chips, this order was in the 2.4 driver and kept for consistency.
112 */
110static const u8 FSCHMD_REG_FAN_MIN[7][7] = { 113static const u8 FSCHMD_REG_FAN_MIN[7][7] = {
111 { 0x55, 0x65 }, /* pos */ 114 { 0x55, 0x65 }, /* pos */
112 { 0x55, 0x65, 0xb5 }, /* her */ 115 { 0x55, 0x65, 0xb5 }, /* her */
@@ -182,11 +185,13 @@ static const u8 FSCHMD_REG_TEMP_STATE[7][11] = {
182 0xb9, 0xc9, 0xd9, 0xe9, 0xf9 }, 185 0xb9, 0xc9, 0xd9, 0xe9, 0xf9 },
183}; 186};
184 187
185/* temperature high limit registers, FSC does not document these. Proven to be 188/*
186 there with field testing on the fscher and fschrc, already supported / used 189 * temperature high limit registers, FSC does not document these. Proven to be
187 in the fscscy 2.4 driver. FSC has confirmed that the fschmd has registers 190 * there with field testing on the fscher and fschrc, already supported / used
188 at these addresses, but doesn't want to confirm they are the same as with 191 * in the fscscy 2.4 driver. FSC has confirmed that the fschmd has registers
189 the fscher?? */ 192 * at these addresses, but doesn't want to confirm they are the same as with
193 * the fscher??
194 */
190static const u8 FSCHMD_REG_TEMP_LIMIT[7][11] = { 195static const u8 FSCHMD_REG_TEMP_LIMIT[7][11] = {
191 { 0, 0, 0 }, /* pos */ 196 { 0, 0, 0 }, /* pos */
192 { 0x76, 0x86, 0x96 }, /* her */ 197 { 0x76, 0x86, 0x96 }, /* her */
@@ -198,13 +203,15 @@ static const u8 FSCHMD_REG_TEMP_LIMIT[7][11] = {
198 0xba, 0xca, 0xda, 0xea, 0xfa }, 203 0xba, 0xca, 0xda, 0xea, 0xfa },
199}; 204};
200 205
201/* These were found through experimenting with an fscher, currently they are 206/*
202 not used, but we keep them around for future reference. 207 * These were found through experimenting with an fscher, currently they are
203 On the fscsyl AUTOP1 lives at 0x#c (so 0x5c for fan1, 0x6c for fan2, etc), 208 * not used, but we keep them around for future reference.
204 AUTOP2 lives at 0x#e, and 0x#1 is a bitmask defining which temps influence 209 * On the fscsyl AUTOP1 lives at 0x#c (so 0x5c for fan1, 0x6c for fan2, etc),
205 the fan speed. 210 * AUTOP2 lives at 0x#e, and 0x#1 is a bitmask defining which temps influence
206static const u8 FSCHER_REG_TEMP_AUTOP1[] = { 0x73, 0x83, 0x93 }; 211 * the fan speed.
207static const u8 FSCHER_REG_TEMP_AUTOP2[] = { 0x75, 0x85, 0x95 }; */ 212 * static const u8 FSCHER_REG_TEMP_AUTOP1[] = { 0x73, 0x83, 0x93 };
213 * static const u8 FSCHER_REG_TEMP_AUTOP2[] = { 0x75, 0x85, 0x95 };
214 */
208 215
209static const int FSCHMD_NO_TEMP_SENSORS[7] = { 3, 3, 4, 3, 5, 5, 11 }; 216static const int FSCHMD_NO_TEMP_SENSORS[7] = { 3, 3, 4, 3, 5, 5, 11 };
210 217
@@ -290,24 +297,30 @@ struct fschmd_data {
290 u8 fan_ripple[7]; /* divider for rps */ 297 u8 fan_ripple[7]; /* divider for rps */
291}; 298};
292 299
293/* Global variables to hold information read from special DMI tables, which are 300/*
294 available on FSC machines with an fscher or later chip. There is no need to 301 * Global variables to hold information read from special DMI tables, which are
295 protect these with a lock as they are only modified from our attach function 302 * available on FSC machines with an fscher or later chip. There is no need to
296 which always gets called with the i2c-core lock held and never accessed 303 * protect these with a lock as they are only modified from our attach function
297 before the attach function is done with them. */ 304 * which always gets called with the i2c-core lock held and never accessed
305 * before the attach function is done with them.
306 */
298static int dmi_mult[6] = { 490, 200, 100, 100, 200, 100 }; 307static int dmi_mult[6] = { 490, 200, 100, 100, 200, 100 };
299static int dmi_offset[6] = { 0, 0, 0, 0, 0, 0 }; 308static int dmi_offset[6] = { 0, 0, 0, 0, 0, 0 };
300static int dmi_vref = -1; 309static int dmi_vref = -1;
301 310
302/* Somewhat ugly :( global data pointer list with all fschmd devices, so that 311/*
303 we can find our device data as when using misc_register there is no other 312 * Somewhat ugly :( global data pointer list with all fschmd devices, so that
304 method to get to ones device data from the open fop. */ 313 * we can find our device data as when using misc_register there is no other
314 * method to get to ones device data from the open fop.
315 */
305static LIST_HEAD(watchdog_data_list); 316static LIST_HEAD(watchdog_data_list);
306/* Note this lock not only protect list access, but also data.kref access */ 317/* Note this lock not only protect list access, but also data.kref access */
307static DEFINE_MUTEX(watchdog_data_mutex); 318static DEFINE_MUTEX(watchdog_data_mutex);
308 319
309/* Release our data struct when we're detached from the i2c client *and* all 320/*
310 references to our watchdog device are released */ 321 * Release our data struct when we're detached from the i2c client *and* all
322 * references to our watchdog device are released
323 */
311static void fschmd_release_resources(struct kref *ref) 324static void fschmd_release_resources(struct kref *ref)
312{ 325{
313 struct fschmd_data *data = container_of(ref, struct fschmd_data, kref); 326 struct fschmd_data *data = container_of(ref, struct fschmd_data, kref);
@@ -359,9 +372,14 @@ static ssize_t store_temp_max(struct device *dev, struct device_attribute
359{ 372{
360 int index = to_sensor_dev_attr(devattr)->index; 373 int index = to_sensor_dev_attr(devattr)->index;
361 struct fschmd_data *data = dev_get_drvdata(dev); 374 struct fschmd_data *data = dev_get_drvdata(dev);
362 long v = simple_strtol(buf, NULL, 10) / 1000; 375 long v;
376 int err;
363 377
364 v = SENSORS_LIMIT(v, -128, 127) + 128; 378 err = kstrtol(buf, 10, &v);
379 if (err)
380 return err;
381
382 v = SENSORS_LIMIT(v / 1000, -128, 127) + 128;
365 383
366 mutex_lock(&data->update_lock); 384 mutex_lock(&data->update_lock);
367 i2c_smbus_write_byte_data(to_i2c_client(dev), 385 i2c_smbus_write_byte_data(to_i2c_client(dev),
@@ -427,12 +445,23 @@ static ssize_t store_fan_div(struct device *dev, struct device_attribute
427 int index = to_sensor_dev_attr(devattr)->index; 445 int index = to_sensor_dev_attr(devattr)->index;
428 struct fschmd_data *data = dev_get_drvdata(dev); 446 struct fschmd_data *data = dev_get_drvdata(dev);
429 /* supported values: 2, 4, 8 */ 447 /* supported values: 2, 4, 8 */
430 unsigned long v = simple_strtoul(buf, NULL, 10); 448 unsigned long v;
449 int err;
450
451 err = kstrtoul(buf, 10, &v);
452 if (err)
453 return err;
431 454
432 switch (v) { 455 switch (v) {
433 case 2: v = 1; break; 456 case 2:
434 case 4: v = 2; break; 457 v = 1;
435 case 8: v = 3; break; 458 break;
459 case 4:
460 v = 2;
461 break;
462 case 8:
463 v = 3;
464 break;
436 default: 465 default:
437 dev_err(dev, "fan_div value %lu not supported. " 466 dev_err(dev, "fan_div value %lu not supported. "
438 "Choose one of 2, 4 or 8!\n", v); 467 "Choose one of 2, 4 or 8!\n", v);
@@ -502,7 +531,12 @@ static ssize_t store_pwm_auto_point1_pwm(struct device *dev,
502{ 531{
503 int index = to_sensor_dev_attr(devattr)->index; 532 int index = to_sensor_dev_attr(devattr)->index;
504 struct fschmd_data *data = dev_get_drvdata(dev); 533 struct fschmd_data *data = dev_get_drvdata(dev);
505 unsigned long v = simple_strtoul(buf, NULL, 10); 534 unsigned long v;
535 int err;
536
537 err = kstrtoul(buf, 10, &v);
538 if (err)
539 return err;
506 540
507 /* reg: 0 = allow turning off (except on the syl), 1-255 = 50-100% */ 541 /* reg: 0 = allow turning off (except on the syl), 1-255 = 50-100% */
508 if (v || data->kind == fscsyl) { 542 if (v || data->kind == fscsyl) {
@@ -522,8 +556,10 @@ static ssize_t store_pwm_auto_point1_pwm(struct device *dev,
522} 556}
523 557
524 558
525/* The FSC hwmon family has the ability to force an attached alert led to flash 559/*
526 from software, we export this as an alert_led sysfs attr */ 560 * The FSC hwmon family has the ability to force an attached alert led to flash
561 * from software, we export this as an alert_led sysfs attr
562 */
527static ssize_t show_alert_led(struct device *dev, 563static ssize_t show_alert_led(struct device *dev,
528 struct device_attribute *devattr, char *buf) 564 struct device_attribute *devattr, char *buf)
529{ 565{
@@ -540,7 +576,12 @@ static ssize_t store_alert_led(struct device *dev,
540{ 576{
541 u8 reg; 577 u8 reg;
542 struct fschmd_data *data = dev_get_drvdata(dev); 578 struct fschmd_data *data = dev_get_drvdata(dev);
543 unsigned long v = simple_strtoul(buf, NULL, 10); 579 unsigned long v;
580 int err;
581
582 err = kstrtoul(buf, 10, &v);
583 if (err)
584 return err;
544 585
545 mutex_lock(&data->update_lock); 586 mutex_lock(&data->update_lock);
546 587
@@ -754,8 +795,10 @@ static int watchdog_stop(struct fschmd_data *data)
754 } 795 }
755 796
756 data->watchdog_control &= ~FSCHMD_WDOG_CONTROL_STARTED; 797 data->watchdog_control &= ~FSCHMD_WDOG_CONTROL_STARTED;
757 /* Don't store the stop flag in our watchdog control register copy, as 798 /*
758 its a write only bit (read always returns 0) */ 799 * Don't store the stop flag in our watchdog control register copy, as
800 * its a write only bit (read always returns 0)
801 */
759 i2c_smbus_write_byte_data(data->client, 802 i2c_smbus_write_byte_data(data->client,
760 FSCHMD_REG_WDOG_CONTROL[data->kind], 803 FSCHMD_REG_WDOG_CONTROL[data->kind],
761 data->watchdog_control | FSCHMD_WDOG_CONTROL_STOP); 804 data->watchdog_control | FSCHMD_WDOG_CONTROL_STOP);
@@ -769,10 +812,12 @@ static int watchdog_open(struct inode *inode, struct file *filp)
769 struct fschmd_data *pos, *data = NULL; 812 struct fschmd_data *pos, *data = NULL;
770 int watchdog_is_open; 813 int watchdog_is_open;
771 814
772 /* We get called from drivers/char/misc.c with misc_mtx hold, and we 815 /*
773 call misc_register() from fschmd_probe() with watchdog_data_mutex 816 * We get called from drivers/char/misc.c with misc_mtx hold, and we
774 hold, as misc_register() takes the misc_mtx lock, this is a possible 817 * call misc_register() from fschmd_probe() with watchdog_data_mutex
775 deadlock, so we use mutex_trylock here. */ 818 * hold, as misc_register() takes the misc_mtx lock, this is a possible
819 * deadlock, so we use mutex_trylock here.
820 */
776 if (!mutex_trylock(&watchdog_data_mutex)) 821 if (!mutex_trylock(&watchdog_data_mutex))
777 return -ERESTARTSYS; 822 return -ERESTARTSYS;
778 list_for_each_entry(pos, &watchdog_data_list, list) { 823 list_for_each_entry(pos, &watchdog_data_list, list) {
@@ -847,7 +892,8 @@ static ssize_t watchdog_write(struct file *filp, const char __user *buf,
847 return count; 892 return count;
848} 893}
849 894
850static long watchdog_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 895static long watchdog_ioctl(struct file *filp, unsigned int cmd,
896 unsigned long arg)
851{ 897{
852 struct watchdog_info ident = { 898 struct watchdog_info ident = {
853 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | 899 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT |
@@ -930,30 +976,38 @@ static const struct file_operations watchdog_fops = {
930 * Detect, register, unregister and update device functions 976 * Detect, register, unregister and update device functions
931 */ 977 */
932 978
933/* DMI decode routine to read voltage scaling factors from special DMI tables, 979/*
934 which are available on FSC machines with an fscher or later chip. */ 980 * DMI decode routine to read voltage scaling factors from special DMI tables,
981 * which are available on FSC machines with an fscher or later chip.
982 */
935static void fschmd_dmi_decode(const struct dmi_header *header, void *dummy) 983static void fschmd_dmi_decode(const struct dmi_header *header, void *dummy)
936{ 984{
937 int i, mult[3] = { 0 }, offset[3] = { 0 }, vref = 0, found = 0; 985 int i, mult[3] = { 0 }, offset[3] = { 0 }, vref = 0, found = 0;
938 986
939 /* dmi code ugliness, we get passed the address of the contents of 987 /*
940 a complete DMI record, but in the form of a dmi_header pointer, in 988 * dmi code ugliness, we get passed the address of the contents of
941 reality this address holds header->length bytes of which the header 989 * a complete DMI record, but in the form of a dmi_header pointer, in
942 are the first 4 bytes */ 990 * reality this address holds header->length bytes of which the header
991 * are the first 4 bytes
992 */
943 u8 *dmi_data = (u8 *)header; 993 u8 *dmi_data = (u8 *)header;
944 994
945 /* We are looking for OEM-specific type 185 */ 995 /* We are looking for OEM-specific type 185 */
946 if (header->type != 185) 996 if (header->type != 185)
947 return; 997 return;
948 998
949 /* we are looking for what Siemens calls "subtype" 19, the subtype 999 /*
950 is stored in byte 5 of the dmi block */ 1000 * we are looking for what Siemens calls "subtype" 19, the subtype
1001 * is stored in byte 5 of the dmi block
1002 */
951 if (header->length < 5 || dmi_data[4] != 19) 1003 if (header->length < 5 || dmi_data[4] != 19)
952 return; 1004 return;
953 1005
954 /* After the subtype comes 1 unknown byte and then blocks of 5 bytes, 1006 /*
955 consisting of what Siemens calls an "Entity" number, followed by 1007 * After the subtype comes 1 unknown byte and then blocks of 5 bytes,
956 2 16-bit words in LSB first order */ 1008 * consisting of what Siemens calls an "Entity" number, followed by
1009 * 2 16-bit words in LSB first order
1010 */
957 for (i = 6; (i + 4) < header->length; i += 5) { 1011 for (i = 6; (i + 4) < header->length; i += 5) {
958 /* entity 1 - 3: voltage multiplier and offset */ 1012 /* entity 1 - 3: voltage multiplier and offset */
959 if (dmi_data[i] >= 1 && dmi_data[i] <= 3) { 1013 if (dmi_data[i] >= 1 && dmi_data[i] <= 3) {
@@ -988,9 +1042,11 @@ static void fschmd_dmi_decode(const struct dmi_header *header, void *dummy)
988 dmi_mult[i] = mult[i] * 10; 1042 dmi_mult[i] = mult[i] * 10;
989 dmi_offset[i] = offset[i] * 10; 1043 dmi_offset[i] = offset[i] * 10;
990 } 1044 }
991 /* According to the docs there should be separate dmi entries 1045 /*
992 for the mult's and offsets of in3-5 of the syl, but on 1046 * According to the docs there should be separate dmi entries
993 my test machine these are not present */ 1047 * for the mult's and offsets of in3-5 of the syl, but on
1048 * my test machine these are not present
1049 */
994 dmi_mult[3] = dmi_mult[2]; 1050 dmi_mult[3] = dmi_mult[2];
995 dmi_mult[4] = dmi_mult[1]; 1051 dmi_mult[4] = dmi_mult[1];
996 dmi_mult[5] = dmi_mult[2]; 1052 dmi_mult[5] = dmi_mult[2];
@@ -1058,15 +1114,19 @@ static int fschmd_probe(struct i2c_client *client,
1058 mutex_init(&data->watchdog_lock); 1114 mutex_init(&data->watchdog_lock);
1059 INIT_LIST_HEAD(&data->list); 1115 INIT_LIST_HEAD(&data->list);
1060 kref_init(&data->kref); 1116 kref_init(&data->kref);
1061 /* Store client pointer in our data struct for watchdog usage 1117 /*
1062 (where the client is found through a data ptr instead of the 1118 * Store client pointer in our data struct for watchdog usage
1063 otherway around) */ 1119 * (where the client is found through a data ptr instead of the
1120 * otherway around)
1121 */
1064 data->client = client; 1122 data->client = client;
1065 data->kind = kind; 1123 data->kind = kind;
1066 1124
1067 if (kind == fscpos) { 1125 if (kind == fscpos) {
1068 /* The Poseidon has hardwired temp limits, fill these 1126 /*
1069 in for the alarm resetting code */ 1127 * The Poseidon has hardwired temp limits, fill these
1128 * in for the alarm resetting code
1129 */
1070 data->temp_max[0] = 70 + 128; 1130 data->temp_max[0] = 70 + 128;
1071 data->temp_max[1] = 50 + 128; 1131 data->temp_max[1] = 50 + 128;
1072 data->temp_max[2] = 50 + 128; 1132 data->temp_max[2] = 50 + 128;
@@ -1157,9 +1217,11 @@ static int fschmd_probe(struct i2c_client *client,
1157 goto exit_detach; 1217 goto exit_detach;
1158 } 1218 }
1159 1219
1160 /* We take the data_mutex lock early so that watchdog_open() cannot 1220 /*
1161 run when misc_register() has completed, but we've not yet added 1221 * We take the data_mutex lock early so that watchdog_open() cannot
1162 our data to the watchdog_data_list (and set the default timeout) */ 1222 * run when misc_register() has completed, but we've not yet added
1223 * our data to the watchdog_data_list (and set the default timeout)
1224 */
1163 mutex_lock(&watchdog_data_mutex); 1225 mutex_lock(&watchdog_data_mutex);
1164 for (i = 0; i < ARRAY_SIZE(watchdog_minors); i++) { 1226 for (i = 0; i < ARRAY_SIZE(watchdog_minors); i++) {
1165 /* Register our watchdog part */ 1227 /* Register our watchdog part */
@@ -1225,8 +1287,10 @@ static int fschmd_remove(struct i2c_client *client)
1225 mutex_unlock(&data->watchdog_lock); 1287 mutex_unlock(&data->watchdog_lock);
1226 } 1288 }
1227 1289
1228 /* Check if registered in case we're called from fschmd_detect 1290 /*
1229 to cleanup after an error */ 1291 * Check if registered in case we're called from fschmd_detect
1292 * to cleanup after an error
1293 */
1230 if (data->hwmon_dev) 1294 if (data->hwmon_dev)
1231 hwmon_device_unregister(data->hwmon_dev); 1295 hwmon_device_unregister(data->hwmon_dev);
1232 1296
@@ -1269,8 +1333,10 @@ static struct fschmd_data *fschmd_update_device(struct device *dev)
1269 client, 1333 client,
1270 FSCHMD_REG_TEMP_LIMIT[data->kind][i]); 1334 FSCHMD_REG_TEMP_LIMIT[data->kind][i]);
1271 1335
1272 /* reset alarm if the alarm condition is gone, 1336 /*
1273 the chip doesn't do this itself */ 1337 * reset alarm if the alarm condition is gone,
1338 * the chip doesn't do this itself
1339 */
1274 if ((data->temp_status[i] & FSCHMD_TEMP_ALARM_MASK) == 1340 if ((data->temp_status[i] & FSCHMD_TEMP_ALARM_MASK) ==
1275 FSCHMD_TEMP_ALARM_MASK && 1341 FSCHMD_TEMP_ALARM_MASK &&
1276 data->temp_act[i] < data->temp_max[i]) 1342 data->temp_act[i] < data->temp_max[i])
@@ -1314,20 +1380,9 @@ static struct fschmd_data *fschmd_update_device(struct device *dev)
1314 return data; 1380 return data;
1315} 1381}
1316 1382
1317static int __init fschmd_init(void) 1383module_i2c_driver(fschmd_driver);
1318{
1319 return i2c_add_driver(&fschmd_driver);
1320}
1321
1322static void __exit fschmd_exit(void)
1323{
1324 i2c_del_driver(&fschmd_driver);
1325}
1326 1384
1327MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>"); 1385MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
1328MODULE_DESCRIPTION("FSC Poseidon, Hermes, Scylla, Heracles, Heimdall, Hades " 1386MODULE_DESCRIPTION("FSC Poseidon, Hermes, Scylla, Heracles, Heimdall, Hades "
1329 "and Syleus driver"); 1387 "and Syleus driver");
1330MODULE_LICENSE("GPL"); 1388MODULE_LICENSE("GPL");
1331
1332module_init(fschmd_init);
1333module_exit(fschmd_exit);
diff --git a/drivers/hwmon/g760a.c b/drivers/hwmon/g760a.c
index 781277ddbaa5..ebcd2698e4dc 100644
--- a/drivers/hwmon/g760a.c
+++ b/drivers/hwmon/g760a.c
@@ -1,17 +1,17 @@
1/* 1/*
2 g760a - Driver for the Global Mixed-mode Technology Inc. G760A 2 * g760a - Driver for the Global Mixed-mode Technology Inc. G760A
3 fan speed PWM controller chip 3 * fan speed PWM controller chip
4 4 *
5 Copyright (C) 2007 Herbert Valerio Riedel <hvr@gnu.org> 5 * Copyright (C) 2007 Herbert Valerio Riedel <hvr@gnu.org>
6 6 *
7 Complete datasheet is available at GMT's website: 7 * Complete datasheet is available at GMT's website:
8 http://www.gmt.com.tw/product/datasheet/EDS-760A.pdf 8 * http://www.gmt.com.tw/product/datasheet/EDS-760A.pdf
9 9 *
10 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
11 it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or 12 * the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version. 13 * (at your option) any later version.
14*/ 14 */
15 15
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/init.h> 17#include <linux/init.h>
@@ -59,7 +59,8 @@ struct g760a_data {
59 u8 act_cnt; /* formula: cnt = (CLK * 30)/(rpm * P) */ 59 u8 act_cnt; /* formula: cnt = (CLK * 30)/(rpm * P) */
60 u8 fan_sta; /* bit 0: set when actual fan speed more than 20% 60 u8 fan_sta; /* bit 0: set when actual fan speed more than 20%
61 * outside requested fan speed 61 * outside requested fan speed
62 * bit 1: set when fan speed below 1920 rpm */ 62 * bit 1: set when fan speed below 1920 rpm
63 */
63}; 64};
64 65
65#define G760A_DEFAULT_CLK 32768 66#define G760A_DEFAULT_CLK 32768
@@ -99,7 +100,7 @@ static int g760a_write_value(struct i2c_client *client, enum g760a_regs reg,
99 return i2c_smbus_write_byte_data(client, reg, value); 100 return i2c_smbus_write_byte_data(client, reg, value);
100} 101}
101 102
102/**************************************************************************** 103/*
103 * sysfs attributes 104 * sysfs attributes
104 */ 105 */
105 106
@@ -192,7 +193,7 @@ static const struct attribute_group g760a_group = {
192 .attrs = g760a_attributes, 193 .attrs = g760a_attributes,
193}; 194};
194 195
195/**************************************************************************** 196/*
196 * new-style driver model code 197 * new-style driver model code
197 */ 198 */
198 199
@@ -250,21 +251,8 @@ static int g760a_remove(struct i2c_client *client)
250 return 0; 251 return 0;
251} 252}
252 253
253/* module management */ 254module_i2c_driver(g760a_driver);
254
255static int __init g760a_init(void)
256{
257 return i2c_add_driver(&g760a_driver);
258}
259
260static void __exit g760a_exit(void)
261{
262 i2c_del_driver(&g760a_driver);
263}
264 255
265MODULE_AUTHOR("Herbert Valerio Riedel <hvr@gnu.org>"); 256MODULE_AUTHOR("Herbert Valerio Riedel <hvr@gnu.org>");
266MODULE_DESCRIPTION("GMT G760A driver"); 257MODULE_DESCRIPTION("GMT G760A driver");
267MODULE_LICENSE("GPL"); 258MODULE_LICENSE("GPL");
268
269module_init(g760a_init);
270module_exit(g760a_exit);
diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c
index a13e2da97e30..764a083ac7a7 100644
--- a/drivers/hwmon/gl518sm.c
+++ b/drivers/hwmon/gl518sm.c
@@ -83,11 +83,12 @@ enum chips { gl518sm_r00, gl518sm_r80 };
83 83
84#define RAW_FROM_REG(val) val 84#define RAW_FROM_REG(val) val
85 85
86#define BOOL_FROM_REG(val) ((val)?0:1) 86#define BOOL_FROM_REG(val) ((val) ? 0 : 1)
87#define BOOL_TO_REG(val) ((val)?0:1) 87#define BOOL_TO_REG(val) ((val) ? 0 : 1)
88 88
89#define TEMP_TO_REG(val) (SENSORS_LIMIT(((((val)<0? \ 89#define TEMP_TO_REG(val) SENSORS_LIMIT(((((val) < 0 ? \
90 (val)-500:(val)+500)/1000)+119),0,255)) 90 (val) - 500 : \
91 (val) + 500) / 1000) + 119), 0, 255)
91#define TEMP_FROM_REG(val) (((val) - 119) * 1000) 92#define TEMP_FROM_REG(val) (((val) - 119) * 1000)
92 93
93static inline u8 FAN_TO_REG(long rpm, int div) 94static inline u8 FAN_TO_REG(long rpm, int div)
@@ -98,13 +99,13 @@ static inline u8 FAN_TO_REG(long rpm, int div)
98 rpmdiv = SENSORS_LIMIT(rpm, 1, 960000) * div; 99 rpmdiv = SENSORS_LIMIT(rpm, 1, 960000) * div;
99 return SENSORS_LIMIT((480000 + rpmdiv / 2) / rpmdiv, 1, 255); 100 return SENSORS_LIMIT((480000 + rpmdiv / 2) / rpmdiv, 1, 255);
100} 101}
101#define FAN_FROM_REG(val,div) ((val)==0 ? 0 : (480000/((val)*(div)))) 102#define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : (480000 / ((val) * (div))))
102 103
103#define IN_TO_REG(val) (SENSORS_LIMIT((((val)+9)/19),0,255)) 104#define IN_TO_REG(val) SENSORS_LIMIT((((val) + 9) / 19), 0, 255)
104#define IN_FROM_REG(val) ((val)*19) 105#define IN_FROM_REG(val) ((val) * 19)
105 106
106#define VDD_TO_REG(val) (SENSORS_LIMIT((((val)*4+47)/95),0,255)) 107#define VDD_TO_REG(val) SENSORS_LIMIT((((val) * 4 + 47) / 95), 0, 255)
107#define VDD_FROM_REG(val) (((val)*95+2)/4) 108#define VDD_FROM_REG(val) (((val) * 95 + 2) / 4)
108 109
109#define DIV_FROM_REG(val) (1 << (val)) 110#define DIV_FROM_REG(val) (1 << (val))
110 111
@@ -169,7 +170,8 @@ static struct i2c_driver gl518_driver = {
169 */ 170 */
170 171
171#define show(type, suffix, value) \ 172#define show(type, suffix, value) \
172static ssize_t show_##suffix(struct device *dev, struct device_attribute *attr, char *buf) \ 173static ssize_t show_##suffix(struct device *dev, \
174 struct device_attribute *attr, char *buf) \
173{ \ 175{ \
174 struct gl518_data *data = gl518_update_device(dev); \ 176 struct gl518_data *data = gl518_update_device(dev); \
175 return sprintf(buf, "%d\n", type##_FROM_REG(data->value)); \ 177 return sprintf(buf, "%d\n", type##_FROM_REG(data->value)); \
@@ -222,12 +224,16 @@ static ssize_t show_fan_div(struct device *dev,
222} 224}
223 225
224#define set(type, suffix, value, reg) \ 226#define set(type, suffix, value, reg) \
225static ssize_t set_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \ 227static ssize_t set_##suffix(struct device *dev, \
226 size_t count) \ 228 struct device_attribute *attr, \
229 const char *buf, size_t count) \
227{ \ 230{ \
228 struct i2c_client *client = to_i2c_client(dev); \ 231 struct i2c_client *client = to_i2c_client(dev); \
229 struct gl518_data *data = i2c_get_clientdata(client); \ 232 struct gl518_data *data = i2c_get_clientdata(client); \
230 long val = simple_strtol(buf, NULL, 10); \ 233 long val; \
234 int err = kstrtol(buf, 10, &val); \
235 if (err) \
236 return err; \
231 \ 237 \
232 mutex_lock(&data->update_lock); \ 238 mutex_lock(&data->update_lock); \
233 data->value = type##_TO_REG(val); \ 239 data->value = type##_TO_REG(val); \
@@ -237,13 +243,17 @@ static ssize_t set_##suffix(struct device *dev, struct device_attribute *attr, c
237} 243}
238 244
239#define set_bits(type, suffix, value, reg, mask, shift) \ 245#define set_bits(type, suffix, value, reg, mask, shift) \
240static ssize_t set_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \ 246static ssize_t set_##suffix(struct device *dev, \
241 size_t count) \ 247 struct device_attribute *attr, \
248 const char *buf, size_t count) \
242{ \ 249{ \
243 struct i2c_client *client = to_i2c_client(dev); \ 250 struct i2c_client *client = to_i2c_client(dev); \
244 struct gl518_data *data = i2c_get_clientdata(client); \ 251 struct gl518_data *data = i2c_get_clientdata(client); \
245 int regvalue; \ 252 int regvalue; \
246 unsigned long val = simple_strtoul(buf, NULL, 10); \ 253 unsigned long val; \
254 int err = kstrtoul(buf, 10, &val); \
255 if (err) \
256 return err; \
247 \ 257 \
248 mutex_lock(&data->update_lock); \ 258 mutex_lock(&data->update_lock); \
249 regvalue = gl518_read_value(client, reg); \ 259 regvalue = gl518_read_value(client, reg); \
@@ -280,7 +290,12 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
280 struct gl518_data *data = i2c_get_clientdata(client); 290 struct gl518_data *data = i2c_get_clientdata(client);
281 int nr = to_sensor_dev_attr(attr)->index; 291 int nr = to_sensor_dev_attr(attr)->index;
282 int regvalue; 292 int regvalue;
283 unsigned long val = simple_strtoul(buf, NULL, 10); 293 unsigned long val;
294 int err;
295
296 err = kstrtoul(buf, 10, &val);
297 if (err)
298 return err;
284 299
285 mutex_lock(&data->update_lock); 300 mutex_lock(&data->update_lock);
286 regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT); 301 regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT);
@@ -308,13 +323,26 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
308 struct gl518_data *data = i2c_get_clientdata(client); 323 struct gl518_data *data = i2c_get_clientdata(client);
309 int nr = to_sensor_dev_attr(attr)->index; 324 int nr = to_sensor_dev_attr(attr)->index;
310 int regvalue; 325 int regvalue;
311 unsigned long val = simple_strtoul(buf, NULL, 10); 326 unsigned long val;
327 int err;
328
329 err = kstrtoul(buf, 10, &val);
330 if (err)
331 return err;
312 332
313 switch (val) { 333 switch (val) {
314 case 1: val = 0; break; 334 case 1:
315 case 2: val = 1; break; 335 val = 0;
316 case 4: val = 2; break; 336 break;
317 case 8: val = 3; break; 337 case 2:
338 val = 1;
339 break;
340 case 4:
341 val = 2;
342 break;
343 case 8:
344 val = 3;
345 break;
318 default: 346 default:
319 dev_err(dev, "Invalid fan clock divider %lu, choose one " 347 dev_err(dev, "Invalid fan clock divider %lu, choose one "
320 "of 1, 2, 4 or 8\n", val); 348 "of 1, 2, 4 or 8\n", val);
@@ -395,8 +423,12 @@ static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
395 struct gl518_data *data = i2c_get_clientdata(client); 423 struct gl518_data *data = i2c_get_clientdata(client);
396 int bitnr = to_sensor_dev_attr(attr)->index; 424 int bitnr = to_sensor_dev_attr(attr)->index;
397 unsigned long bit; 425 unsigned long bit;
426 int err;
427
428 err = kstrtoul(buf, 10, &bit);
429 if (err)
430 return err;
398 431
399 bit = simple_strtoul(buf, NULL, 10);
400 if (bit & ~1) 432 if (bit & ~1)
401 return -EINVAL; 433 return -EINVAL;
402 434
@@ -528,12 +560,14 @@ static int gl518_probe(struct i2c_client *client,
528 gl518_init_client(client); 560 gl518_init_client(client);
529 561
530 /* Register sysfs hooks */ 562 /* Register sysfs hooks */
531 if ((err = sysfs_create_group(&client->dev.kobj, &gl518_group))) 563 err = sysfs_create_group(&client->dev.kobj, &gl518_group);
564 if (err)
532 goto exit_free; 565 goto exit_free;
533 if (data->type == gl518sm_r80) 566 if (data->type == gl518sm_r80) {
534 if ((err = sysfs_create_group(&client->dev.kobj, 567 err = sysfs_create_group(&client->dev.kobj, &gl518_group_r80);
535 &gl518_group_r80))) 568 if (err)
536 goto exit_remove_files; 569 goto exit_remove_files;
570 }
537 571
538 data->hwmon_dev = hwmon_device_register(&client->dev); 572 data->hwmon_dev = hwmon_device_register(&client->dev);
539 if (IS_ERR(data->hwmon_dev)) { 573 if (IS_ERR(data->hwmon_dev)) {
@@ -554,8 +588,10 @@ exit:
554} 588}
555 589
556 590
557/* Called when we have found a new GL518SM. 591/*
558 Note that we preserve D4:NoFan2 and D2:beep_enable. */ 592 * Called when we have found a new GL518SM.
593 * Note that we preserve D4:NoFan2 and D2:beep_enable.
594 */
559static void gl518_init_client(struct i2c_client *client) 595static void gl518_init_client(struct i2c_client *client)
560{ 596{
561 /* Make sure we leave D7:Reset untouched */ 597 /* Make sure we leave D7:Reset untouched */
@@ -585,9 +621,11 @@ static int gl518_remove(struct i2c_client *client)
585 return 0; 621 return 0;
586} 622}
587 623
588/* Registers 0x07 to 0x0c are word-sized, others are byte-sized 624/*
589 GL518 uses a high-byte first convention, which is exactly opposite to 625 * Registers 0x07 to 0x0c are word-sized, others are byte-sized
590 the SMBus standard. */ 626 * GL518 uses a high-byte first convention, which is exactly opposite to
627 * the SMBus standard.
628 */
591static int gl518_read_value(struct i2c_client *client, u8 reg) 629static int gl518_read_value(struct i2c_client *client, u8 reg)
592{ 630{
593 if ((reg >= 0x07) && (reg <= 0x0c)) 631 if ((reg >= 0x07) && (reg <= 0x0c))
@@ -676,21 +714,10 @@ static struct gl518_data *gl518_update_device(struct device *dev)
676 return data; 714 return data;
677} 715}
678 716
679static int __init sensors_gl518sm_init(void) 717module_i2c_driver(gl518_driver);
680{
681 return i2c_add_driver(&gl518_driver);
682}
683
684static void __exit sensors_gl518sm_exit(void)
685{
686 i2c_del_driver(&gl518_driver);
687}
688 718
689MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, " 719MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
690 "Kyosti Malkki <kmalkki@cc.hut.fi> and " 720 "Kyosti Malkki <kmalkki@cc.hut.fi> and "
691 "Hong-Gunn Chew <hglinux@gunnet.org>"); 721 "Hong-Gunn Chew <hglinux@gunnet.org>");
692MODULE_DESCRIPTION("GL518SM driver"); 722MODULE_DESCRIPTION("GL518SM driver");
693MODULE_LICENSE("GPL"); 723MODULE_LICENSE("GPL");
694
695module_init(sensors_gl518sm_init);
696module_exit(sensors_gl518sm_exit);
diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c
index cd6085bbfba7..5ff452b6a4d0 100644
--- a/drivers/hwmon/gl520sm.c
+++ b/drivers/hwmon/gl520sm.c
@@ -1,25 +1,25 @@
1/* 1/*
2 gl520sm.c - Part of lm_sensors, Linux kernel modules for hardware 2 * gl520sm.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 * monitoring
4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>, 4 * Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>,
5 Kyösti Mälkki <kmalkki@cc.hut.fi> 5 * Kyösti Mälkki <kmalkki@cc.hut.fi>
6 Copyright (c) 2005 Maarten Deprez <maartendeprez@users.sourceforge.net> 6 * Copyright (c) 2005 Maarten Deprez <maartendeprez@users.sourceforge.net>
7 7 *
8 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 * (at your option) any later version.
12 12 *
13 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 * GNU General Public License for more details.
17 17 *
18 You should have received a copy of the GNU General Public License 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 19 * along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 21 *
22*/ 22 */
23 23
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/init.h> 25#include <linux/init.h>
@@ -41,10 +41,11 @@ 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/* Many GL520 constants specified below 44/*
45One of the inputs can be configured as either temp or voltage. 45 * Many GL520 constants specified below
46That's why _TEMP2 and _IN4 access the same register 46 * One of the inputs can be configured as either temp or voltage.
47*/ 47 * That's why _TEMP2 and _IN4 access the same register
48 */
48 49
49/* The GL520 registers */ 50/* The GL520 registers */
50#define GL520_REG_CHIP_ID 0x00 51#define GL520_REG_CHIP_ID 0x00
@@ -142,11 +143,11 @@ static ssize_t get_cpu_vid(struct device *dev, struct device_attribute *attr,
142} 143}
143static DEVICE_ATTR(cpu0_vid, S_IRUGO, get_cpu_vid, NULL); 144static DEVICE_ATTR(cpu0_vid, S_IRUGO, get_cpu_vid, NULL);
144 145
145#define VDD_FROM_REG(val) (((val)*95+2)/4) 146#define VDD_FROM_REG(val) (((val) * 95 + 2) / 4)
146#define VDD_TO_REG(val) (SENSORS_LIMIT((((val)*4+47)/95),0,255)) 147#define VDD_TO_REG(val) SENSORS_LIMIT((((val) * 4 + 47) / 95), 0, 255)
147 148
148#define IN_FROM_REG(val) ((val)*19) 149#define IN_FROM_REG(val) ((val) * 19)
149#define IN_TO_REG(val) (SENSORS_LIMIT((((val)+9)/19),0,255)) 150#define IN_TO_REG(val) SENSORS_LIMIT((((val) + 9) / 19), 0, 255)
150 151
151static ssize_t get_in_input(struct device *dev, struct device_attribute *attr, 152static ssize_t get_in_input(struct device *dev, struct device_attribute *attr,
152 char *buf) 153 char *buf)
@@ -193,8 +194,13 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
193 struct i2c_client *client = to_i2c_client(dev); 194 struct i2c_client *client = to_i2c_client(dev);
194 struct gl520_data *data = i2c_get_clientdata(client); 195 struct gl520_data *data = i2c_get_clientdata(client);
195 int n = to_sensor_dev_attr(attr)->index; 196 int n = to_sensor_dev_attr(attr)->index;
196 long v = simple_strtol(buf, NULL, 10);
197 u8 r; 197 u8 r;
198 long v;
199 int err;
200
201 err = kstrtol(buf, 10, &v);
202 if (err)
203 return err;
198 204
199 mutex_lock(&data->update_lock); 205 mutex_lock(&data->update_lock);
200 206
@@ -222,8 +228,13 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
222 struct i2c_client *client = to_i2c_client(dev); 228 struct i2c_client *client = to_i2c_client(dev);
223 struct gl520_data *data = i2c_get_clientdata(client); 229 struct gl520_data *data = i2c_get_clientdata(client);
224 int n = to_sensor_dev_attr(attr)->index; 230 int n = to_sensor_dev_attr(attr)->index;
225 long v = simple_strtol(buf, NULL, 10);
226 u8 r; 231 u8 r;
232 long v;
233 int err;
234
235 err = kstrtol(buf, 10, &v);
236 if (err)
237 return err;
227 238
228 if (n == 0) 239 if (n == 0)
229 r = VDD_TO_REG(v); 240 r = VDD_TO_REG(v);
@@ -272,8 +283,10 @@ static SENSOR_DEVICE_ATTR(in4_max, S_IRUGO | S_IWUSR,
272 get_in_max, set_in_max, 4); 283 get_in_max, set_in_max, 4);
273 284
274#define DIV_FROM_REG(val) (1 << (val)) 285#define DIV_FROM_REG(val) (1 << (val))
275#define FAN_FROM_REG(val,div) ((val)==0 ? 0 : (480000/((val) << (div)))) 286#define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : (480000 / ((val) << (div))))
276#define FAN_TO_REG(val,div) ((val)<=0?0:SENSORS_LIMIT((480000 + ((val) << ((div)-1))) / ((val) << (div)), 1, 255)) 287#define FAN_TO_REG(val, div) ((val) <= 0 ? 0 : \
288 SENSORS_LIMIT((480000 + ((val) << ((div)-1))) / ((val) << (div)), 1, \
289 255))
277 290
278static ssize_t get_fan_input(struct device *dev, struct device_attribute *attr, 291static ssize_t get_fan_input(struct device *dev, struct device_attribute *attr,
279 char *buf) 292 char *buf)
@@ -317,8 +330,13 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
317 struct i2c_client *client = to_i2c_client(dev); 330 struct i2c_client *client = to_i2c_client(dev);
318 struct gl520_data *data = i2c_get_clientdata(client); 331 struct gl520_data *data = i2c_get_clientdata(client);
319 int n = to_sensor_dev_attr(attr)->index; 332 int n = to_sensor_dev_attr(attr)->index;
320 unsigned long v = simple_strtoul(buf, NULL, 10);
321 u8 r; 333 u8 r;
334 unsigned long v;
335 int err;
336
337 err = kstrtoul(buf, 10, &v);
338 if (err)
339 return err;
322 340
323 mutex_lock(&data->update_lock); 341 mutex_lock(&data->update_lock);
324 r = FAN_TO_REG(v, data->fan_div[n]); 342 r = FAN_TO_REG(v, data->fan_div[n]);
@@ -351,16 +369,30 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
351 struct i2c_client *client = to_i2c_client(dev); 369 struct i2c_client *client = to_i2c_client(dev);
352 struct gl520_data *data = i2c_get_clientdata(client); 370 struct gl520_data *data = i2c_get_clientdata(client);
353 int n = to_sensor_dev_attr(attr)->index; 371 int n = to_sensor_dev_attr(attr)->index;
354 unsigned long v = simple_strtoul(buf, NULL, 10);
355 u8 r; 372 u8 r;
373 unsigned long v;
374 int err;
375
376 err = kstrtoul(buf, 10, &v);
377 if (err)
378 return err;
356 379
357 switch (v) { 380 switch (v) {
358 case 1: r = 0; break; 381 case 1:
359 case 2: r = 1; break; 382 r = 0;
360 case 4: r = 2; break; 383 break;
361 case 8: r = 3; break; 384 case 2:
385 r = 1;
386 break;
387 case 4:
388 r = 2;
389 break;
390 case 8:
391 r = 3;
392 break;
362 default: 393 default:
363 dev_err(&client->dev, "fan_div value %ld not supported. Choose one of 1, 2, 4 or 8!\n", v); 394 dev_err(&client->dev,
395 "fan_div value %ld not supported. Choose one of 1, 2, 4 or 8!\n", v);
364 return -EINVAL; 396 return -EINVAL;
365 } 397 }
366 398
@@ -385,7 +417,15 @@ static ssize_t set_fan_off(struct device *dev, struct device_attribute *attr,
385{ 417{
386 struct i2c_client *client = to_i2c_client(dev); 418 struct i2c_client *client = to_i2c_client(dev);
387 struct gl520_data *data = i2c_get_clientdata(client); 419 struct gl520_data *data = i2c_get_clientdata(client);
388 u8 r = simple_strtoul(buf, NULL, 10)?1:0; 420 u8 r;
421 unsigned long v;
422 int err;
423
424 err = kstrtoul(buf, 10, &v);
425 if (err)
426 return err;
427
428 r = (v ? 1 : 0);
389 429
390 mutex_lock(&data->update_lock); 430 mutex_lock(&data->update_lock);
391 data->fan_off = r; 431 data->fan_off = r;
@@ -410,7 +450,8 @@ static DEVICE_ATTR(fan1_off, S_IRUGO | S_IWUSR,
410 get_fan_off, set_fan_off); 450 get_fan_off, set_fan_off);
411 451
412#define TEMP_FROM_REG(val) (((val) - 130) * 1000) 452#define TEMP_FROM_REG(val) (((val) - 130) * 1000)
413#define TEMP_TO_REG(val) (SENSORS_LIMIT(((((val)<0?(val)-500:(val)+500) / 1000)+130),0,255)) 453#define TEMP_TO_REG(val) SENSORS_LIMIT(((((val) < 0 ? \
454 (val) - 500 : (val) + 500) / 1000) + 130), 0, 255)
414 455
415static ssize_t get_temp_input(struct device *dev, struct device_attribute *attr, 456static ssize_t get_temp_input(struct device *dev, struct device_attribute *attr,
416 char *buf) 457 char *buf)
@@ -430,8 +471,8 @@ static ssize_t get_temp_max(struct device *dev, struct device_attribute *attr,
430 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[n])); 471 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[n]));
431} 472}
432 473
433static ssize_t get_temp_max_hyst(struct device *dev, struct device_attribute 474static ssize_t get_temp_max_hyst(struct device *dev,
434 *attr, char *buf) 475 struct device_attribute *attr, char *buf)
435{ 476{
436 int n = to_sensor_dev_attr(attr)->index; 477 int n = to_sensor_dev_attr(attr)->index;
437 struct gl520_data *data = gl520_update_device(dev); 478 struct gl520_data *data = gl520_update_device(dev);
@@ -445,7 +486,12 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
445 struct i2c_client *client = to_i2c_client(dev); 486 struct i2c_client *client = to_i2c_client(dev);
446 struct gl520_data *data = i2c_get_clientdata(client); 487 struct gl520_data *data = i2c_get_clientdata(client);
447 int n = to_sensor_dev_attr(attr)->index; 488 int n = to_sensor_dev_attr(attr)->index;
448 long v = simple_strtol(buf, NULL, 10); 489 long v;
490 int err;
491
492 err = kstrtol(buf, 10, &v);
493 if (err)
494 return err;
449 495
450 mutex_lock(&data->update_lock); 496 mutex_lock(&data->update_lock);
451 data->temp_max[n] = TEMP_TO_REG(v); 497 data->temp_max[n] = TEMP_TO_REG(v);
@@ -460,7 +506,12 @@ static ssize_t set_temp_max_hyst(struct device *dev, struct device_attribute
460 struct i2c_client *client = to_i2c_client(dev); 506 struct i2c_client *client = to_i2c_client(dev);
461 struct gl520_data *data = i2c_get_clientdata(client); 507 struct gl520_data *data = i2c_get_clientdata(client);
462 int n = to_sensor_dev_attr(attr)->index; 508 int n = to_sensor_dev_attr(attr)->index;
463 long v = simple_strtol(buf, NULL, 10); 509 long v;
510 int err;
511
512 err = kstrtol(buf, 10, &v);
513 if (err)
514 return err;
464 515
465 mutex_lock(&data->update_lock); 516 mutex_lock(&data->update_lock);
466 data->temp_max_hyst[n] = TEMP_TO_REG(v); 517 data->temp_max_hyst[n] = TEMP_TO_REG(v);
@@ -507,7 +558,15 @@ static ssize_t set_beep_enable(struct device *dev, struct device_attribute
507{ 558{
508 struct i2c_client *client = to_i2c_client(dev); 559 struct i2c_client *client = to_i2c_client(dev);
509 struct gl520_data *data = i2c_get_clientdata(client); 560 struct gl520_data *data = i2c_get_clientdata(client);
510 u8 r = simple_strtoul(buf, NULL, 10)?0:1; 561 u8 r;
562 unsigned long v;
563 int err;
564
565 err = kstrtoul(buf, 10, &v);
566 if (err)
567 return err;
568
569 r = (v ? 0 : 1);
511 570
512 mutex_lock(&data->update_lock); 571 mutex_lock(&data->update_lock);
513 data->beep_enable = !r; 572 data->beep_enable = !r;
@@ -523,7 +582,12 @@ static ssize_t set_beep_mask(struct device *dev, struct device_attribute *attr,
523{ 582{
524 struct i2c_client *client = to_i2c_client(dev); 583 struct i2c_client *client = to_i2c_client(dev);
525 struct gl520_data *data = i2c_get_clientdata(client); 584 struct gl520_data *data = i2c_get_clientdata(client);
526 u8 r = simple_strtoul(buf, NULL, 10); 585 unsigned long r;
586 int err;
587
588 err = kstrtoul(buf, 10, &r);
589 if (err)
590 return err;
527 591
528 mutex_lock(&data->update_lock); 592 mutex_lock(&data->update_lock);
529 r &= data->alarm_mask; 593 r &= data->alarm_mask;
@@ -575,7 +639,11 @@ static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
575 int bitnr = to_sensor_dev_attr(attr)->index; 639 int bitnr = to_sensor_dev_attr(attr)->index;
576 unsigned long bit; 640 unsigned long bit;
577 641
578 bit = simple_strtoul(buf, NULL, 10); 642 int err;
643
644 err = kstrtoul(buf, 10, &bit);
645 if (err)
646 return err;
579 if (bit & ~1) 647 if (bit & ~1)
580 return -EINVAL; 648 return -EINVAL;
581 649
@@ -652,13 +720,16 @@ static const struct attribute_group gl520_group = {
652 .attrs = gl520_attributes, 720 .attrs = gl520_attributes,
653}; 721};
654 722
655static struct attribute *gl520_attributes_opt[] = { 723static struct attribute *gl520_attributes_in4[] = {
656 &sensor_dev_attr_in4_input.dev_attr.attr, 724 &sensor_dev_attr_in4_input.dev_attr.attr,
657 &sensor_dev_attr_in4_min.dev_attr.attr, 725 &sensor_dev_attr_in4_min.dev_attr.attr,
658 &sensor_dev_attr_in4_max.dev_attr.attr, 726 &sensor_dev_attr_in4_max.dev_attr.attr,
659 &sensor_dev_attr_in4_alarm.dev_attr.attr, 727 &sensor_dev_attr_in4_alarm.dev_attr.attr,
660 &sensor_dev_attr_in4_beep.dev_attr.attr, 728 &sensor_dev_attr_in4_beep.dev_attr.attr,
729 NULL
730};
661 731
732static struct attribute *gl520_attributes_temp2[] = {
662 &sensor_dev_attr_temp2_input.dev_attr.attr, 733 &sensor_dev_attr_temp2_input.dev_attr.attr,
663 &sensor_dev_attr_temp2_max.dev_attr.attr, 734 &sensor_dev_attr_temp2_max.dev_attr.attr,
664 &sensor_dev_attr_temp2_max_hyst.dev_attr.attr, 735 &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
@@ -667,8 +738,12 @@ static struct attribute *gl520_attributes_opt[] = {
667 NULL 738 NULL
668}; 739};
669 740
670static const struct attribute_group gl520_group_opt = { 741static const struct attribute_group gl520_group_in4 = {
671 .attrs = gl520_attributes_opt, 742 .attrs = gl520_attributes_in4,
743};
744
745static const struct attribute_group gl520_group_temp2 = {
746 .attrs = gl520_attributes_temp2,
672}; 747};
673 748
674 749
@@ -717,35 +792,17 @@ static int gl520_probe(struct i2c_client *client,
717 gl520_init_client(client); 792 gl520_init_client(client);
718 793
719 /* Register sysfs hooks */ 794 /* Register sysfs hooks */
720 if ((err = sysfs_create_group(&client->dev.kobj, &gl520_group))) 795 err = sysfs_create_group(&client->dev.kobj, &gl520_group);
796 if (err)
721 goto exit_free; 797 goto exit_free;
722 798
723 if (data->two_temps) { 799 if (data->two_temps)
724 if ((err = device_create_file(&client->dev, 800 err = sysfs_create_group(&client->dev.kobj, &gl520_group_temp2);
725 &sensor_dev_attr_temp2_input.dev_attr)) 801 else
726 || (err = device_create_file(&client->dev, 802 err = sysfs_create_group(&client->dev.kobj, &gl520_group_in4);
727 &sensor_dev_attr_temp2_max.dev_attr))
728 || (err = device_create_file(&client->dev,
729 &sensor_dev_attr_temp2_max_hyst.dev_attr))
730 || (err = device_create_file(&client->dev,
731 &sensor_dev_attr_temp2_alarm.dev_attr))
732 || (err = device_create_file(&client->dev,
733 &sensor_dev_attr_temp2_beep.dev_attr)))
734 goto exit_remove_files;
735 } else {
736 if ((err = device_create_file(&client->dev,
737 &sensor_dev_attr_in4_input.dev_attr))
738 || (err = device_create_file(&client->dev,
739 &sensor_dev_attr_in4_min.dev_attr))
740 || (err = device_create_file(&client->dev,
741 &sensor_dev_attr_in4_max.dev_attr))
742 || (err = device_create_file(&client->dev,
743 &sensor_dev_attr_in4_alarm.dev_attr))
744 || (err = device_create_file(&client->dev,
745 &sensor_dev_attr_in4_beep.dev_attr)))
746 goto exit_remove_files;
747 }
748 803
804 if (err)
805 goto exit_remove_files;
749 806
750 data->hwmon_dev = hwmon_device_register(&client->dev); 807 data->hwmon_dev = hwmon_device_register(&client->dev);
751 if (IS_ERR(data->hwmon_dev)) { 808 if (IS_ERR(data->hwmon_dev)) {
@@ -757,7 +814,8 @@ static int gl520_probe(struct i2c_client *client,
757 814
758exit_remove_files: 815exit_remove_files:
759 sysfs_remove_group(&client->dev.kobj, &gl520_group); 816 sysfs_remove_group(&client->dev.kobj, &gl520_group);
760 sysfs_remove_group(&client->dev.kobj, &gl520_group_opt); 817 sysfs_remove_group(&client->dev.kobj, &gl520_group_in4);
818 sysfs_remove_group(&client->dev.kobj, &gl520_group_temp2);
761exit_free: 819exit_free:
762 kfree(data); 820 kfree(data);
763exit: 821exit:
@@ -809,15 +867,18 @@ static int gl520_remove(struct i2c_client *client)
809 867
810 hwmon_device_unregister(data->hwmon_dev); 868 hwmon_device_unregister(data->hwmon_dev);
811 sysfs_remove_group(&client->dev.kobj, &gl520_group); 869 sysfs_remove_group(&client->dev.kobj, &gl520_group);
812 sysfs_remove_group(&client->dev.kobj, &gl520_group_opt); 870 sysfs_remove_group(&client->dev.kobj, &gl520_group_in4);
871 sysfs_remove_group(&client->dev.kobj, &gl520_group_temp2);
813 872
814 kfree(data); 873 kfree(data);
815 return 0; 874 return 0;
816} 875}
817 876
818 877
819/* Registers 0x07 to 0x0c are word-sized, others are byte-sized 878/*
820 GL520 uses a high-byte first convention */ 879 * Registers 0x07 to 0x0c are word-sized, others are byte-sized
880 * GL520 uses a high-byte first convention
881 */
821static int gl520_read_value(struct i2c_client *client, u8 reg) 882static int gl520_read_value(struct i2c_client *client, u8 reg)
822{ 883{
823 if ((reg >= 0x07) && (reg <= 0x0c)) 884 if ((reg >= 0x07) && (reg <= 0x0c))
@@ -849,7 +910,8 @@ static struct gl520_data *gl520_update_device(struct device *dev)
849 910
850 data->alarms = gl520_read_value(client, GL520_REG_ALARMS); 911 data->alarms = gl520_read_value(client, GL520_REG_ALARMS);
851 data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK); 912 data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK);
852 data->vid = gl520_read_value(client, GL520_REG_VID_INPUT) & 0x1f; 913 data->vid = gl520_read_value(client,
914 GL520_REG_VID_INPUT) & 0x1f;
853 915
854 for (i = 0; i < 4; i++) { 916 for (i = 0; i < 4; i++) {
855 data->in_input[i] = gl520_read_value(client, 917 data->in_input[i] = gl520_read_value(client,
@@ -910,23 +972,10 @@ static struct gl520_data *gl520_update_device(struct device *dev)
910 return data; 972 return data;
911} 973}
912 974
913 975module_i2c_driver(gl520_driver);
914static int __init sensors_gl520sm_init(void)
915{
916 return i2c_add_driver(&gl520_driver);
917}
918
919static void __exit sensors_gl520sm_exit(void)
920{
921 i2c_del_driver(&gl520_driver);
922}
923
924 976
925MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, " 977MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
926 "Kyösti Mälkki <kmalkki@cc.hut.fi>, " 978 "Kyösti Mälkki <kmalkki@cc.hut.fi>, "
927 "Maarten Deprez <maartendeprez@users.sourceforge.net>"); 979 "Maarten Deprez <maartendeprez@users.sourceforge.net>");
928MODULE_DESCRIPTION("GL520SM driver"); 980MODULE_DESCRIPTION("GL520SM driver");
929MODULE_LICENSE("GPL"); 981MODULE_LICENSE("GPL");
930
931module_init(sensors_gl520sm_init);
932module_exit(sensors_gl520sm_exit);
diff --git a/drivers/hwmon/hwmon-vid.c b/drivers/hwmon/hwmon-vid.c
index 932da8a5aaf4..9f26400713f0 100644
--- a/drivers/hwmon/hwmon-vid.c
+++ b/drivers/hwmon/hwmon-vid.c
@@ -40,7 +40,7 @@
40 * available at http://developer.intel.com/. 40 * available at http://developer.intel.com/.
41 * 41 *
42 * AMD Athlon 64 and AMD Opteron Processors, AMD Publication 26094, 42 * AMD Athlon 64 and AMD Opteron Processors, AMD Publication 26094,
43 * http://support.amd.com/us/Processor_TechDocs/26094.PDF 43 * http://support.amd.com/us/Processor_TechDocs/26094.PDF
44 * Table 74. VID Code Voltages 44 * Table 74. VID Code Voltages
45 * This corresponds to an arbitrary VRM code of 24 in the functions below. 45 * This corresponds to an arbitrary VRM code of 24 in the functions below.
46 * These CPU models (K8 revision <= E) have 5 VID pins. See also: 46 * These CPU models (K8 revision <= E) have 5 VID pins. See also:
@@ -83,27 +83,27 @@ int vid_from_reg(int val, u8 vrm)
83{ 83{
84 int vid; 84 int vid;
85 85
86 switch(vrm) { 86 switch (vrm) {
87 87
88 case 100: /* VRD 10.0 */ 88 case 100: /* VRD 10.0 */
89 /* compute in uV, round to mV */ 89 /* compute in uV, round to mV */
90 val &= 0x3f; 90 val &= 0x3f;
91 if((val & 0x1f) == 0x1f) 91 if ((val & 0x1f) == 0x1f)
92 return 0; 92 return 0;
93 if((val & 0x1f) <= 0x09 || val == 0x0a) 93 if ((val & 0x1f) <= 0x09 || val == 0x0a)
94 vid = 1087500 - (val & 0x1f) * 25000; 94 vid = 1087500 - (val & 0x1f) * 25000;
95 else 95 else
96 vid = 1862500 - (val & 0x1f) * 25000; 96 vid = 1862500 - (val & 0x1f) * 25000;
97 if(val & 0x20) 97 if (val & 0x20)
98 vid -= 12500; 98 vid -= 12500;
99 return((vid + 500) / 1000); 99 return (vid + 500) / 1000;
100 100
101 case 110: /* Intel Conroe */ 101 case 110: /* Intel Conroe */
102 /* compute in uV, round to mV */ 102 /* compute in uV, round to mV */
103 val &= 0xff; 103 val &= 0xff;
104 if (val < 0x02 || val > 0xb2) 104 if (val < 0x02 || val > 0xb2)
105 return 0; 105 return 0;
106 return((1600000 - (val - 2) * 6250 + 500) / 1000); 106 return (1600000 - (val - 2) * 6250 + 500) / 1000;
107 107
108 case 24: /* Athlon64 & Opteron */ 108 case 24: /* Athlon64 & Opteron */
109 val &= 0x1f; 109 val &= 0x1f;
@@ -118,38 +118,38 @@ int vid_from_reg(int val, u8 vrm)
118 case 91: /* VRM 9.1 */ 118 case 91: /* VRM 9.1 */
119 case 90: /* VRM 9.0 */ 119 case 90: /* VRM 9.0 */
120 val &= 0x1f; 120 val &= 0x1f;
121 return(val == 0x1f ? 0 : 121 return val == 0x1f ? 0 :
122 1850 - val * 25); 122 1850 - val * 25;
123 123
124 case 85: /* VRM 8.5 */ 124 case 85: /* VRM 8.5 */
125 val &= 0x1f; 125 val &= 0x1f;
126 return((val & 0x10 ? 25 : 0) + 126 return (val & 0x10 ? 25 : 0) +
127 ((val & 0x0f) > 0x04 ? 2050 : 1250) - 127 ((val & 0x0f) > 0x04 ? 2050 : 1250) -
128 ((val & 0x0f) * 50)); 128 ((val & 0x0f) * 50);
129 129
130 case 84: /* VRM 8.4 */ 130 case 84: /* VRM 8.4 */
131 val &= 0x0f; 131 val &= 0x0f;
132 /* fall through */ 132 /* fall through */
133 case 82: /* VRM 8.2 */ 133 case 82: /* VRM 8.2 */
134 val &= 0x1f; 134 val &= 0x1f;
135 return(val == 0x1f ? 0 : 135 return val == 0x1f ? 0 :
136 val & 0x10 ? 5100 - (val) * 100 : 136 val & 0x10 ? 5100 - (val) * 100 :
137 2050 - (val) * 50); 137 2050 - (val) * 50;
138 case 17: /* Intel IMVP-II */ 138 case 17: /* Intel IMVP-II */
139 val &= 0x1f; 139 val &= 0x1f;
140 return(val & 0x10 ? 975 - (val & 0xF) * 25 : 140 return val & 0x10 ? 975 - (val & 0xF) * 25 :
141 1750 - val * 50); 141 1750 - val * 50;
142 case 13: 142 case 13:
143 case 131: 143 case 131:
144 val &= 0x3f; 144 val &= 0x3f;
145 /* Exception for Eden ULV 500 MHz */ 145 /* Exception for Eden ULV 500 MHz */
146 if (vrm == 131 && val == 0x3f) 146 if (vrm == 131 && val == 0x3f)
147 val++; 147 val++;
148 return(1708 - val * 16); 148 return 1708 - val * 16;
149 case 14: /* Intel Core */ 149 case 14: /* Intel Core */
150 /* compute in uV, round to mV */ 150 /* compute in uV, round to mV */
151 val &= 0x7f; 151 val &= 0x7f;
152 return(val > 0x77 ? 0 : (1500000 - (val * 12500) + 500) / 1000); 152 return val > 0x77 ? 0 : (1500000 - (val * 12500) + 500) / 1000;
153 default: /* report 0 for unknown */ 153 default: /* report 0 for unknown */
154 if (vrm) 154 if (vrm)
155 pr_warn("Requested unsupported VRM version (%u)\n", 155 pr_warn("Requested unsupported VRM version (%u)\n",
@@ -157,7 +157,7 @@ int vid_from_reg(int val, u8 vrm)
157 return 0; 157 return 0;
158 } 158 }
159} 159}
160 160EXPORT_SYMBOL(vid_from_reg);
161 161
162/* 162/*
163 * After this point is the code to automatically determine which 163 * After this point is the code to automatically determine which
@@ -166,9 +166,10 @@ int vid_from_reg(int val, u8 vrm)
166 166
167struct vrm_model { 167struct vrm_model {
168 u8 vendor; 168 u8 vendor;
169 u8 eff_family; 169 u8 family;
170 u8 eff_model; 170 u8 model_from;
171 u8 eff_stepping; 171 u8 model_to;
172 u8 stepping_to;
172 u8 vrm_type; 173 u8 vrm_type;
173}; 174};
174 175
@@ -177,42 +178,52 @@ struct vrm_model {
177#ifdef CONFIG_X86 178#ifdef CONFIG_X86
178 179
179/* 180/*
180 * The stepping parameter is highest acceptable stepping for current line. 181 * The stepping_to parameter is highest acceptable stepping for current line.
181 * The model match must be exact for 4-bit values. For model values 0x10 182 * The model match must be exact for 4-bit values. For model values 0x10
182 * and above (extended model), all models below the parameter will match. 183 * and above (extended model), all models below the parameter will match.
183 */ 184 */
184 185
185static struct vrm_model vrm_models[] = { 186static struct vrm_model vrm_models[] = {
186 {X86_VENDOR_AMD, 0x6, ANY, ANY, 90}, /* Athlon Duron etc */ 187 {X86_VENDOR_AMD, 0x6, 0x0, ANY, ANY, 90}, /* Athlon Duron etc */
187 {X86_VENDOR_AMD, 0xF, 0x3F, ANY, 24}, /* Athlon 64, Opteron */ 188 {X86_VENDOR_AMD, 0xF, 0x0, 0x3F, ANY, 24}, /* Athlon 64, Opteron */
188 /* In theory, all NPT family 0Fh processors have 6 VID pins and should 189 /*
189 thus use vrm 25, however in practice not all mainboards route the 190 * In theory, all NPT family 0Fh processors have 6 VID pins and should
190 6th VID pin because it is never needed. So we use the 5 VID pin 191 * thus use vrm 25, however in practice not all mainboards route the
191 variant (vrm 24) for the models which exist today. */ 192 * 6th VID pin because it is never needed. So we use the 5 VID pin
192 {X86_VENDOR_AMD, 0xF, 0x7F, ANY, 24}, /* NPT family 0Fh */ 193 * variant (vrm 24) for the models which exist today.
193 {X86_VENDOR_AMD, 0xF, ANY, ANY, 25}, /* future fam. 0Fh */ 194 */
194 {X86_VENDOR_AMD, 0x10, ANY, ANY, 25}, /* NPT family 10h */ 195 {X86_VENDOR_AMD, 0xF, 0x40, 0x7F, ANY, 24}, /* NPT family 0Fh */
195 196 {X86_VENDOR_AMD, 0xF, 0x80, ANY, ANY, 25}, /* future fam. 0Fh */
196 {X86_VENDOR_INTEL, 0x6, 0x9, ANY, 13}, /* Pentium M (130 nm) */ 197 {X86_VENDOR_AMD, 0x10, 0x0, ANY, ANY, 25}, /* NPT family 10h */
197 {X86_VENDOR_INTEL, 0x6, 0xB, ANY, 85}, /* Tualatin */ 198
198 {X86_VENDOR_INTEL, 0x6, 0xD, ANY, 13}, /* Pentium M (90 nm) */ 199 {X86_VENDOR_INTEL, 0x6, 0x0, 0x6, ANY, 82}, /* Pentium Pro,
199 {X86_VENDOR_INTEL, 0x6, 0xE, ANY, 14}, /* Intel Core (65 nm) */ 200 * Pentium II, Xeon,
200 {X86_VENDOR_INTEL, 0x6, 0xF, ANY, 110}, /* Intel Conroe */ 201 * Mobile Pentium,
201 {X86_VENDOR_INTEL, 0x6, ANY, ANY, 82}, /* any P6 */ 202 * Celeron */
202 {X86_VENDOR_INTEL, 0xF, 0x0, ANY, 90}, /* P4 */ 203 {X86_VENDOR_INTEL, 0x6, 0x7, 0x7, ANY, 84}, /* Pentium III, Xeon */
203 {X86_VENDOR_INTEL, 0xF, 0x1, ANY, 90}, /* P4 Willamette */ 204 {X86_VENDOR_INTEL, 0x6, 0x8, 0x8, ANY, 82}, /* Pentium III, Xeon */
204 {X86_VENDOR_INTEL, 0xF, 0x2, ANY, 90}, /* P4 Northwood */ 205 {X86_VENDOR_INTEL, 0x6, 0x9, 0x9, ANY, 13}, /* Pentium M (130 nm) */
205 {X86_VENDOR_INTEL, 0xF, ANY, ANY, 100}, /* Prescott and above assume VRD 10 */ 206 {X86_VENDOR_INTEL, 0x6, 0xA, 0xA, ANY, 82}, /* Pentium III Xeon */
206 207 {X86_VENDOR_INTEL, 0x6, 0xB, 0xB, ANY, 85}, /* Tualatin */
207 {X86_VENDOR_CENTAUR, 0x6, 0x7, ANY, 85}, /* Eden ESP/Ezra */ 208 {X86_VENDOR_INTEL, 0x6, 0xD, 0xD, ANY, 13}, /* Pentium M (90 nm) */
208 {X86_VENDOR_CENTAUR, 0x6, 0x8, 0x7, 85}, /* Ezra T */ 209 {X86_VENDOR_INTEL, 0x6, 0xE, 0xE, ANY, 14}, /* Intel Core (65 nm) */
209 {X86_VENDOR_CENTAUR, 0x6, 0x9, 0x7, 85}, /* Nehemiah */ 210 {X86_VENDOR_INTEL, 0x6, 0xF, ANY, ANY, 110}, /* Intel Conroe and
210 {X86_VENDOR_CENTAUR, 0x6, 0x9, ANY, 17}, /* C3-M, Eden-N */ 211 * later */
211 {X86_VENDOR_CENTAUR, 0x6, 0xA, 0x7, 0}, /* No information */ 212 {X86_VENDOR_INTEL, 0xF, 0x0, 0x0, ANY, 90}, /* P4 */
212 {X86_VENDOR_CENTAUR, 0x6, 0xA, ANY, 13}, /* C7-M, C7, Eden (Esther) */ 213 {X86_VENDOR_INTEL, 0xF, 0x1, 0x1, ANY, 90}, /* P4 Willamette */
213 {X86_VENDOR_CENTAUR, 0x6, 0xD, ANY, 134}, /* C7-D, C7-M, C7, Eden (Esther) */ 214 {X86_VENDOR_INTEL, 0xF, 0x2, 0x2, ANY, 90}, /* P4 Northwood */
214 215 {X86_VENDOR_INTEL, 0xF, 0x3, ANY, ANY, 100}, /* Prescott and above
215 {X86_VENDOR_UNKNOWN, ANY, ANY, ANY, 0} /* stop here */ 216 * assume VRD 10 */
217
218 {X86_VENDOR_CENTAUR, 0x6, 0x7, 0x7, ANY, 85}, /* Eden ESP/Ezra */
219 {X86_VENDOR_CENTAUR, 0x6, 0x8, 0x8, 0x7, 85}, /* Ezra T */
220 {X86_VENDOR_CENTAUR, 0x6, 0x9, 0x9, 0x7, 85}, /* Nehemiah */
221 {X86_VENDOR_CENTAUR, 0x6, 0x9, 0x9, ANY, 17}, /* C3-M, Eden-N */
222 {X86_VENDOR_CENTAUR, 0x6, 0xA, 0xA, 0x7, 0}, /* No information */
223 {X86_VENDOR_CENTAUR, 0x6, 0xA, 0xA, ANY, 13}, /* C7-M, C7,
224 * Eden (Esther) */
225 {X86_VENDOR_CENTAUR, 0x6, 0xD, 0xD, ANY, 134}, /* C7-D, C7-M, C7,
226 * Eden (Esther) */
216}; 227};
217 228
218/* 229/*
@@ -248,20 +259,17 @@ static u8 get_via_model_d_vrm(void)
248 } 259 }
249} 260}
250 261
251static u8 find_vrm(u8 eff_family, u8 eff_model, u8 eff_stepping, u8 vendor) 262static u8 find_vrm(u8 family, u8 model, u8 stepping, u8 vendor)
252{ 263{
253 int i = 0; 264 int i;
254 265
255 while (vrm_models[i].vendor!=X86_VENDOR_UNKNOWN) { 266 for (i = 0; i < ARRAY_SIZE(vrm_models); i++) {
256 if (vrm_models[i].vendor==vendor) 267 if (vendor == vrm_models[i].vendor &&
257 if ((vrm_models[i].eff_family==eff_family) 268 family == vrm_models[i].family &&
258 && ((vrm_models[i].eff_model==eff_model) || 269 model >= vrm_models[i].model_from &&
259 (vrm_models[i].eff_model >= 0x10 && 270 model <= vrm_models[i].model_to &&
260 eff_model <= vrm_models[i].eff_model) || 271 stepping <= vrm_models[i].stepping_to)
261 (vrm_models[i].eff_model==ANY)) && 272 return vrm_models[i].vrm_type;
262 (eff_stepping <= vrm_models[i].eff_stepping))
263 return vrm_models[i].vrm_type;
264 i++;
265 } 273 }
266 274
267 return 0; 275 return 0;
@@ -270,21 +278,12 @@ static u8 find_vrm(u8 eff_family, u8 eff_model, u8 eff_stepping, u8 vendor)
270u8 vid_which_vrm(void) 278u8 vid_which_vrm(void)
271{ 279{
272 struct cpuinfo_x86 *c = &cpu_data(0); 280 struct cpuinfo_x86 *c = &cpu_data(0);
273 u32 eax; 281 u8 vrm_ret;
274 u8 eff_family, eff_model, eff_stepping, vrm_ret;
275 282
276 if (c->x86 < 6) /* Any CPU with family lower than 6 */ 283 if (c->x86 < 6) /* Any CPU with family lower than 6 */
277 return 0; /* doesn't have VID and/or CPUID */ 284 return 0; /* doesn't have VID */
278 285
279 eax = cpuid_eax(1); 286 vrm_ret = find_vrm(c->x86, c->x86_model, c->x86_mask, c->x86_vendor);
280 eff_family = ((eax & 0x00000F00)>>8);
281 eff_model = ((eax & 0x000000F0)>>4);
282 eff_stepping = eax & 0xF;
283 if (eff_family == 0xF) { /* use extended model & family */
284 eff_family += ((eax & 0x00F00000)>>20);
285 eff_model += ((eax & 0x000F0000)>>16)<<4;
286 }
287 vrm_ret = find_vrm(eff_family, eff_model, eff_stepping, c->x86_vendor);
288 if (vrm_ret == 134) 287 if (vrm_ret == 134)
289 vrm_ret = get_via_model_d_vrm(); 288 vrm_ret = get_via_model_d_vrm();
290 if (vrm_ret == 0) 289 if (vrm_ret == 0)
@@ -300,8 +299,6 @@ u8 vid_which_vrm(void)
300 return 0; 299 return 0;
301} 300}
302#endif 301#endif
303
304EXPORT_SYMBOL(vid_from_reg);
305EXPORT_SYMBOL(vid_which_vrm); 302EXPORT_SYMBOL(vid_which_vrm);
306 303
307MODULE_AUTHOR("Rudolf Marek <r.marek@assembler.cz>"); 304MODULE_AUTHOR("Rudolf Marek <r.marek@assembler.cz>");
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 6460487e41b5..c3c471ca202f 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -1,14 +1,14 @@
1/* 1/*
2 hwmon.c - part of lm_sensors, Linux kernel modules for hardware monitoring 2 * hwmon.c - part of lm_sensors, Linux kernel modules for hardware monitoring
3 3 *
4 This file defines the sysfs class "hwmon", for use by sensors drivers. 4 * This file defines the sysfs class "hwmon", for use by sensors drivers.
5 5 *
6 Copyright (C) 2005 Mark M. Hoffman <mhoffman@lightlink.com> 6 * Copyright (C) 2005 Mark M. Hoffman <mhoffman@lightlink.com>
7 7 *
8 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; version 2 of the License. 10 * the Free Software Foundation; version 2 of the License.
11*/ 11 */
12 12
13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14 14
@@ -55,6 +55,7 @@ struct device *hwmon_device_register(struct device *dev)
55 55
56 return hwdev; 56 return hwdev;
57} 57}
58EXPORT_SYMBOL_GPL(hwmon_device_register);
58 59
59/** 60/**
60 * hwmon_device_unregister - removes the previously registered class device 61 * hwmon_device_unregister - removes the previously registered class device
@@ -72,6 +73,7 @@ void hwmon_device_unregister(struct device *dev)
72 dev_dbg(dev->parent, 73 dev_dbg(dev->parent,
73 "hwmon_device_unregister() failed: bad class ID!\n"); 74 "hwmon_device_unregister() failed: bad class ID!\n");
74} 75}
76EXPORT_SYMBOL_GPL(hwmon_device_unregister);
75 77
76static void __init hwmon_pci_quirks(void) 78static void __init hwmon_pci_quirks(void)
77{ 79{
@@ -119,9 +121,6 @@ static void __exit hwmon_exit(void)
119subsys_initcall(hwmon_init); 121subsys_initcall(hwmon_init);
120module_exit(hwmon_exit); 122module_exit(hwmon_exit);
121 123
122EXPORT_SYMBOL_GPL(hwmon_device_register);
123EXPORT_SYMBOL_GPL(hwmon_device_unregister);
124
125MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>"); 124MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>");
126MODULE_DESCRIPTION("hardware monitoring sysfs/class support"); 125MODULE_DESCRIPTION("hardware monitoring sysfs/class support");
127MODULE_LICENSE("GPL"); 126MODULE_LICENSE("GPL");
diff --git a/drivers/hwmon/i5k_amb.c b/drivers/hwmon/i5k_amb.c
index d22f241b6a67..a18882cc073d 100644
--- a/drivers/hwmon/i5k_amb.c
+++ b/drivers/hwmon/i5k_amb.c
@@ -159,8 +159,12 @@ static ssize_t store_amb_min(struct device *dev,
159{ 159{
160 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 160 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
161 struct i5k_amb_data *data = dev_get_drvdata(dev); 161 struct i5k_amb_data *data = dev_get_drvdata(dev);
162 unsigned long temp = simple_strtoul(buf, NULL, 10) / 500; 162 unsigned long temp;
163 int ret = kstrtoul(buf, 10, &temp);
164 if (ret < 0)
165 return ret;
163 166
167 temp = temp / 500;
164 if (temp > 255) 168 if (temp > 255)
165 temp = 255; 169 temp = 255;
166 170
@@ -175,8 +179,12 @@ static ssize_t store_amb_mid(struct device *dev,
175{ 179{
176 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 180 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
177 struct i5k_amb_data *data = dev_get_drvdata(dev); 181 struct i5k_amb_data *data = dev_get_drvdata(dev);
178 unsigned long temp = simple_strtoul(buf, NULL, 10) / 500; 182 unsigned long temp;
183 int ret = kstrtoul(buf, 10, &temp);
184 if (ret < 0)
185 return ret;
179 186
187 temp = temp / 500;
180 if (temp > 255) 188 if (temp > 255)
181 temp = 255; 189 temp = 255;
182 190
@@ -191,8 +199,12 @@ static ssize_t store_amb_max(struct device *dev,
191{ 199{
192 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 200 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
193 struct i5k_amb_data *data = dev_get_drvdata(dev); 201 struct i5k_amb_data *data = dev_get_drvdata(dev);
194 unsigned long temp = simple_strtoul(buf, NULL, 10) / 500; 202 unsigned long temp;
203 int ret = kstrtoul(buf, 10, &temp);
204 if (ret < 0)
205 return ret;
195 206
207 temp = temp / 500;
196 if (temp > 255) 208 if (temp > 255)
197 temp = 255; 209 temp = 255;
198 210
diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
index cc2981f749a6..37f17e0d9d5d 100644
--- a/drivers/hwmon/ibmaem.c
+++ b/drivers/hwmon/ibmaem.c
@@ -1045,7 +1045,7 @@ static struct aem_ro_sensor_template aem2_ro_sensors[] = {
1045{"power6_average", aem2_show_pcap_value, POWER_CAP_MIN_WARNING}, 1045{"power6_average", aem2_show_pcap_value, POWER_CAP_MIN_WARNING},
1046{"power7_average", aem2_show_pcap_value, POWER_CAP_MIN}, 1046{"power7_average", aem2_show_pcap_value, POWER_CAP_MIN},
1047 1047
1048{"power3_average", aem2_show_pcap_value, POWER_AUX}, 1048{"power3_average", aem2_show_pcap_value, POWER_AUX},
1049{"power_cap", aem2_show_pcap_value, POWER_CAP}, 1049{"power_cap", aem2_show_pcap_value, POWER_CAP},
1050{NULL, NULL, 0}, 1050{NULL, NULL, 0},
1051}; 1051};
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index 0054d6f9cec9..0b204e4cf51c 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -176,12 +176,16 @@ static bool fix_pwm_polarity;
176#define IT87_REG_ALARM2 0x02 176#define IT87_REG_ALARM2 0x02
177#define IT87_REG_ALARM3 0x03 177#define IT87_REG_ALARM3 0x03
178 178
179/* The IT8718F and IT8720F have the VID value in a different register, in 179/*
180 Super-I/O configuration space. */ 180 * The IT8718F and IT8720F have the VID value in a different register, in
181 * Super-I/O configuration space.
182 */
181#define IT87_REG_VID 0x0a 183#define IT87_REG_VID 0x0a
182/* The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b 184/*
183 for fan divisors. Later IT8712F revisions must use 16-bit tachometer 185 * The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b
184 mode. */ 186 * for fan divisors. Later IT8712F revisions must use 16-bit tachometer
187 * mode.
188 */
185#define IT87_REG_FAN_DIV 0x0b 189#define IT87_REG_FAN_DIV 0x0b
186#define IT87_REG_FAN_16BIT 0x0c 190#define IT87_REG_FAN_16BIT 0x0c
187 191
@@ -227,8 +231,10 @@ struct it87_sio_data {
227 u8 skip_pwm; 231 u8 skip_pwm;
228}; 232};
229 233
230/* For each registered chip, we need to keep some data in memory. 234/*
231 The structure is dynamically allocated. */ 235 * For each registered chip, we need to keep some data in memory.
236 * The structure is dynamically allocated.
237 */
232struct it87_data { 238struct it87_data {
233 struct device *hwmon_dev; 239 struct device *hwmon_dev;
234 enum chips type; 240 enum chips type;
@@ -259,14 +265,16 @@ struct it87_data {
259 u8 fan_main_ctrl; /* Register value */ 265 u8 fan_main_ctrl; /* Register value */
260 u8 fan_ctl; /* Register value */ 266 u8 fan_ctl; /* Register value */
261 267
262 /* The following 3 arrays correspond to the same registers up to 268 /*
269 * The following 3 arrays correspond to the same registers up to
263 * the IT8720F. The meaning of bits 6-0 depends on the value of bit 270 * the IT8720F. The meaning of bits 6-0 depends on the value of bit
264 * 7, and we want to preserve settings on mode changes, so we have 271 * 7, and we want to preserve settings on mode changes, so we have
265 * to track all values separately. 272 * to track all values separately.
266 * Starting with the IT8721F, the manual PWM duty cycles are stored 273 * Starting with the IT8721F, the manual PWM duty cycles are stored
267 * in separate registers (8-bit values), so the separate tracking 274 * in separate registers (8-bit values), so the separate tracking
268 * is no longer needed, but it is still done to keep the driver 275 * is no longer needed, but it is still done to keep the driver
269 * simple. */ 276 * simple.
277 */
270 u8 pwm_ctrl[3]; /* Register value */ 278 u8 pwm_ctrl[3]; /* Register value */
271 u8 pwm_duty[3]; /* Manual PWM value set by user */ 279 u8 pwm_duty[3]; /* Manual PWM value set by user */
272 u8 pwm_temp_map[3]; /* PWM to temp. chan. mapping (bits 1-0) */ 280 u8 pwm_temp_map[3]; /* PWM to temp. chan. mapping (bits 1-0) */
@@ -388,9 +396,11 @@ static const unsigned int pwm_freq[8] = {
388 396
389static inline int has_16bit_fans(const struct it87_data *data) 397static inline int has_16bit_fans(const struct it87_data *data)
390{ 398{
391 /* IT8705F Datasheet 0.4.1, 3h == Version G. 399 /*
392 IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J. 400 * IT8705F Datasheet 0.4.1, 3h == Version G.
393 These are the first revisions with 16bit tachometer support. */ 401 * IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J.
402 * These are the first revisions with 16-bit tachometer support.
403 */
394 return (data->type == it87 && data->revision >= 0x03) 404 return (data->type == it87 && data->revision >= 0x03)
395 || (data->type == it8712 && data->revision >= 0x08) 405 || (data->type == it8712 && data->revision >= 0x08)
396 || data->type == it8716 406 || data->type == it8716
@@ -402,9 +412,11 @@ static inline int has_16bit_fans(const struct it87_data *data)
402 412
403static inline int has_old_autopwm(const struct it87_data *data) 413static inline int has_old_autopwm(const struct it87_data *data)
404{ 414{
405 /* The old automatic fan speed control interface is implemented 415 /*
406 by IT8705F chips up to revision F and IT8712F chips up to 416 * The old automatic fan speed control interface is implemented
407 revision G. */ 417 * by IT8705F chips up to revision F and IT8712F chips up to
418 * revision G.
419 */
408 return (data->type == it87 && data->revision < 0x03) 420 return (data->type == it87 && data->revision < 0x03)
409 || (data->type == it8712 && data->revision < 0x08); 421 || (data->type == it8712 && data->revision < 0x08);
410} 422}
@@ -606,10 +618,8 @@ static ssize_t show_sensor(struct device *dev, struct device_attribute *attr,
606{ 618{
607 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 619 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
608 int nr = sensor_attr->index; 620 int nr = sensor_attr->index;
609
610 struct it87_data *data = it87_update_device(dev); 621 struct it87_data *data = it87_update_device(dev);
611 u8 reg = data->sensor; /* In case the value is updated while 622 u8 reg = data->sensor; /* In case value is updated while used */
612 we use it */
613 623
614 if (reg & (1 << nr)) 624 if (reg & (1 << nr))
615 return sprintf(buf, "3\n"); /* thermal diode */ 625 return sprintf(buf, "3\n"); /* thermal diode */
@@ -894,8 +904,10 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
894 904
895 mutex_lock(&data->update_lock); 905 mutex_lock(&data->update_lock);
896 if (has_newer_autopwm(data)) { 906 if (has_newer_autopwm(data)) {
897 /* If we are in automatic mode, the PWM duty cycle register 907 /*
898 * is read-only so we can't write the value */ 908 * If we are in automatic mode, the PWM duty cycle register
909 * is read-only so we can't write the value.
910 */
899 if (data->pwm_ctrl[nr] & 0x80) { 911 if (data->pwm_ctrl[nr] & 0x80) {
900 mutex_unlock(&data->update_lock); 912 mutex_unlock(&data->update_lock);
901 return -EBUSY; 913 return -EBUSY;
@@ -905,8 +917,10 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
905 data->pwm_duty[nr]); 917 data->pwm_duty[nr]);
906 } else { 918 } else {
907 data->pwm_duty[nr] = pwm_to_reg(data, val); 919 data->pwm_duty[nr] = pwm_to_reg(data, val);
908 /* If we are in manual mode, write the duty cycle immediately; 920 /*
909 * otherwise, just store it for later use. */ 921 * If we are in manual mode, write the duty cycle immediately;
922 * otherwise, just store it for later use.
923 */
910 if (!(data->pwm_ctrl[nr] & 0x80)) { 924 if (!(data->pwm_ctrl[nr] & 0x80)) {
911 data->pwm_ctrl[nr] = data->pwm_duty[nr]; 925 data->pwm_ctrl[nr] = data->pwm_duty[nr];
912 it87_write_value(data, IT87_REG_PWM(nr), 926 it87_write_value(data, IT87_REG_PWM(nr),
@@ -965,8 +979,10 @@ static ssize_t set_pwm_temp_map(struct device *dev,
965 long val; 979 long val;
966 u8 reg; 980 u8 reg;
967 981
968 /* This check can go away if we ever support automatic fan speed 982 /*
969 control on newer chips. */ 983 * This check can go away if we ever support automatic fan speed
984 * control on newer chips.
985 */
970 if (!has_old_autopwm(data)) { 986 if (!has_old_autopwm(data)) {
971 dev_notice(dev, "Mapping change disabled for safety reasons\n"); 987 dev_notice(dev, "Mapping change disabled for safety reasons\n");
972 return -EINVAL; 988 return -EINVAL;
@@ -991,8 +1007,10 @@ static ssize_t set_pwm_temp_map(struct device *dev,
991 1007
992 mutex_lock(&data->update_lock); 1008 mutex_lock(&data->update_lock);
993 data->pwm_temp_map[nr] = reg; 1009 data->pwm_temp_map[nr] = reg;
994 /* If we are in automatic mode, write the temp mapping immediately; 1010 /*
995 * otherwise, just store it for later use. */ 1011 * If we are in automatic mode, write the temp mapping immediately;
1012 * otherwise, just store it for later use.
1013 */
996 if (data->pwm_ctrl[nr] & 0x80) { 1014 if (data->pwm_ctrl[nr] & 0x80) {
997 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr]; 1015 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
998 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]); 1016 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
@@ -1162,9 +1180,11 @@ static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr,
1162 return count; 1180 return count;
1163} 1181}
1164 1182
1165/* We want to use the same sysfs file names as 8-bit fans, but we need 1183/*
1166 different variable names, so we have to use SENSOR_ATTR instead of 1184 * We want to use the same sysfs file names as 8-bit fans, but we need
1167 SENSOR_DEVICE_ATTR. */ 1185 * different variable names, so we have to use SENSOR_ATTR instead of
1186 * SENSOR_DEVICE_ATTR.
1187 */
1168#define show_fan16_offset(offset) \ 1188#define show_fan16_offset(offset) \
1169static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \ 1189static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \
1170 = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \ 1190 = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \
@@ -1321,12 +1341,12 @@ static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
1321static ssize_t show_label(struct device *dev, struct device_attribute *attr, 1341static ssize_t show_label(struct device *dev, struct device_attribute *attr,
1322 char *buf) 1342 char *buf)
1323{ 1343{
1324 static const char *labels[] = { 1344 static const char * const labels[] = {
1325 "+5V", 1345 "+5V",
1326 "5VSB", 1346 "5VSB",
1327 "Vbat", 1347 "Vbat",
1328 }; 1348 };
1329 static const char *labels_it8721[] = { 1349 static const char * const labels_it8721[] = {
1330 "+3.3V", 1350 "+3.3V",
1331 "3VSB", 1351 "3VSB",
1332 "Vbat", 1352 "Vbat",
@@ -1736,12 +1756,14 @@ static int __init it87_find(unsigned short *address,
1736 if (board_vendor && board_name) { 1756 if (board_vendor && board_name) {
1737 if (strcmp(board_vendor, "nVIDIA") == 0 1757 if (strcmp(board_vendor, "nVIDIA") == 0
1738 && strcmp(board_name, "FN68PT") == 0) { 1758 && strcmp(board_name, "FN68PT") == 0) {
1739 /* On the Shuttle SN68PT, FAN_CTL2 is apparently not 1759 /*
1740 connected to a fan, but to something else. One user 1760 * On the Shuttle SN68PT, FAN_CTL2 is apparently not
1741 has reported instant system power-off when changing 1761 * connected to a fan, but to something else. One user
1742 the PWM2 duty cycle, so we disable it. 1762 * has reported instant system power-off when changing
1743 I use the board name string as the trigger in case 1763 * the PWM2 duty cycle, so we disable it.
1744 the same board is ever used in other systems. */ 1764 * I use the board name string as the trigger in case
1765 * the same board is ever used in other systems.
1766 */
1745 pr_info("Disabling pwm2 due to hardware constraints\n"); 1767 pr_info("Disabling pwm2 due to hardware constraints\n");
1746 sio_data->skip_pwm = (1 << 1); 1768 sio_data->skip_pwm = (1 << 1);
1747 } 1769 }
@@ -1793,7 +1815,7 @@ static int __devinit it87_probe(struct platform_device *pdev)
1793 int err = 0, i; 1815 int err = 0, i;
1794 int enable_pwm_interface; 1816 int enable_pwm_interface;
1795 int fan_beep_need_rw; 1817 int fan_beep_need_rw;
1796 static const char *names[] = { 1818 static const char * const names[] = {
1797 "it87", 1819 "it87",
1798 "it8712", 1820 "it8712",
1799 "it8716", 1821 "it8716",
@@ -1879,9 +1901,11 @@ static int __devinit it87_probe(struct platform_device *pdev)
1879 if (!fan_beep_need_rw) 1901 if (!fan_beep_need_rw)
1880 continue; 1902 continue;
1881 1903
1882 /* As we have a single beep enable bit for all fans, 1904 /*
1905 * As we have a single beep enable bit for all fans,
1883 * only the first enabled fan has a writable attribute 1906 * only the first enabled fan has a writable attribute
1884 * for it. */ 1907 * for it.
1908 */
1885 if (sysfs_chmod_file(&dev->kobj, 1909 if (sysfs_chmod_file(&dev->kobj,
1886 it87_attributes_fan_beep[i], 1910 it87_attributes_fan_beep[i],
1887 S_IRUGO | S_IWUSR)) 1911 S_IRUGO | S_IWUSR))
@@ -1961,18 +1985,22 @@ static int __devexit it87_remove(struct platform_device *pdev)
1961 return 0; 1985 return 0;
1962} 1986}
1963 1987
1964/* Must be called with data->update_lock held, except during initialization. 1988/*
1965 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, 1989 * Must be called with data->update_lock held, except during initialization.
1966 would slow down the IT87 access and should not be necessary. */ 1990 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1991 * would slow down the IT87 access and should not be necessary.
1992 */
1967static int it87_read_value(struct it87_data *data, u8 reg) 1993static int it87_read_value(struct it87_data *data, u8 reg)
1968{ 1994{
1969 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET); 1995 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
1970 return inb_p(data->addr + IT87_DATA_REG_OFFSET); 1996 return inb_p(data->addr + IT87_DATA_REG_OFFSET);
1971} 1997}
1972 1998
1973/* Must be called with data->update_lock held, except during initialization. 1999/*
1974 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, 2000 * Must be called with data->update_lock held, except during initialization.
1975 would slow down the IT87 access and should not be necessary. */ 2001 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
2002 * would slow down the IT87 access and should not be necessary.
2003 */
1976static void it87_write_value(struct it87_data *data, u8 reg, u8 value) 2004static void it87_write_value(struct it87_data *data, u8 reg, u8 value)
1977{ 2005{
1978 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET); 2006 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
@@ -1983,15 +2011,19 @@ static void it87_write_value(struct it87_data *data, u8 reg, u8 value)
1983static int __devinit it87_check_pwm(struct device *dev) 2011static int __devinit it87_check_pwm(struct device *dev)
1984{ 2012{
1985 struct it87_data *data = dev_get_drvdata(dev); 2013 struct it87_data *data = dev_get_drvdata(dev);
1986 /* Some BIOSes fail to correctly configure the IT87 fans. All fans off 2014 /*
2015 * Some BIOSes fail to correctly configure the IT87 fans. All fans off
1987 * and polarity set to active low is sign that this is the case so we 2016 * and polarity set to active low is sign that this is the case so we
1988 * disable pwm control to protect the user. */ 2017 * disable pwm control to protect the user.
2018 */
1989 int tmp = it87_read_value(data, IT87_REG_FAN_CTL); 2019 int tmp = it87_read_value(data, IT87_REG_FAN_CTL);
1990 if ((tmp & 0x87) == 0) { 2020 if ((tmp & 0x87) == 0) {
1991 if (fix_pwm_polarity) { 2021 if (fix_pwm_polarity) {
1992 /* The user asks us to attempt a chip reconfiguration. 2022 /*
2023 * The user asks us to attempt a chip reconfiguration.
1993 * This means switching to active high polarity and 2024 * This means switching to active high polarity and
1994 * inverting all fan speed values. */ 2025 * inverting all fan speed values.
2026 */
1995 int i; 2027 int i;
1996 u8 pwm[3]; 2028 u8 pwm[3];
1997 2029
@@ -1999,10 +2031,12 @@ static int __devinit it87_check_pwm(struct device *dev)
1999 pwm[i] = it87_read_value(data, 2031 pwm[i] = it87_read_value(data,
2000 IT87_REG_PWM(i)); 2032 IT87_REG_PWM(i));
2001 2033
2002 /* If any fan is in automatic pwm mode, the polarity 2034 /*
2035 * If any fan is in automatic pwm mode, the polarity
2003 * might be correct, as suspicious as it seems, so we 2036 * might be correct, as suspicious as it seems, so we
2004 * better don't change anything (but still disable the 2037 * better don't change anything (but still disable the
2005 * PWM interface). */ 2038 * PWM interface).
2039 */
2006 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) { 2040 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
2007 dev_info(dev, "Reconfiguring PWM to " 2041 dev_info(dev, "Reconfiguring PWM to "
2008 "active high polarity\n"); 2042 "active high polarity\n");
@@ -2038,7 +2072,8 @@ static void __devinit it87_init_device(struct platform_device *pdev)
2038 int tmp, i; 2072 int tmp, i;
2039 u8 mask; 2073 u8 mask;
2040 2074
2041 /* For each PWM channel: 2075 /*
2076 * For each PWM channel:
2042 * - If it is in automatic mode, setting to manual mode should set 2077 * - If it is in automatic mode, setting to manual mode should set
2043 * the fan to full speed by default. 2078 * the fan to full speed by default.
2044 * - If it is in manual mode, we need a mapping to temperature 2079 * - If it is in manual mode, we need a mapping to temperature
@@ -2048,18 +2083,21 @@ static void __devinit it87_init_device(struct platform_device *pdev)
2048 * prior to switching to a different mode. 2083 * prior to switching to a different mode.
2049 * Note that this is no longer needed for the IT8721F and later, as 2084 * Note that this is no longer needed for the IT8721F and later, as
2050 * these have separate registers for the temperature mapping and the 2085 * these have separate registers for the temperature mapping and the
2051 * manual duty cycle. */ 2086 * manual duty cycle.
2087 */
2052 for (i = 0; i < 3; i++) { 2088 for (i = 0; i < 3; i++) {
2053 data->pwm_temp_map[i] = i; 2089 data->pwm_temp_map[i] = i;
2054 data->pwm_duty[i] = 0x7f; /* Full speed */ 2090 data->pwm_duty[i] = 0x7f; /* Full speed */
2055 data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */ 2091 data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */
2056 } 2092 }
2057 2093
2058 /* Some chips seem to have default value 0xff for all limit 2094 /*
2095 * Some chips seem to have default value 0xff for all limit
2059 * registers. For low voltage limits it makes no sense and triggers 2096 * registers. For low voltage limits it makes no sense and triggers
2060 * alarms, so change to 0 instead. For high temperature limits, it 2097 * alarms, so change to 0 instead. For high temperature limits, it
2061 * means -1 degree C, which surprisingly doesn't trigger an alarm, 2098 * means -1 degree C, which surprisingly doesn't trigger an alarm,
2062 * but is still confusing, so change to 127 degrees C. */ 2099 * but is still confusing, so change to 127 degrees C.
2100 */
2063 for (i = 0; i < 8; i++) { 2101 for (i = 0; i < 8; i++) {
2064 tmp = it87_read_value(data, IT87_REG_VIN_MIN(i)); 2102 tmp = it87_read_value(data, IT87_REG_VIN_MIN(i));
2065 if (tmp == 0xff) 2103 if (tmp == 0xff)
@@ -2071,10 +2109,12 @@ static void __devinit it87_init_device(struct platform_device *pdev)
2071 it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127); 2109 it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127);
2072 } 2110 }
2073 2111
2074 /* Temperature channels are not forcibly enabled, as they can be 2112 /*
2113 * Temperature channels are not forcibly enabled, as they can be
2075 * set to two different sensor types and we can't guess which one 2114 * set to two different sensor types and we can't guess which one
2076 * is correct for a given system. These channels can be enabled at 2115 * is correct for a given system. These channels can be enabled at
2077 * run-time through the temp{1-3}_type sysfs accessors if needed. */ 2116 * run-time through the temp{1-3}_type sysfs accessors if needed.
2117 */
2078 2118
2079 /* Check if voltage monitors are reset manually or by some reason */ 2119 /* Check if voltage monitors are reset manually or by some reason */
2080 tmp = it87_read_value(data, IT87_REG_VIN_ENABLE); 2120 tmp = it87_read_value(data, IT87_REG_VIN_ENABLE);
@@ -2157,8 +2197,10 @@ static struct it87_data *it87_update_device(struct device *dev)
2157 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 2197 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
2158 || !data->valid) { 2198 || !data->valid) {
2159 if (update_vbat) { 2199 if (update_vbat) {
2160 /* Cleared after each update, so reenable. Value 2200 /*
2161 returned by this read will be previous value */ 2201 * Cleared after each update, so reenable. Value
2202 * returned by this read will be previous value
2203 */
2162 it87_write_value(data, IT87_REG_CONFIG, 2204 it87_write_value(data, IT87_REG_CONFIG,
2163 it87_read_value(data, IT87_REG_CONFIG) | 0x40); 2205 it87_read_value(data, IT87_REG_CONFIG) | 0x40);
2164 } 2206 }
@@ -2220,13 +2262,17 @@ static struct it87_data *it87_update_device(struct device *dev)
2220 it87_update_pwm_ctrl(data, i); 2262 it87_update_pwm_ctrl(data, i);
2221 2263
2222 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE); 2264 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
2223 /* The 8705 does not have VID capability. 2265 /*
2224 The 8718 and later don't use IT87_REG_VID for the 2266 * The IT8705F does not have VID capability.
2225 same purpose. */ 2267 * The IT8718F and later don't use IT87_REG_VID for the
2268 * same purpose.
2269 */
2226 if (data->type == it8712 || data->type == it8716) { 2270 if (data->type == it8712 || data->type == it8716) {
2227 data->vid = it87_read_value(data, IT87_REG_VID); 2271 data->vid = it87_read_value(data, IT87_REG_VID);
2228 /* The older IT8712F revisions had only 5 VID pins, 2272 /*
2229 but we assume it is always safe to read 6 bits. */ 2273 * The older IT8712F revisions had only 5 VID pins,
2274 * but we assume it is always safe to read 6 bits.
2275 */
2230 data->vid &= 0x3f; 2276 data->vid &= 0x3f;
2231 } 2277 }
2232 data->last_updated = jiffies; 2278 data->last_updated = jiffies;
diff --git a/drivers/hwmon/jc42.c b/drivers/hwmon/jc42.c
index b927ee5ccdd7..a9bfd6736d9a 100644
--- a/drivers/hwmon/jc42.c
+++ b/drivers/hwmon/jc42.c
@@ -180,25 +180,7 @@ static int jc42_remove(struct i2c_client *client);
180static struct jc42_data *jc42_update_device(struct device *dev); 180static struct jc42_data *jc42_update_device(struct device *dev);
181 181
182static const struct i2c_device_id jc42_id[] = { 182static const struct i2c_device_id jc42_id[] = {
183 { "adt7408", 0 },
184 { "at30ts00", 0 },
185 { "cat94ts02", 0 },
186 { "cat6095", 0 },
187 { "jc42", 0 }, 183 { "jc42", 0 },
188 { "max6604", 0 },
189 { "mcp9804", 0 },
190 { "mcp9805", 0 },
191 { "mcp98242", 0 },
192 { "mcp98243", 0 },
193 { "mcp9843", 0 },
194 { "se97", 0 },
195 { "se97b", 0 },
196 { "se98", 0 },
197 { "stts424", 0 },
198 { "stts2002", 0 },
199 { "stts3000", 0 },
200 { "tse2002", 0 },
201 { "ts3000", 0 },
202 { } 184 { }
203}; 185};
204MODULE_DEVICE_TABLE(i2c, jc42_id); 186MODULE_DEVICE_TABLE(i2c, jc42_id);
@@ -350,8 +332,10 @@ set(temp_min, JC42_REG_TEMP_LOWER);
350set(temp_max, JC42_REG_TEMP_UPPER); 332set(temp_max, JC42_REG_TEMP_UPPER);
351set(temp_crit, JC42_REG_TEMP_CRITICAL); 333set(temp_crit, JC42_REG_TEMP_CRITICAL);
352 334
353/* JC42.4 compliant chips only support four hysteresis values. 335/*
354 * Pick best choice and go from there. */ 336 * JC42.4 compliant chips only support four hysteresis values.
337 * Pick best choice and go from there.
338 */
355static ssize_t set_temp_crit_hyst(struct device *dev, 339static ssize_t set_temp_crit_hyst(struct device *dev,
356 struct device_attribute *attr, 340 struct device_attribute *attr,
357 const char *buf, size_t count) 341 const char *buf, size_t count)
@@ -467,20 +451,19 @@ static const struct attribute_group jc42_group = {
467}; 451};
468 452
469/* Return 0 if detection is successful, -ENODEV otherwise */ 453/* Return 0 if detection is successful, -ENODEV otherwise */
470static int jc42_detect(struct i2c_client *new_client, 454static int jc42_detect(struct i2c_client *client, struct i2c_board_info *info)
471 struct i2c_board_info *info)
472{ 455{
473 struct i2c_adapter *adapter = new_client->adapter; 456 struct i2c_adapter *adapter = client->adapter;
474 int i, config, cap, manid, devid; 457 int i, config, cap, manid, devid;
475 458
476 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | 459 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
477 I2C_FUNC_SMBUS_WORD_DATA)) 460 I2C_FUNC_SMBUS_WORD_DATA))
478 return -ENODEV; 461 return -ENODEV;
479 462
480 cap = i2c_smbus_read_word_swapped(new_client, JC42_REG_CAP); 463 cap = i2c_smbus_read_word_swapped(client, JC42_REG_CAP);
481 config = i2c_smbus_read_word_swapped(new_client, JC42_REG_CONFIG); 464 config = i2c_smbus_read_word_swapped(client, JC42_REG_CONFIG);
482 manid = i2c_smbus_read_word_swapped(new_client, JC42_REG_MANID); 465 manid = i2c_smbus_read_word_swapped(client, JC42_REG_MANID);
483 devid = i2c_smbus_read_word_swapped(new_client, JC42_REG_DEVICEID); 466 devid = i2c_smbus_read_word_swapped(client, JC42_REG_DEVICEID);
484 467
485 if (cap < 0 || config < 0 || manid < 0 || devid < 0) 468 if (cap < 0 || config < 0 || manid < 0 || devid < 0)
486 return -ENODEV; 469 return -ENODEV;
@@ -499,47 +482,42 @@ static int jc42_detect(struct i2c_client *new_client,
499 return -ENODEV; 482 return -ENODEV;
500} 483}
501 484
502static int jc42_probe(struct i2c_client *new_client, 485static int jc42_probe(struct i2c_client *client, const struct i2c_device_id *id)
503 const struct i2c_device_id *id)
504{ 486{
505 struct jc42_data *data; 487 struct jc42_data *data;
506 int config, cap, err; 488 int config, cap, err;
489 struct device *dev = &client->dev;
507 490
508 data = kzalloc(sizeof(struct jc42_data), GFP_KERNEL); 491 data = devm_kzalloc(dev, sizeof(struct jc42_data), GFP_KERNEL);
509 if (!data) { 492 if (!data)
510 err = -ENOMEM; 493 return -ENOMEM;
511 goto exit;
512 }
513 494
514 i2c_set_clientdata(new_client, data); 495 i2c_set_clientdata(client, data);
515 mutex_init(&data->update_lock); 496 mutex_init(&data->update_lock);
516 497
517 cap = i2c_smbus_read_word_swapped(new_client, JC42_REG_CAP); 498 cap = i2c_smbus_read_word_swapped(client, JC42_REG_CAP);
518 if (cap < 0) { 499 if (cap < 0)
519 err = -EINVAL; 500 return cap;
520 goto exit_free; 501
521 }
522 data->extended = !!(cap & JC42_CAP_RANGE); 502 data->extended = !!(cap & JC42_CAP_RANGE);
523 503
524 config = i2c_smbus_read_word_swapped(new_client, JC42_REG_CONFIG); 504 config = i2c_smbus_read_word_swapped(client, JC42_REG_CONFIG);
525 if (config < 0) { 505 if (config < 0)
526 err = -EINVAL; 506 return config;
527 goto exit_free; 507
528 }
529 data->orig_config = config; 508 data->orig_config = config;
530 if (config & JC42_CFG_SHUTDOWN) { 509 if (config & JC42_CFG_SHUTDOWN) {
531 config &= ~JC42_CFG_SHUTDOWN; 510 config &= ~JC42_CFG_SHUTDOWN;
532 i2c_smbus_write_word_swapped(new_client, JC42_REG_CONFIG, 511 i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, config);
533 config);
534 } 512 }
535 data->config = config; 513 data->config = config;
536 514
537 /* Register sysfs hooks */ 515 /* Register sysfs hooks */
538 err = sysfs_create_group(&new_client->dev.kobj, &jc42_group); 516 err = sysfs_create_group(&dev->kobj, &jc42_group);
539 if (err) 517 if (err)
540 goto exit_free; 518 return err;
541 519
542 data->hwmon_dev = hwmon_device_register(&new_client->dev); 520 data->hwmon_dev = hwmon_device_register(dev);
543 if (IS_ERR(data->hwmon_dev)) { 521 if (IS_ERR(data->hwmon_dev)) {
544 err = PTR_ERR(data->hwmon_dev); 522 err = PTR_ERR(data->hwmon_dev);
545 goto exit_remove; 523 goto exit_remove;
@@ -548,10 +526,7 @@ static int jc42_probe(struct i2c_client *new_client,
548 return 0; 526 return 0;
549 527
550exit_remove: 528exit_remove:
551 sysfs_remove_group(&new_client->dev.kobj, &jc42_group); 529 sysfs_remove_group(&dev->kobj, &jc42_group);
552exit_free:
553 kfree(data);
554exit:
555 return err; 530 return err;
556} 531}
557 532
@@ -563,7 +538,6 @@ static int jc42_remove(struct i2c_client *client)
563 if (data->config != data->orig_config) 538 if (data->config != data->orig_config)
564 i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, 539 i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG,
565 data->orig_config); 540 data->orig_config);
566 kfree(data);
567 return 0; 541 return 0;
568} 542}
569 543
@@ -614,19 +588,8 @@ abort:
614 return ret; 588 return ret;
615} 589}
616 590
617static int __init sensors_jc42_init(void) 591module_i2c_driver(jc42_driver);
618{
619 return i2c_add_driver(&jc42_driver);
620}
621
622static void __exit sensors_jc42_exit(void)
623{
624 i2c_del_driver(&jc42_driver);
625}
626 592
627MODULE_AUTHOR("Guenter Roeck <guenter.roeck@ericsson.com>"); 593MODULE_AUTHOR("Guenter Roeck <guenter.roeck@ericsson.com>");
628MODULE_DESCRIPTION("JC42 driver"); 594MODULE_DESCRIPTION("JC42 driver");
629MODULE_LICENSE("GPL"); 595MODULE_LICENSE("GPL");
630
631module_init(sensors_jc42_init);
632module_exit(sensors_jc42_exit);
diff --git a/drivers/hwmon/k10temp.c b/drivers/hwmon/k10temp.c
index 41aa6a319870..aba29d63f195 100644
--- a/drivers/hwmon/k10temp.c
+++ b/drivers/hwmon/k10temp.c
@@ -205,7 +205,7 @@ static void __devexit k10temp_remove(struct pci_dev *pdev)
205 pci_set_drvdata(pdev, NULL); 205 pci_set_drvdata(pdev, NULL);
206} 206}
207 207
208static const struct pci_device_id k10temp_id_table[] = { 208static DEFINE_PCI_DEVICE_TABLE(k10temp_id_table) = {
209 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_10H_NB_MISC) }, 209 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_10H_NB_MISC) },
210 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_11H_NB_MISC) }, 210 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_11H_NB_MISC) },
211 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_CNB17H_F3) }, 211 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_CNB17H_F3) },
diff --git a/drivers/hwmon/k8temp.c b/drivers/hwmon/k8temp.c
index b923bc2307ad..575101988751 100644
--- a/drivers/hwmon/k8temp.c
+++ b/drivers/hwmon/k8temp.c
@@ -46,7 +46,7 @@ struct k8temp_data {
46 unsigned long last_updated; /* in jiffies */ 46 unsigned long last_updated; /* in jiffies */
47 47
48 /* registers values */ 48 /* registers values */
49 u8 sensorsp; /* sensor presence bits - SEL_CORE & SEL_PLACE */ 49 u8 sensorsp; /* sensor presence bits - SEL_CORE, SEL_PLACE */
50 u32 temp[2][2]; /* core, place */ 50 u32 temp[2][2]; /* core, place */
51 u8 swap_core_select; /* meaning of SEL_CORE is inverted */ 51 u8 swap_core_select; /* meaning of SEL_CORE is inverted */
52 u32 temp_offset; 52 u32 temp_offset;
@@ -63,7 +63,7 @@ static struct k8temp_data *k8temp_update_device(struct device *dev)
63 if (!data->valid 63 if (!data->valid
64 || time_after(jiffies, data->last_updated + HZ)) { 64 || time_after(jiffies, data->last_updated + HZ)) {
65 pci_read_config_byte(pdev, REG_TEMP, &tmp); 65 pci_read_config_byte(pdev, REG_TEMP, &tmp);
66 tmp &= ~(SEL_PLACE | SEL_CORE); /* Select sensor 0, core0 */ 66 tmp &= ~(SEL_PLACE | SEL_CORE); /* Select sensor 0, core0 */
67 pci_write_config_byte(pdev, REG_TEMP, tmp); 67 pci_write_config_byte(pdev, REG_TEMP, tmp);
68 pci_read_config_dword(pdev, REG_TEMP, &data->temp[0][0]); 68 pci_read_config_dword(pdev, REG_TEMP, &data->temp[0][0]);
69 69
@@ -82,7 +82,7 @@ static struct k8temp_data *k8temp_update_device(struct device *dev)
82 &data->temp[1][0]); 82 &data->temp[1][0]);
83 83
84 if (data->sensorsp & SEL_PLACE) { 84 if (data->sensorsp & SEL_PLACE) {
85 tmp |= SEL_PLACE; /* Select sensor 1, core1 */ 85 tmp |= SEL_PLACE; /* Select sensor 1, core1 */
86 pci_write_config_byte(pdev, REG_TEMP, tmp); 86 pci_write_config_byte(pdev, REG_TEMP, tmp);
87 pci_read_config_dword(pdev, REG_TEMP, 87 pci_read_config_dword(pdev, REG_TEMP,
88 &data->temp[1][1]); 88 &data->temp[1][1]);
@@ -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 const struct pci_device_id k8temp_ids[] = { 139static DEFINE_PCI_DEVICE_TABLE(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};
@@ -183,7 +183,8 @@ static int __devinit k8temp_probe(struct pci_dev *pdev,
183 u8 model, stepping; 183 u8 model, stepping;
184 struct k8temp_data *data; 184 struct k8temp_data *data;
185 185
186 if (!(data = kzalloc(sizeof(struct k8temp_data), GFP_KERNEL))) { 186 data = kzalloc(sizeof(struct k8temp_data), GFP_KERNEL);
187 if (!data) {
187 err = -ENOMEM; 188 err = -ENOMEM;
188 goto exit; 189 goto exit;
189 } 190 }
@@ -217,7 +218,7 @@ static int __devinit k8temp_probe(struct pci_dev *pdev,
217 data->temp_offset = 21000; 218 data->temp_offset = 21000;
218 219
219 pci_read_config_byte(pdev, REG_TEMP, &scfg); 220 pci_read_config_byte(pdev, REG_TEMP, &scfg);
220 scfg &= ~(SEL_PLACE | SEL_CORE); /* Select sensor 0, core0 */ 221 scfg &= ~(SEL_PLACE | SEL_CORE); /* Select sensor 0, core0 */
221 pci_write_config_byte(pdev, REG_TEMP, scfg); 222 pci_write_config_byte(pdev, REG_TEMP, scfg);
222 pci_read_config_byte(pdev, REG_TEMP, &scfg); 223 pci_read_config_byte(pdev, REG_TEMP, &scfg);
223 224
@@ -238,7 +239,7 @@ static int __devinit k8temp_probe(struct pci_dev *pdev,
238 pci_write_config_byte(pdev, REG_TEMP, scfg); 239 pci_write_config_byte(pdev, REG_TEMP, scfg);
239 pci_read_config_dword(pdev, REG_TEMP, &temp); 240 pci_read_config_dword(pdev, REG_TEMP, &temp);
240 scfg |= SEL_CORE; /* prepare for next selection */ 241 scfg |= SEL_CORE; /* prepare for next selection */
241 if (!((temp >> 16) & 0xff)) /* if temp is 0 -49C is not likely */ 242 if (!((temp >> 16) & 0xff)) /* if temp is 0 -49C is unlikely */
242 data->sensorsp &= ~SEL_PLACE; 243 data->sensorsp &= ~SEL_PLACE;
243 } 244 }
244 245
@@ -246,7 +247,7 @@ static int __devinit k8temp_probe(struct pci_dev *pdev,
246 scfg &= ~SEL_PLACE; /* Select sensor 0, core1 */ 247 scfg &= ~SEL_PLACE; /* Select sensor 0, core1 */
247 pci_write_config_byte(pdev, REG_TEMP, scfg); 248 pci_write_config_byte(pdev, REG_TEMP, scfg);
248 pci_read_config_dword(pdev, REG_TEMP, &temp); 249 pci_read_config_dword(pdev, REG_TEMP, &temp);
249 if (!((temp >> 16) & 0xff)) /* if temp is 0 -49C is not likely */ 250 if (!((temp >> 16) & 0xff)) /* if temp is 0 -49C is unlikely */
250 data->sensorsp &= ~SEL_CORE; 251 data->sensorsp &= ~SEL_CORE;
251 } 252 }
252 253
diff --git a/drivers/hwmon/lineage-pem.c b/drivers/hwmon/lineage-pem.c
index 58eded27f385..d264937c7f5e 100644
--- a/drivers/hwmon/lineage-pem.c
+++ b/drivers/hwmon/lineage-pem.c
@@ -448,7 +448,7 @@ static int pem_probe(struct i2c_client *client,
448 | I2C_FUNC_SMBUS_WRITE_BYTE)) 448 | I2C_FUNC_SMBUS_WRITE_BYTE))
449 return -ENODEV; 449 return -ENODEV;
450 450
451 data = kzalloc(sizeof(*data), GFP_KERNEL); 451 data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
452 if (!data) 452 if (!data)
453 return -ENOMEM; 453 return -ENOMEM;
454 454
@@ -462,11 +462,11 @@ static int pem_probe(struct i2c_client *client,
462 ret = pem_read_block(client, PEM_READ_FIRMWARE_REV, 462 ret = pem_read_block(client, PEM_READ_FIRMWARE_REV,
463 data->firmware_rev, sizeof(data->firmware_rev)); 463 data->firmware_rev, sizeof(data->firmware_rev));
464 if (ret < 0) 464 if (ret < 0)
465 goto out_kfree; 465 return ret;
466 466
467 ret = i2c_smbus_write_byte(client, PEM_CLEAR_INFO_FLAGS); 467 ret = i2c_smbus_write_byte(client, PEM_CLEAR_INFO_FLAGS);
468 if (ret < 0) 468 if (ret < 0)
469 goto out_kfree; 469 return ret;
470 470
471 dev_info(&client->dev, "Firmware revision %d.%d.%d\n", 471 dev_info(&client->dev, "Firmware revision %d.%d.%d\n",
472 data->firmware_rev[0], data->firmware_rev[1], 472 data->firmware_rev[0], data->firmware_rev[1],
@@ -475,7 +475,7 @@ static int pem_probe(struct i2c_client *client,
475 /* Register sysfs hooks */ 475 /* Register sysfs hooks */
476 ret = sysfs_create_group(&client->dev.kobj, &pem_group); 476 ret = sysfs_create_group(&client->dev.kobj, &pem_group);
477 if (ret) 477 if (ret)
478 goto out_kfree; 478 return ret;
479 479
480 /* 480 /*
481 * Check if input readings are supported. 481 * Check if input readings are supported.
@@ -534,8 +534,6 @@ out_remove_groups:
534 sysfs_remove_group(&client->dev.kobj, &pem_input_group); 534 sysfs_remove_group(&client->dev.kobj, &pem_input_group);
535 sysfs_remove_group(&client->dev.kobj, &pem_fan_group); 535 sysfs_remove_group(&client->dev.kobj, &pem_fan_group);
536 sysfs_remove_group(&client->dev.kobj, &pem_group); 536 sysfs_remove_group(&client->dev.kobj, &pem_group);
537out_kfree:
538 kfree(data);
539 return ret; 537 return ret;
540} 538}
541 539
@@ -549,7 +547,6 @@ static int pem_remove(struct i2c_client *client)
549 sysfs_remove_group(&client->dev.kobj, &pem_fan_group); 547 sysfs_remove_group(&client->dev.kobj, &pem_fan_group);
550 sysfs_remove_group(&client->dev.kobj, &pem_group); 548 sysfs_remove_group(&client->dev.kobj, &pem_group);
551 549
552 kfree(data);
553 return 0; 550 return 0;
554} 551}
555 552
@@ -568,19 +565,8 @@ static struct i2c_driver pem_driver = {
568 .id_table = pem_id, 565 .id_table = pem_id,
569}; 566};
570 567
571static int __init pem_init(void) 568module_i2c_driver(pem_driver);
572{
573 return i2c_add_driver(&pem_driver);
574}
575
576static void __exit pem_exit(void)
577{
578 i2c_del_driver(&pem_driver);
579}
580 569
581MODULE_AUTHOR("Guenter Roeck <guenter.roeck@ericsson.com>"); 570MODULE_AUTHOR("Guenter Roeck <guenter.roeck@ericsson.com>");
582MODULE_DESCRIPTION("Lineage CPL PEM hardware monitoring driver"); 571MODULE_DESCRIPTION("Lineage CPL PEM hardware monitoring driver");
583MODULE_LICENSE("GPL"); 572MODULE_LICENSE("GPL");
584
585module_init(pem_init);
586module_exit(pem_exit);
diff --git a/drivers/hwmon/lm63.c b/drivers/hwmon/lm63.c
index 5e6457a6644d..15c05cc83e2c 100644
--- a/drivers/hwmon/lm63.c
+++ b/drivers/hwmon/lm63.c
@@ -1119,19 +1119,8 @@ static struct lm63_data *lm63_update_device(struct device *dev)
1119 return data; 1119 return data;
1120} 1120}
1121 1121
1122static int __init sensors_lm63_init(void) 1122module_i2c_driver(lm63_driver);
1123{
1124 return i2c_add_driver(&lm63_driver);
1125}
1126
1127static void __exit sensors_lm63_exit(void)
1128{
1129 i2c_del_driver(&lm63_driver);
1130}
1131 1123
1132MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); 1124MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
1133MODULE_DESCRIPTION("LM63 driver"); 1125MODULE_DESCRIPTION("LM63 driver");
1134MODULE_LICENSE("GPL"); 1126MODULE_LICENSE("GPL");
1135
1136module_init(sensors_lm63_init);
1137module_exit(sensors_lm63_exit);
diff --git a/drivers/hwmon/lm70.c b/drivers/hwmon/lm70.c
index c274ea25d899..472f79521a96 100644
--- a/drivers/hwmon/lm70.c
+++ b/drivers/hwmon/lm70.c
@@ -57,7 +57,7 @@ static ssize_t lm70_sense_temp(struct device *dev,
57 struct spi_device *spi = to_spi_device(dev); 57 struct spi_device *spi = to_spi_device(dev);
58 int status, val = 0; 58 int status, val = 0;
59 u8 rxbuf[2]; 59 u8 rxbuf[2];
60 s16 raw=0; 60 s16 raw = 0;
61 struct lm70 *p_lm70 = spi_get_drvdata(spi); 61 struct lm70 *p_lm70 = spi_get_drvdata(spi);
62 62
63 if (mutex_lock_interruptible(&p_lm70->lock)) 63 if (mutex_lock_interruptible(&p_lm70->lock))
@@ -156,6 +156,15 @@ static int __devinit lm70_probe(struct spi_device *spi)
156 mutex_init(&p_lm70->lock); 156 mutex_init(&p_lm70->lock);
157 p_lm70->chip = chip; 157 p_lm70->chip = chip;
158 158
159 spi_set_drvdata(spi, p_lm70);
160
161 status = device_create_file(&spi->dev, &dev_attr_temp1_input);
162 if (status)
163 goto out_dev_create_temp_file_failed;
164 status = device_create_file(&spi->dev, &dev_attr_name);
165 if (status)
166 goto out_dev_create_file_failed;
167
159 /* sysfs hook */ 168 /* sysfs hook */
160 p_lm70->hwmon_dev = hwmon_device_register(&spi->dev); 169 p_lm70->hwmon_dev = hwmon_device_register(&spi->dev);
161 if (IS_ERR(p_lm70->hwmon_dev)) { 170 if (IS_ERR(p_lm70->hwmon_dev)) {
@@ -163,20 +172,14 @@ static int __devinit lm70_probe(struct spi_device *spi)
163 status = PTR_ERR(p_lm70->hwmon_dev); 172 status = PTR_ERR(p_lm70->hwmon_dev);
164 goto out_dev_reg_failed; 173 goto out_dev_reg_failed;
165 } 174 }
166 spi_set_drvdata(spi, p_lm70);
167
168 if ((status = device_create_file(&spi->dev, &dev_attr_temp1_input))
169 || (status = device_create_file(&spi->dev, &dev_attr_name))) {
170 dev_dbg(&spi->dev, "device_create_file failure.\n");
171 goto out_dev_create_file_failed;
172 }
173 175
174 return 0; 176 return 0;
175 177
178out_dev_reg_failed:
179 device_remove_file(&spi->dev, &dev_attr_name);
176out_dev_create_file_failed: 180out_dev_create_file_failed:
177 device_remove_file(&spi->dev, &dev_attr_temp1_input); 181 device_remove_file(&spi->dev, &dev_attr_temp1_input);
178 hwmon_device_unregister(p_lm70->hwmon_dev); 182out_dev_create_temp_file_failed:
179out_dev_reg_failed:
180 spi_set_drvdata(spi, NULL); 183 spi_set_drvdata(spi, NULL);
181 kfree(p_lm70); 184 kfree(p_lm70);
182 return status; 185 return status;
@@ -186,9 +189,9 @@ static int __devexit lm70_remove(struct spi_device *spi)
186{ 189{
187 struct lm70 *p_lm70 = spi_get_drvdata(spi); 190 struct lm70 *p_lm70 = spi_get_drvdata(spi);
188 191
192 hwmon_device_unregister(p_lm70->hwmon_dev);
189 device_remove_file(&spi->dev, &dev_attr_temp1_input); 193 device_remove_file(&spi->dev, &dev_attr_temp1_input);
190 device_remove_file(&spi->dev, &dev_attr_name); 194 device_remove_file(&spi->dev, &dev_attr_name);
191 hwmon_device_unregister(p_lm70->hwmon_dev);
192 spi_set_drvdata(spi, NULL); 195 spi_set_drvdata(spi, NULL);
193 kfree(p_lm70); 196 kfree(p_lm70);
194 197
@@ -213,18 +216,7 @@ static struct spi_driver lm70_driver = {
213 .remove = __devexit_p(lm70_remove), 216 .remove = __devexit_p(lm70_remove),
214}; 217};
215 218
216static int __init init_lm70(void) 219module_spi_driver(lm70_driver);
217{
218 return spi_register_driver(&lm70_driver);
219}
220
221static void __exit cleanup_lm70(void)
222{
223 spi_unregister_driver(&lm70_driver);
224}
225
226module_init(init_lm70);
227module_exit(cleanup_lm70);
228 220
229MODULE_AUTHOR("Kaiwan N Billimoria"); 221MODULE_AUTHOR("Kaiwan N Billimoria");
230MODULE_DESCRIPTION("NS LM70 / TI TMP121/TMP123 Linux driver"); 222MODULE_DESCRIPTION("NS LM70 / TI TMP121/TMP123 Linux driver");
diff --git a/drivers/hwmon/lm73.c b/drivers/hwmon/lm73.c
index 9c8093c4b307..8fa2632cbbaf 100644
--- a/drivers/hwmon/lm73.c
+++ b/drivers/hwmon/lm73.c
@@ -194,21 +194,8 @@ static struct i2c_driver lm73_driver = {
194 .address_list = normal_i2c, 194 .address_list = normal_i2c,
195}; 195};
196 196
197/* module glue */ 197module_i2c_driver(lm73_driver);
198
199static int __init sensors_lm73_init(void)
200{
201 return i2c_add_driver(&lm73_driver);
202}
203
204static void __exit sensors_lm73_exit(void)
205{
206 i2c_del_driver(&lm73_driver);
207}
208 198
209MODULE_AUTHOR("Guillaume Ligneul <guillaume.ligneul@gmail.com>"); 199MODULE_AUTHOR("Guillaume Ligneul <guillaume.ligneul@gmail.com>");
210MODULE_DESCRIPTION("LM73 driver"); 200MODULE_DESCRIPTION("LM73 driver");
211MODULE_LICENSE("GPL"); 201MODULE_LICENSE("GPL");
212
213module_init(sensors_lm73_init);
214module_exit(sensors_lm73_exit);
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index b3311b1d3d92..a83f206af244 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -438,23 +438,8 @@ abort:
438 return ret; 438 return ret;
439} 439}
440 440
441/*-----------------------------------------------------------------------*/ 441module_i2c_driver(lm75_driver);
442
443/* module glue */
444
445static int __init sensors_lm75_init(void)
446{
447 return i2c_add_driver(&lm75_driver);
448}
449
450static void __exit sensors_lm75_exit(void)
451{
452 i2c_del_driver(&lm75_driver);
453}
454 442
455MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>"); 443MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");
456MODULE_DESCRIPTION("LM75 driver"); 444MODULE_DESCRIPTION("LM75 driver");
457MODULE_LICENSE("GPL"); 445MODULE_LICENSE("GPL");
458
459module_init(sensors_lm75_init);
460module_exit(sensors_lm75_exit);
diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c
index 8dfc6782d596..0fca8613e7d8 100644
--- a/drivers/hwmon/lm77.c
+++ b/drivers/hwmon/lm77.c
@@ -1,29 +1,29 @@
1/* 1/*
2 lm77.c - Part of lm_sensors, Linux kernel modules for hardware 2 * lm77.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 * monitoring
4 4 *
5 Copyright (c) 2004 Andras BALI <drewie@freemail.hu> 5 * Copyright (c) 2004 Andras BALI <drewie@freemail.hu>
6 6 *
7 Heavily based on lm75.c by Frodo Looijaard <frodol@dds.nl>. The LM77 7 * Heavily based on lm75.c by Frodo Looijaard <frodol@dds.nl>. The LM77
8 is a temperature sensor and thermal window comparator with 0.5 deg 8 * is a temperature sensor and thermal window comparator with 0.5 deg
9 resolution made by National Semiconductor. Complete datasheet can be 9 * resolution made by National Semiconductor. Complete datasheet can be
10 obtained at their site: 10 * obtained at their site:
11 http://www.national.com/pf/LM/LM77.html 11 * http://www.national.com/pf/LM/LM77.html
12 12 *
13 This program is free software; you can redistribute it and/or modify 13 * This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by 14 * it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or 15 * the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version. 16 * (at your option) any later version.
17 17 *
18 This program is distributed in the hope that it will be useful, 18 * This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details. 21 * GNU General Public License for more details.
22 22 *
23 You should have received a copy of the GNU General Public License 23 * You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 24 * along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26*/ 26 */
27 27
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/init.h> 29#include <linux/init.h>
@@ -49,7 +49,7 @@ static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b,
49 49
50/* Each client has this additional data */ 50/* Each client has this additional data */
51struct lm77_data { 51struct lm77_data {
52 struct device *hwmon_dev; 52 struct device *hwmon_dev;
53 struct mutex update_lock; 53 struct mutex update_lock;
54 char valid; 54 char valid;
55 unsigned long last_updated; /* In jiffies */ 55 unsigned long last_updated; /* In jiffies */
@@ -95,8 +95,10 @@ static struct i2c_driver lm77_driver = {
95#define LM77_TEMP_MIN (-55000) 95#define LM77_TEMP_MIN (-55000)
96#define LM77_TEMP_MAX 125000 96#define LM77_TEMP_MAX 125000
97 97
98/* In the temperature registers, the low 3 bits are not part of the 98/*
99 temperature values; they are the status bits. */ 99 * In the temperature registers, the low 3 bits are not part of the
100 * temperature values; they are the status bits.
101 */
100static inline s16 LM77_TEMP_TO_REG(int temp) 102static inline s16 LM77_TEMP_TO_REG(int temp)
101{ 103{
102 int ntemp = SENSORS_LIMIT(temp, LM77_TEMP_MIN, LM77_TEMP_MAX); 104 int ntemp = SENSORS_LIMIT(temp, LM77_TEMP_MIN, LM77_TEMP_MAX);
@@ -112,7 +114,9 @@ static inline int LM77_TEMP_FROM_REG(s16 reg)
112 114
113/* read routines for temperature limits */ 115/* read routines for temperature limits */
114#define show(value) \ 116#define show(value) \
115static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \ 117static ssize_t show_##value(struct device *dev, \
118 struct device_attribute *attr, \
119 char *buf) \
116{ \ 120{ \
117 struct lm77_data *data = lm77_update_device(dev); \ 121 struct lm77_data *data = lm77_update_device(dev); \
118 return sprintf(buf, "%d\n", data->value); \ 122 return sprintf(buf, "%d\n", data->value); \
@@ -124,17 +128,20 @@ show(temp_min);
124show(temp_max); 128show(temp_max);
125 129
126/* read routines for hysteresis values */ 130/* read routines for hysteresis values */
127static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute *attr, char *buf) 131static ssize_t show_temp_crit_hyst(struct device *dev,
132 struct device_attribute *attr, char *buf)
128{ 133{
129 struct lm77_data *data = lm77_update_device(dev); 134 struct lm77_data *data = lm77_update_device(dev);
130 return sprintf(buf, "%d\n", data->temp_crit - data->temp_hyst); 135 return sprintf(buf, "%d\n", data->temp_crit - data->temp_hyst);
131} 136}
132static ssize_t show_temp_min_hyst(struct device *dev, struct device_attribute *attr, char *buf) 137static ssize_t show_temp_min_hyst(struct device *dev,
138 struct device_attribute *attr, char *buf)
133{ 139{
134 struct lm77_data *data = lm77_update_device(dev); 140 struct lm77_data *data = lm77_update_device(dev);
135 return sprintf(buf, "%d\n", data->temp_min + data->temp_hyst); 141 return sprintf(buf, "%d\n", data->temp_min + data->temp_hyst);
136} 142}
137static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute *attr, char *buf) 143static ssize_t show_temp_max_hyst(struct device *dev,
144 struct device_attribute *attr, char *buf)
138{ 145{
139 struct lm77_data *data = lm77_update_device(dev); 146 struct lm77_data *data = lm77_update_device(dev);
140 return sprintf(buf, "%d\n", data->temp_max - data->temp_hyst); 147 return sprintf(buf, "%d\n", data->temp_max - data->temp_hyst);
@@ -142,29 +149,42 @@ static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute *a
142 149
143/* write routines */ 150/* write routines */
144#define set(value, reg) \ 151#define set(value, reg) \
145static ssize_t set_##value(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ 152static ssize_t set_##value(struct device *dev, struct device_attribute *attr, \
146{ \ 153 const char *buf, size_t count) \
147 struct i2c_client *client = to_i2c_client(dev); \ 154{ \
148 struct lm77_data *data = i2c_get_clientdata(client); \ 155 struct i2c_client *client = to_i2c_client(dev); \
149 long val = simple_strtol(buf, NULL, 10); \ 156 struct lm77_data *data = i2c_get_clientdata(client); \
150 \ 157 long val; \
151 mutex_lock(&data->update_lock); \ 158 int err = kstrtol(buf, 10, &val); \
152 data->value = val; \ 159 if (err) \
153 lm77_write_value(client, reg, LM77_TEMP_TO_REG(data->value)); \ 160 return err; \
154 mutex_unlock(&data->update_lock); \ 161 \
155 return count; \ 162 mutex_lock(&data->update_lock); \
163 data->value = val; \
164 lm77_write_value(client, reg, LM77_TEMP_TO_REG(data->value)); \
165 mutex_unlock(&data->update_lock); \
166 return count; \
156} 167}
157 168
158set(temp_min, LM77_REG_TEMP_MIN); 169set(temp_min, LM77_REG_TEMP_MIN);
159set(temp_max, LM77_REG_TEMP_MAX); 170set(temp_max, LM77_REG_TEMP_MAX);
160 171
161/* hysteresis is stored as a relative value on the chip, so it has to be 172/*
162 converted first */ 173 * hysteresis is stored as a relative value on the chip, so it has to be
163static ssize_t set_temp_crit_hyst(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 174 * converted first
175 */
176static ssize_t set_temp_crit_hyst(struct device *dev,
177 struct device_attribute *attr,
178 const char *buf, size_t count)
164{ 179{
165 struct i2c_client *client = to_i2c_client(dev); 180 struct i2c_client *client = to_i2c_client(dev);
166 struct lm77_data *data = i2c_get_clientdata(client); 181 struct lm77_data *data = i2c_get_clientdata(client);
167 unsigned long val = simple_strtoul(buf, NULL, 10); 182 unsigned long val;
183 int err;
184
185 err = kstrtoul(buf, 10, &val);
186 if (err)
187 return err;
168 188
169 mutex_lock(&data->update_lock); 189 mutex_lock(&data->update_lock);
170 data->temp_hyst = data->temp_crit - val; 190 data->temp_hyst = data->temp_crit - val;
@@ -175,13 +195,19 @@ static ssize_t set_temp_crit_hyst(struct device *dev, struct device_attribute *a
175} 195}
176 196
177/* preserve hysteresis when setting T_crit */ 197/* preserve hysteresis when setting T_crit */
178static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 198static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
199 const char *buf, size_t count)
179{ 200{
180 struct i2c_client *client = to_i2c_client(dev); 201 struct i2c_client *client = to_i2c_client(dev);
181 struct lm77_data *data = i2c_get_clientdata(client); 202 struct lm77_data *data = i2c_get_clientdata(client);
182 long val = simple_strtoul(buf, NULL, 10);
183 int oldcrithyst; 203 int oldcrithyst;
184 204 unsigned long val;
205 int err;
206
207 err = kstrtoul(buf, 10, &val);
208 if (err)
209 return err;
210
185 mutex_lock(&data->update_lock); 211 mutex_lock(&data->update_lock);
186 oldcrithyst = data->temp_crit - data->temp_hyst; 212 oldcrithyst = data->temp_crit - data->temp_hyst;
187 data->temp_crit = val; 213 data->temp_crit = val;
@@ -251,17 +277,19 @@ static int lm77_detect(struct i2c_client *new_client,
251 I2C_FUNC_SMBUS_WORD_DATA)) 277 I2C_FUNC_SMBUS_WORD_DATA))
252 return -ENODEV; 278 return -ENODEV;
253 279
254 /* Here comes the remaining detection. Since the LM77 has no 280 /*
255 register dedicated to identification, we have to rely on the 281 * Here comes the remaining detection. Since the LM77 has no
256 following tricks: 282 * register dedicated to identification, we have to rely on the
257 283 * following tricks:
258 1. the high 4 bits represent the sign and thus they should 284 *
259 always be the same 285 * 1. the high 4 bits represent the sign and thus they should
260 2. the high 3 bits are unused in the configuration register 286 * always be the same
261 3. addresses 0x06 and 0x07 return the last read value 287 * 2. the high 3 bits are unused in the configuration register
262 4. registers cycling over 8-address boundaries 288 * 3. addresses 0x06 and 0x07 return the last read value
263 289 * 4. registers cycling over 8-address boundaries
264 Word-sized registers are high-byte first. */ 290 *
291 * Word-sized registers are high-byte first.
292 */
265 293
266 /* addresses cycling */ 294 /* addresses cycling */
267 cur = i2c_smbus_read_word_data(new_client, 0); 295 cur = i2c_smbus_read_word_data(new_client, 0);
@@ -330,7 +358,8 @@ static int lm77_probe(struct i2c_client *new_client,
330 lm77_init_client(new_client); 358 lm77_init_client(new_client);
331 359
332 /* Register sysfs hooks */ 360 /* Register sysfs hooks */
333 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm77_group))) 361 err = sysfs_create_group(&new_client->dev.kobj, &lm77_group);
362 if (err)
334 goto exit_free; 363 goto exit_free;
335 364
336 data->hwmon_dev = hwmon_device_register(&new_client->dev); 365 data->hwmon_dev = hwmon_device_register(&new_client->dev);
@@ -358,8 +387,10 @@ static int lm77_remove(struct i2c_client *client)
358 return 0; 387 return 0;
359} 388}
360 389
361/* All registers are word-sized, except for the configuration register. 390/*
362 The LM77 uses the high-byte first convention. */ 391 * All registers are word-sized, except for the configuration register.
392 * The LM77 uses the high-byte first convention.
393 */
363static u16 lm77_read_value(struct i2c_client *client, u8 reg) 394static u16 lm77_read_value(struct i2c_client *client, u8 reg)
364{ 395{
365 if (reg == LM77_REG_CONF) 396 if (reg == LM77_REG_CONF)
@@ -420,19 +451,8 @@ static struct lm77_data *lm77_update_device(struct device *dev)
420 return data; 451 return data;
421} 452}
422 453
423static int __init sensors_lm77_init(void) 454module_i2c_driver(lm77_driver);
424{
425 return i2c_add_driver(&lm77_driver);
426}
427
428static void __exit sensors_lm77_exit(void)
429{
430 i2c_del_driver(&lm77_driver);
431}
432 455
433MODULE_AUTHOR("Andras BALI <drewie@freemail.hu>"); 456MODULE_AUTHOR("Andras BALI <drewie@freemail.hu>");
434MODULE_DESCRIPTION("LM77 driver"); 457MODULE_DESCRIPTION("LM77 driver");
435MODULE_LICENSE("GPL"); 458MODULE_LICENSE("GPL");
436
437module_init(sensors_lm77_init);
438module_exit(sensors_lm77_exit);
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
index 6df0b4681710..f6bc414e1e91 100644
--- a/drivers/hwmon/lm78.c
+++ b/drivers/hwmon/lm78.c
@@ -1,23 +1,23 @@
1/* 1/*
2 lm78.c - Part of lm_sensors, Linux kernel modules for hardware 2 * lm78.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 * monitoring
4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> 4 * Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
5 Copyright (c) 2007, 2011 Jean Delvare <khali@linux-fr.org> 5 * Copyright (c) 2007, 2011 Jean Delvare <khali@linux-fr.org>
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
9 the Free Software Foundation; either version 2 of the License, or 9 * the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 10 * (at your option) any later version.
11 11 *
12 This program is distributed in the hope that it will be useful, 12 * This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 15 * GNU General Public License for more details.
16 16 *
17 You should have received a copy of the GNU General Public License 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 18 * along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/ 20 */
21 21
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23 23
@@ -74,11 +74,15 @@ enum chips { lm78, lm79 };
74#define LM78_REG_I2C_ADDR 0x48 74#define LM78_REG_I2C_ADDR 0x48
75 75
76 76
77/* Conversions. Rounding and limit checking is only done on the TO_REG 77/*
78 variants. */ 78 * Conversions. Rounding and limit checking is only done on the TO_REG
79 * variants.
80 */
79 81
80/* IN: mV, (0V to 4.08V) 82/*
81 REG: 16mV/bit */ 83 * IN: mV (0V to 4.08V)
84 * REG: 16mV/bit
85 */
82static inline u8 IN_TO_REG(unsigned long val) 86static inline u8 IN_TO_REG(unsigned long val)
83{ 87{
84 unsigned long nval = SENSORS_LIMIT(val, 0, 4080); 88 unsigned long nval = SENSORS_LIMIT(val, 0, 4080);
@@ -95,15 +99,17 @@ static inline u8 FAN_TO_REG(long rpm, int div)
95 99
96static inline int FAN_FROM_REG(u8 val, int div) 100static inline int FAN_FROM_REG(u8 val, int div)
97{ 101{
98 return val==0 ? -1 : val==255 ? 0 : 1350000/(val*div); 102 return val == 0 ? -1 : val == 255 ? 0 : 1350000 / (val * div);
99} 103}
100 104
101/* TEMP: mC (-128C to +127C) 105/*
102 REG: 1C/bit, two's complement */ 106 * TEMP: mC (-128C to +127C)
107 * REG: 1C/bit, two's complement
108 */
103static inline s8 TEMP_TO_REG(int val) 109static inline s8 TEMP_TO_REG(int val)
104{ 110{
105 int nval = SENSORS_LIMIT(val, -128000, 127000) ; 111 int nval = SENSORS_LIMIT(val, -128000, 127000) ;
106 return nval<0 ? (nval-500)/1000 : (nval+500)/1000; 112 return nval < 0 ? (nval - 500) / 1000 : (nval + 500) / 1000;
107} 113}
108 114
109static inline int TEMP_FROM_REG(s8 val) 115static inline int TEMP_FROM_REG(s8 val)
@@ -177,8 +183,13 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *da,
177{ 183{
178 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 184 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
179 struct lm78_data *data = dev_get_drvdata(dev); 185 struct lm78_data *data = dev_get_drvdata(dev);
180 unsigned long val = simple_strtoul(buf, NULL, 10);
181 int nr = attr->index; 186 int nr = attr->index;
187 unsigned long val;
188 int err;
189
190 err = kstrtoul(buf, 10, &val);
191 if (err)
192 return err;
182 193
183 mutex_lock(&data->update_lock); 194 mutex_lock(&data->update_lock);
184 data->in_min[nr] = IN_TO_REG(val); 195 data->in_min[nr] = IN_TO_REG(val);
@@ -192,8 +203,13 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *da,
192{ 203{
193 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 204 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
194 struct lm78_data *data = dev_get_drvdata(dev); 205 struct lm78_data *data = dev_get_drvdata(dev);
195 unsigned long val = simple_strtoul(buf, NULL, 10);
196 int nr = attr->index; 206 int nr = attr->index;
207 unsigned long val;
208 int err;
209
210 err = kstrtoul(buf, 10, &val);
211 if (err)
212 return err;
197 213
198 mutex_lock(&data->update_lock); 214 mutex_lock(&data->update_lock);
199 data->in_max[nr] = IN_TO_REG(val); 215 data->in_max[nr] = IN_TO_REG(val);
@@ -201,7 +217,7 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *da,
201 mutex_unlock(&data->update_lock); 217 mutex_unlock(&data->update_lock);
202 return count; 218 return count;
203} 219}
204 220
205#define show_in_offset(offset) \ 221#define show_in_offset(offset) \
206static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ 222static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
207 show_in, NULL, offset); \ 223 show_in, NULL, offset); \
@@ -237,7 +253,12 @@ static ssize_t set_temp_over(struct device *dev, struct device_attribute *da,
237 const char *buf, size_t count) 253 const char *buf, size_t count)
238{ 254{
239 struct lm78_data *data = dev_get_drvdata(dev); 255 struct lm78_data *data = dev_get_drvdata(dev);
240 long val = simple_strtol(buf, NULL, 10); 256 long val;
257 int err;
258
259 err = kstrtol(buf, 10, &val);
260 if (err)
261 return err;
241 262
242 mutex_lock(&data->update_lock); 263 mutex_lock(&data->update_lock);
243 data->temp_over = TEMP_TO_REG(val); 264 data->temp_over = TEMP_TO_REG(val);
@@ -257,7 +278,12 @@ static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *da,
257 const char *buf, size_t count) 278 const char *buf, size_t count)
258{ 279{
259 struct lm78_data *data = dev_get_drvdata(dev); 280 struct lm78_data *data = dev_get_drvdata(dev);
260 long val = simple_strtol(buf, NULL, 10); 281 long val;
282 int err;
283
284 err = kstrtol(buf, 10, &val);
285 if (err)
286 return err;
261 287
262 mutex_lock(&data->update_lock); 288 mutex_lock(&data->update_lock);
263 data->temp_hyst = TEMP_TO_REG(val); 289 data->temp_hyst = TEMP_TO_REG(val);
@@ -280,7 +306,7 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *da,
280 struct lm78_data *data = lm78_update_device(dev); 306 struct lm78_data *data = lm78_update_device(dev);
281 int nr = attr->index; 307 int nr = attr->index;
282 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], 308 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
283 DIV_FROM_REG(data->fan_div[nr])) ); 309 DIV_FROM_REG(data->fan_div[nr])));
284} 310}
285 311
286static ssize_t show_fan_min(struct device *dev, struct device_attribute *da, 312static ssize_t show_fan_min(struct device *dev, struct device_attribute *da,
@@ -289,8 +315,8 @@ static ssize_t show_fan_min(struct device *dev, struct device_attribute *da,
289 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 315 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
290 struct lm78_data *data = lm78_update_device(dev); 316 struct lm78_data *data = lm78_update_device(dev);
291 int nr = attr->index; 317 int nr = attr->index;
292 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr], 318 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
293 DIV_FROM_REG(data->fan_div[nr])) ); 319 DIV_FROM_REG(data->fan_div[nr])));
294} 320}
295 321
296static ssize_t set_fan_min(struct device *dev, struct device_attribute *da, 322static ssize_t set_fan_min(struct device *dev, struct device_attribute *da,
@@ -299,7 +325,12 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *da,
299 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 325 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
300 struct lm78_data *data = dev_get_drvdata(dev); 326 struct lm78_data *data = dev_get_drvdata(dev);
301 int nr = attr->index; 327 int nr = attr->index;
302 unsigned long val = simple_strtoul(buf, NULL, 10); 328 unsigned long val;
329 int err;
330
331 err = kstrtoul(buf, 10, &val);
332 if (err)
333 return err;
303 334
304 mutex_lock(&data->update_lock); 335 mutex_lock(&data->update_lock);
305 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 336 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
@@ -316,29 +347,44 @@ static ssize_t show_fan_div(struct device *dev, struct device_attribute *da,
316 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[attr->index])); 347 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[attr->index]));
317} 348}
318 349
319/* Note: we save and restore the fan minimum here, because its value is 350/*
320 determined in part by the fan divisor. This follows the principle of 351 * Note: we save and restore the fan minimum here, because its value is
321 least surprise; the user doesn't expect the fan minimum to change just 352 * determined in part by the fan divisor. This follows the principle of
322 because the divisor changed. */ 353 * least surprise; the user doesn't expect the fan minimum to change just
354 * because the divisor changed.
355 */
323static ssize_t set_fan_div(struct device *dev, struct device_attribute *da, 356static ssize_t set_fan_div(struct device *dev, struct device_attribute *da,
324 const char *buf, size_t count) 357 const char *buf, size_t count)
325{ 358{
326 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 359 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
327 struct lm78_data *data = dev_get_drvdata(dev); 360 struct lm78_data *data = dev_get_drvdata(dev);
328 int nr = attr->index; 361 int nr = attr->index;
329 unsigned long val = simple_strtoul(buf, NULL, 10);
330 unsigned long min; 362 unsigned long min;
331 u8 reg; 363 u8 reg;
364 unsigned long val;
365 int err;
366
367 err = kstrtoul(buf, 10, &val);
368 if (err)
369 return err;
332 370
333 mutex_lock(&data->update_lock); 371 mutex_lock(&data->update_lock);
334 min = FAN_FROM_REG(data->fan_min[nr], 372 min = FAN_FROM_REG(data->fan_min[nr],
335 DIV_FROM_REG(data->fan_div[nr])); 373 DIV_FROM_REG(data->fan_div[nr]));
336 374
337 switch (val) { 375 switch (val) {
338 case 1: data->fan_div[nr] = 0; break; 376 case 1:
339 case 2: data->fan_div[nr] = 1; break; 377 data->fan_div[nr] = 0;
340 case 4: data->fan_div[nr] = 2; break; 378 break;
341 case 8: data->fan_div[nr] = 3; break; 379 case 2:
380 data->fan_div[nr] = 1;
381 break;
382 case 4:
383 data->fan_div[nr] = 2;
384 break;
385 case 8:
386 data->fan_div[nr] = 3;
387 break;
342 default: 388 default:
343 dev_err(dev, "fan_div value %ld not " 389 dev_err(dev, "fan_div value %ld not "
344 "supported. Choose one of 1, 2, 4 or 8!\n", val); 390 "supported. Choose one of 1, 2, 4 or 8!\n", val);
@@ -484,8 +530,10 @@ static struct platform_device *pdev;
484 530
485static unsigned short isa_address = 0x290; 531static unsigned short isa_address = 0x290;
486 532
487/* I2C devices get this name attribute automatically, but for ISA devices 533/*
488 we must create it by ourselves. */ 534 * I2C devices get this name attribute automatically, but for ISA devices
535 * we must create it by ourselves.
536 */
489static ssize_t show_name(struct device *dev, struct device_attribute 537static ssize_t show_name(struct device *dev, struct device_attribute
490 *devattr, char *buf) 538 *devattr, char *buf)
491{ 539{
@@ -515,8 +563,10 @@ static int lm78_alias_detect(struct i2c_client *client, u8 chipid)
515 if ((lm78_read_value(isa, LM78_REG_CHIPID) & 0xfe) != (chipid & 0xfe)) 563 if ((lm78_read_value(isa, LM78_REG_CHIPID) & 0xfe) != (chipid & 0xfe))
516 return 0; /* Chip type doesn't match */ 564 return 0; /* Chip type doesn't match */
517 565
518 /* We compare all the limit registers, the config register and the 566 /*
519 * interrupt mask registers */ 567 * We compare all the limit registers, the config register and the
568 * interrupt mask registers
569 */
520 for (i = 0x2b; i <= 0x3d; i++) { 570 for (i = 0x2b; i <= 0x3d; i++) {
521 if (lm78_read_value(isa, i) != 571 if (lm78_read_value(isa, i) !=
522 i2c_smbus_read_byte_data(client, i)) 572 i2c_smbus_read_byte_data(client, i))
@@ -558,9 +608,11 @@ static int lm78_i2c_detect(struct i2c_client *client,
558 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 608 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
559 return -ENODEV; 609 return -ENODEV;
560 610
561 /* We block updates of the ISA device to minimize the risk of 611 /*
562 concurrent access to the same LM78 chip through different 612 * We block updates of the ISA device to minimize the risk of
563 interfaces. */ 613 * concurrent access to the same LM78 chip through different
614 * interfaces.
615 */
564 if (isa) 616 if (isa)
565 mutex_lock(&isa->update_lock); 617 mutex_lock(&isa->update_lock);
566 618
@@ -669,11 +721,13 @@ static struct i2c_driver lm78_driver = {
669 .address_list = normal_i2c, 721 .address_list = normal_i2c,
670}; 722};
671 723
672/* The SMBus locks itself, but ISA access must be locked explicitly! 724/*
673 We don't want to lock the whole ISA bus, so we lock each client 725 * The SMBus locks itself, but ISA access must be locked explicitly!
674 separately. 726 * We don't want to lock the whole ISA bus, so we lock each client
675 We ignore the LM78 BUSY flag at this moment - it could lead to deadlocks, 727 * separately.
676 would slow down the LM78 access and should not be necessary. */ 728 * We ignore the LM78 BUSY flag at this moment - it could lead to deadlocks,
729 * would slow down the LM78 access and should not be necessary.
730 */
677static int lm78_read_value(struct lm78_data *data, u8 reg) 731static int lm78_read_value(struct lm78_data *data, u8 reg)
678{ 732{
679 struct i2c_client *client = data->client; 733 struct i2c_client *client = data->client;
@@ -691,13 +745,6 @@ static int lm78_read_value(struct lm78_data *data, u8 reg)
691 return i2c_smbus_read_byte_data(client, reg); 745 return i2c_smbus_read_byte_data(client, reg);
692} 746}
693 747
694/* The SMBus locks itself, but ISA access muse be locked explicitly!
695 We don't want to lock the whole ISA bus, so we lock each client
696 separately.
697 We ignore the LM78 BUSY flag at this moment - it could lead to deadlocks,
698 would slow down the LM78 access and should not be necessary.
699 There are some ugly typecasts here, but the good new is - they should
700 nowhere else be necessary! */
701static int lm78_write_value(struct lm78_data *data, u8 reg, u8 value) 748static int lm78_write_value(struct lm78_data *data, u8 reg, u8 value)
702{ 749{
703 struct i2c_client *client = data->client; 750 struct i2c_client *client = data->client;
@@ -823,8 +870,11 @@ static int __devinit lm78_isa_probe(struct platform_device *pdev)
823 lm78_init_device(data); 870 lm78_init_device(data);
824 871
825 /* Register sysfs hooks */ 872 /* Register sysfs hooks */
826 if ((err = sysfs_create_group(&pdev->dev.kobj, &lm78_group)) 873 err = sysfs_create_group(&pdev->dev.kobj, &lm78_group);
827 || (err = device_create_file(&pdev->dev, &dev_attr_name))) 874 if (err)
875 goto exit_remove_files;
876 err = device_create_file(&pdev->dev, &dev_attr_name);
877 if (err)
828 goto exit_remove_files; 878 goto exit_remove_files;
829 879
830 data->hwmon_dev = hwmon_device_register(&pdev->dev); 880 data->hwmon_dev = hwmon_device_register(&pdev->dev);
@@ -876,9 +926,11 @@ static int __init lm78_isa_found(unsigned short address)
876 int val, save, found = 0; 926 int val, save, found = 0;
877 int port; 927 int port;
878 928
879 /* Some boards declare base+0 to base+7 as a PNP device, some base+4 929 /*
930 * Some boards declare base+0 to base+7 as a PNP device, some base+4
880 * to base+7 and some base+5 to base+6. So we better request each port 931 * to base+7 and some base+5 to base+6. So we better request each port
881 * individually for the probing phase. */ 932 * individually for the probing phase.
933 */
882 for (port = address; port < address + LM78_EXTENT; port++) { 934 for (port = address; port < address + LM78_EXTENT; port++) {
883 if (!request_region(port, 1, "lm78")) { 935 if (!request_region(port, 1, "lm78")) {
884 pr_debug("Failed to request port 0x%x\n", port); 936 pr_debug("Failed to request port 0x%x\n", port);
@@ -887,8 +939,10 @@ static int __init lm78_isa_found(unsigned short address)
887 } 939 }
888 940
889#define REALLY_SLOW_IO 941#define REALLY_SLOW_IO
890 /* We need the timeouts for at least some LM78-like 942 /*
891 chips. But only if we read 'undefined' registers. */ 943 * We need the timeouts for at least some LM78-like
944 * chips. But only if we read 'undefined' registers.
945 */
892 val = inb_p(address + 1); 946 val = inb_p(address + 1);
893 if (inb_p(address + 2) != val 947 if (inb_p(address + 2) != val
894 || inb_p(address + 3) != val 948 || inb_p(address + 3) != val
@@ -896,8 +950,10 @@ static int __init lm78_isa_found(unsigned short address)
896 goto release; 950 goto release;
897#undef REALLY_SLOW_IO 951#undef REALLY_SLOW_IO
898 952
899 /* We should be able to change the 7 LSB of the address port. The 953 /*
900 MSB (busy flag) should be clear initially, set after the write. */ 954 * We should be able to change the 7 LSB of the address port. The
955 * MSB (busy flag) should be clear initially, set after the write.
956 */
901 save = inb_p(address + LM78_ADDR_REG_OFFSET); 957 save = inb_p(address + LM78_ADDR_REG_OFFSET);
902 if (save & 0x80) 958 if (save & 0x80)
903 goto release; 959 goto release;
@@ -1036,8 +1092,10 @@ static int __init sm_lm78_init(void)
1036{ 1092{
1037 int res; 1093 int res;
1038 1094
1039 /* We register the ISA device first, so that we can skip the 1095 /*
1040 * registration of an I2C interface to the same device. */ 1096 * We register the ISA device first, so that we can skip the
1097 * registration of an I2C interface to the same device.
1098 */
1041 res = lm78_isa_register(); 1099 res = lm78_isa_register();
1042 if (res) 1100 if (res)
1043 goto exit; 1101 goto exit;
diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c
index 0891b38ffec0..e2c43e1774be 100644
--- a/drivers/hwmon/lm80.c
+++ b/drivers/hwmon/lm80.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * lm80.c - From lm_sensors, Linux kernel modules for hardware 2 * lm80.c - From lm_sensors, Linux kernel modules for hardware
3 * monitoring 3 * monitoring
4 * Copyright (C) 1998, 1999 Frodo Looijaard <frodol@dds.nl> 4 * Copyright (C) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
5 * and Philip Edelbrock <phil@netroedge.com> 5 * and Philip Edelbrock <phil@netroedge.com>
6 * 6 *
7 * Ported to Linux 2.6 by Tiago Sousa <mirage@kaotik.org> 7 * Ported to Linux 2.6 by Tiago Sousa <mirage@kaotik.org>
8 * 8 *
@@ -60,11 +60,17 @@ static const unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
60#define LM80_REG_FANDIV 0x05 60#define LM80_REG_FANDIV 0x05
61#define LM80_REG_RES 0x06 61#define LM80_REG_RES 0x06
62 62
63#define LM96080_REG_CONV_RATE 0x07
64#define LM96080_REG_MAN_ID 0x3e
65#define LM96080_REG_DEV_ID 0x3f
63 66
64/* Conversions. Rounding and limit checking is only done on the TO_REG 67
65 variants. Note that you should be a bit careful with which arguments 68/*
66 these macros are called: arguments may be evaluated more than once. 69 * Conversions. Rounding and limit checking is only done on the TO_REG
67 Fixing this is just not worth it. */ 70 * variants. Note that you should be a bit careful with which arguments
71 * these macros are called: arguments may be evaluated more than once.
72 * Fixing this is just not worth it.
73 */
68 74
69#define IN_TO_REG(val) (SENSORS_LIMIT(((val) + 5) / 10, 0, 255)) 75#define IN_TO_REG(val) (SENSORS_LIMIT(((val) + 5) / 10, 0, 255))
70#define IN_FROM_REG(val) ((val) * 10) 76#define IN_FROM_REG(val) ((val) * 10)
@@ -108,6 +114,7 @@ static inline long TEMP_FROM_REG(u16 temp)
108struct lm80_data { 114struct lm80_data {
109 struct device *hwmon_dev; 115 struct device *hwmon_dev;
110 struct mutex update_lock; 116 struct mutex update_lock;
117 char error; /* !=0 if error occurred during last update */
111 char valid; /* !=0 if following fields are valid */ 118 char valid; /* !=0 if following fields are valid */
112 unsigned long last_updated; /* In jiffies */ 119 unsigned long last_updated; /* In jiffies */
113 120
@@ -144,6 +151,7 @@ static int lm80_write_value(struct i2c_client *client, u8 reg, u8 value);
144 151
145static const struct i2c_device_id lm80_id[] = { 152static const struct i2c_device_id lm80_id[] = {
146 { "lm80", 0 }, 153 { "lm80", 0 },
154 { "lm96080", 1 },
147 { } 155 { }
148}; 156};
149MODULE_DEVICE_TABLE(i2c, lm80_id); 157MODULE_DEVICE_TABLE(i2c, lm80_id);
@@ -170,6 +178,8 @@ static ssize_t show_in_##suffix(struct device *dev, \
170{ \ 178{ \
171 int nr = to_sensor_dev_attr(attr)->index; \ 179 int nr = to_sensor_dev_attr(attr)->index; \
172 struct lm80_data *data = lm80_update_device(dev); \ 180 struct lm80_data *data = lm80_update_device(dev); \
181 if (IS_ERR(data)) \
182 return PTR_ERR(data); \
173 return sprintf(buf, "%d\n", IN_FROM_REG(data->value[nr])); \ 183 return sprintf(buf, "%d\n", IN_FROM_REG(data->value[nr])); \
174} 184}
175show_in(min, in_min) 185show_in(min, in_min)
@@ -183,7 +193,10 @@ static ssize_t set_in_##suffix(struct device *dev, \
183 int nr = to_sensor_dev_attr(attr)->index; \ 193 int nr = to_sensor_dev_attr(attr)->index; \
184 struct i2c_client *client = to_i2c_client(dev); \ 194 struct i2c_client *client = to_i2c_client(dev); \
185 struct lm80_data *data = i2c_get_clientdata(client); \ 195 struct lm80_data *data = i2c_get_clientdata(client); \
186 long val = simple_strtol(buf, NULL, 10); \ 196 long val; \
197 int err = kstrtol(buf, 10, &val); \
198 if (err < 0) \
199 return err; \
187\ 200\
188 mutex_lock(&data->update_lock);\ 201 mutex_lock(&data->update_lock);\
189 data->value[nr] = IN_TO_REG(val); \ 202 data->value[nr] = IN_TO_REG(val); \
@@ -200,6 +213,8 @@ static ssize_t show_fan_##suffix(struct device *dev, \
200{ \ 213{ \
201 int nr = to_sensor_dev_attr(attr)->index; \ 214 int nr = to_sensor_dev_attr(attr)->index; \
202 struct lm80_data *data = lm80_update_device(dev); \ 215 struct lm80_data *data = lm80_update_device(dev); \
216 if (IS_ERR(data)) \
217 return PTR_ERR(data); \
203 return sprintf(buf, "%d\n", FAN_FROM_REG(data->value[nr], \ 218 return sprintf(buf, "%d\n", FAN_FROM_REG(data->value[nr], \
204 DIV_FROM_REG(data->fan_div[nr]))); \ 219 DIV_FROM_REG(data->fan_div[nr]))); \
205} 220}
@@ -211,6 +226,8 @@ static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
211{ 226{
212 int nr = to_sensor_dev_attr(attr)->index; 227 int nr = to_sensor_dev_attr(attr)->index;
213 struct lm80_data *data = lm80_update_device(dev); 228 struct lm80_data *data = lm80_update_device(dev);
229 if (IS_ERR(data))
230 return PTR_ERR(data);
214 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); 231 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
215} 232}
216 233
@@ -220,7 +237,10 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
220 int nr = to_sensor_dev_attr(attr)->index; 237 int nr = to_sensor_dev_attr(attr)->index;
221 struct i2c_client *client = to_i2c_client(dev); 238 struct i2c_client *client = to_i2c_client(dev);
222 struct lm80_data *data = i2c_get_clientdata(client); 239 struct lm80_data *data = i2c_get_clientdata(client);
223 long val = simple_strtoul(buf, NULL, 10); 240 unsigned long val;
241 int err = kstrtoul(buf, 10, &val);
242 if (err < 0)
243 return err;
224 244
225 mutex_lock(&data->update_lock); 245 mutex_lock(&data->update_lock);
226 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 246 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
@@ -229,18 +249,23 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
229 return count; 249 return count;
230} 250}
231 251
232/* Note: we save and restore the fan minimum here, because its value is 252/*
233 determined in part by the fan divisor. This follows the principle of 253 * Note: we save and restore the fan minimum here, because its value is
234 least surprise; the user doesn't expect the fan minimum to change just 254 * determined in part by the fan divisor. This follows the principle of
235 because the divisor changed. */ 255 * least surprise; the user doesn't expect the fan minimum to change just
256 * because the divisor changed.
257 */
236static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, 258static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
237 const char *buf, size_t count) 259 const char *buf, size_t count)
238{ 260{
239 int nr = to_sensor_dev_attr(attr)->index; 261 int nr = to_sensor_dev_attr(attr)->index;
240 struct i2c_client *client = to_i2c_client(dev); 262 struct i2c_client *client = to_i2c_client(dev);
241 struct lm80_data *data = i2c_get_clientdata(client); 263 struct lm80_data *data = i2c_get_clientdata(client);
242 unsigned long min, val = simple_strtoul(buf, NULL, 10); 264 unsigned long min, val;
243 u8 reg; 265 u8 reg;
266 int err = kstrtoul(buf, 10, &val);
267 if (err < 0)
268 return err;
244 269
245 /* Save fan_min */ 270 /* Save fan_min */
246 mutex_lock(&data->update_lock); 271 mutex_lock(&data->update_lock);
@@ -283,6 +308,8 @@ static ssize_t show_temp_input1(struct device *dev,
283 struct device_attribute *attr, char *buf) 308 struct device_attribute *attr, char *buf)
284{ 309{
285 struct lm80_data *data = lm80_update_device(dev); 310 struct lm80_data *data = lm80_update_device(dev);
311 if (IS_ERR(data))
312 return PTR_ERR(data);
286 return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp)); 313 return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp));
287} 314}
288 315
@@ -291,6 +318,8 @@ static ssize_t show_temp_##suffix(struct device *dev, \
291 struct device_attribute *attr, char *buf) \ 318 struct device_attribute *attr, char *buf) \
292{ \ 319{ \
293 struct lm80_data *data = lm80_update_device(dev); \ 320 struct lm80_data *data = lm80_update_device(dev); \
321 if (IS_ERR(data)) \
322 return PTR_ERR(data); \
294 return sprintf(buf, "%d\n", TEMP_LIMIT_FROM_REG(data->value)); \ 323 return sprintf(buf, "%d\n", TEMP_LIMIT_FROM_REG(data->value)); \
295} 324}
296show_temp(hot_max, temp_hot_max); 325show_temp(hot_max, temp_hot_max);
@@ -304,7 +333,10 @@ static ssize_t set_temp_##suffix(struct device *dev, \
304{ \ 333{ \
305 struct i2c_client *client = to_i2c_client(dev); \ 334 struct i2c_client *client = to_i2c_client(dev); \
306 struct lm80_data *data = i2c_get_clientdata(client); \ 335 struct lm80_data *data = i2c_get_clientdata(client); \
307 long val = simple_strtoul(buf, NULL, 10); \ 336 long val; \
337 int err = kstrtol(buf, 10, &val); \
338 if (err < 0) \
339 return err; \
308\ 340\
309 mutex_lock(&data->update_lock); \ 341 mutex_lock(&data->update_lock); \
310 data->value = TEMP_LIMIT_TO_REG(val); \ 342 data->value = TEMP_LIMIT_TO_REG(val); \
@@ -321,6 +353,8 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
321 char *buf) 353 char *buf)
322{ 354{
323 struct lm80_data *data = lm80_update_device(dev); 355 struct lm80_data *data = lm80_update_device(dev);
356 if (IS_ERR(data))
357 return PTR_ERR(data);
324 return sprintf(buf, "%u\n", data->alarms); 358 return sprintf(buf, "%u\n", data->alarms);
325} 359}
326 360
@@ -329,6 +363,8 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
329{ 363{
330 int bitnr = to_sensor_dev_attr(attr)->index; 364 int bitnr = to_sensor_dev_attr(attr)->index;
331 struct lm80_data *data = lm80_update_device(dev); 365 struct lm80_data *data = lm80_update_device(dev);
366 if (IS_ERR(data))
367 return PTR_ERR(data);
332 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); 368 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
333} 369}
334 370
@@ -459,23 +495,44 @@ static const struct attribute_group lm80_group = {
459static int lm80_detect(struct i2c_client *client, struct i2c_board_info *info) 495static int lm80_detect(struct i2c_client *client, struct i2c_board_info *info)
460{ 496{
461 struct i2c_adapter *adapter = client->adapter; 497 struct i2c_adapter *adapter = client->adapter;
462 int i, cur; 498 int i, cur, man_id, dev_id;
499 const char *name = NULL;
463 500
464 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 501 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
465 return -ENODEV; 502 return -ENODEV;
466 503
467 /* Now, we do the remaining detection. It is lousy. */ 504 /* First check for unused bits, common to both chip types */
468 if (lm80_read_value(client, LM80_REG_ALARM2) & 0xc0) 505 if ((lm80_read_value(client, LM80_REG_ALARM2) & 0xc0)
506 || (lm80_read_value(client, LM80_REG_CONFIG) & 0x80))
469 return -ENODEV; 507 return -ENODEV;
470 for (i = 0x2a; i <= 0x3d; i++) { 508
471 cur = i2c_smbus_read_byte_data(client, i); 509 /*
472 if ((i2c_smbus_read_byte_data(client, i + 0x40) != cur) 510 * The LM96080 has manufacturer and stepping/die rev registers so we
473 || (i2c_smbus_read_byte_data(client, i + 0x80) != cur) 511 * can just check that. The LM80 does not have such registers so we
474 || (i2c_smbus_read_byte_data(client, i + 0xc0) != cur)) 512 * have to use a more expensive trick.
513 */
514 man_id = lm80_read_value(client, LM96080_REG_MAN_ID);
515 dev_id = lm80_read_value(client, LM96080_REG_DEV_ID);
516 if (man_id == 0x01 && dev_id == 0x08) {
517 /* Check more unused bits for confirmation */
518 if (lm80_read_value(client, LM96080_REG_CONV_RATE) & 0xfe)
475 return -ENODEV; 519 return -ENODEV;
520
521 name = "lm96080";
522 } else {
523 /* Check 6-bit addressing */
524 for (i = 0x2a; i <= 0x3d; i++) {
525 cur = i2c_smbus_read_byte_data(client, i);
526 if ((i2c_smbus_read_byte_data(client, i + 0x40) != cur)
527 || (i2c_smbus_read_byte_data(client, i + 0x80) != cur)
528 || (i2c_smbus_read_byte_data(client, i + 0xc0) != cur))
529 return -ENODEV;
530 }
531
532 name = "lm80";
476 } 533 }
477 534
478 strlcpy(info->type, "lm80", I2C_NAME_SIZE); 535 strlcpy(info->type, name, I2C_NAME_SIZE);
479 536
480 return 0; 537 return 0;
481} 538}
@@ -547,9 +604,11 @@ static int lm80_write_value(struct i2c_client *client, u8 reg, u8 value)
547/* Called when we have found a new LM80. */ 604/* Called when we have found a new LM80. */
548static void lm80_init_client(struct i2c_client *client) 605static void lm80_init_client(struct i2c_client *client)
549{ 606{
550 /* Reset all except Watchdog values and last conversion values 607 /*
551 This sets fan-divs to 2, among others. This makes most other 608 * Reset all except Watchdog values and last conversion values
552 initializations unnecessary */ 609 * This sets fan-divs to 2, among others. This makes most other
610 * initializations unnecessary
611 */
553 lm80_write_value(client, LM80_REG_CONFIG, 0x80); 612 lm80_write_value(client, LM80_REG_CONFIG, 0x80);
554 /* Set 11-bit temperature resolution */ 613 /* Set 11-bit temperature resolution */
555 lm80_write_value(client, LM80_REG_RES, 0x08); 614 lm80_write_value(client, LM80_REG_RES, 0x08);
@@ -563,66 +622,116 @@ static struct lm80_data *lm80_update_device(struct device *dev)
563 struct i2c_client *client = to_i2c_client(dev); 622 struct i2c_client *client = to_i2c_client(dev);
564 struct lm80_data *data = i2c_get_clientdata(client); 623 struct lm80_data *data = i2c_get_clientdata(client);
565 int i; 624 int i;
625 int rv;
626 int prev_rv;
627 struct lm80_data *ret = data;
566 628
567 mutex_lock(&data->update_lock); 629 mutex_lock(&data->update_lock);
568 630
631 if (data->error)
632 lm80_init_client(client);
633
569 if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) { 634 if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
570 dev_dbg(&client->dev, "Starting lm80 update\n"); 635 dev_dbg(&client->dev, "Starting lm80 update\n");
571 for (i = 0; i <= 6; i++) { 636 for (i = 0; i <= 6; i++) {
572 data->in[i] = 637 rv = lm80_read_value(client, LM80_REG_IN(i));
573 lm80_read_value(client, LM80_REG_IN(i)); 638 if (rv < 0)
574 data->in_min[i] = 639 goto abort;
575 lm80_read_value(client, LM80_REG_IN_MIN(i)); 640 data->in[i] = rv;
576 data->in_max[i] = 641
577 lm80_read_value(client, LM80_REG_IN_MAX(i)); 642 rv = lm80_read_value(client, LM80_REG_IN_MIN(i));
643 if (rv < 0)
644 goto abort;
645 data->in_min[i] = rv;
646
647 rv = lm80_read_value(client, LM80_REG_IN_MAX(i));
648 if (rv < 0)
649 goto abort;
650 data->in_max[i] = rv;
578 } 651 }
579 data->fan[0] = lm80_read_value(client, LM80_REG_FAN1); 652
580 data->fan_min[0] = 653 rv = lm80_read_value(client, LM80_REG_FAN1);
581 lm80_read_value(client, LM80_REG_FAN_MIN(1)); 654 if (rv < 0)
582 data->fan[1] = lm80_read_value(client, LM80_REG_FAN2); 655 goto abort;
583 data->fan_min[1] = 656 data->fan[0] = rv;
584 lm80_read_value(client, LM80_REG_FAN_MIN(2)); 657
585 658 rv = lm80_read_value(client, LM80_REG_FAN_MIN(1));
586 data->temp = 659 if (rv < 0)
587 (lm80_read_value(client, LM80_REG_TEMP) << 8) | 660 goto abort;
588 (lm80_read_value(client, LM80_REG_RES) & 0xf0); 661 data->fan_min[0] = rv;
589 data->temp_os_max = 662
590 lm80_read_value(client, LM80_REG_TEMP_OS_MAX); 663 rv = lm80_read_value(client, LM80_REG_FAN2);
591 data->temp_os_hyst = 664 if (rv < 0)
592 lm80_read_value(client, LM80_REG_TEMP_OS_HYST); 665 goto abort;
593 data->temp_hot_max = 666 data->fan[1] = rv;
594 lm80_read_value(client, LM80_REG_TEMP_HOT_MAX); 667
595 data->temp_hot_hyst = 668 rv = lm80_read_value(client, LM80_REG_FAN_MIN(2));
596 lm80_read_value(client, LM80_REG_TEMP_HOT_HYST); 669 if (rv < 0)
597 670 goto abort;
598 i = lm80_read_value(client, LM80_REG_FANDIV); 671 data->fan_min[1] = rv;
599 data->fan_div[0] = (i >> 2) & 0x03; 672
600 data->fan_div[1] = (i >> 4) & 0x03; 673 prev_rv = rv = lm80_read_value(client, LM80_REG_TEMP);
601 data->alarms = lm80_read_value(client, LM80_REG_ALARM1) + 674 if (rv < 0)
602 (lm80_read_value(client, LM80_REG_ALARM2) << 8); 675 goto abort;
676 rv = lm80_read_value(client, LM80_REG_RES);
677 if (rv < 0)
678 goto abort;
679 data->temp = (prev_rv << 8) | (rv & 0xf0);
680
681 rv = lm80_read_value(client, LM80_REG_TEMP_OS_MAX);
682 if (rv < 0)
683 goto abort;
684 data->temp_os_max = rv;
685
686 rv = lm80_read_value(client, LM80_REG_TEMP_OS_HYST);
687 if (rv < 0)
688 goto abort;
689 data->temp_os_hyst = rv;
690
691 rv = lm80_read_value(client, LM80_REG_TEMP_HOT_MAX);
692 if (rv < 0)
693 goto abort;
694 data->temp_hot_max = rv;
695
696 rv = lm80_read_value(client, LM80_REG_TEMP_HOT_HYST);
697 if (rv < 0)
698 goto abort;
699 data->temp_hot_hyst = rv;
700
701 rv = lm80_read_value(client, LM80_REG_FANDIV);
702 if (rv < 0)
703 goto abort;
704 data->fan_div[0] = (rv >> 2) & 0x03;
705 data->fan_div[1] = (rv >> 4) & 0x03;
706
707 prev_rv = rv = lm80_read_value(client, LM80_REG_ALARM1);
708 if (rv < 0)
709 goto abort;
710 rv = lm80_read_value(client, LM80_REG_ALARM2);
711 if (rv < 0)
712 goto abort;
713 data->alarms = prev_rv + (rv << 8);
714
603 data->last_updated = jiffies; 715 data->last_updated = jiffies;
604 data->valid = 1; 716 data->valid = 1;
717 data->error = 0;
605 } 718 }
719 goto done;
720
721abort:
722 ret = ERR_PTR(rv);
723 data->valid = 0;
724 data->error = 1;
606 725
726done:
607 mutex_unlock(&data->update_lock); 727 mutex_unlock(&data->update_lock);
608 728
609 return data; 729 return ret;
610} 730}
611 731
612static int __init sensors_lm80_init(void) 732module_i2c_driver(lm80_driver);
613{
614 return i2c_add_driver(&lm80_driver);
615}
616
617static void __exit sensors_lm80_exit(void)
618{
619 i2c_del_driver(&lm80_driver);
620}
621 733
622MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and " 734MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and "
623 "Philip Edelbrock <phil@netroedge.com>"); 735 "Philip Edelbrock <phil@netroedge.com>");
624MODULE_DESCRIPTION("LM80 driver"); 736MODULE_DESCRIPTION("LM80 driver");
625MODULE_LICENSE("GPL"); 737MODULE_LICENSE("GPL");
626
627module_init(sensors_lm80_init);
628module_exit(sensors_lm80_exit);
diff --git a/drivers/hwmon/lm83.c b/drivers/hwmon/lm83.c
index 8290476aee4a..cd45b9d85584 100644
--- a/drivers/hwmon/lm83.c
+++ b/drivers/hwmon/lm83.c
@@ -124,7 +124,7 @@ static struct lm83_data *lm83_update_device(struct device *dev);
124/* 124/*
125 * Driver data (common to all clients) 125 * Driver data (common to all clients)
126 */ 126 */
127 127
128static const struct i2c_device_id lm83_id[] = { 128static const struct i2c_device_id lm83_id[] = {
129 { "lm83", lm83 }, 129 { "lm83", lm83 },
130 { "lm82", lm82 }, 130 { "lm82", lm82 },
@@ -179,8 +179,13 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *devattr,
179 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 179 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
180 struct i2c_client *client = to_i2c_client(dev); 180 struct i2c_client *client = to_i2c_client(dev);
181 struct lm83_data *data = i2c_get_clientdata(client); 181 struct lm83_data *data = i2c_get_clientdata(client);
182 long val = simple_strtol(buf, NULL, 10); 182 long val;
183 int nr = attr->index; 183 int nr = attr->index;
184 int err;
185
186 err = kstrtol(buf, 10, &val);
187 if (err < 0)
188 return err;
184 189
185 mutex_lock(&data->update_lock); 190 mutex_lock(&data->update_lock);
186 data->temp[nr] = TEMP_TO_REG(val); 191 data->temp[nr] = TEMP_TO_REG(val);
@@ -355,12 +360,14 @@ static int lm83_probe(struct i2c_client *new_client,
355 * declare 1 and 3 common, and then 2 and 4 only for the LM83. 360 * declare 1 and 3 common, and then 2 and 4 only for the LM83.
356 */ 361 */
357 362
358 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm83_group))) 363 err = sysfs_create_group(&new_client->dev.kobj, &lm83_group);
364 if (err)
359 goto exit_free; 365 goto exit_free;
360 366
361 if (id->driver_data == lm83) { 367 if (id->driver_data == lm83) {
362 if ((err = sysfs_create_group(&new_client->dev.kobj, 368 err = sysfs_create_group(&new_client->dev.kobj,
363 &lm83_group_opt))) 369 &lm83_group_opt);
370 if (err)
364 goto exit_remove_files; 371 goto exit_remove_files;
365 } 372 }
366 373
@@ -423,19 +430,8 @@ static struct lm83_data *lm83_update_device(struct device *dev)
423 return data; 430 return data;
424} 431}
425 432
426static int __init sensors_lm83_init(void) 433module_i2c_driver(lm83_driver);
427{
428 return i2c_add_driver(&lm83_driver);
429}
430
431static void __exit sensors_lm83_exit(void)
432{
433 i2c_del_driver(&lm83_driver);
434}
435 434
436MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); 435MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
437MODULE_DESCRIPTION("LM83 driver"); 436MODULE_DESCRIPTION("LM83 driver");
438MODULE_LICENSE("GPL"); 437MODULE_LICENSE("GPL");
439
440module_init(sensors_lm83_init);
441module_exit(sensors_lm83_exit);
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
index da72dc12068c..864c7d999e0c 100644
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -1,28 +1,28 @@
1/* 1/*
2 lm85.c - Part of lm_sensors, Linux kernel modules for hardware 2 * lm85.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 * monitoring
4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> 4 * Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
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--2009 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 *
12 This program is free software; you can redistribute it and/or modify 12 * This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by 13 * it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or 14 * the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version. 15 * (at your option) any later version.
16 16 *
17 This program is distributed in the hope that it will be useful, 17 * This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details. 20 * GNU General Public License for more details.
21 21 *
22 You should have received a copy of the GNU General Public License 22 * You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software 23 * along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25*/ 25 */
26 26
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/init.h> 28#include <linux/init.h>
@@ -46,88 +46,89 @@ enum chips {
46 46
47/* The LM85 registers */ 47/* The LM85 registers */
48 48
49#define LM85_REG_IN(nr) (0x20 + (nr)) 49#define LM85_REG_IN(nr) (0x20 + (nr))
50#define LM85_REG_IN_MIN(nr) (0x44 + (nr) * 2) 50#define LM85_REG_IN_MIN(nr) (0x44 + (nr) * 2)
51#define LM85_REG_IN_MAX(nr) (0x45 + (nr) * 2) 51#define LM85_REG_IN_MAX(nr) (0x45 + (nr) * 2)
52 52
53#define LM85_REG_TEMP(nr) (0x25 + (nr)) 53#define LM85_REG_TEMP(nr) (0x25 + (nr))
54#define LM85_REG_TEMP_MIN(nr) (0x4e + (nr) * 2) 54#define LM85_REG_TEMP_MIN(nr) (0x4e + (nr) * 2)
55#define LM85_REG_TEMP_MAX(nr) (0x4f + (nr) * 2) 55#define LM85_REG_TEMP_MAX(nr) (0x4f + (nr) * 2)
56 56
57/* Fan speeds are LSB, MSB (2 bytes) */ 57/* Fan speeds are LSB, MSB (2 bytes) */
58#define LM85_REG_FAN(nr) (0x28 + (nr) * 2) 58#define LM85_REG_FAN(nr) (0x28 + (nr) * 2)
59#define LM85_REG_FAN_MIN(nr) (0x54 + (nr) * 2) 59#define LM85_REG_FAN_MIN(nr) (0x54 + (nr) * 2)
60 60
61#define LM85_REG_PWM(nr) (0x30 + (nr)) 61#define LM85_REG_PWM(nr) (0x30 + (nr))
62 62
63#define LM85_REG_COMPANY 0x3e 63#define LM85_REG_COMPANY 0x3e
64#define LM85_REG_VERSTEP 0x3f 64#define LM85_REG_VERSTEP 0x3f
65 65
66#define ADT7468_REG_CFG5 0x7c 66#define ADT7468_REG_CFG5 0x7c
67#define ADT7468_OFF64 (1 << 0) 67#define ADT7468_OFF64 (1 << 0)
68#define ADT7468_HFPWM (1 << 1) 68#define ADT7468_HFPWM (1 << 1)
69#define IS_ADT7468_OFF64(data) \ 69#define IS_ADT7468_OFF64(data) \
70 ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_OFF64)) 70 ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_OFF64))
71#define IS_ADT7468_HFPWM(data) \ 71#define IS_ADT7468_HFPWM(data) \
72 ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_HFPWM)) 72 ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_HFPWM))
73 73
74/* These are the recognized values for the above regs */ 74/* These are the recognized values for the above regs */
75#define LM85_COMPANY_NATIONAL 0x01 75#define LM85_COMPANY_NATIONAL 0x01
76#define LM85_COMPANY_ANALOG_DEV 0x41 76#define LM85_COMPANY_ANALOG_DEV 0x41
77#define LM85_COMPANY_SMSC 0x5c 77#define LM85_COMPANY_SMSC 0x5c
78#define LM85_VERSTEP_VMASK 0xf0 78#define LM85_VERSTEP_VMASK 0xf0
79#define LM85_VERSTEP_GENERIC 0x60 79#define LM85_VERSTEP_GENERIC 0x60
80#define LM85_VERSTEP_GENERIC2 0x70 80#define LM85_VERSTEP_GENERIC2 0x70
81#define LM85_VERSTEP_LM85C 0x60 81#define LM85_VERSTEP_LM85C 0x60
82#define LM85_VERSTEP_LM85B 0x62 82#define LM85_VERSTEP_LM85B 0x62
83#define LM85_VERSTEP_LM96000_1 0x68 83#define LM85_VERSTEP_LM96000_1 0x68
84#define LM85_VERSTEP_LM96000_2 0x69 84#define LM85_VERSTEP_LM96000_2 0x69
85#define LM85_VERSTEP_ADM1027 0x60 85#define LM85_VERSTEP_ADM1027 0x60
86#define LM85_VERSTEP_ADT7463 0x62 86#define LM85_VERSTEP_ADT7463 0x62
87#define LM85_VERSTEP_ADT7463C 0x6A 87#define LM85_VERSTEP_ADT7463C 0x6A
88#define LM85_VERSTEP_ADT7468_1 0x71 88#define LM85_VERSTEP_ADT7468_1 0x71
89#define LM85_VERSTEP_ADT7468_2 0x72 89#define LM85_VERSTEP_ADT7468_2 0x72
90#define LM85_VERSTEP_EMC6D100_A0 0x60 90#define LM85_VERSTEP_EMC6D100_A0 0x60
91#define LM85_VERSTEP_EMC6D100_A1 0x61 91#define LM85_VERSTEP_EMC6D100_A1 0x61
92#define LM85_VERSTEP_EMC6D102 0x65 92#define LM85_VERSTEP_EMC6D102 0x65
93#define LM85_VERSTEP_EMC6D103_A0 0x68 93#define LM85_VERSTEP_EMC6D103_A0 0x68
94#define LM85_VERSTEP_EMC6D103_A1 0x69 94#define LM85_VERSTEP_EMC6D103_A1 0x69
95#define LM85_VERSTEP_EMC6D103S 0x6A /* Also known as EMC6D103:A2 */ 95#define LM85_VERSTEP_EMC6D103S 0x6A /* Also known as EMC6D103:A2 */
96 96
97#define LM85_REG_CONFIG 0x40 97#define LM85_REG_CONFIG 0x40
98 98
99#define LM85_REG_ALARM1 0x41 99#define LM85_REG_ALARM1 0x41
100#define LM85_REG_ALARM2 0x42 100#define LM85_REG_ALARM2 0x42
101 101
102#define LM85_REG_VID 0x43 102#define LM85_REG_VID 0x43
103 103
104/* Automated FAN control */ 104/* Automated FAN control */
105#define LM85_REG_AFAN_CONFIG(nr) (0x5c + (nr)) 105#define LM85_REG_AFAN_CONFIG(nr) (0x5c + (nr))
106#define LM85_REG_AFAN_RANGE(nr) (0x5f + (nr)) 106#define LM85_REG_AFAN_RANGE(nr) (0x5f + (nr))
107#define LM85_REG_AFAN_SPIKE1 0x62 107#define LM85_REG_AFAN_SPIKE1 0x62
108#define LM85_REG_AFAN_MINPWM(nr) (0x64 + (nr)) 108#define LM85_REG_AFAN_MINPWM(nr) (0x64 + (nr))
109#define LM85_REG_AFAN_LIMIT(nr) (0x67 + (nr)) 109#define LM85_REG_AFAN_LIMIT(nr) (0x67 + (nr))
110#define LM85_REG_AFAN_CRITICAL(nr) (0x6a + (nr)) 110#define LM85_REG_AFAN_CRITICAL(nr) (0x6a + (nr))
111#define LM85_REG_AFAN_HYST1 0x6d 111#define LM85_REG_AFAN_HYST1 0x6d
112#define LM85_REG_AFAN_HYST2 0x6e 112#define LM85_REG_AFAN_HYST2 0x6e
113 113
114#define ADM1027_REG_EXTEND_ADC1 0x76 114#define ADM1027_REG_EXTEND_ADC1 0x76
115#define ADM1027_REG_EXTEND_ADC2 0x77 115#define ADM1027_REG_EXTEND_ADC2 0x77
116 116
117#define EMC6D100_REG_ALARM3 0x7d 117#define EMC6D100_REG_ALARM3 0x7d
118/* IN5, IN6 and IN7 */ 118/* IN5, IN6 and IN7 */
119#define EMC6D100_REG_IN(nr) (0x70 + ((nr) - 5)) 119#define EMC6D100_REG_IN(nr) (0x70 + ((nr) - 5))
120#define EMC6D100_REG_IN_MIN(nr) (0x73 + ((nr) - 5) * 2) 120#define EMC6D100_REG_IN_MIN(nr) (0x73 + ((nr) - 5) * 2)
121#define EMC6D100_REG_IN_MAX(nr) (0x74 + ((nr) - 5) * 2) 121#define EMC6D100_REG_IN_MAX(nr) (0x74 + ((nr) - 5) * 2)
122#define EMC6D102_REG_EXTEND_ADC1 0x85 122#define EMC6D102_REG_EXTEND_ADC1 0x85
123#define EMC6D102_REG_EXTEND_ADC2 0x86 123#define EMC6D102_REG_EXTEND_ADC2 0x86
124#define EMC6D102_REG_EXTEND_ADC3 0x87 124#define EMC6D102_REG_EXTEND_ADC3 0x87
125#define EMC6D102_REG_EXTEND_ADC4 0x88 125#define EMC6D102_REG_EXTEND_ADC4 0x88
126 126
127 127
128/* Conversions. Rounding and limit checking is only done on the TO_REG 128/*
129 variants. Note that you should be a bit careful with which arguments 129 * Conversions. Rounding and limit checking is only done on the TO_REG
130 these macros are called: arguments may be evaluated more than once. 130 * variants. Note that you should be a bit careful with which arguments
131 * these macros are called: arguments may be evaluated more than once.
131 */ 132 */
132 133
133/* IN are scaled according to built-in resistors */ 134/* IN are scaled according to built-in resistors */
@@ -166,7 +167,8 @@ static inline u16 FAN_TO_REG(unsigned long val)
166#define PWM_FROM_REG(val) (val) 167#define PWM_FROM_REG(val) (val)
167 168
168 169
169/* ZONEs have the following parameters: 170/*
171 * ZONEs have the following parameters:
170 * Limit (low) temp, 1. degC 172 * Limit (low) temp, 1. degC
171 * Hysteresis (below limit), 1. degC (0-15) 173 * Hysteresis (below limit), 1. degC (0-15)
172 * Range of speed control, .1 degC (2-80) 174 * Range of speed control, .1 degC (2-80)
@@ -228,7 +230,8 @@ static int FREQ_FROM_REG(const int *map, u8 reg)
228 return map[reg & 0x07]; 230 return map[reg & 0x07];
229} 231}
230 232
231/* Since we can't use strings, I'm abusing these numbers 233/*
234 * Since we can't use strings, I'm abusing these numbers
232 * to stand in for the following meanings: 235 * to stand in for the following meanings:
233 * 1 -- PWM responds to Zone 1 236 * 1 -- PWM responds to Zone 1
234 * 2 -- PWM responds to Zone 2 237 * 2 -- PWM responds to Zone 2
@@ -258,7 +261,8 @@ static int ZONE_TO_REG(int zone)
258#define HYST_TO_REG(val) SENSORS_LIMIT(((val) + 500) / 1000, 0, 15) 261#define HYST_TO_REG(val) SENSORS_LIMIT(((val) + 500) / 1000, 0, 15)
259#define HYST_FROM_REG(val) ((val) * 1000) 262#define HYST_FROM_REG(val) ((val) * 1000)
260 263
261/* Chip sampling rates 264/*
265 * Chip sampling rates
262 * 266 *
263 * Some sensors are not updated more frequently than once per second 267 * Some sensors are not updated more frequently than once per second
264 * so it doesn't make sense to read them more often than that. 268 * so it doesn't make sense to read them more often than that.
@@ -274,7 +278,8 @@ static int ZONE_TO_REG(int zone)
274#define LM85_DATA_INTERVAL (HZ + HZ / 2) 278#define LM85_DATA_INTERVAL (HZ + HZ / 2)
275#define LM85_CONFIG_INTERVAL (1 * 60 * HZ) 279#define LM85_CONFIG_INTERVAL (1 * 60 * HZ)
276 280
277/* LM85 can automatically adjust fan speeds based on temperature 281/*
282 * LM85 can automatically adjust fan speeds based on temperature
278 * This structure encapsulates an entire Zone config. There are 283 * This structure encapsulates an entire Zone config. There are
279 * three zones (one for each temperature input) on the lm85 284 * three zones (one for each temperature input) on the lm85
280 */ 285 */
@@ -283,7 +288,8 @@ struct lm85_zone {
283 u8 hyst; /* Low limit hysteresis. (0-15) */ 288 u8 hyst; /* Low limit hysteresis. (0-15) */
284 u8 range; /* Temp range, encoded */ 289 u8 range; /* Temp range, encoded */
285 s8 critical; /* "All fans ON" temp limit */ 290 s8 critical; /* "All fans ON" temp limit */
286 u8 max_desired; /* Actual "max" temperature specified. Preserved 291 u8 max_desired; /*
292 * Actual "max" temperature specified. Preserved
287 * to prevent "drift" as other autofan control 293 * to prevent "drift" as other autofan control
288 * values change. 294 * values change.
289 */ 295 */
@@ -295,8 +301,10 @@ struct lm85_autofan {
295 u8 min_off; /* Min PWM or OFF below "limit", flag */ 301 u8 min_off; /* Min PWM or OFF below "limit", flag */
296}; 302};
297 303
298/* For each registered chip, we need to keep some data in memory. 304/*
299 The structure is dynamically allocated. */ 305 * For each registered chip, we need to keep some data in memory.
306 * The structure is dynamically allocated.
307 */
300struct lm85_data { 308struct lm85_data {
301 struct device *hwmon_dev; 309 struct device *hwmon_dev;
302 const int *freq_map; 310 const int *freq_map;
@@ -391,7 +399,12 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
391 int nr = to_sensor_dev_attr(attr)->index; 399 int nr = to_sensor_dev_attr(attr)->index;
392 struct i2c_client *client = to_i2c_client(dev); 400 struct i2c_client *client = to_i2c_client(dev);
393 struct lm85_data *data = i2c_get_clientdata(client); 401 struct lm85_data *data = i2c_get_clientdata(client);
394 unsigned long val = simple_strtoul(buf, NULL, 10); 402 unsigned long val;
403 int err;
404
405 err = kstrtoul(buf, 10, &val);
406 if (err)
407 return err;
395 408
396 mutex_lock(&data->update_lock); 409 mutex_lock(&data->update_lock);
397 data->fan_min[nr] = FAN_TO_REG(val); 410 data->fan_min[nr] = FAN_TO_REG(val);
@@ -443,7 +456,14 @@ static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
443 const char *buf, size_t count) 456 const char *buf, size_t count)
444{ 457{
445 struct lm85_data *data = dev_get_drvdata(dev); 458 struct lm85_data *data = dev_get_drvdata(dev);
446 data->vrm = simple_strtoul(buf, NULL, 10); 459 unsigned long val;
460 int err;
461
462 err = kstrtoul(buf, 10, &val);
463 if (err)
464 return err;
465
466 data->vrm = val;
447 return count; 467 return count;
448} 468}
449 469
@@ -500,7 +520,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
500 int nr = to_sensor_dev_attr(attr)->index; 520 int nr = to_sensor_dev_attr(attr)->index;
501 struct i2c_client *client = to_i2c_client(dev); 521 struct i2c_client *client = to_i2c_client(dev);
502 struct lm85_data *data = i2c_get_clientdata(client); 522 struct lm85_data *data = i2c_get_clientdata(client);
503 long val = simple_strtol(buf, NULL, 10); 523 unsigned long val;
524 int err;
525
526 err = kstrtoul(buf, 10, &val);
527 if (err)
528 return err;
504 529
505 mutex_lock(&data->update_lock); 530 mutex_lock(&data->update_lock);
506 data->pwm[nr] = PWM_TO_REG(val); 531 data->pwm[nr] = PWM_TO_REG(val);
@@ -537,8 +562,13 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute
537 int nr = to_sensor_dev_attr(attr)->index; 562 int nr = to_sensor_dev_attr(attr)->index;
538 struct i2c_client *client = to_i2c_client(dev); 563 struct i2c_client *client = to_i2c_client(dev);
539 struct lm85_data *data = i2c_get_clientdata(client); 564 struct lm85_data *data = i2c_get_clientdata(client);
540 long val = simple_strtol(buf, NULL, 10);
541 u8 config; 565 u8 config;
566 unsigned long val;
567 int err;
568
569 err = kstrtoul(buf, 10, &val);
570 if (err)
571 return err;
542 572
543 switch (val) { 573 switch (val) {
544 case 0: 574 case 0:
@@ -548,8 +578,10 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute
548 config = 7; 578 config = 7;
549 break; 579 break;
550 case 2: 580 case 2:
551 /* Here we have to choose arbitrarily one of the 5 possible 581 /*
552 configurations; I go for the safest */ 582 * Here we have to choose arbitrarily one of the 5 possible
583 * configurations; I go for the safest
584 */
553 config = 6; 585 config = 6;
554 break; 586 break;
555 default: 587 default:
@@ -588,12 +620,19 @@ static ssize_t set_pwm_freq(struct device *dev,
588 int nr = to_sensor_dev_attr(attr)->index; 620 int nr = to_sensor_dev_attr(attr)->index;
589 struct i2c_client *client = to_i2c_client(dev); 621 struct i2c_client *client = to_i2c_client(dev);
590 struct lm85_data *data = i2c_get_clientdata(client); 622 struct lm85_data *data = i2c_get_clientdata(client);
591 long val = simple_strtol(buf, NULL, 10); 623 unsigned long val;
624 int err;
625
626 err = kstrtoul(buf, 10, &val);
627 if (err)
628 return err;
592 629
593 mutex_lock(&data->update_lock); 630 mutex_lock(&data->update_lock);
594 /* The ADT7468 has a special high-frequency PWM output mode, 631 /*
632 * The ADT7468 has a special high-frequency PWM output mode,
595 * where all PWM outputs are driven by a 22.5 kHz clock. 633 * where all PWM outputs are driven by a 22.5 kHz clock.
596 * This might confuse the user, but there's not much we can do. */ 634 * This might confuse the user, but there's not much we can do.
635 */
597 if (data->type == adt7468 && val >= 11300) { /* High freq. mode */ 636 if (data->type == adt7468 && val >= 11300) { /* High freq. mode */
598 data->cfg5 &= ~ADT7468_HFPWM; 637 data->cfg5 &= ~ADT7468_HFPWM;
599 lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5); 638 lm85_write_value(client, ADT7468_REG_CFG5, data->cfg5);
@@ -648,7 +687,12 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
648 int nr = to_sensor_dev_attr(attr)->index; 687 int nr = to_sensor_dev_attr(attr)->index;
649 struct i2c_client *client = to_i2c_client(dev); 688 struct i2c_client *client = to_i2c_client(dev);
650 struct lm85_data *data = i2c_get_clientdata(client); 689 struct lm85_data *data = i2c_get_clientdata(client);
651 long val = simple_strtol(buf, NULL, 10); 690 long val;
691 int err;
692
693 err = kstrtol(buf, 10, &val);
694 if (err)
695 return err;
652 696
653 mutex_lock(&data->update_lock); 697 mutex_lock(&data->update_lock);
654 data->in_min[nr] = INS_TO_REG(nr, val); 698 data->in_min[nr] = INS_TO_REG(nr, val);
@@ -671,7 +715,12 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
671 int nr = to_sensor_dev_attr(attr)->index; 715 int nr = to_sensor_dev_attr(attr)->index;
672 struct i2c_client *client = to_i2c_client(dev); 716 struct i2c_client *client = to_i2c_client(dev);
673 struct lm85_data *data = i2c_get_clientdata(client); 717 struct lm85_data *data = i2c_get_clientdata(client);
674 long val = simple_strtol(buf, NULL, 10); 718 long val;
719 int err;
720
721 err = kstrtol(buf, 10, &val);
722 if (err)
723 return err;
675 724
676 mutex_lock(&data->update_lock); 725 mutex_lock(&data->update_lock);
677 data->in_max[nr] = INS_TO_REG(nr, val); 726 data->in_max[nr] = INS_TO_REG(nr, val);
@@ -722,7 +771,12 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
722 int nr = to_sensor_dev_attr(attr)->index; 771 int nr = to_sensor_dev_attr(attr)->index;
723 struct i2c_client *client = to_i2c_client(dev); 772 struct i2c_client *client = to_i2c_client(dev);
724 struct lm85_data *data = i2c_get_clientdata(client); 773 struct lm85_data *data = i2c_get_clientdata(client);
725 long val = simple_strtol(buf, NULL, 10); 774 long val;
775 int err;
776
777 err = kstrtol(buf, 10, &val);
778 if (err)
779 return err;
726 780
727 if (IS_ADT7468_OFF64(data)) 781 if (IS_ADT7468_OFF64(data))
728 val += 64; 782 val += 64;
@@ -748,7 +802,12 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
748 int nr = to_sensor_dev_attr(attr)->index; 802 int nr = to_sensor_dev_attr(attr)->index;
749 struct i2c_client *client = to_i2c_client(dev); 803 struct i2c_client *client = to_i2c_client(dev);
750 struct lm85_data *data = i2c_get_clientdata(client); 804 struct lm85_data *data = i2c_get_clientdata(client);
751 long val = simple_strtol(buf, NULL, 10); 805 long val;
806 int err;
807
808 err = kstrtol(buf, 10, &val);
809 if (err)
810 return err;
752 811
753 if (IS_ADT7468_OFF64(data)) 812 if (IS_ADT7468_OFF64(data))
754 val += 64; 813 val += 64;
@@ -789,7 +848,12 @@ static ssize_t set_pwm_auto_channels(struct device *dev,
789 int nr = to_sensor_dev_attr(attr)->index; 848 int nr = to_sensor_dev_attr(attr)->index;
790 struct i2c_client *client = to_i2c_client(dev); 849 struct i2c_client *client = to_i2c_client(dev);
791 struct lm85_data *data = i2c_get_clientdata(client); 850 struct lm85_data *data = i2c_get_clientdata(client);
792 long val = simple_strtol(buf, NULL, 10); 851 long val;
852 int err;
853
854 err = kstrtol(buf, 10, &val);
855 if (err)
856 return err;
793 857
794 mutex_lock(&data->update_lock); 858 mutex_lock(&data->update_lock);
795 data->autofan[nr].config = (data->autofan[nr].config & (~0xe0)) 859 data->autofan[nr].config = (data->autofan[nr].config & (~0xe0))
@@ -814,7 +878,12 @@ static ssize_t set_pwm_auto_pwm_min(struct device *dev,
814 int nr = to_sensor_dev_attr(attr)->index; 878 int nr = to_sensor_dev_attr(attr)->index;
815 struct i2c_client *client = to_i2c_client(dev); 879 struct i2c_client *client = to_i2c_client(dev);
816 struct lm85_data *data = i2c_get_clientdata(client); 880 struct lm85_data *data = i2c_get_clientdata(client);
817 long val = simple_strtol(buf, NULL, 10); 881 unsigned long val;
882 int err;
883
884 err = kstrtoul(buf, 10, &val);
885 if (err)
886 return err;
818 887
819 mutex_lock(&data->update_lock); 888 mutex_lock(&data->update_lock);
820 data->autofan[nr].min_pwm = PWM_TO_REG(val); 889 data->autofan[nr].min_pwm = PWM_TO_REG(val);
@@ -838,8 +907,13 @@ static ssize_t set_pwm_auto_pwm_minctl(struct device *dev,
838 int nr = to_sensor_dev_attr(attr)->index; 907 int nr = to_sensor_dev_attr(attr)->index;
839 struct i2c_client *client = to_i2c_client(dev); 908 struct i2c_client *client = to_i2c_client(dev);
840 struct lm85_data *data = i2c_get_clientdata(client); 909 struct lm85_data *data = i2c_get_clientdata(client);
841 long val = simple_strtol(buf, NULL, 10);
842 u8 tmp; 910 u8 tmp;
911 long val;
912 int err;
913
914 err = kstrtol(buf, 10, &val);
915 if (err)
916 return err;
843 917
844 mutex_lock(&data->update_lock); 918 mutex_lock(&data->update_lock);
845 data->autofan[nr].min_off = val; 919 data->autofan[nr].min_off = val;
@@ -885,7 +959,12 @@ static ssize_t set_temp_auto_temp_off(struct device *dev,
885 struct i2c_client *client = to_i2c_client(dev); 959 struct i2c_client *client = to_i2c_client(dev);
886 struct lm85_data *data = i2c_get_clientdata(client); 960 struct lm85_data *data = i2c_get_clientdata(client);
887 int min; 961 int min;
888 long val = simple_strtol(buf, NULL, 10); 962 long val;
963 int err;
964
965 err = kstrtol(buf, 10, &val);
966 if (err)
967 return err;
889 968
890 mutex_lock(&data->update_lock); 969 mutex_lock(&data->update_lock);
891 min = TEMP_FROM_REG(data->zone[nr].limit); 970 min = TEMP_FROM_REG(data->zone[nr].limit);
@@ -916,7 +995,12 @@ static ssize_t set_temp_auto_temp_min(struct device *dev,
916 int nr = to_sensor_dev_attr(attr)->index; 995 int nr = to_sensor_dev_attr(attr)->index;
917 struct i2c_client *client = to_i2c_client(dev); 996 struct i2c_client *client = to_i2c_client(dev);
918 struct lm85_data *data = i2c_get_clientdata(client); 997 struct lm85_data *data = i2c_get_clientdata(client);
919 long val = simple_strtol(buf, NULL, 10); 998 long val;
999 int err;
1000
1001 err = kstrtol(buf, 10, &val);
1002 if (err)
1003 return err;
920 1004
921 mutex_lock(&data->update_lock); 1005 mutex_lock(&data->update_lock);
922 data->zone[nr].limit = TEMP_TO_REG(val); 1006 data->zone[nr].limit = TEMP_TO_REG(val);
@@ -951,7 +1035,12 @@ static ssize_t set_temp_auto_temp_max(struct device *dev,
951 struct i2c_client *client = to_i2c_client(dev); 1035 struct i2c_client *client = to_i2c_client(dev);
952 struct lm85_data *data = i2c_get_clientdata(client); 1036 struct lm85_data *data = i2c_get_clientdata(client);
953 int min; 1037 int min;
954 long val = simple_strtol(buf, NULL, 10); 1038 long val;
1039 int err;
1040
1041 err = kstrtol(buf, 10, &val);
1042 if (err)
1043 return err;
955 1044
956 mutex_lock(&data->update_lock); 1045 mutex_lock(&data->update_lock);
957 min = TEMP_FROM_REG(data->zone[nr].limit); 1046 min = TEMP_FROM_REG(data->zone[nr].limit);
@@ -979,7 +1068,12 @@ static ssize_t set_temp_auto_temp_crit(struct device *dev,
979 int nr = to_sensor_dev_attr(attr)->index; 1068 int nr = to_sensor_dev_attr(attr)->index;
980 struct i2c_client *client = to_i2c_client(dev); 1069 struct i2c_client *client = to_i2c_client(dev);
981 struct lm85_data *data = i2c_get_clientdata(client); 1070 struct lm85_data *data = i2c_get_clientdata(client);
982 long val = simple_strtol(buf, NULL, 10); 1071 long val;
1072 int err;
1073
1074 err = kstrtol(buf, 10, &val);
1075 if (err)
1076 return err;
983 1077
984 mutex_lock(&data->update_lock); 1078 mutex_lock(&data->update_lock);
985 data->zone[nr].critical = TEMP_TO_REG(val); 1079 data->zone[nr].critical = TEMP_TO_REG(val);
@@ -1338,24 +1432,28 @@ static int lm85_probe(struct i2c_client *client,
1338 goto err_remove_files; 1432 goto err_remove_files;
1339 } 1433 }
1340 1434
1341 /* The ADT7463/68 have an optional VRM 10 mode where pin 21 is used 1435 /*
1342 as a sixth digital VID input rather than an analog input. */ 1436 * The ADT7463/68 have an optional VRM 10 mode where pin 21 is used
1437 * as a sixth digital VID input rather than an analog input.
1438 */
1343 if (data->type == adt7463 || data->type == adt7468) { 1439 if (data->type == adt7463 || data->type == adt7468) {
1344 u8 vid = lm85_read_value(client, LM85_REG_VID); 1440 u8 vid = lm85_read_value(client, LM85_REG_VID);
1345 if (vid & 0x80) 1441 if (vid & 0x80)
1346 data->has_vid5 = true; 1442 data->has_vid5 = true;
1347 } 1443 }
1348 1444
1349 if (!data->has_vid5) 1445 if (!data->has_vid5) {
1350 if ((err = sysfs_create_group(&client->dev.kobj, 1446 err = sysfs_create_group(&client->dev.kobj, &lm85_group_in4);
1351 &lm85_group_in4))) 1447 if (err)
1352 goto err_remove_files; 1448 goto err_remove_files;
1449 }
1353 1450
1354 /* The EMC6D100 has 3 additional voltage inputs */ 1451 /* The EMC6D100 has 3 additional voltage inputs */
1355 if (data->type == emc6d100) 1452 if (data->type == emc6d100) {
1356 if ((err = sysfs_create_group(&client->dev.kobj, 1453 err = sysfs_create_group(&client->dev.kobj, &lm85_group_in567);
1357 &lm85_group_in567))) 1454 if (err)
1358 goto err_remove_files; 1455 goto err_remove_files;
1456 }
1359 1457
1360 data->hwmon_dev = hwmon_device_register(&client->dev); 1458 data->hwmon_dev = hwmon_device_register(&client->dev);
1361 if (IS_ERR(data->hwmon_dev)) { 1459 if (IS_ERR(data->hwmon_dev)) {
@@ -1443,7 +1541,8 @@ static struct lm85_data *lm85_update_device(struct device *dev)
1443 /* Things that change quickly */ 1541 /* Things that change quickly */
1444 dev_dbg(&client->dev, "Reading sensor values\n"); 1542 dev_dbg(&client->dev, "Reading sensor values\n");
1445 1543
1446 /* Have to read extended bits first to "freeze" the 1544 /*
1545 * Have to read extended bits first to "freeze" the
1447 * more significant bits that are read later. 1546 * more significant bits that are read later.
1448 * There are 2 additional resolution bits per channel and we 1547 * There are 2 additional resolution bits per channel and we
1449 * have room for 4, so we shift them to the left. 1548 * have room for 4, so we shift them to the left.
@@ -1503,9 +1602,10 @@ static struct lm85_data *lm85_update_device(struct device *dev)
1503 EMC6D100_REG_ALARM3) << 16; 1602 EMC6D100_REG_ALARM3) << 16;
1504 } else if (data->type == emc6d102 || data->type == emc6d103 || 1603 } else if (data->type == emc6d102 || data->type == emc6d103 ||
1505 data->type == emc6d103s) { 1604 data->type == emc6d103s) {
1506 /* Have to read LSB bits after the MSB ones because 1605 /*
1507 the reading of the MSB bits has frozen the 1606 * Have to read LSB bits after the MSB ones because
1508 LSBs (backward from the ADM1027). 1607 * the reading of the MSB bits has frozen the
1608 * LSBs (backward from the ADM1027).
1509 */ 1609 */
1510 int ext1 = lm85_read_value(client, 1610 int ext1 = lm85_read_value(client,
1511 EMC6D102_REG_EXTEND_ADC1); 1611 EMC6D102_REG_EXTEND_ADC1);
@@ -1611,22 +1711,10 @@ static struct lm85_data *lm85_update_device(struct device *dev)
1611 return data; 1711 return data;
1612} 1712}
1613 1713
1614 1714module_i2c_driver(lm85_driver);
1615static int __init sm_lm85_init(void)
1616{
1617 return i2c_add_driver(&lm85_driver);
1618}
1619
1620static void __exit sm_lm85_exit(void)
1621{
1622 i2c_del_driver(&lm85_driver);
1623}
1624 1715
1625MODULE_LICENSE("GPL"); 1716MODULE_LICENSE("GPL");
1626MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, " 1717MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
1627 "Margit Schubert-While <margitsw@t-online.de>, " 1718 "Margit Schubert-While <margitsw@t-online.de>, "
1628 "Justin Thiessen <jthiessen@penguincomputing.com>"); 1719 "Justin Thiessen <jthiessen@penguincomputing.com>");
1629MODULE_DESCRIPTION("LM85-B, LM85-C driver"); 1720MODULE_DESCRIPTION("LM85-B, LM85-C driver");
1630
1631module_init(sm_lm85_init);
1632module_exit(sm_lm85_exit);
diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c
index f1e6e7512ffa..314d147bf1ac 100644
--- a/drivers/hwmon/lm87.c
+++ b/drivers/hwmon/lm87.c
@@ -119,20 +119,21 @@ static u8 LM87_REG_TEMP_LOW[3] = { 0x3A, 0x38, 0x2C };
119 * The LM87 uses signed 8-bit values for temperatures. 119 * The LM87 uses signed 8-bit values for temperatures.
120 */ 120 */
121 121
122#define IN_FROM_REG(reg,scale) (((reg) * (scale) + 96) / 192) 122#define IN_FROM_REG(reg, scale) (((reg) * (scale) + 96) / 192)
123#define IN_TO_REG(val,scale) ((val) <= 0 ? 0 : \ 123#define IN_TO_REG(val, scale) ((val) <= 0 ? 0 : \
124 (val) * 192 >= (scale) * 255 ? 255 : \ 124 (val) * 192 >= (scale) * 255 ? 255 : \
125 ((val) * 192 + (scale)/2) / (scale)) 125 ((val) * 192 + (scale) / 2) / (scale))
126 126
127#define TEMP_FROM_REG(reg) ((reg) * 1000) 127#define TEMP_FROM_REG(reg) ((reg) * 1000)
128#define TEMP_TO_REG(val) ((val) <= -127500 ? -128 : \ 128#define TEMP_TO_REG(val) ((val) <= -127500 ? -128 : \
129 (val) >= 126500 ? 127 : \ 129 (val) >= 126500 ? 127 : \
130 (((val) < 0 ? (val)-500 : (val)+500) / 1000)) 130 (((val) < 0 ? (val) - 500 : \
131 (val) + 500) / 1000))
131 132
132#define FAN_FROM_REG(reg,div) ((reg) == 255 || (reg) == 0 ? 0 : \ 133#define FAN_FROM_REG(reg, div) ((reg) == 255 || (reg) == 0 ? 0 : \
133 (1350000 + (reg)*(div) / 2) / ((reg)*(div))) 134 (1350000 + (reg)*(div) / 2) / ((reg) * (div)))
134#define FAN_TO_REG(val,div) ((val)*(div) * 255 <= 1350000 ? 255 : \ 135#define FAN_TO_REG(val, div) ((val) * (div) * 255 <= 1350000 ? 255 : \
135 (1350000 + (val)*(div) / 2) / ((val)*(div))) 136 (1350000 + (val)*(div) / 2) / ((val) * (div)))
136 137
137#define FAN_DIV_FROM_REG(reg) (1 << (reg)) 138#define FAN_DIV_FROM_REG(reg) (1 << (reg))
138 139
@@ -149,41 +150,6 @@ static u8 LM87_REG_TEMP_LOW[3] = { 0x3A, 0x38, 0x2C };
149#define CHAN_NO_VID (1 << 7) 150#define CHAN_NO_VID (1 << 7)
150 151
151/* 152/*
152 * Functions declaration
153 */
154
155static int lm87_probe(struct i2c_client *client,
156 const struct i2c_device_id *id);
157static int lm87_detect(struct i2c_client *new_client,
158 struct i2c_board_info *info);
159static void lm87_init_client(struct i2c_client *client);
160static int lm87_remove(struct i2c_client *client);
161static struct lm87_data *lm87_update_device(struct device *dev);
162
163/*
164 * Driver data (common to all clients)
165 */
166
167static const struct i2c_device_id lm87_id[] = {
168 { "lm87", lm87 },
169 { "adm1024", adm1024 },
170 { }
171};
172MODULE_DEVICE_TABLE(i2c, lm87_id);
173
174static struct i2c_driver lm87_driver = {
175 .class = I2C_CLASS_HWMON,
176 .driver = {
177 .name = "lm87",
178 },
179 .probe = lm87_probe,
180 .remove = lm87_remove,
181 .id_table = lm87_id,
182 .detect = lm87_detect,
183 .address_list = normal_i2c,
184};
185
186/*
187 * Client data (each client gets its own) 153 * Client data (each client gets its own)
188 */ 154 */
189 155
@@ -217,10 +183,6 @@ struct lm87_data {
217 u8 vrm; 183 u8 vrm;
218}; 184};
219 185
220/*
221 * Sysfs stuff
222 */
223
224static inline int lm87_read_value(struct i2c_client *client, u8 reg) 186static inline int lm87_read_value(struct i2c_client *client, u8 reg)
225{ 187{
226 return i2c_smbus_read_byte_data(client, reg); 188 return i2c_smbus_read_byte_data(client, reg);
@@ -231,79 +193,168 @@ static inline int lm87_write_value(struct i2c_client *client, u8 reg, u8 value)
231 return i2c_smbus_write_byte_data(client, reg, value); 193 return i2c_smbus_write_byte_data(client, reg, value);
232} 194}
233 195
234#define show_in(offset) \ 196static struct lm87_data *lm87_update_device(struct device *dev)
235static ssize_t show_in##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \
236{ \
237 struct lm87_data *data = lm87_update_device(dev); \
238 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset], \
239 data->in_scale[offset])); \
240} \
241static ssize_t show_in##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \
242{ \
243 struct lm87_data *data = lm87_update_device(dev); \
244 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset], \
245 data->in_scale[offset])); \
246} \
247static ssize_t show_in##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \
248{ \
249 struct lm87_data *data = lm87_update_device(dev); \
250 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset], \
251 data->in_scale[offset])); \
252} \
253static DEVICE_ATTR(in##offset##_input, S_IRUGO, \
254 show_in##offset##_input, NULL);
255show_in(0);
256show_in(1);
257show_in(2);
258show_in(3);
259show_in(4);
260show_in(5);
261show_in(6);
262show_in(7);
263
264static void set_in_min(struct device *dev, const char *buf, int nr)
265{ 197{
266 struct i2c_client *client = to_i2c_client(dev); 198 struct i2c_client *client = to_i2c_client(dev);
267 struct lm87_data *data = i2c_get_clientdata(client); 199 struct lm87_data *data = i2c_get_clientdata(client);
268 long val = simple_strtol(buf, NULL, 10); 200
201 mutex_lock(&data->update_lock);
202
203 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
204 int i, j;
205
206 dev_dbg(&client->dev, "Updating data.\n");
207
208 i = (data->channel & CHAN_TEMP3) ? 1 : 0;
209 j = (data->channel & CHAN_TEMP3) ? 5 : 6;
210 for (; i < j; i++) {
211 data->in[i] = lm87_read_value(client,
212 LM87_REG_IN(i));
213 data->in_min[i] = lm87_read_value(client,
214 LM87_REG_IN_MIN(i));
215 data->in_max[i] = lm87_read_value(client,
216 LM87_REG_IN_MAX(i));
217 }
218
219 for (i = 0; i < 2; i++) {
220 if (data->channel & CHAN_NO_FAN(i)) {
221 data->in[6+i] = lm87_read_value(client,
222 LM87_REG_AIN(i));
223 data->in_max[6+i] = lm87_read_value(client,
224 LM87_REG_AIN_MAX(i));
225 data->in_min[6+i] = lm87_read_value(client,
226 LM87_REG_AIN_MIN(i));
227
228 } else {
229 data->fan[i] = lm87_read_value(client,
230 LM87_REG_FAN(i));
231 data->fan_min[i] = lm87_read_value(client,
232 LM87_REG_FAN_MIN(i));
233 }
234 }
235
236 j = (data->channel & CHAN_TEMP3) ? 3 : 2;
237 for (i = 0 ; i < j; i++) {
238 data->temp[i] = lm87_read_value(client,
239 LM87_REG_TEMP[i]);
240 data->temp_high[i] = lm87_read_value(client,
241 LM87_REG_TEMP_HIGH[i]);
242 data->temp_low[i] = lm87_read_value(client,
243 LM87_REG_TEMP_LOW[i]);
244 }
245
246 i = lm87_read_value(client, LM87_REG_TEMP_HW_INT_LOCK);
247 j = lm87_read_value(client, LM87_REG_TEMP_HW_INT);
248 data->temp_crit_int = min(i, j);
249
250 i = lm87_read_value(client, LM87_REG_TEMP_HW_EXT_LOCK);
251 j = lm87_read_value(client, LM87_REG_TEMP_HW_EXT);
252 data->temp_crit_ext = min(i, j);
253
254 i = lm87_read_value(client, LM87_REG_VID_FAN_DIV);
255 data->fan_div[0] = (i >> 4) & 0x03;
256 data->fan_div[1] = (i >> 6) & 0x03;
257 data->vid = (i & 0x0F)
258 | (lm87_read_value(client, LM87_REG_VID4) & 0x01)
259 << 4;
260
261 data->alarms = lm87_read_value(client, LM87_REG_ALARMS1)
262 | (lm87_read_value(client, LM87_REG_ALARMS2)
263 << 8);
264 data->aout = lm87_read_value(client, LM87_REG_AOUT);
265
266 data->last_updated = jiffies;
267 data->valid = 1;
268 }
269
270 mutex_unlock(&data->update_lock);
271
272 return data;
273}
274
275/*
276 * Sysfs stuff
277 */
278
279static ssize_t show_in_input(struct device *dev, struct device_attribute *attr,
280 char *buf)
281{
282 struct lm87_data *data = lm87_update_device(dev);
283 int nr = to_sensor_dev_attr(attr)->index;
284
285 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[nr],
286 data->in_scale[nr]));
287}
288
289static ssize_t show_in_min(struct device *dev,
290 struct device_attribute *attr, char *buf)
291{
292 struct lm87_data *data = lm87_update_device(dev);
293 int nr = to_sensor_dev_attr(attr)->index;
294
295 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[nr],
296 data->in_scale[nr]));
297}
298
299static ssize_t show_in_max(struct device *dev,
300 struct device_attribute *attr, char *buf)
301{
302 struct lm87_data *data = lm87_update_device(dev);
303 int nr = to_sensor_dev_attr(attr)->index;
304
305 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[nr],
306 data->in_scale[nr]));
307}
308
309static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
310 const char *buf, size_t count)
311{
312 struct i2c_client *client = to_i2c_client(dev);
313 struct lm87_data *data = i2c_get_clientdata(client);
314 int nr = to_sensor_dev_attr(attr)->index;
315 long val;
316 int err;
317
318 err = kstrtol(buf, 10, &val);
319 if (err)
320 return err;
269 321
270 mutex_lock(&data->update_lock); 322 mutex_lock(&data->update_lock);
271 data->in_min[nr] = IN_TO_REG(val, data->in_scale[nr]); 323 data->in_min[nr] = IN_TO_REG(val, data->in_scale[nr]);
272 lm87_write_value(client, nr<6 ? LM87_REG_IN_MIN(nr) : 324 lm87_write_value(client, nr < 6 ? LM87_REG_IN_MIN(nr) :
273 LM87_REG_AIN_MIN(nr-6), data->in_min[nr]); 325 LM87_REG_AIN_MIN(nr - 6), data->in_min[nr]);
274 mutex_unlock(&data->update_lock); 326 mutex_unlock(&data->update_lock);
327 return count;
275} 328}
276 329
277static void set_in_max(struct device *dev, const char *buf, int nr) 330static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
331 const char *buf, size_t count)
278{ 332{
279 struct i2c_client *client = to_i2c_client(dev); 333 struct i2c_client *client = to_i2c_client(dev);
280 struct lm87_data *data = i2c_get_clientdata(client); 334 struct lm87_data *data = i2c_get_clientdata(client);
281 long val = simple_strtol(buf, NULL, 10); 335 int nr = to_sensor_dev_attr(attr)->index;
336 long val;
337 int err;
338
339 err = kstrtol(buf, 10, &val);
340 if (err)
341 return err;
282 342
283 mutex_lock(&data->update_lock); 343 mutex_lock(&data->update_lock);
284 data->in_max[nr] = IN_TO_REG(val, data->in_scale[nr]); 344 data->in_max[nr] = IN_TO_REG(val, data->in_scale[nr]);
285 lm87_write_value(client, nr<6 ? LM87_REG_IN_MAX(nr) : 345 lm87_write_value(client, nr < 6 ? LM87_REG_IN_MAX(nr) :
286 LM87_REG_AIN_MAX(nr-6), data->in_max[nr]); 346 LM87_REG_AIN_MAX(nr - 6), data->in_max[nr]);
287 mutex_unlock(&data->update_lock); 347 mutex_unlock(&data->update_lock);
348 return count;
288} 349}
289 350
290#define set_in(offset) \ 351#define set_in(offset) \
291static ssize_t set_in##offset##_min(struct device *dev, struct device_attribute *attr, \ 352static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
292 const char *buf, size_t count) \ 353 show_in_input, NULL, offset); \
293{ \ 354static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
294 set_in_min(dev, buf, offset); \ 355 show_in_min, set_in_min, offset); \
295 return count; \ 356static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
296} \ 357 show_in_max, set_in_max, offset)
297static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute *attr, \
298 const char *buf, size_t count) \
299{ \
300 set_in_max(dev, buf, offset); \
301 return count; \
302} \
303static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
304 show_in##offset##_min, set_in##offset##_min); \
305static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
306 show_in##offset##_max, set_in##offset##_max);
307set_in(0); 358set_in(0);
308set_in(1); 359set_in(1);
309set_in(2); 360set_in(2);
@@ -313,80 +364,95 @@ set_in(5);
313set_in(6); 364set_in(6);
314set_in(7); 365set_in(7);
315 366
316#define show_temp(offset) \ 367static ssize_t show_temp_input(struct device *dev,
317static ssize_t show_temp##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \ 368 struct device_attribute *attr, char *buf)
318{ \ 369{
319 struct lm87_data *data = lm87_update_device(dev); \ 370 struct lm87_data *data = lm87_update_device(dev);
320 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[offset-1])); \ 371 int nr = to_sensor_dev_attr(attr)->index;
321} \ 372
322static ssize_t show_temp##offset##_low(struct device *dev, struct device_attribute *attr, char *buf) \ 373 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr]));
323{ \ 374}
324 struct lm87_data *data = lm87_update_device(dev); \ 375
325 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[offset-1])); \ 376static ssize_t show_temp_low(struct device *dev,
326} \ 377 struct device_attribute *attr, char *buf)
327static ssize_t show_temp##offset##_high(struct device *dev, struct device_attribute *attr, char *buf) \ 378{
328{ \ 379 struct lm87_data *data = lm87_update_device(dev);
329 struct lm87_data *data = lm87_update_device(dev); \ 380 int nr = to_sensor_dev_attr(attr)->index;
330 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[offset-1])); \ 381
331}\ 382 return sprintf(buf, "%d\n",
332static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ 383 TEMP_FROM_REG(data->temp_low[nr]));
333 show_temp##offset##_input, NULL); 384}
334show_temp(1); 385
335show_temp(2); 386static ssize_t show_temp_high(struct device *dev,
336show_temp(3); 387 struct device_attribute *attr, char *buf)
337 388{
338static void set_temp_low(struct device *dev, const char *buf, int nr) 389 struct lm87_data *data = lm87_update_device(dev);
390 int nr = to_sensor_dev_attr(attr)->index;
391
392 return sprintf(buf, "%d\n",
393 TEMP_FROM_REG(data->temp_high[nr]));
394}
395
396static ssize_t set_temp_low(struct device *dev, struct device_attribute *attr,
397 const char *buf, size_t count)
339{ 398{
340 struct i2c_client *client = to_i2c_client(dev); 399 struct i2c_client *client = to_i2c_client(dev);
341 struct lm87_data *data = i2c_get_clientdata(client); 400 struct lm87_data *data = i2c_get_clientdata(client);
342 long val = simple_strtol(buf, NULL, 10); 401 int nr = to_sensor_dev_attr(attr)->index;
402 long val;
403 int err;
404
405 err = kstrtol(buf, 10, &val);
406 if (err)
407 return err;
343 408
344 mutex_lock(&data->update_lock); 409 mutex_lock(&data->update_lock);
345 data->temp_low[nr] = TEMP_TO_REG(val); 410 data->temp_low[nr] = TEMP_TO_REG(val);
346 lm87_write_value(client, LM87_REG_TEMP_LOW[nr], data->temp_low[nr]); 411 lm87_write_value(client, LM87_REG_TEMP_LOW[nr], data->temp_low[nr]);
347 mutex_unlock(&data->update_lock); 412 mutex_unlock(&data->update_lock);
413 return count;
348} 414}
349 415
350static void set_temp_high(struct device *dev, const char *buf, int nr) 416static ssize_t set_temp_high(struct device *dev, struct device_attribute *attr,
417 const char *buf, size_t count)
351{ 418{
352 struct i2c_client *client = to_i2c_client(dev); 419 struct i2c_client *client = to_i2c_client(dev);
353 struct lm87_data *data = i2c_get_clientdata(client); 420 struct lm87_data *data = i2c_get_clientdata(client);
354 long val = simple_strtol(buf, NULL, 10); 421 int nr = to_sensor_dev_attr(attr)->index;
422 long val;
423 int err;
424
425 err = kstrtol(buf, 10, &val);
426 if (err)
427 return err;
355 428
356 mutex_lock(&data->update_lock); 429 mutex_lock(&data->update_lock);
357 data->temp_high[nr] = TEMP_TO_REG(val); 430 data->temp_high[nr] = TEMP_TO_REG(val);
358 lm87_write_value(client, LM87_REG_TEMP_HIGH[nr], data->temp_high[nr]); 431 lm87_write_value(client, LM87_REG_TEMP_HIGH[nr], data->temp_high[nr]);
359 mutex_unlock(&data->update_lock); 432 mutex_unlock(&data->update_lock);
433 return count;
360} 434}
361 435
362#define set_temp(offset) \ 436#define set_temp(offset) \
363static ssize_t set_temp##offset##_low(struct device *dev, struct device_attribute *attr, \ 437static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
364 const char *buf, size_t count) \ 438 show_temp_input, NULL, offset - 1); \
365{ \ 439static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
366 set_temp_low(dev, buf, offset-1); \ 440 show_temp_high, set_temp_high, offset - 1); \
367 return count; \ 441static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
368} \ 442 show_temp_low, set_temp_low, offset - 1)
369static ssize_t set_temp##offset##_high(struct device *dev, struct device_attribute *attr, \
370 const char *buf, size_t count) \
371{ \
372 set_temp_high(dev, buf, offset-1); \
373 return count; \
374} \
375static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
376 show_temp##offset##_high, set_temp##offset##_high); \
377static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
378 show_temp##offset##_low, set_temp##offset##_low);
379set_temp(1); 443set_temp(1);
380set_temp(2); 444set_temp(2);
381set_temp(3); 445set_temp(3);
382 446
383static ssize_t show_temp_crit_int(struct device *dev, struct device_attribute *attr, char *buf) 447static ssize_t show_temp_crit_int(struct device *dev,
448 struct device_attribute *attr, char *buf)
384{ 449{
385 struct lm87_data *data = lm87_update_device(dev); 450 struct lm87_data *data = lm87_update_device(dev);
386 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit_int)); 451 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit_int));
387} 452}
388 453
389static ssize_t show_temp_crit_ext(struct device *dev, struct device_attribute *attr, char *buf) 454static ssize_t show_temp_crit_ext(struct device *dev,
455 struct device_attribute *attr, char *buf)
390{ 456{
391 struct lm87_data *data = lm87_update_device(dev); 457 struct lm87_data *data = lm87_update_device(dev);
392 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit_ext)); 458 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit_ext));
@@ -396,64 +462,95 @@ static DEVICE_ATTR(temp1_crit, S_IRUGO, show_temp_crit_int, NULL);
396static DEVICE_ATTR(temp2_crit, S_IRUGO, show_temp_crit_ext, NULL); 462static DEVICE_ATTR(temp2_crit, S_IRUGO, show_temp_crit_ext, NULL);
397static DEVICE_ATTR(temp3_crit, S_IRUGO, show_temp_crit_ext, NULL); 463static DEVICE_ATTR(temp3_crit, S_IRUGO, show_temp_crit_ext, NULL);
398 464
399#define show_fan(offset) \ 465static ssize_t show_fan_input(struct device *dev,
400static ssize_t show_fan##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \ 466 struct device_attribute *attr, char *buf)
401{ \ 467{
402 struct lm87_data *data = lm87_update_device(dev); \ 468 struct lm87_data *data = lm87_update_device(dev);
403 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[offset-1], \ 469 int nr = to_sensor_dev_attr(attr)->index;
404 FAN_DIV_FROM_REG(data->fan_div[offset-1]))); \ 470
405} \ 471 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
406static ssize_t show_fan##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ 472 FAN_DIV_FROM_REG(data->fan_div[nr])));
407{ \ 473}
408 struct lm87_data *data = lm87_update_device(dev); \ 474
409 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[offset-1], \ 475static ssize_t show_fan_min(struct device *dev,
410 FAN_DIV_FROM_REG(data->fan_div[offset-1]))); \ 476 struct device_attribute *attr, char *buf)
411} \ 477{
412static ssize_t show_fan##offset##_div(struct device *dev, struct device_attribute *attr, char *buf) \ 478 struct lm87_data *data = lm87_update_device(dev);
413{ \ 479 int nr = to_sensor_dev_attr(attr)->index;
414 struct lm87_data *data = lm87_update_device(dev); \ 480
415 return sprintf(buf, "%d\n", FAN_DIV_FROM_REG(data->fan_div[offset-1])); \ 481 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
416} \ 482 FAN_DIV_FROM_REG(data->fan_div[nr])));
417static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ 483}
418 show_fan##offset##_input, NULL); 484
419show_fan(1); 485static ssize_t show_fan_div(struct device *dev,
420show_fan(2); 486 struct device_attribute *attr, char *buf)
421 487{
422static void set_fan_min(struct device *dev, const char *buf, int nr) 488 struct lm87_data *data = lm87_update_device(dev);
489 int nr = to_sensor_dev_attr(attr)->index;
490
491 return sprintf(buf, "%d\n",
492 FAN_DIV_FROM_REG(data->fan_div[nr]));
493}
494
495static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
496 const char *buf, size_t count)
423{ 497{
424 struct i2c_client *client = to_i2c_client(dev); 498 struct i2c_client *client = to_i2c_client(dev);
425 struct lm87_data *data = i2c_get_clientdata(client); 499 struct lm87_data *data = i2c_get_clientdata(client);
426 long val = simple_strtol(buf, NULL, 10); 500 int nr = to_sensor_dev_attr(attr)->index;
501 long val;
502 int err;
503
504 err = kstrtol(buf, 10, &val);
505 if (err)
506 return err;
427 507
428 mutex_lock(&data->update_lock); 508 mutex_lock(&data->update_lock);
429 data->fan_min[nr] = FAN_TO_REG(val, 509 data->fan_min[nr] = FAN_TO_REG(val,
430 FAN_DIV_FROM_REG(data->fan_div[nr])); 510 FAN_DIV_FROM_REG(data->fan_div[nr]));
431 lm87_write_value(client, LM87_REG_FAN_MIN(nr), data->fan_min[nr]); 511 lm87_write_value(client, LM87_REG_FAN_MIN(nr), data->fan_min[nr]);
432 mutex_unlock(&data->update_lock); 512 mutex_unlock(&data->update_lock);
513 return count;
433} 514}
434 515
435/* Note: we save and restore the fan minimum here, because its value is 516/*
436 determined in part by the fan clock divider. This follows the principle 517 * Note: we save and restore the fan minimum here, because its value is
437 of least surprise; the user doesn't expect the fan minimum to change just 518 * determined in part by the fan clock divider. This follows the principle
438 because the divider changed. */ 519 * of least surprise; the user doesn't expect the fan minimum to change just
439static ssize_t set_fan_div(struct device *dev, const char *buf, 520 * because the divider changed.
440 size_t count, int nr) 521 */
522static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
523 const char *buf, size_t count)
441{ 524{
442 struct i2c_client *client = to_i2c_client(dev); 525 struct i2c_client *client = to_i2c_client(dev);
443 struct lm87_data *data = i2c_get_clientdata(client); 526 struct lm87_data *data = i2c_get_clientdata(client);
444 long val = simple_strtol(buf, NULL, 10); 527 int nr = to_sensor_dev_attr(attr)->index;
528 long val;
529 int err;
445 unsigned long min; 530 unsigned long min;
446 u8 reg; 531 u8 reg;
447 532
533 err = kstrtol(buf, 10, &val);
534 if (err)
535 return err;
536
448 mutex_lock(&data->update_lock); 537 mutex_lock(&data->update_lock);
449 min = FAN_FROM_REG(data->fan_min[nr], 538 min = FAN_FROM_REG(data->fan_min[nr],
450 FAN_DIV_FROM_REG(data->fan_div[nr])); 539 FAN_DIV_FROM_REG(data->fan_div[nr]));
451 540
452 switch (val) { 541 switch (val) {
453 case 1: data->fan_div[nr] = 0; break; 542 case 1:
454 case 2: data->fan_div[nr] = 1; break; 543 data->fan_div[nr] = 0;
455 case 4: data->fan_div[nr] = 2; break; 544 break;
456 case 8: data->fan_div[nr] = 3; break; 545 case 2:
546 data->fan_div[nr] = 1;
547 break;
548 case 4:
549 data->fan_div[nr] = 2;
550 break;
551 case 8:
552 data->fan_div[nr] = 3;
553 break;
457 default: 554 default:
458 mutex_unlock(&data->update_lock); 555 mutex_unlock(&data->update_lock);
459 return -EINVAL; 556 return -EINVAL;
@@ -479,61 +576,69 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
479} 576}
480 577
481#define set_fan(offset) \ 578#define set_fan(offset) \
482static ssize_t set_fan##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \ 579static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
483 size_t count) \ 580 show_fan_input, NULL, offset - 1); \
484{ \ 581static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
485 set_fan_min(dev, buf, offset-1); \ 582 show_fan_min, set_fan_min, offset - 1); \
486 return count; \ 583static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
487} \ 584 show_fan_div, set_fan_div, offset - 1)
488static ssize_t set_fan##offset##_div(struct device *dev, struct device_attribute *attr, const char *buf, \
489 size_t count) \
490{ \
491 return set_fan_div(dev, buf, count, offset-1); \
492} \
493static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
494 show_fan##offset##_min, set_fan##offset##_min); \
495static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
496 show_fan##offset##_div, set_fan##offset##_div);
497set_fan(1); 585set_fan(1);
498set_fan(2); 586set_fan(2);
499 587
500static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 588static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
589 char *buf)
501{ 590{
502 struct lm87_data *data = lm87_update_device(dev); 591 struct lm87_data *data = lm87_update_device(dev);
503 return sprintf(buf, "%d\n", data->alarms); 592 return sprintf(buf, "%d\n", data->alarms);
504} 593}
505static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 594static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
506 595
507static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) 596static ssize_t show_vid(struct device *dev, struct device_attribute *attr,
597 char *buf)
508{ 598{
509 struct lm87_data *data = lm87_update_device(dev); 599 struct lm87_data *data = lm87_update_device(dev);
510 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); 600 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
511} 601}
512static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 602static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
513 603
514static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf) 604static ssize_t show_vrm(struct device *dev, struct device_attribute *attr,
605 char *buf)
515{ 606{
516 struct lm87_data *data = dev_get_drvdata(dev); 607 struct lm87_data *data = dev_get_drvdata(dev);
517 return sprintf(buf, "%d\n", data->vrm); 608 return sprintf(buf, "%d\n", data->vrm);
518} 609}
519static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 610static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
611 const char *buf, size_t count)
520{ 612{
521 struct lm87_data *data = dev_get_drvdata(dev); 613 struct lm87_data *data = dev_get_drvdata(dev);
522 data->vrm = simple_strtoul(buf, NULL, 10); 614 unsigned long val;
615 int err;
616
617 err = kstrtoul(buf, 10, &val);
618 if (err)
619 return err;
620 data->vrm = val;
523 return count; 621 return count;
524} 622}
525static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); 623static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
526 624
527static ssize_t show_aout(struct device *dev, struct device_attribute *attr, char *buf) 625static ssize_t show_aout(struct device *dev, struct device_attribute *attr,
626 char *buf)
528{ 627{
529 struct lm87_data *data = lm87_update_device(dev); 628 struct lm87_data *data = lm87_update_device(dev);
530 return sprintf(buf, "%d\n", AOUT_FROM_REG(data->aout)); 629 return sprintf(buf, "%d\n", AOUT_FROM_REG(data->aout));
531} 630}
532static ssize_t set_aout(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 631static ssize_t set_aout(struct device *dev, struct device_attribute *attr,
632 const char *buf, size_t count)
533{ 633{
534 struct i2c_client *client = to_i2c_client(dev); 634 struct i2c_client *client = to_i2c_client(dev);
535 struct lm87_data *data = i2c_get_clientdata(client); 635 struct lm87_data *data = i2c_get_clientdata(client);
536 long val = simple_strtol(buf, NULL, 10); 636 long val;
637 int err;
638
639 err = kstrtol(buf, 10, &val);
640 if (err)
641 return err;
537 642
538 mutex_lock(&data->update_lock); 643 mutex_lock(&data->update_lock);
539 data->aout = AOUT_TO_REG(val); 644 data->aout = AOUT_TO_REG(val);
@@ -571,31 +676,31 @@ static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 15);
571 */ 676 */
572 677
573static struct attribute *lm87_attributes[] = { 678static struct attribute *lm87_attributes[] = {
574 &dev_attr_in1_input.attr, 679 &sensor_dev_attr_in1_input.dev_attr.attr,
575 &dev_attr_in1_min.attr, 680 &sensor_dev_attr_in1_min.dev_attr.attr,
576 &dev_attr_in1_max.attr, 681 &sensor_dev_attr_in1_max.dev_attr.attr,
577 &sensor_dev_attr_in1_alarm.dev_attr.attr, 682 &sensor_dev_attr_in1_alarm.dev_attr.attr,
578 &dev_attr_in2_input.attr, 683 &sensor_dev_attr_in2_input.dev_attr.attr,
579 &dev_attr_in2_min.attr, 684 &sensor_dev_attr_in2_min.dev_attr.attr,
580 &dev_attr_in2_max.attr, 685 &sensor_dev_attr_in2_max.dev_attr.attr,
581 &sensor_dev_attr_in2_alarm.dev_attr.attr, 686 &sensor_dev_attr_in2_alarm.dev_attr.attr,
582 &dev_attr_in3_input.attr, 687 &sensor_dev_attr_in3_input.dev_attr.attr,
583 &dev_attr_in3_min.attr, 688 &sensor_dev_attr_in3_min.dev_attr.attr,
584 &dev_attr_in3_max.attr, 689 &sensor_dev_attr_in3_max.dev_attr.attr,
585 &sensor_dev_attr_in3_alarm.dev_attr.attr, 690 &sensor_dev_attr_in3_alarm.dev_attr.attr,
586 &dev_attr_in4_input.attr, 691 &sensor_dev_attr_in4_input.dev_attr.attr,
587 &dev_attr_in4_min.attr, 692 &sensor_dev_attr_in4_min.dev_attr.attr,
588 &dev_attr_in4_max.attr, 693 &sensor_dev_attr_in4_max.dev_attr.attr,
589 &sensor_dev_attr_in4_alarm.dev_attr.attr, 694 &sensor_dev_attr_in4_alarm.dev_attr.attr,
590 695
591 &dev_attr_temp1_input.attr, 696 &sensor_dev_attr_temp1_input.dev_attr.attr,
592 &dev_attr_temp1_max.attr, 697 &sensor_dev_attr_temp1_max.dev_attr.attr,
593 &dev_attr_temp1_min.attr, 698 &sensor_dev_attr_temp1_min.dev_attr.attr,
594 &dev_attr_temp1_crit.attr, 699 &dev_attr_temp1_crit.attr,
595 &sensor_dev_attr_temp1_alarm.dev_attr.attr, 700 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
596 &dev_attr_temp2_input.attr, 701 &sensor_dev_attr_temp2_input.dev_attr.attr,
597 &dev_attr_temp2_max.attr, 702 &sensor_dev_attr_temp2_max.dev_attr.attr,
598 &dev_attr_temp2_min.attr, 703 &sensor_dev_attr_temp2_min.dev_attr.attr,
599 &dev_attr_temp2_crit.attr, 704 &dev_attr_temp2_crit.attr,
600 &sensor_dev_attr_temp2_alarm.dev_attr.attr, 705 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
601 &sensor_dev_attr_temp2_fault.dev_attr.attr, 706 &sensor_dev_attr_temp2_fault.dev_attr.attr,
@@ -610,70 +715,110 @@ static const struct attribute_group lm87_group = {
610 .attrs = lm87_attributes, 715 .attrs = lm87_attributes,
611}; 716};
612 717
613static struct attribute *lm87_attributes_opt[] = { 718static struct attribute *lm87_attributes_in6[] = {
614 &dev_attr_in6_input.attr, 719 &sensor_dev_attr_in6_input.dev_attr.attr,
615 &dev_attr_in6_min.attr, 720 &sensor_dev_attr_in6_min.dev_attr.attr,
616 &dev_attr_in6_max.attr, 721 &sensor_dev_attr_in6_max.dev_attr.attr,
617 &sensor_dev_attr_in6_alarm.dev_attr.attr, 722 &sensor_dev_attr_in6_alarm.dev_attr.attr,
723 NULL
724};
725
726static const struct attribute_group lm87_group_in6 = {
727 .attrs = lm87_attributes_in6,
728};
618 729
619 &dev_attr_fan1_input.attr, 730static struct attribute *lm87_attributes_fan1[] = {
620 &dev_attr_fan1_min.attr, 731 &sensor_dev_attr_fan1_input.dev_attr.attr,
621 &dev_attr_fan1_div.attr, 732 &sensor_dev_attr_fan1_min.dev_attr.attr,
733 &sensor_dev_attr_fan1_div.dev_attr.attr,
622 &sensor_dev_attr_fan1_alarm.dev_attr.attr, 734 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
735 NULL
736};
737
738static const struct attribute_group lm87_group_fan1 = {
739 .attrs = lm87_attributes_fan1,
740};
623 741
624 &dev_attr_in7_input.attr, 742static struct attribute *lm87_attributes_in7[] = {
625 &dev_attr_in7_min.attr, 743 &sensor_dev_attr_in7_input.dev_attr.attr,
626 &dev_attr_in7_max.attr, 744 &sensor_dev_attr_in7_min.dev_attr.attr,
745 &sensor_dev_attr_in7_max.dev_attr.attr,
627 &sensor_dev_attr_in7_alarm.dev_attr.attr, 746 &sensor_dev_attr_in7_alarm.dev_attr.attr,
747 NULL
748};
628 749
629 &dev_attr_fan2_input.attr, 750static const struct attribute_group lm87_group_in7 = {
630 &dev_attr_fan2_min.attr, 751 .attrs = lm87_attributes_in7,
631 &dev_attr_fan2_div.attr, 752};
753
754static struct attribute *lm87_attributes_fan2[] = {
755 &sensor_dev_attr_fan2_input.dev_attr.attr,
756 &sensor_dev_attr_fan2_min.dev_attr.attr,
757 &sensor_dev_attr_fan2_div.dev_attr.attr,
632 &sensor_dev_attr_fan2_alarm.dev_attr.attr, 758 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
759 NULL
760};
761
762static const struct attribute_group lm87_group_fan2 = {
763 .attrs = lm87_attributes_fan2,
764};
633 765
634 &dev_attr_temp3_input.attr, 766static struct attribute *lm87_attributes_temp3[] = {
635 &dev_attr_temp3_max.attr, 767 &sensor_dev_attr_temp3_input.dev_attr.attr,
636 &dev_attr_temp3_min.attr, 768 &sensor_dev_attr_temp3_max.dev_attr.attr,
769 &sensor_dev_attr_temp3_min.dev_attr.attr,
637 &dev_attr_temp3_crit.attr, 770 &dev_attr_temp3_crit.attr,
638 &sensor_dev_attr_temp3_alarm.dev_attr.attr, 771 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
639 &sensor_dev_attr_temp3_fault.dev_attr.attr, 772 &sensor_dev_attr_temp3_fault.dev_attr.attr,
773 NULL
774};
775
776static const struct attribute_group lm87_group_temp3 = {
777 .attrs = lm87_attributes_temp3,
778};
640 779
641 &dev_attr_in0_input.attr, 780static struct attribute *lm87_attributes_in0_5[] = {
642 &dev_attr_in0_min.attr, 781 &sensor_dev_attr_in0_input.dev_attr.attr,
643 &dev_attr_in0_max.attr, 782 &sensor_dev_attr_in0_min.dev_attr.attr,
783 &sensor_dev_attr_in0_max.dev_attr.attr,
644 &sensor_dev_attr_in0_alarm.dev_attr.attr, 784 &sensor_dev_attr_in0_alarm.dev_attr.attr,
645 &dev_attr_in5_input.attr, 785 &sensor_dev_attr_in5_input.dev_attr.attr,
646 &dev_attr_in5_min.attr, 786 &sensor_dev_attr_in5_min.dev_attr.attr,
647 &dev_attr_in5_max.attr, 787 &sensor_dev_attr_in5_max.dev_attr.attr,
648 &sensor_dev_attr_in5_alarm.dev_attr.attr, 788 &sensor_dev_attr_in5_alarm.dev_attr.attr,
789 NULL
790};
649 791
792static const struct attribute_group lm87_group_in0_5 = {
793 .attrs = lm87_attributes_in0_5,
794};
795
796static struct attribute *lm87_attributes_vid[] = {
650 &dev_attr_cpu0_vid.attr, 797 &dev_attr_cpu0_vid.attr,
651 &dev_attr_vrm.attr, 798 &dev_attr_vrm.attr,
652
653 NULL 799 NULL
654}; 800};
655 801
656static const struct attribute_group lm87_group_opt = { 802static const struct attribute_group lm87_group_vid = {
657 .attrs = lm87_attributes_opt, 803 .attrs = lm87_attributes_vid,
658}; 804};
659 805
660/* Return 0 if detection is successful, -ENODEV otherwise */ 806/* Return 0 if detection is successful, -ENODEV otherwise */
661static int lm87_detect(struct i2c_client *new_client, 807static int lm87_detect(struct i2c_client *client, struct i2c_board_info *info)
662 struct i2c_board_info *info)
663{ 808{
664 struct i2c_adapter *adapter = new_client->adapter; 809 struct i2c_adapter *adapter = client->adapter;
665 const char *name; 810 const char *name;
666 u8 cid, rev; 811 u8 cid, rev;
667 812
668 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 813 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
669 return -ENODEV; 814 return -ENODEV;
670 815
671 if (lm87_read_value(new_client, LM87_REG_CONFIG) & 0x80) 816 if (lm87_read_value(client, LM87_REG_CONFIG) & 0x80)
672 return -ENODEV; 817 return -ENODEV;
673 818
674 /* Now, we do the remaining detection. */ 819 /* Now, we do the remaining detection. */
675 cid = lm87_read_value(new_client, LM87_REG_COMPANY_ID); 820 cid = lm87_read_value(client, LM87_REG_COMPANY_ID);
676 rev = lm87_read_value(new_client, LM87_REG_REVISION); 821 rev = lm87_read_value(client, LM87_REG_REVISION);
677 822
678 if (cid == 0x02 /* National Semiconductor */ 823 if (cid == 0x02 /* National Semiconductor */
679 && (rev >= 0x01 && rev <= 0x08)) 824 && (rev >= 0x01 && rev <= 0x08))
@@ -683,7 +828,7 @@ static int lm87_detect(struct i2c_client *new_client,
683 name = "adm1024"; 828 name = "adm1024";
684 else { 829 else {
685 dev_dbg(&adapter->dev, "LM87 detection failed at 0x%02x\n", 830 dev_dbg(&adapter->dev, "LM87 detection failed at 0x%02x\n",
686 new_client->addr); 831 client->addr);
687 return -ENODEV; 832 return -ENODEV;
688 } 833 }
689 834
@@ -692,8 +837,63 @@ static int lm87_detect(struct i2c_client *new_client,
692 return 0; 837 return 0;
693} 838}
694 839
695static int lm87_probe(struct i2c_client *new_client, 840static void lm87_remove_files(struct i2c_client *client)
696 const struct i2c_device_id *id) 841{
842 struct device *dev = &client->dev;
843
844 sysfs_remove_group(&dev->kobj, &lm87_group);
845 sysfs_remove_group(&dev->kobj, &lm87_group_in6);
846 sysfs_remove_group(&dev->kobj, &lm87_group_fan1);
847 sysfs_remove_group(&dev->kobj, &lm87_group_in7);
848 sysfs_remove_group(&dev->kobj, &lm87_group_fan2);
849 sysfs_remove_group(&dev->kobj, &lm87_group_temp3);
850 sysfs_remove_group(&dev->kobj, &lm87_group_in0_5);
851 sysfs_remove_group(&dev->kobj, &lm87_group_vid);
852}
853
854static void lm87_init_client(struct i2c_client *client)
855{
856 struct lm87_data *data = i2c_get_clientdata(client);
857
858 if (client->dev.platform_data) {
859 data->channel = *(u8 *)client->dev.platform_data;
860 lm87_write_value(client,
861 LM87_REG_CHANNEL_MODE, data->channel);
862 } else {
863 data->channel = lm87_read_value(client, LM87_REG_CHANNEL_MODE);
864 }
865 data->config = lm87_read_value(client, LM87_REG_CONFIG) & 0x6F;
866
867 if (!(data->config & 0x01)) {
868 int i;
869
870 /* Limits are left uninitialized after power-up */
871 for (i = 1; i < 6; i++) {
872 lm87_write_value(client, LM87_REG_IN_MIN(i), 0x00);
873 lm87_write_value(client, LM87_REG_IN_MAX(i), 0xFF);
874 }
875 for (i = 0; i < 2; i++) {
876 lm87_write_value(client, LM87_REG_TEMP_HIGH[i], 0x7F);
877 lm87_write_value(client, LM87_REG_TEMP_LOW[i], 0x00);
878 lm87_write_value(client, LM87_REG_AIN_MIN(i), 0x00);
879 lm87_write_value(client, LM87_REG_AIN_MAX(i), 0xFF);
880 }
881 if (data->channel & CHAN_TEMP3) {
882 lm87_write_value(client, LM87_REG_TEMP_HIGH[2], 0x7F);
883 lm87_write_value(client, LM87_REG_TEMP_LOW[2], 0x00);
884 } else {
885 lm87_write_value(client, LM87_REG_IN_MIN(0), 0x00);
886 lm87_write_value(client, LM87_REG_IN_MAX(0), 0xFF);
887 }
888 }
889
890 /* Make sure Start is set and INT#_Clear is clear */
891 if ((data->config & 0x09) != 0x01)
892 lm87_write_value(client, LM87_REG_CONFIG,
893 (data->config & 0x77) | 0x01);
894}
895
896static int lm87_probe(struct i2c_client *client, const struct i2c_device_id *id)
697{ 897{
698 struct lm87_data *data; 898 struct lm87_data *data;
699 int err; 899 int err;
@@ -704,12 +904,12 @@ static int lm87_probe(struct i2c_client *new_client,
704 goto exit; 904 goto exit;
705 } 905 }
706 906
707 i2c_set_clientdata(new_client, data); 907 i2c_set_clientdata(client, data);
708 data->valid = 0; 908 data->valid = 0;
709 mutex_init(&data->update_lock); 909 mutex_init(&data->update_lock);
710 910
711 /* Initialize the LM87 chip */ 911 /* Initialize the LM87 chip */
712 lm87_init_client(new_client); 912 lm87_init_client(client);
713 913
714 data->in_scale[0] = 2500; 914 data->in_scale[0] = 2500;
715 data->in_scale[1] = 2700; 915 data->in_scale[1] = 2700;
@@ -721,97 +921,48 @@ static int lm87_probe(struct i2c_client *new_client,
721 data->in_scale[7] = 1875; 921 data->in_scale[7] = 1875;
722 922
723 /* Register sysfs hooks */ 923 /* Register sysfs hooks */
724 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm87_group))) 924 err = sysfs_create_group(&client->dev.kobj, &lm87_group);
925 if (err)
725 goto exit_free; 926 goto exit_free;
726 927
727 if (data->channel & CHAN_NO_FAN(0)) { 928 if (data->channel & CHAN_NO_FAN(0)) {
728 if ((err = device_create_file(&new_client->dev, 929 err = sysfs_create_group(&client->dev.kobj, &lm87_group_in6);
729 &dev_attr_in6_input)) 930 if (err)
730 || (err = device_create_file(&new_client->dev,
731 &dev_attr_in6_min))
732 || (err = device_create_file(&new_client->dev,
733 &dev_attr_in6_max))
734 || (err = device_create_file(&new_client->dev,
735 &sensor_dev_attr_in6_alarm.dev_attr)))
736 goto exit_remove; 931 goto exit_remove;
737 } else { 932 } else {
738 if ((err = device_create_file(&new_client->dev, 933 err = sysfs_create_group(&client->dev.kobj, &lm87_group_fan1);
739 &dev_attr_fan1_input)) 934 if (err)
740 || (err = device_create_file(&new_client->dev,
741 &dev_attr_fan1_min))
742 || (err = device_create_file(&new_client->dev,
743 &dev_attr_fan1_div))
744 || (err = device_create_file(&new_client->dev,
745 &sensor_dev_attr_fan1_alarm.dev_attr)))
746 goto exit_remove; 935 goto exit_remove;
747 } 936 }
748 937
749 if (data->channel & CHAN_NO_FAN(1)) { 938 if (data->channel & CHAN_NO_FAN(1)) {
750 if ((err = device_create_file(&new_client->dev, 939 err = sysfs_create_group(&client->dev.kobj, &lm87_group_in7);
751 &dev_attr_in7_input)) 940 if (err)
752 || (err = device_create_file(&new_client->dev,
753 &dev_attr_in7_min))
754 || (err = device_create_file(&new_client->dev,
755 &dev_attr_in7_max))
756 || (err = device_create_file(&new_client->dev,
757 &sensor_dev_attr_in7_alarm.dev_attr)))
758 goto exit_remove; 941 goto exit_remove;
759 } else { 942 } else {
760 if ((err = device_create_file(&new_client->dev, 943 err = sysfs_create_group(&client->dev.kobj, &lm87_group_fan2);
761 &dev_attr_fan2_input)) 944 if (err)
762 || (err = device_create_file(&new_client->dev,
763 &dev_attr_fan2_min))
764 || (err = device_create_file(&new_client->dev,
765 &dev_attr_fan2_div))
766 || (err = device_create_file(&new_client->dev,
767 &sensor_dev_attr_fan2_alarm.dev_attr)))
768 goto exit_remove; 945 goto exit_remove;
769 } 946 }
770 947
771 if (data->channel & CHAN_TEMP3) { 948 if (data->channel & CHAN_TEMP3) {
772 if ((err = device_create_file(&new_client->dev, 949 err = sysfs_create_group(&client->dev.kobj, &lm87_group_temp3);
773 &dev_attr_temp3_input)) 950 if (err)
774 || (err = device_create_file(&new_client->dev,
775 &dev_attr_temp3_max))
776 || (err = device_create_file(&new_client->dev,
777 &dev_attr_temp3_min))
778 || (err = device_create_file(&new_client->dev,
779 &dev_attr_temp3_crit))
780 || (err = device_create_file(&new_client->dev,
781 &sensor_dev_attr_temp3_alarm.dev_attr))
782 || (err = device_create_file(&new_client->dev,
783 &sensor_dev_attr_temp3_fault.dev_attr)))
784 goto exit_remove; 951 goto exit_remove;
785 } else { 952 } else {
786 if ((err = device_create_file(&new_client->dev, 953 err = sysfs_create_group(&client->dev.kobj, &lm87_group_in0_5);
787 &dev_attr_in0_input)) 954 if (err)
788 || (err = device_create_file(&new_client->dev,
789 &dev_attr_in0_min))
790 || (err = device_create_file(&new_client->dev,
791 &dev_attr_in0_max))
792 || (err = device_create_file(&new_client->dev,
793 &sensor_dev_attr_in0_alarm.dev_attr))
794 || (err = device_create_file(&new_client->dev,
795 &dev_attr_in5_input))
796 || (err = device_create_file(&new_client->dev,
797 &dev_attr_in5_min))
798 || (err = device_create_file(&new_client->dev,
799 &dev_attr_in5_max))
800 || (err = device_create_file(&new_client->dev,
801 &sensor_dev_attr_in5_alarm.dev_attr)))
802 goto exit_remove; 955 goto exit_remove;
803 } 956 }
804 957
805 if (!(data->channel & CHAN_NO_VID)) { 958 if (!(data->channel & CHAN_NO_VID)) {
806 data->vrm = vid_which_vrm(); 959 data->vrm = vid_which_vrm();
807 if ((err = device_create_file(&new_client->dev, 960 err = sysfs_create_group(&client->dev.kobj, &lm87_group_vid);
808 &dev_attr_cpu0_vid)) 961 if (err)
809 || (err = device_create_file(&new_client->dev,
810 &dev_attr_vrm)))
811 goto exit_remove; 962 goto exit_remove;
812 } 963 }
813 964
814 data->hwmon_dev = hwmon_device_register(&new_client->dev); 965 data->hwmon_dev = hwmon_device_register(&client->dev);
815 if (IS_ERR(data->hwmon_dev)) { 966 if (IS_ERR(data->hwmon_dev)) {
816 err = PTR_ERR(data->hwmon_dev); 967 err = PTR_ERR(data->hwmon_dev);
817 goto exit_remove; 968 goto exit_remove;
@@ -820,162 +971,51 @@ static int lm87_probe(struct i2c_client *new_client,
820 return 0; 971 return 0;
821 972
822exit_remove: 973exit_remove:
823 sysfs_remove_group(&new_client->dev.kobj, &lm87_group); 974 lm87_remove_files(client);
824 sysfs_remove_group(&new_client->dev.kobj, &lm87_group_opt);
825exit_free: 975exit_free:
826 lm87_write_value(new_client, LM87_REG_CONFIG, data->config); 976 lm87_write_value(client, LM87_REG_CONFIG, data->config);
827 kfree(data); 977 kfree(data);
828exit: 978exit:
829 return err; 979 return err;
830} 980}
831 981
832static void lm87_init_client(struct i2c_client *client)
833{
834 struct lm87_data *data = i2c_get_clientdata(client);
835
836 if (client->dev.platform_data) {
837 data->channel = *(u8 *)client->dev.platform_data;
838 lm87_write_value(client,
839 LM87_REG_CHANNEL_MODE, data->channel);
840 } else {
841 data->channel = lm87_read_value(client, LM87_REG_CHANNEL_MODE);
842 }
843 data->config = lm87_read_value(client, LM87_REG_CONFIG) & 0x6F;
844
845 if (!(data->config & 0x01)) {
846 int i;
847
848 /* Limits are left uninitialized after power-up */
849 for (i = 1; i < 6; i++) {
850 lm87_write_value(client, LM87_REG_IN_MIN(i), 0x00);
851 lm87_write_value(client, LM87_REG_IN_MAX(i), 0xFF);
852 }
853 for (i = 0; i < 2; i++) {
854 lm87_write_value(client, LM87_REG_TEMP_HIGH[i], 0x7F);
855 lm87_write_value(client, LM87_REG_TEMP_LOW[i], 0x00);
856 lm87_write_value(client, LM87_REG_AIN_MIN(i), 0x00);
857 lm87_write_value(client, LM87_REG_AIN_MAX(i), 0xFF);
858 }
859 if (data->channel & CHAN_TEMP3) {
860 lm87_write_value(client, LM87_REG_TEMP_HIGH[2], 0x7F);
861 lm87_write_value(client, LM87_REG_TEMP_LOW[2], 0x00);
862 } else {
863 lm87_write_value(client, LM87_REG_IN_MIN(0), 0x00);
864 lm87_write_value(client, LM87_REG_IN_MAX(0), 0xFF);
865 }
866 }
867
868 /* Make sure Start is set and INT#_Clear is clear */
869 if ((data->config & 0x09) != 0x01)
870 lm87_write_value(client, LM87_REG_CONFIG,
871 (data->config & 0x77) | 0x01);
872}
873
874static int lm87_remove(struct i2c_client *client) 982static int lm87_remove(struct i2c_client *client)
875{ 983{
876 struct lm87_data *data = i2c_get_clientdata(client); 984 struct lm87_data *data = i2c_get_clientdata(client);
877 985
878 hwmon_device_unregister(data->hwmon_dev); 986 hwmon_device_unregister(data->hwmon_dev);
879 sysfs_remove_group(&client->dev.kobj, &lm87_group); 987 lm87_remove_files(client);
880 sysfs_remove_group(&client->dev.kobj, &lm87_group_opt);
881 988
882 lm87_write_value(client, LM87_REG_CONFIG, data->config); 989 lm87_write_value(client, LM87_REG_CONFIG, data->config);
883 kfree(data); 990 kfree(data);
884 return 0; 991 return 0;
885} 992}
886 993
887static struct lm87_data *lm87_update_device(struct device *dev) 994/*
888{ 995 * Driver data (common to all clients)
889 struct i2c_client *client = to_i2c_client(dev); 996 */
890 struct lm87_data *data = i2c_get_clientdata(client);
891
892 mutex_lock(&data->update_lock);
893
894 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
895 int i, j;
896
897 dev_dbg(&client->dev, "Updating data.\n");
898
899 i = (data->channel & CHAN_TEMP3) ? 1 : 0;
900 j = (data->channel & CHAN_TEMP3) ? 5 : 6;
901 for (; i < j; i++) {
902 data->in[i] = lm87_read_value(client,
903 LM87_REG_IN(i));
904 data->in_min[i] = lm87_read_value(client,
905 LM87_REG_IN_MIN(i));
906 data->in_max[i] = lm87_read_value(client,
907 LM87_REG_IN_MAX(i));
908 }
909
910 for (i = 0; i < 2; i++) {
911 if (data->channel & CHAN_NO_FAN(i)) {
912 data->in[6+i] = lm87_read_value(client,
913 LM87_REG_AIN(i));
914 data->in_max[6+i] = lm87_read_value(client,
915 LM87_REG_AIN_MAX(i));
916 data->in_min[6+i] = lm87_read_value(client,
917 LM87_REG_AIN_MIN(i));
918
919 } else {
920 data->fan[i] = lm87_read_value(client,
921 LM87_REG_FAN(i));
922 data->fan_min[i] = lm87_read_value(client,
923 LM87_REG_FAN_MIN(i));
924 }
925 }
926
927 j = (data->channel & CHAN_TEMP3) ? 3 : 2;
928 for (i = 0 ; i < j; i++) {
929 data->temp[i] = lm87_read_value(client,
930 LM87_REG_TEMP[i]);
931 data->temp_high[i] = lm87_read_value(client,
932 LM87_REG_TEMP_HIGH[i]);
933 data->temp_low[i] = lm87_read_value(client,
934 LM87_REG_TEMP_LOW[i]);
935 }
936
937 i = lm87_read_value(client, LM87_REG_TEMP_HW_INT_LOCK);
938 j = lm87_read_value(client, LM87_REG_TEMP_HW_INT);
939 data->temp_crit_int = min(i, j);
940
941 i = lm87_read_value(client, LM87_REG_TEMP_HW_EXT_LOCK);
942 j = lm87_read_value(client, LM87_REG_TEMP_HW_EXT);
943 data->temp_crit_ext = min(i, j);
944
945 i = lm87_read_value(client, LM87_REG_VID_FAN_DIV);
946 data->fan_div[0] = (i >> 4) & 0x03;
947 data->fan_div[1] = (i >> 6) & 0x03;
948 data->vid = (i & 0x0F)
949 | (lm87_read_value(client, LM87_REG_VID4) & 0x01)
950 << 4;
951
952 data->alarms = lm87_read_value(client, LM87_REG_ALARMS1)
953 | (lm87_read_value(client, LM87_REG_ALARMS2)
954 << 8);
955 data->aout = lm87_read_value(client, LM87_REG_AOUT);
956
957 data->last_updated = jiffies;
958 data->valid = 1;
959 }
960
961 mutex_unlock(&data->update_lock);
962 997
963 return data; 998static const struct i2c_device_id lm87_id[] = {
964} 999 { "lm87", lm87 },
1000 { "adm1024", adm1024 },
1001 { }
1002};
1003MODULE_DEVICE_TABLE(i2c, lm87_id);
965 1004
966static int __init sensors_lm87_init(void) 1005static struct i2c_driver lm87_driver = {
967{ 1006 .class = I2C_CLASS_HWMON,
968 return i2c_add_driver(&lm87_driver); 1007 .driver = {
969} 1008 .name = "lm87",
1009 },
1010 .probe = lm87_probe,
1011 .remove = lm87_remove,
1012 .id_table = lm87_id,
1013 .detect = lm87_detect,
1014 .address_list = normal_i2c,
1015};
970 1016
971static void __exit sensors_lm87_exit(void) 1017module_i2c_driver(lm87_driver);
972{
973 i2c_del_driver(&lm87_driver);
974}
975 1018
976MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org> and others"); 1019MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org> and others");
977MODULE_DESCRIPTION("LM87 driver"); 1020MODULE_DESCRIPTION("LM87 driver");
978MODULE_LICENSE("GPL"); 1021MODULE_LICENSE("GPL");
979
980module_init(sensors_lm87_init);
981module_exit(sensors_lm87_exit);
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index d2dd5f90496d..248f2b40dfaf 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -1514,19 +1514,8 @@ static struct i2c_driver lm90_driver = {
1514 .address_list = normal_i2c, 1514 .address_list = normal_i2c,
1515}; 1515};
1516 1516
1517static int __init sensors_lm90_init(void) 1517module_i2c_driver(lm90_driver);
1518{
1519 return i2c_add_driver(&lm90_driver);
1520}
1521
1522static void __exit sensors_lm90_exit(void)
1523{
1524 i2c_del_driver(&lm90_driver);
1525}
1526 1518
1527MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); 1519MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
1528MODULE_DESCRIPTION("LM90/ADM1032 driver"); 1520MODULE_DESCRIPTION("LM90/ADM1032 driver");
1529MODULE_LICENSE("GPL"); 1521MODULE_LICENSE("GPL");
1530
1531module_init(sensors_lm90_init);
1532module_exit(sensors_lm90_exit);
diff --git a/drivers/hwmon/lm92.c b/drivers/hwmon/lm92.c
index 8fcbd4d422c5..fdc691a4028f 100644
--- a/drivers/hwmon/lm92.c
+++ b/drivers/hwmon/lm92.c
@@ -49,8 +49,10 @@
49#include <linux/err.h> 49#include <linux/err.h>
50#include <linux/mutex.h> 50#include <linux/mutex.h>
51 51
52/* The LM92 and MAX6635 have 2 two-state pins for address selection, 52/*
53 resulting in 4 possible addresses. */ 53 * The LM92 and MAX6635 have 2 two-state pins for address selection,
54 * resulting in 4 possible addresses.
55 */
54static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 56static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b,
55 I2C_CLIENT_END }; 57 I2C_CLIENT_END };
56 58
@@ -63,11 +65,13 @@ static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b,
63#define LM92_REG_TEMP_HIGH 0x05 /* 16-bit, RW */ 65#define LM92_REG_TEMP_HIGH 0x05 /* 16-bit, RW */
64#define LM92_REG_MAN_ID 0x07 /* 16-bit, RO, LM92 only */ 66#define LM92_REG_MAN_ID 0x07 /* 16-bit, RO, LM92 only */
65 67
66/* The LM92 uses signed 13-bit values with LSB = 0.0625 degree Celsius, 68/*
67 left-justified in 16-bit registers. No rounding is done, with such 69 * The LM92 uses signed 13-bit values with LSB = 0.0625 degree Celsius,
68 a resolution it's just not worth it. Note that the MAX6635 doesn't 70 * left-justified in 16-bit registers. No rounding is done, with such
69 make use of the 4 lower bits for limits (i.e. effective resolution 71 * a resolution it's just not worth it. Note that the MAX6635 doesn't
70 for limits is 1 degree Celsius). */ 72 * make use of the 4 lower bits for limits (i.e. effective resolution
73 * for limits is 1 degree Celsius).
74 */
71static inline int TEMP_FROM_REG(s16 reg) 75static inline int TEMP_FROM_REG(s16 reg)
72{ 76{
73 return reg / 8 * 625 / 10; 77 return reg / 8 * 625 / 10;
@@ -138,7 +142,8 @@ static struct lm92_data *lm92_update_device(struct device *dev)
138} 142}
139 143
140#define show_temp(value) \ 144#define show_temp(value) \
141static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \ 145static ssize_t show_##value(struct device *dev, struct device_attribute *attr, \
146 char *buf) \
142{ \ 147{ \
143 struct lm92_data *data = lm92_update_device(dev); \ 148 struct lm92_data *data = lm92_update_device(dev); \
144 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->value)); \ 149 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->value)); \
@@ -149,13 +154,17 @@ show_temp(temp1_min);
149show_temp(temp1_max); 154show_temp(temp1_max);
150 155
151#define set_temp(value, reg) \ 156#define set_temp(value, reg) \
152static ssize_t set_##value(struct device *dev, struct device_attribute *attr, const char *buf, \ 157static ssize_t set_##value(struct device *dev, struct device_attribute *attr, \
158 const char *buf, \
153 size_t count) \ 159 size_t count) \
154{ \ 160{ \
155 struct i2c_client *client = to_i2c_client(dev); \ 161 struct i2c_client *client = to_i2c_client(dev); \
156 struct lm92_data *data = i2c_get_clientdata(client); \ 162 struct lm92_data *data = i2c_get_clientdata(client); \
157 long val = simple_strtol(buf, NULL, 10); \ 163 long val; \
158 \ 164 int err = kstrtol(buf, 10, &val); \
165 if (err) \
166 return err; \
167\
159 mutex_lock(&data->update_lock); \ 168 mutex_lock(&data->update_lock); \
160 data->value = TEMP_TO_REG(val); \ 169 data->value = TEMP_TO_REG(val); \
161 i2c_smbus_write_word_swapped(client, reg, data->value); \ 170 i2c_smbus_write_word_swapped(client, reg, data->value); \
@@ -166,31 +175,40 @@ set_temp(temp1_crit, LM92_REG_TEMP_CRIT);
166set_temp(temp1_min, LM92_REG_TEMP_LOW); 175set_temp(temp1_min, LM92_REG_TEMP_LOW);
167set_temp(temp1_max, LM92_REG_TEMP_HIGH); 176set_temp(temp1_max, LM92_REG_TEMP_HIGH);
168 177
169static ssize_t show_temp1_crit_hyst(struct device *dev, struct device_attribute *attr, char *buf) 178static ssize_t show_temp1_crit_hyst(struct device *dev,
179 struct device_attribute *attr, char *buf)
170{ 180{
171 struct lm92_data *data = lm92_update_device(dev); 181 struct lm92_data *data = lm92_update_device(dev);
172 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp1_crit) 182 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp1_crit)
173 - TEMP_FROM_REG(data->temp1_hyst)); 183 - TEMP_FROM_REG(data->temp1_hyst));
174} 184}
175static ssize_t show_temp1_max_hyst(struct device *dev, struct device_attribute *attr, char *buf) 185static ssize_t show_temp1_max_hyst(struct device *dev,
186 struct device_attribute *attr, char *buf)
176{ 187{
177 struct lm92_data *data = lm92_update_device(dev); 188 struct lm92_data *data = lm92_update_device(dev);
178 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp1_max) 189 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp1_max)
179 - TEMP_FROM_REG(data->temp1_hyst)); 190 - TEMP_FROM_REG(data->temp1_hyst));
180} 191}
181static ssize_t show_temp1_min_hyst(struct device *dev, struct device_attribute *attr, char *buf) 192static ssize_t show_temp1_min_hyst(struct device *dev,
193 struct device_attribute *attr, char *buf)
182{ 194{
183 struct lm92_data *data = lm92_update_device(dev); 195 struct lm92_data *data = lm92_update_device(dev);
184 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp1_min) 196 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp1_min)
185 + TEMP_FROM_REG(data->temp1_hyst)); 197 + TEMP_FROM_REG(data->temp1_hyst));
186} 198}
187 199
188static ssize_t set_temp1_crit_hyst(struct device *dev, struct device_attribute *attr, const char *buf, 200static ssize_t set_temp1_crit_hyst(struct device *dev,
189 size_t count) 201 struct device_attribute *attr,
202 const char *buf, size_t count)
190{ 203{
191 struct i2c_client *client = to_i2c_client(dev); 204 struct i2c_client *client = to_i2c_client(dev);
192 struct lm92_data *data = i2c_get_clientdata(client); 205 struct lm92_data *data = i2c_get_clientdata(client);
193 long val = simple_strtol(buf, NULL, 10); 206 long val;
207 int err;
208
209 err = kstrtol(buf, 10, &val);
210 if (err)
211 return err;
194 212
195 mutex_lock(&data->update_lock); 213 mutex_lock(&data->update_lock);
196 data->temp1_hyst = TEMP_FROM_REG(data->temp1_crit) - val; 214 data->temp1_hyst = TEMP_FROM_REG(data->temp1_crit) - val;
@@ -200,7 +218,8 @@ static ssize_t set_temp1_crit_hyst(struct device *dev, struct device_attribute *
200 return count; 218 return count;
201} 219}
202 220
203static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 221static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
222 char *buf)
204{ 223{
205 struct lm92_data *data = lm92_update_device(dev); 224 struct lm92_data *data = lm92_update_device(dev);
206 return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->temp1_input)); 225 return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->temp1_input));
@@ -246,26 +265,30 @@ static void lm92_init_client(struct i2c_client *client)
246 config & 0xFE); 265 config & 0xFE);
247} 266}
248 267
249/* The MAX6635 has no identification register, so we have to use tricks 268/*
250 to identify it reliably. This is somewhat slow. 269 * The MAX6635 has no identification register, so we have to use tricks
251 Note that we do NOT rely on the 2 MSB of the configuration register 270 * to identify it reliably. This is somewhat slow.
252 always reading 0, as suggested by the datasheet, because it was once 271 * Note that we do NOT rely on the 2 MSB of the configuration register
253 reported not to be true. */ 272 * always reading 0, as suggested by the datasheet, because it was once
273 * reported not to be true.
274 */
254static int max6635_check(struct i2c_client *client) 275static int max6635_check(struct i2c_client *client)
255{ 276{
256 u16 temp_low, temp_high, temp_hyst, temp_crit; 277 u16 temp_low, temp_high, temp_hyst, temp_crit;
257 u8 conf; 278 u8 conf;
258 int i; 279 int i;
259 280
260 /* No manufacturer ID register, so a read from this address will 281 /*
261 always return the last read value. */ 282 * No manufacturer ID register, so a read from this address will
283 * always return the last read value.
284 */
262 temp_low = i2c_smbus_read_word_data(client, LM92_REG_TEMP_LOW); 285 temp_low = i2c_smbus_read_word_data(client, LM92_REG_TEMP_LOW);
263 if (i2c_smbus_read_word_data(client, LM92_REG_MAN_ID) != temp_low) 286 if (i2c_smbus_read_word_data(client, LM92_REG_MAN_ID) != temp_low)
264 return 0; 287 return 0;
265 temp_high = i2c_smbus_read_word_data(client, LM92_REG_TEMP_HIGH); 288 temp_high = i2c_smbus_read_word_data(client, LM92_REG_TEMP_HIGH);
266 if (i2c_smbus_read_word_data(client, LM92_REG_MAN_ID) != temp_high) 289 if (i2c_smbus_read_word_data(client, LM92_REG_MAN_ID) != temp_high)
267 return 0; 290 return 0;
268 291
269 /* Limits are stored as integer values (signed, 9-bit). */ 292 /* Limits are stored as integer values (signed, 9-bit). */
270 if ((temp_low & 0x7f00) || (temp_high & 0x7f00)) 293 if ((temp_low & 0x7f00) || (temp_high & 0x7f00))
271 return 0; 294 return 0;
@@ -274,22 +297,24 @@ static int max6635_check(struct i2c_client *client)
274 if ((temp_hyst & 0x7f00) || (temp_crit & 0x7f00)) 297 if ((temp_hyst & 0x7f00) || (temp_crit & 0x7f00))
275 return 0; 298 return 0;
276 299
277 /* Registers addresses were found to cycle over 16-byte boundaries. 300 /*
278 We don't test all registers with all offsets so as to save some 301 * Registers addresses were found to cycle over 16-byte boundaries.
279 reads and time, but this should still be sufficient to dismiss 302 * We don't test all registers with all offsets so as to save some
280 non-MAX6635 chips. */ 303 * reads and time, but this should still be sufficient to dismiss
304 * non-MAX6635 chips.
305 */
281 conf = i2c_smbus_read_byte_data(client, LM92_REG_CONFIG); 306 conf = i2c_smbus_read_byte_data(client, LM92_REG_CONFIG);
282 for (i=16; i<96; i*=2) { 307 for (i = 16; i < 96; i *= 2) {
283 if (temp_hyst != i2c_smbus_read_word_data(client, 308 if (temp_hyst != i2c_smbus_read_word_data(client,
284 LM92_REG_TEMP_HYST + i - 16) 309 LM92_REG_TEMP_HYST + i - 16)
285 || temp_crit != i2c_smbus_read_word_data(client, 310 || temp_crit != i2c_smbus_read_word_data(client,
286 LM92_REG_TEMP_CRIT + i) 311 LM92_REG_TEMP_CRIT + i)
287 || temp_low != i2c_smbus_read_word_data(client, 312 || temp_low != i2c_smbus_read_word_data(client,
288 LM92_REG_TEMP_LOW + i + 16) 313 LM92_REG_TEMP_LOW + i + 16)
289 || temp_high != i2c_smbus_read_word_data(client, 314 || temp_high != i2c_smbus_read_word_data(client,
290 LM92_REG_TEMP_HIGH + i + 32) 315 LM92_REG_TEMP_HIGH + i + 32)
291 || conf != i2c_smbus_read_byte_data(client, 316 || conf != i2c_smbus_read_byte_data(client,
292 LM92_REG_CONFIG + i)) 317 LM92_REG_CONFIG + i))
293 return 0; 318 return 0;
294 } 319 }
295 320
@@ -362,7 +387,8 @@ static int lm92_probe(struct i2c_client *new_client,
362 lm92_init_client(new_client); 387 lm92_init_client(new_client);
363 388
364 /* Register sysfs hooks */ 389 /* Register sysfs hooks */
365 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm92_group))) 390 err = sysfs_create_group(&new_client->dev.kobj, &lm92_group);
391 if (err)
366 goto exit_free; 392 goto exit_free;
367 393
368 data->hwmon_dev = hwmon_device_register(&new_client->dev); 394 data->hwmon_dev = hwmon_device_register(&new_client->dev);
@@ -416,19 +442,8 @@ static struct i2c_driver lm92_driver = {
416 .address_list = normal_i2c, 442 .address_list = normal_i2c,
417}; 443};
418 444
419static int __init sensors_lm92_init(void) 445module_i2c_driver(lm92_driver);
420{
421 return i2c_add_driver(&lm92_driver);
422}
423
424static void __exit sensors_lm92_exit(void)
425{
426 i2c_del_driver(&lm92_driver);
427}
428 446
429MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); 447MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
430MODULE_DESCRIPTION("LM92/MAX6635 driver"); 448MODULE_DESCRIPTION("LM92/MAX6635 driver");
431MODULE_LICENSE("GPL"); 449MODULE_LICENSE("GPL");
432
433module_init(sensors_lm92_init);
434module_exit(sensors_lm92_exit);
diff --git a/drivers/hwmon/lm93.c b/drivers/hwmon/lm93.c
index 8bd6c5c9e05b..67e8fe256e02 100644
--- a/drivers/hwmon/lm93.c
+++ b/drivers/hwmon/lm93.c
@@ -1,42 +1,42 @@
1/* 1/*
2 lm93.c - Part of lm_sensors, Linux kernel modules for hardware monitoring 2 * lm93.c - Part of lm_sensors, Linux kernel modules for hardware monitoring
3 3 *
4 Author/Maintainer: Mark M. Hoffman <mhoffman@lightlink.com> 4 * Author/Maintainer: Mark M. Hoffman <mhoffman@lightlink.com>
5 Copyright (c) 2004 Utilitek Systems, Inc. 5 * Copyright (c) 2004 Utilitek Systems, Inc.
6 6 *
7 derived in part from lm78.c: 7 * derived in part from lm78.c:
8 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> 8 * Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
9 9 *
10 derived in part from lm85.c: 10 * derived in part from lm85.c:
11 Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com> 11 * Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
12 Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de> 12 * Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de>
13 13 *
14 derived in part from w83l785ts.c: 14 * derived in part from w83l785ts.c:
15 Copyright (c) 2003-2004 Jean Delvare <khali@linux-fr.org> 15 * Copyright (c) 2003-2004 Jean Delvare <khali@linux-fr.org>
16 16 *
17 Ported to Linux 2.6 by Eric J. Bowersox <ericb@aspsys.com> 17 * Ported to Linux 2.6 by Eric J. Bowersox <ericb@aspsys.com>
18 Copyright (c) 2005 Aspen Systems, Inc. 18 * Copyright (c) 2005 Aspen Systems, Inc.
19 19 *
20 Adapted to 2.6.20 by Carsten Emde <cbe@osadl.org> 20 * Adapted to 2.6.20 by Carsten Emde <cbe@osadl.org>
21 Copyright (c) 2006 Carsten Emde, Open Source Automation Development Lab 21 * Copyright (c) 2006 Carsten Emde, Open Source Automation Development Lab
22 22 *
23 Modified for mainline integration by Hans J. Koch <hjk@hansjkoch.de> 23 * Modified for mainline integration by Hans J. Koch <hjk@hansjkoch.de>
24 Copyright (c) 2007 Hans J. Koch, Linutronix GmbH 24 * Copyright (c) 2007 Hans J. Koch, Linutronix GmbH
25 25 *
26 This program is free software; you can redistribute it and/or modify 26 * This program is free software; you can redistribute it and/or modify
27 it under the terms of the GNU General Public License as published by 27 * it under the terms of the GNU General Public License as published by
28 the Free Software Foundation; either version 2 of the License, or 28 * the Free Software Foundation; either version 2 of the License, or
29 (at your option) any later version. 29 * (at your option) any later version.
30 30 *
31 This program is distributed in the hope that it will be useful, 31 * This program is distributed in the hope that it will be useful,
32 but WITHOUT ANY WARRANTY; without even the implied warranty of 32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 GNU General Public License for more details. 34 * GNU General Public License for more details.
35 35 *
36 You should have received a copy of the GNU General Public License 36 * You should have received a copy of the GNU General Public License
37 along with this program; if not, write to the Free Software 37 * along with this program; if not, write to the Free Software
38 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 38 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
39*/ 39 */
40 40
41#include <linux/module.h> 41#include <linux/module.h>
42#include <linux/init.h> 42#include <linux/init.h>
@@ -83,7 +83,7 @@
83#define LM93_REG_FAN_MIN(nr) (0xb4 + (nr) * 2) 83#define LM93_REG_FAN_MIN(nr) (0xb4 + (nr) * 2)
84 84
85/* pwm outputs: pwm1-pwm2 (nr => 0-1, reg => 0-3) */ 85/* pwm outputs: pwm1-pwm2 (nr => 0-1, reg => 0-3) */
86#define LM93_REG_PWM_CTL(nr,reg) (0xc8 + (reg) + (nr) * 4) 86#define LM93_REG_PWM_CTL(nr, reg) (0xc8 + (reg) + (nr) * 4)
87#define LM93_PWM_CTL1 0x0 87#define LM93_PWM_CTL1 0x0
88#define LM93_PWM_CTL2 0x1 88#define LM93_PWM_CTL2 0x1
89#define LM93_PWM_CTL3 0x2 89#define LM93_PWM_CTL3 0x2
@@ -160,7 +160,7 @@ static bool init;
160module_param(init, bool, 0); 160module_param(init, bool, 0);
161MODULE_PARM_DESC(init, "Set to non-zero to force chip initialization."); 161MODULE_PARM_DESC(init, "Set to non-zero to force chip initialization.");
162 162
163static int vccp_limit_type[2] = {0,0}; 163static int vccp_limit_type[2] = {0, 0};
164module_param_array(vccp_limit_type, int, NULL, 0); 164module_param_array(vccp_limit_type, int, NULL, 0);
165MODULE_PARM_DESC(vccp_limit_type, "Configures in7 and in8 limit modes."); 165MODULE_PARM_DESC(vccp_limit_type, "Configures in7 and in8 limit modes.");
166 166
@@ -187,8 +187,10 @@ static const struct { u8 cmd; u8 len; } lm93_block_read_cmds[12] = {
187 { 0xfd, 9 }, 187 { 0xfd, 9 },
188}; 188};
189 189
190/* ALARMS: SYSCTL format described further below 190/*
191 REG: 64 bits in 8 registers, as immediately below */ 191 * ALARMS: SYSCTL format described further below
192 * REG: 64 bits in 8 registers, as immediately below
193 */
192struct block1_t { 194struct block1_t {
193 u8 host_status_1; 195 u8 host_status_1;
194 u8 host_status_2; 196 u8 host_status_2;
@@ -217,8 +219,10 @@ struct lm93_data {
217 /* register values, arranged by block read groups */ 219 /* register values, arranged by block read groups */
218 struct block1_t block1; 220 struct block1_t block1;
219 221
220 /* temp1 - temp4: unfiltered readings 222 /*
221 temp1 - temp2: filtered readings */ 223 * temp1 - temp4: unfiltered readings
224 * temp1 - temp2: filtered readings
225 */
222 u8 block2[6]; 226 u8 block2[6];
223 227
224 /* vin1 - vin16: readings */ 228 /* vin1 - vin16: readings */
@@ -295,14 +299,18 @@ struct lm93_data {
295 u8 sfc2; 299 u8 sfc2;
296 u8 sf_tach_to_pwm; 300 u8 sf_tach_to_pwm;
297 301
298 /* The two PWM CTL2 registers can read something other than what was 302 /*
299 last written for the OVR_DC field (duty cycle override). So, we 303 * The two PWM CTL2 registers can read something other than what was
300 save the user-commanded value here. */ 304 * last written for the OVR_DC field (duty cycle override). So, we
305 * save the user-commanded value here.
306 */
301 u8 pwm_override[2]; 307 u8 pwm_override[2];
302}; 308};
303 309
304/* VID: mV 310/*
305 REG: 6-bits, right justified, *always* using Intel VRM/VRD 10 */ 311 * VID: mV
312 * REG: 6-bits, right justified, *always* using Intel VRM/VRD 10
313 */
306static int LM93_VID_FROM_REG(u8 reg) 314static int LM93_VID_FROM_REG(u8 reg)
307{ 315{
308 return vid_from_reg((reg & 0x3f), 100); 316 return vid_from_reg((reg & 0x3f), 100);
@@ -317,12 +325,13 @@ static const u8 lm93_vin_reg_max[16] = {
317 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 325 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
318 0xff, 0xfa, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd1, 326 0xff, 0xfa, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd1,
319}; 327};
320/* Values from the datasheet. They're here for documentation only. 328/*
321static const u8 lm93_vin_reg_nom[16] = { 329 * Values from the datasheet. They're here for documentation only.
322 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 330 * static const u8 lm93_vin_reg_nom[16] = {
323 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x40, 0xc0, 331 * 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
324}; 332 * 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x40, 0xc0,
325*/ 333 * };
334 */
326 335
327/* min, max, and nominal voltage readings, per channel (mV)*/ 336/* min, max, and nominal voltage readings, per channel (mV)*/
328static const unsigned long lm93_vin_val_min[16] = { 337static const unsigned long lm93_vin_val_min[16] = {
@@ -334,12 +343,13 @@ static const unsigned long lm93_vin_val_max[16] = {
334 1236, 1236, 1236, 1600, 2000, 2000, 1600, 1600, 343 1236, 1236, 1236, 1600, 2000, 2000, 1600, 1600,
335 4400, 6500, 3333, 2625, 1312, 1312, 1236, 3600, 344 4400, 6500, 3333, 2625, 1312, 1312, 1236, 3600,
336}; 345};
337/* Values from the datasheet. They're here for documentation only. 346/*
338static const unsigned long lm93_vin_val_nom[16] = { 347 * Values from the datasheet. They're here for documentation only.
339 927, 927, 927, 1200, 1500, 1500, 1200, 1200, 348 * static const unsigned long lm93_vin_val_nom[16] = {
340 3300, 5000, 2500, 1969, 984, 984, 309, 3300, 349 * 927, 927, 927, 1200, 1500, 1500, 1200, 1200,
341}; 350 * 3300, 5000, 2500, 1969, 984, 984, 309, 3300,
342*/ 351 * };
352 */
343 353
344static unsigned LM93_IN_FROM_REG(int nr, u8 reg) 354static unsigned LM93_IN_FROM_REG(int nr, u8 reg)
345{ 355{
@@ -353,8 +363,10 @@ static unsigned LM93_IN_FROM_REG(int nr, u8 reg)
353 return (slope * reg + intercept + 500) / 1000; 363 return (slope * reg + intercept + 500) / 1000;
354} 364}
355 365
356/* IN: mV, limits determined by channel nr 366/*
357 REG: scaling determined by channel nr */ 367 * IN: mV, limits determined by channel nr
368 * REG: scaling determined by channel nr
369 */
358static u8 LM93_IN_TO_REG(int nr, unsigned val) 370static u8 LM93_IN_TO_REG(int nr, unsigned val)
359{ 371{
360 /* range limit */ 372 /* range limit */
@@ -386,12 +398,14 @@ static unsigned LM93_IN_REL_FROM_REG(u8 reg, int upper, int vid)
386 return (uV_vid + uV_offset + 5000) / 10000; 398 return (uV_vid + uV_offset + 5000) / 10000;
387} 399}
388 400
389#define LM93_IN_MIN_FROM_REG(reg,vid) LM93_IN_REL_FROM_REG(reg,0,vid) 401#define LM93_IN_MIN_FROM_REG(reg, vid) LM93_IN_REL_FROM_REG((reg), 0, (vid))
390#define LM93_IN_MAX_FROM_REG(reg,vid) LM93_IN_REL_FROM_REG(reg,1,vid) 402#define LM93_IN_MAX_FROM_REG(reg, vid) LM93_IN_REL_FROM_REG((reg), 1, (vid))
391 403
392/* vid in mV , upper == 0 indicates low limit, otherwise upper limit 404/*
393 upper also determines which nibble of the register is returned 405 * vid in mV , upper == 0 indicates low limit, otherwise upper limit
394 (the other nibble will be 0x0) */ 406 * upper also determines which nibble of the register is returned
407 * (the other nibble will be 0x0)
408 */
395static u8 LM93_IN_REL_TO_REG(unsigned val, int upper, int vid) 409static u8 LM93_IN_REL_TO_REG(unsigned val, int upper, int vid)
396{ 410{
397 long uV_offset = vid * 1000 - val * 10000; 411 long uV_offset = vid * 1000 - val * 10000;
@@ -404,22 +418,26 @@ static u8 LM93_IN_REL_TO_REG(unsigned val, int upper, int vid)
404 } 418 }
405} 419}
406 420
407/* TEMP: 1/1000 degrees C (-128C to +127C) 421/*
408 REG: 1C/bit, two's complement */ 422 * TEMP: 1/1000 degrees C (-128C to +127C)
423 * REG: 1C/bit, two's complement
424 */
409static int LM93_TEMP_FROM_REG(u8 reg) 425static int LM93_TEMP_FROM_REG(u8 reg)
410{ 426{
411 return (s8)reg * 1000; 427 return (s8)reg * 1000;
412} 428}
413 429
414#define LM93_TEMP_MIN (-128000) 430#define LM93_TEMP_MIN (-128000)
415#define LM93_TEMP_MAX ( 127000) 431#define LM93_TEMP_MAX (127000)
416 432
417/* TEMP: 1/1000 degrees C (-128C to +127C) 433/*
418 REG: 1C/bit, two's complement */ 434 * TEMP: 1/1000 degrees C (-128C to +127C)
435 * REG: 1C/bit, two's complement
436 */
419static u8 LM93_TEMP_TO_REG(long temp) 437static u8 LM93_TEMP_TO_REG(long temp)
420{ 438{
421 int ntemp = SENSORS_LIMIT(temp, LM93_TEMP_MIN, LM93_TEMP_MAX); 439 int ntemp = SENSORS_LIMIT(temp, LM93_TEMP_MIN, LM93_TEMP_MAX);
422 ntemp += (ntemp<0 ? -500 : 500); 440 ntemp += (ntemp < 0 ? -500 : 500);
423 return (u8)(ntemp / 1000); 441 return (u8)(ntemp / 1000);
424} 442}
425 443
@@ -430,21 +448,25 @@ static int LM93_TEMP_OFFSET_MODE_FROM_REG(u8 sfc2, int nr)
430 return sfc2 & (nr < 2 ? 0x10 : 0x20); 448 return sfc2 & (nr < 2 ? 0x10 : 0x20);
431} 449}
432 450
433/* This function is common to all 4-bit temperature offsets 451/*
434 reg is 4 bits right justified 452 * This function is common to all 4-bit temperature offsets
435 mode 0 => 1C/bit, mode !0 => 0.5C/bit */ 453 * reg is 4 bits right justified
454 * mode 0 => 1C/bit, mode !0 => 0.5C/bit
455 */
436static int LM93_TEMP_OFFSET_FROM_REG(u8 reg, int mode) 456static int LM93_TEMP_OFFSET_FROM_REG(u8 reg, int mode)
437{ 457{
438 return (reg & 0x0f) * (mode ? 5 : 10); 458 return (reg & 0x0f) * (mode ? 5 : 10);
439} 459}
440 460
441#define LM93_TEMP_OFFSET_MIN ( 0) 461#define LM93_TEMP_OFFSET_MIN (0)
442#define LM93_TEMP_OFFSET_MAX0 (150) 462#define LM93_TEMP_OFFSET_MAX0 (150)
443#define LM93_TEMP_OFFSET_MAX1 ( 75) 463#define LM93_TEMP_OFFSET_MAX1 (75)
444 464
445/* This function is common to all 4-bit temperature offsets 465/*
446 returns 4 bits right justified 466 * This function is common to all 4-bit temperature offsets
447 mode 0 => 1C/bit, mode !0 => 0.5C/bit */ 467 * returns 4 bits right justified
468 * mode 0 => 1C/bit, mode !0 => 0.5C/bit
469 */
448static u8 LM93_TEMP_OFFSET_TO_REG(int off, int mode) 470static u8 LM93_TEMP_OFFSET_TO_REG(int off, int mode)
449{ 471{
450 int factor = mode ? 5 : 10; 472 int factor = mode ? 5 : 10;
@@ -466,9 +488,11 @@ static int LM93_TEMP_AUTO_OFFSET_FROM_REG(u8 reg, int nr, int mode)
466 return LM93_TEMP_OFFSET_FROM_REG(reg >> 4 & 0x0f, mode); 488 return LM93_TEMP_OFFSET_FROM_REG(reg >> 4 & 0x0f, mode);
467} 489}
468 490
469/* TEMP: 1/10 degrees C (0C to +15C (mode 0) or +7.5C (mode non-zero)) 491/*
470 REG: 1.0C/bit (mode 0) or 0.5C/bit (mode non-zero) 492 * TEMP: 1/10 degrees C (0C to +15C (mode 0) or +7.5C (mode non-zero))
471 0 <= nr <= 3 */ 493 * REG: 1.0C/bit (mode 0) or 0.5C/bit (mode non-zero)
494 * 0 <= nr <= 3
495 */
472static u8 LM93_TEMP_AUTO_OFFSET_TO_REG(u8 old, int off, int nr, int mode) 496static u8 LM93_TEMP_AUTO_OFFSET_TO_REG(u8 old, int off, int nr, int mode)
473{ 497{
474 u8 new = LM93_TEMP_OFFSET_TO_REG(off, mode); 498 u8 new = LM93_TEMP_OFFSET_TO_REG(off, mode);
@@ -532,9 +556,12 @@ static u8 LM93_AUTO_BOOST_HYST_TO_REG(struct lm93_data *data, long hyst,
532 return reg; 556 return reg;
533} 557}
534 558
535/* PWM: 0-255 per sensors documentation 559/*
536 REG: 0-13 as mapped below... right justified */ 560 * PWM: 0-255 per sensors documentation
537typedef enum { LM93_PWM_MAP_HI_FREQ, LM93_PWM_MAP_LO_FREQ } pwm_freq_t; 561 * REG: 0-13 as mapped below... right justified
562 */
563enum pwm_freq { LM93_PWM_MAP_HI_FREQ, LM93_PWM_MAP_LO_FREQ };
564
538static int lm93_pwm_map[2][16] = { 565static int lm93_pwm_map[2][16] = {
539 { 566 {
540 0x00, /* 0.00% */ 0x40, /* 25.00% */ 567 0x00, /* 0.00% */ 0x40, /* 25.00% */
@@ -558,13 +585,13 @@ static int lm93_pwm_map[2][16] = {
558 }, 585 },
559}; 586};
560 587
561static int LM93_PWM_FROM_REG(u8 reg, pwm_freq_t freq) 588static int LM93_PWM_FROM_REG(u8 reg, enum pwm_freq freq)
562{ 589{
563 return lm93_pwm_map[freq][reg & 0x0f]; 590 return lm93_pwm_map[freq][reg & 0x0f];
564} 591}
565 592
566/* round up to nearest match */ 593/* round up to nearest match */
567static u8 LM93_PWM_TO_REG(int pwm, pwm_freq_t freq) 594static u8 LM93_PWM_TO_REG(int pwm, enum pwm_freq freq)
568{ 595{
569 int i; 596 int i;
570 for (i = 0; i < 13; i++) 597 for (i = 0; i < 13; i++)
@@ -578,7 +605,7 @@ static u8 LM93_PWM_TO_REG(int pwm, pwm_freq_t freq)
578static int LM93_FAN_FROM_REG(u16 regs) 605static int LM93_FAN_FROM_REG(u16 regs)
579{ 606{
580 const u16 count = le16_to_cpu(regs) >> 2; 607 const u16 count = le16_to_cpu(regs) >> 2;
581 return count==0 ? -1 : count==0x3fff ? 0: 1350000 / count; 608 return count == 0 ? -1 : count == 0x3fff ? 0 : 1350000 / count;
582} 609}
583 610
584/* 611/*
@@ -600,8 +627,10 @@ static u16 LM93_FAN_TO_REG(long rpm)
600 return cpu_to_le16(regs); 627 return cpu_to_le16(regs);
601} 628}
602 629
603/* PWM FREQ: HZ 630/*
604 REG: 0-7 as mapped below */ 631 * PWM FREQ: HZ
632 * REG: 0-7 as mapped below
633 */
605static int lm93_pwm_freq_map[8] = { 634static int lm93_pwm_freq_map[8] = {
606 22500, 96, 84, 72, 60, 48, 36, 12 635 22500, 96, 84, 72, 60, 48, 36, 12
607}; 636};
@@ -623,8 +652,10 @@ static u8 LM93_PWM_FREQ_TO_REG(int freq)
623 return (u8)i; 652 return (u8)i;
624} 653}
625 654
626/* TIME: 1/100 seconds 655/*
627 * REG: 0-7 as mapped below */ 656 * TIME: 1/100 seconds
657 * REG: 0-7 as mapped below
658 */
628static int lm93_spinup_time_map[8] = { 659static int lm93_spinup_time_map[8] = {
629 0, 10, 25, 40, 70, 100, 200, 400, 660 0, 10, 25, 40, 70, 100, 200, 400,
630}; 661};
@@ -654,24 +685,30 @@ static int LM93_RAMP_FROM_REG(u8 reg)
654 return (reg & 0x0f) * 5; 685 return (reg & 0x0f) * 5;
655} 686}
656 687
657/* RAMP: 1/100 seconds 688/*
658 REG: 50mS/bit 4-bits right justified */ 689 * RAMP: 1/100 seconds
690 * REG: 50mS/bit 4-bits right justified
691 */
659static u8 LM93_RAMP_TO_REG(int ramp) 692static u8 LM93_RAMP_TO_REG(int ramp)
660{ 693{
661 ramp = SENSORS_LIMIT(ramp, LM93_RAMP_MIN, LM93_RAMP_MAX); 694 ramp = SENSORS_LIMIT(ramp, LM93_RAMP_MIN, LM93_RAMP_MAX);
662 return (u8)((ramp + 2) / 5); 695 return (u8)((ramp + 2) / 5);
663} 696}
664 697
665/* PROCHOT: 0-255, 0 => 0%, 255 => > 96.6% 698/*
666 * REG: (same) */ 699 * PROCHOT: 0-255, 0 => 0%, 255 => > 96.6%
700 * REG: (same)
701 */
667static u8 LM93_PROCHOT_TO_REG(long prochot) 702static u8 LM93_PROCHOT_TO_REG(long prochot)
668{ 703{
669 prochot = SENSORS_LIMIT(prochot, 0, 255); 704 prochot = SENSORS_LIMIT(prochot, 0, 255);
670 return (u8)prochot; 705 return (u8)prochot;
671} 706}
672 707
673/* PROCHOT-INTERVAL: 73 - 37200 (1/100 seconds) 708/*
674 * REG: 0-9 as mapped below */ 709 * PROCHOT-INTERVAL: 73 - 37200 (1/100 seconds)
710 * REG: 0-9 as mapped below
711 */
675static int lm93_interval_map[10] = { 712static int lm93_interval_map[10] = {
676 73, 146, 290, 580, 1170, 2330, 4660, 9320, 18600, 37200, 713 73, 146, 290, 580, 1170, 2330, 4660, 9320, 18600, 37200,
677}; 714};
@@ -693,22 +730,25 @@ static u8 LM93_INTERVAL_TO_REG(long interval)
693 return (u8)i; 730 return (u8)i;
694} 731}
695 732
696/* GPIO: 0-255, GPIO0 is LSB 733/*
697 * REG: inverted */ 734 * GPIO: 0-255, GPIO0 is LSB
735 * REG: inverted
736 */
698static unsigned LM93_GPI_FROM_REG(u8 reg) 737static unsigned LM93_GPI_FROM_REG(u8 reg)
699{ 738{
700 return ~reg & 0xff; 739 return ~reg & 0xff;
701} 740}
702 741
703/* alarm bitmask definitions 742/*
704 The LM93 has nearly 64 bits of error status... I've pared that down to 743 * alarm bitmask definitions
705 what I think is a useful subset in order to fit it into 32 bits. 744 * The LM93 has nearly 64 bits of error status... I've pared that down to
706 745 * what I think is a useful subset in order to fit it into 32 bits.
707 Especially note that the #VRD_HOT alarms are missing because we provide 746 *
708 that information as values in another sysfs file. 747 * Especially note that the #VRD_HOT alarms are missing because we provide
709 748 * that information as values in another sysfs file.
710 If libsensors is extended to support 64 bit values, this could be revisited. 749 *
711*/ 750 * If libsensors is extended to support 64 bit values, this could be revisited.
751 */
712#define LM93_ALARM_IN1 0x00000001 752#define LM93_ALARM_IN1 0x00000001
713#define LM93_ALARM_IN2 0x00000002 753#define LM93_ALARM_IN2 0x00000002
714#define LM93_ALARM_IN3 0x00000004 754#define LM93_ALARM_IN3 0x00000004
@@ -772,11 +812,12 @@ static u8 lm93_read_byte(struct i2c_client *client, u8 reg)
772 int value, i; 812 int value, i;
773 813
774 /* retry in case of read errors */ 814 /* retry in case of read errors */
775 for (i=1; i<=MAX_RETRIES; i++) { 815 for (i = 1; i <= MAX_RETRIES; i++) {
776 if ((value = i2c_smbus_read_byte_data(client, reg)) >= 0) { 816 value = i2c_smbus_read_byte_data(client, reg);
817 if (value >= 0) {
777 return value; 818 return value;
778 } else { 819 } else {
779 dev_warn(&client->dev,"lm93: read byte data failed, " 820 dev_warn(&client->dev, "lm93: read byte data failed, "
780 "address 0x%02x.\n", reg); 821 "address 0x%02x.\n", reg);
781 mdelay(i + 3); 822 mdelay(i + 3);
782 } 823 }
@@ -784,7 +825,7 @@ static u8 lm93_read_byte(struct i2c_client *client, u8 reg)
784 } 825 }
785 826
786 /* <TODO> what to return in case of error? */ 827 /* <TODO> what to return in case of error? */
787 dev_err(&client->dev,"lm93: All read byte retries failed!!\n"); 828 dev_err(&client->dev, "lm93: All read byte retries failed!!\n");
788 return 0; 829 return 0;
789} 830}
790 831
@@ -796,7 +837,7 @@ static int lm93_write_byte(struct i2c_client *client, u8 reg, u8 value)
796 result = i2c_smbus_write_byte_data(client, reg, value); 837 result = i2c_smbus_write_byte_data(client, reg, value);
797 838
798 if (result < 0) 839 if (result < 0)
799 dev_warn(&client->dev,"lm93: write byte data failed, " 840 dev_warn(&client->dev, "lm93: write byte data failed, "
800 "0x%02x at address 0x%02x.\n", value, reg); 841 "0x%02x at address 0x%02x.\n", value, reg);
801 842
802 return result; 843 return result;
@@ -807,11 +848,12 @@ static u16 lm93_read_word(struct i2c_client *client, u8 reg)
807 int value, i; 848 int value, i;
808 849
809 /* retry in case of read errors */ 850 /* retry in case of read errors */
810 for (i=1; i<=MAX_RETRIES; i++) { 851 for (i = 1; i <= MAX_RETRIES; i++) {
811 if ((value = i2c_smbus_read_word_data(client, reg)) >= 0) { 852 value = i2c_smbus_read_word_data(client, reg);
853 if (value >= 0) {
812 return value; 854 return value;
813 } else { 855 } else {
814 dev_warn(&client->dev,"lm93: read word data failed, " 856 dev_warn(&client->dev, "lm93: read word data failed, "
815 "address 0x%02x.\n", reg); 857 "address 0x%02x.\n", reg);
816 mdelay(i + 3); 858 mdelay(i + 3);
817 } 859 }
@@ -819,7 +861,7 @@ static u16 lm93_read_word(struct i2c_client *client, u8 reg)
819 } 861 }
820 862
821 /* <TODO> what to return in case of error? */ 863 /* <TODO> what to return in case of error? */
822 dev_err(&client->dev,"lm93: All read word retries failed!!\n"); 864 dev_err(&client->dev, "lm93: All read word retries failed!!\n");
823 return 0; 865 return 0;
824} 866}
825 867
@@ -831,7 +873,7 @@ static int lm93_write_word(struct i2c_client *client, u8 reg, u16 value)
831 result = i2c_smbus_write_word_data(client, reg, value); 873 result = i2c_smbus_write_word_data(client, reg, value);
832 874
833 if (result < 0) 875 if (result < 0)
834 dev_warn(&client->dev,"lm93: write word data failed, " 876 dev_warn(&client->dev, "lm93: write word data failed, "
835 "0x%04x at address 0x%02x.\n", value, reg); 877 "0x%04x at address 0x%02x.\n", value, reg);
836 878
837 return result; 879 return result;
@@ -840,13 +882,13 @@ static int lm93_write_word(struct i2c_client *client, u8 reg, u16 value)
840static u8 lm93_block_buffer[I2C_SMBUS_BLOCK_MAX]; 882static u8 lm93_block_buffer[I2C_SMBUS_BLOCK_MAX];
841 883
842/* 884/*
843 read block data into values, retry if not expected length 885 * read block data into values, retry if not expected length
844 fbn => index to lm93_block_read_cmds table 886 * fbn => index to lm93_block_read_cmds table
845 (Fixed Block Number - section 14.5.2 of LM93 datasheet) 887 * (Fixed Block Number - section 14.5.2 of LM93 datasheet)
846*/ 888 */
847static void lm93_read_block(struct i2c_client *client, u8 fbn, u8 *values) 889static void lm93_read_block(struct i2c_client *client, u8 fbn, u8 *values)
848{ 890{
849 int i, result=0; 891 int i, result = 0;
850 892
851 for (i = 1; i <= MAX_RETRIES; i++) { 893 for (i = 1; i <= MAX_RETRIES; i++) {
852 result = i2c_smbus_read_block_data(client, 894 result = i2c_smbus_read_block_data(client,
@@ -855,7 +897,7 @@ static void lm93_read_block(struct i2c_client *client, u8 fbn, u8 *values)
855 if (result == lm93_block_read_cmds[fbn].len) { 897 if (result == lm93_block_read_cmds[fbn].len) {
856 break; 898 break;
857 } else { 899 } else {
858 dev_warn(&client->dev,"lm93: block read data failed, " 900 dev_warn(&client->dev, "lm93: block read data failed, "
859 "command 0x%02x.\n", 901 "command 0x%02x.\n",
860 lm93_block_read_cmds[fbn].cmd); 902 lm93_block_read_cmds[fbn].cmd);
861 mdelay(i + 3); 903 mdelay(i + 3);
@@ -863,7 +905,8 @@ static void lm93_read_block(struct i2c_client *client, u8 fbn, u8 *values)
863 } 905 }
864 906
865 if (result == lm93_block_read_cmds[fbn].len) { 907 if (result == lm93_block_read_cmds[fbn].len) {
866 memcpy(values,lm93_block_buffer,lm93_block_read_cmds[fbn].len); 908 memcpy(values, lm93_block_buffer,
909 lm93_block_read_cmds[fbn].len);
867 } else { 910 } else {
868 /* <TODO> what to do in case of error? */ 911 /* <TODO> what to do in case of error? */
869 } 912 }
@@ -964,7 +1007,7 @@ static void lm93_update_client_common(struct lm93_data *data,
964static void lm93_update_client_full(struct lm93_data *data, 1007static void lm93_update_client_full(struct lm93_data *data,
965 struct i2c_client *client) 1008 struct i2c_client *client)
966{ 1009{
967 dev_dbg(&client->dev,"starting device update (block data enabled)\n"); 1010 dev_dbg(&client->dev, "starting device update (block data enabled)\n");
968 1011
969 /* in1 - in16: values & limits */ 1012 /* in1 - in16: values & limits */
970 lm93_read_block(client, 3, (u8 *)(data->block3)); 1013 lm93_read_block(client, 3, (u8 *)(data->block3));
@@ -996,10 +1039,10 @@ static void lm93_update_client_full(struct lm93_data *data,
996static void lm93_update_client_min(struct lm93_data *data, 1039static void lm93_update_client_min(struct lm93_data *data,
997 struct i2c_client *client) 1040 struct i2c_client *client)
998{ 1041{
999 int i,j; 1042 int i, j;
1000 u8 *ptr; 1043 u8 *ptr;
1001 1044
1002 dev_dbg(&client->dev,"starting device update (block data disabled)\n"); 1045 dev_dbg(&client->dev, "starting device update (block data disabled)\n");
1003 1046
1004 /* in1 - in16: values & limits */ 1047 /* in1 - in16: values & limits */
1005 for (i = 0; i < 16; i++) { 1048 for (i = 0; i < 16; i++) {
@@ -1037,7 +1080,7 @@ static void lm93_update_client_min(struct lm93_data *data,
1037 for (i = 0; i < 2; i++) { 1080 for (i = 0; i < 2; i++) {
1038 for (j = 0; j < 4; j++) { 1081 for (j = 0; j < 4; j++) {
1039 data->block9[i][j] = 1082 data->block9[i][j] =
1040 lm93_read_byte(client, LM93_REG_PWM_CTL(i,j)); 1083 lm93_read_byte(client, LM93_REG_PWM_CTL(i, j));
1041 } 1084 }
1042 } 1085 }
1043 1086
@@ -1097,14 +1140,13 @@ static ssize_t show_in_min(struct device *dev,
1097 int vccp = nr - 6; 1140 int vccp = nr - 6;
1098 long rc, vid; 1141 long rc, vid;
1099 1142
1100 if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) { 1143 if ((nr == 6 || nr == 7) && vccp_limit_type[vccp]) {
1101 vid = LM93_VID_FROM_REG(data->vid[vccp]); 1144 vid = LM93_VID_FROM_REG(data->vid[vccp]);
1102 rc = LM93_IN_MIN_FROM_REG(data->vccp_limits[vccp], vid); 1145 rc = LM93_IN_MIN_FROM_REG(data->vccp_limits[vccp], vid);
1146 } else {
1147 rc = LM93_IN_FROM_REG(nr, data->block7[nr].min);
1103 } 1148 }
1104 else { 1149 return sprintf(buf, "%ld\n", rc);
1105 rc = LM93_IN_FROM_REG(nr, data->block7[nr].min); \
1106 }
1107 return sprintf(buf, "%ld\n", rc); \
1108} 1150}
1109 1151
1110static ssize_t store_in_min(struct device *dev, struct device_attribute *attr, 1152static ssize_t store_in_min(struct device *dev, struct device_attribute *attr,
@@ -1113,20 +1155,24 @@ static ssize_t store_in_min(struct device *dev, struct device_attribute *attr,
1113 int nr = (to_sensor_dev_attr(attr))->index; 1155 int nr = (to_sensor_dev_attr(attr))->index;
1114 struct i2c_client *client = to_i2c_client(dev); 1156 struct i2c_client *client = to_i2c_client(dev);
1115 struct lm93_data *data = i2c_get_clientdata(client); 1157 struct lm93_data *data = i2c_get_clientdata(client);
1116 u32 val = simple_strtoul(buf, NULL, 10);
1117 int vccp = nr - 6; 1158 int vccp = nr - 6;
1118 long vid; 1159 long vid;
1160 unsigned long val;
1161 int err;
1162
1163 err = kstrtoul(buf, 10, &val);
1164 if (err)
1165 return err;
1119 1166
1120 mutex_lock(&data->update_lock); 1167 mutex_lock(&data->update_lock);
1121 if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) { 1168 if ((nr == 6 || nr == 7) && vccp_limit_type[vccp]) {
1122 vid = LM93_VID_FROM_REG(data->vid[vccp]); 1169 vid = LM93_VID_FROM_REG(data->vid[vccp]);
1123 data->vccp_limits[vccp] = (data->vccp_limits[vccp] & 0xf0) | 1170 data->vccp_limits[vccp] = (data->vccp_limits[vccp] & 0xf0) |
1124 LM93_IN_REL_TO_REG(val, 0, vid); 1171 LM93_IN_REL_TO_REG(val, 0, vid);
1125 lm93_write_byte(client, LM93_REG_VCCP_LIMIT_OFF(vccp), 1172 lm93_write_byte(client, LM93_REG_VCCP_LIMIT_OFF(vccp),
1126 data->vccp_limits[vccp]); 1173 data->vccp_limits[vccp]);
1127 } 1174 } else {
1128 else { 1175 data->block7[nr].min = LM93_IN_TO_REG(nr, val);
1129 data->block7[nr].min = LM93_IN_TO_REG(nr,val);
1130 lm93_write_byte(client, LM93_REG_IN_MIN(nr), 1176 lm93_write_byte(client, LM93_REG_IN_MIN(nr),
1131 data->block7[nr].min); 1177 data->block7[nr].min);
1132 } 1178 }
@@ -1175,14 +1221,13 @@ static ssize_t show_in_max(struct device *dev,
1175 int vccp = nr - 6; 1221 int vccp = nr - 6;
1176 long rc, vid; 1222 long rc, vid;
1177 1223
1178 if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) { 1224 if ((nr == 6 || nr == 7) && vccp_limit_type[vccp]) {
1179 vid = LM93_VID_FROM_REG(data->vid[vccp]); 1225 vid = LM93_VID_FROM_REG(data->vid[vccp]);
1180 rc = LM93_IN_MAX_FROM_REG(data->vccp_limits[vccp],vid); 1226 rc = LM93_IN_MAX_FROM_REG(data->vccp_limits[vccp], vid);
1181 } 1227 } else {
1182 else { 1228 rc = LM93_IN_FROM_REG(nr, data->block7[nr].max);
1183 rc = LM93_IN_FROM_REG(nr,data->block7[nr].max); \
1184 } 1229 }
1185 return sprintf(buf,"%ld\n",rc); \ 1230 return sprintf(buf, "%ld\n", rc);
1186} 1231}
1187 1232
1188static ssize_t store_in_max(struct device *dev, struct device_attribute *attr, 1233static ssize_t store_in_max(struct device *dev, struct device_attribute *attr,
@@ -1191,20 +1236,24 @@ static ssize_t store_in_max(struct device *dev, struct device_attribute *attr,
1191 int nr = (to_sensor_dev_attr(attr))->index; 1236 int nr = (to_sensor_dev_attr(attr))->index;
1192 struct i2c_client *client = to_i2c_client(dev); 1237 struct i2c_client *client = to_i2c_client(dev);
1193 struct lm93_data *data = i2c_get_clientdata(client); 1238 struct lm93_data *data = i2c_get_clientdata(client);
1194 u32 val = simple_strtoul(buf, NULL, 10);
1195 int vccp = nr - 6; 1239 int vccp = nr - 6;
1196 long vid; 1240 long vid;
1241 unsigned long val;
1242 int err;
1243
1244 err = kstrtoul(buf, 10, &val);
1245 if (err)
1246 return err;
1197 1247
1198 mutex_lock(&data->update_lock); 1248 mutex_lock(&data->update_lock);
1199 if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) { 1249 if ((nr == 6 || nr == 7) && vccp_limit_type[vccp]) {
1200 vid = LM93_VID_FROM_REG(data->vid[vccp]); 1250 vid = LM93_VID_FROM_REG(data->vid[vccp]);
1201 data->vccp_limits[vccp] = (data->vccp_limits[vccp] & 0x0f) | 1251 data->vccp_limits[vccp] = (data->vccp_limits[vccp] & 0x0f) |
1202 LM93_IN_REL_TO_REG(val, 1, vid); 1252 LM93_IN_REL_TO_REG(val, 1, vid);
1203 lm93_write_byte(client, LM93_REG_VCCP_LIMIT_OFF(vccp), 1253 lm93_write_byte(client, LM93_REG_VCCP_LIMIT_OFF(vccp),
1204 data->vccp_limits[vccp]); 1254 data->vccp_limits[vccp]);
1205 } 1255 } else {
1206 else { 1256 data->block7[nr].max = LM93_IN_TO_REG(nr, val);
1207 data->block7[nr].max = LM93_IN_TO_REG(nr,val);
1208 lm93_write_byte(client, LM93_REG_IN_MAX(nr), 1257 lm93_write_byte(client, LM93_REG_IN_MAX(nr),
1209 data->block7[nr].max); 1258 data->block7[nr].max);
1210 } 1259 }
@@ -1250,7 +1299,7 @@ static ssize_t show_temp(struct device *dev,
1250{ 1299{
1251 int nr = (to_sensor_dev_attr(attr))->index; 1300 int nr = (to_sensor_dev_attr(attr))->index;
1252 struct lm93_data *data = lm93_update_device(dev); 1301 struct lm93_data *data = lm93_update_device(dev);
1253 return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->block2[nr])); 1302 return sprintf(buf, "%d\n", LM93_TEMP_FROM_REG(data->block2[nr]));
1254} 1303}
1255 1304
1256static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); 1305static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
@@ -1262,7 +1311,7 @@ static ssize_t show_temp_min(struct device *dev,
1262{ 1311{
1263 int nr = (to_sensor_dev_attr(attr))->index; 1312 int nr = (to_sensor_dev_attr(attr))->index;
1264 struct lm93_data *data = lm93_update_device(dev); 1313 struct lm93_data *data = lm93_update_device(dev);
1265 return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->temp_lim[nr].min)); 1314 return sprintf(buf, "%d\n", LM93_TEMP_FROM_REG(data->temp_lim[nr].min));
1266} 1315}
1267 1316
1268static ssize_t store_temp_min(struct device *dev, struct device_attribute *attr, 1317static ssize_t store_temp_min(struct device *dev, struct device_attribute *attr,
@@ -1271,7 +1320,12 @@ static ssize_t store_temp_min(struct device *dev, struct device_attribute *attr,
1271 int nr = (to_sensor_dev_attr(attr))->index; 1320 int nr = (to_sensor_dev_attr(attr))->index;
1272 struct i2c_client *client = to_i2c_client(dev); 1321 struct i2c_client *client = to_i2c_client(dev);
1273 struct lm93_data *data = i2c_get_clientdata(client); 1322 struct lm93_data *data = i2c_get_clientdata(client);
1274 long val = simple_strtol(buf, NULL, 10); 1323 long val;
1324 int err;
1325
1326 err = kstrtol(buf, 10, &val);
1327 if (err)
1328 return err;
1275 1329
1276 mutex_lock(&data->update_lock); 1330 mutex_lock(&data->update_lock);
1277 data->temp_lim[nr].min = LM93_TEMP_TO_REG(val); 1331 data->temp_lim[nr].min = LM93_TEMP_TO_REG(val);
@@ -1292,7 +1346,7 @@ static ssize_t show_temp_max(struct device *dev,
1292{ 1346{
1293 int nr = (to_sensor_dev_attr(attr))->index; 1347 int nr = (to_sensor_dev_attr(attr))->index;
1294 struct lm93_data *data = lm93_update_device(dev); 1348 struct lm93_data *data = lm93_update_device(dev);
1295 return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->temp_lim[nr].max)); 1349 return sprintf(buf, "%d\n", LM93_TEMP_FROM_REG(data->temp_lim[nr].max));
1296} 1350}
1297 1351
1298static ssize_t store_temp_max(struct device *dev, struct device_attribute *attr, 1352static ssize_t store_temp_max(struct device *dev, struct device_attribute *attr,
@@ -1301,7 +1355,12 @@ static ssize_t store_temp_max(struct device *dev, struct device_attribute *attr,
1301 int nr = (to_sensor_dev_attr(attr))->index; 1355 int nr = (to_sensor_dev_attr(attr))->index;
1302 struct i2c_client *client = to_i2c_client(dev); 1356 struct i2c_client *client = to_i2c_client(dev);
1303 struct lm93_data *data = i2c_get_clientdata(client); 1357 struct lm93_data *data = i2c_get_clientdata(client);
1304 long val = simple_strtol(buf, NULL, 10); 1358 long val;
1359 int err;
1360
1361 err = kstrtol(buf, 10, &val);
1362 if (err)
1363 return err;
1305 1364
1306 mutex_lock(&data->update_lock); 1365 mutex_lock(&data->update_lock);
1307 data->temp_lim[nr].max = LM93_TEMP_TO_REG(val); 1366 data->temp_lim[nr].max = LM93_TEMP_TO_REG(val);
@@ -1322,7 +1381,7 @@ static ssize_t show_temp_auto_base(struct device *dev,
1322{ 1381{
1323 int nr = (to_sensor_dev_attr(attr))->index; 1382 int nr = (to_sensor_dev_attr(attr))->index;
1324 struct lm93_data *data = lm93_update_device(dev); 1383 struct lm93_data *data = lm93_update_device(dev);
1325 return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->block10.base[nr])); 1384 return sprintf(buf, "%d\n", LM93_TEMP_FROM_REG(data->block10.base[nr]));
1326} 1385}
1327 1386
1328static ssize_t store_temp_auto_base(struct device *dev, 1387static ssize_t store_temp_auto_base(struct device *dev,
@@ -1332,7 +1391,12 @@ static ssize_t store_temp_auto_base(struct device *dev,
1332 int nr = (to_sensor_dev_attr(attr))->index; 1391 int nr = (to_sensor_dev_attr(attr))->index;
1333 struct i2c_client *client = to_i2c_client(dev); 1392 struct i2c_client *client = to_i2c_client(dev);
1334 struct lm93_data *data = i2c_get_clientdata(client); 1393 struct lm93_data *data = i2c_get_clientdata(client);
1335 long val = simple_strtol(buf, NULL, 10); 1394 long val;
1395 int err;
1396
1397 err = kstrtol(buf, 10, &val);
1398 if (err)
1399 return err;
1336 1400
1337 mutex_lock(&data->update_lock); 1401 mutex_lock(&data->update_lock);
1338 data->block10.base[nr] = LM93_TEMP_TO_REG(val); 1402 data->block10.base[nr] = LM93_TEMP_TO_REG(val);
@@ -1349,11 +1413,11 @@ static SENSOR_DEVICE_ATTR(temp3_auto_base, S_IWUSR | S_IRUGO,
1349 show_temp_auto_base, store_temp_auto_base, 2); 1413 show_temp_auto_base, store_temp_auto_base, 2);
1350 1414
1351static ssize_t show_temp_auto_boost(struct device *dev, 1415static ssize_t show_temp_auto_boost(struct device *dev,
1352 struct device_attribute *attr,char *buf) 1416 struct device_attribute *attr, char *buf)
1353{ 1417{
1354 int nr = (to_sensor_dev_attr(attr))->index; 1418 int nr = (to_sensor_dev_attr(attr))->index;
1355 struct lm93_data *data = lm93_update_device(dev); 1419 struct lm93_data *data = lm93_update_device(dev);
1356 return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->boost[nr])); 1420 return sprintf(buf, "%d\n", LM93_TEMP_FROM_REG(data->boost[nr]));
1357} 1421}
1358 1422
1359static ssize_t store_temp_auto_boost(struct device *dev, 1423static ssize_t store_temp_auto_boost(struct device *dev,
@@ -1363,7 +1427,12 @@ static ssize_t store_temp_auto_boost(struct device *dev,
1363 int nr = (to_sensor_dev_attr(attr))->index; 1427 int nr = (to_sensor_dev_attr(attr))->index;
1364 struct i2c_client *client = to_i2c_client(dev); 1428 struct i2c_client *client = to_i2c_client(dev);
1365 struct lm93_data *data = i2c_get_clientdata(client); 1429 struct lm93_data *data = i2c_get_clientdata(client);
1366 long val = simple_strtol(buf, NULL, 10); 1430 long val;
1431 int err;
1432
1433 err = kstrtol(buf, 10, &val);
1434 if (err)
1435 return err;
1367 1436
1368 mutex_lock(&data->update_lock); 1437 mutex_lock(&data->update_lock);
1369 data->boost[nr] = LM93_TEMP_TO_REG(val); 1438 data->boost[nr] = LM93_TEMP_TO_REG(val);
@@ -1386,7 +1455,7 @@ static ssize_t show_temp_auto_boost_hyst(struct device *dev,
1386 int nr = (to_sensor_dev_attr(attr))->index; 1455 int nr = (to_sensor_dev_attr(attr))->index;
1387 struct lm93_data *data = lm93_update_device(dev); 1456 struct lm93_data *data = lm93_update_device(dev);
1388 int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); 1457 int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr);
1389 return sprintf(buf,"%d\n", 1458 return sprintf(buf, "%d\n",
1390 LM93_AUTO_BOOST_HYST_FROM_REGS(data, nr, mode)); 1459 LM93_AUTO_BOOST_HYST_FROM_REGS(data, nr, mode));
1391} 1460}
1392 1461
@@ -1397,7 +1466,12 @@ static ssize_t store_temp_auto_boost_hyst(struct device *dev,
1397 int nr = (to_sensor_dev_attr(attr))->index; 1466 int nr = (to_sensor_dev_attr(attr))->index;
1398 struct i2c_client *client = to_i2c_client(dev); 1467 struct i2c_client *client = to_i2c_client(dev);
1399 struct lm93_data *data = i2c_get_clientdata(client); 1468 struct lm93_data *data = i2c_get_clientdata(client);
1400 u32 val = simple_strtoul(buf, NULL, 10); 1469 unsigned long val;
1470 int err;
1471
1472 err = kstrtoul(buf, 10, &val);
1473 if (err)
1474 return err;
1401 1475
1402 mutex_lock(&data->update_lock); 1476 mutex_lock(&data->update_lock);
1403 /* force 0.5C/bit mode */ 1477 /* force 0.5C/bit mode */
@@ -1429,9 +1503,9 @@ static ssize_t show_temp_auto_offset(struct device *dev,
1429 int ofs = s_attr->nr; 1503 int ofs = s_attr->nr;
1430 struct lm93_data *data = lm93_update_device(dev); 1504 struct lm93_data *data = lm93_update_device(dev);
1431 int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); 1505 int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr);
1432 return sprintf(buf,"%d\n", 1506 return sprintf(buf, "%d\n",
1433 LM93_TEMP_AUTO_OFFSET_FROM_REG(data->block10.offset[ofs], 1507 LM93_TEMP_AUTO_OFFSET_FROM_REG(data->block10.offset[ofs],
1434 nr,mode)); 1508 nr, mode));
1435} 1509}
1436 1510
1437static ssize_t store_temp_auto_offset(struct device *dev, 1511static ssize_t store_temp_auto_offset(struct device *dev,
@@ -1443,7 +1517,12 @@ static ssize_t store_temp_auto_offset(struct device *dev,
1443 int ofs = s_attr->nr; 1517 int ofs = s_attr->nr;
1444 struct i2c_client *client = to_i2c_client(dev); 1518 struct i2c_client *client = to_i2c_client(dev);
1445 struct lm93_data *data = i2c_get_clientdata(client); 1519 struct lm93_data *data = i2c_get_clientdata(client);
1446 u32 val = simple_strtoul(buf, NULL, 10); 1520 unsigned long val;
1521 int err;
1522
1523 err = kstrtoul(buf, 10, &val);
1524 if (err)
1525 return err;
1447 1526
1448 mutex_lock(&data->update_lock); 1527 mutex_lock(&data->update_lock);
1449 /* force 0.5C/bit mode */ 1528 /* force 0.5C/bit mode */
@@ -1539,7 +1618,7 @@ static ssize_t show_temp_auto_pwm_min(struct device *dev,
1539 struct lm93_data *data = lm93_update_device(dev); 1618 struct lm93_data *data = lm93_update_device(dev);
1540 reg = data->auto_pwm_min_hyst[nr/2] >> 4 & 0x0f; 1619 reg = data->auto_pwm_min_hyst[nr/2] >> 4 & 0x0f;
1541 ctl4 = data->block9[nr][LM93_PWM_CTL4]; 1620 ctl4 = data->block9[nr][LM93_PWM_CTL4];
1542 return sprintf(buf,"%d\n",LM93_PWM_FROM_REG(reg, (ctl4 & 0x07) ? 1621 return sprintf(buf, "%d\n", LM93_PWM_FROM_REG(reg, (ctl4 & 0x07) ?
1543 LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ)); 1622 LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ));
1544} 1623}
1545 1624
@@ -1550,12 +1629,17 @@ static ssize_t store_temp_auto_pwm_min(struct device *dev,
1550 int nr = (to_sensor_dev_attr(attr))->index; 1629 int nr = (to_sensor_dev_attr(attr))->index;
1551 struct i2c_client *client = to_i2c_client(dev); 1630 struct i2c_client *client = to_i2c_client(dev);
1552 struct lm93_data *data = i2c_get_clientdata(client); 1631 struct lm93_data *data = i2c_get_clientdata(client);
1553 u32 val = simple_strtoul(buf, NULL, 10);
1554 u8 reg, ctl4; 1632 u8 reg, ctl4;
1633 unsigned long val;
1634 int err;
1635
1636 err = kstrtoul(buf, 10, &val);
1637 if (err)
1638 return err;
1555 1639
1556 mutex_lock(&data->update_lock); 1640 mutex_lock(&data->update_lock);
1557 reg = lm93_read_byte(client, LM93_REG_PWM_MIN_HYST(nr)); 1641 reg = lm93_read_byte(client, LM93_REG_PWM_MIN_HYST(nr));
1558 ctl4 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4)); 1642 ctl4 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL4));
1559 reg = (reg & 0x0f) | 1643 reg = (reg & 0x0f) |
1560 LM93_PWM_TO_REG(val, (ctl4 & 0x07) ? 1644 LM93_PWM_TO_REG(val, (ctl4 & 0x07) ?
1561 LM93_PWM_MAP_LO_FREQ : 1645 LM93_PWM_MAP_LO_FREQ :
@@ -1582,8 +1666,8 @@ static ssize_t show_temp_auto_offset_hyst(struct device *dev,
1582 int nr = (to_sensor_dev_attr(attr))->index; 1666 int nr = (to_sensor_dev_attr(attr))->index;
1583 struct lm93_data *data = lm93_update_device(dev); 1667 struct lm93_data *data = lm93_update_device(dev);
1584 int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); 1668 int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr);
1585 return sprintf(buf,"%d\n",LM93_TEMP_OFFSET_FROM_REG( 1669 return sprintf(buf, "%d\n", LM93_TEMP_OFFSET_FROM_REG(
1586 data->auto_pwm_min_hyst[nr/2], mode)); 1670 data->auto_pwm_min_hyst[nr / 2], mode));
1587} 1671}
1588 1672
1589static ssize_t store_temp_auto_offset_hyst(struct device *dev, 1673static ssize_t store_temp_auto_offset_hyst(struct device *dev,
@@ -1593,8 +1677,13 @@ static ssize_t store_temp_auto_offset_hyst(struct device *dev,
1593 int nr = (to_sensor_dev_attr(attr))->index; 1677 int nr = (to_sensor_dev_attr(attr))->index;
1594 struct i2c_client *client = to_i2c_client(dev); 1678 struct i2c_client *client = to_i2c_client(dev);
1595 struct lm93_data *data = i2c_get_clientdata(client); 1679 struct lm93_data *data = i2c_get_clientdata(client);
1596 u32 val = simple_strtoul(buf, NULL, 10);
1597 u8 reg; 1680 u8 reg;
1681 unsigned long val;
1682 int err;
1683
1684 err = kstrtoul(buf, 10, &val);
1685 if (err)
1686 return err;
1598 1687
1599 mutex_lock(&data->update_lock); 1688 mutex_lock(&data->update_lock);
1600 /* force 0.5C/bit mode */ 1689 /* force 0.5C/bit mode */
@@ -1626,7 +1715,7 @@ static ssize_t show_fan_input(struct device *dev,
1626 int nr = s_attr->index; 1715 int nr = s_attr->index;
1627 struct lm93_data *data = lm93_update_device(dev); 1716 struct lm93_data *data = lm93_update_device(dev);
1628 1717
1629 return sprintf(buf,"%d\n",LM93_FAN_FROM_REG(data->block5[nr])); 1718 return sprintf(buf, "%d\n", LM93_FAN_FROM_REG(data->block5[nr]));
1630} 1719}
1631 1720
1632static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input, NULL, 0); 1721static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input, NULL, 0);
@@ -1640,7 +1729,7 @@ static ssize_t show_fan_min(struct device *dev,
1640 int nr = (to_sensor_dev_attr(attr))->index; 1729 int nr = (to_sensor_dev_attr(attr))->index;
1641 struct lm93_data *data = lm93_update_device(dev); 1730 struct lm93_data *data = lm93_update_device(dev);
1642 1731
1643 return sprintf(buf,"%d\n",LM93_FAN_FROM_REG(data->block8[nr])); 1732 return sprintf(buf, "%d\n", LM93_FAN_FROM_REG(data->block8[nr]));
1644} 1733}
1645 1734
1646static ssize_t store_fan_min(struct device *dev, struct device_attribute *attr, 1735static ssize_t store_fan_min(struct device *dev, struct device_attribute *attr,
@@ -1649,11 +1738,16 @@ static ssize_t store_fan_min(struct device *dev, struct device_attribute *attr,
1649 int nr = (to_sensor_dev_attr(attr))->index; 1738 int nr = (to_sensor_dev_attr(attr))->index;
1650 struct i2c_client *client = to_i2c_client(dev); 1739 struct i2c_client *client = to_i2c_client(dev);
1651 struct lm93_data *data = i2c_get_clientdata(client); 1740 struct lm93_data *data = i2c_get_clientdata(client);
1652 u32 val = simple_strtoul(buf, NULL, 10); 1741 unsigned long val;
1742 int err;
1743
1744 err = kstrtoul(buf, 10, &val);
1745 if (err)
1746 return err;
1653 1747
1654 mutex_lock(&data->update_lock); 1748 mutex_lock(&data->update_lock);
1655 data->block8[nr] = LM93_FAN_TO_REG(val); 1749 data->block8[nr] = LM93_FAN_TO_REG(val);
1656 lm93_write_word(client,LM93_REG_FAN_MIN(nr),data->block8[nr]); 1750 lm93_write_word(client, LM93_REG_FAN_MIN(nr), data->block8[nr]);
1657 mutex_unlock(&data->update_lock); 1751 mutex_unlock(&data->update_lock);
1658 return count; 1752 return count;
1659} 1753}
@@ -1667,18 +1761,19 @@ static SENSOR_DEVICE_ATTR(fan3_min, S_IWUSR | S_IRUGO,
1667static SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO, 1761static SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO,
1668 show_fan_min, store_fan_min, 3); 1762 show_fan_min, store_fan_min, 3);
1669 1763
1670/* some tedious bit-twiddling here to deal with the register format: 1764/*
1671 1765 * some tedious bit-twiddling here to deal with the register format:
1672 data->sf_tach_to_pwm: (tach to pwm mapping bits) 1766 *
1673 1767 * data->sf_tach_to_pwm: (tach to pwm mapping bits)
1674 bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 1768 *
1675 T4:P2 T4:P1 T3:P2 T3:P1 T2:P2 T2:P1 T1:P2 T1:P1 1769 * bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
1676 1770 * T4:P2 T4:P1 T3:P2 T3:P1 T2:P2 T2:P1 T1:P2 T1:P1
1677 data->sfc2: (enable bits) 1771 *
1678 1772 * data->sfc2: (enable bits)
1679 bit | 3 | 2 | 1 | 0 1773 *
1680 T4 T3 T2 T1 1774 * bit | 3 | 2 | 1 | 0
1681*/ 1775 * T4 T3 T2 T1
1776 */
1682 1777
1683static ssize_t show_fan_smart_tach(struct device *dev, 1778static ssize_t show_fan_smart_tach(struct device *dev,
1684 struct device_attribute *attr, char *buf) 1779 struct device_attribute *attr, char *buf)
@@ -1694,11 +1789,13 @@ static ssize_t show_fan_smart_tach(struct device *dev,
1694 /* if there's a mapping and it's enabled */ 1789 /* if there's a mapping and it's enabled */
1695 if (mapping && ((data->sfc2 >> nr) & 0x01)) 1790 if (mapping && ((data->sfc2 >> nr) & 0x01))
1696 rc = mapping; 1791 rc = mapping;
1697 return sprintf(buf,"%ld\n",rc); 1792 return sprintf(buf, "%ld\n", rc);
1698} 1793}
1699 1794
1700/* helper function - must grab data->update_lock before calling 1795/*
1701 fan is 0-3, indicating fan1-fan4 */ 1796 * helper function - must grab data->update_lock before calling
1797 * fan is 0-3, indicating fan1-fan4
1798 */
1702static void lm93_write_fan_smart_tach(struct i2c_client *client, 1799static void lm93_write_fan_smart_tach(struct i2c_client *client,
1703 struct lm93_data *data, int fan, long value) 1800 struct lm93_data *data, int fan, long value)
1704{ 1801{
@@ -1724,7 +1821,12 @@ static ssize_t store_fan_smart_tach(struct device *dev,
1724 int nr = (to_sensor_dev_attr(attr))->index; 1821 int nr = (to_sensor_dev_attr(attr))->index;
1725 struct i2c_client *client = to_i2c_client(dev); 1822 struct i2c_client *client = to_i2c_client(dev);
1726 struct lm93_data *data = i2c_get_clientdata(client); 1823 struct lm93_data *data = i2c_get_clientdata(client);
1727 u32 val = simple_strtoul(buf, NULL, 10); 1824 unsigned long val;
1825 int err;
1826
1827 err = kstrtoul(buf, 10, &val);
1828 if (err)
1829 return err;
1728 1830
1729 mutex_lock(&data->update_lock); 1831 mutex_lock(&data->update_lock);
1730 /* sanity test, ignore the write otherwise */ 1832 /* sanity test, ignore the write otherwise */
@@ -1732,7 +1834,7 @@ static ssize_t store_fan_smart_tach(struct device *dev,
1732 /* can't enable if pwm freq is 22.5KHz */ 1834 /* can't enable if pwm freq is 22.5KHz */
1733 if (val) { 1835 if (val) {
1734 u8 ctl4 = lm93_read_byte(client, 1836 u8 ctl4 = lm93_read_byte(client,
1735 LM93_REG_PWM_CTL(val-1,LM93_PWM_CTL4)); 1837 LM93_REG_PWM_CTL(val - 1, LM93_PWM_CTL4));
1736 if ((ctl4 & 0x07) == 0) 1838 if ((ctl4 & 0x07) == 0)
1737 val = 0; 1839 val = 0;
1738 } 1840 }
@@ -1766,7 +1868,7 @@ static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
1766 else /* show present h/w value if manual pwm disabled */ 1868 else /* show present h/w value if manual pwm disabled */
1767 rc = LM93_PWM_FROM_REG(ctl2 >> 4, (ctl4 & 0x07) ? 1869 rc = LM93_PWM_FROM_REG(ctl2 >> 4, (ctl4 & 0x07) ?
1768 LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ); 1870 LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ);
1769 return sprintf(buf,"%ld\n",rc); 1871 return sprintf(buf, "%ld\n", rc);
1770} 1872}
1771 1873
1772static ssize_t store_pwm(struct device *dev, struct device_attribute *attr, 1874static ssize_t store_pwm(struct device *dev, struct device_attribute *attr,
@@ -1775,19 +1877,24 @@ static ssize_t store_pwm(struct device *dev, struct device_attribute *attr,
1775 int nr = (to_sensor_dev_attr(attr))->index; 1877 int nr = (to_sensor_dev_attr(attr))->index;
1776 struct i2c_client *client = to_i2c_client(dev); 1878 struct i2c_client *client = to_i2c_client(dev);
1777 struct lm93_data *data = i2c_get_clientdata(client); 1879 struct lm93_data *data = i2c_get_clientdata(client);
1778 u32 val = simple_strtoul(buf, NULL, 10);
1779 u8 ctl2, ctl4; 1880 u8 ctl2, ctl4;
1881 unsigned long val;
1882 int err;
1883
1884 err = kstrtoul(buf, 10, &val);
1885 if (err)
1886 return err;
1780 1887
1781 mutex_lock(&data->update_lock); 1888 mutex_lock(&data->update_lock);
1782 ctl2 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2)); 1889 ctl2 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL2));
1783 ctl4 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4)); 1890 ctl4 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL4));
1784 ctl2 = (ctl2 & 0x0f) | LM93_PWM_TO_REG(val,(ctl4 & 0x07) ? 1891 ctl2 = (ctl2 & 0x0f) | LM93_PWM_TO_REG(val, (ctl4 & 0x07) ?
1785 LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ) << 4; 1892 LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ) << 4;
1786 /* save user commanded value */ 1893 /* save user commanded value */
1787 data->pwm_override[nr] = LM93_PWM_FROM_REG(ctl2 >> 4, 1894 data->pwm_override[nr] = LM93_PWM_FROM_REG(ctl2 >> 4,
1788 (ctl4 & 0x07) ? LM93_PWM_MAP_LO_FREQ : 1895 (ctl4 & 0x07) ? LM93_PWM_MAP_LO_FREQ :
1789 LM93_PWM_MAP_HI_FREQ); 1896 LM93_PWM_MAP_HI_FREQ);
1790 lm93_write_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2),ctl2); 1897 lm93_write_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL2), ctl2);
1791 mutex_unlock(&data->update_lock); 1898 mutex_unlock(&data->update_lock);
1792 return count; 1899 return count;
1793} 1900}
@@ -1808,7 +1915,7 @@ static ssize_t show_pwm_enable(struct device *dev,
1808 rc = ((ctl2 & 0xF0) == 0xF0) ? 0 : 1; 1915 rc = ((ctl2 & 0xF0) == 0xF0) ? 0 : 1;
1809 else 1916 else
1810 rc = 2; 1917 rc = 2;
1811 return sprintf(buf,"%ld\n",rc); 1918 return sprintf(buf, "%ld\n", rc);
1812} 1919}
1813 1920
1814static ssize_t store_pwm_enable(struct device *dev, 1921static ssize_t store_pwm_enable(struct device *dev,
@@ -1818,26 +1925,33 @@ static ssize_t store_pwm_enable(struct device *dev,
1818 int nr = (to_sensor_dev_attr(attr))->index; 1925 int nr = (to_sensor_dev_attr(attr))->index;
1819 struct i2c_client *client = to_i2c_client(dev); 1926 struct i2c_client *client = to_i2c_client(dev);
1820 struct lm93_data *data = i2c_get_clientdata(client); 1927 struct lm93_data *data = i2c_get_clientdata(client);
1821 u32 val = simple_strtoul(buf, NULL, 10);
1822 u8 ctl2; 1928 u8 ctl2;
1929 unsigned long val;
1930 int err;
1931
1932 err = kstrtoul(buf, 10, &val);
1933 if (err)
1934 return err;
1823 1935
1824 mutex_lock(&data->update_lock); 1936 mutex_lock(&data->update_lock);
1825 ctl2 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2)); 1937 ctl2 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL2));
1826 1938
1827 switch (val) { 1939 switch (val) {
1828 case 0: 1940 case 0:
1829 ctl2 |= 0xF1; /* enable manual override, set PWM to max */ 1941 ctl2 |= 0xF1; /* enable manual override, set PWM to max */
1830 break; 1942 break;
1831 case 1: ctl2 |= 0x01; /* enable manual override */ 1943 case 1:
1944 ctl2 |= 0x01; /* enable manual override */
1832 break; 1945 break;
1833 case 2: ctl2 &= ~0x01; /* disable manual override */ 1946 case 2:
1947 ctl2 &= ~0x01; /* disable manual override */
1834 break; 1948 break;
1835 default: 1949 default:
1836 mutex_unlock(&data->update_lock); 1950 mutex_unlock(&data->update_lock);
1837 return -EINVAL; 1951 return -EINVAL;
1838 } 1952 }
1839 1953
1840 lm93_write_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2),ctl2); 1954 lm93_write_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL2), ctl2);
1841 mutex_unlock(&data->update_lock); 1955 mutex_unlock(&data->update_lock);
1842 return count; 1956 return count;
1843} 1957}
@@ -1855,12 +1969,14 @@ static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
1855 u8 ctl4; 1969 u8 ctl4;
1856 1970
1857 ctl4 = data->block9[nr][LM93_PWM_CTL4]; 1971 ctl4 = data->block9[nr][LM93_PWM_CTL4];
1858 return sprintf(buf,"%d\n",LM93_PWM_FREQ_FROM_REG(ctl4)); 1972 return sprintf(buf, "%d\n", LM93_PWM_FREQ_FROM_REG(ctl4));
1859} 1973}
1860 1974
1861/* helper function - must grab data->update_lock before calling 1975/*
1862 pwm is 0-1, indicating pwm1-pwm2 1976 * helper function - must grab data->update_lock before calling
1863 this disables smart tach for all tach channels bound to the given pwm */ 1977 * pwm is 0-1, indicating pwm1-pwm2
1978 * this disables smart tach for all tach channels bound to the given pwm
1979 */
1864static void lm93_disable_fan_smart_tach(struct i2c_client *client, 1980static void lm93_disable_fan_smart_tach(struct i2c_client *client,
1865 struct lm93_data *data, int pwm) 1981 struct lm93_data *data, int pwm)
1866{ 1982{
@@ -1887,17 +2003,22 @@ static ssize_t store_pwm_freq(struct device *dev,
1887 int nr = (to_sensor_dev_attr(attr))->index; 2003 int nr = (to_sensor_dev_attr(attr))->index;
1888 struct i2c_client *client = to_i2c_client(dev); 2004 struct i2c_client *client = to_i2c_client(dev);
1889 struct lm93_data *data = i2c_get_clientdata(client); 2005 struct lm93_data *data = i2c_get_clientdata(client);
1890 u32 val = simple_strtoul(buf, NULL, 10);
1891 u8 ctl4; 2006 u8 ctl4;
2007 unsigned long val;
2008 int err;
2009
2010 err = kstrtoul(buf, 10, &val);
2011 if (err)
2012 return err;
1892 2013
1893 mutex_lock(&data->update_lock); 2014 mutex_lock(&data->update_lock);
1894 ctl4 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4)); 2015 ctl4 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL4));
1895 ctl4 = (ctl4 & 0xf8) | LM93_PWM_FREQ_TO_REG(val); 2016 ctl4 = (ctl4 & 0xf8) | LM93_PWM_FREQ_TO_REG(val);
1896 data->block9[nr][LM93_PWM_CTL4] = ctl4; 2017 data->block9[nr][LM93_PWM_CTL4] = ctl4;
1897 /* ctl4 == 0 -> 22.5KHz -> disable smart tach */ 2018 /* ctl4 == 0 -> 22.5KHz -> disable smart tach */
1898 if (!ctl4) 2019 if (!ctl4)
1899 lm93_disable_fan_smart_tach(client, data, nr); 2020 lm93_disable_fan_smart_tach(client, data, nr);
1900 lm93_write_byte(client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4), ctl4); 2021 lm93_write_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL4), ctl4);
1901 mutex_unlock(&data->update_lock); 2022 mutex_unlock(&data->update_lock);
1902 return count; 2023 return count;
1903} 2024}
@@ -1912,7 +2033,7 @@ static ssize_t show_pwm_auto_channels(struct device *dev,
1912{ 2033{
1913 int nr = (to_sensor_dev_attr(attr))->index; 2034 int nr = (to_sensor_dev_attr(attr))->index;
1914 struct lm93_data *data = lm93_update_device(dev); 2035 struct lm93_data *data = lm93_update_device(dev);
1915 return sprintf(buf,"%d\n",data->block9[nr][LM93_PWM_CTL1]); 2036 return sprintf(buf, "%d\n", data->block9[nr][LM93_PWM_CTL1]);
1916} 2037}
1917 2038
1918static ssize_t store_pwm_auto_channels(struct device *dev, 2039static ssize_t store_pwm_auto_channels(struct device *dev,
@@ -1922,11 +2043,16 @@ static ssize_t store_pwm_auto_channels(struct device *dev,
1922 int nr = (to_sensor_dev_attr(attr))->index; 2043 int nr = (to_sensor_dev_attr(attr))->index;
1923 struct i2c_client *client = to_i2c_client(dev); 2044 struct i2c_client *client = to_i2c_client(dev);
1924 struct lm93_data *data = i2c_get_clientdata(client); 2045 struct lm93_data *data = i2c_get_clientdata(client);
1925 u32 val = simple_strtoul(buf, NULL, 10); 2046 unsigned long val;
2047 int err;
2048
2049 err = kstrtoul(buf, 10, &val);
2050 if (err)
2051 return err;
1926 2052
1927 mutex_lock(&data->update_lock); 2053 mutex_lock(&data->update_lock);
1928 data->block9[nr][LM93_PWM_CTL1] = SENSORS_LIMIT(val, 0, 255); 2054 data->block9[nr][LM93_PWM_CTL1] = SENSORS_LIMIT(val, 0, 255);
1929 lm93_write_byte(client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL1), 2055 lm93_write_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL1),
1930 data->block9[nr][LM93_PWM_CTL1]); 2056 data->block9[nr][LM93_PWM_CTL1]);
1931 mutex_unlock(&data->update_lock); 2057 mutex_unlock(&data->update_lock);
1932 return count; 2058 return count;
@@ -1938,7 +2064,7 @@ static SENSOR_DEVICE_ATTR(pwm2_auto_channels, S_IWUSR | S_IRUGO,
1938 show_pwm_auto_channels, store_pwm_auto_channels, 1); 2064 show_pwm_auto_channels, store_pwm_auto_channels, 1);
1939 2065
1940static ssize_t show_pwm_auto_spinup_min(struct device *dev, 2066static ssize_t show_pwm_auto_spinup_min(struct device *dev,
1941 struct device_attribute *attr,char *buf) 2067 struct device_attribute *attr, char *buf)
1942{ 2068{
1943 int nr = (to_sensor_dev_attr(attr))->index; 2069 int nr = (to_sensor_dev_attr(attr))->index;
1944 struct lm93_data *data = lm93_update_device(dev); 2070 struct lm93_data *data = lm93_update_device(dev);
@@ -1946,7 +2072,7 @@ static ssize_t show_pwm_auto_spinup_min(struct device *dev,
1946 2072
1947 ctl3 = data->block9[nr][LM93_PWM_CTL3]; 2073 ctl3 = data->block9[nr][LM93_PWM_CTL3];
1948 ctl4 = data->block9[nr][LM93_PWM_CTL4]; 2074 ctl4 = data->block9[nr][LM93_PWM_CTL4];
1949 return sprintf(buf,"%d\n", 2075 return sprintf(buf, "%d\n",
1950 LM93_PWM_FROM_REG(ctl3 & 0x0f, (ctl4 & 0x07) ? 2076 LM93_PWM_FROM_REG(ctl3 & 0x0f, (ctl4 & 0x07) ?
1951 LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ)); 2077 LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ));
1952} 2078}
@@ -1958,17 +2084,22 @@ static ssize_t store_pwm_auto_spinup_min(struct device *dev,
1958 int nr = (to_sensor_dev_attr(attr))->index; 2084 int nr = (to_sensor_dev_attr(attr))->index;
1959 struct i2c_client *client = to_i2c_client(dev); 2085 struct i2c_client *client = to_i2c_client(dev);
1960 struct lm93_data *data = i2c_get_clientdata(client); 2086 struct lm93_data *data = i2c_get_clientdata(client);
1961 u32 val = simple_strtoul(buf, NULL, 10);
1962 u8 ctl3, ctl4; 2087 u8 ctl3, ctl4;
2088 unsigned long val;
2089 int err;
2090
2091 err = kstrtoul(buf, 10, &val);
2092 if (err)
2093 return err;
1963 2094
1964 mutex_lock(&data->update_lock); 2095 mutex_lock(&data->update_lock);
1965 ctl3 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3)); 2096 ctl3 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3));
1966 ctl4 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL4)); 2097 ctl4 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL4));
1967 ctl3 = (ctl3 & 0xf0) | LM93_PWM_TO_REG(val, (ctl4 & 0x07) ? 2098 ctl3 = (ctl3 & 0xf0) | LM93_PWM_TO_REG(val, (ctl4 & 0x07) ?
1968 LM93_PWM_MAP_LO_FREQ : 2099 LM93_PWM_MAP_LO_FREQ :
1969 LM93_PWM_MAP_HI_FREQ); 2100 LM93_PWM_MAP_HI_FREQ);
1970 data->block9[nr][LM93_PWM_CTL3] = ctl3; 2101 data->block9[nr][LM93_PWM_CTL3] = ctl3;
1971 lm93_write_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3), ctl3); 2102 lm93_write_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3), ctl3);
1972 mutex_unlock(&data->update_lock); 2103 mutex_unlock(&data->update_lock);
1973 return count; 2104 return count;
1974} 2105}
@@ -1985,7 +2116,7 @@ static ssize_t show_pwm_auto_spinup_time(struct device *dev,
1985{ 2116{
1986 int nr = (to_sensor_dev_attr(attr))->index; 2117 int nr = (to_sensor_dev_attr(attr))->index;
1987 struct lm93_data *data = lm93_update_device(dev); 2118 struct lm93_data *data = lm93_update_device(dev);
1988 return sprintf(buf,"%d\n",LM93_SPINUP_TIME_FROM_REG( 2119 return sprintf(buf, "%d\n", LM93_SPINUP_TIME_FROM_REG(
1989 data->block9[nr][LM93_PWM_CTL3])); 2120 data->block9[nr][LM93_PWM_CTL3]));
1990} 2121}
1991 2122
@@ -1996,14 +2127,19 @@ static ssize_t store_pwm_auto_spinup_time(struct device *dev,
1996 int nr = (to_sensor_dev_attr(attr))->index; 2127 int nr = (to_sensor_dev_attr(attr))->index;
1997 struct i2c_client *client = to_i2c_client(dev); 2128 struct i2c_client *client = to_i2c_client(dev);
1998 struct lm93_data *data = i2c_get_clientdata(client); 2129 struct lm93_data *data = i2c_get_clientdata(client);
1999 u32 val = simple_strtoul(buf, NULL, 10);
2000 u8 ctl3; 2130 u8 ctl3;
2131 unsigned long val;
2132 int err;
2133
2134 err = kstrtoul(buf, 10, &val);
2135 if (err)
2136 return err;
2001 2137
2002 mutex_lock(&data->update_lock); 2138 mutex_lock(&data->update_lock);
2003 ctl3 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3)); 2139 ctl3 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3));
2004 ctl3 = (ctl3 & 0x1f) | (LM93_SPINUP_TIME_TO_REG(val) << 5 & 0xe0); 2140 ctl3 = (ctl3 & 0x1f) | (LM93_SPINUP_TIME_TO_REG(val) << 5 & 0xe0);
2005 data->block9[nr][LM93_PWM_CTL3] = ctl3; 2141 data->block9[nr][LM93_PWM_CTL3] = ctl3;
2006 lm93_write_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3), ctl3); 2142 lm93_write_byte(client, LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3), ctl3);
2007 mutex_unlock(&data->update_lock); 2143 mutex_unlock(&data->update_lock);
2008 return count; 2144 return count;
2009} 2145}
@@ -2019,7 +2155,7 @@ static ssize_t show_pwm_auto_prochot_ramp(struct device *dev,
2019 struct device_attribute *attr, char *buf) 2155 struct device_attribute *attr, char *buf)
2020{ 2156{
2021 struct lm93_data *data = lm93_update_device(dev); 2157 struct lm93_data *data = lm93_update_device(dev);
2022 return sprintf(buf,"%d\n", 2158 return sprintf(buf, "%d\n",
2023 LM93_RAMP_FROM_REG(data->pwm_ramp_ctl >> 4 & 0x0f)); 2159 LM93_RAMP_FROM_REG(data->pwm_ramp_ctl >> 4 & 0x0f));
2024} 2160}
2025 2161
@@ -2029,8 +2165,13 @@ static ssize_t store_pwm_auto_prochot_ramp(struct device *dev,
2029{ 2165{
2030 struct i2c_client *client = to_i2c_client(dev); 2166 struct i2c_client *client = to_i2c_client(dev);
2031 struct lm93_data *data = i2c_get_clientdata(client); 2167 struct lm93_data *data = i2c_get_clientdata(client);
2032 u32 val = simple_strtoul(buf, NULL, 10);
2033 u8 ramp; 2168 u8 ramp;
2169 unsigned long val;
2170 int err;
2171
2172 err = kstrtoul(buf, 10, &val);
2173 if (err)
2174 return err;
2034 2175
2035 mutex_lock(&data->update_lock); 2176 mutex_lock(&data->update_lock);
2036 ramp = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL); 2177 ramp = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL);
@@ -2048,7 +2189,7 @@ static ssize_t show_pwm_auto_vrdhot_ramp(struct device *dev,
2048 struct device_attribute *attr, char *buf) 2189 struct device_attribute *attr, char *buf)
2049{ 2190{
2050 struct lm93_data *data = lm93_update_device(dev); 2191 struct lm93_data *data = lm93_update_device(dev);
2051 return sprintf(buf,"%d\n", 2192 return sprintf(buf, "%d\n",
2052 LM93_RAMP_FROM_REG(data->pwm_ramp_ctl & 0x0f)); 2193 LM93_RAMP_FROM_REG(data->pwm_ramp_ctl & 0x0f));
2053} 2194}
2054 2195
@@ -2058,8 +2199,13 @@ static ssize_t store_pwm_auto_vrdhot_ramp(struct device *dev,
2058{ 2199{
2059 struct i2c_client *client = to_i2c_client(dev); 2200 struct i2c_client *client = to_i2c_client(dev);
2060 struct lm93_data *data = i2c_get_clientdata(client); 2201 struct lm93_data *data = i2c_get_clientdata(client);
2061 u32 val = simple_strtoul(buf, NULL, 10);
2062 u8 ramp; 2202 u8 ramp;
2203 unsigned long val;
2204 int err;
2205
2206 err = kstrtoul(buf, 10, &val);
2207 if (err)
2208 return err;
2063 2209
2064 mutex_lock(&data->update_lock); 2210 mutex_lock(&data->update_lock);
2065 ramp = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL); 2211 ramp = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL);
@@ -2078,7 +2224,7 @@ static ssize_t show_vid(struct device *dev, struct device_attribute *attr,
2078{ 2224{
2079 int nr = (to_sensor_dev_attr(attr))->index; 2225 int nr = (to_sensor_dev_attr(attr))->index;
2080 struct lm93_data *data = lm93_update_device(dev); 2226 struct lm93_data *data = lm93_update_device(dev);
2081 return sprintf(buf,"%d\n",LM93_VID_FROM_REG(data->vid[nr])); 2227 return sprintf(buf, "%d\n", LM93_VID_FROM_REG(data->vid[nr]));
2082} 2228}
2083 2229
2084static SENSOR_DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL, 0); 2230static SENSOR_DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL, 0);
@@ -2089,7 +2235,7 @@ static ssize_t show_prochot(struct device *dev, struct device_attribute *attr,
2089{ 2235{
2090 int nr = (to_sensor_dev_attr(attr))->index; 2236 int nr = (to_sensor_dev_attr(attr))->index;
2091 struct lm93_data *data = lm93_update_device(dev); 2237 struct lm93_data *data = lm93_update_device(dev);
2092 return sprintf(buf,"%d\n",data->block4[nr].cur); 2238 return sprintf(buf, "%d\n", data->block4[nr].cur);
2093} 2239}
2094 2240
2095static SENSOR_DEVICE_ATTR(prochot1, S_IRUGO, show_prochot, NULL, 0); 2241static SENSOR_DEVICE_ATTR(prochot1, S_IRUGO, show_prochot, NULL, 0);
@@ -2100,7 +2246,7 @@ static ssize_t show_prochot_avg(struct device *dev,
2100{ 2246{
2101 int nr = (to_sensor_dev_attr(attr))->index; 2247 int nr = (to_sensor_dev_attr(attr))->index;
2102 struct lm93_data *data = lm93_update_device(dev); 2248 struct lm93_data *data = lm93_update_device(dev);
2103 return sprintf(buf,"%d\n",data->block4[nr].avg); 2249 return sprintf(buf, "%d\n", data->block4[nr].avg);
2104} 2250}
2105 2251
2106static SENSOR_DEVICE_ATTR(prochot1_avg, S_IRUGO, show_prochot_avg, NULL, 0); 2252static SENSOR_DEVICE_ATTR(prochot1_avg, S_IRUGO, show_prochot_avg, NULL, 0);
@@ -2111,7 +2257,7 @@ static ssize_t show_prochot_max(struct device *dev,
2111{ 2257{
2112 int nr = (to_sensor_dev_attr(attr))->index; 2258 int nr = (to_sensor_dev_attr(attr))->index;
2113 struct lm93_data *data = lm93_update_device(dev); 2259 struct lm93_data *data = lm93_update_device(dev);
2114 return sprintf(buf,"%d\n",data->prochot_max[nr]); 2260 return sprintf(buf, "%d\n", data->prochot_max[nr]);
2115} 2261}
2116 2262
2117static ssize_t store_prochot_max(struct device *dev, 2263static ssize_t store_prochot_max(struct device *dev,
@@ -2121,7 +2267,12 @@ static ssize_t store_prochot_max(struct device *dev,
2121 int nr = (to_sensor_dev_attr(attr))->index; 2267 int nr = (to_sensor_dev_attr(attr))->index;
2122 struct i2c_client *client = to_i2c_client(dev); 2268 struct i2c_client *client = to_i2c_client(dev);
2123 struct lm93_data *data = i2c_get_clientdata(client); 2269 struct lm93_data *data = i2c_get_clientdata(client);
2124 u32 val = simple_strtoul(buf, NULL, 10); 2270 unsigned long val;
2271 int err;
2272
2273 err = kstrtoul(buf, 10, &val);
2274 if (err)
2275 return err;
2125 2276
2126 mutex_lock(&data->update_lock); 2277 mutex_lock(&data->update_lock);
2127 data->prochot_max[nr] = LM93_PROCHOT_TO_REG(val); 2278 data->prochot_max[nr] = LM93_PROCHOT_TO_REG(val);
@@ -2143,7 +2294,7 @@ static ssize_t show_prochot_override(struct device *dev,
2143{ 2294{
2144 int nr = (to_sensor_dev_attr(attr))->index; 2295 int nr = (to_sensor_dev_attr(attr))->index;
2145 struct lm93_data *data = lm93_update_device(dev); 2296 struct lm93_data *data = lm93_update_device(dev);
2146 return sprintf(buf,"%d\n", 2297 return sprintf(buf, "%d\n",
2147 (data->prochot_override & prochot_override_mask[nr]) ? 1 : 0); 2298 (data->prochot_override & prochot_override_mask[nr]) ? 1 : 0);
2148} 2299}
2149 2300
@@ -2154,7 +2305,12 @@ static ssize_t store_prochot_override(struct device *dev,
2154 int nr = (to_sensor_dev_attr(attr))->index; 2305 int nr = (to_sensor_dev_attr(attr))->index;
2155 struct i2c_client *client = to_i2c_client(dev); 2306 struct i2c_client *client = to_i2c_client(dev);
2156 struct lm93_data *data = i2c_get_clientdata(client); 2307 struct lm93_data *data = i2c_get_clientdata(client);
2157 u32 val = simple_strtoul(buf, NULL, 10); 2308 unsigned long val;
2309 int err;
2310
2311 err = kstrtoul(buf, 10, &val);
2312 if (err)
2313 return err;
2158 2314
2159 mutex_lock(&data->update_lock); 2315 mutex_lock(&data->update_lock);
2160 if (val) 2316 if (val)
@@ -2178,11 +2334,11 @@ static ssize_t show_prochot_interval(struct device *dev,
2178 int nr = (to_sensor_dev_attr(attr))->index; 2334 int nr = (to_sensor_dev_attr(attr))->index;
2179 struct lm93_data *data = lm93_update_device(dev); 2335 struct lm93_data *data = lm93_update_device(dev);
2180 u8 tmp; 2336 u8 tmp;
2181 if (nr==1) 2337 if (nr == 1)
2182 tmp = (data->prochot_interval & 0xf0) >> 4; 2338 tmp = (data->prochot_interval & 0xf0) >> 4;
2183 else 2339 else
2184 tmp = data->prochot_interval & 0x0f; 2340 tmp = data->prochot_interval & 0x0f;
2185 return sprintf(buf,"%d\n",LM93_INTERVAL_FROM_REG(tmp)); 2341 return sprintf(buf, "%d\n", LM93_INTERVAL_FROM_REG(tmp));
2186} 2342}
2187 2343
2188static ssize_t store_prochot_interval(struct device *dev, 2344static ssize_t store_prochot_interval(struct device *dev,
@@ -2192,12 +2348,17 @@ static ssize_t store_prochot_interval(struct device *dev,
2192 int nr = (to_sensor_dev_attr(attr))->index; 2348 int nr = (to_sensor_dev_attr(attr))->index;
2193 struct i2c_client *client = to_i2c_client(dev); 2349 struct i2c_client *client = to_i2c_client(dev);
2194 struct lm93_data *data = i2c_get_clientdata(client); 2350 struct lm93_data *data = i2c_get_clientdata(client);
2195 u32 val = simple_strtoul(buf, NULL, 10);
2196 u8 tmp; 2351 u8 tmp;
2352 unsigned long val;
2353 int err;
2354
2355 err = kstrtoul(buf, 10, &val);
2356 if (err)
2357 return err;
2197 2358
2198 mutex_lock(&data->update_lock); 2359 mutex_lock(&data->update_lock);
2199 tmp = lm93_read_byte(client, LM93_REG_PROCHOT_INTERVAL); 2360 tmp = lm93_read_byte(client, LM93_REG_PROCHOT_INTERVAL);
2200 if (nr==1) 2361 if (nr == 1)
2201 tmp = (tmp & 0x0f) | (LM93_INTERVAL_TO_REG(val) << 4); 2362 tmp = (tmp & 0x0f) | (LM93_INTERVAL_TO_REG(val) << 4);
2202 else 2363 else
2203 tmp = (tmp & 0xf0) | LM93_INTERVAL_TO_REG(val); 2364 tmp = (tmp & 0xf0) | LM93_INTERVAL_TO_REG(val);
@@ -2217,7 +2378,7 @@ static ssize_t show_prochot_override_duty_cycle(struct device *dev,
2217 char *buf) 2378 char *buf)
2218{ 2379{
2219 struct lm93_data *data = lm93_update_device(dev); 2380 struct lm93_data *data = lm93_update_device(dev);
2220 return sprintf(buf,"%d\n",data->prochot_override & 0x0f); 2381 return sprintf(buf, "%d\n", data->prochot_override & 0x0f);
2221} 2382}
2222 2383
2223static ssize_t store_prochot_override_duty_cycle(struct device *dev, 2384static ssize_t store_prochot_override_duty_cycle(struct device *dev,
@@ -2226,7 +2387,12 @@ static ssize_t store_prochot_override_duty_cycle(struct device *dev,
2226{ 2387{
2227 struct i2c_client *client = to_i2c_client(dev); 2388 struct i2c_client *client = to_i2c_client(dev);
2228 struct lm93_data *data = i2c_get_clientdata(client); 2389 struct lm93_data *data = i2c_get_clientdata(client);
2229 u32 val = simple_strtoul(buf, NULL, 10); 2390 unsigned long val;
2391 int err;
2392
2393 err = kstrtoul(buf, 10, &val);
2394 if (err)
2395 return err;
2230 2396
2231 mutex_lock(&data->update_lock); 2397 mutex_lock(&data->update_lock);
2232 data->prochot_override = (data->prochot_override & 0xf0) | 2398 data->prochot_override = (data->prochot_override & 0xf0) |
@@ -2245,7 +2411,7 @@ static ssize_t show_prochot_short(struct device *dev,
2245 struct device_attribute *attr, char *buf) 2411 struct device_attribute *attr, char *buf)
2246{ 2412{
2247 struct lm93_data *data = lm93_update_device(dev); 2413 struct lm93_data *data = lm93_update_device(dev);
2248 return sprintf(buf,"%d\n",(data->config & 0x10) ? 1 : 0); 2414 return sprintf(buf, "%d\n", (data->config & 0x10) ? 1 : 0);
2249} 2415}
2250 2416
2251static ssize_t store_prochot_short(struct device *dev, 2417static ssize_t store_prochot_short(struct device *dev,
@@ -2254,7 +2420,12 @@ static ssize_t store_prochot_short(struct device *dev,
2254{ 2420{
2255 struct i2c_client *client = to_i2c_client(dev); 2421 struct i2c_client *client = to_i2c_client(dev);
2256 struct lm93_data *data = i2c_get_clientdata(client); 2422 struct lm93_data *data = i2c_get_clientdata(client);
2257 u32 val = simple_strtoul(buf, NULL, 10); 2423 unsigned long val;
2424 int err;
2425
2426 err = kstrtoul(buf, 10, &val);
2427 if (err)
2428 return err;
2258 2429
2259 mutex_lock(&data->update_lock); 2430 mutex_lock(&data->update_lock);
2260 if (val) 2431 if (val)
@@ -2274,8 +2445,8 @@ static ssize_t show_vrdhot(struct device *dev, struct device_attribute *attr,
2274{ 2445{
2275 int nr = (to_sensor_dev_attr(attr))->index; 2446 int nr = (to_sensor_dev_attr(attr))->index;
2276 struct lm93_data *data = lm93_update_device(dev); 2447 struct lm93_data *data = lm93_update_device(dev);
2277 return sprintf(buf,"%d\n", 2448 return sprintf(buf, "%d\n",
2278 data->block1.host_status_1 & (1 << (nr+4)) ? 1 : 0); 2449 data->block1.host_status_1 & (1 << (nr + 4)) ? 1 : 0);
2279} 2450}
2280 2451
2281static SENSOR_DEVICE_ATTR(vrdhot1, S_IRUGO, show_vrdhot, NULL, 0); 2452static SENSOR_DEVICE_ATTR(vrdhot1, S_IRUGO, show_vrdhot, NULL, 0);
@@ -2285,7 +2456,7 @@ static ssize_t show_gpio(struct device *dev, struct device_attribute *attr,
2285 char *buf) 2456 char *buf)
2286{ 2457{
2287 struct lm93_data *data = lm93_update_device(dev); 2458 struct lm93_data *data = lm93_update_device(dev);
2288 return sprintf(buf,"%d\n",LM93_GPI_FROM_REG(data->gpi)); 2459 return sprintf(buf, "%d\n", LM93_GPI_FROM_REG(data->gpi));
2289} 2460}
2290 2461
2291static DEVICE_ATTR(gpio, S_IRUGO, show_gpio, NULL); 2462static DEVICE_ATTR(gpio, S_IRUGO, show_gpio, NULL);
@@ -2294,7 +2465,7 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
2294 char *buf) 2465 char *buf)
2295{ 2466{
2296 struct lm93_data *data = lm93_update_device(dev); 2467 struct lm93_data *data = lm93_update_device(dev);
2297 return sprintf(buf,"%d\n",LM93_ALARMS_FROM_REG(data->block1)); 2468 return sprintf(buf, "%d\n", LM93_ALARMS_FROM_REG(data->block1));
2298} 2469}
2299 2470
2300static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 2471static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
@@ -2494,13 +2665,13 @@ static void lm93_init_client(struct i2c_client *client)
2494 lm93_write_byte(client, LM93_REG_CONFIG, reg | 0x01); 2665 lm93_write_byte(client, LM93_REG_CONFIG, reg | 0x01);
2495 2666
2496 /* spin until ready */ 2667 /* spin until ready */
2497 for (i=0; i<20; i++) { 2668 for (i = 0; i < 20; i++) {
2498 msleep(10); 2669 msleep(10);
2499 if ((lm93_read_byte(client, LM93_REG_CONFIG) & 0x80) == 0x80) 2670 if ((lm93_read_byte(client, LM93_REG_CONFIG) & 0x80) == 0x80)
2500 return; 2671 return;
2501 } 2672 }
2502 2673
2503 dev_warn(&client->dev,"timed out waiting for sensor " 2674 dev_warn(&client->dev, "timed out waiting for sensor "
2504 "chip to signal ready!\n"); 2675 "chip to signal ready!\n");
2505} 2676}
2506 2677
@@ -2540,7 +2711,7 @@ static int lm93_detect(struct i2c_client *client, struct i2c_board_info *info)
2540 } 2711 }
2541 2712
2542 strlcpy(info->type, name, I2C_NAME_SIZE); 2713 strlcpy(info->type, name, I2C_NAME_SIZE);
2543 dev_dbg(&adapter->dev,"loading %s at %d,0x%02x\n", 2714 dev_dbg(&adapter->dev, "loading %s at %d, 0x%02x\n",
2544 client->name, i2c_adapter_id(client->adapter), 2715 client->name, i2c_adapter_id(client->adapter),
2545 client->addr); 2716 client->addr);
2546 2717
@@ -2593,7 +2764,7 @@ static int lm93_probe(struct i2c_client *client,
2593 2764
2594 /* Register hwmon driver class */ 2765 /* Register hwmon driver class */
2595 data->hwmon_dev = hwmon_device_register(&client->dev); 2766 data->hwmon_dev = hwmon_device_register(&client->dev);
2596 if ( !IS_ERR(data->hwmon_dev)) 2767 if (!IS_ERR(data->hwmon_dev))
2597 return 0; 2768 return 0;
2598 2769
2599 err = PTR_ERR(data->hwmon_dev); 2770 err = PTR_ERR(data->hwmon_dev);
@@ -2635,20 +2806,9 @@ static struct i2c_driver lm93_driver = {
2635 .address_list = normal_i2c, 2806 .address_list = normal_i2c,
2636}; 2807};
2637 2808
2638static int __init lm93_init(void) 2809module_i2c_driver(lm93_driver);
2639{
2640 return i2c_add_driver(&lm93_driver);
2641}
2642
2643static void __exit lm93_exit(void)
2644{
2645 i2c_del_driver(&lm93_driver);
2646}
2647 2810
2648MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>, " 2811MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>, "
2649 "Hans J. Koch <hjk@hansjkoch.de>"); 2812 "Hans J. Koch <hjk@hansjkoch.de>");
2650MODULE_DESCRIPTION("LM93 driver"); 2813MODULE_DESCRIPTION("LM93 driver");
2651MODULE_LICENSE("GPL"); 2814MODULE_LICENSE("GPL");
2652
2653module_init(lm93_init);
2654module_exit(lm93_exit);
diff --git a/drivers/hwmon/lm95241.c b/drivers/hwmon/lm95241.c
index 70bca671e083..bd8cdb7b96ed 100644
--- a/drivers/hwmon/lm95241.c
+++ b/drivers/hwmon/lm95241.c
@@ -455,19 +455,8 @@ static struct i2c_driver lm95241_driver = {
455 .address_list = normal_i2c, 455 .address_list = normal_i2c,
456}; 456};
457 457
458static int __init sensors_lm95241_init(void) 458module_i2c_driver(lm95241_driver);
459{
460 return i2c_add_driver(&lm95241_driver);
461}
462
463static void __exit sensors_lm95241_exit(void)
464{
465 i2c_del_driver(&lm95241_driver);
466}
467 459
468MODULE_AUTHOR("Davide Rizzo <elpa.rizzo@gmail.com>"); 460MODULE_AUTHOR("Davide Rizzo <elpa.rizzo@gmail.com>");
469MODULE_DESCRIPTION("LM95241 sensor driver"); 461MODULE_DESCRIPTION("LM95241 sensor driver");
470MODULE_LICENSE("GPL"); 462MODULE_LICENSE("GPL");
471
472module_init(sensors_lm95241_init);
473module_exit(sensors_lm95241_exit);
diff --git a/drivers/hwmon/lm95245.c b/drivers/hwmon/lm95245.c
index 5e5fc1b0ace1..9a46c106a240 100644
--- a/drivers/hwmon/lm95245.c
+++ b/drivers/hwmon/lm95245.c
@@ -525,19 +525,8 @@ static struct i2c_driver lm95245_driver = {
525 .address_list = normal_i2c, 525 .address_list = normal_i2c,
526}; 526};
527 527
528static int __init sensors_lm95245_init(void) 528module_i2c_driver(lm95245_driver);
529{
530 return i2c_add_driver(&lm95245_driver);
531}
532
533static void __exit sensors_lm95245_exit(void)
534{
535 i2c_del_driver(&lm95245_driver);
536}
537 529
538MODULE_AUTHOR("Alexander Stein <alexander.stein@systec-electronic.com>"); 530MODULE_AUTHOR("Alexander Stein <alexander.stein@systec-electronic.com>");
539MODULE_DESCRIPTION("LM95245 sensor driver"); 531MODULE_DESCRIPTION("LM95245 sensor driver");
540MODULE_LICENSE("GPL"); 532MODULE_LICENSE("GPL");
541
542module_init(sensors_lm95245_init);
543module_exit(sensors_lm95245_exit);
diff --git a/drivers/hwmon/ltc4151.c b/drivers/hwmon/ltc4151.c
index 4ac06b75aa60..4d005b219de2 100644
--- a/drivers/hwmon/ltc4151.c
+++ b/drivers/hwmon/ltc4151.c
@@ -154,7 +154,8 @@ static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, \
154static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, \ 154static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, \
155 ltc4151_show_value, NULL, LTC4151_SENSE_H); 155 ltc4151_show_value, NULL, LTC4151_SENSE_H);
156 156
157/* Finally, construct an array of pointers to members of the above objects, 157/*
158 * Finally, construct an array of pointers to members of the above objects,
158 * as required for sysfs_create_group() 159 * as required for sysfs_create_group()
159 */ 160 */
160static struct attribute *ltc4151_attributes[] = { 161static struct attribute *ltc4151_attributes[] = {
@@ -238,19 +239,8 @@ static struct i2c_driver ltc4151_driver = {
238 .id_table = ltc4151_id, 239 .id_table = ltc4151_id,
239}; 240};
240 241
241static int __init ltc4151_init(void) 242module_i2c_driver(ltc4151_driver);
242{
243 return i2c_add_driver(&ltc4151_driver);
244}
245
246static void __exit ltc4151_exit(void)
247{
248 i2c_del_driver(&ltc4151_driver);
249}
250 243
251MODULE_AUTHOR("Per Dalen <per.dalen@appeartv.com>"); 244MODULE_AUTHOR("Per Dalen <per.dalen@appeartv.com>");
252MODULE_DESCRIPTION("LTC4151 driver"); 245MODULE_DESCRIPTION("LTC4151 driver");
253MODULE_LICENSE("GPL"); 246MODULE_LICENSE("GPL");
254
255module_init(ltc4151_init);
256module_exit(ltc4151_exit);
diff --git a/drivers/hwmon/ltc4215.c b/drivers/hwmon/ltc4215.c
index c7e6d8e81656..429c5b2b66fd 100644
--- a/drivers/hwmon/ltc4215.c
+++ b/drivers/hwmon/ltc4215.c
@@ -91,8 +91,10 @@ static int ltc4215_get_voltage(struct device *dev, u8 reg)
91 voltage = regval * 605 / 10; 91 voltage = regval * 605 / 10;
92 break; 92 break;
93 case LTC4215_ADIN: 93 case LTC4215_ADIN:
94 /* The ADIN input is divided by 12.5, and has 4.82 mV 94 /*
95 * per increment, so we have the additional multiply */ 95 * The ADIN input is divided by 12.5, and has 4.82 mV
96 * per increment, so we have the additional multiply
97 */
96 voltage = regval * 482 * 125 / 1000; 98 voltage = regval * 482 * 125 / 1000;
97 break; 99 break;
98 default: 100 default:
@@ -109,7 +111,8 @@ static unsigned int ltc4215_get_current(struct device *dev)
109{ 111{
110 struct ltc4215_data *data = ltc4215_update_device(dev); 112 struct ltc4215_data *data = ltc4215_update_device(dev);
111 113
112 /* The strange looking conversions that follow are fixed-point 114 /*
115 * The strange looking conversions that follow are fixed-point
113 * math, since we cannot do floating point in the kernel. 116 * math, since we cannot do floating point in the kernel.
114 * 117 *
115 * Step 1: convert sense register to microVolts 118 * Step 1: convert sense register to microVolts
@@ -176,7 +179,8 @@ static ssize_t ltc4215_show_alarm(struct device *dev,
176 return snprintf(buf, PAGE_SIZE, "%u\n", (reg & mask) ? 1 : 0); 179 return snprintf(buf, PAGE_SIZE, "%u\n", (reg & mask) ? 1 : 0);
177} 180}
178 181
179/* These macros are used below in constructing device attribute objects 182/*
183 * These macros are used below in constructing device attribute objects
180 * for use with sysfs_create_group() to make a sysfs device file 184 * for use with sysfs_create_group() to make a sysfs device file
181 * for each register. 185 * for each register.
182 */ 186 */
@@ -215,7 +219,8 @@ LTC4215_ALARM(in1_min_alarm, (1 << 1), LTC4215_STATUS);
215LTC4215_VOLTAGE(in2_input, LTC4215_SOURCE); 219LTC4215_VOLTAGE(in2_input, LTC4215_SOURCE);
216LTC4215_ALARM(in2_min_alarm, (1 << 3), LTC4215_STATUS); 220LTC4215_ALARM(in2_min_alarm, (1 << 3), LTC4215_STATUS);
217 221
218/* Finally, construct an array of pointers to members of the above objects, 222/*
223 * Finally, construct an array of pointers to members of the above objects,
219 * as required for sysfs_create_group() 224 * as required for sysfs_create_group()
220 */ 225 */
221static struct attribute *ltc4215_attributes[] = { 226static struct attribute *ltc4215_attributes[] = {
@@ -309,19 +314,8 @@ static struct i2c_driver ltc4215_driver = {
309 .id_table = ltc4215_id, 314 .id_table = ltc4215_id,
310}; 315};
311 316
312static int __init ltc4215_init(void) 317module_i2c_driver(ltc4215_driver);
313{
314 return i2c_add_driver(&ltc4215_driver);
315}
316
317static void __exit ltc4215_exit(void)
318{
319 i2c_del_driver(&ltc4215_driver);
320}
321 318
322MODULE_AUTHOR("Ira W. Snyder <iws@ovro.caltech.edu>"); 319MODULE_AUTHOR("Ira W. Snyder <iws@ovro.caltech.edu>");
323MODULE_DESCRIPTION("LTC4215 driver"); 320MODULE_DESCRIPTION("LTC4215 driver");
324MODULE_LICENSE("GPL"); 321MODULE_LICENSE("GPL");
325
326module_init(ltc4215_init);
327module_exit(ltc4215_exit);
diff --git a/drivers/hwmon/ltc4245.c b/drivers/hwmon/ltc4245.c
index 659308329308..b99b45bafdad 100644
--- a/drivers/hwmon/ltc4245.c
+++ b/drivers/hwmon/ltc4245.c
@@ -214,7 +214,8 @@ static unsigned int ltc4245_get_current(struct device *dev, u8 reg)
214 unsigned int voltage; 214 unsigned int voltage;
215 unsigned int curr; 215 unsigned int curr;
216 216
217 /* The strange looking conversions that follow are fixed-point 217 /*
218 * The strange looking conversions that follow are fixed-point
218 * math, since we cannot do floating point in the kernel. 219 * math, since we cannot do floating point in the kernel.
219 * 220 *
220 * Step 1: convert sense register to microVolts 221 * Step 1: convert sense register to microVolts
@@ -317,7 +318,8 @@ static ssize_t ltc4245_show_gpio(struct device *dev,
317 return snprintf(buf, PAGE_SIZE, "%u\n", val * 10); 318 return snprintf(buf, PAGE_SIZE, "%u\n", val * 10);
318} 319}
319 320
320/* These macros are used below in constructing device attribute objects 321/*
322 * These macros are used below in constructing device attribute objects
321 * for use with sysfs_create_group() to make a sysfs device file 323 * for use with sysfs_create_group() to make a sysfs device file
322 * for each register. 324 * for each register.
323 */ 325 */
@@ -391,7 +393,8 @@ LTC4245_POWER(power2_input, LTC4245_5VSENSE);
391LTC4245_POWER(power3_input, LTC4245_3VSENSE); 393LTC4245_POWER(power3_input, LTC4245_3VSENSE);
392LTC4245_POWER(power4_input, LTC4245_VEESENSE); 394LTC4245_POWER(power4_input, LTC4245_VEESENSE);
393 395
394/* Finally, construct an array of pointers to members of the above objects, 396/*
397 * Finally, construct an array of pointers to members of the above objects,
395 * as required for sysfs_create_group() 398 * as required for sysfs_create_group()
396 */ 399 */
397static struct attribute *ltc4245_std_attributes[] = { 400static struct attribute *ltc4245_std_attributes[] = {
@@ -578,19 +581,8 @@ static struct i2c_driver ltc4245_driver = {
578 .id_table = ltc4245_id, 581 .id_table = ltc4245_id,
579}; 582};
580 583
581static int __init ltc4245_init(void) 584module_i2c_driver(ltc4245_driver);
582{
583 return i2c_add_driver(&ltc4245_driver);
584}
585
586static void __exit ltc4245_exit(void)
587{
588 i2c_del_driver(&ltc4245_driver);
589}
590 585
591MODULE_AUTHOR("Ira W. Snyder <iws@ovro.caltech.edu>"); 586MODULE_AUTHOR("Ira W. Snyder <iws@ovro.caltech.edu>");
592MODULE_DESCRIPTION("LTC4245 driver"); 587MODULE_DESCRIPTION("LTC4245 driver");
593MODULE_LICENSE("GPL"); 588MODULE_LICENSE("GPL");
594
595module_init(ltc4245_init);
596module_exit(ltc4245_exit);
diff --git a/drivers/hwmon/ltc4261.c b/drivers/hwmon/ltc4261.c
index ce5235560f01..069b7d34d8f9 100644
--- a/drivers/hwmon/ltc4261.c
+++ b/drivers/hwmon/ltc4261.c
@@ -235,11 +235,9 @@ static int ltc4261_probe(struct i2c_client *client,
235 return -ENODEV; 235 return -ENODEV;
236 } 236 }
237 237
238 data = kzalloc(sizeof(*data), GFP_KERNEL); 238 data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
239 if (!data) { 239 if (!data)
240 ret = -ENOMEM; 240 return -ENOMEM;
241 goto out_kzalloc;
242 }
243 241
244 i2c_set_clientdata(client, data); 242 i2c_set_clientdata(client, data);
245 mutex_init(&data->update_lock); 243 mutex_init(&data->update_lock);
@@ -250,7 +248,7 @@ static int ltc4261_probe(struct i2c_client *client,
250 /* Register sysfs hooks */ 248 /* Register sysfs hooks */
251 ret = sysfs_create_group(&client->dev.kobj, &ltc4261_group); 249 ret = sysfs_create_group(&client->dev.kobj, &ltc4261_group);
252 if (ret) 250 if (ret)
253 goto out_sysfs_create_group; 251 return ret;
254 252
255 data->hwmon_dev = hwmon_device_register(&client->dev); 253 data->hwmon_dev = hwmon_device_register(&client->dev);
256 if (IS_ERR(data->hwmon_dev)) { 254 if (IS_ERR(data->hwmon_dev)) {
@@ -262,9 +260,6 @@ static int ltc4261_probe(struct i2c_client *client,
262 260
263out_hwmon_device_register: 261out_hwmon_device_register:
264 sysfs_remove_group(&client->dev.kobj, &ltc4261_group); 262 sysfs_remove_group(&client->dev.kobj, &ltc4261_group);
265out_sysfs_create_group:
266 kfree(data);
267out_kzalloc:
268 return ret; 263 return ret;
269} 264}
270 265
@@ -275,8 +270,6 @@ static int ltc4261_remove(struct i2c_client *client)
275 hwmon_device_unregister(data->hwmon_dev); 270 hwmon_device_unregister(data->hwmon_dev);
276 sysfs_remove_group(&client->dev.kobj, &ltc4261_group); 271 sysfs_remove_group(&client->dev.kobj, &ltc4261_group);
277 272
278 kfree(data);
279
280 return 0; 273 return 0;
281} 274}
282 275
@@ -297,19 +290,8 @@ static struct i2c_driver ltc4261_driver = {
297 .id_table = ltc4261_id, 290 .id_table = ltc4261_id,
298}; 291};
299 292
300static int __init ltc4261_init(void) 293module_i2c_driver(ltc4261_driver);
301{
302 return i2c_add_driver(&ltc4261_driver);
303}
304
305static void __exit ltc4261_exit(void)
306{
307 i2c_del_driver(&ltc4261_driver);
308}
309 294
310MODULE_AUTHOR("Guenter Roeck <guenter.roeck@ericsson.com>"); 295MODULE_AUTHOR("Guenter Roeck <guenter.roeck@ericsson.com>");
311MODULE_DESCRIPTION("LTC4261 driver"); 296MODULE_DESCRIPTION("LTC4261 driver");
312MODULE_LICENSE("GPL"); 297MODULE_LICENSE("GPL");
313
314module_init(ltc4261_init);
315module_exit(ltc4261_exit);
diff --git a/drivers/hwmon/max1111.c b/drivers/hwmon/max1111.c
index 482ca901db30..362a40eb6129 100644
--- a/drivers/hwmon/max1111.c
+++ b/drivers/hwmon/max1111.c
@@ -106,7 +106,8 @@ static ssize_t show_adc(struct device *dev,
106 if (ret < 0) 106 if (ret < 0)
107 return ret; 107 return ret;
108 108
109 /* assume the reference voltage to be 2.048V, with an 8-bit sample, 109 /*
110 * assume the reference voltage to be 2.048V, with an 8-bit sample,
110 * the LSB weight is 8mV 111 * the LSB weight is 8mV
111 */ 112 */
112 return sprintf(buf, "%d\n", ret * 8); 113 return sprintf(buf, "%d\n", ret * 8);
@@ -227,17 +228,7 @@ static struct spi_driver max1111_driver = {
227 .remove = __devexit_p(max1111_remove), 228 .remove = __devexit_p(max1111_remove),
228}; 229};
229 230
230static int __init max1111_init(void) 231module_spi_driver(max1111_driver);
231{
232 return spi_register_driver(&max1111_driver);
233}
234module_init(max1111_init);
235
236static void __exit max1111_exit(void)
237{
238 spi_unregister_driver(&max1111_driver);
239}
240module_exit(max1111_exit);
241 232
242MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>"); 233MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>");
243MODULE_DESCRIPTION("MAX1111 ADC Driver"); 234MODULE_DESCRIPTION("MAX1111 ADC Driver");
diff --git a/drivers/hwmon/max16065.c b/drivers/hwmon/max16065.c
index f8e323ac6cb3..822261be84dd 100644
--- a/drivers/hwmon/max16065.c
+++ b/drivers/hwmon/max16065.c
@@ -554,7 +554,7 @@ static int max16065_probe(struct i2c_client *client,
554 | I2C_FUNC_SMBUS_READ_WORD_DATA)) 554 | I2C_FUNC_SMBUS_READ_WORD_DATA))
555 return -ENODEV; 555 return -ENODEV;
556 556
557 data = kzalloc(sizeof(*data), GFP_KERNEL); 557 data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
558 if (unlikely(!data)) 558 if (unlikely(!data))
559 return -ENOMEM; 559 return -ENOMEM;
560 560
@@ -567,20 +567,16 @@ static int max16065_probe(struct i2c_client *client,
567 567
568 if (have_secondary) { 568 if (have_secondary) {
569 val = i2c_smbus_read_byte_data(client, MAX16065_SW_ENABLE); 569 val = i2c_smbus_read_byte_data(client, MAX16065_SW_ENABLE);
570 if (unlikely(val < 0)) { 570 if (unlikely(val < 0))
571 ret = val; 571 return val;
572 goto out_free;
573 }
574 secondary_is_max = val & MAX16065_WARNING_OV; 572 secondary_is_max = val & MAX16065_WARNING_OV;
575 } 573 }
576 574
577 /* Read scale registers, convert to range */ 575 /* Read scale registers, convert to range */
578 for (i = 0; i < DIV_ROUND_UP(data->num_adc, 4); i++) { 576 for (i = 0; i < DIV_ROUND_UP(data->num_adc, 4); i++) {
579 val = i2c_smbus_read_byte_data(client, MAX16065_SCALE(i)); 577 val = i2c_smbus_read_byte_data(client, MAX16065_SCALE(i));
580 if (unlikely(val < 0)) { 578 if (unlikely(val < 0))
581 ret = val; 579 return val;
582 goto out_free;
583 }
584 for (j = 0; j < 4 && i * 4 + j < data->num_adc; j++) { 580 for (j = 0; j < 4 && i * 4 + j < data->num_adc; j++) {
585 data->range[i * 4 + j] = 581 data->range[i * 4 + j] =
586 max16065_adc_range[(val >> (j * 2)) & 0x3]; 582 max16065_adc_range[(val >> (j * 2)) & 0x3];
@@ -595,10 +591,8 @@ static int max16065_probe(struct i2c_client *client,
595 for (j = 0; j < data->num_adc; j++) { 591 for (j = 0; j < data->num_adc; j++) {
596 val = i2c_smbus_read_byte_data(client, 592 val = i2c_smbus_read_byte_data(client,
597 MAX16065_LIMIT(i, j)); 593 MAX16065_LIMIT(i, j));
598 if (unlikely(val < 0)) { 594 if (unlikely(val < 0))
599 ret = val; 595 return val;
600 goto out_free;
601 }
602 data->limit[i][j] = LIMIT_TO_MV(val, data->range[j]); 596 data->limit[i][j] = LIMIT_TO_MV(val, data->range[j]);
603 } 597 }
604 } 598 }
@@ -661,8 +655,6 @@ static int max16065_probe(struct i2c_client *client,
661 655
662out: 656out:
663 max16065_cleanup(client); 657 max16065_cleanup(client);
664out_free:
665 kfree(data);
666 return ret; 658 return ret;
667} 659}
668 660
@@ -672,7 +664,6 @@ static int max16065_remove(struct i2c_client *client)
672 664
673 hwmon_device_unregister(data->hwmon_dev); 665 hwmon_device_unregister(data->hwmon_dev);
674 max16065_cleanup(client); 666 max16065_cleanup(client);
675 kfree(data);
676 667
677 return 0; 668 return 0;
678} 669}
@@ -699,19 +690,8 @@ static struct i2c_driver max16065_driver = {
699 .id_table = max16065_id, 690 .id_table = max16065_id,
700}; 691};
701 692
702static int __init max16065_init(void) 693module_i2c_driver(max16065_driver);
703{
704 return i2c_add_driver(&max16065_driver);
705}
706
707static void __exit max16065_exit(void)
708{
709 i2c_del_driver(&max16065_driver);
710}
711 694
712MODULE_AUTHOR("Guenter Roeck <guenter.roeck@ericsson.com>"); 695MODULE_AUTHOR("Guenter Roeck <guenter.roeck@ericsson.com>");
713MODULE_DESCRIPTION("MAX16065 driver"); 696MODULE_DESCRIPTION("MAX16065 driver");
714MODULE_LICENSE("GPL"); 697MODULE_LICENSE("GPL");
715
716module_init(max16065_init);
717module_exit(max16065_exit);
diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c
index 022ded098100..ecac04a7b7d6 100644
--- a/drivers/hwmon/max1619.c
+++ b/drivers/hwmon/max1619.c
@@ -125,7 +125,7 @@ struct max1619_data {
125 u8 temp_input2, temp_low2, temp_high2; /* remote */ 125 u8 temp_input2, temp_low2, temp_high2; /* remote */
126 u8 temp_crit2; 126 u8 temp_crit2;
127 u8 temp_hyst2; 127 u8 temp_hyst2;
128 u8 alarms; 128 u8 alarms;
129}; 129};
130 130
131/* 131/*
@@ -133,7 +133,8 @@ struct max1619_data {
133 */ 133 */
134 134
135#define show_temp(value) \ 135#define show_temp(value) \
136static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \ 136static ssize_t show_##value(struct device *dev, struct device_attribute *attr, \
137 char *buf) \
137{ \ 138{ \
138 struct max1619_data *data = max1619_update_device(dev); \ 139 struct max1619_data *data = max1619_update_device(dev); \
139 return sprintf(buf, "%d\n", temp_from_reg(data->value)); \ 140 return sprintf(buf, "%d\n", temp_from_reg(data->value)); \
@@ -146,13 +147,17 @@ show_temp(temp_crit2);
146show_temp(temp_hyst2); 147show_temp(temp_hyst2);
147 148
148#define set_temp2(value, reg) \ 149#define set_temp2(value, reg) \
149static ssize_t set_##value(struct device *dev, struct device_attribute *attr, const char *buf, \ 150static ssize_t set_##value(struct device *dev, struct device_attribute *attr, \
151 const char *buf, \
150 size_t count) \ 152 size_t count) \
151{ \ 153{ \
152 struct i2c_client *client = to_i2c_client(dev); \ 154 struct i2c_client *client = to_i2c_client(dev); \
153 struct max1619_data *data = i2c_get_clientdata(client); \ 155 struct max1619_data *data = i2c_get_clientdata(client); \
154 long val = simple_strtol(buf, NULL, 10); \ 156 long val; \
155 \ 157 int err = kstrtol(buf, 10, &val); \
158 if (err) \
159 return err; \
160\
156 mutex_lock(&data->update_lock); \ 161 mutex_lock(&data->update_lock); \
157 data->value = temp_to_reg(val); \ 162 data->value = temp_to_reg(val); \
158 i2c_smbus_write_byte_data(client, reg, data->value); \ 163 i2c_smbus_write_byte_data(client, reg, data->value); \
@@ -165,7 +170,8 @@ set_temp2(temp_high2, MAX1619_REG_W_REMOTE_HIGH);
165set_temp2(temp_crit2, MAX1619_REG_W_REMOTE_CRIT); 170set_temp2(temp_crit2, MAX1619_REG_W_REMOTE_CRIT);
166set_temp2(temp_hyst2, MAX1619_REG_W_TCRIT_HYST); 171set_temp2(temp_hyst2, MAX1619_REG_W_TCRIT_HYST);
167 172
168static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 173static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
174 char *buf)
169{ 175{
170 struct max1619_data *data = max1619_update_device(dev); 176 struct max1619_data *data = max1619_update_device(dev);
171 return sprintf(buf, "%d\n", data->alarms); 177 return sprintf(buf, "%d\n", data->alarms);
@@ -275,7 +281,8 @@ static int max1619_probe(struct i2c_client *new_client,
275 max1619_init_client(new_client); 281 max1619_init_client(new_client);
276 282
277 /* Register sysfs hooks */ 283 /* Register sysfs hooks */
278 if ((err = sysfs_create_group(&new_client->dev.kobj, &max1619_group))) 284 err = sysfs_create_group(&new_client->dev.kobj, &max1619_group);
285 if (err)
279 goto exit_free; 286 goto exit_free;
280 287
281 data->hwmon_dev = hwmon_device_register(&new_client->dev); 288 data->hwmon_dev = hwmon_device_register(&new_client->dev);
@@ -353,20 +360,9 @@ static struct max1619_data *max1619_update_device(struct device *dev)
353 return data; 360 return data;
354} 361}
355 362
356static int __init sensors_max1619_init(void) 363module_i2c_driver(max1619_driver);
357{
358 return i2c_add_driver(&max1619_driver);
359}
360
361static void __exit sensors_max1619_exit(void)
362{
363 i2c_del_driver(&max1619_driver);
364}
365 364
366MODULE_AUTHOR("Alexey Fisher <fishor@mail.ru> and " 365MODULE_AUTHOR("Alexey Fisher <fishor@mail.ru> and "
367 "Jean Delvare <khali@linux-fr.org>"); 366 "Jean Delvare <khali@linux-fr.org>");
368MODULE_DESCRIPTION("MAX1619 sensor driver"); 367MODULE_DESCRIPTION("MAX1619 sensor driver");
369MODULE_LICENSE("GPL"); 368MODULE_LICENSE("GPL");
370
371module_init(sensors_max1619_init);
372module_exit(sensors_max1619_exit);
diff --git a/drivers/hwmon/max1668.c b/drivers/hwmon/max1668.c
index 88953f99e914..335b183d7c02 100644
--- a/drivers/hwmon/max1668.c
+++ b/drivers/hwmon/max1668.c
@@ -1,23 +1,23 @@
1/* 1/*
2 Copyright (c) 2011 David George <david.george@ska.ac.za> 2 * Copyright (c) 2011 David George <david.george@ska.ac.za>
3 3 *
4 based on adm1021.c 4 * based on adm1021.c
5 some credit to Christoph Scheurer, but largely a rewrite 5 * some credit to Christoph Scheurer, but largely a rewrite
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
9 the Free Software Foundation; either version 2 of the License, or 9 * the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 10 * (at your option) any later version.
11 11 *
12 This program is distributed in the hope that it will be useful, 12 * This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 15 * GNU General Public License for more details.
16 16 *
17 You should have received a copy of the GNU General Public License 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 18 * along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/ 20 */
21 21
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/init.h> 23#include <linux/init.h>
@@ -484,19 +484,8 @@ static struct i2c_driver max1668_driver = {
484 .address_list = max1668_addr_list, 484 .address_list = max1668_addr_list,
485}; 485};
486 486
487static int __init sensors_max1668_init(void) 487module_i2c_driver(max1668_driver);
488{
489 return i2c_add_driver(&max1668_driver);
490}
491
492static void __exit sensors_max1668_exit(void)
493{
494 i2c_del_driver(&max1668_driver);
495}
496 488
497MODULE_AUTHOR("David George <david.george@ska.ac.za>"); 489MODULE_AUTHOR("David George <david.george@ska.ac.za>");
498MODULE_DESCRIPTION("MAX1668 remote temperature sensor driver"); 490MODULE_DESCRIPTION("MAX1668 remote temperature sensor driver");
499MODULE_LICENSE("GPL"); 491MODULE_LICENSE("GPL");
500
501module_init(sensors_max1668_init)
502module_exit(sensors_max1668_exit)
diff --git a/drivers/hwmon/max6639.c b/drivers/hwmon/max6639.c
index a6760bacd915..193067e27b6f 100644
--- a/drivers/hwmon/max6639.c
+++ b/drivers/hwmon/max6639.c
@@ -637,19 +637,8 @@ static struct i2c_driver max6639_driver = {
637 .address_list = normal_i2c, 637 .address_list = normal_i2c,
638}; 638};
639 639
640static int __init max6639_init(void) 640module_i2c_driver(max6639_driver);
641{
642 return i2c_add_driver(&max6639_driver);
643}
644
645static void __exit max6639_exit(void)
646{
647 i2c_del_driver(&max6639_driver);
648}
649 641
650MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>"); 642MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
651MODULE_DESCRIPTION("max6639 driver"); 643MODULE_DESCRIPTION("max6639 driver");
652MODULE_LICENSE("GPL"); 644MODULE_LICENSE("GPL");
653
654module_init(max6639_init);
655module_exit(max6639_exit);
diff --git a/drivers/hwmon/max6642.c b/drivers/hwmon/max6642.c
index 209e8a526eb1..4298909a41fd 100644
--- a/drivers/hwmon/max6642.c
+++ b/drivers/hwmon/max6642.c
@@ -352,19 +352,8 @@ static struct i2c_driver max6642_driver = {
352 .address_list = normal_i2c, 352 .address_list = normal_i2c,
353}; 353};
354 354
355static int __init max6642_init(void) 355module_i2c_driver(max6642_driver);
356{
357 return i2c_add_driver(&max6642_driver);
358}
359
360static void __exit max6642_exit(void)
361{
362 i2c_del_driver(&max6642_driver);
363}
364 356
365MODULE_AUTHOR("Per Dalen <per.dalen@appeartv.com>"); 357MODULE_AUTHOR("Per Dalen <per.dalen@appeartv.com>");
366MODULE_DESCRIPTION("MAX6642 sensor driver"); 358MODULE_DESCRIPTION("MAX6642 sensor driver");
367MODULE_LICENSE("GPL"); 359MODULE_LICENSE("GPL");
368
369module_init(max6642_init);
370module_exit(max6642_exit);
diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c
index 2fc034aeca09..33a8a7f15e18 100644
--- a/drivers/hwmon/max6650.c
+++ b/drivers/hwmon/max6650.c
@@ -135,8 +135,7 @@ static struct i2c_driver max6650_driver = {
135 * Client data (each client gets its own) 135 * Client data (each client gets its own)
136 */ 136 */
137 137
138struct max6650_data 138struct max6650_data {
139{
140 struct device *hwmon_dev; 139 struct device *hwmon_dev;
141 struct mutex update_lock; 140 struct mutex update_lock;
142 int nr_fans; 141 int nr_fans;
@@ -160,13 +159,13 @@ static ssize_t get_fan(struct device *dev, struct device_attribute *devattr,
160 int rpm; 159 int rpm;
161 160
162 /* 161 /*
163 * Calculation details: 162 * Calculation details:
164 * 163 *
165 * Each tachometer counts over an interval given by the "count" 164 * Each tachometer counts over an interval given by the "count"
166 * register (0.25, 0.5, 1 or 2 seconds). This module assumes 165 * register (0.25, 0.5, 1 or 2 seconds). This module assumes
167 * that the fans produce two pulses per revolution (this seems 166 * that the fans produce two pulses per revolution (this seems
168 * to be the most common). 167 * to be the most common).
169 */ 168 */
170 169
171 rpm = ((data->tach[attr->index] * 120) / DIV_FROM_REG(data->count)); 170 rpm = ((data->tach[attr->index] * 120) / DIV_FROM_REG(data->count));
172 return sprintf(buf, "%d\n", rpm); 171 return sprintf(buf, "%d\n", rpm);
@@ -220,12 +219,12 @@ static ssize_t get_target(struct device *dev, struct device_attribute *devattr,
220 int kscale, ktach, rpm; 219 int kscale, ktach, rpm;
221 220
222 /* 221 /*
223 * Use the datasheet equation: 222 * Use the datasheet equation:
224 * 223 *
225 * FanSpeed = KSCALE x fCLK / [256 x (KTACH + 1)] 224 * FanSpeed = KSCALE x fCLK / [256 x (KTACH + 1)]
226 * 225 *
227 * then multiply by 60 to give rpm. 226 * then multiply by 60 to give rpm.
228 */ 227 */
229 228
230 kscale = DIV_FROM_REG(data->config); 229 kscale = DIV_FROM_REG(data->config);
231 ktach = data->speed; 230 ktach = data->speed;
@@ -238,17 +237,22 @@ static ssize_t set_target(struct device *dev, struct device_attribute *devattr,
238{ 237{
239 struct i2c_client *client = to_i2c_client(dev); 238 struct i2c_client *client = to_i2c_client(dev);
240 struct max6650_data *data = i2c_get_clientdata(client); 239 struct max6650_data *data = i2c_get_clientdata(client);
241 int rpm = simple_strtoul(buf, NULL, 10);
242 int kscale, ktach; 240 int kscale, ktach;
241 unsigned long rpm;
242 int err;
243
244 err = kstrtoul(buf, 10, &rpm);
245 if (err)
246 return err;
243 247
244 rpm = SENSORS_LIMIT(rpm, FAN_RPM_MIN, FAN_RPM_MAX); 248 rpm = SENSORS_LIMIT(rpm, FAN_RPM_MIN, FAN_RPM_MAX);
245 249
246 /* 250 /*
247 * Divide the required speed by 60 to get from rpm to rps, then 251 * Divide the required speed by 60 to get from rpm to rps, then
248 * use the datasheet equation: 252 * use the datasheet equation:
249 * 253 *
250 * KTACH = [(fCLK x KSCALE) / (256 x FanSpeed)] - 1 254 * KTACH = [(fCLK x KSCALE) / (256 x FanSpeed)] - 1
251 */ 255 */
252 256
253 mutex_lock(&data->update_lock); 257 mutex_lock(&data->update_lock);
254 258
@@ -282,8 +286,10 @@ static ssize_t get_pwm(struct device *dev, struct device_attribute *devattr,
282 int pwm; 286 int pwm;
283 struct max6650_data *data = max6650_update_device(dev); 287 struct max6650_data *data = max6650_update_device(dev);
284 288
285 /* Useful range for dac is 0-180 for 12V fans and 0-76 for 5V fans. 289 /*
286 Lower DAC values mean higher speeds. */ 290 * Useful range for dac is 0-180 for 12V fans and 0-76 for 5V fans.
291 * Lower DAC values mean higher speeds.
292 */
287 if (data->config & MAX6650_CFG_V12) 293 if (data->config & MAX6650_CFG_V12)
288 pwm = 255 - (255 * (int)data->dac)/180; 294 pwm = 255 - (255 * (int)data->dac)/180;
289 else 295 else
@@ -300,7 +306,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr,
300{ 306{
301 struct i2c_client *client = to_i2c_client(dev); 307 struct i2c_client *client = to_i2c_client(dev);
302 struct max6650_data *data = i2c_get_clientdata(client); 308 struct max6650_data *data = i2c_get_clientdata(client);
303 int pwm = simple_strtoul(buf, NULL, 10); 309 unsigned long pwm;
310 int err;
311
312 err = kstrtoul(buf, 10, &pwm);
313 if (err)
314 return err;
304 315
305 pwm = SENSORS_LIMIT(pwm, 0, 255); 316 pwm = SENSORS_LIMIT(pwm, 0, 255);
306 317
@@ -341,14 +352,16 @@ static ssize_t set_enable(struct device *dev, struct device_attribute *devattr,
341{ 352{
342 struct i2c_client *client = to_i2c_client(dev); 353 struct i2c_client *client = to_i2c_client(dev);
343 struct max6650_data *data = i2c_get_clientdata(client); 354 struct max6650_data *data = i2c_get_clientdata(client);
344 int mode = simple_strtoul(buf, NULL, 10);
345 int max6650_modes[3] = {0, 3, 2}; 355 int max6650_modes[3] = {0, 3, 2};
356 unsigned long mode;
357 int err;
346 358
347 if ((mode < 0)||(mode > 2)) { 359 err = kstrtoul(buf, 10, &mode);
348 dev_err(&client->dev, 360 if (err)
349 "illegal value for pwm1_enable (%d)\n", mode); 361 return err;
362
363 if (mode > 2)
350 return -EINVAL; 364 return -EINVAL;
351 }
352 365
353 mutex_lock(&data->update_lock); 366 mutex_lock(&data->update_lock);
354 367
@@ -389,7 +402,12 @@ static ssize_t set_div(struct device *dev, struct device_attribute *devattr,
389{ 402{
390 struct i2c_client *client = to_i2c_client(dev); 403 struct i2c_client *client = to_i2c_client(dev);
391 struct max6650_data *data = i2c_get_clientdata(client); 404 struct max6650_data *data = i2c_get_clientdata(client);
392 int div = simple_strtoul(buf, NULL, 10); 405 unsigned long div;
406 int err;
407
408 err = kstrtoul(buf, 10, &div);
409 if (err)
410 return err;
393 411
394 mutex_lock(&data->update_lock); 412 mutex_lock(&data->update_lock);
395 switch (div) { 413 switch (div) {
@@ -407,8 +425,6 @@ static ssize_t set_div(struct device *dev, struct device_attribute *devattr,
407 break; 425 break;
408 default: 426 default:
409 mutex_unlock(&data->update_lock); 427 mutex_unlock(&data->update_lock);
410 dev_err(&client->dev,
411 "illegal value for fan divider (%d)\n", div);
412 return -EINVAL; 428 return -EINVAL;
413 } 429 }
414 430
@@ -529,7 +545,8 @@ static int max6650_probe(struct i2c_client *client,
529 struct max6650_data *data; 545 struct max6650_data *data;
530 int err; 546 int err;
531 547
532 if (!(data = kzalloc(sizeof(struct max6650_data), GFP_KERNEL))) { 548 data = kzalloc(sizeof(struct max6650_data), GFP_KERNEL);
549 if (!data) {
533 dev_err(&client->dev, "out of memory.\n"); 550 dev_err(&client->dev, "out of memory.\n");
534 return -ENOMEM; 551 return -ENOMEM;
535 } 552 }
@@ -596,55 +613,54 @@ static int max6650_init_client(struct i2c_client *client)
596 } 613 }
597 614
598 switch (fan_voltage) { 615 switch (fan_voltage) {
599 case 0: 616 case 0:
600 break; 617 break;
601 case 5: 618 case 5:
602 config &= ~MAX6650_CFG_V12; 619 config &= ~MAX6650_CFG_V12;
603 break; 620 break;
604 case 12: 621 case 12:
605 config |= MAX6650_CFG_V12; 622 config |= MAX6650_CFG_V12;
606 break; 623 break;
607 default: 624 default:
608 dev_err(&client->dev, 625 dev_err(&client->dev, "illegal value for fan_voltage (%d)\n",
609 "illegal value for fan_voltage (%d)\n", 626 fan_voltage);
610 fan_voltage);
611 } 627 }
612 628
613 dev_info(&client->dev, "Fan voltage is set to %dV.\n", 629 dev_info(&client->dev, "Fan voltage is set to %dV.\n",
614 (config & MAX6650_CFG_V12) ? 12 : 5); 630 (config & MAX6650_CFG_V12) ? 12 : 5);
615 631
616 switch (prescaler) { 632 switch (prescaler) {
617 case 0: 633 case 0:
618 break; 634 break;
619 case 1: 635 case 1:
620 config &= ~MAX6650_CFG_PRESCALER_MASK; 636 config &= ~MAX6650_CFG_PRESCALER_MASK;
621 break; 637 break;
622 case 2: 638 case 2:
623 config = (config & ~MAX6650_CFG_PRESCALER_MASK) 639 config = (config & ~MAX6650_CFG_PRESCALER_MASK)
624 | MAX6650_CFG_PRESCALER_2; 640 | MAX6650_CFG_PRESCALER_2;
625 break; 641 break;
626 case 4: 642 case 4:
627 config = (config & ~MAX6650_CFG_PRESCALER_MASK) 643 config = (config & ~MAX6650_CFG_PRESCALER_MASK)
628 | MAX6650_CFG_PRESCALER_4; 644 | MAX6650_CFG_PRESCALER_4;
629 break; 645 break;
630 case 8: 646 case 8:
631 config = (config & ~MAX6650_CFG_PRESCALER_MASK) 647 config = (config & ~MAX6650_CFG_PRESCALER_MASK)
632 | MAX6650_CFG_PRESCALER_8; 648 | MAX6650_CFG_PRESCALER_8;
633 break; 649 break;
634 case 16: 650 case 16:
635 config = (config & ~MAX6650_CFG_PRESCALER_MASK) 651 config = (config & ~MAX6650_CFG_PRESCALER_MASK)
636 | MAX6650_CFG_PRESCALER_16; 652 | MAX6650_CFG_PRESCALER_16;
637 break; 653 break;
638 default: 654 default:
639 dev_err(&client->dev, 655 dev_err(&client->dev, "illegal value for prescaler (%d)\n",
640 "illegal value for prescaler (%d)\n", 656 prescaler);
641 prescaler);
642 } 657 }
643 658
644 dev_info(&client->dev, "Prescaler is set to %d.\n", 659 dev_info(&client->dev, "Prescaler is set to %d.\n",
645 1 << (config & MAX6650_CFG_PRESCALER_MASK)); 660 1 << (config & MAX6650_CFG_PRESCALER_MASK));
646 661
647 /* If mode is set to "full off", we change it to "open loop" and 662 /*
663 * If mode is set to "full off", we change it to "open loop" and
648 * set DAC to 255, which has the same effect. We do this because 664 * set DAC to 255, which has the same effect. We do this because
649 * there's no "full off" mode defined in hwmon specifcations. 665 * there's no "full off" mode defined in hwmon specifcations.
650 */ 666 */
@@ -698,9 +714,11 @@ static struct max6650_data *max6650_update_device(struct device *dev)
698 MAX6650_REG_COUNT); 714 MAX6650_REG_COUNT);
699 data->dac = i2c_smbus_read_byte_data(client, MAX6650_REG_DAC); 715 data->dac = i2c_smbus_read_byte_data(client, MAX6650_REG_DAC);
700 716
701 /* Alarms are cleared on read in case the condition that 717 /*
718 * Alarms are cleared on read in case the condition that
702 * caused the alarm is removed. Keep the value latched here 719 * caused the alarm is removed. Keep the value latched here
703 * for providing the register through different alarm files. */ 720 * for providing the register through different alarm files.
721 */
704 data->alarm |= i2c_smbus_read_byte_data(client, 722 data->alarm |= i2c_smbus_read_byte_data(client,
705 MAX6650_REG_ALARM); 723 MAX6650_REG_ALARM);
706 724
@@ -713,19 +731,8 @@ static struct max6650_data *max6650_update_device(struct device *dev)
713 return data; 731 return data;
714} 732}
715 733
716static int __init sensors_max6650_init(void) 734module_i2c_driver(max6650_driver);
717{
718 return i2c_add_driver(&max6650_driver);
719}
720
721static void __exit sensors_max6650_exit(void)
722{
723 i2c_del_driver(&max6650_driver);
724}
725 735
726MODULE_AUTHOR("Hans J. Koch"); 736MODULE_AUTHOR("Hans J. Koch");
727MODULE_DESCRIPTION("MAX6650 sensor driver"); 737MODULE_DESCRIPTION("MAX6650 sensor driver");
728MODULE_LICENSE("GPL"); 738MODULE_LICENSE("GPL");
729
730module_init(sensors_max6650_init);
731module_exit(sensors_max6650_exit);
diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c
index 3d99b8854d7c..79ba48c8c116 100644
--- a/drivers/hwmon/pc87360.c
+++ b/drivers/hwmon/pc87360.c
@@ -56,11 +56,11 @@ static u8 confreg[4];
56static int init = 1; 56static int init = 1;
57module_param(init, int, 0); 57module_param(init, int, 0);
58MODULE_PARM_DESC(init, 58MODULE_PARM_DESC(init,
59 "Chip initialization level:\n" 59"Chip initialization level:\n"
60 " 0: None\n" 60" 0: None\n"
61 "*1: Forcibly enable internal voltage and temperature channels, except in9\n" 61"*1: Forcibly enable internal voltage and temperature channels, except in9\n"
62 " 2: Forcibly enable all voltage and temperature channels, except in9\n" 62" 2: Forcibly enable all voltage and temperature channels, except in9\n"
63 " 3: Forcibly enable all voltage and temperature channels, including in9"); 63" 3: Forcibly enable all voltage and temperature channels, including in9");
64 64
65static unsigned short force_id; 65static unsigned short force_id;
66module_param(force_id, ushort, 0); 66module_param(force_id, ushort, 0);
@@ -88,19 +88,19 @@ static const u8 logdev[LDNI_MAX] = { FSCM, VLM, TMS };
88static inline void superio_outb(int sioaddr, int reg, int val) 88static inline void superio_outb(int sioaddr, int reg, int val)
89{ 89{
90 outb(reg, sioaddr); 90 outb(reg, sioaddr);
91 outb(val, sioaddr+1); 91 outb(val, sioaddr + 1);
92} 92}
93 93
94static inline int superio_inb(int sioaddr, int reg) 94static inline int superio_inb(int sioaddr, int reg)
95{ 95{
96 outb(reg, sioaddr); 96 outb(reg, sioaddr);
97 return inb(sioaddr+1); 97 return inb(sioaddr + 1);
98} 98}
99 99
100static inline void superio_exit(int sioaddr) 100static inline void superio_exit(int sioaddr)
101{ 101{
102 outb(0x02, sioaddr); 102 outb(0x02, sioaddr);
103 outb(0x02, sioaddr+1); 103 outb(0x02, sioaddr + 1);
104} 104}
105 105
106/* 106/*
@@ -122,18 +122,18 @@ static inline void superio_exit(int sioaddr)
122#define PC87360_REG_FAN(nr) (0x07 + 3 * (nr)) 122#define PC87360_REG_FAN(nr) (0x07 + 3 * (nr))
123#define PC87360_REG_FAN_STATUS(nr) (0x08 + 3 * (nr)) 123#define PC87360_REG_FAN_STATUS(nr) (0x08 + 3 * (nr))
124 124
125#define FAN_FROM_REG(val,div) ((val) == 0 ? 0: \ 125#define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : \
126 480000 / ((val)*(div))) 126 480000 / ((val) * (div)))
127#define FAN_TO_REG(val,div) ((val) <= 100 ? 0 : \ 127#define FAN_TO_REG(val, div) ((val) <= 100 ? 0 : \
128 480000 / ((val)*(div))) 128 480000 / ((val) * (div)))
129#define FAN_DIV_FROM_REG(val) (1 << ((val >> 5) & 0x03)) 129#define FAN_DIV_FROM_REG(val) (1 << (((val) >> 5) & 0x03))
130#define FAN_STATUS_FROM_REG(val) ((val) & 0x07) 130#define FAN_STATUS_FROM_REG(val) ((val) & 0x07)
131 131
132#define FAN_CONFIG_MONITOR(val,nr) (((val) >> (2 + nr * 3)) & 1) 132#define FAN_CONFIG_MONITOR(val, nr) (((val) >> (2 + (nr) * 3)) & 1)
133#define FAN_CONFIG_CONTROL(val,nr) (((val) >> (3 + nr * 3)) & 1) 133#define FAN_CONFIG_CONTROL(val, nr) (((val) >> (3 + (nr) * 3)) & 1)
134#define FAN_CONFIG_INVERT(val,nr) (((val) >> (4 + nr * 3)) & 1) 134#define FAN_CONFIG_INVERT(val, nr) (((val) >> (4 + (nr) * 3)) & 1)
135 135
136#define PWM_FROM_REG(val,inv) ((inv) ? 255 - (val) : (val)) 136#define PWM_FROM_REG(val, inv) ((inv) ? 255 - (val) : (val))
137static inline u8 PWM_TO_REG(int val, int inv) 137static inline u8 PWM_TO_REG(int val, int inv)
138{ 138{
139 if (inv) 139 if (inv)
@@ -159,10 +159,10 @@ static inline u8 PWM_TO_REG(int val, int inv)
159#define PC87365_REG_IN_ALARMS2 0x01 159#define PC87365_REG_IN_ALARMS2 0x01
160#define PC87365_REG_VID 0x06 160#define PC87365_REG_VID 0x06
161 161
162#define IN_FROM_REG(val,ref) (((val) * (ref) + 128) / 256) 162#define IN_FROM_REG(val, ref) (((val) * (ref) + 128) / 256)
163#define IN_TO_REG(val,ref) ((val) < 0 ? 0 : \ 163#define IN_TO_REG(val, ref) ((val) < 0 ? 0 : \
164 (val)*256 >= (ref)*255 ? 255: \ 164 (val) * 256 >= (ref) * 255 ? 255 : \
165 ((val) * 256 + (ref)/2) / (ref)) 165 ((val) * 256 + (ref) / 2) / (ref))
166 166
167/* 167/*
168 * Temperature registers and conversions 168 * Temperature registers and conversions
@@ -255,43 +255,54 @@ static struct platform_driver pc87360_driver = {
255 * Sysfs stuff 255 * Sysfs stuff
256 */ 256 */
257 257
258static ssize_t show_fan_input(struct device *dev, struct device_attribute *devattr, char *buf) 258static ssize_t show_fan_input(struct device *dev,
259 struct device_attribute *devattr, char *buf)
259{ 260{
260 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 261 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
261 struct pc87360_data *data = pc87360_update_device(dev); 262 struct pc87360_data *data = pc87360_update_device(dev);
262 return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan[attr->index], 263 return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan[attr->index],
263 FAN_DIV_FROM_REG(data->fan_status[attr->index]))); 264 FAN_DIV_FROM_REG(data->fan_status[attr->index])));
264} 265}
265static ssize_t show_fan_min(struct device *dev, struct device_attribute *devattr, char *buf) 266static ssize_t show_fan_min(struct device *dev,
267 struct device_attribute *devattr, char *buf)
266{ 268{
267 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 269 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
268 struct pc87360_data *data = pc87360_update_device(dev); 270 struct pc87360_data *data = pc87360_update_device(dev);
269 return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan_min[attr->index], 271 return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan_min[attr->index],
270 FAN_DIV_FROM_REG(data->fan_status[attr->index]))); 272 FAN_DIV_FROM_REG(data->fan_status[attr->index])));
271} 273}
272static ssize_t show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf) 274static ssize_t show_fan_div(struct device *dev,
275 struct device_attribute *devattr, char *buf)
273{ 276{
274 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 277 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
275 struct pc87360_data *data = pc87360_update_device(dev); 278 struct pc87360_data *data = pc87360_update_device(dev);
276 return sprintf(buf, "%u\n", 279 return sprintf(buf, "%u\n",
277 FAN_DIV_FROM_REG(data->fan_status[attr->index])); 280 FAN_DIV_FROM_REG(data->fan_status[attr->index]));
278} 281}
279static ssize_t show_fan_status(struct device *dev, struct device_attribute *devattr, char *buf) 282static ssize_t show_fan_status(struct device *dev,
283 struct device_attribute *devattr, char *buf)
280{ 284{
281 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 285 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
282 struct pc87360_data *data = pc87360_update_device(dev); 286 struct pc87360_data *data = pc87360_update_device(dev);
283 return sprintf(buf, "%u\n", 287 return sprintf(buf, "%u\n",
284 FAN_STATUS_FROM_REG(data->fan_status[attr->index])); 288 FAN_STATUS_FROM_REG(data->fan_status[attr->index]));
285} 289}
286static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr, const char *buf, 290static ssize_t set_fan_min(struct device *dev,
291 struct device_attribute *devattr, const char *buf,
287 size_t count) 292 size_t count)
288{ 293{
289 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 294 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
290 struct pc87360_data *data = dev_get_drvdata(dev); 295 struct pc87360_data *data = dev_get_drvdata(dev);
291 long fan_min = simple_strtol(buf, NULL, 10); 296 long fan_min;
297 int err;
298
299 err = kstrtol(buf, 10, &fan_min);
300 if (err)
301 return err;
292 302
293 mutex_lock(&data->update_lock); 303 mutex_lock(&data->update_lock);
294 fan_min = FAN_TO_REG(fan_min, FAN_DIV_FROM_REG(data->fan_status[attr->index])); 304 fan_min = FAN_TO_REG(fan_min,
305 FAN_DIV_FROM_REG(data->fan_status[attr->index]));
295 306
296 /* If it wouldn't fit, change clock divisor */ 307 /* If it wouldn't fit, change clock divisor */
297 while (fan_min > 255 308 while (fan_min > 255
@@ -301,11 +312,13 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr,
301 data->fan_status[attr->index] += 0x20; 312 data->fan_status[attr->index] += 0x20;
302 } 313 }
303 data->fan_min[attr->index] = fan_min > 255 ? 255 : fan_min; 314 data->fan_min[attr->index] = fan_min > 255 ? 255 : fan_min;
304 pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_MIN(attr->index), 315 pc87360_write_value(data, LD_FAN, NO_BANK,
316 PC87360_REG_FAN_MIN(attr->index),
305 data->fan_min[attr->index]); 317 data->fan_min[attr->index]);
306 318
307 /* Write new divider, preserve alarm bits */ 319 /* Write new divider, preserve alarm bits */
308 pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_STATUS(attr->index), 320 pc87360_write_value(data, LD_FAN, NO_BANK,
321 PC87360_REG_FAN_STATUS(attr->index),
309 data->fan_status[attr->index] & 0xF9); 322 data->fan_status[attr->index] & 0xF9);
310 mutex_unlock(&data->update_lock); 323 mutex_unlock(&data->update_lock);
311 324
@@ -333,13 +346,16 @@ static struct sensor_device_attribute fan_min[] = {
333 SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 2), 346 SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 2),
334}; 347};
335 348
336#define FAN_UNIT_ATTRS(X) \ 349#define FAN_UNIT_ATTRS(X) \
337 &fan_input[X].dev_attr.attr, \ 350{ &fan_input[X].dev_attr.attr, \
338 &fan_status[X].dev_attr.attr, \ 351 &fan_status[X].dev_attr.attr, \
339 &fan_div[X].dev_attr.attr, \ 352 &fan_div[X].dev_attr.attr, \
340 &fan_min[X].dev_attr.attr 353 &fan_min[X].dev_attr.attr, \
354 NULL \
355}
341 356
342static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, char *buf) 357static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
358 char *buf)
343{ 359{
344 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 360 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
345 struct pc87360_data *data = pc87360_update_device(dev); 361 struct pc87360_data *data = pc87360_update_device(dev);
@@ -348,12 +364,17 @@ static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, ch
348 FAN_CONFIG_INVERT(data->fan_conf, 364 FAN_CONFIG_INVERT(data->fan_conf,
349 attr->index))); 365 attr->index)));
350} 366}
351static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, const char *buf, 367static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr,
352 size_t count) 368 const char *buf, size_t count)
353{ 369{
354 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 370 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
355 struct pc87360_data *data = dev_get_drvdata(dev); 371 struct pc87360_data *data = dev_get_drvdata(dev);
356 long val = simple_strtol(buf, NULL, 10); 372 long val;
373 int err;
374
375 err = kstrtol(buf, 10, &val);
376 if (err)
377 return err;
357 378
358 mutex_lock(&data->update_lock); 379 mutex_lock(&data->update_lock);
359 data->pwm[attr->index] = PWM_TO_REG(val, 380 data->pwm[attr->index] = PWM_TO_REG(val,
@@ -370,52 +391,60 @@ static struct sensor_device_attribute pwm[] = {
370 SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2), 391 SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2),
371}; 392};
372 393
373static struct attribute * pc8736x_fan_attr_array[] = { 394static struct attribute *pc8736x_fan_attr[][5] = {
374 FAN_UNIT_ATTRS(0), 395 FAN_UNIT_ATTRS(0),
375 FAN_UNIT_ATTRS(1), 396 FAN_UNIT_ATTRS(1),
376 FAN_UNIT_ATTRS(2), 397 FAN_UNIT_ATTRS(2)
377 &pwm[0].dev_attr.attr,
378 &pwm[1].dev_attr.attr,
379 &pwm[2].dev_attr.attr,
380 NULL
381}; 398};
382static const struct attribute_group pc8736x_fan_group = { 399
383 .attrs = pc8736x_fan_attr_array, 400static const struct attribute_group pc8736x_fan_attr_group[] = {
401 { .attrs = pc8736x_fan_attr[0], },
402 { .attrs = pc8736x_fan_attr[1], },
403 { .attrs = pc8736x_fan_attr[2], },
384}; 404};
385 405
386static ssize_t show_in_input(struct device *dev, struct device_attribute *devattr, char *buf) 406static ssize_t show_in_input(struct device *dev,
407 struct device_attribute *devattr, char *buf)
387{ 408{
388 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 409 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
389 struct pc87360_data *data = pc87360_update_device(dev); 410 struct pc87360_data *data = pc87360_update_device(dev);
390 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index], 411 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index],
391 data->in_vref)); 412 data->in_vref));
392} 413}
393static ssize_t show_in_min(struct device *dev, struct device_attribute *devattr, char *buf) 414static ssize_t show_in_min(struct device *dev,
415 struct device_attribute *devattr, char *buf)
394{ 416{
395 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 417 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
396 struct pc87360_data *data = pc87360_update_device(dev); 418 struct pc87360_data *data = pc87360_update_device(dev);
397 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index], 419 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index],
398 data->in_vref)); 420 data->in_vref));
399} 421}
400static ssize_t show_in_max(struct device *dev, struct device_attribute *devattr, char *buf) 422static ssize_t show_in_max(struct device *dev,
423 struct device_attribute *devattr, char *buf)
401{ 424{
402 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 425 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
403 struct pc87360_data *data = pc87360_update_device(dev); 426 struct pc87360_data *data = pc87360_update_device(dev);
404 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index], 427 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index],
405 data->in_vref)); 428 data->in_vref));
406} 429}
407static ssize_t show_in_status(struct device *dev, struct device_attribute *devattr, char *buf) 430static ssize_t show_in_status(struct device *dev,
431 struct device_attribute *devattr, char *buf)
408{ 432{
409 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 433 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
410 struct pc87360_data *data = pc87360_update_device(dev); 434 struct pc87360_data *data = pc87360_update_device(dev);
411 return sprintf(buf, "%u\n", data->in_status[attr->index]); 435 return sprintf(buf, "%u\n", data->in_status[attr->index]);
412} 436}
413static ssize_t set_in_min(struct device *dev, struct device_attribute *devattr, const char *buf, 437static ssize_t set_in_min(struct device *dev, struct device_attribute *devattr,
414 size_t count) 438 const char *buf, size_t count)
415{ 439{
416 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 440 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
417 struct pc87360_data *data = dev_get_drvdata(dev); 441 struct pc87360_data *data = dev_get_drvdata(dev);
418 long val = simple_strtol(buf, NULL, 10); 442 long val;
443 int err;
444
445 err = kstrtol(buf, 10, &val);
446 if (err)
447 return err;
419 448
420 mutex_lock(&data->update_lock); 449 mutex_lock(&data->update_lock);
421 data->in_min[attr->index] = IN_TO_REG(val, data->in_vref); 450 data->in_min[attr->index] = IN_TO_REG(val, data->in_vref);
@@ -424,12 +453,17 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *devattr,
424 mutex_unlock(&data->update_lock); 453 mutex_unlock(&data->update_lock);
425 return count; 454 return count;
426} 455}
427static ssize_t set_in_max(struct device *dev, struct device_attribute *devattr, const char *buf, 456static ssize_t set_in_max(struct device *dev, struct device_attribute *devattr,
428 size_t count) 457 const char *buf, size_t count)
429{ 458{
430 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 459 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
431 struct pc87360_data *data = dev_get_drvdata(dev); 460 struct pc87360_data *data = dev_get_drvdata(dev);
432 long val = simple_strtol(buf, NULL, 10); 461 long val;
462 int err;
463
464 err = kstrtol(buf, 10, &val);
465 if (err)
466 return err;
433 467
434 mutex_lock(&data->update_lock); 468 mutex_lock(&data->update_lock);
435 data->in_max[attr->index] = IN_TO_REG(val, 469 data->in_max[attr->index] = IN_TO_REG(val,
@@ -498,9 +532,11 @@ static struct sensor_device_attribute in_max[] = {
498#define CHAN_ALM_MAX 0x04 /* max limit exceeded */ 532#define CHAN_ALM_MAX 0x04 /* max limit exceeded */
499#define TEMP_ALM_CRIT 0x08 /* temp crit exceeded (temp only) */ 533#define TEMP_ALM_CRIT 0x08 /* temp crit exceeded (temp only) */
500 534
501/* show_in_min/max_alarm() reads data from the per-channel status 535/*
502 register (sec 11.5.12), not the vin event status registers (sec 536 * show_in_min/max_alarm() reads data from the per-channel status
503 11.5.2) that (legacy) show_in_alarm() resds (via data->in_alarms) */ 537 * register (sec 11.5.12), not the vin event status registers (sec
538 * 11.5.2) that (legacy) show_in_alarm() resds (via data->in_alarms)
539 */
504 540
505static ssize_t show_in_min_alarm(struct device *dev, 541static ssize_t show_in_min_alarm(struct device *dev,
506 struct device_attribute *devattr, char *buf) 542 struct device_attribute *devattr, char *buf)
@@ -554,27 +590,38 @@ static struct sensor_device_attribute in_max_alarm[] = {
554 &in_min_alarm[X].dev_attr.attr, \ 590 &in_min_alarm[X].dev_attr.attr, \
555 &in_max_alarm[X].dev_attr.attr 591 &in_max_alarm[X].dev_attr.attr
556 592
557static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) 593static ssize_t show_vid(struct device *dev, struct device_attribute *attr,
594 char *buf)
558{ 595{
559 struct pc87360_data *data = pc87360_update_device(dev); 596 struct pc87360_data *data = pc87360_update_device(dev);
560 return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm)); 597 return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
561} 598}
562static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 599static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
563 600
564static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf) 601static ssize_t show_vrm(struct device *dev, struct device_attribute *attr,
602 char *buf)
565{ 603{
566 struct pc87360_data *data = dev_get_drvdata(dev); 604 struct pc87360_data *data = dev_get_drvdata(dev);
567 return sprintf(buf, "%u\n", data->vrm); 605 return sprintf(buf, "%u\n", data->vrm);
568} 606}
569static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 607static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
608 const char *buf, size_t count)
570{ 609{
571 struct pc87360_data *data = dev_get_drvdata(dev); 610 struct pc87360_data *data = dev_get_drvdata(dev);
572 data->vrm = simple_strtoul(buf, NULL, 10); 611 unsigned long val;
612 int err;
613
614 err = kstrtoul(buf, 10, &val);
615 if (err)
616 return err;
617
618 data->vrm = val;
573 return count; 619 return count;
574} 620}
575static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); 621static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
576 622
577static ssize_t show_in_alarms(struct device *dev, struct device_attribute *attr, char *buf) 623static ssize_t show_in_alarms(struct device *dev,
624 struct device_attribute *attr, char *buf)
578{ 625{
579 struct pc87360_data *data = pc87360_update_device(dev); 626 struct pc87360_data *data = pc87360_update_device(dev);
580 return sprintf(buf, "%u\n", data->in_alarms); 627 return sprintf(buf, "%u\n", data->in_alarms);
@@ -602,46 +649,58 @@ static const struct attribute_group pc8736x_vin_group = {
602 .attrs = pc8736x_vin_attr_array, 649 .attrs = pc8736x_vin_attr_array,
603}; 650};
604 651
605static ssize_t show_therm_input(struct device *dev, struct device_attribute *devattr, char *buf) 652static ssize_t show_therm_input(struct device *dev,
653 struct device_attribute *devattr, char *buf)
606{ 654{
607 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 655 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
608 struct pc87360_data *data = pc87360_update_device(dev); 656 struct pc87360_data *data = pc87360_update_device(dev);
609 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index], 657 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index],
610 data->in_vref)); 658 data->in_vref));
611} 659}
612static ssize_t show_therm_min(struct device *dev, struct device_attribute *devattr, char *buf) 660static ssize_t show_therm_min(struct device *dev,
661 struct device_attribute *devattr, char *buf)
613{ 662{
614 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 663 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
615 struct pc87360_data *data = pc87360_update_device(dev); 664 struct pc87360_data *data = pc87360_update_device(dev);
616 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index], 665 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index],
617 data->in_vref)); 666 data->in_vref));
618} 667}
619static ssize_t show_therm_max(struct device *dev, struct device_attribute *devattr, char *buf) 668static ssize_t show_therm_max(struct device *dev,
669 struct device_attribute *devattr, char *buf)
620{ 670{
621 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 671 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
622 struct pc87360_data *data = pc87360_update_device(dev); 672 struct pc87360_data *data = pc87360_update_device(dev);
623 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index], 673 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index],
624 data->in_vref)); 674 data->in_vref));
625} 675}
626static ssize_t show_therm_crit(struct device *dev, struct device_attribute *devattr, char *buf) 676static ssize_t show_therm_crit(struct device *dev,
677 struct device_attribute *devattr, char *buf)
627{ 678{
628 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 679 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
629 struct pc87360_data *data = pc87360_update_device(dev); 680 struct pc87360_data *data = pc87360_update_device(dev);
630 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_crit[attr->index-11], 681 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_crit[attr->index-11],
631 data->in_vref)); 682 data->in_vref));
632} 683}
633static ssize_t show_therm_status(struct device *dev, struct device_attribute *devattr, char *buf) 684static ssize_t show_therm_status(struct device *dev,
685 struct device_attribute *devattr, char *buf)
634{ 686{
635 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 687 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
636 struct pc87360_data *data = pc87360_update_device(dev); 688 struct pc87360_data *data = pc87360_update_device(dev);
637 return sprintf(buf, "%u\n", data->in_status[attr->index]); 689 return sprintf(buf, "%u\n", data->in_status[attr->index]);
638} 690}
639static ssize_t set_therm_min(struct device *dev, struct device_attribute *devattr, const char *buf, 691
640 size_t count) 692static ssize_t set_therm_min(struct device *dev,
693 struct device_attribute *devattr,
694 const char *buf, size_t count)
641{ 695{
642 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 696 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
643 struct pc87360_data *data = dev_get_drvdata(dev); 697 struct pc87360_data *data = dev_get_drvdata(dev);
644 long val = simple_strtol(buf, NULL, 10); 698 long val;
699 int err;
700
701 err = kstrtol(buf, 10, &val);
702 if (err)
703 return err;
645 704
646 mutex_lock(&data->update_lock); 705 mutex_lock(&data->update_lock);
647 data->in_min[attr->index] = IN_TO_REG(val, data->in_vref); 706 data->in_min[attr->index] = IN_TO_REG(val, data->in_vref);
@@ -650,12 +709,19 @@ static ssize_t set_therm_min(struct device *dev, struct device_attribute *devatt
650 mutex_unlock(&data->update_lock); 709 mutex_unlock(&data->update_lock);
651 return count; 710 return count;
652} 711}
653static ssize_t set_therm_max(struct device *dev, struct device_attribute *devattr, const char *buf, 712
654 size_t count) 713static ssize_t set_therm_max(struct device *dev,
714 struct device_attribute *devattr,
715 const char *buf, size_t count)
655{ 716{
656 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 717 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
657 struct pc87360_data *data = dev_get_drvdata(dev); 718 struct pc87360_data *data = dev_get_drvdata(dev);
658 long val = simple_strtol(buf, NULL, 10); 719 long val;
720 int err;
721
722 err = kstrtol(buf, 10, &val);
723 if (err)
724 return err;
659 725
660 mutex_lock(&data->update_lock); 726 mutex_lock(&data->update_lock);
661 data->in_max[attr->index] = IN_TO_REG(val, data->in_vref); 727 data->in_max[attr->index] = IN_TO_REG(val, data->in_vref);
@@ -664,12 +730,18 @@ static ssize_t set_therm_max(struct device *dev, struct device_attribute *devatt
664 mutex_unlock(&data->update_lock); 730 mutex_unlock(&data->update_lock);
665 return count; 731 return count;
666} 732}
667static ssize_t set_therm_crit(struct device *dev, struct device_attribute *devattr, const char *buf, 733static ssize_t set_therm_crit(struct device *dev,
668 size_t count) 734 struct device_attribute *devattr,
735 const char *buf, size_t count)
669{ 736{
670 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 737 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
671 struct pc87360_data *data = dev_get_drvdata(dev); 738 struct pc87360_data *data = dev_get_drvdata(dev);
672 long val = simple_strtol(buf, NULL, 10); 739 long val;
740 int err;
741
742 err = kstrtol(buf, 10, &val);
743 if (err)
744 return err;
673 745
674 mutex_lock(&data->update_lock); 746 mutex_lock(&data->update_lock);
675 data->in_crit[attr->index-11] = IN_TO_REG(val, data->in_vref); 747 data->in_crit[attr->index-11] = IN_TO_REG(val, data->in_vref);
@@ -679,46 +751,49 @@ static ssize_t set_therm_crit(struct device *dev, struct device_attribute *devat
679 return count; 751 return count;
680} 752}
681 753
682/* the +11 term below reflects the fact that VLM units 11,12,13 are 754/*
683 used in the chip to measure voltage across the thermistors 755 * the +11 term below reflects the fact that VLM units 11,12,13 are
684*/ 756 * used in the chip to measure voltage across the thermistors
757 */
685static struct sensor_device_attribute therm_input[] = { 758static struct sensor_device_attribute therm_input[] = {
686 SENSOR_ATTR(temp4_input, S_IRUGO, show_therm_input, NULL, 0+11), 759 SENSOR_ATTR(temp4_input, S_IRUGO, show_therm_input, NULL, 0 + 11),
687 SENSOR_ATTR(temp5_input, S_IRUGO, show_therm_input, NULL, 1+11), 760 SENSOR_ATTR(temp5_input, S_IRUGO, show_therm_input, NULL, 1 + 11),
688 SENSOR_ATTR(temp6_input, S_IRUGO, show_therm_input, NULL, 2+11), 761 SENSOR_ATTR(temp6_input, S_IRUGO, show_therm_input, NULL, 2 + 11),
689}; 762};
690static struct sensor_device_attribute therm_status[] = { 763static struct sensor_device_attribute therm_status[] = {
691 SENSOR_ATTR(temp4_status, S_IRUGO, show_therm_status, NULL, 0+11), 764 SENSOR_ATTR(temp4_status, S_IRUGO, show_therm_status, NULL, 0 + 11),
692 SENSOR_ATTR(temp5_status, S_IRUGO, show_therm_status, NULL, 1+11), 765 SENSOR_ATTR(temp5_status, S_IRUGO, show_therm_status, NULL, 1 + 11),
693 SENSOR_ATTR(temp6_status, S_IRUGO, show_therm_status, NULL, 2+11), 766 SENSOR_ATTR(temp6_status, S_IRUGO, show_therm_status, NULL, 2 + 11),
694}; 767};
695static struct sensor_device_attribute therm_min[] = { 768static struct sensor_device_attribute therm_min[] = {
696 SENSOR_ATTR(temp4_min, S_IRUGO | S_IWUSR, 769 SENSOR_ATTR(temp4_min, S_IRUGO | S_IWUSR,
697 show_therm_min, set_therm_min, 0+11), 770 show_therm_min, set_therm_min, 0 + 11),
698 SENSOR_ATTR(temp5_min, S_IRUGO | S_IWUSR, 771 SENSOR_ATTR(temp5_min, S_IRUGO | S_IWUSR,
699 show_therm_min, set_therm_min, 1+11), 772 show_therm_min, set_therm_min, 1 + 11),
700 SENSOR_ATTR(temp6_min, S_IRUGO | S_IWUSR, 773 SENSOR_ATTR(temp6_min, S_IRUGO | S_IWUSR,
701 show_therm_min, set_therm_min, 2+11), 774 show_therm_min, set_therm_min, 2 + 11),
702}; 775};
703static struct sensor_device_attribute therm_max[] = { 776static struct sensor_device_attribute therm_max[] = {
704 SENSOR_ATTR(temp4_max, S_IRUGO | S_IWUSR, 777 SENSOR_ATTR(temp4_max, S_IRUGO | S_IWUSR,
705 show_therm_max, set_therm_max, 0+11), 778 show_therm_max, set_therm_max, 0 + 11),
706 SENSOR_ATTR(temp5_max, S_IRUGO | S_IWUSR, 779 SENSOR_ATTR(temp5_max, S_IRUGO | S_IWUSR,
707 show_therm_max, set_therm_max, 1+11), 780 show_therm_max, set_therm_max, 1 + 11),
708 SENSOR_ATTR(temp6_max, S_IRUGO | S_IWUSR, 781 SENSOR_ATTR(temp6_max, S_IRUGO | S_IWUSR,
709 show_therm_max, set_therm_max, 2+11), 782 show_therm_max, set_therm_max, 2 + 11),
710}; 783};
711static struct sensor_device_attribute therm_crit[] = { 784static struct sensor_device_attribute therm_crit[] = {
712 SENSOR_ATTR(temp4_crit, S_IRUGO | S_IWUSR, 785 SENSOR_ATTR(temp4_crit, S_IRUGO | S_IWUSR,
713 show_therm_crit, set_therm_crit, 0+11), 786 show_therm_crit, set_therm_crit, 0 + 11),
714 SENSOR_ATTR(temp5_crit, S_IRUGO | S_IWUSR, 787 SENSOR_ATTR(temp5_crit, S_IRUGO | S_IWUSR,
715 show_therm_crit, set_therm_crit, 1+11), 788 show_therm_crit, set_therm_crit, 1 + 11),
716 SENSOR_ATTR(temp6_crit, S_IRUGO | S_IWUSR, 789 SENSOR_ATTR(temp6_crit, S_IRUGO | S_IWUSR,
717 show_therm_crit, set_therm_crit, 2+11), 790 show_therm_crit, set_therm_crit, 2 + 11),
718}; 791};
719 792
720/* show_therm_min/max_alarm() reads data from the per-channel voltage 793/*
721 status register (sec 11.5.12) */ 794 * show_therm_min/max_alarm() reads data from the per-channel voltage
795 * status register (sec 11.5.12)
796 */
722 797
723static ssize_t show_therm_min_alarm(struct device *dev, 798static ssize_t show_therm_min_alarm(struct device *dev,
724 struct device_attribute *devattr, char *buf) 799 struct device_attribute *devattr, char *buf)
@@ -747,27 +822,27 @@ static ssize_t show_therm_crit_alarm(struct device *dev,
747 822
748static struct sensor_device_attribute therm_min_alarm[] = { 823static struct sensor_device_attribute therm_min_alarm[] = {
749 SENSOR_ATTR(temp4_min_alarm, S_IRUGO, 824 SENSOR_ATTR(temp4_min_alarm, S_IRUGO,
750 show_therm_min_alarm, NULL, 0+11), 825 show_therm_min_alarm, NULL, 0 + 11),
751 SENSOR_ATTR(temp5_min_alarm, S_IRUGO, 826 SENSOR_ATTR(temp5_min_alarm, S_IRUGO,
752 show_therm_min_alarm, NULL, 1+11), 827 show_therm_min_alarm, NULL, 1 + 11),
753 SENSOR_ATTR(temp6_min_alarm, S_IRUGO, 828 SENSOR_ATTR(temp6_min_alarm, S_IRUGO,
754 show_therm_min_alarm, NULL, 2+11), 829 show_therm_min_alarm, NULL, 2 + 11),
755}; 830};
756static struct sensor_device_attribute therm_max_alarm[] = { 831static struct sensor_device_attribute therm_max_alarm[] = {
757 SENSOR_ATTR(temp4_max_alarm, S_IRUGO, 832 SENSOR_ATTR(temp4_max_alarm, S_IRUGO,
758 show_therm_max_alarm, NULL, 0+11), 833 show_therm_max_alarm, NULL, 0 + 11),
759 SENSOR_ATTR(temp5_max_alarm, S_IRUGO, 834 SENSOR_ATTR(temp5_max_alarm, S_IRUGO,
760 show_therm_max_alarm, NULL, 1+11), 835 show_therm_max_alarm, NULL, 1 + 11),
761 SENSOR_ATTR(temp6_max_alarm, S_IRUGO, 836 SENSOR_ATTR(temp6_max_alarm, S_IRUGO,
762 show_therm_max_alarm, NULL, 2+11), 837 show_therm_max_alarm, NULL, 2 + 11),
763}; 838};
764static struct sensor_device_attribute therm_crit_alarm[] = { 839static struct sensor_device_attribute therm_crit_alarm[] = {
765 SENSOR_ATTR(temp4_crit_alarm, S_IRUGO, 840 SENSOR_ATTR(temp4_crit_alarm, S_IRUGO,
766 show_therm_crit_alarm, NULL, 0+11), 841 show_therm_crit_alarm, NULL, 0 + 11),
767 SENSOR_ATTR(temp5_crit_alarm, S_IRUGO, 842 SENSOR_ATTR(temp5_crit_alarm, S_IRUGO,
768 show_therm_crit_alarm, NULL, 1+11), 843 show_therm_crit_alarm, NULL, 1 + 11),
769 SENSOR_ATTR(temp6_crit_alarm, S_IRUGO, 844 SENSOR_ATTR(temp6_crit_alarm, S_IRUGO,
770 show_therm_crit_alarm, NULL, 2+11), 845 show_therm_crit_alarm, NULL, 2 + 11),
771}; 846};
772 847
773#define THERM_UNIT_ATTRS(X) \ 848#define THERM_UNIT_ATTRS(X) \
@@ -780,7 +855,7 @@ static struct sensor_device_attribute therm_crit_alarm[] = {
780 &therm_max_alarm[X].dev_attr.attr, \ 855 &therm_max_alarm[X].dev_attr.attr, \
781 &therm_crit_alarm[X].dev_attr.attr 856 &therm_crit_alarm[X].dev_attr.attr
782 857
783static struct attribute * pc8736x_therm_attr_array[] = { 858static struct attribute *pc8736x_therm_attr_array[] = {
784 THERM_UNIT_ATTRS(0), 859 THERM_UNIT_ATTRS(0),
785 THERM_UNIT_ATTRS(1), 860 THERM_UNIT_ATTRS(1),
786 THERM_UNIT_ATTRS(2), 861 THERM_UNIT_ATTRS(2),
@@ -790,42 +865,59 @@ static const struct attribute_group pc8736x_therm_group = {
790 .attrs = pc8736x_therm_attr_array, 865 .attrs = pc8736x_therm_attr_array,
791}; 866};
792 867
793static ssize_t show_temp_input(struct device *dev, struct device_attribute *devattr, char *buf) 868static ssize_t show_temp_input(struct device *dev,
869 struct device_attribute *devattr, char *buf)
794{ 870{
795 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 871 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
796 struct pc87360_data *data = pc87360_update_device(dev); 872 struct pc87360_data *data = pc87360_update_device(dev);
797 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index])); 873 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index]));
798} 874}
799static ssize_t show_temp_min(struct device *dev, struct device_attribute *devattr, char *buf) 875
876static ssize_t show_temp_min(struct device *dev,
877 struct device_attribute *devattr, char *buf)
800{ 878{
801 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 879 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
802 struct pc87360_data *data = pc87360_update_device(dev); 880 struct pc87360_data *data = pc87360_update_device(dev);
803 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[attr->index])); 881 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[attr->index]));
804} 882}
805static ssize_t show_temp_max(struct device *dev, struct device_attribute *devattr, char *buf) 883
884static ssize_t show_temp_max(struct device *dev,
885 struct device_attribute *devattr, char *buf)
806{ 886{
807 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 887 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
808 struct pc87360_data *data = pc87360_update_device(dev); 888 struct pc87360_data *data = pc87360_update_device(dev);
809 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[attr->index])); 889 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[attr->index]));
810} 890}
811static ssize_t show_temp_crit(struct device *dev, struct device_attribute *devattr, char *buf) 891
892static ssize_t show_temp_crit(struct device *dev,
893 struct device_attribute *devattr, char *buf)
812{ 894{
813 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 895 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
814 struct pc87360_data *data = pc87360_update_device(dev); 896 struct pc87360_data *data = pc87360_update_device(dev);
815 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[attr->index])); 897 return sprintf(buf, "%d\n",
898 TEMP_FROM_REG(data->temp_crit[attr->index]));
816} 899}
817static ssize_t show_temp_status(struct device *dev, struct device_attribute *devattr, char *buf) 900
901static ssize_t show_temp_status(struct device *dev,
902 struct device_attribute *devattr, char *buf)
818{ 903{
819 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 904 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
820 struct pc87360_data *data = pc87360_update_device(dev); 905 struct pc87360_data *data = pc87360_update_device(dev);
821 return sprintf(buf, "%d\n", data->temp_status[attr->index]); 906 return sprintf(buf, "%d\n", data->temp_status[attr->index]);
822} 907}
823static ssize_t set_temp_min(struct device *dev, struct device_attribute *devattr, const char *buf, 908
824 size_t count) 909static ssize_t set_temp_min(struct device *dev,
910 struct device_attribute *devattr,
911 const char *buf, size_t count)
825{ 912{
826 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 913 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
827 struct pc87360_data *data = dev_get_drvdata(dev); 914 struct pc87360_data *data = dev_get_drvdata(dev);
828 long val = simple_strtol(buf, NULL, 10); 915 long val;
916 int err;
917
918 err = kstrtol(buf, 10, &val);
919 if (err)
920 return err;
829 921
830 mutex_lock(&data->update_lock); 922 mutex_lock(&data->update_lock);
831 data->temp_min[attr->index] = TEMP_TO_REG(val); 923 data->temp_min[attr->index] = TEMP_TO_REG(val);
@@ -834,12 +926,19 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *devattr
834 mutex_unlock(&data->update_lock); 926 mutex_unlock(&data->update_lock);
835 return count; 927 return count;
836} 928}
837static ssize_t set_temp_max(struct device *dev, struct device_attribute *devattr, const char *buf, 929
838 size_t count) 930static ssize_t set_temp_max(struct device *dev,
931 struct device_attribute *devattr,
932 const char *buf, size_t count)
839{ 933{
840 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 934 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
841 struct pc87360_data *data = dev_get_drvdata(dev); 935 struct pc87360_data *data = dev_get_drvdata(dev);
842 long val = simple_strtol(buf, NULL, 10); 936 long val;
937 int err;
938
939 err = kstrtol(buf, 10, &val);
940 if (err)
941 return err;
843 942
844 mutex_lock(&data->update_lock); 943 mutex_lock(&data->update_lock);
845 data->temp_max[attr->index] = TEMP_TO_REG(val); 944 data->temp_max[attr->index] = TEMP_TO_REG(val);
@@ -848,12 +947,19 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *devattr
848 mutex_unlock(&data->update_lock); 947 mutex_unlock(&data->update_lock);
849 return count; 948 return count;
850} 949}
851static ssize_t set_temp_crit(struct device *dev, struct device_attribute *devattr, const char *buf, 950
852 size_t count) 951static ssize_t set_temp_crit(struct device *dev,
952 struct device_attribute *devattr, const char *buf,
953 size_t count)
853{ 954{
854 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 955 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
855 struct pc87360_data *data = dev_get_drvdata(dev); 956 struct pc87360_data *data = dev_get_drvdata(dev);
856 long val = simple_strtol(buf, NULL, 10); 957 long val;
958 int err;
959
960 err = kstrtol(buf, 10, &val);
961 if (err)
962 return err;
857 963
858 mutex_lock(&data->update_lock); 964 mutex_lock(&data->update_lock);
859 data->temp_crit[attr->index] = TEMP_TO_REG(val); 965 data->temp_crit[attr->index] = TEMP_TO_REG(val);
@@ -898,16 +1004,20 @@ static struct sensor_device_attribute temp_crit[] = {
898 show_temp_crit, set_temp_crit, 2), 1004 show_temp_crit, set_temp_crit, 2),
899}; 1005};
900 1006
901static ssize_t show_temp_alarms(struct device *dev, struct device_attribute *attr, char *buf) 1007static ssize_t show_temp_alarms(struct device *dev,
1008 struct device_attribute *attr, char *buf)
902{ 1009{
903 struct pc87360_data *data = pc87360_update_device(dev); 1010 struct pc87360_data *data = pc87360_update_device(dev);
904 return sprintf(buf, "%u\n", data->temp_alarms); 1011 return sprintf(buf, "%u\n", data->temp_alarms);
905} 1012}
1013
906static DEVICE_ATTR(alarms_temp, S_IRUGO, show_temp_alarms, NULL); 1014static DEVICE_ATTR(alarms_temp, S_IRUGO, show_temp_alarms, NULL);
907 1015
908/* show_temp_min/max_alarm() reads data from the per-channel status 1016/*
909 register (sec 12.3.7), not the temp event status registers (sec 1017 * show_temp_min/max_alarm() reads data from the per-channel status
910 12.3.2) that show_temp_alarm() reads (via data->temp_alarms) */ 1018 * register (sec 12.3.7), not the temp event status registers (sec
1019 * 12.3.2) that show_temp_alarm() reads (via data->temp_alarms)
1020 */
911 1021
912static ssize_t show_temp_min_alarm(struct device *dev, 1022static ssize_t show_temp_min_alarm(struct device *dev,
913 struct device_attribute *devattr, char *buf) 1023 struct device_attribute *devattr, char *buf)
@@ -917,6 +1027,7 @@ static ssize_t show_temp_min_alarm(struct device *dev,
917 1027
918 return sprintf(buf, "%u\n", !!(data->temp_status[nr] & CHAN_ALM_MIN)); 1028 return sprintf(buf, "%u\n", !!(data->temp_status[nr] & CHAN_ALM_MIN));
919} 1029}
1030
920static ssize_t show_temp_max_alarm(struct device *dev, 1031static ssize_t show_temp_max_alarm(struct device *dev,
921 struct device_attribute *devattr, char *buf) 1032 struct device_attribute *devattr, char *buf)
922{ 1033{
@@ -925,6 +1036,7 @@ static ssize_t show_temp_max_alarm(struct device *dev,
925 1036
926 return sprintf(buf, "%u\n", !!(data->temp_status[nr] & CHAN_ALM_MAX)); 1037 return sprintf(buf, "%u\n", !!(data->temp_status[nr] & CHAN_ALM_MAX));
927} 1038}
1039
928static ssize_t show_temp_crit_alarm(struct device *dev, 1040static ssize_t show_temp_crit_alarm(struct device *dev,
929 struct device_attribute *devattr, char *buf) 1041 struct device_attribute *devattr, char *buf)
930{ 1042{
@@ -939,11 +1051,13 @@ static struct sensor_device_attribute temp_min_alarm[] = {
939 SENSOR_ATTR(temp2_min_alarm, S_IRUGO, show_temp_min_alarm, NULL, 1), 1051 SENSOR_ATTR(temp2_min_alarm, S_IRUGO, show_temp_min_alarm, NULL, 1),
940 SENSOR_ATTR(temp3_min_alarm, S_IRUGO, show_temp_min_alarm, NULL, 2), 1052 SENSOR_ATTR(temp3_min_alarm, S_IRUGO, show_temp_min_alarm, NULL, 2),
941}; 1053};
1054
942static struct sensor_device_attribute temp_max_alarm[] = { 1055static struct sensor_device_attribute temp_max_alarm[] = {
943 SENSOR_ATTR(temp1_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 0), 1056 SENSOR_ATTR(temp1_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 0),
944 SENSOR_ATTR(temp2_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 1), 1057 SENSOR_ATTR(temp2_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 1),
945 SENSOR_ATTR(temp3_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 2), 1058 SENSOR_ATTR(temp3_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 2),
946}; 1059};
1060
947static struct sensor_device_attribute temp_crit_alarm[] = { 1061static struct sensor_device_attribute temp_crit_alarm[] = {
948 SENSOR_ATTR(temp1_crit_alarm, S_IRUGO, show_temp_crit_alarm, NULL, 0), 1062 SENSOR_ATTR(temp1_crit_alarm, S_IRUGO, show_temp_crit_alarm, NULL, 0),
949 SENSOR_ATTR(temp2_crit_alarm, S_IRUGO, show_temp_crit_alarm, NULL, 1), 1063 SENSOR_ATTR(temp2_crit_alarm, S_IRUGO, show_temp_crit_alarm, NULL, 1),
@@ -965,27 +1079,29 @@ static struct sensor_device_attribute temp_fault[] = {
965 SENSOR_ATTR(temp3_fault, S_IRUGO, show_temp_fault, NULL, 2), 1079 SENSOR_ATTR(temp3_fault, S_IRUGO, show_temp_fault, NULL, 2),
966}; 1080};
967 1081
968#define TEMP_UNIT_ATTRS(X) \ 1082#define TEMP_UNIT_ATTRS(X) \
969 &temp_input[X].dev_attr.attr, \ 1083{ &temp_input[X].dev_attr.attr, \
970 &temp_status[X].dev_attr.attr, \ 1084 &temp_status[X].dev_attr.attr, \
971 &temp_min[X].dev_attr.attr, \ 1085 &temp_min[X].dev_attr.attr, \
972 &temp_max[X].dev_attr.attr, \ 1086 &temp_max[X].dev_attr.attr, \
973 &temp_crit[X].dev_attr.attr, \ 1087 &temp_crit[X].dev_attr.attr, \
974 &temp_min_alarm[X].dev_attr.attr, \ 1088 &temp_min_alarm[X].dev_attr.attr, \
975 &temp_max_alarm[X].dev_attr.attr, \ 1089 &temp_max_alarm[X].dev_attr.attr, \
976 &temp_crit_alarm[X].dev_attr.attr, \ 1090 &temp_crit_alarm[X].dev_attr.attr, \
977 &temp_fault[X].dev_attr.attr 1091 &temp_fault[X].dev_attr.attr, \
978 1092 NULL \
979static struct attribute * pc8736x_temp_attr_array[] = { 1093}
1094
1095static struct attribute *pc8736x_temp_attr[][10] = {
980 TEMP_UNIT_ATTRS(0), 1096 TEMP_UNIT_ATTRS(0),
981 TEMP_UNIT_ATTRS(1), 1097 TEMP_UNIT_ATTRS(1),
982 TEMP_UNIT_ATTRS(2), 1098 TEMP_UNIT_ATTRS(2)
983 /* include the few miscellaneous atts here */
984 &dev_attr_alarms_temp.attr,
985 NULL
986}; 1099};
987static const struct attribute_group pc8736x_temp_group = { 1100
988 .attrs = pc8736x_temp_attr_array, 1101static const struct attribute_group pc8736x_temp_attr_group[] = {
1102 { .attrs = pc8736x_temp_attr[0] },
1103 { .attrs = pc8736x_temp_attr[1] },
1104 { .attrs = pc8736x_temp_attr[2] }
989}; 1105};
990 1106
991static ssize_t show_name(struct device *dev, 1107static ssize_t show_name(struct device *dev,
@@ -994,13 +1110,15 @@ static ssize_t show_name(struct device *dev,
994 struct pc87360_data *data = dev_get_drvdata(dev); 1110 struct pc87360_data *data = dev_get_drvdata(dev);
995 return sprintf(buf, "%s\n", data->name); 1111 return sprintf(buf, "%s\n", data->name);
996} 1112}
1113
997static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 1114static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
998 1115
999/* 1116/*
1000 * Device detection, registration and update 1117 * Device detection, registration and update
1001 */ 1118 */
1002 1119
1003static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses) 1120static int __init pc87360_find(int sioaddr, u8 *devid,
1121 unsigned short *addresses)
1004{ 1122{
1005 u16 val; 1123 u16 val;
1006 int i; 1124 int i;
@@ -1047,7 +1165,7 @@ static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses
1047 1165
1048 addresses[i] = val; 1166 addresses[i] = val;
1049 1167
1050 if (i==0) { /* Fans */ 1168 if (i == 0) { /* Fans */
1051 confreg[0] = superio_inb(sioaddr, 0xF0); 1169 confreg[0] = superio_inb(sioaddr, 0xF0);
1052 confreg[1] = superio_inb(sioaddr, 0xF1); 1170 confreg[1] = superio_inb(sioaddr, 0xF1);
1053 1171
@@ -1060,12 +1178,14 @@ static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses
1060 pr_debug("Fan %d: mon=%d ctrl=%d inv=%d\n", 3, 1178 pr_debug("Fan %d: mon=%d ctrl=%d inv=%d\n", 3,
1061 confreg[1] & 1, (confreg[1] >> 1) & 1, 1179 confreg[1] & 1, (confreg[1] >> 1) & 1,
1062 (confreg[1] >> 2) & 1); 1180 (confreg[1] >> 2) & 1);
1063 } else if (i==1) { /* Voltages */ 1181 } else if (i == 1) { /* Voltages */
1064 /* Are we using thermistors? */ 1182 /* Are we using thermistors? */
1065 if (*devid == 0xE9) { /* PC87366 */ 1183 if (*devid == 0xE9) { /* PC87366 */
1066 /* These registers are not logical-device 1184 /*
1067 specific, just that we won't need them if 1185 * These registers are not logical-device
1068 we don't use the VLM device */ 1186 * specific, just that we won't need them if
1187 * we don't use the VLM device
1188 */
1069 confreg[2] = superio_inb(sioaddr, 0x2B); 1189 confreg[2] = superio_inb(sioaddr, 0x2B);
1070 confreg[3] = superio_inb(sioaddr, 0x25); 1190 confreg[3] = superio_inb(sioaddr, 0x25);
1071 1191
@@ -1085,6 +1205,22 @@ static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses
1085 return 0; 1205 return 0;
1086} 1206}
1087 1207
1208static void pc87360_remove_files(struct device *dev)
1209{
1210 int i;
1211
1212 device_remove_file(dev, &dev_attr_name);
1213 device_remove_file(dev, &dev_attr_alarms_temp);
1214 for (i = 0; i < ARRAY_SIZE(pc8736x_temp_attr_group); i++)
1215 sysfs_remove_group(&dev->kobj, &pc8736x_temp_attr_group[i]);
1216 for (i = 0; i < ARRAY_SIZE(pc8736x_fan_attr_group); i++) {
1217 sysfs_remove_group(&pdev->dev.kobj, &pc8736x_fan_attr_group[i]);
1218 device_remove_file(dev, &pwm[i].dev_attr);
1219 }
1220 sysfs_remove_group(&dev->kobj, &pc8736x_therm_group);
1221 sysfs_remove_group(&dev->kobj, &pc8736x_vin_group);
1222}
1223
1088static int __devinit pc87360_probe(struct platform_device *pdev) 1224static int __devinit pc87360_probe(struct platform_device *pdev)
1089{ 1225{
1090 int i; 1226 int i;
@@ -1094,7 +1230,8 @@ static int __devinit pc87360_probe(struct platform_device *pdev)
1094 int use_thermistors = 0; 1230 int use_thermistors = 0;
1095 struct device *dev = &pdev->dev; 1231 struct device *dev = &pdev->dev;
1096 1232
1097 if (!(data = kzalloc(sizeof(struct pc87360_data), GFP_KERNEL))) 1233 data = kzalloc(sizeof(struct pc87360_data), GFP_KERNEL);
1234 if (!data)
1098 return -ENOMEM; 1235 return -ENOMEM;
1099 1236
1100 data->fannr = 2; 1237 data->fannr = 2;
@@ -1130,9 +1267,10 @@ static int __devinit pc87360_probe(struct platform_device *pdev)
1130 platform_set_drvdata(pdev, data); 1267 platform_set_drvdata(pdev, data);
1131 1268
1132 for (i = 0; i < LDNI_MAX; i++) { 1269 for (i = 0; i < LDNI_MAX; i++) {
1133 if (((data->address[i] = extra_isa[i])) 1270 data->address[i] = extra_isa[i];
1271 if (data->address[i]
1134 && !request_region(extra_isa[i], PC87360_EXTENT, 1272 && !request_region(extra_isa[i], PC87360_EXTENT,
1135 pc87360_driver.driver.name)) { 1273 pc87360_driver.driver.name)) {
1136 dev_err(dev, "Region 0x%x-0x%x already " 1274 dev_err(dev, "Region 0x%x-0x%x already "
1137 "in use!\n", extra_isa[i], 1275 "in use!\n", extra_isa[i],
1138 extra_isa[i]+PC87360_EXTENT-1); 1276 extra_isa[i]+PC87360_EXTENT-1);
@@ -1147,9 +1285,11 @@ static int __devinit pc87360_probe(struct platform_device *pdev)
1147 if (data->fannr) 1285 if (data->fannr)
1148 data->fan_conf = confreg[0] | (confreg[1] << 8); 1286 data->fan_conf = confreg[0] | (confreg[1] << 8);
1149 1287
1150 /* Use the correct reference voltage 1288 /*
1151 Unless both the VLM and the TMS logical devices agree to 1289 * Use the correct reference voltage
1152 use an external Vref, the internal one is used. */ 1290 * Unless both the VLM and the TMS logical devices agree to
1291 * use an external Vref, the internal one is used.
1292 */
1153 if (data->innr) { 1293 if (data->innr) {
1154 i = pc87360_read_value(data, LD_IN, NO_BANK, 1294 i = pc87360_read_value(data, LD_IN, NO_BANK,
1155 PC87365_REG_IN_CONFIG); 1295 PC87365_REG_IN_CONFIG);
@@ -1182,62 +1322,48 @@ static int __devinit pc87360_probe(struct platform_device *pdev)
1182 1322
1183 /* Register all-or-nothing sysfs groups */ 1323 /* Register all-or-nothing sysfs groups */
1184 1324
1185 if (data->innr && 1325 if (data->innr) {
1186 (err = sysfs_create_group(&dev->kobj, 1326 err = sysfs_create_group(&dev->kobj, &pc8736x_vin_group);
1187 &pc8736x_vin_group))) 1327 if (err)
1188 goto ERROR3; 1328 goto ERROR3;
1329 }
1189 1330
1190 if (data->innr == 14 && 1331 if (data->innr == 14) {
1191 (err = sysfs_create_group(&dev->kobj, 1332 err = sysfs_create_group(&dev->kobj, &pc8736x_therm_group);
1192 &pc8736x_therm_group))) 1333 if (err)
1193 goto ERROR3; 1334 goto ERROR3;
1335 }
1194 1336
1195 /* create device attr-files for varying sysfs groups */ 1337 /* create device attr-files for varying sysfs groups */
1196 1338
1197 if (data->tempnr) { 1339 if (data->tempnr) {
1198 for (i = 0; i < data->tempnr; i++) { 1340 for (i = 0; i < data->tempnr; i++) {
1199 if ((err = device_create_file(dev, 1341 err = sysfs_create_group(&dev->kobj,
1200 &temp_input[i].dev_attr)) 1342 &pc8736x_temp_attr_group[i]);
1201 || (err = device_create_file(dev, 1343 if (err)
1202 &temp_min[i].dev_attr))
1203 || (err = device_create_file(dev,
1204 &temp_max[i].dev_attr))
1205 || (err = device_create_file(dev,
1206 &temp_crit[i].dev_attr))
1207 || (err = device_create_file(dev,
1208 &temp_status[i].dev_attr))
1209 || (err = device_create_file(dev,
1210 &temp_min_alarm[i].dev_attr))
1211 || (err = device_create_file(dev,
1212 &temp_max_alarm[i].dev_attr))
1213 || (err = device_create_file(dev,
1214 &temp_crit_alarm[i].dev_attr))
1215 || (err = device_create_file(dev,
1216 &temp_fault[i].dev_attr)))
1217 goto ERROR3; 1344 goto ERROR3;
1218 } 1345 }
1219 if ((err = device_create_file(dev, &dev_attr_alarms_temp))) 1346 err = device_create_file(dev, &dev_attr_alarms_temp);
1347 if (err)
1220 goto ERROR3; 1348 goto ERROR3;
1221 } 1349 }
1222 1350
1223 for (i = 0; i < data->fannr; i++) { 1351 for (i = 0; i < data->fannr; i++) {
1224 if (FAN_CONFIG_MONITOR(data->fan_conf, i) 1352 if (FAN_CONFIG_MONITOR(data->fan_conf, i)) {
1225 && ((err = device_create_file(dev, 1353 err = sysfs_create_group(&dev->kobj,
1226 &fan_input[i].dev_attr)) 1354 &pc8736x_fan_attr_group[i]);
1227 || (err = device_create_file(dev, 1355 if (err)
1228 &fan_min[i].dev_attr)) 1356 goto ERROR3;
1229 || (err = device_create_file(dev, 1357 }
1230 &fan_div[i].dev_attr)) 1358 if (FAN_CONFIG_CONTROL(data->fan_conf, i)) {
1231 || (err = device_create_file(dev, 1359 err = device_create_file(dev, &pwm[i].dev_attr);
1232 &fan_status[i].dev_attr)))) 1360 if (err)
1233 goto ERROR3; 1361 goto ERROR3;
1234 1362 }
1235 if (FAN_CONFIG_CONTROL(data->fan_conf, i)
1236 && (err = device_create_file(dev, &pwm[i].dev_attr)))
1237 goto ERROR3;
1238 } 1363 }
1239 1364
1240 if ((err = device_create_file(dev, &dev_attr_name))) 1365 err = device_create_file(dev, &dev_attr_name);
1366 if (err)
1241 goto ERROR3; 1367 goto ERROR3;
1242 1368
1243 data->hwmon_dev = hwmon_device_register(dev); 1369 data->hwmon_dev = hwmon_device_register(dev);
@@ -1248,16 +1374,10 @@ static int __devinit pc87360_probe(struct platform_device *pdev)
1248 return 0; 1374 return 0;
1249 1375
1250ERROR3: 1376ERROR3:
1251 device_remove_file(dev, &dev_attr_name); 1377 pc87360_remove_files(dev);
1252 /* can still remove groups whose members were added individually */
1253 sysfs_remove_group(&dev->kobj, &pc8736x_temp_group);
1254 sysfs_remove_group(&dev->kobj, &pc8736x_fan_group);
1255 sysfs_remove_group(&dev->kobj, &pc8736x_therm_group);
1256 sysfs_remove_group(&dev->kobj, &pc8736x_vin_group);
1257 for (i = 0; i < 3; i++) { 1378 for (i = 0; i < 3; i++) {
1258 if (data->address[i]) { 1379 if (data->address[i])
1259 release_region(data->address[i], PC87360_EXTENT); 1380 release_region(data->address[i], PC87360_EXTENT);
1260 }
1261 } 1381 }
1262ERROR1: 1382ERROR1:
1263 kfree(data); 1383 kfree(data);
@@ -1270,25 +1390,20 @@ static int __devexit pc87360_remove(struct platform_device *pdev)
1270 int i; 1390 int i;
1271 1391
1272 hwmon_device_unregister(data->hwmon_dev); 1392 hwmon_device_unregister(data->hwmon_dev);
1273 1393 pc87360_remove_files(&pdev->dev);
1274 device_remove_file(&pdev->dev, &dev_attr_name);
1275 sysfs_remove_group(&pdev->dev.kobj, &pc8736x_temp_group);
1276 sysfs_remove_group(&pdev->dev.kobj, &pc8736x_fan_group);
1277 sysfs_remove_group(&pdev->dev.kobj, &pc8736x_therm_group);
1278 sysfs_remove_group(&pdev->dev.kobj, &pc8736x_vin_group);
1279
1280 for (i = 0; i < 3; i++) { 1394 for (i = 0; i < 3; i++) {
1281 if (data->address[i]) { 1395 if (data->address[i])
1282 release_region(data->address[i], PC87360_EXTENT); 1396 release_region(data->address[i], PC87360_EXTENT);
1283 }
1284 } 1397 }
1285 kfree(data); 1398 kfree(data);
1286 1399
1287 return 0; 1400 return 0;
1288} 1401}
1289 1402
1290/* ldi is the logical device index 1403/*
1291 bank is for voltages and temperatures only */ 1404 * ldi is the logical device index
1405 * bank is for voltages and temperatures only
1406 */
1292static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank, 1407static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank,
1293 u8 reg) 1408 u8 reg)
1294{ 1409{
@@ -1359,8 +1474,10 @@ static void pc87360_init_device(struct platform_device *pdev,
1359 } 1474 }
1360 } 1475 }
1361 1476
1362 /* We can't blindly trust the Super-I/O space configuration bit, 1477 /*
1363 most BIOS won't set it properly */ 1478 * We can't blindly trust the Super-I/O space configuration bit,
1479 * most BIOS won't set it properly
1480 */
1364 dev_dbg(&pdev->dev, "bios thermistors:%d\n", use_thermistors); 1481 dev_dbg(&pdev->dev, "bios thermistors:%d\n", use_thermistors);
1365 for (i = 11; i < data->innr; i++) { 1482 for (i = 11; i < data->innr; i++) {
1366 reg = pc87360_read_value(data, LD_IN, i, 1483 reg = pc87360_read_value(data, LD_IN, i,
@@ -1375,12 +1492,12 @@ static void pc87360_init_device(struct platform_device *pdev,
1375 for (; i < data->tempnr; i++) { 1492 for (; i < data->tempnr; i++) {
1376 reg = pc87360_read_value(data, LD_TEMP, i, 1493 reg = pc87360_read_value(data, LD_TEMP, i,
1377 PC87365_REG_TEMP_STATUS); 1494 PC87365_REG_TEMP_STATUS);
1378 dev_dbg(&pdev->dev, "bios temp%d_status:0x%02x\n", i+1, reg); 1495 dev_dbg(&pdev->dev, "bios temp%d_status:0x%02x\n", i + 1, reg);
1379 if (init >= init_temp[i]) { 1496 if (init >= init_temp[i]) {
1380 /* Forcibly enable temperature channel */ 1497 /* Forcibly enable temperature channel */
1381 if (!(reg & CHAN_ENA)) { 1498 if (!(reg & CHAN_ENA)) {
1382 dev_dbg(&pdev->dev, "Forcibly " 1499 dev_dbg(&pdev->dev,
1383 "enabling temp%d\n", i+1); 1500 "Forcibly enabling temp%d\n", i + 1);
1384 pc87360_write_value(data, LD_TEMP, i, 1501 pc87360_write_value(data, LD_TEMP, i,
1385 PC87365_REG_TEMP_STATUS, 1502 PC87365_REG_TEMP_STATUS,
1386 0xCF); 1503 0xCF);
@@ -1391,14 +1508,16 @@ static void pc87360_init_device(struct platform_device *pdev,
1391 if (use_thermistors) { 1508 if (use_thermistors) {
1392 for (i = 11; i < data->innr; i++) { 1509 for (i = 11; i < data->innr; i++) {
1393 if (init >= init_in[i]) { 1510 if (init >= init_in[i]) {
1394 /* The pin may already be used by thermal 1511 /*
1395 diodes */ 1512 * The pin may already be used by thermal
1513 * diodes
1514 */
1396 reg = pc87360_read_value(data, LD_TEMP, 1515 reg = pc87360_read_value(data, LD_TEMP,
1397 (i-11)/2, PC87365_REG_TEMP_STATUS); 1516 (i - 11) / 2, PC87365_REG_TEMP_STATUS);
1398 if (reg & CHAN_ENA) { 1517 if (reg & CHAN_ENA) {
1399 dev_dbg(&pdev->dev, "Skipping " 1518 dev_dbg(&pdev->dev,
1400 "temp%d, pin already in use " 1519 "Skipping temp%d, pin already in use by temp%d\n",
1401 "by temp%d\n", i-7, (i-11)/2); 1520 i - 7, (i - 11) / 2);
1402 continue; 1521 continue;
1403 } 1522 }
1404 1523
@@ -1406,8 +1525,9 @@ static void pc87360_init_device(struct platform_device *pdev,
1406 reg = pc87360_read_value(data, LD_IN, i, 1525 reg = pc87360_read_value(data, LD_IN, i,
1407 PC87365_REG_IN_STATUS); 1526 PC87365_REG_IN_STATUS);
1408 if (!(reg & CHAN_ENA)) { 1527 if (!(reg & CHAN_ENA)) {
1409 dev_dbg(&pdev->dev, "Forcibly " 1528 dev_dbg(&pdev->dev,
1410 "enabling temp%d\n", i-7); 1529 "Forcibly enabling temp%d\n",
1530 i - 7);
1411 pc87360_write_value(data, LD_IN, i, 1531 pc87360_write_value(data, LD_IN, i,
1412 PC87365_REG_TEMP_STATUS, 1532 PC87365_REG_TEMP_STATUS,
1413 (reg & 0x60) | 0x8F); 1533 (reg & 0x60) | 0x8F);
@@ -1421,8 +1541,8 @@ static void pc87360_init_device(struct platform_device *pdev,
1421 PC87365_REG_IN_CONFIG); 1541 PC87365_REG_IN_CONFIG);
1422 dev_dbg(&pdev->dev, "bios vin-cfg:0x%02x\n", reg); 1542 dev_dbg(&pdev->dev, "bios vin-cfg:0x%02x\n", reg);
1423 if (reg & CHAN_ENA) { 1543 if (reg & CHAN_ENA) {
1424 dev_dbg(&pdev->dev, "Forcibly " 1544 dev_dbg(&pdev->dev,
1425 "enabling monitoring (VLM)\n"); 1545 "Forcibly enabling monitoring (VLM)\n");
1426 pc87360_write_value(data, LD_IN, NO_BANK, 1546 pc87360_write_value(data, LD_IN, NO_BANK,
1427 PC87365_REG_IN_CONFIG, 1547 PC87365_REG_IN_CONFIG,
1428 reg & 0xFE); 1548 reg & 0xFE);
@@ -1434,8 +1554,8 @@ static void pc87360_init_device(struct platform_device *pdev,
1434 PC87365_REG_TEMP_CONFIG); 1554 PC87365_REG_TEMP_CONFIG);
1435 dev_dbg(&pdev->dev, "bios temp-cfg:0x%02x\n", reg); 1555 dev_dbg(&pdev->dev, "bios temp-cfg:0x%02x\n", reg);
1436 if (reg & CHAN_ENA) { 1556 if (reg & CHAN_ENA) {
1437 dev_dbg(&pdev->dev, "Forcibly enabling " 1557 dev_dbg(&pdev->dev,
1438 "monitoring (TMS)\n"); 1558 "Forcibly enabling monitoring (TMS)\n");
1439 pc87360_write_value(data, LD_TEMP, NO_BANK, 1559 pc87360_write_value(data, LD_TEMP, NO_BANK,
1440 PC87365_REG_TEMP_CONFIG, 1560 PC87365_REG_TEMP_CONFIG,
1441 reg & 0xFE); 1561 reg & 0xFE);
@@ -1444,10 +1564,12 @@ static void pc87360_init_device(struct platform_device *pdev,
1444 if (init >= 2) { 1564 if (init >= 2) {
1445 /* Chip config as documented by National Semi. */ 1565 /* Chip config as documented by National Semi. */
1446 pc87360_write_value(data, LD_TEMP, 0xF, 0xA, 0x08); 1566 pc87360_write_value(data, LD_TEMP, 0xF, 0xA, 0x08);
1447 /* We voluntarily omit the bank here, in case the 1567 /*
1448 sequence itself matters. It shouldn't be a problem, 1568 * We voluntarily omit the bank here, in case the
1449 since nobody else is supposed to access the 1569 * sequence itself matters. It shouldn't be a problem,
1450 device at that point. */ 1570 * since nobody else is supposed to access the
1571 * device at that point.
1572 */
1451 pc87360_write_value(data, LD_TEMP, NO_BANK, 0xB, 0x04); 1573 pc87360_write_value(data, LD_TEMP, NO_BANK, 0xB, 0x04);
1452 pc87360_write_value(data, LD_TEMP, NO_BANK, 0xC, 0x35); 1574 pc87360_write_value(data, LD_TEMP, NO_BANK, 0xC, 0x35);
1453 pc87360_write_value(data, LD_TEMP, NO_BANK, 0xD, 0x05); 1575 pc87360_write_value(data, LD_TEMP, NO_BANK, 0xD, 0x05);
@@ -1470,7 +1592,7 @@ static void pc87360_autodiv(struct device *dev, int nr)
1470 data->fan[nr] >>= 1; 1592 data->fan[nr] >>= 1;
1471 dev_dbg(dev, "Increasing " 1593 dev_dbg(dev, "Increasing "
1472 "clock divider to %d for fan %d\n", 1594 "clock divider to %d for fan %d\n",
1473 FAN_DIV_FROM_REG(data->fan_status[nr]), nr+1); 1595 FAN_DIV_FROM_REG(data->fan_status[nr]), nr + 1);
1474 } 1596 }
1475 } else { 1597 } else {
1476 /* Decrease clock divider if possible */ 1598 /* Decrease clock divider if possible */
@@ -1483,7 +1605,7 @@ static void pc87360_autodiv(struct device *dev, int nr)
1483 dev_dbg(dev, "Decreasing " 1605 dev_dbg(dev, "Decreasing "
1484 "clock divider to %d for fan %d\n", 1606 "clock divider to %d for fan %d\n",
1485 FAN_DIV_FROM_REG(data->fan_status[nr]), 1607 FAN_DIV_FROM_REG(data->fan_status[nr]),
1486 nr+1); 1608 nr + 1);
1487 } 1609 }
1488 } 1610 }
1489 1611
diff --git a/drivers/hwmon/pc87427.c b/drivers/hwmon/pc87427.c
index cb35461d52d9..37059a3755e9 100644
--- a/drivers/hwmon/pc87427.c
+++ b/drivers/hwmon/pc87427.c
@@ -46,9 +46,11 @@ static struct platform_device *pdev;
46 46
47#define DRVNAME "pc87427" 47#define DRVNAME "pc87427"
48 48
49/* The lock mutex protects both the I/O accesses (needed because the 49/*
50 device is using banked registers) and the register cache (needed to keep 50 * The lock mutex protects both the I/O accesses (needed because the
51 the data in the registers and the cache in sync at any time). */ 51 * device is using banked registers) and the register cache (needed to keep
52 * the data in the registers and the cache in sync at any time).
53 */
52struct pc87427_data { 54struct pc87427_data {
53 struct device *hwmon_dev; 55 struct device *hwmon_dev;
54 struct mutex lock; 56 struct mutex lock;
@@ -173,10 +175,12 @@ static inline void pc87427_write8_bank(struct pc87427_data *data, u8 ldi,
173#define FAN_STATUS_LOSPD (1 << 1) 175#define FAN_STATUS_LOSPD (1 << 1)
174#define FAN_STATUS_MONEN (1 << 0) 176#define FAN_STATUS_MONEN (1 << 0)
175 177
176/* Dedicated function to read all registers related to a given fan input. 178/*
177 This saves us quite a few locks and bank selections. 179 * Dedicated function to read all registers related to a given fan input.
178 Must be called with data->lock held. 180 * This saves us quite a few locks and bank selections.
179 nr is from 0 to 7 */ 181 * Must be called with data->lock held.
182 * nr is from 0 to 7
183 */
180static void pc87427_readall_fan(struct pc87427_data *data, u8 nr) 184static void pc87427_readall_fan(struct pc87427_data *data, u8 nr)
181{ 185{
182 int iobase = data->address[LD_FAN]; 186 int iobase = data->address[LD_FAN];
@@ -189,8 +193,10 @@ static void pc87427_readall_fan(struct pc87427_data *data, u8 nr)
189 outb(data->fan_status[nr], iobase + PC87427_REG_FAN_STATUS); 193 outb(data->fan_status[nr], iobase + PC87427_REG_FAN_STATUS);
190} 194}
191 195
192/* The 2 LSB of fan speed registers are used for something different. 196/*
193 The actual 2 LSB of the measurements are not available. */ 197 * The 2 LSB of fan speed registers are used for something different.
198 * The actual 2 LSB of the measurements are not available.
199 */
194static inline unsigned long fan_from_reg(u16 reg) 200static inline unsigned long fan_from_reg(u16 reg)
195{ 201{
196 reg &= 0xfffc; 202 reg &= 0xfffc;
@@ -224,10 +230,12 @@ static inline u16 fan_to_reg(unsigned long val)
224#define PWM_MODE_OFF (2 << 4) 230#define PWM_MODE_OFF (2 << 4)
225#define PWM_MODE_ON (7 << 4) 231#define PWM_MODE_ON (7 << 4)
226 232
227/* Dedicated function to read all registers related to a given PWM output. 233/*
228 This saves us quite a few locks and bank selections. 234 * Dedicated function to read all registers related to a given PWM output.
229 Must be called with data->lock held. 235 * This saves us quite a few locks and bank selections.
230 nr is from 0 to 3 */ 236 * Must be called with data->lock held.
237 * nr is from 0 to 3
238 */
231static void pc87427_readall_pwm(struct pc87427_data *data, u8 nr) 239static void pc87427_readall_pwm(struct pc87427_data *data, u8 nr)
232{ 240{
233 int iobase = data->address[LD_FAN]; 241 int iobase = data->address[LD_FAN];
@@ -286,10 +294,12 @@ static inline u8 pwm_enable_to_reg(unsigned long val, u8 pwmval)
286#define TEMP_TYPE_REMOTE_DIODE (2 << 5) 294#define TEMP_TYPE_REMOTE_DIODE (2 << 5)
287#define TEMP_TYPE_LOCAL_DIODE (3 << 5) 295#define TEMP_TYPE_LOCAL_DIODE (3 << 5)
288 296
289/* Dedicated function to read all registers related to a given temperature 297/*
290 input. This saves us quite a few locks and bank selections. 298 * Dedicated function to read all registers related to a given temperature
291 Must be called with data->lock held. 299 * input. This saves us quite a few locks and bank selections.
292 nr is from 0 to 5 */ 300 * Must be called with data->lock held.
301 * nr is from 0 to 5
302 */
293static void pc87427_readall_temp(struct pc87427_data *data, u8 nr) 303static void pc87427_readall_temp(struct pc87427_data *data, u8 nr)
294{ 304{
295 int iobase = data->address[LD_TEMP]; 305 int iobase = data->address[LD_TEMP];
@@ -318,8 +328,10 @@ static inline unsigned int temp_type_from_reg(u8 reg)
318 } 328 }
319} 329}
320 330
321/* We assume 8-bit thermal sensors; 9-bit thermal sensors are possible 331/*
322 too, but I have no idea how to figure out when they are used. */ 332 * We assume 8-bit thermal sensors; 9-bit thermal sensors are possible
333 * too, but I have no idea how to figure out when they are used.
334 */
323static inline long temp_from_reg(s16 reg) 335static inline long temp_from_reg(s16 reg)
324{ 336{
325 return reg * 1000 / 256; 337 return reg * 1000 / 256;
@@ -423,9 +435,11 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute
423 435
424 mutex_lock(&data->lock); 436 mutex_lock(&data->lock);
425 outb(BANK_FM(nr), iobase + PC87427_REG_BANK); 437 outb(BANK_FM(nr), iobase + PC87427_REG_BANK);
426 /* The low speed limit registers are read-only while monitoring 438 /*
427 is enabled, so we have to disable monitoring, then change the 439 * The low speed limit registers are read-only while monitoring
428 limit, and finally enable monitoring again. */ 440 * is enabled, so we have to disable monitoring, then change the
441 * limit, and finally enable monitoring again.
442 */
429 outb(0, iobase + PC87427_REG_FAN_STATUS); 443 outb(0, iobase + PC87427_REG_FAN_STATUS);
430 data->fan_min[nr] = fan_to_reg(val); 444 data->fan_min[nr] = fan_to_reg(val);
431 outw(data->fan_min[nr], iobase + PC87427_REG_FAN_MIN); 445 outw(data->fan_min[nr], iobase + PC87427_REG_FAN_MIN);
@@ -542,8 +556,10 @@ static const struct attribute_group pc87427_group_fan[8] = {
542 { .attrs = pc87427_attributes_fan[7] }, 556 { .attrs = pc87427_attributes_fan[7] },
543}; 557};
544 558
545/* Must be called with data->lock held and pc87427_readall_pwm() freshly 559/*
546 called */ 560 * Must be called with data->lock held and pc87427_readall_pwm() freshly
561 * called
562 */
547static void update_pwm_enable(struct pc87427_data *data, int nr, u8 mode) 563static void update_pwm_enable(struct pc87427_data *data, int nr, u8 mode)
548{ 564{
549 int iobase = data->address[LD_FAN]; 565 int iobase = data->address[LD_FAN];
@@ -1023,9 +1039,11 @@ static void __devinit pc87427_init_device(struct device *dev)
1023 if (reg & PWM_ENABLE_CTLEN) 1039 if (reg & PWM_ENABLE_CTLEN)
1024 data->pwm_enabled |= (1 << i); 1040 data->pwm_enabled |= (1 << i);
1025 1041
1026 /* We don't expose an interface to reconfigure the automatic 1042 /*
1027 fan control mode, so only allow to return to this mode if 1043 * We don't expose an interface to reconfigure the automatic
1028 it was originally set. */ 1044 * fan control mode, so only allow to return to this mode if
1045 * it was originally set.
1046 */
1029 if ((reg & PWM_ENABLE_MODE_MASK) == PWM_MODE_AUTO) { 1047 if ((reg & PWM_ENABLE_MODE_MASK) == PWM_MODE_AUTO) {
1030 dev_dbg(dev, "PWM%d is in automatic control mode\n", 1048 dev_dbg(dev, "PWM%d is in automatic control mode\n",
1031 i + 1); 1049 i + 1);
diff --git a/drivers/hwmon/pcf8591.c b/drivers/hwmon/pcf8591.c
index 731b09af76b9..4174c7463d70 100644
--- a/drivers/hwmon/pcf8591.c
+++ b/drivers/hwmon/pcf8591.c
@@ -1,22 +1,22 @@
1/* 1/*
2 Copyright (C) 2001-2004 Aurelien Jarno <aurelien@aurel32.net> 2 * Copyright (C) 2001-2004 Aurelien Jarno <aurelien@aurel32.net>
3 Ported to Linux 2.6 by Aurelien Jarno <aurelien@aurel32.net> with 3 * Ported to Linux 2.6 by Aurelien Jarno <aurelien@aurel32.net> with
4 the help of Jean Delvare <khali@linux-fr.org> 4 * the help of Jean Delvare <khali@linux-fr.org>
5 5 *
6 This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or 8 * the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 9 * (at your option) any later version.
10 10 *
11 This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 * GNU General Public License for more details.
15 15 *
16 You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 19 */
20 20
21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22 22
@@ -39,28 +39,34 @@ MODULE_PARM_DESC(input_mode,
39 " 2 = single ended and differential mixed\n" 39 " 2 = single ended and differential mixed\n"
40 " 3 = two differential inputs\n"); 40 " 3 = two differential inputs\n");
41 41
42/* The PCF8591 control byte 42/*
43 7 6 5 4 3 2 1 0 43 * The PCF8591 control byte
44 | 0 |AOEF| AIP | 0 |AINC| AICH | */ 44 * 7 6 5 4 3 2 1 0
45 * | 0 |AOEF| AIP | 0 |AINC| AICH |
46 */
45 47
46/* Analog Output Enable Flag (analog output active if 1) */ 48/* Analog Output Enable Flag (analog output active if 1) */
47#define PCF8591_CONTROL_AOEF 0x40 49#define PCF8591_CONTROL_AOEF 0x40
48 50
49/* Analog Input Programming 51/*
50 0x00 = four single ended inputs 52 * Analog Input Programming
51 0x10 = three differential inputs 53 * 0x00 = four single ended inputs
52 0x20 = single ended and differential mixed 54 * 0x10 = three differential inputs
53 0x30 = two differential inputs */ 55 * 0x20 = single ended and differential mixed
56 * 0x30 = two differential inputs
57 */
54#define PCF8591_CONTROL_AIP_MASK 0x30 58#define PCF8591_CONTROL_AIP_MASK 0x30
55 59
56/* Autoincrement Flag (switch on if 1) */ 60/* Autoincrement Flag (switch on if 1) */
57#define PCF8591_CONTROL_AINC 0x04 61#define PCF8591_CONTROL_AINC 0x04
58 62
59/* Channel selection 63/*
60 0x00 = channel 0 64 * Channel selection
61 0x01 = channel 1 65 * 0x00 = channel 0
62 0x02 = channel 2 66 * 0x01 = channel 1
63 0x03 = channel 3 */ 67 * 0x02 = channel 2
68 * 0x03 = channel 3
69 */
64#define PCF8591_CONTROL_AICH_MASK 0x03 70#define PCF8591_CONTROL_AICH_MASK 0x03
65 71
66/* Initial values */ 72/* Initial values */
@@ -68,7 +74,7 @@ MODULE_PARM_DESC(input_mode,
68#define PCF8591_INIT_AOUT 0 /* DAC out = 0 */ 74#define PCF8591_INIT_AOUT 0 /* DAC out = 0 */
69 75
70/* Conversions */ 76/* Conversions */
71#define REG_TO_SIGNED(reg) (((reg) & 0x80)?((reg) - 256):(reg)) 77#define REG_TO_SIGNED(reg) (((reg) & 0x80) ? ((reg) - 256) : (reg))
72 78
73struct pcf8591_data { 79struct pcf8591_data {
74 struct device *hwmon_dev; 80 struct device *hwmon_dev;
@@ -83,7 +89,9 @@ static int pcf8591_read_channel(struct device *dev, int channel);
83 89
84/* following are the sysfs callback functions */ 90/* following are the sysfs callback functions */
85#define show_in_channel(channel) \ 91#define show_in_channel(channel) \
86static ssize_t show_in##channel##_input(struct device *dev, struct device_attribute *attr, char *buf) \ 92static ssize_t show_in##channel##_input(struct device *dev, \
93 struct device_attribute *attr, \
94 char *buf) \
87{ \ 95{ \
88 return sprintf(buf, "%d\n", pcf8591_read_channel(dev, channel));\ 96 return sprintf(buf, "%d\n", pcf8591_read_channel(dev, channel));\
89} \ 97} \
@@ -95,39 +103,57 @@ show_in_channel(1);
95show_in_channel(2); 103show_in_channel(2);
96show_in_channel(3); 104show_in_channel(3);
97 105
98static ssize_t show_out0_ouput(struct device *dev, struct device_attribute *attr, char *buf) 106static ssize_t show_out0_ouput(struct device *dev,
107 struct device_attribute *attr, char *buf)
99{ 108{
100 struct pcf8591_data *data = i2c_get_clientdata(to_i2c_client(dev)); 109 struct pcf8591_data *data = i2c_get_clientdata(to_i2c_client(dev));
101 return sprintf(buf, "%d\n", data->aout * 10); 110 return sprintf(buf, "%d\n", data->aout * 10);
102} 111}
103 112
104static ssize_t set_out0_output(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 113static ssize_t set_out0_output(struct device *dev,
114 struct device_attribute *attr,
115 const char *buf, size_t count)
105{ 116{
106 unsigned int value; 117 unsigned long val;
107 struct i2c_client *client = to_i2c_client(dev); 118 struct i2c_client *client = to_i2c_client(dev);
108 struct pcf8591_data *data = i2c_get_clientdata(client); 119 struct pcf8591_data *data = i2c_get_clientdata(client);
109 if ((value = (simple_strtoul(buf, NULL, 10) + 5) / 10) <= 255) { 120 int err;
110 data->aout = value; 121
111 i2c_smbus_write_byte_data(client, data->control, data->aout); 122 err = kstrtoul(buf, 10, &val);
112 return count; 123 if (err)
113 } 124 return err;
114 return -EINVAL; 125
126 val /= 10;
127 if (val > 255)
128 return -EINVAL;
129
130 data->aout = val;
131 i2c_smbus_write_byte_data(client, data->control, data->aout);
132 return count;
115} 133}
116 134
117static DEVICE_ATTR(out0_output, S_IWUSR | S_IRUGO, 135static DEVICE_ATTR(out0_output, S_IWUSR | S_IRUGO,
118 show_out0_ouput, set_out0_output); 136 show_out0_ouput, set_out0_output);
119 137
120static ssize_t show_out0_enable(struct device *dev, struct device_attribute *attr, char *buf) 138static ssize_t show_out0_enable(struct device *dev,
139 struct device_attribute *attr, char *buf)
121{ 140{
122 struct pcf8591_data *data = i2c_get_clientdata(to_i2c_client(dev)); 141 struct pcf8591_data *data = i2c_get_clientdata(to_i2c_client(dev));
123 return sprintf(buf, "%u\n", !(!(data->control & PCF8591_CONTROL_AOEF))); 142 return sprintf(buf, "%u\n", !(!(data->control & PCF8591_CONTROL_AOEF)));
124} 143}
125 144
126static ssize_t set_out0_enable(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 145static ssize_t set_out0_enable(struct device *dev,
146 struct device_attribute *attr,
147 const char *buf, size_t count)
127{ 148{
128 struct i2c_client *client = to_i2c_client(dev); 149 struct i2c_client *client = to_i2c_client(dev);
129 struct pcf8591_data *data = i2c_get_clientdata(client); 150 struct pcf8591_data *data = i2c_get_clientdata(client);
130 unsigned long val = simple_strtoul(buf, NULL, 10); 151 unsigned long val;
152 int err;
153
154 err = kstrtoul(buf, 10, &val);
155 if (err)
156 return err;
131 157
132 mutex_lock(&data->update_lock); 158 mutex_lock(&data->update_lock);
133 if (val) 159 if (val)
@@ -174,7 +200,8 @@ static int pcf8591_probe(struct i2c_client *client,
174 struct pcf8591_data *data; 200 struct pcf8591_data *data;
175 int err; 201 int err;
176 202
177 if (!(data = kzalloc(sizeof(struct pcf8591_data), GFP_KERNEL))) { 203 data = kzalloc(sizeof(struct pcf8591_data), GFP_KERNEL);
204 if (!data) {
178 err = -ENOMEM; 205 err = -ENOMEM;
179 goto exit; 206 goto exit;
180 } 207 }
@@ -192,15 +219,15 @@ static int pcf8591_probe(struct i2c_client *client,
192 219
193 /* Register input2 if not in "two differential inputs" mode */ 220 /* Register input2 if not in "two differential inputs" mode */
194 if (input_mode != 3) { 221 if (input_mode != 3) {
195 if ((err = device_create_file(&client->dev, 222 err = device_create_file(&client->dev, &dev_attr_in2_input);
196 &dev_attr_in2_input))) 223 if (err)
197 goto exit_sysfs_remove; 224 goto exit_sysfs_remove;
198 } 225 }
199 226
200 /* Register input3 only in "four single ended inputs" mode */ 227 /* Register input3 only in "four single ended inputs" mode */
201 if (input_mode == 0) { 228 if (input_mode == 0) {
202 if ((err = device_create_file(&client->dev, 229 err = device_create_file(&client->dev, &dev_attr_in3_input);
203 &dev_attr_in3_input))) 230 if (err)
204 goto exit_sysfs_remove; 231 goto exit_sysfs_remove;
205 } 232 }
206 233
@@ -241,8 +268,10 @@ static void pcf8591_init_client(struct i2c_client *client)
241 268
242 i2c_smbus_write_byte_data(client, data->control, data->aout); 269 i2c_smbus_write_byte_data(client, data->control, data->aout);
243 270
244 /* The first byte transmitted contains the conversion code of the 271 /*
245 previous read cycle. FLUSH IT! */ 272 * The first byte transmitted contains the conversion code of the
273 * previous read cycle. FLUSH IT!
274 */
246 i2c_smbus_read_byte(client); 275 i2c_smbus_read_byte(client);
247} 276}
248 277
@@ -259,8 +288,10 @@ static int pcf8591_read_channel(struct device *dev, int channel)
259 | channel; 288 | channel;
260 i2c_smbus_write_byte(client, data->control); 289 i2c_smbus_write_byte(client, data->control);
261 290
262 /* The first byte transmitted contains the conversion code of 291 /*
263 the previous read cycle. FLUSH IT! */ 292 * The first byte transmitted contains the conversion code of
293 * the previous read cycle. FLUSH IT!
294 */
264 i2c_smbus_read_byte(client); 295 i2c_smbus_read_byte(client);
265 } 296 }
266 value = i2c_smbus_read_byte(client); 297 value = i2c_smbus_read_byte(client);
@@ -269,9 +300,9 @@ static int pcf8591_read_channel(struct device *dev, int channel)
269 300
270 if ((channel == 2 && input_mode == 2) || 301 if ((channel == 2 && input_mode == 2) ||
271 (channel != 3 && (input_mode == 1 || input_mode == 3))) 302 (channel != 3 && (input_mode == 1 || input_mode == 3)))
272 return (10 * REG_TO_SIGNED(value)); 303 return 10 * REG_TO_SIGNED(value);
273 else 304 else
274 return (10 * value); 305 return 10 * value;
275} 306}
276 307
277static const struct i2c_device_id pcf8591_id[] = { 308static const struct i2c_device_id pcf8591_id[] = {
diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
index cfec923f42b7..2ca6a5a4f5a7 100644
--- a/drivers/hwmon/pmbus/Kconfig
+++ b/drivers/hwmon/pmbus/Kconfig
@@ -20,7 +20,8 @@ config SENSORS_PMBUS
20 help 20 help
21 If you say yes here you get hardware monitoring support for generic 21 If you say yes here you get hardware monitoring support for generic
22 PMBus devices, including but not limited to ADP4000, BMR453, BMR454, 22 PMBus devices, including but not limited to ADP4000, BMR453, BMR454,
23 NCP4200, and NCP4208. 23 MDT040, NCP4200, NCP4208, PDT003, PDT006, PDT012, UDT020, TPS40400,
24 and TPS40422.
24 25
25 This driver can also be built as a module. If so, the module will 26 This driver can also be built as a module. If so, the module will
26 be called pmbus. 27 be called pmbus.
@@ -30,8 +31,8 @@ config SENSORS_ADM1275
30 default n 31 default n
31 help 32 help
32 If you say yes here you get hardware monitoring support for Analog 33 If you say yes here you get hardware monitoring support for Analog
33 Devices ADM1275 and ADM1276 Hot-Swap Controller and Digital Power 34 Devices ADM1075, ADM1275, and ADM1276 Hot-Swap Controller and Digital
34 Monitor. 35 Power Monitors.
35 36
36 This driver can also be built as a module. If so, the module will 37 This driver can also be built as a module. If so, the module will
37 be called adm1275. 38 be called adm1275.
@@ -67,11 +68,11 @@ config SENSORS_MAX16064
67 be called max16064. 68 be called max16064.
68 69
69config SENSORS_MAX34440 70config SENSORS_MAX34440
70 tristate "Maxim MAX34440/MAX34441" 71 tristate "Maxim MAX34440 and compatibles"
71 default n 72 default n
72 help 73 help
73 If you say yes here you get hardware monitoring support for Maxim 74 If you say yes here you get hardware monitoring support for Maxim
74 MAX34440 and MAX34441. 75 MAX34440, MAX34441, and MAX34446.
75 76
76 This driver can also be built as a module. If so, the module will 77 This driver can also be built as a module. If so, the module will
77 be called max34440. 78 be called max34440.
@@ -113,9 +114,9 @@ config SENSORS_ZL6100
113 default n 114 default n
114 help 115 help
115 If you say yes here you get hardware monitoring support for Intersil 116 If you say yes here you get hardware monitoring support for Intersil
116 ZL2004, ZL2005, ZL2006, ZL2008, ZL2105, ZL2106, ZL6100, and ZL6105 117 ZL2004, ZL2005, ZL2006, ZL2008, ZL2105, ZL2106, ZL6100, ZL6105,
117 Digital DC/DC Controllers, as well as for Ericsson BMR450, BMR451, 118 ZL9101M, and ZL9117M Digital DC/DC Controllers, as well as for
118 BMR462, BMR463, and BMR464. 119 Ericsson BMR450, BMR451, BMR462, BMR463, and BMR464.
119 120
120 This driver can also be built as a module. If so, the module will 121 This driver can also be built as a module. If so, the module will
121 be called zl6100. 122 be called zl6100.
diff --git a/drivers/hwmon/pmbus/adm1275.c b/drivers/hwmon/pmbus/adm1275.c
index 81c7c2ead6f3..60aad9570f01 100644
--- a/drivers/hwmon/pmbus/adm1275.c
+++ b/drivers/hwmon/pmbus/adm1275.c
@@ -23,7 +23,7 @@
23#include <linux/i2c.h> 23#include <linux/i2c.h>
24#include "pmbus.h" 24#include "pmbus.h"
25 25
26enum chips { adm1275, adm1276 }; 26enum chips { adm1075, adm1275, adm1276 };
27 27
28#define ADM1275_PEAK_IOUT 0xd0 28#define ADM1275_PEAK_IOUT 0xd0
29#define ADM1275_PEAK_VIN 0xd1 29#define ADM1275_PEAK_VIN 0xd1
@@ -32,6 +32,9 @@ enum chips { adm1275, adm1276 };
32 32
33#define ADM1275_VIN_VOUT_SELECT (1 << 6) 33#define ADM1275_VIN_VOUT_SELECT (1 << 6)
34#define ADM1275_VRANGE (1 << 5) 34#define ADM1275_VRANGE (1 << 5)
35#define ADM1075_IRANGE_50 (1 << 4)
36#define ADM1075_IRANGE_25 (1 << 3)
37#define ADM1075_IRANGE_MASK ((1 << 3) | (1 << 4))
35 38
36#define ADM1275_IOUT_WARN2_LIMIT 0xd7 39#define ADM1275_IOUT_WARN2_LIMIT 0xd7
37#define ADM1275_DEVICE_CONFIG 0xd8 40#define ADM1275_DEVICE_CONFIG 0xd8
@@ -42,6 +45,14 @@ enum chips { adm1275, adm1276 };
42 45
43#define ADM1275_MFR_STATUS_IOUT_WARN2 (1 << 0) 46#define ADM1275_MFR_STATUS_IOUT_WARN2 (1 << 0)
44 47
48#define ADM1075_READ_VAUX 0xdd
49#define ADM1075_VAUX_OV_WARN_LIMIT 0xde
50#define ADM1075_VAUX_UV_WARN_LIMIT 0xdf
51#define ADM1075_VAUX_STATUS 0xf6
52
53#define ADM1075_VAUX_OV_WARN (1<<7)
54#define ADM1075_VAUX_UV_WARN (1<<6)
55
45struct adm1275_data { 56struct adm1275_data {
46 int id; 57 int id;
47 bool have_oc_fault; 58 bool have_oc_fault;
@@ -74,6 +85,29 @@ static int adm1275_read_word_data(struct i2c_client *client, int page, int reg)
74 } 85 }
75 ret = pmbus_read_word_data(client, 0, ADM1275_IOUT_WARN2_LIMIT); 86 ret = pmbus_read_word_data(client, 0, ADM1275_IOUT_WARN2_LIMIT);
76 break; 87 break;
88 case PMBUS_VOUT_OV_WARN_LIMIT:
89 if (data->id != adm1075) {
90 ret = -ENODATA;
91 break;
92 }
93 ret = pmbus_read_word_data(client, 0,
94 ADM1075_VAUX_OV_WARN_LIMIT);
95 break;
96 case PMBUS_VOUT_UV_WARN_LIMIT:
97 if (data->id != adm1075) {
98 ret = -ENODATA;
99 break;
100 }
101 ret = pmbus_read_word_data(client, 0,
102 ADM1075_VAUX_UV_WARN_LIMIT);
103 break;
104 case PMBUS_READ_VOUT:
105 if (data->id != adm1075) {
106 ret = -ENODATA;
107 break;
108 }
109 ret = pmbus_read_word_data(client, 0, ADM1075_READ_VAUX);
110 break;
77 case PMBUS_VIRT_READ_IOUT_MAX: 111 case PMBUS_VIRT_READ_IOUT_MAX:
78 ret = pmbus_read_word_data(client, 0, ADM1275_PEAK_IOUT); 112 ret = pmbus_read_word_data(client, 0, ADM1275_PEAK_IOUT);
79 break; 113 break;
@@ -84,7 +118,7 @@ static int adm1275_read_word_data(struct i2c_client *client, int page, int reg)
84 ret = pmbus_read_word_data(client, 0, ADM1275_PEAK_VIN); 118 ret = pmbus_read_word_data(client, 0, ADM1275_PEAK_VIN);
85 break; 119 break;
86 case PMBUS_VIRT_READ_PIN_MAX: 120 case PMBUS_VIRT_READ_PIN_MAX:
87 if (data->id != adm1276) { 121 if (data->id == adm1275) {
88 ret = -ENXIO; 122 ret = -ENXIO;
89 break; 123 break;
90 } 124 }
@@ -95,7 +129,7 @@ static int adm1275_read_word_data(struct i2c_client *client, int page, int reg)
95 case PMBUS_VIRT_RESET_VIN_HISTORY: 129 case PMBUS_VIRT_RESET_VIN_HISTORY:
96 break; 130 break;
97 case PMBUS_VIRT_RESET_PIN_HISTORY: 131 case PMBUS_VIRT_RESET_PIN_HISTORY:
98 if (data->id != adm1276) 132 if (data->id == adm1275)
99 ret = -ENXIO; 133 ret = -ENXIO;
100 break; 134 break;
101 default: 135 default:
@@ -163,6 +197,19 @@ static int adm1275_read_byte_data(struct i2c_client *client, int page, int reg)
163 PB_IOUT_OC_FAULT : PB_IOUT_UC_FAULT; 197 PB_IOUT_OC_FAULT : PB_IOUT_UC_FAULT;
164 } 198 }
165 break; 199 break;
200 case PMBUS_STATUS_VOUT:
201 if (data->id != adm1075) {
202 ret = -ENODATA;
203 break;
204 }
205 ret = 0;
206 mfr_status = pmbus_read_byte_data(client, 0,
207 ADM1075_VAUX_STATUS);
208 if (mfr_status & ADM1075_VAUX_OV_WARN)
209 ret |= PB_VOLTAGE_OV_WARNING;
210 if (mfr_status & ADM1075_VAUX_UV_WARN)
211 ret |= PB_VOLTAGE_UV_WARNING;
212 break;
166 default: 213 default:
167 ret = -ENODATA; 214 ret = -ENODATA;
168 break; 215 break;
@@ -171,6 +218,7 @@ static int adm1275_read_byte_data(struct i2c_client *client, int page, int reg)
171} 218}
172 219
173static const struct i2c_device_id adm1275_id[] = { 220static const struct i2c_device_id adm1275_id[] = {
221 { "adm1075", adm1075 },
174 { "adm1275", adm1275 }, 222 { "adm1275", adm1275 },
175 { "adm1276", adm1276 }, 223 { "adm1276", adm1276 },
176 { } 224 { }
@@ -229,7 +277,8 @@ static int adm1275_probe(struct i2c_client *client,
229 if (device_config < 0) 277 if (device_config < 0)
230 return device_config; 278 return device_config;
231 279
232 data = kzalloc(sizeof(struct adm1275_data), GFP_KERNEL); 280 data = devm_kzalloc(&client->dev, sizeof(struct adm1275_data),
281 GFP_KERNEL);
233 if (!data) 282 if (!data)
234 return -ENOMEM; 283 return -ENOMEM;
235 284
@@ -250,7 +299,14 @@ static int adm1275_probe(struct i2c_client *client,
250 info->read_byte_data = adm1275_read_byte_data; 299 info->read_byte_data = adm1275_read_byte_data;
251 info->write_word_data = adm1275_write_word_data; 300 info->write_word_data = adm1275_write_word_data;
252 301
253 if (config & ADM1275_VRANGE) { 302 if (data->id == adm1075) {
303 info->m[PSC_VOLTAGE_IN] = 27169;
304 info->b[PSC_VOLTAGE_IN] = 0;
305 info->R[PSC_VOLTAGE_IN] = -1;
306 info->m[PSC_VOLTAGE_OUT] = 27169;
307 info->b[PSC_VOLTAGE_OUT] = 0;
308 info->R[PSC_VOLTAGE_OUT] = -1;
309 } else if (config & ADM1275_VRANGE) {
254 info->m[PSC_VOLTAGE_IN] = 19199; 310 info->m[PSC_VOLTAGE_IN] = 19199;
255 info->b[PSC_VOLTAGE_IN] = 0; 311 info->b[PSC_VOLTAGE_IN] = 0;
256 info->R[PSC_VOLTAGE_IN] = -2; 312 info->R[PSC_VOLTAGE_IN] = -2;
@@ -270,6 +326,31 @@ static int adm1275_probe(struct i2c_client *client,
270 data->have_oc_fault = true; 326 data->have_oc_fault = true;
271 327
272 switch (data->id) { 328 switch (data->id) {
329 case adm1075:
330 info->format[PSC_POWER] = direct;
331 info->b[PSC_POWER] = 0;
332 info->R[PSC_POWER] = -1;
333 switch (config & ADM1075_IRANGE_MASK) {
334 case ADM1075_IRANGE_25:
335 info->m[PSC_POWER] = 8549;
336 info->m[PSC_CURRENT_OUT] = 806;
337 break;
338 case ADM1075_IRANGE_50:
339 info->m[PSC_POWER] = 4279;
340 info->m[PSC_CURRENT_OUT] = 404;
341 break;
342 default:
343 dev_err(&client->dev, "Invalid input current range");
344 info->m[PSC_POWER] = 0;
345 info->m[PSC_CURRENT_OUT] = 0;
346 break;
347 }
348 info->func[0] |= PMBUS_HAVE_VIN | PMBUS_HAVE_PIN
349 | PMBUS_HAVE_STATUS_INPUT;
350 if (config & ADM1275_VIN_VOUT_SELECT)
351 info->func[0] |=
352 PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT;
353 break;
273 case adm1275: 354 case adm1275:
274 if (config & ADM1275_VIN_VOUT_SELECT) 355 if (config & ADM1275_VIN_VOUT_SELECT)
275 info->func[0] |= 356 info->func[0] |=
@@ -297,24 +378,7 @@ static int adm1275_probe(struct i2c_client *client,
297 break; 378 break;
298 } 379 }
299 380
300 ret = pmbus_do_probe(client, id, info); 381 return pmbus_do_probe(client, id, info);
301 if (ret)
302 goto err_mem;
303 return 0;
304
305err_mem:
306 kfree(data);
307 return ret;
308}
309
310static int adm1275_remove(struct i2c_client *client)
311{
312 const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
313 const struct adm1275_data *data = to_adm1275_data(info);
314
315 pmbus_do_remove(client);
316 kfree(data);
317 return 0;
318} 382}
319 383
320static struct i2c_driver adm1275_driver = { 384static struct i2c_driver adm1275_driver = {
@@ -322,22 +386,12 @@ static struct i2c_driver adm1275_driver = {
322 .name = "adm1275", 386 .name = "adm1275",
323 }, 387 },
324 .probe = adm1275_probe, 388 .probe = adm1275_probe,
325 .remove = adm1275_remove, 389 .remove = pmbus_do_remove,
326 .id_table = adm1275_id, 390 .id_table = adm1275_id,
327}; 391};
328 392
329static int __init adm1275_init(void) 393module_i2c_driver(adm1275_driver);
330{
331 return i2c_add_driver(&adm1275_driver);
332}
333
334static void __exit adm1275_exit(void)
335{
336 i2c_del_driver(&adm1275_driver);
337}
338 394
339MODULE_AUTHOR("Guenter Roeck"); 395MODULE_AUTHOR("Guenter Roeck");
340MODULE_DESCRIPTION("PMBus driver for Analog Devices ADM1275 and compatibles"); 396MODULE_DESCRIPTION("PMBus driver for Analog Devices ADM1275 and compatibles");
341MODULE_LICENSE("GPL"); 397MODULE_LICENSE("GPL");
342module_init(adm1275_init);
343module_exit(adm1275_exit);
diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c
index 84a37f0c8db6..c299392716af 100644
--- a/drivers/hwmon/pmbus/lm25066.c
+++ b/drivers/hwmon/pmbus/lm25066.c
@@ -176,7 +176,6 @@ static int lm25066_probe(struct i2c_client *client,
176 const struct i2c_device_id *id) 176 const struct i2c_device_id *id)
177{ 177{
178 int config; 178 int config;
179 int ret;
180 struct lm25066_data *data; 179 struct lm25066_data *data;
181 struct pmbus_driver_info *info; 180 struct pmbus_driver_info *info;
182 181
@@ -184,15 +183,14 @@ static int lm25066_probe(struct i2c_client *client,
184 I2C_FUNC_SMBUS_READ_BYTE_DATA)) 183 I2C_FUNC_SMBUS_READ_BYTE_DATA))
185 return -ENODEV; 184 return -ENODEV;
186 185
187 data = kzalloc(sizeof(struct lm25066_data), GFP_KERNEL); 186 data = devm_kzalloc(&client->dev, sizeof(struct lm25066_data),
187 GFP_KERNEL);
188 if (!data) 188 if (!data)
189 return -ENOMEM; 189 return -ENOMEM;
190 190
191 config = i2c_smbus_read_byte_data(client, LM25066_DEVICE_SETUP); 191 config = i2c_smbus_read_byte_data(client, LM25066_DEVICE_SETUP);
192 if (config < 0) { 192 if (config < 0)
193 ret = config; 193 return config;
194 goto err_mem;
195 }
196 194
197 data->id = id->driver_data; 195 data->id = id->driver_data;
198 info = &data->info; 196 info = &data->info;
@@ -291,28 +289,10 @@ static int lm25066_probe(struct i2c_client *client,
291 } 289 }
292 break; 290 break;
293 default: 291 default:
294 ret = -ENODEV; 292 return -ENODEV;
295 goto err_mem;
296 } 293 }
297 294
298 ret = pmbus_do_probe(client, id, info); 295 return pmbus_do_probe(client, id, info);
299 if (ret)
300 goto err_mem;
301 return 0;
302
303err_mem:
304 kfree(data);
305 return ret;
306}
307
308static int lm25066_remove(struct i2c_client *client)
309{
310 const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
311 const struct lm25066_data *data = to_lm25066_data(info);
312
313 pmbus_do_remove(client);
314 kfree(data);
315 return 0;
316} 296}
317 297
318static const struct i2c_device_id lm25066_id[] = { 298static const struct i2c_device_id lm25066_id[] = {
@@ -330,22 +310,12 @@ static struct i2c_driver lm25066_driver = {
330 .name = "lm25066", 310 .name = "lm25066",
331 }, 311 },
332 .probe = lm25066_probe, 312 .probe = lm25066_probe,
333 .remove = lm25066_remove, 313 .remove = pmbus_do_remove,
334 .id_table = lm25066_id, 314 .id_table = lm25066_id,
335}; 315};
336 316
337static int __init lm25066_init(void) 317module_i2c_driver(lm25066_driver);
338{
339 return i2c_add_driver(&lm25066_driver);
340}
341
342static void __exit lm25066_exit(void)
343{
344 i2c_del_driver(&lm25066_driver);
345}
346 318
347MODULE_AUTHOR("Guenter Roeck"); 319MODULE_AUTHOR("Guenter Roeck");
348MODULE_DESCRIPTION("PMBus driver for LM25066/LM5064/LM5066"); 320MODULE_DESCRIPTION("PMBus driver for LM25066/LM5064/LM5066");
349MODULE_LICENSE("GPL"); 321MODULE_LICENSE("GPL");
350module_init(lm25066_init);
351module_exit(lm25066_exit);
diff --git a/drivers/hwmon/pmbus/ltc2978.c b/drivers/hwmon/pmbus/ltc2978.c
index 820fff48910b..9652a2c92a24 100644
--- a/drivers/hwmon/pmbus/ltc2978.c
+++ b/drivers/hwmon/pmbus/ltc2978.c
@@ -287,7 +287,7 @@ MODULE_DEVICE_TABLE(i2c, ltc2978_id);
287static int ltc2978_probe(struct i2c_client *client, 287static int ltc2978_probe(struct i2c_client *client,
288 const struct i2c_device_id *id) 288 const struct i2c_device_id *id)
289{ 289{
290 int chip_id, ret, i; 290 int chip_id, i;
291 struct ltc2978_data *data; 291 struct ltc2978_data *data;
292 struct pmbus_driver_info *info; 292 struct pmbus_driver_info *info;
293 293
@@ -295,15 +295,14 @@ static int ltc2978_probe(struct i2c_client *client,
295 I2C_FUNC_SMBUS_READ_WORD_DATA)) 295 I2C_FUNC_SMBUS_READ_WORD_DATA))
296 return -ENODEV; 296 return -ENODEV;
297 297
298 data = kzalloc(sizeof(struct ltc2978_data), GFP_KERNEL); 298 data = devm_kzalloc(&client->dev, sizeof(struct ltc2978_data),
299 GFP_KERNEL);
299 if (!data) 300 if (!data)
300 return -ENOMEM; 301 return -ENOMEM;
301 302
302 chip_id = i2c_smbus_read_word_data(client, LTC2978_MFR_SPECIAL_ID); 303 chip_id = i2c_smbus_read_word_data(client, LTC2978_MFR_SPECIAL_ID);
303 if (chip_id < 0) { 304 if (chip_id < 0)
304 ret = chip_id; 305 return chip_id;
305 goto err_mem;
306 }
307 306
308 if (chip_id == LTC2978_ID_REV1 || chip_id == LTC2978_ID_REV2) { 307 if (chip_id == LTC2978_ID_REV1 || chip_id == LTC2978_ID_REV2) {
309 data->id = ltc2978; 308 data->id = ltc2978;
@@ -311,8 +310,7 @@ static int ltc2978_probe(struct i2c_client *client,
311 data->id = ltc3880; 310 data->id = ltc3880;
312 } else { 311 } else {
313 dev_err(&client->dev, "Unsupported chip ID 0x%x\n", chip_id); 312 dev_err(&client->dev, "Unsupported chip ID 0x%x\n", chip_id);
314 ret = -ENODEV; 313 return -ENODEV;
315 goto err_mem;
316 } 314 }
317 if (data->id != id->driver_data) 315 if (data->id != id->driver_data)
318 dev_warn(&client->dev, 316 dev_warn(&client->dev,
@@ -357,28 +355,10 @@ static int ltc2978_probe(struct i2c_client *client,
357 data->vout_min[1] = 0xffff; 355 data->vout_min[1] = 0xffff;
358 break; 356 break;
359 default: 357 default:
360 ret = -ENODEV; 358 return -ENODEV;
361 goto err_mem;
362 } 359 }
363 360
364 ret = pmbus_do_probe(client, id, info); 361 return pmbus_do_probe(client, id, info);
365 if (ret)
366 goto err_mem;
367 return 0;
368
369err_mem:
370 kfree(data);
371 return ret;
372}
373
374static int ltc2978_remove(struct i2c_client *client)
375{
376 const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
377 const struct ltc2978_data *data = to_ltc2978_data(info);
378
379 pmbus_do_remove(client);
380 kfree(data);
381 return 0;
382} 362}
383 363
384/* This is the driver that will be inserted */ 364/* This is the driver that will be inserted */
@@ -387,22 +367,12 @@ static struct i2c_driver ltc2978_driver = {
387 .name = "ltc2978", 367 .name = "ltc2978",
388 }, 368 },
389 .probe = ltc2978_probe, 369 .probe = ltc2978_probe,
390 .remove = ltc2978_remove, 370 .remove = pmbus_do_remove,
391 .id_table = ltc2978_id, 371 .id_table = ltc2978_id,
392}; 372};
393 373
394static int __init ltc2978_init(void) 374module_i2c_driver(ltc2978_driver);
395{
396 return i2c_add_driver(&ltc2978_driver);
397}
398
399static void __exit ltc2978_exit(void)
400{
401 i2c_del_driver(&ltc2978_driver);
402}
403 375
404MODULE_AUTHOR("Guenter Roeck"); 376MODULE_AUTHOR("Guenter Roeck");
405MODULE_DESCRIPTION("PMBus driver for LTC2978 and LTC3880"); 377MODULE_DESCRIPTION("PMBus driver for LTC2978 and LTC3880");
406MODULE_LICENSE("GPL"); 378MODULE_LICENSE("GPL");
407module_init(ltc2978_init);
408module_exit(ltc2978_exit);
diff --git a/drivers/hwmon/pmbus/max16064.c b/drivers/hwmon/pmbus/max16064.c
index 1d77cf4d2d44..fa237a3c3291 100644
--- a/drivers/hwmon/pmbus/max16064.c
+++ b/drivers/hwmon/pmbus/max16064.c
@@ -103,12 +103,6 @@ static int max16064_probe(struct i2c_client *client,
103 return pmbus_do_probe(client, id, &max16064_info); 103 return pmbus_do_probe(client, id, &max16064_info);
104} 104}
105 105
106static int max16064_remove(struct i2c_client *client)
107{
108 pmbus_do_remove(client);
109 return 0;
110}
111
112static const struct i2c_device_id max16064_id[] = { 106static const struct i2c_device_id max16064_id[] = {
113 {"max16064", 0}, 107 {"max16064", 0},
114 {} 108 {}
@@ -122,22 +116,12 @@ static struct i2c_driver max16064_driver = {
122 .name = "max16064", 116 .name = "max16064",
123 }, 117 },
124 .probe = max16064_probe, 118 .probe = max16064_probe,
125 .remove = max16064_remove, 119 .remove = pmbus_do_remove,
126 .id_table = max16064_id, 120 .id_table = max16064_id,
127}; 121};
128 122
129static int __init max16064_init(void) 123module_i2c_driver(max16064_driver);
130{
131 return i2c_add_driver(&max16064_driver);
132}
133
134static void __exit max16064_exit(void)
135{
136 i2c_del_driver(&max16064_driver);
137}
138 124
139MODULE_AUTHOR("Guenter Roeck"); 125MODULE_AUTHOR("Guenter Roeck");
140MODULE_DESCRIPTION("PMBus driver for Maxim MAX16064"); 126MODULE_DESCRIPTION("PMBus driver for Maxim MAX16064");
141MODULE_LICENSE("GPL"); 127MODULE_LICENSE("GPL");
142module_init(max16064_init);
143module_exit(max16064_exit);
diff --git a/drivers/hwmon/pmbus/max34440.c b/drivers/hwmon/pmbus/max34440.c
index 9b97a5b3cf3d..2ada7b021fbe 100644
--- a/drivers/hwmon/pmbus/max34440.c
+++ b/drivers/hwmon/pmbus/max34440.c
@@ -25,34 +25,82 @@
25#include <linux/i2c.h> 25#include <linux/i2c.h>
26#include "pmbus.h" 26#include "pmbus.h"
27 27
28enum chips { max34440, max34441 }; 28enum chips { max34440, max34441, max34446 };
29 29
30#define MAX34440_MFR_VOUT_PEAK 0xd4 30#define MAX34440_MFR_VOUT_PEAK 0xd4
31#define MAX34440_MFR_IOUT_PEAK 0xd5 31#define MAX34440_MFR_IOUT_PEAK 0xd5
32#define MAX34440_MFR_TEMPERATURE_PEAK 0xd6 32#define MAX34440_MFR_TEMPERATURE_PEAK 0xd6
33#define MAX34440_MFR_VOUT_MIN 0xd7
34
35#define MAX34446_MFR_POUT_PEAK 0xe0
36#define MAX34446_MFR_POUT_AVG 0xe1
37#define MAX34446_MFR_IOUT_AVG 0xe2
38#define MAX34446_MFR_TEMPERATURE_AVG 0xe3
33 39
34#define MAX34440_STATUS_OC_WARN (1 << 0) 40#define MAX34440_STATUS_OC_WARN (1 << 0)
35#define MAX34440_STATUS_OC_FAULT (1 << 1) 41#define MAX34440_STATUS_OC_FAULT (1 << 1)
36#define MAX34440_STATUS_OT_FAULT (1 << 5) 42#define MAX34440_STATUS_OT_FAULT (1 << 5)
37#define MAX34440_STATUS_OT_WARN (1 << 6) 43#define MAX34440_STATUS_OT_WARN (1 << 6)
38 44
45struct max34440_data {
46 int id;
47 struct pmbus_driver_info info;
48};
49
50#define to_max34440_data(x) container_of(x, struct max34440_data, info)
51
39static int max34440_read_word_data(struct i2c_client *client, int page, int reg) 52static int max34440_read_word_data(struct i2c_client *client, int page, int reg)
40{ 53{
41 int ret; 54 int ret;
55 const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
56 const struct max34440_data *data = to_max34440_data(info);
42 57
43 switch (reg) { 58 switch (reg) {
59 case PMBUS_VIRT_READ_VOUT_MIN:
60 ret = pmbus_read_word_data(client, page,
61 MAX34440_MFR_VOUT_MIN);
62 break;
44 case PMBUS_VIRT_READ_VOUT_MAX: 63 case PMBUS_VIRT_READ_VOUT_MAX:
45 ret = pmbus_read_word_data(client, page, 64 ret = pmbus_read_word_data(client, page,
46 MAX34440_MFR_VOUT_PEAK); 65 MAX34440_MFR_VOUT_PEAK);
47 break; 66 break;
67 case PMBUS_VIRT_READ_IOUT_AVG:
68 if (data->id != max34446)
69 return -ENXIO;
70 ret = pmbus_read_word_data(client, page,
71 MAX34446_MFR_IOUT_AVG);
72 break;
48 case PMBUS_VIRT_READ_IOUT_MAX: 73 case PMBUS_VIRT_READ_IOUT_MAX:
49 ret = pmbus_read_word_data(client, page, 74 ret = pmbus_read_word_data(client, page,
50 MAX34440_MFR_IOUT_PEAK); 75 MAX34440_MFR_IOUT_PEAK);
51 break; 76 break;
77 case PMBUS_VIRT_READ_POUT_AVG:
78 if (data->id != max34446)
79 return -ENXIO;
80 ret = pmbus_read_word_data(client, page,
81 MAX34446_MFR_POUT_AVG);
82 break;
83 case PMBUS_VIRT_READ_POUT_MAX:
84 if (data->id != max34446)
85 return -ENXIO;
86 ret = pmbus_read_word_data(client, page,
87 MAX34446_MFR_POUT_PEAK);
88 break;
89 case PMBUS_VIRT_READ_TEMP_AVG:
90 if (data->id != max34446)
91 return -ENXIO;
92 ret = pmbus_read_word_data(client, page,
93 MAX34446_MFR_TEMPERATURE_AVG);
94 break;
52 case PMBUS_VIRT_READ_TEMP_MAX: 95 case PMBUS_VIRT_READ_TEMP_MAX:
53 ret = pmbus_read_word_data(client, page, 96 ret = pmbus_read_word_data(client, page,
54 MAX34440_MFR_TEMPERATURE_PEAK); 97 MAX34440_MFR_TEMPERATURE_PEAK);
55 break; 98 break;
99 case PMBUS_VIRT_RESET_POUT_HISTORY:
100 if (data->id != max34446)
101 return -ENXIO;
102 ret = 0;
103 break;
56 case PMBUS_VIRT_RESET_VOUT_HISTORY: 104 case PMBUS_VIRT_RESET_VOUT_HISTORY:
57 case PMBUS_VIRT_RESET_IOUT_HISTORY: 105 case PMBUS_VIRT_RESET_IOUT_HISTORY:
58 case PMBUS_VIRT_RESET_TEMP_HISTORY: 106 case PMBUS_VIRT_RESET_TEMP_HISTORY:
@@ -68,21 +116,42 @@ static int max34440_read_word_data(struct i2c_client *client, int page, int reg)
68static int max34440_write_word_data(struct i2c_client *client, int page, 116static int max34440_write_word_data(struct i2c_client *client, int page,
69 int reg, u16 word) 117 int reg, u16 word)
70{ 118{
119 const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
120 const struct max34440_data *data = to_max34440_data(info);
71 int ret; 121 int ret;
72 122
73 switch (reg) { 123 switch (reg) {
124 case PMBUS_VIRT_RESET_POUT_HISTORY:
125 ret = pmbus_write_word_data(client, page,
126 MAX34446_MFR_POUT_PEAK, 0);
127 if (ret)
128 break;
129 ret = pmbus_write_word_data(client, page,
130 MAX34446_MFR_POUT_AVG, 0);
131 break;
74 case PMBUS_VIRT_RESET_VOUT_HISTORY: 132 case PMBUS_VIRT_RESET_VOUT_HISTORY:
75 ret = pmbus_write_word_data(client, page, 133 ret = pmbus_write_word_data(client, page,
134 MAX34440_MFR_VOUT_MIN, 0x7fff);
135 if (ret)
136 break;
137 ret = pmbus_write_word_data(client, page,
76 MAX34440_MFR_VOUT_PEAK, 0); 138 MAX34440_MFR_VOUT_PEAK, 0);
77 break; 139 break;
78 case PMBUS_VIRT_RESET_IOUT_HISTORY: 140 case PMBUS_VIRT_RESET_IOUT_HISTORY:
79 ret = pmbus_write_word_data(client, page, 141 ret = pmbus_write_word_data(client, page,
80 MAX34440_MFR_IOUT_PEAK, 0); 142 MAX34440_MFR_IOUT_PEAK, 0);
143 if (!ret && data->id == max34446)
144 ret = pmbus_write_word_data(client, page,
145 MAX34446_MFR_IOUT_AVG, 0);
146
81 break; 147 break;
82 case PMBUS_VIRT_RESET_TEMP_HISTORY: 148 case PMBUS_VIRT_RESET_TEMP_HISTORY:
83 ret = pmbus_write_word_data(client, page, 149 ret = pmbus_write_word_data(client, page,
84 MAX34440_MFR_TEMPERATURE_PEAK, 150 MAX34440_MFR_TEMPERATURE_PEAK,
85 0x8000); 151 0x8000);
152 if (!ret && data->id == max34446)
153 ret = pmbus_write_word_data(client, page,
154 MAX34446_MFR_TEMPERATURE_AVG, 0);
86 break; 155 break;
87 default: 156 default:
88 ret = -ENODATA; 157 ret = -ENODATA;
@@ -216,26 +285,66 @@ static struct pmbus_driver_info max34440_info[] = {
216 .read_word_data = max34440_read_word_data, 285 .read_word_data = max34440_read_word_data,
217 .write_word_data = max34440_write_word_data, 286 .write_word_data = max34440_write_word_data,
218 }, 287 },
288 [max34446] = {
289 .pages = 7,
290 .format[PSC_VOLTAGE_IN] = direct,
291 .format[PSC_VOLTAGE_OUT] = direct,
292 .format[PSC_TEMPERATURE] = direct,
293 .format[PSC_CURRENT_OUT] = direct,
294 .format[PSC_POWER] = direct,
295 .m[PSC_VOLTAGE_IN] = 1,
296 .b[PSC_VOLTAGE_IN] = 0,
297 .R[PSC_VOLTAGE_IN] = 3,
298 .m[PSC_VOLTAGE_OUT] = 1,
299 .b[PSC_VOLTAGE_OUT] = 0,
300 .R[PSC_VOLTAGE_OUT] = 3,
301 .m[PSC_CURRENT_OUT] = 1,
302 .b[PSC_CURRENT_OUT] = 0,
303 .R[PSC_CURRENT_OUT] = 3,
304 .m[PSC_POWER] = 1,
305 .b[PSC_POWER] = 0,
306 .R[PSC_POWER] = 3,
307 .m[PSC_TEMPERATURE] = 1,
308 .b[PSC_TEMPERATURE] = 0,
309 .R[PSC_TEMPERATURE] = 2,
310 .func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
311 | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_POUT,
312 .func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
313 | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
314 .func[2] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
315 | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_POUT,
316 .func[3] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT
317 | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT,
318 .func[4] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
319 .func[5] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
320 .func[6] = PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP,
321 .read_byte_data = max34440_read_byte_data,
322 .read_word_data = max34440_read_word_data,
323 .write_word_data = max34440_write_word_data,
324 },
219}; 325};
220 326
221static int max34440_probe(struct i2c_client *client, 327static int max34440_probe(struct i2c_client *client,
222 const struct i2c_device_id *id) 328 const struct i2c_device_id *id)
223{ 329{
224 return pmbus_do_probe(client, id, &max34440_info[id->driver_data]); 330 struct max34440_data *data;
225}
226 331
227static int max34440_remove(struct i2c_client *client) 332 data = devm_kzalloc(&client->dev, sizeof(struct max34440_data),
228{ 333 GFP_KERNEL);
229 pmbus_do_remove(client); 334 if (!data)
230 return 0; 335 return -ENOMEM;
336 data->id = id->driver_data;
337 data->info = max34440_info[id->driver_data];
338
339 return pmbus_do_probe(client, id, &data->info);
231} 340}
232 341
233static const struct i2c_device_id max34440_id[] = { 342static const struct i2c_device_id max34440_id[] = {
234 {"max34440", max34440}, 343 {"max34440", max34440},
235 {"max34441", max34441}, 344 {"max34441", max34441},
345 {"max34446", max34446},
236 {} 346 {}
237}; 347};
238
239MODULE_DEVICE_TABLE(i2c, max34440_id); 348MODULE_DEVICE_TABLE(i2c, max34440_id);
240 349
241/* This is the driver that will be inserted */ 350/* This is the driver that will be inserted */
@@ -244,22 +353,12 @@ static struct i2c_driver max34440_driver = {
244 .name = "max34440", 353 .name = "max34440",
245 }, 354 },
246 .probe = max34440_probe, 355 .probe = max34440_probe,
247 .remove = max34440_remove, 356 .remove = pmbus_do_remove,
248 .id_table = max34440_id, 357 .id_table = max34440_id,
249}; 358};
250 359
251static int __init max34440_init(void) 360module_i2c_driver(max34440_driver);
252{
253 return i2c_add_driver(&max34440_driver);
254}
255
256static void __exit max34440_exit(void)
257{
258 i2c_del_driver(&max34440_driver);
259}
260 361
261MODULE_AUTHOR("Guenter Roeck"); 362MODULE_AUTHOR("Guenter Roeck");
262MODULE_DESCRIPTION("PMBus driver for Maxim MAX34440/MAX34441"); 363MODULE_DESCRIPTION("PMBus driver for Maxim MAX34440/MAX34441");
263MODULE_LICENSE("GPL"); 364MODULE_LICENSE("GPL");
264module_init(max34440_init);
265module_exit(max34440_exit);
diff --git a/drivers/hwmon/pmbus/max8688.c b/drivers/hwmon/pmbus/max8688.c
index e2b74bb399ba..f04454a42fdd 100644
--- a/drivers/hwmon/pmbus/max8688.c
+++ b/drivers/hwmon/pmbus/max8688.c
@@ -180,12 +180,6 @@ static int max8688_probe(struct i2c_client *client,
180 return pmbus_do_probe(client, id, &max8688_info); 180 return pmbus_do_probe(client, id, &max8688_info);
181} 181}
182 182
183static int max8688_remove(struct i2c_client *client)
184{
185 pmbus_do_remove(client);
186 return 0;
187}
188
189static const struct i2c_device_id max8688_id[] = { 183static const struct i2c_device_id max8688_id[] = {
190 {"max8688", 0}, 184 {"max8688", 0},
191 { } 185 { }
@@ -199,22 +193,12 @@ static struct i2c_driver max8688_driver = {
199 .name = "max8688", 193 .name = "max8688",
200 }, 194 },
201 .probe = max8688_probe, 195 .probe = max8688_probe,
202 .remove = max8688_remove, 196 .remove = pmbus_do_remove,
203 .id_table = max8688_id, 197 .id_table = max8688_id,
204}; 198};
205 199
206static int __init max8688_init(void) 200module_i2c_driver(max8688_driver);
207{
208 return i2c_add_driver(&max8688_driver);
209}
210
211static void __exit max8688_exit(void)
212{
213 i2c_del_driver(&max8688_driver);
214}
215 201
216MODULE_AUTHOR("Guenter Roeck"); 202MODULE_AUTHOR("Guenter Roeck");
217MODULE_DESCRIPTION("PMBus driver for Maxim MAX8688"); 203MODULE_DESCRIPTION("PMBus driver for Maxim MAX8688");
218MODULE_LICENSE("GPL"); 204MODULE_LICENSE("GPL");
219module_init(max8688_init);
220module_exit(max8688_exit);
diff --git a/drivers/hwmon/pmbus/pmbus.c b/drivers/hwmon/pmbus/pmbus.c
index 18a385e753d7..7e91700131a7 100644
--- a/drivers/hwmon/pmbus/pmbus.c
+++ b/drivers/hwmon/pmbus/pmbus.c
@@ -166,33 +166,16 @@ static int pmbus_probe(struct i2c_client *client,
166 const struct i2c_device_id *id) 166 const struct i2c_device_id *id)
167{ 167{
168 struct pmbus_driver_info *info; 168 struct pmbus_driver_info *info;
169 int ret;
170 169
171 info = kzalloc(sizeof(struct pmbus_driver_info), GFP_KERNEL); 170 info = devm_kzalloc(&client->dev, sizeof(struct pmbus_driver_info),
171 GFP_KERNEL);
172 if (!info) 172 if (!info)
173 return -ENOMEM; 173 return -ENOMEM;
174 174
175 info->pages = id->driver_data; 175 info->pages = id->driver_data;
176 info->identify = pmbus_identify; 176 info->identify = pmbus_identify;
177 177
178 ret = pmbus_do_probe(client, id, info); 178 return pmbus_do_probe(client, id, info);
179 if (ret < 0)
180 goto out;
181 return 0;
182
183out:
184 kfree(info);
185 return ret;
186}
187
188static int pmbus_remove(struct i2c_client *client)
189{
190 const struct pmbus_driver_info *info;
191
192 info = pmbus_get_driver_info(client);
193 pmbus_do_remove(client);
194 kfree(info);
195 return 0;
196} 179}
197 180
198/* 181/*
@@ -202,12 +185,15 @@ static const struct i2c_device_id pmbus_id[] = {
202 {"adp4000", 1}, 185 {"adp4000", 1},
203 {"bmr453", 1}, 186 {"bmr453", 1},
204 {"bmr454", 1}, 187 {"bmr454", 1},
188 {"mdt040", 1},
205 {"ncp4200", 1}, 189 {"ncp4200", 1},
206 {"ncp4208", 1}, 190 {"ncp4208", 1},
207 {"pdt003", 1}, 191 {"pdt003", 1},
208 {"pdt006", 1}, 192 {"pdt006", 1},
209 {"pdt012", 1}, 193 {"pdt012", 1},
210 {"pmbus", 0}, 194 {"pmbus", 0},
195 {"tps40400", 1},
196 {"tps40422", 2},
211 {"udt020", 1}, 197 {"udt020", 1},
212 {} 198 {}
213}; 199};
@@ -220,22 +206,12 @@ static struct i2c_driver pmbus_driver = {
220 .name = "pmbus", 206 .name = "pmbus",
221 }, 207 },
222 .probe = pmbus_probe, 208 .probe = pmbus_probe,
223 .remove = pmbus_remove, 209 .remove = pmbus_do_remove,
224 .id_table = pmbus_id, 210 .id_table = pmbus_id,
225}; 211};
226 212
227static int __init pmbus_init(void) 213module_i2c_driver(pmbus_driver);
228{
229 return i2c_add_driver(&pmbus_driver);
230}
231
232static void __exit pmbus_exit(void)
233{
234 i2c_del_driver(&pmbus_driver);
235}
236 214
237MODULE_AUTHOR("Guenter Roeck"); 215MODULE_AUTHOR("Guenter Roeck");
238MODULE_DESCRIPTION("Generic PMBus driver"); 216MODULE_DESCRIPTION("Generic PMBus driver");
239MODULE_LICENSE("GPL"); 217MODULE_LICENSE("GPL");
240module_init(pmbus_init);
241module_exit(pmbus_exit);
diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h
index 5d31d1c2c0f5..3fe03dc47eb7 100644
--- a/drivers/hwmon/pmbus/pmbus.h
+++ b/drivers/hwmon/pmbus/pmbus.h
@@ -146,31 +146,36 @@
146 * code when reading or writing virtual registers. 146 * code when reading or writing virtual registers.
147 */ 147 */
148#define PMBUS_VIRT_BASE 0x100 148#define PMBUS_VIRT_BASE 0x100
149#define PMBUS_VIRT_READ_TEMP_MIN (PMBUS_VIRT_BASE + 0) 149#define PMBUS_VIRT_READ_TEMP_AVG (PMBUS_VIRT_BASE + 0)
150#define PMBUS_VIRT_READ_TEMP_MAX (PMBUS_VIRT_BASE + 1) 150#define PMBUS_VIRT_READ_TEMP_MIN (PMBUS_VIRT_BASE + 1)
151#define PMBUS_VIRT_RESET_TEMP_HISTORY (PMBUS_VIRT_BASE + 2) 151#define PMBUS_VIRT_READ_TEMP_MAX (PMBUS_VIRT_BASE + 2)
152#define PMBUS_VIRT_READ_VIN_AVG (PMBUS_VIRT_BASE + 3) 152#define PMBUS_VIRT_RESET_TEMP_HISTORY (PMBUS_VIRT_BASE + 3)
153#define PMBUS_VIRT_READ_VIN_MIN (PMBUS_VIRT_BASE + 4) 153#define PMBUS_VIRT_READ_VIN_AVG (PMBUS_VIRT_BASE + 4)
154#define PMBUS_VIRT_READ_VIN_MAX (PMBUS_VIRT_BASE + 5) 154#define PMBUS_VIRT_READ_VIN_MIN (PMBUS_VIRT_BASE + 5)
155#define PMBUS_VIRT_RESET_VIN_HISTORY (PMBUS_VIRT_BASE + 6) 155#define PMBUS_VIRT_READ_VIN_MAX (PMBUS_VIRT_BASE + 6)
156#define PMBUS_VIRT_READ_IIN_AVG (PMBUS_VIRT_BASE + 7) 156#define PMBUS_VIRT_RESET_VIN_HISTORY (PMBUS_VIRT_BASE + 7)
157#define PMBUS_VIRT_READ_IIN_MIN (PMBUS_VIRT_BASE + 8) 157#define PMBUS_VIRT_READ_IIN_AVG (PMBUS_VIRT_BASE + 8)
158#define PMBUS_VIRT_READ_IIN_MAX (PMBUS_VIRT_BASE + 9) 158#define PMBUS_VIRT_READ_IIN_MIN (PMBUS_VIRT_BASE + 9)
159#define PMBUS_VIRT_RESET_IIN_HISTORY (PMBUS_VIRT_BASE + 10) 159#define PMBUS_VIRT_READ_IIN_MAX (PMBUS_VIRT_BASE + 10)
160#define PMBUS_VIRT_READ_PIN_AVG (PMBUS_VIRT_BASE + 11) 160#define PMBUS_VIRT_RESET_IIN_HISTORY (PMBUS_VIRT_BASE + 11)
161#define PMBUS_VIRT_READ_PIN_MAX (PMBUS_VIRT_BASE + 12) 161#define PMBUS_VIRT_READ_PIN_AVG (PMBUS_VIRT_BASE + 12)
162#define PMBUS_VIRT_RESET_PIN_HISTORY (PMBUS_VIRT_BASE + 13) 162#define PMBUS_VIRT_READ_PIN_MAX (PMBUS_VIRT_BASE + 13)
163#define PMBUS_VIRT_READ_VOUT_AVG (PMBUS_VIRT_BASE + 14) 163#define PMBUS_VIRT_RESET_PIN_HISTORY (PMBUS_VIRT_BASE + 14)
164#define PMBUS_VIRT_READ_VOUT_MIN (PMBUS_VIRT_BASE + 15) 164#define PMBUS_VIRT_READ_POUT_AVG (PMBUS_VIRT_BASE + 15)
165#define PMBUS_VIRT_READ_VOUT_MAX (PMBUS_VIRT_BASE + 16) 165#define PMBUS_VIRT_READ_POUT_MAX (PMBUS_VIRT_BASE + 16)
166#define PMBUS_VIRT_RESET_VOUT_HISTORY (PMBUS_VIRT_BASE + 17) 166#define PMBUS_VIRT_RESET_POUT_HISTORY (PMBUS_VIRT_BASE + 17)
167#define PMBUS_VIRT_READ_IOUT_AVG (PMBUS_VIRT_BASE + 18) 167#define PMBUS_VIRT_READ_VOUT_AVG (PMBUS_VIRT_BASE + 18)
168#define PMBUS_VIRT_READ_IOUT_MIN (PMBUS_VIRT_BASE + 19) 168#define PMBUS_VIRT_READ_VOUT_MIN (PMBUS_VIRT_BASE + 19)
169#define PMBUS_VIRT_READ_IOUT_MAX (PMBUS_VIRT_BASE + 20) 169#define PMBUS_VIRT_READ_VOUT_MAX (PMBUS_VIRT_BASE + 20)
170#define PMBUS_VIRT_RESET_IOUT_HISTORY (PMBUS_VIRT_BASE + 21) 170#define PMBUS_VIRT_RESET_VOUT_HISTORY (PMBUS_VIRT_BASE + 21)
171#define PMBUS_VIRT_READ_TEMP2_MIN (PMBUS_VIRT_BASE + 22) 171#define PMBUS_VIRT_READ_IOUT_AVG (PMBUS_VIRT_BASE + 22)
172#define PMBUS_VIRT_READ_TEMP2_MAX (PMBUS_VIRT_BASE + 23) 172#define PMBUS_VIRT_READ_IOUT_MIN (PMBUS_VIRT_BASE + 23)
173#define PMBUS_VIRT_RESET_TEMP2_HISTORY (PMBUS_VIRT_BASE + 24) 173#define PMBUS_VIRT_READ_IOUT_MAX (PMBUS_VIRT_BASE + 24)
174#define PMBUS_VIRT_RESET_IOUT_HISTORY (PMBUS_VIRT_BASE + 25)
175#define PMBUS_VIRT_READ_TEMP2_AVG (PMBUS_VIRT_BASE + 26)
176#define PMBUS_VIRT_READ_TEMP2_MIN (PMBUS_VIRT_BASE + 27)
177#define PMBUS_VIRT_READ_TEMP2_MAX (PMBUS_VIRT_BASE + 28)
178#define PMBUS_VIRT_RESET_TEMP2_HISTORY (PMBUS_VIRT_BASE + 29)
174 179
175/* 180/*
176 * CAPABILITY 181 * CAPABILITY
@@ -364,7 +369,7 @@ bool pmbus_check_byte_register(struct i2c_client *client, int page, int reg);
364bool pmbus_check_word_register(struct i2c_client *client, int page, int reg); 369bool pmbus_check_word_register(struct i2c_client *client, int page, int reg);
365int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id, 370int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
366 struct pmbus_driver_info *info); 371 struct pmbus_driver_info *info);
367void pmbus_do_remove(struct i2c_client *client); 372int pmbus_do_remove(struct i2c_client *client);
368const struct pmbus_driver_info *pmbus_get_driver_info(struct i2c_client 373const struct pmbus_driver_info *pmbus_get_driver_info(struct i2c_client
369 *client); 374 *client);
370 375
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index d89b33967a85..be51037363c8 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -40,11 +40,14 @@
40#define PMBUS_IOUT_SENSORS_PER_PAGE 8 /* input, min, max, crit, 40#define PMBUS_IOUT_SENSORS_PER_PAGE 8 /* input, min, max, crit,
41 lowest, highest, avg, 41 lowest, highest, avg,
42 reset */ 42 reset */
43#define PMBUS_POUT_SENSORS_PER_PAGE 4 /* input, cap, max, crit */ 43#define PMBUS_POUT_SENSORS_PER_PAGE 7 /* input, cap, max, crit,
44 * highest, avg, reset
45 */
44#define PMBUS_MAX_SENSORS_PER_FAN 1 /* input */ 46#define PMBUS_MAX_SENSORS_PER_FAN 1 /* input */
45#define PMBUS_MAX_SENSORS_PER_TEMP 8 /* input, min, max, lcrit, 47#define PMBUS_MAX_SENSORS_PER_TEMP 9 /* input, min, max, lcrit,
46 crit, lowest, highest, 48 * crit, lowest, highest, avg,
47 reset */ 49 * reset
50 */
48 51
49#define PMBUS_MAX_INPUT_BOOLEANS 7 /* v: min_alarm, max_alarm, 52#define PMBUS_MAX_INPUT_BOOLEANS 7 /* v: min_alarm, max_alarm,
50 lcrit_alarm, crit_alarm; 53 lcrit_alarm, crit_alarm;
@@ -782,7 +785,7 @@ static ssize_t pmbus_set_sensor(struct device *dev,
782 int ret; 785 int ret;
783 u16 regval; 786 u16 regval;
784 787
785 if (strict_strtol(buf, 10, &val) < 0) 788 if (kstrtol(buf, 10, &val) < 0)
786 return -EINVAL; 789 return -EINVAL;
787 790
788 mutex_lock(&data->update_lock); 791 mutex_lock(&data->update_lock);
@@ -1334,6 +1337,17 @@ static const struct pmbus_limit_attr pout_limit_attrs[] = {
1334 .attr = "crit", 1337 .attr = "crit",
1335 .alarm = "crit_alarm", 1338 .alarm = "crit_alarm",
1336 .sbit = PB_POUT_OP_FAULT, 1339 .sbit = PB_POUT_OP_FAULT,
1340 }, {
1341 .reg = PMBUS_VIRT_READ_POUT_AVG,
1342 .update = true,
1343 .attr = "average",
1344 }, {
1345 .reg = PMBUS_VIRT_READ_POUT_MAX,
1346 .update = true,
1347 .attr = "input_highest",
1348 }, {
1349 .reg = PMBUS_VIRT_RESET_POUT_HISTORY,
1350 .attr = "reset_history",
1337 } 1351 }
1338}; 1352};
1339 1353
@@ -1389,6 +1403,9 @@ static const struct pmbus_limit_attr temp_limit_attrs[] = {
1389 .reg = PMBUS_VIRT_READ_TEMP_MIN, 1403 .reg = PMBUS_VIRT_READ_TEMP_MIN,
1390 .attr = "lowest", 1404 .attr = "lowest",
1391 }, { 1405 }, {
1406 .reg = PMBUS_VIRT_READ_TEMP_AVG,
1407 .attr = "average",
1408 }, {
1392 .reg = PMBUS_VIRT_READ_TEMP_MAX, 1409 .reg = PMBUS_VIRT_READ_TEMP_MAX,
1393 .attr = "highest", 1410 .attr = "highest",
1394 }, { 1411 }, {
@@ -1424,6 +1441,9 @@ static const struct pmbus_limit_attr temp_limit_attrs2[] = {
1424 .reg = PMBUS_VIRT_READ_TEMP2_MIN, 1441 .reg = PMBUS_VIRT_READ_TEMP2_MIN,
1425 .attr = "lowest", 1442 .attr = "lowest",
1426 }, { 1443 }, {
1444 .reg = PMBUS_VIRT_READ_TEMP2_AVG,
1445 .attr = "average",
1446 }, {
1427 .reg = PMBUS_VIRT_READ_TEMP2_MAX, 1447 .reg = PMBUS_VIRT_READ_TEMP2_MAX,
1428 .attr = "highest", 1448 .attr = "highest",
1429 }, { 1449 }, {
@@ -1676,7 +1696,7 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
1676 | I2C_FUNC_SMBUS_WORD_DATA)) 1696 | I2C_FUNC_SMBUS_WORD_DATA))
1677 return -ENODEV; 1697 return -ENODEV;
1678 1698
1679 data = kzalloc(sizeof(*data), GFP_KERNEL); 1699 data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
1680 if (!data) { 1700 if (!data) {
1681 dev_err(&client->dev, "No memory to allocate driver data\n"); 1701 dev_err(&client->dev, "No memory to allocate driver data\n");
1682 return -ENOMEM; 1702 return -ENOMEM;
@@ -1688,8 +1708,7 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
1688 /* Bail out if PMBus status register does not exist. */ 1708 /* Bail out if PMBus status register does not exist. */
1689 if (i2c_smbus_read_byte_data(client, PMBUS_STATUS_BYTE) < 0) { 1709 if (i2c_smbus_read_byte_data(client, PMBUS_STATUS_BYTE) < 0) {
1690 dev_err(&client->dev, "PMBus status register not found\n"); 1710 dev_err(&client->dev, "PMBus status register not found\n");
1691 ret = -ENODEV; 1711 return -ENODEV;
1692 goto out_data;
1693 } 1712 }
1694 1713
1695 if (pdata) 1714 if (pdata)
@@ -1702,50 +1721,49 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
1702 ret = (*info->identify)(client, info); 1721 ret = (*info->identify)(client, info);
1703 if (ret < 0) { 1722 if (ret < 0) {
1704 dev_err(&client->dev, "Chip identification failed\n"); 1723 dev_err(&client->dev, "Chip identification failed\n");
1705 goto out_data; 1724 return ret;
1706 } 1725 }
1707 } 1726 }
1708 1727
1709 if (info->pages <= 0 || info->pages > PMBUS_PAGES) { 1728 if (info->pages <= 0 || info->pages > PMBUS_PAGES) {
1710 dev_err(&client->dev, "Bad number of PMBus pages: %d\n", 1729 dev_err(&client->dev, "Bad number of PMBus pages: %d\n",
1711 info->pages); 1730 info->pages);
1712 ret = -ENODEV; 1731 return -ENODEV;
1713 goto out_data;
1714 } 1732 }
1715 1733
1716 ret = pmbus_identify_common(client, data); 1734 ret = pmbus_identify_common(client, data);
1717 if (ret < 0) { 1735 if (ret < 0) {
1718 dev_err(&client->dev, "Failed to identify chip capabilities\n"); 1736 dev_err(&client->dev, "Failed to identify chip capabilities\n");
1719 goto out_data; 1737 return ret;
1720 } 1738 }
1721 1739
1722 ret = -ENOMEM; 1740 ret = -ENOMEM;
1723 data->sensors = kzalloc(sizeof(struct pmbus_sensor) * data->max_sensors, 1741 data->sensors = devm_kzalloc(&client->dev, sizeof(struct pmbus_sensor)
1724 GFP_KERNEL); 1742 * data->max_sensors, GFP_KERNEL);
1725 if (!data->sensors) { 1743 if (!data->sensors) {
1726 dev_err(&client->dev, "No memory to allocate sensor data\n"); 1744 dev_err(&client->dev, "No memory to allocate sensor data\n");
1727 goto out_data; 1745 return -ENOMEM;
1728 } 1746 }
1729 1747
1730 data->booleans = kzalloc(sizeof(struct pmbus_boolean) 1748 data->booleans = devm_kzalloc(&client->dev, sizeof(struct pmbus_boolean)
1731 * data->max_booleans, GFP_KERNEL); 1749 * data->max_booleans, GFP_KERNEL);
1732 if (!data->booleans) { 1750 if (!data->booleans) {
1733 dev_err(&client->dev, "No memory to allocate boolean data\n"); 1751 dev_err(&client->dev, "No memory to allocate boolean data\n");
1734 goto out_sensors; 1752 return -ENOMEM;
1735 } 1753 }
1736 1754
1737 data->labels = kzalloc(sizeof(struct pmbus_label) * data->max_labels, 1755 data->labels = devm_kzalloc(&client->dev, sizeof(struct pmbus_label)
1738 GFP_KERNEL); 1756 * data->max_labels, GFP_KERNEL);
1739 if (!data->labels) { 1757 if (!data->labels) {
1740 dev_err(&client->dev, "No memory to allocate label data\n"); 1758 dev_err(&client->dev, "No memory to allocate label data\n");
1741 goto out_booleans; 1759 return -ENOMEM;
1742 } 1760 }
1743 1761
1744 data->attributes = kzalloc(sizeof(struct attribute *) 1762 data->attributes = devm_kzalloc(&client->dev, sizeof(struct attribute *)
1745 * data->max_attributes, GFP_KERNEL); 1763 * data->max_attributes, GFP_KERNEL);
1746 if (!data->attributes) { 1764 if (!data->attributes) {
1747 dev_err(&client->dev, "No memory to allocate attribute data\n"); 1765 dev_err(&client->dev, "No memory to allocate attribute data\n");
1748 goto out_labels; 1766 return -ENOMEM;
1749 } 1767 }
1750 1768
1751 pmbus_find_attributes(client, data); 1769 pmbus_find_attributes(client, data);
@@ -1756,8 +1774,7 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
1756 */ 1774 */
1757 if (!data->num_attributes) { 1775 if (!data->num_attributes) {
1758 dev_err(&client->dev, "No attributes found\n"); 1776 dev_err(&client->dev, "No attributes found\n");
1759 ret = -ENODEV; 1777 return -ENODEV;
1760 goto out_attributes;
1761 } 1778 }
1762 1779
1763 /* Register sysfs hooks */ 1780 /* Register sysfs hooks */
@@ -1765,7 +1782,7 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
1765 ret = sysfs_create_group(&client->dev.kobj, &data->group); 1782 ret = sysfs_create_group(&client->dev.kobj, &data->group);
1766 if (ret) { 1783 if (ret) {
1767 dev_err(&client->dev, "Failed to create sysfs entries\n"); 1784 dev_err(&client->dev, "Failed to create sysfs entries\n");
1768 goto out_attributes; 1785 return ret;
1769 } 1786 }
1770 data->hwmon_dev = hwmon_device_register(&client->dev); 1787 data->hwmon_dev = hwmon_device_register(&client->dev);
1771 if (IS_ERR(data->hwmon_dev)) { 1788 if (IS_ERR(data->hwmon_dev)) {
@@ -1777,30 +1794,16 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
1777 1794
1778out_hwmon_device_register: 1795out_hwmon_device_register:
1779 sysfs_remove_group(&client->dev.kobj, &data->group); 1796 sysfs_remove_group(&client->dev.kobj, &data->group);
1780out_attributes:
1781 kfree(data->attributes);
1782out_labels:
1783 kfree(data->labels);
1784out_booleans:
1785 kfree(data->booleans);
1786out_sensors:
1787 kfree(data->sensors);
1788out_data:
1789 kfree(data);
1790 return ret; 1797 return ret;
1791} 1798}
1792EXPORT_SYMBOL_GPL(pmbus_do_probe); 1799EXPORT_SYMBOL_GPL(pmbus_do_probe);
1793 1800
1794void pmbus_do_remove(struct i2c_client *client) 1801int pmbus_do_remove(struct i2c_client *client)
1795{ 1802{
1796 struct pmbus_data *data = i2c_get_clientdata(client); 1803 struct pmbus_data *data = i2c_get_clientdata(client);
1797 hwmon_device_unregister(data->hwmon_dev); 1804 hwmon_device_unregister(data->hwmon_dev);
1798 sysfs_remove_group(&client->dev.kobj, &data->group); 1805 sysfs_remove_group(&client->dev.kobj, &data->group);
1799 kfree(data->attributes); 1806 return 0;
1800 kfree(data->labels);
1801 kfree(data->booleans);
1802 kfree(data->sensors);
1803 kfree(data);
1804} 1807}
1805EXPORT_SYMBOL_GPL(pmbus_do_remove); 1808EXPORT_SYMBOL_GPL(pmbus_do_remove);
1806 1809
diff --git a/drivers/hwmon/pmbus/ucd9000.c b/drivers/hwmon/pmbus/ucd9000.c
index 4ff6cf289f85..fbb1479d3ad4 100644
--- a/drivers/hwmon/pmbus/ucd9000.c
+++ b/drivers/hwmon/pmbus/ucd9000.c
@@ -155,7 +155,8 @@ static int ucd9000_probe(struct i2c_client *client,
155 "Device mismatch: Configured %s, detected %s\n", 155 "Device mismatch: Configured %s, detected %s\n",
156 id->name, mid->name); 156 id->name, mid->name);
157 157
158 data = kzalloc(sizeof(struct ucd9000_data), GFP_KERNEL); 158 data = devm_kzalloc(&client->dev, sizeof(struct ucd9000_data),
159 GFP_KERNEL);
159 if (!data) 160 if (!data)
160 return -ENOMEM; 161 return -ENOMEM;
161 info = &data->info; 162 info = &data->info;
@@ -164,13 +165,12 @@ static int ucd9000_probe(struct i2c_client *client,
164 if (ret < 0) { 165 if (ret < 0) {
165 dev_err(&client->dev, 166 dev_err(&client->dev,
166 "Failed to read number of active pages\n"); 167 "Failed to read number of active pages\n");
167 goto out; 168 return ret;
168 } 169 }
169 info->pages = ret; 170 info->pages = ret;
170 if (!info->pages) { 171 if (!info->pages) {
171 dev_err(&client->dev, "No pages configured\n"); 172 dev_err(&client->dev, "No pages configured\n");
172 ret = -ENODEV; 173 return -ENODEV;
173 goto out;
174 } 174 }
175 175
176 /* The internal temperature sensor is always active */ 176 /* The internal temperature sensor is always active */
@@ -181,8 +181,7 @@ static int ucd9000_probe(struct i2c_client *client,
181 block_buffer); 181 block_buffer);
182 if (ret <= 0) { 182 if (ret <= 0) {
183 dev_err(&client->dev, "Failed to read configuration data\n"); 183 dev_err(&client->dev, "Failed to read configuration data\n");
184 ret = -ENODEV; 184 return -ENODEV;
185 goto out;
186 } 185 }
187 for (i = 0; i < ret; i++) { 186 for (i = 0; i < ret; i++) {
188 int page = UCD9000_MON_PAGE(block_buffer[i]); 187 int page = UCD9000_MON_PAGE(block_buffer[i]);
@@ -218,7 +217,7 @@ static int ucd9000_probe(struct i2c_client *client,
218 UCD9000_FAN_CONFIG, 217 UCD9000_FAN_CONFIG,
219 data->fan_data[i]); 218 data->fan_data[i]);
220 if (ret < 0) 219 if (ret < 0)
221 goto out; 220 return ret;
222 } 221 }
223 i2c_smbus_write_byte_data(client, UCD9000_FAN_CONFIG_INDEX, 0); 222 i2c_smbus_write_byte_data(client, UCD9000_FAN_CONFIG_INDEX, 0);
224 223
@@ -227,49 +226,21 @@ static int ucd9000_probe(struct i2c_client *client,
227 | PMBUS_HAVE_FAN34 | PMBUS_HAVE_STATUS_FAN34; 226 | PMBUS_HAVE_FAN34 | PMBUS_HAVE_STATUS_FAN34;
228 } 227 }
229 228
230 ret = pmbus_do_probe(client, mid, info); 229 return pmbus_do_probe(client, mid, info);
231 if (ret < 0)
232 goto out;
233 return 0;
234
235out:
236 kfree(data);
237 return ret;
238}
239
240static int ucd9000_remove(struct i2c_client *client)
241{
242 struct ucd9000_data *data;
243
244 data = to_ucd9000_data(pmbus_get_driver_info(client));
245 pmbus_do_remove(client);
246 kfree(data);
247 return 0;
248} 230}
249 231
250
251/* This is the driver that will be inserted */ 232/* This is the driver that will be inserted */
252static struct i2c_driver ucd9000_driver = { 233static struct i2c_driver ucd9000_driver = {
253 .driver = { 234 .driver = {
254 .name = "ucd9000", 235 .name = "ucd9000",
255 }, 236 },
256 .probe = ucd9000_probe, 237 .probe = ucd9000_probe,
257 .remove = ucd9000_remove, 238 .remove = pmbus_do_remove,
258 .id_table = ucd9000_id, 239 .id_table = ucd9000_id,
259}; 240};
260 241
261static int __init ucd9000_init(void) 242module_i2c_driver(ucd9000_driver);
262{
263 return i2c_add_driver(&ucd9000_driver);
264}
265
266static void __exit ucd9000_exit(void)
267{
268 i2c_del_driver(&ucd9000_driver);
269}
270 243
271MODULE_AUTHOR("Guenter Roeck"); 244MODULE_AUTHOR("Guenter Roeck");
272MODULE_DESCRIPTION("PMBus driver for TI UCD90xxx"); 245MODULE_DESCRIPTION("PMBus driver for TI UCD90xxx");
273MODULE_LICENSE("GPL"); 246MODULE_LICENSE("GPL");
274module_init(ucd9000_init);
275module_exit(ucd9000_exit);
diff --git a/drivers/hwmon/pmbus/ucd9200.c b/drivers/hwmon/pmbus/ucd9200.c
index 6e1c1a80ab85..033d6aca47d3 100644
--- a/drivers/hwmon/pmbus/ucd9200.c
+++ b/drivers/hwmon/pmbus/ucd9200.c
@@ -81,7 +81,8 @@ static int ucd9200_probe(struct i2c_client *client,
81 "Device mismatch: Configured %s, detected %s\n", 81 "Device mismatch: Configured %s, detected %s\n",
82 id->name, mid->name); 82 id->name, mid->name);
83 83
84 info = kzalloc(sizeof(struct pmbus_driver_info), GFP_KERNEL); 84 info = devm_kzalloc(&client->dev, sizeof(struct pmbus_driver_info),
85 GFP_KERNEL);
85 if (!info) 86 if (!info)
86 return -ENOMEM; 87 return -ENOMEM;
87 88
@@ -89,7 +90,7 @@ static int ucd9200_probe(struct i2c_client *client,
89 block_buffer); 90 block_buffer);
90 if (ret < 0) { 91 if (ret < 0) {
91 dev_err(&client->dev, "Failed to read phase information\n"); 92 dev_err(&client->dev, "Failed to read phase information\n");
92 goto out; 93 return ret;
93 } 94 }
94 95
95 /* 96 /*
@@ -106,8 +107,7 @@ static int ucd9200_probe(struct i2c_client *client,
106 } 107 }
107 if (!info->pages) { 108 if (!info->pages) {
108 dev_err(&client->dev, "No rails configured\n"); 109 dev_err(&client->dev, "No rails configured\n");
109 ret = -ENODEV; 110 return -ENODEV;
110 goto out;
111 } 111 }
112 dev_info(&client->dev, "%d rails configured\n", info->pages); 112 dev_info(&client->dev, "%d rails configured\n", info->pages);
113 113
@@ -137,7 +137,7 @@ static int ucd9200_probe(struct i2c_client *client,
137 if (ret < 0) { 137 if (ret < 0) {
138 dev_err(&client->dev, 138 dev_err(&client->dev,
139 "Failed to initialize PHASE registers\n"); 139 "Failed to initialize PHASE registers\n");
140 goto out; 140 return ret;
141 } 141 }
142 } 142 }
143 if (info->pages > 1) 143 if (info->pages > 1)
@@ -160,48 +160,21 @@ static int ucd9200_probe(struct i2c_client *client,
160 if (mid->driver_data == ucd9240) 160 if (mid->driver_data == ucd9240)
161 info->func[0] |= PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12; 161 info->func[0] |= PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12;
162 162
163 ret = pmbus_do_probe(client, mid, info); 163 return pmbus_do_probe(client, mid, info);
164 if (ret < 0)
165 goto out;
166 return 0;
167out:
168 kfree(info);
169 return ret;
170}
171
172static int ucd9200_remove(struct i2c_client *client)
173{
174 const struct pmbus_driver_info *info;
175
176 info = pmbus_get_driver_info(client);
177 pmbus_do_remove(client);
178 kfree(info);
179 return 0;
180} 164}
181 165
182
183/* This is the driver that will be inserted */ 166/* This is the driver that will be inserted */
184static struct i2c_driver ucd9200_driver = { 167static struct i2c_driver ucd9200_driver = {
185 .driver = { 168 .driver = {
186 .name = "ucd9200", 169 .name = "ucd9200",
187 }, 170 },
188 .probe = ucd9200_probe, 171 .probe = ucd9200_probe,
189 .remove = ucd9200_remove, 172 .remove = pmbus_do_remove,
190 .id_table = ucd9200_id, 173 .id_table = ucd9200_id,
191}; 174};
192 175
193static int __init ucd9200_init(void) 176module_i2c_driver(ucd9200_driver);
194{
195 return i2c_add_driver(&ucd9200_driver);
196}
197
198static void __exit ucd9200_exit(void)
199{
200 i2c_del_driver(&ucd9200_driver);
201}
202 177
203MODULE_AUTHOR("Guenter Roeck"); 178MODULE_AUTHOR("Guenter Roeck");
204MODULE_DESCRIPTION("PMBus driver for TI UCD922x, UCD924x"); 179MODULE_DESCRIPTION("PMBus driver for TI UCD922x, UCD924x");
205MODULE_LICENSE("GPL"); 180MODULE_LICENSE("GPL");
206module_init(ucd9200_init);
207module_exit(ucd9200_exit);
diff --git a/drivers/hwmon/pmbus/zl6100.c b/drivers/hwmon/pmbus/zl6100.c
index e3e8420b7b81..fc5eed8e85bb 100644
--- a/drivers/hwmon/pmbus/zl6100.c
+++ b/drivers/hwmon/pmbus/zl6100.c
@@ -28,7 +28,8 @@
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include "pmbus.h" 29#include "pmbus.h"
30 30
31enum chips { zl2004, zl2005, zl2006, zl2008, zl2105, zl2106, zl6100, zl6105 }; 31enum chips { zl2004, zl2005, zl2006, zl2008, zl2105, zl2106, zl6100, zl6105,
32 zl9101, zl9117 };
32 33
33struct zl6100_data { 34struct zl6100_data {
34 int id; 35 int id;
@@ -152,6 +153,8 @@ static const struct i2c_device_id zl6100_id[] = {
152 {"zl2106", zl2106}, 153 {"zl2106", zl2106},
153 {"zl6100", zl6100}, 154 {"zl6100", zl6100},
154 {"zl6105", zl6105}, 155 {"zl6105", zl6105},
156 {"zl9101", zl9101},
157 {"zl9117", zl9117},
155 { } 158 { }
156}; 159};
157MODULE_DEVICE_TABLE(i2c, zl6100_id); 160MODULE_DEVICE_TABLE(i2c, zl6100_id);
@@ -193,7 +196,8 @@ static int zl6100_probe(struct i2c_client *client,
193 "Device mismatch: Configured %s, detected %s\n", 196 "Device mismatch: Configured %s, detected %s\n",
194 id->name, mid->name); 197 id->name, mid->name);
195 198
196 data = kzalloc(sizeof(struct zl6100_data), GFP_KERNEL); 199 data = devm_kzalloc(&client->dev, sizeof(struct zl6100_data),
200 GFP_KERNEL);
197 if (!data) 201 if (!data)
198 return -ENOMEM; 202 return -ENOMEM;
199 203
@@ -223,7 +227,8 @@ static int zl6100_probe(struct i2c_client *client,
223 227
224 ret = i2c_smbus_read_word_data(client, ZL6100_MFR_CONFIG); 228 ret = i2c_smbus_read_word_data(client, ZL6100_MFR_CONFIG);
225 if (ret < 0) 229 if (ret < 0)
226 goto err_mem; 230 return ret;
231
227 if (ret & ZL6100_MFR_XTEMP_ENABLE) 232 if (ret & ZL6100_MFR_XTEMP_ENABLE)
228 info->func[0] |= PMBUS_HAVE_TEMP2; 233 info->func[0] |= PMBUS_HAVE_TEMP2;
229 234
@@ -235,24 +240,7 @@ static int zl6100_probe(struct i2c_client *client,
235 info->write_word_data = zl6100_write_word_data; 240 info->write_word_data = zl6100_write_word_data;
236 info->write_byte = zl6100_write_byte; 241 info->write_byte = zl6100_write_byte;
237 242
238 ret = pmbus_do_probe(client, mid, info); 243 return pmbus_do_probe(client, mid, info);
239 if (ret)
240 goto err_mem;
241 return 0;
242
243err_mem:
244 kfree(data);
245 return ret;
246}
247
248static int zl6100_remove(struct i2c_client *client)
249{
250 const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
251 const struct zl6100_data *data = to_zl6100_data(info);
252
253 pmbus_do_remove(client);
254 kfree(data);
255 return 0;
256} 244}
257 245
258static struct i2c_driver zl6100_driver = { 246static struct i2c_driver zl6100_driver = {
@@ -260,22 +248,12 @@ static struct i2c_driver zl6100_driver = {
260 .name = "zl6100", 248 .name = "zl6100",
261 }, 249 },
262 .probe = zl6100_probe, 250 .probe = zl6100_probe,
263 .remove = zl6100_remove, 251 .remove = pmbus_do_remove,
264 .id_table = zl6100_id, 252 .id_table = zl6100_id,
265}; 253};
266 254
267static int __init zl6100_init(void) 255module_i2c_driver(zl6100_driver);
268{
269 return i2c_add_driver(&zl6100_driver);
270}
271
272static void __exit zl6100_exit(void)
273{
274 i2c_del_driver(&zl6100_driver);
275}
276 256
277MODULE_AUTHOR("Guenter Roeck"); 257MODULE_AUTHOR("Guenter Roeck");
278MODULE_DESCRIPTION("PMBus driver for ZL6100 and compatibles"); 258MODULE_DESCRIPTION("PMBus driver for ZL6100 and compatibles");
279MODULE_LICENSE("GPL"); 259MODULE_LICENSE("GPL");
280module_init(zl6100_init);
281module_exit(zl6100_exit);
diff --git a/drivers/hwmon/sch5627.c b/drivers/hwmon/sch5627.c
index 79b6dabe3161..8ec6dfbccb64 100644
--- a/drivers/hwmon/sch5627.c
+++ b/drivers/hwmon/sch5627.c
@@ -1,5 +1,5 @@
1/*************************************************************************** 1/***************************************************************************
2 * Copyright (C) 2010-2011 Hans de Goede <hdegoede@redhat.com> * 2 * Copyright (C) 2010-2012 Hans de Goede <hdegoede@redhat.com> *
3 * * 3 * *
4 * This program is free software; you can redistribute it and/or modify * 4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by * 5 * it under the terms of the GNU General Public License as published by *
@@ -79,6 +79,7 @@ static const char * const SCH5627_IN_LABELS[SCH5627_NO_IN] = {
79struct sch5627_data { 79struct sch5627_data {
80 unsigned short addr; 80 unsigned short addr;
81 struct device *hwmon_dev; 81 struct device *hwmon_dev;
82 struct sch56xx_watchdog_data *watchdog;
82 u8 control; 83 u8 control;
83 u8 temp_max[SCH5627_NO_TEMPS]; 84 u8 temp_max[SCH5627_NO_TEMPS];
84 u8 temp_crit[SCH5627_NO_TEMPS]; 85 u8 temp_crit[SCH5627_NO_TEMPS];
@@ -453,6 +454,9 @@ static int sch5627_remove(struct platform_device *pdev)
453{ 454{
454 struct sch5627_data *data = platform_get_drvdata(pdev); 455 struct sch5627_data *data = platform_get_drvdata(pdev);
455 456
457 if (data->watchdog)
458 sch56xx_watchdog_unregister(data->watchdog);
459
456 if (data->hwmon_dev) 460 if (data->hwmon_dev)
457 hwmon_device_unregister(data->hwmon_dev); 461 hwmon_device_unregister(data->hwmon_dev);
458 462
@@ -574,6 +578,11 @@ static int __devinit sch5627_probe(struct platform_device *pdev)
574 goto error; 578 goto error;
575 } 579 }
576 580
581 /* Note failing to register the watchdog is not a fatal error */
582 data->watchdog = sch56xx_watchdog_register(data->addr,
583 (build_code << 24) | (build_id << 8) | hwmon_rev,
584 &data->update_lock, 1);
585
577 return 0; 586 return 0;
578 587
579error: 588error:
diff --git a/drivers/hwmon/sch5636.c b/drivers/hwmon/sch5636.c
index 9d5236fb09b4..906d4ed32d81 100644
--- a/drivers/hwmon/sch5636.c
+++ b/drivers/hwmon/sch5636.c
@@ -1,5 +1,5 @@
1/*************************************************************************** 1/***************************************************************************
2 * Copyright (C) 2011 Hans de Goede <hdegoede@redhat.com> * 2 * Copyright (C) 2011-2012 Hans de Goede <hdegoede@redhat.com> *
3 * * 3 * *
4 * This program is free software; you can redistribute it and/or modify * 4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by * 5 * it under the terms of the GNU General Public License as published by *
@@ -67,6 +67,7 @@ static const u16 SCH5636_REG_FAN_VAL[SCH5636_NO_FANS] = {
67struct sch5636_data { 67struct sch5636_data {
68 unsigned short addr; 68 unsigned short addr;
69 struct device *hwmon_dev; 69 struct device *hwmon_dev;
70 struct sch56xx_watchdog_data *watchdog;
70 71
71 struct mutex update_lock; 72 struct mutex update_lock;
72 char valid; /* !=0 if following fields are valid */ 73 char valid; /* !=0 if following fields are valid */
@@ -384,6 +385,9 @@ static int sch5636_remove(struct platform_device *pdev)
384 struct sch5636_data *data = platform_get_drvdata(pdev); 385 struct sch5636_data *data = platform_get_drvdata(pdev);
385 int i; 386 int i;
386 387
388 if (data->watchdog)
389 sch56xx_watchdog_unregister(data->watchdog);
390
387 if (data->hwmon_dev) 391 if (data->hwmon_dev)
388 hwmon_device_unregister(data->hwmon_dev); 392 hwmon_device_unregister(data->hwmon_dev);
389 393
@@ -505,6 +509,11 @@ static int __devinit sch5636_probe(struct platform_device *pdev)
505 goto error; 509 goto error;
506 } 510 }
507 511
512 /* Note failing to register the watchdog is not a fatal error */
513 data->watchdog = sch56xx_watchdog_register(data->addr,
514 (revision[0] << 8) | revision[1],
515 &data->update_lock, 0);
516
508 return 0; 517 return 0;
509 518
510error: 519error:
diff --git a/drivers/hwmon/sch56xx-common.c b/drivers/hwmon/sch56xx-common.c
index fac32ee0b10e..ce52fc57d41d 100644
--- a/drivers/hwmon/sch56xx-common.c
+++ b/drivers/hwmon/sch56xx-common.c
@@ -1,5 +1,5 @@
1/*************************************************************************** 1/***************************************************************************
2 * Copyright (C) 2010-2011 Hans de Goede <hdegoede@redhat.com> * 2 * Copyright (C) 2010-2012 Hans de Goede <hdegoede@redhat.com> *
3 * * 3 * *
4 * This program is free software; you can redistribute it and/or modify * 4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by * 5 * it under the terms of the GNU General Public License as published by *
@@ -26,8 +26,20 @@
26#include <linux/io.h> 26#include <linux/io.h>
27#include <linux/acpi.h> 27#include <linux/acpi.h>
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include <linux/fs.h>
30#include <linux/watchdog.h>
31#include <linux/miscdevice.h>
32#include <linux/uaccess.h>
33#include <linux/kref.h>
34#include <linux/slab.h>
29#include "sch56xx-common.h" 35#include "sch56xx-common.h"
30 36
37/* Insmod parameters */
38static int nowayout = WATCHDOG_NOWAYOUT;
39module_param(nowayout, int, 0);
40MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
41 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
42
31#define SIO_SCH56XX_LD_EM 0x0C /* Embedded uController Logical Dev */ 43#define SIO_SCH56XX_LD_EM 0x0C /* Embedded uController Logical Dev */
32#define SIO_UNLOCK_KEY 0x55 /* Key to enable Super-I/O */ 44#define SIO_UNLOCK_KEY 0x55 /* Key to enable Super-I/O */
33#define SIO_LOCK_KEY 0xAA /* Key to disable Super-I/O */ 45#define SIO_LOCK_KEY 0xAA /* Key to disable Super-I/O */
@@ -40,13 +52,45 @@
40#define SIO_SCH5627_ID 0xC6 /* Chipset ID */ 52#define SIO_SCH5627_ID 0xC6 /* Chipset ID */
41#define SIO_SCH5636_ID 0xC7 /* Chipset ID */ 53#define SIO_SCH5636_ID 0xC7 /* Chipset ID */
42 54
43#define REGION_LENGTH 9 55#define REGION_LENGTH 10
44 56
45#define SCH56XX_CMD_READ 0x02 57#define SCH56XX_CMD_READ 0x02
46#define SCH56XX_CMD_WRITE 0x03 58#define SCH56XX_CMD_WRITE 0x03
47 59
60/* Watchdog registers */
61#define SCH56XX_REG_WDOG_PRESET 0x58B
62#define SCH56XX_REG_WDOG_CONTROL 0x58C
63#define SCH56XX_WDOG_TIME_BASE_SEC 0x01
64#define SCH56XX_REG_WDOG_OUTPUT_ENABLE 0x58E
65#define SCH56XX_WDOG_OUTPUT_ENABLE 0x02
66
67struct sch56xx_watchdog_data {
68 u16 addr;
69 u32 revision;
70 struct mutex *io_lock;
71 struct mutex watchdog_lock;
72 struct list_head list; /* member of the watchdog_data_list */
73 struct kref kref;
74 struct miscdevice watchdog_miscdev;
75 unsigned long watchdog_is_open;
76 char watchdog_name[10]; /* must be unique to avoid sysfs conflict */
77 char watchdog_expect_close;
78 u8 watchdog_preset;
79 u8 watchdog_control;
80 u8 watchdog_output_enable;
81};
82
48static struct platform_device *sch56xx_pdev; 83static struct platform_device *sch56xx_pdev;
49 84
85/*
86 * Somewhat ugly :( global data pointer list with all sch56xx devices, so that
87 * we can find our device data as when using misc_register there is no other
88 * method to get to ones device data from the open fop.
89 */
90static LIST_HEAD(watchdog_data_list);
91/* Note this lock not only protect list access, but also data.kref access */
92static DEFINE_MUTEX(watchdog_data_mutex);
93
50/* Super I/O functions */ 94/* Super I/O functions */
51static inline int superio_inb(int base, int reg) 95static inline int superio_inb(int base, int reg)
52{ 96{
@@ -224,6 +268,477 @@ int sch56xx_read_virtual_reg12(u16 addr, u16 msb_reg, u16 lsn_reg,
224} 268}
225EXPORT_SYMBOL(sch56xx_read_virtual_reg12); 269EXPORT_SYMBOL(sch56xx_read_virtual_reg12);
226 270
271/*
272 * Watchdog routines
273 */
274
275/*
276 * Release our data struct when the platform device has been released *and*
277 * all references to our watchdog device are released.
278 */
279static void sch56xx_watchdog_release_resources(struct kref *r)
280{
281 struct sch56xx_watchdog_data *data =
282 container_of(r, struct sch56xx_watchdog_data, kref);
283 kfree(data);
284}
285
286static int watchdog_set_timeout(struct sch56xx_watchdog_data *data,
287 int timeout)
288{
289 int ret, resolution;
290 u8 control;
291
292 /* 1 second or 60 second resolution? */
293 if (timeout <= 255)
294 resolution = 1;
295 else
296 resolution = 60;
297
298 if (timeout < resolution || timeout > (resolution * 255))
299 return -EINVAL;
300
301 mutex_lock(&data->watchdog_lock);
302 if (!data->addr) {
303 ret = -ENODEV;
304 goto leave;
305 }
306
307 if (resolution == 1)
308 control = data->watchdog_control | SCH56XX_WDOG_TIME_BASE_SEC;
309 else
310 control = data->watchdog_control & ~SCH56XX_WDOG_TIME_BASE_SEC;
311
312 if (data->watchdog_control != control) {
313 mutex_lock(data->io_lock);
314 ret = sch56xx_write_virtual_reg(data->addr,
315 SCH56XX_REG_WDOG_CONTROL,
316 control);
317 mutex_unlock(data->io_lock);
318 if (ret)
319 goto leave;
320
321 data->watchdog_control = control;
322 }
323
324 /*
325 * Remember new timeout value, but do not write as that (re)starts
326 * the watchdog countdown.
327 */
328 data->watchdog_preset = DIV_ROUND_UP(timeout, resolution);
329
330 ret = data->watchdog_preset * resolution;
331leave:
332 mutex_unlock(&data->watchdog_lock);
333 return ret;
334}
335
336static int watchdog_get_timeout(struct sch56xx_watchdog_data *data)
337{
338 int timeout;
339
340 mutex_lock(&data->watchdog_lock);
341 if (data->watchdog_control & SCH56XX_WDOG_TIME_BASE_SEC)
342 timeout = data->watchdog_preset;
343 else
344 timeout = data->watchdog_preset * 60;
345 mutex_unlock(&data->watchdog_lock);
346
347 return timeout;
348}
349
350static int watchdog_start(struct sch56xx_watchdog_data *data)
351{
352 int ret;
353 u8 val;
354
355 mutex_lock(&data->watchdog_lock);
356 if (!data->addr) {
357 ret = -ENODEV;
358 goto leave_unlock_watchdog;
359 }
360
361 /*
362 * The sch56xx's watchdog cannot really be started / stopped
363 * it is always running, but we can avoid the timer expiring
364 * from causing a system reset by clearing the output enable bit.
365 *
366 * The sch56xx's watchdog will set the watchdog event bit, bit 0
367 * of the second interrupt source register (at base-address + 9),
368 * when the timer expires.
369 *
370 * This will only cause a system reset if the 0-1 flank happens when
371 * output enable is true. Setting output enable after the flank will
372 * not cause a reset, nor will the timer expiring a second time.
373 * This means we must clear the watchdog event bit in case it is set.
374 *
375 * The timer may still be running (after a recent watchdog_stop) and
376 * mere milliseconds away from expiring, so the timer must be reset
377 * first!
378 */
379
380 mutex_lock(data->io_lock);
381
382 /* 1. Reset the watchdog countdown counter */
383 ret = sch56xx_write_virtual_reg(data->addr, SCH56XX_REG_WDOG_PRESET,
384 data->watchdog_preset);
385 if (ret)
386 goto leave;
387
388 /* 2. Enable output (if not already enabled) */
389 if (!(data->watchdog_output_enable & SCH56XX_WDOG_OUTPUT_ENABLE)) {
390 val = data->watchdog_output_enable |
391 SCH56XX_WDOG_OUTPUT_ENABLE;
392 ret = sch56xx_write_virtual_reg(data->addr,
393 SCH56XX_REG_WDOG_OUTPUT_ENABLE,
394 val);
395 if (ret)
396 goto leave;
397
398 data->watchdog_output_enable = val;
399 }
400
401 /* 3. Clear the watchdog event bit if set */
402 val = inb(data->addr + 9);
403 if (val & 0x01)
404 outb(0x01, data->addr + 9);
405
406leave:
407 mutex_unlock(data->io_lock);
408leave_unlock_watchdog:
409 mutex_unlock(&data->watchdog_lock);
410 return ret;
411}
412
413static int watchdog_trigger(struct sch56xx_watchdog_data *data)
414{
415 int ret;
416
417 mutex_lock(&data->watchdog_lock);
418 if (!data->addr) {
419 ret = -ENODEV;
420 goto leave;
421 }
422
423 /* Reset the watchdog countdown counter */
424 mutex_lock(data->io_lock);
425 ret = sch56xx_write_virtual_reg(data->addr, SCH56XX_REG_WDOG_PRESET,
426 data->watchdog_preset);
427 mutex_unlock(data->io_lock);
428leave:
429 mutex_unlock(&data->watchdog_lock);
430 return ret;
431}
432
433static int watchdog_stop_unlocked(struct sch56xx_watchdog_data *data)
434{
435 int ret = 0;
436 u8 val;
437
438 if (!data->addr)
439 return -ENODEV;
440
441 if (data->watchdog_output_enable & SCH56XX_WDOG_OUTPUT_ENABLE) {
442 val = data->watchdog_output_enable &
443 ~SCH56XX_WDOG_OUTPUT_ENABLE;
444 mutex_lock(data->io_lock);
445 ret = sch56xx_write_virtual_reg(data->addr,
446 SCH56XX_REG_WDOG_OUTPUT_ENABLE,
447 val);
448 mutex_unlock(data->io_lock);
449 if (ret)
450 return ret;
451
452 data->watchdog_output_enable = val;
453 }
454
455 return ret;
456}
457
458static int watchdog_stop(struct sch56xx_watchdog_data *data)
459{
460 int ret;
461
462 mutex_lock(&data->watchdog_lock);
463 ret = watchdog_stop_unlocked(data);
464 mutex_unlock(&data->watchdog_lock);
465
466 return ret;
467}
468
469static int watchdog_release(struct inode *inode, struct file *filp)
470{
471 struct sch56xx_watchdog_data *data = filp->private_data;
472
473 if (data->watchdog_expect_close) {
474 watchdog_stop(data);
475 data->watchdog_expect_close = 0;
476 } else {
477 watchdog_trigger(data);
478 pr_crit("unexpected close, not stopping watchdog!\n");
479 }
480
481 clear_bit(0, &data->watchdog_is_open);
482
483 mutex_lock(&watchdog_data_mutex);
484 kref_put(&data->kref, sch56xx_watchdog_release_resources);
485 mutex_unlock(&watchdog_data_mutex);
486
487 return 0;
488}
489
490static int watchdog_open(struct inode *inode, struct file *filp)
491{
492 struct sch56xx_watchdog_data *pos, *data = NULL;
493 int ret, watchdog_is_open;
494
495 /*
496 * We get called from drivers/char/misc.c with misc_mtx hold, and we
497 * call misc_register() from sch56xx_watchdog_probe() with
498 * watchdog_data_mutex hold, as misc_register() takes the misc_mtx
499 * lock, this is a possible deadlock, so we use mutex_trylock here.
500 */
501 if (!mutex_trylock(&watchdog_data_mutex))
502 return -ERESTARTSYS;
503 list_for_each_entry(pos, &watchdog_data_list, list) {
504 if (pos->watchdog_miscdev.minor == iminor(inode)) {
505 data = pos;
506 break;
507 }
508 }
509 /* Note we can never not have found data, so we don't check for this */
510 watchdog_is_open = test_and_set_bit(0, &data->watchdog_is_open);
511 if (!watchdog_is_open)
512 kref_get(&data->kref);
513 mutex_unlock(&watchdog_data_mutex);
514
515 if (watchdog_is_open)
516 return -EBUSY;
517
518 filp->private_data = data;
519
520 /* Start the watchdog */
521 ret = watchdog_start(data);
522 if (ret) {
523 watchdog_release(inode, filp);
524 return ret;
525 }
526
527 return nonseekable_open(inode, filp);
528}
529
530static ssize_t watchdog_write(struct file *filp, const char __user *buf,
531 size_t count, loff_t *offset)
532{
533 int ret;
534 struct sch56xx_watchdog_data *data = filp->private_data;
535
536 if (count) {
537 if (!nowayout) {
538 size_t i;
539
540 /* Clear it in case it was set with a previous write */
541 data->watchdog_expect_close = 0;
542
543 for (i = 0; i != count; i++) {
544 char c;
545 if (get_user(c, buf + i))
546 return -EFAULT;
547 if (c == 'V')
548 data->watchdog_expect_close = 1;
549 }
550 }
551 ret = watchdog_trigger(data);
552 if (ret)
553 return ret;
554 }
555 return count;
556}
557
558static long watchdog_ioctl(struct file *filp, unsigned int cmd,
559 unsigned long arg)
560{
561 struct watchdog_info ident = {
562 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT,
563 .identity = "sch56xx watchdog"
564 };
565 int i, ret = 0;
566 struct sch56xx_watchdog_data *data = filp->private_data;
567
568 switch (cmd) {
569 case WDIOC_GETSUPPORT:
570 ident.firmware_version = data->revision;
571 if (!nowayout)
572 ident.options |= WDIOF_MAGICCLOSE;
573 if (copy_to_user((void __user *)arg, &ident, sizeof(ident)))
574 ret = -EFAULT;
575 break;
576
577 case WDIOC_GETSTATUS:
578 case WDIOC_GETBOOTSTATUS:
579 ret = put_user(0, (int __user *)arg);
580 break;
581
582 case WDIOC_KEEPALIVE:
583 ret = watchdog_trigger(data);
584 break;
585
586 case WDIOC_GETTIMEOUT:
587 i = watchdog_get_timeout(data);
588 ret = put_user(i, (int __user *)arg);
589 break;
590
591 case WDIOC_SETTIMEOUT:
592 if (get_user(i, (int __user *)arg)) {
593 ret = -EFAULT;
594 break;
595 }
596 ret = watchdog_set_timeout(data, i);
597 if (ret >= 0)
598 ret = put_user(ret, (int __user *)arg);
599 break;
600
601 case WDIOC_SETOPTIONS:
602 if (get_user(i, (int __user *)arg)) {
603 ret = -EFAULT;
604 break;
605 }
606
607 if (i & WDIOS_DISABLECARD)
608 ret = watchdog_stop(data);
609 else if (i & WDIOS_ENABLECARD)
610 ret = watchdog_trigger(data);
611 else
612 ret = -EINVAL;
613 break;
614
615 default:
616 ret = -ENOTTY;
617 }
618 return ret;
619}
620
621static const struct file_operations watchdog_fops = {
622 .owner = THIS_MODULE,
623 .llseek = no_llseek,
624 .open = watchdog_open,
625 .release = watchdog_release,
626 .write = watchdog_write,
627 .unlocked_ioctl = watchdog_ioctl,
628};
629
630struct sch56xx_watchdog_data *sch56xx_watchdog_register(
631 u16 addr, u32 revision, struct mutex *io_lock, int check_enabled)
632{
633 struct sch56xx_watchdog_data *data;
634 int i, err, control, output_enable;
635 const int watchdog_minors[] = { WATCHDOG_MINOR, 212, 213, 214, 215 };
636
637 /* Cache the watchdog registers */
638 mutex_lock(io_lock);
639 control =
640 sch56xx_read_virtual_reg(addr, SCH56XX_REG_WDOG_CONTROL);
641 output_enable =
642 sch56xx_read_virtual_reg(addr, SCH56XX_REG_WDOG_OUTPUT_ENABLE);
643 mutex_unlock(io_lock);
644
645 if (control < 0)
646 return NULL;
647 if (output_enable < 0)
648 return NULL;
649 if (check_enabled && !(output_enable & SCH56XX_WDOG_OUTPUT_ENABLE)) {
650 pr_warn("Watchdog not enabled by BIOS, not registering\n");
651 return NULL;
652 }
653
654 data = kzalloc(sizeof(struct sch56xx_watchdog_data), GFP_KERNEL);
655 if (!data)
656 return NULL;
657
658 data->addr = addr;
659 data->revision = revision;
660 data->io_lock = io_lock;
661 data->watchdog_control = control;
662 data->watchdog_output_enable = output_enable;
663 mutex_init(&data->watchdog_lock);
664 INIT_LIST_HEAD(&data->list);
665 kref_init(&data->kref);
666
667 err = watchdog_set_timeout(data, 60);
668 if (err < 0)
669 goto error;
670
671 /*
672 * We take the data_mutex lock early so that watchdog_open() cannot
673 * run when misc_register() has completed, but we've not yet added
674 * our data to the watchdog_data_list.
675 */
676 mutex_lock(&watchdog_data_mutex);
677 for (i = 0; i < ARRAY_SIZE(watchdog_minors); i++) {
678 /* Register our watchdog part */
679 snprintf(data->watchdog_name, sizeof(data->watchdog_name),
680 "watchdog%c", (i == 0) ? '\0' : ('0' + i));
681 data->watchdog_miscdev.name = data->watchdog_name;
682 data->watchdog_miscdev.fops = &watchdog_fops;
683 data->watchdog_miscdev.minor = watchdog_minors[i];
684 err = misc_register(&data->watchdog_miscdev);
685 if (err == -EBUSY)
686 continue;
687 if (err)
688 break;
689
690 list_add(&data->list, &watchdog_data_list);
691 pr_info("Registered /dev/%s chardev major 10, minor: %d\n",
692 data->watchdog_name, watchdog_minors[i]);
693 break;
694 }
695 mutex_unlock(&watchdog_data_mutex);
696
697 if (err) {
698 pr_err("Registering watchdog chardev: %d\n", err);
699 goto error;
700 }
701 if (i == ARRAY_SIZE(watchdog_minors)) {
702 pr_warn("Couldn't register watchdog (no free minor)\n");
703 goto error;
704 }
705
706 return data;
707
708error:
709 kfree(data);
710 return NULL;
711}
712EXPORT_SYMBOL(sch56xx_watchdog_register);
713
714void sch56xx_watchdog_unregister(struct sch56xx_watchdog_data *data)
715{
716 mutex_lock(&watchdog_data_mutex);
717 misc_deregister(&data->watchdog_miscdev);
718 list_del(&data->list);
719 mutex_unlock(&watchdog_data_mutex);
720
721 mutex_lock(&data->watchdog_lock);
722 if (data->watchdog_is_open) {
723 pr_warn("platform device unregistered with watchdog "
724 "open! Stopping watchdog.\n");
725 watchdog_stop_unlocked(data);
726 }
727 /* Tell the wdog start/stop/trigger functions our dev is gone */
728 data->addr = 0;
729 data->io_lock = NULL;
730 mutex_unlock(&data->watchdog_lock);
731
732 mutex_lock(&watchdog_data_mutex);
733 kref_put(&data->kref, sch56xx_watchdog_release_resources);
734 mutex_unlock(&watchdog_data_mutex);
735}
736EXPORT_SYMBOL(sch56xx_watchdog_unregister);
737
738/*
739 * platform dev find, add and remove functions
740 */
741
227static int __init sch56xx_find(int sioaddr, unsigned short *address, 742static int __init sch56xx_find(int sioaddr, unsigned short *address,
228 const char **name) 743 const char **name)
229{ 744{
diff --git a/drivers/hwmon/sch56xx-common.h b/drivers/hwmon/sch56xx-common.h
index d5eaf3b9ebf5..7475086eb978 100644
--- a/drivers/hwmon/sch56xx-common.h
+++ b/drivers/hwmon/sch56xx-common.h
@@ -1,5 +1,5 @@
1/*************************************************************************** 1/***************************************************************************
2 * Copyright (C) 2010-2011 Hans de Goede <hdegoede@redhat.com> * 2 * Copyright (C) 2010-2012 Hans de Goede <hdegoede@redhat.com> *
3 * * 3 * *
4 * This program is free software; you can redistribute it and/or modify * 4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by * 5 * it under the terms of the GNU General Public License as published by *
@@ -17,8 +17,16 @@
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/ 18 ***************************************************************************/
19 19
20#include <linux/mutex.h>
21
22struct sch56xx_watchdog_data;
23
20int sch56xx_read_virtual_reg(u16 addr, u16 reg); 24int sch56xx_read_virtual_reg(u16 addr, u16 reg);
21int sch56xx_write_virtual_reg(u16 addr, u16 reg, u8 val); 25int sch56xx_write_virtual_reg(u16 addr, u16 reg, u8 val);
22int sch56xx_read_virtual_reg16(u16 addr, u16 reg); 26int sch56xx_read_virtual_reg16(u16 addr, u16 reg);
23int sch56xx_read_virtual_reg12(u16 addr, u16 msb_reg, u16 lsn_reg, 27int sch56xx_read_virtual_reg12(u16 addr, u16 msb_reg, u16 lsn_reg,
24 int high_nibble); 28 int high_nibble);
29
30struct sch56xx_watchdog_data *sch56xx_watchdog_register(
31 u16 addr, u32 revision, struct mutex *io_lock, int check_enabled);
32void sch56xx_watchdog_unregister(struct sch56xx_watchdog_data *data);
diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
index 91fdd1fe18b0..8b011d016621 100644
--- a/drivers/hwmon/sht15.c
+++ b/drivers/hwmon/sht15.c
@@ -806,7 +806,7 @@ static void sht15_bh_read_data(struct work_struct *work_s)
806 */ 806 */
807 atomic_set(&data->interrupt_handled, 0); 807 atomic_set(&data->interrupt_handled, 0);
808 enable_irq(gpio_to_irq(data->pdata->gpio_data)); 808 enable_irq(gpio_to_irq(data->pdata->gpio_data));
809 /* If still not occurred or another handler has been scheduled */ 809 /* If still not occurred or another handler was scheduled */
810 if (gpio_get_value(data->pdata->gpio_data) 810 if (gpio_get_value(data->pdata->gpio_data)
811 || atomic_read(&data->interrupt_handled)) 811 || atomic_read(&data->interrupt_handled))
812 return; 812 return;
diff --git a/drivers/hwmon/sht21.c b/drivers/hwmon/sht21.c
index 15398780cc00..6c2dede4b8e7 100644
--- a/drivers/hwmon/sht21.c
+++ b/drivers/hwmon/sht21.c
@@ -261,28 +261,7 @@ static struct i2c_driver sht21_driver = {
261 .id_table = sht21_id, 261 .id_table = sht21_id,
262}; 262};
263 263
264/** 264module_i2c_driver(sht21_driver);
265 * sht21_init() - initialize driver
266 *
267 * Called when kernel is booted or module is inserted.
268 * Returns 0 on success.
269 */
270static int __init sht21_init(void)
271{
272 return i2c_add_driver(&sht21_driver);
273}
274module_init(sht21_init);
275
276/**
277 * sht21_init() - clean up driver
278 *
279 * Called when module is removed.
280 */
281static void __exit sht21_exit(void)
282{
283 i2c_del_driver(&sht21_driver);
284}
285module_exit(sht21_exit);
286 265
287MODULE_AUTHOR("Urs Fleisch <urs.fleisch@sensirion.com>"); 266MODULE_AUTHOR("Urs Fleisch <urs.fleisch@sensirion.com>");
288MODULE_DESCRIPTION("Sensirion SHT21 humidity and temperature sensor driver"); 267MODULE_DESCRIPTION("Sensirion SHT21 humidity and temperature sensor driver");
diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c
index 47d7ce9af8fb..6c4d8eb9b7ca 100644
--- a/drivers/hwmon/sis5595.c
+++ b/drivers/hwmon/sis5595.c
@@ -1,54 +1,54 @@
1/* 1/*
2 sis5595.c - Part of lm_sensors, Linux kernel modules 2 * sis5595.c - Part of lm_sensors, Linux kernel modules
3 for hardware monitoring 3 * for hardware monitoring
4 4 *
5 Copyright (C) 1998 - 2001 Frodo Looijaard <frodol@dds.nl>, 5 * Copyright (C) 1998 - 2001 Frodo Looijaard <frodol@dds.nl>,
6 Kyösti Mälkki <kmalkki@cc.hut.fi>, and 6 * Kyösti Mälkki <kmalkki@cc.hut.fi>, and
7 Mark D. Studebaker <mdsxyz123@yahoo.com> 7 * Mark D. Studebaker <mdsxyz123@yahoo.com>
8 Ported to Linux 2.6 by Aurelien Jarno <aurelien@aurel32.net> with 8 * Ported to Linux 2.6 by Aurelien Jarno <aurelien@aurel32.net> with
9 the help of Jean Delvare <khali@linux-fr.org> 9 * the help of Jean Delvare <khali@linux-fr.org>
10 10 *
11 This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by 12 * it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or 13 * the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version. 14 * (at your option) any later version.
15 15 *
16 This program is distributed in the hope that it will be useful, 16 * This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details. 19 * GNU General Public License for more details.
20 20 *
21 You should have received a copy of the GNU General Public License 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 22 * along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24*/ 24 */
25 25
26/* 26/*
27 SiS southbridge has a LM78-like chip integrated on the same IC. 27 * SiS southbridge has a LM78-like chip integrated on the same IC.
28 This driver is a customized copy of lm78.c 28 * This driver is a customized copy of lm78.c
29 29 *
30 Supports following revisions: 30 * Supports following revisions:
31 Version PCI ID PCI Revision 31 * Version PCI ID PCI Revision
32 1 1039/0008 AF or less 32 * 1 1039/0008 AF or less
33 2 1039/0008 B0 or greater 33 * 2 1039/0008 B0 or greater
34 34 *
35 Note: these chips contain a 0008 device which is incompatible with the 35 * Note: these chips contain a 0008 device which is incompatible with the
36 5595. We recognize these by the presence of the listed 36 * 5595. We recognize these by the presence of the listed
37 "blacklist" PCI ID and refuse to load. 37 * "blacklist" PCI ID and refuse to load.
38 38 *
39 NOT SUPPORTED PCI ID BLACKLIST PCI ID 39 * NOT SUPPORTED PCI ID BLACKLIST PCI ID
40 540 0008 0540 40 * 540 0008 0540
41 550 0008 0550 41 * 550 0008 0550
42 5513 0008 5511 42 * 5513 0008 5511
43 5581 0008 5597 43 * 5581 0008 5597
44 5582 0008 5597 44 * 5582 0008 5597
45 5597 0008 5597 45 * 5597 0008 5597
46 5598 0008 5597/5598 46 * 5598 0008 5597/5598
47 630 0008 0630 47 * 630 0008 0630
48 645 0008 0645 48 * 645 0008 0645
49 730 0008 0730 49 * 730 0008 0730
50 735 0008 0735 50 * 735 0008 0735
51*/ 51 */
52 52
53#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 53#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
54 54
@@ -68,8 +68,10 @@
68#include <linux/io.h> 68#include <linux/io.h>
69 69
70 70
71/* If force_addr is set to anything different from 0, we forcibly enable 71/*
72 the device at the given address. */ 72 * If force_addr is set to anything different from 0, we forcibly enable
73 * the device at the given address.
74 */
73static u16 force_addr; 75static u16 force_addr;
74module_param(force_addr, ushort, 0); 76module_param(force_addr, ushort, 0);
75MODULE_PARM_DESC(force_addr, 77MODULE_PARM_DESC(force_addr,
@@ -98,30 +100,36 @@ static struct platform_device *pdev;
98#define SIS5595_REG_FAN_MIN(nr) (0x3b + (nr)) 100#define SIS5595_REG_FAN_MIN(nr) (0x3b + (nr))
99#define SIS5595_REG_FAN(nr) (0x28 + (nr)) 101#define SIS5595_REG_FAN(nr) (0x28 + (nr))
100 102
101/* On the first version of the chip, the temp registers are separate. 103/*
102 On the second version, 104 * On the first version of the chip, the temp registers are separate.
103 TEMP pin is shared with IN4, configured in PCI register 0x7A. 105 * On the second version,
104 The registers are the same as well. 106 * TEMP pin is shared with IN4, configured in PCI register 0x7A.
105 OVER and HYST are really MAX and MIN. */ 107 * The registers are the same as well.
108 * OVER and HYST are really MAX and MIN.
109 */
106 110
107#define REV2MIN 0xb0 111#define REV2MIN 0xb0
108#define SIS5595_REG_TEMP (( data->revision) >= REV2MIN) ? \ 112#define SIS5595_REG_TEMP (((data->revision) >= REV2MIN) ? \
109 SIS5595_REG_IN(4) : 0x27 113 SIS5595_REG_IN(4) : 0x27)
110#define SIS5595_REG_TEMP_OVER (( data->revision) >= REV2MIN) ? \ 114#define SIS5595_REG_TEMP_OVER (((data->revision) >= REV2MIN) ? \
111 SIS5595_REG_IN_MAX(4) : 0x39 115 SIS5595_REG_IN_MAX(4) : 0x39)
112#define SIS5595_REG_TEMP_HYST (( data->revision) >= REV2MIN) ? \ 116#define SIS5595_REG_TEMP_HYST (((data->revision) >= REV2MIN) ? \
113 SIS5595_REG_IN_MIN(4) : 0x3a 117 SIS5595_REG_IN_MIN(4) : 0x3a)
114 118
115#define SIS5595_REG_CONFIG 0x40 119#define SIS5595_REG_CONFIG 0x40
116#define SIS5595_REG_ALARM1 0x41 120#define SIS5595_REG_ALARM1 0x41
117#define SIS5595_REG_ALARM2 0x42 121#define SIS5595_REG_ALARM2 0x42
118#define SIS5595_REG_FANDIV 0x47 122#define SIS5595_REG_FANDIV 0x47
119 123
120/* Conversions. Limit checking is only done on the TO_REG 124/*
121 variants. */ 125 * Conversions. Limit checking is only done on the TO_REG
126 * variants.
127 */
122 128
123/* IN: mV, (0V to 4.08V) 129/*
124 REG: 16mV/bit */ 130 * IN: mV, (0V to 4.08V)
131 * REG: 16mV/bit
132 */
125static inline u8 IN_TO_REG(unsigned long val) 133static inline u8 IN_TO_REG(unsigned long val)
126{ 134{
127 unsigned long nval = SENSORS_LIMIT(val, 0, 4080); 135 unsigned long nval = SENSORS_LIMIT(val, 0, 4080);
@@ -138,11 +146,13 @@ static inline u8 FAN_TO_REG(long rpm, int div)
138 146
139static inline int FAN_FROM_REG(u8 val, int div) 147static inline int FAN_FROM_REG(u8 val, int div)
140{ 148{
141 return val==0 ? -1 : val==255 ? 0 : 1350000/(val*div); 149 return val == 0 ? -1 : val == 255 ? 0 : 1350000 / (val * div);
142} 150}
143 151
144/* TEMP: mC (-54.12C to +157.53C) 152/*
145 REG: 0.83C/bit + 52.12, two's complement */ 153 * TEMP: mC (-54.12C to +157.53C)
154 * REG: 0.83C/bit + 52.12, two's complement
155 */
146static inline int TEMP_FROM_REG(s8 val) 156static inline int TEMP_FROM_REG(s8 val)
147{ 157{
148 return val * 830 + 52120; 158 return val * 830 + 52120;
@@ -150,19 +160,23 @@ static inline int TEMP_FROM_REG(s8 val)
150static inline s8 TEMP_TO_REG(int val) 160static inline s8 TEMP_TO_REG(int val)
151{ 161{
152 int nval = SENSORS_LIMIT(val, -54120, 157530) ; 162 int nval = SENSORS_LIMIT(val, -54120, 157530) ;
153 return nval<0 ? (nval-5212-415)/830 : (nval-5212+415)/830; 163 return nval < 0 ? (nval - 5212 - 415) / 830 : (nval - 5212 + 415) / 830;
154} 164}
155 165
156/* FAN DIV: 1, 2, 4, or 8 (defaults to 2) 166/*
157 REG: 0, 1, 2, or 3 (respectively) (defaults to 1) */ 167 * FAN DIV: 1, 2, 4, or 8 (defaults to 2)
168 * REG: 0, 1, 2, or 3 (respectively) (defaults to 1)
169 */
158static inline u8 DIV_TO_REG(int val) 170static inline u8 DIV_TO_REG(int val)
159{ 171{
160 return val==8 ? 3 : val==4 ? 2 : val==1 ? 0 : 1; 172 return val == 8 ? 3 : val == 4 ? 2 : val == 1 ? 0 : 1;
161} 173}
162#define DIV_FROM_REG(val) (1 << (val)) 174#define DIV_FROM_REG(val) (1 << (val))
163 175
164/* For each registered chip, we need to keep some data in memory. 176/*
165 The structure is dynamically allocated. */ 177 * For each registered chip, we need to keep some data in memory.
178 * The structure is dynamically allocated.
179 */
166struct sis5595_data { 180struct sis5595_data {
167 unsigned short addr; 181 unsigned short addr;
168 const char *name; 182 const char *name;
@@ -240,7 +254,12 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *da,
240 struct sis5595_data *data = dev_get_drvdata(dev); 254 struct sis5595_data *data = dev_get_drvdata(dev);
241 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 255 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
242 int nr = attr->index; 256 int nr = attr->index;
243 unsigned long val = simple_strtoul(buf, NULL, 10); 257 unsigned long val;
258 int err;
259
260 err = kstrtoul(buf, 10, &val);
261 if (err)
262 return err;
244 263
245 mutex_lock(&data->update_lock); 264 mutex_lock(&data->update_lock);
246 data->in_min[nr] = IN_TO_REG(val); 265 data->in_min[nr] = IN_TO_REG(val);
@@ -255,7 +274,12 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *da,
255 struct sis5595_data *data = dev_get_drvdata(dev); 274 struct sis5595_data *data = dev_get_drvdata(dev);
256 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 275 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
257 int nr = attr->index; 276 int nr = attr->index;
258 unsigned long val = simple_strtoul(buf, NULL, 10); 277 unsigned long val;
278 int err;
279
280 err = kstrtoul(buf, 10, &val);
281 if (err)
282 return err;
259 283
260 mutex_lock(&data->update_lock); 284 mutex_lock(&data->update_lock);
261 data->in_max[nr] = IN_TO_REG(val); 285 data->in_max[nr] = IN_TO_REG(val);
@@ -279,22 +303,30 @@ show_in_offset(3);
279show_in_offset(4); 303show_in_offset(4);
280 304
281/* Temperature */ 305/* Temperature */
282static ssize_t show_temp(struct device *dev, struct device_attribute *attr, char *buf) 306static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
307 char *buf)
283{ 308{
284 struct sis5595_data *data = sis5595_update_device(dev); 309 struct sis5595_data *data = sis5595_update_device(dev);
285 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp)); 310 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp));
286} 311}
287 312
288static ssize_t show_temp_over(struct device *dev, struct device_attribute *attr, char *buf) 313static ssize_t show_temp_over(struct device *dev, struct device_attribute *attr,
314 char *buf)
289{ 315{
290 struct sis5595_data *data = sis5595_update_device(dev); 316 struct sis5595_data *data = sis5595_update_device(dev);
291 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_over)); 317 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_over));
292} 318}
293 319
294static ssize_t set_temp_over(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 320static ssize_t set_temp_over(struct device *dev, struct device_attribute *attr,
321 const char *buf, size_t count)
295{ 322{
296 struct sis5595_data *data = dev_get_drvdata(dev); 323 struct sis5595_data *data = dev_get_drvdata(dev);
297 long val = simple_strtol(buf, NULL, 10); 324 long val;
325 int err;
326
327 err = kstrtol(buf, 10, &val);
328 if (err)
329 return err;
298 330
299 mutex_lock(&data->update_lock); 331 mutex_lock(&data->update_lock);
300 data->temp_over = TEMP_TO_REG(val); 332 data->temp_over = TEMP_TO_REG(val);
@@ -303,16 +335,23 @@ static ssize_t set_temp_over(struct device *dev, struct device_attribute *attr,
303 return count; 335 return count;
304} 336}
305 337
306static ssize_t show_temp_hyst(struct device *dev, struct device_attribute *attr, char *buf) 338static ssize_t show_temp_hyst(struct device *dev, struct device_attribute *attr,
339 char *buf)
307{ 340{
308 struct sis5595_data *data = sis5595_update_device(dev); 341 struct sis5595_data *data = sis5595_update_device(dev);
309 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_hyst)); 342 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_hyst));
310} 343}
311 344
312static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 345static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *attr,
346 const char *buf, size_t count)
313{ 347{
314 struct sis5595_data *data = dev_get_drvdata(dev); 348 struct sis5595_data *data = dev_get_drvdata(dev);
315 long val = simple_strtol(buf, NULL, 10); 349 long val;
350 int err;
351
352 err = kstrtol(buf, 10, &val);
353 if (err)
354 return err;
316 355
317 mutex_lock(&data->update_lock); 356 mutex_lock(&data->update_lock);
318 data->temp_hyst = TEMP_TO_REG(val); 357 data->temp_hyst = TEMP_TO_REG(val);
@@ -335,7 +374,7 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *da,
335 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 374 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
336 int nr = attr->index; 375 int nr = attr->index;
337 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], 376 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
338 DIV_FROM_REG(data->fan_div[nr])) ); 377 DIV_FROM_REG(data->fan_div[nr])));
339} 378}
340 379
341static ssize_t show_fan_min(struct device *dev, struct device_attribute *da, 380static ssize_t show_fan_min(struct device *dev, struct device_attribute *da,
@@ -344,8 +383,8 @@ static ssize_t show_fan_min(struct device *dev, struct device_attribute *da,
344 struct sis5595_data *data = sis5595_update_device(dev); 383 struct sis5595_data *data = sis5595_update_device(dev);
345 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 384 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
346 int nr = attr->index; 385 int nr = attr->index;
347 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr], 386 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
348 DIV_FROM_REG(data->fan_div[nr])) ); 387 DIV_FROM_REG(data->fan_div[nr])));
349} 388}
350 389
351static ssize_t set_fan_min(struct device *dev, struct device_attribute *da, 390static ssize_t set_fan_min(struct device *dev, struct device_attribute *da,
@@ -354,7 +393,12 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *da,
354 struct sis5595_data *data = dev_get_drvdata(dev); 393 struct sis5595_data *data = dev_get_drvdata(dev);
355 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 394 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
356 int nr = attr->index; 395 int nr = attr->index;
357 unsigned long val = simple_strtoul(buf, NULL, 10); 396 unsigned long val;
397 int err;
398
399 err = kstrtoul(buf, 10, &val);
400 if (err)
401 return err;
358 402
359 mutex_lock(&data->update_lock); 403 mutex_lock(&data->update_lock);
360 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 404 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
@@ -369,13 +413,15 @@ static ssize_t show_fan_div(struct device *dev, struct device_attribute *da,
369 struct sis5595_data *data = sis5595_update_device(dev); 413 struct sis5595_data *data = sis5595_update_device(dev);
370 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 414 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
371 int nr = attr->index; 415 int nr = attr->index;
372 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) ); 416 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
373} 417}
374 418
375/* Note: we save and restore the fan minimum here, because its value is 419/*
376 determined in part by the fan divisor. This follows the principle of 420 * Note: we save and restore the fan minimum here, because its value is
377 least surprise; the user doesn't expect the fan minimum to change just 421 * determined in part by the fan divisor. This follows the principle of
378 because the divisor changed. */ 422 * least surprise; the user doesn't expect the fan minimum to change just
423 * because the divisor changed.
424 */
379static ssize_t set_fan_div(struct device *dev, struct device_attribute *da, 425static ssize_t set_fan_div(struct device *dev, struct device_attribute *da,
380 const char *buf, size_t count) 426 const char *buf, size_t count)
381{ 427{
@@ -383,8 +429,13 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *da,
383 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 429 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
384 int nr = attr->index; 430 int nr = attr->index;
385 unsigned long min; 431 unsigned long min;
386 unsigned long val = simple_strtoul(buf, NULL, 10);
387 int reg; 432 int reg;
433 unsigned long val;
434 int err;
435
436 err = kstrtoul(buf, 10, &val);
437 if (err)
438 return err;
388 439
389 mutex_lock(&data->update_lock); 440 mutex_lock(&data->update_lock);
390 min = FAN_FROM_REG(data->fan_min[nr], 441 min = FAN_FROM_REG(data->fan_min[nr],
@@ -392,17 +443,25 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *da,
392 reg = sis5595_read_value(data, SIS5595_REG_FANDIV); 443 reg = sis5595_read_value(data, SIS5595_REG_FANDIV);
393 444
394 switch (val) { 445 switch (val) {
395 case 1: data->fan_div[nr] = 0; break; 446 case 1:
396 case 2: data->fan_div[nr] = 1; break; 447 data->fan_div[nr] = 0;
397 case 4: data->fan_div[nr] = 2; break; 448 break;
398 case 8: data->fan_div[nr] = 3; break; 449 case 2:
450 data->fan_div[nr] = 1;
451 break;
452 case 4:
453 data->fan_div[nr] = 2;
454 break;
455 case 8:
456 data->fan_div[nr] = 3;
457 break;
399 default: 458 default:
400 dev_err(dev, "fan_div value %ld not " 459 dev_err(dev, "fan_div value %ld not "
401 "supported. Choose one of 1, 2, 4 or 8!\n", val); 460 "supported. Choose one of 1, 2, 4 or 8!\n", val);
402 mutex_unlock(&data->update_lock); 461 mutex_unlock(&data->update_lock);
403 return -EINVAL; 462 return -EINVAL;
404 } 463 }
405 464
406 switch (nr) { 465 switch (nr) {
407 case 0: 466 case 0:
408 reg = (reg & 0xcf) | (data->fan_div[nr] << 4); 467 reg = (reg & 0xcf) | (data->fan_div[nr] << 4);
@@ -431,7 +490,8 @@ show_fan_offset(1);
431show_fan_offset(2); 490show_fan_offset(2);
432 491
433/* Alarms */ 492/* Alarms */
434static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 493static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
494 char *buf)
435{ 495{
436 struct sis5595_data *data = sis5595_update_device(dev); 496 struct sis5595_data *data = sis5595_update_device(dev);
437 return sprintf(buf, "%d\n", data->alarms); 497 return sprintf(buf, "%d\n", data->alarms);
@@ -521,7 +581,7 @@ static struct attribute *sis5595_attributes_temp1[] = {
521static const struct attribute_group sis5595_group_temp1 = { 581static const struct attribute_group sis5595_group_temp1 = {
522 .attrs = sis5595_attributes_temp1, 582 .attrs = sis5595_attributes_temp1,
523}; 583};
524 584
525/* This is called when the module is loaded */ 585/* This is called when the module is loaded */
526static int __devinit sis5595_probe(struct platform_device *pdev) 586static int __devinit sis5595_probe(struct platform_device *pdev)
527{ 587{
@@ -539,7 +599,8 @@ static int __devinit sis5595_probe(struct platform_device *pdev)
539 goto exit; 599 goto exit;
540 } 600 }
541 601
542 if (!(data = kzalloc(sizeof(struct sis5595_data), GFP_KERNEL))) { 602 data = kzalloc(sizeof(struct sis5595_data), GFP_KERNEL);
603 if (!data) {
543 err = -ENOMEM; 604 err = -ENOMEM;
544 goto exit_release; 605 goto exit_release;
545 } 606 }
@@ -550,7 +611,9 @@ static int __devinit sis5595_probe(struct platform_device *pdev)
550 data->name = "sis5595"; 611 data->name = "sis5595";
551 platform_set_drvdata(pdev, data); 612 platform_set_drvdata(pdev, data);
552 613
553 /* Check revision and pin registers to determine whether 4 or 5 voltages */ 614 /*
615 * Check revision and pin registers to determine whether 4 or 5 voltages
616 */
554 data->revision = s_bridge->revision; 617 data->revision = s_bridge->revision;
555 /* 4 voltages, 1 temp */ 618 /* 4 voltages, 1 temp */
556 data->maxins = 3; 619 data->maxins = 3;
@@ -560,7 +623,7 @@ static int __devinit sis5595_probe(struct platform_device *pdev)
560 /* 5 voltages, no temps */ 623 /* 5 voltages, no temps */
561 data->maxins = 4; 624 data->maxins = 4;
562 } 625 }
563 626
564 /* Initialize the SIS5595 chip */ 627 /* Initialize the SIS5595 chip */
565 sis5595_init_device(data); 628 sis5595_init_device(data);
566 629
@@ -571,15 +634,16 @@ static int __devinit sis5595_probe(struct platform_device *pdev)
571 } 634 }
572 635
573 /* Register sysfs hooks */ 636 /* Register sysfs hooks */
574 if ((err = sysfs_create_group(&pdev->dev.kobj, &sis5595_group))) 637 err = sysfs_create_group(&pdev->dev.kobj, &sis5595_group);
638 if (err)
575 goto exit_free; 639 goto exit_free;
576 if (data->maxins == 4) { 640 if (data->maxins == 4) {
577 if ((err = sysfs_create_group(&pdev->dev.kobj, 641 err = sysfs_create_group(&pdev->dev.kobj, &sis5595_group_in4);
578 &sis5595_group_in4))) 642 if (err)
579 goto exit_remove_files; 643 goto exit_remove_files;
580 } else { 644 } else {
581 if ((err = sysfs_create_group(&pdev->dev.kobj, 645 err = sysfs_create_group(&pdev->dev.kobj, &sis5595_group_temp1);
582 &sis5595_group_temp1))) 646 if (err)
583 goto exit_remove_files; 647 goto exit_remove_files;
584 } 648 }
585 649
@@ -699,7 +763,7 @@ static struct sis5595_data *sis5595_update_device(struct device *dev)
699 return data; 763 return data;
700} 764}
701 765
702static const struct pci_device_id sis5595_pci_ids[] = { 766static DEFINE_PCI_DEVICE_TABLE(sis5595_pci_ids) = {
703 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) }, 767 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) },
704 { 0, } 768 { 0, }
705}; 769};
@@ -713,9 +777,11 @@ static int blacklist[] __devinitdata = {
713 PCI_DEVICE_ID_SI_645, 777 PCI_DEVICE_ID_SI_645,
714 PCI_DEVICE_ID_SI_730, 778 PCI_DEVICE_ID_SI_730,
715 PCI_DEVICE_ID_SI_735, 779 PCI_DEVICE_ID_SI_735,
716 PCI_DEVICE_ID_SI_5511, /* 5513 chip has the 0008 device but 780 PCI_DEVICE_ID_SI_5511, /*
717 that ID shows up in other chips so we 781 * 5513 chip has the 0008 device but
718 use the 5511 ID for recognition */ 782 * that ID shows up in other chips so we
783 * use the 5511 ID for recognition
784 */
719 PCI_DEVICE_ID_SI_5597, 785 PCI_DEVICE_ID_SI_5597,
720 PCI_DEVICE_ID_SI_5598, 786 PCI_DEVICE_ID_SI_5598,
721 0 }; 787 0 };
@@ -770,13 +836,16 @@ static int __devinit sis5595_pci_probe(struct pci_dev *dev,
770 836
771 for (i = blacklist; *i != 0; i++) { 837 for (i = blacklist; *i != 0; i++) {
772 struct pci_dev *d; 838 struct pci_dev *d;
773 if ((d = pci_get_device(PCI_VENDOR_ID_SI, *i, NULL))) { 839 d = pci_get_device(PCI_VENDOR_ID_SI, *i, NULL);
774 dev_err(&d->dev, "Looked for SIS5595 but found unsupported device %.4x\n", *i); 840 if (d) {
841 dev_err(&d->dev,
842 "Looked for SIS5595 but found unsupported device %.4x\n",
843 *i);
775 pci_dev_put(d); 844 pci_dev_put(d);
776 return -ENODEV; 845 return -ENODEV;
777 } 846 }
778 } 847 }
779 848
780 force_addr &= ~(SIS5595_EXTENT - 1); 849 force_addr &= ~(SIS5595_EXTENT - 1);
781 if (force_addr) { 850 if (force_addr) {
782 dev_warn(&dev->dev, "Forcing ISA address 0x%x\n", force_addr); 851 dev_warn(&dev->dev, "Forcing ISA address 0x%x\n", force_addr);
@@ -788,10 +857,11 @@ static int __devinit sis5595_pci_probe(struct pci_dev *dev,
788 dev_err(&dev->dev, "Failed to read ISA address\n"); 857 dev_err(&dev->dev, "Failed to read ISA address\n");
789 return -ENODEV; 858 return -ENODEV;
790 } 859 }
791 860
792 address &= ~(SIS5595_EXTENT - 1); 861 address &= ~(SIS5595_EXTENT - 1);
793 if (!address) { 862 if (!address) {
794 dev_err(&dev->dev, "Base address not set - upgrade BIOS or use force_addr=0xaddr\n"); 863 dev_err(&dev->dev,
864 "Base address not set - upgrade BIOS or use force_addr=0xaddr\n");
795 return -ENODEV; 865 return -ENODEV;
796 } 866 }
797 if (force_addr && address != force_addr) { 867 if (force_addr && address != force_addr) {
@@ -828,7 +898,8 @@ static int __devinit sis5595_pci_probe(struct pci_dev *dev,
828 if (sis5595_device_add(address)) 898 if (sis5595_device_add(address))
829 goto exit_unregister; 899 goto exit_unregister;
830 900
831 /* Always return failure here. This is to allow other drivers to bind 901 /*
902 * Always return failure here. This is to allow other drivers to bind
832 * to this pci device. We don't really want to have control over the 903 * to this pci device. We don't really want to have control over the
833 * pci device, we only wanted to read as few register values from it. 904 * pci device, we only wanted to read as few register values from it.
834 */ 905 */
diff --git a/drivers/hwmon/smm665.c b/drivers/hwmon/smm665.c
index 411638181fd8..cbc51fb30dba 100644
--- a/drivers/hwmon/smm665.c
+++ b/drivers/hwmon/smm665.c
@@ -124,9 +124,9 @@ enum chips { smm465, smm665, smm665c, smm764, smm766 };
124#define SMM665_AIN_ADC_TO_VOLTS(adc) ((adc) * vref / 512) 124#define SMM665_AIN_ADC_TO_VOLTS(adc) ((adc) * vref / 512)
125 125
126/* Temp Sensor */ 126/* Temp Sensor */
127#define SMM665_TEMP_ADC_TO_CELSIUS(adc) ((adc) <= 511) ? \ 127#define SMM665_TEMP_ADC_TO_CELSIUS(adc) (((adc) <= 511) ? \
128 ((int)(adc) * 1000 / 4) : \ 128 ((int)(adc) * 1000 / 4) : \
129 (((int)(adc) - 0x400) * 1000 / 4) 129 (((int)(adc) - 0x400) * 1000 / 4))
130 130
131#define SMM665_NUM_ADC 11 131#define SMM665_NUM_ADC 11
132 132
@@ -376,7 +376,7 @@ static ssize_t smm665_show_input(struct device *dev,
376} 376}
377 377
378#define SMM665_SHOW(what) \ 378#define SMM665_SHOW(what) \
379 static ssize_t smm665_show_##what(struct device *dev, \ 379static ssize_t smm665_show_##what(struct device *dev, \
380 struct device_attribute *da, char *buf) \ 380 struct device_attribute *da, char *buf) \
381{ \ 381{ \
382 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \ 382 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
@@ -389,7 +389,8 @@ SMM665_SHOW(max);
389SMM665_SHOW(lcrit); 389SMM665_SHOW(lcrit);
390SMM665_SHOW(crit); 390SMM665_SHOW(crit);
391 391
392/* These macros are used below in constructing device attribute objects 392/*
393 * These macros are used below in constructing device attribute objects
393 * for use with sysfs_create_group() to make a sysfs device file 394 * for use with sysfs_create_group() to make a sysfs device file
394 * for each register. 395 * for each register.
395 */ 396 */
@@ -583,10 +584,9 @@ static int smm665_probe(struct i2c_client *client,
583 if (i2c_smbus_read_byte_data(client, SMM665_ADOC_ENABLE) < 0) 584 if (i2c_smbus_read_byte_data(client, SMM665_ADOC_ENABLE) < 0)
584 return -ENODEV; 585 return -ENODEV;
585 586
586 ret = -ENOMEM; 587 data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
587 data = kzalloc(sizeof(*data), GFP_KERNEL);
588 if (!data) 588 if (!data)
589 goto out_return; 589 return -ENOMEM;
590 590
591 i2c_set_clientdata(client, data); 591 i2c_set_clientdata(client, data);
592 mutex_init(&data->update_lock); 592 mutex_init(&data->update_lock);
@@ -595,7 +595,7 @@ static int smm665_probe(struct i2c_client *client,
595 data->cmdreg = i2c_new_dummy(adapter, (client->addr & ~SMM665_REGMASK) 595 data->cmdreg = i2c_new_dummy(adapter, (client->addr & ~SMM665_REGMASK)
596 | SMM665_CMDREG_BASE); 596 | SMM665_CMDREG_BASE);
597 if (!data->cmdreg) 597 if (!data->cmdreg)
598 goto out_kfree; 598 return -ENOMEM;
599 599
600 switch (data->type) { 600 switch (data->type) {
601 case smm465: 601 case smm465:
@@ -678,9 +678,6 @@ out_remove_group:
678 sysfs_remove_group(&client->dev.kobj, &smm665_group); 678 sysfs_remove_group(&client->dev.kobj, &smm665_group);
679out_unregister: 679out_unregister:
680 i2c_unregister_device(data->cmdreg); 680 i2c_unregister_device(data->cmdreg);
681out_kfree:
682 kfree(data);
683out_return:
684 return ret; 681 return ret;
685} 682}
686 683
@@ -692,8 +689,6 @@ static int smm665_remove(struct i2c_client *client)
692 hwmon_device_unregister(data->hwmon_dev); 689 hwmon_device_unregister(data->hwmon_dev);
693 sysfs_remove_group(&client->dev.kobj, &smm665_group); 690 sysfs_remove_group(&client->dev.kobj, &smm665_group);
694 691
695 kfree(data);
696
697 return 0; 692 return 0;
698} 693}
699 694
@@ -718,19 +713,8 @@ static struct i2c_driver smm665_driver = {
718 .id_table = smm665_id, 713 .id_table = smm665_id,
719}; 714};
720 715
721static int __init smm665_init(void) 716module_i2c_driver(smm665_driver);
722{
723 return i2c_add_driver(&smm665_driver);
724}
725
726static void __exit smm665_exit(void)
727{
728 i2c_del_driver(&smm665_driver);
729}
730 717
731MODULE_AUTHOR("Guenter Roeck"); 718MODULE_AUTHOR("Guenter Roeck");
732MODULE_DESCRIPTION("SMM665 driver"); 719MODULE_DESCRIPTION("SMM665 driver");
733MODULE_LICENSE("GPL"); 720MODULE_LICENSE("GPL");
734
735module_init(smm665_init);
736module_exit(smm665_exit);
diff --git a/drivers/hwmon/smsc47b397.c b/drivers/hwmon/smsc47b397.c
index 65c88ff5645a..d3b778da3f86 100644
--- a/drivers/hwmon/smsc47b397.c
+++ b/drivers/hwmon/smsc47b397.c
@@ -1,30 +1,30 @@
1/* 1/*
2 smsc47b397.c - Part of lm_sensors, Linux kernel modules 2 * smsc47b397.c - Part of lm_sensors, Linux kernel modules
3 for hardware monitoring 3 * for hardware monitoring
4 4 *
5 Supports the SMSC LPC47B397-NC Super-I/O chip. 5 * Supports the SMSC LPC47B397-NC Super-I/O chip.
6 6 *
7 Author/Maintainer: Mark M. Hoffman <mhoffman@lightlink.com> 7 * Author/Maintainer: Mark M. Hoffman <mhoffman@lightlink.com>
8 Copyright (C) 2004 Utilitek Systems, Inc. 8 * Copyright (C) 2004 Utilitek Systems, Inc.
9 9 *
10 derived in part from smsc47m1.c: 10 * derived in part from smsc47m1.c:
11 Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com> 11 * Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com>
12 Copyright (C) 2004 Jean Delvare <khali@linux-fr.org> 12 * Copyright (C) 2004 Jean Delvare <khali@linux-fr.org>
13 13 *
14 This program is free software; you can redistribute it and/or modify 14 * This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by 15 * it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or 16 * the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version. 17 * (at your option) any later version.
18 18 *
19 This program is distributed in the hope that it will be useful, 19 * This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details. 22 * GNU General Public License for more details.
23 23 *
24 You should have received a copy of the GNU General Public License 24 * You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software 25 * along with this program; if not, write to the Free Software
26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27*/ 27 */
28 28
29#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 29#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30 30
@@ -157,8 +157,10 @@ static struct smsc47b397_data *smsc47b397_update_device(struct device *dev)
157 return data; 157 return data;
158} 158}
159 159
160/* TEMP: 0.001C/bit (-128C to +127C) 160/*
161 REG: 1C/bit, two's complement */ 161 * TEMP: 0.001C/bit (-128C to +127C)
162 * REG: 1C/bit, two's complement
163 */
162static int temp_from_reg(u8 reg) 164static int temp_from_reg(u8 reg)
163{ 165{
164 return (s8)reg * 1000; 166 return (s8)reg * 1000;
@@ -177,8 +179,10 @@ static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
177static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2); 179static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
178static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 3); 180static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 3);
179 181
180/* FAN: 1 RPM/bit 182/*
181 REG: count of 90kHz pulses / revolution */ 183 * FAN: 1 RPM/bit
184 * REG: count of 90kHz pulses / revolution
185 */
182static int fan_from_reg(u16 reg) 186static int fan_from_reg(u16 reg)
183{ 187{
184 if (reg == 0 || reg == 0xffff) 188 if (reg == 0 || reg == 0xffff)
diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c
index f44a89aac381..c590c1469793 100644
--- a/drivers/hwmon/smsc47m1.c
+++ b/drivers/hwmon/smsc47m1.c
@@ -1,30 +1,30 @@
1/* 1/*
2 smsc47m1.c - Part of lm_sensors, Linux kernel modules 2 * smsc47m1.c - Part of lm_sensors, Linux kernel modules
3 for hardware monitoring 3 * for hardware monitoring
4 4 *
5 Supports the SMSC LPC47B27x, LPC47M10x, LPC47M112, LPC47M13x, 5 * Supports the SMSC LPC47B27x, LPC47M10x, LPC47M112, LPC47M13x,
6 LPC47M14x, LPC47M15x, LPC47M192, LPC47M292 and LPC47M997 6 * LPC47M14x, LPC47M15x, LPC47M192, LPC47M292 and LPC47M997
7 Super-I/O chips. 7 * Super-I/O chips.
8 8 *
9 Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com> 9 * Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com>
10 Copyright (C) 2004-2007 Jean Delvare <khali@linux-fr.org> 10 * Copyright (C) 2004-2007 Jean Delvare <khali@linux-fr.org>
11 Ported to Linux 2.6 by Gabriele Gorla <gorlik@yahoo.com> 11 * Ported to Linux 2.6 by Gabriele Gorla <gorlik@yahoo.com>
12 and Jean Delvare 12 * and Jean Delvare
13 13 *
14 This program is free software; you can redistribute it and/or modify 14 * This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by 15 * it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or 16 * the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version. 17 * (at your option) any later version.
18 18 *
19 This program is distributed in the hope that it will be useful, 19 * This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details. 22 * GNU General Public License for more details.
23 23 *
24 You should have received a copy of the GNU General Public License 24 * You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software 25 * along with this program; if not, write to the Free Software
26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27*/ 27 */
28 28
29#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 29#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30 30
@@ -53,8 +53,8 @@ enum chips { smsc47m1, smsc47m2 };
53 53
54/* Super-I/0 registers and commands */ 54/* Super-I/0 registers and commands */
55 55
56#define REG 0x2e /* The register to read/write */ 56#define REG 0x2e /* The register to read/write */
57#define VAL 0x2f /* The value to read/write */ 57#define VAL 0x2f /* The value to read/write */
58 58
59static inline void 59static inline void
60superio_outb(int reg, int val) 60superio_outb(int reg, int val)
@@ -111,10 +111,11 @@ static const u8 SMSC47M1_REG_PWM[3] = { 0x56, 0x57, 0x69 };
111#define SMSC47M2_REG_PPIN3 0x2c 111#define SMSC47M2_REG_PPIN3 0x2c
112#define SMSC47M2_REG_FANDIV3 0x6a 112#define SMSC47M2_REG_FANDIV3 0x6a
113 113
114#define MIN_FROM_REG(reg,div) ((reg)>=192 ? 0 : \ 114#define MIN_FROM_REG(reg, div) ((reg) >= 192 ? 0 : \
115 983040/((192-(reg))*(div))) 115 983040 / ((192 - (reg)) * (div)))
116#define FAN_FROM_REG(reg,div,preload) ((reg)<=(preload) || (reg)==255 ? 0 : \ 116#define FAN_FROM_REG(reg, div, preload) ((reg) <= (preload) || (reg) == 255 ? \
117 983040/(((reg)-(preload))*(div))) 117 0 : \
118 983040 / (((reg) - (preload)) * (div)))
118#define DIV_FROM_REG(reg) (1 << (reg)) 119#define DIV_FROM_REG(reg) (1 << (reg))
119#define PWM_FROM_REG(reg) (((reg) & 0x7E) << 1) 120#define PWM_FROM_REG(reg) (((reg) & 0x7E) << 1)
120#define PWM_EN_FROM_REG(reg) ((~(reg)) & 0x01) 121#define PWM_EN_FROM_REG(reg) ((~(reg)) & 0x01)
@@ -171,10 +172,12 @@ static ssize_t get_fan(struct device *dev, struct device_attribute
171 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 172 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
172 struct smsc47m1_data *data = smsc47m1_update_device(dev, 0); 173 struct smsc47m1_data *data = smsc47m1_update_device(dev, 0);
173 int nr = attr->index; 174 int nr = attr->index;
174 /* This chip (stupidly) stops monitoring fan speed if PWM is 175 /*
175 enabled and duty cycle is 0%. This is fine if the monitoring 176 * This chip (stupidly) stops monitoring fan speed if PWM is
176 and control concern the same fan, but troublesome if they are 177 * enabled and duty cycle is 0%. This is fine if the monitoring
177 not (which could as well happen). */ 178 * and control concern the same fan, but troublesome if they are
179 * not (which could as well happen).
180 */
178 int rpm = (data->pwm[nr] & 0x7F) == 0x00 ? 0 : 181 int rpm = (data->pwm[nr] & 0x7F) == 0x00 ? 0 :
179 FAN_FROM_REG(data->fan[nr], 182 FAN_FROM_REG(data->fan[nr],
180 DIV_FROM_REG(data->fan_div[nr]), 183 DIV_FROM_REG(data->fan_div[nr]),
@@ -238,7 +241,13 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute
238 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 241 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
239 struct smsc47m1_data *data = dev_get_drvdata(dev); 242 struct smsc47m1_data *data = dev_get_drvdata(dev);
240 int nr = attr->index; 243 int nr = attr->index;
241 long rpmdiv, val = simple_strtol(buf, NULL, 10); 244 long rpmdiv;
245 long val;
246 int err;
247
248 err = kstrtol(buf, 10, &val);
249 if (err)
250 return err;
242 251
243 mutex_lock(&data->update_lock); 252 mutex_lock(&data->update_lock);
244 rpmdiv = val * DIV_FROM_REG(data->fan_div[nr]); 253 rpmdiv = val * DIV_FROM_REG(data->fan_div[nr]);
@@ -256,28 +265,44 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute
256 return count; 265 return count;
257} 266}
258 267
259/* Note: we save and restore the fan minimum here, because its value is 268/*
260 determined in part by the fan clock divider. This follows the principle 269 * Note: we save and restore the fan minimum here, because its value is
261 of least surprise; the user doesn't expect the fan minimum to change just 270 * determined in part by the fan clock divider. This follows the principle
262 because the divider changed. */ 271 * of least surprise; the user doesn't expect the fan minimum to change just
272 * because the divider changed.
273 */
263static ssize_t set_fan_div(struct device *dev, struct device_attribute 274static ssize_t set_fan_div(struct device *dev, struct device_attribute
264 *devattr, const char *buf, size_t count) 275 *devattr, const char *buf, size_t count)
265{ 276{
266 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 277 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
267 struct smsc47m1_data *data = dev_get_drvdata(dev); 278 struct smsc47m1_data *data = dev_get_drvdata(dev);
268 int nr = attr->index; 279 int nr = attr->index;
269 long new_div = simple_strtol(buf, NULL, 10), tmp; 280 long new_div;
281 int err;
282 long tmp;
270 u8 old_div = DIV_FROM_REG(data->fan_div[nr]); 283 u8 old_div = DIV_FROM_REG(data->fan_div[nr]);
271 284
285 err = kstrtol(buf, 10, &new_div);
286 if (err)
287 return err;
288
272 if (new_div == old_div) /* No change */ 289 if (new_div == old_div) /* No change */
273 return count; 290 return count;
274 291
275 mutex_lock(&data->update_lock); 292 mutex_lock(&data->update_lock);
276 switch (new_div) { 293 switch (new_div) {
277 case 1: data->fan_div[nr] = 0; break; 294 case 1:
278 case 2: data->fan_div[nr] = 1; break; 295 data->fan_div[nr] = 0;
279 case 4: data->fan_div[nr] = 2; break; 296 break;
280 case 8: data->fan_div[nr] = 3; break; 297 case 2:
298 data->fan_div[nr] = 1;
299 break;
300 case 4:
301 data->fan_div[nr] = 2;
302 break;
303 case 8:
304 data->fan_div[nr] = 3;
305 break;
281 default: 306 default:
282 mutex_unlock(&data->update_lock); 307 mutex_unlock(&data->update_lock);
283 return -EINVAL; 308 return -EINVAL;
@@ -315,7 +340,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute
315 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 340 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
316 struct smsc47m1_data *data = dev_get_drvdata(dev); 341 struct smsc47m1_data *data = dev_get_drvdata(dev);
317 int nr = attr->index; 342 int nr = attr->index;
318 long val = simple_strtol(buf, NULL, 10); 343 long val;
344 int err;
345
346 err = kstrtol(buf, 10, &val);
347 if (err)
348 return err;
319 349
320 if (val < 0 || val > 255) 350 if (val < 0 || val > 255)
321 return -EINVAL; 351 return -EINVAL;
@@ -336,9 +366,14 @@ static ssize_t set_pwm_en(struct device *dev, struct device_attribute
336 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 366 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
337 struct smsc47m1_data *data = dev_get_drvdata(dev); 367 struct smsc47m1_data *data = dev_get_drvdata(dev);
338 int nr = attr->index; 368 int nr = attr->index;
339 long val = simple_strtol(buf, NULL, 10); 369 unsigned long val;
340 370 int err;
341 if (val != 0 && val != 1) 371
372 err = kstrtoul(buf, 10, &val);
373 if (err)
374 return err;
375
376 if (val > 1)
342 return -EINVAL; 377 return -EINVAL;
343 378
344 mutex_lock(&data->update_lock); 379 mutex_lock(&data->update_lock);
@@ -380,30 +415,73 @@ static ssize_t show_name(struct device *dev, struct device_attribute
380} 415}
381static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 416static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
382 417
383/* Almost all sysfs files may or may not be created depending on the chip 418static struct attribute *smsc47m1_attributes_fan1[] = {
384 setup so we create them individually. It is still convenient to define a
385 group to remove them all at once. */
386static struct attribute *smsc47m1_attributes[] = {
387 &sensor_dev_attr_fan1_input.dev_attr.attr, 419 &sensor_dev_attr_fan1_input.dev_attr.attr,
388 &sensor_dev_attr_fan1_min.dev_attr.attr, 420 &sensor_dev_attr_fan1_min.dev_attr.attr,
389 &sensor_dev_attr_fan1_div.dev_attr.attr, 421 &sensor_dev_attr_fan1_div.dev_attr.attr,
390 &sensor_dev_attr_fan1_alarm.dev_attr.attr, 422 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
423 NULL
424};
425
426static const struct attribute_group smsc47m1_group_fan1 = {
427 .attrs = smsc47m1_attributes_fan1,
428};
429
430static struct attribute *smsc47m1_attributes_fan2[] = {
391 &sensor_dev_attr_fan2_input.dev_attr.attr, 431 &sensor_dev_attr_fan2_input.dev_attr.attr,
392 &sensor_dev_attr_fan2_min.dev_attr.attr, 432 &sensor_dev_attr_fan2_min.dev_attr.attr,
393 &sensor_dev_attr_fan2_div.dev_attr.attr, 433 &sensor_dev_attr_fan2_div.dev_attr.attr,
394 &sensor_dev_attr_fan2_alarm.dev_attr.attr, 434 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
435 NULL
436};
437
438static const struct attribute_group smsc47m1_group_fan2 = {
439 .attrs = smsc47m1_attributes_fan2,
440};
441
442static struct attribute *smsc47m1_attributes_fan3[] = {
395 &sensor_dev_attr_fan3_input.dev_attr.attr, 443 &sensor_dev_attr_fan3_input.dev_attr.attr,
396 &sensor_dev_attr_fan3_min.dev_attr.attr, 444 &sensor_dev_attr_fan3_min.dev_attr.attr,
397 &sensor_dev_attr_fan3_div.dev_attr.attr, 445 &sensor_dev_attr_fan3_div.dev_attr.attr,
398 &sensor_dev_attr_fan3_alarm.dev_attr.attr, 446 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
447 NULL
448};
449
450static const struct attribute_group smsc47m1_group_fan3 = {
451 .attrs = smsc47m1_attributes_fan3,
452};
399 453
454static struct attribute *smsc47m1_attributes_pwm1[] = {
400 &sensor_dev_attr_pwm1.dev_attr.attr, 455 &sensor_dev_attr_pwm1.dev_attr.attr,
401 &sensor_dev_attr_pwm1_enable.dev_attr.attr, 456 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
457 NULL
458};
459
460static const struct attribute_group smsc47m1_group_pwm1 = {
461 .attrs = smsc47m1_attributes_pwm1,
462};
463
464static struct attribute *smsc47m1_attributes_pwm2[] = {
402 &sensor_dev_attr_pwm2.dev_attr.attr, 465 &sensor_dev_attr_pwm2.dev_attr.attr,
403 &sensor_dev_attr_pwm2_enable.dev_attr.attr, 466 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
467 NULL
468};
469
470static const struct attribute_group smsc47m1_group_pwm2 = {
471 .attrs = smsc47m1_attributes_pwm2,
472};
473
474static struct attribute *smsc47m1_attributes_pwm3[] = {
404 &sensor_dev_attr_pwm3.dev_attr.attr, 475 &sensor_dev_attr_pwm3.dev_attr.attr,
405 &sensor_dev_attr_pwm3_enable.dev_attr.attr, 476 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
477 NULL
478};
479
480static const struct attribute_group smsc47m1_group_pwm3 = {
481 .attrs = smsc47m1_attributes_pwm3,
482};
406 483
484static struct attribute *smsc47m1_attributes[] = {
407 &dev_attr_alarms.attr, 485 &dev_attr_alarms.attr,
408 &dev_attr_name.attr, 486 &dev_attr_name.attr,
409 NULL 487 NULL
@@ -476,8 +554,10 @@ static int __init smsc47m1_find(unsigned short *addr,
476 return -ENODEV; 554 return -ENODEV;
477 } 555 }
478 556
479 /* Enable only if address is set (needed at least on the 557 /*
480 * Compaq Presario S4000NX) */ 558 * Enable only if address is set (needed at least on the
559 * Compaq Presario S4000NX)
560 */
481 sio_data->activate = superio_inb(SUPERIO_REG_ACT); 561 sio_data->activate = superio_inb(SUPERIO_REG_ACT);
482 if ((sio_data->activate & 0x01) == 0) { 562 if ((sio_data->activate & 0x01) == 0) {
483 pr_info("Enabling device\n"); 563 pr_info("Enabling device\n");
@@ -583,6 +663,17 @@ static int smsc47m1_handle_resources(unsigned short address, enum chips type,
583 return 0; 663 return 0;
584} 664}
585 665
666static void smsc47m1_remove_files(struct device *dev)
667{
668 sysfs_remove_group(&dev->kobj, &smsc47m1_group);
669 sysfs_remove_group(&dev->kobj, &smsc47m1_group_fan1);
670 sysfs_remove_group(&dev->kobj, &smsc47m1_group_fan2);
671 sysfs_remove_group(&dev->kobj, &smsc47m1_group_fan3);
672 sysfs_remove_group(&dev->kobj, &smsc47m1_group_pwm1);
673 sysfs_remove_group(&dev->kobj, &smsc47m1_group_pwm2);
674 sysfs_remove_group(&dev->kobj, &smsc47m1_group_pwm3);
675}
676
586static int __init smsc47m1_probe(struct platform_device *pdev) 677static int __init smsc47m1_probe(struct platform_device *pdev)
587{ 678{
588 struct device *dev = &pdev->dev; 679 struct device *dev = &pdev->dev;
@@ -592,7 +683,7 @@ static int __init smsc47m1_probe(struct platform_device *pdev)
592 int err; 683 int err;
593 int fan1, fan2, fan3, pwm1, pwm2, pwm3; 684 int fan1, fan2, fan3, pwm1, pwm2, pwm3;
594 685
595 static const char *names[] = { 686 static const char * const names[] = {
596 "smsc47m1", 687 "smsc47m1",
597 "smsc47m2", 688 "smsc47m2",
598 }; 689 };
@@ -603,7 +694,8 @@ static int __init smsc47m1_probe(struct platform_device *pdev)
603 if (err < 0) 694 if (err < 0)
604 return err; 695 return err;
605 696
606 if (!(data = kzalloc(sizeof(struct smsc47m1_data), GFP_KERNEL))) { 697 data = kzalloc(sizeof(struct smsc47m1_data), GFP_KERNEL);
698 if (!data) {
607 err = -ENOMEM; 699 err = -ENOMEM;
608 goto error_release; 700 goto error_release;
609 } 701 }
@@ -614,8 +706,10 @@ static int __init smsc47m1_probe(struct platform_device *pdev)
614 mutex_init(&data->update_lock); 706 mutex_init(&data->update_lock);
615 platform_set_drvdata(pdev, data); 707 platform_set_drvdata(pdev, data);
616 708
617 /* If no function is properly configured, there's no point in 709 /*
618 actually registering the chip. */ 710 * If no function is properly configured, there's no point in
711 * actually registering the chip.
712 */
619 pwm1 = (smsc47m1_read_value(data, SMSC47M1_REG_PPIN(0)) & 0x05) 713 pwm1 = (smsc47m1_read_value(data, SMSC47M1_REG_PPIN(0)) & 0x05)
620 == 0x04; 714 == 0x04;
621 pwm2 = (smsc47m1_read_value(data, SMSC47M1_REG_PPIN(1)) & 0x05) 715 pwm2 = (smsc47m1_read_value(data, SMSC47M1_REG_PPIN(1)) & 0x05)
@@ -643,84 +737,67 @@ static int __init smsc47m1_probe(struct platform_device *pdev)
643 goto error_free; 737 goto error_free;
644 } 738 }
645 739
646 /* Some values (fan min, clock dividers, pwm registers) may be 740 /*
647 needed before any update is triggered, so we better read them 741 * Some values (fan min, clock dividers, pwm registers) may be
648 at least once here. We don't usually do it that way, but in 742 * needed before any update is triggered, so we better read them
649 this particular case, manually reading 5 registers out of 8 743 * at least once here. We don't usually do it that way, but in
650 doesn't make much sense and we're better using the existing 744 * this particular case, manually reading 5 registers out of 8
651 function. */ 745 * doesn't make much sense and we're better using the existing
746 * function.
747 */
652 smsc47m1_update_device(dev, 1); 748 smsc47m1_update_device(dev, 1);
653 749
654 /* Register sysfs hooks */ 750 /* Register sysfs hooks */
655 if (fan1) { 751 if (fan1) {
656 if ((err = device_create_file(dev, 752 err = sysfs_create_group(&dev->kobj,
657 &sensor_dev_attr_fan1_input.dev_attr)) 753 &smsc47m1_group_fan1);
658 || (err = device_create_file(dev, 754 if (err)
659 &sensor_dev_attr_fan1_min.dev_attr))
660 || (err = device_create_file(dev,
661 &sensor_dev_attr_fan1_div.dev_attr))
662 || (err = device_create_file(dev,
663 &sensor_dev_attr_fan1_alarm.dev_attr)))
664 goto error_remove_files; 755 goto error_remove_files;
665 } else 756 } else
666 dev_dbg(dev, "Fan 1 not enabled by hardware, skipping\n"); 757 dev_dbg(dev, "Fan 1 not enabled by hardware, skipping\n");
667 758
668 if (fan2) { 759 if (fan2) {
669 if ((err = device_create_file(dev, 760 err = sysfs_create_group(&dev->kobj,
670 &sensor_dev_attr_fan2_input.dev_attr)) 761 &smsc47m1_group_fan2);
671 || (err = device_create_file(dev, 762 if (err)
672 &sensor_dev_attr_fan2_min.dev_attr))
673 || (err = device_create_file(dev,
674 &sensor_dev_attr_fan2_div.dev_attr))
675 || (err = device_create_file(dev,
676 &sensor_dev_attr_fan2_alarm.dev_attr)))
677 goto error_remove_files; 763 goto error_remove_files;
678 } else 764 } else
679 dev_dbg(dev, "Fan 2 not enabled by hardware, skipping\n"); 765 dev_dbg(dev, "Fan 2 not enabled by hardware, skipping\n");
680 766
681 if (fan3) { 767 if (fan3) {
682 if ((err = device_create_file(dev, 768 err = sysfs_create_group(&dev->kobj,
683 &sensor_dev_attr_fan3_input.dev_attr)) 769 &smsc47m1_group_fan3);
684 || (err = device_create_file(dev, 770 if (err)
685 &sensor_dev_attr_fan3_min.dev_attr))
686 || (err = device_create_file(dev,
687 &sensor_dev_attr_fan3_div.dev_attr))
688 || (err = device_create_file(dev,
689 &sensor_dev_attr_fan3_alarm.dev_attr)))
690 goto error_remove_files; 771 goto error_remove_files;
691 } else if (data->type == smsc47m2) 772 } else if (data->type == smsc47m2)
692 dev_dbg(dev, "Fan 3 not enabled by hardware, skipping\n"); 773 dev_dbg(dev, "Fan 3 not enabled by hardware, skipping\n");
693 774
694 if (pwm1) { 775 if (pwm1) {
695 if ((err = device_create_file(dev, 776 err = sysfs_create_group(&dev->kobj,
696 &sensor_dev_attr_pwm1.dev_attr)) 777 &smsc47m1_group_pwm1);
697 || (err = device_create_file(dev, 778 if (err)
698 &sensor_dev_attr_pwm1_enable.dev_attr)))
699 goto error_remove_files; 779 goto error_remove_files;
700 } else 780 } else
701 dev_dbg(dev, "PWM 1 not enabled by hardware, skipping\n"); 781 dev_dbg(dev, "PWM 1 not enabled by hardware, skipping\n");
702 782
703 if (pwm2) { 783 if (pwm2) {
704 if ((err = device_create_file(dev, 784 err = sysfs_create_group(&dev->kobj,
705 &sensor_dev_attr_pwm2.dev_attr)) 785 &smsc47m1_group_pwm2);
706 || (err = device_create_file(dev, 786 if (err)
707 &sensor_dev_attr_pwm2_enable.dev_attr)))
708 goto error_remove_files; 787 goto error_remove_files;
709 } else 788 } else
710 dev_dbg(dev, "PWM 2 not enabled by hardware, skipping\n"); 789 dev_dbg(dev, "PWM 2 not enabled by hardware, skipping\n");
711 790
712 if (pwm3) { 791 if (pwm3) {
713 if ((err = device_create_file(dev, 792 err = sysfs_create_group(&dev->kobj,
714 &sensor_dev_attr_pwm3.dev_attr)) 793 &smsc47m1_group_pwm3);
715 || (err = device_create_file(dev, 794 if (err)
716 &sensor_dev_attr_pwm3_enable.dev_attr)))
717 goto error_remove_files; 795 goto error_remove_files;
718 } else if (data->type == smsc47m2) 796 } else if (data->type == smsc47m2)
719 dev_dbg(dev, "PWM 3 not enabled by hardware, skipping\n"); 797 dev_dbg(dev, "PWM 3 not enabled by hardware, skipping\n");
720 798
721 if ((err = device_create_file(dev, &dev_attr_alarms))) 799 err = sysfs_create_group(&dev->kobj, &smsc47m1_group);
722 goto error_remove_files; 800 if (err)
723 if ((err = device_create_file(dev, &dev_attr_name)))
724 goto error_remove_files; 801 goto error_remove_files;
725 802
726 data->hwmon_dev = hwmon_device_register(dev); 803 data->hwmon_dev = hwmon_device_register(dev);
@@ -732,7 +809,7 @@ static int __init smsc47m1_probe(struct platform_device *pdev)
732 return 0; 809 return 0;
733 810
734error_remove_files: 811error_remove_files:
735 sysfs_remove_group(&dev->kobj, &smsc47m1_group); 812 smsc47m1_remove_files(dev);
736error_free: 813error_free:
737 platform_set_drvdata(pdev, NULL); 814 platform_set_drvdata(pdev, NULL);
738 kfree(data); 815 kfree(data);
@@ -747,7 +824,7 @@ static int __exit smsc47m1_remove(struct platform_device *pdev)
747 struct resource *res; 824 struct resource *res;
748 825
749 hwmon_device_unregister(data->hwmon_dev); 826 hwmon_device_unregister(data->hwmon_dev);
750 sysfs_remove_group(&pdev->dev.kobj, &smsc47m1_group); 827 smsc47m1_remove_files(&pdev->dev);
751 828
752 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 829 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
753 smsc47m1_handle_resources(res->start, data->type, RELEASE, &pdev->dev); 830 smsc47m1_handle_resources(res->start, data->type, RELEASE, &pdev->dev);
diff --git a/drivers/hwmon/smsc47m192.c b/drivers/hwmon/smsc47m192.c
index 40b26673d87f..4705a8bf11c2 100644
--- a/drivers/hwmon/smsc47m192.c
+++ b/drivers/hwmon/smsc47m192.c
@@ -1,25 +1,25 @@
1/* 1/*
2 smsc47m192.c - Support for hardware monitoring block of 2 * smsc47m192.c - Support for hardware monitoring block of
3 SMSC LPC47M192 and compatible Super I/O chips 3 * SMSC LPC47M192 and compatible Super I/O chips
4 4 *
5 Copyright (C) 2006 Hartmut Rick <linux@rick.claranet.de> 5 * Copyright (C) 2006 Hartmut Rick <linux@rick.claranet.de>
6 6 *
7 Derived from lm78.c and other chip drivers. 7 * Derived from lm78.c and other chip drivers.
8 8 *
9 This program is free software; you can redistribute it and/or modify 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 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 11 * the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version. 12 * (at your option) any later version.
13 13 *
14 This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details. 17 * GNU General Public License for more details.
18 18 *
19 You should have received a copy of the GNU General Public License 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 20 * along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22*/ 22 */
23 23
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/init.h> 25#include <linux/init.h>
@@ -37,16 +37,16 @@
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/* SMSC47M192 registers */ 39/* SMSC47M192 registers */
40#define SMSC47M192_REG_IN(nr) ((nr)<6 ? (0x20 + (nr)) : \ 40#define SMSC47M192_REG_IN(nr) ((nr) < 6 ? (0x20 + (nr)) : \
41 (0x50 + (nr) - 6)) 41 (0x50 + (nr) - 6))
42#define SMSC47M192_REG_IN_MAX(nr) ((nr)<6 ? (0x2b + (nr) * 2) : \ 42#define SMSC47M192_REG_IN_MAX(nr) ((nr) < 6 ? (0x2b + (nr) * 2) : \
43 (0x54 + (((nr) - 6) * 2))) 43 (0x54 + (((nr) - 6) * 2)))
44#define SMSC47M192_REG_IN_MIN(nr) ((nr)<6 ? (0x2c + (nr) * 2) : \ 44#define SMSC47M192_REG_IN_MIN(nr) ((nr) < 6 ? (0x2c + (nr) * 2) : \
45 (0x55 + (((nr) - 6) * 2))) 45 (0x55 + (((nr) - 6) * 2)))
46static u8 SMSC47M192_REG_TEMP[3] = { 0x27, 0x26, 0x52 }; 46static u8 SMSC47M192_REG_TEMP[3] = { 0x27, 0x26, 0x52 };
47static u8 SMSC47M192_REG_TEMP_MAX[3] = { 0x39, 0x37, 0x58 }; 47static u8 SMSC47M192_REG_TEMP_MAX[3] = { 0x39, 0x37, 0x58 };
48static u8 SMSC47M192_REG_TEMP_MIN[3] = { 0x3A, 0x38, 0x59 }; 48static u8 SMSC47M192_REG_TEMP_MIN[3] = { 0x3A, 0x38, 0x59 };
49#define SMSC47M192_REG_TEMP_OFFSET(nr) ((nr)==2 ? 0x1e : 0x1f) 49#define SMSC47M192_REG_TEMP_OFFSET(nr) ((nr) == 2 ? 0x1e : 0x1f)
50#define SMSC47M192_REG_ALARM1 0x41 50#define SMSC47M192_REG_ALARM1 0x41
51#define SMSC47M192_REG_ALARM2 0x42 51#define SMSC47M192_REG_ALARM2 0x42
52#define SMSC47M192_REG_VID 0x47 52#define SMSC47M192_REG_VID 0x47
@@ -80,8 +80,10 @@ static inline u8 IN_TO_REG(unsigned long val, int n)
80 return SENSORS_LIMIT(SCALE(val, 192, nom_mv[n]), 0, 255); 80 return SENSORS_LIMIT(SCALE(val, 192, nom_mv[n]), 0, 255);
81} 81}
82 82
83/* TEMP: 0.001 degC units (-128C to +127C) 83/*
84 REG: 1C/bit, two's complement */ 84 * TEMP: 0.001 degC units (-128C to +127C)
85 * REG: 1C/bit, two's complement
86 */
85static inline s8 TEMP_TO_REG(int val) 87static inline s8 TEMP_TO_REG(int val)
86{ 88{
87 return SENSORS_LIMIT(SCALE(val, 1, 1000), -128000, 127000); 89 return SENSORS_LIMIT(SCALE(val, 1, 1000), -128000, 127000);
@@ -170,7 +172,12 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
170 int nr = sensor_attr->index; 172 int nr = sensor_attr->index;
171 struct i2c_client *client = to_i2c_client(dev); 173 struct i2c_client *client = to_i2c_client(dev);
172 struct smsc47m192_data *data = i2c_get_clientdata(client); 174 struct smsc47m192_data *data = i2c_get_clientdata(client);
173 unsigned long val = simple_strtoul(buf, NULL, 10); 175 unsigned long val;
176 int err;
177
178 err = kstrtoul(buf, 10, &val);
179 if (err)
180 return err;
174 181
175 mutex_lock(&data->update_lock); 182 mutex_lock(&data->update_lock);
176 data->in_min[nr] = IN_TO_REG(val, nr); 183 data->in_min[nr] = IN_TO_REG(val, nr);
@@ -187,7 +194,12 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
187 int nr = sensor_attr->index; 194 int nr = sensor_attr->index;
188 struct i2c_client *client = to_i2c_client(dev); 195 struct i2c_client *client = to_i2c_client(dev);
189 struct smsc47m192_data *data = i2c_get_clientdata(client); 196 struct smsc47m192_data *data = i2c_get_clientdata(client);
190 unsigned long val = simple_strtoul(buf, NULL, 10); 197 unsigned long val;
198 int err;
199
200 err = kstrtoul(buf, 10, &val);
201 if (err)
202 return err;
191 203
192 mutex_lock(&data->update_lock); 204 mutex_lock(&data->update_lock);
193 data->in_max[nr] = IN_TO_REG(val, nr); 205 data->in_max[nr] = IN_TO_REG(val, nr);
@@ -249,7 +261,12 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
249 int nr = sensor_attr->index; 261 int nr = sensor_attr->index;
250 struct i2c_client *client = to_i2c_client(dev); 262 struct i2c_client *client = to_i2c_client(dev);
251 struct smsc47m192_data *data = i2c_get_clientdata(client); 263 struct smsc47m192_data *data = i2c_get_clientdata(client);
252 long val = simple_strtol(buf, NULL, 10); 264 long val;
265 int err;
266
267 err = kstrtol(buf, 10, &val);
268 if (err)
269 return err;
253 270
254 mutex_lock(&data->update_lock); 271 mutex_lock(&data->update_lock);
255 data->temp_min[nr] = TEMP_TO_REG(val); 272 data->temp_min[nr] = TEMP_TO_REG(val);
@@ -266,7 +283,12 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
266 int nr = sensor_attr->index; 283 int nr = sensor_attr->index;
267 struct i2c_client *client = to_i2c_client(dev); 284 struct i2c_client *client = to_i2c_client(dev);
268 struct smsc47m192_data *data = i2c_get_clientdata(client); 285 struct smsc47m192_data *data = i2c_get_clientdata(client);
269 long val = simple_strtol(buf, NULL, 10); 286 long val;
287 int err;
288
289 err = kstrtol(buf, 10, &val);
290 if (err)
291 return err;
270 292
271 mutex_lock(&data->update_lock); 293 mutex_lock(&data->update_lock);
272 data->temp_max[nr] = TEMP_TO_REG(val); 294 data->temp_max[nr] = TEMP_TO_REG(val);
@@ -293,22 +315,29 @@ static ssize_t set_temp_offset(struct device *dev, struct device_attribute
293 struct i2c_client *client = to_i2c_client(dev); 315 struct i2c_client *client = to_i2c_client(dev);
294 struct smsc47m192_data *data = i2c_get_clientdata(client); 316 struct smsc47m192_data *data = i2c_get_clientdata(client);
295 u8 sfr = i2c_smbus_read_byte_data(client, SMSC47M192_REG_SFR); 317 u8 sfr = i2c_smbus_read_byte_data(client, SMSC47M192_REG_SFR);
296 long val = simple_strtol(buf, NULL, 10); 318 long val;
319 int err;
320
321 err = kstrtol(buf, 10, &val);
322 if (err)
323 return err;
297 324
298 mutex_lock(&data->update_lock); 325 mutex_lock(&data->update_lock);
299 data->temp_offset[nr] = TEMP_TO_REG(val); 326 data->temp_offset[nr] = TEMP_TO_REG(val);
300 if (nr>1) 327 if (nr > 1)
301 i2c_smbus_write_byte_data(client, 328 i2c_smbus_write_byte_data(client,
302 SMSC47M192_REG_TEMP_OFFSET(nr), data->temp_offset[nr]); 329 SMSC47M192_REG_TEMP_OFFSET(nr), data->temp_offset[nr]);
303 else if (data->temp_offset[nr] != 0) { 330 else if (data->temp_offset[nr] != 0) {
304 /* offset[0] and offset[1] share the same register, 331 /*
305 SFR bit 4 activates offset[0] */ 332 * offset[0] and offset[1] share the same register,
333 * SFR bit 4 activates offset[0]
334 */
306 i2c_smbus_write_byte_data(client, SMSC47M192_REG_SFR, 335 i2c_smbus_write_byte_data(client, SMSC47M192_REG_SFR,
307 (sfr & 0xef) | (nr==0 ? 0x10 : 0)); 336 (sfr & 0xef) | (nr == 0 ? 0x10 : 0));
308 data->temp_offset[1-nr] = 0; 337 data->temp_offset[1-nr] = 0;
309 i2c_smbus_write_byte_data(client, 338 i2c_smbus_write_byte_data(client,
310 SMSC47M192_REG_TEMP_OFFSET(nr), data->temp_offset[nr]); 339 SMSC47M192_REG_TEMP_OFFSET(nr), data->temp_offset[nr]);
311 } else if ((sfr & 0x10) == (nr==0 ? 0x10 : 0)) 340 } else if ((sfr & 0x10) == (nr == 0 ? 0x10 : 0))
312 i2c_smbus_write_byte_data(client, 341 i2c_smbus_write_byte_data(client,
313 SMSC47M192_REG_TEMP_OFFSET(nr), 0); 342 SMSC47M192_REG_TEMP_OFFSET(nr), 0);
314 mutex_unlock(&data->update_lock); 343 mutex_unlock(&data->update_lock);
@@ -349,7 +378,14 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
349 const char *buf, size_t count) 378 const char *buf, size_t count)
350{ 379{
351 struct smsc47m192_data *data = dev_get_drvdata(dev); 380 struct smsc47m192_data *data = dev_get_drvdata(dev);
352 data->vrm = simple_strtoul(buf, NULL, 10); 381 unsigned long val;
382 int err;
383
384 err = kstrtoul(buf, 10, &val);
385 if (err)
386 return err;
387
388 data->vrm = val;
353 return count; 389 return count;
354} 390}
355static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); 391static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
@@ -458,13 +494,13 @@ static void smsc47m192_init_client(struct i2c_client *client)
458 (sfr & 0xfd) | 0x02); 494 (sfr & 0xfd) | 0x02);
459 if (!(config & 0x01)) { 495 if (!(config & 0x01)) {
460 /* initialize alarm limits */ 496 /* initialize alarm limits */
461 for (i=0; i<8; i++) { 497 for (i = 0; i < 8; i++) {
462 i2c_smbus_write_byte_data(client, 498 i2c_smbus_write_byte_data(client,
463 SMSC47M192_REG_IN_MIN(i), 0); 499 SMSC47M192_REG_IN_MIN(i), 0);
464 i2c_smbus_write_byte_data(client, 500 i2c_smbus_write_byte_data(client,
465 SMSC47M192_REG_IN_MAX(i), 0xff); 501 SMSC47M192_REG_IN_MAX(i), 0xff);
466 } 502 }
467 for (i=0; i<3; i++) { 503 for (i = 0; i < 3; i++) {
468 i2c_smbus_write_byte_data(client, 504 i2c_smbus_write_byte_data(client,
469 SMSC47M192_REG_TEMP_MIN[i], 0x80); 505 SMSC47M192_REG_TEMP_MIN[i], 0x80);
470 i2c_smbus_write_byte_data(client, 506 i2c_smbus_write_byte_data(client,
@@ -532,14 +568,16 @@ static int smsc47m192_probe(struct i2c_client *client,
532 smsc47m192_init_client(client); 568 smsc47m192_init_client(client);
533 569
534 /* Register sysfs hooks */ 570 /* Register sysfs hooks */
535 if ((err = sysfs_create_group(&client->dev.kobj, &smsc47m192_group))) 571 err = sysfs_create_group(&client->dev.kobj, &smsc47m192_group);
572 if (err)
536 goto exit_free; 573 goto exit_free;
537 574
538 /* Pin 110 is either in4 (+12V) or VID4 */ 575 /* Pin 110 is either in4 (+12V) or VID4 */
539 config = i2c_smbus_read_byte_data(client, SMSC47M192_REG_CONFIG); 576 config = i2c_smbus_read_byte_data(client, SMSC47M192_REG_CONFIG);
540 if (!(config & 0x20)) { 577 if (!(config & 0x20)) {
541 if ((err = sysfs_create_group(&client->dev.kobj, 578 err = sysfs_create_group(&client->dev.kobj,
542 &smsc47m192_group_in4))) 579 &smsc47m192_group_in4);
580 if (err)
543 goto exit_remove_files; 581 goto exit_remove_files;
544 } 582 }
545 583
@@ -606,8 +644,10 @@ static struct smsc47m192_data *smsc47m192_update_device(struct device *dev)
606 for (i = 1; i < 3; i++) 644 for (i = 1; i < 3; i++)
607 data->temp_offset[i] = i2c_smbus_read_byte_data(client, 645 data->temp_offset[i] = i2c_smbus_read_byte_data(client,
608 SMSC47M192_REG_TEMP_OFFSET(i)); 646 SMSC47M192_REG_TEMP_OFFSET(i));
609 /* first offset is temp_offset[0] if SFR bit 4 is set, 647 /*
610 temp_offset[1] otherwise */ 648 * first offset is temp_offset[0] if SFR bit 4 is set,
649 * temp_offset[1] otherwise
650 */
611 if (sfr & 0x10) { 651 if (sfr & 0x10) {
612 data->temp_offset[0] = data->temp_offset[1]; 652 data->temp_offset[0] = data->temp_offset[1];
613 data->temp_offset[1] = 0; 653 data->temp_offset[1] = 0;
@@ -624,7 +664,7 @@ static struct smsc47m192_data *smsc47m192_update_device(struct device *dev)
624 data->alarms = i2c_smbus_read_byte_data(client, 664 data->alarms = i2c_smbus_read_byte_data(client,
625 SMSC47M192_REG_ALARM1) | 665 SMSC47M192_REG_ALARM1) |
626 (i2c_smbus_read_byte_data(client, 666 (i2c_smbus_read_byte_data(client,
627 SMSC47M192_REG_ALARM2) << 8); 667 SMSC47M192_REG_ALARM2) << 8);
628 668
629 data->last_updated = jiffies; 669 data->last_updated = jiffies;
630 data->valid = 1; 670 data->valid = 1;
@@ -635,19 +675,8 @@ static struct smsc47m192_data *smsc47m192_update_device(struct device *dev)
635 return data; 675 return data;
636} 676}
637 677
638static int __init smsc47m192_init(void) 678module_i2c_driver(smsc47m192_driver);
639{
640 return i2c_add_driver(&smsc47m192_driver);
641}
642
643static void __exit smsc47m192_exit(void)
644{
645 i2c_del_driver(&smsc47m192_driver);
646}
647 679
648MODULE_AUTHOR("Hartmut Rick <linux@rick.claranet.de>"); 680MODULE_AUTHOR("Hartmut Rick <linux@rick.claranet.de>");
649MODULE_DESCRIPTION("SMSC47M192 driver"); 681MODULE_DESCRIPTION("SMSC47M192 driver");
650MODULE_LICENSE("GPL"); 682MODULE_LICENSE("GPL");
651
652module_init(smsc47m192_init);
653module_exit(smsc47m192_exit);
diff --git a/drivers/hwmon/thmc50.c b/drivers/hwmon/thmc50.c
index 7dfb4dec4c5f..add9f019b24f 100644
--- a/drivers/hwmon/thmc50.c
+++ b/drivers/hwmon/thmc50.c
@@ -1,24 +1,24 @@
1/* 1/*
2 thmc50.c - Part of lm_sensors, Linux kernel modules for hardware 2 * thmc50.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 * monitoring
4 Copyright (C) 2007 Krzysztof Helt <krzysztof.h1@wp.pl> 4 * Copyright (C) 2007 Krzysztof Helt <krzysztof.h1@wp.pl>
5 Based on 2.4 driver by Frodo Looijaard <frodol@dds.nl> and 5 * Based on 2.4 driver by Frodo Looijaard <frodol@dds.nl> and
6 Philip Edelbrock <phil@netroedge.com> 6 * Philip Edelbrock <phil@netroedge.com>
7 7 *
8 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 * (at your option) any later version.
12 12 *
13 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 * GNU General Public License for more details.
17 17 *
18 You should have received a copy of the GNU General Public License 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 19 * along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21*/ 21 */
22 22
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/init.h> 24#include <linux/init.h>
@@ -124,8 +124,13 @@ static ssize_t set_analog_out(struct device *dev,
124{ 124{
125 struct i2c_client *client = to_i2c_client(dev); 125 struct i2c_client *client = to_i2c_client(dev);
126 struct thmc50_data *data = i2c_get_clientdata(client); 126 struct thmc50_data *data = i2c_get_clientdata(client);
127 int tmp = simple_strtoul(buf, NULL, 10);
128 int config; 127 int config;
128 unsigned long tmp;
129 int err;
130
131 err = kstrtoul(buf, 10, &tmp);
132 if (err)
133 return err;
129 134
130 mutex_lock(&data->update_lock); 135 mutex_lock(&data->update_lock);
131 data->analog_out = SENSORS_LIMIT(tmp, 0, 255); 136 data->analog_out = SENSORS_LIMIT(tmp, 0, 255);
@@ -173,7 +178,12 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
173 int nr = to_sensor_dev_attr(attr)->index; 178 int nr = to_sensor_dev_attr(attr)->index;
174 struct i2c_client *client = to_i2c_client(dev); 179 struct i2c_client *client = to_i2c_client(dev);
175 struct thmc50_data *data = i2c_get_clientdata(client); 180 struct thmc50_data *data = i2c_get_clientdata(client);
176 int val = simple_strtol(buf, NULL, 10); 181 long val;
182 int err;
183
184 err = kstrtol(buf, 10, &val);
185 if (err)
186 return err;
177 187
178 mutex_lock(&data->update_lock); 188 mutex_lock(&data->update_lock);
179 data->temp_min[nr] = SENSORS_LIMIT(val / 1000, -128, 127); 189 data->temp_min[nr] = SENSORS_LIMIT(val / 1000, -128, 127);
@@ -197,7 +207,12 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
197 int nr = to_sensor_dev_attr(attr)->index; 207 int nr = to_sensor_dev_attr(attr)->index;
198 struct i2c_client *client = to_i2c_client(dev); 208 struct i2c_client *client = to_i2c_client(dev);
199 struct thmc50_data *data = i2c_get_clientdata(client); 209 struct thmc50_data *data = i2c_get_clientdata(client);
200 int val = simple_strtol(buf, NULL, 10); 210 long val;
211 int err;
212
213 err = kstrtol(buf, 10, &val);
214 if (err)
215 return err;
201 216
202 mutex_lock(&data->update_lock); 217 mutex_lock(&data->update_lock);
203 data->temp_max[nr] = SENSORS_LIMIT(val / 1000, -128, 127); 218 data->temp_max[nr] = SENSORS_LIMIT(val / 1000, -128, 127);
@@ -360,14 +375,16 @@ static int thmc50_probe(struct i2c_client *client,
360 thmc50_init_client(client); 375 thmc50_init_client(client);
361 376
362 /* Register sysfs hooks */ 377 /* Register sysfs hooks */
363 if ((err = sysfs_create_group(&client->dev.kobj, &thmc50_group))) 378 err = sysfs_create_group(&client->dev.kobj, &thmc50_group);
379 if (err)
364 goto exit_free; 380 goto exit_free;
365 381
366 /* Register ADM1022 sysfs hooks */ 382 /* Register ADM1022 sysfs hooks */
367 if (data->has_temp3) 383 if (data->has_temp3) {
368 if ((err = sysfs_create_group(&client->dev.kobj, 384 err = sysfs_create_group(&client->dev.kobj, &temp3_group);
369 &temp3_group))) 385 if (err)
370 goto exit_remove_sysfs_thmc50; 386 goto exit_remove_sysfs_thmc50;
387 }
371 388
372 /* Register a new directory entry with module sensors */ 389 /* Register a new directory entry with module sensors */
373 data->hwmon_dev = hwmon_device_register(&client->dev); 390 data->hwmon_dev = hwmon_device_register(&client->dev);
@@ -465,18 +482,7 @@ static struct thmc50_data *thmc50_update_device(struct device *dev)
465 return data; 482 return data;
466} 483}
467 484
468static int __init sm_thmc50_init(void) 485module_i2c_driver(thmc50_driver);
469{
470 return i2c_add_driver(&thmc50_driver);
471}
472
473static void __exit sm_thmc50_exit(void)
474{
475 i2c_del_driver(&thmc50_driver);
476}
477 486
478MODULE_AUTHOR("Krzysztof Helt <krzysztof.h1@wp.pl>"); 487MODULE_AUTHOR("Krzysztof Helt <krzysztof.h1@wp.pl>");
479MODULE_DESCRIPTION("THMC50 driver"); 488MODULE_DESCRIPTION("THMC50 driver");
480
481module_init(sm_thmc50_init);
482module_exit(sm_thmc50_exit);
diff --git a/drivers/hwmon/tmp102.c b/drivers/hwmon/tmp102.c
index c08eee21d76e..0d466b9d8908 100644
--- a/drivers/hwmon/tmp102.c
+++ b/drivers/hwmon/tmp102.c
@@ -292,17 +292,7 @@ static struct i2c_driver tmp102_driver = {
292 .id_table = tmp102_id, 292 .id_table = tmp102_id,
293}; 293};
294 294
295static int __init tmp102_init(void) 295module_i2c_driver(tmp102_driver);
296{
297 return i2c_add_driver(&tmp102_driver);
298}
299module_init(tmp102_init);
300
301static void __exit tmp102_exit(void)
302{
303 i2c_del_driver(&tmp102_driver);
304}
305module_exit(tmp102_exit);
306 296
307MODULE_AUTHOR("Steven King <sfking@fdwdc.com>"); 297MODULE_AUTHOR("Steven King <sfking@fdwdc.com>");
308MODULE_DESCRIPTION("Texas Instruments TMP102 temperature sensor driver"); 298MODULE_DESCRIPTION("Texas Instruments TMP102 temperature sensor driver");
diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c
index 951442adc067..ea54c3384671 100644
--- a/drivers/hwmon/tmp401.c
+++ b/drivers/hwmon/tmp401.c
@@ -662,19 +662,8 @@ static struct i2c_driver tmp401_driver = {
662 .address_list = normal_i2c, 662 .address_list = normal_i2c,
663}; 663};
664 664
665static int __init tmp401_init(void) 665module_i2c_driver(tmp401_driver);
666{
667 return i2c_add_driver(&tmp401_driver);
668}
669
670static void __exit tmp401_exit(void)
671{
672 i2c_del_driver(&tmp401_driver);
673}
674 666
675MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>"); 667MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
676MODULE_DESCRIPTION("Texas Instruments TMP401 temperature sensor driver"); 668MODULE_DESCRIPTION("Texas Instruments TMP401 temperature sensor driver");
677MODULE_LICENSE("GPL"); 669MODULE_LICENSE("GPL");
678
679module_init(tmp401_init);
680module_exit(tmp401_exit);
diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c
index c48381f2cd02..8fac87a38544 100644
--- a/drivers/hwmon/tmp421.c
+++ b/drivers/hwmon/tmp421.c
@@ -324,20 +324,9 @@ static struct i2c_driver tmp421_driver = {
324 .address_list = normal_i2c, 324 .address_list = normal_i2c,
325}; 325};
326 326
327static int __init tmp421_init(void) 327module_i2c_driver(tmp421_driver);
328{
329 return i2c_add_driver(&tmp421_driver);
330}
331
332static void __exit tmp421_exit(void)
333{
334 i2c_del_driver(&tmp421_driver);
335}
336 328
337MODULE_AUTHOR("Andre Prendel <andre.prendel@gmx.de>"); 329MODULE_AUTHOR("Andre Prendel <andre.prendel@gmx.de>");
338MODULE_DESCRIPTION("Texas Instruments TMP421/422/423 temperature sensor" 330MODULE_DESCRIPTION("Texas Instruments TMP421/422/423 temperature sensor"
339 " driver"); 331 " driver");
340MODULE_LICENSE("GPL"); 332MODULE_LICENSE("GPL");
341
342module_init(tmp421_init);
343module_exit(tmp421_exit);
diff --git a/drivers/hwmon/ultra45_env.c b/drivers/hwmon/ultra45_env.c
index b9a87e89bab4..c315c59f61fe 100644
--- a/drivers/hwmon/ultra45_env.c
+++ b/drivers/hwmon/ultra45_env.c
@@ -1,4 +1,5 @@
1/* ultra45_env.c: Driver for Ultra45 PIC16F747 environmental monitor. 1/*
2 * ultra45_env.c: Driver for Ultra45 PIC16F747 environmental monitor.
2 * 3 *
3 * Copyright (C) 2008 David S. Miller <davem@davemloft.net> 4 * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
4 */ 5 */
@@ -82,7 +83,8 @@ static void env_write(struct env *p, u8 ireg, u8 val)
82 spin_unlock(&p->lock); 83 spin_unlock(&p->lock);
83} 84}
84 85
85/* There seems to be a adr7462 providing these values, thus a lot 86/*
87 * There seems to be a adr7462 providing these values, thus a lot
86 * of these calculations are borrowed from the adt7470 driver. 88 * of these calculations are borrowed from the adt7470 driver.
87 */ 89 */
88#define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x)) 90#define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x))
@@ -90,7 +92,8 @@ static void env_write(struct env *p, u8 ireg, u8 val)
90#define FAN_PERIOD_INVALID (0xff << 8) 92#define FAN_PERIOD_INVALID (0xff << 8)
91#define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) 93#define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID)
92 94
93static ssize_t show_fan_speed(struct device *dev, struct device_attribute *attr, char *buf) 95static ssize_t show_fan_speed(struct device *dev, struct device_attribute *attr,
96 char *buf)
94{ 97{
95 int fan_nr = to_sensor_dev_attr(attr)->index; 98 int fan_nr = to_sensor_dev_attr(attr)->index;
96 struct env *p = dev_get_drvdata(dev); 99 struct env *p = dev_get_drvdata(dev);
@@ -111,10 +114,15 @@ static ssize_t set_fan_speed(struct device *dev, struct device_attribute *attr,
111 const char *buf, size_t count) 114 const char *buf, size_t count)
112{ 115{
113 int fan_nr = to_sensor_dev_attr(attr)->index; 116 int fan_nr = to_sensor_dev_attr(attr)->index;
114 int rpm = simple_strtol(buf, NULL, 10); 117 unsigned long rpm;
115 struct env *p = dev_get_drvdata(dev); 118 struct env *p = dev_get_drvdata(dev);
116 int period; 119 int period;
117 u8 val; 120 u8 val;
121 int err;
122
123 err = kstrtoul(buf, 10, &rpm);
124 if (err)
125 return err;
118 126
119 if (!rpm) 127 if (!rpm)
120 return -EINVAL; 128 return -EINVAL;
@@ -126,7 +134,8 @@ static ssize_t set_fan_speed(struct device *dev, struct device_attribute *attr,
126 return count; 134 return count;
127} 135}
128 136
129static ssize_t show_fan_fault(struct device *dev, struct device_attribute *attr, char *buf) 137static ssize_t show_fan_fault(struct device *dev, struct device_attribute *attr,
138 char *buf)
130{ 139{
131 int fan_nr = to_sensor_dev_attr(attr)->index; 140 int fan_nr = to_sensor_dev_attr(attr)->index;
132 struct env *p = dev_get_drvdata(dev); 141 struct env *p = dev_get_drvdata(dev);
@@ -148,7 +157,8 @@ fan(4);
148 157
149static SENSOR_DEVICE_ATTR(psu_fan_fault, S_IRUGO, show_fan_fault, NULL, 6); 158static SENSOR_DEVICE_ATTR(psu_fan_fault, S_IRUGO, show_fan_fault, NULL, 6);
150 159
151static ssize_t show_temp(struct device *dev, struct device_attribute *attr, char *buf) 160static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
161 char *buf)
152{ 162{
153 int temp_nr = to_sensor_dev_attr(attr)->index; 163 int temp_nr = to_sensor_dev_attr(attr)->index;
154 struct env *p = dev_get_drvdata(dev); 164 struct env *p = dev_get_drvdata(dev);
@@ -168,7 +178,8 @@ static SENSOR_DEVICE_ATTR(lsi1064_local_temp, S_IRUGO, show_temp, NULL, 6);
168static SENSOR_DEVICE_ATTR(front_panel_temp, S_IRUGO, show_temp, NULL, 7); 178static SENSOR_DEVICE_ATTR(front_panel_temp, S_IRUGO, show_temp, NULL, 7);
169static SENSOR_DEVICE_ATTR(psu_temp, S_IRUGO, show_temp, NULL, 13); 179static SENSOR_DEVICE_ATTR(psu_temp, S_IRUGO, show_temp, NULL, 13);
170 180
171static ssize_t show_stat_bit(struct device *dev, struct device_attribute *attr, char *buf) 181static ssize_t show_stat_bit(struct device *dev, struct device_attribute *attr,
182 char *buf)
172{ 183{
173 int index = to_sensor_dev_attr(attr)->index; 184 int index = to_sensor_dev_attr(attr)->index;
174 struct env *p = dev_get_drvdata(dev); 185 struct env *p = dev_get_drvdata(dev);
@@ -181,9 +192,11 @@ static ssize_t show_stat_bit(struct device *dev, struct device_attribute *attr,
181static SENSOR_DEVICE_ATTR(fan_failure, S_IRUGO, show_stat_bit, NULL, 0); 192static SENSOR_DEVICE_ATTR(fan_failure, S_IRUGO, show_stat_bit, NULL, 0);
182static SENSOR_DEVICE_ATTR(env_bus_busy, S_IRUGO, show_stat_bit, NULL, 1); 193static SENSOR_DEVICE_ATTR(env_bus_busy, S_IRUGO, show_stat_bit, NULL, 1);
183static SENSOR_DEVICE_ATTR(env_data_stale, S_IRUGO, show_stat_bit, NULL, 2); 194static SENSOR_DEVICE_ATTR(env_data_stale, S_IRUGO, show_stat_bit, NULL, 2);
184static SENSOR_DEVICE_ATTR(tpm_self_test_passed, S_IRUGO, show_stat_bit, NULL, 3); 195static SENSOR_DEVICE_ATTR(tpm_self_test_passed, S_IRUGO, show_stat_bit, NULL,
196 3);
185 197
186static ssize_t show_fwver(struct device *dev, struct device_attribute *attr, char *buf) 198static ssize_t show_fwver(struct device *dev, struct device_attribute *attr,
199 char *buf)
187{ 200{
188 struct env *p = dev_get_drvdata(dev); 201 struct env *p = dev_get_drvdata(dev);
189 u8 val; 202 u8 val;
@@ -194,7 +207,8 @@ static ssize_t show_fwver(struct device *dev, struct device_attribute *attr, cha
194 207
195static SENSOR_DEVICE_ATTR(firmware_version, S_IRUGO, show_fwver, NULL, 0); 208static SENSOR_DEVICE_ATTR(firmware_version, S_IRUGO, show_fwver, NULL, 0);
196 209
197static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf) 210static ssize_t show_name(struct device *dev, struct device_attribute *attr,
211 char *buf)
198{ 212{
199 return sprintf(buf, "ultra45\n"); 213 return sprintf(buf, "ultra45\n");
200} 214}
diff --git a/drivers/hwmon/via686a.c b/drivers/hwmon/via686a.c
index 25e91665a0a2..288135d85e11 100644
--- a/drivers/hwmon/via686a.c
+++ b/drivers/hwmon/via686a.c
@@ -1,34 +1,35 @@
1/* 1/*
2 via686a.c - Part of lm_sensors, Linux kernel modules 2 * via686a.c - Part of lm_sensors, Linux kernel modules
3 for hardware monitoring 3 * for hardware monitoring
4 4 *
5 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>, 5 * Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>,
6 Kyösti Mälkki <kmalkki@cc.hut.fi>, 6 * Kyösti Mälkki <kmalkki@cc.hut.fi>,
7 Mark Studebaker <mdsxyz123@yahoo.com>, 7 * Mark Studebaker <mdsxyz123@yahoo.com>,
8 and Bob Dougherty <bobd@stanford.edu> 8 * and Bob Dougherty <bobd@stanford.edu>
9 (Some conversion-factor data were contributed by Jonathan Teh Soon Yew 9 *
10 <j.teh@iname.com> and Alex van Kaam <darkside@chello.nl>.) 10 * (Some conversion-factor data were contributed by Jonathan Teh Soon Yew
11 11 * <j.teh@iname.com> and Alex van Kaam <darkside@chello.nl>.)
12 This program is free software; you can redistribute it and/or modify 12 *
13 it under the terms of the GNU General Public License as published by 13 * This program is free software; you can redistribute it and/or modify
14 the Free Software Foundation; either version 2 of the License, or 14 * it under the terms of the GNU General Public License as published by
15 (at your option) any later version. 15 * the Free Software Foundation; either version 2 of the License, or
16 16 * (at your option) any later version.
17 This program is distributed in the hope that it will be useful, 17 *
18 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * This program is distributed in the hope that it will be useful,
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 GNU General Public License for more details. 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 21 * GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License 22 *
23 along with this program; if not, write to the Free Software 23 * You should have received a copy of the GNU General Public License
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 * along with this program; if not, write to the Free Software
25*/ 25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
26 27
27/* 28/*
28 Supports the Via VT82C686A, VT82C686B south bridges. 29 * Supports the Via VT82C686A, VT82C686B south bridges.
29 Reports all as a 686A. 30 * Reports all as a 686A.
30 Warning - only supports a single device. 31 * Warning - only supports a single device.
31*/ 32 */
32 33
33#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 34#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
34 35
@@ -47,8 +48,10 @@
47#include <linux/io.h> 48#include <linux/io.h>
48 49
49 50
50/* If force_addr is set to anything different from 0, we forcibly enable 51/*
51 the device at the given address. */ 52 * If force_addr is set to anything different from 0, we forcibly enable
53 * the device at the given address.
54 */
52static unsigned short force_addr; 55static unsigned short force_addr;
53module_param(force_addr, ushort, 0); 56module_param(force_addr, ushort, 0);
54MODULE_PARM_DESC(force_addr, 57MODULE_PARM_DESC(force_addr,
@@ -57,9 +60,9 @@ MODULE_PARM_DESC(force_addr,
57static struct platform_device *pdev; 60static struct platform_device *pdev;
58 61
59/* 62/*
60 The Via 686a southbridge has a LM78-like chip integrated on the same IC. 63 * The Via 686a southbridge has a LM78-like chip integrated on the same IC.
61 This driver is a customized copy of lm78.c 64 * This driver is a customized copy of lm78.c
62*/ 65 */
63 66
64/* Many VIA686A constants specified below */ 67/* Many VIA686A constants specified below */
65 68
@@ -91,40 +94,46 @@ static const u8 VIA686A_REG_TEMP_HYST[] = { 0x3a, 0x3e, 0x1e };
91#define VIA686A_REG_ALARM2 0x42 94#define VIA686A_REG_ALARM2 0x42
92#define VIA686A_REG_FANDIV 0x47 95#define VIA686A_REG_FANDIV 0x47
93#define VIA686A_REG_CONFIG 0x40 96#define VIA686A_REG_CONFIG 0x40
94/* The following register sets temp interrupt mode (bits 1-0 for temp1, 97/*
95 3-2 for temp2, 5-4 for temp3). Modes are: 98 * The following register sets temp interrupt mode (bits 1-0 for temp1,
96 00 interrupt stays as long as value is out-of-range 99 * 3-2 for temp2, 5-4 for temp3). Modes are:
97 01 interrupt is cleared once register is read (default) 100 * 00 interrupt stays as long as value is out-of-range
98 10 comparator mode- like 00, but ignores hysteresis 101 * 01 interrupt is cleared once register is read (default)
99 11 same as 00 */ 102 * 10 comparator mode- like 00, but ignores hysteresis
103 * 11 same as 00
104 */
100#define VIA686A_REG_TEMP_MODE 0x4b 105#define VIA686A_REG_TEMP_MODE 0x4b
101/* We'll just assume that you want to set all 3 simultaneously: */ 106/* We'll just assume that you want to set all 3 simultaneously: */
102#define VIA686A_TEMP_MODE_MASK 0x3F 107#define VIA686A_TEMP_MODE_MASK 0x3F
103#define VIA686A_TEMP_MODE_CONTINUOUS 0x00 108#define VIA686A_TEMP_MODE_CONTINUOUS 0x00
104 109
105/* Conversions. Limit checking is only done on the TO_REG 110/*
106 variants. 111 * Conversions. Limit checking is only done on the TO_REG
107 112 * variants.
108********* VOLTAGE CONVERSIONS (Bob Dougherty) ******** 113 *
109 From HWMon.cpp (Copyright 1998-2000 Jonathan Teh Soon Yew): 114 ******** VOLTAGE CONVERSIONS (Bob Dougherty) ********
110 voltagefactor[0]=1.25/2628; (2628/1.25=2102.4) // Vccp 115 * From HWMon.cpp (Copyright 1998-2000 Jonathan Teh Soon Yew):
111 voltagefactor[1]=1.25/2628; (2628/1.25=2102.4) // +2.5V 116 * voltagefactor[0]=1.25/2628; (2628/1.25=2102.4) // Vccp
112 voltagefactor[2]=1.67/2628; (2628/1.67=1573.7) // +3.3V 117 * voltagefactor[1]=1.25/2628; (2628/1.25=2102.4) // +2.5V
113 voltagefactor[3]=2.6/2628; (2628/2.60=1010.8) // +5V 118 * voltagefactor[2]=1.67/2628; (2628/1.67=1573.7) // +3.3V
114 voltagefactor[4]=6.3/2628; (2628/6.30=417.14) // +12V 119 * voltagefactor[3]=2.6/2628; (2628/2.60=1010.8) // +5V
115 in[i]=(data[i+2]*25.0+133)*voltagefactor[i]; 120 * voltagefactor[4]=6.3/2628; (2628/6.30=417.14) // +12V
116 That is: 121 * in[i]=(data[i+2]*25.0+133)*voltagefactor[i];
117 volts = (25*regVal+133)*factor 122 * That is:
118 regVal = (volts/factor-133)/25 123 * volts = (25*regVal+133)*factor
119 (These conversions were contributed by Jonathan Teh Soon Yew 124 * regVal = (volts/factor-133)/25
120 <j.teh@iname.com>) */ 125 * (These conversions were contributed by Jonathan Teh Soon Yew
126 * <j.teh@iname.com>)
127 */
121static inline u8 IN_TO_REG(long val, int inNum) 128static inline u8 IN_TO_REG(long val, int inNum)
122{ 129{
123 /* To avoid floating point, we multiply constants by 10 (100 for +12V). 130 /*
124 Rounding is done (120500 is actually 133000 - 12500). 131 * To avoid floating point, we multiply constants by 10 (100 for +12V).
125 Remember that val is expressed in 0.001V/bit, which is why we divide 132 * Rounding is done (120500 is actually 133000 - 12500).
126 by an additional 10000 (100000 for +12V): 1000 for val and 10 (100) 133 * Remember that val is expressed in 0.001V/bit, which is why we divide
127 for the constants. */ 134 * by an additional 10000 (100000 for +12V): 1000 for val and 10 (100)
135 * for the constants.
136 */
128 if (inNum <= 1) 137 if (inNum <= 1)
129 return (u8) 138 return (u8)
130 SENSORS_LIMIT((val * 21024 - 1205000) / 250000, 0, 255); 139 SENSORS_LIMIT((val * 21024 - 1205000) / 250000, 0, 255);
@@ -141,9 +150,11 @@ static inline u8 IN_TO_REG(long val, int inNum)
141 150
142static inline long IN_FROM_REG(u8 val, int inNum) 151static inline long IN_FROM_REG(u8 val, int inNum)
143{ 152{
144 /* To avoid floating point, we multiply constants by 10 (100 for +12V). 153 /*
145 We also multiply them by 1000 because we want 0.001V/bit for the 154 * To avoid floating point, we multiply constants by 10 (100 for +12V).
146 output value. Rounding is done. */ 155 * We also multiply them by 1000 because we want 0.001V/bit for the
156 * output value. Rounding is done.
157 */
147 if (inNum <= 1) 158 if (inNum <= 1)
148 return (long) ((250000 * val + 1330000 + 21024 / 2) / 21024); 159 return (long) ((250000 * val + 1330000 + 21024 / 2) / 21024);
149 else if (inNum == 2) 160 else if (inNum == 2)
@@ -155,9 +166,11 @@ static inline long IN_FROM_REG(u8 val, int inNum)
155} 166}
156 167
157/********* FAN RPM CONVERSIONS ********/ 168/********* FAN RPM CONVERSIONS ********/
158/* Higher register values = slower fans (the fan's strobe gates a counter). 169/*
159 But this chip saturates back at 0, not at 255 like all the other chips. 170 * Higher register values = slower fans (the fan's strobe gates a counter).
160 So, 0 means 0 RPM */ 171 * But this chip saturates back at 0, not at 255 like all the other chips.
172 * So, 0 means 0 RPM
173 */
161static inline u8 FAN_TO_REG(long rpm, int div) 174static inline u8 FAN_TO_REG(long rpm, int div)
162{ 175{
163 if (rpm == 0) 176 if (rpm == 0)
@@ -166,42 +179,45 @@ static inline u8 FAN_TO_REG(long rpm, int div)
166 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 255); 179 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 255);
167} 180}
168 181
169#define FAN_FROM_REG(val,div) ((val)==0?0:(val)==255?0:1350000/((val)*(div))) 182#define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : (val) == 255 ? 0 : 1350000 / \
183 ((val) * (div)))
170 184
171/******** TEMP CONVERSIONS (Bob Dougherty) *********/ 185/******** TEMP CONVERSIONS (Bob Dougherty) *********/
172/* linear fits from HWMon.cpp (Copyright 1998-2000 Jonathan Teh Soon Yew) 186/*
173 if(temp<169) 187 * linear fits from HWMon.cpp (Copyright 1998-2000 Jonathan Teh Soon Yew)
174 return double(temp)*0.427-32.08; 188 * if(temp<169)
175 else if(temp>=169 && temp<=202) 189 * return double(temp)*0.427-32.08;
176 return double(temp)*0.582-58.16; 190 * else if(temp>=169 && temp<=202)
177 else 191 * return double(temp)*0.582-58.16;
178 return double(temp)*0.924-127.33; 192 * else
179 193 * return double(temp)*0.924-127.33;
180 A fifth-order polynomial fits the unofficial data (provided by Alex van 194 *
181 Kaam <darkside@chello.nl>) a bit better. It also give more reasonable 195 * A fifth-order polynomial fits the unofficial data (provided by Alex van
182 numbers on my machine (ie. they agree with what my BIOS tells me). 196 * Kaam <darkside@chello.nl>) a bit better. It also give more reasonable
183 Here's the fifth-order fit to the 8-bit data: 197 * numbers on my machine (ie. they agree with what my BIOS tells me).
184 temp = 1.625093e-10*val^5 - 1.001632e-07*val^4 + 2.457653e-05*val^3 - 198 * Here's the fifth-order fit to the 8-bit data:
185 2.967619e-03*val^2 + 2.175144e-01*val - 7.090067e+0. 199 * temp = 1.625093e-10*val^5 - 1.001632e-07*val^4 + 2.457653e-05*val^3 -
186 200 * 2.967619e-03*val^2 + 2.175144e-01*val - 7.090067e+0.
187 (2000-10-25- RFD: thanks to Uwe Andersen <uandersen@mayah.com> for 201 *
188 finding my typos in this formula!) 202 * (2000-10-25- RFD: thanks to Uwe Andersen <uandersen@mayah.com> for
189 203 * finding my typos in this formula!)
190 Alas, none of the elegant function-fit solutions will work because we 204 *
191 aren't allowed to use floating point in the kernel and doing it with 205 * Alas, none of the elegant function-fit solutions will work because we
192 integers doesn't provide enough precision. So we'll do boring old 206 * aren't allowed to use floating point in the kernel and doing it with
193 look-up table stuff. The unofficial data (see below) have effectively 207 * integers doesn't provide enough precision. So we'll do boring old
194 7-bit resolution (they are rounded to the nearest degree). I'm assuming 208 * look-up table stuff. The unofficial data (see below) have effectively
195 that the transfer function of the device is monotonic and smooth, so a 209 * 7-bit resolution (they are rounded to the nearest degree). I'm assuming
196 smooth function fit to the data will allow us to get better precision. 210 * that the transfer function of the device is monotonic and smooth, so a
197 I used the 5th-order poly fit described above and solved for 211 * smooth function fit to the data will allow us to get better precision.
198 VIA register values 0-255. I *10 before rounding, so we get tenth-degree 212 * I used the 5th-order poly fit described above and solved for
199 precision. (I could have done all 1024 values for our 10-bit readings, 213 * VIA register values 0-255. I *10 before rounding, so we get tenth-degree
200 but the function is very linear in the useful range (0-80 deg C), so 214 * precision. (I could have done all 1024 values for our 10-bit readings,
201 we'll just use linear interpolation for 10-bit readings.) So, tempLUT 215 * but the function is very linear in the useful range (0-80 deg C), so
202 is the temp at via register values 0-255: */ 216 * we'll just use linear interpolation for 10-bit readings.) So, tempLUT
203static const s16 tempLUT[] = 217 * is the temp at via register values 0-255:
204{ -709, -688, -667, -646, -627, -607, -589, -570, -553, -536, -519, 218 */
219static const s16 tempLUT[] = {
220 -709, -688, -667, -646, -627, -607, -589, -570, -553, -536, -519,
205 -503, -487, -471, -456, -442, -428, -414, -400, -387, -375, 221 -503, -487, -471, -456, -442, -428, -414, -400, -387, -375,
206 -362, -350, -339, -327, -316, -305, -295, -285, -275, -265, 222 -362, -350, -339, -327, -316, -305, -295, -285, -275, -265,
207 -255, -246, -237, -229, -220, -212, -204, -196, -188, -180, 223 -255, -246, -237, -229, -220, -212, -204, -196, -188, -180,
@@ -225,29 +241,31 @@ static const s16 tempLUT[] =
225 1276, 1301, 1326, 1352, 1378, 1406, 1434, 1462 241 1276, 1301, 1326, 1352, 1378, 1406, 1434, 1462
226}; 242};
227 243
228/* the original LUT values from Alex van Kaam <darkside@chello.nl> 244/*
229 (for via register values 12-240): 245 * the original LUT values from Alex van Kaam <darkside@chello.nl>
230{-50,-49,-47,-45,-43,-41,-39,-38,-37,-35,-34,-33,-32,-31, 246 * (for via register values 12-240):
231-30,-29,-28,-27,-26,-25,-24,-24,-23,-22,-21,-20,-20,-19,-18,-17,-17,-16,-15, 247 * {-50,-49,-47,-45,-43,-41,-39,-38,-37,-35,-34,-33,-32,-31,
232-15,-14,-14,-13,-12,-12,-11,-11,-10,-9,-9,-8,-8,-7,-7,-6,-6,-5,-5,-4,-4,-3, 248 * -30,-29,-28,-27,-26,-25,-24,-24,-23,-22,-21,-20,-20,-19,-18,-17,-17,-16,-15,
233-3,-2,-2,-1,-1,0,0,1,1,1,3,3,3,4,4,4,5,5,5,6,6,7,7,8,8,9,9,9,10,10,11,11,12, 249 * -15,-14,-14,-13,-12,-12,-11,-11,-10,-9,-9,-8,-8,-7,-7,-6,-6,-5,-5,-4,-4,-3,
23412,12,13,13,13,14,14,15,15,16,16,16,17,17,18,18,19,19,20,20,21,21,21,22,22, 250 * -3,-2,-2,-1,-1,0,0,1,1,1,3,3,3,4,4,4,5,5,5,6,6,7,7,8,8,9,9,9,10,10,11,11,12,
23522,23,23,24,24,25,25,26,26,26,27,27,27,28,28,29,29,30,30,30,31,31,32,32,33, 251 * 12,12,13,13,13,14,14,15,15,16,16,16,17,17,18,18,19,19,20,20,21,21,21,22,22,
23633,34,34,35,35,35,36,36,37,37,38,38,39,39,40,40,41,41,42,42,43,43,44,44,45, 252 * 22,23,23,24,24,25,25,26,26,26,27,27,27,28,28,29,29,30,30,30,31,31,32,32,33,
23745,46,46,47,48,48,49,49,50,51,51,52,52,53,53,54,55,55,56,57,57,58,59,59,60, 253 * 33,34,34,35,35,35,36,36,37,37,38,38,39,39,40,40,41,41,42,42,43,43,44,44,45,
23861,62,62,63,64,65,66,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,83,84, 254 * 45,46,46,47,48,48,49,49,50,51,51,52,52,53,53,54,55,55,56,57,57,58,59,59,60,
23985,86,88,89,91,92,94,96,97,99,101,103,105,107,109,110}; 255 * 61,62,62,63,64,65,66,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,83,84,
240 256 * 85,86,88,89,91,92,94,96,97,99,101,103,105,107,109,110};
241 257 *
242 Here's the reverse LUT. I got it by doing a 6-th order poly fit (needed 258 *
243 an extra term for a good fit to these inverse data!) and then 259 * Here's the reverse LUT. I got it by doing a 6-th order poly fit (needed
244 solving for each temp value from -50 to 110 (the useable range for 260 * an extra term for a good fit to these inverse data!) and then
245 this chip). Here's the fit: 261 * solving for each temp value from -50 to 110 (the useable range for
246 viaRegVal = -1.160370e-10*val^6 +3.193693e-08*val^5 - 1.464447e-06*val^4 262 * this chip). Here's the fit:
247 - 2.525453e-04*val^3 + 1.424593e-02*val^2 + 2.148941e+00*val +7.275808e+01) 263 * viaRegVal = -1.160370e-10*val^6 +3.193693e-08*val^5 - 1.464447e-06*val^4
248 Note that n=161: */ 264 * - 2.525453e-04*val^3 + 1.424593e-02*val^2 + 2.148941e+00*val +7.275808e+01)
249static const u8 viaLUT[] = 265 * Note that n=161:
250{ 12, 12, 13, 14, 14, 15, 16, 16, 17, 18, 18, 19, 20, 20, 21, 22, 23, 266 */
267static const u8 viaLUT[] = {
268 12, 12, 13, 14, 14, 15, 16, 16, 17, 18, 18, 19, 20, 20, 21, 22, 23,
251 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 35, 36, 37, 39, 40, 269 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 35, 36, 37, 39, 40,
252 41, 43, 45, 46, 48, 49, 51, 53, 55, 57, 59, 60, 62, 64, 66, 270 41, 43, 45, 46, 48, 49, 51, 53, 55, 57, 59, 60, 62, 64, 66,
253 69, 71, 73, 75, 77, 79, 82, 84, 86, 88, 91, 93, 95, 98, 100, 271 69, 71, 73, 75, 77, 79, 82, 84, 86, 88, 91, 93, 95, 98, 100,
@@ -262,9 +280,11 @@ static const u8 viaLUT[] =
262 239, 240 280 239, 240
263}; 281};
264 282
265/* Converting temps to (8-bit) hyst and over registers 283/*
266 No interpolation here. 284 * Converting temps to (8-bit) hyst and over registers
267 The +50 is because the temps start at -50 */ 285 * No interpolation here.
286 * The +50 is because the temps start at -50
287 */
268static inline u8 TEMP_TO_REG(long val) 288static inline u8 TEMP_TO_REG(long val)
269{ 289{
270 return viaLUT[val <= -50000 ? 0 : val >= 110000 ? 160 : 290 return viaLUT[val <= -50000 ? 0 : val >= 110000 ? 160 :
@@ -290,10 +310,12 @@ static inline long TEMP_FROM_REG10(u16 val)
290} 310}
291 311
292#define DIV_FROM_REG(val) (1 << (val)) 312#define DIV_FROM_REG(val) (1 << (val))
293#define DIV_TO_REG(val) ((val)==8?3:(val)==4?2:(val)==1?0:1) 313#define DIV_TO_REG(val) ((val) == 8 ? 3 : (val) == 4 ? 2 : (val) == 1 ? 0 : 1)
294 314
295/* For each registered chip, we need to keep some data in memory. 315/*
296 The structure is dynamically allocated. */ 316 * For each registered chip, we need to keep some data in memory.
317 * The structure is dynamically allocated.
318 */
297struct via686a_data { 319struct via686a_data {
298 unsigned short addr; 320 unsigned short addr;
299 const char *name; 321 const char *name;
@@ -365,7 +387,12 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *da,
365 struct via686a_data *data = dev_get_drvdata(dev); 387 struct via686a_data *data = dev_get_drvdata(dev);
366 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 388 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
367 int nr = attr->index; 389 int nr = attr->index;
368 unsigned long val = simple_strtoul(buf, NULL, 10); 390 unsigned long val;
391 int err;
392
393 err = kstrtoul(buf, 10, &val);
394 if (err)
395 return err;
369 396
370 mutex_lock(&data->update_lock); 397 mutex_lock(&data->update_lock);
371 data->in_min[nr] = IN_TO_REG(val, nr); 398 data->in_min[nr] = IN_TO_REG(val, nr);
@@ -379,7 +406,12 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *da,
379 struct via686a_data *data = dev_get_drvdata(dev); 406 struct via686a_data *data = dev_get_drvdata(dev);
380 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 407 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
381 int nr = attr->index; 408 int nr = attr->index;
382 unsigned long val = simple_strtoul(buf, NULL, 10); 409 unsigned long val;
410 int err;
411
412 err = kstrtoul(buf, 10, &val);
413 if (err)
414 return err;
383 415
384 mutex_lock(&data->update_lock); 416 mutex_lock(&data->update_lock);
385 data->in_max[nr] = IN_TO_REG(val, nr); 417 data->in_max[nr] = IN_TO_REG(val, nr);
@@ -429,7 +461,12 @@ static ssize_t set_temp_over(struct device *dev, struct device_attribute *da,
429 struct via686a_data *data = dev_get_drvdata(dev); 461 struct via686a_data *data = dev_get_drvdata(dev);
430 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 462 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
431 int nr = attr->index; 463 int nr = attr->index;
432 int val = simple_strtol(buf, NULL, 10); 464 long val;
465 int err;
466
467 err = kstrtol(buf, 10, &val);
468 if (err)
469 return err;
433 470
434 mutex_lock(&data->update_lock); 471 mutex_lock(&data->update_lock);
435 data->temp_over[nr] = TEMP_TO_REG(val); 472 data->temp_over[nr] = TEMP_TO_REG(val);
@@ -443,7 +480,12 @@ static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *da,
443 struct via686a_data *data = dev_get_drvdata(dev); 480 struct via686a_data *data = dev_get_drvdata(dev);
444 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 481 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
445 int nr = attr->index; 482 int nr = attr->index;
446 int val = simple_strtol(buf, NULL, 10); 483 long val;
484 int err;
485
486 err = kstrtol(buf, 10, &val);
487 if (err)
488 return err;
447 489
448 mutex_lock(&data->update_lock); 490 mutex_lock(&data->update_lock);
449 data->temp_hyst[nr] = TEMP_TO_REG(val); 491 data->temp_hyst[nr] = TEMP_TO_REG(val);
@@ -471,7 +513,7 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *da,
471 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 513 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
472 int nr = attr->index; 514 int nr = attr->index;
473 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], 515 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
474 DIV_FROM_REG(data->fan_div[nr])) ); 516 DIV_FROM_REG(data->fan_div[nr])));
475} 517}
476static ssize_t show_fan_min(struct device *dev, struct device_attribute *da, 518static ssize_t show_fan_min(struct device *dev, struct device_attribute *da,
477 char *buf) { 519 char *buf) {
@@ -479,21 +521,27 @@ static ssize_t show_fan_min(struct device *dev, struct device_attribute *da,
479 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 521 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
480 int nr = attr->index; 522 int nr = attr->index;
481 return sprintf(buf, "%d\n", 523 return sprintf(buf, "%d\n",
482 FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])) ); 524 FAN_FROM_REG(data->fan_min[nr],
525 DIV_FROM_REG(data->fan_div[nr])));
483} 526}
484static ssize_t show_fan_div(struct device *dev, struct device_attribute *da, 527static ssize_t show_fan_div(struct device *dev, struct device_attribute *da,
485 char *buf) { 528 char *buf) {
486 struct via686a_data *data = via686a_update_device(dev); 529 struct via686a_data *data = via686a_update_device(dev);
487 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 530 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
488 int nr = attr->index; 531 int nr = attr->index;
489 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) ); 532 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
490} 533}
491static ssize_t set_fan_min(struct device *dev, struct device_attribute *da, 534static ssize_t set_fan_min(struct device *dev, struct device_attribute *da,
492 const char *buf, size_t count) { 535 const char *buf, size_t count) {
493 struct via686a_data *data = dev_get_drvdata(dev); 536 struct via686a_data *data = dev_get_drvdata(dev);
494 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 537 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
495 int nr = attr->index; 538 int nr = attr->index;
496 int val = simple_strtol(buf, NULL, 10); 539 unsigned long val;
540 int err;
541
542 err = kstrtoul(buf, 10, &val);
543 if (err)
544 return err;
497 545
498 mutex_lock(&data->update_lock); 546 mutex_lock(&data->update_lock);
499 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 547 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
@@ -506,8 +554,13 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *da,
506 struct via686a_data *data = dev_get_drvdata(dev); 554 struct via686a_data *data = dev_get_drvdata(dev);
507 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 555 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
508 int nr = attr->index; 556 int nr = attr->index;
509 int val = simple_strtol(buf, NULL, 10);
510 int old; 557 int old;
558 unsigned long val;
559 int err;
560
561 err = kstrtoul(buf, 10, &val);
562 if (err)
563 return err;
511 564
512 mutex_lock(&data->update_lock); 565 mutex_lock(&data->update_lock);
513 old = via686a_read_value(data, VIA686A_REG_FANDIV); 566 old = via686a_read_value(data, VIA686A_REG_FANDIV);
@@ -530,10 +583,13 @@ show_fan_offset(1);
530show_fan_offset(2); 583show_fan_offset(2);
531 584
532/* Alarms */ 585/* Alarms */
533static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) { 586static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
587 char *buf)
588{
534 struct via686a_data *data = via686a_update_device(dev); 589 struct via686a_data *data = via686a_update_device(dev);
535 return sprintf(buf, "%u\n", data->alarms); 590 return sprintf(buf, "%u\n", data->alarms);
536} 591}
592
537static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 593static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
538 594
539static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, 595static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
@@ -641,7 +697,8 @@ static int __devinit via686a_probe(struct platform_device *pdev)
641 return -ENODEV; 697 return -ENODEV;
642 } 698 }
643 699
644 if (!(data = kzalloc(sizeof(struct via686a_data), GFP_KERNEL))) { 700 data = kzalloc(sizeof(struct via686a_data), GFP_KERNEL);
701 if (!data) {
645 err = -ENOMEM; 702 err = -ENOMEM;
646 goto exit_release; 703 goto exit_release;
647 } 704 }
@@ -655,7 +712,8 @@ static int __devinit via686a_probe(struct platform_device *pdev)
655 via686a_init_device(data); 712 via686a_init_device(data);
656 713
657 /* Register sysfs hooks */ 714 /* Register sysfs hooks */
658 if ((err = sysfs_create_group(&pdev->dev.kobj, &via686a_group))) 715 err = sysfs_create_group(&pdev->dev.kobj, &via686a_group);
716 if (err)
659 goto exit_free; 717 goto exit_free;
660 718
661 data->hwmon_dev = hwmon_device_register(&pdev->dev); 719 data->hwmon_dev = hwmon_device_register(&pdev->dev);
@@ -748,10 +806,11 @@ static struct via686a_data *via686a_update_device(struct device *dev)
748 via686a_read_value(data, 806 via686a_read_value(data,
749 VIA686A_REG_TEMP_HYST[i]); 807 VIA686A_REG_TEMP_HYST[i]);
750 } 808 }
751 /* add in lower 2 bits 809 /*
752 temp1 uses bits 7-6 of VIA686A_REG_TEMP_LOW1 810 * add in lower 2 bits
753 temp2 uses bits 5-4 of VIA686A_REG_TEMP_LOW23 811 * temp1 uses bits 7-6 of VIA686A_REG_TEMP_LOW1
754 temp3 uses bits 7-6 of VIA686A_REG_TEMP_LOW23 812 * temp2 uses bits 5-4 of VIA686A_REG_TEMP_LOW23
813 * temp3 uses bits 7-6 of VIA686A_REG_TEMP_LOW23
755 */ 814 */
756 data->temp[0] |= (via686a_read_value(data, 815 data->temp[0] |= (via686a_read_value(data,
757 VIA686A_REG_TEMP_LOW1) 816 VIA686A_REG_TEMP_LOW1)
@@ -777,11 +836,10 @@ static struct via686a_data *via686a_update_device(struct device *dev)
777 return data; 836 return data;
778} 837}
779 838
780static const struct pci_device_id via686a_pci_ids[] = { 839static DEFINE_PCI_DEVICE_TABLE(via686a_pci_ids) = {
781 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4) }, 840 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4) },
782 { 0, } 841 { }
783}; 842};
784
785MODULE_DEVICE_TABLE(pci, via686a_pci_ids); 843MODULE_DEVICE_TABLE(pci, via686a_pci_ids);
786 844
787static int __devinit via686a_device_add(unsigned short address) 845static int __devinit via686a_device_add(unsigned short address)
@@ -872,7 +930,8 @@ static int __devinit via686a_pci_probe(struct pci_dev *dev,
872 if (via686a_device_add(address)) 930 if (via686a_device_add(address))
873 goto exit_unregister; 931 goto exit_unregister;
874 932
875 /* Always return failure here. This is to allow other drivers to bind 933 /*
934 * Always return failure here. This is to allow other drivers to bind
876 * to this pci device. We don't really want to have control over the 935 * to this pci device. We don't really want to have control over the
877 * pci device, we only wanted to read as few register values from it. 936 * pci device, we only wanted to read as few register values from it.
878 */ 937 */
diff --git a/drivers/hwmon/vt1211.c b/drivers/hwmon/vt1211.c
index 49163d48e966..c2c5c72fb8f0 100644
--- a/drivers/hwmon/vt1211.c
+++ b/drivers/hwmon/vt1211.c
@@ -151,8 +151,10 @@ struct vt1211_data {
151#define ISTEMP(ix, uch_config) ((ix) < 2 ? 1 : \ 151#define ISTEMP(ix, uch_config) ((ix) < 2 ? 1 : \
152 ((uch_config) >> (ix)) & 1) 152 ((uch_config) >> (ix)) & 1)
153 153
154/* in5 (ix = 5) is special. It's the internal 3.3V so it's scaled in the 154/*
155 driver according to the VT1211 BIOS porting guide */ 155 * in5 (ix = 5) is special. It's the internal 3.3V so it's scaled in the
156 * driver according to the VT1211 BIOS porting guide
157 */
156#define IN_FROM_REG(ix, reg) ((reg) < 3 ? 0 : (ix) == 5 ? \ 158#define IN_FROM_REG(ix, reg) ((reg) < 3 ? 0 : (ix) == 5 ? \
157 (((reg) - 3) * 15882 + 479) / 958 : \ 159 (((reg) - 3) * 15882 + 479) / 958 : \
158 (((reg) - 3) * 10000 + 479) / 958) 160 (((reg) - 3) * 10000 + 479) / 958)
@@ -160,11 +162,13 @@ struct vt1211_data {
160 ((val) * 958 + 7941) / 15882 + 3 : \ 162 ((val) * 958 + 7941) / 15882 + 3 : \
161 ((val) * 958 + 5000) / 10000 + 3, 0, 255)) 163 ((val) * 958 + 5000) / 10000 + 3, 0, 255))
162 164
163/* temp1 (ix = 0) is an intel thermal diode which is scaled in user space. 165/*
164 temp2 (ix = 1) is the internal temp diode so it's scaled in the driver 166 * temp1 (ix = 0) is an intel thermal diode which is scaled in user space.
165 according to some measurements that I took on an EPIA M10000. 167 * temp2 (ix = 1) is the internal temp diode so it's scaled in the driver
166 temp3-7 are thermistor based so the driver returns the voltage measured at 168 * according to some measurements that I took on an EPIA M10000.
167 the pin (range 0V - 2.2V). */ 169 * temp3-7 are thermistor based so the driver returns the voltage measured at
170 * the pin (range 0V - 2.2V).
171 */
168#define TEMP_FROM_REG(ix, reg) ((ix) == 0 ? (reg) * 1000 : \ 172#define TEMP_FROM_REG(ix, reg) ((ix) == 0 ? (reg) * 1000 : \
169 (ix) == 1 ? (reg) < 51 ? 0 : \ 173 (ix) == 1 ? (reg) < 51 ? 0 : \
170 ((reg) - 51) * 1000 : \ 174 ((reg) - 51) * 1000 : \
@@ -186,8 +190,10 @@ struct vt1211_data {
186 * Super-I/O constants and functions 190 * Super-I/O constants and functions
187 * --------------------------------------------------------------------- */ 191 * --------------------------------------------------------------------- */
188 192
189/* Configuration index port registers 193/*
190 * The vt1211 can live at 2 different addresses so we need to probe both */ 194 * Configuration index port registers
195 * The vt1211 can live at 2 different addresses so we need to probe both
196 */
191#define SIO_REG_CIP1 0x2e 197#define SIO_REG_CIP1 0x2e
192#define SIO_REG_CIP2 0x4e 198#define SIO_REG_CIP2 0x4e
193 199
@@ -377,7 +383,12 @@ static ssize_t set_in(struct device *dev, struct device_attribute *attr,
377 to_sensor_dev_attr_2(attr); 383 to_sensor_dev_attr_2(attr);
378 int ix = sensor_attr_2->index; 384 int ix = sensor_attr_2->index;
379 int fn = sensor_attr_2->nr; 385 int fn = sensor_attr_2->nr;
380 long val = simple_strtol(buf, NULL, 10); 386 long val;
387 int err;
388
389 err = kstrtol(buf, 10, &val);
390 if (err)
391 return err;
381 392
382 mutex_lock(&data->update_lock); 393 mutex_lock(&data->update_lock);
383 switch (fn) { 394 switch (fn) {
@@ -446,7 +457,12 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
446 to_sensor_dev_attr_2(attr); 457 to_sensor_dev_attr_2(attr);
447 int ix = sensor_attr_2->index; 458 int ix = sensor_attr_2->index;
448 int fn = sensor_attr_2->nr; 459 int fn = sensor_attr_2->nr;
449 long val = simple_strtol(buf, NULL, 10); 460 long val;
461 int err;
462
463 err = kstrtol(buf, 10, &val);
464 if (err)
465 return err;
450 466
451 mutex_lock(&data->update_lock); 467 mutex_lock(&data->update_lock);
452 switch (fn) { 468 switch (fn) {
@@ -517,8 +533,13 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
517 to_sensor_dev_attr_2(attr); 533 to_sensor_dev_attr_2(attr);
518 int ix = sensor_attr_2->index; 534 int ix = sensor_attr_2->index;
519 int fn = sensor_attr_2->nr; 535 int fn = sensor_attr_2->nr;
520 long val = simple_strtol(buf, NULL, 10);
521 int reg; 536 int reg;
537 unsigned long val;
538 int err;
539
540 err = kstrtoul(buf, 10, &val);
541 if (err)
542 return err;
522 543
523 mutex_lock(&data->update_lock); 544 mutex_lock(&data->update_lock);
524 545
@@ -536,16 +557,23 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
536 break; 557 break;
537 case SHOW_SET_FAN_DIV: 558 case SHOW_SET_FAN_DIV:
538 switch (val) { 559 switch (val) {
539 case 1: data->fan_div[ix] = 0; break; 560 case 1:
540 case 2: data->fan_div[ix] = 1; break; 561 data->fan_div[ix] = 0;
541 case 4: data->fan_div[ix] = 2; break; 562 break;
542 case 8: data->fan_div[ix] = 3; break; 563 case 2:
543 default: 564 data->fan_div[ix] = 1;
544 count = -EINVAL; 565 break;
545 dev_warn(dev, "fan div value %ld not " 566 case 4:
546 "supported. Choose one of 1, 2, " 567 data->fan_div[ix] = 2;
547 "4, or 8.\n", val); 568 break;
548 goto EXIT; 569 case 8:
570 data->fan_div[ix] = 3;
571 break;
572 default:
573 count = -EINVAL;
574 dev_warn(dev, "fan div value %ld not supported. "
575 "Choose one of 1, 2, 4, or 8.\n", val);
576 goto EXIT;
549 } 577 }
550 vt1211_write8(data, VT1211_REG_FAN_DIV, 578 vt1211_write8(data, VT1211_REG_FAN_DIV,
551 ((data->fan_div[1] << 6) | 579 ((data->fan_div[1] << 6) |
@@ -610,8 +638,13 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
610 to_sensor_dev_attr_2(attr); 638 to_sensor_dev_attr_2(attr);
611 int ix = sensor_attr_2->index; 639 int ix = sensor_attr_2->index;
612 int fn = sensor_attr_2->nr; 640 int fn = sensor_attr_2->nr;
613 long val = simple_strtol(buf, NULL, 10);
614 int tmp, reg; 641 int tmp, reg;
642 unsigned long val;
643 int err;
644
645 err = kstrtoul(buf, 10, &val);
646 if (err)
647 return err;
615 648
616 mutex_lock(&data->update_lock); 649 mutex_lock(&data->update_lock);
617 650
@@ -628,11 +661,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
628 switch (val) { 661 switch (val) {
629 case 0: 662 case 0:
630 data->pwm_ctl[ix] &= 7; 663 data->pwm_ctl[ix] &= 7;
631 /* disable SmartGuardian if both PWM outputs are 664 /*
632 * disabled */ 665 * disable SmartGuardian if both PWM outputs are
633 if ((data->pwm_ctl[ix ^ 1] & 1) == 0) { 666 * disabled
667 */
668 if ((data->pwm_ctl[ix ^ 1] & 1) == 0)
634 data->fan_ctl &= 0xe; 669 data->fan_ctl &= 0xe;
635 }
636 break; 670 break;
637 case 2: 671 case 2:
638 data->pwm_ctl[ix] |= 8; 672 data->pwm_ctl[ix] |= 8;
@@ -656,16 +690,15 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
656 val = 135000 / SENSORS_LIMIT(val, 135000 >> 7, 135000); 690 val = 135000 / SENSORS_LIMIT(val, 135000 >> 7, 135000);
657 /* calculate tmp = log2(val) */ 691 /* calculate tmp = log2(val) */
658 tmp = 0; 692 tmp = 0;
659 for (val >>= 1; val > 0; val >>= 1) { 693 for (val >>= 1; val > 0; val >>= 1)
660 tmp++; 694 tmp++;
661 }
662 /* sync the data cache */ 695 /* sync the data cache */
663 reg = vt1211_read8(data, VT1211_REG_PWM_CLK); 696 reg = vt1211_read8(data, VT1211_REG_PWM_CLK);
664 data->pwm_clk = (reg & 0xf8) | tmp; 697 data->pwm_clk = (reg & 0xf8) | tmp;
665 vt1211_write8(data, VT1211_REG_PWM_CLK, data->pwm_clk); 698 vt1211_write8(data, VT1211_REG_PWM_CLK, data->pwm_clk);
666 break; 699 break;
667 case SHOW_SET_PWM_AUTO_CHANNELS_TEMP: 700 case SHOW_SET_PWM_AUTO_CHANNELS_TEMP:
668 if ((val < 1) || (val > 7)) { 701 if (val < 1 || val > 7) {
669 count = -EINVAL; 702 count = -EINVAL;
670 dev_warn(dev, "temp channel %ld not supported. " 703 dev_warn(dev, "temp channel %ld not supported. "
671 "Choose a value between 1 and 7.\n", val); 704 "Choose a value between 1 and 7.\n", val);
@@ -741,8 +774,14 @@ static ssize_t set_pwm_auto_point_temp(struct device *dev,
741 to_sensor_dev_attr_2(attr); 774 to_sensor_dev_attr_2(attr);
742 int ix = sensor_attr_2->index; 775 int ix = sensor_attr_2->index;
743 int ap = sensor_attr_2->nr; 776 int ap = sensor_attr_2->nr;
744 long val = simple_strtol(buf, NULL, 10);
745 int reg; 777 int reg;
778 long val;
779 int err;
780
781 err = kstrtol(buf, 10, &val);
782 if (err)
783 return err;
784
746 785
747 mutex_lock(&data->update_lock); 786 mutex_lock(&data->update_lock);
748 787
@@ -774,7 +813,7 @@ static ssize_t set_pwm_auto_point_temp(struct device *dev,
774 * 1 1 : pwm2 low speed duty cycle (pwm_auto_pwm[1][1]) 813 * 1 1 : pwm2 low speed duty cycle (pwm_auto_pwm[1][1])
775 * 1 2 : pwm2 high speed duty cycle (pwm_auto_pwm[1][2]) 814 * 1 2 : pwm2 high speed duty cycle (pwm_auto_pwm[1][2])
776 * 1 3 : pwm2 full speed (pwm_auto_pwm[1][3], hard-wired to 255) 815 * 1 3 : pwm2 full speed (pwm_auto_pwm[1][3], hard-wired to 255)
777*/ 816 */
778 817
779static ssize_t show_pwm_auto_point_pwm(struct device *dev, 818static ssize_t show_pwm_auto_point_pwm(struct device *dev,
780 struct device_attribute *attr, 819 struct device_attribute *attr,
@@ -798,16 +837,15 @@ static ssize_t set_pwm_auto_point_pwm(struct device *dev,
798 to_sensor_dev_attr_2(attr); 837 to_sensor_dev_attr_2(attr);
799 int ix = sensor_attr_2->index; 838 int ix = sensor_attr_2->index;
800 int ap = sensor_attr_2->nr; 839 int ap = sensor_attr_2->nr;
801 long val = simple_strtol(buf, NULL, 10); 840 unsigned long val;
841 int err;
802 842
803 if ((val < 0) || (val > 255)) { 843 err = kstrtoul(buf, 10, &val);
804 dev_err(dev, "pwm value %ld is out of range. " 844 if (err)
805 "Choose a value between 0 and 255.\n" , val); 845 return err;
806 return -EINVAL;
807 }
808 846
809 mutex_lock(&data->update_lock); 847 mutex_lock(&data->update_lock);
810 data->pwm_auto_pwm[ix][ap] = val; 848 data->pwm_auto_pwm[ix][ap] = SENSORS_LIMIT(val, 0, 255);
811 vt1211_write8(data, VT1211_REG_PWM_AUTO_PWM(ix, ap), 849 vt1211_write8(data, VT1211_REG_PWM_AUTO_PWM(ix, ap),
812 data->pwm_auto_pwm[ix][ap]); 850 data->pwm_auto_pwm[ix][ap]);
813 mutex_unlock(&data->update_lock); 851 mutex_unlock(&data->update_lock);
@@ -831,7 +869,12 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
831 const char *buf, size_t count) 869 const char *buf, size_t count)
832{ 870{
833 struct vt1211_data *data = dev_get_drvdata(dev); 871 struct vt1211_data *data = dev_get_drvdata(dev);
834 long val = simple_strtol(buf, NULL, 10); 872 unsigned long val;
873 int err;
874
875 err = kstrtoul(buf, 10, &val);
876 if (err)
877 return err;
835 878
836 data->vrm = val; 879 data->vrm = val;
837 880
@@ -866,112 +909,99 @@ static ssize_t show_alarms(struct device *dev,
866 * Device attribute structs 909 * Device attribute structs
867 * --------------------------------------------------------------------- */ 910 * --------------------------------------------------------------------- */
868 911
869#define SENSOR_ATTR_IN_INPUT(ix) \ 912#define SENSOR_ATTR_IN(ix) \
870 SENSOR_ATTR_2(in##ix##_input, S_IRUGO, \ 913{ SENSOR_ATTR_2(in##ix##_input, S_IRUGO, \
871 show_in, NULL, SHOW_IN_INPUT, ix) 914 show_in, NULL, SHOW_IN_INPUT, ix), \
872
873static struct sensor_device_attribute_2 vt1211_sysfs_in_input[] = {
874 SENSOR_ATTR_IN_INPUT(0),
875 SENSOR_ATTR_IN_INPUT(1),
876 SENSOR_ATTR_IN_INPUT(2),
877 SENSOR_ATTR_IN_INPUT(3),
878 SENSOR_ATTR_IN_INPUT(4),
879 SENSOR_ATTR_IN_INPUT(5),
880};
881
882#define SENSOR_ATTR_IN_MIN(ix) \
883 SENSOR_ATTR_2(in##ix##_min, S_IRUGO | S_IWUSR, \ 915 SENSOR_ATTR_2(in##ix##_min, S_IRUGO | S_IWUSR, \
884 show_in, set_in, SHOW_SET_IN_MIN, ix) 916 show_in, set_in, SHOW_SET_IN_MIN, ix), \
885
886static struct sensor_device_attribute_2 vt1211_sysfs_in_min[] = {
887 SENSOR_ATTR_IN_MIN(0),
888 SENSOR_ATTR_IN_MIN(1),
889 SENSOR_ATTR_IN_MIN(2),
890 SENSOR_ATTR_IN_MIN(3),
891 SENSOR_ATTR_IN_MIN(4),
892 SENSOR_ATTR_IN_MIN(5),
893};
894
895#define SENSOR_ATTR_IN_MAX(ix) \
896 SENSOR_ATTR_2(in##ix##_max, S_IRUGO | S_IWUSR, \ 917 SENSOR_ATTR_2(in##ix##_max, S_IRUGO | S_IWUSR, \
897 show_in, set_in, SHOW_SET_IN_MAX, ix) 918 show_in, set_in, SHOW_SET_IN_MAX, ix), \
898 919 SENSOR_ATTR_2(in##ix##_alarm, S_IRUGO, \
899static struct sensor_device_attribute_2 vt1211_sysfs_in_max[] = { 920 show_in, NULL, SHOW_IN_ALARM, ix) \
900 SENSOR_ATTR_IN_MAX(0), 921}
901 SENSOR_ATTR_IN_MAX(1), 922
902 SENSOR_ATTR_IN_MAX(2), 923static struct sensor_device_attribute_2 vt1211_sysfs_in[][4] = {
903 SENSOR_ATTR_IN_MAX(3), 924 SENSOR_ATTR_IN(0),
904 SENSOR_ATTR_IN_MAX(4), 925 SENSOR_ATTR_IN(1),
905 SENSOR_ATTR_IN_MAX(5), 926 SENSOR_ATTR_IN(2),
927 SENSOR_ATTR_IN(3),
928 SENSOR_ATTR_IN(4),
929 SENSOR_ATTR_IN(5)
906}; 930};
907 931
908#define SENSOR_ATTR_IN_ALARM(ix) \ 932#define IN_UNIT_ATTRS(X) \
909 SENSOR_ATTR_2(in##ix##_alarm, S_IRUGO, \ 933{ &vt1211_sysfs_in[X][0].dev_attr.attr, \
910 show_in, NULL, SHOW_IN_ALARM, ix) 934 &vt1211_sysfs_in[X][1].dev_attr.attr, \
911 935 &vt1211_sysfs_in[X][2].dev_attr.attr, \
912static struct sensor_device_attribute_2 vt1211_sysfs_in_alarm[] = { 936 &vt1211_sysfs_in[X][3].dev_attr.attr, \
913 SENSOR_ATTR_IN_ALARM(0), 937 NULL \
914 SENSOR_ATTR_IN_ALARM(1), 938}
915 SENSOR_ATTR_IN_ALARM(2), 939
916 SENSOR_ATTR_IN_ALARM(3), 940static struct attribute *vt1211_in_attr[][5] = {
917 SENSOR_ATTR_IN_ALARM(4), 941 IN_UNIT_ATTRS(0),
918 SENSOR_ATTR_IN_ALARM(5), 942 IN_UNIT_ATTRS(1),
943 IN_UNIT_ATTRS(2),
944 IN_UNIT_ATTRS(3),
945 IN_UNIT_ATTRS(4),
946 IN_UNIT_ATTRS(5)
919}; 947};
920 948
921#define SENSOR_ATTR_TEMP_INPUT(ix) \ 949static const struct attribute_group vt1211_in_attr_group[] = {
922 SENSOR_ATTR_2(temp##ix##_input, S_IRUGO, \ 950 { .attrs = vt1211_in_attr[0] },
923 show_temp, NULL, SHOW_TEMP_INPUT, ix-1) 951 { .attrs = vt1211_in_attr[1] },
924 952 { .attrs = vt1211_in_attr[2] },
925static struct sensor_device_attribute_2 vt1211_sysfs_temp_input[] = { 953 { .attrs = vt1211_in_attr[3] },
926 SENSOR_ATTR_TEMP_INPUT(1), 954 { .attrs = vt1211_in_attr[4] },
927 SENSOR_ATTR_TEMP_INPUT(2), 955 { .attrs = vt1211_in_attr[5] }
928 SENSOR_ATTR_TEMP_INPUT(3),
929 SENSOR_ATTR_TEMP_INPUT(4),
930 SENSOR_ATTR_TEMP_INPUT(5),
931 SENSOR_ATTR_TEMP_INPUT(6),
932 SENSOR_ATTR_TEMP_INPUT(7),
933}; 956};
934 957
935#define SENSOR_ATTR_TEMP_MAX(ix) \ 958#define SENSOR_ATTR_TEMP(ix) \
959{ SENSOR_ATTR_2(temp##ix##_input, S_IRUGO, \
960 show_temp, NULL, SHOW_TEMP_INPUT, ix-1), \
936 SENSOR_ATTR_2(temp##ix##_max, S_IRUGO | S_IWUSR, \ 961 SENSOR_ATTR_2(temp##ix##_max, S_IRUGO | S_IWUSR, \
937 show_temp, set_temp, SHOW_SET_TEMP_MAX, ix-1) 962 show_temp, set_temp, SHOW_SET_TEMP_MAX, ix-1), \
938 963 SENSOR_ATTR_2(temp##ix##_max_hyst, S_IRUGO | S_IWUSR, \
939static struct sensor_device_attribute_2 vt1211_sysfs_temp_max[] = { 964 show_temp, set_temp, SHOW_SET_TEMP_MAX_HYST, ix-1), \
940 SENSOR_ATTR_TEMP_MAX(1), 965 SENSOR_ATTR_2(temp##ix##_alarm, S_IRUGO, \
941 SENSOR_ATTR_TEMP_MAX(2), 966 show_temp, NULL, SHOW_TEMP_ALARM, ix-1) \
942 SENSOR_ATTR_TEMP_MAX(3), 967}
943 SENSOR_ATTR_TEMP_MAX(4), 968
944 SENSOR_ATTR_TEMP_MAX(5), 969static struct sensor_device_attribute_2 vt1211_sysfs_temp[][4] = {
945 SENSOR_ATTR_TEMP_MAX(6), 970 SENSOR_ATTR_TEMP(1),
946 SENSOR_ATTR_TEMP_MAX(7), 971 SENSOR_ATTR_TEMP(2),
972 SENSOR_ATTR_TEMP(3),
973 SENSOR_ATTR_TEMP(4),
974 SENSOR_ATTR_TEMP(5),
975 SENSOR_ATTR_TEMP(6),
976 SENSOR_ATTR_TEMP(7),
947}; 977};
948 978
949#define SENSOR_ATTR_TEMP_MAX_HYST(ix) \ 979#define TEMP_UNIT_ATTRS(X) \
950 SENSOR_ATTR_2(temp##ix##_max_hyst, S_IRUGO | S_IWUSR, \ 980{ &vt1211_sysfs_temp[X][0].dev_attr.attr, \
951 show_temp, set_temp, SHOW_SET_TEMP_MAX_HYST, ix-1) 981 &vt1211_sysfs_temp[X][1].dev_attr.attr, \
952 982 &vt1211_sysfs_temp[X][2].dev_attr.attr, \
953static struct sensor_device_attribute_2 vt1211_sysfs_temp_max_hyst[] = { 983 &vt1211_sysfs_temp[X][3].dev_attr.attr, \
954 SENSOR_ATTR_TEMP_MAX_HYST(1), 984 NULL \
955 SENSOR_ATTR_TEMP_MAX_HYST(2), 985}
956 SENSOR_ATTR_TEMP_MAX_HYST(3), 986
957 SENSOR_ATTR_TEMP_MAX_HYST(4), 987static struct attribute *vt1211_temp_attr[][5] = {
958 SENSOR_ATTR_TEMP_MAX_HYST(5), 988 TEMP_UNIT_ATTRS(0),
959 SENSOR_ATTR_TEMP_MAX_HYST(6), 989 TEMP_UNIT_ATTRS(1),
960 SENSOR_ATTR_TEMP_MAX_HYST(7), 990 TEMP_UNIT_ATTRS(2),
991 TEMP_UNIT_ATTRS(3),
992 TEMP_UNIT_ATTRS(4),
993 TEMP_UNIT_ATTRS(5),
994 TEMP_UNIT_ATTRS(6)
961}; 995};
962 996
963#define SENSOR_ATTR_TEMP_ALARM(ix) \ 997static const struct attribute_group vt1211_temp_attr_group[] = {
964 SENSOR_ATTR_2(temp##ix##_alarm, S_IRUGO, \ 998 { .attrs = vt1211_temp_attr[0] },
965 show_temp, NULL, SHOW_TEMP_ALARM, ix-1) 999 { .attrs = vt1211_temp_attr[1] },
966 1000 { .attrs = vt1211_temp_attr[2] },
967static struct sensor_device_attribute_2 vt1211_sysfs_temp_alarm[] = { 1001 { .attrs = vt1211_temp_attr[3] },
968 SENSOR_ATTR_TEMP_ALARM(1), 1002 { .attrs = vt1211_temp_attr[4] },
969 SENSOR_ATTR_TEMP_ALARM(2), 1003 { .attrs = vt1211_temp_attr[5] },
970 SENSOR_ATTR_TEMP_ALARM(3), 1004 { .attrs = vt1211_temp_attr[6] }
971 SENSOR_ATTR_TEMP_ALARM(4),
972 SENSOR_ATTR_TEMP_ALARM(5),
973 SENSOR_ATTR_TEMP_ALARM(6),
974 SENSOR_ATTR_TEMP_ALARM(7),
975}; 1005};
976 1006
977#define SENSOR_ATTR_FAN(ix) \ 1007#define SENSOR_ATTR_FAN(ix) \
@@ -1069,7 +1099,8 @@ static void __devinit vt1211_init_device(struct vt1211_data *data)
1069 vt1211_write8(data, VT1211_REG_UCH_CONFIG, data->uch_config); 1099 vt1211_write8(data, VT1211_REG_UCH_CONFIG, data->uch_config);
1070 } 1100 }
1071 1101
1072 /* Initialize the interrupt mode (if request at module load time). 1102 /*
1103 * Initialize the interrupt mode (if request at module load time).
1073 * The VT1211 implements 3 different modes for clearing interrupts: 1104 * The VT1211 implements 3 different modes for clearing interrupts:
1074 * 0: Clear INT when status register is read. Regenerate INT as long 1105 * 0: Clear INT when status register is read. Regenerate INT as long
1075 * as temp stays above hysteresis limit. 1106 * as temp stays above hysteresis limit.
@@ -1079,7 +1110,8 @@ static void __devinit vt1211_init_device(struct vt1211_data *data)
1079 * 2: Clear INT when temp falls below max limit. 1110 * 2: Clear INT when temp falls below max limit.
1080 * 1111 *
1081 * The driver only allows to force mode 0 since that's the only one 1112 * The driver only allows to force mode 0 since that's the only one
1082 * that makes sense for 'sensors' */ 1113 * that makes sense for 'sensors'
1114 */
1083 if (int_mode == 0) { 1115 if (int_mode == 0) {
1084 vt1211_write8(data, VT1211_REG_TEMP1_CONFIG, 0); 1116 vt1211_write8(data, VT1211_REG_TEMP1_CONFIG, 0);
1085 vt1211_write8(data, VT1211_REG_TEMP2_CONFIG, 0); 1117 vt1211_write8(data, VT1211_REG_TEMP2_CONFIG, 0);
@@ -1095,33 +1127,18 @@ static void vt1211_remove_sysfs(struct platform_device *pdev)
1095 struct device *dev = &pdev->dev; 1127 struct device *dev = &pdev->dev;
1096 int i; 1128 int i;
1097 1129
1098 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_in_input); i++) { 1130 for (i = 0; i < ARRAY_SIZE(vt1211_in_attr_group); i++)
1099 device_remove_file(dev, 1131 sysfs_remove_group(&dev->kobj, &vt1211_in_attr_group[i]);
1100 &vt1211_sysfs_in_input[i].dev_attr); 1132
1101 device_remove_file(dev, 1133 for (i = 0; i < ARRAY_SIZE(vt1211_temp_attr_group); i++)
1102 &vt1211_sysfs_in_min[i].dev_attr); 1134 sysfs_remove_group(&dev->kobj, &vt1211_temp_attr_group[i]);
1103 device_remove_file(dev, 1135
1104 &vt1211_sysfs_in_max[i].dev_attr);
1105 device_remove_file(dev,
1106 &vt1211_sysfs_in_alarm[i].dev_attr);
1107 }
1108 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_temp_input); i++) {
1109 device_remove_file(dev,
1110 &vt1211_sysfs_temp_input[i].dev_attr);
1111 device_remove_file(dev,
1112 &vt1211_sysfs_temp_max[i].dev_attr);
1113 device_remove_file(dev,
1114 &vt1211_sysfs_temp_max_hyst[i].dev_attr);
1115 device_remove_file(dev,
1116 &vt1211_sysfs_temp_alarm[i].dev_attr);
1117 }
1118 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_fan_pwm); i++) { 1136 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_fan_pwm); i++) {
1119 device_remove_file(dev, 1137 device_remove_file(dev,
1120 &vt1211_sysfs_fan_pwm[i].dev_attr); 1138 &vt1211_sysfs_fan_pwm[i].dev_attr);
1121 } 1139 }
1122 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_misc); i++) { 1140 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_misc); i++)
1123 device_remove_file(dev, &vt1211_sysfs_misc[i]); 1141 device_remove_file(dev, &vt1211_sysfs_misc[i]);
1124 }
1125} 1142}
1126 1143
1127static int __devinit vt1211_probe(struct platform_device *pdev) 1144static int __devinit vt1211_probe(struct platform_device *pdev)
@@ -1131,7 +1148,8 @@ static int __devinit vt1211_probe(struct platform_device *pdev)
1131 struct resource *res; 1148 struct resource *res;
1132 int i, err; 1149 int i, err;
1133 1150
1134 if (!(data = kzalloc(sizeof(struct vt1211_data), GFP_KERNEL))) { 1151 data = kzalloc(sizeof(struct vt1211_data), GFP_KERNEL);
1152 if (!data) {
1135 err = -ENOMEM; 1153 err = -ENOMEM;
1136 dev_err(dev, "Out of memory\n"); 1154 dev_err(dev, "Out of memory\n");
1137 goto EXIT; 1155 goto EXIT;
@@ -1154,47 +1172,33 @@ static int __devinit vt1211_probe(struct platform_device *pdev)
1154 vt1211_init_device(data); 1172 vt1211_init_device(data);
1155 1173
1156 /* Create sysfs interface files */ 1174 /* Create sysfs interface files */
1157 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_in_input); i++) { 1175 for (i = 0; i < ARRAY_SIZE(vt1211_in_attr_group); i++) {
1158 if (ISVOLT(i, data->uch_config)) { 1176 if (ISVOLT(i, data->uch_config)) {
1159 if ((err = device_create_file(dev, 1177 err = sysfs_create_group(&dev->kobj,
1160 &vt1211_sysfs_in_input[i].dev_attr)) || 1178 &vt1211_in_attr_group[i]);
1161 (err = device_create_file(dev, 1179 if (err)
1162 &vt1211_sysfs_in_min[i].dev_attr)) ||
1163 (err = device_create_file(dev,
1164 &vt1211_sysfs_in_max[i].dev_attr)) ||
1165 (err = device_create_file(dev,
1166 &vt1211_sysfs_in_alarm[i].dev_attr))) {
1167 goto EXIT_DEV_REMOVE; 1180 goto EXIT_DEV_REMOVE;
1168 }
1169 } 1181 }
1170 } 1182 }
1171 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_temp_input); i++) { 1183 for (i = 0; i < ARRAY_SIZE(vt1211_temp_attr_group); i++) {
1172 if (ISTEMP(i, data->uch_config)) { 1184 if (ISTEMP(i, data->uch_config)) {
1173 if ((err = device_create_file(dev, 1185 err = sysfs_create_group(&dev->kobj,
1174 &vt1211_sysfs_temp_input[i].dev_attr)) || 1186 &vt1211_temp_attr_group[i]);
1175 (err = device_create_file(dev, 1187 if (err)
1176 &vt1211_sysfs_temp_max[i].dev_attr)) ||
1177 (err = device_create_file(dev,
1178 &vt1211_sysfs_temp_max_hyst[i].dev_attr)) ||
1179 (err = device_create_file(dev,
1180 &vt1211_sysfs_temp_alarm[i].dev_attr))) {
1181 goto EXIT_DEV_REMOVE; 1188 goto EXIT_DEV_REMOVE;
1182 }
1183 } 1189 }
1184 } 1190 }
1185 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_fan_pwm); i++) { 1191 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_fan_pwm); i++) {
1186 err = device_create_file(dev, 1192 err = device_create_file(dev,
1187 &vt1211_sysfs_fan_pwm[i].dev_attr); 1193 &vt1211_sysfs_fan_pwm[i].dev_attr);
1188 if (err) { 1194 if (err)
1189 goto EXIT_DEV_REMOVE; 1195 goto EXIT_DEV_REMOVE;
1190 }
1191 } 1196 }
1192 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_misc); i++) { 1197 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_misc); i++) {
1193 err = device_create_file(dev, 1198 err = device_create_file(dev,
1194 &vt1211_sysfs_misc[i]); 1199 &vt1211_sysfs_misc[i]);
1195 if (err) { 1200 if (err)
1196 goto EXIT_DEV_REMOVE; 1201 goto EXIT_DEV_REMOVE;
1197 }
1198 } 1202 }
1199 1203
1200 /* Register device */ 1204 /* Register device */
@@ -1293,9 +1297,8 @@ static int __init vt1211_find(int sio_cip, unsigned short *address)
1293 superio_enter(sio_cip); 1297 superio_enter(sio_cip);
1294 1298
1295 devid = force_id ? force_id : superio_inb(sio_cip, SIO_VT1211_DEVID); 1299 devid = force_id ? force_id : superio_inb(sio_cip, SIO_VT1211_DEVID);
1296 if (devid != SIO_VT1211_ID) { 1300 if (devid != SIO_VT1211_ID)
1297 goto EXIT; 1301 goto EXIT;
1298 }
1299 1302
1300 superio_select(sio_cip, SIO_VT1211_LDN_HWMON); 1303 superio_select(sio_cip, SIO_VT1211_LDN_HWMON);
1301 1304
@@ -1325,35 +1328,35 @@ static int __init vt1211_init(void)
1325 int err; 1328 int err;
1326 unsigned short address = 0; 1329 unsigned short address = 0;
1327 1330
1328 if ((err = vt1211_find(SIO_REG_CIP1, &address)) && 1331 err = vt1211_find(SIO_REG_CIP1, &address);
1329 (err = vt1211_find(SIO_REG_CIP2, &address))) { 1332 if (err) {
1330 goto EXIT; 1333 err = vt1211_find(SIO_REG_CIP2, &address);
1334 if (err)
1335 goto EXIT;
1331 } 1336 }
1332 1337
1333 if ((uch_config < -1) || (uch_config > 31)) { 1338 if ((uch_config < -1) || (uch_config > 31)) {
1334 err = -EINVAL; 1339 err = -EINVAL;
1335 pr_warn("Invalid UCH configuration %d. " 1340 pr_warn("Invalid UCH configuration %d. "
1336 "Choose a value between 0 and 31.\n", uch_config); 1341 "Choose a value between 0 and 31.\n", uch_config);
1337 goto EXIT; 1342 goto EXIT;
1338 } 1343 }
1339 1344
1340 if ((int_mode < -1) || (int_mode > 0)) { 1345 if ((int_mode < -1) || (int_mode > 0)) {
1341 err = -EINVAL; 1346 err = -EINVAL;
1342 pr_warn("Invalid interrupt mode %d. " 1347 pr_warn("Invalid interrupt mode %d. "
1343 "Only mode 0 is supported.\n", int_mode); 1348 "Only mode 0 is supported.\n", int_mode);
1344 goto EXIT; 1349 goto EXIT;
1345 } 1350 }
1346 1351
1347 err = platform_driver_register(&vt1211_driver); 1352 err = platform_driver_register(&vt1211_driver);
1348 if (err) { 1353 if (err)
1349 goto EXIT; 1354 goto EXIT;
1350 }
1351 1355
1352 /* Sets global pdev as a side effect */ 1356 /* Sets global pdev as a side effect */
1353 err = vt1211_device_add(address); 1357 err = vt1211_device_add(address);
1354 if (err) { 1358 if (err)
1355 goto EXIT_DRV_UNREGISTER; 1359 goto EXIT_DRV_UNREGISTER;
1356 }
1357 1360
1358 return 0; 1361 return 0;
1359 1362
diff --git a/drivers/hwmon/vt8231.c b/drivers/hwmon/vt8231.c
index db3b2e8d2a67..386a84538010 100644
--- a/drivers/hwmon/vt8231.c
+++ b/drivers/hwmon/vt8231.c
@@ -1,28 +1,29 @@
1/* 1/*
2 vt8231.c - Part of lm_sensors, Linux kernel modules 2 * vt8231.c - Part of lm_sensors, Linux kernel modules
3 for hardware monitoring 3 * for hardware monitoring
4 *
5 * Copyright (c) 2005 Roger Lucas <vt8231@hiddenengine.co.uk>
6 * Copyright (c) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com>
7 * Aaron M. Marsh <amarsh@sdf.lonestar.org>
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 */
4 23
5 Copyright (c) 2005 Roger Lucas <vt8231@hiddenengine.co.uk> 24/*
6 Copyright (c) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com> 25 * Supports VIA VT8231 South Bridge embedded sensors
7 Aaron M. Marsh <amarsh@sdf.lonestar.org> 26 */
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/* Supports VIA VT8231 South Bridge embedded sensors
25*/
26 27
27#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 28#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28 29
@@ -50,26 +51,27 @@ static struct platform_device *pdev;
50#define VT8231_BASE_REG 0x70 51#define VT8231_BASE_REG 0x70
51#define VT8231_ENABLE_REG 0x74 52#define VT8231_ENABLE_REG 0x74
52 53
53/* The VT8231 registers 54/*
54 55 * The VT8231 registers
55 The reset value for the input channel configuration is used (Reg 0x4A=0x07) 56 *
56 which sets the selected inputs marked with '*' below if multiple options are 57 * The reset value for the input channel configuration is used (Reg 0x4A=0x07)
57 possible: 58 * which sets the selected inputs marked with '*' below if multiple options are
58 59 * possible:
59 Voltage Mode Temperature Mode 60 *
60 Sensor Linux Id Linux Id VIA Id 61 * Voltage Mode Temperature Mode
61 -------- -------- -------- ------ 62 * Sensor Linux Id Linux Id VIA Id
62 CPU Diode N/A temp1 0 63 * -------- -------- -------- ------
63 UIC1 in0 temp2 * 1 64 * CPU Diode N/A temp1 0
64 UIC2 in1 * temp3 2 65 * UIC1 in0 temp2 * 1
65 UIC3 in2 * temp4 3 66 * UIC2 in1 * temp3 2
66 UIC4 in3 * temp5 4 67 * UIC3 in2 * temp4 3
67 UIC5 in4 * temp6 5 68 * UIC4 in3 * temp5 4
68 3.3V in5 N/A 69 * UIC5 in4 * temp6 5
69 70 * 3.3V in5 N/A
70 Note that the BIOS may set the configuration register to a different value 71 *
71 to match the motherboard configuration. 72 * Note that the BIOS may set the configuration register to a different value
72*/ 73 * to match the motherboard configuration.
74 */
73 75
74/* fans numbered 0-1 */ 76/* fans numbered 0-1 */
75#define VT8231_REG_FAN_MIN(nr) (0x3b + (nr)) 77#define VT8231_REG_FAN_MIN(nr) (0x3b + (nr))
@@ -81,13 +83,14 @@ static const u8 regvolt[] = { 0x21, 0x22, 0x23, 0x24, 0x25, 0x26 };
81static const u8 regvoltmax[] = { 0x3d, 0x2b, 0x2d, 0x2f, 0x31, 0x33 }; 83static const u8 regvoltmax[] = { 0x3d, 0x2b, 0x2d, 0x2f, 0x31, 0x33 };
82static const u8 regvoltmin[] = { 0x3e, 0x2c, 0x2e, 0x30, 0x32, 0x34 }; 84static const u8 regvoltmin[] = { 0x3e, 0x2c, 0x2e, 0x30, 0x32, 0x34 };
83 85
84/* Temperatures are numbered 1-6 according to the Linux kernel specification. 86/*
85** 87 * Temperatures are numbered 1-6 according to the Linux kernel specification.
86** In the VIA datasheet, however, the temperatures are numbered from zero. 88 *
87** Since it is important that this driver can easily be compared to the VIA 89 * In the VIA datasheet, however, the temperatures are numbered from zero.
88** datasheet, we will use the VIA numbering within this driver and map the 90 * Since it is important that this driver can easily be compared to the VIA
89** kernel sysfs device name to the VIA number in the sysfs callback. 91 * datasheet, we will use the VIA numbering within this driver and map the
90*/ 92 * kernel sysfs device name to the VIA number in the sysfs callback.
93 */
91 94
92#define VT8231_REG_TEMP_LOW01 0x49 95#define VT8231_REG_TEMP_LOW01 0x49
93#define VT8231_REG_TEMP_LOW25 0x4d 96#define VT8231_REG_TEMP_LOW25 0x4d
@@ -108,9 +111,10 @@ static const u8 regtempmin[] = { 0x3a, 0x3e, 0x2c, 0x2e, 0x30, 0x32 };
108#define VT8231_REG_TEMP1_CONFIG 0x4b 111#define VT8231_REG_TEMP1_CONFIG 0x4b
109#define VT8231_REG_TEMP2_CONFIG 0x4c 112#define VT8231_REG_TEMP2_CONFIG 0x4c
110 113
111/* temps 0-5 as numbered in VIA datasheet - see later for mapping to Linux 114/*
112** numbering 115 * temps 0-5 as numbered in VIA datasheet - see later for mapping to Linux
113*/ 116 * numbering
117 */
114#define ISTEMP(i, ch_config) ((i) == 0 ? 1 : \ 118#define ISTEMP(i, ch_config) ((i) == 0 ? 1 : \
115 ((ch_config) >> ((i)+1)) & 0x01) 119 ((ch_config) >> ((i)+1)) & 0x01)
116/* voltages 0-5 */ 120/* voltages 0-5 */
@@ -119,24 +123,26 @@ static const u8 regtempmin[] = { 0x3a, 0x3e, 0x2c, 0x2e, 0x30, 0x32 };
119 123
120#define DIV_FROM_REG(val) (1 << (val)) 124#define DIV_FROM_REG(val) (1 << (val))
121 125
122/* NB The values returned here are NOT temperatures. The calibration curves 126/*
123** for the thermistor curves are board-specific and must go in the 127 * NB The values returned here are NOT temperatures. The calibration curves
124** sensors.conf file. Temperature sensors are actually ten bits, but the 128 * for the thermistor curves are board-specific and must go in the
125** VIA datasheet only considers the 8 MSBs obtained from the regtemp[] 129 * sensors.conf file. Temperature sensors are actually ten bits, but the
126** register. The temperature value returned should have a magnitude of 3, 130 * VIA datasheet only considers the 8 MSBs obtained from the regtemp[]
127** so we use the VIA scaling as the "true" scaling and use the remaining 2 131 * register. The temperature value returned should have a magnitude of 3,
128** LSBs as fractional precision. 132 * so we use the VIA scaling as the "true" scaling and use the remaining 2
129** 133 * LSBs as fractional precision.
130** All the on-chip hardware temperature comparisons for the alarms are only 134 *
131** 8-bits wide, and compare against the 8 MSBs of the temperature. The bits 135 * All the on-chip hardware temperature comparisons for the alarms are only
132** in the registers VT8231_REG_TEMP_LOW01 and VT8231_REG_TEMP_LOW25 are 136 * 8-bits wide, and compare against the 8 MSBs of the temperature. The bits
133** ignored. 137 * in the registers VT8231_REG_TEMP_LOW01 and VT8231_REG_TEMP_LOW25 are
134*/ 138 * ignored.
135 139 */
136/******** FAN RPM CONVERSIONS ******** 140
137** This chip saturates back at 0, not at 255 like many the other chips. 141/*
138** So, 0 means 0 RPM 142 ****** FAN RPM CONVERSIONS ********
139*/ 143 * This chip saturates back at 0, not at 255 like many the other chips.
144 * So, 0 means 0 RPM
145 */
140static inline u8 FAN_TO_REG(long rpm, int div) 146static inline u8 FAN_TO_REG(long rpm, int div)
141{ 147{
142 if (rpm == 0) 148 if (rpm == 0)
@@ -222,7 +228,12 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
222 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 228 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
223 int nr = sensor_attr->index; 229 int nr = sensor_attr->index;
224 struct vt8231_data *data = dev_get_drvdata(dev); 230 struct vt8231_data *data = dev_get_drvdata(dev);
225 unsigned long val = simple_strtoul(buf, NULL, 10); 231 unsigned long val;
232 int err;
233
234 err = kstrtoul(buf, 10, &val);
235 if (err)
236 return err;
226 237
227 mutex_lock(&data->update_lock); 238 mutex_lock(&data->update_lock);
228 data->in_min[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255); 239 data->in_min[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255);
@@ -237,7 +248,12 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
237 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 248 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
238 int nr = sensor_attr->index; 249 int nr = sensor_attr->index;
239 struct vt8231_data *data = dev_get_drvdata(dev); 250 struct vt8231_data *data = dev_get_drvdata(dev);
240 unsigned long val = simple_strtoul(buf, NULL, 10); 251 unsigned long val;
252 int err;
253
254 err = kstrtoul(buf, 10, &val);
255 if (err)
256 return err;
241 257
242 mutex_lock(&data->update_lock); 258 mutex_lock(&data->update_lock);
243 data->in_max[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255); 259 data->in_max[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255);
@@ -278,7 +294,12 @@ static ssize_t set_in5_min(struct device *dev, struct device_attribute *attr,
278 const char *buf, size_t count) 294 const char *buf, size_t count)
279{ 295{
280 struct vt8231_data *data = dev_get_drvdata(dev); 296 struct vt8231_data *data = dev_get_drvdata(dev);
281 unsigned long val = simple_strtoul(buf, NULL, 10); 297 unsigned long val;
298 int err;
299
300 err = kstrtoul(buf, 10, &val);
301 if (err)
302 return err;
282 303
283 mutex_lock(&data->update_lock); 304 mutex_lock(&data->update_lock);
284 data->in_min[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3, 305 data->in_min[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3,
@@ -292,7 +313,12 @@ static ssize_t set_in5_max(struct device *dev, struct device_attribute *attr,
292 const char *buf, size_t count) 313 const char *buf, size_t count)
293{ 314{
294 struct vt8231_data *data = dev_get_drvdata(dev); 315 struct vt8231_data *data = dev_get_drvdata(dev);
295 unsigned long val = simple_strtoul(buf, NULL, 10); 316 unsigned long val;
317 int err;
318
319 err = kstrtoul(buf, 10, &val);
320 if (err)
321 return err;
296 322
297 mutex_lock(&data->update_lock); 323 mutex_lock(&data->update_lock);
298 data->in_max[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3, 324 data->in_max[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3,
@@ -346,7 +372,12 @@ static ssize_t set_temp0_max(struct device *dev, struct device_attribute *attr,
346 const char *buf, size_t count) 372 const char *buf, size_t count)
347{ 373{
348 struct vt8231_data *data = dev_get_drvdata(dev); 374 struct vt8231_data *data = dev_get_drvdata(dev);
349 int val = simple_strtol(buf, NULL, 10); 375 long val;
376 int err;
377
378 err = kstrtol(buf, 10, &val);
379 if (err)
380 return err;
350 381
351 mutex_lock(&data->update_lock); 382 mutex_lock(&data->update_lock);
352 data->temp_max[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255); 383 data->temp_max[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255);
@@ -358,7 +389,12 @@ static ssize_t set_temp0_min(struct device *dev, struct device_attribute *attr,
358 const char *buf, size_t count) 389 const char *buf, size_t count)
359{ 390{
360 struct vt8231_data *data = dev_get_drvdata(dev); 391 struct vt8231_data *data = dev_get_drvdata(dev);
361 int val = simple_strtol(buf, NULL, 10); 392 long val;
393 int err;
394
395 err = kstrtol(buf, 10, &val);
396 if (err)
397 return err;
362 398
363 mutex_lock(&data->update_lock); 399 mutex_lock(&data->update_lock);
364 data->temp_min[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255); 400 data->temp_min[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255);
@@ -400,7 +436,12 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
400 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 436 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
401 int nr = sensor_attr->index; 437 int nr = sensor_attr->index;
402 struct vt8231_data *data = dev_get_drvdata(dev); 438 struct vt8231_data *data = dev_get_drvdata(dev);
403 int val = simple_strtol(buf, NULL, 10); 439 long val;
440 int err;
441
442 err = kstrtol(buf, 10, &val);
443 if (err)
444 return err;
404 445
405 mutex_lock(&data->update_lock); 446 mutex_lock(&data->update_lock);
406 data->temp_max[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255); 447 data->temp_max[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255);
@@ -414,7 +455,12 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
414 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 455 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
415 int nr = sensor_attr->index; 456 int nr = sensor_attr->index;
416 struct vt8231_data *data = dev_get_drvdata(dev); 457 struct vt8231_data *data = dev_get_drvdata(dev);
417 int val = simple_strtol(buf, NULL, 10); 458 long val;
459 int err;
460
461 err = kstrtol(buf, 10, &val);
462 if (err)
463 return err;
418 464
419 mutex_lock(&data->update_lock); 465 mutex_lock(&data->update_lock);
420 data->temp_min[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255); 466 data->temp_min[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255);
@@ -423,9 +469,10 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
423 return count; 469 return count;
424} 470}
425 471
426/* Note that these map the Linux temperature sensor numbering (1-6) to the VIA 472/*
427** temperature sensor numbering (0-5) 473 * Note that these map the Linux temperature sensor numbering (1-6) to the VIA
428*/ 474 * temperature sensor numbering (0-5)
475 */
429#define define_temperature_sysfs(offset) \ 476#define define_temperature_sysfs(offset) \
430static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ 477static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
431 show_temp, NULL, offset - 1); \ 478 show_temp, NULL, offset - 1); \
@@ -436,7 +483,8 @@ static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \
436 483
437static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp0, NULL); 484static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp0, NULL);
438static DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, show_temp0_max, set_temp0_max); 485static DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, show_temp0_max, set_temp0_max);
439static DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp0_min, set_temp0_min); 486static DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp0_min,
487 set_temp0_min);
440 488
441define_temperature_sysfs(2); 489define_temperature_sysfs(2);
442define_temperature_sysfs(3); 490define_temperature_sysfs(3);
@@ -480,7 +528,12 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
480 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 528 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
481 int nr = sensor_attr->index; 529 int nr = sensor_attr->index;
482 struct vt8231_data *data = dev_get_drvdata(dev); 530 struct vt8231_data *data = dev_get_drvdata(dev);
483 int val = simple_strtoul(buf, NULL, 10); 531 unsigned long val;
532 int err;
533
534 err = kstrtoul(buf, 10, &val);
535 if (err)
536 return err;
484 537
485 mutex_lock(&data->update_lock); 538 mutex_lock(&data->update_lock);
486 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 539 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
@@ -494,21 +547,34 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
494{ 547{
495 struct vt8231_data *data = dev_get_drvdata(dev); 548 struct vt8231_data *data = dev_get_drvdata(dev);
496 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 549 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
497 unsigned long val = simple_strtoul(buf, NULL, 10); 550 unsigned long val;
498 int nr = sensor_attr->index; 551 int nr = sensor_attr->index;
499 int old = vt8231_read_value(data, VT8231_REG_FANDIV); 552 int old = vt8231_read_value(data, VT8231_REG_FANDIV);
500 long min = FAN_FROM_REG(data->fan_min[nr], 553 long min = FAN_FROM_REG(data->fan_min[nr],
501 DIV_FROM_REG(data->fan_div[nr])); 554 DIV_FROM_REG(data->fan_div[nr]));
555 int err;
556
557 err = kstrtoul(buf, 10, &val);
558 if (err)
559 return err;
502 560
503 mutex_lock(&data->update_lock); 561 mutex_lock(&data->update_lock);
504 switch (val) { 562 switch (val) {
505 case 1: data->fan_div[nr] = 0; break; 563 case 1:
506 case 2: data->fan_div[nr] = 1; break; 564 data->fan_div[nr] = 0;
507 case 4: data->fan_div[nr] = 2; break; 565 break;
508 case 8: data->fan_div[nr] = 3; break; 566 case 2:
567 data->fan_div[nr] = 1;
568 break;
569 case 4:
570 data->fan_div[nr] = 2;
571 break;
572 case 8:
573 data->fan_div[nr] = 3;
574 break;
509 default: 575 default:
510 dev_err(dev, "fan_div value %ld not supported. " 576 dev_err(dev, "fan_div value %ld not supported. "
511 "Choose one of 1, 2, 4 or 8!\n", val); 577 "Choose one of 1, 2, 4 or 8!\n", val);
512 mutex_unlock(&data->update_lock); 578 mutex_unlock(&data->update_lock);
513 return -EINVAL; 579 return -EINVAL;
514 } 580 }
@@ -699,7 +765,7 @@ static struct platform_driver vt8231_driver = {
699 .remove = __devexit_p(vt8231_remove), 765 .remove = __devexit_p(vt8231_remove),
700}; 766};
701 767
702static const struct pci_device_id vt8231_pci_ids[] = { 768static DEFINE_PCI_DEVICE_TABLE(vt8231_pci_ids) = {
703 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4) }, 769 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4) },
704 { 0, } 770 { 0, }
705}; 771};
@@ -707,7 +773,7 @@ static const struct pci_device_id vt8231_pci_ids[] = {
707MODULE_DEVICE_TABLE(pci, vt8231_pci_ids); 773MODULE_DEVICE_TABLE(pci, vt8231_pci_ids);
708 774
709static int __devinit vt8231_pci_probe(struct pci_dev *dev, 775static int __devinit vt8231_pci_probe(struct pci_dev *dev,
710 const struct pci_device_id *id); 776 const struct pci_device_id *id);
711 777
712static struct pci_driver vt8231_pci_driver = { 778static struct pci_driver vt8231_pci_driver = {
713 .name = "vt8231", 779 .name = "vt8231",
@@ -730,7 +796,8 @@ static int vt8231_probe(struct platform_device *pdev)
730 return -ENODEV; 796 return -ENODEV;
731 } 797 }
732 798
733 if (!(data = kzalloc(sizeof(struct vt8231_data), GFP_KERNEL))) { 799 data = kzalloc(sizeof(struct vt8231_data), GFP_KERNEL);
800 if (!data) {
734 err = -ENOMEM; 801 err = -ENOMEM;
735 goto exit_release; 802 goto exit_release;
736 } 803 }
@@ -743,7 +810,8 @@ static int vt8231_probe(struct platform_device *pdev)
743 vt8231_init_device(data); 810 vt8231_init_device(data);
744 811
745 /* Register sysfs hooks */ 812 /* Register sysfs hooks */
746 if ((err = sysfs_create_group(&pdev->dev.kobj, &vt8231_group))) 813 err = sysfs_create_group(&pdev->dev.kobj, &vt8231_group);
814 if (err)
747 goto exit_free; 815 goto exit_free;
748 816
749 /* Must update device information to find out the config field */ 817 /* Must update device information to find out the config field */
@@ -751,16 +819,18 @@ static int vt8231_probe(struct platform_device *pdev)
751 819
752 for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++) { 820 for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++) {
753 if (ISTEMP(i, data->uch_config)) { 821 if (ISTEMP(i, data->uch_config)) {
754 if ((err = sysfs_create_group(&pdev->dev.kobj, 822 err = sysfs_create_group(&pdev->dev.kobj,
755 &vt8231_group_temps[i]))) 823 &vt8231_group_temps[i]);
824 if (err)
756 goto exit_remove_files; 825 goto exit_remove_files;
757 } 826 }
758 } 827 }
759 828
760 for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++) { 829 for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++) {
761 if (ISVOLT(i, data->uch_config)) { 830 if (ISVOLT(i, data->uch_config)) {
762 if ((err = sysfs_create_group(&pdev->dev.kobj, 831 err = sysfs_create_group(&pdev->dev.kobj,
763 &vt8231_group_volts[i]))) 832 &vt8231_group_volts[i]);
833 if (err)
764 goto exit_remove_files; 834 goto exit_remove_files;
765 } 835 }
766 } 836 }
@@ -866,17 +936,15 @@ static struct vt8231_data *vt8231_update_device(struct device *dev)
866 (vt8231_read_value(data, VT8231_REG_ALARM2) << 8); 936 (vt8231_read_value(data, VT8231_REG_ALARM2) << 8);
867 937
868 /* Set alarm flags correctly */ 938 /* Set alarm flags correctly */
869 if (!data->fan[0] && data->fan_min[0]) { 939 if (!data->fan[0] && data->fan_min[0])
870 data->alarms |= 0x40; 940 data->alarms |= 0x40;
871 } else if (data->fan[0] && !data->fan_min[0]) { 941 else if (data->fan[0] && !data->fan_min[0])
872 data->alarms &= ~0x40; 942 data->alarms &= ~0x40;
873 }
874 943
875 if (!data->fan[1] && data->fan_min[1]) { 944 if (!data->fan[1] && data->fan_min[1])
876 data->alarms |= 0x80; 945 data->alarms |= 0x80;
877 } else if (data->fan[1] && !data->fan_min[1]) { 946 else if (data->fan[1] && !data->fan_min[1])
878 data->alarms &= ~0x80; 947 data->alarms &= ~0x80;
879 }
880 948
881 data->last_updated = jiffies; 949 data->last_updated = jiffies;
882 data->valid = 1; 950 data->valid = 1;
@@ -971,13 +1039,16 @@ static int __devinit vt8231_pci_probe(struct pci_dev *dev,
971 if (vt8231_device_add(address)) 1039 if (vt8231_device_add(address))
972 goto exit_unregister; 1040 goto exit_unregister;
973 1041
974 /* Always return failure here. This is to allow other drivers to bind 1042 /*
1043 * Always return failure here. This is to allow other drivers to bind
975 * to this pci device. We don't really want to have control over the 1044 * to this pci device. We don't really want to have control over the
976 * pci device, we only wanted to read as few register values from it. 1045 * pci device, we only wanted to read as few register values from it.
977 */ 1046 */
978 1047
979 /* We do, however, mark ourselves as using the PCI device to stop it 1048 /*
980 getting unloaded. */ 1049 * We do, however, mark ourselves as using the PCI device to stop it
1050 * getting unloaded.
1051 */
981 s_bridge = pci_dev_get(dev); 1052 s_bridge = pci_dev_get(dev);
982 return -ENODEV; 1053 return -ENODEV;
983 1054
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index a658d62c5e10..a25350cf9554 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -1,50 +1,49 @@
1/* 1/*
2 w83627ehf - Driver for the hardware monitoring functionality of 2 * w83627ehf - Driver for the hardware monitoring functionality of
3 the Winbond W83627EHF Super-I/O chip 3 * the Winbond W83627EHF Super-I/O chip
4 Copyright (C) 2005-2011 Jean Delvare <khali@linux-fr.org> 4 * Copyright (C) 2005-2011 Jean Delvare <khali@linux-fr.org>
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 * Daniel J Blueman <daniel.blueman@gmail.com>
9 Copyright (C) 2010 Sheng-Yuan Huang (Nuvoton) (PS00) 9 * Copyright (C) 2010 Sheng-Yuan Huang (Nuvoton) (PS00)
10 10 *
11 Shamelessly ripped from the w83627hf driver 11 * Shamelessly ripped from the w83627hf driver
12 Copyright (C) 2003 Mark Studebaker 12 * Copyright (C) 2003 Mark Studebaker
13 13 *
14 Thanks to Leon Moonen, Steve Cliffe and Grant Coady for their help 14 * Thanks to Leon Moonen, Steve Cliffe and Grant Coady for their help
15 in testing and debugging this driver. 15 * in testing and debugging this driver.
16 16 *
17 This driver also supports the W83627EHG, which is the lead-free 17 * This driver also supports the W83627EHG, which is the lead-free
18 version of the W83627EHF. 18 * version of the W83627EHF.
19 19 *
20 This program is free software; you can redistribute it and/or modify 20 * This program is free software; you can redistribute it and/or modify
21 it under the terms of the GNU General Public License as published by 21 * it under the terms of the GNU General Public License as published by
22 the Free Software Foundation; either version 2 of the License, or 22 * the Free Software Foundation; either version 2 of the License, or
23 (at your option) any later version. 23 * (at your option) any later version.
24 24 *
25 This program is distributed in the hope that it will be useful, 25 * This program is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of 26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 GNU General Public License for more details. 28 * GNU General Public License for more details.
29 29 *
30 You should have received a copy of the GNU General Public License 30 * You should have received a copy of the GNU General Public License
31 along with this program; if not, write to the Free Software 31 * along with this program; if not, write to the Free Software
32 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 32 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 33 *
34 34 * Supports the following chips:
35 Supports the following chips: 35 *
36 36 * Chip #vin #fan #pwm #temp chip IDs man ID
37 Chip #vin #fan #pwm #temp chip IDs man ID 37 * w83627ehf 10 5 4 3 0x8850 0x88 0x5ca3
38 w83627ehf 10 5 4 3 0x8850 0x88 0x5ca3 38 * 0x8860 0xa1
39 0x8860 0xa1 39 * w83627dhg 9 5 4 3 0xa020 0xc1 0x5ca3
40 w83627dhg 9 5 4 3 0xa020 0xc1 0x5ca3 40 * w83627dhg-p 9 5 4 3 0xb070 0xc1 0x5ca3
41 w83627dhg-p 9 5 4 3 0xb070 0xc1 0x5ca3 41 * w83627uhg 8 2 2 3 0xa230 0xc1 0x5ca3
42 w83627uhg 8 2 2 3 0xa230 0xc1 0x5ca3 42 * w83667hg 9 5 3 3 0xa510 0xc1 0x5ca3
43 w83667hg 9 5 3 3 0xa510 0xc1 0x5ca3 43 * w83667hg-b 9 5 3 4 0xb350 0xc1 0x5ca3
44 w83667hg-b 9 5 3 4 0xb350 0xc1 0x5ca3 44 * nct6775f 9 4 3 9 0xb470 0xc1 0x5ca3
45 nct6775f 9 4 3 9 0xb470 0xc1 0x5ca3 45 * nct6776f 9 5 3 9 0xC330 0xc1 0x5ca3
46 nct6776f 9 5 3 9 0xC330 0xc1 0x5ca3 46 */
47*/
48 47
49#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 48#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
50 49
@@ -164,11 +163,13 @@ superio_exit(int ioreg)
164#define W83627EHF_REG_BANK 0x4E 163#define W83627EHF_REG_BANK 0x4E
165#define W83627EHF_REG_CONFIG 0x40 164#define W83627EHF_REG_CONFIG 0x40
166 165
167/* Not currently used: 166/*
167 * Not currently used:
168 * REG_MAN_ID has the value 0x5ca3 for all supported chips. 168 * REG_MAN_ID has the value 0x5ca3 for all supported chips.
169 * REG_CHIP_ID == 0x88/0xa1/0xc1 depending on chip model. 169 * REG_CHIP_ID == 0x88/0xa1/0xc1 depending on chip model.
170 * REG_MAN_ID is at port 0x4f 170 * REG_MAN_ID is at port 0x4f
171 * REG_CHIP_ID is at port 0x58 */ 171 * REG_CHIP_ID is at port 0x58
172 */
172 173
173static const u16 W83627EHF_REG_FAN[] = { 0x28, 0x29, 0x2a, 0x3f, 0x553 }; 174static const u16 W83627EHF_REG_FAN[] = { 0x28, 0x29, 0x2a, 0x3f, 0x553 };
174static const u16 W83627EHF_REG_FAN_MIN[] = { 0x3b, 0x3c, 0x3d, 0x3e, 0x55c }; 175static const u16 W83627EHF_REG_FAN_MIN[] = { 0x3b, 0x3c, 0x3d, 0x3e, 0x55c };
@@ -239,6 +240,8 @@ static const u16 W83627EHF_REG_FAN_MAX_OUTPUT_W83667_B[] = { 0x67, 0x69, 0x6b };
239static const u16 W83627EHF_REG_FAN_STEP_OUTPUT_W83667_B[] 240static const u16 W83627EHF_REG_FAN_STEP_OUTPUT_W83667_B[]
240 = { 0x68, 0x6a, 0x6c }; 241 = { 0x68, 0x6a, 0x6c };
241 242
243static const u16 W83627EHF_REG_TEMP_OFFSET[] = { 0x454, 0x455, 0x456 };
244
242static const u16 NCT6775_REG_TARGET[] = { 0x101, 0x201, 0x301 }; 245static const u16 NCT6775_REG_TARGET[] = { 0x101, 0x201, 0x301 };
243static const u16 NCT6775_REG_FAN_MODE[] = { 0x102, 0x202, 0x302 }; 246static const u16 NCT6775_REG_FAN_MODE[] = { 0x102, 0x202, 0x302 };
244static const u16 NCT6775_REG_FAN_STOP_OUTPUT[] = { 0x105, 0x205, 0x305 }; 247static const u16 NCT6775_REG_FAN_STOP_OUTPUT[] = { 0x105, 0x205, 0x305 };
@@ -393,8 +396,10 @@ div_from_reg(u8 reg)
393 return 1 << reg; 396 return 1 << reg;
394} 397}
395 398
396/* Some of the voltage inputs have internal scaling, the tables below 399/*
397 * contain 8 (the ADC LSB in mV) * scaling factor * 100 */ 400 * Some of the voltage inputs have internal scaling, the tables below
401 * contain 8 (the ADC LSB in mV) * scaling factor * 100
402 */
398static const u16 scale_in_common[10] = { 403static const u16 scale_in_common[10] = {
399 800, 800, 1600, 1600, 800, 800, 800, 1600, 1600, 800 404 800, 800, 1600, 1600, 800, 800, 800, 1600, 1600, 800
400}; 405};
@@ -462,6 +467,7 @@ struct w83627ehf_data {
462 u8 has_fan_min; /* some fans don't have min register */ 467 u8 has_fan_min; /* some fans don't have min register */
463 bool has_fan_div; 468 bool has_fan_div;
464 u8 temp_type[3]; 469 u8 temp_type[3];
470 s8 temp_offset[3];
465 s16 temp[9]; 471 s16 temp[9];
466 s16 temp_max[9]; 472 s16 temp_max[9];
467 s16 temp_max_hyst[9]; 473 s16 temp_max_hyst[9];
@@ -470,12 +476,13 @@ struct w83627ehf_data {
470 476
471 u8 pwm_mode[4]; /* 0->DC variable voltage, 1->PWM variable duty cycle */ 477 u8 pwm_mode[4]; /* 0->DC variable voltage, 1->PWM variable duty cycle */
472 u8 pwm_enable[4]; /* 1->manual 478 u8 pwm_enable[4]; /* 1->manual
473 2->thermal cruise mode (also called SmartFan I) 479 * 2->thermal cruise mode (also called SmartFan I)
474 3->fan speed cruise mode 480 * 3->fan speed cruise mode
475 4->variable thermal cruise (also called 481 * 4->variable thermal cruise (also called
476 SmartFan III) 482 * SmartFan III)
477 5->enhanced variable thermal cruise (also called 483 * 5->enhanced variable thermal cruise (also called
478 SmartFan IV) */ 484 * SmartFan IV)
485 */
479 u8 pwm_enable_orig[4]; /* original value of pwm_enable */ 486 u8 pwm_enable_orig[4]; /* original value of pwm_enable */
480 u8 pwm_num; /* number of pwm */ 487 u8 pwm_num; /* number of pwm */
481 u8 pwm[4]; 488 u8 pwm[4];
@@ -492,6 +499,7 @@ struct w83627ehf_data {
492 u8 vrm; 499 u8 vrm;
493 500
494 u16 have_temp; 501 u16 have_temp;
502 u16 have_temp_offset;
495 u8 in6_skip:1; 503 u8 in6_skip:1;
496 u8 temp3_val_only:1; 504 u8 temp3_val_only:1;
497}; 505};
@@ -816,9 +824,11 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
816 data->fan_min[i] = w83627ehf_read_value(data, 824 data->fan_min[i] = w83627ehf_read_value(data,
817 data->REG_FAN_MIN[i]); 825 data->REG_FAN_MIN[i]);
818 826
819 /* If we failed to measure the fan speed and clock 827 /*
820 divider can be increased, let's try that for next 828 * If we failed to measure the fan speed and clock
821 time */ 829 * divider can be increased, let's try that for next
830 * time
831 */
822 if (data->has_fan_div 832 if (data->has_fan_div
823 && (reg >= 0xff || (sio_data->kind == nct6775 833 && (reg >= 0xff || (sio_data->kind == nct6775
824 && reg == 0x00)) 834 && reg == 0x00))
@@ -887,6 +897,10 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
887 data->temp_max_hyst[i] 897 data->temp_max_hyst[i]
888 = w83627ehf_read_temp(data, 898 = w83627ehf_read_temp(data,
889 data->reg_temp_hyst[i]); 899 data->reg_temp_hyst[i]);
900 if (data->have_temp_offset & (1 << i))
901 data->temp_offset[i]
902 = w83627ehf_read_value(data,
903 W83627EHF_REG_TEMP_OFFSET[i]);
890 } 904 }
891 905
892 data->alarms = w83627ehf_read_value(data, 906 data->alarms = w83627ehf_read_value(data,
@@ -1081,25 +1095,31 @@ store_fan_min(struct device *dev, struct device_attribute *attr,
1081 new_div = data->fan_div[nr]; /* No change */ 1095 new_div = data->fan_div[nr]; /* No change */
1082 dev_info(dev, "fan%u low limit and alarm disabled\n", nr + 1); 1096 dev_info(dev, "fan%u low limit and alarm disabled\n", nr + 1);
1083 } else if ((reg = 1350000U / val) >= 128 * 255) { 1097 } else if ((reg = 1350000U / val) >= 128 * 255) {
1084 /* Speed below this value cannot possibly be represented, 1098 /*
1085 even with the highest divider (128) */ 1099 * Speed below this value cannot possibly be represented,
1100 * even with the highest divider (128)
1101 */
1086 data->fan_min[nr] = 254; 1102 data->fan_min[nr] = 254;
1087 new_div = 7; /* 128 == (1 << 7) */ 1103 new_div = 7; /* 128 == (1 << 7) */
1088 dev_warn(dev, "fan%u low limit %lu below minimum %u, set to " 1104 dev_warn(dev, "fan%u low limit %lu below minimum %u, set to "
1089 "minimum\n", nr + 1, val, 1105 "minimum\n", nr + 1, val,
1090 data->fan_from_reg_min(254, 7)); 1106 data->fan_from_reg_min(254, 7));
1091 } else if (!reg) { 1107 } else if (!reg) {
1092 /* Speed above this value cannot possibly be represented, 1108 /*
1093 even with the lowest divider (1) */ 1109 * Speed above this value cannot possibly be represented,
1110 * even with the lowest divider (1)
1111 */
1094 data->fan_min[nr] = 1; 1112 data->fan_min[nr] = 1;
1095 new_div = 0; /* 1 == (1 << 0) */ 1113 new_div = 0; /* 1 == (1 << 0) */
1096 dev_warn(dev, "fan%u low limit %lu above maximum %u, set to " 1114 dev_warn(dev, "fan%u low limit %lu above maximum %u, set to "
1097 "maximum\n", nr + 1, val, 1115 "maximum\n", nr + 1, val,
1098 data->fan_from_reg_min(1, 0)); 1116 data->fan_from_reg_min(1, 0));
1099 } else { 1117 } else {
1100 /* Automatically pick the best divider, i.e. the one such 1118 /*
1101 that the min limit will correspond to a register value 1119 * Automatically pick the best divider, i.e. the one such
1102 in the 96..192 range */ 1120 * that the min limit will correspond to a register value
1121 * in the 96..192 range
1122 */
1103 new_div = 0; 1123 new_div = 0;
1104 while (reg > 192 && new_div < 7) { 1124 while (reg > 192 && new_div < 7) {
1105 reg >>= 1; 1125 reg >>= 1;
@@ -1108,8 +1128,10 @@ store_fan_min(struct device *dev, struct device_attribute *attr,
1108 data->fan_min[nr] = reg; 1128 data->fan_min[nr] = reg;
1109 } 1129 }
1110 1130
1111 /* Write both the fan clock divider (if it changed) and the new 1131 /*
1112 fan min (unconditionally) */ 1132 * Write both the fan clock divider (if it changed) and the new
1133 * fan min (unconditionally)
1134 */
1113 if (new_div != data->fan_div[nr]) { 1135 if (new_div != data->fan_div[nr]) {
1114 dev_dbg(dev, "fan%u clock divider changed from %u to %u\n", 1136 dev_dbg(dev, "fan%u clock divider changed from %u to %u\n",
1115 nr + 1, div_from_reg(data->fan_div[nr]), 1137 nr + 1, div_from_reg(data->fan_div[nr]),
@@ -1212,6 +1234,39 @@ store_temp_reg(reg_temp_over, temp_max);
1212store_temp_reg(reg_temp_hyst, temp_max_hyst); 1234store_temp_reg(reg_temp_hyst, temp_max_hyst);
1213 1235
1214static ssize_t 1236static ssize_t
1237show_temp_offset(struct device *dev, struct device_attribute *attr, char *buf)
1238{
1239 struct w83627ehf_data *data = w83627ehf_update_device(dev);
1240 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1241
1242 return sprintf(buf, "%d\n",
1243 data->temp_offset[sensor_attr->index] * 1000);
1244}
1245
1246static ssize_t
1247store_temp_offset(struct device *dev, struct device_attribute *attr,
1248 const char *buf, size_t count)
1249{
1250 struct w83627ehf_data *data = dev_get_drvdata(dev);
1251 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1252 int nr = sensor_attr->index;
1253 long val;
1254 int err;
1255
1256 err = kstrtol(buf, 10, &val);
1257 if (err < 0)
1258 return err;
1259
1260 val = SENSORS_LIMIT(DIV_ROUND_CLOSEST(val, 1000), -128, 127);
1261
1262 mutex_lock(&data->update_lock);
1263 data->temp_offset[nr] = val;
1264 w83627ehf_write_value(data, W83627EHF_REG_TEMP_OFFSET[nr], val);
1265 mutex_unlock(&data->update_lock);
1266 return count;
1267}
1268
1269static ssize_t
1215show_temp_type(struct device *dev, struct device_attribute *attr, char *buf) 1270show_temp_type(struct device *dev, struct device_attribute *attr, char *buf)
1216{ 1271{
1217 struct w83627ehf_data *data = w83627ehf_update_device(dev); 1272 struct w83627ehf_data *data = w83627ehf_update_device(dev);
@@ -1298,6 +1353,15 @@ static struct sensor_device_attribute sda_temp_type[] = {
1298 SENSOR_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2), 1353 SENSOR_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2),
1299}; 1354};
1300 1355
1356static struct sensor_device_attribute sda_temp_offset[] = {
1357 SENSOR_ATTR(temp1_offset, S_IRUGO | S_IWUSR, show_temp_offset,
1358 store_temp_offset, 0),
1359 SENSOR_ATTR(temp2_offset, S_IRUGO | S_IWUSR, show_temp_offset,
1360 store_temp_offset, 1),
1361 SENSOR_ATTR(temp3_offset, S_IRUGO | S_IWUSR, show_temp_offset,
1362 store_temp_offset, 2),
1363};
1364
1301#define show_pwm_reg(reg) \ 1365#define show_pwm_reg(reg) \
1302static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ 1366static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
1303 char *buf) \ 1367 char *buf) \
@@ -1736,8 +1800,10 @@ static struct sensor_device_attribute_2 sda_caseopen[] = {
1736 1800
1737static void w83627ehf_device_remove_files(struct device *dev) 1801static void w83627ehf_device_remove_files(struct device *dev)
1738{ 1802{
1739 /* some entries in the following arrays may not have been used in 1803 /*
1740 * device_create_file(), but device_remove_file() will ignore them */ 1804 * some entries in the following arrays may not have been used in
1805 * device_create_file(), but device_remove_file() will ignore them
1806 */
1741 int i; 1807 int i;
1742 struct w83627ehf_data *data = dev_get_drvdata(dev); 1808 struct w83627ehf_data *data = dev_get_drvdata(dev);
1743 1809
@@ -1788,6 +1854,7 @@ static void w83627ehf_device_remove_files(struct device *dev)
1788 continue; 1854 continue;
1789 device_remove_file(dev, &sda_temp_alarm[i].dev_attr); 1855 device_remove_file(dev, &sda_temp_alarm[i].dev_attr);
1790 device_remove_file(dev, &sda_temp_type[i].dev_attr); 1856 device_remove_file(dev, &sda_temp_type[i].dev_attr);
1857 device_remove_file(dev, &sda_temp_offset[i].dev_attr);
1791 } 1858 }
1792 1859
1793 device_remove_file(dev, &sda_caseopen[0].dev_attr); 1860 device_remove_file(dev, &sda_caseopen[0].dev_attr);
@@ -2110,6 +2177,11 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
2110 } else { 2177 } else {
2111 data->temp_label = nct6775_temp_label; 2178 data->temp_label = nct6775_temp_label;
2112 } 2179 }
2180 data->have_temp_offset = data->have_temp & 0x07;
2181 for (i = 0; i < 3; i++) {
2182 if (data->temp_src[i] > 3)
2183 data->have_temp_offset &= ~(1 << i);
2184 }
2113 } else if (sio_data->kind == w83667hg_b) { 2185 } else if (sio_data->kind == w83667hg_b) {
2114 u8 reg; 2186 u8 reg;
2115 2187
@@ -2152,6 +2224,11 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
2152 data->in6_skip = 1; 2224 data->in6_skip = 1;
2153 2225
2154 data->temp_label = w83667hg_b_temp_label; 2226 data->temp_label = w83667hg_b_temp_label;
2227 data->have_temp_offset = data->have_temp & 0x07;
2228 for (i = 0; i < 3; i++) {
2229 if (data->temp_src[i] > 2)
2230 data->have_temp_offset &= ~(1 << i);
2231 }
2155 } else if (sio_data->kind == w83627uhg) { 2232 } else if (sio_data->kind == w83627uhg) {
2156 u8 reg; 2233 u8 reg;
2157 2234
@@ -2188,6 +2265,11 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
2188 data->in6_skip = 1; /* No VIN3 */ 2265 data->in6_skip = 1; /* No VIN3 */
2189 2266
2190 data->temp_label = w83667hg_b_temp_label; 2267 data->temp_label = w83667hg_b_temp_label;
2268 data->have_temp_offset = data->have_temp & 0x03;
2269 for (i = 0; i < 3; i++) {
2270 if (data->temp_src[i] > 1)
2271 data->have_temp_offset &= ~(1 << i);
2272 }
2191 } else { 2273 } else {
2192 w83627ehf_set_temp_reg_ehf(data, 3); 2274 w83627ehf_set_temp_reg_ehf(data, 3);
2193 2275
@@ -2207,6 +2289,7 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
2207 else 2289 else
2208 data->in6_skip = 1; 2290 data->in6_skip = 1;
2209 } 2291 }
2292 data->have_temp_offset = data->have_temp & 0x07;
2210 } 2293 }
2211 2294
2212 if (sio_data->kind == nct6775) { 2295 if (sio_data->kind == nct6775) {
@@ -2279,9 +2362,11 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
2279 /* Read VID value */ 2362 /* Read VID value */
2280 if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b || 2363 if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b ||
2281 sio_data->kind == nct6775 || sio_data->kind == nct6776) { 2364 sio_data->kind == nct6775 || sio_data->kind == nct6776) {
2282 /* W83667HG has different pins for VID input and output, so 2365 /*
2283 we can get the VID input values directly at logical device D 2366 * W83667HG has different pins for VID input and output, so
2284 0xe3. */ 2367 * we can get the VID input values directly at logical device D
2368 * 0xe3.
2369 */
2285 superio_select(sio_data->sioreg, W83667HG_LD_VID); 2370 superio_select(sio_data->sioreg, W83667HG_LD_VID);
2286 data->vid = superio_inb(sio_data->sioreg, 0xe3); 2371 data->vid = superio_inb(sio_data->sioreg, 0xe3);
2287 err = device_create_file(dev, &dev_attr_cpu0_vid); 2372 err = device_create_file(dev, &dev_attr_cpu0_vid);
@@ -2290,11 +2375,13 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
2290 } else if (sio_data->kind != w83627uhg) { 2375 } else if (sio_data->kind != w83627uhg) {
2291 superio_select(sio_data->sioreg, W83627EHF_LD_HWM); 2376 superio_select(sio_data->sioreg, W83627EHF_LD_HWM);
2292 if (superio_inb(sio_data->sioreg, SIO_REG_VID_CTRL) & 0x80) { 2377 if (superio_inb(sio_data->sioreg, SIO_REG_VID_CTRL) & 0x80) {
2293 /* Set VID input sensibility if needed. In theory the 2378 /*
2294 BIOS should have set it, but in practice it's not 2379 * Set VID input sensibility if needed. In theory the
2295 always the case. We only do it for the W83627EHF/EHG 2380 * BIOS should have set it, but in practice it's not
2296 because the W83627DHG is more complex in this 2381 * always the case. We only do it for the W83627EHF/EHG
2297 respect. */ 2382 * because the W83627DHG is more complex in this
2383 * respect.
2384 */
2298 if (sio_data->kind == w83627ehf) { 2385 if (sio_data->kind == w83627ehf) {
2299 en_vrm10 = superio_inb(sio_data->sioreg, 2386 en_vrm10 = superio_inb(sio_data->sioreg,
2300 SIO_REG_EN_VRM10); 2387 SIO_REG_EN_VRM10);
@@ -2468,6 +2555,12 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
2468 || (err = device_create_file(dev, 2555 || (err = device_create_file(dev,
2469 &sda_temp_type[i].dev_attr))) 2556 &sda_temp_type[i].dev_attr)))
2470 goto exit_remove; 2557 goto exit_remove;
2558 if (data->have_temp_offset & (1 << i)) {
2559 err = device_create_file(dev,
2560 &sda_temp_offset[i].dev_attr);
2561 if (err)
2562 goto exit_remove;
2563 }
2471 } 2564 }
2472 2565
2473 err = device_create_file(dev, &sda_caseopen[0].dev_attr); 2566 err = device_create_file(dev, &sda_caseopen[0].dev_attr);
@@ -2616,10 +2709,12 @@ static int __init w83627ehf_find(int sioaddr, unsigned short *addr,
2616 return 0; 2709 return 0;
2617} 2710}
2618 2711
2619/* when Super-I/O functions move to a separate file, the Super-I/O 2712/*
2713 * when Super-I/O functions move to a separate file, the Super-I/O
2620 * bus will manage the lifetime of the device and this module will only keep 2714 * bus will manage the lifetime of the device and this module will only keep
2621 * track of the w83627ehf driver. But since we platform_device_alloc(), we 2715 * track of the w83627ehf driver. But since we platform_device_alloc(), we
2622 * must keep track of the device */ 2716 * must keep track of the device
2717 */
2623static struct platform_device *pdev; 2718static struct platform_device *pdev;
2624 2719
2625static int __init sensors_w83627ehf_init(void) 2720static int __init sensors_w83627ehf_init(void)
@@ -2629,11 +2724,13 @@ static int __init sensors_w83627ehf_init(void)
2629 struct resource res; 2724 struct resource res;
2630 struct w83627ehf_sio_data sio_data; 2725 struct w83627ehf_sio_data sio_data;
2631 2726
2632 /* initialize sio_data->kind and sio_data->sioreg. 2727 /*
2728 * initialize sio_data->kind and sio_data->sioreg.
2633 * 2729 *
2634 * when Super-I/O functions move to a separate file, the Super-I/O 2730 * when Super-I/O functions move to a separate file, the Super-I/O
2635 * driver will probe 0x2e and 0x4e and auto-detect the presence of a 2731 * driver will probe 0x2e and 0x4e and auto-detect the presence of a
2636 * w83627ehf hardware monitor, and call probe() */ 2732 * w83627ehf hardware monitor, and call probe()
2733 */
2637 if (w83627ehf_find(0x2e, &address, &sio_data) && 2734 if (w83627ehf_find(0x2e, &address, &sio_data) &&
2638 w83627ehf_find(0x4e, &address, &sio_data)) 2735 w83627ehf_find(0x4e, &address, &sio_data))
2639 return -ENODEV; 2736 return -ENODEV;
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c
index 374118f2b9f9..5ce54a297249 100644
--- a/drivers/hwmon/w83627hf.c
+++ b/drivers/hwmon/w83627hf.c
@@ -1,43 +1,43 @@
1/* 1/*
2 w83627hf.c - Part of lm_sensors, Linux kernel modules for hardware 2 * w83627hf.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 * monitoring
4 Copyright (c) 1998 - 2003 Frodo Looijaard <frodol@dds.nl>, 4 * Copyright (c) 1998 - 2003 Frodo Looijaard <frodol@dds.nl>,
5 Philip Edelbrock <phil@netroedge.com>, 5 * Philip Edelbrock <phil@netroedge.com>,
6 and Mark Studebaker <mdsxyz123@yahoo.com> 6 * and Mark Studebaker <mdsxyz123@yahoo.com>
7 Ported to 2.6 by Bernhard C. Schrenk <clemy@clemy.org> 7 * Ported to 2.6 by Bernhard C. Schrenk <clemy@clemy.org>
8 Copyright (c) 2007 Jean Delvare <khali@linux-fr.org> 8 * Copyright (c) 2007 Jean Delvare <khali@linux-fr.org>
9 9 *
10 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
11 it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or 12 * the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version. 13 * (at your option) any later version.
14 14 *
15 This program is distributed in the hope that it will be useful, 15 * This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details. 18 * GNU General Public License for more details.
19 19 *
20 You should have received a copy of the GNU General Public License 20 * You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software 21 * along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23*/ 23 */
24 24
25/* 25/*
26 Supports following chips: 26 * Supports following chips:
27 27 *
28 Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA 28 * Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
29 w83627hf 9 3 2 3 0x20 0x5ca3 no yes(LPC) 29 * w83627hf 9 3 2 3 0x20 0x5ca3 no yes(LPC)
30 w83627thf 7 3 3 3 0x90 0x5ca3 no yes(LPC) 30 * w83627thf 7 3 3 3 0x90 0x5ca3 no yes(LPC)
31 w83637hf 7 3 3 3 0x80 0x5ca3 no yes(LPC) 31 * w83637hf 7 3 3 3 0x80 0x5ca3 no yes(LPC)
32 w83687thf 7 3 3 3 0x90 0x5ca3 no yes(LPC) 32 * w83687thf 7 3 3 3 0x90 0x5ca3 no yes(LPC)
33 w83697hf 8 2 2 2 0x60 0x5ca3 no yes(LPC) 33 * w83697hf 8 2 2 2 0x60 0x5ca3 no yes(LPC)
34 34 *
35 For other winbond chips, and for i2c support in the above chips, 35 * For other winbond chips, and for i2c support in the above chips,
36 use w83781d.c. 36 * use w83781d.c.
37 37 *
38 Note: automatic ("cruise") fan control for 697, 637 & 627thf not 38 * Note: automatic ("cruise") fan control for 697, 637 & 627thf not
39 supported yet. 39 * supported yet.
40*/ 40 */
41 41
42#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 42#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
43 43
@@ -80,7 +80,7 @@ module_param(force_id, ushort, 0);
80MODULE_PARM_DESC(force_id, "Override the detected device ID"); 80MODULE_PARM_DESC(force_id, "Override the detected device ID");
81 81
82/* modified from kernel/include/traps.c */ 82/* modified from kernel/include/traps.c */
83#define DEV 0x07 /* Register: Logical device select */ 83#define DEV 0x07 /* Register: Logical device select */
84 84
85/* logical device numbers for superio_select (below) */ 85/* logical device numbers for superio_select (below) */
86#define W83627HF_LD_FDC 0x00 86#define W83627HF_LD_FDC 0x00
@@ -99,7 +99,7 @@ MODULE_PARM_DESC(force_id, "Override the detected device ID");
99#define W83627HF_LD_ACPI 0x0a 99#define W83627HF_LD_ACPI 0x0a
100#define W83627HF_LD_HWM 0x0b 100#define W83627HF_LD_HWM 0x0b
101 101
102#define DEVID 0x20 /* Register: Device ID */ 102#define DEVID 0x20 /* Register: Device ID */
103 103
104#define W83627THF_GPIO5_EN 0x30 /* w83627thf only */ 104#define W83627THF_GPIO5_EN 0x30 /* w83627thf only */
105#define W83627THF_GPIO5_IOSR 0xf3 /* w83627thf only */ 105#define W83627THF_GPIO5_IOSR 0xf3 /* w83627thf only */
@@ -248,10 +248,12 @@ static const u8 BIT_SCFG1[] = { 0x02, 0x04, 0x08 };
248static const u8 BIT_SCFG2[] = { 0x10, 0x20, 0x40 }; 248static const u8 BIT_SCFG2[] = { 0x10, 0x20, 0x40 };
249#define W83781D_DEFAULT_BETA 3435 249#define W83781D_DEFAULT_BETA 3435
250 250
251/* Conversions. Limit checking is only done on the TO_REG 251/*
252 variants. Note that you should be a bit careful with which arguments 252 * Conversions. Limit checking is only done on the TO_REG
253 these macros are called: arguments may be evaluated more than once. 253 * variants. Note that you should be a bit careful with which arguments
254 Fixing this is just not worth it. */ 254 * these macros are called: arguments may be evaluated more than once.
255 * Fixing this is just not worth it.
256 */
255#define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255)) 257#define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255))
256#define IN_FROM_REG(val) ((val) * 16) 258#define IN_FROM_REG(val) ((val) * 16)
257 259
@@ -267,8 +269,10 @@ static inline u8 FAN_TO_REG(long rpm, int div)
267#define TEMP_MIN (-128000) 269#define TEMP_MIN (-128000)
268#define TEMP_MAX ( 127000) 270#define TEMP_MAX ( 127000)
269 271
270/* TEMP: 0.001C/bit (-128C to +127C) 272/*
271 REG: 1C/bit, two's complement */ 273 * TEMP: 0.001C/bit (-128C to +127C)
274 * REG: 1C/bit, two's complement
275 */
272static u8 TEMP_TO_REG(long temp) 276static u8 TEMP_TO_REG(long temp)
273{ 277{
274 int ntemp = SENSORS_LIMIT(temp, TEMP_MIN, TEMP_MAX); 278 int ntemp = SENSORS_LIMIT(temp, TEMP_MIN, TEMP_MAX);
@@ -294,8 +298,10 @@ static inline unsigned long pwm_freq_from_reg_627hf(u8 reg)
294static inline u8 pwm_freq_to_reg_627hf(unsigned long val) 298static inline u8 pwm_freq_to_reg_627hf(unsigned long val)
295{ 299{
296 u8 i; 300 u8 i;
297 /* Only 5 dividers (1 2 4 8 16) 301 /*
298 Search for the nearest available frequency */ 302 * Only 5 dividers (1 2 4 8 16)
303 * Search for the nearest available frequency
304 */
299 for (i = 0; i < 4; i++) { 305 for (i = 0; i < 4; i++) {
300 if (val > (((W83627HF_BASE_PWM_FREQ >> i) + 306 if (val > (((W83627HF_BASE_PWM_FREQ >> i) +
301 (W83627HF_BASE_PWM_FREQ >> (i+1))) / 2)) 307 (W83627HF_BASE_PWM_FREQ >> (i+1))) / 2))
@@ -313,7 +319,7 @@ static inline unsigned long pwm_freq_from_reg(u8 reg)
313 /* This should not happen but anyway... */ 319 /* This should not happen but anyway... */
314 if (reg == 0) 320 if (reg == 0)
315 reg++; 321 reg++;
316 return (clock / (reg << 8)); 322 return clock / (reg << 8);
317} 323}
318static inline u8 pwm_freq_to_reg(unsigned long val) 324static inline u8 pwm_freq_to_reg(unsigned long val)
319{ 325{
@@ -321,11 +327,11 @@ static inline u8 pwm_freq_to_reg(unsigned long val)
321 if (val >= 93750) /* The highest we can do */ 327 if (val >= 93750) /* The highest we can do */
322 return 0x01; 328 return 0x01;
323 if (val >= 720) /* Use 24 MHz clock */ 329 if (val >= 720) /* Use 24 MHz clock */
324 return (24000000UL / (val << 8)); 330 return 24000000UL / (val << 8);
325 if (val < 6) /* The lowest we can do */ 331 if (val < 6) /* The lowest we can do */
326 return 0xFF; 332 return 0xFF;
327 else /* Use 180 kHz clock */ 333 else /* Use 180 kHz clock */
328 return (0x80 | (180000UL / (val << 8))); 334 return 0x80 | (180000UL / (val << 8));
329} 335}
330 336
331#define BEEP_MASK_FROM_REG(val) ((val) & 0xff7fff) 337#define BEEP_MASK_FROM_REG(val) ((val) & 0xff7fff)
@@ -342,11 +348,13 @@ static inline u8 DIV_TO_REG(long val)
342 break; 348 break;
343 val >>= 1; 349 val >>= 1;
344 } 350 }
345 return ((u8) i); 351 return (u8)i;
346} 352}
347 353
348/* For each registered chip, we need to keep some data in memory. 354/*
349 The structure is dynamically allocated. */ 355 * For each registered chip, we need to keep some data in memory.
356 * The structure is dynamically allocated.
357 */
350struct w83627hf_data { 358struct w83627hf_data {
351 unsigned short addr; 359 unsigned short addr;
352 const char *name; 360 const char *name;
@@ -372,11 +380,13 @@ struct w83627hf_data {
372 u32 beep_mask; /* Register encoding, combined */ 380 u32 beep_mask; /* Register encoding, combined */
373 u8 pwm[3]; /* Register value */ 381 u8 pwm[3]; /* Register value */
374 u8 pwm_enable[3]; /* 1 = manual 382 u8 pwm_enable[3]; /* 1 = manual
375 2 = thermal cruise (also called SmartFan I) 383 * 2 = thermal cruise (also called SmartFan I)
376 3 = fan speed cruise */ 384 * 3 = fan speed cruise
385 */
377 u8 pwm_freq[3]; /* Register value */ 386 u8 pwm_freq[3]; /* Register value */
378 u16 sens[3]; /* 1 = pentium diode; 2 = 3904 diode; 387 u16 sens[3]; /* 1 = pentium diode; 2 = 3904 diode;
379 4 = thermistor */ 388 * 4 = thermistor
389 */
380 u8 vrm; 390 u8 vrm;
381 u8 vrm_ovt; /* Register value, 627THF/637HF/687THF only */ 391 u8 vrm_ovt; /* Register value, 627THF/637HF/687THF only */
382}; 392};
@@ -427,7 +437,12 @@ store_in_min(struct device *dev, struct device_attribute *devattr,
427{ 437{
428 int nr = to_sensor_dev_attr(devattr)->index; 438 int nr = to_sensor_dev_attr(devattr)->index;
429 struct w83627hf_data *data = dev_get_drvdata(dev); 439 struct w83627hf_data *data = dev_get_drvdata(dev);
430 long val = simple_strtol(buf, NULL, 10); 440 long val;
441 int err;
442
443 err = kstrtol(buf, 10, &val);
444 if (err)
445 return err;
431 446
432 mutex_lock(&data->update_lock); 447 mutex_lock(&data->update_lock);
433 data->in_min[nr] = IN_TO_REG(val); 448 data->in_min[nr] = IN_TO_REG(val);
@@ -441,7 +456,12 @@ store_in_max(struct device *dev, struct device_attribute *devattr,
441{ 456{
442 int nr = to_sensor_dev_attr(devattr)->index; 457 int nr = to_sensor_dev_attr(devattr)->index;
443 struct w83627hf_data *data = dev_get_drvdata(dev); 458 struct w83627hf_data *data = dev_get_drvdata(dev);
444 long val = simple_strtol(buf, NULL, 10); 459 long val;
460 int err;
461
462 err = kstrtol(buf, 10, &val);
463 if (err)
464 return err;
445 465
446 mutex_lock(&data->update_lock); 466 mutex_lock(&data->update_lock);
447 data->in_max[nr] = IN_TO_REG(val); 467 data->in_max[nr] = IN_TO_REG(val);
@@ -506,9 +526,12 @@ static ssize_t store_regs_in_min0(struct device *dev, struct device_attribute *a
506 const char *buf, size_t count) 526 const char *buf, size_t count)
507{ 527{
508 struct w83627hf_data *data = dev_get_drvdata(dev); 528 struct w83627hf_data *data = dev_get_drvdata(dev);
509 u32 val; 529 unsigned long val;
530 int err;
510 531
511 val = simple_strtoul(buf, NULL, 10); 532 err = kstrtoul(buf, 10, &val);
533 if (err)
534 return err;
512 535
513 mutex_lock(&data->update_lock); 536 mutex_lock(&data->update_lock);
514 537
@@ -533,9 +556,12 @@ static ssize_t store_regs_in_max0(struct device *dev, struct device_attribute *a
533 const char *buf, size_t count) 556 const char *buf, size_t count)
534{ 557{
535 struct w83627hf_data *data = dev_get_drvdata(dev); 558 struct w83627hf_data *data = dev_get_drvdata(dev);
536 u32 val; 559 unsigned long val;
560 int err;
537 561
538 val = simple_strtoul(buf, NULL, 10); 562 err = kstrtoul(buf, 10, &val);
563 if (err)
564 return err;
539 565
540 mutex_lock(&data->update_lock); 566 mutex_lock(&data->update_lock);
541 567
@@ -584,7 +610,12 @@ store_fan_min(struct device *dev, struct device_attribute *devattr,
584{ 610{
585 int nr = to_sensor_dev_attr(devattr)->index; 611 int nr = to_sensor_dev_attr(devattr)->index;
586 struct w83627hf_data *data = dev_get_drvdata(dev); 612 struct w83627hf_data *data = dev_get_drvdata(dev);
587 u32 val = simple_strtoul(buf, NULL, 10); 613 unsigned long val;
614 int err;
615
616 err = kstrtoul(buf, 10, &val);
617 if (err)
618 return err;
588 619
589 mutex_lock(&data->update_lock); 620 mutex_lock(&data->update_lock);
590 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 621 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
@@ -645,9 +676,15 @@ store_temp_max(struct device *dev, struct device_attribute *devattr,
645{ 676{
646 int nr = to_sensor_dev_attr(devattr)->index; 677 int nr = to_sensor_dev_attr(devattr)->index;
647 struct w83627hf_data *data = dev_get_drvdata(dev); 678 struct w83627hf_data *data = dev_get_drvdata(dev);
648 long val = simple_strtol(buf, NULL, 10); 679 u16 tmp;
649 u16 tmp = (nr) ? LM75_TEMP_TO_REG(val) : TEMP_TO_REG(val); 680 long val;
681 int err;
650 682
683 err = kstrtol(buf, 10, &val);
684 if (err)
685 return err;
686
687 tmp = (nr) ? LM75_TEMP_TO_REG(val) : TEMP_TO_REG(val);
651 mutex_lock(&data->update_lock); 688 mutex_lock(&data->update_lock);
652 data->temp_max[nr] = tmp; 689 data->temp_max[nr] = tmp;
653 w83627hf_write_value(data, w83627hf_reg_temp_over[nr], tmp); 690 w83627hf_write_value(data, w83627hf_reg_temp_over[nr], tmp);
@@ -661,9 +698,15 @@ store_temp_max_hyst(struct device *dev, struct device_attribute *devattr,
661{ 698{
662 int nr = to_sensor_dev_attr(devattr)->index; 699 int nr = to_sensor_dev_attr(devattr)->index;
663 struct w83627hf_data *data = dev_get_drvdata(dev); 700 struct w83627hf_data *data = dev_get_drvdata(dev);
664 long val = simple_strtol(buf, NULL, 10); 701 u16 tmp;
665 u16 tmp = (nr) ? LM75_TEMP_TO_REG(val) : TEMP_TO_REG(val); 702 long val;
703 int err;
704
705 err = kstrtol(buf, 10, &val);
706 if (err)
707 return err;
666 708
709 tmp = (nr) ? LM75_TEMP_TO_REG(val) : TEMP_TO_REG(val);
667 mutex_lock(&data->update_lock); 710 mutex_lock(&data->update_lock);
668 data->temp_max_hyst[nr] = tmp; 711 data->temp_max_hyst[nr] = tmp;
669 w83627hf_write_value(data, w83627hf_reg_temp_hyst[nr], tmp); 712 w83627hf_write_value(data, w83627hf_reg_temp_hyst[nr], tmp);
@@ -701,9 +744,12 @@ static ssize_t
701store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 744store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
702{ 745{
703 struct w83627hf_data *data = dev_get_drvdata(dev); 746 struct w83627hf_data *data = dev_get_drvdata(dev);
704 u32 val; 747 unsigned long val;
748 int err;
705 749
706 val = simple_strtoul(buf, NULL, 10); 750 err = kstrtoul(buf, 10, &val);
751 if (err)
752 return err;
707 data->vrm = val; 753 data->vrm = val;
708 754
709 return count; 755 return count;
@@ -755,8 +801,11 @@ store_beep_mask(struct device *dev, struct device_attribute *attr,
755{ 801{
756 struct w83627hf_data *data = dev_get_drvdata(dev); 802 struct w83627hf_data *data = dev_get_drvdata(dev);
757 unsigned long val; 803 unsigned long val;
804 int err;
758 805
759 val = simple_strtoul(buf, NULL, 10); 806 err = kstrtoul(buf, 10, &val);
807 if (err)
808 return err;
760 809
761 mutex_lock(&data->update_lock); 810 mutex_lock(&data->update_lock);
762 811
@@ -791,10 +840,14 @@ store_beep(struct device *dev, struct device_attribute *attr,
791{ 840{
792 struct w83627hf_data *data = dev_get_drvdata(dev); 841 struct w83627hf_data *data = dev_get_drvdata(dev);
793 int bitnr = to_sensor_dev_attr(attr)->index; 842 int bitnr = to_sensor_dev_attr(attr)->index;
794 unsigned long bit;
795 u8 reg; 843 u8 reg;
844 unsigned long bit;
845 int err;
846
847 err = kstrtoul(buf, 10, &bit);
848 if (err)
849 return err;
796 850
797 bit = simple_strtoul(buf, NULL, 10);
798 if (bit & ~1) 851 if (bit & ~1)
799 return -EINVAL; 852 return -EINVAL;
800 853
@@ -872,10 +925,12 @@ show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf)
872 return sprintf(buf, "%ld\n", 925 return sprintf(buf, "%ld\n",
873 (long) DIV_FROM_REG(data->fan_div[nr])); 926 (long) DIV_FROM_REG(data->fan_div[nr]));
874} 927}
875/* Note: we save and restore the fan minimum here, because its value is 928/*
876 determined in part by the fan divisor. This follows the principle of 929 * Note: we save and restore the fan minimum here, because its value is
877 least surprise; the user doesn't expect the fan minimum to change just 930 * determined in part by the fan divisor. This follows the principle of
878 because the divisor changed. */ 931 * least surprise; the user doesn't expect the fan minimum to change just
932 * because the divisor changed.
933 */
879static ssize_t 934static ssize_t
880store_fan_div(struct device *dev, struct device_attribute *devattr, 935store_fan_div(struct device *dev, struct device_attribute *devattr,
881 const char *buf, size_t count) 936 const char *buf, size_t count)
@@ -884,7 +939,12 @@ store_fan_div(struct device *dev, struct device_attribute *devattr,
884 struct w83627hf_data *data = dev_get_drvdata(dev); 939 struct w83627hf_data *data = dev_get_drvdata(dev);
885 unsigned long min; 940 unsigned long min;
886 u8 reg; 941 u8 reg;
887 unsigned long val = simple_strtoul(buf, NULL, 10); 942 unsigned long val;
943 int err;
944
945 err = kstrtoul(buf, 10, &val);
946 if (err)
947 return err;
888 948
889 mutex_lock(&data->update_lock); 949 mutex_lock(&data->update_lock);
890 950
@@ -933,7 +993,12 @@ store_pwm(struct device *dev, struct device_attribute *devattr,
933{ 993{
934 int nr = to_sensor_dev_attr(devattr)->index; 994 int nr = to_sensor_dev_attr(devattr)->index;
935 struct w83627hf_data *data = dev_get_drvdata(dev); 995 struct w83627hf_data *data = dev_get_drvdata(dev);
936 u32 val = simple_strtoul(buf, NULL, 10); 996 unsigned long val;
997 int err;
998
999 err = kstrtoul(buf, 10, &val);
1000 if (err)
1001 return err;
937 1002
938 mutex_lock(&data->update_lock); 1003 mutex_lock(&data->update_lock);
939 1004
@@ -974,10 +1039,15 @@ store_pwm_enable(struct device *dev, struct device_attribute *devattr,
974{ 1039{
975 int nr = to_sensor_dev_attr(devattr)->index; 1040 int nr = to_sensor_dev_attr(devattr)->index;
976 struct w83627hf_data *data = dev_get_drvdata(dev); 1041 struct w83627hf_data *data = dev_get_drvdata(dev);
977 unsigned long val = simple_strtoul(buf, NULL, 10);
978 u8 reg; 1042 u8 reg;
1043 unsigned long val;
1044 int err;
1045
1046 err = kstrtoul(buf, 10, &val);
1047 if (err)
1048 return err;
979 1049
980 if (!val || (val > 3)) /* modes 1, 2 and 3 are supported */ 1050 if (!val || val > 3) /* modes 1, 2 and 3 are supported */
981 return -EINVAL; 1051 return -EINVAL;
982 mutex_lock(&data->update_lock); 1052 mutex_lock(&data->update_lock);
983 data->pwm_enable[nr] = val; 1053 data->pwm_enable[nr] = val;
@@ -1016,9 +1086,12 @@ store_pwm_freq(struct device *dev, struct device_attribute *devattr,
1016 int nr = to_sensor_dev_attr(devattr)->index; 1086 int nr = to_sensor_dev_attr(devattr)->index;
1017 struct w83627hf_data *data = dev_get_drvdata(dev); 1087 struct w83627hf_data *data = dev_get_drvdata(dev);
1018 static const u8 mask[]={0xF8, 0x8F}; 1088 static const u8 mask[]={0xF8, 0x8F};
1019 u32 val; 1089 unsigned long val;
1090 int err;
1020 1091
1021 val = simple_strtoul(buf, NULL, 10); 1092 err = kstrtoul(buf, 10, &val);
1093 if (err)
1094 return err;
1022 1095
1023 mutex_lock(&data->update_lock); 1096 mutex_lock(&data->update_lock);
1024 1097
@@ -1060,9 +1133,13 @@ store_temp_type(struct device *dev, struct device_attribute *devattr,
1060{ 1133{
1061 int nr = to_sensor_dev_attr(devattr)->index; 1134 int nr = to_sensor_dev_attr(devattr)->index;
1062 struct w83627hf_data *data = dev_get_drvdata(dev); 1135 struct w83627hf_data *data = dev_get_drvdata(dev);
1063 u32 val, tmp; 1136 unsigned long val;
1137 u32 tmp;
1138 int err;
1064 1139
1065 val = simple_strtoul(buf, NULL, 10); 1140 err = kstrtoul(buf, 10, &val);
1141 if (err)
1142 return err;
1066 1143
1067 mutex_lock(&data->update_lock); 1144 mutex_lock(&data->update_lock);
1068 1145
@@ -1290,7 +1367,8 @@ static int __devinit w83627hf_probe(struct platform_device *pdev)
1290 goto ERROR0; 1367 goto ERROR0;
1291 } 1368 }
1292 1369
1293 if (!(data = kzalloc(sizeof(struct w83627hf_data), GFP_KERNEL))) { 1370 data = kzalloc(sizeof(struct w83627hf_data), GFP_KERNEL);
1371 if (!data) {
1294 err = -ENOMEM; 1372 err = -ENOMEM;
1295 goto ERROR1; 1373 goto ERROR1;
1296 } 1374 }
@@ -1311,7 +1389,8 @@ static int __devinit w83627hf_probe(struct platform_device *pdev)
1311 w83627hf_update_fan_div(data); 1389 w83627hf_update_fan_div(data);
1312 1390
1313 /* Register common device attributes */ 1391 /* Register common device attributes */
1314 if ((err = sysfs_create_group(&dev->kobj, &w83627hf_group))) 1392 err = sysfs_create_group(&dev->kobj, &w83627hf_group);
1393 if (err)
1315 goto ERROR3; 1394 goto ERROR3;
1316 1395
1317 /* Register chip-specific device attributes */ 1396 /* Register chip-specific device attributes */
@@ -1387,10 +1466,11 @@ static int __devinit w83627hf_probe(struct platform_device *pdev)
1387 } 1466 }
1388 1467
1389 if (data->type == w83627thf || data->type == w83637hf 1468 if (data->type == w83627thf || data->type == w83637hf
1390 || data->type == w83687thf) 1469 || data->type == w83687thf) {
1391 if ((err = device_create_file(dev, 1470 err = device_create_file(dev, &sensor_dev_attr_pwm3.dev_attr);
1392 &sensor_dev_attr_pwm3.dev_attr))) 1471 if (err)
1393 goto ERROR4; 1472 goto ERROR4;
1473 }
1394 1474
1395 if (data->type == w83637hf || data->type == w83687thf) 1475 if (data->type == w83637hf || data->type == w83687thf)
1396 if ((err = device_create_file(dev, 1476 if ((err = device_create_file(dev,
@@ -1409,10 +1489,12 @@ static int __devinit w83627hf_probe(struct platform_device *pdev)
1409 goto ERROR4; 1489 goto ERROR4;
1410 1490
1411 if (data->type == w83627thf || data->type == w83637hf 1491 if (data->type == w83627thf || data->type == w83637hf
1412 || data->type == w83687thf) 1492 || data->type == w83687thf) {
1413 if ((err = device_create_file(dev, 1493 err = device_create_file(dev,
1414 &sensor_dev_attr_pwm3_enable.dev_attr))) 1494 &sensor_dev_attr_pwm3_enable.dev_attr);
1495 if (err)
1415 goto ERROR4; 1496 goto ERROR4;
1497 }
1416 1498
1417 data->hwmon_dev = hwmon_device_register(dev); 1499 data->hwmon_dev = hwmon_device_register(dev);
1418 if (IS_ERR(data->hwmon_dev)) { 1500 if (IS_ERR(data->hwmon_dev)) {
@@ -1510,8 +1592,10 @@ static int __devinit w83627thf_read_gpio5(struct platform_device *pdev)
1510 goto exit; 1592 goto exit;
1511 } 1593 }
1512 1594
1513 /* Make sure the pins are configured for input 1595 /*
1514 There must be at least five (VRM 9), and possibly 6 (VRM 10) */ 1596 * Make sure the pins are configured for input
1597 * There must be at least five (VRM 9), and possibly 6 (VRM 10)
1598 */
1515 sel = superio_inb(sio_data, W83627THF_GPIO5_IOSR) & 0x3f; 1599 sel = superio_inb(sio_data, W83627THF_GPIO5_IOSR) & 0x3f;
1516 if ((sel & 0x1f) != 0x1f) { 1600 if ((sel & 0x1f) != 0x1f) {
1517 dev_dbg(&pdev->dev, "GPIO5 not configured for VID " 1601 dev_dbg(&pdev->dev, "GPIO5 not configured for VID "
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index 17a8fa2d9ae9..b03d54a799e3 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -1,37 +1,37 @@
1/* 1/*
2 w83781d.c - Part of lm_sensors, Linux kernel modules for hardware 2 * w83781d.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 * monitoring
4 Copyright (c) 1998 - 2001 Frodo Looijaard <frodol@dds.nl>, 4 * Copyright (c) 1998 - 2001 Frodo Looijaard <frodol@dds.nl>,
5 Philip Edelbrock <phil@netroedge.com>, 5 * Philip Edelbrock <phil@netroedge.com>,
6 and Mark Studebaker <mdsxyz123@yahoo.com> 6 * and Mark Studebaker <mdsxyz123@yahoo.com>
7 Copyright (c) 2007 - 2008 Jean Delvare <khali@linux-fr.org> 7 * Copyright (c) 2007 - 2008 Jean Delvare <khali@linux-fr.org>
8 8 *
9 This program is free software; you can redistribute it and/or modify 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 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 11 * the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version. 12 * (at your option) any later version.
13 13 *
14 This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details. 17 * GNU General Public License for more details.
18 18 *
19 You should have received a copy of the GNU General Public License 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 20 * along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22*/ 22 */
23 23
24/* 24/*
25 Supports following chips: 25 * Supports following chips:
26 26 *
27 Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA 27 * Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
28 as99127f 7 3 0 3 0x31 0x12c3 yes no 28 * as99127f 7 3 0 3 0x31 0x12c3 yes no
29 as99127f rev.2 (type_name = as99127f) 0x31 0x5ca3 yes no 29 * as99127f rev.2 (type_name = as99127f) 0x31 0x5ca3 yes no
30 w83781d 7 3 0 3 0x10-1 0x5ca3 yes yes 30 * w83781d 7 3 0 3 0x10-1 0x5ca3 yes yes
31 w83782d 9 3 2-4 3 0x30 0x5ca3 yes yes 31 * w83782d 9 3 2-4 3 0x30 0x5ca3 yes yes
32 w83783s 5-6 3 2 1-2 0x40 0x5ca3 yes no 32 * w83783s 5-6 3 2 1-2 0x40 0x5ca3 yes no
33 33 *
34*/ 34 */
35 35
36#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 36#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
37 37
@@ -145,8 +145,10 @@ static const u8 W83781D_REG_PWM[] = { 0x5B, 0x5A, 0x5E, 0x5F };
145#define W83781D_REG_I2C_ADDR 0x48 145#define W83781D_REG_I2C_ADDR 0x48
146#define W83781D_REG_I2C_SUBADDR 0x4A 146#define W83781D_REG_I2C_SUBADDR 0x4A
147 147
148/* The following are undocumented in the data sheets however we 148/*
149 received the information in an email from Winbond tech support */ 149 * The following are undocumented in the data sheets however we
150 * received the information in an email from Winbond tech support
151 */
150/* Sensor selection - not on 781d */ 152/* Sensor selection - not on 781d */
151#define W83781D_REG_SCFG1 0x5D 153#define W83781D_REG_SCFG1 0x5D
152static const u8 BIT_SCFG1[] = { 0x02, 0x04, 0x08 }; 154static const u8 BIT_SCFG1[] = { 0x02, 0x04, 0x08 };
@@ -182,9 +184,9 @@ FAN_FROM_REG(u8 val, int div)
182#define TEMP_TO_REG(val) SENSORS_LIMIT((val) / 1000, -127, 128) 184#define TEMP_TO_REG(val) SENSORS_LIMIT((val) / 1000, -127, 128)
183#define TEMP_FROM_REG(val) ((val) * 1000) 185#define TEMP_FROM_REG(val) ((val) * 1000)
184 186
185#define BEEP_MASK_FROM_REG(val,type) ((type) == as99127f ? \ 187#define BEEP_MASK_FROM_REG(val, type) ((type) == as99127f ? \
186 (~(val)) & 0x7fff : (val) & 0xff7fff) 188 (~(val)) & 0x7fff : (val) & 0xff7fff)
187#define BEEP_MASK_TO_REG(val,type) ((type) == as99127f ? \ 189#define BEEP_MASK_TO_REG(val, type) ((type) == as99127f ? \
188 (~(val)) & 0x7fff : (val) & 0xff7fff) 190 (~(val)) & 0x7fff : (val) & 0xff7fff)
189 191
190#define DIV_FROM_REG(val) (1 << (val)) 192#define DIV_FROM_REG(val) (1 << (val))
@@ -238,9 +240,11 @@ struct w83781d_data {
238 u32 beep_mask; /* Register encoding, combined */ 240 u32 beep_mask; /* Register encoding, combined */
239 u8 pwm[4]; /* Register value */ 241 u8 pwm[4]; /* Register value */
240 u8 pwm2_enable; /* Boolean */ 242 u8 pwm2_enable; /* Boolean */
241 u16 sens[3]; /* 782D/783S only. 243 u16 sens[3]; /*
242 1 = pentium diode; 2 = 3904 diode; 244 * 782D/783S only.
243 4 = thermistor */ 245 * 1 = pentium diode; 2 = 3904 diode;
246 * 4 = thermistor
247 */
244 u8 vrm; 248 u8 vrm;
245}; 249};
246 250
@@ -254,7 +258,7 @@ static void w83781d_init_device(struct device *dev);
254 258
255/* following are the sysfs callback functions */ 259/* following are the sysfs callback functions */
256#define show_in_reg(reg) \ 260#define show_in_reg(reg) \
257static ssize_t show_##reg (struct device *dev, struct device_attribute *da, \ 261static ssize_t show_##reg(struct device *dev, struct device_attribute *da, \
258 char *buf) \ 262 char *buf) \
259{ \ 263{ \
260 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \ 264 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
@@ -267,20 +271,21 @@ show_in_reg(in_min);
267show_in_reg(in_max); 271show_in_reg(in_max);
268 272
269#define store_in_reg(REG, reg) \ 273#define store_in_reg(REG, reg) \
270static ssize_t store_in_##reg (struct device *dev, struct device_attribute \ 274static ssize_t store_in_##reg(struct device *dev, struct device_attribute \
271 *da, const char *buf, size_t count) \ 275 *da, const char *buf, size_t count) \
272{ \ 276{ \
273 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \ 277 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
274 struct w83781d_data *data = dev_get_drvdata(dev); \ 278 struct w83781d_data *data = dev_get_drvdata(dev); \
275 int nr = attr->index; \ 279 int nr = attr->index; \
276 u32 val; \ 280 unsigned long val; \
277 \ 281 int err = kstrtoul(buf, 10, &val); \
278 val = simple_strtoul(buf, NULL, 10); \ 282 if (err) \
279 \ 283 return err; \
280 mutex_lock(&data->update_lock); \ 284 mutex_lock(&data->update_lock); \
281 data->in_##reg[nr] = IN_TO_REG(val); \ 285 data->in_##reg[nr] = IN_TO_REG(val); \
282 w83781d_write_value(data, W83781D_REG_IN_##REG(nr), data->in_##reg[nr]); \ 286 w83781d_write_value(data, W83781D_REG_IN_##REG(nr), \
283 \ 287 data->in_##reg[nr]); \
288 \
284 mutex_unlock(&data->update_lock); \ 289 mutex_unlock(&data->update_lock); \
285 return count; \ 290 return count; \
286} 291}
@@ -306,12 +311,12 @@ sysfs_in_offsets(7);
306sysfs_in_offsets(8); 311sysfs_in_offsets(8);
307 312
308#define show_fan_reg(reg) \ 313#define show_fan_reg(reg) \
309static ssize_t show_##reg (struct device *dev, struct device_attribute *da, \ 314static ssize_t show_##reg(struct device *dev, struct device_attribute *da, \
310 char *buf) \ 315 char *buf) \
311{ \ 316{ \
312 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \ 317 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
313 struct w83781d_data *data = w83781d_update_device(dev); \ 318 struct w83781d_data *data = w83781d_update_device(dev); \
314 return sprintf(buf,"%ld\n", \ 319 return sprintf(buf, "%ld\n", \
315 FAN_FROM_REG(data->reg[attr->index], \ 320 FAN_FROM_REG(data->reg[attr->index], \
316 DIV_FROM_REG(data->fan_div[attr->index]))); \ 321 DIV_FROM_REG(data->fan_div[attr->index]))); \
317} 322}
@@ -325,9 +330,12 @@ store_fan_min(struct device *dev, struct device_attribute *da,
325 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 330 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
326 struct w83781d_data *data = dev_get_drvdata(dev); 331 struct w83781d_data *data = dev_get_drvdata(dev);
327 int nr = attr->index; 332 int nr = attr->index;
328 u32 val; 333 unsigned long val;
334 int err;
329 335
330 val = simple_strtoul(buf, NULL, 10); 336 err = kstrtoul(buf, 10, &val);
337 if (err)
338 return err;
331 339
332 mutex_lock(&data->update_lock); 340 mutex_lock(&data->update_lock);
333 data->fan_min[nr] = 341 data->fan_min[nr] =
@@ -350,17 +358,17 @@ static SENSOR_DEVICE_ATTR(fan3_min, S_IRUGO | S_IWUSR,
350 show_fan_min, store_fan_min, 2); 358 show_fan_min, store_fan_min, 2);
351 359
352#define show_temp_reg(reg) \ 360#define show_temp_reg(reg) \
353static ssize_t show_##reg (struct device *dev, struct device_attribute *da, \ 361static ssize_t show_##reg(struct device *dev, struct device_attribute *da, \
354 char *buf) \ 362 char *buf) \
355{ \ 363{ \
356 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \ 364 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
357 struct w83781d_data *data = w83781d_update_device(dev); \ 365 struct w83781d_data *data = w83781d_update_device(dev); \
358 int nr = attr->index; \ 366 int nr = attr->index; \
359 if (nr >= 2) { /* TEMP2 and TEMP3 */ \ 367 if (nr >= 2) { /* TEMP2 and TEMP3 */ \
360 return sprintf(buf,"%d\n", \ 368 return sprintf(buf, "%d\n", \
361 LM75_TEMP_FROM_REG(data->reg##_add[nr-2])); \ 369 LM75_TEMP_FROM_REG(data->reg##_add[nr-2])); \
362 } else { /* TEMP1 */ \ 370 } else { /* TEMP1 */ \
363 return sprintf(buf,"%ld\n", (long)TEMP_FROM_REG(data->reg)); \ 371 return sprintf(buf, "%ld\n", (long)TEMP_FROM_REG(data->reg)); \
364 } \ 372 } \
365} 373}
366show_temp_reg(temp); 374show_temp_reg(temp);
@@ -368,16 +376,16 @@ show_temp_reg(temp_max);
368show_temp_reg(temp_max_hyst); 376show_temp_reg(temp_max_hyst);
369 377
370#define store_temp_reg(REG, reg) \ 378#define store_temp_reg(REG, reg) \
371static ssize_t store_temp_##reg (struct device *dev, \ 379static ssize_t store_temp_##reg(struct device *dev, \
372 struct device_attribute *da, const char *buf, size_t count) \ 380 struct device_attribute *da, const char *buf, size_t count) \
373{ \ 381{ \
374 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \ 382 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
375 struct w83781d_data *data = dev_get_drvdata(dev); \ 383 struct w83781d_data *data = dev_get_drvdata(dev); \
376 int nr = attr->index; \ 384 int nr = attr->index; \
377 long val; \ 385 long val; \
378 \ 386 int err = kstrtol(buf, 10, &val); \
379 val = simple_strtol(buf, NULL, 10); \ 387 if (err) \
380 \ 388 return err; \
381 mutex_lock(&data->update_lock); \ 389 mutex_lock(&data->update_lock); \
382 \ 390 \
383 if (nr >= 2) { /* TEMP2 and TEMP3 */ \ 391 if (nr >= 2) { /* TEMP2 and TEMP3 */ \
@@ -425,13 +433,17 @@ show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
425} 433}
426 434
427static ssize_t 435static ssize_t
428store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 436store_vrm_reg(struct device *dev, struct device_attribute *attr,
437 const char *buf, size_t count)
429{ 438{
430 struct w83781d_data *data = dev_get_drvdata(dev); 439 struct w83781d_data *data = dev_get_drvdata(dev);
431 u32 val; 440 unsigned long val;
441 int err;
432 442
433 val = simple_strtoul(buf, NULL, 10); 443 err = kstrtoul(buf, 10, &val);
434 data->vrm = val; 444 if (err)
445 return err;
446 data->vrm = SENSORS_LIMIT(val, 0, 255);
435 447
436 return count; 448 return count;
437} 449}
@@ -480,7 +492,8 @@ static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
480static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5); 492static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
481static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_temp3_alarm, NULL, 0); 493static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_temp3_alarm, NULL, 0);
482 494
483static ssize_t show_beep_mask (struct device *dev, struct device_attribute *attr, char *buf) 495static ssize_t show_beep_mask(struct device *dev,
496 struct device_attribute *attr, char *buf)
484{ 497{
485 struct w83781d_data *data = w83781d_update_device(dev); 498 struct w83781d_data *data = w83781d_update_device(dev);
486 return sprintf(buf, "%ld\n", 499 return sprintf(buf, "%ld\n",
@@ -492,9 +505,12 @@ store_beep_mask(struct device *dev, struct device_attribute *attr,
492 const char *buf, size_t count) 505 const char *buf, size_t count)
493{ 506{
494 struct w83781d_data *data = dev_get_drvdata(dev); 507 struct w83781d_data *data = dev_get_drvdata(dev);
495 u32 val; 508 unsigned long val;
509 int err;
496 510
497 val = simple_strtoul(buf, NULL, 10); 511 err = kstrtoul(buf, 10, &val);
512 if (err)
513 return err;
498 514
499 mutex_lock(&data->update_lock); 515 mutex_lock(&data->update_lock);
500 data->beep_mask &= 0x8000; /* preserve beep enable */ 516 data->beep_mask &= 0x8000; /* preserve beep enable */
@@ -529,10 +545,14 @@ store_beep(struct device *dev, struct device_attribute *attr,
529{ 545{
530 struct w83781d_data *data = dev_get_drvdata(dev); 546 struct w83781d_data *data = dev_get_drvdata(dev);
531 int bitnr = to_sensor_dev_attr(attr)->index; 547 int bitnr = to_sensor_dev_attr(attr)->index;
532 unsigned long bit;
533 u8 reg; 548 u8 reg;
549 unsigned long bit;
550 int err;
551
552 err = kstrtoul(buf, 10, &bit);
553 if (err)
554 return err;
534 555
535 bit = simple_strtoul(buf, NULL, 10);
536 if (bit & ~1) 556 if (bit & ~1)
537 return -EINVAL; 557 return -EINVAL;
538 558
@@ -620,10 +640,12 @@ show_fan_div(struct device *dev, struct device_attribute *da, char *buf)
620 (long) DIV_FROM_REG(data->fan_div[attr->index])); 640 (long) DIV_FROM_REG(data->fan_div[attr->index]));
621} 641}
622 642
623/* Note: we save and restore the fan minimum here, because its value is 643/*
624 determined in part by the fan divisor. This follows the principle of 644 * Note: we save and restore the fan minimum here, because its value is
625 least surprise; the user doesn't expect the fan minimum to change just 645 * determined in part by the fan divisor. This follows the principle of
626 because the divisor changed. */ 646 * least surprise; the user doesn't expect the fan minimum to change just
647 * because the divisor changed.
648 */
627static ssize_t 649static ssize_t
628store_fan_div(struct device *dev, struct device_attribute *da, 650store_fan_div(struct device *dev, struct device_attribute *da,
629 const char *buf, size_t count) 651 const char *buf, size_t count)
@@ -633,7 +655,12 @@ store_fan_div(struct device *dev, struct device_attribute *da,
633 unsigned long min; 655 unsigned long min;
634 int nr = attr->index; 656 int nr = attr->index;
635 u8 reg; 657 u8 reg;
636 unsigned long val = simple_strtoul(buf, NULL, 10); 658 unsigned long val;
659 int err;
660
661 err = kstrtoul(buf, 10, &val);
662 if (err)
663 return err;
637 664
638 mutex_lock(&data->update_lock); 665 mutex_lock(&data->update_lock);
639 666
@@ -643,10 +670,12 @@ store_fan_div(struct device *dev, struct device_attribute *da,
643 670
644 data->fan_div[nr] = DIV_TO_REG(val, data->type); 671 data->fan_div[nr] = DIV_TO_REG(val, data->type);
645 672
646 reg = (w83781d_read_value(data, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV) 673 reg = (w83781d_read_value(data, nr == 2 ?
647 & (nr==0 ? 0xcf : 0x3f)) 674 W83781D_REG_PIN : W83781D_REG_VID_FANDIV)
648 | ((data->fan_div[nr] & 0x03) << (nr==0 ? 4 : 6)); 675 & (nr == 0 ? 0xcf : 0x3f))
649 w83781d_write_value(data, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV, reg); 676 | ((data->fan_div[nr] & 0x03) << (nr == 0 ? 4 : 6));
677 w83781d_write_value(data, nr == 2 ?
678 W83781D_REG_PIN : W83781D_REG_VID_FANDIV, reg);
650 679
651 /* w83781d and as99127f don't have extended divisor bits */ 680 /* w83781d and as99127f don't have extended divisor bits */
652 if (data->type != w83781d && data->type != as99127f) { 681 if (data->type != w83781d && data->type != as99127f) {
@@ -693,9 +722,12 @@ store_pwm(struct device *dev, struct device_attribute *da, const char *buf,
693 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 722 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
694 struct w83781d_data *data = dev_get_drvdata(dev); 723 struct w83781d_data *data = dev_get_drvdata(dev);
695 int nr = attr->index; 724 int nr = attr->index;
696 u32 val; 725 unsigned long val;
726 int err;
697 727
698 val = simple_strtoul(buf, NULL, 10); 728 err = kstrtoul(buf, 10, &val);
729 if (err)
730 return err;
699 731
700 mutex_lock(&data->update_lock); 732 mutex_lock(&data->update_lock);
701 data->pwm[nr] = SENSORS_LIMIT(val, 0, 255); 733 data->pwm[nr] = SENSORS_LIMIT(val, 0, 255);
@@ -709,9 +741,13 @@ store_pwm2_enable(struct device *dev, struct device_attribute *da,
709 const char *buf, size_t count) 741 const char *buf, size_t count)
710{ 742{
711 struct w83781d_data *data = dev_get_drvdata(dev); 743 struct w83781d_data *data = dev_get_drvdata(dev);
712 u32 val, reg; 744 unsigned long val;
745 u32 reg;
746 int err;
713 747
714 val = simple_strtoul(buf, NULL, 10); 748 err = kstrtoul(buf, 10, &val);
749 if (err)
750 return err;
715 751
716 mutex_lock(&data->update_lock); 752 mutex_lock(&data->update_lock);
717 753
@@ -761,9 +797,13 @@ store_sensor(struct device *dev, struct device_attribute *da,
761 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 797 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
762 struct w83781d_data *data = dev_get_drvdata(dev); 798 struct w83781d_data *data = dev_get_drvdata(dev);
763 int nr = attr->index; 799 int nr = attr->index;
764 u32 val, tmp; 800 unsigned long val;
801 u32 tmp;
802 int err;
765 803
766 val = simple_strtoul(buf, NULL, 10); 804 err = kstrtoul(buf, 10, &val);
805 if (err)
806 return err;
767 807
768 mutex_lock(&data->update_lock); 808 mutex_lock(&data->update_lock);
769 809
@@ -813,7 +853,8 @@ static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR,
813static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR, 853static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR,
814 show_sensor, store_sensor, 2); 854 show_sensor, store_sensor, 2);
815 855
816/* Assumes that adapter is of I2C, not ISA variety. 856/*
857 * Assumes that adapter is of I2C, not ISA variety.
817 * OTHERWISE DON'T CALL THIS 858 * OTHERWISE DON'T CALL THIS
818 */ 859 */
819static int 860static int
@@ -911,7 +952,7 @@ ERROR_SC_1:
911 &sensor_dev_attr_temp##X##_alarm.dev_attr.attr, \ 952 &sensor_dev_attr_temp##X##_alarm.dev_attr.attr, \
912 &sensor_dev_attr_temp##X##_beep.dev_attr.attr 953 &sensor_dev_attr_temp##X##_beep.dev_attr.attr
913 954
914static struct attribute* w83781d_attributes[] = { 955static struct attribute *w83781d_attributes[] = {
915 IN_UNIT_ATTRS(0), 956 IN_UNIT_ATTRS(0),
916 IN_UNIT_ATTRS(2), 957 IN_UNIT_ATTRS(2),
917 IN_UNIT_ATTRS(3), 958 IN_UNIT_ATTRS(3),
@@ -934,23 +975,58 @@ static const struct attribute_group w83781d_group = {
934 .attrs = w83781d_attributes, 975 .attrs = w83781d_attributes,
935}; 976};
936 977
937static struct attribute *w83781d_attributes_opt[] = { 978static struct attribute *w83781d_attributes_in1[] = {
938 IN_UNIT_ATTRS(1), 979 IN_UNIT_ATTRS(1),
980 NULL
981};
982static const struct attribute_group w83781d_group_in1 = {
983 .attrs = w83781d_attributes_in1,
984};
985
986static struct attribute *w83781d_attributes_in78[] = {
939 IN_UNIT_ATTRS(7), 987 IN_UNIT_ATTRS(7),
940 IN_UNIT_ATTRS(8), 988 IN_UNIT_ATTRS(8),
989 NULL
990};
991static const struct attribute_group w83781d_group_in78 = {
992 .attrs = w83781d_attributes_in78,
993};
994
995static struct attribute *w83781d_attributes_temp3[] = {
941 TEMP_UNIT_ATTRS(3), 996 TEMP_UNIT_ATTRS(3),
997 NULL
998};
999static const struct attribute_group w83781d_group_temp3 = {
1000 .attrs = w83781d_attributes_temp3,
1001};
1002
1003static struct attribute *w83781d_attributes_pwm12[] = {
942 &sensor_dev_attr_pwm1.dev_attr.attr, 1004 &sensor_dev_attr_pwm1.dev_attr.attr,
943 &sensor_dev_attr_pwm2.dev_attr.attr, 1005 &sensor_dev_attr_pwm2.dev_attr.attr,
1006 &dev_attr_pwm2_enable.attr,
1007 NULL
1008};
1009static const struct attribute_group w83781d_group_pwm12 = {
1010 .attrs = w83781d_attributes_pwm12,
1011};
1012
1013static struct attribute *w83781d_attributes_pwm34[] = {
944 &sensor_dev_attr_pwm3.dev_attr.attr, 1014 &sensor_dev_attr_pwm3.dev_attr.attr,
945 &sensor_dev_attr_pwm4.dev_attr.attr, 1015 &sensor_dev_attr_pwm4.dev_attr.attr,
946 &dev_attr_pwm2_enable.attr, 1016 NULL
1017};
1018static const struct attribute_group w83781d_group_pwm34 = {
1019 .attrs = w83781d_attributes_pwm34,
1020};
1021
1022static struct attribute *w83781d_attributes_other[] = {
947 &sensor_dev_attr_temp1_type.dev_attr.attr, 1023 &sensor_dev_attr_temp1_type.dev_attr.attr,
948 &sensor_dev_attr_temp2_type.dev_attr.attr, 1024 &sensor_dev_attr_temp2_type.dev_attr.attr,
949 &sensor_dev_attr_temp3_type.dev_attr.attr, 1025 &sensor_dev_attr_temp3_type.dev_attr.attr,
950 NULL 1026 NULL
951}; 1027};
952static const struct attribute_group w83781d_group_opt = { 1028static const struct attribute_group w83781d_group_other = {
953 .attrs = w83781d_attributes_opt, 1029 .attrs = w83781d_attributes_other,
954}; 1030};
955 1031
956/* No clean up is done on error, it's up to the caller */ 1032/* No clean up is done on error, it's up to the caller */
@@ -959,56 +1035,23 @@ w83781d_create_files(struct device *dev, int kind, int is_isa)
959{ 1035{
960 int err; 1036 int err;
961 1037
962 if ((err = sysfs_create_group(&dev->kobj, &w83781d_group))) 1038 err = sysfs_create_group(&dev->kobj, &w83781d_group);
1039 if (err)
963 return err; 1040 return err;
964 1041
965 if (kind != w83783s) { 1042 if (kind != w83783s) {
966 if ((err = device_create_file(dev, 1043 err = sysfs_create_group(&dev->kobj, &w83781d_group_in1);
967 &sensor_dev_attr_in1_input.dev_attr)) 1044 if (err)
968 || (err = device_create_file(dev,
969 &sensor_dev_attr_in1_min.dev_attr))
970 || (err = device_create_file(dev,
971 &sensor_dev_attr_in1_max.dev_attr))
972 || (err = device_create_file(dev,
973 &sensor_dev_attr_in1_alarm.dev_attr))
974 || (err = device_create_file(dev,
975 &sensor_dev_attr_in1_beep.dev_attr)))
976 return err; 1045 return err;
977 } 1046 }
978 if (kind != as99127f && kind != w83781d && kind != w83783s) { 1047 if (kind != as99127f && kind != w83781d && kind != w83783s) {
979 if ((err = device_create_file(dev, 1048 err = sysfs_create_group(&dev->kobj, &w83781d_group_in78);
980 &sensor_dev_attr_in7_input.dev_attr)) 1049 if (err)
981 || (err = device_create_file(dev,
982 &sensor_dev_attr_in7_min.dev_attr))
983 || (err = device_create_file(dev,
984 &sensor_dev_attr_in7_max.dev_attr))
985 || (err = device_create_file(dev,
986 &sensor_dev_attr_in7_alarm.dev_attr))
987 || (err = device_create_file(dev,
988 &sensor_dev_attr_in7_beep.dev_attr))
989 || (err = device_create_file(dev,
990 &sensor_dev_attr_in8_input.dev_attr))
991 || (err = device_create_file(dev,
992 &sensor_dev_attr_in8_min.dev_attr))
993 || (err = device_create_file(dev,
994 &sensor_dev_attr_in8_max.dev_attr))
995 || (err = device_create_file(dev,
996 &sensor_dev_attr_in8_alarm.dev_attr))
997 || (err = device_create_file(dev,
998 &sensor_dev_attr_in8_beep.dev_attr)))
999 return err; 1050 return err;
1000 } 1051 }
1001 if (kind != w83783s) { 1052 if (kind != w83783s) {
1002 if ((err = device_create_file(dev, 1053 err = sysfs_create_group(&dev->kobj, &w83781d_group_temp3);
1003 &sensor_dev_attr_temp3_input.dev_attr)) 1054 if (err)
1004 || (err = device_create_file(dev,
1005 &sensor_dev_attr_temp3_max.dev_attr))
1006 || (err = device_create_file(dev,
1007 &sensor_dev_attr_temp3_max_hyst.dev_attr))
1008 || (err = device_create_file(dev,
1009 &sensor_dev_attr_temp3_alarm.dev_attr))
1010 || (err = device_create_file(dev,
1011 &sensor_dev_attr_temp3_beep.dev_attr)))
1012 return err; 1055 return err;
1013 1056
1014 if (kind != w83781d) { 1057 if (kind != w83781d) {
@@ -1021,30 +1064,29 @@ w83781d_create_files(struct device *dev, int kind, int is_isa)
1021 } 1064 }
1022 1065
1023 if (kind != w83781d && kind != as99127f) { 1066 if (kind != w83781d && kind != as99127f) {
1024 if ((err = device_create_file(dev, 1067 err = sysfs_create_group(&dev->kobj, &w83781d_group_pwm12);
1025 &sensor_dev_attr_pwm1.dev_attr)) 1068 if (err)
1026 || (err = device_create_file(dev,
1027 &sensor_dev_attr_pwm2.dev_attr))
1028 || (err = device_create_file(dev, &dev_attr_pwm2_enable)))
1029 return err; 1069 return err;
1030 } 1070 }
1031 if (kind == w83782d && !is_isa) { 1071 if (kind == w83782d && !is_isa) {
1032 if ((err = device_create_file(dev, 1072 err = sysfs_create_group(&dev->kobj, &w83781d_group_pwm34);
1033 &sensor_dev_attr_pwm3.dev_attr)) 1073 if (err)
1034 || (err = device_create_file(dev,
1035 &sensor_dev_attr_pwm4.dev_attr)))
1036 return err; 1074 return err;
1037 } 1075 }
1038 1076
1039 if (kind != as99127f && kind != w83781d) { 1077 if (kind != as99127f && kind != w83781d) {
1040 if ((err = device_create_file(dev, 1078 err = device_create_file(dev,
1041 &sensor_dev_attr_temp1_type.dev_attr)) 1079 &sensor_dev_attr_temp1_type.dev_attr);
1042 || (err = device_create_file(dev, 1080 if (err)
1043 &sensor_dev_attr_temp2_type.dev_attr))) 1081 return err;
1082 err = device_create_file(dev,
1083 &sensor_dev_attr_temp2_type.dev_attr);
1084 if (err)
1044 return err; 1085 return err;
1045 if (kind != w83783s) { 1086 if (kind != w83783s) {
1046 if ((err = device_create_file(dev, 1087 err = device_create_file(dev,
1047 &sensor_dev_attr_temp3_type.dev_attr))) 1088 &sensor_dev_attr_temp3_type.dev_attr);
1089 if (err)
1048 return err; 1090 return err;
1049 } 1091 }
1050 } 1092 }
@@ -1066,9 +1108,11 @@ w83781d_detect(struct i2c_client *client, struct i2c_board_info *info)
1066 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1108 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1067 return -ENODEV; 1109 return -ENODEV;
1068 1110
1069 /* We block updates of the ISA device to minimize the risk of 1111 /*
1070 concurrent access to the same W83781D chip through different 1112 * We block updates of the ISA device to minimize the risk of
1071 interfaces. */ 1113 * concurrent access to the same W83781D chip through different
1114 * interfaces.
1115 */
1072 if (isa) 1116 if (isa)
1073 mutex_lock(&isa->update_lock); 1117 mutex_lock(&isa->update_lock);
1074 1118
@@ -1083,15 +1127,17 @@ w83781d_detect(struct i2c_client *client, struct i2c_board_info *info)
1083 /* Check for Winbond or Asus ID if in bank 0 */ 1127 /* Check for Winbond or Asus ID if in bank 0 */
1084 if (!(val1 & 0x07) && 1128 if (!(val1 & 0x07) &&
1085 ((!(val1 & 0x80) && val2 != 0xa3 && val2 != 0xc3) || 1129 ((!(val1 & 0x80) && val2 != 0xa3 && val2 != 0xc3) ||
1086 ( (val1 & 0x80) && val2 != 0x5c && val2 != 0x12))) { 1130 ((val1 & 0x80) && val2 != 0x5c && val2 != 0x12))) {
1087 dev_dbg(&adapter->dev, 1131 dev_dbg(&adapter->dev,
1088 "Detection of w83781d chip failed at step 4\n"); 1132 "Detection of w83781d chip failed at step 4\n");
1089 goto err_nodev; 1133 goto err_nodev;
1090 } 1134 }
1091 /* If Winbond SMBus, check address at 0x48. 1135 /*
1092 Asus doesn't support, except for as99127f rev.2 */ 1136 * If Winbond SMBus, check address at 0x48.
1137 * Asus doesn't support, except for as99127f rev.2
1138 */
1093 if ((!(val1 & 0x80) && val2 == 0xa3) || 1139 if ((!(val1 & 0x80) && val2 == 0xa3) ||
1094 ( (val1 & 0x80) && val2 == 0x5c)) { 1140 ((val1 & 0x80) && val2 == 0x5c)) {
1095 if (i2c_smbus_read_byte_data(client, W83781D_REG_I2C_ADDR) 1141 if (i2c_smbus_read_byte_data(client, W83781D_REG_I2C_ADDR)
1096 != address) { 1142 != address) {
1097 dev_dbg(&adapter->dev, 1143 dev_dbg(&adapter->dev,
@@ -1149,6 +1195,17 @@ w83781d_detect(struct i2c_client *client, struct i2c_board_info *info)
1149 return -ENODEV; 1195 return -ENODEV;
1150} 1196}
1151 1197
1198static void w83781d_remove_files(struct device *dev)
1199{
1200 sysfs_remove_group(&dev->kobj, &w83781d_group);
1201 sysfs_remove_group(&dev->kobj, &w83781d_group_in1);
1202 sysfs_remove_group(&dev->kobj, &w83781d_group_in78);
1203 sysfs_remove_group(&dev->kobj, &w83781d_group_temp3);
1204 sysfs_remove_group(&dev->kobj, &w83781d_group_pwm12);
1205 sysfs_remove_group(&dev->kobj, &w83781d_group_pwm34);
1206 sysfs_remove_group(&dev->kobj, &w83781d_group_other);
1207}
1208
1152static int 1209static int
1153w83781d_probe(struct i2c_client *client, const struct i2c_device_id *id) 1210w83781d_probe(struct i2c_client *client, const struct i2c_device_id *id)
1154{ 1211{
@@ -1191,9 +1248,7 @@ w83781d_probe(struct i2c_client *client, const struct i2c_device_id *id)
1191 return 0; 1248 return 0;
1192 1249
1193ERROR4: 1250ERROR4:
1194 sysfs_remove_group(&dev->kobj, &w83781d_group); 1251 w83781d_remove_files(dev);
1195 sysfs_remove_group(&dev->kobj, &w83781d_group_opt);
1196
1197 if (data->lm75[0]) 1252 if (data->lm75[0])
1198 i2c_unregister_device(data->lm75[0]); 1253 i2c_unregister_device(data->lm75[0]);
1199 if (data->lm75[1]) 1254 if (data->lm75[1])
@@ -1211,9 +1266,7 @@ w83781d_remove(struct i2c_client *client)
1211 struct device *dev = &client->dev; 1266 struct device *dev = &client->dev;
1212 1267
1213 hwmon_device_unregister(data->hwmon_dev); 1268 hwmon_device_unregister(data->hwmon_dev);
1214 1269 w83781d_remove_files(dev);
1215 sysfs_remove_group(&dev->kobj, &w83781d_group);
1216 sysfs_remove_group(&dev->kobj, &w83781d_group_opt);
1217 1270
1218 if (data->lm75[0]) 1271 if (data->lm75[0])
1219 i2c_unregister_device(data->lm75[0]); 1272 i2c_unregister_device(data->lm75[0]);
@@ -1310,35 +1363,47 @@ w83781d_init_device(struct device *dev)
1310 int type = data->type; 1363 int type = data->type;
1311 u8 tmp; 1364 u8 tmp;
1312 1365
1313 if (reset && type != as99127f) { /* this resets registers we don't have 1366 if (reset && type != as99127f) { /*
1314 documentation for on the as99127f */ 1367 * this resets registers we don't have
1315 /* Resetting the chip has been the default for a long time, 1368 * documentation for on the as99127f
1316 but it causes the BIOS initializations (fan clock dividers, 1369 */
1317 thermal sensor types...) to be lost, so it is now optional. 1370 /*
1318 It might even go away if nobody reports it as being useful, 1371 * Resetting the chip has been the default for a long time,
1319 as I see very little reason why this would be needed at 1372 * but it causes the BIOS initializations (fan clock dividers,
1320 all. */ 1373 * thermal sensor types...) to be lost, so it is now optional.
1374 * It might even go away if nobody reports it as being useful,
1375 * as I see very little reason why this would be needed at
1376 * all.
1377 */
1321 dev_info(dev, "If reset=1 solved a problem you were " 1378 dev_info(dev, "If reset=1 solved a problem you were "
1322 "having, please report!\n"); 1379 "having, please report!\n");
1323 1380
1324 /* save these registers */ 1381 /* save these registers */
1325 i = w83781d_read_value(data, W83781D_REG_BEEP_CONFIG); 1382 i = w83781d_read_value(data, W83781D_REG_BEEP_CONFIG);
1326 p = w83781d_read_value(data, W83781D_REG_PWMCLK12); 1383 p = w83781d_read_value(data, W83781D_REG_PWMCLK12);
1327 /* Reset all except Watchdog values and last conversion values 1384 /*
1328 This sets fan-divs to 2, among others */ 1385 * Reset all except Watchdog values and last conversion values
1386 * This sets fan-divs to 2, among others
1387 */
1329 w83781d_write_value(data, W83781D_REG_CONFIG, 0x80); 1388 w83781d_write_value(data, W83781D_REG_CONFIG, 0x80);
1330 /* Restore the registers and disable power-on abnormal beep. 1389 /*
1331 This saves FAN 1/2/3 input/output values set by BIOS. */ 1390 * Restore the registers and disable power-on abnormal beep.
1391 * This saves FAN 1/2/3 input/output values set by BIOS.
1392 */
1332 w83781d_write_value(data, W83781D_REG_BEEP_CONFIG, i | 0x80); 1393 w83781d_write_value(data, W83781D_REG_BEEP_CONFIG, i | 0x80);
1333 w83781d_write_value(data, W83781D_REG_PWMCLK12, p); 1394 w83781d_write_value(data, W83781D_REG_PWMCLK12, p);
1334 /* Disable master beep-enable (reset turns it on). 1395 /*
1335 Individual beep_mask should be reset to off but for some reason 1396 * Disable master beep-enable (reset turns it on).
1336 disabling this bit helps some people not get beeped */ 1397 * Individual beep_mask should be reset to off but for some
1398 * reason disabling this bit helps some people not get beeped
1399 */
1337 w83781d_write_value(data, W83781D_REG_BEEP_INTS2, 0); 1400 w83781d_write_value(data, W83781D_REG_BEEP_INTS2, 0);
1338 } 1401 }
1339 1402
1340 /* Disable power-on abnormal beep, as advised by the datasheet. 1403 /*
1341 Already done if reset=1. */ 1404 * Disable power-on abnormal beep, as advised by the datasheet.
1405 * Already done if reset=1.
1406 */
1342 if (init && !reset && type != as99127f) { 1407 if (init && !reset && type != as99127f) {
1343 i = w83781d_read_value(data, W83781D_REG_BEEP_CONFIG); 1408 i = w83781d_read_value(data, W83781D_REG_BEEP_CONFIG);
1344 w83781d_write_value(data, W83781D_REG_BEEP_CONFIG, i | 0x80); 1409 w83781d_write_value(data, W83781D_REG_BEEP_CONFIG, i | 0x80);
@@ -1444,7 +1509,7 @@ static struct w83781d_data *w83781d_update_device(struct device *dev)
1444 } 1509 }
1445 /* Only PWM2 can be disabled */ 1510 /* Only PWM2 can be disabled */
1446 data->pwm2_enable = (w83781d_read_value(data, 1511 data->pwm2_enable = (w83781d_read_value(data,
1447 W83781D_REG_PWMCLK12) & 0x08) >> 3; 1512 W83781D_REG_PWMCLK12) & 0x08) >> 3;
1448 } 1513 }
1449 1514
1450 data->temp = w83781d_read_value(data, W83781D_REG_TEMP(1)); 1515 data->temp = w83781d_read_value(data, W83781D_REG_TEMP(1));
@@ -1495,8 +1560,10 @@ static struct w83781d_data *w83781d_update_device(struct device *dev)
1495 | (w83781d_read_value(data, 1560 | (w83781d_read_value(data,
1496 W83782D_REG_ALARM2) << 8); 1561 W83782D_REG_ALARM2) << 8);
1497 } else { 1562 } else {
1498 /* No real-time status registers, fall back to 1563 /*
1499 interrupt status registers */ 1564 * No real-time status registers, fall back to
1565 * interrupt status registers
1566 */
1500 data->alarms = w83781d_read_value(data, 1567 data->alarms = w83781d_read_value(data,
1501 W83781D_REG_ALARM1) 1568 W83781D_REG_ALARM1)
1502 | (w83781d_read_value(data, 1569 | (w83781d_read_value(data,
@@ -1550,8 +1617,10 @@ static struct platform_device *pdev;
1550 1617
1551static unsigned short isa_address = 0x290; 1618static unsigned short isa_address = 0x290;
1552 1619
1553/* I2C devices get this name attribute automatically, but for ISA devices 1620/*
1554 we must create it by ourselves. */ 1621 * I2C devices get this name attribute automatically, but for ISA devices
1622 * we must create it by ourselves.
1623 */
1555static ssize_t 1624static ssize_t
1556show_name(struct device *dev, struct device_attribute *devattr, char *buf) 1625show_name(struct device *dev, struct device_attribute *devattr, char *buf)
1557{ 1626{
@@ -1581,8 +1650,10 @@ static int w83781d_alias_detect(struct i2c_client *client, u8 chipid)
1581 if (w83781d_read_value(isa, W83781D_REG_WCHIPID) != chipid) 1650 if (w83781d_read_value(isa, W83781D_REG_WCHIPID) != chipid)
1582 return 0; /* Chip type doesn't match */ 1651 return 0; /* Chip type doesn't match */
1583 1652
1584 /* We compare all the limit registers, the config register and the 1653 /*
1585 * interrupt mask registers */ 1654 * We compare all the limit registers, the config register and the
1655 * interrupt mask registers
1656 */
1586 for (i = 0x2b; i <= 0x3d; i++) { 1657 for (i = 0x2b; i <= 0x3d; i++) {
1587 if (w83781d_read_value(isa, i) != 1658 if (w83781d_read_value(isa, i) !=
1588 i2c_smbus_read_byte_data(client, i)) 1659 i2c_smbus_read_byte_data(client, i))
@@ -1663,12 +1734,14 @@ w83781d_write_value_isa(struct w83781d_data *data, u16 reg, u16 value)
1663 } 1734 }
1664} 1735}
1665 1736
1666/* The SMBus locks itself, usually, but nothing may access the Winbond between 1737/*
1667 bank switches. ISA access must always be locked explicitly! 1738 * The SMBus locks itself, usually, but nothing may access the Winbond between
1668 We ignore the W83781D BUSY flag at this moment - it could lead to deadlocks, 1739 * bank switches. ISA access must always be locked explicitly!
1669 would slow down the W83781D access and should not be necessary. 1740 * We ignore the W83781D BUSY flag at this moment - it could lead to deadlocks,
1670 There are some ugly typecasts here, but the good news is - they should 1741 * would slow down the W83781D access and should not be necessary.
1671 nowhere else be necessary! */ 1742 * There are some ugly typecasts here, but the good news is - they should
1743 * nowhere else be necessary!
1744 */
1672static int 1745static int
1673w83781d_read_value(struct w83781d_data *data, u16 reg) 1746w83781d_read_value(struct w83781d_data *data, u16 reg)
1674{ 1747{
@@ -1754,8 +1827,7 @@ w83781d_isa_probe(struct platform_device *pdev)
1754 return 0; 1827 return 0;
1755 1828
1756 exit_remove_files: 1829 exit_remove_files:
1757 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group); 1830 w83781d_remove_files(&pdev->dev);
1758 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group_opt);
1759 device_remove_file(&pdev->dev, &dev_attr_name); 1831 device_remove_file(&pdev->dev, &dev_attr_name);
1760 kfree(data); 1832 kfree(data);
1761 exit_release_region: 1833 exit_release_region:
@@ -1770,8 +1842,7 @@ w83781d_isa_remove(struct platform_device *pdev)
1770 struct w83781d_data *data = platform_get_drvdata(pdev); 1842 struct w83781d_data *data = platform_get_drvdata(pdev);
1771 1843
1772 hwmon_device_unregister(data->hwmon_dev); 1844 hwmon_device_unregister(data->hwmon_dev);
1773 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group); 1845 w83781d_remove_files(&pdev->dev);
1774 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group_opt);
1775 device_remove_file(&pdev->dev, &dev_attr_name); 1846 device_remove_file(&pdev->dev, &dev_attr_name);
1776 release_region(data->isa_addr + W83781D_ADDR_REG_OFFSET, 2); 1847 release_region(data->isa_addr + W83781D_ADDR_REG_OFFSET, 2);
1777 kfree(data); 1848 kfree(data);
@@ -1795,9 +1866,11 @@ w83781d_isa_found(unsigned short address)
1795 int val, save, found = 0; 1866 int val, save, found = 0;
1796 int port; 1867 int port;
1797 1868
1798 /* Some boards declare base+0 to base+7 as a PNP device, some base+4 1869 /*
1870 * Some boards declare base+0 to base+7 as a PNP device, some base+4
1799 * to base+7 and some base+5 to base+6. So we better request each port 1871 * to base+7 and some base+5 to base+6. So we better request each port
1800 * individually for the probing phase. */ 1872 * individually for the probing phase.
1873 */
1801 for (port = address; port < address + W83781D_EXTENT; port++) { 1874 for (port = address; port < address + W83781D_EXTENT; port++) {
1802 if (!request_region(port, 1, "w83781d")) { 1875 if (!request_region(port, 1, "w83781d")) {
1803 pr_debug("Failed to request port 0x%x\n", port); 1876 pr_debug("Failed to request port 0x%x\n", port);
@@ -1806,8 +1879,10 @@ w83781d_isa_found(unsigned short address)
1806 } 1879 }
1807 1880
1808#define REALLY_SLOW_IO 1881#define REALLY_SLOW_IO
1809 /* We need the timeouts for at least some W83781D-like 1882 /*
1810 chips. But only if we read 'undefined' registers. */ 1883 * We need the timeouts for at least some W83781D-like
1884 * chips. But only if we read 'undefined' registers.
1885 */
1811 val = inb_p(address + 1); 1886 val = inb_p(address + 1);
1812 if (inb_p(address + 2) != val 1887 if (inb_p(address + 2) != val
1813 || inb_p(address + 3) != val 1888 || inb_p(address + 3) != val
@@ -1817,8 +1892,10 @@ w83781d_isa_found(unsigned short address)
1817 } 1892 }
1818#undef REALLY_SLOW_IO 1893#undef REALLY_SLOW_IO
1819 1894
1820 /* We should be able to change the 7 LSB of the address port. The 1895 /*
1821 MSB (busy flag) should be clear initially, set after the write. */ 1896 * We should be able to change the 7 LSB of the address port. The
1897 * MSB (busy flag) should be clear initially, set after the write.
1898 */
1822 save = inb_p(address + W83781D_ADDR_REG_OFFSET); 1899 save = inb_p(address + W83781D_ADDR_REG_OFFSET);
1823 if (save & 0x80) { 1900 if (save & 0x80) {
1824 pr_debug("Detection failed at step %d\n", 2); 1901 pr_debug("Detection failed at step %d\n", 2);
@@ -2004,8 +2081,10 @@ sensors_w83781d_init(void)
2004{ 2081{
2005 int res; 2082 int res;
2006 2083
2007 /* We register the ISA device first, so that we can skip the 2084 /*
2008 * registration of an I2C interface to the same device. */ 2085 * We register the ISA device first, so that we can skip the
2086 * registration of an I2C interface to the same device.
2087 */
2009 res = w83781d_isa_register(); 2088 res = w83781d_isa_register();
2010 if (res) 2089 if (res)
2011 goto exit; 2090 goto exit;
diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c
index 35aa5149307a..2f446f92acf2 100644
--- a/drivers/hwmon/w83791d.c
+++ b/drivers/hwmon/w83791d.c
@@ -1,36 +1,36 @@
1/* 1/*
2 w83791d.c - Part of lm_sensors, Linux kernel modules for hardware 2 * w83791d.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 * monitoring
4 4 *
5 Copyright (C) 2006-2007 Charles Spirakis <bezaur@gmail.com> 5 * Copyright (C) 2006-2007 Charles Spirakis <bezaur@gmail.com>
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
9 the Free Software Foundation; either version 2 of the License, or 9 * the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 10 * (at your option) any later version.
11 11 *
12 This program is distributed in the hope that it will be useful, 12 * This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 15 * GNU General Public License for more details.
16 16 *
17 You should have received a copy of the GNU General Public License 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 18 * along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/ 20 */
21 21
22/* 22/*
23 Supports following chips: 23 * Supports following chips:
24 24 *
25 Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA 25 * Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
26 w83791d 10 5 5 3 0x71 0x5ca3 yes no 26 * w83791d 10 5 5 3 0x71 0x5ca3 yes no
27 27 *
28 The w83791d chip appears to be part way between the 83781d and the 28 * The w83791d chip appears to be part way between the 83781d and the
29 83792d. Thus, this file is derived from both the w83792d.c and 29 * 83792d. Thus, this file is derived from both the w83792d.c and
30 w83781d.c files. 30 * w83781d.c files.
31 31 *
32 The w83791g chip is the same as the w83791d but lead-free. 32 * The w83791g chip is the same as the w83791d but lead-free.
33*/ 33 */
34 34
35#include <linux/module.h> 35#include <linux/module.h>
36#include <linux/init.h> 36#include <linux/init.h>
@@ -198,10 +198,12 @@ static const u8 W83791D_REG_BEEP_CTRL[3] = {
198#define W83791D_REG_VBAT 0x5D 198#define W83791D_REG_VBAT 0x5D
199#define W83791D_REG_I2C_ADDR 0x48 199#define W83791D_REG_I2C_ADDR 0x48
200 200
201/* The SMBus locks itself. The Winbond W83791D has a bank select register 201/*
202 (index 0x4e), but the driver only accesses registers in bank 0. Since 202 * The SMBus locks itself. The Winbond W83791D has a bank select register
203 we don't switch banks, we don't need any special code to handle 203 * (index 0x4e), but the driver only accesses registers in bank 0. Since
204 locking access between bank switches */ 204 * we don't switch banks, we don't need any special code to handle
205 * locking access between bank switches
206 */
205static inline int w83791d_read(struct i2c_client *client, u8 reg) 207static inline int w83791d_read(struct i2c_client *client, u8 reg)
206{ 208{
207 return i2c_smbus_read_byte_data(client, reg); 209 return i2c_smbus_read_byte_data(client, reg);
@@ -212,9 +214,11 @@ static inline int w83791d_write(struct i2c_client *client, u8 reg, u8 value)
212 return i2c_smbus_write_byte_data(client, reg, value); 214 return i2c_smbus_write_byte_data(client, reg, value);
213} 215}
214 216
215/* The analog voltage inputs have 16mV LSB. Since the sysfs output is 217/*
216 in mV as would be measured on the chip input pin, need to just 218 * The analog voltage inputs have 16mV LSB. Since the sysfs output is
217 multiply/divide by 16 to translate from/to register values. */ 219 * in mV as would be measured on the chip input pin, need to just
220 * multiply/divide by 16 to translate from/to register values.
221 */
218#define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8) / 16), 0, 255)) 222#define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8) / 16), 0, 255))
219#define IN_FROM_REG(val) ((val) * 16) 223#define IN_FROM_REG(val) ((val) * 16)
220 224
@@ -226,7 +230,7 @@ static u8 fan_to_reg(long rpm, int div)
226 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); 230 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
227} 231}
228 232
229#define FAN_FROM_REG(val,div) ((val) == 0 ? -1 : \ 233#define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \
230 ((val) == 255 ? 0 : \ 234 ((val) == 255 ? 0 : \
231 1350000 / ((val) * (div)))) 235 1350000 / ((val) * (div))))
232 236
@@ -237,10 +241,12 @@ static u8 fan_to_reg(long rpm, int div)
237 (val) < 0 ? ((val) - 500) / 1000 : \ 241 (val) < 0 ? ((val) - 500) / 1000 : \
238 ((val) + 500) / 1000) 242 ((val) + 500) / 1000)
239 243
240/* for temp2 and temp3 which are 9-bit resolution, LSB = 0.5 degree Celsius 244/*
241 Assumes the top 8 bits are the integral amount and the bottom 8 bits 245 * for temp2 and temp3 which are 9-bit resolution, LSB = 0.5 degree Celsius
242 are the fractional amount. Since we only have 0.5 degree resolution, 246 * Assumes the top 8 bits are the integral amount and the bottom 8 bits
243 the bottom 7 bits will always be zero */ 247 * are the fractional amount. Since we only have 0.5 degree resolution,
248 * the bottom 7 bits will always be zero
249 */
244#define TEMP23_FROM_REG(val) ((val) / 128 * 500) 250#define TEMP23_FROM_REG(val) ((val) / 128 * 500)
245#define TEMP23_TO_REG(val) ((val) <= -128000 ? 0x8000 : \ 251#define TEMP23_TO_REG(val) ((val) <= -128000 ? 0x8000 : \
246 (val) >= 127500 ? 0x7F80 : \ 252 (val) >= 127500 ? 0x7F80 : \
@@ -300,17 +306,19 @@ struct w83791d_data {
300 306
301 s8 temp1[3]; /* current, over, thyst */ 307 s8 temp1[3]; /* current, over, thyst */
302 s16 temp_add[2][3]; /* fixed point value. Top 8 bits are the 308 s16 temp_add[2][3]; /* fixed point value. Top 8 bits are the
303 integral part, bottom 8 bits are the 309 * integral part, bottom 8 bits are the
304 fractional part. We only use the top 310 * fractional part. We only use the top
305 9 bits as the resolution is only 311 * 9 bits as the resolution is only
306 to the 0.5 degree C... 312 * to the 0.5 degree C...
307 two sensors with three values 313 * two sensors with three values
308 (cur, over, hyst) */ 314 * (cur, over, hyst)
315 */
309 316
310 /* PWMs */ 317 /* PWMs */
311 u8 pwm[5]; /* pwm duty cycle */ 318 u8 pwm[5]; /* pwm duty cycle */
312 u8 pwm_enable[3]; /* pwm enable status for fan 1-3 319 u8 pwm_enable[3]; /* pwm enable status for fan 1-3
313 (fan 4-5 only support manual mode) */ 320 * (fan 4-5 only support manual mode)
321 */
314 322
315 u8 temp_target[3]; /* pwm 1-3 target temperature */ 323 u8 temp_target[3]; /* pwm 1-3 target temperature */
316 u8 temp_tolerance[3]; /* pwm 1-3 temperature tolerance */ 324 u8 temp_tolerance[3]; /* pwm 1-3 temperature tolerance */
@@ -366,7 +374,7 @@ static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
366 to_sensor_dev_attr(attr); \ 374 to_sensor_dev_attr(attr); \
367 struct w83791d_data *data = w83791d_update_device(dev); \ 375 struct w83791d_data *data = w83791d_update_device(dev); \
368 int nr = sensor_attr->index; \ 376 int nr = sensor_attr->index; \
369 return sprintf(buf,"%d\n", IN_FROM_REG(data->reg[nr])); \ 377 return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \
370} 378}
371 379
372show_in_reg(in); 380show_in_reg(in);
@@ -382,9 +390,11 @@ static ssize_t store_in_##reg(struct device *dev, \
382 to_sensor_dev_attr(attr); \ 390 to_sensor_dev_attr(attr); \
383 struct i2c_client *client = to_i2c_client(dev); \ 391 struct i2c_client *client = to_i2c_client(dev); \
384 struct w83791d_data *data = i2c_get_clientdata(client); \ 392 struct w83791d_data *data = i2c_get_clientdata(client); \
385 unsigned long val = simple_strtoul(buf, NULL, 10); \
386 int nr = sensor_attr->index; \ 393 int nr = sensor_attr->index; \
387 \ 394 unsigned long val; \
395 int err = kstrtoul(buf, 10, &val); \
396 if (err) \
397 return err; \
388 mutex_lock(&data->update_lock); \ 398 mutex_lock(&data->update_lock); \
389 data->in_##reg[nr] = IN_TO_REG(val); \ 399 data->in_##reg[nr] = IN_TO_REG(val); \
390 w83791d_write(client, W83791D_REG_IN_##REG[nr], data->in_##reg[nr]); \ 400 w83791d_write(client, W83791D_REG_IN_##REG[nr], data->in_##reg[nr]); \
@@ -455,7 +465,14 @@ static ssize_t store_beep(struct device *dev, struct device_attribute *attr,
455 struct w83791d_data *data = i2c_get_clientdata(client); 465 struct w83791d_data *data = i2c_get_clientdata(client);
456 int bitnr = sensor_attr->index; 466 int bitnr = sensor_attr->index;
457 int bytenr = bitnr / 8; 467 int bytenr = bitnr / 8;
458 long val = simple_strtol(buf, NULL, 10) ? 1 : 0; 468 unsigned long val;
469 int err;
470
471 err = kstrtoul(buf, 10, &val);
472 if (err)
473 return err;
474
475 val = val ? 1 : 0;
459 476
460 mutex_lock(&data->update_lock); 477 mutex_lock(&data->update_lock);
461 478
@@ -485,8 +502,10 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
485 return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1); 502 return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1);
486} 503}
487 504
488/* Note: The bitmask for the beep enable/disable is different than 505/*
489 the bitmask for the alarm. */ 506 * Note: The bitmask for the beep enable/disable is different than
507 * the bitmask for the alarm.
508 */
490static struct sensor_device_attribute sda_in_beep[] = { 509static struct sensor_device_attribute sda_in_beep[] = {
491 SENSOR_ATTR(in0_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 0), 510 SENSOR_ATTR(in0_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 0),
492 SENSOR_ATTR(in1_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 13), 511 SENSOR_ATTR(in1_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 13),
@@ -521,7 +540,7 @@ static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
521 to_sensor_dev_attr(attr); \ 540 to_sensor_dev_attr(attr); \
522 struct w83791d_data *data = w83791d_update_device(dev); \ 541 struct w83791d_data *data = w83791d_update_device(dev); \
523 int nr = sensor_attr->index; \ 542 int nr = sensor_attr->index; \
524 return sprintf(buf,"%d\n", \ 543 return sprintf(buf, "%d\n", \
525 FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \ 544 FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \
526} 545}
527 546
@@ -534,8 +553,13 @@ static ssize_t store_fan_min(struct device *dev, struct device_attribute *attr,
534 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 553 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
535 struct i2c_client *client = to_i2c_client(dev); 554 struct i2c_client *client = to_i2c_client(dev);
536 struct w83791d_data *data = i2c_get_clientdata(client); 555 struct w83791d_data *data = i2c_get_clientdata(client);
537 unsigned long val = simple_strtoul(buf, NULL, 10);
538 int nr = sensor_attr->index; 556 int nr = sensor_attr->index;
557 unsigned long val;
558 int err;
559
560 err = kstrtoul(buf, 10, &val);
561 if (err)
562 return err;
539 563
540 mutex_lock(&data->update_lock); 564 mutex_lock(&data->update_lock);
541 data->fan_min[nr] = fan_to_reg(val, DIV_FROM_REG(data->fan_div[nr])); 565 data->fan_min[nr] = fan_to_reg(val, DIV_FROM_REG(data->fan_div[nr]));
@@ -554,10 +578,12 @@ static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
554 return sprintf(buf, "%u\n", DIV_FROM_REG(data->fan_div[nr])); 578 return sprintf(buf, "%u\n", DIV_FROM_REG(data->fan_div[nr]));
555} 579}
556 580
557/* Note: we save and restore the fan minimum here, because its value is 581/*
558 determined in part by the fan divisor. This follows the principle of 582 * Note: we save and restore the fan minimum here, because its value is
559 least surprise; the user doesn't expect the fan minimum to change just 583 * determined in part by the fan divisor. This follows the principle of
560 because the divisor changed. */ 584 * least surprise; the user doesn't expect the fan minimum to change just
585 * because the divisor changed.
586 */
561static ssize_t store_fan_div(struct device *dev, struct device_attribute *attr, 587static ssize_t store_fan_div(struct device *dev, struct device_attribute *attr,
562 const char *buf, size_t count) 588 const char *buf, size_t count)
563{ 589{
@@ -572,12 +598,18 @@ static ssize_t store_fan_div(struct device *dev, struct device_attribute *attr,
572 int indx = 0; 598 int indx = 0;
573 u8 keep_mask = 0; 599 u8 keep_mask = 0;
574 u8 new_shift = 0; 600 u8 new_shift = 0;
601 unsigned long val;
602 int err;
603
604 err = kstrtoul(buf, 10, &val);
605 if (err)
606 return err;
575 607
576 /* Save fan_min */ 608 /* Save fan_min */
577 min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])); 609 min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]));
578 610
579 mutex_lock(&data->update_lock); 611 mutex_lock(&data->update_lock);
580 data->fan_div[nr] = div_to_reg(nr, simple_strtoul(buf, NULL, 10)); 612 data->fan_div[nr] = div_to_reg(nr, val);
581 613
582 switch (nr) { 614 switch (nr) {
583 case 0: 615 case 0:
@@ -918,8 +950,13 @@ static ssize_t store_temp1(struct device *dev, struct device_attribute *devattr,
918 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 950 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
919 struct i2c_client *client = to_i2c_client(dev); 951 struct i2c_client *client = to_i2c_client(dev);
920 struct w83791d_data *data = i2c_get_clientdata(client); 952 struct w83791d_data *data = i2c_get_clientdata(client);
921 long val = simple_strtol(buf, NULL, 10);
922 int nr = attr->index; 953 int nr = attr->index;
954 long val;
955 int err;
956
957 err = kstrtol(buf, 10, &val);
958 if (err)
959 return err;
923 960
924 mutex_lock(&data->update_lock); 961 mutex_lock(&data->update_lock);
925 data->temp1[nr] = TEMP1_TO_REG(val); 962 data->temp1[nr] = TEMP1_TO_REG(val);
@@ -946,10 +983,15 @@ static ssize_t store_temp23(struct device *dev,
946 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 983 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
947 struct i2c_client *client = to_i2c_client(dev); 984 struct i2c_client *client = to_i2c_client(dev);
948 struct w83791d_data *data = i2c_get_clientdata(client); 985 struct w83791d_data *data = i2c_get_clientdata(client);
949 long val = simple_strtol(buf, NULL, 10); 986 long val;
987 int err;
950 int nr = attr->nr; 988 int nr = attr->nr;
951 int index = attr->index; 989 int index = attr->index;
952 990
991 err = kstrtol(buf, 10, &val);
992 if (err)
993 return err;
994
953 mutex_lock(&data->update_lock); 995 mutex_lock(&data->update_lock);
954 data->temp_add[nr][index] = TEMP23_TO_REG(val); 996 data->temp_add[nr][index] = TEMP23_TO_REG(val);
955 w83791d_write(client, W83791D_REG_TEMP_ADD[nr][index * 2], 997 w83791d_write(client, W83791D_REG_TEMP_ADD[nr][index * 2],
@@ -985,8 +1027,10 @@ static struct sensor_device_attribute_2 sda_temp_max_hyst[] = {
985 show_temp23, store_temp23, 1, 2), 1027 show_temp23, store_temp23, 1, 2),
986}; 1028};
987 1029
988/* Note: The bitmask for the beep enable/disable is different than 1030/*
989 the bitmask for the alarm. */ 1031 * Note: The bitmask for the beep enable/disable is different than
1032 * the bitmask for the alarm.
1033 */
990static struct sensor_device_attribute sda_temp_beep[] = { 1034static struct sensor_device_attribute sda_temp_beep[] = {
991 SENSOR_ATTR(temp1_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 4), 1035 SENSOR_ATTR(temp1_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 4),
992 SENSOR_ATTR(temp2_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 5), 1036 SENSOR_ATTR(temp2_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 5),
@@ -1035,13 +1079,20 @@ static ssize_t store_beep_mask(struct device *dev,
1035{ 1079{
1036 struct i2c_client *client = to_i2c_client(dev); 1080 struct i2c_client *client = to_i2c_client(dev);
1037 struct w83791d_data *data = i2c_get_clientdata(client); 1081 struct w83791d_data *data = i2c_get_clientdata(client);
1038 long val = simple_strtol(buf, NULL, 10);
1039 int i; 1082 int i;
1083 long val;
1084 int err;
1085
1086 err = kstrtol(buf, 10, &val);
1087 if (err)
1088 return err;
1040 1089
1041 mutex_lock(&data->update_lock); 1090 mutex_lock(&data->update_lock);
1042 1091
1043 /* The beep_enable state overrides any enabling request from 1092 /*
1044 the masks */ 1093 * The beep_enable state overrides any enabling request from
1094 * the masks
1095 */
1045 data->beep_mask = BEEP_MASK_TO_REG(val) & ~GLOBAL_BEEP_ENABLE_MASK; 1096 data->beep_mask = BEEP_MASK_TO_REG(val) & ~GLOBAL_BEEP_ENABLE_MASK;
1046 data->beep_mask |= (data->beep_enable << GLOBAL_BEEP_ENABLE_SHIFT); 1097 data->beep_mask |= (data->beep_enable << GLOBAL_BEEP_ENABLE_SHIFT);
1047 1098
@@ -1063,7 +1114,12 @@ static ssize_t store_beep_enable(struct device *dev,
1063{ 1114{
1064 struct i2c_client *client = to_i2c_client(dev); 1115 struct i2c_client *client = to_i2c_client(dev);
1065 struct w83791d_data *data = i2c_get_clientdata(client); 1116 struct w83791d_data *data = i2c_get_clientdata(client);
1066 long val = simple_strtol(buf, NULL, 10); 1117 long val;
1118 int err;
1119
1120 err = kstrtol(buf, 10, &val);
1121 if (err)
1122 return err;
1067 1123
1068 mutex_lock(&data->update_lock); 1124 mutex_lock(&data->update_lock);
1069 1125
@@ -1073,8 +1129,10 @@ static ssize_t store_beep_enable(struct device *dev,
1073 data->beep_mask &= ~GLOBAL_BEEP_ENABLE_MASK; 1129 data->beep_mask &= ~GLOBAL_BEEP_ENABLE_MASK;
1074 data->beep_mask |= (data->beep_enable << GLOBAL_BEEP_ENABLE_SHIFT); 1130 data->beep_mask |= (data->beep_enable << GLOBAL_BEEP_ENABLE_SHIFT);
1075 1131
1076 /* The global control is in the second beep control register 1132 /*
1077 so only need to update that register */ 1133 * The global control is in the second beep control register
1134 * so only need to update that register
1135 */
1078 val = (data->beep_mask >> 8) & 0xff; 1136 val = (data->beep_mask >> 8) & 0xff;
1079 1137
1080 w83791d_write(client, W83791D_REG_BEEP_CTRL[1], val); 1138 w83791d_write(client, W83791D_REG_BEEP_CTRL[1], val);
@@ -1113,36 +1171,44 @@ static ssize_t store_vrm_reg(struct device *dev,
1113 const char *buf, size_t count) 1171 const char *buf, size_t count)
1114{ 1172{
1115 struct w83791d_data *data = dev_get_drvdata(dev); 1173 struct w83791d_data *data = dev_get_drvdata(dev);
1174 unsigned long val;
1175 int err;
1176
1177 /*
1178 * No lock needed as vrm is internal to the driver
1179 * (not read from a chip register) and so is not
1180 * updated in w83791d_update_device()
1181 */
1116 1182
1117 /* No lock needed as vrm is internal to the driver 1183 err = kstrtoul(buf, 10, &val);
1118 (not read from a chip register) and so is not 1184 if (err)
1119 updated in w83791d_update_device() */ 1185 return err;
1120 data->vrm = simple_strtoul(buf, NULL, 10);
1121 1186
1187 data->vrm = val;
1122 return count; 1188 return count;
1123} 1189}
1124 1190
1125static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); 1191static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
1126 1192
1127#define IN_UNIT_ATTRS(X) \ 1193#define IN_UNIT_ATTRS(X) \
1128 &sda_in_input[X].dev_attr.attr, \ 1194 &sda_in_input[X].dev_attr.attr, \
1129 &sda_in_min[X].dev_attr.attr, \ 1195 &sda_in_min[X].dev_attr.attr, \
1130 &sda_in_max[X].dev_attr.attr, \ 1196 &sda_in_max[X].dev_attr.attr, \
1131 &sda_in_beep[X].dev_attr.attr, \ 1197 &sda_in_beep[X].dev_attr.attr, \
1132 &sda_in_alarm[X].dev_attr.attr 1198 &sda_in_alarm[X].dev_attr.attr
1133 1199
1134#define FAN_UNIT_ATTRS(X) \ 1200#define FAN_UNIT_ATTRS(X) \
1135 &sda_fan_input[X].dev_attr.attr, \ 1201 &sda_fan_input[X].dev_attr.attr, \
1136 &sda_fan_min[X].dev_attr.attr, \ 1202 &sda_fan_min[X].dev_attr.attr, \
1137 &sda_fan_div[X].dev_attr.attr, \ 1203 &sda_fan_div[X].dev_attr.attr, \
1138 &sda_fan_beep[X].dev_attr.attr, \ 1204 &sda_fan_beep[X].dev_attr.attr, \
1139 &sda_fan_alarm[X].dev_attr.attr 1205 &sda_fan_alarm[X].dev_attr.attr
1140 1206
1141#define TEMP_UNIT_ATTRS(X) \ 1207#define TEMP_UNIT_ATTRS(X) \
1142 &sda_temp_input[X].dev_attr.attr, \ 1208 &sda_temp_input[X].dev_attr.attr, \
1143 &sda_temp_max[X].dev_attr.attr, \ 1209 &sda_temp_max[X].dev_attr.attr, \
1144 &sda_temp_max_hyst[X].dev_attr.attr, \ 1210 &sda_temp_max_hyst[X].dev_attr.attr, \
1145 &sda_temp_beep[X].dev_attr.attr, \ 1211 &sda_temp_beep[X].dev_attr.attr, \
1146 &sda_temp_alarm[X].dev_attr.attr 1212 &sda_temp_alarm[X].dev_attr.attr
1147 1213
1148static struct attribute *w83791d_attributes[] = { 1214static struct attribute *w83791d_attributes[] = {
@@ -1186,9 +1252,11 @@ static const struct attribute_group w83791d_group = {
1186 .attrs = w83791d_attributes, 1252 .attrs = w83791d_attributes,
1187}; 1253};
1188 1254
1189/* Separate group of attributes for fan/pwm 4-5. Their pins can also be 1255/*
1190 in use for GPIO in which case their sysfs-interface should not be made 1256 * Separate group of attributes for fan/pwm 4-5. Their pins can also be
1191 available */ 1257 * in use for GPIO in which case their sysfs-interface should not be made
1258 * available
1259 */
1192static struct attribute *w83791d_attributes_fanpwm45[] = { 1260static struct attribute *w83791d_attributes_fanpwm45[] = {
1193 FAN_UNIT_ATTRS(3), 1261 FAN_UNIT_ATTRS(3),
1194 FAN_UNIT_ATTRS(4), 1262 FAN_UNIT_ATTRS(4),
@@ -1228,9 +1296,8 @@ static int w83791d_detect_subclients(struct i2c_client *client)
1228 } 1296 }
1229 1297
1230 val = w83791d_read(client, W83791D_REG_I2C_SUBADDR); 1298 val = w83791d_read(client, W83791D_REG_I2C_SUBADDR);
1231 if (!(val & 0x08)) { 1299 if (!(val & 0x08))
1232 data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (val & 0x7)); 1300 data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (val & 0x7));
1233 }
1234 if (!(val & 0x80)) { 1301 if (!(val & 0x80)) {
1235 if ((data->lm75[0] != NULL) && 1302 if ((data->lm75[0] != NULL) &&
1236 ((val & 0x7) == ((val >> 4) & 0x7))) { 1303 ((val & 0x7) == ((val >> 4) & 0x7))) {
@@ -1265,9 +1332,8 @@ static int w83791d_detect(struct i2c_client *client,
1265 int val1, val2; 1332 int val1, val2;
1266 unsigned short address = client->addr; 1333 unsigned short address = client->addr;
1267 1334
1268 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 1335 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1269 return -ENODEV; 1336 return -ENODEV;
1270 }
1271 1337
1272 if (w83791d_read(client, W83791D_REG_CONFIG) & 0x80) 1338 if (w83791d_read(client, W83791D_REG_CONFIG) & 0x80)
1273 return -ENODEV; 1339 return -ENODEV;
@@ -1277,12 +1343,14 @@ static int w83791d_detect(struct i2c_client *client,
1277 /* Check for Winbond ID if in bank 0 */ 1343 /* Check for Winbond ID if in bank 0 */
1278 if (!(val1 & 0x07)) { 1344 if (!(val1 & 0x07)) {
1279 if ((!(val1 & 0x80) && val2 != 0xa3) || 1345 if ((!(val1 & 0x80) && val2 != 0xa3) ||
1280 ( (val1 & 0x80) && val2 != 0x5c)) { 1346 ((val1 & 0x80) && val2 != 0x5c)) {
1281 return -ENODEV; 1347 return -ENODEV;
1282 } 1348 }
1283 } 1349 }
1284 /* If Winbond chip, address of chip and W83791D_REG_I2C_ADDR 1350 /*
1285 should match */ 1351 * If Winbond chip, address of chip and W83791D_REG_I2C_ADDR
1352 * should match
1353 */
1286 if (w83791d_read(client, W83791D_REG_I2C_ADDR) != address) 1354 if (w83791d_read(client, W83791D_REG_I2C_ADDR) != address)
1287 return -ENODEV; 1355 return -ENODEV;
1288 1356
@@ -1332,14 +1400,16 @@ static int w83791d_probe(struct i2c_client *client,
1332 /* Initialize the chip */ 1400 /* Initialize the chip */
1333 w83791d_init_client(client); 1401 w83791d_init_client(client);
1334 1402
1335 /* If the fan_div is changed, make sure there is a rational 1403 /*
1336 fan_min in place */ 1404 * If the fan_div is changed, make sure there is a rational
1337 for (i = 0; i < NUMBER_OF_FANIN; i++) { 1405 * fan_min in place
1406 */
1407 for (i = 0; i < NUMBER_OF_FANIN; i++)
1338 data->fan_min[i] = w83791d_read(client, W83791D_REG_FAN_MIN[i]); 1408 data->fan_min[i] = w83791d_read(client, W83791D_REG_FAN_MIN[i]);
1339 }
1340 1409
1341 /* Register sysfs hooks */ 1410 /* Register sysfs hooks */
1342 if ((err = sysfs_create_group(&client->dev.kobj, &w83791d_group))) 1411 err = sysfs_create_group(&client->dev.kobj, &w83791d_group);
1412 if (err)
1343 goto error3; 1413 goto error3;
1344 1414
1345 /* Check if pins of fan/pwm 4-5 are in use as GPIO */ 1415 /* Check if pins of fan/pwm 4-5 are in use as GPIO */
@@ -1398,19 +1468,20 @@ static void w83791d_init_client(struct i2c_client *client)
1398 u8 tmp; 1468 u8 tmp;
1399 u8 old_beep; 1469 u8 old_beep;
1400 1470
1401 /* The difference between reset and init is that reset 1471 /*
1402 does a hard reset of the chip via index 0x40, bit 7, 1472 * The difference between reset and init is that reset
1403 but init simply forces certain registers to have "sane" 1473 * does a hard reset of the chip via index 0x40, bit 7,
1404 values. The hope is that the BIOS has done the right 1474 * but init simply forces certain registers to have "sane"
1405 thing (which is why the default is reset=0, init=0), 1475 * values. The hope is that the BIOS has done the right
1406 but if not, reset is the hard hammer and init 1476 * thing (which is why the default is reset=0, init=0),
1407 is the soft mallet both of which are trying to whack 1477 * but if not, reset is the hard hammer and init
1408 things into place... 1478 * is the soft mallet both of which are trying to whack
1409 NOTE: The data sheet makes a distinction between 1479 * things into place...
1410 "power on defaults" and "reset by MR". As far as I can tell, 1480 * NOTE: The data sheet makes a distinction between
1411 the hard reset puts everything into a power-on state so I'm 1481 * "power on defaults" and "reset by MR". As far as I can tell,
1412 not sure what "reset by MR" means or how it can happen. 1482 * the hard reset puts everything into a power-on state so I'm
1413 */ 1483 * not sure what "reset by MR" means or how it can happen.
1484 */
1414 if (reset || init) { 1485 if (reset || init) {
1415 /* keep some BIOS settings when we... */ 1486 /* keep some BIOS settings when we... */
1416 old_beep = w83791d_read(client, W83791D_REG_BEEP_CONFIG); 1487 old_beep = w83791d_read(client, W83791D_REG_BEEP_CONFIG);
@@ -1494,8 +1565,10 @@ static struct w83791d_data *w83791d_update_device(struct device *dev)
1494 data->fan_div[3] = reg_array_tmp[2] & 0x07; 1565 data->fan_div[3] = reg_array_tmp[2] & 0x07;
1495 data->fan_div[4] = (reg_array_tmp[2] >> 4) & 0x07; 1566 data->fan_div[4] = (reg_array_tmp[2] >> 4) & 0x07;
1496 1567
1497 /* The fan divisor for fans 0-2 get bit 2 from 1568 /*
1498 bits 5-7 respectively of vbat register */ 1569 * The fan divisor for fans 0-2 get bit 2 from
1570 * bits 5-7 respectively of vbat register
1571 */
1499 vbat_reg = w83791d_read(client, W83791D_REG_VBAT); 1572 vbat_reg = w83791d_read(client, W83791D_REG_VBAT);
1500 for (i = 0; i < 3; i++) 1573 for (i = 0; i < 3; i++)
1501 data->fan_div[i] |= (vbat_reg >> (3 + i)) & 0x04; 1574 data->fan_div[i] |= (vbat_reg >> (3 + i)) & 0x04;
@@ -1601,12 +1674,13 @@ static void w83791d_print_debug(struct w83791d_data *data, struct device *dev)
1601 dev_dbg(dev, "fan_div[%d] is: 0x%02x\n", i, data->fan_div[i]); 1674 dev_dbg(dev, "fan_div[%d] is: 0x%02x\n", i, data->fan_div[i]);
1602 } 1675 }
1603 1676
1604 /* temperature math is signed, but only print out the 1677 /*
1605 bits that matter */ 1678 * temperature math is signed, but only print out the
1679 * bits that matter
1680 */
1606 dev_dbg(dev, "%d set of Temperatures: ===>\n", NUMBER_OF_TEMPIN); 1681 dev_dbg(dev, "%d set of Temperatures: ===>\n", NUMBER_OF_TEMPIN);
1607 for (i = 0; i < 3; i++) { 1682 for (i = 0; i < 3; i++)
1608 dev_dbg(dev, "temp1[%d] is: 0x%02x\n", i, (u8) data->temp1[i]); 1683 dev_dbg(dev, "temp1[%d] is: 0x%02x\n", i, (u8) data->temp1[i]);
1609 }
1610 for (i = 0; i < 2; i++) { 1684 for (i = 0; i < 2; i++) {
1611 for (j = 0; j < 3; j++) { 1685 for (j = 0; j < 3; j++) {
1612 dev_dbg(dev, "temp_add[%d][%d] is: 0x%04x\n", i, j, 1686 dev_dbg(dev, "temp_add[%d][%d] is: 0x%04x\n", i, j,
@@ -1625,19 +1699,8 @@ static void w83791d_print_debug(struct w83791d_data *data, struct device *dev)
1625} 1699}
1626#endif 1700#endif
1627 1701
1628static int __init sensors_w83791d_init(void) 1702module_i2c_driver(w83791d_driver);
1629{
1630 return i2c_add_driver(&w83791d_driver);
1631}
1632
1633static void __exit sensors_w83791d_exit(void)
1634{
1635 i2c_del_driver(&w83791d_driver);
1636}
1637 1703
1638MODULE_AUTHOR("Charles Spirakis <bezaur@gmail.com>"); 1704MODULE_AUTHOR("Charles Spirakis <bezaur@gmail.com>");
1639MODULE_DESCRIPTION("W83791D driver"); 1705MODULE_DESCRIPTION("W83791D driver");
1640MODULE_LICENSE("GPL"); 1706MODULE_LICENSE("GPL");
1641
1642module_init(sensors_w83791d_init);
1643module_exit(sensors_w83791d_exit);
diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c
index d3100eab6b2f..ffb5fdfecf0d 100644
--- a/drivers/hwmon/w83792d.c
+++ b/drivers/hwmon/w83792d.c
@@ -1,39 +1,39 @@
1/* 1/*
2 w83792d.c - Part of lm_sensors, Linux kernel modules for hardware 2 * w83792d.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 * monitoring
4 Copyright (C) 2004, 2005 Winbond Electronics Corp. 4 * Copyright (C) 2004, 2005 Winbond Electronics Corp.
5 Chunhao Huang <DZShen@Winbond.com.tw>, 5 * Chunhao Huang <DZShen@Winbond.com.tw>,
6 Rudolf Marek <r.marek@assembler.cz> 6 * Rudolf Marek <r.marek@assembler.cz>
7 7 *
8 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 * (at your option) any later version.
12 12 *
13 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 * GNU General Public License for more details.
17 17 *
18 You should have received a copy of the GNU General Public License 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 19 * along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 21 *
22 Note: 22 * Note:
23 1. This driver is only for 2.6 kernel, 2.4 kernel need a different driver. 23 * 1. This driver is only for 2.6 kernel, 2.4 kernel need a different driver.
24 2. This driver is only for Winbond W83792D C version device, there 24 * 2. This driver is only for Winbond W83792D C version device, there
25 are also some motherboards with B version W83792D device. The 25 * are also some motherboards with B version W83792D device. The
26 calculation method to in6-in7(measured value, limits) is a little 26 * calculation method to in6-in7(measured value, limits) is a little
27 different between C and B version. C or B version can be identified 27 * different between C and B version. C or B version can be identified
28 by CR[0x49h]. 28 * by CR[0x49h].
29*/ 29 */
30 30
31/* 31/*
32 Supports following chips: 32 * Supports following chips:
33 33 *
34 Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA 34 * Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
35 w83792d 9 7 7 3 0x7a 0x5ca3 yes no 35 * w83792d 9 7 7 3 0x7a 0x5ca3 yes no
36*/ 36 */
37 37
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/init.h> 39#include <linux/init.h>
@@ -218,14 +218,16 @@ static const u8 W83792D_REG_LEVELS[3][4] = {
218#define W83792D_REG_VBAT 0x5D 218#define W83792D_REG_VBAT 0x5D
219#define W83792D_REG_I2C_ADDR 0x48 219#define W83792D_REG_I2C_ADDR 0x48
220 220
221/* Conversions. Rounding and limit checking is only done on the TO_REG 221/*
222 variants. Note that you should be a bit careful with which arguments 222 * Conversions. Rounding and limit checking is only done on the TO_REG
223 these macros are called: arguments may be evaluated more than once. 223 * variants. Note that you should be a bit careful with which arguments
224 Fixing this is just not worth it. */ 224 * these macros are called: arguments may be evaluated more than once.
225#define IN_FROM_REG(nr,val) (((nr)<=1)?(val*2): \ 225 * Fixing this is just not worth it.
226 ((((nr)==6)||((nr)==7))?(val*6):(val*4))) 226 */
227#define IN_TO_REG(nr,val) (((nr)<=1)?(val/2): \ 227#define IN_FROM_REG(nr, val) (((nr) <= 1) ? ((val) * 2) : \
228 ((((nr)==6)||((nr)==7))?(val/6):(val/4))) 228 ((((nr) == 6) || ((nr) == 7)) ? ((val) * 6) : ((val) * 4)))
229#define IN_TO_REG(nr, val) (((nr) <= 1) ? ((val) / 2) : \
230 ((((nr) == 6) || ((nr) == 7)) ? ((val) / 6) : ((val) / 4)))
229 231
230static inline u8 232static inline u8
231FAN_TO_REG(long rpm, int div) 233FAN_TO_REG(long rpm, int div)
@@ -236,7 +238,7 @@ FAN_TO_REG(long rpm, int div)
236 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); 238 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
237} 239}
238 240
239#define FAN_FROM_REG(val,div) ((val) == 0 ? -1 : \ 241#define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \
240 ((val) == 255 ? 0 : \ 242 ((val) == 255 ? 0 : \
241 1350000 / ((val) * (div)))) 243 1350000 / ((val) * (div))))
242 244
@@ -265,7 +267,7 @@ DIV_TO_REG(long val)
265 break; 267 break;
266 val >>= 1; 268 val >>= 1;
267 } 269 }
268 return ((u8) i); 270 return (u8)i;
269} 271}
270 272
271struct w83792d_data { 273struct w83792d_data {
@@ -287,8 +289,10 @@ struct w83792d_data {
287 u8 temp1[3]; /* current, over, thyst */ 289 u8 temp1[3]; /* current, over, thyst */
288 u8 temp_add[2][6]; /* Register value */ 290 u8 temp_add[2][6]; /* Register value */
289 u8 fan_div[7]; /* Register encoding, shifted right */ 291 u8 fan_div[7]; /* Register encoding, shifted right */
290 u8 pwm[7]; /* We only consider the first 3 set of pwm, 292 u8 pwm[7]; /*
291 although 792 chip has 7 set of pwm. */ 293 * We only consider the first 3 set of pwm,
294 * although 792 chip has 7 set of pwm.
295 */
292 u8 pwmenable[3]; 296 u8 pwmenable[3];
293 u32 alarms; /* realtime status register encoding,combined */ 297 u32 alarms; /* realtime status register encoding,combined */
294 u8 chassis; /* Chassis status */ 298 u8 chassis; /* Chassis status */
@@ -333,12 +337,14 @@ static struct i2c_driver w83792d_driver = {
333static inline long in_count_from_reg(int nr, struct w83792d_data *data) 337static inline long in_count_from_reg(int nr, struct w83792d_data *data)
334{ 338{
335 /* in7 and in8 do not have low bits, but the formula still works */ 339 /* in7 and in8 do not have low bits, but the formula still works */
336 return ((data->in[nr] << 2) | ((data->low_bits >> (2 * nr)) & 0x03)); 340 return (data->in[nr] << 2) | ((data->low_bits >> (2 * nr)) & 0x03);
337} 341}
338 342
339/* The SMBus locks itself. The Winbond W83792D chip has a bank register, 343/*
340 but the driver only accesses registers in bank 0, so we don't have 344 * The SMBus locks itself. The Winbond W83792D chip has a bank register,
341 to switch banks and lock access between switches. */ 345 * but the driver only accesses registers in bank 0, so we don't have
346 * to switch banks and lock access between switches.
347 */
342static inline int w83792d_read_value(struct i2c_client *client, u8 reg) 348static inline int w83792d_read_value(struct i2c_client *client, u8 reg)
343{ 349{
344 return i2c_smbus_read_byte_data(client, reg); 350 return i2c_smbus_read_byte_data(client, reg);
@@ -357,37 +363,43 @@ static ssize_t show_in(struct device *dev, struct device_attribute *attr,
357 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 363 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
358 int nr = sensor_attr->index; 364 int nr = sensor_attr->index;
359 struct w83792d_data *data = w83792d_update_device(dev); 365 struct w83792d_data *data = w83792d_update_device(dev);
360 return sprintf(buf,"%ld\n", IN_FROM_REG(nr,(in_count_from_reg(nr, data)))); 366 return sprintf(buf, "%ld\n",
367 IN_FROM_REG(nr, in_count_from_reg(nr, data)));
361} 368}
362 369
363#define show_in_reg(reg) \ 370#define show_in_reg(reg) \
364static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ 371static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
365 char *buf) \ 372 char *buf) \
366{ \ 373{ \
367 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ 374 struct sensor_device_attribute *sensor_attr \
375 = to_sensor_dev_attr(attr); \
368 int nr = sensor_attr->index; \ 376 int nr = sensor_attr->index; \
369 struct w83792d_data *data = w83792d_update_device(dev); \ 377 struct w83792d_data *data = w83792d_update_device(dev); \
370 return sprintf(buf,"%ld\n", (long)(IN_FROM_REG(nr, (data->reg[nr])*4))); \ 378 return sprintf(buf, "%ld\n", \
379 (long)(IN_FROM_REG(nr, data->reg[nr]) * 4)); \
371} 380}
372 381
373show_in_reg(in_min); 382show_in_reg(in_min);
374show_in_reg(in_max); 383show_in_reg(in_max);
375 384
376#define store_in_reg(REG, reg) \ 385#define store_in_reg(REG, reg) \
377static ssize_t store_in_##reg (struct device *dev, \ 386static ssize_t store_in_##reg(struct device *dev, \
378 struct device_attribute *attr, \ 387 struct device_attribute *attr, \
379 const char *buf, size_t count) \ 388 const char *buf, size_t count) \
380{ \ 389{ \
381 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ 390 struct sensor_device_attribute *sensor_attr \
391 = to_sensor_dev_attr(attr); \
382 int nr = sensor_attr->index; \ 392 int nr = sensor_attr->index; \
383 struct i2c_client *client = to_i2c_client(dev); \ 393 struct i2c_client *client = to_i2c_client(dev); \
384 struct w83792d_data *data = i2c_get_clientdata(client); \ 394 struct w83792d_data *data = i2c_get_clientdata(client); \
385 u32 val; \ 395 unsigned long val; \
386 \ 396 int err = kstrtoul(buf, 10, &val); \
387 val = simple_strtoul(buf, NULL, 10); \ 397 if (err) \
398 return err; \
388 mutex_lock(&data->update_lock); \ 399 mutex_lock(&data->update_lock); \
389 data->in_##reg[nr] = SENSORS_LIMIT(IN_TO_REG(nr, val)/4, 0, 255); \ 400 data->in_##reg[nr] = SENSORS_LIMIT(IN_TO_REG(nr, val) / 4, 0, 255); \
390 w83792d_write_value(client, W83792D_REG_IN_##REG[nr], data->in_##reg[nr]); \ 401 w83792d_write_value(client, W83792D_REG_IN_##REG[nr], \
402 data->in_##reg[nr]); \
391 mutex_unlock(&data->update_lock); \ 403 mutex_unlock(&data->update_lock); \
392 \ 404 \
393 return count; \ 405 return count; \
@@ -396,13 +408,14 @@ store_in_reg(MIN, min);
396store_in_reg(MAX, max); 408store_in_reg(MAX, max);
397 409
398#define show_fan_reg(reg) \ 410#define show_fan_reg(reg) \
399static ssize_t show_##reg (struct device *dev, struct device_attribute *attr, \ 411static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
400 char *buf) \ 412 char *buf) \
401{ \ 413{ \
402 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ 414 struct sensor_device_attribute *sensor_attr \
415 = to_sensor_dev_attr(attr); \
403 int nr = sensor_attr->index - 1; \ 416 int nr = sensor_attr->index - 1; \
404 struct w83792d_data *data = w83792d_update_device(dev); \ 417 struct w83792d_data *data = w83792d_update_device(dev); \
405 return sprintf(buf,"%d\n", \ 418 return sprintf(buf, "%d\n", \
406 FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \ 419 FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \
407} 420}
408 421
@@ -417,9 +430,13 @@ store_fan_min(struct device *dev, struct device_attribute *attr,
417 int nr = sensor_attr->index - 1; 430 int nr = sensor_attr->index - 1;
418 struct i2c_client *client = to_i2c_client(dev); 431 struct i2c_client *client = to_i2c_client(dev);
419 struct w83792d_data *data = i2c_get_clientdata(client); 432 struct w83792d_data *data = i2c_get_clientdata(client);
420 u32 val; 433 unsigned long val;
434 int err;
435
436 err = kstrtoul(buf, 10, &val);
437 if (err)
438 return err;
421 439
422 val = simple_strtoul(buf, NULL, 10);
423 mutex_lock(&data->update_lock); 440 mutex_lock(&data->update_lock);
424 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 441 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
425 w83792d_write_value(client, W83792D_REG_FAN_MIN[nr], 442 w83792d_write_value(client, W83792D_REG_FAN_MIN[nr],
@@ -439,10 +456,12 @@ show_fan_div(struct device *dev, struct device_attribute *attr,
439 return sprintf(buf, "%u\n", DIV_FROM_REG(data->fan_div[nr - 1])); 456 return sprintf(buf, "%u\n", DIV_FROM_REG(data->fan_div[nr - 1]));
440} 457}
441 458
442/* Note: we save and restore the fan minimum here, because its value is 459/*
443 determined in part by the fan divisor. This follows the principle of 460 * Note: we save and restore the fan minimum here, because its value is
444 least surprise; the user doesn't expect the fan minimum to change just 461 * determined in part by the fan divisor. This follows the principle of
445 because the divisor changed. */ 462 * least surprise; the user doesn't expect the fan minimum to change just
463 * because the divisor changed.
464 */
446static ssize_t 465static ssize_t
447store_fan_div(struct device *dev, struct device_attribute *attr, 466store_fan_div(struct device *dev, struct device_attribute *attr,
448 const char *buf, size_t count) 467 const char *buf, size_t count)
@@ -455,13 +474,19 @@ store_fan_div(struct device *dev, struct device_attribute *attr,
455 /*u8 reg;*/ 474 /*u8 reg;*/
456 u8 fan_div_reg = 0; 475 u8 fan_div_reg = 0;
457 u8 tmp_fan_div; 476 u8 tmp_fan_div;
477 unsigned long val;
478 int err;
479
480 err = kstrtoul(buf, 10, &val);
481 if (err)
482 return err;
458 483
459 /* Save fan_min */ 484 /* Save fan_min */
460 mutex_lock(&data->update_lock); 485 mutex_lock(&data->update_lock);
461 min = FAN_FROM_REG(data->fan_min[nr], 486 min = FAN_FROM_REG(data->fan_min[nr],
462 DIV_FROM_REG(data->fan_div[nr])); 487 DIV_FROM_REG(data->fan_div[nr]));
463 488
464 data->fan_div[nr] = DIV_TO_REG(simple_strtoul(buf, NULL, 10)); 489 data->fan_div[nr] = DIV_TO_REG(val);
465 490
466 fan_div_reg = w83792d_read_value(client, W83792D_REG_FAN_DIV[nr >> 1]); 491 fan_div_reg = w83792d_read_value(client, W83792D_REG_FAN_DIV[nr >> 1]);
467 fan_div_reg &= (nr & 0x01) ? 0x8f : 0xf8; 492 fan_div_reg &= (nr & 0x01) ? 0x8f : 0xf8;
@@ -496,9 +521,13 @@ static ssize_t store_temp1(struct device *dev, struct device_attribute *attr,
496 int nr = sensor_attr->index; 521 int nr = sensor_attr->index;
497 struct i2c_client *client = to_i2c_client(dev); 522 struct i2c_client *client = to_i2c_client(dev);
498 struct w83792d_data *data = i2c_get_clientdata(client); 523 struct w83792d_data *data = i2c_get_clientdata(client);
499 s32 val; 524 long val;
525 int err;
526
527 err = kstrtol(buf, 10, &val);
528 if (err)
529 return err;
500 530
501 val = simple_strtol(buf, NULL, 10);
502 mutex_lock(&data->update_lock); 531 mutex_lock(&data->update_lock);
503 data->temp1[nr] = TEMP1_TO_REG(val); 532 data->temp1[nr] = TEMP1_TO_REG(val);
504 w83792d_write_value(client, W83792D_REG_TEMP1[nr], 533 w83792d_write_value(client, W83792D_REG_TEMP1[nr],
@@ -513,11 +542,12 @@ static ssize_t store_temp1(struct device *dev, struct device_attribute *attr,
513static ssize_t show_temp23(struct device *dev, struct device_attribute *attr, 542static ssize_t show_temp23(struct device *dev, struct device_attribute *attr,
514 char *buf) 543 char *buf)
515{ 544{
516 struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr); 545 struct sensor_device_attribute_2 *sensor_attr
546 = to_sensor_dev_attr_2(attr);
517 int nr = sensor_attr->nr; 547 int nr = sensor_attr->nr;
518 int index = sensor_attr->index; 548 int index = sensor_attr->index;
519 struct w83792d_data *data = w83792d_update_device(dev); 549 struct w83792d_data *data = w83792d_update_device(dev);
520 return sprintf(buf,"%ld\n", 550 return sprintf(buf, "%ld\n",
521 (long)TEMP_ADD_FROM_REG(data->temp_add[nr][index], 551 (long)TEMP_ADD_FROM_REG(data->temp_add[nr][index],
522 data->temp_add[nr][index+1])); 552 data->temp_add[nr][index+1]));
523} 553}
@@ -525,14 +555,19 @@ static ssize_t show_temp23(struct device *dev, struct device_attribute *attr,
525static ssize_t store_temp23(struct device *dev, struct device_attribute *attr, 555static ssize_t store_temp23(struct device *dev, struct device_attribute *attr,
526 const char *buf, size_t count) 556 const char *buf, size_t count)
527{ 557{
528 struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr); 558 struct sensor_device_attribute_2 *sensor_attr
559 = to_sensor_dev_attr_2(attr);
529 int nr = sensor_attr->nr; 560 int nr = sensor_attr->nr;
530 int index = sensor_attr->index; 561 int index = sensor_attr->index;
531 struct i2c_client *client = to_i2c_client(dev); 562 struct i2c_client *client = to_i2c_client(dev);
532 struct w83792d_data *data = i2c_get_clientdata(client); 563 struct w83792d_data *data = i2c_get_clientdata(client);
533 s32 val; 564 long val;
565 int err;
566
567 err = kstrtol(buf, 10, &val);
568 if (err)
569 return err;
534 570
535 val = simple_strtol(buf, NULL, 10);
536 mutex_lock(&data->update_lock); 571 mutex_lock(&data->update_lock);
537 data->temp_add[nr][index] = TEMP_ADD_TO_REG_HIGH(val); 572 data->temp_add[nr][index] = TEMP_ADD_TO_REG_HIGH(val);
538 data->temp_add[nr][index+1] = TEMP_ADD_TO_REG_LOW(val); 573 data->temp_add[nr][index+1] = TEMP_ADD_TO_REG_LOW(val);
@@ -604,7 +639,13 @@ store_pwm(struct device *dev, struct device_attribute *attr,
604 int nr = sensor_attr->index; 639 int nr = sensor_attr->index;
605 struct i2c_client *client = to_i2c_client(dev); 640 struct i2c_client *client = to_i2c_client(dev);
606 struct w83792d_data *data = i2c_get_clientdata(client); 641 struct w83792d_data *data = i2c_get_clientdata(client);
607 u8 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 255) >> 4; 642 unsigned long val;
643 int err;
644
645 err = kstrtoul(buf, 10, &val);
646 if (err)
647 return err;
648 val = SENSORS_LIMIT(val, 0, 255) >> 4;
608 649
609 mutex_lock(&data->update_lock); 650 mutex_lock(&data->update_lock);
610 val |= w83792d_read_value(client, W83792D_REG_PWM[nr]) & 0xf0; 651 val |= w83792d_read_value(client, W83792D_REG_PWM[nr]) & 0xf0;
@@ -623,10 +664,14 @@ store_pwmenable(struct device *dev, struct device_attribute *attr,
623 int nr = sensor_attr->index - 1; 664 int nr = sensor_attr->index - 1;
624 struct i2c_client *client = to_i2c_client(dev); 665 struct i2c_client *client = to_i2c_client(dev);
625 struct w83792d_data *data = i2c_get_clientdata(client); 666 struct w83792d_data *data = i2c_get_clientdata(client);
626 u32 val;
627 u8 fan_cfg_tmp, cfg1_tmp, cfg2_tmp, cfg3_tmp, cfg4_tmp; 667 u8 fan_cfg_tmp, cfg1_tmp, cfg2_tmp, cfg3_tmp, cfg4_tmp;
668 unsigned long val;
669 int err;
670
671 err = kstrtoul(buf, 10, &val);
672 if (err)
673 return err;
628 674
629 val = simple_strtoul(buf, NULL, 10);
630 if (val < 1 || val > 3) 675 if (val < 1 || val > 3)
631 return -EINVAL; 676 return -EINVAL;
632 677
@@ -645,7 +690,7 @@ store_pwmenable(struct device *dev, struct device_attribute *attr,
645 cfg1_tmp = data->pwmenable[0]; 690 cfg1_tmp = data->pwmenable[0];
646 cfg2_tmp = (data->pwmenable[1]) << 2; 691 cfg2_tmp = (data->pwmenable[1]) << 2;
647 cfg3_tmp = (data->pwmenable[2]) << 4; 692 cfg3_tmp = (data->pwmenable[2]) << 4;
648 cfg4_tmp = w83792d_read_value(client,W83792D_REG_FAN_CFG) & 0xc0; 693 cfg4_tmp = w83792d_read_value(client, W83792D_REG_FAN_CFG) & 0xc0;
649 fan_cfg_tmp = ((cfg4_tmp | cfg3_tmp) | cfg2_tmp) | cfg1_tmp; 694 fan_cfg_tmp = ((cfg4_tmp | cfg3_tmp) | cfg2_tmp) | cfg1_tmp;
650 w83792d_write_value(client, W83792D_REG_FAN_CFG, fan_cfg_tmp); 695 w83792d_write_value(client, W83792D_REG_FAN_CFG, fan_cfg_tmp);
651 mutex_unlock(&data->update_lock); 696 mutex_unlock(&data->update_lock);
@@ -671,10 +716,13 @@ store_pwm_mode(struct device *dev, struct device_attribute *attr,
671 int nr = sensor_attr->index; 716 int nr = sensor_attr->index;
672 struct i2c_client *client = to_i2c_client(dev); 717 struct i2c_client *client = to_i2c_client(dev);
673 struct w83792d_data *data = i2c_get_clientdata(client); 718 struct w83792d_data *data = i2c_get_clientdata(client);
674 u32 val; 719 unsigned long val;
720 int err;
675 721
676 val = simple_strtoul(buf, NULL, 10); 722 err = kstrtoul(buf, 10, &val);
677 if (val != 0 && val != 1) 723 if (err)
724 return err;
725 if (val > 1)
678 return -EINVAL; 726 return -EINVAL;
679 727
680 mutex_lock(&data->update_lock); 728 mutex_lock(&data->update_lock);
@@ -721,16 +769,20 @@ store_chassis_clear_legacy(struct device *dev, struct device_attribute *attr,
721{ 769{
722 struct i2c_client *client = to_i2c_client(dev); 770 struct i2c_client *client = to_i2c_client(dev);
723 struct w83792d_data *data = i2c_get_clientdata(client); 771 struct w83792d_data *data = i2c_get_clientdata(client);
724 u32 val; 772 unsigned long val;
773 int err;
725 u8 temp1 = 0, temp2 = 0; 774 u8 temp1 = 0, temp2 = 0;
726 775
727 dev_warn(dev, 776 dev_warn(dev,
728 "Attribute %s is deprecated, use intrusion0_alarm instead\n", 777 "Attribute %s is deprecated, use intrusion0_alarm instead\n",
729 "chassis_clear"); 778 "chassis_clear");
730 779
731 val = simple_strtoul(buf, NULL, 10); 780 err = kstrtoul(buf, 10, &val);
781 if (err)
782 return err;
783
732 mutex_lock(&data->update_lock); 784 mutex_lock(&data->update_lock);
733 data->chassis_clear = SENSORS_LIMIT(val, 0 ,1); 785 data->chassis_clear = SENSORS_LIMIT(val, 0, 1);
734 temp1 = ((data->chassis_clear) << 7) & 0x80; 786 temp1 = ((data->chassis_clear) << 7) & 0x80;
735 temp2 = w83792d_read_value(client, 787 temp2 = w83792d_read_value(client,
736 W83792D_REG_CHASSIS_CLR) & 0x7f; 788 W83792D_REG_CHASSIS_CLR) & 0x7f;
@@ -780,14 +832,19 @@ store_thermal_cruise(struct device *dev, struct device_attribute *attr,
780 int nr = sensor_attr->index - 1; 832 int nr = sensor_attr->index - 1;
781 struct i2c_client *client = to_i2c_client(dev); 833 struct i2c_client *client = to_i2c_client(dev);
782 struct w83792d_data *data = i2c_get_clientdata(client); 834 struct w83792d_data *data = i2c_get_clientdata(client);
783 u32 val; 835 u8 target_tmp = 0, target_mask = 0;
784 u8 target_tmp=0, target_mask=0; 836 unsigned long val;
837 int err;
838
839 err = kstrtoul(buf, 10, &val);
840 if (err)
841 return err;
785 842
786 val = simple_strtoul(buf, NULL, 10);
787 target_tmp = val; 843 target_tmp = val;
788 target_tmp = target_tmp & 0x7f; 844 target_tmp = target_tmp & 0x7f;
789 mutex_lock(&data->update_lock); 845 mutex_lock(&data->update_lock);
790 target_mask = w83792d_read_value(client, W83792D_REG_THERMAL[nr]) & 0x80; 846 target_mask = w83792d_read_value(client,
847 W83792D_REG_THERMAL[nr]) & 0x80;
791 data->thermal_cruise[nr] = SENSORS_LIMIT(target_tmp, 0, 255); 848 data->thermal_cruise[nr] = SENSORS_LIMIT(target_tmp, 0, 255);
792 w83792d_write_value(client, W83792D_REG_THERMAL[nr], 849 w83792d_write_value(client, W83792D_REG_THERMAL[nr],
793 (data->thermal_cruise[nr]) | target_mask); 850 (data->thermal_cruise[nr]) | target_mask);
@@ -815,19 +872,22 @@ store_tolerance(struct device *dev, struct device_attribute *attr,
815 int nr = sensor_attr->index - 1; 872 int nr = sensor_attr->index - 1;
816 struct i2c_client *client = to_i2c_client(dev); 873 struct i2c_client *client = to_i2c_client(dev);
817 struct w83792d_data *data = i2c_get_clientdata(client); 874 struct w83792d_data *data = i2c_get_clientdata(client);
818 u32 val;
819 u8 tol_tmp, tol_mask; 875 u8 tol_tmp, tol_mask;
876 unsigned long val;
877 int err;
878
879 err = kstrtoul(buf, 10, &val);
880 if (err)
881 return err;
820 882
821 val = simple_strtoul(buf, NULL, 10);
822 mutex_lock(&data->update_lock); 883 mutex_lock(&data->update_lock);
823 tol_mask = w83792d_read_value(client, 884 tol_mask = w83792d_read_value(client,
824 W83792D_REG_TOLERANCE[nr]) & ((nr == 1) ? 0x0f : 0xf0); 885 W83792D_REG_TOLERANCE[nr]) & ((nr == 1) ? 0x0f : 0xf0);
825 tol_tmp = SENSORS_LIMIT(val, 0, 15); 886 tol_tmp = SENSORS_LIMIT(val, 0, 15);
826 tol_tmp &= 0x0f; 887 tol_tmp &= 0x0f;
827 data->tolerance[nr] = tol_tmp; 888 data->tolerance[nr] = tol_tmp;
828 if (nr == 1) { 889 if (nr == 1)
829 tol_tmp <<= 4; 890 tol_tmp <<= 4;
830 }
831 w83792d_write_value(client, W83792D_REG_TOLERANCE[nr], 891 w83792d_write_value(client, W83792D_REG_TOLERANCE[nr],
832 tol_mask | tol_tmp); 892 tol_mask | tol_tmp);
833 mutex_unlock(&data->update_lock); 893 mutex_unlock(&data->update_lock);
@@ -840,7 +900,8 @@ static ssize_t
840show_sf2_point(struct device *dev, struct device_attribute *attr, 900show_sf2_point(struct device *dev, struct device_attribute *attr,
841 char *buf) 901 char *buf)
842{ 902{
843 struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr); 903 struct sensor_device_attribute_2 *sensor_attr
904 = to_sensor_dev_attr_2(attr);
844 int nr = sensor_attr->nr; 905 int nr = sensor_attr->nr;
845 int index = sensor_attr->index; 906 int index = sensor_attr->index;
846 struct w83792d_data *data = w83792d_update_device(dev); 907 struct w83792d_data *data = w83792d_update_device(dev);
@@ -851,15 +912,20 @@ static ssize_t
851store_sf2_point(struct device *dev, struct device_attribute *attr, 912store_sf2_point(struct device *dev, struct device_attribute *attr,
852 const char *buf, size_t count) 913 const char *buf, size_t count)
853{ 914{
854 struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr); 915 struct sensor_device_attribute_2 *sensor_attr
916 = to_sensor_dev_attr_2(attr);
855 int nr = sensor_attr->nr - 1; 917 int nr = sensor_attr->nr - 1;
856 int index = sensor_attr->index - 1; 918 int index = sensor_attr->index - 1;
857 struct i2c_client *client = to_i2c_client(dev); 919 struct i2c_client *client = to_i2c_client(dev);
858 struct w83792d_data *data = i2c_get_clientdata(client); 920 struct w83792d_data *data = i2c_get_clientdata(client);
859 u32 val;
860 u8 mask_tmp = 0; 921 u8 mask_tmp = 0;
922 unsigned long val;
923 int err;
924
925 err = kstrtoul(buf, 10, &val);
926 if (err)
927 return err;
861 928
862 val = simple_strtoul(buf, NULL, 10);
863 mutex_lock(&data->update_lock); 929 mutex_lock(&data->update_lock);
864 data->sf2_points[index][nr] = SENSORS_LIMIT(val, 0, 127); 930 data->sf2_points[index][nr] = SENSORS_LIMIT(val, 0, 127);
865 mask_tmp = w83792d_read_value(client, 931 mask_tmp = w83792d_read_value(client,
@@ -875,7 +941,8 @@ static ssize_t
875show_sf2_level(struct device *dev, struct device_attribute *attr, 941show_sf2_level(struct device *dev, struct device_attribute *attr,
876 char *buf) 942 char *buf)
877{ 943{
878 struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr); 944 struct sensor_device_attribute_2 *sensor_attr
945 = to_sensor_dev_attr_2(attr);
879 int nr = sensor_attr->nr; 946 int nr = sensor_attr->nr;
880 int index = sensor_attr->index; 947 int index = sensor_attr->index;
881 struct w83792d_data *data = w83792d_update_device(dev); 948 struct w83792d_data *data = w83792d_update_device(dev);
@@ -887,25 +954,30 @@ static ssize_t
887store_sf2_level(struct device *dev, struct device_attribute *attr, 954store_sf2_level(struct device *dev, struct device_attribute *attr,
888 const char *buf, size_t count) 955 const char *buf, size_t count)
889{ 956{
890 struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr); 957 struct sensor_device_attribute_2 *sensor_attr
958 = to_sensor_dev_attr_2(attr);
891 int nr = sensor_attr->nr; 959 int nr = sensor_attr->nr;
892 int index = sensor_attr->index - 1; 960 int index = sensor_attr->index - 1;
893 struct i2c_client *client = to_i2c_client(dev); 961 struct i2c_client *client = to_i2c_client(dev);
894 struct w83792d_data *data = i2c_get_clientdata(client); 962 struct w83792d_data *data = i2c_get_clientdata(client);
895 u32 val; 963 u8 mask_tmp = 0, level_tmp = 0;
896 u8 mask_tmp=0, level_tmp=0; 964 unsigned long val;
965 int err;
966
967 err = kstrtoul(buf, 10, &val);
968 if (err)
969 return err;
897 970
898 val = simple_strtoul(buf, NULL, 10);
899 mutex_lock(&data->update_lock); 971 mutex_lock(&data->update_lock);
900 data->sf2_levels[index][nr] = SENSORS_LIMIT((val * 15) / 100, 0, 15); 972 data->sf2_levels[index][nr] = SENSORS_LIMIT((val * 15) / 100, 0, 15);
901 mask_tmp = w83792d_read_value(client, W83792D_REG_LEVELS[index][nr]) 973 mask_tmp = w83792d_read_value(client, W83792D_REG_LEVELS[index][nr])
902 & ((nr==3) ? 0xf0 : 0x0f); 974 & ((nr == 3) ? 0xf0 : 0x0f);
903 if (nr==3) { 975 if (nr == 3)
904 level_tmp = data->sf2_levels[index][nr]; 976 level_tmp = data->sf2_levels[index][nr];
905 } else { 977 else
906 level_tmp = data->sf2_levels[index][nr] << 4; 978 level_tmp = data->sf2_levels[index][nr] << 4;
907 } 979 w83792d_write_value(client, W83792D_REG_LEVELS[index][nr],
908 w83792d_write_value(client, W83792D_REG_LEVELS[index][nr], level_tmp | mask_tmp); 980 level_tmp | mask_tmp);
909 mutex_unlock(&data->update_lock); 981 mutex_unlock(&data->update_lock);
910 982
911 return count; 983 return count;
@@ -939,9 +1011,8 @@ w83792d_detect_subclients(struct i2c_client *new_client)
939 } 1011 }
940 1012
941 val = w83792d_read_value(new_client, W83792D_REG_I2C_SUBADDR); 1013 val = w83792d_read_value(new_client, W83792D_REG_I2C_SUBADDR);
942 if (!(val & 0x08)) { 1014 if (!(val & 0x08))
943 data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (val & 0x7)); 1015 data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (val & 0x7));
944 }
945 if (!(val & 0x80)) { 1016 if (!(val & 0x80)) {
946 if ((data->lm75[0] != NULL) && 1017 if ((data->lm75[0] != NULL) &&
947 ((val & 0x7) == ((val >> 4) & 0x7))) { 1018 ((val & 0x7) == ((val >> 4) & 0x7))) {
@@ -1306,9 +1377,8 @@ w83792d_detect(struct i2c_client *client, struct i2c_board_info *info)
1306 int val1, val2; 1377 int val1, val2;
1307 unsigned short address = client->addr; 1378 unsigned short address = client->addr;
1308 1379
1309 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 1380 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1310 return -ENODEV; 1381 return -ENODEV;
1311 }
1312 1382
1313 if (w83792d_read_value(client, W83792D_REG_CONFIG) & 0x80) 1383 if (w83792d_read_value(client, W83792D_REG_CONFIG) & 0x80)
1314 return -ENODEV; 1384 return -ENODEV;
@@ -1318,11 +1388,13 @@ w83792d_detect(struct i2c_client *client, struct i2c_board_info *info)
1318 /* Check for Winbond ID if in bank 0 */ 1388 /* Check for Winbond ID if in bank 0 */
1319 if (!(val1 & 0x07)) { /* is Bank0 */ 1389 if (!(val1 & 0x07)) { /* is Bank0 */
1320 if ((!(val1 & 0x80) && val2 != 0xa3) || 1390 if ((!(val1 & 0x80) && val2 != 0xa3) ||
1321 ( (val1 & 0x80) && val2 != 0x5c)) 1391 ((val1 & 0x80) && val2 != 0x5c))
1322 return -ENODEV; 1392 return -ENODEV;
1323 } 1393 }
1324 /* If Winbond chip, address of chip and W83792D_REG_I2C_ADDR 1394 /*
1325 should match */ 1395 * If Winbond chip, address of chip and W83792D_REG_I2C_ADDR
1396 * should match
1397 */
1326 if (w83792d_read_value(client, W83792D_REG_I2C_ADDR) != address) 1398 if (w83792d_read_value(client, W83792D_REG_I2C_ADDR) != address)
1327 return -ENODEV; 1399 return -ENODEV;
1328 1400
@@ -1374,33 +1446,40 @@ w83792d_probe(struct i2c_client *client, const struct i2c_device_id *id)
1374 } 1446 }
1375 1447
1376 /* Register sysfs hooks */ 1448 /* Register sysfs hooks */
1377 if ((err = sysfs_create_group(&dev->kobj, &w83792d_group))) 1449 err = sysfs_create_group(&dev->kobj, &w83792d_group);
1450 if (err)
1378 goto ERROR3; 1451 goto ERROR3;
1379 1452
1380 /* Read GPIO enable register to check if pins for fan 4,5 are used as 1453 /*
1381 GPIO */ 1454 * Read GPIO enable register to check if pins for fan 4,5 are used as
1455 * GPIO
1456 */
1382 val1 = w83792d_read_value(client, W83792D_REG_GPIO_EN); 1457 val1 = w83792d_read_value(client, W83792D_REG_GPIO_EN);
1383 1458
1384 if (!(val1 & 0x40)) 1459 if (!(val1 & 0x40)) {
1385 if ((err = sysfs_create_group(&dev->kobj, 1460 err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[0]);
1386 &w83792d_group_fan[0]))) 1461 if (err)
1387 goto exit_remove_files; 1462 goto exit_remove_files;
1463 }
1388 1464
1389 if (!(val1 & 0x20)) 1465 if (!(val1 & 0x20)) {
1390 if ((err = sysfs_create_group(&dev->kobj, 1466 err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[1]);
1391 &w83792d_group_fan[1]))) 1467 if (err)
1392 goto exit_remove_files; 1468 goto exit_remove_files;
1469 }
1393 1470
1394 val1 = w83792d_read_value(client, W83792D_REG_PIN); 1471 val1 = w83792d_read_value(client, W83792D_REG_PIN);
1395 if (val1 & 0x40) 1472 if (val1 & 0x40) {
1396 if ((err = sysfs_create_group(&dev->kobj, 1473 err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[2]);
1397 &w83792d_group_fan[2]))) 1474 if (err)
1398 goto exit_remove_files; 1475 goto exit_remove_files;
1476 }
1399 1477
1400 if (val1 & 0x04) 1478 if (val1 & 0x04) {
1401 if ((err = sysfs_create_group(&dev->kobj, 1479 err = sysfs_create_group(&dev->kobj, &w83792d_group_fan[3]);
1402 &w83792d_group_fan[3]))) 1480 if (err)
1403 goto exit_remove_files; 1481 goto exit_remove_files;
1482 }
1404 1483
1405 data->hwmon_dev = hwmon_device_register(dev); 1484 data->hwmon_dev = hwmon_device_register(dev);
1406 if (IS_ERR(data->hwmon_dev)) { 1485 if (IS_ERR(data->hwmon_dev)) {
@@ -1451,14 +1530,16 @@ w83792d_init_client(struct i2c_client *client)
1451{ 1530{
1452 u8 temp2_cfg, temp3_cfg, vid_in_b; 1531 u8 temp2_cfg, temp3_cfg, vid_in_b;
1453 1532
1454 if (init) { 1533 if (init)
1455 w83792d_write_value(client, W83792D_REG_CONFIG, 0x80); 1534 w83792d_write_value(client, W83792D_REG_CONFIG, 0x80);
1456 } 1535
1457 /* Clear the bit6 of W83792D_REG_VID_IN_B(set it into 0): 1536 /*
1458 W83792D_REG_VID_IN_B bit6 = 0: the high/low limit of 1537 * Clear the bit6 of W83792D_REG_VID_IN_B(set it into 0):
1459 vin0/vin1 can be modified by user; 1538 * W83792D_REG_VID_IN_B bit6 = 0: the high/low limit of
1460 W83792D_REG_VID_IN_B bit6 = 1: the high/low limit of 1539 * vin0/vin1 can be modified by user;
1461 vin0/vin1 auto-updated, can NOT be modified by user. */ 1540 * W83792D_REG_VID_IN_B bit6 = 1: the high/low limit of
1541 * vin0/vin1 auto-updated, can NOT be modified by user.
1542 */
1462 vid_in_b = w83792d_read_value(client, W83792D_REG_VID_IN_B); 1543 vid_in_b = w83792d_read_value(client, W83792D_REG_VID_IN_B);
1463 w83792d_write_value(client, W83792D_REG_VID_IN_B, 1544 w83792d_write_value(client, W83792D_REG_VID_IN_B,
1464 vid_in_b & 0xbf); 1545 vid_in_b & 0xbf);
@@ -1527,7 +1608,7 @@ static struct w83792d_data *w83792d_update_device(struct device *dev)
1527 for (i = 0; i < 2; i++) { 1608 for (i = 0; i < 2; i++) {
1528 for (j = 0; j < 6; j++) { 1609 for (j = 0; j < 6; j++) {
1529 data->temp_add[i][j] = w83792d_read_value( 1610 data->temp_add[i][j] = w83792d_read_value(
1530 client,W83792D_REG_TEMP_ADD[i][j]); 1611 client, W83792D_REG_TEMP_ADD[i][j]);
1531 } 1612 }
1532 } 1613 }
1533 1614
@@ -1572,8 +1653,9 @@ static struct w83792d_data *w83792d_update_device(struct device *dev)
1572 /* Update Smart Fan II temperature points */ 1653 /* Update Smart Fan II temperature points */
1573 for (i = 0; i < 3; i++) { 1654 for (i = 0; i < 3; i++) {
1574 for (j = 0; j < 4; j++) { 1655 for (j = 0; j < 4; j++) {
1575 data->sf2_points[i][j] = w83792d_read_value( 1656 data->sf2_points[i][j]
1576 client,W83792D_REG_POINTS[i][j]) & 0x7f; 1657 = w83792d_read_value(client,
1658 W83792D_REG_POINTS[i][j]) & 0x7f;
1577 } 1659 }
1578 } 1660 }
1579 1661
@@ -1605,10 +1687,10 @@ static struct w83792d_data *w83792d_update_device(struct device *dev)
1605#ifdef DEBUG 1687#ifdef DEBUG
1606static void w83792d_print_debug(struct w83792d_data *data, struct device *dev) 1688static void w83792d_print_debug(struct w83792d_data *data, struct device *dev)
1607{ 1689{
1608 int i=0, j=0; 1690 int i = 0, j = 0;
1609 dev_dbg(dev, "==========The following is the debug message...========\n"); 1691 dev_dbg(dev, "==========The following is the debug message...========\n");
1610 dev_dbg(dev, "9 set of Voltages: =====>\n"); 1692 dev_dbg(dev, "9 set of Voltages: =====>\n");
1611 for (i=0; i<9; i++) { 1693 for (i = 0; i < 9; i++) {
1612 dev_dbg(dev, "vin[%d] is: 0x%x\n", i, data->in[i]); 1694 dev_dbg(dev, "vin[%d] is: 0x%x\n", i, data->in[i]);
1613 dev_dbg(dev, "vin[%d] max is: 0x%x\n", i, data->in_max[i]); 1695 dev_dbg(dev, "vin[%d] max is: 0x%x\n", i, data->in_max[i]);
1614 dev_dbg(dev, "vin[%d] min is: 0x%x\n", i, data->in_min[i]); 1696 dev_dbg(dev, "vin[%d] min is: 0x%x\n", i, data->in_min[i]);
@@ -1616,47 +1698,32 @@ static void w83792d_print_debug(struct w83792d_data *data, struct device *dev)
1616 dev_dbg(dev, "Low Bit1 is: 0x%x\n", data->low_bits & 0xff); 1698 dev_dbg(dev, "Low Bit1 is: 0x%x\n", data->low_bits & 0xff);
1617 dev_dbg(dev, "Low Bit2 is: 0x%x\n", data->low_bits >> 8); 1699 dev_dbg(dev, "Low Bit2 is: 0x%x\n", data->low_bits >> 8);
1618 dev_dbg(dev, "7 set of Fan Counts and Duty Cycles: =====>\n"); 1700 dev_dbg(dev, "7 set of Fan Counts and Duty Cycles: =====>\n");
1619 for (i=0; i<7; i++) { 1701 for (i = 0; i < 7; i++) {
1620 dev_dbg(dev, "fan[%d] is: 0x%x\n", i, data->fan[i]); 1702 dev_dbg(dev, "fan[%d] is: 0x%x\n", i, data->fan[i]);
1621 dev_dbg(dev, "fan[%d] min is: 0x%x\n", i, data->fan_min[i]); 1703 dev_dbg(dev, "fan[%d] min is: 0x%x\n", i, data->fan_min[i]);
1622 dev_dbg(dev, "pwm[%d] is: 0x%x\n", i, data->pwm[i]); 1704 dev_dbg(dev, "pwm[%d] is: 0x%x\n", i, data->pwm[i]);
1623 } 1705 }
1624 dev_dbg(dev, "3 set of Temperatures: =====>\n"); 1706 dev_dbg(dev, "3 set of Temperatures: =====>\n");
1625 for (i=0; i<3; i++) { 1707 for (i = 0; i < 3; i++)
1626 dev_dbg(dev, "temp1[%d] is: 0x%x\n", i, data->temp1[i]); 1708 dev_dbg(dev, "temp1[%d] is: 0x%x\n", i, data->temp1[i]);
1627 }
1628 1709
1629 for (i=0; i<2; i++) { 1710 for (i = 0; i < 2; i++) {
1630 for (j=0; j<6; j++) { 1711 for (j = 0; j < 6; j++) {
1631 dev_dbg(dev, "temp_add[%d][%d] is: 0x%x\n", i, j, 1712 dev_dbg(dev, "temp_add[%d][%d] is: 0x%x\n", i, j,
1632 data->temp_add[i][j]); 1713 data->temp_add[i][j]);
1633 } 1714 }
1634 } 1715 }
1635 1716
1636 for (i=0; i<7; i++) { 1717 for (i = 0; i < 7; i++)
1637 dev_dbg(dev, "fan_div[%d] is: 0x%x\n", i, data->fan_div[i]); 1718 dev_dbg(dev, "fan_div[%d] is: 0x%x\n", i, data->fan_div[i]);
1638 } 1719
1639 dev_dbg(dev, "==========End of the debug message...==================\n"); 1720 dev_dbg(dev, "==========End of the debug message...================\n");
1640 dev_dbg(dev, "\n"); 1721 dev_dbg(dev, "\n");
1641} 1722}
1642#endif 1723#endif
1643 1724
1644static int __init 1725module_i2c_driver(w83792d_driver);
1645sensors_w83792d_init(void)
1646{
1647 return i2c_add_driver(&w83792d_driver);
1648}
1649
1650static void __exit
1651sensors_w83792d_exit(void)
1652{
1653 i2c_del_driver(&w83792d_driver);
1654}
1655 1726
1656MODULE_AUTHOR("Chunhao Huang @ Winbond <DZShen@Winbond.com.tw>"); 1727MODULE_AUTHOR("Chunhao Huang @ Winbond <DZShen@Winbond.com.tw>");
1657MODULE_DESCRIPTION("W83792AD/D driver for linux-2.6"); 1728MODULE_DESCRIPTION("W83792AD/D driver for linux-2.6");
1658MODULE_LICENSE("GPL"); 1729MODULE_LICENSE("GPL");
1659
1660module_init(sensors_w83792d_init);
1661module_exit(sensors_w83792d_exit);
1662
diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
index 45ec7e7c3c27..834e49d1827b 100644
--- a/drivers/hwmon/w83793.c
+++ b/drivers/hwmon/w83793.c
@@ -1,34 +1,34 @@
1/* 1/*
2 w83793.c - Linux kernel driver for hardware monitoring 2 * w83793.c - Linux kernel driver for hardware monitoring
3 Copyright (C) 2006 Winbond Electronics Corp. 3 * Copyright (C) 2006 Winbond Electronics Corp.
4 Yuan Mu 4 * Yuan Mu
5 Rudolf Marek <r.marek@assembler.cz> 5 * Rudolf Marek <r.marek@assembler.cz>
6 Copyright (C) 2009-2010 Sven Anders <anders@anduras.de>, ANDURAS AG. 6 * Copyright (C) 2009-2010 Sven Anders <anders@anduras.de>, ANDURAS AG.
7 Watchdog driver part 7 * Watchdog driver part
8 (Based partially on fschmd driver, 8 * (Based partially on fschmd driver,
9 Copyright 2007-2008 by Hans de Goede) 9 * Copyright 2007-2008 by Hans de Goede)
10 10 *
11 This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by 12 * it under the terms of the GNU General Public License as published by
13 the Free Software Foundation - version 2. 13 * the Free Software Foundation - version 2.
14 14 *
15 This program is distributed in the hope that it will be useful, 15 * This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details. 18 * GNU General Public License for more details.
19 19 *
20 You should have received a copy of the GNU General Public License 20 * You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software 21 * along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 02110-1301 USA. 23 * 02110-1301 USA.
24*/ 24 */
25 25
26/* 26/*
27 Supports following chips: 27 * Supports following chips:
28 28 *
29 Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA 29 * Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
30 w83793 10 12 8 6 0x7b 0x5ca3 yes no 30 * w83793 10 12 8 6 0x7b 0x5ca3 yes no
31*/ 31 */
32 32
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/init.h> 34#include <linux/init.h>
@@ -78,9 +78,9 @@ MODULE_PARM_DESC(nowayout,
78 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); 78 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
79 79
80/* 80/*
81 Address 0x00, 0x0d, 0x0e, 0x0f in all three banks are reserved 81 * Address 0x00, 0x0d, 0x0e, 0x0f in all three banks are reserved
82 as ID, Bank Select registers 82 * as ID, Bank Select registers
83*/ 83 */
84#define W83793_REG_BANKSEL 0x00 84#define W83793_REG_BANKSEL 0x00
85#define W83793_REG_VENDORID 0x0d 85#define W83793_REG_VENDORID 0x0d
86#define W83793_REG_CHIPID 0x0e 86#define W83793_REG_CHIPID 0x0e
@@ -110,8 +110,10 @@ static u16 W83793_REG_TEMP_MODE[2] = { 0x5e, 0x5f };
110#define TEMP_CRIT_HYST 2 110#define TEMP_CRIT_HYST 2
111#define TEMP_WARN 3 111#define TEMP_WARN 3
112#define TEMP_WARN_HYST 4 112#define TEMP_WARN_HYST 4
113/* only crit and crit_hyst affect real-time alarm status 113/*
114 current crit crit_hyst warn warn_hyst */ 114 * only crit and crit_hyst affect real-time alarm status
115 * current crit crit_hyst warn warn_hyst
116 */
115static u16 W83793_REG_TEMP[][5] = { 117static u16 W83793_REG_TEMP[][5] = {
116 {0x1c, 0x78, 0x79, 0x7a, 0x7b}, 118 {0x1c, 0x78, 0x79, 0x7a, 0x7b},
117 {0x1d, 0x7c, 0x7d, 0x7e, 0x7f}, 119 {0x1d, 0x7c, 0x7d, 0x7e, 0x7f},
@@ -181,7 +183,7 @@ static inline unsigned long FAN_FROM_REG(u16 val)
181{ 183{
182 if ((val >= 0xfff) || (val == 0)) 184 if ((val >= 0xfff) || (val == 0))
183 return 0; 185 return 0;
184 return (1350000UL / val); 186 return 1350000UL / val;
185} 187}
186 188
187static inline u16 FAN_TO_REG(long rpm) 189static inline u16 FAN_TO_REG(long rpm)
@@ -193,7 +195,7 @@ static inline u16 FAN_TO_REG(long rpm)
193 195
194static inline unsigned long TIME_FROM_REG(u8 reg) 196static inline unsigned long TIME_FROM_REG(u8 reg)
195{ 197{
196 return (reg * 100); 198 return reg * 100;
197} 199}
198 200
199static inline u8 TIME_TO_REG(unsigned long val) 201static inline u8 TIME_TO_REG(unsigned long val)
@@ -203,7 +205,7 @@ static inline u8 TIME_TO_REG(unsigned long val)
203 205
204static inline long TEMP_FROM_REG(s8 reg) 206static inline long TEMP_FROM_REG(s8 reg)
205{ 207{
206 return (reg * 1000); 208 return reg * 1000;
207} 209}
208 210
209static inline s8 TEMP_TO_REG(long val, s8 min, s8 max) 211static inline s8 TEMP_TO_REG(long val, s8 min, s8 max)
@@ -218,7 +220,8 @@ struct w83793_data {
218 char valid; /* !=0 if following fields are valid */ 220 char valid; /* !=0 if following fields are valid */
219 unsigned long last_updated; /* In jiffies */ 221 unsigned long last_updated; /* In jiffies */
220 unsigned long last_nonvolatile; /* In jiffies, last time we update the 222 unsigned long last_nonvolatile; /* In jiffies, last time we update the
221 nonvolatile registers */ 223 * nonvolatile registers
224 */
222 225
223 u8 bank; 226 u8 bank;
224 u8 vrm; 227 u8 vrm;
@@ -233,7 +236,8 @@ struct w83793_data {
233 s8 temp[6][5]; /* current, crit, crit_hyst,warn, warn_hyst */ 236 s8 temp[6][5]; /* current, crit, crit_hyst,warn, warn_hyst */
234 u8 temp_low_bits; /* Additional resolution TD1-TD4 */ 237 u8 temp_low_bits; /* Additional resolution TD1-TD4 */
235 u8 temp_mode[2]; /* byte 0: Temp D1-D4 mode each has 2 bits 238 u8 temp_mode[2]; /* byte 0: Temp D1-D4 mode each has 2 bits
236 byte 1: Temp R1,R2 mode, each has 1 bit */ 239 * byte 1: Temp R1,R2 mode, each has 1 bit
240 */
237 u8 temp_critical; /* If reached all fan will be at full speed */ 241 u8 temp_critical; /* If reached all fan will be at full speed */
238 u8 temp_fan_map[6]; /* Temp controls which pwm fan, bit field */ 242 u8 temp_fan_map[6]; /* Temp controls which pwm fan, bit field */
239 243
@@ -268,17 +272,21 @@ struct w83793_data {
268 int watchdog_timeout; /* watchdog timeout in minutes */ 272 int watchdog_timeout; /* watchdog timeout in minutes */
269}; 273};
270 274
271/* Somewhat ugly :( global data pointer list with all devices, so that 275/*
272 we can find our device data as when using misc_register. There is no 276 * Somewhat ugly :( global data pointer list with all devices, so that
273 other method to get to one's device data from the open file-op and 277 * we can find our device data as when using misc_register. There is no
274 for usage in the reboot notifier callback. */ 278 * other method to get to one's device data from the open file-op and
279 * for usage in the reboot notifier callback.
280 */
275static LIST_HEAD(watchdog_data_list); 281static LIST_HEAD(watchdog_data_list);
276 282
277/* Note this lock not only protect list access, but also data.kref access */ 283/* Note this lock not only protect list access, but also data.kref access */
278static DEFINE_MUTEX(watchdog_data_mutex); 284static DEFINE_MUTEX(watchdog_data_mutex);
279 285
280/* Release our data struct when we're detached from the i2c client *and* all 286/*
281 references to our watchdog device are released */ 287 * Release our data struct when we're detached from the i2c client *and* all
288 * references to our watchdog device are released
289 */
282static void w83793_release_resources(struct kref *ref) 290static void w83793_release_resources(struct kref *ref)
283{ 291{
284 struct w83793_data *data = container_of(ref, struct w83793_data, kref); 292 struct w83793_data *data = container_of(ref, struct w83793_data, kref);
@@ -337,7 +345,14 @@ store_vrm(struct device *dev, struct device_attribute *attr,
337 const char *buf, size_t count) 345 const char *buf, size_t count)
338{ 346{
339 struct w83793_data *data = dev_get_drvdata(dev); 347 struct w83793_data *data = dev_get_drvdata(dev);
340 data->vrm = simple_strtoul(buf, NULL, 10); 348 unsigned long val;
349 int err;
350
351 err = kstrtoul(buf, 10, &val);
352 if (err)
353 return err;
354
355 data->vrm = val;
341 return count; 356 return count;
342} 357}
343 358
@@ -354,7 +369,7 @@ show_alarm_beep(struct device *dev, struct device_attribute *attr, char *buf)
354 int bit = sensor_attr->index & 0x07; 369 int bit = sensor_attr->index & 0x07;
355 u8 val; 370 u8 val;
356 371
357 if (ALARM_STATUS == nr) { 372 if (nr == ALARM_STATUS) {
358 val = (data->alarms[index] >> (bit)) & 1; 373 val = (data->alarms[index] >> (bit)) & 1;
359 } else { /* BEEP_ENABLE */ 374 } else { /* BEEP_ENABLE */
360 val = (data->beeps[index] >> (bit)) & 1; 375 val = (data->beeps[index] >> (bit)) & 1;
@@ -374,10 +389,14 @@ store_beep(struct device *dev, struct device_attribute *attr,
374 int index = sensor_attr->index >> 3; 389 int index = sensor_attr->index >> 3;
375 int shift = sensor_attr->index & 0x07; 390 int shift = sensor_attr->index & 0x07;
376 u8 beep_bit = 1 << shift; 391 u8 beep_bit = 1 << shift;
377 u8 val; 392 unsigned long val;
393 int err;
394
395 err = kstrtoul(buf, 10, &val);
396 if (err)
397 return err;
378 398
379 val = simple_strtoul(buf, NULL, 10); 399 if (val > 1)
380 if (val != 0 && val != 1)
381 return -EINVAL; 400 return -EINVAL;
382 401
383 mutex_lock(&data->update_lock); 402 mutex_lock(&data->update_lock);
@@ -403,9 +422,14 @@ store_beep_enable(struct device *dev, struct device_attribute *attr,
403{ 422{
404 struct i2c_client *client = to_i2c_client(dev); 423 struct i2c_client *client = to_i2c_client(dev);
405 struct w83793_data *data = i2c_get_clientdata(client); 424 struct w83793_data *data = i2c_get_clientdata(client);
406 u8 val = simple_strtoul(buf, NULL, 10); 425 unsigned long val;
426 int err;
427
428 err = kstrtoul(buf, 10, &val);
429 if (err)
430 return err;
407 431
408 if (val != 0 && val != 1) 432 if (val > 1)
409 return -EINVAL; 433 return -EINVAL;
410 434
411 mutex_lock(&data->update_lock); 435 mutex_lock(&data->update_lock);
@@ -449,8 +473,12 @@ store_chassis_clear(struct device *dev,
449 struct w83793_data *data = i2c_get_clientdata(client); 473 struct w83793_data *data = i2c_get_clientdata(client);
450 unsigned long val; 474 unsigned long val;
451 u8 reg; 475 u8 reg;
476 int err;
452 477
453 if (kstrtoul(buf, 10, &val) || val != 0) 478 err = kstrtoul(buf, 10, &val);
479 if (err)
480 return err;
481 if (val)
454 return -EINVAL; 482 return -EINVAL;
455 483
456 mutex_lock(&data->update_lock); 484 mutex_lock(&data->update_lock);
@@ -473,11 +501,10 @@ show_fan(struct device *dev, struct device_attribute *attr, char *buf)
473 struct w83793_data *data = w83793_update_device(dev); 501 struct w83793_data *data = w83793_update_device(dev);
474 u16 val; 502 u16 val;
475 503
476 if (FAN_INPUT == nr) { 504 if (nr == FAN_INPUT)
477 val = data->fan[index] & 0x0fff; 505 val = data->fan[index] & 0x0fff;
478 } else { 506 else
479 val = data->fan_min[index] & 0x0fff; 507 val = data->fan_min[index] & 0x0fff;
480 }
481 508
482 return sprintf(buf, "%lu\n", FAN_FROM_REG(val)); 509 return sprintf(buf, "%lu\n", FAN_FROM_REG(val));
483} 510}
@@ -491,7 +518,13 @@ store_fan_min(struct device *dev, struct device_attribute *attr,
491 int index = sensor_attr->index; 518 int index = sensor_attr->index;
492 struct i2c_client *client = to_i2c_client(dev); 519 struct i2c_client *client = to_i2c_client(dev);
493 struct w83793_data *data = i2c_get_clientdata(client); 520 struct w83793_data *data = i2c_get_clientdata(client);
494 u16 val = FAN_TO_REG(simple_strtoul(buf, NULL, 10)); 521 unsigned long val;
522 int err;
523
524 err = kstrtoul(buf, 10, &val);
525 if (err)
526 return err;
527 val = FAN_TO_REG(val);
495 528
496 mutex_lock(&data->update_lock); 529 mutex_lock(&data->update_lock);
497 data->fan_min[index] = val; 530 data->fan_min[index] = val;
@@ -513,7 +546,7 @@ show_pwm(struct device *dev, struct device_attribute *attr, char *buf)
513 int nr = sensor_attr->nr; 546 int nr = sensor_attr->nr;
514 int index = sensor_attr->index; 547 int index = sensor_attr->index;
515 548
516 if (PWM_STOP_TIME == nr) 549 if (nr == PWM_STOP_TIME)
517 val = TIME_FROM_REG(data->pwm_stop_time[index]); 550 val = TIME_FROM_REG(data->pwm_stop_time[index]);
518 else 551 else
519 val = (data->pwm[index][nr] & 0x3f) << 2; 552 val = (data->pwm[index][nr] & 0x3f) << 2;
@@ -531,17 +564,21 @@ store_pwm(struct device *dev, struct device_attribute *attr,
531 to_sensor_dev_attr_2(attr); 564 to_sensor_dev_attr_2(attr);
532 int nr = sensor_attr->nr; 565 int nr = sensor_attr->nr;
533 int index = sensor_attr->index; 566 int index = sensor_attr->index;
534 u8 val; 567 unsigned long val;
568 int err;
569
570 err = kstrtoul(buf, 10, &val);
571 if (err)
572 return err;
535 573
536 mutex_lock(&data->update_lock); 574 mutex_lock(&data->update_lock);
537 if (PWM_STOP_TIME == nr) { 575 if (nr == PWM_STOP_TIME) {
538 val = TIME_TO_REG(simple_strtoul(buf, NULL, 10)); 576 val = TIME_TO_REG(val);
539 data->pwm_stop_time[index] = val; 577 data->pwm_stop_time[index] = val;
540 w83793_write_value(client, W83793_REG_PWM_STOP_TIME(index), 578 w83793_write_value(client, W83793_REG_PWM_STOP_TIME(index),
541 val); 579 val);
542 } else { 580 } else {
543 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 0xff) 581 val = SENSORS_LIMIT(val, 0, 0xff) >> 2;
544 >> 2;
545 data->pwm[index][nr] = 582 data->pwm[index][nr] =
546 w83793_read_value(client, W83793_REG_PWM(index, nr)) & 0xc0; 583 w83793_read_value(client, W83793_REG_PWM(index, nr)) & 0xc0;
547 data->pwm[index][nr] |= val; 584 data->pwm[index][nr] |= val;
@@ -563,7 +600,7 @@ show_temp(struct device *dev, struct device_attribute *attr, char *buf)
563 struct w83793_data *data = w83793_update_device(dev); 600 struct w83793_data *data = w83793_update_device(dev);
564 long temp = TEMP_FROM_REG(data->temp[index][nr]); 601 long temp = TEMP_FROM_REG(data->temp[index][nr]);
565 602
566 if (TEMP_READ == nr && index < 4) { /* Only TD1-TD4 have low bits */ 603 if (nr == TEMP_READ && index < 4) { /* Only TD1-TD4 have low bits */
567 int low = ((data->temp_low_bits >> (index * 2)) & 0x03) * 250; 604 int low = ((data->temp_low_bits >> (index * 2)) & 0x03) * 250;
568 temp += temp > 0 ? low : -low; 605 temp += temp > 0 ? low : -low;
569 } 606 }
@@ -580,7 +617,12 @@ store_temp(struct device *dev, struct device_attribute *attr,
580 int index = sensor_attr->index; 617 int index = sensor_attr->index;
581 struct i2c_client *client = to_i2c_client(dev); 618 struct i2c_client *client = to_i2c_client(dev);
582 struct w83793_data *data = i2c_get_clientdata(client); 619 struct w83793_data *data = i2c_get_clientdata(client);
583 long tmp = simple_strtol(buf, NULL, 10); 620 long tmp;
621 int err;
622
623 err = kstrtol(buf, 10, &tmp);
624 if (err)
625 return err;
584 626
585 mutex_lock(&data->update_lock); 627 mutex_lock(&data->update_lock);
586 data->temp[index][nr] = TEMP_TO_REG(tmp, -128, 127); 628 data->temp[index][nr] = TEMP_TO_REG(tmp, -128, 127);
@@ -591,18 +633,18 @@ store_temp(struct device *dev, struct device_attribute *attr,
591} 633}
592 634
593/* 635/*
594 TD1-TD4 636 * TD1-TD4
595 each has 4 mode:(2 bits) 637 * each has 4 mode:(2 bits)
596 0: Stop monitor 638 * 0: Stop monitor
597 1: Use internal temp sensor(default) 639 * 1: Use internal temp sensor(default)
598 2: Reserved 640 * 2: Reserved
599 3: Use sensor in Intel CPU and get result by PECI 641 * 3: Use sensor in Intel CPU and get result by PECI
600 642 *
601 TR1-TR2 643 * TR1-TR2
602 each has 2 mode:(1 bit) 644 * each has 2 mode:(1 bit)
603 0: Disable temp sensor monitor 645 * 0: Disable temp sensor monitor
604 1: To enable temp sensors monitor 646 * 1: To enable temp sensors monitor
605*/ 647 */
606 648
607/* 0 disable, 6 PECI */ 649/* 0 disable, 6 PECI */
608static u8 TO_TEMP_MODE[] = { 0, 0, 0, 6 }; 650static u8 TO_TEMP_MODE[] = { 0, 0, 0, 6 };
@@ -622,11 +664,10 @@ show_temp_mode(struct device *dev, struct device_attribute *attr, char *buf)
622 tmp = (data->temp_mode[index] >> shift) & mask; 664 tmp = (data->temp_mode[index] >> shift) & mask;
623 665
624 /* for the internal sensor, found out if diode or thermistor */ 666 /* for the internal sensor, found out if diode or thermistor */
625 if (tmp == 1) { 667 if (tmp == 1)
626 tmp = index == 0 ? 3 : 4; 668 tmp = index == 0 ? 3 : 4;
627 } else { 669 else
628 tmp = TO_TEMP_MODE[tmp]; 670 tmp = TO_TEMP_MODE[tmp];
629 }
630 671
631 return sprintf(buf, "%d\n", tmp); 672 return sprintf(buf, "%d\n", tmp);
632} 673}
@@ -642,7 +683,12 @@ store_temp_mode(struct device *dev, struct device_attribute *attr,
642 int index = sensor_attr->index; 683 int index = sensor_attr->index;
643 u8 mask = (index < 4) ? 0x03 : 0x01; 684 u8 mask = (index < 4) ? 0x03 : 0x01;
644 u8 shift = (index < 4) ? (2 * index) : (index - 4); 685 u8 shift = (index < 4) ? (2 * index) : (index - 4);
645 u8 val = simple_strtoul(buf, NULL, 10); 686 unsigned long val;
687 int err;
688
689 err = kstrtoul(buf, 10, &val);
690 if (err)
691 return err;
646 692
647 /* transform the sysfs interface values into table above */ 693 /* transform the sysfs interface values into table above */
648 if ((val == 6) && (index < 4)) { 694 if ((val == 6) && (index < 4)) {
@@ -681,15 +727,14 @@ show_sf_setup(struct device *dev, struct device_attribute *attr, char *buf)
681 struct w83793_data *data = w83793_update_device(dev); 727 struct w83793_data *data = w83793_update_device(dev);
682 u32 val = 0; 728 u32 val = 0;
683 729
684 if (SETUP_PWM_DEFAULT == nr) { 730 if (nr == SETUP_PWM_DEFAULT)
685 val = (data->pwm_default & 0x3f) << 2; 731 val = (data->pwm_default & 0x3f) << 2;
686 } else if (SETUP_PWM_UPTIME == nr) { 732 else if (nr == SETUP_PWM_UPTIME)
687 val = TIME_FROM_REG(data->pwm_uptime); 733 val = TIME_FROM_REG(data->pwm_uptime);
688 } else if (SETUP_PWM_DOWNTIME == nr) { 734 else if (nr == SETUP_PWM_DOWNTIME)
689 val = TIME_FROM_REG(data->pwm_downtime); 735 val = TIME_FROM_REG(data->pwm_downtime);
690 } else if (SETUP_TEMP_CRITICAL == nr) { 736 else if (nr == SETUP_TEMP_CRITICAL)
691 val = TEMP_FROM_REG(data->temp_critical & 0x7f); 737 val = TEMP_FROM_REG(data->temp_critical & 0x7f);
692 }
693 738
694 return sprintf(buf, "%d\n", val); 739 return sprintf(buf, "%d\n", val);
695} 740}
@@ -703,31 +748,34 @@ store_sf_setup(struct device *dev, struct device_attribute *attr,
703 int nr = sensor_attr->nr; 748 int nr = sensor_attr->nr;
704 struct i2c_client *client = to_i2c_client(dev); 749 struct i2c_client *client = to_i2c_client(dev);
705 struct w83793_data *data = i2c_get_clientdata(client); 750 struct w83793_data *data = i2c_get_clientdata(client);
751 long val;
752 int err;
753
754 err = kstrtol(buf, 10, &val);
755 if (err)
756 return err;
706 757
707 mutex_lock(&data->update_lock); 758 mutex_lock(&data->update_lock);
708 if (SETUP_PWM_DEFAULT == nr) { 759 if (nr == SETUP_PWM_DEFAULT) {
709 data->pwm_default = 760 data->pwm_default =
710 w83793_read_value(client, W83793_REG_PWM_DEFAULT) & 0xc0; 761 w83793_read_value(client, W83793_REG_PWM_DEFAULT) & 0xc0;
711 data->pwm_default |= SENSORS_LIMIT(simple_strtoul(buf, NULL, 762 data->pwm_default |= SENSORS_LIMIT(val, 0, 0xff) >> 2;
712 10),
713 0, 0xff) >> 2;
714 w83793_write_value(client, W83793_REG_PWM_DEFAULT, 763 w83793_write_value(client, W83793_REG_PWM_DEFAULT,
715 data->pwm_default); 764 data->pwm_default);
716 } else if (SETUP_PWM_UPTIME == nr) { 765 } else if (nr == SETUP_PWM_UPTIME) {
717 data->pwm_uptime = TIME_TO_REG(simple_strtoul(buf, NULL, 10)); 766 data->pwm_uptime = TIME_TO_REG(val);
718 data->pwm_uptime += data->pwm_uptime == 0 ? 1 : 0; 767 data->pwm_uptime += data->pwm_uptime == 0 ? 1 : 0;
719 w83793_write_value(client, W83793_REG_PWM_UPTIME, 768 w83793_write_value(client, W83793_REG_PWM_UPTIME,
720 data->pwm_uptime); 769 data->pwm_uptime);
721 } else if (SETUP_PWM_DOWNTIME == nr) { 770 } else if (nr == SETUP_PWM_DOWNTIME) {
722 data->pwm_downtime = TIME_TO_REG(simple_strtoul(buf, NULL, 10)); 771 data->pwm_downtime = TIME_TO_REG(val);
723 data->pwm_downtime += data->pwm_downtime == 0 ? 1 : 0; 772 data->pwm_downtime += data->pwm_downtime == 0 ? 1 : 0;
724 w83793_write_value(client, W83793_REG_PWM_DOWNTIME, 773 w83793_write_value(client, W83793_REG_PWM_DOWNTIME,
725 data->pwm_downtime); 774 data->pwm_downtime);
726 } else { /* SETUP_TEMP_CRITICAL */ 775 } else { /* SETUP_TEMP_CRITICAL */
727 data->temp_critical = 776 data->temp_critical =
728 w83793_read_value(client, W83793_REG_TEMP_CRITICAL) & 0x80; 777 w83793_read_value(client, W83793_REG_TEMP_CRITICAL) & 0x80;
729 data->temp_critical |= TEMP_TO_REG(simple_strtol(buf, NULL, 10), 778 data->temp_critical |= TEMP_TO_REG(val, 0, 0x7f);
730 0, 0x7f);
731 w83793_write_value(client, W83793_REG_TEMP_CRITICAL, 779 w83793_write_value(client, W83793_REG_TEMP_CRITICAL,
732 data->temp_critical); 780 data->temp_critical);
733 } 781 }
@@ -737,31 +785,31 @@ store_sf_setup(struct device *dev, struct device_attribute *attr,
737} 785}
738 786
739/* 787/*
740 Temp SmartFan control 788 * Temp SmartFan control
741 TEMP_FAN_MAP 789 * TEMP_FAN_MAP
742 Temp channel control which pwm fan, bitfield, bit 0 indicate pwm1... 790 * Temp channel control which pwm fan, bitfield, bit 0 indicate pwm1...
743 It's possible two or more temp channels control the same fan, w83793 791 * It's possible two or more temp channels control the same fan, w83793
744 always prefers to pick the most critical request and applies it to 792 * always prefers to pick the most critical request and applies it to
745 the related Fan. 793 * the related Fan.
746 It's possible one fan is not in any mapping of 6 temp channels, this 794 * It's possible one fan is not in any mapping of 6 temp channels, this
747 means the fan is manual mode 795 * means the fan is manual mode
748 796 *
749 TEMP_PWM_ENABLE 797 * TEMP_PWM_ENABLE
750 Each temp channel has its own SmartFan mode, and temp channel 798 * Each temp channel has its own SmartFan mode, and temp channel
751 control fans that are set by TEMP_FAN_MAP 799 * control fans that are set by TEMP_FAN_MAP
752 0: SmartFanII mode 800 * 0: SmartFanII mode
753 1: Thermal Cruise Mode 801 * 1: Thermal Cruise Mode
754 802 *
755 TEMP_CRUISE 803 * TEMP_CRUISE
756 Target temperature in thermal cruise mode, w83793 will try to turn 804 * Target temperature in thermal cruise mode, w83793 will try to turn
757 fan speed to keep the temperature of target device around this 805 * fan speed to keep the temperature of target device around this
758 temperature. 806 * temperature.
759 807 *
760 TEMP_TOLERANCE 808 * TEMP_TOLERANCE
761 If Temp higher or lower than target with this tolerance, w83793 809 * If Temp higher or lower than target with this tolerance, w83793
762 will take actions to speed up or slow down the fan to keep the 810 * will take actions to speed up or slow down the fan to keep the
763 temperature within the tolerance range. 811 * temperature within the tolerance range.
764*/ 812 */
765 813
766#define TEMP_FAN_MAP 0 814#define TEMP_FAN_MAP 0
767#define TEMP_PWM_ENABLE 1 815#define TEMP_PWM_ENABLE 1
@@ -777,12 +825,12 @@ show_sf_ctrl(struct device *dev, struct device_attribute *attr, char *buf)
777 struct w83793_data *data = w83793_update_device(dev); 825 struct w83793_data *data = w83793_update_device(dev);
778 u32 val; 826 u32 val;
779 827
780 if (TEMP_FAN_MAP == nr) { 828 if (nr == TEMP_FAN_MAP) {
781 val = data->temp_fan_map[index]; 829 val = data->temp_fan_map[index];
782 } else if (TEMP_PWM_ENABLE == nr) { 830 } else if (nr == TEMP_PWM_ENABLE) {
783 /* +2 to transfrom into 2 and 3 to conform with sysfs intf */ 831 /* +2 to transfrom into 2 and 3 to conform with sysfs intf */
784 val = ((data->pwm_enable >> index) & 0x01) + 2; 832 val = ((data->pwm_enable >> index) & 0x01) + 2;
785 } else if (TEMP_CRUISE == nr) { 833 } else if (nr == TEMP_CRUISE) {
786 val = TEMP_FROM_REG(data->temp_cruise[index] & 0x7f); 834 val = TEMP_FROM_REG(data->temp_cruise[index] & 0x7f);
787 } else { /* TEMP_TOLERANCE */ 835 } else { /* TEMP_TOLERANCE */
788 val = data->tolerance[index >> 1] >> ((index & 0x01) ? 4 : 0); 836 val = data->tolerance[index >> 1] >> ((index & 0x01) ? 4 : 0);
@@ -801,16 +849,20 @@ store_sf_ctrl(struct device *dev, struct device_attribute *attr,
801 int index = sensor_attr->index; 849 int index = sensor_attr->index;
802 struct i2c_client *client = to_i2c_client(dev); 850 struct i2c_client *client = to_i2c_client(dev);
803 struct w83793_data *data = i2c_get_clientdata(client); 851 struct w83793_data *data = i2c_get_clientdata(client);
804 u32 val; 852 long val;
853 int err;
854
855 err = kstrtol(buf, 10, &val);
856 if (err)
857 return err;
805 858
806 mutex_lock(&data->update_lock); 859 mutex_lock(&data->update_lock);
807 if (TEMP_FAN_MAP == nr) { 860 if (nr == TEMP_FAN_MAP) {
808 val = simple_strtoul(buf, NULL, 10) & 0xff; 861 val = SENSORS_LIMIT(val, 0, 255);
809 w83793_write_value(client, W83793_REG_TEMP_FAN_MAP(index), val); 862 w83793_write_value(client, W83793_REG_TEMP_FAN_MAP(index), val);
810 data->temp_fan_map[index] = val; 863 data->temp_fan_map[index] = val;
811 } else if (TEMP_PWM_ENABLE == nr) { 864 } else if (nr == TEMP_PWM_ENABLE) {
812 val = simple_strtoul(buf, NULL, 10); 865 if (val == 2 || val == 3) {
813 if (2 == val || 3 == val) {
814 data->pwm_enable = 866 data->pwm_enable =
815 w83793_read_value(client, W83793_REG_PWM_ENABLE); 867 w83793_read_value(client, W83793_REG_PWM_ENABLE);
816 if (val - 2) 868 if (val - 2)
@@ -823,12 +875,11 @@ store_sf_ctrl(struct device *dev, struct device_attribute *attr,
823 mutex_unlock(&data->update_lock); 875 mutex_unlock(&data->update_lock);
824 return -EINVAL; 876 return -EINVAL;
825 } 877 }
826 } else if (TEMP_CRUISE == nr) { 878 } else if (nr == TEMP_CRUISE) {
827 data->temp_cruise[index] = 879 data->temp_cruise[index] =
828 w83793_read_value(client, W83793_REG_TEMP_CRUISE(index)); 880 w83793_read_value(client, W83793_REG_TEMP_CRUISE(index));
829 val = TEMP_TO_REG(simple_strtol(buf, NULL, 10), 0, 0x7f);
830 data->temp_cruise[index] &= 0x80; 881 data->temp_cruise[index] &= 0x80;
831 data->temp_cruise[index] |= val; 882 data->temp_cruise[index] |= TEMP_TO_REG(val, 0, 0x7f);
832 883
833 w83793_write_value(client, W83793_REG_TEMP_CRUISE(index), 884 w83793_write_value(client, W83793_REG_TEMP_CRUISE(index),
834 data->temp_cruise[index]); 885 data->temp_cruise[index]);
@@ -838,9 +889,8 @@ store_sf_ctrl(struct device *dev, struct device_attribute *attr,
838 data->tolerance[i] = 889 data->tolerance[i] =
839 w83793_read_value(client, W83793_REG_TEMP_TOL(i)); 890 w83793_read_value(client, W83793_REG_TEMP_TOL(i));
840 891
841 val = TEMP_TO_REG(simple_strtol(buf, NULL, 10), 0, 0x0f);
842 data->tolerance[i] &= ~(0x0f << shift); 892 data->tolerance[i] &= ~(0x0f << shift);
843 data->tolerance[i] |= val << shift; 893 data->tolerance[i] |= TEMP_TO_REG(val, 0, 0x0f) << shift;
844 w83793_write_value(client, W83793_REG_TEMP_TOL(i), 894 w83793_write_value(client, W83793_REG_TEMP_TOL(i),
845 data->tolerance[i]); 895 data->tolerance[i]);
846 } 896 }
@@ -871,7 +921,13 @@ store_sf2_pwm(struct device *dev, struct device_attribute *attr,
871 to_sensor_dev_attr_2(attr); 921 to_sensor_dev_attr_2(attr);
872 int nr = sensor_attr->nr; 922 int nr = sensor_attr->nr;
873 int index = sensor_attr->index; 923 int index = sensor_attr->index;
874 u8 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 0xff) >> 2; 924 unsigned long val;
925 int err;
926
927 err = kstrtoul(buf, 10, &val);
928 if (err)
929 return err;
930 val = SENSORS_LIMIT(val, 0, 0xff) >> 2;
875 931
876 mutex_lock(&data->update_lock); 932 mutex_lock(&data->update_lock);
877 data->sf2_pwm[index][nr] = 933 data->sf2_pwm[index][nr] =
@@ -906,7 +962,13 @@ store_sf2_temp(struct device *dev, struct device_attribute *attr,
906 to_sensor_dev_attr_2(attr); 962 to_sensor_dev_attr_2(attr);
907 int nr = sensor_attr->nr; 963 int nr = sensor_attr->nr;
908 int index = sensor_attr->index; 964 int index = sensor_attr->index;
909 u8 val = TEMP_TO_REG(simple_strtol(buf, NULL, 10), 0, 0x7f); 965 long val;
966 int err;
967
968 err = kstrtol(buf, 10, &val);
969 if (err)
970 return err;
971 val = TEMP_TO_REG(val, 0, 0x7f);
910 972
911 mutex_lock(&data->update_lock); 973 mutex_lock(&data->update_lock);
912 data->sf2_temp[index][nr] = 974 data->sf2_temp[index][nr] =
@@ -948,17 +1010,19 @@ store_in(struct device *dev, struct device_attribute *attr,
948 int index = sensor_attr->index; 1010 int index = sensor_attr->index;
949 struct i2c_client *client = to_i2c_client(dev); 1011 struct i2c_client *client = to_i2c_client(dev);
950 struct w83793_data *data = i2c_get_clientdata(client); 1012 struct w83793_data *data = i2c_get_clientdata(client);
951 u32 val; 1013 unsigned long val;
1014 int err;
1015
1016 err = kstrtoul(buf, 10, &val);
1017 if (err)
1018 return err;
1019 val = (val + scale_in[index] / 2) / scale_in[index];
952 1020
953 val =
954 (simple_strtoul(buf, NULL, 10) +
955 scale_in[index] / 2) / scale_in[index];
956 mutex_lock(&data->update_lock); 1021 mutex_lock(&data->update_lock);
957 if (index > 2) { 1022 if (index > 2) {
958 /* fix the limit values of 5VDD and 5VSB to ALARM mechanism */ 1023 /* fix the limit values of 5VDD and 5VSB to ALARM mechanism */
959 if (1 == nr || 2 == nr) { 1024 if (nr == 1 || nr == 2)
960 val -= scale_in_add[index] / scale_in[index]; 1025 val -= scale_in_add[index] / scale_in[index];
961 }
962 val = SENSORS_LIMIT(val, 0, 255); 1026 val = SENSORS_LIMIT(val, 0, 255);
963 } else { 1027 } else {
964 val = SENSORS_LIMIT(val, 0, 0x3FF); 1028 val = SENSORS_LIMIT(val, 0, 0x3FF);
@@ -1143,9 +1207,8 @@ static struct sensor_device_attribute_2 sda_single_files[] = {
1143 1207
1144static void w83793_init_client(struct i2c_client *client) 1208static void w83793_init_client(struct i2c_client *client)
1145{ 1209{
1146 if (reset) { 1210 if (reset)
1147 w83793_write_value(client, W83793_REG_CONFIG, 0x80); 1211 w83793_write_value(client, W83793_REG_CONFIG, 0x80);
1148 }
1149 1212
1150 /* Start monitoring */ 1213 /* Start monitoring */
1151 w83793_write_value(client, W83793_REG_CONFIG, 1214 w83793_write_value(client, W83793_REG_CONFIG,
@@ -1259,10 +1322,12 @@ static int watchdog_open(struct inode *inode, struct file *filp)
1259 struct w83793_data *pos, *data = NULL; 1322 struct w83793_data *pos, *data = NULL;
1260 int watchdog_is_open; 1323 int watchdog_is_open;
1261 1324
1262 /* We get called from drivers/char/misc.c with misc_mtx hold, and we 1325 /*
1263 call misc_register() from w83793_probe() with watchdog_data_mutex 1326 * We get called from drivers/char/misc.c with misc_mtx hold, and we
1264 hold, as misc_register() takes the misc_mtx lock, this is a possible 1327 * call misc_register() from w83793_probe() with watchdog_data_mutex
1265 deadlock, so we use mutex_trylock here. */ 1328 * hold, as misc_register() takes the misc_mtx lock, this is a possible
1329 * deadlock, so we use mutex_trylock here.
1330 */
1266 if (!mutex_trylock(&watchdog_data_mutex)) 1331 if (!mutex_trylock(&watchdog_data_mutex))
1267 return -ERESTARTSYS; 1332 return -ERESTARTSYS;
1268 list_for_each_entry(pos, &watchdog_data_list, list) { 1333 list_for_each_entry(pos, &watchdog_data_list, list) {
@@ -1275,8 +1340,10 @@ static int watchdog_open(struct inode *inode, struct file *filp)
1275 /* Check, if device is already open */ 1340 /* Check, if device is already open */
1276 watchdog_is_open = test_and_set_bit(0, &data->watchdog_is_open); 1341 watchdog_is_open = test_and_set_bit(0, &data->watchdog_is_open);
1277 1342
1278 /* Increase data reference counter (if not already done). 1343 /*
1279 Note we can never not have found data, so we don't check for this */ 1344 * Increase data reference counter (if not already done).
1345 * Note we can never not have found data, so we don't check for this
1346 */
1280 if (!watchdog_is_open) 1347 if (!watchdog_is_open)
1281 kref_get(&data->kref); 1348 kref_get(&data->kref);
1282 1349
@@ -1556,9 +1623,8 @@ w83793_detect_subclients(struct i2c_client *client)
1556 } 1623 }
1557 1624
1558 tmp = w83793_read_value(client, W83793_REG_I2C_SUBADDR); 1625 tmp = w83793_read_value(client, W83793_REG_I2C_SUBADDR);
1559 if (!(tmp & 0x08)) { 1626 if (!(tmp & 0x08))
1560 data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (tmp & 0x7)); 1627 data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (tmp & 0x7));
1561 }
1562 if (!(tmp & 0x80)) { 1628 if (!(tmp & 0x80)) {
1563 if ((data->lm75[0] != NULL) 1629 if ((data->lm75[0] != NULL)
1564 && ((tmp & 0x7) == ((tmp >> 4) & 0x7))) { 1630 && ((tmp & 0x7) == ((tmp >> 4) & 0x7))) {
@@ -1591,9 +1657,8 @@ static int w83793_detect(struct i2c_client *client,
1591 struct i2c_adapter *adapter = client->adapter; 1657 struct i2c_adapter *adapter = client->adapter;
1592 unsigned short address = client->addr; 1658 unsigned short address = client->addr;
1593 1659
1594 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 1660 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1595 return -ENODEV; 1661 return -ENODEV;
1596 }
1597 1662
1598 bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL); 1663 bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL);
1599 1664
@@ -1604,8 +1669,10 @@ static int w83793_detect(struct i2c_client *client,
1604 return -ENODEV; 1669 return -ENODEV;
1605 } 1670 }
1606 1671
1607 /* If Winbond chip, address of chip and W83793_REG_I2C_ADDR 1672 /*
1608 should match */ 1673 * If Winbond chip, address of chip and W83793_REG_I2C_ADDR
1674 * should match
1675 */
1609 if ((bank & 0x07) == 0 1676 if ((bank & 0x07) == 0
1610 && i2c_smbus_read_byte_data(client, W83793_REG_I2C_ADDR) != 1677 && i2c_smbus_read_byte_data(client, W83793_REG_I2C_ADDR) !=
1611 (address << 1)) { 1678 (address << 1)) {
@@ -1647,9 +1714,11 @@ static int w83793_probe(struct i2c_client *client,
1647 INIT_LIST_HEAD(&data->list); 1714 INIT_LIST_HEAD(&data->list);
1648 kref_init(&data->kref); 1715 kref_init(&data->kref);
1649 1716
1650 /* Store client pointer in our data struct for watchdog usage 1717 /*
1651 (where the client is found through a data ptr instead of the 1718 * Store client pointer in our data struct for watchdog usage
1652 otherway around) */ 1719 * (where the client is found through a data ptr instead of the
1720 * otherway around)
1721 */
1653 data->client = client; 1722 data->client = client;
1654 1723
1655 err = w83793_detect_subclients(client); 1724 err = w83793_detect_subclients(client);
@@ -1660,8 +1729,8 @@ static int w83793_probe(struct i2c_client *client,
1660 w83793_init_client(client); 1729 w83793_init_client(client);
1661 1730
1662 /* 1731 /*
1663 Only fan 1-5 has their own input pins, 1732 * Only fan 1-5 has their own input pins,
1664 Pwm 1-3 has their own pins 1733 * Pwm 1-3 has their own pins
1665 */ 1734 */
1666 data->has_fan = 0x1f; 1735 data->has_fan = 0x1f;
1667 data->has_pwm = 0x07; 1736 data->has_pwm = 0x07;
@@ -1723,7 +1792,7 @@ static int w83793_probe(struct i2c_client *client,
1723 } 1792 }
1724 1793
1725 /* check the temp1-6 mode, ignore former AMDSI selected inputs */ 1794 /* check the temp1-6 mode, ignore former AMDSI selected inputs */
1726 tmp = w83793_read_value(client,W83793_REG_TEMP_MODE[0]); 1795 tmp = w83793_read_value(client, W83793_REG_TEMP_MODE[0]);
1727 if (tmp & 0x01) 1796 if (tmp & 0x01)
1728 data->has_temp |= 0x01; 1797 data->has_temp |= 0x01;
1729 if (tmp & 0x04) 1798 if (tmp & 0x04)
@@ -1733,7 +1802,7 @@ static int w83793_probe(struct i2c_client *client,
1733 if (tmp & 0x40) 1802 if (tmp & 0x40)
1734 data->has_temp |= 0x08; 1803 data->has_temp |= 0x08;
1735 1804
1736 tmp = w83793_read_value(client,W83793_REG_TEMP_MODE[1]); 1805 tmp = w83793_read_value(client, W83793_REG_TEMP_MODE[1]);
1737 if (tmp & 0x01) 1806 if (tmp & 0x01)
1738 data->has_temp |= 0x10; 1807 data->has_temp |= 0x10;
1739 if (tmp & 0x02) 1808 if (tmp & 0x02)
@@ -1823,9 +1892,11 @@ static int w83793_probe(struct i2c_client *client,
1823 goto exit_devunreg; 1892 goto exit_devunreg;
1824 } 1893 }
1825 1894
1826 /* Enable Watchdog registers. 1895 /*
1827 Set Configuration Register to Enable Watch Dog Registers 1896 * Enable Watchdog registers.
1828 (Bit 2) = XXXX, X1XX. */ 1897 * Set Configuration Register to Enable Watch Dog Registers
1898 * (Bit 2) = XXXX, X1XX.
1899 */
1829 tmp = w83793_read_value(client, W83793_REG_CONFIG); 1900 tmp = w83793_read_value(client, W83793_REG_CONFIG);
1830 w83793_write_value(client, W83793_REG_CONFIG, tmp | 0x04); 1901 w83793_write_value(client, W83793_REG_CONFIG, tmp | 0x04);
1831 1902
@@ -1839,9 +1910,11 @@ static int w83793_probe(struct i2c_client *client,
1839 /* Disable Soft Watchdog during initialiation */ 1910 /* Disable Soft Watchdog during initialiation */
1840 watchdog_disable(data); 1911 watchdog_disable(data);
1841 1912
1842 /* We take the data_mutex lock early so that watchdog_open() cannot 1913 /*
1843 run when misc_register() has completed, but we've not yet added 1914 * We take the data_mutex lock early so that watchdog_open() cannot
1844 our data to the watchdog_data_list (and set the default timeout) */ 1915 * run when misc_register() has completed, but we've not yet added
1916 * our data to the watchdog_data_list (and set the default timeout)
1917 */
1845 mutex_lock(&watchdog_data_mutex); 1918 mutex_lock(&watchdog_data_mutex);
1846 for (i = 0; i < ARRAY_SIZE(watchdog_minors); i++) { 1919 for (i = 0; i < ARRAY_SIZE(watchdog_minors); i++) {
1847 /* Register our watchdog part */ 1920 /* Register our watchdog part */
@@ -1921,9 +1994,9 @@ static void w83793_update_nonvolatile(struct device *dev)
1921 struct w83793_data *data = i2c_get_clientdata(client); 1994 struct w83793_data *data = i2c_get_clientdata(client);
1922 int i, j; 1995 int i, j;
1923 /* 1996 /*
1924 They are somewhat "stable" registers, and to update them every time 1997 * They are somewhat "stable" registers, and to update them every time
1925 takes so much time, it's just not worthy. Update them in a long 1998 * takes so much time, it's just not worthy. Update them in a long
1926 interval to avoid exception. 1999 * interval to avoid exception.
1927 */ 2000 */
1928 if (!(time_after(jiffies, data->last_nonvolatile + HZ * 300) 2001 if (!(time_after(jiffies, data->last_nonvolatile + HZ * 300)
1929 || !data->valid)) 2002 || !data->valid))
@@ -1940,9 +2013,8 @@ static void w83793_update_nonvolatile(struct device *dev)
1940 2013
1941 for (i = 0; i < ARRAY_SIZE(data->fan_min); i++) { 2014 for (i = 0; i < ARRAY_SIZE(data->fan_min); i++) {
1942 /* Update the Fan measured value and limits */ 2015 /* Update the Fan measured value and limits */
1943 if (!(data->has_fan & (1 << i))) { 2016 if (!(data->has_fan & (1 << i)))
1944 continue; 2017 continue;
1945 }
1946 data->fan_min[i] = 2018 data->fan_min[i] =
1947 w83793_read_value(client, W83793_REG_FAN_MIN(i)) << 8; 2019 w83793_read_value(client, W83793_REG_FAN_MIN(i)) << 8;
1948 data->fan_min[i] |= 2020 data->fan_min[i] |=
@@ -1997,9 +2069,8 @@ static void w83793_update_nonvolatile(struct device *dev)
1997 w83793_read_value(client, W83793_REG_TEMP_CRITICAL); 2069 w83793_read_value(client, W83793_REG_TEMP_CRITICAL);
1998 data->beep_enable = w83793_read_value(client, W83793_REG_OVT_BEEP); 2070 data->beep_enable = w83793_read_value(client, W83793_REG_OVT_BEEP);
1999 2071
2000 for (i = 0; i < ARRAY_SIZE(data->beeps); i++) { 2072 for (i = 0; i < ARRAY_SIZE(data->beeps); i++)
2001 data->beeps[i] = w83793_read_value(client, W83793_REG_BEEP(i)); 2073 data->beeps[i] = w83793_read_value(client, W83793_REG_BEEP(i));
2002 }
2003 2074
2004 data->last_nonvolatile = jiffies; 2075 data->last_nonvolatile = jiffies;
2005} 2076}
@@ -2025,9 +2096,8 @@ static struct w83793_data *w83793_update_device(struct device *dev)
2025 w83793_read_value(client, W83793_REG_IN_LOW_BITS[IN_READ]); 2096 w83793_read_value(client, W83793_REG_IN_LOW_BITS[IN_READ]);
2026 2097
2027 for (i = 0; i < ARRAY_SIZE(data->fan); i++) { 2098 for (i = 0; i < ARRAY_SIZE(data->fan); i++) {
2028 if (!(data->has_fan & (1 << i))) { 2099 if (!(data->has_fan & (1 << i)))
2029 continue; 2100 continue;
2030 }
2031 data->fan[i] = 2101 data->fan[i] =
2032 w83793_read_value(client, W83793_REG_FAN(i)) << 8; 2102 w83793_read_value(client, W83793_REG_FAN(i)) << 8;
2033 data->fan[i] |= 2103 data->fan[i] |=
@@ -2067,8 +2137,10 @@ END:
2067 return data; 2137 return data;
2068} 2138}
2069 2139
2070/* Ignore the possibility that somebody change bank outside the driver 2140/*
2071 Must be called with data->update_lock held, except during initialization */ 2141 * Ignore the possibility that somebody change bank outside the driver
2142 * Must be called with data->update_lock held, except during initialization
2143 */
2072static u8 w83793_read_value(struct i2c_client *client, u16 reg) 2144static u8 w83793_read_value(struct i2c_client *client, u16 reg)
2073{ 2145{
2074 struct w83793_data *data = i2c_get_clientdata(client); 2146 struct w83793_data *data = i2c_get_clientdata(client);
@@ -2103,16 +2175,16 @@ static int w83793_write_value(struct i2c_client *client, u16 reg, u8 value)
2103 2175
2104 new_bank |= data->bank & 0xfc; 2176 new_bank |= data->bank & 0xfc;
2105 if (data->bank != new_bank) { 2177 if (data->bank != new_bank) {
2106 if ((res = i2c_smbus_write_byte_data 2178 res = i2c_smbus_write_byte_data(client, W83793_REG_BANKSEL,
2107 (client, W83793_REG_BANKSEL, new_bank)) >= 0) 2179 new_bank);
2108 data->bank = new_bank; 2180 if (res < 0) {
2109 else {
2110 dev_err(&client->dev, 2181 dev_err(&client->dev,
2111 "set bank to %d failed, fall back " 2182 "set bank to %d failed, fall back "
2112 "to bank %d, write reg 0x%x error\n", 2183 "to bank %d, write reg 0x%x error\n",
2113 new_bank, data->bank, reg); 2184 new_bank, data->bank, reg);
2114 goto END; 2185 goto END;
2115 } 2186 }
2187 data->bank = new_bank;
2116 } 2188 }
2117 2189
2118 res = i2c_smbus_write_byte_data(client, reg & 0xff, value); 2190 res = i2c_smbus_write_byte_data(client, reg & 0xff, value);
@@ -2120,19 +2192,8 @@ END:
2120 return res; 2192 return res;
2121} 2193}
2122 2194
2123static int __init sensors_w83793_init(void) 2195module_i2c_driver(w83793_driver);
2124{
2125 return i2c_add_driver(&w83793_driver);
2126}
2127
2128static void __exit sensors_w83793_exit(void)
2129{
2130 i2c_del_driver(&w83793_driver);
2131}
2132 2196
2133MODULE_AUTHOR("Yuan Mu, Sven Anders"); 2197MODULE_AUTHOR("Yuan Mu, Sven Anders");
2134MODULE_DESCRIPTION("w83793 driver"); 2198MODULE_DESCRIPTION("w83793 driver");
2135MODULE_LICENSE("GPL"); 2199MODULE_LICENSE("GPL");
2136
2137module_init(sensors_w83793_init);
2138module_exit(sensors_w83793_exit);
diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c
index aa58b25565bc..deb12c982800 100644
--- a/drivers/hwmon/w83795.c
+++ b/drivers/hwmon/w83795.c
@@ -2244,19 +2244,8 @@ static struct i2c_driver w83795_driver = {
2244 .address_list = normal_i2c, 2244 .address_list = normal_i2c,
2245}; 2245};
2246 2246
2247static int __init sensors_w83795_init(void) 2247module_i2c_driver(w83795_driver);
2248{
2249 return i2c_add_driver(&w83795_driver);
2250}
2251
2252static void __exit sensors_w83795_exit(void)
2253{
2254 i2c_del_driver(&w83795_driver);
2255}
2256 2248
2257MODULE_AUTHOR("Wei Song, Jean Delvare <khali@linux-fr.org>"); 2249MODULE_AUTHOR("Wei Song, Jean Delvare <khali@linux-fr.org>");
2258MODULE_DESCRIPTION("W83795G/ADG hardware monitoring driver"); 2250MODULE_DESCRIPTION("W83795G/ADG hardware monitoring driver");
2259MODULE_LICENSE("GPL"); 2251MODULE_LICENSE("GPL");
2260
2261module_init(sensors_w83795_init);
2262module_exit(sensors_w83795_exit);
diff --git a/drivers/hwmon/w83l785ts.c b/drivers/hwmon/w83l785ts.c
index 20781def65ed..5f14e3897058 100644
--- a/drivers/hwmon/w83l785ts.c
+++ b/drivers/hwmon/w83l785ts.c
@@ -86,7 +86,7 @@ static struct w83l785ts_data *w83l785ts_update_device(struct device *dev);
86/* 86/*
87 * Driver data (common to all clients) 87 * Driver data (common to all clients)
88 */ 88 */
89 89
90static const struct i2c_device_id w83l785ts_id[] = { 90static const struct i2c_device_id w83l785ts_id[] = {
91 { "w83l785ts", 0 }, 91 { "w83l785ts", 0 },
92 { } 92 { }
@@ -116,8 +116,7 @@ struct w83l785ts_data {
116 unsigned long last_updated; /* in jiffies */ 116 unsigned long last_updated; /* in jiffies */
117 117
118 /* registers values */ 118 /* registers values */
119 s8 temp[2]; /* 0: input 119 s8 temp[2]; /* 0: input, 1: critical limit */
120 1: critical limit */
121}; 120};
122 121
123/* 122/*
@@ -250,8 +249,10 @@ static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval)
250 struct device *dev; 249 struct device *dev;
251 const char *prefix; 250 const char *prefix;
252 251
253 /* We might be called during detection, at which point the client 252 /*
254 isn't yet fully initialized, so we can't use dev_dbg on it */ 253 * We might be called during detection, at which point the client
254 * isn't yet fully initialized, so we can't use dev_dbg on it
255 */
255 if (i2c_get_clientdata(client)) { 256 if (i2c_get_clientdata(client)) {
256 dev = &client->dev; 257 dev = &client->dev;
257 prefix = ""; 258 prefix = "";
@@ -260,9 +261,11 @@ static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval)
260 prefix = "w83l785ts: "; 261 prefix = "w83l785ts: ";
261 } 262 }
262 263
263 /* Frequent read errors have been reported on Asus boards, so we 264 /*
265 * Frequent read errors have been reported on Asus boards, so we
264 * retry on read errors. If it still fails (unlikely), return the 266 * retry on read errors. If it still fails (unlikely), return the
265 * default value requested by the caller. */ 267 * default value requested by the caller.
268 */
266 for (i = 1; i <= MAX_RETRIES; i++) { 269 for (i = 1; i <= MAX_RETRIES; i++) {
267 value = i2c_smbus_read_byte_data(client, reg); 270 value = i2c_smbus_read_byte_data(client, reg);
268 if (value >= 0) { 271 if (value >= 0) {
@@ -302,19 +305,8 @@ static struct w83l785ts_data *w83l785ts_update_device(struct device *dev)
302 return data; 305 return data;
303} 306}
304 307
305static int __init sensors_w83l785ts_init(void) 308module_i2c_driver(w83l785ts_driver);
306{
307 return i2c_add_driver(&w83l785ts_driver);
308}
309
310static void __exit sensors_w83l785ts_exit(void)
311{
312 i2c_del_driver(&w83l785ts_driver);
313}
314 309
315MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); 310MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
316MODULE_DESCRIPTION("W83L785TS-S driver"); 311MODULE_DESCRIPTION("W83L785TS-S driver");
317MODULE_LICENSE("GPL"); 312MODULE_LICENSE("GPL");
318
319module_init(sensors_w83l785ts_init);
320module_exit(sensors_w83l785ts_exit);
diff --git a/drivers/hwmon/w83l786ng.c b/drivers/hwmon/w83l786ng.c
index 063bd9508d8a..5850b7706088 100644
--- a/drivers/hwmon/w83l786ng.c
+++ b/drivers/hwmon/w83l786ng.c
@@ -1,28 +1,28 @@
1/* 1/*
2 w83l786ng.c - Linux kernel driver for hardware monitoring 2 * w83l786ng.c - Linux kernel driver for hardware monitoring
3 Copyright (c) 2007 Kevin Lo <kevlo@kevlo.org> 3 * Copyright (c) 2007 Kevin Lo <kevlo@kevlo.org>
4 4 *
5 This program is free software; you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License as published by
7 the Free Software Foundation - version 2. 7 * the Free Software Foundation - version 2.
8 8 *
9 This program is distributed in the hope that it will be useful, 9 * This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 * GNU General Public License for more details.
13 13 *
14 You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software 15 * along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301 USA. 17 * 02110-1301 USA.
18*/ 18 */
19 19
20/* 20/*
21 Supports following chips: 21 * Supports following chips:
22 22 *
23 Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA 23 * Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
24 w83l786ng 3 2 2 2 0x7b 0x5ca3 yes no 24 * w83l786ng 3 2 2 2 0x7b 0x5ca3 yes no
25*/ 25 */
26 26
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/init.h> 28#include <linux/init.h>
@@ -52,7 +52,7 @@ MODULE_PARM_DESC(reset, "Set to 1 to reset chip, not recommended");
52 52
53#define W83L786NG_REG_CONFIG 0x40 53#define W83L786NG_REG_CONFIG 0x40
54#define W83L786NG_REG_ALARM1 0x41 54#define W83L786NG_REG_ALARM1 0x41
55#define W83L786NG_REG_ALARM2 0x42 55#define W83L786NG_REG_ALARM2 0x42
56#define W83L786NG_REG_GPIO_EN 0x47 56#define W83L786NG_REG_GPIO_EN 0x47
57#define W83L786NG_REG_MAN_ID2 0x4C 57#define W83L786NG_REG_MAN_ID2 0x4C
58#define W83L786NG_REG_MAN_ID1 0x4D 58#define W83L786NG_REG_MAN_ID1 0x4D
@@ -89,19 +89,23 @@ FAN_TO_REG(long rpm, int div)
89 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); 89 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
90} 90}
91 91
92#define FAN_FROM_REG(val,div) ((val) == 0 ? -1 : \ 92#define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \
93 ((val) == 255 ? 0 : \ 93 ((val) == 255 ? 0 : \
94 1350000 / ((val) * (div)))) 94 1350000 / ((val) * (div))))
95 95
96/* for temp */ 96/* for temp */
97#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? (val)+0x100*1000 \ 97#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? \
98 : (val)) / 1000, 0, 0xff)) 98 (val) + 0x100 * 1000 \
99#define TEMP_FROM_REG(val) (((val) & 0x80 ? (val)-0x100 : (val)) * 1000) 99 : (val)) / 1000, 0, 0xff))
100 100#define TEMP_FROM_REG(val) (((val) & 0x80 ? \
101/* The analog voltage inputs have 8mV LSB. Since the sysfs output is 101 (val) - 0x100 : (val)) * 1000)
102 in mV as would be measured on the chip input pin, need to just 102
103 multiply/divide by 8 to translate from/to register values. */ 103/*
104#define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 4) / 8), 0, 255)) 104 * The analog voltage inputs have 8mV LSB. Since the sysfs output is
105 * in mV as would be measured on the chip input pin, need to just
106 * multiply/divide by 8 to translate from/to register values.
107 */
108#define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 4) / 8), 0, 255))
105#define IN_FROM_REG(val) ((val) * 8) 109#define IN_FROM_REG(val) ((val) * 8)
106 110
107#define DIV_FROM_REG(val) (1 << (val)) 111#define DIV_FROM_REG(val) (1 << (val))
@@ -116,7 +120,7 @@ DIV_TO_REG(long val)
116 break; 120 break;
117 val >>= 1; 121 val >>= 1;
118 } 122 }
119 return ((u8) i); 123 return (u8)i;
120} 124}
121 125
122struct w83l786ng_data { 126struct w83l786ng_data {
@@ -125,7 +129,7 @@ struct w83l786ng_data {
125 char valid; /* !=0 if following fields are valid */ 129 char valid; /* !=0 if following fields are valid */
126 unsigned long last_updated; /* In jiffies */ 130 unsigned long last_updated; /* In jiffies */
127 unsigned long last_nonvolatile; /* In jiffies, last time we update the 131 unsigned long last_nonvolatile; /* In jiffies, last time we update the
128 nonvolatile registers */ 132 * nonvolatile registers */
129 133
130 u8 in[3]; 134 u8 in[3];
131 u8 in_max[3]; 135 u8 in_max[3];
@@ -137,10 +141,10 @@ struct w83l786ng_data {
137 u8 temp[2][3]; 141 u8 temp[2][3];
138 u8 pwm[2]; 142 u8 pwm[2];
139 u8 pwm_mode[2]; /* 0->DC variable voltage 143 u8 pwm_mode[2]; /* 0->DC variable voltage
140 1->PWM variable duty cycle */ 144 * 1->PWM variable duty cycle */
141 145
142 u8 pwm_enable[2]; /* 1->manual 146 u8 pwm_enable[2]; /* 1->manual
143 2->thermal cruise (also called SmartFan I) */ 147 * 2->thermal cruise (also called SmartFan I) */
144 u8 tolerance[2]; 148 u8 tolerance[2];
145}; 149};
146 150
@@ -186,11 +190,11 @@ w83l786ng_write_value(struct i2c_client *client, u8 reg, u8 value)
186#define show_in_reg(reg) \ 190#define show_in_reg(reg) \
187static ssize_t \ 191static ssize_t \
188show_##reg(struct device *dev, struct device_attribute *attr, \ 192show_##reg(struct device *dev, struct device_attribute *attr, \
189 char *buf) \ 193 char *buf) \
190{ \ 194{ \
191 int nr = to_sensor_dev_attr(attr)->index; \ 195 int nr = to_sensor_dev_attr(attr)->index; \
192 struct w83l786ng_data *data = w83l786ng_update_device(dev); \ 196 struct w83l786ng_data *data = w83l786ng_update_device(dev); \
193 return sprintf(buf,"%d\n", IN_FROM_REG(data->reg[nr])); \ 197 return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \
194} 198}
195 199
196show_in_reg(in) 200show_in_reg(in)
@@ -199,13 +203,16 @@ show_in_reg(in_max)
199 203
200#define store_in_reg(REG, reg) \ 204#define store_in_reg(REG, reg) \
201static ssize_t \ 205static ssize_t \
202store_in_##reg (struct device *dev, struct device_attribute *attr, \ 206store_in_##reg(struct device *dev, struct device_attribute *attr, \
203 const char *buf, size_t count) \ 207 const char *buf, size_t count) \
204{ \ 208{ \
205 int nr = to_sensor_dev_attr(attr)->index; \ 209 int nr = to_sensor_dev_attr(attr)->index; \
206 struct i2c_client *client = to_i2c_client(dev); \ 210 struct i2c_client *client = to_i2c_client(dev); \
207 struct w83l786ng_data *data = i2c_get_clientdata(client); \ 211 struct w83l786ng_data *data = i2c_get_clientdata(client); \
208 unsigned long val = simple_strtoul(buf, NULL, 10); \ 212 unsigned long val; \
213 int err = kstrtoul(buf, 10, &val); \
214 if (err) \
215 return err; \
209 mutex_lock(&data->update_lock); \ 216 mutex_lock(&data->update_lock); \
210 data->in_##reg[nr] = IN_TO_REG(val); \ 217 data->in_##reg[nr] = IN_TO_REG(val); \
211 w83l786ng_write_value(client, W83L786NG_REG_IN_##REG(nr), \ 218 w83l786ng_write_value(client, W83L786NG_REG_IN_##REG(nr), \
@@ -241,8 +248,8 @@ static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
241{ \ 248{ \
242 int nr = to_sensor_dev_attr(attr)->index; \ 249 int nr = to_sensor_dev_attr(attr)->index; \
243 struct w83l786ng_data *data = w83l786ng_update_device(dev); \ 250 struct w83l786ng_data *data = w83l786ng_update_device(dev); \
244 return sprintf(buf,"%d\n", \ 251 return sprintf(buf, "%d\n", \
245 FAN_FROM_REG(data->fan[nr], DIV_FROM_REG(data->fan_div[nr]))); \ 252 FAN_FROM_REG(data->fan[nr], DIV_FROM_REG(data->fan_div[nr]))); \
246} 253}
247 254
248show_fan_reg(fan); 255show_fan_reg(fan);
@@ -255,9 +262,13 @@ store_fan_min(struct device *dev, struct device_attribute *attr,
255 int nr = to_sensor_dev_attr(attr)->index; 262 int nr = to_sensor_dev_attr(attr)->index;
256 struct i2c_client *client = to_i2c_client(dev); 263 struct i2c_client *client = to_i2c_client(dev);
257 struct w83l786ng_data *data = i2c_get_clientdata(client); 264 struct w83l786ng_data *data = i2c_get_clientdata(client);
258 u32 val; 265 unsigned long val;
266 int err;
267
268 err = kstrtoul(buf, 10, &val);
269 if (err)
270 return err;
259 271
260 val = simple_strtoul(buf, NULL, 10);
261 mutex_lock(&data->update_lock); 272 mutex_lock(&data->update_lock);
262 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 273 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
263 w83l786ng_write_value(client, W83L786NG_REG_FAN_MIN(nr), 274 w83l786ng_write_value(client, W83L786NG_REG_FAN_MIN(nr),
@@ -276,10 +287,12 @@ show_fan_div(struct device *dev, struct device_attribute *attr,
276 return sprintf(buf, "%u\n", DIV_FROM_REG(data->fan_div[nr])); 287 return sprintf(buf, "%u\n", DIV_FROM_REG(data->fan_div[nr]));
277} 288}
278 289
279/* Note: we save and restore the fan minimum here, because its value is 290/*
280 determined in part by the fan divisor. This follows the principle of 291 * Note: we save and restore the fan minimum here, because its value is
281 least surprise; the user doesn't expect the fan minimum to change just 292 * determined in part by the fan divisor. This follows the principle of
282 because the divisor changed. */ 293 * least surprise; the user doesn't expect the fan minimum to change just
294 * because the divisor changed.
295 */
283static ssize_t 296static ssize_t
284store_fan_div(struct device *dev, struct device_attribute *attr, 297store_fan_div(struct device *dev, struct device_attribute *attr,
285 const char *buf, size_t count) 298 const char *buf, size_t count)
@@ -294,11 +307,18 @@ store_fan_div(struct device *dev, struct device_attribute *attr,
294 u8 keep_mask = 0; 307 u8 keep_mask = 0;
295 u8 new_shift = 0; 308 u8 new_shift = 0;
296 309
310 unsigned long val;
311 int err;
312
313 err = kstrtoul(buf, 10, &val);
314 if (err)
315 return err;
316
297 /* Save fan_min */ 317 /* Save fan_min */
298 mutex_lock(&data->update_lock); 318 mutex_lock(&data->update_lock);
299 min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])); 319 min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]));
300 320
301 data->fan_div[nr] = DIV_TO_REG(simple_strtoul(buf, NULL, 10)); 321 data->fan_div[nr] = DIV_TO_REG(val);
302 322
303 switch (nr) { 323 switch (nr) {
304 case 0: 324 case 0:
@@ -371,16 +391,20 @@ store_temp(struct device *dev, struct device_attribute *attr,
371 int index = sensor_attr->index; 391 int index = sensor_attr->index;
372 struct i2c_client *client = to_i2c_client(dev); 392 struct i2c_client *client = to_i2c_client(dev);
373 struct w83l786ng_data *data = i2c_get_clientdata(client); 393 struct w83l786ng_data *data = i2c_get_clientdata(client);
374 s32 val; 394 long val;
395 int err;
396
397 err = kstrtol(buf, 10, &val);
398 if (err)
399 return err;
375 400
376 val = simple_strtol(buf, NULL, 10);
377 mutex_lock(&data->update_lock); 401 mutex_lock(&data->update_lock);
378 data->temp[nr][index] = TEMP_TO_REG(val); 402 data->temp[nr][index] = TEMP_TO_REG(val);
379 w83l786ng_write_value(client, W83L786NG_REG_TEMP[nr][index], 403 w83l786ng_write_value(client, W83L786NG_REG_TEMP[nr][index],
380 data->temp[nr][index]); 404 data->temp[nr][index]);
381 mutex_unlock(&data->update_lock); 405 mutex_unlock(&data->update_lock);
382 406
383 return count; 407 return count;
384} 408}
385 409
386static struct sensor_device_attribute_2 sda_temp_input[] = { 410static struct sensor_device_attribute_2 sda_temp_input[] = {
@@ -403,8 +427,8 @@ static struct sensor_device_attribute_2 sda_temp_max_hyst[] = {
403}; 427};
404 428
405#define show_pwm_reg(reg) \ 429#define show_pwm_reg(reg) \
406static ssize_t show_##reg (struct device *dev, struct device_attribute *attr, \ 430static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
407 char *buf) \ 431 char *buf) \
408{ \ 432{ \
409 struct w83l786ng_data *data = w83l786ng_update_device(dev); \ 433 struct w83l786ng_data *data = w83l786ng_update_device(dev); \
410 int nr = to_sensor_dev_attr(attr)->index; \ 434 int nr = to_sensor_dev_attr(attr)->index; \
@@ -422,8 +446,13 @@ store_pwm_mode(struct device *dev, struct device_attribute *attr,
422 int nr = to_sensor_dev_attr(attr)->index; 446 int nr = to_sensor_dev_attr(attr)->index;
423 struct i2c_client *client = to_i2c_client(dev); 447 struct i2c_client *client = to_i2c_client(dev);
424 struct w83l786ng_data *data = i2c_get_clientdata(client); 448 struct w83l786ng_data *data = i2c_get_clientdata(client);
425 u32 val = simple_strtoul(buf, NULL, 10);
426 u8 reg; 449 u8 reg;
450 unsigned long val;
451 int err;
452
453 err = kstrtoul(buf, 10, &val);
454 if (err)
455 return err;
427 456
428 if (val > 1) 457 if (val > 1)
429 return -EINVAL; 458 return -EINVAL;
@@ -445,7 +474,13 @@ store_pwm(struct device *dev, struct device_attribute *attr,
445 int nr = to_sensor_dev_attr(attr)->index; 474 int nr = to_sensor_dev_attr(attr)->index;
446 struct i2c_client *client = to_i2c_client(dev); 475 struct i2c_client *client = to_i2c_client(dev);
447 struct w83l786ng_data *data = i2c_get_clientdata(client); 476 struct w83l786ng_data *data = i2c_get_clientdata(client);
448 u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 255); 477 unsigned long val;
478 int err;
479
480 err = kstrtoul(buf, 10, &val);
481 if (err)
482 return err;
483 val = SENSORS_LIMIT(val, 0, 255);
449 484
450 mutex_lock(&data->update_lock); 485 mutex_lock(&data->update_lock);
451 data->pwm[nr] = val; 486 data->pwm[nr] = val;
@@ -461,11 +496,15 @@ store_pwm_enable(struct device *dev, struct device_attribute *attr,
461 int nr = to_sensor_dev_attr(attr)->index; 496 int nr = to_sensor_dev_attr(attr)->index;
462 struct i2c_client *client = to_i2c_client(dev); 497 struct i2c_client *client = to_i2c_client(dev);
463 struct w83l786ng_data *data = i2c_get_clientdata(client); 498 struct w83l786ng_data *data = i2c_get_clientdata(client);
464 u32 val = simple_strtoul(buf, NULL, 10);
465
466 u8 reg; 499 u8 reg;
500 unsigned long val;
501 int err;
467 502
468 if (!val || (val > 2)) /* only modes 1 and 2 are supported */ 503 err = kstrtoul(buf, 10, &val);
504 if (err)
505 return err;
506
507 if (!val || val > 2) /* only modes 1 and 2 are supported */
469 return -EINVAL; 508 return -EINVAL;
470 509
471 mutex_lock(&data->update_lock); 510 mutex_lock(&data->update_lock);
@@ -513,10 +552,13 @@ store_tolerance(struct device *dev, struct device_attribute *attr,
513 int nr = to_sensor_dev_attr(attr)->index; 552 int nr = to_sensor_dev_attr(attr)->index;
514 struct i2c_client *client = to_i2c_client(dev); 553 struct i2c_client *client = to_i2c_client(dev);
515 struct w83l786ng_data *data = i2c_get_clientdata(client); 554 struct w83l786ng_data *data = i2c_get_clientdata(client);
516 u32 val;
517 u8 tol_tmp, tol_mask; 555 u8 tol_tmp, tol_mask;
556 unsigned long val;
557 int err;
518 558
519 val = simple_strtoul(buf, NULL, 10); 559 err = kstrtoul(buf, 10, &val);
560 if (err)
561 return err;
520 562
521 mutex_lock(&data->update_lock); 563 mutex_lock(&data->update_lock);
522 tol_mask = w83l786ng_read_value(client, 564 tol_mask = w83l786ng_read_value(client,
@@ -524,9 +566,8 @@ store_tolerance(struct device *dev, struct device_attribute *attr,
524 tol_tmp = SENSORS_LIMIT(val, 0, 15); 566 tol_tmp = SENSORS_LIMIT(val, 0, 15);
525 tol_tmp &= 0x0f; 567 tol_tmp &= 0x0f;
526 data->tolerance[nr] = tol_tmp; 568 data->tolerance[nr] = tol_tmp;
527 if (nr == 1) { 569 if (nr == 1)
528 tol_tmp <<= 4; 570 tol_tmp <<= 4;
529 }
530 571
531 w83l786ng_write_value(client, W83L786NG_REG_TOLERANCE, 572 w83l786ng_write_value(client, W83L786NG_REG_TOLERANCE,
532 tol_mask | tol_tmp); 573 tol_mask | tol_tmp);
@@ -591,9 +632,8 @@ w83l786ng_detect(struct i2c_client *client, struct i2c_board_info *info)
591 u16 man_id; 632 u16 man_id;
592 u8 chip_id; 633 u8 chip_id;
593 634
594 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 635 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
595 return -ENODEV; 636 return -ENODEV;
596 }
597 637
598 /* Detection */ 638 /* Detection */
599 if ((w83l786ng_read_value(client, W83L786NG_REG_CONFIG) & 0x80)) { 639 if ((w83l786ng_read_value(client, W83L786NG_REG_CONFIG) & 0x80)) {
@@ -652,7 +692,8 @@ w83l786ng_probe(struct i2c_client *client, const struct i2c_device_id *id)
652 data->fan_div[1] = (reg_tmp >> 4) & 0x07; 692 data->fan_div[1] = (reg_tmp >> 4) & 0x07;
653 693
654 /* Register sysfs hooks */ 694 /* Register sysfs hooks */
655 if ((err = sysfs_create_group(&client->dev.kobj, &w83l786ng_group))) 695 err = sysfs_create_group(&client->dev.kobj, &w83l786ng_group);
696 if (err)
656 goto exit_remove; 697 goto exit_remove;
657 698
658 data->hwmon_dev = hwmon_device_register(dev); 699 data->hwmon_dev = hwmon_device_register(dev);
@@ -769,21 +810,8 @@ static struct w83l786ng_data *w83l786ng_update_device(struct device *dev)
769 return data; 810 return data;
770} 811}
771 812
772static int __init 813module_i2c_driver(w83l786ng_driver);
773sensors_w83l786ng_init(void)
774{
775 return i2c_add_driver(&w83l786ng_driver);
776}
777
778static void __exit
779sensors_w83l786ng_exit(void)
780{
781 i2c_del_driver(&w83l786ng_driver);
782}
783 814
784MODULE_AUTHOR("Kevin Lo"); 815MODULE_AUTHOR("Kevin Lo");
785MODULE_DESCRIPTION("w83l786ng driver"); 816MODULE_DESCRIPTION("w83l786ng driver");
786MODULE_LICENSE("GPL"); 817MODULE_LICENSE("GPL");
787
788module_init(sensors_w83l786ng_init);
789module_exit(sensors_w83l786ng_exit);
diff --git a/drivers/hwmon/wm831x-hwmon.c b/drivers/hwmon/wm831x-hwmon.c
index 9b598ed26020..07cb25ae69be 100644
--- a/drivers/hwmon/wm831x-hwmon.c
+++ b/drivers/hwmon/wm831x-hwmon.c
@@ -40,7 +40,7 @@ static ssize_t show_name(struct device *dev,
40 return sprintf(buf, "wm831x\n"); 40 return sprintf(buf, "wm831x\n");
41} 41}
42 42
43static const char *input_names[] = { 43static const char * const input_names[] = {
44 [WM831X_AUX_SYSVDD] = "SYSVDD", 44 [WM831X_AUX_SYSVDD] = "SYSVDD",
45 [WM831X_AUX_USB] = "USB", 45 [WM831X_AUX_USB] = "USB",
46 [WM831X_AUX_BKUP_BATT] = "Backup battery", 46 [WM831X_AUX_BKUP_BATT] = "Backup battery",
@@ -117,8 +117,10 @@ static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_chip_temp, NULL,
117 WM831X_AUX_CHIP_TEMP); 117 WM831X_AUX_CHIP_TEMP);
118static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, show_label, NULL, 118static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, show_label, NULL,
119 WM831X_AUX_CHIP_TEMP); 119 WM831X_AUX_CHIP_TEMP);
120/* Report as a voltage since conversion depends on external components 120/*
121 * and that's what the ABI wants. */ 121 * Report as a voltage since conversion depends on external components
122 * and that's what the ABI wants.
123 */
122static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_voltage, NULL, 124static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_voltage, NULL,
123 WM831X_AUX_BATT_TEMP); 125 WM831X_AUX_BATT_TEMP);
124static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, show_label, NULL, 126static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, show_label, NULL,
diff --git a/drivers/hwmon/wm8350-hwmon.c b/drivers/hwmon/wm8350-hwmon.c
index 3ff67edbdc44..b955756bdb42 100644
--- a/drivers/hwmon/wm8350-hwmon.c
+++ b/drivers/hwmon/wm8350-hwmon.c
@@ -34,7 +34,7 @@ static ssize_t show_name(struct device *dev,
34 return sprintf(buf, "wm8350\n"); 34 return sprintf(buf, "wm8350\n");
35} 35}
36 36
37static const char *input_names[] = { 37static const char * const input_names[] = {
38 [WM8350_AUXADC_USB] = "USB", 38 [WM8350_AUXADC_USB] = "USB",
39 [WM8350_AUXADC_LINE] = "Line", 39 [WM8350_AUXADC_LINE] = "Line",
40 [WM8350_AUXADC_BATT] = "Battery", 40 [WM8350_AUXADC_BATT] = "Battery",