Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0-only */
2
3#ifndef _AB8500_CHARGER_H_
4#define _AB8500_CHARGER_H_
5
6#include <linux/kernel.h>
7
8/*
9 * System control 2 register offsets.
10 * bank = 0x02
11 */
12#define AB8500_MAIN_WDOG_CTRL_REG 0x01
13#define AB8500_LOW_BAT_REG 0x03
14#define AB8500_BATT_OK_REG 0x04
15/*
16 * USB/ULPI register offsets
17 * Bank : 0x5
18 */
19#define AB8500_USB_LINE_STAT_REG 0x80
20#define AB8500_USB_LINE_CTRL2_REG 0x82
21#define AB8500_USB_LINK1_STAT_REG 0x94
22
23/*
24 * Charger / status register offfsets
25 * Bank : 0x0B
26 */
27#define AB8500_CH_STATUS1_REG 0x00
28#define AB8500_CH_STATUS2_REG 0x01
29#define AB8500_CH_USBCH_STAT1_REG 0x02
30#define AB8500_CH_USBCH_STAT2_REG 0x03
31#define AB8540_CH_USBCH_STAT3_REG 0x04
32#define AB8500_CH_STAT_REG 0x05
33
34/*
35 * Charger / control register offfsets
36 * Bank : 0x0B
37 */
38#define AB8500_CH_VOLT_LVL_REG 0x40
39#define AB8500_CH_VOLT_LVL_MAX_REG 0x41 /*Only in Cut2.0*/
40#define AB8500_CH_OPT_CRNTLVL_REG 0x42
41#define AB8500_CH_OPT_CRNTLVL_MAX_REG 0x43 /*Only in Cut2.0*/
42#define AB8500_CH_WD_TIMER_REG 0x50
43#define AB8500_CHARG_WD_CTRL 0x51
44#define AB8500_BTEMP_HIGH_TH 0x52
45#define AB8500_LED_INDICATOR_PWM_CTRL 0x53
46#define AB8500_LED_INDICATOR_PWM_DUTY 0x54
47#define AB8500_BATT_OVV 0x55
48#define AB8500_CHARGER_CTRL 0x56
49#define AB8500_BAT_CTRL_CURRENT_SOURCE 0x60 /*Only in Cut2.0*/
50
51/*
52 * Charger / main control register offsets
53 * Bank : 0x0B
54 */
55#define AB8500_MCH_CTRL1 0x80
56#define AB8500_MCH_CTRL2 0x81
57#define AB8500_MCH_IPT_CURLVL_REG 0x82
58#define AB8500_CH_WD_REG 0x83
59
60/*
61 * Charger / USB control register offsets
62 * Bank : 0x0B
63 */
64#define AB8500_USBCH_CTRL1_REG 0xC0
65#define AB8500_USBCH_CTRL2_REG 0xC1
66#define AB8500_USBCH_IPT_CRNTLVL_REG 0xC2
67#define AB8540_USB_PP_MODE_REG 0xC5
68#define AB8540_USB_PP_CHR_REG 0xC6
69
70/*
71 * Gas Gauge register offsets
72 * Bank : 0x0C
73 */
74#define AB8500_GASG_CC_CTRL_REG 0x00
75#define AB8500_GASG_CC_ACCU1_REG 0x01
76#define AB8500_GASG_CC_ACCU2_REG 0x02
77#define AB8500_GASG_CC_ACCU3_REG 0x03
78#define AB8500_GASG_CC_ACCU4_REG 0x04
79#define AB8500_GASG_CC_SMPL_CNTRL_REG 0x05
80#define AB8500_GASG_CC_SMPL_CNTRH_REG 0x06
81#define AB8500_GASG_CC_SMPL_CNVL_REG 0x07
82#define AB8500_GASG_CC_SMPL_CNVH_REG 0x08
83#define AB8500_GASG_CC_CNTR_AVGOFF_REG 0x09
84#define AB8500_GASG_CC_OFFSET_REG 0x0A
85#define AB8500_GASG_CC_NCOV_ACCU 0x10
86#define AB8500_GASG_CC_NCOV_ACCU_CTRL 0x11
87#define AB8500_GASG_CC_NCOV_ACCU_LOW 0x12
88#define AB8500_GASG_CC_NCOV_ACCU_MED 0x13
89#define AB8500_GASG_CC_NCOV_ACCU_HIGH 0x14
90
91/*
92 * Interrupt register offsets
93 * Bank : 0x0E
94 */
95#define AB8500_IT_SOURCE2_REG 0x01
96#define AB8500_IT_SOURCE21_REG 0x14
97
98/*
99 * RTC register offsets
100 * Bank: 0x0F
101 */
102#define AB8500_RTC_BACKUP_CHG_REG 0x0C
103#define AB8500_RTC_CC_CONF_REG 0x01
104#define AB8500_RTC_CTRL_REG 0x0B
105#define AB8500_RTC_CTRL1_REG 0x11
106
107/*
108 * OTP register offsets
109 * Bank : 0x15
110 */
111#define AB8500_OTP_CONF_15 0x0E
112
113/* GPADC constants from AB8500 spec, UM0836 */
114#define ADC_RESOLUTION 1024
115#define ADC_CH_MAIN_MIN 0
116#define ADC_CH_MAIN_MAX 20030
117#define ADC_CH_VBUS_MIN 0
118#define ADC_CH_VBUS_MAX 20030
119#define ADC_CH_VBAT_MIN 2300
120#define ADC_CH_VBAT_MAX 4800
121#define ADC_CH_BKBAT_MIN 0
122#define ADC_CH_BKBAT_MAX 3200
123
124/* Main charge i/p current */
125#define MAIN_CH_IP_CUR_0P9A 0x80
126#define MAIN_CH_IP_CUR_1P0A 0x90
127#define MAIN_CH_IP_CUR_1P1A 0xA0
128#define MAIN_CH_IP_CUR_1P2A 0xB0
129#define MAIN_CH_IP_CUR_1P3A 0xC0
130#define MAIN_CH_IP_CUR_1P4A 0xD0
131#define MAIN_CH_IP_CUR_1P5A 0xE0
132
133/* ChVoltLevel */
134#define CH_VOL_LVL_3P5 0x00
135#define CH_VOL_LVL_4P0 0x14
136#define CH_VOL_LVL_4P05 0x16
137#define CH_VOL_LVL_4P1 0x1B
138#define CH_VOL_LVL_4P15 0x20
139#define CH_VOL_LVL_4P2 0x25
140#define CH_VOL_LVL_4P6 0x4D
141
142/* ChOutputCurrentLevel */
143#define CH_OP_CUR_LVL_0P1 0x00
144#define CH_OP_CUR_LVL_0P2 0x01
145#define CH_OP_CUR_LVL_0P3 0x02
146#define CH_OP_CUR_LVL_0P4 0x03
147#define CH_OP_CUR_LVL_0P5 0x04
148#define CH_OP_CUR_LVL_0P6 0x05
149#define CH_OP_CUR_LVL_0P7 0x06
150#define CH_OP_CUR_LVL_0P8 0x07
151#define CH_OP_CUR_LVL_0P9 0x08
152#define CH_OP_CUR_LVL_1P4 0x0D
153#define CH_OP_CUR_LVL_1P5 0x0E
154#define CH_OP_CUR_LVL_1P6 0x0F
155#define CH_OP_CUR_LVL_2P 0x3F
156
157/* BTEMP High thermal limits */
158#define BTEMP_HIGH_TH_57_0 0x00
159#define BTEMP_HIGH_TH_52 0x01
160#define BTEMP_HIGH_TH_57_1 0x02
161#define BTEMP_HIGH_TH_62 0x03
162
163/* current is mA */
164#define USB_0P1A 100
165#define USB_0P2A 200
166#define USB_0P3A 300
167#define USB_0P4A 400
168#define USB_0P5A 500
169
170#define LOW_BAT_3P1V 0x20
171#define LOW_BAT_2P3V 0x00
172#define LOW_BAT_RESET 0x01
173#define LOW_BAT_ENABLE 0x01
174
175/* Backup battery constants */
176#define BUP_ICH_SEL_50UA 0x00
177#define BUP_ICH_SEL_150UA 0x04
178#define BUP_ICH_SEL_300UA 0x08
179#define BUP_ICH_SEL_700UA 0x0C
180
181enum bup_vch_sel {
182 BUP_VCH_SEL_2P5V,
183 BUP_VCH_SEL_2P6V,
184 BUP_VCH_SEL_2P8V,
185 BUP_VCH_SEL_3P1V,
186 /*
187 * Note that the following 5 values 2.7v, 2.9v, 3.0v, 3.2v, 3.3v
188 * are only available on ab8540. You can't choose these 5
189 * voltage on ab8500/ab8505/ab9540.
190 */
191 BUP_VCH_SEL_2P7V,
192 BUP_VCH_SEL_2P9V,
193 BUP_VCH_SEL_3P0V,
194 BUP_VCH_SEL_3P2V,
195 BUP_VCH_SEL_3P3V,
196};
197
198#define BUP_VCH_RANGE 0x02
199#define VBUP33_VRTCN 0x01
200
201/* Battery OVV constants */
202#define BATT_OVV_ENA 0x02
203#define BATT_OVV_TH_3P7 0x00
204#define BATT_OVV_TH_4P75 0x01
205
206/* A value to indicate over voltage */
207#define BATT_OVV_VALUE 4750
208
209/* VBUS OVV constants */
210#define VBUS_OVV_SELECT_MASK 0x78
211#define VBUS_OVV_SELECT_5P6V 0x00
212#define VBUS_OVV_SELECT_5P7V 0x08
213#define VBUS_OVV_SELECT_5P8V 0x10
214#define VBUS_OVV_SELECT_5P9V 0x18
215#define VBUS_OVV_SELECT_6P0V 0x20
216#define VBUS_OVV_SELECT_6P1V 0x28
217#define VBUS_OVV_SELECT_6P2V 0x30
218#define VBUS_OVV_SELECT_6P3V 0x38
219
220#define VBUS_AUTO_IN_CURR_LIM_ENA 0x04
221
222/* Fuel Gauge constants */
223#define RESET_ACCU 0x02
224#define READ_REQ 0x01
225#define CC_DEEP_SLEEP_ENA 0x02
226#define CC_PWR_UP_ENA 0x01
227#define CC_SAMPLES_40 0x28
228#define RD_NCONV_ACCU_REQ 0x01
229#define CC_CALIB 0x08
230#define CC_INTAVGOFFSET_ENA 0x10
231#define CC_MUXOFFSET 0x80
232#define CC_INT_CAL_N_AVG_MASK 0x60
233#define CC_INT_CAL_SAMPLES_16 0x40
234#define CC_INT_CAL_SAMPLES_8 0x20
235#define CC_INT_CAL_SAMPLES_4 0x00
236
237/* RTC constants */
238#define RTC_BUP_CH_ENA 0x10
239
240/* BatCtrl Current Source Constants */
241#define BAT_CTRL_7U_ENA 0x01
242#define BAT_CTRL_20U_ENA 0x02
243#define BAT_CTRL_18U_ENA 0x01
244#define BAT_CTRL_16U_ENA 0x02
245#define BAT_CTRL_CMP_ENA 0x04
246#define FORCE_BAT_CTRL_CMP_HIGH 0x08
247#define BAT_CTRL_PULL_UP_ENA 0x10
248
249/* Battery type */
250#define BATTERY_UNKNOWN 00
251
252/* Registers for pcut feature in ab8505 and ab9540 */
253#define AB8505_RTC_PCUT_CTL_STATUS_REG 0x12
254#define AB8505_RTC_PCUT_TIME_REG 0x13
255#define AB8505_RTC_PCUT_MAX_TIME_REG 0x14
256#define AB8505_RTC_PCUT_FLAG_TIME_REG 0x15
257#define AB8505_RTC_PCUT_RESTART_REG 0x16
258#define AB8505_RTC_PCUT_DEBOUNCE_REG 0x17
259
260/* USB Power Path constants for ab8540 */
261#define BUS_VSYS_VOL_SELECT_MASK 0x06
262#define BUS_VSYS_VOL_SELECT_3P6V 0x00
263#define BUS_VSYS_VOL_SELECT_3P325V 0x02
264#define BUS_VSYS_VOL_SELECT_3P9V 0x04
265#define BUS_VSYS_VOL_SELECT_4P3V 0x06
266#define BUS_POWER_PATH_MODE_ENA 0x01
267#define BUS_PP_PRECHG_CURRENT_MASK 0x0E
268#define BUS_POWER_PATH_PRECHG_ENA 0x01
269
270/*
271 * ADC for the battery thermistor.
272 * When using the ABx500_ADC_THERM_BATCTRL the battery ID resistor is combined
273 * with a NTC resistor to both identify the battery and to measure its
274 * temperature. Different phone manufactures uses different techniques to both
275 * identify the battery and to read its temperature.
276 */
277enum abx500_adc_therm {
278 ABx500_ADC_THERM_BATCTRL,
279 ABx500_ADC_THERM_BATTEMP,
280};
281
282/**
283 * struct abx500_res_to_temp - defines one point in a temp to res curve. To
284 * be used in battery packs that combines the identification resistor with a
285 * NTC resistor.
286 * @temp: battery pack temperature in Celsius
287 * @resist: NTC resistor net total resistance
288 */
289struct abx500_res_to_temp {
290 int temp;
291 int resist;
292};
293
294/**
295 * struct abx500_v_to_cap - Table for translating voltage to capacity
296 * @voltage: Voltage in mV
297 * @capacity: Capacity in percent
298 */
299struct abx500_v_to_cap {
300 int voltage;
301 int capacity;
302};
303
304/* Forward declaration */
305struct abx500_fg;
306
307/**
308 * struct abx500_fg_parameters - Fuel gauge algorithm parameters, in seconds
309 * if not specified
310 * @recovery_sleep_timer: Time between measurements while recovering
311 * @recovery_total_time: Total recovery time
312 * @init_timer: Measurement interval during startup
313 * @init_discard_time: Time we discard voltage measurement at startup
314 * @init_total_time: Total init time during startup
315 * @high_curr_time: Time current has to be high to go to recovery
316 * @accu_charging: FG accumulation time while charging
317 * @accu_high_curr: FG accumulation time in high current mode
318 * @high_curr_threshold: High current threshold, in mA
319 * @lowbat_threshold: Low battery threshold, in mV
320 * @overbat_threshold: Over battery threshold, in mV
321 * @battok_falling_th_sel0 Threshold in mV for battOk signal sel0
322 * Resolution in 50 mV step.
323 * @battok_raising_th_sel1 Threshold in mV for battOk signal sel1
324 * Resolution in 50 mV step.
325 * @user_cap_limit Capacity reported from user must be within this
326 * limit to be considered as sane, in percentage
327 * points.
328 * @maint_thres This is the threshold where we stop reporting
329 * battery full while in maintenance, in per cent
330 * @pcut_enable: Enable power cut feature in ab8505
331 * @pcut_max_time: Max time threshold
332 * @pcut_flag_time: Flagtime threshold
333 * @pcut_max_restart: Max number of restarts
334 * @pcut_debounce_time: Sets battery debounce time
335 */
336struct abx500_fg_parameters {
337 int recovery_sleep_timer;
338 int recovery_total_time;
339 int init_timer;
340 int init_discard_time;
341 int init_total_time;
342 int high_curr_time;
343 int accu_charging;
344 int accu_high_curr;
345 int high_curr_threshold;
346 int lowbat_threshold;
347 int overbat_threshold;
348 int battok_falling_th_sel0;
349 int battok_raising_th_sel1;
350 int user_cap_limit;
351 int maint_thres;
352 bool pcut_enable;
353 u8 pcut_max_time;
354 u8 pcut_flag_time;
355 u8 pcut_max_restart;
356 u8 pcut_debounce_time;
357};
358
359/**
360 * struct abx500_charger_maximization - struct used by the board config.
361 * @use_maxi: Enable maximization for this battery type
362 * @maxi_chg_curr: Maximum charger current allowed
363 * @maxi_wait_cycles: cycles to wait before setting charger current
364 * @charger_curr_step delta between two charger current settings (mA)
365 */
366struct abx500_maxim_parameters {
367 bool ena_maxi;
368 int chg_curr;
369 int wait_cycles;
370 int charger_curr_step;
371};
372
373/**
374 * struct abx500_battery_type - different batteries supported
375 * @name: battery technology
376 * @resis_high: battery upper resistance limit
377 * @resis_low: battery lower resistance limit
378 * @charge_full_design: Maximum battery capacity in mAh
379 * @nominal_voltage: Nominal voltage of the battery in mV
380 * @termination_vol: max voltage upto which battery can be charged
381 * @termination_curr battery charging termination current in mA
382 * @recharge_cap battery capacity limit that will trigger a new
383 * full charging cycle in the case where maintenan-
384 * -ce charging has been disabled
385 * @normal_cur_lvl: charger current in normal state in mA
386 * @normal_vol_lvl: charger voltage in normal state in mV
387 * @maint_a_cur_lvl: charger current in maintenance A state in mA
388 * @maint_a_vol_lvl: charger voltage in maintenance A state in mV
389 * @maint_a_chg_timer_h: charge time in maintenance A state
390 * @maint_b_cur_lvl: charger current in maintenance B state in mA
391 * @maint_b_vol_lvl: charger voltage in maintenance B state in mV
392 * @maint_b_chg_timer_h: charge time in maintenance B state
393 * @low_high_cur_lvl: charger current in temp low/high state in mA
394 * @low_high_vol_lvl: charger voltage in temp low/high state in mV'
395 * @battery_resistance: battery inner resistance in mOhm.
396 * @n_r_t_tbl_elements: number of elements in r_to_t_tbl
397 * @r_to_t_tbl: table containing resistance to temp points
398 * @n_v_cap_tbl_elements: number of elements in v_to_cap_tbl
399 * @v_to_cap_tbl: Voltage to capacity (in %) table
400 * @n_batres_tbl_elements number of elements in the batres_tbl
401 * @batres_tbl battery internal resistance vs temperature table
402 */
403struct abx500_battery_type {
404 int name;
405 int resis_high;
406 int resis_low;
407 int charge_full_design;
408 int nominal_voltage;
409 int termination_vol;
410 int termination_curr;
411 int recharge_cap;
412 int normal_cur_lvl;
413 int normal_vol_lvl;
414 int maint_a_cur_lvl;
415 int maint_a_vol_lvl;
416 int maint_a_chg_timer_h;
417 int maint_b_cur_lvl;
418 int maint_b_vol_lvl;
419 int maint_b_chg_timer_h;
420 int low_high_cur_lvl;
421 int low_high_vol_lvl;
422 int battery_resistance;
423 int n_temp_tbl_elements;
424 const struct abx500_res_to_temp *r_to_t_tbl;
425 int n_v_cap_tbl_elements;
426 const struct abx500_v_to_cap *v_to_cap_tbl;
427 int n_batres_tbl_elements;
428 const struct batres_vs_temp *batres_tbl;
429};
430
431/**
432 * struct abx500_bm_capacity_levels - abx500 capacity level data
433 * @critical: critical capacity level in percent
434 * @low: low capacity level in percent
435 * @normal: normal capacity level in percent
436 * @high: high capacity level in percent
437 * @full: full capacity level in percent
438 */
439struct abx500_bm_capacity_levels {
440 int critical;
441 int low;
442 int normal;
443 int high;
444 int full;
445};
446
447/**
448 * struct abx500_bm_charger_parameters - Charger specific parameters
449 * @usb_volt_max: maximum allowed USB charger voltage in mV
450 * @usb_curr_max: maximum allowed USB charger current in mA
451 * @ac_volt_max: maximum allowed AC charger voltage in mV
452 * @ac_curr_max: maximum allowed AC charger current in mA
453 */
454struct abx500_bm_charger_parameters {
455 int usb_volt_max;
456 int usb_curr_max;
457 int ac_volt_max;
458 int ac_curr_max;
459};
460
461/**
462 * struct abx500_bm_data - abx500 battery management data
463 * @temp_under under this temp, charging is stopped
464 * @temp_low between this temp and temp_under charging is reduced
465 * @temp_high between this temp and temp_over charging is reduced
466 * @temp_over over this temp, charging is stopped
467 * @temp_now present battery temperature
468 * @temp_interval_chg temperature measurement interval in s when charging
469 * @temp_interval_nochg temperature measurement interval in s when not charging
470 * @main_safety_tmr_h safety timer for main charger
471 * @usb_safety_tmr_h safety timer for usb charger
472 * @bkup_bat_v voltage which we charge the backup battery with
473 * @bkup_bat_i current which we charge the backup battery with
474 * @no_maintenance indicates that maintenance charging is disabled
475 * @capacity_scaling indicates whether capacity scaling is to be used
476 * @abx500_adc_therm placement of thermistor, batctrl or battemp adc
477 * @chg_unknown_bat flag to enable charging of unknown batteries
478 * @enable_overshoot flag to enable VBAT overshoot control
479 * @auto_trig flag to enable auto adc trigger
480 * @fg_res resistance of FG resistor in 0.1mOhm
481 * @n_btypes number of elements in array bat_type
482 * @batt_id index of the identified battery in array bat_type
483 * @interval_charging charge alg cycle period time when charging (sec)
484 * @interval_not_charging charge alg cycle period time when not charging (sec)
485 * @temp_hysteresis temperature hysteresis
486 * @gnd_lift_resistance Battery ground to phone ground resistance (mOhm)
487 * @n_chg_out_curr number of elements in array chg_output_curr
488 * @n_chg_in_curr number of elements in array chg_input_curr
489 * @chg_output_curr charger output current level map
490 * @chg_input_curr charger input current level map
491 * @maxi maximization parameters
492 * @cap_levels capacity in percent for the different capacity levels
493 * @bat_type table of supported battery types
494 * @chg_params charger parameters
495 * @fg_params fuel gauge parameters
496 */
497struct abx500_bm_data {
498 int temp_under;
499 int temp_low;
500 int temp_high;
501 int temp_over;
502 int temp_now;
503 int temp_interval_chg;
504 int temp_interval_nochg;
505 int main_safety_tmr_h;
506 int usb_safety_tmr_h;
507 int bkup_bat_v;
508 int bkup_bat_i;
509 bool autopower_cfg;
510 bool ac_enabled;
511 bool usb_enabled;
512 bool no_maintenance;
513 bool capacity_scaling;
514 bool chg_unknown_bat;
515 bool enable_overshoot;
516 bool auto_trig;
517 enum abx500_adc_therm adc_therm;
518 int fg_res;
519 int n_btypes;
520 int batt_id;
521 int interval_charging;
522 int interval_not_charging;
523 int temp_hysteresis;
524 int gnd_lift_resistance;
525 int n_chg_out_curr;
526 int n_chg_in_curr;
527 int *chg_output_curr;
528 int *chg_input_curr;
529 const struct abx500_maxim_parameters *maxi;
530 const struct abx500_bm_capacity_levels *cap_levels;
531 struct abx500_battery_type *bat_type;
532 const struct abx500_bm_charger_parameters *chg_params;
533 const struct abx500_fg_parameters *fg_params;
534};
535
536enum {
537 NTC_EXTERNAL = 0,
538 NTC_INTERNAL,
539};
540
541/**
542 * struct res_to_temp - defines one point in a temp to res curve. To
543 * be used in battery packs that combines the identification resistor with a
544 * NTC resistor.
545 * @temp: battery pack temperature in Celsius
546 * @resist: NTC resistor net total resistance
547 */
548struct res_to_temp {
549 int temp;
550 int resist;
551};
552
553/**
554 * struct batres_vs_temp - defines one point in a temp vs battery internal
555 * resistance curve.
556 * @temp: battery pack temperature in Celsius
557 * @resist: battery internal reistance in mOhm
558 */
559struct batres_vs_temp {
560 int temp;
561 int resist;
562};
563
564/* Forward declaration */
565struct ab8500_fg;
566
567/**
568 * struct ab8500_fg_parameters - Fuel gauge algorithm parameters, in seconds
569 * if not specified
570 * @recovery_sleep_timer: Time between measurements while recovering
571 * @recovery_total_time: Total recovery time
572 * @init_timer: Measurement interval during startup
573 * @init_discard_time: Time we discard voltage measurement at startup
574 * @init_total_time: Total init time during startup
575 * @high_curr_time: Time current has to be high to go to recovery
576 * @accu_charging: FG accumulation time while charging
577 * @accu_high_curr: FG accumulation time in high current mode
578 * @high_curr_threshold: High current threshold, in mA
579 * @lowbat_threshold: Low battery threshold, in mV
580 * @battok_falling_th_sel0 Threshold in mV for battOk signal sel0
581 * Resolution in 50 mV step.
582 * @battok_raising_th_sel1 Threshold in mV for battOk signal sel1
583 * Resolution in 50 mV step.
584 * @user_cap_limit Capacity reported from user must be within this
585 * limit to be considered as sane, in percentage
586 * points.
587 * @maint_thres This is the threshold where we stop reporting
588 * battery full while in maintenance, in per cent
589 * @pcut_enable: Enable power cut feature in ab8505
590 * @pcut_max_time: Max time threshold
591 * @pcut_flag_time: Flagtime threshold
592 * @pcut_max_restart: Max number of restarts
593 * @pcut_debunce_time: Sets battery debounce time
594 */
595struct ab8500_fg_parameters {
596 int recovery_sleep_timer;
597 int recovery_total_time;
598 int init_timer;
599 int init_discard_time;
600 int init_total_time;
601 int high_curr_time;
602 int accu_charging;
603 int accu_high_curr;
604 int high_curr_threshold;
605 int lowbat_threshold;
606 int battok_falling_th_sel0;
607 int battok_raising_th_sel1;
608 int user_cap_limit;
609 int maint_thres;
610 bool pcut_enable;
611 u8 pcut_max_time;
612 u8 pcut_flag_time;
613 u8 pcut_max_restart;
614 u8 pcut_debunce_time;
615};
616
617/**
618 * struct ab8500_charger_maximization - struct used by the board config.
619 * @use_maxi: Enable maximization for this battery type
620 * @maxi_chg_curr: Maximum charger current allowed
621 * @maxi_wait_cycles: cycles to wait before setting charger current
622 * @charger_curr_step delta between two charger current settings (mA)
623 */
624struct ab8500_maxim_parameters {
625 bool ena_maxi;
626 int chg_curr;
627 int wait_cycles;
628 int charger_curr_step;
629};
630
631/**
632 * struct ab8500_bm_capacity_levels - ab8500 capacity level data
633 * @critical: critical capacity level in percent
634 * @low: low capacity level in percent
635 * @normal: normal capacity level in percent
636 * @high: high capacity level in percent
637 * @full: full capacity level in percent
638 */
639struct ab8500_bm_capacity_levels {
640 int critical;
641 int low;
642 int normal;
643 int high;
644 int full;
645};
646
647/**
648 * struct ab8500_bm_charger_parameters - Charger specific parameters
649 * @usb_volt_max: maximum allowed USB charger voltage in mV
650 * @usb_curr_max: maximum allowed USB charger current in mA
651 * @ac_volt_max: maximum allowed AC charger voltage in mV
652 * @ac_curr_max: maximum allowed AC charger current in mA
653 */
654struct ab8500_bm_charger_parameters {
655 int usb_volt_max;
656 int usb_curr_max;
657 int ac_volt_max;
658 int ac_curr_max;
659};
660
661/**
662 * struct ab8500_bm_data - ab8500 battery management data
663 * @temp_under under this temp, charging is stopped
664 * @temp_low between this temp and temp_under charging is reduced
665 * @temp_high between this temp and temp_over charging is reduced
666 * @temp_over over this temp, charging is stopped
667 * @temp_interval_chg temperature measurement interval in s when charging
668 * @temp_interval_nochg temperature measurement interval in s when not charging
669 * @main_safety_tmr_h safety timer for main charger
670 * @usb_safety_tmr_h safety timer for usb charger
671 * @bkup_bat_v voltage which we charge the backup battery with
672 * @bkup_bat_i current which we charge the backup battery with
673 * @no_maintenance indicates that maintenance charging is disabled
674 * @capacity_scaling indicates whether capacity scaling is to be used
675 * @adc_therm placement of thermistor, batctrl or battemp adc
676 * @chg_unknown_bat flag to enable charging of unknown batteries
677 * @enable_overshoot flag to enable VBAT overshoot control
678 * @fg_res resistance of FG resistor in 0.1mOhm
679 * @n_btypes number of elements in array bat_type
680 * @batt_id index of the identified battery in array bat_type
681 * @interval_charging charge alg cycle period time when charging (sec)
682 * @interval_not_charging charge alg cycle period time when not charging (sec)
683 * @temp_hysteresis temperature hysteresis
684 * @gnd_lift_resistance Battery ground to phone ground resistance (mOhm)
685 * @maxi: maximization parameters
686 * @cap_levels capacity in percent for the different capacity levels
687 * @bat_type table of supported battery types
688 * @chg_params charger parameters
689 * @fg_params fuel gauge parameters
690 */
691struct ab8500_bm_data {
692 int temp_under;
693 int temp_low;
694 int temp_high;
695 int temp_over;
696 int temp_interval_chg;
697 int temp_interval_nochg;
698 int main_safety_tmr_h;
699 int usb_safety_tmr_h;
700 int bkup_bat_v;
701 int bkup_bat_i;
702 bool no_maintenance;
703 bool capacity_scaling;
704 bool chg_unknown_bat;
705 bool enable_overshoot;
706 enum abx500_adc_therm adc_therm;
707 int fg_res;
708 int n_btypes;
709 int batt_id;
710 int interval_charging;
711 int interval_not_charging;
712 int temp_hysteresis;
713 int gnd_lift_resistance;
714 const struct ab8500_maxim_parameters *maxi;
715 const struct ab8500_bm_capacity_levels *cap_levels;
716 const struct ab8500_bm_charger_parameters *chg_params;
717 const struct ab8500_fg_parameters *fg_params;
718};
719
720extern struct abx500_bm_data ab8500_bm_data;
721
722void ab8500_charger_usb_state_changed(u8 bm_usb_state, u16 mA);
723struct ab8500_fg *ab8500_fg_get(void);
724int ab8500_fg_inst_curr_blocking(struct ab8500_fg *dev);
725int ab8500_fg_inst_curr_start(struct ab8500_fg *di);
726int ab8500_fg_inst_curr_finalize(struct ab8500_fg *di, int *res);
727int ab8500_fg_inst_curr_started(struct ab8500_fg *di);
728int ab8500_fg_inst_curr_done(struct ab8500_fg *di);
729int ab8500_bm_of_probe(struct device *dev,
730 struct device_node *np,
731 struct abx500_bm_data *bm);
732
733#endif /* _AB8500_CHARGER_H_ */