1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2014-2020, NVIDIA CORPORATION. All rights reserved.
6 #include <linux/kernel.h>
9 #include <linux/delay.h>
12 #include <soc/tegra/mc.h>
14 #include "tegra210-emc.h"
15 #include "tegra210-mc.h"
18 * Enable flags for specifying verbosity.
21 #define STEPS (1 << 1)
22 #define SUB_STEPS (1 << 2)
23 #define PRELOCK (1 << 3)
24 #define PRELOCK_STEPS (1 << 4)
25 #define ACTIVE_EN (1 << 5)
26 #define PRAMP_UP (1 << 6)
27 #define PRAMP_DN (1 << 7)
28 #define EMA_WRITES (1 << 10)
29 #define EMA_UPDATES (1 << 11)
30 #define PER_TRAIN (1 << 16)
31 #define CC_PRINT (1 << 17)
32 #define CCFIFO (1 << 29)
33 #define REGS (1 << 30)
34 #define REG_LISTS (1 << 31)
36 #define emc_dbg(emc, flags, ...) dev_dbg(emc->dev, __VA_ARGS__)
38 #define DVFS_CLOCK_CHANGE_VERSION 21021
39 #define EMC_PRELOCK_VERSION 2101
43 WRITE_TRAINING_SEQUENCE = 2,
44 PERIODIC_TRAINING_SEQUENCE = 3,
49 PERIODIC_TRAINING_UPDATE = 14
53 * PTFV defines - basically just indexes into the per table PTFV array.
55 #define PTFV_DQSOSC_MOVAVG_C0D0U0_INDEX 0
56 #define PTFV_DQSOSC_MOVAVG_C0D0U1_INDEX 1
57 #define PTFV_DQSOSC_MOVAVG_C0D1U0_INDEX 2
58 #define PTFV_DQSOSC_MOVAVG_C0D1U1_INDEX 3
59 #define PTFV_DQSOSC_MOVAVG_C1D0U0_INDEX 4
60 #define PTFV_DQSOSC_MOVAVG_C1D0U1_INDEX 5
61 #define PTFV_DQSOSC_MOVAVG_C1D1U0_INDEX 6
62 #define PTFV_DQSOSC_MOVAVG_C1D1U1_INDEX 7
63 #define PTFV_DVFS_SAMPLES_INDEX 9
64 #define PTFV_MOVAVG_WEIGHT_INDEX 10
65 #define PTFV_CONFIG_CTRL_INDEX 11
67 #define PTFV_CONFIG_CTRL_USE_PREVIOUS_EMA (1 << 0)
70 * Do arithmetic in fixed point.
72 #define MOVAVG_PRECISION_FACTOR 100
75 * The division portion of the average operation.
77 #define __AVERAGE_PTFV(dev) \
78 ({ next->ptfv_list[PTFV_DQSOSC_MOVAVG_ ## dev ## _INDEX] = \
79 next->ptfv_list[PTFV_DQSOSC_MOVAVG_ ## dev ## _INDEX] / \
80 next->ptfv_list[PTFV_DVFS_SAMPLES_INDEX]; })
83 * Convert val to fixed point and add it to the temporary average.
85 #define __INCREMENT_PTFV(dev, val) \
86 ({ next->ptfv_list[PTFV_DQSOSC_MOVAVG_ ## dev ## _INDEX] += \
87 ((val) * MOVAVG_PRECISION_FACTOR); })
90 * Convert a moving average back to integral form and return the value.
92 #define __MOVAVG_AC(timing, dev) \
93 ((timing)->ptfv_list[PTFV_DQSOSC_MOVAVG_ ## dev ## _INDEX] / \
94 MOVAVG_PRECISION_FACTOR)
96 /* Weighted update. */
97 #define __WEIGHTED_UPDATE_PTFV(dev, nval) \
99 int w = PTFV_MOVAVG_WEIGHT_INDEX; \
100 int dqs = PTFV_DQSOSC_MOVAVG_ ## dev ## _INDEX; \
102 next->ptfv_list[dqs] = \
103 ((nval * MOVAVG_PRECISION_FACTOR) + \
104 (next->ptfv_list[dqs] * \
105 next->ptfv_list[w])) / \
106 (next->ptfv_list[w] + 1); \
108 emc_dbg(emc, EMA_UPDATES, "%s: (s=%lu) EMA: %u\n", \
109 __stringify(dev), nval, next->ptfv_list[dqs]); \
112 /* Access a particular average. */
113 #define __MOVAVG(timing, dev) \
114 ((timing)->ptfv_list[PTFV_DQSOSC_MOVAVG_ ## dev ## _INDEX])
116 static u32 update_clock_tree_delay(struct tegra210_emc *emc, int type)
118 bool periodic_training_update = type == PERIODIC_TRAINING_UPDATE;
119 struct tegra210_emc_timing *last = emc->last;
120 struct tegra210_emc_timing *next = emc->next;
121 u32 last_timing_rate_mhz = last->rate / 1000;
122 u32 next_timing_rate_mhz = next->rate / 1000;
123 bool dvfs_update = type == DVFS_UPDATE;
124 s32 tdel = 0, tmdel = 0, adel = 0;
125 bool dvfs_pt1 = type == DVFS_PT1;
126 unsigned long cval = 0;
127 u32 temp[2][2], value;
133 if (dvfs_pt1 || periodic_training_update) {
134 value = tegra210_emc_mrr_read(emc, 2, 19);
136 for (i = 0; i < emc->num_channels; i++) {
137 temp[i][0] = (value & 0x00ff) << 8;
138 temp[i][1] = (value & 0xff00) << 0;
145 value = tegra210_emc_mrr_read(emc, 2, 18);
147 for (i = 0; i < emc->num_channels; i++) {
148 temp[i][0] |= (value & 0x00ff) >> 0;
149 temp[i][1] |= (value & 0xff00) >> 8;
154 if (dvfs_pt1 || periodic_training_update) {
155 cval = tegra210_emc_actual_osc_clocks(last->run_clocks);
157 cval /= last_timing_rate_mhz * 2 * temp[0][0];
161 __INCREMENT_PTFV(C0D0U0, cval);
162 else if (dvfs_update)
163 __AVERAGE_PTFV(C0D0U0);
164 else if (periodic_training_update)
165 __WEIGHTED_UPDATE_PTFV(C0D0U0, cval);
167 if (dvfs_update || periodic_training_update) {
168 tdel = next->current_dram_clktree[C0D0U0] -
169 __MOVAVG_AC(next, C0D0U0);
170 tmdel = (tdel < 0) ? -1 * tdel : tdel;
173 if (tmdel * 128 * next_timing_rate_mhz / 1000000 >
175 next->current_dram_clktree[C0D0U0] =
176 __MOVAVG_AC(next, C0D0U0);
179 if (dvfs_pt1 || periodic_training_update) {
180 cval = tegra210_emc_actual_osc_clocks(last->run_clocks);
182 cval /= last_timing_rate_mhz * 2 * temp[0][1];
186 __INCREMENT_PTFV(C0D0U1, cval);
187 else if (dvfs_update)
188 __AVERAGE_PTFV(C0D0U1);
189 else if (periodic_training_update)
190 __WEIGHTED_UPDATE_PTFV(C0D0U1, cval);
192 if (dvfs_update || periodic_training_update) {
193 tdel = next->current_dram_clktree[C0D0U1] -
194 __MOVAVG_AC(next, C0D0U1);
195 tmdel = (tdel < 0) ? -1 * tdel : tdel;
200 if (tmdel * 128 * next_timing_rate_mhz / 1000000 >
202 next->current_dram_clktree[C0D0U1] =
203 __MOVAVG_AC(next, C0D0U1);
206 if (emc->num_channels > 1) {
207 if (dvfs_pt1 || periodic_training_update) {
208 cval = tegra210_emc_actual_osc_clocks(last->run_clocks);
210 cval /= last_timing_rate_mhz * 2 * temp[1][0];
214 __INCREMENT_PTFV(C1D0U0, cval);
215 else if (dvfs_update)
216 __AVERAGE_PTFV(C1D0U0);
217 else if (periodic_training_update)
218 __WEIGHTED_UPDATE_PTFV(C1D0U0, cval);
220 if (dvfs_update || periodic_training_update) {
221 tdel = next->current_dram_clktree[C1D0U0] -
222 __MOVAVG_AC(next, C1D0U0);
223 tmdel = (tdel < 0) ? -1 * tdel : tdel;
228 if (tmdel * 128 * next_timing_rate_mhz / 1000000 >
230 next->current_dram_clktree[C1D0U0] =
231 __MOVAVG_AC(next, C1D0U0);
234 if (dvfs_pt1 || periodic_training_update) {
235 cval = tegra210_emc_actual_osc_clocks(last->run_clocks);
237 cval /= last_timing_rate_mhz * 2 * temp[1][1];
241 __INCREMENT_PTFV(C1D0U1, cval);
242 else if (dvfs_update)
243 __AVERAGE_PTFV(C1D0U1);
244 else if (periodic_training_update)
245 __WEIGHTED_UPDATE_PTFV(C1D0U1, cval);
247 if (dvfs_update || periodic_training_update) {
248 tdel = next->current_dram_clktree[C1D0U1] -
249 __MOVAVG_AC(next, C1D0U1);
250 tmdel = (tdel < 0) ? -1 * tdel : tdel;
255 if (tmdel * 128 * next_timing_rate_mhz / 1000000 >
257 next->current_dram_clktree[C1D0U1] =
258 __MOVAVG_AC(next, C1D0U1);
262 if (emc->num_devices < 2)
268 if (dvfs_pt1 || periodic_training_update) {
269 value = tegra210_emc_mrr_read(emc, 1, 19);
271 for (i = 0; i < emc->num_channels; i++) {
272 temp[i][0] = (value & 0x00ff) << 8;
273 temp[i][1] = (value & 0xff00) << 0;
280 value = tegra210_emc_mrr_read(emc, 2, 18);
282 for (i = 0; i < emc->num_channels; i++) {
283 temp[i][0] |= (value & 0x00ff) >> 0;
284 temp[i][1] |= (value & 0xff00) >> 8;
289 if (dvfs_pt1 || periodic_training_update) {
290 cval = tegra210_emc_actual_osc_clocks(last->run_clocks);
292 cval /= last_timing_rate_mhz * 2 * temp[0][0];
296 __INCREMENT_PTFV(C0D1U0, cval);
297 else if (dvfs_update)
298 __AVERAGE_PTFV(C0D1U0);
299 else if (periodic_training_update)
300 __WEIGHTED_UPDATE_PTFV(C0D1U0, cval);
302 if (dvfs_update || periodic_training_update) {
303 tdel = next->current_dram_clktree[C0D1U0] -
304 __MOVAVG_AC(next, C0D1U0);
305 tmdel = (tdel < 0) ? -1 * tdel : tdel;
310 if (tmdel * 128 * next_timing_rate_mhz / 1000000 >
312 next->current_dram_clktree[C0D1U0] =
313 __MOVAVG_AC(next, C0D1U0);
316 if (dvfs_pt1 || periodic_training_update) {
317 cval = tegra210_emc_actual_osc_clocks(last->run_clocks);
319 cval /= last_timing_rate_mhz * 2 * temp[0][1];
323 __INCREMENT_PTFV(C0D1U1, cval);
324 else if (dvfs_update)
325 __AVERAGE_PTFV(C0D1U1);
326 else if (periodic_training_update)
327 __WEIGHTED_UPDATE_PTFV(C0D1U1, cval);
329 if (dvfs_update || periodic_training_update) {
330 tdel = next->current_dram_clktree[C0D1U1] -
331 __MOVAVG_AC(next, C0D1U1);
332 tmdel = (tdel < 0) ? -1 * tdel : tdel;
337 if (tmdel * 128 * next_timing_rate_mhz / 1000000 >
339 next->current_dram_clktree[C0D1U1] =
340 __MOVAVG_AC(next, C0D1U1);
343 if (emc->num_channels > 1) {
344 if (dvfs_pt1 || periodic_training_update) {
345 cval = tegra210_emc_actual_osc_clocks(last->run_clocks);
347 cval /= last_timing_rate_mhz * 2 * temp[1][0];
351 __INCREMENT_PTFV(C1D1U0, cval);
352 else if (dvfs_update)
353 __AVERAGE_PTFV(C1D1U0);
354 else if (periodic_training_update)
355 __WEIGHTED_UPDATE_PTFV(C1D1U0, cval);
357 if (dvfs_update || periodic_training_update) {
358 tdel = next->current_dram_clktree[C1D1U0] -
359 __MOVAVG_AC(next, C1D1U0);
360 tmdel = (tdel < 0) ? -1 * tdel : tdel;
365 if (tmdel * 128 * next_timing_rate_mhz / 1000000 >
367 next->current_dram_clktree[C1D1U0] =
368 __MOVAVG_AC(next, C1D1U0);
371 if (dvfs_pt1 || periodic_training_update) {
372 cval = tegra210_emc_actual_osc_clocks(last->run_clocks);
374 cval /= last_timing_rate_mhz * 2 * temp[1][1];
378 __INCREMENT_PTFV(C1D1U1, cval);
379 else if (dvfs_update)
380 __AVERAGE_PTFV(C1D1U1);
381 else if (periodic_training_update)
382 __WEIGHTED_UPDATE_PTFV(C1D1U1, cval);
384 if (dvfs_update || periodic_training_update) {
385 tdel = next->current_dram_clktree[C1D1U1] -
386 __MOVAVG_AC(next, C1D1U1);
387 tmdel = (tdel < 0) ? -1 * tdel : tdel;
392 if (tmdel * 128 * next_timing_rate_mhz / 1000000 >
394 next->current_dram_clktree[C1D1U1] =
395 __MOVAVG_AC(next, C1D1U1);
403 static u32 periodic_compensation_handler(struct tegra210_emc *emc, u32 type,
404 struct tegra210_emc_timing *last,
405 struct tegra210_emc_timing *next)
407 #define __COPY_EMA(nt, lt, dev) \
408 ({ __MOVAVG(nt, dev) = __MOVAVG(lt, dev) * \
409 (nt)->ptfv_list[PTFV_DVFS_SAMPLES_INDEX]; })
411 u32 i, adel = 0, samples = next->ptfv_list[PTFV_DVFS_SAMPLES_INDEX];
414 delay = tegra210_emc_actual_osc_clocks(last->run_clocks);
416 delay = 2 + (delay / last->rate);
418 if (!next->periodic_training)
421 if (type == DVFS_SEQUENCE) {
422 if (last->periodic_training &&
423 (next->ptfv_list[PTFV_CONFIG_CTRL_INDEX] &
424 PTFV_CONFIG_CTRL_USE_PREVIOUS_EMA)) {
426 * If the previous frequency was using periodic
427 * calibration then we can reuse the previous
428 * frequencies EMA data.
430 __COPY_EMA(next, last, C0D0U0);
431 __COPY_EMA(next, last, C0D0U1);
432 __COPY_EMA(next, last, C1D0U0);
433 __COPY_EMA(next, last, C1D0U1);
434 __COPY_EMA(next, last, C0D1U0);
435 __COPY_EMA(next, last, C0D1U1);
436 __COPY_EMA(next, last, C1D1U0);
437 __COPY_EMA(next, last, C1D1U1);
440 __MOVAVG(next, C0D0U0) = 0;
441 __MOVAVG(next, C0D0U1) = 0;
442 __MOVAVG(next, C1D0U0) = 0;
443 __MOVAVG(next, C1D0U1) = 0;
444 __MOVAVG(next, C0D1U0) = 0;
445 __MOVAVG(next, C0D1U1) = 0;
446 __MOVAVG(next, C1D1U0) = 0;
447 __MOVAVG(next, C1D1U1) = 0;
449 for (i = 0; i < samples; i++) {
450 tegra210_emc_start_periodic_compensation(emc);
454 * Generate next sample of data.
456 adel = update_clock_tree_delay(emc, DVFS_PT1);
461 * Seems like it should be part of the
462 * 'if (last_timing->periodic_training)' conditional
463 * since is already done for the else clause.
465 adel = update_clock_tree_delay(emc, DVFS_UPDATE);
468 if (type == PERIODIC_TRAINING_SEQUENCE) {
469 tegra210_emc_start_periodic_compensation(emc);
472 adel = update_clock_tree_delay(emc, PERIODIC_TRAINING_UPDATE);
478 static u32 tegra210_emc_r21021_periodic_compensation(struct tegra210_emc *emc)
480 u32 emc_cfg, emc_cfg_o, emc_cfg_update, del, value;
482 EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_0,
483 EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_1,
484 EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_2,
485 EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_3,
486 EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_0,
487 EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_1,
488 EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_2,
489 EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_3,
493 struct tegra210_emc_timing *last = emc->last;
494 unsigned int items = ARRAY_SIZE(list), i;
497 if (last->periodic_training) {
498 emc_dbg(emc, PER_TRAIN, "Periodic training starting\n");
500 value = emc_readl(emc, EMC_DBG);
501 emc_cfg_o = emc_readl(emc, EMC_CFG);
502 emc_cfg = emc_cfg_o & ~(EMC_CFG_DYN_SELF_REF |
504 EMC_CFG_DRAM_CLKSTOP_PD);
508 * 1. Power optimizations should be off.
510 emc_writel(emc, emc_cfg, EMC_CFG);
512 /* Does emc_timing_update() for above changes. */
513 tegra210_emc_dll_disable(emc);
515 for (i = 0; i < emc->num_channels; i++)
516 tegra210_emc_wait_for_update(emc, i, EMC_EMC_STATUS,
517 EMC_EMC_STATUS_DRAM_IN_POWERDOWN_MASK,
520 for (i = 0; i < emc->num_channels; i++)
521 tegra210_emc_wait_for_update(emc, i, EMC_EMC_STATUS,
522 EMC_EMC_STATUS_DRAM_IN_SELF_REFRESH_MASK,
525 emc_cfg_update = value = emc_readl(emc, EMC_CFG_UPDATE);
526 value &= ~EMC_CFG_UPDATE_UPDATE_DLL_IN_UPDATE_MASK;
527 value |= (2 << EMC_CFG_UPDATE_UPDATE_DLL_IN_UPDATE_SHIFT);
528 emc_writel(emc, value, EMC_CFG_UPDATE);
531 * 2. osc kick off - this assumes training and dvfs have set
534 tegra210_emc_start_periodic_compensation(emc);
537 * 3. Let dram capture its clock tree delays.
539 delay = tegra210_emc_actual_osc_clocks(last->run_clocks);
541 delay /= last->rate + 1;
545 * 4. Check delta wrt previous values (save value if margin
546 * exceeds what is set in table).
548 del = periodic_compensation_handler(emc,
549 PERIODIC_TRAINING_SEQUENCE,
553 * 5. Apply compensation w.r.t. trained values (if clock tree
554 * has drifted more than the set margin).
556 if (last->tree_margin < ((del * 128 * (last->rate / 1000)) / 1000000)) {
557 for (i = 0; i < items; i++) {
558 value = tegra210_emc_compensate(last, list[i]);
559 emc_dbg(emc, EMA_WRITES, "0x%08x <= 0x%08x\n",
561 emc_writel(emc, value, list[i]);
565 emc_writel(emc, emc_cfg_o, EMC_CFG);
568 * 6. Timing update actally applies the new trimmers.
570 tegra210_emc_timing_update(emc);
572 /* 6.1. Restore the UPDATE_DLL_IN_UPDATE field. */
573 emc_writel(emc, emc_cfg_update, EMC_CFG_UPDATE);
575 /* 6.2. Restore the DLL. */
576 tegra210_emc_dll_enable(emc);
583 * Do the clock change sequence.
585 static void tegra210_emc_r21021_set_clock(struct tegra210_emc *emc, u32 clksrc)
587 /* state variables */
588 static bool fsp_for_next_freq;
589 /* constant configuration parameters */
590 const bool save_restore_clkstop_pd = true;
591 const u32 zqcal_before_cc_cutoff = 2400;
592 const bool cya_allow_ref_cc = false;
593 const bool cya_issue_pc_ref = false;
594 const bool opt_cc_short_zcal = true;
595 const bool ref_b4_sref_en = false;
596 const u32 tZQCAL_lpddr4 = 1000000;
597 const bool opt_short_zcal = true;
598 const bool opt_do_sw_qrst = true;
599 const u32 opt_dvfs_mode = MAN_SR;
601 * This is the timing table for the source frequency. It does _not_
602 * necessarily correspond to the actual timing values in the EMC at the
603 * moment. If the boot BCT differs from the table then this can happen.
604 * However, we need it for accessing the dram_timings (which are not
605 * really registers) array for the current frequency.
607 struct tegra210_emc_timing *fake, *last = emc->last, *next = emc->next;
608 u32 tRTM, RP_war, R2P_war, TRPab_war, deltaTWATM, W2P_war, tRPST;
609 u32 mr13_flip_fspwr, mr13_flip_fspop, ramp_up_wait, ramp_down_wait;
610 u32 zq_wait_long, zq_latch_dvfs_wait_time, tZQCAL_lpddr4_fc_adj;
611 u32 emc_auto_cal_config, auto_cal_en, emc_cfg, emc_sel_dpd_ctrl;
612 u32 tFC_lpddr4 = 1000 * next->dram_timings[T_FC_LPDDR4];
613 u32 bg_reg_mode_change, enable_bglp_reg, enable_bg_reg;
614 bool opt_zcal_en_cc = false, is_lpddr3 = false;
615 bool compensate_trimmer_applicable = false;
616 u32 emc_dbg, emc_cfg_pipe_clk, emc_pin;
617 u32 src_clk_period, dst_clk_period; /* in picoseconds */
618 bool shared_zq_resistor = false;
619 u32 value, dram_type;
620 u32 opt_dll_mode = 0;
624 emc_dbg(emc, INFO, "Running clock change.\n");
626 /* XXX fake == last */
627 fake = tegra210_emc_find_timing(emc, last->rate * 1000UL);
628 fsp_for_next_freq = !fsp_for_next_freq;
630 value = emc_readl(emc, EMC_FBIO_CFG5) & EMC_FBIO_CFG5_DRAM_TYPE_MASK;
631 dram_type = value >> EMC_FBIO_CFG5_DRAM_TYPE_SHIFT;
633 if (last->burst_regs[EMC_ZCAL_WAIT_CNT_INDEX] & BIT(31))
634 shared_zq_resistor = true;
636 if ((next->burst_regs[EMC_ZCAL_INTERVAL_INDEX] != 0 &&
637 last->burst_regs[EMC_ZCAL_INTERVAL_INDEX] == 0) ||
638 dram_type == DRAM_TYPE_LPDDR4)
639 opt_zcal_en_cc = true;
641 if (dram_type == DRAM_TYPE_DDR3)
642 opt_dll_mode = tegra210_emc_get_dll_state(next);
644 if ((next->burst_regs[EMC_FBIO_CFG5_INDEX] & BIT(25)) &&
645 (dram_type == DRAM_TYPE_LPDDR2))
648 emc_readl(emc, EMC_CFG);
649 emc_readl(emc, EMC_AUTO_CAL_CONFIG);
651 src_clk_period = 1000000000 / last->rate;
652 dst_clk_period = 1000000000 / next->rate;
654 if (dst_clk_period <= zqcal_before_cc_cutoff)
655 tZQCAL_lpddr4_fc_adj = tZQCAL_lpddr4 - tFC_lpddr4;
657 tZQCAL_lpddr4_fc_adj = tZQCAL_lpddr4;
659 tZQCAL_lpddr4_fc_adj /= dst_clk_period;
661 emc_dbg = emc_readl(emc, EMC_DBG);
662 emc_pin = emc_readl(emc, EMC_PIN);
663 emc_cfg_pipe_clk = emc_readl(emc, EMC_CFG_PIPE_CLK);
665 emc_cfg = next->burst_regs[EMC_CFG_INDEX];
666 emc_cfg &= ~(EMC_CFG_DYN_SELF_REF | EMC_CFG_DRAM_ACPD |
667 EMC_CFG_DRAM_CLKSTOP_SR | EMC_CFG_DRAM_CLKSTOP_PD);
668 emc_sel_dpd_ctrl = next->emc_sel_dpd_ctrl;
669 emc_sel_dpd_ctrl &= ~(EMC_SEL_DPD_CTRL_CLK_SEL_DPD_EN |
670 EMC_SEL_DPD_CTRL_CA_SEL_DPD_EN |
671 EMC_SEL_DPD_CTRL_RESET_SEL_DPD_EN |
672 EMC_SEL_DPD_CTRL_ODT_SEL_DPD_EN |
673 EMC_SEL_DPD_CTRL_DATA_SEL_DPD_EN);
675 emc_dbg(emc, INFO, "Clock change version: %d\n",
676 DVFS_CLOCK_CHANGE_VERSION);
677 emc_dbg(emc, INFO, "DRAM type = %d\n", dram_type);
678 emc_dbg(emc, INFO, "DRAM dev #: %u\n", emc->num_devices);
679 emc_dbg(emc, INFO, "Next EMC clksrc: 0x%08x\n", clksrc);
680 emc_dbg(emc, INFO, "DLL clksrc: 0x%08x\n", next->dll_clk_src);
681 emc_dbg(emc, INFO, "last rate: %u, next rate %u\n", last->rate,
683 emc_dbg(emc, INFO, "last period: %u, next period: %u\n",
684 src_clk_period, dst_clk_period);
685 emc_dbg(emc, INFO, " shared_zq_resistor: %d\n", !!shared_zq_resistor);
686 emc_dbg(emc, INFO, " num_channels: %u\n", emc->num_channels);
687 emc_dbg(emc, INFO, " opt_dll_mode: %d\n", opt_dll_mode);
691 * Pre DVFS SW sequence.
693 emc_dbg(emc, STEPS, "Step 1\n");
694 emc_dbg(emc, STEPS, "Step 1.1: Disable DLL temporarily.\n");
696 value = emc_readl(emc, EMC_CFG_DIG_DLL);
697 value &= ~EMC_CFG_DIG_DLL_CFG_DLL_EN;
698 emc_writel(emc, value, EMC_CFG_DIG_DLL);
700 tegra210_emc_timing_update(emc);
702 for (i = 0; i < emc->num_channels; i++)
703 tegra210_emc_wait_for_update(emc, i, EMC_CFG_DIG_DLL,
704 EMC_CFG_DIG_DLL_CFG_DLL_EN, 0);
706 emc_dbg(emc, STEPS, "Step 1.2: Disable AUTOCAL temporarily.\n");
708 emc_auto_cal_config = next->emc_auto_cal_config;
709 auto_cal_en = emc_auto_cal_config & EMC_AUTO_CAL_CONFIG_AUTO_CAL_ENABLE;
710 emc_auto_cal_config &= ~EMC_AUTO_CAL_CONFIG_AUTO_CAL_START;
711 emc_auto_cal_config |= EMC_AUTO_CAL_CONFIG_AUTO_CAL_MEASURE_STALL;
712 emc_auto_cal_config |= EMC_AUTO_CAL_CONFIG_AUTO_CAL_UPDATE_STALL;
713 emc_auto_cal_config |= auto_cal_en;
714 emc_writel(emc, emc_auto_cal_config, EMC_AUTO_CAL_CONFIG);
715 emc_readl(emc, EMC_AUTO_CAL_CONFIG); /* Flush write. */
717 emc_dbg(emc, STEPS, "Step 1.3: Disable other power features.\n");
719 tegra210_emc_set_shadow_bypass(emc, ACTIVE);
720 emc_writel(emc, emc_cfg, EMC_CFG);
721 emc_writel(emc, emc_sel_dpd_ctrl, EMC_SEL_DPD_CTRL);
722 tegra210_emc_set_shadow_bypass(emc, ASSEMBLY);
724 if (next->periodic_training) {
725 tegra210_emc_reset_dram_clktree_values(next);
727 for (i = 0; i < emc->num_channels; i++)
728 tegra210_emc_wait_for_update(emc, i, EMC_EMC_STATUS,
729 EMC_EMC_STATUS_DRAM_IN_POWERDOWN_MASK,
732 for (i = 0; i < emc->num_channels; i++)
733 tegra210_emc_wait_for_update(emc, i, EMC_EMC_STATUS,
734 EMC_EMC_STATUS_DRAM_IN_SELF_REFRESH_MASK,
737 tegra210_emc_start_periodic_compensation(emc);
739 delay = 1000 * tegra210_emc_actual_osc_clocks(last->run_clocks);
740 udelay((delay / last->rate) + 2);
742 value = periodic_compensation_handler(emc, DVFS_SEQUENCE, fake,
744 value = (value * 128 * next->rate / 1000) / 1000000;
746 if (next->periodic_training && value > next->tree_margin)
747 compensate_trimmer_applicable = true;
750 emc_writel(emc, EMC_INTSTATUS_CLKCHANGE_COMPLETE, EMC_INTSTATUS);
751 tegra210_emc_set_shadow_bypass(emc, ACTIVE);
752 emc_writel(emc, emc_cfg, EMC_CFG);
753 emc_writel(emc, emc_sel_dpd_ctrl, EMC_SEL_DPD_CTRL);
754 emc_writel(emc, emc_cfg_pipe_clk | EMC_CFG_PIPE_CLK_CLK_ALWAYS_ON,
756 emc_writel(emc, next->emc_fdpd_ctrl_cmd_no_ramp &
757 ~EMC_FDPD_CTRL_CMD_NO_RAMP_CMD_DPD_NO_RAMP_ENABLE,
758 EMC_FDPD_CTRL_CMD_NO_RAMP);
761 ((next->burst_regs[EMC_PMACRO_BG_BIAS_CTRL_0_INDEX] &
762 EMC_PMACRO_BG_BIAS_CTRL_0_BGLP_E_PWRD) ^
763 (last->burst_regs[EMC_PMACRO_BG_BIAS_CTRL_0_INDEX] &
764 EMC_PMACRO_BG_BIAS_CTRL_0_BGLP_E_PWRD)) ||
765 ((next->burst_regs[EMC_PMACRO_BG_BIAS_CTRL_0_INDEX] &
766 EMC_PMACRO_BG_BIAS_CTRL_0_BG_E_PWRD) ^
767 (last->burst_regs[EMC_PMACRO_BG_BIAS_CTRL_0_INDEX] &
768 EMC_PMACRO_BG_BIAS_CTRL_0_BG_E_PWRD));
770 (next->burst_regs[EMC_PMACRO_BG_BIAS_CTRL_0_INDEX] &
771 EMC_PMACRO_BG_BIAS_CTRL_0_BGLP_E_PWRD) == 0;
773 (next->burst_regs[EMC_PMACRO_BG_BIAS_CTRL_0_INDEX] &
774 EMC_PMACRO_BG_BIAS_CTRL_0_BG_E_PWRD) == 0;
776 if (bg_reg_mode_change) {
778 emc_writel(emc, last->burst_regs
779 [EMC_PMACRO_BG_BIAS_CTRL_0_INDEX] &
780 ~EMC_PMACRO_BG_BIAS_CTRL_0_BG_E_PWRD,
781 EMC_PMACRO_BG_BIAS_CTRL_0);
784 emc_writel(emc, last->burst_regs
785 [EMC_PMACRO_BG_BIAS_CTRL_0_INDEX] &
786 ~EMC_PMACRO_BG_BIAS_CTRL_0_BGLP_E_PWRD,
787 EMC_PMACRO_BG_BIAS_CTRL_0);
790 /* Check if we need to turn on VREF generator. */
791 if ((((last->burst_regs[EMC_PMACRO_DATA_PAD_TX_CTRL_INDEX] &
792 EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_DQ_E_IVREF) == 0) &&
793 ((next->burst_regs[EMC_PMACRO_DATA_PAD_TX_CTRL_INDEX] &
794 EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_DQ_E_IVREF) == 1)) ||
795 (((last->burst_regs[EMC_PMACRO_DATA_PAD_TX_CTRL_INDEX] &
796 EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_DQS_E_IVREF) == 0) &&
797 ((next->burst_regs[EMC_PMACRO_DATA_PAD_TX_CTRL_INDEX] &
798 EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_DQS_E_IVREF) != 0))) {
800 next->burst_regs[EMC_PMACRO_DATA_PAD_TX_CTRL_INDEX];
801 u32 last_pad_tx_ctrl =
802 last->burst_regs[EMC_PMACRO_DATA_PAD_TX_CTRL_INDEX];
803 u32 next_dq_e_ivref, next_dqs_e_ivref;
805 next_dqs_e_ivref = pad_tx_ctrl &
806 EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_DQS_E_IVREF;
807 next_dq_e_ivref = pad_tx_ctrl &
808 EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_DQ_E_IVREF;
809 value = (last_pad_tx_ctrl &
810 ~EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_DQ_E_IVREF &
811 ~EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_DQS_E_IVREF) |
812 next_dq_e_ivref | next_dqs_e_ivref;
813 emc_writel(emc, value, EMC_PMACRO_DATA_PAD_TX_CTRL);
815 } else if (bg_reg_mode_change) {
819 tegra210_emc_set_shadow_bypass(emc, ASSEMBLY);
825 emc_dbg(emc, STEPS, "Step 2\n");
827 if (next->burst_regs[EMC_CFG_DIG_DLL_INDEX] &
828 EMC_CFG_DIG_DLL_CFG_DLL_EN) {
829 emc_dbg(emc, INFO, "Prelock enabled for target frequency.\n");
830 value = tegra210_emc_dll_prelock(emc, clksrc);
831 emc_dbg(emc, INFO, "DLL out: 0x%03x\n", value);
833 emc_dbg(emc, INFO, "Disabling DLL for target frequency.\n");
834 tegra210_emc_dll_disable(emc);
839 * Prepare autocal for the clock change.
841 emc_dbg(emc, STEPS, "Step 3\n");
843 tegra210_emc_set_shadow_bypass(emc, ACTIVE);
844 emc_writel(emc, next->emc_auto_cal_config2, EMC_AUTO_CAL_CONFIG2);
845 emc_writel(emc, next->emc_auto_cal_config3, EMC_AUTO_CAL_CONFIG3);
846 emc_writel(emc, next->emc_auto_cal_config4, EMC_AUTO_CAL_CONFIG4);
847 emc_writel(emc, next->emc_auto_cal_config5, EMC_AUTO_CAL_CONFIG5);
848 emc_writel(emc, next->emc_auto_cal_config6, EMC_AUTO_CAL_CONFIG6);
849 emc_writel(emc, next->emc_auto_cal_config7, EMC_AUTO_CAL_CONFIG7);
850 emc_writel(emc, next->emc_auto_cal_config8, EMC_AUTO_CAL_CONFIG8);
851 tegra210_emc_set_shadow_bypass(emc, ASSEMBLY);
853 emc_auto_cal_config |= (EMC_AUTO_CAL_CONFIG_AUTO_CAL_COMPUTE_START |
855 emc_writel(emc, emc_auto_cal_config, EMC_AUTO_CAL_CONFIG);
859 * Update EMC_CFG. (??)
861 emc_dbg(emc, STEPS, "Step 4\n");
863 if (src_clk_period > 50000 && dram_type == DRAM_TYPE_LPDDR4)
864 ccfifo_writel(emc, 1, EMC_SELF_REF, 0);
866 emc_writel(emc, next->emc_cfg_2, EMC_CFG_2);
870 * Prepare reference variables for ZQCAL regs.
872 emc_dbg(emc, STEPS, "Step 5\n");
874 if (dram_type == DRAM_TYPE_LPDDR4)
875 zq_wait_long = max((u32)1, div_o3(1000000, dst_clk_period));
876 else if (dram_type == DRAM_TYPE_LPDDR2 || is_lpddr3)
877 zq_wait_long = max(next->min_mrs_wait,
878 div_o3(360000, dst_clk_period)) + 4;
879 else if (dram_type == DRAM_TYPE_DDR3)
880 zq_wait_long = max((u32)256,
881 div_o3(320000, dst_clk_period) + 2);
887 * Training code - removed.
889 emc_dbg(emc, STEPS, "Step 6\n");
893 * Program FSP reference registers and send MRWs to new FSPWR.
895 emc_dbg(emc, STEPS, "Step 7\n");
896 emc_dbg(emc, SUB_STEPS, "Step 7.1: Bug 200024907 - Patch RP R2P");
899 if (dram_type == DRAM_TYPE_LPDDR4) {
902 if (src_clk_period >= 1000000 / 1866) /* 535.91 ps */
905 if (src_clk_period >= 1000000 / 1600) /* 625.00 ps */
908 if (src_clk_period >= 1000000 / 1333) /* 750.19 ps */
911 if (src_clk_period >= 1000000 / 1066) /* 938.09 ps */
914 deltaTWATM = max_t(u32, div_o3(7500, src_clk_period), 8);
917 * Originally there was a + .5 in the tRPST calculation.
918 * However since we can't do FP in the kernel and the tRTM
919 * computation was in a floating point ceiling function, adding
920 * one to tRTP should be ok. There is no other source of non
921 * integer values, so the result was always going to be
922 * something for the form: f_ceil(N + .5) = N + 1;
924 tRPST = (last->emc_mrw & 0x80) >> 7;
925 tRTM = fake->dram_timings[RL] + div_o3(3600, src_clk_period) +
926 max_t(u32, div_o3(7500, src_clk_period), 8) + tRPST +
929 emc_dbg(emc, INFO, "tRTM = %u, EMC_RP = %u\n", tRTM,
930 next->burst_regs[EMC_RP_INDEX]);
932 if (last->burst_regs[EMC_RP_INDEX] < tRTM) {
933 if (tRTM > (last->burst_regs[EMC_R2P_INDEX] +
934 last->burst_regs[EMC_RP_INDEX])) {
935 R2P_war = tRTM - last->burst_regs[EMC_RP_INDEX];
936 RP_war = last->burst_regs[EMC_RP_INDEX];
937 TRPab_war = last->burst_regs[EMC_TRPAB_INDEX];
941 last->burst_regs[EMC_RP_INDEX] - 63;
943 if (TRPab_war < RP_war)
949 R2P_war = last->burst_regs[EMC_R2P_INDEX];
950 RP_war = last->burst_regs[EMC_RP_INDEX];
951 TRPab_war = last->burst_regs[EMC_TRPAB_INDEX];
954 if (RP_war < deltaTWATM) {
955 W2P_war = last->burst_regs[EMC_W2P_INDEX]
956 + deltaTWATM - RP_war;
958 RP_war = RP_war + W2P_war - 63;
959 if (TRPab_war < RP_war)
964 W2P_war = last->burst_regs[
968 if ((last->burst_regs[EMC_W2P_INDEX] ^ W2P_war) ||
969 (last->burst_regs[EMC_R2P_INDEX] ^ R2P_war) ||
970 (last->burst_regs[EMC_RP_INDEX] ^ RP_war) ||
971 (last->burst_regs[EMC_TRPAB_INDEX] ^ TRPab_war)) {
972 emc_writel(emc, RP_war, EMC_RP);
973 emc_writel(emc, R2P_war, EMC_R2P);
974 emc_writel(emc, W2P_war, EMC_W2P);
975 emc_writel(emc, TRPab_war, EMC_TRPAB);
978 tegra210_emc_timing_update(emc);
980 emc_dbg(emc, INFO, "Skipped WAR\n");
984 if (!fsp_for_next_freq) {
985 mr13_flip_fspwr = (next->emc_mrw3 & 0xffffff3f) | 0x80;
986 mr13_flip_fspop = (next->emc_mrw3 & 0xffffff3f) | 0x00;
988 mr13_flip_fspwr = (next->emc_mrw3 & 0xffffff3f) | 0x40;
989 mr13_flip_fspop = (next->emc_mrw3 & 0xffffff3f) | 0xc0;
992 if (dram_type == DRAM_TYPE_LPDDR4) {
993 emc_writel(emc, mr13_flip_fspwr, EMC_MRW3);
994 emc_writel(emc, next->emc_mrw, EMC_MRW);
995 emc_writel(emc, next->emc_mrw2, EMC_MRW2);
1000 * Program the shadow registers.
1002 emc_dbg(emc, STEPS, "Step 8\n");
1003 emc_dbg(emc, SUB_STEPS, "Writing burst_regs\n");
1005 for (i = 0; i < next->num_burst; i++) {
1006 const u16 *offsets = emc->offsets->burst;
1012 value = next->burst_regs[i];
1013 offset = offsets[i];
1015 if (dram_type != DRAM_TYPE_LPDDR4 &&
1016 (offset == EMC_MRW6 || offset == EMC_MRW7 ||
1017 offset == EMC_MRW8 || offset == EMC_MRW9 ||
1018 offset == EMC_MRW10 || offset == EMC_MRW11 ||
1019 offset == EMC_MRW12 || offset == EMC_MRW13 ||
1020 offset == EMC_MRW14 || offset == EMC_MRW15 ||
1021 offset == EMC_TRAINING_CTRL))
1024 /* Pain... And suffering. */
1025 if (offset == EMC_CFG) {
1026 value &= ~EMC_CFG_DRAM_ACPD;
1027 value &= ~EMC_CFG_DYN_SELF_REF;
1029 if (dram_type == DRAM_TYPE_LPDDR4) {
1030 value &= ~EMC_CFG_DRAM_CLKSTOP_SR;
1031 value &= ~EMC_CFG_DRAM_CLKSTOP_PD;
1033 } else if (offset == EMC_MRS_WAIT_CNT &&
1034 dram_type == DRAM_TYPE_LPDDR2 &&
1035 opt_zcal_en_cc && !opt_cc_short_zcal &&
1037 value = (value & ~(EMC_MRS_WAIT_CNT_SHORT_WAIT_MASK <<
1038 EMC_MRS_WAIT_CNT_SHORT_WAIT_SHIFT)) |
1039 ((zq_wait_long & EMC_MRS_WAIT_CNT_SHORT_WAIT_MASK) <<
1040 EMC_MRS_WAIT_CNT_SHORT_WAIT_SHIFT);
1041 } else if (offset == EMC_ZCAL_WAIT_CNT &&
1042 dram_type == DRAM_TYPE_DDR3 && opt_zcal_en_cc &&
1043 !opt_cc_short_zcal && opt_short_zcal) {
1044 value = (value & ~(EMC_ZCAL_WAIT_CNT_ZCAL_WAIT_CNT_MASK <<
1045 EMC_ZCAL_WAIT_CNT_ZCAL_WAIT_CNT_SHIFT)) |
1046 ((zq_wait_long & EMC_ZCAL_WAIT_CNT_ZCAL_WAIT_CNT_MASK) <<
1047 EMC_MRS_WAIT_CNT_SHORT_WAIT_SHIFT);
1048 } else if (offset == EMC_ZCAL_INTERVAL && opt_zcal_en_cc) {
1049 value = 0; /* EMC_ZCAL_INTERVAL reset value. */
1050 } else if (offset == EMC_PMACRO_AUTOCAL_CFG_COMMON) {
1051 value |= EMC_PMACRO_AUTOCAL_CFG_COMMON_E_CAL_BYPASS_DVFS;
1052 } else if (offset == EMC_PMACRO_DATA_PAD_TX_CTRL) {
1053 value &= ~(EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_DQSP_TX_E_DCC |
1054 EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_DQSN_TX_E_DCC |
1055 EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_DQ_TX_E_DCC |
1056 EMC_PMACRO_DATA_PAD_TX_CTRL_DATA_CMD_TX_E_DCC);
1057 } else if (offset == EMC_PMACRO_CMD_PAD_TX_CTRL) {
1058 value |= EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_DQ_TX_DRVFORCEON;
1059 value &= ~(EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_DQSP_TX_E_DCC |
1060 EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_DQSN_TX_E_DCC |
1061 EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_DQ_TX_E_DCC |
1062 EMC_PMACRO_CMD_PAD_TX_CTRL_CMD_CMD_TX_E_DCC);
1063 } else if (offset == EMC_PMACRO_BRICK_CTRL_RFU1) {
1064 value &= 0xf800f800;
1065 } else if (offset == EMC_PMACRO_COMMON_PAD_TX_CTRL) {
1066 value &= 0xfffffff0;
1069 emc_writel(emc, value, offset);
1072 /* SW addition: do EMC refresh adjustment here. */
1073 tegra210_emc_adjust_timing(emc, next);
1075 if (dram_type == DRAM_TYPE_LPDDR4) {
1076 value = (23 << EMC_MRW_MRW_MA_SHIFT) |
1077 (next->run_clocks & EMC_MRW_MRW_OP_MASK);
1078 emc_writel(emc, value, EMC_MRW);
1081 /* Per channel burst registers. */
1082 emc_dbg(emc, SUB_STEPS, "Writing burst_regs_per_ch\n");
1084 for (i = 0; i < next->num_burst_per_ch; i++) {
1085 const struct tegra210_emc_per_channel_regs *burst =
1086 emc->offsets->burst_per_channel;
1088 if (!burst[i].offset)
1091 if (dram_type != DRAM_TYPE_LPDDR4 &&
1092 (burst[i].offset == EMC_MRW6 ||
1093 burst[i].offset == EMC_MRW7 ||
1094 burst[i].offset == EMC_MRW8 ||
1095 burst[i].offset == EMC_MRW9 ||
1096 burst[i].offset == EMC_MRW10 ||
1097 burst[i].offset == EMC_MRW11 ||
1098 burst[i].offset == EMC_MRW12 ||
1099 burst[i].offset == EMC_MRW13 ||
1100 burst[i].offset == EMC_MRW14 ||
1101 burst[i].offset == EMC_MRW15))
1104 /* Filter out second channel if not in DUAL_CHANNEL mode. */
1105 if (emc->num_channels < 2 && burst[i].bank >= 1)
1108 emc_dbg(emc, REG_LISTS, "(%u) 0x%08x => 0x%08x\n", i,
1109 next->burst_reg_per_ch[i], burst[i].offset);
1110 emc_channel_writel(emc, burst[i].bank,
1111 next->burst_reg_per_ch[i],
1116 emc_dbg(emc, SUB_STEPS, "Writing vref_regs\n");
1118 for (i = 0; i < next->vref_num; i++) {
1119 const struct tegra210_emc_per_channel_regs *vref =
1120 emc->offsets->vref_per_channel;
1122 if (!vref[i].offset)
1125 if (emc->num_channels < 2 && vref[i].bank >= 1)
1128 emc_dbg(emc, REG_LISTS, "(%u) 0x%08x => 0x%08x\n", i,
1129 next->vref_perch_regs[i], vref[i].offset);
1130 emc_channel_writel(emc, vref[i].bank, next->vref_perch_regs[i],
1135 emc_dbg(emc, SUB_STEPS, "Writing trim_regs\n");
1137 for (i = 0; i < next->num_trim; i++) {
1138 const u16 *offsets = emc->offsets->trim;
1143 if (compensate_trimmer_applicable &&
1144 (offsets[i] == EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_0 ||
1145 offsets[i] == EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_1 ||
1146 offsets[i] == EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_2 ||
1147 offsets[i] == EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_3 ||
1148 offsets[i] == EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_0 ||
1149 offsets[i] == EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_1 ||
1150 offsets[i] == EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_2 ||
1151 offsets[i] == EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_3 ||
1152 offsets[i] == EMC_DATA_BRLSHFT_0 ||
1153 offsets[i] == EMC_DATA_BRLSHFT_1)) {
1154 value = tegra210_emc_compensate(next, offsets[i]);
1155 emc_dbg(emc, REG_LISTS, "(%u) 0x%08x => 0x%08x\n", i,
1157 emc_dbg(emc, EMA_WRITES, "0x%08x <= 0x%08x\n",
1158 (u32)(u64)offsets[i], value);
1159 emc_writel(emc, value, offsets[i]);
1161 emc_dbg(emc, REG_LISTS, "(%u) 0x%08x => 0x%08x\n", i,
1162 next->trim_regs[i], offsets[i]);
1163 emc_writel(emc, next->trim_regs[i], offsets[i]);
1167 /* Per channel trimmers. */
1168 emc_dbg(emc, SUB_STEPS, "Writing trim_regs_per_ch\n");
1170 for (i = 0; i < next->num_trim_per_ch; i++) {
1171 const struct tegra210_emc_per_channel_regs *trim =
1172 &emc->offsets->trim_per_channel[0];
1173 unsigned int offset;
1175 if (!trim[i].offset)
1178 if (emc->num_channels < 2 && trim[i].bank >= 1)
1181 offset = trim[i].offset;
1183 if (compensate_trimmer_applicable &&
1184 (offset == EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_0 ||
1185 offset == EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_1 ||
1186 offset == EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_2 ||
1187 offset == EMC_PMACRO_OB_DDLL_LONG_DQ_RANK0_3 ||
1188 offset == EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_0 ||
1189 offset == EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_1 ||
1190 offset == EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_2 ||
1191 offset == EMC_PMACRO_OB_DDLL_LONG_DQ_RANK1_3 ||
1192 offset == EMC_DATA_BRLSHFT_0 ||
1193 offset == EMC_DATA_BRLSHFT_1)) {
1194 value = tegra210_emc_compensate(next, offset);
1195 emc_dbg(emc, REG_LISTS, "(%u) 0x%08x => 0x%08x\n", i,
1197 emc_dbg(emc, EMA_WRITES, "0x%08x <= 0x%08x\n", offset,
1199 emc_channel_writel(emc, trim[i].bank, value, offset);
1201 emc_dbg(emc, REG_LISTS, "(%u) 0x%08x => 0x%08x\n", i,
1202 next->trim_perch_regs[i], offset);
1203 emc_channel_writel(emc, trim[i].bank,
1204 next->trim_perch_regs[i], offset);
1208 emc_dbg(emc, SUB_STEPS, "Writing burst_mc_regs\n");
1210 for (i = 0; i < next->num_mc_regs; i++) {
1211 const u16 *offsets = emc->offsets->burst_mc;
1212 u32 *values = next->burst_mc_regs;
1214 emc_dbg(emc, REG_LISTS, "(%u) 0x%08x => 0x%08x\n", i,
1215 values[i], offsets[i]);
1216 mc_writel(emc->mc, values[i], offsets[i]);
1219 /* Registers to be programmed on the faster clock. */
1220 if (next->rate < last->rate) {
1221 const u16 *la = emc->offsets->la_scale;
1223 emc_dbg(emc, SUB_STEPS, "Writing la_scale_regs\n");
1225 for (i = 0; i < next->num_up_down; i++) {
1226 emc_dbg(emc, REG_LISTS, "(%u) 0x%08x => 0x%08x\n", i,
1227 next->la_scale_regs[i], la[i]);
1228 mc_writel(emc->mc, next->la_scale_regs[i], la[i]);
1232 /* Flush all the burst register writes. */
1233 mc_readl(emc->mc, MC_EMEM_ADR_CFG);
1239 emc_dbg(emc, STEPS, "Step 9\n");
1241 value = next->burst_regs[EMC_ZCAL_WAIT_CNT_INDEX];
1242 value &= ~EMC_ZCAL_WAIT_CNT_ZCAL_WAIT_CNT_MASK;
1244 if (dram_type == DRAM_TYPE_LPDDR4) {
1245 emc_writel(emc, 0, EMC_ZCAL_INTERVAL);
1246 emc_writel(emc, value, EMC_ZCAL_WAIT_CNT);
1248 value = emc_dbg | (EMC_DBG_WRITE_MUX_ACTIVE |
1249 EMC_DBG_WRITE_ACTIVE_ONLY);
1251 emc_writel(emc, value, EMC_DBG);
1252 emc_writel(emc, 0, EMC_ZCAL_INTERVAL);
1253 emc_writel(emc, emc_dbg, EMC_DBG);
1258 * LPDDR4 and DDR3 common section.
1260 emc_dbg(emc, STEPS, "Step 10\n");
1262 if (opt_dvfs_mode == MAN_SR || dram_type == DRAM_TYPE_LPDDR4) {
1263 if (dram_type == DRAM_TYPE_LPDDR4)
1264 ccfifo_writel(emc, 0x101, EMC_SELF_REF, 0);
1266 ccfifo_writel(emc, 0x1, EMC_SELF_REF, 0);
1268 if (dram_type == DRAM_TYPE_LPDDR4 &&
1269 dst_clk_period <= zqcal_before_cc_cutoff) {
1270 ccfifo_writel(emc, mr13_flip_fspwr ^ 0x40, EMC_MRW3, 0);
1271 ccfifo_writel(emc, (next->burst_regs[EMC_MRW6_INDEX] &
1273 (last->burst_regs[EMC_MRW6_INDEX] &
1274 0x0000C0C0), EMC_MRW6, 0);
1275 ccfifo_writel(emc, (next->burst_regs[EMC_MRW14_INDEX] &
1277 (last->burst_regs[EMC_MRW14_INDEX] &
1278 0x00003838), EMC_MRW14, 0);
1280 if (emc->num_devices > 1) {
1282 (next->burst_regs[EMC_MRW7_INDEX] &
1284 (last->burst_regs[EMC_MRW7_INDEX] &
1285 0x0000C0C0), EMC_MRW7, 0);
1287 (next->burst_regs[EMC_MRW15_INDEX] &
1289 (last->burst_regs[EMC_MRW15_INDEX] &
1290 0x00003838), EMC_MRW15, 0);
1293 if (opt_zcal_en_cc) {
1294 if (emc->num_devices < 2)
1296 2UL << EMC_ZQ_CAL_DEV_SEL_SHIFT
1297 | EMC_ZQ_CAL_ZQ_CAL_CMD,
1299 else if (shared_zq_resistor)
1301 2UL << EMC_ZQ_CAL_DEV_SEL_SHIFT
1302 | EMC_ZQ_CAL_ZQ_CAL_CMD,
1306 EMC_ZQ_CAL_ZQ_CAL_CMD,
1312 if (dram_type == DRAM_TYPE_LPDDR4) {
1313 value = (1000 * fake->dram_timings[T_RP]) / src_clk_period;
1314 ccfifo_writel(emc, mr13_flip_fspop | 0x8, EMC_MRW3, value);
1315 ccfifo_writel(emc, 0, 0, tFC_lpddr4 / src_clk_period);
1318 if (dram_type == DRAM_TYPE_LPDDR4 || opt_dvfs_mode != MAN_SR) {
1321 if (cya_allow_ref_cc) {
1322 delay += (1000 * fake->dram_timings[T_RP]) /
1324 delay += 4000 * fake->dram_timings[T_RFC];
1327 ccfifo_writel(emc, emc_pin & ~(EMC_PIN_PIN_CKE_PER_DEV |
1333 /* calculate reference delay multiplier */
1339 if (cya_allow_ref_cc)
1342 if (cya_issue_pc_ref)
1345 if (dram_type != DRAM_TYPE_LPDDR4) {
1346 delay = ((1000 * fake->dram_timings[T_RP] / src_clk_period) +
1347 (1000 * fake->dram_timings[T_RFC] / src_clk_period));
1348 delay = value * delay + 20;
1357 emc_dbg(emc, STEPS, "Step 11\n");
1359 ccfifo_writel(emc, 0x0, EMC_CFG_SYNC, delay);
1361 value = emc_dbg | EMC_DBG_WRITE_MUX_ACTIVE | EMC_DBG_WRITE_ACTIVE_ONLY;
1362 ccfifo_writel(emc, value, EMC_DBG, 0);
1364 ramp_down_wait = tegra210_emc_dvfs_power_ramp_down(emc, src_clk_period,
1369 * And finally - trigger the clock change.
1371 emc_dbg(emc, STEPS, "Step 12\n");
1373 ccfifo_writel(emc, 1, EMC_STALL_THEN_EXE_AFTER_CLKCHANGE, 0);
1374 value &= ~EMC_DBG_WRITE_ACTIVE_ONLY;
1375 ccfifo_writel(emc, value, EMC_DBG, 0);
1381 emc_dbg(emc, STEPS, "Step 13\n");
1383 ramp_up_wait = tegra210_emc_dvfs_power_ramp_up(emc, dst_clk_period, 0);
1384 ccfifo_writel(emc, emc_dbg, EMC_DBG, 0);
1390 emc_dbg(emc, STEPS, "Step 14\n");
1392 if (dram_type == DRAM_TYPE_LPDDR4) {
1393 value = emc_pin | EMC_PIN_PIN_CKE;
1395 if (emc->num_devices <= 1)
1396 value &= ~(EMC_PIN_PIN_CKEB | EMC_PIN_PIN_CKE_PER_DEV);
1398 value |= EMC_PIN_PIN_CKEB | EMC_PIN_PIN_CKE_PER_DEV;
1400 ccfifo_writel(emc, value, EMC_PIN, 0);
1404 * Step 15: (two step 15s ??)
1405 * Calculate zqlatch wait time; has dependency on ramping times.
1407 emc_dbg(emc, STEPS, "Step 15\n");
1409 if (dst_clk_period <= zqcal_before_cc_cutoff) {
1410 s32 t = (s32)(ramp_up_wait + ramp_down_wait) /
1411 (s32)dst_clk_period;
1412 zq_latch_dvfs_wait_time = (s32)tZQCAL_lpddr4_fc_adj - t;
1414 zq_latch_dvfs_wait_time = tZQCAL_lpddr4_fc_adj -
1415 div_o3(1000 * next->dram_timings[T_PDEX],
1419 emc_dbg(emc, INFO, "tZQCAL_lpddr4_fc_adj = %u\n", tZQCAL_lpddr4_fc_adj);
1420 emc_dbg(emc, INFO, "dst_clk_period = %u\n",
1422 emc_dbg(emc, INFO, "next->dram_timings[T_PDEX] = %u\n",
1423 next->dram_timings[T_PDEX]);
1424 emc_dbg(emc, INFO, "zq_latch_dvfs_wait_time = %d\n",
1425 max_t(s32, 0, zq_latch_dvfs_wait_time));
1427 if (dram_type == DRAM_TYPE_LPDDR4 && opt_zcal_en_cc) {
1428 delay = div_o3(1000 * next->dram_timings[T_PDEX],
1431 if (emc->num_devices < 2) {
1432 if (dst_clk_period > zqcal_before_cc_cutoff)
1434 2UL << EMC_ZQ_CAL_DEV_SEL_SHIFT |
1435 EMC_ZQ_CAL_ZQ_CAL_CMD, EMC_ZQ_CAL,
1438 value = (mr13_flip_fspop & 0xfffffff7) | 0x0c000000;
1439 ccfifo_writel(emc, value, EMC_MRW3, delay);
1440 ccfifo_writel(emc, 0, EMC_SELF_REF, 0);
1441 ccfifo_writel(emc, 0, EMC_REF, 0);
1442 ccfifo_writel(emc, 2UL << EMC_ZQ_CAL_DEV_SEL_SHIFT |
1443 EMC_ZQ_CAL_ZQ_LATCH_CMD,
1445 max_t(s32, 0, zq_latch_dvfs_wait_time));
1446 } else if (shared_zq_resistor) {
1447 if (dst_clk_period > zqcal_before_cc_cutoff)
1449 2UL << EMC_ZQ_CAL_DEV_SEL_SHIFT |
1450 EMC_ZQ_CAL_ZQ_CAL_CMD, EMC_ZQ_CAL,
1453 ccfifo_writel(emc, 2UL << EMC_ZQ_CAL_DEV_SEL_SHIFT |
1454 EMC_ZQ_CAL_ZQ_LATCH_CMD, EMC_ZQ_CAL,
1455 max_t(s32, 0, zq_latch_dvfs_wait_time) +
1457 ccfifo_writel(emc, 1UL << EMC_ZQ_CAL_DEV_SEL_SHIFT |
1458 EMC_ZQ_CAL_ZQ_LATCH_CMD,
1461 value = (mr13_flip_fspop & 0xfffffff7) | 0x0c000000;
1462 ccfifo_writel(emc, value, EMC_MRW3, 0);
1463 ccfifo_writel(emc, 0, EMC_SELF_REF, 0);
1464 ccfifo_writel(emc, 0, EMC_REF, 0);
1466 ccfifo_writel(emc, 1UL << EMC_ZQ_CAL_DEV_SEL_SHIFT |
1467 EMC_ZQ_CAL_ZQ_LATCH_CMD, EMC_ZQ_CAL,
1468 tZQCAL_lpddr4 / dst_clk_period);
1470 if (dst_clk_period > zqcal_before_cc_cutoff)
1471 ccfifo_writel(emc, EMC_ZQ_CAL_ZQ_CAL_CMD,
1474 value = (mr13_flip_fspop & 0xfffffff7) | 0x0c000000;
1475 ccfifo_writel(emc, value, EMC_MRW3, delay);
1476 ccfifo_writel(emc, 0, EMC_SELF_REF, 0);
1477 ccfifo_writel(emc, 0, EMC_REF, 0);
1479 ccfifo_writel(emc, EMC_ZQ_CAL_ZQ_LATCH_CMD, EMC_ZQ_CAL,
1480 max_t(s32, 0, zq_latch_dvfs_wait_time));
1484 /* WAR: delay for zqlatch */
1485 ccfifo_writel(emc, 0, 0, 10);
1489 * LPDDR4 Conditional Training Kickoff. Removed.
1494 * MANSR exit self refresh.
1496 emc_dbg(emc, STEPS, "Step 17\n");
1498 if (opt_dvfs_mode == MAN_SR && dram_type != DRAM_TYPE_LPDDR4)
1499 ccfifo_writel(emc, 0, EMC_SELF_REF, 0);
1503 * Send MRWs to LPDDR3/DDR3.
1505 emc_dbg(emc, STEPS, "Step 18\n");
1507 if (dram_type == DRAM_TYPE_LPDDR2) {
1508 ccfifo_writel(emc, next->emc_mrw2, EMC_MRW2, 0);
1509 ccfifo_writel(emc, next->emc_mrw, EMC_MRW, 0);
1511 ccfifo_writel(emc, next->emc_mrw4, EMC_MRW4, 0);
1512 } else if (dram_type == DRAM_TYPE_DDR3) {
1514 ccfifo_writel(emc, next->emc_emrs &
1515 ~EMC_EMRS_USE_EMRS_LONG_CNT, EMC_EMRS, 0);
1516 ccfifo_writel(emc, next->emc_emrs2 &
1517 ~EMC_EMRS2_USE_EMRS2_LONG_CNT, EMC_EMRS2, 0);
1518 ccfifo_writel(emc, next->emc_mrs |
1519 EMC_EMRS_USE_EMRS_LONG_CNT, EMC_MRS, 0);
1524 * ZQCAL for LPDDR3/DDR3
1526 emc_dbg(emc, STEPS, "Step 19\n");
1528 if (opt_zcal_en_cc) {
1529 if (dram_type == DRAM_TYPE_LPDDR2) {
1530 value = opt_cc_short_zcal ? 90000 : 360000;
1531 value = div_o3(value, dst_clk_period);
1533 EMC_MRS_WAIT_CNT2_MRS_EXT2_WAIT_CNT_SHIFT |
1535 EMC_MRS_WAIT_CNT2_MRS_EXT1_WAIT_CNT_SHIFT;
1536 ccfifo_writel(emc, value, EMC_MRS_WAIT_CNT2, 0);
1538 value = opt_cc_short_zcal ? 0x56 : 0xab;
1539 ccfifo_writel(emc, 2 << EMC_MRW_MRW_DEV_SELECTN_SHIFT |
1540 EMC_MRW_USE_MRW_EXT_CNT |
1541 10 << EMC_MRW_MRW_MA_SHIFT |
1542 value << EMC_MRW_MRW_OP_SHIFT,
1545 if (emc->num_devices > 1) {
1546 value = 1 << EMC_MRW_MRW_DEV_SELECTN_SHIFT |
1547 EMC_MRW_USE_MRW_EXT_CNT |
1548 10 << EMC_MRW_MRW_MA_SHIFT |
1549 value << EMC_MRW_MRW_OP_SHIFT;
1550 ccfifo_writel(emc, value, EMC_MRW, 0);
1552 } else if (dram_type == DRAM_TYPE_DDR3) {
1553 value = opt_cc_short_zcal ? 0 : EMC_ZQ_CAL_LONG;
1555 ccfifo_writel(emc, value |
1556 2 << EMC_ZQ_CAL_DEV_SEL_SHIFT |
1557 EMC_ZQ_CAL_ZQ_CAL_CMD, EMC_ZQ_CAL,
1560 if (emc->num_devices > 1) {
1561 value = value | 1 << EMC_ZQ_CAL_DEV_SEL_SHIFT |
1562 EMC_ZQ_CAL_ZQ_CAL_CMD;
1563 ccfifo_writel(emc, value, EMC_ZQ_CAL, 0);
1568 if (bg_reg_mode_change) {
1569 tegra210_emc_set_shadow_bypass(emc, ACTIVE);
1571 if (ramp_up_wait <= 1250000)
1572 delay = (1250000 - ramp_up_wait) / dst_clk_period;
1577 next->burst_regs[EMC_PMACRO_BG_BIAS_CTRL_0_INDEX],
1578 EMC_PMACRO_BG_BIAS_CTRL_0, delay);
1579 tegra210_emc_set_shadow_bypass(emc, ASSEMBLY);
1584 * Issue ref and optional QRST.
1586 emc_dbg(emc, STEPS, "Step 20\n");
1588 if (dram_type != DRAM_TYPE_LPDDR4)
1589 ccfifo_writel(emc, 0, EMC_REF, 0);
1591 if (opt_do_sw_qrst) {
1592 ccfifo_writel(emc, 1, EMC_ISSUE_QRST, 0);
1593 ccfifo_writel(emc, 0, EMC_ISSUE_QRST, 2);
1598 * Restore ZCAL and ZCAL interval.
1600 emc_dbg(emc, STEPS, "Step 21\n");
1602 if (save_restore_clkstop_pd || opt_zcal_en_cc) {
1603 ccfifo_writel(emc, emc_dbg | EMC_DBG_WRITE_MUX_ACTIVE,
1605 if (opt_zcal_en_cc && dram_type != DRAM_TYPE_LPDDR4)
1606 ccfifo_writel(emc, next->burst_regs[EMC_ZCAL_INTERVAL_INDEX],
1607 EMC_ZCAL_INTERVAL, 0);
1609 if (save_restore_clkstop_pd)
1610 ccfifo_writel(emc, next->burst_regs[EMC_CFG_INDEX] &
1611 ~EMC_CFG_DYN_SELF_REF,
1613 ccfifo_writel(emc, emc_dbg, EMC_DBG, 0);
1618 * Restore EMC_CFG_PIPE_CLK.
1620 emc_dbg(emc, STEPS, "Step 22\n");
1622 ccfifo_writel(emc, emc_cfg_pipe_clk, EMC_CFG_PIPE_CLK, 0);
1624 if (bg_reg_mode_change) {
1627 next->burst_regs[EMC_PMACRO_BG_BIAS_CTRL_0_INDEX] &
1628 ~EMC_PMACRO_BG_BIAS_CTRL_0_BGLP_E_PWRD,
1629 EMC_PMACRO_BG_BIAS_CTRL_0);
1632 next->burst_regs[EMC_PMACRO_BG_BIAS_CTRL_0_INDEX] &
1633 ~EMC_PMACRO_BG_BIAS_CTRL_0_BG_E_PWRD,
1634 EMC_PMACRO_BG_BIAS_CTRL_0);
1640 emc_dbg(emc, STEPS, "Step 23\n");
1642 value = emc_readl(emc, EMC_CFG_DIG_DLL);
1643 value |= EMC_CFG_DIG_DLL_CFG_DLL_STALL_ALL_TRAFFIC;
1644 value &= ~EMC_CFG_DIG_DLL_CFG_DLL_STALL_RW_UNTIL_LOCK;
1645 value &= ~EMC_CFG_DIG_DLL_CFG_DLL_STALL_ALL_UNTIL_LOCK;
1646 value &= ~EMC_CFG_DIG_DLL_CFG_DLL_EN;
1647 value = (value & ~EMC_CFG_DIG_DLL_CFG_DLL_MODE_MASK) |
1648 (2 << EMC_CFG_DIG_DLL_CFG_DLL_MODE_SHIFT);
1649 emc_writel(emc, value, EMC_CFG_DIG_DLL);
1651 tegra210_emc_do_clock_change(emc, clksrc);
1655 * Save training results. Removed.
1660 * Program MC updown registers.
1662 emc_dbg(emc, STEPS, "Step 25\n");
1664 if (next->rate > last->rate) {
1665 for (i = 0; i < next->num_up_down; i++)
1666 mc_writel(emc->mc, next->la_scale_regs[i],
1667 emc->offsets->la_scale[i]);
1669 tegra210_emc_timing_update(emc);
1674 * Restore ZCAL registers.
1676 emc_dbg(emc, STEPS, "Step 26\n");
1678 if (dram_type == DRAM_TYPE_LPDDR4) {
1679 tegra210_emc_set_shadow_bypass(emc, ACTIVE);
1680 emc_writel(emc, next->burst_regs[EMC_ZCAL_WAIT_CNT_INDEX],
1682 emc_writel(emc, next->burst_regs[EMC_ZCAL_INTERVAL_INDEX],
1684 tegra210_emc_set_shadow_bypass(emc, ASSEMBLY);
1687 if (dram_type != DRAM_TYPE_LPDDR4 && opt_zcal_en_cc &&
1688 !opt_short_zcal && opt_cc_short_zcal) {
1691 tegra210_emc_set_shadow_bypass(emc, ACTIVE);
1692 if (dram_type == DRAM_TYPE_LPDDR2)
1693 emc_writel(emc, next->burst_regs[EMC_MRS_WAIT_CNT_INDEX],
1695 else if (dram_type == DRAM_TYPE_DDR3)
1696 emc_writel(emc, next->burst_regs[EMC_ZCAL_WAIT_CNT_INDEX],
1698 tegra210_emc_set_shadow_bypass(emc, ASSEMBLY);
1703 * Restore EMC_CFG, FDPD registers.
1705 emc_dbg(emc, STEPS, "Step 27\n");
1707 tegra210_emc_set_shadow_bypass(emc, ACTIVE);
1708 emc_writel(emc, next->burst_regs[EMC_CFG_INDEX], EMC_CFG);
1709 tegra210_emc_set_shadow_bypass(emc, ASSEMBLY);
1710 emc_writel(emc, next->emc_fdpd_ctrl_cmd_no_ramp,
1711 EMC_FDPD_CTRL_CMD_NO_RAMP);
1712 emc_writel(emc, next->emc_sel_dpd_ctrl, EMC_SEL_DPD_CTRL);
1716 * Training recover. Removed.
1718 emc_dbg(emc, STEPS, "Step 28\n");
1720 tegra210_emc_set_shadow_bypass(emc, ACTIVE);
1722 next->burst_regs[EMC_PMACRO_AUTOCAL_CFG_COMMON_INDEX],
1723 EMC_PMACRO_AUTOCAL_CFG_COMMON);
1724 tegra210_emc_set_shadow_bypass(emc, ASSEMBLY);
1730 emc_dbg(emc, STEPS, "Step 29\n");
1732 emc_writel(emc, EMC_PMACRO_CFG_PM_GLOBAL_0_DISABLE_CFG_BYTE0 |
1733 EMC_PMACRO_CFG_PM_GLOBAL_0_DISABLE_CFG_BYTE1 |
1734 EMC_PMACRO_CFG_PM_GLOBAL_0_DISABLE_CFG_BYTE2 |
1735 EMC_PMACRO_CFG_PM_GLOBAL_0_DISABLE_CFG_BYTE3 |
1736 EMC_PMACRO_CFG_PM_GLOBAL_0_DISABLE_CFG_BYTE4 |
1737 EMC_PMACRO_CFG_PM_GLOBAL_0_DISABLE_CFG_BYTE5 |
1738 EMC_PMACRO_CFG_PM_GLOBAL_0_DISABLE_CFG_BYTE6 |
1739 EMC_PMACRO_CFG_PM_GLOBAL_0_DISABLE_CFG_BYTE7,
1740 EMC_PMACRO_CFG_PM_GLOBAL_0);
1741 emc_writel(emc, EMC_PMACRO_TRAINING_CTRL_0_CH0_TRAINING_E_WRPTR,
1742 EMC_PMACRO_TRAINING_CTRL_0);
1743 emc_writel(emc, EMC_PMACRO_TRAINING_CTRL_1_CH1_TRAINING_E_WRPTR,
1744 EMC_PMACRO_TRAINING_CTRL_1);
1745 emc_writel(emc, 0, EMC_PMACRO_CFG_PM_GLOBAL_0);
1749 * Re-enable autocal.
1751 emc_dbg(emc, STEPS, "Step 30: Re-enable DLL and AUTOCAL\n");
1753 if (next->burst_regs[EMC_CFG_DIG_DLL_INDEX] & EMC_CFG_DIG_DLL_CFG_DLL_EN) {
1754 value = emc_readl(emc, EMC_CFG_DIG_DLL);
1755 value |= EMC_CFG_DIG_DLL_CFG_DLL_STALL_ALL_TRAFFIC;
1756 value |= EMC_CFG_DIG_DLL_CFG_DLL_EN;
1757 value &= ~EMC_CFG_DIG_DLL_CFG_DLL_STALL_RW_UNTIL_LOCK;
1758 value &= ~EMC_CFG_DIG_DLL_CFG_DLL_STALL_ALL_UNTIL_LOCK;
1759 value = (value & ~EMC_CFG_DIG_DLL_CFG_DLL_MODE_MASK) |
1760 (2 << EMC_CFG_DIG_DLL_CFG_DLL_MODE_SHIFT);
1761 emc_writel(emc, value, EMC_CFG_DIG_DLL);
1762 tegra210_emc_timing_update(emc);
1765 emc_writel(emc, next->emc_auto_cal_config, EMC_AUTO_CAL_CONFIG);
1770 const struct tegra210_emc_sequence tegra210_emc_r21021 = {
1772 .set_clock = tegra210_emc_r21021_set_clock,
1773 .periodic_compensation = tegra210_emc_r21021_periodic_compensation,