diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-08-05 18:55:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-08-05 18:55:36 -0400 |
commit | 161d2e0a195292a8a67b0f5c48e12a9984f75dac (patch) | |
tree | 4f3c516ab41737b1e51a58ca3d5f8cca421ae949 | |
parent | c489d98c8c81a898cfed6bec193cca2006f956aa (diff) | |
parent | fce9626cd93abaf1ef21b361f8a0fa493cc855b2 (diff) |
Merge tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging
Pull hwmon updates from Guenter Roeck:
"Notable changes:
- Heiko Schocher provided a driver for TI TMP103.
- Kamil Debski provided a driver for pwm-controlled fans.
- Neelesh Gupta provided a driver for power, fan rpm, voltage and
temperature reporting on powerpc/powernv systems.
- Scott Kanowitz provided a driver supporting Lattice's POWR1220
power manager IC.
- Richard Zhu provided a pmbus front-end driver for TPS40422.
- Frans Klaver added support for TMP112 to the lm75 driver.
- Johannes Pointner added support for EPCOS B57330V2103 to the
ntc_thermistor driver.
- Guenter Roeck added support for TMP441 and TMP442 to the tmp421
driver.
- Axel Lin converted several drivers to the new hwmon API (36 of
them, if I counted correctly), and cleaned up many of the drivers
along the way.
There are also a number of patches fixing bugs discovered while
testing Axel's changes"
* tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: (88 commits)
hwmon: (g762) Use of_property_read_u32 at appropriate place
hwmon: (sis5595) Prevent overflow problem when writing large limits
hwmon: (gpio-fan) Prevent overflow problem when writing large limits
hwmon: (ibmpowernv) Use of_property_read_u32 at appropriate place
hwmon: (lm85) Convert to devm_hwmon_device_register_with_groups
hwmon: (lm85) Avoid forward declaration
hwmon: (lm78) Convert to devm_hwmon_device_register_with_groups
hwmon: (max6697) Use of_property_read_bool at appropriate places
hwmon: (pwm-fan) Make SENSORS_PWM_FAN depend on OF
hwmon: (pwm-fan) Remove duplicate dev_set_drvdata call
hwmon: (nct6775) Remove num_attr_groups from struct nct6775_data
hwmon: (nct6775) Update module description and Kconfig for NCT6106D and NCT6791D
hwmon: (adt7411) Convert to devm_hwmon_device_register_with_groups
hwmon: (g762) Convert to hwmon_device_register_with_groups
hwmon: (emc2103) Convert to devm_hwmon_device_register_with_groups
hwmon: (smsc47m1) Avoid forward declaration
hwmon: (smsc47m192) Convert to devm_hwmon_device_register_with_groups
hwmon: (smsc47m192) Avoid forward declaration
hwmon: (max1668) Make max1668_addr_list array const
hwmon: (max6639) Make normal_i2c array const
...
81 files changed, 4258 insertions, 3885 deletions
diff --git a/Documentation/devicetree/bindings/hwmon/ibmpowernv.txt b/Documentation/devicetree/bindings/hwmon/ibmpowernv.txt new file mode 100644 index 000000000000..f93242be60a1 --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/ibmpowernv.txt | |||
@@ -0,0 +1,23 @@ | |||
1 | IBM POWERNV platform sensors | ||
2 | ---------------------------- | ||
3 | |||
4 | Required node properties: | ||
5 | - compatible: must be one of | ||
6 | "ibm,opal-sensor-cooling-fan" | ||
7 | "ibm,opal-sensor-amb-temp" | ||
8 | "ibm,opal-sensor-power-supply" | ||
9 | "ibm,opal-sensor-power" | ||
10 | - sensor-id: an opaque id provided by the firmware to the kernel, identifies a | ||
11 | given sensor and its attribute data | ||
12 | |||
13 | Example sensors node: | ||
14 | |||
15 | cooling-fan#8-data { | ||
16 | sensor-id = <0x7052107>; | ||
17 | compatible = "ibm,opal-sensor-cooling-fan"; | ||
18 | }; | ||
19 | |||
20 | amb-temp#1-thrs { | ||
21 | sensor-id = <0x5096000>; | ||
22 | compatible = "ibm,opal-sensor-amb-temp"; | ||
23 | }; | ||
diff --git a/Documentation/devicetree/bindings/hwmon/ntc_thermistor.txt b/Documentation/devicetree/bindings/hwmon/ntc_thermistor.txt index b117b2e9e1a7..2391e5c41999 100644 --- a/Documentation/devicetree/bindings/hwmon/ntc_thermistor.txt +++ b/Documentation/devicetree/bindings/hwmon/ntc_thermistor.txt | |||
@@ -3,6 +3,7 @@ NTC Thermistor hwmon sensors | |||
3 | 3 | ||
4 | Requires node properties: | 4 | Requires node properties: |
5 | - "compatible" value : one of | 5 | - "compatible" value : one of |
6 | "epcos,b57330v2103" | ||
6 | "murata,ncp15wb473" | 7 | "murata,ncp15wb473" |
7 | "murata,ncp18wb473" | 8 | "murata,ncp18wb473" |
8 | "murata,ncp21wb473" | 9 | "murata,ncp21wb473" |
diff --git a/Documentation/devicetree/bindings/hwmon/pwm-fan.txt b/Documentation/devicetree/bindings/hwmon/pwm-fan.txt new file mode 100644 index 000000000000..610757ce4492 --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/pwm-fan.txt | |||
@@ -0,0 +1,12 @@ | |||
1 | Bindings for a fan connected to the PWM lines | ||
2 | |||
3 | Required properties: | ||
4 | - compatible : "pwm-fan" | ||
5 | - pwms : the PWM that is used to control the PWM fan | ||
6 | |||
7 | Example: | ||
8 | pwm-fan { | ||
9 | compatible = "pwm-fan"; | ||
10 | status = "okay"; | ||
11 | pwms = <&pwm 0 10000 0>; | ||
12 | }; | ||
diff --git a/Documentation/devicetree/bindings/i2c/trivial-devices.txt b/Documentation/devicetree/bindings/i2c/trivial-devices.txt index 1a794213f7d1..37803eb5521e 100644 --- a/Documentation/devicetree/bindings/i2c/trivial-devices.txt +++ b/Documentation/devicetree/bindings/i2c/trivial-devices.txt | |||
@@ -84,5 +84,6 @@ stm,m41t80 M41T80 - SERIAL ACCESS RTC WITH ALARMS | |||
84 | taos,tsl2550 Ambient Light Sensor with SMBUS/Two Wire Serial Interface | 84 | taos,tsl2550 Ambient Light Sensor with SMBUS/Two Wire Serial Interface |
85 | ti,tsc2003 I2C Touch-Screen Controller | 85 | ti,tsc2003 I2C Touch-Screen Controller |
86 | ti,tmp102 Low Power Digital Temperature Sensor with SMBUS/Two Wire Serial Interface | 86 | ti,tmp102 Low Power Digital Temperature Sensor with SMBUS/Two Wire Serial Interface |
87 | ti,tmp103 Low Power Digital Temperature Sensor with SMBUS/Two Wire Serial Interface | ||
87 | ti,tmp275 Digital Temperature Sensor | 88 | ti,tmp275 Digital Temperature Sensor |
88 | winbond,wpct301 i2c trusted platform module (TPM) | 89 | winbond,wpct301 i2c trusted platform module (TPM) |
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt index 46a311e728a8..97c9c06132c4 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.txt +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt | |||
@@ -42,6 +42,7 @@ dmo Data Modul AG | |||
42 | ebv EBV Elektronik | 42 | ebv EBV Elektronik |
43 | edt Emerging Display Technologies | 43 | edt Emerging Display Technologies |
44 | emmicro EM Microelectronic | 44 | emmicro EM Microelectronic |
45 | epcos EPCOS AG | ||
45 | epfl Ecole Polytechnique Fédérale de Lausanne | 46 | epfl Ecole Polytechnique Fédérale de Lausanne |
46 | epson Seiko Epson Corp. | 47 | epson Seiko Epson Corp. |
47 | est ESTeem Wireless Modems | 48 | est ESTeem Wireless Modems |
diff --git a/Documentation/hwmon/ibmpowernv b/Documentation/hwmon/ibmpowernv new file mode 100644 index 000000000000..8826ba29db36 --- /dev/null +++ b/Documentation/hwmon/ibmpowernv | |||
@@ -0,0 +1,41 @@ | |||
1 | Kernel Driver IBMPOWERNV | ||
2 | ======================== | ||
3 | |||
4 | Supported systems: | ||
5 | * Any recent IBM P servers based on POWERNV platform | ||
6 | |||
7 | Author: Neelesh Gupta | ||
8 | |||
9 | Description | ||
10 | ----------- | ||
11 | |||
12 | This driver implements reading the platform sensors data like temperature/fan/ | ||
13 | voltage/power for 'POWERNV' platform. | ||
14 | |||
15 | The driver uses the platform device infrastructure. It probes the device tree | ||
16 | for sensor devices during the __init phase and registers them with the 'hwmon'. | ||
17 | 'hwmon' populates the 'sysfs' tree having attribute files, each for a given | ||
18 | sensor type and its attribute data. | ||
19 | |||
20 | All the nodes in the DT appear under "/ibm,opal/sensors" and each valid node in | ||
21 | the DT maps to an attribute file in 'sysfs'. The node exports unique 'sensor-id' | ||
22 | which the driver uses to make an OPAL call to the firmware. | ||
23 | |||
24 | Usage notes | ||
25 | ----------- | ||
26 | The driver is built statically with the kernel by enabling the config | ||
27 | CONFIG_SENSORS_IBMPOWERNV. It can also be built as module 'ibmpowernv'. | ||
28 | |||
29 | Sysfs attributes | ||
30 | ---------------- | ||
31 | |||
32 | fanX_input Measured RPM value. | ||
33 | fanX_min Threshold RPM for alert generation. | ||
34 | fanX_fault 0: No fail condition | ||
35 | 1: Failing fan | ||
36 | tempX_input Measured ambient temperature. | ||
37 | tempX_max Threshold ambient temperature for alert generation. | ||
38 | inX_input Measured power supply voltage | ||
39 | inX_fault 0: No fail condition. | ||
40 | 1: Failing power supply. | ||
41 | power1_input System power consumption (microWatt) | ||
diff --git a/Documentation/hwmon/lm75 b/Documentation/hwmon/lm75 index 2560a9c6d445..c6a5ff1b4641 100644 --- a/Documentation/hwmon/lm75 +++ b/Documentation/hwmon/lm75 | |||
@@ -42,13 +42,14 @@ Supported chips: | |||
42 | Addresses scanned: none | 42 | Addresses scanned: none |
43 | Datasheet: Publicly available at the ST website | 43 | Datasheet: Publicly available at the ST website |
44 | http://www.st.com/internet/analog/product/121769.jsp | 44 | http://www.st.com/internet/analog/product/121769.jsp |
45 | * Texas Instruments TMP100, TMP101, TMP105, TMP75, TMP175, TMP275 | 45 | * Texas Instruments TMP100, TMP101, TMP105, TMP112, TMP75, TMP175, TMP275 |
46 | Prefixes: 'tmp100', 'tmp101', 'tmp105', 'tmp175', 'tmp75', 'tmp275' | 46 | Prefixes: 'tmp100', 'tmp101', 'tmp105', 'tmp112', 'tmp175', 'tmp75', 'tmp275' |
47 | Addresses scanned: none | 47 | Addresses scanned: none |
48 | Datasheet: Publicly available at the Texas Instruments website | 48 | Datasheet: Publicly available at the Texas Instruments website |
49 | http://www.ti.com/product/tmp100 | 49 | http://www.ti.com/product/tmp100 |
50 | http://www.ti.com/product/tmp101 | 50 | http://www.ti.com/product/tmp101 |
51 | http://www.ti.com/product/tmp105 | 51 | http://www.ti.com/product/tmp105 |
52 | http://www.ti.com/product/tmp112 | ||
52 | http://www.ti.com/product/tmp75 | 53 | http://www.ti.com/product/tmp75 |
53 | http://www.ti.com/product/tmp175 | 54 | http://www.ti.com/product/tmp175 |
54 | http://www.ti.com/product/tmp275 | 55 | http://www.ti.com/product/tmp275 |
diff --git a/Documentation/hwmon/ntc_thermistor b/Documentation/hwmon/ntc_thermistor index 057b77029f26..c5e05e2900a3 100644 --- a/Documentation/hwmon/ntc_thermistor +++ b/Documentation/hwmon/ntc_thermistor | |||
@@ -6,6 +6,11 @@ Supported thermistors from Murata: | |||
6 | Prefixes: 'ncp15wb473', 'ncp18wb473', 'ncp21wb473', 'ncp03wb473', 'ncp15wl333' | 6 | Prefixes: 'ncp15wb473', 'ncp18wb473', 'ncp21wb473', 'ncp03wb473', 'ncp15wl333' |
7 | Datasheet: Publicly available at Murata | 7 | Datasheet: Publicly available at Murata |
8 | 8 | ||
9 | Supported thermistors from EPCOS: | ||
10 | * EPCOS NTC Thermistors B57330V2103 | ||
11 | Prefixes: b57330v2103 | ||
12 | Datasheet: Publicly available at EPCOS | ||
13 | |||
9 | Other NTC thermistors can be supported simply by adding compensation | 14 | Other NTC thermistors can be supported simply by adding compensation |
10 | tables; e.g., NCP15WL333 support is added by the table ncpXXwl333. | 15 | tables; e.g., NCP15WL333 support is added by the table ncpXXwl333. |
11 | 16 | ||
diff --git a/Documentation/hwmon/pmbus b/Documentation/hwmon/pmbus index cf756ed48ff9..a3557da8f5b4 100644 --- a/Documentation/hwmon/pmbus +++ b/Documentation/hwmon/pmbus | |||
@@ -23,12 +23,11 @@ Supported chips: | |||
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 | 25 | http://www.lineagepower.com/oem/pdf/MDT040A0X.pdf |
26 | * Texas Instruments TPS40400, TPS40422 | 26 | * Texas Instruments TPS40400 |
27 | Prefixes: 'tps40400', 'tps40422' | 27 | Prefixes: 'tps40400' |
28 | Addresses scanned: - | 28 | Addresses scanned: - |
29 | Datasheets: | 29 | Datasheets: |
30 | http://www.ti.com/lit/gpn/tps40400 | 30 | http://www.ti.com/lit/gpn/tps40400 |
31 | http://www.ti.com/lit/gpn/tps40422 | ||
32 | * Generic PMBus devices | 31 | * Generic PMBus devices |
33 | Prefix: 'pmbus' | 32 | Prefix: 'pmbus' |
34 | Addresses scanned: - | 33 | Addresses scanned: - |
diff --git a/Documentation/hwmon/powr1220 b/Documentation/hwmon/powr1220 new file mode 100644 index 000000000000..21e44f71ae6e --- /dev/null +++ b/Documentation/hwmon/powr1220 | |||
@@ -0,0 +1,45 @@ | |||
1 | Kernel driver powr1220 | ||
2 | ================== | ||
3 | |||
4 | Supported chips: | ||
5 | * Lattice POWR1220AT8 | ||
6 | Prefix: 'powr1220' | ||
7 | Addresses scanned: none | ||
8 | Datasheet: Publicly available at the Lattice website | ||
9 | http://www.latticesemi.com/ | ||
10 | |||
11 | Author: Scott Kanowitz <scott.kanowitz@gmail.com> | ||
12 | |||
13 | Description | ||
14 | ----------- | ||
15 | |||
16 | This driver supports the Lattice POWR1220AT8 chip. The POWR1220 | ||
17 | includes voltage monitoring for 14 inputs as well as trim settings | ||
18 | for output voltages and GPIOs. This driver implements the voltage | ||
19 | monitoring portion of the chip. | ||
20 | |||
21 | Voltages are sampled by a 12-bit ADC with a step size of 2 mV. | ||
22 | An in-line attenuator allows measurements from 0 to 6 V. The | ||
23 | attenuator is enabled or disabled depending on the setting of the | ||
24 | input's max value. The driver will enable the attenuator for any | ||
25 | value over the low measurement range maximum of 2 V. | ||
26 | |||
27 | The input naming convention is as follows: | ||
28 | |||
29 | driver name pin name | ||
30 | in0 VMON1 | ||
31 | in1 VMON2 | ||
32 | in2 VMON3 | ||
33 | in2 VMON4 | ||
34 | in4 VMON5 | ||
35 | in5 VMON6 | ||
36 | in6 VMON7 | ||
37 | in7 VMON8 | ||
38 | in8 VMON9 | ||
39 | in9 VMON10 | ||
40 | in10 VMON11 | ||
41 | in11 VMON12 | ||
42 | in12 VCCA | ||
43 | in13 VCCINP | ||
44 | |||
45 | The ADC readings are updated on request with a minimum period of 1s. | ||
diff --git a/Documentation/hwmon/pwm-fan b/Documentation/hwmon/pwm-fan new file mode 100644 index 000000000000..18529d2e3bcf --- /dev/null +++ b/Documentation/hwmon/pwm-fan | |||
@@ -0,0 +1,17 @@ | |||
1 | Kernel driver pwm-fan | ||
2 | ===================== | ||
3 | |||
4 | This driver enables the use of a PWM module to drive a fan. It uses the | ||
5 | generic PWM interface thus it is hardware independent. It can be used on | ||
6 | many SoCs, as long as the SoC supplies a PWM line driver that exposes | ||
7 | the generic PWM API. | ||
8 | |||
9 | Author: Kamil Debski <k.debski@samsung.com> | ||
10 | |||
11 | Description | ||
12 | ----------- | ||
13 | |||
14 | The driver implements a simple interface for driving a fan connected to | ||
15 | a PWM output. It uses the generic PWM interface, thus it can be used with | ||
16 | a range of SoCs. The driver exposes the fan to the user space through | ||
17 | the hwmon's sysfs interface. | ||
diff --git a/Documentation/hwmon/tmp103 b/Documentation/hwmon/tmp103 new file mode 100644 index 000000000000..ec00a15645ba --- /dev/null +++ b/Documentation/hwmon/tmp103 | |||
@@ -0,0 +1,28 @@ | |||
1 | Kernel driver tmp103 | ||
2 | ==================== | ||
3 | |||
4 | Supported chips: | ||
5 | * Texas Instruments TMP103 | ||
6 | Prefix: 'tmp103' | ||
7 | Addresses scanned: none | ||
8 | Product info and datasheet: http://www.ti.com/product/tmp103 | ||
9 | |||
10 | Author: | ||
11 | Heiko Schocher <hs@denx.de> | ||
12 | |||
13 | Description | ||
14 | ----------- | ||
15 | |||
16 | The TMP103 is a digital output temperature sensor in a four-ball | ||
17 | wafer chip-scale package (WCSP). The TMP103 is capable of reading | ||
18 | temperatures to a resolution of 1°C. The TMP103 is specified for | ||
19 | operation over a temperature range of –40°C to +125°C. | ||
20 | |||
21 | Resolution: 8 Bits | ||
22 | Accuracy: ±1°C Typ (–10°C to +100°C) | ||
23 | |||
24 | The driver provides the common sysfs-interface for temperatures (see | ||
25 | Documentation/hwmon/sysfs-interface under Temperatures). | ||
26 | |||
27 | Please refer how to instantiate this driver: | ||
28 | Documentation/i2c/instantiating-devices | ||
diff --git a/Documentation/hwmon/tmp421 b/Documentation/hwmon/tmp421 index 0cf07f824741..9e6fe5549ca1 100644 --- a/Documentation/hwmon/tmp421 +++ b/Documentation/hwmon/tmp421 | |||
@@ -8,12 +8,20 @@ Supported chips: | |||
8 | Datasheet: http://focus.ti.com/docs/prod/folders/print/tmp421.html | 8 | Datasheet: http://focus.ti.com/docs/prod/folders/print/tmp421.html |
9 | * Texas Instruments TMP422 | 9 | * Texas Instruments TMP422 |
10 | Prefix: 'tmp422' | 10 | Prefix: 'tmp422' |
11 | Addresses scanned: I2C 0x2a, 0x4c, 0x4d, 0x4e and 0x4f | 11 | Addresses scanned: I2C 0x4c, 0x4d, 0x4e and 0x4f |
12 | Datasheet: http://focus.ti.com/docs/prod/folders/print/tmp421.html | 12 | Datasheet: http://focus.ti.com/docs/prod/folders/print/tmp421.html |
13 | * Texas Instruments TMP423 | 13 | * Texas Instruments TMP423 |
14 | Prefix: 'tmp423' | 14 | Prefix: 'tmp423' |
15 | Addresses scanned: I2C 0x2a, 0x4c, 0x4d, 0x4e and 0x4f | 15 | Addresses scanned: I2C 0x4c and 0x4d |
16 | Datasheet: http://focus.ti.com/docs/prod/folders/print/tmp421.html | 16 | Datasheet: http://focus.ti.com/docs/prod/folders/print/tmp421.html |
17 | * Texas Instruments TMP441 | ||
18 | Prefix: 'tmp441' | ||
19 | Addresses scanned: I2C 0x2a, 0x4c, 0x4d, 0x4e and 0x4f | ||
20 | Datasheet: http://www.ti.com/product/tmp441 | ||
21 | * Texas Instruments TMP442 | ||
22 | Prefix: 'tmp442' | ||
23 | Addresses scanned: I2C 0x4c and 0x4d | ||
24 | Datasheet: http://www.ti.com/product/tmp442 | ||
17 | 25 | ||
18 | Authors: | 26 | Authors: |
19 | Andre Prendel <andre.prendel@gmx.de> | 27 | Andre Prendel <andre.prendel@gmx.de> |
@@ -21,13 +29,13 @@ Authors: | |||
21 | Description | 29 | Description |
22 | ----------- | 30 | ----------- |
23 | 31 | ||
24 | This driver implements support for Texas Instruments TMP421, TMP422 | 32 | This driver implements support for Texas Instruments TMP421, TMP422, |
25 | and TMP423 temperature sensor chips. These chips implement one local | 33 | TMP423, TMP441, and TMP442 temperature sensor chips. These chips |
26 | and up to one (TMP421), up to two (TMP422) or up to three (TMP423) | 34 | implement one local and up to one (TMP421, TMP441), up to two (TMP422, |
27 | remote sensors. Temperature is measured in degrees Celsius. The chips | 35 | TMP442) or up to three (TMP423) remote sensors. Temperature is measured |
28 | are wired over I2C/SMBus and specified over a temperature range of -40 | 36 | in degrees Celsius. The chips are wired over I2C/SMBus and specified |
29 | to +125 degrees Celsius. Resolution for both the local and remote | 37 | over a temperature range of -40 to +125 degrees Celsius. Resolution |
30 | channels is 0.0625 degree C. | 38 | for both the local and remote channels is 0.0625 degree C. |
31 | 39 | ||
32 | The chips support only temperature measurement. The driver exports | 40 | The chips support only temperature measurement. The driver exports |
33 | the temperature values via the following sysfs files: | 41 | the temperature values via the following sysfs files: |
diff --git a/Documentation/hwmon/tps40422 b/Documentation/hwmon/tps40422 new file mode 100644 index 000000000000..24bb0688d515 --- /dev/null +++ b/Documentation/hwmon/tps40422 | |||
@@ -0,0 +1,64 @@ | |||
1 | Kernel driver tps40422 | ||
2 | ====================== | ||
3 | |||
4 | Supported chips: | ||
5 | * TI TPS40422 | ||
6 | Prefix: 'tps40422' | ||
7 | Addresses scanned: - | ||
8 | Datasheet: http://www.ti.com/lit/gpn/tps40422 | ||
9 | |||
10 | Author: Zhu Laiwen <richard.zhu@nsn.com> | ||
11 | |||
12 | |||
13 | Description | ||
14 | ----------- | ||
15 | |||
16 | This driver supports TI TPS40422 Dual-Output or Two-Phase Synchronous Buck | ||
17 | Controller with PMBus | ||
18 | |||
19 | The driver is a client driver to the core PMBus driver. | ||
20 | Please see Documentation/hwmon/pmbus for details on PMBus client drivers. | ||
21 | |||
22 | |||
23 | Usage Notes | ||
24 | ----------- | ||
25 | |||
26 | This driver does not auto-detect devices. You will have to instantiate the | ||
27 | devices explicitly. Please see Documentation/i2c/instantiating-devices for | ||
28 | details. | ||
29 | |||
30 | |||
31 | Platform data support | ||
32 | --------------------- | ||
33 | |||
34 | The driver supports standard PMBus driver platform data. | ||
35 | |||
36 | |||
37 | Sysfs entries | ||
38 | ------------- | ||
39 | |||
40 | The following attributes are supported. | ||
41 | |||
42 | in[1-2]_label "vout[1-2]" | ||
43 | in[1-2]_input Measured voltage. From READ_VOUT register. | ||
44 | in[1-2]_alarm voltage alarm. | ||
45 | |||
46 | curr[1-2]_input Measured current. From READ_IOUT register. | ||
47 | curr[1-2]_label "iout[1-2]" | ||
48 | curr1_max Maximum current. From IOUT_OC_WARN_LIMIT register. | ||
49 | curr1_crit Critical maximum current. From IOUT_OC_FAULT_LIMIT register. | ||
50 | curr1_max_alarm Current high alarm. From IOUT_OC_WARN_LIMIT status. | ||
51 | curr1_crit_alarm Current critical high alarm. From IOUT_OC_FAULT status. | ||
52 | curr2_alarm Current high alarm. From IOUT_OC_WARNING status. | ||
53 | |||
54 | temp1_input Measured temperature. From READ_TEMPERATURE_2 register on page 0. | ||
55 | temp1_max Maximum temperature. From OT_WARN_LIMIT register. | ||
56 | temp1_crit Critical high temperature. From OT_FAULT_LIMIT register. | ||
57 | temp1_max_alarm Chip temperature high alarm. Set by comparing | ||
58 | READ_TEMPERATURE_2 on page 0 with OT_WARN_LIMIT if TEMP_OT_WARNING | ||
59 | status is set. | ||
60 | temp1_crit_alarm Chip temperature critical high alarm. Set by comparing | ||
61 | READ_TEMPERATURE_2 on page 0 with OT_FAULT_LIMIT if TEMP_OT_FAULT | ||
62 | status is set. | ||
63 | temp2_input Measured temperature. From READ_TEMPERATURE_2 register on page 1. | ||
64 | temp2_alarm Chip temperature alarm on page 1. | ||
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 02d3d85829f3..f00d048aa583 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig | |||
@@ -554,6 +554,17 @@ config SENSORS_IBMPEX | |||
554 | This driver can also be built as a module. If so, the module | 554 | This driver can also be built as a module. If so, the module |
555 | will be called ibmpex. | 555 | will be called ibmpex. |
556 | 556 | ||
557 | config SENSORS_IBMPOWERNV | ||
558 | tristate "IBM POWERNV platform sensors" | ||
559 | depends on PPC_POWERNV | ||
560 | default y | ||
561 | help | ||
562 | If you say yes here you get support for the temperature/fan/power | ||
563 | sensors on your PowerNV platform. | ||
564 | |||
565 | This driver can also be built as a module. If so, the module | ||
566 | will be called ibmpowernv. | ||
567 | |||
557 | config SENSORS_IIO_HWMON | 568 | config SENSORS_IIO_HWMON |
558 | tristate "Hwmon driver that uses channels specified via iio maps" | 569 | tristate "Hwmon driver that uses channels specified via iio maps" |
559 | depends on IIO | 570 | depends on IIO |
@@ -608,6 +619,18 @@ config SENSORS_JC42 | |||
608 | This driver can also be built as a module. If so, the module | 619 | This driver can also be built as a module. If so, the module |
609 | will be called jc42. | 620 | will be called jc42. |
610 | 621 | ||
622 | config SENSORS_POWR1220 | ||
623 | tristate "Lattice POWR1220 Power Monitoring" | ||
624 | depends on I2C | ||
625 | default n | ||
626 | help | ||
627 | If you say yes here you get access to the hardware monitoring | ||
628 | functions of the Lattice POWR1220 isp Power Supply Monitoring, | ||
629 | Sequencing and Margining Controller. | ||
630 | |||
631 | This driver can also be built as a module. If so, the module | ||
632 | will be called powr1220. | ||
633 | |||
611 | config SENSORS_LINEAGE | 634 | config SENSORS_LINEAGE |
612 | tristate "Lineage Compact Power Line Power Entry Module" | 635 | tristate "Lineage Compact Power Line Power Entry Module" |
613 | depends on I2C | 636 | depends on I2C |
@@ -882,8 +905,8 @@ config SENSORS_LM75 | |||
882 | - NXP's LM75A | 905 | - NXP's LM75A |
883 | - ST Microelectronics STDS75 | 906 | - ST Microelectronics STDS75 |
884 | - TelCom (now Microchip) TCN75 | 907 | - TelCom (now Microchip) TCN75 |
885 | - Texas Instruments TMP100, TMP101, TMP105, TMP75, TMP175, | 908 | - Texas Instruments TMP100, TMP101, TMP105, TMP112, TMP75, |
886 | TMP275 | 909 | TMP175, TMP275 |
887 | 910 | ||
888 | This driver supports driver model based binding through board | 911 | This driver supports driver model based binding through board |
889 | specific I2C device tables. | 912 | specific I2C device tables. |
@@ -1061,7 +1084,7 @@ config SENSORS_NTC_THERMISTOR | |||
1061 | 1084 | ||
1062 | Currently, this driver supports | 1085 | Currently, this driver supports |
1063 | NCP15WB473, NCP18WB473, NCP21WB473, NCP03WB473, and NCP15WL333 | 1086 | NCP15WB473, NCP18WB473, NCP21WB473, NCP03WB473, and NCP15WL333 |
1064 | from Murata. | 1087 | from Murata and B57330V2103 from EPCOS. |
1065 | 1088 | ||
1066 | This driver can also be built as a module. If so, the module | 1089 | This driver can also be built as a module. If so, the module |
1067 | will be called ntc-thermistor. | 1090 | will be called ntc-thermistor. |
@@ -1082,8 +1105,8 @@ config SENSORS_NCT6775 | |||
1082 | select HWMON_VID | 1105 | select HWMON_VID |
1083 | help | 1106 | help |
1084 | If you say yes here you get support for the hardware monitoring | 1107 | If you say yes here you get support for the hardware monitoring |
1085 | functionality of the Nuvoton NCT6775F, NCT6776F, NCT6779D | 1108 | functionality of the Nuvoton NCT6106D, NCT6775F, NCT6776F, NCT6779D, |
1086 | and compatible Super-I/O chips. This driver replaces the | 1109 | NCT6791D and compatible Super-I/O chips. This driver replaces the |
1087 | w83627ehf driver for NCT6775F and NCT6776F. | 1110 | w83627ehf driver for NCT6775F and NCT6776F. |
1088 | 1111 | ||
1089 | This driver can also be built as a module. If so, the module | 1112 | This driver can also be built as a module. If so, the module |
@@ -1105,6 +1128,17 @@ config SENSORS_PCF8591 | |||
1105 | 1128 | ||
1106 | source drivers/hwmon/pmbus/Kconfig | 1129 | source drivers/hwmon/pmbus/Kconfig |
1107 | 1130 | ||
1131 | config SENSORS_PWM_FAN | ||
1132 | tristate "PWM fan" | ||
1133 | depends on (PWM && OF) || COMPILE_TEST | ||
1134 | help | ||
1135 | If you say yes here you get support for fans connected to PWM lines. | ||
1136 | The driver uses the generic PWM interface, thus it will work on a | ||
1137 | variety of SoCs. | ||
1138 | |||
1139 | This driver can also be built as a module. If so, the module | ||
1140 | will be called pwm-fan. | ||
1141 | |||
1108 | config SENSORS_SHT15 | 1142 | config SENSORS_SHT15 |
1109 | tristate "Sensiron humidity and temperature sensors. SHT15 and compat." | 1143 | tristate "Sensiron humidity and temperature sensors. SHT15 and compat." |
1110 | depends on GPIOLIB | 1144 | depends on GPIOLIB |
@@ -1393,6 +1427,17 @@ config SENSORS_TMP102 | |||
1393 | This driver can also be built as a module. If so, the module | 1427 | This driver can also be built as a module. If so, the module |
1394 | will be called tmp102. | 1428 | will be called tmp102. |
1395 | 1429 | ||
1430 | config SENSORS_TMP103 | ||
1431 | tristate "Texas Instruments TMP103" | ||
1432 | depends on I2C | ||
1433 | select REGMAP_I2C | ||
1434 | help | ||
1435 | If you say yes here you get support for Texas Instruments TMP103 | ||
1436 | sensor chips. | ||
1437 | |||
1438 | This driver can also be built as a module. If so, the module | ||
1439 | will be called tmp103. | ||
1440 | |||
1396 | config SENSORS_TMP401 | 1441 | config SENSORS_TMP401 |
1397 | tristate "Texas Instruments TMP401 and compatibles" | 1442 | tristate "Texas Instruments TMP401 and compatibles" |
1398 | depends on I2C | 1443 | depends on I2C |
@@ -1408,7 +1453,7 @@ config SENSORS_TMP421 | |||
1408 | depends on I2C | 1453 | depends on I2C |
1409 | help | 1454 | help |
1410 | If you say yes here you get support for Texas Instruments TMP421, | 1455 | If you say yes here you get support for Texas Instruments TMP421, |
1411 | TMP422 and TMP423 temperature sensor chips. | 1456 | TMP422, TMP423, TMP441, and TMP442 temperature sensor chips. |
1412 | 1457 | ||
1413 | This driver can also be built as a module. If so, the module | 1458 | This driver can also be built as a module. If so, the module |
1414 | will be called tmp421. | 1459 | will be called tmp421. |
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index 3dc0f02f71d2..be28152c9848 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile | |||
@@ -71,6 +71,7 @@ obj-$(CONFIG_SENSORS_ULTRA45) += ultra45_env.o | |||
71 | obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.o | 71 | obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.o |
72 | obj-$(CONFIG_SENSORS_IBMAEM) += ibmaem.o | 72 | obj-$(CONFIG_SENSORS_IBMAEM) += ibmaem.o |
73 | obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o | 73 | obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o |
74 | obj-$(CONFIG_SENSORS_IBMPOWERNV)+= ibmpowernv.o | ||
74 | obj-$(CONFIG_SENSORS_IIO_HWMON) += iio_hwmon.o | 75 | obj-$(CONFIG_SENSORS_IIO_HWMON) += iio_hwmon.o |
75 | obj-$(CONFIG_SENSORS_INA209) += ina209.o | 76 | obj-$(CONFIG_SENSORS_INA209) += ina209.o |
76 | obj-$(CONFIG_SENSORS_INA2XX) += ina2xx.o | 77 | obj-$(CONFIG_SENSORS_INA2XX) += ina2xx.o |
@@ -120,6 +121,8 @@ obj-$(CONFIG_SENSORS_NTC_THERMISTOR) += ntc_thermistor.o | |||
120 | obj-$(CONFIG_SENSORS_PC87360) += pc87360.o | 121 | obj-$(CONFIG_SENSORS_PC87360) += pc87360.o |
121 | obj-$(CONFIG_SENSORS_PC87427) += pc87427.o | 122 | obj-$(CONFIG_SENSORS_PC87427) += pc87427.o |
122 | obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o | 123 | obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o |
124 | obj-$(CONFIG_SENSORS_POWR1220) += powr1220.o | ||
125 | obj-$(CONFIG_SENSORS_PWM_FAN) += pwm-fan.o | ||
123 | obj-$(CONFIG_SENSORS_S3C) += s3c-hwmon.o | 126 | obj-$(CONFIG_SENSORS_S3C) += s3c-hwmon.o |
124 | obj-$(CONFIG_SENSORS_SCH56XX_COMMON)+= sch56xx-common.o | 127 | obj-$(CONFIG_SENSORS_SCH56XX_COMMON)+= sch56xx-common.o |
125 | obj-$(CONFIG_SENSORS_SCH5627) += sch5627.o | 128 | obj-$(CONFIG_SENSORS_SCH5627) += sch5627.o |
@@ -135,6 +138,7 @@ obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o | |||
135 | obj-$(CONFIG_SENSORS_AMC6821) += amc6821.o | 138 | obj-$(CONFIG_SENSORS_AMC6821) += amc6821.o |
136 | obj-$(CONFIG_SENSORS_THMC50) += thmc50.o | 139 | obj-$(CONFIG_SENSORS_THMC50) += thmc50.o |
137 | obj-$(CONFIG_SENSORS_TMP102) += tmp102.o | 140 | obj-$(CONFIG_SENSORS_TMP102) += tmp102.o |
141 | obj-$(CONFIG_SENSORS_TMP103) += tmp103.o | ||
138 | obj-$(CONFIG_SENSORS_TMP401) += tmp401.o | 142 | obj-$(CONFIG_SENSORS_TMP401) += tmp401.o |
139 | obj-$(CONFIG_SENSORS_TMP421) += tmp421.o | 143 | obj-$(CONFIG_SENSORS_TMP421) += tmp421.o |
140 | obj-$(CONFIG_SENSORS_TWL4030_MADC)+= twl4030-madc-hwmon.o | 144 | obj-$(CONFIG_SENSORS_TWL4030_MADC)+= twl4030-madc-hwmon.o |
diff --git a/drivers/hwmon/ad7414.c b/drivers/hwmon/ad7414.c index 5d501adc3e54..763490acc0df 100644 --- a/drivers/hwmon/ad7414.c +++ b/drivers/hwmon/ad7414.c | |||
@@ -39,7 +39,7 @@ | |||
39 | static u8 AD7414_REG_LIMIT[] = { AD7414_REG_T_HIGH, AD7414_REG_T_LOW }; | 39 | static u8 AD7414_REG_LIMIT[] = { AD7414_REG_T_HIGH, AD7414_REG_T_LOW }; |
40 | 40 | ||
41 | struct ad7414_data { | 41 | struct ad7414_data { |
42 | struct device *hwmon_dev; | 42 | struct i2c_client *client; |
43 | struct mutex lock; /* atomic read data updates */ | 43 | struct mutex lock; /* atomic read data updates */ |
44 | char valid; /* !=0 if following fields are valid */ | 44 | char valid; /* !=0 if following fields are valid */ |
45 | unsigned long next_update; /* In jiffies */ | 45 | unsigned long next_update; /* In jiffies */ |
@@ -72,8 +72,8 @@ static inline int ad7414_write(struct i2c_client *client, u8 reg, u8 value) | |||
72 | 72 | ||
73 | static struct ad7414_data *ad7414_update_device(struct device *dev) | 73 | static struct ad7414_data *ad7414_update_device(struct device *dev) |
74 | { | 74 | { |
75 | struct i2c_client *client = to_i2c_client(dev); | 75 | struct ad7414_data *data = dev_get_drvdata(dev); |
76 | struct ad7414_data *data = i2c_get_clientdata(client); | 76 | struct i2c_client *client = data->client; |
77 | 77 | ||
78 | mutex_lock(&data->lock); | 78 | mutex_lock(&data->lock); |
79 | 79 | ||
@@ -127,8 +127,8 @@ static ssize_t set_max_min(struct device *dev, | |||
127 | struct device_attribute *attr, | 127 | struct device_attribute *attr, |
128 | const char *buf, size_t count) | 128 | const char *buf, size_t count) |
129 | { | 129 | { |
130 | struct i2c_client *client = to_i2c_client(dev); | 130 | struct ad7414_data *data = dev_get_drvdata(dev); |
131 | struct ad7414_data *data = i2c_get_clientdata(client); | 131 | struct i2c_client *client = data->client; |
132 | int index = to_sensor_dev_attr(attr)->index; | 132 | int index = to_sensor_dev_attr(attr)->index; |
133 | u8 reg = AD7414_REG_LIMIT[index]; | 133 | u8 reg = AD7414_REG_LIMIT[index]; |
134 | long temp; | 134 | long temp; |
@@ -164,7 +164,7 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, | |||
164 | static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 3); | 164 | static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 3); |
165 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 4); | 165 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 4); |
166 | 166 | ||
167 | static struct attribute *ad7414_attributes[] = { | 167 | static struct attribute *ad7414_attrs[] = { |
168 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 168 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
169 | &sensor_dev_attr_temp1_max.dev_attr.attr, | 169 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
170 | &sensor_dev_attr_temp1_min.dev_attr.attr, | 170 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
@@ -173,27 +173,25 @@ static struct attribute *ad7414_attributes[] = { | |||
173 | NULL | 173 | NULL |
174 | }; | 174 | }; |
175 | 175 | ||
176 | static const struct attribute_group ad7414_group = { | 176 | ATTRIBUTE_GROUPS(ad7414); |
177 | .attrs = ad7414_attributes, | ||
178 | }; | ||
179 | 177 | ||
180 | static int ad7414_probe(struct i2c_client *client, | 178 | static int ad7414_probe(struct i2c_client *client, |
181 | const struct i2c_device_id *dev_id) | 179 | const struct i2c_device_id *dev_id) |
182 | { | 180 | { |
181 | struct device *dev = &client->dev; | ||
183 | struct ad7414_data *data; | 182 | struct ad7414_data *data; |
183 | struct device *hwmon_dev; | ||
184 | int conf; | 184 | int conf; |
185 | int err; | ||
186 | 185 | ||
187 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA | | 186 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA | |
188 | I2C_FUNC_SMBUS_READ_WORD_DATA)) | 187 | I2C_FUNC_SMBUS_READ_WORD_DATA)) |
189 | return -EOPNOTSUPP; | 188 | return -EOPNOTSUPP; |
190 | 189 | ||
191 | data = devm_kzalloc(&client->dev, sizeof(struct ad7414_data), | 190 | data = devm_kzalloc(dev, sizeof(struct ad7414_data), GFP_KERNEL); |
192 | GFP_KERNEL); | ||
193 | if (!data) | 191 | if (!data) |
194 | return -ENOMEM; | 192 | return -ENOMEM; |
195 | 193 | ||
196 | i2c_set_clientdata(client, data); | 194 | data->client = client; |
197 | mutex_init(&data->lock); | 195 | mutex_init(&data->lock); |
198 | 196 | ||
199 | dev_info(&client->dev, "chip found\n"); | 197 | dev_info(&client->dev, "chip found\n"); |
@@ -201,38 +199,16 @@ static int ad7414_probe(struct i2c_client *client, | |||
201 | /* Make sure the chip is powered up. */ | 199 | /* Make sure the chip is powered up. */ |
202 | conf = i2c_smbus_read_byte_data(client, AD7414_REG_CONF); | 200 | conf = i2c_smbus_read_byte_data(client, AD7414_REG_CONF); |
203 | if (conf < 0) | 201 | if (conf < 0) |
204 | dev_warn(&client->dev, | 202 | dev_warn(dev, "ad7414_probe unable to read config register.\n"); |
205 | "ad7414_probe unable to read config register.\n"); | ||
206 | else { | 203 | else { |
207 | conf &= ~(1 << 7); | 204 | conf &= ~(1 << 7); |
208 | i2c_smbus_write_byte_data(client, AD7414_REG_CONF, conf); | 205 | i2c_smbus_write_byte_data(client, AD7414_REG_CONF, conf); |
209 | } | 206 | } |
210 | 207 | ||
211 | /* Register sysfs hooks */ | 208 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, |
212 | err = sysfs_create_group(&client->dev.kobj, &ad7414_group); | 209 | client->name, |
213 | if (err) | 210 | data, ad7414_groups); |
214 | return err; | 211 | return PTR_ERR_OR_ZERO(hwmon_dev); |
215 | |||
216 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
217 | if (IS_ERR(data->hwmon_dev)) { | ||
218 | err = PTR_ERR(data->hwmon_dev); | ||
219 | goto exit_remove; | ||
220 | } | ||
221 | |||
222 | return 0; | ||
223 | |||
224 | exit_remove: | ||
225 | sysfs_remove_group(&client->dev.kobj, &ad7414_group); | ||
226 | return err; | ||
227 | } | ||
228 | |||
229 | static int ad7414_remove(struct i2c_client *client) | ||
230 | { | ||
231 | struct ad7414_data *data = i2c_get_clientdata(client); | ||
232 | |||
233 | hwmon_device_unregister(data->hwmon_dev); | ||
234 | sysfs_remove_group(&client->dev.kobj, &ad7414_group); | ||
235 | return 0; | ||
236 | } | 212 | } |
237 | 213 | ||
238 | static const struct i2c_device_id ad7414_id[] = { | 214 | static const struct i2c_device_id ad7414_id[] = { |
@@ -246,7 +222,6 @@ static struct i2c_driver ad7414_driver = { | |||
246 | .name = "ad7414", | 222 | .name = "ad7414", |
247 | }, | 223 | }, |
248 | .probe = ad7414_probe, | 224 | .probe = ad7414_probe, |
249 | .remove = ad7414_remove, | ||
250 | .id_table = ad7414_id, | 225 | .id_table = ad7414_id, |
251 | }; | 226 | }; |
252 | 227 | ||
diff --git a/drivers/hwmon/ad7418.c b/drivers/hwmon/ad7418.c index 57d4a6295675..a01b731ba5d7 100644 --- a/drivers/hwmon/ad7418.c +++ b/drivers/hwmon/ad7418.c | |||
@@ -44,8 +44,7 @@ static const u8 AD7418_REG_TEMP[] = { AD7418_REG_TEMP_IN, | |||
44 | AD7418_REG_TEMP_OS }; | 44 | AD7418_REG_TEMP_OS }; |
45 | 45 | ||
46 | struct ad7418_data { | 46 | struct ad7418_data { |
47 | struct device *hwmon_dev; | 47 | struct i2c_client *client; |
48 | struct attribute_group attrs; | ||
49 | enum chips type; | 48 | enum chips type; |
50 | struct mutex lock; | 49 | struct mutex lock; |
51 | int adc_max; /* number of ADC channels */ | 50 | int adc_max; /* number of ADC channels */ |
@@ -55,48 +54,10 @@ struct ad7418_data { | |||
55 | u16 in[4]; | 54 | u16 in[4]; |
56 | }; | 55 | }; |
57 | 56 | ||
58 | static int ad7418_probe(struct i2c_client *client, | ||
59 | const struct i2c_device_id *id); | ||
60 | static int ad7418_remove(struct i2c_client *client); | ||
61 | |||
62 | static const struct i2c_device_id ad7418_id[] = { | ||
63 | { "ad7416", ad7416 }, | ||
64 | { "ad7417", ad7417 }, | ||
65 | { "ad7418", ad7418 }, | ||
66 | { } | ||
67 | }; | ||
68 | MODULE_DEVICE_TABLE(i2c, ad7418_id); | ||
69 | |||
70 | static struct i2c_driver ad7418_driver = { | ||
71 | .driver = { | ||
72 | .name = "ad7418", | ||
73 | }, | ||
74 | .probe = ad7418_probe, | ||
75 | .remove = ad7418_remove, | ||
76 | .id_table = ad7418_id, | ||
77 | }; | ||
78 | |||
79 | static void ad7418_init_client(struct i2c_client *client) | ||
80 | { | ||
81 | struct ad7418_data *data = i2c_get_clientdata(client); | ||
82 | |||
83 | int reg = i2c_smbus_read_byte_data(client, AD7418_REG_CONF); | ||
84 | if (reg < 0) { | ||
85 | dev_err(&client->dev, "cannot read configuration register\n"); | ||
86 | } else { | ||
87 | dev_info(&client->dev, "configuring for mode 1\n"); | ||
88 | i2c_smbus_write_byte_data(client, AD7418_REG_CONF, reg & 0xfe); | ||
89 | |||
90 | if (data->type == ad7417 || data->type == ad7418) | ||
91 | i2c_smbus_write_byte_data(client, | ||
92 | AD7418_REG_CONF2, 0x00); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | static struct ad7418_data *ad7418_update_device(struct device *dev) | 57 | static struct ad7418_data *ad7418_update_device(struct device *dev) |
97 | { | 58 | { |
98 | struct i2c_client *client = to_i2c_client(dev); | 59 | struct ad7418_data *data = dev_get_drvdata(dev); |
99 | struct ad7418_data *data = i2c_get_clientdata(client); | 60 | struct i2c_client *client = data->client; |
100 | 61 | ||
101 | mutex_lock(&data->lock); | 62 | mutex_lock(&data->lock); |
102 | 63 | ||
@@ -165,8 +126,8 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *devattr, | |||
165 | const char *buf, size_t count) | 126 | const char *buf, size_t count) |
166 | { | 127 | { |
167 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 128 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
168 | struct i2c_client *client = to_i2c_client(dev); | 129 | struct ad7418_data *data = dev_get_drvdata(dev); |
169 | struct ad7418_data *data = i2c_get_clientdata(client); | 130 | struct i2c_client *client = data->client; |
170 | long temp; | 131 | long temp; |
171 | int ret = kstrtol(buf, 10, &temp); | 132 | int ret = kstrtol(buf, 10, &temp); |
172 | 133 | ||
@@ -193,14 +154,15 @@ static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_adc, NULL, 1); | |||
193 | static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_adc, NULL, 2); | 154 | static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_adc, NULL, 2); |
194 | static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_adc, NULL, 3); | 155 | static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_adc, NULL, 3); |
195 | 156 | ||
196 | static struct attribute *ad7416_attributes[] = { | 157 | static struct attribute *ad7416_attrs[] = { |
197 | &sensor_dev_attr_temp1_max.dev_attr.attr, | 158 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
198 | &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, | 159 | &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, |
199 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 160 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
200 | NULL | 161 | NULL |
201 | }; | 162 | }; |
163 | ATTRIBUTE_GROUPS(ad7416); | ||
202 | 164 | ||
203 | static struct attribute *ad7417_attributes[] = { | 165 | static struct attribute *ad7417_attrs[] = { |
204 | &sensor_dev_attr_temp1_max.dev_attr.attr, | 166 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
205 | &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, | 167 | &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, |
206 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 168 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
@@ -210,83 +172,100 @@ static struct attribute *ad7417_attributes[] = { | |||
210 | &sensor_dev_attr_in4_input.dev_attr.attr, | 172 | &sensor_dev_attr_in4_input.dev_attr.attr, |
211 | NULL | 173 | NULL |
212 | }; | 174 | }; |
175 | ATTRIBUTE_GROUPS(ad7417); | ||
213 | 176 | ||
214 | static struct attribute *ad7418_attributes[] = { | 177 | static struct attribute *ad7418_attrs[] = { |
215 | &sensor_dev_attr_temp1_max.dev_attr.attr, | 178 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
216 | &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, | 179 | &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, |
217 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 180 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
218 | &sensor_dev_attr_in1_input.dev_attr.attr, | 181 | &sensor_dev_attr_in1_input.dev_attr.attr, |
219 | NULL | 182 | NULL |
220 | }; | 183 | }; |
184 | ATTRIBUTE_GROUPS(ad7418); | ||
185 | |||
186 | static void ad7418_init_client(struct i2c_client *client) | ||
187 | { | ||
188 | struct ad7418_data *data = i2c_get_clientdata(client); | ||
189 | |||
190 | int reg = i2c_smbus_read_byte_data(client, AD7418_REG_CONF); | ||
191 | if (reg < 0) { | ||
192 | dev_err(&client->dev, "cannot read configuration register\n"); | ||
193 | } else { | ||
194 | dev_info(&client->dev, "configuring for mode 1\n"); | ||
195 | i2c_smbus_write_byte_data(client, AD7418_REG_CONF, reg & 0xfe); | ||
196 | |||
197 | if (data->type == ad7417 || data->type == ad7418) | ||
198 | i2c_smbus_write_byte_data(client, | ||
199 | AD7418_REG_CONF2, 0x00); | ||
200 | } | ||
201 | } | ||
221 | 202 | ||
222 | static int ad7418_probe(struct i2c_client *client, | 203 | static int ad7418_probe(struct i2c_client *client, |
223 | const struct i2c_device_id *id) | 204 | const struct i2c_device_id *id) |
224 | { | 205 | { |
206 | struct device *dev = &client->dev; | ||
225 | struct i2c_adapter *adapter = client->adapter; | 207 | struct i2c_adapter *adapter = client->adapter; |
226 | struct ad7418_data *data; | 208 | struct ad7418_data *data; |
227 | int err; | 209 | struct device *hwmon_dev; |
210 | const struct attribute_group **attr_groups = NULL; | ||
228 | 211 | ||
229 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | | 212 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | |
230 | I2C_FUNC_SMBUS_WORD_DATA)) | 213 | I2C_FUNC_SMBUS_WORD_DATA)) |
231 | return -EOPNOTSUPP; | 214 | return -EOPNOTSUPP; |
232 | 215 | ||
233 | data = devm_kzalloc(&client->dev, sizeof(struct ad7418_data), | 216 | data = devm_kzalloc(dev, sizeof(struct ad7418_data), GFP_KERNEL); |
234 | GFP_KERNEL); | ||
235 | if (!data) | 217 | if (!data) |
236 | return -ENOMEM; | 218 | return -ENOMEM; |
237 | 219 | ||
238 | i2c_set_clientdata(client, data); | 220 | i2c_set_clientdata(client, data); |
239 | 221 | ||
240 | mutex_init(&data->lock); | 222 | mutex_init(&data->lock); |
223 | data->client = client; | ||
241 | data->type = id->driver_data; | 224 | data->type = id->driver_data; |
242 | 225 | ||
243 | switch (data->type) { | 226 | switch (data->type) { |
244 | case ad7416: | 227 | case ad7416: |
245 | data->adc_max = 0; | 228 | data->adc_max = 0; |
246 | data->attrs.attrs = ad7416_attributes; | 229 | attr_groups = ad7416_groups; |
247 | break; | 230 | break; |
248 | 231 | ||
249 | case ad7417: | 232 | case ad7417: |
250 | data->adc_max = 4; | 233 | data->adc_max = 4; |
251 | data->attrs.attrs = ad7417_attributes; | 234 | attr_groups = ad7417_groups; |
252 | break; | 235 | break; |
253 | 236 | ||
254 | case ad7418: | 237 | case ad7418: |
255 | data->adc_max = 1; | 238 | data->adc_max = 1; |
256 | data->attrs.attrs = ad7418_attributes; | 239 | attr_groups = ad7418_groups; |
257 | break; | 240 | break; |
258 | } | 241 | } |
259 | 242 | ||
260 | dev_info(&client->dev, "%s chip found\n", client->name); | 243 | dev_info(dev, "%s chip found\n", client->name); |
261 | 244 | ||
262 | /* Initialize the AD7418 chip */ | 245 | /* Initialize the AD7418 chip */ |
263 | ad7418_init_client(client); | 246 | ad7418_init_client(client); |
264 | 247 | ||
265 | /* Register sysfs hooks */ | 248 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, |
266 | err = sysfs_create_group(&client->dev.kobj, &data->attrs); | 249 | client->name, |
267 | if (err) | 250 | data, attr_groups); |
268 | return err; | 251 | return PTR_ERR_OR_ZERO(hwmon_dev); |
269 | |||
270 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
271 | if (IS_ERR(data->hwmon_dev)) { | ||
272 | err = PTR_ERR(data->hwmon_dev); | ||
273 | goto exit_remove; | ||
274 | } | ||
275 | |||
276 | return 0; | ||
277 | |||
278 | exit_remove: | ||
279 | sysfs_remove_group(&client->dev.kobj, &data->attrs); | ||
280 | return err; | ||
281 | } | 252 | } |
282 | 253 | ||
283 | static int ad7418_remove(struct i2c_client *client) | 254 | static const struct i2c_device_id ad7418_id[] = { |
284 | { | 255 | { "ad7416", ad7416 }, |
285 | struct ad7418_data *data = i2c_get_clientdata(client); | 256 | { "ad7417", ad7417 }, |
286 | hwmon_device_unregister(data->hwmon_dev); | 257 | { "ad7418", ad7418 }, |
287 | sysfs_remove_group(&client->dev.kobj, &data->attrs); | 258 | { } |
288 | return 0; | 259 | }; |
289 | } | 260 | MODULE_DEVICE_TABLE(i2c, ad7418_id); |
261 | |||
262 | static struct i2c_driver ad7418_driver = { | ||
263 | .driver = { | ||
264 | .name = "ad7418", | ||
265 | }, | ||
266 | .probe = ad7418_probe, | ||
267 | .id_table = ad7418_id, | ||
268 | }; | ||
290 | 269 | ||
291 | module_i2c_driver(ad7418_driver); | 270 | module_i2c_driver(ad7418_driver); |
292 | 271 | ||
diff --git a/drivers/hwmon/adm1021.c b/drivers/hwmon/adm1021.c index d74241bb278c..1fdcc3e703b9 100644 --- a/drivers/hwmon/adm1021.c +++ b/drivers/hwmon/adm1021.c | |||
@@ -98,41 +98,63 @@ struct adm1021_data { | |||
98 | u8 remote_temp_offset_prec; | 98 | u8 remote_temp_offset_prec; |
99 | }; | 99 | }; |
100 | 100 | ||
101 | static int adm1021_probe(struct i2c_client *client, | ||
102 | const struct i2c_device_id *id); | ||
103 | static int adm1021_detect(struct i2c_client *client, | ||
104 | struct i2c_board_info *info); | ||
105 | static void adm1021_init_client(struct i2c_client *client); | ||
106 | static struct adm1021_data *adm1021_update_device(struct device *dev); | ||
107 | |||
108 | /* (amalysh) read only mode, otherwise any limit's writing confuse BIOS */ | 101 | /* (amalysh) read only mode, otherwise any limit's writing confuse BIOS */ |
109 | static bool read_only; | 102 | static bool read_only; |
110 | 103 | ||
104 | static struct adm1021_data *adm1021_update_device(struct device *dev) | ||
105 | { | ||
106 | struct adm1021_data *data = dev_get_drvdata(dev); | ||
107 | struct i2c_client *client = data->client; | ||
111 | 108 | ||
112 | static const struct i2c_device_id adm1021_id[] = { | 109 | mutex_lock(&data->update_lock); |
113 | { "adm1021", adm1021 }, | ||
114 | { "adm1023", adm1023 }, | ||
115 | { "max1617", max1617 }, | ||
116 | { "max1617a", max1617a }, | ||
117 | { "thmc10", thmc10 }, | ||
118 | { "lm84", lm84 }, | ||
119 | { "gl523sm", gl523sm }, | ||
120 | { "mc1066", mc1066 }, | ||
121 | { } | ||
122 | }; | ||
123 | MODULE_DEVICE_TABLE(i2c, adm1021_id); | ||
124 | 110 | ||
125 | /* This is the driver that will be inserted */ | 111 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) |
126 | static struct i2c_driver adm1021_driver = { | 112 | || !data->valid) { |
127 | .class = I2C_CLASS_HWMON, | 113 | int i; |
128 | .driver = { | 114 | |
129 | .name = "adm1021", | 115 | dev_dbg(dev, "Starting adm1021 update\n"); |
130 | }, | 116 | |
131 | .probe = adm1021_probe, | 117 | for (i = 0; i < 2; i++) { |
132 | .id_table = adm1021_id, | 118 | data->temp[i] = 1000 * |
133 | .detect = adm1021_detect, | 119 | (s8) i2c_smbus_read_byte_data( |
134 | .address_list = normal_i2c, | 120 | client, ADM1021_REG_TEMP(i)); |
135 | }; | 121 | data->temp_max[i] = 1000 * |
122 | (s8) i2c_smbus_read_byte_data( | ||
123 | client, ADM1021_REG_TOS_R(i)); | ||
124 | if (data->type != lm84) { | ||
125 | data->temp_min[i] = 1000 * | ||
126 | (s8) i2c_smbus_read_byte_data(client, | ||
127 | ADM1021_REG_THYST_R(i)); | ||
128 | } | ||
129 | } | ||
130 | data->alarms = i2c_smbus_read_byte_data(client, | ||
131 | ADM1021_REG_STATUS) & 0x7c; | ||
132 | if (data->type == adm1023) { | ||
133 | /* | ||
134 | * The ADM1023 provides 3 extra bits of precision for | ||
135 | * the remote sensor in extra registers. | ||
136 | */ | ||
137 | data->temp[1] += 125 * (i2c_smbus_read_byte_data( | ||
138 | client, ADM1023_REG_REM_TEMP_PREC) >> 5); | ||
139 | data->temp_max[1] += 125 * (i2c_smbus_read_byte_data( | ||
140 | client, ADM1023_REG_REM_TOS_PREC) >> 5); | ||
141 | data->temp_min[1] += 125 * (i2c_smbus_read_byte_data( | ||
142 | client, ADM1023_REG_REM_THYST_PREC) >> 5); | ||
143 | data->remote_temp_offset = | ||
144 | i2c_smbus_read_byte_data(client, | ||
145 | ADM1023_REG_REM_OFFSET); | ||
146 | data->remote_temp_offset_prec = | ||
147 | i2c_smbus_read_byte_data(client, | ||
148 | ADM1023_REG_REM_OFFSET_PREC); | ||
149 | } | ||
150 | data->last_updated = jiffies; | ||
151 | data->valid = 1; | ||
152 | } | ||
153 | |||
154 | mutex_unlock(&data->update_lock); | ||
155 | |||
156 | return data; | ||
157 | } | ||
136 | 158 | ||
137 | static ssize_t show_temp(struct device *dev, | 159 | static ssize_t show_temp(struct device *dev, |
138 | struct device_attribute *devattr, char *buf) | 160 | struct device_attribute *devattr, char *buf) |
@@ -411,6 +433,15 @@ static int adm1021_detect(struct i2c_client *client, | |||
411 | return 0; | 433 | return 0; |
412 | } | 434 | } |
413 | 435 | ||
436 | static void adm1021_init_client(struct i2c_client *client) | ||
437 | { | ||
438 | /* Enable ADC and disable suspend mode */ | ||
439 | i2c_smbus_write_byte_data(client, ADM1021_REG_CONFIG_W, | ||
440 | i2c_smbus_read_byte_data(client, ADM1021_REG_CONFIG_R) & 0xBF); | ||
441 | /* Set Conversion rate to 1/sec (this can be tinkered with) */ | ||
442 | i2c_smbus_write_byte_data(client, ADM1021_REG_CONV_RATE_W, 0x04); | ||
443 | } | ||
444 | |||
414 | static int adm1021_probe(struct i2c_client *client, | 445 | static int adm1021_probe(struct i2c_client *client, |
415 | const struct i2c_device_id *id) | 446 | const struct i2c_device_id *id) |
416 | { | 447 | { |
@@ -440,69 +471,29 @@ static int adm1021_probe(struct i2c_client *client, | |||
440 | return PTR_ERR_OR_ZERO(hwmon_dev); | 471 | return PTR_ERR_OR_ZERO(hwmon_dev); |
441 | } | 472 | } |
442 | 473 | ||
443 | static void adm1021_init_client(struct i2c_client *client) | 474 | static const struct i2c_device_id adm1021_id[] = { |
444 | { | 475 | { "adm1021", adm1021 }, |
445 | /* Enable ADC and disable suspend mode */ | 476 | { "adm1023", adm1023 }, |
446 | i2c_smbus_write_byte_data(client, ADM1021_REG_CONFIG_W, | 477 | { "max1617", max1617 }, |
447 | i2c_smbus_read_byte_data(client, ADM1021_REG_CONFIG_R) & 0xBF); | 478 | { "max1617a", max1617a }, |
448 | /* Set Conversion rate to 1/sec (this can be tinkered with) */ | 479 | { "thmc10", thmc10 }, |
449 | i2c_smbus_write_byte_data(client, ADM1021_REG_CONV_RATE_W, 0x04); | 480 | { "lm84", lm84 }, |
450 | } | 481 | { "gl523sm", gl523sm }, |
451 | 482 | { "mc1066", mc1066 }, | |
452 | static struct adm1021_data *adm1021_update_device(struct device *dev) | 483 | { } |
453 | { | 484 | }; |
454 | struct adm1021_data *data = dev_get_drvdata(dev); | 485 | MODULE_DEVICE_TABLE(i2c, adm1021_id); |
455 | struct i2c_client *client = data->client; | ||
456 | |||
457 | mutex_lock(&data->update_lock); | ||
458 | |||
459 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) | ||
460 | || !data->valid) { | ||
461 | int i; | ||
462 | |||
463 | dev_dbg(dev, "Starting adm1021 update\n"); | ||
464 | |||
465 | for (i = 0; i < 2; i++) { | ||
466 | data->temp[i] = 1000 * | ||
467 | (s8) i2c_smbus_read_byte_data( | ||
468 | client, ADM1021_REG_TEMP(i)); | ||
469 | data->temp_max[i] = 1000 * | ||
470 | (s8) i2c_smbus_read_byte_data( | ||
471 | client, ADM1021_REG_TOS_R(i)); | ||
472 | if (data->type != lm84) { | ||
473 | data->temp_min[i] = 1000 * | ||
474 | (s8) i2c_smbus_read_byte_data(client, | ||
475 | ADM1021_REG_THYST_R(i)); | ||
476 | } | ||
477 | } | ||
478 | data->alarms = i2c_smbus_read_byte_data(client, | ||
479 | ADM1021_REG_STATUS) & 0x7c; | ||
480 | if (data->type == adm1023) { | ||
481 | /* | ||
482 | * The ADM1023 provides 3 extra bits of precision for | ||
483 | * the remote sensor in extra registers. | ||
484 | */ | ||
485 | data->temp[1] += 125 * (i2c_smbus_read_byte_data( | ||
486 | client, ADM1023_REG_REM_TEMP_PREC) >> 5); | ||
487 | data->temp_max[1] += 125 * (i2c_smbus_read_byte_data( | ||
488 | client, ADM1023_REG_REM_TOS_PREC) >> 5); | ||
489 | data->temp_min[1] += 125 * (i2c_smbus_read_byte_data( | ||
490 | client, ADM1023_REG_REM_THYST_PREC) >> 5); | ||
491 | data->remote_temp_offset = | ||
492 | i2c_smbus_read_byte_data(client, | ||
493 | ADM1023_REG_REM_OFFSET); | ||
494 | data->remote_temp_offset_prec = | ||
495 | i2c_smbus_read_byte_data(client, | ||
496 | ADM1023_REG_REM_OFFSET_PREC); | ||
497 | } | ||
498 | data->last_updated = jiffies; | ||
499 | data->valid = 1; | ||
500 | } | ||
501 | |||
502 | mutex_unlock(&data->update_lock); | ||
503 | 486 | ||
504 | return data; | 487 | static struct i2c_driver adm1021_driver = { |
505 | } | 488 | .class = I2C_CLASS_HWMON, |
489 | .driver = { | ||
490 | .name = "adm1021", | ||
491 | }, | ||
492 | .probe = adm1021_probe, | ||
493 | .id_table = adm1021_id, | ||
494 | .detect = adm1021_detect, | ||
495 | .address_list = normal_i2c, | ||
496 | }; | ||
506 | 497 | ||
507 | module_i2c_driver(adm1021_driver); | 498 | module_i2c_driver(adm1021_driver); |
508 | 499 | ||
diff --git a/drivers/hwmon/adm1025.c b/drivers/hwmon/adm1025.c index 9ffc4c8ca8b5..d3d0e8cf27b4 100644 --- a/drivers/hwmon/adm1025.c +++ b/drivers/hwmon/adm1025.c | |||
@@ -103,46 +103,12 @@ static const int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 }; | |||
103 | (val) + 500) / 1000)) | 103 | (val) + 500) / 1000)) |
104 | 104 | ||
105 | /* | 105 | /* |
106 | * Functions declaration | ||
107 | */ | ||
108 | |||
109 | static int adm1025_probe(struct i2c_client *client, | ||
110 | const struct i2c_device_id *id); | ||
111 | static int adm1025_detect(struct i2c_client *client, | ||
112 | struct i2c_board_info *info); | ||
113 | static void adm1025_init_client(struct i2c_client *client); | ||
114 | static int adm1025_remove(struct i2c_client *client); | ||
115 | static struct adm1025_data *adm1025_update_device(struct device *dev); | ||
116 | |||
117 | /* | ||
118 | * Driver data (common to all clients) | ||
119 | */ | ||
120 | |||
121 | static const struct i2c_device_id adm1025_id[] = { | ||
122 | { "adm1025", adm1025 }, | ||
123 | { "ne1619", ne1619 }, | ||
124 | { } | ||
125 | }; | ||
126 | MODULE_DEVICE_TABLE(i2c, adm1025_id); | ||
127 | |||
128 | static struct i2c_driver adm1025_driver = { | ||
129 | .class = I2C_CLASS_HWMON, | ||
130 | .driver = { | ||
131 | .name = "adm1025", | ||
132 | }, | ||
133 | .probe = adm1025_probe, | ||
134 | .remove = adm1025_remove, | ||
135 | .id_table = adm1025_id, | ||
136 | .detect = adm1025_detect, | ||
137 | .address_list = normal_i2c, | ||
138 | }; | ||
139 | |||
140 | /* | ||
141 | * Client data (each client gets its own) | 106 | * Client data (each client gets its own) |
142 | */ | 107 | */ |
143 | 108 | ||
144 | struct adm1025_data { | 109 | struct adm1025_data { |
145 | struct device *hwmon_dev; | 110 | struct i2c_client *client; |
111 | const struct attribute_group *groups[3]; | ||
146 | struct mutex update_lock; | 112 | struct mutex update_lock; |
147 | char valid; /* zero until following fields are valid */ | 113 | char valid; /* zero until following fields are valid */ |
148 | unsigned long last_updated; /* in jiffies */ | 114 | unsigned long last_updated; /* in jiffies */ |
@@ -158,6 +124,51 @@ struct adm1025_data { | |||
158 | u8 vrm; | 124 | u8 vrm; |
159 | }; | 125 | }; |
160 | 126 | ||
127 | static struct adm1025_data *adm1025_update_device(struct device *dev) | ||
128 | { | ||
129 | struct adm1025_data *data = dev_get_drvdata(dev); | ||
130 | struct i2c_client *client = data->client; | ||
131 | |||
132 | mutex_lock(&data->update_lock); | ||
133 | |||
134 | if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { | ||
135 | int i; | ||
136 | |||
137 | dev_dbg(&client->dev, "Updating data.\n"); | ||
138 | for (i = 0; i < 6; i++) { | ||
139 | data->in[i] = i2c_smbus_read_byte_data(client, | ||
140 | ADM1025_REG_IN(i)); | ||
141 | data->in_min[i] = i2c_smbus_read_byte_data(client, | ||
142 | ADM1025_REG_IN_MIN(i)); | ||
143 | data->in_max[i] = i2c_smbus_read_byte_data(client, | ||
144 | ADM1025_REG_IN_MAX(i)); | ||
145 | } | ||
146 | for (i = 0; i < 2; i++) { | ||
147 | data->temp[i] = i2c_smbus_read_byte_data(client, | ||
148 | ADM1025_REG_TEMP(i)); | ||
149 | data->temp_min[i] = i2c_smbus_read_byte_data(client, | ||
150 | ADM1025_REG_TEMP_LOW(i)); | ||
151 | data->temp_max[i] = i2c_smbus_read_byte_data(client, | ||
152 | ADM1025_REG_TEMP_HIGH(i)); | ||
153 | } | ||
154 | data->alarms = i2c_smbus_read_byte_data(client, | ||
155 | ADM1025_REG_STATUS1) | ||
156 | | (i2c_smbus_read_byte_data(client, | ||
157 | ADM1025_REG_STATUS2) << 8); | ||
158 | data->vid = (i2c_smbus_read_byte_data(client, | ||
159 | ADM1025_REG_VID) & 0x0f) | ||
160 | | ((i2c_smbus_read_byte_data(client, | ||
161 | ADM1025_REG_VID4) & 0x01) << 4); | ||
162 | |||
163 | data->last_updated = jiffies; | ||
164 | data->valid = 1; | ||
165 | } | ||
166 | |||
167 | mutex_unlock(&data->update_lock); | ||
168 | |||
169 | return data; | ||
170 | } | ||
171 | |||
161 | /* | 172 | /* |
162 | * Sysfs stuff | 173 | * Sysfs stuff |
163 | */ | 174 | */ |
@@ -217,8 +228,8 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | |||
217 | const char *buf, size_t count) | 228 | const char *buf, size_t count) |
218 | { | 229 | { |
219 | int index = to_sensor_dev_attr(attr)->index; | 230 | int index = to_sensor_dev_attr(attr)->index; |
220 | struct i2c_client *client = to_i2c_client(dev); | 231 | struct adm1025_data *data = dev_get_drvdata(dev); |
221 | struct adm1025_data *data = i2c_get_clientdata(client); | 232 | struct i2c_client *client = data->client; |
222 | long val; | 233 | long val; |
223 | int err; | 234 | int err; |
224 | 235 | ||
@@ -238,8 +249,8 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, | |||
238 | const char *buf, size_t count) | 249 | const char *buf, size_t count) |
239 | { | 250 | { |
240 | int index = to_sensor_dev_attr(attr)->index; | 251 | int index = to_sensor_dev_attr(attr)->index; |
241 | struct i2c_client *client = to_i2c_client(dev); | 252 | struct adm1025_data *data = dev_get_drvdata(dev); |
242 | struct adm1025_data *data = i2c_get_clientdata(client); | 253 | struct i2c_client *client = data->client; |
243 | long val; | 254 | long val; |
244 | int err; | 255 | int err; |
245 | 256 | ||
@@ -273,8 +284,8 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | |||
273 | const char *buf, size_t count) | 284 | const char *buf, size_t count) |
274 | { | 285 | { |
275 | int index = to_sensor_dev_attr(attr)->index; | 286 | int index = to_sensor_dev_attr(attr)->index; |
276 | struct i2c_client *client = to_i2c_client(dev); | 287 | struct adm1025_data *data = dev_get_drvdata(dev); |
277 | struct adm1025_data *data = i2c_get_clientdata(client); | 288 | struct i2c_client *client = data->client; |
278 | long val; | 289 | long val; |
279 | int err; | 290 | int err; |
280 | 291 | ||
@@ -294,8 +305,8 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
294 | const char *buf, size_t count) | 305 | const char *buf, size_t count) |
295 | { | 306 | { |
296 | int index = to_sensor_dev_attr(attr)->index; | 307 | int index = to_sensor_dev_attr(attr)->index; |
297 | struct i2c_client *client = to_i2c_client(dev); | 308 | struct adm1025_data *data = dev_get_drvdata(dev); |
298 | struct adm1025_data *data = i2c_get_clientdata(client); | 309 | struct i2c_client *client = data->client; |
299 | long val; | 310 | long val; |
300 | int err; | 311 | int err; |
301 | 312 | ||
@@ -470,51 +481,6 @@ static int adm1025_detect(struct i2c_client *client, | |||
470 | return 0; | 481 | return 0; |
471 | } | 482 | } |
472 | 483 | ||
473 | static int adm1025_probe(struct i2c_client *client, | ||
474 | const struct i2c_device_id *id) | ||
475 | { | ||
476 | struct adm1025_data *data; | ||
477 | int err; | ||
478 | u8 config; | ||
479 | |||
480 | data = devm_kzalloc(&client->dev, sizeof(struct adm1025_data), | ||
481 | GFP_KERNEL); | ||
482 | if (!data) | ||
483 | return -ENOMEM; | ||
484 | |||
485 | i2c_set_clientdata(client, data); | ||
486 | mutex_init(&data->update_lock); | ||
487 | |||
488 | /* Initialize the ADM1025 chip */ | ||
489 | adm1025_init_client(client); | ||
490 | |||
491 | /* Register sysfs hooks */ | ||
492 | err = sysfs_create_group(&client->dev.kobj, &adm1025_group); | ||
493 | if (err) | ||
494 | return err; | ||
495 | |||
496 | /* Pin 11 is either in4 (+12V) or VID4 */ | ||
497 | config = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG); | ||
498 | if (!(config & 0x20)) { | ||
499 | err = sysfs_create_group(&client->dev.kobj, &adm1025_group_in4); | ||
500 | if (err) | ||
501 | goto exit_remove; | ||
502 | } | ||
503 | |||
504 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
505 | if (IS_ERR(data->hwmon_dev)) { | ||
506 | err = PTR_ERR(data->hwmon_dev); | ||
507 | goto exit_remove; | ||
508 | } | ||
509 | |||
510 | return 0; | ||
511 | |||
512 | exit_remove: | ||
513 | sysfs_remove_group(&client->dev.kobj, &adm1025_group); | ||
514 | sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4); | ||
515 | return err; | ||
516 | } | ||
517 | |||
518 | static void adm1025_init_client(struct i2c_client *client) | 484 | static void adm1025_init_client(struct i2c_client *client) |
519 | { | 485 | { |
520 | u8 reg; | 486 | u8 reg; |
@@ -557,61 +523,54 @@ static void adm1025_init_client(struct i2c_client *client) | |||
557 | (reg&0x7E)|0x01); | 523 | (reg&0x7E)|0x01); |
558 | } | 524 | } |
559 | 525 | ||
560 | static int adm1025_remove(struct i2c_client *client) | 526 | static int adm1025_probe(struct i2c_client *client, |
527 | const struct i2c_device_id *id) | ||
561 | { | 528 | { |
562 | struct adm1025_data *data = i2c_get_clientdata(client); | 529 | struct device *dev = &client->dev; |
563 | 530 | struct device *hwmon_dev; | |
564 | hwmon_device_unregister(data->hwmon_dev); | 531 | struct adm1025_data *data; |
565 | sysfs_remove_group(&client->dev.kobj, &adm1025_group); | 532 | u8 config; |
566 | sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4); | ||
567 | |||
568 | return 0; | ||
569 | } | ||
570 | 533 | ||
571 | static struct adm1025_data *adm1025_update_device(struct device *dev) | 534 | data = devm_kzalloc(dev, sizeof(struct adm1025_data), GFP_KERNEL); |
572 | { | 535 | if (!data) |
573 | struct i2c_client *client = to_i2c_client(dev); | 536 | return -ENOMEM; |
574 | struct adm1025_data *data = i2c_get_clientdata(client); | ||
575 | 537 | ||
576 | mutex_lock(&data->update_lock); | 538 | i2c_set_clientdata(client, data); |
539 | data->client = client; | ||
540 | mutex_init(&data->update_lock); | ||
577 | 541 | ||
578 | if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { | 542 | /* Initialize the ADM1025 chip */ |
579 | int i; | 543 | adm1025_init_client(client); |
580 | 544 | ||
581 | dev_dbg(&client->dev, "Updating data.\n"); | 545 | /* sysfs hooks */ |
582 | for (i = 0; i < 6; i++) { | 546 | data->groups[0] = &adm1025_group; |
583 | data->in[i] = i2c_smbus_read_byte_data(client, | 547 | /* Pin 11 is either in4 (+12V) or VID4 */ |
584 | ADM1025_REG_IN(i)); | 548 | config = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG); |
585 | data->in_min[i] = i2c_smbus_read_byte_data(client, | 549 | if (!(config & 0x20)) |
586 | ADM1025_REG_IN_MIN(i)); | 550 | data->groups[1] = &adm1025_group_in4; |
587 | data->in_max[i] = i2c_smbus_read_byte_data(client, | ||
588 | ADM1025_REG_IN_MAX(i)); | ||
589 | } | ||
590 | for (i = 0; i < 2; i++) { | ||
591 | data->temp[i] = i2c_smbus_read_byte_data(client, | ||
592 | ADM1025_REG_TEMP(i)); | ||
593 | data->temp_min[i] = i2c_smbus_read_byte_data(client, | ||
594 | ADM1025_REG_TEMP_LOW(i)); | ||
595 | data->temp_max[i] = i2c_smbus_read_byte_data(client, | ||
596 | ADM1025_REG_TEMP_HIGH(i)); | ||
597 | } | ||
598 | data->alarms = i2c_smbus_read_byte_data(client, | ||
599 | ADM1025_REG_STATUS1) | ||
600 | | (i2c_smbus_read_byte_data(client, | ||
601 | ADM1025_REG_STATUS2) << 8); | ||
602 | data->vid = (i2c_smbus_read_byte_data(client, | ||
603 | ADM1025_REG_VID) & 0x0f) | ||
604 | | ((i2c_smbus_read_byte_data(client, | ||
605 | ADM1025_REG_VID4) & 0x01) << 4); | ||
606 | 551 | ||
607 | data->last_updated = jiffies; | 552 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
608 | data->valid = 1; | 553 | data, data->groups); |
609 | } | 554 | return PTR_ERR_OR_ZERO(hwmon_dev); |
555 | } | ||
610 | 556 | ||
611 | mutex_unlock(&data->update_lock); | 557 | static const struct i2c_device_id adm1025_id[] = { |
558 | { "adm1025", adm1025 }, | ||
559 | { "ne1619", ne1619 }, | ||
560 | { } | ||
561 | }; | ||
562 | MODULE_DEVICE_TABLE(i2c, adm1025_id); | ||
612 | 563 | ||
613 | return data; | 564 | static struct i2c_driver adm1025_driver = { |
614 | } | 565 | .class = I2C_CLASS_HWMON, |
566 | .driver = { | ||
567 | .name = "adm1025", | ||
568 | }, | ||
569 | .probe = adm1025_probe, | ||
570 | .id_table = adm1025_id, | ||
571 | .detect = adm1025_detect, | ||
572 | .address_list = normal_i2c, | ||
573 | }; | ||
615 | 574 | ||
616 | module_i2c_driver(adm1025_driver); | 575 | module_i2c_driver(adm1025_driver); |
617 | 576 | ||
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c index b3498acb9ab4..ca8430f92564 100644 --- a/drivers/hwmon/adm1026.c +++ b/drivers/hwmon/adm1026.c | |||
@@ -266,7 +266,8 @@ struct pwm_data { | |||
266 | }; | 266 | }; |
267 | 267 | ||
268 | struct adm1026_data { | 268 | struct adm1026_data { |
269 | struct device *hwmon_dev; | 269 | struct i2c_client *client; |
270 | const struct attribute_group *groups[3]; | ||
270 | 271 | ||
271 | struct mutex update_lock; | 272 | struct mutex update_lock; |
272 | int valid; /* !=0 if following fields are valid */ | 273 | int valid; /* !=0 if following fields are valid */ |
@@ -298,37 +299,6 @@ struct adm1026_data { | |||
298 | u8 config3; /* Register value */ | 299 | u8 config3; /* Register value */ |
299 | }; | 300 | }; |
300 | 301 | ||
301 | static int adm1026_probe(struct i2c_client *client, | ||
302 | const struct i2c_device_id *id); | ||
303 | static int adm1026_detect(struct i2c_client *client, | ||
304 | struct i2c_board_info *info); | ||
305 | static int adm1026_remove(struct i2c_client *client); | ||
306 | static int adm1026_read_value(struct i2c_client *client, u8 reg); | ||
307 | static int adm1026_write_value(struct i2c_client *client, u8 reg, int value); | ||
308 | static void adm1026_print_gpio(struct i2c_client *client); | ||
309 | static void adm1026_fixup_gpio(struct i2c_client *client); | ||
310 | static struct adm1026_data *adm1026_update_device(struct device *dev); | ||
311 | static void adm1026_init_client(struct i2c_client *client); | ||
312 | |||
313 | |||
314 | static const struct i2c_device_id adm1026_id[] = { | ||
315 | { "adm1026", 0 }, | ||
316 | { } | ||
317 | }; | ||
318 | MODULE_DEVICE_TABLE(i2c, adm1026_id); | ||
319 | |||
320 | static struct i2c_driver adm1026_driver = { | ||
321 | .class = I2C_CLASS_HWMON, | ||
322 | .driver = { | ||
323 | .name = "adm1026", | ||
324 | }, | ||
325 | .probe = adm1026_probe, | ||
326 | .remove = adm1026_remove, | ||
327 | .id_table = adm1026_id, | ||
328 | .detect = adm1026_detect, | ||
329 | .address_list = normal_i2c, | ||
330 | }; | ||
331 | |||
332 | static int adm1026_read_value(struct i2c_client *client, u8 reg) | 302 | static int adm1026_read_value(struct i2c_client *client, u8 reg) |
333 | { | 303 | { |
334 | int res; | 304 | int res; |
@@ -357,212 +327,10 @@ static int adm1026_write_value(struct i2c_client *client, u8 reg, int value) | |||
357 | return res; | 327 | return res; |
358 | } | 328 | } |
359 | 329 | ||
360 | static void adm1026_init_client(struct i2c_client *client) | ||
361 | { | ||
362 | int value, i; | ||
363 | struct adm1026_data *data = i2c_get_clientdata(client); | ||
364 | |||
365 | dev_dbg(&client->dev, "Initializing device\n"); | ||
366 | /* Read chip config */ | ||
367 | data->config1 = adm1026_read_value(client, ADM1026_REG_CONFIG1); | ||
368 | data->config2 = adm1026_read_value(client, ADM1026_REG_CONFIG2); | ||
369 | data->config3 = adm1026_read_value(client, ADM1026_REG_CONFIG3); | ||
370 | |||
371 | /* Inform user of chip config */ | ||
372 | dev_dbg(&client->dev, "ADM1026_REG_CONFIG1 is: 0x%02x\n", | ||
373 | data->config1); | ||
374 | if ((data->config1 & CFG1_MONITOR) == 0) { | ||
375 | dev_dbg(&client->dev, | ||
376 | "Monitoring not currently enabled.\n"); | ||
377 | } | ||
378 | if (data->config1 & CFG1_INT_ENABLE) { | ||
379 | dev_dbg(&client->dev, | ||
380 | "SMBALERT interrupts are enabled.\n"); | ||
381 | } | ||
382 | if (data->config1 & CFG1_AIN8_9) { | ||
383 | dev_dbg(&client->dev, | ||
384 | "in8 and in9 enabled. temp3 disabled.\n"); | ||
385 | } else { | ||
386 | dev_dbg(&client->dev, | ||
387 | "temp3 enabled. in8 and in9 disabled.\n"); | ||
388 | } | ||
389 | if (data->config1 & CFG1_THERM_HOT) { | ||
390 | dev_dbg(&client->dev, | ||
391 | "Automatic THERM, PWM, and temp limits enabled.\n"); | ||
392 | } | ||
393 | |||
394 | if (data->config3 & CFG3_GPIO16_ENABLE) { | ||
395 | dev_dbg(&client->dev, | ||
396 | "GPIO16 enabled. THERM pin disabled.\n"); | ||
397 | } else { | ||
398 | dev_dbg(&client->dev, | ||
399 | "THERM pin enabled. GPIO16 disabled.\n"); | ||
400 | } | ||
401 | if (data->config3 & CFG3_VREF_250) | ||
402 | dev_dbg(&client->dev, "Vref is 2.50 Volts.\n"); | ||
403 | else | ||
404 | dev_dbg(&client->dev, "Vref is 1.82 Volts.\n"); | ||
405 | /* Read and pick apart the existing GPIO configuration */ | ||
406 | value = 0; | ||
407 | for (i = 0; i <= 15; ++i) { | ||
408 | if ((i & 0x03) == 0) { | ||
409 | value = adm1026_read_value(client, | ||
410 | ADM1026_REG_GPIO_CFG_0_3 + i / 4); | ||
411 | } | ||
412 | data->gpio_config[i] = value & 0x03; | ||
413 | value >>= 2; | ||
414 | } | ||
415 | data->gpio_config[16] = (data->config3 >> 6) & 0x03; | ||
416 | |||
417 | /* ... and then print it */ | ||
418 | adm1026_print_gpio(client); | ||
419 | |||
420 | /* | ||
421 | * If the user asks us to reprogram the GPIO config, then | ||
422 | * do it now. | ||
423 | */ | ||
424 | if (gpio_input[0] != -1 || gpio_output[0] != -1 | ||
425 | || gpio_inverted[0] != -1 || gpio_normal[0] != -1 | ||
426 | || gpio_fan[0] != -1) { | ||
427 | adm1026_fixup_gpio(client); | ||
428 | } | ||
429 | |||
430 | /* | ||
431 | * WE INTENTIONALLY make no changes to the limits, | ||
432 | * offsets, pwms, fans and zones. If they were | ||
433 | * configured, we don't want to mess with them. | ||
434 | * If they weren't, the default is 100% PWM, no | ||
435 | * control and will suffice until 'sensors -s' | ||
436 | * can be run by the user. We DO set the default | ||
437 | * value for pwm1.auto_pwm_min to its maximum | ||
438 | * so that enabling automatic pwm fan control | ||
439 | * without first setting a value for pwm1.auto_pwm_min | ||
440 | * will not result in potentially dangerous fan speed decrease. | ||
441 | */ | ||
442 | data->pwm1.auto_pwm_min = 255; | ||
443 | /* Start monitoring */ | ||
444 | value = adm1026_read_value(client, ADM1026_REG_CONFIG1); | ||
445 | /* Set MONITOR, clear interrupt acknowledge and s/w reset */ | ||
446 | value = (value | CFG1_MONITOR) & (~CFG1_INT_CLEAR & ~CFG1_RESET); | ||
447 | dev_dbg(&client->dev, "Setting CONFIG to: 0x%02x\n", value); | ||
448 | data->config1 = value; | ||
449 | adm1026_write_value(client, ADM1026_REG_CONFIG1, value); | ||
450 | |||
451 | /* initialize fan_div[] to hardware defaults */ | ||
452 | value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3) | | ||
453 | (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7) << 8); | ||
454 | for (i = 0; i <= 7; ++i) { | ||
455 | data->fan_div[i] = DIV_FROM_REG(value & 0x03); | ||
456 | value >>= 2; | ||
457 | } | ||
458 | } | ||
459 | |||
460 | static void adm1026_print_gpio(struct i2c_client *client) | ||
461 | { | ||
462 | struct adm1026_data *data = i2c_get_clientdata(client); | ||
463 | int i; | ||
464 | |||
465 | dev_dbg(&client->dev, "GPIO config is:\n"); | ||
466 | for (i = 0; i <= 7; ++i) { | ||
467 | if (data->config2 & (1 << i)) { | ||
468 | dev_dbg(&client->dev, "\t%sGP%s%d\n", | ||
469 | data->gpio_config[i] & 0x02 ? "" : "!", | ||
470 | data->gpio_config[i] & 0x01 ? "OUT" : "IN", | ||
471 | i); | ||
472 | } else { | ||
473 | dev_dbg(&client->dev, "\tFAN%d\n", i); | ||
474 | } | ||
475 | } | ||
476 | for (i = 8; i <= 15; ++i) { | ||
477 | dev_dbg(&client->dev, "\t%sGP%s%d\n", | ||
478 | data->gpio_config[i] & 0x02 ? "" : "!", | ||
479 | data->gpio_config[i] & 0x01 ? "OUT" : "IN", | ||
480 | i); | ||
481 | } | ||
482 | if (data->config3 & CFG3_GPIO16_ENABLE) { | ||
483 | dev_dbg(&client->dev, "\t%sGP%s16\n", | ||
484 | data->gpio_config[16] & 0x02 ? "" : "!", | ||
485 | data->gpio_config[16] & 0x01 ? "OUT" : "IN"); | ||
486 | } else { | ||
487 | /* GPIO16 is THERM */ | ||
488 | dev_dbg(&client->dev, "\tTHERM\n"); | ||
489 | } | ||
490 | } | ||
491 | |||
492 | static void adm1026_fixup_gpio(struct i2c_client *client) | ||
493 | { | ||
494 | struct adm1026_data *data = i2c_get_clientdata(client); | ||
495 | int i; | ||
496 | int value; | ||
497 | |||
498 | /* Make the changes requested. */ | ||
499 | /* | ||
500 | * We may need to unlock/stop monitoring or soft-reset the | ||
501 | * chip before we can make changes. This hasn't been | ||
502 | * tested much. FIXME | ||
503 | */ | ||
504 | |||
505 | /* Make outputs */ | ||
506 | for (i = 0; i <= 16; ++i) { | ||
507 | if (gpio_output[i] >= 0 && gpio_output[i] <= 16) | ||
508 | data->gpio_config[gpio_output[i]] |= 0x01; | ||
509 | /* if GPIO0-7 is output, it isn't a FAN tach */ | ||
510 | if (gpio_output[i] >= 0 && gpio_output[i] <= 7) | ||
511 | data->config2 |= 1 << gpio_output[i]; | ||
512 | } | ||
513 | |||
514 | /* Input overrides output */ | ||
515 | for (i = 0; i <= 16; ++i) { | ||
516 | if (gpio_input[i] >= 0 && gpio_input[i] <= 16) | ||
517 | data->gpio_config[gpio_input[i]] &= ~0x01; | ||
518 | /* if GPIO0-7 is input, it isn't a FAN tach */ | ||
519 | if (gpio_input[i] >= 0 && gpio_input[i] <= 7) | ||
520 | data->config2 |= 1 << gpio_input[i]; | ||
521 | } | ||
522 | |||
523 | /* Inverted */ | ||
524 | for (i = 0; i <= 16; ++i) { | ||
525 | if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16) | ||
526 | data->gpio_config[gpio_inverted[i]] &= ~0x02; | ||
527 | } | ||
528 | |||
529 | /* Normal overrides inverted */ | ||
530 | for (i = 0; i <= 16; ++i) { | ||
531 | if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16) | ||
532 | data->gpio_config[gpio_normal[i]] |= 0x02; | ||
533 | } | ||
534 | |||
535 | /* Fan overrides input and output */ | ||
536 | for (i = 0; i <= 7; ++i) { | ||
537 | if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7) | ||
538 | data->config2 &= ~(1 << gpio_fan[i]); | ||
539 | } | ||
540 | |||
541 | /* Write new configs to registers */ | ||
542 | adm1026_write_value(client, ADM1026_REG_CONFIG2, data->config2); | ||
543 | data->config3 = (data->config3 & 0x3f) | ||
544 | | ((data->gpio_config[16] & 0x03) << 6); | ||
545 | adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3); | ||
546 | for (i = 15, value = 0; i >= 0; --i) { | ||
547 | value <<= 2; | ||
548 | value |= data->gpio_config[i] & 0x03; | ||
549 | if ((i & 0x03) == 0) { | ||
550 | adm1026_write_value(client, | ||
551 | ADM1026_REG_GPIO_CFG_0_3 + i/4, | ||
552 | value); | ||
553 | value = 0; | ||
554 | } | ||
555 | } | ||
556 | |||
557 | /* Print the new config */ | ||
558 | adm1026_print_gpio(client); | ||
559 | } | ||
560 | |||
561 | |||
562 | static struct adm1026_data *adm1026_update_device(struct device *dev) | 330 | static struct adm1026_data *adm1026_update_device(struct device *dev) |
563 | { | 331 | { |
564 | struct i2c_client *client = to_i2c_client(dev); | 332 | struct adm1026_data *data = dev_get_drvdata(dev); |
565 | struct adm1026_data *data = i2c_get_clientdata(client); | 333 | struct i2c_client *client = data->client; |
566 | int i; | 334 | int i; |
567 | long value, alarms, gpio; | 335 | long value, alarms, gpio; |
568 | 336 | ||
@@ -728,8 +496,8 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | |||
728 | { | 496 | { |
729 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 497 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
730 | int nr = sensor_attr->index; | 498 | int nr = sensor_attr->index; |
731 | struct i2c_client *client = to_i2c_client(dev); | 499 | struct adm1026_data *data = dev_get_drvdata(dev); |
732 | struct adm1026_data *data = i2c_get_clientdata(client); | 500 | struct i2c_client *client = data->client; |
733 | long val; | 501 | long val; |
734 | int err; | 502 | int err; |
735 | 503 | ||
@@ -756,8 +524,8 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, | |||
756 | { | 524 | { |
757 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 525 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
758 | int nr = sensor_attr->index; | 526 | int nr = sensor_attr->index; |
759 | struct i2c_client *client = to_i2c_client(dev); | 527 | struct adm1026_data *data = dev_get_drvdata(dev); |
760 | struct adm1026_data *data = i2c_get_clientdata(client); | 528 | struct i2c_client *client = data->client; |
761 | long val; | 529 | long val; |
762 | int err; | 530 | int err; |
763 | 531 | ||
@@ -815,8 +583,8 @@ static ssize_t show_in16_min(struct device *dev, struct device_attribute *attr, | |||
815 | static ssize_t set_in16_min(struct device *dev, struct device_attribute *attr, | 583 | static ssize_t set_in16_min(struct device *dev, struct device_attribute *attr, |
816 | const char *buf, size_t count) | 584 | const char *buf, size_t count) |
817 | { | 585 | { |
818 | struct i2c_client *client = to_i2c_client(dev); | 586 | struct adm1026_data *data = dev_get_drvdata(dev); |
819 | struct adm1026_data *data = i2c_get_clientdata(client); | 587 | struct i2c_client *client = data->client; |
820 | long val; | 588 | long val; |
821 | int err; | 589 | int err; |
822 | 590 | ||
@@ -840,8 +608,8 @@ static ssize_t show_in16_max(struct device *dev, struct device_attribute *attr, | |||
840 | static ssize_t set_in16_max(struct device *dev, struct device_attribute *attr, | 608 | static ssize_t set_in16_max(struct device *dev, struct device_attribute *attr, |
841 | const char *buf, size_t count) | 609 | const char *buf, size_t count) |
842 | { | 610 | { |
843 | struct i2c_client *client = to_i2c_client(dev); | 611 | struct adm1026_data *data = dev_get_drvdata(dev); |
844 | struct adm1026_data *data = i2c_get_clientdata(client); | 612 | struct i2c_client *client = data->client; |
845 | long val; | 613 | long val; |
846 | int err; | 614 | int err; |
847 | 615 | ||
@@ -888,8 +656,8 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | |||
888 | { | 656 | { |
889 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 657 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
890 | int nr = sensor_attr->index; | 658 | int nr = sensor_attr->index; |
891 | struct i2c_client *client = to_i2c_client(dev); | 659 | struct adm1026_data *data = dev_get_drvdata(dev); |
892 | struct adm1026_data *data = i2c_get_clientdata(client); | 660 | struct i2c_client *client = data->client; |
893 | long val; | 661 | long val; |
894 | int err; | 662 | int err; |
895 | 663 | ||
@@ -923,8 +691,8 @@ fan_offset(8); | |||
923 | /* Adjust fan_min to account for new fan divisor */ | 691 | /* Adjust fan_min to account for new fan divisor */ |
924 | static void fixup_fan_min(struct device *dev, int fan, int old_div) | 692 | static void fixup_fan_min(struct device *dev, int fan, int old_div) |
925 | { | 693 | { |
926 | struct i2c_client *client = to_i2c_client(dev); | 694 | struct adm1026_data *data = dev_get_drvdata(dev); |
927 | struct adm1026_data *data = i2c_get_clientdata(client); | 695 | struct i2c_client *client = data->client; |
928 | int new_min; | 696 | int new_min; |
929 | int new_div = data->fan_div[fan]; | 697 | int new_div = data->fan_div[fan]; |
930 | 698 | ||
@@ -952,8 +720,8 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | |||
952 | { | 720 | { |
953 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 721 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
954 | int nr = sensor_attr->index; | 722 | int nr = sensor_attr->index; |
955 | struct i2c_client *client = to_i2c_client(dev); | 723 | struct adm1026_data *data = dev_get_drvdata(dev); |
956 | struct adm1026_data *data = i2c_get_clientdata(client); | 724 | struct i2c_client *client = data->client; |
957 | long val; | 725 | long val; |
958 | int orig_div, new_div; | 726 | int orig_div, new_div; |
959 | int err; | 727 | int err; |
@@ -1024,8 +792,8 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | |||
1024 | { | 792 | { |
1025 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 793 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
1026 | int nr = sensor_attr->index; | 794 | int nr = sensor_attr->index; |
1027 | struct i2c_client *client = to_i2c_client(dev); | 795 | struct adm1026_data *data = dev_get_drvdata(dev); |
1028 | struct adm1026_data *data = i2c_get_clientdata(client); | 796 | struct i2c_client *client = data->client; |
1029 | long val; | 797 | long val; |
1030 | int err; | 798 | int err; |
1031 | 799 | ||
@@ -1053,8 +821,8 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
1053 | { | 821 | { |
1054 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 822 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
1055 | int nr = sensor_attr->index; | 823 | int nr = sensor_attr->index; |
1056 | struct i2c_client *client = to_i2c_client(dev); | 824 | struct adm1026_data *data = dev_get_drvdata(dev); |
1057 | struct adm1026_data *data = i2c_get_clientdata(client); | 825 | struct i2c_client *client = data->client; |
1058 | long val; | 826 | long val; |
1059 | int err; | 827 | int err; |
1060 | 828 | ||
@@ -1097,8 +865,8 @@ static ssize_t set_temp_offset(struct device *dev, | |||
1097 | { | 865 | { |
1098 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 866 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
1099 | int nr = sensor_attr->index; | 867 | int nr = sensor_attr->index; |
1100 | struct i2c_client *client = to_i2c_client(dev); | 868 | struct adm1026_data *data = dev_get_drvdata(dev); |
1101 | struct adm1026_data *data = i2c_get_clientdata(client); | 869 | struct i2c_client *client = data->client; |
1102 | long val; | 870 | long val; |
1103 | int err; | 871 | int err; |
1104 | 872 | ||
@@ -1153,8 +921,8 @@ static ssize_t set_temp_auto_point1_temp(struct device *dev, | |||
1153 | { | 921 | { |
1154 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 922 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
1155 | int nr = sensor_attr->index; | 923 | int nr = sensor_attr->index; |
1156 | struct i2c_client *client = to_i2c_client(dev); | 924 | struct adm1026_data *data = dev_get_drvdata(dev); |
1157 | struct adm1026_data *data = i2c_get_clientdata(client); | 925 | struct i2c_client *client = data->client; |
1158 | long val; | 926 | long val; |
1159 | int err; | 927 | int err; |
1160 | 928 | ||
@@ -1192,8 +960,8 @@ static ssize_t show_temp_crit_enable(struct device *dev, | |||
1192 | static ssize_t set_temp_crit_enable(struct device *dev, | 960 | static ssize_t set_temp_crit_enable(struct device *dev, |
1193 | struct device_attribute *attr, const char *buf, size_t count) | 961 | struct device_attribute *attr, const char *buf, size_t count) |
1194 | { | 962 | { |
1195 | struct i2c_client *client = to_i2c_client(dev); | 963 | struct adm1026_data *data = dev_get_drvdata(dev); |
1196 | struct adm1026_data *data = i2c_get_clientdata(client); | 964 | struct i2c_client *client = data->client; |
1197 | unsigned long val; | 965 | unsigned long val; |
1198 | int err; | 966 | int err; |
1199 | 967 | ||
@@ -1233,8 +1001,8 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr, | |||
1233 | { | 1001 | { |
1234 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 1002 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
1235 | int nr = sensor_attr->index; | 1003 | int nr = sensor_attr->index; |
1236 | struct i2c_client *client = to_i2c_client(dev); | 1004 | struct adm1026_data *data = dev_get_drvdata(dev); |
1237 | struct adm1026_data *data = i2c_get_clientdata(client); | 1005 | struct i2c_client *client = data->client; |
1238 | long val; | 1006 | long val; |
1239 | int err; | 1007 | int err; |
1240 | 1008 | ||
@@ -1268,8 +1036,8 @@ static ssize_t set_analog_out_reg(struct device *dev, | |||
1268 | struct device_attribute *attr, | 1036 | struct device_attribute *attr, |
1269 | const char *buf, size_t count) | 1037 | const char *buf, size_t count) |
1270 | { | 1038 | { |
1271 | struct i2c_client *client = to_i2c_client(dev); | 1039 | struct adm1026_data *data = dev_get_drvdata(dev); |
1272 | struct adm1026_data *data = i2c_get_clientdata(client); | 1040 | struct i2c_client *client = data->client; |
1273 | long val; | 1041 | long val; |
1274 | int err; | 1042 | int err; |
1275 | 1043 | ||
@@ -1378,8 +1146,8 @@ static ssize_t show_alarm_mask(struct device *dev, | |||
1378 | static ssize_t set_alarm_mask(struct device *dev, struct device_attribute *attr, | 1146 | static ssize_t set_alarm_mask(struct device *dev, struct device_attribute *attr, |
1379 | const char *buf, size_t count) | 1147 | const char *buf, size_t count) |
1380 | { | 1148 | { |
1381 | struct i2c_client *client = to_i2c_client(dev); | 1149 | struct adm1026_data *data = dev_get_drvdata(dev); |
1382 | struct adm1026_data *data = i2c_get_clientdata(client); | 1150 | struct i2c_client *client = data->client; |
1383 | unsigned long mask; | 1151 | unsigned long mask; |
1384 | long val; | 1152 | long val; |
1385 | int err; | 1153 | int err; |
@@ -1420,8 +1188,8 @@ static ssize_t show_gpio(struct device *dev, struct device_attribute *attr, | |||
1420 | static ssize_t set_gpio(struct device *dev, struct device_attribute *attr, | 1188 | static ssize_t set_gpio(struct device *dev, struct device_attribute *attr, |
1421 | const char *buf, size_t count) | 1189 | const char *buf, size_t count) |
1422 | { | 1190 | { |
1423 | struct i2c_client *client = to_i2c_client(dev); | 1191 | struct adm1026_data *data = dev_get_drvdata(dev); |
1424 | struct adm1026_data *data = i2c_get_clientdata(client); | 1192 | struct i2c_client *client = data->client; |
1425 | long gpio; | 1193 | long gpio; |
1426 | long val; | 1194 | long val; |
1427 | int err; | 1195 | int err; |
@@ -1453,8 +1221,8 @@ static ssize_t show_gpio_mask(struct device *dev, struct device_attribute *attr, | |||
1453 | static ssize_t set_gpio_mask(struct device *dev, struct device_attribute *attr, | 1221 | static ssize_t set_gpio_mask(struct device *dev, struct device_attribute *attr, |
1454 | const char *buf, size_t count) | 1222 | const char *buf, size_t count) |
1455 | { | 1223 | { |
1456 | struct i2c_client *client = to_i2c_client(dev); | 1224 | struct adm1026_data *data = dev_get_drvdata(dev); |
1457 | struct adm1026_data *data = i2c_get_clientdata(client); | 1225 | struct i2c_client *client = data->client; |
1458 | long mask; | 1226 | long mask; |
1459 | long val; | 1227 | long val; |
1460 | int err; | 1228 | int err; |
@@ -1487,8 +1255,8 @@ static ssize_t show_pwm_reg(struct device *dev, struct device_attribute *attr, | |||
1487 | static ssize_t set_pwm_reg(struct device *dev, struct device_attribute *attr, | 1255 | static ssize_t set_pwm_reg(struct device *dev, struct device_attribute *attr, |
1488 | const char *buf, size_t count) | 1256 | const char *buf, size_t count) |
1489 | { | 1257 | { |
1490 | struct i2c_client *client = to_i2c_client(dev); | 1258 | struct adm1026_data *data = dev_get_drvdata(dev); |
1491 | struct adm1026_data *data = i2c_get_clientdata(client); | 1259 | struct i2c_client *client = data->client; |
1492 | 1260 | ||
1493 | if (data->pwm1.enable == 1) { | 1261 | if (data->pwm1.enable == 1) { |
1494 | long val; | 1262 | long val; |
@@ -1517,8 +1285,8 @@ static ssize_t set_auto_pwm_min(struct device *dev, | |||
1517 | struct device_attribute *attr, const char *buf, | 1285 | struct device_attribute *attr, const char *buf, |
1518 | size_t count) | 1286 | size_t count) |
1519 | { | 1287 | { |
1520 | struct i2c_client *client = to_i2c_client(dev); | 1288 | struct adm1026_data *data = dev_get_drvdata(dev); |
1521 | struct adm1026_data *data = i2c_get_clientdata(client); | 1289 | struct i2c_client *client = data->client; |
1522 | unsigned long val; | 1290 | unsigned long val; |
1523 | int err; | 1291 | int err; |
1524 | 1292 | ||
@@ -1553,8 +1321,8 @@ static ssize_t show_pwm_enable(struct device *dev, | |||
1553 | static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr, | 1321 | static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr, |
1554 | const char *buf, size_t count) | 1322 | const char *buf, size_t count) |
1555 | { | 1323 | { |
1556 | struct i2c_client *client = to_i2c_client(dev); | 1324 | struct adm1026_data *data = dev_get_drvdata(dev); |
1557 | struct adm1026_data *data = i2c_get_clientdata(client); | 1325 | struct i2c_client *client = data->client; |
1558 | int old_enable; | 1326 | int old_enable; |
1559 | unsigned long val; | 1327 | unsigned long val; |
1560 | int err; | 1328 | int err; |
@@ -1829,18 +1597,220 @@ static int adm1026_detect(struct i2c_client *client, | |||
1829 | return 0; | 1597 | return 0; |
1830 | } | 1598 | } |
1831 | 1599 | ||
1600 | static void adm1026_print_gpio(struct i2c_client *client) | ||
1601 | { | ||
1602 | struct adm1026_data *data = i2c_get_clientdata(client); | ||
1603 | int i; | ||
1604 | |||
1605 | dev_dbg(&client->dev, "GPIO config is:\n"); | ||
1606 | for (i = 0; i <= 7; ++i) { | ||
1607 | if (data->config2 & (1 << i)) { | ||
1608 | dev_dbg(&client->dev, "\t%sGP%s%d\n", | ||
1609 | data->gpio_config[i] & 0x02 ? "" : "!", | ||
1610 | data->gpio_config[i] & 0x01 ? "OUT" : "IN", | ||
1611 | i); | ||
1612 | } else { | ||
1613 | dev_dbg(&client->dev, "\tFAN%d\n", i); | ||
1614 | } | ||
1615 | } | ||
1616 | for (i = 8; i <= 15; ++i) { | ||
1617 | dev_dbg(&client->dev, "\t%sGP%s%d\n", | ||
1618 | data->gpio_config[i] & 0x02 ? "" : "!", | ||
1619 | data->gpio_config[i] & 0x01 ? "OUT" : "IN", | ||
1620 | i); | ||
1621 | } | ||
1622 | if (data->config3 & CFG3_GPIO16_ENABLE) { | ||
1623 | dev_dbg(&client->dev, "\t%sGP%s16\n", | ||
1624 | data->gpio_config[16] & 0x02 ? "" : "!", | ||
1625 | data->gpio_config[16] & 0x01 ? "OUT" : "IN"); | ||
1626 | } else { | ||
1627 | /* GPIO16 is THERM */ | ||
1628 | dev_dbg(&client->dev, "\tTHERM\n"); | ||
1629 | } | ||
1630 | } | ||
1631 | |||
1632 | static void adm1026_fixup_gpio(struct i2c_client *client) | ||
1633 | { | ||
1634 | struct adm1026_data *data = i2c_get_clientdata(client); | ||
1635 | int i; | ||
1636 | int value; | ||
1637 | |||
1638 | /* Make the changes requested. */ | ||
1639 | /* | ||
1640 | * We may need to unlock/stop monitoring or soft-reset the | ||
1641 | * chip before we can make changes. This hasn't been | ||
1642 | * tested much. FIXME | ||
1643 | */ | ||
1644 | |||
1645 | /* Make outputs */ | ||
1646 | for (i = 0; i <= 16; ++i) { | ||
1647 | if (gpio_output[i] >= 0 && gpio_output[i] <= 16) | ||
1648 | data->gpio_config[gpio_output[i]] |= 0x01; | ||
1649 | /* if GPIO0-7 is output, it isn't a FAN tach */ | ||
1650 | if (gpio_output[i] >= 0 && gpio_output[i] <= 7) | ||
1651 | data->config2 |= 1 << gpio_output[i]; | ||
1652 | } | ||
1653 | |||
1654 | /* Input overrides output */ | ||
1655 | for (i = 0; i <= 16; ++i) { | ||
1656 | if (gpio_input[i] >= 0 && gpio_input[i] <= 16) | ||
1657 | data->gpio_config[gpio_input[i]] &= ~0x01; | ||
1658 | /* if GPIO0-7 is input, it isn't a FAN tach */ | ||
1659 | if (gpio_input[i] >= 0 && gpio_input[i] <= 7) | ||
1660 | data->config2 |= 1 << gpio_input[i]; | ||
1661 | } | ||
1662 | |||
1663 | /* Inverted */ | ||
1664 | for (i = 0; i <= 16; ++i) { | ||
1665 | if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16) | ||
1666 | data->gpio_config[gpio_inverted[i]] &= ~0x02; | ||
1667 | } | ||
1668 | |||
1669 | /* Normal overrides inverted */ | ||
1670 | for (i = 0; i <= 16; ++i) { | ||
1671 | if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16) | ||
1672 | data->gpio_config[gpio_normal[i]] |= 0x02; | ||
1673 | } | ||
1674 | |||
1675 | /* Fan overrides input and output */ | ||
1676 | for (i = 0; i <= 7; ++i) { | ||
1677 | if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7) | ||
1678 | data->config2 &= ~(1 << gpio_fan[i]); | ||
1679 | } | ||
1680 | |||
1681 | /* Write new configs to registers */ | ||
1682 | adm1026_write_value(client, ADM1026_REG_CONFIG2, data->config2); | ||
1683 | data->config3 = (data->config3 & 0x3f) | ||
1684 | | ((data->gpio_config[16] & 0x03) << 6); | ||
1685 | adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3); | ||
1686 | for (i = 15, value = 0; i >= 0; --i) { | ||
1687 | value <<= 2; | ||
1688 | value |= data->gpio_config[i] & 0x03; | ||
1689 | if ((i & 0x03) == 0) { | ||
1690 | adm1026_write_value(client, | ||
1691 | ADM1026_REG_GPIO_CFG_0_3 + i/4, | ||
1692 | value); | ||
1693 | value = 0; | ||
1694 | } | ||
1695 | } | ||
1696 | |||
1697 | /* Print the new config */ | ||
1698 | adm1026_print_gpio(client); | ||
1699 | } | ||
1700 | |||
1701 | static void adm1026_init_client(struct i2c_client *client) | ||
1702 | { | ||
1703 | int value, i; | ||
1704 | struct adm1026_data *data = i2c_get_clientdata(client); | ||
1705 | |||
1706 | dev_dbg(&client->dev, "Initializing device\n"); | ||
1707 | /* Read chip config */ | ||
1708 | data->config1 = adm1026_read_value(client, ADM1026_REG_CONFIG1); | ||
1709 | data->config2 = adm1026_read_value(client, ADM1026_REG_CONFIG2); | ||
1710 | data->config3 = adm1026_read_value(client, ADM1026_REG_CONFIG3); | ||
1711 | |||
1712 | /* Inform user of chip config */ | ||
1713 | dev_dbg(&client->dev, "ADM1026_REG_CONFIG1 is: 0x%02x\n", | ||
1714 | data->config1); | ||
1715 | if ((data->config1 & CFG1_MONITOR) == 0) { | ||
1716 | dev_dbg(&client->dev, | ||
1717 | "Monitoring not currently enabled.\n"); | ||
1718 | } | ||
1719 | if (data->config1 & CFG1_INT_ENABLE) { | ||
1720 | dev_dbg(&client->dev, | ||
1721 | "SMBALERT interrupts are enabled.\n"); | ||
1722 | } | ||
1723 | if (data->config1 & CFG1_AIN8_9) { | ||
1724 | dev_dbg(&client->dev, | ||
1725 | "in8 and in9 enabled. temp3 disabled.\n"); | ||
1726 | } else { | ||
1727 | dev_dbg(&client->dev, | ||
1728 | "temp3 enabled. in8 and in9 disabled.\n"); | ||
1729 | } | ||
1730 | if (data->config1 & CFG1_THERM_HOT) { | ||
1731 | dev_dbg(&client->dev, | ||
1732 | "Automatic THERM, PWM, and temp limits enabled.\n"); | ||
1733 | } | ||
1734 | |||
1735 | if (data->config3 & CFG3_GPIO16_ENABLE) { | ||
1736 | dev_dbg(&client->dev, | ||
1737 | "GPIO16 enabled. THERM pin disabled.\n"); | ||
1738 | } else { | ||
1739 | dev_dbg(&client->dev, | ||
1740 | "THERM pin enabled. GPIO16 disabled.\n"); | ||
1741 | } | ||
1742 | if (data->config3 & CFG3_VREF_250) | ||
1743 | dev_dbg(&client->dev, "Vref is 2.50 Volts.\n"); | ||
1744 | else | ||
1745 | dev_dbg(&client->dev, "Vref is 1.82 Volts.\n"); | ||
1746 | /* Read and pick apart the existing GPIO configuration */ | ||
1747 | value = 0; | ||
1748 | for (i = 0; i <= 15; ++i) { | ||
1749 | if ((i & 0x03) == 0) { | ||
1750 | value = adm1026_read_value(client, | ||
1751 | ADM1026_REG_GPIO_CFG_0_3 + i / 4); | ||
1752 | } | ||
1753 | data->gpio_config[i] = value & 0x03; | ||
1754 | value >>= 2; | ||
1755 | } | ||
1756 | data->gpio_config[16] = (data->config3 >> 6) & 0x03; | ||
1757 | |||
1758 | /* ... and then print it */ | ||
1759 | adm1026_print_gpio(client); | ||
1760 | |||
1761 | /* | ||
1762 | * If the user asks us to reprogram the GPIO config, then | ||
1763 | * do it now. | ||
1764 | */ | ||
1765 | if (gpio_input[0] != -1 || gpio_output[0] != -1 | ||
1766 | || gpio_inverted[0] != -1 || gpio_normal[0] != -1 | ||
1767 | || gpio_fan[0] != -1) { | ||
1768 | adm1026_fixup_gpio(client); | ||
1769 | } | ||
1770 | |||
1771 | /* | ||
1772 | * WE INTENTIONALLY make no changes to the limits, | ||
1773 | * offsets, pwms, fans and zones. If they were | ||
1774 | * configured, we don't want to mess with them. | ||
1775 | * If they weren't, the default is 100% PWM, no | ||
1776 | * control and will suffice until 'sensors -s' | ||
1777 | * can be run by the user. We DO set the default | ||
1778 | * value for pwm1.auto_pwm_min to its maximum | ||
1779 | * so that enabling automatic pwm fan control | ||
1780 | * without first setting a value for pwm1.auto_pwm_min | ||
1781 | * will not result in potentially dangerous fan speed decrease. | ||
1782 | */ | ||
1783 | data->pwm1.auto_pwm_min = 255; | ||
1784 | /* Start monitoring */ | ||
1785 | value = adm1026_read_value(client, ADM1026_REG_CONFIG1); | ||
1786 | /* Set MONITOR, clear interrupt acknowledge and s/w reset */ | ||
1787 | value = (value | CFG1_MONITOR) & (~CFG1_INT_CLEAR & ~CFG1_RESET); | ||
1788 | dev_dbg(&client->dev, "Setting CONFIG to: 0x%02x\n", value); | ||
1789 | data->config1 = value; | ||
1790 | adm1026_write_value(client, ADM1026_REG_CONFIG1, value); | ||
1791 | |||
1792 | /* initialize fan_div[] to hardware defaults */ | ||
1793 | value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3) | | ||
1794 | (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7) << 8); | ||
1795 | for (i = 0; i <= 7; ++i) { | ||
1796 | data->fan_div[i] = DIV_FROM_REG(value & 0x03); | ||
1797 | value >>= 2; | ||
1798 | } | ||
1799 | } | ||
1800 | |||
1832 | static int adm1026_probe(struct i2c_client *client, | 1801 | static int adm1026_probe(struct i2c_client *client, |
1833 | const struct i2c_device_id *id) | 1802 | const struct i2c_device_id *id) |
1834 | { | 1803 | { |
1804 | struct device *dev = &client->dev; | ||
1805 | struct device *hwmon_dev; | ||
1835 | struct adm1026_data *data; | 1806 | struct adm1026_data *data; |
1836 | int err; | ||
1837 | 1807 | ||
1838 | data = devm_kzalloc(&client->dev, sizeof(struct adm1026_data), | 1808 | data = devm_kzalloc(dev, sizeof(struct adm1026_data), GFP_KERNEL); |
1839 | GFP_KERNEL); | ||
1840 | if (!data) | 1809 | if (!data) |
1841 | return -ENOMEM; | 1810 | return -ENOMEM; |
1842 | 1811 | ||
1843 | i2c_set_clientdata(client, data); | 1812 | i2c_set_clientdata(client, data); |
1813 | data->client = client; | ||
1844 | mutex_init(&data->update_lock); | 1814 | mutex_init(&data->update_lock); |
1845 | 1815 | ||
1846 | /* Set the VRM version */ | 1816 | /* Set the VRM version */ |
@@ -1849,48 +1819,34 @@ static int adm1026_probe(struct i2c_client *client, | |||
1849 | /* Initialize the ADM1026 chip */ | 1819 | /* Initialize the ADM1026 chip */ |
1850 | adm1026_init_client(client); | 1820 | adm1026_init_client(client); |
1851 | 1821 | ||
1852 | /* Register sysfs hooks */ | 1822 | /* sysfs hooks */ |
1853 | err = sysfs_create_group(&client->dev.kobj, &adm1026_group); | 1823 | data->groups[0] = &adm1026_group; |
1854 | if (err) | ||
1855 | return err; | ||
1856 | if (data->config1 & CFG1_AIN8_9) | 1824 | if (data->config1 & CFG1_AIN8_9) |
1857 | err = sysfs_create_group(&client->dev.kobj, | 1825 | data->groups[1] = &adm1026_group_in8_9; |
1858 | &adm1026_group_in8_9); | ||
1859 | else | 1826 | else |
1860 | err = sysfs_create_group(&client->dev.kobj, | 1827 | data->groups[1] = &adm1026_group_temp3; |
1861 | &adm1026_group_temp3); | ||
1862 | if (err) | ||
1863 | goto exitremove; | ||
1864 | |||
1865 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
1866 | if (IS_ERR(data->hwmon_dev)) { | ||
1867 | err = PTR_ERR(data->hwmon_dev); | ||
1868 | goto exitremove; | ||
1869 | } | ||
1870 | |||
1871 | return 0; | ||
1872 | 1828 | ||
1873 | /* Error out and cleanup code */ | 1829 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
1874 | exitremove: | 1830 | data, data->groups); |
1875 | sysfs_remove_group(&client->dev.kobj, &adm1026_group); | 1831 | return PTR_ERR_OR_ZERO(hwmon_dev); |
1876 | if (data->config1 & CFG1_AIN8_9) | ||
1877 | sysfs_remove_group(&client->dev.kobj, &adm1026_group_in8_9); | ||
1878 | else | ||
1879 | sysfs_remove_group(&client->dev.kobj, &adm1026_group_temp3); | ||
1880 | return err; | ||
1881 | } | 1832 | } |
1882 | 1833 | ||
1883 | static int adm1026_remove(struct i2c_client *client) | 1834 | static const struct i2c_device_id adm1026_id[] = { |
1884 | { | 1835 | { "adm1026", 0 }, |
1885 | struct adm1026_data *data = i2c_get_clientdata(client); | 1836 | { } |
1886 | hwmon_device_unregister(data->hwmon_dev); | 1837 | }; |
1887 | sysfs_remove_group(&client->dev.kobj, &adm1026_group); | 1838 | MODULE_DEVICE_TABLE(i2c, adm1026_id); |
1888 | if (data->config1 & CFG1_AIN8_9) | 1839 | |
1889 | sysfs_remove_group(&client->dev.kobj, &adm1026_group_in8_9); | 1840 | static struct i2c_driver adm1026_driver = { |
1890 | else | 1841 | .class = I2C_CLASS_HWMON, |
1891 | sysfs_remove_group(&client->dev.kobj, &adm1026_group_temp3); | 1842 | .driver = { |
1892 | return 0; | 1843 | .name = "adm1026", |
1893 | } | 1844 | }, |
1845 | .probe = adm1026_probe, | ||
1846 | .id_table = adm1026_id, | ||
1847 | .detect = adm1026_detect, | ||
1848 | .address_list = normal_i2c, | ||
1849 | }; | ||
1894 | 1850 | ||
1895 | module_i2c_driver(adm1026_driver); | 1851 | module_i2c_driver(adm1026_driver); |
1896 | 1852 | ||
diff --git a/drivers/hwmon/adm1029.c b/drivers/hwmon/adm1029.c index 2804571b269e..8c5cdb560258 100644 --- a/drivers/hwmon/adm1029.c +++ b/drivers/hwmon/adm1029.c | |||
@@ -106,45 +106,11 @@ static const u8 ADM1029_REG_FAN_DIV[] = { | |||
106 | }; | 106 | }; |
107 | 107 | ||
108 | /* | 108 | /* |
109 | * Functions declaration | ||
110 | */ | ||
111 | |||
112 | static int adm1029_probe(struct i2c_client *client, | ||
113 | const struct i2c_device_id *id); | ||
114 | static int adm1029_detect(struct i2c_client *client, | ||
115 | struct i2c_board_info *info); | ||
116 | static int adm1029_remove(struct i2c_client *client); | ||
117 | static struct adm1029_data *adm1029_update_device(struct device *dev); | ||
118 | static int adm1029_init_client(struct i2c_client *client); | ||
119 | |||
120 | /* | ||
121 | * Driver data (common to all clients) | ||
122 | */ | ||
123 | |||
124 | static const struct i2c_device_id adm1029_id[] = { | ||
125 | { "adm1029", 0 }, | ||
126 | { } | ||
127 | }; | ||
128 | MODULE_DEVICE_TABLE(i2c, adm1029_id); | ||
129 | |||
130 | static struct i2c_driver adm1029_driver = { | ||
131 | .class = I2C_CLASS_HWMON, | ||
132 | .driver = { | ||
133 | .name = "adm1029", | ||
134 | }, | ||
135 | .probe = adm1029_probe, | ||
136 | .remove = adm1029_remove, | ||
137 | .id_table = adm1029_id, | ||
138 | .detect = adm1029_detect, | ||
139 | .address_list = normal_i2c, | ||
140 | }; | ||
141 | |||
142 | /* | ||
143 | * Client data (each client gets its own) | 109 | * Client data (each client gets its own) |
144 | */ | 110 | */ |
145 | 111 | ||
146 | struct adm1029_data { | 112 | struct adm1029_data { |
147 | struct device *hwmon_dev; | 113 | struct i2c_client *client; |
148 | struct mutex update_lock; | 114 | struct mutex update_lock; |
149 | char valid; /* zero until following fields are valid */ | 115 | char valid; /* zero until following fields are valid */ |
150 | unsigned long last_updated; /* in jiffies */ | 116 | unsigned long last_updated; /* in jiffies */ |
@@ -156,6 +122,50 @@ struct adm1029_data { | |||
156 | }; | 122 | }; |
157 | 123 | ||
158 | /* | 124 | /* |
125 | * function that update the status of the chips (temperature for example) | ||
126 | */ | ||
127 | static struct adm1029_data *adm1029_update_device(struct device *dev) | ||
128 | { | ||
129 | struct adm1029_data *data = dev_get_drvdata(dev); | ||
130 | struct i2c_client *client = data->client; | ||
131 | |||
132 | mutex_lock(&data->update_lock); | ||
133 | /* | ||
134 | * Use the "cache" Luke, don't recheck values | ||
135 | * if there are already checked not a long time later | ||
136 | */ | ||
137 | if (time_after(jiffies, data->last_updated + HZ * 2) | ||
138 | || !data->valid) { | ||
139 | int nr; | ||
140 | |||
141 | dev_dbg(&client->dev, "Updating adm1029 data\n"); | ||
142 | |||
143 | for (nr = 0; nr < ARRAY_SIZE(ADM1029_REG_TEMP); nr++) { | ||
144 | data->temp[nr] = | ||
145 | i2c_smbus_read_byte_data(client, | ||
146 | ADM1029_REG_TEMP[nr]); | ||
147 | } | ||
148 | for (nr = 0; nr < ARRAY_SIZE(ADM1029_REG_FAN); nr++) { | ||
149 | data->fan[nr] = | ||
150 | i2c_smbus_read_byte_data(client, | ||
151 | ADM1029_REG_FAN[nr]); | ||
152 | } | ||
153 | for (nr = 0; nr < ARRAY_SIZE(ADM1029_REG_FAN_DIV); nr++) { | ||
154 | data->fan_div[nr] = | ||
155 | i2c_smbus_read_byte_data(client, | ||
156 | ADM1029_REG_FAN_DIV[nr]); | ||
157 | } | ||
158 | |||
159 | data->last_updated = jiffies; | ||
160 | data->valid = 1; | ||
161 | } | ||
162 | |||
163 | mutex_unlock(&data->update_lock); | ||
164 | |||
165 | return data; | ||
166 | } | ||
167 | |||
168 | /* | ||
159 | * Sysfs stuff | 169 | * Sysfs stuff |
160 | */ | 170 | */ |
161 | 171 | ||
@@ -197,8 +207,8 @@ show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf) | |||
197 | static ssize_t set_fan_div(struct device *dev, | 207 | static ssize_t set_fan_div(struct device *dev, |
198 | struct device_attribute *devattr, const char *buf, size_t count) | 208 | struct device_attribute *devattr, const char *buf, size_t count) |
199 | { | 209 | { |
200 | struct i2c_client *client = to_i2c_client(dev); | 210 | struct adm1029_data *data = dev_get_drvdata(dev); |
201 | struct adm1029_data *data = i2c_get_clientdata(client); | 211 | struct i2c_client *client = data->client; |
202 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 212 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
203 | u8 reg; | 213 | u8 reg; |
204 | long val; | 214 | long val; |
@@ -270,7 +280,7 @@ static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, | |||
270 | static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, | 280 | static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, |
271 | show_fan_div, set_fan_div, 1); | 281 | show_fan_div, set_fan_div, 1); |
272 | 282 | ||
273 | static struct attribute *adm1029_attributes[] = { | 283 | static struct attribute *adm1029_attrs[] = { |
274 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 284 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
275 | &sensor_dev_attr_temp1_min.dev_attr.attr, | 285 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
276 | &sensor_dev_attr_temp1_max.dev_attr.attr, | 286 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
@@ -289,9 +299,7 @@ static struct attribute *adm1029_attributes[] = { | |||
289 | NULL | 299 | NULL |
290 | }; | 300 | }; |
291 | 301 | ||
292 | static const struct attribute_group adm1029_group = { | 302 | ATTRIBUTE_GROUPS(adm1029); |
293 | .attrs = adm1029_attributes, | ||
294 | }; | ||
295 | 303 | ||
296 | /* | 304 | /* |
297 | * Real code | 305 | * Real code |
@@ -340,48 +348,10 @@ static int adm1029_detect(struct i2c_client *client, | |||
340 | return 0; | 348 | return 0; |
341 | } | 349 | } |
342 | 350 | ||
343 | static int adm1029_probe(struct i2c_client *client, | ||
344 | const struct i2c_device_id *id) | ||
345 | { | ||
346 | struct adm1029_data *data; | ||
347 | int err; | ||
348 | |||
349 | data = devm_kzalloc(&client->dev, sizeof(struct adm1029_data), | ||
350 | GFP_KERNEL); | ||
351 | if (!data) | ||
352 | return -ENOMEM; | ||
353 | |||
354 | i2c_set_clientdata(client, data); | ||
355 | mutex_init(&data->update_lock); | ||
356 | |||
357 | /* | ||
358 | * Initialize the ADM1029 chip | ||
359 | * Check config register | ||
360 | */ | ||
361 | if (adm1029_init_client(client) == 0) | ||
362 | return -ENODEV; | ||
363 | |||
364 | /* Register sysfs hooks */ | ||
365 | err = sysfs_create_group(&client->dev.kobj, &adm1029_group); | ||
366 | if (err) | ||
367 | return err; | ||
368 | |||
369 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
370 | if (IS_ERR(data->hwmon_dev)) { | ||
371 | err = PTR_ERR(data->hwmon_dev); | ||
372 | goto exit_remove_files; | ||
373 | } | ||
374 | |||
375 | return 0; | ||
376 | |||
377 | exit_remove_files: | ||
378 | sysfs_remove_group(&client->dev.kobj, &adm1029_group); | ||
379 | return err; | ||
380 | } | ||
381 | |||
382 | static int adm1029_init_client(struct i2c_client *client) | 351 | static int adm1029_init_client(struct i2c_client *client) |
383 | { | 352 | { |
384 | u8 config; | 353 | u8 config; |
354 | |||
385 | config = i2c_smbus_read_byte_data(client, ADM1029_REG_CONFIG); | 355 | config = i2c_smbus_read_byte_data(client, ADM1029_REG_CONFIG); |
386 | if ((config & 0x10) == 0) { | 356 | if ((config & 0x10) == 0) { |
387 | i2c_smbus_write_byte_data(client, ADM1029_REG_CONFIG, | 357 | i2c_smbus_write_byte_data(client, ADM1029_REG_CONFIG, |
@@ -396,59 +366,49 @@ static int adm1029_init_client(struct i2c_client *client) | |||
396 | return 1; | 366 | return 1; |
397 | } | 367 | } |
398 | 368 | ||
399 | static int adm1029_remove(struct i2c_client *client) | 369 | static int adm1029_probe(struct i2c_client *client, |
370 | const struct i2c_device_id *id) | ||
400 | { | 371 | { |
401 | struct adm1029_data *data = i2c_get_clientdata(client); | 372 | struct device *dev = &client->dev; |
402 | 373 | struct adm1029_data *data; | |
403 | hwmon_device_unregister(data->hwmon_dev); | 374 | struct device *hwmon_dev; |
404 | sysfs_remove_group(&client->dev.kobj, &adm1029_group); | ||
405 | 375 | ||
406 | return 0; | 376 | data = devm_kzalloc(dev, sizeof(struct adm1029_data), GFP_KERNEL); |
407 | } | 377 | if (!data) |
378 | return -ENOMEM; | ||
408 | 379 | ||
409 | /* | 380 | data->client = client; |
410 | * function that update the status of the chips (temperature for example) | 381 | mutex_init(&data->update_lock); |
411 | */ | ||
412 | static struct adm1029_data *adm1029_update_device(struct device *dev) | ||
413 | { | ||
414 | struct i2c_client *client = to_i2c_client(dev); | ||
415 | struct adm1029_data *data = i2c_get_clientdata(client); | ||
416 | 382 | ||
417 | mutex_lock(&data->update_lock); | ||
418 | /* | 383 | /* |
419 | * Use the "cache" Luke, don't recheck values | 384 | * Initialize the ADM1029 chip |
420 | * if there are already checked not a long time later | 385 | * Check config register |
421 | */ | 386 | */ |
422 | if (time_after(jiffies, data->last_updated + HZ * 2) | 387 | if (adm1029_init_client(client) == 0) |
423 | || !data->valid) { | 388 | return -ENODEV; |
424 | int nr; | ||
425 | |||
426 | dev_dbg(&client->dev, "Updating adm1029 data\n"); | ||
427 | |||
428 | for (nr = 0; nr < ARRAY_SIZE(ADM1029_REG_TEMP); nr++) { | ||
429 | data->temp[nr] = | ||
430 | i2c_smbus_read_byte_data(client, | ||
431 | ADM1029_REG_TEMP[nr]); | ||
432 | } | ||
433 | for (nr = 0; nr < ARRAY_SIZE(ADM1029_REG_FAN); nr++) { | ||
434 | data->fan[nr] = | ||
435 | i2c_smbus_read_byte_data(client, | ||
436 | ADM1029_REG_FAN[nr]); | ||
437 | } | ||
438 | for (nr = 0; nr < ARRAY_SIZE(ADM1029_REG_FAN_DIV); nr++) { | ||
439 | data->fan_div[nr] = | ||
440 | i2c_smbus_read_byte_data(client, | ||
441 | ADM1029_REG_FAN_DIV[nr]); | ||
442 | } | ||
443 | 389 | ||
444 | data->last_updated = jiffies; | 390 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
445 | data->valid = 1; | 391 | data, |
446 | } | 392 | adm1029_groups); |
393 | return PTR_ERR_OR_ZERO(hwmon_dev); | ||
394 | } | ||
447 | 395 | ||
448 | mutex_unlock(&data->update_lock); | 396 | static const struct i2c_device_id adm1029_id[] = { |
397 | { "adm1029", 0 }, | ||
398 | { } | ||
399 | }; | ||
400 | MODULE_DEVICE_TABLE(i2c, adm1029_id); | ||
449 | 401 | ||
450 | return data; | 402 | static struct i2c_driver adm1029_driver = { |
451 | } | 403 | .class = I2C_CLASS_HWMON, |
404 | .driver = { | ||
405 | .name = "adm1029", | ||
406 | }, | ||
407 | .probe = adm1029_probe, | ||
408 | .id_table = adm1029_id, | ||
409 | .detect = adm1029_detect, | ||
410 | .address_list = normal_i2c, | ||
411 | }; | ||
452 | 412 | ||
453 | module_i2c_driver(adm1029_driver); | 413 | module_i2c_driver(adm1029_driver); |
454 | 414 | ||
diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c index 51c1a5a165ab..a5818980dad7 100644 --- a/drivers/hwmon/adm1031.c +++ b/drivers/hwmon/adm1031.c | |||
@@ -74,7 +74,8 @@ typedef u8 auto_chan_table_t[8][2]; | |||
74 | 74 | ||
75 | /* Each client has this additional data */ | 75 | /* Each client has this additional data */ |
76 | struct adm1031_data { | 76 | struct adm1031_data { |
77 | struct device *hwmon_dev; | 77 | struct i2c_client *client; |
78 | const struct attribute_group *groups[3]; | ||
78 | struct mutex update_lock; | 79 | struct mutex update_lock; |
79 | int chip_type; | 80 | int chip_type; |
80 | char valid; /* !=0 if following fields are valid */ | 81 | char valid; /* !=0 if following fields are valid */ |
@@ -105,34 +106,6 @@ struct adm1031_data { | |||
105 | s8 temp_crit[3]; | 106 | s8 temp_crit[3]; |
106 | }; | 107 | }; |
107 | 108 | ||
108 | static int adm1031_probe(struct i2c_client *client, | ||
109 | const struct i2c_device_id *id); | ||
110 | static int adm1031_detect(struct i2c_client *client, | ||
111 | struct i2c_board_info *info); | ||
112 | static void adm1031_init_client(struct i2c_client *client); | ||
113 | static int adm1031_remove(struct i2c_client *client); | ||
114 | static struct adm1031_data *adm1031_update_device(struct device *dev); | ||
115 | |||
116 | static const struct i2c_device_id adm1031_id[] = { | ||
117 | { "adm1030", adm1030 }, | ||
118 | { "adm1031", adm1031 }, | ||
119 | { } | ||
120 | }; | ||
121 | MODULE_DEVICE_TABLE(i2c, adm1031_id); | ||
122 | |||
123 | /* This is the driver that will be inserted */ | ||
124 | static struct i2c_driver adm1031_driver = { | ||
125 | .class = I2C_CLASS_HWMON, | ||
126 | .driver = { | ||
127 | .name = "adm1031", | ||
128 | }, | ||
129 | .probe = adm1031_probe, | ||
130 | .remove = adm1031_remove, | ||
131 | .id_table = adm1031_id, | ||
132 | .detect = adm1031_detect, | ||
133 | .address_list = normal_i2c, | ||
134 | }; | ||
135 | |||
136 | static inline u8 adm1031_read_value(struct i2c_client *client, u8 reg) | 109 | static inline u8 adm1031_read_value(struct i2c_client *client, u8 reg) |
137 | { | 110 | { |
138 | return i2c_smbus_read_byte_data(client, reg); | 111 | return i2c_smbus_read_byte_data(client, reg); |
@@ -144,6 +117,96 @@ adm1031_write_value(struct i2c_client *client, u8 reg, unsigned int value) | |||
144 | return i2c_smbus_write_byte_data(client, reg, value); | 117 | return i2c_smbus_write_byte_data(client, reg, value); |
145 | } | 118 | } |
146 | 119 | ||
120 | static struct adm1031_data *adm1031_update_device(struct device *dev) | ||
121 | { | ||
122 | struct adm1031_data *data = dev_get_drvdata(dev); | ||
123 | struct i2c_client *client = data->client; | ||
124 | unsigned long next_update; | ||
125 | int chan; | ||
126 | |||
127 | mutex_lock(&data->update_lock); | ||
128 | |||
129 | next_update = data->last_updated | ||
130 | + msecs_to_jiffies(data->update_interval); | ||
131 | if (time_after(jiffies, next_update) || !data->valid) { | ||
132 | |||
133 | dev_dbg(&client->dev, "Starting adm1031 update\n"); | ||
134 | for (chan = 0; | ||
135 | chan < ((data->chip_type == adm1031) ? 3 : 2); chan++) { | ||
136 | u8 oldh, newh; | ||
137 | |||
138 | oldh = | ||
139 | adm1031_read_value(client, ADM1031_REG_TEMP(chan)); | ||
140 | data->ext_temp[chan] = | ||
141 | adm1031_read_value(client, ADM1031_REG_EXT_TEMP); | ||
142 | newh = | ||
143 | adm1031_read_value(client, ADM1031_REG_TEMP(chan)); | ||
144 | if (newh != oldh) { | ||
145 | data->ext_temp[chan] = | ||
146 | adm1031_read_value(client, | ||
147 | ADM1031_REG_EXT_TEMP); | ||
148 | #ifdef DEBUG | ||
149 | oldh = | ||
150 | adm1031_read_value(client, | ||
151 | ADM1031_REG_TEMP(chan)); | ||
152 | |||
153 | /* oldh is actually newer */ | ||
154 | if (newh != oldh) | ||
155 | dev_warn(&client->dev, | ||
156 | "Remote temperature may be wrong.\n"); | ||
157 | #endif | ||
158 | } | ||
159 | data->temp[chan] = newh; | ||
160 | |||
161 | data->temp_offset[chan] = | ||
162 | adm1031_read_value(client, | ||
163 | ADM1031_REG_TEMP_OFFSET(chan)); | ||
164 | data->temp_min[chan] = | ||
165 | adm1031_read_value(client, | ||
166 | ADM1031_REG_TEMP_MIN(chan)); | ||
167 | data->temp_max[chan] = | ||
168 | adm1031_read_value(client, | ||
169 | ADM1031_REG_TEMP_MAX(chan)); | ||
170 | data->temp_crit[chan] = | ||
171 | adm1031_read_value(client, | ||
172 | ADM1031_REG_TEMP_CRIT(chan)); | ||
173 | data->auto_temp[chan] = | ||
174 | adm1031_read_value(client, | ||
175 | ADM1031_REG_AUTO_TEMP(chan)); | ||
176 | |||
177 | } | ||
178 | |||
179 | data->conf1 = adm1031_read_value(client, ADM1031_REG_CONF1); | ||
180 | data->conf2 = adm1031_read_value(client, ADM1031_REG_CONF2); | ||
181 | |||
182 | data->alarm = adm1031_read_value(client, ADM1031_REG_STATUS(0)) | ||
183 | | (adm1031_read_value(client, ADM1031_REG_STATUS(1)) << 8); | ||
184 | if (data->chip_type == adm1030) | ||
185 | data->alarm &= 0xc0ff; | ||
186 | |||
187 | for (chan = 0; chan < (data->chip_type == adm1030 ? 1 : 2); | ||
188 | chan++) { | ||
189 | data->fan_div[chan] = | ||
190 | adm1031_read_value(client, | ||
191 | ADM1031_REG_FAN_DIV(chan)); | ||
192 | data->fan_min[chan] = | ||
193 | adm1031_read_value(client, | ||
194 | ADM1031_REG_FAN_MIN(chan)); | ||
195 | data->fan[chan] = | ||
196 | adm1031_read_value(client, | ||
197 | ADM1031_REG_FAN_SPEED(chan)); | ||
198 | data->pwm[chan] = | ||
199 | (adm1031_read_value(client, | ||
200 | ADM1031_REG_PWM) >> (4 * chan)) & 0x0f; | ||
201 | } | ||
202 | data->last_updated = jiffies; | ||
203 | data->valid = 1; | ||
204 | } | ||
205 | |||
206 | mutex_unlock(&data->update_lock); | ||
207 | |||
208 | return data; | ||
209 | } | ||
147 | 210 | ||
148 | #define TEMP_TO_REG(val) (((val) < 0 ? ((val - 500) / 1000) : \ | 211 | #define TEMP_TO_REG(val) (((val) < 0 ? ((val - 500) / 1000) : \ |
149 | ((val + 500) / 1000))) | 212 | ((val + 500) / 1000))) |
@@ -280,8 +343,8 @@ static ssize_t | |||
280 | set_fan_auto_channel(struct device *dev, struct device_attribute *attr, | 343 | set_fan_auto_channel(struct device *dev, struct device_attribute *attr, |
281 | const char *buf, size_t count) | 344 | const char *buf, size_t count) |
282 | { | 345 | { |
283 | struct i2c_client *client = to_i2c_client(dev); | 346 | struct adm1031_data *data = dev_get_drvdata(dev); |
284 | struct adm1031_data *data = i2c_get_clientdata(client); | 347 | struct i2c_client *client = data->client; |
285 | int nr = to_sensor_dev_attr(attr)->index; | 348 | int nr = to_sensor_dev_attr(attr)->index; |
286 | long val; | 349 | long val; |
287 | u8 reg; | 350 | u8 reg; |
@@ -355,8 +418,8 @@ static ssize_t | |||
355 | set_auto_temp_min(struct device *dev, struct device_attribute *attr, | 418 | set_auto_temp_min(struct device *dev, struct device_attribute *attr, |
356 | const char *buf, size_t count) | 419 | const char *buf, size_t count) |
357 | { | 420 | { |
358 | struct i2c_client *client = to_i2c_client(dev); | 421 | struct adm1031_data *data = dev_get_drvdata(dev); |
359 | struct adm1031_data *data = i2c_get_clientdata(client); | 422 | struct i2c_client *client = data->client; |
360 | int nr = to_sensor_dev_attr(attr)->index; | 423 | int nr = to_sensor_dev_attr(attr)->index; |
361 | long val; | 424 | long val; |
362 | int ret; | 425 | int ret; |
@@ -385,8 +448,8 @@ static ssize_t | |||
385 | set_auto_temp_max(struct device *dev, struct device_attribute *attr, | 448 | set_auto_temp_max(struct device *dev, struct device_attribute *attr, |
386 | const char *buf, size_t count) | 449 | const char *buf, size_t count) |
387 | { | 450 | { |
388 | struct i2c_client *client = to_i2c_client(dev); | 451 | struct adm1031_data *data = dev_get_drvdata(dev); |
389 | struct adm1031_data *data = i2c_get_clientdata(client); | 452 | struct i2c_client *client = data->client; |
390 | int nr = to_sensor_dev_attr(attr)->index; | 453 | int nr = to_sensor_dev_attr(attr)->index; |
391 | long val; | 454 | long val; |
392 | int ret; | 455 | int ret; |
@@ -428,8 +491,8 @@ static ssize_t show_pwm(struct device *dev, | |||
428 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | 491 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, |
429 | const char *buf, size_t count) | 492 | const char *buf, size_t count) |
430 | { | 493 | { |
431 | struct i2c_client *client = to_i2c_client(dev); | 494 | struct adm1031_data *data = dev_get_drvdata(dev); |
432 | struct adm1031_data *data = i2c_get_clientdata(client); | 495 | struct i2c_client *client = data->client; |
433 | int nr = to_sensor_dev_attr(attr)->index; | 496 | int nr = to_sensor_dev_attr(attr)->index; |
434 | long val; | 497 | long val; |
435 | int ret, reg; | 498 | int ret, reg; |
@@ -541,8 +604,8 @@ static ssize_t show_fan_min(struct device *dev, | |||
541 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | 604 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, |
542 | const char *buf, size_t count) | 605 | const char *buf, size_t count) |
543 | { | 606 | { |
544 | struct i2c_client *client = to_i2c_client(dev); | 607 | struct adm1031_data *data = dev_get_drvdata(dev); |
545 | struct adm1031_data *data = i2c_get_clientdata(client); | 608 | struct i2c_client *client = data->client; |
546 | int nr = to_sensor_dev_attr(attr)->index; | 609 | int nr = to_sensor_dev_attr(attr)->index; |
547 | long val; | 610 | long val; |
548 | int ret; | 611 | int ret; |
@@ -565,8 +628,8 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | |||
565 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | 628 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, |
566 | const char *buf, size_t count) | 629 | const char *buf, size_t count) |
567 | { | 630 | { |
568 | struct i2c_client *client = to_i2c_client(dev); | 631 | struct adm1031_data *data = dev_get_drvdata(dev); |
569 | struct adm1031_data *data = i2c_get_clientdata(client); | 632 | struct i2c_client *client = data->client; |
570 | int nr = to_sensor_dev_attr(attr)->index; | 633 | int nr = to_sensor_dev_attr(attr)->index; |
571 | long val; | 634 | long val; |
572 | u8 tmp; | 635 | u8 tmp; |
@@ -667,8 +730,8 @@ static ssize_t set_temp_offset(struct device *dev, | |||
667 | struct device_attribute *attr, const char *buf, | 730 | struct device_attribute *attr, const char *buf, |
668 | size_t count) | 731 | size_t count) |
669 | { | 732 | { |
670 | struct i2c_client *client = to_i2c_client(dev); | 733 | struct adm1031_data *data = dev_get_drvdata(dev); |
671 | struct adm1031_data *data = i2c_get_clientdata(client); | 734 | struct i2c_client *client = data->client; |
672 | int nr = to_sensor_dev_attr(attr)->index; | 735 | int nr = to_sensor_dev_attr(attr)->index; |
673 | long val; | 736 | long val; |
674 | int ret; | 737 | int ret; |
@@ -688,8 +751,8 @@ static ssize_t set_temp_offset(struct device *dev, | |||
688 | static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | 751 | static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, |
689 | const char *buf, size_t count) | 752 | const char *buf, size_t count) |
690 | { | 753 | { |
691 | struct i2c_client *client = to_i2c_client(dev); | 754 | struct adm1031_data *data = dev_get_drvdata(dev); |
692 | struct adm1031_data *data = i2c_get_clientdata(client); | 755 | struct i2c_client *client = data->client; |
693 | int nr = to_sensor_dev_attr(attr)->index; | 756 | int nr = to_sensor_dev_attr(attr)->index; |
694 | long val; | 757 | long val; |
695 | int ret; | 758 | int ret; |
@@ -709,8 +772,8 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | |||
709 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | 772 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, |
710 | const char *buf, size_t count) | 773 | const char *buf, size_t count) |
711 | { | 774 | { |
712 | struct i2c_client *client = to_i2c_client(dev); | 775 | struct adm1031_data *data = dev_get_drvdata(dev); |
713 | struct adm1031_data *data = i2c_get_clientdata(client); | 776 | struct i2c_client *client = data->client; |
714 | int nr = to_sensor_dev_attr(attr)->index; | 777 | int nr = to_sensor_dev_attr(attr)->index; |
715 | long val; | 778 | long val; |
716 | int ret; | 779 | int ret; |
@@ -730,8 +793,8 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
730 | static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr, | 793 | static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr, |
731 | const char *buf, size_t count) | 794 | const char *buf, size_t count) |
732 | { | 795 | { |
733 | struct i2c_client *client = to_i2c_client(dev); | 796 | struct adm1031_data *data = dev_get_drvdata(dev); |
734 | struct adm1031_data *data = i2c_get_clientdata(client); | 797 | struct i2c_client *client = data->client; |
735 | int nr = to_sensor_dev_attr(attr)->index; | 798 | int nr = to_sensor_dev_attr(attr)->index; |
736 | long val; | 799 | long val; |
737 | int ret; | 800 | int ret; |
@@ -807,8 +870,7 @@ static const unsigned int update_intervals[] = { | |||
807 | static ssize_t show_update_interval(struct device *dev, | 870 | static ssize_t show_update_interval(struct device *dev, |
808 | struct device_attribute *attr, char *buf) | 871 | struct device_attribute *attr, char *buf) |
809 | { | 872 | { |
810 | struct i2c_client *client = to_i2c_client(dev); | 873 | struct adm1031_data *data = dev_get_drvdata(dev); |
811 | struct adm1031_data *data = i2c_get_clientdata(client); | ||
812 | 874 | ||
813 | return sprintf(buf, "%u\n", data->update_interval); | 875 | return sprintf(buf, "%u\n", data->update_interval); |
814 | } | 876 | } |
@@ -817,8 +879,8 @@ static ssize_t set_update_interval(struct device *dev, | |||
817 | struct device_attribute *attr, | 879 | struct device_attribute *attr, |
818 | const char *buf, size_t count) | 880 | const char *buf, size_t count) |
819 | { | 881 | { |
820 | struct i2c_client *client = to_i2c_client(dev); | 882 | struct adm1031_data *data = dev_get_drvdata(dev); |
821 | struct adm1031_data *data = i2c_get_clientdata(client); | 883 | struct i2c_client *client = data->client; |
822 | unsigned long val; | 884 | unsigned long val; |
823 | int i, err; | 885 | int i, err; |
824 | u8 reg; | 886 | u8 reg; |
@@ -950,64 +1012,6 @@ static int adm1031_detect(struct i2c_client *client, | |||
950 | return 0; | 1012 | return 0; |
951 | } | 1013 | } |
952 | 1014 | ||
953 | static int adm1031_probe(struct i2c_client *client, | ||
954 | const struct i2c_device_id *id) | ||
955 | { | ||
956 | struct adm1031_data *data; | ||
957 | int err; | ||
958 | |||
959 | data = devm_kzalloc(&client->dev, sizeof(struct adm1031_data), | ||
960 | GFP_KERNEL); | ||
961 | if (!data) | ||
962 | return -ENOMEM; | ||
963 | |||
964 | i2c_set_clientdata(client, data); | ||
965 | data->chip_type = id->driver_data; | ||
966 | mutex_init(&data->update_lock); | ||
967 | |||
968 | if (data->chip_type == adm1030) | ||
969 | data->chan_select_table = &auto_channel_select_table_adm1030; | ||
970 | else | ||
971 | data->chan_select_table = &auto_channel_select_table_adm1031; | ||
972 | |||
973 | /* Initialize the ADM1031 chip */ | ||
974 | adm1031_init_client(client); | ||
975 | |||
976 | /* Register sysfs hooks */ | ||
977 | err = sysfs_create_group(&client->dev.kobj, &adm1031_group); | ||
978 | if (err) | ||
979 | return err; | ||
980 | |||
981 | if (data->chip_type == adm1031) { | ||
982 | err = sysfs_create_group(&client->dev.kobj, &adm1031_group_opt); | ||
983 | if (err) | ||
984 | goto exit_remove; | ||
985 | } | ||
986 | |||
987 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
988 | if (IS_ERR(data->hwmon_dev)) { | ||
989 | err = PTR_ERR(data->hwmon_dev); | ||
990 | goto exit_remove; | ||
991 | } | ||
992 | |||
993 | return 0; | ||
994 | |||
995 | exit_remove: | ||
996 | sysfs_remove_group(&client->dev.kobj, &adm1031_group); | ||
997 | sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt); | ||
998 | return err; | ||
999 | } | ||
1000 | |||
1001 | static int adm1031_remove(struct i2c_client *client) | ||
1002 | { | ||
1003 | struct adm1031_data *data = i2c_get_clientdata(client); | ||
1004 | |||
1005 | hwmon_device_unregister(data->hwmon_dev); | ||
1006 | sysfs_remove_group(&client->dev.kobj, &adm1031_group); | ||
1007 | sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt); | ||
1008 | return 0; | ||
1009 | } | ||
1010 | |||
1011 | static void adm1031_init_client(struct i2c_client *client) | 1015 | static void adm1031_init_client(struct i2c_client *client) |
1012 | { | 1016 | { |
1013 | unsigned int read_val; | 1017 | unsigned int read_val; |
@@ -1039,96 +1043,57 @@ static void adm1031_init_client(struct i2c_client *client) | |||
1039 | data->update_interval = update_intervals[i]; | 1043 | data->update_interval = update_intervals[i]; |
1040 | } | 1044 | } |
1041 | 1045 | ||
1042 | static struct adm1031_data *adm1031_update_device(struct device *dev) | 1046 | static int adm1031_probe(struct i2c_client *client, |
1047 | const struct i2c_device_id *id) | ||
1043 | { | 1048 | { |
1044 | struct i2c_client *client = to_i2c_client(dev); | 1049 | struct device *dev = &client->dev; |
1045 | struct adm1031_data *data = i2c_get_clientdata(client); | 1050 | struct device *hwmon_dev; |
1046 | unsigned long next_update; | 1051 | struct adm1031_data *data; |
1047 | int chan; | ||
1048 | |||
1049 | mutex_lock(&data->update_lock); | ||
1050 | |||
1051 | next_update = data->last_updated | ||
1052 | + msecs_to_jiffies(data->update_interval); | ||
1053 | if (time_after(jiffies, next_update) || !data->valid) { | ||
1054 | |||
1055 | dev_dbg(&client->dev, "Starting adm1031 update\n"); | ||
1056 | for (chan = 0; | ||
1057 | chan < ((data->chip_type == adm1031) ? 3 : 2); chan++) { | ||
1058 | u8 oldh, newh; | ||
1059 | |||
1060 | oldh = | ||
1061 | adm1031_read_value(client, ADM1031_REG_TEMP(chan)); | ||
1062 | data->ext_temp[chan] = | ||
1063 | adm1031_read_value(client, ADM1031_REG_EXT_TEMP); | ||
1064 | newh = | ||
1065 | adm1031_read_value(client, ADM1031_REG_TEMP(chan)); | ||
1066 | if (newh != oldh) { | ||
1067 | data->ext_temp[chan] = | ||
1068 | adm1031_read_value(client, | ||
1069 | ADM1031_REG_EXT_TEMP); | ||
1070 | #ifdef DEBUG | ||
1071 | oldh = | ||
1072 | adm1031_read_value(client, | ||
1073 | ADM1031_REG_TEMP(chan)); | ||
1074 | 1052 | ||
1075 | /* oldh is actually newer */ | 1053 | data = devm_kzalloc(dev, sizeof(struct adm1031_data), GFP_KERNEL); |
1076 | if (newh != oldh) | 1054 | if (!data) |
1077 | dev_warn(&client->dev, | 1055 | return -ENOMEM; |
1078 | "Remote temperature may be wrong.\n"); | ||
1079 | #endif | ||
1080 | } | ||
1081 | data->temp[chan] = newh; | ||
1082 | 1056 | ||
1083 | data->temp_offset[chan] = | 1057 | i2c_set_clientdata(client, data); |
1084 | adm1031_read_value(client, | 1058 | data->client = client; |
1085 | ADM1031_REG_TEMP_OFFSET(chan)); | 1059 | data->chip_type = id->driver_data; |
1086 | data->temp_min[chan] = | 1060 | mutex_init(&data->update_lock); |
1087 | adm1031_read_value(client, | ||
1088 | ADM1031_REG_TEMP_MIN(chan)); | ||
1089 | data->temp_max[chan] = | ||
1090 | adm1031_read_value(client, | ||
1091 | ADM1031_REG_TEMP_MAX(chan)); | ||
1092 | data->temp_crit[chan] = | ||
1093 | adm1031_read_value(client, | ||
1094 | ADM1031_REG_TEMP_CRIT(chan)); | ||
1095 | data->auto_temp[chan] = | ||
1096 | adm1031_read_value(client, | ||
1097 | ADM1031_REG_AUTO_TEMP(chan)); | ||
1098 | 1061 | ||
1099 | } | 1062 | if (data->chip_type == adm1030) |
1063 | data->chan_select_table = &auto_channel_select_table_adm1030; | ||
1064 | else | ||
1065 | data->chan_select_table = &auto_channel_select_table_adm1031; | ||
1100 | 1066 | ||
1101 | data->conf1 = adm1031_read_value(client, ADM1031_REG_CONF1); | 1067 | /* Initialize the ADM1031 chip */ |
1102 | data->conf2 = adm1031_read_value(client, ADM1031_REG_CONF2); | 1068 | adm1031_init_client(client); |
1103 | 1069 | ||
1104 | data->alarm = adm1031_read_value(client, ADM1031_REG_STATUS(0)) | 1070 | /* sysfs hooks */ |
1105 | | (adm1031_read_value(client, ADM1031_REG_STATUS(1)) << 8); | 1071 | data->groups[0] = &adm1031_group; |
1106 | if (data->chip_type == adm1030) | 1072 | if (data->chip_type == adm1031) |
1107 | data->alarm &= 0xc0ff; | 1073 | data->groups[1] = &adm1031_group_opt; |
1108 | 1074 | ||
1109 | for (chan = 0; chan < (data->chip_type == adm1030 ? 1 : 2); | 1075 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
1110 | chan++) { | 1076 | data, data->groups); |
1111 | data->fan_div[chan] = | 1077 | return PTR_ERR_OR_ZERO(hwmon_dev); |
1112 | adm1031_read_value(client, | 1078 | } |
1113 | ADM1031_REG_FAN_DIV(chan)); | ||
1114 | data->fan_min[chan] = | ||
1115 | adm1031_read_value(client, | ||
1116 | ADM1031_REG_FAN_MIN(chan)); | ||
1117 | data->fan[chan] = | ||
1118 | adm1031_read_value(client, | ||
1119 | ADM1031_REG_FAN_SPEED(chan)); | ||
1120 | data->pwm[chan] = | ||
1121 | (adm1031_read_value(client, | ||
1122 | ADM1031_REG_PWM) >> (4 * chan)) & 0x0f; | ||
1123 | } | ||
1124 | data->last_updated = jiffies; | ||
1125 | data->valid = 1; | ||
1126 | } | ||
1127 | 1079 | ||
1128 | mutex_unlock(&data->update_lock); | 1080 | static const struct i2c_device_id adm1031_id[] = { |
1081 | { "adm1030", adm1030 }, | ||
1082 | { "adm1031", adm1031 }, | ||
1083 | { } | ||
1084 | }; | ||
1085 | MODULE_DEVICE_TABLE(i2c, adm1031_id); | ||
1129 | 1086 | ||
1130 | return data; | 1087 | static struct i2c_driver adm1031_driver = { |
1131 | } | 1088 | .class = I2C_CLASS_HWMON, |
1089 | .driver = { | ||
1090 | .name = "adm1031", | ||
1091 | }, | ||
1092 | .probe = adm1031_probe, | ||
1093 | .id_table = adm1031_id, | ||
1094 | .detect = adm1031_detect, | ||
1095 | .address_list = normal_i2c, | ||
1096 | }; | ||
1132 | 1097 | ||
1133 | module_i2c_driver(adm1031_driver); | 1098 | module_i2c_driver(adm1031_driver); |
1134 | 1099 | ||
diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c index 086d02a9ecdc..98114cef1e43 100644 --- a/drivers/hwmon/adm9240.c +++ b/drivers/hwmon/adm9240.c | |||
@@ -130,38 +130,9 @@ static inline unsigned int AOUT_FROM_REG(u8 reg) | |||
130 | return SCALE(reg, 1250, 255); | 130 | return SCALE(reg, 1250, 255); |
131 | } | 131 | } |
132 | 132 | ||
133 | static int adm9240_probe(struct i2c_client *client, | ||
134 | const struct i2c_device_id *id); | ||
135 | static int adm9240_detect(struct i2c_client *client, | ||
136 | struct i2c_board_info *info); | ||
137 | static void adm9240_init_client(struct i2c_client *client); | ||
138 | static int adm9240_remove(struct i2c_client *client); | ||
139 | static struct adm9240_data *adm9240_update_device(struct device *dev); | ||
140 | |||
141 | /* driver data */ | ||
142 | static const struct i2c_device_id adm9240_id[] = { | ||
143 | { "adm9240", adm9240 }, | ||
144 | { "ds1780", ds1780 }, | ||
145 | { "lm81", lm81 }, | ||
146 | { } | ||
147 | }; | ||
148 | MODULE_DEVICE_TABLE(i2c, adm9240_id); | ||
149 | |||
150 | static struct i2c_driver adm9240_driver = { | ||
151 | .class = I2C_CLASS_HWMON, | ||
152 | .driver = { | ||
153 | .name = "adm9240", | ||
154 | }, | ||
155 | .probe = adm9240_probe, | ||
156 | .remove = adm9240_remove, | ||
157 | .id_table = adm9240_id, | ||
158 | .detect = adm9240_detect, | ||
159 | .address_list = normal_i2c, | ||
160 | }; | ||
161 | |||
162 | /* per client data */ | 133 | /* per client data */ |
163 | struct adm9240_data { | 134 | struct adm9240_data { |
164 | struct device *hwmon_dev; | 135 | struct i2c_client *client; |
165 | struct mutex update_lock; | 136 | struct mutex update_lock; |
166 | char valid; | 137 | char valid; |
167 | unsigned long last_updated_measure; | 138 | unsigned long last_updated_measure; |
@@ -181,6 +152,110 @@ struct adm9240_data { | |||
181 | u8 vrm; /* -- vrm set on startup, no accessor */ | 152 | u8 vrm; /* -- vrm set on startup, no accessor */ |
182 | }; | 153 | }; |
183 | 154 | ||
155 | /* write new fan div, callers must hold data->update_lock */ | ||
156 | static void adm9240_write_fan_div(struct i2c_client *client, int nr, | ||
157 | u8 fan_div) | ||
158 | { | ||
159 | u8 reg, old, shift = (nr + 2) * 2; | ||
160 | |||
161 | reg = i2c_smbus_read_byte_data(client, ADM9240_REG_VID_FAN_DIV); | ||
162 | old = (reg >> shift) & 3; | ||
163 | reg &= ~(3 << shift); | ||
164 | reg |= (fan_div << shift); | ||
165 | i2c_smbus_write_byte_data(client, ADM9240_REG_VID_FAN_DIV, reg); | ||
166 | dev_dbg(&client->dev, | ||
167 | "fan%d clock divider changed from %u to %u\n", | ||
168 | nr + 1, 1 << old, 1 << fan_div); | ||
169 | } | ||
170 | |||
171 | static struct adm9240_data *adm9240_update_device(struct device *dev) | ||
172 | { | ||
173 | struct adm9240_data *data = dev_get_drvdata(dev); | ||
174 | struct i2c_client *client = data->client; | ||
175 | int i; | ||
176 | |||
177 | mutex_lock(&data->update_lock); | ||
178 | |||
179 | /* minimum measurement cycle: 1.75 seconds */ | ||
180 | if (time_after(jiffies, data->last_updated_measure + (HZ * 7 / 4)) | ||
181 | || !data->valid) { | ||
182 | |||
183 | for (i = 0; i < 6; i++) { /* read voltages */ | ||
184 | data->in[i] = i2c_smbus_read_byte_data(client, | ||
185 | ADM9240_REG_IN(i)); | ||
186 | } | ||
187 | data->alarms = i2c_smbus_read_byte_data(client, | ||
188 | ADM9240_REG_INT(0)) | | ||
189 | i2c_smbus_read_byte_data(client, | ||
190 | ADM9240_REG_INT(1)) << 8; | ||
191 | |||
192 | /* | ||
193 | * read temperature: assume temperature changes less than | ||
194 | * 0.5'C per two measurement cycles thus ignore possible | ||
195 | * but unlikely aliasing error on lsb reading. --Grant | ||
196 | */ | ||
197 | data->temp = ((i2c_smbus_read_byte_data(client, | ||
198 | ADM9240_REG_TEMP) << 8) | | ||
199 | i2c_smbus_read_byte_data(client, | ||
200 | ADM9240_REG_TEMP_CONF)) / 128; | ||
201 | |||
202 | for (i = 0; i < 2; i++) { /* read fans */ | ||
203 | data->fan[i] = i2c_smbus_read_byte_data(client, | ||
204 | ADM9240_REG_FAN(i)); | ||
205 | |||
206 | /* adjust fan clock divider on overflow */ | ||
207 | if (data->valid && data->fan[i] == 255 && | ||
208 | data->fan_div[i] < 3) { | ||
209 | |||
210 | adm9240_write_fan_div(client, i, | ||
211 | ++data->fan_div[i]); | ||
212 | |||
213 | /* adjust fan_min if active, but not to 0 */ | ||
214 | if (data->fan_min[i] < 255 && | ||
215 | data->fan_min[i] >= 2) | ||
216 | data->fan_min[i] /= 2; | ||
217 | } | ||
218 | } | ||
219 | data->last_updated_measure = jiffies; | ||
220 | } | ||
221 | |||
222 | /* minimum config reading cycle: 300 seconds */ | ||
223 | if (time_after(jiffies, data->last_updated_config + (HZ * 300)) | ||
224 | || !data->valid) { | ||
225 | |||
226 | for (i = 0; i < 6; i++) { | ||
227 | data->in_min[i] = i2c_smbus_read_byte_data(client, | ||
228 | ADM9240_REG_IN_MIN(i)); | ||
229 | data->in_max[i] = i2c_smbus_read_byte_data(client, | ||
230 | ADM9240_REG_IN_MAX(i)); | ||
231 | } | ||
232 | for (i = 0; i < 2; i++) { | ||
233 | data->fan_min[i] = i2c_smbus_read_byte_data(client, | ||
234 | ADM9240_REG_FAN_MIN(i)); | ||
235 | } | ||
236 | data->temp_max[0] = i2c_smbus_read_byte_data(client, | ||
237 | ADM9240_REG_TEMP_MAX(0)); | ||
238 | data->temp_max[1] = i2c_smbus_read_byte_data(client, | ||
239 | ADM9240_REG_TEMP_MAX(1)); | ||
240 | |||
241 | /* read fan divs and 5-bit VID */ | ||
242 | i = i2c_smbus_read_byte_data(client, ADM9240_REG_VID_FAN_DIV); | ||
243 | data->fan_div[0] = (i >> 4) & 3; | ||
244 | data->fan_div[1] = (i >> 6) & 3; | ||
245 | data->vid = i & 0x0f; | ||
246 | data->vid |= (i2c_smbus_read_byte_data(client, | ||
247 | ADM9240_REG_VID4) & 1) << 4; | ||
248 | /* read analog out */ | ||
249 | data->aout = i2c_smbus_read_byte_data(client, | ||
250 | ADM9240_REG_ANALOG_OUT); | ||
251 | |||
252 | data->last_updated_config = jiffies; | ||
253 | data->valid = 1; | ||
254 | } | ||
255 | mutex_unlock(&data->update_lock); | ||
256 | return data; | ||
257 | } | ||
258 | |||
184 | /*** sysfs accessors ***/ | 259 | /*** sysfs accessors ***/ |
185 | 260 | ||
186 | /* temperature */ | 261 | /* temperature */ |
@@ -203,8 +278,8 @@ static ssize_t set_max(struct device *dev, struct device_attribute *devattr, | |||
203 | const char *buf, size_t count) | 278 | const char *buf, size_t count) |
204 | { | 279 | { |
205 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 280 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
206 | struct i2c_client *client = to_i2c_client(dev); | 281 | struct adm9240_data *data = dev_get_drvdata(dev); |
207 | struct adm9240_data *data = i2c_get_clientdata(client); | 282 | struct i2c_client *client = data->client; |
208 | long val; | 283 | long val; |
209 | int err; | 284 | int err; |
210 | 285 | ||
@@ -259,8 +334,8 @@ static ssize_t set_in_min(struct device *dev, | |||
259 | const char *buf, size_t count) | 334 | const char *buf, size_t count) |
260 | { | 335 | { |
261 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 336 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
262 | struct i2c_client *client = to_i2c_client(dev); | 337 | struct adm9240_data *data = dev_get_drvdata(dev); |
263 | struct adm9240_data *data = i2c_get_clientdata(client); | 338 | struct i2c_client *client = data->client; |
264 | unsigned long val; | 339 | unsigned long val; |
265 | int err; | 340 | int err; |
266 | 341 | ||
@@ -281,8 +356,8 @@ static ssize_t set_in_max(struct device *dev, | |||
281 | const char *buf, size_t count) | 356 | const char *buf, size_t count) |
282 | { | 357 | { |
283 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 358 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
284 | struct i2c_client *client = to_i2c_client(dev); | 359 | struct adm9240_data *data = dev_get_drvdata(dev); |
285 | struct adm9240_data *data = i2c_get_clientdata(client); | 360 | struct i2c_client *client = data->client; |
286 | unsigned long val; | 361 | unsigned long val; |
287 | int err; | 362 | int err; |
288 | 363 | ||
@@ -340,22 +415,6 @@ static ssize_t show_fan_div(struct device *dev, | |||
340 | return sprintf(buf, "%d\n", 1 << data->fan_div[attr->index]); | 415 | return sprintf(buf, "%d\n", 1 << data->fan_div[attr->index]); |
341 | } | 416 | } |
342 | 417 | ||
343 | /* write new fan div, callers must hold data->update_lock */ | ||
344 | static void adm9240_write_fan_div(struct i2c_client *client, int nr, | ||
345 | u8 fan_div) | ||
346 | { | ||
347 | u8 reg, old, shift = (nr + 2) * 2; | ||
348 | |||
349 | reg = i2c_smbus_read_byte_data(client, ADM9240_REG_VID_FAN_DIV); | ||
350 | old = (reg >> shift) & 3; | ||
351 | reg &= ~(3 << shift); | ||
352 | reg |= (fan_div << shift); | ||
353 | i2c_smbus_write_byte_data(client, ADM9240_REG_VID_FAN_DIV, reg); | ||
354 | dev_dbg(&client->dev, | ||
355 | "fan%d clock divider changed from %u to %u\n", | ||
356 | nr + 1, 1 << old, 1 << fan_div); | ||
357 | } | ||
358 | |||
359 | /* | 418 | /* |
360 | * set fan speed low limit: | 419 | * set fan speed low limit: |
361 | * | 420 | * |
@@ -372,8 +431,8 @@ static ssize_t set_fan_min(struct device *dev, | |||
372 | const char *buf, size_t count) | 431 | const char *buf, size_t count) |
373 | { | 432 | { |
374 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 433 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
375 | struct i2c_client *client = to_i2c_client(dev); | 434 | struct adm9240_data *data = dev_get_drvdata(dev); |
376 | struct adm9240_data *data = i2c_get_clientdata(client); | 435 | struct i2c_client *client = data->client; |
377 | int nr = attr->index; | 436 | int nr = attr->index; |
378 | u8 new_div; | 437 | u8 new_div; |
379 | unsigned long val; | 438 | unsigned long val; |
@@ -485,8 +544,8 @@ static ssize_t set_aout(struct device *dev, | |||
485 | struct device_attribute *attr, | 544 | struct device_attribute *attr, |
486 | const char *buf, size_t count) | 545 | const char *buf, size_t count) |
487 | { | 546 | { |
488 | struct i2c_client *client = to_i2c_client(dev); | 547 | struct adm9240_data *data = dev_get_drvdata(dev); |
489 | struct adm9240_data *data = i2c_get_clientdata(client); | 548 | struct i2c_client *client = data->client; |
490 | long val; | 549 | long val; |
491 | int err; | 550 | int err; |
492 | 551 | ||
@@ -506,8 +565,8 @@ static ssize_t chassis_clear(struct device *dev, | |||
506 | struct device_attribute *attr, | 565 | struct device_attribute *attr, |
507 | const char *buf, size_t count) | 566 | const char *buf, size_t count) |
508 | { | 567 | { |
509 | struct i2c_client *client = to_i2c_client(dev); | 568 | struct adm9240_data *data = dev_get_drvdata(dev); |
510 | struct adm9240_data *data = i2c_get_clientdata(client); | 569 | struct i2c_client *client = data->client; |
511 | unsigned long val; | 570 | unsigned long val; |
512 | 571 | ||
513 | if (kstrtoul(buf, 10, &val) || val != 0) | 572 | if (kstrtoul(buf, 10, &val) || val != 0) |
@@ -524,7 +583,7 @@ static ssize_t chassis_clear(struct device *dev, | |||
524 | static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR, show_alarm, | 583 | static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR, show_alarm, |
525 | chassis_clear, 12); | 584 | chassis_clear, 12); |
526 | 585 | ||
527 | static struct attribute *adm9240_attributes[] = { | 586 | static struct attribute *adm9240_attrs[] = { |
528 | &sensor_dev_attr_in0_input.dev_attr.attr, | 587 | &sensor_dev_attr_in0_input.dev_attr.attr, |
529 | &sensor_dev_attr_in0_min.dev_attr.attr, | 588 | &sensor_dev_attr_in0_min.dev_attr.attr, |
530 | &sensor_dev_attr_in0_max.dev_attr.attr, | 589 | &sensor_dev_attr_in0_max.dev_attr.attr, |
@@ -568,9 +627,7 @@ static struct attribute *adm9240_attributes[] = { | |||
568 | NULL | 627 | NULL |
569 | }; | 628 | }; |
570 | 629 | ||
571 | static const struct attribute_group adm9240_group = { | 630 | ATTRIBUTE_GROUPS(adm9240); |
572 | .attrs = adm9240_attributes, | ||
573 | }; | ||
574 | 631 | ||
575 | 632 | ||
576 | /*** sensor chip detect and driver install ***/ | 633 | /*** sensor chip detect and driver install ***/ |
@@ -620,49 +677,6 @@ static int adm9240_detect(struct i2c_client *new_client, | |||
620 | return 0; | 677 | return 0; |
621 | } | 678 | } |
622 | 679 | ||
623 | static int adm9240_probe(struct i2c_client *new_client, | ||
624 | const struct i2c_device_id *id) | ||
625 | { | ||
626 | struct adm9240_data *data; | ||
627 | int err; | ||
628 | |||
629 | data = devm_kzalloc(&new_client->dev, sizeof(*data), GFP_KERNEL); | ||
630 | if (!data) | ||
631 | return -ENOMEM; | ||
632 | |||
633 | i2c_set_clientdata(new_client, data); | ||
634 | mutex_init(&data->update_lock); | ||
635 | |||
636 | adm9240_init_client(new_client); | ||
637 | |||
638 | /* populate sysfs filesystem */ | ||
639 | err = sysfs_create_group(&new_client->dev.kobj, &adm9240_group); | ||
640 | if (err) | ||
641 | return err; | ||
642 | |||
643 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | ||
644 | if (IS_ERR(data->hwmon_dev)) { | ||
645 | err = PTR_ERR(data->hwmon_dev); | ||
646 | goto exit_remove; | ||
647 | } | ||
648 | |||
649 | return 0; | ||
650 | |||
651 | exit_remove: | ||
652 | sysfs_remove_group(&new_client->dev.kobj, &adm9240_group); | ||
653 | return err; | ||
654 | } | ||
655 | |||
656 | static int adm9240_remove(struct i2c_client *client) | ||
657 | { | ||
658 | struct adm9240_data *data = i2c_get_clientdata(client); | ||
659 | |||
660 | hwmon_device_unregister(data->hwmon_dev); | ||
661 | sysfs_remove_group(&client->dev.kobj, &adm9240_group); | ||
662 | |||
663 | return 0; | ||
664 | } | ||
665 | |||
666 | static void adm9240_init_client(struct i2c_client *client) | 680 | static void adm9240_init_client(struct i2c_client *client) |
667 | { | 681 | { |
668 | struct adm9240_data *data = i2c_get_clientdata(client); | 682 | struct adm9240_data *data = i2c_get_clientdata(client); |
@@ -705,93 +719,48 @@ static void adm9240_init_client(struct i2c_client *client) | |||
705 | } | 719 | } |
706 | } | 720 | } |
707 | 721 | ||
708 | static struct adm9240_data *adm9240_update_device(struct device *dev) | 722 | static int adm9240_probe(struct i2c_client *new_client, |
723 | const struct i2c_device_id *id) | ||
709 | { | 724 | { |
710 | struct i2c_client *client = to_i2c_client(dev); | 725 | struct device *dev = &new_client->dev; |
711 | struct adm9240_data *data = i2c_get_clientdata(client); | 726 | struct device *hwmon_dev; |
712 | int i; | 727 | struct adm9240_data *data; |
713 | |||
714 | mutex_lock(&data->update_lock); | ||
715 | |||
716 | /* minimum measurement cycle: 1.75 seconds */ | ||
717 | if (time_after(jiffies, data->last_updated_measure + (HZ * 7 / 4)) | ||
718 | || !data->valid) { | ||
719 | |||
720 | for (i = 0; i < 6; i++) { /* read voltages */ | ||
721 | data->in[i] = i2c_smbus_read_byte_data(client, | ||
722 | ADM9240_REG_IN(i)); | ||
723 | } | ||
724 | data->alarms = i2c_smbus_read_byte_data(client, | ||
725 | ADM9240_REG_INT(0)) | | ||
726 | i2c_smbus_read_byte_data(client, | ||
727 | ADM9240_REG_INT(1)) << 8; | ||
728 | |||
729 | /* | ||
730 | * read temperature: assume temperature changes less than | ||
731 | * 0.5'C per two measurement cycles thus ignore possible | ||
732 | * but unlikely aliasing error on lsb reading. --Grant | ||
733 | */ | ||
734 | data->temp = ((i2c_smbus_read_byte_data(client, | ||
735 | ADM9240_REG_TEMP) << 8) | | ||
736 | i2c_smbus_read_byte_data(client, | ||
737 | ADM9240_REG_TEMP_CONF)) / 128; | ||
738 | |||
739 | for (i = 0; i < 2; i++) { /* read fans */ | ||
740 | data->fan[i] = i2c_smbus_read_byte_data(client, | ||
741 | ADM9240_REG_FAN(i)); | ||
742 | |||
743 | /* adjust fan clock divider on overflow */ | ||
744 | if (data->valid && data->fan[i] == 255 && | ||
745 | data->fan_div[i] < 3) { | ||
746 | 728 | ||
747 | adm9240_write_fan_div(client, i, | 729 | data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); |
748 | ++data->fan_div[i]); | 730 | if (!data) |
731 | return -ENOMEM; | ||
749 | 732 | ||
750 | /* adjust fan_min if active, but not to 0 */ | 733 | i2c_set_clientdata(new_client, data); |
751 | if (data->fan_min[i] < 255 && | 734 | data->client = new_client; |
752 | data->fan_min[i] >= 2) | 735 | mutex_init(&data->update_lock); |
753 | data->fan_min[i] /= 2; | ||
754 | } | ||
755 | } | ||
756 | data->last_updated_measure = jiffies; | ||
757 | } | ||
758 | 736 | ||
759 | /* minimum config reading cycle: 300 seconds */ | 737 | adm9240_init_client(new_client); |
760 | if (time_after(jiffies, data->last_updated_config + (HZ * 300)) | ||
761 | || !data->valid) { | ||
762 | 738 | ||
763 | for (i = 0; i < 6; i++) { | 739 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, |
764 | data->in_min[i] = i2c_smbus_read_byte_data(client, | 740 | new_client->name, |
765 | ADM9240_REG_IN_MIN(i)); | 741 | data, |
766 | data->in_max[i] = i2c_smbus_read_byte_data(client, | 742 | adm9240_groups); |
767 | ADM9240_REG_IN_MAX(i)); | 743 | return PTR_ERR_OR_ZERO(hwmon_dev); |
768 | } | 744 | } |
769 | for (i = 0; i < 2; i++) { | ||
770 | data->fan_min[i] = i2c_smbus_read_byte_data(client, | ||
771 | ADM9240_REG_FAN_MIN(i)); | ||
772 | } | ||
773 | data->temp_max[0] = i2c_smbus_read_byte_data(client, | ||
774 | ADM9240_REG_TEMP_MAX(0)); | ||
775 | data->temp_max[1] = i2c_smbus_read_byte_data(client, | ||
776 | ADM9240_REG_TEMP_MAX(1)); | ||
777 | 745 | ||
778 | /* read fan divs and 5-bit VID */ | 746 | static const struct i2c_device_id adm9240_id[] = { |
779 | i = i2c_smbus_read_byte_data(client, ADM9240_REG_VID_FAN_DIV); | 747 | { "adm9240", adm9240 }, |
780 | data->fan_div[0] = (i >> 4) & 3; | 748 | { "ds1780", ds1780 }, |
781 | data->fan_div[1] = (i >> 6) & 3; | 749 | { "lm81", lm81 }, |
782 | data->vid = i & 0x0f; | 750 | { } |
783 | data->vid |= (i2c_smbus_read_byte_data(client, | 751 | }; |
784 | ADM9240_REG_VID4) & 1) << 4; | 752 | MODULE_DEVICE_TABLE(i2c, adm9240_id); |
785 | /* read analog out */ | ||
786 | data->aout = i2c_smbus_read_byte_data(client, | ||
787 | ADM9240_REG_ANALOG_OUT); | ||
788 | 753 | ||
789 | data->last_updated_config = jiffies; | 754 | static struct i2c_driver adm9240_driver = { |
790 | data->valid = 1; | 755 | .class = I2C_CLASS_HWMON, |
791 | } | 756 | .driver = { |
792 | mutex_unlock(&data->update_lock); | 757 | .name = "adm9240", |
793 | return data; | 758 | }, |
794 | } | 759 | .probe = adm9240_probe, |
760 | .id_table = adm9240_id, | ||
761 | .detect = adm9240_detect, | ||
762 | .address_list = normal_i2c, | ||
763 | }; | ||
795 | 764 | ||
796 | module_i2c_driver(adm9240_driver); | 765 | module_i2c_driver(adm9240_driver); |
797 | 766 | ||
diff --git a/drivers/hwmon/ads1015.c b/drivers/hwmon/ads1015.c index 7f9dc2f86b63..22e0c926989d 100644 --- a/drivers/hwmon/ads1015.c +++ b/drivers/hwmon/ads1015.c | |||
@@ -198,7 +198,7 @@ static int ads1015_get_channels_config_of(struct i2c_client *client) | |||
198 | } | 198 | } |
199 | 199 | ||
200 | channel = be32_to_cpup(property); | 200 | channel = be32_to_cpup(property); |
201 | if (channel > ADS1015_CHANNELS) { | 201 | if (channel >= ADS1015_CHANNELS) { |
202 | dev_err(&client->dev, | 202 | dev_err(&client->dev, |
203 | "invalid channel index %d on %s\n", | 203 | "invalid channel index %d on %s\n", |
204 | channel, node->full_name); | 204 | channel, node->full_name); |
diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c index 7092c78f814f..a622d40eec17 100644 --- a/drivers/hwmon/ads7828.c +++ b/drivers/hwmon/ads7828.c | |||
@@ -50,7 +50,7 @@ enum ads7828_chips { ads7828, ads7830 }; | |||
50 | 50 | ||
51 | /* Client specific data */ | 51 | /* Client specific data */ |
52 | struct ads7828_data { | 52 | struct ads7828_data { |
53 | struct device *hwmon_dev; | 53 | struct i2c_client *client; |
54 | struct mutex update_lock; /* Mutex protecting updates */ | 54 | struct mutex update_lock; /* Mutex protecting updates */ |
55 | unsigned long last_updated; /* Last updated time (in jiffies) */ | 55 | unsigned long last_updated; /* Last updated time (in jiffies) */ |
56 | u16 adc_input[ADS7828_NCH]; /* ADS7828_NCH samples */ | 56 | u16 adc_input[ADS7828_NCH]; /* ADS7828_NCH samples */ |
@@ -72,8 +72,8 @@ static inline u8 ads7828_cmd_byte(u8 cmd, int ch) | |||
72 | /* Update data for the device (all 8 channels) */ | 72 | /* Update data for the device (all 8 channels) */ |
73 | static struct ads7828_data *ads7828_update_device(struct device *dev) | 73 | static struct ads7828_data *ads7828_update_device(struct device *dev) |
74 | { | 74 | { |
75 | struct i2c_client *client = to_i2c_client(dev); | 75 | struct ads7828_data *data = dev_get_drvdata(dev); |
76 | struct ads7828_data *data = i2c_get_clientdata(client); | 76 | struct i2c_client *client = data->client; |
77 | 77 | ||
78 | mutex_lock(&data->update_lock); | 78 | mutex_lock(&data->update_lock); |
79 | 79 | ||
@@ -116,7 +116,7 @@ static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, ads7828_show_in, NULL, 5); | |||
116 | static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, ads7828_show_in, NULL, 6); | 116 | static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, ads7828_show_in, NULL, 6); |
117 | static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, ads7828_show_in, NULL, 7); | 117 | static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, ads7828_show_in, NULL, 7); |
118 | 118 | ||
119 | static struct attribute *ads7828_attributes[] = { | 119 | static struct attribute *ads7828_attrs[] = { |
120 | &sensor_dev_attr_in0_input.dev_attr.attr, | 120 | &sensor_dev_attr_in0_input.dev_attr.attr, |
121 | &sensor_dev_attr_in1_input.dev_attr.attr, | 121 | &sensor_dev_attr_in1_input.dev_attr.attr, |
122 | &sensor_dev_attr_in2_input.dev_attr.attr, | 122 | &sensor_dev_attr_in2_input.dev_attr.attr, |
@@ -128,29 +128,17 @@ static struct attribute *ads7828_attributes[] = { | |||
128 | NULL | 128 | NULL |
129 | }; | 129 | }; |
130 | 130 | ||
131 | static const struct attribute_group ads7828_group = { | 131 | ATTRIBUTE_GROUPS(ads7828); |
132 | .attrs = ads7828_attributes, | ||
133 | }; | ||
134 | |||
135 | static int ads7828_remove(struct i2c_client *client) | ||
136 | { | ||
137 | struct ads7828_data *data = i2c_get_clientdata(client); | ||
138 | |||
139 | hwmon_device_unregister(data->hwmon_dev); | ||
140 | sysfs_remove_group(&client->dev.kobj, &ads7828_group); | ||
141 | |||
142 | return 0; | ||
143 | } | ||
144 | 132 | ||
145 | static int ads7828_probe(struct i2c_client *client, | 133 | static int ads7828_probe(struct i2c_client *client, |
146 | const struct i2c_device_id *id) | 134 | const struct i2c_device_id *id) |
147 | { | 135 | { |
148 | struct ads7828_platform_data *pdata = dev_get_platdata(&client->dev); | 136 | struct device *dev = &client->dev; |
137 | struct ads7828_platform_data *pdata = dev_get_platdata(dev); | ||
149 | struct ads7828_data *data; | 138 | struct ads7828_data *data; |
150 | int err; | 139 | struct device *hwmon_dev; |
151 | 140 | ||
152 | data = devm_kzalloc(&client->dev, sizeof(struct ads7828_data), | 141 | data = devm_kzalloc(dev, sizeof(struct ads7828_data), GFP_KERNEL); |
153 | GFP_KERNEL); | ||
154 | if (!data) | 142 | if (!data) |
155 | return -ENOMEM; | 143 | return -ENOMEM; |
156 | 144 | ||
@@ -182,24 +170,13 @@ static int ads7828_probe(struct i2c_client *client, | |||
182 | if (!data->diff_input) | 170 | if (!data->diff_input) |
183 | data->cmd_byte |= ADS7828_CMD_SD_SE; | 171 | data->cmd_byte |= ADS7828_CMD_SD_SE; |
184 | 172 | ||
185 | i2c_set_clientdata(client, data); | 173 | data->client = client; |
186 | mutex_init(&data->update_lock); | 174 | mutex_init(&data->update_lock); |
187 | 175 | ||
188 | err = sysfs_create_group(&client->dev.kobj, &ads7828_group); | 176 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
189 | if (err) | 177 | data, |
190 | return err; | 178 | ads7828_groups); |
191 | 179 | return PTR_ERR_OR_ZERO(hwmon_dev); | |
192 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
193 | if (IS_ERR(data->hwmon_dev)) { | ||
194 | err = PTR_ERR(data->hwmon_dev); | ||
195 | goto error; | ||
196 | } | ||
197 | |||
198 | return 0; | ||
199 | |||
200 | error: | ||
201 | sysfs_remove_group(&client->dev.kobj, &ads7828_group); | ||
202 | return err; | ||
203 | } | 180 | } |
204 | 181 | ||
205 | static const struct i2c_device_id ads7828_device_ids[] = { | 182 | static const struct i2c_device_id ads7828_device_ids[] = { |
@@ -216,7 +193,6 @@ static struct i2c_driver ads7828_driver = { | |||
216 | 193 | ||
217 | .id_table = ads7828_device_ids, | 194 | .id_table = ads7828_device_ids, |
218 | .probe = ads7828_probe, | 195 | .probe = ads7828_probe, |
219 | .remove = ads7828_remove, | ||
220 | }; | 196 | }; |
221 | 197 | ||
222 | module_i2c_driver(ads7828_driver); | 198 | module_i2c_driver(ads7828_driver); |
diff --git a/drivers/hwmon/adt7411.c b/drivers/hwmon/adt7411.c index d9299dee37d1..827c03703128 100644 --- a/drivers/hwmon/adt7411.c +++ b/drivers/hwmon/adt7411.c | |||
@@ -51,7 +51,7 @@ struct adt7411_data { | |||
51 | struct mutex update_lock; | 51 | struct mutex update_lock; |
52 | unsigned long next_update; | 52 | unsigned long next_update; |
53 | int vref_cached; | 53 | int vref_cached; |
54 | struct device *hwmon_dev; | 54 | struct i2c_client *client; |
55 | }; | 55 | }; |
56 | 56 | ||
57 | /* | 57 | /* |
@@ -111,7 +111,8 @@ static int adt7411_modify_bit(struct i2c_client *client, u8 reg, u8 bit, | |||
111 | static ssize_t adt7411_show_vdd(struct device *dev, | 111 | static ssize_t adt7411_show_vdd(struct device *dev, |
112 | struct device_attribute *attr, char *buf) | 112 | struct device_attribute *attr, char *buf) |
113 | { | 113 | { |
114 | struct i2c_client *client = to_i2c_client(dev); | 114 | struct adt7411_data *data = dev_get_drvdata(dev); |
115 | struct i2c_client *client = data->client; | ||
115 | int ret = adt7411_read_10_bit(client, ADT7411_REG_INT_TEMP_VDD_LSB, | 116 | int ret = adt7411_read_10_bit(client, ADT7411_REG_INT_TEMP_VDD_LSB, |
116 | ADT7411_REG_VDD_MSB, 2); | 117 | ADT7411_REG_VDD_MSB, 2); |
117 | 118 | ||
@@ -121,7 +122,8 @@ static ssize_t adt7411_show_vdd(struct device *dev, | |||
121 | static ssize_t adt7411_show_temp(struct device *dev, | 122 | static ssize_t adt7411_show_temp(struct device *dev, |
122 | struct device_attribute *attr, char *buf) | 123 | struct device_attribute *attr, char *buf) |
123 | { | 124 | { |
124 | struct i2c_client *client = to_i2c_client(dev); | 125 | struct adt7411_data *data = dev_get_drvdata(dev); |
126 | struct i2c_client *client = data->client; | ||
125 | int val = adt7411_read_10_bit(client, ADT7411_REG_INT_TEMP_VDD_LSB, | 127 | int val = adt7411_read_10_bit(client, ADT7411_REG_INT_TEMP_VDD_LSB, |
126 | ADT7411_REG_INT_TEMP_MSB, 0); | 128 | ADT7411_REG_INT_TEMP_MSB, 0); |
127 | 129 | ||
@@ -137,8 +139,8 @@ static ssize_t adt7411_show_input(struct device *dev, | |||
137 | struct device_attribute *attr, char *buf) | 139 | struct device_attribute *attr, char *buf) |
138 | { | 140 | { |
139 | int nr = to_sensor_dev_attr(attr)->index; | 141 | int nr = to_sensor_dev_attr(attr)->index; |
140 | struct i2c_client *client = to_i2c_client(dev); | 142 | struct adt7411_data *data = dev_get_drvdata(dev); |
141 | struct adt7411_data *data = i2c_get_clientdata(client); | 143 | struct i2c_client *client = data->client; |
142 | int val; | 144 | int val; |
143 | u8 lsb_reg, lsb_shift; | 145 | u8 lsb_reg, lsb_shift; |
144 | 146 | ||
@@ -180,7 +182,8 @@ static ssize_t adt7411_show_bit(struct device *dev, | |||
180 | struct device_attribute *attr, char *buf) | 182 | struct device_attribute *attr, char *buf) |
181 | { | 183 | { |
182 | struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); | 184 | struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); |
183 | struct i2c_client *client = to_i2c_client(dev); | 185 | struct adt7411_data *data = dev_get_drvdata(dev); |
186 | struct i2c_client *client = data->client; | ||
184 | int ret = i2c_smbus_read_byte_data(client, attr2->index); | 187 | int ret = i2c_smbus_read_byte_data(client, attr2->index); |
185 | 188 | ||
186 | return ret < 0 ? ret : sprintf(buf, "%u\n", !!(ret & attr2->nr)); | 189 | return ret < 0 ? ret : sprintf(buf, "%u\n", !!(ret & attr2->nr)); |
@@ -191,8 +194,8 @@ static ssize_t adt7411_set_bit(struct device *dev, | |||
191 | size_t count) | 194 | size_t count) |
192 | { | 195 | { |
193 | struct sensor_device_attribute_2 *s_attr2 = to_sensor_dev_attr_2(attr); | 196 | struct sensor_device_attribute_2 *s_attr2 = to_sensor_dev_attr_2(attr); |
194 | struct i2c_client *client = to_i2c_client(dev); | 197 | struct adt7411_data *data = dev_get_drvdata(dev); |
195 | struct adt7411_data *data = i2c_get_clientdata(client); | 198 | struct i2c_client *client = data->client; |
196 | int ret; | 199 | int ret; |
197 | unsigned long flag; | 200 | unsigned long flag; |
198 | 201 | ||
@@ -245,9 +248,7 @@ static struct attribute *adt7411_attrs[] = { | |||
245 | NULL | 248 | NULL |
246 | }; | 249 | }; |
247 | 250 | ||
248 | static const struct attribute_group adt7411_attr_grp = { | 251 | ATTRIBUTE_GROUPS(adt7411); |
249 | .attrs = adt7411_attrs, | ||
250 | }; | ||
251 | 252 | ||
252 | static int adt7411_detect(struct i2c_client *client, | 253 | static int adt7411_detect(struct i2c_client *client, |
253 | struct i2c_board_info *info) | 254 | struct i2c_board_info *info) |
@@ -281,14 +282,17 @@ static int adt7411_detect(struct i2c_client *client, | |||
281 | static int adt7411_probe(struct i2c_client *client, | 282 | static int adt7411_probe(struct i2c_client *client, |
282 | const struct i2c_device_id *id) | 283 | const struct i2c_device_id *id) |
283 | { | 284 | { |
285 | struct device *dev = &client->dev; | ||
284 | struct adt7411_data *data; | 286 | struct adt7411_data *data; |
287 | struct device *hwmon_dev; | ||
285 | int ret; | 288 | int ret; |
286 | 289 | ||
287 | data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); | 290 | data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); |
288 | if (!data) | 291 | if (!data) |
289 | return -ENOMEM; | 292 | return -ENOMEM; |
290 | 293 | ||
291 | i2c_set_clientdata(client, data); | 294 | i2c_set_clientdata(client, data); |
295 | data->client = client; | ||
292 | mutex_init(&data->device_lock); | 296 | mutex_init(&data->device_lock); |
293 | mutex_init(&data->update_lock); | 297 | mutex_init(&data->update_lock); |
294 | 298 | ||
@@ -300,32 +304,10 @@ static int adt7411_probe(struct i2c_client *client, | |||
300 | /* force update on first occasion */ | 304 | /* force update on first occasion */ |
301 | data->next_update = jiffies; | 305 | data->next_update = jiffies; |
302 | 306 | ||
303 | ret = sysfs_create_group(&client->dev.kobj, &adt7411_attr_grp); | 307 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
304 | if (ret) | 308 | data, |
305 | return ret; | 309 | adt7411_groups); |
306 | 310 | return PTR_ERR_OR_ZERO(hwmon_dev); | |
307 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
308 | if (IS_ERR(data->hwmon_dev)) { | ||
309 | ret = PTR_ERR(data->hwmon_dev); | ||
310 | goto exit_remove; | ||
311 | } | ||
312 | |||
313 | dev_info(&client->dev, "successfully registered\n"); | ||
314 | |||
315 | return 0; | ||
316 | |||
317 | exit_remove: | ||
318 | sysfs_remove_group(&client->dev.kobj, &adt7411_attr_grp); | ||
319 | return ret; | ||
320 | } | ||
321 | |||
322 | static int adt7411_remove(struct i2c_client *client) | ||
323 | { | ||
324 | struct adt7411_data *data = i2c_get_clientdata(client); | ||
325 | |||
326 | hwmon_device_unregister(data->hwmon_dev); | ||
327 | sysfs_remove_group(&client->dev.kobj, &adt7411_attr_grp); | ||
328 | return 0; | ||
329 | } | 311 | } |
330 | 312 | ||
331 | static const struct i2c_device_id adt7411_id[] = { | 313 | static const struct i2c_device_id adt7411_id[] = { |
@@ -339,7 +321,6 @@ static struct i2c_driver adt7411_driver = { | |||
339 | .name = "adt7411", | 321 | .name = "adt7411", |
340 | }, | 322 | }, |
341 | .probe = adt7411_probe, | 323 | .probe = adt7411_probe, |
342 | .remove = adt7411_remove, | ||
343 | .id_table = adt7411_id, | 324 | .id_table = adt7411_id, |
344 | .detect = adt7411_detect, | 325 | .detect = adt7411_detect, |
345 | .address_list = normal_i2c, | 326 | .address_list = normal_i2c, |
diff --git a/drivers/hwmon/adt7462.c b/drivers/hwmon/adt7462.c index 562cc3881d33..5929e126da63 100644 --- a/drivers/hwmon/adt7462.c +++ b/drivers/hwmon/adt7462.c | |||
@@ -202,8 +202,7 @@ static const unsigned short normal_i2c[] = { 0x58, 0x5C, I2C_CLIENT_END }; | |||
202 | (((value) & prefix##_MASK) >> prefix##_SHIFT) | 202 | (((value) & prefix##_MASK) >> prefix##_SHIFT) |
203 | 203 | ||
204 | struct adt7462_data { | 204 | struct adt7462_data { |
205 | struct device *hwmon_dev; | 205 | struct i2c_client *client; |
206 | struct attribute_group attrs; | ||
207 | struct mutex lock; | 206 | struct mutex lock; |
208 | char sensors_valid; | 207 | char sensors_valid; |
209 | char limits_valid; | 208 | char limits_valid; |
@@ -232,30 +231,6 @@ struct adt7462_data { | |||
232 | u8 alarms[ADT7462_ALARM_REG_COUNT]; | 231 | u8 alarms[ADT7462_ALARM_REG_COUNT]; |
233 | }; | 232 | }; |
234 | 233 | ||
235 | static int adt7462_probe(struct i2c_client *client, | ||
236 | const struct i2c_device_id *id); | ||
237 | static int adt7462_detect(struct i2c_client *client, | ||
238 | struct i2c_board_info *info); | ||
239 | static int adt7462_remove(struct i2c_client *client); | ||
240 | |||
241 | static const struct i2c_device_id adt7462_id[] = { | ||
242 | { "adt7462", 0 }, | ||
243 | { } | ||
244 | }; | ||
245 | MODULE_DEVICE_TABLE(i2c, adt7462_id); | ||
246 | |||
247 | static struct i2c_driver adt7462_driver = { | ||
248 | .class = I2C_CLASS_HWMON, | ||
249 | .driver = { | ||
250 | .name = "adt7462", | ||
251 | }, | ||
252 | .probe = adt7462_probe, | ||
253 | .remove = adt7462_remove, | ||
254 | .id_table = adt7462_id, | ||
255 | .detect = adt7462_detect, | ||
256 | .address_list = normal_i2c, | ||
257 | }; | ||
258 | |||
259 | /* | 234 | /* |
260 | * 16-bit registers on the ADT7462 are low-byte first. The data sheet says | 235 | * 16-bit registers on the ADT7462 are low-byte first. The data sheet says |
261 | * that the low byte must be read before the high byte. | 236 | * that the low byte must be read before the high byte. |
@@ -705,8 +680,8 @@ static int find_trange_value(int trange) | |||
705 | 680 | ||
706 | static struct adt7462_data *adt7462_update_device(struct device *dev) | 681 | static struct adt7462_data *adt7462_update_device(struct device *dev) |
707 | { | 682 | { |
708 | struct i2c_client *client = to_i2c_client(dev); | 683 | struct adt7462_data *data = dev_get_drvdata(dev); |
709 | struct adt7462_data *data = i2c_get_clientdata(client); | 684 | struct i2c_client *client = data->client; |
710 | unsigned long local_jiffies = jiffies; | 685 | unsigned long local_jiffies = jiffies; |
711 | int i; | 686 | int i; |
712 | 687 | ||
@@ -828,8 +803,8 @@ static ssize_t set_temp_min(struct device *dev, | |||
828 | size_t count) | 803 | size_t count) |
829 | { | 804 | { |
830 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 805 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
831 | struct i2c_client *client = to_i2c_client(dev); | 806 | struct adt7462_data *data = dev_get_drvdata(dev); |
832 | struct adt7462_data *data = i2c_get_clientdata(client); | 807 | struct i2c_client *client = data->client; |
833 | long temp; | 808 | long temp; |
834 | 809 | ||
835 | if (kstrtol(buf, 10, &temp) || !temp_enabled(data, attr->index)) | 810 | if (kstrtol(buf, 10, &temp) || !temp_enabled(data, attr->index)) |
@@ -866,8 +841,8 @@ static ssize_t set_temp_max(struct device *dev, | |||
866 | size_t count) | 841 | size_t count) |
867 | { | 842 | { |
868 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 843 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
869 | struct i2c_client *client = to_i2c_client(dev); | 844 | struct adt7462_data *data = dev_get_drvdata(dev); |
870 | struct adt7462_data *data = i2c_get_clientdata(client); | 845 | struct i2c_client *client = data->client; |
871 | long temp; | 846 | long temp; |
872 | 847 | ||
873 | if (kstrtol(buf, 10, &temp) || !temp_enabled(data, attr->index)) | 848 | if (kstrtol(buf, 10, &temp) || !temp_enabled(data, attr->index)) |
@@ -929,8 +904,8 @@ static ssize_t set_volt_max(struct device *dev, | |||
929 | size_t count) | 904 | size_t count) |
930 | { | 905 | { |
931 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 906 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
932 | struct i2c_client *client = to_i2c_client(dev); | 907 | struct adt7462_data *data = dev_get_drvdata(dev); |
933 | struct adt7462_data *data = i2c_get_clientdata(client); | 908 | struct i2c_client *client = data->client; |
934 | int x = voltage_multiplier(data, attr->index); | 909 | int x = voltage_multiplier(data, attr->index); |
935 | long temp; | 910 | long temp; |
936 | 911 | ||
@@ -971,8 +946,8 @@ static ssize_t set_volt_min(struct device *dev, | |||
971 | size_t count) | 946 | size_t count) |
972 | { | 947 | { |
973 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 948 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
974 | struct i2c_client *client = to_i2c_client(dev); | 949 | struct adt7462_data *data = dev_get_drvdata(dev); |
975 | struct adt7462_data *data = i2c_get_clientdata(client); | 950 | struct i2c_client *client = data->client; |
976 | int x = voltage_multiplier(data, attr->index); | 951 | int x = voltage_multiplier(data, attr->index); |
977 | long temp; | 952 | long temp; |
978 | 953 | ||
@@ -1061,8 +1036,8 @@ static ssize_t set_fan_min(struct device *dev, | |||
1061 | const char *buf, size_t count) | 1036 | const char *buf, size_t count) |
1062 | { | 1037 | { |
1063 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 1038 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
1064 | struct i2c_client *client = to_i2c_client(dev); | 1039 | struct adt7462_data *data = dev_get_drvdata(dev); |
1065 | struct adt7462_data *data = i2c_get_clientdata(client); | 1040 | struct i2c_client *client = data->client; |
1066 | long temp; | 1041 | long temp; |
1067 | 1042 | ||
1068 | if (kstrtol(buf, 10, &temp) || !temp || | 1043 | if (kstrtol(buf, 10, &temp) || !temp || |
@@ -1109,8 +1084,8 @@ static ssize_t set_force_pwm_max(struct device *dev, | |||
1109 | const char *buf, | 1084 | const char *buf, |
1110 | size_t count) | 1085 | size_t count) |
1111 | { | 1086 | { |
1112 | struct i2c_client *client = to_i2c_client(dev); | 1087 | struct adt7462_data *data = dev_get_drvdata(dev); |
1113 | struct adt7462_data *data = i2c_get_clientdata(client); | 1088 | struct i2c_client *client = data->client; |
1114 | long temp; | 1089 | long temp; |
1115 | u8 reg; | 1090 | u8 reg; |
1116 | 1091 | ||
@@ -1142,8 +1117,8 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, | |||
1142 | const char *buf, size_t count) | 1117 | const char *buf, size_t count) |
1143 | { | 1118 | { |
1144 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 1119 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
1145 | struct i2c_client *client = to_i2c_client(dev); | 1120 | struct adt7462_data *data = dev_get_drvdata(dev); |
1146 | struct adt7462_data *data = i2c_get_clientdata(client); | 1121 | struct i2c_client *client = data->client; |
1147 | long temp; | 1122 | long temp; |
1148 | 1123 | ||
1149 | if (kstrtol(buf, 10, &temp)) | 1124 | if (kstrtol(buf, 10, &temp)) |
@@ -1172,8 +1147,8 @@ static ssize_t set_pwm_max(struct device *dev, | |||
1172 | const char *buf, | 1147 | const char *buf, |
1173 | size_t count) | 1148 | size_t count) |
1174 | { | 1149 | { |
1175 | struct i2c_client *client = to_i2c_client(dev); | 1150 | struct adt7462_data *data = dev_get_drvdata(dev); |
1176 | struct adt7462_data *data = i2c_get_clientdata(client); | 1151 | struct i2c_client *client = data->client; |
1177 | long temp; | 1152 | long temp; |
1178 | 1153 | ||
1179 | if (kstrtol(buf, 10, &temp)) | 1154 | if (kstrtol(buf, 10, &temp)) |
@@ -1204,8 +1179,8 @@ static ssize_t set_pwm_min(struct device *dev, | |||
1204 | size_t count) | 1179 | size_t count) |
1205 | { | 1180 | { |
1206 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 1181 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
1207 | struct i2c_client *client = to_i2c_client(dev); | 1182 | struct adt7462_data *data = dev_get_drvdata(dev); |
1208 | struct adt7462_data *data = i2c_get_clientdata(client); | 1183 | struct i2c_client *client = data->client; |
1209 | long temp; | 1184 | long temp; |
1210 | 1185 | ||
1211 | if (kstrtol(buf, 10, &temp)) | 1186 | if (kstrtol(buf, 10, &temp)) |
@@ -1238,8 +1213,8 @@ static ssize_t set_pwm_hyst(struct device *dev, | |||
1238 | size_t count) | 1213 | size_t count) |
1239 | { | 1214 | { |
1240 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 1215 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
1241 | struct i2c_client *client = to_i2c_client(dev); | 1216 | struct adt7462_data *data = dev_get_drvdata(dev); |
1242 | struct adt7462_data *data = i2c_get_clientdata(client); | 1217 | struct i2c_client *client = data->client; |
1243 | long temp; | 1218 | long temp; |
1244 | 1219 | ||
1245 | if (kstrtol(buf, 10, &temp)) | 1220 | if (kstrtol(buf, 10, &temp)) |
@@ -1283,8 +1258,8 @@ static ssize_t set_pwm_tmax(struct device *dev, | |||
1283 | { | 1258 | { |
1284 | int temp; | 1259 | int temp; |
1285 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 1260 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
1286 | struct i2c_client *client = to_i2c_client(dev); | 1261 | struct adt7462_data *data = dev_get_drvdata(dev); |
1287 | struct adt7462_data *data = i2c_get_clientdata(client); | 1262 | struct i2c_client *client = data->client; |
1288 | int tmin, trange_value; | 1263 | int tmin, trange_value; |
1289 | long trange; | 1264 | long trange; |
1290 | 1265 | ||
@@ -1324,8 +1299,8 @@ static ssize_t set_pwm_tmin(struct device *dev, | |||
1324 | size_t count) | 1299 | size_t count) |
1325 | { | 1300 | { |
1326 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 1301 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
1327 | struct i2c_client *client = to_i2c_client(dev); | 1302 | struct adt7462_data *data = dev_get_drvdata(dev); |
1328 | struct adt7462_data *data = i2c_get_clientdata(client); | 1303 | struct i2c_client *client = data->client; |
1329 | long temp; | 1304 | long temp; |
1330 | 1305 | ||
1331 | if (kstrtol(buf, 10, &temp)) | 1306 | if (kstrtol(buf, 10, &temp)) |
@@ -1381,8 +1356,8 @@ static ssize_t set_pwm_auto(struct device *dev, | |||
1381 | size_t count) | 1356 | size_t count) |
1382 | { | 1357 | { |
1383 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 1358 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
1384 | struct i2c_client *client = to_i2c_client(dev); | 1359 | struct adt7462_data *data = dev_get_drvdata(dev); |
1385 | struct adt7462_data *data = i2c_get_clientdata(client); | 1360 | struct i2c_client *client = data->client; |
1386 | long temp; | 1361 | long temp; |
1387 | 1362 | ||
1388 | if (kstrtol(buf, 10, &temp)) | 1363 | if (kstrtol(buf, 10, &temp)) |
@@ -1440,8 +1415,8 @@ static ssize_t set_pwm_auto_temp(struct device *dev, | |||
1440 | size_t count) | 1415 | size_t count) |
1441 | { | 1416 | { |
1442 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 1417 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
1443 | struct i2c_client *client = to_i2c_client(dev); | 1418 | struct adt7462_data *data = dev_get_drvdata(dev); |
1444 | struct adt7462_data *data = i2c_get_clientdata(client); | 1419 | struct i2c_client *client = data->client; |
1445 | long temp; | 1420 | long temp; |
1446 | 1421 | ||
1447 | if (kstrtol(buf, 10, &temp)) | 1422 | if (kstrtol(buf, 10, &temp)) |
@@ -1725,7 +1700,7 @@ static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IWUSR | S_IRUGO, | |||
1725 | static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO, | 1700 | static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO, |
1726 | show_pwm_auto_temp, set_pwm_auto_temp, 3); | 1701 | show_pwm_auto_temp, set_pwm_auto_temp, 3); |
1727 | 1702 | ||
1728 | static struct attribute *adt7462_attr[] = { | 1703 | static struct attribute *adt7462_attrs[] = { |
1729 | &sensor_dev_attr_temp1_max.dev_attr.attr, | 1704 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
1730 | &sensor_dev_attr_temp2_max.dev_attr.attr, | 1705 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
1731 | &sensor_dev_attr_temp3_max.dev_attr.attr, | 1706 | &sensor_dev_attr_temp3_max.dev_attr.attr, |
@@ -1896,6 +1871,8 @@ static struct attribute *adt7462_attr[] = { | |||
1896 | NULL | 1871 | NULL |
1897 | }; | 1872 | }; |
1898 | 1873 | ||
1874 | ATTRIBUTE_GROUPS(adt7462); | ||
1875 | |||
1899 | /* Return 0 if detection is successful, -ENODEV otherwise */ | 1876 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
1900 | static int adt7462_detect(struct i2c_client *client, | 1877 | static int adt7462_detect(struct i2c_client *client, |
1901 | struct i2c_board_info *info) | 1878 | struct i2c_board_info *info) |
@@ -1926,46 +1903,41 @@ static int adt7462_detect(struct i2c_client *client, | |||
1926 | static int adt7462_probe(struct i2c_client *client, | 1903 | static int adt7462_probe(struct i2c_client *client, |
1927 | const struct i2c_device_id *id) | 1904 | const struct i2c_device_id *id) |
1928 | { | 1905 | { |
1906 | struct device *dev = &client->dev; | ||
1929 | struct adt7462_data *data; | 1907 | struct adt7462_data *data; |
1930 | int err; | 1908 | struct device *hwmon_dev; |
1931 | 1909 | ||
1932 | data = devm_kzalloc(&client->dev, sizeof(struct adt7462_data), | 1910 | data = devm_kzalloc(dev, sizeof(struct adt7462_data), GFP_KERNEL); |
1933 | GFP_KERNEL); | ||
1934 | if (!data) | 1911 | if (!data) |
1935 | return -ENOMEM; | 1912 | return -ENOMEM; |
1936 | 1913 | ||
1937 | i2c_set_clientdata(client, data); | 1914 | data->client = client; |
1938 | mutex_init(&data->lock); | 1915 | mutex_init(&data->lock); |
1939 | 1916 | ||
1940 | dev_info(&client->dev, "%s chip found\n", client->name); | 1917 | dev_info(&client->dev, "%s chip found\n", client->name); |
1941 | 1918 | ||
1942 | /* Register sysfs hooks */ | 1919 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
1943 | data->attrs.attrs = adt7462_attr; | 1920 | data, |
1944 | err = sysfs_create_group(&client->dev.kobj, &data->attrs); | 1921 | adt7462_groups); |
1945 | if (err) | 1922 | return PTR_ERR_OR_ZERO(hwmon_dev); |
1946 | return err; | ||
1947 | |||
1948 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
1949 | if (IS_ERR(data->hwmon_dev)) { | ||
1950 | err = PTR_ERR(data->hwmon_dev); | ||
1951 | goto exit_remove; | ||
1952 | } | ||
1953 | |||
1954 | return 0; | ||
1955 | |||
1956 | exit_remove: | ||
1957 | sysfs_remove_group(&client->dev.kobj, &data->attrs); | ||
1958 | return err; | ||
1959 | } | 1923 | } |
1960 | 1924 | ||
1961 | static int adt7462_remove(struct i2c_client *client) | 1925 | static const struct i2c_device_id adt7462_id[] = { |
1962 | { | 1926 | { "adt7462", 0 }, |
1963 | struct adt7462_data *data = i2c_get_clientdata(client); | 1927 | { } |
1928 | }; | ||
1929 | MODULE_DEVICE_TABLE(i2c, adt7462_id); | ||
1964 | 1930 | ||
1965 | hwmon_device_unregister(data->hwmon_dev); | 1931 | static struct i2c_driver adt7462_driver = { |
1966 | sysfs_remove_group(&client->dev.kobj, &data->attrs); | 1932 | .class = I2C_CLASS_HWMON, |
1967 | return 0; | 1933 | .driver = { |
1968 | } | 1934 | .name = "adt7462", |
1935 | }, | ||
1936 | .probe = adt7462_probe, | ||
1937 | .id_table = adt7462_id, | ||
1938 | .detect = adt7462_detect, | ||
1939 | .address_list = normal_i2c, | ||
1940 | }; | ||
1969 | 1941 | ||
1970 | module_i2c_driver(adt7462_driver); | 1942 | module_i2c_driver(adt7462_driver); |
1971 | 1943 | ||
diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c index 9ee3913850d6..f5da39a68929 100644 --- a/drivers/hwmon/adt7470.c +++ b/drivers/hwmon/adt7470.c | |||
@@ -143,8 +143,7 @@ static const unsigned short normal_i2c[] = { 0x2C, 0x2E, 0x2F, I2C_CLIENT_END }; | |||
143 | #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) | 143 | #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) |
144 | 144 | ||
145 | struct adt7470_data { | 145 | struct adt7470_data { |
146 | struct device *hwmon_dev; | 146 | struct i2c_client *client; |
147 | struct attribute_group attrs; | ||
148 | struct mutex lock; | 147 | struct mutex lock; |
149 | char sensors_valid; | 148 | char sensors_valid; |
150 | char limits_valid; | 149 | char limits_valid; |
@@ -175,30 +174,6 @@ struct adt7470_data { | |||
175 | unsigned int auto_update_interval; | 174 | unsigned int auto_update_interval; |
176 | }; | 175 | }; |
177 | 176 | ||
178 | static int adt7470_probe(struct i2c_client *client, | ||
179 | const struct i2c_device_id *id); | ||
180 | static int adt7470_detect(struct i2c_client *client, | ||
181 | struct i2c_board_info *info); | ||
182 | static int adt7470_remove(struct i2c_client *client); | ||
183 | |||
184 | static const struct i2c_device_id adt7470_id[] = { | ||
185 | { "adt7470", 0 }, | ||
186 | { } | ||
187 | }; | ||
188 | MODULE_DEVICE_TABLE(i2c, adt7470_id); | ||
189 | |||
190 | static struct i2c_driver adt7470_driver = { | ||
191 | .class = I2C_CLASS_HWMON, | ||
192 | .driver = { | ||
193 | .name = "adt7470", | ||
194 | }, | ||
195 | .probe = adt7470_probe, | ||
196 | .remove = adt7470_remove, | ||
197 | .id_table = adt7470_id, | ||
198 | .detect = adt7470_detect, | ||
199 | .address_list = normal_i2c, | ||
200 | }; | ||
201 | |||
202 | /* | 177 | /* |
203 | * 16-bit registers on the ADT7470 are low-byte first. The data sheet says | 178 | * 16-bit registers on the ADT7470 are low-byte first. The data sheet says |
204 | * that the low byte must be read before the high byte. | 179 | * that the low byte must be read before the high byte. |
@@ -218,18 +193,6 @@ static inline int adt7470_write_word_data(struct i2c_client *client, u8 reg, | |||
218 | || i2c_smbus_write_byte_data(client, reg + 1, value >> 8); | 193 | || i2c_smbus_write_byte_data(client, reg + 1, value >> 8); |
219 | } | 194 | } |
220 | 195 | ||
221 | static void adt7470_init_client(struct i2c_client *client) | ||
222 | { | ||
223 | int reg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG); | ||
224 | |||
225 | if (reg < 0) { | ||
226 | dev_err(&client->dev, "cannot read configuration register\n"); | ||
227 | } else { | ||
228 | /* start monitoring (and do a self-test) */ | ||
229 | i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, reg | 3); | ||
230 | } | ||
231 | } | ||
232 | |||
233 | /* Probe for temperature sensors. Assumes lock is held */ | 196 | /* Probe for temperature sensors. Assumes lock is held */ |
234 | static int adt7470_read_temperatures(struct i2c_client *client, | 197 | static int adt7470_read_temperatures(struct i2c_client *client, |
235 | struct adt7470_data *data) | 198 | struct adt7470_data *data) |
@@ -314,8 +277,8 @@ static int adt7470_update_thread(void *p) | |||
314 | 277 | ||
315 | static struct adt7470_data *adt7470_update_device(struct device *dev) | 278 | static struct adt7470_data *adt7470_update_device(struct device *dev) |
316 | { | 279 | { |
317 | struct i2c_client *client = to_i2c_client(dev); | 280 | struct adt7470_data *data = dev_get_drvdata(dev); |
318 | struct adt7470_data *data = i2c_get_clientdata(client); | 281 | struct i2c_client *client = data->client; |
319 | unsigned long local_jiffies = jiffies; | 282 | unsigned long local_jiffies = jiffies; |
320 | u8 cfg; | 283 | u8 cfg; |
321 | int i; | 284 | int i; |
@@ -445,8 +408,7 @@ static ssize_t set_auto_update_interval(struct device *dev, | |||
445 | const char *buf, | 408 | const char *buf, |
446 | size_t count) | 409 | size_t count) |
447 | { | 410 | { |
448 | struct i2c_client *client = to_i2c_client(dev); | 411 | struct adt7470_data *data = dev_get_drvdata(dev); |
449 | struct adt7470_data *data = i2c_get_clientdata(client); | ||
450 | long temp; | 412 | long temp; |
451 | 413 | ||
452 | if (kstrtol(buf, 10, &temp)) | 414 | if (kstrtol(buf, 10, &temp)) |
@@ -474,8 +436,7 @@ static ssize_t set_num_temp_sensors(struct device *dev, | |||
474 | const char *buf, | 436 | const char *buf, |
475 | size_t count) | 437 | size_t count) |
476 | { | 438 | { |
477 | struct i2c_client *client = to_i2c_client(dev); | 439 | struct adt7470_data *data = dev_get_drvdata(dev); |
478 | struct adt7470_data *data = i2c_get_clientdata(client); | ||
479 | long temp; | 440 | long temp; |
480 | 441 | ||
481 | if (kstrtol(buf, 10, &temp)) | 442 | if (kstrtol(buf, 10, &temp)) |
@@ -507,8 +468,8 @@ static ssize_t set_temp_min(struct device *dev, | |||
507 | size_t count) | 468 | size_t count) |
508 | { | 469 | { |
509 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 470 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
510 | struct i2c_client *client = to_i2c_client(dev); | 471 | struct adt7470_data *data = dev_get_drvdata(dev); |
511 | struct adt7470_data *data = i2c_get_clientdata(client); | 472 | struct i2c_client *client = data->client; |
512 | long temp; | 473 | long temp; |
513 | 474 | ||
514 | if (kstrtol(buf, 10, &temp)) | 475 | if (kstrtol(buf, 10, &temp)) |
@@ -541,8 +502,8 @@ static ssize_t set_temp_max(struct device *dev, | |||
541 | size_t count) | 502 | size_t count) |
542 | { | 503 | { |
543 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 504 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
544 | struct i2c_client *client = to_i2c_client(dev); | 505 | struct adt7470_data *data = dev_get_drvdata(dev); |
545 | struct adt7470_data *data = i2c_get_clientdata(client); | 506 | struct i2c_client *client = data->client; |
546 | long temp; | 507 | long temp; |
547 | 508 | ||
548 | if (kstrtol(buf, 10, &temp)) | 509 | if (kstrtol(buf, 10, &temp)) |
@@ -596,8 +557,8 @@ static ssize_t set_fan_max(struct device *dev, | |||
596 | const char *buf, size_t count) | 557 | const char *buf, size_t count) |
597 | { | 558 | { |
598 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 559 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
599 | struct i2c_client *client = to_i2c_client(dev); | 560 | struct adt7470_data *data = dev_get_drvdata(dev); |
600 | struct adt7470_data *data = i2c_get_clientdata(client); | 561 | struct i2c_client *client = data->client; |
601 | long temp; | 562 | long temp; |
602 | 563 | ||
603 | if (kstrtol(buf, 10, &temp) || !temp) | 564 | if (kstrtol(buf, 10, &temp) || !temp) |
@@ -633,8 +594,8 @@ static ssize_t set_fan_min(struct device *dev, | |||
633 | const char *buf, size_t count) | 594 | const char *buf, size_t count) |
634 | { | 595 | { |
635 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 596 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
636 | struct i2c_client *client = to_i2c_client(dev); | 597 | struct adt7470_data *data = dev_get_drvdata(dev); |
637 | struct adt7470_data *data = i2c_get_clientdata(client); | 598 | struct i2c_client *client = data->client; |
638 | long temp; | 599 | long temp; |
639 | 600 | ||
640 | if (kstrtol(buf, 10, &temp) || !temp) | 601 | if (kstrtol(buf, 10, &temp) || !temp) |
@@ -677,8 +638,8 @@ static ssize_t set_force_pwm_max(struct device *dev, | |||
677 | const char *buf, | 638 | const char *buf, |
678 | size_t count) | 639 | size_t count) |
679 | { | 640 | { |
680 | struct i2c_client *client = to_i2c_client(dev); | 641 | struct adt7470_data *data = dev_get_drvdata(dev); |
681 | struct adt7470_data *data = i2c_get_clientdata(client); | 642 | struct i2c_client *client = data->client; |
682 | long temp; | 643 | long temp; |
683 | u8 reg; | 644 | u8 reg; |
684 | 645 | ||
@@ -710,8 +671,8 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, | |||
710 | const char *buf, size_t count) | 671 | const char *buf, size_t count) |
711 | { | 672 | { |
712 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 673 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
713 | struct i2c_client *client = to_i2c_client(dev); | 674 | struct adt7470_data *data = dev_get_drvdata(dev); |
714 | struct adt7470_data *data = i2c_get_clientdata(client); | 675 | struct i2c_client *client = data->client; |
715 | long temp; | 676 | long temp; |
716 | 677 | ||
717 | if (kstrtol(buf, 10, &temp)) | 678 | if (kstrtol(buf, 10, &temp)) |
@@ -742,8 +703,8 @@ static ssize_t set_pwm_max(struct device *dev, | |||
742 | size_t count) | 703 | size_t count) |
743 | { | 704 | { |
744 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 705 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
745 | struct i2c_client *client = to_i2c_client(dev); | 706 | struct adt7470_data *data = dev_get_drvdata(dev); |
746 | struct adt7470_data *data = i2c_get_clientdata(client); | 707 | struct i2c_client *client = data->client; |
747 | long temp; | 708 | long temp; |
748 | 709 | ||
749 | if (kstrtol(buf, 10, &temp)) | 710 | if (kstrtol(buf, 10, &temp)) |
@@ -775,8 +736,8 @@ static ssize_t set_pwm_min(struct device *dev, | |||
775 | size_t count) | 736 | size_t count) |
776 | { | 737 | { |
777 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 738 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
778 | struct i2c_client *client = to_i2c_client(dev); | 739 | struct adt7470_data *data = dev_get_drvdata(dev); |
779 | struct adt7470_data *data = i2c_get_clientdata(client); | 740 | struct i2c_client *client = data->client; |
780 | long temp; | 741 | long temp; |
781 | 742 | ||
782 | if (kstrtol(buf, 10, &temp)) | 743 | if (kstrtol(buf, 10, &temp)) |
@@ -818,8 +779,8 @@ static ssize_t set_pwm_tmin(struct device *dev, | |||
818 | size_t count) | 779 | size_t count) |
819 | { | 780 | { |
820 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 781 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
821 | struct i2c_client *client = to_i2c_client(dev); | 782 | struct adt7470_data *data = dev_get_drvdata(dev); |
822 | struct adt7470_data *data = i2c_get_clientdata(client); | 783 | struct i2c_client *client = data->client; |
823 | long temp; | 784 | long temp; |
824 | 785 | ||
825 | if (kstrtol(buf, 10, &temp)) | 786 | if (kstrtol(buf, 10, &temp)) |
@@ -852,8 +813,8 @@ static ssize_t set_pwm_auto(struct device *dev, | |||
852 | size_t count) | 813 | size_t count) |
853 | { | 814 | { |
854 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 815 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
855 | struct i2c_client *client = to_i2c_client(dev); | 816 | struct adt7470_data *data = dev_get_drvdata(dev); |
856 | struct adt7470_data *data = i2c_get_clientdata(client); | 817 | struct i2c_client *client = data->client; |
857 | int pwm_auto_reg = ADT7470_REG_PWM_CFG(attr->index); | 818 | int pwm_auto_reg = ADT7470_REG_PWM_CFG(attr->index); |
858 | int pwm_auto_reg_mask; | 819 | int pwm_auto_reg_mask; |
859 | long temp; | 820 | long temp; |
@@ -913,8 +874,8 @@ static ssize_t set_pwm_auto_temp(struct device *dev, | |||
913 | size_t count) | 874 | size_t count) |
914 | { | 875 | { |
915 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 876 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
916 | struct i2c_client *client = to_i2c_client(dev); | 877 | struct adt7470_data *data = dev_get_drvdata(dev); |
917 | struct adt7470_data *data = i2c_get_clientdata(client); | 878 | struct i2c_client *client = data->client; |
918 | int pwm_auto_reg = ADT7470_REG_PWM_AUTO_TEMP(attr->index); | 879 | int pwm_auto_reg = ADT7470_REG_PWM_AUTO_TEMP(attr->index); |
919 | long temp; | 880 | long temp; |
920 | u8 reg; | 881 | u8 reg; |
@@ -1131,7 +1092,7 @@ static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IWUSR | S_IRUGO, | |||
1131 | static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO, | 1092 | static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO, |
1132 | show_pwm_auto_temp, set_pwm_auto_temp, 3); | 1093 | show_pwm_auto_temp, set_pwm_auto_temp, 3); |
1133 | 1094 | ||
1134 | static struct attribute *adt7470_attr[] = { | 1095 | static struct attribute *adt7470_attrs[] = { |
1135 | &dev_attr_alarm_mask.attr, | 1096 | &dev_attr_alarm_mask.attr, |
1136 | &dev_attr_num_temp_sensors.attr, | 1097 | &dev_attr_num_temp_sensors.attr, |
1137 | &dev_attr_auto_update_interval.attr, | 1098 | &dev_attr_auto_update_interval.attr, |
@@ -1223,6 +1184,8 @@ static struct attribute *adt7470_attr[] = { | |||
1223 | NULL | 1184 | NULL |
1224 | }; | 1185 | }; |
1225 | 1186 | ||
1187 | ATTRIBUTE_GROUPS(adt7470); | ||
1188 | |||
1226 | /* Return 0 if detection is successful, -ENODEV otherwise */ | 1189 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
1227 | static int adt7470_detect(struct i2c_client *client, | 1190 | static int adt7470_detect(struct i2c_client *client, |
1228 | struct i2c_board_info *info) | 1191 | struct i2c_board_info *info) |
@@ -1250,14 +1213,26 @@ static int adt7470_detect(struct i2c_client *client, | |||
1250 | return 0; | 1213 | return 0; |
1251 | } | 1214 | } |
1252 | 1215 | ||
1216 | static void adt7470_init_client(struct i2c_client *client) | ||
1217 | { | ||
1218 | int reg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG); | ||
1219 | |||
1220 | if (reg < 0) { | ||
1221 | dev_err(&client->dev, "cannot read configuration register\n"); | ||
1222 | } else { | ||
1223 | /* start monitoring (and do a self-test) */ | ||
1224 | i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, reg | 3); | ||
1225 | } | ||
1226 | } | ||
1227 | |||
1253 | static int adt7470_probe(struct i2c_client *client, | 1228 | static int adt7470_probe(struct i2c_client *client, |
1254 | const struct i2c_device_id *id) | 1229 | const struct i2c_device_id *id) |
1255 | { | 1230 | { |
1231 | struct device *dev = &client->dev; | ||
1256 | struct adt7470_data *data; | 1232 | struct adt7470_data *data; |
1257 | int err; | 1233 | struct device *hwmon_dev; |
1258 | 1234 | ||
1259 | data = devm_kzalloc(&client->dev, sizeof(struct adt7470_data), | 1235 | data = devm_kzalloc(dev, sizeof(struct adt7470_data), GFP_KERNEL); |
1260 | GFP_KERNEL); | ||
1261 | if (!data) | 1236 | if (!data) |
1262 | return -ENOMEM; | 1237 | return -ENOMEM; |
1263 | 1238 | ||
@@ -1265,6 +1240,7 @@ static int adt7470_probe(struct i2c_client *client, | |||
1265 | data->auto_update_interval = AUTO_UPDATE_INTERVAL; | 1240 | data->auto_update_interval = AUTO_UPDATE_INTERVAL; |
1266 | 1241 | ||
1267 | i2c_set_clientdata(client, data); | 1242 | i2c_set_clientdata(client, data); |
1243 | data->client = client; | ||
1268 | mutex_init(&data->lock); | 1244 | mutex_init(&data->lock); |
1269 | 1245 | ||
1270 | dev_info(&client->dev, "%s chip found\n", client->name); | 1246 | dev_info(&client->dev, "%s chip found\n", client->name); |
@@ -1273,32 +1249,21 @@ static int adt7470_probe(struct i2c_client *client, | |||
1273 | adt7470_init_client(client); | 1249 | adt7470_init_client(client); |
1274 | 1250 | ||
1275 | /* Register sysfs hooks */ | 1251 | /* Register sysfs hooks */ |
1276 | data->attrs.attrs = adt7470_attr; | 1252 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
1277 | err = sysfs_create_group(&client->dev.kobj, &data->attrs); | 1253 | data, |
1278 | if (err) | 1254 | adt7470_groups); |
1279 | return err; | 1255 | |
1280 | 1256 | if (IS_ERR(hwmon_dev)) | |
1281 | data->hwmon_dev = hwmon_device_register(&client->dev); | 1257 | return PTR_ERR(hwmon_dev); |
1282 | if (IS_ERR(data->hwmon_dev)) { | ||
1283 | err = PTR_ERR(data->hwmon_dev); | ||
1284 | goto exit_remove; | ||
1285 | } | ||
1286 | 1258 | ||
1287 | init_completion(&data->auto_update_stop); | 1259 | init_completion(&data->auto_update_stop); |
1288 | data->auto_update = kthread_run(adt7470_update_thread, client, "%s", | 1260 | data->auto_update = kthread_run(adt7470_update_thread, client, "%s", |
1289 | dev_name(data->hwmon_dev)); | 1261 | dev_name(hwmon_dev)); |
1290 | if (IS_ERR(data->auto_update)) { | 1262 | if (IS_ERR(data->auto_update)) { |
1291 | err = PTR_ERR(data->auto_update); | 1263 | return PTR_ERR(data->auto_update); |
1292 | goto exit_unregister; | ||
1293 | } | 1264 | } |
1294 | 1265 | ||
1295 | return 0; | 1266 | return 0; |
1296 | |||
1297 | exit_unregister: | ||
1298 | hwmon_device_unregister(data->hwmon_dev); | ||
1299 | exit_remove: | ||
1300 | sysfs_remove_group(&client->dev.kobj, &data->attrs); | ||
1301 | return err; | ||
1302 | } | 1267 | } |
1303 | 1268 | ||
1304 | static int adt7470_remove(struct i2c_client *client) | 1269 | static int adt7470_remove(struct i2c_client *client) |
@@ -1307,11 +1272,27 @@ static int adt7470_remove(struct i2c_client *client) | |||
1307 | 1272 | ||
1308 | kthread_stop(data->auto_update); | 1273 | kthread_stop(data->auto_update); |
1309 | wait_for_completion(&data->auto_update_stop); | 1274 | wait_for_completion(&data->auto_update_stop); |
1310 | hwmon_device_unregister(data->hwmon_dev); | ||
1311 | sysfs_remove_group(&client->dev.kobj, &data->attrs); | ||
1312 | return 0; | 1275 | return 0; |
1313 | } | 1276 | } |
1314 | 1277 | ||
1278 | static const struct i2c_device_id adt7470_id[] = { | ||
1279 | { "adt7470", 0 }, | ||
1280 | { } | ||
1281 | }; | ||
1282 | MODULE_DEVICE_TABLE(i2c, adt7470_id); | ||
1283 | |||
1284 | static struct i2c_driver adt7470_driver = { | ||
1285 | .class = I2C_CLASS_HWMON, | ||
1286 | .driver = { | ||
1287 | .name = "adt7470", | ||
1288 | }, | ||
1289 | .probe = adt7470_probe, | ||
1290 | .remove = adt7470_remove, | ||
1291 | .id_table = adt7470_id, | ||
1292 | .detect = adt7470_detect, | ||
1293 | .address_list = normal_i2c, | ||
1294 | }; | ||
1295 | |||
1315 | module_i2c_driver(adt7470_driver); | 1296 | module_i2c_driver(adt7470_driver); |
1316 | 1297 | ||
1317 | MODULE_AUTHOR("Darrick J. Wong <darrick.wong@oracle.com>"); | 1298 | MODULE_AUTHOR("Darrick J. Wong <darrick.wong@oracle.com>"); |
diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c index 9f2be3dd28f3..12e851a5af48 100644 --- a/drivers/hwmon/amc6821.c +++ b/drivers/hwmon/amc6821.c | |||
@@ -21,7 +21,6 @@ | |||
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 | |||
25 | #include <linux/kernel.h> /* Needed for KERN_INFO */ | 24 | #include <linux/kernel.h> /* Needed for KERN_INFO */ |
26 | #include <linux/module.h> | 25 | #include <linux/module.h> |
27 | #include <linux/init.h> | 26 | #include <linux/init.h> |
@@ -33,7 +32,6 @@ | |||
33 | #include <linux/err.h> | 32 | #include <linux/err.h> |
34 | #include <linux/mutex.h> | 33 | #include <linux/mutex.h> |
35 | 34 | ||
36 | |||
37 | /* | 35 | /* |
38 | * Addresses to scan. | 36 | * Addresses to scan. |
39 | */ | 37 | */ |
@@ -41,8 +39,6 @@ | |||
41 | static const unsigned short normal_i2c[] = {0x18, 0x19, 0x1a, 0x2c, 0x2d, 0x2e, | 39 | static const unsigned short normal_i2c[] = {0x18, 0x19, 0x1a, 0x2c, 0x2d, 0x2e, |
42 | 0x4c, 0x4d, 0x4e, I2C_CLIENT_END}; | 40 | 0x4c, 0x4d, 0x4e, I2C_CLIENT_END}; |
43 | 41 | ||
44 | |||
45 | |||
46 | /* | 42 | /* |
47 | * Insmod parameters | 43 | * Insmod parameters |
48 | */ | 44 | */ |
@@ -53,7 +49,6 @@ module_param(pwminv, int, S_IRUGO); | |||
53 | static int init = 1; /*Power-on initialization.*/ | 49 | static int init = 1; /*Power-on initialization.*/ |
54 | module_param(init, int, S_IRUGO); | 50 | module_param(init, int, S_IRUGO); |
55 | 51 | ||
56 | |||
57 | enum chips { amc6821 }; | 52 | enum chips { amc6821 }; |
58 | 53 | ||
59 | #define AMC6821_REG_DEV_ID 0x3D | 54 | #define AMC6821_REG_DEV_ID 0x3D |
@@ -152,46 +147,12 @@ static const u8 fan_reg_hi[] = {AMC6821_REG_TDATA_HI, | |||
152 | AMC6821_REG_TACH_LLIMITH, | 147 | AMC6821_REG_TACH_LLIMITH, |
153 | AMC6821_REG_TACH_HLIMITH, }; | 148 | AMC6821_REG_TACH_HLIMITH, }; |
154 | 149 | ||
155 | static int amc6821_probe( | ||
156 | struct i2c_client *client, | ||
157 | const struct i2c_device_id *id); | ||
158 | static int amc6821_detect( | ||
159 | struct i2c_client *client, | ||
160 | struct i2c_board_info *info); | ||
161 | static int amc6821_init_client(struct i2c_client *client); | ||
162 | static int amc6821_remove(struct i2c_client *client); | ||
163 | static struct amc6821_data *amc6821_update_device(struct device *dev); | ||
164 | |||
165 | /* | ||
166 | * Driver data (common to all clients) | ||
167 | */ | ||
168 | |||
169 | static const struct i2c_device_id amc6821_id[] = { | ||
170 | { "amc6821", amc6821 }, | ||
171 | { } | ||
172 | }; | ||
173 | |||
174 | MODULE_DEVICE_TABLE(i2c, amc6821_id); | ||
175 | |||
176 | static struct i2c_driver amc6821_driver = { | ||
177 | .class = I2C_CLASS_HWMON, | ||
178 | .driver = { | ||
179 | .name = "amc6821", | ||
180 | }, | ||
181 | .probe = amc6821_probe, | ||
182 | .remove = amc6821_remove, | ||
183 | .id_table = amc6821_id, | ||
184 | .detect = amc6821_detect, | ||
185 | .address_list = normal_i2c, | ||
186 | }; | ||
187 | |||
188 | |||
189 | /* | 150 | /* |
190 | * Client data (each client gets its own) | 151 | * Client data (each client gets its own) |
191 | */ | 152 | */ |
192 | 153 | ||
193 | struct amc6821_data { | 154 | struct amc6821_data { |
194 | struct device *hwmon_dev; | 155 | struct i2c_client *client; |
195 | struct mutex update_lock; | 156 | struct mutex update_lock; |
196 | char valid; /* zero until following fields are valid */ | 157 | char valid; /* zero until following fields are valid */ |
197 | unsigned long last_updated; /* in jiffies */ | 158 | unsigned long last_updated; /* in jiffies */ |
@@ -213,6 +174,108 @@ struct amc6821_data { | |||
213 | u8 stat2; | 174 | u8 stat2; |
214 | }; | 175 | }; |
215 | 176 | ||
177 | static struct amc6821_data *amc6821_update_device(struct device *dev) | ||
178 | { | ||
179 | struct amc6821_data *data = dev_get_drvdata(dev); | ||
180 | struct i2c_client *client = data->client; | ||
181 | int timeout = HZ; | ||
182 | u8 reg; | ||
183 | int i; | ||
184 | |||
185 | mutex_lock(&data->update_lock); | ||
186 | |||
187 | if (time_after(jiffies, data->last_updated + timeout) || | ||
188 | !data->valid) { | ||
189 | |||
190 | for (i = 0; i < TEMP_IDX_LEN; i++) | ||
191 | data->temp[i] = i2c_smbus_read_byte_data(client, | ||
192 | temp_reg[i]); | ||
193 | |||
194 | data->stat1 = i2c_smbus_read_byte_data(client, | ||
195 | AMC6821_REG_STAT1); | ||
196 | data->stat2 = i2c_smbus_read_byte_data(client, | ||
197 | AMC6821_REG_STAT2); | ||
198 | |||
199 | data->pwm1 = i2c_smbus_read_byte_data(client, | ||
200 | AMC6821_REG_DCY); | ||
201 | for (i = 0; i < FAN1_IDX_LEN; i++) { | ||
202 | data->fan[i] = i2c_smbus_read_byte_data( | ||
203 | client, | ||
204 | fan_reg_low[i]); | ||
205 | data->fan[i] += i2c_smbus_read_byte_data( | ||
206 | client, | ||
207 | fan_reg_hi[i]) << 8; | ||
208 | } | ||
209 | data->fan1_div = i2c_smbus_read_byte_data(client, | ||
210 | AMC6821_REG_CONF4); | ||
211 | data->fan1_div = data->fan1_div & AMC6821_CONF4_PSPR ? 4 : 2; | ||
212 | |||
213 | data->pwm1_auto_point_pwm[0] = 0; | ||
214 | data->pwm1_auto_point_pwm[2] = 255; | ||
215 | data->pwm1_auto_point_pwm[1] = i2c_smbus_read_byte_data(client, | ||
216 | AMC6821_REG_DCY_LOW_TEMP); | ||
217 | |||
218 | data->temp1_auto_point_temp[0] = | ||
219 | i2c_smbus_read_byte_data(client, | ||
220 | AMC6821_REG_PSV_TEMP); | ||
221 | data->temp2_auto_point_temp[0] = | ||
222 | data->temp1_auto_point_temp[0]; | ||
223 | reg = i2c_smbus_read_byte_data(client, | ||
224 | AMC6821_REG_LTEMP_FAN_CTRL); | ||
225 | data->temp1_auto_point_temp[1] = (reg & 0xF8) >> 1; | ||
226 | reg &= 0x07; | ||
227 | reg = 0x20 >> reg; | ||
228 | if (reg > 0) | ||
229 | data->temp1_auto_point_temp[2] = | ||
230 | data->temp1_auto_point_temp[1] + | ||
231 | (data->pwm1_auto_point_pwm[2] - | ||
232 | data->pwm1_auto_point_pwm[1]) / reg; | ||
233 | else | ||
234 | data->temp1_auto_point_temp[2] = 255; | ||
235 | |||
236 | reg = i2c_smbus_read_byte_data(client, | ||
237 | AMC6821_REG_RTEMP_FAN_CTRL); | ||
238 | data->temp2_auto_point_temp[1] = (reg & 0xF8) >> 1; | ||
239 | reg &= 0x07; | ||
240 | reg = 0x20 >> reg; | ||
241 | if (reg > 0) | ||
242 | data->temp2_auto_point_temp[2] = | ||
243 | data->temp2_auto_point_temp[1] + | ||
244 | (data->pwm1_auto_point_pwm[2] - | ||
245 | data->pwm1_auto_point_pwm[1]) / reg; | ||
246 | else | ||
247 | data->temp2_auto_point_temp[2] = 255; | ||
248 | |||
249 | reg = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF1); | ||
250 | reg = (reg >> 5) & 0x3; | ||
251 | switch (reg) { | ||
252 | case 0: /*open loop: software sets pwm1*/ | ||
253 | data->pwm1_auto_channels_temp = 0; | ||
254 | data->pwm1_enable = 1; | ||
255 | break; | ||
256 | case 2: /*closed loop: remote T (temp2)*/ | ||
257 | data->pwm1_auto_channels_temp = 2; | ||
258 | data->pwm1_enable = 2; | ||
259 | break; | ||
260 | case 3: /*closed loop: local and remote T (temp2)*/ | ||
261 | data->pwm1_auto_channels_temp = 3; | ||
262 | data->pwm1_enable = 3; | ||
263 | break; | ||
264 | case 1: /* | ||
265 | * semi-open loop: software sets rpm, chip controls | ||
266 | * pwm1, currently not implemented | ||
267 | */ | ||
268 | data->pwm1_auto_channels_temp = 0; | ||
269 | data->pwm1_enable = 0; | ||
270 | break; | ||
271 | } | ||
272 | |||
273 | data->last_updated = jiffies; | ||
274 | data->valid = 1; | ||
275 | } | ||
276 | mutex_unlock(&data->update_lock); | ||
277 | return data; | ||
278 | } | ||
216 | 279 | ||
217 | static ssize_t get_temp( | 280 | static ssize_t get_temp( |
218 | struct device *dev, | 281 | struct device *dev, |
@@ -225,16 +288,14 @@ static ssize_t get_temp( | |||
225 | return sprintf(buf, "%d\n", data->temp[ix] * 1000); | 288 | return sprintf(buf, "%d\n", data->temp[ix] * 1000); |
226 | } | 289 | } |
227 | 290 | ||
228 | |||
229 | |||
230 | static ssize_t set_temp( | 291 | static ssize_t set_temp( |
231 | struct device *dev, | 292 | struct device *dev, |
232 | struct device_attribute *attr, | 293 | struct device_attribute *attr, |
233 | const char *buf, | 294 | const char *buf, |
234 | size_t count) | 295 | size_t count) |
235 | { | 296 | { |
236 | struct i2c_client *client = to_i2c_client(dev); | 297 | struct amc6821_data *data = dev_get_drvdata(dev); |
237 | struct amc6821_data *data = i2c_get_clientdata(client); | 298 | struct i2c_client *client = data->client; |
238 | int ix = to_sensor_dev_attr(attr)->index; | 299 | int ix = to_sensor_dev_attr(attr)->index; |
239 | long val; | 300 | long val; |
240 | 301 | ||
@@ -253,9 +314,6 @@ static ssize_t set_temp( | |||
253 | return count; | 314 | return count; |
254 | } | 315 | } |
255 | 316 | ||
256 | |||
257 | |||
258 | |||
259 | static ssize_t get_temp_alarm( | 317 | static ssize_t get_temp_alarm( |
260 | struct device *dev, | 318 | struct device *dev, |
261 | struct device_attribute *devattr, | 319 | struct device_attribute *devattr, |
@@ -294,9 +352,6 @@ static ssize_t get_temp_alarm( | |||
294 | return sprintf(buf, "0"); | 352 | return sprintf(buf, "0"); |
295 | } | 353 | } |
296 | 354 | ||
297 | |||
298 | |||
299 | |||
300 | static ssize_t get_temp2_fault( | 355 | static ssize_t get_temp2_fault( |
301 | struct device *dev, | 356 | struct device *dev, |
302 | struct device_attribute *devattr, | 357 | struct device_attribute *devattr, |
@@ -324,8 +379,8 @@ static ssize_t set_pwm1( | |||
324 | const char *buf, | 379 | const char *buf, |
325 | size_t count) | 380 | size_t count) |
326 | { | 381 | { |
327 | struct i2c_client *client = to_i2c_client(dev); | 382 | struct amc6821_data *data = dev_get_drvdata(dev); |
328 | struct amc6821_data *data = i2c_get_clientdata(client); | 383 | struct i2c_client *client = data->client; |
329 | long val; | 384 | long val; |
330 | int ret = kstrtol(buf, 10, &val); | 385 | int ret = kstrtol(buf, 10, &val); |
331 | if (ret) | 386 | if (ret) |
@@ -353,18 +408,20 @@ static ssize_t set_pwm1_enable( | |||
353 | const char *buf, | 408 | const char *buf, |
354 | size_t count) | 409 | size_t count) |
355 | { | 410 | { |
356 | struct i2c_client *client = to_i2c_client(dev); | 411 | struct amc6821_data *data = dev_get_drvdata(dev); |
357 | struct amc6821_data *data = i2c_get_clientdata(client); | 412 | struct i2c_client *client = data->client; |
358 | long val; | 413 | long val; |
359 | int config = kstrtol(buf, 10, &val); | 414 | int config = kstrtol(buf, 10, &val); |
360 | if (config) | 415 | if (config) |
361 | return config; | 416 | return config; |
362 | 417 | ||
418 | mutex_lock(&data->update_lock); | ||
363 | config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF1); | 419 | config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF1); |
364 | if (config < 0) { | 420 | if (config < 0) { |
365 | dev_err(&client->dev, | 421 | dev_err(&client->dev, |
366 | "Error reading configuration register, aborting.\n"); | 422 | "Error reading configuration register, aborting.\n"); |
367 | return config; | 423 | count = config; |
424 | goto unlock; | ||
368 | } | 425 | } |
369 | 426 | ||
370 | switch (val) { | 427 | switch (val) { |
@@ -381,19 +438,19 @@ static ssize_t set_pwm1_enable( | |||
381 | config |= AMC6821_CONF1_FDRC1; | 438 | config |= AMC6821_CONF1_FDRC1; |
382 | break; | 439 | break; |
383 | default: | 440 | default: |
384 | return -EINVAL; | 441 | count = -EINVAL; |
442 | goto unlock; | ||
385 | } | 443 | } |
386 | mutex_lock(&data->update_lock); | ||
387 | if (i2c_smbus_write_byte_data(client, AMC6821_REG_CONF1, config)) { | 444 | if (i2c_smbus_write_byte_data(client, AMC6821_REG_CONF1, config)) { |
388 | dev_err(&client->dev, | 445 | dev_err(&client->dev, |
389 | "Configuration register write error, aborting.\n"); | 446 | "Configuration register write error, aborting.\n"); |
390 | count = -EIO; | 447 | count = -EIO; |
391 | } | 448 | } |
449 | unlock: | ||
392 | mutex_unlock(&data->update_lock); | 450 | mutex_unlock(&data->update_lock); |
393 | return count; | 451 | return count; |
394 | } | 452 | } |
395 | 453 | ||
396 | |||
397 | static ssize_t get_pwm1_auto_channels_temp( | 454 | static ssize_t get_pwm1_auto_channels_temp( |
398 | struct device *dev, | 455 | struct device *dev, |
399 | struct device_attribute *devattr, | 456 | struct device_attribute *devattr, |
@@ -403,7 +460,6 @@ static ssize_t get_pwm1_auto_channels_temp( | |||
403 | return sprintf(buf, "%d\n", data->pwm1_auto_channels_temp); | 460 | return sprintf(buf, "%d\n", data->pwm1_auto_channels_temp); |
404 | } | 461 | } |
405 | 462 | ||
406 | |||
407 | static ssize_t get_temp_auto_point_temp( | 463 | static ssize_t get_temp_auto_point_temp( |
408 | struct device *dev, | 464 | struct device *dev, |
409 | struct device_attribute *devattr, | 465 | struct device_attribute *devattr, |
@@ -425,7 +481,6 @@ static ssize_t get_temp_auto_point_temp( | |||
425 | } | 481 | } |
426 | } | 482 | } |
427 | 483 | ||
428 | |||
429 | static ssize_t get_pwm1_auto_point_pwm( | 484 | static ssize_t get_pwm1_auto_point_pwm( |
430 | struct device *dev, | 485 | struct device *dev, |
431 | struct device_attribute *devattr, | 486 | struct device_attribute *devattr, |
@@ -436,7 +491,6 @@ static ssize_t get_pwm1_auto_point_pwm( | |||
436 | return sprintf(buf, "%d\n", data->pwm1_auto_point_pwm[ix]); | 491 | return sprintf(buf, "%d\n", data->pwm1_auto_point_pwm[ix]); |
437 | } | 492 | } |
438 | 493 | ||
439 | |||
440 | static inline ssize_t set_slope_register(struct i2c_client *client, | 494 | static inline ssize_t set_slope_register(struct i2c_client *client, |
441 | u8 reg, | 495 | u8 reg, |
442 | u8 dpwm, | 496 | u8 dpwm, |
@@ -459,16 +513,14 @@ static inline ssize_t set_slope_register(struct i2c_client *client, | |||
459 | return 0; | 513 | return 0; |
460 | } | 514 | } |
461 | 515 | ||
462 | |||
463 | |||
464 | static ssize_t set_temp_auto_point_temp( | 516 | static ssize_t set_temp_auto_point_temp( |
465 | struct device *dev, | 517 | struct device *dev, |
466 | struct device_attribute *attr, | 518 | struct device_attribute *attr, |
467 | const char *buf, | 519 | const char *buf, |
468 | size_t count) | 520 | size_t count) |
469 | { | 521 | { |
470 | struct i2c_client *client = to_i2c_client(dev); | ||
471 | struct amc6821_data *data = amc6821_update_device(dev); | 522 | struct amc6821_data *data = amc6821_update_device(dev); |
523 | struct i2c_client *client = data->client; | ||
472 | int ix = to_sensor_dev_attr_2(attr)->index; | 524 | int ix = to_sensor_dev_attr_2(attr)->index; |
473 | int nr = to_sensor_dev_attr_2(attr)->nr; | 525 | int nr = to_sensor_dev_attr_2(attr)->nr; |
474 | u8 *ptemp; | 526 | u8 *ptemp; |
@@ -493,8 +545,9 @@ static ssize_t set_temp_auto_point_temp( | |||
493 | return -EINVAL; | 545 | return -EINVAL; |
494 | } | 546 | } |
495 | 547 | ||
496 | data->valid = 0; | ||
497 | mutex_lock(&data->update_lock); | 548 | mutex_lock(&data->update_lock); |
549 | data->valid = 0; | ||
550 | |||
498 | switch (ix) { | 551 | switch (ix) { |
499 | case 0: | 552 | case 0: |
500 | ptemp[0] = clamp_val(val / 1000, 0, | 553 | ptemp[0] = clamp_val(val / 1000, 0, |
@@ -533,16 +586,14 @@ EXIT: | |||
533 | return count; | 586 | return count; |
534 | } | 587 | } |
535 | 588 | ||
536 | |||
537 | |||
538 | static ssize_t set_pwm1_auto_point_pwm( | 589 | static ssize_t set_pwm1_auto_point_pwm( |
539 | struct device *dev, | 590 | struct device *dev, |
540 | struct device_attribute *attr, | 591 | struct device_attribute *attr, |
541 | const char *buf, | 592 | const char *buf, |
542 | size_t count) | 593 | size_t count) |
543 | { | 594 | { |
544 | struct i2c_client *client = to_i2c_client(dev); | 595 | struct amc6821_data *data = dev_get_drvdata(dev); |
545 | struct amc6821_data *data = i2c_get_clientdata(client); | 596 | struct i2c_client *client = data->client; |
546 | int dpwm; | 597 | int dpwm; |
547 | long val; | 598 | long val; |
548 | int ret = kstrtol(buf, 10, &val); | 599 | int ret = kstrtol(buf, 10, &val); |
@@ -587,8 +638,6 @@ static ssize_t get_fan( | |||
587 | return sprintf(buf, "%d\n", (int)(6000000 / data->fan[ix])); | 638 | return sprintf(buf, "%d\n", (int)(6000000 / data->fan[ix])); |
588 | } | 639 | } |
589 | 640 | ||
590 | |||
591 | |||
592 | static ssize_t get_fan1_fault( | 641 | static ssize_t get_fan1_fault( |
593 | struct device *dev, | 642 | struct device *dev, |
594 | struct device_attribute *devattr, | 643 | struct device_attribute *devattr, |
@@ -601,15 +650,13 @@ static ssize_t get_fan1_fault( | |||
601 | return sprintf(buf, "0"); | 650 | return sprintf(buf, "0"); |
602 | } | 651 | } |
603 | 652 | ||
604 | |||
605 | |||
606 | static ssize_t set_fan( | 653 | static ssize_t set_fan( |
607 | struct device *dev, | 654 | struct device *dev, |
608 | struct device_attribute *attr, | 655 | struct device_attribute *attr, |
609 | const char *buf, size_t count) | 656 | const char *buf, size_t count) |
610 | { | 657 | { |
611 | struct i2c_client *client = to_i2c_client(dev); | 658 | struct amc6821_data *data = dev_get_drvdata(dev); |
612 | struct amc6821_data *data = i2c_get_clientdata(client); | 659 | struct i2c_client *client = data->client; |
613 | long val; | 660 | long val; |
614 | int ix = to_sensor_dev_attr(attr)->index; | 661 | int ix = to_sensor_dev_attr(attr)->index; |
615 | int ret = kstrtol(buf, 10, &val); | 662 | int ret = kstrtol(buf, 10, &val); |
@@ -635,8 +682,6 @@ EXIT: | |||
635 | return count; | 682 | return count; |
636 | } | 683 | } |
637 | 684 | ||
638 | |||
639 | |||
640 | static ssize_t get_fan1_div( | 685 | static ssize_t get_fan1_div( |
641 | struct device *dev, | 686 | struct device *dev, |
642 | struct device_attribute *devattr, | 687 | struct device_attribute *devattr, |
@@ -651,20 +696,21 @@ static ssize_t set_fan1_div( | |||
651 | struct device_attribute *attr, | 696 | struct device_attribute *attr, |
652 | const char *buf, size_t count) | 697 | const char *buf, size_t count) |
653 | { | 698 | { |
654 | struct i2c_client *client = to_i2c_client(dev); | 699 | struct amc6821_data *data = dev_get_drvdata(dev); |
655 | struct amc6821_data *data = i2c_get_clientdata(client); | 700 | struct i2c_client *client = data->client; |
656 | long val; | 701 | long val; |
657 | int config = kstrtol(buf, 10, &val); | 702 | int config = kstrtol(buf, 10, &val); |
658 | if (config) | 703 | if (config) |
659 | return config; | 704 | return config; |
660 | 705 | ||
706 | mutex_lock(&data->update_lock); | ||
661 | config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF4); | 707 | config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF4); |
662 | if (config < 0) { | 708 | if (config < 0) { |
663 | dev_err(&client->dev, | 709 | dev_err(&client->dev, |
664 | "Error reading configuration register, aborting.\n"); | 710 | "Error reading configuration register, aborting.\n"); |
665 | return config; | 711 | count = config; |
712 | goto EXIT; | ||
666 | } | 713 | } |
667 | mutex_lock(&data->update_lock); | ||
668 | switch (val) { | 714 | switch (val) { |
669 | case 2: | 715 | case 2: |
670 | config &= ~AMC6821_CONF4_PSPR; | 716 | config &= ~AMC6821_CONF4_PSPR; |
@@ -688,8 +734,6 @@ EXIT: | |||
688 | return count; | 734 | return count; |
689 | } | 735 | } |
690 | 736 | ||
691 | |||
692 | |||
693 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, | 737 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, |
694 | get_temp, NULL, IDX_TEMP1_INPUT); | 738 | get_temp, NULL, IDX_TEMP1_INPUT); |
695 | static SENSOR_DEVICE_ATTR(temp1_min, S_IRUGO | S_IWUSR, get_temp, | 739 | static SENSOR_DEVICE_ATTR(temp1_min, S_IRUGO | S_IWUSR, get_temp, |
@@ -754,8 +798,6 @@ static SENSOR_DEVICE_ATTR_2(temp2_auto_point2_temp, S_IWUSR | S_IRUGO, | |||
754 | static SENSOR_DEVICE_ATTR_2(temp2_auto_point3_temp, S_IWUSR | S_IRUGO, | 798 | static SENSOR_DEVICE_ATTR_2(temp2_auto_point3_temp, S_IWUSR | S_IRUGO, |
755 | get_temp_auto_point_temp, set_temp_auto_point_temp, 2, 2); | 799 | get_temp_auto_point_temp, set_temp_auto_point_temp, 2, 2); |
756 | 800 | ||
757 | |||
758 | |||
759 | static struct attribute *amc6821_attrs[] = { | 801 | static struct attribute *amc6821_attrs[] = { |
760 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 802 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
761 | &sensor_dev_attr_temp1_min.dev_attr.attr, | 803 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
@@ -792,11 +834,7 @@ static struct attribute *amc6821_attrs[] = { | |||
792 | NULL | 834 | NULL |
793 | }; | 835 | }; |
794 | 836 | ||
795 | static struct attribute_group amc6821_attr_grp = { | 837 | ATTRIBUTE_GROUPS(amc6821); |
796 | .attrs = amc6821_attrs, | ||
797 | }; | ||
798 | |||
799 | |||
800 | 838 | ||
801 | /* Return 0 if detection is successful, -ENODEV otherwise */ | 839 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
802 | static int amc6821_detect( | 840 | static int amc6821_detect( |
@@ -844,53 +882,6 @@ static int amc6821_detect( | |||
844 | return 0; | 882 | return 0; |
845 | } | 883 | } |
846 | 884 | ||
847 | static int amc6821_probe( | ||
848 | struct i2c_client *client, | ||
849 | const struct i2c_device_id *id) | ||
850 | { | ||
851 | struct amc6821_data *data; | ||
852 | int err; | ||
853 | |||
854 | data = devm_kzalloc(&client->dev, sizeof(struct amc6821_data), | ||
855 | GFP_KERNEL); | ||
856 | if (!data) | ||
857 | return -ENOMEM; | ||
858 | |||
859 | i2c_set_clientdata(client, data); | ||
860 | mutex_init(&data->update_lock); | ||
861 | |||
862 | /* | ||
863 | * Initialize the amc6821 chip | ||
864 | */ | ||
865 | err = amc6821_init_client(client); | ||
866 | if (err) | ||
867 | return err; | ||
868 | |||
869 | err = sysfs_create_group(&client->dev.kobj, &amc6821_attr_grp); | ||
870 | if (err) | ||
871 | return err; | ||
872 | |||
873 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
874 | if (!IS_ERR(data->hwmon_dev)) | ||
875 | return 0; | ||
876 | |||
877 | err = PTR_ERR(data->hwmon_dev); | ||
878 | dev_err(&client->dev, "error registering hwmon device.\n"); | ||
879 | sysfs_remove_group(&client->dev.kobj, &amc6821_attr_grp); | ||
880 | return err; | ||
881 | } | ||
882 | |||
883 | static int amc6821_remove(struct i2c_client *client) | ||
884 | { | ||
885 | struct amc6821_data *data = i2c_get_clientdata(client); | ||
886 | |||
887 | hwmon_device_unregister(data->hwmon_dev); | ||
888 | sysfs_remove_group(&client->dev.kobj, &amc6821_attr_grp); | ||
889 | |||
890 | return 0; | ||
891 | } | ||
892 | |||
893 | |||
894 | static int amc6821_init_client(struct i2c_client *client) | 885 | static int amc6821_init_client(struct i2c_client *client) |
895 | { | 886 | { |
896 | int config; | 887 | int config; |
@@ -977,109 +968,51 @@ static int amc6821_init_client(struct i2c_client *client) | |||
977 | return 0; | 968 | return 0; |
978 | } | 969 | } |
979 | 970 | ||
980 | 971 | static int amc6821_probe(struct i2c_client *client, | |
981 | static struct amc6821_data *amc6821_update_device(struct device *dev) | 972 | const struct i2c_device_id *id) |
982 | { | 973 | { |
983 | struct i2c_client *client = to_i2c_client(dev); | 974 | struct device *dev = &client->dev; |
984 | struct amc6821_data *data = i2c_get_clientdata(client); | 975 | struct amc6821_data *data; |
985 | int timeout = HZ; | 976 | struct device *hwmon_dev; |
986 | u8 reg; | 977 | int err; |
987 | int i; | ||
988 | |||
989 | mutex_lock(&data->update_lock); | ||
990 | |||
991 | if (time_after(jiffies, data->last_updated + timeout) || | ||
992 | !data->valid) { | ||
993 | |||
994 | for (i = 0; i < TEMP_IDX_LEN; i++) | ||
995 | data->temp[i] = i2c_smbus_read_byte_data(client, | ||
996 | temp_reg[i]); | ||
997 | 978 | ||
998 | data->stat1 = i2c_smbus_read_byte_data(client, | 979 | data = devm_kzalloc(dev, sizeof(struct amc6821_data), GFP_KERNEL); |
999 | AMC6821_REG_STAT1); | 980 | if (!data) |
1000 | data->stat2 = i2c_smbus_read_byte_data(client, | 981 | return -ENOMEM; |
1001 | AMC6821_REG_STAT2); | ||
1002 | 982 | ||
1003 | data->pwm1 = i2c_smbus_read_byte_data(client, | 983 | data->client = client; |
1004 | AMC6821_REG_DCY); | 984 | mutex_init(&data->update_lock); |
1005 | for (i = 0; i < FAN1_IDX_LEN; i++) { | ||
1006 | data->fan[i] = i2c_smbus_read_byte_data( | ||
1007 | client, | ||
1008 | fan_reg_low[i]); | ||
1009 | data->fan[i] += i2c_smbus_read_byte_data( | ||
1010 | client, | ||
1011 | fan_reg_hi[i]) << 8; | ||
1012 | } | ||
1013 | data->fan1_div = i2c_smbus_read_byte_data(client, | ||
1014 | AMC6821_REG_CONF4); | ||
1015 | data->fan1_div = data->fan1_div & AMC6821_CONF4_PSPR ? 4 : 2; | ||
1016 | 985 | ||
1017 | data->pwm1_auto_point_pwm[0] = 0; | 986 | /* |
1018 | data->pwm1_auto_point_pwm[2] = 255; | 987 | * Initialize the amc6821 chip |
1019 | data->pwm1_auto_point_pwm[1] = i2c_smbus_read_byte_data(client, | 988 | */ |
1020 | AMC6821_REG_DCY_LOW_TEMP); | 989 | err = amc6821_init_client(client); |
990 | if (err) | ||
991 | return err; | ||
1021 | 992 | ||
1022 | data->temp1_auto_point_temp[0] = | 993 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
1023 | i2c_smbus_read_byte_data(client, | 994 | data, |
1024 | AMC6821_REG_PSV_TEMP); | 995 | amc6821_groups); |
1025 | data->temp2_auto_point_temp[0] = | 996 | return PTR_ERR_OR_ZERO(hwmon_dev); |
1026 | data->temp1_auto_point_temp[0]; | 997 | } |
1027 | reg = i2c_smbus_read_byte_data(client, | ||
1028 | AMC6821_REG_LTEMP_FAN_CTRL); | ||
1029 | data->temp1_auto_point_temp[1] = (reg & 0xF8) >> 1; | ||
1030 | reg &= 0x07; | ||
1031 | reg = 0x20 >> reg; | ||
1032 | if (reg > 0) | ||
1033 | data->temp1_auto_point_temp[2] = | ||
1034 | data->temp1_auto_point_temp[1] + | ||
1035 | (data->pwm1_auto_point_pwm[2] - | ||
1036 | data->pwm1_auto_point_pwm[1]) / reg; | ||
1037 | else | ||
1038 | data->temp1_auto_point_temp[2] = 255; | ||
1039 | 998 | ||
1040 | reg = i2c_smbus_read_byte_data(client, | 999 | static const struct i2c_device_id amc6821_id[] = { |
1041 | AMC6821_REG_RTEMP_FAN_CTRL); | 1000 | { "amc6821", amc6821 }, |
1042 | data->temp2_auto_point_temp[1] = (reg & 0xF8) >> 1; | 1001 | { } |
1043 | reg &= 0x07; | 1002 | }; |
1044 | reg = 0x20 >> reg; | ||
1045 | if (reg > 0) | ||
1046 | data->temp2_auto_point_temp[2] = | ||
1047 | data->temp2_auto_point_temp[1] + | ||
1048 | (data->pwm1_auto_point_pwm[2] - | ||
1049 | data->pwm1_auto_point_pwm[1]) / reg; | ||
1050 | else | ||
1051 | data->temp2_auto_point_temp[2] = 255; | ||
1052 | 1003 | ||
1053 | reg = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF1); | 1004 | MODULE_DEVICE_TABLE(i2c, amc6821_id); |
1054 | reg = (reg >> 5) & 0x3; | ||
1055 | switch (reg) { | ||
1056 | case 0: /*open loop: software sets pwm1*/ | ||
1057 | data->pwm1_auto_channels_temp = 0; | ||
1058 | data->pwm1_enable = 1; | ||
1059 | break; | ||
1060 | case 2: /*closed loop: remote T (temp2)*/ | ||
1061 | data->pwm1_auto_channels_temp = 2; | ||
1062 | data->pwm1_enable = 2; | ||
1063 | break; | ||
1064 | case 3: /*closed loop: local and remote T (temp2)*/ | ||
1065 | data->pwm1_auto_channels_temp = 3; | ||
1066 | data->pwm1_enable = 3; | ||
1067 | break; | ||
1068 | case 1: /* | ||
1069 | * semi-open loop: software sets rpm, chip controls | ||
1070 | * pwm1, currently not implemented | ||
1071 | */ | ||
1072 | data->pwm1_auto_channels_temp = 0; | ||
1073 | data->pwm1_enable = 0; | ||
1074 | break; | ||
1075 | } | ||
1076 | 1005 | ||
1077 | data->last_updated = jiffies; | 1006 | static struct i2c_driver amc6821_driver = { |
1078 | data->valid = 1; | 1007 | .class = I2C_CLASS_HWMON, |
1079 | } | 1008 | .driver = { |
1080 | mutex_unlock(&data->update_lock); | 1009 | .name = "amc6821", |
1081 | return data; | 1010 | }, |
1082 | } | 1011 | .probe = amc6821_probe, |
1012 | .id_table = amc6821_id, | ||
1013 | .detect = amc6821_detect, | ||
1014 | .address_list = normal_i2c, | ||
1015 | }; | ||
1083 | 1016 | ||
1084 | module_i2c_driver(amc6821_driver); | 1017 | module_i2c_driver(amc6821_driver); |
1085 | 1018 | ||
diff --git a/drivers/hwmon/asc7621.c b/drivers/hwmon/asc7621.c index 71463689d163..c77644d45a02 100644 --- a/drivers/hwmon/asc7621.c +++ b/drivers/hwmon/asc7621.c | |||
@@ -300,7 +300,7 @@ static ssize_t store_fan16(struct device *dev, | |||
300 | * respectively. That doesn't mean that's what the motherboard provides. :) | 300 | * respectively. That doesn't mean that's what the motherboard provides. :) |
301 | */ | 301 | */ |
302 | 302 | ||
303 | static int asc7621_in_scaling[] = { | 303 | static const int asc7621_in_scaling[] = { |
304 | 2500, 2250, 3300, 5000, 12000 | 304 | 2500, 2250, 3300, 5000, 12000 |
305 | }; | 305 | }; |
306 | 306 | ||
@@ -451,7 +451,7 @@ static ssize_t store_temp62(struct device *dev, | |||
451 | * hwmon specs, we synthesize the auto_point_2 from them. | 451 | * hwmon specs, we synthesize the auto_point_2 from them. |
452 | */ | 452 | */ |
453 | 453 | ||
454 | static u32 asc7621_range_map[] = { | 454 | static const u32 asc7621_range_map[] = { |
455 | 2000, 2500, 3330, 4000, 5000, 6670, 8000, 10000, | 455 | 2000, 2500, 3330, 4000, 5000, 6670, 8000, 10000, |
456 | 13330, 16000, 20000, 26670, 32000, 40000, 53330, 80000, | 456 | 13330, 16000, 20000, 26670, 32000, 40000, 53330, 80000, |
457 | }; | 457 | }; |
@@ -512,7 +512,7 @@ static ssize_t show_pwm_ac(struct device *dev, | |||
512 | { | 512 | { |
513 | SETUP_SHOW_DATA_PARAM(dev, attr); | 513 | SETUP_SHOW_DATA_PARAM(dev, attr); |
514 | u8 config, altbit, regval; | 514 | u8 config, altbit, regval; |
515 | u8 map[] = { | 515 | const u8 map[] = { |
516 | 0x01, 0x02, 0x04, 0x1f, 0x00, 0x06, 0x07, 0x10, | 516 | 0x01, 0x02, 0x04, 0x1f, 0x00, 0x06, 0x07, 0x10, |
517 | 0x08, 0x0f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f | 517 | 0x08, 0x0f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f |
518 | }; | 518 | }; |
@@ -533,7 +533,7 @@ static ssize_t store_pwm_ac(struct device *dev, | |||
533 | SETUP_STORE_DATA_PARAM(dev, attr); | 533 | SETUP_STORE_DATA_PARAM(dev, attr); |
534 | unsigned long reqval; | 534 | unsigned long reqval; |
535 | u8 currval, config, altbit, newval; | 535 | u8 currval, config, altbit, newval; |
536 | u16 map[] = { | 536 | const u16 map[] = { |
537 | 0x04, 0x00, 0x01, 0xff, 0x02, 0xff, 0x05, 0x06, | 537 | 0x04, 0x00, 0x01, 0xff, 0x02, 0xff, 0x05, 0x06, |
538 | 0x08, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, | 538 | 0x08, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, |
539 | 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | 539 | 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
@@ -651,7 +651,7 @@ static ssize_t store_pwm_enable(struct device *dev, | |||
651 | return count; | 651 | return count; |
652 | } | 652 | } |
653 | 653 | ||
654 | static u32 asc7621_pwm_freq_map[] = { | 654 | static const u32 asc7621_pwm_freq_map[] = { |
655 | 10, 15, 23, 30, 38, 47, 62, 94, | 655 | 10, 15, 23, 30, 38, 47, 62, 94, |
656 | 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000 | 656 | 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000 |
657 | }; | 657 | }; |
@@ -700,7 +700,7 @@ static ssize_t store_pwm_freq(struct device *dev, | |||
700 | return count; | 700 | return count; |
701 | } | 701 | } |
702 | 702 | ||
703 | static u32 asc7621_pwm_auto_spinup_map[] = { | 703 | static const u32 asc7621_pwm_auto_spinup_map[] = { |
704 | 0, 100, 250, 400, 700, 1000, 2000, 4000 | 704 | 0, 100, 250, 400, 700, 1000, 2000, 4000 |
705 | }; | 705 | }; |
706 | 706 | ||
@@ -749,7 +749,7 @@ static ssize_t store_pwm_ast(struct device *dev, | |||
749 | return count; | 749 | return count; |
750 | } | 750 | } |
751 | 751 | ||
752 | static u32 asc7621_temp_smoothing_time_map[] = { | 752 | static const u32 asc7621_temp_smoothing_time_map[] = { |
753 | 35000, 17600, 11800, 7000, 4400, 3000, 1600, 800 | 753 | 35000, 17600, 11800, 7000, 4400, 3000, 1600, 800 |
754 | }; | 754 | }; |
755 | 755 | ||
diff --git a/drivers/hwmon/atxp1.c b/drivers/hwmon/atxp1.c index 2ae8a304b5ef..4c829bb2f9db 100644 --- a/drivers/hwmon/atxp1.c +++ b/drivers/hwmon/atxp1.c | |||
@@ -46,7 +46,7 @@ MODULE_AUTHOR("Sebastian Witt <se.witt@gmx.net>"); | |||
46 | static const unsigned short normal_i2c[] = { 0x37, 0x4e, I2C_CLIENT_END }; | 46 | static const unsigned short normal_i2c[] = { 0x37, 0x4e, I2C_CLIENT_END }; |
47 | 47 | ||
48 | struct atxp1_data { | 48 | struct atxp1_data { |
49 | struct device *hwmon_dev; | 49 | struct i2c_client *client; |
50 | struct mutex update_lock; | 50 | struct mutex update_lock; |
51 | unsigned long last_updated; | 51 | unsigned long last_updated; |
52 | u8 valid; | 52 | u8 valid; |
@@ -61,11 +61,8 @@ struct atxp1_data { | |||
61 | 61 | ||
62 | static struct atxp1_data *atxp1_update_device(struct device *dev) | 62 | static struct atxp1_data *atxp1_update_device(struct device *dev) |
63 | { | 63 | { |
64 | struct i2c_client *client; | 64 | struct atxp1_data *data = dev_get_drvdata(dev); |
65 | struct atxp1_data *data; | 65 | struct i2c_client *client = data->client; |
66 | |||
67 | client = to_i2c_client(dev); | ||
68 | data = i2c_get_clientdata(client); | ||
69 | 66 | ||
70 | mutex_lock(&data->update_lock); | 67 | mutex_lock(&data->update_lock); |
71 | 68 | ||
@@ -105,15 +102,12 @@ static ssize_t atxp1_storevcore(struct device *dev, | |||
105 | struct device_attribute *attr, | 102 | struct device_attribute *attr, |
106 | const char *buf, size_t count) | 103 | const char *buf, size_t count) |
107 | { | 104 | { |
108 | struct atxp1_data *data; | 105 | struct atxp1_data *data = atxp1_update_device(dev); |
109 | struct i2c_client *client; | 106 | struct i2c_client *client = data->client; |
110 | int vid, cvid; | 107 | int vid, cvid; |
111 | unsigned long vcore; | 108 | unsigned long vcore; |
112 | int err; | 109 | int err; |
113 | 110 | ||
114 | client = to_i2c_client(dev); | ||
115 | data = atxp1_update_device(dev); | ||
116 | |||
117 | err = kstrtoul(buf, 10, &vcore); | 111 | err = kstrtoul(buf, 10, &vcore); |
118 | if (err) | 112 | if (err) |
119 | return err; | 113 | return err; |
@@ -184,14 +178,11 @@ static ssize_t atxp1_storegpio1(struct device *dev, | |||
184 | struct device_attribute *attr, const char *buf, | 178 | struct device_attribute *attr, const char *buf, |
185 | size_t count) | 179 | size_t count) |
186 | { | 180 | { |
187 | struct atxp1_data *data; | 181 | struct atxp1_data *data = atxp1_update_device(dev); |
188 | struct i2c_client *client; | 182 | struct i2c_client *client = data->client; |
189 | unsigned long value; | 183 | unsigned long value; |
190 | int err; | 184 | int err; |
191 | 185 | ||
192 | client = to_i2c_client(dev); | ||
193 | data = atxp1_update_device(dev); | ||
194 | |||
195 | err = kstrtoul(buf, 16, &value); | 186 | err = kstrtoul(buf, 16, &value); |
196 | if (err) | 187 | if (err) |
197 | return err; | 188 | return err; |
@@ -234,7 +225,7 @@ static ssize_t atxp1_storegpio2(struct device *dev, | |||
234 | const char *buf, size_t count) | 225 | const char *buf, size_t count) |
235 | { | 226 | { |
236 | struct atxp1_data *data = atxp1_update_device(dev); | 227 | struct atxp1_data *data = atxp1_update_device(dev); |
237 | struct i2c_client *client = to_i2c_client(dev); | 228 | struct i2c_client *client = data->client; |
238 | unsigned long value; | 229 | unsigned long value; |
239 | int err; | 230 | int err; |
240 | 231 | ||
@@ -260,17 +251,13 @@ static ssize_t atxp1_storegpio2(struct device *dev, | |||
260 | */ | 251 | */ |
261 | static DEVICE_ATTR(gpio2, S_IRUGO | S_IWUSR, atxp1_showgpio2, atxp1_storegpio2); | 252 | static DEVICE_ATTR(gpio2, S_IRUGO | S_IWUSR, atxp1_showgpio2, atxp1_storegpio2); |
262 | 253 | ||
263 | static struct attribute *atxp1_attributes[] = { | 254 | static struct attribute *atxp1_attrs[] = { |
264 | &dev_attr_gpio1.attr, | 255 | &dev_attr_gpio1.attr, |
265 | &dev_attr_gpio2.attr, | 256 | &dev_attr_gpio2.attr, |
266 | &dev_attr_cpu0_vid.attr, | 257 | &dev_attr_cpu0_vid.attr, |
267 | NULL | 258 | NULL |
268 | }; | 259 | }; |
269 | 260 | ATTRIBUTE_GROUPS(atxp1); | |
270 | static const struct attribute_group atxp1_group = { | ||
271 | .attrs = atxp1_attributes, | ||
272 | }; | ||
273 | |||
274 | 261 | ||
275 | /* Return 0 if detection is successful, -ENODEV otherwise */ | 262 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
276 | static int atxp1_detect(struct i2c_client *new_client, | 263 | static int atxp1_detect(struct i2c_client *new_client, |
@@ -314,50 +301,30 @@ static int atxp1_detect(struct i2c_client *new_client, | |||
314 | return 0; | 301 | return 0; |
315 | } | 302 | } |
316 | 303 | ||
317 | static int atxp1_probe(struct i2c_client *new_client, | 304 | static int atxp1_probe(struct i2c_client *client, |
318 | const struct i2c_device_id *id) | 305 | const struct i2c_device_id *id) |
319 | { | 306 | { |
307 | struct device *dev = &client->dev; | ||
320 | struct atxp1_data *data; | 308 | struct atxp1_data *data; |
321 | int err; | 309 | struct device *hwmon_dev; |
322 | 310 | ||
323 | data = devm_kzalloc(&new_client->dev, sizeof(struct atxp1_data), | 311 | data = devm_kzalloc(dev, sizeof(struct atxp1_data), GFP_KERNEL); |
324 | GFP_KERNEL); | ||
325 | if (!data) | 312 | if (!data) |
326 | return -ENOMEM; | 313 | return -ENOMEM; |
327 | 314 | ||
328 | /* Get VRM */ | 315 | /* Get VRM */ |
329 | data->vrm = vid_which_vrm(); | 316 | data->vrm = vid_which_vrm(); |
330 | 317 | ||
331 | i2c_set_clientdata(new_client, data); | 318 | data->client = client; |
332 | mutex_init(&data->update_lock); | 319 | mutex_init(&data->update_lock); |
333 | 320 | ||
334 | /* Register sysfs hooks */ | 321 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
335 | err = sysfs_create_group(&new_client->dev.kobj, &atxp1_group); | 322 | data, |
336 | if (err) | 323 | atxp1_groups); |
337 | return err; | 324 | if (IS_ERR(hwmon_dev)) |
338 | 325 | return PTR_ERR(hwmon_dev); | |
339 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | ||
340 | if (IS_ERR(data->hwmon_dev)) { | ||
341 | err = PTR_ERR(data->hwmon_dev); | ||
342 | goto exit_remove_files; | ||
343 | } | ||
344 | |||
345 | dev_info(&new_client->dev, "Using VRM: %d.%d\n", | ||
346 | data->vrm / 10, data->vrm % 10); | ||
347 | |||
348 | return 0; | ||
349 | |||
350 | exit_remove_files: | ||
351 | sysfs_remove_group(&new_client->dev.kobj, &atxp1_group); | ||
352 | return err; | ||
353 | }; | ||
354 | |||
355 | static int atxp1_remove(struct i2c_client *client) | ||
356 | { | ||
357 | struct atxp1_data *data = i2c_get_clientdata(client); | ||
358 | 326 | ||
359 | hwmon_device_unregister(data->hwmon_dev); | 327 | dev_info(dev, "Using VRM: %d.%d\n", data->vrm / 10, data->vrm % 10); |
360 | sysfs_remove_group(&client->dev.kobj, &atxp1_group); | ||
361 | 328 | ||
362 | return 0; | 329 | return 0; |
363 | }; | 330 | }; |
@@ -374,7 +341,6 @@ static struct i2c_driver atxp1_driver = { | |||
374 | .name = "atxp1", | 341 | .name = "atxp1", |
375 | }, | 342 | }, |
376 | .probe = atxp1_probe, | 343 | .probe = atxp1_probe, |
377 | .remove = atxp1_remove, | ||
378 | .id_table = atxp1_id, | 344 | .id_table = atxp1_id, |
379 | .detect = atxp1_detect, | 345 | .detect = atxp1_detect, |
380 | .address_list = normal_i2c, | 346 | .address_list = normal_i2c, |
diff --git a/drivers/hwmon/ds620.c b/drivers/hwmon/ds620.c index 0918b9136588..edf550fc4eef 100644 --- a/drivers/hwmon/ds620.c +++ b/drivers/hwmon/ds620.c | |||
@@ -67,7 +67,7 @@ static const u8 DS620_REG_TEMP[3] = { | |||
67 | 67 | ||
68 | /* Each client has this additional data */ | 68 | /* Each client has this additional data */ |
69 | struct ds620_data { | 69 | struct ds620_data { |
70 | struct device *hwmon_dev; | 70 | struct i2c_client *client; |
71 | struct mutex update_lock; | 71 | struct mutex update_lock; |
72 | char valid; /* !=0 if following fields are valid */ | 72 | char valid; /* !=0 if following fields are valid */ |
73 | unsigned long last_updated; /* In jiffies */ | 73 | unsigned long last_updated; /* In jiffies */ |
@@ -106,8 +106,8 @@ static void ds620_init_client(struct i2c_client *client) | |||
106 | 106 | ||
107 | static struct ds620_data *ds620_update_client(struct device *dev) | 107 | static struct ds620_data *ds620_update_client(struct device *dev) |
108 | { | 108 | { |
109 | struct i2c_client *client = to_i2c_client(dev); | 109 | struct ds620_data *data = dev_get_drvdata(dev); |
110 | struct ds620_data *data = i2c_get_clientdata(client); | 110 | struct i2c_client *client = data->client; |
111 | struct ds620_data *ret = data; | 111 | struct ds620_data *ret = data; |
112 | 112 | ||
113 | mutex_lock(&data->update_lock); | 113 | mutex_lock(&data->update_lock); |
@@ -158,8 +158,8 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da, | |||
158 | long val; | 158 | long val; |
159 | 159 | ||
160 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | 160 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
161 | struct i2c_client *client = to_i2c_client(dev); | 161 | struct ds620_data *data = dev_get_drvdata(dev); |
162 | struct ds620_data *data = i2c_get_clientdata(client); | 162 | struct i2c_client *client = data->client; |
163 | 163 | ||
164 | res = kstrtol(buf, 10, &val); | 164 | res = kstrtol(buf, 10, &val); |
165 | 165 | ||
@@ -181,13 +181,15 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute *da, | |||
181 | { | 181 | { |
182 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | 182 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
183 | struct ds620_data *data = ds620_update_client(dev); | 183 | struct ds620_data *data = ds620_update_client(dev); |
184 | struct i2c_client *client = to_i2c_client(dev); | 184 | struct i2c_client *client; |
185 | u16 conf, new_conf; | 185 | u16 conf, new_conf; |
186 | int res; | 186 | int res; |
187 | 187 | ||
188 | if (IS_ERR(data)) | 188 | if (IS_ERR(data)) |
189 | return PTR_ERR(data); | 189 | return PTR_ERR(data); |
190 | 190 | ||
191 | client = data->client; | ||
192 | |||
191 | /* reset alarms if necessary */ | 193 | /* reset alarms if necessary */ |
192 | res = i2c_smbus_read_word_swapped(client, DS620_REG_CONF); | 194 | res = i2c_smbus_read_word_swapped(client, DS620_REG_CONF); |
193 | if (res < 0) | 195 | if (res < 0) |
@@ -213,7 +215,7 @@ static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, | |||
213 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, | 215 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, |
214 | DS620_REG_CONFIG_THF); | 216 | DS620_REG_CONFIG_THF); |
215 | 217 | ||
216 | static struct attribute *ds620_attributes[] = { | 218 | static struct attribute *ds620_attrs[] = { |
217 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 219 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
218 | &sensor_dev_attr_temp1_min.dev_attr.attr, | 220 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
219 | &sensor_dev_attr_temp1_max.dev_attr.attr, | 221 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
@@ -222,55 +224,28 @@ static struct attribute *ds620_attributes[] = { | |||
222 | NULL | 224 | NULL |
223 | }; | 225 | }; |
224 | 226 | ||
225 | static const struct attribute_group ds620_group = { | 227 | ATTRIBUTE_GROUPS(ds620); |
226 | .attrs = ds620_attributes, | ||
227 | }; | ||
228 | 228 | ||
229 | static int ds620_probe(struct i2c_client *client, | 229 | static int ds620_probe(struct i2c_client *client, |
230 | const struct i2c_device_id *id) | 230 | const struct i2c_device_id *id) |
231 | { | 231 | { |
232 | struct device *dev = &client->dev; | ||
233 | struct device *hwmon_dev; | ||
232 | struct ds620_data *data; | 234 | struct ds620_data *data; |
233 | int err; | ||
234 | 235 | ||
235 | data = devm_kzalloc(&client->dev, sizeof(struct ds620_data), | 236 | data = devm_kzalloc(dev, sizeof(struct ds620_data), GFP_KERNEL); |
236 | GFP_KERNEL); | ||
237 | if (!data) | 237 | if (!data) |
238 | return -ENOMEM; | 238 | return -ENOMEM; |
239 | 239 | ||
240 | i2c_set_clientdata(client, data); | 240 | data->client = client; |
241 | mutex_init(&data->update_lock); | 241 | mutex_init(&data->update_lock); |
242 | 242 | ||
243 | /* Initialize the DS620 chip */ | 243 | /* Initialize the DS620 chip */ |
244 | ds620_init_client(client); | 244 | ds620_init_client(client); |
245 | 245 | ||
246 | /* Register sysfs hooks */ | 246 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
247 | err = sysfs_create_group(&client->dev.kobj, &ds620_group); | 247 | data, ds620_groups); |
248 | if (err) | 248 | return PTR_ERR_OR_ZERO(hwmon_dev); |
249 | return err; | ||
250 | |||
251 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
252 | if (IS_ERR(data->hwmon_dev)) { | ||
253 | err = PTR_ERR(data->hwmon_dev); | ||
254 | goto exit_remove_files; | ||
255 | } | ||
256 | |||
257 | dev_info(&client->dev, "temperature sensor found\n"); | ||
258 | |||
259 | return 0; | ||
260 | |||
261 | exit_remove_files: | ||
262 | sysfs_remove_group(&client->dev.kobj, &ds620_group); | ||
263 | return err; | ||
264 | } | ||
265 | |||
266 | static int ds620_remove(struct i2c_client *client) | ||
267 | { | ||
268 | struct ds620_data *data = i2c_get_clientdata(client); | ||
269 | |||
270 | hwmon_device_unregister(data->hwmon_dev); | ||
271 | sysfs_remove_group(&client->dev.kobj, &ds620_group); | ||
272 | |||
273 | return 0; | ||
274 | } | 249 | } |
275 | 250 | ||
276 | static const struct i2c_device_id ds620_id[] = { | 251 | static const struct i2c_device_id ds620_id[] = { |
@@ -287,7 +262,6 @@ static struct i2c_driver ds620_driver = { | |||
287 | .name = "ds620", | 262 | .name = "ds620", |
288 | }, | 263 | }, |
289 | .probe = ds620_probe, | 264 | .probe = ds620_probe, |
290 | .remove = ds620_remove, | ||
291 | .id_table = ds620_id, | 265 | .id_table = ds620_id, |
292 | }; | 266 | }; |
293 | 267 | ||
diff --git a/drivers/hwmon/emc1403.c b/drivers/hwmon/emc1403.c index a37b2204a418..1ea7ca510f84 100644 --- a/drivers/hwmon/emc1403.c +++ b/drivers/hwmon/emc1403.c | |||
@@ -416,7 +416,7 @@ static bool emc1403_regmap_is_volatile(struct device *dev, unsigned int reg) | |||
416 | } | 416 | } |
417 | } | 417 | } |
418 | 418 | ||
419 | static struct regmap_config emc1403_regmap_config = { | 419 | static const struct regmap_config emc1403_regmap_config = { |
420 | .reg_bits = 8, | 420 | .reg_bits = 8, |
421 | .val_bits = 8, | 421 | .val_bits = 8, |
422 | .cache_type = REGCACHE_RBTREE, | 422 | .cache_type = REGCACHE_RBTREE, |
diff --git a/drivers/hwmon/emc2103.c b/drivers/hwmon/emc2103.c index 78002de46cb6..952fe692d764 100644 --- a/drivers/hwmon/emc2103.c +++ b/drivers/hwmon/emc2103.c | |||
@@ -66,7 +66,8 @@ struct temperature { | |||
66 | }; | 66 | }; |
67 | 67 | ||
68 | struct emc2103_data { | 68 | struct emc2103_data { |
69 | struct device *hwmon_dev; | 69 | struct i2c_client *client; |
70 | const struct attribute_group *groups[4]; | ||
70 | struct mutex update_lock; | 71 | struct mutex update_lock; |
71 | bool valid; /* registers are valid */ | 72 | bool valid; /* registers are valid */ |
72 | bool fan_rpm_control; | 73 | bool fan_rpm_control; |
@@ -146,8 +147,8 @@ static void read_fan_config_from_i2c(struct i2c_client *client) | |||
146 | 147 | ||
147 | static struct emc2103_data *emc2103_update_device(struct device *dev) | 148 | static struct emc2103_data *emc2103_update_device(struct device *dev) |
148 | { | 149 | { |
149 | struct i2c_client *client = to_i2c_client(dev); | 150 | struct emc2103_data *data = dev_get_drvdata(dev); |
150 | struct emc2103_data *data = i2c_get_clientdata(client); | 151 | struct i2c_client *client = data->client; |
151 | 152 | ||
152 | mutex_lock(&data->update_lock); | 153 | mutex_lock(&data->update_lock); |
153 | 154 | ||
@@ -242,8 +243,8 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *da, | |||
242 | const char *buf, size_t count) | 243 | const char *buf, size_t count) |
243 | { | 244 | { |
244 | int nr = to_sensor_dev_attr(da)->index; | 245 | int nr = to_sensor_dev_attr(da)->index; |
245 | struct i2c_client *client = to_i2c_client(dev); | 246 | struct emc2103_data *data = dev_get_drvdata(dev); |
246 | struct emc2103_data *data = i2c_get_clientdata(client); | 247 | struct i2c_client *client = data->client; |
247 | long val; | 248 | long val; |
248 | 249 | ||
249 | int result = kstrtol(buf, 10, &val); | 250 | int result = kstrtol(buf, 10, &val); |
@@ -264,8 +265,8 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *da, | |||
264 | const char *buf, size_t count) | 265 | const char *buf, size_t count) |
265 | { | 266 | { |
266 | int nr = to_sensor_dev_attr(da)->index; | 267 | int nr = to_sensor_dev_attr(da)->index; |
267 | struct i2c_client *client = to_i2c_client(dev); | 268 | struct emc2103_data *data = dev_get_drvdata(dev); |
268 | struct emc2103_data *data = i2c_get_clientdata(client); | 269 | struct i2c_client *client = data->client; |
269 | long val; | 270 | long val; |
270 | 271 | ||
271 | int result = kstrtol(buf, 10, &val); | 272 | int result = kstrtol(buf, 10, &val); |
@@ -310,7 +311,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *da, | |||
310 | const char *buf, size_t count) | 311 | const char *buf, size_t count) |
311 | { | 312 | { |
312 | struct emc2103_data *data = emc2103_update_device(dev); | 313 | struct emc2103_data *data = emc2103_update_device(dev); |
313 | struct i2c_client *client = to_i2c_client(dev); | 314 | struct i2c_client *client = data->client; |
314 | int new_range_bits, old_div = 8 / data->fan_multiplier; | 315 | int new_range_bits, old_div = 8 / data->fan_multiplier; |
315 | long new_div; | 316 | long new_div; |
316 | 317 | ||
@@ -385,7 +386,7 @@ static ssize_t set_fan_target(struct device *dev, struct device_attribute *da, | |||
385 | const char *buf, size_t count) | 386 | const char *buf, size_t count) |
386 | { | 387 | { |
387 | struct emc2103_data *data = emc2103_update_device(dev); | 388 | struct emc2103_data *data = emc2103_update_device(dev); |
388 | struct i2c_client *client = to_i2c_client(dev); | 389 | struct i2c_client *client = data->client; |
389 | unsigned long rpm_target; | 390 | unsigned long rpm_target; |
390 | 391 | ||
391 | int result = kstrtoul(buf, 10, &rpm_target); | 392 | int result = kstrtoul(buf, 10, &rpm_target); |
@@ -428,8 +429,8 @@ show_pwm_enable(struct device *dev, struct device_attribute *da, char *buf) | |||
428 | static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *da, | 429 | static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *da, |
429 | const char *buf, size_t count) | 430 | const char *buf, size_t count) |
430 | { | 431 | { |
431 | struct i2c_client *client = to_i2c_client(dev); | 432 | struct emc2103_data *data = dev_get_drvdata(dev); |
432 | struct emc2103_data *data = i2c_get_clientdata(client); | 433 | struct i2c_client *client = data->client; |
433 | long new_value; | 434 | long new_value; |
434 | u8 conf_reg; | 435 | u8 conf_reg; |
435 | 436 | ||
@@ -580,7 +581,8 @@ static int | |||
580 | emc2103_probe(struct i2c_client *client, const struct i2c_device_id *id) | 581 | emc2103_probe(struct i2c_client *client, const struct i2c_device_id *id) |
581 | { | 582 | { |
582 | struct emc2103_data *data; | 583 | struct emc2103_data *data; |
583 | int status; | 584 | struct device *hwmon_dev; |
585 | int status, idx = 0; | ||
584 | 586 | ||
585 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 587 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
586 | return -EIO; | 588 | return -EIO; |
@@ -591,6 +593,7 @@ emc2103_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
591 | return -ENOMEM; | 593 | return -ENOMEM; |
592 | 594 | ||
593 | i2c_set_clientdata(client, data); | 595 | i2c_set_clientdata(client, data); |
596 | data->client = client; | ||
594 | mutex_init(&data->update_lock); | 597 | mutex_init(&data->update_lock); |
595 | 598 | ||
596 | /* 2103-2 and 2103-4 have 3 external diodes, 2103-1 has 1 */ | 599 | /* 2103-2 and 2103-4 have 3 external diodes, 2103-1 has 1 */ |
@@ -624,60 +627,21 @@ emc2103_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
624 | } | 627 | } |
625 | } | 628 | } |
626 | 629 | ||
627 | /* Register sysfs hooks */ | 630 | /* sysfs hooks */ |
628 | status = sysfs_create_group(&client->dev.kobj, &emc2103_group); | 631 | data->groups[idx++] = &emc2103_group; |
629 | if (status) | ||
630 | return status; | ||
631 | |||
632 | if (data->temp_count >= 3) { | ||
633 | status = sysfs_create_group(&client->dev.kobj, | ||
634 | &emc2103_temp3_group); | ||
635 | if (status) | ||
636 | goto exit_remove; | ||
637 | } | ||
638 | |||
639 | if (data->temp_count == 4) { | ||
640 | status = sysfs_create_group(&client->dev.kobj, | ||
641 | &emc2103_temp4_group); | ||
642 | if (status) | ||
643 | goto exit_remove_temp3; | ||
644 | } | ||
645 | |||
646 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
647 | if (IS_ERR(data->hwmon_dev)) { | ||
648 | status = PTR_ERR(data->hwmon_dev); | ||
649 | goto exit_remove_temp4; | ||
650 | } | ||
651 | |||
652 | dev_info(&client->dev, "%s: sensor '%s'\n", | ||
653 | dev_name(data->hwmon_dev), client->name); | ||
654 | |||
655 | return 0; | ||
656 | |||
657 | exit_remove_temp4: | ||
658 | if (data->temp_count == 4) | ||
659 | sysfs_remove_group(&client->dev.kobj, &emc2103_temp4_group); | ||
660 | exit_remove_temp3: | ||
661 | if (data->temp_count >= 3) | 632 | if (data->temp_count >= 3) |
662 | sysfs_remove_group(&client->dev.kobj, &emc2103_temp3_group); | 633 | data->groups[idx++] = &emc2103_temp3_group; |
663 | exit_remove: | ||
664 | sysfs_remove_group(&client->dev.kobj, &emc2103_group); | ||
665 | return status; | ||
666 | } | ||
667 | |||
668 | static int emc2103_remove(struct i2c_client *client) | ||
669 | { | ||
670 | struct emc2103_data *data = i2c_get_clientdata(client); | ||
671 | |||
672 | hwmon_device_unregister(data->hwmon_dev); | ||
673 | |||
674 | if (data->temp_count == 4) | 634 | if (data->temp_count == 4) |
675 | sysfs_remove_group(&client->dev.kobj, &emc2103_temp4_group); | 635 | data->groups[idx++] = &emc2103_temp4_group; |
676 | 636 | ||
677 | if (data->temp_count >= 3) | 637 | hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev, |
678 | sysfs_remove_group(&client->dev.kobj, &emc2103_temp3_group); | 638 | client->name, data, |
639 | data->groups); | ||
640 | if (IS_ERR(hwmon_dev)) | ||
641 | return PTR_ERR(hwmon_dev); | ||
679 | 642 | ||
680 | sysfs_remove_group(&client->dev.kobj, &emc2103_group); | 643 | dev_info(&client->dev, "%s: sensor '%s'\n", |
644 | dev_name(hwmon_dev), client->name); | ||
681 | 645 | ||
682 | return 0; | 646 | return 0; |
683 | } | 647 | } |
@@ -717,7 +681,6 @@ static struct i2c_driver emc2103_driver = { | |||
717 | .name = "emc2103", | 681 | .name = "emc2103", |
718 | }, | 682 | }, |
719 | .probe = emc2103_probe, | 683 | .probe = emc2103_probe, |
720 | .remove = emc2103_remove, | ||
721 | .id_table = emc2103_ids, | 684 | .id_table = emc2103_ids, |
722 | .detect = emc2103_detect, | 685 | .detect = emc2103_detect, |
723 | .address_list = normal_i2c, | 686 | .address_list = normal_i2c, |
diff --git a/drivers/hwmon/emc6w201.c b/drivers/hwmon/emc6w201.c index f76a74cb6dc4..e87da902f3ae 100644 --- a/drivers/hwmon/emc6w201.c +++ b/drivers/hwmon/emc6w201.c | |||
@@ -56,7 +56,7 @@ enum subfeature { input, min, max }; | |||
56 | */ | 56 | */ |
57 | 57 | ||
58 | struct emc6w201_data { | 58 | struct emc6w201_data { |
59 | struct device *hwmon_dev; | 59 | struct i2c_client *client; |
60 | struct mutex update_lock; | 60 | struct mutex update_lock; |
61 | char valid; /* zero until following fields are valid */ | 61 | char valid; /* zero until following fields are valid */ |
62 | unsigned long last_updated; /* in jiffies */ | 62 | unsigned long last_updated; /* in jiffies */ |
@@ -134,8 +134,8 @@ static int emc6w201_write8(struct i2c_client *client, u8 reg, u8 val) | |||
134 | 134 | ||
135 | static struct emc6w201_data *emc6w201_update_device(struct device *dev) | 135 | static struct emc6w201_data *emc6w201_update_device(struct device *dev) |
136 | { | 136 | { |
137 | struct i2c_client *client = to_i2c_client(dev); | 137 | struct emc6w201_data *data = dev_get_drvdata(dev); |
138 | struct emc6w201_data *data = i2c_get_clientdata(client); | 138 | struct i2c_client *client = data->client; |
139 | int nr; | 139 | int nr; |
140 | 140 | ||
141 | mutex_lock(&data->update_lock); | 141 | mutex_lock(&data->update_lock); |
@@ -203,8 +203,8 @@ static ssize_t show_in(struct device *dev, struct device_attribute *devattr, | |||
203 | static ssize_t set_in(struct device *dev, struct device_attribute *devattr, | 203 | static ssize_t set_in(struct device *dev, struct device_attribute *devattr, |
204 | const char *buf, size_t count) | 204 | const char *buf, size_t count) |
205 | { | 205 | { |
206 | struct i2c_client *client = to_i2c_client(dev); | 206 | struct emc6w201_data *data = dev_get_drvdata(dev); |
207 | struct emc6w201_data *data = i2c_get_clientdata(client); | 207 | struct i2c_client *client = data->client; |
208 | int sf = to_sensor_dev_attr_2(devattr)->index; | 208 | int sf = to_sensor_dev_attr_2(devattr)->index; |
209 | int nr = to_sensor_dev_attr_2(devattr)->nr; | 209 | int nr = to_sensor_dev_attr_2(devattr)->nr; |
210 | int err; | 210 | int err; |
@@ -240,8 +240,8 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, | |||
240 | static ssize_t set_temp(struct device *dev, struct device_attribute *devattr, | 240 | static ssize_t set_temp(struct device *dev, struct device_attribute *devattr, |
241 | const char *buf, size_t count) | 241 | const char *buf, size_t count) |
242 | { | 242 | { |
243 | struct i2c_client *client = to_i2c_client(dev); | 243 | struct emc6w201_data *data = dev_get_drvdata(dev); |
244 | struct emc6w201_data *data = i2c_get_clientdata(client); | 244 | struct i2c_client *client = data->client; |
245 | int sf = to_sensor_dev_attr_2(devattr)->index; | 245 | int sf = to_sensor_dev_attr_2(devattr)->index; |
246 | int nr = to_sensor_dev_attr_2(devattr)->nr; | 246 | int nr = to_sensor_dev_attr_2(devattr)->nr; |
247 | int err; | 247 | int err; |
@@ -283,8 +283,8 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, | |||
283 | static ssize_t set_fan(struct device *dev, struct device_attribute *devattr, | 283 | static ssize_t set_fan(struct device *dev, struct device_attribute *devattr, |
284 | const char *buf, size_t count) | 284 | const char *buf, size_t count) |
285 | { | 285 | { |
286 | struct i2c_client *client = to_i2c_client(dev); | 286 | struct emc6w201_data *data = dev_get_drvdata(dev); |
287 | struct emc6w201_data *data = i2c_get_clientdata(client); | 287 | struct i2c_client *client = data->client; |
288 | int sf = to_sensor_dev_attr_2(devattr)->index; | 288 | int sf = to_sensor_dev_attr_2(devattr)->index; |
289 | int nr = to_sensor_dev_attr_2(devattr)->nr; | 289 | int nr = to_sensor_dev_attr_2(devattr)->nr; |
290 | int err; | 290 | int err; |
@@ -388,7 +388,7 @@ static SENSOR_DEVICE_ATTR_2(fan5_input, S_IRUGO, show_fan, NULL, 4, input); | |||
388 | static SENSOR_DEVICE_ATTR_2(fan5_min, S_IRUGO | S_IWUSR, show_fan, set_fan, | 388 | static SENSOR_DEVICE_ATTR_2(fan5_min, S_IRUGO | S_IWUSR, show_fan, set_fan, |
389 | 4, min); | 389 | 4, min); |
390 | 390 | ||
391 | static struct attribute *emc6w201_attributes[] = { | 391 | static struct attribute *emc6w201_attrs[] = { |
392 | &sensor_dev_attr_in0_input.dev_attr.attr, | 392 | &sensor_dev_attr_in0_input.dev_attr.attr, |
393 | &sensor_dev_attr_in0_min.dev_attr.attr, | 393 | &sensor_dev_attr_in0_min.dev_attr.attr, |
394 | &sensor_dev_attr_in0_max.dev_attr.attr, | 394 | &sensor_dev_attr_in0_max.dev_attr.attr, |
@@ -440,9 +440,7 @@ static struct attribute *emc6w201_attributes[] = { | |||
440 | NULL | 440 | NULL |
441 | }; | 441 | }; |
442 | 442 | ||
443 | static const struct attribute_group emc6w201_group = { | 443 | ATTRIBUTE_GROUPS(emc6w201); |
444 | .attrs = emc6w201_attributes, | ||
445 | }; | ||
446 | 444 | ||
447 | /* | 445 | /* |
448 | * Driver interface | 446 | * Driver interface |
@@ -488,44 +486,21 @@ static int emc6w201_detect(struct i2c_client *client, | |||
488 | static int emc6w201_probe(struct i2c_client *client, | 486 | static int emc6w201_probe(struct i2c_client *client, |
489 | const struct i2c_device_id *id) | 487 | const struct i2c_device_id *id) |
490 | { | 488 | { |
489 | struct device *dev = &client->dev; | ||
491 | struct emc6w201_data *data; | 490 | struct emc6w201_data *data; |
492 | int err; | 491 | struct device *hwmon_dev; |
493 | 492 | ||
494 | data = devm_kzalloc(&client->dev, sizeof(struct emc6w201_data), | 493 | data = devm_kzalloc(dev, sizeof(struct emc6w201_data), GFP_KERNEL); |
495 | GFP_KERNEL); | ||
496 | if (!data) | 494 | if (!data) |
497 | return -ENOMEM; | 495 | return -ENOMEM; |
498 | 496 | ||
499 | i2c_set_clientdata(client, data); | 497 | data->client = client; |
500 | mutex_init(&data->update_lock); | 498 | mutex_init(&data->update_lock); |
501 | 499 | ||
502 | /* Create sysfs attribute */ | 500 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
503 | err = sysfs_create_group(&client->dev.kobj, &emc6w201_group); | 501 | data, |
504 | if (err) | 502 | emc6w201_groups); |
505 | return err; | 503 | return PTR_ERR_OR_ZERO(hwmon_dev); |
506 | |||
507 | /* Expose as a hwmon device */ | ||
508 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
509 | if (IS_ERR(data->hwmon_dev)) { | ||
510 | err = PTR_ERR(data->hwmon_dev); | ||
511 | goto exit_remove; | ||
512 | } | ||
513 | |||
514 | return 0; | ||
515 | |||
516 | exit_remove: | ||
517 | sysfs_remove_group(&client->dev.kobj, &emc6w201_group); | ||
518 | return err; | ||
519 | } | ||
520 | |||
521 | static int emc6w201_remove(struct i2c_client *client) | ||
522 | { | ||
523 | struct emc6w201_data *data = i2c_get_clientdata(client); | ||
524 | |||
525 | hwmon_device_unregister(data->hwmon_dev); | ||
526 | sysfs_remove_group(&client->dev.kobj, &emc6w201_group); | ||
527 | |||
528 | return 0; | ||
529 | } | 504 | } |
530 | 505 | ||
531 | static const struct i2c_device_id emc6w201_id[] = { | 506 | static const struct i2c_device_id emc6w201_id[] = { |
@@ -540,7 +515,6 @@ static struct i2c_driver emc6w201_driver = { | |||
540 | .name = "emc6w201", | 515 | .name = "emc6w201", |
541 | }, | 516 | }, |
542 | .probe = emc6w201_probe, | 517 | .probe = emc6w201_probe, |
543 | .remove = emc6w201_remove, | ||
544 | .id_table = emc6w201_id, | 518 | .id_table = emc6w201_id, |
545 | .detect = emc6w201_detect, | 519 | .detect = emc6w201_detect, |
546 | .address_list = normal_i2c, | 520 | .address_list = normal_i2c, |
diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c index 6040121a405a..4a7cbfad1d74 100644 --- a/drivers/hwmon/fam15h_power.c +++ b/drivers/hwmon/fam15h_power.c | |||
@@ -31,9 +31,6 @@ MODULE_DESCRIPTION("AMD Family 15h CPU processor power monitor"); | |||
31 | MODULE_AUTHOR("Andreas Herrmann <herrmann.der.user@googlemail.com>"); | 31 | MODULE_AUTHOR("Andreas Herrmann <herrmann.der.user@googlemail.com>"); |
32 | MODULE_LICENSE("GPL"); | 32 | MODULE_LICENSE("GPL"); |
33 | 33 | ||
34 | /* Family 16h Northbridge's function 4 PCI ID */ | ||
35 | #define PCI_DEVICE_ID_AMD_16H_NB_F4 0x1534 | ||
36 | |||
37 | /* D18F3 */ | 34 | /* D18F3 */ |
38 | #define REG_NORTHBRIDGE_CAP 0xe8 | 35 | #define REG_NORTHBRIDGE_CAP 0xe8 |
39 | 36 | ||
@@ -45,7 +42,7 @@ MODULE_LICENSE("GPL"); | |||
45 | #define REG_TDP_LIMIT3 0xe8 | 42 | #define REG_TDP_LIMIT3 0xe8 |
46 | 43 | ||
47 | struct fam15h_power_data { | 44 | struct fam15h_power_data { |
48 | struct device *hwmon_dev; | 45 | struct pci_dev *pdev; |
49 | unsigned int tdp_to_watts; | 46 | unsigned int tdp_to_watts; |
50 | unsigned int base_tdp; | 47 | unsigned int base_tdp; |
51 | unsigned int processor_pwr_watts; | 48 | unsigned int processor_pwr_watts; |
@@ -57,8 +54,8 @@ static ssize_t show_power(struct device *dev, | |||
57 | u32 val, tdp_limit, running_avg_range; | 54 | u32 val, tdp_limit, running_avg_range; |
58 | s32 running_avg_capture; | 55 | s32 running_avg_capture; |
59 | u64 curr_pwr_watts; | 56 | u64 curr_pwr_watts; |
60 | struct pci_dev *f4 = to_pci_dev(dev); | ||
61 | struct fam15h_power_data *data = dev_get_drvdata(dev); | 57 | struct fam15h_power_data *data = dev_get_drvdata(dev); |
58 | struct pci_dev *f4 = data->pdev; | ||
62 | 59 | ||
63 | pci_bus_read_config_dword(f4->bus, PCI_DEVFN(PCI_SLOT(f4->devfn), 5), | 60 | pci_bus_read_config_dword(f4->bus, PCI_DEVFN(PCI_SLOT(f4->devfn), 5), |
64 | REG_TDP_RUNNING_AVERAGE, &val); | 61 | REG_TDP_RUNNING_AVERAGE, &val); |
@@ -96,23 +93,13 @@ static ssize_t show_power_crit(struct device *dev, | |||
96 | } | 93 | } |
97 | static DEVICE_ATTR(power1_crit, S_IRUGO, show_power_crit, NULL); | 94 | static DEVICE_ATTR(power1_crit, S_IRUGO, show_power_crit, NULL); |
98 | 95 | ||
99 | static ssize_t show_name(struct device *dev, | ||
100 | struct device_attribute *attr, char *buf) | ||
101 | { | ||
102 | return sprintf(buf, "fam15h_power\n"); | ||
103 | } | ||
104 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | ||
105 | |||
106 | static struct attribute *fam15h_power_attrs[] = { | 96 | static struct attribute *fam15h_power_attrs[] = { |
107 | &dev_attr_power1_input.attr, | 97 | &dev_attr_power1_input.attr, |
108 | &dev_attr_power1_crit.attr, | 98 | &dev_attr_power1_crit.attr, |
109 | &dev_attr_name.attr, | ||
110 | NULL | 99 | NULL |
111 | }; | 100 | }; |
112 | 101 | ||
113 | static const struct attribute_group fam15h_power_attr_group = { | 102 | ATTRIBUTE_GROUPS(fam15h_power); |
114 | .attrs = fam15h_power_attrs, | ||
115 | }; | ||
116 | 103 | ||
117 | static bool fam15h_power_is_internal_node0(struct pci_dev *f4) | 104 | static bool fam15h_power_is_internal_node0(struct pci_dev *f4) |
118 | { | 105 | { |
@@ -202,7 +189,7 @@ static int fam15h_power_probe(struct pci_dev *pdev, | |||
202 | { | 189 | { |
203 | struct fam15h_power_data *data; | 190 | struct fam15h_power_data *data; |
204 | struct device *dev = &pdev->dev; | 191 | struct device *dev = &pdev->dev; |
205 | int err; | 192 | struct device *hwmon_dev; |
206 | 193 | ||
207 | /* | 194 | /* |
208 | * though we ignore every other northbridge, we still have to | 195 | * though we ignore every other northbridge, we still have to |
@@ -219,34 +206,12 @@ static int fam15h_power_probe(struct pci_dev *pdev, | |||
219 | return -ENOMEM; | 206 | return -ENOMEM; |
220 | 207 | ||
221 | fam15h_power_init_data(pdev, data); | 208 | fam15h_power_init_data(pdev, data); |
209 | data->pdev = pdev; | ||
222 | 210 | ||
223 | dev_set_drvdata(dev, data); | 211 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, "fam15h_power", |
224 | err = sysfs_create_group(&dev->kobj, &fam15h_power_attr_group); | 212 | data, |
225 | if (err) | 213 | fam15h_power_groups); |
226 | return err; | 214 | return PTR_ERR_OR_ZERO(hwmon_dev); |
227 | |||
228 | data->hwmon_dev = hwmon_device_register(dev); | ||
229 | if (IS_ERR(data->hwmon_dev)) { | ||
230 | err = PTR_ERR(data->hwmon_dev); | ||
231 | goto exit_remove_group; | ||
232 | } | ||
233 | |||
234 | return 0; | ||
235 | |||
236 | exit_remove_group: | ||
237 | sysfs_remove_group(&dev->kobj, &fam15h_power_attr_group); | ||
238 | return err; | ||
239 | } | ||
240 | |||
241 | static void fam15h_power_remove(struct pci_dev *pdev) | ||
242 | { | ||
243 | struct device *dev; | ||
244 | struct fam15h_power_data *data; | ||
245 | |||
246 | dev = &pdev->dev; | ||
247 | data = dev_get_drvdata(dev); | ||
248 | hwmon_device_unregister(data->hwmon_dev); | ||
249 | sysfs_remove_group(&dev->kobj, &fam15h_power_attr_group); | ||
250 | } | 215 | } |
251 | 216 | ||
252 | static const struct pci_device_id fam15h_power_id_table[] = { | 217 | static const struct pci_device_id fam15h_power_id_table[] = { |
@@ -260,7 +225,6 @@ static struct pci_driver fam15h_power_driver = { | |||
260 | .name = "fam15h_power", | 225 | .name = "fam15h_power", |
261 | .id_table = fam15h_power_id_table, | 226 | .id_table = fam15h_power_id_table, |
262 | .probe = fam15h_power_probe, | 227 | .probe = fam15h_power_probe, |
263 | .remove = fam15h_power_remove, | ||
264 | .resume = fam15h_power_resume, | 228 | .resume = fam15h_power_resume, |
265 | }; | 229 | }; |
266 | 230 | ||
diff --git a/drivers/hwmon/g760a.c b/drivers/hwmon/g760a.c index ea6480b80e7f..ec6a77da411a 100644 --- a/drivers/hwmon/g760a.c +++ b/drivers/hwmon/g760a.c | |||
@@ -24,12 +24,6 @@ | |||
24 | #include <linux/mutex.h> | 24 | #include <linux/mutex.h> |
25 | #include <linux/sysfs.h> | 25 | #include <linux/sysfs.h> |
26 | 26 | ||
27 | static const struct i2c_device_id g760a_id[] = { | ||
28 | { "g760a", 0 }, | ||
29 | { } | ||
30 | }; | ||
31 | MODULE_DEVICE_TABLE(i2c, g760a_id); | ||
32 | |||
33 | enum g760a_regs { | 27 | enum g760a_regs { |
34 | G760A_REG_SET_CNT = 0x00, | 28 | G760A_REG_SET_CNT = 0x00, |
35 | G760A_REG_ACT_CNT = 0x01, | 29 | G760A_REG_ACT_CNT = 0x01, |
@@ -44,7 +38,6 @@ enum g760a_regs { | |||
44 | 38 | ||
45 | struct g760a_data { | 39 | struct g760a_data { |
46 | struct i2c_client *client; | 40 | struct i2c_client *client; |
47 | struct device *hwmon_dev; | ||
48 | struct mutex update_lock; | 41 | struct mutex update_lock; |
49 | 42 | ||
50 | /* board specific parameters */ | 43 | /* board specific parameters */ |
@@ -74,20 +67,6 @@ static inline unsigned int rpm_from_cnt(u8 val, u32 clk, u16 div) | |||
74 | return ((val == 0x00) ? 0 : ((clk*30)/(val*div))); | 67 | return ((val == 0x00) ? 0 : ((clk*30)/(val*div))); |
75 | } | 68 | } |
76 | 69 | ||
77 | /* new-style driver model */ | ||
78 | static int g760a_probe(struct i2c_client *client, | ||
79 | const struct i2c_device_id *id); | ||
80 | static int g760a_remove(struct i2c_client *client); | ||
81 | |||
82 | static struct i2c_driver g760a_driver = { | ||
83 | .driver = { | ||
84 | .name = "g760a", | ||
85 | }, | ||
86 | .probe = g760a_probe, | ||
87 | .remove = g760a_remove, | ||
88 | .id_table = g760a_id, | ||
89 | }; | ||
90 | |||
91 | /* read/write wrappers */ | 70 | /* read/write wrappers */ |
92 | static int g760a_read_value(struct i2c_client *client, enum g760a_regs reg) | 71 | static int g760a_read_value(struct i2c_client *client, enum g760a_regs reg) |
93 | { | 72 | { |
@@ -106,8 +85,8 @@ static int g760a_write_value(struct i2c_client *client, enum g760a_regs reg, | |||
106 | 85 | ||
107 | static struct g760a_data *g760a_update_client(struct device *dev) | 86 | static struct g760a_data *g760a_update_client(struct device *dev) |
108 | { | 87 | { |
109 | struct i2c_client *client = to_i2c_client(dev); | 88 | struct g760a_data *data = dev_get_drvdata(dev); |
110 | struct g760a_data *data = i2c_get_clientdata(client); | 89 | struct i2c_client *client = data->client; |
111 | 90 | ||
112 | mutex_lock(&data->update_lock); | 91 | mutex_lock(&data->update_lock); |
113 | 92 | ||
@@ -163,8 +142,8 @@ static ssize_t get_pwm(struct device *dev, struct device_attribute *da, | |||
163 | static ssize_t set_pwm(struct device *dev, struct device_attribute *da, | 142 | static ssize_t set_pwm(struct device *dev, struct device_attribute *da, |
164 | const char *buf, size_t count) | 143 | const char *buf, size_t count) |
165 | { | 144 | { |
166 | struct i2c_client *client = to_i2c_client(dev); | ||
167 | struct g760a_data *data = g760a_update_client(dev); | 145 | struct g760a_data *data = g760a_update_client(dev); |
146 | struct i2c_client *client = data->client; | ||
168 | unsigned long val; | 147 | unsigned long val; |
169 | 148 | ||
170 | if (kstrtoul(buf, 10, &val)) | 149 | if (kstrtoul(buf, 10, &val)) |
@@ -182,16 +161,14 @@ static DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, get_pwm, set_pwm); | |||
182 | static DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL); | 161 | static DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL); |
183 | static DEVICE_ATTR(fan1_alarm, S_IRUGO, show_fan_alarm, NULL); | 162 | static DEVICE_ATTR(fan1_alarm, S_IRUGO, show_fan_alarm, NULL); |
184 | 163 | ||
185 | static struct attribute *g760a_attributes[] = { | 164 | static struct attribute *g760a_attrs[] = { |
186 | &dev_attr_pwm1.attr, | 165 | &dev_attr_pwm1.attr, |
187 | &dev_attr_fan1_input.attr, | 166 | &dev_attr_fan1_input.attr, |
188 | &dev_attr_fan1_alarm.attr, | 167 | &dev_attr_fan1_alarm.attr, |
189 | NULL | 168 | NULL |
190 | }; | 169 | }; |
191 | 170 | ||
192 | static const struct attribute_group g760a_group = { | 171 | ATTRIBUTE_GROUPS(g760a); |
193 | .attrs = g760a_attributes, | ||
194 | }; | ||
195 | 172 | ||
196 | /* | 173 | /* |
197 | * new-style driver model code | 174 | * new-style driver model code |
@@ -200,20 +177,17 @@ static const struct attribute_group g760a_group = { | |||
200 | static int g760a_probe(struct i2c_client *client, | 177 | static int g760a_probe(struct i2c_client *client, |
201 | const struct i2c_device_id *id) | 178 | const struct i2c_device_id *id) |
202 | { | 179 | { |
180 | struct device *dev = &client->dev; | ||
203 | struct g760a_data *data; | 181 | struct g760a_data *data; |
204 | int err; | 182 | struct device *hwmon_dev; |
205 | 183 | ||
206 | if (!i2c_check_functionality(client->adapter, | 184 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
207 | I2C_FUNC_SMBUS_BYTE_DATA)) | ||
208 | return -EIO; | 185 | return -EIO; |
209 | 186 | ||
210 | data = devm_kzalloc(&client->dev, sizeof(struct g760a_data), | 187 | data = devm_kzalloc(dev, sizeof(struct g760a_data), GFP_KERNEL); |
211 | GFP_KERNEL); | ||
212 | if (!data) | 188 | if (!data) |
213 | return -ENOMEM; | 189 | return -ENOMEM; |
214 | 190 | ||
215 | i2c_set_clientdata(client, data); | ||
216 | |||
217 | data->client = client; | 191 | data->client = client; |
218 | mutex_init(&data->update_lock); | 192 | mutex_init(&data->update_lock); |
219 | 193 | ||
@@ -221,31 +195,25 @@ static int g760a_probe(struct i2c_client *client, | |||
221 | data->fan_div = G760A_DEFAULT_FAN_DIV; | 195 | data->fan_div = G760A_DEFAULT_FAN_DIV; |
222 | data->clk = G760A_DEFAULT_CLK; | 196 | data->clk = G760A_DEFAULT_CLK; |
223 | 197 | ||
224 | /* Register sysfs hooks */ | 198 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
225 | err = sysfs_create_group(&client->dev.kobj, &g760a_group); | 199 | data, |
226 | if (err) | 200 | g760a_groups); |
227 | return err; | 201 | return PTR_ERR_OR_ZERO(hwmon_dev); |
228 | |||
229 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
230 | if (IS_ERR(data->hwmon_dev)) { | ||
231 | err = PTR_ERR(data->hwmon_dev); | ||
232 | goto error_hwmon_device_register; | ||
233 | } | ||
234 | |||
235 | return 0; | ||
236 | |||
237 | error_hwmon_device_register: | ||
238 | sysfs_remove_group(&client->dev.kobj, &g760a_group); | ||
239 | return err; | ||
240 | } | 202 | } |
241 | 203 | ||
242 | static int g760a_remove(struct i2c_client *client) | 204 | static const struct i2c_device_id g760a_id[] = { |
243 | { | 205 | { "g760a", 0 }, |
244 | struct g760a_data *data = i2c_get_clientdata(client); | 206 | { } |
245 | hwmon_device_unregister(data->hwmon_dev); | 207 | }; |
246 | sysfs_remove_group(&client->dev.kobj, &g760a_group); | 208 | MODULE_DEVICE_TABLE(i2c, g760a_id); |
247 | return 0; | 209 | |
248 | } | 210 | static struct i2c_driver g760a_driver = { |
211 | .driver = { | ||
212 | .name = "g760a", | ||
213 | }, | ||
214 | .probe = g760a_probe, | ||
215 | .id_table = g760a_id, | ||
216 | }; | ||
249 | 217 | ||
250 | module_i2c_driver(g760a_driver); | 218 | module_i2c_driver(g760a_driver); |
251 | 219 | ||
diff --git a/drivers/hwmon/g762.c b/drivers/hwmon/g762.c index 98a8618d8fbf..6aac695b1688 100644 --- a/drivers/hwmon/g762.c +++ b/drivers/hwmon/g762.c | |||
@@ -128,8 +128,8 @@ enum g762_regs { | |||
128 | G762_REG_FAN_CMD2_GEAR_MODE_1)) >> 2)) | 128 | G762_REG_FAN_CMD2_GEAR_MODE_1)) >> 2)) |
129 | 129 | ||
130 | struct g762_data { | 130 | struct g762_data { |
131 | struct i2c_client *client; | ||
132 | struct device *hwmon_dev; | 131 | struct device *hwmon_dev; |
132 | struct i2c_client *client; | ||
133 | struct clk *clk; | 133 | struct clk *clk; |
134 | 134 | ||
135 | /* update mutex */ | 135 | /* update mutex */ |
@@ -206,8 +206,8 @@ static inline unsigned char cnt_from_rpm(u32 rpm, u32 clk_freq, u16 p, | |||
206 | /* helper to grab and cache data, at most one time per second */ | 206 | /* helper to grab and cache data, at most one time per second */ |
207 | static struct g762_data *g762_update_client(struct device *dev) | 207 | static struct g762_data *g762_update_client(struct device *dev) |
208 | { | 208 | { |
209 | struct i2c_client *client = to_i2c_client(dev); | 209 | struct g762_data *data = dev_get_drvdata(dev); |
210 | struct g762_data *data = i2c_get_clientdata(client); | 210 | struct i2c_client *client = data->client; |
211 | int ret = 0; | 211 | int ret = 0; |
212 | 212 | ||
213 | mutex_lock(&data->update_lock); | 213 | mutex_lock(&data->update_lock); |
@@ -266,8 +266,7 @@ static struct g762_data *g762_update_client(struct device *dev) | |||
266 | */ | 266 | */ |
267 | static int do_set_clk_freq(struct device *dev, unsigned long val) | 267 | static int do_set_clk_freq(struct device *dev, unsigned long val) |
268 | { | 268 | { |
269 | struct i2c_client *client = to_i2c_client(dev); | 269 | struct g762_data *data = dev_get_drvdata(dev); |
270 | struct g762_data *data = i2c_get_clientdata(client); | ||
271 | 270 | ||
272 | if (val > 0xffffff) | 271 | if (val > 0xffffff) |
273 | return -EINVAL; | 272 | return -EINVAL; |
@@ -282,7 +281,6 @@ static int do_set_clk_freq(struct device *dev, unsigned long val) | |||
282 | /* Set pwm mode. Accepts either 0 (PWM mode) or 1 (DC mode) */ | 281 | /* Set pwm mode. Accepts either 0 (PWM mode) or 1 (DC mode) */ |
283 | static int do_set_pwm_mode(struct device *dev, unsigned long val) | 282 | static int do_set_pwm_mode(struct device *dev, unsigned long val) |
284 | { | 283 | { |
285 | struct i2c_client *client = to_i2c_client(dev); | ||
286 | struct g762_data *data = g762_update_client(dev); | 284 | struct g762_data *data = g762_update_client(dev); |
287 | int ret; | 285 | int ret; |
288 | 286 | ||
@@ -301,7 +299,7 @@ static int do_set_pwm_mode(struct device *dev, unsigned long val) | |||
301 | ret = -EINVAL; | 299 | ret = -EINVAL; |
302 | goto out; | 300 | goto out; |
303 | } | 301 | } |
304 | ret = i2c_smbus_write_byte_data(client, G762_REG_FAN_CMD1, | 302 | ret = i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD1, |
305 | data->fan_cmd1); | 303 | data->fan_cmd1); |
306 | data->valid = false; | 304 | data->valid = false; |
307 | out: | 305 | out: |
@@ -313,7 +311,6 @@ static int do_set_pwm_mode(struct device *dev, unsigned long val) | |||
313 | /* Set fan clock divisor. Accepts either 1, 2, 4 or 8. */ | 311 | /* Set fan clock divisor. Accepts either 1, 2, 4 or 8. */ |
314 | static int do_set_fan_div(struct device *dev, unsigned long val) | 312 | static int do_set_fan_div(struct device *dev, unsigned long val) |
315 | { | 313 | { |
316 | struct i2c_client *client = to_i2c_client(dev); | ||
317 | struct g762_data *data = g762_update_client(dev); | 314 | struct g762_data *data = g762_update_client(dev); |
318 | int ret; | 315 | int ret; |
319 | 316 | ||
@@ -342,7 +339,7 @@ static int do_set_fan_div(struct device *dev, unsigned long val) | |||
342 | ret = -EINVAL; | 339 | ret = -EINVAL; |
343 | goto out; | 340 | goto out; |
344 | } | 341 | } |
345 | ret = i2c_smbus_write_byte_data(client, G762_REG_FAN_CMD1, | 342 | ret = i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD1, |
346 | data->fan_cmd1); | 343 | data->fan_cmd1); |
347 | data->valid = false; | 344 | data->valid = false; |
348 | out: | 345 | out: |
@@ -354,7 +351,6 @@ static int do_set_fan_div(struct device *dev, unsigned long val) | |||
354 | /* Set fan gear mode. Accepts either 0, 1 or 2. */ | 351 | /* Set fan gear mode. Accepts either 0, 1 or 2. */ |
355 | static int do_set_fan_gear_mode(struct device *dev, unsigned long val) | 352 | static int do_set_fan_gear_mode(struct device *dev, unsigned long val) |
356 | { | 353 | { |
357 | struct i2c_client *client = to_i2c_client(dev); | ||
358 | struct g762_data *data = g762_update_client(dev); | 354 | struct g762_data *data = g762_update_client(dev); |
359 | int ret; | 355 | int ret; |
360 | 356 | ||
@@ -379,7 +375,7 @@ static int do_set_fan_gear_mode(struct device *dev, unsigned long val) | |||
379 | ret = -EINVAL; | 375 | ret = -EINVAL; |
380 | goto out; | 376 | goto out; |
381 | } | 377 | } |
382 | ret = i2c_smbus_write_byte_data(client, G762_REG_FAN_CMD2, | 378 | ret = i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD2, |
383 | data->fan_cmd2); | 379 | data->fan_cmd2); |
384 | data->valid = false; | 380 | data->valid = false; |
385 | out: | 381 | out: |
@@ -391,7 +387,6 @@ static int do_set_fan_gear_mode(struct device *dev, unsigned long val) | |||
391 | /* Set number of fan pulses per revolution. Accepts either 2 or 4. */ | 387 | /* Set number of fan pulses per revolution. Accepts either 2 or 4. */ |
392 | static int do_set_fan_pulses(struct device *dev, unsigned long val) | 388 | static int do_set_fan_pulses(struct device *dev, unsigned long val) |
393 | { | 389 | { |
394 | struct i2c_client *client = to_i2c_client(dev); | ||
395 | struct g762_data *data = g762_update_client(dev); | 390 | struct g762_data *data = g762_update_client(dev); |
396 | int ret; | 391 | int ret; |
397 | 392 | ||
@@ -410,7 +405,7 @@ static int do_set_fan_pulses(struct device *dev, unsigned long val) | |||
410 | ret = -EINVAL; | 405 | ret = -EINVAL; |
411 | goto out; | 406 | goto out; |
412 | } | 407 | } |
413 | ret = i2c_smbus_write_byte_data(client, G762_REG_FAN_CMD1, | 408 | ret = i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD1, |
414 | data->fan_cmd1); | 409 | data->fan_cmd1); |
415 | data->valid = false; | 410 | data->valid = false; |
416 | out: | 411 | out: |
@@ -422,7 +417,6 @@ static int do_set_fan_pulses(struct device *dev, unsigned long val) | |||
422 | /* Set fan mode. Accepts either 1 (open-loop) or 2 (closed-loop). */ | 417 | /* Set fan mode. Accepts either 1 (open-loop) or 2 (closed-loop). */ |
423 | static int do_set_pwm_enable(struct device *dev, unsigned long val) | 418 | static int do_set_pwm_enable(struct device *dev, unsigned long val) |
424 | { | 419 | { |
425 | struct i2c_client *client = to_i2c_client(dev); | ||
426 | struct g762_data *data = g762_update_client(dev); | 420 | struct g762_data *data = g762_update_client(dev); |
427 | int ret; | 421 | int ret; |
428 | 422 | ||
@@ -444,15 +438,15 @@ static int do_set_pwm_enable(struct device *dev, unsigned long val) | |||
444 | * value of 254 if it is 255 when switching to open-loop. | 438 | * value of 254 if it is 255 when switching to open-loop. |
445 | */ | 439 | */ |
446 | if (data->set_cnt == 0xff) | 440 | if (data->set_cnt == 0xff) |
447 | i2c_smbus_write_byte_data(client, G762_REG_SET_CNT, | 441 | i2c_smbus_write_byte_data(data->client, |
448 | 254); | 442 | G762_REG_SET_CNT, 254); |
449 | break; | 443 | break; |
450 | default: | 444 | default: |
451 | ret = -EINVAL; | 445 | ret = -EINVAL; |
452 | goto out; | 446 | goto out; |
453 | } | 447 | } |
454 | 448 | ||
455 | ret = i2c_smbus_write_byte_data(client, G762_REG_FAN_CMD1, | 449 | ret = i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD1, |
456 | data->fan_cmd1); | 450 | data->fan_cmd1); |
457 | data->valid = false; | 451 | data->valid = false; |
458 | out: | 452 | out: |
@@ -464,7 +458,6 @@ static int do_set_pwm_enable(struct device *dev, unsigned long val) | |||
464 | /* Set PWM polarity. Accepts either 0 (positive duty) or 1 (negative duty) */ | 458 | /* Set PWM polarity. Accepts either 0 (positive duty) or 1 (negative duty) */ |
465 | static int do_set_pwm_polarity(struct device *dev, unsigned long val) | 459 | static int do_set_pwm_polarity(struct device *dev, unsigned long val) |
466 | { | 460 | { |
467 | struct i2c_client *client = to_i2c_client(dev); | ||
468 | struct g762_data *data = g762_update_client(dev); | 461 | struct g762_data *data = g762_update_client(dev); |
469 | int ret; | 462 | int ret; |
470 | 463 | ||
@@ -483,7 +476,7 @@ static int do_set_pwm_polarity(struct device *dev, unsigned long val) | |||
483 | ret = -EINVAL; | 476 | ret = -EINVAL; |
484 | goto out; | 477 | goto out; |
485 | } | 478 | } |
486 | ret = i2c_smbus_write_byte_data(client, G762_REG_FAN_CMD1, | 479 | ret = i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD1, |
487 | data->fan_cmd1); | 480 | data->fan_cmd1); |
488 | data->valid = false; | 481 | data->valid = false; |
489 | out: | 482 | out: |
@@ -498,8 +491,8 @@ static int do_set_pwm_polarity(struct device *dev, unsigned long val) | |||
498 | */ | 491 | */ |
499 | static int do_set_pwm(struct device *dev, unsigned long val) | 492 | static int do_set_pwm(struct device *dev, unsigned long val) |
500 | { | 493 | { |
501 | struct i2c_client *client = to_i2c_client(dev); | 494 | struct g762_data *data = dev_get_drvdata(dev); |
502 | struct g762_data *data = i2c_get_clientdata(client); | 495 | struct i2c_client *client = data->client; |
503 | int ret; | 496 | int ret; |
504 | 497 | ||
505 | if (val > 255) | 498 | if (val > 255) |
@@ -519,7 +512,6 @@ static int do_set_pwm(struct device *dev, unsigned long val) | |||
519 | */ | 512 | */ |
520 | static int do_set_fan_target(struct device *dev, unsigned long val) | 513 | static int do_set_fan_target(struct device *dev, unsigned long val) |
521 | { | 514 | { |
522 | struct i2c_client *client = to_i2c_client(dev); | ||
523 | struct g762_data *data = g762_update_client(dev); | 515 | struct g762_data *data = g762_update_client(dev); |
524 | int ret; | 516 | int ret; |
525 | 517 | ||
@@ -531,7 +523,7 @@ static int do_set_fan_target(struct device *dev, unsigned long val) | |||
531 | G762_PULSE_FROM_REG(data->fan_cmd1), | 523 | G762_PULSE_FROM_REG(data->fan_cmd1), |
532 | G762_CLKDIV_FROM_REG(data->fan_cmd1), | 524 | G762_CLKDIV_FROM_REG(data->fan_cmd1), |
533 | G762_GEARMULT_FROM_REG(data->fan_cmd2)); | 525 | G762_GEARMULT_FROM_REG(data->fan_cmd2)); |
534 | ret = i2c_smbus_write_byte_data(client, G762_REG_SET_CNT, | 526 | ret = i2c_smbus_write_byte_data(data->client, G762_REG_SET_CNT, |
535 | data->set_cnt); | 527 | data->set_cnt); |
536 | data->valid = false; | 528 | data->valid = false; |
537 | mutex_unlock(&data->update_lock); | 529 | mutex_unlock(&data->update_lock); |
@@ -542,7 +534,6 @@ static int do_set_fan_target(struct device *dev, unsigned long val) | |||
542 | /* Set fan startup voltage. Accepted values are either 0, 1, 2 or 3. */ | 534 | /* Set fan startup voltage. Accepted values are either 0, 1, 2 or 3. */ |
543 | static int do_set_fan_startv(struct device *dev, unsigned long val) | 535 | static int do_set_fan_startv(struct device *dev, unsigned long val) |
544 | { | 536 | { |
545 | struct i2c_client *client = to_i2c_client(dev); | ||
546 | struct g762_data *data = g762_update_client(dev); | 537 | struct g762_data *data = g762_update_client(dev); |
547 | int ret; | 538 | int ret; |
548 | 539 | ||
@@ -571,7 +562,7 @@ static int do_set_fan_startv(struct device *dev, unsigned long val) | |||
571 | ret = -EINVAL; | 562 | ret = -EINVAL; |
572 | goto out; | 563 | goto out; |
573 | } | 564 | } |
574 | ret = i2c_smbus_write_byte_data(client, G762_REG_FAN_CMD2, | 565 | ret = i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD2, |
575 | data->fan_cmd2); | 566 | data->fan_cmd2); |
576 | data->valid = false; | 567 | data->valid = false; |
577 | out: | 568 | out: |
@@ -658,15 +649,12 @@ static int g762_of_prop_import_one(struct i2c_client *client, | |||
658 | int (*psetter)(struct device *dev, | 649 | int (*psetter)(struct device *dev, |
659 | unsigned long val)) | 650 | unsigned long val)) |
660 | { | 651 | { |
661 | const __be32 *prop; | 652 | int ret; |
662 | int len, ret; | ||
663 | u32 pval; | 653 | u32 pval; |
664 | 654 | ||
665 | prop = of_get_property(client->dev.of_node, pname, &len); | 655 | if (of_property_read_u32(client->dev.of_node, pname, &pval)) |
666 | if (!prop || len != sizeof(u32)) | ||
667 | return 0; | 656 | return 0; |
668 | 657 | ||
669 | pval = be32_to_cpu(prop[0]); | ||
670 | dev_dbg(&client->dev, "found %s (%d)\n", pname, pval); | 658 | dev_dbg(&client->dev, "found %s (%d)\n", pname, pval); |
671 | ret = (*psetter)(&client->dev, pval); | 659 | ret = (*psetter)(&client->dev, pval); |
672 | if (ret) | 660 | if (ret) |
@@ -1026,7 +1014,7 @@ static DEVICE_ATTR(fan1_pulses, S_IWUSR | S_IRUGO, | |||
1026 | get_fan_pulses, set_fan_pulses); | 1014 | get_fan_pulses, set_fan_pulses); |
1027 | 1015 | ||
1028 | /* Driver data */ | 1016 | /* Driver data */ |
1029 | static struct attribute *g762_attributes[] = { | 1017 | static struct attribute *g762_attrs[] = { |
1030 | &dev_attr_fan1_input.attr, | 1018 | &dev_attr_fan1_input.attr, |
1031 | &dev_attr_fan1_alarm.attr, | 1019 | &dev_attr_fan1_alarm.attr, |
1032 | &dev_attr_fan1_fault.attr, | 1020 | &dev_attr_fan1_fault.attr, |
@@ -1039,9 +1027,7 @@ static struct attribute *g762_attributes[] = { | |||
1039 | NULL | 1027 | NULL |
1040 | }; | 1028 | }; |
1041 | 1029 | ||
1042 | static const struct attribute_group g762_group = { | 1030 | ATTRIBUTE_GROUPS(g762); |
1043 | .attrs = g762_attributes, | ||
1044 | }; | ||
1045 | 1031 | ||
1046 | /* | 1032 | /* |
1047 | * Enable both fan failure detection and fan out of control protection. The | 1033 | * Enable both fan failure detection and fan out of control protection. The |
@@ -1050,7 +1036,6 @@ static const struct attribute_group g762_group = { | |||
1050 | */ | 1036 | */ |
1051 | static inline int g762_fan_init(struct device *dev) | 1037 | static inline int g762_fan_init(struct device *dev) |
1052 | { | 1038 | { |
1053 | struct i2c_client *client = to_i2c_client(dev); | ||
1054 | struct g762_data *data = g762_update_client(dev); | 1039 | struct g762_data *data = g762_update_client(dev); |
1055 | 1040 | ||
1056 | if (IS_ERR(data)) | 1041 | if (IS_ERR(data)) |
@@ -1060,12 +1045,13 @@ static inline int g762_fan_init(struct device *dev) | |||
1060 | data->fan_cmd1 |= G762_REG_FAN_CMD1_DET_FAN_OOC; | 1045 | data->fan_cmd1 |= G762_REG_FAN_CMD1_DET_FAN_OOC; |
1061 | data->valid = false; | 1046 | data->valid = false; |
1062 | 1047 | ||
1063 | return i2c_smbus_write_byte_data(client, G762_REG_FAN_CMD1, | 1048 | return i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD1, |
1064 | data->fan_cmd1); | 1049 | data->fan_cmd1); |
1065 | } | 1050 | } |
1066 | 1051 | ||
1067 | static int g762_probe(struct i2c_client *client, const struct i2c_device_id *id) | 1052 | static int g762_probe(struct i2c_client *client, const struct i2c_device_id *id) |
1068 | { | 1053 | { |
1054 | struct device *dev = &client->dev; | ||
1069 | struct g762_data *data; | 1055 | struct g762_data *data; |
1070 | int ret; | 1056 | int ret; |
1071 | 1057 | ||
@@ -1073,7 +1059,7 @@ static int g762_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
1073 | I2C_FUNC_SMBUS_BYTE_DATA)) | 1059 | I2C_FUNC_SMBUS_BYTE_DATA)) |
1074 | return -ENODEV; | 1060 | return -ENODEV; |
1075 | 1061 | ||
1076 | data = devm_kzalloc(&client->dev, sizeof(struct g762_data), GFP_KERNEL); | 1062 | data = devm_kzalloc(dev, sizeof(struct g762_data), GFP_KERNEL); |
1077 | if (!data) | 1063 | if (!data) |
1078 | return -ENOMEM; | 1064 | return -ENOMEM; |
1079 | 1065 | ||
@@ -1082,7 +1068,7 @@ static int g762_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
1082 | mutex_init(&data->update_lock); | 1068 | mutex_init(&data->update_lock); |
1083 | 1069 | ||
1084 | /* Enable fan failure detection and fan out of control protection */ | 1070 | /* Enable fan failure detection and fan out of control protection */ |
1085 | ret = g762_fan_init(&client->dev); | 1071 | ret = g762_fan_init(dev); |
1086 | if (ret) | 1072 | if (ret) |
1087 | return ret; | 1073 | return ret; |
1088 | 1074 | ||
@@ -1098,22 +1084,17 @@ static int g762_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
1098 | if (ret) | 1084 | if (ret) |
1099 | goto clock_dis; | 1085 | goto clock_dis; |
1100 | 1086 | ||
1101 | /* Register sysfs hooks */ | 1087 | data->hwmon_dev = devm_hwmon_device_register_with_groups(dev, |
1102 | ret = sysfs_create_group(&client->dev.kobj, &g762_group); | 1088 | client->name, |
1103 | if (ret) | 1089 | data, |
1104 | goto clock_dis; | 1090 | g762_groups); |
1105 | |||
1106 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
1107 | if (IS_ERR(data->hwmon_dev)) { | 1091 | if (IS_ERR(data->hwmon_dev)) { |
1108 | ret = PTR_ERR(data->hwmon_dev); | 1092 | ret = PTR_ERR(data->hwmon_dev); |
1109 | goto sysfs_rem; | 1093 | goto clock_dis; |
1110 | } | 1094 | } |
1111 | 1095 | ||
1112 | return 0; | 1096 | return 0; |
1113 | 1097 | ||
1114 | sysfs_rem: | ||
1115 | sysfs_remove_group(&client->dev.kobj, &g762_group); | ||
1116 | |||
1117 | clock_dis: | 1098 | clock_dis: |
1118 | g762_of_clock_disable(client); | 1099 | g762_of_clock_disable(client); |
1119 | 1100 | ||
@@ -1125,7 +1106,6 @@ static int g762_remove(struct i2c_client *client) | |||
1125 | struct g762_data *data = i2c_get_clientdata(client); | 1106 | struct g762_data *data = i2c_get_clientdata(client); |
1126 | 1107 | ||
1127 | hwmon_device_unregister(data->hwmon_dev); | 1108 | hwmon_device_unregister(data->hwmon_dev); |
1128 | sysfs_remove_group(&client->dev.kobj, &g762_group); | ||
1129 | g762_of_clock_disable(client); | 1109 | g762_of_clock_disable(client); |
1130 | 1110 | ||
1131 | return 0; | 1111 | return 0; |
diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c index 1e9830513045..0212c8317bca 100644 --- a/drivers/hwmon/gl518sm.c +++ b/drivers/hwmon/gl518sm.c | |||
@@ -114,7 +114,8 @@ static inline u8 FAN_TO_REG(long rpm, int div) | |||
114 | 114 | ||
115 | /* Each client has this additional data */ | 115 | /* Each client has this additional data */ |
116 | struct gl518_data { | 116 | struct gl518_data { |
117 | struct device *hwmon_dev; | 117 | struct i2c_client *client; |
118 | const struct attribute_group *groups[3]; | ||
118 | enum chips type; | 119 | enum chips type; |
119 | 120 | ||
120 | struct mutex update_lock; | 121 | struct mutex update_lock; |
@@ -137,33 +138,98 @@ struct gl518_data { | |||
137 | u8 beep_enable; /* Boolean */ | 138 | u8 beep_enable; /* Boolean */ |
138 | }; | 139 | }; |
139 | 140 | ||
140 | static int gl518_probe(struct i2c_client *client, | 141 | /* |
141 | const struct i2c_device_id *id); | 142 | * Registers 0x07 to 0x0c are word-sized, others are byte-sized |
142 | static int gl518_detect(struct i2c_client *client, struct i2c_board_info *info); | 143 | * GL518 uses a high-byte first convention, which is exactly opposite to |
143 | static void gl518_init_client(struct i2c_client *client); | 144 | * the SMBus standard. |
144 | static int gl518_remove(struct i2c_client *client); | 145 | */ |
145 | static int gl518_read_value(struct i2c_client *client, u8 reg); | 146 | static int gl518_read_value(struct i2c_client *client, u8 reg) |
146 | static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value); | 147 | { |
147 | static struct gl518_data *gl518_update_device(struct device *dev); | 148 | if ((reg >= 0x07) && (reg <= 0x0c)) |
149 | return i2c_smbus_read_word_swapped(client, reg); | ||
150 | else | ||
151 | return i2c_smbus_read_byte_data(client, reg); | ||
152 | } | ||
148 | 153 | ||
149 | static const struct i2c_device_id gl518_id[] = { | 154 | static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value) |
150 | { "gl518sm", 0 }, | 155 | { |
151 | { } | 156 | if ((reg >= 0x07) && (reg <= 0x0c)) |
152 | }; | 157 | return i2c_smbus_write_word_swapped(client, reg, value); |
153 | MODULE_DEVICE_TABLE(i2c, gl518_id); | 158 | else |
159 | return i2c_smbus_write_byte_data(client, reg, value); | ||
160 | } | ||
154 | 161 | ||
155 | /* This is the driver that will be inserted */ | 162 | static struct gl518_data *gl518_update_device(struct device *dev) |
156 | static struct i2c_driver gl518_driver = { | 163 | { |
157 | .class = I2C_CLASS_HWMON, | 164 | struct gl518_data *data = dev_get_drvdata(dev); |
158 | .driver = { | 165 | struct i2c_client *client = data->client; |
159 | .name = "gl518sm", | 166 | int val; |
160 | }, | 167 | |
161 | .probe = gl518_probe, | 168 | mutex_lock(&data->update_lock); |
162 | .remove = gl518_remove, | 169 | |
163 | .id_table = gl518_id, | 170 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) |
164 | .detect = gl518_detect, | 171 | || !data->valid) { |
165 | .address_list = normal_i2c, | 172 | dev_dbg(&client->dev, "Starting gl518 update\n"); |
166 | }; | 173 | |
174 | data->alarms = gl518_read_value(client, GL518_REG_INT); | ||
175 | data->beep_mask = gl518_read_value(client, GL518_REG_ALARM); | ||
176 | |||
177 | val = gl518_read_value(client, GL518_REG_VDD_LIMIT); | ||
178 | data->voltage_min[0] = val & 0xff; | ||
179 | data->voltage_max[0] = (val >> 8) & 0xff; | ||
180 | val = gl518_read_value(client, GL518_REG_VIN1_LIMIT); | ||
181 | data->voltage_min[1] = val & 0xff; | ||
182 | data->voltage_max[1] = (val >> 8) & 0xff; | ||
183 | val = gl518_read_value(client, GL518_REG_VIN2_LIMIT); | ||
184 | data->voltage_min[2] = val & 0xff; | ||
185 | data->voltage_max[2] = (val >> 8) & 0xff; | ||
186 | val = gl518_read_value(client, GL518_REG_VIN3_LIMIT); | ||
187 | data->voltage_min[3] = val & 0xff; | ||
188 | data->voltage_max[3] = (val >> 8) & 0xff; | ||
189 | |||
190 | val = gl518_read_value(client, GL518_REG_FAN_COUNT); | ||
191 | data->fan_in[0] = (val >> 8) & 0xff; | ||
192 | data->fan_in[1] = val & 0xff; | ||
193 | |||
194 | val = gl518_read_value(client, GL518_REG_FAN_LIMIT); | ||
195 | data->fan_min[0] = (val >> 8) & 0xff; | ||
196 | data->fan_min[1] = val & 0xff; | ||
197 | |||
198 | data->temp_in = gl518_read_value(client, GL518_REG_TEMP_IN); | ||
199 | data->temp_max = | ||
200 | gl518_read_value(client, GL518_REG_TEMP_MAX); | ||
201 | data->temp_hyst = | ||
202 | gl518_read_value(client, GL518_REG_TEMP_HYST); | ||
203 | |||
204 | val = gl518_read_value(client, GL518_REG_MISC); | ||
205 | data->fan_div[0] = (val >> 6) & 0x03; | ||
206 | data->fan_div[1] = (val >> 4) & 0x03; | ||
207 | data->fan_auto1 = (val >> 3) & 0x01; | ||
208 | |||
209 | data->alarms &= data->alarm_mask; | ||
210 | |||
211 | val = gl518_read_value(client, GL518_REG_CONF); | ||
212 | data->beep_enable = (val >> 2) & 1; | ||
213 | |||
214 | if (data->type != gl518sm_r00) { | ||
215 | data->voltage_in[0] = | ||
216 | gl518_read_value(client, GL518_REG_VDD); | ||
217 | data->voltage_in[1] = | ||
218 | gl518_read_value(client, GL518_REG_VIN1); | ||
219 | data->voltage_in[2] = | ||
220 | gl518_read_value(client, GL518_REG_VIN2); | ||
221 | } | ||
222 | data->voltage_in[3] = | ||
223 | gl518_read_value(client, GL518_REG_VIN3); | ||
224 | |||
225 | data->last_updated = jiffies; | ||
226 | data->valid = 1; | ||
227 | } | ||
228 | |||
229 | mutex_unlock(&data->update_lock); | ||
230 | |||
231 | return data; | ||
232 | } | ||
167 | 233 | ||
168 | /* | 234 | /* |
169 | * Sysfs stuff | 235 | * Sysfs stuff |
@@ -228,8 +294,8 @@ static ssize_t set_##suffix(struct device *dev, \ | |||
228 | struct device_attribute *attr, \ | 294 | struct device_attribute *attr, \ |
229 | const char *buf, size_t count) \ | 295 | const char *buf, size_t count) \ |
230 | { \ | 296 | { \ |
231 | struct i2c_client *client = to_i2c_client(dev); \ | 297 | struct gl518_data *data = dev_get_drvdata(dev); \ |
232 | struct gl518_data *data = i2c_get_clientdata(client); \ | 298 | struct i2c_client *client = data->client; \ |
233 | long val; \ | 299 | long val; \ |
234 | int err = kstrtol(buf, 10, &val); \ | 300 | int err = kstrtol(buf, 10, &val); \ |
235 | if (err) \ | 301 | if (err) \ |
@@ -247,8 +313,8 @@ static ssize_t set_##suffix(struct device *dev, \ | |||
247 | struct device_attribute *attr, \ | 313 | struct device_attribute *attr, \ |
248 | const char *buf, size_t count) \ | 314 | const char *buf, size_t count) \ |
249 | { \ | 315 | { \ |
250 | struct i2c_client *client = to_i2c_client(dev); \ | 316 | struct gl518_data *data = dev_get_drvdata(dev); \ |
251 | struct gl518_data *data = i2c_get_clientdata(client); \ | 317 | struct i2c_client *client = data->client; \ |
252 | int regvalue; \ | 318 | int regvalue; \ |
253 | unsigned long val; \ | 319 | unsigned long val; \ |
254 | int err = kstrtoul(buf, 10, &val); \ | 320 | int err = kstrtoul(buf, 10, &val); \ |
@@ -286,8 +352,8 @@ set(BEEP_MASK, beep_mask, beep_mask, GL518_REG_ALARM); | |||
286 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | 352 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, |
287 | const char *buf, size_t count) | 353 | const char *buf, size_t count) |
288 | { | 354 | { |
289 | struct i2c_client *client = to_i2c_client(dev); | 355 | struct gl518_data *data = dev_get_drvdata(dev); |
290 | struct gl518_data *data = i2c_get_clientdata(client); | 356 | struct i2c_client *client = data->client; |
291 | int nr = to_sensor_dev_attr(attr)->index; | 357 | int nr = to_sensor_dev_attr(attr)->index; |
292 | int regvalue; | 358 | int regvalue; |
293 | unsigned long val; | 359 | unsigned long val; |
@@ -319,8 +385,8 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | |||
319 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | 385 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, |
320 | const char *buf, size_t count) | 386 | const char *buf, size_t count) |
321 | { | 387 | { |
322 | struct i2c_client *client = to_i2c_client(dev); | 388 | struct gl518_data *data = dev_get_drvdata(dev); |
323 | struct gl518_data *data = i2c_get_clientdata(client); | 389 | struct i2c_client *client = data->client; |
324 | int nr = to_sensor_dev_attr(attr)->index; | 390 | int nr = to_sensor_dev_attr(attr)->index; |
325 | int regvalue; | 391 | int regvalue; |
326 | unsigned long val; | 392 | unsigned long val; |
@@ -420,8 +486,8 @@ static ssize_t show_beep(struct device *dev, struct device_attribute *attr, | |||
420 | static ssize_t set_beep(struct device *dev, struct device_attribute *attr, | 486 | static ssize_t set_beep(struct device *dev, struct device_attribute *attr, |
421 | const char *buf, size_t count) | 487 | const char *buf, size_t count) |
422 | { | 488 | { |
423 | struct i2c_client *client = to_i2c_client(dev); | 489 | struct gl518_data *data = dev_get_drvdata(dev); |
424 | struct gl518_data *data = i2c_get_clientdata(client); | 490 | struct i2c_client *client = data->client; |
425 | int bitnr = to_sensor_dev_attr(attr)->index; | 491 | int bitnr = to_sensor_dev_attr(attr)->index; |
426 | unsigned long bit; | 492 | unsigned long bit; |
427 | int err; | 493 | int err; |
@@ -539,52 +605,6 @@ static int gl518_detect(struct i2c_client *client, struct i2c_board_info *info) | |||
539 | return 0; | 605 | return 0; |
540 | } | 606 | } |
541 | 607 | ||
542 | static int gl518_probe(struct i2c_client *client, | ||
543 | const struct i2c_device_id *id) | ||
544 | { | ||
545 | struct gl518_data *data; | ||
546 | int err, revision; | ||
547 | |||
548 | data = devm_kzalloc(&client->dev, sizeof(struct gl518_data), | ||
549 | GFP_KERNEL); | ||
550 | if (!data) | ||
551 | return -ENOMEM; | ||
552 | |||
553 | i2c_set_clientdata(client, data); | ||
554 | revision = gl518_read_value(client, GL518_REG_REVISION); | ||
555 | data->type = revision == 0x80 ? gl518sm_r80 : gl518sm_r00; | ||
556 | mutex_init(&data->update_lock); | ||
557 | |||
558 | /* Initialize the GL518SM chip */ | ||
559 | data->alarm_mask = 0xff; | ||
560 | gl518_init_client(client); | ||
561 | |||
562 | /* Register sysfs hooks */ | ||
563 | err = sysfs_create_group(&client->dev.kobj, &gl518_group); | ||
564 | if (err) | ||
565 | return err; | ||
566 | if (data->type == gl518sm_r80) { | ||
567 | err = sysfs_create_group(&client->dev.kobj, &gl518_group_r80); | ||
568 | if (err) | ||
569 | goto exit_remove_files; | ||
570 | } | ||
571 | |||
572 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
573 | if (IS_ERR(data->hwmon_dev)) { | ||
574 | err = PTR_ERR(data->hwmon_dev); | ||
575 | goto exit_remove_files; | ||
576 | } | ||
577 | |||
578 | return 0; | ||
579 | |||
580 | exit_remove_files: | ||
581 | sysfs_remove_group(&client->dev.kobj, &gl518_group); | ||
582 | if (data->type == gl518sm_r80) | ||
583 | sysfs_remove_group(&client->dev.kobj, &gl518_group_r80); | ||
584 | return err; | ||
585 | } | ||
586 | |||
587 | |||
588 | /* | 608 | /* |
589 | * Called when we have found a new GL518SM. | 609 | * Called when we have found a new GL518SM. |
590 | * Note that we preserve D4:NoFan2 and D2:beep_enable. | 610 | * Note that we preserve D4:NoFan2 and D2:beep_enable. |
@@ -605,110 +625,53 @@ static void gl518_init_client(struct i2c_client *client) | |||
605 | gl518_write_value(client, GL518_REG_CONF, 0x40 | regvalue); | 625 | gl518_write_value(client, GL518_REG_CONF, 0x40 | regvalue); |
606 | } | 626 | } |
607 | 627 | ||
608 | static int gl518_remove(struct i2c_client *client) | 628 | static int gl518_probe(struct i2c_client *client, |
609 | { | 629 | const struct i2c_device_id *id) |
610 | struct gl518_data *data = i2c_get_clientdata(client); | ||
611 | |||
612 | hwmon_device_unregister(data->hwmon_dev); | ||
613 | sysfs_remove_group(&client->dev.kobj, &gl518_group); | ||
614 | if (data->type == gl518sm_r80) | ||
615 | sysfs_remove_group(&client->dev.kobj, &gl518_group_r80); | ||
616 | |||
617 | return 0; | ||
618 | } | ||
619 | |||
620 | /* | ||
621 | * Registers 0x07 to 0x0c are word-sized, others are byte-sized | ||
622 | * GL518 uses a high-byte first convention, which is exactly opposite to | ||
623 | * the SMBus standard. | ||
624 | */ | ||
625 | static int gl518_read_value(struct i2c_client *client, u8 reg) | ||
626 | { | ||
627 | if ((reg >= 0x07) && (reg <= 0x0c)) | ||
628 | return i2c_smbus_read_word_swapped(client, reg); | ||
629 | else | ||
630 | return i2c_smbus_read_byte_data(client, reg); | ||
631 | } | ||
632 | |||
633 | static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value) | ||
634 | { | ||
635 | if ((reg >= 0x07) && (reg <= 0x0c)) | ||
636 | return i2c_smbus_write_word_swapped(client, reg, value); | ||
637 | else | ||
638 | return i2c_smbus_write_byte_data(client, reg, value); | ||
639 | } | ||
640 | |||
641 | static struct gl518_data *gl518_update_device(struct device *dev) | ||
642 | { | 630 | { |
643 | struct i2c_client *client = to_i2c_client(dev); | 631 | struct device *dev = &client->dev; |
644 | struct gl518_data *data = i2c_get_clientdata(client); | 632 | struct device *hwmon_dev; |
645 | int val; | 633 | struct gl518_data *data; |
646 | 634 | int revision; | |
647 | mutex_lock(&data->update_lock); | ||
648 | |||
649 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) | ||
650 | || !data->valid) { | ||
651 | dev_dbg(&client->dev, "Starting gl518 update\n"); | ||
652 | |||
653 | data->alarms = gl518_read_value(client, GL518_REG_INT); | ||
654 | data->beep_mask = gl518_read_value(client, GL518_REG_ALARM); | ||
655 | |||
656 | val = gl518_read_value(client, GL518_REG_VDD_LIMIT); | ||
657 | data->voltage_min[0] = val & 0xff; | ||
658 | data->voltage_max[0] = (val >> 8) & 0xff; | ||
659 | val = gl518_read_value(client, GL518_REG_VIN1_LIMIT); | ||
660 | data->voltage_min[1] = val & 0xff; | ||
661 | data->voltage_max[1] = (val >> 8) & 0xff; | ||
662 | val = gl518_read_value(client, GL518_REG_VIN2_LIMIT); | ||
663 | data->voltage_min[2] = val & 0xff; | ||
664 | data->voltage_max[2] = (val >> 8) & 0xff; | ||
665 | val = gl518_read_value(client, GL518_REG_VIN3_LIMIT); | ||
666 | data->voltage_min[3] = val & 0xff; | ||
667 | data->voltage_max[3] = (val >> 8) & 0xff; | ||
668 | |||
669 | val = gl518_read_value(client, GL518_REG_FAN_COUNT); | ||
670 | data->fan_in[0] = (val >> 8) & 0xff; | ||
671 | data->fan_in[1] = val & 0xff; | ||
672 | |||
673 | val = gl518_read_value(client, GL518_REG_FAN_LIMIT); | ||
674 | data->fan_min[0] = (val >> 8) & 0xff; | ||
675 | data->fan_min[1] = val & 0xff; | ||
676 | |||
677 | data->temp_in = gl518_read_value(client, GL518_REG_TEMP_IN); | ||
678 | data->temp_max = | ||
679 | gl518_read_value(client, GL518_REG_TEMP_MAX); | ||
680 | data->temp_hyst = | ||
681 | gl518_read_value(client, GL518_REG_TEMP_HYST); | ||
682 | 635 | ||
683 | val = gl518_read_value(client, GL518_REG_MISC); | 636 | data = devm_kzalloc(dev, sizeof(struct gl518_data), GFP_KERNEL); |
684 | data->fan_div[0] = (val >> 6) & 0x03; | 637 | if (!data) |
685 | data->fan_div[1] = (val >> 4) & 0x03; | 638 | return -ENOMEM; |
686 | data->fan_auto1 = (val >> 3) & 0x01; | ||
687 | 639 | ||
688 | data->alarms &= data->alarm_mask; | 640 | data->client = client; |
641 | revision = gl518_read_value(client, GL518_REG_REVISION); | ||
642 | data->type = revision == 0x80 ? gl518sm_r80 : gl518sm_r00; | ||
643 | mutex_init(&data->update_lock); | ||
689 | 644 | ||
690 | val = gl518_read_value(client, GL518_REG_CONF); | 645 | /* Initialize the GL518SM chip */ |
691 | data->beep_enable = (val >> 2) & 1; | 646 | data->alarm_mask = 0xff; |
647 | gl518_init_client(client); | ||
692 | 648 | ||
693 | if (data->type != gl518sm_r00) { | 649 | /* sysfs hooks */ |
694 | data->voltage_in[0] = | 650 | data->groups[0] = &gl518_group; |
695 | gl518_read_value(client, GL518_REG_VDD); | 651 | if (data->type == gl518sm_r80) |
696 | data->voltage_in[1] = | 652 | data->groups[1] = &gl518_group_r80; |
697 | gl518_read_value(client, GL518_REG_VIN1); | ||
698 | data->voltage_in[2] = | ||
699 | gl518_read_value(client, GL518_REG_VIN2); | ||
700 | } | ||
701 | data->voltage_in[3] = | ||
702 | gl518_read_value(client, GL518_REG_VIN3); | ||
703 | 653 | ||
704 | data->last_updated = jiffies; | 654 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
705 | data->valid = 1; | 655 | data, data->groups); |
706 | } | 656 | return PTR_ERR_OR_ZERO(hwmon_dev); |
657 | } | ||
707 | 658 | ||
708 | mutex_unlock(&data->update_lock); | 659 | static const struct i2c_device_id gl518_id[] = { |
660 | { "gl518sm", 0 }, | ||
661 | { } | ||
662 | }; | ||
663 | MODULE_DEVICE_TABLE(i2c, gl518_id); | ||
709 | 664 | ||
710 | return data; | 665 | static struct i2c_driver gl518_driver = { |
711 | } | 666 | .class = I2C_CLASS_HWMON, |
667 | .driver = { | ||
668 | .name = "gl518sm", | ||
669 | }, | ||
670 | .probe = gl518_probe, | ||
671 | .id_table = gl518_id, | ||
672 | .detect = gl518_detect, | ||
673 | .address_list = normal_i2c, | ||
674 | }; | ||
712 | 675 | ||
713 | module_i2c_driver(gl518_driver); | 676 | module_i2c_driver(gl518_driver); |
714 | 677 | ||
diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c index ed56e09c3dd7..dee93ec87d02 100644 --- a/drivers/hwmon/gl520sm.c +++ b/drivers/hwmon/gl520sm.c | |||
@@ -73,41 +73,10 @@ static const u8 GL520_REG_TEMP_MAX_HYST[] = { 0x06, 0x18 }; | |||
73 | #define GL520_REG_BEEP_MASK 0x10 | 73 | #define GL520_REG_BEEP_MASK 0x10 |
74 | #define GL520_REG_BEEP_ENABLE GL520_REG_CONF | 74 | #define GL520_REG_BEEP_ENABLE GL520_REG_CONF |
75 | 75 | ||
76 | /* | ||
77 | * Function declarations | ||
78 | */ | ||
79 | |||
80 | static int gl520_probe(struct i2c_client *client, | ||
81 | const struct i2c_device_id *id); | ||
82 | static int gl520_detect(struct i2c_client *client, struct i2c_board_info *info); | ||
83 | static void gl520_init_client(struct i2c_client *client); | ||
84 | static int gl520_remove(struct i2c_client *client); | ||
85 | static int gl520_read_value(struct i2c_client *client, u8 reg); | ||
86 | static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value); | ||
87 | static struct gl520_data *gl520_update_device(struct device *dev); | ||
88 | |||
89 | /* Driver data */ | ||
90 | static const struct i2c_device_id gl520_id[] = { | ||
91 | { "gl520sm", 0 }, | ||
92 | { } | ||
93 | }; | ||
94 | MODULE_DEVICE_TABLE(i2c, gl520_id); | ||
95 | |||
96 | static struct i2c_driver gl520_driver = { | ||
97 | .class = I2C_CLASS_HWMON, | ||
98 | .driver = { | ||
99 | .name = "gl520sm", | ||
100 | }, | ||
101 | .probe = gl520_probe, | ||
102 | .remove = gl520_remove, | ||
103 | .id_table = gl520_id, | ||
104 | .detect = gl520_detect, | ||
105 | .address_list = normal_i2c, | ||
106 | }; | ||
107 | |||
108 | /* Client data */ | 76 | /* Client data */ |
109 | struct gl520_data { | 77 | struct gl520_data { |
110 | struct device *hwmon_dev; | 78 | struct i2c_client *client; |
79 | const struct attribute_group *groups[3]; | ||
111 | struct mutex update_lock; | 80 | struct mutex update_lock; |
112 | char valid; /* zero until the following fields are valid */ | 81 | char valid; /* zero until the following fields are valid */ |
113 | unsigned long last_updated; /* in jiffies */ | 82 | unsigned long last_updated; /* in jiffies */ |
@@ -132,6 +101,102 @@ struct gl520_data { | |||
132 | }; | 101 | }; |
133 | 102 | ||
134 | /* | 103 | /* |
104 | * Registers 0x07 to 0x0c are word-sized, others are byte-sized | ||
105 | * GL520 uses a high-byte first convention | ||
106 | */ | ||
107 | static int gl520_read_value(struct i2c_client *client, u8 reg) | ||
108 | { | ||
109 | if ((reg >= 0x07) && (reg <= 0x0c)) | ||
110 | return i2c_smbus_read_word_swapped(client, reg); | ||
111 | else | ||
112 | return i2c_smbus_read_byte_data(client, reg); | ||
113 | } | ||
114 | |||
115 | static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value) | ||
116 | { | ||
117 | if ((reg >= 0x07) && (reg <= 0x0c)) | ||
118 | return i2c_smbus_write_word_swapped(client, reg, value); | ||
119 | else | ||
120 | return i2c_smbus_write_byte_data(client, reg, value); | ||
121 | } | ||
122 | |||
123 | static struct gl520_data *gl520_update_device(struct device *dev) | ||
124 | { | ||
125 | struct gl520_data *data = dev_get_drvdata(dev); | ||
126 | struct i2c_client *client = data->client; | ||
127 | int val, i; | ||
128 | |||
129 | mutex_lock(&data->update_lock); | ||
130 | |||
131 | if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) { | ||
132 | |||
133 | dev_dbg(&client->dev, "Starting gl520sm update\n"); | ||
134 | |||
135 | data->alarms = gl520_read_value(client, GL520_REG_ALARMS); | ||
136 | data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK); | ||
137 | data->vid = gl520_read_value(client, | ||
138 | GL520_REG_VID_INPUT) & 0x1f; | ||
139 | |||
140 | for (i = 0; i < 4; i++) { | ||
141 | data->in_input[i] = gl520_read_value(client, | ||
142 | GL520_REG_IN_INPUT[i]); | ||
143 | val = gl520_read_value(client, GL520_REG_IN_LIMIT[i]); | ||
144 | data->in_min[i] = val & 0xff; | ||
145 | data->in_max[i] = (val >> 8) & 0xff; | ||
146 | } | ||
147 | |||
148 | val = gl520_read_value(client, GL520_REG_FAN_INPUT); | ||
149 | data->fan_input[0] = (val >> 8) & 0xff; | ||
150 | data->fan_input[1] = val & 0xff; | ||
151 | |||
152 | val = gl520_read_value(client, GL520_REG_FAN_MIN); | ||
153 | data->fan_min[0] = (val >> 8) & 0xff; | ||
154 | data->fan_min[1] = val & 0xff; | ||
155 | |||
156 | data->temp_input[0] = gl520_read_value(client, | ||
157 | GL520_REG_TEMP_INPUT[0]); | ||
158 | data->temp_max[0] = gl520_read_value(client, | ||
159 | GL520_REG_TEMP_MAX[0]); | ||
160 | data->temp_max_hyst[0] = gl520_read_value(client, | ||
161 | GL520_REG_TEMP_MAX_HYST[0]); | ||
162 | |||
163 | val = gl520_read_value(client, GL520_REG_FAN_DIV); | ||
164 | data->fan_div[0] = (val >> 6) & 0x03; | ||
165 | data->fan_div[1] = (val >> 4) & 0x03; | ||
166 | data->fan_off = (val >> 2) & 0x01; | ||
167 | |||
168 | data->alarms &= data->alarm_mask; | ||
169 | |||
170 | val = gl520_read_value(client, GL520_REG_CONF); | ||
171 | data->beep_enable = !((val >> 2) & 1); | ||
172 | |||
173 | /* Temp1 and Vin4 are the same input */ | ||
174 | if (data->two_temps) { | ||
175 | data->temp_input[1] = gl520_read_value(client, | ||
176 | GL520_REG_TEMP_INPUT[1]); | ||
177 | data->temp_max[1] = gl520_read_value(client, | ||
178 | GL520_REG_TEMP_MAX[1]); | ||
179 | data->temp_max_hyst[1] = gl520_read_value(client, | ||
180 | GL520_REG_TEMP_MAX_HYST[1]); | ||
181 | } else { | ||
182 | data->in_input[4] = gl520_read_value(client, | ||
183 | GL520_REG_IN_INPUT[4]); | ||
184 | data->in_min[4] = gl520_read_value(client, | ||
185 | GL520_REG_IN_MIN[4]); | ||
186 | data->in_max[4] = gl520_read_value(client, | ||
187 | GL520_REG_IN_MAX[4]); | ||
188 | } | ||
189 | |||
190 | data->last_updated = jiffies; | ||
191 | data->valid = 1; | ||
192 | } | ||
193 | |||
194 | mutex_unlock(&data->update_lock); | ||
195 | |||
196 | return data; | ||
197 | } | ||
198 | |||
199 | /* | ||
135 | * Sysfs stuff | 200 | * Sysfs stuff |
136 | */ | 201 | */ |
137 | 202 | ||
@@ -191,8 +256,8 @@ static ssize_t get_in_max(struct device *dev, struct device_attribute *attr, | |||
191 | static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | 256 | static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, |
192 | const char *buf, size_t count) | 257 | const char *buf, size_t count) |
193 | { | 258 | { |
194 | struct i2c_client *client = to_i2c_client(dev); | 259 | struct gl520_data *data = dev_get_drvdata(dev); |
195 | struct gl520_data *data = i2c_get_clientdata(client); | 260 | struct i2c_client *client = data->client; |
196 | int n = to_sensor_dev_attr(attr)->index; | 261 | int n = to_sensor_dev_attr(attr)->index; |
197 | u8 r; | 262 | u8 r; |
198 | long v; | 263 | long v; |
@@ -225,8 +290,8 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | |||
225 | static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, | 290 | static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, |
226 | const char *buf, size_t count) | 291 | const char *buf, size_t count) |
227 | { | 292 | { |
228 | struct i2c_client *client = to_i2c_client(dev); | 293 | struct gl520_data *data = dev_get_drvdata(dev); |
229 | struct gl520_data *data = i2c_get_clientdata(client); | 294 | struct i2c_client *client = data->client; |
230 | int n = to_sensor_dev_attr(attr)->index; | 295 | int n = to_sensor_dev_attr(attr)->index; |
231 | u8 r; | 296 | u8 r; |
232 | long v; | 297 | long v; |
@@ -326,8 +391,8 @@ static ssize_t get_fan_off(struct device *dev, struct device_attribute *attr, | |||
326 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | 391 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, |
327 | const char *buf, size_t count) | 392 | const char *buf, size_t count) |
328 | { | 393 | { |
329 | struct i2c_client *client = to_i2c_client(dev); | 394 | struct gl520_data *data = dev_get_drvdata(dev); |
330 | struct gl520_data *data = i2c_get_clientdata(client); | 395 | struct i2c_client *client = data->client; |
331 | int n = to_sensor_dev_attr(attr)->index; | 396 | int n = to_sensor_dev_attr(attr)->index; |
332 | u8 r; | 397 | u8 r; |
333 | unsigned long v; | 398 | unsigned long v; |
@@ -365,8 +430,8 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | |||
365 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | 430 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, |
366 | const char *buf, size_t count) | 431 | const char *buf, size_t count) |
367 | { | 432 | { |
368 | struct i2c_client *client = to_i2c_client(dev); | 433 | struct gl520_data *data = dev_get_drvdata(dev); |
369 | struct gl520_data *data = i2c_get_clientdata(client); | 434 | struct i2c_client *client = data->client; |
370 | int n = to_sensor_dev_attr(attr)->index; | 435 | int n = to_sensor_dev_attr(attr)->index; |
371 | u8 r; | 436 | u8 r; |
372 | unsigned long v; | 437 | unsigned long v; |
@@ -414,8 +479,8 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | |||
414 | static ssize_t set_fan_off(struct device *dev, struct device_attribute *attr, | 479 | static ssize_t set_fan_off(struct device *dev, struct device_attribute *attr, |
415 | const char *buf, size_t count) | 480 | const char *buf, size_t count) |
416 | { | 481 | { |
417 | struct i2c_client *client = to_i2c_client(dev); | 482 | struct gl520_data *data = dev_get_drvdata(dev); |
418 | struct gl520_data *data = i2c_get_clientdata(client); | 483 | struct i2c_client *client = data->client; |
419 | u8 r; | 484 | u8 r; |
420 | unsigned long v; | 485 | unsigned long v; |
421 | int err; | 486 | int err; |
@@ -482,8 +547,8 @@ static ssize_t get_temp_max_hyst(struct device *dev, | |||
482 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | 547 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, |
483 | const char *buf, size_t count) | 548 | const char *buf, size_t count) |
484 | { | 549 | { |
485 | struct i2c_client *client = to_i2c_client(dev); | 550 | struct gl520_data *data = dev_get_drvdata(dev); |
486 | struct gl520_data *data = i2c_get_clientdata(client); | 551 | struct i2c_client *client = data->client; |
487 | int n = to_sensor_dev_attr(attr)->index; | 552 | int n = to_sensor_dev_attr(attr)->index; |
488 | long v; | 553 | long v; |
489 | int err; | 554 | int err; |
@@ -502,8 +567,8 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
502 | static ssize_t set_temp_max_hyst(struct device *dev, struct device_attribute | 567 | static ssize_t set_temp_max_hyst(struct device *dev, struct device_attribute |
503 | *attr, const char *buf, size_t count) | 568 | *attr, const char *buf, size_t count) |
504 | { | 569 | { |
505 | struct i2c_client *client = to_i2c_client(dev); | 570 | struct gl520_data *data = dev_get_drvdata(dev); |
506 | struct gl520_data *data = i2c_get_clientdata(client); | 571 | struct i2c_client *client = data->client; |
507 | int n = to_sensor_dev_attr(attr)->index; | 572 | int n = to_sensor_dev_attr(attr)->index; |
508 | long v; | 573 | long v; |
509 | int err; | 574 | int err; |
@@ -555,8 +620,8 @@ static ssize_t get_beep_mask(struct device *dev, struct device_attribute *attr, | |||
555 | static ssize_t set_beep_enable(struct device *dev, struct device_attribute | 620 | static ssize_t set_beep_enable(struct device *dev, struct device_attribute |
556 | *attr, const char *buf, size_t count) | 621 | *attr, const char *buf, size_t count) |
557 | { | 622 | { |
558 | struct i2c_client *client = to_i2c_client(dev); | 623 | struct gl520_data *data = dev_get_drvdata(dev); |
559 | struct gl520_data *data = i2c_get_clientdata(client); | 624 | struct i2c_client *client = data->client; |
560 | u8 r; | 625 | u8 r; |
561 | unsigned long v; | 626 | unsigned long v; |
562 | int err; | 627 | int err; |
@@ -579,8 +644,8 @@ static ssize_t set_beep_enable(struct device *dev, struct device_attribute | |||
579 | static ssize_t set_beep_mask(struct device *dev, struct device_attribute *attr, | 644 | static ssize_t set_beep_mask(struct device *dev, struct device_attribute *attr, |
580 | const char *buf, size_t count) | 645 | const char *buf, size_t count) |
581 | { | 646 | { |
582 | struct i2c_client *client = to_i2c_client(dev); | 647 | struct gl520_data *data = dev_get_drvdata(dev); |
583 | struct gl520_data *data = i2c_get_clientdata(client); | 648 | struct i2c_client *client = data->client; |
584 | unsigned long r; | 649 | unsigned long r; |
585 | int err; | 650 | int err; |
586 | 651 | ||
@@ -633,8 +698,8 @@ static ssize_t get_beep(struct device *dev, struct device_attribute *attr, | |||
633 | static ssize_t set_beep(struct device *dev, struct device_attribute *attr, | 698 | static ssize_t set_beep(struct device *dev, struct device_attribute *attr, |
634 | const char *buf, size_t count) | 699 | const char *buf, size_t count) |
635 | { | 700 | { |
636 | struct i2c_client *client = to_i2c_client(dev); | 701 | struct gl520_data *data = dev_get_drvdata(dev); |
637 | struct gl520_data *data = i2c_get_clientdata(client); | 702 | struct i2c_client *client = data->client; |
638 | int bitnr = to_sensor_dev_attr(attr)->index; | 703 | int bitnr = to_sensor_dev_attr(attr)->index; |
639 | unsigned long bit; | 704 | unsigned long bit; |
640 | 705 | ||
@@ -772,52 +837,6 @@ static int gl520_detect(struct i2c_client *client, struct i2c_board_info *info) | |||
772 | return 0; | 837 | return 0; |
773 | } | 838 | } |
774 | 839 | ||
775 | static int gl520_probe(struct i2c_client *client, | ||
776 | const struct i2c_device_id *id) | ||
777 | { | ||
778 | struct gl520_data *data; | ||
779 | int err; | ||
780 | |||
781 | data = devm_kzalloc(&client->dev, sizeof(struct gl520_data), | ||
782 | GFP_KERNEL); | ||
783 | if (!data) | ||
784 | return -ENOMEM; | ||
785 | |||
786 | i2c_set_clientdata(client, data); | ||
787 | mutex_init(&data->update_lock); | ||
788 | |||
789 | /* Initialize the GL520SM chip */ | ||
790 | gl520_init_client(client); | ||
791 | |||
792 | /* Register sysfs hooks */ | ||
793 | err = sysfs_create_group(&client->dev.kobj, &gl520_group); | ||
794 | if (err) | ||
795 | return err; | ||
796 | |||
797 | if (data->two_temps) | ||
798 | err = sysfs_create_group(&client->dev.kobj, &gl520_group_temp2); | ||
799 | else | ||
800 | err = sysfs_create_group(&client->dev.kobj, &gl520_group_in4); | ||
801 | |||
802 | if (err) | ||
803 | goto exit_remove_files; | ||
804 | |||
805 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
806 | if (IS_ERR(data->hwmon_dev)) { | ||
807 | err = PTR_ERR(data->hwmon_dev); | ||
808 | goto exit_remove_files; | ||
809 | } | ||
810 | |||
811 | return 0; | ||
812 | |||
813 | exit_remove_files: | ||
814 | sysfs_remove_group(&client->dev.kobj, &gl520_group); | ||
815 | sysfs_remove_group(&client->dev.kobj, &gl520_group_in4); | ||
816 | sysfs_remove_group(&client->dev.kobj, &gl520_group_temp2); | ||
817 | return err; | ||
818 | } | ||
819 | |||
820 | |||
821 | /* Called when we have found a new GL520SM. */ | 840 | /* Called when we have found a new GL520SM. */ |
822 | static void gl520_init_client(struct i2c_client *client) | 841 | static void gl520_init_client(struct i2c_client *client) |
823 | { | 842 | { |
@@ -856,115 +875,53 @@ static void gl520_init_client(struct i2c_client *client) | |||
856 | gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask); | 875 | gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask); |
857 | } | 876 | } |
858 | 877 | ||
859 | static int gl520_remove(struct i2c_client *client) | 878 | static int gl520_probe(struct i2c_client *client, |
879 | const struct i2c_device_id *id) | ||
860 | { | 880 | { |
861 | struct gl520_data *data = i2c_get_clientdata(client); | 881 | struct device *dev = &client->dev; |
882 | struct device *hwmon_dev; | ||
883 | struct gl520_data *data; | ||
862 | 884 | ||
863 | hwmon_device_unregister(data->hwmon_dev); | 885 | data = devm_kzalloc(dev, sizeof(struct gl520_data), GFP_KERNEL); |
864 | sysfs_remove_group(&client->dev.kobj, &gl520_group); | 886 | if (!data) |
865 | sysfs_remove_group(&client->dev.kobj, &gl520_group_in4); | 887 | return -ENOMEM; |
866 | sysfs_remove_group(&client->dev.kobj, &gl520_group_temp2); | ||
867 | 888 | ||
868 | return 0; | 889 | i2c_set_clientdata(client, data); |
869 | } | 890 | mutex_init(&data->update_lock); |
891 | data->client = client; | ||
870 | 892 | ||
893 | /* Initialize the GL520SM chip */ | ||
894 | gl520_init_client(client); | ||
871 | 895 | ||
872 | /* | 896 | /* sysfs hooks */ |
873 | * Registers 0x07 to 0x0c are word-sized, others are byte-sized | 897 | data->groups[0] = &gl520_group; |
874 | * GL520 uses a high-byte first convention | ||
875 | */ | ||
876 | static int gl520_read_value(struct i2c_client *client, u8 reg) | ||
877 | { | ||
878 | if ((reg >= 0x07) && (reg <= 0x0c)) | ||
879 | return i2c_smbus_read_word_swapped(client, reg); | ||
880 | else | ||
881 | return i2c_smbus_read_byte_data(client, reg); | ||
882 | } | ||
883 | 898 | ||
884 | static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value) | 899 | if (data->two_temps) |
885 | { | 900 | data->groups[1] = &gl520_group_temp2; |
886 | if ((reg >= 0x07) && (reg <= 0x0c)) | ||
887 | return i2c_smbus_write_word_swapped(client, reg, value); | ||
888 | else | 901 | else |
889 | return i2c_smbus_write_byte_data(client, reg, value); | 902 | data->groups[1] = &gl520_group_in4; |
890 | } | ||
891 | |||
892 | |||
893 | static struct gl520_data *gl520_update_device(struct device *dev) | ||
894 | { | ||
895 | struct i2c_client *client = to_i2c_client(dev); | ||
896 | struct gl520_data *data = i2c_get_clientdata(client); | ||
897 | int val, i; | ||
898 | |||
899 | mutex_lock(&data->update_lock); | ||
900 | |||
901 | if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) { | ||
902 | |||
903 | dev_dbg(&client->dev, "Starting gl520sm update\n"); | ||
904 | |||
905 | data->alarms = gl520_read_value(client, GL520_REG_ALARMS); | ||
906 | data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK); | ||
907 | data->vid = gl520_read_value(client, | ||
908 | GL520_REG_VID_INPUT) & 0x1f; | ||
909 | |||
910 | for (i = 0; i < 4; i++) { | ||
911 | data->in_input[i] = gl520_read_value(client, | ||
912 | GL520_REG_IN_INPUT[i]); | ||
913 | val = gl520_read_value(client, GL520_REG_IN_LIMIT[i]); | ||
914 | data->in_min[i] = val & 0xff; | ||
915 | data->in_max[i] = (val >> 8) & 0xff; | ||
916 | } | ||
917 | |||
918 | val = gl520_read_value(client, GL520_REG_FAN_INPUT); | ||
919 | data->fan_input[0] = (val >> 8) & 0xff; | ||
920 | data->fan_input[1] = val & 0xff; | ||
921 | 903 | ||
922 | val = gl520_read_value(client, GL520_REG_FAN_MIN); | 904 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
923 | data->fan_min[0] = (val >> 8) & 0xff; | 905 | data, data->groups); |
924 | data->fan_min[1] = val & 0xff; | 906 | return PTR_ERR_OR_ZERO(hwmon_dev); |
925 | 907 | } | |
926 | data->temp_input[0] = gl520_read_value(client, | ||
927 | GL520_REG_TEMP_INPUT[0]); | ||
928 | data->temp_max[0] = gl520_read_value(client, | ||
929 | GL520_REG_TEMP_MAX[0]); | ||
930 | data->temp_max_hyst[0] = gl520_read_value(client, | ||
931 | GL520_REG_TEMP_MAX_HYST[0]); | ||
932 | |||
933 | val = gl520_read_value(client, GL520_REG_FAN_DIV); | ||
934 | data->fan_div[0] = (val >> 6) & 0x03; | ||
935 | data->fan_div[1] = (val >> 4) & 0x03; | ||
936 | data->fan_off = (val >> 2) & 0x01; | ||
937 | |||
938 | data->alarms &= data->alarm_mask; | ||
939 | |||
940 | val = gl520_read_value(client, GL520_REG_CONF); | ||
941 | data->beep_enable = !((val >> 2) & 1); | ||
942 | |||
943 | /* Temp1 and Vin4 are the same input */ | ||
944 | if (data->two_temps) { | ||
945 | data->temp_input[1] = gl520_read_value(client, | ||
946 | GL520_REG_TEMP_INPUT[1]); | ||
947 | data->temp_max[1] = gl520_read_value(client, | ||
948 | GL520_REG_TEMP_MAX[1]); | ||
949 | data->temp_max_hyst[1] = gl520_read_value(client, | ||
950 | GL520_REG_TEMP_MAX_HYST[1]); | ||
951 | } else { | ||
952 | data->in_input[4] = gl520_read_value(client, | ||
953 | GL520_REG_IN_INPUT[4]); | ||
954 | data->in_min[4] = gl520_read_value(client, | ||
955 | GL520_REG_IN_MIN[4]); | ||
956 | data->in_max[4] = gl520_read_value(client, | ||
957 | GL520_REG_IN_MAX[4]); | ||
958 | } | ||
959 | |||
960 | data->last_updated = jiffies; | ||
961 | data->valid = 1; | ||
962 | } | ||
963 | 908 | ||
964 | mutex_unlock(&data->update_lock); | 909 | static const struct i2c_device_id gl520_id[] = { |
910 | { "gl520sm", 0 }, | ||
911 | { } | ||
912 | }; | ||
913 | MODULE_DEVICE_TABLE(i2c, gl520_id); | ||
965 | 914 | ||
966 | return data; | 915 | static struct i2c_driver gl520_driver = { |
967 | } | 916 | .class = I2C_CLASS_HWMON, |
917 | .driver = { | ||
918 | .name = "gl520sm", | ||
919 | }, | ||
920 | .probe = gl520_probe, | ||
921 | .id_table = gl520_id, | ||
922 | .detect = gl520_detect, | ||
923 | .address_list = normal_i2c, | ||
924 | }; | ||
968 | 925 | ||
969 | module_i2c_driver(gl520_driver); | 926 | module_i2c_driver(gl520_driver); |
970 | 927 | ||
diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c index 2566c43dd1e9..4efa1734bdad 100644 --- a/drivers/hwmon/gpio-fan.c +++ b/drivers/hwmon/gpio-fan.c | |||
@@ -173,7 +173,7 @@ static int get_fan_speed_index(struct gpio_fan_data *fan_data) | |||
173 | return -ENODEV; | 173 | return -ENODEV; |
174 | } | 174 | } |
175 | 175 | ||
176 | static int rpm_to_speed_index(struct gpio_fan_data *fan_data, int rpm) | 176 | static int rpm_to_speed_index(struct gpio_fan_data *fan_data, unsigned long rpm) |
177 | { | 177 | { |
178 | struct gpio_fan_speed *speed = fan_data->speed; | 178 | struct gpio_fan_speed *speed = fan_data->speed; |
179 | int i; | 179 | int i; |
@@ -537,9 +537,10 @@ static int gpio_fan_probe(struct platform_device *pdev) | |||
537 | } | 537 | } |
538 | 538 | ||
539 | /* Make this driver part of hwmon class. */ | 539 | /* Make this driver part of hwmon class. */ |
540 | fan_data->hwmon_dev = hwmon_device_register_with_groups(&pdev->dev, | 540 | fan_data->hwmon_dev = |
541 | "gpio_fan", fan_data, | 541 | devm_hwmon_device_register_with_groups(&pdev->dev, |
542 | gpio_fan_groups); | 542 | "gpio_fan", fan_data, |
543 | gpio_fan_groups); | ||
543 | if (IS_ERR(fan_data->hwmon_dev)) | 544 | if (IS_ERR(fan_data->hwmon_dev)) |
544 | return PTR_ERR(fan_data->hwmon_dev); | 545 | return PTR_ERR(fan_data->hwmon_dev); |
545 | 546 | ||
@@ -548,15 +549,6 @@ static int gpio_fan_probe(struct platform_device *pdev) | |||
548 | return 0; | 549 | return 0; |
549 | } | 550 | } |
550 | 551 | ||
551 | static int gpio_fan_remove(struct platform_device *pdev) | ||
552 | { | ||
553 | struct gpio_fan_data *fan_data = platform_get_drvdata(pdev); | ||
554 | |||
555 | hwmon_device_unregister(fan_data->hwmon_dev); | ||
556 | |||
557 | return 0; | ||
558 | } | ||
559 | |||
560 | #ifdef CONFIG_PM_SLEEP | 552 | #ifdef CONFIG_PM_SLEEP |
561 | static int gpio_fan_suspend(struct device *dev) | 553 | static int gpio_fan_suspend(struct device *dev) |
562 | { | 554 | { |
@@ -588,7 +580,6 @@ static SIMPLE_DEV_PM_OPS(gpio_fan_pm, gpio_fan_suspend, gpio_fan_resume); | |||
588 | 580 | ||
589 | static struct platform_driver gpio_fan_driver = { | 581 | static struct platform_driver gpio_fan_driver = { |
590 | .probe = gpio_fan_probe, | 582 | .probe = gpio_fan_probe, |
591 | .remove = gpio_fan_remove, | ||
592 | .driver = { | 583 | .driver = { |
593 | .name = "gpio-fan", | 584 | .name = "gpio-fan", |
594 | .pm = GPIO_FAN_PM, | 585 | .pm = GPIO_FAN_PM, |
diff --git a/drivers/hwmon/hih6130.c b/drivers/hwmon/hih6130.c index 7d68a08baaa8..0e01c4e13e33 100644 --- a/drivers/hwmon/hih6130.c +++ b/drivers/hwmon/hih6130.c | |||
@@ -46,7 +46,7 @@ | |||
46 | * @write_length: length for I2C measurement request | 46 | * @write_length: length for I2C measurement request |
47 | */ | 47 | */ |
48 | struct hih6130 { | 48 | struct hih6130 { |
49 | struct device *hwmon_dev; | 49 | struct i2c_client *client; |
50 | struct mutex lock; | 50 | struct mutex lock; |
51 | bool valid; | 51 | bool valid; |
52 | unsigned long last_update; | 52 | unsigned long last_update; |
@@ -62,7 +62,6 @@ struct hih6130 { | |||
62 | */ | 62 | */ |
63 | static inline int hih6130_temp_ticks_to_millicelsius(int ticks) | 63 | static inline int hih6130_temp_ticks_to_millicelsius(int ticks) |
64 | { | 64 | { |
65 | |||
66 | ticks = ticks >> 2; | 65 | ticks = ticks >> 2; |
67 | /* | 66 | /* |
68 | * from data sheet section 5.0 | 67 | * from data sheet section 5.0 |
@@ -78,7 +77,6 @@ static inline int hih6130_temp_ticks_to_millicelsius(int ticks) | |||
78 | */ | 77 | */ |
79 | static inline int hih6130_rh_ticks_to_per_cent_mille(int ticks) | 78 | static inline int hih6130_rh_ticks_to_per_cent_mille(int ticks) |
80 | { | 79 | { |
81 | |||
82 | ticks &= ~0xC000; /* clear status bits */ | 80 | ticks &= ~0xC000; /* clear status bits */ |
83 | /* | 81 | /* |
84 | * from data sheet section 4.0 | 82 | * from data sheet section 4.0 |
@@ -89,15 +87,16 @@ static inline int hih6130_rh_ticks_to_per_cent_mille(int ticks) | |||
89 | 87 | ||
90 | /** | 88 | /** |
91 | * hih6130_update_measurements() - get updated measurements from device | 89 | * hih6130_update_measurements() - get updated measurements from device |
92 | * @client: I2C client device | 90 | * @dev: device |
93 | * | 91 | * |
94 | * Returns 0 on success, else negative errno. | 92 | * Returns 0 on success, else negative errno. |
95 | */ | 93 | */ |
96 | static int hih6130_update_measurements(struct i2c_client *client) | 94 | static int hih6130_update_measurements(struct device *dev) |
97 | { | 95 | { |
96 | struct hih6130 *hih6130 = dev_get_drvdata(dev); | ||
97 | struct i2c_client *client = hih6130->client; | ||
98 | int ret = 0; | 98 | int ret = 0; |
99 | int t; | 99 | int t; |
100 | struct hih6130 *hih6130 = i2c_get_clientdata(client); | ||
101 | unsigned char tmp[4]; | 100 | unsigned char tmp[4]; |
102 | struct i2c_msg msgs[1] = { | 101 | struct i2c_msg msgs[1] = { |
103 | { | 102 | { |
@@ -176,9 +175,10 @@ static ssize_t hih6130_show_temperature(struct device *dev, | |||
176 | struct device_attribute *attr, | 175 | struct device_attribute *attr, |
177 | char *buf) | 176 | char *buf) |
178 | { | 177 | { |
179 | struct i2c_client *client = to_i2c_client(dev); | 178 | struct hih6130 *hih6130 = dev_get_drvdata(dev); |
180 | struct hih6130 *hih6130 = i2c_get_clientdata(client); | 179 | int ret; |
181 | int ret = hih6130_update_measurements(client); | 180 | |
181 | ret = hih6130_update_measurements(dev); | ||
182 | if (ret < 0) | 182 | if (ret < 0) |
183 | return ret; | 183 | return ret; |
184 | return sprintf(buf, "%d\n", hih6130->temperature); | 184 | return sprintf(buf, "%d\n", hih6130->temperature); |
@@ -196,9 +196,10 @@ static ssize_t hih6130_show_temperature(struct device *dev, | |||
196 | static ssize_t hih6130_show_humidity(struct device *dev, | 196 | static ssize_t hih6130_show_humidity(struct device *dev, |
197 | struct device_attribute *attr, char *buf) | 197 | struct device_attribute *attr, char *buf) |
198 | { | 198 | { |
199 | struct i2c_client *client = to_i2c_client(dev); | 199 | struct hih6130 *hih6130 = dev_get_drvdata(dev); |
200 | struct hih6130 *hih6130 = i2c_get_clientdata(client); | 200 | int ret; |
201 | int ret = hih6130_update_measurements(client); | 201 | |
202 | ret = hih6130_update_measurements(dev); | ||
202 | if (ret < 0) | 203 | if (ret < 0) |
203 | return ret; | 204 | return ret; |
204 | return sprintf(buf, "%d\n", hih6130->humidity); | 205 | return sprintf(buf, "%d\n", hih6130->humidity); |
@@ -210,79 +211,37 @@ static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, hih6130_show_temperature, | |||
210 | static SENSOR_DEVICE_ATTR(humidity1_input, S_IRUGO, hih6130_show_humidity, | 211 | static SENSOR_DEVICE_ATTR(humidity1_input, S_IRUGO, hih6130_show_humidity, |
211 | NULL, 0); | 212 | NULL, 0); |
212 | 213 | ||
213 | static struct attribute *hih6130_attributes[] = { | 214 | static struct attribute *hih6130_attrs[] = { |
214 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 215 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
215 | &sensor_dev_attr_humidity1_input.dev_attr.attr, | 216 | &sensor_dev_attr_humidity1_input.dev_attr.attr, |
216 | NULL | 217 | NULL |
217 | }; | 218 | }; |
218 | 219 | ||
219 | static const struct attribute_group hih6130_attr_group = { | 220 | ATTRIBUTE_GROUPS(hih6130); |
220 | .attrs = hih6130_attributes, | ||
221 | }; | ||
222 | 221 | ||
223 | /** | ||
224 | * hih6130_probe() - probe device | ||
225 | * @client: I2C client device | ||
226 | * @id: device ID | ||
227 | * | ||
228 | * Called by the I2C core when an entry in the ID table matches a | ||
229 | * device's name. | ||
230 | * Returns 0 on success. | ||
231 | */ | ||
232 | static int hih6130_probe(struct i2c_client *client, | 222 | static int hih6130_probe(struct i2c_client *client, |
233 | const struct i2c_device_id *id) | 223 | const struct i2c_device_id *id) |
234 | { | 224 | { |
225 | struct device *dev = &client->dev; | ||
235 | struct hih6130 *hih6130; | 226 | struct hih6130 *hih6130; |
236 | int err; | 227 | struct device *hwmon_dev; |
237 | 228 | ||
238 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { | 229 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { |
239 | dev_err(&client->dev, "adapter does not support true I2C\n"); | 230 | dev_err(&client->dev, "adapter does not support true I2C\n"); |
240 | return -ENODEV; | 231 | return -ENODEV; |
241 | } | 232 | } |
242 | 233 | ||
243 | hih6130 = devm_kzalloc(&client->dev, sizeof(*hih6130), GFP_KERNEL); | 234 | hih6130 = devm_kzalloc(dev, sizeof(*hih6130), GFP_KERNEL); |
244 | if (!hih6130) | 235 | if (!hih6130) |
245 | return -ENOMEM; | 236 | return -ENOMEM; |
246 | 237 | ||
247 | i2c_set_clientdata(client, hih6130); | 238 | hih6130->client = client; |
248 | |||
249 | mutex_init(&hih6130->lock); | 239 | mutex_init(&hih6130->lock); |
250 | 240 | ||
251 | err = sysfs_create_group(&client->dev.kobj, &hih6130_attr_group); | 241 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
252 | if (err) { | 242 | hih6130, |
253 | dev_dbg(&client->dev, "could not create sysfs files\n"); | 243 | hih6130_groups); |
254 | return err; | 244 | return PTR_ERR_OR_ZERO(hwmon_dev); |
255 | } | ||
256 | |||
257 | hih6130->hwmon_dev = hwmon_device_register(&client->dev); | ||
258 | if (IS_ERR(hih6130->hwmon_dev)) { | ||
259 | dev_dbg(&client->dev, "unable to register hwmon device\n"); | ||
260 | err = PTR_ERR(hih6130->hwmon_dev); | ||
261 | goto fail_remove_sysfs; | ||
262 | } | ||
263 | |||
264 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_QUICK)) | ||
265 | hih6130->write_length = 1; | ||
266 | |||
267 | return 0; | ||
268 | |||
269 | fail_remove_sysfs: | ||
270 | sysfs_remove_group(&client->dev.kobj, &hih6130_attr_group); | ||
271 | return err; | ||
272 | } | ||
273 | |||
274 | /** | ||
275 | * hih6130_remove() - remove device | ||
276 | * @client: I2C client device | ||
277 | */ | ||
278 | static int hih6130_remove(struct i2c_client *client) | ||
279 | { | ||
280 | struct hih6130 *hih6130 = i2c_get_clientdata(client); | ||
281 | |||
282 | hwmon_device_unregister(hih6130->hwmon_dev); | ||
283 | sysfs_remove_group(&client->dev.kobj, &hih6130_attr_group); | ||
284 | |||
285 | return 0; | ||
286 | } | 245 | } |
287 | 246 | ||
288 | /* Device ID table */ | 247 | /* Device ID table */ |
@@ -295,7 +254,6 @@ MODULE_DEVICE_TABLE(i2c, hih6130_id); | |||
295 | static struct i2c_driver hih6130_driver = { | 254 | static struct i2c_driver hih6130_driver = { |
296 | .driver.name = "hih6130", | 255 | .driver.name = "hih6130", |
297 | .probe = hih6130_probe, | 256 | .probe = hih6130_probe, |
298 | .remove = hih6130_remove, | ||
299 | .id_table = hih6130_id, | 257 | .id_table = hih6130_id, |
300 | }; | 258 | }; |
301 | 259 | ||
diff --git a/drivers/hwmon/htu21.c b/drivers/hwmon/htu21.c index 839086e0e951..4c3bbb72f82a 100644 --- a/drivers/hwmon/htu21.c +++ b/drivers/hwmon/htu21.c | |||
@@ -31,7 +31,7 @@ | |||
31 | #define HTU21_RH_MEASUREMENT_HM 0xE5 | 31 | #define HTU21_RH_MEASUREMENT_HM 0xE5 |
32 | 32 | ||
33 | struct htu21 { | 33 | struct htu21 { |
34 | struct device *hwmon_dev; | 34 | struct i2c_client *client; |
35 | struct mutex lock; | 35 | struct mutex lock; |
36 | bool valid; | 36 | bool valid; |
37 | unsigned long last_update; | 37 | unsigned long last_update; |
@@ -59,10 +59,11 @@ static inline int htu21_rh_ticks_to_per_cent_mille(int ticks) | |||
59 | return ((15625 * ticks) >> 13) - 6000; | 59 | return ((15625 * ticks) >> 13) - 6000; |
60 | } | 60 | } |
61 | 61 | ||
62 | static int htu21_update_measurements(struct i2c_client *client) | 62 | static int htu21_update_measurements(struct device *dev) |
63 | { | 63 | { |
64 | struct htu21 *htu21 = dev_get_drvdata(dev); | ||
65 | struct i2c_client *client = htu21->client; | ||
64 | int ret = 0; | 66 | int ret = 0; |
65 | struct htu21 *htu21 = i2c_get_clientdata(client); | ||
66 | 67 | ||
67 | mutex_lock(&htu21->lock); | 68 | mutex_lock(&htu21->lock); |
68 | 69 | ||
@@ -90,9 +91,10 @@ out: | |||
90 | static ssize_t htu21_show_temperature(struct device *dev, | 91 | static ssize_t htu21_show_temperature(struct device *dev, |
91 | struct device_attribute *attr, char *buf) | 92 | struct device_attribute *attr, char *buf) |
92 | { | 93 | { |
93 | struct i2c_client *client = to_i2c_client(dev); | 94 | struct htu21 *htu21 = dev_get_drvdata(dev); |
94 | struct htu21 *htu21 = i2c_get_clientdata(client); | 95 | int ret; |
95 | int ret = htu21_update_measurements(client); | 96 | |
97 | ret = htu21_update_measurements(dev); | ||
96 | if (ret < 0) | 98 | if (ret < 0) |
97 | return ret; | 99 | return ret; |
98 | return sprintf(buf, "%d\n", htu21->temperature); | 100 | return sprintf(buf, "%d\n", htu21->temperature); |
@@ -101,9 +103,10 @@ static ssize_t htu21_show_temperature(struct device *dev, | |||
101 | static ssize_t htu21_show_humidity(struct device *dev, | 103 | static ssize_t htu21_show_humidity(struct device *dev, |
102 | struct device_attribute *attr, char *buf) | 104 | struct device_attribute *attr, char *buf) |
103 | { | 105 | { |
104 | struct i2c_client *client = to_i2c_client(dev); | 106 | struct htu21 *htu21 = dev_get_drvdata(dev); |
105 | struct htu21 *htu21 = i2c_get_clientdata(client); | 107 | int ret; |
106 | int ret = htu21_update_measurements(client); | 108 | |
109 | ret = htu21_update_measurements(dev); | ||
107 | if (ret < 0) | 110 | if (ret < 0) |
108 | return ret; | 111 | return ret; |
109 | return sprintf(buf, "%d\n", htu21->humidity); | 112 | return sprintf(buf, "%d\n", htu21->humidity); |
@@ -114,21 +117,20 @@ static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, | |||
114 | static SENSOR_DEVICE_ATTR(humidity1_input, S_IRUGO, | 117 | static SENSOR_DEVICE_ATTR(humidity1_input, S_IRUGO, |
115 | htu21_show_humidity, NULL, 0); | 118 | htu21_show_humidity, NULL, 0); |
116 | 119 | ||
117 | static struct attribute *htu21_attributes[] = { | 120 | static struct attribute *htu21_attrs[] = { |
118 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 121 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
119 | &sensor_dev_attr_humidity1_input.dev_attr.attr, | 122 | &sensor_dev_attr_humidity1_input.dev_attr.attr, |
120 | NULL | 123 | NULL |
121 | }; | 124 | }; |
122 | 125 | ||
123 | static const struct attribute_group htu21_group = { | 126 | ATTRIBUTE_GROUPS(htu21); |
124 | .attrs = htu21_attributes, | ||
125 | }; | ||
126 | 127 | ||
127 | static int htu21_probe(struct i2c_client *client, | 128 | static int htu21_probe(struct i2c_client *client, |
128 | const struct i2c_device_id *id) | 129 | const struct i2c_device_id *id) |
129 | { | 130 | { |
131 | struct device *dev = &client->dev; | ||
130 | struct htu21 *htu21; | 132 | struct htu21 *htu21; |
131 | int err; | 133 | struct device *hwmon_dev; |
132 | 134 | ||
133 | if (!i2c_check_functionality(client->adapter, | 135 | if (!i2c_check_functionality(client->adapter, |
134 | I2C_FUNC_SMBUS_READ_WORD_DATA)) { | 136 | I2C_FUNC_SMBUS_READ_WORD_DATA)) { |
@@ -137,43 +139,17 @@ static int htu21_probe(struct i2c_client *client, | |||
137 | return -ENODEV; | 139 | return -ENODEV; |
138 | } | 140 | } |
139 | 141 | ||
140 | htu21 = devm_kzalloc(&client->dev, sizeof(*htu21), GFP_KERNEL); | 142 | htu21 = devm_kzalloc(dev, sizeof(*htu21), GFP_KERNEL); |
141 | if (!htu21) | 143 | if (!htu21) |
142 | return -ENOMEM; | 144 | return -ENOMEM; |
143 | 145 | ||
144 | i2c_set_clientdata(client, htu21); | 146 | htu21->client = client; |
145 | |||
146 | mutex_init(&htu21->lock); | 147 | mutex_init(&htu21->lock); |
147 | 148 | ||
148 | err = sysfs_create_group(&client->dev.kobj, &htu21_group); | 149 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
149 | if (err) { | 150 | htu21, |
150 | dev_dbg(&client->dev, "could not create sysfs files\n"); | 151 | htu21_groups); |
151 | return err; | 152 | return PTR_ERR_OR_ZERO(hwmon_dev); |
152 | } | ||
153 | htu21->hwmon_dev = hwmon_device_register(&client->dev); | ||
154 | if (IS_ERR(htu21->hwmon_dev)) { | ||
155 | dev_dbg(&client->dev, "unable to register hwmon device\n"); | ||
156 | err = PTR_ERR(htu21->hwmon_dev); | ||
157 | goto error; | ||
158 | } | ||
159 | |||
160 | dev_info(&client->dev, "initialized\n"); | ||
161 | |||
162 | return 0; | ||
163 | |||
164 | error: | ||
165 | sysfs_remove_group(&client->dev.kobj, &htu21_group); | ||
166 | return err; | ||
167 | } | ||
168 | |||
169 | static int htu21_remove(struct i2c_client *client) | ||
170 | { | ||
171 | struct htu21 *htu21 = i2c_get_clientdata(client); | ||
172 | |||
173 | hwmon_device_unregister(htu21->hwmon_dev); | ||
174 | sysfs_remove_group(&client->dev.kobj, &htu21_group); | ||
175 | |||
176 | return 0; | ||
177 | } | 153 | } |
178 | 154 | ||
179 | static const struct i2c_device_id htu21_id[] = { | 155 | static const struct i2c_device_id htu21_id[] = { |
@@ -188,7 +164,6 @@ static struct i2c_driver htu21_driver = { | |||
188 | .name = "htu21", | 164 | .name = "htu21", |
189 | }, | 165 | }, |
190 | .probe = htu21_probe, | 166 | .probe = htu21_probe, |
191 | .remove = htu21_remove, | ||
192 | .id_table = htu21_id, | 167 | .id_table = htu21_id, |
193 | }; | 168 | }; |
194 | 169 | ||
diff --git a/drivers/hwmon/ibmpowernv.c b/drivers/hwmon/ibmpowernv.c new file mode 100644 index 000000000000..d2bf2c97ae70 --- /dev/null +++ b/drivers/hwmon/ibmpowernv.c | |||
@@ -0,0 +1,363 @@ | |||
1 | /* | ||
2 | * IBM PowerNV platform sensors for temperature/fan/voltage/power | ||
3 | * Copyright (C) 2014 IBM | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. | ||
17 | */ | ||
18 | |||
19 | #define DRVNAME "ibmpowernv" | ||
20 | #define pr_fmt(fmt) DRVNAME ": " fmt | ||
21 | |||
22 | #include <linux/init.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/hwmon.h> | ||
26 | #include <linux/hwmon-sysfs.h> | ||
27 | #include <linux/of.h> | ||
28 | #include <linux/slab.h> | ||
29 | |||
30 | #include <linux/platform_device.h> | ||
31 | #include <asm/opal.h> | ||
32 | #include <linux/err.h> | ||
33 | |||
34 | #define MAX_ATTR_LEN 32 | ||
35 | |||
36 | /* Sensor suffix name from DT */ | ||
37 | #define DT_FAULT_ATTR_SUFFIX "faulted" | ||
38 | #define DT_DATA_ATTR_SUFFIX "data" | ||
39 | #define DT_THRESHOLD_ATTR_SUFFIX "thrs" | ||
40 | |||
41 | /* | ||
42 | * Enumerates all the types of sensors in the POWERNV platform and does index | ||
43 | * into 'struct sensor_group' | ||
44 | */ | ||
45 | enum sensors { | ||
46 | FAN, | ||
47 | AMBIENT_TEMP, | ||
48 | POWER_SUPPLY, | ||
49 | POWER_INPUT, | ||
50 | MAX_SENSOR_TYPE, | ||
51 | }; | ||
52 | |||
53 | static struct sensor_group { | ||
54 | const char *name; | ||
55 | const char *compatible; | ||
56 | struct attribute_group group; | ||
57 | u32 attr_count; | ||
58 | } sensor_groups[] = { | ||
59 | {"fan", "ibm,opal-sensor-cooling-fan"}, | ||
60 | {"temp", "ibm,opal-sensor-amb-temp"}, | ||
61 | {"in", "ibm,opal-sensor-power-supply"}, | ||
62 | {"power", "ibm,opal-sensor-power"} | ||
63 | }; | ||
64 | |||
65 | struct sensor_data { | ||
66 | u32 id; /* An opaque id of the firmware for each sensor */ | ||
67 | enum sensors type; | ||
68 | char name[MAX_ATTR_LEN]; | ||
69 | struct device_attribute dev_attr; | ||
70 | }; | ||
71 | |||
72 | struct platform_data { | ||
73 | const struct attribute_group *attr_groups[MAX_SENSOR_TYPE + 1]; | ||
74 | u32 sensors_count; /* Total count of sensors from each group */ | ||
75 | }; | ||
76 | |||
77 | /* Platform device representing all the ibmpowernv sensors */ | ||
78 | static struct platform_device *pdevice; | ||
79 | |||
80 | static ssize_t show_sensor(struct device *dev, struct device_attribute *devattr, | ||
81 | char *buf) | ||
82 | { | ||
83 | struct sensor_data *sdata = container_of(devattr, struct sensor_data, | ||
84 | dev_attr); | ||
85 | ssize_t ret; | ||
86 | u32 x; | ||
87 | |||
88 | ret = opal_get_sensor_data(sdata->id, &x); | ||
89 | if (ret) | ||
90 | return ret; | ||
91 | |||
92 | /* Convert temperature to milli-degrees */ | ||
93 | if (sdata->type == AMBIENT_TEMP) | ||
94 | x *= 1000; | ||
95 | /* Convert power to micro-watts */ | ||
96 | else if (sdata->type == POWER_INPUT) | ||
97 | x *= 1000000; | ||
98 | |||
99 | return sprintf(buf, "%u\n", x); | ||
100 | } | ||
101 | |||
102 | static int __init get_sensor_index_attr(const char *name, u32 *index, | ||
103 | char *attr) | ||
104 | { | ||
105 | char *hash_pos = strchr(name, '#'); | ||
106 | char buf[8] = { 0 }; | ||
107 | char *dash_pos; | ||
108 | u32 copy_len; | ||
109 | int err; | ||
110 | |||
111 | if (!hash_pos) | ||
112 | return -EINVAL; | ||
113 | |||
114 | dash_pos = strchr(hash_pos, '-'); | ||
115 | if (!dash_pos) | ||
116 | return -EINVAL; | ||
117 | |||
118 | copy_len = dash_pos - hash_pos - 1; | ||
119 | if (copy_len >= sizeof(buf)) | ||
120 | return -EINVAL; | ||
121 | |||
122 | strncpy(buf, hash_pos + 1, copy_len); | ||
123 | |||
124 | err = kstrtou32(buf, 10, index); | ||
125 | if (err) | ||
126 | return err; | ||
127 | |||
128 | strncpy(attr, dash_pos + 1, MAX_ATTR_LEN); | ||
129 | |||
130 | return 0; | ||
131 | } | ||
132 | |||
133 | /* | ||
134 | * This function translates the DT node name into the 'hwmon' attribute name. | ||
135 | * IBMPOWERNV device node appear like cooling-fan#2-data, amb-temp#1-thrs etc. | ||
136 | * which need to be mapped as fan2_input, temp1_max respectively before | ||
137 | * populating them inside hwmon device class. | ||
138 | */ | ||
139 | static int __init create_hwmon_attr_name(struct device *dev, enum sensors type, | ||
140 | const char *node_name, | ||
141 | char *hwmon_attr_name) | ||
142 | { | ||
143 | char attr_suffix[MAX_ATTR_LEN]; | ||
144 | char *attr_name; | ||
145 | u32 index; | ||
146 | int err; | ||
147 | |||
148 | err = get_sensor_index_attr(node_name, &index, attr_suffix); | ||
149 | if (err) { | ||
150 | dev_err(dev, "Sensor device node name '%s' is invalid\n", | ||
151 | node_name); | ||
152 | return err; | ||
153 | } | ||
154 | |||
155 | if (!strcmp(attr_suffix, DT_FAULT_ATTR_SUFFIX)) { | ||
156 | attr_name = "fault"; | ||
157 | } else if (!strcmp(attr_suffix, DT_DATA_ATTR_SUFFIX)) { | ||
158 | attr_name = "input"; | ||
159 | } else if (!strcmp(attr_suffix, DT_THRESHOLD_ATTR_SUFFIX)) { | ||
160 | if (type == AMBIENT_TEMP) | ||
161 | attr_name = "max"; | ||
162 | else if (type == FAN) | ||
163 | attr_name = "min"; | ||
164 | else | ||
165 | return -ENOENT; | ||
166 | } else { | ||
167 | return -ENOENT; | ||
168 | } | ||
169 | |||
170 | snprintf(hwmon_attr_name, MAX_ATTR_LEN, "%s%d_%s", | ||
171 | sensor_groups[type].name, index, attr_name); | ||
172 | return 0; | ||
173 | } | ||
174 | |||
175 | static int __init populate_attr_groups(struct platform_device *pdev) | ||
176 | { | ||
177 | struct platform_data *pdata = platform_get_drvdata(pdev); | ||
178 | const struct attribute_group **pgroups = pdata->attr_groups; | ||
179 | struct device_node *opal, *np; | ||
180 | enum sensors type; | ||
181 | |||
182 | opal = of_find_node_by_path("/ibm,opal/sensors"); | ||
183 | if (!opal) { | ||
184 | dev_err(&pdev->dev, "Opal node 'sensors' not found\n"); | ||
185 | return -ENODEV; | ||
186 | } | ||
187 | |||
188 | for_each_child_of_node(opal, np) { | ||
189 | if (np->name == NULL) | ||
190 | continue; | ||
191 | |||
192 | for (type = 0; type < MAX_SENSOR_TYPE; type++) | ||
193 | if (of_device_is_compatible(np, | ||
194 | sensor_groups[type].compatible)) { | ||
195 | sensor_groups[type].attr_count++; | ||
196 | break; | ||
197 | } | ||
198 | } | ||
199 | |||
200 | of_node_put(opal); | ||
201 | |||
202 | for (type = 0; type < MAX_SENSOR_TYPE; type++) { | ||
203 | sensor_groups[type].group.attrs = devm_kzalloc(&pdev->dev, | ||
204 | sizeof(struct attribute *) * | ||
205 | (sensor_groups[type].attr_count + 1), | ||
206 | GFP_KERNEL); | ||
207 | if (!sensor_groups[type].group.attrs) | ||
208 | return -ENOMEM; | ||
209 | |||
210 | pgroups[type] = &sensor_groups[type].group; | ||
211 | pdata->sensors_count += sensor_groups[type].attr_count; | ||
212 | sensor_groups[type].attr_count = 0; | ||
213 | } | ||
214 | |||
215 | return 0; | ||
216 | } | ||
217 | |||
218 | /* | ||
219 | * Iterate through the device tree for each child of 'sensors' node, create | ||
220 | * a sysfs attribute file, the file is named by translating the DT node name | ||
221 | * to the name required by the higher 'hwmon' driver like fan1_input, temp1_max | ||
222 | * etc.. | ||
223 | */ | ||
224 | static int __init create_device_attrs(struct platform_device *pdev) | ||
225 | { | ||
226 | struct platform_data *pdata = platform_get_drvdata(pdev); | ||
227 | const struct attribute_group **pgroups = pdata->attr_groups; | ||
228 | struct device_node *opal, *np; | ||
229 | struct sensor_data *sdata; | ||
230 | u32 sensor_id; | ||
231 | enum sensors type; | ||
232 | u32 count = 0; | ||
233 | int err = 0; | ||
234 | |||
235 | opal = of_find_node_by_path("/ibm,opal/sensors"); | ||
236 | sdata = devm_kzalloc(&pdev->dev, pdata->sensors_count * sizeof(*sdata), | ||
237 | GFP_KERNEL); | ||
238 | if (!sdata) { | ||
239 | err = -ENOMEM; | ||
240 | goto exit_put_node; | ||
241 | } | ||
242 | |||
243 | for_each_child_of_node(opal, np) { | ||
244 | if (np->name == NULL) | ||
245 | continue; | ||
246 | |||
247 | for (type = 0; type < MAX_SENSOR_TYPE; type++) | ||
248 | if (of_device_is_compatible(np, | ||
249 | sensor_groups[type].compatible)) | ||
250 | break; | ||
251 | |||
252 | if (type == MAX_SENSOR_TYPE) | ||
253 | continue; | ||
254 | |||
255 | if (of_property_read_u32(np, "sensor-id", &sensor_id)) { | ||
256 | dev_info(&pdev->dev, | ||
257 | "'sensor-id' missing in the node '%s'\n", | ||
258 | np->name); | ||
259 | continue; | ||
260 | } | ||
261 | |||
262 | sdata[count].id = sensor_id; | ||
263 | sdata[count].type = type; | ||
264 | err = create_hwmon_attr_name(&pdev->dev, type, np->name, | ||
265 | sdata[count].name); | ||
266 | if (err) | ||
267 | goto exit_put_node; | ||
268 | |||
269 | sysfs_attr_init(&sdata[count].dev_attr.attr); | ||
270 | sdata[count].dev_attr.attr.name = sdata[count].name; | ||
271 | sdata[count].dev_attr.attr.mode = S_IRUGO; | ||
272 | sdata[count].dev_attr.show = show_sensor; | ||
273 | |||
274 | pgroups[type]->attrs[sensor_groups[type].attr_count++] = | ||
275 | &sdata[count++].dev_attr.attr; | ||
276 | } | ||
277 | |||
278 | exit_put_node: | ||
279 | of_node_put(opal); | ||
280 | return err; | ||
281 | } | ||
282 | |||
283 | static int __init ibmpowernv_probe(struct platform_device *pdev) | ||
284 | { | ||
285 | struct platform_data *pdata; | ||
286 | struct device *hwmon_dev; | ||
287 | int err; | ||
288 | |||
289 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); | ||
290 | if (!pdata) | ||
291 | return -ENOMEM; | ||
292 | |||
293 | platform_set_drvdata(pdev, pdata); | ||
294 | pdata->sensors_count = 0; | ||
295 | err = populate_attr_groups(pdev); | ||
296 | if (err) | ||
297 | return err; | ||
298 | |||
299 | /* Create sysfs attribute data for each sensor found in the DT */ | ||
300 | err = create_device_attrs(pdev); | ||
301 | if (err) | ||
302 | return err; | ||
303 | |||
304 | /* Finally, register with hwmon */ | ||
305 | hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev, DRVNAME, | ||
306 | pdata, | ||
307 | pdata->attr_groups); | ||
308 | |||
309 | return PTR_ERR_OR_ZERO(hwmon_dev); | ||
310 | } | ||
311 | |||
312 | static struct platform_driver ibmpowernv_driver = { | ||
313 | .driver = { | ||
314 | .owner = THIS_MODULE, | ||
315 | .name = DRVNAME, | ||
316 | }, | ||
317 | }; | ||
318 | |||
319 | static int __init ibmpowernv_init(void) | ||
320 | { | ||
321 | int err; | ||
322 | |||
323 | pdevice = platform_device_alloc(DRVNAME, 0); | ||
324 | if (!pdevice) { | ||
325 | pr_err("Device allocation failed\n"); | ||
326 | err = -ENOMEM; | ||
327 | goto exit; | ||
328 | } | ||
329 | |||
330 | err = platform_device_add(pdevice); | ||
331 | if (err) { | ||
332 | pr_err("Device addition failed (%d)\n", err); | ||
333 | goto exit_device_put; | ||
334 | } | ||
335 | |||
336 | err = platform_driver_probe(&ibmpowernv_driver, ibmpowernv_probe); | ||
337 | if (err) { | ||
338 | pr_err("Platfrom driver probe failed\n"); | ||
339 | goto exit_device_del; | ||
340 | } | ||
341 | |||
342 | return 0; | ||
343 | |||
344 | exit_device_del: | ||
345 | platform_device_del(pdevice); | ||
346 | exit_device_put: | ||
347 | platform_device_put(pdevice); | ||
348 | exit: | ||
349 | return err; | ||
350 | } | ||
351 | |||
352 | static void __exit ibmpowernv_exit(void) | ||
353 | { | ||
354 | platform_driver_unregister(&ibmpowernv_driver); | ||
355 | platform_device_unregister(pdevice); | ||
356 | } | ||
357 | |||
358 | MODULE_AUTHOR("Neelesh Gupta <neelegup@linux.vnet.ibm.com>"); | ||
359 | MODULE_DESCRIPTION("IBM POWERNV platform sensors"); | ||
360 | MODULE_LICENSE("GPL"); | ||
361 | |||
362 | module_init(ibmpowernv_init); | ||
363 | module_exit(ibmpowernv_exit); | ||
diff --git a/drivers/hwmon/lineage-pem.c b/drivers/hwmon/lineage-pem.c index ebbb9f4f27a3..84d791bdb62d 100644 --- a/drivers/hwmon/lineage-pem.c +++ b/drivers/hwmon/lineage-pem.c | |||
@@ -125,7 +125,8 @@ | |||
125 | #define FAN_SPEED_LEN 5 | 125 | #define FAN_SPEED_LEN 5 |
126 | 126 | ||
127 | struct pem_data { | 127 | struct pem_data { |
128 | struct device *hwmon_dev; | 128 | struct i2c_client *client; |
129 | const struct attribute_group *groups[4]; | ||
129 | 130 | ||
130 | struct mutex update_lock; | 131 | struct mutex update_lock; |
131 | bool valid; | 132 | bool valid; |
@@ -160,8 +161,8 @@ abort: | |||
160 | 161 | ||
161 | static struct pem_data *pem_update_device(struct device *dev) | 162 | static struct pem_data *pem_update_device(struct device *dev) |
162 | { | 163 | { |
163 | struct i2c_client *client = to_i2c_client(dev); | 164 | struct pem_data *data = dev_get_drvdata(dev); |
164 | struct pem_data *data = i2c_get_clientdata(client); | 165 | struct i2c_client *client = data->client; |
165 | struct pem_data *ret = data; | 166 | struct pem_data *ret = data; |
166 | 167 | ||
167 | mutex_lock(&data->update_lock); | 168 | mutex_lock(&data->update_lock); |
@@ -444,18 +445,20 @@ static int pem_probe(struct i2c_client *client, | |||
444 | const struct i2c_device_id *id) | 445 | const struct i2c_device_id *id) |
445 | { | 446 | { |
446 | struct i2c_adapter *adapter = client->adapter; | 447 | struct i2c_adapter *adapter = client->adapter; |
448 | struct device *dev = &client->dev; | ||
449 | struct device *hwmon_dev; | ||
447 | struct pem_data *data; | 450 | struct pem_data *data; |
448 | int ret; | 451 | int ret, idx = 0; |
449 | 452 | ||
450 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BLOCK_DATA | 453 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BLOCK_DATA |
451 | | I2C_FUNC_SMBUS_WRITE_BYTE)) | 454 | | I2C_FUNC_SMBUS_WRITE_BYTE)) |
452 | return -ENODEV; | 455 | return -ENODEV; |
453 | 456 | ||
454 | data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); | 457 | data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); |
455 | if (!data) | 458 | if (!data) |
456 | return -ENOMEM; | 459 | return -ENOMEM; |
457 | 460 | ||
458 | i2c_set_clientdata(client, data); | 461 | data->client = client; |
459 | mutex_init(&data->update_lock); | 462 | mutex_init(&data->update_lock); |
460 | 463 | ||
461 | /* | 464 | /* |
@@ -471,14 +474,12 @@ static int pem_probe(struct i2c_client *client, | |||
471 | if (ret < 0) | 474 | if (ret < 0) |
472 | return ret; | 475 | return ret; |
473 | 476 | ||
474 | dev_info(&client->dev, "Firmware revision %d.%d.%d\n", | 477 | dev_info(dev, "Firmware revision %d.%d.%d\n", |
475 | data->firmware_rev[0], data->firmware_rev[1], | 478 | data->firmware_rev[0], data->firmware_rev[1], |
476 | data->firmware_rev[2]); | 479 | data->firmware_rev[2]); |
477 | 480 | ||
478 | /* Register sysfs hooks */ | 481 | /* sysfs hooks */ |
479 | ret = sysfs_create_group(&client->dev.kobj, &pem_group); | 482 | data->groups[idx++] = &pem_group; |
480 | if (ret) | ||
481 | return ret; | ||
482 | 483 | ||
483 | /* | 484 | /* |
484 | * Check if input readings are supported. | 485 | * Check if input readings are supported. |
@@ -501,12 +502,9 @@ static int pem_probe(struct i2c_client *client, | |||
501 | data->input_string[2] || data->input_string[3])) | 502 | data->input_string[2] || data->input_string[3])) |
502 | data->input_length = sizeof(data->input_string); | 503 | data->input_length = sizeof(data->input_string); |
503 | } | 504 | } |
504 | ret = 0; | 505 | |
505 | if (data->input_length) { | 506 | if (data->input_length) |
506 | ret = sysfs_create_group(&client->dev.kobj, &pem_input_group); | 507 | data->groups[idx++] = &pem_input_group; |
507 | if (ret) | ||
508 | goto out_remove_groups; | ||
509 | } | ||
510 | 508 | ||
511 | /* | 509 | /* |
512 | * Check if fan speed readings are supported. | 510 | * Check if fan speed readings are supported. |
@@ -520,37 +518,12 @@ static int pem_probe(struct i2c_client *client, | |||
520 | if (!ret && (data->fan_speed[0] || data->fan_speed[1] || | 518 | if (!ret && (data->fan_speed[0] || data->fan_speed[1] || |
521 | data->fan_speed[2] || data->fan_speed[3])) { | 519 | data->fan_speed[2] || data->fan_speed[3])) { |
522 | data->fans_supported = true; | 520 | data->fans_supported = true; |
523 | ret = sysfs_create_group(&client->dev.kobj, &pem_fan_group); | 521 | data->groups[idx++] = &pem_fan_group; |
524 | if (ret) | ||
525 | goto out_remove_groups; | ||
526 | } | ||
527 | |||
528 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
529 | if (IS_ERR(data->hwmon_dev)) { | ||
530 | ret = PTR_ERR(data->hwmon_dev); | ||
531 | goto out_remove_groups; | ||
532 | } | 522 | } |
533 | 523 | ||
534 | return 0; | 524 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
535 | 525 | data, data->groups); | |
536 | out_remove_groups: | 526 | return PTR_ERR_OR_ZERO(hwmon_dev); |
537 | sysfs_remove_group(&client->dev.kobj, &pem_input_group); | ||
538 | sysfs_remove_group(&client->dev.kobj, &pem_fan_group); | ||
539 | sysfs_remove_group(&client->dev.kobj, &pem_group); | ||
540 | return ret; | ||
541 | } | ||
542 | |||
543 | static int pem_remove(struct i2c_client *client) | ||
544 | { | ||
545 | struct pem_data *data = i2c_get_clientdata(client); | ||
546 | |||
547 | hwmon_device_unregister(data->hwmon_dev); | ||
548 | |||
549 | sysfs_remove_group(&client->dev.kobj, &pem_input_group); | ||
550 | sysfs_remove_group(&client->dev.kobj, &pem_fan_group); | ||
551 | sysfs_remove_group(&client->dev.kobj, &pem_group); | ||
552 | |||
553 | return 0; | ||
554 | } | 527 | } |
555 | 528 | ||
556 | static const struct i2c_device_id pem_id[] = { | 529 | static const struct i2c_device_id pem_id[] = { |
@@ -564,7 +537,6 @@ static struct i2c_driver pem_driver = { | |||
564 | .name = "lineage_pem", | 537 | .name = "lineage_pem", |
565 | }, | 538 | }, |
566 | .probe = pem_probe, | 539 | .probe = pem_probe, |
567 | .remove = pem_remove, | ||
568 | .id_table = pem_id, | 540 | .id_table = pem_id, |
569 | }; | 541 | }; |
570 | 542 | ||
diff --git a/drivers/hwmon/lm63.c b/drivers/hwmon/lm63.c index 848b9611151f..33bfdb444138 100644 --- a/drivers/hwmon/lm63.c +++ b/drivers/hwmon/lm63.c | |||
@@ -126,24 +126,17 @@ static const unsigned short normal_i2c[] = { 0x18, 0x4c, 0x4e, I2C_CLIENT_END }; | |||
126 | #define FAN_TO_REG(val) ((val) <= 82 ? 0xFFFC : \ | 126 | #define FAN_TO_REG(val) ((val) <= 82 ? 0xFFFC : \ |
127 | (5400000 / (val)) & 0xFFFC) | 127 | (5400000 / (val)) & 0xFFFC) |
128 | #define TEMP8_FROM_REG(reg) ((reg) * 1000) | 128 | #define TEMP8_FROM_REG(reg) ((reg) * 1000) |
129 | #define TEMP8_TO_REG(val) ((val) <= -128000 ? -128 : \ | 129 | #define TEMP8_TO_REG(val) DIV_ROUND_CLOSEST(clamp_val((val), -128000, \ |
130 | (val) >= 127000 ? 127 : \ | 130 | 127000), 1000) |
131 | (val) < 0 ? ((val) - 500) / 1000 : \ | 131 | #define TEMP8U_TO_REG(val) DIV_ROUND_CLOSEST(clamp_val((val), 0, \ |
132 | ((val) + 500) / 1000) | 132 | 255000), 1000) |
133 | #define TEMP8U_TO_REG(val) ((val) <= 0 ? 0 : \ | ||
134 | (val) >= 255000 ? 255 : \ | ||
135 | ((val) + 500) / 1000) | ||
136 | #define TEMP11_FROM_REG(reg) ((reg) / 32 * 125) | 133 | #define TEMP11_FROM_REG(reg) ((reg) / 32 * 125) |
137 | #define TEMP11_TO_REG(val) ((val) <= -128000 ? 0x8000 : \ | 134 | #define TEMP11_TO_REG(val) (DIV_ROUND_CLOSEST(clamp_val((val), -128000, \ |
138 | (val) >= 127875 ? 0x7FE0 : \ | 135 | 127875), 125) * 32) |
139 | (val) < 0 ? ((val) - 62) / 125 * 32 : \ | 136 | #define TEMP11U_TO_REG(val) (DIV_ROUND_CLOSEST(clamp_val((val), 0, \ |
140 | ((val) + 62) / 125 * 32) | 137 | 255875), 125) * 32) |
141 | #define TEMP11U_TO_REG(val) ((val) <= 0 ? 0 : \ | 138 | #define HYST_TO_REG(val) DIV_ROUND_CLOSEST(clamp_val((val), 0, 127000), \ |
142 | (val) >= 255875 ? 0xFFE0 : \ | 139 | 1000) |
143 | ((val) + 62) / 125 * 32) | ||
144 | #define HYST_TO_REG(val) ((val) <= 0 ? 0 : \ | ||
145 | (val) >= 127000 ? 127 : \ | ||
146 | ((val) + 500) / 1000) | ||
147 | 140 | ||
148 | #define UPDATE_INTERVAL(max, rate) \ | 141 | #define UPDATE_INTERVAL(max, rate) \ |
149 | ((1000 << (LM63_MAX_CONVRATE - (rate))) / (max)) | 142 | ((1000 << (LM63_MAX_CONVRATE - (rate))) / (max)) |
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index 479ffbeed3f8..d16dbb33a531 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c | |||
@@ -52,6 +52,7 @@ enum lm75_type { /* keep sorted in alphabetical order */ | |||
52 | tmp100, | 52 | tmp100, |
53 | tmp101, | 53 | tmp101, |
54 | tmp105, | 54 | tmp105, |
55 | tmp112, | ||
55 | tmp175, | 56 | tmp175, |
56 | tmp275, | 57 | tmp275, |
57 | tmp75, | 58 | tmp75, |
@@ -255,6 +256,12 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
255 | data->sample_time = HZ; | 256 | data->sample_time = HZ; |
256 | clr_mask |= 1 << 7; /* not one-shot mode */ | 257 | clr_mask |= 1 << 7; /* not one-shot mode */ |
257 | break; | 258 | break; |
259 | case tmp112: | ||
260 | set_mask |= 3 << 5; /* 12-bit mode */ | ||
261 | clr_mask |= 1 << 7; /* not one-shot mode */ | ||
262 | data->resolution = 12; | ||
263 | data->sample_time = HZ / 4; | ||
264 | break; | ||
258 | case tmp105: | 265 | case tmp105: |
259 | case tmp175: | 266 | case tmp175: |
260 | case tmp275: | 267 | case tmp275: |
@@ -323,6 +330,7 @@ static const struct i2c_device_id lm75_ids[] = { | |||
323 | { "tmp100", tmp100, }, | 330 | { "tmp100", tmp100, }, |
324 | { "tmp101", tmp101, }, | 331 | { "tmp101", tmp101, }, |
325 | { "tmp105", tmp105, }, | 332 | { "tmp105", tmp105, }, |
333 | { "tmp112", tmp112, }, | ||
326 | { "tmp175", tmp175, }, | 334 | { "tmp175", tmp175, }, |
327 | { "tmp275", tmp275, }, | 335 | { "tmp275", tmp275, }, |
328 | { "tmp75", tmp75, }, | 336 | { "tmp75", tmp75, }, |
diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c index 5ceb443b938d..69b05cc2f60e 100644 --- a/drivers/hwmon/lm77.c +++ b/drivers/hwmon/lm77.c | |||
@@ -80,8 +80,7 @@ struct lm77_data { | |||
80 | */ | 80 | */ |
81 | static inline s16 LM77_TEMP_TO_REG(int temp) | 81 | static inline s16 LM77_TEMP_TO_REG(int temp) |
82 | { | 82 | { |
83 | int ntemp = clamp_val(temp, LM77_TEMP_MIN, LM77_TEMP_MAX); | 83 | return (temp / 500) * 8; |
84 | return (ntemp / 500) * 8; | ||
85 | } | 84 | } |
86 | 85 | ||
87 | static inline int LM77_TEMP_FROM_REG(s16 reg) | 86 | static inline int LM77_TEMP_FROM_REG(s16 reg) |
@@ -175,6 +174,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *devattr, | |||
175 | if (err) | 174 | if (err) |
176 | return err; | 175 | return err; |
177 | 176 | ||
177 | val = clamp_val(val, LM77_TEMP_MIN, LM77_TEMP_MAX); | ||
178 | mutex_lock(&data->update_lock); | 178 | mutex_lock(&data->update_lock); |
179 | data->temp[nr] = val; | 179 | data->temp[nr] = val; |
180 | lm77_write_value(client, temp_regs[nr], LM77_TEMP_TO_REG(val)); | 180 | lm77_write_value(client, temp_regs[nr], LM77_TEMP_TO_REG(val)); |
@@ -192,15 +192,16 @@ static ssize_t set_temp_hyst(struct device *dev, | |||
192 | { | 192 | { |
193 | struct lm77_data *data = dev_get_drvdata(dev); | 193 | struct lm77_data *data = dev_get_drvdata(dev); |
194 | struct i2c_client *client = data->client; | 194 | struct i2c_client *client = data->client; |
195 | unsigned long val; | 195 | long val; |
196 | int err; | 196 | int err; |
197 | 197 | ||
198 | err = kstrtoul(buf, 10, &val); | 198 | err = kstrtol(buf, 10, &val); |
199 | if (err) | 199 | if (err) |
200 | return err; | 200 | return err; |
201 | 201 | ||
202 | mutex_lock(&data->update_lock); | 202 | mutex_lock(&data->update_lock); |
203 | data->temp[t_hyst] = data->temp[t_crit] - val; | 203 | val = clamp_val(data->temp[t_crit] - val, LM77_TEMP_MIN, LM77_TEMP_MAX); |
204 | data->temp[t_hyst] = val; | ||
204 | lm77_write_value(client, LM77_REG_TEMP_HYST, | 205 | lm77_write_value(client, LM77_REG_TEMP_HYST, |
205 | LM77_TEMP_TO_REG(data->temp[t_hyst])); | 206 | LM77_TEMP_TO_REG(data->temp[t_hyst])); |
206 | mutex_unlock(&data->update_lock); | 207 | mutex_unlock(&data->update_lock); |
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c index 9efadfc851bc..759661c7d480 100644 --- a/drivers/hwmon/lm78.c +++ b/drivers/hwmon/lm78.c | |||
@@ -108,7 +108,7 @@ static inline int FAN_FROM_REG(u8 val, int div) | |||
108 | * TEMP: mC (-128C to +127C) | 108 | * TEMP: mC (-128C to +127C) |
109 | * REG: 1C/bit, two's complement | 109 | * REG: 1C/bit, two's complement |
110 | */ | 110 | */ |
111 | static inline s8 TEMP_TO_REG(int val) | 111 | static inline s8 TEMP_TO_REG(long val) |
112 | { | 112 | { |
113 | int nval = clamp_val(val, -128000, 127000) ; | 113 | int nval = clamp_val(val, -128000, 127000) ; |
114 | return nval < 0 ? (nval - 500) / 1000 : (nval + 500) / 1000; | 114 | return nval < 0 ? (nval - 500) / 1000 : (nval + 500) / 1000; |
@@ -123,7 +123,6 @@ static inline int TEMP_FROM_REG(s8 val) | |||
123 | 123 | ||
124 | struct lm78_data { | 124 | struct lm78_data { |
125 | struct i2c_client *client; | 125 | struct i2c_client *client; |
126 | struct device *hwmon_dev; | ||
127 | struct mutex lock; | 126 | struct mutex lock; |
128 | enum chips type; | 127 | enum chips type; |
129 | 128 | ||
@@ -468,7 +467,7 @@ static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7); | |||
468 | static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11); | 467 | static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11); |
469 | static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4); | 468 | static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4); |
470 | 469 | ||
471 | static struct attribute *lm78_attributes[] = { | 470 | static struct attribute *lm78_attrs[] = { |
472 | &sensor_dev_attr_in0_input.dev_attr.attr, | 471 | &sensor_dev_attr_in0_input.dev_attr.attr, |
473 | &sensor_dev_attr_in0_min.dev_attr.attr, | 472 | &sensor_dev_attr_in0_min.dev_attr.attr, |
474 | &sensor_dev_attr_in0_max.dev_attr.attr, | 473 | &sensor_dev_attr_in0_max.dev_attr.attr, |
@@ -519,9 +518,7 @@ static struct attribute *lm78_attributes[] = { | |||
519 | NULL | 518 | NULL |
520 | }; | 519 | }; |
521 | 520 | ||
522 | static const struct attribute_group lm78_group = { | 521 | ATTRIBUTE_GROUPS(lm78); |
523 | .attrs = lm78_attributes, | ||
524 | }; | ||
525 | 522 | ||
526 | /* | 523 | /* |
527 | * ISA related code | 524 | * ISA related code |
@@ -533,19 +530,6 @@ static struct platform_device *pdev; | |||
533 | 530 | ||
534 | static unsigned short isa_address = 0x290; | 531 | static unsigned short isa_address = 0x290; |
535 | 532 | ||
536 | /* | ||
537 | * I2C devices get this name attribute automatically, but for ISA devices | ||
538 | * we must create it by ourselves. | ||
539 | */ | ||
540 | static ssize_t show_name(struct device *dev, struct device_attribute | ||
541 | *devattr, char *buf) | ||
542 | { | ||
543 | struct lm78_data *data = dev_get_drvdata(dev); | ||
544 | |||
545 | return sprintf(buf, "%s\n", data->name); | ||
546 | } | ||
547 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | ||
548 | |||
549 | static struct lm78_data *lm78_data_if_isa(void) | 533 | static struct lm78_data *lm78_data_if_isa(void) |
550 | { | 534 | { |
551 | return pdev ? platform_get_drvdata(pdev) : NULL; | 535 | return pdev ? platform_get_drvdata(pdev) : NULL; |
@@ -661,46 +645,23 @@ static int lm78_i2c_detect(struct i2c_client *client, | |||
661 | static int lm78_i2c_probe(struct i2c_client *client, | 645 | static int lm78_i2c_probe(struct i2c_client *client, |
662 | const struct i2c_device_id *id) | 646 | const struct i2c_device_id *id) |
663 | { | 647 | { |
648 | struct device *dev = &client->dev; | ||
649 | struct device *hwmon_dev; | ||
664 | struct lm78_data *data; | 650 | struct lm78_data *data; |
665 | int err; | ||
666 | 651 | ||
667 | data = devm_kzalloc(&client->dev, sizeof(struct lm78_data), GFP_KERNEL); | 652 | data = devm_kzalloc(dev, sizeof(struct lm78_data), GFP_KERNEL); |
668 | if (!data) | 653 | if (!data) |
669 | return -ENOMEM; | 654 | return -ENOMEM; |
670 | 655 | ||
671 | i2c_set_clientdata(client, data); | ||
672 | data->client = client; | 656 | data->client = client; |
673 | data->type = id->driver_data; | 657 | data->type = id->driver_data; |
674 | 658 | ||
675 | /* Initialize the LM78 chip */ | 659 | /* Initialize the LM78 chip */ |
676 | lm78_init_device(data); | 660 | lm78_init_device(data); |
677 | 661 | ||
678 | /* Register sysfs hooks */ | 662 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
679 | err = sysfs_create_group(&client->dev.kobj, &lm78_group); | 663 | data, lm78_groups); |
680 | if (err) | 664 | return PTR_ERR_OR_ZERO(hwmon_dev); |
681 | return err; | ||
682 | |||
683 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
684 | if (IS_ERR(data->hwmon_dev)) { | ||
685 | err = PTR_ERR(data->hwmon_dev); | ||
686 | goto error; | ||
687 | } | ||
688 | |||
689 | return 0; | ||
690 | |||
691 | error: | ||
692 | sysfs_remove_group(&client->dev.kobj, &lm78_group); | ||
693 | return err; | ||
694 | } | ||
695 | |||
696 | static int lm78_i2c_remove(struct i2c_client *client) | ||
697 | { | ||
698 | struct lm78_data *data = i2c_get_clientdata(client); | ||
699 | |||
700 | hwmon_device_unregister(data->hwmon_dev); | ||
701 | sysfs_remove_group(&client->dev.kobj, &lm78_group); | ||
702 | |||
703 | return 0; | ||
704 | } | 665 | } |
705 | 666 | ||
706 | static const struct i2c_device_id lm78_i2c_id[] = { | 667 | static const struct i2c_device_id lm78_i2c_id[] = { |
@@ -716,7 +677,6 @@ static struct i2c_driver lm78_driver = { | |||
716 | .name = "lm78", | 677 | .name = "lm78", |
717 | }, | 678 | }, |
718 | .probe = lm78_i2c_probe, | 679 | .probe = lm78_i2c_probe, |
719 | .remove = lm78_i2c_remove, | ||
720 | .id_table = lm78_i2c_id, | 680 | .id_table = lm78_i2c_id, |
721 | .detect = lm78_i2c_detect, | 681 | .detect = lm78_i2c_detect, |
722 | .address_list = normal_i2c, | 682 | .address_list = normal_i2c, |
@@ -839,17 +799,18 @@ static struct lm78_data *lm78_update_device(struct device *dev) | |||
839 | #ifdef CONFIG_ISA | 799 | #ifdef CONFIG_ISA |
840 | static int lm78_isa_probe(struct platform_device *pdev) | 800 | static int lm78_isa_probe(struct platform_device *pdev) |
841 | { | 801 | { |
842 | int err; | 802 | struct device *dev = &pdev->dev; |
803 | struct device *hwmon_dev; | ||
843 | struct lm78_data *data; | 804 | struct lm78_data *data; |
844 | struct resource *res; | 805 | struct resource *res; |
845 | 806 | ||
846 | /* Reserve the ISA region */ | 807 | /* Reserve the ISA region */ |
847 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | 808 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
848 | if (!devm_request_region(&pdev->dev, res->start + LM78_ADDR_REG_OFFSET, | 809 | if (!devm_request_region(dev, res->start + LM78_ADDR_REG_OFFSET, |
849 | 2, "lm78")) | 810 | 2, "lm78")) |
850 | return -EBUSY; | 811 | return -EBUSY; |
851 | 812 | ||
852 | data = devm_kzalloc(&pdev->dev, sizeof(struct lm78_data), GFP_KERNEL); | 813 | data = devm_kzalloc(dev, sizeof(struct lm78_data), GFP_KERNEL); |
853 | if (!data) | 814 | if (!data) |
854 | return -ENOMEM; | 815 | return -ENOMEM; |
855 | 816 | ||
@@ -868,37 +829,9 @@ static int lm78_isa_probe(struct platform_device *pdev) | |||
868 | /* Initialize the LM78 chip */ | 829 | /* Initialize the LM78 chip */ |
869 | lm78_init_device(data); | 830 | lm78_init_device(data); |
870 | 831 | ||
871 | /* Register sysfs hooks */ | 832 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, data->name, |
872 | err = sysfs_create_group(&pdev->dev.kobj, &lm78_group); | 833 | data, lm78_groups); |
873 | if (err) | 834 | return PTR_ERR_OR_ZERO(hwmon_dev); |
874 | goto exit_remove_files; | ||
875 | err = device_create_file(&pdev->dev, &dev_attr_name); | ||
876 | if (err) | ||
877 | goto exit_remove_files; | ||
878 | |||
879 | data->hwmon_dev = hwmon_device_register(&pdev->dev); | ||
880 | if (IS_ERR(data->hwmon_dev)) { | ||
881 | err = PTR_ERR(data->hwmon_dev); | ||
882 | goto exit_remove_files; | ||
883 | } | ||
884 | |||
885 | return 0; | ||
886 | |||
887 | exit_remove_files: | ||
888 | sysfs_remove_group(&pdev->dev.kobj, &lm78_group); | ||
889 | device_remove_file(&pdev->dev, &dev_attr_name); | ||
890 | return err; | ||
891 | } | ||
892 | |||
893 | static int lm78_isa_remove(struct platform_device *pdev) | ||
894 | { | ||
895 | struct lm78_data *data = platform_get_drvdata(pdev); | ||
896 | |||
897 | hwmon_device_unregister(data->hwmon_dev); | ||
898 | sysfs_remove_group(&pdev->dev.kobj, &lm78_group); | ||
899 | device_remove_file(&pdev->dev, &dev_attr_name); | ||
900 | |||
901 | return 0; | ||
902 | } | 835 | } |
903 | 836 | ||
904 | static struct platform_driver lm78_isa_driver = { | 837 | static struct platform_driver lm78_isa_driver = { |
@@ -907,7 +840,6 @@ static struct platform_driver lm78_isa_driver = { | |||
907 | .name = "lm78", | 840 | .name = "lm78", |
908 | }, | 841 | }, |
909 | .probe = lm78_isa_probe, | 842 | .probe = lm78_isa_probe, |
910 | .remove = lm78_isa_remove, | ||
911 | }; | 843 | }; |
912 | 844 | ||
913 | /* return 1 if a supported chip is found, 0 otherwise */ | 845 | /* return 1 if a supported chip is found, 0 otherwise */ |
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c index b0129a54e1a6..2b4b419273fe 100644 --- a/drivers/hwmon/lm85.c +++ b/drivers/hwmon/lm85.c | |||
@@ -121,7 +121,6 @@ enum chips { | |||
121 | #define EMC6D102_REG_EXTEND_ADC3 0x87 | 121 | #define EMC6D102_REG_EXTEND_ADC3 0x87 |
122 | #define EMC6D102_REG_EXTEND_ADC4 0x88 | 122 | #define EMC6D102_REG_EXTEND_ADC4 0x88 |
123 | 123 | ||
124 | |||
125 | /* | 124 | /* |
126 | * Conversions. Rounding and limit checking is only done on the TO_REG | 125 | * Conversions. Rounding and limit checking is only done on the TO_REG |
127 | * variants. Note that you should be a bit careful with which arguments | 126 | * variants. Note that you should be a bit careful with which arguments |
@@ -155,7 +154,7 @@ static inline u16 FAN_TO_REG(unsigned long val) | |||
155 | 154 | ||
156 | /* Temperature is reported in .001 degC increments */ | 155 | /* Temperature is reported in .001 degC increments */ |
157 | #define TEMP_TO_REG(val) \ | 156 | #define TEMP_TO_REG(val) \ |
158 | clamp_val(SCALE(val, 1000, 1), -127, 127) | 157 | DIV_ROUND_CLOSEST(clamp_val((val), -127000, 127000), 1000) |
159 | #define TEMPEXT_FROM_REG(val, ext) \ | 158 | #define TEMPEXT_FROM_REG(val, ext) \ |
160 | SCALE(((val) << 4) + (ext), 16, 1000) | 159 | SCALE(((val) << 4) + (ext), 16, 1000) |
161 | #define TEMP_FROM_REG(val) ((val) * 1000) | 160 | #define TEMP_FROM_REG(val) ((val) * 1000) |
@@ -189,7 +188,7 @@ static const int lm85_range_map[] = { | |||
189 | 13300, 16000, 20000, 26600, 32000, 40000, 53300, 80000 | 188 | 13300, 16000, 20000, 26600, 32000, 40000, 53300, 80000 |
190 | }; | 189 | }; |
191 | 190 | ||
192 | static int RANGE_TO_REG(int range) | 191 | static int RANGE_TO_REG(long range) |
193 | { | 192 | { |
194 | int i; | 193 | int i; |
195 | 194 | ||
@@ -211,7 +210,7 @@ static const int adm1027_freq_map[8] = { /* 1 Hz */ | |||
211 | 11, 15, 22, 29, 35, 44, 59, 88 | 210 | 11, 15, 22, 29, 35, 44, 59, 88 |
212 | }; | 211 | }; |
213 | 212 | ||
214 | static int FREQ_TO_REG(const int *map, int freq) | 213 | static int FREQ_TO_REG(const int *map, unsigned long freq) |
215 | { | 214 | { |
216 | int i; | 215 | int i; |
217 | 216 | ||
@@ -303,7 +302,8 @@ struct lm85_autofan { | |||
303 | * The structure is dynamically allocated. | 302 | * The structure is dynamically allocated. |
304 | */ | 303 | */ |
305 | struct lm85_data { | 304 | struct lm85_data { |
306 | struct device *hwmon_dev; | 305 | struct i2c_client *client; |
306 | const struct attribute_group *groups[6]; | ||
307 | const int *freq_map; | 307 | const int *freq_map; |
308 | enum chips type; | 308 | enum chips type; |
309 | 309 | ||
@@ -334,44 +334,235 @@ struct lm85_data { | |||
334 | struct lm85_zone zone[3]; | 334 | struct lm85_zone zone[3]; |
335 | }; | 335 | }; |
336 | 336 | ||
337 | static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info); | 337 | static int lm85_read_value(struct i2c_client *client, u8 reg) |
338 | static int lm85_probe(struct i2c_client *client, | 338 | { |
339 | const struct i2c_device_id *id); | 339 | int res; |
340 | static int lm85_remove(struct i2c_client *client); | ||
341 | 340 | ||
342 | static int lm85_read_value(struct i2c_client *client, u8 reg); | 341 | /* What size location is it? */ |
343 | static void lm85_write_value(struct i2c_client *client, u8 reg, int value); | 342 | switch (reg) { |
344 | static struct lm85_data *lm85_update_device(struct device *dev); | 343 | case LM85_REG_FAN(0): /* Read WORD data */ |
344 | case LM85_REG_FAN(1): | ||
345 | case LM85_REG_FAN(2): | ||
346 | case LM85_REG_FAN(3): | ||
347 | case LM85_REG_FAN_MIN(0): | ||
348 | case LM85_REG_FAN_MIN(1): | ||
349 | case LM85_REG_FAN_MIN(2): | ||
350 | case LM85_REG_FAN_MIN(3): | ||
351 | case LM85_REG_ALARM1: /* Read both bytes at once */ | ||
352 | res = i2c_smbus_read_byte_data(client, reg) & 0xff; | ||
353 | res |= i2c_smbus_read_byte_data(client, reg + 1) << 8; | ||
354 | break; | ||
355 | default: /* Read BYTE data */ | ||
356 | res = i2c_smbus_read_byte_data(client, reg); | ||
357 | break; | ||
358 | } | ||
345 | 359 | ||
360 | return res; | ||
361 | } | ||
346 | 362 | ||
347 | static const struct i2c_device_id lm85_id[] = { | 363 | static void lm85_write_value(struct i2c_client *client, u8 reg, int value) |
348 | { "adm1027", adm1027 }, | 364 | { |
349 | { "adt7463", adt7463 }, | 365 | switch (reg) { |
350 | { "adt7468", adt7468 }, | 366 | case LM85_REG_FAN(0): /* Write WORD data */ |
351 | { "lm85", lm85 }, | 367 | case LM85_REG_FAN(1): |
352 | { "lm85b", lm85 }, | 368 | case LM85_REG_FAN(2): |
353 | { "lm85c", lm85 }, | 369 | case LM85_REG_FAN(3): |
354 | { "emc6d100", emc6d100 }, | 370 | case LM85_REG_FAN_MIN(0): |
355 | { "emc6d101", emc6d100 }, | 371 | case LM85_REG_FAN_MIN(1): |
356 | { "emc6d102", emc6d102 }, | 372 | case LM85_REG_FAN_MIN(2): |
357 | { "emc6d103", emc6d103 }, | 373 | case LM85_REG_FAN_MIN(3): |
358 | { "emc6d103s", emc6d103s }, | 374 | /* NOTE: ALARM is read only, so not included here */ |
359 | { } | 375 | i2c_smbus_write_byte_data(client, reg, value & 0xff); |
360 | }; | 376 | i2c_smbus_write_byte_data(client, reg + 1, value >> 8); |
361 | MODULE_DEVICE_TABLE(i2c, lm85_id); | 377 | break; |
378 | default: /* Write BYTE data */ | ||
379 | i2c_smbus_write_byte_data(client, reg, value); | ||
380 | break; | ||
381 | } | ||
382 | } | ||
362 | 383 | ||
363 | static struct i2c_driver lm85_driver = { | 384 | static struct lm85_data *lm85_update_device(struct device *dev) |
364 | .class = I2C_CLASS_HWMON, | 385 | { |
365 | .driver = { | 386 | struct lm85_data *data = dev_get_drvdata(dev); |
366 | .name = "lm85", | 387 | struct i2c_client *client = data->client; |
367 | }, | 388 | int i; |
368 | .probe = lm85_probe, | 389 | |
369 | .remove = lm85_remove, | 390 | mutex_lock(&data->update_lock); |
370 | .id_table = lm85_id, | 391 | |
371 | .detect = lm85_detect, | 392 | if (!data->valid || |
372 | .address_list = normal_i2c, | 393 | time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL)) { |
373 | }; | 394 | /* Things that change quickly */ |
395 | dev_dbg(&client->dev, "Reading sensor values\n"); | ||
396 | |||
397 | /* | ||
398 | * Have to read extended bits first to "freeze" the | ||
399 | * more significant bits that are read later. | ||
400 | * There are 2 additional resolution bits per channel and we | ||
401 | * have room for 4, so we shift them to the left. | ||
402 | */ | ||
403 | if (data->type == adm1027 || data->type == adt7463 || | ||
404 | data->type == adt7468) { | ||
405 | int ext1 = lm85_read_value(client, | ||
406 | ADM1027_REG_EXTEND_ADC1); | ||
407 | int ext2 = lm85_read_value(client, | ||
408 | ADM1027_REG_EXTEND_ADC2); | ||
409 | int val = (ext1 << 8) + ext2; | ||
410 | |||
411 | for (i = 0; i <= 4; i++) | ||
412 | data->in_ext[i] = | ||
413 | ((val >> (i * 2)) & 0x03) << 2; | ||
414 | |||
415 | for (i = 0; i <= 2; i++) | ||
416 | data->temp_ext[i] = | ||
417 | (val >> ((i + 4) * 2)) & 0x0c; | ||
418 | } | ||
419 | |||
420 | data->vid = lm85_read_value(client, LM85_REG_VID); | ||
421 | |||
422 | for (i = 0; i <= 3; ++i) { | ||
423 | data->in[i] = | ||
424 | lm85_read_value(client, LM85_REG_IN(i)); | ||
425 | data->fan[i] = | ||
426 | lm85_read_value(client, LM85_REG_FAN(i)); | ||
427 | } | ||
428 | |||
429 | if (!data->has_vid5) | ||
430 | data->in[4] = lm85_read_value(client, LM85_REG_IN(4)); | ||
431 | |||
432 | if (data->type == adt7468) | ||
433 | data->cfg5 = lm85_read_value(client, ADT7468_REG_CFG5); | ||
374 | 434 | ||
435 | for (i = 0; i <= 2; ++i) { | ||
436 | data->temp[i] = | ||
437 | lm85_read_value(client, LM85_REG_TEMP(i)); | ||
438 | data->pwm[i] = | ||
439 | lm85_read_value(client, LM85_REG_PWM(i)); | ||
440 | |||
441 | if (IS_ADT7468_OFF64(data)) | ||
442 | data->temp[i] -= 64; | ||
443 | } | ||
444 | |||
445 | data->alarms = lm85_read_value(client, LM85_REG_ALARM1); | ||
446 | |||
447 | if (data->type == emc6d100) { | ||
448 | /* Three more voltage sensors */ | ||
449 | for (i = 5; i <= 7; ++i) { | ||
450 | data->in[i] = lm85_read_value(client, | ||
451 | EMC6D100_REG_IN(i)); | ||
452 | } | ||
453 | /* More alarm bits */ | ||
454 | data->alarms |= lm85_read_value(client, | ||
455 | EMC6D100_REG_ALARM3) << 16; | ||
456 | } else if (data->type == emc6d102 || data->type == emc6d103 || | ||
457 | data->type == emc6d103s) { | ||
458 | /* | ||
459 | * Have to read LSB bits after the MSB ones because | ||
460 | * the reading of the MSB bits has frozen the | ||
461 | * LSBs (backward from the ADM1027). | ||
462 | */ | ||
463 | int ext1 = lm85_read_value(client, | ||
464 | EMC6D102_REG_EXTEND_ADC1); | ||
465 | int ext2 = lm85_read_value(client, | ||
466 | EMC6D102_REG_EXTEND_ADC2); | ||
467 | int ext3 = lm85_read_value(client, | ||
468 | EMC6D102_REG_EXTEND_ADC3); | ||
469 | int ext4 = lm85_read_value(client, | ||
470 | EMC6D102_REG_EXTEND_ADC4); | ||
471 | data->in_ext[0] = ext3 & 0x0f; | ||
472 | data->in_ext[1] = ext4 & 0x0f; | ||
473 | data->in_ext[2] = ext4 >> 4; | ||
474 | data->in_ext[3] = ext3 >> 4; | ||
475 | data->in_ext[4] = ext2 >> 4; | ||
476 | |||
477 | data->temp_ext[0] = ext1 & 0x0f; | ||
478 | data->temp_ext[1] = ext2 & 0x0f; | ||
479 | data->temp_ext[2] = ext1 >> 4; | ||
480 | } | ||
481 | |||
482 | data->last_reading = jiffies; | ||
483 | } /* last_reading */ | ||
484 | |||
485 | if (!data->valid || | ||
486 | time_after(jiffies, data->last_config + LM85_CONFIG_INTERVAL)) { | ||
487 | /* Things that don't change often */ | ||
488 | dev_dbg(&client->dev, "Reading config values\n"); | ||
489 | |||
490 | for (i = 0; i <= 3; ++i) { | ||
491 | data->in_min[i] = | ||
492 | lm85_read_value(client, LM85_REG_IN_MIN(i)); | ||
493 | data->in_max[i] = | ||
494 | lm85_read_value(client, LM85_REG_IN_MAX(i)); | ||
495 | data->fan_min[i] = | ||
496 | lm85_read_value(client, LM85_REG_FAN_MIN(i)); | ||
497 | } | ||
498 | |||
499 | if (!data->has_vid5) { | ||
500 | data->in_min[4] = lm85_read_value(client, | ||
501 | LM85_REG_IN_MIN(4)); | ||
502 | data->in_max[4] = lm85_read_value(client, | ||
503 | LM85_REG_IN_MAX(4)); | ||
504 | } | ||
505 | |||
506 | if (data->type == emc6d100) { | ||
507 | for (i = 5; i <= 7; ++i) { | ||
508 | data->in_min[i] = lm85_read_value(client, | ||
509 | EMC6D100_REG_IN_MIN(i)); | ||
510 | data->in_max[i] = lm85_read_value(client, | ||
511 | EMC6D100_REG_IN_MAX(i)); | ||
512 | } | ||
513 | } | ||
514 | |||
515 | for (i = 0; i <= 2; ++i) { | ||
516 | int val; | ||
517 | |||
518 | data->temp_min[i] = | ||
519 | lm85_read_value(client, LM85_REG_TEMP_MIN(i)); | ||
520 | data->temp_max[i] = | ||
521 | lm85_read_value(client, LM85_REG_TEMP_MAX(i)); | ||
522 | |||
523 | data->autofan[i].config = | ||
524 | lm85_read_value(client, LM85_REG_AFAN_CONFIG(i)); | ||
525 | val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i)); | ||
526 | data->pwm_freq[i] = val & 0x07; | ||
527 | data->zone[i].range = val >> 4; | ||
528 | data->autofan[i].min_pwm = | ||
529 | lm85_read_value(client, LM85_REG_AFAN_MINPWM(i)); | ||
530 | data->zone[i].limit = | ||
531 | lm85_read_value(client, LM85_REG_AFAN_LIMIT(i)); | ||
532 | data->zone[i].critical = | ||
533 | lm85_read_value(client, LM85_REG_AFAN_CRITICAL(i)); | ||
534 | |||
535 | if (IS_ADT7468_OFF64(data)) { | ||
536 | data->temp_min[i] -= 64; | ||
537 | data->temp_max[i] -= 64; | ||
538 | data->zone[i].limit -= 64; | ||
539 | data->zone[i].critical -= 64; | ||
540 | } | ||
541 | } | ||
542 | |||
543 | if (data->type != emc6d103s) { | ||
544 | i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1); | ||
545 | data->autofan[0].min_off = (i & 0x20) != 0; | ||
546 | data->autofan[1].min_off = (i & 0x40) != 0; | ||
547 | data->autofan[2].min_off = (i & 0x80) != 0; | ||
548 | |||
549 | i = lm85_read_value(client, LM85_REG_AFAN_HYST1); | ||
550 | data->zone[0].hyst = i >> 4; | ||
551 | data->zone[1].hyst = i & 0x0f; | ||
552 | |||
553 | i = lm85_read_value(client, LM85_REG_AFAN_HYST2); | ||
554 | data->zone[2].hyst = i >> 4; | ||
555 | } | ||
556 | |||
557 | data->last_config = jiffies; | ||
558 | } /* last_config */ | ||
559 | |||
560 | data->valid = 1; | ||
561 | |||
562 | mutex_unlock(&data->update_lock); | ||
563 | |||
564 | return data; | ||
565 | } | ||
375 | 566 | ||
376 | /* 4 Fans */ | 567 | /* 4 Fans */ |
377 | static ssize_t show_fan(struct device *dev, struct device_attribute *attr, | 568 | static ssize_t show_fan(struct device *dev, struct device_attribute *attr, |
@@ -394,8 +585,8 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | |||
394 | const char *buf, size_t count) | 585 | const char *buf, size_t count) |
395 | { | 586 | { |
396 | int nr = to_sensor_dev_attr(attr)->index; | 587 | int nr = to_sensor_dev_attr(attr)->index; |
397 | struct i2c_client *client = to_i2c_client(dev); | 588 | struct lm85_data *data = dev_get_drvdata(dev); |
398 | struct lm85_data *data = i2c_get_clientdata(client); | 589 | struct i2c_client *client = data->client; |
399 | unsigned long val; | 590 | unsigned long val; |
400 | int err; | 591 | int err; |
401 | 592 | ||
@@ -460,6 +651,9 @@ static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, | |||
460 | if (err) | 651 | if (err) |
461 | return err; | 652 | return err; |
462 | 653 | ||
654 | if (val > 255) | ||
655 | return -EINVAL; | ||
656 | |||
463 | data->vrm = val; | 657 | data->vrm = val; |
464 | return count; | 658 | return count; |
465 | } | 659 | } |
@@ -515,8 +709,8 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
515 | const char *buf, size_t count) | 709 | const char *buf, size_t count) |
516 | { | 710 | { |
517 | int nr = to_sensor_dev_attr(attr)->index; | 711 | int nr = to_sensor_dev_attr(attr)->index; |
518 | struct i2c_client *client = to_i2c_client(dev); | 712 | struct lm85_data *data = dev_get_drvdata(dev); |
519 | struct lm85_data *data = i2c_get_clientdata(client); | 713 | struct i2c_client *client = data->client; |
520 | unsigned long val; | 714 | unsigned long val; |
521 | int err; | 715 | int err; |
522 | 716 | ||
@@ -557,8 +751,8 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute | |||
557 | *attr, const char *buf, size_t count) | 751 | *attr, const char *buf, size_t count) |
558 | { | 752 | { |
559 | int nr = to_sensor_dev_attr(attr)->index; | 753 | int nr = to_sensor_dev_attr(attr)->index; |
560 | struct i2c_client *client = to_i2c_client(dev); | 754 | struct lm85_data *data = dev_get_drvdata(dev); |
561 | struct lm85_data *data = i2c_get_clientdata(client); | 755 | struct i2c_client *client = data->client; |
562 | u8 config; | 756 | u8 config; |
563 | unsigned long val; | 757 | unsigned long val; |
564 | int err; | 758 | int err; |
@@ -615,8 +809,8 @@ static ssize_t set_pwm_freq(struct device *dev, | |||
615 | struct device_attribute *attr, const char *buf, size_t count) | 809 | struct device_attribute *attr, const char *buf, size_t count) |
616 | { | 810 | { |
617 | int nr = to_sensor_dev_attr(attr)->index; | 811 | int nr = to_sensor_dev_attr(attr)->index; |
618 | struct i2c_client *client = to_i2c_client(dev); | 812 | struct lm85_data *data = dev_get_drvdata(dev); |
619 | struct lm85_data *data = i2c_get_clientdata(client); | 813 | struct i2c_client *client = data->client; |
620 | unsigned long val; | 814 | unsigned long val; |
621 | int err; | 815 | int err; |
622 | 816 | ||
@@ -682,8 +876,8 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | |||
682 | const char *buf, size_t count) | 876 | const char *buf, size_t count) |
683 | { | 877 | { |
684 | int nr = to_sensor_dev_attr(attr)->index; | 878 | int nr = to_sensor_dev_attr(attr)->index; |
685 | struct i2c_client *client = to_i2c_client(dev); | 879 | struct lm85_data *data = dev_get_drvdata(dev); |
686 | struct lm85_data *data = i2c_get_clientdata(client); | 880 | struct i2c_client *client = data->client; |
687 | long val; | 881 | long val; |
688 | int err; | 882 | int err; |
689 | 883 | ||
@@ -710,8 +904,8 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, | |||
710 | const char *buf, size_t count) | 904 | const char *buf, size_t count) |
711 | { | 905 | { |
712 | int nr = to_sensor_dev_attr(attr)->index; | 906 | int nr = to_sensor_dev_attr(attr)->index; |
713 | struct i2c_client *client = to_i2c_client(dev); | 907 | struct lm85_data *data = dev_get_drvdata(dev); |
714 | struct lm85_data *data = i2c_get_clientdata(client); | 908 | struct i2c_client *client = data->client; |
715 | long val; | 909 | long val; |
716 | int err; | 910 | int err; |
717 | 911 | ||
@@ -766,8 +960,8 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | |||
766 | const char *buf, size_t count) | 960 | const char *buf, size_t count) |
767 | { | 961 | { |
768 | int nr = to_sensor_dev_attr(attr)->index; | 962 | int nr = to_sensor_dev_attr(attr)->index; |
769 | struct i2c_client *client = to_i2c_client(dev); | 963 | struct lm85_data *data = dev_get_drvdata(dev); |
770 | struct lm85_data *data = i2c_get_clientdata(client); | 964 | struct i2c_client *client = data->client; |
771 | long val; | 965 | long val; |
772 | int err; | 966 | int err; |
773 | 967 | ||
@@ -797,8 +991,8 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
797 | const char *buf, size_t count) | 991 | const char *buf, size_t count) |
798 | { | 992 | { |
799 | int nr = to_sensor_dev_attr(attr)->index; | 993 | int nr = to_sensor_dev_attr(attr)->index; |
800 | struct i2c_client *client = to_i2c_client(dev); | 994 | struct lm85_data *data = dev_get_drvdata(dev); |
801 | struct lm85_data *data = i2c_get_clientdata(client); | 995 | struct i2c_client *client = data->client; |
802 | long val; | 996 | long val; |
803 | int err; | 997 | int err; |
804 | 998 | ||
@@ -843,8 +1037,8 @@ static ssize_t set_pwm_auto_channels(struct device *dev, | |||
843 | struct device_attribute *attr, const char *buf, size_t count) | 1037 | struct device_attribute *attr, const char *buf, size_t count) |
844 | { | 1038 | { |
845 | int nr = to_sensor_dev_attr(attr)->index; | 1039 | int nr = to_sensor_dev_attr(attr)->index; |
846 | struct i2c_client *client = to_i2c_client(dev); | 1040 | struct lm85_data *data = dev_get_drvdata(dev); |
847 | struct lm85_data *data = i2c_get_clientdata(client); | 1041 | struct i2c_client *client = data->client; |
848 | long val; | 1042 | long val; |
849 | int err; | 1043 | int err; |
850 | 1044 | ||
@@ -873,8 +1067,8 @@ static ssize_t set_pwm_auto_pwm_min(struct device *dev, | |||
873 | struct device_attribute *attr, const char *buf, size_t count) | 1067 | struct device_attribute *attr, const char *buf, size_t count) |
874 | { | 1068 | { |
875 | int nr = to_sensor_dev_attr(attr)->index; | 1069 | int nr = to_sensor_dev_attr(attr)->index; |
876 | struct i2c_client *client = to_i2c_client(dev); | 1070 | struct lm85_data *data = dev_get_drvdata(dev); |
877 | struct lm85_data *data = i2c_get_clientdata(client); | 1071 | struct i2c_client *client = data->client; |
878 | unsigned long val; | 1072 | unsigned long val; |
879 | int err; | 1073 | int err; |
880 | 1074 | ||
@@ -902,8 +1096,8 @@ static ssize_t set_pwm_auto_pwm_minctl(struct device *dev, | |||
902 | struct device_attribute *attr, const char *buf, size_t count) | 1096 | struct device_attribute *attr, const char *buf, size_t count) |
903 | { | 1097 | { |
904 | int nr = to_sensor_dev_attr(attr)->index; | 1098 | int nr = to_sensor_dev_attr(attr)->index; |
905 | struct i2c_client *client = to_i2c_client(dev); | 1099 | struct lm85_data *data = dev_get_drvdata(dev); |
906 | struct lm85_data *data = i2c_get_clientdata(client); | 1100 | struct i2c_client *client = data->client; |
907 | u8 tmp; | 1101 | u8 tmp; |
908 | long val; | 1102 | long val; |
909 | int err; | 1103 | int err; |
@@ -953,8 +1147,8 @@ static ssize_t set_temp_auto_temp_off(struct device *dev, | |||
953 | struct device_attribute *attr, const char *buf, size_t count) | 1147 | struct device_attribute *attr, const char *buf, size_t count) |
954 | { | 1148 | { |
955 | int nr = to_sensor_dev_attr(attr)->index; | 1149 | int nr = to_sensor_dev_attr(attr)->index; |
956 | struct i2c_client *client = to_i2c_client(dev); | 1150 | struct lm85_data *data = dev_get_drvdata(dev); |
957 | struct lm85_data *data = i2c_get_clientdata(client); | 1151 | struct i2c_client *client = data->client; |
958 | int min; | 1152 | int min; |
959 | long val; | 1153 | long val; |
960 | int err; | 1154 | int err; |
@@ -990,8 +1184,8 @@ static ssize_t set_temp_auto_temp_min(struct device *dev, | |||
990 | struct device_attribute *attr, const char *buf, size_t count) | 1184 | struct device_attribute *attr, const char *buf, size_t count) |
991 | { | 1185 | { |
992 | int nr = to_sensor_dev_attr(attr)->index; | 1186 | int nr = to_sensor_dev_attr(attr)->index; |
993 | struct i2c_client *client = to_i2c_client(dev); | 1187 | struct lm85_data *data = dev_get_drvdata(dev); |
994 | struct lm85_data *data = i2c_get_clientdata(client); | 1188 | struct i2c_client *client = data->client; |
995 | long val; | 1189 | long val; |
996 | int err; | 1190 | int err; |
997 | 1191 | ||
@@ -1029,8 +1223,8 @@ static ssize_t set_temp_auto_temp_max(struct device *dev, | |||
1029 | struct device_attribute *attr, const char *buf, size_t count) | 1223 | struct device_attribute *attr, const char *buf, size_t count) |
1030 | { | 1224 | { |
1031 | int nr = to_sensor_dev_attr(attr)->index; | 1225 | int nr = to_sensor_dev_attr(attr)->index; |
1032 | struct i2c_client *client = to_i2c_client(dev); | 1226 | struct lm85_data *data = dev_get_drvdata(dev); |
1033 | struct lm85_data *data = i2c_get_clientdata(client); | 1227 | struct i2c_client *client = data->client; |
1034 | int min; | 1228 | int min; |
1035 | long val; | 1229 | long val; |
1036 | int err; | 1230 | int err; |
@@ -1063,8 +1257,8 @@ static ssize_t set_temp_auto_temp_crit(struct device *dev, | |||
1063 | struct device_attribute *attr, const char *buf, size_t count) | 1257 | struct device_attribute *attr, const char *buf, size_t count) |
1064 | { | 1258 | { |
1065 | int nr = to_sensor_dev_attr(attr)->index; | 1259 | int nr = to_sensor_dev_attr(attr)->index; |
1066 | struct i2c_client *client = to_i2c_client(dev); | 1260 | struct lm85_data *data = dev_get_drvdata(dev); |
1067 | struct lm85_data *data = i2c_get_clientdata(client); | 1261 | struct i2c_client *client = data->client; |
1068 | long val; | 1262 | long val; |
1069 | int err; | 1263 | int err; |
1070 | 1264 | ||
@@ -1355,30 +1549,18 @@ static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info) | |||
1355 | return 0; | 1549 | return 0; |
1356 | } | 1550 | } |
1357 | 1551 | ||
1358 | static void lm85_remove_files(struct i2c_client *client, struct lm85_data *data) | 1552 | static int lm85_probe(struct i2c_client *client, const struct i2c_device_id *id) |
1359 | { | ||
1360 | sysfs_remove_group(&client->dev.kobj, &lm85_group); | ||
1361 | if (data->type != emc6d103s) { | ||
1362 | sysfs_remove_group(&client->dev.kobj, &lm85_group_minctl); | ||
1363 | sysfs_remove_group(&client->dev.kobj, &lm85_group_temp_off); | ||
1364 | } | ||
1365 | if (!data->has_vid5) | ||
1366 | sysfs_remove_group(&client->dev.kobj, &lm85_group_in4); | ||
1367 | if (data->type == emc6d100) | ||
1368 | sysfs_remove_group(&client->dev.kobj, &lm85_group_in567); | ||
1369 | } | ||
1370 | |||
1371 | static int lm85_probe(struct i2c_client *client, | ||
1372 | const struct i2c_device_id *id) | ||
1373 | { | 1553 | { |
1554 | struct device *dev = &client->dev; | ||
1555 | struct device *hwmon_dev; | ||
1374 | struct lm85_data *data; | 1556 | struct lm85_data *data; |
1375 | int err; | 1557 | int idx = 0; |
1376 | 1558 | ||
1377 | data = devm_kzalloc(&client->dev, sizeof(struct lm85_data), GFP_KERNEL); | 1559 | data = devm_kzalloc(dev, sizeof(struct lm85_data), GFP_KERNEL); |
1378 | if (!data) | 1560 | if (!data) |
1379 | return -ENOMEM; | 1561 | return -ENOMEM; |
1380 | 1562 | ||
1381 | i2c_set_clientdata(client, data); | 1563 | data->client = client; |
1382 | data->type = id->driver_data; | 1564 | data->type = id->driver_data; |
1383 | mutex_init(&data->update_lock); | 1565 | mutex_init(&data->update_lock); |
1384 | 1566 | ||
@@ -1403,20 +1585,13 @@ static int lm85_probe(struct i2c_client *client, | |||
1403 | /* Initialize the LM85 chip */ | 1585 | /* Initialize the LM85 chip */ |
1404 | lm85_init_client(client); | 1586 | lm85_init_client(client); |
1405 | 1587 | ||
1406 | /* Register sysfs hooks */ | 1588 | /* sysfs hooks */ |
1407 | err = sysfs_create_group(&client->dev.kobj, &lm85_group); | 1589 | data->groups[idx++] = &lm85_group; |
1408 | if (err) | ||
1409 | return err; | ||
1410 | 1590 | ||
1411 | /* minctl and temp_off exist on all chips except emc6d103s */ | 1591 | /* minctl and temp_off exist on all chips except emc6d103s */ |
1412 | if (data->type != emc6d103s) { | 1592 | if (data->type != emc6d103s) { |
1413 | err = sysfs_create_group(&client->dev.kobj, &lm85_group_minctl); | 1593 | data->groups[idx++] = &lm85_group_minctl; |
1414 | if (err) | 1594 | data->groups[idx++] = &lm85_group_temp_off; |
1415 | goto err_remove_files; | ||
1416 | err = sysfs_create_group(&client->dev.kobj, | ||
1417 | &lm85_group_temp_off); | ||
1418 | if (err) | ||
1419 | goto err_remove_files; | ||
1420 | } | 1595 | } |
1421 | 1596 | ||
1422 | /* | 1597 | /* |
@@ -1429,271 +1604,44 @@ static int lm85_probe(struct i2c_client *client, | |||
1429 | data->has_vid5 = true; | 1604 | data->has_vid5 = true; |
1430 | } | 1605 | } |
1431 | 1606 | ||
1432 | if (!data->has_vid5) { | 1607 | if (!data->has_vid5) |
1433 | err = sysfs_create_group(&client->dev.kobj, &lm85_group_in4); | 1608 | data->groups[idx++] = &lm85_group_in4; |
1434 | if (err) | ||
1435 | goto err_remove_files; | ||
1436 | } | ||
1437 | 1609 | ||
1438 | /* The EMC6D100 has 3 additional voltage inputs */ | 1610 | /* The EMC6D100 has 3 additional voltage inputs */ |
1439 | if (data->type == emc6d100) { | 1611 | if (data->type == emc6d100) |
1440 | err = sysfs_create_group(&client->dev.kobj, &lm85_group_in567); | 1612 | data->groups[idx++] = &lm85_group_in567; |
1441 | if (err) | ||
1442 | goto err_remove_files; | ||
1443 | } | ||
1444 | |||
1445 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
1446 | if (IS_ERR(data->hwmon_dev)) { | ||
1447 | err = PTR_ERR(data->hwmon_dev); | ||
1448 | goto err_remove_files; | ||
1449 | } | ||
1450 | |||
1451 | return 0; | ||
1452 | |||
1453 | /* Error out and cleanup code */ | ||
1454 | err_remove_files: | ||
1455 | lm85_remove_files(client, data); | ||
1456 | return err; | ||
1457 | } | ||
1458 | |||
1459 | static int lm85_remove(struct i2c_client *client) | ||
1460 | { | ||
1461 | struct lm85_data *data = i2c_get_clientdata(client); | ||
1462 | hwmon_device_unregister(data->hwmon_dev); | ||
1463 | lm85_remove_files(client, data); | ||
1464 | return 0; | ||
1465 | } | ||
1466 | |||
1467 | |||
1468 | static int lm85_read_value(struct i2c_client *client, u8 reg) | ||
1469 | { | ||
1470 | int res; | ||
1471 | |||
1472 | /* What size location is it? */ | ||
1473 | switch (reg) { | ||
1474 | case LM85_REG_FAN(0): /* Read WORD data */ | ||
1475 | case LM85_REG_FAN(1): | ||
1476 | case LM85_REG_FAN(2): | ||
1477 | case LM85_REG_FAN(3): | ||
1478 | case LM85_REG_FAN_MIN(0): | ||
1479 | case LM85_REG_FAN_MIN(1): | ||
1480 | case LM85_REG_FAN_MIN(2): | ||
1481 | case LM85_REG_FAN_MIN(3): | ||
1482 | case LM85_REG_ALARM1: /* Read both bytes at once */ | ||
1483 | res = i2c_smbus_read_byte_data(client, reg) & 0xff; | ||
1484 | res |= i2c_smbus_read_byte_data(client, reg + 1) << 8; | ||
1485 | break; | ||
1486 | default: /* Read BYTE data */ | ||
1487 | res = i2c_smbus_read_byte_data(client, reg); | ||
1488 | break; | ||
1489 | } | ||
1490 | |||
1491 | return res; | ||
1492 | } | ||
1493 | 1613 | ||
1494 | static void lm85_write_value(struct i2c_client *client, u8 reg, int value) | 1614 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
1495 | { | 1615 | data, data->groups); |
1496 | switch (reg) { | 1616 | return PTR_ERR_OR_ZERO(hwmon_dev); |
1497 | case LM85_REG_FAN(0): /* Write WORD data */ | ||
1498 | case LM85_REG_FAN(1): | ||
1499 | case LM85_REG_FAN(2): | ||
1500 | case LM85_REG_FAN(3): | ||
1501 | case LM85_REG_FAN_MIN(0): | ||
1502 | case LM85_REG_FAN_MIN(1): | ||
1503 | case LM85_REG_FAN_MIN(2): | ||
1504 | case LM85_REG_FAN_MIN(3): | ||
1505 | /* NOTE: ALARM is read only, so not included here */ | ||
1506 | i2c_smbus_write_byte_data(client, reg, value & 0xff); | ||
1507 | i2c_smbus_write_byte_data(client, reg + 1, value >> 8); | ||
1508 | break; | ||
1509 | default: /* Write BYTE data */ | ||
1510 | i2c_smbus_write_byte_data(client, reg, value); | ||
1511 | break; | ||
1512 | } | ||
1513 | } | 1617 | } |
1514 | 1618 | ||
1515 | static struct lm85_data *lm85_update_device(struct device *dev) | 1619 | static const struct i2c_device_id lm85_id[] = { |
1516 | { | 1620 | { "adm1027", adm1027 }, |
1517 | struct i2c_client *client = to_i2c_client(dev); | 1621 | { "adt7463", adt7463 }, |
1518 | struct lm85_data *data = i2c_get_clientdata(client); | 1622 | { "adt7468", adt7468 }, |
1519 | int i; | 1623 | { "lm85", lm85 }, |
1520 | 1624 | { "lm85b", lm85 }, | |
1521 | mutex_lock(&data->update_lock); | 1625 | { "lm85c", lm85 }, |
1522 | 1626 | { "emc6d100", emc6d100 }, | |
1523 | if (!data->valid || | 1627 | { "emc6d101", emc6d100 }, |
1524 | time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL)) { | 1628 | { "emc6d102", emc6d102 }, |
1525 | /* Things that change quickly */ | 1629 | { "emc6d103", emc6d103 }, |
1526 | dev_dbg(&client->dev, "Reading sensor values\n"); | 1630 | { "emc6d103s", emc6d103s }, |
1527 | 1631 | { } | |
1528 | /* | 1632 | }; |
1529 | * Have to read extended bits first to "freeze" the | 1633 | MODULE_DEVICE_TABLE(i2c, lm85_id); |
1530 | * more significant bits that are read later. | ||
1531 | * There are 2 additional resolution bits per channel and we | ||
1532 | * have room for 4, so we shift them to the left. | ||
1533 | */ | ||
1534 | if (data->type == adm1027 || data->type == adt7463 || | ||
1535 | data->type == adt7468) { | ||
1536 | int ext1 = lm85_read_value(client, | ||
1537 | ADM1027_REG_EXTEND_ADC1); | ||
1538 | int ext2 = lm85_read_value(client, | ||
1539 | ADM1027_REG_EXTEND_ADC2); | ||
1540 | int val = (ext1 << 8) + ext2; | ||
1541 | |||
1542 | for (i = 0; i <= 4; i++) | ||
1543 | data->in_ext[i] = | ||
1544 | ((val >> (i * 2)) & 0x03) << 2; | ||
1545 | |||
1546 | for (i = 0; i <= 2; i++) | ||
1547 | data->temp_ext[i] = | ||
1548 | (val >> ((i + 4) * 2)) & 0x0c; | ||
1549 | } | ||
1550 | |||
1551 | data->vid = lm85_read_value(client, LM85_REG_VID); | ||
1552 | |||
1553 | for (i = 0; i <= 3; ++i) { | ||
1554 | data->in[i] = | ||
1555 | lm85_read_value(client, LM85_REG_IN(i)); | ||
1556 | data->fan[i] = | ||
1557 | lm85_read_value(client, LM85_REG_FAN(i)); | ||
1558 | } | ||
1559 | |||
1560 | if (!data->has_vid5) | ||
1561 | data->in[4] = lm85_read_value(client, LM85_REG_IN(4)); | ||
1562 | |||
1563 | if (data->type == adt7468) | ||
1564 | data->cfg5 = lm85_read_value(client, ADT7468_REG_CFG5); | ||
1565 | |||
1566 | for (i = 0; i <= 2; ++i) { | ||
1567 | data->temp[i] = | ||
1568 | lm85_read_value(client, LM85_REG_TEMP(i)); | ||
1569 | data->pwm[i] = | ||
1570 | lm85_read_value(client, LM85_REG_PWM(i)); | ||
1571 | |||
1572 | if (IS_ADT7468_OFF64(data)) | ||
1573 | data->temp[i] -= 64; | ||
1574 | } | ||
1575 | |||
1576 | data->alarms = lm85_read_value(client, LM85_REG_ALARM1); | ||
1577 | |||
1578 | if (data->type == emc6d100) { | ||
1579 | /* Three more voltage sensors */ | ||
1580 | for (i = 5; i <= 7; ++i) { | ||
1581 | data->in[i] = lm85_read_value(client, | ||
1582 | EMC6D100_REG_IN(i)); | ||
1583 | } | ||
1584 | /* More alarm bits */ | ||
1585 | data->alarms |= lm85_read_value(client, | ||
1586 | EMC6D100_REG_ALARM3) << 16; | ||
1587 | } else if (data->type == emc6d102 || data->type == emc6d103 || | ||
1588 | data->type == emc6d103s) { | ||
1589 | /* | ||
1590 | * Have to read LSB bits after the MSB ones because | ||
1591 | * the reading of the MSB bits has frozen the | ||
1592 | * LSBs (backward from the ADM1027). | ||
1593 | */ | ||
1594 | int ext1 = lm85_read_value(client, | ||
1595 | EMC6D102_REG_EXTEND_ADC1); | ||
1596 | int ext2 = lm85_read_value(client, | ||
1597 | EMC6D102_REG_EXTEND_ADC2); | ||
1598 | int ext3 = lm85_read_value(client, | ||
1599 | EMC6D102_REG_EXTEND_ADC3); | ||
1600 | int ext4 = lm85_read_value(client, | ||
1601 | EMC6D102_REG_EXTEND_ADC4); | ||
1602 | data->in_ext[0] = ext3 & 0x0f; | ||
1603 | data->in_ext[1] = ext4 & 0x0f; | ||
1604 | data->in_ext[2] = ext4 >> 4; | ||
1605 | data->in_ext[3] = ext3 >> 4; | ||
1606 | data->in_ext[4] = ext2 >> 4; | ||
1607 | |||
1608 | data->temp_ext[0] = ext1 & 0x0f; | ||
1609 | data->temp_ext[1] = ext2 & 0x0f; | ||
1610 | data->temp_ext[2] = ext1 >> 4; | ||
1611 | } | ||
1612 | |||
1613 | data->last_reading = jiffies; | ||
1614 | } /* last_reading */ | ||
1615 | |||
1616 | if (!data->valid || | ||
1617 | time_after(jiffies, data->last_config + LM85_CONFIG_INTERVAL)) { | ||
1618 | /* Things that don't change often */ | ||
1619 | dev_dbg(&client->dev, "Reading config values\n"); | ||
1620 | |||
1621 | for (i = 0; i <= 3; ++i) { | ||
1622 | data->in_min[i] = | ||
1623 | lm85_read_value(client, LM85_REG_IN_MIN(i)); | ||
1624 | data->in_max[i] = | ||
1625 | lm85_read_value(client, LM85_REG_IN_MAX(i)); | ||
1626 | data->fan_min[i] = | ||
1627 | lm85_read_value(client, LM85_REG_FAN_MIN(i)); | ||
1628 | } | ||
1629 | |||
1630 | if (!data->has_vid5) { | ||
1631 | data->in_min[4] = lm85_read_value(client, | ||
1632 | LM85_REG_IN_MIN(4)); | ||
1633 | data->in_max[4] = lm85_read_value(client, | ||
1634 | LM85_REG_IN_MAX(4)); | ||
1635 | } | ||
1636 | |||
1637 | if (data->type == emc6d100) { | ||
1638 | for (i = 5; i <= 7; ++i) { | ||
1639 | data->in_min[i] = lm85_read_value(client, | ||
1640 | EMC6D100_REG_IN_MIN(i)); | ||
1641 | data->in_max[i] = lm85_read_value(client, | ||
1642 | EMC6D100_REG_IN_MAX(i)); | ||
1643 | } | ||
1644 | } | ||
1645 | |||
1646 | for (i = 0; i <= 2; ++i) { | ||
1647 | int val; | ||
1648 | |||
1649 | data->temp_min[i] = | ||
1650 | lm85_read_value(client, LM85_REG_TEMP_MIN(i)); | ||
1651 | data->temp_max[i] = | ||
1652 | lm85_read_value(client, LM85_REG_TEMP_MAX(i)); | ||
1653 | |||
1654 | data->autofan[i].config = | ||
1655 | lm85_read_value(client, LM85_REG_AFAN_CONFIG(i)); | ||
1656 | val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i)); | ||
1657 | data->pwm_freq[i] = val & 0x07; | ||
1658 | data->zone[i].range = val >> 4; | ||
1659 | data->autofan[i].min_pwm = | ||
1660 | lm85_read_value(client, LM85_REG_AFAN_MINPWM(i)); | ||
1661 | data->zone[i].limit = | ||
1662 | lm85_read_value(client, LM85_REG_AFAN_LIMIT(i)); | ||
1663 | data->zone[i].critical = | ||
1664 | lm85_read_value(client, LM85_REG_AFAN_CRITICAL(i)); | ||
1665 | |||
1666 | if (IS_ADT7468_OFF64(data)) { | ||
1667 | data->temp_min[i] -= 64; | ||
1668 | data->temp_max[i] -= 64; | ||
1669 | data->zone[i].limit -= 64; | ||
1670 | data->zone[i].critical -= 64; | ||
1671 | } | ||
1672 | } | ||
1673 | |||
1674 | if (data->type != emc6d103s) { | ||
1675 | i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1); | ||
1676 | data->autofan[0].min_off = (i & 0x20) != 0; | ||
1677 | data->autofan[1].min_off = (i & 0x40) != 0; | ||
1678 | data->autofan[2].min_off = (i & 0x80) != 0; | ||
1679 | |||
1680 | i = lm85_read_value(client, LM85_REG_AFAN_HYST1); | ||
1681 | data->zone[0].hyst = i >> 4; | ||
1682 | data->zone[1].hyst = i & 0x0f; | ||
1683 | |||
1684 | i = lm85_read_value(client, LM85_REG_AFAN_HYST2); | ||
1685 | data->zone[2].hyst = i >> 4; | ||
1686 | } | ||
1687 | |||
1688 | data->last_config = jiffies; | ||
1689 | } /* last_config */ | ||
1690 | |||
1691 | data->valid = 1; | ||
1692 | |||
1693 | mutex_unlock(&data->update_lock); | ||
1694 | 1634 | ||
1695 | return data; | 1635 | static struct i2c_driver lm85_driver = { |
1696 | } | 1636 | .class = I2C_CLASS_HWMON, |
1637 | .driver = { | ||
1638 | .name = "lm85", | ||
1639 | }, | ||
1640 | .probe = lm85_probe, | ||
1641 | .id_table = lm85_id, | ||
1642 | .detect = lm85_detect, | ||
1643 | .address_list = normal_i2c, | ||
1644 | }; | ||
1697 | 1645 | ||
1698 | module_i2c_driver(lm85_driver); | 1646 | module_i2c_driver(lm85_driver); |
1699 | 1647 | ||
diff --git a/drivers/hwmon/lm93.c b/drivers/hwmon/lm93.c index 6c2df576f253..90bb04858117 100644 --- a/drivers/hwmon/lm93.c +++ b/drivers/hwmon/lm93.c | |||
@@ -207,7 +207,7 @@ struct block1_t { | |||
207 | * Client-specific data | 207 | * Client-specific data |
208 | */ | 208 | */ |
209 | struct lm93_data { | 209 | struct lm93_data { |
210 | struct device *hwmon_dev; | 210 | struct i2c_client *client; |
211 | 211 | ||
212 | struct mutex update_lock; | 212 | struct mutex update_lock; |
213 | unsigned long last_updated; /* In jiffies */ | 213 | unsigned long last_updated; /* In jiffies */ |
@@ -919,8 +919,8 @@ static void lm93_read_block(struct i2c_client *client, u8 fbn, u8 *values) | |||
919 | 919 | ||
920 | static struct lm93_data *lm93_update_device(struct device *dev) | 920 | static struct lm93_data *lm93_update_device(struct device *dev) |
921 | { | 921 | { |
922 | struct i2c_client *client = to_i2c_client(dev); | 922 | struct lm93_data *data = dev_get_drvdata(dev); |
923 | struct lm93_data *data = i2c_get_clientdata(client); | 923 | struct i2c_client *client = data->client; |
924 | const unsigned long interval = HZ + (HZ / 2); | 924 | const unsigned long interval = HZ + (HZ / 2); |
925 | 925 | ||
926 | mutex_lock(&data->update_lock); | 926 | mutex_lock(&data->update_lock); |
@@ -1158,8 +1158,8 @@ static ssize_t store_in_min(struct device *dev, struct device_attribute *attr, | |||
1158 | const char *buf, size_t count) | 1158 | const char *buf, size_t count) |
1159 | { | 1159 | { |
1160 | int nr = (to_sensor_dev_attr(attr))->index; | 1160 | int nr = (to_sensor_dev_attr(attr))->index; |
1161 | struct i2c_client *client = to_i2c_client(dev); | 1161 | struct lm93_data *data = dev_get_drvdata(dev); |
1162 | struct lm93_data *data = i2c_get_clientdata(client); | 1162 | struct i2c_client *client = data->client; |
1163 | int vccp = nr - 6; | 1163 | int vccp = nr - 6; |
1164 | long vid; | 1164 | long vid; |
1165 | unsigned long val; | 1165 | unsigned long val; |
@@ -1239,8 +1239,8 @@ static ssize_t store_in_max(struct device *dev, struct device_attribute *attr, | |||
1239 | const char *buf, size_t count) | 1239 | const char *buf, size_t count) |
1240 | { | 1240 | { |
1241 | int nr = (to_sensor_dev_attr(attr))->index; | 1241 | int nr = (to_sensor_dev_attr(attr))->index; |
1242 | struct i2c_client *client = to_i2c_client(dev); | 1242 | struct lm93_data *data = dev_get_drvdata(dev); |
1243 | struct lm93_data *data = i2c_get_clientdata(client); | 1243 | struct i2c_client *client = data->client; |
1244 | int vccp = nr - 6; | 1244 | int vccp = nr - 6; |
1245 | long vid; | 1245 | long vid; |
1246 | unsigned long val; | 1246 | unsigned long val; |
@@ -1323,8 +1323,8 @@ static ssize_t store_temp_min(struct device *dev, struct device_attribute *attr, | |||
1323 | const char *buf, size_t count) | 1323 | const char *buf, size_t count) |
1324 | { | 1324 | { |
1325 | int nr = (to_sensor_dev_attr(attr))->index; | 1325 | int nr = (to_sensor_dev_attr(attr))->index; |
1326 | struct i2c_client *client = to_i2c_client(dev); | 1326 | struct lm93_data *data = dev_get_drvdata(dev); |
1327 | struct lm93_data *data = i2c_get_clientdata(client); | 1327 | struct i2c_client *client = data->client; |
1328 | long val; | 1328 | long val; |
1329 | int err; | 1329 | int err; |
1330 | 1330 | ||
@@ -1358,8 +1358,8 @@ static ssize_t store_temp_max(struct device *dev, struct device_attribute *attr, | |||
1358 | const char *buf, size_t count) | 1358 | const char *buf, size_t count) |
1359 | { | 1359 | { |
1360 | int nr = (to_sensor_dev_attr(attr))->index; | 1360 | int nr = (to_sensor_dev_attr(attr))->index; |
1361 | struct i2c_client *client = to_i2c_client(dev); | 1361 | struct lm93_data *data = dev_get_drvdata(dev); |
1362 | struct lm93_data *data = i2c_get_clientdata(client); | 1362 | struct i2c_client *client = data->client; |
1363 | long val; | 1363 | long val; |
1364 | int err; | 1364 | int err; |
1365 | 1365 | ||
@@ -1394,8 +1394,8 @@ static ssize_t store_temp_auto_base(struct device *dev, | |||
1394 | const char *buf, size_t count) | 1394 | const char *buf, size_t count) |
1395 | { | 1395 | { |
1396 | int nr = (to_sensor_dev_attr(attr))->index; | 1396 | int nr = (to_sensor_dev_attr(attr))->index; |
1397 | struct i2c_client *client = to_i2c_client(dev); | 1397 | struct lm93_data *data = dev_get_drvdata(dev); |
1398 | struct lm93_data *data = i2c_get_clientdata(client); | 1398 | struct i2c_client *client = data->client; |
1399 | long val; | 1399 | long val; |
1400 | int err; | 1400 | int err; |
1401 | 1401 | ||
@@ -1430,8 +1430,8 @@ static ssize_t store_temp_auto_boost(struct device *dev, | |||
1430 | const char *buf, size_t count) | 1430 | const char *buf, size_t count) |
1431 | { | 1431 | { |
1432 | int nr = (to_sensor_dev_attr(attr))->index; | 1432 | int nr = (to_sensor_dev_attr(attr))->index; |
1433 | struct i2c_client *client = to_i2c_client(dev); | 1433 | struct lm93_data *data = dev_get_drvdata(dev); |
1434 | struct lm93_data *data = i2c_get_clientdata(client); | 1434 | struct i2c_client *client = data->client; |
1435 | long val; | 1435 | long val; |
1436 | int err; | 1436 | int err; |
1437 | 1437 | ||
@@ -1469,8 +1469,8 @@ static ssize_t store_temp_auto_boost_hyst(struct device *dev, | |||
1469 | const char *buf, size_t count) | 1469 | const char *buf, size_t count) |
1470 | { | 1470 | { |
1471 | int nr = (to_sensor_dev_attr(attr))->index; | 1471 | int nr = (to_sensor_dev_attr(attr))->index; |
1472 | struct i2c_client *client = to_i2c_client(dev); | 1472 | struct lm93_data *data = dev_get_drvdata(dev); |
1473 | struct lm93_data *data = i2c_get_clientdata(client); | 1473 | struct i2c_client *client = data->client; |
1474 | unsigned long val; | 1474 | unsigned long val; |
1475 | int err; | 1475 | int err; |
1476 | 1476 | ||
@@ -1520,8 +1520,8 @@ static ssize_t store_temp_auto_offset(struct device *dev, | |||
1520 | struct sensor_device_attribute_2 *s_attr = to_sensor_dev_attr_2(attr); | 1520 | struct sensor_device_attribute_2 *s_attr = to_sensor_dev_attr_2(attr); |
1521 | int nr = s_attr->index; | 1521 | int nr = s_attr->index; |
1522 | int ofs = s_attr->nr; | 1522 | int ofs = s_attr->nr; |
1523 | struct i2c_client *client = to_i2c_client(dev); | 1523 | struct lm93_data *data = dev_get_drvdata(dev); |
1524 | struct lm93_data *data = i2c_get_clientdata(client); | 1524 | struct i2c_client *client = data->client; |
1525 | unsigned long val; | 1525 | unsigned long val; |
1526 | int err; | 1526 | int err; |
1527 | 1527 | ||
@@ -1632,8 +1632,8 @@ static ssize_t store_temp_auto_pwm_min(struct device *dev, | |||
1632 | const char *buf, size_t count) | 1632 | const char *buf, size_t count) |
1633 | { | 1633 | { |
1634 | int nr = (to_sensor_dev_attr(attr))->index; | 1634 | int nr = (to_sensor_dev_attr(attr))->index; |
1635 | struct i2c_client *client = to_i2c_client(dev); | 1635 | struct lm93_data *data = dev_get_drvdata(dev); |
1636 | struct lm93_data *data = i2c_get_clientdata(client); | 1636 | struct i2c_client *client = data->client; |
1637 | u8 reg, ctl4; | 1637 | u8 reg, ctl4; |
1638 | unsigned long val; | 1638 | unsigned long val; |
1639 | int err; | 1639 | int err; |
@@ -1680,8 +1680,8 @@ static ssize_t store_temp_auto_offset_hyst(struct device *dev, | |||
1680 | const char *buf, size_t count) | 1680 | const char *buf, size_t count) |
1681 | { | 1681 | { |
1682 | int nr = (to_sensor_dev_attr(attr))->index; | 1682 | int nr = (to_sensor_dev_attr(attr))->index; |
1683 | struct i2c_client *client = to_i2c_client(dev); | 1683 | struct lm93_data *data = dev_get_drvdata(dev); |
1684 | struct lm93_data *data = i2c_get_clientdata(client); | 1684 | struct i2c_client *client = data->client; |
1685 | u8 reg; | 1685 | u8 reg; |
1686 | unsigned long val; | 1686 | unsigned long val; |
1687 | int err; | 1687 | int err; |
@@ -1741,8 +1741,8 @@ static ssize_t store_fan_min(struct device *dev, struct device_attribute *attr, | |||
1741 | const char *buf, size_t count) | 1741 | const char *buf, size_t count) |
1742 | { | 1742 | { |
1743 | int nr = (to_sensor_dev_attr(attr))->index; | 1743 | int nr = (to_sensor_dev_attr(attr))->index; |
1744 | struct i2c_client *client = to_i2c_client(dev); | 1744 | struct lm93_data *data = dev_get_drvdata(dev); |
1745 | struct lm93_data *data = i2c_get_clientdata(client); | 1745 | struct i2c_client *client = data->client; |
1746 | unsigned long val; | 1746 | unsigned long val; |
1747 | int err; | 1747 | int err; |
1748 | 1748 | ||
@@ -1824,8 +1824,8 @@ static ssize_t store_fan_smart_tach(struct device *dev, | |||
1824 | const char *buf, size_t count) | 1824 | const char *buf, size_t count) |
1825 | { | 1825 | { |
1826 | int nr = (to_sensor_dev_attr(attr))->index; | 1826 | int nr = (to_sensor_dev_attr(attr))->index; |
1827 | struct i2c_client *client = to_i2c_client(dev); | 1827 | struct lm93_data *data = dev_get_drvdata(dev); |
1828 | struct lm93_data *data = i2c_get_clientdata(client); | 1828 | struct i2c_client *client = data->client; |
1829 | unsigned long val; | 1829 | unsigned long val; |
1830 | int err; | 1830 | int err; |
1831 | 1831 | ||
@@ -1880,8 +1880,8 @@ static ssize_t store_pwm(struct device *dev, struct device_attribute *attr, | |||
1880 | const char *buf, size_t count) | 1880 | const char *buf, size_t count) |
1881 | { | 1881 | { |
1882 | int nr = (to_sensor_dev_attr(attr))->index; | 1882 | int nr = (to_sensor_dev_attr(attr))->index; |
1883 | struct i2c_client *client = to_i2c_client(dev); | 1883 | struct lm93_data *data = dev_get_drvdata(dev); |
1884 | struct lm93_data *data = i2c_get_clientdata(client); | 1884 | struct i2c_client *client = data->client; |
1885 | u8 ctl2, ctl4; | 1885 | u8 ctl2, ctl4; |
1886 | unsigned long val; | 1886 | unsigned long val; |
1887 | int err; | 1887 | int err; |
@@ -1928,8 +1928,8 @@ static ssize_t store_pwm_enable(struct device *dev, | |||
1928 | const char *buf, size_t count) | 1928 | const char *buf, size_t count) |
1929 | { | 1929 | { |
1930 | int nr = (to_sensor_dev_attr(attr))->index; | 1930 | int nr = (to_sensor_dev_attr(attr))->index; |
1931 | struct i2c_client *client = to_i2c_client(dev); | 1931 | struct lm93_data *data = dev_get_drvdata(dev); |
1932 | struct lm93_data *data = i2c_get_clientdata(client); | 1932 | struct i2c_client *client = data->client; |
1933 | u8 ctl2; | 1933 | u8 ctl2; |
1934 | unsigned long val; | 1934 | unsigned long val; |
1935 | int err; | 1935 | int err; |
@@ -2006,8 +2006,8 @@ static ssize_t store_pwm_freq(struct device *dev, | |||
2006 | const char *buf, size_t count) | 2006 | const char *buf, size_t count) |
2007 | { | 2007 | { |
2008 | int nr = (to_sensor_dev_attr(attr))->index; | 2008 | int nr = (to_sensor_dev_attr(attr))->index; |
2009 | struct i2c_client *client = to_i2c_client(dev); | 2009 | struct lm93_data *data = dev_get_drvdata(dev); |
2010 | struct lm93_data *data = i2c_get_clientdata(client); | 2010 | struct i2c_client *client = data->client; |
2011 | u8 ctl4; | 2011 | u8 ctl4; |
2012 | unsigned long val; | 2012 | unsigned long val; |
2013 | int err; | 2013 | int err; |
@@ -2046,8 +2046,8 @@ static ssize_t store_pwm_auto_channels(struct device *dev, | |||
2046 | const char *buf, size_t count) | 2046 | const char *buf, size_t count) |
2047 | { | 2047 | { |
2048 | int nr = (to_sensor_dev_attr(attr))->index; | 2048 | int nr = (to_sensor_dev_attr(attr))->index; |
2049 | struct i2c_client *client = to_i2c_client(dev); | 2049 | struct lm93_data *data = dev_get_drvdata(dev); |
2050 | struct lm93_data *data = i2c_get_clientdata(client); | 2050 | struct i2c_client *client = data->client; |
2051 | unsigned long val; | 2051 | unsigned long val; |
2052 | int err; | 2052 | int err; |
2053 | 2053 | ||
@@ -2087,8 +2087,8 @@ static ssize_t store_pwm_auto_spinup_min(struct device *dev, | |||
2087 | const char *buf, size_t count) | 2087 | const char *buf, size_t count) |
2088 | { | 2088 | { |
2089 | int nr = (to_sensor_dev_attr(attr))->index; | 2089 | int nr = (to_sensor_dev_attr(attr))->index; |
2090 | struct i2c_client *client = to_i2c_client(dev); | 2090 | struct lm93_data *data = dev_get_drvdata(dev); |
2091 | struct lm93_data *data = i2c_get_clientdata(client); | 2091 | struct i2c_client *client = data->client; |
2092 | u8 ctl3, ctl4; | 2092 | u8 ctl3, ctl4; |
2093 | unsigned long val; | 2093 | unsigned long val; |
2094 | int err; | 2094 | int err; |
@@ -2130,8 +2130,8 @@ static ssize_t store_pwm_auto_spinup_time(struct device *dev, | |||
2130 | const char *buf, size_t count) | 2130 | const char *buf, size_t count) |
2131 | { | 2131 | { |
2132 | int nr = (to_sensor_dev_attr(attr))->index; | 2132 | int nr = (to_sensor_dev_attr(attr))->index; |
2133 | struct i2c_client *client = to_i2c_client(dev); | 2133 | struct lm93_data *data = dev_get_drvdata(dev); |
2134 | struct lm93_data *data = i2c_get_clientdata(client); | 2134 | struct i2c_client *client = data->client; |
2135 | u8 ctl3; | 2135 | u8 ctl3; |
2136 | unsigned long val; | 2136 | unsigned long val; |
2137 | int err; | 2137 | int err; |
@@ -2168,8 +2168,8 @@ static ssize_t store_pwm_auto_prochot_ramp(struct device *dev, | |||
2168 | struct device_attribute *attr, | 2168 | struct device_attribute *attr, |
2169 | const char *buf, size_t count) | 2169 | const char *buf, size_t count) |
2170 | { | 2170 | { |
2171 | struct i2c_client *client = to_i2c_client(dev); | 2171 | struct lm93_data *data = dev_get_drvdata(dev); |
2172 | struct lm93_data *data = i2c_get_clientdata(client); | 2172 | struct i2c_client *client = data->client; |
2173 | u8 ramp; | 2173 | u8 ramp; |
2174 | unsigned long val; | 2174 | unsigned long val; |
2175 | int err; | 2175 | int err; |
@@ -2202,8 +2202,8 @@ static ssize_t store_pwm_auto_vrdhot_ramp(struct device *dev, | |||
2202 | struct device_attribute *attr, | 2202 | struct device_attribute *attr, |
2203 | const char *buf, size_t count) | 2203 | const char *buf, size_t count) |
2204 | { | 2204 | { |
2205 | struct i2c_client *client = to_i2c_client(dev); | 2205 | struct lm93_data *data = dev_get_drvdata(dev); |
2206 | struct lm93_data *data = i2c_get_clientdata(client); | 2206 | struct i2c_client *client = data->client; |
2207 | u8 ramp; | 2207 | u8 ramp; |
2208 | unsigned long val; | 2208 | unsigned long val; |
2209 | int err; | 2209 | int err; |
@@ -2270,8 +2270,8 @@ static ssize_t store_prochot_max(struct device *dev, | |||
2270 | const char *buf, size_t count) | 2270 | const char *buf, size_t count) |
2271 | { | 2271 | { |
2272 | int nr = (to_sensor_dev_attr(attr))->index; | 2272 | int nr = (to_sensor_dev_attr(attr))->index; |
2273 | struct i2c_client *client = to_i2c_client(dev); | 2273 | struct lm93_data *data = dev_get_drvdata(dev); |
2274 | struct lm93_data *data = i2c_get_clientdata(client); | 2274 | struct i2c_client *client = data->client; |
2275 | unsigned long val; | 2275 | unsigned long val; |
2276 | int err; | 2276 | int err; |
2277 | 2277 | ||
@@ -2308,8 +2308,8 @@ static ssize_t store_prochot_override(struct device *dev, | |||
2308 | const char *buf, size_t count) | 2308 | const char *buf, size_t count) |
2309 | { | 2309 | { |
2310 | int nr = (to_sensor_dev_attr(attr))->index; | 2310 | int nr = (to_sensor_dev_attr(attr))->index; |
2311 | struct i2c_client *client = to_i2c_client(dev); | 2311 | struct lm93_data *data = dev_get_drvdata(dev); |
2312 | struct lm93_data *data = i2c_get_clientdata(client); | 2312 | struct i2c_client *client = data->client; |
2313 | unsigned long val; | 2313 | unsigned long val; |
2314 | int err; | 2314 | int err; |
2315 | 2315 | ||
@@ -2351,8 +2351,8 @@ static ssize_t store_prochot_interval(struct device *dev, | |||
2351 | const char *buf, size_t count) | 2351 | const char *buf, size_t count) |
2352 | { | 2352 | { |
2353 | int nr = (to_sensor_dev_attr(attr))->index; | 2353 | int nr = (to_sensor_dev_attr(attr))->index; |
2354 | struct i2c_client *client = to_i2c_client(dev); | 2354 | struct lm93_data *data = dev_get_drvdata(dev); |
2355 | struct lm93_data *data = i2c_get_clientdata(client); | 2355 | struct i2c_client *client = data->client; |
2356 | u8 tmp; | 2356 | u8 tmp; |
2357 | unsigned long val; | 2357 | unsigned long val; |
2358 | int err; | 2358 | int err; |
@@ -2390,8 +2390,8 @@ static ssize_t store_prochot_override_duty_cycle(struct device *dev, | |||
2390 | struct device_attribute *attr, | 2390 | struct device_attribute *attr, |
2391 | const char *buf, size_t count) | 2391 | const char *buf, size_t count) |
2392 | { | 2392 | { |
2393 | struct i2c_client *client = to_i2c_client(dev); | 2393 | struct lm93_data *data = dev_get_drvdata(dev); |
2394 | struct lm93_data *data = i2c_get_clientdata(client); | 2394 | struct i2c_client *client = data->client; |
2395 | unsigned long val; | 2395 | unsigned long val; |
2396 | int err; | 2396 | int err; |
2397 | 2397 | ||
@@ -2423,8 +2423,8 @@ static ssize_t store_prochot_short(struct device *dev, | |||
2423 | struct device_attribute *attr, | 2423 | struct device_attribute *attr, |
2424 | const char *buf, size_t count) | 2424 | const char *buf, size_t count) |
2425 | { | 2425 | { |
2426 | struct i2c_client *client = to_i2c_client(dev); | 2426 | struct lm93_data *data = dev_get_drvdata(dev); |
2427 | struct lm93_data *data = i2c_get_clientdata(client); | 2427 | struct i2c_client *client = data->client; |
2428 | unsigned long val; | 2428 | unsigned long val; |
2429 | int err; | 2429 | int err; |
2430 | 2430 | ||
@@ -2631,9 +2631,7 @@ static struct attribute *lm93_attrs[] = { | |||
2631 | NULL | 2631 | NULL |
2632 | }; | 2632 | }; |
2633 | 2633 | ||
2634 | static struct attribute_group lm93_attr_grp = { | 2634 | ATTRIBUTE_GROUPS(lm93); |
2635 | .attrs = lm93_attrs, | ||
2636 | }; | ||
2637 | 2635 | ||
2638 | static void lm93_init_client(struct i2c_client *client) | 2636 | static void lm93_init_client(struct i2c_client *client) |
2639 | { | 2637 | { |
@@ -2726,61 +2724,42 @@ static int lm93_detect(struct i2c_client *client, struct i2c_board_info *info) | |||
2726 | static int lm93_probe(struct i2c_client *client, | 2724 | static int lm93_probe(struct i2c_client *client, |
2727 | const struct i2c_device_id *id) | 2725 | const struct i2c_device_id *id) |
2728 | { | 2726 | { |
2727 | struct device *dev = &client->dev; | ||
2729 | struct lm93_data *data; | 2728 | struct lm93_data *data; |
2730 | int err, func; | 2729 | struct device *hwmon_dev; |
2730 | int func; | ||
2731 | void (*update)(struct lm93_data *, struct i2c_client *); | 2731 | void (*update)(struct lm93_data *, struct i2c_client *); |
2732 | 2732 | ||
2733 | /* choose update routine based on bus capabilities */ | 2733 | /* choose update routine based on bus capabilities */ |
2734 | func = i2c_get_functionality(client->adapter); | 2734 | func = i2c_get_functionality(client->adapter); |
2735 | if (((LM93_SMBUS_FUNC_FULL & func) == LM93_SMBUS_FUNC_FULL) && | 2735 | if (((LM93_SMBUS_FUNC_FULL & func) == LM93_SMBUS_FUNC_FULL) && |
2736 | (!disable_block)) { | 2736 | (!disable_block)) { |
2737 | dev_dbg(&client->dev, "using SMBus block data transactions\n"); | 2737 | dev_dbg(dev, "using SMBus block data transactions\n"); |
2738 | update = lm93_update_client_full; | 2738 | update = lm93_update_client_full; |
2739 | } else if ((LM93_SMBUS_FUNC_MIN & func) == LM93_SMBUS_FUNC_MIN) { | 2739 | } else if ((LM93_SMBUS_FUNC_MIN & func) == LM93_SMBUS_FUNC_MIN) { |
2740 | dev_dbg(&client->dev, | 2740 | dev_dbg(dev, "disabled SMBus block data transactions\n"); |
2741 | "disabled SMBus block data transactions\n"); | ||
2742 | update = lm93_update_client_min; | 2741 | update = lm93_update_client_min; |
2743 | } else { | 2742 | } else { |
2744 | dev_dbg(&client->dev, | 2743 | dev_dbg(dev, "detect failed, smbus byte and/or word data not supported!\n"); |
2745 | "detect failed, smbus byte and/or word data not supported!\n"); | ||
2746 | return -ENODEV; | 2744 | return -ENODEV; |
2747 | } | 2745 | } |
2748 | 2746 | ||
2749 | data = devm_kzalloc(&client->dev, sizeof(struct lm93_data), GFP_KERNEL); | 2747 | data = devm_kzalloc(dev, sizeof(struct lm93_data), GFP_KERNEL); |
2750 | if (!data) | 2748 | if (!data) |
2751 | return -ENOMEM; | 2749 | return -ENOMEM; |
2752 | i2c_set_clientdata(client, data); | ||
2753 | 2750 | ||
2754 | /* housekeeping */ | 2751 | /* housekeeping */ |
2752 | data->client = client; | ||
2755 | data->update = update; | 2753 | data->update = update; |
2756 | mutex_init(&data->update_lock); | 2754 | mutex_init(&data->update_lock); |
2757 | 2755 | ||
2758 | /* initialize the chip */ | 2756 | /* initialize the chip */ |
2759 | lm93_init_client(client); | 2757 | lm93_init_client(client); |
2760 | 2758 | ||
2761 | err = sysfs_create_group(&client->dev.kobj, &lm93_attr_grp); | 2759 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
2762 | if (err) | 2760 | data, |
2763 | return err; | 2761 | lm93_groups); |
2764 | 2762 | return PTR_ERR_OR_ZERO(hwmon_dev); | |
2765 | /* Register hwmon driver class */ | ||
2766 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
2767 | if (!IS_ERR(data->hwmon_dev)) | ||
2768 | return 0; | ||
2769 | |||
2770 | err = PTR_ERR(data->hwmon_dev); | ||
2771 | dev_err(&client->dev, "error registering hwmon device.\n"); | ||
2772 | sysfs_remove_group(&client->dev.kobj, &lm93_attr_grp); | ||
2773 | return err; | ||
2774 | } | ||
2775 | |||
2776 | static int lm93_remove(struct i2c_client *client) | ||
2777 | { | ||
2778 | struct lm93_data *data = i2c_get_clientdata(client); | ||
2779 | |||
2780 | hwmon_device_unregister(data->hwmon_dev); | ||
2781 | sysfs_remove_group(&client->dev.kobj, &lm93_attr_grp); | ||
2782 | |||
2783 | return 0; | ||
2784 | } | 2763 | } |
2785 | 2764 | ||
2786 | static const struct i2c_device_id lm93_id[] = { | 2765 | static const struct i2c_device_id lm93_id[] = { |
@@ -2796,7 +2775,6 @@ static struct i2c_driver lm93_driver = { | |||
2796 | .name = "lm93", | 2775 | .name = "lm93", |
2797 | }, | 2776 | }, |
2798 | .probe = lm93_probe, | 2777 | .probe = lm93_probe, |
2799 | .remove = lm93_remove, | ||
2800 | .id_table = lm93_id, | 2778 | .id_table = lm93_id, |
2801 | .detect = lm93_detect, | 2779 | .detect = lm93_detect, |
2802 | .address_list = normal_i2c, | 2780 | .address_list = normal_i2c, |
diff --git a/drivers/hwmon/ltc2945.c b/drivers/hwmon/ltc2945.c index 3701b329b6ae..1b92e4f6e234 100644 --- a/drivers/hwmon/ltc2945.c +++ b/drivers/hwmon/ltc2945.c | |||
@@ -469,7 +469,7 @@ static struct attribute *ltc2945_attrs[] = { | |||
469 | }; | 469 | }; |
470 | ATTRIBUTE_GROUPS(ltc2945); | 470 | ATTRIBUTE_GROUPS(ltc2945); |
471 | 471 | ||
472 | static struct regmap_config ltc2945_regmap_config = { | 472 | static const struct regmap_config ltc2945_regmap_config = { |
473 | .reg_bits = 8, | 473 | .reg_bits = 8, |
474 | .val_bits = 8, | 474 | .val_bits = 8, |
475 | .max_register = LTC2945_MIN_ADIN_THRES_L, | 475 | .max_register = LTC2945_MIN_ADIN_THRES_L, |
diff --git a/drivers/hwmon/ltc4222.c b/drivers/hwmon/ltc4222.c index 07c25653659f..88f747292816 100644 --- a/drivers/hwmon/ltc4222.c +++ b/drivers/hwmon/ltc4222.c | |||
@@ -186,7 +186,7 @@ static struct attribute *ltc4222_attrs[] = { | |||
186 | }; | 186 | }; |
187 | ATTRIBUTE_GROUPS(ltc4222); | 187 | ATTRIBUTE_GROUPS(ltc4222); |
188 | 188 | ||
189 | static struct regmap_config ltc4222_regmap_config = { | 189 | static const struct regmap_config ltc4222_regmap_config = { |
190 | .reg_bits = 8, | 190 | .reg_bits = 8, |
191 | .val_bits = 8, | 191 | .val_bits = 8, |
192 | .max_register = LTC4222_ADC_CONTROL, | 192 | .max_register = LTC4222_ADC_CONTROL, |
diff --git a/drivers/hwmon/ltc4260.c b/drivers/hwmon/ltc4260.c index 453a250d9df5..afb09574b12c 100644 --- a/drivers/hwmon/ltc4260.c +++ b/drivers/hwmon/ltc4260.c | |||
@@ -150,7 +150,7 @@ static struct attribute *ltc4260_attrs[] = { | |||
150 | }; | 150 | }; |
151 | ATTRIBUTE_GROUPS(ltc4260); | 151 | ATTRIBUTE_GROUPS(ltc4260); |
152 | 152 | ||
153 | static struct regmap_config ltc4260_regmap_config = { | 153 | static const struct regmap_config ltc4260_regmap_config = { |
154 | .reg_bits = 8, | 154 | .reg_bits = 8, |
155 | .val_bits = 8, | 155 | .val_bits = 8, |
156 | .max_register = LTC4260_ADIN, | 156 | .max_register = LTC4260_ADIN, |
diff --git a/drivers/hwmon/max16065.c b/drivers/hwmon/max16065.c index d4efc79d7b93..162401aaef71 100644 --- a/drivers/hwmon/max16065.c +++ b/drivers/hwmon/max16065.c | |||
@@ -642,10 +642,7 @@ static int max16065_probe(struct i2c_client *client, | |||
642 | 642 | ||
643 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, | 643 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
644 | data, data->groups); | 644 | data, data->groups); |
645 | if (unlikely(IS_ERR(hwmon_dev))) | 645 | return PTR_ERR_OR_ZERO(hwmon_dev); |
646 | return PTR_ERR(hwmon_dev); | ||
647 | |||
648 | return 0; | ||
649 | } | 646 | } |
650 | 647 | ||
651 | static const struct i2c_device_id max16065_id[] = { | 648 | static const struct i2c_device_id max16065_id[] = { |
diff --git a/drivers/hwmon/max1668.c b/drivers/hwmon/max1668.c index e3ed0a5b6d94..7ca889910262 100644 --- a/drivers/hwmon/max1668.c +++ b/drivers/hwmon/max1668.c | |||
@@ -30,7 +30,7 @@ | |||
30 | #include <linux/mutex.h> | 30 | #include <linux/mutex.h> |
31 | 31 | ||
32 | /* Addresses to scan */ | 32 | /* Addresses to scan */ |
33 | static unsigned short max1668_addr_list[] = { | 33 | static const unsigned short max1668_addr_list[] = { |
34 | 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END }; | 34 | 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END }; |
35 | 35 | ||
36 | /* max1668 registers */ | 36 | /* max1668 registers */ |
diff --git a/drivers/hwmon/max6639.c b/drivers/hwmon/max6639.c index 70650de2cbd1..dac6d85f2fd9 100644 --- a/drivers/hwmon/max6639.c +++ b/drivers/hwmon/max6639.c | |||
@@ -35,7 +35,7 @@ | |||
35 | #include <linux/i2c/max6639.h> | 35 | #include <linux/i2c/max6639.h> |
36 | 36 | ||
37 | /* Addresses to scan */ | 37 | /* Addresses to scan */ |
38 | static unsigned short normal_i2c[] = { 0x2c, 0x2e, 0x2f, I2C_CLIENT_END }; | 38 | static const unsigned short normal_i2c[] = { 0x2c, 0x2e, 0x2f, I2C_CLIENT_END }; |
39 | 39 | ||
40 | /* The MAX6639 registers, valid channel numbers: 0, 1 */ | 40 | /* The MAX6639 registers, valid channel numbers: 0, 1 */ |
41 | #define MAX6639_REG_TEMP(ch) (0x00 + (ch)) | 41 | #define MAX6639_REG_TEMP(ch) (0x00 + (ch)) |
diff --git a/drivers/hwmon/max6697.c b/drivers/hwmon/max6697.c index 7fd3eaf817f4..f03a71722849 100644 --- a/drivers/hwmon/max6697.c +++ b/drivers/hwmon/max6697.c | |||
@@ -495,15 +495,13 @@ static void max6697_get_config_of(struct device_node *node, | |||
495 | int len; | 495 | int len; |
496 | const __be32 *prop; | 496 | const __be32 *prop; |
497 | 497 | ||
498 | prop = of_get_property(node, "smbus-timeout-disable", &len); | 498 | pdata->smbus_timeout_disable = |
499 | if (prop) | 499 | of_property_read_bool(node, "smbus-timeout-disable"); |
500 | pdata->smbus_timeout_disable = true; | 500 | pdata->extended_range_enable = |
501 | prop = of_get_property(node, "extended-range-enable", &len); | 501 | of_property_read_bool(node, "extended-range-enable"); |
502 | if (prop) | 502 | pdata->beta_compensation = |
503 | pdata->extended_range_enable = true; | 503 | of_property_read_bool(node, "beta-compensation-enable"); |
504 | prop = of_get_property(node, "beta-compensation-enable", &len); | 504 | |
505 | if (prop) | ||
506 | pdata->beta_compensation = true; | ||
507 | prop = of_get_property(node, "alert-mask", &len); | 505 | prop = of_get_property(node, "alert-mask", &len); |
508 | if (prop && len == sizeof(u32)) | 506 | if (prop && len == sizeof(u32)) |
509 | pdata->alert_mask = be32_to_cpu(prop[0]); | 507 | pdata->alert_mask = be32_to_cpu(prop[0]); |
diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c index 59d9a3fc96b7..504cbddbdd90 100644 --- a/drivers/hwmon/nct6775.c +++ b/drivers/hwmon/nct6775.c | |||
@@ -735,7 +735,6 @@ struct nct6775_data { | |||
735 | enum kinds kind; | 735 | enum kinds kind; |
736 | const char *name; | 736 | const char *name; |
737 | 737 | ||
738 | int num_attr_groups; | ||
739 | const struct attribute_group *groups[6]; | 738 | const struct attribute_group *groups[6]; |
740 | 739 | ||
741 | u16 reg_temp[5][NUM_TEMP]; /* 0=temp, 1=temp_over, 2=temp_hyst, | 740 | u16 reg_temp[5][NUM_TEMP]; /* 0=temp, 1=temp_over, 2=temp_hyst, |
@@ -3276,6 +3275,7 @@ static int nct6775_probe(struct platform_device *pdev) | |||
3276 | u8 cr2a; | 3275 | u8 cr2a; |
3277 | struct attribute_group *group; | 3276 | struct attribute_group *group; |
3278 | struct device *hwmon_dev; | 3277 | struct device *hwmon_dev; |
3278 | int num_attr_groups = 0; | ||
3279 | 3279 | ||
3280 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | 3280 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
3281 | if (!devm_request_region(&pdev->dev, res->start, IOREGION_LENGTH, | 3281 | if (!devm_request_region(&pdev->dev, res->start, IOREGION_LENGTH, |
@@ -3907,29 +3907,29 @@ static int nct6775_probe(struct platform_device *pdev) | |||
3907 | if (IS_ERR(group)) | 3907 | if (IS_ERR(group)) |
3908 | return PTR_ERR(group); | 3908 | return PTR_ERR(group); |
3909 | 3909 | ||
3910 | data->groups[data->num_attr_groups++] = group; | 3910 | data->groups[num_attr_groups++] = group; |
3911 | 3911 | ||
3912 | group = nct6775_create_attr_group(dev, &nct6775_in_template_group, | 3912 | group = nct6775_create_attr_group(dev, &nct6775_in_template_group, |
3913 | fls(data->have_in)); | 3913 | fls(data->have_in)); |
3914 | if (IS_ERR(group)) | 3914 | if (IS_ERR(group)) |
3915 | return PTR_ERR(group); | 3915 | return PTR_ERR(group); |
3916 | 3916 | ||
3917 | data->groups[data->num_attr_groups++] = group; | 3917 | data->groups[num_attr_groups++] = group; |
3918 | 3918 | ||
3919 | group = nct6775_create_attr_group(dev, &nct6775_fan_template_group, | 3919 | group = nct6775_create_attr_group(dev, &nct6775_fan_template_group, |
3920 | fls(data->has_fan)); | 3920 | fls(data->has_fan)); |
3921 | if (IS_ERR(group)) | 3921 | if (IS_ERR(group)) |
3922 | return PTR_ERR(group); | 3922 | return PTR_ERR(group); |
3923 | 3923 | ||
3924 | data->groups[data->num_attr_groups++] = group; | 3924 | data->groups[num_attr_groups++] = group; |
3925 | 3925 | ||
3926 | group = nct6775_create_attr_group(dev, &nct6775_temp_template_group, | 3926 | group = nct6775_create_attr_group(dev, &nct6775_temp_template_group, |
3927 | fls(data->have_temp)); | 3927 | fls(data->have_temp)); |
3928 | if (IS_ERR(group)) | 3928 | if (IS_ERR(group)) |
3929 | return PTR_ERR(group); | 3929 | return PTR_ERR(group); |
3930 | 3930 | ||
3931 | data->groups[data->num_attr_groups++] = group; | 3931 | data->groups[num_attr_groups++] = group; |
3932 | data->groups[data->num_attr_groups++] = &nct6775_group_other; | 3932 | data->groups[num_attr_groups++] = &nct6775_group_other; |
3933 | 3933 | ||
3934 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, data->name, | 3934 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, data->name, |
3935 | data, data->groups); | 3935 | data, data->groups); |
@@ -4221,7 +4221,7 @@ static void __exit sensors_nct6775_exit(void) | |||
4221 | } | 4221 | } |
4222 | 4222 | ||
4223 | MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>"); | 4223 | MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>"); |
4224 | MODULE_DESCRIPTION("NCT6775F/NCT6776F/NCT6779D driver"); | 4224 | MODULE_DESCRIPTION("NCT6106D/NCT6775F/NCT6776F/NCT6779D/NCT6791D driver"); |
4225 | MODULE_LICENSE("GPL"); | 4225 | MODULE_LICENSE("GPL"); |
4226 | 4226 | ||
4227 | module_init(sensors_nct6775_init); | 4227 | module_init(sensors_nct6775_init); |
diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c index ae66f42c4d6d..bd410722cd4b 100644 --- a/drivers/hwmon/ntc_thermistor.c +++ b/drivers/hwmon/ntc_thermistor.c | |||
@@ -51,6 +51,7 @@ static const struct platform_device_id ntc_thermistor_id[] = { | |||
51 | { "ncp21wb473", TYPE_NCPXXWB473 }, | 51 | { "ncp21wb473", TYPE_NCPXXWB473 }, |
52 | { "ncp03wb473", TYPE_NCPXXWB473 }, | 52 | { "ncp03wb473", TYPE_NCPXXWB473 }, |
53 | { "ncp15wl333", TYPE_NCPXXWL333 }, | 53 | { "ncp15wl333", TYPE_NCPXXWL333 }, |
54 | { "b57330v2103", TYPE_B57330V2103}, | ||
54 | { }, | 55 | { }, |
55 | }; | 56 | }; |
56 | 57 | ||
@@ -133,6 +134,47 @@ static const struct ntc_compensation ncpXXwl333[] = { | |||
133 | { .temp_c = 125, .ohm = 707 }, | 134 | { .temp_c = 125, .ohm = 707 }, |
134 | }; | 135 | }; |
135 | 136 | ||
137 | /* | ||
138 | * The following compensation table is from the specification of EPCOS NTC | ||
139 | * Thermistors Datasheet | ||
140 | */ | ||
141 | static const struct ntc_compensation b57330v2103[] = { | ||
142 | { .temp_c = -40, .ohm = 190030 }, | ||
143 | { .temp_c = -35, .ohm = 145360 }, | ||
144 | { .temp_c = -30, .ohm = 112060 }, | ||
145 | { .temp_c = -25, .ohm = 87041 }, | ||
146 | { .temp_c = -20, .ohm = 68104 }, | ||
147 | { .temp_c = -15, .ohm = 53665 }, | ||
148 | { .temp_c = -10, .ohm = 42576 }, | ||
149 | { .temp_c = -5, .ohm = 34001 }, | ||
150 | { .temp_c = 0, .ohm = 27326 }, | ||
151 | { .temp_c = 5, .ohm = 22096 }, | ||
152 | { .temp_c = 10, .ohm = 17973 }, | ||
153 | { .temp_c = 15, .ohm = 14703 }, | ||
154 | { .temp_c = 20, .ohm = 12090 }, | ||
155 | { .temp_c = 25, .ohm = 10000 }, | ||
156 | { .temp_c = 30, .ohm = 8311 }, | ||
157 | { .temp_c = 35, .ohm = 6941 }, | ||
158 | { .temp_c = 40, .ohm = 5825 }, | ||
159 | { .temp_c = 45, .ohm = 4911 }, | ||
160 | { .temp_c = 50, .ohm = 4158 }, | ||
161 | { .temp_c = 55, .ohm = 3536 }, | ||
162 | { .temp_c = 60, .ohm = 3019 }, | ||
163 | { .temp_c = 65, .ohm = 2588 }, | ||
164 | { .temp_c = 70, .ohm = 2227 }, | ||
165 | { .temp_c = 75, .ohm = 1924 }, | ||
166 | { .temp_c = 80, .ohm = 1668 }, | ||
167 | { .temp_c = 85, .ohm = 1451 }, | ||
168 | { .temp_c = 90, .ohm = 1266 }, | ||
169 | { .temp_c = 95, .ohm = 1108 }, | ||
170 | { .temp_c = 100, .ohm = 973 }, | ||
171 | { .temp_c = 105, .ohm = 857 }, | ||
172 | { .temp_c = 110, .ohm = 757 }, | ||
173 | { .temp_c = 115, .ohm = 671 }, | ||
174 | { .temp_c = 120, .ohm = 596 }, | ||
175 | { .temp_c = 125, .ohm = 531 }, | ||
176 | }; | ||
177 | |||
136 | struct ntc_data { | 178 | struct ntc_data { |
137 | struct device *hwmon_dev; | 179 | struct device *hwmon_dev; |
138 | struct ntc_thermistor_platform_data *pdata; | 180 | struct ntc_thermistor_platform_data *pdata; |
@@ -173,6 +215,8 @@ static const struct of_device_id ntc_match[] = { | |||
173 | .data = &ntc_thermistor_id[3] }, | 215 | .data = &ntc_thermistor_id[3] }, |
174 | { .compatible = "murata,ncp15wl333", | 216 | { .compatible = "murata,ncp15wl333", |
175 | .data = &ntc_thermistor_id[4] }, | 217 | .data = &ntc_thermistor_id[4] }, |
218 | { .compatible = "epcos,b57330v2103", | ||
219 | .data = &ntc_thermistor_id[5]}, | ||
176 | 220 | ||
177 | /* Usage of vendor name "ntc" is deprecated */ | 221 | /* Usage of vendor name "ntc" is deprecated */ |
178 | { .compatible = "ntc,ncp15wb473", | 222 | { .compatible = "ntc,ncp15wb473", |
@@ -490,6 +534,10 @@ static int ntc_thermistor_probe(struct platform_device *pdev) | |||
490 | data->comp = ncpXXwl333; | 534 | data->comp = ncpXXwl333; |
491 | data->n_comp = ARRAY_SIZE(ncpXXwl333); | 535 | data->n_comp = ARRAY_SIZE(ncpXXwl333); |
492 | break; | 536 | break; |
537 | case TYPE_B57330V2103: | ||
538 | data->comp = b57330v2103; | ||
539 | data->n_comp = ARRAY_SIZE(b57330v2103); | ||
540 | break; | ||
493 | default: | 541 | default: |
494 | dev_err(&pdev->dev, "Unknown device type: %lu(%s)\n", | 542 | dev_err(&pdev->dev, "Unknown device type: %lu(%s)\n", |
495 | pdev_id->driver_data, pdev_id->name); | 543 | pdev_id->driver_data, pdev_id->name); |
@@ -546,7 +594,7 @@ static struct platform_driver ntc_thermistor_driver = { | |||
546 | 594 | ||
547 | module_platform_driver(ntc_thermistor_driver); | 595 | module_platform_driver(ntc_thermistor_driver); |
548 | 596 | ||
549 | MODULE_DESCRIPTION("NTC Thermistor Driver from Murata"); | 597 | MODULE_DESCRIPTION("NTC Thermistor Driver"); |
550 | MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>"); | 598 | MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>"); |
551 | MODULE_LICENSE("GPL"); | 599 | MODULE_LICENSE("GPL"); |
552 | MODULE_ALIAS("platform:ntc-thermistor"); | 600 | MODULE_ALIAS("platform:ntc-thermistor"); |
diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig index 39cc63edfbb0..6e1e4935fc62 100644 --- a/drivers/hwmon/pmbus/Kconfig +++ b/drivers/hwmon/pmbus/Kconfig | |||
@@ -20,8 +20,7 @@ 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 | MDT040, NCP4200, NCP4208, PDT003, PDT006, PDT012, UDT020, TPS40400, | 23 | MDT040, NCP4200, NCP4208, PDT003, PDT006, PDT012, UDT020, and TPS40400. |
24 | and TPS40422. | ||
25 | 24 | ||
26 | This driver can also be built as a module. If so, the module will | 25 | This driver can also be built as a module. If so, the module will |
27 | be called pmbus. | 26 | be called pmbus. |
@@ -87,6 +86,16 @@ config SENSORS_MAX8688 | |||
87 | This driver can also be built as a module. If so, the module will | 86 | This driver can also be built as a module. If so, the module will |
88 | be called max8688. | 87 | be called max8688. |
89 | 88 | ||
89 | config SENSORS_TPS40422 | ||
90 | tristate "TI TPS40422" | ||
91 | default n | ||
92 | help | ||
93 | If you say yes here you get hardware monitoring support for TI | ||
94 | TPS40422. | ||
95 | |||
96 | This driver can also be built as a module. If so, the module will | ||
97 | be called tps40422. | ||
98 | |||
90 | config SENSORS_UCD9000 | 99 | config SENSORS_UCD9000 |
91 | tristate "TI UCD90120, UCD90124, UCD9090, UCD90910" | 100 | tristate "TI UCD90120, UCD90124, UCD9090, UCD90910" |
92 | default n | 101 | default n |
diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile index 789376c85dbb..1454293e985c 100644 --- a/drivers/hwmon/pmbus/Makefile +++ b/drivers/hwmon/pmbus/Makefile | |||
@@ -10,6 +10,7 @@ obj-$(CONFIG_SENSORS_LTC2978) += ltc2978.o | |||
10 | obj-$(CONFIG_SENSORS_MAX16064) += max16064.o | 10 | obj-$(CONFIG_SENSORS_MAX16064) += max16064.o |
11 | obj-$(CONFIG_SENSORS_MAX34440) += max34440.o | 11 | obj-$(CONFIG_SENSORS_MAX34440) += max34440.o |
12 | obj-$(CONFIG_SENSORS_MAX8688) += max8688.o | 12 | obj-$(CONFIG_SENSORS_MAX8688) += max8688.o |
13 | obj-$(CONFIG_SENSORS_TPS40422) += tps40422.o | ||
13 | obj-$(CONFIG_SENSORS_UCD9000) += ucd9000.o | 14 | obj-$(CONFIG_SENSORS_UCD9000) += ucd9000.o |
14 | obj-$(CONFIG_SENSORS_UCD9200) += ucd9200.o | 15 | obj-$(CONFIG_SENSORS_UCD9200) += ucd9200.o |
15 | obj-$(CONFIG_SENSORS_ZL6100) += zl6100.o | 16 | obj-$(CONFIG_SENSORS_ZL6100) += zl6100.o |
diff --git a/drivers/hwmon/pmbus/pmbus.c b/drivers/hwmon/pmbus/pmbus.c index 7e91700131a7..554d0249dcde 100644 --- a/drivers/hwmon/pmbus/pmbus.c +++ b/drivers/hwmon/pmbus/pmbus.c | |||
@@ -193,7 +193,6 @@ static const struct i2c_device_id pmbus_id[] = { | |||
193 | {"pdt012", 1}, | 193 | {"pdt012", 1}, |
194 | {"pmbus", 0}, | 194 | {"pmbus", 0}, |
195 | {"tps40400", 1}, | 195 | {"tps40400", 1}, |
196 | {"tps40422", 2}, | ||
197 | {"udt020", 1}, | 196 | {"udt020", 1}, |
198 | {} | 197 | {} |
199 | }; | 198 | }; |
diff --git a/drivers/hwmon/pmbus/tps40422.c b/drivers/hwmon/pmbus/tps40422.c new file mode 100644 index 000000000000..32803825d47e --- /dev/null +++ b/drivers/hwmon/pmbus/tps40422.c | |||
@@ -0,0 +1,64 @@ | |||
1 | /* | ||
2 | * Hardware monitoring driver for TI TPS40422 | ||
3 | * | ||
4 | * Copyright (c) 2014 Nokia Solutions and Networks. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | */ | ||
16 | |||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/init.h> | ||
20 | #include <linux/err.h> | ||
21 | #include <linux/i2c.h> | ||
22 | #include "pmbus.h" | ||
23 | |||
24 | static struct pmbus_driver_info tps40422_info = { | ||
25 | .pages = 2, | ||
26 | .format[PSC_VOLTAGE_IN] = linear, | ||
27 | .format[PSC_VOLTAGE_OUT] = linear, | ||
28 | .format[PSC_TEMPERATURE] = linear, | ||
29 | .func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_TEMP2 | ||
30 | | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_TEMP | ||
31 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT, | ||
32 | .func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_TEMP2 | ||
33 | | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_TEMP | ||
34 | | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT, | ||
35 | }; | ||
36 | |||
37 | static int tps40422_probe(struct i2c_client *client, | ||
38 | const struct i2c_device_id *id) | ||
39 | { | ||
40 | return pmbus_do_probe(client, id, &tps40422_info); | ||
41 | } | ||
42 | |||
43 | static const struct i2c_device_id tps40422_id[] = { | ||
44 | {"tps40422", 0}, | ||
45 | {} | ||
46 | }; | ||
47 | |||
48 | MODULE_DEVICE_TABLE(i2c, tps40422_id); | ||
49 | |||
50 | /* This is the driver that will be inserted */ | ||
51 | static struct i2c_driver tps40422_driver = { | ||
52 | .driver = { | ||
53 | .name = "tps40422", | ||
54 | }, | ||
55 | .probe = tps40422_probe, | ||
56 | .remove = pmbus_do_remove, | ||
57 | .id_table = tps40422_id, | ||
58 | }; | ||
59 | |||
60 | module_i2c_driver(tps40422_driver); | ||
61 | |||
62 | MODULE_AUTHOR("Zhu Laiwen <richard.zhu@nsn.com>"); | ||
63 | MODULE_DESCRIPTION("PMBus driver for TI TPS40422"); | ||
64 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/hwmon/powr1220.c b/drivers/hwmon/powr1220.c new file mode 100644 index 000000000000..3014e4ac741e --- /dev/null +++ b/drivers/hwmon/powr1220.c | |||
@@ -0,0 +1,391 @@ | |||
1 | /* | ||
2 | * powr1220.c - Driver for the Lattice POWR1220 programmable power supply | ||
3 | * and monitor. Users can read all ADC inputs along with their labels | ||
4 | * using the sysfs nodes. | ||
5 | * | ||
6 | * Copyright (c) 2014 Echo360 http://www.echo360.com | ||
7 | * Scott Kanowitz <skanowitz@echo360.com> <scott.kanowitz@gmail.com> | ||
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 | |||
20 | #include <linux/module.h> | ||
21 | #include <linux/init.h> | ||
22 | #include <linux/slab.h> | ||
23 | #include <linux/jiffies.h> | ||
24 | #include <linux/i2c.h> | ||
25 | #include <linux/hwmon.h> | ||
26 | #include <linux/hwmon-sysfs.h> | ||
27 | #include <linux/err.h> | ||
28 | #include <linux/mutex.h> | ||
29 | #include <linux/delay.h> | ||
30 | |||
31 | #define ADC_STEP_MV 2 | ||
32 | #define ADC_MAX_LOW_MEASUREMENT_MV 2000 | ||
33 | |||
34 | enum powr1220_regs { | ||
35 | VMON_STATUS0, | ||
36 | VMON_STATUS1, | ||
37 | VMON_STATUS2, | ||
38 | OUTPUT_STATUS0, | ||
39 | OUTPUT_STATUS1, | ||
40 | OUTPUT_STATUS2, | ||
41 | INPUT_STATUS, | ||
42 | ADC_VALUE_LOW, | ||
43 | ADC_VALUE_HIGH, | ||
44 | ADC_MUX, | ||
45 | UES_BYTE0, | ||
46 | UES_BYTE1, | ||
47 | UES_BYTE2, | ||
48 | UES_BYTE3, | ||
49 | GP_OUTPUT1, | ||
50 | GP_OUTPUT2, | ||
51 | GP_OUTPUT3, | ||
52 | INPUT_VALUE, | ||
53 | RESET, | ||
54 | TRIM1_TRIM, | ||
55 | TRIM2_TRIM, | ||
56 | TRIM3_TRIM, | ||
57 | TRIM4_TRIM, | ||
58 | TRIM5_TRIM, | ||
59 | TRIM6_TRIM, | ||
60 | TRIM7_TRIM, | ||
61 | TRIM8_TRIM, | ||
62 | MAX_POWR1220_REGS | ||
63 | }; | ||
64 | |||
65 | enum powr1220_adc_values { | ||
66 | VMON1, | ||
67 | VMON2, | ||
68 | VMON3, | ||
69 | VMON4, | ||
70 | VMON5, | ||
71 | VMON6, | ||
72 | VMON7, | ||
73 | VMON8, | ||
74 | VMON9, | ||
75 | VMON10, | ||
76 | VMON11, | ||
77 | VMON12, | ||
78 | VCCA, | ||
79 | VCCINP, | ||
80 | MAX_POWR1220_ADC_VALUES | ||
81 | }; | ||
82 | |||
83 | struct powr1220_data { | ||
84 | struct i2c_client *client; | ||
85 | struct mutex update_lock; | ||
86 | bool adc_valid[MAX_POWR1220_ADC_VALUES]; | ||
87 | /* the next value is in jiffies */ | ||
88 | unsigned long adc_last_updated[MAX_POWR1220_ADC_VALUES]; | ||
89 | |||
90 | /* values */ | ||
91 | int adc_maxes[MAX_POWR1220_ADC_VALUES]; | ||
92 | int adc_values[MAX_POWR1220_ADC_VALUES]; | ||
93 | }; | ||
94 | |||
95 | static const char * const input_names[] = { | ||
96 | [VMON1] = "vmon1", | ||
97 | [VMON2] = "vmon2", | ||
98 | [VMON3] = "vmon3", | ||
99 | [VMON4] = "vmon4", | ||
100 | [VMON5] = "vmon5", | ||
101 | [VMON6] = "vmon6", | ||
102 | [VMON7] = "vmon7", | ||
103 | [VMON8] = "vmon8", | ||
104 | [VMON9] = "vmon9", | ||
105 | [VMON10] = "vmon10", | ||
106 | [VMON11] = "vmon11", | ||
107 | [VMON12] = "vmon12", | ||
108 | [VCCA] = "vcca", | ||
109 | [VCCINP] = "vccinp", | ||
110 | }; | ||
111 | |||
112 | /* Reads the specified ADC channel */ | ||
113 | static int powr1220_read_adc(struct device *dev, int ch_num) | ||
114 | { | ||
115 | struct powr1220_data *data = dev_get_drvdata(dev); | ||
116 | int reading; | ||
117 | int result; | ||
118 | int adc_range = 0; | ||
119 | |||
120 | mutex_lock(&data->update_lock); | ||
121 | |||
122 | if (time_after(jiffies, data->adc_last_updated[ch_num] + HZ) || | ||
123 | !data->adc_valid[ch_num]) { | ||
124 | /* | ||
125 | * figure out if we need to use the attenuator for | ||
126 | * high inputs or inputs that we don't yet have a measurement | ||
127 | * for. We dynamically set the attenuator depending on the | ||
128 | * max reading. | ||
129 | */ | ||
130 | if (data->adc_maxes[ch_num] > ADC_MAX_LOW_MEASUREMENT_MV || | ||
131 | data->adc_maxes[ch_num] == 0) | ||
132 | adc_range = 1 << 4; | ||
133 | |||
134 | /* set the attenuator and mux */ | ||
135 | result = i2c_smbus_write_byte_data(data->client, ADC_MUX, | ||
136 | adc_range | ch_num); | ||
137 | if (result) | ||
138 | goto exit; | ||
139 | |||
140 | /* | ||
141 | * wait at least Tconvert time (200 us) for the | ||
142 | * conversion to complete | ||
143 | */ | ||
144 | udelay(200); | ||
145 | |||
146 | /* get the ADC reading */ | ||
147 | result = i2c_smbus_read_byte_data(data->client, ADC_VALUE_LOW); | ||
148 | if (result < 0) | ||
149 | goto exit; | ||
150 | |||
151 | reading = result >> 4; | ||
152 | |||
153 | /* get the upper half of the reading */ | ||
154 | result = i2c_smbus_read_byte_data(data->client, ADC_VALUE_HIGH); | ||
155 | if (result < 0) | ||
156 | goto exit; | ||
157 | |||
158 | reading |= result << 4; | ||
159 | |||
160 | /* now convert the reading to a voltage */ | ||
161 | reading *= ADC_STEP_MV; | ||
162 | data->adc_values[ch_num] = reading; | ||
163 | data->adc_valid[ch_num] = true; | ||
164 | data->adc_last_updated[ch_num] = jiffies; | ||
165 | result = reading; | ||
166 | |||
167 | if (reading > data->adc_maxes[ch_num]) | ||
168 | data->adc_maxes[ch_num] = reading; | ||
169 | } else { | ||
170 | result = data->adc_values[ch_num]; | ||
171 | } | ||
172 | |||
173 | exit: | ||
174 | mutex_unlock(&data->update_lock); | ||
175 | |||
176 | return result; | ||
177 | } | ||
178 | |||
179 | /* Shows the voltage associated with the specified ADC channel */ | ||
180 | static ssize_t powr1220_show_voltage(struct device *dev, | ||
181 | struct device_attribute *dev_attr, char *buf) | ||
182 | { | ||
183 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); | ||
184 | int adc_val = powr1220_read_adc(dev, attr->index); | ||
185 | |||
186 | if (adc_val < 0) | ||
187 | return adc_val; | ||
188 | |||
189 | return sprintf(buf, "%d\n", adc_val); | ||
190 | } | ||
191 | |||
192 | /* Shows the maximum setting associated with the specified ADC channel */ | ||
193 | static ssize_t powr1220_show_max(struct device *dev, | ||
194 | struct device_attribute *dev_attr, char *buf) | ||
195 | { | ||
196 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); | ||
197 | struct powr1220_data *data = dev_get_drvdata(dev); | ||
198 | |||
199 | return sprintf(buf, "%d\n", data->adc_maxes[attr->index]); | ||
200 | } | ||
201 | |||
202 | /* Shows the label associated with the specified ADC channel */ | ||
203 | static ssize_t powr1220_show_label(struct device *dev, | ||
204 | struct device_attribute *dev_attr, char *buf) | ||
205 | { | ||
206 | struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); | ||
207 | |||
208 | return sprintf(buf, "%s\n", input_names[attr->index]); | ||
209 | } | ||
210 | |||
211 | static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, powr1220_show_voltage, NULL, | ||
212 | VMON1); | ||
213 | static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, powr1220_show_voltage, NULL, | ||
214 | VMON2); | ||
215 | static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, powr1220_show_voltage, NULL, | ||
216 | VMON3); | ||
217 | static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, powr1220_show_voltage, NULL, | ||
218 | VMON4); | ||
219 | static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, powr1220_show_voltage, NULL, | ||
220 | VMON5); | ||
221 | static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, powr1220_show_voltage, NULL, | ||
222 | VMON6); | ||
223 | static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, powr1220_show_voltage, NULL, | ||
224 | VMON7); | ||
225 | static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, powr1220_show_voltage, NULL, | ||
226 | VMON8); | ||
227 | static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, powr1220_show_voltage, NULL, | ||
228 | VMON9); | ||
229 | static SENSOR_DEVICE_ATTR(in9_input, S_IRUGO, powr1220_show_voltage, NULL, | ||
230 | VMON10); | ||
231 | static SENSOR_DEVICE_ATTR(in10_input, S_IRUGO, powr1220_show_voltage, NULL, | ||
232 | VMON11); | ||
233 | static SENSOR_DEVICE_ATTR(in11_input, S_IRUGO, powr1220_show_voltage, NULL, | ||
234 | VMON12); | ||
235 | static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, powr1220_show_voltage, NULL, | ||
236 | VCCA); | ||
237 | static SENSOR_DEVICE_ATTR(in13_input, S_IRUGO, powr1220_show_voltage, NULL, | ||
238 | VCCINP); | ||
239 | |||
240 | static SENSOR_DEVICE_ATTR(in0_highest, S_IRUGO, powr1220_show_max, NULL, | ||
241 | VMON1); | ||
242 | static SENSOR_DEVICE_ATTR(in1_highest, S_IRUGO, powr1220_show_max, NULL, | ||
243 | VMON2); | ||
244 | static SENSOR_DEVICE_ATTR(in2_highest, S_IRUGO, powr1220_show_max, NULL, | ||
245 | VMON3); | ||
246 | static SENSOR_DEVICE_ATTR(in3_highest, S_IRUGO, powr1220_show_max, NULL, | ||
247 | VMON4); | ||
248 | static SENSOR_DEVICE_ATTR(in4_highest, S_IRUGO, powr1220_show_max, NULL, | ||
249 | VMON5); | ||
250 | static SENSOR_DEVICE_ATTR(in5_highest, S_IRUGO, powr1220_show_max, NULL, | ||
251 | VMON6); | ||
252 | static SENSOR_DEVICE_ATTR(in6_highest, S_IRUGO, powr1220_show_max, NULL, | ||
253 | VMON7); | ||
254 | static SENSOR_DEVICE_ATTR(in7_highest, S_IRUGO, powr1220_show_max, NULL, | ||
255 | VMON8); | ||
256 | static SENSOR_DEVICE_ATTR(in8_highest, S_IRUGO, powr1220_show_max, NULL, | ||
257 | VMON9); | ||
258 | static SENSOR_DEVICE_ATTR(in9_highest, S_IRUGO, powr1220_show_max, NULL, | ||
259 | VMON10); | ||
260 | static SENSOR_DEVICE_ATTR(in10_highest, S_IRUGO, powr1220_show_max, NULL, | ||
261 | VMON11); | ||
262 | static SENSOR_DEVICE_ATTR(in11_highest, S_IRUGO, powr1220_show_max, NULL, | ||
263 | VMON12); | ||
264 | static SENSOR_DEVICE_ATTR(in12_highest, S_IRUGO, powr1220_show_max, NULL, | ||
265 | VCCA); | ||
266 | static SENSOR_DEVICE_ATTR(in13_highest, S_IRUGO, powr1220_show_max, NULL, | ||
267 | VCCINP); | ||
268 | |||
269 | static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO, powr1220_show_label, NULL, | ||
270 | VMON1); | ||
271 | static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO, powr1220_show_label, NULL, | ||
272 | VMON2); | ||
273 | static SENSOR_DEVICE_ATTR(in2_label, S_IRUGO, powr1220_show_label, NULL, | ||
274 | VMON3); | ||
275 | static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, powr1220_show_label, NULL, | ||
276 | VMON4); | ||
277 | static SENSOR_DEVICE_ATTR(in4_label, S_IRUGO, powr1220_show_label, NULL, | ||
278 | VMON5); | ||
279 | static SENSOR_DEVICE_ATTR(in5_label, S_IRUGO, powr1220_show_label, NULL, | ||
280 | VMON6); | ||
281 | static SENSOR_DEVICE_ATTR(in6_label, S_IRUGO, powr1220_show_label, NULL, | ||
282 | VMON7); | ||
283 | static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, powr1220_show_label, NULL, | ||
284 | VMON8); | ||
285 | static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, powr1220_show_label, NULL, | ||
286 | VMON9); | ||
287 | static SENSOR_DEVICE_ATTR(in9_label, S_IRUGO, powr1220_show_label, NULL, | ||
288 | VMON10); | ||
289 | static SENSOR_DEVICE_ATTR(in10_label, S_IRUGO, powr1220_show_label, NULL, | ||
290 | VMON11); | ||
291 | static SENSOR_DEVICE_ATTR(in11_label, S_IRUGO, powr1220_show_label, NULL, | ||
292 | VMON12); | ||
293 | static SENSOR_DEVICE_ATTR(in12_label, S_IRUGO, powr1220_show_label, NULL, | ||
294 | VCCA); | ||
295 | static SENSOR_DEVICE_ATTR(in13_label, S_IRUGO, powr1220_show_label, NULL, | ||
296 | VCCINP); | ||
297 | |||
298 | static struct attribute *powr1220_attrs[] = { | ||
299 | &sensor_dev_attr_in0_input.dev_attr.attr, | ||
300 | &sensor_dev_attr_in1_input.dev_attr.attr, | ||
301 | &sensor_dev_attr_in2_input.dev_attr.attr, | ||
302 | &sensor_dev_attr_in3_input.dev_attr.attr, | ||
303 | &sensor_dev_attr_in4_input.dev_attr.attr, | ||
304 | &sensor_dev_attr_in5_input.dev_attr.attr, | ||
305 | &sensor_dev_attr_in6_input.dev_attr.attr, | ||
306 | &sensor_dev_attr_in7_input.dev_attr.attr, | ||
307 | &sensor_dev_attr_in8_input.dev_attr.attr, | ||
308 | &sensor_dev_attr_in9_input.dev_attr.attr, | ||
309 | &sensor_dev_attr_in10_input.dev_attr.attr, | ||
310 | &sensor_dev_attr_in11_input.dev_attr.attr, | ||
311 | &sensor_dev_attr_in12_input.dev_attr.attr, | ||
312 | &sensor_dev_attr_in13_input.dev_attr.attr, | ||
313 | |||
314 | &sensor_dev_attr_in0_highest.dev_attr.attr, | ||
315 | &sensor_dev_attr_in1_highest.dev_attr.attr, | ||
316 | &sensor_dev_attr_in2_highest.dev_attr.attr, | ||
317 | &sensor_dev_attr_in3_highest.dev_attr.attr, | ||
318 | &sensor_dev_attr_in4_highest.dev_attr.attr, | ||
319 | &sensor_dev_attr_in5_highest.dev_attr.attr, | ||
320 | &sensor_dev_attr_in6_highest.dev_attr.attr, | ||
321 | &sensor_dev_attr_in7_highest.dev_attr.attr, | ||
322 | &sensor_dev_attr_in8_highest.dev_attr.attr, | ||
323 | &sensor_dev_attr_in9_highest.dev_attr.attr, | ||
324 | &sensor_dev_attr_in10_highest.dev_attr.attr, | ||
325 | &sensor_dev_attr_in11_highest.dev_attr.attr, | ||
326 | &sensor_dev_attr_in12_highest.dev_attr.attr, | ||
327 | &sensor_dev_attr_in13_highest.dev_attr.attr, | ||
328 | |||
329 | &sensor_dev_attr_in0_label.dev_attr.attr, | ||
330 | &sensor_dev_attr_in1_label.dev_attr.attr, | ||
331 | &sensor_dev_attr_in2_label.dev_attr.attr, | ||
332 | &sensor_dev_attr_in3_label.dev_attr.attr, | ||
333 | &sensor_dev_attr_in4_label.dev_attr.attr, | ||
334 | &sensor_dev_attr_in5_label.dev_attr.attr, | ||
335 | &sensor_dev_attr_in6_label.dev_attr.attr, | ||
336 | &sensor_dev_attr_in7_label.dev_attr.attr, | ||
337 | &sensor_dev_attr_in8_label.dev_attr.attr, | ||
338 | &sensor_dev_attr_in9_label.dev_attr.attr, | ||
339 | &sensor_dev_attr_in10_label.dev_attr.attr, | ||
340 | &sensor_dev_attr_in11_label.dev_attr.attr, | ||
341 | &sensor_dev_attr_in12_label.dev_attr.attr, | ||
342 | &sensor_dev_attr_in13_label.dev_attr.attr, | ||
343 | |||
344 | NULL | ||
345 | }; | ||
346 | |||
347 | ATTRIBUTE_GROUPS(powr1220); | ||
348 | |||
349 | static int powr1220_probe(struct i2c_client *client, | ||
350 | const struct i2c_device_id *id) | ||
351 | { | ||
352 | struct powr1220_data *data; | ||
353 | struct device *hwmon_dev; | ||
354 | |||
355 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | ||
356 | return -ENODEV; | ||
357 | |||
358 | data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); | ||
359 | if (!data) | ||
360 | return -ENOMEM; | ||
361 | |||
362 | mutex_init(&data->update_lock); | ||
363 | data->client = client; | ||
364 | |||
365 | hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev, | ||
366 | client->name, data, powr1220_groups); | ||
367 | |||
368 | return PTR_ERR_OR_ZERO(hwmon_dev); | ||
369 | } | ||
370 | |||
371 | static const struct i2c_device_id powr1220_ids[] = { | ||
372 | { "powr1220", 0, }, | ||
373 | { } | ||
374 | }; | ||
375 | |||
376 | MODULE_DEVICE_TABLE(i2c, powr1220_ids); | ||
377 | |||
378 | static struct i2c_driver powr1220_driver = { | ||
379 | .class = I2C_CLASS_HWMON, | ||
380 | .driver = { | ||
381 | .name = "powr1220", | ||
382 | }, | ||
383 | .probe = powr1220_probe, | ||
384 | .id_table = powr1220_ids, | ||
385 | }; | ||
386 | |||
387 | module_i2c_driver(powr1220_driver); | ||
388 | |||
389 | MODULE_AUTHOR("Scott Kanowitz"); | ||
390 | MODULE_DESCRIPTION("POWR1220 driver"); | ||
391 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c new file mode 100644 index 000000000000..823c877a1ec0 --- /dev/null +++ b/drivers/hwmon/pwm-fan.c | |||
@@ -0,0 +1,193 @@ | |||
1 | /* | ||
2 | * pwm-fan.c - Hwmon driver for fans connected to PWM lines. | ||
3 | * | ||
4 | * Copyright (c) 2014 Samsung Electronics Co., Ltd. | ||
5 | * | ||
6 | * Author: Kamil Debski <k.debski@samsung.com> | ||
7 | * | ||
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 | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | */ | ||
18 | |||
19 | #include <linux/hwmon.h> | ||
20 | #include <linux/hwmon-sysfs.h> | ||
21 | #include <linux/module.h> | ||
22 | #include <linux/mutex.h> | ||
23 | #include <linux/of.h> | ||
24 | #include <linux/platform_device.h> | ||
25 | #include <linux/pwm.h> | ||
26 | #include <linux/sysfs.h> | ||
27 | |||
28 | #define MAX_PWM 255 | ||
29 | |||
30 | struct pwm_fan_ctx { | ||
31 | struct mutex lock; | ||
32 | struct pwm_device *pwm; | ||
33 | unsigned char pwm_value; | ||
34 | }; | ||
35 | |||
36 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | ||
37 | const char *buf, size_t count) | ||
38 | { | ||
39 | struct pwm_fan_ctx *ctx = dev_get_drvdata(dev); | ||
40 | unsigned long pwm, duty; | ||
41 | ssize_t ret; | ||
42 | |||
43 | if (kstrtoul(buf, 10, &pwm) || pwm > MAX_PWM) | ||
44 | return -EINVAL; | ||
45 | |||
46 | mutex_lock(&ctx->lock); | ||
47 | |||
48 | if (ctx->pwm_value == pwm) | ||
49 | goto exit_set_pwm_no_change; | ||
50 | |||
51 | if (pwm == 0) { | ||
52 | pwm_disable(ctx->pwm); | ||
53 | goto exit_set_pwm; | ||
54 | } | ||
55 | |||
56 | duty = DIV_ROUND_UP(pwm * (ctx->pwm->period - 1), MAX_PWM); | ||
57 | ret = pwm_config(ctx->pwm, duty, ctx->pwm->period); | ||
58 | if (ret) | ||
59 | goto exit_set_pwm_err; | ||
60 | |||
61 | if (ctx->pwm_value == 0) { | ||
62 | ret = pwm_enable(ctx->pwm); | ||
63 | if (ret) | ||
64 | goto exit_set_pwm_err; | ||
65 | } | ||
66 | |||
67 | exit_set_pwm: | ||
68 | ctx->pwm_value = pwm; | ||
69 | exit_set_pwm_no_change: | ||
70 | ret = count; | ||
71 | exit_set_pwm_err: | ||
72 | mutex_unlock(&ctx->lock); | ||
73 | return ret; | ||
74 | } | ||
75 | |||
76 | static ssize_t show_pwm(struct device *dev, | ||
77 | struct device_attribute *attr, char *buf) | ||
78 | { | ||
79 | struct pwm_fan_ctx *ctx = dev_get_drvdata(dev); | ||
80 | |||
81 | return sprintf(buf, "%u\n", ctx->pwm_value); | ||
82 | } | ||
83 | |||
84 | |||
85 | static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0); | ||
86 | |||
87 | static struct attribute *pwm_fan_attrs[] = { | ||
88 | &sensor_dev_attr_pwm1.dev_attr.attr, | ||
89 | NULL, | ||
90 | }; | ||
91 | |||
92 | ATTRIBUTE_GROUPS(pwm_fan); | ||
93 | |||
94 | static int pwm_fan_probe(struct platform_device *pdev) | ||
95 | { | ||
96 | struct device *hwmon; | ||
97 | struct pwm_fan_ctx *ctx; | ||
98 | int duty_cycle; | ||
99 | int ret; | ||
100 | |||
101 | ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); | ||
102 | if (!ctx) | ||
103 | return -ENOMEM; | ||
104 | |||
105 | mutex_init(&ctx->lock); | ||
106 | |||
107 | ctx->pwm = devm_of_pwm_get(&pdev->dev, pdev->dev.of_node, NULL); | ||
108 | if (IS_ERR(ctx->pwm)) { | ||
109 | dev_err(&pdev->dev, "Could not get PWM\n"); | ||
110 | return PTR_ERR(ctx->pwm); | ||
111 | } | ||
112 | |||
113 | platform_set_drvdata(pdev, ctx); | ||
114 | |||
115 | /* Set duty cycle to maximum allowed */ | ||
116 | duty_cycle = ctx->pwm->period - 1; | ||
117 | ctx->pwm_value = MAX_PWM; | ||
118 | |||
119 | ret = pwm_config(ctx->pwm, duty_cycle, ctx->pwm->period); | ||
120 | if (ret) { | ||
121 | dev_err(&pdev->dev, "Failed to configure PWM\n"); | ||
122 | return ret; | ||
123 | } | ||
124 | |||
125 | /* Enbale PWM output */ | ||
126 | ret = pwm_enable(ctx->pwm); | ||
127 | if (ret) { | ||
128 | dev_err(&pdev->dev, "Failed to enable PWM\n"); | ||
129 | return ret; | ||
130 | } | ||
131 | |||
132 | hwmon = devm_hwmon_device_register_with_groups(&pdev->dev, "pwmfan", | ||
133 | ctx, pwm_fan_groups); | ||
134 | if (IS_ERR(hwmon)) { | ||
135 | dev_err(&pdev->dev, "Failed to register hwmon device\n"); | ||
136 | pwm_disable(ctx->pwm); | ||
137 | return PTR_ERR(hwmon); | ||
138 | } | ||
139 | return 0; | ||
140 | } | ||
141 | |||
142 | static int pwm_fan_remove(struct platform_device *pdev) | ||
143 | { | ||
144 | struct pwm_fan_ctx *ctx = platform_get_drvdata(pdev); | ||
145 | |||
146 | if (ctx->pwm_value) | ||
147 | pwm_disable(ctx->pwm); | ||
148 | return 0; | ||
149 | } | ||
150 | |||
151 | #ifdef CONFIG_PM_SLEEP | ||
152 | static int pwm_fan_suspend(struct device *dev) | ||
153 | { | ||
154 | struct pwm_fan_ctx *ctx = dev_get_drvdata(dev); | ||
155 | |||
156 | if (ctx->pwm_value) | ||
157 | pwm_disable(ctx->pwm); | ||
158 | return 0; | ||
159 | } | ||
160 | |||
161 | static int pwm_fan_resume(struct device *dev) | ||
162 | { | ||
163 | struct pwm_fan_ctx *ctx = dev_get_drvdata(dev); | ||
164 | |||
165 | if (ctx->pwm_value) | ||
166 | return pwm_enable(ctx->pwm); | ||
167 | return 0; | ||
168 | } | ||
169 | #endif | ||
170 | |||
171 | static SIMPLE_DEV_PM_OPS(pwm_fan_pm, pwm_fan_suspend, pwm_fan_resume); | ||
172 | |||
173 | static struct of_device_id of_pwm_fan_match[] = { | ||
174 | { .compatible = "pwm-fan", }, | ||
175 | {}, | ||
176 | }; | ||
177 | |||
178 | static struct platform_driver pwm_fan_driver = { | ||
179 | .probe = pwm_fan_probe, | ||
180 | .remove = pwm_fan_remove, | ||
181 | .driver = { | ||
182 | .name = "pwm-fan", | ||
183 | .pm = &pwm_fan_pm, | ||
184 | .of_match_table = of_pwm_fan_match, | ||
185 | }, | ||
186 | }; | ||
187 | |||
188 | module_platform_driver(pwm_fan_driver); | ||
189 | |||
190 | MODULE_AUTHOR("Kamil Debski <k.debski@samsung.com>"); | ||
191 | MODULE_ALIAS("platform:pwm-fan"); | ||
192 | MODULE_DESCRIPTION("PWM FAN driver"); | ||
193 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/hwmon/sht21.c b/drivers/hwmon/sht21.c index 2e9f9570b6f8..84cdb1cf0fb4 100644 --- a/drivers/hwmon/sht21.c +++ b/drivers/hwmon/sht21.c | |||
@@ -45,7 +45,7 @@ | |||
45 | * @humidity: cached humidity measurement value | 45 | * @humidity: cached humidity measurement value |
46 | */ | 46 | */ |
47 | struct sht21 { | 47 | struct sht21 { |
48 | struct device *hwmon_dev; | 48 | struct i2c_client *client; |
49 | struct mutex lock; | 49 | struct mutex lock; |
50 | char valid; | 50 | char valid; |
51 | unsigned long last_update; | 51 | unsigned long last_update; |
@@ -85,14 +85,15 @@ static inline int sht21_rh_ticks_to_per_cent_mille(int ticks) | |||
85 | 85 | ||
86 | /** | 86 | /** |
87 | * sht21_update_measurements() - get updated measurements from device | 87 | * sht21_update_measurements() - get updated measurements from device |
88 | * @client: I2C client device | 88 | * @dev: device |
89 | * | 89 | * |
90 | * Returns 0 on success, else negative errno. | 90 | * Returns 0 on success, else negative errno. |
91 | */ | 91 | */ |
92 | static int sht21_update_measurements(struct i2c_client *client) | 92 | static int sht21_update_measurements(struct device *dev) |
93 | { | 93 | { |
94 | int ret = 0; | 94 | int ret = 0; |
95 | struct sht21 *sht21 = i2c_get_clientdata(client); | 95 | struct sht21 *sht21 = dev_get_drvdata(dev); |
96 | struct i2c_client *client = sht21->client; | ||
96 | 97 | ||
97 | mutex_lock(&sht21->lock); | 98 | mutex_lock(&sht21->lock); |
98 | /* | 99 | /* |
@@ -133,9 +134,10 @@ static ssize_t sht21_show_temperature(struct device *dev, | |||
133 | struct device_attribute *attr, | 134 | struct device_attribute *attr, |
134 | char *buf) | 135 | char *buf) |
135 | { | 136 | { |
136 | struct i2c_client *client = to_i2c_client(dev); | 137 | struct sht21 *sht21 = dev_get_drvdata(dev); |
137 | struct sht21 *sht21 = i2c_get_clientdata(client); | 138 | int ret; |
138 | int ret = sht21_update_measurements(client); | 139 | |
140 | ret = sht21_update_measurements(dev); | ||
139 | if (ret < 0) | 141 | if (ret < 0) |
140 | return ret; | 142 | return ret; |
141 | return sprintf(buf, "%d\n", sht21->temperature); | 143 | return sprintf(buf, "%d\n", sht21->temperature); |
@@ -154,9 +156,10 @@ static ssize_t sht21_show_humidity(struct device *dev, | |||
154 | struct device_attribute *attr, | 156 | struct device_attribute *attr, |
155 | char *buf) | 157 | char *buf) |
156 | { | 158 | { |
157 | struct i2c_client *client = to_i2c_client(dev); | 159 | struct sht21 *sht21 = dev_get_drvdata(dev); |
158 | struct sht21 *sht21 = i2c_get_clientdata(client); | 160 | int ret; |
159 | int ret = sht21_update_measurements(client); | 161 | |
162 | ret = sht21_update_measurements(dev); | ||
160 | if (ret < 0) | 163 | if (ret < 0) |
161 | return ret; | 164 | return ret; |
162 | return sprintf(buf, "%d\n", sht21->humidity); | 165 | return sprintf(buf, "%d\n", sht21->humidity); |
@@ -168,30 +171,20 @@ static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, sht21_show_temperature, | |||
168 | static SENSOR_DEVICE_ATTR(humidity1_input, S_IRUGO, sht21_show_humidity, | 171 | static SENSOR_DEVICE_ATTR(humidity1_input, S_IRUGO, sht21_show_humidity, |
169 | NULL, 0); | 172 | NULL, 0); |
170 | 173 | ||
171 | static struct attribute *sht21_attributes[] = { | 174 | static struct attribute *sht21_attrs[] = { |
172 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 175 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
173 | &sensor_dev_attr_humidity1_input.dev_attr.attr, | 176 | &sensor_dev_attr_humidity1_input.dev_attr.attr, |
174 | NULL | 177 | NULL |
175 | }; | 178 | }; |
176 | 179 | ||
177 | static const struct attribute_group sht21_attr_group = { | 180 | ATTRIBUTE_GROUPS(sht21); |
178 | .attrs = sht21_attributes, | ||
179 | }; | ||
180 | 181 | ||
181 | /** | ||
182 | * sht21_probe() - probe device | ||
183 | * @client: I2C client device | ||
184 | * @id: device ID | ||
185 | * | ||
186 | * Called by the I2C core when an entry in the ID table matches a | ||
187 | * device's name. | ||
188 | * Returns 0 on success. | ||
189 | */ | ||
190 | static int sht21_probe(struct i2c_client *client, | 182 | static int sht21_probe(struct i2c_client *client, |
191 | const struct i2c_device_id *id) | 183 | const struct i2c_device_id *id) |
192 | { | 184 | { |
185 | struct device *dev = &client->dev; | ||
186 | struct device *hwmon_dev; | ||
193 | struct sht21 *sht21; | 187 | struct sht21 *sht21; |
194 | int err; | ||
195 | 188 | ||
196 | if (!i2c_check_functionality(client->adapter, | 189 | if (!i2c_check_functionality(client->adapter, |
197 | I2C_FUNC_SMBUS_WORD_DATA)) { | 190 | I2C_FUNC_SMBUS_WORD_DATA)) { |
@@ -200,47 +193,17 @@ static int sht21_probe(struct i2c_client *client, | |||
200 | return -ENODEV; | 193 | return -ENODEV; |
201 | } | 194 | } |
202 | 195 | ||
203 | sht21 = devm_kzalloc(&client->dev, sizeof(*sht21), GFP_KERNEL); | 196 | sht21 = devm_kzalloc(dev, sizeof(*sht21), GFP_KERNEL); |
204 | if (!sht21) | 197 | if (!sht21) |
205 | return -ENOMEM; | 198 | return -ENOMEM; |
206 | 199 | ||
207 | i2c_set_clientdata(client, sht21); | 200 | sht21->client = client; |
208 | 201 | ||
209 | mutex_init(&sht21->lock); | 202 | mutex_init(&sht21->lock); |
210 | 203 | ||
211 | err = sysfs_create_group(&client->dev.kobj, &sht21_attr_group); | 204 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
212 | if (err) { | 205 | sht21, sht21_groups); |
213 | dev_dbg(&client->dev, "could not create sysfs files\n"); | 206 | return PTR_ERR_OR_ZERO(hwmon_dev); |
214 | return err; | ||
215 | } | ||
216 | sht21->hwmon_dev = hwmon_device_register(&client->dev); | ||
217 | if (IS_ERR(sht21->hwmon_dev)) { | ||
218 | dev_dbg(&client->dev, "unable to register hwmon device\n"); | ||
219 | err = PTR_ERR(sht21->hwmon_dev); | ||
220 | goto fail_remove_sysfs; | ||
221 | } | ||
222 | |||
223 | dev_info(&client->dev, "initialized\n"); | ||
224 | |||
225 | return 0; | ||
226 | |||
227 | fail_remove_sysfs: | ||
228 | sysfs_remove_group(&client->dev.kobj, &sht21_attr_group); | ||
229 | return err; | ||
230 | } | ||
231 | |||
232 | /** | ||
233 | * sht21_remove() - remove device | ||
234 | * @client: I2C client device | ||
235 | */ | ||
236 | static int sht21_remove(struct i2c_client *client) | ||
237 | { | ||
238 | struct sht21 *sht21 = i2c_get_clientdata(client); | ||
239 | |||
240 | hwmon_device_unregister(sht21->hwmon_dev); | ||
241 | sysfs_remove_group(&client->dev.kobj, &sht21_attr_group); | ||
242 | |||
243 | return 0; | ||
244 | } | 207 | } |
245 | 208 | ||
246 | /* Device ID table */ | 209 | /* Device ID table */ |
@@ -253,7 +216,6 @@ MODULE_DEVICE_TABLE(i2c, sht21_id); | |||
253 | static struct i2c_driver sht21_driver = { | 216 | static struct i2c_driver sht21_driver = { |
254 | .driver.name = "sht21", | 217 | .driver.name = "sht21", |
255 | .probe = sht21_probe, | 218 | .probe = sht21_probe, |
256 | .remove = sht21_remove, | ||
257 | .id_table = sht21_id, | 219 | .id_table = sht21_id, |
258 | }; | 220 | }; |
259 | 221 | ||
diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c index 3532026e25da..bf1d7893d51c 100644 --- a/drivers/hwmon/sis5595.c +++ b/drivers/hwmon/sis5595.c | |||
@@ -159,7 +159,7 @@ static inline int TEMP_FROM_REG(s8 val) | |||
159 | { | 159 | { |
160 | return val * 830 + 52120; | 160 | return val * 830 + 52120; |
161 | } | 161 | } |
162 | static inline s8 TEMP_TO_REG(int val) | 162 | static inline s8 TEMP_TO_REG(long val) |
163 | { | 163 | { |
164 | int nval = clamp_val(val, -54120, 157530) ; | 164 | int nval = clamp_val(val, -54120, 157530) ; |
165 | return nval < 0 ? (nval - 5212 - 415) / 830 : (nval - 5212 + 415) / 830; | 165 | return nval < 0 ? (nval - 5212 - 415) / 830 : (nval - 5212 + 415) / 830; |
diff --git a/drivers/hwmon/smm665.c b/drivers/hwmon/smm665.c index 4ef5802df6d8..627c9c3a8255 100644 --- a/drivers/hwmon/smm665.c +++ b/drivers/hwmon/smm665.c | |||
@@ -140,7 +140,7 @@ enum chips { smm465, smm665, smm665c, smm764, smm766 }; | |||
140 | struct smm665_data { | 140 | struct smm665_data { |
141 | enum chips type; | 141 | enum chips type; |
142 | int conversion_time; /* ADC conversion time */ | 142 | int conversion_time; /* ADC conversion time */ |
143 | struct device *hwmon_dev; | 143 | struct i2c_client *client; |
144 | struct mutex update_lock; | 144 | struct mutex update_lock; |
145 | bool valid; | 145 | bool valid; |
146 | unsigned long last_updated; /* in jiffies */ | 146 | unsigned long last_updated; /* in jiffies */ |
@@ -239,8 +239,8 @@ static int smm665_read_adc(struct smm665_data *data, int adc) | |||
239 | 239 | ||
240 | static struct smm665_data *smm665_update_device(struct device *dev) | 240 | static struct smm665_data *smm665_update_device(struct device *dev) |
241 | { | 241 | { |
242 | struct i2c_client *client = to_i2c_client(dev); | 242 | struct smm665_data *data = dev_get_drvdata(dev); |
243 | struct smm665_data *data = i2c_get_clientdata(client); | 243 | struct i2c_client *client = data->client; |
244 | struct smm665_data *ret = data; | 244 | struct smm665_data *ret = data; |
245 | 245 | ||
246 | mutex_lock(&data->update_lock); | 246 | mutex_lock(&data->update_lock); |
@@ -315,32 +315,28 @@ static int smm665_convert(u16 adcval, int index) | |||
315 | 315 | ||
316 | static int smm665_get_min(struct device *dev, int index) | 316 | static int smm665_get_min(struct device *dev, int index) |
317 | { | 317 | { |
318 | struct i2c_client *client = to_i2c_client(dev); | 318 | struct smm665_data *data = dev_get_drvdata(dev); |
319 | struct smm665_data *data = i2c_get_clientdata(client); | ||
320 | 319 | ||
321 | return data->alarm_min_limit[index]; | 320 | return data->alarm_min_limit[index]; |
322 | } | 321 | } |
323 | 322 | ||
324 | static int smm665_get_max(struct device *dev, int index) | 323 | static int smm665_get_max(struct device *dev, int index) |
325 | { | 324 | { |
326 | struct i2c_client *client = to_i2c_client(dev); | 325 | struct smm665_data *data = dev_get_drvdata(dev); |
327 | struct smm665_data *data = i2c_get_clientdata(client); | ||
328 | 326 | ||
329 | return data->alarm_max_limit[index]; | 327 | return data->alarm_max_limit[index]; |
330 | } | 328 | } |
331 | 329 | ||
332 | static int smm665_get_lcrit(struct device *dev, int index) | 330 | static int smm665_get_lcrit(struct device *dev, int index) |
333 | { | 331 | { |
334 | struct i2c_client *client = to_i2c_client(dev); | 332 | struct smm665_data *data = dev_get_drvdata(dev); |
335 | struct smm665_data *data = i2c_get_clientdata(client); | ||
336 | 333 | ||
337 | return data->critical_min_limit[index]; | 334 | return data->critical_min_limit[index]; |
338 | } | 335 | } |
339 | 336 | ||
340 | static int smm665_get_crit(struct device *dev, int index) | 337 | static int smm665_get_crit(struct device *dev, int index) |
341 | { | 338 | { |
342 | struct i2c_client *client = to_i2c_client(dev); | 339 | struct smm665_data *data = dev_get_drvdata(dev); |
343 | struct smm665_data *data = i2c_get_clientdata(client); | ||
344 | 340 | ||
345 | return data->critical_max_limit[index]; | 341 | return data->critical_max_limit[index]; |
346 | } | 342 | } |
@@ -486,7 +482,7 @@ SMM665_ATTR(temp1, crit_alarm, SMM665_FAULT_TEMP); | |||
486 | * Finally, construct an array of pointers to members of the above objects, | 482 | * Finally, construct an array of pointers to members of the above objects, |
487 | * as required for sysfs_create_group() | 483 | * as required for sysfs_create_group() |
488 | */ | 484 | */ |
489 | static struct attribute *smm665_attributes[] = { | 485 | static struct attribute *smm665_attrs[] = { |
490 | &sensor_dev_attr_in1_input.dev_attr.attr, | 486 | &sensor_dev_attr_in1_input.dev_attr.attr, |
491 | &sensor_dev_attr_in1_min.dev_attr.attr, | 487 | &sensor_dev_attr_in1_min.dev_attr.attr, |
492 | &sensor_dev_attr_in1_max.dev_attr.attr, | 488 | &sensor_dev_attr_in1_max.dev_attr.attr, |
@@ -567,15 +563,14 @@ static struct attribute *smm665_attributes[] = { | |||
567 | NULL, | 563 | NULL, |
568 | }; | 564 | }; |
569 | 565 | ||
570 | static const struct attribute_group smm665_group = { | 566 | ATTRIBUTE_GROUPS(smm665); |
571 | .attrs = smm665_attributes, | ||
572 | }; | ||
573 | 567 | ||
574 | static int smm665_probe(struct i2c_client *client, | 568 | static int smm665_probe(struct i2c_client *client, |
575 | const struct i2c_device_id *id) | 569 | const struct i2c_device_id *id) |
576 | { | 570 | { |
577 | struct i2c_adapter *adapter = client->adapter; | 571 | struct i2c_adapter *adapter = client->adapter; |
578 | struct smm665_data *data; | 572 | struct smm665_data *data; |
573 | struct device *hwmon_dev; | ||
579 | int i, ret; | 574 | int i, ret; |
580 | 575 | ||
581 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | 576 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
@@ -592,6 +587,7 @@ static int smm665_probe(struct i2c_client *client, | |||
592 | i2c_set_clientdata(client, data); | 587 | i2c_set_clientdata(client, data); |
593 | mutex_init(&data->update_lock); | 588 | mutex_init(&data->update_lock); |
594 | 589 | ||
590 | data->client = client; | ||
595 | data->type = id->driver_data; | 591 | data->type = id->driver_data; |
596 | data->cmdreg = i2c_new_dummy(adapter, (client->addr & ~SMM665_REGMASK) | 592 | data->cmdreg = i2c_new_dummy(adapter, (client->addr & ~SMM665_REGMASK) |
597 | | SMM665_CMDREG_BASE); | 593 | | SMM665_CMDREG_BASE); |
@@ -662,21 +658,16 @@ static int smm665_probe(struct i2c_client *client, | |||
662 | data->alarm_max_limit[i] = smm665_convert(val, i); | 658 | data->alarm_max_limit[i] = smm665_convert(val, i); |
663 | } | 659 | } |
664 | 660 | ||
665 | /* Register sysfs hooks */ | 661 | hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev, |
666 | ret = sysfs_create_group(&client->dev.kobj, &smm665_group); | 662 | client->name, data, |
667 | if (ret) | 663 | smm665_groups); |
664 | if (IS_ERR(hwmon_dev)) { | ||
665 | ret = PTR_ERR(hwmon_dev); | ||
668 | goto out_unregister; | 666 | goto out_unregister; |
669 | |||
670 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
671 | if (IS_ERR(data->hwmon_dev)) { | ||
672 | ret = PTR_ERR(data->hwmon_dev); | ||
673 | goto out_remove_group; | ||
674 | } | 667 | } |
675 | 668 | ||
676 | return 0; | 669 | return 0; |
677 | 670 | ||
678 | out_remove_group: | ||
679 | sysfs_remove_group(&client->dev.kobj, &smm665_group); | ||
680 | out_unregister: | 671 | out_unregister: |
681 | i2c_unregister_device(data->cmdreg); | 672 | i2c_unregister_device(data->cmdreg); |
682 | return ret; | 673 | return ret; |
@@ -687,9 +678,6 @@ static int smm665_remove(struct i2c_client *client) | |||
687 | struct smm665_data *data = i2c_get_clientdata(client); | 678 | struct smm665_data *data = i2c_get_clientdata(client); |
688 | 679 | ||
689 | i2c_unregister_device(data->cmdreg); | 680 | i2c_unregister_device(data->cmdreg); |
690 | hwmon_device_unregister(data->hwmon_dev); | ||
691 | sysfs_remove_group(&client->dev.kobj, &smm665_group); | ||
692 | |||
693 | return 0; | 681 | return 0; |
694 | } | 682 | } |
695 | 683 | ||
diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c index 23a22c4eee51..d7485659acc5 100644 --- a/drivers/hwmon/smsc47m1.c +++ b/drivers/hwmon/smsc47m1.c | |||
@@ -142,11 +142,6 @@ struct smsc47m1_sio_data { | |||
142 | u8 activate; /* Remember initial device state */ | 142 | u8 activate; /* Remember initial device state */ |
143 | }; | 143 | }; |
144 | 144 | ||
145 | |||
146 | static int __exit smsc47m1_remove(struct platform_device *pdev); | ||
147 | static struct smsc47m1_data *smsc47m1_update_device(struct device *dev, | ||
148 | int init); | ||
149 | |||
150 | static inline int smsc47m1_read_value(struct smsc47m1_data *data, u8 reg) | 145 | static inline int smsc47m1_read_value(struct smsc47m1_data *data, u8 reg) |
151 | { | 146 | { |
152 | return inb_p(data->addr + reg); | 147 | return inb_p(data->addr + reg); |
@@ -158,13 +153,54 @@ static inline void smsc47m1_write_value(struct smsc47m1_data *data, u8 reg, | |||
158 | outb_p(value, data->addr + reg); | 153 | outb_p(value, data->addr + reg); |
159 | } | 154 | } |
160 | 155 | ||
161 | static struct platform_driver smsc47m1_driver = { | 156 | static struct smsc47m1_data *smsc47m1_update_device(struct device *dev, |
162 | .driver = { | 157 | int init) |
163 | .owner = THIS_MODULE, | 158 | { |
164 | .name = DRVNAME, | 159 | struct smsc47m1_data *data = dev_get_drvdata(dev); |
165 | }, | 160 | |
166 | .remove = __exit_p(smsc47m1_remove), | 161 | mutex_lock(&data->update_lock); |
167 | }; | 162 | |
163 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || init) { | ||
164 | int i, fan_nr; | ||
165 | fan_nr = data->type == smsc47m2 ? 3 : 2; | ||
166 | |||
167 | for (i = 0; i < fan_nr; i++) { | ||
168 | data->fan[i] = smsc47m1_read_value(data, | ||
169 | SMSC47M1_REG_FAN[i]); | ||
170 | data->fan_preload[i] = smsc47m1_read_value(data, | ||
171 | SMSC47M1_REG_FAN_PRELOAD[i]); | ||
172 | data->pwm[i] = smsc47m1_read_value(data, | ||
173 | SMSC47M1_REG_PWM[i]); | ||
174 | } | ||
175 | |||
176 | i = smsc47m1_read_value(data, SMSC47M1_REG_FANDIV); | ||
177 | data->fan_div[0] = (i >> 4) & 0x03; | ||
178 | data->fan_div[1] = i >> 6; | ||
179 | |||
180 | data->alarms = smsc47m1_read_value(data, | ||
181 | SMSC47M1_REG_ALARM) >> 6; | ||
182 | /* Clear alarms if needed */ | ||
183 | if (data->alarms) | ||
184 | smsc47m1_write_value(data, SMSC47M1_REG_ALARM, 0xC0); | ||
185 | |||
186 | if (fan_nr >= 3) { | ||
187 | data->fan_div[2] = (smsc47m1_read_value(data, | ||
188 | SMSC47M2_REG_FANDIV3) >> 4) & 0x03; | ||
189 | data->alarms |= (smsc47m1_read_value(data, | ||
190 | SMSC47M2_REG_ALARM6) & 0x40) >> 4; | ||
191 | /* Clear alarm if needed */ | ||
192 | if (data->alarms & 0x04) | ||
193 | smsc47m1_write_value(data, | ||
194 | SMSC47M2_REG_ALARM6, | ||
195 | 0x40); | ||
196 | } | ||
197 | |||
198 | data->last_updated = jiffies; | ||
199 | } | ||
200 | |||
201 | mutex_unlock(&data->update_lock); | ||
202 | return data; | ||
203 | } | ||
168 | 204 | ||
169 | static ssize_t get_fan(struct device *dev, struct device_attribute | 205 | static ssize_t get_fan(struct device *dev, struct device_attribute |
170 | *devattr, char *buf) | 206 | *devattr, char *buf) |
@@ -811,54 +847,13 @@ static int __exit smsc47m1_remove(struct platform_device *pdev) | |||
811 | return 0; | 847 | return 0; |
812 | } | 848 | } |
813 | 849 | ||
814 | static struct smsc47m1_data *smsc47m1_update_device(struct device *dev, | 850 | static struct platform_driver smsc47m1_driver = { |
815 | int init) | 851 | .driver = { |
816 | { | 852 | .owner = THIS_MODULE, |
817 | struct smsc47m1_data *data = dev_get_drvdata(dev); | 853 | .name = DRVNAME, |
818 | 854 | }, | |
819 | mutex_lock(&data->update_lock); | 855 | .remove = __exit_p(smsc47m1_remove), |
820 | 856 | }; | |
821 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || init) { | ||
822 | int i, fan_nr; | ||
823 | fan_nr = data->type == smsc47m2 ? 3 : 2; | ||
824 | |||
825 | for (i = 0; i < fan_nr; i++) { | ||
826 | data->fan[i] = smsc47m1_read_value(data, | ||
827 | SMSC47M1_REG_FAN[i]); | ||
828 | data->fan_preload[i] = smsc47m1_read_value(data, | ||
829 | SMSC47M1_REG_FAN_PRELOAD[i]); | ||
830 | data->pwm[i] = smsc47m1_read_value(data, | ||
831 | SMSC47M1_REG_PWM[i]); | ||
832 | } | ||
833 | |||
834 | i = smsc47m1_read_value(data, SMSC47M1_REG_FANDIV); | ||
835 | data->fan_div[0] = (i >> 4) & 0x03; | ||
836 | data->fan_div[1] = i >> 6; | ||
837 | |||
838 | data->alarms = smsc47m1_read_value(data, | ||
839 | SMSC47M1_REG_ALARM) >> 6; | ||
840 | /* Clear alarms if needed */ | ||
841 | if (data->alarms) | ||
842 | smsc47m1_write_value(data, SMSC47M1_REG_ALARM, 0xC0); | ||
843 | |||
844 | if (fan_nr >= 3) { | ||
845 | data->fan_div[2] = (smsc47m1_read_value(data, | ||
846 | SMSC47M2_REG_FANDIV3) >> 4) & 0x03; | ||
847 | data->alarms |= (smsc47m1_read_value(data, | ||
848 | SMSC47M2_REG_ALARM6) & 0x40) >> 4; | ||
849 | /* Clear alarm if needed */ | ||
850 | if (data->alarms & 0x04) | ||
851 | smsc47m1_write_value(data, | ||
852 | SMSC47M2_REG_ALARM6, | ||
853 | 0x40); | ||
854 | } | ||
855 | |||
856 | data->last_updated = jiffies; | ||
857 | } | ||
858 | |||
859 | mutex_unlock(&data->update_lock); | ||
860 | return data; | ||
861 | } | ||
862 | 857 | ||
863 | static int __init smsc47m1_device_add(unsigned short address, | 858 | static int __init smsc47m1_device_add(unsigned short address, |
864 | const struct smsc47m1_sio_data *sio_data) | 859 | const struct smsc47m1_sio_data *sio_data) |
diff --git a/drivers/hwmon/smsc47m192.c b/drivers/hwmon/smsc47m192.c index 34b9a601ad07..6ac7cda72d4c 100644 --- a/drivers/hwmon/smsc47m192.c +++ b/drivers/hwmon/smsc47m192.c | |||
@@ -95,7 +95,8 @@ static inline int TEMP_FROM_REG(s8 val) | |||
95 | } | 95 | } |
96 | 96 | ||
97 | struct smsc47m192_data { | 97 | struct smsc47m192_data { |
98 | struct device *hwmon_dev; | 98 | struct i2c_client *client; |
99 | const struct attribute_group *groups[3]; | ||
99 | struct mutex update_lock; | 100 | struct mutex update_lock; |
100 | char valid; /* !=0 if following fields are valid */ | 101 | char valid; /* !=0 if following fields are valid */ |
101 | unsigned long last_updated; /* In jiffies */ | 102 | unsigned long last_updated; /* In jiffies */ |
@@ -112,30 +113,69 @@ struct smsc47m192_data { | |||
112 | u8 vrm; | 113 | u8 vrm; |
113 | }; | 114 | }; |
114 | 115 | ||
115 | static int smsc47m192_probe(struct i2c_client *client, | 116 | static struct smsc47m192_data *smsc47m192_update_device(struct device *dev) |
116 | const struct i2c_device_id *id); | 117 | { |
117 | static int smsc47m192_detect(struct i2c_client *client, | 118 | struct smsc47m192_data *data = dev_get_drvdata(dev); |
118 | struct i2c_board_info *info); | 119 | struct i2c_client *client = data->client; |
119 | static int smsc47m192_remove(struct i2c_client *client); | 120 | int i, config; |
120 | static struct smsc47m192_data *smsc47m192_update_device(struct device *dev); | ||
121 | 121 | ||
122 | static const struct i2c_device_id smsc47m192_id[] = { | 122 | mutex_lock(&data->update_lock); |
123 | { "smsc47m192", 0 }, | ||
124 | { } | ||
125 | }; | ||
126 | MODULE_DEVICE_TABLE(i2c, smsc47m192_id); | ||
127 | 123 | ||
128 | static struct i2c_driver smsc47m192_driver = { | 124 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) |
129 | .class = I2C_CLASS_HWMON, | 125 | || !data->valid) { |
130 | .driver = { | 126 | u8 sfr = i2c_smbus_read_byte_data(client, SMSC47M192_REG_SFR); |
131 | .name = "smsc47m192", | 127 | |
132 | }, | 128 | dev_dbg(&client->dev, "Starting smsc47m192 update\n"); |
133 | .probe = smsc47m192_probe, | 129 | |
134 | .remove = smsc47m192_remove, | 130 | for (i = 0; i <= 7; i++) { |
135 | .id_table = smsc47m192_id, | 131 | data->in[i] = i2c_smbus_read_byte_data(client, |
136 | .detect = smsc47m192_detect, | 132 | SMSC47M192_REG_IN(i)); |
137 | .address_list = normal_i2c, | 133 | data->in_min[i] = i2c_smbus_read_byte_data(client, |
138 | }; | 134 | SMSC47M192_REG_IN_MIN(i)); |
135 | data->in_max[i] = i2c_smbus_read_byte_data(client, | ||
136 | SMSC47M192_REG_IN_MAX(i)); | ||
137 | } | ||
138 | for (i = 0; i < 3; i++) { | ||
139 | data->temp[i] = i2c_smbus_read_byte_data(client, | ||
140 | SMSC47M192_REG_TEMP[i]); | ||
141 | data->temp_max[i] = i2c_smbus_read_byte_data(client, | ||
142 | SMSC47M192_REG_TEMP_MAX[i]); | ||
143 | data->temp_min[i] = i2c_smbus_read_byte_data(client, | ||
144 | SMSC47M192_REG_TEMP_MIN[i]); | ||
145 | } | ||
146 | for (i = 1; i < 3; i++) | ||
147 | data->temp_offset[i] = i2c_smbus_read_byte_data(client, | ||
148 | SMSC47M192_REG_TEMP_OFFSET(i)); | ||
149 | /* | ||
150 | * first offset is temp_offset[0] if SFR bit 4 is set, | ||
151 | * temp_offset[1] otherwise | ||
152 | */ | ||
153 | if (sfr & 0x10) { | ||
154 | data->temp_offset[0] = data->temp_offset[1]; | ||
155 | data->temp_offset[1] = 0; | ||
156 | } else | ||
157 | data->temp_offset[0] = 0; | ||
158 | |||
159 | data->vid = i2c_smbus_read_byte_data(client, SMSC47M192_REG_VID) | ||
160 | & 0x0f; | ||
161 | config = i2c_smbus_read_byte_data(client, | ||
162 | SMSC47M192_REG_CONFIG); | ||
163 | if (config & 0x20) | ||
164 | data->vid |= (i2c_smbus_read_byte_data(client, | ||
165 | SMSC47M192_REG_VID4) & 0x01) << 4; | ||
166 | data->alarms = i2c_smbus_read_byte_data(client, | ||
167 | SMSC47M192_REG_ALARM1) | | ||
168 | (i2c_smbus_read_byte_data(client, | ||
169 | SMSC47M192_REG_ALARM2) << 8); | ||
170 | |||
171 | data->last_updated = jiffies; | ||
172 | data->valid = 1; | ||
173 | } | ||
174 | |||
175 | mutex_unlock(&data->update_lock); | ||
176 | |||
177 | return data; | ||
178 | } | ||
139 | 179 | ||
140 | /* Voltages */ | 180 | /* Voltages */ |
141 | static ssize_t show_in(struct device *dev, struct device_attribute *attr, | 181 | static ssize_t show_in(struct device *dev, struct device_attribute *attr, |
@@ -170,8 +210,8 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | |||
170 | { | 210 | { |
171 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 211 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
172 | int nr = sensor_attr->index; | 212 | int nr = sensor_attr->index; |
173 | struct i2c_client *client = to_i2c_client(dev); | 213 | struct smsc47m192_data *data = dev_get_drvdata(dev); |
174 | struct smsc47m192_data *data = i2c_get_clientdata(client); | 214 | struct i2c_client *client = data->client; |
175 | unsigned long val; | 215 | unsigned long val; |
176 | int err; | 216 | int err; |
177 | 217 | ||
@@ -192,8 +232,8 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, | |||
192 | { | 232 | { |
193 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 233 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
194 | int nr = sensor_attr->index; | 234 | int nr = sensor_attr->index; |
195 | struct i2c_client *client = to_i2c_client(dev); | 235 | struct smsc47m192_data *data = dev_get_drvdata(dev); |
196 | struct smsc47m192_data *data = i2c_get_clientdata(client); | 236 | struct i2c_client *client = data->client; |
197 | unsigned long val; | 237 | unsigned long val; |
198 | int err; | 238 | int err; |
199 | 239 | ||
@@ -259,8 +299,8 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | |||
259 | { | 299 | { |
260 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 300 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
261 | int nr = sensor_attr->index; | 301 | int nr = sensor_attr->index; |
262 | struct i2c_client *client = to_i2c_client(dev); | 302 | struct smsc47m192_data *data = dev_get_drvdata(dev); |
263 | struct smsc47m192_data *data = i2c_get_clientdata(client); | 303 | struct i2c_client *client = data->client; |
264 | long val; | 304 | long val; |
265 | int err; | 305 | int err; |
266 | 306 | ||
@@ -281,8 +321,8 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
281 | { | 321 | { |
282 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 322 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
283 | int nr = sensor_attr->index; | 323 | int nr = sensor_attr->index; |
284 | struct i2c_client *client = to_i2c_client(dev); | 324 | struct smsc47m192_data *data = dev_get_drvdata(dev); |
285 | struct smsc47m192_data *data = i2c_get_clientdata(client); | 325 | struct i2c_client *client = data->client; |
286 | long val; | 326 | long val; |
287 | int err; | 327 | int err; |
288 | 328 | ||
@@ -312,8 +352,8 @@ static ssize_t set_temp_offset(struct device *dev, struct device_attribute | |||
312 | { | 352 | { |
313 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 353 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
314 | int nr = sensor_attr->index; | 354 | int nr = sensor_attr->index; |
315 | struct i2c_client *client = to_i2c_client(dev); | 355 | struct smsc47m192_data *data = dev_get_drvdata(dev); |
316 | struct smsc47m192_data *data = i2c_get_clientdata(client); | 356 | struct i2c_client *client = data->client; |
317 | u8 sfr = i2c_smbus_read_byte_data(client, SMSC47M192_REG_SFR); | 357 | u8 sfr = i2c_smbus_read_byte_data(client, SMSC47M192_REG_SFR); |
318 | long val; | 358 | long val; |
319 | int err; | 359 | int err; |
@@ -552,124 +592,50 @@ static int smsc47m192_detect(struct i2c_client *client, | |||
552 | static int smsc47m192_probe(struct i2c_client *client, | 592 | static int smsc47m192_probe(struct i2c_client *client, |
553 | const struct i2c_device_id *id) | 593 | const struct i2c_device_id *id) |
554 | { | 594 | { |
595 | struct device *dev = &client->dev; | ||
596 | struct device *hwmon_dev; | ||
555 | struct smsc47m192_data *data; | 597 | struct smsc47m192_data *data; |
556 | int config; | 598 | int config; |
557 | int err; | ||
558 | 599 | ||
559 | data = devm_kzalloc(&client->dev, sizeof(struct smsc47m192_data), | 600 | data = devm_kzalloc(dev, sizeof(struct smsc47m192_data), GFP_KERNEL); |
560 | GFP_KERNEL); | ||
561 | if (!data) | 601 | if (!data) |
562 | return -ENOMEM; | 602 | return -ENOMEM; |
563 | 603 | ||
564 | i2c_set_clientdata(client, data); | 604 | data->client = client; |
565 | data->vrm = vid_which_vrm(); | 605 | data->vrm = vid_which_vrm(); |
566 | mutex_init(&data->update_lock); | 606 | mutex_init(&data->update_lock); |
567 | 607 | ||
568 | /* Initialize the SMSC47M192 chip */ | 608 | /* Initialize the SMSC47M192 chip */ |
569 | smsc47m192_init_client(client); | 609 | smsc47m192_init_client(client); |
570 | 610 | ||
571 | /* Register sysfs hooks */ | 611 | /* sysfs hooks */ |
572 | err = sysfs_create_group(&client->dev.kobj, &smsc47m192_group); | 612 | data->groups[0] = &smsc47m192_group; |
573 | if (err) | ||
574 | return err; | ||
575 | |||
576 | /* Pin 110 is either in4 (+12V) or VID4 */ | 613 | /* Pin 110 is either in4 (+12V) or VID4 */ |
577 | config = i2c_smbus_read_byte_data(client, SMSC47M192_REG_CONFIG); | 614 | config = i2c_smbus_read_byte_data(client, SMSC47M192_REG_CONFIG); |
578 | if (!(config & 0x20)) { | 615 | if (!(config & 0x20)) |
579 | err = sysfs_create_group(&client->dev.kobj, | 616 | data->groups[1] = &smsc47m192_group_in4; |
580 | &smsc47m192_group_in4); | ||
581 | if (err) | ||
582 | goto exit_remove_files; | ||
583 | } | ||
584 | |||
585 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
586 | if (IS_ERR(data->hwmon_dev)) { | ||
587 | err = PTR_ERR(data->hwmon_dev); | ||
588 | goto exit_remove_files; | ||
589 | } | ||
590 | |||
591 | return 0; | ||
592 | |||
593 | exit_remove_files: | ||
594 | sysfs_remove_group(&client->dev.kobj, &smsc47m192_group); | ||
595 | sysfs_remove_group(&client->dev.kobj, &smsc47m192_group_in4); | ||
596 | return err; | ||
597 | } | ||
598 | |||
599 | static int smsc47m192_remove(struct i2c_client *client) | ||
600 | { | ||
601 | struct smsc47m192_data *data = i2c_get_clientdata(client); | ||
602 | |||
603 | hwmon_device_unregister(data->hwmon_dev); | ||
604 | sysfs_remove_group(&client->dev.kobj, &smsc47m192_group); | ||
605 | sysfs_remove_group(&client->dev.kobj, &smsc47m192_group_in4); | ||
606 | 617 | ||
607 | return 0; | 618 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
619 | data, data->groups); | ||
620 | return PTR_ERR_OR_ZERO(hwmon_dev); | ||
608 | } | 621 | } |
609 | 622 | ||
610 | static struct smsc47m192_data *smsc47m192_update_device(struct device *dev) | 623 | static const struct i2c_device_id smsc47m192_id[] = { |
611 | { | 624 | { "smsc47m192", 0 }, |
612 | struct i2c_client *client = to_i2c_client(dev); | 625 | { } |
613 | struct smsc47m192_data *data = i2c_get_clientdata(client); | 626 | }; |
614 | int i, config; | 627 | MODULE_DEVICE_TABLE(i2c, smsc47m192_id); |
615 | |||
616 | mutex_lock(&data->update_lock); | ||
617 | |||
618 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) | ||
619 | || !data->valid) { | ||
620 | u8 sfr = i2c_smbus_read_byte_data(client, SMSC47M192_REG_SFR); | ||
621 | |||
622 | dev_dbg(&client->dev, "Starting smsc47m192 update\n"); | ||
623 | |||
624 | for (i = 0; i <= 7; i++) { | ||
625 | data->in[i] = i2c_smbus_read_byte_data(client, | ||
626 | SMSC47M192_REG_IN(i)); | ||
627 | data->in_min[i] = i2c_smbus_read_byte_data(client, | ||
628 | SMSC47M192_REG_IN_MIN(i)); | ||
629 | data->in_max[i] = i2c_smbus_read_byte_data(client, | ||
630 | SMSC47M192_REG_IN_MAX(i)); | ||
631 | } | ||
632 | for (i = 0; i < 3; i++) { | ||
633 | data->temp[i] = i2c_smbus_read_byte_data(client, | ||
634 | SMSC47M192_REG_TEMP[i]); | ||
635 | data->temp_max[i] = i2c_smbus_read_byte_data(client, | ||
636 | SMSC47M192_REG_TEMP_MAX[i]); | ||
637 | data->temp_min[i] = i2c_smbus_read_byte_data(client, | ||
638 | SMSC47M192_REG_TEMP_MIN[i]); | ||
639 | } | ||
640 | for (i = 1; i < 3; i++) | ||
641 | data->temp_offset[i] = i2c_smbus_read_byte_data(client, | ||
642 | SMSC47M192_REG_TEMP_OFFSET(i)); | ||
643 | /* | ||
644 | * first offset is temp_offset[0] if SFR bit 4 is set, | ||
645 | * temp_offset[1] otherwise | ||
646 | */ | ||
647 | if (sfr & 0x10) { | ||
648 | data->temp_offset[0] = data->temp_offset[1]; | ||
649 | data->temp_offset[1] = 0; | ||
650 | } else | ||
651 | data->temp_offset[0] = 0; | ||
652 | |||
653 | data->vid = i2c_smbus_read_byte_data(client, SMSC47M192_REG_VID) | ||
654 | & 0x0f; | ||
655 | config = i2c_smbus_read_byte_data(client, | ||
656 | SMSC47M192_REG_CONFIG); | ||
657 | if (config & 0x20) | ||
658 | data->vid |= (i2c_smbus_read_byte_data(client, | ||
659 | SMSC47M192_REG_VID4) & 0x01) << 4; | ||
660 | data->alarms = i2c_smbus_read_byte_data(client, | ||
661 | SMSC47M192_REG_ALARM1) | | ||
662 | (i2c_smbus_read_byte_data(client, | ||
663 | SMSC47M192_REG_ALARM2) << 8); | ||
664 | |||
665 | data->last_updated = jiffies; | ||
666 | data->valid = 1; | ||
667 | } | ||
668 | |||
669 | mutex_unlock(&data->update_lock); | ||
670 | 628 | ||
671 | return data; | 629 | static struct i2c_driver smsc47m192_driver = { |
672 | } | 630 | .class = I2C_CLASS_HWMON, |
631 | .driver = { | ||
632 | .name = "smsc47m192", | ||
633 | }, | ||
634 | .probe = smsc47m192_probe, | ||
635 | .id_table = smsc47m192_id, | ||
636 | .detect = smsc47m192_detect, | ||
637 | .address_list = normal_i2c, | ||
638 | }; | ||
673 | 639 | ||
674 | module_i2c_driver(smsc47m192_driver); | 640 | module_i2c_driver(smsc47m192_driver); |
675 | 641 | ||
diff --git a/drivers/hwmon/thmc50.c b/drivers/hwmon/thmc50.c index db288db7d3e9..6a0ee903127e 100644 --- a/drivers/hwmon/thmc50.c +++ b/drivers/hwmon/thmc50.c | |||
@@ -68,7 +68,8 @@ static const u8 THMC50_REG_TEMP_DEFAULT[] = { 0x17, 0x18, 0x18 }; | |||
68 | 68 | ||
69 | /* Each client has this additional data */ | 69 | /* Each client has this additional data */ |
70 | struct thmc50_data { | 70 | struct thmc50_data { |
71 | struct device *hwmon_dev; | 71 | struct i2c_client *client; |
72 | const struct attribute_group *groups[3]; | ||
72 | 73 | ||
73 | struct mutex update_lock; | 74 | struct mutex update_lock; |
74 | enum chips type; | 75 | enum chips type; |
@@ -85,32 +86,47 @@ struct thmc50_data { | |||
85 | u8 alarms; | 86 | u8 alarms; |
86 | }; | 87 | }; |
87 | 88 | ||
88 | static int thmc50_detect(struct i2c_client *client, | 89 | static struct thmc50_data *thmc50_update_device(struct device *dev) |
89 | struct i2c_board_info *info); | 90 | { |
90 | static int thmc50_probe(struct i2c_client *client, | 91 | struct thmc50_data *data = dev_get_drvdata(dev); |
91 | const struct i2c_device_id *id); | 92 | struct i2c_client *client = data->client; |
92 | static int thmc50_remove(struct i2c_client *client); | 93 | int timeout = HZ / 5 + (data->type == thmc50 ? HZ : 0); |
93 | static void thmc50_init_client(struct i2c_client *client); | ||
94 | static struct thmc50_data *thmc50_update_device(struct device *dev); | ||
95 | 94 | ||
96 | static const struct i2c_device_id thmc50_id[] = { | 95 | mutex_lock(&data->update_lock); |
97 | { "adm1022", adm1022 }, | ||
98 | { "thmc50", thmc50 }, | ||
99 | { } | ||
100 | }; | ||
101 | MODULE_DEVICE_TABLE(i2c, thmc50_id); | ||
102 | 96 | ||
103 | static struct i2c_driver thmc50_driver = { | 97 | if (time_after(jiffies, data->last_updated + timeout) |
104 | .class = I2C_CLASS_HWMON, | 98 | || !data->valid) { |
105 | .driver = { | 99 | |
106 | .name = "thmc50", | 100 | int temps = data->has_temp3 ? 3 : 2; |
107 | }, | 101 | int i; |
108 | .probe = thmc50_probe, | 102 | int prog = i2c_smbus_read_byte_data(client, THMC50_REG_CONF); |
109 | .remove = thmc50_remove, | 103 | |
110 | .id_table = thmc50_id, | 104 | prog &= THMC50_REG_CONF_PROGRAMMED; |
111 | .detect = thmc50_detect, | 105 | |
112 | .address_list = normal_i2c, | 106 | for (i = 0; i < temps; i++) { |
113 | }; | 107 | data->temp_input[i] = i2c_smbus_read_byte_data(client, |
108 | THMC50_REG_TEMP[i]); | ||
109 | data->temp_max[i] = i2c_smbus_read_byte_data(client, | ||
110 | THMC50_REG_TEMP_MAX[i]); | ||
111 | data->temp_min[i] = i2c_smbus_read_byte_data(client, | ||
112 | THMC50_REG_TEMP_MIN[i]); | ||
113 | data->temp_critical[i] = | ||
114 | i2c_smbus_read_byte_data(client, | ||
115 | prog ? THMC50_REG_TEMP_CRITICAL[i] | ||
116 | : THMC50_REG_TEMP_DEFAULT[i]); | ||
117 | } | ||
118 | data->analog_out = | ||
119 | i2c_smbus_read_byte_data(client, THMC50_REG_ANALOG_OUT); | ||
120 | data->alarms = | ||
121 | i2c_smbus_read_byte_data(client, THMC50_REG_INTR); | ||
122 | data->last_updated = jiffies; | ||
123 | data->valid = 1; | ||
124 | } | ||
125 | |||
126 | mutex_unlock(&data->update_lock); | ||
127 | |||
128 | return data; | ||
129 | } | ||
114 | 130 | ||
115 | static ssize_t show_analog_out(struct device *dev, | 131 | static ssize_t show_analog_out(struct device *dev, |
116 | struct device_attribute *attr, char *buf) | 132 | struct device_attribute *attr, char *buf) |
@@ -123,8 +139,8 @@ static ssize_t set_analog_out(struct device *dev, | |||
123 | struct device_attribute *attr, | 139 | struct device_attribute *attr, |
124 | const char *buf, size_t count) | 140 | const char *buf, size_t count) |
125 | { | 141 | { |
126 | struct i2c_client *client = to_i2c_client(dev); | 142 | struct thmc50_data *data = dev_get_drvdata(dev); |
127 | struct thmc50_data *data = i2c_get_clientdata(client); | 143 | struct i2c_client *client = data->client; |
128 | int config; | 144 | int config; |
129 | unsigned long tmp; | 145 | unsigned long tmp; |
130 | int err; | 146 | int err; |
@@ -177,8 +193,8 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | |||
177 | const char *buf, size_t count) | 193 | const char *buf, size_t count) |
178 | { | 194 | { |
179 | int nr = to_sensor_dev_attr(attr)->index; | 195 | int nr = to_sensor_dev_attr(attr)->index; |
180 | struct i2c_client *client = to_i2c_client(dev); | 196 | struct thmc50_data *data = dev_get_drvdata(dev); |
181 | struct thmc50_data *data = i2c_get_clientdata(client); | 197 | struct i2c_client *client = data->client; |
182 | long val; | 198 | long val; |
183 | int err; | 199 | int err; |
184 | 200 | ||
@@ -206,8 +222,8 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
206 | const char *buf, size_t count) | 222 | const char *buf, size_t count) |
207 | { | 223 | { |
208 | int nr = to_sensor_dev_attr(attr)->index; | 224 | int nr = to_sensor_dev_attr(attr)->index; |
209 | struct i2c_client *client = to_i2c_client(dev); | 225 | struct thmc50_data *data = dev_get_drvdata(dev); |
210 | struct thmc50_data *data = i2c_get_clientdata(client); | 226 | struct i2c_client *client = data->client; |
211 | long val; | 227 | long val; |
212 | int err; | 228 | int err; |
213 | 229 | ||
@@ -355,67 +371,9 @@ static int thmc50_detect(struct i2c_client *client, | |||
355 | return 0; | 371 | return 0; |
356 | } | 372 | } |
357 | 373 | ||
358 | static int thmc50_probe(struct i2c_client *client, | 374 | static void thmc50_init_client(struct thmc50_data *data) |
359 | const struct i2c_device_id *id) | ||
360 | { | ||
361 | struct thmc50_data *data; | ||
362 | int err; | ||
363 | |||
364 | data = devm_kzalloc(&client->dev, sizeof(struct thmc50_data), | ||
365 | GFP_KERNEL); | ||
366 | if (!data) | ||
367 | return -ENOMEM; | ||
368 | |||
369 | i2c_set_clientdata(client, data); | ||
370 | data->type = id->driver_data; | ||
371 | mutex_init(&data->update_lock); | ||
372 | |||
373 | thmc50_init_client(client); | ||
374 | |||
375 | /* Register sysfs hooks */ | ||
376 | err = sysfs_create_group(&client->dev.kobj, &thmc50_group); | ||
377 | if (err) | ||
378 | return err; | ||
379 | |||
380 | /* Register ADM1022 sysfs hooks */ | ||
381 | if (data->has_temp3) { | ||
382 | err = sysfs_create_group(&client->dev.kobj, &temp3_group); | ||
383 | if (err) | ||
384 | goto exit_remove_sysfs_thmc50; | ||
385 | } | ||
386 | |||
387 | /* Register a new directory entry with module sensors */ | ||
388 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
389 | if (IS_ERR(data->hwmon_dev)) { | ||
390 | err = PTR_ERR(data->hwmon_dev); | ||
391 | goto exit_remove_sysfs; | ||
392 | } | ||
393 | |||
394 | return 0; | ||
395 | |||
396 | exit_remove_sysfs: | ||
397 | if (data->has_temp3) | ||
398 | sysfs_remove_group(&client->dev.kobj, &temp3_group); | ||
399 | exit_remove_sysfs_thmc50: | ||
400 | sysfs_remove_group(&client->dev.kobj, &thmc50_group); | ||
401 | return err; | ||
402 | } | ||
403 | |||
404 | static int thmc50_remove(struct i2c_client *client) | ||
405 | { | 375 | { |
406 | struct thmc50_data *data = i2c_get_clientdata(client); | 376 | struct i2c_client *client = data->client; |
407 | |||
408 | hwmon_device_unregister(data->hwmon_dev); | ||
409 | sysfs_remove_group(&client->dev.kobj, &thmc50_group); | ||
410 | if (data->has_temp3) | ||
411 | sysfs_remove_group(&client->dev.kobj, &temp3_group); | ||
412 | |||
413 | return 0; | ||
414 | } | ||
415 | |||
416 | static void thmc50_init_client(struct i2c_client *client) | ||
417 | { | ||
418 | struct thmc50_data *data = i2c_get_clientdata(client); | ||
419 | int config; | 377 | int config; |
420 | 378 | ||
421 | data->analog_out = i2c_smbus_read_byte_data(client, | 379 | data->analog_out = i2c_smbus_read_byte_data(client, |
@@ -433,48 +391,54 @@ static void thmc50_init_client(struct i2c_client *client) | |||
433 | i2c_smbus_write_byte_data(client, THMC50_REG_CONF, config); | 391 | i2c_smbus_write_byte_data(client, THMC50_REG_CONF, config); |
434 | } | 392 | } |
435 | 393 | ||
436 | static struct thmc50_data *thmc50_update_device(struct device *dev) | 394 | static int thmc50_probe(struct i2c_client *client, |
395 | const struct i2c_device_id *id) | ||
437 | { | 396 | { |
438 | struct i2c_client *client = to_i2c_client(dev); | 397 | struct device *dev = &client->dev; |
439 | struct thmc50_data *data = i2c_get_clientdata(client); | 398 | struct thmc50_data *data; |
440 | int timeout = HZ / 5 + (data->type == thmc50 ? HZ : 0); | 399 | struct device *hwmon_dev; |
400 | int idx = 0; | ||
441 | 401 | ||
442 | mutex_lock(&data->update_lock); | 402 | data = devm_kzalloc(dev, sizeof(struct thmc50_data), GFP_KERNEL); |
403 | if (!data) | ||
404 | return -ENOMEM; | ||
443 | 405 | ||
444 | if (time_after(jiffies, data->last_updated + timeout) | 406 | data->client = client; |
445 | || !data->valid) { | 407 | data->type = id->driver_data; |
408 | mutex_init(&data->update_lock); | ||
446 | 409 | ||
447 | int temps = data->has_temp3 ? 3 : 2; | 410 | thmc50_init_client(data); |
448 | int i; | ||
449 | int prog = i2c_smbus_read_byte_data(client, THMC50_REG_CONF); | ||
450 | 411 | ||
451 | prog &= THMC50_REG_CONF_PROGRAMMED; | 412 | /* sysfs hooks */ |
413 | data->groups[idx++] = &thmc50_group; | ||
452 | 414 | ||
453 | for (i = 0; i < temps; i++) { | 415 | /* Register additional ADM1022 sysfs hooks */ |
454 | data->temp_input[i] = i2c_smbus_read_byte_data(client, | 416 | if (data->has_temp3) |
455 | THMC50_REG_TEMP[i]); | 417 | data->groups[idx++] = &temp3_group; |
456 | data->temp_max[i] = i2c_smbus_read_byte_data(client, | ||
457 | THMC50_REG_TEMP_MAX[i]); | ||
458 | data->temp_min[i] = i2c_smbus_read_byte_data(client, | ||
459 | THMC50_REG_TEMP_MIN[i]); | ||
460 | data->temp_critical[i] = | ||
461 | i2c_smbus_read_byte_data(client, | ||
462 | prog ? THMC50_REG_TEMP_CRITICAL[i] | ||
463 | : THMC50_REG_TEMP_DEFAULT[i]); | ||
464 | } | ||
465 | data->analog_out = | ||
466 | i2c_smbus_read_byte_data(client, THMC50_REG_ANALOG_OUT); | ||
467 | data->alarms = | ||
468 | i2c_smbus_read_byte_data(client, THMC50_REG_INTR); | ||
469 | data->last_updated = jiffies; | ||
470 | data->valid = 1; | ||
471 | } | ||
472 | |||
473 | mutex_unlock(&data->update_lock); | ||
474 | 418 | ||
475 | return data; | 419 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
420 | data, data->groups); | ||
421 | return PTR_ERR_OR_ZERO(hwmon_dev); | ||
476 | } | 422 | } |
477 | 423 | ||
424 | static const struct i2c_device_id thmc50_id[] = { | ||
425 | { "adm1022", adm1022 }, | ||
426 | { "thmc50", thmc50 }, | ||
427 | { } | ||
428 | }; | ||
429 | MODULE_DEVICE_TABLE(i2c, thmc50_id); | ||
430 | |||
431 | static struct i2c_driver thmc50_driver = { | ||
432 | .class = I2C_CLASS_HWMON, | ||
433 | .driver = { | ||
434 | .name = "thmc50", | ||
435 | }, | ||
436 | .probe = thmc50_probe, | ||
437 | .id_table = thmc50_id, | ||
438 | .detect = thmc50_detect, | ||
439 | .address_list = normal_i2c, | ||
440 | }; | ||
441 | |||
478 | module_i2c_driver(thmc50_driver); | 442 | module_i2c_driver(thmc50_driver); |
479 | 443 | ||
480 | MODULE_AUTHOR("Krzysztof Helt <krzysztof.h1@wp.pl>"); | 444 | MODULE_AUTHOR("Krzysztof Helt <krzysztof.h1@wp.pl>"); |
diff --git a/drivers/hwmon/tmp103.c b/drivers/hwmon/tmp103.c new file mode 100644 index 000000000000..c74d2da389d9 --- /dev/null +++ b/drivers/hwmon/tmp103.c | |||
@@ -0,0 +1,206 @@ | |||
1 | /* | ||
2 | * Texas Instruments TMP103 SMBus temperature sensor driver | ||
3 | * Copyright (C) 2014 Heiko Schocher <hs@denx.de> | ||
4 | * | ||
5 | * Based on: | ||
6 | * Texas Instruments TMP102 SMBus temperature sensor driver | ||
7 | * | ||
8 | * Copyright (C) 2010 Steven King <sfking@fdwdc.com> | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License as published by | ||
12 | * the Free Software Foundation; either version 2 of the License, or | ||
13 | * (at your option) any later version. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | */ | ||
21 | |||
22 | #include <linux/module.h> | ||
23 | #include <linux/init.h> | ||
24 | #include <linux/slab.h> | ||
25 | #include <linux/i2c.h> | ||
26 | #include <linux/hwmon.h> | ||
27 | #include <linux/hwmon-sysfs.h> | ||
28 | #include <linux/err.h> | ||
29 | #include <linux/mutex.h> | ||
30 | #include <linux/device.h> | ||
31 | #include <linux/jiffies.h> | ||
32 | #include <linux/regmap.h> | ||
33 | |||
34 | #define TMP103_TEMP_REG 0x00 | ||
35 | #define TMP103_CONF_REG 0x01 | ||
36 | #define TMP103_TLOW_REG 0x02 | ||
37 | #define TMP103_THIGH_REG 0x03 | ||
38 | |||
39 | #define TMP103_CONF_M0 0x01 | ||
40 | #define TMP103_CONF_M1 0x02 | ||
41 | #define TMP103_CONF_LC 0x04 | ||
42 | #define TMP103_CONF_FL 0x08 | ||
43 | #define TMP103_CONF_FH 0x10 | ||
44 | #define TMP103_CONF_CR0 0x20 | ||
45 | #define TMP103_CONF_CR1 0x40 | ||
46 | #define TMP103_CONF_ID 0x80 | ||
47 | #define TMP103_CONF_SD (TMP103_CONF_M1) | ||
48 | #define TMP103_CONF_SD_MASK (TMP103_CONF_M0 | TMP103_CONF_M1) | ||
49 | |||
50 | #define TMP103_CONFIG (TMP103_CONF_CR1 | TMP103_CONF_M1) | ||
51 | #define TMP103_CONFIG_MASK (TMP103_CONF_CR0 | TMP103_CONF_CR1 | \ | ||
52 | TMP103_CONF_M0 | TMP103_CONF_M1) | ||
53 | |||
54 | static inline int tmp103_reg_to_mc(s8 val) | ||
55 | { | ||
56 | return val * 1000; | ||
57 | } | ||
58 | |||
59 | static inline u8 tmp103_mc_to_reg(int val) | ||
60 | { | ||
61 | return DIV_ROUND_CLOSEST(val, 1000); | ||
62 | } | ||
63 | |||
64 | static ssize_t tmp103_show_temp(struct device *dev, | ||
65 | struct device_attribute *attr, | ||
66 | char *buf) | ||
67 | { | ||
68 | struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); | ||
69 | struct regmap *regmap = dev_get_drvdata(dev); | ||
70 | unsigned int regval; | ||
71 | int ret; | ||
72 | |||
73 | ret = regmap_read(regmap, sda->index, ®val); | ||
74 | if (ret < 0) | ||
75 | return ret; | ||
76 | |||
77 | return sprintf(buf, "%d\n", tmp103_reg_to_mc(regval)); | ||
78 | } | ||
79 | |||
80 | static ssize_t tmp103_set_temp(struct device *dev, | ||
81 | struct device_attribute *attr, | ||
82 | const char *buf, size_t count) | ||
83 | { | ||
84 | struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); | ||
85 | struct regmap *regmap = dev_get_drvdata(dev); | ||
86 | long val; | ||
87 | int ret; | ||
88 | |||
89 | if (kstrtol(buf, 10, &val) < 0) | ||
90 | return -EINVAL; | ||
91 | |||
92 | val = clamp_val(val, -55000, 127000); | ||
93 | ret = regmap_write(regmap, sda->index, tmp103_mc_to_reg(val)); | ||
94 | return ret ? ret : count; | ||
95 | } | ||
96 | |||
97 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, tmp103_show_temp, NULL , | ||
98 | TMP103_TEMP_REG); | ||
99 | |||
100 | static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, tmp103_show_temp, | ||
101 | tmp103_set_temp, TMP103_TLOW_REG); | ||
102 | |||
103 | static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, tmp103_show_temp, | ||
104 | tmp103_set_temp, TMP103_THIGH_REG); | ||
105 | |||
106 | static struct attribute *tmp103_attrs[] = { | ||
107 | &sensor_dev_attr_temp1_input.dev_attr.attr, | ||
108 | &sensor_dev_attr_temp1_min.dev_attr.attr, | ||
109 | &sensor_dev_attr_temp1_max.dev_attr.attr, | ||
110 | NULL | ||
111 | }; | ||
112 | ATTRIBUTE_GROUPS(tmp103); | ||
113 | |||
114 | static bool tmp103_regmap_is_volatile(struct device *dev, unsigned int reg) | ||
115 | { | ||
116 | return reg == TMP103_TEMP_REG; | ||
117 | } | ||
118 | |||
119 | static const struct regmap_config tmp103_regmap_config = { | ||
120 | .reg_bits = 8, | ||
121 | .val_bits = 8, | ||
122 | .max_register = TMP103_THIGH_REG, | ||
123 | .volatile_reg = tmp103_regmap_is_volatile, | ||
124 | }; | ||
125 | |||
126 | static int tmp103_probe(struct i2c_client *client, | ||
127 | const struct i2c_device_id *id) | ||
128 | { | ||
129 | struct device *dev = &client->dev; | ||
130 | struct device *hwmon_dev; | ||
131 | struct regmap *regmap; | ||
132 | int ret; | ||
133 | |||
134 | if (!i2c_check_functionality(client->adapter, | ||
135 | I2C_FUNC_SMBUS_BYTE_DATA)) { | ||
136 | dev_err(&client->dev, | ||
137 | "adapter doesn't support SMBus byte transactions\n"); | ||
138 | return -ENODEV; | ||
139 | } | ||
140 | |||
141 | regmap = devm_regmap_init_i2c(client, &tmp103_regmap_config); | ||
142 | if (IS_ERR(regmap)) { | ||
143 | dev_err(dev, "failed to allocate register map\n"); | ||
144 | return PTR_ERR(regmap); | ||
145 | } | ||
146 | |||
147 | ret = regmap_update_bits(regmap, TMP103_CONF_REG, TMP103_CONFIG_MASK, | ||
148 | TMP103_CONFIG); | ||
149 | if (ret < 0) { | ||
150 | dev_err(&client->dev, "error writing config register\n"); | ||
151 | return ret; | ||
152 | } | ||
153 | |||
154 | i2c_set_clientdata(client, regmap); | ||
155 | hwmon_dev = hwmon_device_register_with_groups(dev, client->name, | ||
156 | regmap, tmp103_groups); | ||
157 | return PTR_ERR_OR_ZERO(hwmon_dev); | ||
158 | } | ||
159 | |||
160 | #ifdef CONFIG_PM | ||
161 | static int tmp103_suspend(struct device *dev) | ||
162 | { | ||
163 | struct regmap *regmap = dev_get_drvdata(dev); | ||
164 | |||
165 | return regmap_update_bits(regmap, TMP103_CONF_REG, | ||
166 | TMP103_CONF_SD_MASK, 0); | ||
167 | } | ||
168 | |||
169 | static int tmp103_resume(struct device *dev) | ||
170 | { | ||
171 | struct regmap *regmap = dev_get_drvdata(dev); | ||
172 | |||
173 | return regmap_update_bits(regmap, TMP103_CONF_REG, | ||
174 | TMP103_CONF_SD_MASK, TMP103_CONF_SD); | ||
175 | } | ||
176 | |||
177 | static const struct dev_pm_ops tmp103_dev_pm_ops = { | ||
178 | .suspend = tmp103_suspend, | ||
179 | .resume = tmp103_resume, | ||
180 | }; | ||
181 | |||
182 | #define TMP103_DEV_PM_OPS (&tmp103_dev_pm_ops) | ||
183 | #else | ||
184 | #define TMP103_DEV_PM_OPS NULL | ||
185 | #endif /* CONFIG_PM */ | ||
186 | |||
187 | static const struct i2c_device_id tmp103_id[] = { | ||
188 | { "tmp103", 0 }, | ||
189 | { } | ||
190 | }; | ||
191 | MODULE_DEVICE_TABLE(i2c, tmp103_id); | ||
192 | |||
193 | static struct i2c_driver tmp103_driver = { | ||
194 | .driver = { | ||
195 | .name = "tmp103", | ||
196 | .pm = TMP103_DEV_PM_OPS, | ||
197 | }, | ||
198 | .probe = tmp103_probe, | ||
199 | .id_table = tmp103_id, | ||
200 | }; | ||
201 | |||
202 | module_i2c_driver(tmp103_driver); | ||
203 | |||
204 | MODULE_AUTHOR("Heiko Schocher <hs@denx.de>"); | ||
205 | MODULE_DESCRIPTION("Texas Instruments TMP103 temperature sensor driver"); | ||
206 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c index 7bab7a9bedc6..85d48d80822a 100644 --- a/drivers/hwmon/tmp421.c +++ b/drivers/hwmon/tmp421.c | |||
@@ -13,15 +13,11 @@ | |||
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 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
20 | */ | 16 | */ |
21 | 17 | ||
22 | /* | 18 | /* |
23 | * Driver for the Texas Instruments TMP421 SMBus temperature sensor IC. | 19 | * Driver for the Texas Instruments TMP421 SMBus temperature sensor IC. |
24 | * Supported models: TMP421, TMP422, TMP423 | 20 | * Supported models: TMP421, TMP422, TMP423, TMP441, TMP442 |
25 | */ | 21 | */ |
26 | 22 | ||
27 | #include <linux/module.h> | 23 | #include <linux/module.h> |
@@ -39,9 +35,10 @@ | |||
39 | static const unsigned short normal_i2c[] = { 0x2a, 0x4c, 0x4d, 0x4e, 0x4f, | 35 | static const unsigned short normal_i2c[] = { 0x2a, 0x4c, 0x4d, 0x4e, 0x4f, |
40 | I2C_CLIENT_END }; | 36 | I2C_CLIENT_END }; |
41 | 37 | ||
42 | enum chips { tmp421, tmp422, tmp423 }; | 38 | enum chips { tmp421, tmp422, tmp423, tmp441, tmp442 }; |
43 | 39 | ||
44 | /* The TMP421 registers */ | 40 | /* The TMP421 registers */ |
41 | #define TMP421_STATUS_REG 0x08 | ||
45 | #define TMP421_CONFIG_REG_1 0x09 | 42 | #define TMP421_CONFIG_REG_1 0x09 |
46 | #define TMP421_CONVERSION_RATE_REG 0x0B | 43 | #define TMP421_CONVERSION_RATE_REG 0x0B |
47 | #define TMP421_MANUFACTURER_ID_REG 0xFE | 44 | #define TMP421_MANUFACTURER_ID_REG 0xFE |
@@ -59,11 +56,15 @@ static const u8 TMP421_TEMP_LSB[4] = { 0x10, 0x11, 0x12, 0x13 }; | |||
59 | #define TMP421_DEVICE_ID 0x21 | 56 | #define TMP421_DEVICE_ID 0x21 |
60 | #define TMP422_DEVICE_ID 0x22 | 57 | #define TMP422_DEVICE_ID 0x22 |
61 | #define TMP423_DEVICE_ID 0x23 | 58 | #define TMP423_DEVICE_ID 0x23 |
59 | #define TMP441_DEVICE_ID 0x41 | ||
60 | #define TMP442_DEVICE_ID 0x42 | ||
62 | 61 | ||
63 | static const struct i2c_device_id tmp421_id[] = { | 62 | static const struct i2c_device_id tmp421_id[] = { |
64 | { "tmp421", 2 }, | 63 | { "tmp421", 2 }, |
65 | { "tmp422", 3 }, | 64 | { "tmp422", 3 }, |
66 | { "tmp423", 4 }, | 65 | { "tmp423", 4 }, |
66 | { "tmp441", 2 }, | ||
67 | { "tmp442", 3 }, | ||
67 | { } | 68 | { } |
68 | }; | 69 | }; |
69 | MODULE_DEVICE_TABLE(i2c, tmp421_id); | 70 | MODULE_DEVICE_TABLE(i2c, tmp421_id); |
@@ -234,7 +235,9 @@ static int tmp421_detect(struct i2c_client *client, | |||
234 | { | 235 | { |
235 | enum chips kind; | 236 | enum chips kind; |
236 | struct i2c_adapter *adapter = client->adapter; | 237 | struct i2c_adapter *adapter = client->adapter; |
237 | const char *names[] = { "TMP421", "TMP422", "TMP423" }; | 238 | const char * const names[] = { "TMP421", "TMP422", "TMP423", |
239 | "TMP441", "TMP442" }; | ||
240 | int addr = client->addr; | ||
238 | u8 reg; | 241 | u8 reg; |
239 | 242 | ||
240 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 243 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
@@ -244,17 +247,37 @@ static int tmp421_detect(struct i2c_client *client, | |||
244 | if (reg != TMP421_MANUFACTURER_ID) | 247 | if (reg != TMP421_MANUFACTURER_ID) |
245 | return -ENODEV; | 248 | return -ENODEV; |
246 | 249 | ||
250 | reg = i2c_smbus_read_byte_data(client, TMP421_CONVERSION_RATE_REG); | ||
251 | if (reg & 0xf8) | ||
252 | return -ENODEV; | ||
253 | |||
254 | reg = i2c_smbus_read_byte_data(client, TMP421_STATUS_REG); | ||
255 | if (reg & 0x7f) | ||
256 | return -ENODEV; | ||
257 | |||
247 | reg = i2c_smbus_read_byte_data(client, TMP421_DEVICE_ID_REG); | 258 | reg = i2c_smbus_read_byte_data(client, TMP421_DEVICE_ID_REG); |
248 | switch (reg) { | 259 | switch (reg) { |
249 | case TMP421_DEVICE_ID: | 260 | case TMP421_DEVICE_ID: |
250 | kind = tmp421; | 261 | kind = tmp421; |
251 | break; | 262 | break; |
252 | case TMP422_DEVICE_ID: | 263 | case TMP422_DEVICE_ID: |
264 | if (addr == 0x2a) | ||
265 | return -ENODEV; | ||
253 | kind = tmp422; | 266 | kind = tmp422; |
254 | break; | 267 | break; |
255 | case TMP423_DEVICE_ID: | 268 | case TMP423_DEVICE_ID: |
269 | if (addr != 0x4c && addr != 0x4d) | ||
270 | return -ENODEV; | ||
256 | kind = tmp423; | 271 | kind = tmp423; |
257 | break; | 272 | break; |
273 | case TMP441_DEVICE_ID: | ||
274 | kind = tmp441; | ||
275 | break; | ||
276 | case TMP442_DEVICE_ID: | ||
277 | if (addr != 0x4c && addr != 0x4d) | ||
278 | return -ENODEV; | ||
279 | kind = tmp442; | ||
280 | break; | ||
258 | default: | 281 | default: |
259 | return -ENODEV; | 282 | return -ENODEV; |
260 | } | 283 | } |
@@ -305,5 +328,5 @@ static struct i2c_driver tmp421_driver = { | |||
305 | module_i2c_driver(tmp421_driver); | 328 | module_i2c_driver(tmp421_driver); |
306 | 329 | ||
307 | MODULE_AUTHOR("Andre Prendel <andre.prendel@gmx.de>"); | 330 | MODULE_AUTHOR("Andre Prendel <andre.prendel@gmx.de>"); |
308 | MODULE_DESCRIPTION("Texas Instruments TMP421/422/423 temperature sensor driver"); | 331 | MODULE_DESCRIPTION("Texas Instruments TMP421/422/423/441/442 temperature sensor driver"); |
309 | MODULE_LICENSE("GPL"); | 332 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/hwmon/twl4030-madc-hwmon.c b/drivers/hwmon/twl4030-madc-hwmon.c index 6c6d440bb2dd..9a0e2b8e8b94 100644 --- a/drivers/hwmon/twl4030-madc-hwmon.c +++ b/drivers/hwmon/twl4030-madc-hwmon.c | |||
@@ -74,7 +74,7 @@ static SENSOR_DEVICE_ATTR(in11_input, S_IRUGO, madc_read, NULL, 11); | |||
74 | static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, madc_read, NULL, 12); | 74 | static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, madc_read, NULL, 12); |
75 | static SENSOR_DEVICE_ATTR(in15_input, S_IRUGO, madc_read, NULL, 15); | 75 | static SENSOR_DEVICE_ATTR(in15_input, S_IRUGO, madc_read, NULL, 15); |
76 | 76 | ||
77 | static struct attribute *twl4030_madc_attributes[] = { | 77 | static struct attribute *twl4030_madc_attrs[] = { |
78 | &sensor_dev_attr_in0_input.dev_attr.attr, | 78 | &sensor_dev_attr_in0_input.dev_attr.attr, |
79 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 79 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
80 | &sensor_dev_attr_in2_input.dev_attr.attr, | 80 | &sensor_dev_attr_in2_input.dev_attr.attr, |
@@ -91,46 +91,20 @@ static struct attribute *twl4030_madc_attributes[] = { | |||
91 | &sensor_dev_attr_in15_input.dev_attr.attr, | 91 | &sensor_dev_attr_in15_input.dev_attr.attr, |
92 | NULL | 92 | NULL |
93 | }; | 93 | }; |
94 | 94 | ATTRIBUTE_GROUPS(twl4030_madc); | |
95 | static const struct attribute_group twl4030_madc_group = { | ||
96 | .attrs = twl4030_madc_attributes, | ||
97 | }; | ||
98 | 95 | ||
99 | static int twl4030_madc_hwmon_probe(struct platform_device *pdev) | 96 | static int twl4030_madc_hwmon_probe(struct platform_device *pdev) |
100 | { | 97 | { |
101 | int ret; | ||
102 | struct device *hwmon; | 98 | struct device *hwmon; |
103 | 99 | ||
104 | ret = sysfs_create_group(&pdev->dev.kobj, &twl4030_madc_group); | 100 | hwmon = devm_hwmon_device_register_with_groups(&pdev->dev, |
105 | if (ret) | 101 | "twl4030_madc", NULL, |
106 | goto err_sysfs; | 102 | twl4030_madc_groups); |
107 | hwmon = hwmon_device_register(&pdev->dev); | 103 | return PTR_ERR_OR_ZERO(hwmon); |
108 | if (IS_ERR(hwmon)) { | ||
109 | dev_err(&pdev->dev, "hwmon_device_register failed.\n"); | ||
110 | ret = PTR_ERR(hwmon); | ||
111 | goto err_reg; | ||
112 | } | ||
113 | |||
114 | return 0; | ||
115 | |||
116 | err_reg: | ||
117 | sysfs_remove_group(&pdev->dev.kobj, &twl4030_madc_group); | ||
118 | err_sysfs: | ||
119 | |||
120 | return ret; | ||
121 | } | ||
122 | |||
123 | static int twl4030_madc_hwmon_remove(struct platform_device *pdev) | ||
124 | { | ||
125 | hwmon_device_unregister(&pdev->dev); | ||
126 | sysfs_remove_group(&pdev->dev.kobj, &twl4030_madc_group); | ||
127 | |||
128 | return 0; | ||
129 | } | 104 | } |
130 | 105 | ||
131 | static struct platform_driver twl4030_madc_hwmon_driver = { | 106 | static struct platform_driver twl4030_madc_hwmon_driver = { |
132 | .probe = twl4030_madc_hwmon_probe, | 107 | .probe = twl4030_madc_hwmon_probe, |
133 | .remove = twl4030_madc_hwmon_remove, | ||
134 | .driver = { | 108 | .driver = { |
135 | .name = "twl4030_madc_hwmon", | 109 | .name = "twl4030_madc_hwmon", |
136 | .owner = THIS_MODULE, | 110 | .owner = THIS_MODULE, |
diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c index bdcf2dce5ec4..cb3765fec98c 100644 --- a/drivers/hwmon/w83791d.c +++ b/drivers/hwmon/w83791d.c | |||
@@ -249,19 +249,16 @@ static u8 fan_to_reg(long rpm, int div) | |||
249 | * the bottom 7 bits will always be zero | 249 | * the bottom 7 bits will always be zero |
250 | */ | 250 | */ |
251 | #define TEMP23_FROM_REG(val) ((val) / 128 * 500) | 251 | #define TEMP23_FROM_REG(val) ((val) / 128 * 500) |
252 | #define TEMP23_TO_REG(val) ((val) <= -128000 ? 0x8000 : \ | 252 | #define TEMP23_TO_REG(val) (DIV_ROUND_CLOSEST(clamp_val((val), -128000, \ |
253 | (val) >= 127500 ? 0x7F80 : \ | 253 | 127500), 500) * 128) |
254 | (val) < 0 ? ((val) - 250) / 500 * 128 : \ | ||
255 | ((val) + 250) / 500 * 128) | ||
256 | 254 | ||
257 | /* for thermal cruise target temp, 7-bits, LSB = 1 degree Celsius */ | 255 | /* for thermal cruise target temp, 7-bits, LSB = 1 degree Celsius */ |
258 | #define TARGET_TEMP_TO_REG(val) ((val) < 0 ? 0 : \ | 256 | #define TARGET_TEMP_TO_REG(val) DIV_ROUND_CLOSEST(clamp_val((val), 0, 127000), \ |
259 | (val) >= 127000 ? 127 : \ | 257 | 1000) |
260 | ((val) + 500) / 1000) | ||
261 | 258 | ||
262 | /* for thermal cruise temp tolerance, 4-bits, LSB = 1 degree Celsius */ | 259 | /* for thermal cruise temp tolerance, 4-bits, LSB = 1 degree Celsius */ |
263 | #define TOL_TEMP_TO_REG(val) ((val) >= 15000 ? 15 : \ | 260 | #define TOL_TEMP_TO_REG(val) DIV_ROUND_CLOSEST(clamp_val((val), 0, 15000), \ |
264 | ((val) + 500) / 1000) | 261 | 1000) |
265 | 262 | ||
266 | #define BEEP_MASK_TO_REG(val) ((val) & 0xffffff) | 263 | #define BEEP_MASK_TO_REG(val) ((val) & 0xffffff) |
267 | #define BEEP_MASK_FROM_REG(val) ((val) & 0xffffff) | 264 | #define BEEP_MASK_FROM_REG(val) ((val) & 0xffffff) |
diff --git a/drivers/hwmon/w83l786ng.c b/drivers/hwmon/w83l786ng.c index 32487c19cbfc..330299613d38 100644 --- a/drivers/hwmon/w83l786ng.c +++ b/drivers/hwmon/w83l786ng.c | |||
@@ -124,7 +124,7 @@ DIV_TO_REG(long val) | |||
124 | } | 124 | } |
125 | 125 | ||
126 | struct w83l786ng_data { | 126 | struct w83l786ng_data { |
127 | struct device *hwmon_dev; | 127 | struct i2c_client *client; |
128 | struct mutex update_lock; | 128 | struct mutex update_lock; |
129 | char valid; /* !=0 if following fields are valid */ | 129 | char valid; /* !=0 if following fields are valid */ |
130 | unsigned long last_updated; /* In jiffies */ | 130 | unsigned long last_updated; /* In jiffies */ |
@@ -148,32 +148,6 @@ struct w83l786ng_data { | |||
148 | u8 tolerance[2]; | 148 | u8 tolerance[2]; |
149 | }; | 149 | }; |
150 | 150 | ||
151 | static int w83l786ng_probe(struct i2c_client *client, | ||
152 | const struct i2c_device_id *id); | ||
153 | static int w83l786ng_detect(struct i2c_client *client, | ||
154 | struct i2c_board_info *info); | ||
155 | static int w83l786ng_remove(struct i2c_client *client); | ||
156 | static void w83l786ng_init_client(struct i2c_client *client); | ||
157 | static struct w83l786ng_data *w83l786ng_update_device(struct device *dev); | ||
158 | |||
159 | static const struct i2c_device_id w83l786ng_id[] = { | ||
160 | { "w83l786ng", 0 }, | ||
161 | { } | ||
162 | }; | ||
163 | MODULE_DEVICE_TABLE(i2c, w83l786ng_id); | ||
164 | |||
165 | static struct i2c_driver w83l786ng_driver = { | ||
166 | .class = I2C_CLASS_HWMON, | ||
167 | .driver = { | ||
168 | .name = "w83l786ng", | ||
169 | }, | ||
170 | .probe = w83l786ng_probe, | ||
171 | .remove = w83l786ng_remove, | ||
172 | .id_table = w83l786ng_id, | ||
173 | .detect = w83l786ng_detect, | ||
174 | .address_list = normal_i2c, | ||
175 | }; | ||
176 | |||
177 | static u8 | 151 | static u8 |
178 | w83l786ng_read_value(struct i2c_client *client, u8 reg) | 152 | w83l786ng_read_value(struct i2c_client *client, u8 reg) |
179 | { | 153 | { |
@@ -186,6 +160,77 @@ w83l786ng_write_value(struct i2c_client *client, u8 reg, u8 value) | |||
186 | return i2c_smbus_write_byte_data(client, reg, value); | 160 | return i2c_smbus_write_byte_data(client, reg, value); |
187 | } | 161 | } |
188 | 162 | ||
163 | static struct w83l786ng_data *w83l786ng_update_device(struct device *dev) | ||
164 | { | ||
165 | struct w83l786ng_data *data = dev_get_drvdata(dev); | ||
166 | struct i2c_client *client = data->client; | ||
167 | int i, j; | ||
168 | u8 reg_tmp, pwmcfg; | ||
169 | |||
170 | mutex_lock(&data->update_lock); | ||
171 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) | ||
172 | || !data->valid) { | ||
173 | dev_dbg(&client->dev, "Updating w83l786ng data.\n"); | ||
174 | |||
175 | /* Update the voltages measured value and limits */ | ||
176 | for (i = 0; i < 3; i++) { | ||
177 | data->in[i] = w83l786ng_read_value(client, | ||
178 | W83L786NG_REG_IN(i)); | ||
179 | data->in_min[i] = w83l786ng_read_value(client, | ||
180 | W83L786NG_REG_IN_MIN(i)); | ||
181 | data->in_max[i] = w83l786ng_read_value(client, | ||
182 | W83L786NG_REG_IN_MAX(i)); | ||
183 | } | ||
184 | |||
185 | /* Update the fan counts and limits */ | ||
186 | for (i = 0; i < 2; i++) { | ||
187 | data->fan[i] = w83l786ng_read_value(client, | ||
188 | W83L786NG_REG_FAN(i)); | ||
189 | data->fan_min[i] = w83l786ng_read_value(client, | ||
190 | W83L786NG_REG_FAN_MIN(i)); | ||
191 | } | ||
192 | |||
193 | /* Update the fan divisor */ | ||
194 | reg_tmp = w83l786ng_read_value(client, W83L786NG_REG_FAN_DIV); | ||
195 | data->fan_div[0] = reg_tmp & 0x07; | ||
196 | data->fan_div[1] = (reg_tmp >> 4) & 0x07; | ||
197 | |||
198 | pwmcfg = w83l786ng_read_value(client, W83L786NG_REG_FAN_CFG); | ||
199 | for (i = 0; i < 2; i++) { | ||
200 | data->pwm_mode[i] = | ||
201 | ((pwmcfg >> W83L786NG_PWM_MODE_SHIFT[i]) & 1) | ||
202 | ? 0 : 1; | ||
203 | data->pwm_enable[i] = | ||
204 | ((pwmcfg >> W83L786NG_PWM_ENABLE_SHIFT[i]) & 3) + 1; | ||
205 | data->pwm[i] = | ||
206 | (w83l786ng_read_value(client, W83L786NG_REG_PWM[i]) | ||
207 | & 0x0f) * 0x11; | ||
208 | } | ||
209 | |||
210 | |||
211 | /* Update the temperature sensors */ | ||
212 | for (i = 0; i < 2; i++) { | ||
213 | for (j = 0; j < 3; j++) { | ||
214 | data->temp[i][j] = w83l786ng_read_value(client, | ||
215 | W83L786NG_REG_TEMP[i][j]); | ||
216 | } | ||
217 | } | ||
218 | |||
219 | /* Update Smart Fan I/II tolerance */ | ||
220 | reg_tmp = w83l786ng_read_value(client, W83L786NG_REG_TOLERANCE); | ||
221 | data->tolerance[0] = reg_tmp & 0x0f; | ||
222 | data->tolerance[1] = (reg_tmp >> 4) & 0x0f; | ||
223 | |||
224 | data->last_updated = jiffies; | ||
225 | data->valid = 1; | ||
226 | |||
227 | } | ||
228 | |||
229 | mutex_unlock(&data->update_lock); | ||
230 | |||
231 | return data; | ||
232 | } | ||
233 | |||
189 | /* following are the sysfs callback functions */ | 234 | /* following are the sysfs callback functions */ |
190 | #define show_in_reg(reg) \ | 235 | #define show_in_reg(reg) \ |
191 | static ssize_t \ | 236 | static ssize_t \ |
@@ -207,8 +252,8 @@ store_in_##reg(struct device *dev, struct device_attribute *attr, \ | |||
207 | const char *buf, size_t count) \ | 252 | const char *buf, size_t count) \ |
208 | { \ | 253 | { \ |
209 | int nr = to_sensor_dev_attr(attr)->index; \ | 254 | int nr = to_sensor_dev_attr(attr)->index; \ |
210 | struct i2c_client *client = to_i2c_client(dev); \ | 255 | struct w83l786ng_data *data = dev_get_drvdata(dev); \ |
211 | struct w83l786ng_data *data = i2c_get_clientdata(client); \ | 256 | struct i2c_client *client = data->client; \ |
212 | unsigned long val; \ | 257 | unsigned long val; \ |
213 | int err = kstrtoul(buf, 10, &val); \ | 258 | int err = kstrtoul(buf, 10, &val); \ |
214 | if (err) \ | 259 | if (err) \ |
@@ -260,8 +305,8 @@ store_fan_min(struct device *dev, struct device_attribute *attr, | |||
260 | const char *buf, size_t count) | 305 | const char *buf, size_t count) |
261 | { | 306 | { |
262 | int nr = to_sensor_dev_attr(attr)->index; | 307 | int nr = to_sensor_dev_attr(attr)->index; |
263 | struct i2c_client *client = to_i2c_client(dev); | 308 | struct w83l786ng_data *data = dev_get_drvdata(dev); |
264 | struct w83l786ng_data *data = i2c_get_clientdata(client); | 309 | struct i2c_client *client = data->client; |
265 | unsigned long val; | 310 | unsigned long val; |
266 | int err; | 311 | int err; |
267 | 312 | ||
@@ -298,8 +343,8 @@ store_fan_div(struct device *dev, struct device_attribute *attr, | |||
298 | const char *buf, size_t count) | 343 | const char *buf, size_t count) |
299 | { | 344 | { |
300 | int nr = to_sensor_dev_attr(attr)->index; | 345 | int nr = to_sensor_dev_attr(attr)->index; |
301 | struct i2c_client *client = to_i2c_client(dev); | 346 | struct w83l786ng_data *data = dev_get_drvdata(dev); |
302 | struct w83l786ng_data *data = i2c_get_clientdata(client); | 347 | struct i2c_client *client = data->client; |
303 | 348 | ||
304 | unsigned long min; | 349 | unsigned long min; |
305 | u8 tmp_fan_div; | 350 | u8 tmp_fan_div; |
@@ -389,8 +434,8 @@ store_temp(struct device *dev, struct device_attribute *attr, | |||
389 | to_sensor_dev_attr_2(attr); | 434 | to_sensor_dev_attr_2(attr); |
390 | int nr = sensor_attr->nr; | 435 | int nr = sensor_attr->nr; |
391 | int index = sensor_attr->index; | 436 | int index = sensor_attr->index; |
392 | struct i2c_client *client = to_i2c_client(dev); | 437 | struct w83l786ng_data *data = dev_get_drvdata(dev); |
393 | struct w83l786ng_data *data = i2c_get_clientdata(client); | 438 | struct i2c_client *client = data->client; |
394 | long val; | 439 | long val; |
395 | int err; | 440 | int err; |
396 | 441 | ||
@@ -444,8 +489,8 @@ store_pwm_mode(struct device *dev, struct device_attribute *attr, | |||
444 | const char *buf, size_t count) | 489 | const char *buf, size_t count) |
445 | { | 490 | { |
446 | int nr = to_sensor_dev_attr(attr)->index; | 491 | int nr = to_sensor_dev_attr(attr)->index; |
447 | struct i2c_client *client = to_i2c_client(dev); | 492 | struct w83l786ng_data *data = dev_get_drvdata(dev); |
448 | struct w83l786ng_data *data = i2c_get_clientdata(client); | 493 | struct i2c_client *client = data->client; |
449 | u8 reg; | 494 | u8 reg; |
450 | unsigned long val; | 495 | unsigned long val; |
451 | int err; | 496 | int err; |
@@ -472,8 +517,8 @@ store_pwm(struct device *dev, struct device_attribute *attr, | |||
472 | const char *buf, size_t count) | 517 | const char *buf, size_t count) |
473 | { | 518 | { |
474 | int nr = to_sensor_dev_attr(attr)->index; | 519 | int nr = to_sensor_dev_attr(attr)->index; |
475 | struct i2c_client *client = to_i2c_client(dev); | 520 | struct w83l786ng_data *data = dev_get_drvdata(dev); |
476 | struct w83l786ng_data *data = i2c_get_clientdata(client); | 521 | struct i2c_client *client = data->client; |
477 | unsigned long val; | 522 | unsigned long val; |
478 | int err; | 523 | int err; |
479 | 524 | ||
@@ -496,8 +541,8 @@ store_pwm_enable(struct device *dev, struct device_attribute *attr, | |||
496 | const char *buf, size_t count) | 541 | const char *buf, size_t count) |
497 | { | 542 | { |
498 | int nr = to_sensor_dev_attr(attr)->index; | 543 | int nr = to_sensor_dev_attr(attr)->index; |
499 | struct i2c_client *client = to_i2c_client(dev); | 544 | struct w83l786ng_data *data = dev_get_drvdata(dev); |
500 | struct w83l786ng_data *data = i2c_get_clientdata(client); | 545 | struct i2c_client *client = data->client; |
501 | u8 reg; | 546 | u8 reg; |
502 | unsigned long val; | 547 | unsigned long val; |
503 | int err; | 548 | int err; |
@@ -552,8 +597,8 @@ store_tolerance(struct device *dev, struct device_attribute *attr, | |||
552 | const char *buf, size_t count) | 597 | const char *buf, size_t count) |
553 | { | 598 | { |
554 | int nr = to_sensor_dev_attr(attr)->index; | 599 | int nr = to_sensor_dev_attr(attr)->index; |
555 | struct i2c_client *client = to_i2c_client(dev); | 600 | struct w83l786ng_data *data = dev_get_drvdata(dev); |
556 | struct w83l786ng_data *data = i2c_get_clientdata(client); | 601 | struct i2c_client *client = data->client; |
557 | u8 tol_tmp, tol_mask; | 602 | u8 tol_tmp, tol_mask; |
558 | unsigned long val; | 603 | unsigned long val; |
559 | int err; | 604 | int err; |
@@ -608,7 +653,7 @@ static struct sensor_device_attribute sda_tolerance[] = { | |||
608 | #define TOLERANCE_UNIT_ATTRS(X) \ | 653 | #define TOLERANCE_UNIT_ATTRS(X) \ |
609 | &sda_tolerance[X].dev_attr.attr | 654 | &sda_tolerance[X].dev_attr.attr |
610 | 655 | ||
611 | static struct attribute *w83l786ng_attributes[] = { | 656 | static struct attribute *w83l786ng_attrs[] = { |
612 | IN_UNIT_ATTRS(0), | 657 | IN_UNIT_ATTRS(0), |
613 | IN_UNIT_ATTRS(1), | 658 | IN_UNIT_ATTRS(1), |
614 | IN_UNIT_ATTRS(2), | 659 | IN_UNIT_ATTRS(2), |
@@ -623,9 +668,7 @@ static struct attribute *w83l786ng_attributes[] = { | |||
623 | NULL | 668 | NULL |
624 | }; | 669 | }; |
625 | 670 | ||
626 | static const struct attribute_group w83l786ng_group = { | 671 | ATTRIBUTE_GROUPS(w83l786ng); |
627 | .attrs = w83l786ng_attributes, | ||
628 | }; | ||
629 | 672 | ||
630 | static int | 673 | static int |
631 | w83l786ng_detect(struct i2c_client *client, struct i2c_board_info *info) | 674 | w83l786ng_detect(struct i2c_client *client, struct i2c_board_info *info) |
@@ -662,20 +705,33 @@ w83l786ng_detect(struct i2c_client *client, struct i2c_board_info *info) | |||
662 | return 0; | 705 | return 0; |
663 | } | 706 | } |
664 | 707 | ||
708 | static void w83l786ng_init_client(struct i2c_client *client) | ||
709 | { | ||
710 | u8 tmp; | ||
711 | |||
712 | if (reset) | ||
713 | w83l786ng_write_value(client, W83L786NG_REG_CONFIG, 0x80); | ||
714 | |||
715 | /* Start monitoring */ | ||
716 | tmp = w83l786ng_read_value(client, W83L786NG_REG_CONFIG); | ||
717 | if (!(tmp & 0x01)) | ||
718 | w83l786ng_write_value(client, W83L786NG_REG_CONFIG, tmp | 0x01); | ||
719 | } | ||
720 | |||
665 | static int | 721 | static int |
666 | w83l786ng_probe(struct i2c_client *client, const struct i2c_device_id *id) | 722 | w83l786ng_probe(struct i2c_client *client, const struct i2c_device_id *id) |
667 | { | 723 | { |
668 | struct device *dev = &client->dev; | 724 | struct device *dev = &client->dev; |
669 | struct w83l786ng_data *data; | 725 | struct w83l786ng_data *data; |
670 | int i, err = 0; | 726 | struct device *hwmon_dev; |
727 | int i; | ||
671 | u8 reg_tmp; | 728 | u8 reg_tmp; |
672 | 729 | ||
673 | data = devm_kzalloc(&client->dev, sizeof(struct w83l786ng_data), | 730 | data = devm_kzalloc(dev, sizeof(struct w83l786ng_data), GFP_KERNEL); |
674 | GFP_KERNEL); | ||
675 | if (!data) | 731 | if (!data) |
676 | return -ENOMEM; | 732 | return -ENOMEM; |
677 | 733 | ||
678 | i2c_set_clientdata(client, data); | 734 | data->client = client; |
679 | mutex_init(&data->update_lock); | 735 | mutex_init(&data->update_lock); |
680 | 736 | ||
681 | /* Initialize the chip */ | 737 | /* Initialize the chip */ |
@@ -692,121 +748,28 @@ w83l786ng_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
692 | data->fan_div[0] = reg_tmp & 0x07; | 748 | data->fan_div[0] = reg_tmp & 0x07; |
693 | data->fan_div[1] = (reg_tmp >> 4) & 0x07; | 749 | data->fan_div[1] = (reg_tmp >> 4) & 0x07; |
694 | 750 | ||
695 | /* Register sysfs hooks */ | 751 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
696 | err = sysfs_create_group(&client->dev.kobj, &w83l786ng_group); | 752 | data, |
697 | if (err) | 753 | w83l786ng_groups); |
698 | goto exit_remove; | 754 | return PTR_ERR_OR_ZERO(hwmon_dev); |
699 | |||
700 | data->hwmon_dev = hwmon_device_register(dev); | ||
701 | if (IS_ERR(data->hwmon_dev)) { | ||
702 | err = PTR_ERR(data->hwmon_dev); | ||
703 | goto exit_remove; | ||
704 | } | ||
705 | |||
706 | return 0; | ||
707 | |||
708 | /* Unregister sysfs hooks */ | ||
709 | |||
710 | exit_remove: | ||
711 | sysfs_remove_group(&client->dev.kobj, &w83l786ng_group); | ||
712 | return err; | ||
713 | } | ||
714 | |||
715 | static int | ||
716 | w83l786ng_remove(struct i2c_client *client) | ||
717 | { | ||
718 | struct w83l786ng_data *data = i2c_get_clientdata(client); | ||
719 | |||
720 | hwmon_device_unregister(data->hwmon_dev); | ||
721 | sysfs_remove_group(&client->dev.kobj, &w83l786ng_group); | ||
722 | |||
723 | return 0; | ||
724 | } | 755 | } |
725 | 756 | ||
726 | static void | 757 | static const struct i2c_device_id w83l786ng_id[] = { |
727 | w83l786ng_init_client(struct i2c_client *client) | 758 | { "w83l786ng", 0 }, |
728 | { | 759 | { } |
729 | u8 tmp; | 760 | }; |
730 | 761 | MODULE_DEVICE_TABLE(i2c, w83l786ng_id); | |
731 | if (reset) | ||
732 | w83l786ng_write_value(client, W83L786NG_REG_CONFIG, 0x80); | ||
733 | |||
734 | /* Start monitoring */ | ||
735 | tmp = w83l786ng_read_value(client, W83L786NG_REG_CONFIG); | ||
736 | if (!(tmp & 0x01)) | ||
737 | w83l786ng_write_value(client, W83L786NG_REG_CONFIG, tmp | 0x01); | ||
738 | } | ||
739 | |||
740 | static struct w83l786ng_data *w83l786ng_update_device(struct device *dev) | ||
741 | { | ||
742 | struct i2c_client *client = to_i2c_client(dev); | ||
743 | struct w83l786ng_data *data = i2c_get_clientdata(client); | ||
744 | int i, j; | ||
745 | u8 reg_tmp, pwmcfg; | ||
746 | |||
747 | mutex_lock(&data->update_lock); | ||
748 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) | ||
749 | || !data->valid) { | ||
750 | dev_dbg(&client->dev, "Updating w83l786ng data.\n"); | ||
751 | |||
752 | /* Update the voltages measured value and limits */ | ||
753 | for (i = 0; i < 3; i++) { | ||
754 | data->in[i] = w83l786ng_read_value(client, | ||
755 | W83L786NG_REG_IN(i)); | ||
756 | data->in_min[i] = w83l786ng_read_value(client, | ||
757 | W83L786NG_REG_IN_MIN(i)); | ||
758 | data->in_max[i] = w83l786ng_read_value(client, | ||
759 | W83L786NG_REG_IN_MAX(i)); | ||
760 | } | ||
761 | |||
762 | /* Update the fan counts and limits */ | ||
763 | for (i = 0; i < 2; i++) { | ||
764 | data->fan[i] = w83l786ng_read_value(client, | ||
765 | W83L786NG_REG_FAN(i)); | ||
766 | data->fan_min[i] = w83l786ng_read_value(client, | ||
767 | W83L786NG_REG_FAN_MIN(i)); | ||
768 | } | ||
769 | |||
770 | /* Update the fan divisor */ | ||
771 | reg_tmp = w83l786ng_read_value(client, W83L786NG_REG_FAN_DIV); | ||
772 | data->fan_div[0] = reg_tmp & 0x07; | ||
773 | data->fan_div[1] = (reg_tmp >> 4) & 0x07; | ||
774 | |||
775 | pwmcfg = w83l786ng_read_value(client, W83L786NG_REG_FAN_CFG); | ||
776 | for (i = 0; i < 2; i++) { | ||
777 | data->pwm_mode[i] = | ||
778 | ((pwmcfg >> W83L786NG_PWM_MODE_SHIFT[i]) & 1) | ||
779 | ? 0 : 1; | ||
780 | data->pwm_enable[i] = | ||
781 | ((pwmcfg >> W83L786NG_PWM_ENABLE_SHIFT[i]) & 3) + 1; | ||
782 | data->pwm[i] = | ||
783 | (w83l786ng_read_value(client, W83L786NG_REG_PWM[i]) | ||
784 | & 0x0f) * 0x11; | ||
785 | } | ||
786 | |||
787 | |||
788 | /* Update the temperature sensors */ | ||
789 | for (i = 0; i < 2; i++) { | ||
790 | for (j = 0; j < 3; j++) { | ||
791 | data->temp[i][j] = w83l786ng_read_value(client, | ||
792 | W83L786NG_REG_TEMP[i][j]); | ||
793 | } | ||
794 | } | ||
795 | |||
796 | /* Update Smart Fan I/II tolerance */ | ||
797 | reg_tmp = w83l786ng_read_value(client, W83L786NG_REG_TOLERANCE); | ||
798 | data->tolerance[0] = reg_tmp & 0x0f; | ||
799 | data->tolerance[1] = (reg_tmp >> 4) & 0x0f; | ||
800 | |||
801 | data->last_updated = jiffies; | ||
802 | data->valid = 1; | ||
803 | |||
804 | } | ||
805 | |||
806 | mutex_unlock(&data->update_lock); | ||
807 | 762 | ||
808 | return data; | 763 | static struct i2c_driver w83l786ng_driver = { |
809 | } | 764 | .class = I2C_CLASS_HWMON, |
765 | .driver = { | ||
766 | .name = "w83l786ng", | ||
767 | }, | ||
768 | .probe = w83l786ng_probe, | ||
769 | .id_table = w83l786ng_id, | ||
770 | .detect = w83l786ng_detect, | ||
771 | .address_list = normal_i2c, | ||
772 | }; | ||
810 | 773 | ||
811 | module_i2c_driver(w83l786ng_driver); | 774 | module_i2c_driver(w83l786ng_driver); |
812 | 775 | ||
diff --git a/drivers/hwmon/wm831x-hwmon.c b/drivers/hwmon/wm831x-hwmon.c index df6ceaf8d58a..3e6a3195cd11 100644 --- a/drivers/hwmon/wm831x-hwmon.c +++ b/drivers/hwmon/wm831x-hwmon.c | |||
@@ -29,17 +29,6 @@ | |||
29 | #include <linux/mfd/wm831x/core.h> | 29 | #include <linux/mfd/wm831x/core.h> |
30 | #include <linux/mfd/wm831x/auxadc.h> | 30 | #include <linux/mfd/wm831x/auxadc.h> |
31 | 31 | ||
32 | struct wm831x_hwmon { | ||
33 | struct wm831x *wm831x; | ||
34 | struct device *classdev; | ||
35 | }; | ||
36 | |||
37 | static ssize_t show_name(struct device *dev, | ||
38 | struct device_attribute *attr, char *buf) | ||
39 | { | ||
40 | return sprintf(buf, "wm831x\n"); | ||
41 | } | ||
42 | |||
43 | static const char * const input_names[] = { | 32 | static const char * const input_names[] = { |
44 | [WM831X_AUX_SYSVDD] = "SYSVDD", | 33 | [WM831X_AUX_SYSVDD] = "SYSVDD", |
45 | [WM831X_AUX_USB] = "USB", | 34 | [WM831X_AUX_USB] = "USB", |
@@ -50,15 +39,14 @@ static const char * const input_names[] = { | |||
50 | [WM831X_AUX_BATT_TEMP] = "Battery", | 39 | [WM831X_AUX_BATT_TEMP] = "Battery", |
51 | }; | 40 | }; |
52 | 41 | ||
53 | |||
54 | static ssize_t show_voltage(struct device *dev, | 42 | static ssize_t show_voltage(struct device *dev, |
55 | struct device_attribute *attr, char *buf) | 43 | struct device_attribute *attr, char *buf) |
56 | { | 44 | { |
57 | struct wm831x_hwmon *hwmon = dev_get_drvdata(dev); | 45 | struct wm831x *wm831x = dev_get_drvdata(dev); |
58 | int channel = to_sensor_dev_attr(attr)->index; | 46 | int channel = to_sensor_dev_attr(attr)->index; |
59 | int ret; | 47 | int ret; |
60 | 48 | ||
61 | ret = wm831x_auxadc_read_uv(hwmon->wm831x, channel); | 49 | ret = wm831x_auxadc_read_uv(wm831x, channel); |
62 | if (ret < 0) | 50 | if (ret < 0) |
63 | return ret; | 51 | return ret; |
64 | 52 | ||
@@ -68,11 +56,11 @@ static ssize_t show_voltage(struct device *dev, | |||
68 | static ssize_t show_chip_temp(struct device *dev, | 56 | static ssize_t show_chip_temp(struct device *dev, |
69 | struct device_attribute *attr, char *buf) | 57 | struct device_attribute *attr, char *buf) |
70 | { | 58 | { |
71 | struct wm831x_hwmon *hwmon = dev_get_drvdata(dev); | 59 | struct wm831x *wm831x = dev_get_drvdata(dev); |
72 | int channel = to_sensor_dev_attr(attr)->index; | 60 | int channel = to_sensor_dev_attr(attr)->index; |
73 | int ret; | 61 | int ret; |
74 | 62 | ||
75 | ret = wm831x_auxadc_read(hwmon->wm831x, channel); | 63 | ret = wm831x_auxadc_read(wm831x, channel); |
76 | if (ret < 0) | 64 | if (ret < 0) |
77 | return ret; | 65 | return ret; |
78 | 66 | ||
@@ -100,8 +88,6 @@ static ssize_t show_label(struct device *dev, | |||
100 | static SENSOR_DEVICE_ATTR(in##id##_label, S_IRUGO, show_label, \ | 88 | static SENSOR_DEVICE_ATTR(in##id##_label, S_IRUGO, show_label, \ |
101 | NULL, name) | 89 | NULL, name) |
102 | 90 | ||
103 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | ||
104 | |||
105 | WM831X_VOLTAGE(0, WM831X_AUX_AUX1); | 91 | WM831X_VOLTAGE(0, WM831X_AUX_AUX1); |
106 | WM831X_VOLTAGE(1, WM831X_AUX_AUX2); | 92 | WM831X_VOLTAGE(1, WM831X_AUX_AUX2); |
107 | WM831X_VOLTAGE(2, WM831X_AUX_AUX3); | 93 | WM831X_VOLTAGE(2, WM831X_AUX_AUX3); |
@@ -126,9 +112,7 @@ static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_voltage, NULL, | |||
126 | static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, show_label, NULL, | 112 | static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, show_label, NULL, |
127 | WM831X_AUX_BATT_TEMP); | 113 | WM831X_AUX_BATT_TEMP); |
128 | 114 | ||
129 | static struct attribute *wm831x_attributes[] = { | 115 | static struct attribute *wm831x_attrs[] = { |
130 | &dev_attr_name.attr, | ||
131 | |||
132 | &sensor_dev_attr_in0_input.dev_attr.attr, | 116 | &sensor_dev_attr_in0_input.dev_attr.attr, |
133 | &sensor_dev_attr_in1_input.dev_attr.attr, | 117 | &sensor_dev_attr_in1_input.dev_attr.attr, |
134 | &sensor_dev_attr_in2_input.dev_attr.attr, | 118 | &sensor_dev_attr_in2_input.dev_attr.attr, |
@@ -153,55 +137,21 @@ static struct attribute *wm831x_attributes[] = { | |||
153 | NULL | 137 | NULL |
154 | }; | 138 | }; |
155 | 139 | ||
156 | static const struct attribute_group wm831x_attr_group = { | 140 | ATTRIBUTE_GROUPS(wm831x); |
157 | .attrs = wm831x_attributes, | ||
158 | }; | ||
159 | 141 | ||
160 | static int wm831x_hwmon_probe(struct platform_device *pdev) | 142 | static int wm831x_hwmon_probe(struct platform_device *pdev) |
161 | { | 143 | { |
162 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); | 144 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); |
163 | struct wm831x_hwmon *hwmon; | 145 | struct device *hwmon_dev; |
164 | int ret; | ||
165 | |||
166 | hwmon = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_hwmon), | ||
167 | GFP_KERNEL); | ||
168 | if (!hwmon) | ||
169 | return -ENOMEM; | ||
170 | |||
171 | hwmon->wm831x = wm831x; | ||
172 | |||
173 | ret = sysfs_create_group(&pdev->dev.kobj, &wm831x_attr_group); | ||
174 | if (ret) | ||
175 | return ret; | ||
176 | |||
177 | hwmon->classdev = hwmon_device_register(&pdev->dev); | ||
178 | if (IS_ERR(hwmon->classdev)) { | ||
179 | ret = PTR_ERR(hwmon->classdev); | ||
180 | goto err_sysfs; | ||
181 | } | ||
182 | |||
183 | platform_set_drvdata(pdev, hwmon); | ||
184 | |||
185 | return 0; | ||
186 | |||
187 | err_sysfs: | ||
188 | sysfs_remove_group(&pdev->dev.kobj, &wm831x_attr_group); | ||
189 | return ret; | ||
190 | } | ||
191 | |||
192 | static int wm831x_hwmon_remove(struct platform_device *pdev) | ||
193 | { | ||
194 | struct wm831x_hwmon *hwmon = platform_get_drvdata(pdev); | ||
195 | |||
196 | hwmon_device_unregister(hwmon->classdev); | ||
197 | sysfs_remove_group(&pdev->dev.kobj, &wm831x_attr_group); | ||
198 | 146 | ||
199 | return 0; | 147 | hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev, "wm831x", |
148 | wm831x, | ||
149 | wm831x_groups); | ||
150 | return PTR_ERR_OR_ZERO(hwmon_dev); | ||
200 | } | 151 | } |
201 | 152 | ||
202 | static struct platform_driver wm831x_hwmon_driver = { | 153 | static struct platform_driver wm831x_hwmon_driver = { |
203 | .probe = wm831x_hwmon_probe, | 154 | .probe = wm831x_hwmon_probe, |
204 | .remove = wm831x_hwmon_remove, | ||
205 | .driver = { | 155 | .driver = { |
206 | .name = "wm831x-hwmon", | 156 | .name = "wm831x-hwmon", |
207 | .owner = THIS_MODULE, | 157 | .owner = THIS_MODULE, |
diff --git a/drivers/hwmon/wm8350-hwmon.c b/drivers/hwmon/wm8350-hwmon.c index 64bf75c9442b..90e3d918e597 100644 --- a/drivers/hwmon/wm8350-hwmon.c +++ b/drivers/hwmon/wm8350-hwmon.c | |||
@@ -28,19 +28,12 @@ | |||
28 | #include <linux/mfd/wm8350/core.h> | 28 | #include <linux/mfd/wm8350/core.h> |
29 | #include <linux/mfd/wm8350/comparator.h> | 29 | #include <linux/mfd/wm8350/comparator.h> |
30 | 30 | ||
31 | static ssize_t show_name(struct device *dev, | ||
32 | struct device_attribute *attr, char *buf) | ||
33 | { | ||
34 | return sprintf(buf, "wm8350\n"); | ||
35 | } | ||
36 | |||
37 | static const char * const input_names[] = { | 31 | static const char * const input_names[] = { |
38 | [WM8350_AUXADC_USB] = "USB", | 32 | [WM8350_AUXADC_USB] = "USB", |
39 | [WM8350_AUXADC_LINE] = "Line", | 33 | [WM8350_AUXADC_LINE] = "Line", |
40 | [WM8350_AUXADC_BATT] = "Battery", | 34 | [WM8350_AUXADC_BATT] = "Battery", |
41 | }; | 35 | }; |
42 | 36 | ||
43 | |||
44 | static ssize_t show_voltage(struct device *dev, | 37 | static ssize_t show_voltage(struct device *dev, |
45 | struct device_attribute *attr, char *buf) | 38 | struct device_attribute *attr, char *buf) |
46 | { | 39 | { |
@@ -68,15 +61,11 @@ static ssize_t show_label(struct device *dev, | |||
68 | static SENSOR_DEVICE_ATTR(in##id##_label, S_IRUGO, show_label, \ | 61 | static SENSOR_DEVICE_ATTR(in##id##_label, S_IRUGO, show_label, \ |
69 | NULL, name) | 62 | NULL, name) |
70 | 63 | ||
71 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | ||
72 | |||
73 | WM8350_NAMED_VOLTAGE(0, WM8350_AUXADC_USB); | 64 | WM8350_NAMED_VOLTAGE(0, WM8350_AUXADC_USB); |
74 | WM8350_NAMED_VOLTAGE(1, WM8350_AUXADC_BATT); | 65 | WM8350_NAMED_VOLTAGE(1, WM8350_AUXADC_BATT); |
75 | WM8350_NAMED_VOLTAGE(2, WM8350_AUXADC_LINE); | 66 | WM8350_NAMED_VOLTAGE(2, WM8350_AUXADC_LINE); |
76 | 67 | ||
77 | static struct attribute *wm8350_attributes[] = { | 68 | static struct attribute *wm8350_attrs[] = { |
78 | &dev_attr_name.attr, | ||
79 | |||
80 | &sensor_dev_attr_in0_input.dev_attr.attr, | 69 | &sensor_dev_attr_in0_input.dev_attr.attr, |
81 | &sensor_dev_attr_in0_label.dev_attr.attr, | 70 | &sensor_dev_attr_in0_label.dev_attr.attr, |
82 | &sensor_dev_attr_in1_input.dev_attr.attr, | 71 | &sensor_dev_attr_in1_input.dev_attr.attr, |
@@ -87,46 +76,21 @@ static struct attribute *wm8350_attributes[] = { | |||
87 | NULL, | 76 | NULL, |
88 | }; | 77 | }; |
89 | 78 | ||
90 | static const struct attribute_group wm8350_attr_group = { | 79 | ATTRIBUTE_GROUPS(wm8350); |
91 | .attrs = wm8350_attributes, | ||
92 | }; | ||
93 | 80 | ||
94 | static int wm8350_hwmon_probe(struct platform_device *pdev) | 81 | static int wm8350_hwmon_probe(struct platform_device *pdev) |
95 | { | 82 | { |
96 | struct wm8350 *wm8350 = platform_get_drvdata(pdev); | 83 | struct wm8350 *wm8350 = platform_get_drvdata(pdev); |
97 | int ret; | 84 | struct device *hwmon_dev; |
98 | |||
99 | ret = sysfs_create_group(&pdev->dev.kobj, &wm8350_attr_group); | ||
100 | if (ret) | ||
101 | goto err; | ||
102 | |||
103 | wm8350->hwmon.classdev = hwmon_device_register(&pdev->dev); | ||
104 | if (IS_ERR(wm8350->hwmon.classdev)) { | ||
105 | ret = PTR_ERR(wm8350->hwmon.classdev); | ||
106 | goto err_group; | ||
107 | } | ||
108 | |||
109 | return 0; | ||
110 | |||
111 | err_group: | ||
112 | sysfs_remove_group(&pdev->dev.kobj, &wm8350_attr_group); | ||
113 | err: | ||
114 | return ret; | ||
115 | } | ||
116 | |||
117 | static int wm8350_hwmon_remove(struct platform_device *pdev) | ||
118 | { | ||
119 | struct wm8350 *wm8350 = platform_get_drvdata(pdev); | ||
120 | |||
121 | hwmon_device_unregister(wm8350->hwmon.classdev); | ||
122 | sysfs_remove_group(&pdev->dev.kobj, &wm8350_attr_group); | ||
123 | 85 | ||
124 | return 0; | 86 | hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev, "wm8350", |
87 | wm8350, | ||
88 | wm8350_groups); | ||
89 | return PTR_ERR_OR_ZERO(hwmon_dev); | ||
125 | } | 90 | } |
126 | 91 | ||
127 | static struct platform_driver wm8350_hwmon_driver = { | 92 | static struct platform_driver wm8350_hwmon_driver = { |
128 | .probe = wm8350_hwmon_probe, | 93 | .probe = wm8350_hwmon_probe, |
129 | .remove = wm8350_hwmon_remove, | ||
130 | .driver = { | 94 | .driver = { |
131 | .name = "wm8350-hwmon", | 95 | .name = "wm8350-hwmon", |
132 | .owner = THIS_MODULE, | 96 | .owner = THIS_MODULE, |
diff --git a/include/linux/platform_data/ntc_thermistor.h b/include/linux/platform_data/ntc_thermistor.h index c7285b575462..0a6de4ca4930 100644 --- a/include/linux/platform_data/ntc_thermistor.h +++ b/include/linux/platform_data/ntc_thermistor.h | |||
@@ -26,6 +26,7 @@ struct iio_channel; | |||
26 | enum ntc_thermistor_type { | 26 | enum ntc_thermistor_type { |
27 | TYPE_NCPXXWB473, | 27 | TYPE_NCPXXWB473, |
28 | TYPE_NCPXXWL333, | 28 | TYPE_NCPXXWL333, |
29 | TYPE_B57330V2103, | ||
29 | }; | 30 | }; |
30 | 31 | ||
31 | struct ntc_thermistor_platform_data { | 32 | struct ntc_thermistor_platform_data { |