]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mx35/3stack/v2_0/src/board_misc.c
Initial revision
[karo-tx-redboot.git] / packages / hal / arm / mx35 / 3stack / 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 static void mxc_fec_setup(void);
66 static void mxc_serial_setup(void);
67
68 void hal_mmu_init(void)
69 {
70     unsigned long ttb_base = RAM_BANK0_BASE + 0x4000;
71     unsigned long i;
72
73     /*
74      * Set the TTB register
75      */
76     asm volatile ("mcr  p15,0,%0,c2,c0,0" : : "r"(ttb_base) /*:*/);
77
78     /*
79      * Set the Domain Access Control Register
80      */
81     i = ARM_ACCESS_DACR_DEFAULT;
82     asm volatile ("mcr  p15,0,%0,c3,c0,0" : : "r"(i) /*:*/);
83
84     /*
85      * First clear all TT entries - ie Set them to Faulting
86      */
87     memset((void *)ttb_base, 0, ARM_FIRST_LEVEL_PAGE_TABLE_SIZE);
88
89     /*              Actual   Virtual  Size   Attributes                                                    Function  */
90     /*              Base     Base     MB     cached?           buffered?        access permissions                 */
91     /*              xxx00000 xxx00000                                                                                */
92     X_ARM_MMU_SECTION(0x000, 0xF00,   0x1,   ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* ROM */
93     X_ARM_MMU_SECTION(0x300, 0x300,   0x1,   ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* L2CC */
94     X_ARM_MMU_SECTION(0x400, 0x400,   0x400, ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* Internal Regsisters upto SDRAM*/
95     X_ARM_MMU_SECTION(0x800, 0x000,   0x80,  ARM_CACHEABLE,   ARM_BUFFERABLE,   ARM_ACCESS_PERM_RW_RW); /* SDRAM 0:128M*/
96     X_ARM_MMU_SECTION(0x800, 0x800,   0x80,  ARM_CACHEABLE,   ARM_BUFFERABLE,   ARM_ACCESS_PERM_RW_RW); /* SDRAM 0:128M*/
97     X_ARM_MMU_SECTION(0x800, 0x880,   0x80,  ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* SDRAM 0:128M*/
98     X_ARM_MMU_SECTION(0xA00, 0xA00,   0x100, ARM_CACHEABLE,   ARM_BUFFERABLE,   ARM_ACCESS_PERM_RW_RW); /* Flash */
99     X_ARM_MMU_SECTION(0xB00, 0xB00,   0x20,  ARM_CACHEABLE,   ARM_BUFFERABLE,   ARM_ACCESS_PERM_RW_RW); /* PSRAM */
100     X_ARM_MMU_SECTION(0xB20, 0xB20,   0x1E0, ARM_UNCACHEABLE, ARM_UNBUFFERABLE,ARM_ACCESS_PERM_RW_RW); /* ESDCTL, WEIM, M3IF, EMI, NFC, External I/O */
101 }
102
103 //
104 // Platform specific initialization
105 //
106
107 unsigned int g_clock_src;
108
109 void plf_hardware_init(void)
110 {
111     unsigned long val = readl(CCM_BASE_ADDR + CLKCTL_CCMR);
112
113     g_clock_src = FREQ_24MHZ;
114     /* PBC setup */
115     /* Reset interrupt status reg */
116     writew(0x1F, PBC_INT_REST);
117     writew(0x00, PBC_INT_REST);
118     writew(0xFFFF, PBC_INT_MASK);
119    
120     mxc_serial_setup();
121     mxc_fec_setup();
122 }
123
124 static void mxc_serial_setup(void)
125 {
126     // UART1
127      /*RXD1*/
128      writel(0, IOMUXC_BASE_ADDR + 0x188);
129      writel(0x1E0, IOMUXC_BASE_ADDR + 0x55C);
130
131      /*TXD1*/
132      writel(0, IOMUXC_BASE_ADDR + 0x18C);
133      writel(0x40, IOMUXC_BASE_ADDR + 0x560);
134
135      /*RTS1*/
136      writel(0, IOMUXC_BASE_ADDR + 0x190);
137      writel(0x1E0, IOMUXC_BASE_ADDR + 0x564);
138
139      /*CTS1*/
140      writel(0, IOMUXC_BASE_ADDR + 0x194);
141      writel(0x40, IOMUXC_BASE_ADDR + 0x568);
142
143     // UART2
144     //writel(0x13131300, IOMUXC_BASE_ADDR + 0x70);
145     //writel(0x00001313, IOMUXC_BASE_ADDR + 0x74);
146     //writel(0x00000040, IOMUXC_BASE_ADDR + 0x7C);
147     //writel(0x40400000, IOMUXC_BASE_ADDR + 0x78);
148 }
149
150 static void mxc_fec_setup(void)
151 {
152         unsigned long val;
153
154         /*FEC_TX_CLK*/
155         writel(0, IOMUXC_BASE_ADDR + 0x02E0);
156         writel(0x1C0, IOMUXC_BASE_ADDR + 0x0744);
157
158         /*FEC_RX_CLK*/
159         writel(0, IOMUXC_BASE_ADDR + 0x02E4);
160         writel(0x1C0, IOMUXC_BASE_ADDR + 0x0748);
161
162         /*FEC_RX_DV*/
163         writel(0, IOMUXC_BASE_ADDR + 0x02E8);
164         writel(0x1C0, IOMUXC_BASE_ADDR + 0x074C);
165
166         /*FEC_COL*/
167         writel(0, IOMUXC_BASE_ADDR + 0x02EC);
168         writel(0x1C0, IOMUXC_BASE_ADDR + 0x0750);
169
170         /*FEC_RDATA0*/
171         writel(0, IOMUXC_BASE_ADDR + 0x02F0);
172         writel(0x1C0, IOMUXC_BASE_ADDR + 0x0754);
173
174         /*FEC_TDATA0*/
175         writel(0, IOMUXC_BASE_ADDR + 0x02F4);
176         writel(0x40, IOMUXC_BASE_ADDR + 0x0758);
177
178         /*FEC_TX_EN*/
179         writel(0, IOMUXC_BASE_ADDR + 0x02F8);
180         writel(0x40, IOMUXC_BASE_ADDR + 0x075C);
181
182         /*FEC_MDC*/
183         writel(0, IOMUXC_BASE_ADDR + 0x02FC);
184         writel(0x40, IOMUXC_BASE_ADDR + 0x0760);
185
186         /*FEC_MDIO*/
187         writel(0, IOMUXC_BASE_ADDR + 0x0300);
188         writel(0x1F0, IOMUXC_BASE_ADDR + 0x0764);
189
190         /*FEC_TX_ERR*/
191         writel(0, IOMUXC_BASE_ADDR + 0x0304);
192         writel(0x40, IOMUXC_BASE_ADDR + 0x0768);
193
194         /*FEC_RX_ERR*/
195         writel(0, IOMUXC_BASE_ADDR + 0x0308);
196         writel(0x1C0, IOMUXC_BASE_ADDR + 0x076C);
197
198         /*FEC_CRS*/
199         writel(0, IOMUXC_BASE_ADDR + 0x030C);
200         writel(0x1C0, IOMUXC_BASE_ADDR + 0x0770);
201
202         /*FEC_RDATA1*/
203         writel(0, IOMUXC_BASE_ADDR + 0x0310);
204         writel(0x1C0, IOMUXC_BASE_ADDR + 0x0774);
205
206         /*FEC_TDATA1*/
207         writel(0, IOMUXC_BASE_ADDR + 0x0314);
208         writel(0x40, IOMUXC_BASE_ADDR + 0x0778);
209
210         /*FEC_RDATA2*/
211         writel(0, IOMUXC_BASE_ADDR + 0x0318);
212         writel(0x1C0, IOMUXC_BASE_ADDR + 0x077C);
213
214         /*FEC_TDATA2*/
215         writel(0, IOMUXC_BASE_ADDR + 0x031C);
216         writel(0x40, IOMUXC_BASE_ADDR + 0x0780);
217
218         /*FEC_RDATA3*/
219         writel(0, IOMUXC_BASE_ADDR + 0x0320);
220         writel(0x1C0, IOMUXC_BASE_ADDR + 0x0784);
221
222         /*FEC_TDATA3*/
223         writel(0, IOMUXC_BASE_ADDR + 0x0324);
224         writel(0x40, IOMUXC_BASE_ADDR + 0x0788);
225
226         /*FEC/UART3 MUX, enable GPIO1_5 output */
227         writel(0, IOMUXC_BASE_ADDR + 0x032C);
228         writel(0x5 , IOMUXC_BASE_ADDR + 0x08);
229         val = readl(GPIO1_BASE_ADDR + 0x04);
230         writel(val | (1 << 5), GPIO1_BASE_ADDR + 0x04);
231         val = readl(GPIO1_BASE_ADDR);
232         writel(val | (1 << 5), GPIO1_BASE_ADDR);
233 }
234
235 static void mxc_cspi_setup(void)
236 {
237         /*CSPI1*/
238         /*SCLK*/
239         writel(0, IOMUXC_BASE_ADDR + 0x180);
240         writel(0x1C0, IOMUXC_BASE_ADDR + 0x5c4);
241         /*SPI_RDY*/
242         writel(0, IOMUXC_BASE_ADDR + 0x184);
243         writel(0x1E0, IOMUXC_BASE_ADDR + 0x5c8);
244         /*MOSI*/
245         writel(0, IOMUXC_BASE_ADDR + 0x170);
246         writel(0x1C0, IOMUXC_BASE_ADDR + 0x5b4);
247         /*MISO*/
248         writel(0, IOMUXC_BASE_ADDR + 0x174);
249         writel(0x1C0, IOMUXC_BASE_ADDR + 0x5b8);
250         /*SS1*/
251         writel(0, IOMUXC_BASE_ADDR + 0x17C);
252         writel(0x1E0, IOMUXC_BASE_ADDR + 0x5C0);
253 }
254
255 void mxc_i2c_init(unsigned int module_base)
256 {
257         switch(module_base) {
258         case I2C_BASE_ADDR:
259                 writel(0x10, IOMUXC_BASE_ADDR + 0x110);
260                 writel(0x10, IOMUXC_BASE_ADDR + 0x114);
261                 writel(0x1E4, IOMUXC_BASE_ADDR + 0x554);
262                 writel(0x1E4, IOMUXC_BASE_ADDR + 0x558);
263                 break;
264         case I2C2_BASE_ADDR:
265         case I2C3_BASE_ADDR:
266         default:
267                 break;
268         }
269 }
270
271 void mxc_mmc_init(base_address)
272 {
273         switch(base_address) {
274         case MMC_SDHC1_BASE_ADDR:
275                 writel (0x1E3, IOMUXC_BASE_ADDR + 0x328 + 224 * 4);
276                 break;
277         default:
278                 break;
279         }
280 }
281
282 #include CYGHWR_MEMORY_LAYOUT_H
283
284 typedef void code_fun(void);
285
286 void board_program_new_stack(void *func)
287 {
288     register CYG_ADDRESS stack_ptr asm("sp");
289     register CYG_ADDRESS old_stack asm("r4");
290     register code_fun *new_func asm("r0");
291     old_stack = stack_ptr;
292     stack_ptr = CYGMEM_REGION_ram + CYGMEM_REGION_ram_SIZE - sizeof(CYG_ADDRESS);
293     new_func = (code_fun*)func;
294     new_func();
295     stack_ptr = old_stack;
296 }
297
298 static void display_clock_src(void)
299 {
300     diag_printf("\n");
301     diag_printf("Clock input is 24 MHz");
302 }
303 RedBoot_init(display_clock_src, RedBoot_INIT_LAST);
304
305 extern unsigned int pmic_reg(unsigned int reg, unsigned int val, unsigned int write);
306 static void fec_power_init(void)
307 {
308         unsigned int val;
309         val = pmic_reg(0x20, 0, 0);
310         hal_delay_us(25);
311         pmic_reg(0x20, val | 0x4, 1);
312 }
313
314 RedBoot_init(fec_power_init, RedBoot_INIT_PRIO(900));
315 // ------------------------------------------------------------------------