]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/xscale/prpmc1100/v2_0/include/hal_platform_setup.h
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / hal / arm / xscale / prpmc1100 / v2_0 / include / hal_platform_setup.h
1 #ifndef CYGONCE_HAL_PLATFORM_SETUP_H
2 #define CYGONCE_HAL_PLATFORM_SETUP_H
3
4 /*=============================================================================
5 //
6 //      hal_platform_setup.h
7 //
8 //      Platform specific support for HAL (assembly code)
9 //
10 //=============================================================================
11 //####ECOSGPLCOPYRIGHTBEGIN####
12 // -------------------------------------------
13 // This file is part of eCos, the Embedded Configurable Operating System.
14 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
15 //
16 // eCos is free software; you can redistribute it and/or modify it under
17 // the terms of the GNU General Public License as published by the Free
18 // Software Foundation; either version 2 or (at your option) any later version.
19 //
20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23 // for more details.
24 //
25 // You should have received a copy of the GNU General Public License along
26 // with eCos; if not, write to the Free Software Foundation, Inc.,
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 //
29 // As a special exception, if other files instantiate templates or use macros
30 // or inline functions from this file, or you compile this file and link it
31 // with other works to produce a work based on this file, this file does not
32 // by itself cause the resulting work to be covered by the GNU General Public
33 // License. However the source code for this file must still be made available
34 // in accordance with section (3) of the GNU General Public License.
35 //
36 // This exception does not invalidate any other reasons why a work based on
37 // this file might be covered by the GNU General Public License.
38 //
39 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
40 // at http://sources.redhat.com/ecos/ecos-license/
41 // -------------------------------------------
42 //####ECOSGPLCOPYRIGHTEND####
43 //=============================================================================
44 //#####DESCRIPTIONBEGIN####
45 //
46 // Author(s):    msalter
47 // Contributors: msalter
48 // Date:         2003-03-27
49 // Purpose:      Motorola PRPMC1100 specific support routines
50 // Description: 
51 // Usage:        #include <cyg/hal/hal_platform_setup.h>
52 //     Only used by "vectors.S"         
53 //
54 //####DESCRIPTIONEND####
55 //
56 //===========================================================================*/
57
58 #include <pkgconf/system.h>             // System-wide configuration info
59 #include CYGBLD_HAL_VARIANT_H           // Variant specific configuration
60 #include CYGBLD_HAL_PLATFORM_H          // Platform specific configuration
61 #include <cyg/hal/hal_ixp425.h>         // Variant specific hardware definitions
62 #include <cyg/hal/hal_mmu.h>            // MMU definitions
63 #include <cyg/hal/hal_mm.h>             // more MMU definitions
64 #include <cyg/hal/prpmc1100.h>          // Platform specific hardware definitions
65
66 #if defined(CYG_HAL_STARTUP_ROM)
67 #define PLATFORM_SETUP1  _platform_setup1
68 #define PLATFORM_EXTRAS  <cyg/hal/hal_platform_extras.h>
69 #define CYGHWR_HAL_ARM_HAS_MMU
70
71 // ------------------------------------------------------------------------
72 // Define macro used to diddle the LEDs during early initialization.
73 // Can use r0+r1.  Argument in \x.
74 #define CYGHWR_LED_MACRO
75
76 // Delay a bit
77 .macro DELAY cycles, reg0
78     ldr     \reg0, =\cycles
79     subs    \reg0, \reg0, #1
80     subne   pc,  pc, #0xc
81 .endm
82
83 // ------------------------------------------------------------------------
84 // This macro represents the initial startup code for the platform        
85         .macro _platform_setup1
86
87 #if CYGINT_HAL_ARM_BIGENDIAN
88         // set big-endian
89         mrc     p15, 0, r0, c1, c0, 0
90         orr     r0, r0, #0x80
91         mcr     p15, 0, r0, c1, c0, 0
92         CPWAIT  r0
93 #endif
94
95         ldr     r0,=(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_SUPERVISOR_MODE)
96         msr     cpsr, r0
97
98         // invalidate I & D caches & BTB
99         mcr     p15, 0, r0, c7, c7, 0
100         CPWAIT  r0
101
102         // invalidate I & Data TLB
103         mcr     p15, 0, r0, c8, c7, 0
104         CPWAIT r0
105
106         // drain write and fill buffers
107         mcr     p15, 0, r0, c7, c10, 4
108         CPWAIT  r0
109
110         // disable write buffer coalescing
111         mrc     p15, 0, r0, c1, c0, 1
112         orr     r0, r0, #1
113         mcr     p15, 0, r0, c1, c0, 1
114         CPWAIT  r0
115                 
116         // Setup chip selects
117         ldr     r1, =IXP425_EXP_CFG_BASE
118 #ifdef IXP425_EXP_CS0_INIT
119         ldr     r0, =IXP425_EXP_CS0_INIT
120         str     r0, [r1, #IXP425_EXP_CS0]
121 #endif
122 #ifdef IXP425_EXP_CS1_INIT
123         ldr     r0, =IXP425_EXP_CS1_INIT
124         str     r0, [r1, #IXP425_EXP_CS1]
125 #endif
126 #ifdef IXP425_EXP_CS2_INIT
127         ldr     r0, =IXP425_EXP_CS2_INIT
128         str     r0, [r1, #IXP425_EXP_CS2]
129 #endif
130 #ifdef IXP425_EXP_CS3_INIT
131         ldr     r0, =IXP425_EXP_CS3_INIT
132         str     r0, [r1, #IXP425_EXP_CS3]
133 #endif
134 #ifdef IXP425_EXP_CS4_INIT
135         ldr     r0, =IXP425_EXP_CS4_INIT
136         str     r0, [r1, #IXP425_EXP_CS4]
137 #endif
138 #ifdef IXP425_EXP_CS5_INIT
139         ldr     r0, =IXP425_EXP_CS5_INIT
140         str     r0, [r1, #IXP425_EXP_CS5]
141 #endif
142 #ifdef IXP425_EXP_CS6_INIT
143         ldr     r0, =IXP425_EXP_CS6_INIT
144         str     r0, [r1, #IXP425_EXP_CS6]
145 #endif
146 #ifdef IXP425_EXP_CS7_INIT
147         ldr     r0, =IXP425_EXP_CS7_INIT
148         str     r0, [r1, #IXP425_EXP_CS7]
149 #endif
150
151         // Enable the Icache
152         mrc     p15, 0, r0, c1, c0, 0
153         orr     r0, r0, #MMU_Control_I
154         mcr     p15, 0, r0, c1, c0, 0
155         CPWAIT  r0
156
157         // Setup SDRAM controller
158
159         ldr     r0, =IXP425_SDRAM_CFG_BASE
160
161         ldr     r1, =IXP425_SDRAM_CONFIG_INIT
162         str     r1, [r0, #IXP425_SDRAM_CONFIG]
163
164         // disable refresh cycles
165         mov     r1, #0
166         str     r1, [r0, #IXP425_SDRAM_REFRESH]
167
168         // send nop command
169         mov     r1, #SDRAM_IR_NOP
170         str     r1, [r0, #IXP425_SDRAM_IR]
171         DELAY   0x10000, r1
172         
173         // set SDRAM internal refresh val
174         ldr     r1, =IXP425_SDRAM_REFRESH_CNT
175         str     r1, [r0, #IXP425_SDRAM_REFRESH]
176         DELAY   0x10000, r1
177
178         // send precharge-all command to close all open banks
179         mov     r1, #SDRAM_IR_PRECHARGE
180         str     r1, [r0, #IXP425_SDRAM_IR]
181         DELAY   0x10000, r1
182
183         // provide 8 auto-refresh cycles
184         mov     r1, #SDRAM_IR_AUTO_REFRESH
185         mov     r2, #8
186   1:
187         str     r1, [r0, #IXP425_SDRAM_IR]
188         DELAY   0x800, r3
189         subs    r2, r2, #1
190         bne     1b
191
192         // set mode register in sdram
193         mov     r1, #IXP425_SDRAM_SET_MODE_CMD
194         str     r1, [r0, #IXP425_SDRAM_IR]
195         DELAY   0x10000, r1
196
197         // start normal operation
198         mov     r1, #SDRAM_IR_NORMAL
199         str     r1, [r0, #IXP425_SDRAM_IR]
200         DELAY   0x10000, r1
201
202         // value to load into pc to jump to real runtime address
203         ldr     r0, =1f
204
205         // Setup EXP_CNFG0 value to switch EXP bus out of low memory
206         ldr     r2, =IXP425_EXP_CFG_BASE
207         ldr     r1, [r2, #IXP425_EXP_CNFG0]
208         bic     r1, r1, #EXP_CNFG0_MEM_MAP
209
210         b       icache_boundary
211         .p2align 5
212 icache_boundary:
213         // Here is where we switch from boot address (0x000000000) to the
214         // actual flash runtime address. We align to cache boundary so we
215         // execute from cache during the switchover. Cachelines are 8 words.
216         str     r1, [r2, #IXP425_EXP_CNFG0]    // make the EXP bus switch
217         nop
218         nop
219         nop
220         nop
221         mov     pc, r0
222         nop
223                             // display FFFF and loop forever.
224     0:  b       0b
225     1:
226
227         // Move mmu tables into RAM so page table walks by the cpu
228         // don't interfere with FLASH programming.
229         ldr     r0, =mmu_table
230         add     r2, r0, #0x4000         // End of tables
231         mov     r1, #SDRAM_PHYS_BASE
232         orr     r1, r1, #0x4000         // RAM tables
233
234         // everything can go as-is
235     1:
236         ldr     r3, [r0], #4
237         str     r3, [r1], #4
238         cmp     r0, r2
239         bne     1b
240
241         mcr     p15, 0, r0, c7, c10, 4  // drain the write & fill buffers
242         CPWAIT  r0
243
244         // Set the TTB register to DRAM mmu_table
245         ldr     r0, =(SDRAM_PHYS_BASE | 0x4000) // RAM tables
246         mcr     p15, 0, r0, c2, c0, 0           // load page table pointer
247         CPWAIT  r0
248
249         // enable permission checks in all domains
250         ldr     r0, =0x55555555
251         mcr     p15, 0, r0, c3, c0, 0
252         CPWAIT  r0
253
254         // enable mmu
255         mrc     p15, 0, r0, c1, c0, 0
256         orr     r0, r0, #MMU_Control_M
257         orr     r0, r0, #MMU_Control_R
258         mcr     p15, 0, r0, c1, c0, 0
259         CPWAIT  r0
260
261         // enable D cache
262         mrc     p15, 0, r0, c1, c0, 0
263         orr     r0, r0, #MMU_Control_C
264         mcr     p15, 0, r0, c1, c0, 0
265         CPWAIT  r0
266
267         // Enable branch target buffer
268         mrc     p15, 0, r0, c1, c0, 0
269         orr     r0, r0, #MMU_Control_BTB
270         mcr     p15, 0, r0, c1, c0, 0
271         CPWAIT  r0
272
273         mcr     p15, 0, r0, c7, c10, 4  // drain the write & fill buffers
274         CPWAIT  r0
275
276         mcr     p15, 0, r0, c7, c7, 0   // flush Icache, Dcache and BTB
277         CPWAIT  r0
278
279         mcr     p15, 0, r0, c8, c7, 0   // flush instuction and data TLBs
280         CPWAIT  r0
281
282         mcr     p15, 0, r0, c7, c10, 4  // drain the write & fill buffers
283         CPWAIT r0       
284         
285         // save SDRAM size
286         ldr     r1, =hal_dram_size  /* [see hal_intr.h] */
287         mov     r8, #SDRAM_SIZE
288         str     r8, [r1]
289
290         .endm    // _platform_setup1
291
292 #else // defined(CYG_HAL_STARTUP_ROM)
293 #define PLATFORM_SETUP1
294 #endif
295
296 #define PLATFORM_VECTORS         _platform_vectors
297         .macro  _platform_vectors
298         .endm                                        
299
300 /*---------------------------------------------------------------------------*/
301 /* end of hal_platform_setup.h                                               */
302 #endif /* CYGONCE_HAL_PLATFORM_SETUP_H */