13bb3dbbdSDonggeun Kim /* 23bb3dbbdSDonggeun Kim * Copyright (C) 2011 Samsung Electronics Co., Ltd. 33bb3dbbdSDonggeun Kim * MyungJoo.Ham <myungjoo.ham@samsung.com> 43bb3dbbdSDonggeun Kim * 53bb3dbbdSDonggeun Kim * Charger Manager. 63bb3dbbdSDonggeun Kim * This framework enables to control and multiple chargers and to 73bb3dbbdSDonggeun Kim * monitor charging even in the context of suspend-to-RAM with 83bb3dbbdSDonggeun Kim * an interface combining the chargers. 93bb3dbbdSDonggeun Kim * 103bb3dbbdSDonggeun Kim * This program is free software; you can redistribute it and/or modify 113bb3dbbdSDonggeun Kim * it under the terms of the GNU General Public License version 2 as 123bb3dbbdSDonggeun Kim * published by the Free Software Foundation. 133bb3dbbdSDonggeun Kim **/ 143bb3dbbdSDonggeun Kim 153bb3dbbdSDonggeun Kim #ifndef _CHARGER_MANAGER_H 163bb3dbbdSDonggeun Kim #define _CHARGER_MANAGER_H 173bb3dbbdSDonggeun Kim 183bb3dbbdSDonggeun Kim #include <linux/power_supply.h> 193bb3dbbdSDonggeun Kim 203bb3dbbdSDonggeun Kim enum data_source { 21d829dc75SChanwoo Choi CM_BATTERY_PRESENT, 22d829dc75SChanwoo Choi CM_NO_BATTERY, 233bb3dbbdSDonggeun Kim CM_FUEL_GAUGE, 243bb3dbbdSDonggeun Kim CM_CHARGER_STAT, 253bb3dbbdSDonggeun Kim }; 263bb3dbbdSDonggeun Kim 273bb3dbbdSDonggeun Kim enum polling_modes { 283bb3dbbdSDonggeun Kim CM_POLL_DISABLE = 0, 293bb3dbbdSDonggeun Kim CM_POLL_ALWAYS, 303bb3dbbdSDonggeun Kim CM_POLL_EXTERNAL_POWER_ONLY, 313bb3dbbdSDonggeun Kim CM_POLL_CHARGING_ONLY, 323bb3dbbdSDonggeun Kim }; 333bb3dbbdSDonggeun Kim 34*dfeccb12SChanwoo Choi enum cm_event_types { 35*dfeccb12SChanwoo Choi CM_EVENT_UNKNOWN = 0, 36*dfeccb12SChanwoo Choi CM_EVENT_BATT_FULL, 37*dfeccb12SChanwoo Choi CM_EVENT_BATT_IN, 38*dfeccb12SChanwoo Choi CM_EVENT_BATT_OUT, 39*dfeccb12SChanwoo Choi CM_EVENT_EXT_PWR_IN_OUT, 40*dfeccb12SChanwoo Choi CM_EVENT_CHG_START_STOP, 41*dfeccb12SChanwoo Choi CM_EVENT_OTHERS, 42*dfeccb12SChanwoo Choi }; 43*dfeccb12SChanwoo Choi 443bb3dbbdSDonggeun Kim /** 453bb3dbbdSDonggeun Kim * struct charger_global_desc 463bb3dbbdSDonggeun Kim * @rtc_name: the name of RTC used to wake up the system from suspend. 473bb3dbbdSDonggeun Kim * @rtc_only_wakeup: 483bb3dbbdSDonggeun Kim * If the system is woken up by waekup-sources other than the RTC or 493bb3dbbdSDonggeun Kim * callbacks, Charger Manager should recognize with 503bb3dbbdSDonggeun Kim * rtc_only_wakeup() returning false. 513bb3dbbdSDonggeun Kim * If the RTC given to CM is the only wakeup reason, 523bb3dbbdSDonggeun Kim * rtc_only_wakeup should return true. 53d829dc75SChanwoo Choi * @assume_timer_stops_in_suspend: 54d829dc75SChanwoo Choi * Assume that the jiffy timer stops in suspend-to-RAM. 55d829dc75SChanwoo Choi * When enabled, CM does not rely on jiffies value in 56d829dc75SChanwoo Choi * suspend_again and assumes that jiffies value does not 57d829dc75SChanwoo Choi * change during suspend. 583bb3dbbdSDonggeun Kim */ 593bb3dbbdSDonggeun Kim struct charger_global_desc { 603bb3dbbdSDonggeun Kim char *rtc_name; 613bb3dbbdSDonggeun Kim 623bb3dbbdSDonggeun Kim bool (*rtc_only_wakeup)(void); 63d829dc75SChanwoo Choi 64d829dc75SChanwoo Choi bool assume_timer_stops_in_suspend; 653bb3dbbdSDonggeun Kim }; 663bb3dbbdSDonggeun Kim 673bb3dbbdSDonggeun Kim /** 683bb3dbbdSDonggeun Kim * struct charger_desc 69ad3d13eeSDonggeun Kim * @psy_name: the name of power-supply-class for charger manager 703bb3dbbdSDonggeun Kim * @polling_mode: 713bb3dbbdSDonggeun Kim * Determine which polling mode will be used 72d829dc75SChanwoo Choi * @fullbatt_vchkdrop_ms: 73d829dc75SChanwoo Choi * @fullbatt_vchkdrop_uV: 74d829dc75SChanwoo Choi * Check voltage drop after the battery is fully charged. 75d829dc75SChanwoo Choi * If it has dropped more than fullbatt_vchkdrop_uV after 76d829dc75SChanwoo Choi * fullbatt_vchkdrop_ms, CM will restart charging. 77ad3d13eeSDonggeun Kim * @fullbatt_uV: voltage in microvolt 78ad3d13eeSDonggeun Kim * If it is not being charged and VBATT >= fullbatt_uV, 79ad3d13eeSDonggeun Kim * it is assumed to be full. 803bb3dbbdSDonggeun Kim * @polling_interval_ms: interval in millisecond at which 813bb3dbbdSDonggeun Kim * charger manager will monitor battery health 823bb3dbbdSDonggeun Kim * @battery_present: 833bb3dbbdSDonggeun Kim * Specify where information for existance of battery can be obtained 843bb3dbbdSDonggeun Kim * @psy_charger_stat: the names of power-supply for chargers 853bb3dbbdSDonggeun Kim * @num_charger_regulator: the number of entries in charger_regulators 863bb3dbbdSDonggeun Kim * @charger_regulators: array of regulator_bulk_data for chargers 873bb3dbbdSDonggeun Kim * @psy_fuel_gauge: the name of power-supply for fuel gauge 883bb3dbbdSDonggeun Kim * @temperature_out_of_range: 893bb3dbbdSDonggeun Kim * Determine whether the status is overheat or cold or normal. 903bb3dbbdSDonggeun Kim * return_value > 0: overheat 913bb3dbbdSDonggeun Kim * return_value == 0: normal 923bb3dbbdSDonggeun Kim * return_value < 0: cold 93ad3d13eeSDonggeun Kim * @measure_battery_temp: 94ad3d13eeSDonggeun Kim * true: measure battery temperature 95ad3d13eeSDonggeun Kim * false: measure ambient temperature 963bb3dbbdSDonggeun Kim */ 973bb3dbbdSDonggeun Kim struct charger_desc { 98ad3d13eeSDonggeun Kim char *psy_name; 99ad3d13eeSDonggeun Kim 1003bb3dbbdSDonggeun Kim enum polling_modes polling_mode; 1013bb3dbbdSDonggeun Kim unsigned int polling_interval_ms; 1023bb3dbbdSDonggeun Kim 103d829dc75SChanwoo Choi unsigned int fullbatt_vchkdrop_ms; 104d829dc75SChanwoo Choi unsigned int fullbatt_vchkdrop_uV; 105ad3d13eeSDonggeun Kim unsigned int fullbatt_uV; 106ad3d13eeSDonggeun Kim 1073bb3dbbdSDonggeun Kim enum data_source battery_present; 1083bb3dbbdSDonggeun Kim 1093bb3dbbdSDonggeun Kim char **psy_charger_stat; 1103bb3dbbdSDonggeun Kim 1113bb3dbbdSDonggeun Kim int num_charger_regulators; 1123bb3dbbdSDonggeun Kim struct regulator_bulk_data *charger_regulators; 1133bb3dbbdSDonggeun Kim 1143bb3dbbdSDonggeun Kim char *psy_fuel_gauge; 1153bb3dbbdSDonggeun Kim 1163bb3dbbdSDonggeun Kim int (*temperature_out_of_range)(int *mC); 117ad3d13eeSDonggeun Kim bool measure_battery_temp; 1183bb3dbbdSDonggeun Kim }; 1193bb3dbbdSDonggeun Kim 1203bb3dbbdSDonggeun Kim #define PSY_NAME_MAX 30 1213bb3dbbdSDonggeun Kim 1223bb3dbbdSDonggeun Kim /** 1233bb3dbbdSDonggeun Kim * struct charger_manager 1243bb3dbbdSDonggeun Kim * @entry: entry for list 1253bb3dbbdSDonggeun Kim * @dev: device pointer 1263bb3dbbdSDonggeun Kim * @desc: instance of charger_desc 1273bb3dbbdSDonggeun Kim * @fuel_gauge: power_supply for fuel gauge 1283bb3dbbdSDonggeun Kim * @charger_stat: array of power_supply for chargers 1293bb3dbbdSDonggeun Kim * @charger_enabled: the state of charger 130d829dc75SChanwoo Choi * @fullbatt_vchk_jiffies_at: 131d829dc75SChanwoo Choi * jiffies at the time full battery check will occur. 132d829dc75SChanwoo Choi * @fullbatt_vchk_uV: voltage in microvolt 133d829dc75SChanwoo Choi * criteria for full battery 134d829dc75SChanwoo Choi * @fullbatt_vchk_work: work queue for full battery check 1353bb3dbbdSDonggeun Kim * @emergency_stop: 1363bb3dbbdSDonggeun Kim * When setting true, stop charging 1373bb3dbbdSDonggeun Kim * @last_temp_mC: the measured temperature in milli-Celsius 138ad3d13eeSDonggeun Kim * @psy_name_buf: the name of power-supply-class for charger manager 139ad3d13eeSDonggeun Kim * @charger_psy: power_supply for charger manager 1403bb3dbbdSDonggeun Kim * @status_save_ext_pwr_inserted: 1413bb3dbbdSDonggeun Kim * saved status of external power before entering suspend-to-RAM 1423bb3dbbdSDonggeun Kim * @status_save_batt: 1433bb3dbbdSDonggeun Kim * saved status of battery before entering suspend-to-RAM 1443bb3dbbdSDonggeun Kim */ 1453bb3dbbdSDonggeun Kim struct charger_manager { 1463bb3dbbdSDonggeun Kim struct list_head entry; 1473bb3dbbdSDonggeun Kim struct device *dev; 1483bb3dbbdSDonggeun Kim struct charger_desc *desc; 1493bb3dbbdSDonggeun Kim 1503bb3dbbdSDonggeun Kim struct power_supply *fuel_gauge; 1513bb3dbbdSDonggeun Kim struct power_supply **charger_stat; 1523bb3dbbdSDonggeun Kim 1533bb3dbbdSDonggeun Kim bool charger_enabled; 1543bb3dbbdSDonggeun Kim 155d829dc75SChanwoo Choi unsigned long fullbatt_vchk_jiffies_at; 156d829dc75SChanwoo Choi unsigned int fullbatt_vchk_uV; 157d829dc75SChanwoo Choi struct delayed_work fullbatt_vchk_work; 158d829dc75SChanwoo Choi 1593bb3dbbdSDonggeun Kim int emergency_stop; 1603bb3dbbdSDonggeun Kim int last_temp_mC; 1613bb3dbbdSDonggeun Kim 162ad3d13eeSDonggeun Kim char psy_name_buf[PSY_NAME_MAX + 1]; 163ad3d13eeSDonggeun Kim struct power_supply charger_psy; 164ad3d13eeSDonggeun Kim 1653bb3dbbdSDonggeun Kim bool status_save_ext_pwr_inserted; 1663bb3dbbdSDonggeun Kim bool status_save_batt; 1673bb3dbbdSDonggeun Kim }; 1683bb3dbbdSDonggeun Kim 1693bb3dbbdSDonggeun Kim #ifdef CONFIG_CHARGER_MANAGER 1703bb3dbbdSDonggeun Kim extern int setup_charger_manager(struct charger_global_desc *gd); 1713bb3dbbdSDonggeun Kim extern bool cm_suspend_again(void); 172*dfeccb12SChanwoo Choi extern void cm_notify_event(struct power_supply *psy, 173*dfeccb12SChanwoo Choi enum cm_event_types type, char *msg); 1743bb3dbbdSDonggeun Kim #else 175*dfeccb12SChanwoo Choi static inline int setup_charger_manager(struct charger_global_desc *gd) 176*dfeccb12SChanwoo Choi { return 0; } 177*dfeccb12SChanwoo Choi static inline bool cm_suspend_again(void) { return false; } 178*dfeccb12SChanwoo Choi static inline void cm_notify_event(struct power_supply *psy, 179*dfeccb12SChanwoo Choi enum cm_event_types type, char *msg) { } 1803bb3dbbdSDonggeun Kim #endif 1813bb3dbbdSDonggeun Kim #endif /* _CHARGER_MANAGER_H */ 182