wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
Stefan Roese | c443fe9 | 2005-11-22 13:20:42 +0100 | [diff] [blame] | 2 | * (C) Copyright 2005 |
| 3 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
| 4 | * |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 5 | * (C) Copyright 2002-2004 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 6 | * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com |
| 7 | * |
| 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | #include <common.h> |
| 28 | #include <ppc4xx.h> |
| 29 | #include <asm/processor.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 30 | |
| 31 | |
| 32 | #ifdef CONFIG_SDRAM_BANK0 |
| 33 | |
| 34 | |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 35 | #define mtsdram0(reg, data) mtdcr(memcfga,reg);mtdcr(memcfgd,data) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 36 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 37 | |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 38 | struct sdram_conf_s { |
| 39 | unsigned long size; |
| 40 | unsigned long reg; |
| 41 | }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 42 | |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 43 | typedef struct sdram_conf_s sdram_conf_t; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 44 | |
Stefan Roese | c443fe9 | 2005-11-22 13:20:42 +0100 | [diff] [blame] | 45 | #ifndef CFG_SDRAM_TABLE |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 46 | sdram_conf_t mb0cf[] = { |
| 47 | {(128 << 20), 0x000A4001}, /* (0-128MB) Address Mode 3, 13x10(4) */ |
| 48 | {(64 << 20), 0x00084001}, /* (0-64MB) Address Mode 3, 13x9(4) */ |
| 49 | {(32 << 20), 0x00062001}, /* (0-32MB) Address Mode 2, 12x9(4) */ |
| 50 | {(16 << 20), 0x00046001}, /* (0-16MB) Address Mode 4, 12x8(4) */ |
| 51 | {(4 << 20), 0x00008001}, /* (0-4MB) Address Mode 5, 11x8(2) */ |
| 52 | }; |
Stefan Roese | c443fe9 | 2005-11-22 13:20:42 +0100 | [diff] [blame] | 53 | #else |
| 54 | sdram_conf_t mb0cf[] = CFG_SDRAM_TABLE; |
| 55 | #endif |
| 56 | |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 57 | #define N_MB0CF (sizeof(mb0cf) / sizeof(mb0cf[0])) |
| 58 | |
| 59 | |
Stefan Roese | c443fe9 | 2005-11-22 13:20:42 +0100 | [diff] [blame] | 60 | #ifndef CONFIG_440 |
| 61 | |
| 62 | /* |
| 63 | * Autodetect onboard SDRAM on 405 platforms |
| 64 | */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 65 | void sdram_init(void) |
| 66 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 67 | ulong sdtr1; |
| 68 | ulong rtr; |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 69 | int i; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 70 | |
| 71 | /* |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 72 | * Support for 100MHz and 133MHz SDRAM |
| 73 | */ |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 74 | if (get_bus_freq(0) > 100000000) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 75 | /* |
| 76 | * 133 MHz SDRAM |
| 77 | */ |
| 78 | sdtr1 = 0x01074015; |
| 79 | rtr = 0x07f00000; |
| 80 | } else { |
| 81 | /* |
| 82 | * default: 100 MHz SDRAM |
| 83 | */ |
| 84 | sdtr1 = 0x0086400d; |
| 85 | rtr = 0x05f00000; |
| 86 | } |
| 87 | |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 88 | for (i=0; i<N_MB0CF; i++) { |
stroese | 51c57b9 | 2003-02-10 16:26:37 +0000 | [diff] [blame] | 89 | /* |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 90 | * Disable memory controller. |
stroese | 51c57b9 | 2003-02-10 16:26:37 +0000 | [diff] [blame] | 91 | */ |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 92 | mtsdram0(mem_mcopt1, 0x00000000); |
wdenk | 41e2e05 | 2003-02-11 01:49:43 +0000 | [diff] [blame] | 93 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 94 | /* |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 95 | * Set MB0CF for bank 0. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 96 | */ |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 97 | mtsdram0(mem_mb0cf, mb0cf[i].reg); |
| 98 | mtsdram0(mem_sdtr1, sdtr1); |
| 99 | mtsdram0(mem_rtr, rtr); |
wdenk | 41e2e05 | 2003-02-11 01:49:43 +0000 | [diff] [blame] | 100 | |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 101 | udelay(200); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 102 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 103 | /* |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 104 | * Set memory controller options reg, MCOPT1. |
| 105 | * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst |
| 106 | * read/prefetch. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 107 | */ |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 108 | mtsdram0(mem_mcopt1, 0x80800000); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 109 | |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 110 | udelay(10000); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 111 | |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 112 | if (get_ram_size(0, mb0cf[i].size) == mb0cf[i].size) { |
| 113 | /* |
| 114 | * OK, size detected -> all done |
| 115 | */ |
| 116 | return; |
| 117 | } |
stroese | 51c57b9 | 2003-02-10 16:26:37 +0000 | [diff] [blame] | 118 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Stefan Roese | c443fe9 | 2005-11-22 13:20:42 +0100 | [diff] [blame] | 121 | #else /* CONFIG_440 */ |
| 122 | |
| 123 | /* |
| 124 | * Autodetect onboard DDR SDRAM on 440 platforms |
| 125 | * |
| 126 | * NOTE: Some of the hardcoded values are hardware dependant, |
| 127 | * so this should be extended for other future boards |
| 128 | * using this routine! |
| 129 | */ |
| 130 | long int initdram(int board_type) |
| 131 | { |
| 132 | int i; |
| 133 | |
| 134 | for (i=0; i<N_MB0CF; i++) { |
| 135 | /* |
| 136 | * Disable memory controller. |
| 137 | */ |
| 138 | mtsdram(mem_cfg0, 0x00000000); |
| 139 | |
| 140 | /* |
| 141 | * Setup some default |
| 142 | */ |
| 143 | mtsdram(mem_uabba, 0x00000000); /* ubba=0 (default) */ |
| 144 | mtsdram(mem_slio, 0x00000000); /* rdre=0 wrre=0 rarw=0 */ |
| 145 | mtsdram(mem_devopt, 0x00000000); /* dll=0 ds=0 (normal) */ |
| 146 | mtsdram(mem_wddctr, 0x00000000); /* wrcp=0 dcd=0 */ |
| 147 | mtsdram(mem_clktr, 0x40000000); /* clkp=1 (90 deg wr) dcdt=0 */ |
| 148 | |
| 149 | /* |
| 150 | * Following for CAS Latency = 2.5 @ 133 MHz PLB |
| 151 | */ |
| 152 | mtsdram(mem_b0cr, mb0cf[i].reg); |
| 153 | mtsdram(mem_tr0, 0x41094012); |
| 154 | mtsdram(mem_tr1, 0x80800800); /* SS=T2 SL=STAGE 3 CD=1 CT=0x00*/ |
| 155 | mtsdram(mem_rtr, 0x7e000000); /* Interval 15.20µs @ 133MHz PLB*/ |
| 156 | mtsdram(mem_cfg1, 0x00000000); /* Self-refresh exit, disable PM*/ |
| 157 | udelay(400); /* Delay 200 usecs (min) */ |
| 158 | |
| 159 | /* |
| 160 | * Enable the controller, then wait for DCEN to complete |
| 161 | */ |
| 162 | mtsdram(mem_cfg0, 0x86000000); /* DCEN=1, PMUD=1, 64-bit */ |
| 163 | udelay(10000); |
| 164 | |
| 165 | if (get_ram_size(0, mb0cf[i].size) == mb0cf[i].size) { |
| 166 | /* |
| 167 | * OK, size detected -> all done |
| 168 | */ |
| 169 | return mb0cf[i].size; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | return 0; /* nothing found ! */ |
| 174 | } |
| 175 | |
| 176 | #endif /* CONFIG_440 */ |
| 177 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 178 | #endif /* CONFIG_SDRAM_BANK0 */ |