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 { 213bb3dbbdSDonggeun Kim CM_FUEL_GAUGE, 223bb3dbbdSDonggeun Kim CM_CHARGER_STAT, 233bb3dbbdSDonggeun Kim }; 243bb3dbbdSDonggeun Kim 253bb3dbbdSDonggeun Kim enum polling_modes { 263bb3dbbdSDonggeun Kim CM_POLL_DISABLE = 0, 273bb3dbbdSDonggeun Kim CM_POLL_ALWAYS, 283bb3dbbdSDonggeun Kim CM_POLL_EXTERNAL_POWER_ONLY, 293bb3dbbdSDonggeun Kim CM_POLL_CHARGING_ONLY, 303bb3dbbdSDonggeun Kim }; 313bb3dbbdSDonggeun Kim 323bb3dbbdSDonggeun Kim /** 333bb3dbbdSDonggeun Kim * struct charger_global_desc 343bb3dbbdSDonggeun Kim * @rtc_name: the name of RTC used to wake up the system from suspend. 353bb3dbbdSDonggeun Kim * @rtc_only_wakeup: 363bb3dbbdSDonggeun Kim * If the system is woken up by waekup-sources other than the RTC or 373bb3dbbdSDonggeun Kim * callbacks, Charger Manager should recognize with 383bb3dbbdSDonggeun Kim * rtc_only_wakeup() returning false. 393bb3dbbdSDonggeun Kim * If the RTC given to CM is the only wakeup reason, 403bb3dbbdSDonggeun Kim * rtc_only_wakeup should return true. 413bb3dbbdSDonggeun Kim */ 423bb3dbbdSDonggeun Kim struct charger_global_desc { 433bb3dbbdSDonggeun Kim char *rtc_name; 443bb3dbbdSDonggeun Kim 453bb3dbbdSDonggeun Kim bool (*rtc_only_wakeup)(void); 463bb3dbbdSDonggeun Kim }; 473bb3dbbdSDonggeun Kim 483bb3dbbdSDonggeun Kim /** 493bb3dbbdSDonggeun Kim * struct charger_desc 50*ad3d13eeSDonggeun Kim * @psy_name: the name of power-supply-class for charger manager 513bb3dbbdSDonggeun Kim * @polling_mode: 523bb3dbbdSDonggeun Kim * Determine which polling mode will be used 53*ad3d13eeSDonggeun Kim * @fullbatt_uV: voltage in microvolt 54*ad3d13eeSDonggeun Kim * If it is not being charged and VBATT >= fullbatt_uV, 55*ad3d13eeSDonggeun Kim * it is assumed to be full. 563bb3dbbdSDonggeun Kim * @polling_interval_ms: interval in millisecond at which 573bb3dbbdSDonggeun Kim * charger manager will monitor battery health 583bb3dbbdSDonggeun Kim * @battery_present: 593bb3dbbdSDonggeun Kim * Specify where information for existance of battery can be obtained 603bb3dbbdSDonggeun Kim * @psy_charger_stat: the names of power-supply for chargers 613bb3dbbdSDonggeun Kim * @num_charger_regulator: the number of entries in charger_regulators 623bb3dbbdSDonggeun Kim * @charger_regulators: array of regulator_bulk_data for chargers 633bb3dbbdSDonggeun Kim * @psy_fuel_gauge: the name of power-supply for fuel gauge 643bb3dbbdSDonggeun Kim * @temperature_out_of_range: 653bb3dbbdSDonggeun Kim * Determine whether the status is overheat or cold or normal. 663bb3dbbdSDonggeun Kim * return_value > 0: overheat 673bb3dbbdSDonggeun Kim * return_value == 0: normal 683bb3dbbdSDonggeun Kim * return_value < 0: cold 69*ad3d13eeSDonggeun Kim * @measure_battery_temp: 70*ad3d13eeSDonggeun Kim * true: measure battery temperature 71*ad3d13eeSDonggeun Kim * false: measure ambient temperature 723bb3dbbdSDonggeun Kim */ 733bb3dbbdSDonggeun Kim struct charger_desc { 74*ad3d13eeSDonggeun Kim char *psy_name; 75*ad3d13eeSDonggeun Kim 763bb3dbbdSDonggeun Kim enum polling_modes polling_mode; 773bb3dbbdSDonggeun Kim unsigned int polling_interval_ms; 783bb3dbbdSDonggeun Kim 79*ad3d13eeSDonggeun Kim unsigned int fullbatt_uV; 80*ad3d13eeSDonggeun Kim 813bb3dbbdSDonggeun Kim enum data_source battery_present; 823bb3dbbdSDonggeun Kim 833bb3dbbdSDonggeun Kim char **psy_charger_stat; 843bb3dbbdSDonggeun Kim 853bb3dbbdSDonggeun Kim int num_charger_regulators; 863bb3dbbdSDonggeun Kim struct regulator_bulk_data *charger_regulators; 873bb3dbbdSDonggeun Kim 883bb3dbbdSDonggeun Kim char *psy_fuel_gauge; 893bb3dbbdSDonggeun Kim 903bb3dbbdSDonggeun Kim int (*temperature_out_of_range)(int *mC); 91*ad3d13eeSDonggeun Kim bool measure_battery_temp; 923bb3dbbdSDonggeun Kim }; 933bb3dbbdSDonggeun Kim 943bb3dbbdSDonggeun Kim #define PSY_NAME_MAX 30 953bb3dbbdSDonggeun Kim 963bb3dbbdSDonggeun Kim /** 973bb3dbbdSDonggeun Kim * struct charger_manager 983bb3dbbdSDonggeun Kim * @entry: entry for list 993bb3dbbdSDonggeun Kim * @dev: device pointer 1003bb3dbbdSDonggeun Kim * @desc: instance of charger_desc 1013bb3dbbdSDonggeun Kim * @fuel_gauge: power_supply for fuel gauge 1023bb3dbbdSDonggeun Kim * @charger_stat: array of power_supply for chargers 1033bb3dbbdSDonggeun Kim * @charger_enabled: the state of charger 1043bb3dbbdSDonggeun Kim * @emergency_stop: 1053bb3dbbdSDonggeun Kim * When setting true, stop charging 1063bb3dbbdSDonggeun Kim * @last_temp_mC: the measured temperature in milli-Celsius 107*ad3d13eeSDonggeun Kim * @psy_name_buf: the name of power-supply-class for charger manager 108*ad3d13eeSDonggeun Kim * @charger_psy: power_supply for charger manager 1093bb3dbbdSDonggeun Kim * @status_save_ext_pwr_inserted: 1103bb3dbbdSDonggeun Kim * saved status of external power before entering suspend-to-RAM 1113bb3dbbdSDonggeun Kim * @status_save_batt: 1123bb3dbbdSDonggeun Kim * saved status of battery before entering suspend-to-RAM 1133bb3dbbdSDonggeun Kim */ 1143bb3dbbdSDonggeun Kim struct charger_manager { 1153bb3dbbdSDonggeun Kim struct list_head entry; 1163bb3dbbdSDonggeun Kim struct device *dev; 1173bb3dbbdSDonggeun Kim struct charger_desc *desc; 1183bb3dbbdSDonggeun Kim 1193bb3dbbdSDonggeun Kim struct power_supply *fuel_gauge; 1203bb3dbbdSDonggeun Kim struct power_supply **charger_stat; 1213bb3dbbdSDonggeun Kim 1223bb3dbbdSDonggeun Kim bool charger_enabled; 1233bb3dbbdSDonggeun Kim 1243bb3dbbdSDonggeun Kim int emergency_stop; 1253bb3dbbdSDonggeun Kim int last_temp_mC; 1263bb3dbbdSDonggeun Kim 127*ad3d13eeSDonggeun Kim char psy_name_buf[PSY_NAME_MAX + 1]; 128*ad3d13eeSDonggeun Kim struct power_supply charger_psy; 129*ad3d13eeSDonggeun Kim 1303bb3dbbdSDonggeun Kim bool status_save_ext_pwr_inserted; 1313bb3dbbdSDonggeun Kim bool status_save_batt; 1323bb3dbbdSDonggeun Kim }; 1333bb3dbbdSDonggeun Kim 1343bb3dbbdSDonggeun Kim #ifdef CONFIG_CHARGER_MANAGER 1353bb3dbbdSDonggeun Kim extern int setup_charger_manager(struct charger_global_desc *gd); 1363bb3dbbdSDonggeun Kim extern bool cm_suspend_again(void); 1373bb3dbbdSDonggeun Kim #else 1383bb3dbbdSDonggeun Kim static void __maybe_unused setup_charger_manager(struct charger_global_desc *gd) 1393bb3dbbdSDonggeun Kim { } 1403bb3dbbdSDonggeun Kim 1413bb3dbbdSDonggeun Kim static bool __maybe_unused cm_suspend_again(void) 1423bb3dbbdSDonggeun Kim { 1433bb3dbbdSDonggeun Kim return false; 1443bb3dbbdSDonggeun Kim } 1453bb3dbbdSDonggeun Kim #endif 1463bb3dbbdSDonggeun Kim 1473bb3dbbdSDonggeun Kim #endif /* _CHARGER_MANAGER_H */ 148