xref: /freebsd/sys/arm/allwinner/axp209reg.h (revision 076ad2f8)
1 /*-
2  * Copyright (c) 2016 Emmanuel Vadot <manu@freeebsd.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  * $FreeBSD$
26  */
27 
28 #ifndef _AXP209REG_H_
29 #define	_AXP209REG_H_
30 
31 /* Power State Register */
32 #define	AXP2XX_PSR		0x00
33 #define	AXP2XX_PSR_ACIN		0x80
34 #define	AXP2XX_PSR_ACIN_SHIFT	7
35 #define	AXP2XX_PSR_VBUS		0x20
36 #define	AXP2XX_PSR_VBUS_SHIFT	5
37 
38 /* Shutdown and battery control */
39 #define	AXP2XX_SHUTBAT		0x32
40 #define	AXP2XX_SHUTBAT_SHUTDOWN	0x80
41 
42 /* Voltage/Current Monitor */
43 #define	AXP209_ACIN_VOLTAGE		0x56
44 #define	AXP209_ACIN_CURRENT		0x58
45 #define	AXP209_VBUS_VOLTAGE		0x5A
46 #define	AXP209_VBUS_CURRENT		0x5C
47 #define	AXP2XX_BAT_VOLTAGE		0x78
48 #define	AXP2XX_BAT_CHARGE_CURRENT	0x7A
49 #define	AXP2XX_BAT_DISCHARGE_CURRENT	0x7C
50 
51 #define	AXP209_VOLT_STEP	1700
52 #define	AXP2XX_BATVOLT_STEP	1100
53 #define	AXP209_ACCURRENT_STEP	625
54 #define	AXP209_VBUSCURRENT_STEP	375
55 #define	AXP2XX_BATCURRENT_STEP	500
56 
57 /* Temperature monitor */
58 #define	AXP209_TEMPMON		0x5e
59 #define	AXP209_TEMPMON_MIN	1447	/* -144.7C */
60 #define	AXP221_TEMPMON_MIN	2437	/* -243.7C */
61 
62 #define	AXP221_TEMPMON		0x56
63 
64 /* Sensors conversion macros */
65 #define	AXP209_SENSOR_H(a)	((a) << 4)
66 #define	AXP209_SENSOR_L(a)	((a) & 0xf)
67 #define	AXP209_SENSOR_BAT_H(a)	((a) << 5)
68 #define	AXP209_SENSOR_BAT_L(a)	((a) & 0x1f)
69 
70 #define	AXP209_0C_TO_K		2732
71 
72 /* ADC Sensors */
73 #define	AXP2XX_ADC_ENABLE1	0x82
74 #define	AXP209_ADC_ENABLE2	0x83
75 
76 #define	AXP2XX_ADC1_BATVOLT	(1 << 7)
77 #define	AXP2XX_ADC1_BATCURRENT	(1 << 6)
78 #define	AXP209_ADC1_ACVOLT	(1 << 5)
79 #define	AXP221_ADC1_TEMP	(1 << 5)
80 #define	AXP209_ADC1_ACCURRENT	(1 << 4)
81 #define	AXP209_ADC1_VBUSVOLT	(1 << 3)
82 #define	AXP209_ADC1_VBUSCURRENT	(1 << 2)
83 #define	AXP221_ADC1_TS_PIN	(1 << 0)
84 
85 #define	AXP209_ADC2_TEMP	(1 << 7)
86 
87 /* Interrupt related registers */
88 #define	AXP2XX_IRQ1_ENABLE	0x40
89 #define	AXP2XX_IRQ1_STATUS	0x48
90 #define	 AXP2XX_IRQ1_AC_OVERVOLT	(1 << 7)
91 #define	 AXP2XX_IRQ1_AC_CONN		(1 << 6)
92 #define	 AXP2XX_IRQ1_AC_DISCONN		(1 << 5)
93 #define	 AXP2XX_IRQ1_VBUS_OVERVOLT	(1 << 4)
94 #define	 AXP2XX_IRQ1_VBUS_CONN		(1 << 3)
95 #define	 AXP2XX_IRQ1_VBUS_DISCONN	(1 << 2)
96 #define	 AXP2XX_IRQ1_VBUS_LOW		(1 << 1)
97 
98 #define	AXP2XX_IRQ2_ENABLE	0x41
99 #define	AXP2XX_IRQ2_STATUS	0x49
100 #define	 AXP2XX_IRQ2_BATT_CONN			(1 << 7)
101 #define	 AXP2XX_IRQ2_BATT_DISCONN		(1 << 6)
102 #define	 AXP2XX_IRQ2_BATT_CHARGE_ACCT_ON	(1 << 5)
103 #define	 AXP2XX_IRQ2_BATT_CHARGE_ACCT_OFF	(1 << 4)
104 #define	 AXP2XX_IRQ2_BATT_CHARGING		(1 << 3)
105 #define	 AXP2XX_IRQ2_BATT_CHARGED		(1 << 2)
106 #define	 AXP2XX_IRQ2_BATT_TEMP_OVER		(1 << 1)
107 #define	 AXP2XX_IRQ2_BATT_TEMP_LOW		(1 << 0)
108 
109 #define	AXP2XX_IRQ3_ENABLE	0x42
110 #define	AXP2XX_IRQ3_STATUS	0x4A
111 #define	 AXP2XX_IRQ3_TEMP_OVER		(1 << 7)
112 #define	 AXP2XX_IRQ3_CHARGE_CURRENT_LOW	(1 << 6)
113 #define	 AXP2XX_IRQ3_DCDC2_LOW		(1 << 4)
114 #define	 AXP2XX_IRQ3_DCDC3_LOW		(1 << 3)
115 #define	 AXP2XX_IRQ3_LDO3_LOW		(1 << 2)
116 #define	 AXP2XX_IRQ3_PEK_SHORT		(1 << 1)
117 #define	 AXP2XX_IRQ3_PEK_LONG		(1 << 0)
118 
119 #define	AXP2XX_IRQ4_ENABLE	0x43
120 #define	AXP2XX_IRQ4_STATUS	0x4B
121 #define	 AXP2XX_IRQ4_NOE_START		(1 << 7)
122 #define	 AXP2XX_IRQ4_NOE_SHUT		(1 << 6)
123 #define	 AXP2XX_IRQ4_VBUS_VALID		(1 << 5)
124 #define	 AXP2XX_IRQ4_VBUS_INVALID	(1 << 4)
125 #define	 AXP2XX_IRQ4_VBUS_SESSION	(1 << 3)
126 #define	 AXP2XX_IRQ4_VBUS_SESSION_END	(1 << 2)
127 #define	 AXP2XX_IRQ4_APS_LOW_1		(1 << 1)
128 #define	 AXP2XX_IRQ4_APS_LOW_2		(1 << 0)
129 
130 #define	AXP2XX_IRQ5_ENABLE	0x44
131 #define	AXP2XX_IRQ5_STATUS	0x4C
132 #define	 AXP2XX_IRQ5_TIMER_EXPIRE	(1 << 7)
133 #define	 AXP2XX_IRQ5_PEK_RISE_EDGE	(1 << 6)
134 #define	 AXP2XX_IRQ5_PEK_FALL_EDGE	(1 << 5)
135 #define	 AXP2XX_IRQ5_GPIO3	(1 << 3)
136 #define	 AXP2XX_IRQ5_GPIO2	(1 << 2)
137 #define	 AXP2XX_IRQ5_GPIO1	(1 << 1)
138 #define	 AXP2XX_IRQ5_GPIO0	(1 << 0)
139 
140 #define	AXP2XX_IRQ_ACK		0xff
141 
142 /* GPIOs registers */
143 #define	AXP2XX_GPIO_FUNC_MASK		0x7
144 
145 #define	AXP2XX_GPIO_FUNC_DRVLO		0x0
146 #define	AXP2XX_GPIO_FUNC_DRVHI		0x1
147 #define	AXP2XX_GPIO_FUNC_INPUT		0x2
148 
149 #define	AXP2XX_GPIO0_CTRL	0x90
150 #define	AXP2XX_GPIO1_CTRL	0x92
151 #define	AXP209_GPIO2_CTRL	0x93
152 #define	AXP2XX_GPIO_STATUS	0x94
153 
154 /* Regulators registers */
155 #define	AXP209_POWERCTL			0x12
156 #define	 AXP209_POWERCTL_LDO3		(1 << 6)
157 #define	 AXP209_POWERCTL_DCDC2		(1 << 4)
158 #define	 AXP209_POWERCTL_LDO4		(1 << 3)
159 #define	 AXP209_POWERCTL_LDO2		(1 << 2)
160 #define	 AXP209_POWERCTL_DCDC3		(1 << 1)
161 
162 #define	AXP221_POWERCTL_1		0x10
163 #define	 AXP221_POWERCTL1_ALDO2		(1 << 7)
164 #define	 AXP221_POWERCTL1_ALDO1		(1 << 6)
165 #define	 AXP221_POWERCTL1_DCDC5		(1 << 5)
166 #define	 AXP221_POWERCTL1_DCDC4		(1 << 4)
167 #define	 AXP221_POWERCTL1_DCDC3		(1 << 3)
168 #define	 AXP221_POWERCTL1_DCDC2		(1 << 2)
169 #define	 AXP221_POWERCTL1_DCDC1		(1 << 1)
170 #define	 AXP221_POWERCTL1_DC5LDO	(1 << 0)
171 
172 #define	AXP221_POWERCTL_2		0x12
173 #define	 AXP221_POWERCTL2_DC1SW		(1 << 7)
174 #define	 AXP221_POWERCTL2_DLDO4		(1 << 6)
175 #define	 AXP221_POWERCTL2_DLDO3		(1 << 5)
176 #define	 AXP221_POWERCTL2_DLDO2		(1 << 4)
177 #define	 AXP221_POWERCTL2_DLDO1		(1 << 3)
178 #define	 AXP221_POWERCTL2_ELDO3		(1 << 2)
179 #define	 AXP221_POWERCTL2_ELDO2		(1 << 1)
180 #define	 AXP221_POWERCTL2_ELDO1		(1 << 0)
181 
182 #define	AXP221_POWERCTL_3		0x14
183 #define	 AXP221_POWERCTL3_ALDO3		(1 << 7)
184 
185 #define	AXP209_REG_DCDC2_VOLTAGE	0x23
186 #define	AXP209_REG_DCDC3_VOLTAGE	0x27
187 #define	AXP209_REG_LDO24_VOLTAGE	0x28
188 #define	AXP209_REG_LDO3_VOLTAGE		0x29
189 
190 #define	AXP221_REG_DLDO1_VOLTAGE	0x15
191 #define	AXP221_REG_DLDO2_VOLTAGE	0x16
192 #define	AXP221_REG_DLDO3_VOLTAGE	0x17
193 #define	AXP221_REG_DLDO4_VOLTAGE	0x18
194 #define	AXP221_REG_ELDO1_VOLTAGE	0x19
195 #define	AXP221_REG_ELDO2_VOLTAGE	0x1A
196 #define	AXP221_REG_ELDO3_VOLTAGE	0x1B
197 #define	AXP221_REG_DC5LDO_VOLTAGE	0x1C
198 #define	AXP221_REG_DCDC1_VOLTAGE	0x21
199 #define	AXP221_REG_DCDC2_VOLTAGE	0x22
200 #define	AXP221_REG_DCDC3_VOLTAGE	0x23
201 #define	AXP221_REG_DCDC4_VOLTAGE	0x24
202 #define	AXP221_REG_DCDC5_VOLTAGE	0x25
203 #define	AXP221_REG_DCDC23_VRC		0x27
204 #define	AXP221_REG_ALDO1_VOLTAGE	0x28
205 #define	AXP221_REG_ALDO2_VOLTAGE	0x29
206 #define	AXP221_REG_ALDO3_VOLTAGE	0x2A
207 
208 
209 enum axp2xx_sensor {
210 	AXP209_ACVOLT,
211 	AXP209_ACCURRENT,
212 	AXP209_VBUSVOLT,
213 	AXP209_VBUSCURRENT,
214 	AXP2XX_TEMP,
215 	AXP2XX_BATVOLT,
216 	AXP2XX_BATCHARGECURRENT,
217 	AXP2XX_BATDISCHARGECURRENT,
218 };
219 
220 enum axp2xx_regulators {
221 	AXP209_REG_ID_DCDC2,
222 	AXP209_REG_ID_DCDC3,
223 	AXP209_REG_ID_LDO1,
224 	AXP209_REG_ID_LDO2,
225 	AXP209_REG_ID_LDO3,
226 	/* LDO4 is weird, need to find a correct way to handle it */
227 	/* AXP209_REG_ID_LDO4, */
228 	AXP209_REG_ID_LDO5,
229 	AXP221_REG_ID_DLDO1,
230 	AXP221_REG_ID_DLDO2,
231 	AXP221_REG_ID_DLDO3,
232 	AXP221_REG_ID_DLDO4,
233 	AXP221_REG_ID_ELDO1,
234 	AXP221_REG_ID_ELDO2,
235 	AXP221_REG_ID_ELDO3,
236 	AXP221_REG_ID_DC5LDO,
237 	AXP221_REG_ID_DCDC1,
238 	AXP221_REG_ID_DCDC2,
239 	AXP221_REG_ID_DCDC3,
240 	AXP221_REG_ID_DCDC4,
241 	AXP221_REG_ID_DCDC5,
242 	AXP221_REG_ID_ALDO1,
243 	AXP221_REG_ID_ALDO2,
244 	AXP221_REG_ID_ALDO3,
245 	AXP221_REG_ID_DC1SW,
246 };
247 
248 #endif /* _AXP209REG_H_ */
249