1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/export.h>
3 #include <linux/power_supply.h>
5 #include <linux/mfd/abx500.h>
6 #include <linux/mfd/abx500/ab8500.h>
11 * These are the defined batteries that uses a NTC and ID resistor placed
12 * inside of the battery pack.
13 * Note that the res_to_temp table must be strictly sorted by falling resistance
16 const struct abx500_res_to_temp ab8500_temp_tbl_a_thermistor[] = {
33 EXPORT_SYMBOL(ab8500_temp_tbl_a_thermistor);
35 const int ab8500_temp_tbl_a_size = ARRAY_SIZE(ab8500_temp_tbl_a_thermistor);
36 EXPORT_SYMBOL(ab8500_temp_tbl_a_size);
38 const struct abx500_res_to_temp ab8500_temp_tbl_b_thermistor[] = {
55 EXPORT_SYMBOL(ab8500_temp_tbl_b_thermistor);
57 const int ab8500_temp_tbl_b_size = ARRAY_SIZE(ab8500_temp_tbl_b_thermistor);
58 EXPORT_SYMBOL(ab8500_temp_tbl_b_size);
60 static const struct abx500_v_to_cap cap_tbl_a_thermistor[] = {
83 static const struct abx500_v_to_cap cap_tbl_b_thermistor[] = {
106 static const struct abx500_v_to_cap cap_tbl[] = {
134 * Note that the res_to_temp table must be strictly sorted by falling
135 * resistance values to work.
137 static const struct abx500_res_to_temp temp_tbl[] = {
156 * Note that the batres_vs_temp table must be strictly sorted by falling
157 * temperature values to work.
159 static const struct batres_vs_temp temp_to_batres_tbl_thermistor[] = {
170 * Note that the batres_vs_temp table must be strictly sorted by falling
171 * temperature values to work.
173 static const struct batres_vs_temp temp_to_batres_tbl_ext_thermistor[] = {
183 /* battery resistance table for LI ION 9100 battery */
184 static const struct batres_vs_temp temp_to_batres_tbl_9100[] = {
194 static struct abx500_battery_type bat_type_thermistor[] = {
195 [BATTERY_UNKNOWN] = {
196 /* First element always represent the UNKNOWN battery */
197 .name = POWER_SUPPLY_TECHNOLOGY_UNKNOWN,
200 .battery_resistance = 300,
201 .charge_full_design = 612,
202 .nominal_voltage = 3700,
203 .termination_vol = 4050,
204 .termination_curr = 200,
206 .normal_cur_lvl = 400,
207 .normal_vol_lvl = 4100,
208 .maint_a_cur_lvl = 400,
209 .maint_a_vol_lvl = 4050,
210 .maint_a_chg_timer_h = 60,
211 .maint_b_cur_lvl = 400,
212 .maint_b_vol_lvl = 4000,
213 .maint_b_chg_timer_h = 200,
214 .low_high_cur_lvl = 300,
215 .low_high_vol_lvl = 4000,
216 .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl),
217 .r_to_t_tbl = temp_tbl,
218 .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl),
219 .v_to_cap_tbl = cap_tbl,
220 .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
221 .batres_tbl = temp_to_batres_tbl_thermistor,
224 .name = POWER_SUPPLY_TECHNOLOGY_LIPO,
227 .battery_resistance = 300,
228 .charge_full_design = 900,
229 .nominal_voltage = 3600,
230 .termination_vol = 4150,
231 .termination_curr = 80,
233 .normal_cur_lvl = 700,
234 .normal_vol_lvl = 4200,
235 .maint_a_cur_lvl = 600,
236 .maint_a_vol_lvl = 4150,
237 .maint_a_chg_timer_h = 60,
238 .maint_b_cur_lvl = 600,
239 .maint_b_vol_lvl = 4100,
240 .maint_b_chg_timer_h = 200,
241 .low_high_cur_lvl = 300,
242 .low_high_vol_lvl = 4000,
243 .n_temp_tbl_elements = ARRAY_SIZE(ab8500_temp_tbl_a_thermistor),
244 .r_to_t_tbl = ab8500_temp_tbl_a_thermistor,
245 .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl_a_thermistor),
246 .v_to_cap_tbl = cap_tbl_a_thermistor,
247 .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
248 .batres_tbl = temp_to_batres_tbl_thermistor,
252 .name = POWER_SUPPLY_TECHNOLOGY_LIPO,
253 .resis_high = 200000,
255 .battery_resistance = 300,
256 .charge_full_design = 900,
257 .nominal_voltage = 3600,
258 .termination_vol = 4150,
259 .termination_curr = 80,
261 .normal_cur_lvl = 700,
262 .normal_vol_lvl = 4200,
263 .maint_a_cur_lvl = 600,
264 .maint_a_vol_lvl = 4150,
265 .maint_a_chg_timer_h = 60,
266 .maint_b_cur_lvl = 600,
267 .maint_b_vol_lvl = 4100,
268 .maint_b_chg_timer_h = 200,
269 .low_high_cur_lvl = 300,
270 .low_high_vol_lvl = 4000,
271 .n_temp_tbl_elements = ARRAY_SIZE(ab8500_temp_tbl_b_thermistor),
272 .r_to_t_tbl = ab8500_temp_tbl_b_thermistor,
273 .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl_b_thermistor),
274 .v_to_cap_tbl = cap_tbl_b_thermistor,
275 .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
276 .batres_tbl = temp_to_batres_tbl_thermistor,
280 static struct abx500_battery_type bat_type_ext_thermistor[] = {
281 [BATTERY_UNKNOWN] = {
282 /* First element always represent the UNKNOWN battery */
283 .name = POWER_SUPPLY_TECHNOLOGY_UNKNOWN,
286 .battery_resistance = 300,
287 .charge_full_design = 612,
288 .nominal_voltage = 3700,
289 .termination_vol = 4050,
290 .termination_curr = 200,
292 .normal_cur_lvl = 400,
293 .normal_vol_lvl = 4100,
294 .maint_a_cur_lvl = 400,
295 .maint_a_vol_lvl = 4050,
296 .maint_a_chg_timer_h = 60,
297 .maint_b_cur_lvl = 400,
298 .maint_b_vol_lvl = 4000,
299 .maint_b_chg_timer_h = 200,
300 .low_high_cur_lvl = 300,
301 .low_high_vol_lvl = 4000,
302 .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl),
303 .r_to_t_tbl = temp_tbl,
304 .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl),
305 .v_to_cap_tbl = cap_tbl,
306 .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
307 .batres_tbl = temp_to_batres_tbl_thermistor,
310 * These are the batteries that doesn't have an internal NTC resistor to measure
311 * its temperature. The temperature in this case is measure with a NTC placed
312 * near the battery but on the PCB.
315 .name = POWER_SUPPLY_TECHNOLOGY_LIPO,
318 .battery_resistance = 300,
319 .charge_full_design = 900,
320 .nominal_voltage = 3700,
321 .termination_vol = 4150,
322 .termination_curr = 100,
324 .normal_cur_lvl = 700,
325 .normal_vol_lvl = 4200,
326 .maint_a_cur_lvl = 600,
327 .maint_a_vol_lvl = 4150,
328 .maint_a_chg_timer_h = 60,
329 .maint_b_cur_lvl = 600,
330 .maint_b_vol_lvl = 4100,
331 .maint_b_chg_timer_h = 200,
332 .low_high_cur_lvl = 300,
333 .low_high_vol_lvl = 4000,
334 .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl),
335 .r_to_t_tbl = temp_tbl,
336 .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl),
337 .v_to_cap_tbl = cap_tbl,
338 .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
339 .batres_tbl = temp_to_batres_tbl_thermistor,
342 .name = POWER_SUPPLY_TECHNOLOGY_LION,
345 .battery_resistance = 300,
346 .charge_full_design = 950,
347 .nominal_voltage = 3700,
348 .termination_vol = 4150,
349 .termination_curr = 100,
351 .normal_cur_lvl = 700,
352 .normal_vol_lvl = 4200,
353 .maint_a_cur_lvl = 600,
354 .maint_a_vol_lvl = 4150,
355 .maint_a_chg_timer_h = 60,
356 .maint_b_cur_lvl = 600,
357 .maint_b_vol_lvl = 4100,
358 .maint_b_chg_timer_h = 200,
359 .low_high_cur_lvl = 300,
360 .low_high_vol_lvl = 4000,
361 .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl),
362 .r_to_t_tbl = temp_tbl,
363 .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl),
364 .v_to_cap_tbl = cap_tbl,
365 .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
366 .batres_tbl = temp_to_batres_tbl_thermistor,
369 .name = POWER_SUPPLY_TECHNOLOGY_LION,
372 .battery_resistance = 300,
373 .charge_full_design = 950,
374 .nominal_voltage = 3700,
375 .termination_vol = 4150,
376 .termination_curr = 100,
378 .normal_cur_lvl = 700,
379 .normal_vol_lvl = 4200,
380 .maint_a_cur_lvl = 600,
381 .maint_a_vol_lvl = 4150,
382 .maint_a_chg_timer_h = 60,
383 .maint_b_cur_lvl = 600,
384 .maint_b_vol_lvl = 4100,
385 .maint_b_chg_timer_h = 200,
386 .low_high_cur_lvl = 300,
387 .low_high_vol_lvl = 4000,
388 .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl),
389 .r_to_t_tbl = temp_tbl,
390 .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl),
391 .v_to_cap_tbl = cap_tbl,
392 .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
393 .batres_tbl = temp_to_batres_tbl_thermistor,
397 static const struct abx500_bm_capacity_levels cap_levels = {
405 static const struct abx500_fg_parameters fg = {
406 .recovery_sleep_timer = 10,
407 .recovery_total_time = 100,
409 .init_discard_time = 5,
410 .init_total_time = 40,
411 .high_curr_time = 60,
413 .accu_high_curr = 30,
414 .high_curr_threshold = 50,
415 .lowbat_threshold = 3100,
416 .battok_falling_th_sel0 = 2860,
417 .battok_raising_th_sel1 = 2860,
419 .user_cap_limit = 15,
421 .pcut_max_time = 127,
422 .pcut_flag_time = 112,
423 .pcut_max_restart = 15,
424 .pcut_debounce_time = 2,
427 static const struct abx500_maxim_parameters ab8500_maxi_params = {
431 .charger_curr_step = 100,
434 static const struct abx500_bm_charger_parameters chg = {
435 .usb_volt_max = 5500,
436 .usb_curr_max = 1500,
442 * This array maps the raw hex value to charger output current used by the
445 static int ab8500_charge_output_curr_map[] = {
446 100, 200, 300, 400, 500, 600, 700, 800,
447 900, 1000, 1100, 1200, 1300, 1400, 1500, 1500,
451 * This array maps the raw hex value to charger input current used by the
454 static int ab8500_charge_input_curr_map[] = {
455 50, 98, 193, 290, 380, 450, 500, 600,
456 700, 800, 900, 1000, 1100, 1300, 1400, 1500,
459 struct abx500_bm_data ab8500_bm_data = {
464 .main_safety_tmr_h = 4,
465 .temp_interval_chg = 20,
466 .temp_interval_nochg = 120,
467 .usb_safety_tmr_h = 4,
468 .bkup_bat_v = BUP_VCH_SEL_2P6V,
469 .bkup_bat_i = BUP_ICH_SEL_150UA,
470 .no_maintenance = false,
471 .capacity_scaling = false,
472 .adc_therm = ABx500_ADC_THERM_BATCTRL,
473 .chg_unknown_bat = false,
474 .enable_overshoot = false,
476 .cap_levels = &cap_levels,
477 .bat_type = bat_type_thermistor,
478 .n_btypes = ARRAY_SIZE(bat_type_thermistor),
480 .interval_charging = 5,
481 .interval_not_charging = 120,
482 .temp_hysteresis = 3,
483 .gnd_lift_resistance = 34,
484 .chg_output_curr = ab8500_charge_output_curr_map,
485 .n_chg_out_curr = ARRAY_SIZE(ab8500_charge_output_curr_map),
486 .maxi = &ab8500_maxi_params,
489 .chg_input_curr = ab8500_charge_input_curr_map,
490 .n_chg_in_curr = ARRAY_SIZE(ab8500_charge_input_curr_map),
493 int ab8500_bm_of_probe(struct device *dev,
494 struct device_node *np,
495 struct abx500_bm_data *bm)
497 const struct batres_vs_temp *tmp_batres_tbl;
498 struct device_node *battery_node;
502 /* get phandle to 'battery-info' node */
503 battery_node = of_parse_phandle(np, "battery", 0);
505 dev_err(dev, "battery node or reference missing\n");
509 btech = of_get_property(battery_node, "stericsson,battery-type", NULL);
511 dev_warn(dev, "missing property battery-name/type\n");
512 of_node_put(battery_node);
516 if (strncmp(btech, "LION", 4) == 0) {
517 bm->no_maintenance = true;
518 bm->chg_unknown_bat = true;
519 bm->bat_type[BATTERY_UNKNOWN].charge_full_design = 2600;
520 bm->bat_type[BATTERY_UNKNOWN].termination_vol = 4150;
521 bm->bat_type[BATTERY_UNKNOWN].recharge_cap = 95;
522 bm->bat_type[BATTERY_UNKNOWN].normal_cur_lvl = 520;
523 bm->bat_type[BATTERY_UNKNOWN].normal_vol_lvl = 4200;
526 if (of_property_read_bool(battery_node, "thermistor-on-batctrl")) {
527 if (strncmp(btech, "LION", 4) == 0)
528 tmp_batres_tbl = temp_to_batres_tbl_9100;
530 tmp_batres_tbl = temp_to_batres_tbl_thermistor;
533 bm->bat_type = bat_type_ext_thermistor;
534 bm->adc_therm = ABx500_ADC_THERM_BATTEMP;
535 tmp_batres_tbl = temp_to_batres_tbl_ext_thermistor;
538 /* select the battery resolution table */
539 for (i = 0; i < bm->n_btypes; ++i)
540 bm->bat_type[i].batres_tbl = tmp_batres_tbl;
542 of_node_put(battery_node);