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 { 21*d829dc75SChanwoo Choi CM_BATTERY_PRESENT, 22*d829dc75SChanwoo 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 343bb3dbbdSDonggeun Kim /** 353bb3dbbdSDonggeun Kim * struct charger_global_desc 363bb3dbbdSDonggeun Kim * @rtc_name: the name of RTC used to wake up the system from suspend. 373bb3dbbdSDonggeun Kim * @rtc_only_wakeup: 383bb3dbbdSDonggeun Kim * If the system is woken up by waekup-sources other than the RTC or 393bb3dbbdSDonggeun Kim * callbacks, Charger Manager should recognize with 403bb3dbbdSDonggeun Kim * rtc_only_wakeup() returning false. 413bb3dbbdSDonggeun Kim * If the RTC given to CM is the only wakeup reason, 423bb3dbbdSDonggeun Kim * rtc_only_wakeup should return true. 43*d829dc75SChanwoo Choi * @assume_timer_stops_in_suspend: 44*d829dc75SChanwoo Choi * Assume that the jiffy timer stops in suspend-to-RAM. 45*d829dc75SChanwoo Choi * When enabled, CM does not rely on jiffies value in 46*d829dc75SChanwoo Choi * suspend_again and assumes that jiffies value does not 47*d829dc75SChanwoo Choi * change during suspend. 483bb3dbbdSDonggeun Kim */ 493bb3dbbdSDonggeun Kim struct charger_global_desc { 503bb3dbbdSDonggeun Kim char *rtc_name; 513bb3dbbdSDonggeun Kim 523bb3dbbdSDonggeun Kim bool (*rtc_only_wakeup)(void); 53*d829dc75SChanwoo Choi 54*d829dc75SChanwoo Choi bool assume_timer_stops_in_suspend; 553bb3dbbdSDonggeun Kim }; 563bb3dbbdSDonggeun Kim 573bb3dbbdSDonggeun Kim /** 583bb3dbbdSDonggeun Kim * struct charger_desc 59ad3d13eeSDonggeun Kim * @psy_name: the name of power-supply-class for charger manager 603bb3dbbdSDonggeun Kim * @polling_mode: 613bb3dbbdSDonggeun Kim * Determine which polling mode will be used 62*d829dc75SChanwoo Choi * @fullbatt_vchkdrop_ms: 63*d829dc75SChanwoo Choi * @fullbatt_vchkdrop_uV: 64*d829dc75SChanwoo Choi * Check voltage drop after the battery is fully charged. 65*d829dc75SChanwoo Choi * If it has dropped more than fullbatt_vchkdrop_uV after 66*d829dc75SChanwoo Choi * fullbatt_vchkdrop_ms, CM will restart charging. 67ad3d13eeSDonggeun Kim * @fullbatt_uV: voltage in microvolt 68ad3d13eeSDonggeun Kim * If it is not being charged and VBATT >= fullbatt_uV, 69ad3d13eeSDonggeun Kim * it is assumed to be full. 703bb3dbbdSDonggeun Kim * @polling_interval_ms: interval in millisecond at which 713bb3dbbdSDonggeun Kim * charger manager will monitor battery health 723bb3dbbdSDonggeun Kim * @battery_present: 733bb3dbbdSDonggeun Kim * Specify where information for existance of battery can be obtained 743bb3dbbdSDonggeun Kim * @psy_charger_stat: the names of power-supply for chargers 753bb3dbbdSDonggeun Kim * @num_charger_regulator: the number of entries in charger_regulators 763bb3dbbdSDonggeun Kim * @charger_regulators: array of regulator_bulk_data for chargers 773bb3dbbdSDonggeun Kim * @psy_fuel_gauge: the name of power-supply for fuel gauge 783bb3dbbdSDonggeun Kim * @temperature_out_of_range: 793bb3dbbdSDonggeun Kim * Determine whether the status is overheat or cold or normal. 803bb3dbbdSDonggeun Kim * return_value > 0: overheat 813bb3dbbdSDonggeun Kim * return_value == 0: normal 823bb3dbbdSDonggeun Kim * return_value < 0: cold 83ad3d13eeSDonggeun Kim * @measure_battery_temp: 84ad3d13eeSDonggeun Kim * true: measure battery temperature 85ad3d13eeSDonggeun Kim * false: measure ambient temperature 863bb3dbbdSDonggeun Kim */ 873bb3dbbdSDonggeun Kim struct charger_desc { 88ad3d13eeSDonggeun Kim char *psy_name; 89ad3d13eeSDonggeun Kim 903bb3dbbdSDonggeun Kim enum polling_modes polling_mode; 913bb3dbbdSDonggeun Kim unsigned int polling_interval_ms; 923bb3dbbdSDonggeun Kim 93*d829dc75SChanwoo Choi unsigned int fullbatt_vchkdrop_ms; 94*d829dc75SChanwoo Choi unsigned int fullbatt_vchkdrop_uV; 95ad3d13eeSDonggeun Kim unsigned int fullbatt_uV; 96ad3d13eeSDonggeun Kim 973bb3dbbdSDonggeun Kim enum data_source battery_present; 983bb3dbbdSDonggeun Kim 993bb3dbbdSDonggeun Kim char **psy_charger_stat; 1003bb3dbbdSDonggeun Kim 1013bb3dbbdSDonggeun Kim int num_charger_regulators; 1023bb3dbbdSDonggeun Kim struct regulator_bulk_data *charger_regulators; 1033bb3dbbdSDonggeun Kim 1043bb3dbbdSDonggeun Kim char *psy_fuel_gauge; 1053bb3dbbdSDonggeun Kim 1063bb3dbbdSDonggeun Kim int (*temperature_out_of_range)(int *mC); 107ad3d13eeSDonggeun Kim bool measure_battery_temp; 1083bb3dbbdSDonggeun Kim }; 1093bb3dbbdSDonggeun Kim 1103bb3dbbdSDonggeun Kim #define PSY_NAME_MAX 30 1113bb3dbbdSDonggeun Kim 1123bb3dbbdSDonggeun Kim /** 1133bb3dbbdSDonggeun Kim * struct charger_manager 1143bb3dbbdSDonggeun Kim * @entry: entry for list 1153bb3dbbdSDonggeun Kim * @dev: device pointer 1163bb3dbbdSDonggeun Kim * @desc: instance of charger_desc 1173bb3dbbdSDonggeun Kim * @fuel_gauge: power_supply for fuel gauge 1183bb3dbbdSDonggeun Kim * @charger_stat: array of power_supply for chargers 1193bb3dbbdSDonggeun Kim * @charger_enabled: the state of charger 120*d829dc75SChanwoo Choi * @fullbatt_vchk_jiffies_at: 121*d829dc75SChanwoo Choi * jiffies at the time full battery check will occur. 122*d829dc75SChanwoo Choi * @fullbatt_vchk_uV: voltage in microvolt 123*d829dc75SChanwoo Choi * criteria for full battery 124*d829dc75SChanwoo Choi * @fullbatt_vchk_work: work queue for full battery check 1253bb3dbbdSDonggeun Kim * @emergency_stop: 1263bb3dbbdSDonggeun Kim * When setting true, stop charging 1273bb3dbbdSDonggeun Kim * @last_temp_mC: the measured temperature in milli-Celsius 128ad3d13eeSDonggeun Kim * @psy_name_buf: the name of power-supply-class for charger manager 129ad3d13eeSDonggeun Kim * @charger_psy: power_supply for charger manager 1303bb3dbbdSDonggeun Kim * @status_save_ext_pwr_inserted: 1313bb3dbbdSDonggeun Kim * saved status of external power before entering suspend-to-RAM 1323bb3dbbdSDonggeun Kim * @status_save_batt: 1333bb3dbbdSDonggeun Kim * saved status of battery before entering suspend-to-RAM 1343bb3dbbdSDonggeun Kim */ 1353bb3dbbdSDonggeun Kim struct charger_manager { 1363bb3dbbdSDonggeun Kim struct list_head entry; 1373bb3dbbdSDonggeun Kim struct device *dev; 1383bb3dbbdSDonggeun Kim struct charger_desc *desc; 1393bb3dbbdSDonggeun Kim 1403bb3dbbdSDonggeun Kim struct power_supply *fuel_gauge; 1413bb3dbbdSDonggeun Kim struct power_supply **charger_stat; 1423bb3dbbdSDonggeun Kim 1433bb3dbbdSDonggeun Kim bool charger_enabled; 1443bb3dbbdSDonggeun Kim 145*d829dc75SChanwoo Choi unsigned long fullbatt_vchk_jiffies_at; 146*d829dc75SChanwoo Choi unsigned int fullbatt_vchk_uV; 147*d829dc75SChanwoo Choi struct delayed_work fullbatt_vchk_work; 148*d829dc75SChanwoo Choi 1493bb3dbbdSDonggeun Kim int emergency_stop; 1503bb3dbbdSDonggeun Kim int last_temp_mC; 1513bb3dbbdSDonggeun Kim 152ad3d13eeSDonggeun Kim char psy_name_buf[PSY_NAME_MAX + 1]; 153ad3d13eeSDonggeun Kim struct power_supply charger_psy; 154ad3d13eeSDonggeun Kim 1553bb3dbbdSDonggeun Kim bool status_save_ext_pwr_inserted; 1563bb3dbbdSDonggeun Kim bool status_save_batt; 1573bb3dbbdSDonggeun Kim }; 1583bb3dbbdSDonggeun Kim 1593bb3dbbdSDonggeun Kim #ifdef CONFIG_CHARGER_MANAGER 1603bb3dbbdSDonggeun Kim extern int setup_charger_manager(struct charger_global_desc *gd); 1613bb3dbbdSDonggeun Kim extern bool cm_suspend_again(void); 1623bb3dbbdSDonggeun Kim #else 1633bb3dbbdSDonggeun Kim static void __maybe_unused setup_charger_manager(struct charger_global_desc *gd) 1643bb3dbbdSDonggeun Kim { } 1653bb3dbbdSDonggeun Kim 1663bb3dbbdSDonggeun Kim static bool __maybe_unused cm_suspend_again(void) 1673bb3dbbdSDonggeun Kim { 1683bb3dbbdSDonggeun Kim return false; 1693bb3dbbdSDonggeun Kim } 1703bb3dbbdSDonggeun Kim #endif 1713bb3dbbdSDonggeun Kim 1723bb3dbbdSDonggeun Kim #endif /* _CHARGER_MANAGER_H */ 173