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

Subversion Repositories openrisc

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

powered by: WebSVN 2.1.0

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