]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mxc91311/var/v2_0/include/hal_soc.h
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / hal / arm / mxc91311 / var / v2_0 / include / hal_soc.h
1 //==========================================================================
2 //
3 //      hal_soc.h
4 //
5 //      SoC chip definitions
6 //
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12 // Copyright (C) 2002 Gary Thomas
13 //
14 // eCos is free software; you can redistribute it and/or modify it under
15 // the terms of the GNU General Public License as published by the Free
16 // Software Foundation; either version 2 or (at your option) any later version.
17 //
18 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
19 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21 // for more details.
22 //
23 // You should have received a copy of the GNU General Public License along
24 // with eCos; if not, write to the Free Software Foundation, Inc.,
25 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 //
27 // As a special exception, if other files instantiate templates or use macros
28 // or inline functions from this file, or you compile this file and link it
29 // with other works to produce a work based on this file, this file does not
30 // by itself cause the resulting work to be covered by the GNU General Public
31 // License. However the source code for this file must still be made available
32 // in accordance with section (3) of the GNU General Public License.
33 //
34 // This exception does not invalidate any other reasons why a work based on
35 // this file might be covered by the GNU General Public License.
36 //
37 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
38 // at http://sources.redhat.com/ecos/ecos-license/
39 // -------------------------------------------
40 //####ECOSGPLCOPYRIGHTEND####
41 //========================================================================*/
42
43 #ifndef __HAL_SOC_H__
44 #define __HAL_SOC_H__
45
46 #ifdef __ASSEMBLER__
47
48 #define REG8_VAL(a)          (a)
49 #define REG16_VAL(a)         (a)
50 #define REG32_VAL(a)         (a)
51
52 #define REG8_PTR(a)          (a)
53 #define REG16_PTR(a)         (a)
54 #define REG32_PTR(a)         (a)
55
56 #else /* __ASSEMBLER__ */
57
58 extern char HAL_PLATFORM_EXTRA[];
59 #define REG8_VAL(a)          ((unsigned char)(a))
60 #define REG16_VAL(a)         ((unsigned short)(a))
61 #define REG32_VAL(a)         ((unsigned int)(a))
62
63 #define REG8_PTR(a)          ((volatile unsigned char *)(a))
64 #define REG16_PTR(a)         ((volatile unsigned short *)(a))
65 #define REG32_PTR(a)         ((volatile unsigned int *)(a))
66 #define readb(a)             (*(volatile unsigned char *)(a))
67 #define readw(a)             (*(volatile unsigned short *)(a))
68 #define readl(a)             (*(volatile unsigned int *)(a))
69 #define writeb(v,a)          (*(volatile unsigned char *)(a) = (v))
70 #define writew(v,a)          (*(volatile unsigned short *)(a) = (v))
71 #define writel(v,a)          (*(volatile unsigned int *)(a) = (v))
72
73 #endif /* __ASSEMBLER__ */
74
75 /*
76  * Default Memory Layout Definitions
77  */
78
79 /*
80  * AIPS 1
81  */
82 #define AIPS1_BASE_ADDR         0x43F00000
83 #define AIPS1_CTRL_BASE_ADDR    AIPS1_BASE_ADDR
84 #define MAX_BASE_ADDR           0x43F04000
85 #define CLKCTL_BASE_ADDR        0x43F08000
86 #define ETB_SLOT4_BASE_ADDR     0x43F0C000
87 #define ETB_SLOT5_BASE_ADDR     0x43F10000
88 #define AAPE_BASE_ADDR          0x43F14000
89
90 #define I2C_BASE_ADDR           0x43F80000
91 #define MU_BASE_ADDR            0x43F84000
92 #define UART2_BASE_ADDR         0x43F94000
93 #define OWIRE_BASE_ADDR         0x43F9C000
94 #define CSPI1_BASE_ADDR         0x43FA4000
95 #define KPP_BASE_ADDR           0x43FA8000
96 #define CTI_ARM_BASE_ADDR       0x43FBC000
97 /*
98  * SPBA
99  */
100 #define SPBA_BASE_ADDR          0x50000000
101
102 #define IOMUXC_BASE_ADDR        0x50000000
103 #define MMC_SDHC1_BASE_ADDR     0x50004000
104 #define MMC_SDHC2_BASE_ADDR     0x50008000
105 #define UART3_BASE_ADDR         0x5000C000
106 #define CSPI2_BASE_ADDR         0x50010000
107 #define SSI1_BASE_ADDR          0x50014000
108 #define RTIC_BASE_ADDR          0x50018000
109 #define IIM_BASE_ADDR           0x5001C000
110 #define USBOTG_BASE_ADDR        0x50020000
111 #define RNGC_BASE_ADDR          0x50024000
112 #define UART4_BASE_ADDR         0x50028000
113 #define GPIO2_BASE_ADDR         0x5002C000
114 #define SIM1_BASE_ADDR          0x50030000
115 #define GEMK_BASE_ADDR          0x50034000
116 #define SDMA_CTI_BASE_ADDR      0x50038000
117 #define SPBA_CTRL_BASE_ADDR     0x5003C000
118
119 /*
120  * AIPS 2
121  */
122 #define AIPS2_BASE_ADDR         0x53F00000
123 #define AIPS2_CTRL_BASE_ADDR    AIPS2_BASE_ADDR
124 #define CRM_MCU_BASE_ADDR       0x53F80000
125 #define ECT_MCU_CTI_BASE_ADDR   0x53F84000
126 #define EDIO_BASE_ADDR          0x53F88000
127 #define GPT_BASE_ADDR           0x53F90000
128 #define EPIT1_BASE_ADDR         0x53F94000
129 #define SCC_BASE                0x53FAC000
130 #define RTR_BASE_ADDR           0x53FB4000
131 #define IPU_CTRL_BASE_ADDR      0x53FC0000
132 #define AUDMUX_BASE             0x53FC4000
133 #define GPIO1_BASE_ADDR         0x53FCC000
134 #define SDMA_BASE_ADDR          0x53FD4000
135 #define RTC_BASE_ADDR           0x53FD8000
136 #define WDOG1_BASE_ADDR         0x53FDC000
137 #define WDOG_BASE_ADDR          WDOG1_BASE_ADDR
138
139 /*
140  * ROMPATCH and AVIC
141  */
142 #define ROMPATCH_BASE_ADDR      0x60000000
143 #define AVIC_BASE_ADDR          0x68000000
144
145 /*
146  * NAND, SDRAM, WEIM, M3IF, EMI controllers
147  */
148 #define EXT_MEM_CTRL_BASE       0xB8000000
149 #define NFC_BASE                EXT_MEM_CTRL_BASE
150 #define ESDCTL_BASE             0xB8001000
151 #define WEIM_BASE_ADDR          0xB8002000
152 #define WEIM_CTRL_CS0           WEIM_BASE_ADDR
153 #define WEIM_CTRL_CS1           (WEIM_BASE_ADDR + 0x10)
154 #define WEIM_CTRL_CS2           (WEIM_BASE_ADDR + 0x20)
155 #define WEIM_CTRL_CS3           (WEIM_BASE_ADDR + 0x30)
156 #define WEIM_CTRL_CS4           (WEIM_BASE_ADDR + 0x40)
157 #define M3IF_BASE               0xB8003000
158
159 /*
160  * Memory regions and CS
161  */
162 #define IPU_MEM_BASE_ADDR       0x70000000
163 #define CSD0_BASE_ADDR          0x80000000
164 #define CSD1_BASE_ADDR          0x90000000
165 #define CS0_BASE_ADDR           0xA0000000
166 #define CS1_BASE_ADDR           0xA8000000
167 #define CS2_BASE_ADDR           0xB0000000
168 #define CS3_BASE_ADDR           0xB2000000
169 #define CS4_BASE_ADDR           0xB4000000
170
171 #define INTERNAL_ROM_VA         0xF0000000
172
173 /*
174  * IRQ Controller Register Definitions.
175  */
176 #define AVIC_NIMASK                     REG32_PTR(AVIC_BASE_ADDR + (0x04))
177 #define AVIC_INTTYPEH                   REG32_PTR(AVIC_BASE_ADDR + (0x18))
178 #define AVIC_INTTYPEL                   REG32_PTR(AVIC_BASE_ADDR + (0x1C))
179
180 /* SPBA */
181 #define SPBA_IOMUX                      0x0
182 #define SPBA_GPIO_SDMA                  0x2C
183
184 /* CCM */
185 #define CLKCTL_MCR                      0x00
186 #define CLKCTL_PDR0                     0x04
187 #define CLKCTL_PDR1                     0x08
188 #define CLKCTL_RCSR                     0x0C
189 #define CLKCTL_MPCTL                    0x10
190 #define CLKCTL_UPCTL                    0x14
191 #define CLKCTL_COSR                     0x18
192 #define CLKCTL_MCGR0                    0x1C
193 #define CLKCTL_MCGR1                    0x20
194 #define CLKCTL_MCGR2                    0x24
195 #define CLKCTL_DCVR0                    0x28
196 #define CLKCTL_DCVR1                    0x2C
197 #define CLKCTL_DCVR2                    0x30
198 #define CLKCTL_DCVR3                    0x34
199 #define CLKCTL_PMCR                     0x38
200 #define CLKCTL_SDCR                     0x3C
201 #define CLKCTL_CDTR                     0x40
202 #define CLKCTL_TPCTL                    0x44
203 #define CLKCTL_UCDTR                    0x48
204 #define CLKCTL_TCDTR                    0x4C
205 #define CLKCTL_MPDR2                    0x50
206 #define CLKCTL_DPTCDBG                  0x54
207 #define CLKCTL_PMCR1                    0x58
208
209 #define FREQ_26MHZ                      26000000
210 #define FREQ_32768HZ                    (32768 * 512)
211 #define FREQ_32000HZ                    (32000 * 512)
212 #define PLL_REF_CLK                     FREQ_26MHZ
213 //#define PLL_REF_CLK  FREQ_32768HZ
214 //#define PLL_REF_CLK  FREQ_32000HZ
215
216 /* WEIM - CS0 */
217 #define CSCRU                           0x00
218 #define CSCRL                           0x04
219 #define CSCRA                           0x08
220
221 /* ESDCTL */
222 #define ESDCTL_ESDCTL0                  0x00
223 #define ESDCTL_ESDCFG0                  0x04
224 #define ESDCTL_ESDCTL1                  0x08
225 #define ESDCTL_ESDCFG1                  0x0C
226 #define ESDCTL_ESDMISC                  0x10
227 #define ESDCTL_ESDCDLY1                 0x20
228 #define ESDCTL_ESDCDLY2                 0x24
229 #define ESDCTL_ESDCDLY5                 0x30
230 #define ESDCTL_ESDCDLYL                 0x34
231
232 #if (PLL_REF_CLK != 26000000)
233 #error Wrong PLL reference clock! The following macros will not work.
234 #endif
235
236 /* Assuming 26MHz input clock */
237 /* MPCTL                   BRMO             PD             MFD              MFI          MFN */
238 #define MPCTL_PARAM_208  ((0  << 31) + ((2-1) << 26) + ((1-1)  << 16) + (8  << 11) + (0  << 0))
239 #define MPCTL_PARAM_266  ((0  << 31) + ((1-1) << 26) + ((416-1) << 16) + (5  << 11) + (48 << 0))
240 #define MPCTL_PARAM_240  ((0  << 31) + ((2-1) << 26) + ((416-1) << 16) + (9 << 11) + (96 << 0))
241
242 #define TPCTL_PARAM_360  ((1  << 31) + ((1-1) << 26) + ((416-1) << 16) + (6 << 11) + (384 << 0))
243 #define TPCTL_PARAM_399  ((0  << 31) + ((1-1) << 26) + ((52-1) << 16) + (7 << 11) + (35 << 0))
244
245 /* UPCTL                   PD             MFD              MFI          MFN */
246 #define UPCTL_PARAM_288  (((1-1) << 26) + ((13-1) << 16) + (5  << 10) + (7  << 0))
247 #define UPCTL_PARAM_240  (((2-1) << 26) + ((416-1) << 16) + (9  << 10) + (96  << 0))
248
249 #define PDR0_266_133_66     0xFF800548  /* ARM=266MHz, HCLK=133MHz, IPG=66.5MHz */
250 #define PDR0_240_120_60     0xFF800548  /* ARM=240MHz, HCLK=120MHz, IPG=60MHz */
251 #define PDR0_240_60_60      0xFF800518  /* ARM=240MHz, HCLK=60MHz, IPG=60MHz */
252 #define PDR0_266_66_66      0xFF800318  /* ARM=266MHz, HCLK=IPG=66.5MHz */
253 #define PDR0_208_52_52      0xFF800218  /* ARM=208MHz, HCLK=52MHz, IPG=52MHz */
254
255 /* IIM */
256 #define CHIP_REV_1_0        0x10      /* PASS 1.0 */
257 #define CHIP_REV_1_1        0x11      /* PASS 1.0 */
258 #define CHIP_REV_1_2        0x12      /* PASS 1.2 */
259 #define CHIP_REV_2_0        0x20      /* PASS 2.0 */
260 #define CHIP_REV_2_1        0x21      /* PASS 2.1 */
261
262 #define CHIP_LATEST         CHIP_REV_1_0
263
264 #define IIM_STAT_OFF        0x00
265 #define IIM_STAT_BUSY       (1 << 7)
266 #define IIM_STAT_PRGD       (1 << 1)
267 #define IIM_STAT_SNSD       (1 << 0)
268 #define IIM_STATM_OFF       0x04
269 #define IIM_ERR_OFF         0x08
270 #define IIM_ERR_PRGE        (1 << 7)
271 #define IIM_ERR_WPE         (1 << 6)
272 #define IIM_ERR_OPE         (1 << 5)
273 #define IIM_ERR_RPE         (1 << 4)
274 #define IIM_ERR_WLRE        (1 << 3)
275 #define IIM_ERR_SNSE        (1 << 2)
276 #define IIM_ERR_PARITYE     (1 << 1)
277 #define IIM_EMASK_OFF       0x0C
278 #define IIM_FCTL_OFF        0x10
279 #define IIM_UA_OFF          0x14
280 #define IIM_LA_OFF          0x18
281 #define IIM_SDAT_OFF        0x1C
282 #define IIM_PREV_OFF        0x20
283 #define IIM_SREV_OFF        0x24
284 #define IIM_PREG_P_OFF      0x28
285 #define IIM_SCS0_OFF        0x2C
286 #define IIM_SCS1_P_OFF      0x30
287 #define IIM_SCS2_OFF        0x34
288 #define IIM_SCS3_P_OFF      0x38
289
290 #define EPIT_BASE_ADDR      EPIT1_BASE_ADDR
291 #define EPITCR              0x00
292 #define EPITSR              0x04
293 #define EPITLR              0x08
294 #define EPITCMPR            0x0C
295 #define EPITCNR             0x10
296
297 #define NAND_REG_BASE                   (NFC_BASE + 0xE00)
298 #define NFC_BUFSIZE_REG_OFF             (0 + 0x00)
299 #define RAM_BUFFER_ADDRESS_REG_OFF      (0 + 0x04)
300 #define NAND_FLASH_ADD_REG_OFF          (0 + 0x06)
301 #define NAND_FLASH_CMD_REG_OFF          (0 + 0x08)
302 #define NFC_CONFIGURATION_REG_OFF       (0 + 0x0A)
303 #define ECC_STATUS_RESULT_REG_OFF       (0 + 0x0C)
304 #define ECC_RSLT_MAIN_AREA_REG_OFF      (0 + 0x0E)
305 #define ECC_RSLT_SPARE_AREA_REG_OFF     (0 + 0x10)
306 #define NF_WR_PROT_REG_OFF              (0 + 0x12)
307 #define UNLOCK_START_BLK_ADD_REG_OFF    (0 + 0x14)
308 #define UNLOCK_END_BLK_ADD_REG_OFF      (0 + 0x16)
309 #define NAND_FLASH_WR_PR_ST_REG_OFF     (0 + 0x18)
310 #define NAND_FLASH_CONFIG1_REG_OFF      (0 + 0x1A)
311 #define NAND_FLASH_CONFIG2_REG_OFF      (0 + 0x1C)
312 #define RAM_BUFFER_ADDRESS_RBA_3        0x3
313 #define NFC_BUFSIZE_1KB                 0x0
314 #define NFC_BUFSIZE_2KB                 0x1
315 #define NFC_CONFIGURATION_UNLOCKED      0x2
316 #define ECC_STATUS_RESULT_NO_ERR        0x0
317 #define ECC_STATUS_RESULT_1BIT_ERR      0x1
318 #define ECC_STATUS_RESULT_2BIT_ERR      0x2
319 #define NF_WR_PROT_UNLOCK               0x4
320 #define NAND_FLASH_CONFIG1_FORCE_CE     (1 << 7)
321 #define NAND_FLASH_CONFIG1_RST          (1 << 6)
322 #define NAND_FLASH_CONFIG1_BIG          (1 << 5)
323 #define NAND_FLASH_CONFIG1_INT_MSK      (1 << 4)
324 #define NAND_FLASH_CONFIG1_ECC_EN       (1 << 3)
325 #define NAND_FLASH_CONFIG1_SP_EN        (1 << 2)
326 #define NAND_FLASH_CONFIG2_INT_DONE     (1 << 15)
327 #define NAND_FLASH_CONFIG2_FDO_PAGE     (0 << 3)
328 #define NAND_FLASH_CONFIG2_FDO_ID       (2 << 3)
329 #define NAND_FLASH_CONFIG2_FDO_STATUS   (4 << 3)
330 #define NAND_FLASH_CONFIG2_FDI_EN       (1 << 2)
331 #define NAND_FLASH_CONFIG2_FADD_EN      (1 << 1)
332 #define NAND_FLASH_CONFIG2_FCMD_EN      (1 << 0)
333 #define FDO_PAGE_SPARE_VAL              0x8
334
335 #define MXC_NAND_BASE_DUMMY             0xE0000000
336 #define NOR_FLASH_BOOT                  0
337 #define NAND_FLASH_BOOT                 0x10000000
338 #define SDRAM_NON_FLASH_BOOT            0x20000000
339 #define MXCBOOT_FLAG_REG                (AVIC_BASE_ADDR + 0x20)
340 #define MXCFIS_NOTHING                  0x00000000
341 #define MXCFIS_NAND                     0x10000000
342 #define MXCFIS_NOR                      0x20000000
343 #define MXCFIS_FLAG_REG                 (AVIC_BASE_ADDR + 0x24)
344
345 #define IS_BOOTING_FROM_NAND()          (readl(MXCBOOT_FLAG_REG) == NAND_FLASH_BOOT)
346 #define IS_BOOTING_FROM_NOR()           (readl(MXCBOOT_FLAG_REG) == NOR_FLASH_BOOT)
347 #define IS_BOOTING_FROM_SDRAM()         (readl(MXCBOOT_FLAG_REG) == SDRAM_NON_FLASH_BOOT)
348
349 #ifndef MXCFLASH_SELECT_NAND
350 #define IS_FIS_FROM_NAND()              0
351 #else
352 #define IS_FIS_FROM_NAND()              (readl(MXCFIS_FLAG_REG) == MXCFIS_NAND)
353 #endif
354
355 #ifndef MXCFLASH_SELECT_NOR
356 #define IS_FIS_FROM_NOR()               0
357 #else
358 #define IS_FIS_FROM_NOR()               (!IS_FIS_FROM_NAND())
359 #endif
360
361 #define MXC_ASSERT_NOR_BOOT()           writel(MXCFIS_NOR, MXCFIS_FLAG_REG)
362 #define MXC_ASSERT_NAND_BOOT()          writel(MXCFIS_NAND, MXCFIS_FLAG_REG)
363
364 /*
365  * This macro is used to get certain bit field from a number
366  */
367 #define MXC_GET_FIELD(val, len, sh)          ((val >> sh) & ((1 << len) - 1))
368
369 /*
370  * This macro is used to set certain bit field inside a number
371  */
372 #define MXC_SET_FIELD(val, len, sh, nval)    ((val & ~(((1 << len) - 1) << sh)) | (nval << sh))
373
374 #define UART_WIDTH_32         /* internal UART is 32bit access only */
375
376
377 #if !defined(__ASSEMBLER__)
378 void cyg_hal_plf_serial_init(void);
379 void cyg_hal_plf_serial_stop(void);
380 void hal_delay_us(unsigned int usecs);
381 #define HAL_DELAY_US(n)     hal_delay_us(n)
382
383 enum plls {
384     MCU_PLL = CRM_MCU_BASE_ADDR + CLKCTL_MPCTL,
385     USB_PLL = CRM_MCU_BASE_ADDR + CLKCTL_UPCTL,
386     TUR_PLL = CRM_MCU_BASE_ADDR + CLKCTL_TPCTL,
387 };
388
389 enum main_clocks {
390     CPU_CLK,
391     AHB_CLK,
392     IPG_CLK,
393     NFC_CLK,
394     USB_CLK,
395 };
396
397 enum peri_clocks {
398     UART2_BAUD,
399     UART3_BAUD,
400     UART4_BAUD,
401     SSI1_BAUD,
402     CSI_BAUD,
403     SPI1_CLK = CSPI1_BASE_ADDR,
404     SPI2_CLK = CSPI2_BASE_ADDR,
405 };
406
407 unsigned int pll_clock(enum plls pll);
408
409 unsigned int get_main_clock(enum main_clocks clk);
410
411 unsigned int get_peri_clock(enum peri_clocks clk);
412
413 typedef unsigned int nfc_setup_func_t(unsigned int, unsigned int, unsigned int);
414
415 #endif //#if !defined(__ASSEMBLER__)
416
417 #define HAL_MMU_OFF() \
418 CYG_MACRO_START          \
419     asm volatile (                                                      \
420         "1: "                                                           \
421         "mrc p15, 0, r15, c7, c14, 3;"   /*test clean and inval*/       \
422         "bne 1b;"                                                       \
423         "mov r0, #0;"                                                   \
424         "mcr p15, 0, r0, c7, c10, 4;" /* drain the write buffer */      \
425         "mcr p15, 0, r0, c7, c5, 0;" /* invalidate I cache */           \
426         "mrc p15, 0, r0, c1, c0, 0;" /* read c1 */                      \
427         "bic r0, r0, #0x7;" /* disable DCache and MMU */                \
428         "bic r0, r0, #0x1000;" /* disable ICache */                     \
429         "mcr p15, 0, r0, c1, c0, 0;" /*  */                             \
430         "nop;" /* flush i+d-TLBs */                                     \
431         "nop;" /* flush i+d-TLBs */                                     \
432         "nop;" /* flush i+d-TLBs */                                     \
433         :                                                               \
434         :                                                               \
435         : "r0","memory" /* clobber list */);                            \
436 CYG_MACRO_END
437
438 #endif // __HAL_SOC_H__