Root/nandprog/include/jz4740.h

1/*
2 * Include file for Ingenic Semiconductor's JZ4740 CPU.
3 */
4#ifndef __JZ4740_H__
5#define __JZ4740_H__
6
7#ifndef __ASSEMBLY__
8
9#define u32 unsigned int
10#define u16 unsigned short
11#define u8 unsigned char
12
13#define REG8(addr) *((volatile u8 *)(addr))
14#define REG16(addr) *((volatile u16 *)(addr))
15#define REG32(addr) *((volatile u32 *)(addr))
16
17#else
18
19#define REG8(addr) (addr)
20#define REG16(addr) (addr)
21#define REG32(addr) (addr)
22
23#endif /* !ASSEMBLY */
24
25//----------------------------------------------------------------------
26// Boot ROM Specification
27//
28
29/* NOR Boot config */
30#define JZ4740_NORBOOT_8BIT 0x00000000 /* 8-bit data bus flash */
31#define JZ4740_NORBOOT_16BIT 0x10101010 /* 16-bit data bus flash */
32#define JZ4740_NORBOOT_32BIT 0x20202020 /* 32-bit data bus flash */
33
34/* NAND Boot config */
35#define JZ4740_NANDBOOT_B8R3 0xffffffff /* 8-bit bus & 3 row cycles */
36#define JZ4740_NANDBOOT_B8R2 0xf0f0f0f0 /* 8-bit bus & 2 row cycles */
37#define JZ4740_NANDBOOT_B16R3 0x0f0f0f0f /* 16-bit bus & 3 row cycles */
38#define JZ4740_NANDBOOT_B16R2 0x00000000 /* 16-bit bus & 2 row cycles */
39
40
41//----------------------------------------------------------------------
42// Register Definitions
43//
44#define CPM_BASE 0xB0000000
45#define INTC_BASE 0xB0001000
46#define TCU_BASE 0xB0002000
47#define WDT_BASE 0xB0002000
48#define RTC_BASE 0xB0003000
49//#define GPIO_BASE 0xB0010000
50#define AIC_BASE 0xB0020000
51#define ICDC_BASE 0xB0020000
52#define MSC_BASE 0xB0021000
53#define UART0_BASE 0xB0030000
54#define I2C_BASE 0xB0042000
55#define SSI_BASE 0xB0043000
56#define SADC_BASE 0xB0070000
57//#define EMC_BASE 0xB3010000
58#define DMAC_BASE 0xB3020000
59#define UHC_BASE 0xB3030000
60#define UDC_BASE 0xB3040000
61#define LCD_BASE 0xB3050000
62#define SLCD_BASE 0xB3050000
63#define CIM_BASE 0xB3060000
64#define ETH_BASE 0xB3100000
65
66
67/*************************************************************************
68 * INTC (Interrupt Controller)
69 *************************************************************************/
70#define INTC_ISR (INTC_BASE + 0x00)
71#define INTC_IMR (INTC_BASE + 0x04)
72#define INTC_IMSR (INTC_BASE + 0x08)
73#define INTC_IMCR (INTC_BASE + 0x0c)
74#define INTC_IPR (INTC_BASE + 0x10)
75
76#define REG_INTC_ISR REG32(INTC_ISR)
77#define REG_INTC_IMR REG32(INTC_IMR)
78#define REG_INTC_IMSR REG32(INTC_IMSR)
79#define REG_INTC_IMCR REG32(INTC_IMCR)
80#define REG_INTC_IPR REG32(INTC_IPR)
81
82// 1st-level interrupts
83#define IRQ_I2C 1
84#define IRQ_UHC 3
85#define IRQ_UART0 9
86#define IRQ_SADC 12
87#define IRQ_MSC 14
88#define IRQ_RTC 15
89#define IRQ_SSI 16
90#define IRQ_CIM 17
91#define IRQ_AIC 18
92#define IRQ_ETH 19
93#define IRQ_DMAC 20
94#define IRQ_TCU2 21
95#define IRQ_TCU1 22
96#define IRQ_TCU0 23
97#define IRQ_UDC 24
98#define IRQ_GPIO3 25
99#define IRQ_GPIO2 26
100#define IRQ_GPIO1 27
101#define IRQ_GPIO0 28
102#define IRQ_IPU 29
103#define IRQ_LCD 30
104
105// 2nd-level interrupts
106#define IRQ_DMA_0 32 /* 32 to 37 for DMAC channel 0 to 5 */
107#define IRQ_GPIO_0 48 /* 48 to 175 for GPIO pin 0 to 127 */
108
109
110/*************************************************************************
111 * RTC
112 *************************************************************************/
113#define RTC_RCR (RTC_BASE + 0x00) /* RTC Control Register */
114#define RTC_RSR (RTC_BASE + 0x04) /* RTC Second Register */
115#define RTC_RSAR (RTC_BASE + 0x08) /* RTC Second Alarm Register */
116#define RTC_RGR (RTC_BASE + 0x0c) /* RTC Regulator Register */
117
118#define RTC_HCR (RTC_BASE + 0x20) /* Hibernate Control Register */
119#define RTC_HWFCR (RTC_BASE + 0x24) /* Hibernate Wakeup Filter Counter Reg */
120#define RTC_HRCR (RTC_BASE + 0x28) /* Hibernate Reset Counter Register */
121#define RTC_HWCR (RTC_BASE + 0x2c) /* Hibernate Wakeup Control Register */
122#define RTC_HWSR (RTC_BASE + 0x30) /* Hibernate Wakeup Status Register */
123
124#define REG_RTC_RCR REG32(RTC_RCR)
125#define REG_RTC_RSR REG32(RTC_RSR)
126#define REG_RTC_RSAR REG32(RTC_RSAR)
127#define REG_RTC_RGR REG32(RTC_RGR)
128#define REG_RTC_HCR REG32(RTC_HCR)
129#define REG_RTC_HWFCR REG32(RTC_HWFCR)
130#define REG_RTC_HRCR REG32(RTC_HRCR)
131#define REG_RTC_HWCR REG32(RTC_HWCR)
132#define REG_RTC_HWSR REG32(RTC_HWSR)
133
134/* RTC Control Register */
135#define RTC_RCR_WRDY (1 << 7) /* Write Ready Flag */
136#define RTC_RCR_HZ (1 << 6) /* 1Hz Flag */
137#define RTC_RCR_HZIE (1 << 5) /* 1Hz Interrupt Enable */
138#define RTC_RCR_AF (1 << 4) /* Alarm Flag */
139#define RTC_RCR_AIE (1 << 3) /* Alarm Interrupt Enable */
140#define RTC_RCR_AE (1 << 2) /* Alarm Enable */
141#define RTC_RCR_RTCE (1 << 0) /* RTC Enable */
142
143/* RTC Regulator Register */
144#define RTC_RGR_LOCK (1 << 31) /* Lock Bit */
145#define RTC_RGR_ADJC_BIT 16
146#define RTC_RGR_ADJC_MASK (0x3ff << RTC_RGR_ADJC_BIT)
147#define RTC_RGR_NC1HZ_BIT 0
148#define RTC_REG_NC1HZ_MASK (0xffff << RTC_RGR_NC1HZ_BIT)
149
150/* Hibernate Control Register */
151#define RTC_HCR_PD (1 << 0) /* Power Down */
152
153/* Hibernate Wakeup Filter Counter Register */
154#define RTC_HWFCR_BIT 5
155#define RTC_HWFCR_MASK (0x7ff << RTC_HWFCR_BIT)
156
157/* Hibernate Reset Counter Register */
158#define RTC_HRCR_BIT 5
159#define RTC_HRCR_MASK (0x7f << RTC_HRCR_BIT)
160
161/* Hibernate Wakeup Control Register */
162#define RTC_HWCR_WL (1 << 2) /* Wakeup pin level: 0-low 1-high */
163#define RTC_HWCR_EPIN (1 << 1) /* Wakeup pin wakeup enable */
164#define RTC_HWCR_EALM (1 << 0) /* RTC alarm wakeup enable */
165
166/* Hibernate Wakeup Status Register */
167#define RTC_HWSR_HR (1 << 5) /* Hibernate reset */
168#define RTC_HWSR_POR (1 << 4) /* POR reset */
169#define RTC_HWSR_PIN (1 << 1) /* Wakeup pin status bit */
170#define RTC_HWSR_ALM (1 << 0) /* RTC alarm status bit */
171
172
173/*************************************************************************
174 * CPM (Clock reset and Power control Management)
175 *************************************************************************/
176#define CPM_CPCCR (CPM_BASE+0x00)
177#define CPM_CPPCR (CPM_BASE+0x10)
178#define CPM_I2SCDR (CPM_BASE+0x60)
179#define CPM_LPCDR (CPM_BASE+0x64)
180#define CPM_MSCCDR (CPM_BASE+0x68)
181#define CPM_UHCCDR (CPM_BASE+0x6C)
182
183#define CPM_LCR (CPM_BASE+0x04)
184#define CPM_CLKGR (CPM_BASE+0x20)
185#define CPM_SCR (CPM_BASE+0x24)
186
187#define CPM_HCR (CPM_BASE+0x30)
188#define CPM_HWFCR (CPM_BASE+0x34)
189#define CPM_HRCR (CPM_BASE+0x38)
190#define CPM_HWCR (CPM_BASE+0x3c)
191#define CPM_HWSR (CPM_BASE+0x40)
192#define CPM_HSPR (CPM_BASE+0x44)
193
194#define CPM_RSR (CPM_BASE+0x08)
195
196
197#define REG_CPM_CPCCR REG32(CPM_CPCCR)
198#define REG_CPM_CPPCR REG32(CPM_CPPCR)
199#define REG_CPM_I2SCDR REG32(CPM_I2SCDR)
200#define REG_CPM_LPCDR REG32(CPM_LPCDR)
201#define REG_CPM_MSCCDR REG32(CPM_MSCCDR)
202#define REG_CPM_UHCCDR REG32(CPM_UHCCDR)
203
204#define REG_CPM_LCR REG32(CPM_LCR)
205#define REG_CPM_CLKGR REG32(CPM_CLKGR)
206#define REG_CPM_SCR REG32(CPM_SCR)
207#define REG_CPM_HCR REG32(CPM_HCR)
208#define REG_CPM_HWFCR REG32(CPM_HWFCR)
209#define REG_CPM_HRCR REG32(CPM_HRCR)
210#define REG_CPM_HWCR REG32(CPM_HWCR)
211#define REG_CPM_HWSR REG32(CPM_HWSR)
212#define REG_CPM_HSPR REG32(CPM_HSPR)
213
214#define REG_CPM_RSR REG32(CPM_RSR)
215
216
217/* Clock Control Register */
218#define CPM_CPCCR_I2CS (1 << 31)
219#define CPM_CPCCR_CLKOEN (1 << 30)
220#define CPM_CPCCR_UCS (1 << 29)
221#define CPM_CPCCR_UDIV_BIT 23
222#define CPM_CPCCR_UDIV_MASK (0x3f << CPM_CPCCR_UDIV_BIT)
223#define CPM_CPCCR_CE (1 << 22)
224#define CPM_CPCCR_PCS (1 << 21)
225#define CPM_CPCCR_LDIV_BIT 16
226#define CPM_CPCCR_LDIV_MASK (0x1f << CPM_CPCCR_LDIV_BIT)
227#define CPM_CPCCR_MDIV_BIT 12
228#define CPM_CPCCR_MDIV_MASK (0x0f << CPM_CPCCR_MDIV_BIT)
229#define CPM_CPCCR_PDIV_BIT 8
230#define CPM_CPCCR_PDIV_MASK (0x0f << CPM_CPCCR_PDIV_BIT)
231#define CPM_CPCCR_HDIV_BIT 4
232#define CPM_CPCCR_HDIV_MASK (0x0f << CPM_CPCCR_HDIV_BIT)
233#define CPM_CPCCR_CDIV_BIT 0
234#define CPM_CPCCR_CDIV_MASK (0x0f << CPM_CPCCR_CDIV_BIT)
235
236/* I2S Clock Divider Register */
237#define CPM_I2SCDR_I2SDIV_BIT 0
238#define CPM_I2SCDR_I2SDIV_MASK (0x1ff << CPM_I2SCDR_I2SDIV_BIT)
239
240/* LCD Pixel Clock Divider Register */
241#define CPM_LPCDR_PIXDIV_BIT 0
242#define CPM_LPCDR_PIXDIV_MASK (0x1ff << CPM_LPCDR_PIXDIV_BIT)
243
244/* MSC Clock Divider Register */
245#define CPM_MSCCDR_MSCDIV_BIT 0
246#define CPM_MSCCDR_MSCDIV_MASK (0x1f << CPM_MSCCDR_MSCDIV_BIT)
247
248/* PLL Control Register */
249#define CPM_CPPCR_PLLM_BIT 23
250#define CPM_CPPCR_PLLM_MASK (0x1ff << CPM_CPPCR_PLLM_BIT)
251#define CPM_CPPCR_PLLN_BIT 18
252#define CPM_CPPCR_PLLN_MASK (0x1f << CPM_CPPCR_PLLN_BIT)
253#define CPM_CPPCR_PLLOD_BIT 16
254#define CPM_CPPCR_PLLOD_MASK (0x03 << CPM_CPPCR_PLLOD_BIT)
255#define CPM_CPPCR_PLLS (1 << 10)
256#define CPM_CPPCR_PLLBP (1 << 9)
257#define CPM_CPPCR_PLLEN (1 << 8)
258#define CPM_CPPCR_PLLST_BIT 0
259#define CPM_CPPCR_PLLST_MASK (0xff << CPM_CPPCR_PLLST_BIT)
260
261/* Low Power Control Register */
262#define CPM_LCR_DOZE_DUTY_BIT 3
263#define CPM_LCR_DOZE_DUTY_MASK (0x1f << CPM_LCR_DOZE_DUTY_BIT)
264#define CPM_LCR_DOZE_ON (1 << 2)
265#define CPM_LCR_LPM_BIT 0
266#define CPM_LCR_LPM_MASK (0x3 << CPM_LCR_LPM_BIT)
267  #define CPM_LCR_LPM_IDLE (0x0 << CPM_LCR_LPM_BIT)
268  #define CPM_LCR_LPM_SLEEP (0x1 << CPM_LCR_LPM_BIT)
269
270/* Clock Gate Register */
271#define CPM_CLKGR_UART1 (1 << 15)
272#define CPM_CLKGR_UHC (1 << 14)
273#define CPM_CLKGR_IPU (1 << 13)
274#define CPM_CLKGR_DMAC (1 << 12)
275#define CPM_CLKGR_UDC (1 << 11)
276#define CPM_CLKGR_LCD (1 << 10)
277#define CPM_CLKGR_CIM (1 << 9)
278#define CPM_CLKGR_SADC (1 << 8)
279#define CPM_CLKGR_MSC (1 << 7)
280#define CPM_CLKGR_AIC1 (1 << 6)
281#define CPM_CLKGR_AIC2 (1 << 5)
282#define CPM_CLKGR_SSI (1 << 4)
283#define CPM_CLKGR_I2C (1 << 3)
284#define CPM_CLKGR_RTC (1 << 2)
285#define CPM_CLKGR_TCU (1 << 1)
286#define CPM_CLKGR_UART0 (1 << 0)
287
288/* Sleep Control Register */
289#define CPM_SCR_O1ST_BIT 8
290#define CPM_SCR_O1ST_MASK (0xff << CPM_SCR_O1ST_BIT)
291#define CPM_SCR_USBPHY_ENABLE (1 << 6)
292#define CPM_SCR_OSC_ENABLE (1 << 4)
293
294/* Hibernate Control Register */
295#define CPM_HCR_PD (1 << 0)
296
297/* Wakeup Filter Counter Register in Hibernate Mode */
298#define CPM_HWFCR_TIME_BIT 0
299#define CPM_HWFCR_TIME_MASK (0x3ff << CPM_HWFCR_TIME_BIT)
300
301/* Reset Counter Register in Hibernate Mode */
302#define CPM_HRCR_TIME_BIT 0
303#define CPM_HRCR_TIME_MASK (0x7f << CPM_HRCR_TIME_BIT)
304
305/* Wakeup Control Register in Hibernate Mode */
306#define CPM_HWCR_WLE_LOW (0 << 2)
307#define CPM_HWCR_WLE_HIGH (1 << 2)
308#define CPM_HWCR_PIN_WAKEUP (1 << 1)
309#define CPM_HWCR_RTC_WAKEUP (1 << 0)
310
311/* Wakeup Status Register in Hibernate Mode */
312#define CPM_HWSR_WSR_PIN (1 << 1)
313#define CPM_HWSR_WSR_RTC (1 << 0)
314
315/* Reset Status Register */
316#define CPM_RSR_HR (1 << 2)
317#define CPM_RSR_WR (1 << 1)
318#define CPM_RSR_PR (1 << 0)
319
320
321/*************************************************************************
322 * TCU (Timer Counter Unit)
323 *************************************************************************/
324#define TCU_TSR (TCU_BASE + 0x1C) /* Timer Stop Register */
325#define TCU_TSSR (TCU_BASE + 0x2C) /* Timer Stop Set Register */
326#define TCU_TSCR (TCU_BASE + 0x3C) /* Timer Stop Clear Register */
327#define TCU_TER (TCU_BASE + 0x10) /* Timer Counter Enable Register */
328#define TCU_TESR (TCU_BASE + 0x14) /* Timer Counter Enable Set Register */
329#define TCU_TECR (TCU_BASE + 0x18) /* Timer Counter Enable Clear Register */
330#define TCU_TFR (TCU_BASE + 0x20) /* Timer Flag Register */
331#define TCU_TFSR (TCU_BASE + 0x24) /* Timer Flag Set Register */
332#define TCU_TFCR (TCU_BASE + 0x28) /* Timer Flag Clear Register */
333#define TCU_TMR (TCU_BASE + 0x30) /* Timer Mask Register */
334#define TCU_TMSR (TCU_BASE + 0x34) /* Timer Mask Set Register */
335#define TCU_TMCR (TCU_BASE + 0x38) /* Timer Mask Clear Register */
336#define TCU_TDFR0 (TCU_BASE + 0x40) /* Timer Data Full Register */
337#define TCU_TDHR0 (TCU_BASE + 0x44) /* Timer Data Half Register */
338#define TCU_TCNT0 (TCU_BASE + 0x48) /* Timer Counter Register */
339#define TCU_TCSR0 (TCU_BASE + 0x4C) /* Timer Control Register */
340#define TCU_TDFR1 (TCU_BASE + 0x50)
341#define TCU_TDHR1 (TCU_BASE + 0x54)
342#define TCU_TCNT1 (TCU_BASE + 0x58)
343#define TCU_TCSR1 (TCU_BASE + 0x5C)
344#define TCU_TDFR2 (TCU_BASE + 0x60)
345#define TCU_TDHR2 (TCU_BASE + 0x64)
346#define TCU_TCNT2 (TCU_BASE + 0x68)
347#define TCU_TCSR2 (TCU_BASE + 0x6C)
348#define TCU_TDFR3 (TCU_BASE + 0x70)
349#define TCU_TDHR3 (TCU_BASE + 0x74)
350#define TCU_TCNT3 (TCU_BASE + 0x78)
351#define TCU_TCSR3 (TCU_BASE + 0x7C)
352#define TCU_TDFR4 (TCU_BASE + 0x80)
353#define TCU_TDHR4 (TCU_BASE + 0x84)
354#define TCU_TCNT4 (TCU_BASE + 0x88)
355#define TCU_TCSR4 (TCU_BASE + 0x8C)
356#define TCU_TDFR5 (TCU_BASE + 0x90)
357#define TCU_TDHR5 (TCU_BASE + 0x94)
358#define TCU_TCNT5 (TCU_BASE + 0x98)
359#define TCU_TCSR5 (TCU_BASE + 0x9C)
360
361#define REG_TCU_TSR REG32(TCU_TSR)
362#define REG_TCU_TSSR REG32(TCU_TSSR)
363#define REG_TCU_TSCR REG32(TCU_TSCR)
364#define REG_TCU_TER REG8(TCU_TER)
365#define REG_TCU_TESR REG8(TCU_TESR)
366#define REG_TCU_TECR REG8(TCU_TECR)
367#define REG_TCU_TFR REG32(TCU_TFR)
368#define REG_TCU_TFSR REG32(TCU_TFSR)
369#define REG_TCU_TFCR REG32(TCU_TFCR)
370#define REG_TCU_TMR REG32(TCU_TMR)
371#define REG_TCU_TMSR REG32(TCU_TMSR)
372#define REG_TCU_TMCR REG32(TCU_TMCR)
373#define REG_TCU_TDFR0 REG16(TCU_TDFR0)
374#define REG_TCU_TDHR0 REG16(TCU_TDHR0)
375#define REG_TCU_TCNT0 REG16(TCU_TCNT0)
376#define REG_TCU_TCSR0 REG16(TCU_TCSR0)
377#define REG_TCU_TDFR1 REG16(TCU_TDFR1)
378#define REG_TCU_TDHR1 REG16(TCU_TDHR1)
379#define REG_TCU_TCNT1 REG16(TCU_TCNT1)
380#define REG_TCU_TCSR1 REG16(TCU_TCSR1)
381#define REG_TCU_TDFR2 REG16(TCU_TDFR2)
382#define REG_TCU_TDHR2 REG16(TCU_TDHR2)
383#define REG_TCU_TCNT2 REG16(TCU_TCNT2)
384#define REG_TCU_TCSR2 REG16(TCU_TCSR2)
385#define REG_TCU_TDFR3 REG16(TCU_TDFR3)
386#define REG_TCU_TDHR3 REG16(TCU_TDHR3)
387#define REG_TCU_TCNT3 REG16(TCU_TCNT3)
388#define REG_TCU_TCSR3 REG16(TCU_TCSR3)
389#define REG_TCU_TDFR4 REG16(TCU_TDFR4)
390#define REG_TCU_TDHR4 REG16(TCU_TDHR4)
391#define REG_TCU_TCNT4 REG16(TCU_TCNT4)
392#define REG_TCU_TCSR4 REG16(TCU_TCSR4)
393
394// n = 0,1,2,3,4,5
395#define TCU_TDFR(n) (TCU_BASE + (0x40 + (n)*0x10)) /* Timer Data Full Reg */
396#define TCU_TDHR(n) (TCU_BASE + (0x44 + (n)*0x10)) /* Timer Data Half Reg */
397#define TCU_TCNT(n) (TCU_BASE + (0x48 + (n)*0x10)) /* Timer Counter Reg */
398#define TCU_TCSR(n) (TCU_BASE + (0x4C + (n)*0x10)) /* Timer Control Reg */
399
400#define REG_TCU_TDFR(n) REG16(TCU_TDFR((n)))
401#define REG_TCU_TDHR(n) REG16(TCU_TDHR((n)))
402#define REG_TCU_TCNT(n) REG16(TCU_TCNT((n)))
403#define REG_TCU_TCSR(n) REG16(TCU_TCSR((n)))
404
405// Register definitions
406#define TCU_TCSR_PWM_SD (1 << 9)
407#define TCU_TCSR_PWM_INITL_HIGH (1 << 8)
408#define TCU_TCSR_PWM_EN (1 << 7)
409#define TCU_TCSR_PRESCALE_BIT 3
410#define TCU_TCSR_PRESCALE_MASK (0x7 << TCU_TCSR_PRESCALE_BIT)
411  #define TCU_TCSR_PRESCALE1 (0x0 << TCU_TCSR_PRESCALE_BIT)
412  #define TCU_TCSR_PRESCALE4 (0x1 << TCU_TCSR_PRESCALE_BIT)
413  #define TCU_TCSR_PRESCALE16 (0x2 << TCU_TCSR_PRESCALE_BIT)
414  #define TCU_TCSR_PRESCALE64 (0x3 << TCU_TCSR_PRESCALE_BIT)
415  #define TCU_TCSR_PRESCALE256 (0x4 << TCU_TCSR_PRESCALE_BIT)
416  #define TCU_TCSR_PRESCALE1024 (0x5 << TCU_TCSR_PRESCALE_BIT)
417#define TCU_TCSR_EXT_EN (1 << 2)
418#define TCU_TCSR_RTC_EN (1 << 1)
419#define TCU_TCSR_PCK_EN (1 << 0)
420
421#define TCU_TER_TCEN5 (1 << 5)
422#define TCU_TER_TCEN4 (1 << 4)
423#define TCU_TER_TCEN3 (1 << 3)
424#define TCU_TER_TCEN2 (1 << 2)
425#define TCU_TER_TCEN1 (1 << 1)
426#define TCU_TER_TCEN0 (1 << 0)
427
428#define TCU_TESR_TCST5 (1 << 5)
429#define TCU_TESR_TCST4 (1 << 4)
430#define TCU_TESR_TCST3 (1 << 3)
431#define TCU_TESR_TCST2 (1 << 2)
432#define TCU_TESR_TCST1 (1 << 1)
433#define TCU_TESR_TCST0 (1 << 0)
434
435#define TCU_TECR_TCCL5 (1 << 5)
436#define TCU_TECR_TCCL4 (1 << 4)
437#define TCU_TECR_TCCL3 (1 << 3)
438#define TCU_TECR_TCCL2 (1 << 2)
439#define TCU_TECR_TCCL1 (1 << 1)
440#define TCU_TECR_TCCL0 (1 << 0)
441
442#define TCU_TFR_HFLAG5 (1 << 21)
443#define TCU_TFR_HFLAG4 (1 << 20)
444#define TCU_TFR_HFLAG3 (1 << 19)
445#define TCU_TFR_HFLAG2 (1 << 18)
446#define TCU_TFR_HFLAG1 (1 << 17)
447#define TCU_TFR_HFLAG0 (1 << 16)
448#define TCU_TFR_FFLAG5 (1 << 5)
449#define TCU_TFR_FFLAG4 (1 << 4)
450#define TCU_TFR_FFLAG3 (1 << 3)
451#define TCU_TFR_FFLAG2 (1 << 2)
452#define TCU_TFR_FFLAG1 (1 << 1)
453#define TCU_TFR_FFLAG0 (1 << 0)
454
455#define TCU_TFSR_HFLAG5 (1 << 21)
456#define TCU_TFSR_HFLAG4 (1 << 20)
457#define TCU_TFSR_HFLAG3 (1 << 19)
458#define TCU_TFSR_HFLAG2 (1 << 18)
459#define TCU_TFSR_HFLAG1 (1 << 17)
460#define TCU_TFSR_HFLAG0 (1 << 16)
461#define TCU_TFSR_FFLAG5 (1 << 5)
462#define TCU_TFSR_FFLAG4 (1 << 4)
463#define TCU_TFSR_FFLAG3 (1 << 3)
464#define TCU_TFSR_FFLAG2 (1 << 2)
465#define TCU_TFSR_FFLAG1 (1 << 1)
466#define TCU_TFSR_FFLAG0 (1 << 0)
467
468#define TCU_TFCR_HFLAG5 (1 << 21)
469#define TCU_TFCR_HFLAG4 (1 << 20)
470#define TCU_TFCR_HFLAG3 (1 << 19)
471#define TCU_TFCR_HFLAG2 (1 << 18)
472#define TCU_TFCR_HFLAG1 (1 << 17)
473#define TCU_TFCR_HFLAG0 (1 << 16)
474#define TCU_TFCR_FFLAG5 (1 << 5)
475#define TCU_TFCR_FFLAG4 (1 << 4)
476#define TCU_TFCR_FFLAG3 (1 << 3)
477#define TCU_TFCR_FFLAG2 (1 << 2)
478#define TCU_TFCR_FFLAG1 (1 << 1)
479#define TCU_TFCR_FFLAG0 (1 << 0)
480
481#define TCU_TMR_HMASK5 (1 << 21)
482#define TCU_TMR_HMASK4 (1 << 20)
483#define TCU_TMR_HMASK3 (1 << 19)
484#define TCU_TMR_HMASK2 (1 << 18)
485#define TCU_TMR_HMASK1 (1 << 17)
486#define TCU_TMR_HMASK0 (1 << 16)
487#define TCU_TMR_FMASK5 (1 << 5)
488#define TCU_TMR_FMASK4 (1 << 4)
489#define TCU_TMR_FMASK3 (1 << 3)
490#define TCU_TMR_FMASK2 (1 << 2)
491#define TCU_TMR_FMASK1 (1 << 1)
492#define TCU_TMR_FMASK0 (1 << 0)
493
494#define TCU_TMSR_HMST5 (1 << 21)
495#define TCU_TMSR_HMST4 (1 << 20)
496#define TCU_TMSR_HMST3 (1 << 19)
497#define TCU_TMSR_HMST2 (1 << 18)
498#define TCU_TMSR_HMST1 (1 << 17)
499#define TCU_TMSR_HMST0 (1 << 16)
500#define TCU_TMSR_FMST5 (1 << 5)
501#define TCU_TMSR_FMST4 (1 << 4)
502#define TCU_TMSR_FMST3 (1 << 3)
503#define TCU_TMSR_FMST2 (1 << 2)
504#define TCU_TMSR_FMST1 (1 << 1)
505#define TCU_TMSR_FMST0 (1 << 0)
506
507#define TCU_TMCR_HMCL5 (1 << 21)
508#define TCU_TMCR_HMCL4 (1 << 20)
509#define TCU_TMCR_HMCL3 (1 << 19)
510#define TCU_TMCR_HMCL2 (1 << 18)
511#define TCU_TMCR_HMCL1 (1 << 17)
512#define TCU_TMCR_HMCL0 (1 << 16)
513#define TCU_TMCR_FMCL5 (1 << 5)
514#define TCU_TMCR_FMCL4 (1 << 4)
515#define TCU_TMCR_FMCL3 (1 << 3)
516#define TCU_TMCR_FMCL2 (1 << 2)
517#define TCU_TMCR_FMCL1 (1 << 1)
518#define TCU_TMCR_FMCL0 (1 << 0)
519
520#define TCU_TSR_WDTS (1 << 16)
521#define TCU_TSR_STOP5 (1 << 5)
522#define TCU_TSR_STOP4 (1 << 4)
523#define TCU_TSR_STOP3 (1 << 3)
524#define TCU_TSR_STOP2 (1 << 2)
525#define TCU_TSR_STOP1 (1 << 1)
526#define TCU_TSR_STOP0 (1 << 0)
527
528#define TCU_TSSR_WDTSS (1 << 16)
529#define TCU_TSSR_STPS5 (1 << 5)
530#define TCU_TSSR_STPS4 (1 << 4)
531#define TCU_TSSR_STPS3 (1 << 3)
532#define TCU_TSSR_STPS2 (1 << 2)
533#define TCU_TSSR_STPS1 (1 << 1)
534#define TCU_TSSR_STPS0 (1 << 0)
535
536#define TCU_TSSR_WDTSC (1 << 16)
537#define TCU_TSSR_STPC5 (1 << 5)
538#define TCU_TSSR_STPC4 (1 << 4)
539#define TCU_TSSR_STPC3 (1 << 3)
540#define TCU_TSSR_STPC2 (1 << 2)
541#define TCU_TSSR_STPC1 (1 << 1)
542#define TCU_TSSR_STPC0 (1 << 0)
543
544
545/*************************************************************************
546 * WDT (WatchDog Timer)
547 *************************************************************************/
548#define WDT_TDR (WDT_BASE + 0x00)
549#define WDT_TCER (WDT_BASE + 0x04)
550#define WDT_TCNT (WDT_BASE + 0x08)
551#define WDT_TCSR (WDT_BASE + 0x0C)
552
553#define REG_WDT_TDR REG16(WDT_TDR)
554#define REG_WDT_TCER REG8(WDT_TCER)
555#define REG_WDT_TCNT REG16(WDT_TCNT)
556#define REG_WDT_TCSR REG16(WDT_TCSR)
557
558// Register definition
559#define WDT_TCSR_PRESCALE_BIT 3
560#define WDT_TCSR_PRESCALE_MASK (0x7 << WDT_TCSR_PRESCALE_BIT)
561  #define WDT_TCSR_PRESCALE1 (0x0 << WDT_TCSR_PRESCALE_BIT)
562  #define WDT_TCSR_PRESCALE4 (0x1 << WDT_TCSR_PRESCALE_BIT)
563  #define WDT_TCSR_PRESCALE16 (0x2 << WDT_TCSR_PRESCALE_BIT)
564  #define WDT_TCSR_PRESCALE64 (0x3 << WDT_TCSR_PRESCALE_BIT)
565  #define WDT_TCSR_PRESCALE256 (0x4 << WDT_TCSR_PRESCALE_BIT)
566  #define WDT_TCSR_PRESCALE1024 (0x5 << WDT_TCSR_PRESCALE_BIT)
567#define WDT_TCSR_EXT_EN (1 << 2)
568#define WDT_TCSR_RTC_EN (1 << 1)
569#define WDT_TCSR_PCK_EN (1 << 0)
570
571#define WDT_TCER_TCEN (1 << 0)
572
573
574/*************************************************************************
575 * DMAC (DMA Controller)
576 *************************************************************************/
577
578#define MAX_DMA_NUM 6 /* max 6 channels */
579
580#define DMAC_DSAR(n) (DMAC_BASE + (0x00 + (n) * 0x20)) /* DMA source address */
581#define DMAC_DTAR(n) (DMAC_BASE + (0x04 + (n) * 0x20)) /* DMA target address */
582#define DMAC_DTCR(n) (DMAC_BASE + (0x08 + (n) * 0x20)) /* DMA transfer count */
583#define DMAC_DRSR(n) (DMAC_BASE + (0x0c + (n) * 0x20)) /* DMA request source */
584#define DMAC_DCCSR(n) (DMAC_BASE + (0x10 + (n) * 0x20)) /* DMA control/status */
585#define DMAC_DCMD(n) (DMAC_BASE + (0x14 + (n) * 0x20)) /* DMA command */
586#define DMAC_DDA(n) (DMAC_BASE + (0x18 + (n) * 0x20)) /* DMA descriptor address */
587#define DMAC_DMACR (DMAC_BASE + 0x0300) /* DMA control register */
588#define DMAC_DMAIPR (DMAC_BASE + 0x0304) /* DMA interrupt pending */
589#define DMAC_DMADBR (DMAC_BASE + 0x0308) /* DMA doorbell */
590#define DMAC_DMADBSR (DMAC_BASE + 0x030C) /* DMA doorbell set */
591
592// channel 0
593#define DMAC_DSAR0 DMAC_DSAR(0)
594#define DMAC_DTAR0 DMAC_DTAR(0)
595#define DMAC_DTCR0 DMAC_DTCR(0)
596#define DMAC_DRSR0 DMAC_DRSR(0)
597#define DMAC_DCCSR0 DMAC_DCCSR(0)
598#define DMAC_DCMD0 DMAC_DCMD(0)
599#define DMAC_DDA0 DMAC_DDA(0)
600
601// channel 1
602#define DMAC_DSAR1 DMAC_DSAR(1)
603#define DMAC_DTAR1 DMAC_DTAR(1)
604#define DMAC_DTCR1 DMAC_DTCR(1)
605#define DMAC_DRSR1 DMAC_DRSR(1)
606#define DMAC_DCCSR1 DMAC_DCCSR(1)
607#define DMAC_DCMD1 DMAC_DCMD(1)
608#define DMAC_DDA1 DMAC_DDA(1)
609
610// channel 2
611#define DMAC_DSAR2 DMAC_DSAR(2)
612#define DMAC_DTAR2 DMAC_DTAR(2)
613#define DMAC_DTCR2 DMAC_DTCR(2)
614#define DMAC_DRSR2 DMAC_DRSR(2)
615#define DMAC_DCCSR2 DMAC_DCCSR(2)
616#define DMAC_DCMD2 DMAC_DCMD(2)
617#define DMAC_DDA2 DMAC_DDA(2)
618
619// channel 3
620#define DMAC_DSAR3 DMAC_DSAR(3)
621#define DMAC_DTAR3 DMAC_DTAR(3)
622#define DMAC_DTCR3 DMAC_DTCR(3)
623#define DMAC_DRSR3 DMAC_DRSR(3)
624#define DMAC_DCCSR3 DMAC_DCCSR(3)
625#define DMAC_DCMD3 DMAC_DCMD(3)
626#define DMAC_DDA3 DMAC_DDA(3)
627
628// channel 4
629#define DMAC_DSAR4 DMAC_DSAR(4)
630#define DMAC_DTAR4 DMAC_DTAR(4)
631#define DMAC_DTCR4 DMAC_DTCR(4)
632#define DMAC_DRSR4 DMAC_DRSR(4)
633#define DMAC_DCCSR4 DMAC_DCCSR(4)
634#define DMAC_DCMD4 DMAC_DCMD(4)
635#define DMAC_DDA4 DMAC_DDA(4)
636
637// channel 5
638#define DMAC_DSAR5 DMAC_DSAR(5)
639#define DMAC_DTAR5 DMAC_DTAR(5)
640#define DMAC_DTCR5 DMAC_DTCR(5)
641#define DMAC_DRSR5 DMAC_DRSR(5)
642#define DMAC_DCCSR5 DMAC_DCCSR(5)
643#define DMAC_DCMD5 DMAC_DCMD(5)
644#define DMAC_DDA5 DMAC_DDA(5)
645
646#define REG_DMAC_DSAR(n) REG32(DMAC_DSAR((n)))
647#define REG_DMAC_DTAR(n) REG32(DMAC_DTAR((n)))
648#define REG_DMAC_DTCR(n) REG32(DMAC_DTCR((n)))
649#define REG_DMAC_DRSR(n) REG32(DMAC_DRSR((n)))
650#define REG_DMAC_DCCSR(n) REG32(DMAC_DCCSR((n)))
651#define REG_DMAC_DCMD(n) REG32(DMAC_DCMD((n)))
652#define REG_DMAC_DDA(n) REG32(DMAC_DDA((n)))
653#define REG_DMAC_DMACR REG32(DMAC_DMACR)
654#define REG_DMAC_DMAIPR REG32(DMAC_DMAIPR)
655#define REG_DMAC_DMADBR REG32(DMAC_DMADBR)
656#define REG_DMAC_DMADBSR REG32(DMAC_DMADBSR)
657
658// DMA request source register
659#define DMAC_DRSR_RS_BIT 0
660#define DMAC_DRSR_RS_MASK (0x1f << DMAC_DRSR_RS_BIT)
661  #define DMAC_DRSR_RS_AUTO (8 << DMAC_DRSR_RS_BIT)
662  #define DMAC_DRSR_RS_UART0OUT (20 << DMAC_DRSR_RS_BIT)
663  #define DMAC_DRSR_RS_UART0IN (21 << DMAC_DRSR_RS_BIT)
664  #define DMAC_DRSR_RS_SSIOUT (22 << DMAC_DRSR_RS_BIT)
665  #define DMAC_DRSR_RS_SSIIN (23 << DMAC_DRSR_RS_BIT)
666  #define DMAC_DRSR_RS_AICOUT (24 << DMAC_DRSR_RS_BIT)
667  #define DMAC_DRSR_RS_AICIN (25 << DMAC_DRSR_RS_BIT)
668  #define DMAC_DRSR_RS_MSCOUT (26 << DMAC_DRSR_RS_BIT)
669  #define DMAC_DRSR_RS_MSCIN (27 << DMAC_DRSR_RS_BIT)
670  #define DMAC_DRSR_RS_TCU (28 << DMAC_DRSR_RS_BIT)
671  #define DMAC_DRSR_RS_SADC (29 << DMAC_DRSR_RS_BIT)
672  #define DMAC_DRSR_RS_SLCD (30 << DMAC_DRSR_RS_BIT)
673
674// DMA channel control/status register
675#define DMAC_DCCSR_NDES (1 << 31) /* descriptor (0) or not (1) ? */
676#define DMAC_DCCSR_CDOA_BIT 16 /* copy of DMA offset address */
677#define DMAC_DCCSR_CDOA_MASK (0xff << DMAC_DCCSR_CDOA_BIT)
678#define DMAC_DCCSR_INV (1 << 6) /* descriptor invalid */
679#define DMAC_DCCSR_AR (1 << 4) /* address error */
680#define DMAC_DCCSR_TT (1 << 3) /* transfer terminated */
681#define DMAC_DCCSR_HLT (1 << 2) /* DMA halted */
682#define DMAC_DCCSR_CT (1 << 1) /* count terminated */
683#define DMAC_DCCSR_EN (1 << 0) /* channel enable bit */
684
685// DMA channel command register
686#define DMAC_DCMD_SAI (1 << 23) /* source address increment */
687#define DMAC_DCMD_DAI (1 << 22) /* dest address increment */
688#define DMAC_DCMD_RDIL_BIT 16 /* request detection interval length */
689#define DMAC_DCMD_RDIL_MASK (0x0f << DMAC_DCMD_RDIL_BIT)
690  #define DMAC_DCMD_RDIL_IGN (0 << DMAC_DCMD_RDIL_BIT)
691  #define DMAC_DCMD_RDIL_2 (1 << DMAC_DCMD_RDIL_BIT)
692  #define DMAC_DCMD_RDIL_4 (2 << DMAC_DCMD_RDIL_BIT)
693  #define DMAC_DCMD_RDIL_8 (3 << DMAC_DCMD_RDIL_BIT)
694  #define DMAC_DCMD_RDIL_12 (4 << DMAC_DCMD_RDIL_BIT)
695  #define DMAC_DCMD_RDIL_16 (5 << DMAC_DCMD_RDIL_BIT)
696  #define DMAC_DCMD_RDIL_20 (6 << DMAC_DCMD_RDIL_BIT)
697  #define DMAC_DCMD_RDIL_24 (7 << DMAC_DCMD_RDIL_BIT)
698  #define DMAC_DCMD_RDIL_28 (8 << DMAC_DCMD_RDIL_BIT)
699  #define DMAC_DCMD_RDIL_32 (9 << DMAC_DCMD_RDIL_BIT)
700  #define DMAC_DCMD_RDIL_48 (10 << DMAC_DCMD_RDIL_BIT)
701  #define DMAC_DCMD_RDIL_60 (11 << DMAC_DCMD_RDIL_BIT)
702  #define DMAC_DCMD_RDIL_64 (12 << DMAC_DCMD_RDIL_BIT)
703  #define DMAC_DCMD_RDIL_124 (13 << DMAC_DCMD_RDIL_BIT)
704  #define DMAC_DCMD_RDIL_128 (14 << DMAC_DCMD_RDIL_BIT)
705  #define DMAC_DCMD_RDIL_200 (15 << DMAC_DCMD_RDIL_BIT)
706#define DMAC_DCMD_SWDH_BIT 14 /* source port width */
707#define DMAC_DCMD_SWDH_MASK (0x03 << DMAC_DCMD_SWDH_BIT)
708  #define DMAC_DCMD_SWDH_32 (0 << DMAC_DCMD_SWDH_BIT)
709  #define DMAC_DCMD_SWDH_8 (1 << DMAC_DCMD_SWDH_BIT)
710  #define DMAC_DCMD_SWDH_16 (2 << DMAC_DCMD_SWDH_BIT)
711#define DMAC_DCMD_DWDH_BIT 12 /* dest port width */
712#define DMAC_DCMD_DWDH_MASK (0x03 << DMAC_DCMD_DWDH_BIT)
713  #define DMAC_DCMD_DWDH_32 (0 << DMAC_DCMD_DWDH_BIT)
714  #define DMAC_DCMD_DWDH_8 (1 << DMAC_DCMD_DWDH_BIT)
715  #define DMAC_DCMD_DWDH_16 (2 << DMAC_DCMD_DWDH_BIT)
716#define DMAC_DCMD_DS_BIT 8 /* transfer data size of a data unit */
717#define DMAC_DCMD_DS_MASK (0x07 << DMAC_DCMD_DS_BIT)
718  #define DMAC_DCMD_DS_32BIT (0 << DMAC_DCMD_DS_BIT)
719  #define DMAC_DCMD_DS_8BIT (1 << DMAC_DCMD_DS_BIT)
720  #define DMAC_DCMD_DS_16BIT (2 << DMAC_DCMD_DS_BIT)
721  #define DMAC_DCMD_DS_16BYTE (3 << DMAC_DCMD_DS_BIT)
722  #define DMAC_DCMD_DS_32BYTE (4 << DMAC_DCMD_DS_BIT)
723#define DMAC_DCMD_TM (1 << 7) /* transfer mode: 0-single 1-block */
724#define DMAC_DCMD_DES_V (1 << 4) /* descriptor valid flag */
725#define DMAC_DCMD_DES_VM (1 << 3) /* descriptor valid mask: 1:support V-bit */
726#define DMAC_DCMD_DES_VIE (1 << 2) /* DMA valid error interrupt enable */
727#define DMAC_DCMD_TIE (1 << 1) /* DMA transfer interrupt enable */
728#define DMAC_DCMD_LINK (1 << 0) /* descriptor link enable */
729
730// DMA descriptor address register
731#define DMAC_DDA_BASE_BIT 12 /* descriptor base address */
732#define DMAC_DDA_BASE_MASK (0x0fffff << DMAC_DDA_BASE_BIT)
733#define DMAC_DDA_OFFSET_BIT 4 /* descriptor offset address */
734#define DMAC_DDA_OFFSET_MASK (0x0ff << DMAC_DDA_OFFSET_BIT)
735
736// DMA control register
737#define DMAC_DMACR_PR_BIT 8 /* channel priority mode */
738#define DMAC_DMACR_PR_MASK (0x03 << DMAC_DMACR_PR_BIT)
739  #define DMAC_DMACR_PR_012345 (0 << DMAC_DMACR_PR_BIT)
740  #define DMAC_DMACR_PR_023145 (1 << DMAC_DMACR_PR_BIT)
741  #define DMAC_DMACR_PR_201345 (2 << DMAC_DMACR_PR_BIT)
742  #define DMAC_DMACR_PR_RR (3 << DMAC_DMACR_PR_BIT) /* round robin */
743#define DMAC_DMACR_HLT (1 << 3) /* DMA halt flag */
744#define DMAC_DMACR_AR (1 << 2) /* address error flag */
745#define DMAC_DMACR_DMAE (1 << 0) /* DMA enable bit */
746
747// DMA doorbell register
748#define DMAC_DMADBR_DB5 (1 << 5) /* doorbell for channel 5 */
749#define DMAC_DMADBR_DB4 (1 << 5) /* doorbell for channel 4 */
750#define DMAC_DMADBR_DB3 (1 << 5) /* doorbell for channel 3 */
751#define DMAC_DMADBR_DB2 (1 << 5) /* doorbell for channel 2 */
752#define DMAC_DMADBR_DB1 (1 << 5) /* doorbell for channel 1 */
753#define DMAC_DMADBR_DB0 (1 << 5) /* doorbell for channel 0 */
754
755// DMA doorbell set register
756#define DMAC_DMADBSR_DBS5 (1 << 5) /* enable doorbell for channel 5 */
757#define DMAC_DMADBSR_DBS4 (1 << 5) /* enable doorbell for channel 4 */
758#define DMAC_DMADBSR_DBS3 (1 << 5) /* enable doorbell for channel 3 */
759#define DMAC_DMADBSR_DBS2 (1 << 5) /* enable doorbell for channel 2 */
760#define DMAC_DMADBSR_DBS1 (1 << 5) /* enable doorbell for channel 1 */
761#define DMAC_DMADBSR_DBS0 (1 << 5) /* enable doorbell for channel 0 */
762
763// DMA interrupt pending register
764#define DMAC_DMAIPR_CIRQ5 (1 << 5) /* irq pending status for channel 5 */
765#define DMAC_DMAIPR_CIRQ4 (1 << 4) /* irq pending status for channel 4 */
766#define DMAC_DMAIPR_CIRQ3 (1 << 3) /* irq pending status for channel 3 */
767#define DMAC_DMAIPR_CIRQ2 (1 << 2) /* irq pending status for channel 2 */
768#define DMAC_DMAIPR_CIRQ1 (1 << 1) /* irq pending status for channel 1 */
769#define DMAC_DMAIPR_CIRQ0 (1 << 0) /* irq pending status for channel 0 */
770
771
772/*************************************************************************
773 * GPIO (General-Purpose I/O Ports)
774 *************************************************************************/
775#define MAX_GPIO_NUM 128
776
777//n = 0,1,2,3
778#define GPIO_PXPIN(n) (GPIO_BASE + (0x00 + (n)*0x100)) /* PIN Level Register */
779#define GPIO_PXDAT(n) (GPIO_BASE + (0x10 + (n)*0x100)) /* Port Data Register */
780#define GPIO_PXDATS(n) (GPIO_BASE + (0x14 + (n)*0x100)) /* Port Data Set Register */
781#define GPIO_PXDATC(n) (GPIO_BASE + (0x18 + (n)*0x100)) /* Port Data Clear Register */
782#define GPIO_PXIM(n) (GPIO_BASE + (0x20 + (n)*0x100)) /* Interrupt Mask Register */
783#define GPIO_PXIMS(n) (GPIO_BASE + (0x24 + (n)*0x100)) /* Interrupt Mask Set Reg */
784#define GPIO_PXIMC(n) (GPIO_BASE + (0x28 + (n)*0x100)) /* Interrupt Mask Clear Reg */
785#define GPIO_PXPE(n) (GPIO_BASE + (0x30 + (n)*0x100)) /* Pull Enable Register */
786#define GPIO_PXPES(n) (GPIO_BASE + (0x34 + (n)*0x100)) /* Pull Enable Set Reg. */
787#define GPIO_PXPEC(n) (GPIO_BASE + (0x38 + (n)*0x100)) /* Pull Enable Clear Reg. */
788#define GPIO_PXFUN(n) (GPIO_BASE + (0x40 + (n)*0x100)) /* Function Register */
789#define GPIO_PXFUNS(n) (GPIO_BASE + (0x44 + (n)*0x100)) /* Function Set Register */
790#define GPIO_PXFUNC(n) (GPIO_BASE + (0x48 + (n)*0x100)) /* Function Clear Register */
791#define GPIO_PXSEL(n) (GPIO_BASE + (0x50 + (n)*0x100)) /* Select Register */
792#define GPIO_PXSELS(n) (GPIO_BASE + (0x54 + (n)*0x100)) /* Select Set Register */
793#define GPIO_PXSELC(n) (GPIO_BASE + (0x58 + (n)*0x100)) /* Select Clear Register */
794#define GPIO_PXDIR(n) (GPIO_BASE + (0x60 + (n)*0x100)) /* Direction Register */
795#define GPIO_PXDIRS(n) (GPIO_BASE + (0x64 + (n)*0x100)) /* Direction Set Register */
796#define GPIO_PXDIRC(n) (GPIO_BASE + (0x68 + (n)*0x100)) /* Direction Clear Register */
797#define GPIO_PXTRG(n) (GPIO_BASE + (0x70 + (n)*0x100)) /* Trigger Register */
798#define GPIO_PXTRGS(n) (GPIO_BASE + (0x74 + (n)*0x100)) /* Trigger Set Register */
799#define GPIO_PXTRGC(n) (GPIO_BASE + (0x78 + (n)*0x100)) /* Trigger Set Register */
800#define GPIO_PXFLG(n) (GPIO_BASE + (0x80 + (n)*0x100)) /* Port Flag Register */
801
802#define REG_GPIO_PXPIN(n) REG32(GPIO_PXPIN((n))) /* PIN level */
803#define REG_GPIO_PXDAT(n) REG32(GPIO_PXDAT((n))) /* 1: interrupt pending */
804#define REG_GPIO_PXDATS(n) REG32(GPIO_PXDATS((n)))
805#define REG_GPIO_PXDATC(n) REG32(GPIO_PXDATC((n)))
806#define REG_GPIO_PXIM(n) REG32(GPIO_PXIM((n))) /* 1: mask pin interrupt */
807#define REG_GPIO_PXIMS(n) REG32(GPIO_PXIMS((n)))
808#define REG_GPIO_PXIMC(n) REG32(GPIO_PXIMC((n)))
809#define REG_GPIO_PXPE(n) REG32(GPIO_PXPE((n))) /* 1: disable pull up/down */
810#define REG_GPIO_PXPES(n) REG32(GPIO_PXPES((n)))
811#define REG_GPIO_PXPEC(n) REG32(GPIO_PXPEC((n)))
812#define REG_GPIO_PXFUN(n) REG32(GPIO_PXFUN((n))) /* 0:GPIO or intr, 1:FUNC */
813#define REG_GPIO_PXFUNS(n) REG32(GPIO_PXFUNS((n)))
814#define REG_GPIO_PXFUNC(n) REG32(GPIO_PXFUNC((n)))
815#define REG_GPIO_PXSEL(n) REG32(GPIO_PXSEL((n))) /* 0:GPIO/Fun0,1:intr/fun1*/
816#define REG_GPIO_PXSELS(n) REG32(GPIO_PXSELS((n)))
817#define REG_GPIO_PXSELC(n) REG32(GPIO_PXSELC((n)))
818#define REG_GPIO_PXDIR(n) REG32(GPIO_PXDIR((n))) /* 0:input/low-level-trig/falling-edge-trig, 1:output/high-level-trig/rising-edge-trig */
819#define REG_GPIO_PXDIRS(n) REG32(GPIO_PXDIRS((n)))
820#define REG_GPIO_PXDIRC(n) REG32(GPIO_PXDIRC((n)))
821#define REG_GPIO_PXTRG(n) REG32(GPIO_PXTRG((n))) /* 0:level-trigger, 1:edge-trigger */
822#define REG_GPIO_PXTRGS(n) REG32(GPIO_PXTRGS((n)))
823#define REG_GPIO_PXTRGC(n) REG32(GPIO_PXTRGC((n)))
824#define REG_GPIO_PXFLG(n) REG32(GPIO_PXFLG((n))) /* interrupt flag */
825
826
827/*************************************************************************
828 * UART
829 *************************************************************************/
830
831#define IRDA_BASE UART0_BASE
832#define UART_BASE UART0_BASE
833#define UART_OFF 0x1000
834
835/* Register Offset */
836#define OFF_RDR (0x00) /* R 8b H'xx */
837#define OFF_TDR (0x00) /* W 8b H'xx */
838#define OFF_DLLR (0x00) /* RW 8b H'00 */
839#define OFF_DLHR (0x04) /* RW 8b H'00 */
840#define OFF_IER (0x04) /* RW 8b H'00 */
841#define OFF_ISR (0x08) /* R 8b H'01 */
842#define OFF_FCR (0x08) /* W 8b H'00 */
843#define OFF_LCR (0x0C) /* RW 8b H'00 */
844#define OFF_MCR (0x10) /* RW 8b H'00 */
845#define OFF_LSR (0x14) /* R 8b H'00 */
846#define OFF_MSR (0x18) /* R 8b H'00 */
847#define OFF_SPR (0x1C) /* RW 8b H'00 */
848#define OFF_SIRCR (0x20) /* RW 8b H'00, UART0 */
849#define OFF_UMR (0x24) /* RW 8b H'00, UART M Register */
850#define OFF_UACR (0x28) /* RW 8b H'00, UART Add Cycle Register */
851
852/* Register Address */
853#define UART0_RDR (UART0_BASE + OFF_RDR)
854#define UART0_TDR (UART0_BASE + OFF_TDR)
855#define UART0_DLLR (UART0_BASE + OFF_DLLR)
856#define UART0_DLHR (UART0_BASE + OFF_DLHR)
857#define UART0_IER (UART0_BASE + OFF_IER)
858#define UART0_ISR (UART0_BASE + OFF_ISR)
859#define UART0_FCR (UART0_BASE + OFF_FCR)
860#define UART0_LCR (UART0_BASE + OFF_LCR)
861#define UART0_MCR (UART0_BASE + OFF_MCR)
862#define UART0_LSR (UART0_BASE + OFF_LSR)
863#define UART0_MSR (UART0_BASE + OFF_MSR)
864#define UART0_SPR (UART0_BASE + OFF_SPR)
865#define UART0_SIRCR (UART0_BASE + OFF_SIRCR)
866#define UART0_UMR (UART0_BASE + OFF_UMR)
867#define UART0_UACR (UART0_BASE + OFF_UACR)
868
869/*
870 * Define macros for UART_IER
871 * UART Interrupt Enable Register
872 */
873#define UART_IER_RIE (1 << 0) /* 0: receive fifo "full" interrupt disable */
874#define UART_IER_TIE (1 << 1) /* 0: transmit fifo "empty" interrupt disable */
875#define UART_IER_RLIE (1 << 2) /* 0: receive line status interrupt disable */
876#define UART_IER_MIE (1 << 3) /* 0: modem status interrupt disable */
877#define UART_IER_RTIE (1 << 4) /* 0: receive timeout interrupt disable */
878
879/*
880 * Define macros for UART_ISR
881 * UART Interrupt Status Register
882 */
883#define UART_ISR_IP (1 << 0) /* 0: interrupt is pending 1: no interrupt */
884#define UART_ISR_IID (7 << 1) /* Source of Interrupt */
885#define UART_ISR_IID_MSI (0 << 1) /* Modem status interrupt */
886#define UART_ISR_IID_THRI (1 << 1) /* Transmitter holding register empty */
887#define UART_ISR_IID_RDI (2 << 1) /* Receiver data interrupt */
888#define UART_ISR_IID_RLSI (3 << 1) /* Receiver line status interrupt */
889#define UART_ISR_FFMS (3 << 6) /* FIFO mode select, set when UART_FCR.FE is set to 1 */
890#define UART_ISR_FFMS_NO_FIFO (0 << 6)
891#define UART_ISR_FFMS_FIFO_MODE (3 << 6)
892
893/*
894 * Define macros for UART_FCR
895 * UART FIFO Control Register
896 */
897#define UART_FCR_FE (1 << 0) /* 0: non-FIFO mode 1: FIFO mode */
898#define UART_FCR_RFLS (1 << 1) /* write 1 to flush receive FIFO */
899#define UART_FCR_TFLS (1 << 2) /* write 1 to flush transmit FIFO */
900#define UART_FCR_DMS (1 << 3) /* 0: disable DMA mode */
901#define UART_FCR_UUE (1 << 4) /* 0: disable UART */
902#define UART_FCR_RTRG (3 << 6) /* Receive FIFO Data Trigger */
903#define UART_FCR_RTRG_1 (0 << 6)
904#define UART_FCR_RTRG_4 (1 << 6)
905#define UART_FCR_RTRG_8 (2 << 6)
906#define UART_FCR_RTRG_15 (3 << 6)
907
908/*
909 * Define macros for UART_LCR
910 * UART Line Control Register
911 */
912#define UART_LCR_WLEN (3 << 0) /* word length */
913#define UART_LCR_WLEN_5 (0 << 0)
914#define UART_LCR_WLEN_6 (1 << 0)
915#define UART_LCR_WLEN_7 (2 << 0)
916#define UART_LCR_WLEN_8 (3 << 0)
917#define UART_LCR_STOP (1 << 2) /* 0: 1 stop bit when word length is 5,6,7,8
918                       1: 1.5 stop bits when 5; 2 stop bits when 6,7,8 */
919#define UART_LCR_STOP_1 (0 << 2) /* 0: 1 stop bit when word length is 5,6,7,8
920                       1: 1.5 stop bits when 5; 2 stop bits when 6,7,8 */
921#define UART_LCR_STOP_2 (1 << 2) /* 0: 1 stop bit when word length is 5,6,7,8
922                       1: 1.5 stop bits when 5; 2 stop bits when 6,7,8 */
923
924#define UART_LCR_PE (1 << 3) /* 0: parity disable */
925#define UART_LCR_PROE (1 << 4) /* 0: even parity 1: odd parity */
926#define UART_LCR_SPAR (1 << 5) /* 0: sticky parity disable */
927#define UART_LCR_SBRK (1 << 6) /* write 0 normal, write 1 send break */
928#define UART_LCR_DLAB (1 << 7) /* 0: access UART_RDR/TDR/IER 1: access UART_DLLR/DLHR */
929
930/*
931 * Define macros for UART_LSR
932 * UART Line Status Register
933 */
934#define UART_LSR_DR (1 << 0) /* 0: receive FIFO is empty 1: receive data is ready */
935#define UART_LSR_ORER (1 << 1) /* 0: no overrun error */
936#define UART_LSR_PER (1 << 2) /* 0: no parity error */
937#define UART_LSR_FER (1 << 3) /* 0; no framing error */
938#define UART_LSR_BRK (1 << 4) /* 0: no break detected 1: receive a break signal */
939#define UART_LSR_TDRQ (1 << 5) /* 1: transmit FIFO half "empty" */
940#define UART_LSR_TEMT (1 << 6) /* 1: transmit FIFO and shift registers empty */
941#define UART_LSR_RFER (1 << 7) /* 0: no receive error 1: receive error in FIFO mode */
942
943/*
944 * Define macros for UART_MCR
945 * UART Modem Control Register
946 */
947#define UART_MCR_DTR (1 << 0) /* 0: DTR_ ouput high */
948#define UART_MCR_RTS (1 << 1) /* 0: RTS_ output high */
949#define UART_MCR_OUT1 (1 << 2) /* 0: UART_MSR.RI is set to 0 and RI_ input high */
950#define UART_MCR_OUT2 (1 << 3) /* 0: UART_MSR.DCD is set to 0 and DCD_ input high */
951#define UART_MCR_LOOP (1 << 4) /* 0: normal 1: loopback mode */
952#define UART_MCR_MCE (1 << 7) /* 0: modem function is disable */
953
954/*
955 * Define macros for UART_MSR
956 * UART Modem Status Register
957 */
958#define UART_MSR_DCTS (1 << 0) /* 0: no change on CTS_ pin since last read of UART_MSR */
959#define UART_MSR_DDSR (1 << 1) /* 0: no change on DSR_ pin since last read of UART_MSR */
960#define UART_MSR_DRI (1 << 2) /* 0: no change on RI_ pin since last read of UART_MSR */
961#define UART_MSR_DDCD (1 << 3) /* 0: no change on DCD_ pin since last read of UART_MSR */
962#define UART_MSR_CTS (1 << 4) /* 0: CTS_ pin is high */
963#define UART_MSR_DSR (1 << 5) /* 0: DSR_ pin is high */
964#define UART_MSR_RI (1 << 6) /* 0: RI_ pin is high */
965#define UART_MSR_DCD (1 << 7) /* 0: DCD_ pin is high */
966
967/*
968 * Define macros for SIRCR
969 * Slow IrDA Control Register
970 */
971#define SIRCR_TSIRE (1 << 0) /* 0: transmitter is in UART mode 1: IrDA mode */
972#define SIRCR_RSIRE (1 << 1) /* 0: receiver is in UART mode 1: IrDA mode */
973#define SIRCR_TPWS (1 << 2) /* 0: transmit 0 pulse width is 3/16 of bit length
974                       1: 0 pulse width is 1.6us for 115.2Kbps */
975#define SIRCR_TXPL (1 << 3) /* 0: encoder generates a positive pulse for 0 */
976#define SIRCR_RXPL (1 << 4) /* 0: decoder interprets positive pulse as 0 */
977
978
979/*************************************************************************
980 * AIC (AC97/I2S Controller)
981 *************************************************************************/
982#define AIC_FR (AIC_BASE + 0x000)
983#define AIC_CR (AIC_BASE + 0x004)
984#define AIC_ACCR1 (AIC_BASE + 0x008)
985#define AIC_ACCR2 (AIC_BASE + 0x00C)
986#define AIC_I2SCR (AIC_BASE + 0x010)
987#define AIC_SR (AIC_BASE + 0x014)
988#define AIC_ACSR (AIC_BASE + 0x018)
989#define AIC_I2SSR (AIC_BASE + 0x01C)
990#define AIC_ACCAR (AIC_BASE + 0x020)
991#define AIC_ACCDR (AIC_BASE + 0x024)
992#define AIC_ACSAR (AIC_BASE + 0x028)
993#define AIC_ACSDR (AIC_BASE + 0x02C)
994#define AIC_I2SDIV (AIC_BASE + 0x030)
995#define AIC_DR (AIC_BASE + 0x034)
996
997#define REG_AIC_FR REG32(AIC_FR)
998#define REG_AIC_CR REG32(AIC_CR)
999#define REG_AIC_ACCR1 REG32(AIC_ACCR1)
1000#define REG_AIC_ACCR2 REG32(AIC_ACCR2)
1001#define REG_AIC_I2SCR REG32(AIC_I2SCR)
1002#define REG_AIC_SR REG32(AIC_SR)
1003#define REG_AIC_ACSR REG32(AIC_ACSR)
1004#define REG_AIC_I2SSR REG32(AIC_I2SSR)
1005#define REG_AIC_ACCAR REG32(AIC_ACCAR)
1006#define REG_AIC_ACCDR REG32(AIC_ACCDR)
1007#define REG_AIC_ACSAR REG32(AIC_ACSAR)
1008#define REG_AIC_ACSDR REG32(AIC_ACSDR)
1009#define REG_AIC_I2SDIV REG32(AIC_I2SDIV)
1010#define REG_AIC_DR REG32(AIC_DR)
1011
1012/* AIC Controller Configuration Register (AIC_FR) */
1013
1014#define AIC_FR_RFTH_BIT 12 /* Receive FIFO Threshold */
1015#define AIC_FR_RFTH_MASK (0xf << AIC_FR_RFTH_BIT)
1016#define AIC_FR_TFTH_BIT 8 /* Transmit FIFO Threshold */
1017#define AIC_FR_TFTH_MASK (0xf << AIC_FR_TFTH_BIT)
1018#define AIC_FR_ICDC (1 << 5) /* External(0) or Internal CODEC(1) */
1019#define AIC_FR_AUSEL (1 << 4) /* AC97(0) or I2S/MSB-justified(1) */
1020#define AIC_FR_RST (1 << 3) /* AIC registers reset */
1021#define AIC_FR_BCKD (1 << 2) /* I2S BIT_CLK direction, 0:input,1:output */
1022#define AIC_FR_SYNCD (1 << 1) /* I2S SYNC direction, 0:input,1:output */
1023#define AIC_FR_ENB (1 << 0) /* AIC enable bit */
1024
1025/* AIC Controller Common Control Register (AIC_CR) */
1026
1027#define AIC_CR_OSS_BIT 19 /* Output Sample Size from memory (AIC V2 only) */
1028#define AIC_CR_OSS_MASK (0x7 << AIC_CR_OSS_BIT)
1029  #define AIC_CR_OSS_8BIT (0x0 << AIC_CR_OSS_BIT)
1030  #define AIC_CR_OSS_16BIT (0x1 << AIC_CR_OSS_BIT)
1031  #define AIC_CR_OSS_18BIT (0x2 << AIC_CR_OSS_BIT)
1032  #define AIC_CR_OSS_20BIT (0x3 << AIC_CR_OSS_BIT)
1033  #define AIC_CR_OSS_24BIT (0x4 << AIC_CR_OSS_BIT)
1034#define AIC_CR_ISS_BIT 16 /* Input Sample Size from memory (AIC V2 only) */
1035#define AIC_CR_ISS_MASK (0x7 << AIC_CR_ISS_BIT)
1036  #define AIC_CR_ISS_8BIT (0x0 << AIC_CR_ISS_BIT)
1037  #define AIC_CR_ISS_16BIT (0x1 << AIC_CR_ISS_BIT)
1038  #define AIC_CR_ISS_18BIT (0x2 << AIC_CR_ISS_BIT)
1039  #define AIC_CR_ISS_20BIT (0x3 << AIC_CR_ISS_BIT)
1040  #define AIC_CR_ISS_24BIT (0x4 << AIC_CR_ISS_BIT)
1041#define AIC_CR_RDMS (1 << 15) /* Receive DMA enable */
1042#define AIC_CR_TDMS (1 << 14) /* Transmit DMA enable */
1043#define AIC_CR_M2S (1 << 11) /* Mono to Stereo enable */
1044#define AIC_CR_ENDSW (1 << 10) /* Endian switch enable */
1045#define AIC_CR_AVSTSU (1 << 9) /* Signed <-> Unsigned toggle enable */
1046#define AIC_CR_FLUSH (1 << 8) /* Flush FIFO */
1047#define AIC_CR_EROR (1 << 6) /* Enable ROR interrupt */
1048#define AIC_CR_ETUR (1 << 5) /* Enable TUR interrupt */
1049#define AIC_CR_ERFS (1 << 4) /* Enable RFS interrupt */
1050#define AIC_CR_ETFS (1 << 3) /* Enable TFS interrupt */
1051#define AIC_CR_ENLBF (1 << 2) /* Enable Loopback Function */
1052#define AIC_CR_ERPL (1 << 1) /* Enable Playback Function */
1053#define AIC_CR_EREC (1 << 0) /* Enable Record Function */
1054
1055/* AIC Controller AC-link Control Register 1 (AIC_ACCR1) */
1056
1057#define AIC_ACCR1_RS_BIT 16 /* Receive Valid Slots */
1058#define AIC_ACCR1_RS_MASK (0x3ff << AIC_ACCR1_RS_BIT)
1059  #define AIC_ACCR1_RS_SLOT12 (1 << 25) /* Slot 12 valid bit */
1060  #define AIC_ACCR1_RS_SLOT11 (1 << 24) /* Slot 11 valid bit */
1061  #define AIC_ACCR1_RS_SLOT10 (1 << 23) /* Slot 10 valid bit */
1062  #define AIC_ACCR1_RS_SLOT9 (1 << 22) /* Slot 9 valid bit, LFE */
1063  #define AIC_ACCR1_RS_SLOT8 (1 << 21) /* Slot 8 valid bit, Surround Right */
1064  #define AIC_ACCR1_RS_SLOT7 (1 << 20) /* Slot 7 valid bit, Surround Left */
1065  #define AIC_ACCR1_RS_SLOT6 (1 << 19) /* Slot 6 valid bit, PCM Center */
1066  #define AIC_ACCR1_RS_SLOT5 (1 << 18) /* Slot 5 valid bit */
1067  #define AIC_ACCR1_RS_SLOT4 (1 << 17) /* Slot 4 valid bit, PCM Right */
1068  #define AIC_ACCR1_RS_SLOT3 (1 << 16) /* Slot 3 valid bit, PCM Left */
1069#define AIC_ACCR1_XS_BIT 0 /* Transmit Valid Slots */
1070#define AIC_ACCR1_XS_MASK (0x3ff << AIC_ACCR1_XS_BIT)
1071  #define AIC_ACCR1_XS_SLOT12 (1 << 9) /* Slot 12 valid bit */
1072  #define AIC_ACCR1_XS_SLOT11 (1 << 8) /* Slot 11 valid bit */
1073  #define AIC_ACCR1_XS_SLOT10 (1 << 7) /* Slot 10 valid bit */
1074  #define AIC_ACCR1_XS_SLOT9 (1 << 6) /* Slot 9 valid bit, LFE */
1075  #define AIC_ACCR1_XS_SLOT8 (1 << 5) /* Slot 8 valid bit, Surround Right */
1076  #define AIC_ACCR1_XS_SLOT7 (1 << 4) /* Slot 7 valid bit, Surround Left */
1077  #define AIC_ACCR1_XS_SLOT6 (1 << 3) /* Slot 6 valid bit, PCM Center */
1078  #define AIC_ACCR1_XS_SLOT5 (1 << 2) /* Slot 5 valid bit */
1079  #define AIC_ACCR1_XS_SLOT4 (1 << 1) /* Slot 4 valid bit, PCM Right */
1080  #define AIC_ACCR1_XS_SLOT3 (1 << 0) /* Slot 3 valid bit, PCM Left */
1081
1082/* AIC Controller AC-link Control Register 2 (AIC_ACCR2) */
1083
1084#define AIC_ACCR2_ERSTO (1 << 18) /* Enable RSTO interrupt */
1085#define AIC_ACCR2_ESADR (1 << 17) /* Enable SADR interrupt */
1086#define AIC_ACCR2_ECADT (1 << 16) /* Enable CADT interrupt */
1087#define AIC_ACCR2_OASS_BIT 8 /* Output Sample Size for AC-link */
1088#define AIC_ACCR2_OASS_MASK (0x3 << AIC_ACCR2_OASS_BIT)
1089  #define AIC_ACCR2_OASS_20BIT (0 << AIC_ACCR2_OASS_BIT) /* Output Audio Sample Size is 20-bit */
1090  #define AIC_ACCR2_OASS_18BIT (1 << AIC_ACCR2_OASS_BIT) /* Output Audio Sample Size is 18-bit */
1091  #define AIC_ACCR2_OASS_16BIT (2 << AIC_ACCR2_OASS_BIT) /* Output Audio Sample Size is 16-bit */
1092  #define AIC_ACCR2_OASS_8BIT (3 << AIC_ACCR2_OASS_BIT) /* Output Audio Sample Size is 8-bit */
1093#define AIC_ACCR2_IASS_BIT 6 /* Output Sample Size for AC-link */
1094#define AIC_ACCR2_IASS_MASK (0x3 << AIC_ACCR2_IASS_BIT)
1095  #define AIC_ACCR2_IASS_20BIT (0 << AIC_ACCR2_IASS_BIT) /* Input Audio Sample Size is 20-bit */
1096  #define AIC_ACCR2_IASS_18BIT (1 << AIC_ACCR2_IASS_BIT) /* Input Audio Sample Size is 18-bit */
1097  #define AIC_ACCR2_IASS_16BIT (2 << AIC_ACCR2_IASS_BIT) /* Input Audio Sample Size is 16-bit */
1098  #define AIC_ACCR2_IASS_8BIT (3 << AIC_ACCR2_IASS_BIT) /* Input Audio Sample Size is 8-bit */
1099#define AIC_ACCR2_SO (1 << 3) /* SDATA_OUT output value */
1100#define AIC_ACCR2_SR (1 << 2) /* RESET# pin level */
1101#define AIC_ACCR2_SS (1 << 1) /* SYNC pin level */
1102#define AIC_ACCR2_SA (1 << 0) /* SYNC and SDATA_OUT alternation */
1103
1104/* AIC Controller I2S/MSB-justified Control Register (AIC_I2SCR) */
1105
1106#define AIC_I2SCR_STPBK (1 << 12) /* Stop BIT_CLK for I2S/MSB-justified */
1107#define AIC_I2SCR_WL_BIT 1 /* Input/Output Sample Size for I2S/MSB-justified */
1108#define AIC_I2SCR_WL_MASK (0x7 << AIC_I2SCR_WL_BIT)
1109  #define AIC_I2SCR_WL_24BIT (0 << AIC_I2SCR_WL_BIT) /* Word Length is 24 bit */
1110  #define AIC_I2SCR_WL_20BIT (1 << AIC_I2SCR_WL_BIT) /* Word Length is 20 bit */
1111  #define AIC_I2SCR_WL_18BIT (2 << AIC_I2SCR_WL_BIT) /* Word Length is 18 bit */
1112  #define AIC_I2SCR_WL_16BIT (3 << AIC_I2SCR_WL_BIT) /* Word Length is 16 bit */
1113  #define AIC_I2SCR_WL_8BIT (4 << AIC_I2SCR_WL_BIT) /* Word Length is 8 bit */
1114#define AIC_I2SCR_AMSL (1 << 0) /* 0:I2S, 1:MSB-justified */
1115
1116/* AIC Controller FIFO Status Register (AIC_SR) */
1117
1118#define AIC_SR_RFL_BIT 24 /* Receive FIFO Level */
1119#define AIC_SR_RFL_MASK (0x3f << AIC_SR_RFL_BIT)
1120#define AIC_SR_TFL_BIT 8 /* Transmit FIFO level */
1121#define AIC_SR_TFL_MASK (0x3f << AIC_SR_TFL_BIT)
1122#define AIC_SR_ROR (1 << 6) /* Receive FIFO Overrun */
1123#define AIC_SR_TUR (1 << 5) /* Transmit FIFO Underrun */
1124#define AIC_SR_RFS (1 << 4) /* Receive FIFO Service Request */
1125#define AIC_SR_TFS (1 << 3) /* Transmit FIFO Service Request */
1126
1127/* AIC Controller AC-link Status Register (AIC_ACSR) */
1128
1129#define AIC_ACSR_SLTERR (1 << 21) /* Slot Error Flag */
1130#define AIC_ACSR_CRDY (1 << 20) /* External CODEC Ready Flag */
1131#define AIC_ACSR_CLPM (1 << 19) /* External CODEC low power mode flag */
1132#define AIC_ACSR_RSTO (1 << 18) /* External CODEC regs read status timeout */
1133#define AIC_ACSR_SADR (1 << 17) /* External CODEC regs status addr and data received */
1134#define AIC_ACSR_CADT (1 << 16) /* Command Address and Data Transmitted */
1135
1136/* AIC Controller I2S/MSB-justified Status Register (AIC_I2SSR) */
1137
1138#define AIC_I2SSR_BSY (1 << 2) /* AIC Busy in I2S/MSB-justified format */
1139
1140/* AIC Controller AC97 codec Command Address Register (AIC_ACCAR) */
1141
1142#define AIC_ACCAR_CAR_BIT 0
1143#define AIC_ACCAR_CAR_MASK (0xfffff << AIC_ACCAR_CAR_BIT)
1144
1145/* AIC Controller AC97 codec Command Data Register (AIC_ACCDR) */
1146
1147#define AIC_ACCDR_CDR_BIT 0
1148#define AIC_ACCDR_CDR_MASK (0xfffff << AIC_ACCDR_CDR_BIT)
1149
1150/* AIC Controller AC97 codec Status Address Register (AIC_ACSAR) */
1151
1152#define AIC_ACSAR_SAR_BIT 0
1153#define AIC_ACSAR_SAR_MASK (0xfffff << AIC_ACSAR_SAR_BIT)
1154
1155/* AIC Controller AC97 codec Status Data Register (AIC_ACSDR) */
1156
1157#define AIC_ACSDR_SDR_BIT 0
1158#define AIC_ACSDR_SDR_MASK (0xfffff << AIC_ACSDR_SDR_BIT)
1159
1160/* AIC Controller I2S/MSB-justified Clock Divider Register (AIC_I2SDIV) */
1161
1162#define AIC_I2SDIV_DIV_BIT 0
1163#define AIC_I2SDIV_DIV_MASK (0x7f << AIC_I2SDIV_DIV_BIT)
1164  #define AIC_I2SDIV_BITCLK_3072KHZ (0x0C << AIC_I2SDIV_DIV_BIT) /* BIT_CLK of 3.072MHz */
1165  #define AIC_I2SDIV_BITCLK_2836KHZ (0x0D << AIC_I2SDIV_DIV_BIT) /* BIT_CLK of 2.836MHz */
1166  #define AIC_I2SDIV_BITCLK_1418KHZ (0x1A << AIC_I2SDIV_DIV_BIT) /* BIT_CLK of 1.418MHz */
1167  #define AIC_I2SDIV_BITCLK_1024KHZ (0x24 << AIC_I2SDIV_DIV_BIT) /* BIT_CLK of 1.024MHz */
1168  #define AIC_I2SDIV_BITCLK_7089KHZ (0x34 << AIC_I2SDIV_DIV_BIT) /* BIT_CLK of 708.92KHz */
1169  #define AIC_I2SDIV_BITCLK_512KHZ (0x48 << AIC_I2SDIV_DIV_BIT) /* BIT_CLK of 512.00KHz */
1170
1171
1172/*************************************************************************
1173 * ICDC (Internal CODEC)
1174 *************************************************************************/
1175#define ICDC_CR (ICDC_BASE + 0x0400) /* ICDC Control Register */
1176#define ICDC_APWAIT (ICDC_BASE + 0x0404) /* Anti-Pop WAIT Stage Timing Control Register */
1177#define ICDC_APPRE (ICDC_BASE + 0x0408) /* Anti-Pop HPEN-PRE Stage Timing Control Register */
1178#define ICDC_APHPEN (ICDC_BASE + 0x040C) /* Anti-Pop HPEN Stage Timing Control Register */
1179#define ICDC_APSR (ICDC_BASE + 0x0410) /* Anti-Pop Status Register */
1180#define ICDC_CDCCR1 (ICDC_BASE + 0x0080)
1181#define ICDC_CDCCR2 (ICDC_BASE + 0x0084)
1182
1183#define REG_ICDC_CR REG32(ICDC_CR)
1184#define REG_ICDC_APWAIT REG32(ICDC_APWAIT)
1185#define REG_ICDC_APPRE REG32(ICDC_APPRE)
1186#define REG_ICDC_APHPEN REG32(ICDC_APHPEN)
1187#define REG_ICDC_APSR REG32(ICDC_APSR)
1188#define REG_ICDC_CDCCR1 REG32(ICDC_CDCCR1)
1189#define REG_ICDC_CDCCR2 REG32(ICDC_CDCCR2)
1190
1191/* ICDC Control Register */
1192#define ICDC_CR_LINVOL_BIT 24 /* LINE Input Volume Gain: GAIN=LINVOL*1.5-34.5 */
1193#define ICDC_CR_LINVOL_MASK (0x1f << ICDC_CR_LINVOL_BIT)
1194#define ICDC_CR_ASRATE_BIT 20 /* Audio Sample Rate */
1195#define ICDC_CR_ASRATE_MASK (0x0f << ICDC_CR_ASRATE_BIT)
1196  #define ICDC_CR_ASRATE_8000 (0x0 << ICDC_CR_ASRATE_BIT)
1197  #define ICDC_CR_ASRATE_11025 (0x1 << ICDC_CR_ASRATE_BIT)
1198  #define ICDC_CR_ASRATE_12000 (0x2 << ICDC_CR_ASRATE_BIT)
1199  #define ICDC_CR_ASRATE_16000 (0x3 << ICDC_CR_ASRATE_BIT)
1200  #define ICDC_CR_ASRATE_22050 (0x4 << ICDC_CR_ASRATE_BIT)
1201  #define ICDC_CR_ASRATE_24000 (0x5 << ICDC_CR_ASRATE_BIT)
1202  #define ICDC_CR_ASRATE_32000 (0x6 << ICDC_CR_ASRATE_BIT)
1203  #define ICDC_CR_ASRATE_44100 (0x7 << ICDC_CR_ASRATE_BIT)
1204  #define ICDC_CR_ASRATE_48000 (0x8 << ICDC_CR_ASRATE_BIT)
1205#define ICDC_CR_MICBG_BIT 18 /* MIC Boost Gain */
1206#define ICDC_CR_MICBG_MASK (0x3 << ICDC_CR_MICBG_BIT)
1207  #define ICDC_CR_MICBG_0DB (0x0 << ICDC_CR_MICBG_BIT)
1208  #define ICDC_CR_MICBG_6DB (0x1 << ICDC_CR_MICBG_BIT)
1209  #define ICDC_CR_MICBG_12DB (0x2 << ICDC_CR_MICBG_BIT)
1210  #define ICDC_CR_MICBG_20DB (0x3 << ICDC_CR_MICBG_BIT)
1211#define ICDC_CR_HPVOL_BIT 16 /* Headphone Volume Gain */
1212#define ICDC_CR_HPVOL_MASK (0x3 << ICDC_CR_HPVOL_BIT)
1213  #define ICDC_CR_HPVOL_0DB (0x0 << ICDC_CR_HPVOL_BIT)
1214  #define ICDC_CR_HPVOL_2DB (0x1 << ICDC_CR_HPVOL_BIT)
1215  #define ICDC_CR_HPVOL_4DB (0x2 << ICDC_CR_HPVOL_BIT)
1216  #define ICDC_CR_HPVOL_6DB (0x3 << ICDC_CR_HPVOL_BIT)
1217#define ICDC_CR_ELINEIN (1 << 13) /* Enable LINE Input */
1218#define ICDC_CR_EMIC (1 << 12) /* Enable MIC Input */
1219#define ICDC_CR_SW1ON (1 << 11) /* Switch 1 in CODEC is on */
1220#define ICDC_CR_EADC (1 << 10) /* Enable ADC */
1221#define ICDC_CR_SW2ON (1 << 9) /* Switch 2 in CODEC is on */
1222#define ICDC_CR_EDAC (1 << 8) /* Enable DAC */
1223#define ICDC_CR_HPMUTE (1 << 5) /* Headphone Mute */
1224#define ICDC_CR_HPTON (1 << 4) /* Headphone Amplifier Trun On */
1225#define ICDC_CR_HPTOFF (1 << 3) /* Headphone Amplifier Trun Off */
1226#define ICDC_CR_TAAP (1 << 2) /* Turn Around of the Anti-Pop Procedure */
1227#define ICDC_CR_EAP (1 << 1) /* Enable Anti-Pop Procedure */
1228#define ICDC_CR_SUSPD (1 << 0) /* CODEC Suspend */
1229
1230/* Anti-Pop WAIT Stage Timing Control Register */
1231#define ICDC_APWAIT_WAITSN_BIT 0
1232#define ICDC_APWAIT_WAITSN_MASK (0x7ff << ICDC_APWAIT_WAITSN_BIT)
1233
1234/* Anti-Pop HPEN-PRE Stage Timing Control Register */
1235#define ICDC_APPRE_PRESN_BIT 0
1236#define ICDC_APPRE_PRESN_MASK (0x1ff << ICDC_APPRE_PRESN_BIT)
1237
1238/* Anti-Pop HPEN Stage Timing Control Register */
1239#define ICDC_APHPEN_HPENSN_BIT 0
1240#define ICDC_APHPEN_HPENSN_MASK (0x3fff << ICDC_APHPEN_HPENSN_BIT)
1241
1242/* Anti-Pop Status Register */
1243#define ICDC_SR_HPST_BIT 14 /* Headphone Amplifier State */
1244#define ICDC_SR_HPST_MASK (0x7 << ICDC_SR_HPST_BIT)
1245#define ICDC_SR_HPST_HP_OFF (0x0 << ICDC_SR_HPST_BIT) /* HP amplifier is off */
1246#define ICDC_SR_HPST_TON_WAIT (0x1 << ICDC_SR_HPST_BIT) /* wait state in turn-on */
1247  #define ICDC_SR_HPST_TON_PRE (0x2 << ICDC_SR_HPST_BIT) /* pre-enable state in turn-on */
1248#define ICDC_SR_HPST_TON_HPEN (0x3 << ICDC_SR_HPST_BIT) /* HP enable state in turn-on */
1249  #define ICDC_SR_HPST_TOFF_HPEN (0x4 << ICDC_SR_HPST_BIT) /* HP enable state in turn-off */
1250  #define ICDC_SR_HPST_TOFF_PRE (0x5 << ICDC_SR_HPST_BIT) /* pre-enable state in turn-off */
1251  #define ICDC_SR_HPST_TOFF_WAIT (0x6 << ICDC_SR_HPST_BIT) /* wait state in turn-off */
1252  #define ICDC_SR_HPST_HP_ON (0x7 << ICDC_SR_HPST_BIT) /* HP amplifier is on */
1253#define ICDC_SR_SNCNT_BIT 0 /* Sample Number Counter */
1254#define ICDC_SR_SNCNT_MASK (0x3fff << ICDC_SR_SNCNT_BIT)
1255
1256
1257/*************************************************************************
1258 * I2C
1259 *************************************************************************/
1260#define I2C_DR (I2C_BASE + 0x000)
1261#define I2C_CR (I2C_BASE + 0x004)
1262#define I2C_SR (I2C_BASE + 0x008)
1263#define I2C_GR (I2C_BASE + 0x00C)
1264
1265#define REG_I2C_DR REG8(I2C_DR)
1266#define REG_I2C_CR REG8(I2C_CR)
1267#define REG_I2C_SR REG8(I2C_SR)
1268#define REG_I2C_GR REG16(I2C_GR)
1269
1270/* I2C Control Register (I2C_CR) */
1271
1272#define I2C_CR_IEN (1 << 4)
1273#define I2C_CR_STA (1 << 3)
1274#define I2C_CR_STO (1 << 2)
1275#define I2C_CR_AC (1 << 1)
1276#define I2C_CR_I2CE (1 << 0)
1277
1278/* I2C Status Register (I2C_SR) */
1279
1280#define I2C_SR_STX (1 << 4)
1281#define I2C_SR_BUSY (1 << 3)
1282#define I2C_SR_TEND (1 << 2)
1283#define I2C_SR_DRF (1 << 1)
1284#define I2C_SR_ACKF (1 << 0)
1285
1286
1287/*************************************************************************
1288 * SSI
1289 *************************************************************************/
1290#define SSI_DR (SSI_BASE + 0x000)
1291#define SSI_CR0 (SSI_BASE + 0x004)
1292#define SSI_CR1 (SSI_BASE + 0x008)
1293#define SSI_SR (SSI_BASE + 0x00C)
1294#define SSI_ITR (SSI_BASE + 0x010)
1295#define SSI_ICR (SSI_BASE + 0x014)
1296#define SSI_GR (SSI_BASE + 0x018)
1297
1298#define REG_SSI_DR REG32(SSI_DR)
1299#define REG_SSI_CR0 REG16(SSI_CR0)
1300#define REG_SSI_CR1 REG32(SSI_CR1)
1301#define REG_SSI_SR REG32(SSI_SR)
1302#define REG_SSI_ITR REG16(SSI_ITR)
1303#define REG_SSI_ICR REG8(SSI_ICR)
1304#define REG_SSI_GR REG16(SSI_GR)
1305
1306/* SSI Data Register (SSI_DR) */
1307
1308#define SSI_DR_GPC_BIT 0
1309#define SSI_DR_GPC_MASK (0x1ff << SSI_DR_GPC_BIT)
1310
1311/* SSI Control Register 0 (SSI_CR0) */
1312
1313#define SSI_CR0_SSIE (1 << 15)
1314#define SSI_CR0_TIE (1 << 14)
1315#define SSI_CR0_RIE (1 << 13)
1316#define SSI_CR0_TEIE (1 << 12)
1317#define SSI_CR0_REIE (1 << 11)
1318#define SSI_CR0_LOOP (1 << 10)
1319#define SSI_CR0_RFINE (1 << 9)
1320#define SSI_CR0_RFINC (1 << 8)
1321#define SSI_CR0_FSEL (1 << 6)
1322#define SSI_CR0_TFLUSH (1 << 2)
1323#define SSI_CR0_RFLUSH (1 << 1)
1324#define SSI_CR0_DISREV (1 << 0)
1325
1326/* SSI Control Register 1 (SSI_CR1) */
1327
1328#define SSI_CR1_FRMHL_BIT 30
1329#define SSI_CR1_FRMHL_MASK (0x3 << SSI_CR1_FRMHL_BIT)
1330  #define SSI_CR1_FRMHL_CELOW_CE2LOW (0 << SSI_CR1_FRMHL_BIT) /* SSI_CE_ is low valid and SSI_CE2_ is low valid */
1331  #define SSI_CR1_FRMHL_CEHIGH_CE2LOW (1 << SSI_CR1_FRMHL_BIT) /* SSI_CE_ is high valid and SSI_CE2_ is low valid */
1332  #define SSI_CR1_FRMHL_CELOW_CE2HIGH (2 << SSI_CR1_FRMHL_BIT) /* SSI_CE_ is low valid and SSI_CE2_ is high valid */
1333  #define SSI_CR1_FRMHL_CEHIGH_CE2HIGH (3 << SSI_CR1_FRMHL_BIT) /* SSI_CE_ is high valid and SSI_CE2_ is high valid */
1334#define SSI_CR1_TFVCK_BIT 28
1335#define SSI_CR1_TFVCK_MASK (0x3 << SSI_CR1_TFVCK_BIT)
1336  #define SSI_CR1_TFVCK_0 (0 << SSI_CR1_TFVCK_BIT)
1337  #define SSI_CR1_TFVCK_1 (1 << SSI_CR1_TFVCK_BIT)
1338  #define SSI_CR1_TFVCK_2 (2 << SSI_CR1_TFVCK_BIT)
1339  #define SSI_CR1_TFVCK_3 (3 << SSI_CR1_TFVCK_BIT)
1340#define SSI_CR1_TCKFI_BIT 26
1341#define SSI_CR1_TCKFI_MASK (0x3 << SSI_CR1_TCKFI_BIT)
1342  #define SSI_CR1_TCKFI_0 (0 << SSI_CR1_TCKFI_BIT)
1343  #define SSI_CR1_TCKFI_1 (1 << SSI_CR1_TCKFI_BIT)
1344  #define SSI_CR1_TCKFI_2 (2 << SSI_CR1_TCKFI_BIT)
1345  #define SSI_CR1_TCKFI_3 (3 << SSI_CR1_TCKFI_BIT)
1346#define SSI_CR1_LFST (1 << 25)
1347#define SSI_CR1_ITFRM (1 << 24)
1348#define SSI_CR1_UNFIN (1 << 23)
1349#define SSI_CR1_MULTS (1 << 22)
1350#define SSI_CR1_FMAT_BIT 20
1351#define SSI_CR1_FMAT_MASK (0x3 << SSI_CR1_FMAT_BIT)
1352  #define SSI_CR1_FMAT_SPI (0 << SSI_CR1_FMAT_BIT) /* Motorola¡¯s SPI format */
1353  #define SSI_CR1_FMAT_SSP (1 << SSI_CR1_FMAT_BIT) /* TI's SSP format */
1354  #define SSI_CR1_FMAT_MW1 (2 << SSI_CR1_FMAT_BIT) /* National Microwire 1 format */
1355  #define SSI_CR1_FMAT_MW2 (3 << SSI_CR1_FMAT_BIT) /* National Microwire 2 format */
1356#define SSI_CR1_MCOM_BIT 12
1357#define SSI_CR1_MCOM_MASK (0xf << SSI_CR1_MCOM_BIT)
1358  #define SSI_CR1_MCOM_1BIT (0x0 << SSI_CR1_MCOM_BIT) /* 1-bit command selected */
1359  #define SSI_CR1_MCOM_2BIT (0x1 << SSI_CR1_MCOM_BIT) /* 2-bit command selected */
1360  #define SSI_CR1_MCOM_3BIT (0x2 << SSI_CR1_MCOM_BIT) /* 3-bit command selected */
1361  #define SSI_CR1_MCOM_4BIT (0x3 << SSI_CR1_MCOM_BIT) /* 4-bit command selected */
1362  #define SSI_CR1_MCOM_5BIT (0x4 << SSI_CR1_MCOM_BIT) /* 5-bit command selected */
1363  #define SSI_CR1_MCOM_6BIT (0x5 << SSI_CR1_MCOM_BIT) /* 6-bit command selected */
1364  #define SSI_CR1_MCOM_7BIT (0x6 << SSI_CR1_MCOM_BIT) /* 7-bit command selected */
1365  #define SSI_CR1_MCOM_8BIT (0x7 << SSI_CR1_MCOM_BIT) /* 8-bit command selected */
1366  #define SSI_CR1_MCOM_9BIT (0x8 << SSI_CR1_MCOM_BIT) /* 9-bit command selected */
1367  #define SSI_CR1_MCOM_10BIT (0x9 << SSI_CR1_MCOM_BIT) /* 10-bit command selected */
1368  #define SSI_CR1_MCOM_11BIT (0xA << SSI_CR1_MCOM_BIT) /* 11-bit command selected */
1369  #define SSI_CR1_MCOM_12BIT (0xB << SSI_CR1_MCOM_BIT) /* 12-bit command selected */
1370  #define SSI_CR1_MCOM_13BIT (0xC << SSI_CR1_MCOM_BIT) /* 13-bit command selected */
1371  #define SSI_CR1_MCOM_14BIT (0xD << SSI_CR1_MCOM_BIT) /* 14-bit command selected */
1372  #define SSI_CR1_MCOM_15BIT (0xE << SSI_CR1_MCOM_BIT) /* 15-bit command selected */
1373  #define SSI_CR1_MCOM_16BIT (0xF << SSI_CR1_MCOM_BIT) /* 16-bit command selected */
1374#define SSI_CR1_TTRG_BIT 10
1375#define SSI_CR1_TTRG_MASK (0x3 << SSI_CR1_TTRG_BIT)
1376  #define SSI_CR1_TTRG_1 (0 << SSI_CR1_TTRG_BIT)/* Less than or equal to 1 */
1377  #define SSI_CR1_TTRG_4 (1 << SSI_CR1_TTRG_BIT) /* Less than or equal to 4 */
1378  #define SSI_CR1_TTRG_8 (2 << SSI_CR1_TTRG_BIT) /* Less than or equal to 8 */
1379  #define SSI_CR1_TTRG_14 (3 << SSI_CR1_TTRG_BIT) /* Less than or equal to 14 */
1380#define SSI_CR1_RTRG_BIT 8
1381#define SSI_CR1_RTRG_MASK (0x3 << SSI_CR1_RTRG_BIT)
1382  #define SSI_CR1_RTRG_1 (0 << SSI_CR1_RTRG_BIT) /* More than or equal to 1 */
1383  #define SSI_CR1_RTRG_4 (1 << SSI_CR1_RTRG_BIT) /* More than or equal to 4 */
1384  #define SSI_CR1_RTRG_8 (2 << SSI_CR1_RTRG_BIT) /* More than or equal to 8 */
1385  #define SSI_CR1_RTRG_14 (3 << SSI_CR1_RTRG_BIT) /* More than or equal to 14 */
1386#define SSI_CR1_FLEN_BIT 4
1387#define SSI_CR1_FLEN_MASK (0xf << SSI_CR1_FLEN_BIT)
1388  #define SSI_CR1_FLEN_2BIT (0x0 << SSI_CR1_FLEN_BIT)
1389  #define SSI_CR1_FLEN_3BIT (0x1 << SSI_CR1_FLEN_BIT)
1390  #define SSI_CR1_FLEN_4BIT (0x2 << SSI_CR1_FLEN_BIT)
1391  #define SSI_CR1_FLEN_5BIT (0x3 << SSI_CR1_FLEN_BIT)
1392  #define SSI_CR1_FLEN_6BIT (0x4 << SSI_CR1_FLEN_BIT)
1393  #define SSI_CR1_FLEN_7BIT (0x5 << SSI_CR1_FLEN_BIT)
1394  #define SSI_CR1_FLEN_8BIT (0x6 << SSI_CR1_FLEN_BIT)
1395  #define SSI_CR1_FLEN_9BIT (0x7 << SSI_CR1_FLEN_BIT)
1396  #define SSI_CR1_FLEN_10BIT (0x8 << SSI_CR1_FLEN_BIT)
1397  #define SSI_CR1_FLEN_11BIT (0x9 << SSI_CR1_FLEN_BIT)
1398  #define SSI_CR1_FLEN_12BIT (0xA << SSI_CR1_FLEN_BIT)
1399  #define SSI_CR1_FLEN_13BIT (0xB << SSI_CR1_FLEN_BIT)
1400  #define SSI_CR1_FLEN_14BIT (0xC << SSI_CR1_FLEN_BIT)
1401  #define SSI_CR1_FLEN_15BIT (0xD << SSI_CR1_FLEN_BIT)
1402  #define SSI_CR1_FLEN_16BIT (0xE << SSI_CR1_FLEN_BIT)
1403  #define SSI_CR1_FLEN_17BIT (0xF << SSI_CR1_FLEN_BIT)
1404#define SSI_CR1_PHA (1 << 1)
1405#define SSI_CR1_POL (1 << 0)
1406
1407/* SSI Status Register (SSI_SR) */
1408
1409#define SSI_SR_TFIFONUM_BIT 13
1410#define SSI_SR_TFIFONUM_MASK (0x1f << SSI_SR_TFIFONUM_BIT)
1411#define SSI_SR_RFIFONUM_BIT 8
1412#define SSI_SR_RFIFONUM_MASK (0x1f << SSI_SR_RFIFONUM_BIT)
1413#define SSI_SR_END (1 << 7)
1414#define SSI_SR_BUSY (1 << 6)
1415#define SSI_SR_TFF (1 << 5)
1416#define SSI_SR_RFE (1 << 4)
1417#define SSI_SR_TFHE (1 << 3)
1418#define SSI_SR_RFHF (1 << 2)
1419#define SSI_SR_UNDR (1 << 1)
1420#define SSI_SR_OVER (1 << 0)
1421
1422/* SSI Interval Time Control Register (SSI_ITR) */
1423
1424#define SSI_ITR_CNTCLK (1 << 15)
1425#define SSI_ITR_IVLTM_BIT 0
1426#define SSI_ITR_IVLTM_MASK (0x7fff << SSI_ITR_IVLTM_BIT)
1427
1428
1429/*************************************************************************
1430 * MSC
1431 *************************************************************************/
1432#define MSC_STRPCL (MSC_BASE + 0x000)
1433#define MSC_STAT (MSC_BASE + 0x004)
1434#define MSC_CLKRT (MSC_BASE + 0x008)
1435#define MSC_CMDAT (MSC_BASE + 0x00C)
1436#define MSC_RESTO (MSC_BASE + 0x010)
1437#define MSC_RDTO (MSC_BASE + 0x014)
1438#define MSC_BLKLEN (MSC_BASE + 0x018)
1439#define MSC_NOB (MSC_BASE + 0x01C)
1440#define MSC_SNOB (MSC_BASE + 0x020)
1441#define MSC_IMASK (MSC_BASE + 0x024)
1442#define MSC_IREG (MSC_BASE + 0x028)
1443#define MSC_CMD (MSC_BASE + 0x02C)
1444#define MSC_ARG (MSC_BASE + 0x030)
1445#define MSC_RES (MSC_BASE + 0x034)
1446#define MSC_RXFIFO (MSC_BASE + 0x038)
1447#define MSC_TXFIFO (MSC_BASE + 0x03C)
1448
1449#define REG_MSC_STRPCL REG16(MSC_STRPCL)
1450#define REG_MSC_STAT REG32(MSC_STAT)
1451#define REG_MSC_CLKRT REG16(MSC_CLKRT)
1452#define REG_MSC_CMDAT REG32(MSC_CMDAT)
1453#define REG_MSC_RESTO REG16(MSC_RESTO)
1454#define REG_MSC_RDTO REG16(MSC_RDTO)
1455#define REG_MSC_BLKLEN REG16(MSC_BLKLEN)
1456#define REG_MSC_NOB REG16(MSC_NOB)
1457#define REG_MSC_SNOB REG16(MSC_SNOB)
1458#define REG_MSC_IMASK REG16(MSC_IMASK)
1459#define REG_MSC_IREG REG16(MSC_IREG)
1460#define REG_MSC_CMD REG8(MSC_CMD)
1461#define REG_MSC_ARG REG32(MSC_ARG)
1462#define REG_MSC_RES REG16(MSC_RES)
1463#define REG_MSC_RXFIFO REG32(MSC_RXFIFO)
1464#define REG_MSC_TXFIFO REG32(MSC_TXFIFO)
1465
1466/* MSC Clock and Control Register (MSC_STRPCL) */
1467
1468#define MSC_STRPCL_EXIT_MULTIPLE (1 << 7)
1469#define MSC_STRPCL_EXIT_TRANSFER (1 << 6)
1470#define MSC_STRPCL_START_READWAIT (1 << 5)
1471#define MSC_STRPCL_STOP_READWAIT (1 << 4)
1472#define MSC_STRPCL_RESET (1 << 3)
1473#define MSC_STRPCL_START_OP (1 << 2)
1474#define MSC_STRPCL_CLOCK_CONTROL_BIT 0
1475#define MSC_STRPCL_CLOCK_CONTROL_MASK (0x3 << MSC_STRPCL_CLOCK_CONTROL_BIT)
1476  #define MSC_STRPCL_CLOCK_CONTROL_STOP (0x1 << MSC_STRPCL_CLOCK_CONTROL_BIT) /* Stop MMC/SD clock */
1477  #define MSC_STRPCL_CLOCK_CONTROL_START (0x2 << MSC_STRPCL_CLOCK_CONTROL_BIT) /* Start MMC/SD clock */
1478
1479/* MSC Status Register (MSC_STAT) */
1480
1481#define MSC_STAT_IS_RESETTING (1 << 15)
1482#define MSC_STAT_SDIO_INT_ACTIVE (1 << 14)
1483#define MSC_STAT_PRG_DONE (1 << 13)
1484#define MSC_STAT_DATA_TRAN_DONE (1 << 12)
1485#define MSC_STAT_END_CMD_RES (1 << 11)
1486#define MSC_STAT_DATA_FIFO_AFULL (1 << 10)
1487#define MSC_STAT_IS_READWAIT (1 << 9)
1488#define MSC_STAT_CLK_EN (1 << 8)
1489#define MSC_STAT_DATA_FIFO_FULL (1 << 7)
1490#define MSC_STAT_DATA_FIFO_EMPTY (1 << 6)
1491#define MSC_STAT_CRC_RES_ERR (1 << 5)
1492#define MSC_STAT_CRC_READ_ERROR (1 << 4)
1493#define MSC_STAT_CRC_WRITE_ERROR_BIT 2
1494#define MSC_STAT_CRC_WRITE_ERROR_MASK (0x3 << MSC_STAT_CRC_WRITE_ERROR_BIT)
1495  #define MSC_STAT_CRC_WRITE_ERROR_NO (0 << MSC_STAT_CRC_WRITE_ERROR_BIT) /* No error on transmission of data */
1496  #define MSC_STAT_CRC_WRITE_ERROR (1 << MSC_STAT_CRC_WRITE_ERROR_BIT) /* Card observed erroneous transmission of data */
1497  #define MSC_STAT_CRC_WRITE_ERROR_NOSTS (2 << MSC_STAT_CRC_WRITE_ERROR_BIT) /* No CRC status is sent back */
1498#define MSC_STAT_TIME_OUT_RES (1 << 1)
1499#define MSC_STAT_TIME_OUT_READ (1 << 0)
1500
1501/* MSC Bus Clock Control Register (MSC_CLKRT) */
1502
1503#define MSC_CLKRT_CLK_RATE_BIT 0
1504#define MSC_CLKRT_CLK_RATE_MASK (0x7 << MSC_CLKRT_CLK_RATE_BIT)
1505  #define MSC_CLKRT_CLK_RATE_DIV_1 (0x0 << MSC_CLKRT_CLK_RATE_BIT) /* CLK_SRC */
1506  #define MSC_CLKRT_CLK_RATE_DIV_2 (0x1 << MSC_CLKRT_CLK_RATE_BIT) /* 1/2 of CLK_SRC */
1507  #define MSC_CLKRT_CLK_RATE_DIV_4 (0x2 << MSC_CLKRT_CLK_RATE_BIT) /* 1/4 of CLK_SRC */
1508  #define MSC_CLKRT_CLK_RATE_DIV_8 (0x3 << MSC_CLKRT_CLK_RATE_BIT) /* 1/8 of CLK_SRC */
1509  #define MSC_CLKRT_CLK_RATE_DIV_16 (0x4 << MSC_CLKRT_CLK_RATE_BIT) /* 1/16 of CLK_SRC */
1510  #define MSC_CLKRT_CLK_RATE_DIV_32 (0x5 << MSC_CLKRT_CLK_RATE_BIT) /* 1/32 of CLK_SRC */
1511  #define MSC_CLKRT_CLK_RATE_DIV_64 (0x6 << MSC_CLKRT_CLK_RATE_BIT) /* 1/64 of CLK_SRC */
1512  #define MSC_CLKRT_CLK_RATE_DIV_128 (0x7 << MSC_CLKRT_CLK_RATE_BIT) /* 1/128 of CLK_SRC */
1513
1514/* MSC Command Sequence Control Register (MSC_CMDAT) */
1515
1516#define MSC_CMDAT_IO_ABORT (1 << 11)
1517#define MSC_CMDAT_BUS_WIDTH_BIT 9
1518#define MSC_CMDAT_BUS_WIDTH_MASK (0x3 << MSC_CMDAT_BUS_WIDTH_BIT)
1519  #define MSC_CMDAT_BUS_WIDTH_1BIT (0x0 << MSC_CMDAT_BUS_WIDTH_BIT) /* 1-bit data bus */
1520  #define MSC_CMDAT_BUS_WIDTH_4BIT (0x2 << MSC_CMDAT_BUS_WIDTH_BIT) /* 4-bit data bus */
1521  #define CMDAT_BUS_WIDTH1 (0x0 << MSC_CMDAT_BUS_WIDTH_BIT)
1522  #define CMDAT_BUS_WIDTH4 (0x2 << MSC_CMDAT_BUS_WIDTH_BIT)
1523#define MSC_CMDAT_DMA_EN (1 << 8)
1524#define MSC_CMDAT_INIT (1 << 7)
1525#define MSC_CMDAT_BUSY (1 << 6)
1526#define MSC_CMDAT_STREAM_BLOCK (1 << 5)
1527#define MSC_CMDAT_WRITE (1 << 4)
1528#define MSC_CMDAT_READ (0 << 4)
1529#define MSC_CMDAT_DATA_EN (1 << 3)
1530#define MSC_CMDAT_RESPONSE_BIT 0
1531#define MSC_CMDAT_RESPONSE_MASK (0x7 << MSC_CMDAT_RESPONSE_BIT)
1532  #define MSC_CMDAT_RESPONSE_NONE (0x0 << MSC_CMDAT_RESPONSE_BIT) /* No response */
1533  #define MSC_CMDAT_RESPONSE_R1 (0x1 << MSC_CMDAT_RESPONSE_BIT) /* Format R1 and R1b */
1534  #define MSC_CMDAT_RESPONSE_R2 (0x2 << MSC_CMDAT_RESPONSE_BIT) /* Format R2 */
1535  #define MSC_CMDAT_RESPONSE_R3 (0x3 << MSC_CMDAT_RESPONSE_BIT) /* Format R3 */
1536  #define MSC_CMDAT_RESPONSE_R4 (0x4 << MSC_CMDAT_RESPONSE_BIT) /* Format R4 */
1537  #define MSC_CMDAT_RESPONSE_R5 (0x5 << MSC_CMDAT_RESPONSE_BIT) /* Format R5 */
1538  #define MSC_CMDAT_RESPONSE_R6 (0x6 << MSC_CMDAT_RESPONSE_BIT) /* Format R6 */
1539
1540#define CMDAT_DMA_EN (1 << 8)
1541#define CMDAT_INIT (1 << 7)
1542#define CMDAT_BUSY (1 << 6)
1543#define CMDAT_STREAM (1 << 5)
1544#define CMDAT_WRITE (1 << 4)
1545#define CMDAT_DATA_EN (1 << 3)
1546
1547/* MSC Interrupts Mask Register (MSC_IMASK) */
1548
1549#define MSC_IMASK_SDIO (1 << 7)
1550#define MSC_IMASK_TXFIFO_WR_REQ (1 << 6)
1551#define MSC_IMASK_RXFIFO_RD_REQ (1 << 5)
1552#define MSC_IMASK_END_CMD_RES (1 << 2)
1553#define MSC_IMASK_PRG_DONE (1 << 1)
1554#define MSC_IMASK_DATA_TRAN_DONE (1 << 0)
1555
1556
1557/* MSC Interrupts Status Register (MSC_IREG) */
1558
1559#define MSC_IREG_SDIO (1 << 7)
1560#define MSC_IREG_TXFIFO_WR_REQ (1 << 6)
1561#define MSC_IREG_RXFIFO_RD_REQ (1 << 5)
1562#define MSC_IREG_END_CMD_RES (1 << 2)
1563#define MSC_IREG_PRG_DONE (1 << 1)
1564#define MSC_IREG_DATA_TRAN_DONE (1 << 0)
1565
1566
1567/*************************************************************************
1568 * EMC (External Memory Controller)
1569 *************************************************************************/
1570#define EMC_BCR (EMC_BASE + 0x10) /* BCR */
1571
1572#define EMC_SMCR0 (EMC_BASE + 0x10) /* Static Memory Control Register 0 */
1573#define EMC_SMCR1 (EMC_BASE + 0x14) /* Static Memory Control Register 1 */
1574#define EMC_SMCR2 (EMC_BASE + 0x18) /* Static Memory Control Register 2 */
1575#define EMC_SMCR3 (EMC_BASE + 0x1c) /* Static Memory Control Register 3 */
1576#define EMC_SMCR4 (EMC_BASE + 0x20) /* Static Memory Control Register 4 */
1577#define EMC_SACR0 (EMC_BASE + 0x30) /* Static Memory Bank 0 Addr Config Reg */
1578#define EMC_SACR1 (EMC_BASE + 0x34) /* Static Memory Bank 1 Addr Config Reg */
1579#define EMC_SACR2 (EMC_BASE + 0x38) /* Static Memory Bank 2 Addr Config Reg */
1580#define EMC_SACR3 (EMC_BASE + 0x3c) /* Static Memory Bank 3 Addr Config Reg */
1581#define EMC_SACR4 (EMC_BASE + 0x40) /* Static Memory Bank 4 Addr Config Reg */
1582
1583#define EMC_NFCSR (EMC_BASE + 0x050) /* NAND Flash Control/Status Register */
1584#define EMC_NFECR (EMC_BASE + 0x100) /* NAND Flash ECC Control Register */
1585#define EMC_NFECC (EMC_BASE + 0x104) /* NAND Flash ECC Data Register */
1586#define EMC_NFPAR0 (EMC_BASE + 0x108) /* NAND Flash RS Parity 0 Register */
1587#define EMC_NFPAR1 (EMC_BASE + 0x10c) /* NAND Flash RS Parity 1 Register */
1588#define EMC_NFPAR2 (EMC_BASE + 0x110) /* NAND Flash RS Parity 2 Register */
1589#define EMC_NFINTS (EMC_BASE + 0x114) /* NAND Flash Interrupt Status Register */
1590#define EMC_NFINTE (EMC_BASE + 0x118) /* NAND Flash Interrupt Enable Register */
1591#define EMC_NFERR0 (EMC_BASE + 0x11c) /* NAND Flash RS Error Report 0 Register */
1592#define EMC_NFERR1 (EMC_BASE + 0x120) /* NAND Flash RS Error Report 1 Register */
1593#define EMC_NFERR2 (EMC_BASE + 0x124) /* NAND Flash RS Error Report 2 Register */
1594#define EMC_NFERR3 (EMC_BASE + 0x128) /* NAND Flash RS Error Report 3 Register */
1595
1596#define EMC_DMCR (EMC_BASE + 0x80) /* DRAM Control Register */
1597#define EMC_RTCSR (EMC_BASE + 0x84) /* Refresh Time Control/Status Register */
1598#define EMC_RTCNT (EMC_BASE + 0x88) /* Refresh Timer Counter */
1599#define EMC_RTCOR (EMC_BASE + 0x8c) /* Refresh Time Constant Register */
1600#define EMC_DMAR0 (EMC_BASE + 0x90) /* SDRAM Bank 0 Addr Config Register */
1601#define EMC_SDMR0 (EMC_BASE + 0xa000) /* Mode Register of SDRAM bank 0 */
1602
1603#define REG_EMC_BCR REG32(EMC_BCR)
1604
1605#define REG_EMC_SMCR0 REG32(EMC_SMCR0)
1606#define REG_EMC_SMCR1 REG32(EMC_SMCR1)
1607#define REG_EMC_SMCR2 REG32(EMC_SMCR2)
1608#define REG_EMC_SMCR3 REG32(EMC_SMCR3)
1609#define REG_EMC_SMCR4 REG32(EMC_SMCR4)
1610#define REG_EMC_SACR0 REG32(EMC_SACR0)
1611#define REG_EMC_SACR1 REG32(EMC_SACR1)
1612#define REG_EMC_SACR2 REG32(EMC_SACR2)
1613#define REG_EMC_SACR3 REG32(EMC_SACR3)
1614#define REG_EMC_SACR4 REG32(EMC_SACR4)
1615
1616#define REG_EMC_NFCSR REG32(EMC_NFCSR)
1617#define REG_EMC_NFECR REG32(EMC_NFECR)
1618#define REG_EMC_NFECC REG32(EMC_NFECC)
1619#define REG_EMC_NFPAR0 REG32(EMC_NFPAR0)
1620#define REG_EMC_NFPAR1 REG32(EMC_NFPAR1)
1621#define REG_EMC_NFPAR2 REG32(EMC_NFPAR2)
1622#define REG_EMC_NFINTS REG32(EMC_NFINTS)
1623#define REG_EMC_NFINTE REG32(EMC_NFINTE)
1624#define REG_EMC_NFERR0 REG32(EMC_NFERR0)
1625#define REG_EMC_NFERR1 REG32(EMC_NFERR1)
1626#define REG_EMC_NFERR2 REG32(EMC_NFERR2)
1627#define REG_EMC_NFERR3 REG32(EMC_NFERR3)
1628
1629#define REG_EMC_DMCR REG32(EMC_DMCR)
1630#define REG_EMC_RTCSR REG16(EMC_RTCSR)
1631#define REG_EMC_RTCNT REG16(EMC_RTCNT)
1632#define REG_EMC_RTCOR REG16(EMC_RTCOR)
1633#define REG_EMC_DMAR0 REG32(EMC_DMAR0)
1634
1635/* Static Memory Control Register */
1636#define EMC_SMCR_STRV_BIT 24
1637#define EMC_SMCR_STRV_MASK (0x0f << EMC_SMCR_STRV_BIT)
1638#define EMC_SMCR_TAW_BIT 20
1639#define EMC_SMCR_TAW_MASK (0x0f << EMC_SMCR_TAW_BIT)
1640#define EMC_SMCR_TBP_BIT 16
1641#define EMC_SMCR_TBP_MASK (0x0f << EMC_SMCR_TBP_BIT)
1642#define EMC_SMCR_TAH_BIT 12
1643#define EMC_SMCR_TAH_MASK (0x07 << EMC_SMCR_TAH_BIT)
1644#define EMC_SMCR_TAS_BIT 8
1645#define EMC_SMCR_TAS_MASK (0x07 << EMC_SMCR_TAS_BIT)
1646#define EMC_SMCR_BW_BIT 6
1647#define EMC_SMCR_BW_MASK (0x03 << EMC_SMCR_BW_BIT)
1648  #define EMC_SMCR_BW_8BIT (0 << EMC_SMCR_BW_BIT)
1649  #define EMC_SMCR_BW_16BIT (1 << EMC_SMCR_BW_BIT)
1650  #define EMC_SMCR_BW_32BIT (2 << EMC_SMCR_BW_BIT)
1651#define EMC_SMCR_BCM (1 << 3)
1652#define EMC_SMCR_BL_BIT 1
1653#define EMC_SMCR_BL_MASK (0x03 << EMC_SMCR_BL_BIT)
1654  #define EMC_SMCR_BL_4 (0 << EMC_SMCR_BL_BIT)
1655  #define EMC_SMCR_BL_8 (1 << EMC_SMCR_BL_BIT)
1656  #define EMC_SMCR_BL_16 (2 << EMC_SMCR_BL_BIT)
1657  #define EMC_SMCR_BL_32 (3 << EMC_SMCR_BL_BIT)
1658#define EMC_SMCR_SMT (1 << 0)
1659
1660/* Static Memory Bank Addr Config Reg */
1661#define EMC_SACR_BASE_BIT 8
1662#define EMC_SACR_BASE_MASK (0xff << EMC_SACR_BASE_BIT)
1663#define EMC_SACR_MASK_BIT 0
1664#define EMC_SACR_MASK_MASK (0xff << EMC_SACR_MASK_BIT)
1665
1666/* NAND Flash Control/Status Register */
1667#define EMC_NFCSR_NFCE4 (1 << 7) /* NAND Flash Enable */
1668#define EMC_NFCSR_NFE4 (1 << 6) /* NAND Flash FCE# Assertion Enable */
1669#define EMC_NFCSR_NFCE3 (1 << 5)
1670#define EMC_NFCSR_NFE3 (1 << 4)
1671#define EMC_NFCSR_NFCE2 (1 << 3)
1672#define EMC_NFCSR_NFE2 (1 << 2)
1673#define EMC_NFCSR_NFCE1 (1 << 1)
1674#define EMC_NFCSR_NFE1 (1 << 0)
1675
1676/* NAND Flash ECC Control Register */
1677#define EMC_NFECR_PRDY (1 << 4) /* Parity Ready */
1678#define EMC_NFECR_RS_DECODING (0 << 3) /* RS is in decoding phase */
1679#define EMC_NFECR_RS_ENCODING (1 << 3) /* RS is in encoding phase */
1680#define EMC_NFECR_HAMMING (0 << 2) /* Select HAMMING Correction Algorithm */
1681#define EMC_NFECR_RS (1 << 2) /* Select RS Correction Algorithm */
1682#define EMC_NFECR_ERST (1 << 1) /* ECC Reset */
1683#define EMC_NFECR_ECCE (1 << 0) /* ECC Enable */
1684
1685/* NAND Flash ECC Data Register */
1686#define EMC_NFECC_ECC2_BIT 16
1687#define EMC_NFECC_ECC2_MASK (0xff << EMC_NFECC_ECC2_BIT)
1688#define EMC_NFECC_ECC1_BIT 8
1689#define EMC_NFECC_ECC1_MASK (0xff << EMC_NFECC_ECC1_BIT)
1690#define EMC_NFECC_ECC0_BIT 0
1691#define EMC_NFECC_ECC0_MASK (0xff << EMC_NFECC_ECC0_BIT)
1692
1693/* NAND Flash Interrupt Status Register */
1694#define EMC_NFINTS_ERRCNT_BIT 29 /* Error Count */
1695#define EMC_NFINTS_ERRCNT_MASK (0x7 << EMC_NFINTS_ERRCNT_BIT)
1696#define EMC_NFINTS_PADF (1 << 4) /* Padding Finished */
1697#define EMC_NFINTS_DECF (1 << 3) /* Decoding Finished */
1698#define EMC_NFINTS_ENCF (1 << 2) /* Encoding Finished */
1699#define EMC_NFINTS_UNCOR (1 << 1) /* Uncorrectable Error Occurred */
1700#define EMC_NFINTS_ERR (1 << 0) /* Error Occurred */
1701
1702/* NAND Flash Interrupt Enable Register */
1703#define EMC_NFINTE_PADFE (1 << 4) /* Padding Finished Interrupt Enable */
1704#define EMC_NFINTE_DECFE (1 << 3) /* Decoding Finished Interrupt Enable */
1705#define EMC_NFINTE_ENCFE (1 << 2) /* Encoding Finished Interrupt Enable */
1706#define EMC_NFINTE_UNCORE (1 << 1) /* Uncorrectable Error Occurred Intr Enable */
1707#define EMC_NFINTE_ERRE (1 << 0) /* Error Occurred Interrupt */
1708
1709/* NAND Flash RS Error Report Register */
1710#define EMC_NFERR_INDEX_BIT 16 /* Error Symbol Index */
1711#define EMC_NFERR_INDEX_MASK (0x1ff << EMC_NFERR_INDEX_BIT)
1712#define EMC_NFERR_MASK_BIT 0 /* Error Symbol Value */
1713#define EMC_NFERR_MASK_MASK (0x1ff << EMC_NFERR_MASK_BIT)
1714
1715
1716/* DRAM Control Register */
1717#define EMC_DMCR_BW_BIT 31
1718#define EMC_DMCR_BW (1 << EMC_DMCR_BW_BIT)
1719#define EMC_DMCR_CA_BIT 26
1720#define EMC_DMCR_CA_MASK (0x07 << EMC_DMCR_CA_BIT)
1721  #define EMC_DMCR_CA_8 (0 << EMC_DMCR_CA_BIT)
1722  #define EMC_DMCR_CA_9 (1 << EMC_DMCR_CA_BIT)
1723  #define EMC_DMCR_CA_10 (2 << EMC_DMCR_CA_BIT)
1724  #define EMC_DMCR_CA_11 (3 << EMC_DMCR_CA_BIT)
1725  #define EMC_DMCR_CA_12 (4 << EMC_DMCR_CA_BIT)
1726#define EMC_DMCR_RMODE (1 << 25)
1727#define EMC_DMCR_RFSH (1 << 24)
1728#define EMC_DMCR_MRSET (1 << 23)
1729#define EMC_DMCR_RA_BIT 20
1730#define EMC_DMCR_RA_MASK (0x03 << EMC_DMCR_RA_BIT)
1731  #define EMC_DMCR_RA_11 (0 << EMC_DMCR_RA_BIT)
1732  #define EMC_DMCR_RA_12 (1 << EMC_DMCR_RA_BIT)
1733  #define EMC_DMCR_RA_13 (2 << EMC_DMCR_RA_BIT)
1734#define EMC_DMCR_BA_BIT 19
1735#define EMC_DMCR_BA (1 << EMC_DMCR_BA_BIT)
1736#define EMC_DMCR_PDM (1 << 18)
1737#define EMC_DMCR_EPIN (1 << 17)
1738#define EMC_DMCR_TRAS_BIT 13
1739#define EMC_DMCR_TRAS_MASK (0x07 << EMC_DMCR_TRAS_BIT)
1740#define EMC_DMCR_RCD_BIT 11
1741#define EMC_DMCR_RCD_MASK (0x03 << EMC_DMCR_RCD_BIT)
1742#define EMC_DMCR_TPC_BIT 8
1743#define EMC_DMCR_TPC_MASK (0x07 << EMC_DMCR_TPC_BIT)
1744#define EMC_DMCR_TRWL_BIT 5
1745#define EMC_DMCR_TRWL_MASK (0x03 << EMC_DMCR_TRWL_BIT)
1746#define EMC_DMCR_TRC_BIT 2
1747#define EMC_DMCR_TRC_MASK (0x07 << EMC_DMCR_TRC_BIT)
1748#define EMC_DMCR_TCL_BIT 0
1749#define EMC_DMCR_TCL_MASK (0x03 << EMC_DMCR_TCL_BIT)
1750
1751/* Refresh Time Control/Status Register */
1752#define EMC_RTCSR_CMF (1 << 7)
1753#define EMC_RTCSR_CKS_BIT 0
1754#define EMC_RTCSR_CKS_MASK (0x07 << EMC_RTCSR_CKS_BIT)
1755  #define EMC_RTCSR_CKS_DISABLE (0 << EMC_RTCSR_CKS_BIT)
1756  #define EMC_RTCSR_CKS_4 (1 << EMC_RTCSR_CKS_BIT)
1757  #define EMC_RTCSR_CKS_16 (2 << EMC_RTCSR_CKS_BIT)
1758  #define EMC_RTCSR_CKS_64 (3 << EMC_RTCSR_CKS_BIT)
1759  #define EMC_RTCSR_CKS_256 (4 << EMC_RTCSR_CKS_BIT)
1760  #define EMC_RTCSR_CKS_1024 (5 << EMC_RTCSR_CKS_BIT)
1761  #define EMC_RTCSR_CKS_2048 (6 << EMC_RTCSR_CKS_BIT)
1762  #define EMC_RTCSR_CKS_4096 (7 << EMC_RTCSR_CKS_BIT)
1763
1764/* SDRAM Bank Address Configuration Register */
1765#define EMC_DMAR_BASE_BIT 8
1766#define EMC_DMAR_BASE_MASK (0xff << EMC_DMAR_BASE_BIT)
1767#define EMC_DMAR_MASK_BIT 0
1768#define EMC_DMAR_MASK_MASK (0xff << EMC_DMAR_MASK_BIT)
1769
1770/* Mode Register of SDRAM bank 0 */
1771#define EMC_SDMR_BM (1 << 9) /* Write Burst Mode */
1772#define EMC_SDMR_OM_BIT 7 /* Operating Mode */
1773#define EMC_SDMR_OM_MASK (3 << EMC_SDMR_OM_BIT)
1774  #define EMC_SDMR_OM_NORMAL (0 << EMC_SDMR_OM_BIT)
1775#define EMC_SDMR_CAS_BIT 4 /* CAS Latency */
1776#define EMC_SDMR_CAS_MASK (7 << EMC_SDMR_CAS_BIT)
1777  #define EMC_SDMR_CAS_1 (1 << EMC_SDMR_CAS_BIT)
1778  #define EMC_SDMR_CAS_2 (2 << EMC_SDMR_CAS_BIT)
1779  #define EMC_SDMR_CAS_3 (3 << EMC_SDMR_CAS_BIT)
1780#define EMC_SDMR_BT_BIT 3 /* Burst Type */
1781#define EMC_SDMR_BT_MASK (1 << EMC_SDMR_BT_BIT)
1782  #define EMC_SDMR_BT_SEQ (0 << EMC_SDMR_BT_BIT) /* Sequential */
1783  #define EMC_SDMR_BT_INT (1 << EMC_SDMR_BT_BIT) /* Interleave */
1784#define EMC_SDMR_BL_BIT 0 /* Burst Length */
1785#define EMC_SDMR_BL_MASK (7 << EMC_SDMR_BL_BIT)
1786  #define EMC_SDMR_BL_1 (0 << EMC_SDMR_BL_BIT)
1787  #define EMC_SDMR_BL_2 (1 << EMC_SDMR_BL_BIT)
1788  #define EMC_SDMR_BL_4 (2 << EMC_SDMR_BL_BIT)
1789  #define EMC_SDMR_BL_8 (3 << EMC_SDMR_BL_BIT)
1790
1791#define EMC_SDMR_CAS2_16BIT \
1792  (EMC_SDMR_CAS_2 | EMC_SDMR_BT_SEQ | EMC_SDMR_BL_2)
1793#define EMC_SDMR_CAS2_32BIT \
1794  (EMC_SDMR_CAS_2 | EMC_SDMR_BT_SEQ | EMC_SDMR_BL_4)
1795#define EMC_SDMR_CAS3_16BIT \
1796  (EMC_SDMR_CAS_3 | EMC_SDMR_BT_SEQ | EMC_SDMR_BL_2)
1797#define EMC_SDMR_CAS3_32BIT \
1798  (EMC_SDMR_CAS_3 | EMC_SDMR_BT_SEQ | EMC_SDMR_BL_4)
1799
1800
1801/*************************************************************************
1802 * CIM
1803 *************************************************************************/
1804#define CIM_CFG (CIM_BASE + 0x0000)
1805#define CIM_CTRL (CIM_BASE + 0x0004)
1806#define CIM_STATE (CIM_BASE + 0x0008)
1807#define CIM_IID (CIM_BASE + 0x000C)
1808#define CIM_RXFIFO (CIM_BASE + 0x0010)
1809#define CIM_DA (CIM_BASE + 0x0020)
1810#define CIM_FA (CIM_BASE + 0x0024)
1811#define CIM_FID (CIM_BASE + 0x0028)
1812#define CIM_CMD (CIM_BASE + 0x002C)
1813
1814#define REG_CIM_CFG REG32(CIM_CFG)
1815#define REG_CIM_CTRL REG32(CIM_CTRL)
1816#define REG_CIM_STATE REG32(CIM_STATE)
1817#define REG_CIM_IID REG32(CIM_IID)
1818#define REG_CIM_RXFIFO REG32(CIM_RXFIFO)
1819#define REG_CIM_DA REG32(CIM_DA)
1820#define REG_CIM_FA REG32(CIM_FA)
1821#define REG_CIM_FID REG32(CIM_FID)
1822#define REG_CIM_CMD REG32(CIM_CMD)
1823
1824/* CIM Configuration Register (CIM_CFG) */
1825
1826#define CIM_CFG_INV_DAT (1 << 15)
1827#define CIM_CFG_VSP (1 << 14)
1828#define CIM_CFG_HSP (1 << 13)
1829#define CIM_CFG_PCP (1 << 12)
1830#define CIM_CFG_DUMMY_ZERO (1 << 9)
1831#define CIM_CFG_EXT_VSYNC (1 << 8)
1832#define CIM_CFG_PACK_BIT 4
1833#define CIM_CFG_PACK_MASK (0x7 << CIM_CFG_PACK_BIT)
1834  #define CIM_CFG_PACK_0 (0 << CIM_CFG_PACK_BIT)
1835  #define CIM_CFG_PACK_1 (1 << CIM_CFG_PACK_BIT)
1836  #define CIM_CFG_PACK_2 (2 << CIM_CFG_PACK_BIT)
1837  #define CIM_CFG_PACK_3 (3 << CIM_CFG_PACK_BIT)
1838  #define CIM_CFG_PACK_4 (4 << CIM_CFG_PACK_BIT)
1839  #define CIM_CFG_PACK_5 (5 << CIM_CFG_PACK_BIT)
1840  #define CIM_CFG_PACK_6 (6 << CIM_CFG_PACK_BIT)
1841  #define CIM_CFG_PACK_7 (7 << CIM_CFG_PACK_BIT)
1842#define CIM_CFG_DSM_BIT 0
1843#define CIM_CFG_DSM_MASK (0x3 << CIM_CFG_DSM_BIT)
1844  #define CIM_CFG_DSM_CPM (0 << CIM_CFG_DSM_BIT) /* CCIR656 Progressive Mode */
1845  #define CIM_CFG_DSM_CIM (1 << CIM_CFG_DSM_BIT) /* CCIR656 Interlace Mode */
1846  #define CIM_CFG_DSM_GCM (2 << CIM_CFG_DSM_BIT) /* Gated Clock Mode */
1847  #define CIM_CFG_DSM_NGCM (3 << CIM_CFG_DSM_BIT) /* Non-Gated Clock Mode */
1848
1849/* CIM Control Register (CIM_CTRL) */
1850
1851#define CIM_CTRL_MCLKDIV_BIT 24
1852#define CIM_CTRL_MCLKDIV_MASK (0xff << CIM_CTRL_MCLKDIV_BIT)
1853#define CIM_CTRL_FRC_BIT 16
1854#define CIM_CTRL_FRC_MASK (0xf << CIM_CTRL_FRC_BIT)
1855  #define CIM_CTRL_FRC_1 (0x0 << CIM_CTRL_FRC_BIT) /* Sample every frame */
1856  #define CIM_CTRL_FRC_2 (0x1 << CIM_CTRL_FRC_BIT) /* Sample 1/2 frame */
1857  #define CIM_CTRL_FRC_3 (0x2 << CIM_CTRL_FRC_BIT) /* Sample 1/3 frame */
1858  #define CIM_CTRL_FRC_4 (0x3 << CIM_CTRL_FRC_BIT) /* Sample 1/4 frame */
1859  #define CIM_CTRL_FRC_5 (0x4 << CIM_CTRL_FRC_BIT) /* Sample 1/5 frame */
1860  #define CIM_CTRL_FRC_6 (0x5 << CIM_CTRL_FRC_BIT) /* Sample 1/6 frame */
1861  #define CIM_CTRL_FRC_7 (0x6 << CIM_CTRL_FRC_BIT) /* Sample 1/7 frame */
1862  #define CIM_CTRL_FRC_8 (0x7 << CIM_CTRL_FRC_BIT) /* Sample 1/8 frame */
1863  #define CIM_CTRL_FRC_9 (0x8 << CIM_CTRL_FRC_BIT) /* Sample 1/9 frame */
1864  #define CIM_CTRL_FRC_10 (0x9 << CIM_CTRL_FRC_BIT) /* Sample 1/10 frame */
1865  #define CIM_CTRL_FRC_11 (0xA << CIM_CTRL_FRC_BIT) /* Sample 1/11 frame */
1866  #define CIM_CTRL_FRC_12 (0xB << CIM_CTRL_FRC_BIT) /* Sample 1/12 frame */
1867  #define CIM_CTRL_FRC_13 (0xC << CIM_CTRL_FRC_BIT) /* Sample 1/13 frame */
1868  #define CIM_CTRL_FRC_14 (0xD << CIM_CTRL_FRC_BIT) /* Sample 1/14 frame */
1869  #define CIM_CTRL_FRC_15 (0xE << CIM_CTRL_FRC_BIT) /* Sample 1/15 frame */
1870  #define CIM_CTRL_FRC_16 (0xF << CIM_CTRL_FRC_BIT) /* Sample 1/16 frame */
1871#define CIM_CTRL_VDDM (1 << 13)
1872#define CIM_CTRL_DMA_SOFM (1 << 12)
1873#define CIM_CTRL_DMA_EOFM (1 << 11)
1874#define CIM_CTRL_DMA_STOPM (1 << 10)
1875#define CIM_CTRL_RXF_TRIGM (1 << 9)
1876#define CIM_CTRL_RXF_OFM (1 << 8)
1877#define CIM_CTRL_RXF_TRIG_BIT 4
1878#define CIM_CTRL_RXF_TRIG_MASK (0x7 << CIM_CTRL_RXF_TRIG_BIT)
1879  #define CIM_CTRL_RXF_TRIG_4 (0 << CIM_CTRL_RXF_TRIG_BIT) /* RXFIFO Trigger Value is 4 */
1880  #define CIM_CTRL_RXF_TRIG_8 (1 << CIM_CTRL_RXF_TRIG_BIT) /* RXFIFO Trigger Value is 8 */
1881  #define CIM_CTRL_RXF_TRIG_12 (2 << CIM_CTRL_RXF_TRIG_BIT) /* RXFIFO Trigger Value is 12 */
1882  #define CIM_CTRL_RXF_TRIG_16 (3 << CIM_CTRL_RXF_TRIG_BIT) /* RXFIFO Trigger Value is 16 */
1883  #define CIM_CTRL_RXF_TRIG_20 (4 << CIM_CTRL_RXF_TRIG_BIT) /* RXFIFO Trigger Value is 20 */
1884  #define CIM_CTRL_RXF_TRIG_24 (5 << CIM_CTRL_RXF_TRIG_BIT) /* RXFIFO Trigger Value is 24 */
1885  #define CIM_CTRL_RXF_TRIG_28 (6 << CIM_CTRL_RXF_TRIG_BIT) /* RXFIFO Trigger Value is 28 */
1886  #define CIM_CTRL_RXF_TRIG_32 (7 << CIM_CTRL_RXF_TRIG_BIT) /* RXFIFO Trigger Value is 32 */
1887#define CIM_CTRL_DMA_EN (1 << 2)
1888#define CIM_CTRL_RXF_RST (1 << 1)
1889#define CIM_CTRL_ENA (1 << 0)
1890
1891/* CIM State Register (CIM_STATE) */
1892
1893#define CIM_STATE_DMA_SOF (1 << 6)
1894#define CIM_STATE_DMA_EOF (1 << 5)
1895#define CIM_STATE_DMA_STOP (1 << 4)
1896#define CIM_STATE_RXF_OF (1 << 3)
1897#define CIM_STATE_RXF_TRIG (1 << 2)
1898#define CIM_STATE_RXF_EMPTY (1 << 1)
1899#define CIM_STATE_VDD (1 << 0)
1900
1901/* CIM DMA Command Register (CIM_CMD) */
1902
1903#define CIM_CMD_SOFINT (1 << 31)
1904#define CIM_CMD_EOFINT (1 << 30)
1905#define CIM_CMD_STOP (1 << 28)
1906#define CIM_CMD_LEN_BIT 0
1907#define CIM_CMD_LEN_MASK (0xffffff << CIM_CMD_LEN_BIT)
1908
1909
1910/*************************************************************************
1911 * SADC (Smart A/D Controller)
1912 *************************************************************************/
1913
1914#define SADC_ENA (SADC_BASE + 0x00) /* ADC Enable Register */
1915#define SADC_CFG (SADC_BASE + 0x04) /* ADC Configure Register */
1916#define SADC_CTRL (SADC_BASE + 0x08) /* ADC Control Register */
1917#define SADC_STATE (SADC_BASE + 0x0C) /* ADC Status Register*/
1918#define SADC_SAMETIME (SADC_BASE + 0x10) /* ADC Same Point Time Register */
1919#define SADC_WAITTIME (SADC_BASE + 0x14) /* ADC Wait Time Register */
1920#define SADC_TSDAT (SADC_BASE + 0x18) /* ADC Touch Screen Data Register */
1921#define SADC_BATDAT (SADC_BASE + 0x1C) /* ADC PBAT Data Register */
1922#define SADC_SADDAT (SADC_BASE + 0x20) /* ADC SADCIN Data Register */
1923
1924#define REG_SADC_ENA REG8(SADC_ENA)
1925#define REG_SADC_CFG REG32(SADC_CFG)
1926#define REG_SADC_CTRL REG8(SADC_CTRL)
1927#define REG_SADC_STATE REG8(SADC_STATE)
1928#define REG_SADC_SAMETIME REG16(SADC_SAMETIME)
1929#define REG_SADC_WAITTIME REG16(SADC_WAITTIME)
1930#define REG_SADC_TSDAT REG32(SADC_TSDAT)
1931#define REG_SADC_BATDAT REG16(SADC_BATDAT)
1932#define REG_SADC_SADDAT REG16(SADC_SADDAT)
1933
1934/* ADC Enable Register */
1935#define SADC_ENA_ADEN (1 << 7) /* Touch Screen Enable */
1936#define SADC_ENA_TSEN (1 << 2) /* Touch Screen Enable */
1937#define SADC_ENA_PBATEN (1 << 1) /* PBAT Enable */
1938#define SADC_ENA_SADCINEN (1 << 0) /* SADCIN Enable */
1939
1940/* ADC Configure Register */
1941#define SADC_CFG_CLKOUT_NUM_BIT 16
1942#define SADC_CFG_CLKOUT_NUM_MASK (0x7 << SADC_CFG_CLKOUT_NUM_BIT)
1943#define SADC_CFG_TS_DMA (1 << 15) /* Touch Screen DMA Enable */
1944#define SADC_CFG_XYZ_BIT 13 /* XYZ selection */
1945#define SADC_CFG_XYZ_MASK (0x3 << SADC_CFG_XYZ_BIT)
1946  #define SADC_CFG_XY (0 << SADC_CFG_XYZ_BIT)
1947  #define SADC_CFG_XYZ (1 << SADC_CFG_XYZ_BIT)
1948  #define SADC_CFG_XYZ1Z2 (2 << SADC_CFG_XYZ_BIT)
1949#define SADC_CFG_SNUM_BIT 10 /* Sample Number */
1950#define SADC_CFG_SNUM_MASK (0x7 << SADC_CFG_SNUM_BIT)
1951  #define SADC_CFG_SNUM_1 (0x0 << SADC_CFG_SNUM_BIT)
1952  #define SADC_CFG_SNUM_2 (0x1 << SADC_CFG_SNUM_BIT)
1953  #define SADC_CFG_SNUM_3 (0x2 << SADC_CFG_SNUM_BIT)
1954  #define SADC_CFG_SNUM_4 (0x3 << SADC_CFG_SNUM_BIT)
1955  #define SADC_CFG_SNUM_5 (0x4 << SADC_CFG_SNUM_BIT)
1956  #define SADC_CFG_SNUM_6 (0x5 << SADC_CFG_SNUM_BIT)
1957  #define SADC_CFG_SNUM_8 (0x6 << SADC_CFG_SNUM_BIT)
1958  #define SADC_CFG_SNUM_9 (0x7 << SADC_CFG_SNUM_BIT)
1959#define SADC_CFG_CLKDIV_BIT 5 /* AD Converter frequency clock divider */
1960#define SADC_CFG_CLKDIV_MASK (0x1f << SADC_CFG_CLKDIV_BIT)
1961#define SADC_CFG_PBAT_HIGH (0 << 4) /* PBAT >= 2.5V */
1962#define SADC_CFG_PBAT_LOW (1 << 4) /* PBAT < 2.5V */
1963#define SADC_CFG_CMD_BIT 0 /* ADC Command */
1964#define SADC_CFG_CMD_MASK (0xf << SADC_CFG_CMD_BIT)
1965  #define SADC_CFG_CMD_X_SE (0x0 << SADC_CFG_CMD_BIT) /* X Single-End */
1966  #define SADC_CFG_CMD_Y_SE (0x1 << SADC_CFG_CMD_BIT) /* Y Single-End */
1967  #define SADC_CFG_CMD_X_DIFF (0x2 << SADC_CFG_CMD_BIT) /* X Differential */
1968  #define SADC_CFG_CMD_Y_DIFF (0x3 << SADC_CFG_CMD_BIT) /* Y Differential */
1969  #define SADC_CFG_CMD_Z1_DIFF (0x4 << SADC_CFG_CMD_BIT) /* Z1 Differential */
1970  #define SADC_CFG_CMD_Z2_DIFF (0x5 << SADC_CFG_CMD_BIT) /* Z2 Differential */
1971  #define SADC_CFG_CMD_Z3_DIFF (0x6 << SADC_CFG_CMD_BIT) /* Z3 Differential */
1972  #define SADC_CFG_CMD_Z4_DIFF (0x7 << SADC_CFG_CMD_BIT) /* Z4 Differential */
1973  #define SADC_CFG_CMD_TP_SE (0x8 << SADC_CFG_CMD_BIT) /* Touch Pressure */
1974  #define SADC_CFG_CMD_PBATH_SE (0x9 << SADC_CFG_CMD_BIT) /* PBAT >= 2.5V */
1975  #define SADC_CFG_CMD_PBATL_SE (0xa << SADC_CFG_CMD_BIT) /* PBAT < 2.5V */
1976  #define SADC_CFG_CMD_SADCIN_SE (0xb << SADC_CFG_CMD_BIT) /* Measure SADCIN */
1977  #define SADC_CFG_CMD_INT_PEN (0xc << SADC_CFG_CMD_BIT) /* INT_PEN Enable */
1978
1979/* ADC Control Register */
1980#define SADC_CTRL_PENDM (1 << 4) /* Pen Down Interrupt Mask */
1981#define SADC_CTRL_PENUM (1 << 3) /* Pen Up Interrupt Mask */
1982#define SADC_CTRL_TSRDYM (1 << 2) /* Touch Screen Data Ready Interrupt Mask */
1983#define SADC_CTRL_PBATRDYM (1 << 1) /* PBAT Data Ready Interrupt Mask */
1984#define SADC_CTRL_SRDYM (1 << 0) /* SADCIN Data Ready Interrupt Mask */
1985
1986/* ADC Status Register */
1987#define SADC_STATE_TSBUSY (1 << 7) /* TS A/D is working */
1988#define SADC_STATE_PBATBUSY (1 << 6) /* PBAT A/D is working */
1989#define SADC_STATE_SBUSY (1 << 5) /* SADCIN A/D is working */
1990#define SADC_STATE_PEND (1 << 4) /* Pen Down Interrupt Flag */
1991#define SADC_STATE_PENU (1 << 3) /* Pen Up Interrupt Flag */
1992#define SADC_STATE_TSRDY (1 << 2) /* Touch Screen Data Ready Interrupt Flag */
1993#define SADC_STATE_PBATRDY (1 << 1) /* PBAT Data Ready Interrupt Flag */
1994#define SADC_STATE_SRDY (1 << 0) /* SADCIN Data Ready Interrupt Flag */
1995
1996/* ADC Touch Screen Data Register */
1997#define SADC_TSDAT_DATA0_BIT 0
1998#define SADC_TSDAT_DATA0_MASK (0xfff << SADC_TSDAT_DATA0_BIT)
1999#define SADC_TSDAT_TYPE0 (1 << 15)
2000#define SADC_TSDAT_DATA1_BIT 16
2001#define SADC_TSDAT_DATA1_MASK (0xfff << SADC_TSDAT_DATA1_BIT)
2002#define SADC_TSDAT_TYPE1 (1 << 31)
2003
2004
2005/*************************************************************************
2006 * SLCD (Smart LCD Controller)
2007 *************************************************************************/
2008
2009#define SLCD_CFG (SLCD_BASE + 0xA0) /* SLCD Configure Register */
2010#define SLCD_CTRL (SLCD_BASE + 0xA4) /* SLCD Control Register */
2011#define SLCD_STATE (SLCD_BASE + 0xA8) /* SLCD Status Register */
2012#define SLCD_DATA (SLCD_BASE + 0xAC) /* SLCD Data Register */
2013#define SLCD_FIFO (SLCD_BASE + 0xB0) /* SLCD FIFO Register */
2014
2015#define REG_SLCD_CFG REG32(SLCD_CFG)
2016#define REG_SLCD_CTRL REG8(SLCD_CTRL)
2017#define REG_SLCD_STATE REG8(SLCD_STATE)
2018#define REG_SLCD_DATA REG32(SLCD_DATA)
2019#define REG_SLCD_FIFO REG32(SLCD_FIFO)
2020
2021/* SLCD Configure Register */
2022#define SLCD_CFG_BURST_BIT 14
2023#define SLCD_CFG_BURST_MASK (0x3 << SLCD_CFG_BURST_BIT)
2024  #define SLCD_CFG_BURST_4_WORD (0 << SLCD_CFG_BURST_BIT)
2025  #define SLCD_CFG_BURST_8_WORD (1 << SLCD_CFG_BURST_BIT)
2026#define SLCD_CFG_DWIDTH_BIT 10
2027#define SLCD_CFG_DWIDTH_MASK (0x7 << SLCD_CFG_DWIDTH_BIT)
2028  #define SLCD_CFG_DWIDTH_18 (0 << SLCD_CFG_DWIDTH_BIT)
2029  #define SLCD_CFG_DWIDTH_16 (1 << SLCD_CFG_DWIDTH_BIT)
2030  #define SLCD_CFG_DWIDTH_8_x3 (2 << SLCD_CFG_DWIDTH_BIT)
2031  #define SLCD_CFG_DWIDTH_8_x2 (3 << SLCD_CFG_DWIDTH_BIT)
2032  #define SLCD_CFG_DWIDTH_9_x2 (4 << SLCD_CFG_DWIDTH_BIT)
2033#define SLCD_CFG_CWIDTH_16BIT (0 << 8)
2034#define SLCD_CFG_CWIDTH_8BIT (1 << 8)
2035#define SLCD_CFG_CS_ACTIVE_LOW (0 << 4)
2036#define SLCD_CFG_CS_ACTIVE_HIGH (1 << 4)
2037#define SLCD_CFG_RS_CMD_LOW (0 << 3)
2038#define SLCD_CFG_RS_CMD_HIGH (1 << 3)
2039#define SLCD_CFG_CLK_ACTIVE_FALLING (0 << 1)
2040#define SLCD_CFG_CLK_ACTIVE_RISING (1 << 1)
2041#define SLCD_CFG_TYPE_PARALLEL (0 << 0)
2042#define SLCD_CFG_TYPE_SERIAL (1 << 0)
2043
2044/* SLCD Control Register */
2045#define SLCD_CTRL_DMA_EN (1 << 0)
2046
2047/* SLCD Status Register */
2048#define SLCD_STATE_BUSY (1 << 0)
2049
2050/* SLCD Data Register */
2051#define SLCD_DATA_RS_DATA (0 << 31)
2052#define SLCD_DATA_RS_COMMAND (1 << 31)
2053
2054/* SLCD FIFO Register */
2055#define SLCD_FIFO_RS_DATA (0 << 31)
2056#define SLCD_FIFO_RS_COMMAND (1 << 31)
2057
2058
2059/*************************************************************************
2060 * LCD (LCD Controller)
2061 *************************************************************************/
2062#define LCD_CFG (LCD_BASE + 0x00) /* LCD Configure Register */
2063#define LCD_VSYNC (LCD_BASE + 0x04) /* Vertical Synchronize Register */
2064#define LCD_HSYNC (LCD_BASE + 0x08) /* Horizontal Synchronize Register */
2065#define LCD_VAT (LCD_BASE + 0x0c) /* Virtual Area Setting Register */
2066#define LCD_DAH (LCD_BASE + 0x10) /* Display Area Horizontal Start/End Point */
2067#define LCD_DAV (LCD_BASE + 0x14) /* Display Area Vertical Start/End Point */
2068#define LCD_PS (LCD_BASE + 0x18) /* PS Signal Setting */
2069#define LCD_CLS (LCD_BASE + 0x1c) /* CLS Signal Setting */
2070#define LCD_SPL (LCD_BASE + 0x20) /* SPL Signal Setting */
2071#define LCD_REV (LCD_BASE + 0x24) /* REV Signal Setting */
2072#define LCD_CTRL (LCD_BASE + 0x30) /* LCD Control Register */
2073#define LCD_STATE (LCD_BASE + 0x34) /* LCD Status Register */
2074#define LCD_IID (LCD_BASE + 0x38) /* Interrupt ID Register */
2075#define LCD_DA0 (LCD_BASE + 0x40) /* Descriptor Address Register 0 */
2076#define LCD_SA0 (LCD_BASE + 0x44) /* Source Address Register 0 */
2077#define LCD_FID0 (LCD_BASE + 0x48) /* Frame ID Register 0 */
2078#define LCD_CMD0 (LCD_BASE + 0x4c) /* DMA Command Register 0 */
2079#define LCD_DA1 (LCD_BASE + 0x50) /* Descriptor Address Register 1 */
2080#define LCD_SA1 (LCD_BASE + 0x54) /* Source Address Register 1 */
2081#define LCD_FID1 (LCD_BASE + 0x58) /* Frame ID Register 1 */
2082#define LCD_CMD1 (LCD_BASE + 0x5c) /* DMA Command Register 1 */
2083
2084#define REG_LCD_CFG REG32(LCD_CFG)
2085#define REG_LCD_VSYNC REG32(LCD_VSYNC)
2086#define REG_LCD_HSYNC REG32(LCD_HSYNC)
2087#define REG_LCD_VAT REG32(LCD_VAT)
2088#define REG_LCD_DAH REG32(LCD_DAH)
2089#define REG_LCD_DAV REG32(LCD_DAV)
2090#define REG_LCD_PS REG32(LCD_PS)
2091#define REG_LCD_CLS REG32(LCD_CLS)
2092#define REG_LCD_SPL REG32(LCD_SPL)
2093#define REG_LCD_REV REG32(LCD_REV)
2094#define REG_LCD_CTRL REG32(LCD_CTRL)
2095#define REG_LCD_STATE REG32(LCD_STATE)
2096#define REG_LCD_IID REG32(LCD_IID)
2097#define REG_LCD_DA0 REG32(LCD_DA0)
2098#define REG_LCD_SA0 REG32(LCD_SA0)
2099#define REG_LCD_FID0 REG32(LCD_FID0)
2100#define REG_LCD_CMD0 REG32(LCD_CMD0)
2101#define REG_LCD_DA1 REG32(LCD_DA1)
2102#define REG_LCD_SA1 REG32(LCD_SA1)
2103#define REG_LCD_FID1 REG32(LCD_FID1)
2104#define REG_LCD_CMD1 REG32(LCD_CMD1)
2105
2106/* LCD Configure Register */
2107#define LCD_CFG_LCDPIN_BIT 31 /* LCD pins selection */
2108#define LCD_CFG_LCDPIN_MASK (0x1 << LCD_CFG_LCDPIN_BIT)
2109  #define LCD_CFG_LCDPIN_LCD (0x0 << LCD_CFG_LCDPIN_BIT)
2110  #define LCD_CFG_LCDPIN_SLCD (0x1 << LCD_CFG_LCDPIN_BIT)
2111#define LCD_CFG_PSM (1 << 23) /* PS signal mode */
2112#define LCD_CFG_CLSM (1 << 22) /* CLS signal mode */
2113#define LCD_CFG_SPLM (1 << 21) /* SPL signal mode */
2114#define LCD_CFG_REVM (1 << 20) /* REV signal mode */
2115#define LCD_CFG_HSYNM (1 << 19) /* HSYNC signal mode */
2116#define LCD_CFG_PCLKM (1 << 18) /* PCLK signal mode */
2117#define LCD_CFG_INVDAT (1 << 17) /* Inverse output data */
2118#define LCD_CFG_SYNDIR_IN (1 << 16) /* VSYNC&HSYNC direction */
2119#define LCD_CFG_PSP (1 << 15) /* PS pin reset state */
2120#define LCD_CFG_CLSP (1 << 14) /* CLS pin reset state */
2121#define LCD_CFG_SPLP (1 << 13) /* SPL pin reset state */
2122#define LCD_CFG_REVP (1 << 12) /* REV pin reset state */
2123#define LCD_CFG_HSP (1 << 11) /* HSYNC pority:0-active high,1-active low */
2124#define LCD_CFG_PCP (1 << 10) /* PCLK pority:0-rising,1-falling */
2125#define LCD_CFG_DEP (1 << 9) /* DE pority:0-active high,1-active low */
2126#define LCD_CFG_VSP (1 << 8) /* VSYNC pority:0-rising,1-falling */
2127#define LCD_CFG_PDW_BIT 4 /* STN pins utilization */
2128#define LCD_CFG_PDW_MASK (0x3 << LCD_DEV_PDW_BIT)
2129#define LCD_CFG_PDW_1 (0 << LCD_CFG_PDW_BIT) /* LCD_D[0] */
2130  #define LCD_CFG_PDW_2 (1 << LCD_CFG_PDW_BIT) /* LCD_D[0:1] */
2131  #define LCD_CFG_PDW_4 (2 << LCD_CFG_PDW_BIT) /* LCD_D[0:3]/LCD_D[8:11] */
2132  #define LCD_CFG_PDW_8 (3 << LCD_CFG_PDW_BIT) /* LCD_D[0:7]/LCD_D[8:15] */
2133#define LCD_CFG_MODE_BIT 0 /* Display Device Mode Select */
2134#define LCD_CFG_MODE_MASK (0x0f << LCD_CFG_MODE_BIT)
2135  #define LCD_CFG_MODE_GENERIC_TFT (0 << LCD_CFG_MODE_BIT) /* 16,18 bit TFT */
2136  #define LCD_CFG_MODE_SPECIAL_TFT_1 (1 << LCD_CFG_MODE_BIT)
2137  #define LCD_CFG_MODE_SPECIAL_TFT_2 (2 << LCD_CFG_MODE_BIT)
2138  #define LCD_CFG_MODE_SPECIAL_TFT_3 (3 << LCD_CFG_MODE_BIT)
2139  #define LCD_CFG_MODE_NONINTER_CCIR656 (4 << LCD_CFG_MODE_BIT)
2140  #define LCD_CFG_MODE_INTER_CCIR656 (5 << LCD_CFG_MODE_BIT)
2141  #define LCD_CFG_MODE_SINGLE_CSTN (8 << LCD_CFG_MODE_BIT)
2142  #define LCD_CFG_MODE_SINGLE_MSTN (9 << LCD_CFG_MODE_BIT)
2143  #define LCD_CFG_MODE_DUAL_CSTN (10 << LCD_CFG_MODE_BIT)
2144  #define LCD_CFG_MODE_DUAL_MSTN (11 << LCD_CFG_MODE_BIT)
2145  #define LCD_CFG_MODE_SERIAL_TFT (12 << LCD_CFG_MODE_BIT)
2146  #define LCD_CFG_MODE_GENERIC_18BIT_TFT (13 << LCD_CFG_MODE_BIT)
2147  /* JZ47XX defines */
2148  #define LCD_CFG_MODE_SHARP_HR (1 << LCD_CFG_MODE_BIT)
2149  #define LCD_CFG_MODE_CASIO_TFT (2 << LCD_CFG_MODE_BIT)
2150  #define LCD_CFG_MODE_SAMSUNG_ALPHA (3 << LCD_CFG_MODE_BIT)
2151
2152
2153
2154/* Vertical Synchronize Register */
2155#define LCD_VSYNC_VPS_BIT 16 /* VSYNC pulse start in line clock, fixed to 0 */
2156#define LCD_VSYNC_VPS_MASK (0xffff << LCD_VSYNC_VPS_BIT)
2157#define LCD_VSYNC_VPE_BIT 0 /* VSYNC pulse end in line clock */
2158#define LCD_VSYNC_VPE_MASK (0xffff << LCD_VSYNC_VPS_BIT)
2159
2160/* Horizontal Synchronize Register */
2161#define LCD_HSYNC_HPS_BIT 16 /* HSYNC pulse start position in dot clock */
2162#define LCD_HSYNC_HPS_MASK (0xffff << LCD_HSYNC_HPS_BIT)
2163#define LCD_HSYNC_HPE_BIT 0 /* HSYNC pulse end position in dot clock */
2164#define LCD_HSYNC_HPE_MASK (0xffff << LCD_HSYNC_HPE_BIT)
2165
2166/* Virtual Area Setting Register */
2167#define LCD_VAT_HT_BIT 16 /* Horizontal Total size in dot clock */
2168#define LCD_VAT_HT_MASK (0xffff << LCD_VAT_HT_BIT)
2169#define LCD_VAT_VT_BIT 0 /* Vertical Total size in dot clock */
2170#define LCD_VAT_VT_MASK (0xffff << LCD_VAT_VT_BIT)
2171
2172/* Display Area Horizontal Start/End Point Register */
2173#define LCD_DAH_HDS_BIT 16 /* Horizontal display area start in dot clock */
2174#define LCD_DAH_HDS_MASK (0xffff << LCD_DAH_HDS_BIT)
2175#define LCD_DAH_HDE_BIT 0 /* Horizontal display area end in dot clock */
2176#define LCD_DAH_HDE_MASK (0xffff << LCD_DAH_HDE_BIT)
2177
2178/* Display Area Vertical Start/End Point Register */
2179#define LCD_DAV_VDS_BIT 16 /* Vertical display area start in line clock */
2180#define LCD_DAV_VDS_MASK (0xffff << LCD_DAV_VDS_BIT)
2181#define LCD_DAV_VDE_BIT 0 /* Vertical display area end in line clock */
2182#define LCD_DAV_VDE_MASK (0xffff << LCD_DAV_VDE_BIT)
2183
2184/* PS Signal Setting */
2185#define LCD_PS_PSS_BIT 16 /* PS signal start position in dot clock */
2186#define LCD_PS_PSS_MASK (0xffff << LCD_PS_PSS_BIT)
2187#define LCD_PS_PSE_BIT 0 /* PS signal end position in dot clock */
2188#define LCD_PS_PSE_MASK (0xffff << LCD_PS_PSE_BIT)
2189
2190/* CLS Signal Setting */
2191#define LCD_CLS_CLSS_BIT 16 /* CLS signal start position in dot clock */
2192#define LCD_CLS_CLSS_MASK (0xffff << LCD_CLS_CLSS_BIT)
2193#define LCD_CLS_CLSE_BIT 0 /* CLS signal end position in dot clock */
2194#define LCD_CLS_CLSE_MASK (0xffff << LCD_CLS_CLSE_BIT)
2195
2196/* SPL Signal Setting */
2197#define LCD_SPL_SPLS_BIT 16 /* SPL signal start position in dot clock */
2198#define LCD_SPL_SPLS_MASK (0xffff << LCD_SPL_SPLS_BIT)
2199#define LCD_SPL_SPLE_BIT 0 /* SPL signal end position in dot clock */
2200#define LCD_SPL_SPLE_MASK (0xffff << LCD_SPL_SPLE_BIT)
2201
2202/* REV Signal Setting */
2203#define LCD_REV_REVS_BIT 16 /* REV signal start position in dot clock */
2204#define LCD_REV_REVS_MASK (0xffff << LCD_REV_REVS_BIT)
2205
2206/* LCD Control Register */
2207#define LCD_CTRL_BST_BIT 28 /* Burst Length Selection */
2208#define LCD_CTRL_BST_MASK (0x03 << LCD_CTRL_BST_BIT)
2209  #define LCD_CTRL_BST_4 (0 << LCD_CTRL_BST_BIT) /* 4-word */
2210  #define LCD_CTRL_BST_8 (1 << LCD_CTRL_BST_BIT) /* 8-word */
2211  #define LCD_CTRL_BST_16 (2 << LCD_CTRL_BST_BIT) /* 16-word */
2212#define LCD_CTRL_RGB565 (0 << 27) /* RGB565 mode */
2213#define LCD_CTRL_RGB555 (1 << 27) /* RGB555 mode */
2214#define LCD_CTRL_OFUP (1 << 26) /* Output FIFO underrun protection enable */
2215#define LCD_CTRL_FRC_BIT 24 /* STN FRC Algorithm Selection */
2216#define LCD_CTRL_FRC_MASK (0x03 << LCD_CTRL_FRC_BIT)
2217  #define LCD_CTRL_FRC_16 (0 << LCD_CTRL_FRC_BIT) /* 16 grayscale */
2218  #define LCD_CTRL_FRC_4 (1 << LCD_CTRL_FRC_BIT) /* 4 grayscale */
2219  #define LCD_CTRL_FRC_2 (2 << LCD_CTRL_FRC_BIT) /* 2 grayscale */
2220#define LCD_CTRL_PDD_BIT 16 /* Load Palette Delay Counter */
2221#define LCD_CTRL_PDD_MASK (0xff << LCD_CTRL_PDD_BIT)
2222#define LCD_CTRL_EOFM (1 << 13) /* EOF interrupt mask */
2223#define LCD_CTRL_SOFM (1 << 12) /* SOF interrupt mask */
2224#define LCD_CTRL_OFUM (1 << 11) /* Output FIFO underrun interrupt mask */
2225#define LCD_CTRL_IFUM0 (1 << 10) /* Input FIFO 0 underrun interrupt mask */
2226#define LCD_CTRL_IFUM1 (1 << 9) /* Input FIFO 1 underrun interrupt mask */
2227#define LCD_CTRL_LDDM (1 << 8) /* LCD disable done interrupt mask */
2228#define LCD_CTRL_QDM (1 << 7) /* LCD quick disable done interrupt mask */
2229#define LCD_CTRL_BEDN (1 << 6) /* Endian selection */
2230#define LCD_CTRL_PEDN (1 << 5) /* Endian in byte:0-msb first, 1-lsb first */
2231#define LCD_CTRL_DIS (1 << 4) /* Disable indicate bit */
2232#define LCD_CTRL_ENA (1 << 3) /* LCD enable bit */
2233#define LCD_CTRL_BPP_BIT 0 /* Bits Per Pixel */
2234#define LCD_CTRL_BPP_MASK (0x07 << LCD_CTRL_BPP_BIT)
2235  #define LCD_CTRL_BPP_1 (0 << LCD_CTRL_BPP_BIT) /* 1 bpp */
2236  #define LCD_CTRL_BPP_2 (1 << LCD_CTRL_BPP_BIT) /* 2 bpp */
2237  #define LCD_CTRL_BPP_4 (2 << LCD_CTRL_BPP_BIT) /* 4 bpp */
2238  #define LCD_CTRL_BPP_8 (3 << LCD_CTRL_BPP_BIT) /* 8 bpp */
2239  #define LCD_CTRL_BPP_16 (4 << LCD_CTRL_BPP_BIT) /* 15/16 bpp */
2240  #define LCD_CTRL_BPP_18_24 (5 << LCD_CTRL_BPP_BIT) /* 18/24/32 bpp */
2241
2242/* LCD Status Register */
2243#define LCD_STATE_QD (1 << 7) /* Quick Disable Done */
2244#define LCD_STATE_EOF (1 << 5) /* EOF Flag */
2245#define LCD_STATE_SOF (1 << 4) /* SOF Flag */
2246#define LCD_STATE_OFU (1 << 3) /* Output FIFO Underrun */
2247#define LCD_STATE_IFU0 (1 << 2) /* Input FIFO 0 Underrun */
2248#define LCD_STATE_IFU1 (1 << 1) /* Input FIFO 1 Underrun */
2249#define LCD_STATE_LDD (1 << 0) /* LCD Disabled */
2250
2251/* DMA Command Register */
2252#define LCD_CMD_SOFINT (1 << 31)
2253#define LCD_CMD_EOFINT (1 << 30)
2254#define LCD_CMD_PAL (1 << 28)
2255#define LCD_CMD_LEN_BIT 0
2256#define LCD_CMD_LEN_MASK (0xffffff << LCD_CMD_LEN_BIT)
2257
2258
2259/*************************************************************************
2260 * USB Device
2261 *************************************************************************/
2262#define USB_BASE UDC_BASE
2263
2264#define USB_REG_FADDR (USB_BASE + 0x00) /* Function Address 8-bit */
2265#define USB_REG_POWER (USB_BASE + 0x01) /* Power Managemetn 8-bit */
2266#define USB_REG_INTRIN (USB_BASE + 0x02) /* Interrupt IN 16-bit */
2267#define USB_REG_INTROUT (USB_BASE + 0x04) /* Interrupt OUT 16-bit */
2268#define USB_REG_INTRINE (USB_BASE + 0x06) /* Intr IN enable 16-bit */
2269#define USB_REG_INTROUTE (USB_BASE + 0x08) /* Intr OUT enable 16-bit */
2270#define USB_REG_INTRUSB (USB_BASE + 0x0a) /* Interrupt USB 8-bit */
2271#define USB_REG_INTRUSBE (USB_BASE + 0x0b) /* Interrupt USB Enable 8-bit */
2272#define USB_REG_FRAME (USB_BASE + 0x0c) /* Frame number 16-bit */
2273#define USB_REG_INDEX (USB_BASE + 0x0e) /* Index register 8-bit */
2274#define USB_REG_TESTMODE (USB_BASE + 0x0f) /* USB test mode 8-bit */
2275
2276#define USB_REG_CSR0 (USB_BASE + 0x12) /* EP0 CSR 8-bit */
2277#define USB_REG_INMAXP (USB_BASE + 0x10) /* EP1-2 IN Max Pkt Size 16-bit */
2278#define USB_REG_INCSR (USB_BASE + 0x12) /* EP1-2 IN CSR LSB 8/16bit */
2279#define USB_REG_INCSRH (USB_BASE + 0x13) /* EP1-2 IN CSR MSB 8-bit */
2280#define USB_REG_OUTMAXP (USB_BASE + 0x14) /* EP1 OUT Max Pkt Size 16-bit */
2281#define USB_REG_OUTCSR (USB_BASE + 0x16) /* EP1 OUT CSR LSB 8/16bit */
2282#define USB_REG_OUTCSRH (USB_BASE + 0x17) /* EP1 OUT CSR MSB 8-bit */
2283#define USB_REG_OUTCOUNT (USB_BASE + 0x18) /* bytes in EP0/1 OUT FIFO 16-bit */
2284
2285#define USB_FIFO_EP0 (USB_BASE + 0x20)
2286#define USB_FIFO_EP1 (USB_BASE + 0x24)
2287#define USB_FIFO_EP2 (USB_BASE + 0x28)
2288
2289#define USB_REG_EPINFO (USB_BASE + 0x78) /* Endpoint information */
2290#define USB_REG_RAMINFO (USB_BASE + 0x79) /* RAM information */
2291
2292#define USB_REG_INTR (USB_BASE + 0x200) /* DMA pending interrupts */
2293#define USB_REG_CNTL1 (USB_BASE + 0x204) /* DMA channel 1 control */
2294#define USB_REG_ADDR1 (USB_BASE + 0x208) /* DMA channel 1 AHB memory addr */
2295#define USB_REG_COUNT1 (USB_BASE + 0x20c) /* DMA channel 1 byte count */
2296#define USB_REG_CNTL2 (USB_BASE + 0x214) /* DMA channel 2 control */
2297#define USB_REG_ADDR2 (USB_BASE + 0x218) /* DMA channel 2 AHB memory addr */
2298#define USB_REG_COUNT2 (USB_BASE + 0x21c) /* DMA channel 2 byte count */
2299
2300
2301/* Power register bit masks */
2302#define USB_POWER_SUSPENDM 0x01
2303#define USB_POWER_RESUME 0x04
2304#define USB_POWER_HSMODE 0x10
2305#define USB_POWER_HSENAB 0x20
2306#define USB_POWER_SOFTCONN 0x40
2307
2308/* Interrupt register bit masks */
2309#define USB_INTR_SUSPEND 0x01
2310#define USB_INTR_RESUME 0x02
2311#define USB_INTR_RESET 0x04
2312
2313#define USB_INTR_EP0 0x0001
2314#define USB_INTR_INEP1 0x0002
2315#define USB_INTR_INEP2 0x0004
2316#define USB_INTR_OUTEP1 0x0002
2317
2318/* CSR0 bit masks */
2319#define USB_CSR0_OUTPKTRDY 0x01
2320#define USB_CSR0_INPKTRDY 0x02
2321#define USB_CSR0_SENTSTALL 0x04
2322#define USB_CSR0_DATAEND 0x08
2323#define USB_CSR0_SETUPEND 0x10
2324#define USB_CSR0_SENDSTALL 0x20
2325#define USB_CSR0_SVDOUTPKTRDY 0x40
2326#define USB_CSR0_SVDSETUPEND 0x80
2327
2328/* Endpoint CSR register bits */
2329#define USB_INCSRH_AUTOSET 0x80
2330#define USB_INCSRH_ISO 0x40
2331#define USB_INCSRH_MODE 0x20
2332#define USB_INCSRH_DMAREQENAB 0x10
2333#define USB_INCSRH_DMAREQMODE 0x04
2334#define USB_INCSR_CDT 0x40
2335#define USB_INCSR_SENTSTALL 0x20
2336#define USB_INCSR_SENDSTALL 0x10
2337#define USB_INCSR_FF 0x08
2338#define USB_INCSR_UNDERRUN 0x04
2339#define USB_INCSR_FFNOTEMPT 0x02
2340#define USB_INCSR_INPKTRDY 0x01
2341#define USB_OUTCSRH_AUTOCLR 0x80
2342#define USB_OUTCSRH_ISO 0x40
2343#define USB_OUTCSRH_DMAREQENAB 0x20
2344#define USB_OUTCSRH_DNYT 0x10
2345#define USB_OUTCSRH_DMAREQMODE 0x08
2346#define USB_OUTCSR_CDT 0x80
2347#define USB_OUTCSR_SENTSTALL 0x40
2348#define USB_OUTCSR_SENDSTALL 0x20
2349#define USB_OUTCSR_FF 0x10
2350#define USB_OUTCSR_DATAERR 0x08
2351#define USB_OUTCSR_OVERRUN 0x04
2352#define USB_OUTCSR_FFFULL 0x02
2353#define USB_OUTCSR_OUTPKTRDY 0x01
2354
2355/* Testmode register bits */
2356#define USB_TEST_SE0NAK 0x01
2357#define USB_TEST_J 0x02
2358#define USB_TEST_K 0x04
2359#define USB_TEST_PACKET 0x08
2360
2361/* DMA control bits */
2362#define USB_CNTL_ENA 0x01
2363#define USB_CNTL_DIR_IN 0x02
2364#define USB_CNTL_MODE_1 0x04
2365#define USB_CNTL_INTR_EN 0x08
2366#define USB_CNTL_EP(n) ((n) << 4)
2367#define USB_CNTL_BURST_0 (0 << 9)
2368#define USB_CNTL_BURST_4 (1 << 9)
2369#define USB_CNTL_BURST_8 (2 << 9)
2370#define USB_CNTL_BURST_16 (3 << 9)
2371
2372
2373//----------------------------------------------------------------------
2374//
2375// Module Operation Definitions
2376//
2377//----------------------------------------------------------------------
2378#ifndef __ASSEMBLY__
2379
2380/***************************************************************************
2381 * GPIO
2382 ***************************************************************************/
2383
2384//------------------------------------------------------
2385// GPIO Pins Description
2386//
2387// PORT 0:
2388//
2389// PIN/BIT N FUNC0 FUNC1
2390// 0 D0 -
2391// 1 D1 -
2392// 2 D2 -
2393// 3 D3 -
2394// 4 D4 -
2395// 5 D5 -
2396// 6 D6 -
2397// 7 D7 -
2398// 8 D8 -
2399// 9 D9 -
2400// 10 D10 -
2401// 11 D11 -
2402// 12 D12 -
2403// 13 D13 -
2404// 14 D14 -
2405// 15 D15 -
2406// 16 D16 -
2407// 17 D17 -
2408// 18 D18 -
2409// 19 D19 -
2410// 20 D20 -
2411// 21 D21 -
2412// 22 D22 -
2413// 23 D23 -
2414// 24 D24 -
2415// 25 D25 -
2416// 26 D26 -
2417// 27 D27 -
2418// 28 D28 -
2419// 29 D29 -
2420// 30 D30 -
2421// 31 D31 -
2422//
2423//------------------------------------------------------
2424// PORT 1:
2425//
2426// PIN/BIT N FUNC0 FUNC1
2427// 0 A0 -
2428// 1 A1 -
2429// 2 A2 -
2430// 3 A3 -
2431// 4 A4 -
2432// 5 A5 -
2433// 6 A6 -
2434// 7 A7 -
2435// 8 A8 -
2436// 9 A9 -
2437// 10 A10 -
2438// 11 A11 -
2439// 12 A12 -
2440// 13 A13 -
2441// 14 A14 -
2442// 15 A15/CL -
2443// 16 A16/AL -
2444// 17 LCD_CLS A21
2445// 18 LCD_SPL A22
2446// 19 DCS# -
2447// 20 RAS# -
2448// 21 CAS# -
2449// 22 RDWE#/BUFD# -
2450// 23 CKE -
2451// 24 CKO -
2452// 25 CS1# -
2453// 26 CS2# -
2454// 27 CS3# -
2455// 28 CS4# -
2456// 29 RD# -
2457// 30 WR# -
2458// 31 WE0# -
2459//
2460// Note: PIN15&16 are CL&AL when connecting to NAND flash.
2461//------------------------------------------------------
2462// PORT 2:
2463//
2464// PIN/BIT N FUNC0 FUNC1
2465// 0 LCD_D0 -
2466// 1 LCD_D1 -
2467// 2 LCD_D2 -
2468// 3 LCD_D3 -
2469// 4 LCD_D4 -
2470// 5 LCD_D5 -
2471// 6 LCD_D6 -
2472// 7 LCD_D7 -
2473// 8 LCD_D8 -
2474// 9 LCD_D9 -
2475// 10 LCD_D10 -
2476// 11 LCD_D11 -
2477// 12 LCD_D12 -
2478// 13 LCD_D13 -
2479// 14 LCD_D14 -
2480// 15 LCD_D15 -
2481// 16 LCD_D16 -
2482// 17 LCD_D17 -
2483// 18 LCD_PCLK -
2484// 19 LCD_HSYNC -
2485// 20 LCD_VSYNC -
2486// 21 LCD_DE -
2487// 22 LCD_PS A19
2488// 23 LCD_REV A20
2489// 24 WE1# -
2490// 25 WE2# -
2491// 26 WE3# -
2492// 27 WAIT# -
2493// 28 FRE# -
2494// 29 FWE# -
2495// 30(NOTE:FRB#) - -
2496// 31 - -
2497//
2498// NOTE(1): PIN30 is used for FRB# when connecting to NAND flash.
2499//------------------------------------------------------
2500// PORT 3:
2501//
2502// PIN/BIT N FUNC0 FUNC1
2503// 0 CIM_D0 -
2504// 1 CIM_D1 -
2505// 2 CIM_D2 -
2506// 3 CIM_D3 -
2507// 4 CIM_D4 -
2508// 5 CIM_D5 -
2509// 6 CIM_D6 -
2510// 7 CIM_D7 -
2511// 8 MSC_CMD -
2512// 9 MSC_CLK -
2513// 10 MSC_D0 -
2514// 11 MSC_D1 -
2515// 12 MSC_D2 -
2516// 13 MSC_D3 -
2517// 14 CIM_MCLK -
2518// 15 CIM_PCLK -
2519// 16 CIM_VSYNC -
2520// 17 CIM_HSYNC -
2521// 18 SSI_CLK SCLK_RSTN
2522// 19 SSI_CE0# BIT_CLK(AIC)
2523// 20 SSI_DT SDATA_OUT(AIC)
2524// 21 SSI_DR SDATA_IN(AIC)
2525// 22 SSI_CE1#&GPC SYNC(AIC)
2526// 23 PWM0 I2C_SDA
2527// 24 PWM1 I2C_SCK
2528// 25 PWM2 UART0_TxD
2529// 26 PWM3 UART0_RxD
2530// 27 PWM4 A17
2531// 28 PWM5 A18
2532// 29 - -
2533// 30 PWM6 UART0_CTS/UART1_RxD
2534// 31 PWM7 UART0_RTS/UART1_TxD
2535//
2536//////////////////////////////////////////////////////////
2537
2538/*
2539 * p is the port number (0,1,2,3)
2540 * o is the pin offset (0-31) inside the port
2541 * n is the absolute number of a pin (0-127), regardless of the port
2542 */
2543
2544//-------------------------------------------
2545// Function Pins Mode
2546
2547#define __gpio_as_func0(n) \
2548do { \
2549    unsigned int p, o; \
2550    p = (n) / 32; \
2551    o = (n) % 32; \
2552    REG_GPIO_PXFUNS(p) = (1 << o); \
2553    REG_GPIO_PXSELC(p) = (1 << o); \
2554} while (0)
2555
2556#define __gpio_as_func1(n) \
2557do { \
2558    unsigned int p, o; \
2559    p = (n) / 32; \
2560    o = (n) % 32; \
2561    REG_GPIO_PXFUNS(p) = (1 << o); \
2562    REG_GPIO_PXSELS(p) = (1 << o); \
2563} while (0)
2564
2565/*
2566 * D0 ~ D31, A0 ~ A16, DCS#, RAS#, CAS#, CKE#,
2567 * RDWE#, CKO#, WE0#, WE1#, WE2#, WE3#
2568 */
2569#define __gpio_as_sdram_32bit() \
2570do { \
2571    REG_GPIO_PXFUNS(0) = 0xffffffff; \
2572    REG_GPIO_PXFUNS(0) = 0xffffffff; \
2573    REG_GPIO_PXPES(0) = 0xffffffff; \
2574    REG_GPIO_PXFUNS(1) = 0x81f9ffff; \
2575    REG_GPIO_PXSELC(1) = 0x81f9ffff; \
2576    REG_GPIO_PXPES(1) = 0x81f9ffff; \
2577    REG_GPIO_PXFUNS(2) = 0x07000000; \
2578    REG_GPIO_PXSELC(2) = 0x07000000; \
2579    REG_GPIO_PXPES(1) = 0x07000000; \
2580} while (0)
2581
2582/*
2583 * D0 ~ D15, A0 ~ A16, DCS#, RAS#, CAS#, CKE#,
2584 * RDWE#, CKO#, WE0#, WE1#, WE2#, WE3#
2585 */
2586#define __gpio_as_sdram_16bit() \
2587do { \
2588    REG_GPIO_PXFUNS(0) = 0x0000ffff; \
2589    REG_GPIO_PXFUNS(0) = 0x0000ffff; \
2590    REG_GPIO_PXPES(0) = 0x0000ffff; \
2591    REG_GPIO_PXFUNS(1) = 0x81f9ffff; \
2592    REG_GPIO_PXSELC(1) = 0x81f9ffff; \
2593    REG_GPIO_PXPES(1) = 0x81f9ffff; \
2594    REG_GPIO_PXFUNS(2) = 0x07000000; \
2595    REG_GPIO_PXSELC(2) = 0x07000000; \
2596    REG_GPIO_PXPES(1) = 0x07000000; \
2597} while (0)
2598
2599/*
2600 * CS1#, CLE, ALE, FRE#, FWE#, FRB#, RDWE#/BUFD#
2601 */
2602#define __gpio_as_nand() \
2603do { \
2604    REG_GPIO_PXFUNS(1) = 0x02018000; \
2605    REG_GPIO_PXSELC(1) = 0x02018000; \
2606    REG_GPIO_PXPES(1) = 0x02018000; \
2607    REG_GPIO_PXFUNS(2) = 0x30000000; \
2608    REG_GPIO_PXSELC(2) = 0x30000000; \
2609    REG_GPIO_PXPES(2) = 0x30000000; \
2610    REG_GPIO_PXFUNC(2) = 0x40000000; \
2611    REG_GPIO_PXSELC(2) = 0x40000000; \
2612    REG_GPIO_PXDIRC(2) = 0x40000000; \
2613    REG_GPIO_PXPES(2) = 0x40000000; \
2614    REG_GPIO_PXFUNS(1) = 0x00400000; \
2615    REG_GPIO_PXSELC(1) = 0x00400000; \
2616} while (0)
2617
2618/*
2619 * CS4#, RD#, WR#, WAIT#, A0 ~ A22, D0 ~ D7
2620 */
2621#define __gpio_as_nor_8bit() \
2622do { \
2623    REG_GPIO_PXFUNS(0) = 0x000000ff; \
2624    REG_GPIO_PXSELC(0) = 0x000000ff; \
2625    REG_GPIO_PXPES(0) = 0x000000ff; \
2626    REG_GPIO_PXFUNS(1) = 0x7041ffff; \
2627    REG_GPIO_PXSELC(1) = 0x7041ffff; \
2628    REG_GPIO_PXPES(1) = 0x7041ffff; \
2629    REG_GPIO_PXFUNS(1) = 0x00060000; \
2630    REG_GPIO_PXSELS(1) = 0x00060000; \
2631    REG_GPIO_PXPES(1) = 0x00060000; \
2632    REG_GPIO_PXFUNS(2) = 0x08000000; \
2633    REG_GPIO_PXSELC(2) = 0x08000000; \
2634    REG_GPIO_PXPES(2) = 0x08000000; \
2635    REG_GPIO_PXFUNS(2) = 0x00c00000; \
2636    REG_GPIO_PXSELS(2) = 0x00c00000; \
2637    REG_GPIO_PXPES(2) = 0x00c00000; \
2638    REG_GPIO_PXFUNS(3) = 0x18000000; \
2639    REG_GPIO_PXSELS(3) = 0x18000000; \
2640    REG_GPIO_PXPES(3) = 0x18000000; \
2641} while (0)
2642
2643/*
2644 * CS4#, RD#, WR#, WAIT#, A0 ~ A22, D0 ~ D15
2645 */
2646#define __gpio_as_nor_16bit() \
2647do { \
2648    REG_GPIO_PXFUNS(0) = 0x0000ffff; \
2649    REG_GPIO_PXSELC(0) = 0x0000ffff; \
2650    REG_GPIO_PXPES(0) = 0x0000ffff; \
2651    REG_GPIO_PXFUNS(1) = 0x7041ffff; \
2652    REG_GPIO_PXSELC(1) = 0x7041ffff; \
2653    REG_GPIO_PXPES(1) = 0x7041ffff; \
2654    REG_GPIO_PXFUNS(1) = 0x00060000; \
2655    REG_GPIO_PXSELS(1) = 0x00060000; \
2656    REG_GPIO_PXPES(1) = 0x00060000; \
2657    REG_GPIO_PXFUNS(2) = 0x08000000; \
2658    REG_GPIO_PXSELC(2) = 0x08000000; \
2659    REG_GPIO_PXPES(2) = 0x08000000; \
2660    REG_GPIO_PXFUNS(2) = 0x00c00000; \
2661    REG_GPIO_PXSELS(2) = 0x00c00000; \
2662    REG_GPIO_PXPES(2) = 0x00c00000; \
2663    REG_GPIO_PXFUNS(3) = 0x18000000; \
2664    REG_GPIO_PXSELS(3) = 0x18000000; \
2665    REG_GPIO_PXPES(3) = 0x18000000; \
2666} while (0)
2667
2668/*
2669 * UART0_TxD, UART_RxD0
2670 */
2671#define __gpio_as_uart0() \
2672do { \
2673    REG_GPIO_PXFUNS(3) = 0x06000000; \
2674    REG_GPIO_PXSELS(3) = 0x06000000; \
2675    REG_GPIO_PXPES(3) = 0x06000000; \
2676} while (0)
2677
2678/*
2679 * UART1_TxD, UART1_RxD1
2680 */
2681#define __gpio_as_uart1() \
2682do { \
2683    REG_GPIO_PXFUNS(3) = 0xc0000000; \
2684    REG_GPIO_PXSELS(3) = 0xc0000000; \
2685    REG_GPIO_PXPES(3) = 0xc0000000; \
2686} while (0)
2687
2688/*
2689 * LCD_D0~LCD_D15, LCD_PCLK, LCD_HSYNC, LCD_VSYNC, LCD_DE
2690 */
2691#define __gpio_as_lcd_16bit() \
2692do { \
2693    REG_GPIO_PXFUNS(2) = 0x003cffff; \
2694    REG_GPIO_PXSELC(2) = 0x003cffff; \
2695    REG_GPIO_PXPES(2) = 0x003cffff; \
2696} while (0)
2697
2698/*
2699 * LCD_D0~LCD_D17, LCD_PCLK, LCD_HSYNC, LCD_VSYNC, LCD_DE
2700 */
2701#define __gpio_as_lcd_18bit() \
2702do { \
2703    REG_GPIO_PXFUNS(2) = 0x003fffff; \
2704    REG_GPIO_PXSELC(2) = 0x003fffff; \
2705    REG_GPIO_PXPES(2) = 0x003fffff; \
2706} while (0)
2707
2708/*
2709 * CIM_D0~CIM_D7, CIM_MCLK, CIM_PCLK, CIM_VSYNC, CIM_HSYNC
2710 */
2711#define __gpio_as_cim() \
2712do { \
2713    REG_GPIO_PXFUNS(3) = 0x0003c0ff; \
2714    REG_GPIO_PXSELC(3) = 0x0003c0ff; \
2715    REG_GPIO_PXPES(3) = 0x0003c0ff; \
2716} while (0)
2717
2718/*
2719 * SDATA_OUT, SDATA_IN, BIT_CLK, SYNC, SCLK_RESET
2720 */
2721#define __gpio_as_aic() \
2722do { \
2723    REG_GPIO_PXFUNS(3) = 0x007c0000; \
2724    REG_GPIO_PXSELS(3) = 0x007c0000; \
2725    REG_GPIO_PXPES(3) = 0x007c0000; \
2726} while (0)
2727
2728/*
2729 * MSC_CMD, MSC_CLK, MSC_D0 ~ MSC_D3
2730 */
2731#define __gpio_as_msc() \
2732do { \
2733    REG_GPIO_PXFUNS(3) = 0x00003f00; \
2734    REG_GPIO_PXSELC(3) = 0x00003f00; \
2735    REG_GPIO_PXPES(3) = 0x00003f00; \
2736} while (0)
2737
2738/*
2739 * SSI_CS0, SSI_CLK, SSI_DT, SSI_DR
2740 */
2741#define __gpio_as_ssi() \
2742do { \
2743    REG_GPIO_PXFUNS(3) = 0x003c0000; \
2744    REG_GPIO_PXSELC(3) = 0x003c0000; \
2745    REG_GPIO_PXPES(3) = 0x003c0000; \
2746} while (0)
2747
2748/*
2749 * I2C_SCK, I2C_SDA
2750 */
2751#define __gpio_as_i2c() \
2752do { \
2753    REG_GPIO_PXFUNS(3) = 0x01800000; \
2754    REG_GPIO_PXSELS(3) = 0x01800000; \
2755    REG_GPIO_PXPES(3) = 0x01800000; \
2756} while (0)
2757
2758/*
2759 * PWM0
2760 */
2761#define __gpio_as_pwm0() \
2762do { \
2763    REG_GPIO_PXFUNS(3) = 0x00800000; \
2764    REG_GPIO_PXSELC(3) = 0x00800000; \
2765    REG_GPIO_PXPES(3) = 0x00800000; \
2766} while (0)
2767
2768/*
2769 * PWM1
2770 */
2771#define __gpio_as_pwm1() \
2772do { \
2773    REG_GPIO_PXFUNS(3) = 0x01000000; \
2774    REG_GPIO_PXSELC(3) = 0x01000000; \
2775    REG_GPIO_PXPES(3) = 0x01000000; \
2776} while (0)
2777
2778/*
2779 * PWM2
2780 */
2781#define __gpio_as_pwm2() \
2782do { \
2783    REG_GPIO_PXFUNS(3) = 0x02000000; \
2784    REG_GPIO_PXSELC(3) = 0x02000000; \
2785    REG_GPIO_PXPES(3) = 0x02000000; \
2786} while (0)
2787
2788/*
2789 * PWM3
2790 */
2791#define __gpio_as_pwm3() \
2792do { \
2793    REG_GPIO_PXFUNS(3) = 0x04000000; \
2794    REG_GPIO_PXSELC(3) = 0x04000000; \
2795    REG_GPIO_PXPES(3) = 0x04000000; \
2796} while (0)
2797
2798/*
2799 * PWM4
2800 */
2801#define __gpio_as_pwm4() \
2802do { \
2803    REG_GPIO_PXFUNS(3) = 0x08000000; \
2804    REG_GPIO_PXSELC(3) = 0x08000000; \
2805    REG_GPIO_PXPES(3) = 0x08000000; \
2806} while (0)
2807
2808/*
2809 * PWM5
2810 */
2811#define __gpio_as_pwm5() \
2812do { \
2813    REG_GPIO_PXFUNS(3) = 0x10000000; \
2814    REG_GPIO_PXSELC(3) = 0x10000000; \
2815    REG_GPIO_PXPES(3) = 0x10000000; \
2816} while (0)
2817
2818/*
2819 * PWM6
2820 */
2821#define __gpio_as_pwm6() \
2822do { \
2823    REG_GPIO_PXFUNS(3) = 0x40000000; \
2824    REG_GPIO_PXSELC(3) = 0x40000000; \
2825    REG_GPIO_PXPES(3) = 0x40000000; \
2826} while (0)
2827
2828/*
2829 * PWM7
2830 */
2831#define __gpio_as_pwm7() \
2832do { \
2833    REG_GPIO_PXFUNS(3) = 0x80000000; \
2834    REG_GPIO_PXSELC(3) = 0x80000000; \
2835    REG_GPIO_PXPES(3) = 0x80000000; \
2836} while (0)
2837
2838/*
2839 * n = 0 ~ 7
2840 */
2841#define __gpio_as_pwm(n) __gpio_as_pwm##n()
2842
2843//-------------------------------------------
2844// GPIO or Interrupt Mode
2845
2846#define __gpio_get_port(p) (REG_GPIO_PXPIN(p))
2847
2848#define __gpio_port_as_output(p, o) \
2849do { \
2850    REG_GPIO_PXFUNC(p) = (1 << (o)); \
2851    REG_GPIO_PXSELC(p) = (1 << (o)); \
2852    REG_GPIO_PXDIRS(p) = (1 << (o)); \
2853} while (0)
2854
2855#define __gpio_port_as_input(p, o) \
2856do { \
2857    REG_GPIO_PXFUNC(p) = (1 << (o)); \
2858    REG_GPIO_PXSELC(p) = (1 << (o)); \
2859    REG_GPIO_PXDIRC(p) = (1 << (o)); \
2860} while (0)
2861
2862#define __gpio_as_output(n) \
2863do { \
2864    unsigned int p, o; \
2865    p = (n) / 32; \
2866    o = (n) % 32; \
2867    __gpio_port_as_output(p, o); \
2868} while (0)
2869
2870#define __gpio_as_input(n) \
2871do { \
2872    unsigned int p, o; \
2873    p = (n) / 32; \
2874    o = (n) % 32; \
2875    __gpio_port_as_input(p, o); \
2876} while (0)
2877
2878#define __gpio_set_pin(n) \
2879do { \
2880    unsigned int p, o; \
2881    p = (n) / 32; \
2882    o = (n) % 32; \
2883    REG_GPIO_PXDATS(p) = (1 << o); \
2884} while (0)
2885
2886#define __gpio_clear_pin(n) \
2887do { \
2888    unsigned int p, o; \
2889    p = (n) / 32; \
2890    o = (n) % 32; \
2891    REG_GPIO_PXDATC(p) = (1 << o); \
2892} while (0)
2893
2894#define __gpio_get_pin(n) \
2895({ \
2896    unsigned int p, o, v; \
2897    p = (n) / 32; \
2898    o = (n) % 32; \
2899    if (__gpio_get_port(p) & (1 << o)) \
2900        v = 1; \
2901    else \
2902        v = 0; \
2903    v; \
2904})
2905
2906#define __gpio_as_irq_high_level(n) \
2907do { \
2908    unsigned int p, o; \
2909    p = (n) / 32; \
2910    o = (n) % 32; \
2911    REG_GPIO_PXIMS(p) = (1 << o); \
2912    REG_GPIO_PXFUNC(p) = (1 << o); \
2913    REG_GPIO_PXSELS(p) = (1 << o); \
2914    REG_GPIO_PXTRGC(p) = (1 << o); \
2915    REG_GPIO_PXDIRS(p) = (1 << o); \
2916    REG_GPIO_PXDATC(p) = (1 << o); \
2917    REG_GPIO_PXIMC(p) = (1 << o); \
2918} while (0)
2919
2920#define __gpio_as_irq_low_level(n) \
2921do { \
2922    unsigned int p, o; \
2923    p = (n) / 32; \
2924    o = (n) % 32; \
2925    REG_GPIO_PXIMS(p) = (1 << o); \
2926    REG_GPIO_PXFUNC(p) = (1 << o); \
2927    REG_GPIO_PXSELS(p) = (1 << o); \
2928    REG_GPIO_PXTRGC(p) = (1 << o); \
2929    REG_GPIO_PXDIRC(p) = (1 << o); \
2930    REG_GPIO_PXDATC(p) = (1 << o); \
2931    REG_GPIO_PXIMC(p) = (1 << o); \
2932} while (0)
2933
2934#define __gpio_as_irq_rise_edge(n) \
2935do { \
2936    unsigned int p, o; \
2937    p = (n) / 32; \
2938    o = (n) % 32; \
2939    REG_GPIO_PXIMS(p) = (1 << o); \
2940    REG_GPIO_PXFUNC(p) = (1 << o); \
2941    REG_GPIO_PXSELS(p) = (1 << o); \
2942    REG_GPIO_PXTRGS(p) = (1 << o); \
2943    REG_GPIO_PXDIRS(p) = (1 << o); \
2944    REG_GPIO_PXDATC(p) = (1 << o); \
2945    REG_GPIO_PXIMC(p) = (1 << o); \
2946} while (0)
2947
2948#define __gpio_as_irq_fall_edge(n) \
2949do { \
2950    unsigned int p, o; \
2951    p = (n) / 32; \
2952    o = (n) % 32; \
2953    REG_GPIO_PXIMS(p) = (1 << o); \
2954    REG_GPIO_PXFUNC(p) = (1 << o); \
2955    REG_GPIO_PXSELS(p) = (1 << o); \
2956    REG_GPIO_PXTRGS(p) = (1 << o); \
2957    REG_GPIO_PXDIRC(p) = (1 << o); \
2958    REG_GPIO_PXDATC(p) = (1 << o); \
2959    REG_GPIO_PXIMC(p) = (1 << o); \
2960} while (0)
2961
2962#define __gpio_mask_irq(n) \
2963do { \
2964    unsigned int p, o; \
2965    p = (n) / 32; \
2966    o = (n) % 32; \
2967    REG_GPIO_PXIMS(p) = (1 << o); \
2968} while (0)
2969
2970#define __gpio_unmask_irq(n) \
2971do { \
2972    unsigned int p, o; \
2973    p = (n) / 32; \
2974    o = (n) % 32; \
2975    REG_GPIO_PXIMC(p) = (1 << o); \
2976} while (0)
2977
2978#define __gpio_ack_irq(n) \
2979do { \
2980    unsigned int p, o; \
2981    p = (n) / 32; \
2982    o = (n) % 32; \
2983    REG_GPIO_PXDATC(p) = (1 << o); \
2984} while (0)
2985
2986#define __gpio_get_irq() \
2987({ \
2988    unsigned int p, i, tmp, v = 0; \
2989    for (p = 3; p >= 0; p--) { \
2990        tmp = REG_GPIO_PXFLG(p); \
2991        for (i = 0; i < 32; i++) \
2992            if (tmp & (1 << i)) \
2993                v = (32*p + i); \
2994    } \
2995    v; \
2996})
2997
2998#define __gpio_group_irq(n) \
2999({ \
3000    register int tmp, i; \
3001    tmp = REG_GPIO_PXFLG((n)); \
3002    for (i=31;i>=0;i--) \
3003        if (tmp & (1 << i)) \
3004            break; \
3005    i; \
3006})
3007
3008#define __gpio_enable_pull(n) \
3009do { \
3010    unsigned int p, o; \
3011    p = (n) / 32; \
3012    o = (n) % 32; \
3013    REG_GPIO_PXPEC(p) = (1 << o); \
3014} while (0)
3015
3016#define __gpio_disable_pull(n) \
3017do { \
3018    unsigned int p, o; \
3019    p = (n) / 32; \
3020    o = (n) % 32; \
3021    REG_GPIO_PXPES(p) = (1 << o); \
3022} while (0)
3023
3024
3025/***************************************************************************
3026 * CPM
3027 ***************************************************************************/
3028#define __cpm_get_pllm() \
3029    ((REG_CPM_CPPCR & CPM_CPPCR_PLLM_MASK) >> CPM_CPPCR_PLLM_BIT)
3030#define __cpm_get_plln() \
3031    ((REG_CPM_CPPCR & CPM_CPPCR_PLLN_MASK) >> CPM_CPPCR_PLLN_BIT)
3032#define __cpm_get_pllod() \
3033    ((REG_CPM_CPPCR & CPM_CPPCR_PLLOD_MASK) >> CPM_CPPCR_PLLOD_BIT)
3034
3035#define __cpm_get_cdiv() \
3036    ((REG_CPM_CPCCR & CPM_CPCCR_CDIV_MASK) >> CPM_CPCCR_CDIV_BIT)
3037#define __cpm_get_hdiv() \
3038    ((REG_CPM_CPCCR & CPM_CPCCR_HDIV_MASK) >> CPM_CPCCR_HDIV_BIT)
3039#define __cpm_get_pdiv() \
3040    ((REG_CPM_CPCCR & CPM_CPCCR_PDIV_MASK) >> CPM_CPCCR_PDIV_BIT)
3041#define __cpm_get_mdiv() \
3042    ((REG_CPM_CPCCR & CPM_CPCCR_MDIV_MASK) >> CPM_CPCCR_MDIV_BIT)
3043#define __cpm_get_ldiv() \
3044    ((REG_CPM_CPCCR & CPM_CPCCR_LDIV_MASK) >> CPM_CPCCR_LDIV_BIT)
3045#define __cpm_get_udiv() \
3046    ((REG_CPM_CPCCR & CPM_CPCCR_UDIV_MASK) >> CPM_CPCCR_UDIV_BIT)
3047#define __cpm_get_i2sdiv() \
3048    ((REG_CPM_I2SCDR & CPM_I2SCDR_I2SDIV_MASK) >> CPM_I2SCDR_I2SDIV_BIT)
3049#define __cpm_get_pixdiv() \
3050    ((REG_CPM_LPCDR & CPM_LPCDR_PIXDIV_MASK) >> CPM_LPCDR_PIXDIV_BIT)
3051#define __cpm_get_mscdiv() \
3052    ((REG_CPM_MSCCDR & CPM_MSCCDR_MSCDIV_MASK) >> CPM_MSCCDR_MSCDIV_BIT)
3053
3054#define __cpm_set_cdiv(v) \
3055    (REG_CPM_CPCCR = (REG_CPM_CPCCR & ~CPM_CPCCR_CDIV_MASK) | ((v) << (CPM_CPCCR_CDIV_BIT)))
3056#define __cpm_set_hdiv(v) \
3057    (REG_CPM_CPCCR = (REG_CPM_CPCCR & ~CPM_CPCCR_HDIV_MASK) | ((v) << (CPM_CPCCR_HDIV_BIT)))
3058#define __cpm_set_pdiv(v) \
3059    (REG_CPM_CPCCR = (REG_CPM_CPCCR & ~CPM_CPCCR_PDIV_MASK) | ((v) << (CPM_CPCCR_PDIV_BIT)))
3060#define __cpm_set_mdiv(v) \
3061    (REG_CPM_CPCCR = (REG_CPM_CPCCR & ~CPM_CPCCR_MDIV_MASK) | ((v) << (CPM_CPCCR_MDIV_BIT)))
3062#define __cpm_set_ldiv(v) \
3063    (REG_CPM_CPCCR = (REG_CPM_CPCCR & ~CPM_CPCCR_LDIV_MASK) | ((v) << (CPM_CPCCR_LDIV_BIT)))
3064#define __cpm_set_udiv(v) \
3065    (REG_CPM_CPCCR = (REG_CPM_CPCCR & ~CPM_CPCCR_UDIV_MASK) | ((v) << (CPM_CPCCR_UDIV_BIT)))
3066#define __cpm_set_i2sdiv(v) \
3067    (REG_CPM_I2SCDR = (REG_CPM_I2SCDR & ~CPM_I2SCDR_I2SDIV_MASK) | ((v) << (CPM_I2SCDR_I2SDIV_BIT)))
3068#define __cpm_set_pixdiv(v) \
3069    (REG_CPM_LPCDR = (REG_CPM_LPCDR & ~CPM_LPCDR_PIXDIV_MASK) | ((v) << (CPM_LPCDR_PIXDIV_BIT)))
3070#define __cpm_set_mscdiv(v) \
3071    (REG_CPM_MSCCDR = (REG_CPM_MSCCDR & ~CPM_MSCCDR_MSCDIV_MASK) | ((v) << (CPM_MSCCDR_MSCDIV_BIT)))
3072
3073#define __cpm_select_i2sclk_exclk() (REG_CPM_CPCCR &= ~CPM_CPCCR_I2CS)
3074#define __cpm_select_i2sclk_pll() (REG_CPM_CPCCR |= CPM_CPCCR_I2CS)
3075#define __cpm_enable_cko() (REG_CPM_CPCCR |= CPM_CPCCR_CLKOEN)
3076#define __cpm_select_usbclk_exclk() (REG_CPM_CPCCR &= ~CPM_CPCCR_UCS)
3077#define __cpm_select_usbclk_pll() (REG_CPM_CPCCR |= CPM_CPCCR_UCS)
3078#define __cpm_enable_pll_change() (REG_CPM_CPCCR |= CPM_CPCCR_CE)
3079#define __cpm_pllout_direct() (REG_CPM_CPCCR |= CPM_CPCCR_PCS)
3080#define __cpm_pllout_div2() (REG_CPM_CPCCR &= ~CPM_CPCCR_PCS)
3081
3082#define __cpm_pll_is_on() (REG_CPM_CPPCR & CPM_CPPCR_PLLS)
3083#define __cpm_pll_bypass() (REG_CPM_CPPCR |= CPM_CPPCR_PLLBP)
3084#define __cpm_pll_enable() (REG_CPM_CPPCR |= CPM_CPPCR_PLLEN)
3085
3086#define __cpm_get_cclk_doze_duty() \
3087    ((REG_CPM_LCR & CPM_LCR_DOZE_DUTY_MASK) >> CPM_LCR_DOZE_DUTY_BIT)
3088#define __cpm_set_cclk_doze_duty(v) \
3089    (REG_CPM_LCR = (REG_CPM_LCR & ~CPM_LCR_DOZE_DUTY_MASK) | ((v) << (CPM_LCR_DOZE_DUTY_BIT)))
3090
3091#define __cpm_doze_mode() (REG_CPM_LCR |= CPM_LCR_DOZE_ON)
3092#define __cpm_idle_mode() \
3093    (REG_CPM_LCR = (REG_CPM_LCR & ~CPM_LCR_LPM_MASK) | CPM_LCR_LPM_IDLE)
3094#define __cpm_sleep_mode() \
3095    (REG_CPM_LCR = (REG_CPM_LCR & ~CPM_LCR_LPM_MASK) | CPM_LCR_LPM_SLEEP)
3096
3097#define __cpm_stop_all() (REG_CPM_CLKGR = 0x7fff)
3098#define __cpm_stop_uart1() (REG_CPM_CLKGR |= CPM_CLKGR_UART1)
3099#define __cpm_stop_uhc() (REG_CPM_CLKGR |= CPM_CLKGR_UHC)
3100#define __cpm_stop_ipu() (REG_CPM_CLKGR |= CPM_CLKGR_IPU)
3101#define __cpm_stop_dmac() (REG_CPM_CLKGR |= CPM_CLKGR_DMAC)
3102#define __cpm_stop_udc() (REG_CPM_CLKGR |= CPM_CLKGR_UDC)
3103#define __cpm_stop_lcd() (REG_CPM_CLKGR |= CPM_CLKGR_LCD)
3104#define __cpm_stop_cim() (REG_CPM_CLKGR |= CPM_CLKGR_CIM)
3105#define __cpm_stop_sadc() (REG_CPM_CLKGR |= CPM_CLKGR_SADC)
3106#define __cpm_stop_msc() (REG_CPM_CLKGR |= CPM_CLKGR_MSC)
3107#define __cpm_stop_aic1() (REG_CPM_CLKGR |= CPM_CLKGR_AIC1)
3108#define __cpm_stop_aic2() (REG_CPM_CLKGR |= CPM_CLKGR_AIC2)
3109#define __cpm_stop_ssi() (REG_CPM_CLKGR |= CPM_CLKGR_SSI)
3110#define __cpm_stop_i2c() (REG_CPM_CLKGR |= CPM_CLKGR_I2C)
3111#define __cpm_stop_rtc() (REG_CPM_CLKGR |= CPM_CLKGR_RTC)
3112#define __cpm_stop_tcu() (REG_CPM_CLKGR |= CPM_CLKGR_TCU)
3113#define __cpm_stop_uart0() (REG_CPM_CLKGR |= CPM_CLKGR_UART0)
3114
3115#define __cpm_start_all() (REG_CPM_CLKGR = 0x0)
3116#define __cpm_start_uart1() (REG_CPM_CLKGR &= ~CPM_CLKGR_UART1)
3117#define __cpm_start_uhc() (REG_CPM_CLKGR &= ~CPM_CLKGR_UHC)
3118#define __cpm_start_ipu() (REG_CPM_CLKGR &= ~CPM_CLKGR_IPU)
3119#define __cpm_start_dmac() (REG_CPM_CLKGR &= ~CPM_CLKGR_DMAC)
3120#define __cpm_start_udc() (REG_CPM_CLKGR &= ~CPM_CLKGR_UDC)
3121#define __cpm_start_lcd() (REG_CPM_CLKGR &= ~CPM_CLKGR_LCD)
3122#define __cpm_start_cim() (REG_CPM_CLKGR &= ~CPM_CLKGR_CIM)
3123#define __cpm_start_sadc() (REG_CPM_CLKGR &= ~CPM_CLKGR_SADC)
3124#define __cpm_start_msc() (REG_CPM_CLKGR &= ~CPM_CLKGR_MSC)
3125#define __cpm_start_aic1() (REG_CPM_CLKGR &= ~CPM_CLKGR_AIC1)
3126#define __cpm_start_aic2() (REG_CPM_CLKGR &= ~CPM_CLKGR_AIC2)
3127#define __cpm_start_ssi() (REG_CPM_CLKGR &= ~CPM_CLKGR_SSI)
3128#define __cpm_start_i2c() (REG_CPM_CLKGR &= ~CPM_CLKGR_I2C)
3129#define __cpm_start_rtc() (REG_CPM_CLKGR &= ~CPM_CLKGR_RTC)
3130#define __cpm_start_tcu() (REG_CPM_CLKGR &= ~CPM_CLKGR_TCU)
3131#define __cpm_start_uart0() (REG_CPM_CLKGR &= ~CPM_CLKGR_UART0)
3132
3133#define __cpm_get_o1st() \
3134    ((REG_CPM_SCR & CPM_SCR_O1ST_MASK) >> CPM_SCR_O1ST_BIT)
3135#define __cpm_set_o1st(v) \
3136    (REG_CPM_SCR = (REG_CPM_SCR & ~CPM_SCR_O1ST_MASK) | ((v) << (CPM_SCR_O1ST_BIT)))
3137#define __cpm_suspend_usbphy() (REG_CPM_SCR |= CPM_SCR_USBPHY_SUSPEND)
3138#define __cpm_enable_osc_in_sleep() (REG_CPM_SCR |= CPM_SCR_OSC_ENABLE)
3139
3140
3141#ifdef CFG_EXTAL
3142#define JZ_EXTAL CFG_EXTAL
3143#else
3144#define JZ_EXTAL 3686400
3145#endif
3146#define JZ_EXTAL2 32768 /* RTC clock */
3147
3148/* PLL output frequency */
3149static __inline__ unsigned int __cpm_get_pllout(void)
3150{
3151    unsigned long m, n, no, pllout;
3152    unsigned long cppcr = REG_CPM_CPPCR;
3153    unsigned long od[4] = {1, 2, 2, 4};
3154    if ((cppcr & CPM_CPPCR_PLLEN) && !(cppcr & CPM_CPPCR_PLLBP)) {
3155        m = __cpm_get_pllm() + 2;
3156        n = __cpm_get_plln() + 2;
3157        no = od[__cpm_get_pllod()];
3158        pllout = ((JZ_EXTAL) / (n * no)) * m;
3159    } else
3160        pllout = JZ_EXTAL;
3161    return pllout;
3162}
3163
3164/* PLL output frequency for MSC/I2S/LCD/USB */
3165static __inline__ unsigned int __cpm_get_pllout2(void)
3166{
3167    if (REG_CPM_CPCCR & CPM_CPCCR_PCS)
3168        return __cpm_get_pllout();
3169    else
3170        return __cpm_get_pllout()/2;
3171}
3172
3173/* CPU core clock */
3174static __inline__ unsigned int __cpm_get_cclk(void)
3175{
3176    int div[] = {1, 2, 3, 4, 6, 8, 12, 16, 24, 32};
3177
3178    return __cpm_get_pllout() / div[__cpm_get_cdiv()];
3179}
3180
3181/* AHB system bus clock */
3182static __inline__ unsigned int __cpm_get_hclk(void)
3183{
3184    int div[] = {1, 2, 3, 4, 6, 8, 12, 16, 24, 32};
3185
3186    return __cpm_get_pllout() / div[__cpm_get_hdiv()];
3187}
3188
3189/* Memory bus clock */
3190static __inline__ unsigned int __cpm_get_mclk(void)
3191{
3192    int div[] = {1, 2, 3, 4, 6, 8, 12, 16, 24, 32};
3193
3194    return __cpm_get_pllout() / div[__cpm_get_mdiv()];
3195}
3196
3197/* APB peripheral bus clock */
3198static __inline__ unsigned int __cpm_get_pclk(void)
3199{
3200    int div[] = {1, 2, 3, 4, 6, 8, 12, 16, 24, 32};
3201
3202    return __cpm_get_pllout() / div[__cpm_get_pdiv()];
3203}
3204
3205/* LCDC module clock */
3206static __inline__ unsigned int __cpm_get_lcdclk(void)
3207{
3208    return __cpm_get_pllout2() / (__cpm_get_ldiv() + 1);
3209}
3210
3211/* LCD pixel clock */
3212static __inline__ unsigned int __cpm_get_pixclk(void)
3213{
3214    return __cpm_get_pllout2() / (__cpm_get_pixdiv() + 1);
3215}
3216
3217/* I2S clock */
3218static __inline__ unsigned int __cpm_get_i2sclk(void)
3219{
3220    if (REG_CPM_CPCCR & CPM_CPCCR_I2CS) {
3221        return __cpm_get_pllout2() / (__cpm_get_i2sdiv() + 1);
3222    }
3223    else {
3224        return JZ_EXTAL;
3225    }
3226}
3227
3228/* USB clock */
3229static __inline__ unsigned int __cpm_get_usbclk(void)
3230{
3231    if (REG_CPM_CPCCR & CPM_CPCCR_UCS) {
3232        return __cpm_get_pllout2() / (__cpm_get_udiv() + 1);
3233    }
3234    else {
3235        return JZ_EXTAL;
3236    }
3237}
3238
3239/* MSC clock */
3240static __inline__ unsigned int __cpm_get_mscclk(void)
3241{
3242    return __cpm_get_pllout2() / (__cpm_get_mscdiv() + 1);
3243}
3244
3245/* EXTAL clock for UART,I2C,SSI,TCU,USB-PHY */
3246static __inline__ unsigned int __cpm_get_extalclk(void)
3247{
3248    return JZ_EXTAL;
3249}
3250
3251/* RTC clock for CPM,INTC,RTC,TCU,WDT */
3252static __inline__ unsigned int __cpm_get_rtcclk(void)
3253{
3254    return JZ_EXTAL2;
3255}
3256
3257/*
3258 * Output 24MHz for SD and 16MHz for MMC.
3259 */
3260static inline void __cpm_select_msc_clk(int sd)
3261{
3262    unsigned int pllout2 = __cpm_get_pllout2();
3263    unsigned int div = 0;
3264
3265    if (sd) {
3266        div = pllout2 / 24000000;
3267    }
3268    else {
3269        div = pllout2 / 16000000;
3270    }
3271
3272    REG_CPM_MSCCDR = div - 1;
3273}
3274
3275/***************************************************************************
3276 * TCU
3277 ***************************************************************************/
3278// where 'n' is the TCU channel
3279#define __tcu_select_extalclk(n) \
3280    (REG_TCU_TCSR((n)) = (REG_TCU_TCSR((n)) & ~(TCU_TCSR_EXT_EN | TCU_TCSR_RTC_EN | TCU_TCSR_PCK_EN)) | TCU_TCSR_EXT_EN)
3281#define __tcu_select_rtcclk(n) \
3282    (REG_TCU_TCSR((n)) = (REG_TCU_TCSR((n)) & ~(TCU_TCSR_EXT_EN | TCU_TCSR_RTC_EN | TCU_TCSR_PCK_EN)) | TCU_TCSR_RTC_EN)
3283#define __tcu_select_pclk(n) \
3284    (REG_TCU_TCSR((n)) = (REG_TCU_TCSR((n)) & ~(TCU_TCSR_EXT_EN | TCU_TCSR_RTC_EN | TCU_TCSR_PCK_EN)) | TCU_TCSR_PCK_EN)
3285
3286#define __tcu_select_clk_div1(n) \
3287    (REG_TCU_TCSR((n)) = (REG_TCU_TCSR((n)) & ~TCU_TCSR_PRESCALE_MASK) | TCU_TCSR_PRESCALE1)
3288#define __tcu_select_clk_div4(n) \
3289    (REG_TCU_TCSR((n)) = (REG_TCU_TCSR((n)) & ~TCU_TCSR_PRESCALE_MASK) | TCU_TCSR_PRESCALE4)
3290#define __tcu_select_clk_div16(n) \
3291    (REG_TCU_TCSR((n)) = (REG_TCU_TCSR((n)) & ~TCU_TCSR_PRESCALE_MASK) | TCU_TCSR_PRESCALE16)
3292#define __tcu_select_clk_div64(n) \
3293    (REG_TCU_TCSR((n)) = (REG_TCU_TCSR((n)) & ~TCU_TCSR_PRESCALE_MASK) | TCU_TCSR_PRESCALE64)
3294#define __tcu_select_clk_div256(n) \
3295    (REG_TCU_TCSR((n)) = (REG_TCU_TCSR((n)) & ~TCU_TCSR_PRESCALE_MASK) | TCU_TCSR_PRESCALE256)
3296#define __tcu_select_clk_div1024(n) \
3297    (REG_TCU_TCSR((n)) = (REG_TCU_TCSR((n)) & ~TCU_TCSR_PRESCALE_MASK) | TCU_TCSR_PRESCALE1024)
3298
3299#define __tcu_enable_pwm_output(n) ( REG_TCU_TCSR((n)) |= TCU_TCSR_PWM_EN )
3300#define __tcu_disable_pwm_output(n) ( REG_TCU_TCSR((n)) &= ~TCU_TCSR_PWM_EN )
3301
3302#define __tcu_init_pwm_output_high(n) ( REG_TCU_TCSR((n)) |= TCU_TCSR_PWM_INITL_HIGH )
3303#define __tcu_init_pwm_output_low(n) ( REG_TCU_TCSR((n)) &= ~TCU_TCSR_PWM_INITL_HIGH )
3304
3305#define __tcu_set_pwm_output_shutdown_graceful(n) ( REG_TCU_TCSR((n)) &= ~TCU_TCSR_PWM_SD )
3306#define __tcu_set_pwm_output_shutdown_abrupt(n) ( REG_TCU_TCSR((n)) |= TCU_TCSR_PWM_SD )
3307
3308#define __tcu_start_counter(n) ( REG_TCU_TESR |= (1 << (n)) )
3309#define __tcu_stop_counter(n) ( REG_TCU_TECR |= (1 << (n)) )
3310
3311#define __tcu_half_match_flag(n) ( REG_TCU_TFR & (1 << ((n) + 16)) )
3312#define __tcu_full_match_flag(n) ( REG_TCU_TFR & (1 << (n)) )
3313#define __tcu_set_half_match_flag(n) ( REG_TCU_TFSR = (1 << ((n) + 16)) )
3314#define __tcu_set_full_match_flag(n) ( REG_TCU_TFSR = (1 << (n)) )
3315#define __tcu_clear_half_match_flag(n) ( REG_TCU_TFCR = (1 << ((n) + 16)) )
3316#define __tcu_clear_full_match_flag(n) ( REG_TCU_TFCR = (1 << (n)) )
3317#define __tcu_mask_half_match_irq(n) ( REG_TCU_TMSR = (1 << ((n) + 16)) )
3318#define __tcu_mask_full_match_irq(n) ( REG_TCU_TMSR = (1 << (n)) )
3319#define __tcu_unmask_half_match_irq(n) ( REG_TCU_TMCR = (1 << ((n) + 16)) )
3320#define __tcu_unmask_full_match_irq(n) ( REG_TCU_TMCR = (1 << (n)) )
3321
3322#define __tcu_wdt_clock_stopped() ( REG_TCU_TSR & TCU_TSSR_WDTSC )
3323#define __tcu_timer_clock_stopped(n) ( REG_TCU_TSR & (1 << (n)) )
3324
3325#define __tcu_start_wdt_clock() ( REG_TCU_TSCR = TCU_TSSR_WDTSC )
3326#define __tcu_start_timer_clock(n) ( REG_TCU_TSCR = (1 << (n)) )
3327
3328#define __tcu_stop_wdt_clock() ( REG_TCU_TSSR = TCU_TSSR_WDTSC )
3329#define __tcu_stop_timer_clock(n) ( REG_TCU_TSSR = (1 << (n)) )
3330
3331#define __tcu_get_count(n) ( REG_TCU_TCNT((n)) )
3332#define __tcu_set_count(n,v) ( REG_TCU_TCNT((n)) = (v) )
3333#define __tcu_set_full_data(n,v) ( REG_TCU_TDFR((n)) = (v) )
3334#define __tcu_set_half_data(n,v) ( REG_TCU_TDHR((n)) = (v) )
3335
3336
3337/***************************************************************************
3338 * WDT
3339 ***************************************************************************/
3340#define __wdt_start() ( REG_WDT_TCER |= WDT_TCER_TCEN )
3341#define __wdt_stop() ( REG_WDT_TCER &= ~WDT_TCER_TCEN )
3342#define __wdt_set_count(v) ( REG_WDT_TCNT = (v) )
3343#define __wdt_set_data(v) ( REG_WDT_TDR = (v) )
3344
3345#define __wdt_select_extalclk() \
3346    (REG_WDT_TCSR = (REG_WDT_TCSR & ~(WDT_TCSR_EXT_EN | WDT_TCSR_RTC_EN | WDT_TCSR_PCK_EN)) | WDT_TCSR_EXT_EN)
3347#define __wdt_select_rtcclk() \
3348    (REG_WDT_TCSR = (REG_WDT_TCSR & ~(WDT_TCSR_EXT_EN | WDT_TCSR_RTC_EN | WDT_TCSR_PCK_EN)) | WDT_TCSR_RTC_EN)
3349#define __wdt_select_pclk() \
3350    (REG_WDT_TCSR = (REG_WDT_TCSR & ~(WDT_TCSR_EXT_EN | WDT_TCSR_RTC_EN | WDT_TCSR_PCK_EN)) | WDT_TCSR_PCK_EN)
3351
3352#define __wdt_select_clk_div1() \
3353    (REG_WDT_TCSR = (REG_WDT_TCSR & ~WDT_TCSR_PRESCALE_MASK) | WDT_TCSR_PRESCALE1)
3354#define __wdt_select_clk_div4() \
3355    (REG_WDT_TCSR = (REG_WDT_TCSR & ~WDT_TCSR_PRESCALE_MASK) | WDT_TCSR_PRESCALE4)
3356#define __wdt_select_clk_div16() \
3357    (REG_WDT_TCSR = (REG_WDT_TCSR & ~WDT_TCSR_PRESCALE_MASK) | WDT_TCSR_PRESCALE16)
3358#define __wdt_select_clk_div64() \
3359    (REG_WDT_TCSR = (REG_WDT_TCSR & ~WDT_TCSR_PRESCALE_MASK) | WDT_TCSR_PRESCALE64)
3360#define __wdt_select_clk_div256() \
3361    (REG_WDT_TCSR = (REG_WDT_TCSR & ~WDT_TCSR_PRESCALE_MASK) | WDT_TCSR_PRESCALE256)
3362#define __wdt_select_clk_div1024() \
3363    (REG_WDT_TCSR = (REG_WDT_TCSR & ~WDT_TCSR_PRESCALE_MASK) | WDT_TCSR_PRESCALE1024)
3364
3365
3366/***************************************************************************
3367 * UART
3368 ***************************************************************************/
3369
3370#define __uart_enable() ( REG8(UART0_FCR) |= UARTFCR_UUE | UARTFCR_FE )
3371#define __uart_disable() ( REG8(UART0_FCR) = ~UARTFCR_UUE )
3372
3373#define __uart_enable_transmit_irq() ( REG8(UART0_IER) |= UARTIER_TIE )
3374#define __uart_disable_transmit_irq() ( REG8(UART0_IER) &= ~UARTIER_TIE )
3375
3376#define __uart_enable_receive_irq() \
3377  ( REG8(UART0_IER) |= UARTIER_RIE | UARTIER_RLIE | UARTIER_RTIE )
3378#define __uart_disable_receive_irq() \
3379  ( REG8(UART0_IER) &= ~(UARTIER_RIE | UARTIER_RLIE | UARTIER_RTIE) )
3380
3381#define __uart_enable_loopback() ( REG8(UART0_MCR) |= UARTMCR_LOOP )
3382#define __uart_disable_loopback() ( REG8(UART0_MCR) &= ~UARTMCR_LOOP )
3383
3384#define __uart_set_8n1() ( REG8(UART0_LCR) = UARTLCR_WLEN_8 )
3385
3386#define __uart_set_baud(devclk, baud) \
3387  do { \
3388    REG8(UART0_LCR) |= UARTLCR_DLAB; \
3389    REG8(UART0_DLLR) = (devclk / 16 / baud) & 0xff; \
3390    REG8(UART0_DLHR) = ((devclk / 16 / baud) >> 8) & 0xff; \
3391    REG8(UART0_LCR) &= ~UARTLCR_DLAB; \
3392  } while (0)
3393
3394#define __uart_parity_error() ( (REG8(UART0_LSR) & UARTLSR_PER) != 0 )
3395#define __uart_clear_errors() \
3396  ( REG8(UART0_LSR) &= ~(UARTLSR_ORER | UARTLSR_BRK | UARTLSR_FER | UARTLSR_PER | UARTLSR_RFER) )
3397
3398#define __uart_transmit_fifo_empty() ( (REG8(UART0_LSR) & UARTLSR_TDRQ) != 0 )
3399#define __uart_transmit_end() ( (REG8(UART0_LSR) & UARTLSR_TEMT) != 0 )
3400#define __uart_transmit_char(ch) ( REG8(UART0_TDR) = (ch) )
3401#define __uart_receive_fifo_full() ( (REG8(UART0_LSR) & UARTLSR_DR) != 0 )
3402#define __uart_receive_ready() ( (REG8(UART0_LSR) & UARTLSR_DR) != 0 )
3403#define __uart_receive_char() REG8(UART0_RDR)
3404#define __uart_disable_irda() ( REG8(UART0_SIRCR) &= ~(SIRCR_TSIRE | SIRCR_RSIRE) )
3405#define __uart_enable_irda() \
3406  /* Tx high pulse as 0, Rx low pulse as 0 */ \
3407  ( REG8(UART0_SIRCR) = SIRCR_TSIRE | SIRCR_RSIRE | SIRCR_RXPL | SIRCR_TPWS )
3408
3409
3410/***************************************************************************
3411 * DMAC
3412 ***************************************************************************/
3413
3414/* n is the DMA channel (0 - 5) */
3415
3416#define __dmac_enable_module() \
3417  ( REG_DMAC_DMACR |= DMAC_DMACR_DMAE | DMAC_DMACR_PR_RR )
3418#define __dmac_disable_module() \
3419  ( REG_DMAC_DMACR &= ~DMAC_DMACR_DMAE )
3420
3421/* p=0,1,2,3 */
3422#define __dmac_set_priority(p) \
3423do { \
3424    REG_DMAC_DMACR &= ~DMAC_DMACR_PR_MASK; \
3425    REG_DMAC_DMACR |= ((p) << DMAC_DMACR_PR_BIT); \
3426} while (0)
3427
3428#define __dmac_test_halt_error() ( REG_DMAC_DMACR & DMAC_DMACR_HLT )
3429#define __dmac_test_addr_error() ( REG_DMAC_DMACR & DMAC_DMACR_AR )
3430
3431#define __dmac_enable_descriptor(n) \
3432  ( REG_DMAC_DCCSR((n)) &= ~DMAC_DCCSR_NDES )
3433#define __dmac_disable_descriptor(n) \
3434  ( REG_DMAC_DCCSR((n)) |= DMAC_DCCSR_NDES )
3435
3436#define __dmac_enable_channel(n) \
3437  ( REG_DMAC_DCCSR((n)) |= DMAC_DCCSR_EN )
3438#define __dmac_disable_channel(n) \
3439  ( REG_DMAC_DCCSR((n)) &= ~DMAC_DCCSR_EN )
3440#define __dmac_channel_enabled(n) \
3441  ( REG_DMAC_DCCSR((n)) & DMAC_DCCSR_EN )
3442
3443#define __dmac_channel_enable_irq(n) \
3444  ( REG_DMAC_DCMD((n)) |= DMAC_DCMD_TIE )
3445#define __dmac_channel_disable_irq(n) \
3446  ( REG_DMAC_DCMD((n)) &= ~DMAC_DCMD_TIE )
3447
3448#define __dmac_channel_transmit_halt_detected(n) \
3449  ( REG_DMAC_DCCSR((n)) & DMAC_DCCSR_HLT )
3450#define __dmac_channel_transmit_end_detected(n) \
3451  ( REG_DMAC_DCCSR((n)) & DMAC_DCCSR_TT )
3452#define __dmac_channel_address_error_detected(n) \
3453  ( REG_DMAC_DCCSR((n)) & DMAC_DCCSR_AR )
3454#define __dmac_channel_count_terminated_detected(n) \
3455  ( REG_DMAC_DCCSR((n)) & DMAC_DCCSR_CT )
3456#define __dmac_channel_descriptor_invalid_detected(n) \
3457  ( REG_DMAC_DCCSR((n)) & DMAC_DCCSR_INV )
3458
3459#define __dmac_channel_clear_transmit_halt(n) \
3460  ( REG_DMAC_DCCSR(n) &= ~DMAC_DCCSR_HLT )
3461#define __dmac_channel_clear_transmit_end(n) \
3462  ( REG_DMAC_DCCSR(n) &= ~DMAC_DCCSR_TT )
3463#define __dmac_channel_clear_address_error(n) \
3464  ( REG_DMAC_DCCSR(n) &= ~DMAC_DCCSR_AR )
3465#define __dmac_channel_clear_count_terminated(n) \
3466  ( REG_DMAC_DCCSR((n)) &= ~DMAC_DCCSR_CT )
3467#define __dmac_channel_clear_descriptor_invalid(n) \
3468  ( REG_DMAC_DCCSR((n)) &= ~DMAC_DCCSR_INV )
3469
3470#define __dmac_channel_set_single_mode(n) \
3471  ( REG_DMAC_DCMD((n)) &= ~DMAC_DCMD_TM )
3472#define __dmac_channel_set_block_mode(n) \
3473  ( REG_DMAC_DCMD((n)) |= DMAC_DCMD_TM )
3474
3475#define __dmac_channel_set_transfer_unit_32bit(n) \
3476do { \
3477    REG_DMAC_DCMD((n)) &= ~DMAC_DCMD_DS_MASK; \
3478    REG_DMAC_DCMD((n)) |= DMAC_DCMD_DS_32BIT; \
3479} while (0)
3480
3481#define __dmac_channel_set_transfer_unit_16bit(n) \
3482do { \
3483    REG_DMAC_DCMD((n)) &= ~DMAC_DCMD_DS_MASK; \
3484    REG_DMAC_DCMD((n)) |= DMAC_DCMD_DS_16BIT; \
3485} while (0)
3486
3487#define __dmac_channel_set_transfer_unit_8bit(n) \
3488do { \
3489    REG_DMAC_DCMD((n)) &= ~DMAC_DCMD_DS_MASK; \
3490    REG_DMAC_DCMD((n)) |= DMAC_DCMD_DS_8BIT; \
3491} while (0)
3492
3493#define __dmac_channel_set_transfer_unit_16byte(n) \
3494do { \
3495    REG_DMAC_DCMD((n)) &= ~DMAC_DCMD_DS_MASK; \
3496    REG_DMAC_DCMD((n)) |= DMAC_DCMD_DS_16BYTE; \
3497} while (0)
3498
3499#define __dmac_channel_set_transfer_unit_32byte(n) \
3500do { \
3501    REG_DMAC_DCMD((n)) &= ~DMAC_DCMD_DS_MASK; \
3502    REG_DMAC_DCMD((n)) |= DMAC_DCMD_DS_32BYTE; \
3503} while (0)
3504
3505/* w=8,16,32 */
3506#define __dmac_channel_set_dest_port_width(n,w) \
3507do { \
3508    REG_DMAC_DCMD((n)) &= ~DMAC_DCMD_DWDH_MASK; \
3509    REG_DMAC_DCMD((n)) |= DMAC_DCMD_DWDH_##w; \
3510} while (0)
3511
3512/* w=8,16,32 */
3513#define __dmac_channel_set_src_port_width(n,w) \
3514do { \
3515    REG_DMAC_DCMD((n)) &= ~DMAC_DCMD_SWDH_MASK; \
3516    REG_DMAC_DCMD((n)) |= DMAC_DCMD_SWDH_##w; \
3517} while (0)
3518
3519/* v=0-15 */
3520#define __dmac_channel_set_rdil(n,v) \
3521do { \
3522    REG_DMAC_DCMD((n)) &= ~DMAC_DCMD_RDIL_MASK; \
3523    REG_DMAC_DCMD((n) |= ((v) << DMAC_DCMD_RDIL_BIT); \
3524} while (0)
3525
3526#define __dmac_channel_dest_addr_fixed(n) \
3527  ( REG_DMAC_DCMD((n)) &= ~DMAC_DCMD_DAI )
3528#define __dmac_channel_dest_addr_increment(n) \
3529  ( REG_DMAC_DCMD((n)) |= DMAC_DCMD_DAI )
3530
3531#define __dmac_channel_src_addr_fixed(n) \
3532  ( REG_DMAC_DCMD((n)) &= ~DMAC_DCMD_SAI )
3533#define __dmac_channel_src_addr_increment(n) \
3534  ( REG_DMAC_DCMD((n)) |= DMAC_DCMD_SAI )
3535
3536#define __dmac_channel_set_doorbell(n) \
3537  ( REG_DMAC_DMADBSR = (1 << (n)) )
3538
3539#define __dmac_channel_irq_detected(n) ( REG_DMAC_DMAIPR & (1 << (n)) )
3540#define __dmac_channel_ack_irq(n) ( REG_DMAC_DMAIPR &= ~(1 << (n)) )
3541
3542static __inline__ int __dmac_get_irq(void)
3543{
3544    int i;
3545    for (i = 0; i < MAX_DMA_NUM; i++)
3546        if (__dmac_channel_irq_detected(i))
3547            return i;
3548    return -1;
3549}
3550
3551
3552/***************************************************************************
3553 * AIC (AC'97 & I2S Controller)
3554 ***************************************************************************/
3555
3556#define __aic_enable() ( REG_AIC_FR |= AIC_FR_ENB )
3557#define __aic_disable() ( REG_AIC_FR &= ~AIC_FR_ENB )
3558
3559#define __aic_select_ac97() ( REG_AIC_FR &= ~AIC_FR_AUSEL )
3560#define __aic_select_i2s() ( REG_AIC_FR |= AIC_FR_AUSEL )
3561
3562#define __i2s_as_master() ( REG_AIC_FR |= AIC_FR_BCKD | AIC_FR_SYNCD )
3563#define __i2s_as_slave() ( REG_AIC_FR &= ~(AIC_FR_BCKD | AIC_FR_SYNCD) )
3564#define __aic_reset_status() ( REG_AIC_FR & AIC_FR_RST )
3565
3566#define __aic_reset() \
3567do { \
3568        REG_AIC_FR |= AIC_FR_RST; \
3569} while(0)
3570
3571
3572#define __aic_set_transmit_trigger(n) \
3573do { \
3574    REG_AIC_FR &= ~AIC_FR_TFTH_MASK; \
3575    REG_AIC_FR |= ((n) << AIC_FR_TFTH_BIT); \
3576} while(0)
3577
3578#define __aic_set_receive_trigger(n) \
3579do { \
3580    REG_AIC_FR &= ~AIC_FR_RFTH_MASK; \
3581    REG_AIC_FR |= ((n) << AIC_FR_RFTH_BIT); \
3582} while(0)
3583
3584#define __aic_enable_record() ( REG_AIC_CR |= AIC_CR_EREC )
3585#define __aic_disable_record() ( REG_AIC_CR &= ~AIC_CR_EREC )
3586#define __aic_enable_replay() ( REG_AIC_CR |= AIC_CR_ERPL )
3587#define __aic_disable_replay() ( REG_AIC_CR &= ~AIC_CR_ERPL )
3588#define __aic_enable_loopback() ( REG_AIC_CR |= AIC_CR_ENLBF )
3589#define __aic_disable_loopback() ( REG_AIC_CR &= ~AIC_CR_ENLBF )
3590
3591#define __aic_flush_fifo() ( REG_AIC_CR |= AIC_CR_FLUSH )
3592#define __aic_unflush_fifo() ( REG_AIC_CR &= ~AIC_CR_FLUSH )
3593
3594#define __aic_enable_transmit_intr() \
3595  ( REG_AIC_CR |= (AIC_CR_ETFS | AIC_CR_ETUR) )
3596#define __aic_disable_transmit_intr() \
3597  ( REG_AIC_CR &= ~(AIC_CR_ETFS | AIC_CR_ETUR) )
3598#define __aic_enable_receive_intr() \
3599  ( REG_AIC_CR |= (AIC_CR_ERFS | AIC_CR_EROR) )
3600#define __aic_disable_receive_intr() \
3601  ( REG_AIC_CR &= ~(AIC_CR_ERFS | AIC_CR_EROR) )
3602
3603#define __aic_enable_transmit_dma() ( REG_AIC_CR |= AIC_CR_TDMS )
3604#define __aic_disable_transmit_dma() ( REG_AIC_CR &= ~AIC_CR_TDMS )
3605#define __aic_enable_receive_dma() ( REG_AIC_CR |= AIC_CR_RDMS )
3606#define __aic_disable_receive_dma() ( REG_AIC_CR &= ~AIC_CR_RDMS )
3607
3608#define __aic_enable_mono2stereo() ( REG_AIC_CR |= AIC_CR_M2S )
3609#define __aic_disable_mono2stereo() ( REG_AIC_CR &= ~AIC_CR_M2S )
3610#define __aic_enable_byteswap() ( REG_AIC_CR |= AIC_CR_ENDSW )
3611#define __aic_disable_byteswap() ( REG_AIC_CR &= ~AIC_CR_ENDSW )
3612#define __aic_enable_unsignadj() ( REG_AIC_CR |= AIC_CR_AVSTSU )
3613#define __aic_disable_unsignadj() ( REG_AIC_CR &= ~AIC_CR_AVSTSU )
3614
3615#define AC97_PCM_XS_L_FRONT AIC_ACCR1_XS_SLOT3
3616#define AC97_PCM_XS_R_FRONT AIC_ACCR1_XS_SLOT4
3617#define AC97_PCM_XS_CENTER AIC_ACCR1_XS_SLOT6
3618#define AC97_PCM_XS_L_SURR AIC_ACCR1_XS_SLOT7
3619#define AC97_PCM_XS_R_SURR AIC_ACCR1_XS_SLOT8
3620#define AC97_PCM_XS_LFE AIC_ACCR1_XS_SLOT9
3621
3622#define AC97_PCM_RS_L_FRONT AIC_ACCR1_RS_SLOT3
3623#define AC97_PCM_RS_R_FRONT AIC_ACCR1_RS_SLOT4
3624#define AC97_PCM_RS_CENTER AIC_ACCR1_RS_SLOT6
3625#define AC97_PCM_RS_L_SURR AIC_ACCR1_RS_SLOT7
3626#define AC97_PCM_RS_R_SURR AIC_ACCR1_RS_SLOT8
3627#define AC97_PCM_RS_LFE AIC_ACCR1_RS_SLOT9
3628
3629#define __ac97_set_xs_none() ( REG_AIC_ACCR1 &= ~AIC_ACCR1_XS_MASK )
3630#define __ac97_set_xs_mono() \
3631do { \
3632    REG_AIC_ACCR1 &= ~AIC_ACCR1_XS_MASK; \
3633    REG_AIC_ACCR1 |= AC97_PCM_XS_R_FRONT; \
3634} while(0)
3635#define __ac97_set_xs_stereo() \
3636do { \
3637    REG_AIC_ACCR1 &= ~AIC_ACCR1_XS_MASK; \
3638    REG_AIC_ACCR1 |= AC97_PCM_XS_L_FRONT | AC97_PCM_XS_R_FRONT; \
3639} while(0)
3640
3641/* In fact, only stereo is support now. */
3642#define __ac97_set_rs_none() ( REG_AIC_ACCR1 &= ~AIC_ACCR1_RS_MASK )
3643#define __ac97_set_rs_mono() \
3644do { \
3645    REG_AIC_ACCR1 &= ~AIC_ACCR1_RS_MASK; \
3646    REG_AIC_ACCR1 |= AC97_PCM_RS_R_FRONT; \
3647} while(0)
3648#define __ac97_set_rs_stereo() \
3649do { \
3650    REG_AIC_ACCR1 &= ~AIC_ACCR1_RS_MASK; \
3651    REG_AIC_ACCR1 |= AC97_PCM_RS_L_FRONT | AC97_PCM_RS_R_FRONT; \
3652} while(0)
3653
3654#define __ac97_warm_reset_codec() \
3655 do { \
3656    REG_AIC_ACCR2 |= AIC_ACCR2_SA; \
3657    REG_AIC_ACCR2 |= AIC_ACCR2_SS; \
3658    udelay(2); \
3659    REG_AIC_ACCR2 &= ~AIC_ACCR2_SS; \
3660    REG_AIC_ACCR2 &= ~AIC_ACCR2_SA; \
3661 } while (0)
3662
3663#define __ac97_cold_reset_codec() \
3664 do { \
3665    REG_AIC_ACCR2 |= AIC_ACCR2_SR; \
3666    udelay(2); \
3667    REG_AIC_ACCR2 &= ~AIC_ACCR2_SR; \
3668 } while (0)
3669
3670/* n=8,16,18,20 */
3671#define __ac97_set_iass(n) \
3672 ( REG_AIC_ACCR2 = (REG_AIC_ACCR2 & ~AIC_ACCR2_IASS_MASK) | AIC_ACCR2_IASS_##n##BIT )
3673#define __ac97_set_oass(n) \
3674 ( REG_AIC_ACCR2 = (REG_AIC_ACCR2 & ~AIC_ACCR2_OASS_MASK) | AIC_ACCR2_OASS_##n##BIT )
3675
3676#define __i2s_select_i2s() ( REG_AIC_I2SCR &= ~AIC_I2SCR_AMSL )
3677#define __i2s_select_msbjustified() ( REG_AIC_I2SCR |= AIC_I2SCR_AMSL )
3678
3679/* n=8,16,18,20,24 */
3680/*#define __i2s_set_sample_size(n) \
3681 ( REG_AIC_I2SCR |= (REG_AIC_I2SCR & ~AIC_I2SCR_WL_MASK) | AIC_I2SCR_WL_##n##BIT )*/
3682
3683#define __i2s_set_oss_sample_size(n) \
3684 ( REG_AIC_CR = (REG_AIC_CR & ~AIC_CR_OSS_MASK) | AIC_CR_OSS_##n##BIT )
3685#define __i2s_set_iss_sample_size(n) \
3686 ( REG_AIC_CR = (REG_AIC_CR & ~AIC_CR_ISS_MASK) | AIC_CR_ISS_##n##BIT )
3687
3688#define __i2s_stop_bitclk() ( REG_AIC_I2SCR |= AIC_I2SCR_STPBK )
3689#define __i2s_start_bitclk() ( REG_AIC_I2SCR &= ~AIC_I2SCR_STPBK )
3690
3691#define __aic_transmit_request() ( REG_AIC_SR & AIC_SR_TFS )
3692#define __aic_receive_request() ( REG_AIC_SR & AIC_SR_RFS )
3693#define __aic_transmit_underrun() ( REG_AIC_SR & AIC_SR_TUR )
3694#define __aic_receive_overrun() ( REG_AIC_SR & AIC_SR_ROR )
3695
3696#define __aic_clear_errors() ( REG_AIC_SR &= ~(AIC_SR_TUR | AIC_SR_ROR) )
3697
3698#define __aic_get_transmit_resident() \
3699  ( (REG_AIC_SR & AIC_SR_TFL_MASK) >> AIC_SR_TFL_BIT )
3700#define __aic_get_receive_count() \
3701  ( (REG_AIC_SR & AIC_SR_RFL_MASK) >> AIC_SR_RFL_BIT )
3702
3703#define __ac97_command_transmitted() ( REG_AIC_ACSR & AIC_ACSR_CADT )
3704#define __ac97_status_received() ( REG_AIC_ACSR & AIC_ACSR_SADR )
3705#define __ac97_status_receive_timeout() ( REG_AIC_ACSR & AIC_ACSR_RSTO )
3706#define __ac97_codec_is_low_power_mode() ( REG_AIC_ACSR & AIC_ACSR_CLPM )
3707#define __ac97_codec_is_ready() ( REG_AIC_ACSR & AIC_ACSR_CRDY )
3708#define __ac97_slot_error_detected() ( REG_AIC_ACSR & AIC_ACSR_SLTERR )
3709#define __ac97_clear_slot_error() ( REG_AIC_ACSR &= ~AIC_ACSR_SLTERR )
3710
3711#define __i2s_is_busy() ( REG_AIC_I2SSR & AIC_I2SSR_BSY )
3712
3713#define CODEC_READ_CMD (1 << 19)
3714#define CODEC_WRITE_CMD (0 << 19)
3715#define CODEC_REG_INDEX_BIT 12
3716#define CODEC_REG_INDEX_MASK (0x7f << CODEC_REG_INDEX_BIT) /* 18:12 */
3717#define CODEC_REG_DATA_BIT 4
3718#define CODEC_REG_DATA_MASK (0x0ffff << 4) /* 19:4 */
3719
3720#define __ac97_out_rcmd_addr(reg) \
3721do { \
3722    REG_AIC_ACCAR = CODEC_READ_CMD | ((reg) << CODEC_REG_INDEX_BIT); \
3723} while (0)
3724
3725#define __ac97_out_wcmd_addr(reg) \
3726do { \
3727    REG_AIC_ACCAR = CODEC_WRITE_CMD | ((reg) << CODEC_REG_INDEX_BIT); \
3728} while (0)
3729
3730#define __ac97_out_data(value) \
3731do { \
3732    REG_AIC_ACCDR = ((value) << CODEC_REG_DATA_BIT); \
3733} while (0)
3734
3735#define __ac97_in_data() \
3736 ( (REG_AIC_ACSDR & CODEC_REG_DATA_MASK) >> CODEC_REG_DATA_BIT )
3737
3738#define __ac97_in_status_addr() \
3739 ( (REG_AIC_ACSAR & CODEC_REG_INDEX_MASK) >> CODEC_REG_INDEX_BIT )
3740
3741#define __i2s_set_sample_rate(i2sclk, sync) \
3742  ( REG_AIC_I2SDIV = ((i2sclk) / (4*64)) / (sync) )
3743
3744#define __aic_write_tfifo(v) ( REG_AIC_DR = (v) )
3745#define __aic_read_rfifo() ( REG_AIC_DR )
3746
3747#define __aic_internal_codec() ( REG_AIC_FR |= AIC_FR_ICDC )
3748#define __aic_external_codec() ( REG_AIC_FR &= ~AIC_FR_ICDC )
3749
3750//
3751// Define next ops for AC97 compatible
3752//
3753
3754#define AC97_ACSR AIC_ACSR
3755
3756#define __ac97_enable() __aic_enable(); __aic_select_ac97()
3757#define __ac97_disable() __aic_disable()
3758#define __ac97_reset() __aic_reset()
3759
3760#define __ac97_set_transmit_trigger(n) __aic_set_transmit_trigger(n)
3761#define __ac97_set_receive_trigger(n) __aic_set_receive_trigger(n)
3762
3763#define __ac97_enable_record() __aic_enable_record()
3764#define __ac97_disable_record() __aic_disable_record()
3765#define __ac97_enable_replay() __aic_enable_replay()
3766#define __ac97_disable_replay() __aic_disable_replay()
3767#define __ac97_enable_loopback() __aic_enable_loopback()
3768#define __ac97_disable_loopback() __aic_disable_loopback()
3769
3770#define __ac97_enable_transmit_dma() __aic_enable_transmit_dma()
3771#define __ac97_disable_transmit_dma() __aic_disable_transmit_dma()
3772#define __ac97_enable_receive_dma() __aic_enable_receive_dma()
3773#define __ac97_disable_receive_dma() __aic_disable_receive_dma()
3774
3775#define __ac97_transmit_request() __aic_transmit_request()
3776#define __ac97_receive_request() __aic_receive_request()
3777#define __ac97_transmit_underrun() __aic_transmit_underrun()
3778#define __ac97_receive_overrun() __aic_receive_overrun()
3779
3780#define __ac97_clear_errors() __aic_clear_errors()
3781
3782#define __ac97_get_transmit_resident() __aic_get_transmit_resident()
3783#define __ac97_get_receive_count() __aic_get_receive_count()
3784
3785#define __ac97_enable_transmit_intr() __aic_enable_transmit_intr()
3786#define __ac97_disable_transmit_intr() __aic_disable_transmit_intr()
3787#define __ac97_enable_receive_intr() __aic_enable_receive_intr()
3788#define __ac97_disable_receive_intr() __aic_disable_receive_intr()
3789
3790#define __ac97_write_tfifo(v) __aic_write_tfifo(v)
3791#define __ac97_read_rfifo() __aic_read_rfifo()
3792
3793//
3794// Define next ops for I2S compatible
3795//
3796
3797#define I2S_ACSR AIC_I2SSR
3798
3799#define __i2s_enable() __aic_enable(); __aic_select_i2s()
3800#define __i2s_disable() __aic_disable()
3801#define __i2s_reset() __aic_reset()
3802
3803#define __i2s_set_transmit_trigger(n) __aic_set_transmit_trigger(n)
3804#define __i2s_set_receive_trigger(n) __aic_set_receive_trigger(n)
3805
3806#define __i2s_enable_record() __aic_enable_record()
3807#define __i2s_disable_record() __aic_disable_record()
3808#define __i2s_enable_replay() __aic_enable_replay()
3809#define __i2s_disable_replay() __aic_disable_replay()
3810#define __i2s_enable_loopback() __aic_enable_loopback()
3811#define __i2s_disable_loopback() __aic_disable_loopback()
3812
3813#define __i2s_enable_transmit_dma() __aic_enable_transmit_dma()
3814#define __i2s_disable_transmit_dma() __aic_disable_transmit_dma()
3815#define __i2s_enable_receive_dma() __aic_enable_receive_dma()
3816#define __i2s_disable_receive_dma() __aic_disable_receive_dma()
3817
3818#define __i2s_transmit_request() __aic_transmit_request()
3819#define __i2s_receive_request() __aic_receive_request()
3820#define __i2s_transmit_underrun() __aic_transmit_underrun()
3821#define __i2s_receive_overrun() __aic_receive_overrun()
3822
3823#define __i2s_clear_errors() __aic_clear_errors()
3824
3825#define __i2s_get_transmit_resident() __aic_get_transmit_resident()
3826#define __i2s_get_receive_count() __aic_get_receive_count()
3827
3828#define __i2s_enable_transmit_intr() __aic_enable_transmit_intr()
3829#define __i2s_disable_transmit_intr() __aic_disable_transmit_intr()
3830#define __i2s_enable_receive_intr() __aic_enable_receive_intr()
3831#define __i2s_disable_receive_intr() __aic_disable_receive_intr()
3832
3833#define __i2s_write_tfifo(v) __aic_write_tfifo(v)
3834#define __i2s_read_rfifo() __aic_read_rfifo()
3835
3836#define __i2s_reset_codec() \
3837 do { \
3838 } while (0)
3839
3840
3841/***************************************************************************
3842 * ICDC
3843 ***************************************************************************/
3844#define __i2s_internal_codec() __aic_internal_codec()
3845#define __i2s_external_codec() __aic_external_codec()
3846
3847/***************************************************************************
3848 * INTC
3849 ***************************************************************************/
3850#define __intc_unmask_irq(n) ( REG_INTC_IMCR = (1 << (n)) )
3851#define __intc_mask_irq(n) ( REG_INTC_IMSR = (1 << (n)) )
3852#define __intc_ack_irq(n) ( REG_INTC_IPR = (1 << (n)) )
3853
3854
3855/***************************************************************************
3856 * I2C
3857 ***************************************************************************/
3858
3859#define __i2c_enable() ( REG_I2C_CR |= I2C_CR_I2CE )
3860#define __i2c_disable() ( REG_I2C_CR &= ~I2C_CR_I2CE )
3861
3862#define __i2c_send_start() ( REG_I2C_CR |= I2C_CR_STA )
3863#define __i2c_send_stop() ( REG_I2C_CR |= I2C_CR_STO )
3864#define __i2c_send_ack() ( REG_I2C_CR &= ~I2C_CR_AC )
3865#define __i2c_send_nack() ( REG_I2C_CR |= I2C_CR_AC )
3866
3867#define __i2c_set_drf() ( REG_I2C_SR |= I2C_SR_DRF )
3868#define __i2c_clear_drf() ( REG_I2C_SR &= ~I2C_SR_DRF )
3869#define __i2c_check_drf() ( REG_I2C_SR & I2C_SR_DRF )
3870
3871#define __i2c_received_ack() ( !(REG_I2C_SR & I2C_SR_ACKF) )
3872#define __i2c_is_busy() ( REG_I2C_SR & I2C_SR_BUSY )
3873#define __i2c_transmit_ended() ( REG_I2C_SR & I2C_SR_TEND )
3874
3875#define __i2c_set_clk(dev_clk, i2c_clk) \
3876  ( REG_I2C_GR = (dev_clk) / (16*(i2c_clk)) - 1 )
3877
3878#define __i2c_read() ( REG_I2C_DR )
3879#define __i2c_write(val) ( REG_I2C_DR = (val) )
3880
3881
3882/***************************************************************************
3883 * MSC
3884 ***************************************************************************/
3885
3886#define __msc_start_op() \
3887  ( REG_MSC_STRPCL = MSC_STRPCL_START_OP | MSC_STRPCL_CLOCK_CONTROL_START )
3888
3889#define __msc_set_resto(to) ( REG_MSC_RESTO = to )
3890#define __msc_set_rdto(to) ( REG_MSC_RDTO = to )
3891#define __msc_set_cmd(cmd) ( REG_MSC_CMD = cmd )
3892#define __msc_set_arg(arg) ( REG_MSC_ARG = arg )
3893#define __msc_set_nob(nob) ( REG_MSC_NOB = nob )
3894#define __msc_get_nob() ( REG_MSC_NOB )
3895#define __msc_set_blklen(len) ( REG_MSC_BLKLEN = len )
3896#define __msc_set_cmdat(cmdat) ( REG_MSC_CMDAT = cmdat )
3897#define __msc_set_cmdat_ioabort() ( REG_MSC_CMDAT |= MSC_CMDAT_IO_ABORT )
3898#define __msc_clear_cmdat_ioabort() ( REG_MSC_CMDAT &= ~MSC_CMDAT_IO_ABORT )
3899
3900#define __msc_set_cmdat_bus_width1() \
3901do { \
3902    REG_MSC_CMDAT &= ~MSC_CMDAT_BUS_WIDTH_MASK; \
3903    REG_MSC_CMDAT |= MSC_CMDAT_BUS_WIDTH_1BIT; \
3904} while(0)
3905
3906#define __msc_set_cmdat_bus_width4() \
3907do { \
3908    REG_MSC_CMDAT &= ~MSC_CMDAT_BUS_WIDTH_MASK; \
3909    REG_MSC_CMDAT |= MSC_CMDAT_BUS_WIDTH_4BIT; \
3910} while(0)
3911
3912#define __msc_set_cmdat_dma_en() ( REG_MSC_CMDAT |= MSC_CMDAT_DMA_EN )
3913#define __msc_set_cmdat_init() ( REG_MSC_CMDAT |= MSC_CMDAT_INIT )
3914#define __msc_set_cmdat_busy() ( REG_MSC_CMDAT |= MSC_CMDAT_BUSY )
3915#define __msc_set_cmdat_stream() ( REG_MSC_CMDAT |= MSC_CMDAT_STREAM_BLOCK )
3916#define __msc_set_cmdat_block() ( REG_MSC_CMDAT &= ~MSC_CMDAT_STREAM_BLOCK )
3917#define __msc_set_cmdat_read() ( REG_MSC_CMDAT &= ~MSC_CMDAT_WRITE_READ )
3918#define __msc_set_cmdat_write() ( REG_MSC_CMDAT |= MSC_CMDAT_WRITE_READ )
3919#define __msc_set_cmdat_data_en() ( REG_MSC_CMDAT |= MSC_CMDAT_DATA_EN )
3920
3921/* r is MSC_CMDAT_RESPONSE_FORMAT_Rx or MSC_CMDAT_RESPONSE_FORMAT_NONE */
3922#define __msc_set_cmdat_res_format(r) \
3923do { \
3924    REG_MSC_CMDAT &= ~MSC_CMDAT_RESPONSE_FORMAT_MASK; \
3925    REG_MSC_CMDAT |= (r); \
3926} while(0)
3927
3928#define __msc_clear_cmdat() \
3929  REG_MSC_CMDAT &= ~( MSC_CMDAT_IO_ABORT | MSC_CMDAT_DMA_EN | MSC_CMDAT_INIT| \
3930  MSC_CMDAT_BUSY | MSC_CMDAT_STREAM_BLOCK | MSC_CMDAT_WRITE_READ | \
3931  MSC_CMDAT_DATA_EN | MSC_CMDAT_RESPONSE_FORMAT_MASK )
3932
3933#define __msc_get_imask() ( REG_MSC_IMASK )
3934#define __msc_mask_all_intrs() ( REG_MSC_IMASK = 0xff )
3935#define __msc_unmask_all_intrs() ( REG_MSC_IMASK = 0x00 )
3936#define __msc_mask_rd() ( REG_MSC_IMASK |= MSC_IMASK_RXFIFO_RD_REQ )
3937#define __msc_unmask_rd() ( REG_MSC_IMASK &= ~MSC_IMASK_RXFIFO_RD_REQ )
3938#define __msc_mask_wr() ( REG_MSC_IMASK |= MSC_IMASK_TXFIFO_WR_REQ )
3939#define __msc_unmask_wr() ( REG_MSC_IMASK &= ~MSC_IMASK_TXFIFO_WR_REQ )
3940#define __msc_mask_endcmdres() ( REG_MSC_IMASK |= MSC_IMASK_END_CMD_RES )
3941#define __msc_unmask_endcmdres() ( REG_MSC_IMASK &= ~MSC_IMASK_END_CMD_RES )
3942#define __msc_mask_datatrandone() ( REG_MSC_IMASK |= MSC_IMASK_DATA_TRAN_DONE )
3943#define __msc_unmask_datatrandone() ( REG_MSC_IMASK &= ~MSC_IMASK_DATA_TRAN_DONE )
3944#define __msc_mask_prgdone() ( REG_MSC_IMASK |= MSC_IMASK_PRG_DONE )
3945#define __msc_unmask_prgdone() ( REG_MSC_IMASK &= ~MSC_IMASK_PRG_DONE )
3946
3947/* n=0,1,2,3,4,5,6,7 */
3948#define __msc_set_clkrt(n) \
3949do { \
3950    REG_MSC_CLKRT = n; \
3951} while(0)
3952
3953#define __msc_get_ireg() ( REG_MSC_IREG )
3954#define __msc_ireg_rd() ( REG_MSC_IREG & MSC_IREG_RXFIFO_RD_REQ )
3955#define __msc_ireg_wr() ( REG_MSC_IREG & MSC_IREG_TXFIFO_WR_REQ )
3956#define __msc_ireg_end_cmd_res() ( REG_MSC_IREG & MSC_IREG_END_CMD_RES )
3957#define __msc_ireg_data_tran_done() ( REG_MSC_IREG & MSC_IREG_DATA_TRAN_DONE )
3958#define __msc_ireg_prg_done() ( REG_MSC_IREG & MSC_IREG_PRG_DONE )
3959#define __msc_ireg_clear_end_cmd_res() ( REG_MSC_IREG = MSC_IREG_END_CMD_RES )
3960#define __msc_ireg_clear_data_tran_done() ( REG_MSC_IREG = MSC_IREG_DATA_TRAN_DONE )
3961#define __msc_ireg_clear_prg_done() ( REG_MSC_IREG = MSC_IREG_PRG_DONE )
3962
3963#define __msc_get_stat() ( REG_MSC_STAT )
3964#define __msc_stat_not_end_cmd_res() ( (REG_MSC_STAT & MSC_STAT_END_CMD_RES) == 0)
3965#define __msc_stat_crc_err() \
3966  ( REG_MSC_STAT & (MSC_STAT_CRC_RES_ERR | MSC_STAT_CRC_READ_ERROR | MSC_STAT_CRC_WRITE_ERROR_YES) )
3967#define __msc_stat_res_crc_err() ( REG_MSC_STAT & MSC_STAT_CRC_RES_ERR )
3968#define __msc_stat_rd_crc_err() ( REG_MSC_STAT & MSC_STAT_CRC_READ_ERROR )
3969#define __msc_stat_wr_crc_err() ( REG_MSC_STAT & MSC_STAT_CRC_WRITE_ERROR_YES )
3970#define __msc_stat_resto_err() ( REG_MSC_STAT & MSC_STAT_TIME_OUT_RES )
3971#define __msc_stat_rdto_err() ( REG_MSC_STAT & MSC_STAT_TIME_OUT_READ )
3972
3973#define __msc_rd_resfifo() ( REG_MSC_RES )
3974#define __msc_rd_rxfifo() ( REG_MSC_RXFIFO )
3975#define __msc_wr_txfifo(v) ( REG_MSC_TXFIFO = v )
3976
3977#define __msc_reset() \
3978do { \
3979    REG_MSC_STRPCL = MSC_STRPCL_RESET; \
3980     while (REG_MSC_STAT & MSC_STAT_IS_RESETTING); \
3981} while (0)
3982
3983#define __msc_start_clk() \
3984do { \
3985    REG_MSC_STRPCL = MSC_STRPCL_CLOCK_CONTROL_START; \
3986} while (0)
3987
3988#define __msc_stop_clk() \
3989do { \
3990    REG_MSC_STRPCL = MSC_STRPCL_CLOCK_CONTROL_STOP; \
3991} while (0)
3992
3993#define MMC_CLK 19169200
3994#define SD_CLK 24576000
3995
3996/* msc_clk should little than pclk and little than clk retrieve from card */
3997#define __msc_calc_clk_divisor(type,dev_clk,msc_clk,lv) \
3998do { \
3999    unsigned int rate, pclk, i; \
4000    pclk = dev_clk; \
4001    rate = type?SD_CLK:MMC_CLK; \
4002      if (msc_clk && msc_clk < pclk) \
4003            pclk = msc_clk; \
4004    i = 0; \
4005      while (pclk < rate) \
4006        { \
4007              i ++; \
4008              rate >>= 1; \
4009        } \
4010      lv = i; \
4011} while(0)
4012
4013/* divide rate to little than or equal to 400kHz */
4014#define __msc_calc_slow_clk_divisor(type, lv) \
4015do { \
4016    unsigned int rate, i; \
4017    rate = (type?SD_CLK:MMC_CLK)/1000/400; \
4018    i = 0; \
4019    while (rate > 0) \
4020        { \
4021              rate >>= 1; \
4022              i ++; \
4023        } \
4024      lv = i; \
4025} while(0)
4026
4027
4028/***************************************************************************
4029 * SSI
4030 ***************************************************************************/
4031
4032#define __ssi_enable() ( REG_SSI_CR0 |= SSI_CR0_SSIE )
4033#define __ssi_disable() ( REG_SSI_CR0 &= ~SSI_CR0_SSIE )
4034#define __ssi_select_ce() ( REG_SSI_CR0 &= ~SSI_CR0_FSEL )
4035
4036#define __ssi_normal_mode() ( REG_SSI_ITR &= ~SSI_ITR_IVLTM_MASK )
4037
4038#define __ssi_select_ce2() \
4039do { \
4040    REG_SSI_CR0 |= SSI_CR0_FSEL; \
4041    REG_SSI_CR1 &= ~SSI_CR1_MULTS; \
4042} while (0)
4043
4044#define __ssi_select_gpc() \
4045do { \
4046    REG_SSI_CR0 &= ~SSI_CR0_FSEL; \
4047    REG_SSI_CR1 |= SSI_CR1_MULTS; \
4048} while (0)
4049
4050#define __ssi_enable_tx_intr() \
4051  ( REG_SSI_CR0 |= SSI_CR0_TIE | SSI_CR0_TEIE )
4052
4053#define __ssi_disable_tx_intr() \
4054  ( REG_SSI_CR0 &= ~(SSI_CR0_TIE | SSI_CR0_TEIE) )
4055
4056#define __ssi_enable_rx_intr() \
4057  ( REG_SSI_CR0 |= SSI_CR0_RIE | SSI_CR0_REIE )
4058
4059#define __ssi_disable_rx_intr() \
4060  ( REG_SSI_CR0 &= ~(SSI_CR0_RIE | SSI_CR0_REIE) )
4061
4062#define __ssi_enable_loopback() ( REG_SSI_CR0 |= SSI_CR0_LOOP )
4063#define __ssi_disable_loopback() ( REG_SSI_CR0 &= ~SSI_CR0_LOOP )
4064
4065#define __ssi_enable_receive() ( REG_SSI_CR0 &= ~SSI_CR0_DISREV )
4066#define __ssi_disable_receive() ( REG_SSI_CR0 |= SSI_CR0_DISREV )
4067
4068#define __ssi_finish_receive() \
4069  ( REG_SSI_CR0 |= (SSI_CR0_RFINE | SSI_CR0_RFINC) )
4070
4071#define __ssi_disable_recvfinish() \
4072  ( REG_SSI_CR0 &= ~(SSI_CR0_RFINE | SSI_CR0_RFINC) )
4073
4074#define __ssi_flush_txfifo() ( REG_SSI_CR0 |= SSI_CR0_TFLUSH )
4075#define __ssi_flush_rxfifo() ( REG_SSI_CR0 |= SSI_CR0_RFLUSH )
4076
4077#define __ssi_flush_fifo() \
4078  ( REG_SSI_CR0 |= SSI_CR0_TFLUSH | SSI_CR0_RFLUSH )
4079
4080#define __ssi_finish_transmit() ( REG_SSI_CR1 &= ~SSI_CR1_UNFIN )
4081
4082#define __ssi_spi_format() \
4083do { \
4084    REG_SSI_CR1 &= ~SSI_CR1_FMAT_MASK; \
4085    REG_SSI_CR1 |= SSI_CR1_FMAT_SPI; \
4086    REG_SSI_CR1 &= ~(SSI_CR1_TFVCK_MASK|SSI_CR1_TCKFI_MASK);\
4087    REG_SSI_CR1 |= (SSI_CR1_TFVCK_1 | SSI_CR1_TCKFI_1); \
4088} while (0)
4089
4090/* TI's SSP format, must clear SSI_CR1.UNFIN */
4091#define __ssi_ssp_format() \
4092do { \
4093    REG_SSI_CR1 &= ~(SSI_CR1_FMAT_MASK | SSI_CR1_UNFIN); \
4094    REG_SSI_CR1 |= SSI_CR1_FMAT_SSP; \
4095} while (0)
4096
4097/* National's Microwire format, must clear SSI_CR0.RFINE, and set max delay */
4098#define __ssi_microwire_format() \
4099do { \
4100    REG_SSI_CR1 &= ~SSI_CR1_FMAT_MASK; \
4101    REG_SSI_CR1 |= SSI_CR1_FMAT_MW1; \
4102    REG_SSI_CR1 &= ~(SSI_CR1_TFVCK_MASK|SSI_CR1_TCKFI_MASK);\
4103    REG_SSI_CR1 |= (SSI_CR1_TFVCK_3 | SSI_CR1_TCKFI_3); \
4104    REG_SSI_CR0 &= ~SSI_CR0_RFINE; \
4105} while (0)
4106
4107/* CE# level (FRMHL), CE# in interval time (ITFRM),
4108   clock phase and polarity (PHA POL),
4109   interval time (SSIITR), interval characters/frame (SSIICR) */
4110
4111 /* frmhl,endian,mcom,flen,pha,pol MASK */
4112#define SSICR1_MISC_MASK \
4113    ( SSI_CR1_FRMHL_MASK | SSI_CR1_LFST | SSI_CR1_MCOM_MASK \
4114    | SSI_CR1_FLEN_MASK | SSI_CR1_PHA | SSI_CR1_POL ) \
4115
4116#define __ssi_spi_set_misc(frmhl,endian,flen,mcom,pha,pol) \
4117do { \
4118    REG_SSI_CR1 &= ~SSICR1_MISC_MASK; \
4119    REG_SSI_CR1 |= ((frmhl) << 30) | ((endian) << 25) | \
4120         (((mcom) - 1) << 12) | (((flen) - 2) << 4) | \
4121             ((pha) << 1) | (pol); \
4122} while(0)
4123
4124/* Transfer with MSB or LSB first */
4125#define __ssi_set_msb() ( REG_SSI_CR1 &= ~SSI_CR1_LFST )
4126#define __ssi_set_lsb() ( REG_SSI_CR1 |= SSI_CR1_LFST )
4127
4128#define __ssi_set_frame_length(n) \
4129    REG_SSI_CR1 = (REG_SSI_CR1 & ~SSI_CR1_FLEN_MASK) | (((n) - 2) << 4)
4130
4131/* n = 1 - 16 */
4132#define __ssi_set_microwire_command_length(n) \
4133    ( REG_SSI_CR1 = ((REG_SSI_CR1 & ~SSI_CR1_MCOM_MASK) | SSI_CR1_MCOM_##n##BIT) )
4134
4135/* Set the clock phase for SPI */
4136#define __ssi_set_spi_clock_phase(n) \
4137    ( REG_SSI_CR1 = ((REG_SSI_CR1 & ~SSI_CR1_PHA) | (n&0x1)) )
4138
4139/* Set the clock polarity for SPI */
4140#define __ssi_set_spi_clock_polarity(n) \
4141    ( REG_SSI_CR1 = ((REG_SSI_CR1 & ~SSI_CR1_POL) | (n&0x1)) )
4142
4143/* n = 1,4,8,14 */
4144#define __ssi_set_tx_trigger(n) \
4145do { \
4146    REG_SSI_CR1 &= ~SSI_CR1_TTRG_MASK; \
4147    REG_SSI_CR1 |= SSI_CR1_TTRG_##n; \
4148} while (0)
4149
4150/* n = 1,4,8,14 */
4151#define __ssi_set_rx_trigger(n) \
4152do { \
4153    REG_SSI_CR1 &= ~SSI_CR1_RTRG_MASK; \
4154    REG_SSI_CR1 |= SSI_CR1_RTRG_##n; \
4155} while (0)
4156
4157#define __ssi_get_txfifo_count() \
4158    ( (REG_SSI_SR & SSI_SR_TFIFONUM_MASK) >> SSI_SR_TFIFONUM_BIT )
4159
4160#define __ssi_get_rxfifo_count() \
4161    ( (REG_SSI_SR & SSI_SR_RFIFONUM_MASK) >> SSI_SR_RFIFONUM_BIT )
4162
4163#define __ssi_clear_errors() \
4164    ( REG_SSI_SR &= ~(SSI_SR_UNDR | SSI_SR_OVER) )
4165
4166#define __ssi_transfer_end() ( REG_SSI_SR & SSI_SR_END )
4167#define __ssi_is_busy() ( REG_SSI_SR & SSI_SR_BUSY )
4168
4169#define __ssi_txfifo_full() ( REG_SSI_SR & SSI_SR_TFF )
4170#define __ssi_rxfifo_empty() ( REG_SSI_SR & SSI_SR_RFE )
4171#define __ssi_rxfifo_noempty() ( REG_SSI_SR & SSI_SR_RFHF )
4172
4173#define __ssi_set_clk(dev_clk, ssi_clk) \
4174  ( REG_SSI_GR = (dev_clk) / (2*(ssi_clk)) - 1 )
4175
4176#define __ssi_receive_data() REG_SSI_DR
4177#define __ssi_transmit_data(v) ( REG_SSI_DR = (v) )
4178
4179
4180/***************************************************************************
4181 * CIM
4182 ***************************************************************************/
4183
4184#define __cim_enable() ( REG_CIM_CTRL |= CIM_CTRL_ENA )
4185#define __cim_disable() ( REG_CIM_CTRL &= ~CIM_CTRL_ENA )
4186
4187#define __cim_input_data_inverse() ( REG_CIM_CFG |= CIM_CFG_INV_DAT )
4188#define __cim_input_data_normal() ( REG_CIM_CFG &= ~CIM_CFG_INV_DAT )
4189
4190#define __cim_vsync_active_low() ( REG_CIM_CFG |= CIM_CFG_VSP )
4191#define __cim_vsync_active_high() ( REG_CIM_CFG &= ~CIM_CFG_VSP )
4192
4193#define __cim_hsync_active_low() ( REG_CIM_CFG |= CIM_CFG_HSP )
4194#define __cim_hsync_active_high() ( REG_CIM_CFG &= ~CIM_CFG_HSP )
4195
4196#define __cim_sample_data_at_pclk_falling_edge() \
4197  ( REG_CIM_CFG |= CIM_CFG_PCP )
4198#define __cim_sample_data_at_pclk_rising_edge() \
4199  ( REG_CIM_CFG &= ~CIM_CFG_PCP )
4200
4201#define __cim_enable_dummy_zero() ( REG_CIM_CFG |= CIM_CFG_DUMMY_ZERO )
4202#define __cim_disable_dummy_zero() ( REG_CIM_CFG &= ~CIM_CFG_DUMMY_ZERO )
4203
4204#define __cim_select_external_vsync() ( REG_CIM_CFG |= CIM_CFG_EXT_VSYNC )
4205#define __cim_select_internal_vsync() ( REG_CIM_CFG &= ~CIM_CFG_EXT_VSYNC )
4206
4207/* n=0-7 */
4208#define __cim_set_data_packing_mode(n) \
4209do { \
4210    REG_CIM_CFG &= ~CIM_CFG_PACK_MASK; \
4211    REG_CIM_CFG |= (CIM_CFG_PACK_##n); \
4212} while (0)
4213
4214#define __cim_enable_ccir656_progressive_mode() \
4215do { \
4216    REG_CIM_CFG &= ~CIM_CFG_DSM_MASK; \
4217    REG_CIM_CFG |= CIM_CFG_DSM_CPM; \
4218} while (0)
4219
4220#define __cim_enable_ccir656_interlace_mode() \
4221do { \
4222    REG_CIM_CFG &= ~CIM_CFG_DSM_MASK; \
4223    REG_CIM_CFG |= CIM_CFG_DSM_CIM; \
4224} while (0)
4225
4226#define __cim_enable_gated_clock_mode() \
4227do { \
4228    REG_CIM_CFG &= ~CIM_CFG_DSM_MASK; \
4229    REG_CIM_CFG |= CIM_CFG_DSM_GCM; \
4230} while (0)
4231
4232#define __cim_enable_nongated_clock_mode() \
4233do { \
4234    REG_CIM_CFG &= ~CIM_CFG_DSM_MASK; \
4235    REG_CIM_CFG |= CIM_CFG_DSM_NGCM; \
4236} while (0)
4237
4238/* sclk:system bus clock
4239 * mclk: CIM master clock
4240 */
4241#define __cim_set_master_clk(sclk, mclk) \
4242do { \
4243    REG_CIM_CTRL &= ~CIM_CTRL_MCLKDIV_MASK; \
4244    REG_CIM_CTRL |= (((sclk)/(mclk) - 1) << CIM_CTRL_MCLKDIV_BIT); \
4245} while (0)
4246
4247#define __cim_enable_sof_intr() \
4248  ( REG_CIM_CTRL |= CIM_CTRL_DMA_SOFM )
4249#define __cim_disable_sof_intr() \
4250  ( REG_CIM_CTRL &= ~CIM_CTRL_DMA_SOFM )
4251
4252#define __cim_enable_eof_intr() \
4253  ( REG_CIM_CTRL |= CIM_CTRL_DMA_EOFM )
4254#define __cim_disable_eof_intr() \
4255  ( REG_CIM_CTRL &= ~CIM_CTRL_DMA_EOFM )
4256
4257#define __cim_enable_stop_intr() \
4258  ( REG_CIM_CTRL |= CIM_CTRL_DMA_STOPM )
4259#define __cim_disable_stop_intr() \
4260  ( REG_CIM_CTRL &= ~CIM_CTRL_DMA_STOPM )
4261
4262#define __cim_enable_trig_intr() \
4263  ( REG_CIM_CTRL |= CIM_CTRL_RXF_TRIGM )
4264#define __cim_disable_trig_intr() \
4265  ( REG_CIM_CTRL &= ~CIM_CTRL_RXF_TRIGM )
4266
4267#define __cim_enable_rxfifo_overflow_intr() \
4268  ( REG_CIM_CTRL |= CIM_CTRL_RXF_OFM )
4269#define __cim_disable_rxfifo_overflow_intr() \
4270  ( REG_CIM_CTRL &= ~CIM_CTRL_RXF_OFM )
4271
4272/* n=1-16 */
4273#define __cim_set_frame_rate(n) \
4274do { \
4275    REG_CIM_CTRL &= ~CIM_CTRL_FRC_MASK; \
4276    REG_CIM_CTRL |= CIM_CTRL_FRC_##n; \
4277} while (0)
4278
4279#define __cim_enable_dma() ( REG_CIM_CTRL |= CIM_CTRL_DMA_EN )
4280#define __cim_disable_dma() ( REG_CIM_CTRL &= ~CIM_CTRL_DMA_EN )
4281
4282#define __cim_reset_rxfifo() ( REG_CIM_CTRL |= CIM_CTRL_RXF_RST )
4283#define __cim_unreset_rxfifo() ( REG_CIM_CTRL &= ~CIM_CTRL_RXF_RST )
4284
4285/* n=4,8,12,16,20,24,28,32 */
4286#define __cim_set_rxfifo_trigger(n) \
4287do { \
4288    REG_CIM_CTRL &= ~CIM_CTRL_RXF_TRIG_MASK; \
4289    REG_CIM_CTRL |= CIM_CTRL_RXF_TRIG_##n; \
4290} while (0)
4291
4292#define __cim_clear_state() ( REG_CIM_STATE = 0 )
4293
4294#define __cim_disable_done() ( REG_CIM_STATE & CIM_STATE_VDD )
4295#define __cim_rxfifo_empty() ( REG_CIM_STATE & CIM_STATE_RXF_EMPTY )
4296#define __cim_rxfifo_reach_trigger() ( REG_CIM_STATE & CIM_STATE_RXF_TRIG )
4297#define __cim_rxfifo_overflow() ( REG_CIM_STATE & CIM_STATE_RXF_OF )
4298#define __cim_clear_rxfifo_overflow() ( REG_CIM_STATE &= ~CIM_STATE_RXF_OF )
4299#define __cim_dma_stop() ( REG_CIM_STATE & CIM_STATE_DMA_STOP )
4300#define __cim_dma_eof() ( REG_CIM_STATE & CIM_STATE_DMA_EOF )
4301#define __cim_dma_sof() ( REG_CIM_STATE & CIM_STATE_DMA_SOF )
4302
4303#define __cim_get_iid() ( REG_CIM_IID )
4304#define __cim_get_image_data() ( REG_CIM_RXFIFO )
4305#define __cim_get_dam_cmd() ( REG_CIM_CMD )
4306
4307#define __cim_set_da(a) ( REG_CIM_DA = (a) )
4308
4309/***************************************************************************
4310 * LCD
4311 ***************************************************************************/
4312#define __lcd_as_smart_lcd() ( REG_LCD_CFG |= (1<<LCD_CFG_LCDPIN_BIT) )
4313#define __lcd_as_general_lcd() ( REG_LCD_CFG &= ~(1<<LCD_CFG_LCDPIN_BIT) )
4314
4315#define __lcd_set_dis() ( REG_LCD_CTRL |= LCD_CTRL_DIS )
4316#define __lcd_clr_dis() ( REG_LCD_CTRL &= ~LCD_CTRL_DIS )
4317
4318#define __lcd_set_ena() ( REG_LCD_CTRL |= LCD_CTRL_ENA )
4319#define __lcd_clr_ena() ( REG_LCD_CTRL &= ~LCD_CTRL_ENA )
4320
4321/* n=1,2,4,8,16 */
4322#define __lcd_set_bpp(n) \
4323  ( REG_LCD_CTRL = (REG_LCD_CTRL & ~LCD_CTRL_BPP_MASK) | LCD_CTRL_BPP_##n )
4324
4325/* n=4,8,16 */
4326#define __lcd_set_burst_length(n) \
4327do { \
4328    REG_LCD_CTRL &= ~LCD_CTRL_BST_MASK; \
4329    REG_LCD_CTRL |= LCD_CTRL_BST_n##; \
4330} while (0)
4331
4332#define __lcd_select_rgb565() ( REG_LCD_CTRL &= ~LCD_CTRL_RGB555 )
4333#define __lcd_select_rgb555() ( REG_LCD_CTRL |= LCD_CTRL_RGB555 )
4334
4335#define __lcd_set_ofup() ( REG_LCD_CTRL |= LCD_CTRL_OFUP )
4336#define __lcd_clr_ofup() ( REG_LCD_CTRL &= ~LCD_CTRL_OFUP )
4337
4338/* n=2,4,16 */
4339#define __lcd_set_stn_frc(n) \
4340do { \
4341    REG_LCD_CTRL &= ~LCD_CTRL_FRC_MASK; \
4342    REG_LCD_CTRL |= LCD_CTRL_FRC_n##; \
4343} while (0)
4344
4345
4346#define __lcd_pixel_endian_little() ( REG_LCD_CTRL |= LCD_CTRL_PEDN )
4347#define __lcd_pixel_endian_big() ( REG_LCD_CTRL &= ~LCD_CTRL_PEDN )
4348
4349#define __lcd_reverse_byte_endian() ( REG_LCD_CTRL |= LCD_CTRL_BEDN )
4350#define __lcd_normal_byte_endian() ( REG_LCD_CTRL &= ~LCD_CTRL_BEDN )
4351
4352#define __lcd_enable_eof_intr() ( REG_LCD_CTRL |= LCD_CTRL_EOFM )
4353#define __lcd_disable_eof_intr() ( REG_LCD_CTRL &= ~LCD_CTRL_EOFM )
4354
4355#define __lcd_enable_sof_intr() ( REG_LCD_CTRL |= LCD_CTRL_SOFM )
4356#define __lcd_disable_sof_intr() ( REG_LCD_CTRL &= ~LCD_CTRL_SOFM )
4357
4358#define __lcd_enable_ofu_intr() ( REG_LCD_CTRL |= LCD_CTRL_OFUM )
4359#define __lcd_disable_ofu_intr() ( REG_LCD_CTRL &= ~LCD_CTRL_OFUM )
4360
4361#define __lcd_enable_ifu0_intr() ( REG_LCD_CTRL |= LCD_CTRL_IFUM0 )
4362#define __lcd_disable_ifu0_intr() ( REG_LCD_CTRL &= ~LCD_CTRL_IFUM0 )
4363
4364#define __lcd_enable_ifu1_intr() ( REG_LCD_CTRL |= LCD_CTRL_IFUM1 )
4365#define __lcd_disable_ifu1_intr() ( REG_LCD_CTRL &= ~LCD_CTRL_IFUM1 )
4366
4367#define __lcd_enable_ldd_intr() ( REG_LCD_CTRL |= LCD_CTRL_LDDM )
4368#define __lcd_disable_ldd_intr() ( REG_LCD_CTRL &= ~LCD_CTRL_LDDM )
4369
4370#define __lcd_enable_qd_intr() ( REG_LCD_CTRL |= LCD_CTRL_QDM )
4371#define __lcd_disable_qd_intr() ( REG_LCD_CTRL &= ~LCD_CTRL_QDM )
4372
4373
4374/* LCD status register indication */
4375
4376#define __lcd_quick_disable_done() ( REG_LCD_STATE & LCD_STATE_QD )
4377#define __lcd_disable_done() ( REG_LCD_STATE & LCD_STATE_LDD )
4378#define __lcd_infifo0_underrun() ( REG_LCD_STATE & LCD_STATE_IFU0 )
4379#define __lcd_infifo1_underrun() ( REG_LCD_STATE & LCD_STATE_IFU1 )
4380#define __lcd_outfifo_underrun() ( REG_LCD_STATE & LCD_STATE_OFU )
4381#define __lcd_start_of_frame() ( REG_LCD_STATE & LCD_STATE_SOF )
4382#define __lcd_end_of_frame() ( REG_LCD_STATE & LCD_STATE_EOF )
4383
4384#define __lcd_clr_outfifounderrun() ( REG_LCD_STATE &= ~LCD_STATE_OFU )
4385#define __lcd_clr_sof() ( REG_LCD_STATE &= ~LCD_STATE_SOF )
4386#define __lcd_clr_eof() ( REG_LCD_STATE &= ~LCD_STATE_EOF )
4387
4388#define __lcd_panel_white() ( REG_LCD_CFG |= LCD_CFG_WHITE )
4389#define __lcd_panel_black() ( REG_LCD_CFG &= ~LCD_CFG_WHITE )
4390
4391/* n=1,2,4,8 for single mono-STN
4392 * n=4,8 for dual mono-STN
4393 */
4394#define __lcd_set_panel_datawidth(n) \
4395do { \
4396    REG_LCD_CFG &= ~LCD_CFG_PDW_MASK; \
4397    REG_LCD_CFG |= LCD_CFG_PDW_n##; \
4398} while (0)
4399
4400/* m=LCD_CFG_MODE_GENERUIC_TFT_xxx */
4401#define __lcd_set_panel_mode(m) \
4402do { \
4403    REG_LCD_CFG &= ~LCD_CFG_MODE_MASK; \
4404    REG_LCD_CFG |= (m); \
4405} while(0)
4406
4407/* n = 0-255 */
4408#define __lcd_disable_ac_bias() ( REG_LCD_IO = 0xff )
4409#define __lcd_set_ac_bias(n) \
4410do { \
4411    REG_LCD_IO &= ~LCD_IO_ACB_MASK; \
4412    REG_LCD_IO |= ((n) << LCD_IO_ACB_BIT); \
4413} while(0)
4414
4415#define __lcd_io_set_dir() ( REG_LCD_IO |= LCD_IO_DIR )
4416#define __lcd_io_clr_dir() ( REG_LCD_IO &= ~LCD_IO_DIR )
4417
4418#define __lcd_io_set_dep() ( REG_LCD_IO |= LCD_IO_DEP )
4419#define __lcd_io_clr_dep() ( REG_LCD_IO &= ~LCD_IO_DEP )
4420
4421#define __lcd_io_set_vsp() ( REG_LCD_IO |= LCD_IO_VSP )
4422#define __lcd_io_clr_vsp() ( REG_LCD_IO &= ~LCD_IO_VSP )
4423
4424#define __lcd_io_set_hsp() ( REG_LCD_IO |= LCD_IO_HSP )
4425#define __lcd_io_clr_hsp() ( REG_LCD_IO &= ~LCD_IO_HSP )
4426
4427#define __lcd_io_set_pcp() ( REG_LCD_IO |= LCD_IO_PCP )
4428#define __lcd_io_clr_pcp() ( REG_LCD_IO &= ~LCD_IO_PCP )
4429
4430#define __lcd_vsync_get_vps() \
4431  ( (REG_LCD_VSYNC & LCD_VSYNC_VPS_MASK) >> LCD_VSYNC_VPS_BIT )
4432
4433#define __lcd_vsync_get_vpe() \
4434  ( (REG_LCD_VSYNC & LCD_VSYNC_VPE_MASK) >> LCD_VSYNC_VPE_BIT )
4435#define __lcd_vsync_set_vpe(n) \
4436do { \
4437    REG_LCD_VSYNC &= ~LCD_VSYNC_VPE_MASK; \
4438    REG_LCD_VSYNC |= (n) << LCD_VSYNC_VPE_BIT; \
4439} while (0)
4440
4441#define __lcd_hsync_get_hps() \
4442  ( (REG_LCD_HSYNC & LCD_HSYNC_HPS_MASK) >> LCD_HSYNC_HPS_BIT )
4443#define __lcd_hsync_set_hps(n) \
4444do { \
4445    REG_LCD_HSYNC &= ~LCD_HSYNC_HPS_MASK; \
4446    REG_LCD_HSYNC |= (n) << LCD_HSYNC_HPS_BIT; \
4447} while (0)
4448
4449#define __lcd_hsync_get_hpe() \
4450  ( (REG_LCD_HSYNC & LCD_HSYNC_HPE_MASK) >> LCD_VSYNC_HPE_BIT )
4451#define __lcd_hsync_set_hpe(n) \
4452do { \
4453    REG_LCD_HSYNC &= ~LCD_HSYNC_HPE_MASK; \
4454    REG_LCD_HSYNC |= (n) << LCD_HSYNC_HPE_BIT; \
4455} while (0)
4456
4457#define __lcd_vat_get_ht() \
4458  ( (REG_LCD_VAT & LCD_VAT_HT_MASK) >> LCD_VAT_HT_BIT )
4459#define __lcd_vat_set_ht(n) \
4460do { \
4461    REG_LCD_VAT &= ~LCD_VAT_HT_MASK; \
4462    REG_LCD_VAT |= (n) << LCD_VAT_HT_BIT; \
4463} while (0)
4464
4465#define __lcd_vat_get_vt() \
4466  ( (REG_LCD_VAT & LCD_VAT_VT_MASK) >> LCD_VAT_VT_BIT )
4467#define __lcd_vat_set_vt(n) \
4468do { \
4469    REG_LCD_VAT &= ~LCD_VAT_VT_MASK; \
4470    REG_LCD_VAT |= (n) << LCD_VAT_VT_BIT; \
4471} while (0)
4472
4473#define __lcd_dah_get_hds() \
4474  ( (REG_LCD_DAH & LCD_DAH_HDS_MASK) >> LCD_DAH_HDS_BIT )
4475#define __lcd_dah_set_hds(n) \
4476do { \
4477    REG_LCD_DAH &= ~LCD_DAH_HDS_MASK; \
4478    REG_LCD_DAH |= (n) << LCD_DAH_HDS_BIT; \
4479} while (0)
4480
4481#define __lcd_dah_get_hde() \
4482  ( (REG_LCD_DAH & LCD_DAH_HDE_MASK) >> LCD_DAH_HDE_BIT )
4483#define __lcd_dah_set_hde(n) \
4484do { \
4485    REG_LCD_DAH &= ~LCD_DAH_HDE_MASK; \
4486    REG_LCD_DAH |= (n) << LCD_DAH_HDE_BIT; \
4487} while (0)
4488
4489#define __lcd_dav_get_vds() \
4490  ( (REG_LCD_DAV & LCD_DAV_VDS_MASK) >> LCD_DAV_VDS_BIT )
4491#define __lcd_dav_set_vds(n) \
4492do { \
4493    REG_LCD_DAV &= ~LCD_DAV_VDS_MASK; \
4494    REG_LCD_DAV |= (n) << LCD_DAV_VDS_BIT; \
4495} while (0)
4496
4497#define __lcd_dav_get_vde() \
4498  ( (REG_LCD_DAV & LCD_DAV_VDE_MASK) >> LCD_DAV_VDE_BIT )
4499#define __lcd_dav_set_vde(n) \
4500do { \
4501    REG_LCD_DAV &= ~LCD_DAV_VDE_MASK; \
4502    REG_LCD_DAV |= (n) << LCD_DAV_VDE_BIT; \
4503} while (0)
4504
4505#define __lcd_cmd0_set_sofint() ( REG_LCD_CMD0 |= LCD_CMD_SOFINT )
4506#define __lcd_cmd0_clr_sofint() ( REG_LCD_CMD0 &= ~LCD_CMD_SOFINT )
4507#define __lcd_cmd1_set_sofint() ( REG_LCD_CMD1 |= LCD_CMD_SOFINT )
4508#define __lcd_cmd1_clr_sofint() ( REG_LCD_CMD1 &= ~LCD_CMD_SOFINT )
4509
4510#define __lcd_cmd0_set_eofint() ( REG_LCD_CMD0 |= LCD_CMD_EOFINT )
4511#define __lcd_cmd0_clr_eofint() ( REG_LCD_CMD0 &= ~LCD_CMD_EOFINT )
4512#define __lcd_cmd1_set_eofint() ( REG_LCD_CMD1 |= LCD_CMD_EOFINT )
4513#define __lcd_cmd1_clr_eofint() ( REG_LCD_CMD1 &= ~LCD_CMD_EOFINT )
4514
4515#define __lcd_cmd0_set_pal() ( REG_LCD_CMD0 |= LCD_CMD_PAL )
4516#define __lcd_cmd0_clr_pal() ( REG_LCD_CMD0 &= ~LCD_CMD_PAL )
4517
4518#define __lcd_cmd0_get_len() \
4519  ( (REG_LCD_CMD0 & LCD_CMD_LEN_MASK) >> LCD_CMD_LEN_BIT )
4520#define __lcd_cmd1_get_len() \
4521  ( (REG_LCD_CMD1 & LCD_CMD_LEN_MASK) >> LCD_CMD_LEN_BIT )
4522
4523#endif /* !__ASSEMBLY__ */
4524
4525#endif /* __JZ4740_H__ */
4526

Archive Download this file



interactive