blob: baa299a95e13c65581ccaef4c98b4ea8becbad50 [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
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 Choid829dc72012-05-05 06:24:10 -070043 * @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 Kim3bb3dbb2011-12-27 18:47:48 +090048 */
49struct charger_global_desc {
50 char *rtc_name;
51
52 bool (*rtc_only_wakeup)(void);
Chanwoo Choid829dc72012-05-05 06:24:10 -070053
54 bool assume_timer_stops_in_suspend;
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +090055};
56
57/**
58 * struct charger_desc
Donggeun Kimad3d13ee2011-12-27 18:47:49 +090059 * @psy_name: the name of power-supply-class for charger manager
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +090060 * @polling_mode:
61 * Determine which polling mode will be used
Chanwoo Choid829dc72012-05-05 06:24:10 -070062 * @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 Kimad3d13ee2011-12-27 18:47:49 +090067 * @fullbatt_uV: voltage in microvolt
68 * If it is not being charged and VBATT >= fullbatt_uV,
69 * it is assumed to be full.
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +090070 * @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 Kimad3d13ee2011-12-27 18:47:49 +090083 * @measure_battery_temp:
84 * true: measure battery temperature
85 * false: measure ambient temperature
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +090086 */
87struct charger_desc {
Donggeun Kimad3d13ee2011-12-27 18:47:49 +090088 char *psy_name;
89
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +090090 enum polling_modes polling_mode;
91 unsigned int polling_interval_ms;
92
Chanwoo Choid829dc72012-05-05 06:24:10 -070093 unsigned int fullbatt_vchkdrop_ms;
94 unsigned int fullbatt_vchkdrop_uV;
Donggeun Kimad3d13ee2011-12-27 18:47:49 +090095 unsigned int fullbatt_uV;
96
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +090097 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 Kimad3d13ee2011-12-27 18:47:49 +0900107 bool measure_battery_temp;
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +0900108};
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 Choid829dc72012-05-05 06:24:10 -0700120 * @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 Kim3bb3dbb2011-12-27 18:47:48 +0900125 * @emergency_stop:
126 * When setting true, stop charging
127 * @last_temp_mC: the measured temperature in milli-Celsius
Donggeun Kimad3d13ee2011-12-27 18:47:49 +0900128 * @psy_name_buf: the name of power-supply-class for charger manager
129 * @charger_psy: power_supply for charger manager
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +0900130 * @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 */
135struct 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 Choid829dc72012-05-05 06:24:10 -0700145 unsigned long fullbatt_vchk_jiffies_at;
146 unsigned int fullbatt_vchk_uV;
147 struct delayed_work fullbatt_vchk_work;
148
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +0900149 int emergency_stop;
150 int last_temp_mC;
151
Donggeun Kimad3d13ee2011-12-27 18:47:49 +0900152 char psy_name_buf[PSY_NAME_MAX + 1];
153 struct power_supply charger_psy;
154
Donggeun Kim3bb3dbb2011-12-27 18:47:48 +0900155 bool status_save_ext_pwr_inserted;
156 bool status_save_batt;
157};
158
159#ifdef CONFIG_CHARGER_MANAGER
160extern int setup_charger_manager(struct charger_global_desc *gd);
161extern bool cm_suspend_again(void);
162#else
163static void __maybe_unused setup_charger_manager(struct charger_global_desc *gd)
164{ }
165
166static bool __maybe_unused cm_suspend_again(void)
167{
168 return false;
169}
170#endif
171
172#endif /* _CHARGER_MANAGER_H */