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