]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/xscale/prpmc1100/v2_0/include/hal_platform_setup.h
Initial revision
[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 #if 0
79     ldr     \reg0, =\cycles
80     subs    \reg0, \reg0, #1
81     subne   pc,  pc, #0xc
82 #endif
83 .endm
84
85 // ------------------------------------------------------------------------
86 // This macro represents the initial startup code for the platform        
87         .macro _platform_setup1
88
89 #if CYGINT_HAL_ARM_BIGENDIAN
90         // set big-endian
91         mrc     p15, 0, r0, c1, c0, 0
92         orr     r0, r0, #0x80
93         mcr     p15, 0, r0, c1, c0, 0
94         CPWAIT  r0
95 #endif
96
97         ldr     r0,=(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_SUPERVISOR_MODE)
98         msr     cpsr, r0
99
100         // invalidate I & D caches & BTB
101         mcr     p15, 0, r0, c7, c7, 0
102         CPWAIT  r0
103
104         // invalidate I & Data TLB
105         mcr     p15, 0, r0, c8, c7, 0
106         CPWAIT r0
107
108         // drain write and fill buffers
109         mcr     p15, 0, r0, c7, c10, 4
110         CPWAIT  r0
111
112         // disable write buffer coalescing
113         mrc     p15, 0, r0, c1, c0, 1
114         orr     r0, r0, #1
115         mcr     p15, 0, r0, c1, c0, 1
116         CPWAIT  r0
117                 
118         // Setup chip selects
119         ldr     r1, =IXP425_EXP_CFG_BASE
120 #ifdef IXP425_EXP_CS0_INIT
121         ldr     r0, =IXP425_EXP_CS0_INIT
122         str     r0, [r1, #IXP425_EXP_CS0]
123 #endif
124 #ifdef IXP425_EXP_CS1_INIT
125         ldr     r0, =IXP425_EXP_CS1_INIT
126         str     r0, [r1, #IXP425_EXP_CS1]
127 #endif
128 #ifdef IXP425_EXP_CS2_INIT
129         ldr     r0, =IXP425_EXP_CS2_INIT
130         str     r0, [r1, #IXP425_EXP_CS2]
131 #endif
132 #ifdef IXP425_EXP_CS3_INIT
133         ldr     r0, =IXP425_EXP_CS3_INIT
134         str     r0, [r1, #IXP425_EXP_CS3]
135 #endif
136 #ifdef IXP425_EXP_CS4_INIT
137         ldr     r0, =IXP425_EXP_CS4_INIT
138         str     r0, [r1, #IXP425_EXP_CS4]
139 #endif
140 #ifdef IXP425_EXP_CS5_INIT
141         ldr     r0, =IXP425_EXP_CS5_INIT
142         str     r0, [r1, #IXP425_EXP_CS5]
143 #endif
144 #ifdef IXP425_EXP_CS6_INIT
145         ldr     r0, =IXP425_EXP_CS6_INIT
146         str     r0, [r1, #IXP425_EXP_CS6]
147 #endif
148 #ifdef IXP425_EXP_CS7_INIT
149         ldr     r0, =IXP425_EXP_CS7_INIT
150         str     r0, [r1, #IXP425_EXP_CS7]
151 #endif
152
153         // Enable the Icache
154         mrc     p15, 0, r0, c1, c0, 0
155         orr     r0, r0, #MMU_Control_I
156         mcr     p15, 0, r0, c1, c0, 0
157         CPWAIT  r0
158
159         // Setup SDRAM controller
160
161         ldr     r0, =IXP425_SDRAM_CFG_BASE
162
163         ldr     r1, =IXP425_SDRAM_CONFIG_INIT
164         str     r1, [r0, #IXP425_SDRAM_CONFIG]
165
166         // disable refresh cycles
167         mov     r1, #0
168         str     r1, [r0, #IXP425_SDRAM_REFRESH]
169
170         // send nop command
171         mov     r1, #SDRAM_IR_NOP
172         str     r1, [r0, #IXP425_SDRAM_IR]
173         DELAY   0x10000, r1
174         
175         // set SDRAM internal refresh val
176         ldr     r1, =IXP425_SDRAM_REFRESH_CNT
177         str     r1, [r0, #IXP425_SDRAM_REFRESH]
178         DELAY   0x10000, r1
179
180         // send precharge-all command to close all open banks
181         mov     r1, #SDRAM_IR_PRECHARGE
182         str     r1, [r0, #IXP425_SDRAM_IR]
183         DELAY   0x10000, r1
184
185         // provide 8 auto-refresh cycles
186         mov     r1, #SDRAM_IR_AUTO_REFRESH
187         mov     r2, #8
188   1:
189         str     r1, [r0, #IXP425_SDRAM_IR]
190         DELAY   0x800, r3
191         subs    r2, r2, #1
192         bne     1b
193
194         // set mode register in sdram
195         mov     r1, #IXP425_SDRAM_SET_MODE_CMD
196         str     r1, [r0, #IXP425_SDRAM_IR]
197         DELAY   0x10000, r1
198
199         // start normal operation
200         mov     r1, #SDRAM_IR_NORMAL
201         str     r1, [r0, #IXP425_SDRAM_IR]
202         DELAY   0x10000, r1
203
204         // value to load into pc to jump to real runtime address
205         ldr     r0, =1f
206
207         // Setup EXP_CNFG0 value to switch EXP bus out of low memory
208         ldr     r2, =IXP425_EXP_CFG_BASE
209         ldr     r1, [r2, #IXP425_EXP_CNFG0]
210         bic     r1, r1, #EXP_CNFG0_MEM_MAP
211
212         b       icache_boundary
213         .p2align 5
214 icache_boundary:
215         // Here is where we switch from boot address (0x000000000) to the
216         // actual flash runtime address. We align to cache boundary so we
217         // execute from cache during the switchover. Cachelines are 8 words.
218         str     r1, [r2, #IXP425_EXP_CNFG0]    // make the EXP bus switch
219         nop
220         nop
221         nop
222         nop
223         mov     pc, r0
224         nop
225                             // display FFFF and loop forever.
226     0:  b       0b
227     1:
228
229         // Move mmu tables into RAM so page table walks by the cpu
230         // don't interfere with FLASH programming.
231         ldr     r0, =mmu_table
232         add     r2, r0, #0x4000         // End of tables
233         mov     r1, #SDRAM_PHYS_BASE
234         orr     r1, r1, #0x4000         // RAM tables
235
236         // everything can go as-is
237     1:
238         ldr     r3, [r0], #4
239         str     r3, [r1], #4
240         cmp     r0, r2
241         bne     1b
242
243         mcr     p15, 0, r0, c7, c10, 4  // drain the write & fill buffers
244         CPWAIT  r0
245
246         // Set the TTB register to DRAM mmu_table
247         ldr     r0, =(SDRAM_PHYS_BASE | 0x4000) // RAM tables
248         mcr     p15, 0, r0, c2, c0, 0           // load page table pointer
249         CPWAIT  r0
250
251         // enable permission checks in all domains
252         ldr     r0, =0x55555555
253         mcr     p15, 0, r0, c3, c0, 0
254         CPWAIT  r0
255
256         // enable mmu
257         mrc     p15, 0, r0, c1, c0, 0
258         orr     r0, r0, #MMU_Control_M
259         orr     r0, r0, #MMU_Control_R
260         mcr     p15, 0, r0, c1, c0, 0
261         CPWAIT  r0
262
263         // enable D cache
264         mrc     p15, 0, r0, c1, c0, 0
265         orr     r0, r0, #MMU_Control_C
266         mcr     p15, 0, r0, c1, c0, 0
267         CPWAIT  r0
268
269         // Enable branch target buffer
270         mrc     p15, 0, r0, c1, c0, 0
271         orr     r0, r0, #MMU_Control_BTB
272         mcr     p15, 0, r0, c1, c0, 0
273         CPWAIT  r0
274
275         mcr     p15, 0, r0, c7, c10, 4  // drain the write & fill buffers
276         CPWAIT  r0
277
278         mcr     p15, 0, r0, c7, c7, 0   // flush Icache, Dcache and BTB
279         CPWAIT  r0
280
281         mcr     p15, 0, r0, c8, c7, 0   // flush instuction and data TLBs
282         CPWAIT  r0
283
284         mcr     p15, 0, r0, c7, c10, 4  // drain the write & fill buffers
285         CPWAIT r0       
286         
287         // save SDRAM size
288         ldr     r1, =hal_dram_size  /* [see hal_intr.h] */
289         mov     r8, #SDRAM_SIZE
290         str     r8, [r1]
291
292         .endm    // _platform_setup1
293
294 #else // defined(CYG_HAL_STARTUP_ROM)
295 #define PLATFORM_SETUP1
296 #endif
297
298 #define PLATFORM_VECTORS         _platform_vectors
299         .macro  _platform_vectors
300         .endm                                        
301
302 /*---------------------------------------------------------------------------*/
303 /* end of hal_platform_setup.h                                               */
304 #endif /* CYGONCE_HAL_PLATFORM_SETUP_H */