]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/xscale/triton/v2_0/include/hal_platform_setup.h
RedBoot TX53 Release 2012-02-15
[karo-tx-redboot.git] / packages / hal / arm / xscale / triton / v2_0 / include / hal_platform_setup.h
1 #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 //#####ECOSGPLCOPYRIGHTBEGIN####
11 //## -------------------------------------------
12 //## This file is part of eCos, the Embedded Configurable Operating System.
13 //## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
14 //##
15 //## eCos is free software; you can redistribute it and/or modify it under
16 //## the terms of the GNU General Public License as published by the Free
17 //## Software Foundation; either version 2 or (at your option) any later version.
18 //##
19 //## eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20 //## WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 //## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22 //## for more details.
23 //##
24 //## You should have received a copy of the GNU General Public License along
25 //## with eCos; if not, write to the Free Software Foundation, Inc.,
26 //## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27 //##
28 //## As a special exception, if other files instantiate templates or use macros
29 //## or inline functions from this file, or you compile this file and link it
30 //## with other works to produce a work based on this file, this file does not
31 //## by itself cause the resulting work to be covered by the GNU General Public
32 //## License. However the source code for this file must still be made available
33 //## in accordance with section (3) of the GNU General Public License.
34 //##
35 //## This exception does not invalidate any other reasons why a work based on
36 //## this file might be covered by the GNU General Public License.
37 //##
38 //## Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39 //## at http://sources.redhat.com/ecos/ecos-license/
40 //## -------------------------------------------
41 //#####ECOSGPLCOPYRIGHTEND####
42 //#####DESCRIPTIONBEGIN####
43 //
44 // Author(s):   usteinkohl
45 // Contributors:
46 // Date:                14th January 2003
47 // Purpose:             KaRo TRITON platform specific support routines
48 // Description:
49 // Usage:               #include <cyg/hal/hal_platform_setup.h>
50 //
51 //####DESCRIPTIONEND####
52 //
53 //===========================================================================*/
54
55 #include <pkgconf/system.h>             // System-wide configuration info
56 #include CYGBLD_HAL_PLATFORM_H          // Platform specific configuration
57 #include <cyg/hal/hal_triton.h>         // Platform specific hardware definitions
58 #include <cyg/hal/hal_mmu.h>            // MMU definitions
59
60 // Define macro used to diddle the LEDs during early initialization.
61 // Can use r0+r1.  Argument in \x.
62 #define CYGHWR_LED_MACRO nop ;
63
64 // The main useful output of this file is PLATFORM_SETUP1: it invokes lots
65 // of other stuff (may depend on RAM or ROM start).     The other stuff is
66 // divided into further macros to make it easier to manage what's enabled
67 // when.
68
69 #if defined(CYG_HAL_STARTUP_ROM)
70 #define PLATFORM_SETUP1 _platform_setup1
71 //#define CYGHWR_HAL_ARM_HAS_MMU
72 #else
73 #define PLATFORM_SETUP1
74 #endif
75
76 #define RAM_BASE        0xa0000000
77 #define DRAM_SIZE       (64*1024*1024)          // max size of available SDRAM
78 #define DCACHE_SIZE     (32*1024)               // size of the Dcache
79 #define DCACHE_FLUSH_AREA (RAM_BASE+DRAM_SIZE)  // NB: needs page table support
80
81 #if 0
82 #define CPSR_IRQ_DISABLE        0x80    // IRQ disabled when =1
83 #define CPSR_FIQ_DISABLE        0x40    // FIQ disabled when =1
84 #define CPSR_FIQ_MODE           0x11
85 #define CPSR_IRQ_MODE           0x12
86 #define CPSR_SUPERVISOR_MODE    0x13
87 #define CPSR_UNDEF_MODE         0x1B
88
89 #define CPSR_MODE_BITS          0x1F
90
91 #endif
92
93 #define MMU_Control_BTB 0x800
94
95 // Reserved area for battery backup SDRAM memory test
96 // This area is not zeroed out by initialization code
97 #define SDRAM_BATTERY_TEST_BASE 0xA1FFFFF0      // base address of last 16 memory locations in a 32MB SDRAM
98
99         .macro MEM_TEST
100                 nop
101         .endm
102
103         // Trigger the logic analyzer by writing a particular
104         // address, and triggering on that address.
105         .macro TRIGGER_LA_ON_ADDRESS address, reg0, reg1
106         mrc     p15, 0, \reg0, c1, c0, 0        // read ARM control register
107         //      CPWAIT  \reg0
108         ldr     \reg1, =\address
109         str     \reg0, [\reg1]
110         .endm
111
112         // Delay a bit
113         .macro DELAY_FOR cycles, reg0
114         ldr     \reg0, =\cycles
115         subs    \reg0, \reg0, #1
116         subne   pc, pc, #0xc
117         .endm
118
119         // wait for coprocessor write complete
120         .macro CPWAIT reg
121         mrc     p15, 0, \reg, c2, c0, 0
122         mov     \reg, \reg
123         sub     pc, pc, #4
124         .endm
125
126         // blink some times on GPIO10
127         .macro BLINK10 count
128         ldr     r4, =\count
129 220961:
130         ldr     r1, =0x00000400         // we use GPIO10 for controlling the debug LED
131
132         ldr     r0, =GPCRx
133         str     r1, [r0]                // switch the LED on
134
135         ldr     r2, =0x00500000         // wait some time
136         mov     r3, #1
137 998:
138         sub     r2, r2, r3
139         cmp     r2, #0
140         bne     998b
141
142         ldr     r0, =GPSRx              // switch the LED off
143         str     r1, [r0]
144
145         ldr     r2, =0x00500000         // wait some time
146         mov     r3, #1
147 998:
148         sub     r2, r2, r3
149         cmp     r2, #0
150         bne     998b
151
152         sub     r4, r4, r3
153         cmp     r4, #0
154         bne     220961b
155         .endm
156
157         .macro TRITON_SET_REFR_VAL
158         // TRITON specific, DRAM specific !!!!!!!!!!!!!
159         // example:
160         // Refresh period for 4096 rows = 64 ms (47 memory cycles) for 99,5 MHz MCLK
161         // DRI = 64 ms * 99,5 MHz / (4096 * 32) = 48
162
163         ldr r3, =MDREFR
164         ldr r2, [r3]                    // read MDREFR value
165         ldr     r4, =0xFFF
166         bic r2, r2, r4                  // clear out value in DRI
167 #ifdef TRITON_DRAM32_64
168         // DRI = 64 ms * 99,5 MHz / (8192 * 32) = 24   (0x18)
169         orr r2, r2, #0x00000018         // put in a valid SDRAM Refresh Interval (DRI)
170 #endif
171 #ifdef TRITON_DRAM16_16_MOBILE
172         // DRI = 64 ms * 99,5 MHz / (4096 * 32) = 48
173         orr r2, r2, #0x00000030         // put in a valid SDRAM Refresh Interval (DRI)
174 #endif
175 #ifdef TRITON_DRAM16_32_MOBILE
176         // DRI = 64 ms * 99,5 MHz / (8192 * 32) = 24
177         orr r2, r2, #0x00000018         // put in a valid SDRAM Refresh Interval (DRI)
178 #endif
179
180         str     r2, [r3]                // store it
181
182         .endm
183
184         .macro TRITON_CONFIG_SDRAM_BANKS
185
186         // Banks configured for 64-Mbit SDRAM devices (12(13) row x 9 col x 4 internal banks)
187         // CAS latency = 3, 32/16-bit bus width,
188
189         ldr r3, =MDCNFG                 // sdram config -- sdram should remain disabled !!!!!
190
191 #ifdef TRITON_DRAM32_64
192         ldr r2, =0x00000ac8             // 13 rows
193 #endif
194 #ifdef TRITON_DRAM16_16_MOBILE
195         ldr r2, =0x00000aac             // 12 rows / 9 col / 4 banks / 16 bit / CL3
196 #endif
197 #ifdef TRITON_DRAM16_32_MOBILE
198         ldr r2, =0x00000acc             // 13 rows / 9 col / 4 banks / 16 bit / CL3
199 #endif
200
201         str r2, [r3]
202         .endm
203
204         // form a first-level section entry
205         .macro FL_SECTION_ENTRY base,x,ap,p,d,c,b
206         .word (\base << 20) | (\x << 12) | (\ap << 10) | (\p << 9) |\
207         (\d << 5) | (\c << 3) | (\b << 2) | 2
208         .endm
209
210         // form a first-level page table entry
211         .macro FL_PT_ENTRY base,d
212         // I wanted to use logical operations here, but since I am using symbols later
213         // to fill in the parameters, I had to use addition to force the assembler to
214         // do it right
215         .word \base + (\d << 5) + 1
216         .endm
217
218         // form a second level small page entry
219         .macro SL_SMPAGE_ENTRY base,ap3,ap2,ap1,ap0,c,b
220         .word (\base << 12) | (\ap3 << 10) | (\ap2 << 8) | (\ap1 << 6) |\
221         (\ap0 << 4) | (\c << 3) | (\b << 2) | 2
222         .endm
223
224         // form a second level extended small page entry
225         .macro SL_XSMPAGE_ENTRY base,x,ap,c,b
226         .word (\base << 12) | (\x << 6) | (\ap << 4) | (\c << 3) | (\b << 2) | 3
227         .endm
228
229         // start of platform setup
230         .macro _platform_setup1
231
232         // This is where we wind up immediately after reset. On the CYCLONE, we have
233         // to jump around a hole in flash which runs from 0x00001000 - 0x0001fff.
234         // We might not have to do this for TRITON
235         // The start of _platform_setup1 will be below 0x1000 and since we need to
236         // align the mmu table on a 16k boundary, we just branch around the page
237         // table which we will locate at FLASH_BASE+0x4000.
238         b _real_platform_setup
239
240         .p2align 13
241         // the following alignment creates the mmu table at address 0x4000.
242         mmu_table:
243
244         // 1MB of FLASH with i80312 MMRs mapped in using 4K small pages so we can
245         // set the access permission on flash and memory-mapped registers properly.
246         FL_PT_ENTRY mmu_table_flashbase, 0
247
248         // Remaining 63MB of FLASH area (Static Chip select 0)
249         //      rw, cacheable, non-bufferable
250         .set    __base, 1
251         .rept   0x040-0x001
252         FL_SECTION_ENTRY __base, 0, 3, 0, 0, 1, 0
253         .set    __base, __base+1
254         .endr
255
256         // nothing interesting here, static chip select area 1 (Address Translation)
257         .rept   0x080 - 0x040
258         FL_SECTION_ENTRY __base, 0, 3, 0, 0, 0, 0
259         .set    __base, __base+1
260         .endr
261
262         // nothing interesting here, static chip select area 2 (Address Translation)
263         .rept   0x0C0 - 0x080
264         FL_SECTION_ENTRY __base, 0, 3, 0, 0, 0, 0
265         .set    __base, __base+1
266         .endr
267
268         // nothing interesting here, static chip select area 3 (Address Translation)
269         .rept   0x100 - 0x0C0
270         FL_SECTION_ENTRY __base, 0, 3, 0, 0, 0, 0
271         .set    __base, __base+1
272         .endr
273
274         // nothing interesting here, static chip select area 4 (Address Translation)
275         .rept   0x140 - 0x100
276         FL_SECTION_ENTRY __base, 0, 3, 0, 0, 0, 0
277         .set    __base, __base+1
278         .endr
279
280         // nothing interesting here, static chip select area 5 (Address Translation)
281         .rept   0x180 - 0x140
282         FL_SECTION_ENTRY __base, 0, 3, 0, 0, 0, 0
283         .set    __base, __base+1
284         .endr
285
286         // nothing interesting here (Address Translation)
287         .rept   0xA00 - 0x180
288         FL_SECTION_ENTRY __base, 0, 3, 0, 0, 0, 0
289         .set    __base, __base+1
290         .endr
291
292         // up to 64MB SDRAM
293         //      x=c=b=1
294         // first 1MB mapped by second level table
295         FL_PT_ENTRY mmu_table_rambase, 0
296         .set    __base, __base+1
297
298         // remainder of SDRAM mapped 1-to-1
299         .rept   0xC00 - 0xA01
300         FL_SECTION_ENTRY __base, 1, 3, 1, 0, 1, 1
301         .set    __base, __base+1
302         .endr
303
304         // Cache flush region.
305         // Don't need physical memory, just a cached area.
306         .rept   0xD00 - 0xC00
307         FL_SECTION_ENTRY __base, 0, 3, 0, 0, 1, 1
308         .set    __base, __base+1
309         .endr
310
311         // Invalid
312         .rept   0x1000 - 0xD00
313         .word 0
314         .set    __base, __base+1
315         .endr
316
317         // Immediately after the above table (at 0x8000) is the
318         // second level page table which breaks up the lowest 1MB
319         // of physical memory into 4KB sized virtual pages.
320         mmu_table_flashbase:
321         // Virtual address 0 (Flash boot code).
322         // Map 4k page at 0x00000000 virt --> 0xA0000000 physical
323         // This allows us to have a writable vector table.
324         //      Read-Write, cacheable, bufferable
325         SL_XSMPAGE_ENTRY 0xa0000, 1, 3, 1, 1
326
327         // Virtual address 0x1000 (Memory mapped registers)
328         // Map 1-to-1, but don't cache or buffer
329         //      Read-Write, non-cacheable, non-bufferable
330         .set    __base, 1
331         SL_SMPAGE_ENTRY __base, 3, 3, 3, 3, 0, 0
332         .set    __base, __base+1
333
334         // Virtual address 0x2000-0x100000 (remainder of flash1)
335         //      Read-Write, cacheable, non-bufferable
336         .rept   0x100 - 0x2
337         SL_SMPAGE_ENTRY __base, 3, 3, 3, 3, 1, 0
338         .set    __base, __base+1
339         .endr
340
341         // Now is the second level table for the first megabyte
342         // of DRAM.
343         mmu_table_rambase:
344         // Map 4k page at 0xa0000000 virt --> 0x00000000 physical
345         //      Read-Write, cacheable, non-bufferable
346         SL_SMPAGE_ENTRY 0x00000, 3, 3, 3, 3, 1, 0
347         .set    __base, __base+1
348
349         // Map remainder of first meg of SDRAM
350         //      Read-Write, cacheable, non-bufferable
351         .set    __base, 0xA0001
352         .rept   0x100 - 0x1
353         SL_XSMPAGE_ENTRY __base, 1, 3, 1, 1
354         .set    __base, __base+1
355         .endr
356
357 _real_platform_setup://Angel SDRAM init code follows
358
359         // if we come out of sleep mode, check if there is a pointer
360         // from the os, and jump to it if so
361
362         ldr r0, =RCSR           // check reset source
363         ldr     r1, [r0]
364         and r1, r1, #4
365         cmp r1, #4
366         bne 1923f
367
368         ldr r2, =PSPR           // check if there is a pointer from the operating system
369         ldr r1, [r2]
370         cmp r1, #0
371         beq 1923f
372
373         ldr r3, =0x0000000f             // reset RCSR
374         str r3, [r0]
375
376         // get SDRAM out of Self Refresh
377         TRITON_SET_REFR_VAL
378         TRITON_CONFIG_SDRAM_BANKS
379
380         ldr r3, =MDREFR
381         ldr r2, [r3]            // read MDREFR value
382         bic r2, r2, #0x03800000 // clear all Free Running Clocks
383         orr r2, r2, #0x00010000 // assert MDREFR:K1RUN
384         bic r2, r2, #0x00020000 // clear MDREFR:K1DB2 -> SDRAM-CLK = MEMCLK
385         str r2, [r3]            // change from "self-refresh and clock-stop" to "self-refresh"
386         ldr r2, [r3]            // read MDREFR value (to make sure the previous value stuck) (this is in Tricia's code)
387
388         bic r2, r2, #0x00400000 // clear self-refresh bit
389         str r2, [r3]            // change from "self-refresh" to "Power Down"
390         orr r2, r2, #0x00008000 // assert MDREFR:E1PIN
391         str r2, [r3]            // change from "Power Down" to "PWRDWNX"
392         nop
393         nop                             // no write required to change from "PWRDWNX" to "NOP"
394
395         ldr r3, =MDCNFG         // sdram config -- sdram enable
396         ldr r2, [r3]
397         orr r2, r2, #0x00000001 // enable appropriate banks
398         str r2, [r3]
399
400         // initialize CPSR (machine state register)
401         mov     r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_SUPERVISOR_MODE)
402         msr     cpsr, r0
403
404         /*      Set up the stack pointer to a fixed value */
405         ldr     r3, =0xa0700000
406         mov     sp, r3
407
408         ldr r2, =PSPR           // get pointer
409         ldr r1, [r2]
410         mov r15, r1                     // jump to pointer
411
412 1923:
413         //      must set the GPIOs up before any chip selects will work
414         //GPCRx = 0xffffffff put a 0 on any of the GPIOs (0=unchanged, 1=drive 0)
415         // reset all first
416         ldr     r0, =GPCRx
417         ldr     r1, =0xffffffff
418         str     r1, [r0]
419         //GPCRy = 0xffffffff
420         ldr     r0, =GPCRy
421         ldr     r1, =0xffffffff
422         str     r1, [r0]
423         //GPCRz = 0xffffffff
424         ldr     r0, =GPCRz
425         ldr     r1, =0xffffffff
426         str     r1, [r0]
427
428         // GPSRx = 0x01800000 put a 1 on any of the GPIOs (0=unchanged, 1=drive 1)
429         ldr     r0, =GPSRx
430         ldr     r1, =0x01800000
431 #ifdef TRITON_CS2_SMSC
432         ldr     r1, =0x01808000
433 #endif
434
435 #ifdef TRITON_CS2_8900
436         ldr     r1, =0x01808000
437 #endif
438         str     r1, [r0]
439
440         //GPSRy = 0x70ff0000
441         ldr     r0, =GPSRy
442         ldr     r1, =0x70ff0800
443 #ifdef TRITON_USE_STUART
444         ldr     r2, =0x00008000
445         orr     r1, r1, r2
446 #endif
447         str     r1, [r0]
448
449         //GPSRz = 0x00000000
450         ldr     r0, =GPSRz
451         ldr     r1, =0x00000000
452         str     r1, [r0]
453
454         //GPDRx = 0x01800800 put the GPIOs in the correct direction (0=in, 1=out)
455         ldr     r0, =GPDRx
456         ldr     r1, =0x01800000         //vorher 0x01800400
457 #ifdef TRITON_CS2_SMSC
458         ldr     r1, =0x01808800
459 #endif
460 #ifdef TRITON_CS2_8900
461         ldr     r1, =0x01808000
462 #endif
463 #if (TRITON_STK==1)
464         orr     r1, r1, #0x00000800
465 #endif
466 #ifdef GPIO_10_OUT
467         orr     r1, r1, #0x00000400
468 #endif
469         str     r1, [r0]
470
471         //GPDRy = 0x7cff0280
472         ldr     r0, =GPDRy
473         ldr     r1, =0x7cff0a80
474 #ifdef TRITON_USE_STUART
475         ldr     r2, =0x00008000
476         orr     r1, r1, r2
477 #endif
478         str     r1, [r0]
479         //GPDRz = 0x00000000
480         ldr     r0, =GPDRz
481         ldr     r1, =0x00000000
482         str     r1, [r0]
483
484         //GAFR0x = 0x00000000  setup the alternate functions (00=normal, 01=alt fuct 1, etc)
485         ldr     r0, =GAFR0x
486         ldr     r1, =0x00000000
487 #ifdef TRITON_CS2_SMSC
488         ldr     r1, =0x80000000
489 #endif
490 #ifdef TRITON_CS2_8900
491         ldr     r1, =0x80000000
492 #endif
493         str     r1, [r0]
494
495         //GAFR1x = 0x00128140
496         ldr     r0, =GAFR1x
497         ldr     r1, =0x0012814
498         str     r1, [r0]
499
500         //GAFR0y = 0x00988050
501         ldr     r0, =GAFR0y
502         ldr     r1, =0x00988050
503 #ifdef TRITON_USE_STUART
504         ldr     r2, =0x60000000
505         orr     r1, r1, r2
506 #endif
507         str     r1, [r0]
508
509         //GAFR1y = 0x0005aaaa
510         ldr     r0, =GAFR1y
511         ldr     r1, =0x0005aaaa
512         str     r1, [r0]
513
514         //GAFR0z = 0x00000000
515         ldr     r0, =GAFR0z
516         ldr     r1, =0x00000000
517         str     r1, [r0]
518
519         //GAFR1z = 0x00000000
520         ldr     r0, =GAFR1z
521         ldr     r1, =0x00000000
522         str     r1, [r0]
523
524         //PSSR = 0x20 clear the RDH and PH bit in the PSSR
525         ldr     r0, =PSSR
526         ldr     r1, =0x30
527         str     r1, [r0]
528
529         ldr r3, =PCFR           // clear PCFR[FS] and PCFR[FP]
530         ldr r2, [r3]
531         bic r2, r2, #0x00000006
532         str r2, [r3]
533 #ifdef GPIO_10_OUT
534         BLINK10 3
535 #endif
536         MRC     p15, 0, r0, c0, c0, 0           // read the ID reg .... 0x69052100
537         // and display it if possible
538         // not possible for TRITON
539
540         // turn everything off
541         mov     r0, #0x78
542         mcr     p15, 0, r0, c1, c0, 0   // caches off -- MMU off or ID map
543
544         mcr p15, 0, R0, c7, c7, 0       // Invalidate the I & D cache, mini- d cache, and BTB
545
546         //MCR   p15, 0, r0, c7, c5, 0   // Invalidate the instruction cache and branch target buffer
547         //MCR   p15, 0, r0, c7, c6, 0   // Invalidate the data cache and mini-data cache
548
549         MCR p15, 0, r0, c7, c10, 4      // Drain write buffer -- r0 ignored
550
551                                         // CPWAIT macro
552         MRC p15, 0, R0, c2, c0, 0       // arbitrary read of CP15
553         MOV R0, R0                      // wait for it
554         SUB PC, PC, #4                  // branch to next instruction
555
556         nop
557         nop
558         nop
559         nop
560 // setup manager access, interrupts, etc.
561 // grant manager access to all domains
562         mvn     r0, #0          // all 1s
563         mcr     p15, 0, r0, c3, c0, 0
564                                         // all IRQs should be masked to prevent spurious IRQs
565         ldr     r3, =ICMR               // pending interrupts are masked from becoming active
566         mov     r2, #0
567         str     r2, [r3]
568
569         ldr     r3, =ICLR               // route all interrupts to CPU IRQ ( not to FIQ )
570         mov     r2, #0
571         str     r2, [r3]
572
573         ldr     r3, =ICCR               // only enabled and unmasked interrupts bring core out of idle
574         mov     r2, #1
575         str     r2, [r3]
576
577 // Turn on the RTC circuit (if you want)
578
579         ldr     r1, =OSCC               // oscillator config reg
580         // turn on the 32.768 KHz clock for RTC, etc.
581         mov     r0, #0x2
582         str     r0, [r1]
583
584         // Wait 200 usec
585         ldr     r3, =OSCR       // reset the OS Timer Count to zero
586         mov     r2, #0
587         str     r2, [r3]
588         ldr     r4, =0x300      // really 0x2E1 is about 200usec, so 0x300 should be plenty
589
590 10:
591         ldr     r2, [r3]
592         cmp     r4, r2
593         bgt     10b
594
595 // CS0  : RDF=14(15), RDN=4 , RRR=2, 32 bits Flash
596 // Suitable for 128-Mbit StrataFlash (Tcyc = 150 ns) and 100MHz MEMCLK
597         ldr     r3, =MSC0               // low  - bank 0 Flash
598 #ifdef TRITON_FLASH32_32
599         ldr     r2, =0x7ff024d0
600 #endif
601 #ifdef TRITON_FLASH16_16
602         ldr     r2, =0x7ff024d8
603 #endif
604
605 #ifdef TRITON_CS2_SMSC
606         ldr     r4, =0x0000ffff
607         and     r2, r2, r4
608         ldr     r4, =0x12440000
609         orr     r2, r2, r4
610 #endif
611 #ifdef TRITON_CS2_8900
612         ldr     r4, =0x0000ffff
613         and     r2, r2, r4
614         ldr     r4, =0x12dc0000
615         orr     r2, r2, r4
616 #endif
617         str     r2, [r3]
618         ldr     r2, [r3]                // need to read it back to make sure the value latches (see MSC section of manual)
619
620         ldr     r3, =MSC1
621         ldr     r2, =0x7ff07ff0
622         str     r2, [r3]
623         ldr     r2, [r3]                // need to read it back to make sure the value latches (see MSC section of manual)
624
625         ldr     r3, =MSC2
626         ldr     r2, =0x7ff07ff0
627         str     r2, [r3]
628         ldr     r2, [r3]                // need to read it back to make sure the value latches (see MSC section of manual)
629
630         // ********************************************************************
631         // Disable (mask) all interrupts at the interrupt controller
632
633         // clear the interrupt level register (use IRQ, not FIQ)
634         mov     r1, #0
635         ldr     r2,  =ICLR
636         str     r1,  [r2]
637
638         // mask all interrupts at the controller
639         ldr     r2,  =ICMR
640         str     r1,  [r2]
641
642         // make sure the DCACHE is off
643         mov     r0, #0x78               // turn everything off
644         mcr     p15, 0, r0, c1, c0, 0   // caches off, MMU off, etc.
645
646         TRITON_SET_REFR_VAL
647
648         ldr     r3, =SXCNFG
649         mov     r2, #0x0                // since Triton does not have SMROM, make register = 0
650         str     r2, [r3]                // store it
651
652         ldr     r3, =MDREFR
653         ldr     r2, [r3]                // read MDREFR value
654         bic     r2, r2, #0x03800000     // clear all Free Running Clocks
655         orr     r2, r2, #0x00010000     // assert MDREFR:K1RUN
656         bic     r2, r2, #0x00020000     // clear MDREFR:K1DB2 -> SDRAM-CLK = MEMCLK
657
658         str     r2, [r3]                // change from "self-refresh and clock-stop" to "self-refresh"
659         ldr     r2, [r3]                // read MDREFR value (to make sure the previous value stuck) (this is in Tricia's code)
660
661         bic     r2, r2, #0x00400000     // clear self-refresh bit
662         str     r2, [r3]                // change from "self-refresh" to "Power Down"
663         orr     r2, r2, #0x00008000     // assert MDREFR:E1PIN
664         str     r2, [r3]                // change from "Power Down" to "PWRDWNX"
665         nop
666         nop                     // no write required to change from "PWRDWNX" to "NOP"
667
668         TRITON_CONFIG_SDRAM_BANKS
669
670         //---- Wait 200 usec
671         ldr     r3, =OSCR       // reset the OS Timer Count to zero
672         mov     r2, #0
673         str     r2, [r3]
674         ldr     r4, =0x300      // really 0x2E1 is about 200usec, so 0x300 should be plenty
675 10:
676         ldr     r2, [r3]
677         cmp     r4, r2
678         bgt     10b
679
680         ldr     r3, =SDRAM_B0
681         mov     r2, #9          // now must do 8 refresh or CBR commands before the first access
682 10:                             // no we must do 9 because of errata 116
683         str     r3, [r3]
684         subs    r2, r2, #1
685         bne     10b
686
687         ldr     r3, =MDCNFG             // sdram config -- sdram enable
688         ldr     r2, [r3]
689         orr     r2, r2, #0x00000001     // enable appropriate banks
690         str     r2, [r3]
691
692         ldr     r3, =MDMRS              // write the MDMRS
693         mov     r2, #0                  // the writable bits will be written as a 0 (Tricia's code writes 0x00320032)
694         str     r2, [r3]
695 #ifdef TRITON_DRAM16_16_MOBILE
696         ldr     r3, =MDMRSLP
697         ldr     r2, =0x0000a000
698         str     r2, [r3]
699 #endif
700 #ifdef TRITON_DRAM16_32_MOBILE
701         ldr     r3, =MDMRSLP
702         ldr     r2, =0x0000c000
703         str     r2, [r3]
704 #endif
705         //---- Wait 600 usec
706         ldr     r3, =OSCR               // reset the OS Timer Count to zero
707         mov     r2, #0
708         str     r2, [r3]
709         ldr     r4, =0x900              // really 0x2E1 is about 200usec, so 0x300 should be plenty
710 10:
711         ldr     r2, [r3]
712         cmp     r4, r2
713         bgt     10b
714
715         MEM_TEST
716 #if 0
717         /*      Set up the stack pointer to a fixed value */
718         ldr     r3, =0xa0700000
719         mov     sp, r3
720
721         // if we come out of sleep mode, check if there is a pointer
722         // from the os, and jump to it if so
723
724         ldr     r0, =RCSR               // check reset source
725         ldr     r1, [r0]
726         and     r1, r1, #4
727         cmp     r1, #4
728         bne     1923f
729
730         ldr     r2, =PSPR               // check if there is a pointer from the operating system
731         ldr     r1, [r2]
732         cmp     r1, #0
733         beq     1923f
734
735         ldr     r3, =0x0000000f // reset RCSR
736         str     r3, [r0]
737
738         // initialize CPSR (machine state register)
739         mov     r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_SUPERVISOR_MODE)
740         msr     cpsr, r0
741
742         mov     r15, r1         // jump to pointer
743 1923:
744 #endif
745
746 _sdram_init_end:
747 //
748 //
749 // Change Frequency!!!
750 //
751 //
752 #if 0
753         ldr     r4, =0x145      // PxBus = 165,9 MHz MEM/LCD Clock = 165,9 MHz SDRAM-Clock 83 MHz
754         ldr     r2, =CCCR       // Core Clock Config Reg
755         str     r4, [r2]        // set speed
756
757         // set to Frequency Change Mode
758         mov     r0, #0x3
759         mcr     p14, 0, r0, c6, c0, 0   // write to the CCLKCFG coprocessor reg
760                                         // no TURBO-mode is set here
761 #endif
762         // Enable access to all coprocessor registers
763         ldr     r0, =0x2001             // enable access to all coprocessors
764         mcr     p15, 0, r0, c15, c1, 0
765
766         mcr     p15, 0, r0, c7, c10, 4  // drain the write & fill buffers
767         CPWAIT  r0
768
769         mcr     p15, 0, r0, c7, c7, 0   // flush Icache, Dcache and BTB
770         CPWAIT  r0
771
772         mcr     p15, 0, r0, c8, c7, 0   // flush instuction and data TLBs
773         CPWAIT  r0
774
775         // Enable the Icache
776         mrc     p15, 0, r0, c1, c0, 0
777         orr     r0, r0, #MMU_Control_I
778         mcr     p15, 0, r0, c1, c0, 0
779         CPWAIT  r0
780
781         // Set the TTB register
782         ldr     r0, =mmu_table
783         mcr     p15, 0, r0, c2, c0, 0
784
785         // Enable permission checks in all domains
786         ldr     r0, =0x55555555
787         mcr     p15, 0, r0, c3, c0, 0
788
789         // Enable the MMU
790         mrc     p15, 0, r0, c1, c0, 0
791         orr     r0, r0, #MMU_Control_M
792         orr     r0, r0, #MMU_Control_R
793         mcr     p15, 0, r0, c1, c0, 0
794         CPWAIT  r0
795
796         mcr     p15, 0, r0, c7, c10, 4  // drain the write & fill buffers
797         CPWAIT  r0
798
799         // Enable the Dcache
800         mrc     p15, 0, r0, c1, c0, 0
801         orr     r0, r0, #MMU_Control_C
802         mcr     p15, 0, r0, c1, c0, 0
803         CPWAIT  r0
804
805         // Enable the BTB
806         mrc     p15, 0, r0, c1, c0, 0
807         orr     r0, r0, #MMU_Control_BTB
808         mcr     p15, 0, r0, c1, c0, 0
809         CPWAIT  r0
810
811         // clean/drain/flush the main Dcache
812         mov     r1, #DCACHE_FLUSH_AREA  // use a CACHEABLE area of
813                                         // the memory map above SDRAM
814         mov     r0, #1024               // number of lines in the Dcache
815 20:
816         mcr     p15, 0, r1, c7, c2, 5   // allocate a Dcache line
817 /* increment the address to the next cache line */
818         add     r1, r1, #32
819 // decrement the loop count
820         subs    r0, r0, #1              // decrement the loop count
821         bne     20b
822
823         // clean/drain/flush the mini Dcache
824         ldr     r2, =(DCACHE_FLUSH_AREA+DCACHE_SIZE) // use a CACHEABLE area of
825                                         // the memory map above SDRAM
826         mov     r0, #64                 // number of lines in the mini Dcache
827 21:
828         mcr     p15, 0, r2, c7, c2, 5   // allocate a Dcache line
829         add     r2, r2, #32             // increment the address to
830                                         // the next cache line
831         subs    r0, r0, #1              // decrement the loop count
832         bne     21b
833
834         mcr     p15, 0, r0, c7, c6, 0   // flush Dcache
835         CPWAIT  r0
836
837         mcr     p15, 0, r0, c7, c10, 4  // drain the write & fill buffers
838         CPWAIT  r0
839 #if 1
840         mov     r0, #0x1000000
841 1:
842         subs    r0, r0, #1
843         bne     1b
844 #endif
845         // Save SDRAM size
846         ldr     r1, =hal_dram_size      // [see hal_intr.h]
847         str     r8, [r1]
848
849         // Move mmu tables into RAM so page table walks by the cpu
850         // don't interfere with FLASH programming.
851         ldr     r0, =mmu_table
852         mov     r4, r0
853         add     r2, r0, #0x4800         // End of tables
854         mov     r1, #RAM_BASE
855         orr     r1, r1, #0x4000         // RAM tables
856         mov     r5, r1
857
858         // first, fixup physical address to second level
859         // table used to map first 1MB of flash.
860         ldr     r3, [r0], #4
861         sub     r3, r3, r4
862         add     r3, r3, r5
863         str     r3, [r1], #4
864         // everything else can go as-is
865 1:
866         ldr     r3, [r0], #4
867         str     r3, [r1], #4
868         cmp     r0, r2
869         bne     1b
870
871         // go back and fixup physical address to second level
872         // table used to map first 1MB of SDRAM.
873         add     r1, r5, #(0xA00 * 4)
874         ldr     r0, [r1]                // entry for first 1MB of DRAM
875         sub     r0, r0, r4
876         add     r0, r0, r5
877         str     r0, [r1]                // store it back
878
879         // Flush the cache
880         mov     r0, #DCACHE_FLUSH_AREA  /* cache flush region */
881         add     r1, r0, #0x8000 /* 32KB cache   */
882 667:
883         mcr     p15, 0, r0, c7, c2, 5   /* allocate a line      */
884         add     r0, r0, #32             /* 32 bytes/line        */
885         teq     r1, r0
886         bne     667b
887         mcr     p15, 0, r0, c7, c6, 0   /* invalidate data cache */
888         /* cpuwait */
889         mrc     p15, 0, r1, c2, c0, 0   /* arbitrary read       */
890         mov     r1, r1
891         sub     pc, pc, #4
892         mcr     p15, 0, r0, c7, c10, 4
893         /* cpuwait */
894         mrc     p15, 0, r1, c2, c0, 0   /* arbitrary read       */
895         mov     r1, r1
896         sub     pc, pc, #4
897         nop
898
899         // Set the TTB register to DRAM mmu_table
900         mov     r0, r5
901         mov     r1, #0
902         mcr     p15, 0, r1, c7, c5, 0   // flush I cache
903         mcr     p15, 0, r1, c7, c10, 4  // drain WB
904         mcr     p15, 0, r0, c2, c0, 0   // load page table pointer
905         mcr     p15, 0, r1, c8, c7, 0   // flush TLBs
906         CPWAIT  r0
907
908         //Disable software and data breakpoints
909         mov     r0, #0
910         mcr     p15, 0, r0, c14, c8, 0  // ibcr0
911         mcr     p15, 0, r0, c14, c9, 0  // ibcr1
912         mcr     p15, 0, r0, c14, c4, 0  // dbcon
913
914         //Enable all debug functionality
915         mov     r0, #0x80000000
916         mcr     p14, 0, r0, c10, c0, 0  // dcsr
917 #if 0
918 220961:
919         ldr     r1, =0x00000800         // we use GPIO23 for controlling the debug LED
920
921         ldr     r0, =GPCRx
922         str     r1, [r0]                // switch the LED on
923
924         ldr     r2, =0x00500000         // wait some time
925         mov     r3, #1
926 998:
927         sub     r2, r2, r3
928         cmp     r2, #0
929         bne     998b
930
931         ldr     r0, =GPSRx              // switch the LED off
932         str     r1, [r0]
933
934         ldr     r2, =0x00500000         // wait some time
935         mov     r3, #1
936 998:
937         sub     r2, r2, r3
938         cmp     r2, #0
939         bne     998b
940
941         b       220961b
942 #endif
943         mov     r0, #0
944
945         //---- Wait 200 usec
946         ldr     r3, =OSCR                       // reset the OS Timer Count to zero
947         mov     r2, #0
948         str     r2, [r3]
949         ldr     r4, =0x300              // really 0x2E1 is about 200usec, so 0x300 should be plenty
950 10:
951         add     r0, r0, #1
952         ldr     r2, [r3]
953         cmp     r4, r2
954         bgt     10b
955
956         ldr     r2, =0xa0800000
957         str     r0, [r2]
958         .endm   // _platform_setup1
959 /*----------------------------------------------------------------------*/
960 /* end of hal_platform_setup.h                                          */
961 #endif /* CYGONCE_HAL_PLATFORM_SETUP_H */