blob: 241065c9ce51832962f0fce4c93696d4b09dcb9d [file] [log] [blame]
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +09001/*
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
20enum data_source {
Chanwoo Choid829dc72012-05-05 06:24:10 -070021 CM_BATTERY_PRESENT,
22 CM_NO_BATTERY,
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +090023 CM_FUEL_GAUGE,
24 CM_CHARGER_STAT,
25};
26
27enum polling_modes {
28 CM_POLL_DISABLE = 0,
29 CM_POLL_ALWAYS,
30 CM_POLL_EXTERNAL_POWER_ONLY,
31 CM_POLL_CHARGING_ONLY,
32};
33
Chanwoo Choidfeccb12012-05-05 06:26:47 -070034enum cm_event_types {
35 CM_EVENT_UNKNOWN = 0,
36 CM_EVENT_BATT_FULL,
37 CM_EVENT_BATT_IN,
38 CM_EVENT_BATT_OUT,
39 CM_EVENT_EXT_PWR_IN_OUT,
40 CM_EVENT_CHG_START_STOP,
41 CM_EVENT_OTHERS,
42};
43
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +090044/**
45 * struct charger_global_desc
46 * @rtc_name: the name of RTC used to wake up the system from suspend.
47 * @rtc_only_wakeup:
48 * If the system is woken up by waekup-sources other than the RTC or
49 * callbacks, Charger Manager should recognize with
50 * rtc_only_wakeup() returning false.
51 * If the RTC given to CM is the only wakeup reason,
52 * rtc_only_wakeup should return true.
Chanwoo Choid829dc72012-05-05 06:24:10 -070053 * @assume_timer_stops_in_suspend:
54 * Assume that the jiffy timer stops in suspend-to-RAM.
55 * When enabled, CM does not rely on jiffies value in
56 * suspend_again and assumes that jiffies value does not
57 * change during suspend.
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +090058 */
59struct charger_global_desc {
60 char *rtc_name;
61
62 bool (*rtc_only_wakeup)(void);
Chanwoo Choid829dc72012-05-05 06:24:10 -070063
64 bool assume_timer_stops_in_suspend;
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +090065};
66
67/**
68 * struct charger_desc
Donggeun Kimad3d13ee2011-12-27 18:47:49 +090069 * @psy_name: the name of power-supply-class for charger manager
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +090070 * @polling_mode:
71 * Determine which polling mode will be used
Chanwoo Choid829dc72012-05-05 06:24:10 -070072 * @fullbatt_vchkdrop_ms:
73 * @fullbatt_vchkdrop_uV:
74 * Check voltage drop after the battery is fully charged.
75 * If it has dropped more than fullbatt_vchkdrop_uV after
76 * fullbatt_vchkdrop_ms, CM will restart charging.
Donggeun Kimad3d13ee2011-12-27 18:47:49 +090077 * @fullbatt_uV: voltage in microvolt
78 * If it is not being charged and VBATT >= fullbatt_uV,
79 * it is assumed to be full.
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +090080 * @polling_interval_ms: interval in millisecond at which
81 * charger manager will monitor battery health
82 * @battery_present:
83 * Specify where information for existance of battery can be obtained
84 * @psy_charger_stat: the names of power-supply for chargers
85 * @num_charger_regulator: the number of entries in charger_regulators
86 * @charger_regulators: array of regulator_bulk_data for chargers
87 * @psy_fuel_gauge: the name of power-supply for fuel gauge
88 * @temperature_out_of_range:
89 * Determine whether the status is overheat or cold or normal.
90 * return_value > 0: overheat
91 * return_value == 0: normal
92 * return_value < 0: cold
Donggeun Kimad3d13ee2011-12-27 18:47:49 +090093 * @measure_battery_temp:
94 * true: measure battery temperature
95 * false: measure ambient temperature
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +090096 */
97struct charger_desc {
Donggeun Kimad3d13ee2011-12-27 18:47:49 +090098 char *psy_name;
99
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +0900100 enum polling_modes polling_mode;
101 unsigned int polling_interval_ms;
102
Chanwoo Choid829dc72012-05-05 06:24:10 -0700103 unsigned int fullbatt_vchkdrop_ms;
104 unsigned int fullbatt_vchkdrop_uV;
Donggeun Kimad3d13ee2011-12-27 18:47:49 +0900105 unsigned int fullbatt_uV;
106
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +0900107 enum data_source battery_present;
108
109 char **psy_charger_stat;
110
111 int num_charger_regulators;
112 struct regulator_bulk_data *charger_regulators;
113
114 char *psy_fuel_gauge;
115
116 int (*temperature_out_of_range)(int *mC);
Donggeun Kimad3d13ee2011-12-27 18:47:49 +0900117 bool measure_battery_temp;
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +0900118};
119
120#define PSY_NAME_MAX 30
121
122/**
123 * struct charger_manager
124 * @entry: entry for list
125 * @dev: device pointer
126 * @desc: instance of charger_desc
127 * @fuel_gauge: power_supply for fuel gauge
128 * @charger_stat: array of power_supply for chargers
129 * @charger_enabled: the state of charger
Chanwoo Choid829dc72012-05-05 06:24:10 -0700130 * @fullbatt_vchk_jiffies_at:
131 * jiffies at the time full battery check will occur.
132 * @fullbatt_vchk_uV: voltage in microvolt
133 * criteria for full battery
134 * @fullbatt_vchk_work: work queue for full battery check
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +0900135 * @emergency_stop:
136 * When setting true, stop charging
137 * @last_temp_mC: the measured temperature in milli-Celsius
Donggeun Kimad3d13ee2011-12-27 18:47:49 +0900138 * @psy_name_buf: the name of power-supply-class for charger manager
139 * @charger_psy: power_supply for charger manager
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +0900140 * @status_save_ext_pwr_inserted:
141 * saved status of external power before entering suspend-to-RAM
142 * @status_save_batt:
143 * saved status of battery before entering suspend-to-RAM
144 */
145struct charger_manager {
146 struct list_head entry;
147 struct device *dev;
148 struct charger_desc *desc;
149
150 struct power_supply *fuel_gauge;
151 struct power_supply **charger_stat;
152
153 bool charger_enabled;
154
Chanwoo Choid829dc72012-05-05 06:24:10 -0700155 unsigned long fullbatt_vchk_jiffies_at;
156 unsigned int fullbatt_vchk_uV;
157 struct delayed_work fullbatt_vchk_work;
158
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +0900159 int emergency_stop;
160 int last_temp_mC;
161
Donggeun Kimad3d13ee2011-12-27 18:47:49 +0900162 char psy_name_buf[PSY_NAME_MAX + 1];
163 struct power_supply charger_psy;
164
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +0900165 bool status_save_ext_pwr_inserted;
166 bool status_save_batt;
167};
168
169#ifdef CONFIG_CHARGER_MANAGER
170extern int setup_charger_manager(struct charger_global_desc *gd);
171extern bool cm_suspend_again(void);
Chanwoo Choidfeccb12012-05-05 06:26:47 -0700172extern void cm_notify_event(struct power_supply *psy,
173 enum cm_event_types type, char *msg);
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +0900174#else
Chanwoo Choidfeccb12012-05-05 06:26:47 -0700175static inline int setup_charger_manager(struct charger_global_desc *gd)
176{ return 0; }
177static inline bool cm_suspend_again(void) { return false; }
178static inline void cm_notify_event(struct power_supply *psy,
179 enum cm_event_types type, char *msg) { }
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +0900180#endif
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +0900181#endif /* _CHARGER_MANAGER_H */