15d108ac8SSergei Poselenov /* 25d108ac8SSergei Poselenov * (C) Copyright 2008 35d108ac8SSergei Poselenov * Sergei Poselenov, Emcraft Systems, sposelenov@emcraft.com. 45d108ac8SSergei Poselenov * 55d108ac8SSergei Poselenov * See file CREDITS for list of people who contributed to this 65d108ac8SSergei Poselenov * project. 75d108ac8SSergei Poselenov * 85d108ac8SSergei Poselenov * This program is free software; you can redistribute it and/or 95d108ac8SSergei Poselenov * modify it under the terms of the GNU General Public License as 105d108ac8SSergei Poselenov * published by the Free Software Foundation; either version 2 of 115d108ac8SSergei Poselenov * the License, or (at your option) any later version. 125d108ac8SSergei Poselenov * 135d108ac8SSergei Poselenov * This program is distributed in the hope that it will be useful, 145d108ac8SSergei Poselenov * but WITHOUT ANY WARRANTY; without even the implied warranty of 155d108ac8SSergei Poselenov * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 165d108ac8SSergei Poselenov * GNU General Public License for more details. 175d108ac8SSergei Poselenov * 185d108ac8SSergei Poselenov * You should have received a copy of the GNU General Public License 195d108ac8SSergei Poselenov * along with this program; if not, write to the Free Software 205d108ac8SSergei Poselenov * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 215d108ac8SSergei Poselenov * MA 02111-1307 USA 225d108ac8SSergei Poselenov */ 235d108ac8SSergei Poselenov 245d108ac8SSergei Poselenov 255d108ac8SSergei Poselenov #include <common.h> 265d108ac8SSergei Poselenov #include <asm/processor.h> 275d108ac8SSergei Poselenov #include <asm/immap_85xx.h> 28be0bd823SKumar Gala #include <asm/fsl_ddr_sdram.h> 295d108ac8SSergei Poselenov #include <asm/processor.h> 305d108ac8SSergei Poselenov #include <asm/mmu.h> 315d108ac8SSergei Poselenov #include <spd_sdram.h> 325d108ac8SSergei Poselenov 335d108ac8SSergei Poselenov 345d108ac8SSergei Poselenov #if !defined(CONFIG_SPD_EEPROM) 355d108ac8SSergei Poselenov /* 365d108ac8SSergei Poselenov * Autodetect onboard DDR SDRAM on 85xx platforms 375d108ac8SSergei Poselenov * 385d108ac8SSergei Poselenov * NOTE: Some of the hardcoded values are hardware dependant, 395d108ac8SSergei Poselenov * so this should be extended for other future boards 405d108ac8SSergei Poselenov * using this routine! 415d108ac8SSergei Poselenov */ 42*38dba0c2SBecky Bruce phys_size_t fixed_sdram(void) 435d108ac8SSergei Poselenov { 446d0f6bcfSJean-Christophe PLAGNIOL-VILLARD volatile ccsr_ddr_t *ddr = (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR); 455d108ac8SSergei Poselenov 465d108ac8SSergei Poselenov /* 475d108ac8SSergei Poselenov * Disable memory controller. 485d108ac8SSergei Poselenov */ 495d108ac8SSergei Poselenov ddr->cs0_config = 0; 505d108ac8SSergei Poselenov ddr->sdram_cfg = 0; 515d108ac8SSergei Poselenov 526d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS; 536d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG; 546d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0; 556d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1; 566d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2; 576d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->sdram_mode = CONFIG_SYS_DDR_MODE; 586d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL; 596d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CONFIG_2; 606d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CONTROL; 615d108ac8SSergei Poselenov 625d108ac8SSergei Poselenov asm ("sync;isync;msync"); 635d108ac8SSergei Poselenov udelay(1000); 645d108ac8SSergei Poselenov 656d0f6bcfSJean-Christophe PLAGNIOL-VILLARD ddr->sdram_cfg = CONFIG_SYS_DDR_CONFIG; 665d108ac8SSergei Poselenov asm ("sync; isync; msync"); 675d108ac8SSergei Poselenov udelay(1000); 685d108ac8SSergei Poselenov 696d0f6bcfSJean-Christophe PLAGNIOL-VILLARD if (get_ram_size(0, CONFIG_SYS_SDRAM_SIZE<<20) == CONFIG_SYS_SDRAM_SIZE<<20) { 705d108ac8SSergei Poselenov /* 715d108ac8SSergei Poselenov * OK, size detected -> all done 725d108ac8SSergei Poselenov */ 736d0f6bcfSJean-Christophe PLAGNIOL-VILLARD return CONFIG_SYS_SDRAM_SIZE<<20; 745d108ac8SSergei Poselenov } 755d108ac8SSergei Poselenov 765d108ac8SSergei Poselenov return 0; /* nothing found ! */ 775d108ac8SSergei Poselenov } 785d108ac8SSergei Poselenov #endif 795d108ac8SSergei Poselenov 806d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #if defined(CONFIG_SYS_DRAM_TEST) 815d108ac8SSergei Poselenov int testdram (void) 825d108ac8SSergei Poselenov { 836d0f6bcfSJean-Christophe PLAGNIOL-VILLARD uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START; 846d0f6bcfSJean-Christophe PLAGNIOL-VILLARD uint *pend = (uint *) CONFIG_SYS_MEMTEST_END; 855d108ac8SSergei Poselenov uint *p; 865d108ac8SSergei Poselenov 875d108ac8SSergei Poselenov printf ("SDRAM test phase 1:\n"); 885d108ac8SSergei Poselenov for (p = pstart; p < pend; p++) 895d108ac8SSergei Poselenov *p = 0xaaaaaaaa; 905d108ac8SSergei Poselenov 915d108ac8SSergei Poselenov for (p = pstart; p < pend; p++) { 925d108ac8SSergei Poselenov if (*p != 0xaaaaaaaa) { 935d108ac8SSergei Poselenov printf ("SDRAM test fails at: %08x\n", (uint) p); 945d108ac8SSergei Poselenov return 1; 955d108ac8SSergei Poselenov } 965d108ac8SSergei Poselenov } 975d108ac8SSergei Poselenov 985d108ac8SSergei Poselenov printf ("SDRAM test phase 2:\n"); 995d108ac8SSergei Poselenov for (p = pstart; p < pend; p++) 1005d108ac8SSergei Poselenov *p = 0x55555555; 1015d108ac8SSergei Poselenov 1025d108ac8SSergei Poselenov for (p = pstart; p < pend; p++) { 1035d108ac8SSergei Poselenov if (*p != 0x55555555) { 1045d108ac8SSergei Poselenov printf ("SDRAM test fails at: %08x\n", (uint) p); 1055d108ac8SSergei Poselenov return 1; 1065d108ac8SSergei Poselenov } 1075d108ac8SSergei Poselenov } 1085d108ac8SSergei Poselenov 1095d108ac8SSergei Poselenov printf ("SDRAM test passed.\n"); 1105d108ac8SSergei Poselenov return 0; 1115d108ac8SSergei Poselenov } 1125d108ac8SSergei Poselenov #endif 113