Blame view

drivers/power/supply/ab8500_bmdata.c 16.5 KB
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
1
2
3
4
5
6
7
8
9
10
11
12
13
  #include <linux/export.h>
  #include <linux/power_supply.h>
  #include <linux/of.h>
  #include <linux/mfd/abx500.h>
  #include <linux/mfd/abx500/ab8500.h>
  #include <linux/mfd/abx500/ab8500-bm.h>
  
  /*
   * These are the defined batteries that uses a NTC and ID resistor placed
   * inside of the battery pack.
   * Note that the res_to_temp table must be strictly sorted by falling resistance
   * values to work.
   */
ea2be6f21   Hongbo Zhang   ab8500_bmdata: Ex...
14
  const struct abx500_res_to_temp ab8500_temp_tbl_a_thermistor[] = {
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  	{-5, 53407},
  	{ 0, 48594},
  	{ 5, 43804},
  	{10, 39188},
  	{15, 34870},
  	{20, 30933},
  	{25, 27422},
  	{30, 24347},
  	{35, 21694},
  	{40, 19431},
  	{45, 17517},
  	{50, 15908},
  	{55, 14561},
  	{60, 13437},
  	{65, 12500},
  };
ea2be6f21   Hongbo Zhang   ab8500_bmdata: Ex...
31
  EXPORT_SYMBOL(ab8500_temp_tbl_a_thermistor);
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
32

ea2be6f21   Hongbo Zhang   ab8500_bmdata: Ex...
33
34
35
36
  const int ab8500_temp_tbl_a_size = ARRAY_SIZE(ab8500_temp_tbl_a_thermistor);
  EXPORT_SYMBOL(ab8500_temp_tbl_a_size);
  
  const struct abx500_res_to_temp ab8500_temp_tbl_b_thermistor[] = {
bd9e8ab2d   Rajanikanth H.V   ab8500: Add devic...
37
  	{-5, 200000},
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  	{ 0, 159024},
  	{ 5, 151921},
  	{10, 144300},
  	{15, 136424},
  	{20, 128565},
  	{25, 120978},
  	{30, 113875},
  	{35, 107397},
  	{40, 101629},
  	{45,  96592},
  	{50,  92253},
  	{55,  88569},
  	{60,  85461},
  	{65,  82869},
  };
ea2be6f21   Hongbo Zhang   ab8500_bmdata: Ex...
53
54
55
56
  EXPORT_SYMBOL(ab8500_temp_tbl_b_thermistor);
  
  const int ab8500_temp_tbl_b_size = ARRAY_SIZE(ab8500_temp_tbl_b_thermistor);
  EXPORT_SYMBOL(ab8500_temp_tbl_b_size);
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
57

2c8994078   Hongbo Zhang   ab8500_{bmdata,fg...
58
  static const struct abx500_v_to_cap cap_tbl_a_thermistor[] = {
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  	{4171,	100},
  	{4114,	 95},
  	{4009,	 83},
  	{3947,	 74},
  	{3907,	 67},
  	{3863,	 59},
  	{3830,	 56},
  	{3813,	 53},
  	{3791,	 46},
  	{3771,	 33},
  	{3754,	 25},
  	{3735,	 20},
  	{3717,	 17},
  	{3681,	 13},
  	{3664,	  8},
  	{3651,	  6},
  	{3635,	  5},
  	{3560,	  3},
  	{3408,    1},
  	{3247,	  0},
  };
2c8994078   Hongbo Zhang   ab8500_{bmdata,fg...
80
  static const struct abx500_v_to_cap cap_tbl_b_thermistor[] = {
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
  	{4161,	100},
  	{4124,	 98},
  	{4044,	 90},
  	{4003,	 85},
  	{3966,	 80},
  	{3933,	 75},
  	{3888,	 67},
  	{3849,	 60},
  	{3813,	 55},
  	{3787,	 47},
  	{3772,	 30},
  	{3751,	 25},
  	{3718,	 20},
  	{3681,	 16},
  	{3660,	 14},
  	{3589,	 10},
  	{3546,	  7},
  	{3495,	  4},
  	{3404,	  2},
  	{3250,	  0},
  };
2c8994078   Hongbo Zhang   ab8500_{bmdata,fg...
102
  static const struct abx500_v_to_cap cap_tbl[] = {
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
  	{4186,	100},
  	{4163,	 99},
  	{4114,	 95},
  	{4068,	 90},
  	{3990,	 80},
  	{3926,	 70},
  	{3898,	 65},
  	{3866,	 60},
  	{3833,	 55},
  	{3812,	 50},
  	{3787,	 40},
  	{3768,	 30},
  	{3747,	 25},
  	{3730,	 20},
  	{3705,	 15},
  	{3699,	 14},
  	{3684,	 12},
  	{3672,	  9},
  	{3657,	  7},
  	{3638,	  6},
  	{3556,	  4},
  	{3424,	  2},
  	{3317,	  1},
  	{3094,	  0},
  };
  
  /*
   * Note that the res_to_temp table must be strictly sorted by falling
   * resistance values to work.
   */
2c8994078   Hongbo Zhang   ab8500_{bmdata,fg...
133
  static const struct abx500_res_to_temp temp_tbl[] = {
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
  	{-5, 214834},
  	{ 0, 162943},
  	{ 5, 124820},
  	{10,  96520},
  	{15,  75306},
  	{20,  59254},
  	{25,  47000},
  	{30,  37566},
  	{35,  30245},
  	{40,  24520},
  	{45,  20010},
  	{50,  16432},
  	{55,  13576},
  	{60,  11280},
  	{65,   9425},
  };
  
  /*
   * Note that the batres_vs_temp table must be strictly sorted by falling
   * temperature values to work.
   */
2c8994078   Hongbo Zhang   ab8500_{bmdata,fg...
155
  static const struct batres_vs_temp temp_to_batres_tbl_thermistor[] = {
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
156
157
158
159
160
161
162
163
164
165
166
167
168
  	{ 40, 120},
  	{ 30, 135},
  	{ 20, 165},
  	{ 10, 230},
  	{ 00, 325},
  	{-10, 445},
  	{-20, 595},
  };
  
  /*
   * Note that the batres_vs_temp table must be strictly sorted by falling
   * temperature values to work.
   */
2c8994078   Hongbo Zhang   ab8500_{bmdata,fg...
169
  static const struct batres_vs_temp temp_to_batres_tbl_ext_thermistor[] = {
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
170
171
172
173
174
175
176
177
178
179
  	{ 60, 300},
  	{ 30, 300},
  	{ 20, 300},
  	{ 10, 300},
  	{ 00, 300},
  	{-10, 300},
  	{-20, 300},
  };
  
  /* battery resistance table for LI ION 9100 battery */
2c8994078   Hongbo Zhang   ab8500_{bmdata,fg...
180
  static const struct batres_vs_temp temp_to_batres_tbl_9100[] = {
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
181
182
183
184
185
186
187
188
189
190
  	{ 60, 180},
  	{ 30, 180},
  	{ 20, 180},
  	{ 10, 180},
  	{ 00, 180},
  	{-10, 180},
  	{-20, 180},
  };
  
  static struct abx500_battery_type bat_type_thermistor[] = {
43dc4470e   Lee Jones   ab8500_btemp: Fix...
191
192
193
194
195
196
197
198
199
200
  	[BATTERY_UNKNOWN] = {
  		/* First element always represent the UNKNOWN battery */
  		.name = POWER_SUPPLY_TECHNOLOGY_UNKNOWN,
  		.resis_high = 0,
  		.resis_low = 0,
  		.battery_resistance = 300,
  		.charge_full_design = 612,
  		.nominal_voltage = 3700,
  		.termination_vol = 4050,
  		.termination_curr = 200,
ea4024017   Marcus Cooper   ab8500_bm: Rechar...
201
  		.recharge_cap = 95,
43dc4470e   Lee Jones   ab8500_btemp: Fix...
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
  		.normal_cur_lvl = 400,
  		.normal_vol_lvl = 4100,
  		.maint_a_cur_lvl = 400,
  		.maint_a_vol_lvl = 4050,
  		.maint_a_chg_timer_h = 60,
  		.maint_b_cur_lvl = 400,
  		.maint_b_vol_lvl = 4000,
  		.maint_b_chg_timer_h = 200,
  		.low_high_cur_lvl = 300,
  		.low_high_vol_lvl = 4000,
  		.n_temp_tbl_elements = ARRAY_SIZE(temp_tbl),
  		.r_to_t_tbl = temp_tbl,
  		.n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl),
  		.v_to_cap_tbl = cap_tbl,
  		.n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
  		.batres_tbl = temp_to_batres_tbl_thermistor,
  	},
  	{
  		.name = POWER_SUPPLY_TECHNOLOGY_LIPO,
  		.resis_high = 53407,
  		.resis_low = 12500,
  		.battery_resistance = 300,
  		.charge_full_design = 900,
  		.nominal_voltage = 3600,
  		.termination_vol = 4150,
  		.termination_curr = 80,
ea4024017   Marcus Cooper   ab8500_bm: Rechar...
228
  		.recharge_cap = 95,
43dc4470e   Lee Jones   ab8500_btemp: Fix...
229
230
231
232
233
234
235
236
237
238
  		.normal_cur_lvl = 700,
  		.normal_vol_lvl = 4200,
  		.maint_a_cur_lvl = 600,
  		.maint_a_vol_lvl = 4150,
  		.maint_a_chg_timer_h = 60,
  		.maint_b_cur_lvl = 600,
  		.maint_b_vol_lvl = 4100,
  		.maint_b_chg_timer_h = 200,
  		.low_high_cur_lvl = 300,
  		.low_high_vol_lvl = 4000,
ea2be6f21   Hongbo Zhang   ab8500_bmdata: Ex...
239
240
  		.n_temp_tbl_elements = ARRAY_SIZE(ab8500_temp_tbl_a_thermistor),
  		.r_to_t_tbl = ab8500_temp_tbl_a_thermistor,
6c1f8e02c   Hongbo Zhang   ab8500_bmdata: El...
241
242
  		.n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl_a_thermistor),
  		.v_to_cap_tbl = cap_tbl_a_thermistor,
43dc4470e   Lee Jones   ab8500_btemp: Fix...
243
244
  		.n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
  		.batres_tbl = temp_to_batres_tbl_thermistor,
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
245

43dc4470e   Lee Jones   ab8500_btemp: Fix...
246
247
248
249
250
251
252
253
254
255
  	},
  	{
  		.name = POWER_SUPPLY_TECHNOLOGY_LIPO,
  		.resis_high = 200000,
  		.resis_low = 82869,
  		.battery_resistance = 300,
  		.charge_full_design = 900,
  		.nominal_voltage = 3600,
  		.termination_vol = 4150,
  		.termination_curr = 80,
ea4024017   Marcus Cooper   ab8500_bm: Rechar...
256
  		.recharge_cap = 95,
43dc4470e   Lee Jones   ab8500_btemp: Fix...
257
258
259
260
261
262
263
264
265
266
  		.normal_cur_lvl = 700,
  		.normal_vol_lvl = 4200,
  		.maint_a_cur_lvl = 600,
  		.maint_a_vol_lvl = 4150,
  		.maint_a_chg_timer_h = 60,
  		.maint_b_cur_lvl = 600,
  		.maint_b_vol_lvl = 4100,
  		.maint_b_chg_timer_h = 200,
  		.low_high_cur_lvl = 300,
  		.low_high_vol_lvl = 4000,
ea2be6f21   Hongbo Zhang   ab8500_bmdata: Ex...
267
268
  		.n_temp_tbl_elements = ARRAY_SIZE(ab8500_temp_tbl_b_thermistor),
  		.r_to_t_tbl = ab8500_temp_tbl_b_thermistor,
6c1f8e02c   Hongbo Zhang   ab8500_bmdata: El...
269
270
  		.n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl_b_thermistor),
  		.v_to_cap_tbl = cap_tbl_b_thermistor,
43dc4470e   Lee Jones   ab8500_btemp: Fix...
271
272
273
  		.n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
  		.batres_tbl = temp_to_batres_tbl_thermistor,
  	},
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
274
275
276
  };
  
  static struct abx500_battery_type bat_type_ext_thermistor[] = {
43dc4470e   Lee Jones   ab8500_btemp: Fix...
277
278
279
280
281
282
283
284
285
286
  	[BATTERY_UNKNOWN] = {
  		/* First element always represent the UNKNOWN battery */
  		.name = POWER_SUPPLY_TECHNOLOGY_UNKNOWN,
  		.resis_high = 0,
  		.resis_low = 0,
  		.battery_resistance = 300,
  		.charge_full_design = 612,
  		.nominal_voltage = 3700,
  		.termination_vol = 4050,
  		.termination_curr = 200,
ea4024017   Marcus Cooper   ab8500_bm: Rechar...
287
  		.recharge_cap = 95,
43dc4470e   Lee Jones   ab8500_btemp: Fix...
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
  		.normal_cur_lvl = 400,
  		.normal_vol_lvl = 4100,
  		.maint_a_cur_lvl = 400,
  		.maint_a_vol_lvl = 4050,
  		.maint_a_chg_timer_h = 60,
  		.maint_b_cur_lvl = 400,
  		.maint_b_vol_lvl = 4000,
  		.maint_b_chg_timer_h = 200,
  		.low_high_cur_lvl = 300,
  		.low_high_vol_lvl = 4000,
  		.n_temp_tbl_elements = ARRAY_SIZE(temp_tbl),
  		.r_to_t_tbl = temp_tbl,
  		.n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl),
  		.v_to_cap_tbl = cap_tbl,
  		.n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
  		.batres_tbl = temp_to_batres_tbl_thermistor,
  	},
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
305
306
307
308
309
  /*
   * These are the batteries that doesn't have an internal NTC resistor to measure
   * its temperature. The temperature in this case is measure with a NTC placed
   * near the battery but on the PCB.
   */
43dc4470e   Lee Jones   ab8500_btemp: Fix...
310
311
312
313
314
315
316
317
318
  	{
  		.name = POWER_SUPPLY_TECHNOLOGY_LIPO,
  		.resis_high = 76000,
  		.resis_low = 53000,
  		.battery_resistance = 300,
  		.charge_full_design = 900,
  		.nominal_voltage = 3700,
  		.termination_vol = 4150,
  		.termination_curr = 100,
ea4024017   Marcus Cooper   ab8500_bm: Rechar...
319
  		.recharge_cap = 95,
43dc4470e   Lee Jones   ab8500_btemp: Fix...
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
  		.normal_cur_lvl = 700,
  		.normal_vol_lvl = 4200,
  		.maint_a_cur_lvl = 600,
  		.maint_a_vol_lvl = 4150,
  		.maint_a_chg_timer_h = 60,
  		.maint_b_cur_lvl = 600,
  		.maint_b_vol_lvl = 4100,
  		.maint_b_chg_timer_h = 200,
  		.low_high_cur_lvl = 300,
  		.low_high_vol_lvl = 4000,
  		.n_temp_tbl_elements = ARRAY_SIZE(temp_tbl),
  		.r_to_t_tbl = temp_tbl,
  		.n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl),
  		.v_to_cap_tbl = cap_tbl,
  		.n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
  		.batres_tbl = temp_to_batres_tbl_thermistor,
  	},
  	{
  		.name = POWER_SUPPLY_TECHNOLOGY_LION,
  		.resis_high = 30000,
  		.resis_low = 10000,
  		.battery_resistance = 300,
  		.charge_full_design = 950,
  		.nominal_voltage = 3700,
  		.termination_vol = 4150,
  		.termination_curr = 100,
ea4024017   Marcus Cooper   ab8500_bm: Rechar...
346
  		.recharge_cap = 95,
43dc4470e   Lee Jones   ab8500_btemp: Fix...
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
  		.normal_cur_lvl = 700,
  		.normal_vol_lvl = 4200,
  		.maint_a_cur_lvl = 600,
  		.maint_a_vol_lvl = 4150,
  		.maint_a_chg_timer_h = 60,
  		.maint_b_cur_lvl = 600,
  		.maint_b_vol_lvl = 4100,
  		.maint_b_chg_timer_h = 200,
  		.low_high_cur_lvl = 300,
  		.low_high_vol_lvl = 4000,
  		.n_temp_tbl_elements = ARRAY_SIZE(temp_tbl),
  		.r_to_t_tbl = temp_tbl,
  		.n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl),
  		.v_to_cap_tbl = cap_tbl,
  		.n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
  		.batres_tbl = temp_to_batres_tbl_thermistor,
  	},
  	{
  		.name = POWER_SUPPLY_TECHNOLOGY_LION,
  		.resis_high = 95000,
  		.resis_low = 76001,
  		.battery_resistance = 300,
  		.charge_full_design = 950,
  		.nominal_voltage = 3700,
  		.termination_vol = 4150,
  		.termination_curr = 100,
ea4024017   Marcus Cooper   ab8500_bm: Rechar...
373
  		.recharge_cap = 95,
43dc4470e   Lee Jones   ab8500_btemp: Fix...
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
  		.normal_cur_lvl = 700,
  		.normal_vol_lvl = 4200,
  		.maint_a_cur_lvl = 600,
  		.maint_a_vol_lvl = 4150,
  		.maint_a_chg_timer_h = 60,
  		.maint_b_cur_lvl = 600,
  		.maint_b_vol_lvl = 4100,
  		.maint_b_chg_timer_h = 200,
  		.low_high_cur_lvl = 300,
  		.low_high_vol_lvl = 4000,
  		.n_temp_tbl_elements = ARRAY_SIZE(temp_tbl),
  		.r_to_t_tbl = temp_tbl,
  		.n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl),
  		.v_to_cap_tbl = cap_tbl,
  		.n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
  		.batres_tbl = temp_to_batres_tbl_thermistor,
  	},
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
  };
  
  static const struct abx500_bm_capacity_levels cap_levels = {
  	.critical	= 2,
  	.low		= 10,
  	.normal		= 70,
  	.high		= 95,
  	.full		= 100,
  };
  
  static const struct abx500_fg_parameters fg = {
  	.recovery_sleep_timer = 10,
  	.recovery_total_time = 100,
  	.init_timer = 1,
  	.init_discard_time = 5,
  	.init_total_time = 40,
  	.high_curr_time = 60,
  	.accu_charging = 30,
  	.accu_high_curr = 30,
  	.high_curr_threshold = 50,
  	.lowbat_threshold = 3100,
  	.battok_falling_th_sel0 = 2860,
  	.battok_raising_th_sel1 = 2860,
ea4024017   Marcus Cooper   ab8500_bm: Rechar...
414
  	.maint_thres = 95,
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
415
  	.user_cap_limit = 15,
93ff722e8   Lee Jones   ab8500-fg: Add po...
416
417
418
419
420
  	.pcut_enable = 1,
  	.pcut_max_time = 127,
  	.pcut_flag_time = 112,
  	.pcut_max_restart = 15,
  	.pcut_debounce_time = 2,
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
421
  };
861a30da5   Lee Jones   ab8500-bm: Add su...
422
  static const struct abx500_maxim_parameters ab8500_maxi_params = {
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
423
424
425
426
427
  	.ena_maxi = true,
  	.chg_curr = 910,
  	.wait_cycles = 10,
  	.charger_curr_step = 100,
  };
861a30da5   Lee Jones   ab8500-bm: Add su...
428
429
430
431
432
433
  static const struct abx500_maxim_parameters abx540_maxi_params = {
          .ena_maxi = true,
          .chg_curr = 3000,
          .wait_cycles = 10,
          .charger_curr_step = 200,
  };
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
434
435
436
437
438
439
  static const struct abx500_bm_charger_parameters chg = {
  	.usb_volt_max		= 5500,
  	.usb_curr_max		= 1500,
  	.ac_volt_max		= 7500,
  	.ac_curr_max		= 1500,
  };
861a30da5   Lee Jones   ab8500-bm: Add su...
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
  /*
   * This array maps the raw hex value to charger output current used by the
   * AB8500 values
   */
  static int ab8500_charge_output_curr_map[] = {
          100,    200,    300,    400,    500,    600,    700,    800,
          900,    1000,   1100,   1200,   1300,   1400,   1500,   1500,
  };
  
  static int ab8540_charge_output_curr_map[] = {
          0,      0,      0,      75,     100,    125,    150,    175,
          200,    225,    250,    275,    300,    325,    350,    375,
          400,    425,    450,    475,    500,    525,    550,    575,
          600,    625,    650,    675,    700,    725,    750,    775,
          800,    825,    850,    875,    900,    925,    950,    975,
          1000,   1025,   1050,   1075,   1100,   1125,   1150,   1175,
          1200,   1225,   1250,   1275,   1300,   1325,   1350,   1375,
          1400,   1425,   1450,   1500,   1600,   1700,   1900,   2000,
  };
  
  /*
   * This array maps the raw hex value to charger input current used by the
   * AB8500 values
   */
  static int ab8500_charge_input_curr_map[] = {
          50,     98,     193,    290,    380,    450,    500,    600,
          700,    800,    900,    1000,   1100,   1300,   1400,   1500,
  };
  
  static int ab8540_charge_input_curr_map[] = {
          25,     50,     75,     100,    125,    150,    175,    200,
          225,    250,    275,    300,    325,    350,    375,    400,
          425,    450,    475,    500,    525,    550,    575,    600,
          625,    650,    675,    700,    725,    750,    775,    800,
          825,    850,    875,    900,    925,    950,    975,    1000,
          1025,   1050,   1075,   1100,   1125,   1150,   1175,   1200,
          1225,   1250,   1275,   1300,   1325,   1350,   1375,   1400,
          1425,   1450,   1475,   1500,   1500,   1500,   1500,   1500,
  };
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
479
  struct abx500_bm_data ab8500_bm_data = {
43dc4470e   Lee Jones   ab8500_btemp: Fix...
480
481
482
483
484
485
486
487
488
489
490
  	.temp_under             = 3,
  	.temp_low               = 8,
  	.temp_high              = 43,
  	.temp_over              = 48,
  	.main_safety_tmr_h      = 4,
  	.temp_interval_chg      = 20,
  	.temp_interval_nochg    = 120,
  	.usb_safety_tmr_h       = 4,
  	.bkup_bat_v             = BUP_VCH_SEL_2P6V,
  	.bkup_bat_i             = BUP_ICH_SEL_150UA,
  	.no_maintenance         = false,
ea4024017   Marcus Cooper   ab8500_bm: Rechar...
491
  	.capacity_scaling       = false,
43dc4470e   Lee Jones   ab8500_btemp: Fix...
492
493
494
495
496
497
  	.adc_therm              = ABx500_ADC_THERM_BATCTRL,
  	.chg_unknown_bat        = false,
  	.enable_overshoot       = false,
  	.fg_res                 = 100,
  	.cap_levels             = &cap_levels,
  	.bat_type               = bat_type_thermistor,
861a30da5   Lee Jones   ab8500-bm: Add su...
498
  	.n_btypes               = ARRAY_SIZE(bat_type_thermistor),
43dc4470e   Lee Jones   ab8500_btemp: Fix...
499
500
501
502
503
  	.batt_id                = 0,
  	.interval_charging      = 5,
  	.interval_not_charging  = 120,
  	.temp_hysteresis        = 3,
  	.gnd_lift_resistance    = 34,
861a30da5   Lee Jones   ab8500-bm: Add su...
504
505
506
  	.chg_output_curr        = ab8500_charge_output_curr_map,
  	.n_chg_out_curr         = ARRAY_SIZE(ab8500_charge_output_curr_map),
  	.maxi                   = &ab8500_maxi_params,
43dc4470e   Lee Jones   ab8500_btemp: Fix...
507
508
  	.chg_params             = &chg,
  	.fg_params              = &fg,
861a30da5   Lee Jones   ab8500-bm: Add su...
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
          .chg_input_curr         = ab8500_charge_input_curr_map,
          .n_chg_in_curr          = ARRAY_SIZE(ab8500_charge_input_curr_map),
  };
  
  struct abx500_bm_data ab8540_bm_data = {
          .temp_under             = 3,
          .temp_low               = 8,
          .temp_high              = 43,
          .temp_over              = 48,
          .main_safety_tmr_h      = 4,
          .temp_interval_chg      = 20,
          .temp_interval_nochg    = 120,
          .usb_safety_tmr_h       = 4,
          .bkup_bat_v             = BUP_VCH_SEL_2P6V,
          .bkup_bat_i             = BUP_ICH_SEL_150UA,
          .no_maintenance         = false,
          .capacity_scaling       = false,
          .adc_therm              = ABx500_ADC_THERM_BATCTRL,
          .chg_unknown_bat        = false,
          .enable_overshoot       = false,
          .fg_res                 = 100,
          .cap_levels             = &cap_levels,
          .bat_type               = bat_type_thermistor,
          .n_btypes               = ARRAY_SIZE(bat_type_thermistor),
          .batt_id                = 0,
          .interval_charging      = 5,
          .interval_not_charging  = 120,
          .temp_hysteresis        = 3,
          .gnd_lift_resistance    = 0,
          .maxi                   = &abx540_maxi_params,
          .chg_params             = &chg,
          .fg_params              = &fg,
          .chg_output_curr        = ab8540_charge_output_curr_map,
          .n_chg_out_curr         = ARRAY_SIZE(ab8540_charge_output_curr_map),
          .chg_input_curr         = ab8540_charge_input_curr_map,
          .n_chg_in_curr          = ARRAY_SIZE(ab8540_charge_input_curr_map),
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
545
  };
5a1203914   Linus Torvalds   Merge tag 'for-v3...
546
547
548
  int ab8500_bm_of_probe(struct device *dev,
  		       struct device_node *np,
  		       struct abx500_bm_data *bm)
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
549
  {
2c8994078   Hongbo Zhang   ab8500_{bmdata,fg...
550
  	const struct batres_vs_temp *tmp_batres_tbl;
215cf5c93   Lee Jones   ab8500_bm: Make t...
551
  	struct device_node *battery_node;
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
552
  	const char *btech;
8e3a71e56   Lee Jones   ab8500-bmdata: Re...
553
  	int i;
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
554
555
  
  	/* get phandle to 'battery-info' node */
215cf5c93   Lee Jones   ab8500_bm: Make t...
556
557
  	battery_node = of_parse_phandle(np, "battery", 0);
  	if (!battery_node) {
8e3a71e56   Lee Jones   ab8500-bmdata: Re...
558
559
  		dev_err(dev, "battery node or reference missing
  ");
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
560
561
  		return -EINVAL;
  	}
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
562

215cf5c93   Lee Jones   ab8500_bm: Make t...
563
  	btech = of_get_property(battery_node, "stericsson,battery-type", NULL);
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
564
565
566
  	if (!btech) {
  		dev_warn(dev, "missing property battery-name/type
  ");
f5695a398   Rajanikanth H.V   ab8500: remove ex...
567
  		return -EINVAL;
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
568
  	}
f5695a398   Rajanikanth H.V   ab8500: remove ex...
569
  	if (strncmp(btech, "LION", 4) == 0) {
23a04f9f4   Lee Jones   ab8500_bm: Always...
570
571
572
573
  		bm->no_maintenance  = true;
  		bm->chg_unknown_bat = true;
  		bm->bat_type[BATTERY_UNKNOWN].charge_full_design = 2600;
  		bm->bat_type[BATTERY_UNKNOWN].termination_vol    = 4150;
ea4024017   Marcus Cooper   ab8500_bm: Rechar...
574
  		bm->bat_type[BATTERY_UNKNOWN].recharge_cap       = 95;
23a04f9f4   Lee Jones   ab8500_bm: Always...
575
576
  		bm->bat_type[BATTERY_UNKNOWN].normal_cur_lvl     = 520;
  		bm->bat_type[BATTERY_UNKNOWN].normal_vol_lvl     = 4200;
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
577
  	}
43dc4470e   Lee Jones   ab8500_btemp: Fix...
578

215cf5c93   Lee Jones   ab8500_bm: Make t...
579
  	if (of_property_read_bool(battery_node, "thermistor-on-batctrl")) {
8e3a71e56   Lee Jones   ab8500-bmdata: Re...
580
581
582
583
584
  		if (strncmp(btech, "LION", 4) == 0)
  			tmp_batres_tbl = temp_to_batres_tbl_9100;
  		else
  			tmp_batres_tbl = temp_to_batres_tbl_thermistor;
  	} else {
23a04f9f4   Lee Jones   ab8500_bm: Always...
585
586
587
588
  		bm->n_btypes   = 4;
  		bm->bat_type   = bat_type_ext_thermistor;
  		bm->adc_therm  = ABx500_ADC_THERM_BATTEMP;
  		tmp_batres_tbl = temp_to_batres_tbl_ext_thermistor;
e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
589
  	}
8e3a71e56   Lee Jones   ab8500-bmdata: Re...
590
591
  
  	/* select the battery resolution table */
23a04f9f4   Lee Jones   ab8500_bm: Always...
592
593
  	for (i = 0; i < bm->n_btypes; ++i)
  		bm->bat_type[i].batres_tbl = tmp_batres_tbl;
8e3a71e56   Lee Jones   ab8500-bmdata: Re...
594

215cf5c93   Lee Jones   ab8500_bm: Make t...
595
  	of_node_put(battery_node);
43dc4470e   Lee Jones   ab8500_btemp: Fix...
596

e0f1abeba   Rajanikanth H.V   ab8500: Add devic...
597
598
  	return 0;
  }