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

Subversion Repositories openrisc

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

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

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

powered by: WebSVN 2.1.0

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