aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-04-01 16:51:48 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-04-01 16:51:48 -0400
commit26f31fb936042459d481557a83bda7a3f4d61906 (patch)
tree1d871ee1c82896355ad0aef6eea8dbd601d8169d
parent0c8cfbade0e9bef5637907ed00c7b81bc86ad359 (diff)
parentf76992b00a4111fc4679b0b2d49fe75f05c2b04d (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: - New drivers for ADC128D818, LTC2945, LTC4260, and LTC4222 - Added support for LTM4676 to ltc2978 driver - Converted several drivers to use devm_hwmon_device_register_with_groups - Various cleanup in several drivers * tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: (36 commits) hwmon: (pmbus/ltc2978) Add support for LTM4676 hwmon: (pmbus/ltc2978) Add new chip ID for LTC2974 hwmon: Do not accept invalid name attributes hwmon: (max6639) Use SIMPLE_DEV_PM_OPS macro hwmon: (lm95245) Make temp2_crit_hyst read-only hwmon: (lm95245) Convert to use devm_hwmon_device_register_with_groups hwmon: (lm95245) Drop useless debug message hwmon: (lm95245) Fix hysteresis temperatures hwmon: (max6639) Convert to use devm_hwmon_device_register_with_groups hwmon: (max6639) Introduce local dev variable, and reduce noisiness hwmon: (max6650) Introduce local 'dev' variable hwmon: (max6650) Drop error message after memory allocation failures hwmon: (max6650) Convert to use devm_hwmon_device_register_with_groups hwmon: (max6650) Rearrange code to no longer require forward declarations hwmon: (ltc4215) Convert to devm_hwmon_device_register_with_groups hwmon: (coretemp) Convert to use devm_hwmon_device_register_with_groups hwmon: (coretemp) Allocate platform data with devm_kzalloc hwmon: (coretemp) Use sysfs_create_group to create sysfs attributes hwmon: (ltc4245) Remove devicetree conditionals hwmon: (ltc4245) Drop debug messages ...
-rw-r--r--Documentation/hwmon/adc128d81847
-rw-r--r--Documentation/hwmon/lm952458
-rw-r--r--Documentation/hwmon/ltc294584
-rw-r--r--Documentation/hwmon/ltc297817
-rw-r--r--Documentation/hwmon/ltc426056
-rw-r--r--drivers/hwmon/Kconfig600
-rw-r--r--drivers/hwmon/Makefile4
-rw-r--r--drivers/hwmon/adc128d818.c491
-rw-r--r--drivers/hwmon/coretemp.c71
-rw-r--r--drivers/hwmon/emc2103.c2
-rw-r--r--drivers/hwmon/hwmon.c5
-rw-r--r--drivers/hwmon/iio_hwmon.c37
-rw-r--r--drivers/hwmon/jz4740-hwmon.c25
-rw-r--r--drivers/hwmon/lm95241.c93
-rw-r--r--drivers/hwmon/lm95245.c112
-rw-r--r--drivers/hwmon/ltc2945.c519
-rw-r--r--drivers/hwmon/ltc4215.c51
-rw-r--r--drivers/hwmon/ltc4222.c237
-rw-r--r--drivers/hwmon/ltc4245.c30
-rw-r--r--drivers/hwmon/ltc4260.c200
-rw-r--r--drivers/hwmon/max1668.c81
-rw-r--r--drivers/hwmon/max6639.c91
-rw-r--r--drivers/hwmon/max6650.c257
-rw-r--r--drivers/hwmon/pmbus/ltc2978.c25
-rw-r--r--drivers/hwmon/smm665.c2
25 files changed, 2292 insertions, 853 deletions
diff --git a/Documentation/hwmon/adc128d818 b/Documentation/hwmon/adc128d818
new file mode 100644
index 000000000000..39c95004dabc
--- /dev/null
+++ b/Documentation/hwmon/adc128d818
@@ -0,0 +1,47 @@
1Kernel driver adc128d818
2========================
3
4Supported chips:
5 * Texas Instruments ADC818D818
6 Prefix: 'adc818d818'
7 Addresses scanned: I2C 0x1d, 0x1e, 0x1f, 0x2d, 0x2e, 0x2f
8 Datasheet: Publicly available at the TI website
9 http://www.ti.com/
10
11Author: Guenter Roeck
12
13Description
14-----------
15
16This driver implements support for the Texas Instruments ADC128D818.
17It is described as 'ADC System Monitor with Temperature Sensor'.
18
19The ADC128D818 implements one temperature sensor and seven voltage sensors.
20
21Temperatures are measured in degrees Celsius. There is one set of limits.
22When the HOT Temperature Limit is crossed, this will cause an alarm that will
23be reasserted until the temperature drops below the HOT Hysteresis.
24Measurements are guaranteed between -55 and +125 degrees. The temperature
25measurement has a resolution of 0.5 degrees; the limits have a resolution
26of 1 degree.
27
28Voltage sensors (also known as IN sensors) report their values in volts.
29An alarm is triggered if the voltage has crossed a programmable minimum
30or maximum limit. Note that minimum in this case always means 'closest to
31zero'; this is important for negative voltage measurements. All voltage
32inputs can measure voltages between 0 and 2.55 volts, with a resolution
33of 0.625 mV.
34
35If an alarm triggers, it will remain triggered until the hardware register
36is read at least once. This means that the cause for the alarm may
37already have disappeared by the time the alarm is read. The driver
38caches the alarm status for each sensor until it is at least reported
39once, to ensure that alarms are reported to user space.
40
41The ADC128D818 only updates its values approximately once per second;
42reading it more often will do no harm, but will return 'old' values.
43
44In addition to the scanned address list, the chip can also be configured for
45addresses 0x35 to 0x37. Those addresses are not scanned. You have to instantiate
46the driver explicitly if the chip is configured for any of those addresses in
47your system.
diff --git a/Documentation/hwmon/lm95245 b/Documentation/hwmon/lm95245
index cbd8aeab7124..77eaf2812d25 100644
--- a/Documentation/hwmon/lm95245
+++ b/Documentation/hwmon/lm95245
@@ -24,8 +24,12 @@ is given within a range of -127 to +127.875 degrees. Remote temperatures are
24given within a range of -127 to +255 degrees. Resolution depends on 24given within a range of -127 to +255 degrees. Resolution depends on
25temperature input and range. 25temperature input and range.
26 26
27Each sensor has its own critical limit, but the hysteresis is common to all 27Each sensor has its own critical limit. Additionally, there is a relative
28two channels. 28hysteresis value common to both critical limits. To make life easier to
29user-space applications, two absolute values are exported, one for each
30channel, but these values are of course linked. Only the local hysteresis
31can be set from user-space, and the same delta applies to the remote
32hysteresis.
29 33
30The lm95245 driver can change its update interval to a fixed set of values. 34The lm95245 driver can change its update interval to a fixed set of values.
31It will round up to the next selectable interval. See the datasheet for exact 35It will round up to the next selectable interval. See the datasheet for exact
diff --git a/Documentation/hwmon/ltc2945 b/Documentation/hwmon/ltc2945
new file mode 100644
index 000000000000..f8d0f7f19adb
--- /dev/null
+++ b/Documentation/hwmon/ltc2945
@@ -0,0 +1,84 @@
1Kernel driver ltc2945
2=====================
3
4Supported chips:
5 * Linear Technology LTC2945
6 Prefix: 'ltc2945'
7 Addresses scanned: -
8 Datasheet:
9 http://cds.linear.com/docs/en/datasheet/2945fa.pdf
10
11Author: Guenter Roeck <linux@roeck-us.net>
12
13
14Description
15-----------
16
17The LTC2945 is a rail-to-rail system monitor that measures current, voltage,
18and power consumption.
19
20
21Usage Notes
22-----------
23
24This driver does not probe for LTC2945 devices, since there is no register
25which can be safely used to identify the chip. You will have to instantiate
26the devices explicitly.
27
28Example: the following will load the driver for an LTC2945 at address 0x10
29on I2C bus #1:
30$ modprobe ltc2945
31$ echo ltc2945 0x10 > /sys/bus/i2c/devices/i2c-1/new_device
32
33
34Sysfs entries
35-------------
36
37Voltage readings provided by this driver are reported as obtained from the ADC
38registers. If a set of voltage divider resistors is installed, calculate the
39real voltage by multiplying the reported value with (R1+R2)/R2, where R1 is the
40value of the divider resistor against the measured voltage and R2 is the value
41of the divider resistor against Ground.
42
43Current reading provided by this driver is reported as obtained from the ADC
44Current Sense register. The reported value assumes that a 1 mOhm sense resistor
45is installed. If a different sense resistor is installed, calculate the real
46current by dividing the reported value by the sense resistor value in mOhm.
47
48in1_input VIN voltage (mV). Voltage is measured either at
49 SENSE+ or VDD pin depending on chip configuration.
50in1_min Undervoltage threshold
51in1_max Overvoltage threshold
52in1_lowest Lowest measured voltage
53in1_highest Highest measured voltage
54in1_reset_history Write 1 to reset in1 history
55in1_min_alarm Undervoltage alarm
56in1_max_alarm Overvoltage alarm
57
58in2_input ADIN voltage (mV)
59in2_min Undervoltage threshold
60in2_max Overvoltage threshold
61in2_lowest Lowest measured voltage
62in2_highest Highest measured voltage
63in2_reset_history Write 1 to reset in2 history
64in2_min_alarm Undervoltage alarm
65in2_max_alarm Overvoltage alarm
66
67curr1_input SENSE current (mA)
68curr1_min Undercurrent threshold
69curr1_max Overcurrent threshold
70curr1_lowest Lowest measured current
71curr1_highest Highest measured current
72curr1_reset_history Write 1 to reset curr1 history
73curr1_min_alarm Undercurrent alarm
74curr1_max_alarm Overcurrent alarm
75
76power1_input Power (in uW). Power is calculated based on SENSE+/VDD
77 voltage or ADIN voltage depending on chip configuration.
78power1_min Low lower threshold
79power1_max High power threshold
80power1_input_lowest Historical minimum power use
81power1_input_highest Historical maximum power use
82power1_reset_history Write 1 to reset power1 history
83power1_min_alarm Low power alarm
84power1_max_alarm High power alarm
diff --git a/Documentation/hwmon/ltc2978 b/Documentation/hwmon/ltc2978
index a0546fc42273..686c078bb0e0 100644
--- a/Documentation/hwmon/ltc2978
+++ b/Documentation/hwmon/ltc2978
@@ -23,6 +23,10 @@ Supported chips:
23 Prefix: 'ltc3883' 23 Prefix: 'ltc3883'
24 Addresses scanned: - 24 Addresses scanned: -
25 Datasheet: http://www.linear.com/product/ltc3883 25 Datasheet: http://www.linear.com/product/ltc3883
26 * Linear Technology LTM4676
27 Prefix: 'ltm4676'
28 Addresses scanned: -
29 Datasheet: http://www.linear.com/product/ltm4676
26 30
27Author: Guenter Roeck <linux@roeck-us.net> 31Author: Guenter Roeck <linux@roeck-us.net>
28 32
@@ -33,7 +37,8 @@ Description
33LTC2974 is a quad digital power supply manager. LTC2978 is an octal power supply 37LTC2974 is a quad digital power supply manager. LTC2978 is an octal power supply
34monitor. LTC2977 is a pin compatible replacement for LTC2978. LTC3880 is a dual 38monitor. LTC2977 is a pin compatible replacement for LTC2978. LTC3880 is a dual
35output poly-phase step-down DC/DC controller. LTC3883 is a single phase 39output poly-phase step-down DC/DC controller. LTC3883 is a single phase
36step-down DC/DC controller. 40step-down DC/DC controller. LTM4676 is a dual 13A or single 26A uModule
41regulator.
37 42
38 43
39Usage Notes 44Usage Notes
@@ -75,7 +80,7 @@ in[N]_label "vout[1-8]".
75 LTC2974: N=2-5 80 LTC2974: N=2-5
76 LTC2977: N=2-9 81 LTC2977: N=2-9
77 LTC2978: N=2-9 82 LTC2978: N=2-9
78 LTC3880: N=2-3 83 LTC3880, LTM4676: N=2-3
79 LTC3883: N=2 84 LTC3883: N=2
80in[N]_input Measured output voltage. 85in[N]_input Measured output voltage.
81in[N]_min Minimum output voltage. 86in[N]_min Minimum output voltage.
@@ -95,7 +100,7 @@ temp[N]_input Measured temperature.
95 and temp5 reports the chip temperature. 100 and temp5 reports the chip temperature.
96 On LTC2977 and LTC2978, only one temperature measurement 101 On LTC2977 and LTC2978, only one temperature measurement
97 is supported and reports the chip temperature. 102 is supported and reports the chip temperature.
98 On LTC3880, temp1 and temp2 report external 103 On LTC3880 and LTM4676, temp1 and temp2 report external
99 temperatures, and temp3 reports the chip temperature. 104 temperatures, and temp3 reports the chip temperature.
100 On LTC3883, temp1 reports an external temperature, 105 On LTC3883, temp1 reports an external temperature,
101 and temp2 reports the chip temperature. 106 and temp2 reports the chip temperature.
@@ -123,11 +128,11 @@ power[N]_label "pout[1-4]".
123 LTC2974: N=1-4 128 LTC2974: N=1-4
124 LTC2977: Not supported 129 LTC2977: Not supported
125 LTC2978: Not supported 130 LTC2978: Not supported
126 LTC3880: N=1-2 131 LTC3880, LTM4676: N=1-2
127 LTC3883: N=2 132 LTC3883: N=2
128power[N]_input Measured output power. 133power[N]_input Measured output power.
129 134
130curr1_label "iin". LTC3880 and LTC3883 only. 135curr1_label "iin". LTC3880, LTC3883, and LTM4676 only.
131curr1_input Measured input current. 136curr1_input Measured input current.
132curr1_max Maximum input current. 137curr1_max Maximum input current.
133curr1_max_alarm Input current high alarm. 138curr1_max_alarm Input current high alarm.
@@ -138,7 +143,7 @@ curr[N]_label "iout[1-4]".
138 LTC2974: N=1-4 143 LTC2974: N=1-4
139 LTC2977: not supported 144 LTC2977: not supported
140 LTC2978: not supported 145 LTC2978: not supported
141 LTC3880: N=2-3 146 LTC3880, LTM4676: N=2-3
142 LTC3883: N=2 147 LTC3883: N=2
143curr[N]_input Measured output current. 148curr[N]_input Measured output current.
144curr[N]_max Maximum output current. 149curr[N]_max Maximum output current.
diff --git a/Documentation/hwmon/ltc4260 b/Documentation/hwmon/ltc4260
new file mode 100644
index 000000000000..c4ff4ad998b2
--- /dev/null
+++ b/Documentation/hwmon/ltc4260
@@ -0,0 +1,56 @@
1Kernel driver ltc4260
2=====================
3
4Supported chips:
5 * Linear Technology LTC4260
6 Prefix: 'ltc4260'
7 Addresses scanned: -
8 Datasheet:
9 http://cds.linear.com/docs/en/datasheet/4260fc.pdf
10
11Author: Guenter Roeck <linux@roeck-us.net>
12
13
14Description
15-----------
16
17The LTC4260 Hot Swap controller allows a board to be safely inserted
18and removed from a live backplane.
19
20
21Usage Notes
22-----------
23
24This driver does not probe for LTC4260 devices, since there is no register
25which can be safely used to identify the chip. You will have to instantiate
26the devices explicitly.
27
28Example: the following will load the driver for an LTC4260 at address 0x10
29on I2C bus #1:
30$ modprobe ltc4260
31$ echo ltc4260 0x10 > /sys/bus/i2c/devices/i2c-1/new_device
32
33
34Sysfs entries
35-------------
36
37Voltage readings provided by this driver are reported as obtained from the ADC
38registers. If a set of voltage divider resistors is installed, calculate the
39real voltage by multiplying the reported value with (R1+R2)/R2, where R1 is the
40value of the divider resistor against the measured voltage and R2 is the value
41of the divider resistor against Ground.
42
43Current reading provided by this driver is reported as obtained from the ADC
44Current Sense register. The reported value assumes that a 1 mOhm sense resistor
45is installed. If a different sense resistor is installed, calculate the real
46current by dividing the reported value by the sense resistor value in mOhm.
47
48in1_input SOURCE voltage (mV)
49in1_min_alarm Undervoltage alarm
50in1_max_alarm Overvoltage alarm
51
52in2_input ADIN voltage (mV)
53in2_alarm Power bad alarm
54
55curr1_input SENSE current (mA)
56curr1_alarm SENSE overcurrent alarm
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 5ce43d8dfa98..f288b60a87be 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -111,22 +111,6 @@ config SENSORS_AD7418
111 This driver can also be built as a module. If so, the module 111 This driver can also be built as a module. If so, the module
112 will be called ad7418. 112 will be called ad7418.
113 113
114config SENSORS_ADCXX
115 tristate "National Semiconductor ADCxxxSxxx"
116 depends on SPI_MASTER
117 help
118 If you say yes here you get support for the National Semiconductor
119 ADC<bb><c>S<sss> chip family, where
120 * bb is the resolution in number of bits (8, 10, 12)
121 * c is the number of channels (1, 2, 4, 8)
122 * sss is the maximum conversion speed (021 for 200 kSPS, 051 for 500
123 kSPS and 101 for 1 MSPS)
124
125 Examples : ADC081S101, ADC124S501, ...
126
127 This driver can also be built as a module. If so, the module
128 will be called adcxx.
129
130config SENSORS_ADM1021 114config SENSORS_ADM1021
131 tristate "Analog Devices ADM1021 and compatibles" 115 tristate "Analog Devices ADM1021 and compatibles"
132 depends on I2C 116 depends on I2C
@@ -312,6 +296,31 @@ config SENSORS_FAM15H_POWER
312 This driver can also be built as a module. If so, the module 296 This driver can also be built as a module. If so, the module
313 will be called fam15h_power. 297 will be called fam15h_power.
314 298
299config SENSORS_APPLESMC
300 tristate "Apple SMC (Motion sensor, light sensor, keyboard backlight)"
301 depends on INPUT && X86
302 select NEW_LEDS
303 select LEDS_CLASS
304 select INPUT_POLLDEV
305 default n
306 help
307 This driver provides support for the Apple System Management
308 Controller, which provides an accelerometer (Apple Sudden Motion
309 Sensor), light sensors, temperature sensors, keyboard backlight
310 control and fan control.
311
312 Only Intel-based Apple's computers are supported (MacBook Pro,
313 MacBook, MacMini).
314
315 Data from the different sensors, keyboard backlight control and fan
316 control are accessible via sysfs.
317
318 This driver also provides an absolute input class device, allowing
319 the laptop to act as a pinball machine-esque joystick.
320
321 Say Y here if you have an applicable laptop and want to experience
322 the awesome power of applesmc.
323
315config SENSORS_ASB100 324config SENSORS_ASB100
316 tristate "Asus ASB100 Bach" 325 tristate "Asus ASB100 Bach"
317 depends on X86 && I2C 326 depends on X86 && I2C
@@ -435,6 +444,12 @@ config SENSORS_F75375S
435 This driver can also be built as a module. If so, the module 444 This driver can also be built as a module. If so, the module
436 will be called f75375s. 445 will be called f75375s.
437 446
447config SENSORS_MC13783_ADC
448 tristate "Freescale MC13783/MC13892 ADC"
449 depends on MFD_MC13XXX
450 help
451 Support for the A/D converter on MC13783 and MC13892 PMIC.
452
438config SENSORS_FSCHMD 453config SENSORS_FSCHMD
439 tristate "Fujitsu Siemens Computers sensor chips" 454 tristate "Fujitsu Siemens Computers sensor chips"
440 depends on X86 && I2C 455 depends on X86 && I2C
@@ -451,26 +466,6 @@ config SENSORS_FSCHMD
451 This driver can also be built as a module. If so, the module 466 This driver can also be built as a module. If so, the module
452 will be called fschmd. 467 will be called fschmd.
453 468
454config SENSORS_G760A
455 tristate "GMT G760A"
456 depends on I2C
457 help
458 If you say yes here you get support for Global Mixed-mode
459 Technology Inc G760A fan speed PWM controller chips.
460
461 This driver can also be built as a module. If so, the module
462 will be called g760a.
463
464config SENSORS_G762
465 tristate "GMT G762 and G763"
466 depends on I2C
467 help
468 If you say yes here you get support for Global Mixed-mode
469 Technology Inc G762 and G763 fan speed PWM controller chips.
470
471 This driver can also be built as a module. If so, the module
472 will be called g762.
473
474config SENSORS_GL518SM 469config SENSORS_GL518SM
475 tristate "Genesys Logic GL518SM" 470 tristate "Genesys Logic GL518SM"
476 depends on I2C 471 depends on I2C
@@ -492,6 +487,26 @@ config SENSORS_GL520SM
492 This driver can also be built as a module. If so, the module 487 This driver can also be built as a module. If so, the module
493 will be called gl520sm. 488 will be called gl520sm.
494 489
490config SENSORS_G760A
491 tristate "GMT G760A"
492 depends on I2C
493 help
494 If you say yes here you get support for Global Mixed-mode
495 Technology Inc G760A fan speed PWM controller chips.
496
497 This driver can also be built as a module. If so, the module
498 will be called g760a.
499
500config SENSORS_G762
501 tristate "GMT G762 and G763"
502 depends on I2C
503 help
504 If you say yes here you get support for Global Mixed-mode
505 Technology Inc G762 and G763 fan speed PWM controller chips.
506
507 This driver can also be built as a module. If so, the module
508 will be called g762.
509
495config SENSORS_GPIO_FAN 510config SENSORS_GPIO_FAN
496 tristate "GPIO fan" 511 tristate "GPIO fan"
497 depends on GPIOLIB 512 depends on GPIOLIB
@@ -511,24 +526,6 @@ config SENSORS_HIH6130
511 This driver can also be built as a module. If so, the module 526 This driver can also be built as a module. If so, the module
512 will be called hih6130. 527 will be called hih6130.
513 528
514config SENSORS_HTU21
515 tristate "Measurement Specialties HTU21D humidity/temperature sensors"
516 depends on I2C
517 help
518 If you say yes here you get support for the Measurement Specialties
519 HTU21D humidity and temperature sensors.
520
521 This driver can also be built as a module. If so, the module
522 will be called htu21.
523
524config SENSORS_CORETEMP
525 tristate "Intel Core/Core2/Atom temperature sensor"
526 depends on X86
527 help
528 If you say yes here you get support for the temperature
529 sensor inside your CPU. Most of the family 6 CPUs
530 are supported. Check Documentation/hwmon/coretemp for details.
531
532config SENSORS_IBMAEM 529config SENSORS_IBMAEM
533 tristate "IBM Active Energy Manager temperature/power sensors and control" 530 tristate "IBM Active Energy Manager temperature/power sensors and control"
534 select IPMI_SI 531 select IPMI_SI
@@ -566,6 +563,14 @@ config SENSORS_IIO_HWMON
566 for those channels specified in the map. This map can be provided 563 for those channels specified in the map. This map can be provided
567 either via platform data or the device tree bindings. 564 either via platform data or the device tree bindings.
568 565
566config SENSORS_CORETEMP
567 tristate "Intel Core/Core2/Atom temperature sensor"
568 depends on X86
569 help
570 If you say yes here you get support for the temperature
571 sensor inside your CPU. Most of the family 6 CPUs
572 are supported. Check Documentation/hwmon/coretemp for details.
573
569config SENSORS_IT87 574config SENSORS_IT87
570 tristate "ITE IT87xx and compatibles" 575 tristate "ITE IT87xx and compatibles"
571 depends on !PPC 576 depends on !PPC
@@ -614,6 +619,219 @@ config SENSORS_LINEAGE
614 This driver can also be built as a module. If so, the module 619 This driver can also be built as a module. If so, the module
615 will be called lineage-pem. 620 will be called lineage-pem.
616 621
622config SENSORS_LTC2945
623 tristate "Linear Technology LTC2945"
624 depends on I2C
625 select REGMAP_I2C
626 default n
627 help
628 If you say yes here you get support for Linear Technology LTC2945
629 I2C System Monitor.
630
631 This driver can also be built as a module. If so, the module will
632 be called ltc2945.
633
634config SENSORS_LTC4151
635 tristate "Linear Technology LTC4151"
636 depends on I2C
637 default n
638 help
639 If you say yes here you get support for Linear Technology LTC4151
640 High Voltage I2C Current and Voltage Monitor interface.
641
642 This driver can also be built as a module. If so, the module will
643 be called ltc4151.
644
645config SENSORS_LTC4215
646 tristate "Linear Technology LTC4215"
647 depends on I2C
648 default n
649 help
650 If you say yes here you get support for Linear Technology LTC4215
651 Hot Swap Controller I2C interface.
652
653 This driver can also be built as a module. If so, the module will
654 be called ltc4215.
655
656config SENSORS_LTC4222
657 tristate "Linear Technology LTC4222"
658 depends on I2C
659 select REGMAP_I2C
660 default n
661 help
662 If you say yes here you get support for Linear Technology LTC4222
663 Dual Hot Swap Controller I2C interface.
664
665 This driver can also be built as a module. If so, the module will
666 be called ltc4222.
667
668config SENSORS_LTC4245
669 tristate "Linear Technology LTC4245"
670 depends on I2C
671 default n
672 help
673 If you say yes here you get support for Linear Technology LTC4245
674 Multiple Supply Hot Swap Controller I2C interface.
675
676 This driver can also be built as a module. If so, the module will
677 be called ltc4245.
678
679config SENSORS_LTC4260
680 tristate "Linear Technology LTC4260"
681 depends on I2C
682 select REGMAP_I2C
683 default n
684 help
685 If you say yes here you get support for Linear Technology LTC4260
686 Positive Voltage Hot Swap Controller I2C interface.
687
688 This driver can also be built as a module. If so, the module will
689 be called ltc4260.
690
691config SENSORS_LTC4261
692 tristate "Linear Technology LTC4261"
693 depends on I2C
694 default n
695 help
696 If you say yes here you get support for Linear Technology LTC4261
697 Negative Voltage Hot Swap Controller I2C interface.
698
699 This driver can also be built as a module. If so, the module will
700 be called ltc4261.
701
702config SENSORS_MAX1111
703 tristate "Maxim MAX1111 Serial 8-bit ADC chip and compatibles"
704 depends on SPI_MASTER
705 help
706 Say y here to support Maxim's MAX1110, MAX1111, MAX1112, and MAX1113
707 ADC chips.
708
709 This driver can also be built as a module. If so, the module
710 will be called max1111.
711
712config SENSORS_MAX16065
713 tristate "Maxim MAX16065 System Manager and compatibles"
714 depends on I2C
715 help
716 If you say yes here you get support for hardware monitoring
717 capabilities of the following Maxim System Manager chips.
718 MAX16065
719 MAX16066
720 MAX16067
721 MAX16068
722 MAX16070
723 MAX16071
724
725 This driver can also be built as a module. If so, the module
726 will be called max16065.
727
728config SENSORS_MAX1619
729 tristate "Maxim MAX1619 sensor chip"
730 depends on I2C
731 help
732 If you say yes here you get support for MAX1619 sensor chip.
733
734 This driver can also be built as a module. If so, the module
735 will be called max1619.
736
737config SENSORS_MAX1668
738 tristate "Maxim MAX1668 and compatibles"
739 depends on I2C
740 help
741 If you say yes here you get support for MAX1668, MAX1989 and
742 MAX1805 chips.
743
744 This driver can also be built as a module. If so, the module
745 will be called max1668.
746
747config SENSORS_MAX197
748 tristate "Maxim MAX197 and compatibles"
749 help
750 Support for the Maxim MAX197 A/D converter.
751 Support will include, but not be limited to, MAX197, and MAX199.
752
753 This driver can also be built as a module. If so, the module
754 will be called max197.
755
756config SENSORS_MAX6639
757 tristate "Maxim MAX6639 sensor chip"
758 depends on I2C
759 help
760 If you say yes here you get support for the MAX6639
761 sensor chips.
762
763 This driver can also be built as a module. If so, the module
764 will be called max6639.
765
766config SENSORS_MAX6642
767 tristate "Maxim MAX6642 sensor chip"
768 depends on I2C
769 help
770 If you say yes here you get support for MAX6642 sensor chip.
771 MAX6642 is a SMBus-Compatible Remote/Local Temperature Sensor
772 with Overtemperature Alarm from Maxim.
773
774 This driver can also be built as a module. If so, the module
775 will be called max6642.
776
777config SENSORS_MAX6650
778 tristate "Maxim MAX6650 sensor chip"
779 depends on I2C
780 help
781 If you say yes here you get support for the MAX6650 / MAX6651
782 sensor chips.
783
784 This driver can also be built as a module. If so, the module
785 will be called max6650.
786
787config SENSORS_MAX6697
788 tristate "Maxim MAX6697 and compatibles"
789 depends on I2C
790 help
791 If you say yes here you get support for MAX6581, MAX6602, MAX6622,
792 MAX6636, MAX6689, MAX6693, MAX6694, MAX6697, MAX6698, and MAX6699
793 temperature sensor chips.
794
795 This driver can also be built as a module. If so, the module
796 will be called max6697.
797
798config SENSORS_HTU21
799 tristate "Measurement Specialties HTU21D humidity/temperature sensors"
800 depends on I2C
801 help
802 If you say yes here you get support for the Measurement Specialties
803 HTU21D humidity and temperature sensors.
804
805 This driver can also be built as a module. If so, the module
806 will be called htu21.
807
808config SENSORS_MCP3021
809 tristate "Microchip MCP3021 and compatibles"
810 depends on I2C
811 help
812 If you say yes here you get support for MCP3021 and MCP3221.
813 The MCP3021 is a A/D converter (ADC) with 10-bit and the MCP3221
814 with 12-bit resolution.
815
816 This driver can also be built as a module. If so, the module
817 will be called mcp3021.
818
819config SENSORS_ADCXX
820 tristate "National Semiconductor ADCxxxSxxx"
821 depends on SPI_MASTER
822 help
823 If you say yes here you get support for the National Semiconductor
824 ADC<bb><c>S<sss> chip family, where
825 * bb is the resolution in number of bits (8, 10, 12)
826 * c is the number of channels (1, 2, 4, 8)
827 * sss is the maximum conversion speed (021 for 200 kSPS, 051 for 500
828 kSPS and 101 for 1 MSPS)
829
830 Examples : ADC081S101, ADC124S501, ...
831
832 This driver can also be built as a module. If so, the module
833 will be called adcxx.
834
617config SENSORS_LM63 835config SENSORS_LM63
618 tristate "National Semiconductor LM63 and compatibles" 836 tristate "National Semiconductor LM63 and compatibles"
619 depends on I2C 837 depends on I2C
@@ -776,50 +994,6 @@ config SENSORS_LM93
776 This driver can also be built as a module. If so, the module 994 This driver can also be built as a module. If so, the module
777 will be called lm93. 995 will be called lm93.
778 996
779config SENSORS_LTC4151
780 tristate "Linear Technology LTC4151"
781 depends on I2C
782 default n
783 help
784 If you say yes here you get support for Linear Technology LTC4151
785 High Voltage I2C Current and Voltage Monitor interface.
786
787 This driver can also be built as a module. If so, the module will
788 be called ltc4151.
789
790config SENSORS_LTC4215
791 tristate "Linear Technology LTC4215"
792 depends on I2C
793 default n
794 help
795 If you say yes here you get support for Linear Technology LTC4215
796 Hot Swap Controller I2C interface.
797
798 This driver can also be built as a module. If so, the module will
799 be called ltc4215.
800
801config SENSORS_LTC4245
802 tristate "Linear Technology LTC4245"
803 depends on I2C
804 default n
805 help
806 If you say yes here you get support for Linear Technology LTC4245
807 Multiple Supply Hot Swap Controller I2C interface.
808
809 This driver can also be built as a module. If so, the module will
810 be called ltc4245.
811
812config SENSORS_LTC4261
813 tristate "Linear Technology LTC4261"
814 depends on I2C
815 default n
816 help
817 If you say yes here you get support for Linear Technology LTC4261
818 Negative Voltage Hot Swap Controller I2C interface.
819
820 This driver can also be built as a module. If so, the module will
821 be called ltc4261.
822
823config SENSORS_LM95234 997config SENSORS_LM95234
824 tristate "National Semiconductor LM95234" 998 tristate "National Semiconductor LM95234"
825 depends on I2C 999 depends on I2C
@@ -849,125 +1023,33 @@ config SENSORS_LM95245
849 This driver can also be built as a module. If so, the module 1023 This driver can also be built as a module. If so, the module
850 will be called lm95245. 1024 will be called lm95245.
851 1025
852config SENSORS_MAX1111 1026config SENSORS_PC87360
853 tristate "Maxim MAX1111 Serial 8-bit ADC chip and compatibles" 1027 tristate "National Semiconductor PC87360 family"
854 depends on SPI_MASTER 1028 depends on !PPC
855 help 1029 select HWMON_VID
856 Say y here to support Maxim's MAX1110, MAX1111, MAX1112, and MAX1113
857 ADC chips.
858
859 This driver can also be built as a module. If so, the module
860 will be called max1111.
861
862config SENSORS_MAX16065
863 tristate "Maxim MAX16065 System Manager and compatibles"
864 depends on I2C
865 help
866 If you say yes here you get support for hardware monitoring
867 capabilities of the following Maxim System Manager chips.
868 MAX16065
869 MAX16066
870 MAX16067
871 MAX16068
872 MAX16070
873 MAX16071
874
875 This driver can also be built as a module. If so, the module
876 will be called max16065.
877
878config SENSORS_MAX1619
879 tristate "Maxim MAX1619 sensor chip"
880 depends on I2C
881 help
882 If you say yes here you get support for MAX1619 sensor chip.
883
884 This driver can also be built as a module. If so, the module
885 will be called max1619.
886
887config SENSORS_MAX1668
888 tristate "Maxim MAX1668 and compatibles"
889 depends on I2C
890 help
891 If you say yes here you get support for MAX1668, MAX1989 and
892 MAX1805 chips.
893
894 This driver can also be built as a module. If so, the module
895 will be called max1668.
896
897config SENSORS_MAX197
898 tristate "Maxim MAX197 and compatibles"
899 help
900 Support for the Maxim MAX197 A/D converter.
901 Support will include, but not be limited to, MAX197, and MAX199.
902
903 This driver can also be built as a module. If so, the module
904 will be called max197.
905
906config SENSORS_MAX6639
907 tristate "Maxim MAX6639 sensor chip"
908 depends on I2C
909 help
910 If you say yes here you get support for the MAX6639
911 sensor chips.
912
913 This driver can also be built as a module. If so, the module
914 will be called max6639.
915
916config SENSORS_MAX6642
917 tristate "Maxim MAX6642 sensor chip"
918 depends on I2C
919 help
920 If you say yes here you get support for MAX6642 sensor chip.
921 MAX6642 is a SMBus-Compatible Remote/Local Temperature Sensor
922 with Overtemperature Alarm from Maxim.
923
924 This driver can also be built as a module. If so, the module
925 will be called max6642.
926
927config SENSORS_MAX6650
928 tristate "Maxim MAX6650 sensor chip"
929 depends on I2C
930 help
931 If you say yes here you get support for the MAX6650 / MAX6651
932 sensor chips.
933
934 This driver can also be built as a module. If so, the module
935 will be called max6650.
936
937config SENSORS_MAX6697
938 tristate "Maxim MAX6697 and compatibles"
939 depends on I2C
940 help
941 If you say yes here you get support for MAX6581, MAX6602, MAX6622,
942 MAX6636, MAX6689, MAX6693, MAX6694, MAX6697, MAX6698, and MAX6699
943 temperature sensor chips.
944
945 This driver can also be built as a module. If so, the module
946 will be called max6697.
947
948config SENSORS_MCP3021
949 tristate "Microchip MCP3021 and compatibles"
950 depends on I2C
951 help 1030 help
952 If you say yes here you get support for MCP3021 and MCP3221. 1031 If you say yes here you get access to the hardware monitoring
953 The MCP3021 is a A/D converter (ADC) with 10-bit and the MCP3221 1032 functions of the National Semiconductor PC8736x Super-I/O chips.
954 with 12-bit resolution. 1033 The PC87360, PC87363 and PC87364 only have fan monitoring and
1034 control. The PC87365 and PC87366 additionally have voltage and
1035 temperature monitoring.
955 1036
956 This driver can also be built as a module. If so, the module 1037 This driver can also be built as a module. If so, the module
957 will be called mcp3021. 1038 will be called pc87360.
958 1039
959config SENSORS_NCT6775 1040config SENSORS_PC87427
960 tristate "Nuvoton NCT6775F and compatibles" 1041 tristate "National Semiconductor PC87427"
961 depends on !PPC 1042 depends on !PPC
962 select HWMON_VID
963 help 1043 help
964 If you say yes here you get support for the hardware monitoring 1044 If you say yes here you get access to the hardware monitoring
965 functionality of the Nuvoton NCT6775F, NCT6776F, NCT6779D 1045 functions of the National Semiconductor PC87427 Super-I/O chip.
966 and compatible Super-I/O chips. This driver replaces the 1046 The chip has two distinct logical devices, one for fan speed
967 w83627ehf driver for NCT6775F and NCT6776F. 1047 monitoring and control, and one for voltage and temperature
1048 monitoring. Fan speed monitoring and control are supported, as
1049 well as temperature monitoring. Voltages aren't supported yet.
968 1050
969 This driver can also be built as a module. If so, the module 1051 This driver can also be built as a module. If so, the module
970 will be called nct6775. 1052 will be called pc87427.
971 1053
972config SENSORS_NTC_THERMISTOR 1054config SENSORS_NTC_THERMISTOR
973 tristate "NTC thermistor support" 1055 tristate "NTC thermistor support"
@@ -983,33 +1065,18 @@ config SENSORS_NTC_THERMISTOR
983 This driver can also be built as a module. If so, the module 1065 This driver can also be built as a module. If so, the module
984 will be called ntc-thermistor. 1066 will be called ntc-thermistor.
985 1067
986config SENSORS_PC87360 1068config SENSORS_NCT6775
987 tristate "National Semiconductor PC87360 family" 1069 tristate "Nuvoton NCT6775F and compatibles"
988 depends on !PPC 1070 depends on !PPC
989 select HWMON_VID 1071 select HWMON_VID
990 help 1072 help
991 If you say yes here you get access to the hardware monitoring 1073 If you say yes here you get support for the hardware monitoring
992 functions of the National Semiconductor PC8736x Super-I/O chips. 1074 functionality of the Nuvoton NCT6775F, NCT6776F, NCT6779D
993 The PC87360, PC87363 and PC87364 only have fan monitoring and 1075 and compatible Super-I/O chips. This driver replaces the
994 control. The PC87365 and PC87366 additionally have voltage and 1076 w83627ehf driver for NCT6775F and NCT6776F.
995 temperature monitoring.
996
997 This driver can also be built as a module. If so, the module
998 will be called pc87360.
999
1000config SENSORS_PC87427
1001 tristate "National Semiconductor PC87427"
1002 depends on !PPC
1003 help
1004 If you say yes here you get access to the hardware monitoring
1005 functions of the National Semiconductor PC87427 Super-I/O chip.
1006 The chip has two distinct logical devices, one for fan speed
1007 monitoring and control, and one for voltage and temperature
1008 monitoring. Fan speed monitoring and control are supported, as
1009 well as temperature monitoring. Voltages aren't supported yet.
1010 1077
1011 This driver can also be built as a module. If so, the module 1078 This driver can also be built as a module. If so, the module
1012 will be called pc87427. 1079 will be called nct6775.
1013 1080
1014config SENSORS_PCF8591 1081config SENSORS_PCF8591
1015 tristate "Philips PCF8591 ADC/DAC" 1082 tristate "Philips PCF8591 ADC/DAC"
@@ -1074,21 +1141,6 @@ config SENSORS_SIS5595
1074 This driver can also be built as a module. If so, the module 1141 This driver can also be built as a module. If so, the module
1075 will be called sis5595. 1142 will be called sis5595.
1076 1143
1077config SENSORS_SMM665
1078 tristate "Summit Microelectronics SMM665"
1079 depends on I2C
1080 default n
1081 help
1082 If you say yes here you get support for the hardware monitoring
1083 features of the Summit Microelectronics SMM665/SMM665B Six-Channel
1084 Active DC Output Controller / Monitor.
1085
1086 Other supported chips are SMM465, SMM665C, SMM764, and SMM766.
1087 Support for those chips is untested.
1088
1089 This driver can also be built as a module. If so, the module will
1090 be called smm665.
1091
1092config SENSORS_DME1737 1144config SENSORS_DME1737
1093 tristate "SMSC DME1737, SCH311x and compatibles" 1145 tristate "SMSC DME1737, SCH311x and compatibles"
1094 depends on I2C && !PPC 1146 depends on I2C && !PPC
@@ -1210,6 +1262,31 @@ config SENSORS_SCH5636
1210 This driver can also be built as a module. If so, the module 1262 This driver can also be built as a module. If so, the module
1211 will be called sch5636. 1263 will be called sch5636.
1212 1264
1265config SENSORS_SMM665
1266 tristate "Summit Microelectronics SMM665"
1267 depends on I2C
1268 default n
1269 help
1270 If you say yes here you get support for the hardware monitoring
1271 features of the Summit Microelectronics SMM665/SMM665B Six-Channel
1272 Active DC Output Controller / Monitor.
1273
1274 Other supported chips are SMM465, SMM665C, SMM764, and SMM766.
1275 Support for those chips is untested.
1276
1277 This driver can also be built as a module. If so, the module will
1278 be called smm665.
1279
1280config SENSORS_ADC128D818
1281 tristate "Texas Instruments ADC128D818"
1282 depends on I2C
1283 help
1284 If you say yes here you get support for the Texas Instruments
1285 ADC128D818 System Monitor with Temperature Sensor chip.
1286
1287 This driver can also be built as a module. If so, the module
1288 will be called adc128d818.
1289
1213config SENSORS_ADS1015 1290config SENSORS_ADS1015
1214 tristate "Texas Instruments ADS1015" 1291 tristate "Texas Instruments ADS1015"
1215 depends on I2C 1292 depends on I2C
@@ -1525,37 +1602,6 @@ config SENSORS_ULTRA45
1525 This driver provides support for the Ultra45 workstation environmental 1602 This driver provides support for the Ultra45 workstation environmental
1526 sensors. 1603 sensors.
1527 1604
1528config SENSORS_APPLESMC
1529 tristate "Apple SMC (Motion sensor, light sensor, keyboard backlight)"
1530 depends on INPUT && X86
1531 select NEW_LEDS
1532 select LEDS_CLASS
1533 select INPUT_POLLDEV
1534 default n
1535 help
1536 This driver provides support for the Apple System Management
1537 Controller, which provides an accelerometer (Apple Sudden Motion
1538 Sensor), light sensors, temperature sensors, keyboard backlight
1539 control and fan control.
1540
1541 Only Intel-based Apple's computers are supported (MacBook Pro,
1542 MacBook, MacMini).
1543
1544 Data from the different sensors, keyboard backlight control and fan
1545 control are accessible via sysfs.
1546
1547 This driver also provides an absolute input class device, allowing
1548 the laptop to act as a pinball machine-esque joystick.
1549
1550 Say Y here if you have an applicable laptop and want to experience
1551 the awesome power of applesmc.
1552
1553config SENSORS_MC13783_ADC
1554 tristate "Freescale MC13783/MC13892 ADC"
1555 depends on MFD_MC13XXX
1556 help
1557 Support for the A/D converter on MC13783 and MC13892 PMIC.
1558
1559if ACPI 1605if ACPI
1560 1606
1561comment "ACPI drivers" 1607comment "ACPI drivers"
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index ec7cde06eb52..c48f9873ac73 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -25,6 +25,7 @@ obj-$(CONFIG_SENSORS_ABITUGURU3)+= abituguru3.o
25obj-$(CONFIG_SENSORS_AD7314) += ad7314.o 25obj-$(CONFIG_SENSORS_AD7314) += ad7314.o
26obj-$(CONFIG_SENSORS_AD7414) += ad7414.o 26obj-$(CONFIG_SENSORS_AD7414) += ad7414.o
27obj-$(CONFIG_SENSORS_AD7418) += ad7418.o 27obj-$(CONFIG_SENSORS_AD7418) += ad7418.o
28obj-$(CONFIG_SENSORS_ADC128D818) += adc128d818.o
28obj-$(CONFIG_SENSORS_ADCXX) += adcxx.o 29obj-$(CONFIG_SENSORS_ADCXX) += adcxx.o
29obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o 30obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o
30obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o 31obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o
@@ -95,9 +96,12 @@ obj-$(CONFIG_SENSORS_LM93) += lm93.o
95obj-$(CONFIG_SENSORS_LM95234) += lm95234.o 96obj-$(CONFIG_SENSORS_LM95234) += lm95234.o
96obj-$(CONFIG_SENSORS_LM95241) += lm95241.o 97obj-$(CONFIG_SENSORS_LM95241) += lm95241.o
97obj-$(CONFIG_SENSORS_LM95245) += lm95245.o 98obj-$(CONFIG_SENSORS_LM95245) += lm95245.o
99obj-$(CONFIG_SENSORS_LTC2945) += ltc2945.o
98obj-$(CONFIG_SENSORS_LTC4151) += ltc4151.o 100obj-$(CONFIG_SENSORS_LTC4151) += ltc4151.o
99obj-$(CONFIG_SENSORS_LTC4215) += ltc4215.o 101obj-$(CONFIG_SENSORS_LTC4215) += ltc4215.o
102obj-$(CONFIG_SENSORS_LTC4222) += ltc4222.o
100obj-$(CONFIG_SENSORS_LTC4245) += ltc4245.o 103obj-$(CONFIG_SENSORS_LTC4245) += ltc4245.o
104obj-$(CONFIG_SENSORS_LTC4260) += ltc4260.o
101obj-$(CONFIG_SENSORS_LTC4261) += ltc4261.o 105obj-$(CONFIG_SENSORS_LTC4261) += ltc4261.o
102obj-$(CONFIG_SENSORS_MAX1111) += max1111.o 106obj-$(CONFIG_SENSORS_MAX1111) += max1111.o
103obj-$(CONFIG_SENSORS_MAX16065) += max16065.o 107obj-$(CONFIG_SENSORS_MAX16065) += max16065.o
diff --git a/drivers/hwmon/adc128d818.c b/drivers/hwmon/adc128d818.c
new file mode 100644
index 000000000000..5ffd81f19d01
--- /dev/null
+++ b/drivers/hwmon/adc128d818.c
@@ -0,0 +1,491 @@
1/*
2 * Driver for TI ADC128D818 System Monitor with Temperature Sensor
3 *
4 * Copyright (c) 2014 Guenter Roeck
5 *
6 * Derived from lm80.c
7 * Copyright (C) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
8 * and Philip Edelbrock <phil@netroedge.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21#include <linux/module.h>
22#include <linux/slab.h>
23#include <linux/jiffies.h>
24#include <linux/i2c.h>
25#include <linux/hwmon.h>
26#include <linux/hwmon-sysfs.h>
27#include <linux/err.h>
28#include <linux/regulator/consumer.h>
29#include <linux/mutex.h>
30
31/* Addresses to scan
32 * The chip also supports addresses 0x35..0x37. Don't scan those addresses
33 * since they are also used by some EEPROMs, which may result in false
34 * positives.
35 */
36static const unsigned short normal_i2c[] = {
37 0x1d, 0x1e, 0x1f, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END };
38
39/* registers */
40#define ADC128_REG_IN_MAX(nr) (0x2a + (nr) * 2)
41#define ADC128_REG_IN_MIN(nr) (0x2b + (nr) * 2)
42#define ADC128_REG_IN(nr) (0x20 + (nr))
43
44#define ADC128_REG_TEMP 0x27
45#define ADC128_REG_TEMP_MAX 0x38
46#define ADC128_REG_TEMP_HYST 0x39
47
48#define ADC128_REG_CONFIG 0x00
49#define ADC128_REG_ALARM 0x01
50#define ADC128_REG_MASK 0x03
51#define ADC128_REG_CONV_RATE 0x07
52#define ADC128_REG_ONESHOT 0x09
53#define ADC128_REG_SHUTDOWN 0x0a
54#define ADC128_REG_CONFIG_ADV 0x0b
55#define ADC128_REG_BUSY_STATUS 0x0c
56
57#define ADC128_REG_MAN_ID 0x3e
58#define ADC128_REG_DEV_ID 0x3f
59
60struct adc128_data {
61 struct i2c_client *client;
62 struct regulator *regulator;
63 int vref; /* Reference voltage in mV */
64 struct mutex update_lock;
65 bool valid; /* true if following fields are valid */
66 unsigned long last_updated; /* In jiffies */
67
68 u16 in[3][7]; /* Register value, normalized to 12 bit
69 * 0: input voltage
70 * 1: min limit
71 * 2: max limit
72 */
73 s16 temp[3]; /* Register value, normalized to 9 bit
74 * 0: sensor 1: limit 2: hyst
75 */
76 u8 alarms; /* alarm register value */
77};
78
79static struct adc128_data *adc128_update_device(struct device *dev)
80{
81 struct adc128_data *data = dev_get_drvdata(dev);
82 struct i2c_client *client = data->client;
83 struct adc128_data *ret = data;
84 int i, rv;
85
86 mutex_lock(&data->update_lock);
87
88 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
89 for (i = 0; i < 7; i++) {
90 rv = i2c_smbus_read_word_swapped(client,
91 ADC128_REG_IN(i));
92 if (rv < 0)
93 goto abort;
94 data->in[0][i] = rv >> 4;
95
96 rv = i2c_smbus_read_byte_data(client,
97 ADC128_REG_IN_MIN(i));
98 if (rv < 0)
99 goto abort;
100 data->in[1][i] = rv << 4;
101
102 rv = i2c_smbus_read_byte_data(client,
103 ADC128_REG_IN_MAX(i));
104 if (rv < 0)
105 goto abort;
106 data->in[2][i] = rv << 4;
107 }
108
109 rv = i2c_smbus_read_word_swapped(client, ADC128_REG_TEMP);
110 if (rv < 0)
111 goto abort;
112 data->temp[0] = rv >> 7;
113
114 rv = i2c_smbus_read_byte_data(client, ADC128_REG_TEMP_MAX);
115 if (rv < 0)
116 goto abort;
117 data->temp[1] = rv << 1;
118
119 rv = i2c_smbus_read_byte_data(client, ADC128_REG_TEMP_HYST);
120 if (rv < 0)
121 goto abort;
122 data->temp[2] = rv << 1;
123
124 rv = i2c_smbus_read_byte_data(client, ADC128_REG_ALARM);
125 if (rv < 0)
126 goto abort;
127 data->alarms |= rv;
128
129 data->last_updated = jiffies;
130 data->valid = true;
131 }
132 goto done;
133
134abort:
135 ret = ERR_PTR(rv);
136 data->valid = false;
137done:
138 mutex_unlock(&data->update_lock);
139 return ret;
140}
141
142static ssize_t adc128_show_in(struct device *dev, struct device_attribute *attr,
143 char *buf)
144{
145 struct adc128_data *data = adc128_update_device(dev);
146 int index = to_sensor_dev_attr_2(attr)->index;
147 int nr = to_sensor_dev_attr_2(attr)->nr;
148 int val;
149
150 if (IS_ERR(data))
151 return PTR_ERR(data);
152
153 val = DIV_ROUND_CLOSEST(data->in[index][nr] * data->vref, 4095);
154 return sprintf(buf, "%d\n", val);
155}
156
157static ssize_t adc128_set_in(struct device *dev, struct device_attribute *attr,
158 const char *buf, size_t count)
159{
160 struct adc128_data *data = dev_get_drvdata(dev);
161 int index = to_sensor_dev_attr_2(attr)->index;
162 int nr = to_sensor_dev_attr_2(attr)->nr;
163 u8 reg, regval;
164 long val;
165 int err;
166
167 err = kstrtol(buf, 10, &val);
168 if (err < 0)
169 return err;
170
171 mutex_lock(&data->update_lock);
172 /* 10 mV LSB on limit registers */
173 regval = clamp_val(DIV_ROUND_CLOSEST(val, 10), 0, 255);
174 data->in[index][nr] = regval << 4;
175 reg = index == 1 ? ADC128_REG_IN_MIN(nr) : ADC128_REG_IN_MAX(nr);
176 i2c_smbus_write_byte_data(data->client, reg, regval);
177 mutex_unlock(&data->update_lock);
178
179 return count;
180}
181
182static ssize_t adc128_show_temp(struct device *dev,
183 struct device_attribute *attr, char *buf)
184{
185 struct adc128_data *data = adc128_update_device(dev);
186 int index = to_sensor_dev_attr(attr)->index;
187 int temp;
188
189 if (IS_ERR(data))
190 return PTR_ERR(data);
191
192 temp = (data->temp[index] << 7) >> 7; /* sign extend */
193 return sprintf(buf, "%d\n", temp * 500);/* 0.5 degrees C resolution */
194}
195
196static ssize_t adc128_set_temp(struct device *dev,
197 struct device_attribute *attr,
198 const char *buf, size_t count)
199{
200 struct adc128_data *data = dev_get_drvdata(dev);
201 int index = to_sensor_dev_attr(attr)->index;
202 long val;
203 int err;
204 s8 regval;
205
206 err = kstrtol(buf, 10, &val);
207 if (err < 0)
208 return err;
209
210 mutex_lock(&data->update_lock);
211 regval = clamp_val(DIV_ROUND_CLOSEST(val, 1000), -128, 127);
212 data->temp[index] = regval << 1;
213 i2c_smbus_write_byte_data(data->client,
214 index == 1 ? ADC128_REG_TEMP_MAX
215 : ADC128_REG_TEMP_HYST,
216 regval);
217 mutex_unlock(&data->update_lock);
218
219 return count;
220}
221
222static ssize_t adc128_show_alarm(struct device *dev,
223 struct device_attribute *attr, char *buf)
224{
225 struct adc128_data *data = adc128_update_device(dev);
226 int mask = 1 << to_sensor_dev_attr(attr)->index;
227 u8 alarms;
228
229 if (IS_ERR(data))
230 return PTR_ERR(data);
231
232 /*
233 * Clear an alarm after reporting it to user space. If it is still
234 * active, the next update sequence will set the alarm bit again.
235 */
236 alarms = data->alarms;
237 data->alarms &= ~mask;
238
239 return sprintf(buf, "%u\n", !!(alarms & mask));
240}
241
242static SENSOR_DEVICE_ATTR_2(in0_input, S_IWUSR | S_IRUGO,
243 adc128_show_in, adc128_set_in, 0, 0);
244static SENSOR_DEVICE_ATTR_2(in0_min, S_IWUSR | S_IRUGO,
245 adc128_show_in, adc128_set_in, 0, 1);
246static SENSOR_DEVICE_ATTR_2(in0_max, S_IWUSR | S_IRUGO,
247 adc128_show_in, adc128_set_in, 0, 2);
248
249static SENSOR_DEVICE_ATTR_2(in1_input, S_IWUSR | S_IRUGO,
250 adc128_show_in, adc128_set_in, 1, 0);
251static SENSOR_DEVICE_ATTR_2(in1_min, S_IWUSR | S_IRUGO,
252 adc128_show_in, adc128_set_in, 1, 1);
253static SENSOR_DEVICE_ATTR_2(in1_max, S_IWUSR | S_IRUGO,
254 adc128_show_in, adc128_set_in, 1, 2);
255
256static SENSOR_DEVICE_ATTR_2(in2_input, S_IWUSR | S_IRUGO,
257 adc128_show_in, adc128_set_in, 2, 0);
258static SENSOR_DEVICE_ATTR_2(in2_min, S_IWUSR | S_IRUGO,
259 adc128_show_in, adc128_set_in, 2, 1);
260static SENSOR_DEVICE_ATTR_2(in2_max, S_IWUSR | S_IRUGO,
261 adc128_show_in, adc128_set_in, 2, 2);
262
263static SENSOR_DEVICE_ATTR_2(in3_input, S_IWUSR | S_IRUGO,
264 adc128_show_in, adc128_set_in, 3, 0);
265static SENSOR_DEVICE_ATTR_2(in3_min, S_IWUSR | S_IRUGO,
266 adc128_show_in, adc128_set_in, 3, 1);
267static SENSOR_DEVICE_ATTR_2(in3_max, S_IWUSR | S_IRUGO,
268 adc128_show_in, adc128_set_in, 3, 2);
269
270static SENSOR_DEVICE_ATTR_2(in4_input, S_IWUSR | S_IRUGO,
271 adc128_show_in, adc128_set_in, 4, 0);
272static SENSOR_DEVICE_ATTR_2(in4_min, S_IWUSR | S_IRUGO,
273 adc128_show_in, adc128_set_in, 4, 1);
274static SENSOR_DEVICE_ATTR_2(in4_max, S_IWUSR | S_IRUGO,
275 adc128_show_in, adc128_set_in, 4, 2);
276
277static SENSOR_DEVICE_ATTR_2(in5_input, S_IWUSR | S_IRUGO,
278 adc128_show_in, adc128_set_in, 5, 0);
279static SENSOR_DEVICE_ATTR_2(in5_min, S_IWUSR | S_IRUGO,
280 adc128_show_in, adc128_set_in, 5, 1);
281static SENSOR_DEVICE_ATTR_2(in5_max, S_IWUSR | S_IRUGO,
282 adc128_show_in, adc128_set_in, 5, 2);
283
284static SENSOR_DEVICE_ATTR_2(in6_input, S_IWUSR | S_IRUGO,
285 adc128_show_in, adc128_set_in, 6, 0);
286static SENSOR_DEVICE_ATTR_2(in6_min, S_IWUSR | S_IRUGO,
287 adc128_show_in, adc128_set_in, 6, 1);
288static SENSOR_DEVICE_ATTR_2(in6_max, S_IWUSR | S_IRUGO,
289 adc128_show_in, adc128_set_in, 6, 2);
290
291static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, adc128_show_temp, NULL, 0);
292static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO,
293 adc128_show_temp, adc128_set_temp, 1);
294static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO,
295 adc128_show_temp, adc128_set_temp, 2);
296
297static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, adc128_show_alarm, NULL, 0);
298static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, adc128_show_alarm, NULL, 1);
299static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, adc128_show_alarm, NULL, 2);
300static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, adc128_show_alarm, NULL, 3);
301static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, adc128_show_alarm, NULL, 4);
302static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, adc128_show_alarm, NULL, 5);
303static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, adc128_show_alarm, NULL, 6);
304static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, adc128_show_alarm, NULL, 7);
305
306static struct attribute *adc128_attrs[] = {
307 &sensor_dev_attr_in0_min.dev_attr.attr,
308 &sensor_dev_attr_in1_min.dev_attr.attr,
309 &sensor_dev_attr_in2_min.dev_attr.attr,
310 &sensor_dev_attr_in3_min.dev_attr.attr,
311 &sensor_dev_attr_in4_min.dev_attr.attr,
312 &sensor_dev_attr_in5_min.dev_attr.attr,
313 &sensor_dev_attr_in6_min.dev_attr.attr,
314 &sensor_dev_attr_in0_max.dev_attr.attr,
315 &sensor_dev_attr_in1_max.dev_attr.attr,
316 &sensor_dev_attr_in2_max.dev_attr.attr,
317 &sensor_dev_attr_in3_max.dev_attr.attr,
318 &sensor_dev_attr_in4_max.dev_attr.attr,
319 &sensor_dev_attr_in5_max.dev_attr.attr,
320 &sensor_dev_attr_in6_max.dev_attr.attr,
321 &sensor_dev_attr_in0_input.dev_attr.attr,
322 &sensor_dev_attr_in1_input.dev_attr.attr,
323 &sensor_dev_attr_in2_input.dev_attr.attr,
324 &sensor_dev_attr_in3_input.dev_attr.attr,
325 &sensor_dev_attr_in4_input.dev_attr.attr,
326 &sensor_dev_attr_in5_input.dev_attr.attr,
327 &sensor_dev_attr_in6_input.dev_attr.attr,
328 &sensor_dev_attr_temp1_input.dev_attr.attr,
329 &sensor_dev_attr_temp1_max.dev_attr.attr,
330 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
331 &sensor_dev_attr_in0_alarm.dev_attr.attr,
332 &sensor_dev_attr_in1_alarm.dev_attr.attr,
333 &sensor_dev_attr_in2_alarm.dev_attr.attr,
334 &sensor_dev_attr_in3_alarm.dev_attr.attr,
335 &sensor_dev_attr_in4_alarm.dev_attr.attr,
336 &sensor_dev_attr_in5_alarm.dev_attr.attr,
337 &sensor_dev_attr_in6_alarm.dev_attr.attr,
338 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
339 NULL
340};
341ATTRIBUTE_GROUPS(adc128);
342
343static int adc128_detect(struct i2c_client *client, struct i2c_board_info *info)
344{
345 int man_id, dev_id;
346
347 if (!i2c_check_functionality(client->adapter,
348 I2C_FUNC_SMBUS_BYTE_DATA |
349 I2C_FUNC_SMBUS_WORD_DATA))
350 return -ENODEV;
351
352 man_id = i2c_smbus_read_byte_data(client, ADC128_REG_MAN_ID);
353 dev_id = i2c_smbus_read_byte_data(client, ADC128_REG_DEV_ID);
354 if (man_id != 0x01 || dev_id != 0x09)
355 return -ENODEV;
356
357 /* Check unused bits for confirmation */
358 if (i2c_smbus_read_byte_data(client, ADC128_REG_CONFIG) & 0xf4)
359 return -ENODEV;
360 if (i2c_smbus_read_byte_data(client, ADC128_REG_CONV_RATE) & 0xfe)
361 return -ENODEV;
362 if (i2c_smbus_read_byte_data(client, ADC128_REG_ONESHOT) & 0xfe)
363 return -ENODEV;
364 if (i2c_smbus_read_byte_data(client, ADC128_REG_SHUTDOWN) & 0xfe)
365 return -ENODEV;
366 if (i2c_smbus_read_byte_data(client, ADC128_REG_CONFIG_ADV) & 0xf8)
367 return -ENODEV;
368 if (i2c_smbus_read_byte_data(client, ADC128_REG_BUSY_STATUS) & 0xfc)
369 return -ENODEV;
370
371 strlcpy(info->type, "adc128d818", I2C_NAME_SIZE);
372
373 return 0;
374}
375
376static int adc128_init_client(struct adc128_data *data)
377{
378 struct i2c_client *client = data->client;
379 int err;
380
381 /*
382 * Reset chip to defaults.
383 * This makes most other initializations unnecessary.
384 */
385 err = i2c_smbus_write_byte_data(client, ADC128_REG_CONFIG, 0x80);
386 if (err)
387 return err;
388
389 /* Start monitoring */
390 err = i2c_smbus_write_byte_data(client, ADC128_REG_CONFIG, 0x01);
391 if (err)
392 return err;
393
394 /* If external vref is selected, configure the chip to use it */
395 if (data->regulator) {
396 err = i2c_smbus_write_byte_data(client,
397 ADC128_REG_CONFIG_ADV, 0x01);
398 if (err)
399 return err;
400 }
401
402 return 0;
403}
404
405static int adc128_probe(struct i2c_client *client,
406 const struct i2c_device_id *id)
407{
408 struct device *dev = &client->dev;
409 struct regulator *regulator;
410 struct device *hwmon_dev;
411 struct adc128_data *data;
412 int err, vref;
413
414 data = devm_kzalloc(dev, sizeof(struct adc128_data), GFP_KERNEL);
415 if (!data)
416 return -ENOMEM;
417
418 /* vref is optional. If specified, is used as chip reference voltage */
419 regulator = devm_regulator_get_optional(dev, "vref");
420 if (!IS_ERR(regulator)) {
421 data->regulator = regulator;
422 err = regulator_enable(regulator);
423 if (err < 0)
424 return err;
425 vref = regulator_get_voltage(regulator);
426 if (vref < 0) {
427 err = vref;
428 goto error;
429 }
430 data->vref = DIV_ROUND_CLOSEST(vref, 1000);
431 } else {
432 data->vref = 2560; /* 2.56V, in mV */
433 }
434
435 data->client = client;
436 i2c_set_clientdata(client, data);
437 mutex_init(&data->update_lock);
438
439 /* Initialize the chip */
440 err = adc128_init_client(data);
441 if (err < 0)
442 goto error;
443
444 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
445 data, adc128_groups);
446 if (IS_ERR(hwmon_dev)) {
447 err = PTR_ERR(hwmon_dev);
448 goto error;
449 }
450
451 return 0;
452
453error:
454 if (data->regulator)
455 regulator_disable(data->regulator);
456 return err;
457}
458
459static int adc128_remove(struct i2c_client *client)
460{
461 struct adc128_data *data = i2c_get_clientdata(client);
462
463 if (data->regulator)
464 regulator_disable(data->regulator);
465
466 return 0;
467}
468
469static const struct i2c_device_id adc128_id[] = {
470 { "adc128d818", 0 },
471 { }
472};
473MODULE_DEVICE_TABLE(i2c, adc128_id);
474
475static struct i2c_driver adc128_driver = {
476 .class = I2C_CLASS_HWMON,
477 .driver = {
478 .name = "adc128d818",
479 },
480 .probe = adc128_probe,
481 .remove = adc128_remove,
482 .id_table = adc128_id,
483 .detect = adc128_detect,
484 .address_list = normal_i2c,
485};
486
487module_i2c_driver(adc128_driver);
488
489MODULE_AUTHOR("Guenter Roeck");
490MODULE_DESCRIPTION("Driver for ADC128D818");
491MODULE_LICENSE("GPL");
diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
index bbb0b0d463f7..f31bc4c48644 100644
--- a/drivers/hwmon/coretemp.c
+++ b/drivers/hwmon/coretemp.c
@@ -94,6 +94,8 @@ struct temp_data {
94 bool valid; 94 bool valid;
95 struct sensor_device_attribute sd_attrs[TOTAL_ATTRS]; 95 struct sensor_device_attribute sd_attrs[TOTAL_ATTRS];
96 char attr_name[TOTAL_ATTRS][CORETEMP_NAME_LENGTH]; 96 char attr_name[TOTAL_ATTRS][CORETEMP_NAME_LENGTH];
97 struct attribute *attrs[TOTAL_ATTRS + 1];
98 struct attribute_group attr_group;
97 struct mutex update_lock; 99 struct mutex update_lock;
98}; 100};
99 101
@@ -114,12 +116,6 @@ struct pdev_entry {
114static LIST_HEAD(pdev_list); 116static LIST_HEAD(pdev_list);
115static DEFINE_MUTEX(pdev_list_mutex); 117static DEFINE_MUTEX(pdev_list_mutex);
116 118
117static ssize_t show_name(struct device *dev,
118 struct device_attribute *devattr, char *buf)
119{
120 return sprintf(buf, "%s\n", DRVNAME);
121}
122
123static ssize_t show_label(struct device *dev, 119static ssize_t show_label(struct device *dev,
124 struct device_attribute *devattr, char *buf) 120 struct device_attribute *devattr, char *buf)
125{ 121{
@@ -393,20 +389,10 @@ static int get_tjmax(struct cpuinfo_x86 *c, u32 id, struct device *dev)
393 return adjust_tjmax(c, id, dev); 389 return adjust_tjmax(c, id, dev);
394} 390}
395 391
396static int create_name_attr(struct platform_data *pdata,
397 struct device *dev)
398{
399 sysfs_attr_init(&pdata->name_attr.attr);
400 pdata->name_attr.attr.name = "name";
401 pdata->name_attr.attr.mode = S_IRUGO;
402 pdata->name_attr.show = show_name;
403 return device_create_file(dev, &pdata->name_attr);
404}
405
406static int create_core_attrs(struct temp_data *tdata, struct device *dev, 392static int create_core_attrs(struct temp_data *tdata, struct device *dev,
407 int attr_no) 393 int attr_no)
408{ 394{
409 int err, i; 395 int i;
410 static ssize_t (*const rd_ptr[TOTAL_ATTRS]) (struct device *dev, 396 static ssize_t (*const rd_ptr[TOTAL_ATTRS]) (struct device *dev,
411 struct device_attribute *devattr, char *buf) = { 397 struct device_attribute *devattr, char *buf) = {
412 show_label, show_crit_alarm, show_temp, show_tjmax, 398 show_label, show_crit_alarm, show_temp, show_tjmax,
@@ -424,16 +410,10 @@ static int create_core_attrs(struct temp_data *tdata, struct device *dev,
424 tdata->sd_attrs[i].dev_attr.attr.mode = S_IRUGO; 410 tdata->sd_attrs[i].dev_attr.attr.mode = S_IRUGO;
425 tdata->sd_attrs[i].dev_attr.show = rd_ptr[i]; 411 tdata->sd_attrs[i].dev_attr.show = rd_ptr[i];
426 tdata->sd_attrs[i].index = attr_no; 412 tdata->sd_attrs[i].index = attr_no;
427 err = device_create_file(dev, &tdata->sd_attrs[i].dev_attr); 413 tdata->attrs[i] = &tdata->sd_attrs[i].dev_attr.attr;
428 if (err)
429 goto exit_free;
430 } 414 }
431 return 0; 415 tdata->attr_group.attrs = tdata->attrs;
432 416 return sysfs_create_group(&dev->kobj, &tdata->attr_group);
433exit_free:
434 while (--i >= 0)
435 device_remove_file(dev, &tdata->sd_attrs[i].dev_attr);
436 return err;
437} 417}
438 418
439 419
@@ -548,7 +528,7 @@ static int create_core_data(struct platform_device *pdev, unsigned int cpu,
548 pdata->core_data[attr_no] = tdata; 528 pdata->core_data[attr_no] = tdata;
549 529
550 /* Create sysfs interfaces */ 530 /* Create sysfs interfaces */
551 err = create_core_attrs(tdata, &pdev->dev, attr_no); 531 err = create_core_attrs(tdata, pdata->hwmon_dev, attr_no);
552 if (err) 532 if (err)
553 goto exit_free; 533 goto exit_free;
554 534
@@ -573,14 +553,12 @@ static void coretemp_add_core(unsigned int cpu, int pkg_flag)
573} 553}
574 554
575static void coretemp_remove_core(struct platform_data *pdata, 555static void coretemp_remove_core(struct platform_data *pdata,
576 struct device *dev, int indx) 556 int indx)
577{ 557{
578 int i;
579 struct temp_data *tdata = pdata->core_data[indx]; 558 struct temp_data *tdata = pdata->core_data[indx];
580 559
581 /* Remove the sysfs attributes */ 560 /* Remove the sysfs attributes */
582 for (i = 0; i < tdata->attr_size; i++) 561 sysfs_remove_group(&pdata->hwmon_dev->kobj, &tdata->attr_group);
583 device_remove_file(dev, &tdata->sd_attrs[i].dev_attr);
584 562
585 kfree(pdata->core_data[indx]); 563 kfree(pdata->core_data[indx]);
586 pdata->core_data[indx] = NULL; 564 pdata->core_data[indx] = NULL;
@@ -588,34 +566,20 @@ static void coretemp_remove_core(struct platform_data *pdata,
588 566
589static int coretemp_probe(struct platform_device *pdev) 567static int coretemp_probe(struct platform_device *pdev)
590{ 568{
569 struct device *dev = &pdev->dev;
591 struct platform_data *pdata; 570 struct platform_data *pdata;
592 int err;
593 571
594 /* Initialize the per-package data structures */ 572 /* Initialize the per-package data structures */
595 pdata = kzalloc(sizeof(struct platform_data), GFP_KERNEL); 573 pdata = devm_kzalloc(dev, sizeof(struct platform_data), GFP_KERNEL);
596 if (!pdata) 574 if (!pdata)
597 return -ENOMEM; 575 return -ENOMEM;
598 576
599 err = create_name_attr(pdata, &pdev->dev);
600 if (err)
601 goto exit_free;
602
603 pdata->phys_proc_id = pdev->id; 577 pdata->phys_proc_id = pdev->id;
604 platform_set_drvdata(pdev, pdata); 578 platform_set_drvdata(pdev, pdata);
605 579
606 pdata->hwmon_dev = hwmon_device_register(&pdev->dev); 580 pdata->hwmon_dev = devm_hwmon_device_register_with_groups(dev, DRVNAME,
607 if (IS_ERR(pdata->hwmon_dev)) { 581 pdata, NULL);
608 err = PTR_ERR(pdata->hwmon_dev); 582 return PTR_ERR_OR_ZERO(pdata->hwmon_dev);
609 dev_err(&pdev->dev, "Class registration failed (%d)\n", err);
610 goto exit_name;
611 }
612 return 0;
613
614exit_name:
615 device_remove_file(&pdev->dev, &pdata->name_attr);
616exit_free:
617 kfree(pdata);
618 return err;
619} 583}
620 584
621static int coretemp_remove(struct platform_device *pdev) 585static int coretemp_remove(struct platform_device *pdev)
@@ -625,11 +589,8 @@ static int coretemp_remove(struct platform_device *pdev)
625 589
626 for (i = MAX_CORE_DATA - 1; i >= 0; --i) 590 for (i = MAX_CORE_DATA - 1; i >= 0; --i)
627 if (pdata->core_data[i]) 591 if (pdata->core_data[i])
628 coretemp_remove_core(pdata, &pdev->dev, i); 592 coretemp_remove_core(pdata, i);
629 593
630 device_remove_file(&pdev->dev, &pdata->name_attr);
631 hwmon_device_unregister(pdata->hwmon_dev);
632 kfree(pdata);
633 return 0; 594 return 0;
634} 595}
635 596
@@ -777,7 +738,7 @@ static void put_core_offline(unsigned int cpu)
777 return; 738 return;
778 739
779 if (pdata->core_data[indx] && pdata->core_data[indx]->cpu == cpu) 740 if (pdata->core_data[indx] && pdata->core_data[indx]->cpu == cpu)
780 coretemp_remove_core(pdata, &pdev->dev, indx); 741 coretemp_remove_core(pdata, indx);
781 742
782 /* 743 /*
783 * If a HT sibling of a core is taken offline, but another HT sibling 744 * If a HT sibling of a core is taken offline, but another HT sibling
diff --git a/drivers/hwmon/emc2103.c b/drivers/hwmon/emc2103.c
index 2c137b26acb4..fd892dd48e4c 100644
--- a/drivers/hwmon/emc2103.c
+++ b/drivers/hwmon/emc2103.c
@@ -349,7 +349,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *da,
349 dev_dbg(&client->dev, "reg 0x%02x, err %d\n", 349 dev_dbg(&client->dev, "reg 0x%02x, err %d\n",
350 REG_FAN_CONF1, status); 350 REG_FAN_CONF1, status);
351 mutex_unlock(&data->update_lock); 351 mutex_unlock(&data->update_lock);
352 return -EIO; 352 return status;
353 } 353 }
354 status &= 0x9F; 354 status &= 0x9F;
355 status |= (new_range_bits << 5); 355 status |= (new_range_bits << 5);
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index e176a43af63d..a26c385a435b 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -22,6 +22,7 @@
22#include <linux/gfp.h> 22#include <linux/gfp.h>
23#include <linux/spinlock.h> 23#include <linux/spinlock.h>
24#include <linux/pci.h> 24#include <linux/pci.h>
25#include <linux/string.h>
25 26
26#define HWMON_ID_PREFIX "hwmon" 27#define HWMON_ID_PREFIX "hwmon"
27#define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d" 28#define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d"
@@ -99,6 +100,10 @@ hwmon_device_register_with_groups(struct device *dev, const char *name,
99 struct hwmon_device *hwdev; 100 struct hwmon_device *hwdev;
100 int err, id; 101 int err, id;
101 102
103 /* Do not accept invalid characters in hwmon name attribute */
104 if (name && (!strlen(name) || strpbrk(name, "-* \t\n")))
105 return ERR_PTR(-EINVAL);
106
102 id = ida_simple_get(&hwmon_ida, 0, 0, GFP_KERNEL); 107 id = ida_simple_get(&hwmon_ida, 0, 0, GFP_KERNEL);
103 if (id < 0) 108 if (id < 0)
104 return ERR_PTR(id); 109 return ERR_PTR(id);
diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
index 708081b68c6f..9fbb1b1fdff3 100644
--- a/drivers/hwmon/iio_hwmon.c
+++ b/drivers/hwmon/iio_hwmon.c
@@ -31,6 +31,7 @@ struct iio_hwmon_state {
31 int num_channels; 31 int num_channels;
32 struct device *hwmon_dev; 32 struct device *hwmon_dev;
33 struct attribute_group attr_group; 33 struct attribute_group attr_group;
34 const struct attribute_group *groups[2];
34 struct attribute **attrs; 35 struct attribute **attrs;
35}; 36};
36 37
@@ -56,19 +57,6 @@ static ssize_t iio_hwmon_read_val(struct device *dev,
56 return sprintf(buf, "%d\n", result); 57 return sprintf(buf, "%d\n", result);
57} 58}
58 59
59static ssize_t show_name(struct device *dev, struct device_attribute *attr,
60 char *buf)
61{
62 const char *name = "iio_hwmon";
63
64 if (dev->of_node && dev->of_node->name)
65 name = dev->of_node->name;
66
67 return sprintf(buf, "%s\n", name);
68}
69
70static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
71
72static int iio_hwmon_probe(struct platform_device *pdev) 60static int iio_hwmon_probe(struct platform_device *pdev)
73{ 61{
74 struct device *dev = &pdev->dev; 62 struct device *dev = &pdev->dev;
@@ -78,6 +66,10 @@ static int iio_hwmon_probe(struct platform_device *pdev)
78 int in_i = 1, temp_i = 1, curr_i = 1; 66 int in_i = 1, temp_i = 1, curr_i = 1;
79 enum iio_chan_type type; 67 enum iio_chan_type type;
80 struct iio_channel *channels; 68 struct iio_channel *channels;
69 const char *name = "iio_hwmon";
70
71 if (dev->of_node && dev->of_node->name)
72 name = dev->of_node->name;
81 73
82 channels = iio_channel_get_all(dev); 74 channels = iio_channel_get_all(dev);
83 if (IS_ERR(channels)) 75 if (IS_ERR(channels))
@@ -96,7 +88,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
96 st->num_channels++; 88 st->num_channels++;
97 89
98 st->attrs = devm_kzalloc(dev, 90 st->attrs = devm_kzalloc(dev,
99 sizeof(*st->attrs) * (st->num_channels + 2), 91 sizeof(*st->attrs) * (st->num_channels + 1),
100 GFP_KERNEL); 92 GFP_KERNEL);
101 if (st->attrs == NULL) { 93 if (st->attrs == NULL) {
102 ret = -ENOMEM; 94 ret = -ENOMEM;
@@ -144,22 +136,18 @@ static int iio_hwmon_probe(struct platform_device *pdev)
144 a->index = i; 136 a->index = i;
145 st->attrs[i] = &a->dev_attr.attr; 137 st->attrs[i] = &a->dev_attr.attr;
146 } 138 }
147 st->attrs[st->num_channels] = &dev_attr_name.attr;
148 st->attr_group.attrs = st->attrs;
149 platform_set_drvdata(pdev, st);
150 ret = sysfs_create_group(&dev->kobj, &st->attr_group);
151 if (ret < 0)
152 goto error_release_channels;
153 139
154 st->hwmon_dev = hwmon_device_register(dev); 140 st->attr_group.attrs = st->attrs;
141 st->groups[0] = &st->attr_group;
142 st->hwmon_dev = hwmon_device_register_with_groups(dev, name, st,
143 st->groups);
155 if (IS_ERR(st->hwmon_dev)) { 144 if (IS_ERR(st->hwmon_dev)) {
156 ret = PTR_ERR(st->hwmon_dev); 145 ret = PTR_ERR(st->hwmon_dev);
157 goto error_remove_group; 146 goto error_release_channels;
158 } 147 }
148 platform_set_drvdata(pdev, st);
159 return 0; 149 return 0;
160 150
161error_remove_group:
162 sysfs_remove_group(&dev->kobj, &st->attr_group);
163error_release_channels: 151error_release_channels:
164 iio_channel_release_all(channels); 152 iio_channel_release_all(channels);
165 return ret; 153 return ret;
@@ -170,7 +158,6 @@ static int iio_hwmon_remove(struct platform_device *pdev)
170 struct iio_hwmon_state *st = platform_get_drvdata(pdev); 158 struct iio_hwmon_state *st = platform_get_drvdata(pdev);
171 159
172 hwmon_device_unregister(st->hwmon_dev); 160 hwmon_device_unregister(st->hwmon_dev);
173 sysfs_remove_group(&pdev->dev.kobj, &st->attr_group);
174 iio_channel_release_all(st->channels); 161 iio_channel_release_all(st->channels);
175 162
176 return 0; 163 return 0;
diff --git a/drivers/hwmon/jz4740-hwmon.c b/drivers/hwmon/jz4740-hwmon.c
index a183e488db78..7488e36809c8 100644
--- a/drivers/hwmon/jz4740-hwmon.c
+++ b/drivers/hwmon/jz4740-hwmon.c
@@ -28,7 +28,6 @@
28#include <linux/hwmon.h> 28#include <linux/hwmon.h>
29 29
30struct jz4740_hwmon { 30struct jz4740_hwmon {
31 struct resource *mem;
32 void __iomem *base; 31 void __iomem *base;
33 32
34 int irq; 33 int irq;
@@ -106,6 +105,7 @@ static int jz4740_hwmon_probe(struct platform_device *pdev)
106{ 105{
107 int ret; 106 int ret;
108 struct jz4740_hwmon *hwmon; 107 struct jz4740_hwmon *hwmon;
108 struct resource *mem;
109 109
110 hwmon = devm_kzalloc(&pdev->dev, sizeof(*hwmon), GFP_KERNEL); 110 hwmon = devm_kzalloc(&pdev->dev, sizeof(*hwmon), GFP_KERNEL);
111 if (!hwmon) 111 if (!hwmon)
@@ -120,25 +120,10 @@ static int jz4740_hwmon_probe(struct platform_device *pdev)
120 return hwmon->irq; 120 return hwmon->irq;
121 } 121 }
122 122
123 hwmon->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 123 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
124 if (!hwmon->mem) { 124 hwmon->base = devm_ioremap_resource(&pdev->dev, mem);
125 dev_err(&pdev->dev, "Failed to get platform mmio resource\n"); 125 if (IS_ERR(hwmon->base))
126 return -ENOENT; 126 return PTR_ERR(hwmon->base);
127 }
128
129 hwmon->mem = devm_request_mem_region(&pdev->dev, hwmon->mem->start,
130 resource_size(hwmon->mem), pdev->name);
131 if (!hwmon->mem) {
132 dev_err(&pdev->dev, "Failed to request mmio memory region\n");
133 return -EBUSY;
134 }
135
136 hwmon->base = devm_ioremap_nocache(&pdev->dev, hwmon->mem->start,
137 resource_size(hwmon->mem));
138 if (!hwmon->base) {
139 dev_err(&pdev->dev, "Failed to ioremap mmio memory\n");
140 return -EBUSY;
141 }
142 127
143 init_completion(&hwmon->read_completion); 128 init_completion(&hwmon->read_completion);
144 mutex_init(&hwmon->lock); 129 mutex_init(&hwmon->lock);
diff --git a/drivers/hwmon/lm95241.c b/drivers/hwmon/lm95241.c
index 4b68fb2a31d7..cdf19adaec79 100644
--- a/drivers/hwmon/lm95241.c
+++ b/drivers/hwmon/lm95241.c
@@ -89,7 +89,7 @@ static const u8 lm95241_reg_address[] = {
89 89
90/* Client data (each client gets its own) */ 90/* Client data (each client gets its own) */
91struct lm95241_data { 91struct lm95241_data {
92 struct device *hwmon_dev; 92 struct i2c_client *client;
93 struct mutex update_lock; 93 struct mutex update_lock;
94 unsigned long last_updated, interval; /* in jiffies */ 94 unsigned long last_updated, interval; /* in jiffies */
95 char valid; /* zero until following fields are valid */ 95 char valid; /* zero until following fields are valid */
@@ -113,8 +113,8 @@ static int temp_from_reg_unsigned(u8 val_h, u8 val_l)
113 113
114static struct lm95241_data *lm95241_update_device(struct device *dev) 114static struct lm95241_data *lm95241_update_device(struct device *dev)
115{ 115{
116 struct i2c_client *client = to_i2c_client(dev); 116 struct lm95241_data *data = dev_get_drvdata(dev);
117 struct lm95241_data *data = i2c_get_clientdata(client); 117 struct i2c_client *client = data->client;
118 118
119 mutex_lock(&data->update_lock); 119 mutex_lock(&data->update_lock);
120 120
@@ -122,7 +122,7 @@ static struct lm95241_data *lm95241_update_device(struct device *dev)
122 !data->valid) { 122 !data->valid) {
123 int i; 123 int i;
124 124
125 dev_dbg(&client->dev, "Updating lm95241 data.\n"); 125 dev_dbg(dev, "Updating lm95241 data.\n");
126 for (i = 0; i < ARRAY_SIZE(lm95241_reg_address); i++) 126 for (i = 0; i < ARRAY_SIZE(lm95241_reg_address); i++)
127 data->temp[i] 127 data->temp[i]
128 = i2c_smbus_read_byte_data(client, 128 = i2c_smbus_read_byte_data(client,
@@ -153,8 +153,7 @@ static ssize_t show_input(struct device *dev, struct device_attribute *attr,
153static ssize_t show_type(struct device *dev, struct device_attribute *attr, 153static ssize_t show_type(struct device *dev, struct device_attribute *attr,
154 char *buf) 154 char *buf)
155{ 155{
156 struct i2c_client *client = to_i2c_client(dev); 156 struct lm95241_data *data = dev_get_drvdata(dev);
157 struct lm95241_data *data = i2c_get_clientdata(client);
158 157
159 return snprintf(buf, PAGE_SIZE - 1, 158 return snprintf(buf, PAGE_SIZE - 1,
160 data->model & to_sensor_dev_attr(attr)->index ? "1\n" : "2\n"); 159 data->model & to_sensor_dev_attr(attr)->index ? "1\n" : "2\n");
@@ -163,8 +162,8 @@ static ssize_t show_type(struct device *dev, struct device_attribute *attr,
163static ssize_t set_type(struct device *dev, struct device_attribute *attr, 162static ssize_t set_type(struct device *dev, struct device_attribute *attr,
164 const char *buf, size_t count) 163 const char *buf, size_t count)
165{ 164{
166 struct i2c_client *client = to_i2c_client(dev); 165 struct lm95241_data *data = dev_get_drvdata(dev);
167 struct lm95241_data *data = i2c_get_clientdata(client); 166 struct i2c_client *client = data->client;
168 unsigned long val; 167 unsigned long val;
169 int shift; 168 int shift;
170 u8 mask = to_sensor_dev_attr(attr)->index; 169 u8 mask = to_sensor_dev_attr(attr)->index;
@@ -201,8 +200,7 @@ static ssize_t set_type(struct device *dev, struct device_attribute *attr,
201static ssize_t show_min(struct device *dev, struct device_attribute *attr, 200static ssize_t show_min(struct device *dev, struct device_attribute *attr,
202 char *buf) 201 char *buf)
203{ 202{
204 struct i2c_client *client = to_i2c_client(dev); 203 struct lm95241_data *data = dev_get_drvdata(dev);
205 struct lm95241_data *data = i2c_get_clientdata(client);
206 204
207 return snprintf(buf, PAGE_SIZE - 1, 205 return snprintf(buf, PAGE_SIZE - 1,
208 data->config & to_sensor_dev_attr(attr)->index ? 206 data->config & to_sensor_dev_attr(attr)->index ?
@@ -212,8 +210,7 @@ static ssize_t show_min(struct device *dev, struct device_attribute *attr,
212static ssize_t set_min(struct device *dev, struct device_attribute *attr, 210static ssize_t set_min(struct device *dev, struct device_attribute *attr,
213 const char *buf, size_t count) 211 const char *buf, size_t count)
214{ 212{
215 struct i2c_client *client = to_i2c_client(dev); 213 struct lm95241_data *data = dev_get_drvdata(dev);
216 struct lm95241_data *data = i2c_get_clientdata(client);
217 long val; 214 long val;
218 215
219 if (kstrtol(buf, 10, &val) < 0) 216 if (kstrtol(buf, 10, &val) < 0)
@@ -229,7 +226,8 @@ static ssize_t set_min(struct device *dev, struct device_attribute *attr,
229 data->config &= ~to_sensor_dev_attr(attr)->index; 226 data->config &= ~to_sensor_dev_attr(attr)->index;
230 data->valid = 0; 227 data->valid = 0;
231 228
232 i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, data->config); 229 i2c_smbus_write_byte_data(data->client, LM95241_REG_RW_CONFIG,
230 data->config);
233 231
234 mutex_unlock(&data->update_lock); 232 mutex_unlock(&data->update_lock);
235 233
@@ -239,8 +237,7 @@ static ssize_t set_min(struct device *dev, struct device_attribute *attr,
239static ssize_t show_max(struct device *dev, struct device_attribute *attr, 237static ssize_t show_max(struct device *dev, struct device_attribute *attr,
240 char *buf) 238 char *buf)
241{ 239{
242 struct i2c_client *client = to_i2c_client(dev); 240 struct lm95241_data *data = dev_get_drvdata(dev);
243 struct lm95241_data *data = i2c_get_clientdata(client);
244 241
245 return snprintf(buf, PAGE_SIZE - 1, 242 return snprintf(buf, PAGE_SIZE - 1,
246 data->config & to_sensor_dev_attr(attr)->index ? 243 data->config & to_sensor_dev_attr(attr)->index ?
@@ -250,8 +247,7 @@ static ssize_t show_max(struct device *dev, struct device_attribute *attr,
250static ssize_t set_max(struct device *dev, struct device_attribute *attr, 247static ssize_t set_max(struct device *dev, struct device_attribute *attr,
251 const char *buf, size_t count) 248 const char *buf, size_t count)
252{ 249{
253 struct i2c_client *client = to_i2c_client(dev); 250 struct lm95241_data *data = dev_get_drvdata(dev);
254 struct lm95241_data *data = i2c_get_clientdata(client);
255 long val; 251 long val;
256 252
257 if (kstrtol(buf, 10, &val) < 0) 253 if (kstrtol(buf, 10, &val) < 0)
@@ -267,7 +263,8 @@ static ssize_t set_max(struct device *dev, struct device_attribute *attr,
267 data->config &= ~to_sensor_dev_attr(attr)->index; 263 data->config &= ~to_sensor_dev_attr(attr)->index;
268 data->valid = 0; 264 data->valid = 0;
269 265
270 i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, data->config); 266 i2c_smbus_write_byte_data(data->client, LM95241_REG_RW_CONFIG,
267 data->config);
271 268
272 mutex_unlock(&data->update_lock); 269 mutex_unlock(&data->update_lock);
273 270
@@ -286,8 +283,7 @@ static ssize_t show_interval(struct device *dev, struct device_attribute *attr,
286static ssize_t set_interval(struct device *dev, struct device_attribute *attr, 283static ssize_t set_interval(struct device *dev, struct device_attribute *attr,
287 const char *buf, size_t count) 284 const char *buf, size_t count)
288{ 285{
289 struct i2c_client *client = to_i2c_client(dev); 286 struct lm95241_data *data = dev_get_drvdata(dev);
290 struct lm95241_data *data = i2c_get_clientdata(client);
291 unsigned long val; 287 unsigned long val;
292 288
293 if (kstrtoul(buf, 10, &val) < 0) 289 if (kstrtoul(buf, 10, &val) < 0)
@@ -316,7 +312,7 @@ static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_max, set_max,
316static DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, show_interval, 312static DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, show_interval,
317 set_interval); 313 set_interval);
318 314
319static struct attribute *lm95241_attributes[] = { 315static struct attribute *lm95241_attrs[] = {
320 &sensor_dev_attr_temp1_input.dev_attr.attr, 316 &sensor_dev_attr_temp1_input.dev_attr.attr,
321 &sensor_dev_attr_temp2_input.dev_attr.attr, 317 &sensor_dev_attr_temp2_input.dev_attr.attr,
322 &sensor_dev_attr_temp3_input.dev_attr.attr, 318 &sensor_dev_attr_temp3_input.dev_attr.attr,
@@ -329,10 +325,7 @@ static struct attribute *lm95241_attributes[] = {
329 &dev_attr_update_interval.attr, 325 &dev_attr_update_interval.attr,
330 NULL 326 NULL
331}; 327};
332 328ATTRIBUTE_GROUPS(lm95241);
333static const struct attribute_group lm95241_group = {
334 .attrs = lm95241_attributes,
335};
336 329
337/* Return 0 if detection is successful, -ENODEV otherwise */ 330/* Return 0 if detection is successful, -ENODEV otherwise */
338static int lm95241_detect(struct i2c_client *new_client, 331static int lm95241_detect(struct i2c_client *new_client,
@@ -366,14 +359,11 @@ static int lm95241_detect(struct i2c_client *new_client,
366 return 0; 359 return 0;
367} 360}
368 361
369static void lm95241_init_client(struct i2c_client *client) 362static void lm95241_init_client(struct i2c_client *client,
363 struct lm95241_data *data)
370{ 364{
371 struct lm95241_data *data = i2c_get_clientdata(client);
372
373 data->interval = HZ; /* 1 sec default */ 365 data->interval = HZ; /* 1 sec default */
374 data->valid = 0;
375 data->config = CFG_CR0076; 366 data->config = CFG_CR0076;
376 data->model = 0;
377 data->trutherm = (TT_OFF << TT1_SHIFT) | (TT_OFF << TT2_SHIFT); 367 data->trutherm = (TT_OFF << TT1_SHIFT) | (TT_OFF << TT2_SHIFT);
378 368
379 i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, data->config); 369 i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, data->config);
@@ -385,49 +375,27 @@ static void lm95241_init_client(struct i2c_client *client)
385 data->model); 375 data->model);
386} 376}
387 377
388static int lm95241_probe(struct i2c_client *new_client, 378static int lm95241_probe(struct i2c_client *client,
389 const struct i2c_device_id *id) 379 const struct i2c_device_id *id)
390{ 380{
381 struct device *dev = &client->dev;
391 struct lm95241_data *data; 382 struct lm95241_data *data;
392 int err; 383 struct device *hwmon_dev;
393 384
394 data = devm_kzalloc(&new_client->dev, sizeof(struct lm95241_data), 385 data = devm_kzalloc(dev, sizeof(struct lm95241_data), GFP_KERNEL);
395 GFP_KERNEL);
396 if (!data) 386 if (!data)
397 return -ENOMEM; 387 return -ENOMEM;
398 388
399 i2c_set_clientdata(new_client, data); 389 data->client = client;
400 mutex_init(&data->update_lock); 390 mutex_init(&data->update_lock);
401 391
402 /* Initialize the LM95241 chip */ 392 /* Initialize the LM95241 chip */
403 lm95241_init_client(new_client); 393 lm95241_init_client(client, data);
404 394
405 /* Register sysfs hooks */ 395 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
406 err = sysfs_create_group(&new_client->dev.kobj, &lm95241_group); 396 data,
407 if (err) 397 lm95241_groups);
408 return err; 398 return PTR_ERR_OR_ZERO(hwmon_dev);
409
410 data->hwmon_dev = hwmon_device_register(&new_client->dev);
411 if (IS_ERR(data->hwmon_dev)) {
412 err = PTR_ERR(data->hwmon_dev);
413 goto exit_remove_files;
414 }
415
416 return 0;
417
418exit_remove_files:
419 sysfs_remove_group(&new_client->dev.kobj, &lm95241_group);
420 return err;
421}
422
423static int lm95241_remove(struct i2c_client *client)
424{
425 struct lm95241_data *data = i2c_get_clientdata(client);
426
427 hwmon_device_unregister(data->hwmon_dev);
428 sysfs_remove_group(&client->dev.kobj, &lm95241_group);
429
430 return 0;
431} 399}
432 400
433/* Driver data (common to all clients) */ 401/* Driver data (common to all clients) */
@@ -444,7 +412,6 @@ static struct i2c_driver lm95241_driver = {
444 .name = DEVNAME, 412 .name = DEVNAME,
445 }, 413 },
446 .probe = lm95241_probe, 414 .probe = lm95241_probe,
447 .remove = lm95241_remove,
448 .id_table = lm95241_id, 415 .id_table = lm95241_id,
449 .detect = lm95241_detect, 416 .detect = lm95241_detect,
450 .address_list = normal_i2c, 417 .address_list = normal_i2c,
diff --git a/drivers/hwmon/lm95245.c b/drivers/hwmon/lm95245.c
index a6c85f0ff8f3..0ae0dfdafdff 100644
--- a/drivers/hwmon/lm95245.c
+++ b/drivers/hwmon/lm95245.c
@@ -115,7 +115,7 @@ static const u8 lm95245_reg_address[] = {
115 115
116/* Client data (each client gets its own) */ 116/* Client data (each client gets its own) */
117struct lm95245_data { 117struct lm95245_data {
118 struct device *hwmon_dev; 118 struct i2c_client *client;
119 struct mutex update_lock; 119 struct mutex update_lock;
120 unsigned long last_updated; /* in jiffies */ 120 unsigned long last_updated; /* in jiffies */
121 unsigned long interval; /* in msecs */ 121 unsigned long interval; /* in msecs */
@@ -140,8 +140,8 @@ static int temp_from_reg_signed(u8 val_h, u8 val_l)
140 140
141static struct lm95245_data *lm95245_update_device(struct device *dev) 141static struct lm95245_data *lm95245_update_device(struct device *dev)
142{ 142{
143 struct i2c_client *client = to_i2c_client(dev); 143 struct lm95245_data *data = dev_get_drvdata(dev);
144 struct lm95245_data *data = i2c_get_clientdata(client); 144 struct i2c_client *client = data->client;
145 145
146 mutex_lock(&data->update_lock); 146 mutex_lock(&data->update_lock);
147 147
@@ -149,7 +149,6 @@ static struct lm95245_data *lm95245_update_device(struct device *dev)
149 + msecs_to_jiffies(data->interval)) || !data->valid) { 149 + msecs_to_jiffies(data->interval)) || !data->valid) {
150 int i; 150 int i;
151 151
152 dev_dbg(&client->dev, "Updating lm95245 data.\n");
153 for (i = 0; i < ARRAY_SIZE(lm95245_reg_address); i++) 152 for (i = 0; i < ARRAY_SIZE(lm95245_reg_address); i++)
154 data->regs[i] 153 data->regs[i]
155 = i2c_smbus_read_byte_data(client, 154 = i2c_smbus_read_byte_data(client,
@@ -249,9 +248,9 @@ static ssize_t show_limit(struct device *dev, struct device_attribute *attr,
249static ssize_t set_limit(struct device *dev, struct device_attribute *attr, 248static ssize_t set_limit(struct device *dev, struct device_attribute *attr,
250 const char *buf, size_t count) 249 const char *buf, size_t count)
251{ 250{
252 struct i2c_client *client = to_i2c_client(dev); 251 struct lm95245_data *data = dev_get_drvdata(dev);
253 struct lm95245_data *data = i2c_get_clientdata(client);
254 int index = to_sensor_dev_attr(attr)->index; 252 int index = to_sensor_dev_attr(attr)->index;
253 struct i2c_client *client = data->client;
255 unsigned long val; 254 unsigned long val;
256 255
257 if (kstrtoul(buf, 10, &val) < 0) 256 if (kstrtoul(buf, 10, &val) < 0)
@@ -272,27 +271,38 @@ static ssize_t set_limit(struct device *dev, struct device_attribute *attr,
272 return count; 271 return count;
273} 272}
274 273
274static ssize_t show_crit_hyst(struct device *dev, struct device_attribute *attr,
275 char *buf)
276{
277 struct lm95245_data *data = lm95245_update_device(dev);
278 int index = to_sensor_dev_attr(attr)->index;
279 int hyst = data->regs[index] - data->regs[8];
280
281 return snprintf(buf, PAGE_SIZE - 1, "%d\n", hyst * 1000);
282}
283
275static ssize_t set_crit_hyst(struct device *dev, struct device_attribute *attr, 284static ssize_t set_crit_hyst(struct device *dev, struct device_attribute *attr,
276 const char *buf, size_t count) 285 const char *buf, size_t count)
277{ 286{
278 struct i2c_client *client = to_i2c_client(dev); 287 struct lm95245_data *data = dev_get_drvdata(dev);
279 struct lm95245_data *data = i2c_get_clientdata(client); 288 int index = to_sensor_dev_attr(attr)->index;
289 struct i2c_client *client = data->client;
280 unsigned long val; 290 unsigned long val;
291 int hyst, limit;
281 292
282 if (kstrtoul(buf, 10, &val) < 0) 293 if (kstrtoul(buf, 10, &val) < 0)
283 return -EINVAL; 294 return -EINVAL;
284 295
285 val /= 1000;
286
287 val = clamp_val(val, 0, 31);
288
289 mutex_lock(&data->update_lock); 296 mutex_lock(&data->update_lock);
290 297
291 data->valid = 0; 298 limit = i2c_smbus_read_byte_data(client, lm95245_reg_address[index]);
299 hyst = limit - val / 1000;
300 hyst = clamp_val(hyst, 0, 31);
301 data->regs[8] = hyst;
292 302
293 /* shared crit hysteresis */ 303 /* shared crit hysteresis */
294 i2c_smbus_write_byte_data(client, LM95245_REG_RW_COMMON_HYSTERESIS, 304 i2c_smbus_write_byte_data(client, LM95245_REG_RW_COMMON_HYSTERESIS,
295 val); 305 hyst);
296 306
297 mutex_unlock(&data->update_lock); 307 mutex_unlock(&data->update_lock);
298 308
@@ -302,8 +312,7 @@ static ssize_t set_crit_hyst(struct device *dev, struct device_attribute *attr,
302static ssize_t show_type(struct device *dev, struct device_attribute *attr, 312static ssize_t show_type(struct device *dev, struct device_attribute *attr,
303 char *buf) 313 char *buf)
304{ 314{
305 struct i2c_client *client = to_i2c_client(dev); 315 struct lm95245_data *data = dev_get_drvdata(dev);
306 struct lm95245_data *data = i2c_get_clientdata(client);
307 316
308 return snprintf(buf, PAGE_SIZE - 1, 317 return snprintf(buf, PAGE_SIZE - 1,
309 data->config2 & CFG2_REMOTE_TT ? "1\n" : "2\n"); 318 data->config2 & CFG2_REMOTE_TT ? "1\n" : "2\n");
@@ -312,8 +321,8 @@ static ssize_t show_type(struct device *dev, struct device_attribute *attr,
312static ssize_t set_type(struct device *dev, struct device_attribute *attr, 321static ssize_t set_type(struct device *dev, struct device_attribute *attr,
313 const char *buf, size_t count) 322 const char *buf, size_t count)
314{ 323{
315 struct i2c_client *client = to_i2c_client(dev); 324 struct lm95245_data *data = dev_get_drvdata(dev);
316 struct lm95245_data *data = i2c_get_clientdata(client); 325 struct i2c_client *client = data->client;
317 unsigned long val; 326 unsigned long val;
318 327
319 if (kstrtoul(buf, 10, &val) < 0) 328 if (kstrtoul(buf, 10, &val) < 0)
@@ -359,8 +368,8 @@ static ssize_t show_interval(struct device *dev, struct device_attribute *attr,
359static ssize_t set_interval(struct device *dev, struct device_attribute *attr, 368static ssize_t set_interval(struct device *dev, struct device_attribute *attr,
360 const char *buf, size_t count) 369 const char *buf, size_t count)
361{ 370{
362 struct i2c_client *client = to_i2c_client(dev); 371 struct lm95245_data *data = dev_get_drvdata(dev);
363 struct lm95245_data *data = i2c_get_clientdata(client); 372 struct i2c_client *client = data->client;
364 unsigned long val; 373 unsigned long val;
365 374
366 if (kstrtoul(buf, 10, &val) < 0) 375 if (kstrtoul(buf, 10, &val) < 0)
@@ -378,16 +387,15 @@ static ssize_t set_interval(struct device *dev, struct device_attribute *attr,
378static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_input, NULL, 0); 387static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_input, NULL, 0);
379static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_limit, 388static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_limit,
380 set_limit, 6); 389 set_limit, 6);
381static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_limit, 390static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_crit_hyst,
382 set_crit_hyst, 8); 391 set_crit_hyst, 6);
383static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 392static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL,
384 STATUS1_LOC); 393 STATUS1_LOC);
385 394
386static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_input, NULL, 2); 395static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_input, NULL, 2);
387static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_limit, 396static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_limit,
388 set_limit, 7); 397 set_limit, 7);
389static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_limit, 398static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_crit_hyst, NULL, 7);
390 set_crit_hyst, 8);
391static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 399static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL,
392 STATUS1_RTCRIT); 400 STATUS1_RTCRIT);
393static SENSOR_DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type, 401static SENSOR_DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type,
@@ -398,7 +406,7 @@ static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL,
398static DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, show_interval, 406static DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, show_interval,
399 set_interval); 407 set_interval);
400 408
401static struct attribute *lm95245_attributes[] = { 409static struct attribute *lm95245_attrs[] = {
402 &sensor_dev_attr_temp1_input.dev_attr.attr, 410 &sensor_dev_attr_temp1_input.dev_attr.attr,
403 &sensor_dev_attr_temp1_crit.dev_attr.attr, 411 &sensor_dev_attr_temp1_crit.dev_attr.attr,
404 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr, 412 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
@@ -412,10 +420,7 @@ static struct attribute *lm95245_attributes[] = {
412 &dev_attr_update_interval.attr, 420 &dev_attr_update_interval.attr,
413 NULL 421 NULL
414}; 422};
415 423ATTRIBUTE_GROUPS(lm95245);
416static const struct attribute_group lm95245_group = {
417 .attrs = lm95245_attributes,
418};
419 424
420/* Return 0 if detection is successful, -ENODEV otherwise */ 425/* Return 0 if detection is successful, -ENODEV otherwise */
421static int lm95245_detect(struct i2c_client *new_client, 426static int lm95245_detect(struct i2c_client *new_client,
@@ -436,11 +441,9 @@ static int lm95245_detect(struct i2c_client *new_client,
436 return 0; 441 return 0;
437} 442}
438 443
439static void lm95245_init_client(struct i2c_client *client) 444static void lm95245_init_client(struct i2c_client *client,
445 struct lm95245_data *data)
440{ 446{
441 struct lm95245_data *data = i2c_get_clientdata(client);
442
443 data->valid = 0;
444 data->interval = lm95245_read_conversion_rate(client); 447 data->interval = lm95245_read_conversion_rate(client);
445 448
446 data->config1 = i2c_smbus_read_byte_data(client, 449 data->config1 = i2c_smbus_read_byte_data(client,
@@ -456,49 +459,27 @@ static void lm95245_init_client(struct i2c_client *client)
456 } 459 }
457} 460}
458 461
459static int lm95245_probe(struct i2c_client *new_client, 462static int lm95245_probe(struct i2c_client *client,
460 const struct i2c_device_id *id) 463 const struct i2c_device_id *id)
461{ 464{
465 struct device *dev = &client->dev;
462 struct lm95245_data *data; 466 struct lm95245_data *data;
463 int err; 467 struct device *hwmon_dev;
464 468
465 data = devm_kzalloc(&new_client->dev, sizeof(struct lm95245_data), 469 data = devm_kzalloc(dev, sizeof(struct lm95245_data), GFP_KERNEL);
466 GFP_KERNEL);
467 if (!data) 470 if (!data)
468 return -ENOMEM; 471 return -ENOMEM;
469 472
470 i2c_set_clientdata(new_client, data); 473 data->client = client;
471 mutex_init(&data->update_lock); 474 mutex_init(&data->update_lock);
472 475
473 /* Initialize the LM95245 chip */ 476 /* Initialize the LM95245 chip */
474 lm95245_init_client(new_client); 477 lm95245_init_client(client, data);
475
476 /* Register sysfs hooks */
477 err = sysfs_create_group(&new_client->dev.kobj, &lm95245_group);
478 if (err)
479 return err;
480
481 data->hwmon_dev = hwmon_device_register(&new_client->dev);
482 if (IS_ERR(data->hwmon_dev)) {
483 err = PTR_ERR(data->hwmon_dev);
484 goto exit_remove_files;
485 }
486
487 return 0;
488
489exit_remove_files:
490 sysfs_remove_group(&new_client->dev.kobj, &lm95245_group);
491 return err;
492}
493 478
494static int lm95245_remove(struct i2c_client *client) 479 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
495{ 480 data,
496 struct lm95245_data *data = i2c_get_clientdata(client); 481 lm95245_groups);
497 482 return PTR_ERR_OR_ZERO(hwmon_dev);
498 hwmon_device_unregister(data->hwmon_dev);
499 sysfs_remove_group(&client->dev.kobj, &lm95245_group);
500
501 return 0;
502} 483}
503 484
504/* Driver data (common to all clients) */ 485/* Driver data (common to all clients) */
@@ -514,7 +495,6 @@ static struct i2c_driver lm95245_driver = {
514 .name = DEVNAME, 495 .name = DEVNAME,
515 }, 496 },
516 .probe = lm95245_probe, 497 .probe = lm95245_probe,
517 .remove = lm95245_remove,
518 .id_table = lm95245_id, 498 .id_table = lm95245_id,
519 .detect = lm95245_detect, 499 .detect = lm95245_detect,
520 .address_list = normal_i2c, 500 .address_list = normal_i2c,
diff --git a/drivers/hwmon/ltc2945.c b/drivers/hwmon/ltc2945.c
new file mode 100644
index 000000000000..c104cc32989d
--- /dev/null
+++ b/drivers/hwmon/ltc2945.c
@@ -0,0 +1,519 @@
1/*
2 * Driver for Linear Technology LTC2945 I2C Power Monitor
3 *
4 * Copyright (c) 2014 Guenter Roeck
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/err.h>
20#include <linux/slab.h>
21#include <linux/i2c.h>
22#include <linux/hwmon.h>
23#include <linux/hwmon-sysfs.h>
24#include <linux/jiffies.h>
25#include <linux/regmap.h>
26
27/* chip registers */
28#define LTC2945_CONTROL 0x00
29#define LTC2945_ALERT 0x01
30#define LTC2945_STATUS 0x02
31#define LTC2945_FAULT 0x03
32#define LTC2945_POWER_H 0x05
33#define LTC2945_MAX_POWER_H 0x08
34#define LTC2945_MIN_POWER_H 0x0b
35#define LTC2945_MAX_POWER_THRES_H 0x0e
36#define LTC2945_MIN_POWER_THRES_H 0x11
37#define LTC2945_SENSE_H 0x14
38#define LTC2945_MAX_SENSE_H 0x16
39#define LTC2945_MIN_SENSE_H 0x18
40#define LTC2945_MAX_SENSE_THRES_H 0x1a
41#define LTC2945_MIN_SENSE_THRES_H 0x1c
42#define LTC2945_VIN_H 0x1e
43#define LTC2945_MAX_VIN_H 0x20
44#define LTC2945_MIN_VIN_H 0x22
45#define LTC2945_MAX_VIN_THRES_H 0x24
46#define LTC2945_MIN_VIN_THRES_H 0x26
47#define LTC2945_ADIN_H 0x28
48#define LTC2945_MAX_ADIN_H 0x2a
49#define LTC2945_MIN_ADIN_H 0x2c
50#define LTC2945_MAX_ADIN_THRES_H 0x2e
51#define LTC2945_MIN_ADIN_THRES_H 0x30
52#define LTC2945_MIN_ADIN_THRES_L 0x31
53
54/* Fault register bits */
55
56#define FAULT_ADIN_UV (1 << 0)
57#define FAULT_ADIN_OV (1 << 1)
58#define FAULT_VIN_UV (1 << 2)
59#define FAULT_VIN_OV (1 << 3)
60#define FAULT_SENSE_UV (1 << 4)
61#define FAULT_SENSE_OV (1 << 5)
62#define FAULT_POWER_UV (1 << 6)
63#define FAULT_POWER_OV (1 << 7)
64
65/* Control register bits */
66
67#define CONTROL_MULT_SELECT (1 << 0)
68#define CONTROL_TEST_MODE (1 << 4)
69
70static inline bool is_power_reg(u8 reg)
71{
72 return reg < LTC2945_SENSE_H;
73}
74
75/* Return the value from the given register in uW, mV, or mA */
76static long long ltc2945_reg_to_val(struct device *dev, u8 reg)
77{
78 struct regmap *regmap = dev_get_drvdata(dev);
79 unsigned int control;
80 u8 buf[3];
81 long long val;
82 int ret;
83
84 ret = regmap_bulk_read(regmap, reg, buf,
85 is_power_reg(reg) ? 3 : 2);
86 if (ret < 0)
87 return ret;
88
89 if (is_power_reg(reg)) {
90 /* power */
91 val = (buf[0] << 16) + (buf[1] << 8) + buf[2];
92 } else {
93 /* current, voltage */
94 val = (buf[0] << 4) + (buf[1] >> 4);
95 }
96
97 switch (reg) {
98 case LTC2945_POWER_H:
99 case LTC2945_MAX_POWER_H:
100 case LTC2945_MIN_POWER_H:
101 case LTC2945_MAX_POWER_THRES_H:
102 case LTC2945_MIN_POWER_THRES_H:
103 /*
104 * Convert to uW by assuming current is measured with
105 * an 1mOhm sense resistor, similar to current
106 * measurements.
107 * Control register bit 0 selects if voltage at SENSE+/VDD
108 * or voltage at ADIN is used to measure power.
109 */
110 ret = regmap_read(regmap, LTC2945_CONTROL, &control);
111 if (ret < 0)
112 return ret;
113 if (control & CONTROL_MULT_SELECT) {
114 /* 25 mV * 25 uV = 0.625 uV resolution. */
115 val *= 625LL;
116 } else {
117 /* 0.5 mV * 25 uV = 0.0125 uV resolution. */
118 val = (val * 25LL) >> 1;
119 }
120 break;
121 case LTC2945_VIN_H:
122 case LTC2945_MAX_VIN_H:
123 case LTC2945_MIN_VIN_H:
124 case LTC2945_MAX_VIN_THRES_H:
125 case LTC2945_MIN_VIN_THRES_H:
126 /* 25 mV resolution. Convert to mV. */
127 val *= 25;
128 break;
129 case LTC2945_ADIN_H:
130 case LTC2945_MAX_ADIN_H:
131 case LTC2945_MIN_ADIN_THRES_H:
132 case LTC2945_MAX_ADIN_THRES_H:
133 case LTC2945_MIN_ADIN_H:
134 /* 0.5mV resolution. Convert to mV. */
135 val = val >> 1;
136 break;
137 case LTC2945_SENSE_H:
138 case LTC2945_MAX_SENSE_H:
139 case LTC2945_MIN_SENSE_H:
140 case LTC2945_MAX_SENSE_THRES_H:
141 case LTC2945_MIN_SENSE_THRES_H:
142 /*
143 * 25 uV resolution. Convert to current as measured with
144 * an 1 mOhm sense resistor, in mA. If a different sense
145 * resistor is installed, calculate the actual current by
146 * dividing the reported current by the sense resistor value
147 * in mOhm.
148 */
149 val *= 25;
150 break;
151 default:
152 return -EINVAL;
153 }
154 return val;
155}
156
157static int ltc2945_val_to_reg(struct device *dev, u8 reg,
158 unsigned long val)
159{
160 struct regmap *regmap = dev_get_drvdata(dev);
161 unsigned int control;
162 int ret;
163
164 switch (reg) {
165 case LTC2945_POWER_H:
166 case LTC2945_MAX_POWER_H:
167 case LTC2945_MIN_POWER_H:
168 case LTC2945_MAX_POWER_THRES_H:
169 case LTC2945_MIN_POWER_THRES_H:
170 /*
171 * Convert to register value by assuming current is measured
172 * with an 1mOhm sense resistor, similar to current
173 * measurements.
174 * Control register bit 0 selects if voltage at SENSE+/VDD
175 * or voltage at ADIN is used to measure power, which in turn
176 * determines register calculations.
177 */
178 ret = regmap_read(regmap, LTC2945_CONTROL, &control);
179 if (ret < 0)
180 return ret;
181 if (control & CONTROL_MULT_SELECT) {
182 /* 25 mV * 25 uV = 0.625 uV resolution. */
183 val = DIV_ROUND_CLOSEST(val, 625);
184 } else {
185 /*
186 * 0.5 mV * 25 uV = 0.0125 uV resolution.
187 * Divide first to avoid overflow;
188 * accept loss of accuracy.
189 */
190 val = DIV_ROUND_CLOSEST(val, 25) * 2;
191 }
192 break;
193 case LTC2945_VIN_H:
194 case LTC2945_MAX_VIN_H:
195 case LTC2945_MIN_VIN_H:
196 case LTC2945_MAX_VIN_THRES_H:
197 case LTC2945_MIN_VIN_THRES_H:
198 /* 25 mV resolution. */
199 val /= 25;
200 break;
201 case LTC2945_ADIN_H:
202 case LTC2945_MAX_ADIN_H:
203 case LTC2945_MIN_ADIN_THRES_H:
204 case LTC2945_MAX_ADIN_THRES_H:
205 case LTC2945_MIN_ADIN_H:
206 /* 0.5mV resolution. */
207 val *= 2;
208 break;
209 case LTC2945_SENSE_H:
210 case LTC2945_MAX_SENSE_H:
211 case LTC2945_MIN_SENSE_H:
212 case LTC2945_MAX_SENSE_THRES_H:
213 case LTC2945_MIN_SENSE_THRES_H:
214 /*
215 * 25 uV resolution. Convert to current as measured with
216 * an 1 mOhm sense resistor, in mA. If a different sense
217 * resistor is installed, calculate the actual current by
218 * dividing the reported current by the sense resistor value
219 * in mOhm.
220 */
221 val = DIV_ROUND_CLOSEST(val, 25);
222 break;
223 default:
224 return -EINVAL;
225 }
226 return val;
227}
228
229static ssize_t ltc2945_show_value(struct device *dev,
230 struct device_attribute *da, char *buf)
231{
232 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
233 long long value;
234
235 value = ltc2945_reg_to_val(dev, attr->index);
236 if (value < 0)
237 return value;
238 return snprintf(buf, PAGE_SIZE, "%lld\n", value);
239}
240
241static ssize_t ltc2945_set_value(struct device *dev,
242 struct device_attribute *da,
243 const char *buf, size_t count)
244{
245 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
246 struct regmap *regmap = dev_get_drvdata(dev);
247 u8 reg = attr->index;
248 unsigned long val;
249 u8 regbuf[3];
250 int num_regs;
251 int regval;
252 int ret;
253
254 ret = kstrtoul(buf, 10, &val);
255 if (ret)
256 return ret;
257
258 /* convert to register value, then clamp and write result */
259 regval = ltc2945_val_to_reg(dev, reg, val);
260 if (is_power_reg(reg)) {
261 regval = clamp_val(regval, 0, 0xffffff);
262 regbuf[0] = regval >> 16;
263 regbuf[1] = (regval >> 8) & 0xff;
264 regbuf[2] = regval;
265 num_regs = 3;
266 } else {
267 regval = clamp_val(regval, 0, 0xfff) << 4;
268 regbuf[0] = regval >> 8;
269 regbuf[1] = regval & 0xff;
270 num_regs = 2;
271 }
272 ret = regmap_bulk_write(regmap, reg, regbuf, num_regs);
273 return ret < 0 ? ret : count;
274}
275
276static ssize_t ltc2945_reset_history(struct device *dev,
277 struct device_attribute *da,
278 const char *buf, size_t count)
279{
280 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
281 struct regmap *regmap = dev_get_drvdata(dev);
282 u8 reg = attr->index;
283 int num_regs = is_power_reg(reg) ? 3 : 2;
284 u8 buf_min[3] = { 0xff, 0xff, 0xff };
285 u8 buf_max[3] = { 0, 0, 0 };
286 unsigned long val;
287 int ret;
288
289 ret = kstrtoul(buf, 10, &val);
290 if (ret)
291 return ret;
292 if (val != 1)
293 return -EINVAL;
294
295 ret = regmap_update_bits(regmap, LTC2945_CONTROL, CONTROL_TEST_MODE,
296 CONTROL_TEST_MODE);
297
298 /* Reset minimum */
299 ret = regmap_bulk_write(regmap, reg, buf_min, num_regs);
300 if (ret)
301 return ret;
302
303 switch (reg) {
304 case LTC2945_MIN_POWER_H:
305 reg = LTC2945_MAX_POWER_H;
306 break;
307 case LTC2945_MIN_SENSE_H:
308 reg = LTC2945_MAX_SENSE_H;
309 break;
310 case LTC2945_MIN_VIN_H:
311 reg = LTC2945_MAX_VIN_H;
312 break;
313 case LTC2945_MIN_ADIN_H:
314 reg = LTC2945_MAX_ADIN_H;
315 break;
316 default:
317 BUG();
318 break;
319 }
320 /* Reset maximum */
321 ret = regmap_bulk_write(regmap, reg, buf_max, num_regs);
322
323 /* Try resetting test mode even if there was an error */
324 regmap_update_bits(regmap, LTC2945_CONTROL, CONTROL_TEST_MODE, 0);
325
326 return ret ? : count;
327}
328
329static ssize_t ltc2945_show_bool(struct device *dev,
330 struct device_attribute *da, char *buf)
331{
332 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
333 struct regmap *regmap = dev_get_drvdata(dev);
334 unsigned int fault;
335 int ret;
336
337 ret = regmap_read(regmap, LTC2945_FAULT, &fault);
338 if (ret < 0)
339 return ret;
340
341 fault &= attr->index;
342 if (fault) /* Clear reported faults in chip register */
343 regmap_update_bits(regmap, LTC2945_FAULT, attr->index, 0);
344
345 return snprintf(buf, PAGE_SIZE, "%d\n", !!fault);
346}
347
348/* Input voltages */
349
350static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, ltc2945_show_value, NULL,
351 LTC2945_VIN_H);
352static SENSOR_DEVICE_ATTR(in1_min, S_IRUGO | S_IWUSR, ltc2945_show_value,
353 ltc2945_set_value, LTC2945_MIN_VIN_THRES_H);
354static SENSOR_DEVICE_ATTR(in1_max, S_IRUGO | S_IWUSR, ltc2945_show_value,
355 ltc2945_set_value, LTC2945_MAX_VIN_THRES_H);
356static SENSOR_DEVICE_ATTR(in1_lowest, S_IRUGO, ltc2945_show_value, NULL,
357 LTC2945_MIN_VIN_H);
358static SENSOR_DEVICE_ATTR(in1_highest, S_IRUGO, ltc2945_show_value, NULL,
359 LTC2945_MAX_VIN_H);
360static SENSOR_DEVICE_ATTR(in1_reset_history, S_IWUSR, NULL,
361 ltc2945_reset_history, LTC2945_MIN_VIN_H);
362
363static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, ltc2945_show_value, NULL,
364 LTC2945_ADIN_H);
365static SENSOR_DEVICE_ATTR(in2_min, S_IRUGO | S_IWUSR, ltc2945_show_value,
366 ltc2945_set_value, LTC2945_MIN_ADIN_THRES_H);
367static SENSOR_DEVICE_ATTR(in2_max, S_IRUGO | S_IWUSR, ltc2945_show_value,
368 ltc2945_set_value, LTC2945_MAX_ADIN_THRES_H);
369static SENSOR_DEVICE_ATTR(in2_lowest, S_IRUGO, ltc2945_show_value, NULL,
370 LTC2945_MIN_ADIN_H);
371static SENSOR_DEVICE_ATTR(in2_highest, S_IRUGO, ltc2945_show_value, NULL,
372 LTC2945_MAX_ADIN_H);
373static SENSOR_DEVICE_ATTR(in2_reset_history, S_IWUSR, NULL,
374 ltc2945_reset_history, LTC2945_MIN_ADIN_H);
375
376/* Voltage alarms */
377
378static SENSOR_DEVICE_ATTR(in1_min_alarm, S_IRUGO, ltc2945_show_bool, NULL,
379 FAULT_VIN_UV);
380static SENSOR_DEVICE_ATTR(in1_max_alarm, S_IRUGO, ltc2945_show_bool, NULL,
381 FAULT_VIN_OV);
382static SENSOR_DEVICE_ATTR(in2_min_alarm, S_IRUGO, ltc2945_show_bool, NULL,
383 FAULT_ADIN_UV);
384static SENSOR_DEVICE_ATTR(in2_max_alarm, S_IRUGO, ltc2945_show_bool, NULL,
385 FAULT_ADIN_OV);
386
387/* Currents (via sense resistor) */
388
389static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, ltc2945_show_value, NULL,
390 LTC2945_SENSE_H);
391static SENSOR_DEVICE_ATTR(curr1_min, S_IRUGO | S_IWUSR, ltc2945_show_value,
392 ltc2945_set_value, LTC2945_MIN_SENSE_THRES_H);
393static SENSOR_DEVICE_ATTR(curr1_max, S_IRUGO | S_IWUSR, ltc2945_show_value,
394 ltc2945_set_value, LTC2945_MAX_SENSE_THRES_H);
395static SENSOR_DEVICE_ATTR(curr1_lowest, S_IRUGO, ltc2945_show_value, NULL,
396 LTC2945_MIN_SENSE_H);
397static SENSOR_DEVICE_ATTR(curr1_highest, S_IRUGO, ltc2945_show_value, NULL,
398 LTC2945_MAX_SENSE_H);
399static SENSOR_DEVICE_ATTR(curr1_reset_history, S_IWUSR, NULL,
400 ltc2945_reset_history, LTC2945_MIN_SENSE_H);
401
402/* Current alarms */
403
404static SENSOR_DEVICE_ATTR(curr1_min_alarm, S_IRUGO, ltc2945_show_bool, NULL,
405 FAULT_SENSE_UV);
406static SENSOR_DEVICE_ATTR(curr1_max_alarm, S_IRUGO, ltc2945_show_bool, NULL,
407 FAULT_SENSE_OV);
408
409/* Power */
410
411static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO, ltc2945_show_value, NULL,
412 LTC2945_POWER_H);
413static SENSOR_DEVICE_ATTR(power1_min, S_IRUGO | S_IWUSR, ltc2945_show_value,
414 ltc2945_set_value, LTC2945_MIN_POWER_THRES_H);
415static SENSOR_DEVICE_ATTR(power1_max, S_IRUGO | S_IWUSR, ltc2945_show_value,
416 ltc2945_set_value, LTC2945_MAX_POWER_THRES_H);
417static SENSOR_DEVICE_ATTR(power1_input_lowest, S_IRUGO, ltc2945_show_value,
418 NULL, LTC2945_MIN_POWER_H);
419static SENSOR_DEVICE_ATTR(power1_input_highest, S_IRUGO, ltc2945_show_value,
420 NULL, LTC2945_MAX_POWER_H);
421static SENSOR_DEVICE_ATTR(power1_reset_history, S_IWUSR, NULL,
422 ltc2945_reset_history, LTC2945_MIN_POWER_H);
423
424/* Power alarms */
425
426static SENSOR_DEVICE_ATTR(power1_min_alarm, S_IRUGO, ltc2945_show_bool, NULL,
427 FAULT_POWER_UV);
428static SENSOR_DEVICE_ATTR(power1_max_alarm, S_IRUGO, ltc2945_show_bool, NULL,
429 FAULT_POWER_OV);
430
431static struct attribute *ltc2945_attrs[] = {
432 &sensor_dev_attr_in1_input.dev_attr.attr,
433 &sensor_dev_attr_in1_min.dev_attr.attr,
434 &sensor_dev_attr_in1_max.dev_attr.attr,
435 &sensor_dev_attr_in1_lowest.dev_attr.attr,
436 &sensor_dev_attr_in1_highest.dev_attr.attr,
437 &sensor_dev_attr_in1_reset_history.dev_attr.attr,
438 &sensor_dev_attr_in1_min_alarm.dev_attr.attr,
439 &sensor_dev_attr_in1_max_alarm.dev_attr.attr,
440
441 &sensor_dev_attr_in2_input.dev_attr.attr,
442 &sensor_dev_attr_in2_min.dev_attr.attr,
443 &sensor_dev_attr_in2_max.dev_attr.attr,
444 &sensor_dev_attr_in2_lowest.dev_attr.attr,
445 &sensor_dev_attr_in2_highest.dev_attr.attr,
446 &sensor_dev_attr_in2_reset_history.dev_attr.attr,
447 &sensor_dev_attr_in2_min_alarm.dev_attr.attr,
448 &sensor_dev_attr_in2_max_alarm.dev_attr.attr,
449
450 &sensor_dev_attr_curr1_input.dev_attr.attr,
451 &sensor_dev_attr_curr1_min.dev_attr.attr,
452 &sensor_dev_attr_curr1_max.dev_attr.attr,
453 &sensor_dev_attr_curr1_lowest.dev_attr.attr,
454 &sensor_dev_attr_curr1_highest.dev_attr.attr,
455 &sensor_dev_attr_curr1_reset_history.dev_attr.attr,
456 &sensor_dev_attr_curr1_min_alarm.dev_attr.attr,
457 &sensor_dev_attr_curr1_max_alarm.dev_attr.attr,
458
459 &sensor_dev_attr_power1_input.dev_attr.attr,
460 &sensor_dev_attr_power1_min.dev_attr.attr,
461 &sensor_dev_attr_power1_max.dev_attr.attr,
462 &sensor_dev_attr_power1_input_lowest.dev_attr.attr,
463 &sensor_dev_attr_power1_input_highest.dev_attr.attr,
464 &sensor_dev_attr_power1_reset_history.dev_attr.attr,
465 &sensor_dev_attr_power1_min_alarm.dev_attr.attr,
466 &sensor_dev_attr_power1_max_alarm.dev_attr.attr,
467
468 NULL,
469};
470ATTRIBUTE_GROUPS(ltc2945);
471
472static struct regmap_config ltc2945_regmap_config = {
473 .reg_bits = 8,
474 .val_bits = 8,
475 .max_register = LTC2945_MIN_ADIN_THRES_L,
476};
477
478static int ltc2945_probe(struct i2c_client *client,
479 const struct i2c_device_id *id)
480{
481 struct device *dev = &client->dev;
482 struct device *hwmon_dev;
483 struct regmap *regmap;
484
485 regmap = devm_regmap_init_i2c(client, &ltc2945_regmap_config);
486 if (IS_ERR(regmap)) {
487 dev_err(dev, "failed to allocate register map\n");
488 return PTR_ERR(regmap);
489 }
490
491 /* Clear faults */
492 regmap_write(regmap, LTC2945_FAULT, 0x00);
493
494 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
495 regmap,
496 ltc2945_groups);
497 return PTR_ERR_OR_ZERO(hwmon_dev);
498}
499
500static const struct i2c_device_id ltc2945_id[] = {
501 {"ltc2945", 0},
502 { }
503};
504
505MODULE_DEVICE_TABLE(i2c, ltc2945_id);
506
507static struct i2c_driver ltc2945_driver = {
508 .driver = {
509 .name = "ltc2945",
510 },
511 .probe = ltc2945_probe,
512 .id_table = ltc2945_id,
513};
514
515module_i2c_driver(ltc2945_driver);
516
517MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");
518MODULE_DESCRIPTION("LTC2945 driver");
519MODULE_LICENSE("GPL");
diff --git a/drivers/hwmon/ltc4215.c b/drivers/hwmon/ltc4215.c
index 8a142960d69e..c8a9bd9b050f 100644
--- a/drivers/hwmon/ltc4215.c
+++ b/drivers/hwmon/ltc4215.c
@@ -33,7 +33,7 @@ enum ltc4215_cmd {
33}; 33};
34 34
35struct ltc4215_data { 35struct ltc4215_data {
36 struct device *hwmon_dev; 36 struct i2c_client *client;
37 37
38 struct mutex update_lock; 38 struct mutex update_lock;
39 bool valid; 39 bool valid;
@@ -45,8 +45,8 @@ struct ltc4215_data {
45 45
46static struct ltc4215_data *ltc4215_update_device(struct device *dev) 46static struct ltc4215_data *ltc4215_update_device(struct device *dev)
47{ 47{
48 struct i2c_client *client = to_i2c_client(dev); 48 struct ltc4215_data *data = dev_get_drvdata(dev);
49 struct ltc4215_data *data = i2c_get_clientdata(client); 49 struct i2c_client *client = data->client;
50 s32 val; 50 s32 val;
51 int i; 51 int i;
52 52
@@ -214,7 +214,7 @@ static SENSOR_DEVICE_ATTR(in2_min_alarm, S_IRUGO, ltc4215_show_alarm, NULL,
214 * Finally, construct an array of pointers to members of the above objects, 214 * Finally, construct an array of pointers to members of the above objects,
215 * as required for sysfs_create_group() 215 * as required for sysfs_create_group()
216 */ 216 */
217static struct attribute *ltc4215_attributes[] = { 217static struct attribute *ltc4215_attrs[] = {
218 &sensor_dev_attr_curr1_input.dev_attr.attr, 218 &sensor_dev_attr_curr1_input.dev_attr.attr,
219 &sensor_dev_attr_curr1_max_alarm.dev_attr.attr, 219 &sensor_dev_attr_curr1_max_alarm.dev_attr.attr,
220 220
@@ -229,57 +229,33 @@ static struct attribute *ltc4215_attributes[] = {
229 229
230 NULL, 230 NULL,
231}; 231};
232 232ATTRIBUTE_GROUPS(ltc4215);
233static const struct attribute_group ltc4215_group = {
234 .attrs = ltc4215_attributes,
235};
236 233
237static int ltc4215_probe(struct i2c_client *client, 234static int ltc4215_probe(struct i2c_client *client,
238 const struct i2c_device_id *id) 235 const struct i2c_device_id *id)
239{ 236{
240 struct i2c_adapter *adapter = client->adapter; 237 struct i2c_adapter *adapter = client->adapter;
238 struct device *dev = &client->dev;
241 struct ltc4215_data *data; 239 struct ltc4215_data *data;
242 int ret; 240 struct device *hwmon_dev;
243 241
244 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 242 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
245 return -ENODEV; 243 return -ENODEV;
246 244
247 data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); 245 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
248 if (!data) 246 if (!data)
249 return -ENOMEM; 247 return -ENOMEM;
250 248
251 i2c_set_clientdata(client, data); 249 data->client = client;
252 mutex_init(&data->update_lock); 250 mutex_init(&data->update_lock);
253 251
254 /* Initialize the LTC4215 chip */ 252 /* Initialize the LTC4215 chip */
255 i2c_smbus_write_byte_data(client, LTC4215_FAULT, 0x00); 253 i2c_smbus_write_byte_data(client, LTC4215_FAULT, 0x00);
256 254
257 /* Register sysfs hooks */ 255 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
258 ret = sysfs_create_group(&client->dev.kobj, &ltc4215_group); 256 data,
259 if (ret) 257 ltc4215_groups);
260 return ret; 258 return PTR_ERR_OR_ZERO(hwmon_dev);
261
262 data->hwmon_dev = hwmon_device_register(&client->dev);
263 if (IS_ERR(data->hwmon_dev)) {
264 ret = PTR_ERR(data->hwmon_dev);
265 goto out_hwmon_device_register;
266 }
267
268 return 0;
269
270out_hwmon_device_register:
271 sysfs_remove_group(&client->dev.kobj, &ltc4215_group);
272 return ret;
273}
274
275static int ltc4215_remove(struct i2c_client *client)
276{
277 struct ltc4215_data *data = i2c_get_clientdata(client);
278
279 hwmon_device_unregister(data->hwmon_dev);
280 sysfs_remove_group(&client->dev.kobj, &ltc4215_group);
281
282 return 0;
283} 259}
284 260
285static const struct i2c_device_id ltc4215_id[] = { 261static const struct i2c_device_id ltc4215_id[] = {
@@ -294,7 +270,6 @@ static struct i2c_driver ltc4215_driver = {
294 .name = "ltc4215", 270 .name = "ltc4215",
295 }, 271 },
296 .probe = ltc4215_probe, 272 .probe = ltc4215_probe,
297 .remove = ltc4215_remove,
298 .id_table = ltc4215_id, 273 .id_table = ltc4215_id,
299}; 274};
300 275
diff --git a/drivers/hwmon/ltc4222.c b/drivers/hwmon/ltc4222.c
new file mode 100644
index 000000000000..07c25653659f
--- /dev/null
+++ b/drivers/hwmon/ltc4222.c
@@ -0,0 +1,237 @@
1/*
2 * Driver for Linear Technology LTC4222 Dual Hot Swap controller
3 *
4 * Copyright (c) 2014 Guenter Roeck
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/err.h>
20#include <linux/slab.h>
21#include <linux/bitops.h>
22#include <linux/i2c.h>
23#include <linux/hwmon.h>
24#include <linux/hwmon-sysfs.h>
25#include <linux/jiffies.h>
26#include <linux/regmap.h>
27
28/* chip registers */
29
30#define LTC4222_CONTROL1 0xd0
31#define LTC4222_ALERT1 0xd1
32#define LTC4222_STATUS1 0xd2
33#define LTC4222_FAULT1 0xd3
34#define LTC4222_CONTROL2 0xd4
35#define LTC4222_ALERT2 0xd5
36#define LTC4222_STATUS2 0xd6
37#define LTC4222_FAULT2 0xd7
38#define LTC4222_SOURCE1 0xd8
39#define LTC4222_SOURCE2 0xda
40#define LTC4222_ADIN1 0xdc
41#define LTC4222_ADIN2 0xde
42#define LTC4222_SENSE1 0xe0
43#define LTC4222_SENSE2 0xe2
44#define LTC4222_ADC_CONTROL 0xe4
45
46/*
47 * Fault register bits
48 */
49#define FAULT_OV BIT(0)
50#define FAULT_UV BIT(1)
51#define FAULT_OC BIT(2)
52#define FAULT_POWER_BAD BIT(3)
53#define FAULT_FET_BAD BIT(5)
54
55/* Return the voltage from the given register in mV or mA */
56static int ltc4222_get_value(struct device *dev, u8 reg)
57{
58 struct regmap *regmap = dev_get_drvdata(dev);
59 unsigned int val;
60 u8 buf[2];
61 int ret;
62
63 ret = regmap_bulk_read(regmap, reg, buf, 2);
64 if (ret < 0)
65 return ret;
66
67 val = ((buf[0] << 8) + buf[1]) >> 6;
68
69 switch (reg) {
70 case LTC4222_ADIN1:
71 case LTC4222_ADIN2:
72 /* 1.25 mV resolution. Convert to mV. */
73 val = DIV_ROUND_CLOSEST(val * 5, 4);
74 break;
75 case LTC4222_SOURCE1:
76 case LTC4222_SOURCE2:
77 /* 31.25 mV resolution. Convert to mV. */
78 val = DIV_ROUND_CLOSEST(val * 125, 4);
79 break;
80 case LTC4222_SENSE1:
81 case LTC4222_SENSE2:
82 /*
83 * 62.5 uV resolution. Convert to current as measured with
84 * an 1 mOhm sense resistor, in mA. If a different sense
85 * resistor is installed, calculate the actual current by
86 * dividing the reported current by the sense resistor value
87 * in mOhm.
88 */
89 val = DIV_ROUND_CLOSEST(val * 125, 2);
90 break;
91 default:
92 return -EINVAL;
93 }
94 return val;
95}
96
97static ssize_t ltc4222_show_value(struct device *dev,
98 struct device_attribute *da, char *buf)
99{
100 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
101 int value;
102
103 value = ltc4222_get_value(dev, attr->index);
104 if (value < 0)
105 return value;
106 return snprintf(buf, PAGE_SIZE, "%d\n", value);
107}
108
109static ssize_t ltc4222_show_bool(struct device *dev,
110 struct device_attribute *da, char *buf)
111{
112 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(da);
113 struct regmap *regmap = dev_get_drvdata(dev);
114 unsigned int fault;
115 int ret;
116
117 ret = regmap_read(regmap, attr->nr, &fault);
118 if (ret < 0)
119 return ret;
120 fault &= attr->index;
121 if (fault) /* Clear reported faults in chip register */
122 regmap_update_bits(regmap, attr->nr, attr->index, 0);
123
124 return snprintf(buf, PAGE_SIZE, "%d\n", !!fault);
125}
126
127/* Voltages */
128static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, ltc4222_show_value, NULL,
129 LTC4222_SOURCE1);
130static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, ltc4222_show_value, NULL,
131 LTC4222_ADIN1);
132static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, ltc4222_show_value, NULL,
133 LTC4222_SOURCE2);
134static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, ltc4222_show_value, NULL,
135 LTC4222_ADIN2);
136
137/*
138 * Voltage alarms
139 * UV/OV faults are associated with the input voltage, and power bad and fet
140 * faults are associated with the output voltage.
141 */
142static SENSOR_DEVICE_ATTR_2(in1_min_alarm, S_IRUGO, ltc4222_show_bool, NULL,
143 LTC4222_FAULT1, FAULT_UV);
144static SENSOR_DEVICE_ATTR_2(in1_max_alarm, S_IRUGO, ltc4222_show_bool, NULL,
145 LTC4222_FAULT1, FAULT_OV);
146static SENSOR_DEVICE_ATTR_2(in2_alarm, S_IRUGO, ltc4222_show_bool, NULL,
147 LTC4222_FAULT1, FAULT_POWER_BAD | FAULT_FET_BAD);
148
149static SENSOR_DEVICE_ATTR_2(in3_min_alarm, S_IRUGO, ltc4222_show_bool, NULL,
150 LTC4222_FAULT2, FAULT_UV);
151static SENSOR_DEVICE_ATTR_2(in3_max_alarm, S_IRUGO, ltc4222_show_bool, NULL,
152 LTC4222_FAULT2, FAULT_OV);
153static SENSOR_DEVICE_ATTR_2(in4_alarm, S_IRUGO, ltc4222_show_bool, NULL,
154 LTC4222_FAULT2, FAULT_POWER_BAD | FAULT_FET_BAD);
155
156/* Current (via sense resistor) */
157static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, ltc4222_show_value, NULL,
158 LTC4222_SENSE1);
159static SENSOR_DEVICE_ATTR(curr2_input, S_IRUGO, ltc4222_show_value, NULL,
160 LTC4222_SENSE2);
161
162/* Overcurrent alarm */
163static SENSOR_DEVICE_ATTR_2(curr1_max_alarm, S_IRUGO, ltc4222_show_bool, NULL,
164 LTC4222_FAULT1, FAULT_OC);
165static SENSOR_DEVICE_ATTR_2(curr2_max_alarm, S_IRUGO, ltc4222_show_bool, NULL,
166 LTC4222_FAULT2, FAULT_OC);
167
168static struct attribute *ltc4222_attrs[] = {
169 &sensor_dev_attr_in1_input.dev_attr.attr,
170 &sensor_dev_attr_in1_min_alarm.dev_attr.attr,
171 &sensor_dev_attr_in1_max_alarm.dev_attr.attr,
172 &sensor_dev_attr_in2_input.dev_attr.attr,
173 &sensor_dev_attr_in2_alarm.dev_attr.attr,
174 &sensor_dev_attr_in3_input.dev_attr.attr,
175 &sensor_dev_attr_in3_min_alarm.dev_attr.attr,
176 &sensor_dev_attr_in3_max_alarm.dev_attr.attr,
177 &sensor_dev_attr_in4_input.dev_attr.attr,
178 &sensor_dev_attr_in4_alarm.dev_attr.attr,
179
180 &sensor_dev_attr_curr1_input.dev_attr.attr,
181 &sensor_dev_attr_curr1_max_alarm.dev_attr.attr,
182 &sensor_dev_attr_curr2_input.dev_attr.attr,
183 &sensor_dev_attr_curr2_max_alarm.dev_attr.attr,
184
185 NULL,
186};
187ATTRIBUTE_GROUPS(ltc4222);
188
189static struct regmap_config ltc4222_regmap_config = {
190 .reg_bits = 8,
191 .val_bits = 8,
192 .max_register = LTC4222_ADC_CONTROL,
193};
194
195static int ltc4222_probe(struct i2c_client *client,
196 const struct i2c_device_id *id)
197{
198 struct device *dev = &client->dev;
199 struct device *hwmon_dev;
200 struct regmap *regmap;
201
202 regmap = devm_regmap_init_i2c(client, &ltc4222_regmap_config);
203 if (IS_ERR(regmap)) {
204 dev_err(dev, "failed to allocate register map\n");
205 return PTR_ERR(regmap);
206 }
207
208 /* Clear faults */
209 regmap_write(regmap, LTC4222_FAULT1, 0x00);
210 regmap_write(regmap, LTC4222_FAULT2, 0x00);
211
212 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
213 regmap,
214 ltc4222_groups);
215 return PTR_ERR_OR_ZERO(hwmon_dev);
216}
217
218static const struct i2c_device_id ltc4222_id[] = {
219 {"ltc4222", 0},
220 { }
221};
222
223MODULE_DEVICE_TABLE(i2c, ltc4222_id);
224
225static struct i2c_driver ltc4222_driver = {
226 .driver = {
227 .name = "ltc4222",
228 },
229 .probe = ltc4222_probe,
230 .id_table = ltc4222_id,
231};
232
233module_i2c_driver(ltc4222_driver);
234
235MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");
236MODULE_DESCRIPTION("LTC4222 driver");
237MODULE_LICENSE("GPL");
diff --git a/drivers/hwmon/ltc4245.c b/drivers/hwmon/ltc4245.c
index d4172933ce4f..681b5b7b3c3b 100644
--- a/drivers/hwmon/ltc4245.c
+++ b/drivers/hwmon/ltc4245.c
@@ -95,7 +95,6 @@ static void ltc4245_update_gpios(struct device *dev)
95 * readings as stale by setting them to -EAGAIN 95 * readings as stale by setting them to -EAGAIN
96 */ 96 */
97 if (time_after(jiffies, data->last_updated + 5 * HZ)) { 97 if (time_after(jiffies, data->last_updated + 5 * HZ)) {
98 dev_dbg(&client->dev, "Marking GPIOs invalid\n");
99 for (i = 0; i < ARRAY_SIZE(data->gpios); i++) 98 for (i = 0; i < ARRAY_SIZE(data->gpios); i++)
100 data->gpios[i] = -EAGAIN; 99 data->gpios[i] = -EAGAIN;
101 } 100 }
@@ -141,8 +140,6 @@ static struct ltc4245_data *ltc4245_update_device(struct device *dev)
141 140
142 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { 141 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
143 142
144 dev_dbg(&client->dev, "Starting ltc4245 update\n");
145
146 /* Read control registers -- 0x00 to 0x07 */ 143 /* Read control registers -- 0x00 to 0x07 */
147 for (i = 0; i < ARRAY_SIZE(data->cregs); i++) { 144 for (i = 0; i < ARRAY_SIZE(data->cregs); i++) {
148 val = i2c_smbus_read_byte_data(client, i); 145 val = i2c_smbus_read_byte_data(client, i);
@@ -470,19 +467,15 @@ static void ltc4245_sysfs_add_groups(struct ltc4245_data *data)
470static bool ltc4245_use_extra_gpios(struct i2c_client *client) 467static bool ltc4245_use_extra_gpios(struct i2c_client *client)
471{ 468{
472 struct ltc4245_platform_data *pdata = dev_get_platdata(&client->dev); 469 struct ltc4245_platform_data *pdata = dev_get_platdata(&client->dev);
473#ifdef CONFIG_OF
474 struct device_node *np = client->dev.of_node; 470 struct device_node *np = client->dev.of_node;
475#endif
476 471
477 /* prefer platform data */ 472 /* prefer platform data */
478 if (pdata) 473 if (pdata)
479 return pdata->use_extra_gpios; 474 return pdata->use_extra_gpios;
480 475
481#ifdef CONFIG_OF
482 /* fallback on OF */ 476 /* fallback on OF */
483 if (of_find_property(np, "ltc4245,use-extra-gpios", NULL)) 477 if (of_find_property(np, "ltc4245,use-extra-gpios", NULL))
484 return true; 478 return true;
485#endif
486 479
487 return false; 480 return false;
488} 481}
@@ -512,24 +505,10 @@ static int ltc4245_probe(struct i2c_client *client,
512 /* Add sysfs hooks */ 505 /* Add sysfs hooks */
513 ltc4245_sysfs_add_groups(data); 506 ltc4245_sysfs_add_groups(data);
514 507
515 hwmon_dev = hwmon_device_register_with_groups(&client->dev, 508 hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev,
516 client->name, data, 509 client->name, data,
517 data->groups); 510 data->groups);
518 if (IS_ERR(hwmon_dev)) 511 return PTR_ERR_OR_ZERO(hwmon_dev);
519 return PTR_ERR(hwmon_dev);
520
521 i2c_set_clientdata(client, hwmon_dev);
522
523 return 0;
524}
525
526static int ltc4245_remove(struct i2c_client *client)
527{
528 struct device *hwmon_dev = i2c_get_clientdata(client);
529
530 hwmon_device_unregister(hwmon_dev);
531
532 return 0;
533} 512}
534 513
535static const struct i2c_device_id ltc4245_id[] = { 514static const struct i2c_device_id ltc4245_id[] = {
@@ -544,7 +523,6 @@ static struct i2c_driver ltc4245_driver = {
544 .name = "ltc4245", 523 .name = "ltc4245",
545 }, 524 },
546 .probe = ltc4245_probe, 525 .probe = ltc4245_probe,
547 .remove = ltc4245_remove,
548 .id_table = ltc4245_id, 526 .id_table = ltc4245_id,
549}; 527};
550 528
diff --git a/drivers/hwmon/ltc4260.c b/drivers/hwmon/ltc4260.c
new file mode 100644
index 000000000000..453a250d9df5
--- /dev/null
+++ b/drivers/hwmon/ltc4260.c
@@ -0,0 +1,200 @@
1/*
2 * Driver for Linear Technology LTC4260 I2C Positive Voltage Hot Swap Controller
3 *
4 * Copyright (c) 2014 Guenter Roeck
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/err.h>
20#include <linux/slab.h>
21#include <linux/i2c.h>
22#include <linux/hwmon.h>
23#include <linux/hwmon-sysfs.h>
24#include <linux/jiffies.h>
25#include <linux/regmap.h>
26
27/* chip registers */
28#define LTC4260_CONTROL 0x00
29#define LTC4260_ALERT 0x01
30#define LTC4260_STATUS 0x02
31#define LTC4260_FAULT 0x03
32#define LTC4260_SENSE 0x04
33#define LTC4260_SOURCE 0x05
34#define LTC4260_ADIN 0x06
35
36/*
37 * Fault register bits
38 */
39#define FAULT_OV (1 << 0)
40#define FAULT_UV (1 << 1)
41#define FAULT_OC (1 << 2)
42#define FAULT_POWER_BAD (1 << 3)
43#define FAULT_FET_SHORT (1 << 5)
44
45/* Return the voltage from the given register in mV or mA */
46static int ltc4260_get_value(struct device *dev, u8 reg)
47{
48 struct regmap *regmap = dev_get_drvdata(dev);
49 unsigned int val;
50 int ret;
51
52 ret = regmap_read(regmap, reg, &val);
53 if (ret < 0)
54 return ret;
55
56 switch (reg) {
57 case LTC4260_ADIN:
58 /* 10 mV resolution. Convert to mV. */
59 val = val * 10;
60 break;
61 case LTC4260_SOURCE:
62 /* 400 mV resolution. Convert to mV. */
63 val = val * 400;
64 break;
65 case LTC4260_SENSE:
66 /*
67 * 300 uV resolution. Convert to current as measured with
68 * an 1 mOhm sense resistor, in mA. If a different sense
69 * resistor is installed, calculate the actual current by
70 * dividing the reported current by the sense resistor value
71 * in mOhm.
72 */
73 val = val * 300;
74 break;
75 default:
76 return -EINVAL;
77 }
78
79 return val;
80}
81
82static ssize_t ltc4260_show_value(struct device *dev,
83 struct device_attribute *da, char *buf)
84{
85 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
86 int value;
87
88 value = ltc4260_get_value(dev, attr->index);
89 if (value < 0)
90 return value;
91 return snprintf(buf, PAGE_SIZE, "%d\n", value);
92}
93
94static ssize_t ltc4260_show_bool(struct device *dev,
95 struct device_attribute *da, char *buf)
96{
97 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
98 struct regmap *regmap = dev_get_drvdata(dev);
99 unsigned int fault;
100 int ret;
101
102 ret = regmap_read(regmap, LTC4260_FAULT, &fault);
103 if (ret < 0)
104 return ret;
105
106 fault &= attr->index;
107 if (fault) /* Clear reported faults in chip register */
108 regmap_update_bits(regmap, LTC4260_FAULT, attr->index, 0);
109
110 return snprintf(buf, PAGE_SIZE, "%d\n", !!fault);
111}
112
113/* Voltages */
114static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, ltc4260_show_value, NULL,
115 LTC4260_SOURCE);
116static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, ltc4260_show_value, NULL,
117 LTC4260_ADIN);
118
119/*
120 * Voltage alarms
121 * UV/OV faults are associated with the input voltage, and the POWER BAD and
122 * FET SHORT faults are associated with the output voltage.
123 */
124static SENSOR_DEVICE_ATTR(in1_min_alarm, S_IRUGO, ltc4260_show_bool, NULL,
125 FAULT_UV);
126static SENSOR_DEVICE_ATTR(in1_max_alarm, S_IRUGO, ltc4260_show_bool, NULL,
127 FAULT_OV);
128static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, ltc4260_show_bool, NULL,
129 FAULT_POWER_BAD | FAULT_FET_SHORT);
130
131/* Current (via sense resistor) */
132static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, ltc4260_show_value, NULL,
133 LTC4260_SENSE);
134
135/* Overcurrent alarm */
136static SENSOR_DEVICE_ATTR(curr1_max_alarm, S_IRUGO, ltc4260_show_bool, NULL,
137 FAULT_OC);
138
139static struct attribute *ltc4260_attrs[] = {
140 &sensor_dev_attr_in1_input.dev_attr.attr,
141 &sensor_dev_attr_in1_min_alarm.dev_attr.attr,
142 &sensor_dev_attr_in1_max_alarm.dev_attr.attr,
143 &sensor_dev_attr_in2_input.dev_attr.attr,
144 &sensor_dev_attr_in2_alarm.dev_attr.attr,
145
146 &sensor_dev_attr_curr1_input.dev_attr.attr,
147 &sensor_dev_attr_curr1_max_alarm.dev_attr.attr,
148
149 NULL,
150};
151ATTRIBUTE_GROUPS(ltc4260);
152
153static struct regmap_config ltc4260_regmap_config = {
154 .reg_bits = 8,
155 .val_bits = 8,
156 .max_register = LTC4260_ADIN,
157};
158
159static int ltc4260_probe(struct i2c_client *client,
160 const struct i2c_device_id *id)
161{
162 struct device *dev = &client->dev;
163 struct device *hwmon_dev;
164 struct regmap *regmap;
165
166 regmap = devm_regmap_init_i2c(client, &ltc4260_regmap_config);
167 if (IS_ERR(regmap)) {
168 dev_err(dev, "failed to allocate register map\n");
169 return PTR_ERR(regmap);
170 }
171
172 /* Clear faults */
173 regmap_write(regmap, LTC4260_FAULT, 0x00);
174
175 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
176 regmap,
177 ltc4260_groups);
178 return PTR_ERR_OR_ZERO(hwmon_dev);
179}
180
181static const struct i2c_device_id ltc4260_id[] = {
182 {"ltc4260", 0},
183 { }
184};
185
186MODULE_DEVICE_TABLE(i2c, ltc4260_id);
187
188static struct i2c_driver ltc4260_driver = {
189 .driver = {
190 .name = "ltc4260",
191 },
192 .probe = ltc4260_probe,
193 .id_table = ltc4260_id,
194};
195
196module_i2c_driver(ltc4260_driver);
197
198MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");
199MODULE_DESCRIPTION("LTC4260 driver");
200MODULE_LICENSE("GPL");
diff --git a/drivers/hwmon/max1668.c b/drivers/hwmon/max1668.c
index 029b65e6c589..e3ed0a5b6d94 100644
--- a/drivers/hwmon/max1668.c
+++ b/drivers/hwmon/max1668.c
@@ -66,7 +66,8 @@ MODULE_PARM_DESC(read_only, "Don't set any values, read only mode");
66enum chips { max1668, max1805, max1989 }; 66enum chips { max1668, max1805, max1989 };
67 67
68struct max1668_data { 68struct max1668_data {
69 struct device *hwmon_dev; 69 struct i2c_client *client;
70 const struct attribute_group *groups[3];
70 enum chips type; 71 enum chips type;
71 72
72 struct mutex update_lock; 73 struct mutex update_lock;
@@ -82,8 +83,8 @@ struct max1668_data {
82 83
83static struct max1668_data *max1668_update_device(struct device *dev) 84static struct max1668_data *max1668_update_device(struct device *dev)
84{ 85{
85 struct i2c_client *client = to_i2c_client(dev); 86 struct max1668_data *data = dev_get_drvdata(dev);
86 struct max1668_data *data = i2c_get_clientdata(client); 87 struct i2c_client *client = data->client;
87 struct max1668_data *ret = data; 88 struct max1668_data *ret = data;
88 s32 val; 89 s32 val;
89 int i; 90 int i;
@@ -205,8 +206,8 @@ static ssize_t set_temp_max(struct device *dev,
205 const char *buf, size_t count) 206 const char *buf, size_t count)
206{ 207{
207 int index = to_sensor_dev_attr(devattr)->index; 208 int index = to_sensor_dev_attr(devattr)->index;
208 struct i2c_client *client = to_i2c_client(dev); 209 struct max1668_data *data = dev_get_drvdata(dev);
209 struct max1668_data *data = i2c_get_clientdata(client); 210 struct i2c_client *client = data->client;
210 long temp; 211 long temp;
211 int ret; 212 int ret;
212 213
@@ -216,10 +217,11 @@ static ssize_t set_temp_max(struct device *dev,
216 217
217 mutex_lock(&data->update_lock); 218 mutex_lock(&data->update_lock);
218 data->temp_max[index] = clamp_val(temp/1000, -128, 127); 219 data->temp_max[index] = clamp_val(temp/1000, -128, 127);
219 if (i2c_smbus_write_byte_data(client, 220 ret = i2c_smbus_write_byte_data(client,
220 MAX1668_REG_LIMH_WR(index), 221 MAX1668_REG_LIMH_WR(index),
221 data->temp_max[index])) 222 data->temp_max[index]);
222 count = -EIO; 223 if (ret < 0)
224 count = ret;
223 mutex_unlock(&data->update_lock); 225 mutex_unlock(&data->update_lock);
224 226
225 return count; 227 return count;
@@ -230,8 +232,8 @@ static ssize_t set_temp_min(struct device *dev,
230 const char *buf, size_t count) 232 const char *buf, size_t count)
231{ 233{
232 int index = to_sensor_dev_attr(devattr)->index; 234 int index = to_sensor_dev_attr(devattr)->index;
233 struct i2c_client *client = to_i2c_client(dev); 235 struct max1668_data *data = dev_get_drvdata(dev);
234 struct max1668_data *data = i2c_get_clientdata(client); 236 struct i2c_client *client = data->client;
235 long temp; 237 long temp;
236 int ret; 238 int ret;
237 239
@@ -241,10 +243,11 @@ static ssize_t set_temp_min(struct device *dev,
241 243
242 mutex_lock(&data->update_lock); 244 mutex_lock(&data->update_lock);
243 data->temp_min[index] = clamp_val(temp/1000, -128, 127); 245 data->temp_min[index] = clamp_val(temp/1000, -128, 127);
244 if (i2c_smbus_write_byte_data(client, 246 ret = i2c_smbus_write_byte_data(client,
245 MAX1668_REG_LIML_WR(index), 247 MAX1668_REG_LIML_WR(index),
246 data->temp_min[index])) 248 data->temp_min[index]);
247 count = -EIO; 249 if (ret < 0)
250 count = ret;
248 mutex_unlock(&data->update_lock); 251 mutex_unlock(&data->update_lock);
249 252
250 return count; 253 return count;
@@ -405,60 +408,29 @@ static int max1668_probe(struct i2c_client *client,
405 const struct i2c_device_id *id) 408 const struct i2c_device_id *id)
406{ 409{
407 struct i2c_adapter *adapter = client->adapter; 410 struct i2c_adapter *adapter = client->adapter;
411 struct device *dev = &client->dev;
412 struct device *hwmon_dev;
408 struct max1668_data *data; 413 struct max1668_data *data;
409 int err;
410 414
411 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 415 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
412 return -ENODEV; 416 return -ENODEV;
413 417
414 data = devm_kzalloc(&client->dev, sizeof(struct max1668_data), 418 data = devm_kzalloc(dev, sizeof(struct max1668_data), GFP_KERNEL);
415 GFP_KERNEL);
416 if (!data) 419 if (!data)
417 return -ENOMEM; 420 return -ENOMEM;
418 421
419 i2c_set_clientdata(client, data); 422 data->client = client;
420 data->type = id->driver_data; 423 data->type = id->driver_data;
421 mutex_init(&data->update_lock); 424 mutex_init(&data->update_lock);
422 425
423 /* Register sysfs hooks */ 426 /* sysfs hooks */
424 err = sysfs_create_group(&client->dev.kobj, &max1668_group_common); 427 data->groups[0] = &max1668_group_common;
425 if (err)
426 return err;
427
428 if (data->type == max1668 || data->type == max1989) {
429 err = sysfs_create_group(&client->dev.kobj,
430 &max1668_group_unique);
431 if (err)
432 goto error_sysrem0;
433 }
434
435 data->hwmon_dev = hwmon_device_register(&client->dev);
436 if (IS_ERR(data->hwmon_dev)) {
437 err = PTR_ERR(data->hwmon_dev);
438 goto error_sysrem1;
439 }
440
441 return 0;
442
443error_sysrem1:
444 if (data->type == max1668 || data->type == max1989) 428 if (data->type == max1668 || data->type == max1989)
445 sysfs_remove_group(&client->dev.kobj, &max1668_group_unique); 429 data->groups[1] = &max1668_group_unique;
446error_sysrem0:
447 sysfs_remove_group(&client->dev.kobj, &max1668_group_common);
448 return err;
449}
450
451static int max1668_remove(struct i2c_client *client)
452{
453 struct max1668_data *data = i2c_get_clientdata(client);
454 430
455 hwmon_device_unregister(data->hwmon_dev); 431 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
456 if (data->type == max1668 || data->type == max1989) 432 data, data->groups);
457 sysfs_remove_group(&client->dev.kobj, &max1668_group_unique); 433 return PTR_ERR_OR_ZERO(hwmon_dev);
458
459 sysfs_remove_group(&client->dev.kobj, &max1668_group_common);
460
461 return 0;
462} 434}
463 435
464static const struct i2c_device_id max1668_id[] = { 436static const struct i2c_device_id max1668_id[] = {
@@ -476,7 +448,6 @@ static struct i2c_driver max1668_driver = {
476 .name = "max1668", 448 .name = "max1668",
477 }, 449 },
478 .probe = max1668_probe, 450 .probe = max1668_probe,
479 .remove = max1668_remove,
480 .id_table = max1668_id, 451 .id_table = max1668_id,
481 .detect = max1668_detect, 452 .detect = max1668_detect,
482 .address_list = max1668_addr_list, 453 .address_list = max1668_addr_list,
diff --git a/drivers/hwmon/max6639.c b/drivers/hwmon/max6639.c
index 066e587a18a5..70650de2cbd1 100644
--- a/drivers/hwmon/max6639.c
+++ b/drivers/hwmon/max6639.c
@@ -80,7 +80,7 @@ static const int rpm_ranges[] = { 2000, 4000, 8000, 16000 };
80 * Client data (each client gets its own) 80 * Client data (each client gets its own)
81 */ 81 */
82struct max6639_data { 82struct max6639_data {
83 struct device *hwmon_dev; 83 struct i2c_client *client;
84 struct mutex update_lock; 84 struct mutex update_lock;
85 char valid; /* !=0 if following fields are valid */ 85 char valid; /* !=0 if following fields are valid */
86 unsigned long last_updated; /* In jiffies */ 86 unsigned long last_updated; /* In jiffies */
@@ -104,8 +104,8 @@ struct max6639_data {
104 104
105static struct max6639_data *max6639_update_device(struct device *dev) 105static struct max6639_data *max6639_update_device(struct device *dev)
106{ 106{
107 struct i2c_client *client = to_i2c_client(dev); 107 struct max6639_data *data = dev_get_drvdata(dev);
108 struct max6639_data *data = i2c_get_clientdata(client); 108 struct i2c_client *client = data->client;
109 struct max6639_data *ret = data; 109 struct max6639_data *ret = data;
110 int i; 110 int i;
111 int status_reg; 111 int status_reg;
@@ -191,9 +191,8 @@ static ssize_t show_temp_fault(struct device *dev,
191static ssize_t show_temp_max(struct device *dev, 191static ssize_t show_temp_max(struct device *dev,
192 struct device_attribute *dev_attr, char *buf) 192 struct device_attribute *dev_attr, char *buf)
193{ 193{
194 struct i2c_client *client = to_i2c_client(dev);
195 struct max6639_data *data = i2c_get_clientdata(client);
196 struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); 194 struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
195 struct max6639_data *data = dev_get_drvdata(dev);
197 196
198 return sprintf(buf, "%d\n", (data->temp_therm[attr->index] * 1000)); 197 return sprintf(buf, "%d\n", (data->temp_therm[attr->index] * 1000));
199} 198}
@@ -202,9 +201,9 @@ static ssize_t set_temp_max(struct device *dev,
202 struct device_attribute *dev_attr, 201 struct device_attribute *dev_attr,
203 const char *buf, size_t count) 202 const char *buf, size_t count)
204{ 203{
205 struct i2c_client *client = to_i2c_client(dev);
206 struct max6639_data *data = i2c_get_clientdata(client);
207 struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); 204 struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
205 struct max6639_data *data = dev_get_drvdata(dev);
206 struct i2c_client *client = data->client;
208 unsigned long val; 207 unsigned long val;
209 int res; 208 int res;
210 209
@@ -224,9 +223,8 @@ static ssize_t set_temp_max(struct device *dev,
224static ssize_t show_temp_crit(struct device *dev, 223static ssize_t show_temp_crit(struct device *dev,
225 struct device_attribute *dev_attr, char *buf) 224 struct device_attribute *dev_attr, char *buf)
226{ 225{
227 struct i2c_client *client = to_i2c_client(dev);
228 struct max6639_data *data = i2c_get_clientdata(client);
229 struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); 226 struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
227 struct max6639_data *data = dev_get_drvdata(dev);
230 228
231 return sprintf(buf, "%d\n", (data->temp_alert[attr->index] * 1000)); 229 return sprintf(buf, "%d\n", (data->temp_alert[attr->index] * 1000));
232} 230}
@@ -235,9 +233,9 @@ static ssize_t set_temp_crit(struct device *dev,
235 struct device_attribute *dev_attr, 233 struct device_attribute *dev_attr,
236 const char *buf, size_t count) 234 const char *buf, size_t count)
237{ 235{
238 struct i2c_client *client = to_i2c_client(dev);
239 struct max6639_data *data = i2c_get_clientdata(client);
240 struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); 236 struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
237 struct max6639_data *data = dev_get_drvdata(dev);
238 struct i2c_client *client = data->client;
241 unsigned long val; 239 unsigned long val;
242 int res; 240 int res;
243 241
@@ -258,9 +256,8 @@ static ssize_t show_temp_emergency(struct device *dev,
258 struct device_attribute *dev_attr, 256 struct device_attribute *dev_attr,
259 char *buf) 257 char *buf)
260{ 258{
261 struct i2c_client *client = to_i2c_client(dev);
262 struct max6639_data *data = i2c_get_clientdata(client);
263 struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); 259 struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
260 struct max6639_data *data = dev_get_drvdata(dev);
264 261
265 return sprintf(buf, "%d\n", (data->temp_ot[attr->index] * 1000)); 262 return sprintf(buf, "%d\n", (data->temp_ot[attr->index] * 1000));
266} 263}
@@ -269,9 +266,9 @@ static ssize_t set_temp_emergency(struct device *dev,
269 struct device_attribute *dev_attr, 266 struct device_attribute *dev_attr,
270 const char *buf, size_t count) 267 const char *buf, size_t count)
271{ 268{
272 struct i2c_client *client = to_i2c_client(dev);
273 struct max6639_data *data = i2c_get_clientdata(client);
274 struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); 269 struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
270 struct max6639_data *data = dev_get_drvdata(dev);
271 struct i2c_client *client = data->client;
275 unsigned long val; 272 unsigned long val;
276 int res; 273 int res;
277 274
@@ -291,9 +288,8 @@ static ssize_t set_temp_emergency(struct device *dev,
291static ssize_t show_pwm(struct device *dev, 288static ssize_t show_pwm(struct device *dev,
292 struct device_attribute *dev_attr, char *buf) 289 struct device_attribute *dev_attr, char *buf)
293{ 290{
294 struct i2c_client *client = to_i2c_client(dev);
295 struct max6639_data *data = i2c_get_clientdata(client);
296 struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); 291 struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
292 struct max6639_data *data = dev_get_drvdata(dev);
297 293
298 return sprintf(buf, "%d\n", data->pwm[attr->index] * 255 / 120); 294 return sprintf(buf, "%d\n", data->pwm[attr->index] * 255 / 120);
299} 295}
@@ -302,9 +298,9 @@ static ssize_t set_pwm(struct device *dev,
302 struct device_attribute *dev_attr, 298 struct device_attribute *dev_attr,
303 const char *buf, size_t count) 299 const char *buf, size_t count)
304{ 300{
305 struct i2c_client *client = to_i2c_client(dev);
306 struct max6639_data *data = i2c_get_clientdata(client);
307 struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr); 301 struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
302 struct max6639_data *data = dev_get_drvdata(dev);
303 struct i2c_client *client = data->client;
308 unsigned long val; 304 unsigned long val;
309 int res; 305 int res;
310 306
@@ -378,7 +374,7 @@ static SENSOR_DEVICE_ATTR(temp1_emergency_alarm, S_IRUGO, show_alarm, NULL, 5);
378static SENSOR_DEVICE_ATTR(temp2_emergency_alarm, S_IRUGO, show_alarm, NULL, 4); 374static SENSOR_DEVICE_ATTR(temp2_emergency_alarm, S_IRUGO, show_alarm, NULL, 4);
379 375
380 376
381static struct attribute *max6639_attributes[] = { 377static struct attribute *max6639_attrs[] = {
382 &sensor_dev_attr_temp1_input.dev_attr.attr, 378 &sensor_dev_attr_temp1_input.dev_attr.attr,
383 &sensor_dev_attr_temp2_input.dev_attr.attr, 379 &sensor_dev_attr_temp2_input.dev_attr.attr,
384 &sensor_dev_attr_temp1_fault.dev_attr.attr, 380 &sensor_dev_attr_temp1_fault.dev_attr.attr,
@@ -403,10 +399,7 @@ static struct attribute *max6639_attributes[] = {
403 &sensor_dev_attr_temp2_emergency_alarm.dev_attr.attr, 399 &sensor_dev_attr_temp2_emergency_alarm.dev_attr.attr,
404 NULL 400 NULL
405}; 401};
406 402ATTRIBUTE_GROUPS(max6639);
407static const struct attribute_group max6639_group = {
408 .attrs = max6639_attributes,
409};
410 403
411/* 404/*
412 * returns respective index in rpm_ranges table 405 * returns respective index in rpm_ranges table
@@ -424,9 +417,9 @@ static int rpm_range_to_reg(int range)
424 return 1; /* default: 4000 RPM */ 417 return 1; /* default: 4000 RPM */
425} 418}
426 419
427static int max6639_init_client(struct i2c_client *client) 420static int max6639_init_client(struct i2c_client *client,
421 struct max6639_data *data)
428{ 422{
429 struct max6639_data *data = i2c_get_clientdata(client);
430 struct max6639_platform_data *max6639_info = 423 struct max6639_platform_data *max6639_info =
431 dev_get_platdata(&client->dev); 424 dev_get_platdata(&client->dev);
432 int i; 425 int i;
@@ -545,50 +538,27 @@ static int max6639_detect(struct i2c_client *client,
545static int max6639_probe(struct i2c_client *client, 538static int max6639_probe(struct i2c_client *client,
546 const struct i2c_device_id *id) 539 const struct i2c_device_id *id)
547{ 540{
541 struct device *dev = &client->dev;
548 struct max6639_data *data; 542 struct max6639_data *data;
543 struct device *hwmon_dev;
549 int err; 544 int err;
550 545
551 data = devm_kzalloc(&client->dev, sizeof(struct max6639_data), 546 data = devm_kzalloc(dev, sizeof(struct max6639_data), GFP_KERNEL);
552 GFP_KERNEL);
553 if (!data) 547 if (!data)
554 return -ENOMEM; 548 return -ENOMEM;
555 549
556 i2c_set_clientdata(client, data); 550 data->client = client;
557 mutex_init(&data->update_lock); 551 mutex_init(&data->update_lock);
558 552
559 /* Initialize the max6639 chip */ 553 /* Initialize the max6639 chip */
560 err = max6639_init_client(client); 554 err = max6639_init_client(client, data);
561 if (err < 0) 555 if (err < 0)
562 return err; 556 return err;
563 557
564 /* Register sysfs hooks */ 558 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
565 err = sysfs_create_group(&client->dev.kobj, &max6639_group); 559 data,
566 if (err) 560 max6639_groups);
567 return err; 561 return PTR_ERR_OR_ZERO(hwmon_dev);
568
569 data->hwmon_dev = hwmon_device_register(&client->dev);
570 if (IS_ERR(data->hwmon_dev)) {
571 err = PTR_ERR(data->hwmon_dev);
572 goto error_remove;
573 }
574
575 dev_info(&client->dev, "temperature sensor and fan control found\n");
576
577 return 0;
578
579error_remove:
580 sysfs_remove_group(&client->dev.kobj, &max6639_group);
581 return err;
582}
583
584static int max6639_remove(struct i2c_client *client)
585{
586 struct max6639_data *data = i2c_get_clientdata(client);
587
588 hwmon_device_unregister(data->hwmon_dev);
589 sysfs_remove_group(&client->dev.kobj, &max6639_group);
590
591 return 0;
592} 562}
593 563
594#ifdef CONFIG_PM_SLEEP 564#ifdef CONFIG_PM_SLEEP
@@ -622,9 +592,7 @@ static const struct i2c_device_id max6639_id[] = {
622 592
623MODULE_DEVICE_TABLE(i2c, max6639_id); 593MODULE_DEVICE_TABLE(i2c, max6639_id);
624 594
625static const struct dev_pm_ops max6639_pm_ops = { 595static SIMPLE_DEV_PM_OPS(max6639_pm_ops, max6639_suspend, max6639_resume);
626 SET_SYSTEM_SLEEP_PM_OPS(max6639_suspend, max6639_resume)
627};
628 596
629static struct i2c_driver max6639_driver = { 597static struct i2c_driver max6639_driver = {
630 .class = I2C_CLASS_HWMON, 598 .class = I2C_CLASS_HWMON,
@@ -633,7 +601,6 @@ static struct i2c_driver max6639_driver = {
633 .pm = &max6639_pm_ops, 601 .pm = &max6639_pm_ops,
634 }, 602 },
635 .probe = max6639_probe, 603 .probe = max6639_probe,
636 .remove = max6639_remove,
637 .id_table = max6639_id, 604 .id_table = max6639_id,
638 .detect = max6639_detect, 605 .detect = max6639_detect,
639 .address_list = normal_i2c, 606 .address_list = normal_i2c,
diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c
index 0cafc390db4d..162a520f4bd6 100644
--- a/drivers/hwmon/max6650.c
+++ b/drivers/hwmon/max6650.c
@@ -105,38 +105,13 @@ module_param(clock, int, S_IRUGO);
105 105
106#define DIV_FROM_REG(reg) (1 << (reg & 7)) 106#define DIV_FROM_REG(reg) (1 << (reg & 7))
107 107
108static int max6650_probe(struct i2c_client *client,
109 const struct i2c_device_id *id);
110static int max6650_init_client(struct i2c_client *client);
111static int max6650_remove(struct i2c_client *client);
112static struct max6650_data *max6650_update_device(struct device *dev);
113
114/*
115 * Driver data (common to all clients)
116 */
117
118static const struct i2c_device_id max6650_id[] = {
119 { "max6650", 1 },
120 { "max6651", 4 },
121 { }
122};
123MODULE_DEVICE_TABLE(i2c, max6650_id);
124
125static struct i2c_driver max6650_driver = {
126 .driver = {
127 .name = "max6650",
128 },
129 .probe = max6650_probe,
130 .remove = max6650_remove,
131 .id_table = max6650_id,
132};
133
134/* 108/*
135 * Client data (each client gets its own) 109 * Client data (each client gets its own)
136 */ 110 */
137 111
138struct max6650_data { 112struct max6650_data {
139 struct device *hwmon_dev; 113 struct i2c_client *client;
114 const struct attribute_group *groups[3];
140 struct mutex update_lock; 115 struct mutex update_lock;
141 int nr_fans; 116 int nr_fans;
142 char valid; /* zero until following fields are valid */ 117 char valid; /* zero until following fields are valid */
@@ -151,6 +126,51 @@ struct max6650_data {
151 u8 alarm; 126 u8 alarm;
152}; 127};
153 128
129static const u8 tach_reg[] = {
130 MAX6650_REG_TACH0,
131 MAX6650_REG_TACH1,
132 MAX6650_REG_TACH2,
133 MAX6650_REG_TACH3,
134};
135
136static struct max6650_data *max6650_update_device(struct device *dev)
137{
138 struct max6650_data *data = dev_get_drvdata(dev);
139 struct i2c_client *client = data->client;
140 int i;
141
142 mutex_lock(&data->update_lock);
143
144 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
145 data->speed = i2c_smbus_read_byte_data(client,
146 MAX6650_REG_SPEED);
147 data->config = i2c_smbus_read_byte_data(client,
148 MAX6650_REG_CONFIG);
149 for (i = 0; i < data->nr_fans; i++) {
150 data->tach[i] = i2c_smbus_read_byte_data(client,
151 tach_reg[i]);
152 }
153 data->count = i2c_smbus_read_byte_data(client,
154 MAX6650_REG_COUNT);
155 data->dac = i2c_smbus_read_byte_data(client, MAX6650_REG_DAC);
156
157 /*
158 * Alarms are cleared on read in case the condition that
159 * caused the alarm is removed. Keep the value latched here
160 * for providing the register through different alarm files.
161 */
162 data->alarm |= i2c_smbus_read_byte_data(client,
163 MAX6650_REG_ALARM);
164
165 data->last_updated = jiffies;
166 data->valid = 1;
167 }
168
169 mutex_unlock(&data->update_lock);
170
171 return data;
172}
173
154static ssize_t get_fan(struct device *dev, struct device_attribute *devattr, 174static ssize_t get_fan(struct device *dev, struct device_attribute *devattr,
155 char *buf) 175 char *buf)
156{ 176{
@@ -235,8 +255,8 @@ static ssize_t get_target(struct device *dev, struct device_attribute *devattr,
235static ssize_t set_target(struct device *dev, struct device_attribute *devattr, 255static ssize_t set_target(struct device *dev, struct device_attribute *devattr,
236 const char *buf, size_t count) 256 const char *buf, size_t count)
237{ 257{
238 struct i2c_client *client = to_i2c_client(dev); 258 struct max6650_data *data = dev_get_drvdata(dev);
239 struct max6650_data *data = i2c_get_clientdata(client); 259 struct i2c_client *client = data->client;
240 int kscale, ktach; 260 int kscale, ktach;
241 unsigned long rpm; 261 unsigned long rpm;
242 int err; 262 int err;
@@ -304,8 +324,8 @@ static ssize_t get_pwm(struct device *dev, struct device_attribute *devattr,
304static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, 324static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr,
305 const char *buf, size_t count) 325 const char *buf, size_t count)
306{ 326{
307 struct i2c_client *client = to_i2c_client(dev); 327 struct max6650_data *data = dev_get_drvdata(dev);
308 struct max6650_data *data = i2c_get_clientdata(client); 328 struct i2c_client *client = data->client;
309 unsigned long pwm; 329 unsigned long pwm;
310 int err; 330 int err;
311 331
@@ -350,8 +370,8 @@ static ssize_t get_enable(struct device *dev, struct device_attribute *devattr,
350static ssize_t set_enable(struct device *dev, struct device_attribute *devattr, 370static ssize_t set_enable(struct device *dev, struct device_attribute *devattr,
351 const char *buf, size_t count) 371 const char *buf, size_t count)
352{ 372{
353 struct i2c_client *client = to_i2c_client(dev); 373 struct max6650_data *data = dev_get_drvdata(dev);
354 struct max6650_data *data = i2c_get_clientdata(client); 374 struct i2c_client *client = data->client;
355 int max6650_modes[3] = {0, 3, 2}; 375 int max6650_modes[3] = {0, 3, 2};
356 unsigned long mode; 376 unsigned long mode;
357 int err; 377 int err;
@@ -400,8 +420,8 @@ static ssize_t get_div(struct device *dev, struct device_attribute *devattr,
400static ssize_t set_div(struct device *dev, struct device_attribute *devattr, 420static ssize_t set_div(struct device *dev, struct device_attribute *devattr,
401 const char *buf, size_t count) 421 const char *buf, size_t count)
402{ 422{
403 struct i2c_client *client = to_i2c_client(dev); 423 struct max6650_data *data = dev_get_drvdata(dev);
404 struct max6650_data *data = i2c_get_clientdata(client); 424 struct i2c_client *client = data->client;
405 unsigned long div; 425 unsigned long div;
406 int err; 426 int err;
407 427
@@ -446,7 +466,7 @@ static ssize_t get_alarm(struct device *dev, struct device_attribute *devattr,
446{ 466{
447 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 467 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
448 struct max6650_data *data = max6650_update_device(dev); 468 struct max6650_data *data = max6650_update_device(dev);
449 struct i2c_client *client = to_i2c_client(dev); 469 struct i2c_client *client = data->client;
450 int alarm = 0; 470 int alarm = 0;
451 471
452 if (data->alarm & attr->index) { 472 if (data->alarm & attr->index) {
@@ -484,7 +504,8 @@ static umode_t max6650_attrs_visible(struct kobject *kobj, struct attribute *a,
484 int n) 504 int n)
485{ 505{
486 struct device *dev = container_of(kobj, struct device, kobj); 506 struct device *dev = container_of(kobj, struct device, kobj);
487 struct i2c_client *client = to_i2c_client(dev); 507 struct max6650_data *data = dev_get_drvdata(dev);
508 struct i2c_client *client = data->client;
488 u8 alarm_en = i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM_EN); 509 u8 alarm_en = i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM_EN);
489 struct device_attribute *devattr; 510 struct device_attribute *devattr;
490 511
@@ -519,7 +540,7 @@ static struct attribute *max6650_attrs[] = {
519 NULL 540 NULL
520}; 541};
521 542
522static struct attribute_group max6650_attr_grp = { 543static const struct attribute_group max6650_group = {
523 .attrs = max6650_attrs, 544 .attrs = max6650_attrs,
524 .is_visible = max6650_attrs_visible, 545 .is_visible = max6650_attrs_visible,
525}; 546};
@@ -531,7 +552,7 @@ static struct attribute *max6651_attrs[] = {
531 NULL 552 NULL
532}; 553};
533 554
534static const struct attribute_group max6651_attr_grp = { 555static const struct attribute_group max6651_group = {
535 .attrs = max6651_attrs, 556 .attrs = max6651_attrs,
536}; 557};
537 558
@@ -539,74 +560,17 @@ static const struct attribute_group max6651_attr_grp = {
539 * Real code 560 * Real code
540 */ 561 */
541 562
542static int max6650_probe(struct i2c_client *client, 563static int max6650_init_client(struct max6650_data *data,
543 const struct i2c_device_id *id) 564 struct i2c_client *client)
544{
545 struct max6650_data *data;
546 int err;
547
548 data = devm_kzalloc(&client->dev, sizeof(struct max6650_data),
549 GFP_KERNEL);
550 if (!data) {
551 dev_err(&client->dev, "out of memory.\n");
552 return -ENOMEM;
553 }
554
555 i2c_set_clientdata(client, data);
556 mutex_init(&data->update_lock);
557 data->nr_fans = id->driver_data;
558
559 /*
560 * Initialize the max6650 chip
561 */
562 err = max6650_init_client(client);
563 if (err)
564 return err;
565
566 err = sysfs_create_group(&client->dev.kobj, &max6650_attr_grp);
567 if (err)
568 return err;
569 /* 3 additional fan inputs for the MAX6651 */
570 if (data->nr_fans == 4) {
571 err = sysfs_create_group(&client->dev.kobj, &max6651_attr_grp);
572 if (err)
573 goto err_remove;
574 }
575
576 data->hwmon_dev = hwmon_device_register(&client->dev);
577 if (!IS_ERR(data->hwmon_dev))
578 return 0;
579
580 err = PTR_ERR(data->hwmon_dev);
581 dev_err(&client->dev, "error registering hwmon device.\n");
582 if (data->nr_fans == 4)
583 sysfs_remove_group(&client->dev.kobj, &max6651_attr_grp);
584err_remove:
585 sysfs_remove_group(&client->dev.kobj, &max6650_attr_grp);
586 return err;
587}
588
589static int max6650_remove(struct i2c_client *client)
590{ 565{
591 struct max6650_data *data = i2c_get_clientdata(client); 566 struct device *dev = &client->dev;
592
593 hwmon_device_unregister(data->hwmon_dev);
594 if (data->nr_fans == 4)
595 sysfs_remove_group(&client->dev.kobj, &max6651_attr_grp);
596 sysfs_remove_group(&client->dev.kobj, &max6650_attr_grp);
597 return 0;
598}
599
600static int max6650_init_client(struct i2c_client *client)
601{
602 struct max6650_data *data = i2c_get_clientdata(client);
603 int config; 567 int config;
604 int err = -EIO; 568 int err = -EIO;
605 569
606 config = i2c_smbus_read_byte_data(client, MAX6650_REG_CONFIG); 570 config = i2c_smbus_read_byte_data(client, MAX6650_REG_CONFIG);
607 571
608 if (config < 0) { 572 if (config < 0) {
609 dev_err(&client->dev, "Error reading config, aborting.\n"); 573 dev_err(dev, "Error reading config, aborting.\n");
610 return err; 574 return err;
611 } 575 }
612 576
@@ -620,11 +584,11 @@ static int max6650_init_client(struct i2c_client *client)
620 config |= MAX6650_CFG_V12; 584 config |= MAX6650_CFG_V12;
621 break; 585 break;
622 default: 586 default:
623 dev_err(&client->dev, "illegal value for fan_voltage (%d)\n", 587 dev_err(dev, "illegal value for fan_voltage (%d)\n",
624 fan_voltage); 588 fan_voltage);
625 } 589 }
626 590
627 dev_info(&client->dev, "Fan voltage is set to %dV.\n", 591 dev_info(dev, "Fan voltage is set to %dV.\n",
628 (config & MAX6650_CFG_V12) ? 12 : 5); 592 (config & MAX6650_CFG_V12) ? 12 : 5);
629 593
630 switch (prescaler) { 594 switch (prescaler) {
@@ -650,11 +614,10 @@ static int max6650_init_client(struct i2c_client *client)
650 | MAX6650_CFG_PRESCALER_16; 614 | MAX6650_CFG_PRESCALER_16;
651 break; 615 break;
652 default: 616 default:
653 dev_err(&client->dev, "illegal value for prescaler (%d)\n", 617 dev_err(dev, "illegal value for prescaler (%d)\n", prescaler);
654 prescaler);
655 } 618 }
656 619
657 dev_info(&client->dev, "Prescaler is set to %d.\n", 620 dev_info(dev, "Prescaler is set to %d.\n",
658 1 << (config & MAX6650_CFG_PRESCALER_MASK)); 621 1 << (config & MAX6650_CFG_PRESCALER_MASK));
659 622
660 /* 623 /*
@@ -664,17 +627,17 @@ static int max6650_init_client(struct i2c_client *client)
664 */ 627 */
665 628
666 if ((config & MAX6650_CFG_MODE_MASK) == MAX6650_CFG_MODE_OFF) { 629 if ((config & MAX6650_CFG_MODE_MASK) == MAX6650_CFG_MODE_OFF) {
667 dev_dbg(&client->dev, "Change mode to open loop, full off.\n"); 630 dev_dbg(dev, "Change mode to open loop, full off.\n");
668 config = (config & ~MAX6650_CFG_MODE_MASK) 631 config = (config & ~MAX6650_CFG_MODE_MASK)
669 | MAX6650_CFG_MODE_OPEN_LOOP; 632 | MAX6650_CFG_MODE_OPEN_LOOP;
670 if (i2c_smbus_write_byte_data(client, MAX6650_REG_DAC, 255)) { 633 if (i2c_smbus_write_byte_data(client, MAX6650_REG_DAC, 255)) {
671 dev_err(&client->dev, "DAC write error, aborting.\n"); 634 dev_err(dev, "DAC write error, aborting.\n");
672 return err; 635 return err;
673 } 636 }
674 } 637 }
675 638
676 if (i2c_smbus_write_byte_data(client, MAX6650_REG_CONFIG, config)) { 639 if (i2c_smbus_write_byte_data(client, MAX6650_REG_CONFIG, config)) {
677 dev_err(&client->dev, "Config write error, aborting.\n"); 640 dev_err(dev, "Config write error, aborting.\n");
678 return err; 641 return err;
679 } 642 }
680 643
@@ -684,51 +647,55 @@ static int max6650_init_client(struct i2c_client *client)
684 return 0; 647 return 0;
685} 648}
686 649
687static const u8 tach_reg[] = { 650static int max6650_probe(struct i2c_client *client,
688 MAX6650_REG_TACH0, 651 const struct i2c_device_id *id)
689 MAX6650_REG_TACH1,
690 MAX6650_REG_TACH2,
691 MAX6650_REG_TACH3,
692};
693
694static struct max6650_data *max6650_update_device(struct device *dev)
695{ 652{
696 int i; 653 struct device *dev = &client->dev;
697 struct i2c_client *client = to_i2c_client(dev); 654 struct max6650_data *data;
698 struct max6650_data *data = i2c_get_clientdata(client); 655 struct device *hwmon_dev;
699 656 int err;
700 mutex_lock(&data->update_lock);
701 657
702 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { 658 data = devm_kzalloc(dev, sizeof(struct max6650_data), GFP_KERNEL);
703 data->speed = i2c_smbus_read_byte_data(client, 659 if (!data)
704 MAX6650_REG_SPEED); 660 return -ENOMEM;
705 data->config = i2c_smbus_read_byte_data(client,
706 MAX6650_REG_CONFIG);
707 for (i = 0; i < data->nr_fans; i++) {
708 data->tach[i] = i2c_smbus_read_byte_data(client,
709 tach_reg[i]);
710 }
711 data->count = i2c_smbus_read_byte_data(client,
712 MAX6650_REG_COUNT);
713 data->dac = i2c_smbus_read_byte_data(client, MAX6650_REG_DAC);
714 661
715 /* 662 data->client = client;
716 * Alarms are cleared on read in case the condition that 663 mutex_init(&data->update_lock);
717 * caused the alarm is removed. Keep the value latched here 664 data->nr_fans = id->driver_data;
718 * for providing the register through different alarm files.
719 */
720 data->alarm |= i2c_smbus_read_byte_data(client,
721 MAX6650_REG_ALARM);
722 665
723 data->last_updated = jiffies; 666 /*
724 data->valid = 1; 667 * Initialize the max6650 chip
725 } 668 */
669 err = max6650_init_client(data, client);
670 if (err)
671 return err;
726 672
727 mutex_unlock(&data->update_lock); 673 data->groups[0] = &max6650_group;
674 /* 3 additional fan inputs for the MAX6651 */
675 if (data->nr_fans == 4)
676 data->groups[1] = &max6651_group;
728 677
729 return data; 678 hwmon_dev = devm_hwmon_device_register_with_groups(dev,
679 client->name, data,
680 data->groups);
681 return PTR_ERR_OR_ZERO(hwmon_dev);
730} 682}
731 683
684static const struct i2c_device_id max6650_id[] = {
685 { "max6650", 1 },
686 { "max6651", 4 },
687 { }
688};
689MODULE_DEVICE_TABLE(i2c, max6650_id);
690
691static struct i2c_driver max6650_driver = {
692 .driver = {
693 .name = "max6650",
694 },
695 .probe = max6650_probe,
696 .id_table = max6650_id,
697};
698
732module_i2c_driver(max6650_driver); 699module_i2c_driver(max6650_driver);
733 700
734MODULE_AUTHOR("Hans J. Koch"); 701MODULE_AUTHOR("Hans J. Koch");
diff --git a/drivers/hwmon/pmbus/ltc2978.c b/drivers/hwmon/pmbus/ltc2978.c
index de3c152a1d9a..e24ed521051a 100644
--- a/drivers/hwmon/pmbus/ltc2978.c
+++ b/drivers/hwmon/pmbus/ltc2978.c
@@ -1,9 +1,9 @@
1/* 1/*
2 * Hardware monitoring driver for LTC2974, LTC2977, LTC2978, LTC3880, 2 * Hardware monitoring driver for LTC2974, LTC2977, LTC2978, LTC3880,
3 * and LTC3883 3 * LTC3883, and LTM4676
4 * 4 *
5 * Copyright (c) 2011 Ericsson AB. 5 * Copyright (c) 2011 Ericsson AB.
6 * Copyright (c) 2013 Guenter Roeck 6 * Copyright (c) 2013, 2014 Guenter Roeck
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
@@ -14,10 +14,6 @@
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */ 17 */
22 18
23#include <linux/kernel.h> 19#include <linux/kernel.h>
@@ -28,7 +24,7 @@
28#include <linux/i2c.h> 24#include <linux/i2c.h>
29#include "pmbus.h" 25#include "pmbus.h"
30 26
31enum chips { ltc2974, ltc2977, ltc2978, ltc3880, ltc3883 }; 27enum chips { ltc2974, ltc2977, ltc2978, ltc3880, ltc3883, ltm4676 };
32 28
33/* Common for all chips */ 29/* Common for all chips */
34#define LTC2978_MFR_VOUT_PEAK 0xdd 30#define LTC2978_MFR_VOUT_PEAK 0xdd
@@ -45,7 +41,7 @@ enum chips { ltc2974, ltc2977, ltc2978, ltc3880, ltc3883 };
45#define LTC2974_MFR_IOUT_PEAK 0xd7 41#define LTC2974_MFR_IOUT_PEAK 0xd7
46#define LTC2974_MFR_IOUT_MIN 0xd8 42#define LTC2974_MFR_IOUT_MIN 0xd8
47 43
48/* LTC3880 and LTC3883 */ 44/* LTC3880, LTC3883, and LTM4676 */
49#define LTC3880_MFR_IOUT_PEAK 0xd7 45#define LTC3880_MFR_IOUT_PEAK 0xd7
50#define LTC3880_MFR_CLEAR_PEAKS 0xe3 46#define LTC3880_MFR_CLEAR_PEAKS 0xe3
51#define LTC3880_MFR_TEMPERATURE2_PEAK 0xf4 47#define LTC3880_MFR_TEMPERATURE2_PEAK 0xf4
@@ -53,7 +49,8 @@ enum chips { ltc2974, ltc2977, ltc2978, ltc3880, ltc3883 };
53/* LTC3883 only */ 49/* LTC3883 only */
54#define LTC3883_MFR_IIN_PEAK 0xe1 50#define LTC3883_MFR_IIN_PEAK 0xe1
55 51
56#define LTC2974_ID 0x0212 52#define LTC2974_ID_REV1 0x0212
53#define LTC2974_ID_REV2 0x0213
57#define LTC2977_ID 0x0130 54#define LTC2977_ID 0x0130
58#define LTC2978_ID_REV1 0x0121 55#define LTC2978_ID_REV1 0x0121
59#define LTC2978_ID_REV2 0x0122 56#define LTC2978_ID_REV2 0x0122
@@ -62,6 +59,8 @@ enum chips { ltc2974, ltc2977, ltc2978, ltc3880, ltc3883 };
62#define LTC3880_ID_MASK 0xff00 59#define LTC3880_ID_MASK 0xff00
63#define LTC3883_ID 0x4300 60#define LTC3883_ID 0x4300
64#define LTC3883_ID_MASK 0xff00 61#define LTC3883_ID_MASK 0xff00
62#define LTM4676_ID 0x4480 /* datasheet claims 0x440X */
63#define LTM4676_ID_MASK 0xfff0
65 64
66#define LTC2974_NUM_PAGES 4 65#define LTC2974_NUM_PAGES 4
67#define LTC2978_NUM_PAGES 8 66#define LTC2978_NUM_PAGES 8
@@ -370,6 +369,7 @@ static const struct i2c_device_id ltc2978_id[] = {
370 {"ltc2978", ltc2978}, 369 {"ltc2978", ltc2978},
371 {"ltc3880", ltc3880}, 370 {"ltc3880", ltc3880},
372 {"ltc3883", ltc3883}, 371 {"ltc3883", ltc3883},
372 {"ltm4676", ltm4676},
373 {} 373 {}
374}; 374};
375MODULE_DEVICE_TABLE(i2c, ltc2978_id); 375MODULE_DEVICE_TABLE(i2c, ltc2978_id);
@@ -394,7 +394,7 @@ static int ltc2978_probe(struct i2c_client *client,
394 if (chip_id < 0) 394 if (chip_id < 0)
395 return chip_id; 395 return chip_id;
396 396
397 if (chip_id == LTC2974_ID) { 397 if (chip_id == LTC2974_ID_REV1 || chip_id == LTC2974_ID_REV2) {
398 data->id = ltc2974; 398 data->id = ltc2974;
399 } else if (chip_id == LTC2977_ID) { 399 } else if (chip_id == LTC2977_ID) {
400 data->id = ltc2977; 400 data->id = ltc2977;
@@ -405,6 +405,8 @@ static int ltc2978_probe(struct i2c_client *client,
405 data->id = ltc3880; 405 data->id = ltc3880;
406 } else if ((chip_id & LTC3883_ID_MASK) == LTC3883_ID) { 406 } else if ((chip_id & LTC3883_ID_MASK) == LTC3883_ID) {
407 data->id = ltc3883; 407 data->id = ltc3883;
408 } else if ((chip_id & LTM4676_ID_MASK) == LTM4676_ID) {
409 data->id = ltm4676;
408 } else { 410 } else {
409 dev_err(&client->dev, "Unsupported chip ID 0x%x\n", chip_id); 411 dev_err(&client->dev, "Unsupported chip ID 0x%x\n", chip_id);
410 return -ENODEV; 412 return -ENODEV;
@@ -458,6 +460,7 @@ static int ltc2978_probe(struct i2c_client *client,
458 } 460 }
459 break; 461 break;
460 case ltc3880: 462 case ltc3880:
463 case ltm4676:
461 info->read_word_data = ltc3880_read_word_data; 464 info->read_word_data = ltc3880_read_word_data;
462 info->pages = LTC3880_NUM_PAGES; 465 info->pages = LTC3880_NUM_PAGES;
463 info->func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_IIN 466 info->func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_IIN
@@ -500,5 +503,5 @@ static struct i2c_driver ltc2978_driver = {
500module_i2c_driver(ltc2978_driver); 503module_i2c_driver(ltc2978_driver);
501 504
502MODULE_AUTHOR("Guenter Roeck"); 505MODULE_AUTHOR("Guenter Roeck");
503MODULE_DESCRIPTION("PMBus driver for LTC2974, LTC2978, LTC3880, and LTC3883"); 506MODULE_DESCRIPTION("PMBus driver for LTC2974, LTC2978, LTC3880, LTC3883, and LTM4676");
504MODULE_LICENSE("GPL"); 507MODULE_LICENSE("GPL");
diff --git a/drivers/hwmon/smm665.c b/drivers/hwmon/smm665.c
index d9e1b7de78da..4ef5802df6d8 100644
--- a/drivers/hwmon/smm665.c
+++ b/drivers/hwmon/smm665.c
@@ -222,7 +222,7 @@ static int smm665_read_adc(struct smm665_data *data, int adc)
222 rv = i2c_smbus_read_word_swapped(client, 0); 222 rv = i2c_smbus_read_word_swapped(client, 0);
223 if (rv < 0) { 223 if (rv < 0) {
224 dev_dbg(&client->dev, "Failed to read ADC value: error %d", rv); 224 dev_dbg(&client->dev, "Failed to read ADC value: error %d", rv);
225 return -1; 225 return rv;
226 } 226 }
227 /* 227 /*
228 * Validate/verify readback adc channel (in bit 11..14). 228 * Validate/verify readback adc channel (in bit 11..14).