wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
Stefan Roese | 8d98230 | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 2 | * (C) Copyright 2005-2007 |
Stefan Roese | c443fe9 | 2005-11-22 13:20:42 +0100 | [diff] [blame] | 3 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
| 4 | * |
Stefan Roese | fd63793 | 2006-03-17 10:28:24 +0100 | [diff] [blame] | 5 | * (C) Copyright 2006 |
| 6 | * DAVE Srl <www.dave-tech.it> |
| 7 | * |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 8 | * (C) Copyright 2002-2004 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 9 | * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com |
| 10 | * |
| 11 | * See file CREDITS for list of people who contributed to this |
| 12 | * project. |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU General Public License as |
| 16 | * published by the Free Software Foundation; either version 2 of |
| 17 | * the License, or (at your option) any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, write to the Free Software |
| 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 27 | * MA 02111-1307 USA |
| 28 | */ |
| 29 | |
| 30 | #include <common.h> |
| 31 | #include <ppc4xx.h> |
| 32 | #include <asm/processor.h> |
Stefan Roese | fd63793 | 2006-03-17 10:28:24 +0100 | [diff] [blame] | 33 | #include "sdram.h" |
Grant Erickson | b693341 | 2008-05-22 14:44:14 -0700 | [diff] [blame] | 34 | #include "ecc.h" |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 35 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 36 | #ifdef CONFIG_SDRAM_BANK0 |
| 37 | |
Stefan Roese | 8d98230 | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 38 | #ifndef CONFIG_440 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 39 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 40 | #ifndef CONFIG_SYS_SDRAM_TABLE |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 41 | sdram_conf_t mb0cf[] = { |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 42 | {(128 << 20), 13, 0x000A4001}, /* (0-128MB) Address Mode 3, 13x10(4) */ |
| 43 | {(64 << 20), 13, 0x00084001}, /* (0-64MB) Address Mode 3, 13x9(4) */ |
| 44 | {(32 << 20), 12, 0x00062001}, /* (0-32MB) Address Mode 2, 12x9(4) */ |
| 45 | {(16 << 20), 12, 0x00046001}, /* (0-16MB) Address Mode 4, 12x8(4) */ |
| 46 | {(4 << 20), 11, 0x00008001}, /* (0-4MB) Address Mode 5, 11x8(2) */ |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 47 | }; |
Stefan Roese | c443fe9 | 2005-11-22 13:20:42 +0100 | [diff] [blame] | 48 | #else |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 49 | sdram_conf_t mb0cf[] = CONFIG_SYS_SDRAM_TABLE; |
Stefan Roese | c443fe9 | 2005-11-22 13:20:42 +0100 | [diff] [blame] | 50 | #endif |
| 51 | |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 52 | #define N_MB0CF (sizeof(mb0cf) / sizeof(mb0cf[0])) |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 53 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 54 | #ifdef CONFIG_SYS_SDRAM_CASL |
Stefan Roese | fd63793 | 2006-03-17 10:28:24 +0100 | [diff] [blame] | 55 | static ulong ns2clks(ulong ns) |
| 56 | { |
| 57 | ulong bus_period_x_10 = ONE_BILLION / (get_bus_freq(0) / 10); |
| 58 | |
| 59 | return ((ns * 10) + bus_period_x_10) / bus_period_x_10; |
| 60 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 61 | #endif /* CONFIG_SYS_SDRAM_CASL */ |
Stefan Roese | fd63793 | 2006-03-17 10:28:24 +0100 | [diff] [blame] | 62 | |
| 63 | static ulong compute_sdtr1(ulong speed) |
| 64 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 65 | #ifdef CONFIG_SYS_SDRAM_CASL |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 66 | ulong tmp; |
| 67 | ulong sdtr1 = 0; |
Stefan Roese | fd63793 | 2006-03-17 10:28:24 +0100 | [diff] [blame] | 68 | |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 69 | /* CASL */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 70 | if (CONFIG_SYS_SDRAM_CASL < 2) |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 71 | sdtr1 |= (1 << SDRAM0_TR_CASL); |
| 72 | else |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 73 | if (CONFIG_SYS_SDRAM_CASL > 4) |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 74 | sdtr1 |= (3 << SDRAM0_TR_CASL); |
| 75 | else |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 76 | sdtr1 |= ((CONFIG_SYS_SDRAM_CASL-1) << SDRAM0_TR_CASL); |
Stefan Roese | fd63793 | 2006-03-17 10:28:24 +0100 | [diff] [blame] | 77 | |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 78 | /* PTA */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 79 | tmp = ns2clks(CONFIG_SYS_SDRAM_PTA); |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 80 | if ((tmp >= 2) && (tmp <= 4)) |
| 81 | sdtr1 |= ((tmp-1) << SDRAM0_TR_PTA); |
| 82 | else |
| 83 | sdtr1 |= ((4-1) << SDRAM0_TR_PTA); |
Stefan Roese | fd63793 | 2006-03-17 10:28:24 +0100 | [diff] [blame] | 84 | |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 85 | /* CTP */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 86 | tmp = ns2clks(CONFIG_SYS_SDRAM_CTP); |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 87 | if ((tmp >= 2) && (tmp <= 4)) |
| 88 | sdtr1 |= ((tmp-1) << SDRAM0_TR_CTP); |
| 89 | else |
| 90 | sdtr1 |= ((4-1) << SDRAM0_TR_CTP); |
Stefan Roese | fd63793 | 2006-03-17 10:28:24 +0100 | [diff] [blame] | 91 | |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 92 | /* LDF */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 93 | tmp = ns2clks(CONFIG_SYS_SDRAM_LDF); |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 94 | if ((tmp >= 2) && (tmp <= 4)) |
| 95 | sdtr1 |= ((tmp-1) << SDRAM0_TR_LDF); |
| 96 | else |
| 97 | sdtr1 |= ((2-1) << SDRAM0_TR_LDF); |
Stefan Roese | fd63793 | 2006-03-17 10:28:24 +0100 | [diff] [blame] | 98 | |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 99 | /* RFTA */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 100 | tmp = ns2clks(CONFIG_SYS_SDRAM_RFTA); |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 101 | if ((tmp >= 4) && (tmp <= 10)) |
| 102 | sdtr1 |= ((tmp-4) << SDRAM0_TR_RFTA); |
| 103 | else |
| 104 | sdtr1 |= ((10-4) << SDRAM0_TR_RFTA); |
Stefan Roese | fd63793 | 2006-03-17 10:28:24 +0100 | [diff] [blame] | 105 | |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 106 | /* RCD */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 107 | tmp = ns2clks(CONFIG_SYS_SDRAM_RCD); |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 108 | if ((tmp >= 2) && (tmp <= 4)) |
| 109 | sdtr1 |= ((tmp-1) << SDRAM0_TR_RCD); |
| 110 | else |
| 111 | sdtr1 |= ((4-1) << SDRAM0_TR_RCD); |
Stefan Roese | fd63793 | 2006-03-17 10:28:24 +0100 | [diff] [blame] | 112 | |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 113 | return sdtr1; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 114 | #else /* CONFIG_SYS_SDRAM_CASL */ |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 115 | /* |
| 116 | * If no values are configured in the board config file |
| 117 | * use the default values, which seem to be ok for most |
| 118 | * boards. |
| 119 | * |
| 120 | * REMARK: |
| 121 | * For new board ports we strongly recommend to define the |
| 122 | * correct values for the used SDRAM chips in your board |
| 123 | * config file (see PPChameleonEVB.h) |
| 124 | */ |
| 125 | if (speed > 100000000) { |
| 126 | /* |
| 127 | * 133 MHz SDRAM |
| 128 | */ |
| 129 | return 0x01074015; |
| 130 | } else { |
| 131 | /* |
| 132 | * default: 100 MHz SDRAM |
| 133 | */ |
| 134 | return 0x0086400d; |
| 135 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 136 | #endif /* CONFIG_SYS_SDRAM_CASL */ |
Stefan Roese | fd63793 | 2006-03-17 10:28:24 +0100 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /* refresh is expressed in ms */ |
| 140 | static ulong compute_rtr(ulong speed, ulong rows, ulong refresh) |
| 141 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 142 | #ifdef CONFIG_SYS_SDRAM_CASL |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 143 | ulong tmp; |
Stefan Roese | fd63793 | 2006-03-17 10:28:24 +0100 | [diff] [blame] | 144 | |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 145 | tmp = ((refresh*1000*1000) / (1 << rows)) * (speed / 1000); |
| 146 | tmp /= 1000000; |
Stefan Roese | fd63793 | 2006-03-17 10:28:24 +0100 | [diff] [blame] | 147 | |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 148 | return ((tmp & 0x00003FF8) << 16); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 149 | #else /* CONFIG_SYS_SDRAM_CASL */ |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 150 | if (speed > 100000000) { |
| 151 | /* |
| 152 | * 133 MHz SDRAM |
| 153 | */ |
Stefan Roese | fd63793 | 2006-03-17 10:28:24 +0100 | [diff] [blame] | 154 | return 0x07f00000; |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 155 | } else { |
| 156 | /* |
| 157 | * default: 100 MHz SDRAM |
| 158 | */ |
Stefan Roese | fd63793 | 2006-03-17 10:28:24 +0100 | [diff] [blame] | 159 | return 0x05f00000; |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 160 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 161 | #endif /* CONFIG_SYS_SDRAM_CASL */ |
Stefan Roese | fd63793 | 2006-03-17 10:28:24 +0100 | [diff] [blame] | 162 | } |
| 163 | |
Stefan Roese | c443fe9 | 2005-11-22 13:20:42 +0100 | [diff] [blame] | 164 | /* |
| 165 | * Autodetect onboard SDRAM on 405 platforms |
| 166 | */ |
Becky Bruce | bd99ae7 | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 167 | phys_size_t initdram(int board_type) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 168 | { |
Stefan Roese | fd63793 | 2006-03-17 10:28:24 +0100 | [diff] [blame] | 169 | ulong speed; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 170 | ulong sdtr1; |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 171 | int i; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 172 | |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 173 | /* |
| 174 | * Determine SDRAM speed |
| 175 | */ |
| 176 | speed = get_bus_freq(0); /* parameter not used on ppc4xx */ |
Stefan Roese | fd63793 | 2006-03-17 10:28:24 +0100 | [diff] [blame] | 177 | |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 178 | /* |
| 179 | * sdtr1 (register SDRAM0_TR) must take into account timings listed |
| 180 | * in SDRAM chip datasheet. rtr (register SDRAM0_RTR) must take into |
| 181 | * account actual SDRAM size. So we can set up sdtr1 according to what |
| 182 | * is specified in board configuration file while rtr dependds on SDRAM |
| 183 | * size we are assuming before detection. |
| 184 | */ |
| 185 | sdtr1 = compute_sdtr1(speed); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 186 | |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 187 | for (i=0; i<N_MB0CF; i++) { |
stroese | 51c57b9 | 2003-02-10 16:26:37 +0000 | [diff] [blame] | 188 | /* |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 189 | * Disable memory controller. |
stroese | 51c57b9 | 2003-02-10 16:26:37 +0000 | [diff] [blame] | 190 | */ |
Stefan Roese | a5d182e | 2007-08-14 14:44:41 +0200 | [diff] [blame] | 191 | mtsdram(mem_mcopt1, 0x00000000); |
wdenk | 41e2e05 | 2003-02-11 01:49:43 +0000 | [diff] [blame] | 192 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 193 | /* |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 194 | * Set MB0CF for bank 0. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 195 | */ |
Stefan Roese | a5d182e | 2007-08-14 14:44:41 +0200 | [diff] [blame] | 196 | mtsdram(mem_mb0cf, mb0cf[i].reg); |
| 197 | mtsdram(mem_sdtr1, sdtr1); |
| 198 | mtsdram(mem_rtr, compute_rtr(speed, mb0cf[i].rows, 64)); |
wdenk | 41e2e05 | 2003-02-11 01:49:43 +0000 | [diff] [blame] | 199 | |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 200 | udelay(200); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 201 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 202 | /* |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 203 | * Set memory controller options reg, MCOPT1. |
| 204 | * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst |
| 205 | * read/prefetch. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 206 | */ |
Stefan Roese | a5d182e | 2007-08-14 14:44:41 +0200 | [diff] [blame] | 207 | mtsdram(mem_mcopt1, 0x80800000); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 208 | |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 209 | udelay(10000); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 210 | |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 211 | if (get_ram_size(0, mb0cf[i].size) == mb0cf[i].size) { |
Stefan Roese | 58296a1 | 2008-09-10 16:53:47 +0200 | [diff] [blame] | 212 | phys_size_t size = mb0cf[i].size; |
| 213 | |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 214 | /* |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 215 | * OK, size detected. Enable second bank if |
| 216 | * defined (assumes same type as bank 0) |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 217 | */ |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 218 | #ifdef CONFIG_SDRAM_BANK1 |
Stefan Roese | a5d182e | 2007-08-14 14:44:41 +0200 | [diff] [blame] | 219 | mtsdram(mem_mcopt1, 0x00000000); |
Stefan Roese | 58296a1 | 2008-09-10 16:53:47 +0200 | [diff] [blame] | 220 | mtsdram(mem_mb1cf, mb0cf[i].size | mb0cf[i].reg); |
Stefan Roese | a5d182e | 2007-08-14 14:44:41 +0200 | [diff] [blame] | 221 | mtsdram(mem_mcopt1, 0x80800000); |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 222 | udelay(10000); |
Stefan Roese | a5d182e | 2007-08-14 14:44:41 +0200 | [diff] [blame] | 223 | |
| 224 | /* |
| 225 | * Check if 2nd bank is really available. |
| 226 | * If the size not equal to the size of the first |
| 227 | * bank, then disable the 2nd bank completely. |
| 228 | */ |
| 229 | if (get_ram_size((long *)mb0cf[i].size, mb0cf[i].size) != |
| 230 | mb0cf[i].size) { |
| 231 | mtsdram(mem_mb1cf, 0); |
| 232 | mtsdram(mem_mcopt1, 0); |
Stefan Roese | 58296a1 | 2008-09-10 16:53:47 +0200 | [diff] [blame] | 233 | } else { |
| 234 | /* |
| 235 | * We have two identical banks, so the size |
| 236 | * is twice the bank size |
| 237 | */ |
| 238 | size = 2 * size; |
Stefan Roese | a5d182e | 2007-08-14 14:44:41 +0200 | [diff] [blame] | 239 | } |
John Otken | 9aa3677 | 2007-07-26 17:49:11 +0200 | [diff] [blame] | 240 | #endif |
Stefan Roese | cdb0470 | 2008-06-02 17:37:28 +0200 | [diff] [blame] | 241 | |
| 242 | /* |
| 243 | * OK, size detected -> all done |
| 244 | */ |
Stefan Roese | 58296a1 | 2008-09-10 16:53:47 +0200 | [diff] [blame] | 245 | return size; |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 246 | } |
stroese | 51c57b9 | 2003-02-10 16:26:37 +0000 | [diff] [blame] | 247 | } |
Stefan Roese | cdb0470 | 2008-06-02 17:37:28 +0200 | [diff] [blame] | 248 | |
| 249 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 250 | } |
| 251 | |
Stefan Roese | c443fe9 | 2005-11-22 13:20:42 +0100 | [diff] [blame] | 252 | #else /* CONFIG_440 */ |
| 253 | |
Stefan Roese | 8d98230 | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 254 | /* |
| 255 | * Define some default values. Those can be overwritten in the |
| 256 | * board config file. |
| 257 | */ |
| 258 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 259 | #ifndef CONFIG_SYS_SDRAM_TABLE |
Stefan Roese | 8d98230 | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 260 | sdram_conf_t mb0cf[] = { |
| 261 | {(256 << 20), 13, 0x000C4001}, /* 256MB mode 3, 13x10(4) */ |
| 262 | {(64 << 20), 12, 0x00082001} /* 64MB mode 2, 12x9(4) */ |
| 263 | }; |
| 264 | #else |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 265 | sdram_conf_t mb0cf[] = CONFIG_SYS_SDRAM_TABLE; |
Stefan Roese | 8d98230 | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 266 | #endif |
| 267 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 268 | #ifndef CONFIG_SYS_SDRAM0_TR0 |
| 269 | #define CONFIG_SYS_SDRAM0_TR0 0x41094012 |
Stefan Roese | 8d98230 | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 270 | #endif |
| 271 | |
| 272 | #define N_MB0CF (sizeof(mb0cf) / sizeof(mb0cf[0])) |
| 273 | |
Stefan Roese | fd63793 | 2006-03-17 10:28:24 +0100 | [diff] [blame] | 274 | #define NUM_TRIES 64 |
| 275 | #define NUM_READS 10 |
| 276 | |
| 277 | static void sdram_tr1_set(int ram_address, int* tr1_value) |
| 278 | { |
| 279 | int i; |
| 280 | int j, k; |
| 281 | volatile unsigned int* ram_pointer = (unsigned int *)ram_address; |
| 282 | int first_good = -1, last_bad = 0x1ff; |
| 283 | |
| 284 | unsigned long test[NUM_TRIES] = { |
| 285 | 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, |
| 286 | 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, |
| 287 | 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, |
| 288 | 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, |
| 289 | 0xAAAAAAAA, 0xAAAAAAAA, 0x55555555, 0x55555555, |
| 290 | 0xAAAAAAAA, 0xAAAAAAAA, 0x55555555, 0x55555555, |
| 291 | 0x55555555, 0x55555555, 0xAAAAAAAA, 0xAAAAAAAA, |
| 292 | 0x55555555, 0x55555555, 0xAAAAAAAA, 0xAAAAAAAA, |
| 293 | 0xA5A5A5A5, 0xA5A5A5A5, 0x5A5A5A5A, 0x5A5A5A5A, |
| 294 | 0xA5A5A5A5, 0xA5A5A5A5, 0x5A5A5A5A, 0x5A5A5A5A, |
| 295 | 0x5A5A5A5A, 0x5A5A5A5A, 0xA5A5A5A5, 0xA5A5A5A5, |
| 296 | 0x5A5A5A5A, 0x5A5A5A5A, 0xA5A5A5A5, 0xA5A5A5A5, |
| 297 | 0xAA55AA55, 0xAA55AA55, 0x55AA55AA, 0x55AA55AA, |
| 298 | 0xAA55AA55, 0xAA55AA55, 0x55AA55AA, 0x55AA55AA, |
| 299 | 0x55AA55AA, 0x55AA55AA, 0xAA55AA55, 0xAA55AA55, |
| 300 | 0x55AA55AA, 0x55AA55AA, 0xAA55AA55, 0xAA55AA55 }; |
| 301 | |
| 302 | /* go through all possible SDRAM0_TR1[RDCT] values */ |
| 303 | for (i=0; i<=0x1ff; i++) { |
| 304 | /* set the current value for TR1 */ |
| 305 | mtsdram(mem_tr1, (0x80800800 | i)); |
| 306 | |
| 307 | /* write values */ |
| 308 | for (j=0; j<NUM_TRIES; j++) { |
| 309 | ram_pointer[j] = test[j]; |
| 310 | |
| 311 | /* clear any cache at ram location */ |
| 312 | __asm__("dcbf 0,%0": :"r" (&ram_pointer[j])); |
| 313 | } |
| 314 | |
| 315 | /* read values back */ |
| 316 | for (j=0; j<NUM_TRIES; j++) { |
| 317 | for (k=0; k<NUM_READS; k++) { |
| 318 | /* clear any cache at ram location */ |
| 319 | __asm__("dcbf 0,%0": :"r" (&ram_pointer[j])); |
| 320 | |
| 321 | if (ram_pointer[j] != test[j]) |
| 322 | break; |
| 323 | } |
| 324 | |
| 325 | /* read error */ |
| 326 | if (k != NUM_READS) |
| 327 | break; |
| 328 | } |
| 329 | |
| 330 | /* we have a SDRAM0_TR1[RDCT] that is part of the window */ |
| 331 | if (j == NUM_TRIES) { |
| 332 | if (first_good == -1) |
| 333 | first_good = i; /* found beginning of window */ |
| 334 | } else { /* bad read */ |
| 335 | /* if we have not had a good read then don't care */ |
| 336 | if (first_good != -1) { |
| 337 | /* first failure after a good read */ |
| 338 | last_bad = i-1; |
| 339 | break; |
| 340 | } |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | /* return the current value for TR1 */ |
| 345 | *tr1_value = (first_good + last_bad) / 2; |
| 346 | } |
| 347 | |
Stefan Roese | c443fe9 | 2005-11-22 13:20:42 +0100 | [diff] [blame] | 348 | /* |
| 349 | * Autodetect onboard DDR SDRAM on 440 platforms |
| 350 | * |
| 351 | * NOTE: Some of the hardcoded values are hardware dependant, |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 352 | * so this should be extended for other future boards |
| 353 | * using this routine! |
Stefan Roese | c443fe9 | 2005-11-22 13:20:42 +0100 | [diff] [blame] | 354 | */ |
Becky Bruce | bd99ae7 | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 355 | phys_size_t initdram(int board_type) |
Stefan Roese | c443fe9 | 2005-11-22 13:20:42 +0100 | [diff] [blame] | 356 | { |
| 357 | int i; |
Stefan Roese | fd63793 | 2006-03-17 10:28:24 +0100 | [diff] [blame] | 358 | int tr1_bank1; |
Stefan Roese | c443fe9 | 2005-11-22 13:20:42 +0100 | [diff] [blame] | 359 | |
Stefan Roese | 8d98230 | 2007-01-18 10:25:34 +0100 | [diff] [blame] | 360 | #if defined(CONFIG_440GX) || defined(CONFIG_440EP) || \ |
| 361 | defined(CONFIG_440GR) || defined(CONFIG_440SP) |
Stefan Roese | 4963968 | 2006-08-15 14:22:35 +0200 | [diff] [blame] | 362 | /* |
| 363 | * Soft-reset SDRAM controller. |
| 364 | */ |
| 365 | mtsdr(sdr_srst, SDR0_SRST_DMC); |
| 366 | mtsdr(sdr_srst, 0x00000000); |
| 367 | #endif |
| 368 | |
Stefan Roese | c443fe9 | 2005-11-22 13:20:42 +0100 | [diff] [blame] | 369 | for (i=0; i<N_MB0CF; i++) { |
| 370 | /* |
| 371 | * Disable memory controller. |
| 372 | */ |
| 373 | mtsdram(mem_cfg0, 0x00000000); |
| 374 | |
| 375 | /* |
| 376 | * Setup some default |
| 377 | */ |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 378 | mtsdram(mem_uabba, 0x00000000); /* ubba=0 (default) */ |
| 379 | mtsdram(mem_slio, 0x00000000); /* rdre=0 wrre=0 rarw=0 */ |
Stefan Roese | c443fe9 | 2005-11-22 13:20:42 +0100 | [diff] [blame] | 380 | mtsdram(mem_devopt, 0x00000000); /* dll=0 ds=0 (normal) */ |
| 381 | mtsdram(mem_wddctr, 0x00000000); /* wrcp=0 dcd=0 */ |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 382 | mtsdram(mem_clktr, 0x40000000); /* clkp=1 (90 deg wr) dcdt=0 */ |
Stefan Roese | c443fe9 | 2005-11-22 13:20:42 +0100 | [diff] [blame] | 383 | |
| 384 | /* |
| 385 | * Following for CAS Latency = 2.5 @ 133 MHz PLB |
| 386 | */ |
| 387 | mtsdram(mem_b0cr, mb0cf[i].reg); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 388 | mtsdram(mem_tr0, CONFIG_SYS_SDRAM0_TR0); |
Stefan Roese | c443fe9 | 2005-11-22 13:20:42 +0100 | [diff] [blame] | 389 | mtsdram(mem_tr1, 0x80800800); /* SS=T2 SL=STAGE 3 CD=1 CT=0x00*/ |
Stefan Roese | 76e3d2a | 2007-01-06 15:58:09 +0100 | [diff] [blame] | 390 | mtsdram(mem_rtr, 0x04100000); /* Interval 7.8µs @ 133MHz PLB */ |
Stefan Roese | c443fe9 | 2005-11-22 13:20:42 +0100 | [diff] [blame] | 391 | mtsdram(mem_cfg1, 0x00000000); /* Self-refresh exit, disable PM*/ |
| 392 | udelay(400); /* Delay 200 usecs (min) */ |
| 393 | |
| 394 | /* |
| 395 | * Enable the controller, then wait for DCEN to complete |
| 396 | */ |
Stefan Roese | e335ee0 | 2006-07-28 18:34:58 +0200 | [diff] [blame] | 397 | mtsdram(mem_cfg0, 0x82000000); /* DCEN=1, PMUD=0, 64-bit */ |
Stefan Roese | c443fe9 | 2005-11-22 13:20:42 +0100 | [diff] [blame] | 398 | udelay(10000); |
| 399 | |
| 400 | if (get_ram_size(0, mb0cf[i].size) == mb0cf[i].size) { |
| 401 | /* |
Stefan Roese | fd63793 | 2006-03-17 10:28:24 +0100 | [diff] [blame] | 402 | * Optimize TR1 to current hardware environment |
| 403 | */ |
| 404 | sdram_tr1_set(0x00000000, &tr1_bank1); |
| 405 | mtsdram(mem_tr1, (tr1_bank1 | 0x80800800)); |
| 406 | |
| 407 | #ifdef CONFIG_SDRAM_ECC |
| 408 | ecc_init(0, mb0cf[i].size); |
| 409 | #endif |
| 410 | |
| 411 | /* |
Stefan Roese | c443fe9 | 2005-11-22 13:20:42 +0100 | [diff] [blame] | 412 | * OK, size detected -> all done |
| 413 | */ |
| 414 | return mb0cf[i].size; |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | return 0; /* nothing found ! */ |
| 419 | } |
| 420 | |
| 421 | #endif /* CONFIG_440 */ |
| 422 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 423 | #endif /* CONFIG_SDRAM_BANK0 */ |