18bd522ceSDave Liu /* 28bd522ceSDave Liu * Copyright (C) 2007 Freescale Semiconductor, Inc. 38bd522ceSDave Liu * 48bd522ceSDave Liu * Authors: Nick.Spence@freescale.com 58bd522ceSDave Liu * Wilson.Lo@freescale.com 68bd522ceSDave Liu * scottwood@freescale.com 78bd522ceSDave Liu * 88bd522ceSDave Liu * See file CREDITS for list of people who contributed to this 98bd522ceSDave Liu * project. 108bd522ceSDave Liu * 118bd522ceSDave Liu * This program is free software; you can redistribute it and/or 128bd522ceSDave Liu * modify it under the terms of the GNU General Public License as 138bd522ceSDave Liu * published by the Free Software Foundation; either version 2 of 148bd522ceSDave Liu * the License, or (at your option) any later version. 158bd522ceSDave Liu * 168bd522ceSDave Liu * This program is distributed in the hope that it will be useful, 178bd522ceSDave Liu * but WITHOUT ANY WARRANTY; without even the implied warranty of 188bd522ceSDave Liu * MERCHANTABILITY or FITNESS for A PARTICULAR PURPOSE. See the 198bd522ceSDave Liu * GNU General Public License for more details. 208bd522ceSDave Liu * 218bd522ceSDave Liu * You should have received a copy of the GNU General Public License 228bd522ceSDave Liu * along with this program; if not, write to the Free Software 238bd522ceSDave Liu * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 248bd522ceSDave Liu * MA 02111-1307 USA 258bd522ceSDave Liu */ 268bd522ceSDave Liu 278bd522ceSDave Liu #include <common.h> 288bd522ceSDave Liu #include <mpc83xx.h> 298bd522ceSDave Liu #include <spd_sdram.h> 308bd522ceSDave Liu 318bd522ceSDave Liu #include <asm/bitops.h> 328bd522ceSDave Liu #include <asm/io.h> 338bd522ceSDave Liu 348bd522ceSDave Liu #include <asm/processor.h> 358bd522ceSDave Liu 368bd522ceSDave Liu DECLARE_GLOBAL_DATA_PTR; 378bd522ceSDave Liu 388bd522ceSDave Liu static void resume_from_sleep(void) 398bd522ceSDave Liu { 408bd522ceSDave Liu u32 magic = *(u32 *)0; 418bd522ceSDave Liu 428bd522ceSDave Liu typedef void (*func_t)(void); 438bd522ceSDave Liu func_t resume = *(func_t *)4; 448bd522ceSDave Liu 458bd522ceSDave Liu if (magic == 0xf5153ae5) 468bd522ceSDave Liu resume(); 478bd522ceSDave Liu 488bd522ceSDave Liu gd->flags &= ~GD_FLG_SILENT; 498bd522ceSDave Liu puts("\nResume from sleep failed: bad magic word\n"); 508bd522ceSDave Liu } 518bd522ceSDave Liu 528bd522ceSDave Liu /* Fixed sdram init -- doesn't use serial presence detect. 538bd522ceSDave Liu * 548bd522ceSDave Liu * This is useful for faster booting in configs where the RAM is unlikely 558bd522ceSDave Liu * to be changed, or for things like NAND booting where space is tight. 568bd522ceSDave Liu */ 57*2e95004dSAnton Vorontsov #ifndef CONFIG_SYS_RAMBOOT 588bd522ceSDave Liu static long fixed_sdram(void) 598bd522ceSDave Liu { 606d0f6bcfSJean-Christophe PLAGNIOL-VILLARD volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR; 616d0f6bcfSJean-Christophe PLAGNIOL-VILLARD u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024; 628bd522ceSDave Liu u32 msize_log2 = __ilog2(msize); 638bd522ceSDave Liu 646d0f6bcfSJean-Christophe PLAGNIOL-VILLARD im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000; 658bd522ceSDave Liu im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1); 666d0f6bcfSJean-Christophe PLAGNIOL-VILLARD im->sysconf.ddrcdr = CONFIG_SYS_DDRCDR_VALUE; 678bd522ceSDave Liu 688bd522ceSDave Liu /* 698bd522ceSDave Liu * Erratum DDR3 requires a 50ms delay after clearing DDRCDR[DDR_cfg], 708bd522ceSDave Liu * or the DDR2 controller may fail to initialize correctly. 718bd522ceSDave Liu */ 72*2e95004dSAnton Vorontsov __udelay(50000); 738bd522ceSDave Liu 748bd522ceSDave Liu im->ddr.csbnds[0].csbnds = (msize - 1) >> 24; 756d0f6bcfSJean-Christophe PLAGNIOL-VILLARD im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG; 768bd522ceSDave Liu 778bd522ceSDave Liu /* Currently we use only one CS, so disable the other bank. */ 788bd522ceSDave Liu im->ddr.cs_config[1] = 0; 798bd522ceSDave Liu 806d0f6bcfSJean-Christophe PLAGNIOL-VILLARD im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL; 816d0f6bcfSJean-Christophe PLAGNIOL-VILLARD im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3; 826d0f6bcfSJean-Christophe PLAGNIOL-VILLARD im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1; 836d0f6bcfSJean-Christophe PLAGNIOL-VILLARD im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2; 846d0f6bcfSJean-Christophe PLAGNIOL-VILLARD im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0; 858bd522ceSDave Liu 868bd522ceSDave Liu if (im->pmc.pmccr1 & PMCCR1_POWER_OFF) 876d0f6bcfSJean-Christophe PLAGNIOL-VILLARD im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG | SDRAM_CFG_BI; 888bd522ceSDave Liu else 896d0f6bcfSJean-Christophe PLAGNIOL-VILLARD im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG; 908bd522ceSDave Liu 916d0f6bcfSJean-Christophe PLAGNIOL-VILLARD im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2; 926d0f6bcfSJean-Christophe PLAGNIOL-VILLARD im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE; 936d0f6bcfSJean-Christophe PLAGNIOL-VILLARD im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2; 948bd522ceSDave Liu 956d0f6bcfSJean-Christophe PLAGNIOL-VILLARD im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL; 968bd522ceSDave Liu sync(); 978bd522ceSDave Liu 988bd522ceSDave Liu /* enable DDR controller */ 998bd522ceSDave Liu im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN; 1008bd522ceSDave Liu sync(); 1018bd522ceSDave Liu 1028bd522ceSDave Liu return msize; 1038bd522ceSDave Liu } 104*2e95004dSAnton Vorontsov #else 105*2e95004dSAnton Vorontsov static long fixed_sdram(void) 106*2e95004dSAnton Vorontsov { 107*2e95004dSAnton Vorontsov return CONFIG_SYS_DDR_SIZE * 1024 * 1024; 108*2e95004dSAnton Vorontsov } 109*2e95004dSAnton Vorontsov #endif /* CONFIG_SYS_RAMBOOT */ 1108bd522ceSDave Liu 1119973e3c6SBecky Bruce phys_size_t initdram(int board_type) 1128bd522ceSDave Liu { 1136d0f6bcfSJean-Christophe PLAGNIOL-VILLARD volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR; 1148bd522ceSDave Liu u32 msize; 1158bd522ceSDave Liu 1168bd522ceSDave Liu if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im) 1178bd522ceSDave Liu return -1; 1188bd522ceSDave Liu 1198bd522ceSDave Liu /* DDR SDRAM */ 1208bd522ceSDave Liu msize = fixed_sdram(); 1218bd522ceSDave Liu 1228bd522ceSDave Liu if (im->pmc.pmccr1 & PMCCR1_POWER_OFF) 1238bd522ceSDave Liu resume_from_sleep(); 1248bd522ceSDave Liu 1258bd522ceSDave Liu /* return total bus SDRAM size(bytes) -- DDR */ 1268bd522ceSDave Liu return msize; 1278bd522ceSDave Liu } 128