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

Subversion Repositories openrisc_me

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

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