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>
7 #include <linux/mfd/abx500/ab8500-bm.h>
10 * These are the defined batteries that uses a NTC and ID resistor placed
11 * inside of the battery pack.
12 * Note that the res_to_temp table must be strictly sorted by falling resistance
15 const struct abx500_res_to_temp ab8500_temp_tbl_a_thermistor
[] = {
32 EXPORT_SYMBOL(ab8500_temp_tbl_a_thermistor
);
34 const int ab8500_temp_tbl_a_size
= ARRAY_SIZE(ab8500_temp_tbl_a_thermistor
);
35 EXPORT_SYMBOL(ab8500_temp_tbl_a_size
);
37 const struct abx500_res_to_temp ab8500_temp_tbl_b_thermistor
[] = {
54 EXPORT_SYMBOL(ab8500_temp_tbl_b_thermistor
);
56 const int ab8500_temp_tbl_b_size
= ARRAY_SIZE(ab8500_temp_tbl_b_thermistor
);
57 EXPORT_SYMBOL(ab8500_temp_tbl_b_size
);
59 static const struct abx500_v_to_cap cap_tbl_a_thermistor
[] = {
82 static const struct abx500_v_to_cap cap_tbl_b_thermistor
[] = {
105 static const struct abx500_v_to_cap cap_tbl
[] = {
133 * Note that the res_to_temp table must be strictly sorted by falling
134 * resistance values to work.
136 static const struct abx500_res_to_temp temp_tbl
[] = {
155 * Note that the batres_vs_temp table must be strictly sorted by falling
156 * temperature values to work.
158 static const struct batres_vs_temp temp_to_batres_tbl_thermistor
[] = {
169 * Note that the batres_vs_temp table must be strictly sorted by falling
170 * temperature values to work.
172 static const struct batres_vs_temp temp_to_batres_tbl_ext_thermistor
[] = {
182 /* battery resistance table for LI ION 9100 battery */
183 static const struct batres_vs_temp temp_to_batres_tbl_9100
[] = {
193 static struct abx500_battery_type bat_type_thermistor
[] = {
194 [BATTERY_UNKNOWN
] = {
195 /* First element always represent the UNKNOWN battery */
196 .name
= POWER_SUPPLY_TECHNOLOGY_UNKNOWN
,
199 .battery_resistance
= 300,
200 .charge_full_design
= 612,
201 .nominal_voltage
= 3700,
202 .termination_vol
= 4050,
203 .termination_curr
= 200,
205 .normal_cur_lvl
= 400,
206 .normal_vol_lvl
= 4100,
207 .maint_a_cur_lvl
= 400,
208 .maint_a_vol_lvl
= 4050,
209 .maint_a_chg_timer_h
= 60,
210 .maint_b_cur_lvl
= 400,
211 .maint_b_vol_lvl
= 4000,
212 .maint_b_chg_timer_h
= 200,
213 .low_high_cur_lvl
= 300,
214 .low_high_vol_lvl
= 4000,
215 .n_temp_tbl_elements
= ARRAY_SIZE(temp_tbl
),
216 .r_to_t_tbl
= temp_tbl
,
217 .n_v_cap_tbl_elements
= ARRAY_SIZE(cap_tbl
),
218 .v_to_cap_tbl
= cap_tbl
,
219 .n_batres_tbl_elements
= ARRAY_SIZE(temp_to_batres_tbl_thermistor
),
220 .batres_tbl
= temp_to_batres_tbl_thermistor
,
223 .name
= POWER_SUPPLY_TECHNOLOGY_LIPO
,
226 .battery_resistance
= 300,
227 .charge_full_design
= 900,
228 .nominal_voltage
= 3600,
229 .termination_vol
= 4150,
230 .termination_curr
= 80,
232 .normal_cur_lvl
= 700,
233 .normal_vol_lvl
= 4200,
234 .maint_a_cur_lvl
= 600,
235 .maint_a_vol_lvl
= 4150,
236 .maint_a_chg_timer_h
= 60,
237 .maint_b_cur_lvl
= 600,
238 .maint_b_vol_lvl
= 4100,
239 .maint_b_chg_timer_h
= 200,
240 .low_high_cur_lvl
= 300,
241 .low_high_vol_lvl
= 4000,
242 .n_temp_tbl_elements
= ARRAY_SIZE(ab8500_temp_tbl_a_thermistor
),
243 .r_to_t_tbl
= ab8500_temp_tbl_a_thermistor
,
244 .n_v_cap_tbl_elements
= ARRAY_SIZE(cap_tbl_a_thermistor
),
245 .v_to_cap_tbl
= cap_tbl_a_thermistor
,
246 .n_batres_tbl_elements
= ARRAY_SIZE(temp_to_batres_tbl_thermistor
),
247 .batres_tbl
= temp_to_batres_tbl_thermistor
,
251 .name
= POWER_SUPPLY_TECHNOLOGY_LIPO
,
252 .resis_high
= 200000,
254 .battery_resistance
= 300,
255 .charge_full_design
= 900,
256 .nominal_voltage
= 3600,
257 .termination_vol
= 4150,
258 .termination_curr
= 80,
260 .normal_cur_lvl
= 700,
261 .normal_vol_lvl
= 4200,
262 .maint_a_cur_lvl
= 600,
263 .maint_a_vol_lvl
= 4150,
264 .maint_a_chg_timer_h
= 60,
265 .maint_b_cur_lvl
= 600,
266 .maint_b_vol_lvl
= 4100,
267 .maint_b_chg_timer_h
= 200,
268 .low_high_cur_lvl
= 300,
269 .low_high_vol_lvl
= 4000,
270 .n_temp_tbl_elements
= ARRAY_SIZE(ab8500_temp_tbl_b_thermistor
),
271 .r_to_t_tbl
= ab8500_temp_tbl_b_thermistor
,
272 .n_v_cap_tbl_elements
= ARRAY_SIZE(cap_tbl_b_thermistor
),
273 .v_to_cap_tbl
= cap_tbl_b_thermistor
,
274 .n_batres_tbl_elements
= ARRAY_SIZE(temp_to_batres_tbl_thermistor
),
275 .batres_tbl
= temp_to_batres_tbl_thermistor
,
279 static struct abx500_battery_type bat_type_ext_thermistor
[] = {
280 [BATTERY_UNKNOWN
] = {
281 /* First element always represent the UNKNOWN battery */
282 .name
= POWER_SUPPLY_TECHNOLOGY_UNKNOWN
,
285 .battery_resistance
= 300,
286 .charge_full_design
= 612,
287 .nominal_voltage
= 3700,
288 .termination_vol
= 4050,
289 .termination_curr
= 200,
291 .normal_cur_lvl
= 400,
292 .normal_vol_lvl
= 4100,
293 .maint_a_cur_lvl
= 400,
294 .maint_a_vol_lvl
= 4050,
295 .maint_a_chg_timer_h
= 60,
296 .maint_b_cur_lvl
= 400,
297 .maint_b_vol_lvl
= 4000,
298 .maint_b_chg_timer_h
= 200,
299 .low_high_cur_lvl
= 300,
300 .low_high_vol_lvl
= 4000,
301 .n_temp_tbl_elements
= ARRAY_SIZE(temp_tbl
),
302 .r_to_t_tbl
= temp_tbl
,
303 .n_v_cap_tbl_elements
= ARRAY_SIZE(cap_tbl
),
304 .v_to_cap_tbl
= cap_tbl
,
305 .n_batres_tbl_elements
= ARRAY_SIZE(temp_to_batres_tbl_thermistor
),
306 .batres_tbl
= temp_to_batres_tbl_thermistor
,
309 * These are the batteries that doesn't have an internal NTC resistor to measure
310 * its temperature. The temperature in this case is measure with a NTC placed
311 * near the battery but on the PCB.
314 .name
= POWER_SUPPLY_TECHNOLOGY_LIPO
,
317 .battery_resistance
= 300,
318 .charge_full_design
= 900,
319 .nominal_voltage
= 3700,
320 .termination_vol
= 4150,
321 .termination_curr
= 100,
323 .normal_cur_lvl
= 700,
324 .normal_vol_lvl
= 4200,
325 .maint_a_cur_lvl
= 600,
326 .maint_a_vol_lvl
= 4150,
327 .maint_a_chg_timer_h
= 60,
328 .maint_b_cur_lvl
= 600,
329 .maint_b_vol_lvl
= 4100,
330 .maint_b_chg_timer_h
= 200,
331 .low_high_cur_lvl
= 300,
332 .low_high_vol_lvl
= 4000,
333 .n_temp_tbl_elements
= ARRAY_SIZE(temp_tbl
),
334 .r_to_t_tbl
= temp_tbl
,
335 .n_v_cap_tbl_elements
= ARRAY_SIZE(cap_tbl
),
336 .v_to_cap_tbl
= cap_tbl
,
337 .n_batres_tbl_elements
= ARRAY_SIZE(temp_to_batres_tbl_thermistor
),
338 .batres_tbl
= temp_to_batres_tbl_thermistor
,
341 .name
= POWER_SUPPLY_TECHNOLOGY_LION
,
344 .battery_resistance
= 300,
345 .charge_full_design
= 950,
346 .nominal_voltage
= 3700,
347 .termination_vol
= 4150,
348 .termination_curr
= 100,
350 .normal_cur_lvl
= 700,
351 .normal_vol_lvl
= 4200,
352 .maint_a_cur_lvl
= 600,
353 .maint_a_vol_lvl
= 4150,
354 .maint_a_chg_timer_h
= 60,
355 .maint_b_cur_lvl
= 600,
356 .maint_b_vol_lvl
= 4100,
357 .maint_b_chg_timer_h
= 200,
358 .low_high_cur_lvl
= 300,
359 .low_high_vol_lvl
= 4000,
360 .n_temp_tbl_elements
= ARRAY_SIZE(temp_tbl
),
361 .r_to_t_tbl
= temp_tbl
,
362 .n_v_cap_tbl_elements
= ARRAY_SIZE(cap_tbl
),
363 .v_to_cap_tbl
= cap_tbl
,
364 .n_batres_tbl_elements
= ARRAY_SIZE(temp_to_batres_tbl_thermistor
),
365 .batres_tbl
= temp_to_batres_tbl_thermistor
,
368 .name
= POWER_SUPPLY_TECHNOLOGY_LION
,
371 .battery_resistance
= 300,
372 .charge_full_design
= 950,
373 .nominal_voltage
= 3700,
374 .termination_vol
= 4150,
375 .termination_curr
= 100,
377 .normal_cur_lvl
= 700,
378 .normal_vol_lvl
= 4200,
379 .maint_a_cur_lvl
= 600,
380 .maint_a_vol_lvl
= 4150,
381 .maint_a_chg_timer_h
= 60,
382 .maint_b_cur_lvl
= 600,
383 .maint_b_vol_lvl
= 4100,
384 .maint_b_chg_timer_h
= 200,
385 .low_high_cur_lvl
= 300,
386 .low_high_vol_lvl
= 4000,
387 .n_temp_tbl_elements
= ARRAY_SIZE(temp_tbl
),
388 .r_to_t_tbl
= temp_tbl
,
389 .n_v_cap_tbl_elements
= ARRAY_SIZE(cap_tbl
),
390 .v_to_cap_tbl
= cap_tbl
,
391 .n_batres_tbl_elements
= ARRAY_SIZE(temp_to_batres_tbl_thermistor
),
392 .batres_tbl
= temp_to_batres_tbl_thermistor
,
396 static const struct abx500_bm_capacity_levels cap_levels
= {
404 static const struct abx500_fg_parameters fg
= {
405 .recovery_sleep_timer
= 10,
406 .recovery_total_time
= 100,
408 .init_discard_time
= 5,
409 .init_total_time
= 40,
410 .high_curr_time
= 60,
412 .accu_high_curr
= 30,
413 .high_curr_threshold
= 50,
414 .lowbat_threshold
= 3100,
415 .battok_falling_th_sel0
= 2860,
416 .battok_raising_th_sel1
= 2860,
418 .user_cap_limit
= 15,
420 .pcut_max_time
= 127,
421 .pcut_flag_time
= 112,
422 .pcut_max_restart
= 15,
423 .pcut_debounce_time
= 2,
426 static const struct abx500_maxim_parameters ab8500_maxi_params
= {
430 .charger_curr_step
= 100,
433 static const struct abx500_bm_charger_parameters chg
= {
434 .usb_volt_max
= 5500,
435 .usb_curr_max
= 1500,
441 * This array maps the raw hex value to charger output current used by the
444 static int ab8500_charge_output_curr_map
[] = {
445 100, 200, 300, 400, 500, 600, 700, 800,
446 900, 1000, 1100, 1200, 1300, 1400, 1500, 1500,
450 * This array maps the raw hex value to charger input current used by the
453 static int ab8500_charge_input_curr_map
[] = {
454 50, 98, 193, 290, 380, 450, 500, 600,
455 700, 800, 900, 1000, 1100, 1300, 1400, 1500,
458 struct abx500_bm_data ab8500_bm_data
= {
463 .main_safety_tmr_h
= 4,
464 .temp_interval_chg
= 20,
465 .temp_interval_nochg
= 120,
466 .usb_safety_tmr_h
= 4,
467 .bkup_bat_v
= BUP_VCH_SEL_2P6V
,
468 .bkup_bat_i
= BUP_ICH_SEL_150UA
,
469 .no_maintenance
= false,
470 .capacity_scaling
= false,
471 .adc_therm
= ABx500_ADC_THERM_BATCTRL
,
472 .chg_unknown_bat
= false,
473 .enable_overshoot
= false,
475 .cap_levels
= &cap_levels
,
476 .bat_type
= bat_type_thermistor
,
477 .n_btypes
= ARRAY_SIZE(bat_type_thermistor
),
479 .interval_charging
= 5,
480 .interval_not_charging
= 120,
481 .temp_hysteresis
= 3,
482 .gnd_lift_resistance
= 34,
483 .chg_output_curr
= ab8500_charge_output_curr_map
,
484 .n_chg_out_curr
= ARRAY_SIZE(ab8500_charge_output_curr_map
),
485 .maxi
= &ab8500_maxi_params
,
488 .chg_input_curr
= ab8500_charge_input_curr_map
,
489 .n_chg_in_curr
= ARRAY_SIZE(ab8500_charge_input_curr_map
),
492 int ab8500_bm_of_probe(struct device
*dev
,
493 struct device_node
*np
,
494 struct abx500_bm_data
*bm
)
496 const struct batres_vs_temp
*tmp_batres_tbl
;
497 struct device_node
*battery_node
;
501 /* get phandle to 'battery-info' node */
502 battery_node
= of_parse_phandle(np
, "battery", 0);
504 dev_err(dev
, "battery node or reference missing\n");
508 btech
= of_get_property(battery_node
, "stericsson,battery-type", NULL
);
510 dev_warn(dev
, "missing property battery-name/type\n");
511 of_node_put(battery_node
);
515 if (strncmp(btech
, "LION", 4) == 0) {
516 bm
->no_maintenance
= true;
517 bm
->chg_unknown_bat
= true;
518 bm
->bat_type
[BATTERY_UNKNOWN
].charge_full_design
= 2600;
519 bm
->bat_type
[BATTERY_UNKNOWN
].termination_vol
= 4150;
520 bm
->bat_type
[BATTERY_UNKNOWN
].recharge_cap
= 95;
521 bm
->bat_type
[BATTERY_UNKNOWN
].normal_cur_lvl
= 520;
522 bm
->bat_type
[BATTERY_UNKNOWN
].normal_vol_lvl
= 4200;
525 if (of_property_read_bool(battery_node
, "thermistor-on-batctrl")) {
526 if (strncmp(btech
, "LION", 4) == 0)
527 tmp_batres_tbl
= temp_to_batres_tbl_9100
;
529 tmp_batres_tbl
= temp_to_batres_tbl_thermistor
;
532 bm
->bat_type
= bat_type_ext_thermistor
;
533 bm
->adc_therm
= ABx500_ADC_THERM_BATTEMP
;
534 tmp_batres_tbl
= temp_to_batres_tbl_ext_thermistor
;
537 /* select the battery resolution table */
538 for (i
= 0; i
< bm
->n_btypes
; ++i
)
539 bm
->bat_type
[i
].batres_tbl
= tmp_batres_tbl
;
541 of_node_put(battery_node
);