1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/export.h>
3 #include <linux/power_supply.h>
9 * These are the defined batteries that uses a NTC and ID resistor placed
10 * inside of the battery pack.
11 * Note that the res_to_temp table must be strictly sorted by falling resistance
14 const struct ab8500_res_to_temp ab8500_temp_tbl_a_thermistor[] = {
31 EXPORT_SYMBOL(ab8500_temp_tbl_a_thermistor);
33 const int ab8500_temp_tbl_a_size = ARRAY_SIZE(ab8500_temp_tbl_a_thermistor);
34 EXPORT_SYMBOL(ab8500_temp_tbl_a_size);
36 const struct ab8500_res_to_temp ab8500_temp_tbl_b_thermistor[] = {
53 EXPORT_SYMBOL(ab8500_temp_tbl_b_thermistor);
55 const int ab8500_temp_tbl_b_size = ARRAY_SIZE(ab8500_temp_tbl_b_thermistor);
56 EXPORT_SYMBOL(ab8500_temp_tbl_b_size);
58 static const struct ab8500_v_to_cap cap_tbl_a_thermistor[] = {
81 static const struct ab8500_v_to_cap cap_tbl_b_thermistor[] = {
104 static const struct ab8500_v_to_cap cap_tbl[] = {
132 * Note that the res_to_temp table must be strictly sorted by falling
133 * resistance values to work.
135 static const struct ab8500_res_to_temp temp_tbl[] = {
154 * Note that the batres_vs_temp table must be strictly sorted by falling
155 * temperature values to work.
157 static const struct batres_vs_temp temp_to_batres_tbl_thermistor[] = {
168 * Note that the batres_vs_temp table must be strictly sorted by falling
169 * temperature values to work.
171 static const struct batres_vs_temp temp_to_batres_tbl_ext_thermistor[] = {
181 /* battery resistance table for LI ION 9100 battery */
182 static const struct batres_vs_temp temp_to_batres_tbl_9100[] = {
192 static struct ab8500_battery_type bat_type_thermistor[] = {
193 [BATTERY_UNKNOWN] = {
194 /* First element always represent the UNKNOWN battery */
195 .name = POWER_SUPPLY_TECHNOLOGY_UNKNOWN,
198 .battery_resistance = 300,
199 .charge_full_design = 612,
200 .nominal_voltage = 3700,
201 .termination_vol = 4050,
202 .termination_curr = 200,
204 .normal_cur_lvl = 400,
205 .normal_vol_lvl = 4100,
206 .maint_a_cur_lvl = 400,
207 .maint_a_vol_lvl = 4050,
208 .maint_a_chg_timer_h = 60,
209 .maint_b_cur_lvl = 400,
210 .maint_b_vol_lvl = 4000,
211 .maint_b_chg_timer_h = 200,
212 .low_high_cur_lvl = 300,
213 .low_high_vol_lvl = 4000,
214 .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl),
215 .r_to_t_tbl = temp_tbl,
216 .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl),
217 .v_to_cap_tbl = cap_tbl,
218 .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
219 .batres_tbl = temp_to_batres_tbl_thermistor,
222 .name = POWER_SUPPLY_TECHNOLOGY_LIPO,
225 .battery_resistance = 300,
226 .charge_full_design = 900,
227 .nominal_voltage = 3600,
228 .termination_vol = 4150,
229 .termination_curr = 80,
231 .normal_cur_lvl = 700,
232 .normal_vol_lvl = 4200,
233 .maint_a_cur_lvl = 600,
234 .maint_a_vol_lvl = 4150,
235 .maint_a_chg_timer_h = 60,
236 .maint_b_cur_lvl = 600,
237 .maint_b_vol_lvl = 4100,
238 .maint_b_chg_timer_h = 200,
239 .low_high_cur_lvl = 300,
240 .low_high_vol_lvl = 4000,
241 .n_temp_tbl_elements = ARRAY_SIZE(ab8500_temp_tbl_a_thermistor),
242 .r_to_t_tbl = ab8500_temp_tbl_a_thermistor,
243 .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl_a_thermistor),
244 .v_to_cap_tbl = cap_tbl_a_thermistor,
245 .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
246 .batres_tbl = temp_to_batres_tbl_thermistor,
250 .name = POWER_SUPPLY_TECHNOLOGY_LIPO,
251 .resis_high = 200000,
253 .battery_resistance = 300,
254 .charge_full_design = 900,
255 .nominal_voltage = 3600,
256 .termination_vol = 4150,
257 .termination_curr = 80,
259 .normal_cur_lvl = 700,
260 .normal_vol_lvl = 4200,
261 .maint_a_cur_lvl = 600,
262 .maint_a_vol_lvl = 4150,
263 .maint_a_chg_timer_h = 60,
264 .maint_b_cur_lvl = 600,
265 .maint_b_vol_lvl = 4100,
266 .maint_b_chg_timer_h = 200,
267 .low_high_cur_lvl = 300,
268 .low_high_vol_lvl = 4000,
269 .n_temp_tbl_elements = ARRAY_SIZE(ab8500_temp_tbl_b_thermistor),
270 .r_to_t_tbl = ab8500_temp_tbl_b_thermistor,
271 .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl_b_thermistor),
272 .v_to_cap_tbl = cap_tbl_b_thermistor,
273 .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
274 .batres_tbl = temp_to_batres_tbl_thermistor,
278 static struct ab8500_battery_type bat_type_ext_thermistor[] = {
279 [BATTERY_UNKNOWN] = {
280 /* First element always represent the UNKNOWN battery */
281 .name = POWER_SUPPLY_TECHNOLOGY_UNKNOWN,
284 .battery_resistance = 300,
285 .charge_full_design = 612,
286 .nominal_voltage = 3700,
287 .termination_vol = 4050,
288 .termination_curr = 200,
290 .normal_cur_lvl = 400,
291 .normal_vol_lvl = 4100,
292 .maint_a_cur_lvl = 400,
293 .maint_a_vol_lvl = 4050,
294 .maint_a_chg_timer_h = 60,
295 .maint_b_cur_lvl = 400,
296 .maint_b_vol_lvl = 4000,
297 .maint_b_chg_timer_h = 200,
298 .low_high_cur_lvl = 300,
299 .low_high_vol_lvl = 4000,
300 .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl),
301 .r_to_t_tbl = temp_tbl,
302 .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl),
303 .v_to_cap_tbl = cap_tbl,
304 .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
305 .batres_tbl = temp_to_batres_tbl_thermistor,
308 * These are the batteries that doesn't have an internal NTC resistor to measure
309 * its temperature. The temperature in this case is measure with a NTC placed
310 * near the battery but on the PCB.
313 .name = POWER_SUPPLY_TECHNOLOGY_LIPO,
316 .battery_resistance = 300,
317 .charge_full_design = 900,
318 .nominal_voltage = 3700,
319 .termination_vol = 4150,
320 .termination_curr = 100,
322 .normal_cur_lvl = 700,
323 .normal_vol_lvl = 4200,
324 .maint_a_cur_lvl = 600,
325 .maint_a_vol_lvl = 4150,
326 .maint_a_chg_timer_h = 60,
327 .maint_b_cur_lvl = 600,
328 .maint_b_vol_lvl = 4100,
329 .maint_b_chg_timer_h = 200,
330 .low_high_cur_lvl = 300,
331 .low_high_vol_lvl = 4000,
332 .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl),
333 .r_to_t_tbl = temp_tbl,
334 .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl),
335 .v_to_cap_tbl = cap_tbl,
336 .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
337 .batres_tbl = temp_to_batres_tbl_thermistor,
340 .name = POWER_SUPPLY_TECHNOLOGY_LION,
343 .battery_resistance = 300,
344 .charge_full_design = 950,
345 .nominal_voltage = 3700,
346 .termination_vol = 4150,
347 .termination_curr = 100,
349 .normal_cur_lvl = 700,
350 .normal_vol_lvl = 4200,
351 .maint_a_cur_lvl = 600,
352 .maint_a_vol_lvl = 4150,
353 .maint_a_chg_timer_h = 60,
354 .maint_b_cur_lvl = 600,
355 .maint_b_vol_lvl = 4100,
356 .maint_b_chg_timer_h = 200,
357 .low_high_cur_lvl = 300,
358 .low_high_vol_lvl = 4000,
359 .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl),
360 .r_to_t_tbl = temp_tbl,
361 .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl),
362 .v_to_cap_tbl = cap_tbl,
363 .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
364 .batres_tbl = temp_to_batres_tbl_thermistor,
367 .name = POWER_SUPPLY_TECHNOLOGY_LION,
370 .battery_resistance = 300,
371 .charge_full_design = 950,
372 .nominal_voltage = 3700,
373 .termination_vol = 4150,
374 .termination_curr = 100,
376 .normal_cur_lvl = 700,
377 .normal_vol_lvl = 4200,
378 .maint_a_cur_lvl = 600,
379 .maint_a_vol_lvl = 4150,
380 .maint_a_chg_timer_h = 60,
381 .maint_b_cur_lvl = 600,
382 .maint_b_vol_lvl = 4100,
383 .maint_b_chg_timer_h = 200,
384 .low_high_cur_lvl = 300,
385 .low_high_vol_lvl = 4000,
386 .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl),
387 .r_to_t_tbl = temp_tbl,
388 .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl),
389 .v_to_cap_tbl = cap_tbl,
390 .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
391 .batres_tbl = temp_to_batres_tbl_thermistor,
395 static const struct ab8500_bm_capacity_levels cap_levels = {
403 static const struct ab8500_fg_parameters fg = {
404 .recovery_sleep_timer = 10,
405 .recovery_total_time = 100,
407 .init_discard_time = 5,
408 .init_total_time = 40,
409 .high_curr_time = 60,
411 .accu_high_curr = 30,
412 .high_curr_threshold = 50,
413 .lowbat_threshold = 3100,
414 .battok_falling_th_sel0 = 2860,
415 .battok_raising_th_sel1 = 2860,
417 .user_cap_limit = 15,
419 .pcut_max_time = 127,
420 .pcut_flag_time = 112,
421 .pcut_max_restart = 15,
422 .pcut_debounce_time = 2,
425 static const struct ab8500_maxim_parameters ab8500_maxi_params = {
429 .charger_curr_step = 100,
432 static const struct ab8500_bm_charger_parameters chg = {
433 .usb_volt_max = 5500,
434 .usb_curr_max = 1500,
440 * This array maps the raw hex value to charger output current used by the
443 static int ab8500_charge_output_curr_map[] = {
444 100, 200, 300, 400, 500, 600, 700, 800,
445 900, 1000, 1100, 1200, 1300, 1400, 1500, 1500,
449 * This array maps the raw hex value to charger input current used by the
452 static int ab8500_charge_input_curr_map[] = {
453 50, 98, 193, 290, 380, 450, 500, 600,
454 700, 800, 900, 1000, 1100, 1300, 1400, 1500,
457 struct ab8500_bm_data ab8500_bm_data = {
462 .main_safety_tmr_h = 4,
463 .temp_interval_chg = 20,
464 .temp_interval_nochg = 120,
465 .usb_safety_tmr_h = 4,
466 .bkup_bat_v = BUP_VCH_SEL_2P6V,
467 .bkup_bat_i = BUP_ICH_SEL_150UA,
468 .no_maintenance = false,
469 .capacity_scaling = false,
470 .adc_therm = AB8500_ADC_THERM_BATCTRL,
471 .chg_unknown_bat = false,
472 .enable_overshoot = false,
474 .cap_levels = &cap_levels,
475 .bat_type = bat_type_thermistor,
476 .n_btypes = ARRAY_SIZE(bat_type_thermistor),
478 .interval_charging = 5,
479 .interval_not_charging = 120,
480 .temp_hysteresis = 3,
481 .gnd_lift_resistance = 34,
482 .chg_output_curr = ab8500_charge_output_curr_map,
483 .n_chg_out_curr = ARRAY_SIZE(ab8500_charge_output_curr_map),
484 .maxi = &ab8500_maxi_params,
487 .chg_input_curr = ab8500_charge_input_curr_map,
488 .n_chg_in_curr = ARRAY_SIZE(ab8500_charge_input_curr_map),
491 int ab8500_bm_of_probe(struct device *dev,
492 struct device_node *np,
493 struct ab8500_bm_data *bm)
495 const struct batres_vs_temp *tmp_batres_tbl;
496 struct device_node *battery_node;
500 /* get phandle to 'battery-info' node */
501 battery_node = of_parse_phandle(np, "battery", 0);
503 dev_err(dev, "battery node or reference missing\n");
507 btech = of_get_property(battery_node, "stericsson,battery-type", NULL);
509 dev_warn(dev, "missing property battery-name/type\n");
510 of_node_put(battery_node);
514 if (strncmp(btech, "LION", 4) == 0) {
515 bm->no_maintenance = true;
516 bm->chg_unknown_bat = true;
517 bm->bat_type[BATTERY_UNKNOWN].charge_full_design = 2600;
518 bm->bat_type[BATTERY_UNKNOWN].termination_vol = 4150;
519 bm->bat_type[BATTERY_UNKNOWN].recharge_cap = 95;
520 bm->bat_type[BATTERY_UNKNOWN].normal_cur_lvl = 520;
521 bm->bat_type[BATTERY_UNKNOWN].normal_vol_lvl = 4200;
524 if (of_property_read_bool(battery_node, "thermistor-on-batctrl")) {
525 if (strncmp(btech, "LION", 4) == 0)
526 tmp_batres_tbl = temp_to_batres_tbl_9100;
528 tmp_batres_tbl = temp_to_batres_tbl_thermistor;
531 bm->bat_type = bat_type_ext_thermistor;
532 bm->adc_therm = AB8500_ADC_THERM_BATTEMP;
533 tmp_batres_tbl = temp_to_batres_tbl_ext_thermistor;
536 /* select the battery resolution table */
537 for (i = 0; i < bm->n_btypes; ++i)
538 bm->bat_type[i].batres_tbl = tmp_batres_tbl;
540 of_node_put(battery_node);