Poonam Aggrwal | 987862c | 2009-08-05 13:29:24 +0530 | [diff] [blame] | 1 | /* |
Kumar Gala | f77ca5d | 2011-01-24 23:36:17 -0600 | [diff] [blame] | 2 | * Copyright 2009, 2011 Freescale Semiconductor, Inc. |
Poonam Aggrwal | 987862c | 2009-08-05 13:29:24 +0530 | [diff] [blame] | 3 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Poonam Aggrwal | 987862c | 2009-08-05 13:29:24 +0530 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <asm/mmu.h> |
| 9 | #include <asm/immap_85xx.h> |
Poonam Aggrwal | dfa652d | 2009-09-19 17:50:17 +0530 | [diff] [blame] | 10 | #include <asm/processor.h> |
York Sun | f062659 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 11 | #include <fsl_ddr_sdram.h> |
Poonam Aggrwal | 987862c | 2009-08-05 13:29:24 +0530 | [diff] [blame] | 12 | #include <asm/io.h> |
| 13 | #include <asm/fsl_law.h> |
| 14 | |
Poonam Aggrwal | dfa652d | 2009-09-19 17:50:17 +0530 | [diff] [blame] | 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
Poonam Aggrwal | 987862c | 2009-08-05 13:29:24 +0530 | [diff] [blame] | 17 | #define CONFIG_SYS_DDR_CS0_BNDS 0x0000003F |
| 18 | #define CONFIG_SYS_DDR_CS0_CONFIG 0x80014202 |
| 19 | #define CONFIG_SYS_DDR_CS0_CONFIG_2 0x00000000 |
| 20 | #define CONFIG_SYS_DDR_INIT_ADDR 0x00000000 |
| 21 | #define CONFIG_SYS_DDR_INIT_EXT_ADDR 0x00000000 |
| 22 | #define CONFIG_SYS_DDR_MODE_CONTROL 0x00000000 |
| 23 | #define CONFIG_SYS_DDR_ZQ_CONTROL 0x00000000 |
| 24 | #define CONFIG_SYS_DDR_WRLVL_CONTROL 0x00000000 |
Poonam Aggrwal | 987862c | 2009-08-05 13:29:24 +0530 | [diff] [blame] | 25 | #define CONFIG_SYS_DDR_SR_CNTR 0x00000000 |
| 26 | #define CONFIG_SYS_DDR_RCW_1 0x00000000 |
| 27 | #define CONFIG_SYS_DDR_RCW_2 0x00000000 |
| 28 | #define CONFIG_SYS_DDR_CONTROL 0x43000000 /* Type = DDR2*/ |
| 29 | #define CONFIG_SYS_DDR_CONTROL_2 0x24401000 |
| 30 | #define CONFIG_SYS_DDR_TIMING_4 0x00000000 |
| 31 | #define CONFIG_SYS_DDR_TIMING_5 0x00000000 |
| 32 | |
| 33 | #define CONFIG_SYS_DDR_TIMING_3_400 0x00010000 |
| 34 | #define CONFIG_SYS_DDR_TIMING_0_400 0x00260802 |
| 35 | #define CONFIG_SYS_DDR_TIMING_1_400 0x39355322 |
| 36 | #define CONFIG_SYS_DDR_TIMING_2_400 0x1f9048ca |
| 37 | #define CONFIG_SYS_DDR_CLK_CTRL_400 0x02800000 |
| 38 | #define CONFIG_SYS_DDR_MODE_1_400 0x00480432 |
| 39 | #define CONFIG_SYS_DDR_MODE_2_400 0x00000000 |
| 40 | #define CONFIG_SYS_DDR_INTERVAL_400 0x06180100 |
| 41 | |
| 42 | #define CONFIG_SYS_DDR_TIMING_3_533 0x00020000 |
| 43 | #define CONFIG_SYS_DDR_TIMING_0_533 0x00260802 |
| 44 | #define CONFIG_SYS_DDR_TIMING_1_533 0x4c47c432 |
| 45 | #define CONFIG_SYS_DDR_TIMING_2_533 0x0f9848ce |
| 46 | #define CONFIG_SYS_DDR_CLK_CTRL_533 0x02800000 |
| 47 | #define CONFIG_SYS_DDR_MODE_1_533 0x00040642 |
| 48 | #define CONFIG_SYS_DDR_MODE_2_533 0x00000000 |
| 49 | #define CONFIG_SYS_DDR_INTERVAL_533 0x08200100 |
| 50 | |
| 51 | #define CONFIG_SYS_DDR_TIMING_3_667 0x00030000 |
| 52 | #define CONFIG_SYS_DDR_TIMING_0_667 0x55770802 |
| 53 | #define CONFIG_SYS_DDR_TIMING_1_667 0x5f599543 |
| 54 | #define CONFIG_SYS_DDR_TIMING_2_667 0x0fa074d1 |
Poonam Aggrwal | 9cd9e13 | 2010-06-23 19:32:28 +0530 | [diff] [blame] | 55 | #define CONFIG_SYS_DDR_CLK_CTRL_667 0x03000000 |
Poonam Aggrwal | 987862c | 2009-08-05 13:29:24 +0530 | [diff] [blame] | 56 | #define CONFIG_SYS_DDR_MODE_1_667 0x00040852 |
| 57 | #define CONFIG_SYS_DDR_MODE_2_667 0x00000000 |
| 58 | #define CONFIG_SYS_DDR_INTERVAL_667 0x0a280100 |
| 59 | |
| 60 | #define CONFIG_SYS_DDR_TIMING_3_800 0x00040000 |
Poonam Aggrwal | 2b32351 | 2011-02-07 17:17:28 +0530 | [diff] [blame] | 61 | #define CONFIG_SYS_DDR_TIMING_0_800 0x00770802 |
Poonam Aggrwal | 987862c | 2009-08-05 13:29:24 +0530 | [diff] [blame] | 62 | #define CONFIG_SYS_DDR_TIMING_1_800 0x6f6b6543 |
| 63 | #define CONFIG_SYS_DDR_TIMING_2_800 0x0fa074d1 |
Poonam Aggrwal | a417d6b | 2009-10-27 09:36:38 +0530 | [diff] [blame] | 64 | #define CONFIG_SYS_DDR_CLK_CTRL_800 0x02800000 |
| 65 | #define CONFIG_SYS_DDR_MODE_1_800 0x00040852 |
Poonam Aggrwal | 987862c | 2009-08-05 13:29:24 +0530 | [diff] [blame] | 66 | #define CONFIG_SYS_DDR_MODE_2_800 0x00000000 |
Poonam Aggrwal | 2b32351 | 2011-02-07 17:17:28 +0530 | [diff] [blame] | 67 | #define CONFIG_SYS_DDR_INTERVAL_800 0x0c300100 |
Poonam Aggrwal | 987862c | 2009-08-05 13:29:24 +0530 | [diff] [blame] | 68 | |
| 69 | fsl_ddr_cfg_regs_t ddr_cfg_regs_400 = { |
| 70 | .cs[0].bnds = CONFIG_SYS_DDR_CS0_BNDS, |
| 71 | .cs[0].config = CONFIG_SYS_DDR_CS0_CONFIG, |
| 72 | .cs[0].config_2 = CONFIG_SYS_DDR_CS0_CONFIG_2, |
| 73 | .timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3_400, |
| 74 | .timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0_400, |
| 75 | .timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1_400, |
| 76 | .timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2_400, |
| 77 | .ddr_sdram_cfg = CONFIG_SYS_DDR_CONTROL, |
| 78 | .ddr_sdram_cfg_2 = CONFIG_SYS_DDR_CONTROL_2, |
| 79 | .ddr_sdram_mode = CONFIG_SYS_DDR_MODE_1_400, |
| 80 | .ddr_sdram_mode_2 = CONFIG_SYS_DDR_MODE_2_400, |
| 81 | .ddr_sdram_md_cntl = CONFIG_SYS_DDR_MODE_CONTROL, |
| 82 | .ddr_sdram_interval = CONFIG_SYS_DDR_INTERVAL_400, |
| 83 | .ddr_data_init = CONFIG_MEM_INIT_VALUE, |
| 84 | .ddr_sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL_400, |
| 85 | .ddr_init_addr = CONFIG_SYS_DDR_INIT_ADDR, |
| 86 | .ddr_init_ext_addr = CONFIG_SYS_DDR_INIT_EXT_ADDR, |
| 87 | .timing_cfg_4 = CONFIG_SYS_DDR_TIMING_4, |
| 88 | .timing_cfg_5 = CONFIG_SYS_DDR_TIMING_5, |
| 89 | .ddr_zq_cntl = CONFIG_SYS_DDR_ZQ_CONTROL, |
| 90 | .ddr_wrlvl_cntl = CONFIG_SYS_DDR_WRLVL_CONTROL, |
Poonam Aggrwal | 987862c | 2009-08-05 13:29:24 +0530 | [diff] [blame] | 91 | .ddr_sr_cntr = CONFIG_SYS_DDR_SR_CNTR, |
| 92 | .ddr_sdram_rcw_1 = CONFIG_SYS_DDR_RCW_1, |
| 93 | .ddr_sdram_rcw_2 = CONFIG_SYS_DDR_RCW_2 |
| 94 | }; |
| 95 | |
| 96 | fsl_ddr_cfg_regs_t ddr_cfg_regs_533 = { |
| 97 | .cs[0].bnds = CONFIG_SYS_DDR_CS0_BNDS, |
| 98 | .cs[0].config = CONFIG_SYS_DDR_CS0_CONFIG, |
| 99 | .cs[0].config_2 = CONFIG_SYS_DDR_CS0_CONFIG_2, |
| 100 | .timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3_533, |
| 101 | .timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0_533, |
| 102 | .timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1_533, |
| 103 | .timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2_533, |
| 104 | .ddr_sdram_cfg = CONFIG_SYS_DDR_CONTROL, |
| 105 | .ddr_sdram_cfg_2 = CONFIG_SYS_DDR_CONTROL_2, |
| 106 | .ddr_sdram_mode = CONFIG_SYS_DDR_MODE_1_533, |
| 107 | .ddr_sdram_mode_2 = CONFIG_SYS_DDR_MODE_2_533, |
| 108 | .ddr_sdram_md_cntl = CONFIG_SYS_DDR_MODE_CONTROL, |
| 109 | .ddr_sdram_interval = CONFIG_SYS_DDR_INTERVAL_533, |
| 110 | .ddr_data_init = CONFIG_MEM_INIT_VALUE, |
| 111 | .ddr_sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL_533, |
| 112 | .ddr_init_addr = CONFIG_SYS_DDR_INIT_ADDR, |
| 113 | .ddr_init_ext_addr = CONFIG_SYS_DDR_INIT_EXT_ADDR, |
| 114 | .timing_cfg_4 = CONFIG_SYS_DDR_TIMING_4, |
| 115 | .timing_cfg_5 = CONFIG_SYS_DDR_TIMING_5, |
| 116 | .ddr_zq_cntl = CONFIG_SYS_DDR_ZQ_CONTROL, |
| 117 | .ddr_wrlvl_cntl = CONFIG_SYS_DDR_WRLVL_CONTROL, |
Poonam Aggrwal | 987862c | 2009-08-05 13:29:24 +0530 | [diff] [blame] | 118 | .ddr_sr_cntr = CONFIG_SYS_DDR_SR_CNTR, |
| 119 | .ddr_sdram_rcw_1 = CONFIG_SYS_DDR_RCW_1, |
| 120 | .ddr_sdram_rcw_2 = CONFIG_SYS_DDR_RCW_2 |
| 121 | }; |
| 122 | |
| 123 | fsl_ddr_cfg_regs_t ddr_cfg_regs_667 = { |
| 124 | .cs[0].bnds = CONFIG_SYS_DDR_CS0_BNDS, |
| 125 | .cs[0].config = CONFIG_SYS_DDR_CS0_CONFIG, |
| 126 | .cs[0].config_2 = CONFIG_SYS_DDR_CS0_CONFIG_2, |
| 127 | .timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3_667, |
| 128 | .timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0_667, |
| 129 | .timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1_667, |
| 130 | .timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2_667, |
| 131 | .ddr_sdram_cfg = CONFIG_SYS_DDR_CONTROL, |
| 132 | .ddr_sdram_cfg_2 = CONFIG_SYS_DDR_CONTROL_2, |
| 133 | .ddr_sdram_mode = CONFIG_SYS_DDR_MODE_1_667, |
| 134 | .ddr_sdram_mode_2 = CONFIG_SYS_DDR_MODE_2_667, |
| 135 | .ddr_sdram_md_cntl = CONFIG_SYS_DDR_MODE_CONTROL, |
| 136 | .ddr_sdram_interval = CONFIG_SYS_DDR_INTERVAL_667, |
| 137 | .ddr_data_init = CONFIG_MEM_INIT_VALUE, |
| 138 | .ddr_sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL_667, |
| 139 | .ddr_init_addr = CONFIG_SYS_DDR_INIT_ADDR, |
| 140 | .ddr_init_ext_addr = CONFIG_SYS_DDR_INIT_EXT_ADDR, |
| 141 | .timing_cfg_4 = CONFIG_SYS_DDR_TIMING_4, |
| 142 | .timing_cfg_5 = CONFIG_SYS_DDR_TIMING_5, |
| 143 | .ddr_zq_cntl = CONFIG_SYS_DDR_ZQ_CONTROL, |
| 144 | .ddr_wrlvl_cntl = CONFIG_SYS_DDR_WRLVL_CONTROL, |
Poonam Aggrwal | 987862c | 2009-08-05 13:29:24 +0530 | [diff] [blame] | 145 | .ddr_sr_cntr = CONFIG_SYS_DDR_SR_CNTR, |
| 146 | .ddr_sdram_rcw_1 = CONFIG_SYS_DDR_RCW_1, |
| 147 | .ddr_sdram_rcw_2 = CONFIG_SYS_DDR_RCW_2 |
| 148 | }; |
| 149 | |
| 150 | fsl_ddr_cfg_regs_t ddr_cfg_regs_800 = { |
| 151 | .cs[0].bnds = CONFIG_SYS_DDR_CS0_BNDS, |
| 152 | .cs[0].config = CONFIG_SYS_DDR_CS0_CONFIG, |
| 153 | .cs[0].config_2 = CONFIG_SYS_DDR_CS0_CONFIG_2, |
| 154 | .timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3_800, |
| 155 | .timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0_800, |
| 156 | .timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1_800, |
| 157 | .timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2_800, |
| 158 | .ddr_sdram_cfg = CONFIG_SYS_DDR_CONTROL, |
| 159 | .ddr_sdram_cfg_2 = CONFIG_SYS_DDR_CONTROL_2, |
| 160 | .ddr_sdram_mode = CONFIG_SYS_DDR_MODE_1_800, |
| 161 | .ddr_sdram_mode_2 = CONFIG_SYS_DDR_MODE_2_800, |
| 162 | .ddr_sdram_md_cntl = CONFIG_SYS_DDR_MODE_CONTROL, |
| 163 | .ddr_sdram_interval = CONFIG_SYS_DDR_INTERVAL_800, |
| 164 | .ddr_data_init = CONFIG_MEM_INIT_VALUE, |
| 165 | .ddr_sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL_800, |
| 166 | .ddr_init_addr = CONFIG_SYS_DDR_INIT_ADDR, |
| 167 | .ddr_init_ext_addr = CONFIG_SYS_DDR_INIT_EXT_ADDR, |
| 168 | .timing_cfg_4 = CONFIG_SYS_DDR_TIMING_4, |
| 169 | .timing_cfg_5 = CONFIG_SYS_DDR_TIMING_5, |
| 170 | .ddr_zq_cntl = CONFIG_SYS_DDR_ZQ_CONTROL, |
| 171 | .ddr_wrlvl_cntl = CONFIG_SYS_DDR_WRLVL_CONTROL, |
Poonam Aggrwal | 987862c | 2009-08-05 13:29:24 +0530 | [diff] [blame] | 172 | .ddr_sr_cntr = CONFIG_SYS_DDR_SR_CNTR, |
| 173 | .ddr_sdram_rcw_1 = CONFIG_SYS_DDR_RCW_1, |
| 174 | .ddr_sdram_rcw_2 = CONFIG_SYS_DDR_RCW_2 |
| 175 | }; |
| 176 | |
| 177 | /* |
| 178 | * Fixed sdram init -- doesn't use serial presence detect. |
| 179 | */ |
| 180 | |
| 181 | phys_size_t fixed_sdram (void) |
| 182 | { |
Poonam Aggrwal | a4f546d | 2009-10-27 09:26:55 +0530 | [diff] [blame] | 183 | fsl_ddr_cfg_regs_t ddr_cfg_regs; |
Poonam Aggrwal | dfa652d | 2009-09-19 17:50:17 +0530 | [diff] [blame] | 184 | size_t ddr_size; |
| 185 | struct cpu_type *cpu; |
Kumar Gala | f77ca5d | 2011-01-24 23:36:17 -0600 | [diff] [blame] | 186 | ulong ddr_freq, ddr_freq_mhz; |
Poonam Aggrwal | 987862c | 2009-08-05 13:29:24 +0530 | [diff] [blame] | 187 | |
Simon Glass | a8b5739 | 2012-12-13 20:48:48 +0000 | [diff] [blame] | 188 | cpu = gd->arch.cpu; |
Prabhakar Kushwaha | a30a9de | 2014-05-15 16:43:12 +0530 | [diff] [blame] | 189 | |
| 190 | ddr_size = CONFIG_SYS_SDRAM_SIZE * 1024 * 1024; |
| 191 | |
Priyanka Jain | 56a9899 | 2011-02-08 13:13:15 +0530 | [diff] [blame] | 192 | #if defined(CONFIG_SYS_RAMBOOT) |
| 193 | return ddr_size; |
| 194 | #endif |
Kumar Gala | f77ca5d | 2011-01-24 23:36:17 -0600 | [diff] [blame] | 195 | ddr_freq = get_ddr_freq(0); |
| 196 | ddr_freq_mhz = ddr_freq / 1000000; |
| 197 | |
Prabhakar Kushwaha | a30a9de | 2014-05-15 16:43:12 +0530 | [diff] [blame] | 198 | printf("Configuring DDR for %ld T/s data rate\n", ddr_freq); |
Poonam Aggrwal | 987862c | 2009-08-05 13:29:24 +0530 | [diff] [blame] | 199 | |
Kumar Gala | f77ca5d | 2011-01-24 23:36:17 -0600 | [diff] [blame] | 200 | if(ddr_freq_mhz <= 400) |
Poonam Aggrwal | a4f546d | 2009-10-27 09:26:55 +0530 | [diff] [blame] | 201 | memcpy(&ddr_cfg_regs, &ddr_cfg_regs_400, sizeof(ddr_cfg_regs)); |
Kumar Gala | f77ca5d | 2011-01-24 23:36:17 -0600 | [diff] [blame] | 202 | else if(ddr_freq_mhz <= 533) |
Poonam Aggrwal | a4f546d | 2009-10-27 09:26:55 +0530 | [diff] [blame] | 203 | memcpy(&ddr_cfg_regs, &ddr_cfg_regs_533, sizeof(ddr_cfg_regs)); |
Kumar Gala | f77ca5d | 2011-01-24 23:36:17 -0600 | [diff] [blame] | 204 | else if(ddr_freq_mhz <= 667) |
Poonam Aggrwal | a4f546d | 2009-10-27 09:26:55 +0530 | [diff] [blame] | 205 | memcpy(&ddr_cfg_regs, &ddr_cfg_regs_667, sizeof(ddr_cfg_regs)); |
Kumar Gala | f77ca5d | 2011-01-24 23:36:17 -0600 | [diff] [blame] | 206 | else if(ddr_freq_mhz <= 800) |
Poonam Aggrwal | a4f546d | 2009-10-27 09:26:55 +0530 | [diff] [blame] | 207 | memcpy(&ddr_cfg_regs, &ddr_cfg_regs_800, sizeof(ddr_cfg_regs)); |
Poonam Aggrwal | 987862c | 2009-08-05 13:29:24 +0530 | [diff] [blame] | 208 | else |
Prabhakar Kushwaha | a30a9de | 2014-05-15 16:43:12 +0530 | [diff] [blame] | 209 | panic("Unsupported DDR data rate %ld T/s\n", ddr_freq); |
Poonam Aggrwal | 987862c | 2009-08-05 13:29:24 +0530 | [diff] [blame] | 210 | |
Poonam Aggrwal | dfa652d | 2009-09-19 17:50:17 +0530 | [diff] [blame] | 211 | /* P1020 and it's derivatives support max 32bit DDR width */ |
York Sun | 8cb6548 | 2012-07-06 17:10:33 -0500 | [diff] [blame] | 212 | if (cpu->soc_ver == SVR_P1020 || cpu->soc_ver == SVR_P1011) { |
Poonam Aggrwal | a4f546d | 2009-10-27 09:26:55 +0530 | [diff] [blame] | 213 | ddr_cfg_regs.ddr_sdram_cfg |= SDRAM_CFG_32_BE; |
| 214 | ddr_cfg_regs.cs[0].bnds = 0x0000001F; |
Poonam Aggrwal | dfa652d | 2009-09-19 17:50:17 +0530 | [diff] [blame] | 215 | } |
Poonam Aggrwal | dfa652d | 2009-09-19 17:50:17 +0530 | [diff] [blame] | 216 | |
York Sun | 5e15555 | 2013-06-25 11:37:48 -0700 | [diff] [blame] | 217 | fsl_ddr_set_memctl_regs(&ddr_cfg_regs, 0, 0); |
Poonam Aggrwal | dfa652d | 2009-09-19 17:50:17 +0530 | [diff] [blame] | 218 | |
Becky Bruce | 5e35d8a | 2010-12-17 17:17:56 -0600 | [diff] [blame] | 219 | set_ddr_laws(0, ddr_size, LAW_TRGT_IF_DDR_1); |
Poonam Aggrwal | dfa652d | 2009-09-19 17:50:17 +0530 | [diff] [blame] | 220 | return ddr_size; |
Poonam Aggrwal | 987862c | 2009-08-05 13:29:24 +0530 | [diff] [blame] | 221 | } |