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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [arm/] [sa11x0/] [brutus/] [v2_0/] [include/] [hal_platform_setup.h] - Blame information for rev 565

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
#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 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):    gthomas
47
// Contributors: gthomas
48
//               Travis C. Furrer <furrer@mit.edu>
49
// Date:         2000-05-08
50
// Purpose:      Intel SA1110/Assabet platform specific support routines
51
// Description:
52
// Usage:        #include <cyg/hal/hal_platform_setup.h>
53
//     This file should only be used by "vectors.S"
54
//
55
//####DESCRIPTIONEND####
56
//
57
//===========================================================================*/
58
 
59
#include <pkgconf/system.h>             // System-wide configuration info
60
#include CYGBLD_HAL_PLATFORM_H          // Platform specific configuration
61
#include <cyg/hal/hal_sa11x0.h>         // Platform specific hardware definitions
62
#include <cyg/hal/hal_mmu.h>            // MMU definitions
63
 
64
#if defined(CYG_HAL_STARTUP_ROM)
65
#define PLATFORM_SETUP1 _platform_setup1
66
#define CYGHWR_HAL_ARM_HAS_MMU
67
 
68
#if (CYGHWR_HAL_ARM_SA11X0_PROCESSOR_CLOCK == 59000)
69
#define SA11X0_PLL_CLOCK 0x0        
70
#elif (CYGHWR_HAL_ARM_SA11X0_PROCESSOR_CLOCK == 73700)
71
#define SA11X0_PLL_CLOCK 0x1
72
#elif (CYGHWR_HAL_ARM_SA11X0_PROCESSOR_CLOCK == 88500)
73
#define SA11X0_PLL_CLOCK 0x2        
74
#elif (CYGHWR_HAL_ARM_SA11X0_PROCESSOR_CLOCK == 103200) 
75
#define SA11X0_PLL_CLOCK 0x3        
76
#elif (CYGHWR_HAL_ARM_SA11X0_PROCESSOR_CLOCK == 118000)
77
#define SA11X0_PLL_CLOCK 0x4        
78
#elif (CYGHWR_HAL_ARM_SA11X0_PROCESSOR_CLOCK == 132700)
79
#define SA11X0_PLL_CLOCK 0x5        
80
#elif (CYGHWR_HAL_ARM_SA11X0_PROCESSOR_CLOCK == 147500)
81
#define SA11X0_PLL_CLOCK 0x6        
82
#elif (CYGHWR_HAL_ARM_SA11X0_PROCESSOR_CLOCK == 162200)
83
#define SA11X0_PLL_CLOCK 0x7        
84
#elif (CYGHWR_HAL_ARM_SA11X0_PROCESSOR_CLOCK == 176900)
85
#define SA11X0_PLL_CLOCK 0x8        
86
#elif (CYGHWR_HAL_ARM_SA11X0_PROCESSOR_CLOCK == 191700)
87
#define SA11X0_PLL_CLOCK 0x9        
88
#elif (CYGHWR_HAL_ARM_SA11X0_PROCESSOR_CLOCK == 206400)
89
#define SA11X0_PLL_CLOCK 0xA        
90
#elif (CYGHWR_HAL_ARM_SA11X0_PROCESSOR_CLOCK == 221200)
91
#define SA11X0_PLL_CLOCK 0xB        
92
#else
93
#error Invalid processor clock speed
94
#endif
95
 
96
// This function is called very early on by the boot ROM (or by any ROM
97
// based startup).  It's job is to initialize the hardware to a known state
98
// so that eCos applications can execute properly.
99
 
100
// This version of the code is patterned after the contribution from
101
// Travis Furer (@MIT)                
102
 
103
 
104
// Define macro used to diddle the LEDs during early initialization.
105
// Can use r0+r1.  Argument in \x.
106
 
107
#define CYGHWR_LED_MACRO _set_LEDS(\x)
108
 
109
// Initialize GPIOs
110
#define GPIO_GRER (SA11X0_GPIO_RISING_EDGE_DETECT-SA11X0_GPIO_PIN_LEVEL)
111
#define GPIO_GFER (SA11X0_GPIO_FALLING_EDGE_DETECT-SA11X0_GPIO_PIN_LEVEL)
112
#define GPIO_GAFR (SA11X0_GPIO_ALTERNATE_FUNCTION-SA11X0_GPIO_PIN_LEVEL)
113
#define GPIO_GEDR (SA11X0_GPIO_EDGE_DETECT_STATUS-SA11X0_GPIO_PIN_LEVEL)
114
#define GPIO_GPDR (SA11X0_GPIO_PIN_DIRECTION-SA11X0_GPIO_PIN_LEVEL)
115
#define GPIO_GPCR (SA11X0_GPIO_PIN_OUTPUT_CLEAR-SA11X0_GPIO_PIN_LEVEL)
116
        .macro  _init_GPIO
117
        ldr     r1,=SA11X0_GPIO_PIN_LEVEL
118
        mov     r0,#0           
119
        str     r0,[r1,#GPIO_GRER]      // Disable rising edge detects
120
        str     r0,[r1,#GPIO_GFER]      // Disable falling edge detects
121
        str     r0,[r1,#GPIO_GAFR]      // No alt. funcs. during init
122
        sub     r0,r0,#1        
123
        str     r0,[r1,#GPIO_GPCR]      // Force all outputs to low
124
        str     r0,[r1,#GPIO_GEDR]      // Clear edge detect status
125
        ldr     r0,=0x00100300
126
        str     r0,[r1,#GPIO_GPDR]      // Only LEDs outputs (for now)
127
        .endm
128
 
129
// Initialize HEX display.
130
#define MCP_STAT  (SA11X0_MCP_STATUS-SA11X0_MCP_CONTROL_0)        
131
#define MCP_CTRL0 (SA11X0_MCP_CONTROL_0-SA11X0_MCP_CONTROL_0)        
132
#define MCP_DATA2 (SA11X0_MCP_DATA_2-SA11X0_MCP_CONTROL_0)        
133
        .macro  _init_HEX_DISPLAY
134
        ldr     r1, =SA11X0_MCP_CONTROL_0
135
        ldr     r2, =0xFFFFFFFF
136
        str     r2, [r1, #MCP_STAT]
137
        ldr     r2, =0x801F
138
        orr     r2, r2, #(3 << 16)
139
        str     r2, [r1, #MCP_DATA2]
140
        ldr     r2, =0x50000
141
        str     r2, [r1, #MCP_CTRL0]
142
        .endm
143
 
144
// Display value on hex LED display
145
        .macro  _set_LEDS,val
146
        mov     r0,#\val
147
        orr     r0,r0,#(1<<16)
148
        ldr     r1,=SA11X0_MCP_DATA_2
149
        str     r0,[r1]
150
        .endm
151
 
152
// Setup pin directions:
153
//  inputs: all serial receive pins
154
// outputs: all LCD pins, all serial transmit pins
155
        .macro  _init_PERIPHERAL_PINS
156
        ldr     r0,=0x00355FFF
157
        ldr     r1,=SA11X0_PPC_PIN_DIRECTION
158
        str     r0,[r1]
159
        mov     r0,#0                           // Force initial state
160
        ldr     r1,=SA11X0_PPC_PIN_STATE
161
        str     r0,[r1]
162
        ldr     r1,=SA11X0_PPC_PIN_ASSIGNMENT   // Disable any reassignments
163
        str     r0,[r1]
164
        .endm
165
 
166
// Set core frequency (this can take up to 150us)        
167
        .macro  _set_CLOCK_FREQUENCY
168
        mov     r0,#SA11X0_PLL_CLOCK
169
        ldr     r1,=SA11X0_PWR_MGR_PLL_CONFIG
170
        str     r0,[r1]
171
        .endm
172
 
173
// Enable clock switching (must be done after setting core frequency)
174
        .macro  _enable_CLOCK_SWITCHING
175
        mcr     p15,0,r1,c15,c1,2
176
        .endm
177
 
178
// Initialize memory interfaces. (ROM, SRAM, Flash, DRAM, etc)
179
//
180
// Note: This code has hardcoded values (taken from the uHAL
181
//       code for brutus provided at the Intel StrongARM
182
//       website) that are specific to the memory devices
183
//       used on the Brutus board.
184
//
185
// Brutus memory is as follows:
186
//   ROM     256K (assuming 32 bit accesses)
187
//   Flash   256K (assuming 32 bit accesses)
188
//   SRAM    512K
189
//   DRAM     16M (4M per bank)
190
//
191
// From SA11X0 Manual, Section 10.7.1:
192
//
193
//  The following flow should be followed when coming out of
194
//  reset, whether for sleep or power-up:
195
//
196
//    - Read boot ROM and write to memory configuration
197
//      registers, but do not enable DRAM banks.
198
//
199
//    - If necessary, finish any DRAM power-up wait period
200
//      (usually about 100us).
201
//
202
//    - If coming out of sleep, see Section 9.5, Power
203
//      Manager on page 9-26 on how to release the nCAS and
204
//      nRAS pins from their self-refresh state.
205
//
206
//    - If coming out of sleep, wait the DRAM-specific
207
//      post-self-refresh precharge period before issuing
208
//      a new DRAM transaction.
209
//
210
//    - If power-on reset, perform the number of
211
//      initialization refreshes required by the specific
212
//      DRAM part by reading disabled banks. A read from
213
//      any disabled bank will refresh all four banks.
214
//
215
//    - Enable DRAM banks by setting MDCNFG:DE3:0.
216
//
217
//
218
// FIXME: Values for Brutus SRAM (NOT yet supported) are:
219
//  MDCAS0 = 0xCCCCCCCF
220
//  MDCAS1 = 0xFFFFFFFC
221
//  MDCAS2 = 0xFFFFFFFF
222
//  MDCNFG = 0 //DRAM not enabled
223
//
224
//
225
// Configure Bank 0 (ROM) and Bank 1 (Flash) in MSC0 as
226
// follows:
227
//
228
// Bank 0:
229
//                ROM type = Nonburst ROM or Flash EPROM
230
//           ROM bus width = as specified on ROM_SEL pin (s11)
231
//  ROM delay first access = 17 MCLK cycles
232
//   ROM delay next access = 0 (unused)
233
//       ROM recovery time = 2 MCLK cycles
234
//
235
// Bank 1:
236
//                ROM type = Nonburst ROM or SRAM
237
//           ROM bus width = 32 bits
238
//  ROM delay first access = 17 MCLK cycles
239
//   ROM delay next access = 20 MCLK cycles
240
//       ROM recovery time = 1 MCLK cycles
241
//
242
//
243
// Configure Bank 2 (SRAM) and Bank 3 (External Register)
244
// in MSC1 as follows:
245
//
246
// Bank 2:
247
//                ROM type = Nonburst ROM or SRAM
248
//           ROM bus width = 32 bits
249
//  ROM delay first access = 4 MCLK cycles
250
//   ROM delay next access = 2 MCLK cycles
251
//       ROM recovery time = 2 MCLK cycles
252
//
253
// Bank 3:
254
//                ROM type = Nonburst ROM or SRAM
255
//           ROM bus width = 32 bits
256
//  ROM delay first access = 5 MCLK cycles
257
//   ROM delay next access = 3 MCLK cycles
258
//       ROM recovery time = 4 MCLK cycles
259
//
260
//
261
// Enable DRAM banks 0-3 and configure for:
262
//  12 row address bits (brutus has 12x8 DRAMs)
263
//  CAS waveform shifted on DCLK
264
//  RAS precharges for 4 MCLK cycles
265
//  RAS asserts for 6 MCLK cycles during CBR
266
//  Data latched 3 DCLK cycles after CAS
267
//  0x400 * 4 = 4096 MCLK cycles between refreshes
268
//
269
#define MDCFG  (SA11X0_DRAM_CONFIGURATION-SA11X0_DRAM_CONFIGURATION)        
270
#define MDCAS0 (SA11X0_DRAM0_CAS_0-SA11X0_DRAM_CONFIGURATION)        
271
#define MDCAS1 (SA11X0_DRAM0_CAS_1-SA11X0_DRAM_CONFIGURATION)        
272
#define MDCAS2 (SA11X0_DRAM0_CAS_2-SA11X0_DRAM_CONFIGURATION)        
273
#define MSCTL0 (SA11X0_STATIC_CONTROL_0-SA11X0_DRAM_CONFIGURATION)        
274
#define MSCTL1 (SA11X0_STATIC_CONTROL_1-SA11X0_DRAM_CONFIGURATION)        
275
        .macro  _init_MEM_INTERFACES
276
        /* Do nothing if DRAM already configured */
277
        ldr     r1,=SA11X0_DRAM_CONFIGURATION
278
        ldr     r1,[r1]
279
        ands    r1,r1,#0xF
280
        bne     2003f
281
        /* Configure Memory */
282
        /* Configure Waveform Registers */
283
        ldr     r1,=SA11X0_DRAM_CONFIGURATION
284
        ldr     r0,=0x83C1E01F
285
        str     r0,[r1,#MDCAS0]
286
        ldr     r0,=0x3C1E0F07
287
        str     r0,[r1,#MDCAS1]
288
        ldr     r0,=0xFFFFF078
289
        str     r0,[r1,#MDCAS2]
290
        /* Configure Static Memory Regs */
291
        /*      FIXME: I think this is right? See note on page 10-11. */
292
        /*             Value from uHAL was actually 13812080          */
293
        ldr     r0,=0x13802080
294
        ldr     r2,[r1,#MSCTL0]
295
        and     r2,r2,#4        /* Extract the ROM_SEL (s11) value */
296
        orr     r0,r0,r2        /* Merge in the ROM_SEL value */
297
        str     r0,[r1,#MSCTL0]
298
        /*      FIXME: I think this is right? See note on page 10-11. */
299
        /*             Value from uHAL was actually 42210119          */
300
        ldr     r0,=0x42200118
301
        str     r0,[r1,#MSCTL1]
302
        /* FIXME: According to the SA11X0 Manual, we need to force    */
303
        /*        a certain number of refreshes here by doing reads   */
304
        /*        to the disabled banks.  However, the uHAL code      */
305
        /*        doesn't seem to do this, so we skip it here too     */
306
        /*        for now.                                            */
307
        /* Configure DRAM Registers */
308
        ldr     r0,=0x0801A9BF
309
        str     r0,[r1,#MDCFG]
310
        /* Wait for DRAM to be ready for use (as in uHAL code) */
311
        /* FIXME: why do we need to do this? */
312
        mov     r0,#0x200
313
2002:   subs    r0,r0,#1
314
        bne     2002b
315
2003:
316
        .endm
317
 
318
        .macro  _platform_setup1
319
        nop
320
        nop
321
        nop
322
        nop
323
        nop
324
        nop
325
        nop
326
        nop
327
        nop
328
 
329
        _init_GPIO
330
        _init_HEX_DISPLAY               /* this is flaky sometimes */
331
        _init_HEX_DISPLAY               /* so do it twice just in case */
332
        _set_LEDS(15)
333
 
334
        _init_PERIPHERAL_PINS
335
        _set_LEDS(13)
336
 
337
        _set_CLOCK_FREQUENCY
338
        _enable_CLOCK_SWITCHING
339
        _set_LEDS(12)
340
 
341
        _init_MEM_INTERFACES
342
        _set_LEDS(11)
343
 
344
        // Set up a stack [for calling C code]
345
        ldr     r1,=__startup_stack
346
        ldr     r2,=SA11X0_RAM_BANK0_BASE
347
        orr     sp,r1,r2
348
 
349
        // Create MMU tables
350
        bl      hal_mmu_init
351
 
352
        _set_LEDS(9)
353
        // Enable MMU
354
        ldr     r2,=10f
355
        ldr     r1,=MMU_Control_Init|MMU_Control_M
356
        mcr     MMU_CP,0,r1,MMU_Control,c0
357
        mov     pc,r2    /* Change address spaces */
358
        nop
359
        nop
360
        nop
361
10:
362
        _set_LEDS(8)
363
 
364
        .endm
365
 
366
#else // STARTUP_ROM        
367
#define PLATFORM_SETUP1
368
#endif
369
 
370
/*---------------------------------------------------------------------------*/
371
/* end of hal_platform_setup.h                                               */
372
#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.