Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/arm/allwinner/axp209reg.h
39507 views
1
/*-
2
* Copyright (c) 2016 Emmanuel Vadot <[email protected]>
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
25
#ifndef _AXP209REG_H_
26
#define _AXP209REG_H_
27
28
/* Power State Register */
29
#define AXP2XX_PSR 0x00
30
#define AXP2XX_PSR_ACIN 0x80
31
#define AXP2XX_PSR_ACIN_SHIFT 7
32
#define AXP2XX_PSR_VBUS 0x20
33
#define AXP2XX_PSR_VBUS_SHIFT 5
34
35
/* Shutdown and battery control */
36
#define AXP2XX_SHUTBAT 0x32
37
#define AXP2XX_SHUTBAT_SHUTDOWN 0x80
38
39
/* Voltage/Current Monitor */
40
#define AXP209_ACIN_VOLTAGE 0x56
41
#define AXP209_ACIN_CURRENT 0x58
42
#define AXP209_VBUS_VOLTAGE 0x5A
43
#define AXP209_VBUS_CURRENT 0x5C
44
#define AXP2XX_BAT_VOLTAGE 0x78
45
#define AXP2XX_BAT_CHARGE_CURRENT 0x7A
46
#define AXP2XX_BAT_DISCHARGE_CURRENT 0x7C
47
48
#define AXP209_VOLT_STEP 1700
49
#define AXP2XX_BATVOLT_STEP 1100
50
#define AXP209_ACCURRENT_STEP 625
51
#define AXP209_VBUSCURRENT_STEP 375
52
#define AXP2XX_BATCURRENT_STEP 500
53
54
/* Temperature monitor */
55
#define AXP209_TEMPMON 0x5e
56
#define AXP209_TEMPMON_MIN 1447 /* -144.7C */
57
#define AXP221_TEMPMON_MIN 2437 /* -243.7C */
58
59
#define AXP221_TEMPMON 0x56
60
61
/* Sensors conversion macros */
62
#define AXP209_SENSOR_H(a) ((a) << 4)
63
#define AXP209_SENSOR_L(a) ((a) & 0xf)
64
#define AXP209_SENSOR_BAT_H(a) ((a) << 5)
65
#define AXP209_SENSOR_BAT_L(a) ((a) & 0x1f)
66
67
#define AXP209_0C_TO_K 2732
68
69
/* ADC Sensors */
70
#define AXP2XX_ADC_ENABLE1 0x82
71
#define AXP209_ADC_ENABLE2 0x83
72
73
#define AXP2XX_ADC1_BATVOLT (1 << 7)
74
#define AXP2XX_ADC1_BATCURRENT (1 << 6)
75
#define AXP209_ADC1_ACVOLT (1 << 5)
76
#define AXP221_ADC1_TEMP (1 << 5)
77
#define AXP209_ADC1_ACCURRENT (1 << 4)
78
#define AXP209_ADC1_VBUSVOLT (1 << 3)
79
#define AXP209_ADC1_VBUSCURRENT (1 << 2)
80
#define AXP221_ADC1_TS_PIN (1 << 0)
81
82
#define AXP209_ADC2_TEMP (1 << 7)
83
84
/* Interrupt related registers */
85
#define AXP2XX_IRQ1_ENABLE 0x40
86
#define AXP2XX_IRQ1_STATUS 0x48
87
#define AXP2XX_IRQ1_AC_OVERVOLT (1 << 7)
88
#define AXP2XX_IRQ1_AC_CONN (1 << 6)
89
#define AXP2XX_IRQ1_AC_DISCONN (1 << 5)
90
#define AXP2XX_IRQ1_VBUS_OVERVOLT (1 << 4)
91
#define AXP2XX_IRQ1_VBUS_CONN (1 << 3)
92
#define AXP2XX_IRQ1_VBUS_DISCONN (1 << 2)
93
#define AXP2XX_IRQ1_VBUS_LOW (1 << 1)
94
95
#define AXP2XX_IRQ2_ENABLE 0x41
96
#define AXP2XX_IRQ2_STATUS 0x49
97
#define AXP2XX_IRQ2_BATT_CONN (1 << 7)
98
#define AXP2XX_IRQ2_BATT_DISCONN (1 << 6)
99
#define AXP2XX_IRQ2_BATT_CHARGE_ACCT_ON (1 << 5)
100
#define AXP2XX_IRQ2_BATT_CHARGE_ACCT_OFF (1 << 4)
101
#define AXP2XX_IRQ2_BATT_CHARGING (1 << 3)
102
#define AXP2XX_IRQ2_BATT_CHARGED (1 << 2)
103
#define AXP2XX_IRQ2_BATT_TEMP_OVER (1 << 1)
104
#define AXP2XX_IRQ2_BATT_TEMP_LOW (1 << 0)
105
106
#define AXP2XX_IRQ3_ENABLE 0x42
107
#define AXP2XX_IRQ3_STATUS 0x4A
108
#define AXP2XX_IRQ3_TEMP_OVER (1 << 7)
109
#define AXP2XX_IRQ3_CHARGE_CURRENT_LOW (1 << 6)
110
#define AXP2XX_IRQ3_DCDC2_LOW (1 << 4)
111
#define AXP2XX_IRQ3_DCDC3_LOW (1 << 3)
112
#define AXP2XX_IRQ3_LDO3_LOW (1 << 2)
113
#define AXP2XX_IRQ3_PEK_SHORT (1 << 1)
114
#define AXP2XX_IRQ3_PEK_LONG (1 << 0)
115
116
#define AXP2XX_IRQ4_ENABLE 0x43
117
#define AXP2XX_IRQ4_STATUS 0x4B
118
#define AXP2XX_IRQ4_NOE_START (1 << 7)
119
#define AXP2XX_IRQ4_NOE_SHUT (1 << 6)
120
#define AXP2XX_IRQ4_VBUS_VALID (1 << 5)
121
#define AXP2XX_IRQ4_VBUS_INVALID (1 << 4)
122
#define AXP2XX_IRQ4_VBUS_SESSION (1 << 3)
123
#define AXP2XX_IRQ4_VBUS_SESSION_END (1 << 2)
124
#define AXP2XX_IRQ4_APS_LOW_1 (1 << 1)
125
#define AXP2XX_IRQ4_APS_LOW_2 (1 << 0)
126
127
#define AXP2XX_IRQ5_ENABLE 0x44
128
#define AXP2XX_IRQ5_STATUS 0x4C
129
#define AXP2XX_IRQ5_TIMER_EXPIRE (1 << 7)
130
#define AXP2XX_IRQ5_PEK_RISE_EDGE (1 << 6)
131
#define AXP2XX_IRQ5_PEK_FALL_EDGE (1 << 5)
132
#define AXP2XX_IRQ5_GPIO3 (1 << 3)
133
#define AXP2XX_IRQ5_GPIO2 (1 << 2)
134
#define AXP2XX_IRQ5_GPIO1 (1 << 1)
135
#define AXP2XX_IRQ5_GPIO0 (1 << 0)
136
137
#define AXP2XX_IRQ_ACK 0xff
138
139
/* GPIOs registers */
140
#define AXP2XX_GPIO_FUNC_MASK 0x7
141
142
#define AXP2XX_GPIO_FUNC_DRVLO 0x0
143
#define AXP2XX_GPIO_FUNC_DRVHI 0x1
144
#define AXP2XX_GPIO_FUNC_INPUT 0x2
145
146
#define AXP2XX_GPIO0_CTRL 0x90
147
#define AXP2XX_GPIO1_CTRL 0x92
148
#define AXP209_GPIO2_CTRL 0x93
149
#define AXP2XX_GPIO_STATUS 0x94
150
151
/* Regulators registers */
152
#define AXP209_POWERCTL 0x12
153
#define AXP209_POWERCTL_LDO3 (1 << 6)
154
#define AXP209_POWERCTL_DCDC2 (1 << 4)
155
#define AXP209_POWERCTL_LDO4 (1 << 3)
156
#define AXP209_POWERCTL_LDO2 (1 << 2)
157
#define AXP209_POWERCTL_DCDC3 (1 << 1)
158
159
#define AXP221_POWERCTL_1 0x10
160
#define AXP221_POWERCTL1_ALDO2 (1 << 7)
161
#define AXP221_POWERCTL1_ALDO1 (1 << 6)
162
#define AXP221_POWERCTL1_DCDC5 (1 << 5)
163
#define AXP221_POWERCTL1_DCDC4 (1 << 4)
164
#define AXP221_POWERCTL1_DCDC3 (1 << 3)
165
#define AXP221_POWERCTL1_DCDC2 (1 << 2)
166
#define AXP221_POWERCTL1_DCDC1 (1 << 1)
167
#define AXP221_POWERCTL1_DC5LDO (1 << 0)
168
169
#define AXP221_POWERCTL_2 0x12
170
#define AXP221_POWERCTL2_DC1SW (1 << 7)
171
#define AXP221_POWERCTL2_DLDO4 (1 << 6)
172
#define AXP221_POWERCTL2_DLDO3 (1 << 5)
173
#define AXP221_POWERCTL2_DLDO2 (1 << 4)
174
#define AXP221_POWERCTL2_DLDO1 (1 << 3)
175
#define AXP221_POWERCTL2_ELDO3 (1 << 2)
176
#define AXP221_POWERCTL2_ELDO2 (1 << 1)
177
#define AXP221_POWERCTL2_ELDO1 (1 << 0)
178
179
#define AXP221_POWERCTL_3 0x14
180
#define AXP221_POWERCTL3_ALDO3 (1 << 7)
181
182
#define AXP209_REG_DCDC2_VOLTAGE 0x23
183
#define AXP209_REG_DCDC3_VOLTAGE 0x27
184
#define AXP209_REG_LDO24_VOLTAGE 0x28
185
#define AXP209_REG_LDO3_VOLTAGE 0x29
186
187
#define AXP221_REG_DLDO1_VOLTAGE 0x15
188
#define AXP221_REG_DLDO2_VOLTAGE 0x16
189
#define AXP221_REG_DLDO3_VOLTAGE 0x17
190
#define AXP221_REG_DLDO4_VOLTAGE 0x18
191
#define AXP221_REG_ELDO1_VOLTAGE 0x19
192
#define AXP221_REG_ELDO2_VOLTAGE 0x1A
193
#define AXP221_REG_ELDO3_VOLTAGE 0x1B
194
#define AXP221_REG_DC5LDO_VOLTAGE 0x1C
195
#define AXP221_REG_DCDC1_VOLTAGE 0x21
196
#define AXP221_REG_DCDC2_VOLTAGE 0x22
197
#define AXP221_REG_DCDC3_VOLTAGE 0x23
198
#define AXP221_REG_DCDC4_VOLTAGE 0x24
199
#define AXP221_REG_DCDC5_VOLTAGE 0x25
200
#define AXP221_REG_DCDC23_VRC 0x27
201
#define AXP221_REG_ALDO1_VOLTAGE 0x28
202
#define AXP221_REG_ALDO2_VOLTAGE 0x29
203
#define AXP221_REG_ALDO3_VOLTAGE 0x2A
204
205
enum axp2xx_sensor {
206
AXP209_ACVOLT,
207
AXP209_ACCURRENT,
208
AXP209_VBUSVOLT,
209
AXP209_VBUSCURRENT,
210
AXP2XX_TEMP,
211
AXP2XX_BATVOLT,
212
AXP2XX_BATCHARGECURRENT,
213
AXP2XX_BATDISCHARGECURRENT,
214
};
215
216
enum axp2xx_regulators {
217
AXP209_REG_ID_DCDC2,
218
AXP209_REG_ID_DCDC3,
219
AXP209_REG_ID_LDO1,
220
AXP209_REG_ID_LDO2,
221
AXP209_REG_ID_LDO3,
222
/* LDO4 is weird, need to find a correct way to handle it */
223
/* AXP209_REG_ID_LDO4, */
224
AXP209_REG_ID_LDO5,
225
AXP221_REG_ID_DLDO1,
226
AXP221_REG_ID_DLDO2,
227
AXP221_REG_ID_DLDO3,
228
AXP221_REG_ID_DLDO4,
229
AXP221_REG_ID_ELDO1,
230
AXP221_REG_ID_ELDO2,
231
AXP221_REG_ID_ELDO3,
232
AXP221_REG_ID_DC5LDO,
233
AXP221_REG_ID_DCDC1,
234
AXP221_REG_ID_DCDC2,
235
AXP221_REG_ID_DCDC3,
236
AXP221_REG_ID_DCDC4,
237
AXP221_REG_ID_DCDC5,
238
AXP221_REG_ID_ALDO1,
239
AXP221_REG_ID_ALDO2,
240
AXP221_REG_ID_ALDO3,
241
AXP221_REG_ID_DC1SW,
242
};
243
244
#endif /* _AXP209REG_H_ */
245
246