1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright © 2010 by Rafaël Carré
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
25 #define CACHE_ALL 0x0C
26 #define UNCACHED_ADDR(a) (a + 0x10000000)
28 #if defined(SANSA_CLIP) || defined(SANSA_M200V4) || defined(SANSA_C200V2)
29 /* 16 bits external bus, low power SDRAM, 16 Mbits = 2 Mbytes */
30 #define MEMORY_MODEL 0x21
32 #elif defined(SANSA_E200V2) || defined(SANSA_FUZE) || defined(SANSA_CLIPV2) \
33 || defined(SANSA_CLIPPLUS) || defined(SANSA_FUZEV2)
34 /* 16 bits external bus, high performance SDRAM, 64 Mbits = 8 Mbytes */
35 #define MEMORY_MODEL 0x5
38 #error "The external memory in your player is unknown"
48 ldr r2, =0xC80F0014 @ CGU_PERI
50 orr r1, r1, #(CGU_EXTMEM_CLOCK_ENABLE|CGU_EXTMEMIF_CLOCK_ENABLE)
53 ldr r3, =0xC6030000 @ MPMC_BASE
55 mov r2, #1 @ enable MPMC
56 str r2, [r3] @ MPMC_CONTROL
57 ldr r2, =0x183 @ SDRAM NOP, all clocks high
58 str r2, [r3, #0x20] @ MPMC_DYNAMIC_CONTROL
59 ldr r2, =0x103 @ SDRAM PALL, all clocks high
60 str r2, [r3, #0x20] @ MPMC_DYNAMIC_CONTROL
61 ldr r1, =0x138 @ 0x138 * 16 HCLK ticks between SDRAM refresh cycles
62 str r1, [r3, #0x24] @ MPMC_DYNAMIC_REFRESH
63 mov r2, #0 @ little endian, HCLK:MPMCCLKOUT[3:0] ratio = 1:1
64 str r2, [r3, #8] @ MPMC_CONFIG
66 ldr r2, [r3, #0xfe8] @ MPMC_PERIPH_ID2
68 movne r2, #1 @ command delayed, clock out not delayed
69 strne r2, [r3, #0x28] @ MPMC_DYNAMIC_READ_CONFIG
75 str r1, [r3, #0x30] @ tRP
76 str ip, [r3, #0x34] @ tRAS
77 str r0, [r3, #0x38] @ tSREX
78 str r2, [r3, #0x3c] @ tAPR
79 str ip, [r3, #0x40] @ tDAL
80 str r1, [r3, #0x44] @ tWR
81 str r0, [r3, #0x48] @ tRC
82 str r0, [r3, #0x4c] @ tRFC
83 str r0, [r3, #0x50] @ tXSR
84 str r1, [r3, #0x54] @ tRRD
85 str r1, [r3, #0x58] @ tMRD
86 mov ip, #(MEMORY_MODEL << 7)
87 str ip, [r3, #0x100] @ MPMC_DYNAMIC_CONFIG_CONFIG_0
88 orr r1, r1, #(2<<8) @ CAS & RAS latency = 2 clock cycle
89 str r1, [r3, #0x104] @ MPMC_DYNAMIC_CONFIG_RASCAS_0
91 str r2, [r3, #0x120] @ MPMC_DYNAMIC_CONFIG_CONFIG_1
92 str r2, [r3, #0x124] @ MPMC_DYNAMIC_CONFIG_RASCAS_1
93 str r2, [r3, #0x140] @ MPMC_DYNAMIC_CONFIG_CONFIG_2
94 str r2, [r3, #0x144] @ MPMC_DYNAMIC_CONFIG_RASCAS_2
95 str r2, [r3, #0x160] @ MPMC_DYNAMIC_CONFIG_CONFIG_3
96 str r2, [r3, #0x164] @ MPMC_DYNAMIC_CONFIG_RASCAS_3
98 mov r1, #0x82 @ SDRAM MODE, MPMCCLKOUT runs continuously
99 str r1, [r3, #0x20] @ MPMC_DYNAMIC_CONTROL
101 ldr r1, =DRAM_ORIG+(0x2300*MEM)
104 str r2, [r3, #0x20] @ MPMC_DYNAMIC_CONTROL= SDRAM NORMAL,
105 @ MPMCCLKOUT stopped when SDRAM is idle
107 ldr r2, [r3, #0x100] @ MPMC_DYNAMIC_CONFIG_0
108 orr r2, r2, #(1<<19) @ buffer enable
111 #endif /* BOOTLOADER */
113 @ XXX: to avoid using the stack, we rely on the fact that:
117 @ do not modify ip (r12)
124 mov r0, #0 @ physical address
125 mov r1, #0 @ virtual address
126 mov r2, #0x1000 @ size (all memory)
130 mov r0, #0 @ physical address
131 ldr r1, =IRAM_ORIG @ virtual address
132 mov r2, #1 @ size : 1MB
136 mov r0, #0 @ physical address
137 ldr r1, =UNCACHED_ADDR(IRAM_ORIG) @ virtual address
138 mov r2, #1 @ size : 1MB
142 mov r0, #0x30000000 @ physical address
143 mov r1, #DRAM_ORIG @ virtual address
144 mov r2, #MEMORYSIZE @ size
148 mov r0, #0x30000000 @ physical address
149 mov r1, #UNCACHED_ADDR(DRAM_ORIG) @ virtual address
150 mov r2, #MEMORYSIZE @ size
154 /* map 1st mbyte of RAM at 0x0 to have exception vectors available */
156 mov r0, #0x81000000 @ physical address
158 mov r0, #0x30000000 @ physical address
160 mov r1, #0 @ virtual address