diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-10-15 00:56:23 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-10-15 00:56:23 -0400 |
commit | 50fa86172bec2769979b5eb0cd1a244391ae4bb0 (patch) | |
tree | 5fd4949b031e1362af8b226d6372da2604de13ff | |
parent | 6b0490816671b2f4126a99998c9bf3c8c0472de2 (diff) | |
parent | 7881c64716f3a7d60b325ed0ad4d15f49b474a43 (diff) |
Merge tag 'for-v3.18' of git://git.infradead.org/battery-2.6
Pull power supply and reset updates from Sebastian Reichel:
- Initial support for the following chips
* max77836 (charger)
* max14577 (charger)
* bq27742 (battery gauge)
* ltc2952 (poweroff)
* stih416 (restart)
* syscon-reboot (restart)
* gpio-restart (restart)
- cleanup of power supply core
- misc fixes in power supply and reset drivers
* tag 'for-v3.18' of git://git.infradead.org/battery-2.6: (48 commits)
power: ab8500_fg: Fix build warning
Documentation: charger: max14577: Update the date of introducing ABI
power: reset: corrections for simple syscon reboot driver
Documentation: power: reset: Add documentation for generic SYSCON reboot driver
power: reset: Add generic SYSCON register mapped reset
bq27x00_battery: Fix flag reading for bq27742
power: reset: use restart_notifier mechanism for msm-poweroff
power: Add simple gpio-restart driver
power: reset: st: Provide DT bindings for ST's Power Reset driver
power: reset: Add restart functionality for STiH41x platforms
power: charger-manager: Fix NULL pointer exception with missing cm-fuel-gauge
power: max14577: Fix circular config SYSFS dependency
power: gpio-charger: do not use gpio value directly
power: max8925: Use of_get_child_by_name
power: max8925: Fix NULL ptr dereference on memory allocation failure
bq27x00_battery: Add support to bq27742
Documentation: charger: max14577: Document exported sysfs entry
devicetree: mfd: max14577: Add device tree bindings document
power: max17040: Add ID for MAX77836 Fuel Gauge block
charger: max14577: Configure battery-dependent settings from DTS and sysfs
...
Conflicts:
drivers/power/reset/Kconfig
drivers/power/reset/Makefile
33 files changed, 1919 insertions, 249 deletions
diff --git a/Documentation/ABI/testing/sysfs-class-power b/Documentation/ABI/testing/sysfs-class-power index 78c7baca3587..909e7602c717 100644 --- a/Documentation/ABI/testing/sysfs-class-power +++ b/Documentation/ABI/testing/sysfs-class-power | |||
@@ -18,3 +18,17 @@ Description: | |||
18 | This file is writeable and can be used to set the assumed | 18 | This file is writeable and can be used to set the assumed |
19 | battery 'full level'. As batteries age, this value has to be | 19 | battery 'full level'. As batteries age, this value has to be |
20 | amended over time. | 20 | amended over time. |
21 | |||
22 | What: /sys/class/power_supply/max14577-charger/device/fast_charge_timer | ||
23 | Date: October 2014 | ||
24 | KernelVersion: 3.18.0 | ||
25 | Contact: Krzysztof Kozlowski <k.kozlowski@samsung.com> | ||
26 | Description: | ||
27 | This entry shows and sets the maximum time the max14577 | ||
28 | charger operates in fast-charge mode. When the timer expires | ||
29 | the device will terminate fast-charge mode (charging current | ||
30 | will drop to 0 A) and will trigger interrupt. | ||
31 | |||
32 | Valid values: | ||
33 | - 5, 6 or 7 (hours), | ||
34 | - 0: disabled. | ||
diff --git a/Documentation/devicetree/bindings/gpio/gpio-restart.txt b/Documentation/devicetree/bindings/gpio/gpio-restart.txt new file mode 100644 index 000000000000..af3701bc15c4 --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/gpio-restart.txt | |||
@@ -0,0 +1,54 @@ | |||
1 | Drive a GPIO line that can be used to restart the system from a restart | ||
2 | handler. | ||
3 | |||
4 | This binding supports level and edge triggered reset. At driver load | ||
5 | time, the driver will request the given gpio line and install a restart | ||
6 | handler. If the optional properties 'open-source' is not found, the GPIO line | ||
7 | will be driven in the inactive state. Otherwise its not driven until | ||
8 | the restart is initiated. | ||
9 | |||
10 | When the system is restarted, the restart handler will be invoked in | ||
11 | priority order. The gpio is configured as an output, and driven active, | ||
12 | triggering a level triggered reset condition. This will also cause an | ||
13 | inactive->active edge condition, triggering positive edge triggered | ||
14 | reset. After a delay specified by active-delay, the GPIO is set to | ||
15 | inactive, thus causing an active->inactive edge, triggering negative edge | ||
16 | triggered reset. After a delay specified by inactive-delay, the GPIO | ||
17 | is driven active again. After a delay specified by wait-delay, the | ||
18 | restart handler completes allowing other restart handlers to be attempted. | ||
19 | |||
20 | Required properties: | ||
21 | - compatible : should be "gpio-restart". | ||
22 | - gpios : The GPIO to set high/low, see "gpios property" in | ||
23 | Documentation/devicetree/bindings/gpio/gpio.txt. If the pin should be | ||
24 | low to reset the board set it to "Active Low", otherwise set | ||
25 | gpio to "Active High". | ||
26 | |||
27 | Optional properties: | ||
28 | - open-source : Treat the GPIO as being open source and defer driving | ||
29 | it to when the restart is initiated. If this optional property is not | ||
30 | specified, the GPIO is initialized as an output in its inactive state. | ||
31 | - priority : A priority ranging from 0 to 255 (default 128) according to | ||
32 | the following guidelines: | ||
33 | 0: Restart handler of last resort, with limited restart | ||
34 | capabilities | ||
35 | 128: Default restart handler; use if no other restart handler is | ||
36 | expected to be available, and/or if restart functionality is | ||
37 | sufficient to restart the entire system | ||
38 | 255: Highest priority restart handler, will preempt all other | ||
39 | restart handlers | ||
40 | - active-delay: Delay (default 100) to wait after driving gpio active [ms] | ||
41 | - inactive-delay: Delay (default 100) to wait after driving gpio inactive [ms] | ||
42 | - wait-delay: Delay (default 3000) to wait after completing restart | ||
43 | sequence [ms] | ||
44 | |||
45 | Examples: | ||
46 | |||
47 | gpio-restart { | ||
48 | compatible = "gpio-restart"; | ||
49 | gpios = <&gpio 4 0>; | ||
50 | priority = <128>; | ||
51 | active-delay = <100>; | ||
52 | inactive-delay = <100>; | ||
53 | wait-delay = <3000>; | ||
54 | }; | ||
diff --git a/Documentation/devicetree/bindings/mfd/max14577.txt b/Documentation/devicetree/bindings/mfd/max14577.txt new file mode 100644 index 000000000000..236264c10b92 --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/max14577.txt | |||
@@ -0,0 +1,146 @@ | |||
1 | Maxim MAX14577/77836 Multi-Function Device | ||
2 | |||
3 | MAX14577 is a Multi-Function Device with Micro-USB Interface Circuit, Li+ | ||
4 | Battery Charger and SFOUT LDO output for powering USB devices. It is | ||
5 | interfaced to host controller using I2C. | ||
6 | |||
7 | MAX77836 additionally contains PMIC (with two LDO regulators) and Fuel Gauge. | ||
8 | |||
9 | |||
10 | Required properties: | ||
11 | - compatible : Must be "maxim,max14577" or "maxim,max77836". | ||
12 | - reg : I2C slave address for the max14577 chip (0x25 for max14577/max77836) | ||
13 | - interrupts : IRQ line for the chip. | ||
14 | - interrupt-parent : The parent interrupt controller. | ||
15 | |||
16 | |||
17 | Required nodes: | ||
18 | - charger : | ||
19 | Node for configuring the charger driver. | ||
20 | Required properties: | ||
21 | - compatible : "maxim,max14577-charger" | ||
22 | or "maxim,max77836-charger" | ||
23 | - maxim,fast-charge-uamp : Current in uA for Fast Charge; | ||
24 | Valid values: | ||
25 | - for max14577: 90000 - 950000; | ||
26 | - for max77836: 45000 - 475000; | ||
27 | - maxim,eoc-uamp : Current in uA for End-Of-Charge mode; | ||
28 | Valid values: | ||
29 | - for max14577: 50000 - 200000; | ||
30 | - for max77836: 5000 - 100000; | ||
31 | - maxim,ovp-uvolt : OverVoltage Protection Threshold in uV; | ||
32 | In an overvoltage condition, INT asserts and charging | ||
33 | stops. Valid values: | ||
34 | - 6000000, 6500000, 7000000, 7500000; | ||
35 | - maxim,constant-uvolt : Battery Constant Voltage in uV; | ||
36 | Valid values: | ||
37 | - 4000000 - 4280000 (step by 20000); | ||
38 | - 4350000; | ||
39 | |||
40 | |||
41 | Optional nodes: | ||
42 | - max14577-muic/max77836-muic : | ||
43 | Node used only by extcon consumers. | ||
44 | Required properties: | ||
45 | - compatible : "maxim,max14577-muic" or "maxim,max77836-muic" | ||
46 | |||
47 | - regulators : | ||
48 | Required properties: | ||
49 | - compatible : "maxim,max14577-regulator" | ||
50 | or "maxim,max77836-regulator" | ||
51 | |||
52 | May contain a sub-node per regulator from the list below. Each | ||
53 | sub-node should contain the constraints and initialization information | ||
54 | for that regulator. See regulator.txt for a description of standard | ||
55 | properties for these sub-nodes. | ||
56 | |||
57 | List of valid regulator names: | ||
58 | - for max14577: CHARGER, SAFEOUT. | ||
59 | - for max77836: CHARGER, SAFEOUT, LDO1, LDO2. | ||
60 | |||
61 | The SAFEOUT is a fixed voltage regulator so there is no need to specify | ||
62 | voltages for it. | ||
63 | |||
64 | |||
65 | Example: | ||
66 | |||
67 | #include <dt-bindings/interrupt-controller/irq.h> | ||
68 | |||
69 | max14577@25 { | ||
70 | compatible = "maxim,max14577"; | ||
71 | reg = <0x25>; | ||
72 | interrupt-parent = <&gpx1>; | ||
73 | interrupts = <5 IRQ_TYPE_NONE>; | ||
74 | |||
75 | muic: max14577-muic { | ||
76 | compatible = "maxim,max14577-muic"; | ||
77 | }; | ||
78 | |||
79 | regulators { | ||
80 | compatible = "maxim,max14577-regulator"; | ||
81 | |||
82 | SAFEOUT { | ||
83 | regulator-name = "SAFEOUT"; | ||
84 | }; | ||
85 | CHARGER { | ||
86 | regulator-name = "CHARGER"; | ||
87 | regulator-min-microamp = <90000>; | ||
88 | regulator-max-microamp = <950000>; | ||
89 | regulator-boot-on; | ||
90 | }; | ||
91 | }; | ||
92 | |||
93 | charger { | ||
94 | compatible = "maxim,max14577-charger"; | ||
95 | |||
96 | maxim,constant-uvolt = <4350000>; | ||
97 | maxim,fast-charge-uamp = <450000>; | ||
98 | maxim,eoc-uamp = <50000>; | ||
99 | maxim,ovp-uvolt = <6500000>; | ||
100 | }; | ||
101 | }; | ||
102 | |||
103 | |||
104 | max77836@25 { | ||
105 | compatible = "maxim,max77836"; | ||
106 | reg = <0x25>; | ||
107 | interrupt-parent = <&gpx1>; | ||
108 | interrupts = <5 IRQ_TYPE_NONE>; | ||
109 | |||
110 | muic: max77836-muic { | ||
111 | compatible = "maxim,max77836-muic"; | ||
112 | }; | ||
113 | |||
114 | regulators { | ||
115 | compatible = "maxim,max77836-regulator"; | ||
116 | |||
117 | SAFEOUT { | ||
118 | regulator-name = "SAFEOUT"; | ||
119 | }; | ||
120 | CHARGER { | ||
121 | regulator-name = "CHARGER"; | ||
122 | regulator-min-microamp = <90000>; | ||
123 | regulator-max-microamp = <950000>; | ||
124 | regulator-boot-on; | ||
125 | }; | ||
126 | LDO1 { | ||
127 | regulator-name = "LDO1"; | ||
128 | regulator-min-microvolt = <2700000>; | ||
129 | regulator-max-microvolt = <2700000>; | ||
130 | }; | ||
131 | LDO2 { | ||
132 | regulator-name = "LDO2"; | ||
133 | regulator-min-microvolt = <800000>; | ||
134 | regulator-max-microvolt = <3950000>; | ||
135 | }; | ||
136 | }; | ||
137 | |||
138 | charger { | ||
139 | compatible = "maxim,max77836-charger"; | ||
140 | |||
141 | maxim,constant-uvolt = <4350000>; | ||
142 | maxim,fast-charge-uamp = <225000>; | ||
143 | maxim,eoc-uamp = <7500>; | ||
144 | maxim,ovp-uvolt = <6500000>; | ||
145 | }; | ||
146 | }; | ||
diff --git a/Documentation/devicetree/bindings/power/reset/ltc2952-poweroff.txt b/Documentation/devicetree/bindings/power/reset/ltc2952-poweroff.txt new file mode 100644 index 000000000000..0c94c637f63b --- /dev/null +++ b/Documentation/devicetree/bindings/power/reset/ltc2952-poweroff.txt | |||
@@ -0,0 +1,26 @@ | |||
1 | Binding for the LTC2952 PowerPath controller | ||
2 | |||
3 | This chip is used to externally trigger a system shut down. Once the trigger has | ||
4 | been sent, the chips' watchdog has to be reset to gracefully shut down. | ||
5 | If the Linux systems decides to shut down it powers off the platform via the | ||
6 | kill signal. | ||
7 | |||
8 | Required properties: | ||
9 | |||
10 | - compatible: Must contain: "lltc,ltc2952" | ||
11 | - trigger-gpios: phandle + gpio-specifier for the GPIO connected to the | ||
12 | chip's trigger line | ||
13 | - watchdog-gpios: phandle + gpio-specifier for the GPIO connected to the | ||
14 | chip's watchdog line | ||
15 | - kill-gpios: phandle + gpio-specifier for the GPIO connected to the | ||
16 | chip's kill line | ||
17 | |||
18 | Example: | ||
19 | |||
20 | ltc2952 { | ||
21 | compatible = "lltc,ltc2952"; | ||
22 | |||
23 | trigger-gpios = <&gpio0 1 GPIO_ACTIVE_LOW>; | ||
24 | watchdog-gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>; | ||
25 | kill-gpios = <&gpio0 2 GPIO_ACTIVE_LOW>; | ||
26 | }; | ||
diff --git a/Documentation/devicetree/bindings/power/reset/st-reset.txt b/Documentation/devicetree/bindings/power/reset/st-reset.txt new file mode 100644 index 000000000000..809af54f02f3 --- /dev/null +++ b/Documentation/devicetree/bindings/power/reset/st-reset.txt | |||
@@ -0,0 +1,11 @@ | |||
1 | *Device-Tree bindings for ST SW reset functionality | ||
2 | |||
3 | Required properties: | ||
4 | - compatible: should be "st,<chip>-restart". | ||
5 | - st,syscfg: should be a phandle of the syscfg node. | ||
6 | |||
7 | Example node: | ||
8 | restart { | ||
9 | compatible = "st,stih416-restart"; | ||
10 | st,syscfg = <&syscfg_sbc>; | ||
11 | }; | ||
diff --git a/Documentation/devicetree/bindings/power/reset/syscon-reboot.txt b/Documentation/devicetree/bindings/power/reset/syscon-reboot.txt new file mode 100644 index 000000000000..11906316b43d --- /dev/null +++ b/Documentation/devicetree/bindings/power/reset/syscon-reboot.txt | |||
@@ -0,0 +1,23 @@ | |||
1 | Generic SYSCON mapped register reset driver | ||
2 | |||
3 | This is a generic reset driver using syscon to map the reset register. | ||
4 | The reset is generally performed with a write to the reset register | ||
5 | defined by the register map pointed by syscon reference plus the offset | ||
6 | with the mask defined in the reboot node. | ||
7 | |||
8 | Required properties: | ||
9 | - compatible: should contain "syscon-reboot" | ||
10 | - regmap: this is phandle to the register map node | ||
11 | - offset: offset in the register map for the reboot register (in bytes) | ||
12 | - mask: the reset value written to the reboot register (32 bit access) | ||
13 | |||
14 | Default will be little endian mode, 32 bit access only. | ||
15 | |||
16 | Examples: | ||
17 | |||
18 | reboot { | ||
19 | compatible = "syscon-reboot"; | ||
20 | regmap = <®mapnode>; | ||
21 | offset = <0x0>; | ||
22 | mask = <0x1>; | ||
23 | }; | ||
diff --git a/Documentation/power/charger-manager.txt b/Documentation/power/charger-manager.txt index b4f7f4b23f64..9ff1105e58d6 100644 --- a/Documentation/power/charger-manager.txt +++ b/Documentation/power/charger-manager.txt | |||
@@ -29,7 +29,7 @@ Charger Manager supports the following: | |||
29 | While the battery is being charged and the system is in suspend-to-RAM, | 29 | While the battery is being charged and the system is in suspend-to-RAM, |
30 | we may need to monitor the battery health by looking at the ambient or | 30 | we may need to monitor the battery health by looking at the ambient or |
31 | battery temperature. We can accomplish this by waking up the system | 31 | battery temperature. We can accomplish this by waking up the system |
32 | periodically. However, such a method wakes up devices unncessary for | 32 | periodically. However, such a method wakes up devices unnecessarily for |
33 | monitoring the battery health and tasks, and user processes that are | 33 | monitoring the battery health and tasks, and user processes that are |
34 | supposed to be kept suspended. That, in turn, incurs unnecessary power | 34 | supposed to be kept suspended. That, in turn, incurs unnecessary power |
35 | consumption and slow down charging process. Or even, such peak power | 35 | consumption and slow down charging process. Or even, such peak power |
diff --git a/Documentation/power/power_supply_class.txt b/Documentation/power/power_supply_class.txt index 48cff881cb8a..82dacc06e355 100644 --- a/Documentation/power/power_supply_class.txt +++ b/Documentation/power/power_supply_class.txt | |||
@@ -101,6 +101,10 @@ VOLTAGE_MAX, VOLTAGE_MIN - same as _DESIGN voltage values except that | |||
101 | these ones should be used if hardware could only guess (measure and | 101 | these ones should be used if hardware could only guess (measure and |
102 | retain) the thresholds of a given power supply. | 102 | retain) the thresholds of a given power supply. |
103 | 103 | ||
104 | VOLTAGE_BOOT - Reports the voltage measured during boot | ||
105 | |||
106 | CURRENT_BOOT - Reports the current measured during boot | ||
107 | |||
104 | CHARGE_FULL_DESIGN, CHARGE_EMPTY_DESIGN - design charge values, when | 108 | CHARGE_FULL_DESIGN, CHARGE_EMPTY_DESIGN - design charge values, when |
105 | battery considered full/empty. | 109 | battery considered full/empty. |
106 | 110 | ||
@@ -123,6 +127,8 @@ the current drawn from a charging source. | |||
123 | CHARGE_TERM_CURRENT - Charge termination current used to detect the end of charge | 127 | CHARGE_TERM_CURRENT - Charge termination current used to detect the end of charge |
124 | condition. | 128 | condition. |
125 | 129 | ||
130 | CALIBRATE - battery or coulomb counter calibration status | ||
131 | |||
126 | CONSTANT_CHARGE_VOLTAGE - constant charge voltage programmed by charger. | 132 | CONSTANT_CHARGE_VOLTAGE - constant charge voltage programmed by charger. |
127 | CONSTANT_CHARGE_VOLTAGE_MAX - maximum charge voltage supported by the | 133 | CONSTANT_CHARGE_VOLTAGE_MAX - maximum charge voltage supported by the |
128 | power supply object. | 134 | power supply object. |
diff --git a/drivers/mfd/max14577.c b/drivers/mfd/max14577.c index 4a5e885383f8..b8af263be594 100644 --- a/drivers/mfd/max14577.c +++ b/drivers/mfd/max14577.c | |||
@@ -26,6 +26,87 @@ | |||
26 | #include <linux/mfd/max14577.h> | 26 | #include <linux/mfd/max14577.h> |
27 | #include <linux/mfd/max14577-private.h> | 27 | #include <linux/mfd/max14577-private.h> |
28 | 28 | ||
29 | /* | ||
30 | * Table of valid charger currents for different Maxim chipsets. | ||
31 | * It is placed here because it is used by both charger and regulator driver. | ||
32 | */ | ||
33 | const struct maxim_charger_current maxim_charger_currents[] = { | ||
34 | [MAXIM_DEVICE_TYPE_UNKNOWN] = { 0, 0, 0, 0 }, | ||
35 | [MAXIM_DEVICE_TYPE_MAX14577] = { | ||
36 | .min = MAX14577_CHARGER_CURRENT_LIMIT_MIN, | ||
37 | .high_start = MAX14577_CHARGER_CURRENT_LIMIT_HIGH_START, | ||
38 | .high_step = MAX14577_CHARGER_CURRENT_LIMIT_HIGH_STEP, | ||
39 | .max = MAX14577_CHARGER_CURRENT_LIMIT_MAX, | ||
40 | }, | ||
41 | [MAXIM_DEVICE_TYPE_MAX77836] = { | ||
42 | .min = MAX77836_CHARGER_CURRENT_LIMIT_MIN, | ||
43 | .high_start = MAX77836_CHARGER_CURRENT_LIMIT_HIGH_START, | ||
44 | .high_step = MAX77836_CHARGER_CURRENT_LIMIT_HIGH_STEP, | ||
45 | .max = MAX77836_CHARGER_CURRENT_LIMIT_MAX, | ||
46 | }, | ||
47 | }; | ||
48 | EXPORT_SYMBOL_GPL(maxim_charger_currents); | ||
49 | |||
50 | /* | ||
51 | * maxim_charger_calc_reg_current - Calculate register value for current | ||
52 | * @limits: constraints for charger, matching the MBCICHWRC register | ||
53 | * @min_ua: minimal requested current, micro Amps | ||
54 | * @max_ua: maximum requested current, micro Amps | ||
55 | * @dst: destination to store calculated register value | ||
56 | * | ||
57 | * Calculates the value of MBCICHWRC (Fast Battery Charge Current) register | ||
58 | * for given current and stores it under pointed 'dst'. The stored value | ||
59 | * combines low bit (MBCICHWRCL) and high bits (MBCICHWRCH). It is also | ||
60 | * properly shifted. | ||
61 | * | ||
62 | * The calculated register value matches the current which: | ||
63 | * - is always between <limits.min, limits.max>; | ||
64 | * - is always less or equal to max_ua; | ||
65 | * - is the highest possible value; | ||
66 | * - may be lower than min_ua. | ||
67 | * | ||
68 | * On success returns 0. On error returns -EINVAL (requested min/max current | ||
69 | * is outside of given charger limits) and 'dst' is not set. | ||
70 | */ | ||
71 | int maxim_charger_calc_reg_current(const struct maxim_charger_current *limits, | ||
72 | unsigned int min_ua, unsigned int max_ua, u8 *dst) | ||
73 | { | ||
74 | unsigned int current_bits = 0xf; | ||
75 | |||
76 | if (min_ua > max_ua) | ||
77 | return -EINVAL; | ||
78 | |||
79 | if (min_ua > limits->max || max_ua < limits->min) | ||
80 | return -EINVAL; | ||
81 | |||
82 | if (max_ua < limits->high_start) { | ||
83 | /* | ||
84 | * Less than high_start, so set the minimal current | ||
85 | * (turn Low Bit off, 0 as high bits). | ||
86 | */ | ||
87 | *dst = 0x0; | ||
88 | return 0; | ||
89 | } | ||
90 | |||
91 | /* max_ua is in range: <high_start, infinite>, cut it to limits.max */ | ||
92 | max_ua = min(limits->max, max_ua); | ||
93 | max_ua -= limits->high_start; | ||
94 | /* | ||
95 | * There is no risk of overflow 'max_ua' here because: | ||
96 | * - max_ua >= limits.high_start | ||
97 | * - BUILD_BUG checks that 'limits' are: max >= high_start + high_step | ||
98 | */ | ||
99 | current_bits = max_ua / limits->high_step; | ||
100 | |||
101 | /* Turn Low Bit on (use range <limits.high_start, limits.max>) ... */ | ||
102 | *dst = 0x1 << CHGCTRL4_MBCICHWRCL_SHIFT; | ||
103 | /* and set proper High Bits */ | ||
104 | *dst |= current_bits << CHGCTRL4_MBCICHWRCH_SHIFT; | ||
105 | |||
106 | return 0; | ||
107 | } | ||
108 | EXPORT_SYMBOL_GPL(maxim_charger_calc_reg_current); | ||
109 | |||
29 | static const struct mfd_cell max14577_devs[] = { | 110 | static const struct mfd_cell max14577_devs[] = { |
30 | { | 111 | { |
31 | .name = "max14577-muic", | 112 | .name = "max14577-muic", |
@@ -35,7 +116,10 @@ static const struct mfd_cell max14577_devs[] = { | |||
35 | .name = "max14577-regulator", | 116 | .name = "max14577-regulator", |
36 | .of_compatible = "maxim,max14577-regulator", | 117 | .of_compatible = "maxim,max14577-regulator", |
37 | }, | 118 | }, |
38 | { .name = "max14577-charger", }, | 119 | { |
120 | .name = "max14577-charger", | ||
121 | .of_compatible = "maxim,max14577-charger", | ||
122 | }, | ||
39 | }; | 123 | }; |
40 | 124 | ||
41 | static const struct mfd_cell max77836_devs[] = { | 125 | static const struct mfd_cell max77836_devs[] = { |
@@ -463,6 +547,20 @@ static int __init max14577_i2c_init(void) | |||
463 | BUILD_BUG_ON(ARRAY_SIZE(max14577_i2c_id) != MAXIM_DEVICE_TYPE_NUM); | 547 | BUILD_BUG_ON(ARRAY_SIZE(max14577_i2c_id) != MAXIM_DEVICE_TYPE_NUM); |
464 | BUILD_BUG_ON(ARRAY_SIZE(max14577_dt_match) != MAXIM_DEVICE_TYPE_NUM); | 548 | BUILD_BUG_ON(ARRAY_SIZE(max14577_dt_match) != MAXIM_DEVICE_TYPE_NUM); |
465 | 549 | ||
550 | /* Valid charger current values must be provided for each chipset */ | ||
551 | BUILD_BUG_ON(ARRAY_SIZE(maxim_charger_currents) != MAXIM_DEVICE_TYPE_NUM); | ||
552 | |||
553 | /* Check for valid values for charger */ | ||
554 | BUILD_BUG_ON(MAX14577_CHARGER_CURRENT_LIMIT_HIGH_START + | ||
555 | MAX14577_CHARGER_CURRENT_LIMIT_HIGH_STEP * 0xf != | ||
556 | MAX14577_CHARGER_CURRENT_LIMIT_MAX); | ||
557 | BUILD_BUG_ON(MAX14577_CHARGER_CURRENT_LIMIT_HIGH_STEP == 0); | ||
558 | |||
559 | BUILD_BUG_ON(MAX77836_CHARGER_CURRENT_LIMIT_HIGH_START + | ||
560 | MAX77836_CHARGER_CURRENT_LIMIT_HIGH_STEP * 0xf != | ||
561 | MAX77836_CHARGER_CURRENT_LIMIT_MAX); | ||
562 | BUILD_BUG_ON(MAX77836_CHARGER_CURRENT_LIMIT_HIGH_STEP == 0); | ||
563 | |||
466 | return i2c_add_driver(&max14577_i2c_driver); | 564 | return i2c_add_driver(&max14577_i2c_driver); |
467 | } | 565 | } |
468 | subsys_initcall(max14577_i2c_init); | 566 | subsys_initcall(max14577_i2c_init); |
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 73cfcdf28a36..0108c2af005b 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig | |||
@@ -325,11 +325,12 @@ config CHARGER_MANAGER | |||
325 | with help of suspend_again support. | 325 | with help of suspend_again support. |
326 | 326 | ||
327 | config CHARGER_MAX14577 | 327 | config CHARGER_MAX14577 |
328 | tristate "Maxim MAX14577 MUIC battery charger driver" | 328 | tristate "Maxim MAX14577/77836 battery charger driver" |
329 | depends on MFD_MAX14577 | 329 | depends on MFD_MAX14577 |
330 | depends on SYSFS | ||
330 | help | 331 | help |
331 | Say Y to enable support for the battery charger control sysfs and | 332 | Say Y to enable support for the battery charger control sysfs and |
332 | platform data of MAX14577 MUICs. | 333 | platform data of MAX14577/77836 MUICs. |
333 | 334 | ||
334 | config CHARGER_MAX8997 | 335 | config CHARGER_MAX8997 |
335 | tristate "Maxim MAX8997/MAX8966 PMIC battery charger driver" | 336 | tristate "Maxim MAX8997/MAX8966 PMIC battery charger driver" |
diff --git a/drivers/power/ab8500_fg.c b/drivers/power/ab8500_fg.c index 3cb4178e397c..217da4b2ca86 100644 --- a/drivers/power/ab8500_fg.c +++ b/drivers/power/ab8500_fg.c | |||
@@ -2969,7 +2969,7 @@ static struct device_attribute ab8505_fg_sysfs_psy_attrs[] = { | |||
2969 | 2969 | ||
2970 | static int ab8500_fg_sysfs_psy_create_attrs(struct device *dev) | 2970 | static int ab8500_fg_sysfs_psy_create_attrs(struct device *dev) |
2971 | { | 2971 | { |
2972 | unsigned int i, j; | 2972 | unsigned int i; |
2973 | struct power_supply *psy = dev_get_drvdata(dev); | 2973 | struct power_supply *psy = dev_get_drvdata(dev); |
2974 | struct ab8500_fg *di; | 2974 | struct ab8500_fg *di; |
2975 | 2975 | ||
@@ -2978,14 +2978,15 @@ static int ab8500_fg_sysfs_psy_create_attrs(struct device *dev) | |||
2978 | if (((is_ab8505(di->parent) || is_ab9540(di->parent)) && | 2978 | if (((is_ab8505(di->parent) || is_ab9540(di->parent)) && |
2979 | abx500_get_chip_id(dev->parent) >= AB8500_CUT2P0) | 2979 | abx500_get_chip_id(dev->parent) >= AB8500_CUT2P0) |
2980 | || is_ab8540(di->parent)) { | 2980 | || is_ab8540(di->parent)) { |
2981 | for (j = 0; j < ARRAY_SIZE(ab8505_fg_sysfs_psy_attrs); j++) | 2981 | for (i = 0; i < ARRAY_SIZE(ab8505_fg_sysfs_psy_attrs); i++) |
2982 | if (device_create_file(dev, &ab8505_fg_sysfs_psy_attrs[j])) | 2982 | if (device_create_file(dev, |
2983 | &ab8505_fg_sysfs_psy_attrs[i])) | ||
2983 | goto sysfs_psy_create_attrs_failed_ab8505; | 2984 | goto sysfs_psy_create_attrs_failed_ab8505; |
2984 | } | 2985 | } |
2985 | return 0; | 2986 | return 0; |
2986 | sysfs_psy_create_attrs_failed_ab8505: | 2987 | sysfs_psy_create_attrs_failed_ab8505: |
2987 | dev_err(dev, "Failed creating sysfs psy attrs for ab8505.\n"); | 2988 | dev_err(dev, "Failed creating sysfs psy attrs for ab8505.\n"); |
2988 | while (j--) | 2989 | while (i--) |
2989 | device_remove_file(dev, &ab8505_fg_sysfs_psy_attrs[i]); | 2990 | device_remove_file(dev, &ab8505_fg_sysfs_psy_attrs[i]); |
2990 | 2991 | ||
2991 | return -EIO; | 2992 | return -EIO; |
diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c index e10763e3a1d5..e3bacfe3bcd0 100644 --- a/drivers/power/bq27x00_battery.c +++ b/drivers/power/bq27x00_battery.c | |||
@@ -23,6 +23,7 @@ | |||
23 | * http://focus.ti.com/docs/prod/folders/print/bq27000.html | 23 | * http://focus.ti.com/docs/prod/folders/print/bq27000.html |
24 | * http://focus.ti.com/docs/prod/folders/print/bq27500.html | 24 | * http://focus.ti.com/docs/prod/folders/print/bq27500.html |
25 | * http://www.ti.com/product/bq27425-g1 | 25 | * http://www.ti.com/product/bq27425-g1 |
26 | * http://www.ti.com/product/BQ27742-G1 | ||
26 | */ | 27 | */ |
27 | 28 | ||
28 | #include <linux/device.h> | 29 | #include <linux/device.h> |
@@ -71,6 +72,8 @@ | |||
71 | #define BQ27500_FLAG_FC BIT(9) | 72 | #define BQ27500_FLAG_FC BIT(9) |
72 | #define BQ27500_FLAG_OTC BIT(15) | 73 | #define BQ27500_FLAG_OTC BIT(15) |
73 | 74 | ||
75 | #define BQ27742_POWER_AVG 0x76 | ||
76 | |||
74 | /* bq27425 register addresses are same as bq27x00 addresses minus 4 */ | 77 | /* bq27425 register addresses are same as bq27x00 addresses minus 4 */ |
75 | #define BQ27425_REG_OFFSET 0x04 | 78 | #define BQ27425_REG_OFFSET 0x04 |
76 | #define BQ27425_REG_SOC 0x18 /* Register address plus offset */ | 79 | #define BQ27425_REG_SOC 0x18 /* Register address plus offset */ |
@@ -83,7 +86,7 @@ struct bq27x00_access_methods { | |||
83 | int (*read)(struct bq27x00_device_info *di, u8 reg, bool single); | 86 | int (*read)(struct bq27x00_device_info *di, u8 reg, bool single); |
84 | }; | 87 | }; |
85 | 88 | ||
86 | enum bq27x00_chip { BQ27000, BQ27500, BQ27425}; | 89 | enum bq27x00_chip { BQ27000, BQ27500, BQ27425, BQ27742}; |
87 | 90 | ||
88 | struct bq27x00_reg_cache { | 91 | struct bq27x00_reg_cache { |
89 | int temperature; | 92 | int temperature; |
@@ -152,6 +155,24 @@ static enum power_supply_property bq27425_battery_props[] = { | |||
152 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, | 155 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, |
153 | }; | 156 | }; |
154 | 157 | ||
158 | static enum power_supply_property bq27742_battery_props[] = { | ||
159 | POWER_SUPPLY_PROP_STATUS, | ||
160 | POWER_SUPPLY_PROP_PRESENT, | ||
161 | POWER_SUPPLY_PROP_VOLTAGE_NOW, | ||
162 | POWER_SUPPLY_PROP_CURRENT_NOW, | ||
163 | POWER_SUPPLY_PROP_CAPACITY, | ||
164 | POWER_SUPPLY_PROP_CAPACITY_LEVEL, | ||
165 | POWER_SUPPLY_PROP_TEMP, | ||
166 | POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, | ||
167 | POWER_SUPPLY_PROP_TECHNOLOGY, | ||
168 | POWER_SUPPLY_PROP_CHARGE_FULL, | ||
169 | POWER_SUPPLY_PROP_CHARGE_NOW, | ||
170 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, | ||
171 | POWER_SUPPLY_PROP_CYCLE_COUNT, | ||
172 | POWER_SUPPLY_PROP_POWER_AVG, | ||
173 | POWER_SUPPLY_PROP_HEALTH, | ||
174 | }; | ||
175 | |||
155 | static unsigned int poll_interval = 360; | 176 | static unsigned int poll_interval = 360; |
156 | module_param(poll_interval, uint, 0644); | 177 | module_param(poll_interval, uint, 0644); |
157 | MODULE_PARM_DESC(poll_interval, "battery poll interval in seconds - " \ | 178 | MODULE_PARM_DESC(poll_interval, "battery poll interval in seconds - " \ |
@@ -176,7 +197,7 @@ static inline int bq27x00_read(struct bq27x00_device_info *di, u8 reg, | |||
176 | */ | 197 | */ |
177 | static bool bq27xxx_is_chip_version_higher(struct bq27x00_device_info *di) | 198 | static bool bq27xxx_is_chip_version_higher(struct bq27x00_device_info *di) |
178 | { | 199 | { |
179 | if (di->chip == BQ27425 || di->chip == BQ27500) | 200 | if (di->chip == BQ27425 || di->chip == BQ27500 || di->chip == BQ27742) |
180 | return true; | 201 | return true; |
181 | return false; | 202 | return false; |
182 | } | 203 | } |
@@ -189,7 +210,7 @@ static int bq27x00_battery_read_rsoc(struct bq27x00_device_info *di) | |||
189 | { | 210 | { |
190 | int rsoc; | 211 | int rsoc; |
191 | 212 | ||
192 | if (di->chip == BQ27500) | 213 | if (di->chip == BQ27500 || di->chip == BQ27742) |
193 | rsoc = bq27x00_read(di, BQ27500_REG_SOC, false); | 214 | rsoc = bq27x00_read(di, BQ27500_REG_SOC, false); |
194 | else if (di->chip == BQ27425) | 215 | else if (di->chip == BQ27425) |
195 | rsoc = bq27x00_read(di, BQ27425_REG_SOC, false); | 216 | rsoc = bq27x00_read(di, BQ27425_REG_SOC, false); |
@@ -233,9 +254,11 @@ static inline int bq27x00_battery_read_nac(struct bq27x00_device_info *di) | |||
233 | { | 254 | { |
234 | int flags; | 255 | int flags; |
235 | bool is_bq27500 = di->chip == BQ27500; | 256 | bool is_bq27500 = di->chip == BQ27500; |
257 | bool is_bq27742 = di->chip == BQ27742; | ||
236 | bool is_higher = bq27xxx_is_chip_version_higher(di); | 258 | bool is_higher = bq27xxx_is_chip_version_higher(di); |
259 | bool flags_1b = !(is_bq27500 || is_bq27742); | ||
237 | 260 | ||
238 | flags = bq27x00_read(di, BQ27x00_REG_FLAGS, !is_bq27500); | 261 | flags = bq27x00_read(di, BQ27x00_REG_FLAGS, flags_1b); |
239 | if (flags >= 0 && !is_higher && (flags & BQ27000_FLAG_CI)) | 262 | if (flags >= 0 && !is_higher && (flags & BQ27000_FLAG_CI)) |
240 | return -ENODATA; | 263 | return -ENODATA; |
241 | 264 | ||
@@ -414,13 +437,15 @@ static void bq27x00_update(struct bq27x00_device_info *di) | |||
414 | struct bq27x00_reg_cache cache = {0, }; | 437 | struct bq27x00_reg_cache cache = {0, }; |
415 | bool is_bq27500 = di->chip == BQ27500; | 438 | bool is_bq27500 = di->chip == BQ27500; |
416 | bool is_bq27425 = di->chip == BQ27425; | 439 | bool is_bq27425 = di->chip == BQ27425; |
440 | bool is_bq27742 = di->chip == BQ27742; | ||
441 | bool flags_1b = !(is_bq27500 || is_bq27742); | ||
417 | 442 | ||
418 | cache.flags = bq27x00_read(di, BQ27x00_REG_FLAGS, !is_bq27500); | 443 | cache.flags = bq27x00_read(di, BQ27x00_REG_FLAGS, flags_1b); |
419 | if ((cache.flags & 0xff) == 0xff) | 444 | if ((cache.flags & 0xff) == 0xff) |
420 | /* read error */ | 445 | /* read error */ |
421 | cache.flags = -1; | 446 | cache.flags = -1; |
422 | if (cache.flags >= 0) { | 447 | if (cache.flags >= 0) { |
423 | if (!is_bq27500 && !is_bq27425 | 448 | if (!is_bq27500 && !is_bq27425 && !is_bq27742 |
424 | && (cache.flags & BQ27000_FLAG_CI)) { | 449 | && (cache.flags & BQ27000_FLAG_CI)) { |
425 | dev_info(di->dev, "battery is not calibrated! ignoring capacity values\n"); | 450 | dev_info(di->dev, "battery is not calibrated! ignoring capacity values\n"); |
426 | cache.capacity = -ENODATA; | 451 | cache.capacity = -ENODATA; |
@@ -432,7 +457,11 @@ static void bq27x00_update(struct bq27x00_device_info *di) | |||
432 | cache.health = -ENODATA; | 457 | cache.health = -ENODATA; |
433 | } else { | 458 | } else { |
434 | cache.capacity = bq27x00_battery_read_rsoc(di); | 459 | cache.capacity = bq27x00_battery_read_rsoc(di); |
435 | if (!is_bq27425) { | 460 | if (is_bq27742) |
461 | cache.time_to_empty = | ||
462 | bq27x00_battery_read_time(di, | ||
463 | BQ27x00_REG_TTE); | ||
464 | else if (!is_bq27425) { | ||
436 | cache.energy = bq27x00_battery_read_energy(di); | 465 | cache.energy = bq27x00_battery_read_energy(di); |
437 | cache.time_to_empty = | 466 | cache.time_to_empty = |
438 | bq27x00_battery_read_time(di, | 467 | bq27x00_battery_read_time(di, |
@@ -450,8 +479,14 @@ static void bq27x00_update(struct bq27x00_device_info *di) | |||
450 | cache.temperature = bq27x00_battery_read_temperature(di); | 479 | cache.temperature = bq27x00_battery_read_temperature(di); |
451 | if (!is_bq27425) | 480 | if (!is_bq27425) |
452 | cache.cycle_count = bq27x00_battery_read_cyct(di); | 481 | cache.cycle_count = bq27x00_battery_read_cyct(di); |
453 | cache.power_avg = | 482 | if (is_bq27742) |
454 | bq27x00_battery_read_pwr_avg(di, BQ27x00_POWER_AVG); | 483 | cache.power_avg = |
484 | bq27x00_battery_read_pwr_avg(di, | ||
485 | BQ27742_POWER_AVG); | ||
486 | else | ||
487 | cache.power_avg = | ||
488 | bq27x00_battery_read_pwr_avg(di, | ||
489 | BQ27x00_POWER_AVG); | ||
455 | 490 | ||
456 | /* We only have to read charge design full once */ | 491 | /* We only have to read charge design full once */ |
457 | if (di->charge_design_full <= 0) | 492 | if (di->charge_design_full <= 0) |
@@ -702,6 +737,9 @@ static int bq27x00_powersupply_init(struct bq27x00_device_info *di) | |||
702 | if (di->chip == BQ27425) { | 737 | if (di->chip == BQ27425) { |
703 | di->bat.properties = bq27425_battery_props; | 738 | di->bat.properties = bq27425_battery_props; |
704 | di->bat.num_properties = ARRAY_SIZE(bq27425_battery_props); | 739 | di->bat.num_properties = ARRAY_SIZE(bq27425_battery_props); |
740 | } else if (di->chip == BQ27742) { | ||
741 | di->bat.properties = bq27742_battery_props; | ||
742 | di->bat.num_properties = ARRAY_SIZE(bq27742_battery_props); | ||
705 | } else { | 743 | } else { |
706 | di->bat.properties = bq27x00_battery_props; | 744 | di->bat.properties = bq27x00_battery_props; |
707 | di->bat.num_properties = ARRAY_SIZE(bq27x00_battery_props); | 745 | di->bat.num_properties = ARRAY_SIZE(bq27x00_battery_props); |
@@ -858,6 +896,7 @@ static const struct i2c_device_id bq27x00_id[] = { | |||
858 | { "bq27200", BQ27000 }, /* bq27200 is same as bq27000, but with i2c */ | 896 | { "bq27200", BQ27000 }, /* bq27200 is same as bq27000, but with i2c */ |
859 | { "bq27500", BQ27500 }, | 897 | { "bq27500", BQ27500 }, |
860 | { "bq27425", BQ27425 }, | 898 | { "bq27425", BQ27425 }, |
899 | { "bq27742", BQ27742 }, | ||
861 | {}, | 900 | {}, |
862 | }; | 901 | }; |
863 | MODULE_DEVICE_TABLE(i2c, bq27x00_id); | 902 | MODULE_DEVICE_TABLE(i2c, bq27x00_id); |
diff --git a/drivers/power/charger-manager.c b/drivers/power/charger-manager.c index 9e4dab46eefd..7098a1ce2d3c 100644 --- a/drivers/power/charger-manager.c +++ b/drivers/power/charger-manager.c | |||
@@ -1656,7 +1656,7 @@ static inline struct charger_desc *cm_get_drv_data(struct platform_device *pdev) | |||
1656 | { | 1656 | { |
1657 | if (pdev->dev.of_node) | 1657 | if (pdev->dev.of_node) |
1658 | return of_cm_parse_desc(&pdev->dev); | 1658 | return of_cm_parse_desc(&pdev->dev); |
1659 | return (struct charger_desc *)dev_get_platdata(&pdev->dev); | 1659 | return dev_get_platdata(&pdev->dev); |
1660 | } | 1660 | } |
1661 | 1661 | ||
1662 | static int charger_manager_probe(struct platform_device *pdev) | 1662 | static int charger_manager_probe(struct platform_device *pdev) |
@@ -1677,7 +1677,7 @@ static int charger_manager_probe(struct platform_device *pdev) | |||
1677 | } | 1677 | } |
1678 | } | 1678 | } |
1679 | 1679 | ||
1680 | if (!desc) { | 1680 | if (IS_ERR(desc)) { |
1681 | dev_err(&pdev->dev, "No platform data (desc) found\n"); | 1681 | dev_err(&pdev->dev, "No platform data (desc) found\n"); |
1682 | return -ENODEV; | 1682 | return -ENODEV; |
1683 | } | 1683 | } |
@@ -1720,6 +1720,11 @@ static int charger_manager_probe(struct platform_device *pdev) | |||
1720 | return -EINVAL; | 1720 | return -EINVAL; |
1721 | } | 1721 | } |
1722 | 1722 | ||
1723 | if (!desc->psy_fuel_gauge) { | ||
1724 | dev_err(&pdev->dev, "No fuel gauge power supply defined\n"); | ||
1725 | return -EINVAL; | ||
1726 | } | ||
1727 | |||
1723 | /* Counting index only */ | 1728 | /* Counting index only */ |
1724 | while (desc->psy_charger_stat[i]) | 1729 | while (desc->psy_charger_stat[i]) |
1725 | i++; | 1730 | i++; |
@@ -1839,6 +1844,13 @@ static int charger_manager_probe(struct platform_device *pdev) | |||
1839 | device_init_wakeup(&pdev->dev, true); | 1844 | device_init_wakeup(&pdev->dev, true); |
1840 | device_set_wakeup_capable(&pdev->dev, false); | 1845 | device_set_wakeup_capable(&pdev->dev, false); |
1841 | 1846 | ||
1847 | /* | ||
1848 | * Charger-manager have to check the charging state right after | ||
1849 | * tialization of charger-manager and then update current charging | ||
1850 | * state. | ||
1851 | */ | ||
1852 | cm_monitor(); | ||
1853 | |||
1842 | schedule_work(&setup_polling); | 1854 | schedule_work(&setup_polling); |
1843 | 1855 | ||
1844 | return 0; | 1856 | return 0; |
diff --git a/drivers/power/gpio-charger.c b/drivers/power/gpio-charger.c index a0024b252197..7536933d0ab9 100644 --- a/drivers/power/gpio-charger.c +++ b/drivers/power/gpio-charger.c | |||
@@ -55,7 +55,7 @@ static int gpio_charger_get_property(struct power_supply *psy, | |||
55 | 55 | ||
56 | switch (psp) { | 56 | switch (psp) { |
57 | case POWER_SUPPLY_PROP_ONLINE: | 57 | case POWER_SUPPLY_PROP_ONLINE: |
58 | val->intval = gpio_get_value_cansleep(pdata->gpio); | 58 | val->intval = !!gpio_get_value_cansleep(pdata->gpio); |
59 | val->intval ^= pdata->gpio_active_low; | 59 | val->intval ^= pdata->gpio_active_low; |
60 | break; | 60 | break; |
61 | default: | 61 | default: |
diff --git a/drivers/power/max14577_charger.c b/drivers/power/max14577_charger.c index fad2a75b3604..0a2bc7277026 100644 --- a/drivers/power/max14577_charger.c +++ b/drivers/power/max14577_charger.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * Battery charger driver for the Maxim 14577 | 2 | * max14577_charger.c - Battery charger driver for the Maxim 14577/77836 |
3 | * | 3 | * |
4 | * Copyright (C) 2013 Samsung Electronics | 4 | * Copyright (C) 2013,2014 Samsung Electronics |
5 | * Krzysztof Kozlowski <k.kozlowski@samsung.com> | 5 | * Krzysztof Kozlowski <k.kozlowski@samsung.com> |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
@@ -19,16 +19,44 @@ | |||
19 | #include <linux/platform_device.h> | 19 | #include <linux/platform_device.h> |
20 | #include <linux/power_supply.h> | 20 | #include <linux/power_supply.h> |
21 | #include <linux/mfd/max14577-private.h> | 21 | #include <linux/mfd/max14577-private.h> |
22 | #include <linux/mfd/max14577.h> | ||
22 | 23 | ||
23 | struct max14577_charger { | 24 | struct max14577_charger { |
24 | struct device *dev; | 25 | struct device *dev; |
25 | struct max14577 *max14577; | 26 | struct max14577 *max14577; |
26 | struct power_supply charger; | 27 | struct power_supply charger; |
27 | 28 | ||
28 | unsigned int charging_state; | 29 | unsigned int charging_state; |
29 | unsigned int battery_state; | 30 | unsigned int battery_state; |
31 | |||
32 | struct max14577_charger_platform_data *pdata; | ||
30 | }; | 33 | }; |
31 | 34 | ||
35 | /* | ||
36 | * Helper function for mapping values of STATUS2/CHGTYP register on max14577 | ||
37 | * and max77836 chipsets to enum maxim_muic_charger_type. | ||
38 | */ | ||
39 | static enum max14577_muic_charger_type maxim_get_charger_type( | ||
40 | enum maxim_device_type dev_type, u8 val) { | ||
41 | switch (val) { | ||
42 | case MAX14577_CHARGER_TYPE_NONE: | ||
43 | case MAX14577_CHARGER_TYPE_USB: | ||
44 | case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT: | ||
45 | case MAX14577_CHARGER_TYPE_DEDICATED_CHG: | ||
46 | case MAX14577_CHARGER_TYPE_SPECIAL_500MA: | ||
47 | case MAX14577_CHARGER_TYPE_SPECIAL_1A: | ||
48 | return val; | ||
49 | case MAX14577_CHARGER_TYPE_DEAD_BATTERY: | ||
50 | case MAX14577_CHARGER_TYPE_RESERVED: | ||
51 | if (dev_type == MAXIM_DEVICE_TYPE_MAX77836) | ||
52 | val |= 0x8; | ||
53 | return val; | ||
54 | default: | ||
55 | WARN_ONCE(1, "max14577: Unsupported chgtyp register value 0x%02x", val); | ||
56 | return val; | ||
57 | } | ||
58 | } | ||
59 | |||
32 | static int max14577_get_charger_state(struct max14577_charger *chg) | 60 | static int max14577_get_charger_state(struct max14577_charger *chg) |
33 | { | 61 | { |
34 | struct regmap *rmap = chg->max14577->regmap; | 62 | struct regmap *rmap = chg->max14577->regmap; |
@@ -89,19 +117,23 @@ static int max14577_get_online(struct max14577_charger *chg) | |||
89 | { | 117 | { |
90 | struct regmap *rmap = chg->max14577->regmap; | 118 | struct regmap *rmap = chg->max14577->regmap; |
91 | u8 reg_data; | 119 | u8 reg_data; |
120 | enum max14577_muic_charger_type chg_type; | ||
92 | 121 | ||
93 | max14577_read_reg(rmap, MAX14577_MUIC_REG_STATUS2, ®_data); | 122 | max14577_read_reg(rmap, MAX14577_MUIC_REG_STATUS2, ®_data); |
94 | reg_data = ((reg_data & STATUS2_CHGTYP_MASK) >> STATUS2_CHGTYP_SHIFT); | 123 | reg_data = ((reg_data & STATUS2_CHGTYP_MASK) >> STATUS2_CHGTYP_SHIFT); |
95 | switch (reg_data) { | 124 | chg_type = maxim_get_charger_type(chg->max14577->dev_type, reg_data); |
125 | switch (chg_type) { | ||
96 | case MAX14577_CHARGER_TYPE_USB: | 126 | case MAX14577_CHARGER_TYPE_USB: |
97 | case MAX14577_CHARGER_TYPE_DEDICATED_CHG: | 127 | case MAX14577_CHARGER_TYPE_DEDICATED_CHG: |
98 | case MAX14577_CHARGER_TYPE_SPECIAL_500MA: | 128 | case MAX14577_CHARGER_TYPE_SPECIAL_500MA: |
99 | case MAX14577_CHARGER_TYPE_SPECIAL_1A: | 129 | case MAX14577_CHARGER_TYPE_SPECIAL_1A: |
100 | case MAX14577_CHARGER_TYPE_DEAD_BATTERY: | 130 | case MAX14577_CHARGER_TYPE_DEAD_BATTERY: |
131 | case MAX77836_CHARGER_TYPE_SPECIAL_BIAS: | ||
101 | return 1; | 132 | return 1; |
102 | case MAX14577_CHARGER_TYPE_NONE: | 133 | case MAX14577_CHARGER_TYPE_NONE: |
103 | case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT: | 134 | case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT: |
104 | case MAX14577_CHARGER_TYPE_RESERVED: | 135 | case MAX14577_CHARGER_TYPE_RESERVED: |
136 | case MAX77836_CHARGER_TYPE_RESERVED: | ||
105 | default: | 137 | default: |
106 | return 0; | 138 | return 0; |
107 | } | 139 | } |
@@ -118,10 +150,12 @@ static int max14577_get_battery_health(struct max14577_charger *chg) | |||
118 | struct regmap *rmap = chg->max14577->regmap; | 150 | struct regmap *rmap = chg->max14577->regmap; |
119 | int state = POWER_SUPPLY_HEALTH_GOOD; | 151 | int state = POWER_SUPPLY_HEALTH_GOOD; |
120 | u8 reg_data; | 152 | u8 reg_data; |
153 | enum max14577_muic_charger_type chg_type; | ||
121 | 154 | ||
122 | max14577_read_reg(rmap, MAX14577_MUIC_REG_STATUS2, ®_data); | 155 | max14577_read_reg(rmap, MAX14577_MUIC_REG_STATUS2, ®_data); |
123 | reg_data = ((reg_data & STATUS2_CHGTYP_MASK) >> STATUS2_CHGTYP_SHIFT); | 156 | reg_data = ((reg_data & STATUS2_CHGTYP_MASK) >> STATUS2_CHGTYP_SHIFT); |
124 | if (reg_data == MAX14577_CHARGER_TYPE_DEAD_BATTERY) { | 157 | chg_type = maxim_get_charger_type(chg->max14577->dev_type, reg_data); |
158 | if (chg_type == MAX14577_CHARGER_TYPE_DEAD_BATTERY) { | ||
125 | state = POWER_SUPPLY_HEALTH_DEAD; | 159 | state = POWER_SUPPLY_HEALTH_DEAD; |
126 | goto state_set; | 160 | goto state_set; |
127 | } | 161 | } |
@@ -147,15 +181,131 @@ static int max14577_get_present(struct max14577_charger *chg) | |||
147 | return 1; | 181 | return 1; |
148 | } | 182 | } |
149 | 183 | ||
184 | static int max14577_set_fast_charge_timer(struct max14577_charger *chg, | ||
185 | unsigned long hours) | ||
186 | { | ||
187 | u8 reg_data; | ||
188 | |||
189 | switch (hours) { | ||
190 | case 5 ... 7: | ||
191 | reg_data = hours - 3; | ||
192 | break; | ||
193 | case 0: | ||
194 | /* Disable */ | ||
195 | reg_data = 0x7; | ||
196 | break; | ||
197 | default: | ||
198 | dev_err(chg->dev, "Wrong value for Fast-Charge Timer: %lu\n", | ||
199 | hours); | ||
200 | return -EINVAL; | ||
201 | } | ||
202 | reg_data <<= CHGCTRL1_TCHW_SHIFT; | ||
203 | |||
204 | return max14577_update_reg(chg->max14577->regmap, | ||
205 | MAX14577_REG_CHGCTRL1, CHGCTRL1_TCHW_MASK, reg_data); | ||
206 | } | ||
207 | |||
208 | static int max14577_init_constant_voltage(struct max14577_charger *chg, | ||
209 | unsigned int uvolt) | ||
210 | { | ||
211 | u8 reg_data; | ||
212 | |||
213 | if (uvolt < MAXIM_CHARGER_CONSTANT_VOLTAGE_MIN || | ||
214 | uvolt > MAXIM_CHARGER_CONSTANT_VOLTAGE_MAX) | ||
215 | return -EINVAL; | ||
216 | |||
217 | if (uvolt == 4200000) | ||
218 | reg_data = 0x0; | ||
219 | else if (uvolt == MAXIM_CHARGER_CONSTANT_VOLTAGE_MAX) | ||
220 | reg_data = 0x1f; | ||
221 | else if (uvolt <= 4280000) { | ||
222 | unsigned int val = uvolt; | ||
223 | |||
224 | val -= MAXIM_CHARGER_CONSTANT_VOLTAGE_MIN; | ||
225 | val /= MAXIM_CHARGER_CONSTANT_VOLTAGE_STEP; | ||
226 | if (uvolt <= 4180000) | ||
227 | reg_data = 0x1 + val; | ||
228 | else | ||
229 | reg_data = val; /* Fix for gap between 4.18V and 4.22V */ | ||
230 | } else | ||
231 | return -EINVAL; | ||
232 | |||
233 | reg_data <<= CHGCTRL3_MBCCVWRC_SHIFT; | ||
234 | |||
235 | return max14577_write_reg(chg->max14577->regmap, | ||
236 | MAX14577_CHG_REG_CHG_CTRL3, reg_data); | ||
237 | } | ||
238 | |||
239 | static int max14577_init_eoc(struct max14577_charger *chg, | ||
240 | unsigned int uamp) | ||
241 | { | ||
242 | unsigned int current_bits = 0xf; | ||
243 | u8 reg_data; | ||
244 | |||
245 | switch (chg->max14577->dev_type) { | ||
246 | case MAXIM_DEVICE_TYPE_MAX77836: | ||
247 | if (uamp < 5000) | ||
248 | return -EINVAL; /* Requested current is too low */ | ||
249 | |||
250 | if (uamp >= 7500 && uamp < 10000) | ||
251 | current_bits = 0x0; | ||
252 | else if (uamp <= 50000) { | ||
253 | /* <5000, 7499> and <10000, 50000> */ | ||
254 | current_bits = uamp / 5000; | ||
255 | } else { | ||
256 | uamp = min(uamp, 100000U) - 50000U; | ||
257 | current_bits = 0xa + uamp / 10000; | ||
258 | } | ||
259 | break; | ||
260 | |||
261 | case MAXIM_DEVICE_TYPE_MAX14577: | ||
262 | default: | ||
263 | if (uamp < MAX14577_CHARGER_EOC_CURRENT_LIMIT_MIN) | ||
264 | return -EINVAL; /* Requested current is too low */ | ||
265 | |||
266 | uamp = min(uamp, MAX14577_CHARGER_EOC_CURRENT_LIMIT_MAX); | ||
267 | uamp -= MAX14577_CHARGER_EOC_CURRENT_LIMIT_MIN; | ||
268 | current_bits = uamp / MAX14577_CHARGER_EOC_CURRENT_LIMIT_STEP; | ||
269 | break; | ||
270 | } | ||
271 | |||
272 | reg_data = current_bits << CHGCTRL5_EOCS_SHIFT; | ||
273 | |||
274 | return max14577_update_reg(chg->max14577->regmap, | ||
275 | MAX14577_CHG_REG_CHG_CTRL5, CHGCTRL5_EOCS_MASK, | ||
276 | reg_data); | ||
277 | } | ||
278 | |||
279 | static int max14577_init_fast_charge(struct max14577_charger *chg, | ||
280 | unsigned int uamp) | ||
281 | { | ||
282 | u8 reg_data; | ||
283 | int ret; | ||
284 | const struct maxim_charger_current *limits = | ||
285 | &maxim_charger_currents[chg->max14577->dev_type]; | ||
286 | |||
287 | ret = maxim_charger_calc_reg_current(limits, uamp, uamp, ®_data); | ||
288 | if (ret) { | ||
289 | dev_err(chg->dev, "Wrong value for fast charge: %u\n", uamp); | ||
290 | return ret; | ||
291 | } | ||
292 | |||
293 | return max14577_update_reg(chg->max14577->regmap, | ||
294 | MAX14577_CHG_REG_CHG_CTRL4, | ||
295 | CHGCTRL4_MBCICHWRCL_MASK | CHGCTRL4_MBCICHWRCH_MASK, | ||
296 | reg_data); | ||
297 | } | ||
298 | |||
150 | /* | 299 | /* |
151 | * Sets charger registers to proper and safe default values. | 300 | * Sets charger registers to proper and safe default values. |
152 | * Some of these values are equal to defaults in MAX14577E | 301 | * Some of these values are equal to defaults in MAX14577E |
153 | * data sheet but there are minor differences. | 302 | * data sheet but there are minor differences. |
154 | */ | 303 | */ |
155 | static void max14577_charger_reg_init(struct max14577_charger *chg) | 304 | static int max14577_charger_reg_init(struct max14577_charger *chg) |
156 | { | 305 | { |
157 | struct regmap *rmap = chg->max14577->regmap; | 306 | struct regmap *rmap = chg->max14577->regmap; |
158 | u8 reg_data; | 307 | u8 reg_data; |
308 | int ret; | ||
159 | 309 | ||
160 | /* | 310 | /* |
161 | * Charger-Type Manual Detection, default off (set CHGTYPMAN to 0) | 311 | * Charger-Type Manual Detection, default off (set CHGTYPMAN to 0) |
@@ -167,10 +317,6 @@ static void max14577_charger_reg_init(struct max14577_charger *chg) | |||
167 | CDETCTRL1_CHGDETEN_MASK | CDETCTRL1_CHGTYPMAN_MASK, | 317 | CDETCTRL1_CHGDETEN_MASK | CDETCTRL1_CHGTYPMAN_MASK, |
168 | reg_data); | 318 | reg_data); |
169 | 319 | ||
170 | /* Battery Fast-Charge Timer, from SM-V700: 6hrs */ | ||
171 | reg_data = 0x3 << CHGCTRL1_TCHW_SHIFT; | ||
172 | max14577_write_reg(rmap, MAX14577_REG_CHGCTRL1, reg_data); | ||
173 | |||
174 | /* | 320 | /* |
175 | * Wall-Adapter Rapid Charge, default on | 321 | * Wall-Adapter Rapid Charge, default on |
176 | * Battery-Charger, default on | 322 | * Battery-Charger, default on |
@@ -179,29 +325,46 @@ static void max14577_charger_reg_init(struct max14577_charger *chg) | |||
179 | reg_data |= 0x1 << CHGCTRL2_MBCHOSTEN_SHIFT; | 325 | reg_data |= 0x1 << CHGCTRL2_MBCHOSTEN_SHIFT; |
180 | max14577_write_reg(rmap, MAX14577_REG_CHGCTRL2, reg_data); | 326 | max14577_write_reg(rmap, MAX14577_REG_CHGCTRL2, reg_data); |
181 | 327 | ||
182 | /* Battery-Charger Constant Voltage (CV) Mode, from SM-V700: 4.35V */ | ||
183 | reg_data = 0xf << CHGCTRL3_MBCCVWRC_SHIFT; | ||
184 | max14577_write_reg(rmap, MAX14577_REG_CHGCTRL3, reg_data); | ||
185 | |||
186 | /* | ||
187 | * Fast Battery-Charge Current Low, default 200-950mA | ||
188 | * Fast Battery-Charge Current High, from SM-V700: 450mA | ||
189 | */ | ||
190 | reg_data = 0x1 << CHGCTRL4_MBCICHWRCL_SHIFT; | ||
191 | reg_data |= 0x5 << CHGCTRL4_MBCICHWRCH_SHIFT; | ||
192 | max14577_write_reg(rmap, MAX14577_REG_CHGCTRL4, reg_data); | ||
193 | |||
194 | /* End-of-Charge Current, from SM-V700: 50mA */ | ||
195 | reg_data = 0x0 << CHGCTRL5_EOCS_SHIFT; | ||
196 | max14577_write_reg(rmap, MAX14577_REG_CHGCTRL5, reg_data); | ||
197 | |||
198 | /* Auto Charging Stop, default off */ | 328 | /* Auto Charging Stop, default off */ |
199 | reg_data = 0x0 << CHGCTRL6_AUTOSTOP_SHIFT; | 329 | reg_data = 0x0 << CHGCTRL6_AUTOSTOP_SHIFT; |
200 | max14577_write_reg(rmap, MAX14577_REG_CHGCTRL6, reg_data); | 330 | max14577_write_reg(rmap, MAX14577_REG_CHGCTRL6, reg_data); |
201 | 331 | ||
202 | /* Overvoltage-Protection Threshold, from SM-V700: 6.5V */ | 332 | ret = max14577_init_constant_voltage(chg, chg->pdata->constant_uvolt); |
203 | reg_data = 0x2 << CHGCTRL7_OTPCGHCVS_SHIFT; | 333 | if (ret) |
334 | return ret; | ||
335 | |||
336 | ret = max14577_init_eoc(chg, chg->pdata->eoc_uamp); | ||
337 | if (ret) | ||
338 | return ret; | ||
339 | |||
340 | ret = max14577_init_fast_charge(chg, chg->pdata->fast_charge_uamp); | ||
341 | if (ret) | ||
342 | return ret; | ||
343 | |||
344 | ret = max14577_set_fast_charge_timer(chg, | ||
345 | MAXIM_CHARGER_FAST_CHARGE_TIMER_DEFAULT); | ||
346 | if (ret) | ||
347 | return ret; | ||
348 | |||
349 | /* Initialize Overvoltage-Protection Threshold */ | ||
350 | switch (chg->pdata->ovp_uvolt) { | ||
351 | case 7500000: | ||
352 | reg_data = 0x0; | ||
353 | break; | ||
354 | case 6000000: | ||
355 | case 6500000: | ||
356 | case 7000000: | ||
357 | reg_data = 0x1 + (chg->pdata->ovp_uvolt - 6000000) / 500000; | ||
358 | break; | ||
359 | default: | ||
360 | dev_err(chg->dev, "Wrong value for OVP: %u\n", | ||
361 | chg->pdata->ovp_uvolt); | ||
362 | return -EINVAL; | ||
363 | } | ||
364 | reg_data <<= CHGCTRL7_OTPCGHCVS_SHIFT; | ||
204 | max14577_write_reg(rmap, MAX14577_REG_CHGCTRL7, reg_data); | 365 | max14577_write_reg(rmap, MAX14577_REG_CHGCTRL7, reg_data); |
366 | |||
367 | return 0; | ||
205 | } | 368 | } |
206 | 369 | ||
207 | /* Support property from charger */ | 370 | /* Support property from charger */ |
@@ -215,7 +378,11 @@ static enum power_supply_property max14577_charger_props[] = { | |||
215 | POWER_SUPPLY_PROP_MANUFACTURER, | 378 | POWER_SUPPLY_PROP_MANUFACTURER, |
216 | }; | 379 | }; |
217 | 380 | ||
218 | static const char *model_name = "MAX14577"; | 381 | static const char * const model_names[] = { |
382 | [MAXIM_DEVICE_TYPE_UNKNOWN] = "MAX14577-like", | ||
383 | [MAXIM_DEVICE_TYPE_MAX14577] = "MAX14577", | ||
384 | [MAXIM_DEVICE_TYPE_MAX77836] = "MAX77836", | ||
385 | }; | ||
219 | static const char *manufacturer = "Maxim Integrated"; | 386 | static const char *manufacturer = "Maxim Integrated"; |
220 | 387 | ||
221 | static int max14577_charger_get_property(struct power_supply *psy, | 388 | static int max14577_charger_get_property(struct power_supply *psy, |
@@ -244,7 +411,8 @@ static int max14577_charger_get_property(struct power_supply *psy, | |||
244 | val->intval = max14577_get_online(chg); | 411 | val->intval = max14577_get_online(chg); |
245 | break; | 412 | break; |
246 | case POWER_SUPPLY_PROP_MODEL_NAME: | 413 | case POWER_SUPPLY_PROP_MODEL_NAME: |
247 | val->strval = model_name; | 414 | BUILD_BUG_ON(ARRAY_SIZE(model_names) != MAXIM_DEVICE_TYPE_NUM); |
415 | val->strval = model_names[chg->max14577->dev_type]; | ||
248 | break; | 416 | break; |
249 | case POWER_SUPPLY_PROP_MANUFACTURER: | 417 | case POWER_SUPPLY_PROP_MANUFACTURER: |
250 | val->strval = manufacturer; | 418 | val->strval = manufacturer; |
@@ -256,6 +424,110 @@ static int max14577_charger_get_property(struct power_supply *psy, | |||
256 | return ret; | 424 | return ret; |
257 | } | 425 | } |
258 | 426 | ||
427 | #ifdef CONFIG_OF | ||
428 | static struct max14577_charger_platform_data *max14577_charger_dt_init( | ||
429 | struct platform_device *pdev) | ||
430 | { | ||
431 | struct max14577_charger_platform_data *pdata; | ||
432 | struct device_node *np = pdev->dev.of_node; | ||
433 | int ret; | ||
434 | |||
435 | if (!np) { | ||
436 | dev_err(&pdev->dev, "No charger OF node\n"); | ||
437 | return ERR_PTR(-EINVAL); | ||
438 | } | ||
439 | |||
440 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); | ||
441 | if (!pdata) | ||
442 | return ERR_PTR(-ENOMEM); | ||
443 | |||
444 | ret = of_property_read_u32(np, "maxim,constant-uvolt", | ||
445 | &pdata->constant_uvolt); | ||
446 | if (ret) { | ||
447 | dev_err(&pdev->dev, "Cannot parse maxim,constant-uvolt field from DT\n"); | ||
448 | return ERR_PTR(ret); | ||
449 | } | ||
450 | |||
451 | ret = of_property_read_u32(np, "maxim,fast-charge-uamp", | ||
452 | &pdata->fast_charge_uamp); | ||
453 | if (ret) { | ||
454 | dev_err(&pdev->dev, "Cannot parse maxim,fast-charge-uamp field from DT\n"); | ||
455 | return ERR_PTR(ret); | ||
456 | } | ||
457 | |||
458 | ret = of_property_read_u32(np, "maxim,eoc-uamp", &pdata->eoc_uamp); | ||
459 | if (ret) { | ||
460 | dev_err(&pdev->dev, "Cannot parse maxim,eoc-uamp field from DT\n"); | ||
461 | return ERR_PTR(ret); | ||
462 | } | ||
463 | |||
464 | ret = of_property_read_u32(np, "maxim,ovp-uvolt", &pdata->ovp_uvolt); | ||
465 | if (ret) { | ||
466 | dev_err(&pdev->dev, "Cannot parse maxim,ovp-uvolt field from DT\n"); | ||
467 | return ERR_PTR(ret); | ||
468 | } | ||
469 | |||
470 | return pdata; | ||
471 | } | ||
472 | #else /* CONFIG_OF */ | ||
473 | static struct max14577_charger_platform_data *max14577_charger_dt_init( | ||
474 | struct platform_device *pdev) | ||
475 | { | ||
476 | return NULL; | ||
477 | } | ||
478 | #endif /* CONFIG_OF */ | ||
479 | |||
480 | static ssize_t show_fast_charge_timer(struct device *dev, | ||
481 | struct device_attribute *attr, char *buf) | ||
482 | { | ||
483 | struct max14577_charger *chg = dev_get_drvdata(dev); | ||
484 | u8 reg_data; | ||
485 | int ret; | ||
486 | unsigned int val; | ||
487 | |||
488 | ret = max14577_read_reg(chg->max14577->regmap, MAX14577_REG_CHGCTRL1, | ||
489 | ®_data); | ||
490 | if (ret) | ||
491 | return ret; | ||
492 | |||
493 | reg_data &= CHGCTRL1_TCHW_MASK; | ||
494 | reg_data >>= CHGCTRL1_TCHW_SHIFT; | ||
495 | switch (reg_data) { | ||
496 | case 0x2 ... 0x4: | ||
497 | val = reg_data + 3; | ||
498 | break; | ||
499 | case 0x7: | ||
500 | val = 0; | ||
501 | break; | ||
502 | default: | ||
503 | val = 5; | ||
504 | break; | ||
505 | } | ||
506 | |||
507 | return scnprintf(buf, PAGE_SIZE, "%u\n", val); | ||
508 | } | ||
509 | |||
510 | static ssize_t store_fast_charge_timer(struct device *dev, | ||
511 | struct device_attribute *attr, const char *buf, size_t count) | ||
512 | { | ||
513 | struct max14577_charger *chg = dev_get_drvdata(dev); | ||
514 | unsigned long val; | ||
515 | int ret; | ||
516 | |||
517 | ret = kstrtoul(buf, 10, &val); | ||
518 | if (ret) | ||
519 | return ret; | ||
520 | |||
521 | ret = max14577_set_fast_charge_timer(chg, val); | ||
522 | if (ret) | ||
523 | return ret; | ||
524 | |||
525 | return count; | ||
526 | } | ||
527 | |||
528 | static DEVICE_ATTR(fast_charge_timer, S_IRUGO | S_IWUSR, | ||
529 | show_fast_charge_timer, store_fast_charge_timer); | ||
530 | |||
259 | static int max14577_charger_probe(struct platform_device *pdev) | 531 | static int max14577_charger_probe(struct platform_device *pdev) |
260 | { | 532 | { |
261 | struct max14577_charger *chg; | 533 | struct max14577_charger *chg; |
@@ -270,7 +542,13 @@ static int max14577_charger_probe(struct platform_device *pdev) | |||
270 | chg->dev = &pdev->dev; | 542 | chg->dev = &pdev->dev; |
271 | chg->max14577 = max14577; | 543 | chg->max14577 = max14577; |
272 | 544 | ||
273 | max14577_charger_reg_init(chg); | 545 | chg->pdata = max14577_charger_dt_init(pdev); |
546 | if (IS_ERR_OR_NULL(chg->pdata)) | ||
547 | return PTR_ERR(chg->pdata); | ||
548 | |||
549 | ret = max14577_charger_reg_init(chg); | ||
550 | if (ret) | ||
551 | return ret; | ||
274 | 552 | ||
275 | chg->charger.name = "max14577-charger", | 553 | chg->charger.name = "max14577-charger", |
276 | chg->charger.type = POWER_SUPPLY_TYPE_BATTERY, | 554 | chg->charger.type = POWER_SUPPLY_TYPE_BATTERY, |
@@ -278,24 +556,47 @@ static int max14577_charger_probe(struct platform_device *pdev) | |||
278 | chg->charger.num_properties = ARRAY_SIZE(max14577_charger_props), | 556 | chg->charger.num_properties = ARRAY_SIZE(max14577_charger_props), |
279 | chg->charger.get_property = max14577_charger_get_property, | 557 | chg->charger.get_property = max14577_charger_get_property, |
280 | 558 | ||
559 | ret = device_create_file(&pdev->dev, &dev_attr_fast_charge_timer); | ||
560 | if (ret) { | ||
561 | dev_err(&pdev->dev, "failed: create sysfs entry\n"); | ||
562 | return ret; | ||
563 | } | ||
564 | |||
281 | ret = power_supply_register(&pdev->dev, &chg->charger); | 565 | ret = power_supply_register(&pdev->dev, &chg->charger); |
282 | if (ret) { | 566 | if (ret) { |
283 | dev_err(&pdev->dev, "failed: power supply register\n"); | 567 | dev_err(&pdev->dev, "failed: power supply register\n"); |
284 | return ret; | 568 | goto err; |
285 | } | 569 | } |
286 | 570 | ||
571 | /* Check for valid values for charger */ | ||
572 | BUILD_BUG_ON(MAX14577_CHARGER_EOC_CURRENT_LIMIT_MIN + | ||
573 | MAX14577_CHARGER_EOC_CURRENT_LIMIT_STEP * 0xf != | ||
574 | MAX14577_CHARGER_EOC_CURRENT_LIMIT_MAX); | ||
287 | return 0; | 575 | return 0; |
576 | |||
577 | err: | ||
578 | device_remove_file(&pdev->dev, &dev_attr_fast_charge_timer); | ||
579 | |||
580 | return ret; | ||
288 | } | 581 | } |
289 | 582 | ||
290 | static int max14577_charger_remove(struct platform_device *pdev) | 583 | static int max14577_charger_remove(struct platform_device *pdev) |
291 | { | 584 | { |
292 | struct max14577_charger *chg = platform_get_drvdata(pdev); | 585 | struct max14577_charger *chg = platform_get_drvdata(pdev); |
293 | 586 | ||
587 | device_remove_file(&pdev->dev, &dev_attr_fast_charge_timer); | ||
294 | power_supply_unregister(&chg->charger); | 588 | power_supply_unregister(&chg->charger); |
295 | 589 | ||
296 | return 0; | 590 | return 0; |
297 | } | 591 | } |
298 | 592 | ||
593 | static const struct platform_device_id max14577_charger_id[] = { | ||
594 | { "max14577-charger", MAXIM_DEVICE_TYPE_MAX14577, }, | ||
595 | { "max77836-charger", MAXIM_DEVICE_TYPE_MAX77836, }, | ||
596 | { } | ||
597 | }; | ||
598 | MODULE_DEVICE_TABLE(platform, max14577_charger_id); | ||
599 | |||
299 | static struct platform_driver max14577_charger_driver = { | 600 | static struct platform_driver max14577_charger_driver = { |
300 | .driver = { | 601 | .driver = { |
301 | .owner = THIS_MODULE, | 602 | .owner = THIS_MODULE, |
@@ -303,9 +604,10 @@ static struct platform_driver max14577_charger_driver = { | |||
303 | }, | 604 | }, |
304 | .probe = max14577_charger_probe, | 605 | .probe = max14577_charger_probe, |
305 | .remove = max14577_charger_remove, | 606 | .remove = max14577_charger_remove, |
607 | .id_table = max14577_charger_id, | ||
306 | }; | 608 | }; |
307 | module_platform_driver(max14577_charger_driver); | 609 | module_platform_driver(max14577_charger_driver); |
308 | 610 | ||
309 | MODULE_AUTHOR("Krzysztof Kozlowski <k.kozlowski@samsung.com>"); | 611 | MODULE_AUTHOR("Krzysztof Kozlowski <k.kozlowski@samsung.com>"); |
310 | MODULE_DESCRIPTION("MAXIM 14577 charger driver"); | 612 | MODULE_DESCRIPTION("Maxim 14577/77836 charger driver"); |
311 | MODULE_LICENSE("GPL"); | 613 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/power/max17040_battery.c b/drivers/power/max17040_battery.c index 0fbac861080d..14d44706327b 100644 --- a/drivers/power/max17040_battery.c +++ b/drivers/power/max17040_battery.c | |||
@@ -277,7 +277,8 @@ static SIMPLE_DEV_PM_OPS(max17040_pm_ops, max17040_suspend, max17040_resume); | |||
277 | #endif /* CONFIG_PM_SLEEP */ | 277 | #endif /* CONFIG_PM_SLEEP */ |
278 | 278 | ||
279 | static const struct i2c_device_id max17040_id[] = { | 279 | static const struct i2c_device_id max17040_id[] = { |
280 | { "max17040", 0 }, | 280 | { "max17040" }, |
281 | { "max77836-battery" }, | ||
281 | { } | 282 | { } |
282 | }; | 283 | }; |
283 | MODULE_DEVICE_TABLE(i2c, max17040_id); | 284 | MODULE_DEVICE_TABLE(i2c, max17040_id); |
diff --git a/drivers/power/max8925_power.c b/drivers/power/max8925_power.c index b4513f284bbc..a6d45eef64dd 100644 --- a/drivers/power/max8925_power.c +++ b/drivers/power/max8925_power.c | |||
@@ -443,7 +443,7 @@ max8925_power_dt_init(struct platform_device *pdev) | |||
443 | if (!nproot) | 443 | if (!nproot) |
444 | return pdev->dev.platform_data; | 444 | return pdev->dev.platform_data; |
445 | 445 | ||
446 | np = of_find_node_by_name(nproot, "charger"); | 446 | np = of_get_child_by_name(nproot, "charger"); |
447 | if (!np) { | 447 | if (!np) { |
448 | dev_err(&pdev->dev, "failed to find charger node\n"); | 448 | dev_err(&pdev->dev, "failed to find charger node\n"); |
449 | return NULL; | 449 | return NULL; |
@@ -452,13 +452,14 @@ max8925_power_dt_init(struct platform_device *pdev) | |||
452 | pdata = devm_kzalloc(&pdev->dev, | 452 | pdata = devm_kzalloc(&pdev->dev, |
453 | sizeof(struct max8925_power_pdata), | 453 | sizeof(struct max8925_power_pdata), |
454 | GFP_KERNEL); | 454 | GFP_KERNEL); |
455 | if (!pdata) | ||
456 | goto ret; | ||
455 | 457 | ||
456 | of_property_read_u32(np, "topoff-threshold", &topoff_threshold); | 458 | of_property_read_u32(np, "topoff-threshold", &topoff_threshold); |
457 | of_property_read_u32(np, "batt-detect", &batt_detect); | 459 | of_property_read_u32(np, "batt-detect", &batt_detect); |
458 | of_property_read_u32(np, "fast-charge", &fast_charge); | 460 | of_property_read_u32(np, "fast-charge", &fast_charge); |
459 | of_property_read_u32(np, "no-insert-detect", &no_insert_detect); | 461 | of_property_read_u32(np, "no-insert-detect", &no_insert_detect); |
460 | of_property_read_u32(np, "no-temp-support", &no_temp_support); | 462 | of_property_read_u32(np, "no-temp-support", &no_temp_support); |
461 | of_node_put(np); | ||
462 | 463 | ||
463 | pdata->batt_detect = batt_detect; | 464 | pdata->batt_detect = batt_detect; |
464 | pdata->fast_charge = fast_charge; | 465 | pdata->fast_charge = fast_charge; |
@@ -466,6 +467,8 @@ max8925_power_dt_init(struct platform_device *pdev) | |||
466 | pdata->no_insert_detect = no_insert_detect; | 467 | pdata->no_insert_detect = no_insert_detect; |
467 | pdata->no_temp_support = no_temp_support; | 468 | pdata->no_temp_support = no_temp_support; |
468 | 469 | ||
470 | ret: | ||
471 | of_node_put(np); | ||
469 | return pdata; | 472 | return pdata; |
470 | } | 473 | } |
471 | #else | 474 | #else |
diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c index 078afd61490d..6cb7fe5c022d 100644 --- a/drivers/power/power_supply_core.c +++ b/drivers/power/power_supply_core.c | |||
@@ -58,7 +58,7 @@ static bool __power_supply_is_supplied_by(struct power_supply *supplier, | |||
58 | 58 | ||
59 | static int __power_supply_changed_work(struct device *dev, void *data) | 59 | static int __power_supply_changed_work(struct device *dev, void *data) |
60 | { | 60 | { |
61 | struct power_supply *psy = (struct power_supply *)data; | 61 | struct power_supply *psy = data; |
62 | struct power_supply *pst = dev_get_drvdata(dev); | 62 | struct power_supply *pst = dev_get_drvdata(dev); |
63 | 63 | ||
64 | if (__power_supply_is_supplied_by(psy, pst)) { | 64 | if (__power_supply_is_supplied_by(psy, pst)) { |
@@ -78,7 +78,14 @@ static void power_supply_changed_work(struct work_struct *work) | |||
78 | dev_dbg(psy->dev, "%s\n", __func__); | 78 | dev_dbg(psy->dev, "%s\n", __func__); |
79 | 79 | ||
80 | spin_lock_irqsave(&psy->changed_lock, flags); | 80 | spin_lock_irqsave(&psy->changed_lock, flags); |
81 | if (psy->changed) { | 81 | /* |
82 | * Check 'changed' here to avoid issues due to race between | ||
83 | * power_supply_changed() and this routine. In worst case | ||
84 | * power_supply_changed() can be called again just before we take above | ||
85 | * lock. During the first call of this routine we will mark 'changed' as | ||
86 | * false and it will stay false for the next call as well. | ||
87 | */ | ||
88 | if (likely(psy->changed)) { | ||
82 | psy->changed = false; | 89 | psy->changed = false; |
83 | spin_unlock_irqrestore(&psy->changed_lock, flags); | 90 | spin_unlock_irqrestore(&psy->changed_lock, flags); |
84 | class_for_each_device(power_supply_class, NULL, psy, | 91 | class_for_each_device(power_supply_class, NULL, psy, |
@@ -89,12 +96,13 @@ static void power_supply_changed_work(struct work_struct *work) | |||
89 | kobject_uevent(&psy->dev->kobj, KOBJ_CHANGE); | 96 | kobject_uevent(&psy->dev->kobj, KOBJ_CHANGE); |
90 | spin_lock_irqsave(&psy->changed_lock, flags); | 97 | spin_lock_irqsave(&psy->changed_lock, flags); |
91 | } | 98 | } |
99 | |||
92 | /* | 100 | /* |
93 | * Dependent power supplies (e.g. battery) may have changed state | 101 | * Hold the wakeup_source until all events are processed. |
94 | * as a result of this event, so poll again and hold the | 102 | * power_supply_changed() might have called again and have set 'changed' |
95 | * wakeup_source until all events are processed. | 103 | * to true. |
96 | */ | 104 | */ |
97 | if (!psy->changed) | 105 | if (likely(!psy->changed)) |
98 | pm_relax(psy->dev); | 106 | pm_relax(psy->dev); |
99 | spin_unlock_irqrestore(&psy->changed_lock, flags); | 107 | spin_unlock_irqrestore(&psy->changed_lock, flags); |
100 | } | 108 | } |
@@ -119,7 +127,7 @@ EXPORT_SYMBOL_GPL(power_supply_changed); | |||
119 | static int __power_supply_populate_supplied_from(struct device *dev, | 127 | static int __power_supply_populate_supplied_from(struct device *dev, |
120 | void *data) | 128 | void *data) |
121 | { | 129 | { |
122 | struct power_supply *psy = (struct power_supply *)data; | 130 | struct power_supply *psy = data; |
123 | struct power_supply *epsy = dev_get_drvdata(dev); | 131 | struct power_supply *epsy = dev_get_drvdata(dev); |
124 | struct device_node *np; | 132 | struct device_node *np; |
125 | int i = 0; | 133 | int i = 0; |
@@ -127,7 +135,7 @@ static int __power_supply_populate_supplied_from(struct device *dev, | |||
127 | do { | 135 | do { |
128 | np = of_parse_phandle(psy->of_node, "power-supplies", i++); | 136 | np = of_parse_phandle(psy->of_node, "power-supplies", i++); |
129 | if (!np) | 137 | if (!np) |
130 | continue; | 138 | break; |
131 | 139 | ||
132 | if (np == epsy->of_node) { | 140 | if (np == epsy->of_node) { |
133 | dev_info(psy->dev, "%s: Found supply : %s\n", | 141 | dev_info(psy->dev, "%s: Found supply : %s\n", |
@@ -158,12 +166,12 @@ static int power_supply_populate_supplied_from(struct power_supply *psy) | |||
158 | static int __power_supply_find_supply_from_node(struct device *dev, | 166 | static int __power_supply_find_supply_from_node(struct device *dev, |
159 | void *data) | 167 | void *data) |
160 | { | 168 | { |
161 | struct device_node *np = (struct device_node *)data; | 169 | struct device_node *np = data; |
162 | struct power_supply *epsy = dev_get_drvdata(dev); | 170 | struct power_supply *epsy = dev_get_drvdata(dev); |
163 | 171 | ||
164 | /* return error breaks out of class_for_each_device loop */ | 172 | /* returning non-zero breaks out of class_for_each_device loop */ |
165 | if (epsy->of_node == np) | 173 | if (epsy->of_node == np) |
166 | return -EINVAL; | 174 | return 1; |
167 | 175 | ||
168 | return 0; | 176 | return 0; |
169 | } | 177 | } |
@@ -171,30 +179,21 @@ static int __power_supply_find_supply_from_node(struct device *dev, | |||
171 | static int power_supply_find_supply_from_node(struct device_node *supply_node) | 179 | static int power_supply_find_supply_from_node(struct device_node *supply_node) |
172 | { | 180 | { |
173 | int error; | 181 | int error; |
174 | struct device *dev; | ||
175 | struct class_dev_iter iter; | ||
176 | 182 | ||
177 | /* | 183 | /* |
178 | * Use iterator to see if any other device is registered. | 184 | * class_for_each_device() either returns its own errors or values |
179 | * This is required since class_for_each_device returns 0 | 185 | * returned by __power_supply_find_supply_from_node(). |
180 | * if there are no devices registered. | 186 | * |
181 | */ | 187 | * __power_supply_find_supply_from_node() will return 0 (no match) |
182 | class_dev_iter_init(&iter, power_supply_class, NULL, NULL); | 188 | * or 1 (match). |
183 | dev = class_dev_iter_next(&iter); | 189 | * |
184 | 190 | * We return 0 if class_for_each_device() returned 1, -EPROBE_DEFER if | |
185 | if (!dev) | 191 | * it returned 0, or error as returned by it. |
186 | return -EPROBE_DEFER; | ||
187 | |||
188 | /* | ||
189 | * We have to treat the return value as inverted, because if | ||
190 | * we return error on not found, then it won't continue looking. | ||
191 | * So we trick it by returning error on success to stop looking | ||
192 | * once the matching device is found. | ||
193 | */ | 192 | */ |
194 | error = class_for_each_device(power_supply_class, NULL, supply_node, | 193 | error = class_for_each_device(power_supply_class, NULL, supply_node, |
195 | __power_supply_find_supply_from_node); | 194 | __power_supply_find_supply_from_node); |
196 | 195 | ||
197 | return error ? 0 : -EPROBE_DEFER; | 196 | return error ? (error == 1 ? 0 : error) : -EPROBE_DEFER; |
198 | } | 197 | } |
199 | 198 | ||
200 | static int power_supply_check_supplies(struct power_supply *psy) | 199 | static int power_supply_check_supplies(struct power_supply *psy) |
@@ -215,17 +214,21 @@ static int power_supply_check_supplies(struct power_supply *psy) | |||
215 | 214 | ||
216 | np = of_parse_phandle(psy->of_node, "power-supplies", cnt++); | 215 | np = of_parse_phandle(psy->of_node, "power-supplies", cnt++); |
217 | if (!np) | 216 | if (!np) |
218 | continue; | 217 | break; |
219 | 218 | ||
220 | ret = power_supply_find_supply_from_node(np); | 219 | ret = power_supply_find_supply_from_node(np); |
220 | of_node_put(np); | ||
221 | |||
221 | if (ret) { | 222 | if (ret) { |
222 | dev_dbg(psy->dev, "Failed to find supply, defer!\n"); | 223 | dev_dbg(psy->dev, "Failed to find supply!\n"); |
223 | of_node_put(np); | 224 | return ret; |
224 | return -EPROBE_DEFER; | ||
225 | } | 225 | } |
226 | of_node_put(np); | ||
227 | } while (np); | 226 | } while (np); |
228 | 227 | ||
228 | /* Missing valid "power-supplies" entries */ | ||
229 | if (cnt == 1) | ||
230 | return 0; | ||
231 | |||
229 | /* All supplies found, allocate char ** array for filling */ | 232 | /* All supplies found, allocate char ** array for filling */ |
230 | psy->supplied_from = devm_kzalloc(psy->dev, sizeof(psy->supplied_from), | 233 | psy->supplied_from = devm_kzalloc(psy->dev, sizeof(psy->supplied_from), |
231 | GFP_KERNEL); | 234 | GFP_KERNEL); |
@@ -234,7 +237,7 @@ static int power_supply_check_supplies(struct power_supply *psy) | |||
234 | return -ENOMEM; | 237 | return -ENOMEM; |
235 | } | 238 | } |
236 | 239 | ||
237 | *psy->supplied_from = devm_kzalloc(psy->dev, sizeof(char *) * cnt, | 240 | *psy->supplied_from = devm_kzalloc(psy->dev, sizeof(char *) * (cnt - 1), |
238 | GFP_KERNEL); | 241 | GFP_KERNEL); |
239 | if (!*psy->supplied_from) { | 242 | if (!*psy->supplied_from) { |
240 | dev_err(psy->dev, "Couldn't allocate memory for supply list\n"); | 243 | dev_err(psy->dev, "Couldn't allocate memory for supply list\n"); |
@@ -253,14 +256,12 @@ static inline int power_supply_check_supplies(struct power_supply *psy) | |||
253 | static int __power_supply_am_i_supplied(struct device *dev, void *data) | 256 | static int __power_supply_am_i_supplied(struct device *dev, void *data) |
254 | { | 257 | { |
255 | union power_supply_propval ret = {0,}; | 258 | union power_supply_propval ret = {0,}; |
256 | struct power_supply *psy = (struct power_supply *)data; | 259 | struct power_supply *psy = data; |
257 | struct power_supply *epsy = dev_get_drvdata(dev); | 260 | struct power_supply *epsy = dev_get_drvdata(dev); |
258 | 261 | ||
259 | if (__power_supply_is_supplied_by(epsy, psy)) | 262 | if (__power_supply_is_supplied_by(epsy, psy)) |
260 | if (!epsy->get_property(epsy, POWER_SUPPLY_PROP_ONLINE, &ret)) { | 263 | if (!epsy->get_property(epsy, POWER_SUPPLY_PROP_ONLINE, &ret)) |
261 | if (ret.intval) | 264 | return ret.intval; |
262 | return ret.intval; | ||
263 | } | ||
264 | 265 | ||
265 | return 0; | 266 | return 0; |
266 | } | 267 | } |
@@ -285,12 +286,10 @@ static int __power_supply_is_system_supplied(struct device *dev, void *data) | |||
285 | unsigned int *count = data; | 286 | unsigned int *count = data; |
286 | 287 | ||
287 | (*count)++; | 288 | (*count)++; |
288 | if (psy->type != POWER_SUPPLY_TYPE_BATTERY) { | 289 | if (psy->type != POWER_SUPPLY_TYPE_BATTERY) |
289 | if (psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &ret)) | 290 | if (!psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &ret)) |
290 | return 0; | ||
291 | if (ret.intval) | ||
292 | return ret.intval; | 291 | return ret.intval; |
293 | } | 292 | |
294 | return 0; | 293 | return 0; |
295 | } | 294 | } |
296 | 295 | ||
@@ -423,9 +422,7 @@ static int psy_register_thermal(struct power_supply *psy) | |||
423 | if (psy->properties[i] == POWER_SUPPLY_PROP_TEMP) { | 422 | if (psy->properties[i] == POWER_SUPPLY_PROP_TEMP) { |
424 | psy->tzd = thermal_zone_device_register(psy->name, 0, 0, | 423 | psy->tzd = thermal_zone_device_register(psy->name, 0, 0, |
425 | psy, &psy_tzd_ops, NULL, 0, 0); | 424 | psy, &psy_tzd_ops, NULL, 0, 0); |
426 | if (IS_ERR(psy->tzd)) | 425 | return PTR_ERR_OR_ZERO(psy->tzd); |
427 | return PTR_ERR(psy->tzd); | ||
428 | break; | ||
429 | } | 426 | } |
430 | } | 427 | } |
431 | return 0; | 428 | return 0; |
@@ -503,9 +500,7 @@ static int psy_register_cooler(struct power_supply *psy) | |||
503 | psy->tcd = thermal_cooling_device_register( | 500 | psy->tcd = thermal_cooling_device_register( |
504 | (char *)psy->name, | 501 | (char *)psy->name, |
505 | psy, &psy_tcd_ops); | 502 | psy, &psy_tcd_ops); |
506 | if (IS_ERR(psy->tcd)) | 503 | return PTR_ERR_OR_ZERO(psy->tcd); |
507 | return PTR_ERR(psy->tcd); | ||
508 | break; | ||
509 | } | 504 | } |
510 | } | 505 | } |
511 | return 0; | 506 | return 0; |
@@ -591,7 +586,7 @@ static int __power_supply_register(struct device *parent, | |||
591 | 586 | ||
592 | power_supply_changed(psy); | 587 | power_supply_changed(psy); |
593 | 588 | ||
594 | goto success; | 589 | return 0; |
595 | 590 | ||
596 | create_triggers_failed: | 591 | create_triggers_failed: |
597 | psy_unregister_cooler(psy); | 592 | psy_unregister_cooler(psy); |
@@ -604,7 +599,6 @@ wakeup_init_failed: | |||
604 | check_supplies_failed: | 599 | check_supplies_failed: |
605 | dev_set_name_failed: | 600 | dev_set_name_failed: |
606 | put_device(dev); | 601 | put_device(dev); |
607 | success: | ||
608 | return rc; | 602 | return rc; |
609 | } | 603 | } |
610 | 604 | ||
diff --git a/drivers/power/power_supply_leds.c b/drivers/power/power_supply_leds.c index 995f966ed5b7..effa093c37b0 100644 --- a/drivers/power/power_supply_leds.c +++ b/drivers/power/power_supply_leds.c | |||
@@ -57,8 +57,6 @@ static void power_supply_update_bat_leds(struct power_supply *psy) | |||
57 | 57 | ||
58 | static int power_supply_create_bat_triggers(struct power_supply *psy) | 58 | static int power_supply_create_bat_triggers(struct power_supply *psy) |
59 | { | 59 | { |
60 | int rc = 0; | ||
61 | |||
62 | psy->charging_full_trig_name = kasprintf(GFP_KERNEL, | 60 | psy->charging_full_trig_name = kasprintf(GFP_KERNEL, |
63 | "%s-charging-or-full", psy->name); | 61 | "%s-charging-or-full", psy->name); |
64 | if (!psy->charging_full_trig_name) | 62 | if (!psy->charging_full_trig_name) |
@@ -87,7 +85,7 @@ static int power_supply_create_bat_triggers(struct power_supply *psy) | |||
87 | led_trigger_register_simple(psy->charging_blink_full_solid_trig_name, | 85 | led_trigger_register_simple(psy->charging_blink_full_solid_trig_name, |
88 | &psy->charging_blink_full_solid_trig); | 86 | &psy->charging_blink_full_solid_trig); |
89 | 87 | ||
90 | goto success; | 88 | return 0; |
91 | 89 | ||
92 | charging_blink_full_solid_failed: | 90 | charging_blink_full_solid_failed: |
93 | kfree(psy->full_trig_name); | 91 | kfree(psy->full_trig_name); |
@@ -96,9 +94,7 @@ full_failed: | |||
96 | charging_failed: | 94 | charging_failed: |
97 | kfree(psy->charging_full_trig_name); | 95 | kfree(psy->charging_full_trig_name); |
98 | charging_full_failed: | 96 | charging_full_failed: |
99 | rc = -ENOMEM; | 97 | return -ENOMEM; |
100 | success: | ||
101 | return rc; | ||
102 | } | 98 | } |
103 | 99 | ||
104 | static void power_supply_remove_bat_triggers(struct power_supply *psy) | 100 | static void power_supply_remove_bat_triggers(struct power_supply *psy) |
@@ -132,20 +128,13 @@ static void power_supply_update_gen_leds(struct power_supply *psy) | |||
132 | 128 | ||
133 | static int power_supply_create_gen_triggers(struct power_supply *psy) | 129 | static int power_supply_create_gen_triggers(struct power_supply *psy) |
134 | { | 130 | { |
135 | int rc = 0; | ||
136 | |||
137 | psy->online_trig_name = kasprintf(GFP_KERNEL, "%s-online", psy->name); | 131 | psy->online_trig_name = kasprintf(GFP_KERNEL, "%s-online", psy->name); |
138 | if (!psy->online_trig_name) | 132 | if (!psy->online_trig_name) |
139 | goto online_failed; | 133 | return -ENOMEM; |
140 | 134 | ||
141 | led_trigger_register_simple(psy->online_trig_name, &psy->online_trig); | 135 | led_trigger_register_simple(psy->online_trig_name, &psy->online_trig); |
142 | 136 | ||
143 | goto success; | 137 | return 0; |
144 | |||
145 | online_failed: | ||
146 | rc = -ENOMEM; | ||
147 | success: | ||
148 | return rc; | ||
149 | } | 138 | } |
150 | 139 | ||
151 | static void power_supply_remove_gen_triggers(struct power_supply *psy) | 140 | static void power_supply_remove_gen_triggers(struct power_supply *psy) |
diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c index 750a20275664..62653f50a524 100644 --- a/drivers/power/power_supply_sysfs.c +++ b/drivers/power/power_supply_sysfs.c | |||
@@ -73,19 +73,20 @@ static ssize_t power_supply_show_property(struct device *dev, | |||
73 | const ptrdiff_t off = attr - power_supply_attrs; | 73 | const ptrdiff_t off = attr - power_supply_attrs; |
74 | union power_supply_propval value; | 74 | union power_supply_propval value; |
75 | 75 | ||
76 | if (off == POWER_SUPPLY_PROP_TYPE) | 76 | if (off == POWER_SUPPLY_PROP_TYPE) { |
77 | value.intval = psy->type; | 77 | value.intval = psy->type; |
78 | else | 78 | } else { |
79 | ret = psy->get_property(psy, off, &value); | 79 | ret = psy->get_property(psy, off, &value); |
80 | 80 | ||
81 | if (ret < 0) { | 81 | if (ret < 0) { |
82 | if (ret == -ENODATA) | 82 | if (ret == -ENODATA) |
83 | dev_dbg(dev, "driver has no data for `%s' property\n", | 83 | dev_dbg(dev, "driver has no data for `%s' property\n", |
84 | attr->attr.name); | 84 | attr->attr.name); |
85 | else if (ret != -ENODEV) | 85 | else if (ret != -ENODEV) |
86 | dev_err(dev, "driver failed to report `%s' property: %zd\n", | 86 | dev_err(dev, "driver failed to report `%s' property: %zd\n", |
87 | attr->attr.name, ret); | 87 | attr->attr.name, ret); |
88 | return ret; | 88 | return ret; |
89 | } | ||
89 | } | 90 | } |
90 | 91 | ||
91 | if (off == POWER_SUPPLY_PROP_STATUS) | 92 | if (off == POWER_SUPPLY_PROP_STATUS) |
@@ -149,9 +150,11 @@ static struct device_attribute power_supply_attrs[] = { | |||
149 | POWER_SUPPLY_ATTR(voltage_now), | 150 | POWER_SUPPLY_ATTR(voltage_now), |
150 | POWER_SUPPLY_ATTR(voltage_avg), | 151 | POWER_SUPPLY_ATTR(voltage_avg), |
151 | POWER_SUPPLY_ATTR(voltage_ocv), | 152 | POWER_SUPPLY_ATTR(voltage_ocv), |
153 | POWER_SUPPLY_ATTR(voltage_boot), | ||
152 | POWER_SUPPLY_ATTR(current_max), | 154 | POWER_SUPPLY_ATTR(current_max), |
153 | POWER_SUPPLY_ATTR(current_now), | 155 | POWER_SUPPLY_ATTR(current_now), |
154 | POWER_SUPPLY_ATTR(current_avg), | 156 | POWER_SUPPLY_ATTR(current_avg), |
157 | POWER_SUPPLY_ATTR(current_boot), | ||
155 | POWER_SUPPLY_ATTR(power_now), | 158 | POWER_SUPPLY_ATTR(power_now), |
156 | POWER_SUPPLY_ATTR(power_avg), | 159 | POWER_SUPPLY_ATTR(power_avg), |
157 | POWER_SUPPLY_ATTR(charge_full_design), | 160 | POWER_SUPPLY_ATTR(charge_full_design), |
@@ -193,6 +196,7 @@ static struct device_attribute power_supply_attrs[] = { | |||
193 | POWER_SUPPLY_ATTR(type), | 196 | POWER_SUPPLY_ATTR(type), |
194 | POWER_SUPPLY_ATTR(scope), | 197 | POWER_SUPPLY_ATTR(scope), |
195 | POWER_SUPPLY_ATTR(charge_term_current), | 198 | POWER_SUPPLY_ATTR(charge_term_current), |
199 | POWER_SUPPLY_ATTR(calibrate), | ||
196 | /* Properties of type `const char *' */ | 200 | /* Properties of type `const char *' */ |
197 | POWER_SUPPLY_ATTR(model_name), | 201 | POWER_SUPPLY_ATTR(model_name), |
198 | POWER_SUPPLY_ATTR(manufacturer), | 202 | POWER_SUPPLY_ATTR(manufacturer), |
diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index 527a0f47ef44..f65ff49bb275 100644 --- a/drivers/power/reset/Kconfig +++ b/drivers/power/reset/Kconfig | |||
@@ -40,7 +40,7 @@ config POWER_RESET_AXXIA | |||
40 | 40 | ||
41 | config POWER_RESET_BRCMSTB | 41 | config POWER_RESET_BRCMSTB |
42 | bool "Broadcom STB reset driver" if COMPILE_TEST | 42 | bool "Broadcom STB reset driver" if COMPILE_TEST |
43 | depends on POWER_RESET && ARM | 43 | depends on ARM |
44 | default ARCH_BRCMSTB | 44 | default ARCH_BRCMSTB |
45 | help | 45 | help |
46 | This driver provides restart support for ARM-based Broadcom STB | 46 | This driver provides restart support for ARM-based Broadcom STB |
@@ -57,9 +57,17 @@ config POWER_RESET_GPIO | |||
57 | If your board needs a GPIO high/low to power down, say Y and | 57 | If your board needs a GPIO high/low to power down, say Y and |
58 | create a binding in your devicetree. | 58 | create a binding in your devicetree. |
59 | 59 | ||
60 | config POWER_RESET_GPIO_RESTART | ||
61 | bool "GPIO restart driver" | ||
62 | depends on OF_GPIO | ||
63 | help | ||
64 | This driver supports restarting your board via a GPIO line. | ||
65 | If your board needs a GPIO high/low to restart, say Y and | ||
66 | create a binding in your devicetree. | ||
67 | |||
60 | config POWER_RESET_HISI | 68 | config POWER_RESET_HISI |
61 | bool "Hisilicon power-off driver" | 69 | bool "Hisilicon power-off driver" |
62 | depends on POWER_RESET && ARCH_HISI | 70 | depends on ARCH_HISI |
63 | help | 71 | help |
64 | Reboot support for Hisilicon boards. | 72 | Reboot support for Hisilicon boards. |
65 | 73 | ||
@@ -69,6 +77,13 @@ config POWER_RESET_MSM | |||
69 | help | 77 | help |
70 | Power off and restart support for Qualcomm boards. | 78 | Power off and restart support for Qualcomm boards. |
71 | 79 | ||
80 | config POWER_RESET_LTC2952 | ||
81 | bool "LTC2952 PowerPath power-off driver" | ||
82 | depends on OF_GPIO | ||
83 | help | ||
84 | This driver supports an external powerdown trigger and board power | ||
85 | down via the LTC2952. Bindings are made in the device tree. | ||
86 | |||
72 | config POWER_RESET_QNAP | 87 | config POWER_RESET_QNAP |
73 | bool "QNAP power-off driver" | 88 | bool "QNAP power-off driver" |
74 | depends on OF_GPIO && PLAT_ORION | 89 | depends on OF_GPIO && PLAT_ORION |
@@ -92,6 +107,12 @@ config POWER_RESET_SUN6I | |||
92 | help | 107 | help |
93 | Reboot support for the Allwinner A31 SoCs. | 108 | Reboot support for the Allwinner A31 SoCs. |
94 | 109 | ||
110 | config POWER_RESET_ST | ||
111 | bool "ST restart power-off driver" | ||
112 | depends on ARCH_STI | ||
113 | help | ||
114 | Power off and reset support for STMicroelectronics boards. | ||
115 | |||
95 | config POWER_RESET_VERSATILE | 116 | config POWER_RESET_VERSATILE |
96 | bool "ARM Versatile family reboot driver" | 117 | bool "ARM Versatile family reboot driver" |
97 | depends on ARM | 118 | depends on ARM |
@@ -122,4 +143,12 @@ config POWER_RESET_KEYSTONE | |||
122 | help | 143 | help |
123 | Reboot support for the KEYSTONE SoCs. | 144 | Reboot support for the KEYSTONE SoCs. |
124 | 145 | ||
146 | config POWER_RESET_SYSCON | ||
147 | bool "Generic SYSCON regmap reset driver" | ||
148 | depends on OF | ||
149 | select MFD_SYSCON | ||
150 | help | ||
151 | Reboot support for generic SYSCON mapped register reset. | ||
152 | |||
125 | endif | 153 | endif |
154 | |||
diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile index 73221009f2bf..76ce1c59469b 100644 --- a/drivers/power/reset/Makefile +++ b/drivers/power/reset/Makefile | |||
@@ -4,12 +4,16 @@ obj-$(CONFIG_POWER_RESET_AT91_RESET) += at91-reset.o | |||
4 | obj-$(CONFIG_POWER_RESET_AXXIA) += axxia-reset.o | 4 | obj-$(CONFIG_POWER_RESET_AXXIA) += axxia-reset.o |
5 | obj-$(CONFIG_POWER_RESET_BRCMSTB) += brcmstb-reboot.o | 5 | obj-$(CONFIG_POWER_RESET_BRCMSTB) += brcmstb-reboot.o |
6 | obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o | 6 | obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o |
7 | obj-$(CONFIG_POWER_RESET_GPIO_RESTART) += gpio-restart.o | ||
7 | obj-$(CONFIG_POWER_RESET_HISI) += hisi-reboot.o | 8 | obj-$(CONFIG_POWER_RESET_HISI) += hisi-reboot.o |
8 | obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o | 9 | obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o |
10 | obj-$(CONFIG_POWER_RESET_LTC2952) += ltc2952-poweroff.o | ||
9 | obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o | 11 | obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o |
10 | obj-$(CONFIG_POWER_RESET_RESTART) += restart-poweroff.o | 12 | obj-$(CONFIG_POWER_RESET_RESTART) += restart-poweroff.o |
11 | obj-$(CONFIG_POWER_RESET_SUN6I) += sun6i-reboot.o | 13 | obj-$(CONFIG_POWER_RESET_SUN6I) += sun6i-reboot.o |
14 | obj-$(CONFIG_POWER_RESET_ST) += st-poweroff.o | ||
12 | obj-$(CONFIG_POWER_RESET_VERSATILE) += arm-versatile-reboot.o | 15 | obj-$(CONFIG_POWER_RESET_VERSATILE) += arm-versatile-reboot.o |
13 | obj-$(CONFIG_POWER_RESET_VEXPRESS) += vexpress-poweroff.o | 16 | obj-$(CONFIG_POWER_RESET_VEXPRESS) += vexpress-poweroff.o |
14 | obj-$(CONFIG_POWER_RESET_XGENE) += xgene-reboot.o | 17 | obj-$(CONFIG_POWER_RESET_XGENE) += xgene-reboot.o |
15 | obj-$(CONFIG_POWER_RESET_KEYSTONE) += keystone-reset.o | 18 | obj-$(CONFIG_POWER_RESET_KEYSTONE) += keystone-reset.o |
19 | obj-$(CONFIG_POWER_RESET_SYSCON) += syscon-reboot.o | ||
diff --git a/drivers/power/reset/gpio-restart.c b/drivers/power/reset/gpio-restart.c new file mode 100644 index 000000000000..a76829b3f1cd --- /dev/null +++ b/drivers/power/reset/gpio-restart.c | |||
@@ -0,0 +1,149 @@ | |||
1 | /* | ||
2 | * Toggles a GPIO pin to restart a device | ||
3 | * | ||
4 | * Copyright (C) 2014 Google, Inc. | ||
5 | * | ||
6 | * This software is licensed under the terms of the GNU General Public | ||
7 | * License version 2, as published by the Free Software Foundation, and | ||
8 | * may be copied, distributed, and modified under those terms. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * Based on the gpio-poweroff driver. | ||
16 | */ | ||
17 | #include <linux/reboot.h> | ||
18 | #include <linux/kernel.h> | ||
19 | #include <linux/init.h> | ||
20 | #include <linux/delay.h> | ||
21 | #include <linux/platform_device.h> | ||
22 | #include <linux/gpio/consumer.h> | ||
23 | #include <linux/of_platform.h> | ||
24 | #include <linux/module.h> | ||
25 | |||
26 | struct gpio_restart { | ||
27 | struct gpio_desc *reset_gpio; | ||
28 | struct notifier_block restart_handler; | ||
29 | u32 active_delay_ms; | ||
30 | u32 inactive_delay_ms; | ||
31 | u32 wait_delay_ms; | ||
32 | }; | ||
33 | |||
34 | static int gpio_restart_notify(struct notifier_block *this, | ||
35 | unsigned long mode, void *cmd) | ||
36 | { | ||
37 | struct gpio_restart *gpio_restart = | ||
38 | container_of(this, struct gpio_restart, restart_handler); | ||
39 | |||
40 | /* drive it active, also inactive->active edge */ | ||
41 | gpiod_direction_output(gpio_restart->reset_gpio, 1); | ||
42 | mdelay(gpio_restart->active_delay_ms); | ||
43 | |||
44 | /* drive inactive, also active->inactive edge */ | ||
45 | gpiod_set_value(gpio_restart->reset_gpio, 0); | ||
46 | mdelay(gpio_restart->inactive_delay_ms); | ||
47 | |||
48 | /* drive it active, also inactive->active edge */ | ||
49 | gpiod_set_value(gpio_restart->reset_gpio, 1); | ||
50 | |||
51 | /* give it some time */ | ||
52 | mdelay(gpio_restart->wait_delay_ms); | ||
53 | |||
54 | WARN_ON(1); | ||
55 | |||
56 | return NOTIFY_DONE; | ||
57 | } | ||
58 | |||
59 | static int gpio_restart_probe(struct platform_device *pdev) | ||
60 | { | ||
61 | struct gpio_restart *gpio_restart; | ||
62 | bool open_source = false; | ||
63 | u32 property; | ||
64 | int ret; | ||
65 | |||
66 | gpio_restart = devm_kzalloc(&pdev->dev, sizeof(*gpio_restart), | ||
67 | GFP_KERNEL); | ||
68 | if (!gpio_restart) | ||
69 | return -ENOMEM; | ||
70 | |||
71 | open_source = of_property_read_bool(pdev->dev.of_node, "open-source"); | ||
72 | |||
73 | gpio_restart->reset_gpio = devm_gpiod_get(&pdev->dev, NULL, | ||
74 | open_source ? GPIOD_IN : GPIOD_OUT_LOW); | ||
75 | if (IS_ERR(gpio_restart->reset_gpio)) { | ||
76 | dev_err(&pdev->dev, "Could net get reset GPIO\n"); | ||
77 | return PTR_ERR(gpio_restart->reset_gpio); | ||
78 | } | ||
79 | |||
80 | gpio_restart->restart_handler.notifier_call = gpio_restart_notify; | ||
81 | gpio_restart->restart_handler.priority = 128; | ||
82 | gpio_restart->active_delay_ms = 100; | ||
83 | gpio_restart->inactive_delay_ms = 100; | ||
84 | gpio_restart->wait_delay_ms = 3000; | ||
85 | |||
86 | ret = of_property_read_u32(pdev->dev.of_node, "priority", &property); | ||
87 | if (!ret) { | ||
88 | if (property > 255) | ||
89 | dev_err(&pdev->dev, "Invalid priority property: %u\n", | ||
90 | property); | ||
91 | else | ||
92 | gpio_restart->restart_handler.priority = property; | ||
93 | } | ||
94 | |||
95 | of_property_read_u32(pdev->dev.of_node, "active-delay", | ||
96 | &gpio_restart->active_delay_ms); | ||
97 | of_property_read_u32(pdev->dev.of_node, "inactive-delay", | ||
98 | &gpio_restart->inactive_delay_ms); | ||
99 | of_property_read_u32(pdev->dev.of_node, "wait-delay", | ||
100 | &gpio_restart->wait_delay_ms); | ||
101 | |||
102 | platform_set_drvdata(pdev, gpio_restart); | ||
103 | |||
104 | ret = register_restart_handler(&gpio_restart->restart_handler); | ||
105 | if (ret) { | ||
106 | dev_err(&pdev->dev, "%s: cannot register restart handler, %d\n", | ||
107 | __func__, ret); | ||
108 | return -ENODEV; | ||
109 | } | ||
110 | |||
111 | return 0; | ||
112 | } | ||
113 | |||
114 | static int gpio_restart_remove(struct platform_device *pdev) | ||
115 | { | ||
116 | struct gpio_restart *gpio_restart = platform_get_drvdata(pdev); | ||
117 | int ret; | ||
118 | |||
119 | ret = unregister_restart_handler(&gpio_restart->restart_handler); | ||
120 | if (ret) { | ||
121 | dev_err(&pdev->dev, | ||
122 | "%s: cannot unregister restart handler, %d\n", | ||
123 | __func__, ret); | ||
124 | return -ENODEV; | ||
125 | } | ||
126 | |||
127 | return 0; | ||
128 | } | ||
129 | |||
130 | static const struct of_device_id of_gpio_restart_match[] = { | ||
131 | { .compatible = "gpio-restart", }, | ||
132 | {}, | ||
133 | }; | ||
134 | |||
135 | static struct platform_driver gpio_restart_driver = { | ||
136 | .probe = gpio_restart_probe, | ||
137 | .remove = gpio_restart_remove, | ||
138 | .driver = { | ||
139 | .name = "restart-gpio", | ||
140 | .owner = THIS_MODULE, | ||
141 | .of_match_table = of_gpio_restart_match, | ||
142 | }, | ||
143 | }; | ||
144 | |||
145 | module_platform_driver(gpio_restart_driver); | ||
146 | |||
147 | MODULE_AUTHOR("David Riley <davidriley@chromium.org>"); | ||
148 | MODULE_DESCRIPTION("GPIO restart driver"); | ||
149 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/power/reset/ltc2952-poweroff.c b/drivers/power/reset/ltc2952-poweroff.c new file mode 100644 index 000000000000..116a1cef8f7b --- /dev/null +++ b/drivers/power/reset/ltc2952-poweroff.c | |||
@@ -0,0 +1,386 @@ | |||
1 | /* | ||
2 | * LTC2952 (PowerPath) driver | ||
3 | * | ||
4 | * Copyright (C) 2014, Xsens Technologies BV <info@xsens.com> | ||
5 | * Maintainer: René Moll <linux@r-moll.nl> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * as published by the Free Software Foundation; either version 2 | ||
10 | * of the License, or (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * ---------------------------------------- | ||
18 | * - Description | ||
19 | * ---------------------------------------- | ||
20 | * | ||
21 | * This driver is to be used with an external PowerPath Controller (LTC2952). | ||
22 | * Its function is to determine when a external shut down is triggered | ||
23 | * and react by properly shutting down the system. | ||
24 | * | ||
25 | * This driver expects a device tree with a ltc2952 entry for pin mapping. | ||
26 | * | ||
27 | * ---------------------------------------- | ||
28 | * - GPIO | ||
29 | * ---------------------------------------- | ||
30 | * | ||
31 | * The following GPIOs are used: | ||
32 | * - trigger (input) | ||
33 | * A level change indicates the shut-down trigger. If it's state reverts | ||
34 | * within the time-out defined by trigger_delay, the shut down is not | ||
35 | * executed. | ||
36 | * | ||
37 | * - watchdog (output) | ||
38 | * Once a shut down is triggered, the driver will toggle this signal, | ||
39 | * with an internal (wde_interval) to stall the hardware shut down. | ||
40 | * | ||
41 | * - kill (output) | ||
42 | * The last action during shut down is triggering this signalling, such | ||
43 | * that the PowerPath Control will power down the hardware. | ||
44 | * | ||
45 | * ---------------------------------------- | ||
46 | * - Interrupts | ||
47 | * ---------------------------------------- | ||
48 | * | ||
49 | * The driver requires a non-shared, edge-triggered interrupt on the trigger | ||
50 | * GPIO. | ||
51 | * | ||
52 | */ | ||
53 | |||
54 | #include <linux/kernel.h> | ||
55 | #include <linux/init.h> | ||
56 | #include <linux/interrupt.h> | ||
57 | #include <linux/device.h> | ||
58 | #include <linux/platform_device.h> | ||
59 | #include <linux/ktime.h> | ||
60 | #include <linux/slab.h> | ||
61 | #include <linux/kmod.h> | ||
62 | #include <linux/module.h> | ||
63 | #include <linux/gpio/consumer.h> | ||
64 | #include <linux/reboot.h> | ||
65 | |||
66 | struct ltc2952_poweroff_data { | ||
67 | struct hrtimer timer_trigger; | ||
68 | struct hrtimer timer_wde; | ||
69 | |||
70 | ktime_t trigger_delay; | ||
71 | ktime_t wde_interval; | ||
72 | |||
73 | struct device *dev; | ||
74 | |||
75 | unsigned int virq; | ||
76 | |||
77 | /** | ||
78 | * 0: trigger | ||
79 | * 1: watchdog | ||
80 | * 2: kill | ||
81 | */ | ||
82 | struct gpio_desc *gpio[3]; | ||
83 | }; | ||
84 | |||
85 | static int ltc2952_poweroff_panic; | ||
86 | static struct ltc2952_poweroff_data *ltc2952_data; | ||
87 | |||
88 | #define POWERPATH_IO_TRIGGER 0 | ||
89 | #define POWERPATH_IO_WATCHDOG 1 | ||
90 | #define POWERPATH_IO_KILL 2 | ||
91 | |||
92 | /** | ||
93 | * ltc2952_poweroff_timer_wde - Timer callback | ||
94 | * Toggles the watchdog reset signal each wde_interval | ||
95 | * | ||
96 | * @timer: corresponding timer | ||
97 | * | ||
98 | * Returns HRTIMER_RESTART for an infinite loop which will only stop when the | ||
99 | * machine actually shuts down | ||
100 | */ | ||
101 | static enum hrtimer_restart ltc2952_poweroff_timer_wde(struct hrtimer *timer) | ||
102 | { | ||
103 | ktime_t now; | ||
104 | int state; | ||
105 | unsigned long overruns; | ||
106 | |||
107 | if (ltc2952_poweroff_panic) | ||
108 | return HRTIMER_NORESTART; | ||
109 | |||
110 | state = gpiod_get_value(ltc2952_data->gpio[POWERPATH_IO_WATCHDOG]); | ||
111 | gpiod_set_value(ltc2952_data->gpio[POWERPATH_IO_WATCHDOG], !state); | ||
112 | |||
113 | now = hrtimer_cb_get_time(timer); | ||
114 | overruns = hrtimer_forward(timer, now, ltc2952_data->wde_interval); | ||
115 | |||
116 | return HRTIMER_RESTART; | ||
117 | } | ||
118 | |||
119 | static enum hrtimer_restart ltc2952_poweroff_timer_trigger( | ||
120 | struct hrtimer *timer) | ||
121 | { | ||
122 | int ret; | ||
123 | |||
124 | ret = hrtimer_start(<c2952_data->timer_wde, | ||
125 | ltc2952_data->wde_interval, HRTIMER_MODE_REL); | ||
126 | |||
127 | if (ret) { | ||
128 | dev_err(ltc2952_data->dev, "unable to start the timer\n"); | ||
129 | /* | ||
130 | * The device will not toggle the watchdog reset, | ||
131 | * thus shut down is only safe if the PowerPath controller | ||
132 | * has a long enough time-off before triggering a hardware | ||
133 | * power-off. | ||
134 | * | ||
135 | * Only sending a warning as the system will power-off anyway | ||
136 | */ | ||
137 | } | ||
138 | |||
139 | dev_info(ltc2952_data->dev, "executing shutdown\n"); | ||
140 | |||
141 | orderly_poweroff(true); | ||
142 | |||
143 | return HRTIMER_NORESTART; | ||
144 | } | ||
145 | |||
146 | /** | ||
147 | * ltc2952_poweroff_handler - Interrupt handler | ||
148 | * Triggered each time the trigger signal changes state and (de)activates a | ||
149 | * time-out (timer_trigger). Once the time-out is actually reached the shut | ||
150 | * down is executed. | ||
151 | * | ||
152 | * @irq: IRQ number | ||
153 | * @dev_id: pointer to the main data structure | ||
154 | */ | ||
155 | static irqreturn_t ltc2952_poweroff_handler(int irq, void *dev_id) | ||
156 | { | ||
157 | int ret; | ||
158 | struct ltc2952_poweroff_data *data = dev_id; | ||
159 | |||
160 | if (ltc2952_poweroff_panic) | ||
161 | goto irq_ok; | ||
162 | |||
163 | if (hrtimer_active(&data->timer_wde)) { | ||
164 | /* shutdown is already triggered, nothing to do any more */ | ||
165 | goto irq_ok; | ||
166 | } | ||
167 | |||
168 | if (!hrtimer_active(&data->timer_trigger)) { | ||
169 | ret = hrtimer_start(&data->timer_trigger, data->trigger_delay, | ||
170 | HRTIMER_MODE_REL); | ||
171 | |||
172 | if (ret) | ||
173 | dev_err(data->dev, "unable to start the wait timer\n"); | ||
174 | } else { | ||
175 | ret = hrtimer_cancel(&data->timer_trigger); | ||
176 | /* omitting return value check, timer should have been valid */ | ||
177 | } | ||
178 | |||
179 | irq_ok: | ||
180 | return IRQ_HANDLED; | ||
181 | } | ||
182 | |||
183 | static void ltc2952_poweroff_kill(void) | ||
184 | { | ||
185 | gpiod_set_value(ltc2952_data->gpio[POWERPATH_IO_KILL], 1); | ||
186 | } | ||
187 | |||
188 | static int ltc2952_poweroff_suspend(struct platform_device *pdev, | ||
189 | pm_message_t state) | ||
190 | { | ||
191 | return -ENOSYS; | ||
192 | } | ||
193 | |||
194 | static int ltc2952_poweroff_resume(struct platform_device *pdev) | ||
195 | { | ||
196 | return -ENOSYS; | ||
197 | } | ||
198 | |||
199 | static void ltc2952_poweroff_default(struct ltc2952_poweroff_data *data) | ||
200 | { | ||
201 | unsigned int i; | ||
202 | |||
203 | for (i = 0; i < ARRAY_SIZE(data->gpio); i++) | ||
204 | data->gpio[i] = NULL; | ||
205 | |||
206 | data->wde_interval = ktime_set(0, 300L*1E6L); | ||
207 | data->trigger_delay = ktime_set(2, 500L*1E6L); | ||
208 | |||
209 | hrtimer_init(&data->timer_trigger, CLOCK_MONOTONIC, HRTIMER_MODE_REL); | ||
210 | data->timer_trigger.function = <c2952_poweroff_timer_trigger; | ||
211 | |||
212 | hrtimer_init(&data->timer_wde, CLOCK_MONOTONIC, HRTIMER_MODE_REL); | ||
213 | data->timer_wde.function = <c2952_poweroff_timer_wde; | ||
214 | } | ||
215 | |||
216 | static int ltc2952_poweroff_init(struct platform_device *pdev) | ||
217 | { | ||
218 | int ret, virq; | ||
219 | unsigned int i; | ||
220 | struct ltc2952_poweroff_data *data; | ||
221 | |||
222 | static char *name[] = { | ||
223 | "trigger", | ||
224 | "watchdog", | ||
225 | "kill", | ||
226 | NULL | ||
227 | }; | ||
228 | |||
229 | data = ltc2952_data; | ||
230 | ltc2952_poweroff_default(ltc2952_data); | ||
231 | |||
232 | for (i = 0; i < ARRAY_SIZE(ltc2952_data->gpio); i++) { | ||
233 | ltc2952_data->gpio[i] = gpiod_get(&pdev->dev, name[i]); | ||
234 | |||
235 | if (IS_ERR(ltc2952_data->gpio[i])) { | ||
236 | ret = PTR_ERR(ltc2952_data->gpio[i]); | ||
237 | dev_err(&pdev->dev, | ||
238 | "unable to claim the following gpio: %s\n", | ||
239 | name[i]); | ||
240 | goto err_io; | ||
241 | } | ||
242 | } | ||
243 | |||
244 | ret = gpiod_direction_output( | ||
245 | ltc2952_data->gpio[POWERPATH_IO_WATCHDOG], 0); | ||
246 | if (ret) { | ||
247 | dev_err(&pdev->dev, "unable to use watchdog-gpio as output\n"); | ||
248 | goto err_io; | ||
249 | } | ||
250 | |||
251 | ret = gpiod_direction_output(ltc2952_data->gpio[POWERPATH_IO_KILL], 0); | ||
252 | if (ret) { | ||
253 | dev_err(&pdev->dev, "unable to use kill-gpio as output\n"); | ||
254 | goto err_io; | ||
255 | } | ||
256 | |||
257 | virq = gpiod_to_irq(ltc2952_data->gpio[POWERPATH_IO_TRIGGER]); | ||
258 | if (virq < 0) { | ||
259 | dev_err(&pdev->dev, "cannot map GPIO as interrupt"); | ||
260 | goto err_io; | ||
261 | } | ||
262 | |||
263 | ltc2952_data->virq = virq; | ||
264 | ret = request_irq(virq, | ||
265 | ltc2952_poweroff_handler, | ||
266 | (IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING), | ||
267 | "ltc2952-poweroff", | ||
268 | ltc2952_data | ||
269 | ); | ||
270 | |||
271 | if (ret) { | ||
272 | dev_err(&pdev->dev, "cannot configure an interrupt handler\n"); | ||
273 | goto err_io; | ||
274 | } | ||
275 | |||
276 | return 0; | ||
277 | |||
278 | err_io: | ||
279 | for (i = 0; i < ARRAY_SIZE(ltc2952_data->gpio); i++) | ||
280 | if (ltc2952_data->gpio[i]) | ||
281 | gpiod_put(ltc2952_data->gpio[i]); | ||
282 | |||
283 | return ret; | ||
284 | } | ||
285 | |||
286 | static int ltc2952_poweroff_probe(struct platform_device *pdev) | ||
287 | { | ||
288 | int ret; | ||
289 | |||
290 | if (pm_power_off) { | ||
291 | dev_err(&pdev->dev, "pm_power_off already registered"); | ||
292 | return -EBUSY; | ||
293 | } | ||
294 | |||
295 | ltc2952_data = kzalloc(sizeof(*ltc2952_data), GFP_KERNEL); | ||
296 | if (!ltc2952_data) | ||
297 | return -ENOMEM; | ||
298 | |||
299 | ltc2952_data->dev = &pdev->dev; | ||
300 | |||
301 | ret = ltc2952_poweroff_init(pdev); | ||
302 | if (ret) | ||
303 | goto err; | ||
304 | |||
305 | pm_power_off = <c2952_poweroff_kill; | ||
306 | |||
307 | dev_info(&pdev->dev, "probe successful\n"); | ||
308 | |||
309 | return 0; | ||
310 | |||
311 | err: | ||
312 | kfree(ltc2952_data); | ||
313 | return ret; | ||
314 | } | ||
315 | |||
316 | static int ltc2952_poweroff_remove(struct platform_device *pdev) | ||
317 | { | ||
318 | unsigned int i; | ||
319 | |||
320 | pm_power_off = NULL; | ||
321 | |||
322 | if (ltc2952_data) { | ||
323 | free_irq(ltc2952_data->virq, ltc2952_data); | ||
324 | |||
325 | for (i = 0; i < ARRAY_SIZE(ltc2952_data->gpio); i++) | ||
326 | gpiod_put(ltc2952_data->gpio[i]); | ||
327 | |||
328 | kfree(ltc2952_data); | ||
329 | } | ||
330 | |||
331 | return 0; | ||
332 | } | ||
333 | |||
334 | static const struct of_device_id of_ltc2952_poweroff_match[] = { | ||
335 | { .compatible = "lltc,ltc2952"}, | ||
336 | {}, | ||
337 | }; | ||
338 | MODULE_DEVICE_TABLE(of, of_ltc2952_poweroff_match); | ||
339 | |||
340 | static struct platform_driver ltc2952_poweroff_driver = { | ||
341 | .probe = ltc2952_poweroff_probe, | ||
342 | .remove = ltc2952_poweroff_remove, | ||
343 | .driver = { | ||
344 | .name = "ltc2952-poweroff", | ||
345 | .owner = THIS_MODULE, | ||
346 | .of_match_table = of_ltc2952_poweroff_match, | ||
347 | }, | ||
348 | .suspend = ltc2952_poweroff_suspend, | ||
349 | .resume = ltc2952_poweroff_resume, | ||
350 | }; | ||
351 | |||
352 | static int ltc2952_poweroff_notify_panic(struct notifier_block *nb, | ||
353 | unsigned long code, void *unused) | ||
354 | { | ||
355 | ltc2952_poweroff_panic = 1; | ||
356 | return NOTIFY_DONE; | ||
357 | } | ||
358 | |||
359 | static struct notifier_block ltc2952_poweroff_panic_nb = { | ||
360 | .notifier_call = ltc2952_poweroff_notify_panic, | ||
361 | }; | ||
362 | |||
363 | static int __init ltc2952_poweroff_platform_init(void) | ||
364 | { | ||
365 | ltc2952_poweroff_panic = 0; | ||
366 | |||
367 | atomic_notifier_chain_register(&panic_notifier_list, | ||
368 | <c2952_poweroff_panic_nb); | ||
369 | |||
370 | return platform_driver_register(<c2952_poweroff_driver); | ||
371 | } | ||
372 | |||
373 | static void __exit ltc2952_poweroff_platform_exit(void) | ||
374 | { | ||
375 | atomic_notifier_chain_unregister(&panic_notifier_list, | ||
376 | <c2952_poweroff_panic_nb); | ||
377 | |||
378 | platform_driver_unregister(<c2952_poweroff_driver); | ||
379 | } | ||
380 | |||
381 | module_init(ltc2952_poweroff_platform_init); | ||
382 | module_exit(ltc2952_poweroff_platform_exit); | ||
383 | |||
384 | MODULE_AUTHOR("René Moll <rene.moll@xsens.com>"); | ||
385 | MODULE_DESCRIPTION("LTC PowerPath power-off driver"); | ||
386 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/power/reset/msm-poweroff.c b/drivers/power/reset/msm-poweroff.c index 774f9a3b310d..4702efdfe466 100644 --- a/drivers/power/reset/msm-poweroff.c +++ b/drivers/power/reset/msm-poweroff.c | |||
@@ -20,21 +20,27 @@ | |||
20 | #include <linux/platform_device.h> | 20 | #include <linux/platform_device.h> |
21 | #include <linux/module.h> | 21 | #include <linux/module.h> |
22 | #include <linux/reboot.h> | 22 | #include <linux/reboot.h> |
23 | 23 | #include <linux/pm.h> | |
24 | #include <asm/system_misc.h> | ||
25 | 24 | ||
26 | static void __iomem *msm_ps_hold; | 25 | static void __iomem *msm_ps_hold; |
27 | 26 | static int do_msm_restart(struct notifier_block *nb, unsigned long action, | |
28 | static void do_msm_restart(enum reboot_mode reboot_mode, const char *cmd) | 27 | void *data) |
29 | { | 28 | { |
30 | writel(0, msm_ps_hold); | 29 | writel(0, msm_ps_hold); |
31 | mdelay(10000); | 30 | mdelay(10000); |
31 | |||
32 | return NOTIFY_DONE; | ||
32 | } | 33 | } |
33 | 34 | ||
35 | static struct notifier_block restart_nb = { | ||
36 | .notifier_call = do_msm_restart, | ||
37 | .priority = 128, | ||
38 | }; | ||
39 | |||
34 | static void do_msm_poweroff(void) | 40 | static void do_msm_poweroff(void) |
35 | { | 41 | { |
36 | /* TODO: Add poweroff capability */ | 42 | /* TODO: Add poweroff capability */ |
37 | do_msm_restart(REBOOT_HARD, NULL); | 43 | do_msm_restart(&restart_nb, 0, NULL); |
38 | } | 44 | } |
39 | 45 | ||
40 | static int msm_restart_probe(struct platform_device *pdev) | 46 | static int msm_restart_probe(struct platform_device *pdev) |
@@ -47,8 +53,10 @@ static int msm_restart_probe(struct platform_device *pdev) | |||
47 | if (IS_ERR(msm_ps_hold)) | 53 | if (IS_ERR(msm_ps_hold)) |
48 | return PTR_ERR(msm_ps_hold); | 54 | return PTR_ERR(msm_ps_hold); |
49 | 55 | ||
56 | register_restart_handler(&restart_nb); | ||
57 | |||
50 | pm_power_off = do_msm_poweroff; | 58 | pm_power_off = do_msm_poweroff; |
51 | arm_pm_restart = do_msm_restart; | 59 | |
52 | return 0; | 60 | return 0; |
53 | } | 61 | } |
54 | 62 | ||
diff --git a/drivers/power/reset/st-poweroff.c b/drivers/power/reset/st-poweroff.c new file mode 100644 index 000000000000..a0acf25ee2a2 --- /dev/null +++ b/drivers/power/reset/st-poweroff.c | |||
@@ -0,0 +1,151 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014 STMicroelectronics | ||
3 | * | ||
4 | * Power off Restart driver, used in STMicroelectronics devices. | ||
5 | * | ||
6 | * Author: Christophe Kerello <christophe.kerello@st.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2, as | ||
10 | * published by the Free Software Foundation. | ||
11 | */ | ||
12 | |||
13 | #include <linux/module.h> | ||
14 | #include <linux/of.h> | ||
15 | #include <linux/of_platform.h> | ||
16 | #include <linux/platform_device.h> | ||
17 | #include <linux/mfd/syscon.h> | ||
18 | #include <linux/regmap.h> | ||
19 | |||
20 | #include <asm/system_misc.h> | ||
21 | |||
22 | struct reset_syscfg { | ||
23 | struct regmap *regmap; | ||
24 | /* syscfg used for reset */ | ||
25 | unsigned int offset_rst; | ||
26 | unsigned int mask_rst; | ||
27 | /* syscfg used for unmask the reset */ | ||
28 | unsigned int offset_rst_msk; | ||
29 | unsigned int mask_rst_msk; | ||
30 | }; | ||
31 | |||
32 | /* STiH415 */ | ||
33 | #define STIH415_SYSCFG_11 0x2c | ||
34 | #define STIH415_SYSCFG_15 0x3c | ||
35 | |||
36 | static struct reset_syscfg stih415_reset = { | ||
37 | .offset_rst = STIH415_SYSCFG_11, | ||
38 | .mask_rst = BIT(0), | ||
39 | .offset_rst_msk = STIH415_SYSCFG_15, | ||
40 | .mask_rst_msk = BIT(0) | ||
41 | }; | ||
42 | |||
43 | /* STiH416 */ | ||
44 | #define STIH416_SYSCFG_500 0x7d0 | ||
45 | #define STIH416_SYSCFG_504 0x7e0 | ||
46 | |||
47 | static struct reset_syscfg stih416_reset = { | ||
48 | .offset_rst = STIH416_SYSCFG_500, | ||
49 | .mask_rst = BIT(0), | ||
50 | .offset_rst_msk = STIH416_SYSCFG_504, | ||
51 | .mask_rst_msk = BIT(0) | ||
52 | }; | ||
53 | |||
54 | /* STiH407 */ | ||
55 | #define STIH407_SYSCFG_4000 0x0 | ||
56 | #define STIH407_SYSCFG_4008 0x20 | ||
57 | |||
58 | static struct reset_syscfg stih407_reset = { | ||
59 | .offset_rst = STIH407_SYSCFG_4000, | ||
60 | .mask_rst = BIT(0), | ||
61 | .offset_rst_msk = STIH407_SYSCFG_4008, | ||
62 | .mask_rst_msk = BIT(0) | ||
63 | }; | ||
64 | |||
65 | /* STiD127 */ | ||
66 | #define STID127_SYSCFG_700 0x0 | ||
67 | #define STID127_SYSCFG_773 0x124 | ||
68 | |||
69 | static struct reset_syscfg stid127_reset = { | ||
70 | .offset_rst = STID127_SYSCFG_773, | ||
71 | .mask_rst = BIT(0), | ||
72 | .offset_rst_msk = STID127_SYSCFG_700, | ||
73 | .mask_rst_msk = BIT(8) | ||
74 | }; | ||
75 | |||
76 | static struct reset_syscfg *st_restart_syscfg; | ||
77 | |||
78 | static void st_restart(enum reboot_mode reboot_mode, const char *cmd) | ||
79 | { | ||
80 | /* reset syscfg updated */ | ||
81 | regmap_update_bits(st_restart_syscfg->regmap, | ||
82 | st_restart_syscfg->offset_rst, | ||
83 | st_restart_syscfg->mask_rst, | ||
84 | 0); | ||
85 | |||
86 | /* unmask the reset */ | ||
87 | regmap_update_bits(st_restart_syscfg->regmap, | ||
88 | st_restart_syscfg->offset_rst_msk, | ||
89 | st_restart_syscfg->mask_rst_msk, | ||
90 | 0); | ||
91 | } | ||
92 | |||
93 | static struct of_device_id st_reset_of_match[] = { | ||
94 | { | ||
95 | .compatible = "st,stih415-restart", | ||
96 | .data = (void *)&stih415_reset, | ||
97 | }, { | ||
98 | .compatible = "st,stih416-restart", | ||
99 | .data = (void *)&stih416_reset, | ||
100 | }, { | ||
101 | .compatible = "st,stih407-restart", | ||
102 | .data = (void *)&stih407_reset, | ||
103 | }, { | ||
104 | .compatible = "st,stid127-restart", | ||
105 | .data = (void *)&stid127_reset, | ||
106 | }, | ||
107 | {} | ||
108 | }; | ||
109 | |||
110 | static int st_reset_probe(struct platform_device *pdev) | ||
111 | { | ||
112 | struct device_node *np = pdev->dev.of_node; | ||
113 | const struct of_device_id *match; | ||
114 | struct device *dev = &pdev->dev; | ||
115 | |||
116 | match = of_match_device(st_reset_of_match, dev); | ||
117 | if (!match) | ||
118 | return -ENODEV; | ||
119 | |||
120 | st_restart_syscfg = (struct reset_syscfg *)match->data; | ||
121 | |||
122 | st_restart_syscfg->regmap = | ||
123 | syscon_regmap_lookup_by_phandle(np, "st,syscfg"); | ||
124 | if (IS_ERR(st_restart_syscfg->regmap)) { | ||
125 | dev_err(dev, "No syscfg phandle specified\n"); | ||
126 | return PTR_ERR(st_restart_syscfg->regmap); | ||
127 | } | ||
128 | |||
129 | arm_pm_restart = st_restart; | ||
130 | |||
131 | return 0; | ||
132 | } | ||
133 | |||
134 | static struct platform_driver st_reset_driver = { | ||
135 | .probe = st_reset_probe, | ||
136 | .driver = { | ||
137 | .name = "st_reset", | ||
138 | .of_match_table = st_reset_of_match, | ||
139 | }, | ||
140 | }; | ||
141 | |||
142 | static int __init st_reset_init(void) | ||
143 | { | ||
144 | return platform_driver_register(&st_reset_driver); | ||
145 | } | ||
146 | |||
147 | device_initcall(st_reset_init); | ||
148 | |||
149 | MODULE_AUTHOR("Christophe Kerello <christophe.kerello@st.com>"); | ||
150 | MODULE_DESCRIPTION("STMicroelectronics Power off Restart driver"); | ||
151 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/power/reset/syscon-reboot.c b/drivers/power/reset/syscon-reboot.c new file mode 100644 index 000000000000..815b901822cf --- /dev/null +++ b/drivers/power/reset/syscon-reboot.c | |||
@@ -0,0 +1,91 @@ | |||
1 | /* | ||
2 | * Generic Syscon Reboot Driver | ||
3 | * | ||
4 | * Copyright (c) 2013, Applied Micro Circuits Corporation | ||
5 | * Author: Feng Kan <fkan@apm.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License as | ||
9 | * published by the Free Software Foundation; either version 2 of | ||
10 | * the License, or (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | */ | ||
17 | #include <linux/delay.h> | ||
18 | #include <linux/io.h> | ||
19 | #include <linux/notifier.h> | ||
20 | #include <linux/mfd/syscon.h> | ||
21 | #include <linux/of_address.h> | ||
22 | #include <linux/of_device.h> | ||
23 | #include <linux/platform_device.h> | ||
24 | #include <linux/reboot.h> | ||
25 | #include <linux/regmap.h> | ||
26 | |||
27 | struct syscon_reboot_context { | ||
28 | struct regmap *map; | ||
29 | u32 offset; | ||
30 | u32 mask; | ||
31 | struct notifier_block restart_handler; | ||
32 | }; | ||
33 | |||
34 | static int syscon_restart_handle(struct notifier_block *this, | ||
35 | unsigned long mode, void *cmd) | ||
36 | { | ||
37 | struct syscon_reboot_context *ctx = | ||
38 | container_of(this, struct syscon_reboot_context, | ||
39 | restart_handler); | ||
40 | |||
41 | /* Issue the reboot */ | ||
42 | regmap_write(ctx->map, ctx->offset, ctx->mask); | ||
43 | |||
44 | mdelay(1000); | ||
45 | |||
46 | pr_emerg("Unable to restart system\n"); | ||
47 | return NOTIFY_DONE; | ||
48 | } | ||
49 | |||
50 | static int syscon_reboot_probe(struct platform_device *pdev) | ||
51 | { | ||
52 | struct syscon_reboot_context *ctx; | ||
53 | struct device *dev = &pdev->dev; | ||
54 | int err; | ||
55 | |||
56 | ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); | ||
57 | if (!ctx) | ||
58 | return -ENOMEM; | ||
59 | |||
60 | ctx->map = syscon_regmap_lookup_by_phandle(dev->of_node, "regmap"); | ||
61 | if (IS_ERR(ctx->map)) | ||
62 | return PTR_ERR(ctx->map); | ||
63 | |||
64 | if (of_property_read_u32(pdev->dev.of_node, "offset", &ctx->offset)) | ||
65 | return -EINVAL; | ||
66 | |||
67 | if (of_property_read_u32(pdev->dev.of_node, "mask", &ctx->mask)) | ||
68 | return -EINVAL; | ||
69 | |||
70 | ctx->restart_handler.notifier_call = syscon_restart_handle; | ||
71 | ctx->restart_handler.priority = 128; | ||
72 | err = register_restart_handler(&ctx->restart_handler); | ||
73 | if (err) | ||
74 | dev_err(dev, "can't register restart notifier (err=%d)\n", err); | ||
75 | |||
76 | return err; | ||
77 | } | ||
78 | |||
79 | static struct of_device_id syscon_reboot_of_match[] = { | ||
80 | { .compatible = "syscon-reboot" }, | ||
81 | {} | ||
82 | }; | ||
83 | |||
84 | static struct platform_driver syscon_reboot_driver = { | ||
85 | .probe = syscon_reboot_probe, | ||
86 | .driver = { | ||
87 | .name = "syscon-reboot", | ||
88 | .of_match_table = syscon_reboot_of_match, | ||
89 | }, | ||
90 | }; | ||
91 | module_platform_driver(syscon_reboot_driver); | ||
diff --git a/drivers/power/reset/xgene-reboot.c b/drivers/power/reset/xgene-reboot.c index ecd55f81b9d1..6b49be6867ab 100644 --- a/drivers/power/reset/xgene-reboot.c +++ b/drivers/power/reset/xgene-reboot.c | |||
@@ -40,7 +40,7 @@ struct xgene_reboot_context { | |||
40 | 40 | ||
41 | static struct xgene_reboot_context *xgene_restart_ctx; | 41 | static struct xgene_reboot_context *xgene_restart_ctx; |
42 | 42 | ||
43 | static void xgene_restart(char str, const char *cmd) | 43 | static void xgene_restart(enum reboot_mode mode, const char *cmd) |
44 | { | 44 | { |
45 | struct xgene_reboot_context *ctx = xgene_restart_ctx; | 45 | struct xgene_reboot_context *ctx = xgene_restart_ctx; |
46 | unsigned long timeout; | 46 | unsigned long timeout; |
diff --git a/drivers/power/sbs-battery.c b/drivers/power/sbs-battery.c index b5f2a76b6cdf..c7b7b4018df3 100644 --- a/drivers/power/sbs-battery.c +++ b/drivers/power/sbs-battery.c | |||
@@ -48,7 +48,10 @@ enum { | |||
48 | REG_FULL_CHARGE_CAPACITY_CHARGE, | 48 | REG_FULL_CHARGE_CAPACITY_CHARGE, |
49 | REG_DESIGN_CAPACITY, | 49 | REG_DESIGN_CAPACITY, |
50 | REG_DESIGN_CAPACITY_CHARGE, | 50 | REG_DESIGN_CAPACITY_CHARGE, |
51 | REG_DESIGN_VOLTAGE, | 51 | REG_DESIGN_VOLTAGE_MIN, |
52 | REG_DESIGN_VOLTAGE_MAX, | ||
53 | REG_MANUFACTURER, | ||
54 | REG_MODEL_NAME, | ||
52 | }; | 55 | }; |
53 | 56 | ||
54 | /* Battery Mode defines */ | 57 | /* Battery Mode defines */ |
@@ -68,6 +71,7 @@ enum sbs_battery_mode { | |||
68 | #define BATTERY_FULL_CHARGED 0x20 | 71 | #define BATTERY_FULL_CHARGED 0x20 |
69 | #define BATTERY_FULL_DISCHARGED 0x10 | 72 | #define BATTERY_FULL_DISCHARGED 0x10 |
70 | 73 | ||
74 | /* min_value and max_value are only valid for numerical data */ | ||
71 | #define SBS_DATA(_psp, _addr, _min_value, _max_value) { \ | 75 | #define SBS_DATA(_psp, _addr, _min_value, _max_value) { \ |
72 | .psp = _psp, \ | 76 | .psp = _psp, \ |
73 | .addr = _addr, \ | 77 | .addr = _addr, \ |
@@ -111,10 +115,17 @@ static const struct chip_data { | |||
111 | SBS_DATA(POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, 0x18, 0, 65535), | 115 | SBS_DATA(POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, 0x18, 0, 65535), |
112 | [REG_DESIGN_CAPACITY_CHARGE] = | 116 | [REG_DESIGN_CAPACITY_CHARGE] = |
113 | SBS_DATA(POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, 0x18, 0, 65535), | 117 | SBS_DATA(POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, 0x18, 0, 65535), |
114 | [REG_DESIGN_VOLTAGE] = | 118 | [REG_DESIGN_VOLTAGE_MIN] = |
119 | SBS_DATA(POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, 0x19, 0, 65535), | ||
120 | [REG_DESIGN_VOLTAGE_MAX] = | ||
115 | SBS_DATA(POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, 0x19, 0, 65535), | 121 | SBS_DATA(POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, 0x19, 0, 65535), |
116 | [REG_SERIAL_NUMBER] = | 122 | [REG_SERIAL_NUMBER] = |
117 | SBS_DATA(POWER_SUPPLY_PROP_SERIAL_NUMBER, 0x1C, 0, 65535), | 123 | SBS_DATA(POWER_SUPPLY_PROP_SERIAL_NUMBER, 0x1C, 0, 65535), |
124 | /* Properties of type `const char *' */ | ||
125 | [REG_MANUFACTURER] = | ||
126 | SBS_DATA(POWER_SUPPLY_PROP_MANUFACTURER, 0x20, 0, 65535), | ||
127 | [REG_MODEL_NAME] = | ||
128 | SBS_DATA(POWER_SUPPLY_PROP_MODEL_NAME, 0x21, 0, 65535) | ||
118 | }; | 129 | }; |
119 | 130 | ||
120 | static enum power_supply_property sbs_properties[] = { | 131 | static enum power_supply_property sbs_properties[] = { |
@@ -130,6 +141,7 @@ static enum power_supply_property sbs_properties[] = { | |||
130 | POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, | 141 | POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, |
131 | POWER_SUPPLY_PROP_TIME_TO_FULL_AVG, | 142 | POWER_SUPPLY_PROP_TIME_TO_FULL_AVG, |
132 | POWER_SUPPLY_PROP_SERIAL_NUMBER, | 143 | POWER_SUPPLY_PROP_SERIAL_NUMBER, |
144 | POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, | ||
133 | POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, | 145 | POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, |
134 | POWER_SUPPLY_PROP_ENERGY_NOW, | 146 | POWER_SUPPLY_PROP_ENERGY_NOW, |
135 | POWER_SUPPLY_PROP_ENERGY_FULL, | 147 | POWER_SUPPLY_PROP_ENERGY_FULL, |
@@ -137,6 +149,9 @@ static enum power_supply_property sbs_properties[] = { | |||
137 | POWER_SUPPLY_PROP_CHARGE_NOW, | 149 | POWER_SUPPLY_PROP_CHARGE_NOW, |
138 | POWER_SUPPLY_PROP_CHARGE_FULL, | 150 | POWER_SUPPLY_PROP_CHARGE_FULL, |
139 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, | 151 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, |
152 | /* Properties of type `const char *' */ | ||
153 | POWER_SUPPLY_PROP_MANUFACTURER, | ||
154 | POWER_SUPPLY_PROP_MODEL_NAME | ||
140 | }; | 155 | }; |
141 | 156 | ||
142 | struct sbs_info { | 157 | struct sbs_info { |
@@ -153,6 +168,9 @@ struct sbs_info { | |||
153 | int ignore_changes; | 168 | int ignore_changes; |
154 | }; | 169 | }; |
155 | 170 | ||
171 | static char model_name[I2C_SMBUS_BLOCK_MAX + 1]; | ||
172 | static char manufacturer[I2C_SMBUS_BLOCK_MAX + 1]; | ||
173 | |||
156 | static int sbs_read_word_data(struct i2c_client *client, u8 address) | 174 | static int sbs_read_word_data(struct i2c_client *client, u8 address) |
157 | { | 175 | { |
158 | struct sbs_info *chip = i2c_get_clientdata(client); | 176 | struct sbs_info *chip = i2c_get_clientdata(client); |
@@ -179,6 +197,74 @@ static int sbs_read_word_data(struct i2c_client *client, u8 address) | |||
179 | return le16_to_cpu(ret); | 197 | return le16_to_cpu(ret); |
180 | } | 198 | } |
181 | 199 | ||
200 | static int sbs_read_string_data(struct i2c_client *client, u8 address, | ||
201 | char *values) | ||
202 | { | ||
203 | struct sbs_info *chip = i2c_get_clientdata(client); | ||
204 | s32 ret = 0, block_length = 0; | ||
205 | int retries_length = 1, retries_block = 1; | ||
206 | u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1]; | ||
207 | |||
208 | if (chip->pdata) { | ||
209 | retries_length = max(chip->pdata->i2c_retry_count + 1, 1); | ||
210 | retries_block = max(chip->pdata->i2c_retry_count + 1, 1); | ||
211 | } | ||
212 | |||
213 | /* Adapter needs to support these two functions */ | ||
214 | if (!i2c_check_functionality(client->adapter, | ||
215 | I2C_FUNC_SMBUS_BYTE_DATA | | ||
216 | I2C_FUNC_SMBUS_I2C_BLOCK)){ | ||
217 | return -ENODEV; | ||
218 | } | ||
219 | |||
220 | /* Get the length of block data */ | ||
221 | while (retries_length > 0) { | ||
222 | ret = i2c_smbus_read_byte_data(client, address); | ||
223 | if (ret >= 0) | ||
224 | break; | ||
225 | retries_length--; | ||
226 | } | ||
227 | |||
228 | if (ret < 0) { | ||
229 | dev_dbg(&client->dev, | ||
230 | "%s: i2c read at address 0x%x failed\n", | ||
231 | __func__, address); | ||
232 | return ret; | ||
233 | } | ||
234 | |||
235 | /* block_length does not include NULL terminator */ | ||
236 | block_length = ret; | ||
237 | if (block_length > I2C_SMBUS_BLOCK_MAX) { | ||
238 | dev_err(&client->dev, | ||
239 | "%s: Returned block_length is longer than 0x%x\n", | ||
240 | __func__, I2C_SMBUS_BLOCK_MAX); | ||
241 | return -EINVAL; | ||
242 | } | ||
243 | |||
244 | /* Get the block data */ | ||
245 | while (retries_block > 0) { | ||
246 | ret = i2c_smbus_read_i2c_block_data( | ||
247 | client, address, | ||
248 | block_length + 1, block_buffer); | ||
249 | if (ret >= 0) | ||
250 | break; | ||
251 | retries_block--; | ||
252 | } | ||
253 | |||
254 | if (ret < 0) { | ||
255 | dev_dbg(&client->dev, | ||
256 | "%s: i2c read at address 0x%x failed\n", | ||
257 | __func__, address); | ||
258 | return ret; | ||
259 | } | ||
260 | |||
261 | /* block_buffer[0] == block_length */ | ||
262 | memcpy(values, block_buffer + 1, block_length); | ||
263 | values[block_length] = '\0'; | ||
264 | |||
265 | return le16_to_cpu(ret); | ||
266 | } | ||
267 | |||
182 | static int sbs_write_word_data(struct i2c_client *client, u8 address, | 268 | static int sbs_write_word_data(struct i2c_client *client, u8 address, |
183 | u16 value) | 269 | u16 value) |
184 | { | 270 | { |
@@ -318,6 +404,19 @@ static int sbs_get_battery_property(struct i2c_client *client, | |||
318 | return 0; | 404 | return 0; |
319 | } | 405 | } |
320 | 406 | ||
407 | static int sbs_get_battery_string_property(struct i2c_client *client, | ||
408 | int reg_offset, enum power_supply_property psp, char *val) | ||
409 | { | ||
410 | s32 ret; | ||
411 | |||
412 | ret = sbs_read_string_data(client, sbs_data[reg_offset].addr, val); | ||
413 | |||
414 | if (ret < 0) | ||
415 | return ret; | ||
416 | |||
417 | return 0; | ||
418 | } | ||
419 | |||
321 | static void sbs_unit_adjustment(struct i2c_client *client, | 420 | static void sbs_unit_adjustment(struct i2c_client *client, |
322 | enum power_supply_property psp, union power_supply_propval *val) | 421 | enum power_supply_property psp, union power_supply_propval *val) |
323 | { | 422 | { |
@@ -336,6 +435,7 @@ static void sbs_unit_adjustment(struct i2c_client *client, | |||
336 | break; | 435 | break; |
337 | 436 | ||
338 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: | 437 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: |
438 | case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: | ||
339 | case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: | 439 | case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: |
340 | case POWER_SUPPLY_PROP_CURRENT_NOW: | 440 | case POWER_SUPPLY_PROP_CURRENT_NOW: |
341 | case POWER_SUPPLY_PROP_CHARGE_NOW: | 441 | case POWER_SUPPLY_PROP_CHARGE_NOW: |
@@ -497,6 +597,7 @@ static int sbs_get_property(struct power_supply *psy, | |||
497 | case POWER_SUPPLY_PROP_TEMP: | 597 | case POWER_SUPPLY_PROP_TEMP: |
498 | case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: | 598 | case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: |
499 | case POWER_SUPPLY_PROP_TIME_TO_FULL_AVG: | 599 | case POWER_SUPPLY_PROP_TIME_TO_FULL_AVG: |
600 | case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: | ||
500 | case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: | 601 | case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: |
501 | ret = sbs_get_property_index(client, psp); | 602 | ret = sbs_get_property_index(client, psp); |
502 | if (ret < 0) | 603 | if (ret < 0) |
@@ -505,6 +606,26 @@ static int sbs_get_property(struct power_supply *psy, | |||
505 | ret = sbs_get_battery_property(client, ret, psp, val); | 606 | ret = sbs_get_battery_property(client, ret, psp, val); |
506 | break; | 607 | break; |
507 | 608 | ||
609 | case POWER_SUPPLY_PROP_MODEL_NAME: | ||
610 | ret = sbs_get_property_index(client, psp); | ||
611 | if (ret < 0) | ||
612 | break; | ||
613 | |||
614 | ret = sbs_get_battery_string_property(client, ret, psp, | ||
615 | model_name); | ||
616 | val->strval = model_name; | ||
617 | break; | ||
618 | |||
619 | case POWER_SUPPLY_PROP_MANUFACTURER: | ||
620 | ret = sbs_get_property_index(client, psp); | ||
621 | if (ret < 0) | ||
622 | break; | ||
623 | |||
624 | ret = sbs_get_battery_string_property(client, ret, psp, | ||
625 | manufacturer); | ||
626 | val->strval = manufacturer; | ||
627 | break; | ||
628 | |||
508 | default: | 629 | default: |
509 | dev_err(&client->dev, | 630 | dev_err(&client->dev, |
510 | "%s: INVALID property\n", __func__); | 631 | "%s: INVALID property\n", __func__); |
diff --git a/drivers/regulator/max14577.c b/drivers/regulator/max14577.c index 5d9c605cf534..0ff5a20ac958 100644 --- a/drivers/regulator/max14577.c +++ b/drivers/regulator/max14577.c | |||
@@ -22,42 +22,6 @@ | |||
22 | #include <linux/mfd/max14577-private.h> | 22 | #include <linux/mfd/max14577-private.h> |
23 | #include <linux/regulator/of_regulator.h> | 23 | #include <linux/regulator/of_regulator.h> |
24 | 24 | ||
25 | /* | ||
26 | * Valid limits of current for max14577 and max77836 chargers. | ||
27 | * They must correspond to MBCICHWRCL and MBCICHWRCH fields in CHGCTRL4 | ||
28 | * register for given chipset. | ||
29 | */ | ||
30 | struct maxim_charger_current { | ||
31 | /* Minimal current, set in CHGCTRL4/MBCICHWRCL, uA */ | ||
32 | unsigned int min; | ||
33 | /* | ||
34 | * Minimal current when high setting is active, | ||
35 | * set in CHGCTRL4/MBCICHWRCH, uA | ||
36 | */ | ||
37 | unsigned int high_start; | ||
38 | /* Value of one step in high setting, uA */ | ||
39 | unsigned int high_step; | ||
40 | /* Maximum current of high setting, uA */ | ||
41 | unsigned int max; | ||
42 | }; | ||
43 | |||
44 | /* Table of valid charger currents for different Maxim chipsets */ | ||
45 | static const struct maxim_charger_current maxim_charger_currents[] = { | ||
46 | [MAXIM_DEVICE_TYPE_UNKNOWN] = { 0, 0, 0, 0 }, | ||
47 | [MAXIM_DEVICE_TYPE_MAX14577] = { | ||
48 | .min = MAX14577_REGULATOR_CURRENT_LIMIT_MIN, | ||
49 | .high_start = MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START, | ||
50 | .high_step = MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP, | ||
51 | .max = MAX14577_REGULATOR_CURRENT_LIMIT_MAX, | ||
52 | }, | ||
53 | [MAXIM_DEVICE_TYPE_MAX77836] = { | ||
54 | .min = MAX77836_REGULATOR_CURRENT_LIMIT_MIN, | ||
55 | .high_start = MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_START, | ||
56 | .high_step = MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_STEP, | ||
57 | .max = MAX77836_REGULATOR_CURRENT_LIMIT_MAX, | ||
58 | }, | ||
59 | }; | ||
60 | |||
61 | static int max14577_reg_is_enabled(struct regulator_dev *rdev) | 25 | static int max14577_reg_is_enabled(struct regulator_dev *rdev) |
62 | { | 26 | { |
63 | int rid = rdev_get_id(rdev); | 27 | int rid = rdev_get_id(rdev); |
@@ -103,8 +67,8 @@ static int max14577_reg_get_current_limit(struct regulator_dev *rdev) | |||
103 | static int max14577_reg_set_current_limit(struct regulator_dev *rdev, | 67 | static int max14577_reg_set_current_limit(struct regulator_dev *rdev, |
104 | int min_uA, int max_uA) | 68 | int min_uA, int max_uA) |
105 | { | 69 | { |
106 | int i, current_bits = 0xf; | ||
107 | u8 reg_data; | 70 | u8 reg_data; |
71 | int ret; | ||
108 | struct max14577 *max14577 = rdev_get_drvdata(rdev); | 72 | struct max14577 *max14577 = rdev_get_drvdata(rdev); |
109 | const struct maxim_charger_current *limits = | 73 | const struct maxim_charger_current *limits = |
110 | &maxim_charger_currents[max14577->dev_type]; | 74 | &maxim_charger_currents[max14577->dev_type]; |
@@ -112,35 +76,9 @@ static int max14577_reg_set_current_limit(struct regulator_dev *rdev, | |||
112 | if (rdev_get_id(rdev) != MAX14577_CHARGER) | 76 | if (rdev_get_id(rdev) != MAX14577_CHARGER) |
113 | return -EINVAL; | 77 | return -EINVAL; |
114 | 78 | ||
115 | if (min_uA > limits->max || max_uA < limits->min) | 79 | ret = maxim_charger_calc_reg_current(limits, min_uA, max_uA, ®_data); |
116 | return -EINVAL; | 80 | if (ret) |
117 | 81 | return ret; | |
118 | if (max_uA < limits->high_start) { | ||
119 | /* | ||
120 | * Less than high_start, | ||
121 | * so set the minimal current (turn only Low Bit off) | ||
122 | */ | ||
123 | u8 reg_data = 0x0 << CHGCTRL4_MBCICHWRCL_SHIFT; | ||
124 | return max14577_update_reg(rdev->regmap, | ||
125 | MAX14577_CHG_REG_CHG_CTRL4, | ||
126 | CHGCTRL4_MBCICHWRCL_MASK, reg_data); | ||
127 | } | ||
128 | |||
129 | /* | ||
130 | * max_uA is in range: <high_start, inifinite>, so search for | ||
131 | * valid current starting from maximum current. | ||
132 | */ | ||
133 | for (i = limits->max; i >= limits->high_start; i -= limits->high_step) { | ||
134 | if (i <= max_uA) | ||
135 | break; | ||
136 | current_bits--; | ||
137 | } | ||
138 | BUG_ON(current_bits < 0); /* Cannot happen */ | ||
139 | |||
140 | /* Turn Low Bit on (use range high_start-max)... */ | ||
141 | reg_data = 0x1 << CHGCTRL4_MBCICHWRCL_SHIFT; | ||
142 | /* and set proper High Bits */ | ||
143 | reg_data |= current_bits << CHGCTRL4_MBCICHWRCH_SHIFT; | ||
144 | 82 | ||
145 | return max14577_update_reg(rdev->regmap, MAX14577_CHG_REG_CHG_CTRL4, | 83 | return max14577_update_reg(rdev->regmap, MAX14577_CHG_REG_CHG_CTRL4, |
146 | CHGCTRL4_MBCICHWRCL_MASK | CHGCTRL4_MBCICHWRCH_MASK, | 84 | CHGCTRL4_MBCICHWRCL_MASK | CHGCTRL4_MBCICHWRCH_MASK, |
@@ -442,16 +380,6 @@ static struct platform_driver max14577_regulator_driver = { | |||
442 | 380 | ||
443 | static int __init max14577_regulator_init(void) | 381 | static int __init max14577_regulator_init(void) |
444 | { | 382 | { |
445 | /* Check for valid values for charger */ | ||
446 | BUILD_BUG_ON(MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START + | ||
447 | MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP * 0xf != | ||
448 | MAX14577_REGULATOR_CURRENT_LIMIT_MAX); | ||
449 | BUILD_BUG_ON(MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_START + | ||
450 | MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_STEP * 0xf != | ||
451 | MAX77836_REGULATOR_CURRENT_LIMIT_MAX); | ||
452 | /* Valid charger current values must be provided for each chipset */ | ||
453 | BUILD_BUG_ON(ARRAY_SIZE(maxim_charger_currents) != MAXIM_DEVICE_TYPE_NUM); | ||
454 | |||
455 | BUILD_BUG_ON(ARRAY_SIZE(max14577_supported_regulators) != MAX14577_REGULATOR_NUM); | 383 | BUILD_BUG_ON(ARRAY_SIZE(max14577_supported_regulators) != MAX14577_REGULATOR_NUM); |
456 | BUILD_BUG_ON(ARRAY_SIZE(max77836_supported_regulators) != MAX77836_REGULATOR_NUM); | 384 | BUILD_BUG_ON(ARRAY_SIZE(max77836_supported_regulators) != MAX77836_REGULATOR_NUM); |
457 | 385 | ||
diff --git a/include/linux/mfd/max14577-private.h b/include/linux/mfd/max14577-private.h index 499253604026..f01c1fae4d84 100644 --- a/include/linux/mfd/max14577-private.h +++ b/include/linux/mfd/max14577-private.h | |||
@@ -72,15 +72,33 @@ enum max14577_muic_reg { | |||
72 | MAX14577_MUIC_REG_END, | 72 | MAX14577_MUIC_REG_END, |
73 | }; | 73 | }; |
74 | 74 | ||
75 | /* | ||
76 | * Combined charger types for max14577 and max77836. | ||
77 | * | ||
78 | * On max14577 three lower bits map to STATUS2/CHGTYP field. | ||
79 | * However the max77836 has different two last values of STATUS2/CHGTYP. | ||
80 | * To indicate the difference enum has two additional values for max77836. | ||
81 | * These values are just a register value bitwise OR with 0x8. | ||
82 | */ | ||
75 | enum max14577_muic_charger_type { | 83 | enum max14577_muic_charger_type { |
76 | MAX14577_CHARGER_TYPE_NONE = 0, | 84 | MAX14577_CHARGER_TYPE_NONE = 0x0, |
77 | MAX14577_CHARGER_TYPE_USB, | 85 | MAX14577_CHARGER_TYPE_USB = 0x1, |
78 | MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT, | 86 | MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT = 0x2, |
79 | MAX14577_CHARGER_TYPE_DEDICATED_CHG, | 87 | MAX14577_CHARGER_TYPE_DEDICATED_CHG = 0x3, |
80 | MAX14577_CHARGER_TYPE_SPECIAL_500MA, | 88 | MAX14577_CHARGER_TYPE_SPECIAL_500MA = 0x4, |
81 | MAX14577_CHARGER_TYPE_SPECIAL_1A, | 89 | /* Special 1A or 2A charger */ |
82 | MAX14577_CHARGER_TYPE_RESERVED, | 90 | MAX14577_CHARGER_TYPE_SPECIAL_1A = 0x5, |
83 | MAX14577_CHARGER_TYPE_DEAD_BATTERY = 7, | 91 | /* max14577: reserved, used on max77836 */ |
92 | MAX14577_CHARGER_TYPE_RESERVED = 0x6, | ||
93 | /* max14577: dead-battery charing with maximum current 100mA */ | ||
94 | MAX14577_CHARGER_TYPE_DEAD_BATTERY = 0x7, | ||
95 | /* | ||
96 | * max77836: special charger (bias on D+/D-), | ||
97 | * matches register value of 0x6 | ||
98 | */ | ||
99 | MAX77836_CHARGER_TYPE_SPECIAL_BIAS = 0xe, | ||
100 | /* max77836: reserved, register value 0x7 */ | ||
101 | MAX77836_CHARGER_TYPE_RESERVED = 0xf, | ||
84 | }; | 102 | }; |
85 | 103 | ||
86 | /* MAX14577 interrupts */ | 104 | /* MAX14577 interrupts */ |
@@ -121,13 +139,15 @@ enum max14577_muic_charger_type { | |||
121 | #define STATUS2_CHGTYP_SHIFT 0 | 139 | #define STATUS2_CHGTYP_SHIFT 0 |
122 | #define STATUS2_CHGDETRUN_SHIFT 3 | 140 | #define STATUS2_CHGDETRUN_SHIFT 3 |
123 | #define STATUS2_DCDTMR_SHIFT 4 | 141 | #define STATUS2_DCDTMR_SHIFT 4 |
124 | #define STATUS2_DBCHG_SHIFT 5 | 142 | #define MAX14577_STATUS2_DBCHG_SHIFT 5 |
143 | #define MAX77836_STATUS2_DXOVP_SHIFT 5 | ||
125 | #define STATUS2_VBVOLT_SHIFT 6 | 144 | #define STATUS2_VBVOLT_SHIFT 6 |
126 | #define MAX77836_STATUS2_VIDRM_SHIFT 7 | 145 | #define MAX77836_STATUS2_VIDRM_SHIFT 7 |
127 | #define STATUS2_CHGTYP_MASK (0x7 << STATUS2_CHGTYP_SHIFT) | 146 | #define STATUS2_CHGTYP_MASK (0x7 << STATUS2_CHGTYP_SHIFT) |
128 | #define STATUS2_CHGDETRUN_MASK BIT(STATUS2_CHGDETRUN_SHIFT) | 147 | #define STATUS2_CHGDETRUN_MASK BIT(STATUS2_CHGDETRUN_SHIFT) |
129 | #define STATUS2_DCDTMR_MASK BIT(STATUS2_DCDTMR_SHIFT) | 148 | #define STATUS2_DCDTMR_MASK BIT(STATUS2_DCDTMR_SHIFT) |
130 | #define STATUS2_DBCHG_MASK BIT(STATUS2_DBCHG_SHIFT) | 149 | #define MAX14577_STATUS2_DBCHG_MASK BIT(MAX14577_STATUS2_DBCHG_SHIFT) |
150 | #define MAX77836_STATUS2_DXOVP_MASK BIT(MAX77836_STATUS2_DXOVP_SHIFT) | ||
131 | #define STATUS2_VBVOLT_MASK BIT(STATUS2_VBVOLT_SHIFT) | 151 | #define STATUS2_VBVOLT_MASK BIT(STATUS2_VBVOLT_SHIFT) |
132 | #define MAX77836_STATUS2_VIDRM_MASK BIT(MAX77836_STATUS2_VIDRM_SHIFT) | 152 | #define MAX77836_STATUS2_VIDRM_MASK BIT(MAX77836_STATUS2_VIDRM_SHIFT) |
133 | 153 | ||
@@ -177,9 +197,11 @@ enum max14577_muic_charger_type { | |||
177 | #define CTRL3_JIGSET_SHIFT 0 | 197 | #define CTRL3_JIGSET_SHIFT 0 |
178 | #define CTRL3_BOOTSET_SHIFT 2 | 198 | #define CTRL3_BOOTSET_SHIFT 2 |
179 | #define CTRL3_ADCDBSET_SHIFT 4 | 199 | #define CTRL3_ADCDBSET_SHIFT 4 |
200 | #define CTRL3_WBTH_SHIFT 6 | ||
180 | #define CTRL3_JIGSET_MASK (0x3 << CTRL3_JIGSET_SHIFT) | 201 | #define CTRL3_JIGSET_MASK (0x3 << CTRL3_JIGSET_SHIFT) |
181 | #define CTRL3_BOOTSET_MASK (0x3 << CTRL3_BOOTSET_SHIFT) | 202 | #define CTRL3_BOOTSET_MASK (0x3 << CTRL3_BOOTSET_SHIFT) |
182 | #define CTRL3_ADCDBSET_MASK (0x3 << CTRL3_ADCDBSET_SHIFT) | 203 | #define CTRL3_ADCDBSET_MASK (0x3 << CTRL3_ADCDBSET_SHIFT) |
204 | #define CTRL3_WBTH_MASK (0x3 << CTRL3_WBTH_SHIFT) | ||
183 | 205 | ||
184 | /* Slave addr = 0x4A: Charger */ | 206 | /* Slave addr = 0x4A: Charger */ |
185 | enum max14577_charger_reg { | 207 | enum max14577_charger_reg { |
@@ -210,16 +232,20 @@ enum max14577_charger_reg { | |||
210 | #define CDETCTRL1_CHGTYPMAN_SHIFT 1 | 232 | #define CDETCTRL1_CHGTYPMAN_SHIFT 1 |
211 | #define CDETCTRL1_DCDEN_SHIFT 2 | 233 | #define CDETCTRL1_DCDEN_SHIFT 2 |
212 | #define CDETCTRL1_DCD2SCT_SHIFT 3 | 234 | #define CDETCTRL1_DCD2SCT_SHIFT 3 |
213 | #define CDETCTRL1_DCHKTM_SHIFT 4 | 235 | #define MAX14577_CDETCTRL1_DCHKTM_SHIFT 4 |
214 | #define CDETCTRL1_DBEXIT_SHIFT 5 | 236 | #define MAX77836_CDETCTRL1_CDLY_SHIFT 4 |
237 | #define MAX14577_CDETCTRL1_DBEXIT_SHIFT 5 | ||
238 | #define MAX77836_CDETCTRL1_DCDCPL_SHIFT 5 | ||
215 | #define CDETCTRL1_DBIDLE_SHIFT 6 | 239 | #define CDETCTRL1_DBIDLE_SHIFT 6 |
216 | #define CDETCTRL1_CDPDET_SHIFT 7 | 240 | #define CDETCTRL1_CDPDET_SHIFT 7 |
217 | #define CDETCTRL1_CHGDETEN_MASK BIT(CDETCTRL1_CHGDETEN_SHIFT) | 241 | #define CDETCTRL1_CHGDETEN_MASK BIT(CDETCTRL1_CHGDETEN_SHIFT) |
218 | #define CDETCTRL1_CHGTYPMAN_MASK BIT(CDETCTRL1_CHGTYPMAN_SHIFT) | 242 | #define CDETCTRL1_CHGTYPMAN_MASK BIT(CDETCTRL1_CHGTYPMAN_SHIFT) |
219 | #define CDETCTRL1_DCDEN_MASK BIT(CDETCTRL1_DCDEN_SHIFT) | 243 | #define CDETCTRL1_DCDEN_MASK BIT(CDETCTRL1_DCDEN_SHIFT) |
220 | #define CDETCTRL1_DCD2SCT_MASK BIT(CDETCTRL1_DCD2SCT_SHIFT) | 244 | #define CDETCTRL1_DCD2SCT_MASK BIT(CDETCTRL1_DCD2SCT_SHIFT) |
221 | #define CDETCTRL1_DCHKTM_MASK BIT(CDETCTRL1_DCHKTM_SHIFT) | 245 | #define MAX14577_CDETCTRL1_DCHKTM_MASK BIT(MAX14577_CDETCTRL1_DCHKTM_SHIFT) |
222 | #define CDETCTRL1_DBEXIT_MASK BIT(CDETCTRL1_DBEXIT_SHIFT) | 246 | #define MAX77836_CDETCTRL1_CDDLY_MASK BIT(MAX77836_CDETCTRL1_CDDLY_SHIFT) |
247 | #define MAX14577_CDETCTRL1_DBEXIT_MASK BIT(MAX14577_CDETCTRL1_DBEXIT_SHIFT) | ||
248 | #define MAX77836_CDETCTRL1_DCDCPL_MASK BIT(MAX77836_CDETCTRL1_DCDCPL_SHIFT) | ||
223 | #define CDETCTRL1_DBIDLE_MASK BIT(CDETCTRL1_DBIDLE_SHIFT) | 249 | #define CDETCTRL1_DBIDLE_MASK BIT(CDETCTRL1_DBIDLE_SHIFT) |
224 | #define CDETCTRL1_CDPDET_MASK BIT(CDETCTRL1_CDPDET_SHIFT) | 250 | #define CDETCTRL1_CDPDET_MASK BIT(CDETCTRL1_CDPDET_SHIFT) |
225 | 251 | ||
@@ -255,17 +281,36 @@ enum max14577_charger_reg { | |||
255 | #define CHGCTRL7_OTPCGHCVS_SHIFT 0 | 281 | #define CHGCTRL7_OTPCGHCVS_SHIFT 0 |
256 | #define CHGCTRL7_OTPCGHCVS_MASK (0x3 << CHGCTRL7_OTPCGHCVS_SHIFT) | 282 | #define CHGCTRL7_OTPCGHCVS_MASK (0x3 << CHGCTRL7_OTPCGHCVS_SHIFT) |
257 | 283 | ||
258 | /* MAX14577 regulator current limits (as in CHGCTRL4 register), uA */ | 284 | /* MAX14577 charger current limits (as in CHGCTRL4 register), uA */ |
259 | #define MAX14577_REGULATOR_CURRENT_LIMIT_MIN 90000 | 285 | #define MAX14577_CHARGER_CURRENT_LIMIT_MIN 90000U |
260 | #define MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START 200000 | 286 | #define MAX14577_CHARGER_CURRENT_LIMIT_HIGH_START 200000U |
261 | #define MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP 50000 | 287 | #define MAX14577_CHARGER_CURRENT_LIMIT_HIGH_STEP 50000U |
262 | #define MAX14577_REGULATOR_CURRENT_LIMIT_MAX 950000 | 288 | #define MAX14577_CHARGER_CURRENT_LIMIT_MAX 950000U |
263 | 289 | ||
264 | /* MAX77836 regulator current limits (as in CHGCTRL4 register), uA */ | 290 | /* MAX77836 charger current limits (as in CHGCTRL4 register), uA */ |
265 | #define MAX77836_REGULATOR_CURRENT_LIMIT_MIN 45000 | 291 | #define MAX77836_CHARGER_CURRENT_LIMIT_MIN 45000U |
266 | #define MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_START 100000 | 292 | #define MAX77836_CHARGER_CURRENT_LIMIT_HIGH_START 100000U |
267 | #define MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_STEP 25000 | 293 | #define MAX77836_CHARGER_CURRENT_LIMIT_HIGH_STEP 25000U |
268 | #define MAX77836_REGULATOR_CURRENT_LIMIT_MAX 475000 | 294 | #define MAX77836_CHARGER_CURRENT_LIMIT_MAX 475000U |
295 | |||
296 | /* | ||
297 | * MAX14577 charger End-Of-Charge current limits | ||
298 | * (as in CHGCTRL5 register), uA | ||
299 | */ | ||
300 | #define MAX14577_CHARGER_EOC_CURRENT_LIMIT_MIN 50000U | ||
301 | #define MAX14577_CHARGER_EOC_CURRENT_LIMIT_STEP 10000U | ||
302 | #define MAX14577_CHARGER_EOC_CURRENT_LIMIT_MAX 200000U | ||
303 | |||
304 | /* | ||
305 | * MAX14577/MAX77836 Battery Constant Voltage | ||
306 | * (as in CHGCTRL3 register), uV | ||
307 | */ | ||
308 | #define MAXIM_CHARGER_CONSTANT_VOLTAGE_MIN 4000000U | ||
309 | #define MAXIM_CHARGER_CONSTANT_VOLTAGE_STEP 20000U | ||
310 | #define MAXIM_CHARGER_CONSTANT_VOLTAGE_MAX 4350000U | ||
311 | |||
312 | /* Default value for fast charge timer, in hours */ | ||
313 | #define MAXIM_CHARGER_FAST_CHARGE_TIMER_DEFAULT 5 | ||
269 | 314 | ||
270 | /* MAX14577 regulator SFOUT LDO voltage, fixed, uV */ | 315 | /* MAX14577 regulator SFOUT LDO voltage, fixed, uV */ |
271 | #define MAX14577_REGULATOR_SAFEOUT_VOLTAGE 4900000 | 316 | #define MAX14577_REGULATOR_SAFEOUT_VOLTAGE 4900000 |
diff --git a/include/linux/mfd/max14577.h b/include/linux/mfd/max14577.h index c83fbed1c7b6..ccfaf952c31b 100644 --- a/include/linux/mfd/max14577.h +++ b/include/linux/mfd/max14577.h | |||
@@ -54,6 +54,13 @@ struct max14577_regulator_platform_data { | |||
54 | struct device_node *of_node; | 54 | struct device_node *of_node; |
55 | }; | 55 | }; |
56 | 56 | ||
57 | struct max14577_charger_platform_data { | ||
58 | u32 constant_uvolt; | ||
59 | u32 fast_charge_uamp; | ||
60 | u32 eoc_uamp; | ||
61 | u32 ovp_uvolt; | ||
62 | }; | ||
63 | |||
57 | /* | 64 | /* |
58 | * MAX14577 MFD platform data | 65 | * MAX14577 MFD platform data |
59 | */ | 66 | */ |
@@ -74,4 +81,27 @@ struct max14577_platform_data { | |||
74 | struct max14577_regulator_platform_data *regulators; | 81 | struct max14577_regulator_platform_data *regulators; |
75 | }; | 82 | }; |
76 | 83 | ||
84 | /* | ||
85 | * Valid limits of current for max14577 and max77836 chargers. | ||
86 | * They must correspond to MBCICHWRCL and MBCICHWRCH fields in CHGCTRL4 | ||
87 | * register for given chipset. | ||
88 | */ | ||
89 | struct maxim_charger_current { | ||
90 | /* Minimal current, set in CHGCTRL4/MBCICHWRCL, uA */ | ||
91 | unsigned int min; | ||
92 | /* | ||
93 | * Minimal current when high setting is active, | ||
94 | * set in CHGCTRL4/MBCICHWRCH, uA | ||
95 | */ | ||
96 | unsigned int high_start; | ||
97 | /* Value of one step in high setting, uA */ | ||
98 | unsigned int high_step; | ||
99 | /* Maximum current of high setting, uA */ | ||
100 | unsigned int max; | ||
101 | }; | ||
102 | |||
103 | extern const struct maxim_charger_current maxim_charger_currents[]; | ||
104 | extern int maxim_charger_calc_reg_current(const struct maxim_charger_current *limits, | ||
105 | unsigned int min_ua, unsigned int max_ua, u8 *dst); | ||
106 | |||
77 | #endif /* __MAX14577_H__ */ | 107 | #endif /* __MAX14577_H__ */ |
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index f3dea41dbcd2..3ed049673022 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h | |||
@@ -18,8 +18,6 @@ | |||
18 | #include <linux/spinlock.h> | 18 | #include <linux/spinlock.h> |
19 | #include <linux/notifier.h> | 19 | #include <linux/notifier.h> |
20 | 20 | ||
21 | struct device; | ||
22 | |||
23 | /* | 21 | /* |
24 | * All voltages, currents, charges, energies, time and temperatures in uV, | 22 | * All voltages, currents, charges, energies, time and temperatures in uV, |
25 | * µA, µAh, µWh, seconds and tenths of degree Celsius unless otherwise | 23 | * µA, µAh, µWh, seconds and tenths of degree Celsius unless otherwise |
@@ -102,9 +100,11 @@ enum power_supply_property { | |||
102 | POWER_SUPPLY_PROP_VOLTAGE_NOW, | 100 | POWER_SUPPLY_PROP_VOLTAGE_NOW, |
103 | POWER_SUPPLY_PROP_VOLTAGE_AVG, | 101 | POWER_SUPPLY_PROP_VOLTAGE_AVG, |
104 | POWER_SUPPLY_PROP_VOLTAGE_OCV, | 102 | POWER_SUPPLY_PROP_VOLTAGE_OCV, |
103 | POWER_SUPPLY_PROP_VOLTAGE_BOOT, | ||
105 | POWER_SUPPLY_PROP_CURRENT_MAX, | 104 | POWER_SUPPLY_PROP_CURRENT_MAX, |
106 | POWER_SUPPLY_PROP_CURRENT_NOW, | 105 | POWER_SUPPLY_PROP_CURRENT_NOW, |
107 | POWER_SUPPLY_PROP_CURRENT_AVG, | 106 | POWER_SUPPLY_PROP_CURRENT_AVG, |
107 | POWER_SUPPLY_PROP_CURRENT_BOOT, | ||
108 | POWER_SUPPLY_PROP_POWER_NOW, | 108 | POWER_SUPPLY_PROP_POWER_NOW, |
109 | POWER_SUPPLY_PROP_POWER_AVG, | 109 | POWER_SUPPLY_PROP_POWER_AVG, |
110 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, | 110 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, |
@@ -146,6 +146,7 @@ enum power_supply_property { | |||
146 | POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */ | 146 | POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */ |
147 | POWER_SUPPLY_PROP_SCOPE, | 147 | POWER_SUPPLY_PROP_SCOPE, |
148 | POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT, | 148 | POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT, |
149 | POWER_SUPPLY_PROP_CALIBRATE, | ||
149 | /* Properties of type `const char *' */ | 150 | /* Properties of type `const char *' */ |
150 | POWER_SUPPLY_PROP_MODEL_NAME, | 151 | POWER_SUPPLY_PROP_MODEL_NAME, |
151 | POWER_SUPPLY_PROP_MANUFACTURER, | 152 | POWER_SUPPLY_PROP_MANUFACTURER, |
@@ -172,6 +173,7 @@ union power_supply_propval { | |||
172 | const char *strval; | 173 | const char *strval; |
173 | }; | 174 | }; |
174 | 175 | ||
176 | struct device; | ||
175 | struct device_node; | 177 | struct device_node; |
176 | 178 | ||
177 | struct power_supply { | 179 | struct power_supply { |
@@ -291,6 +293,7 @@ static inline bool power_supply_is_amp_property(enum power_supply_property psp) | |||
291 | case POWER_SUPPLY_PROP_CURRENT_MAX: | 293 | case POWER_SUPPLY_PROP_CURRENT_MAX: |
292 | case POWER_SUPPLY_PROP_CURRENT_NOW: | 294 | case POWER_SUPPLY_PROP_CURRENT_NOW: |
293 | case POWER_SUPPLY_PROP_CURRENT_AVG: | 295 | case POWER_SUPPLY_PROP_CURRENT_AVG: |
296 | case POWER_SUPPLY_PROP_CURRENT_BOOT: | ||
294 | return 1; | 297 | return 1; |
295 | default: | 298 | default: |
296 | break; | 299 | break; |
@@ -315,6 +318,7 @@ static inline bool power_supply_is_watt_property(enum power_supply_property psp) | |||
315 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: | 318 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: |
316 | case POWER_SUPPLY_PROP_VOLTAGE_AVG: | 319 | case POWER_SUPPLY_PROP_VOLTAGE_AVG: |
317 | case POWER_SUPPLY_PROP_VOLTAGE_OCV: | 320 | case POWER_SUPPLY_PROP_VOLTAGE_OCV: |
321 | case POWER_SUPPLY_PROP_VOLTAGE_BOOT: | ||
318 | case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: | 322 | case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: |
319 | case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX: | 323 | case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX: |
320 | case POWER_SUPPLY_PROP_POWER_NOW: | 324 | case POWER_SUPPLY_PROP_POWER_NOW: |