]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mx31/var/v2_0/include/hal_soc.h
ffa4498200b47b1ab3f27cda35e2aef3808df6ad
[karo-tx-redboot.git] / packages / hal / arm / mx31 / 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 #define L2CC_BASE_ADDR          0x30000000
80
81 /*
82  * AIPS 1
83  */
84 #define AIPS1_BASE_ADDR         0x43F00000
85 #define AIPS1_CTRL_BASE_ADDR    AIPS1_BASE_ADDR
86 #define MAX_BASE_ADDR           0x43F04000
87 #define EVTMON_BASE_ADDR        0x43F08000
88 #define CLKCTL_BASE_ADDR        0x43F0C000
89 #define ETB_SLOT4_BASE_ADDR     0x43F10000
90 #define ETB_SLOT5_BASE_ADDR     0x43F14000
91 #define ECT_CTIO_BASE_ADDR      0x43F18000
92 #define I2C_BASE_ADDR           0x43F80000
93 #define I2C3_BASE_ADDR          0x43F84000
94 #define OTG_BASE_ADDR           0x43F88000
95 #define ATA_BASE_ADDR           0x43F8C000
96 #define UART1_BASE_ADDR         0x43F90000
97 #define UART2_BASE_ADDR         0x43F94000
98 #define I2C2_BASE_ADDR          0x43F98000
99 #define OWIRE_BASE_ADDR         0x43F9C000
100 #define SSI1_BASE_ADDR          0x43FA0000
101 #define CSPI1_BASE_ADDR         0x43FA4000
102 #define KPP_BASE_ADDR           0x43FA8000
103 #define IOMUXC_BASE_ADDR        0x43FAC000
104 #define UART4_BASE_ADDR         0x43FB0000
105 #define UART5_BASE_ADDR         0x43FB4000
106 #define ECT_IP1_BASE_ADDR       0x43FB8000
107 #define ECT_IP2_BASE_ADDR       0x43FBC000
108
109 /*
110  * SPBA
111  */
112 #define SPBA_BASE_ADDR          0x50000000
113 #define MMC_SDHC1_BASE_ADDR     0x50004000
114 #define MMC_SDHC2_BASE_ADDR     0x50008000
115 #define UART3_BASE_ADDR         0x5000C000
116 #define CSPI2_BASE_ADDR         0x50010000
117 #define SSI2_BASE_ADDR          0x50014000
118 #define SIM_BASE_ADDR           0x50018000
119 #define IIM_BASE_ADDR           0x5001C000
120 #define ATA_DMA_BASE_ADDR       0x50020000
121 #define SPBA_CTRL_BASE_ADDR     0x5003C000
122
123 /*
124  * AIPS 2
125  */
126 #define AIPS2_BASE_ADDR         0x53F00000
127 #define AIPS2_CTRL_BASE_ADDR    AIPS2_BASE_ADDR
128 #define CCM_BASE_ADDR           0x53F80000
129 #define FIRI_BASE_ADDR          0x53F8C000
130 #define GPT1_BASE_ADDR          0x53F90000
131 #define EPIT1_BASE_ADDR         0x53F94000
132 #define EPIT2_BASE_ADDR         0x53F98000
133 #define GPIO3_BASE_ADDR         0x53FA4000
134 #define SCC_BASE                0x53FAC000
135 #define SCM_BASE                0x53FAE000
136 #define SMN_BASE                0x53FAF000
137 #define RNGA_BASE_ADDR          0x53FB0000
138 #define IPU_CTRL_BASE_ADDR      0x53FC0000
139 #define AUDMUX_BASE             0x53FC4000
140 #define MPEG4_ENC_BASE          0x53FC8000
141 #define GPIO1_BASE_ADDR         0x53FCC000
142 #define GPIO2_BASE_ADDR         0x53FD0000
143 #define SDMA_BASE_ADDR          0x53FD4000
144 #define RTC_BASE_ADDR           0x53FD8000
145 #define WDOG_BASE_ADDR          0x53FDC000
146 #define PWM_BASE_ADDR           0x53FE0000
147 #define RTIC_BASE_ADDR          0x53FEC000
148
149 /*
150  * ROMPATCH and AVIC
151  */
152 #define ROMPATCH_BASE_ADDR      0x60000000
153 #define AVIC_BASE_ADDR          0x68000000
154
155 /*
156  * NAND, SDRAM, WEIM, M3IF, EMI controllers
157  */
158 #define EXT_MEM_CTRL_BASE       0xB8000000
159 #define NFC_BASE                EXT_MEM_CTRL_BASE
160 #define ESDCTL_BASE             0xB8001000
161 #define WEIM_BASE_ADDR          0xB8002000
162 #define WEIM_CTRL_CS0           WEIM_BASE_ADDR
163 #define WEIM_CTRL_CS1           (WEIM_BASE_ADDR + 0x10)
164 #define WEIM_CTRL_CS2           (WEIM_BASE_ADDR + 0x20)
165 #define WEIM_CTRL_CS3           (WEIM_BASE_ADDR + 0x30)
166 #define WEIM_CTRL_CS4           (WEIM_BASE_ADDR + 0x40)
167 #define M3IF_BASE               0xB8003000
168 #define PCMCIA_CTL_BASE         0xB8004000
169
170 /*
171  * Memory regions and CS
172  */
173 #define IPU_MEM_BASE_ADDR       0x70000000
174 #define CSD0_BASE_ADDR          0x80000000
175 #define CSD1_BASE_ADDR          0x90000000
176 #define CS0_BASE_ADDR           0xA0000000
177 #define CS1_BASE_ADDR           0xA8000000
178 #define CS2_BASE_ADDR           0xB0000000
179 #define CS3_BASE_ADDR           0xB2000000
180 #define CS4_BASE_ADDR           0xB4000000
181 #define CS4_BASE_PSRAM          0xB5000000
182 #define CS5_BASE_ADDR           0xB6000000
183 #define PCMCIA_MEM_BASE_ADDR    0xC0000000
184
185 #define INTERNAL_ROM_VA         0xF0000000
186
187 /*
188  * IRQ Controller Register Definitions.
189  */
190 #define AVIC_NIMASK                     REG32_PTR(AVIC_BASE_ADDR + (0x04))
191 #define AVIC_INTTYPEH                   REG32_PTR(AVIC_BASE_ADDR + (0x18))
192 #define AVIC_INTTYPEL                   REG32_PTR(AVIC_BASE_ADDR + (0x1C))
193
194 /* L210 */
195 #define L2CC_BASE_ADDR                  0x30000000
196 #define L2_CACHE_LINE_SIZE              32
197 #define L2_CACHE_CTL_REG                0x100
198 #define L2_CACHE_AUX_CTL_REG            0x104
199 #define L2_CACHE_SYNC_REG               0x730
200 #define L2_CACHE_INV_LINE_REG           0x770
201 #define L2_CACHE_INV_WAY_REG            0x77C
202 #define L2_CACHE_CLEAN_LINE_REG         0x7B0
203 #define L2_CACHE_CLEAN_INV_LINE_REG     0x7F0
204
205 /* CCM */
206 #define CLKCTL_CCMR                     0x00
207 #define CLKCTL_PDR0                     0x04
208 #define CLKCTL_PDR1                     0x08
209 #define CLKCTL_PDR2                     0x64
210 #define CLKCTL_RCSR                     0x0C
211 #define CLKCTL_MPCTL                    0x10
212 #define CLKCTL_UPCTL                    0x14
213 #define CLKCTL_SPCTL                    0x18
214 #define CLKCTL_COSR                     0x1C
215 #define FREQ_26MHZ                      26000000
216 #define FREQ_27MHZ                      27000000
217 #define FREQ_32768HZ                    (32768 * 512)
218 #define FREQ_32000HZ                    (32000 * 512)
219 #define PLL_REF_CLK                     FREQ_26MHZ
220 //#define PLL_REF_CLK  FREQ_32768HZ
221 //#define PLL_REF_CLK  FREQ_32000HZ
222
223 /* WEIM - CS0 */
224 #define CSCRU                           0x00
225 #define CSCRL                           0x04
226 #define CSCRA                           0x08
227 #define CHIP_REV_1_0            0x0      /* PASS 1.0 */
228 #define CHIP_REV_1_1            0x1      /* PASS 1.1 */
229 #define CHIP_REV_2_0            0x2      /* PASS 2.0 */
230 #define CHIP_LATEST             CHIP_REV_1_1
231
232 #define IIM_STAT_OFF            0x00
233 #define IIM_STAT_BUSY           (1 << 7)
234 #define IIM_STAT_PRGD           (1 << 1)
235 #define IIM_STAT_SNSD           (1 << 0)
236 #define IIM_STATM_OFF           0x04
237 #define IIM_ERR_OFF             0x08
238 #define IIM_ERR_PRGE            (1 << 7)
239 #define IIM_ERR_WPE         (1 << 6)
240 #define IIM_ERR_OPE         (1 << 5)
241 #define IIM_ERR_RPE         (1 << 4)
242 #define IIM_ERR_WLRE        (1 << 3)
243 #define IIM_ERR_SNSE        (1 << 2)
244 #define IIM_ERR_PARITYE     (1 << 1)
245 #define IIM_EMASK_OFF           0x0C
246 #define IIM_FCTL_OFF            0x10
247 #define IIM_UA_OFF              0x14
248 #define IIM_LA_OFF              0x18
249 #define IIM_SDAT_OFF            0x1C
250 #define IIM_PREV_OFF            0x20
251 #define IIM_SREV_OFF            0x24
252 #define IIM_PREG_P_OFF          0x28
253 #define IIM_SCS0_OFF            0x2C
254 #define IIM_SCS1_P_OFF          0x30
255 #define IIM_SCS2_OFF            0x34
256 #define IIM_SCS3_P_OFF          0x38
257
258 #define EPIT_BASE_ADDR          EPIT1_BASE_ADDR
259 #define EPITCR                  0x00
260 #define EPITSR                  0x04
261 #define EPITLR                  0x08
262 #define EPITCMPR                0x0C
263 #define EPITCNR                 0x10
264
265 #define GPT_BASE_ADDR           GPT1_BASE_ADDR
266 #define GPTCR                   0x00
267 #define GPTPR                   0x04
268 #define GPTSR                   0x08
269 #define GPTIR                   0x0C
270 #define GPTOCR1                 0x10
271 #define GPTOCR2                 0x14
272 #define GPTOCR3                 0x18
273 #define GPTICR1                 0x1C
274 #define GPTICR2                 0x20
275 #define GPTCNT                  0x24
276
277 /* ESDCTL */
278 #define ESDCTL_ESDCTL0                  0x00
279 #define ESDCTL_ESDCFG0                  0x04
280 #define ESDCTL_ESDCTL1                  0x08
281 #define ESDCTL_ESDCFG1                  0x0C
282 #define ESDCTL_ESDMISC                  0x10
283
284 #if (PLL_REF_CLK != 26000000)
285 #error Wrong PLL reference clock! The following macros will not work.
286 #endif
287
288 /* Assuming 26MHz input clock */
289 /*                            PD             MFD              MFI          MFN */
290 #define MPCTL_PARAM_208     (((2-1) << 26) + ((1 -1) << 16) + (8  << 10) + (0  << 0))
291 #define MPCTL_PARAM_399     (((1-1) << 26) + ((52-1) << 16) + (7  << 10) + (35 << 0))
292 #define MPCTL_PARAM_532     (((1-1) << 26) + ((52-1) << 16) + (10 << 10) + (12 << 0))
293 #define MPCTL_PARAM_665     (((1-1) << 26) + ((52-1) << 16) + (12 << 10) + (41 << 0))
294 #define MPCTL_PARAM_532_27  (((1-1) << 26) + ((15-1) << 16) + (9  << 10) + (13 << 0))
295
296 /* UPCTL                      PD             MFD              MFI          MFN */
297 #define UPCTL_PARAM_288     (((1-1) << 26) + ((13-1) << 16) + (5  << 10) + (7  << 0))
298 #define UPCTL_PARAM_240     (((2-1) << 26) + ((13-1) << 16) + (9  << 10) + (3  << 0))
299 #define UPCTL_PARAM_240_27  (((2-1) << 26) + ((9 -1) << 16) + (8  << 10) + (8  << 0))
300
301 /* PDR0 */
302 #define PDR0_208_104_52     0xFF870D48  /* ARM=208MHz, HCLK=104MHz, IPG=52MHz */
303 #define PDR0_399_66_66      0xFF872B28  /* ARM=399MHz, HCLK=IPG=66.5MHz */
304 #define PDR0_399_133_66     0xFF871650  /* ARM=399MHz, HCLK=133MHz, IPG=66.5MHz */
305 #define PDR0_532_133_66     0xFF871D58  /* ARM=532MHz, HCLK=133MHz, IPG=66MHz */
306 #define PDR0_665_83_42      0xFF873B78  /* ARM=665MHz, HCLK=83MHz, IPG=42MHz */
307 #define PDR0_665_133_66     0xFF872560  /* ARM=665MHz, HCLK=133MHz, IPG=66MHz */
308
309 #define NAND_REG_BASE                   (NFC_BASE + 0xE00)
310 #define NFC_BUFSIZE_REG_OFF             (0 + 0x00)
311 #define RAM_BUFFER_ADDRESS_REG_OFF      (0 + 0x04)
312 #define NAND_FLASH_ADD_REG_OFF          (0 + 0x06)
313 #define NAND_FLASH_CMD_REG_OFF          (0 + 0x08)
314 #define NFC_CONFIGURATION_REG_OFF       (0 + 0x0A)
315 #define ECC_STATUS_RESULT_REG_OFF       (0 + 0x0C)
316 #define ECC_RSLT_MAIN_AREA_REG_OFF      (0 + 0x0E)
317 #define ECC_RSLT_SPARE_AREA_REG_OFF     (0 + 0x10)
318 #define NF_WR_PROT_REG_OFF              (0 + 0x12)
319 #define UNLOCK_START_BLK_ADD_REG_OFF    (0 + 0x14)
320 #define UNLOCK_END_BLK_ADD_REG_OFF      (0 + 0x16)
321 #define NAND_FLASH_WR_PR_ST_REG_OFF     (0 + 0x18)
322 #define NAND_FLASH_CONFIG1_REG_OFF      (0 + 0x1A)
323 #define NAND_FLASH_CONFIG2_REG_OFF      (0 + 0x1C)
324 #define RAM_BUFFER_ADDRESS_RBA_3        0x3
325 #define NFC_BUFSIZE_1KB                 0x0
326 #define NFC_BUFSIZE_2KB                 0x1
327 #define NFC_CONFIGURATION_UNLOCKED      0x2
328 #define ECC_STATUS_RESULT_NO_ERR        0x0
329 #define ECC_STATUS_RESULT_1BIT_ERR      0x1
330 #define ECC_STATUS_RESULT_2BIT_ERR      0x2
331 #define NF_WR_PROT_UNLOCK               0x4
332 #define NAND_FLASH_CONFIG1_FORCE_CE     (1 << 7)
333 #define NAND_FLASH_CONFIG1_RST          (1 << 6)
334 #define NAND_FLASH_CONFIG1_BIG          (1 << 5)
335 #define NAND_FLASH_CONFIG1_INT_MSK      (1 << 4)
336 #define NAND_FLASH_CONFIG1_ECC_EN       (1 << 3)
337 #define NAND_FLASH_CONFIG1_SP_EN        (1 << 2)
338 #define NAND_FLASH_CONFIG2_INT_DONE     (1 << 15)
339 #define NAND_FLASH_CONFIG2_FDO_PAGE     (0 << 3)
340 #define NAND_FLASH_CONFIG2_FDO_ID       (2 << 3)
341 #define NAND_FLASH_CONFIG2_FDO_STATUS   (4 << 3)
342 #define NAND_FLASH_CONFIG2_FDI_EN       (1 << 2)
343 #define NAND_FLASH_CONFIG2_FADD_EN      (1 << 1)
344 #define NAND_FLASH_CONFIG2_FCMD_EN      (1 << 0)
345 #define FDO_PAGE_SPARE_VAL              0x8
346
347 #define MXC_NAND_BASE_DUMMY             0x00000000
348 #define NOR_FLASH_BOOT                  0
349 #define NAND_FLASH_BOOT                 0x10000000
350 #define SDRAM_NON_FLASH_BOOT            0x20000000
351 #define MXCBOOT_FLAG_REG                (AVIC_BASE_ADDR + 0x100)
352 #define MXCFIS_NOTHING                  0x00000000
353 #define MXCFIS_NAND                     0x10000000
354 #define MXCFIS_NOR                      0x20000000
355 #define MXCFIS_FLAG_REG                 (AVIC_BASE_ADDR + 0x104)
356
357 #define IS_BOOTING_FROM_NAND()          (readl(MXCBOOT_FLAG_REG) == NAND_FLASH_BOOT)
358 #define IS_BOOTING_FROM_NOR()           (readl(MXCBOOT_FLAG_REG) == NOR_FLASH_BOOT)
359 #define IS_BOOTING_FROM_SDRAM()         (readl(MXCBOOT_FLAG_REG) == SDRAM_NON_FLASH_BOOT)
360
361 #ifndef MXCFLASH_SELECT_NAND
362 #define IS_FIS_FROM_NAND()              0
363 #else
364 #define IS_FIS_FROM_NAND()              (readl(MXCFIS_FLAG_REG) == MXCFIS_NAND)
365 #endif
366
367 #ifndef MXCFLASH_SELECT_NOR
368 #define IS_FIS_FROM_NOR()               0
369 #else
370 #define IS_FIS_FROM_NOR()               (!IS_FIS_FROM_NAND())
371 #endif
372
373 #define MXC_ASSERT_NOR_BOOT()           writel(MXCFIS_NOR, MXCFIS_FLAG_REG)
374 #define MXC_ASSERT_NAND_BOOT()          writel(MXCFIS_NAND, MXCFIS_FLAG_REG)
375
376 /*
377  * This macro is used to get certain bit field from a number
378  */
379 #define MXC_GET_FIELD(val, len, sh)          ((val >> sh) & ((1 << len) - 1))
380
381 /*
382  * This macro is used to set certain bit field inside a number
383  */
384 #define MXC_SET_FIELD(val, len, sh, nval)    ((val & ~(((1 << len) - 1) << sh)) | (nval << sh))
385
386 #define L2CC_ENABLED
387 #define UART_WIDTH_32         /* internal UART is 32bit access only */
388
389 #if !defined(__ASSEMBLER__)
390 void cyg_hal_plf_serial_init(void);
391 void cyg_hal_plf_serial_stop(void);
392 void hal_delay_us(unsigned int usecs);
393 #define HAL_DELAY_US(n)     hal_delay_us(n)
394
395 enum plls {
396         MCU_PLL = CCM_BASE_ADDR + CLKCTL_MPCTL,
397         USB_PLL = CCM_BASE_ADDR + CLKCTL_UPCTL,
398         SER_PLL = CCM_BASE_ADDR + CLKCTL_SPCTL,
399 };
400
401 enum main_clocks {
402         CPU_CLK,
403         AHB_CLK,
404         MBX_CLK,
405         IPG_CLK,
406         IPG_PER_CLK,
407         NFC_CLK,
408         USB_CLK,
409         HSP_CLK,
410 };
411
412 enum peri_clocks {
413         UART1_BAUD,
414         UART2_BAUD,
415         UART3_BAUD,
416         UART4_BAUD,
417         UART5_BAUD,
418         FIRI_BAUD,
419         SIM_BAUD,
420         SSI1_BAUD,
421         SSI2_BAUD,
422         CSI_BAUD,
423         MSTICK1_CLK,
424         MSTICK2_CLK,
425         SPI1_CLK = CSPI1_BASE_ADDR,
426         SPI2_CLK = CSPI2_BASE_ADDR,
427 };
428
429 unsigned int pll_clock(enum plls pll);
430
431 unsigned int get_main_clock(enum main_clocks clk);
432
433 unsigned int get_peri_clock(enum peri_clocks clk);
434
435 enum {
436     MXC_NFC_V1,
437     MXC_NFC_V2,
438 };
439
440 typedef unsigned int nfc_setup_func_t(unsigned int, unsigned int, unsigned int);
441
442 #endif //#if !defined(__ASSEMBLER__)
443
444 #define HAL_MMU_OFF() \
445 CYG_MACRO_START          \
446     asm volatile (                                                      \
447         "mcr p15, 0, r0, c7, c14, 0;"                                   \
448         "mcr p15, 0, r0, c7, c10, 4;" /* drain the write buffer */      \
449         "mcr p15, 0, r0, c7, c5, 0;" /* invalidate I cache */           \
450         "mrc p15, 0, r0, c1, c0, 0;" /* read c1 */                      \
451         "bic r0, r0, #0x7;" /* disable DCache and MMU */                \
452         "bic r0, r0, #0x1000;" /* disable ICache */                     \
453         "mcr p15, 0, r0, c1, c0, 0;" /*  */                             \
454         "nop;" /* flush i+d-TLBs */                                     \
455         "nop;" /* flush i+d-TLBs */                                     \
456         "nop;" /* flush i+d-TLBs */                                     \
457         :                                                               \
458         :                                                               \
459         : "r0","memory" /* clobber list */);                            \
460 CYG_MACRO_END
461
462 #endif /* __HAL_SOC_H__ */