xref: /linux/drivers/power/supply/ab8500-bm.h (revision 417c0fc24dd4dbd60d94fa8deb36bf1176930e06)
1*417c0fc2SLinus Walleij /* SPDX-License-Identifier: GPL-2.0-only */
2*417c0fc2SLinus Walleij 
3*417c0fc2SLinus Walleij #ifndef _AB8500_CHARGER_H_
4*417c0fc2SLinus Walleij #define _AB8500_CHARGER_H_
5*417c0fc2SLinus Walleij 
6*417c0fc2SLinus Walleij #include <linux/kernel.h>
7*417c0fc2SLinus Walleij #include <linux/mfd/abx500.h>
8*417c0fc2SLinus Walleij 
9*417c0fc2SLinus Walleij /*
10*417c0fc2SLinus Walleij  * System control 2 register offsets.
11*417c0fc2SLinus Walleij  * bank = 0x02
12*417c0fc2SLinus Walleij  */
13*417c0fc2SLinus Walleij #define AB8500_MAIN_WDOG_CTRL_REG	0x01
14*417c0fc2SLinus Walleij #define AB8500_LOW_BAT_REG		0x03
15*417c0fc2SLinus Walleij #define AB8500_BATT_OK_REG		0x04
16*417c0fc2SLinus Walleij /*
17*417c0fc2SLinus Walleij  * USB/ULPI register offsets
18*417c0fc2SLinus Walleij  * Bank : 0x5
19*417c0fc2SLinus Walleij  */
20*417c0fc2SLinus Walleij #define AB8500_USB_LINE_STAT_REG	0x80
21*417c0fc2SLinus Walleij #define AB8500_USB_LINE_CTRL2_REG	0x82
22*417c0fc2SLinus Walleij #define AB8500_USB_LINK1_STAT_REG	0x94
23*417c0fc2SLinus Walleij 
24*417c0fc2SLinus Walleij /*
25*417c0fc2SLinus Walleij  * Charger / status register offfsets
26*417c0fc2SLinus Walleij  * Bank : 0x0B
27*417c0fc2SLinus Walleij  */
28*417c0fc2SLinus Walleij #define AB8500_CH_STATUS1_REG		0x00
29*417c0fc2SLinus Walleij #define AB8500_CH_STATUS2_REG		0x01
30*417c0fc2SLinus Walleij #define AB8500_CH_USBCH_STAT1_REG	0x02
31*417c0fc2SLinus Walleij #define AB8500_CH_USBCH_STAT2_REG	0x03
32*417c0fc2SLinus Walleij #define AB8540_CH_USBCH_STAT3_REG	0x04
33*417c0fc2SLinus Walleij #define AB8500_CH_STAT_REG		0x05
34*417c0fc2SLinus Walleij 
35*417c0fc2SLinus Walleij /*
36*417c0fc2SLinus Walleij  * Charger / control register offfsets
37*417c0fc2SLinus Walleij  * Bank : 0x0B
38*417c0fc2SLinus Walleij  */
39*417c0fc2SLinus Walleij #define AB8500_CH_VOLT_LVL_REG		0x40
40*417c0fc2SLinus Walleij #define AB8500_CH_VOLT_LVL_MAX_REG	0x41  /*Only in Cut2.0*/
41*417c0fc2SLinus Walleij #define AB8500_CH_OPT_CRNTLVL_REG	0x42
42*417c0fc2SLinus Walleij #define AB8500_CH_OPT_CRNTLVL_MAX_REG	0x43  /*Only in Cut2.0*/
43*417c0fc2SLinus Walleij #define AB8500_CH_WD_TIMER_REG		0x50
44*417c0fc2SLinus Walleij #define AB8500_CHARG_WD_CTRL		0x51
45*417c0fc2SLinus Walleij #define AB8500_BTEMP_HIGH_TH		0x52
46*417c0fc2SLinus Walleij #define AB8500_LED_INDICATOR_PWM_CTRL	0x53
47*417c0fc2SLinus Walleij #define AB8500_LED_INDICATOR_PWM_DUTY	0x54
48*417c0fc2SLinus Walleij #define AB8500_BATT_OVV			0x55
49*417c0fc2SLinus Walleij #define AB8500_CHARGER_CTRL		0x56
50*417c0fc2SLinus Walleij #define AB8500_BAT_CTRL_CURRENT_SOURCE	0x60  /*Only in Cut2.0*/
51*417c0fc2SLinus Walleij 
52*417c0fc2SLinus Walleij /*
53*417c0fc2SLinus Walleij  * Charger / main control register offsets
54*417c0fc2SLinus Walleij  * Bank : 0x0B
55*417c0fc2SLinus Walleij  */
56*417c0fc2SLinus Walleij #define AB8500_MCH_CTRL1		0x80
57*417c0fc2SLinus Walleij #define AB8500_MCH_CTRL2		0x81
58*417c0fc2SLinus Walleij #define AB8500_MCH_IPT_CURLVL_REG	0x82
59*417c0fc2SLinus Walleij #define AB8500_CH_WD_REG		0x83
60*417c0fc2SLinus Walleij 
61*417c0fc2SLinus Walleij /*
62*417c0fc2SLinus Walleij  * Charger / USB control register offsets
63*417c0fc2SLinus Walleij  * Bank : 0x0B
64*417c0fc2SLinus Walleij  */
65*417c0fc2SLinus Walleij #define AB8500_USBCH_CTRL1_REG		0xC0
66*417c0fc2SLinus Walleij #define AB8500_USBCH_CTRL2_REG		0xC1
67*417c0fc2SLinus Walleij #define AB8500_USBCH_IPT_CRNTLVL_REG	0xC2
68*417c0fc2SLinus Walleij #define AB8540_USB_PP_MODE_REG		0xC5
69*417c0fc2SLinus Walleij #define AB8540_USB_PP_CHR_REG		0xC6
70*417c0fc2SLinus Walleij 
71*417c0fc2SLinus Walleij /*
72*417c0fc2SLinus Walleij  * Gas Gauge register offsets
73*417c0fc2SLinus Walleij  * Bank : 0x0C
74*417c0fc2SLinus Walleij  */
75*417c0fc2SLinus Walleij #define AB8500_GASG_CC_CTRL_REG		0x00
76*417c0fc2SLinus Walleij #define AB8500_GASG_CC_ACCU1_REG	0x01
77*417c0fc2SLinus Walleij #define AB8500_GASG_CC_ACCU2_REG	0x02
78*417c0fc2SLinus Walleij #define AB8500_GASG_CC_ACCU3_REG	0x03
79*417c0fc2SLinus Walleij #define AB8500_GASG_CC_ACCU4_REG	0x04
80*417c0fc2SLinus Walleij #define AB8500_GASG_CC_SMPL_CNTRL_REG	0x05
81*417c0fc2SLinus Walleij #define AB8500_GASG_CC_SMPL_CNTRH_REG	0x06
82*417c0fc2SLinus Walleij #define AB8500_GASG_CC_SMPL_CNVL_REG	0x07
83*417c0fc2SLinus Walleij #define AB8500_GASG_CC_SMPL_CNVH_REG	0x08
84*417c0fc2SLinus Walleij #define AB8500_GASG_CC_CNTR_AVGOFF_REG	0x09
85*417c0fc2SLinus Walleij #define AB8500_GASG_CC_OFFSET_REG	0x0A
86*417c0fc2SLinus Walleij #define AB8500_GASG_CC_NCOV_ACCU	0x10
87*417c0fc2SLinus Walleij #define AB8500_GASG_CC_NCOV_ACCU_CTRL	0x11
88*417c0fc2SLinus Walleij #define AB8500_GASG_CC_NCOV_ACCU_LOW	0x12
89*417c0fc2SLinus Walleij #define AB8500_GASG_CC_NCOV_ACCU_MED	0x13
90*417c0fc2SLinus Walleij #define AB8500_GASG_CC_NCOV_ACCU_HIGH	0x14
91*417c0fc2SLinus Walleij 
92*417c0fc2SLinus Walleij /*
93*417c0fc2SLinus Walleij  * Interrupt register offsets
94*417c0fc2SLinus Walleij  * Bank : 0x0E
95*417c0fc2SLinus Walleij  */
96*417c0fc2SLinus Walleij #define AB8500_IT_SOURCE2_REG		0x01
97*417c0fc2SLinus Walleij #define AB8500_IT_SOURCE21_REG		0x14
98*417c0fc2SLinus Walleij 
99*417c0fc2SLinus Walleij /*
100*417c0fc2SLinus Walleij  * RTC register offsets
101*417c0fc2SLinus Walleij  * Bank: 0x0F
102*417c0fc2SLinus Walleij  */
103*417c0fc2SLinus Walleij #define AB8500_RTC_BACKUP_CHG_REG	0x0C
104*417c0fc2SLinus Walleij #define AB8500_RTC_CC_CONF_REG		0x01
105*417c0fc2SLinus Walleij #define AB8500_RTC_CTRL_REG		0x0B
106*417c0fc2SLinus Walleij #define AB8500_RTC_CTRL1_REG		0x11
107*417c0fc2SLinus Walleij 
108*417c0fc2SLinus Walleij /*
109*417c0fc2SLinus Walleij  * OTP register offsets
110*417c0fc2SLinus Walleij  * Bank : 0x15
111*417c0fc2SLinus Walleij  */
112*417c0fc2SLinus Walleij #define AB8500_OTP_CONF_15		0x0E
113*417c0fc2SLinus Walleij 
114*417c0fc2SLinus Walleij /* GPADC constants from AB8500 spec, UM0836 */
115*417c0fc2SLinus Walleij #define ADC_RESOLUTION			1024
116*417c0fc2SLinus Walleij #define ADC_CH_MAIN_MIN			0
117*417c0fc2SLinus Walleij #define ADC_CH_MAIN_MAX			20030
118*417c0fc2SLinus Walleij #define ADC_CH_VBUS_MIN			0
119*417c0fc2SLinus Walleij #define ADC_CH_VBUS_MAX			20030
120*417c0fc2SLinus Walleij #define ADC_CH_VBAT_MIN			2300
121*417c0fc2SLinus Walleij #define ADC_CH_VBAT_MAX			4800
122*417c0fc2SLinus Walleij #define ADC_CH_BKBAT_MIN		0
123*417c0fc2SLinus Walleij #define ADC_CH_BKBAT_MAX		3200
124*417c0fc2SLinus Walleij 
125*417c0fc2SLinus Walleij /* Main charge i/p current */
126*417c0fc2SLinus Walleij #define MAIN_CH_IP_CUR_0P9A		0x80
127*417c0fc2SLinus Walleij #define MAIN_CH_IP_CUR_1P0A		0x90
128*417c0fc2SLinus Walleij #define MAIN_CH_IP_CUR_1P1A		0xA0
129*417c0fc2SLinus Walleij #define MAIN_CH_IP_CUR_1P2A		0xB0
130*417c0fc2SLinus Walleij #define MAIN_CH_IP_CUR_1P3A		0xC0
131*417c0fc2SLinus Walleij #define MAIN_CH_IP_CUR_1P4A		0xD0
132*417c0fc2SLinus Walleij #define MAIN_CH_IP_CUR_1P5A		0xE0
133*417c0fc2SLinus Walleij 
134*417c0fc2SLinus Walleij /* ChVoltLevel */
135*417c0fc2SLinus Walleij #define CH_VOL_LVL_3P5			0x00
136*417c0fc2SLinus Walleij #define CH_VOL_LVL_4P0			0x14
137*417c0fc2SLinus Walleij #define CH_VOL_LVL_4P05			0x16
138*417c0fc2SLinus Walleij #define CH_VOL_LVL_4P1			0x1B
139*417c0fc2SLinus Walleij #define CH_VOL_LVL_4P15			0x20
140*417c0fc2SLinus Walleij #define CH_VOL_LVL_4P2			0x25
141*417c0fc2SLinus Walleij #define CH_VOL_LVL_4P6			0x4D
142*417c0fc2SLinus Walleij 
143*417c0fc2SLinus Walleij /* ChOutputCurrentLevel */
144*417c0fc2SLinus Walleij #define CH_OP_CUR_LVL_0P1		0x00
145*417c0fc2SLinus Walleij #define CH_OP_CUR_LVL_0P2		0x01
146*417c0fc2SLinus Walleij #define CH_OP_CUR_LVL_0P3		0x02
147*417c0fc2SLinus Walleij #define CH_OP_CUR_LVL_0P4		0x03
148*417c0fc2SLinus Walleij #define CH_OP_CUR_LVL_0P5		0x04
149*417c0fc2SLinus Walleij #define CH_OP_CUR_LVL_0P6		0x05
150*417c0fc2SLinus Walleij #define CH_OP_CUR_LVL_0P7		0x06
151*417c0fc2SLinus Walleij #define CH_OP_CUR_LVL_0P8		0x07
152*417c0fc2SLinus Walleij #define CH_OP_CUR_LVL_0P9		0x08
153*417c0fc2SLinus Walleij #define CH_OP_CUR_LVL_1P4		0x0D
154*417c0fc2SLinus Walleij #define CH_OP_CUR_LVL_1P5		0x0E
155*417c0fc2SLinus Walleij #define CH_OP_CUR_LVL_1P6		0x0F
156*417c0fc2SLinus Walleij #define CH_OP_CUR_LVL_2P		0x3F
157*417c0fc2SLinus Walleij 
158*417c0fc2SLinus Walleij /* BTEMP High thermal limits */
159*417c0fc2SLinus Walleij #define BTEMP_HIGH_TH_57_0		0x00
160*417c0fc2SLinus Walleij #define BTEMP_HIGH_TH_52		0x01
161*417c0fc2SLinus Walleij #define BTEMP_HIGH_TH_57_1		0x02
162*417c0fc2SLinus Walleij #define BTEMP_HIGH_TH_62		0x03
163*417c0fc2SLinus Walleij 
164*417c0fc2SLinus Walleij /* current is mA */
165*417c0fc2SLinus Walleij #define USB_0P1A			100
166*417c0fc2SLinus Walleij #define USB_0P2A			200
167*417c0fc2SLinus Walleij #define USB_0P3A			300
168*417c0fc2SLinus Walleij #define USB_0P4A			400
169*417c0fc2SLinus Walleij #define USB_0P5A			500
170*417c0fc2SLinus Walleij 
171*417c0fc2SLinus Walleij #define LOW_BAT_3P1V			0x20
172*417c0fc2SLinus Walleij #define LOW_BAT_2P3V			0x00
173*417c0fc2SLinus Walleij #define LOW_BAT_RESET			0x01
174*417c0fc2SLinus Walleij #define LOW_BAT_ENABLE			0x01
175*417c0fc2SLinus Walleij 
176*417c0fc2SLinus Walleij /* Backup battery constants */
177*417c0fc2SLinus Walleij #define BUP_ICH_SEL_50UA		0x00
178*417c0fc2SLinus Walleij #define BUP_ICH_SEL_150UA		0x04
179*417c0fc2SLinus Walleij #define BUP_ICH_SEL_300UA		0x08
180*417c0fc2SLinus Walleij #define BUP_ICH_SEL_700UA		0x0C
181*417c0fc2SLinus Walleij 
182*417c0fc2SLinus Walleij enum bup_vch_sel {
183*417c0fc2SLinus Walleij 	BUP_VCH_SEL_2P5V,
184*417c0fc2SLinus Walleij 	BUP_VCH_SEL_2P6V,
185*417c0fc2SLinus Walleij 	BUP_VCH_SEL_2P8V,
186*417c0fc2SLinus Walleij 	BUP_VCH_SEL_3P1V,
187*417c0fc2SLinus Walleij 	/*
188*417c0fc2SLinus Walleij 	 * Note that the following 5 values 2.7v, 2.9v, 3.0v, 3.2v, 3.3v
189*417c0fc2SLinus Walleij 	 * are only available on ab8540. You can't choose these 5
190*417c0fc2SLinus Walleij 	 * voltage on ab8500/ab8505/ab9540.
191*417c0fc2SLinus Walleij 	 */
192*417c0fc2SLinus Walleij 	BUP_VCH_SEL_2P7V,
193*417c0fc2SLinus Walleij 	BUP_VCH_SEL_2P9V,
194*417c0fc2SLinus Walleij 	BUP_VCH_SEL_3P0V,
195*417c0fc2SLinus Walleij 	BUP_VCH_SEL_3P2V,
196*417c0fc2SLinus Walleij 	BUP_VCH_SEL_3P3V,
197*417c0fc2SLinus Walleij };
198*417c0fc2SLinus Walleij 
199*417c0fc2SLinus Walleij #define BUP_VCH_RANGE		0x02
200*417c0fc2SLinus Walleij #define VBUP33_VRTCN		0x01
201*417c0fc2SLinus Walleij 
202*417c0fc2SLinus Walleij /* Battery OVV constants */
203*417c0fc2SLinus Walleij #define BATT_OVV_ENA			0x02
204*417c0fc2SLinus Walleij #define BATT_OVV_TH_3P7			0x00
205*417c0fc2SLinus Walleij #define BATT_OVV_TH_4P75		0x01
206*417c0fc2SLinus Walleij 
207*417c0fc2SLinus Walleij /* A value to indicate over voltage */
208*417c0fc2SLinus Walleij #define BATT_OVV_VALUE			4750
209*417c0fc2SLinus Walleij 
210*417c0fc2SLinus Walleij /* VBUS OVV constants */
211*417c0fc2SLinus Walleij #define VBUS_OVV_SELECT_MASK		0x78
212*417c0fc2SLinus Walleij #define VBUS_OVV_SELECT_5P6V		0x00
213*417c0fc2SLinus Walleij #define VBUS_OVV_SELECT_5P7V		0x08
214*417c0fc2SLinus Walleij #define VBUS_OVV_SELECT_5P8V		0x10
215*417c0fc2SLinus Walleij #define VBUS_OVV_SELECT_5P9V		0x18
216*417c0fc2SLinus Walleij #define VBUS_OVV_SELECT_6P0V		0x20
217*417c0fc2SLinus Walleij #define VBUS_OVV_SELECT_6P1V		0x28
218*417c0fc2SLinus Walleij #define VBUS_OVV_SELECT_6P2V		0x30
219*417c0fc2SLinus Walleij #define VBUS_OVV_SELECT_6P3V		0x38
220*417c0fc2SLinus Walleij 
221*417c0fc2SLinus Walleij #define VBUS_AUTO_IN_CURR_LIM_ENA	0x04
222*417c0fc2SLinus Walleij 
223*417c0fc2SLinus Walleij /* Fuel Gauge constants */
224*417c0fc2SLinus Walleij #define RESET_ACCU			0x02
225*417c0fc2SLinus Walleij #define READ_REQ			0x01
226*417c0fc2SLinus Walleij #define CC_DEEP_SLEEP_ENA		0x02
227*417c0fc2SLinus Walleij #define CC_PWR_UP_ENA			0x01
228*417c0fc2SLinus Walleij #define CC_SAMPLES_40			0x28
229*417c0fc2SLinus Walleij #define RD_NCONV_ACCU_REQ		0x01
230*417c0fc2SLinus Walleij #define CC_CALIB			0x08
231*417c0fc2SLinus Walleij #define CC_INTAVGOFFSET_ENA		0x10
232*417c0fc2SLinus Walleij #define CC_MUXOFFSET			0x80
233*417c0fc2SLinus Walleij #define CC_INT_CAL_N_AVG_MASK		0x60
234*417c0fc2SLinus Walleij #define CC_INT_CAL_SAMPLES_16		0x40
235*417c0fc2SLinus Walleij #define CC_INT_CAL_SAMPLES_8		0x20
236*417c0fc2SLinus Walleij #define CC_INT_CAL_SAMPLES_4		0x00
237*417c0fc2SLinus Walleij 
238*417c0fc2SLinus Walleij /* RTC constants */
239*417c0fc2SLinus Walleij #define RTC_BUP_CH_ENA			0x10
240*417c0fc2SLinus Walleij 
241*417c0fc2SLinus Walleij /* BatCtrl Current Source Constants */
242*417c0fc2SLinus Walleij #define BAT_CTRL_7U_ENA			0x01
243*417c0fc2SLinus Walleij #define BAT_CTRL_20U_ENA		0x02
244*417c0fc2SLinus Walleij #define BAT_CTRL_18U_ENA		0x01
245*417c0fc2SLinus Walleij #define BAT_CTRL_16U_ENA		0x02
246*417c0fc2SLinus Walleij #define BAT_CTRL_CMP_ENA		0x04
247*417c0fc2SLinus Walleij #define FORCE_BAT_CTRL_CMP_HIGH		0x08
248*417c0fc2SLinus Walleij #define BAT_CTRL_PULL_UP_ENA		0x10
249*417c0fc2SLinus Walleij 
250*417c0fc2SLinus Walleij /* Battery type */
251*417c0fc2SLinus Walleij #define BATTERY_UNKNOWN			00
252*417c0fc2SLinus Walleij 
253*417c0fc2SLinus Walleij /* Registers for pcut feature in ab8505 and ab9540 */
254*417c0fc2SLinus Walleij #define AB8505_RTC_PCUT_CTL_STATUS_REG	0x12
255*417c0fc2SLinus Walleij #define AB8505_RTC_PCUT_TIME_REG	0x13
256*417c0fc2SLinus Walleij #define AB8505_RTC_PCUT_MAX_TIME_REG	0x14
257*417c0fc2SLinus Walleij #define AB8505_RTC_PCUT_FLAG_TIME_REG	0x15
258*417c0fc2SLinus Walleij #define AB8505_RTC_PCUT_RESTART_REG	0x16
259*417c0fc2SLinus Walleij #define AB8505_RTC_PCUT_DEBOUNCE_REG	0x17
260*417c0fc2SLinus Walleij 
261*417c0fc2SLinus Walleij /* USB Power Path constants for ab8540 */
262*417c0fc2SLinus Walleij #define BUS_VSYS_VOL_SELECT_MASK		0x06
263*417c0fc2SLinus Walleij #define BUS_VSYS_VOL_SELECT_3P6V		0x00
264*417c0fc2SLinus Walleij #define BUS_VSYS_VOL_SELECT_3P325V		0x02
265*417c0fc2SLinus Walleij #define BUS_VSYS_VOL_SELECT_3P9V		0x04
266*417c0fc2SLinus Walleij #define BUS_VSYS_VOL_SELECT_4P3V		0x06
267*417c0fc2SLinus Walleij #define BUS_POWER_PATH_MODE_ENA			0x01
268*417c0fc2SLinus Walleij #define BUS_PP_PRECHG_CURRENT_MASK		0x0E
269*417c0fc2SLinus Walleij #define BUS_POWER_PATH_PRECHG_ENA		0x01
270*417c0fc2SLinus Walleij 
271*417c0fc2SLinus Walleij /**
272*417c0fc2SLinus Walleij  * struct res_to_temp - defines one point in a temp to res curve. To
273*417c0fc2SLinus Walleij  * be used in battery packs that combines the identification resistor with a
274*417c0fc2SLinus Walleij  * NTC resistor.
275*417c0fc2SLinus Walleij  * @temp:			battery pack temperature in Celsius
276*417c0fc2SLinus Walleij  * @resist:			NTC resistor net total resistance
277*417c0fc2SLinus Walleij  */
278*417c0fc2SLinus Walleij struct res_to_temp {
279*417c0fc2SLinus Walleij 	int temp;
280*417c0fc2SLinus Walleij 	int resist;
281*417c0fc2SLinus Walleij };
282*417c0fc2SLinus Walleij 
283*417c0fc2SLinus Walleij /**
284*417c0fc2SLinus Walleij  * struct batres_vs_temp - defines one point in a temp vs battery internal
285*417c0fc2SLinus Walleij  * resistance curve.
286*417c0fc2SLinus Walleij  * @temp:			battery pack temperature in Celsius
287*417c0fc2SLinus Walleij  * @resist:			battery internal reistance in mOhm
288*417c0fc2SLinus Walleij  */
289*417c0fc2SLinus Walleij struct batres_vs_temp {
290*417c0fc2SLinus Walleij 	int temp;
291*417c0fc2SLinus Walleij 	int resist;
292*417c0fc2SLinus Walleij };
293*417c0fc2SLinus Walleij 
294*417c0fc2SLinus Walleij /* Forward declaration */
295*417c0fc2SLinus Walleij struct ab8500_fg;
296*417c0fc2SLinus Walleij 
297*417c0fc2SLinus Walleij /**
298*417c0fc2SLinus Walleij  * struct ab8500_fg_parameters - Fuel gauge algorithm parameters, in seconds
299*417c0fc2SLinus Walleij  * if not specified
300*417c0fc2SLinus Walleij  * @recovery_sleep_timer:	Time between measurements while recovering
301*417c0fc2SLinus Walleij  * @recovery_total_time:	Total recovery time
302*417c0fc2SLinus Walleij  * @init_timer:			Measurement interval during startup
303*417c0fc2SLinus Walleij  * @init_discard_time:		Time we discard voltage measurement at startup
304*417c0fc2SLinus Walleij  * @init_total_time:		Total init time during startup
305*417c0fc2SLinus Walleij  * @high_curr_time:		Time current has to be high to go to recovery
306*417c0fc2SLinus Walleij  * @accu_charging:		FG accumulation time while charging
307*417c0fc2SLinus Walleij  * @accu_high_curr:		FG accumulation time in high current mode
308*417c0fc2SLinus Walleij  * @high_curr_threshold:	High current threshold, in mA
309*417c0fc2SLinus Walleij  * @lowbat_threshold:		Low battery threshold, in mV
310*417c0fc2SLinus Walleij  * @battok_falling_th_sel0	Threshold in mV for battOk signal sel0
311*417c0fc2SLinus Walleij  *				Resolution in 50 mV step.
312*417c0fc2SLinus Walleij  * @battok_raising_th_sel1	Threshold in mV for battOk signal sel1
313*417c0fc2SLinus Walleij  *				Resolution in 50 mV step.
314*417c0fc2SLinus Walleij  * @user_cap_limit		Capacity reported from user must be within this
315*417c0fc2SLinus Walleij  *				limit to be considered as sane, in percentage
316*417c0fc2SLinus Walleij  *				points.
317*417c0fc2SLinus Walleij  * @maint_thres			This is the threshold where we stop reporting
318*417c0fc2SLinus Walleij  *				battery full while in maintenance, in per cent
319*417c0fc2SLinus Walleij  * @pcut_enable:			Enable power cut feature in ab8505
320*417c0fc2SLinus Walleij  * @pcut_max_time:		Max time threshold
321*417c0fc2SLinus Walleij  * @pcut_flag_time:		Flagtime threshold
322*417c0fc2SLinus Walleij  * @pcut_max_restart:		Max number of restarts
323*417c0fc2SLinus Walleij  * @pcut_debunce_time:	Sets battery debounce time
324*417c0fc2SLinus Walleij  */
325*417c0fc2SLinus Walleij struct ab8500_fg_parameters {
326*417c0fc2SLinus Walleij 	int recovery_sleep_timer;
327*417c0fc2SLinus Walleij 	int recovery_total_time;
328*417c0fc2SLinus Walleij 	int init_timer;
329*417c0fc2SLinus Walleij 	int init_discard_time;
330*417c0fc2SLinus Walleij 	int init_total_time;
331*417c0fc2SLinus Walleij 	int high_curr_time;
332*417c0fc2SLinus Walleij 	int accu_charging;
333*417c0fc2SLinus Walleij 	int accu_high_curr;
334*417c0fc2SLinus Walleij 	int high_curr_threshold;
335*417c0fc2SLinus Walleij 	int lowbat_threshold;
336*417c0fc2SLinus Walleij 	int battok_falling_th_sel0;
337*417c0fc2SLinus Walleij 	int battok_raising_th_sel1;
338*417c0fc2SLinus Walleij 	int user_cap_limit;
339*417c0fc2SLinus Walleij 	int maint_thres;
340*417c0fc2SLinus Walleij 	bool pcut_enable;
341*417c0fc2SLinus Walleij 	u8 pcut_max_time;
342*417c0fc2SLinus Walleij 	u8 pcut_flag_time;
343*417c0fc2SLinus Walleij 	u8 pcut_max_restart;
344*417c0fc2SLinus Walleij 	u8 pcut_debunce_time;
345*417c0fc2SLinus Walleij };
346*417c0fc2SLinus Walleij 
347*417c0fc2SLinus Walleij /**
348*417c0fc2SLinus Walleij  * struct ab8500_charger_maximization - struct used by the board config.
349*417c0fc2SLinus Walleij  * @use_maxi:		Enable maximization for this battery type
350*417c0fc2SLinus Walleij  * @maxi_chg_curr:	Maximum charger current allowed
351*417c0fc2SLinus Walleij  * @maxi_wait_cycles:	cycles to wait before setting charger current
352*417c0fc2SLinus Walleij  * @charger_curr_step	delta between two charger current settings (mA)
353*417c0fc2SLinus Walleij  */
354*417c0fc2SLinus Walleij struct ab8500_maxim_parameters {
355*417c0fc2SLinus Walleij 	bool ena_maxi;
356*417c0fc2SLinus Walleij 	int chg_curr;
357*417c0fc2SLinus Walleij 	int wait_cycles;
358*417c0fc2SLinus Walleij 	int charger_curr_step;
359*417c0fc2SLinus Walleij };
360*417c0fc2SLinus Walleij 
361*417c0fc2SLinus Walleij /**
362*417c0fc2SLinus Walleij  * struct ab8500_bm_capacity_levels - ab8500 capacity level data
363*417c0fc2SLinus Walleij  * @critical:		critical capacity level in percent
364*417c0fc2SLinus Walleij  * @low:		low capacity level in percent
365*417c0fc2SLinus Walleij  * @normal:		normal capacity level in percent
366*417c0fc2SLinus Walleij  * @high:		high capacity level in percent
367*417c0fc2SLinus Walleij  * @full:		full capacity level in percent
368*417c0fc2SLinus Walleij  */
369*417c0fc2SLinus Walleij struct ab8500_bm_capacity_levels {
370*417c0fc2SLinus Walleij 	int critical;
371*417c0fc2SLinus Walleij 	int low;
372*417c0fc2SLinus Walleij 	int normal;
373*417c0fc2SLinus Walleij 	int high;
374*417c0fc2SLinus Walleij 	int full;
375*417c0fc2SLinus Walleij };
376*417c0fc2SLinus Walleij 
377*417c0fc2SLinus Walleij /**
378*417c0fc2SLinus Walleij  * struct ab8500_bm_charger_parameters - Charger specific parameters
379*417c0fc2SLinus Walleij  * @usb_volt_max:	maximum allowed USB charger voltage in mV
380*417c0fc2SLinus Walleij  * @usb_curr_max:	maximum allowed USB charger current in mA
381*417c0fc2SLinus Walleij  * @ac_volt_max:	maximum allowed AC charger voltage in mV
382*417c0fc2SLinus Walleij  * @ac_curr_max:	maximum allowed AC charger current in mA
383*417c0fc2SLinus Walleij  */
384*417c0fc2SLinus Walleij struct ab8500_bm_charger_parameters {
385*417c0fc2SLinus Walleij 	int usb_volt_max;
386*417c0fc2SLinus Walleij 	int usb_curr_max;
387*417c0fc2SLinus Walleij 	int ac_volt_max;
388*417c0fc2SLinus Walleij 	int ac_curr_max;
389*417c0fc2SLinus Walleij };
390*417c0fc2SLinus Walleij 
391*417c0fc2SLinus Walleij /**
392*417c0fc2SLinus Walleij  * struct ab8500_bm_data - ab8500 battery management data
393*417c0fc2SLinus Walleij  * @temp_under		under this temp, charging is stopped
394*417c0fc2SLinus Walleij  * @temp_low		between this temp and temp_under charging is reduced
395*417c0fc2SLinus Walleij  * @temp_high		between this temp and temp_over charging is reduced
396*417c0fc2SLinus Walleij  * @temp_over		over this temp, charging is stopped
397*417c0fc2SLinus Walleij  * @temp_interval_chg	temperature measurement interval in s when charging
398*417c0fc2SLinus Walleij  * @temp_interval_nochg	temperature measurement interval in s when not charging
399*417c0fc2SLinus Walleij  * @main_safety_tmr_h	safety timer for main charger
400*417c0fc2SLinus Walleij  * @usb_safety_tmr_h	safety timer for usb charger
401*417c0fc2SLinus Walleij  * @bkup_bat_v		voltage which we charge the backup battery with
402*417c0fc2SLinus Walleij  * @bkup_bat_i		current which we charge the backup battery with
403*417c0fc2SLinus Walleij  * @no_maintenance	indicates that maintenance charging is disabled
404*417c0fc2SLinus Walleij  * @capacity_scaling    indicates whether capacity scaling is to be used
405*417c0fc2SLinus Walleij  * @adc_therm		placement of thermistor, batctrl or battemp adc
406*417c0fc2SLinus Walleij  * @chg_unknown_bat	flag to enable charging of unknown batteries
407*417c0fc2SLinus Walleij  * @enable_overshoot	flag to enable VBAT overshoot control
408*417c0fc2SLinus Walleij  * @fg_res		resistance of FG resistor in 0.1mOhm
409*417c0fc2SLinus Walleij  * @n_btypes		number of elements in array bat_type
410*417c0fc2SLinus Walleij  * @batt_id		index of the identified battery in array bat_type
411*417c0fc2SLinus Walleij  * @interval_charging	charge alg cycle period time when charging (sec)
412*417c0fc2SLinus Walleij  * @interval_not_charging charge alg cycle period time when not charging (sec)
413*417c0fc2SLinus Walleij  * @temp_hysteresis	temperature hysteresis
414*417c0fc2SLinus Walleij  * @gnd_lift_resistance	Battery ground to phone ground resistance (mOhm)
415*417c0fc2SLinus Walleij  * @maxi:		maximization parameters
416*417c0fc2SLinus Walleij  * @cap_levels		capacity in percent for the different capacity levels
417*417c0fc2SLinus Walleij  * @bat_type		table of supported battery types
418*417c0fc2SLinus Walleij  * @chg_params		charger parameters
419*417c0fc2SLinus Walleij  * @fg_params		fuel gauge parameters
420*417c0fc2SLinus Walleij  */
421*417c0fc2SLinus Walleij struct ab8500_bm_data {
422*417c0fc2SLinus Walleij 	int temp_under;
423*417c0fc2SLinus Walleij 	int temp_low;
424*417c0fc2SLinus Walleij 	int temp_high;
425*417c0fc2SLinus Walleij 	int temp_over;
426*417c0fc2SLinus Walleij 	int temp_interval_chg;
427*417c0fc2SLinus Walleij 	int temp_interval_nochg;
428*417c0fc2SLinus Walleij 	int main_safety_tmr_h;
429*417c0fc2SLinus Walleij 	int usb_safety_tmr_h;
430*417c0fc2SLinus Walleij 	int bkup_bat_v;
431*417c0fc2SLinus Walleij 	int bkup_bat_i;
432*417c0fc2SLinus Walleij 	bool no_maintenance;
433*417c0fc2SLinus Walleij 	bool capacity_scaling;
434*417c0fc2SLinus Walleij 	bool chg_unknown_bat;
435*417c0fc2SLinus Walleij 	bool enable_overshoot;
436*417c0fc2SLinus Walleij 	enum abx500_adc_therm adc_therm;
437*417c0fc2SLinus Walleij 	int fg_res;
438*417c0fc2SLinus Walleij 	int n_btypes;
439*417c0fc2SLinus Walleij 	int batt_id;
440*417c0fc2SLinus Walleij 	int interval_charging;
441*417c0fc2SLinus Walleij 	int interval_not_charging;
442*417c0fc2SLinus Walleij 	int temp_hysteresis;
443*417c0fc2SLinus Walleij 	int gnd_lift_resistance;
444*417c0fc2SLinus Walleij 	const struct ab8500_maxim_parameters *maxi;
445*417c0fc2SLinus Walleij 	const struct ab8500_bm_capacity_levels *cap_levels;
446*417c0fc2SLinus Walleij 	const struct ab8500_bm_charger_parameters *chg_params;
447*417c0fc2SLinus Walleij 	const struct ab8500_fg_parameters *fg_params;
448*417c0fc2SLinus Walleij };
449*417c0fc2SLinus Walleij 
450*417c0fc2SLinus Walleij struct ab8500_btemp;
451*417c0fc2SLinus Walleij struct ab8500_fg;
452*417c0fc2SLinus Walleij 
453*417c0fc2SLinus Walleij extern struct abx500_bm_data ab8500_bm_data;
454*417c0fc2SLinus Walleij 
455*417c0fc2SLinus Walleij void ab8500_charger_usb_state_changed(u8 bm_usb_state, u16 mA);
456*417c0fc2SLinus Walleij struct ab8500_fg *ab8500_fg_get(void);
457*417c0fc2SLinus Walleij int ab8500_fg_inst_curr_blocking(struct ab8500_fg *dev);
458*417c0fc2SLinus Walleij int ab8500_fg_inst_curr_start(struct ab8500_fg *di);
459*417c0fc2SLinus Walleij int ab8500_fg_inst_curr_finalize(struct ab8500_fg *di, int *res);
460*417c0fc2SLinus Walleij int ab8500_fg_inst_curr_started(struct ab8500_fg *di);
461*417c0fc2SLinus Walleij int ab8500_fg_inst_curr_done(struct ab8500_fg *di);
462*417c0fc2SLinus Walleij 
463*417c0fc2SLinus Walleij #endif /* _AB8500_CHARGER_H_ */
464