charger-manager: Poll battery health in normal state
[deliverable/linux.git] / Documentation / power / charger-manager.txt
CommitLineData
3bb3dbbd
DK
1Charger Manager
2 (C) 2011 MyungJoo Ham <myungjoo.ham@samsung.com>, GPL
3
4Charger Manager provides in-kernel battery charger management that
5requires temperature monitoring during suspend-to-RAM state
6and where each battery may have multiple chargers attached and the userland
7wants to look at the aggregated information of the multiple chargers.
8
9Charger Manager is a platform_driver with power-supply-class entries.
10An instance of Charger Manager (a platform-device created with Charger-Manager)
11represents an independent battery with chargers. If there are multiple
12batteries with their own chargers acting independently in a system,
13the system may need multiple instances of Charger Manager.
14
151. Introduction
16===============
17
18Charger Manager supports the following:
19
20* Support for multiple chargers (e.g., a device with USB, AC, and solar panels)
21 A system may have multiple chargers (or power sources) and some of
22 they may be activated at the same time. Each charger may have its
23 own power-supply-class and each power-supply-class can provide
24 different information about the battery status. This framework
25 aggregates charger-related information from multiple sources and
26 shows combined information as a single power-supply-class.
27
28* Support for in suspend-to-RAM polling (with suspend_again callback)
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
31 battery temperature. We can accomplish this by waking up the system
32 periodically. However, such a method wakes up devices unncessary for
33 monitoring the battery health and tasks, and user processes that are
34 supposed to be kept suspended. That, in turn, incurs unnecessary power
35 consumption and slow down charging process. Or even, such peak power
36 consumption can stop chargers in the middle of charging
37 (external power input < device power consumption), which not
38 only affects the charging time, but the lifespan of the battery.
39
40 Charger Manager provides a function "cm_suspend_again" that can be
41 used as suspend_again callback of platform_suspend_ops. If the platform
42 requires tasks other than cm_suspend_again, it may implement its own
43 suspend_again callback that calls cm_suspend_again in the middle.
44 Normally, the platform will need to resume and suspend some devices
45 that are used by Charger Manager.
46
d829dc75
CC
47* Support for premature full-battery event handling
48 If the battery voltage drops by "fullbatt_vchkdrop_uV" after
49 "fullbatt_vchkdrop_ms" from the full-battery event, the framework
50 restarts charging. This check is also performed while suspended by
51 setting wakeup time accordingly and using suspend_again.
52
3bb3dbbd
DK
532. Global Charger-Manager Data related with suspend_again
54========================================================
55In order to setup Charger Manager with suspend-again feature
56(in-suspend monitoring), the user should provide charger_global_desc
57with setup_charger_manager(struct charger_global_desc *).
58This charger_global_desc data for in-suspend monitoring is global
59as the name suggests. Thus, the user needs to provide only once even
60if there are multiple batteries. If there are multiple batteries, the
61multiple instances of Charger Manager share the same charger_global_desc
62and it will manage in-suspend monitoring for all instances of Charger Manager.
63
d829dc75 64The user needs to provide all the three entries properly in order to activate
3bb3dbbd
DK
65in-suspend monitoring:
66
67struct charger_global_desc {
68
69char *rtc_name;
70 : The name of rtc (e.g., "rtc0") used to wakeup the system from
71 suspend for Charger Manager. The alarm interrupt (AIE) of the rtc
72 should be able to wake up the system from suspend. Charger Manager
73 saves and restores the alarm value and use the previously-defined
74 alarm if it is going to go off earlier than Charger Manager so that
75 Charger Manager does not interfere with previously-defined alarms.
76
77bool (*rtc_only_wakeup)(void);
78 : This callback should let CM know whether
79 the wakeup-from-suspend is caused only by the alarm of "rtc" in the
80 same struct. If there is any other wakeup source triggered the
81 wakeup, it should return false. If the "rtc" is the only wakeup
82 reason, it should return true.
d829dc75
CC
83
84bool assume_timer_stops_in_suspend;
85 : if true, Charger Manager assumes that
86 the timer (CM uses jiffies as timer) stops during suspend. Then, CM
87 assumes that the suspend-duration is same as the alarm length.
3bb3dbbd
DK
88};
89
903. How to setup suspend_again
91=============================
92Charger Manager provides a function "extern bool cm_suspend_again(void)".
93When cm_suspend_again is called, it monitors every battery. The suspend_ops
94callback of the system's platform_suspend_ops can call cm_suspend_again
95function to know whether Charger Manager wants to suspend again or not.
96If there are no other devices or tasks that want to use suspend_again
97feature, the platform_suspend_ops may directly refer to cm_suspend_again
98for its suspend_again callback.
99
100The cm_suspend_again() returns true (meaning "I want to suspend again")
101if the system was woken up by Charger Manager and the polling
102(in-suspend monitoring) results in "normal".
103
1044. Charger-Manager Data (struct charger_desc)
105=============================================
106For each battery charged independently from other batteries (if a series of
107batteries are charged by a single charger, they are counted as one independent
108battery), an instance of Charger Manager is attached to it.
109
110struct charger_desc {
111
ad3d13ee
DK
112char *psy_name;
113 : The power-supply-class name of the battery. Default is
114 "battery" if psy_name is NULL. Users can access the psy entries
115 at "/sys/class/power_supply/[psy_name]/".
116
3bb3dbbd
DK
117enum polling_modes polling_mode;
118 : CM_POLL_DISABLE: do not poll this battery.
119 CM_POLL_ALWAYS: always poll this battery.
120 CM_POLL_EXTERNAL_POWER_ONLY: poll this battery if and only if
121 an external power source is attached.
122 CM_POLL_CHARGING_ONLY: poll this battery if and only if the
123 battery is being charged.
124
d829dc75
CC
125unsigned int fullbatt_vchkdrop_ms;
126unsigned int fullbatt_vchkdrop_uV;
127 : If both have non-zero values, Charger Manager will check the
128 battery voltage drop fullbatt_vchkdrop_ms after the battery is fully
129 charged. If the voltage drop is over fullbatt_vchkdrop_uV, Charger
130 Manager will try to recharge the battery by disabling and enabling
131 chargers. Recharge with voltage drop condition only (without delay
132 condition) is needed to be implemented with hardware interrupts from
133 fuel gauges or charger devices/chips.
134
ad3d13ee
DK
135unsigned int fullbatt_uV;
136 : If specified with a non-zero value, Charger Manager assumes
137 that the battery is full (capacity = 100) if the battery is not being
138 charged and the battery voltage is equal to or greater than
139 fullbatt_uV.
140
3bb3dbbd
DK
141unsigned int polling_interval_ms;
142 : Required polling interval in ms. Charger Manager will poll
143 this battery every polling_interval_ms or more frequently.
144
145enum data_source battery_present;
d829dc75
CC
146 : CM_BATTERY_PRESENT: assume that the battery exists.
147 CM_NO_BATTERY: assume that the battery does not exists.
3bb3dbbd
DK
148 CM_FUEL_GAUGE: get battery presence information from fuel gauge.
149 CM_CHARGER_STAT: get battery presence from chargers.
150
151char **psy_charger_stat;
152 : An array ending with NULL that has power-supply-class names of
153 chargers. Each power-supply-class should provide "PRESENT" (if
154 battery_present is "CM_CHARGER_STAT"), "ONLINE" (shows whether an
155 external power source is attached or not), and "STATUS" (shows whether
156 the battery is {"FULL" or not FULL} or {"FULL", "Charging",
157 "Discharging", "NotCharging"}).
158
159int num_charger_regulators;
160struct regulator_bulk_data *charger_regulators;
161 : Regulators representing the chargers in the form for
162 regulator framework's bulk functions.
163
164char *psy_fuel_gauge;
165 : Power-supply-class name of the fuel gauge.
166
167int (*temperature_out_of_range)(int *mC);
ad3d13ee 168bool measure_battery_temp;
3bb3dbbd
DK
169 : This callback returns 0 if the temperature is safe for charging,
170 a positive number if it is too hot to charge, and a negative number
171 if it is too cold to charge. With the variable mC, the callback returns
172 the temperature in 1/1000 of centigrade.
ad3d13ee
DK
173 The source of temperature can be battery or ambient one according to
174 the value of measure_battery_temp.
3bb3dbbd
DK
175};
176
1775. Other Considerations
178=======================
179
180At the charger/battery-related events such as battery-pulled-out,
181charger-pulled-out, charger-inserted, DCIN-over/under-voltage, charger-stopped,
182and others critical to chargers, the system should be configured to wake up.
183At least the following should wake up the system from a suspend:
184a) charger-on/off b) external-power-in/out c) battery-in/out (while charging)
185
186It is usually accomplished by configuring the PMIC as a wakeup source.
This page took 0.056517 seconds and 5 git commands to generate.