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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [arm/] [xscale/] [iq80310/] [v2_0/] [include/] [hal_platform_setup.h] - Blame information for rev 587

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

powered by: WebSVN 2.1.0

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