1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2011 Samsung Electronics Co., Ltd.
4 * MyungJoo.Ham <myungjoo.ham@samsung.com>
7 * This framework enables to control and multiple chargers and to
8 * monitor charging even in the context of suspend-to-RAM with
9 * an interface combining the chargers.
13 #ifndef _CHARGER_MANAGER_H
14 #define _CHARGER_MANAGER_H
16 #include <linux/power_supply.h>
17 #include <linux/extcon.h>
18 #include <linux/alarmtimer.h>
30 CM_POLL_EXTERNAL_POWER_ONLY
,
31 CM_POLL_CHARGING_ONLY
,
41 * struct charger_cable
42 * @extcon_name: the name of extcon device.
43 * @name: the name of the cable connector
44 * @extcon_dev: the extcon device.
45 * @wq: the workqueue to control charger according to the state of
46 * charger cable. If charger cable is attached, enable charger.
47 * But if charger cable is detached, disable charger.
48 * @nb: the notifier block to receive changed state from EXTCON
49 * (External Connector) when charger cable is attached/detached.
50 * @attached: the state of charger cable.
51 * true: the charger cable is attached
52 * false: the charger cable is detached
53 * @charger: the instance of struct charger_regulator.
54 * @cm: the Charger Manager representing the battery.
56 struct charger_cable
{
57 const char *extcon_name
;
59 struct extcon_dev
*extcon_dev
;
62 /* The charger-manager use Extcon framework */
63 struct work_struct wq
;
64 struct notifier_block nb
;
66 /* The state of charger cable */
69 struct charger_regulator
*charger
;
72 * Set min/max current of regulator to protect over-current issue
73 * according to a kind of charger cable when cable is attached.
78 struct charger_manager
*cm
;
82 * struct charger_regulator
83 * @regulator_name: the name of regulator for using charger.
84 * @consumer: the regulator consumer for the charger.
85 * @externally_control:
86 * Set if the charger-manager cannot control charger,
87 * the charger will be maintained with disabled state.
89 * the array of charger cables to enable/disable charger
90 * and set current limit according to constraint data of
91 * struct charger_cable if only charger cable included
92 * in the array of charger cables is attached/detached.
93 * @num_cables: the number of charger cables.
94 * @attr_g: Attribute group for the charger(regulator)
95 * @attr_name: "name" sysfs entry
96 * @attr_state: "state" sysfs entry
97 * @attr_externally_control: "externally_control" sysfs entry
98 * @attrs: Arrays pointing to attr_name/state/externally_control for attr_g
100 struct charger_regulator
{
101 /* The name of regulator for charging */
102 const char *regulator_name
;
103 struct regulator
*consumer
;
105 /* charger never on when system is on */
106 int externally_control
;
109 * Store constraint information related to current limit,
110 * each cable have different condition for charging.
112 struct charger_cable
*cables
;
115 struct attribute_group attr_grp
;
116 struct device_attribute attr_name
;
117 struct device_attribute attr_state
;
118 struct device_attribute attr_externally_control
;
119 struct attribute
*attrs
[4];
121 struct charger_manager
*cm
;
125 * struct charger_desc
126 * @psy_name: the name of power-supply-class for charger manager
128 * Determine which polling mode will be used
129 * @fullbatt_vchkdrop_uV:
130 * Check voltage drop after the battery is fully charged.
131 * If it has dropped more than fullbatt_vchkdrop_uV
132 * CM will restart charging.
133 * @fullbatt_uV: voltage in microvolt
134 * If VBATT >= fullbatt_uV, it is assumed to be full.
135 * @fullbatt_soc: state of Charge in %
136 * If state of Charge >= fullbatt_soc, it is assumed to be full.
137 * @fullbatt_full_capacity: full capacity measure
138 * If full capacity of battery >= fullbatt_full_capacity,
139 * it is assumed to be full.
140 * @polling_interval_ms: interval in millisecond at which
141 * charger manager will monitor battery health
143 * Specify where information for existence of battery can be obtained
144 * @psy_charger_stat: the names of power-supply for chargers
145 * @num_charger_regulator: the number of entries in charger_regulators
146 * @charger_regulators: array of charger regulators
147 * @psy_fuel_gauge: the name of power-supply for fuel gauge
148 * @thermal_zone : the name of thermal zone for battery
149 * @temp_min : Minimum battery temperature for charging.
150 * @temp_max : Maximum battery temperature for charging.
151 * @temp_diff : Temperature difference to restart charging.
152 * @measure_battery_temp:
153 * true: measure battery temperature
154 * false: measure ambient temperature
155 * @charging_max_duration_ms: Maximum possible duration for charging
156 * If whole charging duration exceed 'charging_max_duration_ms',
158 * @discharging_max_duration_ms:
159 * Maximum possible duration for discharging with charger cable
160 * after full-batt. If discharging duration exceed 'discharging
161 * max_duration_ms', cm start charging.
163 struct charger_desc
{
164 const char *psy_name
;
166 enum polling_modes polling_mode
;
167 unsigned int polling_interval_ms
;
169 unsigned int fullbatt_vchkdrop_uV
;
170 unsigned int fullbatt_uV
;
171 unsigned int fullbatt_soc
;
172 unsigned int fullbatt_full_capacity
;
174 enum data_source battery_present
;
176 const char **psy_charger_stat
;
178 int num_charger_regulators
;
179 struct charger_regulator
*charger_regulators
;
180 const struct attribute_group
**sysfs_groups
;
182 const char *psy_fuel_gauge
;
184 const char *thermal_zone
;
190 bool measure_battery_temp
;
192 u32 charging_max_duration_ms
;
193 u32 discharging_max_duration_ms
;
196 #define PSY_NAME_MAX 30
199 * struct charger_manager
200 * @entry: entry for list
201 * @dev: device pointer
202 * @desc: instance of charger_desc
203 * @fuel_gauge: power_supply for fuel gauge
204 * @charger_stat: array of power_supply for chargers
205 * @tzd_batt : thermal zone device for battery
206 * @charger_enabled: the state of charger
208 * When setting true, stop charging
209 * @psy_name_buf: the name of power-supply-class for charger manager
210 * @charger_psy: power_supply for charger manager
211 * @status_save_ext_pwr_inserted:
212 * saved status of external power before entering suspend-to-RAM
214 * saved status of battery before entering suspend-to-RAM
215 * @charging_start_time: saved start time of enabling charging
216 * @charging_end_time: saved end time of disabling charging
217 * @battery_status: Current battery status
219 struct charger_manager
{
220 struct list_head entry
;
222 struct charger_desc
*desc
;
224 #ifdef CONFIG_THERMAL
225 struct thermal_zone_device
*tzd_batt
;
227 bool charger_enabled
;
231 char psy_name_buf
[PSY_NAME_MAX
+ 1];
232 struct power_supply_desc charger_psy_desc
;
233 struct power_supply
*charger_psy
;
235 u64 charging_start_time
;
236 u64 charging_end_time
;
241 #endif /* _CHARGER_MANAGER_H */