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 { |
| 21 | CM_FUEL_GAUGE, |
| 22 | CM_CHARGER_STAT, |
| 23 | }; |
| 24 | |
| 25 | enum polling_modes { |
| 26 | CM_POLL_DISABLE = 0, |
| 27 | CM_POLL_ALWAYS, |
| 28 | CM_POLL_EXTERNAL_POWER_ONLY, |
| 29 | CM_POLL_CHARGING_ONLY, |
| 30 | }; |
| 31 | |
| 32 | /** |
| 33 | * struct charger_global_desc |
| 34 | * @rtc_name: the name of RTC used to wake up the system from suspend. |
| 35 | * @rtc_only_wakeup: |
| 36 | * If the system is woken up by waekup-sources other than the RTC or |
| 37 | * callbacks, Charger Manager should recognize with |
| 38 | * rtc_only_wakeup() returning false. |
| 39 | * If the RTC given to CM is the only wakeup reason, |
| 40 | * rtc_only_wakeup should return true. |
| 41 | */ |
| 42 | struct charger_global_desc { |
| 43 | char *rtc_name; |
| 44 | |
| 45 | bool (*rtc_only_wakeup)(void); |
| 46 | }; |
| 47 | |
| 48 | /** |
| 49 | * struct charger_desc |
Donggeun Kim | ad3d13ee | 2011-12-27 18:47:49 +0900 | [diff] [blame] | 50 | * @psy_name: the name of power-supply-class for charger manager |
Donggeun Kim | 3bb3dbb | 2011-12-27 18:47:48 +0900 | [diff] [blame] | 51 | * @polling_mode: |
| 52 | * Determine which polling mode will be used |
Donggeun Kim | ad3d13ee | 2011-12-27 18:47:49 +0900 | [diff] [blame] | 53 | * @fullbatt_uV: voltage in microvolt |
| 54 | * If it is not being charged and VBATT >= fullbatt_uV, |
| 55 | * it is assumed to be full. |
Donggeun Kim | 3bb3dbb | 2011-12-27 18:47:48 +0900 | [diff] [blame] | 56 | * @polling_interval_ms: interval in millisecond at which |
| 57 | * charger manager will monitor battery health |
| 58 | * @battery_present: |
| 59 | * Specify where information for existance of battery can be obtained |
| 60 | * @psy_charger_stat: the names of power-supply for chargers |
| 61 | * @num_charger_regulator: the number of entries in charger_regulators |
| 62 | * @charger_regulators: array of regulator_bulk_data for chargers |
| 63 | * @psy_fuel_gauge: the name of power-supply for fuel gauge |
| 64 | * @temperature_out_of_range: |
| 65 | * Determine whether the status is overheat or cold or normal. |
| 66 | * return_value > 0: overheat |
| 67 | * return_value == 0: normal |
| 68 | * return_value < 0: cold |
Donggeun Kim | ad3d13ee | 2011-12-27 18:47:49 +0900 | [diff] [blame] | 69 | * @measure_battery_temp: |
| 70 | * true: measure battery temperature |
| 71 | * false: measure ambient temperature |
Donggeun Kim | 3bb3dbb | 2011-12-27 18:47:48 +0900 | [diff] [blame] | 72 | */ |
| 73 | struct charger_desc { |
Donggeun Kim | ad3d13ee | 2011-12-27 18:47:49 +0900 | [diff] [blame] | 74 | char *psy_name; |
| 75 | |
Donggeun Kim | 3bb3dbb | 2011-12-27 18:47:48 +0900 | [diff] [blame] | 76 | enum polling_modes polling_mode; |
| 77 | unsigned int polling_interval_ms; |
| 78 | |
Donggeun Kim | ad3d13ee | 2011-12-27 18:47:49 +0900 | [diff] [blame] | 79 | unsigned int fullbatt_uV; |
| 80 | |
Donggeun Kim | 3bb3dbb | 2011-12-27 18:47:48 +0900 | [diff] [blame] | 81 | enum data_source battery_present; |
| 82 | |
| 83 | char **psy_charger_stat; |
| 84 | |
| 85 | int num_charger_regulators; |
| 86 | struct regulator_bulk_data *charger_regulators; |
| 87 | |
| 88 | char *psy_fuel_gauge; |
| 89 | |
| 90 | int (*temperature_out_of_range)(int *mC); |
Donggeun Kim | ad3d13ee | 2011-12-27 18:47:49 +0900 | [diff] [blame] | 91 | bool measure_battery_temp; |
Donggeun Kim | 3bb3dbb | 2011-12-27 18:47:48 +0900 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | #define PSY_NAME_MAX 30 |
| 95 | |
| 96 | /** |
| 97 | * struct charger_manager |
| 98 | * @entry: entry for list |
| 99 | * @dev: device pointer |
| 100 | * @desc: instance of charger_desc |
| 101 | * @fuel_gauge: power_supply for fuel gauge |
| 102 | * @charger_stat: array of power_supply for chargers |
| 103 | * @charger_enabled: the state of charger |
| 104 | * @emergency_stop: |
| 105 | * When setting true, stop charging |
| 106 | * @last_temp_mC: the measured temperature in milli-Celsius |
Donggeun Kim | ad3d13ee | 2011-12-27 18:47:49 +0900 | [diff] [blame] | 107 | * @psy_name_buf: the name of power-supply-class for charger manager |
| 108 | * @charger_psy: power_supply for charger manager |
Donggeun Kim | 3bb3dbb | 2011-12-27 18:47:48 +0900 | [diff] [blame] | 109 | * @status_save_ext_pwr_inserted: |
| 110 | * saved status of external power before entering suspend-to-RAM |
| 111 | * @status_save_batt: |
| 112 | * saved status of battery before entering suspend-to-RAM |
| 113 | */ |
| 114 | struct charger_manager { |
| 115 | struct list_head entry; |
| 116 | struct device *dev; |
| 117 | struct charger_desc *desc; |
| 118 | |
| 119 | struct power_supply *fuel_gauge; |
| 120 | struct power_supply **charger_stat; |
| 121 | |
| 122 | bool charger_enabled; |
| 123 | |
| 124 | int emergency_stop; |
| 125 | int last_temp_mC; |
| 126 | |
Donggeun Kim | ad3d13ee | 2011-12-27 18:47:49 +0900 | [diff] [blame] | 127 | char psy_name_buf[PSY_NAME_MAX + 1]; |
| 128 | struct power_supply charger_psy; |
| 129 | |
Donggeun Kim | 3bb3dbb | 2011-12-27 18:47:48 +0900 | [diff] [blame] | 130 | bool status_save_ext_pwr_inserted; |
| 131 | bool status_save_batt; |
| 132 | }; |
| 133 | |
| 134 | #ifdef CONFIG_CHARGER_MANAGER |
| 135 | extern int setup_charger_manager(struct charger_global_desc *gd); |
| 136 | extern bool cm_suspend_again(void); |
| 137 | #else |
| 138 | static void __maybe_unused setup_charger_manager(struct charger_global_desc *gd) |
| 139 | { } |
| 140 | |
| 141 | static bool __maybe_unused cm_suspend_again(void) |
| 142 | { |
| 143 | return false; |
| 144 | } |
| 145 | #endif |
| 146 | |
| 147 | #endif /* _CHARGER_MANAGER_H */ |