Stefan Roese | 211ea91 | 2007-10-22 07:34:34 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 |
| 3 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <asm/processor.h> |
| 26 | |
| 27 | void sdram_init(void) |
| 28 | { |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | long int initdram(int board_type) |
| 33 | { |
| 34 | /* |
| 35 | * Same as on Kilauea, Makalu generates exception 0x200 |
| 36 | * (machine check) after trap_init() in board_init_f, |
| 37 | * when SDRAM is initialized here (late) and d-cache is |
| 38 | * used earlier as INIT_RAM. |
| 39 | * So for now, initialize DDR2 in init.S very early and |
| 40 | * also use it for INIT_RAM. Then this exception doesn't |
| 41 | * occur. |
| 42 | */ |
| 43 | #if 0 |
| 44 | u32 val; |
| 45 | |
| 46 | /* base=00000000, size=128MByte (5), mode=2 (n*10*4) */ |
| 47 | mtsdram(SDRAM_MB0CF, 0x00005201); |
| 48 | |
| 49 | /* SET SDRAM_MB1CF - Not enabled */ |
| 50 | mtsdram(SDRAM_MB1CF, 0x00000000); |
| 51 | |
| 52 | /* SET SDRAM_MB2CF - Not enabled */ |
| 53 | mtsdram(SDRAM_MB2CF, 0x00000000); |
| 54 | |
| 55 | /* SET SDRAM_MB3CF - Not enabled */ |
| 56 | mtsdram(SDRAM_MB3CF, 0x00000000); |
| 57 | |
| 58 | /* SDRAM_CLKTR: Adv Addr clock by 90 deg */ |
| 59 | mtsdram(SDRAM_CLKTR, 0x80000000); |
| 60 | |
| 61 | /* Refresh Time register (0x30) Refresh every 7.8125uS */ |
| 62 | mtsdram(SDRAM_RTR, 0x06180000); |
| 63 | |
| 64 | /* SDRAM_SDTR1 */ |
| 65 | mtsdram(SDRAM_SDTR1, 0x80201000); |
| 66 | |
| 67 | /* SDRAM_SDTR2 */ |
| 68 | mtsdram(SDRAM_SDTR2, 0x32204232); |
| 69 | |
| 70 | /* SDRAM_SDTR3 */ |
| 71 | mtsdram(SDRAM_SDTR3, 0x080b0d1a); |
| 72 | |
| 73 | mtsdram(SDRAM_MMODE, 0x00000442); |
| 74 | mtsdram(SDRAM_MEMODE, 0x00000404); |
| 75 | |
| 76 | /* SDRAM0_MCOPT1 (0X20) No ECC Gen */ |
| 77 | mtsdram(SDRAM_MCOPT1, 0x04322000); |
| 78 | |
| 79 | /* NOP */ |
| 80 | mtsdram(SDRAM_INITPLR0, 0xa8380000); |
| 81 | /* precharge 3 DDR clock cycle */ |
| 82 | mtsdram(SDRAM_INITPLR1, 0x81900400); |
| 83 | /* EMR2 twr = 2tck */ |
| 84 | mtsdram(SDRAM_INITPLR2, 0x81020000); |
| 85 | /* EMR3 twr = 2tck */ |
| 86 | mtsdram(SDRAM_INITPLR3, 0x81030000); |
| 87 | /* EMR DLL ENABLE twr = 2tck */ |
| 88 | mtsdram(SDRAM_INITPLR4, 0x81010404); |
| 89 | /* MR w/ DLL reset |
| 90 | * Note: 5 is CL. May need to be changed |
| 91 | */ |
| 92 | mtsdram(SDRAM_INITPLR5, 0x81000542); |
| 93 | /* precharge 3 DDR clock cycle */ |
| 94 | mtsdram(SDRAM_INITPLR6, 0x81900400); |
| 95 | /* Auto-refresh trfc = 26tck */ |
| 96 | mtsdram(SDRAM_INITPLR7, 0x8D080000); |
| 97 | /* Auto-refresh trfc = 26tck */ |
| 98 | mtsdram(SDRAM_INITPLR8, 0x8D080000); |
| 99 | /* Auto-refresh */ |
| 100 | mtsdram(SDRAM_INITPLR9, 0x8D080000); |
| 101 | /* Auto-refresh */ |
| 102 | mtsdram(SDRAM_INITPLR10, 0x8D080000); |
| 103 | /* MRS - normal operation; wait 2 cycle (set wait to tMRD) */ |
| 104 | mtsdram(SDRAM_INITPLR11, 0x81000442); |
| 105 | mtsdram(SDRAM_INITPLR12, 0x81010780); |
| 106 | mtsdram(SDRAM_INITPLR13, 0x81010400); |
| 107 | mtsdram(SDRAM_INITPLR14, 0x00000000); |
| 108 | mtsdram(SDRAM_INITPLR15, 0x00000000); |
| 109 | |
| 110 | /* SET MCIF0_CODT Die Termination On */ |
| 111 | mtsdram(SDRAM_CODT, 0x0080f837); |
| 112 | mtsdram(SDRAM_MODT0, 0x01800000); |
| 113 | mtsdram(SDRAM_MODT1, 0x00000000); |
| 114 | |
| 115 | mtsdram(SDRAM_WRDTR, 0x00000000); |
| 116 | |
| 117 | /* SDRAM0_MCOPT2 (0X21) Start initialization */ |
| 118 | mtsdram(SDRAM_MCOPT2, 0x20000000); |
| 119 | |
| 120 | /* Step 5 */ |
| 121 | do { |
| 122 | mfsdram(SDRAM_MCSTAT, val); |
| 123 | } while ((val & SDRAM_MCSTAT_MIC_COMP) != SDRAM_MCSTAT_MIC_COMP); |
| 124 | |
| 125 | /* Step 6 */ |
| 126 | |
| 127 | /* SDRAM_DLCR */ |
| 128 | mtsdram(SDRAM_DLCR, 0x030000a5); |
| 129 | |
| 130 | /* SDRAM_RDCC */ |
| 131 | mtsdram(SDRAM_RDCC, 0x40000000); |
| 132 | |
| 133 | /* SDRAM_RQDC */ |
| 134 | mtsdram(SDRAM_RQDC, 0x80000038); |
| 135 | |
| 136 | /* SDRAM_RFDC */ |
| 137 | mtsdram(SDRAM_RFDC, 0x00000209); |
| 138 | |
| 139 | /* Enable memory controller */ |
| 140 | mfsdram(SDRAM_MCOPT2, val); |
| 141 | val |= SDRAM_MCOPT2_DCEN_ENABLE; |
| 142 | mtsdram(SDRAM_MCOPT2, val); |
| 143 | #endif |
| 144 | return (CFG_MBYTES_SDRAM << 20); |
| 145 | } |
| 146 | |
| 147 | #if defined(CFG_DRAM_TEST) |
| 148 | int testdram (void) |
| 149 | { |
| 150 | printf ("testdram\n"); |
| 151 | #if defined (CONFIG_NAND_U_BOOT) |
| 152 | return 0; |
| 153 | #endif |
| 154 | uint *pstart = (uint *) 0x00000000; |
| 155 | uint *pend = (uint *) 0x00001000; |
| 156 | uint *p; |
| 157 | |
| 158 | for (p = pstart; p < pend; p++) { |
| 159 | *p = 0xaaaaaaaa; |
| 160 | } |
| 161 | |
| 162 | for (p = pstart; p < pend; p++) { |
| 163 | if (*p != 0xaaaaaaaa) { |
| 164 | #if !defined (CONFIG_NAND_SPL) |
| 165 | printf ("SDRAM test fails at: %08x\n", (uint) p); |
| 166 | #endif |
| 167 | return 1; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | for (p = pstart; p < pend; p++) { |
| 172 | *p = 0x55555555; |
| 173 | } |
| 174 | |
| 175 | for (p = pstart; p < pend; p++) { |
| 176 | if (*p != 0x55555555) { |
| 177 | #if !defined (CONFIG_NAND_SPL) |
| 178 | printf ("SDRAM test fails at: %08x\n", (uint) p); |
| 179 | #endif |
| 180 | return 1; |
| 181 | } |
| 182 | } |
| 183 | #if !defined (CONFIG_NAND_SPL) |
| 184 | printf ("SDRAM test passed!!!\n"); |
| 185 | #endif |
| 186 | return 0; |
| 187 | } |
| 188 | #endif |