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>
30 CM_POLL_EXTERNAL_POWER_ONLY,
31 CM_POLL_CHARGING_ONLY,
39 CM_EVENT_EXT_PWR_IN_OUT,
40 CM_EVENT_CHG_START_STOP,
45 * struct charger_global_desc
46 * @rtc_name: the name of RTC used to wake up the system from suspend.
48 * If the system is woken up by waekup-sources other than the RTC or
49 * callbacks, Charger Manager should recognize with
50 * rtc_only_wakeup() returning false.
51 * If the RTC given to CM is the only wakeup reason,
52 * rtc_only_wakeup should return true.
53 * @assume_timer_stops_in_suspend:
54 * Assume that the jiffy timer stops in suspend-to-RAM.
55 * When enabled, CM does not rely on jiffies value in
56 * suspend_again and assumes that jiffies value does not
57 * change during suspend.
59 struct charger_global_desc {
62 bool (*rtc_only_wakeup)(void);
64 bool assume_timer_stops_in_suspend;
69 * @psy_name: the name of power-supply-class for charger manager
71 * Determine which polling mode will be used
72 * @fullbatt_vchkdrop_ms:
73 * @fullbatt_vchkdrop_uV:
74 * Check voltage drop after the battery is fully charged.
75 * If it has dropped more than fullbatt_vchkdrop_uV after
76 * fullbatt_vchkdrop_ms, CM will restart charging.
77 * @fullbatt_uV: voltage in microvolt
78 * If it is not being charged and VBATT >= fullbatt_uV,
79 * it is assumed to be full.
80 * @polling_interval_ms: interval in millisecond at which
81 * charger manager will monitor battery health
83 * Specify where information for existance of battery can be obtained
84 * @psy_charger_stat: the names of power-supply for chargers
85 * @num_charger_regulator: the number of entries in charger_regulators
86 * @charger_regulators: array of regulator_bulk_data for chargers
87 * @psy_fuel_gauge: the name of power-supply for fuel gauge
88 * @temperature_out_of_range:
89 * Determine whether the status is overheat or cold or normal.
90 * return_value > 0: overheat
91 * return_value == 0: normal
92 * return_value < 0: cold
93 * @measure_battery_temp:
94 * true: measure battery temperature
95 * false: measure ambient temperature
100 enum polling_modes polling_mode;
101 unsigned int polling_interval_ms;
103 unsigned int fullbatt_vchkdrop_ms;
104 unsigned int fullbatt_vchkdrop_uV;
105 unsigned int fullbatt_uV;
107 enum data_source battery_present;
109 char **psy_charger_stat;
111 int num_charger_regulators;
112 struct regulator_bulk_data *charger_regulators;
114 char *psy_fuel_gauge;
116 int (*temperature_out_of_range)(int *mC);
117 bool measure_battery_temp;
120 #define PSY_NAME_MAX 30
123 * struct charger_manager
124 * @entry: entry for list
125 * @dev: device pointer
126 * @desc: instance of charger_desc
127 * @fuel_gauge: power_supply for fuel gauge
128 * @charger_stat: array of power_supply for chargers
129 * @charger_enabled: the state of charger
130 * @fullbatt_vchk_jiffies_at:
131 * jiffies at the time full battery check will occur.
132 * @fullbatt_vchk_uV: voltage in microvolt
133 * criteria for full battery
134 * @fullbatt_vchk_work: work queue for full battery check
136 * When setting true, stop charging
137 * @last_temp_mC: the measured temperature in milli-Celsius
138 * @psy_name_buf: the name of power-supply-class for charger manager
139 * @charger_psy: power_supply for charger manager
140 * @status_save_ext_pwr_inserted:
141 * saved status of external power before entering suspend-to-RAM
143 * saved status of battery before entering suspend-to-RAM
145 struct charger_manager {
146 struct list_head entry;
148 struct charger_desc *desc;
150 struct power_supply *fuel_gauge;
151 struct power_supply **charger_stat;
153 bool charger_enabled;
155 unsigned long fullbatt_vchk_jiffies_at;
156 unsigned int fullbatt_vchk_uV;
157 struct delayed_work fullbatt_vchk_work;
162 char psy_name_buf[PSY_NAME_MAX + 1];
163 struct power_supply charger_psy;
165 bool status_save_ext_pwr_inserted;
166 bool status_save_batt;
169 #ifdef CONFIG_CHARGER_MANAGER
170 extern int setup_charger_manager(struct charger_global_desc *gd);
171 extern bool cm_suspend_again(void);
172 extern void cm_notify_event(struct power_supply *psy,
173 enum cm_event_types type, char *msg);
175 static inline int setup_charger_manager(struct charger_global_desc *gd)
177 static inline bool cm_suspend_again(void) { return false; }
178 static inline void cm_notify_event(struct power_supply *psy,
179 enum cm_event_types type, char *msg) { }
181 #endif /* _CHARGER_MANAGER_H */