1 /* SPDX-License-Identifier: GPL-2.0-only */ 1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 2 /* 3 * Copyright (C) 2011 Samsung Electronics Co., 3 * Copyright (C) 2011 Samsung Electronics Co., Ltd. 4 * MyungJoo.Ham <myungjoo.ham@samsung.com> 4 * MyungJoo.Ham <myungjoo.ham@samsung.com> 5 * 5 * 6 * Charger Manager. 6 * Charger Manager. 7 * This framework enables to control and multi 7 * This framework enables to control and multiple chargers and to 8 * monitor charging even in the context of sus 8 * monitor charging even in the context of suspend-to-RAM with 9 * an interface combining the chargers. 9 * an interface combining the chargers. 10 * 10 * 11 **/ 11 **/ 12 12 13 #ifndef _CHARGER_MANAGER_H 13 #ifndef _CHARGER_MANAGER_H 14 #define _CHARGER_MANAGER_H 14 #define _CHARGER_MANAGER_H 15 15 16 #include <linux/power_supply.h> 16 #include <linux/power_supply.h> 17 #include <linux/extcon.h> 17 #include <linux/extcon.h> 18 #include <linux/alarmtimer.h> 18 #include <linux/alarmtimer.h> 19 19 20 enum data_source { 20 enum data_source { 21 CM_BATTERY_PRESENT, 21 CM_BATTERY_PRESENT, 22 CM_NO_BATTERY, 22 CM_NO_BATTERY, 23 CM_FUEL_GAUGE, 23 CM_FUEL_GAUGE, 24 CM_CHARGER_STAT, 24 CM_CHARGER_STAT, 25 }; 25 }; 26 26 27 enum polling_modes { 27 enum polling_modes { 28 CM_POLL_DISABLE = 0, 28 CM_POLL_DISABLE = 0, 29 CM_POLL_ALWAYS, 29 CM_POLL_ALWAYS, 30 CM_POLL_EXTERNAL_POWER_ONLY, 30 CM_POLL_EXTERNAL_POWER_ONLY, 31 CM_POLL_CHARGING_ONLY, 31 CM_POLL_CHARGING_ONLY, 32 }; 32 }; 33 33 34 enum cm_batt_temp { !! 34 enum cm_event_types { 35 CM_BATT_OK = 0, !! 35 CM_EVENT_UNKNOWN = 0, 36 CM_BATT_OVERHEAT, !! 36 CM_EVENT_BATT_FULL, 37 CM_BATT_COLD, !! 37 CM_EVENT_BATT_IN, >> 38 CM_EVENT_BATT_OUT, >> 39 CM_EVENT_BATT_OVERHEAT, >> 40 CM_EVENT_BATT_COLD, >> 41 CM_EVENT_EXT_PWR_IN_OUT, >> 42 CM_EVENT_CHG_START_STOP, >> 43 CM_EVENT_OTHERS, 38 }; 44 }; 39 45 40 /** 46 /** 41 * struct charger_cable 47 * struct charger_cable 42 * @extcon_name: the name of extcon device. 48 * @extcon_name: the name of extcon device. 43 * @name: the name of the cable connector !! 49 * @name: the name of charger cable(external connector). 44 * @extcon_dev: the extcon device. 50 * @extcon_dev: the extcon device. 45 * @wq: the workqueue to control charger accor 51 * @wq: the workqueue to control charger according to the state of 46 * charger cable. If charger cable is att 52 * charger cable. If charger cable is attached, enable charger. 47 * But if charger cable is detached, disa 53 * But if charger cable is detached, disable charger. 48 * @nb: the notifier block to receive changed 54 * @nb: the notifier block to receive changed state from EXTCON 49 * (External Connector) when charger cabl 55 * (External Connector) when charger cable is attached/detached. 50 * @attached: the state of charger cable. 56 * @attached: the state of charger cable. 51 * true: the charger cable is attached 57 * true: the charger cable is attached 52 * false: the charger cable is detached 58 * false: the charger cable is detached 53 * @charger: the instance of struct charger_re 59 * @charger: the instance of struct charger_regulator. 54 * @cm: the Charger Manager representing the b 60 * @cm: the Charger Manager representing the battery. 55 */ 61 */ 56 struct charger_cable { 62 struct charger_cable { 57 const char *extcon_name; 63 const char *extcon_name; 58 const char *name; 64 const char *name; 59 struct extcon_dev *extcon_dev; << 60 u64 extcon_type; << 61 65 62 /* The charger-manager use Extcon fram 66 /* The charger-manager use Extcon framework */ >> 67 struct extcon_specific_cable_nb extcon_dev; 63 struct work_struct wq; 68 struct work_struct wq; 64 struct notifier_block nb; 69 struct notifier_block nb; 65 70 66 /* The state of charger cable */ 71 /* The state of charger cable */ 67 bool attached; 72 bool attached; 68 73 69 struct charger_regulator *charger; 74 struct charger_regulator *charger; 70 75 71 /* 76 /* 72 * Set min/max current of regulator to 77 * Set min/max current of regulator to protect over-current issue 73 * according to a kind of charger cabl 78 * according to a kind of charger cable when cable is attached. 74 */ 79 */ 75 int min_uA; 80 int min_uA; 76 int max_uA; 81 int max_uA; 77 82 78 struct charger_manager *cm; 83 struct charger_manager *cm; 79 }; 84 }; 80 85 81 /** 86 /** 82 * struct charger_regulator 87 * struct charger_regulator 83 * @regulator_name: the name of regulator for 88 * @regulator_name: the name of regulator for using charger. 84 * @consumer: the regulator consumer for the c 89 * @consumer: the regulator consumer for the charger. 85 * @externally_control: 90 * @externally_control: 86 * Set if the charger-manager cannot cont 91 * Set if the charger-manager cannot control charger, 87 * the charger will be maintained with di 92 * the charger will be maintained with disabled state. 88 * @cables: 93 * @cables: 89 * the array of charger cables to enable/ 94 * the array of charger cables to enable/disable charger 90 * and set current limit according to con 95 * and set current limit according to constraint data of 91 * struct charger_cable if only charger c 96 * struct charger_cable if only charger cable included 92 * in the array of charger cables is atta 97 * in the array of charger cables is attached/detached. 93 * @num_cables: the number of charger cables. 98 * @num_cables: the number of charger cables. 94 * @attr_g: Attribute group for the charger(re 99 * @attr_g: Attribute group for the charger(regulator) 95 * @attr_name: "name" sysfs entry 100 * @attr_name: "name" sysfs entry 96 * @attr_state: "state" sysfs entry 101 * @attr_state: "state" sysfs entry 97 * @attr_externally_control: "externally_contr 102 * @attr_externally_control: "externally_control" sysfs entry 98 * @attrs: Arrays pointing to attr_name/state/ 103 * @attrs: Arrays pointing to attr_name/state/externally_control for attr_g 99 */ 104 */ 100 struct charger_regulator { 105 struct charger_regulator { 101 /* The name of regulator for charging 106 /* The name of regulator for charging */ 102 const char *regulator_name; 107 const char *regulator_name; 103 struct regulator *consumer; 108 struct regulator *consumer; 104 109 105 /* charger never on when system is on 110 /* charger never on when system is on */ 106 int externally_control; 111 int externally_control; 107 112 108 /* 113 /* 109 * Store constraint information relate 114 * Store constraint information related to current limit, 110 * each cable have different condition 115 * each cable have different condition for charging. 111 */ 116 */ 112 struct charger_cable *cables; 117 struct charger_cable *cables; 113 int num_cables; 118 int num_cables; 114 119 115 struct attribute_group attr_grp; 120 struct attribute_group attr_grp; 116 struct device_attribute attr_name; 121 struct device_attribute attr_name; 117 struct device_attribute attr_state; 122 struct device_attribute attr_state; 118 struct device_attribute attr_externall 123 struct device_attribute attr_externally_control; 119 struct attribute *attrs[4]; 124 struct attribute *attrs[4]; 120 125 121 struct charger_manager *cm; 126 struct charger_manager *cm; 122 }; 127 }; 123 128 124 /** 129 /** 125 * struct charger_desc 130 * struct charger_desc 126 * @psy_name: the name of power-supply-class f 131 * @psy_name: the name of power-supply-class for charger manager 127 * @polling_mode: 132 * @polling_mode: 128 * Determine which polling mode will be u 133 * Determine which polling mode will be used >> 134 * @fullbatt_vchkdrop_ms: 129 * @fullbatt_vchkdrop_uV: 135 * @fullbatt_vchkdrop_uV: 130 * Check voltage drop after the battery i 136 * Check voltage drop after the battery is fully charged. 131 * If it has dropped more than fullbatt_v !! 137 * If it has dropped more than fullbatt_vchkdrop_uV after 132 * CM will restart charging. !! 138 * fullbatt_vchkdrop_ms, CM will restart charging. 133 * @fullbatt_uV: voltage in microvolt 139 * @fullbatt_uV: voltage in microvolt 134 * If VBATT >= fullbatt_uV, it is assumed 140 * If VBATT >= fullbatt_uV, it is assumed to be full. 135 * @fullbatt_soc: state of Charge in % 141 * @fullbatt_soc: state of Charge in % 136 * If state of Charge >= fullbatt_soc, it 142 * If state of Charge >= fullbatt_soc, it is assumed to be full. 137 * @fullbatt_full_capacity: full capacity meas 143 * @fullbatt_full_capacity: full capacity measure 138 * If full capacity of battery >= fullbat 144 * If full capacity of battery >= fullbatt_full_capacity, 139 * it is assumed to be full. 145 * it is assumed to be full. 140 * @polling_interval_ms: interval in milliseco 146 * @polling_interval_ms: interval in millisecond at which 141 * charger manager will monitor battery h 147 * charger manager will monitor battery health 142 * @battery_present: 148 * @battery_present: 143 * Specify where information for existenc 149 * Specify where information for existence of battery can be obtained 144 * @psy_charger_stat: the names of power-suppl 150 * @psy_charger_stat: the names of power-supply for chargers 145 * @num_charger_regulator: the number of entri 151 * @num_charger_regulator: the number of entries in charger_regulators 146 * @charger_regulators: array of charger regul 152 * @charger_regulators: array of charger regulators 147 * @psy_fuel_gauge: the name of power-supply f 153 * @psy_fuel_gauge: the name of power-supply for fuel gauge 148 * @thermal_zone : the name of thermal zone fo 154 * @thermal_zone : the name of thermal zone for battery 149 * @temp_min : Minimum battery temperature for 155 * @temp_min : Minimum battery temperature for charging. 150 * @temp_max : Maximum battery temperature for 156 * @temp_max : Maximum battery temperature for charging. 151 * @temp_diff : Temperature difference to rest 157 * @temp_diff : Temperature difference to restart charging. 152 * @measure_battery_temp: 158 * @measure_battery_temp: 153 * true: measure battery temperature 159 * true: measure battery temperature 154 * false: measure ambient temperature 160 * false: measure ambient temperature 155 * @charging_max_duration_ms: Maximum possible 161 * @charging_max_duration_ms: Maximum possible duration for charging 156 * If whole charging duration exceed 'cha 162 * If whole charging duration exceed 'charging_max_duration_ms', 157 * cm stop charging. 163 * cm stop charging. 158 * @discharging_max_duration_ms: 164 * @discharging_max_duration_ms: 159 * Maximum possible duration for discharg 165 * Maximum possible duration for discharging with charger cable 160 * after full-batt. If discharging durati 166 * after full-batt. If discharging duration exceed 'discharging 161 * max_duration_ms', cm start charging. 167 * max_duration_ms', cm start charging. 162 */ 168 */ 163 struct charger_desc { 169 struct charger_desc { 164 const char *psy_name; 170 const char *psy_name; 165 171 166 enum polling_modes polling_mode; 172 enum polling_modes polling_mode; 167 unsigned int polling_interval_ms; 173 unsigned int polling_interval_ms; 168 174 >> 175 unsigned int fullbatt_vchkdrop_ms; 169 unsigned int fullbatt_vchkdrop_uV; 176 unsigned int fullbatt_vchkdrop_uV; 170 unsigned int fullbatt_uV; 177 unsigned int fullbatt_uV; 171 unsigned int fullbatt_soc; 178 unsigned int fullbatt_soc; 172 unsigned int fullbatt_full_capacity; 179 unsigned int fullbatt_full_capacity; 173 180 174 enum data_source battery_present; 181 enum data_source battery_present; 175 182 176 const char **psy_charger_stat; 183 const char **psy_charger_stat; 177 184 178 int num_charger_regulators; 185 int num_charger_regulators; 179 struct charger_regulator *charger_regu 186 struct charger_regulator *charger_regulators; 180 const struct attribute_group **sysfs_g 187 const struct attribute_group **sysfs_groups; 181 188 182 const char *psy_fuel_gauge; 189 const char *psy_fuel_gauge; 183 190 184 const char *thermal_zone; 191 const char *thermal_zone; 185 192 186 int temp_min; 193 int temp_min; 187 int temp_max; 194 int temp_max; 188 int temp_diff; 195 int temp_diff; 189 196 190 bool measure_battery_temp; 197 bool measure_battery_temp; 191 198 192 u32 charging_max_duration_ms; 199 u32 charging_max_duration_ms; 193 u32 discharging_max_duration_ms; 200 u32 discharging_max_duration_ms; 194 }; 201 }; 195 202 196 #define PSY_NAME_MAX 30 203 #define PSY_NAME_MAX 30 197 204 198 /** 205 /** 199 * struct charger_manager 206 * struct charger_manager 200 * @entry: entry for list 207 * @entry: entry for list 201 * @dev: device pointer 208 * @dev: device pointer 202 * @desc: instance of charger_desc 209 * @desc: instance of charger_desc 203 * @fuel_gauge: power_supply for fuel gauge 210 * @fuel_gauge: power_supply for fuel gauge 204 * @charger_stat: array of power_supply for ch 211 * @charger_stat: array of power_supply for chargers 205 * @tzd_batt : thermal zone device for battery 212 * @tzd_batt : thermal zone device for battery 206 * @charger_enabled: the state of charger 213 * @charger_enabled: the state of charger >> 214 * @fullbatt_vchk_jiffies_at: >> 215 * jiffies at the time full battery check will occur. >> 216 * @fullbatt_vchk_work: work queue for full battery check 207 * @emergency_stop: 217 * @emergency_stop: 208 * When setting true, stop charging 218 * When setting true, stop charging 209 * @psy_name_buf: the name of power-supply-cla 219 * @psy_name_buf: the name of power-supply-class for charger manager 210 * @charger_psy: power_supply for charger mana 220 * @charger_psy: power_supply for charger manager 211 * @status_save_ext_pwr_inserted: 221 * @status_save_ext_pwr_inserted: 212 * saved status of external power before 222 * saved status of external power before entering suspend-to-RAM 213 * @status_save_batt: 223 * @status_save_batt: 214 * saved status of battery before enterin 224 * saved status of battery before entering suspend-to-RAM 215 * @charging_start_time: saved start time of e 225 * @charging_start_time: saved start time of enabling charging 216 * @charging_end_time: saved end time of disab 226 * @charging_end_time: saved end time of disabling charging 217 * @battery_status: Current battery status << 218 */ 227 */ 219 struct charger_manager { 228 struct charger_manager { 220 struct list_head entry; 229 struct list_head entry; 221 struct device *dev; 230 struct device *dev; 222 struct charger_desc *desc; 231 struct charger_desc *desc; 223 232 224 #ifdef CONFIG_THERMAL 233 #ifdef CONFIG_THERMAL 225 struct thermal_zone_device *tzd_batt; 234 struct thermal_zone_device *tzd_batt; 226 #endif 235 #endif 227 bool charger_enabled; 236 bool charger_enabled; 228 237 >> 238 unsigned long fullbatt_vchk_jiffies_at; >> 239 struct delayed_work fullbatt_vchk_work; >> 240 229 int emergency_stop; 241 int emergency_stop; 230 242 231 char psy_name_buf[PSY_NAME_MAX + 1]; 243 char psy_name_buf[PSY_NAME_MAX + 1]; 232 struct power_supply_desc charger_psy_d 244 struct power_supply_desc charger_psy_desc; 233 struct power_supply *charger_psy; 245 struct power_supply *charger_psy; 234 246 235 u64 charging_start_time; 247 u64 charging_start_time; 236 u64 charging_end_time; 248 u64 charging_end_time; 237 << 238 int battery_status; << 239 }; 249 }; 240 250 >> 251 #ifdef CONFIG_CHARGER_MANAGER >> 252 extern void cm_notify_event(struct power_supply *psy, >> 253 enum cm_event_types type, char *msg); >> 254 #else >> 255 static inline void cm_notify_event(struct power_supply *psy, >> 256 enum cm_event_types type, char *msg) { } >> 257 #endif 241 #endif /* _CHARGER_MANAGER_H */ 258 #endif /* _CHARGER_MANAGER_H */ 242 259
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.