Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Freescale Semiconductor, Inc. |
| 3 | * |
| 4 | * Authors: Nick.Spence@freescale.com |
| 5 | * Wilson.Lo@freescale.com |
| 6 | * scottwood@freescale.com |
| 7 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <mpc83xx.h> |
| 13 | #include <spd_sdram.h> |
| 14 | |
| 15 | #include <asm/bitops.h> |
| 16 | #include <asm/io.h> |
| 17 | |
| 18 | #include <asm/processor.h> |
| 19 | |
| 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
| 22 | static void resume_from_sleep(void) |
| 23 | { |
| 24 | u32 magic = *(u32 *)0; |
| 25 | |
| 26 | typedef void (*func_t)(void); |
| 27 | func_t resume = *(func_t *)4; |
| 28 | |
| 29 | if (magic == 0xf5153ae5) |
| 30 | resume(); |
| 31 | |
| 32 | gd->flags &= ~GD_FLG_SILENT; |
| 33 | puts("\nResume from sleep failed: bad magic word\n"); |
| 34 | } |
| 35 | |
| 36 | /* Fixed sdram init -- doesn't use serial presence detect. |
| 37 | * |
| 38 | * This is useful for faster booting in configs where the RAM is unlikely |
| 39 | * to be changed, or for things like NAND booting where space is tight. |
| 40 | */ |
Anton Vorontsov | ec82175 | 2009-11-24 20:12:12 +0300 | [diff] [blame] | 41 | #ifndef CONFIG_SYS_RAMBOOT |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 42 | static long fixed_sdram(void) |
| 43 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 44 | volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR; |
| 45 | u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024; |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 46 | u32 msize_log2 = __ilog2(msize); |
| 47 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 48 | im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000; |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 49 | im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 50 | im->sysconf.ddrcdr = CONFIG_SYS_DDRCDR_VALUE; |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 51 | |
| 52 | /* |
| 53 | * Erratum DDR3 requires a 50ms delay after clearing DDRCDR[DDR_cfg], |
| 54 | * or the DDR2 controller may fail to initialize correctly. |
| 55 | */ |
Anton Vorontsov | ec82175 | 2009-11-24 20:12:12 +0300 | [diff] [blame] | 56 | __udelay(50000); |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 57 | |
| 58 | im->ddr.csbnds[0].csbnds = (msize - 1) >> 24; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 59 | im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG; |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 60 | |
| 61 | /* Currently we use only one CS, so disable the other bank. */ |
| 62 | im->ddr.cs_config[1] = 0; |
| 63 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 64 | im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL; |
| 65 | im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3; |
| 66 | im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1; |
| 67 | im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2; |
| 68 | im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0; |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 69 | |
| 70 | if (im->pmc.pmccr1 & PMCCR1_POWER_OFF) |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 71 | im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG | SDRAM_CFG_BI; |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 72 | else |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 73 | im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG; |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 74 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 75 | im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2; |
| 76 | im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE; |
| 77 | im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2; |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 78 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 79 | im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL; |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 80 | sync(); |
| 81 | |
| 82 | /* enable DDR controller */ |
| 83 | im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN; |
| 84 | sync(); |
| 85 | |
| 86 | return msize; |
| 87 | } |
Anton Vorontsov | ec82175 | 2009-11-24 20:12:12 +0300 | [diff] [blame] | 88 | #else |
| 89 | static long fixed_sdram(void) |
| 90 | { |
| 91 | return CONFIG_SYS_DDR_SIZE * 1024 * 1024; |
| 92 | } |
| 93 | #endif /* CONFIG_SYS_RAMBOOT */ |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 94 | |
Becky Bruce | bd99ae7 | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 95 | phys_size_t initdram(int board_type) |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 96 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 97 | volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR; |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 98 | u32 msize; |
| 99 | |
| 100 | if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im) |
| 101 | return -1; |
| 102 | |
| 103 | /* DDR SDRAM */ |
| 104 | msize = fixed_sdram(); |
| 105 | |
| 106 | if (im->pmc.pmccr1 & PMCCR1_POWER_OFF) |
| 107 | resume_from_sleep(); |
| 108 | |
| 109 | /* return total bus SDRAM size(bytes) -- DDR */ |
| 110 | return msize; |
| 111 | } |