OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [arm/] [arm9/] [excalibur/] [current/] [include/] [hal_platform_setup.h] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
#ifndef CYGONCE_HAL_PLATFORM_SETUP_H
2
#define CYGONCE_HAL_PLATFORM_SETUP_H
3
//=============================================================================
4
//
5
//      hal_platform_setup.h
6
//
7
//      Platform specific support for HAL (assembly code)
8
//
9
//=============================================================================
10
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
11
// -------------------------------------------                              
12
// This file is part of eCos, the Embedded Configurable Operating System.   
13
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
14
//
15
// eCos is free software; you can redistribute it and/or modify it under    
16
// the terms of the GNU General Public License as published by the Free     
17
// Software Foundation; either version 2 or (at your option) any later      
18
// version.                                                                 
19
//
20
// eCos is distributed in the hope that it will be useful, but WITHOUT      
21
// ANY 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        
26
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
27
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
28
//
29
// As a special exception, if other files instantiate templates or use      
30
// macros or inline functions from this file, or you compile this file      
31
// and link it with other works to produce a work based on this file,       
32
// this file does not by itself cause the resulting work to be covered by   
33
// the GNU General Public License. However the source code for this file    
34
// must still be made available in accordance with section (3) of the GNU   
35
// General Public License v2.                                               
36
//
37
// This exception does not invalidate any other reasons why a work based    
38
// on this file might be covered by the GNU General Public License.         
39
// -------------------------------------------                              
40
// ####ECOSGPLCOPYRIGHTEND####                                              
41
//=============================================================================
42
//#####DESCRIPTIONBEGIN####
43
//
44
// Author(s):    jskov
45
// Contributors: jskov, gthomas
46
// Date:         2001-08-06
47
// Purpose:      ARM9/EXCALIBUR platform specific support routines
48
// Description: 
49
// Usage:        #include <cyg/hal/hal_platform_setup.h>
50
//     Only used by "vectors.S"         
51
//
52
//####DESCRIPTIONEND####
53
//
54
//=============================================================================
55
 
56
#include <pkgconf/system.h>             // System-wide configuration info
57
#include CYGBLD_HAL_VARIANT_H           // Variant specific configuration
58
#include CYGBLD_HAL_PLATFORM_H          // Platform specific configuration
59
#include CYGHWR_MEMORY_LAYOUT_H
60
#include <cyg/hal/hal_mmu.h>            // MMU definitions
61
#include <cyg/hal/excalibur.h>          // Platform specific hardware definitions
62
 
63
#define nDEBUG
64
#define n_ALTERA_CACHEHACK  // doesn't have any apparent effect
65
 
66
#if defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM) || defined(CYG_HAL_STARTUP_REDBOOT)
67
#define PLATFORM_SETUP1 _platform_setup1
68
#define CYGHWR_HAL_ARM_HAS_MMU
69
#define CYGSEM_HAL_ROM_RESET_USES_JUMP
70
 
71
#define CYG_DEVICE_SERIAL_BAUD_DIV (CYGNUM_HAL_ARM_EXCALIBUR_PERIPHERAL_CLOCK/CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD/16)
72
#define CYG_DEVICE_SERIAL_BAUD_LSB (CYG_DEVICE_SERIAL_BAUD_DIV&0xff)
73
#define CYG_DEVICE_SERIAL_BAUD_MSB ((CYG_DEVICE_SERIAL_BAUD_DIV>>8)&0xff)
74
 
75
// We need this here - can't rely on a translation table until MMU has
76
// been initialized
77
        .macro RAW_LED_MACRO x
78
#ifdef DEBUG
79
        ldr     r0,=(EXCALIBUR_UART0_BASE+_UART_TD)
80
        mov     r1,#(\x + 0x41)
81
        str     r1,[r0]
82
#endif
83
        .endm
84
 
85
// This macro represents the initial startup code for the platform        
86
        .macro  _platform_setup1
87
        // IO controller init
88
        ldr     r1,=EXCALIBUR_IOCR_BASE
89
        ldr     r2,=EXCALIBUR_IOCR_SDRAM_INIT
90
        str     r2,[r1,#_IOCR_SDRAM]
91
        ldr     r2,=EXCALIBUR_IOCR_EBI_INIT
92
        str     r2,[r1,#_IOCR_EBI]
93
        ldr     r2,=EXCALIBUR_IOCR_UART_INIT
94
        str     r2,[r1,#_IOCR_UART]
95
 
96
        // Expansion bus init
97
        ldr     r1,=EXCALIBUR_EBI_CR
98
        ldr     r2,=EXCALIBUR_EBI_CR_INIT
99
        str     r2,[r1]
100
 
101
#ifdef DEBUG
102
        // Init UART for debug tracing
103
        ldr     r4,=EXCALIBUR_UART0_BASE
104
        ldr     r2,=(_UART_MC_8BIT | _UART_MC_1STOP | _UART_MC_PARITY_NONE)
105
        str     r2,[r4,#_UART_MC]
106
        ldr     r2,=CYG_DEVICE_SERIAL_BAUD_LSB
107
        str     r2,[r4,#_UART_DIV_LO]
108
        ldr     r2,=CYG_DEVICE_SERIAL_BAUD_MSB
109
        str     r2,[r4,#_UART_DIV_HI]
110
        ldr     r2,=(_UART_FCR_TC | _UART_FCR_RC | _UART_FCR_TX_THR_15 | _UART_FCR_RX_THR_1)
111
        str     r2,[r4,#_UART_FCR]
112
#endif
113
 
114
        // Setup the PLLs see the label PLL_ADDR below for the input
115
        // clock frequency and the desired output frequencies of PLL1
116
        // and PLL2 Load the value into K,M,N for PLL 1 and 2
117
        adr     r0,2f
118
        ldmia   r0,{r0-r11}
119
        str     r6,[r0]
120
        str     r7,[r1]
121
        str     r8,[r2]
122
        str     r9,[r3]
123
        str     r10,[r4]
124
        str     r11,[r5]
125
 
126
        // Turn on the PLLs
127
        ldr     r3,=EXCALIBUR_CLK_BASE
128
        ldr     r1,=(0x1035 | _CLK_PLL1_CTRL_P)
129
        str     r1,[r3, #_CLK_PLL1_CTRL]
130
        str     r1,[r3, #_CLK_PLL2_CTRL]
131
 
132
        // Ensure the PLLs are not in bypass
133
        ldr     r1,=(0x10 | _CLK_DERIVE_BP1 | _CLK_DERIVE_BP2)
134
        str     r1,[r3, #_CLK_DERIVE]
135
        orr     r1,r1,#0x300 /* Use PLL2 for AHB and for the SDRAM */
136
        str     r1,[r3, #_CLK_DERIVE]
137
        ldr     r2,=(_CLK_DERIVE_BP1 | _CLK_DERIVE_BP2)
138
        bic     r1,r1,r2
139
        str     r1,[r3, #_CLK_DERIVE]
140
 
141
        // Poll waiting for the PLL's to lock and the bits to not be
142
        // in bypass mode
143
        ldr     r2,=_CLK_STATUS_L2 /*_CLK_STATUS_L1 | _CLK_STATUS_L2*/
144
1:      ldr     r1, [r3, #_CLK_STATUS]
145
        and     r1, r1, r2
146
        cmp     r1, r2
147
        bne     1b
148
 
149
        // Clear the interrupt caused by the change in lock status
150
        ldr     r2, =(_CLK_STATUS_C1 | _CLK_STATUS_C2)
151
        str     r2, [r3, #_CLK_STATUS]
152
 
153
        b       3f
154
 
155
        // PLL Registers Addresses
156
2:      .long EXCALIBUR_CLK_BASE+_CLK_PLL1_KCNT
157
        .long EXCALIBUR_CLK_BASE+_CLK_PLL1_MCNT
158
        .long EXCALIBUR_CLK_BASE+_CLK_PLL1_NCNT
159
        .long EXCALIBUR_CLK_BASE+_CLK_PLL2_KCNT
160
        .long EXCALIBUR_CLK_BASE+_CLK_PLL2_MCNT
161
        .long EXCALIBUR_CLK_BASE+_CLK_PLL2_NCNT
162
        // PLL Registers Values ensure this follows on from the
163
        // addresses the code depends on it
164
        .long 0x40000 // CLK_PLL1_KCNT_VAL  = 1
165
        .long 0x20101 // CLK_PLL1_MCNT_VAL  = 2
166
        .long 0x40000 // CLK_PLL1_NCNT_VAL  = 1
167
        .long 0x40000 // CLK_PLL2_KCNT_VAL  = 1
168
        .long 0x20303 // CLK_PLL2_MCNT_VAL  = 6
169
        .long 0x40000 // CLK_PLL2_NCNT_VAL  = 1
170
3:
171
 
172
        RAW_LED_MACRO 0
173
 
174
        // Jump to ROM
175
        ldr     r1,=(EXCALIBUR_MMAP_BASE + _MMAP_EBI0)
176
        ldr     r2,=_MMAP_EBI0_INIT
177
        str     r2,[r1]
178
        ldr     r1,=CYGMEM_REGION_rom
179
        add     pc,pc,r1
180
        nop
181
        nop
182
 
183
        // Disable ROM mapping
184
        ldr     r1,=EXCALIBUR_BOOT_CR
185
        ldr     r2,=EXCALIBUR_BOOT_CR_BM
186
        str     r2,[r1]
187
 
188
        RAW_LED_MACRO 1
189
 
190
        // Disable and clear caches
191
 
192
        mrc  p15,0,r0,c1,c0,0
193
        bic  r0,r0,#0x1000              // disable ICache
194
        bic  r0,r0,#0x0007              // disable DCache,
195
                                        // MMU and alignment faults
196
        mcr  p15,0,r0,c1,c0,0
197
        nop
198
        nop
199
        nop
200
        nop
201
        nop
202
        nop
203
        nop
204
        nop
205
        mov  r0,#0
206
        mcr  p15,0,r0,c7,c6,0           // clear data cache
207
        mcr  p15,0,r0,c7,c5,0           // clear instruction cache
208
 
209
#if 0
210
        mrc  p15,0,r0,c15,c1,0          // disable streaming
211
        orr  r0,r0,#0x80
212
        mcr  p15,0,r0,c15,c1,0
213
#endif
214
 
215
        RAW_LED_MACRO 2
216
 
217
        // Set memory mapping
218
        ldr     r1,=EXCALIBUR_MMAP_BASE
219
        ldr     r2,=_MMAP_REGISTERS_INIT
220
        str     r2,[r1,#_MMAP_REGISTERS]
221
        ldr     r2,=_MMAP_SRAM0_INIT
222
        str     r2,[r1,#_MMAP_SRAM0]
223
        ldr     r2,=_MMAP_SRAM1_INIT
224
        str     r2,[r1,#_MMAP_SRAM1]
225
        ldr     r2,=_MMAP_DPSRAM0_INIT
226
        str     r2,[r1,#_MMAP_DPSRAM0]
227
        ldr     r2,=_MMAP_DPSRAM1_INIT
228
        str     r2,[r1,#_MMAP_DPSRAM1]
229
        ldr     r2,=_MMAP_SDRAM0_INIT
230
        str     r2,[r1,#_MMAP_SDRAM0]
231
        ldr     r2,=_MMAP_SDRAM1_INIT
232
        str     r2,[r1,#_MMAP_SDRAM1]
233
        ldr     r2,=_MMAP_PLD0_INIT
234
        str     r2,[r1,#_MMAP_PLD0]
235
        ldr     r2,=_MMAP_PLD1_INIT
236
        str     r2,[r1,#_MMAP_PLD1]
237
        ldr     r2,=_MMAP_PLD2_INIT
238
        str     r2,[r1,#_MMAP_PLD2]
239
        ldr     r2,=_MMAP_PLD3_INIT
240
        str     r2,[r1,#_MMAP_PLD3]
241
        ldr     r2,=_MMAP_EBI1_INIT
242
        str     r2,[r1,#_MMAP_EBI1]
243
        ldr     r2,=_MMAP_EBI2_INIT
244
        str     r2,[r1,#_MMAP_EBI2]
245
        ldr     r2,=_MMAP_EBI3_INIT
246
        str     r2,[r1,#_MMAP_EBI3]
247
 
248
        RAW_LED_MACRO 3
249
 
250
        // FIXME: Disable MMAP registers?
251
 
252
        RAW_LED_MACRO 4
253
 
254
        // DPSRAM init
255
        ldr     r2,=EXCALIBUR_DPSRAM_BASE
256
        ldr     r1,=_DPSRAM0_LCR_INIT
257
        str     r1,[r2,#_DPSRAM0_LCR]
258
        ldr     r1,=_DPSRAM1_LCR_INIT
259
        str     r1,[r2,#_DPSRAM1_LCR]
260
 
261
        RAW_LED_MACRO 5
262
 
263
#ifdef _ALTERA_CACHEHACK
264
        mrc     p15,0,r0,c1,c0,0
265
        orr     r0,r0,#0x1000              // enable ICache
266
        mcr     p15,0,r0,c1,c0,0
267
        nop
268
        nop
269
        nop
270
        nop
271
        nop
272
        nop
273
        nop
274
        nop
275
#endif //  _ALTERA_CACHEHACK
276
 
277
        //  Setup the SDR
278
 
279
        // All the clock values below assume the SDR is running @ 100 MHz
280
 
281
        // 1. Wait for the PLL's to lock this was already done in
282
        // Setup_plls Then wait another 100uS, which given we're
283
        // running @ 150MHz is 15,000 clock cycles
284
        mov     r3,#0x3b00 // (15104)
285
1:      subs    r3,r3,#1
286
        bne     1b
287
 
288
 
289
        // 2. Set up all the SDRAM Controllers configuration settings
290
        // These are done using LDMIA's as it's more efficient, they're
291
        // done in the order they appear in the datasheet with the
292
        // exception of SDRAM_INIT which has to be written last
293
 
294
        // Load the address of the first seven SDRAM registers and the
295
        // contents
296
        adr     r0,SDRAM_REGS_ADDR
297
        ldmia   r0,{r0-r5}
298
 
299
        adr     r6,SDRAM_REGS_VALUE
300
        ldmia   r6,{r6-r11}
301
        str     r6,[r0]
302
        str     r7,[r1]
303
        str     r8,[r2]
304
        str     r9,[r3]
305
        str     r10,[r4]
306
        str     r11,[r5]
307
 
308
        ldr     r11,=EXCALIBUR_SDRAM_BASE
309
        ldr     r0,=EXCALIBUR_SDRAM_WIDTH
310
        ldr     r1,=(_SDRAM_WIDTH_W | _SDRAM_WIDTH_LK)  /* 32 bit wide */
311
        str     r1,[r0]
312
 
313
#ifdef _ALTERA_CACHEHACK
314
        // OK we have a minor "feature/bug" in the chip which requires
315
        // us to be a little clever now.  The code between the labels
316
        // Cache_Start and Cache_stop starts the SDRAM controller and
317
        // issues the pre_charge command
318
 
319
        // It must execute within one refresh period, so we must load
320
        // this code and the code it calls (Issue_SDRAM_Command) into
321
        // cache, as typical flashes have a cycle time of ~100nS If we
322
        // are doing byte loads that's ~400ns per instruction.  Depending
323
        // upon the size of the DDR the refresh period can be as low as
324
        // 7us (smallest we found).
325
        adr     r1,SDR_Cache_Start
326
        adr     r2,SDR_Cache_Stop
327
        adr     r3,Issue_SDRAM_Command
328
        adr     r4,End_Issue_SDRAM_Command
329
 
330
SDR_Load_Code:
331
        mcr     p15,0,r1,c7,c13,1
332
        add     r1,r1,#32
333
        cmp     r1,r2
334
        ble     SDR_Load_Code
335
 
336
SDR_Load_Code2:
337
        mcr     p15,0,r3,c7,c13,1
338
        add     r3,r3,#32
339
        cmp     r3,r4
340
        ble     SDR_Load_Code2
341
#endif // _ALTERA_CACHEHACK
342
 
343
        // setup the timer for later
344
        ldr     r4,=EXCALIBUR_TIMER0_LIMIT
345
        mvn     r5, #1
346
        str     r5, [r4]
347
 
348
        ldr     r4,=_SDRAM_INIT_PR
349
        ldr     r5,=_SDRAM_INIT_RF
350
        ldr     r6,=_SDRAM_INIT_LM
351
        ldr     r9,=EXCALIBUR_TIMER0_READ
352
        ldr     r10,=EXCALIBUR_TIMER0_CR
353
 
354
        // Enable the controller by setting the EN bit in the
355
        // SDRAM_INIT register
356
        mov     r1,#_SDRAM_INIT_EN
357
SDR_Cache_Start:
358
        str     r1,[r11, #_SDRAM_INIT]
359
 
360
        // Short delay
361
        mov     r3, #EXCALIBUR_TIMER_CR_S
362
        str     r3, [r10]
363
        ldr     r3, [r9]
364
        add     r3,r3,#200 
365
short_delay:
366
        ldr     r8, [r9]
367
        cmp     r3, r8
368
        bgt     short_delay
369
        mov     r3, #0
370
        str     r3, [r10]
371
 
372
        // 4. Issue pre-charge all command
373
        mov     r1,r4
374
        bl      Issue_SDRAM_Command
375
 
376
        // 5. Issue two Refresh Commands
377
        mov     r1, r5
378
        mov     r4,#2
379
SDR_RF_Command:
380
        bl      Issue_SDRAM_Command
381
        subs    r4,r4,#1
382
        bne     SDR_RF_Command
383
 
384
        // 6. Issue a load mode command with the DLL being Reset
385
        mov     r1, r6
386
        bl      Issue_SDRAM_Command
387
 
388
SDR_Cache_Stop:
389
        b        10f
390
 
391
 
392
        //--------------------------------------------
393
        // Issue a command from the SDRAM controller
394
        // Assumes:
395
        // r1 is the command to be issued
396
        // r2 and r3 are trashed
397
Issue_SDRAM_Command:
398
        mov     r2,#_SDRAM_INIT_EN
399
        orr     r2,r2,r1
400
        str     r2,[r11, #_SDRAM_INIT]
401
 
402
        // OK chip bug, the busy bit does not work properly, so we need
403
        // to insert a delay of 50 SDRAM clock cycles here NB Obviously
404
        // this must change when either the SDRAM clock or the processor
405
        // clock change
406
        ldr     r2,=(EXCALIBUR_CLK_BASE+_CLK_AHB1_COUNT)
407
        ldr     r3, [r2]
408
        add     r3,r3,#200 // CPU 150 MHz SDRAM 75 MHz
409
clock_cycles:
410
        ldr     r8, [r2]
411
        cmp     r3, r8
412
        bgt     clock_cycles
413
        mov     pc, lr
414
End_Issue_SDRAM_Command:
415
 
416
 
417
        // SDRAM Register Addresses
418
SDRAM_REGS_ADDR:
419
        .long EXCALIBUR_SDRAM_BASE+_SDRAM_TIMING1
420
        .long EXCALIBUR_SDRAM_BASE+_SDRAM_TIMING2
421
        .long EXCALIBUR_SDRAM_BASE+_SDRAM_CONFIG
422
        .long EXCALIBUR_SDRAM_BASE+_SDRAM_REFRESH
423
        .long EXCALIBUR_SDRAM_BASE+_SDRAM_ADDR
424
        .long EXCALIBUR_SDRAM_BASE+_SDRAM_MODE0
425
        .long EXCALIBUR_SDRAM_BASE+_SDRAM_MODE1
426
 
427
SDRAM_REGS_VALUE:
428
        .long 0x00004892 /* SDRAM_TIMING1_VAL */
429
        .long 0x000007b0 /* SDRAM_TIMING2_VAL */
430
        .long 0x00000000 /* DDR */
431
        .long 0x00000492 /* SDRAM_REFRESH_VAL */
432
        .long 0x0000Ca80 /* SDRAM_ADDR_VAL */
433
        .long 0x00000023 /* SDRAM_MODE0_VAL */
434
        .long 0x00000000 /* SDRAM_MODE1_VAL */
435
10:
436
#ifdef _ALTERA_CACHEHACK
437
        mrc     p15,0,r0,c1,c0,0
438
        bic     r0,r0,#0x1000              // disable ICache
439
        mcr     p15,0,r0,c1,c0,0
440
        nop
441
        nop
442
        nop
443
        nop
444
        nop
445
        nop
446
        nop
447
        nop
448
#endif // _ALTERA_CACHEHACK
449
 
450
        RAW_LED_MACRO 6
451
 
452
#if defined(CYG_HAL_STARTUP_ROMRAM) || defined(CYG_HAL_STARTUP_REDBOOT)
453
        ldr     r0,=__rom_vectors_lma   // Relocate FLASH/ROM to SDRAM
454
        ldr     r1,=__rom_vectors_vma   // ram base & length
455
        ldr     r2,=__ram_data_end
456
20:     ldr     r3,[r0],#4
457
        str     r3,[r1],#4
458
        cmp     r1,r2
459
        bne     20b
460
        ldr     r0,=30f
461
        nop
462
        mov     pc,r0
463
        nop
464
30:     nop
465
#endif
466
 
467
        RAW_LED_MACRO 7
468
 
469
        // Set up a stack [for calling C code]
470
        ldr     r1,=__startup_stack
471
        ldr     r2,=EXCALIBUR_SDRAM_PHYS_BASE
472
        orr     sp,r1,r2
473
 
474
        // Create MMU tables
475
        bl      hal_mmu_init
476
 
477
        RAW_LED_MACRO 8
478
 
479
        // Enable MMU
480
        ldr     r2,=10f
481
        ldr     r1,=MMU_Control_Init|MMU_Control_M
482
        mcr     MMU_CP,0,r1,MMU_Control,c0
483
        mov     pc,r2    // Change address spaces
484
        nop
485
        nop
486
        nop
487
10:
488
 
489
        RAW_LED_MACRO 9
490
        .endm
491
 
492
#else // defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM) || defined(CYG_HAL_STARTUP_REDBOOT)
493
#define PLATFORM_SETUP1
494
#endif
495
 
496
//-----------------------------------------------------------------------------
497
#ifdef DEBUG
498
#define CYGHWR_LED_MACRO                                \
499
        ldr     r0,=(EXCALIBUR_UART0_BASE+_UART_TD);    \
500
        mov     r1,#((\x) + 0x61);                      \
501
        str     r1,[r0];
502
#endif
503
 
504
//-----------------------------------------------------------------------------
505
// end of hal_platform_setup.h
506
#endif // CYGONCE_HAL_PLATFORM_SETUP_H

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.