blob: dfabd6db7ddf7c1cba523a022aa5dcf008671652 [file] [log] [blame]
Carlo Caionecfb61a42014-05-01 14:29:27 +02001/*
2 * Functions and registers to access AXP20X power management chip.
3 *
4 * Copyright (C) 2013, Carlo Caione <carlo@caione.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef __LINUX_MFD_AXP20X_H
12#define __LINUX_MFD_AXP20X_H
13
14enum {
15 AXP202_ID = 0,
16 AXP209_ID,
Jacob Panaf7e9062014-10-06 21:17:14 -070017 AXP288_ID,
18 NR_AXP20X_VARIANTS,
Carlo Caionecfb61a42014-05-01 14:29:27 +020019};
20
21#define AXP20X_DATACACHE(m) (0x04 + (m))
22
23/* Power supply */
24#define AXP20X_PWR_INPUT_STATUS 0x00
25#define AXP20X_PWR_OP_MODE 0x01
26#define AXP20X_USB_OTG_STATUS 0x02
27#define AXP20X_PWR_OUT_CTRL 0x12
28#define AXP20X_DCDC2_V_OUT 0x23
29#define AXP20X_DCDC2_LDO3_V_SCAL 0x25
30#define AXP20X_DCDC3_V_OUT 0x27
31#define AXP20X_LDO24_V_OUT 0x28
32#define AXP20X_LDO3_V_OUT 0x29
33#define AXP20X_VBUS_IPSOUT_MGMT 0x30
34#define AXP20X_V_OFF 0x31
35#define AXP20X_OFF_CTRL 0x32
36#define AXP20X_CHRG_CTRL1 0x33
37#define AXP20X_CHRG_CTRL2 0x34
38#define AXP20X_CHRG_BAK_CTRL 0x35
39#define AXP20X_PEK_KEY 0x36
40#define AXP20X_DCDC_FREQ 0x37
41#define AXP20X_V_LTF_CHRG 0x38
42#define AXP20X_V_HTF_CHRG 0x39
43#define AXP20X_APS_WARN_L1 0x3a
44#define AXP20X_APS_WARN_L2 0x3b
45#define AXP20X_V_LTF_DISCHRG 0x3c
46#define AXP20X_V_HTF_DISCHRG 0x3d
47
48/* Interrupt */
49#define AXP20X_IRQ1_EN 0x40
50#define AXP20X_IRQ2_EN 0x41
51#define AXP20X_IRQ3_EN 0x42
52#define AXP20X_IRQ4_EN 0x43
53#define AXP20X_IRQ5_EN 0x44
Jacob Panaf7e9062014-10-06 21:17:14 -070054#define AXP20X_IRQ6_EN 0x45
Carlo Caionecfb61a42014-05-01 14:29:27 +020055#define AXP20X_IRQ1_STATE 0x48
56#define AXP20X_IRQ2_STATE 0x49
57#define AXP20X_IRQ3_STATE 0x4a
58#define AXP20X_IRQ4_STATE 0x4b
59#define AXP20X_IRQ5_STATE 0x4c
Jacob Panaf7e9062014-10-06 21:17:14 -070060#define AXP20X_IRQ6_STATE 0x4d
Carlo Caionecfb61a42014-05-01 14:29:27 +020061
62/* ADC */
63#define AXP20X_ACIN_V_ADC_H 0x56
64#define AXP20X_ACIN_V_ADC_L 0x57
65#define AXP20X_ACIN_I_ADC_H 0x58
66#define AXP20X_ACIN_I_ADC_L 0x59
67#define AXP20X_VBUS_V_ADC_H 0x5a
68#define AXP20X_VBUS_V_ADC_L 0x5b
69#define AXP20X_VBUS_I_ADC_H 0x5c
70#define AXP20X_VBUS_I_ADC_L 0x5d
71#define AXP20X_TEMP_ADC_H 0x5e
72#define AXP20X_TEMP_ADC_L 0x5f
73#define AXP20X_TS_IN_H 0x62
74#define AXP20X_TS_IN_L 0x63
75#define AXP20X_GPIO0_V_ADC_H 0x64
76#define AXP20X_GPIO0_V_ADC_L 0x65
77#define AXP20X_GPIO1_V_ADC_H 0x66
78#define AXP20X_GPIO1_V_ADC_L 0x67
79#define AXP20X_PWR_BATT_H 0x70
80#define AXP20X_PWR_BATT_M 0x71
81#define AXP20X_PWR_BATT_L 0x72
82#define AXP20X_BATT_V_H 0x78
83#define AXP20X_BATT_V_L 0x79
84#define AXP20X_BATT_CHRG_I_H 0x7a
85#define AXP20X_BATT_CHRG_I_L 0x7b
86#define AXP20X_BATT_DISCHRG_I_H 0x7c
87#define AXP20X_BATT_DISCHRG_I_L 0x7d
88#define AXP20X_IPSOUT_V_HIGH_H 0x7e
89#define AXP20X_IPSOUT_V_HIGH_L 0x7f
90
91/* Power supply */
92#define AXP20X_DCDC_MODE 0x80
93#define AXP20X_ADC_EN1 0x82
94#define AXP20X_ADC_EN2 0x83
95#define AXP20X_ADC_RATE 0x84
96#define AXP20X_GPIO10_IN_RANGE 0x85
97#define AXP20X_GPIO1_ADC_IRQ_RIS 0x86
98#define AXP20X_GPIO1_ADC_IRQ_FAL 0x87
99#define AXP20X_TIMER_CTRL 0x8a
100#define AXP20X_VBUS_MON 0x8b
101#define AXP20X_OVER_TMP 0x8f
102
103/* GPIO */
104#define AXP20X_GPIO0_CTRL 0x90
105#define AXP20X_LDO5_V_OUT 0x91
106#define AXP20X_GPIO1_CTRL 0x92
107#define AXP20X_GPIO2_CTRL 0x93
108#define AXP20X_GPIO20_SS 0x94
109#define AXP20X_GPIO3_CTRL 0x95
110
111/* Battery */
112#define AXP20X_CHRG_CC_31_24 0xb0
113#define AXP20X_CHRG_CC_23_16 0xb1
114#define AXP20X_CHRG_CC_15_8 0xb2
115#define AXP20X_CHRG_CC_7_0 0xb3
116#define AXP20X_DISCHRG_CC_31_24 0xb4
117#define AXP20X_DISCHRG_CC_23_16 0xb5
118#define AXP20X_DISCHRG_CC_15_8 0xb6
119#define AXP20X_DISCHRG_CC_7_0 0xb7
120#define AXP20X_CC_CTRL 0xb8
121#define AXP20X_FG_RES 0xb9
122
Jacob Panaf7e9062014-10-06 21:17:14 -0700123/* AXP288 specific registers */
124#define AXP288_PMIC_ADC_H 0x56
125#define AXP288_PMIC_ADC_L 0x57
126#define AXP288_ADC_TS_PIN_CTRL 0x84
Jacob Panaf7e9062014-10-06 21:17:14 -0700127#define AXP288_PMIC_ADC_EN 0x84
Jacob Panaf7e9062014-10-06 21:17:14 -0700128
Todd E Brandt774e0b42015-01-07 13:25:52 -0800129/* Fuel Gauge */
130#define AXP288_FG_RDC1_REG 0xba
131#define AXP288_FG_RDC0_REG 0xbb
132#define AXP288_FG_OCVH_REG 0xbc
133#define AXP288_FG_OCVL_REG 0xbd
134#define AXP288_FG_OCV_CURVE_REG 0xc0
135#define AXP288_FG_DES_CAP1_REG 0xe0
136#define AXP288_FG_DES_CAP0_REG 0xe1
137#define AXP288_FG_CC_MTR1_REG 0xe2
138#define AXP288_FG_CC_MTR0_REG 0xe3
139#define AXP288_FG_OCV_CAP_REG 0xe4
140#define AXP288_FG_CC_CAP_REG 0xe5
141#define AXP288_FG_LOW_CAP_REG 0xe6
142#define AXP288_FG_TUNE0 0xe8
143#define AXP288_FG_TUNE1 0xe9
144#define AXP288_FG_TUNE2 0xea
145#define AXP288_FG_TUNE3 0xeb
146#define AXP288_FG_TUNE4 0xec
147#define AXP288_FG_TUNE5 0xed
Jacob Panaf7e9062014-10-06 21:17:14 -0700148
Carlo Caionecfb61a42014-05-01 14:29:27 +0200149/* Regulators IDs */
150enum {
151 AXP20X_LDO1 = 0,
152 AXP20X_LDO2,
153 AXP20X_LDO3,
154 AXP20X_LDO4,
155 AXP20X_LDO5,
156 AXP20X_DCDC2,
157 AXP20X_DCDC3,
158 AXP20X_REG_ID_MAX,
159};
160
161/* IRQs */
162enum {
163 AXP20X_IRQ_ACIN_OVER_V = 1,
164 AXP20X_IRQ_ACIN_PLUGIN,
165 AXP20X_IRQ_ACIN_REMOVAL,
166 AXP20X_IRQ_VBUS_OVER_V,
167 AXP20X_IRQ_VBUS_PLUGIN,
168 AXP20X_IRQ_VBUS_REMOVAL,
169 AXP20X_IRQ_VBUS_V_LOW,
170 AXP20X_IRQ_BATT_PLUGIN,
171 AXP20X_IRQ_BATT_REMOVAL,
172 AXP20X_IRQ_BATT_ENT_ACT_MODE,
173 AXP20X_IRQ_BATT_EXIT_ACT_MODE,
174 AXP20X_IRQ_CHARG,
175 AXP20X_IRQ_CHARG_DONE,
176 AXP20X_IRQ_BATT_TEMP_HIGH,
177 AXP20X_IRQ_BATT_TEMP_LOW,
178 AXP20X_IRQ_DIE_TEMP_HIGH,
179 AXP20X_IRQ_CHARG_I_LOW,
180 AXP20X_IRQ_DCDC1_V_LONG,
181 AXP20X_IRQ_DCDC2_V_LONG,
182 AXP20X_IRQ_DCDC3_V_LONG,
183 AXP20X_IRQ_PEK_SHORT = 22,
184 AXP20X_IRQ_PEK_LONG,
185 AXP20X_IRQ_N_OE_PWR_ON,
186 AXP20X_IRQ_N_OE_PWR_OFF,
187 AXP20X_IRQ_VBUS_VALID,
188 AXP20X_IRQ_VBUS_NOT_VALID,
189 AXP20X_IRQ_VBUS_SESS_VALID,
190 AXP20X_IRQ_VBUS_SESS_END,
191 AXP20X_IRQ_LOW_PWR_LVL1,
192 AXP20X_IRQ_LOW_PWR_LVL2,
193 AXP20X_IRQ_TIMER,
194 AXP20X_IRQ_PEK_RIS_EDGE,
195 AXP20X_IRQ_PEK_FAL_EDGE,
196 AXP20X_IRQ_GPIO3_INPUT,
197 AXP20X_IRQ_GPIO2_INPUT,
198 AXP20X_IRQ_GPIO1_INPUT,
199 AXP20X_IRQ_GPIO0_INPUT,
200};
201
Jacob Panaf7e9062014-10-06 21:17:14 -0700202enum axp288_irqs {
203 AXP288_IRQ_VBUS_FALL = 2,
204 AXP288_IRQ_VBUS_RISE,
205 AXP288_IRQ_OV,
206 AXP288_IRQ_FALLING_ALT,
207 AXP288_IRQ_RISING_ALT,
208 AXP288_IRQ_OV_ALT,
209 AXP288_IRQ_DONE = 10,
210 AXP288_IRQ_CHARGING,
211 AXP288_IRQ_SAFE_QUIT,
212 AXP288_IRQ_SAFE_ENTER,
213 AXP288_IRQ_ABSENT,
214 AXP288_IRQ_APPEND,
215 AXP288_IRQ_QWBTU,
216 AXP288_IRQ_WBTU,
217 AXP288_IRQ_QWBTO,
218 AXP288_IRQ_WBTO,
219 AXP288_IRQ_QCBTU,
220 AXP288_IRQ_CBTU,
221 AXP288_IRQ_QCBTO,
222 AXP288_IRQ_CBTO,
223 AXP288_IRQ_WL2,
224 AXP288_IRQ_WL1,
225 AXP288_IRQ_GPADC,
226 AXP288_IRQ_OT = 31,
227 AXP288_IRQ_GPIO0,
228 AXP288_IRQ_GPIO1,
229 AXP288_IRQ_POKO,
230 AXP288_IRQ_POKL,
231 AXP288_IRQ_POKS,
232 AXP288_IRQ_POKN,
233 AXP288_IRQ_POKP,
234 AXP288_IRQ_TIMER,
235 AXP288_IRQ_MV_CHNG,
236 AXP288_IRQ_BC_USB_CHNG,
237};
238
239#define AXP288_TS_ADC_H 0x58
240#define AXP288_TS_ADC_L 0x59
241#define AXP288_GP_ADC_H 0x5a
242#define AXP288_GP_ADC_L 0x5b
243
Carlo Caionecfb61a42014-05-01 14:29:27 +0200244struct axp20x_dev {
245 struct device *dev;
246 struct i2c_client *i2c_client;
247 struct regmap *regmap;
248 struct regmap_irq_chip_data *regmap_irqc;
249 long variant;
Jacob Panaf7e9062014-10-06 21:17:14 -0700250 int nr_cells;
251 struct mfd_cell *cells;
252 const struct regmap_config *regmap_cfg;
253 const struct regmap_irq_chip *regmap_irq_chip;
Carlo Caionecfb61a42014-05-01 14:29:27 +0200254};
255
Todd E Brandt774e0b42015-01-07 13:25:52 -0800256#define BATTID_LEN 64
257#define OCV_CURVE_SIZE 32
258#define MAX_THERM_CURVE_SIZE 25
259#define PD_DEF_MIN_TEMP 0
260#define PD_DEF_MAX_TEMP 55
261
262struct axp20x_fg_pdata {
263 char battid[BATTID_LEN + 1];
264 int design_cap;
265 int min_volt;
266 int max_volt;
267 int max_temp;
268 int min_temp;
269 int cap1;
270 int cap0;
271 int rdc1;
272 int rdc0;
273 int ocv_curve[OCV_CURVE_SIZE];
274 int tcsz;
275 int thermistor_curve[MAX_THERM_CURVE_SIZE][2];
276};
277
Carlo Caionecfb61a42014-05-01 14:29:27 +0200278#endif /* __LINUX_MFD_AXP20X_H */