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