Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 1 | /* |
York Sun | b513d9d | 2012-08-17 08:22:36 +0000 | [diff] [blame] | 2 | * Copyright 2008-2012 Freescale Semiconductor, Inc. |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * Version 2 as published by the Free Software Foundation. |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <asm/io.h> |
| 11 | #include <asm/fsl_ddr_sdram.h> |
York Sun | 7dda847 | 2011-01-10 12:02:59 +0000 | [diff] [blame] | 12 | #include <asm/processor.h> |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 13 | |
| 14 | #if (CONFIG_CHIP_SELECTS_PER_CTRL > 4) |
| 15 | #error Invalid setting for CONFIG_CHIP_SELECTS_PER_CTRL |
| 16 | #endif |
| 17 | |
| 18 | void fsl_ddr_set_memctl_regs(const fsl_ddr_cfg_regs_t *regs, |
| 19 | unsigned int ctrl_num) |
| 20 | { |
| 21 | unsigned int i; |
| 22 | volatile ccsr_ddr_t *ddr; |
Poonam_Aggrwal-b10812 | 30cb145 | 2009-01-04 08:46:38 +0530 | [diff] [blame] | 23 | u32 temp_sdram_cfg; |
York Sun | c8fc959 | 2011-01-25 22:05:49 -0800 | [diff] [blame] | 24 | #ifdef CONFIG_SYS_FSL_ERRATUM_DDR111_DDR134 |
| 25 | volatile ccsr_local_ecm_t *ecm = (void *)CONFIG_SYS_MPC85xx_ECM_ADDR; |
| 26 | u32 total_gb_size_per_controller; |
York Sun | 7d9781b | 2011-03-17 11:18:13 -0700 | [diff] [blame] | 27 | unsigned int csn_bnds_backup = 0, cs_sa, cs_ea, *csn_bnds_t; |
| 28 | int csn = -1; |
York Sun | c8fc959 | 2011-01-25 22:05:49 -0800 | [diff] [blame] | 29 | #endif |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 30 | |
| 31 | switch (ctrl_num) { |
| 32 | case 0: |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 33 | ddr = (void *)CONFIG_SYS_MPC85xx_DDR_ADDR; |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 34 | break; |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 35 | #if defined(CONFIG_SYS_MPC85xx_DDR2_ADDR) && (CONFIG_NUM_DDR_CONTROLLERS > 1) |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 36 | case 1: |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 37 | ddr = (void *)CONFIG_SYS_MPC85xx_DDR2_ADDR; |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 38 | break; |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 39 | #endif |
| 40 | #if defined(CONFIG_SYS_MPC85xx_DDR3_ADDR) && (CONFIG_NUM_DDR_CONTROLLERS > 2) |
| 41 | case 2: |
| 42 | ddr = (void *)CONFIG_SYS_MPC85xx_DDR3_ADDR; |
| 43 | break; |
| 44 | #endif |
| 45 | #if defined(CONFIG_SYS_MPC85xx_DDR4_ADDR) && (CONFIG_NUM_DDR_CONTROLLERS > 3) |
| 46 | case 3: |
| 47 | ddr = (void *)CONFIG_SYS_MPC85xx_DDR4_ADDR; |
| 48 | break; |
| 49 | #endif |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 50 | default: |
| 51 | printf("%s unexpected ctrl_num = %u\n", __FUNCTION__, ctrl_num); |
| 52 | return; |
| 53 | } |
| 54 | |
york | 4260372 | 2010-07-02 22:25:54 +0000 | [diff] [blame] | 55 | out_be32(&ddr->eor, regs->ddr_eor); |
| 56 | |
York Sun | 7d9781b | 2011-03-17 11:18:13 -0700 | [diff] [blame] | 57 | #ifdef CONFIG_SYS_FSL_ERRATUM_DDR111_DDR134 |
York Sun | b513d9d | 2012-08-17 08:22:36 +0000 | [diff] [blame] | 58 | debug("Workaround for ERRATUM_DDR111_DDR134\n"); |
York Sun | 7d9781b | 2011-03-17 11:18:13 -0700 | [diff] [blame] | 59 | for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) { |
| 60 | cs_sa = (regs->cs[i].bnds >> 16) & 0xfff; |
| 61 | cs_ea = regs->cs[i].bnds & 0xfff; |
| 62 | if ((cs_sa <= 0xff) && (cs_ea >= 0xff)) { |
| 63 | csn = i; |
| 64 | csn_bnds_backup = regs->cs[i].bnds; |
| 65 | csn_bnds_t = (unsigned int *) ®s->cs[i].bnds; |
York Sun | 4b736b8 | 2012-05-21 08:43:11 +0000 | [diff] [blame] | 66 | if (cs_ea > 0xeff) |
| 67 | *csn_bnds_t = regs->cs[i].bnds + 0x01000000; |
| 68 | else |
| 69 | *csn_bnds_t = regs->cs[i].bnds + 0x01000100; |
York Sun | 7d9781b | 2011-03-17 11:18:13 -0700 | [diff] [blame] | 70 | debug("Found cs%d_bns (0x%08x) covering 0xff000000, " |
| 71 | "change it to 0x%x\n", |
| 72 | csn, csn_bnds_backup, regs->cs[i].bnds); |
| 73 | break; |
| 74 | } |
| 75 | } |
| 76 | #endif |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 77 | for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) { |
| 78 | if (i == 0) { |
| 79 | out_be32(&ddr->cs0_bnds, regs->cs[i].bnds); |
| 80 | out_be32(&ddr->cs0_config, regs->cs[i].config); |
| 81 | out_be32(&ddr->cs0_config_2, regs->cs[i].config_2); |
| 82 | |
| 83 | } else if (i == 1) { |
| 84 | out_be32(&ddr->cs1_bnds, regs->cs[i].bnds); |
| 85 | out_be32(&ddr->cs1_config, regs->cs[i].config); |
| 86 | out_be32(&ddr->cs1_config_2, regs->cs[i].config_2); |
| 87 | |
| 88 | } else if (i == 2) { |
| 89 | out_be32(&ddr->cs2_bnds, regs->cs[i].bnds); |
| 90 | out_be32(&ddr->cs2_config, regs->cs[i].config); |
| 91 | out_be32(&ddr->cs2_config_2, regs->cs[i].config_2); |
| 92 | |
| 93 | } else if (i == 3) { |
| 94 | out_be32(&ddr->cs3_bnds, regs->cs[i].bnds); |
| 95 | out_be32(&ddr->cs3_config, regs->cs[i].config); |
| 96 | out_be32(&ddr->cs3_config_2, regs->cs[i].config_2); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | out_be32(&ddr->timing_cfg_3, regs->timing_cfg_3); |
| 101 | out_be32(&ddr->timing_cfg_0, regs->timing_cfg_0); |
| 102 | out_be32(&ddr->timing_cfg_1, regs->timing_cfg_1); |
| 103 | out_be32(&ddr->timing_cfg_2, regs->timing_cfg_2); |
| 104 | out_be32(&ddr->sdram_cfg_2, regs->ddr_sdram_cfg_2); |
| 105 | out_be32(&ddr->sdram_mode, regs->ddr_sdram_mode); |
| 106 | out_be32(&ddr->sdram_mode_2, regs->ddr_sdram_mode_2); |
York Sun | ba0c2eb | 2011-01-10 12:03:00 +0000 | [diff] [blame] | 107 | out_be32(&ddr->sdram_mode_3, regs->ddr_sdram_mode_3); |
| 108 | out_be32(&ddr->sdram_mode_4, regs->ddr_sdram_mode_4); |
| 109 | out_be32(&ddr->sdram_mode_5, regs->ddr_sdram_mode_5); |
| 110 | out_be32(&ddr->sdram_mode_6, regs->ddr_sdram_mode_6); |
| 111 | out_be32(&ddr->sdram_mode_7, regs->ddr_sdram_mode_7); |
| 112 | out_be32(&ddr->sdram_mode_8, regs->ddr_sdram_mode_8); |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 113 | out_be32(&ddr->sdram_md_cntl, regs->ddr_sdram_md_cntl); |
| 114 | out_be32(&ddr->sdram_interval, regs->ddr_sdram_interval); |
| 115 | out_be32(&ddr->sdram_data_init, regs->ddr_data_init); |
| 116 | out_be32(&ddr->sdram_clk_cntl, regs->ddr_sdram_clk_cntl); |
| 117 | out_be32(&ddr->init_addr, regs->ddr_init_addr); |
| 118 | out_be32(&ddr->init_ext_addr, regs->ddr_init_ext_addr); |
| 119 | |
| 120 | out_be32(&ddr->timing_cfg_4, regs->timing_cfg_4); |
| 121 | out_be32(&ddr->timing_cfg_5, regs->timing_cfg_5); |
| 122 | out_be32(&ddr->ddr_zq_cntl, regs->ddr_zq_cntl); |
| 123 | out_be32(&ddr->ddr_wrlvl_cntl, regs->ddr_wrlvl_cntl); |
York Sun | 7d69ea3 | 2012-10-08 07:44:22 +0000 | [diff] [blame] | 124 | if (regs->ddr_wrlvl_cntl_2) |
| 125 | out_be32(&ddr->ddr_wrlvl_cntl_2, regs->ddr_wrlvl_cntl_2); |
| 126 | if (regs->ddr_wrlvl_cntl_3) |
| 127 | out_be32(&ddr->ddr_wrlvl_cntl_3, regs->ddr_wrlvl_cntl_3); |
| 128 | |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 129 | out_be32(&ddr->ddr_sr_cntr, regs->ddr_sr_cntr); |
| 130 | out_be32(&ddr->ddr_sdram_rcw_1, regs->ddr_sdram_rcw_1); |
| 131 | out_be32(&ddr->ddr_sdram_rcw_2, regs->ddr_sdram_rcw_2); |
York Sun | 7dda847 | 2011-01-10 12:02:59 +0000 | [diff] [blame] | 132 | out_be32(&ddr->ddr_cdr1, regs->ddr_cdr1); |
| 133 | out_be32(&ddr->ddr_cdr2, regs->ddr_cdr2); |
| 134 | out_be32(&ddr->err_disable, regs->err_disable); |
| 135 | out_be32(&ddr->err_int_en, regs->err_int_en); |
York Sun | b513d9d | 2012-08-17 08:22:36 +0000 | [diff] [blame] | 136 | for (i = 0; i < 32; i++) { |
| 137 | if (regs->debug[i]) { |
| 138 | debug("Write to debug_%d as %08x\n", i+1, regs->debug[i]); |
| 139 | out_be32(&ddr->debug[i], regs->debug[i]); |
| 140 | } |
| 141 | } |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 142 | |
York Sun | df2be19 | 2011-11-20 10:01:35 -0800 | [diff] [blame] | 143 | #ifdef CONFIG_SYS_FSL_ERRATUM_DDR_A003474 |
| 144 | out_be32(&ddr->debug[12], 0x00000015); |
| 145 | out_be32(&ddr->debug[21], 0x24000000); |
| 146 | #endif /* CONFIG_SYS_FSL_ERRATUM_DDR_A003474 */ |
| 147 | |
Ed Swarthout | e674b83 | 2009-02-24 02:37:59 -0600 | [diff] [blame] | 148 | /* Set, but do not enable the memory */ |
| 149 | temp_sdram_cfg = regs->ddr_sdram_cfg; |
Poonam_Aggrwal-b10812 | 30cb145 | 2009-01-04 08:46:38 +0530 | [diff] [blame] | 150 | temp_sdram_cfg &= ~(SDRAM_CFG_MEM_EN); |
| 151 | out_be32(&ddr->sdram_cfg, temp_sdram_cfg); |
York Sun | 922f40f | 2011-01-10 12:03:01 +0000 | [diff] [blame] | 152 | #ifdef CONFIG_SYS_FSL_ERRATUM_DDR_A003 |
York Sun | b513d9d | 2012-08-17 08:22:36 +0000 | [diff] [blame] | 153 | debug("Workaround for ERRATUM_DDR_A003\n"); |
York Sun | 922f40f | 2011-01-10 12:03:01 +0000 | [diff] [blame] | 154 | if (regs->ddr_sdram_rcw_2 & 0x00f00000) { |
| 155 | out_be32(&ddr->timing_cfg_2, regs->timing_cfg_2 & 0xf07fffff); |
| 156 | out_be32(&ddr->debug[2], 0x00000400); |
| 157 | out_be32(&ddr->ddr_zq_cntl, regs->ddr_zq_cntl & 0x7fffffff); |
| 158 | out_be32(&ddr->ddr_wrlvl_cntl, regs->ddr_wrlvl_cntl & 0x7fffffff); |
| 159 | out_be32(&ddr->sdram_cfg_2, regs->ddr_sdram_cfg_2 & 0xffffffeb); |
| 160 | out_be32(&ddr->mtcr, 0); |
| 161 | out_be32(&ddr->debug[12], 0x00000015); |
| 162 | out_be32(&ddr->debug[21], 0x24000000); |
| 163 | out_be32(&ddr->sdram_interval, regs->ddr_sdram_interval & 0xffff); |
| 164 | out_be32(&ddr->sdram_cfg, temp_sdram_cfg | SDRAM_CFG_BI | SDRAM_CFG_MEM_EN); |
| 165 | |
| 166 | asm volatile("sync;isync"); |
| 167 | while (!(in_be32(&ddr->debug[1]) & 0x2)) |
| 168 | ; |
| 169 | |
| 170 | switch (regs->ddr_sdram_rcw_2 & 0x00f00000) { |
| 171 | case 0x00000000: |
| 172 | out_be32(&ddr->sdram_md_cntl, |
| 173 | MD_CNTL_MD_EN | |
| 174 | MD_CNTL_CS_SEL_CS0_CS1 | |
| 175 | 0x04000000 | |
| 176 | MD_CNTL_WRCW | |
| 177 | MD_CNTL_MD_VALUE(0x02)); |
| 178 | break; |
| 179 | case 0x00100000: |
| 180 | out_be32(&ddr->sdram_md_cntl, |
| 181 | MD_CNTL_MD_EN | |
| 182 | MD_CNTL_CS_SEL_CS0_CS1 | |
| 183 | 0x04000000 | |
| 184 | MD_CNTL_WRCW | |
| 185 | MD_CNTL_MD_VALUE(0x0a)); |
| 186 | break; |
| 187 | case 0x00200000: |
| 188 | out_be32(&ddr->sdram_md_cntl, |
| 189 | MD_CNTL_MD_EN | |
| 190 | MD_CNTL_CS_SEL_CS0_CS1 | |
| 191 | 0x04000000 | |
| 192 | MD_CNTL_WRCW | |
| 193 | MD_CNTL_MD_VALUE(0x12)); |
| 194 | break; |
| 195 | case 0x00300000: |
| 196 | out_be32(&ddr->sdram_md_cntl, |
| 197 | MD_CNTL_MD_EN | |
| 198 | MD_CNTL_CS_SEL_CS0_CS1 | |
| 199 | 0x04000000 | |
| 200 | MD_CNTL_WRCW | |
| 201 | MD_CNTL_MD_VALUE(0x1a)); |
| 202 | break; |
| 203 | default: |
| 204 | out_be32(&ddr->sdram_md_cntl, |
| 205 | MD_CNTL_MD_EN | |
| 206 | MD_CNTL_CS_SEL_CS0_CS1 | |
| 207 | 0x04000000 | |
| 208 | MD_CNTL_WRCW | |
| 209 | MD_CNTL_MD_VALUE(0x02)); |
| 210 | printf("Unsupported RC10\n"); |
| 211 | break; |
| 212 | } |
| 213 | |
| 214 | while (in_be32(&ddr->sdram_md_cntl) & 0x80000000) |
| 215 | ; |
| 216 | udelay(6); |
| 217 | out_be32(&ddr->sdram_cfg, temp_sdram_cfg); |
| 218 | out_be32(&ddr->timing_cfg_2, regs->timing_cfg_2); |
| 219 | out_be32(&ddr->debug[2], 0x0); |
| 220 | out_be32(&ddr->ddr_zq_cntl, regs->ddr_zq_cntl); |
| 221 | out_be32(&ddr->ddr_wrlvl_cntl, regs->ddr_wrlvl_cntl); |
| 222 | out_be32(&ddr->sdram_cfg_2, regs->ddr_sdram_cfg_2); |
| 223 | out_be32(&ddr->debug[12], 0x0); |
| 224 | out_be32(&ddr->debug[21], 0x0); |
| 225 | out_be32(&ddr->sdram_interval, regs->ddr_sdram_interval); |
| 226 | |
| 227 | } |
| 228 | #endif |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 229 | /* |
Dave Liu | 7dc79f7 | 2008-10-23 21:18:53 +0800 | [diff] [blame] | 230 | * For 8572 DDR1 erratum - DDR controller may enter illegal state |
| 231 | * when operatiing in 32-bit bus mode with 4-beat bursts, |
| 232 | * This erratum does not affect DDR3 mode, only for DDR2 mode. |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 233 | */ |
York Sun | 9aa857b | 2011-01-25 21:51:27 -0800 | [diff] [blame] | 234 | #ifdef CONFIG_SYS_FSL_ERRATUM_DDR_115 |
York Sun | b513d9d | 2012-08-17 08:22:36 +0000 | [diff] [blame] | 235 | debug("Workaround for ERRATUM_DDR_115\n"); |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 236 | if ((((in_be32(&ddr->sdram_cfg) >> 24) & 0x7) == SDRAM_TYPE_DDR2) |
Dave Liu | 7dc79f7 | 2008-10-23 21:18:53 +0800 | [diff] [blame] | 237 | && in_be32(&ddr->sdram_cfg) & 0x80000) { |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 238 | /* set DEBUG_1[31] */ |
York Sun | 7dda847 | 2011-01-10 12:02:59 +0000 | [diff] [blame] | 239 | setbits_be32(&ddr->debug[0], 1); |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 240 | } |
Dave Liu | 7dc79f7 | 2008-10-23 21:18:53 +0800 | [diff] [blame] | 241 | #endif |
York Sun | c8fc959 | 2011-01-25 22:05:49 -0800 | [diff] [blame] | 242 | #ifdef CONFIG_SYS_FSL_ERRATUM_DDR111_DDR134 |
York Sun | b513d9d | 2012-08-17 08:22:36 +0000 | [diff] [blame] | 243 | debug("Workaround for ERRATUM_DDR111_DDR134\n"); |
York Sun | c8fc959 | 2011-01-25 22:05:49 -0800 | [diff] [blame] | 244 | /* |
| 245 | * This is the combined workaround for DDR111 and DDR134 |
| 246 | * following the published errata for MPC8572 |
| 247 | */ |
| 248 | |
| 249 | /* 1. Set EEBACR[3] */ |
| 250 | setbits_be32(&ecm->eebacr, 0x10000000); |
| 251 | debug("Setting EEBACR[3] to 0x%08x\n", in_be32(&ecm->eebacr)); |
| 252 | |
| 253 | /* 2. Set DINIT in SDRAM_CFG_2*/ |
| 254 | setbits_be32(&ddr->sdram_cfg_2, SDRAM_CFG2_D_INIT); |
| 255 | debug("Setting sdram_cfg_2[D_INIT] to 0x%08x\n", |
| 256 | in_be32(&ddr->sdram_cfg_2)); |
| 257 | |
| 258 | /* 3. Set DEBUG_3[21] */ |
| 259 | setbits_be32(&ddr->debug[2], 0x400); |
| 260 | debug("Setting DEBUG_3[21] to 0x%08x\n", in_be32(&ddr->debug[2])); |
| 261 | |
| 262 | #endif /* part 1 of the workaound */ |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 263 | |
| 264 | /* |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 265 | * 500 painful micro-seconds must elapse between |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 266 | * the DDR clock setup and the DDR config enable. |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 267 | * DDR2 need 200 us, and DDR3 need 500 us from spec, |
| 268 | * we choose the max, that is 500 us for all of case. |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 269 | */ |
Dave Liu | 4be87b2 | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 270 | udelay(500); |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 271 | asm volatile("sync;isync"); |
| 272 | |
Poonam_Aggrwal-b10812 | 30cb145 | 2009-01-04 08:46:38 +0530 | [diff] [blame] | 273 | /* Let the controller go */ |
York Sun | 922f40f | 2011-01-10 12:03:01 +0000 | [diff] [blame] | 274 | temp_sdram_cfg = in_be32(&ddr->sdram_cfg) & ~SDRAM_CFG_BI; |
Poonam_Aggrwal-b10812 | 30cb145 | 2009-01-04 08:46:38 +0530 | [diff] [blame] | 275 | out_be32(&ddr->sdram_cfg, temp_sdram_cfg | SDRAM_CFG_MEM_EN); |
York Sun | 922f40f | 2011-01-10 12:03:01 +0000 | [diff] [blame] | 276 | asm volatile("sync;isync"); |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 277 | |
| 278 | /* Poll DDR_SDRAM_CFG_2[D_INIT] bit until auto-data init is done. */ |
York Sun | c8fc959 | 2011-01-25 22:05:49 -0800 | [diff] [blame] | 279 | while (in_be32(&ddr->sdram_cfg_2) & SDRAM_CFG2_D_INIT) |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 280 | udelay(10000); /* throttle polling rate */ |
York Sun | c8fc959 | 2011-01-25 22:05:49 -0800 | [diff] [blame] | 281 | |
| 282 | #ifdef CONFIG_SYS_FSL_ERRATUM_DDR111_DDR134 |
| 283 | /* continue this workaround */ |
| 284 | |
| 285 | /* 4. Clear DEBUG3[21] */ |
| 286 | clrbits_be32(&ddr->debug[2], 0x400); |
| 287 | debug("Clearing D3[21] to 0x%08x\n", in_be32(&ddr->debug[2])); |
| 288 | |
| 289 | /* DDR134 workaround starts */ |
| 290 | /* A: Clear sdram_cfg_2[odt_cfg] */ |
| 291 | clrbits_be32(&ddr->sdram_cfg_2, SDRAM_CFG2_ODT_CFG_MASK); |
| 292 | debug("Clearing SDRAM_CFG2[ODT_CFG] to 0x%08x\n", |
| 293 | in_be32(&ddr->sdram_cfg_2)); |
| 294 | |
| 295 | /* B: Set DEBUG1[15] */ |
| 296 | setbits_be32(&ddr->debug[0], 0x10000); |
| 297 | debug("Setting D1[15] to 0x%08x\n", in_be32(&ddr->debug[0])); |
| 298 | |
| 299 | /* C: Set timing_cfg_2[cpo] to 0b11111 */ |
| 300 | setbits_be32(&ddr->timing_cfg_2, TIMING_CFG_2_CPO_MASK); |
| 301 | debug("Setting TMING_CFG_2[CPO] to 0x%08x\n", |
| 302 | in_be32(&ddr->timing_cfg_2)); |
| 303 | |
| 304 | /* D: Set D6 to 0x9f9f9f9f */ |
| 305 | out_be32(&ddr->debug[5], 0x9f9f9f9f); |
| 306 | debug("Setting D6 to 0x%08x\n", in_be32(&ddr->debug[5])); |
| 307 | |
| 308 | /* E: Set D7 to 0x9f9f9f9f */ |
| 309 | out_be32(&ddr->debug[6], 0x9f9f9f9f); |
| 310 | debug("Setting D7 to 0x%08x\n", in_be32(&ddr->debug[6])); |
| 311 | |
| 312 | /* F: Set D2[20] */ |
| 313 | setbits_be32(&ddr->debug[1], 0x800); |
| 314 | debug("Setting D2[20] to 0x%08x\n", in_be32(&ddr->debug[1])); |
| 315 | |
| 316 | /* G: Poll on D2[20] until cleared */ |
| 317 | while (in_be32(&ddr->debug[1]) & 0x800) |
| 318 | udelay(10000); /* throttle polling rate */ |
| 319 | |
| 320 | /* H: Clear D1[15] */ |
| 321 | clrbits_be32(&ddr->debug[0], 0x10000); |
| 322 | debug("Setting D1[15] to 0x%08x\n", in_be32(&ddr->debug[0])); |
| 323 | |
| 324 | /* I: Set sdram_cfg_2[odt_cfg] */ |
| 325 | setbits_be32(&ddr->sdram_cfg_2, |
| 326 | regs->ddr_sdram_cfg_2 & SDRAM_CFG2_ODT_CFG_MASK); |
| 327 | debug("Setting sdram_cfg_2 to 0x%08x\n", in_be32(&ddr->sdram_cfg_2)); |
| 328 | |
| 329 | /* Continuing with the DDR111 workaround */ |
| 330 | /* 5. Set D2[21] */ |
| 331 | setbits_be32(&ddr->debug[1], 0x400); |
| 332 | debug("Setting D2[21] to 0x%08x\n", in_be32(&ddr->debug[1])); |
| 333 | |
| 334 | /* 6. Poll D2[21] until its cleared */ |
| 335 | while (in_be32(&ddr->debug[1]) & 0x400) |
| 336 | udelay(10000); /* throttle polling rate */ |
| 337 | |
| 338 | /* 7. Wait for 400ms/GB */ |
| 339 | total_gb_size_per_controller = 0; |
| 340 | for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) { |
York Sun | 4b736b8 | 2012-05-21 08:43:11 +0000 | [diff] [blame] | 341 | if (i == csn) { |
| 342 | total_gb_size_per_controller += |
| 343 | ((csn_bnds_backup & 0xFFFF) >> 6) |
| 344 | - (csn_bnds_backup >> 22) + 1; |
| 345 | } else { |
| 346 | total_gb_size_per_controller += |
York Sun | c8fc959 | 2011-01-25 22:05:49 -0800 | [diff] [blame] | 347 | ((regs->cs[i].bnds & 0xFFFF) >> 6) |
| 348 | - (regs->cs[i].bnds >> 22) + 1; |
York Sun | 4b736b8 | 2012-05-21 08:43:11 +0000 | [diff] [blame] | 349 | } |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 350 | } |
York Sun | c8fc959 | 2011-01-25 22:05:49 -0800 | [diff] [blame] | 351 | if (in_be32(&ddr->sdram_cfg) & 0x80000) |
| 352 | total_gb_size_per_controller <<= 1; |
| 353 | debug("Wait for %d ms\n", total_gb_size_per_controller * 400); |
| 354 | udelay(total_gb_size_per_controller * 400000); |
| 355 | |
| 356 | /* 8. Set sdram_cfg_2[dinit] if options requires */ |
| 357 | setbits_be32(&ddr->sdram_cfg_2, |
| 358 | regs->ddr_sdram_cfg_2 & SDRAM_CFG2_D_INIT); |
| 359 | debug("Setting sdram_cfg_2 to 0x%08x\n", in_be32(&ddr->sdram_cfg_2)); |
| 360 | |
| 361 | /* 9. Poll until dinit is cleared */ |
| 362 | while (in_be32(&ddr->sdram_cfg_2) & SDRAM_CFG2_D_INIT) |
| 363 | udelay(10000); |
| 364 | |
| 365 | /* 10. Clear EEBACR[3] */ |
| 366 | clrbits_be32(&ecm->eebacr, 10000000); |
| 367 | debug("Clearing EEBACR[3] to 0x%08x\n", in_be32(&ecm->eebacr)); |
York Sun | 7d9781b | 2011-03-17 11:18:13 -0700 | [diff] [blame] | 368 | |
| 369 | if (csn != -1) { |
| 370 | csn_bnds_t = (unsigned int *) ®s->cs[csn].bnds; |
| 371 | *csn_bnds_t = csn_bnds_backup; |
| 372 | debug("Change cs%d_bnds back to 0x%08x\n", |
| 373 | csn, regs->cs[csn].bnds); |
| 374 | setbits_be32(&ddr->sdram_cfg, 0x2); /* MEM_HALT */ |
| 375 | switch (csn) { |
| 376 | case 0: |
| 377 | out_be32(&ddr->cs0_bnds, regs->cs[csn].bnds); |
| 378 | break; |
| 379 | case 1: |
| 380 | out_be32(&ddr->cs1_bnds, regs->cs[csn].bnds); |
| 381 | break; |
| 382 | case 2: |
| 383 | out_be32(&ddr->cs2_bnds, regs->cs[csn].bnds); |
| 384 | break; |
| 385 | case 3: |
| 386 | out_be32(&ddr->cs3_bnds, regs->cs[csn].bnds); |
| 387 | break; |
| 388 | } |
| 389 | clrbits_be32(&ddr->sdram_cfg, 0x2); |
| 390 | } |
York Sun | c8fc959 | 2011-01-25 22:05:49 -0800 | [diff] [blame] | 391 | #endif /* CONFIG_SYS_FSL_ERRATUM_DDR111_DDR134 */ |
Kumar Gala | d5a1fb9 | 2008-08-26 21:34:55 -0500 | [diff] [blame] | 392 | } |