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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [arm/] [xscale/] [iq80321/] [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, 2003 Free Software Foundation, Inc.
15
//
16
// eCos is free software; you can redistribute it and/or modify it under
17
// the terms of the GNU General Public License as published by the Free
18
// Software Foundation; either version 2 or (at your option) any later
19
// version.
20
//
21
// eCos is distributed in the hope that it will be useful, but WITHOUT
22
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24
// for more details.
25
//
26
// You should have received a copy of the GNU General Public License
27
// along with eCos; if not, write to the Free Software Foundation, Inc.,
28
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
29
//
30
// As a special exception, if other files instantiate templates or use
31
// macros or inline functions from this file, or you compile this file
32
// and link it with other works to produce a work based on this file,
33
// this file does not by itself cause the resulting work to be covered by
34
// the GNU General Public License. However the source code for this file
35
// must still be made available in accordance with section (3) of the GNU
36
// General Public License v2.
37
//
38
// This exception does not invalidate any other reasons why a work based
39
// on this file might be covered by the GNU General Public License.
40
// -------------------------------------------
41
// ####ECOSGPLCOPYRIGHTEND####
42
//=============================================================================
43
//#####DESCRIPTIONBEGIN####
44
//
45
// Author(s):    msalter
46
// Contributors: msalter
47
// Date:         2001-12-03
48
// Purpose:      Intel XScale IQ80321 platform specific support routines
49
// Description:
50
// Usage:        #include <cyg/hal/hal_platform_setup.h>
51
//     Only used by "vectors.S"
52
//
53
//####DESCRIPTIONEND####
54
//
55
//===========================================================================*/
56
 
57
#include <pkgconf/system.h>             // System-wide configuration info
58
#include CYGBLD_HAL_VARIANT_H           // Variant specific configuration
59
#include CYGBLD_HAL_PLATFORM_H          // Platform specific configuration
60
#include <cyg/hal/hal_verde.h>          // Variant specific hardware definitions
61
#include <cyg/hal/hal_mmu.h>            // MMU definitions
62
#include <cyg/hal/hal_mm.h>             // more MMU definitions
63
#include <cyg/hal/iq80321.h>            // Platform specific hardware definitions
64
#include <cyg/hal/hal_spd.h>
65
 
66
#if defined(CYG_HAL_STARTUP_ROM)
67
#define PLATFORM_SETUP1  _platform_setup1
68
#define PLATFORM_EXTRAS  <cyg/hal/hal_platform_extras.h>
69
#define CYGHWR_HAL_ARM_HAS_MMU
70
 
71
.macro  NOPs count
72
        .rept \count
73
        nop
74
        nop
75
        .endr
76
.endm
77
 
78
// ------------------------------------------------------------------------
79
// Define macro used to diddle the LEDs during early initialization.
80
// Can use r0+r1.  Argument in \x.
81
#define CYGHWR_LED_MACRO                                     \
82
        b       667f                                        ;\
83
   666:                                                     ;\
84
        .byte   DISPLAY_0, DISPLAY_1, DISPLAY_2, DISPLAY_3  ;\
85
        .byte   DISPLAY_4, DISPLAY_5, DISPLAY_6, DISPLAY_7  ;\
86
        .byte   DISPLAY_8, DISPLAY_9, DISPLAY_A, DISPLAY_B  ;\
87
        .byte   DISPLAY_C, DISPLAY_D, DISPLAY_E, DISPLAY_F  ;\
88
   667:                                                     ;\
89
        ldr     r0, =666b                                   ;\
90
        add     r0, r0, #\x                                 ;\
91
        ldrb    r1, [r0]                                    ;\
92
        ldr     r0, =DISPLAY_RIGHT                          ;\
93
        str     r1, [r0]
94
 
95
#define PAUSE                            \
96
        ldr     r1,=0x8000;              \
97
  555:  sub     r1,r1,#1;                \
98
        cmp     r1,#0;                   \
99
        bne     555b;
100
 
101
#define DCACHE_SIZE (32 * 1024)
102
 
103
// ------------------------------------------------------------------------
104
// MCU Register Values
105
 
106
// ------------------------------------------------------------------------
107
// This macro represents the initial startup code for the platform        
108
        .macro _platform_setup1
109
        // This is where we wind up immediately after reset. At this point, we
110
        // are executing from the boot address (0x00000000), not the eventual
111
        // flash address. Do some basic setup using position independent code
112
        // then switch to real flash address
113
 
114
// FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME 
115
// This is a quick and dirty workaround to an apparent gas/ld
116
// bug. The computed UNMAPPED_PTR(reset_vector) is off by 0x20.
117
        .rept 0x20/4
118
        nop
119
        .endr
120
// FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME 
121
 
122
        ldr     r0,=(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_SUPERVISOR_MODE)
123
        msr     cpsr, r0
124
 
125
        // enable coprocessor access
126
        ldr     r0, =0x20c1              // CP13,CP7,CP6,CP0
127
        mcr     p15, 0, r0, c15, c1, 0
128
 
129
        // Drain write and fill buffer
130
        mcr     p15, 0, r0, c7, c10, 4
131
        CPWAIT  r0
132
 
133
        // Setup PBIU chip selects
134
        ldr     r8, =PBIU_PBCR
135
 
136
        ldr     r2, =PBLR_SZ_4K
137
        ldr     r1, =IQ80321_UART_ADDR | PBAR_FLASH | PBAR_RCWAIT_20 | PBAR_ADWAIT_20 | PBAR_BUS_8
138
        str     r1, [r8, #0x10]  // PBIU_PBAR1
139
        str     r2, [r8, #0x14]  // PBIU_PBLR1
140
 
141
        ldr     r1, =IQ80321_DISPLAY_RIGHT_ADDR | PBAR_FLASH | PBAR_RCWAIT_20 | PBAR_ADWAIT_20 | PBAR_BUS_32
142
        str     r1, [r8, #0x18]  // PBIU_PBAR2
143
        str     r2, [r8, #0x1C]  // PBIU_PBLR2
144
 
145
        ldr     r1, =IQ80321_DISPLAY_LEFT_ADDR | PBAR_FLASH | PBAR_RCWAIT_20 | PBAR_ADWAIT_20 | PBAR_BUS_32
146
        str     r1, [r8, #0x20]  // PBIU_PBAR3
147
        str     r2, [r8, #0x24]  // PBIU_PBLR3
148
 
149
        ldr     r1, =IQ80321_ROTARY_SWITCH_ADDR | PBAR_FLASH | PBAR_RCWAIT_20 | PBAR_ADWAIT_20 | PBAR_BUS_32
150
        str     r1, [r8, #0x28]  // PBIU_PBAR4
151
        str     r2, [r8, #0x2C]  // PBIU_PBLR4
152
 
153
        ldr     r1, =IQ80321_BATTERY_STATUS_ADDR | PBAR_FLASH | PBAR_RCWAIT_20 | PBAR_ADWAIT_20 | PBAR_BUS_32
154
        str     r1, [r8, #0x30]  // PBIU_PBAR5
155
        str     r2, [r8, #0x34]  // PBIU_PBLR5
156
 
157
        // ====================================================================
158
        HEX_DISPLAY r0, r1, DISPLAY_A, DISPLAY_1
159
        // ====================================================================
160
 
161
        // Enable the Icache
162
        mrc     p15, 0, r0, c1, c0, 0
163
        orr     r0, r0, #MMU_Control_I
164
        mcr     p15, 0, r0, c1, c0, 0
165
        CPWAIT  r0
166
 
167
        // ====================================================================
168
        HEX_DISPLAY r0, r1, DISPLAY_A, DISPLAY_2
169
        // ====================================================================
170
 
171
        // value to write into PBIU_PBAR0 to establish runtime flash address
172
        ldr     r1, =IQ80321_FLASH_ADDR | PBAR_FLASH | PBAR_RCWAIT_20 | PBAR_ADWAIT_20 | PBAR_BUS_16
173
 
174
        // value to write into PBIU_PBLR0 to establish runtime flash address
175
        ldr     r2, =PBLR_SZ_8M
176
 
177
        // value to load into pc to jump to real runtime address
178
        ldr     r7, =1f
179
 
180
        ldr     r9, =IQ80321_DISPLAY_RIGHT_ADDR
181
        ldr     r10,=IQ80321_DISPLAY_LEFT_ADDR
182
        ldr     r11,=DISPLAY_F
183
 
184
        b       icache_boundary
185
        .p2align 5
186
icache_boundary:
187
        // Here is where we switch from boot address (0x000000000) to the
188
        // actual flash runtime address. We align to cache boundary so we
189
        // execute from cache during the switchover. Cachelines are 8 words.
190
        str     r1, [r8, #0x08]  // PBIU_PBAR0
191
        str     r2, [r8, #0x0c]  // PBIU_PBLR0
192
        nop
193
        nop
194
        mov     pc, r7
195
        str     r11, [r9]    // We should never reach this point. If we do,
196
        str     r11, [r10]   // display FF and loop forever.
197
    0:  b       0b
198
    1:
199
        // ====================================================================
200
        HEX_DISPLAY r0, r1, DISPLAY_A, DISPLAY_3
201
        // ====================================================================
202
 
203
        // Set the TTB register
204
        ldr     r0, =mmu_table
205
        mcr     p15, 0, r0, c2, c0, 0
206
 
207
        // Enable permission checks in all domains
208
        ldr     r0, =0x55555555
209
        mcr     p15, 0, r0, c3, c0, 0
210
 
211
        // Enable the MMU
212
        mrc     p15, 0, r0, c1, c0, 0
213
        orr     r0, r0, #MMU_Control_M
214
        orr     r0, r0, #MMU_Control_R
215
        mcr     p15, 0, r0, c1, c0, 0
216
        CPWAIT  r0
217
 
218
        // ====================================================================
219
        HEX_DISPLAY r0, r1, DISPLAY_A, DISPLAY_4
220
        // ====================================================================
221
 
222
        //
223
        // ***  I2C interface initialization ***
224
        //
225
 
226
        // Pointers to I2C Registers
227
        ldr     r11, =I2C_BASE0         // base address of the I2C unit
228
 
229
        //  Write 0 to avoid interfering with I2C bus.
230
        //  (See GPIO section in 80321 manual)
231
        ldr     r2, =GPIO_GPOD
232
        mov     r3, #0
233
        strb    r3, [r2]
234
 
235
        // Reset I2C Unit
236
        mov     r1, #ICR_RESET
237
        str     r1, [r11, #I2C_ICR0]
238
        ldr     r1, =0x7ff
239
        str     r1, [r11, #I2C_ISR0]
240
        mov     r1, #0
241
        str     r1, [r11, #I2C_ICR0]
242
 
243
        //  Setup I2C Slave Address Register
244
        mov     r1, #I2C_DEVID          // Load slave address r1.
245
        str     r1, [r11, #I2C_ISAR0]   // Save the value 0x02 (I2C_DEVID) in the register.
246
 
247
        //  Enable I2C Interface Unit - status will be polled
248
        ldr     r1, =ICR_GCALL | ICR_ENB | ICR_SCLENB
249
        str     r1, [r11, #I2C_ICR0]
250
 
251
        //
252
        //  *** Now read the SPD Data ***
253
        //
254
 
255
        // Initialize regs for loop
256
        mov     r4, #0          // SDRAM size
257
        mov     r5, #0          // R5 has running checksum calculation
258
        mov     r6, #0          // Counter incremented before byte is read
259
        mov     r7, #64         // Number of bytes to read in the Presence Detect EEPROM of SDRAM
260
        mov     r8, #0          // Flags: b0-b6 == bankcnt, b7 = x16 flag
261
        mov     r9, #RFR_15_6us // Refresh rate (assume normal 15.6us)
262
        mov     r10, #0         // Bank size
263
        mov     r14, #0         // ECC flag
264
 
265
        ldr     r0, [r11, #I2C_ISR0]    // Load I2C Status Reg into R0
266
        str     r0, [r11, #I2C_ISR0]    // Clear status
267
 
268
        /*  FREE REGISTERS ARE R0 - R3 */
269
 
270
        // *** Put out address, with WRITE mode ***
271
 
272
        // Set SDRAM module address and write mode
273
        mov     r1, #SDRAM_DEVID        // Load slave address for SDRAM module. 0xA2 (Presence Detect Data)
274
        bic     r1, r1, #IDBR_MODE      // Clear read bit (bit #0)
275
        str     r1, [r11, #I2C_IDBR0]   // Store to data register
276
 
277
        // Initiate dummy write to set EEPROM pointer to 0
278
        ldr     r1, [r11, #I2C_ICR0]    // read the current Control Register value
279
        bic     r1, r1, #ICR_STOP       // No stop bit
280
        orr     r1, r1, #ICR_START | ICR_TRANSFER
281
        str     r1, [r11, #I2C_ICR0]    // Store to control register
282
 
283
        // ====================================================================
284
        HEX_DISPLAY r0, r1, DISPLAY_9, DISPLAY_0
285
        // ====================================================================
286
 
287
        // Wait for transmit empty status
288
        mov     r1, #I2C_TIMOUT         // Initialize I2C timeout counter
289
    0:   subs    r1, r1, #1              // Increment I2C timeout counter (r1 = r1 + 1)
290
        beq     i2c_error               // Kick out of SDRAM initialization if timeout occurs
291
        ldr     r0, [r11, #I2C_ISR0]    // Load I2C Status Reg into R0
292
        ands    r3, r0, #ISR_EMPTY      // Bit #6 is checked, IDBR Transmit Empty
293
        beq     0b                      // If bit = 0 then branch to 0 and check again
294
        str     r0, [r11, #I2C_ISR0]    // Write back status to clear
295
 
296
        // ====================================================================
297
        HEX_DISPLAY r0, r1, DISPLAY_9, DISPLAY_1
298
        // ====================================================================
299
 
300
        // Write pointer register on EEPROM to 0x00000000
301
        mov     r1, #0                  // Load base address of SDRAM module EEPROM
302
        str     r1, [r11, #I2C_IDBR0]   // Store to data register
303
 
304
        //  Send address to EEPROM
305
        ldr     r1, [r11, #I2C_ICR0]    // read the current Control Register value
306
        bic     r1, r1, #ICR_START | ICR_STOP
307
        orr     r1, r1, #ICR_TRANSFER   // Set transfer bit - bit is self_clearing
308
        str     r1, [r11, #I2C_ICR0]    // Store to control register
309
 
310
        // ====================================================================
311
        HEX_DISPLAY r0, r1, DISPLAY_9, DISPLAY_2
312
        // ====================================================================
313
 
314
        // Wait for transmit empty status
315
        mov     r1, #I2C_TIMOUT         // Initialize I2C timeout counter
316
    0:   subs    r1, r1, #1              // Increment I2C timeout counter (r1 = r1 + 1)
317
        beq     i2c_error               // Kick out of SDRAM initialization if timeout occurs
318
        ldr     r0, [r11, #I2C_ISR0]    // Load I2C Status Reg into R0
319
        ands    r3, r0, #ISR_EMPTY      // Bit #6 is checked, IDBR Transmit Empty
320
        beq     0b                      // If bit = 0 then branch to 0 and check again
321
        str     r0, [r11, #I2C_ISR0]    // Write back status to clear
322
1:
323
        // ====================================================================
324
        HEX_DISPLAY r0, r1, DISPLAY_9, DISPLAY_3
325
        // ====================================================================
326
 
327
        // *** Read SDRAM PD data ***
328
 
329
        // *** Put out address, with READ mode ***
330
 
331
        //  Set SDRAM module address and read mode
332
        mov     r0, #SDRAM_DEVID        // Load slave address for SDRAM module (0xA2)
333
        orr     r1, r0, #IDBR_MODE      // Set read bit (bit #0)
334
        str     r1, [r11, #I2C_IDBR0]   // Store to data register
335
 
336
        //  Send next read request
337
        ldr     r1, [r11, #I2C_ICR0]    // read the current Control Register value
338
        bic     r1, r1, #ICR_STOP       // No stop bit
339
        orr     r1, r1, #ICR_START | ICR_TRANSFER
340
        str     r1, [r11, #I2C_ICR0]    // Store to control register
341
 
342
        // Wait for transmit empty status
343
        mov     r1, #I2C_TIMOUT         // Initialize I2C timeout counter
344
    0:   subs    r1, r1, #1              // Increment I2C timeout counter (r1 = r1 + 1)
345
        beq     i2c_error               // Kick out of SDRAM initialization if timeout occurs
346
        ldr     r0, [r11, #I2C_ISR0]    // Load I2C Status Reg into R0
347
        ands    r3, r0, #ISR_EMPTY      // Bit #6 is checked, IDBR Transmit Empty
348
        beq     0b                      // If bit = 0 then branch to 0 and check again
349
        str     r0, [r11, #I2C_ISR0]    // Write back status to clear
350
 
351
        // ====================================================================
352
        HEX_DISPLAY r0, r1, DISPLAY_9, DISPLAY_4
353
        // ====================================================================
354
 
355
  spd_loop:
356
        // read the next Byte of Serial Presence Detect data
357
 
358
        ldr     r1, [r11, #I2C_ICR0]    // read the current Control Register value
359
        bic     r1, r1, #ICR_START      // No start bit (already started)
360
        orr     r1, r1, #ICR_TRANSFER   // Set transfer bit - bit is self_clearing
361
 
362
        // we have to set NACK before reading the last byte
363
        add     r2, r6, #1
364
        cmp     r2, r7                  // r7 = 64 (decimal) so if r6 = 64, this is the last byte to be read
365
        orreq   r1, r1, #ICR_ACK | ICR_STOP
366
        str     r1, [r11, #I2C_ICR0]    // Store to control register
367
 
368
        // Wait for read full status
369
        mov     r1, #I2C_TIMOUT         // Initialize I2C timeout counter
370
    0:   subs    r1, r1, #1              // decrement timeout
371
        beq     i2c_error               // Kick out of SDRAM initialization if timeout occurs
372
        ldr     r0, [r11, #I2C_ISR0]    // Load I2C Status Reg into R0
373
        ands    r3, r0, #ISR_FULL       // Bit #7 is checked
374
        beq     0b                      // If bit = 0 then branch to 0 and check again
375
        str     r0, [r11, #I2C_ISR0]    // Write back status to clear
376
 
377
        ldr     r1, [r11, #I2C_IDBR0]   // Read the byte
378
 
379
        // check for checksum byte
380
        subs    r2, r6, #SPD_CHECKSUM
381
        addne   r5, r5, r1              // Add it to the checksum if not the checksum byte
382
        bne     1f                      // skip checksum comparison
383
        and     r5, r5, #0xff           //      against the calculated checksum
384
        cmp     r1, r5
385
        beq     spd_continue
386
 
387
        // bad checksum
388
        HEX_DISPLAY r2, r3, DISPLAY_7, DISPLAY_7
389
        0: b 0b
390
 
391
    1:
392
        // Check for bank count byte
393
        subs    r2, r6, #SPD_BANKCNT
394
        moveq   r8, r1                  // Store bank count
395
        beq     spd_continue
396
 
397
        // Check for ECC
398
        subs    r2, r6, #SPD_CONFIG
399
        bne     1f
400
        subs    r2, r1, #2
401
        addeq   r14, r14, #1
402
        b       spd_continue
403
    1:
404
 
405
        // Check for refresh rate
406
        subs    r2, r6, #SPD_REFRESH
407
        bne     1f
408
 
409
        ands    r2, r1, #0x7f
410
        moveq   r9, #RFR_15_6us
411
        subs    r3, r2, #1
412
        moveq   r9, #RFR_3_9us
413
        subs    r3, r2, #2
414
        moveq   r9, #RFR_7_8us
415
 
416
        b       spd_continue
417
 
418
    1:
419
        // Check for SDRAM width byte
420
        subs    r2, r6, #SPD_SDRAM_WIDTH
421
        bne     1f
422
 
423
        ands    r2, r1, #0x10           // Check for data width of 16
424
        orr     r8, r8, r2, lsl #3      // set b7 in r8 if x16
425
 
426
#if 0 // drive strength doesn't depend on width
427
        ldreq   r2, =x8_table           // x8 if bit not set
428
        ldrne   r2, =x16_table          // x16 if bit not set
429
        b       init_drive_strength
430
 
431
    x16_table:
432
        .word   0x18    // Data Bus Pull Up
433
        .word   0x18    // Data Bus Pull Down
434
        .word   0x22    // Clock Pull Up
435
        .word   0x20    // Clock Pull Down
436
        .word   0x30    // Clock Enable Pull Up
437
        .word   0x30    // Clock Enable Pull Down
438
        .word   0x30    // Chip Select Pull Up
439
        .word   0x30    // Chip Select Pull Down
440
        .word   0x18    // Receive Enable Pull Up
441
        .word   0x18    // Receive Enable Pull Down
442
        .word   0x3c    // Address Bus Pull Up
443
        .word   0x3c    // Address Bus Pull Down
444
 
445
    x8_table:
446
        .word   0x18    // Data Bus Pull Up
447
        .word   0x18    // Data Bus Pull Down
448
        .word   0x22    // Clock Pull Up
449
        .word   0x20    // Clock Pull Down
450
        .word   0x30    // Clock Enable Pull Up
451
        .word   0x30    // Clock Enable Pull Down
452
        .word   0x30    // Chip Select Pull Up
453
        .word   0x30    // Chip Select Pull Down
454
        .word   0x18    // Receive Enable Pull Up
455
        .word   0x18    // Receive Enable Pull Down
456
        .word   0x3c    // Address Bus Pull Up
457
        .word   0x3c    // Address Bus Pull Down
458
#else
459
        b       spd_continue
460
 
461
    registered_table:
462
        .word   13      // Data Bus Pull Up
463
        .word   13      // Data Bus Pull Down
464
        .word   34      // Clock Pull Up
465
        .word   32      // Clock Pull Down
466
        .word   48      // Clock Enable Pull Up
467
        .word   48      // Clock Enable Pull Down
468
        .word   13      // Chip Select Pull Up
469
        .word   13      // Chip Select Pull Down
470
        .word   13      // Receive Enable Pull Up
471
        .word   13      // Receive Enable Pull Down
472
        .word   13      // Address Bus Pull Up
473
        .word   13      // Address Bus Pull Down
474
 
475
    unbuffered_table:
476
        .word   13      // Data Bus Pull Up
477
        .word   13      // Data Bus Pull Down
478
        .word   34      // Clock Pull Up
479
        .word   32      // Clock Pull Down
480
        .word   48      // Clock Enable Pull Up
481
        .word   48      // Clock Enable Pull Down
482
        .word   24      // Chip Select Pull Up
483
        .word   24      // Chip Select Pull Down
484
        .word   13      // Receive Enable Pull Up
485
        .word   13      // Receive Enable Pull Down
486
        .word   24      // Address Bus Pull Up
487
        .word   24      // Address Bus Pull Down
488
#endif
489
 
490
    init_drive_strength:
491
 
492
        ldr     r1, =MCU_DBUDSR
493
        mov     r3, #12         // 12 contiguous registers to set
494
    0:
495
        ldr     r0, [r2], #4    // load value
496
        str     r0, [r1], #4    // store to register
497
        subs    r3, r3, #1
498
        bne     0b
499
        b       spd_continue
500
    1:
501
 
502
        // Check for module attribute byte
503
        subs    r2, r6, #SPD_MOD_ATTRIB
504
        bne     1f
505
        ldr     r0, =MCU_SDCR
506
        mov     r2, #SDCR_INIT_VAL
507
        ands    r3, r1, #SPD_ATTRIB_REG_CTL  // check for registered modules
508
        beq     2f
509
        orr     r2, r2, #2
510
        str     r2, [r0]
511
        ldr     r2, =registered_table
512
        b       init_drive_strength
513
    2:
514
        str     r2, [r0]
515
        ldr     r2, =unbuffered_table
516
        b       init_drive_strength
517
    1:
518
 
519
        // Check for bank size byte
520
        subs    r2, r6, #SPD_BANKSZ
521
        bne     1f
522
        mov     r10, r1, lsl #2         // Store bank size in Mbytes (shift left 2 bits)
523
        and     r3, r8, #0x7f           // isolate bank count     
524
        mul     r2, r3, r10             // Multiply by bank count to get DRAM size in MB
525
        mov     r4, r2, lsl #20         // Convert size to bytes  - r4 contains DRAM size in bytes
526
        b       spd_continue
527
    1:
528
 
529
  spd_continue:
530
        // Continue reading bytes if not done
531
        add     r6, r6, #1      // Increment byte counter
532
        cmp     r6, r7
533
        bne     spd_loop
534
 
535
        b       i2c_disable
536
 
537
        .ltorg
538
    i2c_error:
539
        // hit the leds if an error occurred
540
        HEX_DISPLAY r2, r3, DISPLAY_5, DISPLAY_5
541
        b i2c_error
542
    i2c_disable:
543
        //  Disable I2C Interface Unit
544
        ldr     r1, [r11, #I2C_ICR0] 
545
        bic     r1, r1, #ICR_ENB | ICR_SCLENB   // Disable I2C unit
546
        str     r1, [r11, #I2C_ICR0]
547
 
548
        // At this point, r4 = SDRAM size in bytes, r8 = Bank count, r10 = bank size in MB
549
 
550
 
551
        // *** SDRAM setup ***
552
 
553
        // Set the DDR SDRAM Base Register - SDBR (the lowest address for memory)
554
        ldr     r0, =MCU_SDBR
555
        mov     r1, #SDRAM_PHYS_BASE
556
        str     r1, [r0]
557
 
558
        // Set up bank 0 register
559
        subs    r1, r10, #32
560
        moveq   r0, #SBR_32MEG          // Program SDRAM Bank0 Boundary register to 32 MB
561
        beq     1f
562
        subs    r1, r10, #64            // do we have 64 MB banks?
563
        moveq   r0, #SBR_64MEG          // Program SDRAM Bank0 Boundary register to 64 MB
564
        beq     1f
565
        subs    r1, r10, #128           // do we have 128 MB banks?
566
        moveq   r0, #SBR_128MEG         // Program SDRAM Bank0 Boundary register to 128 MB
567
        beq     1f
568
        subs    r1, r10, #256           // do we have 256 MB banks?
569
        moveq   r0, #SBR_256MEG         // Program SDRAM Bank0 Boundary register to 64 MB
570
        beq     1f
571
        subs    r1, r10, #512           // do we have 512 MB banks?
572
        moveq   r0, #SBR_512MEG         // Program SDRAM Bank0 Boundary register to 64 MB
573
        beq     1f
574
 
575
     bank_err:
576
        HEX_DISPLAY r2, r3, DISPLAY_F, DISPLAY_F
577
        b       bank_err
578
    1:
579
        mov     r1, #SDRAM_PHYS_BASE
580
        mov     r2, #0x1f
581
        and     r2, r2, r1, lsr #25
582
        add     r2, r2, r0
583
 
584
        ands    r1, r8, #0x80
585
        and     r8, r8, #0x7f
586
        beq     1f
587
        // x16
588
        subs    r1, r10, #128
589
        addeq   r2, r2, #0x80000000
590
    1:
591
        ldr     r1, =MCU_SBR0
592
        str     r2, [r1]                // store SBR0
593
 
594
        subs    r1, r8, #2              // do we have 2 banks???
595
        addeq   r2, r2, r0              // SBR1 == SBR0+r0 if two banks
596
        ldr     r1, =MCU_SBR1
597
        str     r2, [r1]
598
 
599
        // ====================================================================
600
        HEX_DISPLAY r0, r1, DISPLAY_A, DISPLAY_5
601
        // ====================================================================
602
 
603
        DELAY_FOR 0x1800000, r0
604
 
605
        //  Disable the refresh counter by setting the RFR to zero.
606
        // (from section 7.2.2.6 of the Verde technical specification)
607
        ldr     r0, =MCU_RFR
608
        mov     r1, #0
609
        str     r1, [r0]
610
 
611
        // Issue one NOP cycle after the 200 us device deselect. A NOP is 
612
        // accomplished by setting the SDIR to 0101.
613
        ldr     r0, =MCU_SDIR
614
        mov     r1, #SDIR_CMD_NOP
615
        str     r1, [r0]
616
 
617
        // Issue a precharge-all command to the DDR SDRAM interface by setting 
618
        // the SDIR to 0100.
619
        mov     r1, #SDIR_CMD_PRECHARGE_ALL
620
        str     r1, [r0]
621
 
622
        // Issue an extended-mode-register-set command to enable the DLL by 
623
        // writing 0110 to the SDIR.
624
        NOPs    8
625
 
626
        mov     r1, #SDIR_CMD_ENABLE_DLL
627
        str     r1, [r0]
628
 
629
        // After waiting T mrd cycles (4 clocks at 200 MHz), issue a 
630
        // mode-register-set command by writing to the SDIR to program the DDR 
631
        // SDRAM parameters and to Reset the DLL. Setting the SDIR to 0010 
632
        // programs the MCU for CAS Latency of two while setting the SDIR to 0011
633
        // programs the MCU for CAS Latency of two and one-half. The MCU supports 
634
        // the following DDR SDRAM mode parameters:
635
        //   a. CAS Latency (CL) = two or two and one-half
636
        //   b. Wrap Type (WT) = Sequential
637
        //   c. Burst Length (BL) = four
638
        NOPs    8
639
 
640
        mov     r1, #SDIR_CMD_CAS_LAT_2_A   // Set CAS Latency to 2
641
        str     r1, [r0]
642
 
643
        // After waiting T mrd cycles (4 clocks at 200 MHz), issue a precharge-all
644
        // command to the DDR SDRAM interface by setting the SDIR to 0100.
645
        NOPs    8
646
 
647
        mov     r1, #SDIR_CMD_PRECHARGE_ALL
648
        str     r1, [r0]
649
 
650
        // After waiting T rp cycles (4 clocks at 200 MHz), provide two 
651
        // auto-refresh cycles. An auto-refresh cycle is accomplished by 
652
        // setting the SDIR to 0111. Software must ensure at least T rfc 
653
        // cycles (16 clocks at 200 MHz) between each auto-refresh command.
654
        NOPs    8
655
 
656
        mov     r1, #SDIR_CMD_AUTO_REFRESH      // 1st of two auto-refresh cycle commands
657
        str     r1, [r0]
658
 
659
        NOPs    8
660
 
661
        str     r1, [r0]                        // 2nd of two auto-refresh cycle commands
662
 
663
        NOPs    8
664
 
665
        // Issues a mode-register-set command by writing to the SDIR to program the
666
        // DDR SDRAM parameters without resetting the DLL. Setting the SDIR to 0000 
667
        // programs the MCU for CAS Latency of two while setting the SDIR to 0001
668
        // programs the MCU for CAS Latency of two and one-half. The MCU supports 
669
        // the following DDR SDRAM mode parameters:
670
        //   a. CAS Latency (CL) = two or two and one-half
671
        //   b. Wrap Type (WT) = Sequential
672
        //   c. Burst Length (BL) = four
673
        mov     r1, #SDIR_CMD_CAS_LAT_2_B       // Set CAS Latency to 2
674
        str     r1, [r0]
675
 
676
        NOPs    8
677
 
678
        mov     r1, #0xF                        // DDR Normal Operation
679
        str     r1, [r0]
680
 
681
        // Re-enable the refresh counter by setting the RFR to the required value.
682
        //
683
        ldr     r0, =MCU_RFR
684
        str     r9, [r0]
685
 
686
        // DSDR   - Data Strobe Delay Register                       (Section 7.6.25)
687
        ldr     r0, =MCU_DSDR
688
        ldr     r1, =DSDR_REC_VAL
689
        str     r1, [r0]
690
 
691
        // REDR   - Receive Enable Delay Register                    (Section 7.6.26)
692
        ldr     r0, =MCU_REDR
693
        ldr     r1, =REDR_REC_VAL
694
        str     r1, [r0]
695
 
696
        // ====================================================================
697
        HEX_DISPLAY r0, r1, DISPLAY_A, DISPLAY_6
698
        // ====================================================================
699
 
700
        // delay before using SDRAM 
701
        DELAY_FOR 0x1800000, 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
        // Enable branch target buffer
710
        mrc     p15, 0, r0, c1, c0, 0
711
        orr     r0, r0, #MMU_Control_BTB
712
        mcr     p15, 0, r0, c1, c0, 0
713
        CPWAIT  r0
714
 
715
        mcr     p15, 0, r0, c7, c10, 4  // drain the write & fill buffers
716
        CPWAIT  r0
717
 
718
        mcr     p15, 0, r0, c7, c7, 0   // flush Icache, Dcache and BTB
719
        CPWAIT  r0
720
 
721
        mcr     p15, 0, r0, c8, c7, 0   // flush instuction and data TLBs
722
        CPWAIT  r0
723
 
724
        mcr     p15, 0, r0, c7, c10, 4   // drain the write & fill buffers
725
        CPWAIT r0
726
 
727
        // ====================================================================
728
        HEX_DISPLAY r0, r1, DISPLAY_S, DISPLAY_L
729
        // ====================================================================
730
 
731
        ldr     r0, =MCU_ECTST           // clear test register
732
        mov     r1, #0
733
        str     r1, [r0]
734
 
735
        ldr     r0, =MCU_ECCR
736
        mov     r1, #0x0                 // disable ECC, disable reporting
737
        str     r1, [r0]
738
 
739
#ifdef CYGSEM_HAL_ARM_IQ80321_BATTERY_TEST
740
        //  Battery Backup SDRAM Memory Test
741
        //  Move test pattern into register prior to memory scrub
742
        ldr     r9, =SDRAM_BATTERY_TEST_ADDR
743
        ldr     r10, [r9]
744
#endif
745
 
746
        orrs    r14, r14, r14
747
        beq     no_ecc1
748
 
749
        ldr     r0, =MCU_ECCR
750
        mov     r1, #0x8                 // enable ECC, disable reporting
751
        str     r1, [r0]
752
 
753
  no_ecc1:
754
 
755
#ifdef CYGSEM_HAL_ARM_IQ80321_CLEAR_PCI_RETRY
756
        // Minimally setup ATU and release "retry" bit.
757
        ldr     r1, =ATU_IATVR2
758
        mov     r0, #SDRAM_PHYS_BASE
759
        str     r0, [r1]
760
        ldr     r0, =0xffffffff
761
        sub     r1, r4, #1
762
        sub     r0, r0, r1
763
        bic     r0, r0, #0x3f
764
        ldr     r1, =ATU_IALR2
765
        str     r0, [r1]
766
        ldr     r0, =((0xFFFFFFFF - ((64 * 1024 * 1024) - 1)) & 0xFFFFFFC0)
767
        ldr     r1, =ATU_IALR1
768
        str     r0, [r1]
769
        mov     r0, #0xc
770
        ldr     r1, =ATU_IABAR1
771
        str     r0, [r1]
772
        ldr     r1, =ATU_IABAR2
773
        str     r0, [r1]
774
        mov     r0, #0
775
        ldr     r1, =ATU_IAUBAR1
776
        str     r0, [r1]
777
        ldr     r1, =ATU_PCSR
778
        ldr     r0, [r1]
779
        and     r13, r0, #4     // save retry bit for later
780
        bic     r0, r0, #4
781
        str     r0, [r1]
782
#endif
783
 
784
        // scrub init
785
        mov     r12, r4         // size of memory to scrub
786
        mov     r8, r4          // save DRAM size
787
        mov     r0, #0
788
        mov     r1, #0
789
        mov     r2, #0
790
        mov     r3, #0
791
        mov     r4, #0
792
        mov     r5, #0
793
        mov     r6, #0
794
        mov     r7, #0
795
 
796
        ldr     r11, =SDRAM_UNCACHED_BASE
797
 
798
        // scrub Loop
799
    0:
800
        stmia   r11!, {r0-r7}
801
        subs    r12, r12, #32
802
        bne     0b
803
 
804
        // ====================================================================
805
        HEX_DISPLAY r0, r1, DISPLAY_S, DISPLAY_E
806
        // ====================================================================
807
 
808
        // ====================================================================
809
        HEX_DISPLAY r0, r1, DISPLAY_A, DISPLAY_7
810
        // ====================================================================
811
 
812
        // clean, drain, flush the main Dcache
813
        ldr     r1, =DCACHE_FLUSH_AREA  // use a CACHEABLE area of
814
                                        // memory that's mapped above SDRAM
815
        mov     r0, #1024               // number of lines in the Dcache
816
    0:
817
        mcr     p15, 0, r1, c7, c2, 5   // allocate a Dcache line
818
        add     r1, r1, #32             // increment to the next cache line
819
        subs    r0, r0, #1              // decrement the loop count
820
        bne     0b
821
 
822
        // ====================================================================
823
        HEX_DISPLAY r0, r1, DISPLAY_A, DISPLAY_8
824
        // ====================================================================
825
 
826
        // clean, drain, flush the mini Dcache
827
        ldr     r2, =DCACHE_FLUSH_AREA + DCACHE_SIZE
828
        mov     r0, #64                 // number of lines in the Dcache
829
    0:
830
        mcr     p15, 0, r2, c7, c2, 5   // allocate a Dcache line
831
        add     r2, r2, #32          // increment to the next cache line
832
        subs    r0, r0, #1              // decrement the loop count
833
        bne     0b
834
 
835
        mcr     p15, 0, r0, c7, c6, 0   // flush Dcache
836
        CPWAIT  r0
837
 
838
        mcr     p15, 0, r0, c7, c10, 4  // drain the write & fill buffers
839
        CPWAIT  r0
840
 
841
        // ====================================================================
842
        HEX_DISPLAY r0, r1, DISPLAY_A, DISPLAY_9
843
        // ====================================================================
844
        orrs    r14, r14, r14
845
        beq     no_ecc2
846
 
847
        ldr     r0, =MCU_MCISR
848
        mov     r1, #7
849
        str     r1, [r0]
850
 
851
        ldr     r0, =MCU_ECCR
852
        ldr     r1, =0x0f                        // enable ECC
853
        str     r1, [r0]
854
 
855
  no_ecc2:
856
 
857
        // ====================================================================
858
        HEX_DISPLAY r0, r1, DISPLAY_A, DISPLAY_A
859
        // ====================================================================
860
 
861
#ifdef CYGSEM_HAL_ARM_IQ80321_BATTERY_TEST
862
        // Battery Backup SDRAM Memory Test
863
        // Store test pattern back into memory
864
        str     r10, [r9]
865
#endif
866
 
867
        // Save SDRAM size
868
        ldr     r1, =hal_dram_size  /* [see hal_intr.h] */
869
        str     r8, [r1]
870
 
871
#ifdef CYGSEM_HAL_ARM_IQ80321_CLEAR_PCI_RETRY
872
        // Save boot time retry flag.
873
        ldr     r1, =hal_pcsr_cfg_retry
874
        str     r13, [r1]
875
#endif
876
 
877
        // Move mmu tables into RAM so page table walks by the cpu
878
        // don't interfere with FLASH programming.
879
        ldr     r0, =mmu_table
880
        add     r2, r0, #0x4000         // End of tables
881
        mov     r1, #SDRAM_BASE
882
        orr     r1, r1, #0x4000         // RAM tables
883
 
884
        // everything can go as-is
885
    1:
886
        ldr     r3, [r0], #4
887
        str     r3, [r1], #4
888
        cmp     r0, r2
889
        bne     1b
890
 
891
        // ====================================================================
892
        HEX_DISPLAY r0, r1, DISPLAY_A, DISPLAY_B
893
        // ====================================================================
894
 
895
        // clean, drain, flush the main Dcache
896
        ldr     r1, =DCACHE_FLUSH_AREA  // use a CACHEABLE area of memory
897
        mov     r0, #1024               // number of lines in the Dcache
898
    0:
899
        mcr     p15, 0, r1, c7, c2, 5   // allocate a Dcache line
900
        add     r1, r1, #32             // increment to the next cache line
901
        subs    r0, r0, #1              // decrement the loop count
902
        bne     0b
903
 
904
        // clean, drain, flush the mini Dcache
905
        ldr     r2, =DCACHE_FLUSH_AREA + DCACHE_SIZE
906
        mov     r0, #64                 // number of lines in the Dcache
907
    0:
908
        mcr     p15, 0, r2, c7, c2, 5   // allocate a Dcache line
909
        add     r2, r2, #32             // increment to the next cache line
910
        subs    r0, r0, #1              // decrement the loop count
911
        bne     0b
912
 
913
        mcr     p15, 0, r0, c7, c6, 0   // flush Dcache
914
        CPWAIT  r0
915
 
916
        mcr     p15, 0, r0, c7, c10, 4  // drain the write & fill buffers
917
        CPWAIT  r0
918
 
919
        // ====================================================================
920
        HEX_DISPLAY r0, r1, DISPLAY_A, DISPLAY_C
921
        // ====================================================================
922
 
923
        // Set the TTB register to DRAM mmu_table
924
        ldr     r0, =(SDRAM_PHYS_BASE | 0x4000) // RAM tables
925
        mov     r1, #0
926
        mcr     p15, 0, r1, c7, c5, 0             // flush I cache
927
        mcr     p15, 0, r1, c7, c10, 4           // drain WB
928
        mcr     p15, 0, r0, c2, c0, 0             // load page table pointer
929
        mcr     p15, 0, r1, c8, c7, 0             // flush TLBs
930
        CPWAIT  r0
931
 
932
        // ====================================================================
933
        HEX_DISPLAY r0, r1, DISPLAY_A, DISPLAY_D
934
        // ====================================================================
935
        .endm    // _platform_setup1
936
 
937
#else // defined(CYG_HAL_STARTUP_ROM)
938
#define PLATFORM_SETUP1
939
#endif
940
 
941
#define PLATFORM_VECTORS         _platform_vectors
942
        .macro  _platform_vectors
943
        .globl  hal_pcsr_cfg_retry
944
hal_pcsr_cfg_retry:   .long   0  // Boot-time value of PCSR Retry bit.
945
        .endm
946
 
947
/*---------------------------------------------------------------------------*/
948
/* end of hal_platform_setup.h                                               */
949
#endif /* CYGONCE_HAL_PLATFORM_SETUP_H */

powered by: WebSVN 2.1.0

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