Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 Gateworks Corporation |
| 3 | * Author: Tim Harvey <tharvey@gateworks.com> |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <linux/types.h> |
| 10 | #include <asm/arch/mx6-ddr.h> |
| 11 | #include <asm/arch/sys_proto.h> |
| 12 | #include <asm/io.h> |
| 13 | #include <asm/types.h> |
| 14 | |
Peng Fan | d9efd47 | 2014-12-30 17:24:01 +0800 | [diff] [blame] | 15 | #if defined(CONFIG_MX6SX) |
| 16 | /* Configure MX6SX mmdc iomux */ |
| 17 | void mx6sx_dram_iocfg(unsigned width, |
| 18 | const struct mx6sx_iomux_ddr_regs *ddr, |
| 19 | const struct mx6sx_iomux_grp_regs *grp) |
| 20 | { |
| 21 | struct mx6sx_iomux_ddr_regs *mx6_ddr_iomux; |
| 22 | struct mx6sx_iomux_grp_regs *mx6_grp_iomux; |
| 23 | |
| 24 | mx6_ddr_iomux = (struct mx6sx_iomux_ddr_regs *)MX6SX_IOM_DDR_BASE; |
| 25 | mx6_grp_iomux = (struct mx6sx_iomux_grp_regs *)MX6SX_IOM_GRP_BASE; |
| 26 | |
| 27 | /* DDR IO TYPE */ |
| 28 | writel(grp->grp_ddr_type, &mx6_grp_iomux->grp_ddr_type); |
| 29 | writel(grp->grp_ddrpke, &mx6_grp_iomux->grp_ddrpke); |
| 30 | |
| 31 | /* CLOCK */ |
| 32 | writel(ddr->dram_sdclk_0, &mx6_ddr_iomux->dram_sdclk_0); |
| 33 | |
| 34 | /* ADDRESS */ |
| 35 | writel(ddr->dram_cas, &mx6_ddr_iomux->dram_cas); |
| 36 | writel(ddr->dram_ras, &mx6_ddr_iomux->dram_ras); |
| 37 | writel(grp->grp_addds, &mx6_grp_iomux->grp_addds); |
| 38 | |
| 39 | /* Control */ |
| 40 | writel(ddr->dram_reset, &mx6_ddr_iomux->dram_reset); |
| 41 | writel(ddr->dram_sdba2, &mx6_ddr_iomux->dram_sdba2); |
| 42 | writel(ddr->dram_sdcke0, &mx6_ddr_iomux->dram_sdcke0); |
| 43 | writel(ddr->dram_sdcke1, &mx6_ddr_iomux->dram_sdcke1); |
| 44 | writel(ddr->dram_odt0, &mx6_ddr_iomux->dram_odt0); |
| 45 | writel(ddr->dram_odt1, &mx6_ddr_iomux->dram_odt1); |
| 46 | writel(grp->grp_ctlds, &mx6_grp_iomux->grp_ctlds); |
| 47 | |
| 48 | /* Data Strobes */ |
| 49 | writel(grp->grp_ddrmode_ctl, &mx6_grp_iomux->grp_ddrmode_ctl); |
| 50 | writel(ddr->dram_sdqs0, &mx6_ddr_iomux->dram_sdqs0); |
| 51 | writel(ddr->dram_sdqs1, &mx6_ddr_iomux->dram_sdqs1); |
| 52 | if (width >= 32) { |
| 53 | writel(ddr->dram_sdqs2, &mx6_ddr_iomux->dram_sdqs2); |
| 54 | writel(ddr->dram_sdqs3, &mx6_ddr_iomux->dram_sdqs3); |
| 55 | } |
| 56 | |
| 57 | /* Data */ |
| 58 | writel(grp->grp_ddrmode, &mx6_grp_iomux->grp_ddrmode); |
| 59 | writel(grp->grp_b0ds, &mx6_grp_iomux->grp_b0ds); |
| 60 | writel(grp->grp_b1ds, &mx6_grp_iomux->grp_b1ds); |
| 61 | if (width >= 32) { |
| 62 | writel(grp->grp_b2ds, &mx6_grp_iomux->grp_b2ds); |
| 63 | writel(grp->grp_b3ds, &mx6_grp_iomux->grp_b3ds); |
| 64 | } |
| 65 | writel(ddr->dram_dqm0, &mx6_ddr_iomux->dram_dqm0); |
| 66 | writel(ddr->dram_dqm1, &mx6_ddr_iomux->dram_dqm1); |
| 67 | if (width >= 32) { |
| 68 | writel(ddr->dram_dqm2, &mx6_ddr_iomux->dram_dqm2); |
| 69 | writel(ddr->dram_dqm3, &mx6_ddr_iomux->dram_dqm3); |
| 70 | } |
| 71 | } |
| 72 | #endif |
| 73 | |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 74 | #if defined(CONFIG_MX6QDL) || defined(CONFIG_MX6Q) || defined(CONFIG_MX6D) |
| 75 | /* Configure MX6DQ mmdc iomux */ |
| 76 | void mx6dq_dram_iocfg(unsigned width, |
| 77 | const struct mx6dq_iomux_ddr_regs *ddr, |
| 78 | const struct mx6dq_iomux_grp_regs *grp) |
| 79 | { |
| 80 | volatile struct mx6dq_iomux_ddr_regs *mx6_ddr_iomux; |
| 81 | volatile struct mx6dq_iomux_grp_regs *mx6_grp_iomux; |
| 82 | |
| 83 | mx6_ddr_iomux = (struct mx6dq_iomux_ddr_regs *)MX6DQ_IOM_DDR_BASE; |
| 84 | mx6_grp_iomux = (struct mx6dq_iomux_grp_regs *)MX6DQ_IOM_GRP_BASE; |
| 85 | |
| 86 | /* DDR IO Type */ |
| 87 | mx6_grp_iomux->grp_ddr_type = grp->grp_ddr_type; |
| 88 | mx6_grp_iomux->grp_ddrpke = grp->grp_ddrpke; |
| 89 | |
| 90 | /* Clock */ |
| 91 | mx6_ddr_iomux->dram_sdclk_0 = ddr->dram_sdclk_0; |
| 92 | mx6_ddr_iomux->dram_sdclk_1 = ddr->dram_sdclk_1; |
| 93 | |
| 94 | /* Address */ |
| 95 | mx6_ddr_iomux->dram_cas = ddr->dram_cas; |
| 96 | mx6_ddr_iomux->dram_ras = ddr->dram_ras; |
| 97 | mx6_grp_iomux->grp_addds = grp->grp_addds; |
| 98 | |
| 99 | /* Control */ |
| 100 | mx6_ddr_iomux->dram_reset = ddr->dram_reset; |
| 101 | mx6_ddr_iomux->dram_sdcke0 = ddr->dram_sdcke0; |
| 102 | mx6_ddr_iomux->dram_sdcke1 = ddr->dram_sdcke1; |
| 103 | mx6_ddr_iomux->dram_sdba2 = ddr->dram_sdba2; |
| 104 | mx6_ddr_iomux->dram_sdodt0 = ddr->dram_sdodt0; |
| 105 | mx6_ddr_iomux->dram_sdodt1 = ddr->dram_sdodt1; |
| 106 | mx6_grp_iomux->grp_ctlds = grp->grp_ctlds; |
| 107 | |
| 108 | /* Data Strobes */ |
| 109 | mx6_grp_iomux->grp_ddrmode_ctl = grp->grp_ddrmode_ctl; |
| 110 | mx6_ddr_iomux->dram_sdqs0 = ddr->dram_sdqs0; |
| 111 | mx6_ddr_iomux->dram_sdqs1 = ddr->dram_sdqs1; |
| 112 | if (width >= 32) { |
| 113 | mx6_ddr_iomux->dram_sdqs2 = ddr->dram_sdqs2; |
| 114 | mx6_ddr_iomux->dram_sdqs3 = ddr->dram_sdqs3; |
| 115 | } |
| 116 | if (width >= 64) { |
| 117 | mx6_ddr_iomux->dram_sdqs4 = ddr->dram_sdqs4; |
| 118 | mx6_ddr_iomux->dram_sdqs5 = ddr->dram_sdqs5; |
| 119 | mx6_ddr_iomux->dram_sdqs6 = ddr->dram_sdqs6; |
| 120 | mx6_ddr_iomux->dram_sdqs7 = ddr->dram_sdqs7; |
| 121 | } |
| 122 | |
| 123 | /* Data */ |
| 124 | mx6_grp_iomux->grp_ddrmode = grp->grp_ddrmode; |
| 125 | mx6_grp_iomux->grp_b0ds = grp->grp_b0ds; |
| 126 | mx6_grp_iomux->grp_b1ds = grp->grp_b1ds; |
| 127 | if (width >= 32) { |
| 128 | mx6_grp_iomux->grp_b2ds = grp->grp_b2ds; |
| 129 | mx6_grp_iomux->grp_b3ds = grp->grp_b3ds; |
| 130 | } |
| 131 | if (width >= 64) { |
| 132 | mx6_grp_iomux->grp_b4ds = grp->grp_b4ds; |
| 133 | mx6_grp_iomux->grp_b5ds = grp->grp_b5ds; |
| 134 | mx6_grp_iomux->grp_b6ds = grp->grp_b6ds; |
| 135 | mx6_grp_iomux->grp_b7ds = grp->grp_b7ds; |
| 136 | } |
| 137 | mx6_ddr_iomux->dram_dqm0 = ddr->dram_dqm0; |
| 138 | mx6_ddr_iomux->dram_dqm1 = ddr->dram_dqm1; |
| 139 | if (width >= 32) { |
| 140 | mx6_ddr_iomux->dram_dqm2 = ddr->dram_dqm2; |
| 141 | mx6_ddr_iomux->dram_dqm3 = ddr->dram_dqm3; |
| 142 | } |
| 143 | if (width >= 64) { |
| 144 | mx6_ddr_iomux->dram_dqm4 = ddr->dram_dqm4; |
| 145 | mx6_ddr_iomux->dram_dqm5 = ddr->dram_dqm5; |
| 146 | mx6_ddr_iomux->dram_dqm6 = ddr->dram_dqm6; |
| 147 | mx6_ddr_iomux->dram_dqm7 = ddr->dram_dqm7; |
| 148 | } |
| 149 | } |
| 150 | #endif |
| 151 | |
| 152 | #if defined(CONFIG_MX6QDL) || defined(CONFIG_MX6DL) || defined(CONFIG_MX6S) |
| 153 | /* Configure MX6SDL mmdc iomux */ |
| 154 | void mx6sdl_dram_iocfg(unsigned width, |
| 155 | const struct mx6sdl_iomux_ddr_regs *ddr, |
| 156 | const struct mx6sdl_iomux_grp_regs *grp) |
| 157 | { |
| 158 | volatile struct mx6sdl_iomux_ddr_regs *mx6_ddr_iomux; |
| 159 | volatile struct mx6sdl_iomux_grp_regs *mx6_grp_iomux; |
| 160 | |
| 161 | mx6_ddr_iomux = (struct mx6sdl_iomux_ddr_regs *)MX6SDL_IOM_DDR_BASE; |
| 162 | mx6_grp_iomux = (struct mx6sdl_iomux_grp_regs *)MX6SDL_IOM_GRP_BASE; |
| 163 | |
| 164 | /* DDR IO Type */ |
| 165 | mx6_grp_iomux->grp_ddr_type = grp->grp_ddr_type; |
| 166 | mx6_grp_iomux->grp_ddrpke = grp->grp_ddrpke; |
| 167 | |
| 168 | /* Clock */ |
| 169 | mx6_ddr_iomux->dram_sdclk_0 = ddr->dram_sdclk_0; |
| 170 | mx6_ddr_iomux->dram_sdclk_1 = ddr->dram_sdclk_1; |
| 171 | |
| 172 | /* Address */ |
| 173 | mx6_ddr_iomux->dram_cas = ddr->dram_cas; |
| 174 | mx6_ddr_iomux->dram_ras = ddr->dram_ras; |
| 175 | mx6_grp_iomux->grp_addds = grp->grp_addds; |
| 176 | |
| 177 | /* Control */ |
| 178 | mx6_ddr_iomux->dram_reset = ddr->dram_reset; |
| 179 | mx6_ddr_iomux->dram_sdcke0 = ddr->dram_sdcke0; |
| 180 | mx6_ddr_iomux->dram_sdcke1 = ddr->dram_sdcke1; |
| 181 | mx6_ddr_iomux->dram_sdba2 = ddr->dram_sdba2; |
| 182 | mx6_ddr_iomux->dram_sdodt0 = ddr->dram_sdodt0; |
| 183 | mx6_ddr_iomux->dram_sdodt1 = ddr->dram_sdodt1; |
| 184 | mx6_grp_iomux->grp_ctlds = grp->grp_ctlds; |
| 185 | |
| 186 | /* Data Strobes */ |
| 187 | mx6_grp_iomux->grp_ddrmode_ctl = grp->grp_ddrmode_ctl; |
| 188 | mx6_ddr_iomux->dram_sdqs0 = ddr->dram_sdqs0; |
| 189 | mx6_ddr_iomux->dram_sdqs1 = ddr->dram_sdqs1; |
| 190 | if (width >= 32) { |
| 191 | mx6_ddr_iomux->dram_sdqs2 = ddr->dram_sdqs2; |
| 192 | mx6_ddr_iomux->dram_sdqs3 = ddr->dram_sdqs3; |
| 193 | } |
| 194 | if (width >= 64) { |
| 195 | mx6_ddr_iomux->dram_sdqs4 = ddr->dram_sdqs4; |
| 196 | mx6_ddr_iomux->dram_sdqs5 = ddr->dram_sdqs5; |
| 197 | mx6_ddr_iomux->dram_sdqs6 = ddr->dram_sdqs6; |
| 198 | mx6_ddr_iomux->dram_sdqs7 = ddr->dram_sdqs7; |
| 199 | } |
| 200 | |
| 201 | /* Data */ |
| 202 | mx6_grp_iomux->grp_ddrmode = grp->grp_ddrmode; |
| 203 | mx6_grp_iomux->grp_b0ds = grp->grp_b0ds; |
| 204 | mx6_grp_iomux->grp_b1ds = grp->grp_b1ds; |
| 205 | if (width >= 32) { |
| 206 | mx6_grp_iomux->grp_b2ds = grp->grp_b2ds; |
| 207 | mx6_grp_iomux->grp_b3ds = grp->grp_b3ds; |
| 208 | } |
| 209 | if (width >= 64) { |
| 210 | mx6_grp_iomux->grp_b4ds = grp->grp_b4ds; |
| 211 | mx6_grp_iomux->grp_b5ds = grp->grp_b5ds; |
| 212 | mx6_grp_iomux->grp_b6ds = grp->grp_b6ds; |
| 213 | mx6_grp_iomux->grp_b7ds = grp->grp_b7ds; |
| 214 | } |
| 215 | mx6_ddr_iomux->dram_dqm0 = ddr->dram_dqm0; |
| 216 | mx6_ddr_iomux->dram_dqm1 = ddr->dram_dqm1; |
| 217 | if (width >= 32) { |
| 218 | mx6_ddr_iomux->dram_dqm2 = ddr->dram_dqm2; |
| 219 | mx6_ddr_iomux->dram_dqm3 = ddr->dram_dqm3; |
| 220 | } |
| 221 | if (width >= 64) { |
| 222 | mx6_ddr_iomux->dram_dqm4 = ddr->dram_dqm4; |
| 223 | mx6_ddr_iomux->dram_dqm5 = ddr->dram_dqm5; |
| 224 | mx6_ddr_iomux->dram_dqm6 = ddr->dram_dqm6; |
| 225 | mx6_ddr_iomux->dram_dqm7 = ddr->dram_dqm7; |
| 226 | } |
| 227 | } |
| 228 | #endif |
| 229 | |
| 230 | /* |
| 231 | * Configure mx6 mmdc registers based on: |
| 232 | * - board-specific memory configuration |
| 233 | * - board-specific calibration data |
| 234 | * - ddr3 chip details |
| 235 | * |
| 236 | * The various calculations here are derived from the Freescale |
| 237 | * i.Mx6DQSDL DDR3 Script Aid spreadsheet (DOC-94917) designed to generate MMDC |
| 238 | * configuration registers based on memory system and memory chip parameters. |
| 239 | * |
| 240 | * The defaults here are those which were specified in the spreadsheet. |
| 241 | * For details on each register, refer to the IMX6DQRM and/or IMX6SDLRM |
| 242 | * section titled MMDC initialization |
| 243 | */ |
| 244 | #define MR(val, ba, cmd, cs1) \ |
| 245 | ((val << 16) | (1 << 15) | (cmd << 4) | (cs1 << 3) | ba) |
Peng Fan | d9efd47 | 2014-12-30 17:24:01 +0800 | [diff] [blame] | 246 | #ifdef CONFIG_MX6SX |
| 247 | #define MMDC1(entry, value) do {} while (0) |
| 248 | #else |
| 249 | #define MMDC1(entry, value) do { mmdc1->entry = value; } while (0) |
| 250 | #endif |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 251 | void mx6_dram_cfg(const struct mx6_ddr_sysinfo *sysinfo, |
| 252 | const struct mx6_mmdc_calibration *calib, |
| 253 | const struct mx6_ddr3_cfg *ddr3_cfg) |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 254 | { |
| 255 | volatile struct mmdc_p_regs *mmdc0; |
Peng Fan | d9efd47 | 2014-12-30 17:24:01 +0800 | [diff] [blame] | 256 | #ifndef CONFIG_MX6SX |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 257 | volatile struct mmdc_p_regs *mmdc1; |
Peng Fan | d9efd47 | 2014-12-30 17:24:01 +0800 | [diff] [blame] | 258 | #endif |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 259 | u32 val; |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 260 | u8 tcke, tcksrx, tcksre, txpdll, taofpd, taonpd, trrd; |
| 261 | u8 todtlon, taxpd, tanpd, tcwl, txp, tfaw, tcl; |
| 262 | u8 todt_idle_off = 0x4; /* from DDR3 Script Aid spreadsheet */ |
| 263 | u16 trcd, trc, tras, twr, tmrd, trtp, trp, twtr, trfc, txs, txpr; |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 264 | u16 cs0_end; |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 265 | u16 tdllk = 0x1ff; /* DLL locking time: 512 cycles (JEDEC DDR3) */ |
Marek Vasut | b299ab7 | 2014-08-04 01:47:10 +0200 | [diff] [blame] | 266 | u8 coladdr; |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 267 | int clkper; /* clock period in picoseconds */ |
Nikolay Dimitrov | 8a2bd21 | 2015-04-22 18:37:31 +0300 | [diff] [blame^] | 268 | int clock; /* clock freq in MHz */ |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 269 | int cs; |
Nikolay Dimitrov | 8a2bd21 | 2015-04-22 18:37:31 +0300 | [diff] [blame^] | 270 | u16 mem_speed = ddr3_cfg->mem_speed; |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 271 | |
| 272 | mmdc0 = (struct mmdc_p_regs *)MMDC_P0_BASE_ADDR; |
Peng Fan | d9efd47 | 2014-12-30 17:24:01 +0800 | [diff] [blame] | 273 | #ifndef CONFIG_MX6SX |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 274 | mmdc1 = (struct mmdc_p_regs *)MMDC_P1_BASE_ADDR; |
Peng Fan | d9efd47 | 2014-12-30 17:24:01 +0800 | [diff] [blame] | 275 | #endif |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 276 | |
Nikolay Dimitrov | 8a2bd21 | 2015-04-22 18:37:31 +0300 | [diff] [blame^] | 277 | /* Limit mem_speed for MX6D/MX6Q */ |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 278 | if (is_cpu_type(MXC_CPU_MX6Q) || is_cpu_type(MXC_CPU_MX6D)) { |
Nikolay Dimitrov | 8a2bd21 | 2015-04-22 18:37:31 +0300 | [diff] [blame^] | 279 | if (mem_speed > 1066) |
| 280 | mem_speed = 1066; /* 1066 MT/s */ |
| 281 | |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 282 | tcwl = 4; |
| 283 | } |
Nikolay Dimitrov | 8a2bd21 | 2015-04-22 18:37:31 +0300 | [diff] [blame^] | 284 | /* Limit mem_speed for MX6S/MX6DL */ |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 285 | else { |
Nikolay Dimitrov | 8a2bd21 | 2015-04-22 18:37:31 +0300 | [diff] [blame^] | 286 | if (mem_speed > 800) |
| 287 | mem_speed = 800; /* 800 MT/s */ |
| 288 | |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 289 | tcwl = 3; |
| 290 | } |
Nikolay Dimitrov | 8a2bd21 | 2015-04-22 18:37:31 +0300 | [diff] [blame^] | 291 | |
| 292 | clock = mem_speed / 2; |
| 293 | /* |
| 294 | * Data rate of 1066 MT/s requires 533 MHz DDR3 clock, but MX6D/Q supports |
| 295 | * up to 528 MHz, so reduce the clock to fit chip specs |
| 296 | */ |
| 297 | if (is_cpu_type(MXC_CPU_MX6Q) || is_cpu_type(MXC_CPU_MX6D)) { |
| 298 | if (clock > 528) |
| 299 | clock = 528; /* 528 MHz */ |
| 300 | } |
| 301 | |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 302 | clkper = (1000 * 1000) / clock; /* pico seconds */ |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 303 | todtlon = tcwl; |
| 304 | taxpd = tcwl; |
| 305 | tanpd = tcwl; |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 306 | |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 307 | switch (ddr3_cfg->density) { |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 308 | case 1: /* 1Gb per chip */ |
| 309 | trfc = DIV_ROUND_UP(110000, clkper) - 1; |
| 310 | txs = DIV_ROUND_UP(120000, clkper) - 1; |
| 311 | break; |
| 312 | case 2: /* 2Gb per chip */ |
| 313 | trfc = DIV_ROUND_UP(160000, clkper) - 1; |
| 314 | txs = DIV_ROUND_UP(170000, clkper) - 1; |
| 315 | break; |
| 316 | case 4: /* 4Gb per chip */ |
| 317 | trfc = DIV_ROUND_UP(260000, clkper) - 1; |
| 318 | txs = DIV_ROUND_UP(270000, clkper) - 1; |
| 319 | break; |
| 320 | case 8: /* 8Gb per chip */ |
| 321 | trfc = DIV_ROUND_UP(350000, clkper) - 1; |
| 322 | txs = DIV_ROUND_UP(360000, clkper) - 1; |
| 323 | break; |
| 324 | default: |
| 325 | /* invalid density */ |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 326 | puts("invalid chip density\n"); |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 327 | hang(); |
| 328 | break; |
| 329 | } |
| 330 | txpr = txs; |
| 331 | |
Nikolay Dimitrov | 8a2bd21 | 2015-04-22 18:37:31 +0300 | [diff] [blame^] | 332 | switch (mem_speed) { |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 333 | case 800: |
Masahiro Yamada | c79cba3 | 2014-09-18 13:28:06 +0900 | [diff] [blame] | 334 | txp = DIV_ROUND_UP(max(3 * clkper, 7500), clkper) - 1; |
| 335 | tcke = DIV_ROUND_UP(max(3 * clkper, 7500), clkper) - 1; |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 336 | if (ddr3_cfg->pagesz == 1) { |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 337 | tfaw = DIV_ROUND_UP(40000, clkper) - 1; |
Masahiro Yamada | c79cba3 | 2014-09-18 13:28:06 +0900 | [diff] [blame] | 338 | trrd = DIV_ROUND_UP(max(4 * clkper, 10000), clkper) - 1; |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 339 | } else { |
| 340 | tfaw = DIV_ROUND_UP(50000, clkper) - 1; |
Masahiro Yamada | c79cba3 | 2014-09-18 13:28:06 +0900 | [diff] [blame] | 341 | trrd = DIV_ROUND_UP(max(4 * clkper, 10000), clkper) - 1; |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 342 | } |
| 343 | break; |
| 344 | case 1066: |
Masahiro Yamada | c79cba3 | 2014-09-18 13:28:06 +0900 | [diff] [blame] | 345 | txp = DIV_ROUND_UP(max(3 * clkper, 7500), clkper) - 1; |
| 346 | tcke = DIV_ROUND_UP(max(3 * clkper, 5625), clkper) - 1; |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 347 | if (ddr3_cfg->pagesz == 1) { |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 348 | tfaw = DIV_ROUND_UP(37500, clkper) - 1; |
Masahiro Yamada | c79cba3 | 2014-09-18 13:28:06 +0900 | [diff] [blame] | 349 | trrd = DIV_ROUND_UP(max(4 * clkper, 7500), clkper) - 1; |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 350 | } else { |
| 351 | tfaw = DIV_ROUND_UP(50000, clkper) - 1; |
Masahiro Yamada | c79cba3 | 2014-09-18 13:28:06 +0900 | [diff] [blame] | 352 | trrd = DIV_ROUND_UP(max(4 * clkper, 10000), clkper) - 1; |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 353 | } |
| 354 | break; |
| 355 | case 1333: |
Masahiro Yamada | c79cba3 | 2014-09-18 13:28:06 +0900 | [diff] [blame] | 356 | txp = DIV_ROUND_UP(max(3 * clkper, 6000), clkper) - 1; |
| 357 | tcke = DIV_ROUND_UP(max(3 * clkper, 5625), clkper) - 1; |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 358 | if (ddr3_cfg->pagesz == 1) { |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 359 | tfaw = DIV_ROUND_UP(30000, clkper) - 1; |
Masahiro Yamada | c79cba3 | 2014-09-18 13:28:06 +0900 | [diff] [blame] | 360 | trrd = DIV_ROUND_UP(max(4 * clkper, 6000), clkper) - 1; |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 361 | } else { |
| 362 | tfaw = DIV_ROUND_UP(45000, clkper) - 1; |
Masahiro Yamada | c79cba3 | 2014-09-18 13:28:06 +0900 | [diff] [blame] | 363 | trrd = DIV_ROUND_UP(max(4 * clkper, 7500), clkper) - 1; |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 364 | } |
| 365 | break; |
| 366 | case 1600: |
Masahiro Yamada | c79cba3 | 2014-09-18 13:28:06 +0900 | [diff] [blame] | 367 | txp = DIV_ROUND_UP(max(3 * clkper, 6000), clkper) - 1; |
| 368 | tcke = DIV_ROUND_UP(max(3 * clkper, 5000), clkper) - 1; |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 369 | if (ddr3_cfg->pagesz == 1) { |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 370 | tfaw = DIV_ROUND_UP(30000, clkper) - 1; |
Masahiro Yamada | c79cba3 | 2014-09-18 13:28:06 +0900 | [diff] [blame] | 371 | trrd = DIV_ROUND_UP(max(4 * clkper, 6000), clkper) - 1; |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 372 | } else { |
| 373 | tfaw = DIV_ROUND_UP(40000, clkper) - 1; |
Masahiro Yamada | c79cba3 | 2014-09-18 13:28:06 +0900 | [diff] [blame] | 374 | trrd = DIV_ROUND_UP(max(4 * clkper, 7500), clkper) - 1; |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 375 | } |
| 376 | break; |
| 377 | default: |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 378 | puts("invalid memory speed\n"); |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 379 | hang(); |
| 380 | break; |
| 381 | } |
Masahiro Yamada | c79cba3 | 2014-09-18 13:28:06 +0900 | [diff] [blame] | 382 | txpdll = DIV_ROUND_UP(max(10 * clkper, 24000), clkper) - 1; |
| 383 | tcksre = DIV_ROUND_UP(max(5 * clkper, 10000), clkper); |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 384 | taonpd = DIV_ROUND_UP(2000, clkper) - 1; |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 385 | tcksrx = tcksre; |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 386 | taofpd = taonpd; |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 387 | twr = DIV_ROUND_UP(15000, clkper) - 1; |
Masahiro Yamada | c79cba3 | 2014-09-18 13:28:06 +0900 | [diff] [blame] | 388 | tmrd = DIV_ROUND_UP(max(12 * clkper, 15000), clkper) - 1; |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 389 | trc = DIV_ROUND_UP(ddr3_cfg->trcmin, clkper / 10) - 1; |
| 390 | tras = DIV_ROUND_UP(ddr3_cfg->trasmin, clkper / 10) - 1; |
| 391 | tcl = DIV_ROUND_UP(ddr3_cfg->trcd, clkper / 10) - 3; |
| 392 | trp = DIV_ROUND_UP(ddr3_cfg->trcd, clkper / 10) - 1; |
Masahiro Yamada | c79cba3 | 2014-09-18 13:28:06 +0900 | [diff] [blame] | 393 | twtr = ROUND(max(4 * clkper, 7500) / clkper, 1) - 1; |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 394 | trcd = trp; |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 395 | trtp = twtr; |
Nikita Kiryanov | 07ee927 | 2014-08-20 15:08:58 +0300 | [diff] [blame] | 396 | cs0_end = 4 * sysinfo->cs_density - 1; |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 397 | |
| 398 | debug("density:%d Gb (%d Gb per chip)\n", |
| 399 | sysinfo->cs_density, ddr3_cfg->density); |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 400 | debug("clock: %dMHz (%d ps)\n", clock, clkper); |
Nikolay Dimitrov | 8a2bd21 | 2015-04-22 18:37:31 +0300 | [diff] [blame^] | 401 | debug("memspd:%d\n", mem_speed); |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 402 | debug("tcke=%d\n", tcke); |
| 403 | debug("tcksrx=%d\n", tcksrx); |
| 404 | debug("tcksre=%d\n", tcksre); |
| 405 | debug("taofpd=%d\n", taofpd); |
| 406 | debug("taonpd=%d\n", taonpd); |
| 407 | debug("todtlon=%d\n", todtlon); |
| 408 | debug("tanpd=%d\n", tanpd); |
| 409 | debug("taxpd=%d\n", taxpd); |
| 410 | debug("trfc=%d\n", trfc); |
| 411 | debug("txs=%d\n", txs); |
| 412 | debug("txp=%d\n", txp); |
| 413 | debug("txpdll=%d\n", txpdll); |
| 414 | debug("tfaw=%d\n", tfaw); |
| 415 | debug("tcl=%d\n", tcl); |
| 416 | debug("trcd=%d\n", trcd); |
| 417 | debug("trp=%d\n", trp); |
| 418 | debug("trc=%d\n", trc); |
| 419 | debug("tras=%d\n", tras); |
| 420 | debug("twr=%d\n", twr); |
| 421 | debug("tmrd=%d\n", tmrd); |
| 422 | debug("tcwl=%d\n", tcwl); |
| 423 | debug("tdllk=%d\n", tdllk); |
| 424 | debug("trtp=%d\n", trtp); |
| 425 | debug("twtr=%d\n", twtr); |
| 426 | debug("trrd=%d\n", trrd); |
| 427 | debug("txpr=%d\n", txpr); |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 428 | debug("cs0_end=%d\n", cs0_end); |
| 429 | debug("ncs=%d\n", sysinfo->ncs); |
| 430 | debug("Rtt_wr=%d\n", sysinfo->rtt_wr); |
| 431 | debug("Rtt_nom=%d\n", sysinfo->rtt_nom); |
| 432 | debug("SRT=%d\n", ddr3_cfg->SRT); |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 433 | debug("tcl=%d\n", tcl); |
| 434 | debug("twr=%d\n", twr); |
| 435 | |
| 436 | /* |
| 437 | * board-specific configuration: |
| 438 | * These values are determined empirically and vary per board layout |
| 439 | * see: |
| 440 | * appnote, ddr3 spreadsheet |
| 441 | */ |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 442 | mmdc0->mpwldectrl0 = calib->p0_mpwldectrl0; |
| 443 | mmdc0->mpwldectrl1 = calib->p0_mpwldectrl1; |
| 444 | mmdc0->mpdgctrl0 = calib->p0_mpdgctrl0; |
| 445 | mmdc0->mpdgctrl1 = calib->p0_mpdgctrl1; |
| 446 | mmdc0->mprddlctl = calib->p0_mprddlctl; |
| 447 | mmdc0->mpwrdlctl = calib->p0_mpwrdlctl; |
| 448 | if (sysinfo->dsize > 1) { |
Peng Fan | d9efd47 | 2014-12-30 17:24:01 +0800 | [diff] [blame] | 449 | MMDC1(mpwldectrl0, calib->p1_mpwldectrl0); |
| 450 | MMDC1(mpwldectrl1, calib->p1_mpwldectrl1); |
| 451 | MMDC1(mpdgctrl0, calib->p1_mpdgctrl0); |
| 452 | MMDC1(mpdgctrl1, calib->p1_mpdgctrl1); |
| 453 | MMDC1(mprddlctl, calib->p1_mprddlctl); |
| 454 | MMDC1(mpwrdlctl, calib->p1_mpwrdlctl); |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | /* Read data DQ Byte0-3 delay */ |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 458 | mmdc0->mprddqby0dl = 0x33333333; |
| 459 | mmdc0->mprddqby1dl = 0x33333333; |
| 460 | if (sysinfo->dsize > 0) { |
| 461 | mmdc0->mprddqby2dl = 0x33333333; |
| 462 | mmdc0->mprddqby3dl = 0x33333333; |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 463 | } |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 464 | |
| 465 | if (sysinfo->dsize > 1) { |
Peng Fan | d9efd47 | 2014-12-30 17:24:01 +0800 | [diff] [blame] | 466 | MMDC1(mprddqby0dl, 0x33333333); |
| 467 | MMDC1(mprddqby1dl, 0x33333333); |
| 468 | MMDC1(mprddqby2dl, 0x33333333); |
| 469 | MMDC1(mprddqby3dl, 0x33333333); |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | /* MMDC Termination: rtt_nom:2 RZQ/2(120ohm), rtt_nom:1 RZQ/4(60ohm) */ |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 473 | val = (sysinfo->rtt_nom == 2) ? 0x00011117 : 0x00022227; |
| 474 | mmdc0->mpodtctrl = val; |
| 475 | if (sysinfo->dsize > 1) |
Peng Fan | d9efd47 | 2014-12-30 17:24:01 +0800 | [diff] [blame] | 476 | MMDC1(mpodtctrl, val); |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 477 | |
| 478 | /* complete calibration */ |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 479 | val = (1 << 11); /* Force measurement on delay-lines */ |
| 480 | mmdc0->mpmur0 = val; |
| 481 | if (sysinfo->dsize > 1) |
Peng Fan | d9efd47 | 2014-12-30 17:24:01 +0800 | [diff] [blame] | 482 | MMDC1(mpmur0, val); |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 483 | |
| 484 | /* Step 1: configuration request */ |
| 485 | mmdc0->mdscr = (u32)(1 << 15); /* config request */ |
| 486 | |
| 487 | /* Step 2: Timing configuration */ |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 488 | mmdc0->mdcfg0 = (trfc << 24) | (txs << 16) | (txp << 13) | |
| 489 | (txpdll << 9) | (tfaw << 4) | tcl; |
| 490 | mmdc0->mdcfg1 = (trcd << 29) | (trp << 26) | (trc << 21) | |
| 491 | (tras << 16) | (1 << 15) /* trpa */ | |
| 492 | (twr << 9) | (tmrd << 5) | tcwl; |
| 493 | mmdc0->mdcfg2 = (tdllk << 16) | (trtp << 6) | (twtr << 3) | trrd; |
| 494 | mmdc0->mdotc = (taofpd << 27) | (taonpd << 24) | (tanpd << 20) | |
| 495 | (taxpd << 16) | (todtlon << 12) | (todt_idle_off << 4); |
| 496 | mmdc0->mdasp = cs0_end; /* CS addressing */ |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 497 | |
| 498 | /* Step 3: Configure DDR type */ |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 499 | mmdc0->mdmisc = (sysinfo->cs1_mirror << 19) | (sysinfo->walat << 16) | |
| 500 | (sysinfo->bi_on << 12) | (sysinfo->mif3_mode << 9) | |
| 501 | (sysinfo->ralat << 6); |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 502 | |
| 503 | /* Step 4: Configure delay while leaving reset */ |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 504 | mmdc0->mdor = (txpr << 16) | (sysinfo->sde_to_rst << 8) | |
| 505 | (sysinfo->rst_to_cke << 0); |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 506 | |
| 507 | /* Step 5: Configure DDR physical parameters (density and burst len) */ |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 508 | coladdr = ddr3_cfg->coladdr; |
| 509 | if (ddr3_cfg->coladdr == 8) /* 8-bit COL is 0x3 */ |
Marek Vasut | b299ab7 | 2014-08-04 01:47:10 +0200 | [diff] [blame] | 510 | coladdr += 4; |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 511 | else if (ddr3_cfg->coladdr == 12) /* 12-bit COL is 0x4 */ |
Marek Vasut | b299ab7 | 2014-08-04 01:47:10 +0200 | [diff] [blame] | 512 | coladdr += 1; |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 513 | mmdc0->mdctl = (ddr3_cfg->rowaddr - 11) << 24 | /* ROW */ |
| 514 | (coladdr - 9) << 20 | /* COL */ |
| 515 | (1 << 19) | /* Burst Length = 8 for DDR3 */ |
| 516 | (sysinfo->dsize << 16); /* DDR data bus size */ |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 517 | |
| 518 | /* Step 6: Perform ZQ calibration */ |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 519 | val = 0xa1390001; /* one-time HW ZQ calib */ |
| 520 | mmdc0->mpzqhwctrl = val; |
| 521 | if (sysinfo->dsize > 1) |
Peng Fan | d9efd47 | 2014-12-30 17:24:01 +0800 | [diff] [blame] | 522 | MMDC1(mpzqhwctrl, val); |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 523 | |
| 524 | /* Step 7: Enable MMDC with desired chip select */ |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 525 | mmdc0->mdctl |= (1 << 31) | /* SDE_0 for CS0 */ |
| 526 | ((sysinfo->ncs == 2) ? 1 : 0) << 30; /* SDE_1 for CS1 */ |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 527 | |
| 528 | /* Step 8: Write Mode Registers to Init DDR3 devices */ |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 529 | for (cs = 0; cs < sysinfo->ncs; cs++) { |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 530 | /* MR2 */ |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 531 | val = (sysinfo->rtt_wr & 3) << 9 | (ddr3_cfg->SRT & 1) << 7 | |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 532 | ((tcwl - 3) & 3) << 3; |
Tim Harvey | 78c5a18 | 2015-04-03 16:52:52 -0700 | [diff] [blame] | 533 | debug("MR2 CS%d: 0x%08x\n", cs, (u32)MR(val, 2, 3, cs)); |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 534 | mmdc0->mdscr = MR(val, 2, 3, cs); |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 535 | /* MR3 */ |
Tim Harvey | 78c5a18 | 2015-04-03 16:52:52 -0700 | [diff] [blame] | 536 | debug("MR3 CS%d: 0x%08x\n", cs, (u32)MR(0, 3, 3, cs)); |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 537 | mmdc0->mdscr = MR(0, 3, 3, cs); |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 538 | /* MR1 */ |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 539 | val = ((sysinfo->rtt_nom & 1) ? 1 : 0) << 2 | |
| 540 | ((sysinfo->rtt_nom & 2) ? 1 : 0) << 6; |
Tim Harvey | 78c5a18 | 2015-04-03 16:52:52 -0700 | [diff] [blame] | 541 | debug("MR1 CS%d: 0x%08x\n", cs, (u32)MR(val, 1, 3, cs)); |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 542 | mmdc0->mdscr = MR(val, 1, 3, cs); |
| 543 | /* MR0 */ |
| 544 | val = ((tcl - 1) << 4) | /* CAS */ |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 545 | (1 << 8) | /* DLL Reset */ |
| 546 | ((twr - 3) << 9); /* Write Recovery */ |
Tim Harvey | 78c5a18 | 2015-04-03 16:52:52 -0700 | [diff] [blame] | 547 | debug("MR0 CS%d: 0x%08x\n", cs, (u32)MR(val, 0, 3, cs)); |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 548 | mmdc0->mdscr = MR(val, 0, 3, cs); |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 549 | /* ZQ calibration */ |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 550 | val = (1 << 10); |
| 551 | mmdc0->mdscr = MR(val, 0, 4, cs); |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | /* Step 10: Power down control and self-refresh */ |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 555 | mmdc0->mdpdc = (tcke & 0x7) << 16 | |
| 556 | 5 << 12 | /* PWDT_1: 256 cycles */ |
| 557 | 5 << 8 | /* PWDT_0: 256 cycles */ |
| 558 | 1 << 6 | /* BOTH_CS_PD */ |
| 559 | (tcksrx & 0x7) << 3 | |
| 560 | (tcksre & 0x7); |
Tim Harvey | 78c5a18 | 2015-04-03 16:52:52 -0700 | [diff] [blame] | 561 | if (!sysinfo->pd_fast_exit) |
| 562 | mmdc0->mdpdc |= (1 << 7); /* SLOW_PD */ |
Nikita Kiryanov | 06a51b8 | 2014-08-20 15:08:56 +0300 | [diff] [blame] | 563 | mmdc0->mapsr = 0x00001006; /* ADOPT power down enabled */ |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 564 | |
| 565 | /* Step 11: Configure ZQ calibration: one-time and periodic 1ms */ |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 566 | val = 0xa1390003; |
| 567 | mmdc0->mpzqhwctrl = val; |
| 568 | if (sysinfo->dsize > 1) |
Peng Fan | d9efd47 | 2014-12-30 17:24:01 +0800 | [diff] [blame] | 569 | MMDC1(mpzqhwctrl, val); |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 570 | |
| 571 | /* Step 12: Configure and activate periodic refresh */ |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 572 | mmdc0->mdref = (1 << 14) | /* REF_SEL: Periodic refresh cycle: 32kHz */ |
| 573 | (7 << 11); /* REFR: Refresh Rate - 8 refreshes */ |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 574 | |
| 575 | /* Step 13: Deassert config request - init complete */ |
Nikita Kiryanov | 3368918 | 2014-09-07 18:58:11 +0300 | [diff] [blame] | 576 | mmdc0->mdscr = 0x00000000; |
Tim Harvey | fe0f7f7 | 2014-06-02 16:13:23 -0700 | [diff] [blame] | 577 | |
| 578 | /* wait for auto-ZQ calibration to complete */ |
| 579 | mdelay(1); |
| 580 | } |