]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mx31/ads/v2_0/src/board_misc.c
66d41fd68fa6e546eb1d7a0b4076283d0da9a369
[karo-tx-redboot.git] / packages / hal / arm / mx31 / ads / v2_0 / src / board_misc.c
1 //==========================================================================
2 //
3 //      board_misc.c
4 //
5 //      HAL misc board support code for the board
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 //
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
16 //
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20 // for more details.
21 //
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 //
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
32 //
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
35 //
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //========================================================================*/
41
42 #include <pkgconf/hal.h>
43 #include <pkgconf/system.h>
44 #include <redboot.h>
45 #include CYGBLD_HAL_PLATFORM_H
46
47 #include <cyg/infra/cyg_type.h>         // base types
48 #include <cyg/infra/cyg_trac.h>         // tracing macros
49 #include <cyg/infra/cyg_ass.h>          // assertion macros
50
51 #include <cyg/hal/hal_io.h>             // IO macros
52 #include <cyg/hal/hal_arch.h>           // Register state info
53 #include <cyg/hal/hal_diag.h>
54 #include <cyg/hal/hal_intr.h>           // Interrupt names
55 #include <cyg/hal/hal_cache.h>
56 #include <cyg/hal/hal_soc.h>         // Hardware definitions
57 #include <cyg/hal/fsl_board.h>             // Platform specifics
58
59 #include <cyg/infra/diag.h>             // diag_printf
60
61 // All the MM table layout is here:
62 #include <cyg/hal/hal_mm.h>
63
64 externC void* memset(void *, int, size_t);
65
66 void hal_mmu_init(void)
67 {
68     unsigned long ttb_base = RAM_BANK0_BASE + 0x4000;
69     unsigned long i;
70
71     /*
72      * Set the TTB register
73      */
74     asm volatile ("mcr  p15,0,%0,c2,c0,0" : : "r"(ttb_base) /*:*/);
75
76     /*
77      * Set the Domain Access Control Register
78      */
79     i = ARM_ACCESS_DACR_DEFAULT;
80     asm volatile ("mcr  p15,0,%0,c3,c0,0" : : "r"(i) /*:*/);
81
82     /*
83      * First clear all TT entries - ie Set them to Faulting
84      */
85     memset((void *)ttb_base, 0, ARM_FIRST_LEVEL_PAGE_TABLE_SIZE);
86
87     /*              Actual   Virtual  Size   Attributes                                                    Function  */
88     /*              Base     Base     MB     cached?           buffered?        access permissions                 */
89     /*              xxx00000 xxx00000                                                                                */
90     X_ARM_MMU_SECTION(0x000, 0xF00,   0x1,   ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* ROM */
91     X_ARM_MMU_SECTION(0x300, 0x300,   0x1,   ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* L2CC */
92     X_ARM_MMU_SECTION(0x43F, 0x43F,   0x3C1, ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* Internal Regsisters upto SDRAM*/
93     X_ARM_MMU_SECTION(0x800, 0x000,   0x80,  ARM_CACHEABLE,   ARM_BUFFERABLE,   ARM_ACCESS_PERM_RW_RW); /* SDRAM */
94     X_ARM_MMU_SECTION(0x800, 0x800,   0x80,  ARM_CACHEABLE,   ARM_BUFFERABLE,   ARM_ACCESS_PERM_RW_RW); /* SDRAM */
95     X_ARM_MMU_SECTION(0xA00, 0xA00,   0x20,  ARM_CACHEABLE,   ARM_BUFFERABLE,   ARM_ACCESS_PERM_RW_RW); /* Flash */
96     X_ARM_MMU_SECTION(0xB40, 0xB40,   0x10,  ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* External I/O */
97     X_ARM_MMU_SECTION(0xB50, 0xB50,   0x8,   ARM_CACHEABLE,   ARM_BUFFERABLE,   ARM_ACCESS_PERM_RW_RW); /* PSRAM */
98     X_ARM_MMU_SECTION(0xB80, 0xB80,   0x10,  ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* EIM control*/
99 }
100
101 //
102 // Platform specific initialization
103 //
104
105 unsigned int g_clock_src;
106
107 void plf_hardware_init(void)
108 {
109     volatile unsigned short dummy, temp;
110     volatile int i = 0;
111     unsigned long val = readl(CCM_BASE_ADDR + CLKCTL_CCMR);
112     
113     if ((val & 0x6) == 0x4) {
114         if ((readw(PBC_BASE + PBC_BSTAT2) & CLK_INPUT_27MHZ_SET) != 0) {
115             g_clock_src = FREQ_27MHZ;
116         } else {
117             g_clock_src = FREQ_26MHZ;
118         }
119     } else if ((val & 0x6) == 0x2) {
120         g_clock_src = FREQ_32768HZ;
121     }
122
123     /* PBC setup */
124     //Enable UART transceivers also reset the Ethernet/external UART
125     temp = readw(PBC_BASE + PBC_BCTRL1);
126
127     writew(0x8023, PBC_BASE + PBC_BCTRL1);
128
129     for (i = 0; i < 100000; i++) {
130     }
131
132     // clear the reset, toggle the LEDs
133     writew(0xDF, PBC_BASE + PBC_BCTRL1_CLR);
134
135     for (i = 0; i < 100000; i++) {
136     }
137
138     dummy = readb(0xB4000008);
139     dummy = readb(0xB4000007);
140     dummy = readb(0xB4000008);
141     dummy = readb(0xB4000007);
142
143     // UAT1
144     writel(0x12121212, IOMUXC_BASE_ADDR + 0x7C);
145     writel(0x12121212, IOMUXC_BASE_ADDR + 0x80);
146
147     // UART2
148     writel(0x13131300, IOMUXC_BASE_ADDR + 0x70);
149     writel(0x00001313, IOMUXC_BASE_ADDR + 0x74);
150     writel(0x00000040, IOMUXC_BASE_ADDR + 0x7C);
151     writel(0x40400000, IOMUXC_BASE_ADDR + 0x78);
152 }
153
154 #include CYGHWR_MEMORY_LAYOUT_H
155
156 typedef void code_fun(void);
157
158 void board_program_new_stack(void *func)
159 {
160     register CYG_ADDRESS stack_ptr asm("sp");
161     register CYG_ADDRESS old_stack asm("r4");
162     register code_fun *new_func asm("r0");
163     old_stack = stack_ptr;
164     stack_ptr = CYGMEM_REGION_ram + CYGMEM_REGION_ram_SIZE - sizeof(CYG_ADDRESS);
165     new_func = (code_fun*)func;
166     new_func();
167     stack_ptr = old_stack;
168 }
169
170 static void display_clock_src(void)
171 {
172     diag_printf("\n");
173     if (g_clock_src == FREQ_27MHZ) {
174         diag_printf("Clock input is 27 MHz");
175     } else if (g_clock_src == FREQ_26MHZ) {
176         diag_printf("Clock input is 26 MHz");
177     } else if (g_clock_src == FREQ_32768HZ) {
178         diag_printf("Clock input is 32KHz");
179     } else {
180         diag_printf("Unknown clock input source. Something is wrong!");
181     }
182 }
183 RedBoot_init(display_clock_src, RedBoot_INIT_LAST);
184
185 // ------------------------------------------------------------------------