Donggeun Kim | 3bb3dbb | 2011-12-27 18:47:48 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 Samsung Electronics Co., Ltd. |
| 3 | * MyungJoo.Ham <myungjoo.ham@samsung.com> |
| 4 | * |
| 5 | * Charger Manager. |
| 6 | * This framework enables to control and multiple chargers and to |
| 7 | * monitor charging even in the context of suspend-to-RAM with |
| 8 | * an interface combining the chargers. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 13 | **/ |
| 14 | |
| 15 | #ifndef _CHARGER_MANAGER_H |
| 16 | #define _CHARGER_MANAGER_H |
| 17 | |
| 18 | #include <linux/power_supply.h> |
| 19 | |
| 20 | enum data_source { |
Chanwoo Choi | d829dc7 | 2012-05-05 06:24:10 -0700 | [diff] [blame^] | 21 | CM_BATTERY_PRESENT, |
| 22 | CM_NO_BATTERY, |
Donggeun Kim | 3bb3dbb | 2011-12-27 18:47:48 +0900 | [diff] [blame] | 23 | CM_FUEL_GAUGE, |
| 24 | CM_CHARGER_STAT, |
| 25 | }; |
| 26 | |
| 27 | enum polling_modes { |
| 28 | CM_POLL_DISABLE = 0, |
| 29 | CM_POLL_ALWAYS, |
| 30 | CM_POLL_EXTERNAL_POWER_ONLY, |
| 31 | CM_POLL_CHARGING_ONLY, |
| 32 | }; |
| 33 | |
| 34 | /** |
| 35 | * struct charger_global_desc |
| 36 | * @rtc_name: the name of RTC used to wake up the system from suspend. |
| 37 | * @rtc_only_wakeup: |
| 38 | * If the system is woken up by waekup-sources other than the RTC or |
| 39 | * callbacks, Charger Manager should recognize with |
| 40 | * rtc_only_wakeup() returning false. |
| 41 | * If the RTC given to CM is the only wakeup reason, |
| 42 | * rtc_only_wakeup should return true. |
Chanwoo Choi | d829dc7 | 2012-05-05 06:24:10 -0700 | [diff] [blame^] | 43 | * @assume_timer_stops_in_suspend: |
| 44 | * Assume that the jiffy timer stops in suspend-to-RAM. |
| 45 | * When enabled, CM does not rely on jiffies value in |
| 46 | * suspend_again and assumes that jiffies value does not |
| 47 | * change during suspend. |
Donggeun Kim | 3bb3dbb | 2011-12-27 18:47:48 +0900 | [diff] [blame] | 48 | */ |
| 49 | struct charger_global_desc { |
| 50 | char *rtc_name; |
| 51 | |
| 52 | bool (*rtc_only_wakeup)(void); |
Chanwoo Choi | d829dc7 | 2012-05-05 06:24:10 -0700 | [diff] [blame^] | 53 | |
| 54 | bool assume_timer_stops_in_suspend; |
Donggeun Kim | 3bb3dbb | 2011-12-27 18:47:48 +0900 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | /** |
| 58 | * struct charger_desc |
Donggeun Kim | ad3d13ee | 2011-12-27 18:47:49 +0900 | [diff] [blame] | 59 | * @psy_name: the name of power-supply-class for charger manager |
Donggeun Kim | 3bb3dbb | 2011-12-27 18:47:48 +0900 | [diff] [blame] | 60 | * @polling_mode: |
| 61 | * Determine which polling mode will be used |
Chanwoo Choi | d829dc7 | 2012-05-05 06:24:10 -0700 | [diff] [blame^] | 62 | * @fullbatt_vchkdrop_ms: |
| 63 | * @fullbatt_vchkdrop_uV: |
| 64 | * Check voltage drop after the battery is fully charged. |
| 65 | * If it has dropped more than fullbatt_vchkdrop_uV after |
| 66 | * fullbatt_vchkdrop_ms, CM will restart charging. |
Donggeun Kim | ad3d13ee | 2011-12-27 18:47:49 +0900 | [diff] [blame] | 67 | * @fullbatt_uV: voltage in microvolt |
| 68 | * If it is not being charged and VBATT >= fullbatt_uV, |
| 69 | * it is assumed to be full. |
Donggeun Kim | 3bb3dbb | 2011-12-27 18:47:48 +0900 | [diff] [blame] | 70 | * @polling_interval_ms: interval in millisecond at which |
| 71 | * charger manager will monitor battery health |
| 72 | * @battery_present: |
| 73 | * Specify where information for existance of battery can be obtained |
| 74 | * @psy_charger_stat: the names of power-supply for chargers |
| 75 | * @num_charger_regulator: the number of entries in charger_regulators |
| 76 | * @charger_regulators: array of regulator_bulk_data for chargers |
| 77 | * @psy_fuel_gauge: the name of power-supply for fuel gauge |
| 78 | * @temperature_out_of_range: |
| 79 | * Determine whether the status is overheat or cold or normal. |
| 80 | * return_value > 0: overheat |
| 81 | * return_value == 0: normal |
| 82 | * return_value < 0: cold |
Donggeun Kim | ad3d13ee | 2011-12-27 18:47:49 +0900 | [diff] [blame] | 83 | * @measure_battery_temp: |
| 84 | * true: measure battery temperature |
| 85 | * false: measure ambient temperature |
Donggeun Kim | 3bb3dbb | 2011-12-27 18:47:48 +0900 | [diff] [blame] | 86 | */ |
| 87 | struct charger_desc { |
Donggeun Kim | ad3d13ee | 2011-12-27 18:47:49 +0900 | [diff] [blame] | 88 | char *psy_name; |
| 89 | |
Donggeun Kim | 3bb3dbb | 2011-12-27 18:47:48 +0900 | [diff] [blame] | 90 | enum polling_modes polling_mode; |
| 91 | unsigned int polling_interval_ms; |
| 92 | |
Chanwoo Choi | d829dc7 | 2012-05-05 06:24:10 -0700 | [diff] [blame^] | 93 | unsigned int fullbatt_vchkdrop_ms; |
| 94 | unsigned int fullbatt_vchkdrop_uV; |
Donggeun Kim | ad3d13ee | 2011-12-27 18:47:49 +0900 | [diff] [blame] | 95 | unsigned int fullbatt_uV; |
| 96 | |
Donggeun Kim | 3bb3dbb | 2011-12-27 18:47:48 +0900 | [diff] [blame] | 97 | enum data_source battery_present; |
| 98 | |
| 99 | char **psy_charger_stat; |
| 100 | |
| 101 | int num_charger_regulators; |
| 102 | struct regulator_bulk_data *charger_regulators; |
| 103 | |
| 104 | char *psy_fuel_gauge; |
| 105 | |
| 106 | int (*temperature_out_of_range)(int *mC); |
Donggeun Kim | ad3d13ee | 2011-12-27 18:47:49 +0900 | [diff] [blame] | 107 | bool measure_battery_temp; |
Donggeun Kim | 3bb3dbb | 2011-12-27 18:47:48 +0900 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | #define PSY_NAME_MAX 30 |
| 111 | |
| 112 | /** |
| 113 | * struct charger_manager |
| 114 | * @entry: entry for list |
| 115 | * @dev: device pointer |
| 116 | * @desc: instance of charger_desc |
| 117 | * @fuel_gauge: power_supply for fuel gauge |
| 118 | * @charger_stat: array of power_supply for chargers |
| 119 | * @charger_enabled: the state of charger |
Chanwoo Choi | d829dc7 | 2012-05-05 06:24:10 -0700 | [diff] [blame^] | 120 | * @fullbatt_vchk_jiffies_at: |
| 121 | * jiffies at the time full battery check will occur. |
| 122 | * @fullbatt_vchk_uV: voltage in microvolt |
| 123 | * criteria for full battery |
| 124 | * @fullbatt_vchk_work: work queue for full battery check |
Donggeun Kim | 3bb3dbb | 2011-12-27 18:47:48 +0900 | [diff] [blame] | 125 | * @emergency_stop: |
| 126 | * When setting true, stop charging |
| 127 | * @last_temp_mC: the measured temperature in milli-Celsius |
Donggeun Kim | ad3d13ee | 2011-12-27 18:47:49 +0900 | [diff] [blame] | 128 | * @psy_name_buf: the name of power-supply-class for charger manager |
| 129 | * @charger_psy: power_supply for charger manager |
Donggeun Kim | 3bb3dbb | 2011-12-27 18:47:48 +0900 | [diff] [blame] | 130 | * @status_save_ext_pwr_inserted: |
| 131 | * saved status of external power before entering suspend-to-RAM |
| 132 | * @status_save_batt: |
| 133 | * saved status of battery before entering suspend-to-RAM |
| 134 | */ |
| 135 | struct charger_manager { |
| 136 | struct list_head entry; |
| 137 | struct device *dev; |
| 138 | struct charger_desc *desc; |
| 139 | |
| 140 | struct power_supply *fuel_gauge; |
| 141 | struct power_supply **charger_stat; |
| 142 | |
| 143 | bool charger_enabled; |
| 144 | |
Chanwoo Choi | d829dc7 | 2012-05-05 06:24:10 -0700 | [diff] [blame^] | 145 | unsigned long fullbatt_vchk_jiffies_at; |
| 146 | unsigned int fullbatt_vchk_uV; |
| 147 | struct delayed_work fullbatt_vchk_work; |
| 148 | |
Donggeun Kim | 3bb3dbb | 2011-12-27 18:47:48 +0900 | [diff] [blame] | 149 | int emergency_stop; |
| 150 | int last_temp_mC; |
| 151 | |
Donggeun Kim | ad3d13ee | 2011-12-27 18:47:49 +0900 | [diff] [blame] | 152 | char psy_name_buf[PSY_NAME_MAX + 1]; |
| 153 | struct power_supply charger_psy; |
| 154 | |
Donggeun Kim | 3bb3dbb | 2011-12-27 18:47:48 +0900 | [diff] [blame] | 155 | bool status_save_ext_pwr_inserted; |
| 156 | bool status_save_batt; |
| 157 | }; |
| 158 | |
| 159 | #ifdef CONFIG_CHARGER_MANAGER |
| 160 | extern int setup_charger_manager(struct charger_global_desc *gd); |
| 161 | extern bool cm_suspend_again(void); |
| 162 | #else |
| 163 | static void __maybe_unused setup_charger_manager(struct charger_global_desc *gd) |
| 164 | { } |
| 165 | |
| 166 | static bool __maybe_unused cm_suspend_again(void) |
| 167 | { |
| 168 | return false; |
| 169 | } |
| 170 | #endif |
| 171 | |
| 172 | #endif /* _CHARGER_MANAGER_H */ |