ingenic_regs.h revision 1.14 1 1.14 macallan /* $NetBSD: ingenic_regs.h,v 1.14 2015/04/21 19:56:01 macallan Exp $ */
2 1.1 macallan
3 1.1 macallan /*-
4 1.1 macallan * Copyright (c) 2014 Michael Lorenz
5 1.1 macallan * All rights reserved.
6 1.1 macallan *
7 1.1 macallan * Redistribution and use in source and binary forms, with or without
8 1.1 macallan * modification, are permitted provided that the following conditions
9 1.1 macallan * are met:
10 1.1 macallan * 1. Redistributions of source code must retain the above copyright
11 1.1 macallan * notice, this list of conditions and the following disclaimer.
12 1.1 macallan * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 macallan * notice, this list of conditions and the following disclaimer in the
14 1.1 macallan * documentation and/or other materials provided with the distribution.
15 1.1 macallan *
16 1.1 macallan * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.1 macallan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.1 macallan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.1 macallan * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.1 macallan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1 macallan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1 macallan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1 macallan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1 macallan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.1 macallan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 macallan * POSSIBILITY OF SUCH DAMAGE.
27 1.1 macallan */
28 1.1 macallan
29 1.1 macallan #ifndef INGENIC_REGS_H
30 1.1 macallan #define INGENIC_REGS_H
31 1.1 macallan
32 1.13 macallan /* for wbflush() */
33 1.13 macallan #include <mips/locore.h>
34 1.13 macallan
35 1.1 macallan /* UARTs, mostly 16550 compatible with 32bit spaced registers */
36 1.1 macallan #define JZ_UART0 0x10030000
37 1.1 macallan #define JZ_UART1 0x10031000
38 1.1 macallan #define JZ_UART2 0x10032000
39 1.1 macallan #define JZ_UART3 0x10033000
40 1.1 macallan #define JZ_UART4 0x10034000
41 1.1 macallan
42 1.13 macallan /* LCD controller base addresses, registers are in jzfb_regs.h */
43 1.13 macallan #define JZ_LCDC0_BASE 0x13050000
44 1.13 macallan #define JZ_LCDC1_BASE 0x130a0000
45 1.13 macallan
46 1.1 macallan /* watchdog */
47 1.1 macallan #define JZ_WDOG_TDR 0x10002000 /* compare */
48 1.1 macallan #define JZ_WDOG_TCER 0x10002004
49 1.1 macallan #define TCER_ENABLE 0x01 /* enable counter */
50 1.1 macallan #define JZ_WDOG_TCNT 0x10002008 /* 16bit up count */
51 1.1 macallan #define JZ_WDOG_TCSR 0x1000200c
52 1.1 macallan #define TCSR_PCK_EN 0x01 /* PCLK */
53 1.1 macallan #define TCSR_RTC_EN 0x02 /* RTCCLK - 32.768kHz */
54 1.2 macallan #define TCSR_EXT_EN 0x04 /* EXTCLK - 48MHz */
55 1.1 macallan #define TCSR_PRESCALE_M 0x38
56 1.1 macallan #define TCSR_DIV_1 0x00
57 1.1 macallan #define TCSR_DIV_4 0x08
58 1.1 macallan #define TCSR_DIV_16 0x10
59 1.1 macallan #define TCSR_DIV_64 0x18
60 1.1 macallan #define TCSR_DIV_256 0x20
61 1.1 macallan #define TCSR_DIV_1024 0x28
62 1.1 macallan
63 1.1 macallan /* timers and PWMs */
64 1.1 macallan #define JZ_TC_TER 0x10002010 /* TC enable reg, ro */
65 1.1 macallan #define JZ_TC_TESR 0x10002014 /* TC enable set reg. */
66 1.1 macallan #define TESR_TCST0 0x0001 /* enable counter 0 */
67 1.1 macallan #define TESR_TCST1 0x0002 /* enable counter 1 */
68 1.1 macallan #define TESR_TCST2 0x0004 /* enable counter 2 */
69 1.1 macallan #define TESR_TCST3 0x0008 /* enable counter 3 */
70 1.1 macallan #define TESR_TCST4 0x0010 /* enable counter 4 */
71 1.2 macallan #define TESR_TCST5 0x0020 /* enable counter 5 */
72 1.2 macallan #define TESR_TCST6 0x0040 /* enable counter 6 */
73 1.2 macallan #define TESR_TCST7 0x0080 /* enable counter 7 */
74 1.1 macallan #define TESR_OST 0x8000 /* enable OST */
75 1.1 macallan #define JZ_TC_TECR 0x10002018 /* TC enable clear reg. */
76 1.2 macallan #define JZ_TC_TFR 0x10002020
77 1.2 macallan #define TFR_FFLAG0 0x00000001 /* channel 0 */
78 1.2 macallan #define TFR_FFLAG1 0x00000002 /* channel 1 */
79 1.2 macallan #define TFR_FFLAG2 0x00000004 /* channel 2 */
80 1.2 macallan #define TFR_FFLAG3 0x00000008 /* channel 3 */
81 1.2 macallan #define TFR_FFLAG4 0x00000010 /* channel 4 */
82 1.2 macallan #define TFR_FFLAG5 0x00000020 /* channel 5 */
83 1.2 macallan #define TFR_FFLAG6 0x00000040 /* channel 6 */
84 1.2 macallan #define TFR_FFLAG7 0x00000080 /* channel 7 */
85 1.2 macallan #define TFR_OSTFLAG 0x00008000 /* OS timer */
86 1.2 macallan #define JZ_TC_TFSR 0x10002024 /* timer flag set */
87 1.2 macallan #define JZ_TC_TFCR 0x10002028 /* timer flag clear */
88 1.2 macallan #define JZ_TC_TMR 0x10002030 /* timer flag mask */
89 1.2 macallan #define JZ_TC_TMSR 0x10002034 /* timer flag mask set */
90 1.2 macallan #define JZ_TC_TMCR 0x10002038 /* timer flag mask clear*/
91 1.2 macallan
92 1.2 macallan #define JZ_TC_TDFR(n) (0x10002040 + (n * 0x10)) /* FULL compare */
93 1.2 macallan #define JZ_TC_TDHR(n) (0x10002044 + (n * 0x10)) /* HALF compare */
94 1.2 macallan #define JZ_TC_TCNT(n) (0x10002048 + (n * 0x10)) /* count */
95 1.2 macallan
96 1.2 macallan #define JZ_TC_TCSR(n) (0x1000204c + (n * 0x10))
97 1.2 macallan /* same bits as in JZ_WDOG_TCSR */
98 1.1 macallan
99 1.1 macallan /* operating system timer */
100 1.1 macallan #define JZ_OST_DATA 0x100020e0 /* compare */
101 1.1 macallan #define JZ_OST_CNT_LO 0x100020e4
102 1.1 macallan #define JZ_OST_CNT_HI 0x100020e8
103 1.1 macallan #define JZ_OST_CTRL 0x100020ec
104 1.1 macallan #define OSTC_PCK_EN 0x0001 /* use PCLK */
105 1.1 macallan #define OSTC_RTC_EN 0x0002 /* use RTCCLK */
106 1.1 macallan #define OSTC_EXT_EN 0x0004 /* use EXTCLK */
107 1.1 macallan #define OSTC_PRESCALE_M 0x0038
108 1.1 macallan #define OSTC_DIV_1 0x0000
109 1.1 macallan #define OSTC_DIV_4 0x0008
110 1.1 macallan #define OSTC_DIV_16 0x0010
111 1.1 macallan #define OSTC_DIV_64 0x0018
112 1.1 macallan #define OSTC_DIV_256 0x0020
113 1.1 macallan #define OSTC_DIV_1024 0x0028
114 1.1 macallan #define OSTC_SHUTDOWN 0x0200
115 1.1 macallan #define OSTC_MODE 0x8000 /* 0 - reset to 0 when = OST_DATA */
116 1.1 macallan #define JZ_OST_CNT_U32 0x100020fc /* copy of CNT_HI when reading CNT_LO */
117 1.1 macallan
118 1.1 macallan static inline void
119 1.1 macallan writereg(uint32_t reg, uint32_t val)
120 1.1 macallan {
121 1.1 macallan *(int32_t *)MIPS_PHYS_TO_KSEG1(reg) = val;
122 1.1 macallan wbflush();
123 1.1 macallan }
124 1.1 macallan
125 1.1 macallan static inline uint32_t
126 1.1 macallan readreg(uint32_t reg)
127 1.1 macallan {
128 1.1 macallan wbflush();
129 1.1 macallan return *(int32_t *)MIPS_PHYS_TO_KSEG1(reg);
130 1.1 macallan }
131 1.1 macallan
132 1.2 macallan /* extra CP0 registers */
133 1.2 macallan static inline uint32_t
134 1.2 macallan MFC0(uint32_t r, uint32_t s)
135 1.2 macallan {
136 1.2 macallan uint32_t ret = 0x12345678;
137 1.2 macallan
138 1.2 macallan __asm volatile("mfc0 %0, $%1, %2; nop;" : "=r"(ret) : "i"(r), "i"(s));
139 1.2 macallan return ret;
140 1.2 macallan }
141 1.2 macallan
142 1.2 macallan #define MTC0(v, r, s) __asm volatile("mtc0 %0, $%1, %2; nop;" :: "r"(v), "i"(r), "i"(s))
143 1.2 macallan
144 1.2 macallan #define CP0_CORE_CTRL 12 /* select 2 */
145 1.2 macallan #define CC_SW_RST0 1 /* reset core 0 */
146 1.2 macallan #define CC_SW_RST1 2 /* reset core 1 */
147 1.2 macallan #define CC_RPC0 0x100 /* dedicater reset entry core 0 */
148 1.2 macallan #define CC_RPC1 0x200 /* -- || -- core 1 */
149 1.2 macallan #define CC_SLEEP0M 0x10000 /* mask sleep core 0 */
150 1.2 macallan #define CC_SLEEP1M 0x20000 /* mask sleep core 1 */
151 1.2 macallan
152 1.2 macallan /* cores status, 12 select 3 */
153 1.2 macallan #define CS_MIRQ0_P 0x00001 /* mailbox IRQ for 0 pending */
154 1.2 macallan #define CS_MIRQ1_P 0x00002 /* || core 1 */
155 1.2 macallan #define CS_IRQ0_P 0x00100 /* peripheral IRQ for core 0 */
156 1.2 macallan #define CS_IRQ1_P 0x00200 /* || core 1 */
157 1.2 macallan #define CS_SLEEP0 0x10000 /* core 0 sleeping */
158 1.2 macallan #define CS_SLEEP1 0x20000 /* core 1 sleeping */
159 1.2 macallan
160 1.2 macallan /* cores reset entry & IRQ masks - 12 select 4 */
161 1.2 macallan #define REIM_MIRQ0_M 0x00001 /* allow mailbox IRQ for core 0 */
162 1.2 macallan #define REIM_MIRQ1_M 0x00002 /* allow mailbox IRQ for core 1 */
163 1.2 macallan #define REIM_IRQ0_M 0x00100 /* allow peripheral IRQ for core 0 */
164 1.2 macallan #define REIM_IRQ1_M 0x00200 /* allow peripheral IRQ for core 1 */
165 1.2 macallan #define REIM_ENTRY_M 0xffff0000 /* reset exception entry if RPCn=1 */
166 1.2 macallan
167 1.2 macallan #define CP0_CORE_MBOX 20 /* select 0 for core 0, 1 for 1 */
168 1.2 macallan
169 1.3 macallan /* power management */
170 1.12 macallan #define JZ_CPCCR 0x10000000 /* Clock Control Register */
171 1.12 macallan #define JZ_PDIV_M 0x000f0000 /* PCLK divider mask */
172 1.12 macallan #define JZ_PDIV_S 16 /* PCLK divider shift */
173 1.12 macallan #define JZ_CPMPCR 0x00000014 /* MPLL */
174 1.12 macallan #define JZ_PLLM_S 19 /* PLL multiplier shift */
175 1.12 macallan #define JZ_PLLM_M 0xfff80000 /* PLL multiplier mask */
176 1.12 macallan #define JZ_PLLN_S 13 /* PLL divider shift */
177 1.12 macallan #define JZ_PLLN_M 0x0007e000 /* PLL divider mask */
178 1.12 macallan #define JZ_PLLP_S 9 /* PLL postdivider shift */
179 1.12 macallan #define JZ_PLLP_M 0x00001700 /* PLL postdivider mask */
180 1.12 macallan #define JZ_PLLON 0x00000010 /* PLL is on and stable */
181 1.12 macallan #define JZ_PLLBP 0x00000002 /* PLL bypass */
182 1.12 macallan #define JZ_PLLEN 0x00000001 /* PLL enable */
183 1.3 macallan #define JZ_CLKGR0 0x10000020 /* CLocK Gating Registers */
184 1.14 macallan #define CLK_OTG0 (1 << 2)
185 1.14 macallan #define CLK_SMB0 (1 << 5)
186 1.14 macallan #define CLK_SMB1 (1 << 6)
187 1.14 macallan #define CLK_UHC (1 << 24)
188 1.14 macallan #define CLK_SMB2 (1 << 25)
189 1.14 macallan #define CLK_LCD (1 << 28)
190 1.3 macallan #define JZ_OPCR 0x10000024 /* Oscillator Power Control Reg. */
191 1.5 macallan #define OPCR_IDLE_DIS 0x80000000 /* don't stop CPU clk on idle */
192 1.5 macallan #define OPCR_GPU_CLK_ST 0x40000000 /* stop GPU clock */
193 1.5 macallan #define OPCR_L2CM_M 0x0c000000
194 1.5 macallan #define OPCR_L2CM_ON 0x00000000 /* L2 stays on in sleep */
195 1.5 macallan #define OPCR_L2CM_RET 0x04000000 /* L2 retention mode in sleep */
196 1.5 macallan #define OPCR_L2CM_OFF 0x08000000 /* L2 powers down in sleep */
197 1.5 macallan #define OPCR_SPENDN0 0x00000080 /* OTG port forced down */
198 1.5 macallan #define OPCR_SPENDN1 0x00000040 /* UHC port forced down */
199 1.5 macallan #define OPCR_BUS_MODE 0x00000020 /* 1 - bursts */
200 1.5 macallan #define OPCR_O1SE 0x00000010 /* EXTCLK on in sleep */
201 1.5 macallan #define OPCR_PD 0x00000008 /* P0 down in sleep */
202 1.5 macallan #define OPCR_ERCS 0x00000004 /* 1 RTCCLK, 0 EXTCLK/512 */
203 1.5 macallan #define OPCR_CPU_MODE 0x00000002 /* 1 access 'accelerated' */
204 1.5 macallan #define OPCR_OSE 0x00000001 /* disable EXTCLK */
205 1.3 macallan #define JZ_CLKGR1 0x10000028 /* CLocK Gating Registers */
206 1.14 macallan #define CLK_SMB3 (1 << 0)
207 1.14 macallan #define CLK_OTG1 (1 << 8)
208 1.14 macallan #define CLK_HDMI (1 << 9)
209 1.14 macallan #define CLK_AHB_MON (1 << 11)
210 1.14 macallan #define CLK_SMB4 (1 << 12)
211 1.14 macallan
212 1.3 macallan #define JZ_USBPCR 0x1000003c
213 1.5 macallan #define PCR_USB_MODE 0x80000000 /* 1 - otg */
214 1.5 macallan #define PCR_AVLD_REG 0x40000000
215 1.5 macallan #define PCR_IDPULLUP_MASK 0x30000000
216 1.5 macallan #define PCR_INCR_MASK 0x08000000
217 1.5 macallan #define PCR_TCRISETUNE 0x04000000
218 1.5 macallan #define PCR_COMMONONN 0x02000000
219 1.5 macallan #define PCR_VBUSVLDEXT 0x01000000
220 1.5 macallan #define PCR_VBUSVLDEXTSEL 0x00800000
221 1.5 macallan #define PCR_POR 0x00400000
222 1.5 macallan #define PCR_SIDDQ 0x00200000
223 1.5 macallan #define PCR_OTG_DISABLE 0x00100000
224 1.5 macallan #define PCR_COMPDISTN_M 0x000e0000
225 1.5 macallan #define PCR_OTGTUNE 0x0001c000
226 1.5 macallan #define PCR_SQRXTUNE 0x00003800
227 1.5 macallan #define PCR_TXFSLSTUNE 0x00000780
228 1.5 macallan #define PCR_TXPREEMPHTUNE 0x00000040
229 1.5 macallan #define PCR_TXHSXVTUNE 0x00000030
230 1.5 macallan #define PCR_TXVREFTUNE 0x0000000f
231 1.6 macallan #define JZ_USBRDT 0x10000040 /* Reset Detect Timer Register */
232 1.3 macallan #define JZ_USBPCR1 0x10000048
233 1.3 macallan #define PCR_SYNOPSYS 0x10000000 /* Mentor mode otherwise */
234 1.3 macallan #define PCR_REFCLK_CORE 0x0c000000
235 1.3 macallan #define PCR_REFCLK_XO25 0x04000000
236 1.3 macallan #define PCR_REFCLK_CO 0x00000000
237 1.3 macallan #define PCR_CLK_M 0x03000000 /* clock */
238 1.3 macallan #define PCR_CLK_192 0x03000000 /* 19.2MHz */
239 1.3 macallan #define PCR_CLK_48 0x02000000 /* 48MHz */
240 1.3 macallan #define PCR_CLK_24 0x01000000 /* 24MHz */
241 1.3 macallan #define PCR_CLK_12 0x00000000 /* 12MHz */
242 1.3 macallan #define PCR_DMPD1 0x00800000 /* pull down D- on port 1 */
243 1.3 macallan #define PCR_DPPD1 0x00400000 /* pull down D+ on port 1 */
244 1.3 macallan #define PCR_PORT0_RST 0x00200000 /* port 0 reset */
245 1.3 macallan #define PCR_PORT1_RST 0x00100000 /* port 1 reset */
246 1.3 macallan #define PCR_WORD_I_F0 0x00080000 /* 1: 16bit/30M, 8/60 otherw. */
247 1.3 macallan #define PCR_WORD_I_F1 0x00040000 /* same for port 1 */
248 1.3 macallan #define PCR_COMPDISTUNE 0x00038000 /* disconnect threshold */
249 1.3 macallan #define PCR_SQRXTUNE1 0x00007000 /* squelch threshold */
250 1.3 macallan #define PCR_TXFSLSTUNE1 0x00000f00 /* FS/LS impedance adj. */
251 1.3 macallan #define PCR_TXPREEMPH 0x00000080 /* HS transm. pre-emphasis */
252 1.3 macallan #define PCR_TXHSXVTUNE1 0x00000060 /* dp/dm voltage adj. */
253 1.3 macallan #define PCR_TXVREFTUNE1 0x00000017 /* HS DC voltage adj. */
254 1.8 macallan #define PCR_TXRISETUNE1 0x00000001 /* rise/fall wave adj. */
255 1.6 macallan
256 1.6 macallan #define JZ_UHCCDR 0x1000006c /* UHC Clock Divider Register */
257 1.3 macallan #define JZ_SPCR0 0x100000b8 /* SRAM Power Control Registers */
258 1.3 macallan #define JZ_SPCR1 0x100000bc
259 1.3 macallan #define JZ_SRBC 0x100000c4 /* Soft Reset & Bus Control */
260 1.3 macallan
261 1.2 macallan /* interrupt controller */
262 1.2 macallan #define JZ_ICSR0 0x10001000 /* raw IRQ line status */
263 1.2 macallan #define JZ_ICMR0 0x10001004 /* IRQ mask, 1 masks IRQ */
264 1.2 macallan #define JZ_ICMSR0 0x10001008 /* sets bits in mask register */
265 1.9 macallan #define JZ_ICMCR0 0x1000100c /* clears bits in mask register */
266 1.2 macallan #define JZ_ICPR0 0x10001010 /* line status after masking */
267 1.2 macallan
268 1.2 macallan #define JZ_ICSR1 0x10001020 /* raw IRQ line status */
269 1.2 macallan #define JZ_ICMR1 0x10001024 /* IRQ mask, 1 masks IRQ */
270 1.2 macallan #define JZ_ICMSR1 0x10001028 /* sets bits in mask register */
271 1.2 macallan #define JZ_ICMCR1 0x1000102c /* clears bits in maks register */
272 1.2 macallan #define JZ_ICPR1 0x10001030 /* line status after masking */
273 1.2 macallan
274 1.2 macallan #define JZ_DSR0 0x10001034 /* source for PDMA */
275 1.2 macallan #define JZ_DMR0 0x10001038 /* mask for PDMA */
276 1.2 macallan #define JZ_DPR0 0x1000103c /* pending for PDMA */
277 1.2 macallan
278 1.2 macallan #define JZ_DSR1 0x10001040 /* source for PDMA */
279 1.2 macallan #define JZ_DMR1 0x10001044 /* mask for PDMA */
280 1.2 macallan #define JZ_DPR1 0x10001048 /* pending for PDMA */
281 1.2 macallan
282 1.7 macallan /* memory controller */
283 1.7 macallan #define JZ_DMMAP0 0x13010024
284 1.7 macallan #define JZ_DMMAP1 0x13010028
285 1.7 macallan #define DMMAP_BASE 0x0000ff00 /* base PADDR of memory chunk */
286 1.7 macallan #define DMMAP_MASK 0x000000ff /* mask which bits of PADDR are
287 1.7 macallan * constant */
288 1.8 macallan /* USB controllers */
289 1.8 macallan #define JZ_EHCI_BASE 0x13490000
290 1.8 macallan #define JZ_OHCI_BASE 0x134a0000
291 1.8 macallan #define JZ_DWC2_BASE 0x13500000
292 1.8 macallan
293 1.8 macallan /* Ethernet */
294 1.8 macallan #define JZ_DME_BASE 0x16000000
295 1.9 macallan #define JZ_DME_IO 0
296 1.9 macallan #define JZ_DME_DATA 2
297 1.7 macallan
298 1.9 macallan /* GPIO */
299 1.9 macallan #define JZ_GPIO_A_BASE 0x10010000
300 1.9 macallan #define JZ_GPIO_B_BASE 0x10010100
301 1.9 macallan #define JZ_GPIO_C_BASE 0x10010200
302 1.9 macallan #define JZ_GPIO_D_BASE 0x10010300
303 1.9 macallan #define JZ_GPIO_E_BASE 0x10010400
304 1.9 macallan #define JZ_GPIO_F_BASE 0x10010500
305 1.9 macallan
306 1.9 macallan /* GPIO registers per port */
307 1.9 macallan #define JZ_GPIO_PIN 0x00000000 /* pin level register */
308 1.9 macallan /* 0 - normal gpio, 1 - interrupt */
309 1.9 macallan #define JZ_GPIO_INT 0x00000010 /* interrupt register */
310 1.9 macallan #define JZ_GPIO_INTS 0x00000014 /* interrupt set register */
311 1.9 macallan #define JZ_GPIO_INTC 0x00000018 /* interrupt clear register */
312 1.9 macallan /*
313 1.9 macallan * INT == 1: 1 disables interrupt
314 1.9 macallan * INT == 0: device select, see below
315 1.9 macallan */
316 1.9 macallan #define JZ_GPIO_MASK 0x00000020 /* port mask register */
317 1.9 macallan #define JZ_GPIO_MASKS 0x00000024 /* port mask set register */
318 1.9 macallan #define JZ_GPIO_MASKC 0x00000028 /* port mask clear register */
319 1.9 macallan /*
320 1.9 macallan * INT == 1: 0 - level triggered, 1 - edge triggered
321 1.9 macallan * INT == 0: 0 - device select, see below
322 1.9 macallan */
323 1.9 macallan #define JZ_GPIO_PAT1 0x00000030 /* pattern 1 register */
324 1.9 macallan #define JZ_GPIO_PAT1S 0x00000034 /* pattern 1 set register */
325 1.9 macallan #define JZ_GPIO_PAT1C 0x00000038 /* pattern 1 clear register */
326 1.9 macallan /*
327 1.9 macallan * INT == 1:
328 1.9 macallan * PAT1 == 0: 0 - trigger on low, 1 - trigger on high
329 1.9 macallan * PAT1 == 1: 0 - trigger on falling edge, 1 - trigger on rising edge
330 1.9 macallan * INT == 0:
331 1.9 macallan * MASK == 0:
332 1.9 macallan * PAT1 == 0: 0 - device 0, 1 - device 1
333 1.9 macallan * PAT1 == 1: 0 - device 2, 1 - device 3
334 1.9 macallan * MASK == 1:
335 1.9 macallan * PAT1 == 0: set gpio output
336 1.9 macallan * PAT1 == 1: pin is input
337 1.9 macallan */
338 1.9 macallan #define JZ_GPIO_PAT0 0x00000040 /* pattern 0 register */
339 1.9 macallan #define JZ_GPIO_PAT0S 0x00000044 /* pattern 0 set register */
340 1.9 macallan #define JZ_GPIO_PAT0C 0x00000048 /* pattern 0 clear register */
341 1.9 macallan /* 1 - interrupt happened */
342 1.9 macallan #define JZ_GPIO_FLAG 0x00000050 /* flag register */
343 1.9 macallan #define JZ_GPIO_FLAGC 0x00000058 /* flag clear register */
344 1.9 macallan /* 1 - disable pull up/down resistors */
345 1.9 macallan #define JZ_GPIO_DPULL 0x00000070 /* pull disable register */
346 1.9 macallan #define JZ_GPIO_DPULLS 0x00000074 /* pull disable set register */
347 1.9 macallan #define JZ_GPIO_DPULLC 0x00000078 /* pull disable clear register */
348 1.9 macallan /* the following are uncommented in the manual */
349 1.9 macallan #define JZ_GPIO_DRVL 0x00000080 /* drive low register */
350 1.9 macallan #define JZ_GPIO_DRVLS 0x00000084 /* drive low set register */
351 1.9 macallan #define JZ_GPIO_DRVLC 0x00000088 /* drive low clear register */
352 1.9 macallan #define JZ_GPIO_DIR 0x00000090 /* direction register */
353 1.9 macallan #define JZ_GPIO_DIRS 0x00000094 /* direction register */
354 1.9 macallan #define JZ_GPIO_DIRC 0x00000098 /* direction register */
355 1.9 macallan #define JZ_GPIO_DRVH 0x000000a0 /* drive high register */
356 1.9 macallan #define JZ_GPIO_DRVHS 0x000000a4 /* drive high set register */
357 1.9 macallan #define JZ_GPIO_DRVHC 0x000000a8 /* drive high clear register */
358 1.9 macallan
359 1.9 macallan static inline void
360 1.9 macallan gpio_as_output(uint32_t g, int pin)
361 1.9 macallan {
362 1.9 macallan uint32_t mask = 1 << pin;
363 1.9 macallan uint32_t reg = JZ_GPIO_A_BASE + (g << 8);
364 1.9 macallan
365 1.9 macallan writereg(reg + JZ_GPIO_INTC, mask); /* use as gpio */
366 1.9 macallan writereg(reg + JZ_GPIO_MASKS, mask);
367 1.9 macallan writereg(reg + JZ_GPIO_PAT1C, mask); /* make output */
368 1.9 macallan }
369 1.9 macallan
370 1.9 macallan static inline void
371 1.9 macallan gpio_set(uint32_t g, int pin, int level)
372 1.9 macallan {
373 1.9 macallan uint32_t mask = 1 << pin;
374 1.9 macallan uint32_t reg = JZ_GPIO_A_BASE + (g << 8);
375 1.9 macallan
376 1.9 macallan reg += (level == 0) ? JZ_GPIO_PAT0C : JZ_GPIO_PAT0S;
377 1.9 macallan writereg(reg, mask);
378 1.9 macallan }
379 1.9 macallan
380 1.9 macallan static inline void
381 1.9 macallan gpio_as_dev0(uint32_t g, int pin)
382 1.9 macallan {
383 1.9 macallan uint32_t mask = 1 << pin;
384 1.9 macallan uint32_t reg = JZ_GPIO_A_BASE + (g << 8);
385 1.9 macallan
386 1.9 macallan writereg(reg + JZ_GPIO_INTC, mask); /* use as gpio */
387 1.9 macallan writereg(reg + JZ_GPIO_MASKC, mask); /* device mode */
388 1.9 macallan writereg(reg + JZ_GPIO_PAT1C, mask); /* select 0 */
389 1.9 macallan writereg(reg + JZ_GPIO_PAT0C, mask);
390 1.9 macallan }
391 1.9 macallan
392 1.9 macallan static inline void
393 1.12 macallan gpio_as_dev1(uint32_t g, int pin)
394 1.12 macallan {
395 1.12 macallan uint32_t mask = 1 << pin;
396 1.12 macallan uint32_t reg = JZ_GPIO_A_BASE + (g << 8);
397 1.12 macallan
398 1.12 macallan writereg(reg + JZ_GPIO_INTC, mask); /* use as gpio */
399 1.12 macallan writereg(reg + JZ_GPIO_MASKC, mask); /* device mode */
400 1.12 macallan writereg(reg + JZ_GPIO_PAT1C, mask); /* select 1 */
401 1.12 macallan writereg(reg + JZ_GPIO_PAT0S, mask);
402 1.12 macallan }
403 1.12 macallan
404 1.12 macallan static inline void
405 1.12 macallan gpio_as_dev2(uint32_t g, int pin)
406 1.12 macallan {
407 1.12 macallan uint32_t mask = 1 << pin;
408 1.12 macallan uint32_t reg = JZ_GPIO_A_BASE + (g << 8);
409 1.12 macallan
410 1.12 macallan writereg(reg + JZ_GPIO_INTC, mask); /* use as gpio */
411 1.12 macallan writereg(reg + JZ_GPIO_MASKC, mask); /* device mode */
412 1.12 macallan writereg(reg + JZ_GPIO_PAT1S, mask); /* select 2 */
413 1.12 macallan writereg(reg + JZ_GPIO_PAT0C, mask);
414 1.12 macallan }
415 1.12 macallan
416 1.12 macallan static inline void
417 1.12 macallan gpio_as_dev3(uint32_t g, int pin)
418 1.12 macallan {
419 1.12 macallan uint32_t mask = 1 << pin;
420 1.12 macallan uint32_t reg = JZ_GPIO_A_BASE + (g << 8);
421 1.12 macallan
422 1.12 macallan writereg(reg + JZ_GPIO_INTC, mask); /* use as gpio */
423 1.12 macallan writereg(reg + JZ_GPIO_MASKC, mask); /* device mode */
424 1.12 macallan writereg(reg + JZ_GPIO_PAT1S, mask); /* select 3 */
425 1.12 macallan writereg(reg + JZ_GPIO_PAT0S, mask);
426 1.12 macallan }
427 1.12 macallan
428 1.12 macallan static inline void
429 1.9 macallan gpio_as_intr_level(uint32_t g, int pin)
430 1.9 macallan {
431 1.9 macallan uint32_t mask = 1 << pin;
432 1.9 macallan uint32_t reg = JZ_GPIO_A_BASE + (g << 8);
433 1.9 macallan
434 1.9 macallan writereg(reg + JZ_GPIO_MASKS, mask); /* mask it */
435 1.9 macallan writereg(reg + JZ_GPIO_INTS, mask); /* use as interrupt */
436 1.9 macallan writereg(reg + JZ_GPIO_PAT1C, mask); /* level trigger */
437 1.9 macallan writereg(reg + JZ_GPIO_PAT0S, mask); /* trigger on high */
438 1.9 macallan writereg(reg + JZ_GPIO_FLAGC, mask); /* clear it */
439 1.9 macallan writereg(reg + JZ_GPIO_MASKC, mask); /* enable it */
440 1.9 macallan }
441 1.10 macallan
442 1.10 macallan /* I2C / SMBus */
443 1.10 macallan #define JZ_SMB0_BASE 0x10050000
444 1.10 macallan #define JZ_SMB1_BASE 0x10051000
445 1.10 macallan #define JZ_SMB2_BASE 0x10052000
446 1.10 macallan #define JZ_SMB3_BASE 0x10053000
447 1.10 macallan #define JZ_SMB4_BASE 0x10054000
448 1.10 macallan
449 1.11 macallan /* SMBus register offsets, per port */
450 1.11 macallan #define JZ_SMBCON 0x00 /* SMB control */
451 1.11 macallan #define JZ_STPHLD 0x80 /* Stop Hold Enable bit */
452 1.11 macallan #define JZ_SLVDIS 0x40 /* 1 - slave disabled */
453 1.11 macallan #define JZ_REST 0x20 /* 1 - allow RESTART */
454 1.11 macallan #define JZ_MATP 0x10 /* 1 - enable 10bit addr. for master */
455 1.11 macallan #define JZ_SATP 0x08 /* 1 - enable 10bit addr. for slave */
456 1.11 macallan #define JZ_SPD_M 0x06 /* bus speed control */
457 1.11 macallan #define JZ_SPD_100KB 0x02 /* 100kBit/s mode */
458 1.11 macallan #define JZ_SPD_400KB 0x04 /* 400kBit/s mode */
459 1.11 macallan #define JZ_MD 0x01 /* enable master */
460 1.11 macallan #define JZ_SMBTAR 0x04 /* SMB target address */
461 1.11 macallan #define JZ_SMATP 0x1000 /* enable 10bit master addr */
462 1.11 macallan #define JZ_SPECIAL 0x0800 /* 1 - special command */
463 1.11 macallan #define JZ_START 0x0400 /* 1 - send START */
464 1.11 macallan #define JZ_SMBTAR_M 0x03ff /* target address */
465 1.11 macallan #define JZ_SMBSAR 0x08 /* SMB slave address */
466 1.11 macallan #define JZ_SMBDC 0x10 /* SMB data buffer and command */
467 1.11 macallan #define JZ_CMD 0x100 /* 1 - read, 0 - write */
468 1.11 macallan #define JZ_DATA 0x0ff
469 1.11 macallan #define JZ_SMBSHCNT 0x14 /* Standard speed SMB SCL high count */
470 1.11 macallan #define JZ_SMBSLCNT 0x18 /* Standard speed SMB SCL low count */
471 1.11 macallan #define JZ_SMBFHCNT 0x1C /* Fast speed SMB SCL high count */
472 1.11 macallan #define JZ_SMBFLCNT 0x20 /* Fast speed SMB SCL low count */
473 1.11 macallan #define JZ_SMBINTST 0x2C /* SMB Interrupt Status */
474 1.11 macallan #define JZ_ISTT 0x400 /* START or RESTART occured */
475 1.11 macallan #define JZ_ISTP 0x200 /* STOP occured */
476 1.11 macallan #define JZ_TXABT 0x40 /* ABORT occured */
477 1.11 macallan #define JZ_TXEMP 0x10 /* TX FIFO is low */
478 1.11 macallan #define JZ_TXOF 0x08 /* TX FIFO is high */
479 1.13 macallan #define JZ_RXFL 0x04 /* RX FIFO is at JZ_SMBRXTL*/
480 1.11 macallan #define JZ_RXOF 0x02 /* RX FIFO is high */
481 1.11 macallan #define JZ_RXUF 0x01 /* RX FIFO underflow */
482 1.11 macallan #define JZ_SMBINTM 0x30 /* SMB Interrupt Mask */
483 1.11 macallan #define JZ_SMBRXTL 0x38 /* SMB RxFIFO Threshold */
484 1.11 macallan #define JZ_SMBTXTL 0x3C /* SMB TxFIFO Threshold */
485 1.11 macallan #define JZ_SMBCINT 0x40 /* Clear Interrupts */
486 1.11 macallan #define JZ_CLEARALL 0x01
487 1.11 macallan #define JZ_SMBCRXUF 0x44 /* Clear RXUF Interrupt */
488 1.11 macallan #define JZ_SMBCRXOF 0x48 /* Clear RX_OVER Interrupt */
489 1.11 macallan #define JZ_SMBCTXOF 0x4C /* Clear TX_OVER Interrupt */
490 1.11 macallan #define JZ_SMBCRXREQ 0x50 /* Clear RDREQ Interrupt */
491 1.11 macallan #define JZ_SMBCTXABT 0x54 /* Clear TX_ABRT Interrupt */
492 1.11 macallan #define JZ_SMBCRXDN 0x58 /* Clear RX_DONE Interrupt */
493 1.11 macallan #define JZ_SMBCACT 0x5c /* Clear ACTIVITY Interrupt */
494 1.11 macallan #define JZ_SMBCSTP 0x60 /* Clear STOP Interrupt */
495 1.11 macallan #define JZ_SMBCSTT 0x64 /* Clear START Interrupt */
496 1.11 macallan #define JZ_SMBCGC 0x68 /* Clear GEN_CALL Interrupt */
497 1.11 macallan #define JZ_SMBENB 0x6C /* SMB Enable */
498 1.11 macallan #define JZ_ENABLE 0x01
499 1.11 macallan #define JZ_SMBST 0x70 /* SMB Status register */
500 1.11 macallan #define JZ_SLVACT 0x40 /* slave is active */
501 1.11 macallan #define JZ_MSTACT 0x20 /* master is active */
502 1.11 macallan #define JZ_RFF 0x10 /* RX FIFO is full */
503 1.11 macallan #define JZ_RFNE 0x08 /* RX FIFO not empty */
504 1.11 macallan #define JZ_TFE 0x04 /* TX FIFO is empty */
505 1.11 macallan #define JZ_TFNF 0x02 /* TX FIFO is not full */
506 1.11 macallan #define JZ_ACT 0x01 /* JZ_SLVACT | JZ_MSTACT */
507 1.11 macallan #define JZ_SMBABTSRC 0x80 /* SMB Transmit Abort Status Register */
508 1.11 macallan #define JZ_SMBDMACR 0x88 /* DMA Control Register */
509 1.11 macallan #define JZ_SMBDMATDL 0x8c /* DMA Transmit Data Level */
510 1.11 macallan #define JZ_SMBDMARDL 0x90 /* DMA Receive Data Level */
511 1.11 macallan #define JZ_SMBSDASU 0x94 /* SMB SDA Setup Register */
512 1.11 macallan #define JZ_SMBACKGC 0x98 /* SMB ACK General Call Register */
513 1.11 macallan #define JZ_SMBENBST 0x9C /* SMB Enable Status Register */
514 1.11 macallan #define JZ_SMBSDAHD 0xD0 /* SMB SDA HolD time Register */
515 1.12 macallan #define JZ_HDENB 0x100 /* enable hold time */
516 1.11 macallan
517 1.2 macallan #endif /* INGENIC_REGS_H */
518