2 * Copyright (C) 2011 Samsung Electronics Co., Ltd.
3 * MyungJoo.Ham <myungjoo.ham@samsung.com>
6 * This framework enables to control and multiple chargers and to
7 * monitor charging even in the context of suspend-to-RAM with
8 * an interface combining the chargers.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #ifndef _CHARGER_MANAGER_H
16 #define _CHARGER_MANAGER_H
18 #include <linux/power_supply.h>
19 #include <linux/extcon.h>
31 CM_POLL_EXTERNAL_POWER_ONLY,
32 CM_POLL_CHARGING_ONLY,
40 CM_EVENT_EXT_PWR_IN_OUT,
41 CM_EVENT_CHG_START_STOP,
46 * struct charger_global_desc
47 * @rtc_name: the name of RTC used to wake up the system from suspend.
49 * If the system is woken up by waekup-sources other than the RTC or
50 * callbacks, Charger Manager should recognize with
51 * rtc_only_wakeup() returning false.
52 * If the RTC given to CM is the only wakeup reason,
53 * rtc_only_wakeup should return true.
54 * @assume_timer_stops_in_suspend:
55 * Assume that the jiffy timer stops in suspend-to-RAM.
56 * When enabled, CM does not rely on jiffies value in
57 * suspend_again and assumes that jiffies value does not
58 * change during suspend.
60 struct charger_global_desc {
63 bool (*rtc_only_wakeup)(void);
65 bool assume_timer_stops_in_suspend;
69 * struct charger_cable
70 * @extcon_name: the name of extcon device.
71 * @name: the name of charger cable(external connector).
72 * @extcon_dev: the extcon device.
73 * @wq: the workqueue to control charger according to the state of
74 * charger cable. If charger cable is attached, enable charger.
75 * But if charger cable is detached, disable charger.
76 * @nb: the notifier block to receive changed state from EXTCON
77 * (External Connector) when charger cable is attached/detached.
78 * @attached: the state of charger cable.
79 * true: the charger cable is attached
80 * false: the charger cable is detached
81 * @charger: the instance of struct charger_regulator.
82 * @cm: the Charger Manager representing the battery.
84 struct charger_cable {
85 const char *extcon_name;
88 /* The charger-manager use Exton framework*/
89 struct extcon_specific_cable_nb extcon_dev;
90 struct work_struct wq;
91 struct notifier_block nb;
93 /* The state of charger cable */
96 struct charger_regulator *charger;
99 * Set min/max current of regulator to protect over-current issue
100 * according to a kind of charger cable when cable is attached.
105 struct charger_manager *cm;
109 * struct charger_regulator
110 * @regulator_name: the name of regulator for using charger.
111 * @consumer: the regulator consumer for the charger.
113 * the array of charger cables to enable/disable charger
114 * and set current limit according to constratint data of
115 * struct charger_cable if only charger cable included
116 * in the array of charger cables is attached/detached.
117 * @num_cables: the number of charger cables.
119 struct charger_regulator {
120 /* The name of regulator for charging */
121 const char *regulator_name;
122 struct regulator *consumer;
125 * Store constraint information related to current limit,
126 * each cable have different condition for charging.
128 struct charger_cable *cables;
133 * struct charger_desc
134 * @psy_name: the name of power-supply-class for charger manager
136 * Determine which polling mode will be used
137 * @fullbatt_vchkdrop_ms:
138 * @fullbatt_vchkdrop_uV:
139 * Check voltage drop after the battery is fully charged.
140 * If it has dropped more than fullbatt_vchkdrop_uV after
141 * fullbatt_vchkdrop_ms, CM will restart charging.
142 * @fullbatt_uV: voltage in microvolt
143 * If it is not being charged and VBATT >= fullbatt_uV,
144 * it is assumed to be full.
145 * @polling_interval_ms: interval in millisecond at which
146 * charger manager will monitor battery health
148 * Specify where information for existance of battery can be obtained
149 * @psy_charger_stat: the names of power-supply for chargers
150 * @num_charger_regulator: the number of entries in charger_regulators
151 * @charger_regulators: array of regulator_bulk_data for chargers
152 * @psy_fuel_gauge: the name of power-supply for fuel gauge
153 * @temperature_out_of_range:
154 * Determine whether the status is overheat or cold or normal.
155 * return_value > 0: overheat
156 * return_value == 0: normal
157 * return_value < 0: cold
158 * @measure_battery_temp:
159 * true: measure battery temperature
160 * false: measure ambient temperature
162 struct charger_desc {
165 enum polling_modes polling_mode;
166 unsigned int polling_interval_ms;
168 unsigned int fullbatt_vchkdrop_ms;
169 unsigned int fullbatt_vchkdrop_uV;
170 unsigned int fullbatt_uV;
172 enum data_source battery_present;
174 char **psy_charger_stat;
176 int num_charger_regulators;
177 struct charger_regulator *charger_regulators;
179 char *psy_fuel_gauge;
181 int (*temperature_out_of_range)(int *mC);
182 bool measure_battery_temp;
185 #define PSY_NAME_MAX 30
188 * struct charger_manager
189 * @entry: entry for list
190 * @dev: device pointer
191 * @desc: instance of charger_desc
192 * @fuel_gauge: power_supply for fuel gauge
193 * @charger_stat: array of power_supply for chargers
194 * @charger_enabled: the state of charger
195 * @fullbatt_vchk_jiffies_at:
196 * jiffies at the time full battery check will occur.
197 * @fullbatt_vchk_uV: voltage in microvolt
198 * criteria for full battery
199 * @fullbatt_vchk_work: work queue for full battery check
201 * When setting true, stop charging
202 * @last_temp_mC: the measured temperature in milli-Celsius
203 * @psy_name_buf: the name of power-supply-class for charger manager
204 * @charger_psy: power_supply for charger manager
205 * @status_save_ext_pwr_inserted:
206 * saved status of external power before entering suspend-to-RAM
208 * saved status of battery before entering suspend-to-RAM
210 struct charger_manager {
211 struct list_head entry;
213 struct charger_desc *desc;
215 struct power_supply *fuel_gauge;
216 struct power_supply **charger_stat;
218 bool charger_enabled;
220 unsigned long fullbatt_vchk_jiffies_at;
221 unsigned int fullbatt_vchk_uV;
222 struct delayed_work fullbatt_vchk_work;
227 char psy_name_buf[PSY_NAME_MAX + 1];
228 struct power_supply charger_psy;
230 bool status_save_ext_pwr_inserted;
231 bool status_save_batt;
234 #ifdef CONFIG_CHARGER_MANAGER
235 extern int setup_charger_manager(struct charger_global_desc *gd);
236 extern bool cm_suspend_again(void);
237 extern void cm_notify_event(struct power_supply *psy,
238 enum cm_event_types type, char *msg);
240 static inline int setup_charger_manager(struct charger_global_desc *gd)
242 static inline bool cm_suspend_again(void) { return false; }
243 static inline void cm_notify_event(struct power_supply *psy,
244 enum cm_event_types type, char *msg) { }
246 #endif /* _CHARGER_MANAGER_H */