Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 1 | /* |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 2 | * (C) Copyright 2006 Freescale Semiconductor, Inc. |
| 3 | * |
Rafal Jaworowski | 4a9b6aa | 2006-03-16 17:46:46 +0100 | [diff] [blame] | 4 | * (C) Copyright 2006 |
| 5 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 6 | * |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 7 | * Copyright (C) 2004-2006 Freescale Semiconductor, Inc. |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 8 | * (C) Copyright 2003 Motorola Inc. |
| 9 | * Xianghua Xiao (X.Xiao@motorola.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 |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 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 |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 28 | */ |
| 29 | |
| 30 | #include <common.h> |
| 31 | #include <asm/processor.h> |
| 32 | #include <i2c.h> |
| 33 | #include <spd.h> |
| 34 | #include <asm/mmu.h> |
| 35 | #include <spd_sdram.h> |
| 36 | |
| 37 | #ifdef CONFIG_SPD_EEPROM |
| 38 | |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 39 | DECLARE_GLOBAL_DATA_PTR; |
| 40 | |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 41 | #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 42 | extern void dma_init(void); |
| 43 | extern uint dma_check(void); |
| 44 | extern int dma_xfer(void *dest, uint count, void *src); |
| 45 | #endif |
| 46 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 47 | #ifndef CFG_READ_SPD |
| 48 | #define CFG_READ_SPD i2c_read |
| 49 | #endif |
| 50 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 51 | /* |
| 52 | * Convert picoseconds into clock cycles (rounding up if needed). |
| 53 | */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 54 | int |
| 55 | picos_to_clk(int picos) |
| 56 | { |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 57 | unsigned int ddr_bus_clk; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 58 | int clks; |
| 59 | |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 60 | ddr_bus_clk = gd->ddr_clk >> 1; |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 61 | clks = picos / ((1000000000 / ddr_bus_clk) * 1000); |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 62 | if (picos % ((1000000000 / ddr_bus_clk) * 1000) != 0) |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 63 | clks++; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 64 | |
| 65 | return clks; |
| 66 | } |
| 67 | |
Marian Balakowicz | 6f6104d | 2006-03-14 16:23:35 +0100 | [diff] [blame] | 68 | unsigned int banksize(unsigned char row_dens) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 69 | { |
| 70 | return ((row_dens >> 2) | ((row_dens & 3) << 6)) << 24; |
| 71 | } |
| 72 | |
Marian Balakowicz | 6f6104d | 2006-03-14 16:23:35 +0100 | [diff] [blame] | 73 | int read_spd(uint addr) |
| 74 | { |
| 75 | return ((int) addr); |
| 76 | } |
| 77 | |
Rafal Jaworowski | 4a9b6aa | 2006-03-16 17:46:46 +0100 | [diff] [blame] | 78 | #undef SPD_DEBUG |
| 79 | #ifdef SPD_DEBUG |
| 80 | static void spd_debug(spd_eeprom_t *spd) |
| 81 | { |
| 82 | printf ("\nDIMM type: %-18.18s\n", spd->mpart); |
| 83 | printf ("SPD size: %d\n", spd->info_size); |
| 84 | printf ("EEPROM size: %d\n", 1 << spd->chip_size); |
| 85 | printf ("Memory type: %d\n", spd->mem_type); |
| 86 | printf ("Row addr: %d\n", spd->nrow_addr); |
| 87 | printf ("Column addr: %d\n", spd->ncol_addr); |
| 88 | printf ("# of rows: %d\n", spd->nrows); |
| 89 | printf ("Row density: %d\n", spd->row_dens); |
| 90 | printf ("# of banks: %d\n", spd->nbanks); |
| 91 | printf ("Data width: %d\n", |
| 92 | 256 * spd->dataw_msb + spd->dataw_lsb); |
| 93 | printf ("Chip width: %d\n", spd->primw); |
| 94 | printf ("Refresh rate: %02X\n", spd->refresh); |
| 95 | printf ("CAS latencies: %02X\n", spd->cas_lat); |
| 96 | printf ("Write latencies: %02X\n", spd->write_lat); |
| 97 | printf ("tRP: %d\n", spd->trp); |
| 98 | printf ("tRCD: %d\n", spd->trcd); |
| 99 | printf ("\n"); |
| 100 | } |
| 101 | #endif /* SPD_DEBUG */ |
| 102 | |
| 103 | long int spd_sdram() |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 104 | { |
Timur Tabi | 386a280 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 105 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 106 | volatile ddr83xx_t *ddr = &immap->ddr; |
| 107 | volatile law83xx_t *ecm = &immap->sysconf.ddrlaw[0]; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 108 | spd_eeprom_t spd; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 109 | unsigned int memsize; |
| 110 | unsigned int law_size; |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 111 | unsigned char caslat, caslat_ctrl; |
| 112 | unsigned char burstlen; |
| 113 | unsigned int max_bus_clk; |
| 114 | unsigned int max_data_rate, effective_data_rate; |
| 115 | unsigned int ddrc_clk; |
| 116 | unsigned int refresh_clk; |
| 117 | unsigned sdram_cfg; |
| 118 | unsigned int ddrc_ecc_enable; |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 119 | |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 120 | /* Read SPD parameters with I2C */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 121 | CFG_READ_SPD(SPD_EEPROM_ADDRESS, 0, 1, (uchar *) & spd, sizeof (spd)); |
Rafal Jaworowski | 4a9b6aa | 2006-03-16 17:46:46 +0100 | [diff] [blame] | 122 | #ifdef SPD_DEBUG |
| 123 | spd_debug(&spd); |
| 124 | #endif |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 125 | /* Check the memory type */ |
| 126 | if (spd.mem_type != SPD_MEMTYPE_DDR) { |
| 127 | printf("DDR: Module mem type is %02X\n", spd.mem_type); |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | /* Check the number of physical bank */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 132 | if (spd.nrows > 2) { |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 133 | printf("DDR: The number of physical bank is %02X\n", spd.nrows); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 134 | return 0; |
| 135 | } |
| 136 | |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 137 | /* Check if the number of row of the module is in the range of DDRC */ |
| 138 | if (spd.nrow_addr < 12 || spd.nrow_addr > 14) { |
| 139 | printf("DDR: Row number is out of range of DDRC, row=%02X\n", |
| 140 | spd.nrow_addr); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 141 | return 0; |
| 142 | } |
| 143 | |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 144 | /* Check if the number of col of the module is in the range of DDRC */ |
| 145 | if (spd.ncol_addr < 8 || spd.ncol_addr > 11) { |
| 146 | printf("DDR: Col number is out of range of DDRC, col=%02X\n", |
| 147 | spd.ncol_addr); |
| 148 | return 0; |
| 149 | } |
| 150 | /* Setup DDR chip select register */ |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 151 | #ifdef CFG_83XX_DDR_USES_CS0 |
| 152 | ddr->csbnds[0].csbnds = (banksize(spd.row_dens) >> 24) - 1; |
| 153 | ddr->cs_config[0] = ( 1 << 31 |
| 154 | | (spd.nrow_addr - 12) << 8 |
| 155 | | (spd.ncol_addr - 8) ); |
| 156 | debug("\n"); |
| 157 | debug("cs0_bnds = 0x%08x\n",ddr->csbnds[0].csbnds); |
| 158 | debug("cs0_config = 0x%08x\n",ddr->cs_config[0]); |
| 159 | |
| 160 | if (spd.nrows == 2) { |
| 161 | ddr->csbnds[1].csbnds = ( (banksize(spd.row_dens) >> 8) |
| 162 | | ((banksize(spd.row_dens) >> 23) - 1) ); |
| 163 | ddr->cs_config[1] = ( 1<<31 |
| 164 | | (spd.nrow_addr-12) << 8 |
| 165 | | (spd.ncol_addr-8) ); |
| 166 | debug("cs1_bnds = 0x%08x\n",ddr->csbnds[1].csbnds); |
| 167 | debug("cs1_config = 0x%08x\n",ddr->cs_config[1]); |
| 168 | } |
| 169 | |
| 170 | #else |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 171 | ddr->csbnds[2].csbnds = (banksize(spd.row_dens) >> 24) - 1; |
| 172 | ddr->cs_config[2] = ( 1 << 31 |
| 173 | | (spd.nrow_addr - 12) << 8 |
| 174 | | (spd.ncol_addr - 8) ); |
| 175 | debug("\n"); |
| 176 | debug("cs2_bnds = 0x%08x\n",ddr->csbnds[2].csbnds); |
| 177 | debug("cs2_config = 0x%08x\n",ddr->cs_config[2]); |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 178 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 179 | if (spd.nrows == 2) { |
| 180 | ddr->csbnds[3].csbnds = ( (banksize(spd.row_dens) >> 8) |
| 181 | | ((banksize(spd.row_dens) >> 23) - 1) ); |
| 182 | ddr->cs_config[3] = ( 1<<31 |
| 183 | | (spd.nrow_addr-12) << 8 |
| 184 | | (spd.ncol_addr-8) ); |
| 185 | debug("cs3_bnds = 0x%08x\n",ddr->csbnds[3].csbnds); |
| 186 | debug("cs3_config = 0x%08x\n",ddr->cs_config[3]); |
| 187 | } |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 188 | #endif |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 189 | |
| 190 | if (spd.mem_type != 0x07) { |
| 191 | puts("No DDR module found!\n"); |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | /* |
| 196 | * Figure out memory size in Megabytes. |
| 197 | */ |
| 198 | memsize = spd.nrows * banksize(spd.row_dens) / 0x100000; |
| 199 | |
| 200 | /* |
| 201 | * First supported LAW size is 16M, at LAWAR_SIZE_16M == 23. |
| 202 | */ |
| 203 | law_size = 19 + __ilog2(memsize); |
| 204 | |
| 205 | /* |
| 206 | * Set up LAWBAR for all of DDR. |
| 207 | */ |
| 208 | ecm->bar = ((CFG_DDR_SDRAM_BASE>>12) & 0xfffff); |
| 209 | ecm->ar = (LAWAR_EN | LAWAR_TRGT_IF_DDR | (LAWAR_SIZE & law_size)); |
| 210 | debug("DDR:bar=0x%08x\n", ecm->bar); |
| 211 | debug("DDR:ar=0x%08x\n", ecm->ar); |
| 212 | |
| 213 | /* |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 214 | * Find the largest CAS by locating the highest 1 bit |
| 215 | * in the spd.cas_lat field. Translate it to a DDR |
| 216 | * controller field value: |
| 217 | * |
| 218 | * CAS Lat DDR I Ctrl |
| 219 | * Clocks SPD Bit Value |
| 220 | * -------+--------+--------- |
| 221 | * 1.0 0 001 |
| 222 | * 1.5 1 010 |
| 223 | * 2.0 2 011 |
| 224 | * 2.5 3 100 |
| 225 | * 3.0 4 101 |
| 226 | * 3.5 5 110 |
| 227 | * 4.0 6 111 |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 228 | */ |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 229 | caslat = __ilog2(spd.cas_lat); |
| 230 | |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 231 | if (caslat > 6 ) { |
| 232 | printf("DDR: Invalid SPD CAS Latency, caslat=%02X\n", |
| 233 | spd.cas_lat); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 234 | return 0; |
| 235 | } |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 236 | max_bus_clk = 1000 *10 / (((spd.clk_cycle & 0xF0) >> 4) * 10 |
| 237 | + (spd.clk_cycle & 0x0f)); |
| 238 | max_data_rate = max_bus_clk * 2; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 239 | |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 240 | debug("DDR:Module maximum data rate is: %dMhz\n", max_data_rate); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 241 | |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 242 | ddrc_clk = gd->ddr_clk / 1000000; |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 243 | |
| 244 | if (max_data_rate >= 390) { /* it is DDR 400 */ |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 245 | if (ddrc_clk <= 410 && ddrc_clk > 350) { |
| 246 | /* DDR controller clk at 350~410 */ |
| 247 | effective_data_rate = 400; /* 5ns */ |
| 248 | caslat = caslat; |
| 249 | } else if (ddrc_clk <= 350 && ddrc_clk > 280) { |
| 250 | /* DDR controller clk at 280~350 */ |
| 251 | effective_data_rate = 333; /* 6ns */ |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 252 | if (spd.clk_cycle2 == 0x60) |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 253 | caslat = caslat - 1; |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 254 | else |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 255 | caslat = caslat; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 256 | } else if (ddrc_clk <= 280 && ddrc_clk > 230) { |
| 257 | /* DDR controller clk at 230~280 */ |
| 258 | effective_data_rate = 266; /* 7.5ns */ |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 259 | if (spd.clk_cycle3 == 0x75) |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 260 | caslat = caslat - 2; |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 261 | else if (spd.clk_cycle2 == 0x60) |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 262 | caslat = caslat - 1; |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 263 | else |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 264 | caslat = caslat; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 265 | } else if (ddrc_clk <= 230 && ddrc_clk > 90) { |
| 266 | /* DDR controller clk at 90~230 */ |
| 267 | effective_data_rate = 200; /* 10ns */ |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 268 | if (spd.clk_cycle3 == 0x75) |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 269 | caslat = caslat - 2; |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 270 | else if (spd.clk_cycle2 == 0x60) |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 271 | caslat = caslat - 1; |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 272 | else |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 273 | caslat = caslat; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 274 | } |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 275 | } else if (max_data_rate >= 323) { /* it is DDR 333 */ |
| 276 | if (ddrc_clk <= 350 && ddrc_clk > 280) { |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 277 | /* DDR controller clk at 280~350 */ |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 278 | effective_data_rate = 333; /* 6ns */ |
| 279 | caslat = caslat; |
| 280 | } else if (ddrc_clk <= 280 && ddrc_clk > 230) { |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 281 | /* DDR controller clk at 230~280 */ |
| 282 | effective_data_rate = 266; /* 7.5ns */ |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 283 | if (spd.clk_cycle2 == 0x75) |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 284 | caslat = caslat - 1; |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 285 | else |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 286 | caslat = caslat; |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 287 | } else if (ddrc_clk <= 230 && ddrc_clk > 90) { |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 288 | /* DDR controller clk at 90~230 */ |
| 289 | effective_data_rate = 200; /* 10ns */ |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 290 | if (spd.clk_cycle3 == 0xa0) |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 291 | caslat = caslat - 2; |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 292 | else if (spd.clk_cycle2 == 0x75) |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 293 | caslat = caslat - 1; |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 294 | else |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 295 | caslat = caslat; |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 296 | } |
| 297 | } else if (max_data_rate >= 256) { /* it is DDR 266 */ |
| 298 | if (ddrc_clk <= 350 && ddrc_clk > 280) { |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 299 | /* DDR controller clk at 280~350 */ |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 300 | printf("DDR: DDR controller freq is more than " |
| 301 | "max data rate of the module\n"); |
| 302 | return 0; |
| 303 | } else if (ddrc_clk <= 280 && ddrc_clk > 230) { |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 304 | /* DDR controller clk at 230~280 */ |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 305 | effective_data_rate = 266; /* 7.5ns */ |
| 306 | caslat = caslat; |
| 307 | } else if (ddrc_clk <= 230 && ddrc_clk > 90) { |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 308 | /* DDR controller clk at 90~230 */ |
| 309 | effective_data_rate = 200; /* 10ns */ |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 310 | if (spd.clk_cycle2 == 0xa0) |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 311 | caslat = caslat - 1; |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 312 | } |
| 313 | } else if (max_data_rate >= 190) { /* it is DDR 200 */ |
| 314 | if (ddrc_clk <= 350 && ddrc_clk > 230) { |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 315 | /* DDR controller clk at 230~350 */ |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 316 | printf("DDR: DDR controller freq is more than " |
| 317 | "max data rate of the module\n"); |
| 318 | return 0; |
| 319 | } else if (ddrc_clk <= 230 && ddrc_clk > 90) { |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 320 | /* DDR controller clk at 90~230 */ |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 321 | effective_data_rate = 200; /* 10ns */ |
| 322 | caslat = caslat; |
| 323 | } |
Timur Tabi | efec630 | 2006-10-31 18:13:36 -0600 | [diff] [blame] | 324 | } |
| 325 | |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 326 | debug("DDR:Effective data rate is: %dMhz\n", effective_data_rate); |
| 327 | debug("DDR:The MSB 1 of CAS Latency is: %d\n", caslat); |
Timur Tabi | efec630 | 2006-10-31 18:13:36 -0600 | [diff] [blame] | 328 | |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 329 | /* |
| 330 | * Errata DDR6 work around: input enable 2 cycles earlier. |
| 331 | * including MPC834x Rev1.0/1.1 and MPC8360 Rev1.1/1.2. |
| 332 | */ |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 333 | if (caslat == 2) |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 334 | ddr->debug_reg = 0x201c0000; /* CL=2 */ |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 335 | else if (caslat == 3) |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 336 | ddr->debug_reg = 0x202c0000; /* CL=2.5 */ |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 337 | else if (caslat == 4) |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 338 | ddr->debug_reg = 0x202c0000; /* CL=3.0 */ |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 339 | |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 340 | __asm__ __volatile__ ("sync"); |
Timur Tabi | efec630 | 2006-10-31 18:13:36 -0600 | [diff] [blame] | 341 | |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 342 | debug("Errata DDR6 (debug_reg=0x%08x)\n", ddr->debug_reg); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 343 | |
| 344 | /* |
| 345 | * note: caslat must also be programmed into ddr->sdram_mode |
| 346 | * register. |
| 347 | * |
| 348 | * note: WRREC(Twr) and WRTORD(Twtr) are not in SPD, |
| 349 | * use conservative value here. |
| 350 | */ |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 351 | caslat_ctrl = (caslat + 1) & 0x07; /* see as above */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 352 | |
| 353 | ddr->timing_cfg_1 = |
| 354 | (((picos_to_clk(spd.trp * 250) & 0x07) << 28 ) | |
| 355 | ((picos_to_clk(spd.tras * 1000) & 0x0f ) << 24 ) | |
| 356 | ((picos_to_clk(spd.trcd * 250) & 0x07) << 20 ) | |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 357 | ((caslat_ctrl & 0x07) << 16 ) | |
| 358 | (((picos_to_clk(spd.trfc * 1000) - 8) & 0x0f) << 12 ) | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 359 | ( 0x300 ) | |
| 360 | ((picos_to_clk(spd.trrd * 250) & 0x07) << 4) | 1); |
| 361 | |
| 362 | ddr->timing_cfg_2 = 0x00000800; |
| 363 | |
| 364 | debug("DDR:timing_cfg_1=0x%08x\n", ddr->timing_cfg_1); |
| 365 | debug("DDR:timing_cfg_2=0x%08x\n", ddr->timing_cfg_2); |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 366 | /* Setup init value, but not enable */ |
| 367 | ddr->sdram_cfg = 0x42000000; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 368 | |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 369 | /* Check DIMM data bus width */ |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 370 | if (spd.dataw_lsb == 0x20) { |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 371 | burstlen = 0x03; /* 32 bit data bus, burst len is 8 */ |
| 372 | printf("\n DDR DIMM: data bus width is 32 bit"); |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 373 | } else { |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 374 | burstlen = 0x02; /* Others act as 64 bit bus, burst len is 4 */ |
| 375 | printf("\n DDR DIMM: data bus width is 64 bit"); |
| 376 | } |
| 377 | |
| 378 | /* Is this an ECC DDR chip? */ |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 379 | if (spd.config == 0x02) |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 380 | printf(" with ECC\n"); |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 381 | else |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 382 | printf(" without ECC\n"); |
| 383 | |
| 384 | /* Burst length is always 4 for 64 bit data bus, 8 for 32 bit data bus, |
| 385 | Burst type is sequential |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 386 | */ |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 387 | switch (caslat) { |
| 388 | case 1: |
| 389 | ddr->sdram_mode = 0x50 | burstlen; /* CL=1.5 */ |
| 390 | break; |
| 391 | case 2: |
| 392 | ddr->sdram_mode = 0x20 | burstlen; /* CL=2.0 */ |
| 393 | break; |
| 394 | case 3: |
| 395 | ddr->sdram_mode = 0x60 | burstlen; /* CL=2.5 */ |
| 396 | break; |
| 397 | case 4: |
| 398 | ddr->sdram_mode = 0x30 | burstlen; /* CL=3.0 */ |
| 399 | break; |
| 400 | default: |
| 401 | printf("DDR:only CL 1.5, 2.0, 2.5, 3.0 is supported\n"); |
| 402 | return 0; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 403 | } |
| 404 | debug("DDR:sdram_mode=0x%08x\n", ddr->sdram_mode); |
| 405 | |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 406 | switch (spd.refresh) { |
| 407 | case 0x00: |
| 408 | case 0x80: |
| 409 | refresh_clk = picos_to_clk(15625000); |
| 410 | break; |
| 411 | case 0x01: |
| 412 | case 0x81: |
| 413 | refresh_clk = picos_to_clk(3900000); |
| 414 | break; |
| 415 | case 0x02: |
| 416 | case 0x82: |
| 417 | refresh_clk = picos_to_clk(7800000); |
| 418 | break; |
| 419 | case 0x03: |
| 420 | case 0x83: |
| 421 | refresh_clk = picos_to_clk(31300000); |
| 422 | break; |
| 423 | case 0x04: |
| 424 | case 0x84: |
| 425 | refresh_clk = picos_to_clk(62500000); |
| 426 | break; |
| 427 | case 0x05: |
| 428 | case 0x85: |
| 429 | refresh_clk = picos_to_clk(125000000); |
| 430 | break; |
| 431 | default: |
| 432 | refresh_clk = 0x512; |
| 433 | break; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | /* |
| 437 | * Set BSTOPRE to 0x100 for page mode |
| 438 | * If auto-charge is used, set BSTOPRE = 0 |
| 439 | */ |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 440 | ddr->sdram_interval = ((refresh_clk & 0x3fff) << 16) | 0x100; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 441 | debug("DDR:sdram_interval=0x%08x\n", ddr->sdram_interval); |
| 442 | |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 443 | /* SS_EN = 0, source synchronous disable |
| 444 | * CLK_ADJST = 0, MCK/MCK# is launched aligned with addr/cmd |
| 445 | */ |
| 446 | ddr->sdram_clk_cntl = 0x00000000; |
| 447 | debug("DDR:sdram_clk_cntl=0x%08x\n", ddr->sdram_clk_cntl); |
Marian Balakowicz | 6f6104d | 2006-03-14 16:23:35 +0100 | [diff] [blame] | 448 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 449 | asm("sync;isync"); |
| 450 | |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 451 | udelay(600); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 452 | |
| 453 | /* |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 454 | * Figure out the settings for the sdram_cfg register. Build up |
| 455 | * the value in 'sdram_cfg' before writing since the write into |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 456 | * the register will actually enable the memory controller, and all |
| 457 | * settings must be done before enabling. |
| 458 | * |
| 459 | * sdram_cfg[0] = 1 (ddr sdram logic enable) |
| 460 | * sdram_cfg[1] = 1 (self-refresh-enable) |
| 461 | * sdram_cfg[6:7] = 2 (SDRAM type = DDR SDRAM) |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 462 | * sdram_cfg[12] = 0 (32_BE =0 , 64 bit bus mode) |
| 463 | * sdram_cfg[13] = 0 (8_BE =0, 4-beat bursts) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 464 | */ |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 465 | sdram_cfg = 0xC2000000; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 466 | |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 467 | /* sdram_cfg[3] = RD_EN - registered DIMM enable */ |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 468 | if (spd.mod_attr & 0x02) |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 469 | sdram_cfg |= 0x10000000; |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 470 | |
| 471 | /* The DIMM is 32bit width */ |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 472 | if (spd.dataw_lsb == 0x20) |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 473 | sdram_cfg |= 0x000C0000; |
Timur Tabi | ff0215a | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 474 | |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 475 | ddrc_ecc_enable = 0; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 476 | |
| 477 | #if defined(CONFIG_DDR_ECC) |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 478 | /* Enable ECC with sdram_cfg[2] */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 479 | if (spd.config == 0x02) { |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 480 | sdram_cfg |= 0x20000000; |
| 481 | ddrc_ecc_enable = 1; |
| 482 | /* disable error detection */ |
| 483 | ddr->err_disable = ~ECC_ERROR_ENABLE; |
| 484 | /* set single bit error threshold to maximum value, |
| 485 | * reset counter to zero */ |
| 486 | ddr->err_sbe = (255 << ECC_ERROR_MAN_SBET_SHIFT) | |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 487 | (0 << ECC_ERROR_MAN_SBEC_SHIFT); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 488 | } |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 489 | |
| 490 | debug("DDR:err_disable=0x%08x\n", ddr->err_disable); |
| 491 | debug("DDR:err_sbe=0x%08x\n", ddr->err_sbe); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 492 | #endif |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 493 | printf(" DDRC ECC mode: %s\n", ddrc_ecc_enable ? "ON":"OFF"); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 494 | |
| 495 | #if defined(CONFIG_DDR_2T_TIMING) |
| 496 | /* |
| 497 | * Enable 2T timing by setting sdram_cfg[16]. |
| 498 | */ |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 499 | sdram_cfg |= SDRAM_CFG_2T_EN; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 500 | #endif |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 501 | /* Enable controller, and GO! */ |
| 502 | ddr->sdram_cfg = sdram_cfg; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 503 | asm("sync;isync"); |
| 504 | udelay(500); |
| 505 | |
| 506 | debug("DDR:sdram_cfg=0x%08x\n", ddr->sdram_cfg); |
Rafal Jaworowski | 4a9b6aa | 2006-03-16 17:46:46 +0100 | [diff] [blame] | 507 | return memsize; /*in MBytes*/ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 508 | } |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 509 | #endif /* CONFIG_SPD_EEPROM */ |
| 510 | |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 511 | #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 512 | /* |
Marian Balakowicz | 6f6104d | 2006-03-14 16:23:35 +0100 | [diff] [blame] | 513 | * Use timebase counter, get_timer() is not availabe |
| 514 | * at this point of initialization yet. |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 515 | */ |
Marian Balakowicz | 6f6104d | 2006-03-14 16:23:35 +0100 | [diff] [blame] | 516 | static __inline__ unsigned long get_tbms (void) |
| 517 | { |
| 518 | unsigned long tbl; |
| 519 | unsigned long tbu1, tbu2; |
| 520 | unsigned long ms; |
| 521 | unsigned long long tmp; |
| 522 | |
| 523 | ulong tbclk = get_tbclk(); |
| 524 | |
| 525 | /* get the timebase ticks */ |
| 526 | do { |
| 527 | asm volatile ("mftbu %0":"=r" (tbu1):); |
| 528 | asm volatile ("mftb %0":"=r" (tbl):); |
| 529 | asm volatile ("mftbu %0":"=r" (tbu2):); |
| 530 | } while (tbu1 != tbu2); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 531 | |
Marian Balakowicz | 6f6104d | 2006-03-14 16:23:35 +0100 | [diff] [blame] | 532 | /* convert ticks to ms */ |
| 533 | tmp = (unsigned long long)(tbu1); |
| 534 | tmp = (tmp << 32); |
| 535 | tmp += (unsigned long long)(tbl); |
| 536 | ms = tmp/(tbclk/1000); |
| 537 | |
| 538 | return ms; |
| 539 | } |
| 540 | |
| 541 | /* |
| 542 | * Initialize all of memory for ECC, then enable errors. |
| 543 | */ |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 544 | /* #define CONFIG_DDR_ECC_INIT_VIA_DMA */ |
Marian Balakowicz | 6f6104d | 2006-03-14 16:23:35 +0100 | [diff] [blame] | 545 | void ddr_enable_ecc(unsigned int dram_size) |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 546 | { |
Timur Tabi | 386a280 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 547 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 548 | volatile ddr83xx_t *ddr= &immap->ddr; |
Marian Balakowicz | 6f6104d | 2006-03-14 16:23:35 +0100 | [diff] [blame] | 549 | unsigned long t_start, t_end; |
Dave Liu | 8c84e47 | 2006-11-02 18:05:50 -0600 | [diff] [blame] | 550 | register u64 *p; |
| 551 | register uint size; |
| 552 | unsigned int pattern[2]; |
Marian Balakowicz | 6f6104d | 2006-03-14 16:23:35 +0100 | [diff] [blame] | 553 | #if defined(CONFIG_DDR_ECC_INIT_VIA_DMA) |
| 554 | uint i; |
| 555 | #endif |
Marian Balakowicz | 6f6104d | 2006-03-14 16:23:35 +0100 | [diff] [blame] | 556 | icache_enable(); |
Marian Balakowicz | 6f6104d | 2006-03-14 16:23:35 +0100 | [diff] [blame] | 557 | t_start = get_tbms(); |
Dave Liu | 8c84e47 | 2006-11-02 18:05:50 -0600 | [diff] [blame] | 558 | pattern[0] = 0xdeadbeef; |
| 559 | pattern[1] = 0xdeadbeef; |
Marian Balakowicz | 6f6104d | 2006-03-14 16:23:35 +0100 | [diff] [blame] | 560 | |
| 561 | #if !defined(CONFIG_DDR_ECC_INIT_VIA_DMA) |
Dave Liu | 8c84e47 | 2006-11-02 18:05:50 -0600 | [diff] [blame] | 562 | debug("ddr init: CPU FP write method\n"); |
| 563 | size = dram_size; |
| 564 | for (p = 0; p < (u64*)(size); p++) { |
| 565 | ppcDWstore((u32*)p, pattern); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 566 | } |
Dave Liu | 8c84e47 | 2006-11-02 18:05:50 -0600 | [diff] [blame] | 567 | __asm__ __volatile__ ("sync"); |
Marian Balakowicz | 6f6104d | 2006-03-14 16:23:35 +0100 | [diff] [blame] | 568 | #else |
Dave Liu | 8c84e47 | 2006-11-02 18:05:50 -0600 | [diff] [blame] | 569 | debug("ddr init: DMA method\n"); |
| 570 | size = 0x2000; |
| 571 | for (p = 0; p < (u64*)(size); p++) { |
| 572 | ppcDWstore((u32*)p, pattern); |
Marian Balakowicz | 6f6104d | 2006-03-14 16:23:35 +0100 | [diff] [blame] | 573 | } |
Dave Liu | 8c84e47 | 2006-11-02 18:05:50 -0600 | [diff] [blame] | 574 | __asm__ __volatile__ ("sync"); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 575 | |
Dave Liu | 8c84e47 | 2006-11-02 18:05:50 -0600 | [diff] [blame] | 576 | /* Initialise DMA for direct transfer */ |
| 577 | dma_init(); |
| 578 | /* Start DMA to transfer */ |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 579 | dma_xfer((uint *)0x2000, 0x2000, (uint *)0); /* 8K */ |
| 580 | dma_xfer((uint *)0x4000, 0x4000, (uint *)0); /* 16K */ |
| 581 | dma_xfer((uint *)0x8000, 0x8000, (uint *)0); /* 32K */ |
| 582 | dma_xfer((uint *)0x10000, 0x10000, (uint *)0); /* 64K */ |
| 583 | dma_xfer((uint *)0x20000, 0x20000, (uint *)0); /* 128K */ |
| 584 | dma_xfer((uint *)0x40000, 0x40000, (uint *)0); /* 256K */ |
| 585 | dma_xfer((uint *)0x80000, 0x80000, (uint *)0); /* 512K */ |
| 586 | dma_xfer((uint *)0x100000, 0x100000, (uint *)0); /* 1M */ |
| 587 | dma_xfer((uint *)0x200000, 0x200000, (uint *)0); /* 2M */ |
| 588 | dma_xfer((uint *)0x400000, 0x400000, (uint *)0); /* 4M */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 589 | |
| 590 | for (i = 1; i < dram_size / 0x800000; i++) { |
| 591 | dma_xfer((uint *)(0x800000*i), 0x800000, (uint *)0); |
| 592 | } |
Jon Loeliger | ebc7224 | 2005-08-01 13:20:47 -0500 | [diff] [blame] | 593 | #endif |
Marian Balakowicz | 6f6104d | 2006-03-14 16:23:35 +0100 | [diff] [blame] | 594 | |
| 595 | t_end = get_tbms(); |
| 596 | icache_disable(); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 597 | |
Marian Balakowicz | 6f6104d | 2006-03-14 16:23:35 +0100 | [diff] [blame] | 598 | debug("\nREADY!!\n"); |
| 599 | debug("ddr init duration: %ld ms\n", t_end - t_start); |
| 600 | |
| 601 | /* Clear All ECC Errors */ |
| 602 | if ((ddr->err_detect & ECC_ERROR_DETECT_MME) == ECC_ERROR_DETECT_MME) |
| 603 | ddr->err_detect |= ECC_ERROR_DETECT_MME; |
| 604 | if ((ddr->err_detect & ECC_ERROR_DETECT_MBE) == ECC_ERROR_DETECT_MBE) |
| 605 | ddr->err_detect |= ECC_ERROR_DETECT_MBE; |
| 606 | if ((ddr->err_detect & ECC_ERROR_DETECT_SBE) == ECC_ERROR_DETECT_SBE) |
| 607 | ddr->err_detect |= ECC_ERROR_DETECT_SBE; |
| 608 | if ((ddr->err_detect & ECC_ERROR_DETECT_MSE) == ECC_ERROR_DETECT_MSE) |
| 609 | ddr->err_detect |= ECC_ERROR_DETECT_MSE; |
| 610 | |
| 611 | /* Disable ECC-Interrupts */ |
| 612 | ddr->err_int_en &= ECC_ERR_INT_DISABLE; |
| 613 | |
| 614 | /* Enable errors for ECC */ |
| 615 | ddr->err_disable &= ECC_ERROR_ENABLE; |
| 616 | |
| 617 | __asm__ __volatile__ ("sync"); |
| 618 | __asm__ __volatile__ ("isync"); |
| 619 | } |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 620 | #endif /* CONFIG_DDR_ECC */ |