Merge branch 'upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/floppy...
[linux-drm-fsl-dcu.git] / include / linux / power / charger-manager.h
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_BATTERY_PRESENT,
22         CM_NO_BATTERY,
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 enum 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
44 /**
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.
53  * @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.
58  */
59 struct charger_global_desc {
60         char *rtc_name;
61
62         bool (*rtc_only_wakeup)(void);
63
64         bool assume_timer_stops_in_suspend;
65 };
66
67 /**
68  * struct charger_desc
69  * @psy_name: the name of power-supply-class for charger manager
70  * @polling_mode:
71  *      Determine which polling mode will be used
72  * @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.
77  * @fullbatt_uV: voltage in microvolt
78  *      If it is not being charged and VBATT >= fullbatt_uV,
79  *      it is assumed to be full.
80  * @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
93  * @measure_battery_temp:
94  *      true: measure battery temperature
95  *      false: measure ambient temperature
96  */
97 struct charger_desc {
98         char *psy_name;
99
100         enum polling_modes polling_mode;
101         unsigned int polling_interval_ms;
102
103         unsigned int fullbatt_vchkdrop_ms;
104         unsigned int fullbatt_vchkdrop_uV;
105         unsigned int fullbatt_uV;
106
107         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);
117         bool measure_battery_temp;
118 };
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
130  * @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
135  * @emergency_stop:
136  *      When setting true, stop charging
137  * @last_temp_mC: the measured temperature in milli-Celsius
138  * @psy_name_buf: the name of power-supply-class for charger manager
139  * @charger_psy: power_supply for charger manager
140  * @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  */
145 struct 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
155         unsigned long fullbatt_vchk_jiffies_at;
156         unsigned int fullbatt_vchk_uV;
157         struct delayed_work fullbatt_vchk_work;
158
159         int emergency_stop;
160         int last_temp_mC;
161
162         char psy_name_buf[PSY_NAME_MAX + 1];
163         struct power_supply charger_psy;
164
165         bool status_save_ext_pwr_inserted;
166         bool status_save_batt;
167 };
168
169 #ifdef CONFIG_CHARGER_MANAGER
170 extern int setup_charger_manager(struct charger_global_desc *gd);
171 extern bool cm_suspend_again(void);
172 extern void cm_notify_event(struct power_supply *psy,
173                                 enum cm_event_types type, char *msg);
174 #else
175 static inline int setup_charger_manager(struct charger_global_desc *gd)
176 { return 0; }
177 static inline bool cm_suspend_again(void) { return false; }
178 static inline void cm_notify_event(struct power_supply *psy,
179                                 enum cm_event_types type, char *msg) { }
180 #endif
181 #endif /* _CHARGER_MANAGER_H */