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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [arm/] [xscale/] [iq80310/] [current/] [include/] [hal_platform_setup.h] - Blame information for rev 838

Go to most recent revision | 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
//
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 Free Software Foundation, 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
19
// version.
20
//
21
// eCos is distributed in the hope that it will be useful, but WITHOUT
22
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24
// for more details.
25
//
26
// You should have received a copy of the GNU General Public License
27
// along with eCos; if not, write to the Free Software Foundation, Inc.,
28
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
29
//
30
// As a special exception, if other files instantiate templates or use
31
// macros or inline functions from this file, or you compile this file
32
// and link it with other works to produce a work based on this file,
33
// this file does not by itself cause the resulting work to be covered by
34
// the GNU General Public License. However the source code for this file
35
// must still be made available in accordance with section (3) of the GNU
36
// General Public License v2.
37
//
38
// This exception does not invalidate any other reasons why a work based
39
// on this file might be covered by the GNU General Public License.
40
// -------------------------------------------
41
// ####ECOSGPLCOPYRIGHTEND####
42
//=============================================================================
43
//#####DESCRIPTIONBEGIN####
44
//
45
// Author(s):    msalter
46
// Contributors:
47
// Date:         2000-10-10
48
// Purpose:      Intel IQ80310 platform specific support routines
49
// Description:
50
// Usage:       #include <cyg/hal/hal_platform_setup.h>
51
//
52
//####DESCRIPTIONEND####
53
//
54
//===========================================================================*/
55
 
56
#include <pkgconf/system.h>             // System-wide configuration info
57
#include <cyg/hal/hal_mmu.h>            // MMU definitions
58
#include <cyg/hal/hal_mm.h>             // More MMU definitions
59
#include CYGBLD_HAL_VARIANT_H           // Variant specific configuration
60
#include CYGBLD_HAL_PLATFORM_H          // Platform specific configuration
61
#include <cyg/hal/hal_iop310.h>         // Platform specific hardware definitions
62
 
63
// Define macro used to diddle the LEDs during early initialization.
64
// Can use r0+r1.  Argument in \x.
65
#define CYGHWR_LED_MACRO                 \
66
        b       667f                    ;\
67
   666:                                 ;\
68
        .byte   0xc0, 0xf9, 0xa4, 0xb0  ;\
69
        .byte   0x99, 0x92, 0x82, 0xf8  ;\
70
        .byte   0x80, 0x90, 0x88, 0x83  ;\
71
        .byte   0xa7, 0xa1, 0x86, 0x8e  ;\
72
   667:                                 ;\
73
        ldr     r0, =666b               ;\
74
        add     r0, r0, #\x             ;\
75
        ldrb    r1, [r0]                ;\
76
        ldr     r0, =DISPLAY_RIGHT      ;\
77
        str     r1, [r0]
78
 
79
 
80
// The main useful output of this file is PLATFORM_SETUP1: it invokes lots
81
// of other stuff (may depend on RAM or ROM start).  The other stuff is
82
// divided into further macros to make it easier to manage what's enabled
83
// when.
84
 
85
#if defined(CYG_HAL_STARTUP_ROM)
86
#define PLATFORM_SETUP1 _platform_setup1
87
//#define CYGHWR_HAL_ARM_HAS_MMU
88
#else
89
#define PLATFORM_SETUP1
90
#endif
91
 
92
#define RAM_BASE        0xa0000000
93
#define DRAM_SIZE       (512*1024*1024)         // max size of available SDRAM
94
#define DCACHE_SIZE     (32*1024)               // size of the Dcache
95
 
96
// Reserved area for battery backup SDRAM memory test
97
// This area is not zeroed out by initialization code
98
#define SDRAM_BATTERY_TEST_BASE         0xA1FFFFF0      // base address of last 16 memory locations in a 32MB SDRAM
99
 
100
 
101
 
102
        // Display 'lvalue:rvalue' on the hex display
103
        // lvalue and rvalue must be of the form 'DISPLAY_x'
104
        // where 'x' is a hex digit from 0-F.
105
        .macro HEX_DISPLAY reg0, reg1, lvalue, rvalue
106
        ldr     \reg0, =DISPLAY_LEFT            // display left digit
107
        ldr     \reg1, =\lvalue
108
        str     \reg1, [\reg0]
109
        ldr     \reg0, =DISPLAY_RIGHT
110
        ldr     \reg1, =\rvalue                 // display right digit
111
        str     \reg1, [\reg0]
112
        .endm
113
 
114
        // Trigger the logic analyzer by writing a particular
115
        // address, and triggering on that address.
116
        .macro TRIGGER_LA_ON_ADDRESS address, reg0, reg1
117
        mrc     p15, 0, \reg0, c1, c0, 0     // read ARM control register
118
        //      CPWAIT  \reg0
119
        ldr     \reg1, =\address
120
        str     \reg0, [\reg1]
121
        .endm
122
 
123
        // Delay a bit
124
        .macro DELAY_FOR cycles, reg0
125
        ldr     \reg0, =\cycles
126
        subs    \reg0, \reg0, #1
127
        subne   pc,  pc, #0xc
128
        .endm
129
 
130
        // wait for coprocessor write complete
131
        .macro CPWAIT reg
132
        mrc  p15,0,\reg,c2,c0,0
133
        mov  \reg,\reg
134
        sub  pc,pc,#4
135
        .endm
136
 
137
        // start of platform setup
138
        .macro _platform_setup1
139
 
140
        // This is where we wind up immediately after reset. On the IOP310, we have
141
        // to jump around a hole in flash which runs from 0x00001000 - 0x0001fff.
142
        // The start of _platform_setup1 will be below 0x1000 and since we need to
143
        // align the mmu table on a 16k boundary, we just branch around the page
144
        // table which we will locate at FLASH_BASE+0x4000.
145
        b _real_platform_setup
146
 
147
        .p2align 13
148
        // the following alignment creates the mmu table at address 0x4000.
149
    mmu_table:
150
 
151
        // 1MB of FLASH with i80312 MMRs mapped in using 4K small pages so we can
152
        // set the access permission on flash and memory-mapped registers properly.
153
        FL_PT_ENTRY mmu_table_flashbase,0,0
154
 
155
        // Remaining 7MB of FLASH
156
        //   rw, cacheable, non-bufferable
157
        .set    __base,1
158
        .rept   7
159
        FL_SECTION_ENTRY __base,0,3,0,0,1,0
160
        .set    __base,__base+1
161
        .endr
162
 
163
        // nothing interesting here (Address Translation)
164
        .rept   0xA00 - 0x8
165
        FL_SECTION_ENTRY __base,0,3,0,0,0,0
166
        .set    __base,__base+1
167
        .endr
168
 
169
        // up to 512MB ECC SDRAM mapped 1-to-1
170
        // first 1MB mapped in 4K chunks
171
        //   x=c=b=1
172
        FL_PT_ENTRY mmu_table_rambase,1,0
173
        .set    __base,__base+1
174
        .rept   0xC00 - 0xA01
175
        FL_SECTION_ENTRY __base,1,3,1,0,1,1
176
        .set    __base,__base+1
177
        .endr
178
 
179
        // Cache flush region.
180
        // Don't need physical memory, just a cached area.
181
        .rept   0xD00 - 0xC00
182
        FL_SECTION_ENTRY __base,0,3,0,0,1,1
183
        .set    __base,__base+1
184
        .endr
185
 
186
        // Alias for first 1MB of FLASH
187
        //  rw, cacheable, non-bufferable
188
        FL_SECTION_ENTRY 0x000,0,3,0,0,1,0
189
        .set    __base,__base+1
190
 
191
        // Invalid
192
        .rept   0xE00 - 0xD01
193
        .word 0
194
        .set    __base,__base+1
195
        .endr
196
 
197
        // Uncached and unbuffered alias for first 256MB of SDRAM. This
198
        // area can be used by device drivers for DMA operations. Buffers
199
        // should be cache aligned.
200
        .set    __base,0xA00
201
        .rept   0xF00 - 0xE00
202
        FL_SECTION_ENTRY __base,0,3,1,0,0,0
203
        .set    __base,__base+1
204
        .endr
205
 
206
        // only I/O at 0xFE8xxxxx
207
        .set    __base,0xF00
208
        .rept   0x1000 - 0xF00
209
        FL_SECTION_ENTRY __base,0,3,0,0,0,0
210
        .set    __base,__base+1
211
        .endr
212
 
213
        // Immediately after the above table (at 0x8000) is the
214
        // second level page table which breaks up the lowest 1MB
215
        // of physical memory into 4KB sized virtual pages. These
216
        // pages work around a hole in flash (0x1000-0x1fff) used
217
        // by the Yavapai companion chip internal registers.
218
    mmu_table_flashbase:
219
        // Virtual address 0 (Flash boot code).
220
        // Map 4k page at 0x00000000 virt --> 0xA0000000 physical
221
        // This allows us to have a writable vector table.
222
        //   Read-Write, cacheable, bufferable
223
        SL_XSMPAGE_ENTRY 0xa0000,1,3,1,1
224
 
225
        // Virtual address 0x1000 (Memory mapped registers)
226
        // Map 1-to-1, but don't cache or buffer
227
        //   Read-Write, non-cacheable, non-bufferable         
228
        .set    __base,1
229
        SL_SMPAGE_ENTRY __base,3,3,3,3,0,0
230
        .set    __base,__base+1
231
 
232
        // Virtual address 0x2000-0x100000 (remainder of flash1)
233
        //   Read-Write, cacheable, non-bufferable
234
        .rept   0x100 - 0x2
235
        SL_SMPAGE_ENTRY __base,3,3,3,3,1,0
236
        .set    __base,__base+1
237
        .endr
238
 
239
        // Now is the second level table for the first megabyte
240
        // of DRAM.
241
    mmu_table_rambase:
242
        // Map first meg of SDRAM
243
        //   Read-Write, cacheable, bufferable
244
        .set    __base,0xA0000
245
        .rept   0x100
246
        SL_XSMPAGE_ENTRY __base,1,3,1,1
247
        .set    __base,__base+1
248
        .endr
249
 
250
_real_platform_setup:
251
        // Drain write and fill buffer
252
        mcr     p15,0,r0,c7,c10,4
253
        CPWAIT  r0
254
 
255
        // Delay appx 60 ms to let battery-backup reset complete
256
        DELAY_FOR 0x400000, r0
257
        // Eventually we will be able to check a register bit
258
        // to determine when this is complete 
259
 
260
        HEX_DISPLAY r0, r1, DISPLAY_0, DISPLAY_1
261
 
262
        //
263
        // ***  I2C interface initialization ***
264
        //
265
 
266
        //  Setup I2C Slave Address Register
267
        ldr     r1, =I2C_DEVID          // Load slave address r1.
268
        ldr     r2, =ISAR_ADDR          // Load address of the I2C Slave Address Register in r2.
269
        ldr     r3, =0x0000007f         // Load mask in r3.
270
        and     r1, r3, r3              // The mask zeroes the 25 MSBs of r1 just to make sure.
271
        str     r3, [r2]                // Save the value 0x02 (I2C_DEVID) in the register.
272
 
273
        //  Setup I2C Clock Count Register
274
        ldr     r2, =ICCR_ADDR          // Load the address of the I2C Clock Control Register in r2.
275
        ldr     r3, =0x0000014d         // Set for 5.05 us transition time at 66MHz (0x14D = 333).
276
        str     r3, [r2]                // Save the value in the register.
277
 
278
        //  Enable I2C Interface Unit - status will be polled
279
        ldr     r2, =ICR_ADDR           // Load the address of the Control Register in r2.
280
        ldr     r1, =ICR_GCALL          // Disable General Call (will be master)
281
        ldr     r3, =ICR_ENB            // Enable I2C unit ).
282
        orr     r1, r3, r1              // OR the two and store in R1
283
        ldr     r3, =ICR_SCLENB         // Enable I2C Clock Generator disabled
284
        orr     r1, r3, r1              // OR the two and store in R1
285
        str     r1, [r2]                // Save the value to the Control Register.
286
 
287
        //
288
        //  *** Now read the SPD Data ***
289
        //
290
 
291
        // Pointers to I2C Registers
292
        ldr     r11, =ICR_ADDR          // Load the address of the I2C Control Register in r11.
293
        ldr     r12, =ISR_ADDR          // Load the address of the I2C Status Register in r12.
294
        ldr     r13, =IDBR_ADDR         // Load the address of the I2C Data Buffer Register in r13.
295
 
296
        // Initialize byte counters
297
        ldr     r6, =0x00000000  // Counter incremented before byte is read
298
        ldr     r7, =0x00000040  // Number of bytes to read in the Presence Detect EEPROM of SDRAM: 64 bytes
299
        ldr     r5, =0x00000000  // R5 has running checksum calculation
300
        ldr     r9, =I2C_TIMOUT  // Timeout limit in case EEPROM does not respond
301
 
302
        // At the end of all this, R4 has DRAM size, R8 has bank count, and R10 has Bank size
303
        ldr     r10,=0x00000000  // Bank size
304
        ldr     r8, =0x00000000  // Bank count
305
        ldr     r4, =0x00000000  // SDRAM size
306
 
307
        /*  FREE REGISTERS ARE R0 - R3 */
308
 
309
        // *** Put out address, with WRITE mode ***
310
 
311
        // Set SDRAM module address and write mode
312
        ldr     r1, =SDRAM_DEVID        // Load slave address for SDRAM module: 0xA2 (Presence Detect Data)
313
        bic     r1, r1, #IDBR_MODE      // Clear read bit (bit #0)
314
        str     r1, [r13]               // Store to data register
315
 
316
        // Initiate dummy write to set EEPROM pointer to 0
317
        ldr     r1, [r11]               // read the current Control Register value
318
        orr     r1, r1, #ICR_START      // Set start bit
319
        orr     r1, r1, #ICR_TRANSFER   // Set transfer bit - bit is self_clearing
320
        str     r1, [r11]               // Store to control register
321
 
322
        // Wait for transmit empty status
323
        ldr     r1, =0x00000000         // Initialize I2C timeout counter
324
    0:
325
        add     r1, r1, #1              // Increment I2C timeout counter (r1 = r1 + 1)
326
        cmp     r1, r9
327
        beq     i2c_error               // Kick out of SDRAM initialization if timeout occurs
328
        ldr     r0, [r12]               // Load I2C Status Reg into R0
329
        ands    r3, r0, #ISR_EMPTY      // Bit #6 is checked: IDBR Transmit Empty
330
        beq     0b
331
        str     r0, [r12]               // Write back status to clear
332
 
333
        // *** Write pointer register on EEPROM to 0x00000000 ***
334
 
335
        //  Set SDRAM module EEPROM address to 0
336
        ldr     r1, =0x00000000         // Load base address of SDRAM module EEPROM
337
        str     r1, [r13]               // Store to data register
338
 
339
        //  Send address to EEPROM
340
        ldr     r1, [r11]               // read the current Control Register value
341
        bic     r1, r1, #ICR_START      // No start bit (already started)
342
        orr     r1, r1, #ICR_TRANSFER   // Set transfer bit - bit is self_clearing
343
        str     r1, [r11]               // Store to control register
344
 
345
        // Wait for transmit empty status
346
        ldr     r1, =0x00000000         // Initialize I2C timeout counter
347
    0:
348
        add     r1, r1, #1              // Increment I2C timeout counter (r1 = r1 + 1)
349
        cmp     r1, r9
350
        beq     i2c_error               // Kick out of SDRAM initialization if timeout occurs
351
        ldr     r0, [r12]               // Load I2C Status Reg into R0 -  ld    (r12), r10
352
        ands    r3, r0, #ISR_EMPTY      // Bit #6 is checked: IDBR Transmit Empty
353
        beq     0b
354
        str     r0, [r12]               // Write back status to clear
355
 
356
        // *** Read SDRAM PD data ***
357
 
358
        // *** Put out address, with READ mode ***
359
 
360
        //  Set SDRAM module address and read mode
361
        ldr     r0, =SDRAM_DEVID        // Load slave address for SDRAM module (0xA2)
362
        orr     r1, r0, #IDBR_MODE      // Set read bit (bit #0)
363
        str     r1, [r13]               // Store to data register
364
 
365
        //  Send next read request
366
        ldr     r1, [r11]               // read the current Control Register value
367
        orr     r1, r1, #ICR_START      // Set start bit
368
        orr     r1, r1, #ICR_TRANSFER   // Set transfer bit - bit is self_clearing
369
        str     r1, [r11]               // Store to control register
370
 
371
        // Wait for transmit empty status
372
        ldr     r1, =0x00000000         // Initialize I2C timeout counter
373
    0:
374
        add     r1, r1, #1              // Increment I2C timeout counter (r1 = r1 + 1)
375
        cmp     r1, r9
376
        beq     i2c_error               // Kick out of SDRAM initialization if timeout occurs
377
        ldr     r0, [r12]               // Load I2C Status Reg into R0 -  ld    (r12), r10
378
        ands    r3, r0, #ISR_EMPTY      // Bit #6 is checked: IDBR Transmit Empty
379
        beq     0b
380
        str     r0, [r12]               // Write back status to clear
381
 
382
    sdram_loop:
383
        add     r6, r6, #1              // Increment byte counter
384
 
385
        // *** READ the next Byte!!! ***
386
 
387
        ldr     r1, [r11]               // read the current Control Register value
388
        bic     r1, r1, #ICR_START      // No start bit (already started)
389
        orr     r1, r1, #ICR_TRANSFER   // Set transfer bit - bit is self_clearing
390
 
391
        // we have to set NACK before reading the last bit
392
        cmp     r6, r7                  // r7 = 64 (decimal) so if r6 = 64, this is the last byte to be read
393
        bne     1f                      // If bytes left, skip ahead
394
        orr     r1, r1, #ICR_ACK        // Set NACK if this is the last byte
395
        orr     r1, r1, #ICR_STOP       // Set STOP if this is the last byte
396
    1:
397
        str     r1, [r11]               // Store to control register
398
 
399
        // Wait for read full status
400
        ldr     r1, =0x00000000         // Initialize I2C timeout counter
401
    0:
402
        add     r1, r1, #1              // Increment I2C timeout counter (r1 = r1 + 1)
403
        cmp     r1, r9
404
        beq     i2c_error               // Kick out of SDRAM initialization if timeout occurs
405
        ldr     r0, [r12]               // Load I2C Status Reg into R0
406
        ands    r3, r0, #ISR_FULL       // Bit #6 is checked: IDBR Transmit Empty
407
        beq     0b
408
        str     r0, [r12]               // Write back status to clear
409
 
410
        // Read the data byte
411
        ldr     r1, [r13]               // Read the byte
412
 
413
        ldr     r2, =CHECKSUM_BYTE
414
        cmp     r6, r2                  // is it the CHECKSUM byte???
415
        beq     1f
416
        add     r5, r5, r1              // Add it to the checksum if not the checksum byte
417
        bal     2f                      // skip checksum comparison
418
    1:
419
        ldr     r0, =0xff               // If this is the checksum byte, compare it
420
        and     r5, r5, r0              //      against the calculated checksum
421
        cmp     r1, r5
422
        bne     bad_checksum            // If no match, skip SDRAM controller initialization
423
    2:
424
        ldr     r2, =BANKCNT_BYTE       // Check for bank count byte
425
        cmp     r6, r2
426
        bne     1f
427
        mov     r8, r1                  // Store bank count
428
    1:
429
        ldr     r2, =BANKSZ_BYTE        // Check for bank size byte
430
        cmp     r6, r2
431
        bne     1f
432
 
433
        ldr     r2, =0x04               // Store bank size in Mbytes (shift left 2 bits)
434
        mul     r10, r1, r2
435
        mul     r2, r8, r10             // Multiply by bank count to get DRAM size in MB
436
        ldr     r0, =0x100000
437
        mul     r4, r2, r0              // Convert size to bytes  - r4 contains DRAM size in bytes
438
 
439
1:
440
        // Handle the SDRAM drive strength setup here since we are out of
441
        // temporary registers to hold the SDRAM width value until after
442
        // all of the SPD data has been read.  Using the value of r8 for
443
        // the Bank Count is allright here since the SPD specification states that
444
        // the Bank Count SPD byte is #5 and the SDRAM Width SPD byte is #13.
445
 
446
        ldr     r2, =SDRAM_WIDTH_BYTE   // Check for SDRAM width byte
447
        cmp     r6, r2
448
        bne     1f
449
        mov     r2, #0x10         // Check for data width of 16
450
        cmp     r1, r2
451
        bne     SDRAM_DRIVE_X8
452
 
453
        // Module is composed of x16 devices
454
        mov     r2, #0x02                       
455
        cmp     r2, r8          // do we have 2 banks???
456
        beq     SDRAM_DRIVE_2_BANK_X16
457
 
458
        // Module is composed of 1 Bank of x16 devices
459
        ldr     r1, =SDCR_ADDR          // point at SDRAM Control Register
460
        ldr     r2, =SDCR_1BANK_X16     // drive strength value
461
        str     r2, [r1]                // set value in SDCR
462
        b       1f
463
 
464
SDRAM_DRIVE_2_BANK_X16:
465
        // Module is composed of 2 Banks of x16 devices
466
        ldr     r1, =SDCR_ADDR          // point at SDRAM Control Register
467
        ldr     r2, =SDCR_2BANK_X16     // drive strength value
468
        str     r2, [r1]                // set value in SDCR
469
        b       1f
470
 
471
SDRAM_DRIVE_X8:
472
        // Module is composed of x8 devices
473
        mov     r2, #0x02                       
474
        cmp     r2, r8                  // do we have 2 banks???
475
        beq     SDRAM_DRIVE_2_BANK_X8
476
 
477
        // Module is composed of 1 Bank of x8 devices
478
        ldr     r1, =SDCR_ADDR          // point at SDRAM Control Register
479
        ldr     r2, =SDCR_1BANK_X8      // drive strength value
480
        str     r2, [r1]                // set value in SDCR
481
        b       1f
482
 
483
SDRAM_DRIVE_2_BANK_X8:
484
        // Module is composed of 2 Banks of x16 devices
485
        ldr     r1, =SDCR_ADDR          // point at SDRAM Control Register
486
        ldr     r2, =SDCR_2BANK_X8      // drive strength value
487
        str     r2, [r1]                // set value in SDCR
488
    1:
489
 
490
 
491
        // Continue reading bytes if not done
492
        cmp     r6, r7
493
        bne     sdram_loop
494
 
495
        b       i2c_disable
496
 
497
    bad_checksum:
498
        HEX_DISPLAY r2, r3, DISPLAY_7, DISPLAY_7
499
 
500
    i2c_error:
501
        // hit the leds if an error occurred
502
        HEX_DISPLAY r2, r3, DISPLAY_5, DISPLAY_5
503
 
504
 
505
    i2c_disable:
506
        //  Disable I2C Interface Unit
507
        ldr     r1, [r11]
508
        bic     r1, r1, #ICR_ENB        // Disable I2C unit
509
        bic     r1, r1, #ICR_SCLENB     // Disable I2C clock generator
510
        str     r1, [r11]               // Store to control register
511
 
512
        // ADD THIS???:
513
        //  cmpobne     1, g9, test_init
514
        // Skip SDRAM controller initialization if checksum test failed
515
 
516
        // *** SDRAM setup ***
517
 
518
        ldr     r9, =MMR_BASE           // get base of MMRs
519
        ldr     r0, =RAM_BASE           // Program SDRAM Base Address register
520
        str     r0, [r9, #SDBR_OFF]    
521
 
522
        // Set up bank 0 register
523
    CHECK_32MB:
524
        ldr     r1, =RAM_32MEG          // do we have 32 MB banks?
525
        cmp     r10, r1
526
        bne     CHECK_64MB
527
 
528
        ldr     r0, =SBR_32MEG          // Program SDRAM Bank0 Boundary register to 32 MB
529
        b       SET_BANK1
530
 
531
    CHECK_64MB:
532
        ldr     r1, =RAM_64MEG          // do we have 64 MB banks?
533
        cmp     r10, r1
534
        bne     CHECK_128MB
535
 
536
        ldr     r0, =SBR_64MEG          // Program SDRAM Bank0 Boundary register to 64 MB
537
        b       SET_BANK1
538
 
539
    CHECK_128MB:
540
        ldr     r1, =RAM_128MEG         // do we have 128 MB banks?
541
        cmp     r10, r1
542
        bne     CHECK_256MB
543
 
544
        ldr     r0, =SBR_128MEG         // Program SDRAM Bank0 Boundary register to 128 MB
545
        b       SET_BANK1
546
 
547
    CHECK_256MB:
548
        ldr     r1, =RAM_256MEG         // do we have 256 MB banks?
549
        cmp     r10, r1
550
        bne     dram_error
551
 
552
        ldr     r0, =SBR_256MEG         // Program SDRAM Bank0 Boundary register to 64 MB
553
        b       SET_BANK1
554
 
555
    SET_BANK1:
556
        str     r0, [r9, #SBR0_OFF]     // store SBR0
557
 
558
        ldr     r2, =0x02
559
        cmp     r2, r8                  // do we have 2 banks???
560
        bne     SDRAM_1_BANK
561
 
562
        add     r0, r0, r0              // SDRAM Bank1 Boundary register is double SBR0
563
        str     r0, [r9, #SBR1_OFF]
564
        b       END_DRAM_SIZE
565
 
566
    SDRAM_1_BANK:
567
        // SDRAM Bank1 Boundary register is same as SBR0 for 1 bank configuration
568
        str     r0, [r9, #SBR1_OFF]
569
        b       END_DRAM_SIZE
570
 
571
    END_DRAM_SIZE:
572
        b       init_dram
573
 
574
    dram_error:
575
 
576
        HEX_DISPLAY r2, r3, DISPLAY_F, DISPLAY_F
577
 
578
   init_dram:
579
        ldr     r0, =0                   // turn off refresh
580
        str     r0, [r9, #RFR_OFF]
581
 
582
        ldr     r0,   =MRS_NO_OP        // Issue NOP cmd to SDRAM
583
        str     r0, [r9, #SDIR_OFF]
584
        DELAY_FOR 0x4000, r0
585
 
586
        ldr     r0, =MRS_PRECHRG        // Issue 1 Precharge all
587
        str     r0, [r9, #SDIR_OFF]    
588
        DELAY_FOR 0x4000, r0
589
 
590
 
591
        ldr     r0, =MRS_AUTO_RFRSH     // Issue 1 Auto Refresh command
592
        str     r0, [r9, #SDIR_OFF]    
593
        DELAY_FOR 0x4000, r0
594
 
595
 
596
        ldr     r0, =MRS_AUTO_RFRSH
597
        str     r0, [r9, #SDIR_OFF]    // Auto Refresh #1
598
        str     r0, [r9, #SDIR_OFF]    // Auto Refresh #2
599
        str     r0, [r9, #SDIR_OFF]    // Auto Refresh #3
600
        str     r0, [r9, #SDIR_OFF]    // Auto Refresh #4
601
        str     r0, [r9, #SDIR_OFF]    // Auto Refresh #5
602
        str     r0, [r9, #SDIR_OFF]    // Auto Refresh #6
603
        str     r0, [r9, #SDIR_OFF]    // Auto Refresh #7
604
        str     r0, [r9, #SDIR_OFF]    // Auto Refresh #8
605
 
606
        ldr     r0, =MRS_CAS_LAT_2      // set the CAS latency
607
        str     r0, [r9, #SDIR_OFF]
608
        DELAY_FOR 0x4000, r0
609
 
610
        ldr     r0, =MRS_NORM_OP        // Issue a Normal Operation command
611
        str     r0, [r9, #SDIR_OFF]     
612
 
613
        ldr     r0, =RFR_INIT_VAL       // Program Refresh Rate register
614
        str     r0, [r9, #RFR_OFF]     
615
 
616
        // ldr   r0, =(FLASH_BASE :AND: &FFFF0000)
617
        // str   r0, [r10, #FEBR1_OFF]   ; Program Flash Bank1 Base Address register
618
 
619
        // ldr   r0, =(FLASH_SIZE :AND: &FFFF0000)
620
        // str   r0, [r10, #FBSR1_OFF]   ; Program Flash Bank1 Size register
621
 
622
        // ldr   r0, =FWSR0_INIT_VAL
623
        // str   r0, [r10, #FWSR0_OFF]   ; Program Flash Bank0 Wait State register
624
 
625
        // ldr   r0, =FWSR1_INIT_VAL
626
        // str   r0, [r10, #FWSR1_OFF]   ; Program Flash Bank1 Wait State register
627
 
628
        HEX_DISPLAY r0, r1, DISPLAY_0, DISPLAY_2
629
 
630
        // begin initializing the i80310
631
 
632
        // Enable access to all coprocessor registers
633
        ldr     r0, =0x2001                     // enable access to all coprocessors
634
        mcr     p15, 0, r0, c15, c1, 0
635
 
636
        mcr     p15, 0, r0, c7, c10, 4           // drain the write & fill buffers
637
        CPWAIT r0
638
 
639
        mcr     p15, 0, r0, c7, c7, 0             // flush Icache, Dcache and BTB
640
        CPWAIT r0
641
 
642
        mcr     p15, 0, r0, c8, c7, 0             // flush instuction and data TLBs
643
        CPWAIT r0
644
 
645
        // Enable the Icache
646
        mrc     p15, 0, r0, c1, c0, 0
647
        orr     r0, r0, #MMU_Control_I
648
        mcr     p15, 0, r0, c1, c0, 0
649
        CPWAIT  r0
650
 
651
        // Set the TTB register
652
        ldr     r0, =mmu_table
653
        mcr     p15, 0, r0, c2, c0, 0
654
 
655
        // Enable permission checks in all domains
656
        ldr     r0, =0x55555555
657
        mcr     p15, 0, r0, c3, c0, 0
658
 
659
        // Enable the MMU
660
        mrc     p15, 0, r0, c1, c0, 0
661
        orr     r0, r0, #MMU_Control_M
662
        orr     r0, r0, #MMU_Control_R
663
        mcr     p15, 0, r0, c1, c0, 0
664
        CPWAIT  r0
665
 
666
        mcr     p15, 0, r0, c7, c10, 4           // drain the write & fill buffers
667
        CPWAIT r0
668
 
669
        // Enable the Dcache
670
        mrc     p15, 0, r0, c1, c0, 0
671
        orr     r0, r0, #MMU_Control_C
672
        mcr     p15, 0, r0, c1, c0, 0
673
        CPWAIT  r0
674
 
675
        // Initialize branch target buffer
676
        BTB_INIT r0
677
 
678
        //  Battery Backup SDRAM Memory Test
679
        //  Move 4 byte Test Pattern into register prior to zeroing out
680
        //  contents of SDRAM locations
681
        ldr     r9, =SDRAM_BATTERY_TEST_BASE
682
        ldr     r10, [r9]
683
 
684
        IOP310_EARLY_PCI_SETUP  r0, r1, r4, 0x113C, 0x0700
685
 
686
        // scrub/init SDRAM if enabled/present
687
        ldr     r11, =RAM_BASE  // base address of SDRAM
688
        mov     r12, r4         // size of memory to scrub
689
        mov     r8,r4           // save DRAM size
690
        mov     r0, #0          // scrub with 0x0000:0000
691
        mov     r1, #0
692
        mov     r2, #0                          
693
        mov     r3, #0
694
        mov     r4, #0                                  
695
        mov     r5, #0
696
        mov     r6, #0                                  
697
        mov     r7, #0
698
    10: // fastScrubLoop
699
        subs    r12, r12, #32   // 32 bytes/line
700
        stmia   r11!, {r0-r7}
701
        beq     15f
702
        b       10b
703
    15:
704
 
705
        // now copy 1st 4K page of flash into first 4K of RAM.
706
        ldr     r1, =RAM_BASE   // base address of SDRAM
707
        mov     r2, #0xd0000000 // alias for first 1M of flash
708
        mov     r3, #0x1000
709
    16:
710
        ldr     r4, [r2]
711
        add     r2, r2, #4
712
        str     r4, [r1]
713
        add     r1, r1, #4
714
        subs    r3, r3, #4
715
        bne     16b
716
 
717
        // Battery Backup SDRAM Memory Test
718
        // Store 4 byte Test Pattern back into memory
719
        str r10, [r9, #0x0]
720
 
721
        HEX_DISPLAY r0, r1, DISPLAY_1, DISPLAY_0
722
 
723
        // clean/drain/flush the main Dcache
724
        mov     r1, #DCACHE_FLUSH_AREA           // use a CACHEABLE area of
725
                                                 // the memory map above SDRAM
726
        mov     r0, #1024                        // number of lines in the Dcache
727
    20:
728
        mcr     p15, 0, r1, c7, c2, 5             // allocate a Dcache line
729
        add     r1, r1, #32                      // increment the address to
730
                                                 // the next cache line
731
        subs    r0, r0, #1                       // decrement the loop count
732
        bne     20b
733
 
734
        HEX_DISPLAY r0, r1, DISPLAY_9, DISPLAY_9
735
 
736
        // clean/drain/flush the mini Dcache
737
        ldr     r2, =(DCACHE_FLUSH_AREA+DCACHE_SIZE) // use a CACHEABLE area of
738
                                                // the memory map above SDRAM
739
        mov     r0, #64                         // number of lines in the mini Dcache
740
    21:
741
        mcr     p15, 0, r2, c7, c2, 5            // allocate a Dcache line
742
        add     r2, r2, #32                     // increment the address to
743
                                                // the next cache line
744
        subs    r0, r0, #1                      // decrement the loop count
745
        bne     21b
746
 
747
        mcr     p15, 0, r0, c7, c6, 0             // flush Dcache
748
        CPWAIT r0
749
 
750
        HEX_DISPLAY r0, r1, DISPLAY_7, DISPLAY_7
751
 
752
        mcr     p15, 0, r0, c7, c10, 4           // drain the write & fill buffers
753
        CPWAIT r0
754
 
755
        // enable ECC stuff here
756
        mcr p15, 0, r0, c7, c10, 4               // 
757
        CPWAIT r0
758
 
759
        mrc     p13, 0, r0, c0, c1, 0             // BCU_WAIT --> wait until the BCU isn't busy
760
        submi   pc, pc, #0xc
761
 
762
    checkme:    // add in multi-bit error reporting */
763
        mrc     p13, 0, r0, c0, c1, 0             // disable ECC
764
        and     r0, r0, #(-1-8)
765
        mcr     p13, 0, r0, c0, c1, 0
766
        orr     r0, r0, #6                      // enable single-bit correction,
767
        mcr     p13, 0, r0, c0, c1, 0             // multi-bit detection
768
        orr     r0, r0, #8                      // enable ECC
769
        mcr     p13, 0, r0, c0, c1, 0
770
 
771
        mrc     p13, 0, r0, c0, c1, 0             // BCU_WAIT --> wait until the BCU isn't busy
772
        submi   pc, pc, #0xc
773
 
774
        // Enable ECC circuitry in Yavapai
775
        ldr     r1, =ECCR_ADDR
776
        mov     r0, #0x6  // Enable single bit ECC Correction (Reporting Enabled)
777
        str     r0, [r1, #0]
778
 
779
        HEX_DISPLAY r0, r1, DISPLAY_6, DISPLAY_6
780
 
781
#if 1
782
        mov     r0, #0x1000000
783
    1:  subs    r0,r0,#1
784
        bne     1b
785
#endif
786
        // Save SDRAM size
787
        ldr     r1, =hal_dram_size  /* [see hal_intr.h] */
788
        str     r8, [r1]
789
 
790
        // Move mmu tables into RAM so page table walks by the cpu
791
        // don't interfere with FLASH programming.
792
        ldr     r0, =mmu_table
793
        mov     r4, r0
794
        add     r2, r0, #0x4800         // End of tables
795
        mov     r1, #RAM_BASE
796
        orr     r1, r1, #0x4000         // RAM tables
797
        mov     r5, r1
798
 
799
        // first, fixup physical address to second level
800
        // table used to map first 1MB of flash.
801
        ldr     r3, [r0], #4
802
        sub     r3, r3, r4
803
        add     r3, r3, r5
804
        str     r3, [r1], #4
805
        // everything else can go as-is
806
    1:
807
        ldr     r3, [r0], #4
808
        str     r3, [r1], #4
809
        cmp     r0, r2
810
        bne     1b
811
 
812
        // go back and fixup physical address to second level
813
        // table used to map first 1MB of SDRAM.
814
        add     r1, r5, #(0xA00 * 4)
815
        ldr     r0, [r1]                // entry for first 1MB of DRAM
816
        sub     r0, r0, r4
817
        add     r0, r0, r5
818
        str     r0, [r1]                // store it back
819
 
820
        // Flush the cache
821
        mov    r0, #DCACHE_FLUSH_AREA   /* cache flush region */
822
        add    r1, r0, #0x8000          /* 32KB cache         */
823
  667:
824
        mcr    p15,0,r0,c7,c2,5          /* allocate a line    */
825
        add    r0, r0, #32              /* 32 bytes/line      */
826
        teq    r1, r0
827
        bne    667b
828
        mcr    p15,0,r0,c7,c6,0           /* invalidate data cache */
829
        /* cpuwait */
830
        mrc    p15,0,r1,c2,c0,0           /* arbitrary read   */
831
        mov    r1,r1
832
        sub    pc,pc,#4
833
        mcr    p15,0,r0,c7,c10,4
834
        /* cpuwait */
835
        mrc    p15,0,r1,c2,c0,0           /* arbitrary read   */
836
        mov    r1,r1
837
        sub    pc,pc,#4
838
        nop
839
 
840
        HEX_DISPLAY r0, r1, DISPLAY_5, DISPLAY_2
841
 
842
        // Set the TTB register to DRAM mmu_table
843
        mov     r0, r5
844
        mov     r1, #0
845
        mcr     p15, 0, r1, c7, c5, 0             // flush I cache
846
        mcr     p15, 0, r1, c7, c10, 4           // drain WB
847
        mcr     p15, 0, r0, c2, c0, 0             // load page table pointer
848
        mcr     p15, 0, r1, c8, c7, 0             // flush TLBs
849
        CPWAIT  r0
850
 
851
        // Interrupt init
852
        mov     r0, #0 // enable no sources
853
        mcr     p13,0,r0,c0,c0,0 // write to INTCTL
854
        // Steer both BCU and PMU to IRQ
855
        mcr     p13,0,r0,c8,c0,0 // write to INTSTR
856
 
857
        HEX_DISPLAY r0, r1, DISPLAY_0, DISPLAY_0
858
 
859
        .endm    // _platform_setup1
860
 
861
 
862
#define PLATFORM_VECTORS         _platform_vectors
863
        .macro  _platform_vectors
864
        .globl  _80312_EMISR
865
_80312_EMISR:   .long   0       // Companion chip "clear-on-read" interrupt status
866
                                // register for the performance monitor unit.
867
        .endm
868
 
869
/*---------------------------------------------------------------------------*/
870
/* end of hal_platform_setup.h                                               */
871
#endif /* CYGONCE_HAL_PLATFORM_SETUP_H */
872
 

powered by: WebSVN 2.1.0

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