|
5 | 5 | * Battery pack vendor provided charging profile
|
6 | 6 | */
|
7 | 7 |
|
| 8 | +#include "adc.h" |
| 9 | +#include "adc_chip.h" |
8 | 10 | #include "battery.h"
|
9 | 11 | #include "battery_smart.h"
|
10 | 12 | #include "charge_state.h"
|
|
17 | 19 | #define PARAM_CUT_OFF_LOW 0x10
|
18 | 20 | #define PARAM_CUT_OFF_HIGH 0x00
|
19 | 21 |
|
20 |
| -/* Battery info for BQ40Z55 */ |
| 22 | +/* Battery info for BQ40Z50 */ |
21 | 23 | static const struct battery_info info = {
|
22 |
| - .voltage_max = 8700, /* mV */ |
23 |
| - .voltage_normal = 7600, |
| 24 | + .voltage_max = 17600, /* mV */ |
| 25 | + .voltage_normal = 15400, |
24 | 26 | .voltage_min = 6000,
|
25 |
| - .precharge_current = 256, /* mA */ |
| 27 | + .precharge_current = 72, /* mA */ |
26 | 28 | .start_charging_min_c = 0,
|
27 |
| - .start_charging_max_c = 46, |
| 29 | + .start_charging_max_c = 47, |
28 | 30 | .charging_min_c = 0,
|
29 |
| - .charging_max_c = 60, |
| 31 | + .charging_max_c = 52, |
30 | 32 | .discharging_min_c = 0,
|
31 |
| - .discharging_max_c = 60, |
| 33 | + .discharging_max_c = 62, |
32 | 34 | };
|
33 | 35 |
|
34 | 36 | const struct battery_info *battery_get_info(void)
|
@@ -56,175 +58,17 @@ int board_cut_off_battery(void)
|
56 | 58 | return rv;
|
57 | 59 | }
|
58 | 60 |
|
59 |
| -#ifdef CONFIG_CHARGER_PROFILE_OVERRIDE |
60 |
| - |
61 |
| -static int fast_charging_allowed = 1; |
62 |
| - |
63 |
| -/* |
64 |
| - * This can override the smart battery's charging profile. To make a change, |
65 |
| - * modify one or more of requested_voltage, requested_current, or state. |
66 |
| - * Leave everything else unchanged. |
67 |
| - * |
68 |
| - * Return the next poll period in usec, or zero to use the default (which is |
69 |
| - * state dependent). |
70 |
| - */ |
71 |
| -int charger_profile_override(struct charge_state_data *curr) |
| 61 | +enum battery_present battery_is_present(void) |
72 | 62 | {
|
73 |
| - /* temp in 0.1 deg C */ |
74 |
| - int temp_c = curr->batt.temperature - 2731; |
75 |
| - /* keep track of last temperature range for hysteresis */ |
76 |
| - static enum { |
77 |
| - TEMP_RANGE_1, |
78 |
| - TEMP_RANGE_2, |
79 |
| - TEMP_RANGE_3, |
80 |
| - TEMP_RANGE_4, |
81 |
| - TEMP_RANGE_5, |
82 |
| - } temp_range = TEMP_RANGE_3; |
83 |
| - /* keep track of last voltage range for hysteresis */ |
84 |
| - static enum { |
85 |
| - VOLTAGE_RANGE_LOW, |
86 |
| - VOLTAGE_RANGE_HIGH, |
87 |
| - } voltage_range = VOLTAGE_RANGE_LOW; |
88 |
| - |
89 |
| - /* Current and previous battery voltage */ |
90 |
| - int batt_voltage; |
91 |
| - static int prev_batt_voltage; |
| 63 | + enum battery_present bp; |
| 64 | + int mv; |
92 | 65 |
|
93 |
| - /* |
94 |
| - * Determine temperature range. The five ranges are: |
95 |
| - * < 10C |
96 |
| - * 10-15C |
97 |
| - * 15-23C |
98 |
| - * 23-45C |
99 |
| - * > 45C |
100 |
| - * |
101 |
| - * Add 0.2 degrees of hysteresis. |
102 |
| - * If temp reading was bad, use last range. |
103 |
| - */ |
104 |
| - if (!(curr->batt.flags & BATT_FLAG_BAD_TEMPERATURE)) { |
105 |
| - if (temp_c < 99) |
106 |
| - temp_range = TEMP_RANGE_1; |
107 |
| - else if (temp_c > 101 && temp_c < 149) |
108 |
| - temp_range = TEMP_RANGE_2; |
109 |
| - else if (temp_c > 151 && temp_c < 229) |
110 |
| - temp_range = TEMP_RANGE_3; |
111 |
| - else if (temp_c > 231 && temp_c < 449) |
112 |
| - temp_range = TEMP_RANGE_4; |
113 |
| - else if (temp_c > 451) |
114 |
| - temp_range = TEMP_RANGE_5; |
115 |
| - } |
| 66 | + mv = adc_read_channel(ADC_VCIN1_BATT_TEMP); |
116 | 67 |
|
117 |
| - /* |
118 |
| - * If battery voltage reading is bad, use the last reading. Otherwise, |
119 |
| - * determine voltage range with hysteresis. |
120 |
| - */ |
121 |
| - if (curr->batt.flags & BATT_FLAG_BAD_VOLTAGE) { |
122 |
| - batt_voltage = prev_batt_voltage; |
123 |
| - } else { |
124 |
| - batt_voltage = prev_batt_voltage = curr->batt.voltage; |
125 |
| - if (batt_voltage < 8200) |
126 |
| - voltage_range = VOLTAGE_RANGE_LOW; |
127 |
| - else if (batt_voltage > 8300) |
128 |
| - voltage_range = VOLTAGE_RANGE_HIGH; |
129 |
| - } |
| 68 | + if (mv == ADC_READ_ERROR) |
| 69 | + return -1; |
130 | 70 |
|
131 |
| - /* |
132 |
| - * If we are not charging or we aren't using fast charging profiles, |
133 |
| - * then do not override desired current and voltage. |
134 |
| - */ |
135 |
| - if (curr->state != ST_CHARGE || !fast_charging_allowed) |
136 |
| - return 0; |
| 71 | + bp = (mv < 3000 ? BP_YES : BP_NO); |
137 | 72 |
|
138 |
| - /* |
139 |
| - * Okay, impose our custom will: |
140 |
| - * When battery is 0-10C: |
141 |
| - * CC at 486mA @ 8.7V |
142 |
| - * CV at 8.7V |
143 |
| - * |
144 |
| - * When battery is <15C: |
145 |
| - * CC at 1458mA @ 8.7V |
146 |
| - * CV at 8.7V |
147 |
| - * |
148 |
| - * When battery is <23C: |
149 |
| - * CC at 3402mA until 8.3V @ 8.7V |
150 |
| - * CC at 2430mA @ 8.7V |
151 |
| - * CV at 8.7V |
152 |
| - * |
153 |
| - * When battery is <45C: |
154 |
| - * CC at 4860mA until 8.3V @ 8.7V |
155 |
| - * CC at 2430mA @ 8.7V |
156 |
| - * CV at 8.7V until current drops to 450mA |
157 |
| - * |
158 |
| - * When battery is >45C: |
159 |
| - * CC at 2430mA @ 8.3V |
160 |
| - * CV at 8.3V (when battery is hot we don't go to fully charged) |
161 |
| - */ |
162 |
| - switch (temp_range) { |
163 |
| - case TEMP_RANGE_1: |
164 |
| - curr->requested_current = 486; |
165 |
| - curr->requested_voltage = 8700; |
166 |
| - break; |
167 |
| - case TEMP_RANGE_2: |
168 |
| - curr->requested_current = 1458; |
169 |
| - curr->requested_voltage = 8700; |
170 |
| - break; |
171 |
| - case TEMP_RANGE_3: |
172 |
| - curr->requested_voltage = 8700; |
173 |
| - if (voltage_range == VOLTAGE_RANGE_HIGH) |
174 |
| - curr->requested_current = 2430; |
175 |
| - else |
176 |
| - curr->requested_current = 3402; |
177 |
| - break; |
178 |
| - case TEMP_RANGE_4: |
179 |
| - curr->requested_voltage = 8700; |
180 |
| - if (voltage_range == VOLTAGE_RANGE_HIGH) |
181 |
| - curr->requested_current = 2430; |
182 |
| - else |
183 |
| - curr->requested_current = 4860; |
184 |
| - break; |
185 |
| - case TEMP_RANGE_5: |
186 |
| - curr->requested_current = 2430; |
187 |
| - curr->requested_voltage = 8300; |
188 |
| - break; |
189 |
| - } |
190 |
| - |
191 |
| - return 0; |
192 |
| -} |
193 |
| - |
194 |
| -/* Customs options controllable by host command. */ |
195 |
| -#define PARAM_FASTCHARGE (CS_PARAM_CUSTOM_PROFILE_MIN + 0) |
196 |
| - |
197 |
| -enum ec_status charger_profile_override_get_param(uint32_t param, |
198 |
| - uint32_t *value) |
199 |
| -{ |
200 |
| - if (param == PARAM_FASTCHARGE) { |
201 |
| - *value = fast_charging_allowed; |
202 |
| - return EC_RES_SUCCESS; |
203 |
| - } |
204 |
| - return EC_RES_INVALID_PARAM; |
| 73 | + return bp; |
205 | 74 | }
|
206 |
| - |
207 |
| -enum ec_status charger_profile_override_set_param(uint32_t param, |
208 |
| - uint32_t value) |
209 |
| -{ |
210 |
| - if (param == PARAM_FASTCHARGE) { |
211 |
| - fast_charging_allowed = value; |
212 |
| - return EC_RES_SUCCESS; |
213 |
| - } |
214 |
| - return EC_RES_INVALID_PARAM; |
215 |
| -} |
216 |
| - |
217 |
| -static int command_fastcharge(int argc, char **argv) |
218 |
| -{ |
219 |
| - if (argc > 1 && !parse_bool(argv[1], &fast_charging_allowed)) |
220 |
| - return EC_ERROR_PARAM1; |
221 |
| - |
222 |
| - ccprintf("fastcharge %s\n", fast_charging_allowed ? "on" : "off"); |
223 |
| - |
224 |
| - return EC_SUCCESS; |
225 |
| -} |
226 |
| -DECLARE_CONSOLE_COMMAND(fastcharge, command_fastcharge, |
227 |
| - "[on|off]", |
228 |
| - "Get or set fast charging profile"); |
229 |
| - |
230 |
| -#endif /* CONFIG_CHARGER_PROFILE_OVERRIDE */ |
0 commit comments