]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/xscale/triton270/v2_0/include/hal_platform_setup.h
Initial revision
[karo-tx-redboot.git] / packages / hal / arm / xscale / triton270 / 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:         23th August 2004
47 // Purpose:      KaRo TRITON 270 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_triton270.h>        // Platform specific hardware definitions
58 #include <cyg/hal/hal_mmu.h>            // MMU definitions
59
60
61 // Define macro used to diddle the LEDs during early initialization.
62 // Can use r0+r1.  Argument in \x.
63 #define CYGHWR_LED_MACRO nop ;
64
65
66
67 // The main useful output of this file is PLATFORM_SETUP1: it invokes lots
68 // of other stuff (may depend on RAM or ROM start).  The other stuff is
69 // divided into further macros to make it easier to manage what's enabled
70 // when.
71
72 #if defined(CYG_HAL_STARTUP_ROM)
73 #define PLATFORM_SETUP1 _platform_setup1
74 //#define CYGHWR_HAL_ARM_HAS_MMU
75 #else
76 #define PLATFORM_SETUP1
77 #endif
78
79
80 #define RAM_BASE        0xa0000000
81 #define DRAM_SIZE       (64*1024*1024)          // max size of available SDRAM
82 #define DCACHE_SIZE     (32*1024)               // size of the Dcache
83 #define DCACHE_FLUSH_AREA (RAM_BASE+DRAM_SIZE)  // NB: needs page table support
84
85 #if 0
86 #define CPSR_IRQ_DISABLE                0x80    // IRQ disabled when =1
87 #define CPSR_FIQ_DISABLE                0x40    // FIQ disabled when =1
88 #define CPSR_FIQ_MODE                   0x11
89 #define CPSR_IRQ_MODE                   0x12
90 #define CPSR_SUPERVISOR_MODE    0x13
91 #define CPSR_UNDEF_MODE                 0x1B
92
93 #define CPSR_MODE_BITS          0x1F
94
95 #endif
96
97
98
99 #define MMU_Control_BTB 0x800
100
101 // Reserved area for battery backup SDRAM memory test
102 // This area is not zeroed out by initialization code
103 #define SDRAM_BATTERY_TEST_BASE         0xA1FFFFF0      // base address of last 16 memory locations in a 32MB SDRAM
104
105
106
107         .macro MEM_TEST
108                 nop
109         .endm
110
111
112
113
114         // macro to print a string
115         // modifies r9-r12
116         .macro PRINT_STRING_STD address
117         ldr             r9, =\address                   // print our welcome string
118         ldr             r10, =STLSR
119         ldr             r11, =STTHR
120         
121         
122 12:
123         ldr             r12, [r10]              // LSR
124         and             r12, r12, #32
125         cmp             r12, #32
126         bne             12b
127         
128         ldrb    r12, [r9], #1
129         str             r12, [r11]
130         cmp             r12, #0
131         bne             12b
132         .endm
133
134
135
136
137
138
139                 
140         // Trigger the logic analyzer by writing a particular
141         // address, and triggering on that address.
142         .macro TRIGGER_LA_ON_ADDRESS address, reg0, reg1
143         mrc     p15, 0, \reg0, c1, c0, 0     // read ARM control register
144         //      CPWAIT  \reg0
145         ldr     \reg1, =\address
146         str     \reg0, [\reg1]
147         .endm
148
149         // Delay a bit
150         .macro DELAY_FOR cycles, reg0
151         ldr     \reg0, =\cycles
152         subs    \reg0, \reg0, #1
153         subne   pc,  pc, #0xc
154         .endm
155         
156         // wait for coprocessor write complete
157         .macro CPWAIT reg
158         mrc  p15,0,\reg,c2,c0,0
159         mov  \reg,\reg
160         sub  pc,pc,#4
161         .endm
162
163         // blink some times on GPIO0
164         .macro BLINK0 count
165                 ldr  r4, =\count
166         
167       
168                 220961:                                                               
169                         ldr             r1,=0x00000001                  // we use GPIO0 for controlling the debug LED
170                      
171                 
172                         ldr             r0,=GPCRa
173                         str             r1,     [r0]                            // switch the LED on
174                 
175                 
176                         ldr             r2,=0x005                       // wait some time
177                         mov             r3,#1                   
178                 998:                    
179                         sub             r2, r2, r3
180                         cmp             r2,#0
181                         bne             998b
182                 
183                         ldr             r0,=GPSRa                               // switch the LED off
184                         str             r1,     [r0]
185                 
186                 
187                         ldr             r2,=0x005                       // wait some time
188                         mov             r3,#1                   
189                 998:                    
190                         sub             r2, r2, r3
191                         cmp             r2,#0
192                         bne             998b
193                 
194                         sub             r4, r4, r3
195                         cmp             r4, #0
196                         bne             220961b
197         
198         .endm
199
200
201
202
203
204
205
206         .macro TRITON270_SET_REFR_VAL
207         // TRITON270 specific, DRAM specific !!!!!!!!!!!!!
208
209
210
211         
212         
213         ldr r3, =MDREFR 
214         ldr r2, [r3]                    // read MDREFR value
215         ldr     r4, =0xFFF
216         bic r2, r2, r4  
217         // clear out value in DRI
218         
219         
220         
221         
222         #ifdef TRITON270_DRAM32_64
223                 // DRI = (64 ms * 99,5 MHz / 8192 - 31) / 32 = 23   (0x17)
224                 orr r2, r2, #0x00000017         // put in a valid SDRAM Refresh Interval (DRI)
225         #endif
226         
227         #ifdef TRITON270_DRAM16_32
228                 // DRI = (64 ms * 99,5 MHz / 8192 - 31) / 32 = 23   (0x17)
229                 orr r2, r2, #0x00000017         // put in a valid SDRAM Refresh Interval (DRI)
230         #endif
231
232
233
234         #ifdef TRITON270_DRAM32_128
235                 // DRI = (64 ms * 99,5 MHz / 8192 - 31) / 32 = 23   (0x17)
236                 orr r2, r2, #0x00000017         // put in a valid SDRAM Refresh Interval (DRI)
237         #endif
238         
239         
240         str     r2, [r3]                                // store it
241         
242         
243         .endm
244
245
246
247
248
249
250         .macro TRITON270_CONFIG_SDRAM_BANKS
251
252
253
254         
255         ldr r3, =MDCNFG             // sdram config -- sdram should remain disabled !!!!!
256                                                                 
257
258
259
260         
261         
262         
263         
264         
265         #ifdef TRITON270_DRAM32_64
266                 ldr r2, =0x08000bc8             // 13 rows / 9 col / 2 bank / 32 bit / CL3
267
268         #endif
269
270
271         #ifdef TRITON270_DRAM16_32
272                 ldr r2, =0x08000bcc             // 13 rows / 9 col / 2 bank / 16 bit / CL3
273
274         #endif
275
276
277
278
279         #ifdef TRITON270_DRAM16_64
280                 ldr r2, =0x08000bcC             // 13 rows / 9 col / 2 bank / 32 bit / CL3
281
282         #endif
283
284
285
286         #ifdef TRITON270_DRAM32_128
287                 ldr r2, =0x88000bd0             // 13 rows / 10 col / 2 bank / 32 bit / CL3 / 1 GB Memory map
288
289         #endif
290
291
292
293         str r2, [r3] 
294         .endm
295         
296         
297         
298         
299         
300
301
302
303         // form a first-level section entry
304         .macro FL_SECTION_ENTRY base,x,ap,p,d,c,b
305         .word (\base << 20) | (\x << 12) | (\ap << 10) | (\p << 9) |\
306               (\d << 5) | (\c << 3) | (\b << 2) | 2
307         .endm
308
309         // form a first-level page table entry
310         .macro FL_PT_ENTRY base,d
311         // I wanted to use logical operations here, but since I am using symbols later 
312         // to fill in the parameters, I had to use addition to force the assembler to
313         // do it right
314         .word \base + (\d << 5) + 1
315         .endm
316
317         // form a second level small page entry
318         .macro SL_SMPAGE_ENTRY base,ap3,ap2,ap1,ap0,c,b
319         .word (\base << 12) | (\ap3 << 10) | (\ap2 << 8) | (\ap1 << 6) |\
320               (\ap0 << 4) | (\c << 3) | (\b << 2) | 2
321         .endm
322
323         // form a second level extended small page entry
324         .macro SL_XSMPAGE_ENTRY base,x,ap,c,b
325         .word (\base << 12) | (\x << 6) | (\ap << 4) | (\c << 3) | (\b << 2) | 3
326         .endm
327
328
329         // start of platform setup
330         .macro _platform_setup1
331
332         // This is where we wind up immediately after reset. On the CYCLONE, we have
333         // to jump around a hole in flash which runs from 0x00001000 - 0x0001fff.  
334         // The start of _platform_setup1 will be below 0x1000 and since we need to
335         // align the mmu table on a 16k boundary, we just branch around the page
336         // table which we will locate at FLASH_BASE+0x4000.
337         b _real_platform_setup
338
339         .p2align 13
340         // the following alignment creates the mmu table at address 0x4000.
341     mmu_table:
342
343         // 1MB of FLASH with i80312 MMRs mapped in using 4K small pages so we can
344         // set the access permission on flash and memory-mapped registers properly.
345         FL_PT_ENTRY mmu_table_flashbase,0
346
347         // Remaining 63MB of FLASH area (Static Chip select 0)
348         //   rw, cacheable, non-bufferable
349         .set    __base,1
350         .rept   0x040-0x001
351         FL_SECTION_ENTRY __base,0,3,0,0,1,0
352         .set    __base,__base+1
353         .endr   
354         
355         
356         // nothing interesting here, static chip select area 1 (Address Translation)
357         .rept   0x080 - 0x040
358         FL_SECTION_ENTRY __base,0,3,0,0,0,0
359         .set    __base,__base+1
360         .endr
361
362
363         // nothing interesting here, static chip select area 2 (Address Translation)
364         .rept   0x0C0 - 0x080
365         FL_SECTION_ENTRY __base,0,3,0,0,0,0
366         .set    __base,__base+1
367         .endr
368
369
370         // nothing interesting here, static chip select area 3 (Address Translation)
371         .rept   0x100 - 0x0C0
372         FL_SECTION_ENTRY __base,0,3,0,0,0,0
373         .set    __base,__base+1
374         .endr
375
376         // nothing interesting here, static chip select area 4 (Address Translation)
377         .rept   0x140 - 0x100
378         FL_SECTION_ENTRY __base,0,3,0,0,0,0
379         .set    __base,__base+1
380         .endr
381
382         // nothing interesting here, static chip select area 5 (Address Translation)
383         .rept   0x180 - 0x140
384         FL_SECTION_ENTRY __base,0,3,0,0,0,0
385         .set    __base,__base+1
386         .endr
387
388
389
390         // nothing interesting here (Address Translation)
391         .rept   0xA00 - 0x180
392         FL_SECTION_ENTRY __base,0,3,0,0,0,0
393         .set    __base,__base+1
394         .endr
395
396         
397
398
399         
400
401
402         // up to 64MB SDRAM
403         //   x=c=b=1
404         // first 1MB mapped by second level table
405         FL_PT_ENTRY mmu_table_rambase,0
406         .set    __base,__base+1
407         
408         
409         
410         
411         // remainder of SDRAM mapped 1-to-1
412         .rept   0xC00 - 0xA01
413         FL_SECTION_ENTRY __base,1,3,1,0,1,1
414         .set    __base,__base+1
415         .endr
416         
417         
418         
419         
420         
421         
422         
423         
424         
425         
426         
427         
428
429         // Cache flush region.
430         // Don't need physical memory, just a cached area.
431         .rept   0xD00 - 0xC00
432         FL_SECTION_ENTRY __base,0,3,0,0,1,1
433         .set    __base,__base+1
434         .endr
435         
436         // Invalid
437         .rept   0x1000 - 0xD00
438         .word 0
439         .set    __base,__base+1
440         .endr
441
442
443         // Immediately after the above table (at 0x8000) is the
444         // second level page table which breaks up the lowest 1MB
445         // of physical memory into 4KB sized virtual pages. 
446     mmu_table_flashbase:
447         // Virtual address 0 (Flash boot code).
448         // Map 4k page at 0x00000000 virt --> 0xA0000000 physical
449         // This allows us to have a writable vector table.
450         //   Read-Write, cacheable, bufferable
451         SL_XSMPAGE_ENTRY 0xa0000,1,3,1,1
452
453         // Virtual address 0x1000 (Memory mapped registers)
454         // Map 1-to-1, but don't cache or buffer
455         //   Read-Write, non-cacheable, non-bufferable         
456         .set    __base,1                   
457         SL_SMPAGE_ENTRY __base,3,3,3,3,0,0
458         .set    __base,__base+1
459
460         // Virtual address 0x2000-0x100000 (remainder of flash1)
461         //   Read-Write, cacheable, non-bufferable
462         .rept   0x100 - 0x2
463         SL_SMPAGE_ENTRY __base,3,3,3,3,1,0
464         .set    __base,__base+1
465         .endr
466
467         // Now is the second level table for the first megabyte
468         // of DRAM.
469     mmu_table_rambase:
470         // Map 4k page at 0xa0000000 virt --> 0x00000000 physical
471         //   Read-Write, cacheable, non-bufferable
472         SL_SMPAGE_ENTRY 0x00000,3,3,3,3,1,0
473         .set    __base,__base+1            
474
475         // Map remainder of first meg of SDRAM
476         //   Read-Write, cacheable, non-bufferable
477         .set    __base,0xA0001
478         .rept   0x100 - 0x1
479         SL_XSMPAGE_ENTRY __base,1,3,1,1
480         .set    __base,__base+1
481         .endr
482
483
484
485 _real_platform_setup://Angel SDRAM init code follows
486
487
488
489         mov    r6, #0 
490         ldr             r0, =CKEN
491         ldr             r1, = 0x81ffffff
492         str             r1, [r0]
493
494
495         // if we come out of sleep mode, check if there is a pointer
496         // from the os, and jump to it if so
497
498         ldr r0, =RCSR                           // check reset source
499         ldr     r1, [r0]
500         and r1, r1, #4
501         cmp r1, #4
502         bne 1923f
503
504
505
506         ldr r2, =PSPR                           // check if there is a pointer from the operating system
507         ldr r1, [r2]
508         cmp r1, #0
509         beq 1922f                                       // wake up from deep sleep
510
511         //ldr r3, =0x0000000f                   // reset RCSR
512         //str r3, [r0]
513
514
515 #if 0
516         ldr             r0, =CKEN
517         ldr             r1, [r0]
518         orr             r1, r1, #(1<<22)                                                // enable memory controller
519         str             r1, [r0]
520 #endif
521
522         // get SDRAM out of Self Refresh
523         TRITON270_SET_REFR_VAL
524         TRITON270_CONFIG_SDRAM_BANKS
525
526         
527         ldr r3, =MDREFR 
528         ldr r2, [r3]                            // read MDREFR value
529         bic r2, r2, #0x03800000         // clear all Free Running Clocks
530         orr r2, r2, #0x00010000         // assert MDREFR:K1RUN
531         ldr r4, =0x20020000
532         orr r2, r2, r4                          // set K0DB4, K1DB2
533         str r2, [r3]                // change from "self-refresh and clock-stop" to "self-refresh"
534         ldr r2, [r3]                            // read MDREFR value 
535         
536         bic r2, r2, #0x00400000         // clear self-refresh bit
537         str r2, [r3]                // change from "self-refresh" to "Power Down" 
538         orr r2, r2, #0x00008000     // assert MDREFR:E1PIN
539         str r2, [r3]                // change from "Power Down" to "PWRDWNX" 
540         nop 
541         nop                         // no write required to change from "PWRDWNX" to "NOP" 
542
543         
544         
545
546         ldr r3, =MDCNFG               // sdram config -- sdram enable 
547         ldr r2, [r3] 
548         orr r2, r2, #0x00000001       // enable appropriate banks 
549         str r2, [r3] 
550         
551         
552         
553         
554     // initialize CPSR (machine state register)
555     mov     r0,#(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_SUPERVISOR_MODE)
556     msr     cpsr,r0
557
558
559         b __setup_stack
560
561         .rept   32
562         .word 0
563         .endr   
564
565 __setup_stack:
566
567         /*  Set up the stack pointer to a fixed value */
568         ldr     r3, =__setup_stack
569         sub r3, r3, #4
570         mov     sp, r3
571
572         
573         ldr r2, =PSPR                           // get pointer
574         ldr r1, [r2]
575         mov r15, r1                                     // jump to pointer
576         
577
578         
579         
580         1922:
581         
582         mov    r6, #1 
583
584         
585         ldr             r0, =CKEN
586         ldr             r1, = 0x81ffffff
587         str             r1, [r0]
588
589
590         1923:
591
592
593         
594         bl  __hal_initio                        // init the IO pins
595
596    //BLINK0 10  
597         
598
599         //PSSR = 0x20 clear the RDH and PH bit in the PSSR
600         ldr             r0,     =PSSR
601         ldr             r1,     =0x30
602         str             r1, [r0]
603         
604
605
606
607
608         ldr r3, =PCFR                   // clear PCFR[FS] and PCFR[FP]
609         ldr r2, [r3]
610         bic r2, r2, #0x00000006
611         str r2, [r3]
612
613
614
615 #ifdef GPIO_10_OUT
616         BLINK10 3
617 #endif  
618
619
620
621
622
623   MRC           p15, 0, r0, c0, c0, 0                   // read the ID reg ....  0x69052100
624         // and display it if possible
625         // not possible TRITON270 SK3   
626
627         
628
629 // turn everything off
630         mov    r0, #0x78                         
631         mcr    p15, 0, r0, c1, c0, 0    // caches off -- MMU off or ID map
632
633         mcr p15, 0, R0, c7, c7, 0       // Invalidate the I & D cache, mini- d cache, and BTB
634
635
636         MCR p15, 0, r0, c7, c10, 4      // Drain write buffer -- r0 ignored
637
638                                                                 // CPWAIT macro
639         MRC p15, 0, R0, c2, c0, 0               // arbitrary read of CP15
640         MOV R0, R0                                      // wait for it
641         SUB PC, PC, #4                          // branch to next instruction
642
643     nop
644     nop
645     nop
646     nop
647     
648   
649     
650     
651 // setup manager access, interrupts, etc.
652
653 // grant manager access to all domains
654     mvn    r0, #0               // all 1s                  
655     mcr    p15, 0, r0, c3, c0, 0  
656
657
658                                        // all IRQs should be masked to prevent spurious IRQs
659     ldr    r3, =ICMR                   // pending interrupts are masked from becoming active
660     mov    r2, #0                                     
661     str    r2, [r3]
662     ldr    r3, =ICMR2 
663     str    r2, [r3]     
664
665
666     ldr    r3, =ICLR                   // route all interrupts to CPU IRQ ( not to FIQ )
667     mov    r2, #0                                     
668     str    r2, [r3] 
669     ldr    r3, =ICLR2 
670     str    r2, [r3]    
671
672     ldr    r3, =ICCR                   // only enabled and unmasked interrupts bring core out of idle
673     mov    r2, #1                                     
674     str    r2, [r3]      
675
676
677
678
679
680
681
682
683
684 // Turn on the RTC circuit (if you want)
685
686
687
688     ldr r1, =OSCC               // oscillator config reg
689                 // turn on the 32.768 KHz clock for RTC, etc.
690     mov r0, #0x2                
691     str r0, [r1]        
692
693
694
695
696       // Wait 200 usec
697         ldr r3, =OSCR         // reset the OS Timer Count to zero
698         mov r2, #0 
699         str r2, [r3] 
700         ldr r4, =0x300            // really 0x2E1 is about 200usec, so 0x300 should be plenty
701
702         10:
703         ldr r2, [r3] 
704         cmp r4, r2
705         bgt 10b
706
707
708
709 // CS0  : RDF=8, RDN=8 , RRR=2, 16 bits Flash
710 // Suitable for Flash (Tcyc = 85 ns) and 200 MHz MEMCLK
711
712
713
714         ldr r3, =MSC0                 // low  - bank 0 Flash   CS0 / CS1
715         ldr r2, =0x7ff04ff8                     // 16 Bit Flash
716         str r2, [r3] 
717     ldr r2, [r3]                        // need to read it back to make sure the value latches (see MSC section of manual)
718
719
720
721
722
723
724
725         ldr r3, =MSC1                   // CS3 / CS2      
726         ldr r2, =0x7ff07ff0             
727         str r2, [r3] 
728     ldr r2, [r3]                        // need to read it back to make sure the value latches (see MSC section of manual)
729
730
731
732         ldr r3, =MSC2            // CS5 / CS4     
733         ldr r2, =0x28847ff0             //
734         str r2, [r3] 
735     ldr r2, [r3]                        // need to read it back to make sure the value latches (see MSC section of manual)
736
737
738
739
740
741
742      // ********************************************************************
743      // Disable (mask) all interrupts at the interrupt controller
744      
745
746      // clear the interrupt level register (use IRQ, not FIQ)
747        
748      mov     r1, #0
749      ldr     r2,  =ICLR
750      str     r1,  [r2]
751      ldr     r2,  =ICLR2
752      str     r1,  [r2]
753         
754      // mask all interrupts at the controller
755                
756      ldr     r2,  =ICMR
757      str     r1,  [r2]
758      ldr     r2,  =ICMR2
759      str     r1,  [r2]
760
761
762
763
764     // make sure the DCACHE is off 
765         mov    r0, #0x78                                // turn everything off 
766         mcr    p15, 0, r0, c1, c0, 0            // caches off, MMU off, etc.
767         
768
769
770
771
772
773
774
775
776         TRITON270_SET_REFR_VAL
777
778
779
780         ldr r3, =SXCNFG
781         mov r2, #0x0                            // configure the synchrounous flash memory later
782         str     r2, [r3]                                // 
783
784         
785
786
787
788         
789         ldr r3, =MDREFR 
790         ldr r2, [r3]                            // read MDREFR value
791         bic r2, r2, #0x03800000         // clear all Free Running Clocks
792         orr r2, r2, #0x00010000         // assert MDREFR:K1RUN
793         ldr r4, =0x20020000
794         orr r2, r2, r4                          // set K0DB4, K1DB2
795          
796         str r2, [r3]                // change from "self-refresh and clock-stop" to "self-refresh"
797         ldr r2, [r3]                            // read MDREFR value (to make sure the previous value stuck) (this is in Tricia's code)
798         
799         bic r2, r2, #0x00400000         // clear self-refresh bit
800         str r2, [r3]                // change from "self-refresh" to "Power Down" 
801         orr r2, r2, #0x00008000     // assert MDREFR:E1PIN
802         str r2, [r3]                // change from "Power Down" to "PWRDWNX" 
803         nop 
804         nop                         // no write required to change from "PWRDWNX" to "NOP" 
805
806
807
808
809
810
811
812         TRITON270_CONFIG_SDRAM_BANKS
813
814
815
816
817
818
819       //---- Wait 200 usec
820         ldr r3, =OSCR                      // reset the OS Timer Count to zero
821         mov r2, #0 
822         str r2, [r3] 
823         ldr r4, =0x300                  // really 0x2E1 is about 200usec, so 0x300 should be plenty
824         10:
825         ldr r2, [r3] 
826         cmp r4, r2
827         bgt 10b
828         
829         
830         
831         
832         
833         
834         
835         ldr r3, =SDRAM_B0 
836         mov r2, #8            // now must do 8 refresh or CBR commands before the first access 
837         10:                                       // 
838         str r3, [r3] 
839         subs r2, r2, #1 
840         bne 10b
841         
842         
843
844         ldr r3, =MDCNFG               // sdram config -- sdram enable 
845         ldr r2, [r3] 
846         orr r2, r2, #0x00000001       // enable appropriate banks 
847         str r2, [r3] 
848         
849         
850         
851         
852         
853         
854
855
856         ldr r3, =MDMRS              // write the MDMRS
857         ldr r2, =0x00000032
858         str r2, [r3] 
859
860
861
862
863
864
865       //---- Wait 600 usec
866         ldr r3, =OSCR                      // reset the OS Timer Count to zero
867         mov r2, #0 
868         str r2, [r3] 
869         ldr r4, =0x900                  // really 0x2E1 is about 200usec, so 0x300 should be plenty
870         10:
871         ldr r2, [r3] 
872         cmp r4, r2
873         bgt 10b
874
875
876
877
878         MEM_TEST
879         
880         
881
882         
883         
884         
885
886 _sdram_init_end: 
887
888
889 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
890 //                                                                                                                                                                                                                        //
891 //                                              Memory Test                                                                                                                                                       //
892 //                                                                                                                                                                                                                        //
893 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
894
895 #if 0
896
897         b 70f
898
899 __string_a:
900
901         .ascii "\r\n\r\nchecking SDRAM size now \0"     
902
903
904
905 __string_b:
906
907         .ascii "\r\nfailed\r\nerror, did not found the expected 32 MBytes\r\n\0"     
908
909
910
911 __string_b64:
912
913         .ascii "\r\nfailed\r\nerror, did not found the expected 64 MBytes\r\n\0"     
914
915
916
917
918
919 __string_c:
920
921         .ascii "\r\npassed, 32 MBytes found\r\n\0"     
922
923
924 __string_c64:
925
926         .ascii "\r\npassed, 64 MBytes found\r\n\0"     
927
928
929
930 __string_dot:
931
932         .ascii ".\0"     
933
934
935         .align 3
936
937
938 70:
939
940
941         ldr             r0, =CKEN
942         ldr             r1, = 0x81ffffff
943         orr             r1, r1, #0x20                                           // enable STUART
944         str             r1, [r0]
945
946
947 // setup the standard UART
948 //
949 // 38400 baud 8N1
950 //
951 //
952     ldr         r0,     = STLCR          
953         ldr             r1,      = 0x83                                 // enable Divisor Latch Access
954         str             r1, [r0]
955
956     ldr         r0,     = STDLH          
957         ldr             r1,      = 0x00                                 // 
958         str             r1, [r0]
959
960     ldr         r0,     = STDLL          
961         ldr             r1,      = 24                                   // 38400 Baud
962         str             r1, [r0]
963
964     ldr         r0,     = STLCR          
965         ldr             r1,      = 0x03                                 // set 8N1
966         str             r1, [r0]
967         
968         
969         ldr             r0, = STFCR                                     // enable FIFOs
970         ldr             r1, =0x03
971 //      str             r1, [r0]
972         
973         
974         
975         
976         ldr             r0, =STIER
977         ldr             r1, =0x40                                       // enable UART
978         str             r1, [r0]
979
980
981
982
983
984
985
986
987
988
989 #if 1
990         b 938f
991 __string_dsleep:
992
993         .ascii "\r\nwaking up from deep sleep mode ... \r\n\0"     
994         .align 3
995
996 938:
997         cmp r6, #0
998         beq 939f
999         PRINT_STRING_STD __string_dsleep
1000
1001 #endif 
1002
1003 939:
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013 #ifdef DRAM_TEST32
1014
1015         PRINT_STRING_STD __string_a
1016         
1017         ldr     r0, =0xa0000000                 // base address
1018         ldr r1, =32                                     // counter
1019         ldr r2, =0x12345678
1020         ldr r3, =0x100000
1021         
1022 88:
1023         mov r4, r0
1024         str r4, [r0], #4
1025         str r2, [r0]
1026         add r0, r0, r3
1027         sub r0, r0, #4
1028         sub r1, r1, #1
1029         cmp r1, #0
1030         bne 88b
1031         
1032         
1033         
1034         // test now
1035         
1036         ldr     r0, =0xa0000000                 // base address
1037         ldr r1, =0                                      // counter
1038         ldr r2, =0x12345678
1039         ldr r3, =0x100000
1040
1041 89:
1042         mov r4, r0
1043         ldr r5, [r0], #4
1044         cmp r5, r4
1045         bne 99f                                         // no match
1046         ldr r5, [r0]
1047         cmp r5, r2
1048         bne 99f                                         // no match
1049         PRINT_STRING_STD __string_dot
1050         add r0, r0, r3
1051         sub r0, r0, #4
1052         add r1, r1, #1
1053         cmp r1, #32
1054         bne 89b
1055         
1056         
1057 99:     
1058         cmp r1, #32
1059         beq     100f
1060         
1061         PRINT_STRING_STD __string_b
1062         
1063 __halt_system001:
1064         nop
1065         nop
1066         b __halt_system001
1067
1068 100:
1069
1070         PRINT_STRING_STD __string_c
1071
1072
1073 101:
1074
1075 #endif
1076
1077 #ifdef DRAM_TEST64
1078
1079         
1080
1081
1082         PRINT_STRING_STD __string_a
1083         
1084         ldr     r0, =0xa0000000                 // base address
1085         ldr r1, =64                                     // counter
1086         ldr r2, =0x12345678
1087         ldr r3, =0x100000
1088         
1089 88:
1090         mov r4, r0
1091         str r4, [r0], #4
1092         str r2, [r0]
1093         add r0, r0, r3
1094         sub r0, r0, #4
1095         sub r1, r1, #1
1096         cmp r1, #0
1097         bne 88b
1098         
1099         
1100         
1101         // test now
1102         
1103         ldr     r0, =0xa0000000                 // base address
1104         ldr r1, =0                                      // counter
1105         ldr r2, =0x12345678
1106         ldr r3, =0x100000
1107
1108 89:
1109         mov r4, r0
1110         ldr r5, [r0], #4
1111         cmp r5, r4
1112         bne 99f                                         // no match
1113         ldr r5, [r0]
1114         cmp r5, r2
1115         bne 99f                                         // no match
1116         PRINT_STRING_STD __string_dot
1117         add r0, r0, r3
1118         sub r0, r0, #4
1119         add r1, r1, #1
1120         cmp r1, #64
1121         bne 89b
1122         
1123         
1124 99:     
1125         cmp r1, #64
1126         beq     100f
1127         
1128         PRINT_STRING_STD __string_b64
1129         
1130 __halt_system001:
1131         nop
1132         nop
1133         b __halt_system001
1134
1135 100:
1136
1137         PRINT_STRING_STD __string_c64
1138
1139
1140 101:
1141         
1142         
1143 #endif          //#ifdef DRAM_TEST64
1144
1145
1146
1147
1148
1149
1150
1151 #endif          //#if 1
1152
1153
1154 #if 0
1155
1156
1157
1158         b 170f
1159
1160 __string_a1:
1161
1162         .ascii "\r\n\r\ntesting first 64 kbytes of SDRAM now ... \0"     
1163
1164
1165 __string_a_ok:
1166
1167         .ascii "ok\r\n\r\n\0"     
1168
1169
1170 __string_a_failed:
1171
1172         .ascii "failed\r\n\r\n\0"     
1173
1174         .align 3
1175
1176
1177 170:
1178
1179
1180         PRINT_STRING_STD __string_a1
1181         
1182         ldr     r0, =0xa0000000                 // base address
1183         ldr r1, =0x10000                        // counter
1184         ldr r2, =0x12345678
1185         
1186 188:
1187         str r2, [r0], #4
1188         add r2, r2, #3
1189         sub r1, r1, #1
1190         cmp r1, #0
1191         bne 188b
1192         
1193         
1194         
1195         // test now
1196         
1197         ldr     r0, =0xa0000000                 // base address
1198         ldr r1, =0x10000                        // counter
1199         ldr r2, =0x12345678
1200
1201 189:
1202         ldr r3, [r0], #4
1203         cmp r3, r2
1204         beq 190f
1205         
1206         
1207         
1208         PRINT_STRING_STD __string_a_failed
1209 191:
1210         nop
1211         nop
1212         b 191b
1213
1214
1215
1216 190:
1217         add r2, r2, #3
1218         sub r1, r1, #1
1219         cmp r1, #0
1220         bne 189b
1221         
1222
1223         PRINT_STRING_STD __string_a_ok
1224
1225
1226 199:
1227
1228
1229 #endif
1230
1231
1232
1233
1234
1235
1236
1237 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1238
1239
1240
1241
1242
1243
1244 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1245 //
1246 //
1247 // Change Frequency!!!
1248 //
1249 //      RUN=208 TURBO=208 SystemBus=208 MEMClk=208 SDRAM=104 Flash=52 LCD=104
1250 //
1251 //      CCCR: L=16 2N=2 A=1                     CLKCFG: T=1 HT=0 B=1
1252 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1253
1254 #if 0
1255
1256         ldr r1, =0x02000110
1257         ldr r2, =CCCR
1258     str    r1, [r2]                             // set speed
1259     mov r1, #0xb                                        // set turbo mode, set fast bus , set frequency change
1260         mov     r3, r1                                          // save value
1261         mcr     p14, 0, r1, c6, c0, 0           // frequency change  sequence
1262         ldr     r1, [r2]                                        // dummy read from CCCR
1263 100:
1264         mrc     p14, 0, r1, c6, c0, 0           // read CLKCFG
1265         cmp r3, r1                                              // compare it with value written
1266         bne 100b
1267         
1268         
1269 #endif
1270
1271
1272
1273
1274         // Enable access to all coprocessor registers
1275         ldr     r0, =0x2001                                     // enable access to all coprocessors
1276         mcr     p15, 0, r0, c15, c1, 0
1277         
1278         mcr     p15, 0, r0, c7, c10, 4          // drain the write & fill buffers
1279         CPWAIT r0       
1280         
1281         mcr     p15, 0, r0, c7, c7, 0           // flush Icache, Dcache and BTB
1282         CPWAIT r0       
1283         
1284         mcr     p15, 0, r0, c8, c7, 0           // flush instuction and data TLBs
1285         CPWAIT r0       
1286
1287
1288
1289         
1290         // Enable the Icache
1291         mrc     p15, 0, r0, c1, c0, 0
1292         orr     r0, r0, #MMU_Control_I
1293         mcr     p15, 0, r0, c1, c0, 0
1294         CPWAIT  r0
1295
1296
1297
1298         // Set the TTB register
1299         ldr     r0, =mmu_table
1300         mcr     p15, 0, r0, c2, c0, 0
1301
1302         // Enable permission checks in all domains
1303         ldr     r0, =0x55555555
1304         mcr     p15, 0, r0, c3, c0, 0
1305         
1306         // Enable the MMU
1307         mrc     p15, 0, r0, c1, c0, 0
1308         orr     r0, r0, #MMU_Control_M
1309         orr     r0, r0, #MMU_Control_R
1310         mcr     p15, 0, r0, c1, c0, 0
1311         CPWAIT  r0
1312         
1313         mcr     p15, 0, r0, c7, c10, 4          // drain the write & fill buffers
1314         CPWAIT r0       
1315
1316
1317
1318
1319         
1320         // Enable the Dcache
1321         mrc     p15, 0, r0, c1, c0, 0
1322         orr     r0, r0, #MMU_Control_C
1323         mcr     p15, 0, r0, c1, c0, 0
1324         CPWAIT  r0
1325
1326         // Enable the BTB
1327         mrc     p15, 0, r0, c1, c0, 0
1328         orr     r0, r0, #MMU_Control_BTB
1329         mcr     p15, 0, r0, c1, c0, 0
1330         CPWAIT  r0
1331
1332
1333         // clean/drain/flush the main Dcache
1334         mov     r1, #DCACHE_FLUSH_AREA           // use a CACHEABLE area of
1335                                                  // the memory map above SDRAM
1336         mov     r0, #1024                        // number of lines in the Dcache
1337     20:
1338         mcr     p15, 0, r1, c7, c2, 5            // allocate a Dcache line
1339 /* increment the address to the next cache line */
1340         add     r1, r1, #32     
1341 // decrement the loop count
1342         subs    r0, r0, #1                       // decrement the loop count
1343         bne     20b
1344
1345
1346
1347         // clean/drain/flush the mini Dcache
1348         ldr     r2, =(DCACHE_FLUSH_AREA+DCACHE_SIZE) // use a CACHEABLE area of
1349                                                 // the memory map above SDRAM
1350         mov     r0, #64                         // number of lines in the mini Dcache
1351     21:
1352         mcr     p15, 0, r2, c7, c2, 5           // allocate a Dcache line
1353         add     r2, r2, #32                     // increment the address to
1354                                                 // the next cache line
1355         subs    r0, r0, #1                      // decrement the loop count
1356         bne     21b
1357
1358
1359         mcr     p15, 0, r0, c7, c6, 0           // flush Dcache
1360         CPWAIT r0
1361
1362         mcr     p15, 0, r0, c7, c10, 4          // drain the write & fill buffers
1363         CPWAIT r0       
1364         
1365         
1366         
1367
1368         
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381         //  !!!!!!!!!!!!!!!!!!!!!!! what is in r8 (usteinkohl)
1382         // Save SDRAM size
1383         //we made it to here ok 
1384         ldr     r1, =hal_dram_size  // [see hal_intr.h] 
1385         str     r8, [r1]
1386
1387
1388
1389
1390
1391         // Move mmu tables into RAM so page table walks by the cpu
1392         // don't interfere with FLASH programming.
1393         ldr     r0,=mmu_table
1394         mov     r4, r0
1395         add     r2, r0, #0x4800         // End of tables
1396         mov     r1, #RAM_BASE
1397         orr     r1, r1, #0x4000                         // RAM tables
1398         mov     r5, r1
1399
1400
1401
1402
1403         // first, fixup physical address to second level
1404         // table used to map first 1MB of flash.
1405         ldr     r3, [r0], #4
1406         sub     r3, r3, r4
1407         add     r3, r3, r5
1408         str     r3, [r1], #4
1409         // everything else can go as-is
1410     1:
1411         ldr     r3, [r0], #4
1412         str     r3, [r1], #4
1413         cmp     r0, r2
1414         bne     1b
1415
1416
1417
1418
1419
1420
1421
1422
1423         // go back and fixup physical address to second level
1424         // table used to map first 1MB of SDRAM.
1425         add     r1, r5, #(0xA00 * 4)
1426         ldr     r0, [r1]                // entry for first 1MB of DRAM
1427         sub     r0, r0, r4
1428         add     r0, r0, r5
1429         str     r0, [r1]                // store it back
1430 //we made it to here ok
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441         // Flush the cache
1442         mov    r0, #DCACHE_FLUSH_AREA   /* cache flush region */
1443         add    r1, r0, #0x8000          /* 32KB cache         */
1444   667:
1445         mcr    p15,0,r0,c7,c2,5         /* allocate a line    */
1446         add    r0, r0, #32              /* 32 bytes/line      */
1447         teq    r1, r0
1448         bne    667b
1449         mcr    p15,0,r0,c7,c6,0         /* invalidate data cache */
1450         /* cpuwait */
1451         mrc    p15,0,r1,c2,c0,0         /* arbitrary read   */
1452         mov    r1,r1
1453         sub    pc,pc,#4
1454         mcr    p15,0,r0,c7,c10,4
1455         /* cpuwait */
1456         mrc    p15,0,r1,c2,c0,0         /* arbitrary read   */
1457         mov    r1,r1
1458         sub    pc,pc,#4
1459         nop
1460 //we make it here ok
1461
1462
1463
1464
1465
1466
1467         // Set the TTB register to DRAM mmu_table
1468         mov     r0, r5
1469         mov     r1, #0
1470         mcr     p15, 0, r1, c7, c5, 0           // flush I cache
1471         mcr     p15, 0, r1, c7, c10, 4          // drain WB
1472         mcr     p15, 0, r0, c2, c0, 0           // load page table pointer
1473         mcr     p15, 0, r1, c8, c7, 0           // flush TLBs
1474         CPWAIT  r0
1475
1476
1477
1478
1479
1480
1481         //Disable software and data breakpoints
1482         mov     r0,#0
1483         mcr     p15,0,r0,c14,c8,0  // ibcr0
1484         mcr     p15,0,r0,c14,c9,0  // ibcr1
1485         mcr     p15,0,r0,c14,c4,0  // dbcon
1486
1487         //Enable all debug functionality
1488         mov     r0,#0x80000000
1489         mcr     p14,0,r0,c10,c0,0  // dcsr
1490
1491
1492 //
1493         
1494         mov             r0, #0
1495         
1496       //---- Wait 200 usec
1497         ldr r3, =OSCR                      // reset the OS Timer Count to zero
1498         mov r2, #0 
1499         str r2, [r3] 
1500         ldr r4, =0x300                  // really 0x2E1 is about 200usec, so 0x300 should be plenty
1501         10:
1502         add             r0, r0, #1
1503         ldr r2, [r3] 
1504         cmp r4, r2
1505         bgt 10b
1506         
1507
1508
1509
1510
1511
1512
1513         /* deactivate reset of SMC91C111 (GPIO10) */
1514         ldr r3, =GPCRa
1515         ldr r2, =0x00000400
1516         str r2, [r3]
1517         
1518
1519 #if 0
1520         b 930f
1521 __string_good_1:
1522
1523         .ascii "\r\nup to now, it is ok \r\n\0"     
1524         .align 3
1525
1526 930:
1527         PRINT_STRING_STD __string_good_1
1528
1529 #endif 
1530
1531         .endm    // _platform_setup1
1532
1533
1534
1535 /*---------------------------------------------------------------------------*/
1536 /* end of hal_platform_setup.h                                               */
1537 #endif /* CYGONCE_HAL_PLATFORM_SETUP_H */
1538
1539
1540