blob: c2b8c0bb77e275c67671f4c224f41b2c400b5bc3 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -08002#include <linux/export.h>
3#include <linux/power_supply.h>
4#include <linux/of.h>
5#include <linux/mfd/abx500.h>
6#include <linux/mfd/abx500/ab8500.h>
Linus Walleij417c0fc2021-03-12 09:36:02 +01007
8#include "ab8500-bm.h"
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -08009
10/*
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
14 * values to work.
15 */
Hongbo Zhangea2be6f2013-04-03 20:18:11 +080016const struct abx500_res_to_temp ab8500_temp_tbl_a_thermistor[] = {
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -080017 {-5, 53407},
18 { 0, 48594},
19 { 5, 43804},
20 {10, 39188},
21 {15, 34870},
22 {20, 30933},
23 {25, 27422},
24 {30, 24347},
25 {35, 21694},
26 {40, 19431},
27 {45, 17517},
28 {50, 15908},
29 {55, 14561},
30 {60, 13437},
31 {65, 12500},
32};
Hongbo Zhangea2be6f2013-04-03 20:18:11 +080033EXPORT_SYMBOL(ab8500_temp_tbl_a_thermistor);
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -080034
Hongbo Zhangea2be6f2013-04-03 20:18:11 +080035const int ab8500_temp_tbl_a_size = ARRAY_SIZE(ab8500_temp_tbl_a_thermistor);
36EXPORT_SYMBOL(ab8500_temp_tbl_a_size);
37
38const struct abx500_res_to_temp ab8500_temp_tbl_b_thermistor[] = {
Rajanikanth H.Vbd9e8ab2012-11-18 19:16:58 -080039 {-5, 200000},
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -080040 { 0, 159024},
41 { 5, 151921},
42 {10, 144300},
43 {15, 136424},
44 {20, 128565},
45 {25, 120978},
46 {30, 113875},
47 {35, 107397},
48 {40, 101629},
49 {45, 96592},
50 {50, 92253},
51 {55, 88569},
52 {60, 85461},
53 {65, 82869},
54};
Hongbo Zhangea2be6f2013-04-03 20:18:11 +080055EXPORT_SYMBOL(ab8500_temp_tbl_b_thermistor);
56
57const int ab8500_temp_tbl_b_size = ARRAY_SIZE(ab8500_temp_tbl_b_thermistor);
58EXPORT_SYMBOL(ab8500_temp_tbl_b_size);
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -080059
Hongbo Zhang2c899402013-04-03 20:18:10 +080060static const struct abx500_v_to_cap cap_tbl_a_thermistor[] = {
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -080061 {4171, 100},
62 {4114, 95},
63 {4009, 83},
64 {3947, 74},
65 {3907, 67},
66 {3863, 59},
67 {3830, 56},
68 {3813, 53},
69 {3791, 46},
70 {3771, 33},
71 {3754, 25},
72 {3735, 20},
73 {3717, 17},
74 {3681, 13},
75 {3664, 8},
76 {3651, 6},
77 {3635, 5},
78 {3560, 3},
79 {3408, 1},
80 {3247, 0},
81};
82
Hongbo Zhang2c899402013-04-03 20:18:10 +080083static const struct abx500_v_to_cap cap_tbl_b_thermistor[] = {
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -080084 {4161, 100},
85 {4124, 98},
86 {4044, 90},
87 {4003, 85},
88 {3966, 80},
89 {3933, 75},
90 {3888, 67},
91 {3849, 60},
92 {3813, 55},
93 {3787, 47},
94 {3772, 30},
95 {3751, 25},
96 {3718, 20},
97 {3681, 16},
98 {3660, 14},
99 {3589, 10},
100 {3546, 7},
101 {3495, 4},
102 {3404, 2},
103 {3250, 0},
104};
105
Hongbo Zhang2c899402013-04-03 20:18:10 +0800106static const struct abx500_v_to_cap cap_tbl[] = {
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800107 {4186, 100},
108 {4163, 99},
109 {4114, 95},
110 {4068, 90},
111 {3990, 80},
112 {3926, 70},
113 {3898, 65},
114 {3866, 60},
115 {3833, 55},
116 {3812, 50},
117 {3787, 40},
118 {3768, 30},
119 {3747, 25},
120 {3730, 20},
121 {3705, 15},
122 {3699, 14},
123 {3684, 12},
124 {3672, 9},
125 {3657, 7},
126 {3638, 6},
127 {3556, 4},
128 {3424, 2},
129 {3317, 1},
130 {3094, 0},
131};
132
133/*
134 * Note that the res_to_temp table must be strictly sorted by falling
135 * resistance values to work.
136 */
Hongbo Zhang2c899402013-04-03 20:18:10 +0800137static const struct abx500_res_to_temp temp_tbl[] = {
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800138 {-5, 214834},
139 { 0, 162943},
140 { 5, 124820},
141 {10, 96520},
142 {15, 75306},
143 {20, 59254},
144 {25, 47000},
145 {30, 37566},
146 {35, 30245},
147 {40, 24520},
148 {45, 20010},
149 {50, 16432},
150 {55, 13576},
151 {60, 11280},
152 {65, 9425},
153};
154
155/*
156 * Note that the batres_vs_temp table must be strictly sorted by falling
157 * temperature values to work.
158 */
Hongbo Zhang2c899402013-04-03 20:18:10 +0800159static const struct batres_vs_temp temp_to_batres_tbl_thermistor[] = {
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800160 { 40, 120},
161 { 30, 135},
162 { 20, 165},
163 { 10, 230},
164 { 00, 325},
165 {-10, 445},
166 {-20, 595},
167};
168
169/*
170 * Note that the batres_vs_temp table must be strictly sorted by falling
171 * temperature values to work.
172 */
Hongbo Zhang2c899402013-04-03 20:18:10 +0800173static const struct batres_vs_temp temp_to_batres_tbl_ext_thermistor[] = {
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800174 { 60, 300},
175 { 30, 300},
176 { 20, 300},
177 { 10, 300},
178 { 00, 300},
179 {-10, 300},
180 {-20, 300},
181};
182
183/* battery resistance table for LI ION 9100 battery */
Hongbo Zhang2c899402013-04-03 20:18:10 +0800184static const struct batres_vs_temp temp_to_batres_tbl_9100[] = {
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800185 { 60, 180},
186 { 30, 180},
187 { 20, 180},
188 { 10, 180},
189 { 00, 180},
190 {-10, 180},
191 {-20, 180},
192};
193
194static struct abx500_battery_type bat_type_thermistor[] = {
Lee Jones43dc4472012-11-29 15:26:22 +0000195 [BATTERY_UNKNOWN] = {
196 /* First element always represent the UNKNOWN battery */
197 .name = POWER_SUPPLY_TECHNOLOGY_UNKNOWN,
198 .resis_high = 0,
199 .resis_low = 0,
200 .battery_resistance = 300,
201 .charge_full_design = 612,
202 .nominal_voltage = 3700,
203 .termination_vol = 4050,
204 .termination_curr = 200,
Marcus Cooperea402402013-01-11 13:12:54 +0000205 .recharge_cap = 95,
Lee Jones43dc4472012-11-29 15:26:22 +0000206 .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,
222 },
223 {
224 .name = POWER_SUPPLY_TECHNOLOGY_LIPO,
225 .resis_high = 53407,
226 .resis_low = 12500,
227 .battery_resistance = 300,
228 .charge_full_design = 900,
229 .nominal_voltage = 3600,
230 .termination_vol = 4150,
231 .termination_curr = 80,
Marcus Cooperea402402013-01-11 13:12:54 +0000232 .recharge_cap = 95,
Lee Jones43dc4472012-11-29 15:26:22 +0000233 .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,
Hongbo Zhangea2be6f2013-04-03 20:18:11 +0800243 .n_temp_tbl_elements = ARRAY_SIZE(ab8500_temp_tbl_a_thermistor),
244 .r_to_t_tbl = ab8500_temp_tbl_a_thermistor,
Hongbo Zhang6c1f8e02013-04-03 20:18:09 +0800245 .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl_a_thermistor),
246 .v_to_cap_tbl = cap_tbl_a_thermistor,
Lee Jones43dc4472012-11-29 15:26:22 +0000247 .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
248 .batres_tbl = temp_to_batres_tbl_thermistor,
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800249
Lee Jones43dc4472012-11-29 15:26:22 +0000250 },
251 {
252 .name = POWER_SUPPLY_TECHNOLOGY_LIPO,
253 .resis_high = 200000,
254 .resis_low = 82869,
255 .battery_resistance = 300,
256 .charge_full_design = 900,
257 .nominal_voltage = 3600,
258 .termination_vol = 4150,
259 .termination_curr = 80,
Marcus Cooperea402402013-01-11 13:12:54 +0000260 .recharge_cap = 95,
Lee Jones43dc4472012-11-29 15:26:22 +0000261 .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,
Hongbo Zhangea2be6f2013-04-03 20:18:11 +0800271 .n_temp_tbl_elements = ARRAY_SIZE(ab8500_temp_tbl_b_thermistor),
272 .r_to_t_tbl = ab8500_temp_tbl_b_thermistor,
Hongbo Zhang6c1f8e02013-04-03 20:18:09 +0800273 .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl_b_thermistor),
274 .v_to_cap_tbl = cap_tbl_b_thermistor,
Lee Jones43dc4472012-11-29 15:26:22 +0000275 .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
276 .batres_tbl = temp_to_batres_tbl_thermistor,
277 },
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800278};
279
280static struct abx500_battery_type bat_type_ext_thermistor[] = {
Lee Jones43dc4472012-11-29 15:26:22 +0000281 [BATTERY_UNKNOWN] = {
282 /* First element always represent the UNKNOWN battery */
283 .name = POWER_SUPPLY_TECHNOLOGY_UNKNOWN,
284 .resis_high = 0,
285 .resis_low = 0,
286 .battery_resistance = 300,
287 .charge_full_design = 612,
288 .nominal_voltage = 3700,
289 .termination_vol = 4050,
290 .termination_curr = 200,
Marcus Cooperea402402013-01-11 13:12:54 +0000291 .recharge_cap = 95,
Lee Jones43dc4472012-11-29 15:26:22 +0000292 .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,
308 },
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800309/*
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.
313 */
Lee Jones43dc4472012-11-29 15:26:22 +0000314 {
315 .name = POWER_SUPPLY_TECHNOLOGY_LIPO,
316 .resis_high = 76000,
317 .resis_low = 53000,
318 .battery_resistance = 300,
319 .charge_full_design = 900,
320 .nominal_voltage = 3700,
321 .termination_vol = 4150,
322 .termination_curr = 100,
Marcus Cooperea402402013-01-11 13:12:54 +0000323 .recharge_cap = 95,
Lee Jones43dc4472012-11-29 15:26:22 +0000324 .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,
340 },
341 {
342 .name = POWER_SUPPLY_TECHNOLOGY_LION,
343 .resis_high = 30000,
344 .resis_low = 10000,
345 .battery_resistance = 300,
346 .charge_full_design = 950,
347 .nominal_voltage = 3700,
348 .termination_vol = 4150,
349 .termination_curr = 100,
Marcus Cooperea402402013-01-11 13:12:54 +0000350 .recharge_cap = 95,
Lee Jones43dc4472012-11-29 15:26:22 +0000351 .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,
367 },
368 {
369 .name = POWER_SUPPLY_TECHNOLOGY_LION,
370 .resis_high = 95000,
371 .resis_low = 76001,
372 .battery_resistance = 300,
373 .charge_full_design = 950,
374 .nominal_voltage = 3700,
375 .termination_vol = 4150,
376 .termination_curr = 100,
Marcus Cooperea402402013-01-11 13:12:54 +0000377 .recharge_cap = 95,
Lee Jones43dc4472012-11-29 15:26:22 +0000378 .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,
394 },
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800395};
396
397static const struct abx500_bm_capacity_levels cap_levels = {
398 .critical = 2,
399 .low = 10,
400 .normal = 70,
401 .high = 95,
402 .full = 100,
403};
404
405static const struct abx500_fg_parameters fg = {
406 .recovery_sleep_timer = 10,
407 .recovery_total_time = 100,
408 .init_timer = 1,
409 .init_discard_time = 5,
410 .init_total_time = 40,
411 .high_curr_time = 60,
412 .accu_charging = 30,
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,
Marcus Cooperea402402013-01-11 13:12:54 +0000418 .maint_thres = 95,
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800419 .user_cap_limit = 15,
Lee Jones93ff7222012-05-31 16:16:36 +0200420 .pcut_enable = 1,
421 .pcut_max_time = 127,
422 .pcut_flag_time = 112,
423 .pcut_max_restart = 15,
424 .pcut_debounce_time = 2,
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800425};
426
Lee Jones861a30d2012-08-29 20:36:51 +0800427static const struct abx500_maxim_parameters ab8500_maxi_params = {
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800428 .ena_maxi = true,
429 .chg_curr = 910,
430 .wait_cycles = 10,
431 .charger_curr_step = 100,
432};
433
434static const struct abx500_bm_charger_parameters chg = {
435 .usb_volt_max = 5500,
436 .usb_curr_max = 1500,
437 .ac_volt_max = 7500,
438 .ac_curr_max = 1500,
439};
440
Lee Jones861a30d2012-08-29 20:36:51 +0800441/*
442 * This array maps the raw hex value to charger output current used by the
443 * AB8500 values
444 */
445static int ab8500_charge_output_curr_map[] = {
446 100, 200, 300, 400, 500, 600, 700, 800,
447 900, 1000, 1100, 1200, 1300, 1400, 1500, 1500,
448};
449
Lee Jones861a30d2012-08-29 20:36:51 +0800450/*
451 * This array maps the raw hex value to charger input current used by the
452 * AB8500 values
453 */
454static int ab8500_charge_input_curr_map[] = {
455 50, 98, 193, 290, 380, 450, 500, 600,
456 700, 800, 900, 1000, 1100, 1300, 1400, 1500,
457};
458
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800459struct abx500_bm_data ab8500_bm_data = {
Lee Jones43dc4472012-11-29 15:26:22 +0000460 .temp_under = 3,
461 .temp_low = 8,
462 .temp_high = 43,
463 .temp_over = 48,
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,
Marcus Cooperea402402013-01-11 13:12:54 +0000471 .capacity_scaling = false,
Lee Jones43dc4472012-11-29 15:26:22 +0000472 .adc_therm = ABx500_ADC_THERM_BATCTRL,
473 .chg_unknown_bat = false,
474 .enable_overshoot = false,
475 .fg_res = 100,
476 .cap_levels = &cap_levels,
477 .bat_type = bat_type_thermistor,
Lee Jones861a30d2012-08-29 20:36:51 +0800478 .n_btypes = ARRAY_SIZE(bat_type_thermistor),
Lee Jones43dc4472012-11-29 15:26:22 +0000479 .batt_id = 0,
480 .interval_charging = 5,
481 .interval_not_charging = 120,
482 .temp_hysteresis = 3,
483 .gnd_lift_resistance = 34,
Lee Jones861a30d2012-08-29 20:36:51 +0800484 .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,
Lee Jones43dc4472012-11-29 15:26:22 +0000487 .chg_params = &chg,
488 .fg_params = &fg,
Lee Jones861a30d2012-08-29 20:36:51 +0800489 .chg_input_curr = ab8500_charge_input_curr_map,
490 .n_chg_in_curr = ARRAY_SIZE(ab8500_charge_input_curr_map),
491};
492
Linus Torvalds5a120392013-02-20 10:19:07 -0800493int ab8500_bm_of_probe(struct device *dev,
494 struct device_node *np,
495 struct abx500_bm_data *bm)
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800496{
Hongbo Zhang2c899402013-04-03 20:18:10 +0800497 const struct batres_vs_temp *tmp_batres_tbl;
Lee Jones215cf5c2012-11-30 11:38:52 +0000498 struct device_node *battery_node;
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800499 const char *btech;
Lee Jones8e3a71e2012-11-30 09:16:40 +0000500 int i;
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800501
502 /* get phandle to 'battery-info' node */
Lee Jones215cf5c2012-11-30 11:38:52 +0000503 battery_node = of_parse_phandle(np, "battery", 0);
504 if (!battery_node) {
Lee Jones8e3a71e2012-11-30 09:16:40 +0000505 dev_err(dev, "battery node or reference missing\n");
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800506 return -EINVAL;
507 }
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800508
Lee Jones215cf5c2012-11-30 11:38:52 +0000509 btech = of_get_property(battery_node, "stericsson,battery-type", NULL);
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800510 if (!btech) {
511 dev_warn(dev, "missing property battery-name/type\n");
Wen Yang0b646fd2019-04-17 10:43:02 +0800512 of_node_put(battery_node);
Rajanikanth H.Vf5695a32012-11-29 00:57:45 +0530513 return -EINVAL;
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800514 }
515
Rajanikanth H.Vf5695a32012-11-29 00:57:45 +0530516 if (strncmp(btech, "LION", 4) == 0) {
Lee Jones23a04f92012-11-29 15:08:41 +0000517 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;
Marcus Cooperea402402013-01-11 13:12:54 +0000521 bm->bat_type[BATTERY_UNKNOWN].recharge_cap = 95;
Lee Jones23a04f92012-11-29 15:08:41 +0000522 bm->bat_type[BATTERY_UNKNOWN].normal_cur_lvl = 520;
523 bm->bat_type[BATTERY_UNKNOWN].normal_vol_lvl = 4200;
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800524 }
Lee Jones43dc4472012-11-29 15:26:22 +0000525
Lee Jones215cf5c2012-11-30 11:38:52 +0000526 if (of_property_read_bool(battery_node, "thermistor-on-batctrl")) {
Lee Jones8e3a71e2012-11-30 09:16:40 +0000527 if (strncmp(btech, "LION", 4) == 0)
528 tmp_batres_tbl = temp_to_batres_tbl_9100;
529 else
530 tmp_batres_tbl = temp_to_batres_tbl_thermistor;
531 } else {
Lee Jones23a04f92012-11-29 15:08:41 +0000532 bm->n_btypes = 4;
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;
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800536 }
Lee Jones8e3a71e2012-11-30 09:16:40 +0000537
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800538 /* select the battery resolution table */
Lee Jones23a04f92012-11-29 15:08:41 +0000539 for (i = 0; i < bm->n_btypes; ++i)
540 bm->bat_type[i].batres_tbl = tmp_batres_tbl;
Lee Jones8e3a71e2012-11-30 09:16:40 +0000541
Lee Jones215cf5c2012-11-30 11:38:52 +0000542 of_node_put(battery_node);
Lee Jones43dc4472012-11-29 15:26:22 +0000543
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800544 return 0;
545}