wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Memory sub-system initialization code for INCA-IP development board. |
| 3 | * |
| 4 | * Copyright (c) 2003 Wolfgang Denk <wd@denx.de> |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | #include <config.h> |
| 26 | #include <version.h> |
| 27 | #include <asm/regdef.h> |
| 28 | |
| 29 | |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 30 | #define EBU_MODUL_BASE 0xB8000200 |
| 31 | #define EBU_CLC(value) 0x0000(value) |
| 32 | #define EBU_CON(value) 0x0010(value) |
| 33 | #define EBU_ADDSEL0(value) 0x0020(value) |
| 34 | #define EBU_ADDSEL1(value) 0x0024(value) |
| 35 | #define EBU_ADDSEL2(value) 0x0028(value) |
| 36 | #define EBU_BUSCON0(value) 0x0060(value) |
| 37 | #define EBU_BUSCON1(value) 0x0064(value) |
| 38 | #define EBU_BUSCON2(value) 0x0068(value) |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 39 | |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 40 | #define MC_MODUL_BASE 0xBF800000 |
| 41 | #define MC_ERRCAUSE(value) 0x0100(value) |
| 42 | #define MC_ERRADDR(value) 0x0108(value) |
| 43 | #define MC_IOGP(value) 0x0800(value) |
| 44 | #define MC_SELFRFSH(value) 0x0A00(value) |
| 45 | #define MC_CTRLENA(value) 0x1000(value) |
| 46 | #define MC_MRSCODE(value) 0x1008(value) |
| 47 | #define MC_CFGDW(value) 0x1010(value) |
| 48 | #define MC_CFGPB0(value) 0x1018(value) |
| 49 | #define MC_LATENCY(value) 0x1038(value) |
| 50 | #define MC_TREFRESH(value) 0x1040(value) |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 51 | |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 52 | #define CGU_MODUL_BASE 0xBF107000 |
| 53 | #define CGU_PLL1CR(value) 0x0008(value) |
| 54 | #define CGU_DIVCR(value) 0x0010(value) |
| 55 | #define CGU_MUXCR(value) 0x0014(value) |
| 56 | #define CGU_PLL1SR(value) 0x000C(value) |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 57 | |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 58 | .set noreorder |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 59 | |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 60 | |
wdenk | 67f1336 | 2003-12-27 19:24:54 +0000 | [diff] [blame] | 61 | /* |
| 62 | * void ebu_init(long) |
| 63 | * |
| 64 | * a0 has the clock value we are going to run at |
| 65 | */ |
| 66 | .globl ebu_init |
| 67 | .ent ebu_init |
| 68 | ebu_init: |
Wolfgang Denk | f6a692b | 2005-12-04 00:40:34 +0100 | [diff] [blame] | 69 | __ebu_init: |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 70 | |
wdenk | 67f1336 | 2003-12-27 19:24:54 +0000 | [diff] [blame] | 71 | li t1, EBU_MODUL_BASE |
| 72 | li t2, 0xA0000041 |
| 73 | sw t2, EBU_ADDSEL0(t1) |
| 74 | li t2, 0xA0800041 |
| 75 | sw t2, EBU_ADDSEL2(t1) |
| 76 | li t2, 0xBE0000F1 |
| 77 | sw t2, EBU_ADDSEL1(t1) |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 78 | |
wdenk | 67f1336 | 2003-12-27 19:24:54 +0000 | [diff] [blame] | 79 | li t3, 100000000 |
| 80 | beq a0, t3, 1f |
| 81 | nop |
| 82 | li t3, 133000000 |
| 83 | beq a0, t3, 2f |
| 84 | nop |
| 85 | li t3, 150000000 |
| 86 | beq a0, t3, 2f |
| 87 | nop |
| 88 | b 3f |
| 89 | nop |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 90 | |
wdenk | 67f1336 | 2003-12-27 19:24:54 +0000 | [diff] [blame] | 91 | /* 100 MHz */ |
| 92 | 1: |
| 93 | li t2, 0x8841417D |
| 94 | sw t2, EBU_BUSCON0(t1) |
| 95 | sw t2, EBU_BUSCON2(t1) |
| 96 | li t2, 0x684142BD |
| 97 | b 3f |
| 98 | sw t2, EBU_BUSCON1(t1) /* delay slot */ |
| 99 | |
| 100 | /* 133 or 150 MHz */ |
| 101 | 2: |
| 102 | li t2, 0x8841417E |
| 103 | sw t2, EBU_BUSCON0(t1) |
| 104 | sw t2, EBU_BUSCON2(t1) |
| 105 | li t2, 0x684143FD |
| 106 | sw t2, EBU_BUSCON1(t1) |
| 107 | 3: |
| 108 | j ra |
| 109 | nop |
| 110 | |
| 111 | .end ebu_init |
| 112 | |
| 113 | |
| 114 | /* |
| 115 | * void cgu_init(long) |
| 116 | * |
| 117 | * a0 has the clock value |
| 118 | */ |
| 119 | .globl cgu_init |
| 120 | .ent cgu_init |
| 121 | cgu_init: |
Wolfgang Denk | f6a692b | 2005-12-04 00:40:34 +0100 | [diff] [blame] | 122 | __cgu_init: |
wdenk | 67f1336 | 2003-12-27 19:24:54 +0000 | [diff] [blame] | 123 | |
| 124 | li t1, CGU_MODUL_BASE |
| 125 | |
| 126 | li t3, 100000000 |
| 127 | beq a0, t3, 1f |
| 128 | nop |
| 129 | li t3, 133000000 |
| 130 | beq a0, t3, 2f |
| 131 | nop |
| 132 | li t3, 150000000 |
| 133 | beq a0, t3, 3f |
| 134 | nop |
| 135 | b 5f |
| 136 | nop |
| 137 | |
| 138 | /* 100 MHz clock */ |
| 139 | 1: |
| 140 | li t2, 0x80000014 |
| 141 | sw t2, CGU_DIVCR(t1) |
| 142 | li t2, 0x80000000 |
| 143 | sw t2, CGU_MUXCR(t1) |
| 144 | li t2, 0x800B0001 |
| 145 | b 5f |
| 146 | sw t2, CGU_PLL1CR(t1) /* delay slot */ |
| 147 | |
| 148 | /* 133 MHz clock */ |
| 149 | 2: |
| 150 | li t2, 0x80000054 |
| 151 | sw t2, CGU_DIVCR(t1) |
| 152 | li t2, 0x80000000 |
| 153 | sw t2, CGU_MUXCR(t1) |
| 154 | li t2, 0x800B0001 |
| 155 | b 5f |
| 156 | sw t2, CGU_PLL1CR(t1) /* delay slot */ |
| 157 | |
| 158 | /* 150 MHz clock */ |
| 159 | 3: |
| 160 | li t2, 0x80000017 |
| 161 | sw t2, CGU_DIVCR(t1) |
| 162 | li t2, 0xC00B0001 |
| 163 | sw t2, CGU_PLL1CR(t1) |
| 164 | li t3, 0x80000000 |
| 165 | 4: |
| 166 | lw t2, CGU_PLL1SR(t1) |
| 167 | and t2, t2, t3 |
| 168 | beq t2, zero, 4b |
| 169 | nop |
| 170 | li t2, 0x80000001 |
| 171 | sw t2, CGU_MUXCR(t1) |
| 172 | 5: |
| 173 | j ra |
| 174 | nop |
| 175 | |
| 176 | .end cgu_init |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 177 | |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 178 | |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 179 | /* |
| 180 | * void sdram_init(long) |
| 181 | * |
| 182 | * a0 has the clock value |
| 183 | */ |
| 184 | .globl sdram_init |
| 185 | .ent sdram_init |
| 186 | sdram_init: |
Wolfgang Denk | f6a692b | 2005-12-04 00:40:34 +0100 | [diff] [blame] | 187 | __sdram_init: |
wdenk | 67f1336 | 2003-12-27 19:24:54 +0000 | [diff] [blame] | 188 | |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 189 | li t1, MC_MODUL_BASE |
wdenk | 67f1336 | 2003-12-27 19:24:54 +0000 | [diff] [blame] | 190 | |
wdenk | 4dd56e5 | 2004-02-20 22:02:48 +0000 | [diff] [blame] | 191 | #if 0 |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 192 | /* Disable memory controller before changing any of its registers */ |
| 193 | sw zero, MC_CTRLENA(t1) |
wdenk | 4dd56e5 | 2004-02-20 22:02:48 +0000 | [diff] [blame] | 194 | #endif |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 195 | |
| 196 | li t2, 100000000 |
| 197 | beq a0, t2, 1f |
wdenk | 67f1336 | 2003-12-27 19:24:54 +0000 | [diff] [blame] | 198 | nop |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 199 | li t2, 133000000 |
| 200 | beq a0, t2, 2f |
wdenk | 67f1336 | 2003-12-27 19:24:54 +0000 | [diff] [blame] | 201 | nop |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 202 | li t2, 150000000 |
| 203 | beq a0, t2, 3f |
| 204 | nop |
| 205 | b 5f |
| 206 | nop |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 207 | |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 208 | /* 100 MHz clock */ |
| 209 | 1: |
| 210 | /* Set clock ratio (clkrat=1:1, rddel=3) */ |
| 211 | li t2, 0x00000003 |
| 212 | sw t2, MC_IOGP(t1) |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 213 | |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 214 | /* Set sdram refresh rate (4K/64ms @ 100MHz) */ |
| 215 | li t2, 0x0000061A |
| 216 | b 4f |
| 217 | sw t2, MC_TREFRESH(t1) |
| 218 | |
| 219 | /* 133 MHz clock */ |
| 220 | 2: |
| 221 | /* Set clock ratio (clkrat=1:1, rddel=3) */ |
| 222 | li t2, 0x00000003 |
| 223 | sw t2, MC_IOGP(t1) |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 224 | |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 225 | /* Set sdram refresh rate (4K/64ms @ 133MHz) */ |
| 226 | li t2, 0x00000822 |
| 227 | b 4f |
| 228 | sw t2, MC_TREFRESH(t1) |
| 229 | |
| 230 | /* 150 MHz clock */ |
| 231 | 3: |
| 232 | /* Set clock ratio (clkrat=3:2, rddel=4) */ |
| 233 | li t2, 0x00000014 |
| 234 | sw t2, MC_IOGP(t1) |
| 235 | |
| 236 | /* Set sdram refresh rate (4K/64ms @ 150MHz) */ |
| 237 | li t2, 0x00000927 |
| 238 | sw t2, MC_TREFRESH(t1) |
| 239 | |
| 240 | 4: |
| 241 | /* Clear Error log registers */ |
| 242 | sw zero, MC_ERRCAUSE(t1) |
| 243 | sw zero, MC_ERRADDR(t1) |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 244 | |
| 245 | /* Clear Power-down registers */ |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 246 | sw zero, MC_SELFRFSH(t1) |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 247 | |
| 248 | /* Set CAS Latency */ |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 249 | li t2, 0x00000020 /* CL = 2 */ |
| 250 | sw t2, MC_MRSCODE(t1) |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 251 | |
| 252 | /* Set word width to 16 bit */ |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 253 | li t2, 0x2 |
| 254 | sw t2, MC_CFGDW(t1) |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 255 | |
| 256 | /* Set CS0 to SDRAM parameters */ |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 257 | li t2, 0x000014C9 |
| 258 | sw t2, MC_CFGPB0(t1) |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 259 | |
| 260 | /* Set SDRAM latency parameters */ |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 261 | li t2, 0x00026325 /* BC PC100 */ |
| 262 | sw t2, MC_LATENCY(t1) |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 263 | |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 264 | 5: |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 265 | /* Finally enable the controller */ |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 266 | li t2, 0x00000001 |
| 267 | sw t2, MC_CTRLENA(t1) |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 268 | |
| 269 | j ra |
| 270 | nop |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 271 | |
| 272 | .end sdram_init |
| 273 | |
| 274 | |
wdenk | 336b2bc | 2005-04-02 23:52:25 +0000 | [diff] [blame] | 275 | .globl lowlevel_init |
| 276 | .ent lowlevel_init |
| 277 | lowlevel_init: |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 278 | |
Shinya Kuribayashi | b5876f6 | 2008-03-25 21:30:07 +0900 | [diff] [blame^] | 279 | /* Disable Watchdog. |
| 280 | */ |
| 281 | la t9, disable_incaip_wdt |
| 282 | jalr t9 |
| 283 | nop |
| 284 | |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 285 | /* EBU, CGU and SDRAM Initialization. |
| 286 | */ |
| 287 | li a0, CPU_CLOCK_RATE |
| 288 | move t0, ra |
| 289 | |
| 290 | /* We rely on the fact that neither ebu_init() nor cgu_init() nor sdram_init() |
| 291 | * modify t0 and a0. |
| 292 | */ |
Wolfgang Denk | f6a692b | 2005-12-04 00:40:34 +0100 | [diff] [blame] | 293 | bal __cgu_init |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 294 | nop |
Wolfgang Denk | f6a692b | 2005-12-04 00:40:34 +0100 | [diff] [blame] | 295 | bal __ebu_init |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 296 | nop |
Wolfgang Denk | f6a692b | 2005-12-04 00:40:34 +0100 | [diff] [blame] | 297 | bal __sdram_init |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 298 | nop |
| 299 | move ra, t0 |
| 300 | |
| 301 | j ra |
| 302 | nop |
| 303 | |
wdenk | 336b2bc | 2005-04-02 23:52:25 +0000 | [diff] [blame] | 304 | .end lowlevel_init |