blob: 4a7ed50d1dc549901596e4b0e67efa46a7ba9e7e [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>
7#include <linux/mfd/abx500/ab8500-bm.h>
8
9/*
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
13 * values to work.
14 */
Hongbo Zhangea2be6f2013-04-03 20:18:11 +080015const struct abx500_res_to_temp ab8500_temp_tbl_a_thermistor[] = {
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -080016 {-5, 53407},
17 { 0, 48594},
18 { 5, 43804},
19 {10, 39188},
20 {15, 34870},
21 {20, 30933},
22 {25, 27422},
23 {30, 24347},
24 {35, 21694},
25 {40, 19431},
26 {45, 17517},
27 {50, 15908},
28 {55, 14561},
29 {60, 13437},
30 {65, 12500},
31};
Hongbo Zhangea2be6f2013-04-03 20:18:11 +080032EXPORT_SYMBOL(ab8500_temp_tbl_a_thermistor);
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -080033
Hongbo Zhangea2be6f2013-04-03 20:18:11 +080034const int ab8500_temp_tbl_a_size = ARRAY_SIZE(ab8500_temp_tbl_a_thermistor);
35EXPORT_SYMBOL(ab8500_temp_tbl_a_size);
36
37const struct abx500_res_to_temp ab8500_temp_tbl_b_thermistor[] = {
Rajanikanth H.Vbd9e8ab2012-11-18 19:16:58 -080038 {-5, 200000},
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -080039 { 0, 159024},
40 { 5, 151921},
41 {10, 144300},
42 {15, 136424},
43 {20, 128565},
44 {25, 120978},
45 {30, 113875},
46 {35, 107397},
47 {40, 101629},
48 {45, 96592},
49 {50, 92253},
50 {55, 88569},
51 {60, 85461},
52 {65, 82869},
53};
Hongbo Zhangea2be6f2013-04-03 20:18:11 +080054EXPORT_SYMBOL(ab8500_temp_tbl_b_thermistor);
55
56const int ab8500_temp_tbl_b_size = ARRAY_SIZE(ab8500_temp_tbl_b_thermistor);
57EXPORT_SYMBOL(ab8500_temp_tbl_b_size);
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -080058
Hongbo Zhang2c899402013-04-03 20:18:10 +080059static const struct abx500_v_to_cap cap_tbl_a_thermistor[] = {
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -080060 {4171, 100},
61 {4114, 95},
62 {4009, 83},
63 {3947, 74},
64 {3907, 67},
65 {3863, 59},
66 {3830, 56},
67 {3813, 53},
68 {3791, 46},
69 {3771, 33},
70 {3754, 25},
71 {3735, 20},
72 {3717, 17},
73 {3681, 13},
74 {3664, 8},
75 {3651, 6},
76 {3635, 5},
77 {3560, 3},
78 {3408, 1},
79 {3247, 0},
80};
81
Hongbo Zhang2c899402013-04-03 20:18:10 +080082static const struct abx500_v_to_cap cap_tbl_b_thermistor[] = {
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -080083 {4161, 100},
84 {4124, 98},
85 {4044, 90},
86 {4003, 85},
87 {3966, 80},
88 {3933, 75},
89 {3888, 67},
90 {3849, 60},
91 {3813, 55},
92 {3787, 47},
93 {3772, 30},
94 {3751, 25},
95 {3718, 20},
96 {3681, 16},
97 {3660, 14},
98 {3589, 10},
99 {3546, 7},
100 {3495, 4},
101 {3404, 2},
102 {3250, 0},
103};
104
Hongbo Zhang2c899402013-04-03 20:18:10 +0800105static const struct abx500_v_to_cap cap_tbl[] = {
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800106 {4186, 100},
107 {4163, 99},
108 {4114, 95},
109 {4068, 90},
110 {3990, 80},
111 {3926, 70},
112 {3898, 65},
113 {3866, 60},
114 {3833, 55},
115 {3812, 50},
116 {3787, 40},
117 {3768, 30},
118 {3747, 25},
119 {3730, 20},
120 {3705, 15},
121 {3699, 14},
122 {3684, 12},
123 {3672, 9},
124 {3657, 7},
125 {3638, 6},
126 {3556, 4},
127 {3424, 2},
128 {3317, 1},
129 {3094, 0},
130};
131
132/*
133 * Note that the res_to_temp table must be strictly sorted by falling
134 * resistance values to work.
135 */
Hongbo Zhang2c899402013-04-03 20:18:10 +0800136static const struct abx500_res_to_temp temp_tbl[] = {
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800137 {-5, 214834},
138 { 0, 162943},
139 { 5, 124820},
140 {10, 96520},
141 {15, 75306},
142 {20, 59254},
143 {25, 47000},
144 {30, 37566},
145 {35, 30245},
146 {40, 24520},
147 {45, 20010},
148 {50, 16432},
149 {55, 13576},
150 {60, 11280},
151 {65, 9425},
152};
153
154/*
155 * Note that the batres_vs_temp table must be strictly sorted by falling
156 * temperature values to work.
157 */
Hongbo Zhang2c899402013-04-03 20:18:10 +0800158static const struct batres_vs_temp temp_to_batres_tbl_thermistor[] = {
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800159 { 40, 120},
160 { 30, 135},
161 { 20, 165},
162 { 10, 230},
163 { 00, 325},
164 {-10, 445},
165 {-20, 595},
166};
167
168/*
169 * Note that the batres_vs_temp table must be strictly sorted by falling
170 * temperature values to work.
171 */
Hongbo Zhang2c899402013-04-03 20:18:10 +0800172static const struct batres_vs_temp temp_to_batres_tbl_ext_thermistor[] = {
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800173 { 60, 300},
174 { 30, 300},
175 { 20, 300},
176 { 10, 300},
177 { 00, 300},
178 {-10, 300},
179 {-20, 300},
180};
181
182/* battery resistance table for LI ION 9100 battery */
Hongbo Zhang2c899402013-04-03 20:18:10 +0800183static const struct batres_vs_temp temp_to_batres_tbl_9100[] = {
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800184 { 60, 180},
185 { 30, 180},
186 { 20, 180},
187 { 10, 180},
188 { 00, 180},
189 {-10, 180},
190 {-20, 180},
191};
192
193static struct abx500_battery_type bat_type_thermistor[] = {
Lee Jones43dc4472012-11-29 15:26:22 +0000194 [BATTERY_UNKNOWN] = {
195 /* First element always represent the UNKNOWN battery */
196 .name = POWER_SUPPLY_TECHNOLOGY_UNKNOWN,
197 .resis_high = 0,
198 .resis_low = 0,
199 .battery_resistance = 300,
200 .charge_full_design = 612,
201 .nominal_voltage = 3700,
202 .termination_vol = 4050,
203 .termination_curr = 200,
Marcus Cooperea402402013-01-11 13:12:54 +0000204 .recharge_cap = 95,
Lee Jones43dc4472012-11-29 15:26:22 +0000205 .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,
221 },
222 {
223 .name = POWER_SUPPLY_TECHNOLOGY_LIPO,
224 .resis_high = 53407,
225 .resis_low = 12500,
226 .battery_resistance = 300,
227 .charge_full_design = 900,
228 .nominal_voltage = 3600,
229 .termination_vol = 4150,
230 .termination_curr = 80,
Marcus Cooperea402402013-01-11 13:12:54 +0000231 .recharge_cap = 95,
Lee Jones43dc4472012-11-29 15:26:22 +0000232 .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,
Hongbo Zhangea2be6f2013-04-03 20:18:11 +0800242 .n_temp_tbl_elements = ARRAY_SIZE(ab8500_temp_tbl_a_thermistor),
243 .r_to_t_tbl = ab8500_temp_tbl_a_thermistor,
Hongbo Zhang6c1f8e02013-04-03 20:18:09 +0800244 .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl_a_thermistor),
245 .v_to_cap_tbl = cap_tbl_a_thermistor,
Lee Jones43dc4472012-11-29 15:26:22 +0000246 .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
247 .batres_tbl = temp_to_batres_tbl_thermistor,
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800248
Lee Jones43dc4472012-11-29 15:26:22 +0000249 },
250 {
251 .name = POWER_SUPPLY_TECHNOLOGY_LIPO,
252 .resis_high = 200000,
253 .resis_low = 82869,
254 .battery_resistance = 300,
255 .charge_full_design = 900,
256 .nominal_voltage = 3600,
257 .termination_vol = 4150,
258 .termination_curr = 80,
Marcus Cooperea402402013-01-11 13:12:54 +0000259 .recharge_cap = 95,
Lee Jones43dc4472012-11-29 15:26:22 +0000260 .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,
Hongbo Zhangea2be6f2013-04-03 20:18:11 +0800270 .n_temp_tbl_elements = ARRAY_SIZE(ab8500_temp_tbl_b_thermistor),
271 .r_to_t_tbl = ab8500_temp_tbl_b_thermistor,
Hongbo Zhang6c1f8e02013-04-03 20:18:09 +0800272 .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl_b_thermistor),
273 .v_to_cap_tbl = cap_tbl_b_thermistor,
Lee Jones43dc4472012-11-29 15:26:22 +0000274 .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
275 .batres_tbl = temp_to_batres_tbl_thermistor,
276 },
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800277};
278
279static struct abx500_battery_type bat_type_ext_thermistor[] = {
Lee Jones43dc4472012-11-29 15:26:22 +0000280 [BATTERY_UNKNOWN] = {
281 /* First element always represent the UNKNOWN battery */
282 .name = POWER_SUPPLY_TECHNOLOGY_UNKNOWN,
283 .resis_high = 0,
284 .resis_low = 0,
285 .battery_resistance = 300,
286 .charge_full_design = 612,
287 .nominal_voltage = 3700,
288 .termination_vol = 4050,
289 .termination_curr = 200,
Marcus Cooperea402402013-01-11 13:12:54 +0000290 .recharge_cap = 95,
Lee Jones43dc4472012-11-29 15:26:22 +0000291 .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,
307 },
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800308/*
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.
312 */
Lee Jones43dc4472012-11-29 15:26:22 +0000313 {
314 .name = POWER_SUPPLY_TECHNOLOGY_LIPO,
315 .resis_high = 76000,
316 .resis_low = 53000,
317 .battery_resistance = 300,
318 .charge_full_design = 900,
319 .nominal_voltage = 3700,
320 .termination_vol = 4150,
321 .termination_curr = 100,
Marcus Cooperea402402013-01-11 13:12:54 +0000322 .recharge_cap = 95,
Lee Jones43dc4472012-11-29 15:26:22 +0000323 .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,
339 },
340 {
341 .name = POWER_SUPPLY_TECHNOLOGY_LION,
342 .resis_high = 30000,
343 .resis_low = 10000,
344 .battery_resistance = 300,
345 .charge_full_design = 950,
346 .nominal_voltage = 3700,
347 .termination_vol = 4150,
348 .termination_curr = 100,
Marcus Cooperea402402013-01-11 13:12:54 +0000349 .recharge_cap = 95,
Lee Jones43dc4472012-11-29 15:26:22 +0000350 .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,
366 },
367 {
368 .name = POWER_SUPPLY_TECHNOLOGY_LION,
369 .resis_high = 95000,
370 .resis_low = 76001,
371 .battery_resistance = 300,
372 .charge_full_design = 950,
373 .nominal_voltage = 3700,
374 .termination_vol = 4150,
375 .termination_curr = 100,
Marcus Cooperea402402013-01-11 13:12:54 +0000376 .recharge_cap = 95,
Lee Jones43dc4472012-11-29 15:26:22 +0000377 .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,
393 },
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800394};
395
396static const struct abx500_bm_capacity_levels cap_levels = {
397 .critical = 2,
398 .low = 10,
399 .normal = 70,
400 .high = 95,
401 .full = 100,
402};
403
404static const struct abx500_fg_parameters fg = {
405 .recovery_sleep_timer = 10,
406 .recovery_total_time = 100,
407 .init_timer = 1,
408 .init_discard_time = 5,
409 .init_total_time = 40,
410 .high_curr_time = 60,
411 .accu_charging = 30,
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,
Marcus Cooperea402402013-01-11 13:12:54 +0000417 .maint_thres = 95,
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800418 .user_cap_limit = 15,
Lee Jones93ff7222012-05-31 16:16:36 +0200419 .pcut_enable = 1,
420 .pcut_max_time = 127,
421 .pcut_flag_time = 112,
422 .pcut_max_restart = 15,
423 .pcut_debounce_time = 2,
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800424};
425
Lee Jones861a30d2012-08-29 20:36:51 +0800426static const struct abx500_maxim_parameters ab8500_maxi_params = {
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800427 .ena_maxi = true,
428 .chg_curr = 910,
429 .wait_cycles = 10,
430 .charger_curr_step = 100,
431};
432
Lee Jones861a30d2012-08-29 20:36:51 +0800433static const struct abx500_maxim_parameters abx540_maxi_params = {
Munir Contractord7147242017-02-19 18:19:53 -0500434 .ena_maxi = true,
435 .chg_curr = 3000,
436 .wait_cycles = 10,
437 .charger_curr_step = 200,
Lee Jones861a30d2012-08-29 20:36:51 +0800438};
439
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800440static const struct abx500_bm_charger_parameters chg = {
441 .usb_volt_max = 5500,
442 .usb_curr_max = 1500,
443 .ac_volt_max = 7500,
444 .ac_curr_max = 1500,
445};
446
Lee Jones861a30d2012-08-29 20:36:51 +0800447/*
448 * This array maps the raw hex value to charger output current used by the
449 * AB8500 values
450 */
451static int ab8500_charge_output_curr_map[] = {
452 100, 200, 300, 400, 500, 600, 700, 800,
453 900, 1000, 1100, 1200, 1300, 1400, 1500, 1500,
454};
455
456static int ab8540_charge_output_curr_map[] = {
457 0, 0, 0, 75, 100, 125, 150, 175,
458 200, 225, 250, 275, 300, 325, 350, 375,
459 400, 425, 450, 475, 500, 525, 550, 575,
460 600, 625, 650, 675, 700, 725, 750, 775,
461 800, 825, 850, 875, 900, 925, 950, 975,
462 1000, 1025, 1050, 1075, 1100, 1125, 1150, 1175,
463 1200, 1225, 1250, 1275, 1300, 1325, 1350, 1375,
464 1400, 1425, 1450, 1500, 1600, 1700, 1900, 2000,
465};
466
467/*
468 * This array maps the raw hex value to charger input current used by the
469 * AB8500 values
470 */
471static int ab8500_charge_input_curr_map[] = {
472 50, 98, 193, 290, 380, 450, 500, 600,
473 700, 800, 900, 1000, 1100, 1300, 1400, 1500,
474};
475
476static int ab8540_charge_input_curr_map[] = {
477 25, 50, 75, 100, 125, 150, 175, 200,
478 225, 250, 275, 300, 325, 350, 375, 400,
479 425, 450, 475, 500, 525, 550, 575, 600,
480 625, 650, 675, 700, 725, 750, 775, 800,
481 825, 850, 875, 900, 925, 950, 975, 1000,
482 1025, 1050, 1075, 1100, 1125, 1150, 1175, 1200,
483 1225, 1250, 1275, 1300, 1325, 1350, 1375, 1400,
484 1425, 1450, 1475, 1500, 1500, 1500, 1500, 1500,
485};
486
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800487struct abx500_bm_data ab8500_bm_data = {
Lee Jones43dc4472012-11-29 15:26:22 +0000488 .temp_under = 3,
489 .temp_low = 8,
490 .temp_high = 43,
491 .temp_over = 48,
492 .main_safety_tmr_h = 4,
493 .temp_interval_chg = 20,
494 .temp_interval_nochg = 120,
495 .usb_safety_tmr_h = 4,
496 .bkup_bat_v = BUP_VCH_SEL_2P6V,
497 .bkup_bat_i = BUP_ICH_SEL_150UA,
498 .no_maintenance = false,
Marcus Cooperea402402013-01-11 13:12:54 +0000499 .capacity_scaling = false,
Lee Jones43dc4472012-11-29 15:26:22 +0000500 .adc_therm = ABx500_ADC_THERM_BATCTRL,
501 .chg_unknown_bat = false,
502 .enable_overshoot = false,
503 .fg_res = 100,
504 .cap_levels = &cap_levels,
505 .bat_type = bat_type_thermistor,
Lee Jones861a30d2012-08-29 20:36:51 +0800506 .n_btypes = ARRAY_SIZE(bat_type_thermistor),
Lee Jones43dc4472012-11-29 15:26:22 +0000507 .batt_id = 0,
508 .interval_charging = 5,
509 .interval_not_charging = 120,
510 .temp_hysteresis = 3,
511 .gnd_lift_resistance = 34,
Lee Jones861a30d2012-08-29 20:36:51 +0800512 .chg_output_curr = ab8500_charge_output_curr_map,
513 .n_chg_out_curr = ARRAY_SIZE(ab8500_charge_output_curr_map),
514 .maxi = &ab8500_maxi_params,
Lee Jones43dc4472012-11-29 15:26:22 +0000515 .chg_params = &chg,
516 .fg_params = &fg,
Lee Jones861a30d2012-08-29 20:36:51 +0800517 .chg_input_curr = ab8500_charge_input_curr_map,
518 .n_chg_in_curr = ARRAY_SIZE(ab8500_charge_input_curr_map),
519};
520
521struct abx500_bm_data ab8540_bm_data = {
522 .temp_under = 3,
523 .temp_low = 8,
524 .temp_high = 43,
525 .temp_over = 48,
526 .main_safety_tmr_h = 4,
527 .temp_interval_chg = 20,
528 .temp_interval_nochg = 120,
529 .usb_safety_tmr_h = 4,
530 .bkup_bat_v = BUP_VCH_SEL_2P6V,
531 .bkup_bat_i = BUP_ICH_SEL_150UA,
532 .no_maintenance = false,
533 .capacity_scaling = false,
534 .adc_therm = ABx500_ADC_THERM_BATCTRL,
535 .chg_unknown_bat = false,
536 .enable_overshoot = false,
537 .fg_res = 100,
538 .cap_levels = &cap_levels,
539 .bat_type = bat_type_thermistor,
540 .n_btypes = ARRAY_SIZE(bat_type_thermistor),
541 .batt_id = 0,
542 .interval_charging = 5,
543 .interval_not_charging = 120,
544 .temp_hysteresis = 3,
545 .gnd_lift_resistance = 0,
546 .maxi = &abx540_maxi_params,
547 .chg_params = &chg,
548 .fg_params = &fg,
549 .chg_output_curr = ab8540_charge_output_curr_map,
550 .n_chg_out_curr = ARRAY_SIZE(ab8540_charge_output_curr_map),
551 .chg_input_curr = ab8540_charge_input_curr_map,
552 .n_chg_in_curr = ARRAY_SIZE(ab8540_charge_input_curr_map),
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800553};
554
Linus Torvalds5a120392013-02-20 10:19:07 -0800555int ab8500_bm_of_probe(struct device *dev,
556 struct device_node *np,
557 struct abx500_bm_data *bm)
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800558{
Hongbo Zhang2c899402013-04-03 20:18:10 +0800559 const struct batres_vs_temp *tmp_batres_tbl;
Lee Jones215cf5c2012-11-30 11:38:52 +0000560 struct device_node *battery_node;
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800561 const char *btech;
Lee Jones8e3a71e2012-11-30 09:16:40 +0000562 int i;
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800563
564 /* get phandle to 'battery-info' node */
Lee Jones215cf5c2012-11-30 11:38:52 +0000565 battery_node = of_parse_phandle(np, "battery", 0);
566 if (!battery_node) {
Lee Jones8e3a71e2012-11-30 09:16:40 +0000567 dev_err(dev, "battery node or reference missing\n");
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800568 return -EINVAL;
569 }
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800570
Lee Jones215cf5c2012-11-30 11:38:52 +0000571 btech = of_get_property(battery_node, "stericsson,battery-type", NULL);
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800572 if (!btech) {
573 dev_warn(dev, "missing property battery-name/type\n");
Rajanikanth H.Vf5695a32012-11-29 00:57:45 +0530574 return -EINVAL;
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800575 }
576
Rajanikanth H.Vf5695a32012-11-29 00:57:45 +0530577 if (strncmp(btech, "LION", 4) == 0) {
Lee Jones23a04f92012-11-29 15:08:41 +0000578 bm->no_maintenance = true;
579 bm->chg_unknown_bat = true;
580 bm->bat_type[BATTERY_UNKNOWN].charge_full_design = 2600;
581 bm->bat_type[BATTERY_UNKNOWN].termination_vol = 4150;
Marcus Cooperea402402013-01-11 13:12:54 +0000582 bm->bat_type[BATTERY_UNKNOWN].recharge_cap = 95;
Lee Jones23a04f92012-11-29 15:08:41 +0000583 bm->bat_type[BATTERY_UNKNOWN].normal_cur_lvl = 520;
584 bm->bat_type[BATTERY_UNKNOWN].normal_vol_lvl = 4200;
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800585 }
Lee Jones43dc4472012-11-29 15:26:22 +0000586
Lee Jones215cf5c2012-11-30 11:38:52 +0000587 if (of_property_read_bool(battery_node, "thermistor-on-batctrl")) {
Lee Jones8e3a71e2012-11-30 09:16:40 +0000588 if (strncmp(btech, "LION", 4) == 0)
589 tmp_batres_tbl = temp_to_batres_tbl_9100;
590 else
591 tmp_batres_tbl = temp_to_batres_tbl_thermistor;
592 } else {
Lee Jones23a04f92012-11-29 15:08:41 +0000593 bm->n_btypes = 4;
594 bm->bat_type = bat_type_ext_thermistor;
595 bm->adc_therm = ABx500_ADC_THERM_BATTEMP;
596 tmp_batres_tbl = temp_to_batres_tbl_ext_thermistor;
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800597 }
Lee Jones8e3a71e2012-11-30 09:16:40 +0000598
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800599 /* select the battery resolution table */
Lee Jones23a04f92012-11-29 15:08:41 +0000600 for (i = 0; i < bm->n_btypes; ++i)
601 bm->bat_type[i].batres_tbl = tmp_batres_tbl;
Lee Jones8e3a71e2012-11-30 09:16:40 +0000602
Lee Jones215cf5c2012-11-30 11:38:52 +0000603 of_node_put(battery_node);
Lee Jones43dc4472012-11-29 15:26:22 +0000604
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800605 return 0;
606}