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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [arm/] [ebsa285/] [current/] [src/] [mem285.S] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// #========================================================================
2
// #
3
// #    mem285.S
4
// #
5
// #    StrongARM EBSA-285 memory setup
6
// #
7
// #========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later
16
// version.
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21
// for more details.
22
//
23
// You should have received a copy of the GNU General Public License
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
26
//
27
// As a special exception, if other files instantiate templates or use
28
// macros or inline functions from this file, or you compile this file
29
// and link it with other works to produce a work based on this file,
30
// this file does not by itself cause the resulting work to be covered by
31
// the GNU General Public License. However the source code for this file
32
// must still be made available in accordance with section (3) of the GNU
33
// General Public License v2.
34
//
35
// This exception does not invalidate any other reasons why a work based
36
// on this file might be covered by the GNU General Public License.
37
// -------------------------------------------
38
// ####ECOSGPLCOPYRIGHTEND####
39
// #========================================================================
40
// ######DESCRIPTIONBEGIN####
41
// #
42
// # Author(s):     Red Hat, hmt
43
// # Contributors:  Red Hat, hmt
44
// # Date:          1999-07-05
45
// # Purpose:       StrongARM EBSA-285 SDRAM initialization
46
// # Description:   SDRAM Initialization for Intel(R) SA-110 21285 Companion
47
// #                Chip
48
// #                Intel is a Registered Trademark of Intel Corporation.
49
// #                Other Brands and Trademarks are the property of their
50
// #                respective owners.
51
// #
52
// #####DESCRIPTIONEND####
53
// #
54
// #========================================================================
55
 
56
//      .file "mem285.S"
57
        .title "SDRAM Init for Intel(R) SA-110 21285 Companion Chip"
58
 
59
#include 
60
 
61
#include 
62
 
63
        .text
64
        .align     4
65
 
66
#define ARRAY_0_MODE_REGISTER     (SA110_SDRAM_ARRAY_0_MODE_REGISTER_BASE)
67
#define ARRAY_1_MODE_REGISTER     (SA110_SDRAM_ARRAY_1_MODE_REGISTER_BASE)
68
 
69
#define MODE_REGISTER_STEP (ARRAY_1_MODE_REGISTER - ARRAY_0_MODE_REGISTER)
70
 
71
        // [6:4] /CAS Latency is 2 (2)
72
        // [ 3 ] Burst Type is 0, Sequential
73
        // [2:0] Burst Length is 2, meaning 4
74
#define SDRAM_MODE_REGISTER_SETUP 0x22
75
        // Shifted left 2 because this is a word-address-offset!
76
#define SDRAM_MODE_REGISTER_SETUP_OFFSET ((SDRAM_MODE_REGISTER_SETUP) << 2)
77
 
78
 
79
#define SDRAM_TIMING_VALUE        (SA110_SDRAM_ROW_PRECHARGE_2_CYCLES    | \
80
                                   SA110_SDRAM_LAST_DATA_IN_3_CYCLES     | \
81
                                   SA110_SDRAM_RAS_TO_CAS_DELAY_2_CYCLES | \
82
                                   SA110_SDRAM_CAS_LATENCY_2_CYCLES      | \
83
                                   SA110_SDRAM_ROW_CYCLE_TIME_4_CYCLES   | \
84
                                   SA110_SDRAM_COMMAND_DRIVE_SAME_CYCLE)
85
 
86
#define SDRAM_TIMING_VALUE_MIN    (SDRAM_TIMING_VALUE                    | \
87
                                   SA110_SDRAM_REFRESH_INTERVAL_MIN)
88
 
89
#define SDRAM_TIMING_VALUE_NORMAL (SDRAM_TIMING_VALUE                    | \
90
                                   SA110_SDRAM_REFRESH_INTERVAL_NORMAL)
91
 
92
 
93
 
94
        /*
95
         * This subroutine sizes and configures up to four banks of SDRAM DIMMs.
96
         * It runs early without a stack.
97
         *
98
         * R0 - R9 are destroyed. All others preserved.
99
         * Except r11 which is also destroyed.
100
         *
101
         */
102
        .global __mem285_init
103
__mem285_init:
104
 
105
        /*
106
         * First we find out whether the SDRAMs are already initialized,
107
         * and if so, leave them alone.  RAM start implies just do the
108
         * sizing sums to return top of memory.
109
         */
110
        ldr     r0, =SA110_CONTROL_STATUS_BASE
111
 
112
#ifndef CYG_HAL_STARTUP_RAM
113
        // This is conditional even in ROM start for
114
        // a) testing ROM images eg. stubs in RAM really
115
        // b) cooperation with eg. POST code, so we are not really at reset
116
        ldr     r0, =SA110_CONTROL_STATUS_BASE
117
        ldr     r1, [r0, #SA110_SDRAM_TIMING_o]
118
        ldr     r2, =SDRAM_TIMING_VALUE_NORMAL
119
        cmps    r1, r2
120
        movne   r11, #0
121
        bne     12f
122
#endif  // ! defined CYG_HAL_STARTUP_RAM
123
 
124
        // Add up the sizes and return in r0:
125
        mov     r1, #SA110_SDRAM_ADDRESS_SIZE_ARRAY_0_o
126
        mov     r2, #0
127
        mov     r3, #1
128
    1:
129
        ldr     r4, [r0, r1]
130
        ands    r4, r4, #7              // if zero, no mem here
131
        addne   r2, r2, r3, asl r4      // tot up array sizes (in 1/2 Megs)
132
        add     r1, r1, #4
133
        cmps    r1, #(SA110_SDRAM_ADDRESS_SIZE_ARRAY_3_o + 4)
134
        blt     1b
135
 
136
        mov     r0, r2, asl #19         // get size into Mb
137
        mov     pc, lr
138
 
139
#ifndef CYG_HAL_STARTUP_RAM
140
 
141
    12:
142
        /*
143
         * Write to the SDRAM Timing Register in the 21285.  Disable
144
         * refresh totally.
145
         */
146
        mov     r1, #0
147
        str     r1, [r0, #SA110_SDRAM_TIMING_o]
148
 
149
        // Disable each array
150
        mov     r1, #0
151
        str     r1, [r0, #SA110_SDRAM_ADDRESS_SIZE_ARRAY_0_o]
152
        str     r1, [r0, #SA110_SDRAM_ADDRESS_SIZE_ARRAY_1_o]
153
        str     r1, [r0, #SA110_SDRAM_ADDRESS_SIZE_ARRAY_2_o]
154
        str     r1, [r0, #SA110_SDRAM_ADDRESS_SIZE_ARRAY_3_o]
155
 
156
        // Wait for 8 refresh cycles to complete
157
        mov     r1, #(9 * 32)
158
    1:  subs    r1, r1, #1
159
        bpl     1b
160
 
161
        /*
162
         * Force an all-banks recharge on all four SDRAM arrays
163
         *
164
         * This code came from the SA-IOP ver 1.0 (3-16-98) spec pg 22
165
         *
166
         * You must access all four arrays regardless of whether there is
167
         * memory there because the 21285 counts the precharge accesses and
168
         * inhibits access to the SDRAM until all four have been done.
169
         *
170
         * An all banks rechargs is initiated by a read from any address
171
         * in the mode register space.
172
         */
173
 
174
        mov     r1, #3
175
        mov     r0, #ARRAY_0_MODE_REGISTER
176
   1:
177
        ldr     r2, [r0]
178
        add     r0, r0, #MODE_REGISTER_STEP
179
        subs    r1, r1, #1
180
        bpl     1b
181
 
182
        /*
183
         * Now we need to write to the SDRAM Mode Register.
184
         * The address is important, not the data.  The mode register
185
         * should be configured for a burst size of 4 with linear addressing
186
         */
187
        mov     r1, #3
188
        mov     r0, #ARRAY_0_MODE_REGISTER
189
   1:
190
        str     r0, [r0, #SDRAM_MODE_REGISTER_SETUP_OFFSET]
191
        add     r0, r0, #MODE_REGISTER_STEP
192
        subs    r1, r1, #1
193
        bpl     1b
194
 
195
        /*
196
         * Write to the SDRAM Timing Register in the 21285.  Set the
197
         * refresh interval to the minimum because we have to wait for
198
         * 8 refresh cycles to complete before we can rely on the SDRAMs
199
         * to be operating normally
200
         */
201
        ldr     r0, =SA110_CONTROL_STATUS_BASE
202
        ldr     r1, =SDRAM_TIMING_VALUE_MIN
203
        str     r1, [r0, #SA110_SDRAM_TIMING_o]
204
 
205
        // Disable each array
206
        mov     r1, #0
207
        str     r1, [r0, #SA110_SDRAM_ADDRESS_SIZE_ARRAY_0_o]
208
        str     r1, [r0, #SA110_SDRAM_ADDRESS_SIZE_ARRAY_1_o]
209
        str     r1, [r0, #SA110_SDRAM_ADDRESS_SIZE_ARRAY_2_o]
210
        str     r1, [r0, #SA110_SDRAM_ADDRESS_SIZE_ARRAY_3_o]
211
 
212
        // Wait for 8 refresh cycles to complete
213
        mov     r1, #(9 * 32)
214
    1:  subs    r1, r1, #1
215
        bpl     1b
216
 
217
        // Now reset the Refresh interval to a sensible value
218
        ldr     r1, =SDRAM_TIMING_VALUE_NORMAL
219
        str     r1, [r0, #SA110_SDRAM_TIMING_o]
220
 
221
        /* start out assuming 64M part with MUX mode 2 */
222
        mov     r1, #(SA110_SDRAM_SIZE_64MB | SA110_SDRAM_MUX_MODE2)
223
        str     r1, [r0, #SA110_SDRAM_ADDRESS_SIZE_ARRAY_0_o]
224
        add     r1, r1, #(64 << 20) // Add 64Mb
225
        str     r1, [r0, #SA110_SDRAM_ADDRESS_SIZE_ARRAY_1_o]
226
        add     r1, r1, #(64 << 20) // Add 64Mb again
227
        str     r1, [r0, #SA110_SDRAM_ADDRESS_SIZE_ARRAY_2_o]
228
        add     r1, r1, #(64 << 20) // Add 64Mb and again
229
        str     r1, [r0, #SA110_SDRAM_ADDRESS_SIZE_ARRAY_3_o]
230
 
231
        /*
232
         * First, try to figure out which banks are populated and
233
         * the real mux mode for those banks.
234
         *
235
         * At this point:
236
         *   r0 - Base of control/status registers
237
         *
238
         * Register usage:
239
         *   r8 - offset to SDRAM addr/size register
240
         *   r5 - pattern
241
         *   r4 - inverse pattern
242
         *   r3 - scratch/mux mode output
243
         *   r2 - scratch offset
244
         *   r1 - base address of 64M block in consideration
245
         *   r0 - base address of control register sets
246
         */
247
        mov     r8, #SA110_SDRAM_ADDRESS_SIZE_ARRAY_0_o
248
        mov     r1, #0
249
 
250
        ldr     r5, =0x12345678
251
        mvn     r4, r5
252
 
253
    20:
254
        str     r5, [r1]      // Offset 0 should work regardless
255
        str     r4, [r1, #4]  // put something else on the data bus
256
        ldr     r3, [r1]      // read back original
257
        cmps    r3, r5
258
 
259
        // If we didn't read pattern, then no memory present
260
        movne   r3, #0
261
        strne   r3, [r0, r8]            // write to addr/size register
262
        bne     49f                     // straight to next loop
263
 
264
        /*
265
         * This bank is populated, so try to determine mux mode.
266
         * All banks are currently set for mux mode 2.
267
         */
268
 
269
        // A21 having no effect distinguishes the need for mux mode 0.
270
        str     r5, [r1]
271
        mov     r2, #(1 << 21)
272
        str     r4, [r1, r2]   // Store bad value at A21 mirror address
273
                                 // expect to trash value at r1 if mode 0
274
        ldr     r3, [r1]
275
        cmps    r3, r5
276
        // If we don't read back pattern, then its mux mode 0
277
 
278
        // Force to 32M size to include A18 when sizing:
279
        movne   r3, #(SA110_SDRAM_SIZE_32MB | SA110_SDRAM_MUX_MODE0)
280
        bne     2f
281
 
282
        // A23 having effect distinguishes the need for mux mode 2.
283
        str     r5, [r1]
284
        mov     r2, #(1 << 23)
285
        str     r4, [r1, r2]   // Store bad value at A23 mirror address
286
                               // expect to preserve value at r1 if mode 2
287
        ldr     r3, [r1]
288
        cmps    r3, r5
289
        // if pattern still there, then mode 2
290
        moveq   r3, #(SA110_SDRAM_SIZE_64MB | SA110_SDRAM_MUX_MODE2)
291
        beq     2f
292
 
293
        // A22 having effect distinguishes the need for mux mode 4.
294
        str     r5, [r1]
295
        mov     r2, #(1 << 22)
296
        str     r4, [r1, r2]   // Store bad value at A22 mirror address
297
                               // expect to preserve value at r1 if mode 4
298
        ldr     r3, [r1]
299
        cmps    r3, r5
300
        // if pattern A still there, then mode 4
301
        moveq   r3, #(SA110_SDRAM_SIZE_64MB | SA110_SDRAM_MUX_MODE4)
302
        beq     2f
303
 
304
        /*
305
         * At this point it is either mode 1 or 3. There is no clear cut
306
         * test to differentiate the two, so make a best guess now, then
307
         * correct later (if necessary) while sizing the bank.
308
         */
309
 
310
        // NB the bank is still in mux mode 2, so A24 is fed to the wire for
311
        // A22 (mode 1) or no-connection (mode 3); so:
312
        // A24 having effect distinguishes the need for mux mode 1
313
        // A24 having no effect distinguishes the need for mux mode 3
314
        str     r5, [r1]
315
        mov     r2, #(1 << 24)
316
        str     r4, [r1, r2]
317
        ldr     r3, [r1]
318
        cmps    r3, r5
319
        // If pattern, try mode 1
320
        moveq   r3, #(SA110_SDRAM_SIZE_64MB | SA110_SDRAM_MUX_MODE1)
321
        // otherwise, try mode 3
322
        movne   r3, #(SA110_SDRAM_SIZE_64MB | SA110_SDRAM_MUX_MODE3)
323
 
324
        bne 2f
325
 
326
    2:
327
        orr     r3, r3, r1                      // add in base address
328
        str     r3, [r0, r8]                    // write to addr/size register
329
 
330
        /*
331
         * Now that mux mode for this array is (hopefully) setup, we can try
332
         * to size this SDRAM array.
333
         *
334
         * Register usage:
335
         *    r8 - offset to current size/mode register
336
         *    r1 - offset to current base (in 64M blocks)
337
         *    r0 - base address of control register sets
338
         */
339
 
340
        mov     r4, #(63 << 20)         // 63Mb to start with
341
    1:  str     r4, [r1, r4]
342
        subs    r4, r4, #(1 << 20)      // go down in increments of 1Mb
343
        bpl     1b
344
 
345
        str     r4, [r1, #4]            // change pattern on data bus
346
 
347
        // search for first unexpected data in ascending order
348
        mov     r4, #0
349
    1:
350
        ldr     r5, [r1, r4]
351
        cmps    r5, r4
352
        bne     23f                     // different so end of array
353
        add     r4, r4, #(1 << 20)      // go up in increments of 1Mb
354
        cmps    r4, #(64 << 20)
355
        blt     1b
356
        // fall-through assumes it is a 64Mb device
357
   23:
358
        movs    r4, r4, lsr #20         // get a plain number of Mb
359
        // if this gave a zero, maybe we were mistaken about the RAM
360
        // working earlier: disable this bank.
361
        streq   r4, [r0, r8]            // write to addr/size register
362
        beq     49f                     // straight to next loop
363
 
364
        // apparently, mode 3 devices *must* be 8Mb; if we got a different
365
        // answer, set it to mode 1 and go back to try again:
366
        cmps    r4, #8
367
        beq     4f
368
 
369
        // skip if 8Mb; we are happy
370
        ldr     r3, [r0, r8]            // read in the mode we set
371
        and     r3, r3, #SA110_SDRAM_MUX_MODE_MASK
372
        cmp     r3, #SA110_SDRAM_MUX_MODE3
373
        // Must be misconfigured mux mode. Set to mode 1 and retry
374
        moveq   r3, #(SA110_SDRAM_SIZE_64MB | SA110_SDRAM_MUX_MODE1)
375
        beq     2b
376
        // not mux mode 3; drop though OK
377
 
378
    4:
379
        // convert MB size to register size val
380
        mov     r5, #0
381
        mov     r3, r4
382
    5:  movs    r3, r3, lsr #1
383
        add     r5, r5, #1
384
        bcc     5b
385
 
386
        // Double check that the size was a power of 2
387
        mov     r6, #1
388
        mov     r6, r6, lsl r5          // should get Mb count back doubled
389
        cmps    r6, r4, lsl #1          // compare with doubled
390
        movne   r5, #0                  // disable this bank
391
        ldr     r3, [r0, r8]            // Load current setting
392
        bic     r3, r3, #7
393
        orr     r3, r3, r5              // insert the correct size code
394
        str     r3, [r0, r8]            // into the control register
395
 
396
   49:
397
        add     r8, r8, #4                      // next addr/size register
398
        add     r1, r1, #(64<<20)               // next array
399
        cmps    r1, #(256<<20)                  // top address + 1 bank
400
        blt     20b
401
        // END of main loop to size all 4 DRAM banks
402
 
403
        /*
404
         * At this point, the size values are all in the control registers.
405
         *
406
         * We want to set memory up to be contiguous. Since the
407
         * banks' base address needs to be naturally aligned, we
408
         * need to sort the bank sizes from large to small.
409
         *
410
         * Register usage:
411
         *   r0 - base address of control register sets
412
         *   r1 - bitmap of which slots we have covered in toto
413
         *   r2 - cumulative base address of mapped SDRAM
414
         *   r3 - biggest size code this pass
415
         *   r4 - bit index of current slot
416
         *   r5 - bit index of biggest slot found this pass
417
         *   r6 - scratch control reg contents
418
         *   r7 - scratch size code
419
         *   r8 - address of current slot's control register
420
         *   r9 - address of biggest slot found's control register
421
         */
422
        mov     r1, #0                  // bitmap of which we have covered
423
        mov     r2, #0                  // cumulative base address
424
        // do... until there are no more slots to deal with
425
    70:
426
        mov     r3, #0                  // biggest this pass
427
        mov     r4, #1                  // bit index of current slot
428
        mov     r5, #0                  // bit index of biggest slot found
429
        mov     r8, #SA110_SDRAM_ADDRESS_SIZE_ARRAY_0_o
430
        mov     r9, #0                  // address of biggest slot found
431
        // Foreach slot we have not yet dealt with
432
    75:
433
        tst     r4, r1
434
        bne     88f
435
        ldr     r6, [r0, r8]
436
        and     r7, r6, #7
437
        cmps    r7, r3
438
        movgt   r3, r7                  // save biggest's size
439
        movgt   r5, r4                  // save biggest's index
440
        movgt   r9, r8                  // save biggest's reg address
441
    88:
442
        mov     r4, r4, asl #1
443
        add     r8, r8, #4
444
        cmps    r4, #0x10
445
        blt     75b                     // next slot
446
        // Did we find a largest slot?
447
        cmps    r5, #0
448
        beq     95f     // No!  Finished
449
 
450
        orr     r1, r1, r5              // can forget r4 and r5 now
451
        ldr     r6, [r0, r9]            // get the control register
452
        bic     r6, r6, #0x0ff00000     // clear base address bits
453
        orr     r6, r6, r2              // insert base address to use
454
        str     r6, [r0, r9]            // store the new control register
455
        mov     r6, #1
456
        mov     r6, r6, asl r3
457
        mov     r6, r6, asl #19         // 1 << (size-code + 19) is size
458
        add     r2, r2, r6              // increment the cumulating address
459
 
460
        b       70b                     // go look for the next one
461
 
462
    95: // all done!
463
        // at this point, r2 contains the top of memory.
464
        // (r11 is the value from last time or zero if first time)
465
 
466
        cmps    r11, r2                 // Same answer as last time?
467
        movne   r11, r2                 // if not, save memsize
468
        bne     12b                     // ...and try again.
469
 
470
        mov     r0, r2
471
        mov     pc, lr
472
#endif // ! defined CYG_HAL_STARTUP_RAM
473
//FUNC_END __mem285_init
474
 
475
/* EOF mem285.S */

powered by: WebSVN 2.1.0

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