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