Root/usbboot/xburst_include/target/jz4740.h

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

Archive Download this file



interactive