Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright Altera Corporation (C) 2012-2015 |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 6 | #include <log.h> |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 7 | #include <linux/string.h> |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 8 | #include <asm/io.h> |
| 9 | #include <asm/arch/sdram.h> |
Marek Vasut | 6ca5b96 | 2015-07-18 02:46:56 +0200 | [diff] [blame] | 10 | #include <errno.h> |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 11 | #include <hang.h> |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 12 | #include "sequencer.h" |
Marek Vasut | 662a8a6 | 2015-08-02 16:55:45 +0200 | [diff] [blame] | 13 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 14 | static const struct socfpga_sdr_rw_load_manager *sdr_rw_load_mgr_regs = |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 15 | (struct socfpga_sdr_rw_load_manager *) |
| 16 | (SDR_PHYGRP_RWMGRGRP_ADDRESS | 0x800); |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 17 | static const struct socfpga_sdr_rw_load_jump_manager *sdr_rw_load_jump_mgr_regs |
| 18 | = (struct socfpga_sdr_rw_load_jump_manager *) |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 19 | (SDR_PHYGRP_RWMGRGRP_ADDRESS | 0xC00); |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 20 | static const struct socfpga_sdr_reg_file *sdr_reg_file = |
Marek Vasut | 341ceec | 2015-07-12 18:31:05 +0200 | [diff] [blame] | 21 | (struct socfpga_sdr_reg_file *)SDR_PHYGRP_REGFILEGRP_ADDRESS; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 22 | static const struct socfpga_sdr_scc_mgr *sdr_scc_mgr = |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 23 | (struct socfpga_sdr_scc_mgr *) |
| 24 | (SDR_PHYGRP_SCCGRP_ADDRESS | 0xe00); |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 25 | static const struct socfpga_phy_mgr_cmd *phy_mgr_cmd = |
Marek Vasut | c3b9b0f | 2015-07-12 18:54:37 +0200 | [diff] [blame] | 26 | (struct socfpga_phy_mgr_cmd *)SDR_PHYGRP_PHYMGRGRP_ADDRESS; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 27 | static const struct socfpga_phy_mgr_cfg *phy_mgr_cfg = |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 28 | (struct socfpga_phy_mgr_cfg *) |
| 29 | (SDR_PHYGRP_PHYMGRGRP_ADDRESS | 0x40); |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 30 | static const struct socfpga_data_mgr *data_mgr = |
Marek Vasut | a334010 | 2015-07-12 19:03:33 +0200 | [diff] [blame] | 31 | (struct socfpga_data_mgr *)SDR_PHYGRP_DATAMGRGRP_ADDRESS; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 32 | static const struct socfpga_sdr_ctrl *sdr_ctrl = |
Marek Vasut | cd5d38e | 2015-07-12 20:49:39 +0200 | [diff] [blame] | 33 | (struct socfpga_sdr_ctrl *)SDR_CTRLGRP_ADDRESS; |
| 34 | |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 35 | #define DELTA_D 1 |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 36 | |
| 37 | /* |
| 38 | * In order to reduce ROM size, most of the selectable calibration steps are |
| 39 | * decided at compile time based on the user's calibration mode selection, |
| 40 | * as captured by the STATIC_CALIB_STEPS selection below. |
| 41 | * |
| 42 | * However, to support simulation-time selection of fast simulation mode, where |
| 43 | * we skip everything except the bare minimum, we need a few of the steps to |
| 44 | * be dynamic. In those cases, we either use the DYNAMIC_CALIB_STEPS for the |
| 45 | * check, which is based on the rtl-supplied value, or we dynamically compute |
| 46 | * the value to use based on the dynamically-chosen calibration mode |
| 47 | */ |
| 48 | |
| 49 | #define DLEVEL 0 |
| 50 | #define STATIC_IN_RTL_SIM 0 |
| 51 | #define STATIC_SKIP_DELAY_LOOPS 0 |
| 52 | |
| 53 | #define STATIC_CALIB_STEPS (STATIC_IN_RTL_SIM | CALIB_SKIP_FULL_TEST | \ |
| 54 | STATIC_SKIP_DELAY_LOOPS) |
| 55 | |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 56 | #define SKIP_DELAY_LOOP_VALUE_OR_ZERO(non_skip_value) \ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 57 | ((non_skip_value) & seq->skip_delay_mask) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 58 | |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 59 | bool dram_is_ddr(const u8 ddr) |
| 60 | { |
| 61 | const struct socfpga_sdram_config *cfg = socfpga_get_sdram_config(); |
| 62 | const u8 type = (cfg->ctrl_cfg >> SDR_CTRLGRP_CTRLCFG_MEMTYPE_LSB) & |
| 63 | SDR_CTRLGRP_CTRLCFG_MEMTYPE_MASK; |
| 64 | |
| 65 | if (ddr == 2 && type == 1) /* DDR2 */ |
| 66 | return true; |
| 67 | |
| 68 | if (ddr == 3 && type == 2) /* DDR3 */ |
| 69 | return true; |
| 70 | |
| 71 | return false; |
| 72 | } |
| 73 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 74 | static void set_failing_group_stage(struct socfpga_sdrseq *seq, |
| 75 | u32 group, u32 stage, u32 substage) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 76 | { |
| 77 | /* |
| 78 | * Only set the global stage if there was not been any other |
| 79 | * failing group |
| 80 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 81 | if (seq->gbl.error_stage == CAL_STAGE_NIL) { |
| 82 | seq->gbl.error_substage = substage; |
| 83 | seq->gbl.error_stage = stage; |
| 84 | seq->gbl.error_group = group; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | |
Marek Vasut | 6eeb747 | 2015-07-12 21:10:24 +0200 | [diff] [blame] | 88 | static void reg_file_set_group(u16 set_group) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 89 | { |
Marek Vasut | 6eeb747 | 2015-07-12 21:10:24 +0200 | [diff] [blame] | 90 | clrsetbits_le32(&sdr_reg_file->cur_stage, 0xffff0000, set_group << 16); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 91 | } |
| 92 | |
Marek Vasut | 6eeb747 | 2015-07-12 21:10:24 +0200 | [diff] [blame] | 93 | static void reg_file_set_stage(u8 set_stage) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 94 | { |
Marek Vasut | 6eeb747 | 2015-07-12 21:10:24 +0200 | [diff] [blame] | 95 | clrsetbits_le32(&sdr_reg_file->cur_stage, 0xffff, set_stage & 0xff); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 96 | } |
| 97 | |
Marek Vasut | 6eeb747 | 2015-07-12 21:10:24 +0200 | [diff] [blame] | 98 | static void reg_file_set_sub_stage(u8 set_sub_stage) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 99 | { |
Marek Vasut | 6eeb747 | 2015-07-12 21:10:24 +0200 | [diff] [blame] | 100 | set_sub_stage &= 0xff; |
| 101 | clrsetbits_le32(&sdr_reg_file->cur_stage, 0xff00, set_sub_stage << 8); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 102 | } |
| 103 | |
Marek Vasut | fe5aa45 | 2015-07-17 01:36:32 +0200 | [diff] [blame] | 104 | /** |
| 105 | * phy_mgr_initialize() - Initialize PHY Manager |
| 106 | * |
| 107 | * Initialize PHY Manager. |
| 108 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 109 | static void phy_mgr_initialize(struct socfpga_sdrseq *seq) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 110 | { |
Marek Vasut | fe5aa45 | 2015-07-17 01:36:32 +0200 | [diff] [blame] | 111 | u32 ratio; |
| 112 | |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 113 | debug("%s:%d\n", __func__, __LINE__); |
Marek Vasut | fe5aa45 | 2015-07-17 01:36:32 +0200 | [diff] [blame] | 114 | /* Calibration has control over path to memory */ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 115 | /* |
| 116 | * In Hard PHY this is a 2-bit control: |
| 117 | * 0: AFI Mux Select |
| 118 | * 1: DDIO Mux Select |
| 119 | */ |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 120 | writel(0x3, &phy_mgr_cfg->mux_sel); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 121 | |
| 122 | /* USER memory clock is not stable we begin initialization */ |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 123 | writel(0, &phy_mgr_cfg->reset_mem_stbl); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 124 | |
| 125 | /* USER calibration status all set to zero */ |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 126 | writel(0, &phy_mgr_cfg->cal_status); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 127 | |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 128 | writel(0, &phy_mgr_cfg->cal_debug_info); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 129 | |
Marek Vasut | fe5aa45 | 2015-07-17 01:36:32 +0200 | [diff] [blame] | 130 | /* Init params only if we do NOT skip calibration. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 131 | if ((seq->dyn_calib_steps & CALIB_SKIP_ALL) == CALIB_SKIP_ALL) |
Marek Vasut | fe5aa45 | 2015-07-17 01:36:32 +0200 | [diff] [blame] | 132 | return; |
| 133 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 134 | ratio = seq->rwcfg->mem_dq_per_read_dqs / |
| 135 | seq->rwcfg->mem_virtual_groups_per_read_dqs; |
| 136 | seq->param.read_correct_mask_vg = (1 << ratio) - 1; |
| 137 | seq->param.write_correct_mask_vg = (1 << ratio) - 1; |
| 138 | seq->param.read_correct_mask = (1 << seq->rwcfg->mem_dq_per_read_dqs) |
| 139 | - 1; |
| 140 | seq->param.write_correct_mask = (1 << seq->rwcfg->mem_dq_per_write_dqs) |
| 141 | - 1; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 142 | } |
| 143 | |
Marek Vasut | 575029d | 2015-07-20 08:15:57 +0200 | [diff] [blame] | 144 | /** |
| 145 | * set_rank_and_odt_mask() - Set Rank and ODT mask |
| 146 | * @rank: Rank mask |
| 147 | * @odt_mode: ODT mode, OFF or READ_WRITE |
| 148 | * |
| 149 | * Set Rank and ODT mask (On-Die Termination). |
| 150 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 151 | static void set_rank_and_odt_mask(struct socfpga_sdrseq *seq, |
| 152 | const u32 rank, const u32 odt_mode) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 153 | { |
Marek Vasut | 0b5e257 | 2015-07-20 08:03:11 +0200 | [diff] [blame] | 154 | u32 odt_mask_0 = 0; |
| 155 | u32 odt_mask_1 = 0; |
| 156 | u32 cs_and_odt_mask; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 157 | |
Marek Vasut | 0b5e257 | 2015-07-20 08:03:11 +0200 | [diff] [blame] | 158 | if (odt_mode == RW_MGR_ODT_MODE_OFF) { |
| 159 | odt_mask_0 = 0x0; |
| 160 | odt_mask_1 = 0x0; |
| 161 | } else { /* RW_MGR_ODT_MODE_READ_WRITE */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 162 | switch (seq->rwcfg->mem_number_of_ranks) { |
Marek Vasut | 9252308 | 2015-07-20 08:09:05 +0200 | [diff] [blame] | 163 | case 1: /* 1 Rank */ |
| 164 | /* Read: ODT = 0 ; Write: ODT = 1 */ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 165 | odt_mask_0 = 0x0; |
| 166 | odt_mask_1 = 0x1; |
Marek Vasut | 9252308 | 2015-07-20 08:09:05 +0200 | [diff] [blame] | 167 | break; |
| 168 | case 2: /* 2 Ranks */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 169 | if (seq->rwcfg->mem_number_of_cs_per_dimm == 1) { |
Marek Vasut | 575029d | 2015-07-20 08:15:57 +0200 | [diff] [blame] | 170 | /* |
| 171 | * - Dual-Slot , Single-Rank (1 CS per DIMM) |
| 172 | * OR |
| 173 | * - RDIMM, 4 total CS (2 CS per DIMM, 2 DIMM) |
| 174 | * |
| 175 | * Since MEM_NUMBER_OF_RANKS is 2, they |
| 176 | * are both single rank with 2 CS each |
| 177 | * (special for RDIMM). |
| 178 | * |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 179 | * Read: Turn on ODT on the opposite rank |
| 180 | * Write: Turn on ODT on all ranks |
| 181 | */ |
| 182 | odt_mask_0 = 0x3 & ~(1 << rank); |
| 183 | odt_mask_1 = 0x3; |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 184 | if (dram_is_ddr(2)) |
| 185 | odt_mask_1 &= ~(1 << rank); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 186 | } else { |
| 187 | /* |
Marek Vasut | 575029d | 2015-07-20 08:15:57 +0200 | [diff] [blame] | 188 | * - Single-Slot , Dual-Rank (2 CS per DIMM) |
| 189 | * |
| 190 | * Read: Turn on ODT off on all ranks |
| 191 | * Write: Turn on ODT on active rank |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 192 | */ |
| 193 | odt_mask_0 = 0x0; |
| 194 | odt_mask_1 = 0x3 & (1 << rank); |
| 195 | } |
Marek Vasut | 9252308 | 2015-07-20 08:09:05 +0200 | [diff] [blame] | 196 | break; |
| 197 | case 4: /* 4 Ranks */ |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 198 | /* |
| 199 | * DDR3 Read, DDR2 Read/Write: |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 200 | * ----------+-----------------------+ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 201 | * | ODT | |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 202 | * +-----------------------+ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 203 | * Rank | 3 | 2 | 1 | 0 | |
| 204 | * ----------+-----+-----+-----+-----+ |
| 205 | * 0 | 0 | 1 | 0 | 0 | |
| 206 | * 1 | 1 | 0 | 0 | 0 | |
| 207 | * 2 | 0 | 0 | 0 | 1 | |
| 208 | * 3 | 0 | 0 | 1 | 0 | |
| 209 | * ----------+-----+-----+-----+-----+ |
| 210 | * |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 211 | * DDR3 Write: |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 212 | * ----------+-----------------------+ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 213 | * | ODT | |
| 214 | * Write To +-----------------------+ |
| 215 | * Rank | 3 | 2 | 1 | 0 | |
| 216 | * ----------+-----+-----+-----+-----+ |
| 217 | * 0 | 0 | 1 | 0 | 1 | |
| 218 | * 1 | 1 | 0 | 1 | 0 | |
| 219 | * 2 | 0 | 1 | 0 | 1 | |
| 220 | * 3 | 1 | 0 | 1 | 0 | |
| 221 | * ----------+-----+-----+-----+-----+ |
| 222 | */ |
| 223 | switch (rank) { |
| 224 | case 0: |
| 225 | odt_mask_0 = 0x4; |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 226 | if (dram_is_ddr(2)) |
| 227 | odt_mask_1 = 0x4; |
| 228 | else if (dram_is_ddr(3)) |
| 229 | odt_mask_1 = 0x5; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 230 | break; |
| 231 | case 1: |
| 232 | odt_mask_0 = 0x8; |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 233 | if (dram_is_ddr(2)) |
| 234 | odt_mask_1 = 0x8; |
| 235 | else if (dram_is_ddr(3)) |
| 236 | odt_mask_1 = 0xA; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 237 | break; |
| 238 | case 2: |
| 239 | odt_mask_0 = 0x1; |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 240 | if (dram_is_ddr(2)) |
| 241 | odt_mask_1 = 0x1; |
| 242 | else if (dram_is_ddr(3)) |
| 243 | odt_mask_1 = 0x5; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 244 | break; |
| 245 | case 3: |
| 246 | odt_mask_0 = 0x2; |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 247 | if (dram_is_ddr(2)) |
| 248 | odt_mask_1 = 0x2; |
| 249 | else if (dram_is_ddr(3)) |
| 250 | odt_mask_1 = 0xA; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 251 | break; |
| 252 | } |
Marek Vasut | 9252308 | 2015-07-20 08:09:05 +0200 | [diff] [blame] | 253 | break; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 254 | } |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 255 | } |
| 256 | |
Marek Vasut | 0b5e257 | 2015-07-20 08:03:11 +0200 | [diff] [blame] | 257 | cs_and_odt_mask = (0xFF & ~(1 << rank)) | |
| 258 | ((0xFF & odt_mask_0) << 8) | |
| 259 | ((0xFF & odt_mask_1) << 16); |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 260 | writel(cs_and_odt_mask, SDR_PHYGRP_RWMGRGRP_ADDRESS | |
| 261 | RW_MGR_SET_CS_AND_ODT_MASK_OFFSET); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 262 | } |
| 263 | |
Marek Vasut | 303a3dc | 2015-07-12 22:28:33 +0200 | [diff] [blame] | 264 | /** |
| 265 | * scc_mgr_set() - Set SCC Manager register |
| 266 | * @off: Base offset in SCC Manager space |
| 267 | * @grp: Read/Write group |
| 268 | * @val: Value to be set |
| 269 | * |
| 270 | * This function sets the SCC Manager (Scan Chain Control Manager) register. |
| 271 | */ |
| 272 | static void scc_mgr_set(u32 off, u32 grp, u32 val) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 273 | { |
Marek Vasut | 303a3dc | 2015-07-12 22:28:33 +0200 | [diff] [blame] | 274 | writel(val, SDR_PHYGRP_SCCGRP_ADDRESS | off | (grp << 2)); |
| 275 | } |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 276 | |
Marek Vasut | 8957b49 | 2015-07-20 07:16:42 +0200 | [diff] [blame] | 277 | /** |
| 278 | * scc_mgr_initialize() - Initialize SCC Manager registers |
| 279 | * |
| 280 | * Initialize SCC Manager registers. |
| 281 | */ |
Marek Vasut | 303a3dc | 2015-07-12 22:28:33 +0200 | [diff] [blame] | 282 | static void scc_mgr_initialize(void) |
| 283 | { |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 284 | /* |
Marek Vasut | 8957b49 | 2015-07-20 07:16:42 +0200 | [diff] [blame] | 285 | * Clear register file for HPS. 16 (2^4) is the size of the |
| 286 | * full register file in the scc mgr: |
| 287 | * RFILE_DEPTH = 1 + log2(MEM_DQ_PER_DQS + 1 + MEM_DM_PER_DQS + |
| 288 | * MEM_IF_READ_DQS_WIDTH - 1); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 289 | */ |
Marek Vasut | 303a3dc | 2015-07-12 22:28:33 +0200 | [diff] [blame] | 290 | int i; |
Marek Vasut | 8957b49 | 2015-07-20 07:16:42 +0200 | [diff] [blame] | 291 | |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 292 | for (i = 0; i < 16; i++) { |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 293 | debug_cond(DLEVEL >= 1, "%s:%d: Clearing SCC RFILE index %u\n", |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 294 | __func__, __LINE__, i); |
Marek Vasut | 45ce296 | 2016-04-04 17:28:16 +0200 | [diff] [blame] | 295 | scc_mgr_set(SCC_MGR_HHP_RFILE_OFFSET, i, 0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | |
Marek Vasut | 8af9ca0 | 2015-08-02 19:42:26 +0200 | [diff] [blame] | 299 | static void scc_mgr_set_dqdqs_output_phase(u32 write_group, u32 phase) |
Marek Vasut | 7481b69 | 2015-07-12 22:11:55 +0200 | [diff] [blame] | 300 | { |
Marek Vasut | 303a3dc | 2015-07-12 22:28:33 +0200 | [diff] [blame] | 301 | scc_mgr_set(SCC_MGR_DQDQS_OUT_PHASE_OFFSET, write_group, phase); |
Marek Vasut | 7481b69 | 2015-07-12 22:11:55 +0200 | [diff] [blame] | 302 | } |
| 303 | |
Marek Vasut | 8af9ca0 | 2015-08-02 19:42:26 +0200 | [diff] [blame] | 304 | static void scc_mgr_set_dqs_bus_in_delay(u32 read_group, u32 delay) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 305 | { |
Marek Vasut | 303a3dc | 2015-07-12 22:28:33 +0200 | [diff] [blame] | 306 | scc_mgr_set(SCC_MGR_DQS_IN_DELAY_OFFSET, read_group, delay); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 307 | } |
| 308 | |
Marek Vasut | 8af9ca0 | 2015-08-02 19:42:26 +0200 | [diff] [blame] | 309 | static void scc_mgr_set_dqs_en_phase(u32 read_group, u32 phase) |
Marek Vasut | 7481b69 | 2015-07-12 22:11:55 +0200 | [diff] [blame] | 310 | { |
Marek Vasut | 303a3dc | 2015-07-12 22:28:33 +0200 | [diff] [blame] | 311 | scc_mgr_set(SCC_MGR_DQS_EN_PHASE_OFFSET, read_group, phase); |
Marek Vasut | 7481b69 | 2015-07-12 22:11:55 +0200 | [diff] [blame] | 312 | } |
| 313 | |
Marek Vasut | 8af9ca0 | 2015-08-02 19:42:26 +0200 | [diff] [blame] | 314 | static void scc_mgr_set_dqs_en_delay(u32 read_group, u32 delay) |
Marek Vasut | 7481b69 | 2015-07-12 22:11:55 +0200 | [diff] [blame] | 315 | { |
Marek Vasut | 303a3dc | 2015-07-12 22:28:33 +0200 | [diff] [blame] | 316 | scc_mgr_set(SCC_MGR_DQS_EN_DELAY_OFFSET, read_group, delay); |
Marek Vasut | 7481b69 | 2015-07-12 22:11:55 +0200 | [diff] [blame] | 317 | } |
| 318 | |
Marek Vasut | f4d3862 | 2016-04-04 21:16:18 +0200 | [diff] [blame] | 319 | static void scc_mgr_set_dq_in_delay(u32 dq_in_group, u32 delay) |
| 320 | { |
| 321 | scc_mgr_set(SCC_MGR_IO_IN_DELAY_OFFSET, dq_in_group, delay); |
| 322 | } |
| 323 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 324 | static void scc_mgr_set_dqs_io_in_delay(struct socfpga_sdrseq *seq, |
| 325 | u32 delay) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 326 | { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 327 | scc_mgr_set(SCC_MGR_IO_IN_DELAY_OFFSET, |
| 328 | seq->rwcfg->mem_dq_per_write_dqs, delay); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 329 | } |
| 330 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 331 | static void scc_mgr_set_dm_in_delay(struct socfpga_sdrseq *seq, u32 dm, |
| 332 | u32 delay) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 333 | { |
Marek Vasut | f4d3862 | 2016-04-04 21:16:18 +0200 | [diff] [blame] | 334 | scc_mgr_set(SCC_MGR_IO_IN_DELAY_OFFSET, |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 335 | seq->rwcfg->mem_dq_per_write_dqs + 1 + dm, |
Marek Vasut | f4d3862 | 2016-04-04 21:16:18 +0200 | [diff] [blame] | 336 | delay); |
Marek Vasut | 7481b69 | 2015-07-12 22:11:55 +0200 | [diff] [blame] | 337 | } |
| 338 | |
Marek Vasut | 8af9ca0 | 2015-08-02 19:42:26 +0200 | [diff] [blame] | 339 | static void scc_mgr_set_dq_out1_delay(u32 dq_in_group, u32 delay) |
Marek Vasut | 7481b69 | 2015-07-12 22:11:55 +0200 | [diff] [blame] | 340 | { |
Marek Vasut | 303a3dc | 2015-07-12 22:28:33 +0200 | [diff] [blame] | 341 | scc_mgr_set(SCC_MGR_IO_OUT1_DELAY_OFFSET, dq_in_group, delay); |
Marek Vasut | 7481b69 | 2015-07-12 22:11:55 +0200 | [diff] [blame] | 342 | } |
| 343 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 344 | static void scc_mgr_set_dqs_out1_delay(struct socfpga_sdrseq *seq, |
| 345 | u32 delay) |
Marek Vasut | 7481b69 | 2015-07-12 22:11:55 +0200 | [diff] [blame] | 346 | { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 347 | scc_mgr_set(SCC_MGR_IO_OUT1_DELAY_OFFSET, |
| 348 | seq->rwcfg->mem_dq_per_write_dqs, delay); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 349 | } |
| 350 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 351 | static void scc_mgr_set_dm_out1_delay(struct socfpga_sdrseq *seq, u32 dm, |
| 352 | u32 delay) |
Marek Vasut | 7481b69 | 2015-07-12 22:11:55 +0200 | [diff] [blame] | 353 | { |
Marek Vasut | 303a3dc | 2015-07-12 22:28:33 +0200 | [diff] [blame] | 354 | scc_mgr_set(SCC_MGR_IO_OUT1_DELAY_OFFSET, |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 355 | seq->rwcfg->mem_dq_per_write_dqs + 1 + dm, |
Marek Vasut | 303a3dc | 2015-07-12 22:28:33 +0200 | [diff] [blame] | 356 | delay); |
Marek Vasut | 7481b69 | 2015-07-12 22:11:55 +0200 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | /* load up dqs config settings */ |
Marek Vasut | 8af9ca0 | 2015-08-02 19:42:26 +0200 | [diff] [blame] | 360 | static void scc_mgr_load_dqs(u32 dqs) |
Marek Vasut | 7481b69 | 2015-07-12 22:11:55 +0200 | [diff] [blame] | 361 | { |
| 362 | writel(dqs, &sdr_scc_mgr->dqs_ena); |
| 363 | } |
| 364 | |
| 365 | /* load up dqs io config settings */ |
| 366 | static void scc_mgr_load_dqs_io(void) |
| 367 | { |
| 368 | writel(0, &sdr_scc_mgr->dqs_io_ena); |
| 369 | } |
| 370 | |
| 371 | /* load up dq config settings */ |
Marek Vasut | 8af9ca0 | 2015-08-02 19:42:26 +0200 | [diff] [blame] | 372 | static void scc_mgr_load_dq(u32 dq_in_group) |
Marek Vasut | 7481b69 | 2015-07-12 22:11:55 +0200 | [diff] [blame] | 373 | { |
| 374 | writel(dq_in_group, &sdr_scc_mgr->dq_ena); |
| 375 | } |
| 376 | |
| 377 | /* load up dm config settings */ |
Marek Vasut | 8af9ca0 | 2015-08-02 19:42:26 +0200 | [diff] [blame] | 378 | static void scc_mgr_load_dm(u32 dm) |
Marek Vasut | 7481b69 | 2015-07-12 22:11:55 +0200 | [diff] [blame] | 379 | { |
| 380 | writel(dm, &sdr_scc_mgr->dm_ena); |
| 381 | } |
| 382 | |
Marek Vasut | 1d3cde3 | 2015-07-12 23:25:21 +0200 | [diff] [blame] | 383 | /** |
| 384 | * scc_mgr_set_all_ranks() - Set SCC Manager register for all ranks |
| 385 | * @off: Base offset in SCC Manager space |
| 386 | * @grp: Read/Write group |
| 387 | * @val: Value to be set |
| 388 | * @update: If non-zero, trigger SCC Manager update for all ranks |
| 389 | * |
| 390 | * This function sets the SCC Manager (Scan Chain Control Manager) register |
| 391 | * and optionally triggers the SCC update for all ranks. |
| 392 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 393 | static void scc_mgr_set_all_ranks(struct socfpga_sdrseq *seq, |
| 394 | const u32 off, const u32 grp, const u32 val, |
Marek Vasut | 1d3cde3 | 2015-07-12 23:25:21 +0200 | [diff] [blame] | 395 | const int update) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 396 | { |
Marek Vasut | 1d3cde3 | 2015-07-12 23:25:21 +0200 | [diff] [blame] | 397 | u32 r; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 398 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 399 | for (r = 0; r < seq->rwcfg->mem_number_of_ranks; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 400 | r += NUM_RANKS_PER_SHADOW_REG) { |
Marek Vasut | 1d3cde3 | 2015-07-12 23:25:21 +0200 | [diff] [blame] | 401 | scc_mgr_set(off, grp, val); |
Marek Vasut | 4972282 | 2015-07-12 23:14:33 +0200 | [diff] [blame] | 402 | |
Marek Vasut | 1d3cde3 | 2015-07-12 23:25:21 +0200 | [diff] [blame] | 403 | if (update || (r == 0)) { |
| 404 | writel(grp, &sdr_scc_mgr->dqs_ena); |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 405 | writel(0, &sdr_scc_mgr->update); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 406 | } |
| 407 | } |
| 408 | } |
| 409 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 410 | static void scc_mgr_set_dqs_en_phase_all_ranks(struct socfpga_sdrseq *seq, |
| 411 | u32 read_group, u32 phase) |
Marek Vasut | 1d3cde3 | 2015-07-12 23:25:21 +0200 | [diff] [blame] | 412 | { |
| 413 | /* |
| 414 | * USER although the h/w doesn't support different phases per |
| 415 | * shadow register, for simplicity our scc manager modeling |
| 416 | * keeps different phase settings per shadow reg, and it's |
| 417 | * important for us to keep them in sync to match h/w. |
| 418 | * for efficiency, the scan chain update should occur only |
| 419 | * once to sr0. |
| 420 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 421 | scc_mgr_set_all_ranks(seq, SCC_MGR_DQS_EN_PHASE_OFFSET, |
Marek Vasut | 1d3cde3 | 2015-07-12 23:25:21 +0200 | [diff] [blame] | 422 | read_group, phase, 0); |
| 423 | } |
| 424 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 425 | static void scc_mgr_set_dqdqs_output_phase_all_ranks(struct socfpga_sdrseq *seq, |
| 426 | u32 write_group, u32 phase) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 427 | { |
Marek Vasut | 1d3cde3 | 2015-07-12 23:25:21 +0200 | [diff] [blame] | 428 | /* |
| 429 | * USER although the h/w doesn't support different phases per |
| 430 | * shadow register, for simplicity our scc manager modeling |
| 431 | * keeps different phase settings per shadow reg, and it's |
| 432 | * important for us to keep them in sync to match h/w. |
| 433 | * for efficiency, the scan chain update should occur only |
| 434 | * once to sr0. |
| 435 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 436 | scc_mgr_set_all_ranks(seq, SCC_MGR_DQDQS_OUT_PHASE_OFFSET, |
Marek Vasut | 1d3cde3 | 2015-07-12 23:25:21 +0200 | [diff] [blame] | 437 | write_group, phase, 0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 438 | } |
| 439 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 440 | static void scc_mgr_set_dqs_en_delay_all_ranks(struct socfpga_sdrseq *seq, |
| 441 | u32 read_group, u32 delay) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 442 | { |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 443 | /* |
| 444 | * In shadow register mode, the T11 settings are stored in |
| 445 | * registers in the core, which are updated by the DQS_ENA |
| 446 | * signals. Not issuing the SCC_MGR_UPD command allows us to |
| 447 | * save lots of rank switching overhead, by calling |
| 448 | * select_shadow_regs_for_update with update_scan_chains |
| 449 | * set to 0. |
| 450 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 451 | scc_mgr_set_all_ranks(seq, SCC_MGR_DQS_EN_DELAY_OFFSET, |
Marek Vasut | 1d3cde3 | 2015-07-12 23:25:21 +0200 | [diff] [blame] | 452 | read_group, delay, 1); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 453 | } |
| 454 | |
Marek Vasut | e62f691 | 2015-07-12 23:39:06 +0200 | [diff] [blame] | 455 | /** |
| 456 | * scc_mgr_set_oct_out1_delay() - Set OCT output delay |
| 457 | * @write_group: Write group |
| 458 | * @delay: Delay value |
| 459 | * |
| 460 | * This function sets the OCT output delay in SCC manager. |
| 461 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 462 | static void scc_mgr_set_oct_out1_delay(struct socfpga_sdrseq *seq, |
| 463 | const u32 write_group, const u32 delay) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 464 | { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 465 | const int ratio = seq->rwcfg->mem_if_read_dqs_width / |
| 466 | seq->rwcfg->mem_if_write_dqs_width; |
Marek Vasut | e62f691 | 2015-07-12 23:39:06 +0200 | [diff] [blame] | 467 | const int base = write_group * ratio; |
| 468 | int i; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 469 | /* |
| 470 | * Load the setting in the SCC manager |
| 471 | * Although OCT affects only write data, the OCT delay is controlled |
| 472 | * by the DQS logic block which is instantiated once per read group. |
| 473 | * For protocols where a write group consists of multiple read groups, |
| 474 | * the setting must be set multiple times. |
| 475 | */ |
Marek Vasut | e62f691 | 2015-07-12 23:39:06 +0200 | [diff] [blame] | 476 | for (i = 0; i < ratio; i++) |
| 477 | scc_mgr_set(SCC_MGR_OCT_OUT1_DELAY_OFFSET, base + i, delay); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 478 | } |
| 479 | |
Marek Vasut | 3b8e5b0 | 2015-07-19 01:32:55 +0200 | [diff] [blame] | 480 | /** |
| 481 | * scc_mgr_set_hhp_extras() - Set HHP extras. |
| 482 | * |
| 483 | * Load the fixed setting in the SCC manager HHP extras. |
| 484 | */ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 485 | static void scc_mgr_set_hhp_extras(void) |
| 486 | { |
| 487 | /* |
| 488 | * Load the fixed setting in the SCC manager |
Marek Vasut | 3b8e5b0 | 2015-07-19 01:32:55 +0200 | [diff] [blame] | 489 | * bits: 0:0 = 1'b1 - DQS bypass |
| 490 | * bits: 1:1 = 1'b1 - DQ bypass |
| 491 | * bits: 4:2 = 3'b001 - rfifo_mode |
| 492 | * bits: 6:5 = 2'b01 - rfifo clock_select |
| 493 | * bits: 7:7 = 1'b0 - separate gating from ungating setting |
| 494 | * bits: 8:8 = 1'b0 - separate OE from Output delay setting |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 495 | */ |
Marek Vasut | 3b8e5b0 | 2015-07-19 01:32:55 +0200 | [diff] [blame] | 496 | const u32 value = (0 << 8) | (0 << 7) | (1 << 5) | |
| 497 | (1 << 2) | (1 << 1) | (1 << 0); |
| 498 | const u32 addr = SDR_PHYGRP_SCCGRP_ADDRESS | |
| 499 | SCC_MGR_HHP_GLOBALS_OFFSET | |
| 500 | SCC_MGR_HHP_EXTRAS_OFFSET; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 501 | |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 502 | debug_cond(DLEVEL >= 1, "%s:%d Setting HHP Extras\n", |
Marek Vasut | 3b8e5b0 | 2015-07-19 01:32:55 +0200 | [diff] [blame] | 503 | __func__, __LINE__); |
| 504 | writel(value, addr); |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 505 | debug_cond(DLEVEL >= 1, "%s:%d Done Setting HHP Extras\n", |
Marek Vasut | 3b8e5b0 | 2015-07-19 01:32:55 +0200 | [diff] [blame] | 506 | __func__, __LINE__); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 507 | } |
| 508 | |
Marek Vasut | 08bcb98 | 2015-07-20 04:41:53 +0200 | [diff] [blame] | 509 | /** |
| 510 | * scc_mgr_zero_all() - Zero all DQS config |
| 511 | * |
| 512 | * Zero all DQS config. |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 513 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 514 | static void scc_mgr_zero_all(struct socfpga_sdrseq *seq) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 515 | { |
Marek Vasut | 08bcb98 | 2015-07-20 04:41:53 +0200 | [diff] [blame] | 516 | int i, r; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 517 | |
| 518 | /* |
| 519 | * USER Zero all DQS config settings, across all groups and all |
| 520 | * shadow registers |
| 521 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 522 | for (r = 0; r < seq->rwcfg->mem_number_of_ranks; |
Marek Vasut | 08bcb98 | 2015-07-20 04:41:53 +0200 | [diff] [blame] | 523 | r += NUM_RANKS_PER_SHADOW_REG) { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 524 | for (i = 0; i < seq->rwcfg->mem_if_read_dqs_width; i++) { |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 525 | /* |
| 526 | * The phases actually don't exist on a per-rank basis, |
| 527 | * but there's no harm updating them several times, so |
| 528 | * let's keep the code simple. |
| 529 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 530 | scc_mgr_set_dqs_bus_in_delay(i, |
| 531 | seq->iocfg->dqs_in_reserve |
| 532 | ); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 533 | scc_mgr_set_dqs_en_phase(i, 0); |
| 534 | scc_mgr_set_dqs_en_delay(i, 0); |
| 535 | } |
| 536 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 537 | for (i = 0; i < seq->rwcfg->mem_if_write_dqs_width; i++) { |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 538 | scc_mgr_set_dqdqs_output_phase(i, 0); |
Marek Vasut | 08bcb98 | 2015-07-20 04:41:53 +0200 | [diff] [blame] | 539 | /* Arria V/Cyclone V don't have out2. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 540 | scc_mgr_set_oct_out1_delay(seq, i, |
| 541 | seq->iocfg->dqs_out_reserve); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 542 | } |
| 543 | } |
| 544 | |
Marek Vasut | 08bcb98 | 2015-07-20 04:41:53 +0200 | [diff] [blame] | 545 | /* Multicast to all DQS group enables. */ |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 546 | writel(0xff, &sdr_scc_mgr->dqs_ena); |
| 547 | writel(0, &sdr_scc_mgr->update); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 548 | } |
| 549 | |
Marek Vasut | 0341de4 | 2015-07-17 02:06:20 +0200 | [diff] [blame] | 550 | /** |
| 551 | * scc_set_bypass_mode() - Set bypass mode and trigger SCC update |
| 552 | * @write_group: Write group |
| 553 | * |
| 554 | * Set bypass mode and trigger SCC update. |
| 555 | */ |
| 556 | static void scc_set_bypass_mode(const u32 write_group) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 557 | { |
Marek Vasut | 0341de4 | 2015-07-17 02:06:20 +0200 | [diff] [blame] | 558 | /* Multicast to all DQ enables. */ |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 559 | writel(0xff, &sdr_scc_mgr->dq_ena); |
| 560 | writel(0xff, &sdr_scc_mgr->dm_ena); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 561 | |
Marek Vasut | 0341de4 | 2015-07-17 02:06:20 +0200 | [diff] [blame] | 562 | /* Update current DQS IO enable. */ |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 563 | writel(0, &sdr_scc_mgr->dqs_io_ena); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 564 | |
Marek Vasut | 0341de4 | 2015-07-17 02:06:20 +0200 | [diff] [blame] | 565 | /* Update the DQS logic. */ |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 566 | writel(write_group, &sdr_scc_mgr->dqs_ena); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 567 | |
Marek Vasut | 0341de4 | 2015-07-17 02:06:20 +0200 | [diff] [blame] | 568 | /* Hit update. */ |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 569 | writel(0, &sdr_scc_mgr->update); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 570 | } |
| 571 | |
Marek Vasut | 5a4379e | 2015-07-13 00:30:09 +0200 | [diff] [blame] | 572 | /** |
| 573 | * scc_mgr_load_dqs_for_write_group() - Load DQS settings for Write Group |
| 574 | * @write_group: Write group |
| 575 | * |
| 576 | * Load DQS settings for Write Group, do not trigger SCC update. |
| 577 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 578 | static void scc_mgr_load_dqs_for_write_group(struct socfpga_sdrseq *seq, |
| 579 | const u32 write_group) |
Marek Vasut | 7481b69 | 2015-07-12 22:11:55 +0200 | [diff] [blame] | 580 | { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 581 | const int ratio = seq->rwcfg->mem_if_read_dqs_width / |
| 582 | seq->rwcfg->mem_if_write_dqs_width; |
Marek Vasut | 5a4379e | 2015-07-13 00:30:09 +0200 | [diff] [blame] | 583 | const int base = write_group * ratio; |
| 584 | int i; |
Marek Vasut | 7481b69 | 2015-07-12 22:11:55 +0200 | [diff] [blame] | 585 | /* |
Marek Vasut | 5a4379e | 2015-07-13 00:30:09 +0200 | [diff] [blame] | 586 | * Load the setting in the SCC manager |
Marek Vasut | 7481b69 | 2015-07-12 22:11:55 +0200 | [diff] [blame] | 587 | * Although OCT affects only write data, the OCT delay is controlled |
| 588 | * by the DQS logic block which is instantiated once per read group. |
| 589 | * For protocols where a write group consists of multiple read groups, |
Marek Vasut | 5a4379e | 2015-07-13 00:30:09 +0200 | [diff] [blame] | 590 | * the setting must be set multiple times. |
Marek Vasut | 7481b69 | 2015-07-12 22:11:55 +0200 | [diff] [blame] | 591 | */ |
Marek Vasut | 5a4379e | 2015-07-13 00:30:09 +0200 | [diff] [blame] | 592 | for (i = 0; i < ratio; i++) |
| 593 | writel(base + i, &sdr_scc_mgr->dqs_ena); |
Marek Vasut | 7481b69 | 2015-07-12 22:11:55 +0200 | [diff] [blame] | 594 | } |
| 595 | |
Marek Vasut | 62d3c69 | 2015-07-20 08:41:04 +0200 | [diff] [blame] | 596 | /** |
| 597 | * scc_mgr_zero_group() - Zero all configs for a group |
| 598 | * |
| 599 | * Zero DQ, DM, DQS and OCT configs for a group. |
| 600 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 601 | static void scc_mgr_zero_group(struct socfpga_sdrseq *seq, |
| 602 | const u32 write_group, const int out_only) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 603 | { |
Marek Vasut | 62d3c69 | 2015-07-20 08:41:04 +0200 | [diff] [blame] | 604 | int i, r; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 605 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 606 | for (r = 0; r < seq->rwcfg->mem_number_of_ranks; |
Marek Vasut | 62d3c69 | 2015-07-20 08:41:04 +0200 | [diff] [blame] | 607 | r += NUM_RANKS_PER_SHADOW_REG) { |
| 608 | /* Zero all DQ config settings. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 609 | for (i = 0; i < seq->rwcfg->mem_dq_per_write_dqs; i++) { |
Marek Vasut | cab8079 | 2015-07-12 22:07:33 +0200 | [diff] [blame] | 610 | scc_mgr_set_dq_out1_delay(i, 0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 611 | if (!out_only) |
Marek Vasut | cab8079 | 2015-07-12 22:07:33 +0200 | [diff] [blame] | 612 | scc_mgr_set_dq_in_delay(i, 0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 613 | } |
| 614 | |
Marek Vasut | 62d3c69 | 2015-07-20 08:41:04 +0200 | [diff] [blame] | 615 | /* Multicast to all DQ enables. */ |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 616 | writel(0xff, &sdr_scc_mgr->dq_ena); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 617 | |
Marek Vasut | 62d3c69 | 2015-07-20 08:41:04 +0200 | [diff] [blame] | 618 | /* Zero all DM config settings. */ |
Marek Vasut | f4d3862 | 2016-04-04 21:16:18 +0200 | [diff] [blame] | 619 | for (i = 0; i < RW_MGR_NUM_DM_PER_WRITE_GROUP; i++) { |
| 620 | if (!out_only) |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 621 | scc_mgr_set_dm_in_delay(seq, i, 0); |
| 622 | scc_mgr_set_dm_out1_delay(seq, i, 0); |
Marek Vasut | f4d3862 | 2016-04-04 21:16:18 +0200 | [diff] [blame] | 623 | } |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 624 | |
Marek Vasut | 62d3c69 | 2015-07-20 08:41:04 +0200 | [diff] [blame] | 625 | /* Multicast to all DM enables. */ |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 626 | writel(0xff, &sdr_scc_mgr->dm_ena); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 627 | |
Marek Vasut | 62d3c69 | 2015-07-20 08:41:04 +0200 | [diff] [blame] | 628 | /* Zero all DQS IO settings. */ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 629 | if (!out_only) |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 630 | scc_mgr_set_dqs_io_in_delay(seq, 0); |
Marek Vasut | 62d3c69 | 2015-07-20 08:41:04 +0200 | [diff] [blame] | 631 | |
| 632 | /* Arria V/Cyclone V don't have out2. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 633 | scc_mgr_set_dqs_out1_delay(seq, seq->iocfg->dqs_out_reserve); |
| 634 | scc_mgr_set_oct_out1_delay(seq, write_group, |
| 635 | seq->iocfg->dqs_out_reserve); |
| 636 | scc_mgr_load_dqs_for_write_group(seq, write_group); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 637 | |
Marek Vasut | 62d3c69 | 2015-07-20 08:41:04 +0200 | [diff] [blame] | 638 | /* Multicast to all DQS IO enables (only 1 in total). */ |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 639 | writel(0, &sdr_scc_mgr->dqs_io_ena); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 640 | |
Marek Vasut | 62d3c69 | 2015-07-20 08:41:04 +0200 | [diff] [blame] | 641 | /* Hit update to zero everything. */ |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 642 | writel(0, &sdr_scc_mgr->update); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 643 | } |
| 644 | } |
| 645 | |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 646 | /* |
| 647 | * apply and load a particular input delay for the DQ pins in a group |
| 648 | * group_bgn is the index of the first dq pin (in the write group) |
| 649 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 650 | static void scc_mgr_apply_group_dq_in_delay(struct socfpga_sdrseq *seq, |
| 651 | u32 group_bgn, u32 delay) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 652 | { |
Marek Vasut | 8af9ca0 | 2015-08-02 19:42:26 +0200 | [diff] [blame] | 653 | u32 i, p; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 654 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 655 | for (i = 0, p = group_bgn; i < seq->rwcfg->mem_dq_per_read_dqs; |
| 656 | i++, p++) { |
Marek Vasut | cab8079 | 2015-07-12 22:07:33 +0200 | [diff] [blame] | 657 | scc_mgr_set_dq_in_delay(p, delay); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 658 | scc_mgr_load_dq(p); |
| 659 | } |
| 660 | } |
| 661 | |
Marek Vasut | cd64950 | 2015-07-17 05:42:49 +0200 | [diff] [blame] | 662 | /** |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 663 | * scc_mgr_apply_group_dq_out1_delay() - Apply and load an output delay for the |
| 664 | * DQ pins in a group |
Marek Vasut | cd64950 | 2015-07-17 05:42:49 +0200 | [diff] [blame] | 665 | * @delay: Delay value |
| 666 | * |
| 667 | * Apply and load a particular output delay for the DQ pins in a group. |
| 668 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 669 | static void scc_mgr_apply_group_dq_out1_delay(struct socfpga_sdrseq *seq, |
| 670 | const u32 delay) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 671 | { |
Marek Vasut | cd64950 | 2015-07-17 05:42:49 +0200 | [diff] [blame] | 672 | int i; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 673 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 674 | for (i = 0; i < seq->rwcfg->mem_dq_per_write_dqs; i++) { |
Marek Vasut | cd64950 | 2015-07-17 05:42:49 +0200 | [diff] [blame] | 675 | scc_mgr_set_dq_out1_delay(i, delay); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 676 | scc_mgr_load_dq(i); |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | /* apply and load a particular output delay for the DM pins in a group */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 681 | static void scc_mgr_apply_group_dm_out1_delay(struct socfpga_sdrseq *seq, |
| 682 | u32 delay1) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 683 | { |
Marek Vasut | 8af9ca0 | 2015-08-02 19:42:26 +0200 | [diff] [blame] | 684 | u32 i; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 685 | |
| 686 | for (i = 0; i < RW_MGR_NUM_DM_PER_WRITE_GROUP; i++) { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 687 | scc_mgr_set_dm_out1_delay(seq, i, delay1); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 688 | scc_mgr_load_dm(i); |
| 689 | } |
| 690 | } |
| 691 | |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 692 | /* apply and load delay on both DQS and OCT out1 */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 693 | static void scc_mgr_apply_group_dqs_io_and_oct_out1(struct socfpga_sdrseq *seq, |
| 694 | u32 write_group, u32 delay) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 695 | { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 696 | scc_mgr_set_dqs_out1_delay(seq, delay); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 697 | scc_mgr_load_dqs_io(); |
| 698 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 699 | scc_mgr_set_oct_out1_delay(seq, write_group, delay); |
| 700 | scc_mgr_load_dqs_for_write_group(seq, write_group); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 701 | } |
| 702 | |
Marek Vasut | 484fb3b | 2015-07-17 05:33:28 +0200 | [diff] [blame] | 703 | /** |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 704 | * scc_mgr_apply_group_all_out_delay_add() - Apply a delay to the entire output |
| 705 | * side: DQ, DM, DQS, OCT |
Marek Vasut | 484fb3b | 2015-07-17 05:33:28 +0200 | [diff] [blame] | 706 | * @write_group: Write group |
| 707 | * @delay: Delay value |
| 708 | * |
| 709 | * Apply a delay to the entire output side: DQ, DM, DQS, OCT. |
| 710 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 711 | static void scc_mgr_apply_group_all_out_delay_add(struct socfpga_sdrseq *seq, |
| 712 | const u32 write_group, |
Marek Vasut | 20bfb9d | 2015-07-17 05:30:14 +0200 | [diff] [blame] | 713 | const u32 delay) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 714 | { |
Marek Vasut | 20bfb9d | 2015-07-17 05:30:14 +0200 | [diff] [blame] | 715 | u32 i, new_delay; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 716 | |
Marek Vasut | 20bfb9d | 2015-07-17 05:30:14 +0200 | [diff] [blame] | 717 | /* DQ shift */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 718 | for (i = 0; i < seq->rwcfg->mem_dq_per_write_dqs; i++) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 719 | scc_mgr_load_dq(i); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 720 | |
Marek Vasut | 20bfb9d | 2015-07-17 05:30:14 +0200 | [diff] [blame] | 721 | /* DM shift */ |
| 722 | for (i = 0; i < RW_MGR_NUM_DM_PER_WRITE_GROUP; i++) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 723 | scc_mgr_load_dm(i); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 724 | |
Marek Vasut | 484fb3b | 2015-07-17 05:33:28 +0200 | [diff] [blame] | 725 | /* DQS shift */ |
| 726 | new_delay = READ_SCC_DQS_IO_OUT2_DELAY + delay; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 727 | if (new_delay > seq->iocfg->io_out2_delay_max) { |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 728 | debug_cond(DLEVEL >= 1, |
Marek Vasut | 484fb3b | 2015-07-17 05:33:28 +0200 | [diff] [blame] | 729 | "%s:%d (%u, %u) DQS: %u > %d; adding %u to OUT1\n", |
| 730 | __func__, __LINE__, write_group, delay, new_delay, |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 731 | seq->iocfg->io_out2_delay_max, |
| 732 | new_delay - seq->iocfg->io_out2_delay_max); |
| 733 | new_delay -= seq->iocfg->io_out2_delay_max; |
| 734 | scc_mgr_set_dqs_out1_delay(seq, new_delay); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | scc_mgr_load_dqs_io(); |
| 738 | |
Marek Vasut | 484fb3b | 2015-07-17 05:33:28 +0200 | [diff] [blame] | 739 | /* OCT shift */ |
| 740 | new_delay = READ_SCC_OCT_OUT2_DELAY + delay; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 741 | if (new_delay > seq->iocfg->io_out2_delay_max) { |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 742 | debug_cond(DLEVEL >= 1, |
Marek Vasut | 484fb3b | 2015-07-17 05:33:28 +0200 | [diff] [blame] | 743 | "%s:%d (%u, %u) DQS: %u > %d; adding %u to OUT1\n", |
| 744 | __func__, __LINE__, write_group, delay, |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 745 | new_delay, seq->iocfg->io_out2_delay_max, |
| 746 | new_delay - seq->iocfg->io_out2_delay_max); |
| 747 | new_delay -= seq->iocfg->io_out2_delay_max; |
| 748 | scc_mgr_set_oct_out1_delay(seq, write_group, new_delay); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 749 | } |
| 750 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 751 | scc_mgr_load_dqs_for_write_group(seq, write_group); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 752 | } |
| 753 | |
Marek Vasut | 788870f | 2015-07-19 02:18:21 +0200 | [diff] [blame] | 754 | /** |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 755 | * scc_mgr_apply_group_all_out_delay_add() - Apply a delay to the entire output |
| 756 | * side to all ranks |
Marek Vasut | 788870f | 2015-07-19 02:18:21 +0200 | [diff] [blame] | 757 | * @write_group: Write group |
| 758 | * @delay: Delay value |
| 759 | * |
| 760 | * Apply a delay to the entire output side (DQ, DM, DQS, OCT) to all ranks. |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 761 | */ |
Marek Vasut | 788870f | 2015-07-19 02:18:21 +0200 | [diff] [blame] | 762 | static void |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 763 | scc_mgr_apply_group_all_out_delay_add_all_ranks(struct socfpga_sdrseq *seq, |
| 764 | const u32 write_group, |
Marek Vasut | 788870f | 2015-07-19 02:18:21 +0200 | [diff] [blame] | 765 | const u32 delay) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 766 | { |
Marek Vasut | 788870f | 2015-07-19 02:18:21 +0200 | [diff] [blame] | 767 | int r; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 768 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 769 | for (r = 0; r < seq->rwcfg->mem_number_of_ranks; |
Marek Vasut | 788870f | 2015-07-19 02:18:21 +0200 | [diff] [blame] | 770 | r += NUM_RANKS_PER_SHADOW_REG) { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 771 | scc_mgr_apply_group_all_out_delay_add(seq, write_group, delay); |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 772 | writel(0, &sdr_scc_mgr->update); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 773 | } |
| 774 | } |
| 775 | |
Marek Vasut | 42e7860 | 2015-07-26 11:07:19 +0200 | [diff] [blame] | 776 | /** |
| 777 | * set_jump_as_return() - Return instruction optimization |
| 778 | * |
| 779 | * Optimization used to recover some slots in ddr3 inst_rom could be |
| 780 | * applied to other protocols if we wanted to |
| 781 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 782 | static void set_jump_as_return(struct socfpga_sdrseq *seq) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 783 | { |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 784 | /* |
Marek Vasut | 42e7860 | 2015-07-26 11:07:19 +0200 | [diff] [blame] | 785 | * To save space, we replace return with jump to special shared |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 786 | * RETURN instruction so we set the counter to large value so that |
Marek Vasut | 42e7860 | 2015-07-26 11:07:19 +0200 | [diff] [blame] | 787 | * we always jump. |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 788 | */ |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 789 | writel(0xff, &sdr_rw_load_mgr_regs->load_cntr0); |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 790 | writel(seq->rwcfg->rreturn, &sdr_rw_load_jump_mgr_regs->load_jump_add0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 791 | } |
| 792 | |
Marek Vasut | 98d279a | 2015-07-26 11:46:04 +0200 | [diff] [blame] | 793 | /** |
| 794 | * delay_for_n_mem_clocks() - Delay for N memory clocks |
| 795 | * @clocks: Length of the delay |
| 796 | * |
| 797 | * Delay for N memory clocks. |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 798 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 799 | static void delay_for_n_mem_clocks(struct socfpga_sdrseq *seq, |
| 800 | const u32 clocks) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 801 | { |
Marek Vasut | 50d7199 | 2015-07-26 11:11:28 +0200 | [diff] [blame] | 802 | u32 afi_clocks; |
Marek Vasut | 13ee438 | 2015-07-26 11:42:53 +0200 | [diff] [blame] | 803 | u16 c_loop; |
| 804 | u8 inner; |
| 805 | u8 outer; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 806 | |
| 807 | debug("%s:%d: clocks=%u ... start\n", __func__, __LINE__, clocks); |
| 808 | |
Marek Vasut | 4b203df | 2015-07-26 11:34:09 +0200 | [diff] [blame] | 809 | /* Scale (rounding up) to get afi clocks. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 810 | afi_clocks = DIV_ROUND_UP(clocks, seq->misccfg->afi_rate_ratio); |
Marek Vasut | 4b203df | 2015-07-26 11:34:09 +0200 | [diff] [blame] | 811 | if (afi_clocks) /* Temporary underflow protection */ |
| 812 | afi_clocks--; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 813 | |
| 814 | /* |
Marek Vasut | 50d7199 | 2015-07-26 11:11:28 +0200 | [diff] [blame] | 815 | * Note, we don't bother accounting for being off a little |
| 816 | * bit because of a few extra instructions in outer loops. |
| 817 | * Note, the loops have a test at the end, and do the test |
| 818 | * before the decrement, and so always perform the loop |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 819 | * 1 time more than the counter value |
| 820 | */ |
Marek Vasut | 13ee438 | 2015-07-26 11:42:53 +0200 | [diff] [blame] | 821 | c_loop = afi_clocks >> 16; |
| 822 | outer = c_loop ? 0xff : (afi_clocks >> 8); |
| 823 | inner = outer ? 0xff : afi_clocks; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 824 | |
| 825 | /* |
| 826 | * rom instructions are structured as follows: |
| 827 | * |
| 828 | * IDLE_LOOP2: jnz cntr0, TARGET_A |
| 829 | * IDLE_LOOP1: jnz cntr1, TARGET_B |
| 830 | * return |
| 831 | * |
| 832 | * so, when doing nested loops, TARGET_A is set to IDLE_LOOP2, and |
| 833 | * TARGET_B is set to IDLE_LOOP2 as well |
| 834 | * |
| 835 | * if we have no outer loop, though, then we can use IDLE_LOOP1 only, |
| 836 | * and set TARGET_B to IDLE_LOOP1 and we skip IDLE_LOOP2 entirely |
| 837 | * |
| 838 | * a little confusing, but it helps save precious space in the inst_rom |
| 839 | * and sequencer rom and keeps the delays more accurate and reduces |
| 840 | * overhead |
| 841 | */ |
Marek Vasut | 4b203df | 2015-07-26 11:34:09 +0200 | [diff] [blame] | 842 | if (afi_clocks < 0x100) { |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 843 | writel(SKIP_DELAY_LOOP_VALUE_OR_ZERO(inner), |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 844 | &sdr_rw_load_mgr_regs->load_cntr1); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 845 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 846 | writel(seq->rwcfg->idle_loop1, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 847 | &sdr_rw_load_jump_mgr_regs->load_jump_add1); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 848 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 849 | writel(seq->rwcfg->idle_loop1, SDR_PHYGRP_RWMGRGRP_ADDRESS | |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 850 | RW_MGR_RUN_SINGLE_GROUP_OFFSET); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 851 | } else { |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 852 | writel(SKIP_DELAY_LOOP_VALUE_OR_ZERO(inner), |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 853 | &sdr_rw_load_mgr_regs->load_cntr0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 854 | |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 855 | writel(SKIP_DELAY_LOOP_VALUE_OR_ZERO(outer), |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 856 | &sdr_rw_load_mgr_regs->load_cntr1); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 857 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 858 | writel(seq->rwcfg->idle_loop2, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 859 | &sdr_rw_load_jump_mgr_regs->load_jump_add0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 860 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 861 | writel(seq->rwcfg->idle_loop2, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 862 | &sdr_rw_load_jump_mgr_regs->load_jump_add1); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 863 | |
Marek Vasut | 7574c87 | 2015-07-26 11:44:54 +0200 | [diff] [blame] | 864 | do { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 865 | writel(seq->rwcfg->idle_loop2, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 866 | SDR_PHYGRP_RWMGRGRP_ADDRESS | |
| 867 | RW_MGR_RUN_SINGLE_GROUP_OFFSET); |
Marek Vasut | 7574c87 | 2015-07-26 11:44:54 +0200 | [diff] [blame] | 868 | } while (c_loop-- != 0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 869 | } |
| 870 | debug("%s:%d clocks=%u ... end\n", __func__, __LINE__, clocks); |
| 871 | } |
| 872 | |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 873 | static void delay_for_n_ns(struct socfpga_sdrseq *seq, const u32 ns) |
| 874 | { |
| 875 | delay_for_n_mem_clocks(seq, (ns * seq->misccfg->afi_clk_freq * |
| 876 | seq->misccfg->afi_rate_ratio) / 1000); |
| 877 | } |
| 878 | |
Marek Vasut | 8bf9227 | 2015-07-13 00:44:30 +0200 | [diff] [blame] | 879 | /** |
| 880 | * rw_mgr_mem_init_load_regs() - Load instruction registers |
| 881 | * @cntr0: Counter 0 value |
| 882 | * @cntr1: Counter 1 value |
| 883 | * @cntr2: Counter 2 value |
| 884 | * @jump: Jump instruction value |
| 885 | * |
| 886 | * Load instruction registers. |
| 887 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 888 | static void rw_mgr_mem_init_load_regs(struct socfpga_sdrseq *seq, |
| 889 | u32 cntr0, u32 cntr1, u32 cntr2, u32 jump) |
Marek Vasut | 8bf9227 | 2015-07-13 00:44:30 +0200 | [diff] [blame] | 890 | { |
Marek Vasut | 8af9ca0 | 2015-08-02 19:42:26 +0200 | [diff] [blame] | 891 | u32 grpaddr = SDR_PHYGRP_RWMGRGRP_ADDRESS | |
Marek Vasut | 8bf9227 | 2015-07-13 00:44:30 +0200 | [diff] [blame] | 892 | RW_MGR_RUN_SINGLE_GROUP_OFFSET; |
| 893 | |
| 894 | /* Load counters */ |
| 895 | writel(SKIP_DELAY_LOOP_VALUE_OR_ZERO(cntr0), |
| 896 | &sdr_rw_load_mgr_regs->load_cntr0); |
| 897 | writel(SKIP_DELAY_LOOP_VALUE_OR_ZERO(cntr1), |
| 898 | &sdr_rw_load_mgr_regs->load_cntr1); |
| 899 | writel(SKIP_DELAY_LOOP_VALUE_OR_ZERO(cntr2), |
| 900 | &sdr_rw_load_mgr_regs->load_cntr2); |
| 901 | |
| 902 | /* Load jump address */ |
| 903 | writel(jump, &sdr_rw_load_jump_mgr_regs->load_jump_add0); |
| 904 | writel(jump, &sdr_rw_load_jump_mgr_regs->load_jump_add1); |
| 905 | writel(jump, &sdr_rw_load_jump_mgr_regs->load_jump_add2); |
| 906 | |
| 907 | /* Execute count instruction */ |
| 908 | writel(jump, grpaddr); |
| 909 | } |
| 910 | |
Marek Vasut | c577ab5 | 2015-07-13 00:51:05 +0200 | [diff] [blame] | 911 | /** |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 912 | * rw_mgr_mem_load_user_ddr2() - Load user calibration values for DDR2 |
| 913 | * @handoff: Indicate whether this is initialization or handoff phase |
| 914 | * |
| 915 | * Load user calibration values and optionally precharge the banks. |
| 916 | */ |
| 917 | static void rw_mgr_mem_load_user_ddr2(struct socfpga_sdrseq *seq, |
| 918 | const int handoff) |
| 919 | { |
| 920 | u32 grpaddr = SDR_PHYGRP_RWMGRGRP_ADDRESS | |
| 921 | RW_MGR_RUN_SINGLE_GROUP_OFFSET; |
| 922 | u32 r; |
| 923 | |
| 924 | for (r = 0; r < seq->rwcfg->mem_number_of_ranks; r++) { |
| 925 | /* set rank */ |
| 926 | set_rank_and_odt_mask(seq, r, RW_MGR_ODT_MODE_OFF); |
| 927 | |
| 928 | /* precharge all banks ... */ |
| 929 | writel(seq->rwcfg->precharge_all, grpaddr); |
| 930 | |
| 931 | writel(seq->rwcfg->emr2, grpaddr); |
| 932 | writel(seq->rwcfg->emr3, grpaddr); |
| 933 | writel(seq->rwcfg->emr, grpaddr); |
| 934 | |
| 935 | if (handoff) { |
| 936 | writel(seq->rwcfg->mr_user, grpaddr); |
| 937 | continue; |
| 938 | } |
| 939 | |
| 940 | writel(seq->rwcfg->mr_dll_reset, grpaddr); |
| 941 | |
| 942 | writel(seq->rwcfg->precharge_all, grpaddr); |
| 943 | |
| 944 | writel(seq->rwcfg->refresh, grpaddr); |
| 945 | delay_for_n_ns(seq, 200); |
| 946 | writel(seq->rwcfg->refresh, grpaddr); |
| 947 | delay_for_n_ns(seq, 200); |
| 948 | |
| 949 | writel(seq->rwcfg->mr_calib, grpaddr); |
| 950 | writel(/*seq->rwcfg->*/0x0b, grpaddr); // EMR_OCD_ENABLE |
| 951 | writel(seq->rwcfg->emr, grpaddr); |
| 952 | delay_for_n_mem_clocks(seq, 200); |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | /** |
| 957 | * rw_mgr_mem_load_user_ddr3() - Load user calibration values |
Marek Vasut | c577ab5 | 2015-07-13 00:51:05 +0200 | [diff] [blame] | 958 | * @fin1: Final instruction 1 |
| 959 | * @fin2: Final instruction 2 |
| 960 | * @precharge: If 1, precharge the banks at the end |
| 961 | * |
| 962 | * Load user calibration values and optionally precharge the banks. |
| 963 | */ |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 964 | static void rw_mgr_mem_load_user_ddr3(struct socfpga_sdrseq *seq, |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 965 | const u32 fin1, const u32 fin2, |
Marek Vasut | c577ab5 | 2015-07-13 00:51:05 +0200 | [diff] [blame] | 966 | const int precharge) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 967 | { |
Marek Vasut | c577ab5 | 2015-07-13 00:51:05 +0200 | [diff] [blame] | 968 | u32 grpaddr = SDR_PHYGRP_RWMGRGRP_ADDRESS | |
| 969 | RW_MGR_RUN_SINGLE_GROUP_OFFSET; |
| 970 | u32 r; |
| 971 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 972 | for (r = 0; r < seq->rwcfg->mem_number_of_ranks; r++) { |
Marek Vasut | c577ab5 | 2015-07-13 00:51:05 +0200 | [diff] [blame] | 973 | /* set rank */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 974 | set_rank_and_odt_mask(seq, r, RW_MGR_ODT_MODE_OFF); |
Marek Vasut | c577ab5 | 2015-07-13 00:51:05 +0200 | [diff] [blame] | 975 | |
| 976 | /* precharge all banks ... */ |
| 977 | if (precharge) |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 978 | writel(seq->rwcfg->precharge_all, grpaddr); |
Marek Vasut | c577ab5 | 2015-07-13 00:51:05 +0200 | [diff] [blame] | 979 | |
| 980 | /* |
| 981 | * USER Use Mirror-ed commands for odd ranks if address |
| 982 | * mirrorring is on |
| 983 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 984 | if ((seq->rwcfg->mem_address_mirroring >> r) & 0x1) { |
| 985 | set_jump_as_return(seq); |
| 986 | writel(seq->rwcfg->mrs2_mirr, grpaddr); |
| 987 | delay_for_n_mem_clocks(seq, 4); |
| 988 | set_jump_as_return(seq); |
| 989 | writel(seq->rwcfg->mrs3_mirr, grpaddr); |
| 990 | delay_for_n_mem_clocks(seq, 4); |
| 991 | set_jump_as_return(seq); |
| 992 | writel(seq->rwcfg->mrs1_mirr, grpaddr); |
| 993 | delay_for_n_mem_clocks(seq, 4); |
| 994 | set_jump_as_return(seq); |
Marek Vasut | c577ab5 | 2015-07-13 00:51:05 +0200 | [diff] [blame] | 995 | writel(fin1, grpaddr); |
| 996 | } else { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 997 | set_jump_as_return(seq); |
| 998 | writel(seq->rwcfg->mrs2, grpaddr); |
| 999 | delay_for_n_mem_clocks(seq, 4); |
| 1000 | set_jump_as_return(seq); |
| 1001 | writel(seq->rwcfg->mrs3, grpaddr); |
| 1002 | delay_for_n_mem_clocks(seq, 4); |
| 1003 | set_jump_as_return(seq); |
| 1004 | writel(seq->rwcfg->mrs1, grpaddr); |
| 1005 | set_jump_as_return(seq); |
Marek Vasut | c577ab5 | 2015-07-13 00:51:05 +0200 | [diff] [blame] | 1006 | writel(fin2, grpaddr); |
| 1007 | } |
| 1008 | |
| 1009 | if (precharge) |
| 1010 | continue; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1011 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1012 | set_jump_as_return(seq); |
| 1013 | writel(seq->rwcfg->zqcl, grpaddr); |
Marek Vasut | c577ab5 | 2015-07-13 00:51:05 +0200 | [diff] [blame] | 1014 | |
| 1015 | /* tZQinit = tDLLK = 512 ck cycles */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1016 | delay_for_n_mem_clocks(seq, 512); |
Marek Vasut | c577ab5 | 2015-07-13 00:51:05 +0200 | [diff] [blame] | 1017 | } |
| 1018 | } |
| 1019 | |
Marek Vasut | 1185e22 | 2015-07-26 10:57:06 +0200 | [diff] [blame] | 1020 | /** |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 1021 | * rw_mgr_mem_load_user() - Load user calibration values |
| 1022 | * @fin1: Final instruction 1 |
| 1023 | * @fin2: Final instruction 2 |
| 1024 | * @precharge: If 1, precharge the banks at the end |
| 1025 | * |
| 1026 | * Load user calibration values and optionally precharge the banks. |
| 1027 | */ |
| 1028 | static void rw_mgr_mem_load_user(struct socfpga_sdrseq *seq, |
| 1029 | const u32 fin1, const u32 fin2, |
| 1030 | const int precharge) |
| 1031 | { |
| 1032 | if (dram_is_ddr(2)) |
| 1033 | rw_mgr_mem_load_user_ddr2(seq, precharge); |
| 1034 | else if (dram_is_ddr(3)) |
| 1035 | rw_mgr_mem_load_user_ddr3(seq, fin1, fin2, precharge); |
| 1036 | else |
| 1037 | hang(); |
| 1038 | } |
| 1039 | /** |
Marek Vasut | 1185e22 | 2015-07-26 10:57:06 +0200 | [diff] [blame] | 1040 | * rw_mgr_mem_initialize() - Initialize RW Manager |
| 1041 | * |
| 1042 | * Initialize RW Manager. |
| 1043 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1044 | static void rw_mgr_mem_initialize(struct socfpga_sdrseq *seq) |
Marek Vasut | c577ab5 | 2015-07-13 00:51:05 +0200 | [diff] [blame] | 1045 | { |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1046 | debug("%s:%d\n", __func__, __LINE__); |
| 1047 | |
| 1048 | /* The reset / cke part of initialization is broadcasted to all ranks */ |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 1049 | if (dram_is_ddr(3)) { |
| 1050 | writel(RW_MGR_RANK_ALL, SDR_PHYGRP_RWMGRGRP_ADDRESS | |
| 1051 | RW_MGR_SET_CS_AND_ODT_MASK_OFFSET); |
| 1052 | } |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1053 | |
| 1054 | /* |
| 1055 | * Here's how you load register for a loop |
| 1056 | * Counters are located @ 0x800 |
| 1057 | * Jump address are located @ 0xC00 |
| 1058 | * For both, registers 0 to 3 are selected using bits 3 and 2, like |
| 1059 | * in 0x800, 0x804, 0x808, 0x80C and 0xC00, 0xC04, 0xC08, 0xC0C |
| 1060 | * I know this ain't pretty, but Avalon bus throws away the 2 least |
| 1061 | * significant bits |
| 1062 | */ |
| 1063 | |
Marek Vasut | 1185e22 | 2015-07-26 10:57:06 +0200 | [diff] [blame] | 1064 | /* Start with memory RESET activated */ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1065 | |
| 1066 | /* tINIT = 200us */ |
| 1067 | |
| 1068 | /* |
| 1069 | * 200us @ 266MHz (3.75 ns) ~ 54000 clock cycles |
| 1070 | * If a and b are the number of iteration in 2 nested loops |
| 1071 | * it takes the following number of cycles to complete the operation: |
| 1072 | * number_of_cycles = ((2 + n) * a + 2) * b |
| 1073 | * where n is the number of instruction in the inner loop |
| 1074 | * One possible solution is n = 0 , a = 256 , b = 106 => a = FF, |
| 1075 | * b = 6A |
| 1076 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1077 | rw_mgr_mem_init_load_regs(seq, seq->misccfg->tinit_cntr0_val, |
| 1078 | seq->misccfg->tinit_cntr1_val, |
| 1079 | seq->misccfg->tinit_cntr2_val, |
| 1080 | seq->rwcfg->init_reset_0_cke_0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1081 | |
Marek Vasut | 1185e22 | 2015-07-26 10:57:06 +0200 | [diff] [blame] | 1082 | /* Indicate that memory is stable. */ |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 1083 | writel(1, &phy_mgr_cfg->reset_mem_stbl); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1084 | |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 1085 | if (dram_is_ddr(2)) { |
| 1086 | writel(seq->rwcfg->nop, SDR_PHYGRP_RWMGRGRP_ADDRESS | |
| 1087 | RW_MGR_RUN_SINGLE_GROUP_OFFSET); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1088 | |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 1089 | /* Bring up clock enable. */ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1090 | |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 1091 | /* tXRP < 400 ck cycles */ |
| 1092 | delay_for_n_ns(seq, 400); |
| 1093 | } else if (dram_is_ddr(3)) { |
| 1094 | /* |
| 1095 | * transition the RESET to high |
| 1096 | * Wait for 500us |
| 1097 | */ |
| 1098 | |
| 1099 | /* |
| 1100 | * 500us @ 266MHz (3.75 ns) ~ 134000 clock cycles |
| 1101 | * If a and b are the number of iteration in 2 nested loops |
| 1102 | * it takes the following number of cycles to complete the |
| 1103 | * operation number_of_cycles = ((2 + n) * a + 2) * b |
| 1104 | * where n is the number of instruction in the inner loop |
| 1105 | * One possible solution is |
| 1106 | * n = 2 , a = 131 , b = 256 => a = 83, b = FF |
| 1107 | */ |
| 1108 | rw_mgr_mem_init_load_regs(seq, seq->misccfg->treset_cntr0_val, |
| 1109 | seq->misccfg->treset_cntr1_val, |
| 1110 | seq->misccfg->treset_cntr2_val, |
| 1111 | seq->rwcfg->init_reset_1_cke_0); |
| 1112 | /* Bring up clock enable. */ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1113 | |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 1114 | /* tXRP < 250 ck cycles */ |
| 1115 | delay_for_n_mem_clocks(seq, 250); |
| 1116 | } |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1117 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1118 | rw_mgr_mem_load_user(seq, seq->rwcfg->mrs0_dll_reset_mirr, |
| 1119 | seq->rwcfg->mrs0_dll_reset, 0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1120 | } |
| 1121 | |
Marek Vasut | c140275 | 2015-07-26 10:59:19 +0200 | [diff] [blame] | 1122 | /** |
| 1123 | * rw_mgr_mem_handoff() - Hand off the memory to user |
| 1124 | * |
| 1125 | * At the end of calibration we have to program the user settings in |
| 1126 | * and hand off the memory to the user. |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1127 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1128 | static void rw_mgr_mem_handoff(struct socfpga_sdrseq *seq) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1129 | { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1130 | rw_mgr_mem_load_user(seq, seq->rwcfg->mrs0_user_mirr, |
| 1131 | seq->rwcfg->mrs0_user, 1); |
Marek Vasut | c577ab5 | 2015-07-13 00:51:05 +0200 | [diff] [blame] | 1132 | /* |
Marek Vasut | c140275 | 2015-07-26 10:59:19 +0200 | [diff] [blame] | 1133 | * Need to wait tMOD (12CK or 15ns) time before issuing other |
| 1134 | * commands, but we will have plenty of NIOS cycles before actual |
| 1135 | * handoff so its okay. |
Marek Vasut | c577ab5 | 2015-07-13 00:51:05 +0200 | [diff] [blame] | 1136 | */ |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1137 | } |
| 1138 | |
Marek Vasut | adbaa2d | 2015-07-21 06:00:36 +0200 | [diff] [blame] | 1139 | /** |
| 1140 | * rw_mgr_mem_calibrate_write_test_issue() - Issue write test command |
| 1141 | * @group: Write Group |
| 1142 | * @use_dm: Use DM |
| 1143 | * |
| 1144 | * Issue write test command. Two variants are provided, one that just tests |
| 1145 | * a write pattern and another that tests datamask functionality. |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1146 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1147 | static void rw_mgr_mem_calibrate_write_test_issue(struct socfpga_sdrseq *seq, |
| 1148 | u32 group, u32 test_dm) |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1149 | { |
Marek Vasut | adbaa2d | 2015-07-21 06:00:36 +0200 | [diff] [blame] | 1150 | const u32 quick_write_mode = |
| 1151 | (STATIC_CALIB_STEPS & CALIB_SKIP_WRITES) && |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1152 | seq->misccfg->enable_super_quick_calibration; |
Marek Vasut | adbaa2d | 2015-07-21 06:00:36 +0200 | [diff] [blame] | 1153 | u32 mcc_instruction; |
| 1154 | u32 rw_wl_nop_cycles; |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1155 | |
| 1156 | /* |
| 1157 | * Set counter and jump addresses for the right |
| 1158 | * number of NOP cycles. |
| 1159 | * The number of supported NOP cycles can range from -1 to infinity |
| 1160 | * Three different cases are handled: |
| 1161 | * |
| 1162 | * 1. For a number of NOP cycles greater than 0, the RW Mgr looping |
| 1163 | * mechanism will be used to insert the right number of NOPs |
| 1164 | * |
| 1165 | * 2. For a number of NOP cycles equals to 0, the micro-instruction |
| 1166 | * issuing the write command will jump straight to the |
| 1167 | * micro-instruction that turns on DQS (for DDRx), or outputs write |
| 1168 | * data (for RLD), skipping |
| 1169 | * the NOP micro-instruction all together |
| 1170 | * |
| 1171 | * 3. A number of NOP cycles equal to -1 indicates that DQS must be |
| 1172 | * turned on in the same micro-instruction that issues the write |
| 1173 | * command. Then we need |
| 1174 | * to directly jump to the micro-instruction that sends out the data |
| 1175 | * |
| 1176 | * NOTE: Implementing this mechanism uses 2 RW Mgr jump-counters |
| 1177 | * (2 and 3). One jump-counter (0) is used to perform multiple |
| 1178 | * write-read operations. |
| 1179 | * one counter left to issue this command in "multiple-group" mode |
| 1180 | */ |
| 1181 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1182 | rw_wl_nop_cycles = seq->gbl.rw_wl_nop_cycles; |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1183 | |
| 1184 | if (rw_wl_nop_cycles == -1) { |
| 1185 | /* |
| 1186 | * CNTR 2 - We want to execute the special write operation that |
| 1187 | * turns on DQS right away and then skip directly to the |
| 1188 | * instruction that sends out the data. We set the counter to a |
| 1189 | * large number so that the jump is always taken. |
| 1190 | */ |
| 1191 | writel(0xFF, &sdr_rw_load_mgr_regs->load_cntr2); |
| 1192 | |
| 1193 | /* CNTR 3 - Not used */ |
| 1194 | if (test_dm) { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1195 | mcc_instruction = seq->rwcfg->lfsr_wr_rd_dm_bank_0_wl_1; |
| 1196 | writel(seq->rwcfg->lfsr_wr_rd_dm_bank_0_data, |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1197 | &sdr_rw_load_jump_mgr_regs->load_jump_add2); |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1198 | writel(seq->rwcfg->lfsr_wr_rd_dm_bank_0_nop, |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1199 | &sdr_rw_load_jump_mgr_regs->load_jump_add3); |
| 1200 | } else { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1201 | mcc_instruction = seq->rwcfg->lfsr_wr_rd_bank_0_wl_1; |
| 1202 | writel(seq->rwcfg->lfsr_wr_rd_bank_0_data, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 1203 | &sdr_rw_load_jump_mgr_regs->load_jump_add2); |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1204 | writel(seq->rwcfg->lfsr_wr_rd_bank_0_nop, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 1205 | &sdr_rw_load_jump_mgr_regs->load_jump_add3); |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1206 | } |
| 1207 | } else if (rw_wl_nop_cycles == 0) { |
| 1208 | /* |
| 1209 | * CNTR 2 - We want to skip the NOP operation and go straight |
| 1210 | * to the DQS enable instruction. We set the counter to a large |
| 1211 | * number so that the jump is always taken. |
| 1212 | */ |
| 1213 | writel(0xFF, &sdr_rw_load_mgr_regs->load_cntr2); |
| 1214 | |
| 1215 | /* CNTR 3 - Not used */ |
| 1216 | if (test_dm) { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1217 | mcc_instruction = seq->rwcfg->lfsr_wr_rd_dm_bank_0; |
| 1218 | writel(seq->rwcfg->lfsr_wr_rd_dm_bank_0_dqs, |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1219 | &sdr_rw_load_jump_mgr_regs->load_jump_add2); |
| 1220 | } else { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1221 | mcc_instruction = seq->rwcfg->lfsr_wr_rd_bank_0; |
| 1222 | writel(seq->rwcfg->lfsr_wr_rd_bank_0_dqs, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 1223 | &sdr_rw_load_jump_mgr_regs->load_jump_add2); |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1224 | } |
| 1225 | } else { |
| 1226 | /* |
| 1227 | * CNTR 2 - In this case we want to execute the next instruction |
| 1228 | * and NOT take the jump. So we set the counter to 0. The jump |
| 1229 | * address doesn't count. |
| 1230 | */ |
| 1231 | writel(0x0, &sdr_rw_load_mgr_regs->load_cntr2); |
| 1232 | writel(0x0, &sdr_rw_load_jump_mgr_regs->load_jump_add2); |
| 1233 | |
| 1234 | /* |
| 1235 | * CNTR 3 - Set the nop counter to the number of cycles we |
| 1236 | * need to loop for, minus 1. |
| 1237 | */ |
| 1238 | writel(rw_wl_nop_cycles - 1, &sdr_rw_load_mgr_regs->load_cntr3); |
| 1239 | if (test_dm) { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1240 | mcc_instruction = seq->rwcfg->lfsr_wr_rd_dm_bank_0; |
| 1241 | writel(seq->rwcfg->lfsr_wr_rd_dm_bank_0_nop, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 1242 | &sdr_rw_load_jump_mgr_regs->load_jump_add3); |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1243 | } else { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1244 | mcc_instruction = seq->rwcfg->lfsr_wr_rd_bank_0; |
| 1245 | writel(seq->rwcfg->lfsr_wr_rd_bank_0_nop, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 1246 | &sdr_rw_load_jump_mgr_regs->load_jump_add3); |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1247 | } |
| 1248 | } |
| 1249 | |
| 1250 | writel(0, SDR_PHYGRP_RWMGRGRP_ADDRESS | |
| 1251 | RW_MGR_RESET_READ_DATAPATH_OFFSET); |
| 1252 | |
| 1253 | if (quick_write_mode) |
| 1254 | writel(0x08, &sdr_rw_load_mgr_regs->load_cntr0); |
| 1255 | else |
| 1256 | writel(0x40, &sdr_rw_load_mgr_regs->load_cntr0); |
| 1257 | |
| 1258 | writel(mcc_instruction, &sdr_rw_load_jump_mgr_regs->load_jump_add0); |
| 1259 | |
| 1260 | /* |
| 1261 | * CNTR 1 - This is used to ensure enough time elapses |
| 1262 | * for read data to come back. |
| 1263 | */ |
| 1264 | writel(0x30, &sdr_rw_load_mgr_regs->load_cntr1); |
| 1265 | |
| 1266 | if (test_dm) { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1267 | writel(seq->rwcfg->lfsr_wr_rd_dm_bank_0_wait, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 1268 | &sdr_rw_load_jump_mgr_regs->load_jump_add1); |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1269 | } else { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1270 | writel(seq->rwcfg->lfsr_wr_rd_bank_0_wait, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 1271 | &sdr_rw_load_jump_mgr_regs->load_jump_add1); |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1272 | } |
| 1273 | |
Marek Vasut | adbaa2d | 2015-07-21 06:00:36 +0200 | [diff] [blame] | 1274 | writel(mcc_instruction, (SDR_PHYGRP_RWMGRGRP_ADDRESS | |
| 1275 | RW_MGR_RUN_SINGLE_GROUP_OFFSET) + |
| 1276 | (group << 2)); |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1277 | } |
| 1278 | |
Marek Vasut | c67d962 | 2015-07-21 05:57:11 +0200 | [diff] [blame] | 1279 | /** |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1280 | * rw_mgr_mem_calibrate_write_test() - Test writes, check for single/multiple |
| 1281 | * pass |
Marek Vasut | c67d962 | 2015-07-21 05:57:11 +0200 | [diff] [blame] | 1282 | * @rank_bgn: Rank number |
| 1283 | * @write_group: Write Group |
| 1284 | * @use_dm: Use DM |
| 1285 | * @all_correct: All bits must be correct in the mask |
| 1286 | * @bit_chk: Resulting bit mask after the test |
| 1287 | * @all_ranks: Test all ranks |
| 1288 | * |
| 1289 | * Test writes, can check for a single bit pass or multiple bit pass. |
| 1290 | */ |
Marek Vasut | bc773a1 | 2015-07-21 05:54:39 +0200 | [diff] [blame] | 1291 | static int |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1292 | rw_mgr_mem_calibrate_write_test(struct socfpga_sdrseq *seq, |
| 1293 | const u32 rank_bgn, const u32 write_group, |
Marek Vasut | bc773a1 | 2015-07-21 05:54:39 +0200 | [diff] [blame] | 1294 | const u32 use_dm, const u32 all_correct, |
| 1295 | u32 *bit_chk, const u32 all_ranks) |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1296 | { |
Marek Vasut | bc773a1 | 2015-07-21 05:54:39 +0200 | [diff] [blame] | 1297 | const u32 rank_end = all_ranks ? |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1298 | seq->rwcfg->mem_number_of_ranks : |
Marek Vasut | bc773a1 | 2015-07-21 05:54:39 +0200 | [diff] [blame] | 1299 | (rank_bgn + NUM_RANKS_PER_SHADOW_REG); |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1300 | const u32 shift_ratio = seq->rwcfg->mem_dq_per_write_dqs / |
| 1301 | seq->rwcfg->mem_virtual_groups_per_write_dqs; |
| 1302 | const u32 correct_mask_vg = seq->param.write_correct_mask_vg; |
Marek Vasut | bc773a1 | 2015-07-21 05:54:39 +0200 | [diff] [blame] | 1303 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1304 | u32 tmp_bit_chk, base_rw_mgr, group; |
Marek Vasut | bc773a1 | 2015-07-21 05:54:39 +0200 | [diff] [blame] | 1305 | int vg, r; |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1306 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1307 | *bit_chk = seq->param.write_correct_mask; |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1308 | |
| 1309 | for (r = rank_bgn; r < rank_end; r++) { |
Marek Vasut | bc773a1 | 2015-07-21 05:54:39 +0200 | [diff] [blame] | 1310 | /* Set rank */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1311 | set_rank_and_odt_mask(seq, r, RW_MGR_ODT_MODE_READ_WRITE); |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1312 | |
| 1313 | tmp_bit_chk = 0; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1314 | for (vg = seq->rwcfg->mem_virtual_groups_per_write_dqs - 1; |
Marek Vasut | bc773a1 | 2015-07-21 05:54:39 +0200 | [diff] [blame] | 1315 | vg >= 0; vg--) { |
| 1316 | /* Reset the FIFOs to get pointers to known state. */ |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1317 | writel(0, &phy_mgr_cmd->fifo_reset); |
| 1318 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1319 | group = write_group * |
| 1320 | seq->rwcfg->mem_virtual_groups_per_write_dqs |
| 1321 | + vg; |
| 1322 | rw_mgr_mem_calibrate_write_test_issue(seq, group, |
| 1323 | use_dm); |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1324 | |
Marek Vasut | bc773a1 | 2015-07-21 05:54:39 +0200 | [diff] [blame] | 1325 | base_rw_mgr = readl(SDR_PHYGRP_RWMGRGRP_ADDRESS); |
| 1326 | tmp_bit_chk <<= shift_ratio; |
| 1327 | tmp_bit_chk |= (correct_mask_vg & ~(base_rw_mgr)); |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1328 | } |
Marek Vasut | bc773a1 | 2015-07-21 05:54:39 +0200 | [diff] [blame] | 1329 | |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1330 | *bit_chk &= tmp_bit_chk; |
| 1331 | } |
| 1332 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1333 | set_rank_and_odt_mask(seq, 0, RW_MGR_ODT_MODE_OFF); |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1334 | if (all_correct) { |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 1335 | debug_cond(DLEVEL >= 2, |
Marek Vasut | bc773a1 | 2015-07-21 05:54:39 +0200 | [diff] [blame] | 1336 | "write_test(%u,%u,ALL) : %u == %u => %i\n", |
| 1337 | write_group, use_dm, *bit_chk, |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1338 | seq->param.write_correct_mask, |
| 1339 | *bit_chk == seq->param.write_correct_mask); |
| 1340 | return *bit_chk == seq->param.write_correct_mask; |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1341 | } else { |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 1342 | debug_cond(DLEVEL >= 2, |
Marek Vasut | bc773a1 | 2015-07-21 05:54:39 +0200 | [diff] [blame] | 1343 | "write_test(%u,%u,ONE) : %u != %i => %i\n", |
| 1344 | write_group, use_dm, *bit_chk, 0, *bit_chk != 0); |
Marek Vasut | 0b97c42 | 2015-07-21 05:43:37 +0200 | [diff] [blame] | 1345 | return *bit_chk != 0x00; |
| 1346 | } |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1347 | } |
| 1348 | |
Marek Vasut | 55c4d69 | 2015-07-18 03:55:07 +0200 | [diff] [blame] | 1349 | /** |
| 1350 | * rw_mgr_mem_calibrate_read_test_patterns() - Read back test patterns |
| 1351 | * @rank_bgn: Rank number |
| 1352 | * @group: Read/Write Group |
| 1353 | * @all_ranks: Test all ranks |
| 1354 | * |
| 1355 | * Performs a guaranteed read on the patterns we are going to use during a |
| 1356 | * read test to ensure memory works. |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1357 | */ |
Marek Vasut | 55c4d69 | 2015-07-18 03:55:07 +0200 | [diff] [blame] | 1358 | static int |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1359 | rw_mgr_mem_calibrate_read_test_patterns(struct socfpga_sdrseq *seq, |
| 1360 | const u32 rank_bgn, const u32 group, |
Marek Vasut | 55c4d69 | 2015-07-18 03:55:07 +0200 | [diff] [blame] | 1361 | const u32 all_ranks) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1362 | { |
Marek Vasut | 55c4d69 | 2015-07-18 03:55:07 +0200 | [diff] [blame] | 1363 | const u32 addr = SDR_PHYGRP_RWMGRGRP_ADDRESS | |
| 1364 | RW_MGR_RUN_SINGLE_GROUP_OFFSET; |
| 1365 | const u32 addr_offset = |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1366 | (group * seq->rwcfg->mem_virtual_groups_per_read_dqs) |
| 1367 | << 2; |
Marek Vasut | 55c4d69 | 2015-07-18 03:55:07 +0200 | [diff] [blame] | 1368 | const u32 rank_end = all_ranks ? |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1369 | seq->rwcfg->mem_number_of_ranks : |
Marek Vasut | 55c4d69 | 2015-07-18 03:55:07 +0200 | [diff] [blame] | 1370 | (rank_bgn + NUM_RANKS_PER_SHADOW_REG); |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1371 | const u32 shift_ratio = seq->rwcfg->mem_dq_per_read_dqs / |
| 1372 | seq->rwcfg->mem_virtual_groups_per_read_dqs; |
| 1373 | const u32 correct_mask_vg = seq->param.read_correct_mask_vg; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1374 | |
Marek Vasut | 55c4d69 | 2015-07-18 03:55:07 +0200 | [diff] [blame] | 1375 | u32 tmp_bit_chk, base_rw_mgr, bit_chk; |
| 1376 | int vg, r; |
| 1377 | int ret = 0; |
| 1378 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1379 | bit_chk = seq->param.read_correct_mask; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1380 | |
| 1381 | for (r = rank_bgn; r < rank_end; r++) { |
Marek Vasut | 55c4d69 | 2015-07-18 03:55:07 +0200 | [diff] [blame] | 1382 | /* Set rank */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1383 | set_rank_and_odt_mask(seq, r, RW_MGR_ODT_MODE_READ_WRITE); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1384 | |
| 1385 | /* Load up a constant bursts of read commands */ |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 1386 | writel(0x20, &sdr_rw_load_mgr_regs->load_cntr0); |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1387 | writel(seq->rwcfg->guaranteed_read, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 1388 | &sdr_rw_load_jump_mgr_regs->load_jump_add0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1389 | |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 1390 | writel(0x20, &sdr_rw_load_mgr_regs->load_cntr1); |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1391 | writel(seq->rwcfg->guaranteed_read_cont, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 1392 | &sdr_rw_load_jump_mgr_regs->load_jump_add1); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1393 | |
| 1394 | tmp_bit_chk = 0; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1395 | for (vg = seq->rwcfg->mem_virtual_groups_per_read_dqs - 1; |
Marek Vasut | 55c4d69 | 2015-07-18 03:55:07 +0200 | [diff] [blame] | 1396 | vg >= 0; vg--) { |
| 1397 | /* Reset the FIFOs to get pointers to known state. */ |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 1398 | writel(0, &phy_mgr_cmd->fifo_reset); |
| 1399 | writel(0, SDR_PHYGRP_RWMGRGRP_ADDRESS | |
| 1400 | RW_MGR_RESET_READ_DATAPATH_OFFSET); |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1401 | writel(seq->rwcfg->guaranteed_read, |
Marek Vasut | 55c4d69 | 2015-07-18 03:55:07 +0200 | [diff] [blame] | 1402 | addr + addr_offset + (vg << 2)); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1403 | |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 1404 | base_rw_mgr = readl(SDR_PHYGRP_RWMGRGRP_ADDRESS); |
Marek Vasut | 55c4d69 | 2015-07-18 03:55:07 +0200 | [diff] [blame] | 1405 | tmp_bit_chk <<= shift_ratio; |
| 1406 | tmp_bit_chk |= correct_mask_vg & ~base_rw_mgr; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1407 | } |
Marek Vasut | 55c4d69 | 2015-07-18 03:55:07 +0200 | [diff] [blame] | 1408 | |
| 1409 | bit_chk &= tmp_bit_chk; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1410 | } |
| 1411 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1412 | writel(seq->rwcfg->clear_dqs_enable, addr + (group << 2)); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1413 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1414 | set_rank_and_odt_mask(seq, 0, RW_MGR_ODT_MODE_OFF); |
Marek Vasut | 55c4d69 | 2015-07-18 03:55:07 +0200 | [diff] [blame] | 1415 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1416 | if (bit_chk != seq->param.read_correct_mask) |
Marek Vasut | 55c4d69 | 2015-07-18 03:55:07 +0200 | [diff] [blame] | 1417 | ret = -EIO; |
| 1418 | |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 1419 | debug_cond(DLEVEL >= 1, |
Marek Vasut | 55c4d69 | 2015-07-18 03:55:07 +0200 | [diff] [blame] | 1420 | "%s:%d test_load_patterns(%u,ALL) => (%u == %u) => %i\n", |
| 1421 | __func__, __LINE__, group, bit_chk, |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1422 | seq->param.read_correct_mask, ret); |
Marek Vasut | 55c4d69 | 2015-07-18 03:55:07 +0200 | [diff] [blame] | 1423 | |
| 1424 | return ret; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1425 | } |
| 1426 | |
Marek Vasut | 6a75278 | 2015-07-18 03:34:22 +0200 | [diff] [blame] | 1427 | /** |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1428 | * rw_mgr_mem_calibrate_read_load_patterns() - Load up the patterns for read |
| 1429 | * test |
Marek Vasut | 6a75278 | 2015-07-18 03:34:22 +0200 | [diff] [blame] | 1430 | * @rank_bgn: Rank number |
| 1431 | * @all_ranks: Test all ranks |
| 1432 | * |
| 1433 | * Load up the patterns we are going to use during a read test. |
| 1434 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1435 | static void rw_mgr_mem_calibrate_read_load_patterns(struct socfpga_sdrseq *seq, |
| 1436 | const u32 rank_bgn, |
Marek Vasut | 6a75278 | 2015-07-18 03:34:22 +0200 | [diff] [blame] | 1437 | const int all_ranks) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1438 | { |
Marek Vasut | 6a75278 | 2015-07-18 03:34:22 +0200 | [diff] [blame] | 1439 | const u32 rank_end = all_ranks ? |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1440 | seq->rwcfg->mem_number_of_ranks : |
Marek Vasut | 6a75278 | 2015-07-18 03:34:22 +0200 | [diff] [blame] | 1441 | (rank_bgn + NUM_RANKS_PER_SHADOW_REG); |
| 1442 | u32 r; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1443 | |
| 1444 | debug("%s:%d\n", __func__, __LINE__); |
Marek Vasut | 6a75278 | 2015-07-18 03:34:22 +0200 | [diff] [blame] | 1445 | |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1446 | for (r = rank_bgn; r < rank_end; r++) { |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1447 | /* set rank */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1448 | set_rank_and_odt_mask(seq, r, RW_MGR_ODT_MODE_READ_WRITE); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1449 | |
| 1450 | /* Load up a constant bursts */ |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 1451 | writel(0x20, &sdr_rw_load_mgr_regs->load_cntr0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1452 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1453 | writel(seq->rwcfg->guaranteed_write_wait0, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 1454 | &sdr_rw_load_jump_mgr_regs->load_jump_add0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1455 | |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 1456 | writel(0x20, &sdr_rw_load_mgr_regs->load_cntr1); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1457 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1458 | writel(seq->rwcfg->guaranteed_write_wait1, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 1459 | &sdr_rw_load_jump_mgr_regs->load_jump_add1); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1460 | |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 1461 | writel(0x04, &sdr_rw_load_mgr_regs->load_cntr2); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1462 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1463 | writel(seq->rwcfg->guaranteed_write_wait2, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 1464 | &sdr_rw_load_jump_mgr_regs->load_jump_add2); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1465 | |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 1466 | writel(0x04, &sdr_rw_load_mgr_regs->load_cntr3); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1467 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1468 | writel(seq->rwcfg->guaranteed_write_wait3, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 1469 | &sdr_rw_load_jump_mgr_regs->load_jump_add3); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1470 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1471 | writel(seq->rwcfg->guaranteed_write, |
| 1472 | SDR_PHYGRP_RWMGRGRP_ADDRESS | |
| 1473 | RW_MGR_RUN_SINGLE_GROUP_OFFSET); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1474 | } |
| 1475 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1476 | set_rank_and_odt_mask(seq, 0, RW_MGR_ODT_MODE_OFF); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1477 | } |
| 1478 | |
Marek Vasut | 656002e | 2015-07-20 03:26:05 +0200 | [diff] [blame] | 1479 | /** |
| 1480 | * rw_mgr_mem_calibrate_read_test() - Perform READ test on single rank |
| 1481 | * @rank_bgn: Rank number |
| 1482 | * @group: Read/Write group |
| 1483 | * @num_tries: Number of retries of the test |
| 1484 | * @all_correct: All bits must be correct in the mask |
| 1485 | * @bit_chk: Resulting bit mask after the test |
| 1486 | * @all_groups: Test all R/W groups |
| 1487 | * @all_ranks: Test all ranks |
| 1488 | * |
| 1489 | * Try a read and see if it returns correct data back. Test has dummy reads |
| 1490 | * inserted into the mix used to align DQS enable. Test has more thorough |
| 1491 | * checks than the regular read test. |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1492 | */ |
Marek Vasut | c6c1fe7 | 2015-07-19 07:48:58 +0200 | [diff] [blame] | 1493 | static int |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1494 | rw_mgr_mem_calibrate_read_test(struct socfpga_sdrseq *seq, |
| 1495 | const u32 rank_bgn, const u32 group, |
Marek Vasut | c6c1fe7 | 2015-07-19 07:48:58 +0200 | [diff] [blame] | 1496 | const u32 num_tries, const u32 all_correct, |
| 1497 | u32 *bit_chk, |
| 1498 | const u32 all_groups, const u32 all_ranks) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1499 | { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1500 | const u32 rank_end = all_ranks ? seq->rwcfg->mem_number_of_ranks : |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1501 | (rank_bgn + NUM_RANKS_PER_SHADOW_REG); |
Marek Vasut | c6c1fe7 | 2015-07-19 07:48:58 +0200 | [diff] [blame] | 1502 | const u32 quick_read_mode = |
| 1503 | ((STATIC_CALIB_STEPS & CALIB_SKIP_DELAY_SWEEPS) && |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1504 | seq->misccfg->enable_super_quick_calibration); |
| 1505 | u32 correct_mask_vg = seq->param.read_correct_mask_vg; |
Marek Vasut | c6c1fe7 | 2015-07-19 07:48:58 +0200 | [diff] [blame] | 1506 | u32 tmp_bit_chk; |
| 1507 | u32 base_rw_mgr; |
| 1508 | u32 addr; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1509 | |
Marek Vasut | c6c1fe7 | 2015-07-19 07:48:58 +0200 | [diff] [blame] | 1510 | int r, vg, ret; |
Marek Vasut | a005c77 | 2015-07-19 07:44:21 +0200 | [diff] [blame] | 1511 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1512 | *bit_chk = seq->param.read_correct_mask; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1513 | |
| 1514 | for (r = rank_bgn; r < rank_end; r++) { |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1515 | /* set rank */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1516 | set_rank_and_odt_mask(seq, r, RW_MGR_ODT_MODE_READ_WRITE); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1517 | |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 1518 | writel(0x10, &sdr_rw_load_mgr_regs->load_cntr1); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1519 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1520 | writel(seq->rwcfg->read_b2b_wait1, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 1521 | &sdr_rw_load_jump_mgr_regs->load_jump_add1); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1522 | |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 1523 | writel(0x10, &sdr_rw_load_mgr_regs->load_cntr2); |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1524 | writel(seq->rwcfg->read_b2b_wait2, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 1525 | &sdr_rw_load_jump_mgr_regs->load_jump_add2); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1526 | |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1527 | if (quick_read_mode) |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 1528 | writel(0x1, &sdr_rw_load_mgr_regs->load_cntr0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1529 | /* need at least two (1+1) reads to capture failures */ |
| 1530 | else if (all_groups) |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 1531 | writel(0x06, &sdr_rw_load_mgr_regs->load_cntr0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1532 | else |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 1533 | writel(0x32, &sdr_rw_load_mgr_regs->load_cntr0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1534 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1535 | writel(seq->rwcfg->read_b2b, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 1536 | &sdr_rw_load_jump_mgr_regs->load_jump_add0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1537 | if (all_groups) |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1538 | writel(seq->rwcfg->mem_if_read_dqs_width * |
| 1539 | seq->rwcfg->mem_virtual_groups_per_read_dqs - 1, |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 1540 | &sdr_rw_load_mgr_regs->load_cntr3); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1541 | else |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 1542 | writel(0x0, &sdr_rw_load_mgr_regs->load_cntr3); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1543 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1544 | writel(seq->rwcfg->read_b2b, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 1545 | &sdr_rw_load_jump_mgr_regs->load_jump_add3); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1546 | |
| 1547 | tmp_bit_chk = 0; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1548 | for (vg = seq->rwcfg->mem_virtual_groups_per_read_dqs - 1; |
| 1549 | vg >= 0; vg--) { |
Marek Vasut | 50a780f | 2015-07-19 07:57:28 +0200 | [diff] [blame] | 1550 | /* Reset the FIFOs to get pointers to known state. */ |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 1551 | writel(0, &phy_mgr_cmd->fifo_reset); |
| 1552 | writel(0, SDR_PHYGRP_RWMGRGRP_ADDRESS | |
| 1553 | RW_MGR_RESET_READ_DATAPATH_OFFSET); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1554 | |
Marek Vasut | 50a780f | 2015-07-19 07:57:28 +0200 | [diff] [blame] | 1555 | if (all_groups) { |
| 1556 | addr = SDR_PHYGRP_RWMGRGRP_ADDRESS | |
| 1557 | RW_MGR_RUN_ALL_GROUPS_OFFSET; |
| 1558 | } else { |
| 1559 | addr = SDR_PHYGRP_RWMGRGRP_ADDRESS | |
| 1560 | RW_MGR_RUN_SINGLE_GROUP_OFFSET; |
| 1561 | } |
Marek Vasut | a334010 | 2015-07-12 19:03:33 +0200 | [diff] [blame] | 1562 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1563 | writel(seq->rwcfg->read_b2b, addr + |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 1564 | ((group * |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1565 | seq->rwcfg->mem_virtual_groups_per_read_dqs + |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 1566 | vg) << 2)); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1567 | |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 1568 | base_rw_mgr = readl(SDR_PHYGRP_RWMGRGRP_ADDRESS); |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1569 | tmp_bit_chk <<= |
| 1570 | seq->rwcfg->mem_dq_per_read_dqs / |
| 1571 | seq->rwcfg->mem_virtual_groups_per_read_dqs; |
Marek Vasut | 50a780f | 2015-07-19 07:57:28 +0200 | [diff] [blame] | 1572 | tmp_bit_chk |= correct_mask_vg & ~(base_rw_mgr); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1573 | } |
Marek Vasut | 28957f3 | 2015-07-19 07:51:17 +0200 | [diff] [blame] | 1574 | |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1575 | *bit_chk &= tmp_bit_chk; |
| 1576 | } |
| 1577 | |
Marek Vasut | a334010 | 2015-07-12 19:03:33 +0200 | [diff] [blame] | 1578 | addr = SDR_PHYGRP_RWMGRGRP_ADDRESS | RW_MGR_RUN_SINGLE_GROUP_OFFSET; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1579 | writel(seq->rwcfg->clear_dqs_enable, addr + (group << 2)); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1580 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1581 | set_rank_and_odt_mask(seq, 0, RW_MGR_ODT_MODE_OFF); |
Marek Vasut | a005c77 | 2015-07-19 07:44:21 +0200 | [diff] [blame] | 1582 | |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1583 | if (all_correct) { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1584 | ret = (*bit_chk == seq->param.read_correct_mask); |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 1585 | debug_cond(DLEVEL >= 2, |
Marek Vasut | a005c77 | 2015-07-19 07:44:21 +0200 | [diff] [blame] | 1586 | "%s:%d read_test(%u,ALL,%u) => (%u == %u) => %i\n", |
| 1587 | __func__, __LINE__, group, all_groups, *bit_chk, |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1588 | seq->param.read_correct_mask, ret); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1589 | } else { |
Marek Vasut | a005c77 | 2015-07-19 07:44:21 +0200 | [diff] [blame] | 1590 | ret = (*bit_chk != 0x00); |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 1591 | debug_cond(DLEVEL >= 2, |
Marek Vasut | a005c77 | 2015-07-19 07:44:21 +0200 | [diff] [blame] | 1592 | "%s:%d read_test(%u,ONE,%u) => (%u != %u) => %i\n", |
| 1593 | __func__, __LINE__, group, all_groups, *bit_chk, |
| 1594 | 0, ret); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1595 | } |
Marek Vasut | a005c77 | 2015-07-19 07:44:21 +0200 | [diff] [blame] | 1596 | |
| 1597 | return ret; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1598 | } |
| 1599 | |
Marek Vasut | a50d5d7 | 2015-07-19 07:35:36 +0200 | [diff] [blame] | 1600 | /** |
| 1601 | * rw_mgr_mem_calibrate_read_test_all_ranks() - Perform READ test on all ranks |
| 1602 | * @grp: Read/Write group |
| 1603 | * @num_tries: Number of retries of the test |
| 1604 | * @all_correct: All bits must be correct in the mask |
| 1605 | * @all_groups: Test all R/W groups |
| 1606 | * |
| 1607 | * Perform a READ test across all memory ranks. |
| 1608 | */ |
| 1609 | static int |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1610 | rw_mgr_mem_calibrate_read_test_all_ranks(struct socfpga_sdrseq *seq, |
| 1611 | const u32 grp, const u32 num_tries, |
Marek Vasut | a50d5d7 | 2015-07-19 07:35:36 +0200 | [diff] [blame] | 1612 | const u32 all_correct, |
| 1613 | const u32 all_groups) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1614 | { |
Marek Vasut | a50d5d7 | 2015-07-19 07:35:36 +0200 | [diff] [blame] | 1615 | u32 bit_chk; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1616 | return rw_mgr_mem_calibrate_read_test(seq, 0, grp, num_tries, |
| 1617 | all_correct, &bit_chk, all_groups, |
| 1618 | 1); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1619 | } |
| 1620 | |
Marek Vasut | 1c9f25b | 2015-07-19 06:25:27 +0200 | [diff] [blame] | 1621 | /** |
| 1622 | * rw_mgr_incr_vfifo() - Increase VFIFO value |
| 1623 | * @grp: Read/Write group |
Marek Vasut | 1c9f25b | 2015-07-19 06:25:27 +0200 | [diff] [blame] | 1624 | * |
| 1625 | * Increase VFIFO value. |
| 1626 | */ |
Marek Vasut | 42e43ab | 2015-07-19 06:37:51 +0200 | [diff] [blame] | 1627 | static void rw_mgr_incr_vfifo(const u32 grp) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1628 | { |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 1629 | writel(grp, &phy_mgr_cmd->inc_vfifo_hard_phy); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1630 | } |
| 1631 | |
Marek Vasut | 1c9f25b | 2015-07-19 06:25:27 +0200 | [diff] [blame] | 1632 | /** |
| 1633 | * rw_mgr_decr_vfifo() - Decrease VFIFO value |
| 1634 | * @grp: Read/Write group |
Marek Vasut | 1c9f25b | 2015-07-19 06:25:27 +0200 | [diff] [blame] | 1635 | * |
| 1636 | * Decrease VFIFO value. |
| 1637 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1638 | static void rw_mgr_decr_vfifo(struct socfpga_sdrseq *seq, const u32 grp) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1639 | { |
Marek Vasut | 1c9f25b | 2015-07-19 06:25:27 +0200 | [diff] [blame] | 1640 | u32 i; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1641 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1642 | for (i = 0; i < seq->misccfg->read_valid_fifo_size - 1; i++) |
Marek Vasut | 42e43ab | 2015-07-19 06:37:51 +0200 | [diff] [blame] | 1643 | rw_mgr_incr_vfifo(grp); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1644 | } |
| 1645 | |
Marek Vasut | 088eb21 | 2015-07-19 06:45:43 +0200 | [diff] [blame] | 1646 | /** |
| 1647 | * find_vfifo_failing_read() - Push VFIFO to get a failing read |
| 1648 | * @grp: Read/Write group |
| 1649 | * |
| 1650 | * Push VFIFO until a failing read happens. |
| 1651 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1652 | static int find_vfifo_failing_read(struct socfpga_sdrseq *seq, |
| 1653 | const u32 grp) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1654 | { |
Marek Vasut | a50d5d7 | 2015-07-19 07:35:36 +0200 | [diff] [blame] | 1655 | u32 v, ret, fail_cnt = 0; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1656 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1657 | for (v = 0; v < seq->misccfg->read_valid_fifo_size; v++) { |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 1658 | debug_cond(DLEVEL >= 2, "%s:%d: vfifo %u\n", |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1659 | __func__, __LINE__, v); |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1660 | ret = rw_mgr_mem_calibrate_read_test_all_ranks(seq, grp, 1, |
| 1661 | PASS_ONE_BIT, 0); |
Marek Vasut | 088eb21 | 2015-07-19 06:45:43 +0200 | [diff] [blame] | 1662 | if (!ret) { |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1663 | fail_cnt++; |
| 1664 | |
| 1665 | if (fail_cnt == 2) |
Marek Vasut | 088eb21 | 2015-07-19 06:45:43 +0200 | [diff] [blame] | 1666 | return v; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1667 | } |
| 1668 | |
Marek Vasut | 088eb21 | 2015-07-19 06:45:43 +0200 | [diff] [blame] | 1669 | /* Fiddle with FIFO. */ |
Marek Vasut | 42e43ab | 2015-07-19 06:37:51 +0200 | [diff] [blame] | 1670 | rw_mgr_incr_vfifo(grp); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1671 | } |
| 1672 | |
Marek Vasut | 088eb21 | 2015-07-19 06:45:43 +0200 | [diff] [blame] | 1673 | /* No failing read found! Something must have gone wrong. */ |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 1674 | debug_cond(DLEVEL >= 2, "%s:%d: vfifo failed\n", __func__, __LINE__); |
Marek Vasut | 088eb21 | 2015-07-19 06:45:43 +0200 | [diff] [blame] | 1675 | return 0; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1676 | } |
| 1677 | |
Marek Vasut | f2b02d4 | 2015-07-19 05:26:49 +0200 | [diff] [blame] | 1678 | /** |
Marek Vasut | 6ff36b7 | 2015-07-19 07:27:06 +0200 | [diff] [blame] | 1679 | * sdr_find_phase_delay() - Find DQS enable phase or delay |
| 1680 | * @working: If 1, look for working phase/delay, if 0, look for non-working |
| 1681 | * @delay: If 1, look for delay, if 0, look for phase |
| 1682 | * @grp: Read/Write group |
| 1683 | * @work: Working window position |
| 1684 | * @work_inc: Working window increment |
| 1685 | * @pd: DQS Phase/Delay Iterator |
| 1686 | * |
| 1687 | * Find working or non-working DQS enable phase setting. |
| 1688 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1689 | static int sdr_find_phase_delay(struct socfpga_sdrseq *seq, int working, |
| 1690 | int delay, const u32 grp, u32 *work, |
| 1691 | const u32 work_inc, u32 *pd) |
Marek Vasut | 6ff36b7 | 2015-07-19 07:27:06 +0200 | [diff] [blame] | 1692 | { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1693 | const u32 max = delay ? seq->iocfg->dqs_en_delay_max : |
| 1694 | seq->iocfg->dqs_en_phase_max; |
Marek Vasut | a50d5d7 | 2015-07-19 07:35:36 +0200 | [diff] [blame] | 1695 | u32 ret; |
Marek Vasut | 6ff36b7 | 2015-07-19 07:27:06 +0200 | [diff] [blame] | 1696 | |
| 1697 | for (; *pd <= max; (*pd)++) { |
| 1698 | if (delay) |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1699 | scc_mgr_set_dqs_en_delay_all_ranks(seq, grp, *pd); |
Marek Vasut | 6ff36b7 | 2015-07-19 07:27:06 +0200 | [diff] [blame] | 1700 | else |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1701 | scc_mgr_set_dqs_en_phase_all_ranks(seq, grp, *pd); |
Marek Vasut | 6ff36b7 | 2015-07-19 07:27:06 +0200 | [diff] [blame] | 1702 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1703 | ret = rw_mgr_mem_calibrate_read_test_all_ranks(seq, grp, 1, |
| 1704 | PASS_ONE_BIT, 0); |
Marek Vasut | 6ff36b7 | 2015-07-19 07:27:06 +0200 | [diff] [blame] | 1705 | if (!working) |
| 1706 | ret = !ret; |
| 1707 | |
| 1708 | if (ret) |
| 1709 | return 0; |
| 1710 | |
| 1711 | if (work) |
| 1712 | *work += work_inc; |
| 1713 | } |
| 1714 | |
| 1715 | return -EINVAL; |
| 1716 | } |
| 1717 | /** |
Marek Vasut | f2b02d4 | 2015-07-19 05:26:49 +0200 | [diff] [blame] | 1718 | * sdr_find_phase() - Find DQS enable phase |
| 1719 | * @working: If 1, look for working phase, if 0, look for non-working phase |
| 1720 | * @grp: Read/Write group |
Marek Vasut | f2b02d4 | 2015-07-19 05:26:49 +0200 | [diff] [blame] | 1721 | * @work: Working window position |
| 1722 | * @i: Iterator |
| 1723 | * @p: DQS Phase Iterator |
Marek Vasut | f2b02d4 | 2015-07-19 05:26:49 +0200 | [diff] [blame] | 1724 | * |
| 1725 | * Find working or non-working DQS enable phase setting. |
| 1726 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1727 | static int sdr_find_phase(struct socfpga_sdrseq *seq, int working, |
| 1728 | const u32 grp, u32 *work, u32 *i, u32 *p) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1729 | { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1730 | const u32 end = seq->misccfg->read_valid_fifo_size + (working ? 0 : 1); |
Marek Vasut | 6ff36b7 | 2015-07-19 07:27:06 +0200 | [diff] [blame] | 1731 | int ret; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1732 | |
Marek Vasut | f2b02d4 | 2015-07-19 05:26:49 +0200 | [diff] [blame] | 1733 | for (; *i < end; (*i)++) { |
| 1734 | if (working) |
| 1735 | *p = 0; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1736 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1737 | ret = sdr_find_phase_delay(seq, working, 0, grp, work, |
| 1738 | seq->iocfg->delay_per_opa_tap, p); |
Marek Vasut | 6ff36b7 | 2015-07-19 07:27:06 +0200 | [diff] [blame] | 1739 | if (!ret) |
| 1740 | return 0; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1741 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1742 | if (*p > seq->iocfg->dqs_en_phase_max) { |
Marek Vasut | f2b02d4 | 2015-07-19 05:26:49 +0200 | [diff] [blame] | 1743 | /* Fiddle with FIFO. */ |
Marek Vasut | 42e43ab | 2015-07-19 06:37:51 +0200 | [diff] [blame] | 1744 | rw_mgr_incr_vfifo(grp); |
Marek Vasut | f2b02d4 | 2015-07-19 05:26:49 +0200 | [diff] [blame] | 1745 | if (!working) |
| 1746 | *p = 0; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1747 | } |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1748 | } |
| 1749 | |
Marek Vasut | f2b02d4 | 2015-07-19 05:26:49 +0200 | [diff] [blame] | 1750 | return -EINVAL; |
| 1751 | } |
| 1752 | |
Marek Vasut | 6394ef5 | 2015-07-19 06:04:00 +0200 | [diff] [blame] | 1753 | /** |
| 1754 | * sdr_working_phase() - Find working DQS enable phase |
| 1755 | * @grp: Read/Write group |
| 1756 | * @work_bgn: Working window start position |
Marek Vasut | 6394ef5 | 2015-07-19 06:04:00 +0200 | [diff] [blame] | 1757 | * @d: dtaps output value |
| 1758 | * @p: DQS Phase Iterator |
| 1759 | * @i: Iterator |
| 1760 | * |
| 1761 | * Find working DQS enable phase setting. |
| 1762 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1763 | static int sdr_working_phase(struct socfpga_sdrseq *seq, const u32 grp, |
| 1764 | u32 *work_bgn, u32 *d, u32 *p, u32 *i) |
Marek Vasut | f2b02d4 | 2015-07-19 05:26:49 +0200 | [diff] [blame] | 1765 | { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1766 | const u32 dtaps_per_ptap = seq->iocfg->delay_per_opa_tap / |
| 1767 | seq->iocfg->delay_per_dqs_en_dchain_tap; |
Marek Vasut | f2b02d4 | 2015-07-19 05:26:49 +0200 | [diff] [blame] | 1768 | int ret; |
| 1769 | |
| 1770 | *work_bgn = 0; |
| 1771 | |
| 1772 | for (*d = 0; *d <= dtaps_per_ptap; (*d)++) { |
| 1773 | *i = 0; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1774 | scc_mgr_set_dqs_en_delay_all_ranks(seq, grp, *d); |
| 1775 | ret = sdr_find_phase(seq, 1, grp, work_bgn, i, p); |
Marek Vasut | f2b02d4 | 2015-07-19 05:26:49 +0200 | [diff] [blame] | 1776 | if (!ret) |
| 1777 | return 0; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1778 | *work_bgn += seq->iocfg->delay_per_dqs_en_dchain_tap; |
Marek Vasut | f2b02d4 | 2015-07-19 05:26:49 +0200 | [diff] [blame] | 1779 | } |
| 1780 | |
Marek Vasut | b148ebe | 2015-07-19 05:01:12 +0200 | [diff] [blame] | 1781 | /* Cannot find working solution */ |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 1782 | debug_cond(DLEVEL >= 2, "%s:%d find_dqs_en_phase: no vfifo/ptap/dtap\n", |
Marek Vasut | f2b02d4 | 2015-07-19 05:26:49 +0200 | [diff] [blame] | 1783 | __func__, __LINE__); |
| 1784 | return -EINVAL; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1785 | } |
| 1786 | |
Marek Vasut | 6394ef5 | 2015-07-19 06:04:00 +0200 | [diff] [blame] | 1787 | /** |
| 1788 | * sdr_backup_phase() - Find DQS enable backup phase |
| 1789 | * @grp: Read/Write group |
| 1790 | * @work_bgn: Working window start position |
Marek Vasut | 6394ef5 | 2015-07-19 06:04:00 +0200 | [diff] [blame] | 1791 | * @p: DQS Phase Iterator |
| 1792 | * |
| 1793 | * Find DQS enable backup phase setting. |
| 1794 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1795 | static void sdr_backup_phase(struct socfpga_sdrseq *seq, const u32 grp, |
| 1796 | u32 *work_bgn, u32 *p) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1797 | { |
Marek Vasut | a50d5d7 | 2015-07-19 07:35:36 +0200 | [diff] [blame] | 1798 | u32 tmp_delay, d; |
Marek Vasut | 6394ef5 | 2015-07-19 06:04:00 +0200 | [diff] [blame] | 1799 | int ret; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1800 | |
| 1801 | /* Special case code for backing up a phase */ |
| 1802 | if (*p == 0) { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1803 | *p = seq->iocfg->dqs_en_phase_max; |
| 1804 | rw_mgr_decr_vfifo(seq, grp); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1805 | } else { |
| 1806 | (*p)--; |
| 1807 | } |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1808 | tmp_delay = *work_bgn - seq->iocfg->delay_per_opa_tap; |
| 1809 | scc_mgr_set_dqs_en_phase_all_ranks(seq, grp, *p); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1810 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1811 | for (d = 0; d <= seq->iocfg->dqs_en_delay_max && tmp_delay < *work_bgn; |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 1812 | d++) { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1813 | scc_mgr_set_dqs_en_delay_all_ranks(seq, grp, d); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1814 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1815 | ret = rw_mgr_mem_calibrate_read_test_all_ranks(seq, grp, 1, |
| 1816 | PASS_ONE_BIT, 0); |
Marek Vasut | 6394ef5 | 2015-07-19 06:04:00 +0200 | [diff] [blame] | 1817 | if (ret) { |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1818 | *work_bgn = tmp_delay; |
| 1819 | break; |
| 1820 | } |
Marek Vasut | 6eff803 | 2015-07-19 05:48:30 +0200 | [diff] [blame] | 1821 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1822 | tmp_delay += seq->iocfg->delay_per_dqs_en_dchain_tap; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1823 | } |
| 1824 | |
Marek Vasut | 6394ef5 | 2015-07-19 06:04:00 +0200 | [diff] [blame] | 1825 | /* Restore VFIFO to old state before we decremented it (if needed). */ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1826 | (*p)++; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1827 | if (*p > seq->iocfg->dqs_en_phase_max) { |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1828 | *p = 0; |
Marek Vasut | 42e43ab | 2015-07-19 06:37:51 +0200 | [diff] [blame] | 1829 | rw_mgr_incr_vfifo(grp); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1830 | } |
| 1831 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1832 | scc_mgr_set_dqs_en_delay_all_ranks(seq, grp, 0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1833 | } |
| 1834 | |
Marek Vasut | 6394ef5 | 2015-07-19 06:04:00 +0200 | [diff] [blame] | 1835 | /** |
| 1836 | * sdr_nonworking_phase() - Find non-working DQS enable phase |
| 1837 | * @grp: Read/Write group |
| 1838 | * @work_end: Working window end position |
Marek Vasut | 6394ef5 | 2015-07-19 06:04:00 +0200 | [diff] [blame] | 1839 | * @p: DQS Phase Iterator |
| 1840 | * @i: Iterator |
| 1841 | * |
| 1842 | * Find non-working DQS enable phase setting. |
| 1843 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1844 | static int sdr_nonworking_phase(struct socfpga_sdrseq *seq, |
| 1845 | const u32 grp, u32 *work_end, u32 *p, u32 *i) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1846 | { |
Marek Vasut | f2b02d4 | 2015-07-19 05:26:49 +0200 | [diff] [blame] | 1847 | int ret; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1848 | |
| 1849 | (*p)++; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1850 | *work_end += seq->iocfg->delay_per_opa_tap; |
| 1851 | if (*p > seq->iocfg->dqs_en_phase_max) { |
Marek Vasut | f2b02d4 | 2015-07-19 05:26:49 +0200 | [diff] [blame] | 1852 | /* Fiddle with FIFO. */ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1853 | *p = 0; |
Marek Vasut | 42e43ab | 2015-07-19 06:37:51 +0200 | [diff] [blame] | 1854 | rw_mgr_incr_vfifo(grp); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1855 | } |
| 1856 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1857 | ret = sdr_find_phase(seq, 0, grp, work_end, i, p); |
Marek Vasut | f2b02d4 | 2015-07-19 05:26:49 +0200 | [diff] [blame] | 1858 | if (ret) { |
| 1859 | /* Cannot see edge of failing read. */ |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 1860 | debug_cond(DLEVEL >= 2, "%s:%d: end: failed\n", |
Marek Vasut | f2b02d4 | 2015-07-19 05:26:49 +0200 | [diff] [blame] | 1861 | __func__, __LINE__); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1862 | } |
| 1863 | |
Marek Vasut | f2b02d4 | 2015-07-19 05:26:49 +0200 | [diff] [blame] | 1864 | return ret; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1865 | } |
| 1866 | |
Marek Vasut | fea03c3 | 2015-07-19 04:14:32 +0200 | [diff] [blame] | 1867 | /** |
| 1868 | * sdr_find_window_center() - Find center of the working DQS window. |
| 1869 | * @grp: Read/Write group |
| 1870 | * @work_bgn: First working settings |
| 1871 | * @work_end: Last working settings |
Marek Vasut | fea03c3 | 2015-07-19 04:14:32 +0200 | [diff] [blame] | 1872 | * |
| 1873 | * Find center of the working DQS enable window. |
| 1874 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1875 | static int sdr_find_window_center(struct socfpga_sdrseq *seq, |
| 1876 | const u32 grp, const u32 work_bgn, |
Marek Vasut | 42e43ab | 2015-07-19 06:37:51 +0200 | [diff] [blame] | 1877 | const u32 work_end) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1878 | { |
Marek Vasut | a50d5d7 | 2015-07-19 07:35:36 +0200 | [diff] [blame] | 1879 | u32 work_mid; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1880 | int tmp_delay = 0; |
Marek Vasut | d996e80 | 2015-07-19 02:56:59 +0200 | [diff] [blame] | 1881 | int i, p, d; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1882 | |
Marek Vasut | d996e80 | 2015-07-19 02:56:59 +0200 | [diff] [blame] | 1883 | work_mid = (work_bgn + work_end) / 2; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1884 | |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 1885 | debug_cond(DLEVEL >= 2, "work_bgn=%d work_end=%d work_mid=%d\n", |
Marek Vasut | d996e80 | 2015-07-19 02:56:59 +0200 | [diff] [blame] | 1886 | work_bgn, work_end, work_mid); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1887 | /* Get the middle delay to be less than a VFIFO delay */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1888 | tmp_delay = (seq->iocfg->dqs_en_phase_max + 1) |
| 1889 | * seq->iocfg->delay_per_opa_tap; |
Marek Vasut | d996e80 | 2015-07-19 02:56:59 +0200 | [diff] [blame] | 1890 | |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 1891 | debug_cond(DLEVEL >= 2, "vfifo ptap delay %d\n", tmp_delay); |
Marek Vasut | ea4c4bb | 2015-07-19 04:04:33 +0200 | [diff] [blame] | 1892 | work_mid %= tmp_delay; |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 1893 | debug_cond(DLEVEL >= 2, "new work_mid %d\n", work_mid); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1894 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1895 | tmp_delay = rounddown(work_mid, seq->iocfg->delay_per_opa_tap); |
| 1896 | if (tmp_delay > seq->iocfg->dqs_en_phase_max |
| 1897 | * seq->iocfg->delay_per_opa_tap) { |
| 1898 | tmp_delay = seq->iocfg->dqs_en_phase_max |
| 1899 | * seq->iocfg->delay_per_opa_tap; |
| 1900 | } |
| 1901 | p = tmp_delay / seq->iocfg->delay_per_opa_tap; |
Marek Vasut | d996e80 | 2015-07-19 02:56:59 +0200 | [diff] [blame] | 1902 | |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 1903 | debug_cond(DLEVEL >= 2, "new p %d, tmp_delay=%d\n", p, tmp_delay); |
Marek Vasut | ea4c4bb | 2015-07-19 04:04:33 +0200 | [diff] [blame] | 1904 | |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 1905 | d = DIV_ROUND_UP(work_mid - tmp_delay, |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1906 | seq->iocfg->delay_per_dqs_en_dchain_tap); |
| 1907 | if (d > seq->iocfg->dqs_en_delay_max) |
| 1908 | d = seq->iocfg->dqs_en_delay_max; |
| 1909 | tmp_delay += d * seq->iocfg->delay_per_dqs_en_dchain_tap; |
Marek Vasut | ea4c4bb | 2015-07-19 04:04:33 +0200 | [diff] [blame] | 1910 | |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 1911 | debug_cond(DLEVEL >= 2, "new d %d, tmp_delay=%d\n", d, tmp_delay); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1912 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1913 | scc_mgr_set_dqs_en_phase_all_ranks(seq, grp, p); |
| 1914 | scc_mgr_set_dqs_en_delay_all_ranks(seq, grp, d); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1915 | |
| 1916 | /* |
| 1917 | * push vfifo until we can successfully calibrate. We can do this |
| 1918 | * because the largest possible margin in 1 VFIFO cycle. |
| 1919 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1920 | for (i = 0; i < seq->misccfg->read_valid_fifo_size; i++) { |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 1921 | debug_cond(DLEVEL >= 2, "find_dqs_en_phase: center\n"); |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1922 | if (rw_mgr_mem_calibrate_read_test_all_ranks(seq, grp, 1, |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1923 | PASS_ONE_BIT, |
Marek Vasut | a50d5d7 | 2015-07-19 07:35:36 +0200 | [diff] [blame] | 1924 | 0)) { |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 1925 | debug_cond(DLEVEL >= 2, |
Marek Vasut | 42e43ab | 2015-07-19 06:37:51 +0200 | [diff] [blame] | 1926 | "%s:%d center: found: ptap=%u dtap=%u\n", |
| 1927 | __func__, __LINE__, p, d); |
Marek Vasut | fea03c3 | 2015-07-19 04:14:32 +0200 | [diff] [blame] | 1928 | return 0; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1929 | } |
| 1930 | |
Marek Vasut | fea03c3 | 2015-07-19 04:14:32 +0200 | [diff] [blame] | 1931 | /* Fiddle with FIFO. */ |
Marek Vasut | 42e43ab | 2015-07-19 06:37:51 +0200 | [diff] [blame] | 1932 | rw_mgr_incr_vfifo(grp); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1933 | } |
| 1934 | |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 1935 | debug_cond(DLEVEL >= 2, "%s:%d center: failed.\n", |
Marek Vasut | fea03c3 | 2015-07-19 04:14:32 +0200 | [diff] [blame] | 1936 | __func__, __LINE__); |
| 1937 | return -EINVAL; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1938 | } |
| 1939 | |
Marek Vasut | ec4bbd3 | 2015-07-20 09:11:09 +0200 | [diff] [blame] | 1940 | /** |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1941 | * rw_mgr_mem_calibrate_vfifo_find_dqs_en_phase() - Find a good DQS enable to |
| 1942 | * use |
Marek Vasut | ec4bbd3 | 2015-07-20 09:11:09 +0200 | [diff] [blame] | 1943 | * @grp: Read/Write Group |
| 1944 | * |
| 1945 | * Find a good DQS enable to use. |
| 1946 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1947 | static int |
| 1948 | rw_mgr_mem_calibrate_vfifo_find_dqs_en_phase(struct socfpga_sdrseq *seq, |
| 1949 | const u32 grp) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1950 | { |
Marek Vasut | 59729a6 | 2015-07-20 09:20:20 +0200 | [diff] [blame] | 1951 | u32 d, p, i; |
| 1952 | u32 dtaps_per_ptap; |
| 1953 | u32 work_bgn, work_end; |
Marek Vasut | eb447cb | 2015-08-10 23:01:43 +0200 | [diff] [blame] | 1954 | u32 found_passing_read, found_failing_read = 0, initial_failing_dtap; |
Marek Vasut | 59729a6 | 2015-07-20 09:20:20 +0200 | [diff] [blame] | 1955 | int ret; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1956 | |
| 1957 | debug("%s:%d %u\n", __func__, __LINE__, grp); |
| 1958 | |
| 1959 | reg_file_set_sub_stage(CAL_SUBSTAGE_VFIFO_CENTER); |
| 1960 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1961 | scc_mgr_set_dqs_en_delay_all_ranks(seq, grp, 0); |
| 1962 | scc_mgr_set_dqs_en_phase_all_ranks(seq, grp, 0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1963 | |
Marek Vasut | 4896bcc | 2015-07-19 02:42:21 +0200 | [diff] [blame] | 1964 | /* Step 0: Determine number of delay taps for each phase tap. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1965 | dtaps_per_ptap = seq->iocfg->delay_per_opa_tap / |
| 1966 | seq->iocfg->delay_per_dqs_en_dchain_tap; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1967 | |
Marek Vasut | 4896bcc | 2015-07-19 02:42:21 +0200 | [diff] [blame] | 1968 | /* Step 1: First push vfifo until we get a failing read. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1969 | find_vfifo_failing_read(seq, grp); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1970 | |
Marek Vasut | 4896bcc | 2015-07-19 02:42:21 +0200 | [diff] [blame] | 1971 | /* Step 2: Find first working phase, increment in ptaps. */ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1972 | work_bgn = 0; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1973 | ret = sdr_working_phase(seq, grp, &work_bgn, &d, &p, &i); |
Marek Vasut | 28dbf12 | 2015-07-20 09:20:42 +0200 | [diff] [blame] | 1974 | if (ret) |
| 1975 | return ret; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1976 | |
| 1977 | work_end = work_bgn; |
| 1978 | |
| 1979 | /* |
Marek Vasut | 4896bcc | 2015-07-19 02:42:21 +0200 | [diff] [blame] | 1980 | * If d is 0 then the working window covers a phase tap and we can |
| 1981 | * follow the old procedure. Otherwise, we've found the beginning |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1982 | * and we need to increment the dtaps until we find the end. |
| 1983 | */ |
| 1984 | if (d == 0) { |
Marek Vasut | 4896bcc | 2015-07-19 02:42:21 +0200 | [diff] [blame] | 1985 | /* |
| 1986 | * Step 3a: If we have room, back off by one and |
| 1987 | * increment in dtaps. |
| 1988 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1989 | sdr_backup_phase(seq, grp, &work_bgn, &p); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1990 | |
Marek Vasut | 4896bcc | 2015-07-19 02:42:21 +0200 | [diff] [blame] | 1991 | /* |
| 1992 | * Step 4a: go forward from working phase to non working |
| 1993 | * phase, increment in ptaps. |
| 1994 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 1995 | ret = sdr_nonworking_phase(seq, grp, &work_end, &p, &i); |
Marek Vasut | 28dbf12 | 2015-07-20 09:20:42 +0200 | [diff] [blame] | 1996 | if (ret) |
| 1997 | return ret; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 1998 | |
Marek Vasut | 4896bcc | 2015-07-19 02:42:21 +0200 | [diff] [blame] | 1999 | /* Step 5a: Back off one from last, increment in dtaps. */ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2000 | |
| 2001 | /* Special case code for backing up a phase */ |
| 2002 | if (p == 0) { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2003 | p = seq->iocfg->dqs_en_phase_max; |
| 2004 | rw_mgr_decr_vfifo(seq, grp); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2005 | } else { |
| 2006 | p = p - 1; |
| 2007 | } |
| 2008 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2009 | work_end -= seq->iocfg->delay_per_opa_tap; |
| 2010 | scc_mgr_set_dqs_en_phase_all_ranks(seq, grp, p); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2011 | |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2012 | d = 0; |
| 2013 | |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2014 | debug_cond(DLEVEL >= 2, "%s:%d p: ptap=%u\n", |
Marek Vasut | 4896bcc | 2015-07-19 02:42:21 +0200 | [diff] [blame] | 2015 | __func__, __LINE__, p); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2016 | } |
| 2017 | |
Marek Vasut | 4896bcc | 2015-07-19 02:42:21 +0200 | [diff] [blame] | 2018 | /* The dtap increment to find the failing edge is done here. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2019 | sdr_find_phase_delay(seq, 0, 1, grp, &work_end, |
| 2020 | seq->iocfg->delay_per_dqs_en_dchain_tap, &d); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2021 | |
| 2022 | /* Go back to working dtap */ |
| 2023 | if (d != 0) |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2024 | work_end -= seq->iocfg->delay_per_dqs_en_dchain_tap; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2025 | |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2026 | debug_cond(DLEVEL >= 2, |
Marek Vasut | 4896bcc | 2015-07-19 02:42:21 +0200 | [diff] [blame] | 2027 | "%s:%d p/d: ptap=%u dtap=%u end=%u\n", |
| 2028 | __func__, __LINE__, p, d - 1, work_end); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2029 | |
| 2030 | if (work_end < work_bgn) { |
| 2031 | /* nil range */ |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2032 | debug_cond(DLEVEL >= 2, "%s:%d end-2: failed\n", |
Marek Vasut | 4896bcc | 2015-07-19 02:42:21 +0200 | [diff] [blame] | 2033 | __func__, __LINE__); |
Marek Vasut | 28dbf12 | 2015-07-20 09:20:42 +0200 | [diff] [blame] | 2034 | return -EINVAL; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2035 | } |
| 2036 | |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2037 | debug_cond(DLEVEL >= 2, "%s:%d found range [%u,%u]\n", |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2038 | __func__, __LINE__, work_bgn, work_end); |
| 2039 | |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2040 | /* |
Marek Vasut | 4896bcc | 2015-07-19 02:42:21 +0200 | [diff] [blame] | 2041 | * We need to calculate the number of dtaps that equal a ptap. |
| 2042 | * To do that we'll back up a ptap and re-find the edge of the |
| 2043 | * window using dtaps |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2044 | */ |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2045 | debug_cond(DLEVEL >= 2, "%s:%d calculate dtaps_per_ptap for tracking\n", |
Marek Vasut | 4896bcc | 2015-07-19 02:42:21 +0200 | [diff] [blame] | 2046 | __func__, __LINE__); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2047 | |
| 2048 | /* Special case code for backing up a phase */ |
| 2049 | if (p == 0) { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2050 | p = seq->iocfg->dqs_en_phase_max; |
| 2051 | rw_mgr_decr_vfifo(seq, grp); |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2052 | debug_cond(DLEVEL >= 2, "%s:%d backedup cycle/phase: p=%u\n", |
Marek Vasut | 4896bcc | 2015-07-19 02:42:21 +0200 | [diff] [blame] | 2053 | __func__, __LINE__, p); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2054 | } else { |
| 2055 | p = p - 1; |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2056 | debug_cond(DLEVEL >= 2, "%s:%d backedup phase only: p=%u", |
Marek Vasut | 4896bcc | 2015-07-19 02:42:21 +0200 | [diff] [blame] | 2057 | __func__, __LINE__, p); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2058 | } |
| 2059 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2060 | scc_mgr_set_dqs_en_phase_all_ranks(seq, grp, p); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2061 | |
| 2062 | /* |
| 2063 | * Increase dtap until we first see a passing read (in case the |
Marek Vasut | 4896bcc | 2015-07-19 02:42:21 +0200 | [diff] [blame] | 2064 | * window is smaller than a ptap), and then a failing read to |
| 2065 | * mark the edge of the window again. |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2066 | */ |
| 2067 | |
Marek Vasut | 4896bcc | 2015-07-19 02:42:21 +0200 | [diff] [blame] | 2068 | /* Find a passing read. */ |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2069 | debug_cond(DLEVEL >= 2, "%s:%d find passing read\n", |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2070 | __func__, __LINE__); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2071 | |
Marek Vasut | 6ff36b7 | 2015-07-19 07:27:06 +0200 | [diff] [blame] | 2072 | initial_failing_dtap = d; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2073 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2074 | found_passing_read = !sdr_find_phase_delay(seq, 1, 1, grp, NULL, 0, &d); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2075 | if (found_passing_read) { |
Marek Vasut | 4896bcc | 2015-07-19 02:42:21 +0200 | [diff] [blame] | 2076 | /* Find a failing read. */ |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2077 | debug_cond(DLEVEL >= 2, "%s:%d find failing read\n", |
Marek Vasut | 4896bcc | 2015-07-19 02:42:21 +0200 | [diff] [blame] | 2078 | __func__, __LINE__); |
Marek Vasut | 6ff36b7 | 2015-07-19 07:27:06 +0200 | [diff] [blame] | 2079 | d++; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2080 | found_failing_read = !sdr_find_phase_delay(seq, 0, 1, grp, NULL, |
| 2081 | 0, &d); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2082 | } else { |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2083 | debug_cond(DLEVEL >= 1, |
Marek Vasut | 4896bcc | 2015-07-19 02:42:21 +0200 | [diff] [blame] | 2084 | "%s:%d failed to calculate dtaps per ptap. Fall back on static value\n", |
| 2085 | __func__, __LINE__); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | /* |
| 2089 | * The dynamically calculated dtaps_per_ptap is only valid if we |
| 2090 | * found a passing/failing read. If we didn't, it means d hit the max |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2091 | * (seq->iocfg->dqs_en_delay_max). Otherwise, dtaps_per_ptap retains its |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2092 | * statically calculated value. |
| 2093 | */ |
| 2094 | if (found_passing_read && found_failing_read) |
| 2095 | dtaps_per_ptap = d - initial_failing_dtap; |
| 2096 | |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 2097 | writel(dtaps_per_ptap, &sdr_reg_file->dtaps_per_ptap); |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2098 | debug_cond(DLEVEL >= 2, "%s:%d dtaps_per_ptap=%u - %u = %u", |
Marek Vasut | 4896bcc | 2015-07-19 02:42:21 +0200 | [diff] [blame] | 2099 | __func__, __LINE__, d, initial_failing_dtap, dtaps_per_ptap); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2100 | |
Marek Vasut | 4896bcc | 2015-07-19 02:42:21 +0200 | [diff] [blame] | 2101 | /* Step 6: Find the centre of the window. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2102 | ret = sdr_find_window_center(seq, grp, work_bgn, work_end); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2103 | |
Marek Vasut | 28dbf12 | 2015-07-20 09:20:42 +0200 | [diff] [blame] | 2104 | return ret; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2105 | } |
| 2106 | |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 2107 | /** |
Marek Vasut | 85cd4d7 | 2015-07-13 02:48:34 +0200 | [diff] [blame] | 2108 | * search_stop_check() - Check if the detected edge is valid |
| 2109 | * @write: Perform read (Stage 2) or write (Stage 3) calibration |
| 2110 | * @d: DQS delay |
| 2111 | * @rank_bgn: Rank number |
| 2112 | * @write_group: Write Group |
| 2113 | * @read_group: Read Group |
| 2114 | * @bit_chk: Resulting bit mask after the test |
| 2115 | * @sticky_bit_chk: Resulting sticky bit mask after the test |
| 2116 | * @use_read_test: Perform read test |
| 2117 | * |
| 2118 | * Test if the found edge is valid. |
| 2119 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2120 | static u32 search_stop_check(struct socfpga_sdrseq *seq, const int write, |
| 2121 | const int d, const int rank_bgn, |
Marek Vasut | 85cd4d7 | 2015-07-13 02:48:34 +0200 | [diff] [blame] | 2122 | const u32 write_group, const u32 read_group, |
| 2123 | u32 *bit_chk, u32 *sticky_bit_chk, |
| 2124 | const u32 use_read_test) |
| 2125 | { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2126 | const u32 ratio = seq->rwcfg->mem_if_read_dqs_width / |
| 2127 | seq->rwcfg->mem_if_write_dqs_width; |
| 2128 | const u32 correct_mask = write ? seq->param.write_correct_mask : |
| 2129 | seq->param.read_correct_mask; |
| 2130 | const u32 per_dqs = write ? seq->rwcfg->mem_dq_per_write_dqs : |
| 2131 | seq->rwcfg->mem_dq_per_read_dqs; |
Marek Vasut | 85cd4d7 | 2015-07-13 02:48:34 +0200 | [diff] [blame] | 2132 | u32 ret; |
| 2133 | /* |
| 2134 | * Stop searching when the read test doesn't pass AND when |
| 2135 | * we've seen a passing read on every bit. |
| 2136 | */ |
| 2137 | if (write) { /* WRITE-ONLY */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2138 | ret = !rw_mgr_mem_calibrate_write_test(seq, rank_bgn, |
| 2139 | write_group, 0, |
| 2140 | PASS_ONE_BIT, bit_chk, |
| 2141 | 0); |
Marek Vasut | 85cd4d7 | 2015-07-13 02:48:34 +0200 | [diff] [blame] | 2142 | } else if (use_read_test) { /* READ-ONLY */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2143 | ret = !rw_mgr_mem_calibrate_read_test(seq, rank_bgn, read_group, |
Marek Vasut | 85cd4d7 | 2015-07-13 02:48:34 +0200 | [diff] [blame] | 2144 | NUM_READ_PB_TESTS, |
| 2145 | PASS_ONE_BIT, bit_chk, |
| 2146 | 0, 0); |
| 2147 | } else { /* READ-ONLY */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2148 | rw_mgr_mem_calibrate_write_test(seq, rank_bgn, write_group, 0, |
Marek Vasut | 85cd4d7 | 2015-07-13 02:48:34 +0200 | [diff] [blame] | 2149 | PASS_ONE_BIT, bit_chk, 0); |
| 2150 | *bit_chk = *bit_chk >> (per_dqs * |
| 2151 | (read_group - (write_group * ratio))); |
| 2152 | ret = (*bit_chk == 0); |
| 2153 | } |
| 2154 | *sticky_bit_chk = *sticky_bit_chk | *bit_chk; |
| 2155 | ret = ret && (*sticky_bit_chk == correct_mask); |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2156 | debug_cond(DLEVEL >= 2, |
Marek Vasut | 85cd4d7 | 2015-07-13 02:48:34 +0200 | [diff] [blame] | 2157 | "%s:%d center(left): dtap=%u => %u == %u && %u", |
| 2158 | __func__, __LINE__, d, |
| 2159 | *sticky_bit_chk, correct_mask, ret); |
| 2160 | return ret; |
| 2161 | } |
| 2162 | |
| 2163 | /** |
Marek Vasut | e624caf | 2015-07-13 02:38:15 +0200 | [diff] [blame] | 2164 | * search_left_edge() - Find left edge of DQ/DQS working phase |
| 2165 | * @write: Perform read (Stage 2) or write (Stage 3) calibration |
| 2166 | * @rank_bgn: Rank number |
| 2167 | * @write_group: Write Group |
| 2168 | * @read_group: Read Group |
| 2169 | * @test_bgn: Rank number to begin the test |
Marek Vasut | e624caf | 2015-07-13 02:38:15 +0200 | [diff] [blame] | 2170 | * @sticky_bit_chk: Resulting sticky bit mask after the test |
| 2171 | * @left_edge: Left edge of the DQ/DQS phase |
| 2172 | * @right_edge: Right edge of the DQ/DQS phase |
| 2173 | * @use_read_test: Perform read test |
| 2174 | * |
| 2175 | * Find left edge of DQ/DQS working phase. |
| 2176 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2177 | static void search_left_edge(struct socfpga_sdrseq *seq, const int write, |
| 2178 | const int rank_bgn, const u32 write_group, |
| 2179 | const u32 read_group, const u32 test_bgn, |
| 2180 | u32 *sticky_bit_chk, int *left_edge, |
| 2181 | int *right_edge, const u32 use_read_test) |
Marek Vasut | e624caf | 2015-07-13 02:38:15 +0200 | [diff] [blame] | 2182 | { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2183 | const u32 delay_max = write ? seq->iocfg->io_out1_delay_max : |
| 2184 | seq->iocfg->io_in_delay_max; |
| 2185 | const u32 dqs_max = write ? seq->iocfg->io_out1_delay_max : |
| 2186 | seq->iocfg->dqs_in_delay_max; |
| 2187 | const u32 per_dqs = write ? seq->rwcfg->mem_dq_per_write_dqs : |
| 2188 | seq->rwcfg->mem_dq_per_read_dqs; |
Marek Vasut | b69c247 | 2015-07-18 20:34:00 +0200 | [diff] [blame] | 2189 | u32 stop, bit_chk; |
Marek Vasut | e624caf | 2015-07-13 02:38:15 +0200 | [diff] [blame] | 2190 | int i, d; |
| 2191 | |
| 2192 | for (d = 0; d <= dqs_max; d++) { |
| 2193 | if (write) |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2194 | scc_mgr_apply_group_dq_out1_delay(seq, d); |
Marek Vasut | e624caf | 2015-07-13 02:38:15 +0200 | [diff] [blame] | 2195 | else |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2196 | scc_mgr_apply_group_dq_in_delay(seq, test_bgn, d); |
Marek Vasut | e624caf | 2015-07-13 02:38:15 +0200 | [diff] [blame] | 2197 | |
| 2198 | writel(0, &sdr_scc_mgr->update); |
| 2199 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2200 | stop = search_stop_check(seq, write, d, rank_bgn, write_group, |
Marek Vasut | b69c247 | 2015-07-18 20:34:00 +0200 | [diff] [blame] | 2201 | read_group, &bit_chk, sticky_bit_chk, |
Marek Vasut | 85cd4d7 | 2015-07-13 02:48:34 +0200 | [diff] [blame] | 2202 | use_read_test); |
Marek Vasut | e624caf | 2015-07-13 02:38:15 +0200 | [diff] [blame] | 2203 | if (stop == 1) |
| 2204 | break; |
| 2205 | |
| 2206 | /* stop != 1 */ |
| 2207 | for (i = 0; i < per_dqs; i++) { |
Marek Vasut | b69c247 | 2015-07-18 20:34:00 +0200 | [diff] [blame] | 2208 | if (bit_chk & 1) { |
Marek Vasut | e624caf | 2015-07-13 02:38:15 +0200 | [diff] [blame] | 2209 | /* |
| 2210 | * Remember a passing test as |
| 2211 | * the left_edge. |
| 2212 | */ |
| 2213 | left_edge[i] = d; |
| 2214 | } else { |
| 2215 | /* |
| 2216 | * If a left edge has not been seen |
| 2217 | * yet, then a future passing test |
| 2218 | * will mark this edge as the right |
| 2219 | * edge. |
| 2220 | */ |
| 2221 | if (left_edge[i] == delay_max + 1) |
| 2222 | right_edge[i] = -(d + 1); |
| 2223 | } |
Marek Vasut | b69c247 | 2015-07-18 20:34:00 +0200 | [diff] [blame] | 2224 | bit_chk >>= 1; |
Marek Vasut | e624caf | 2015-07-13 02:38:15 +0200 | [diff] [blame] | 2225 | } |
| 2226 | } |
| 2227 | |
| 2228 | /* Reset DQ delay chains to 0 */ |
| 2229 | if (write) |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2230 | scc_mgr_apply_group_dq_out1_delay(seq, 0); |
Marek Vasut | e624caf | 2015-07-13 02:38:15 +0200 | [diff] [blame] | 2231 | else |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2232 | scc_mgr_apply_group_dq_in_delay(seq, test_bgn, 0); |
Marek Vasut | e624caf | 2015-07-13 02:38:15 +0200 | [diff] [blame] | 2233 | |
| 2234 | *sticky_bit_chk = 0; |
| 2235 | for (i = per_dqs - 1; i >= 0; i--) { |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2236 | debug_cond(DLEVEL >= 2, |
Marek Vasut | e624caf | 2015-07-13 02:38:15 +0200 | [diff] [blame] | 2237 | "%s:%d vfifo_center: left_edge[%u]: %d right_edge[%u]: %d\n", |
| 2238 | __func__, __LINE__, i, left_edge[i], |
| 2239 | i, right_edge[i]); |
| 2240 | |
| 2241 | /* |
| 2242 | * Check for cases where we haven't found the left edge, |
| 2243 | * which makes our assignment of the the right edge invalid. |
| 2244 | * Reset it to the illegal value. |
| 2245 | */ |
| 2246 | if ((left_edge[i] == delay_max + 1) && |
| 2247 | (right_edge[i] != delay_max + 1)) { |
| 2248 | right_edge[i] = delay_max + 1; |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2249 | debug_cond(DLEVEL >= 2, |
Marek Vasut | e624caf | 2015-07-13 02:38:15 +0200 | [diff] [blame] | 2250 | "%s:%d vfifo_center: reset right_edge[%u]: %d\n", |
| 2251 | __func__, __LINE__, i, right_edge[i]); |
| 2252 | } |
| 2253 | |
| 2254 | /* |
| 2255 | * Reset sticky bit |
| 2256 | * READ: except for bits where we have seen both |
| 2257 | * the left and right edge. |
| 2258 | * WRITE: except for bits where we have seen the |
| 2259 | * left edge. |
| 2260 | */ |
| 2261 | *sticky_bit_chk <<= 1; |
| 2262 | if (write) { |
| 2263 | if (left_edge[i] != delay_max + 1) |
| 2264 | *sticky_bit_chk |= 1; |
| 2265 | } else { |
| 2266 | if ((left_edge[i] != delay_max + 1) && |
| 2267 | (right_edge[i] != delay_max + 1)) |
| 2268 | *sticky_bit_chk |= 1; |
| 2269 | } |
| 2270 | } |
Marek Vasut | e624caf | 2015-07-13 02:38:15 +0200 | [diff] [blame] | 2271 | } |
| 2272 | |
| 2273 | /** |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 2274 | * search_right_edge() - Find right edge of DQ/DQS working phase |
| 2275 | * @write: Perform read (Stage 2) or write (Stage 3) calibration |
| 2276 | * @rank_bgn: Rank number |
| 2277 | * @write_group: Write Group |
| 2278 | * @read_group: Read Group |
| 2279 | * @start_dqs: DQS start phase |
| 2280 | * @start_dqs_en: DQS enable start phase |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 2281 | * @sticky_bit_chk: Resulting sticky bit mask after the test |
| 2282 | * @left_edge: Left edge of the DQ/DQS phase |
| 2283 | * @right_edge: Right edge of the DQ/DQS phase |
| 2284 | * @use_read_test: Perform read test |
| 2285 | * |
| 2286 | * Find right edge of DQ/DQS working phase. |
| 2287 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2288 | static int search_right_edge(struct socfpga_sdrseq *seq, const int write, |
| 2289 | const int rank_bgn, const u32 write_group, |
| 2290 | const u32 read_group, const int start_dqs, |
| 2291 | const int start_dqs_en, u32 *sticky_bit_chk, |
| 2292 | int *left_edge, int *right_edge, |
| 2293 | const u32 use_read_test) |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 2294 | { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2295 | const u32 delay_max = write ? seq->iocfg->io_out1_delay_max : |
| 2296 | seq->iocfg->io_in_delay_max; |
| 2297 | const u32 dqs_max = write ? seq->iocfg->io_out1_delay_max : |
| 2298 | seq->iocfg->dqs_in_delay_max; |
| 2299 | const u32 per_dqs = write ? seq->rwcfg->mem_dq_per_write_dqs : |
| 2300 | seq->rwcfg->mem_dq_per_read_dqs; |
Marek Vasut | b69c247 | 2015-07-18 20:34:00 +0200 | [diff] [blame] | 2301 | u32 stop, bit_chk; |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 2302 | int i, d; |
| 2303 | |
| 2304 | for (d = 0; d <= dqs_max - start_dqs; d++) { |
| 2305 | if (write) { /* WRITE-ONLY */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2306 | scc_mgr_apply_group_dqs_io_and_oct_out1(seq, |
| 2307 | write_group, |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 2308 | d + start_dqs); |
| 2309 | } else { /* READ-ONLY */ |
| 2310 | scc_mgr_set_dqs_bus_in_delay(read_group, d + start_dqs); |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2311 | if (seq->iocfg->shift_dqs_en_when_shift_dqs) { |
Marek Vasut | 8af9ca0 | 2015-08-02 19:42:26 +0200 | [diff] [blame] | 2312 | u32 delay = d + start_dqs_en; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2313 | if (delay > seq->iocfg->dqs_en_delay_max) |
| 2314 | delay = seq->iocfg->dqs_en_delay_max; |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 2315 | scc_mgr_set_dqs_en_delay(read_group, delay); |
| 2316 | } |
| 2317 | scc_mgr_load_dqs(read_group); |
| 2318 | } |
| 2319 | |
| 2320 | writel(0, &sdr_scc_mgr->update); |
| 2321 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2322 | stop = search_stop_check(seq, write, d, rank_bgn, write_group, |
Marek Vasut | b69c247 | 2015-07-18 20:34:00 +0200 | [diff] [blame] | 2323 | read_group, &bit_chk, sticky_bit_chk, |
Marek Vasut | 85cd4d7 | 2015-07-13 02:48:34 +0200 | [diff] [blame] | 2324 | use_read_test); |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 2325 | if (stop == 1) { |
| 2326 | if (write && (d == 0)) { /* WRITE-ONLY */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2327 | for (i = 0; |
| 2328 | i < seq->rwcfg->mem_dq_per_write_dqs; |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 2329 | i++) { |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 2330 | /* |
| 2331 | * d = 0 failed, but it passed when |
| 2332 | * testing the left edge, so it must be |
| 2333 | * marginal, set it to -1 |
| 2334 | */ |
| 2335 | if (right_edge[i] == delay_max + 1 && |
| 2336 | left_edge[i] != delay_max + 1) |
| 2337 | right_edge[i] = -1; |
| 2338 | } |
| 2339 | } |
| 2340 | break; |
| 2341 | } |
| 2342 | |
| 2343 | /* stop != 1 */ |
| 2344 | for (i = 0; i < per_dqs; i++) { |
Marek Vasut | b69c247 | 2015-07-18 20:34:00 +0200 | [diff] [blame] | 2345 | if (bit_chk & 1) { |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 2346 | /* |
| 2347 | * Remember a passing test as |
| 2348 | * the right_edge. |
| 2349 | */ |
| 2350 | right_edge[i] = d; |
| 2351 | } else { |
| 2352 | if (d != 0) { |
| 2353 | /* |
| 2354 | * If a right edge has not |
| 2355 | * been seen yet, then a future |
| 2356 | * passing test will mark this |
| 2357 | * edge as the left edge. |
| 2358 | */ |
| 2359 | if (right_edge[i] == delay_max + 1) |
| 2360 | left_edge[i] = -(d + 1); |
| 2361 | } else { |
| 2362 | /* |
| 2363 | * d = 0 failed, but it passed |
| 2364 | * when testing the left edge, |
| 2365 | * so it must be marginal, set |
| 2366 | * it to -1 |
| 2367 | */ |
| 2368 | if (right_edge[i] == delay_max + 1 && |
| 2369 | left_edge[i] != delay_max + 1) |
| 2370 | right_edge[i] = -1; |
| 2371 | /* |
| 2372 | * If a right edge has not been |
| 2373 | * seen yet, then a future |
| 2374 | * passing test will mark this |
| 2375 | * edge as the left edge. |
| 2376 | */ |
| 2377 | else if (right_edge[i] == delay_max + 1) |
| 2378 | left_edge[i] = -(d + 1); |
| 2379 | } |
| 2380 | } |
| 2381 | |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2382 | debug_cond(DLEVEL >= 2, "%s:%d center[r,d=%u]: ", |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 2383 | __func__, __LINE__, d); |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2384 | debug_cond(DLEVEL >= 2, |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 2385 | "bit_chk_test=%i left_edge[%u]: %d ", |
Marek Vasut | b69c247 | 2015-07-18 20:34:00 +0200 | [diff] [blame] | 2386 | bit_chk & 1, i, left_edge[i]); |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2387 | debug_cond(DLEVEL >= 2, "right_edge[%u]: %d\n", i, |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 2388 | right_edge[i]); |
Marek Vasut | b69c247 | 2015-07-18 20:34:00 +0200 | [diff] [blame] | 2389 | bit_chk >>= 1; |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 2390 | } |
| 2391 | } |
| 2392 | |
| 2393 | /* Check that all bits have a window */ |
| 2394 | for (i = 0; i < per_dqs; i++) { |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2395 | debug_cond(DLEVEL >= 2, |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 2396 | "%s:%d write_center: left_edge[%u]: %d right_edge[%u]: %d", |
| 2397 | __func__, __LINE__, i, left_edge[i], |
| 2398 | i, right_edge[i]); |
| 2399 | if ((left_edge[i] == dqs_max + 1) || |
| 2400 | (right_edge[i] == dqs_max + 1)) |
| 2401 | return i + 1; /* FIXME: If we fail, retval > 0 */ |
| 2402 | } |
| 2403 | |
| 2404 | return 0; |
| 2405 | } |
| 2406 | |
Marek Vasut | aa0e6e1 | 2015-07-18 19:18:06 +0200 | [diff] [blame] | 2407 | /** |
| 2408 | * get_window_mid_index() - Find the best middle setting of DQ/DQS phase |
| 2409 | * @write: Perform read (Stage 2) or write (Stage 3) calibration |
| 2410 | * @left_edge: Left edge of the DQ/DQS phase |
| 2411 | * @right_edge: Right edge of the DQ/DQS phase |
| 2412 | * @mid_min: Best DQ/DQS phase middle setting |
| 2413 | * |
| 2414 | * Find index and value of the middle of the DQ/DQS working phase. |
| 2415 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2416 | static int get_window_mid_index(struct socfpga_sdrseq *seq, |
| 2417 | const int write, int *left_edge, |
Marek Vasut | aa0e6e1 | 2015-07-18 19:18:06 +0200 | [diff] [blame] | 2418 | int *right_edge, int *mid_min) |
| 2419 | { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2420 | const u32 per_dqs = write ? seq->rwcfg->mem_dq_per_write_dqs : |
| 2421 | seq->rwcfg->mem_dq_per_read_dqs; |
Marek Vasut | aa0e6e1 | 2015-07-18 19:18:06 +0200 | [diff] [blame] | 2422 | int i, mid, min_index; |
| 2423 | |
| 2424 | /* Find middle of window for each DQ bit */ |
| 2425 | *mid_min = left_edge[0] - right_edge[0]; |
| 2426 | min_index = 0; |
| 2427 | for (i = 1; i < per_dqs; i++) { |
| 2428 | mid = left_edge[i] - right_edge[i]; |
| 2429 | if (mid < *mid_min) { |
| 2430 | *mid_min = mid; |
| 2431 | min_index = i; |
| 2432 | } |
| 2433 | } |
| 2434 | |
| 2435 | /* |
| 2436 | * -mid_min/2 represents the amount that we need to move DQS. |
| 2437 | * If mid_min is odd and positive we'll need to add one to make |
| 2438 | * sure the rounding in further calculations is correct (always |
| 2439 | * bias to the right), so just add 1 for all positive values. |
| 2440 | */ |
| 2441 | if (*mid_min > 0) |
| 2442 | (*mid_min)++; |
| 2443 | *mid_min = *mid_min / 2; |
| 2444 | |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2445 | debug_cond(DLEVEL >= 1, "%s:%d vfifo_center: *mid_min=%d (index=%u)\n", |
Marek Vasut | aa0e6e1 | 2015-07-18 19:18:06 +0200 | [diff] [blame] | 2446 | __func__, __LINE__, *mid_min, min_index); |
| 2447 | return min_index; |
| 2448 | } |
| 2449 | |
Marek Vasut | 89feb50 | 2015-07-18 19:46:26 +0200 | [diff] [blame] | 2450 | /** |
| 2451 | * center_dq_windows() - Center the DQ/DQS windows |
| 2452 | * @write: Perform read (Stage 2) or write (Stage 3) calibration |
| 2453 | * @left_edge: Left edge of the DQ/DQS phase |
| 2454 | * @right_edge: Right edge of the DQ/DQS phase |
| 2455 | * @mid_min: Adjusted DQ/DQS phase middle setting |
| 2456 | * @orig_mid_min: Original DQ/DQS phase middle setting |
| 2457 | * @min_index: DQ/DQS phase middle setting index |
| 2458 | * @test_bgn: Rank number to begin the test |
| 2459 | * @dq_margin: Amount of shift for the DQ |
| 2460 | * @dqs_margin: Amount of shift for the DQS |
| 2461 | * |
| 2462 | * Align the DQ/DQS windows in each group. |
| 2463 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2464 | static void center_dq_windows(struct socfpga_sdrseq *seq, |
| 2465 | const int write, int *left_edge, int *right_edge, |
Marek Vasut | 89feb50 | 2015-07-18 19:46:26 +0200 | [diff] [blame] | 2466 | const int mid_min, const int orig_mid_min, |
| 2467 | const int min_index, const int test_bgn, |
| 2468 | int *dq_margin, int *dqs_margin) |
| 2469 | { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2470 | const s32 delay_max = write ? seq->iocfg->io_out1_delay_max : |
| 2471 | seq->iocfg->io_in_delay_max; |
| 2472 | const s32 per_dqs = write ? seq->rwcfg->mem_dq_per_write_dqs : |
| 2473 | seq->rwcfg->mem_dq_per_read_dqs; |
Marek Vasut | 66acabc | 2016-04-05 23:17:35 +0200 | [diff] [blame] | 2474 | const s32 delay_off = write ? SCC_MGR_IO_OUT1_DELAY_OFFSET : |
Marek Vasut | 89feb50 | 2015-07-18 19:46:26 +0200 | [diff] [blame] | 2475 | SCC_MGR_IO_IN_DELAY_OFFSET; |
Marek Vasut | 66acabc | 2016-04-05 23:17:35 +0200 | [diff] [blame] | 2476 | const s32 addr = SDR_PHYGRP_SCCGRP_ADDRESS | delay_off; |
Marek Vasut | 89feb50 | 2015-07-18 19:46:26 +0200 | [diff] [blame] | 2477 | |
Marek Vasut | 66acabc | 2016-04-05 23:17:35 +0200 | [diff] [blame] | 2478 | s32 temp_dq_io_delay1; |
Marek Vasut | 89feb50 | 2015-07-18 19:46:26 +0200 | [diff] [blame] | 2479 | int shift_dq, i, p; |
| 2480 | |
| 2481 | /* Initialize data for export structures */ |
| 2482 | *dqs_margin = delay_max + 1; |
| 2483 | *dq_margin = delay_max + 1; |
| 2484 | |
| 2485 | /* add delay to bring centre of all DQ windows to the same "level" */ |
| 2486 | for (i = 0, p = test_bgn; i < per_dqs; i++, p++) { |
| 2487 | /* Use values before divide by 2 to reduce round off error */ |
| 2488 | shift_dq = (left_edge[i] - right_edge[i] - |
| 2489 | (left_edge[min_index] - right_edge[min_index]))/2 + |
| 2490 | (orig_mid_min - mid_min); |
| 2491 | |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2492 | debug_cond(DLEVEL >= 2, |
Marek Vasut | 89feb50 | 2015-07-18 19:46:26 +0200 | [diff] [blame] | 2493 | "vfifo_center: before: shift_dq[%u]=%d\n", |
| 2494 | i, shift_dq); |
| 2495 | |
Marek Vasut | 66acabc | 2016-04-05 23:17:35 +0200 | [diff] [blame] | 2496 | temp_dq_io_delay1 = readl(addr + (i << 2)); |
Marek Vasut | 89feb50 | 2015-07-18 19:46:26 +0200 | [diff] [blame] | 2497 | |
| 2498 | if (shift_dq + temp_dq_io_delay1 > delay_max) |
Marek Vasut | 66acabc | 2016-04-05 23:17:35 +0200 | [diff] [blame] | 2499 | shift_dq = delay_max - temp_dq_io_delay1; |
Marek Vasut | 89feb50 | 2015-07-18 19:46:26 +0200 | [diff] [blame] | 2500 | else if (shift_dq + temp_dq_io_delay1 < 0) |
| 2501 | shift_dq = -temp_dq_io_delay1; |
| 2502 | |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2503 | debug_cond(DLEVEL >= 2, |
Marek Vasut | 89feb50 | 2015-07-18 19:46:26 +0200 | [diff] [blame] | 2504 | "vfifo_center: after: shift_dq[%u]=%d\n", |
| 2505 | i, shift_dq); |
| 2506 | |
| 2507 | if (write) |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 2508 | scc_mgr_set_dq_out1_delay(i, |
| 2509 | temp_dq_io_delay1 + shift_dq); |
Marek Vasut | 89feb50 | 2015-07-18 19:46:26 +0200 | [diff] [blame] | 2510 | else |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 2511 | scc_mgr_set_dq_in_delay(p, |
| 2512 | temp_dq_io_delay1 + shift_dq); |
Marek Vasut | 89feb50 | 2015-07-18 19:46:26 +0200 | [diff] [blame] | 2513 | |
| 2514 | scc_mgr_load_dq(p); |
| 2515 | |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2516 | debug_cond(DLEVEL >= 2, |
Marek Vasut | 89feb50 | 2015-07-18 19:46:26 +0200 | [diff] [blame] | 2517 | "vfifo_center: margin[%u]=[%d,%d]\n", i, |
| 2518 | left_edge[i] - shift_dq + (-mid_min), |
| 2519 | right_edge[i] + shift_dq - (-mid_min)); |
| 2520 | |
| 2521 | /* To determine values for export structures */ |
| 2522 | if (left_edge[i] - shift_dq + (-mid_min) < *dq_margin) |
| 2523 | *dq_margin = left_edge[i] - shift_dq + (-mid_min); |
| 2524 | |
| 2525 | if (right_edge[i] + shift_dq - (-mid_min) < *dqs_margin) |
| 2526 | *dqs_margin = right_edge[i] + shift_dq - (-mid_min); |
| 2527 | } |
Marek Vasut | 89feb50 | 2015-07-18 19:46:26 +0200 | [diff] [blame] | 2528 | } |
| 2529 | |
Marek Vasut | 9cdbb96 | 2015-07-21 04:27:32 +0200 | [diff] [blame] | 2530 | /** |
| 2531 | * rw_mgr_mem_calibrate_vfifo_center() - Per-bit deskew DQ and centering |
| 2532 | * @rank_bgn: Rank number |
| 2533 | * @rw_group: Read/Write Group |
| 2534 | * @test_bgn: Rank at which the test begins |
| 2535 | * @use_read_test: Perform a read test |
| 2536 | * @update_fom: Update FOM |
| 2537 | * |
| 2538 | * Per-bit deskew DQ and centering. |
| 2539 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2540 | static int rw_mgr_mem_calibrate_vfifo_center(struct socfpga_sdrseq *seq, |
| 2541 | const u32 rank_bgn, |
| 2542 | const u32 rw_group, |
| 2543 | const u32 test_bgn, |
| 2544 | const int use_read_test, |
| 2545 | const int update_fom) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2546 | { |
Marek Vasut | f1b8f71 | 2015-07-18 19:57:12 +0200 | [diff] [blame] | 2547 | const u32 addr = |
| 2548 | SDR_PHYGRP_SCCGRP_ADDRESS + SCC_MGR_DQS_IN_DELAY_OFFSET + |
Marek Vasut | dfed1e6 | 2015-07-18 20:42:27 +0200 | [diff] [blame] | 2549 | (rw_group << 2); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2550 | /* |
| 2551 | * Store these as signed since there are comparisons with |
| 2552 | * signed numbers. |
| 2553 | */ |
Marek Vasut | 8af9ca0 | 2015-08-02 19:42:26 +0200 | [diff] [blame] | 2554 | u32 sticky_bit_chk; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2555 | s32 left_edge[seq->rwcfg->mem_dq_per_read_dqs]; |
| 2556 | s32 right_edge[seq->rwcfg->mem_dq_per_read_dqs]; |
| 2557 | s32 orig_mid_min, mid_min; |
| 2558 | s32 new_dqs, start_dqs, start_dqs_en = 0, final_dqs_en; |
| 2559 | s32 dq_margin, dqs_margin; |
Marek Vasut | f1b8f71 | 2015-07-18 19:57:12 +0200 | [diff] [blame] | 2560 | int i, min_index; |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 2561 | int ret; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2562 | |
Marek Vasut | dfed1e6 | 2015-07-18 20:42:27 +0200 | [diff] [blame] | 2563 | debug("%s:%d: %u %u", __func__, __LINE__, rw_group, test_bgn); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2564 | |
Marek Vasut | f1b8f71 | 2015-07-18 19:57:12 +0200 | [diff] [blame] | 2565 | start_dqs = readl(addr); |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2566 | if (seq->iocfg->shift_dqs_en_when_shift_dqs) |
| 2567 | start_dqs_en = readl(addr - seq->iocfg->dqs_en_delay_offset); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2568 | |
| 2569 | /* set the left and right edge of each bit to an illegal value */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2570 | /* use (seq->iocfg->io_in_delay_max + 1) as an illegal value */ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2571 | sticky_bit_chk = 0; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2572 | for (i = 0; i < seq->rwcfg->mem_dq_per_read_dqs; i++) { |
| 2573 | left_edge[i] = seq->iocfg->io_in_delay_max + 1; |
| 2574 | right_edge[i] = seq->iocfg->io_in_delay_max + 1; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2575 | } |
| 2576 | |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2577 | /* Search for the left edge of the window for each bit */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2578 | search_left_edge(seq, 0, rank_bgn, rw_group, rw_group, test_bgn, |
Marek Vasut | b69c247 | 2015-07-18 20:34:00 +0200 | [diff] [blame] | 2579 | &sticky_bit_chk, |
Marek Vasut | e624caf | 2015-07-13 02:38:15 +0200 | [diff] [blame] | 2580 | left_edge, right_edge, use_read_test); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2581 | |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2582 | /* Search for the right edge of the window for each bit */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2583 | ret = search_right_edge(seq, 0, rank_bgn, rw_group, rw_group, |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 2584 | start_dqs, start_dqs_en, |
Marek Vasut | b69c247 | 2015-07-18 20:34:00 +0200 | [diff] [blame] | 2585 | &sticky_bit_chk, |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 2586 | left_edge, right_edge, use_read_test); |
| 2587 | if (ret) { |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2588 | /* |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 2589 | * Restore delay chain settings before letting the loop |
| 2590 | * in rw_mgr_mem_calibrate_vfifo to retry different |
| 2591 | * dqs/ck relationships. |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2592 | */ |
Marek Vasut | dfed1e6 | 2015-07-18 20:42:27 +0200 | [diff] [blame] | 2593 | scc_mgr_set_dqs_bus_in_delay(rw_group, start_dqs); |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2594 | if (seq->iocfg->shift_dqs_en_when_shift_dqs) |
Marek Vasut | dfed1e6 | 2015-07-18 20:42:27 +0200 | [diff] [blame] | 2595 | scc_mgr_set_dqs_en_delay(rw_group, start_dqs_en); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2596 | |
Marek Vasut | dfed1e6 | 2015-07-18 20:42:27 +0200 | [diff] [blame] | 2597 | scc_mgr_load_dqs(rw_group); |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 2598 | writel(0, &sdr_scc_mgr->update); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2599 | |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2600 | debug_cond(DLEVEL >= 1, |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 2601 | "%s:%d vfifo_center: failed to find edge [%u]: %d %d", |
| 2602 | __func__, __LINE__, i, left_edge[i], right_edge[i]); |
| 2603 | if (use_read_test) { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2604 | set_failing_group_stage(seq, rw_group * |
| 2605 | seq->rwcfg->mem_dq_per_read_dqs + i, |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 2606 | CAL_STAGE_VFIFO, |
| 2607 | CAL_SUBSTAGE_VFIFO_CENTER); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2608 | } else { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2609 | set_failing_group_stage(seq, rw_group * |
| 2610 | seq->rwcfg->mem_dq_per_read_dqs + i, |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 2611 | CAL_STAGE_VFIFO_AFTER_WRITES, |
| 2612 | CAL_SUBSTAGE_VFIFO_CENTER); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2613 | } |
Marek Vasut | d29f804 | 2015-07-18 20:44:28 +0200 | [diff] [blame] | 2614 | return -EIO; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2615 | } |
| 2616 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2617 | min_index = get_window_mid_index(seq, 0, left_edge, right_edge, |
| 2618 | &mid_min); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2619 | |
| 2620 | /* Determine the amount we can change DQS (which is -mid_min) */ |
| 2621 | orig_mid_min = mid_min; |
| 2622 | new_dqs = start_dqs - mid_min; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2623 | if (new_dqs > seq->iocfg->dqs_in_delay_max) |
| 2624 | new_dqs = seq->iocfg->dqs_in_delay_max; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2625 | else if (new_dqs < 0) |
| 2626 | new_dqs = 0; |
| 2627 | |
| 2628 | mid_min = start_dqs - new_dqs; |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2629 | debug_cond(DLEVEL >= 1, "vfifo_center: new mid_min=%d new_dqs=%d\n", |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2630 | mid_min, new_dqs); |
| 2631 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2632 | if (seq->iocfg->shift_dqs_en_when_shift_dqs) { |
| 2633 | if (start_dqs_en - mid_min > seq->iocfg->dqs_en_delay_max) |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 2634 | mid_min += start_dqs_en - mid_min - |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2635 | seq->iocfg->dqs_en_delay_max; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2636 | else if (start_dqs_en - mid_min < 0) |
| 2637 | mid_min += start_dqs_en - mid_min; |
| 2638 | } |
| 2639 | new_dqs = start_dqs - mid_min; |
| 2640 | |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2641 | debug_cond(DLEVEL >= 1, |
Marek Vasut | ca8ea37 | 2015-07-18 08:01:45 +0200 | [diff] [blame] | 2642 | "vfifo_center: start_dqs=%d start_dqs_en=%d new_dqs=%d mid_min=%d\n", |
| 2643 | start_dqs, |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2644 | seq->iocfg->shift_dqs_en_when_shift_dqs ? start_dqs_en : -1, |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2645 | new_dqs, mid_min); |
| 2646 | |
Marek Vasut | 89feb50 | 2015-07-18 19:46:26 +0200 | [diff] [blame] | 2647 | /* Add delay to bring centre of all DQ windows to the same "level". */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2648 | center_dq_windows(seq, 0, left_edge, right_edge, mid_min, orig_mid_min, |
Marek Vasut | 89feb50 | 2015-07-18 19:46:26 +0200 | [diff] [blame] | 2649 | min_index, test_bgn, &dq_margin, &dqs_margin); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2650 | |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2651 | /* Move DQS-en */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2652 | if (seq->iocfg->shift_dqs_en_when_shift_dqs) { |
Marek Vasut | f1b8f71 | 2015-07-18 19:57:12 +0200 | [diff] [blame] | 2653 | final_dqs_en = start_dqs_en - mid_min; |
Marek Vasut | dfed1e6 | 2015-07-18 20:42:27 +0200 | [diff] [blame] | 2654 | scc_mgr_set_dqs_en_delay(rw_group, final_dqs_en); |
| 2655 | scc_mgr_load_dqs(rw_group); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2656 | } |
| 2657 | |
| 2658 | /* Move DQS */ |
Marek Vasut | dfed1e6 | 2015-07-18 20:42:27 +0200 | [diff] [blame] | 2659 | scc_mgr_set_dqs_bus_in_delay(rw_group, new_dqs); |
| 2660 | scc_mgr_load_dqs(rw_group); |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2661 | debug_cond(DLEVEL >= 2, |
Marek Vasut | ca8ea37 | 2015-07-18 08:01:45 +0200 | [diff] [blame] | 2662 | "%s:%d vfifo_center: dq_margin=%d dqs_margin=%d", |
| 2663 | __func__, __LINE__, dq_margin, dqs_margin); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2664 | |
| 2665 | /* |
| 2666 | * Do not remove this line as it makes sure all of our decisions |
| 2667 | * have been applied. Apply the update bit. |
| 2668 | */ |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 2669 | writel(0, &sdr_scc_mgr->update); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2670 | |
Marek Vasut | d29f804 | 2015-07-18 20:44:28 +0200 | [diff] [blame] | 2671 | if ((dq_margin < 0) || (dqs_margin < 0)) |
| 2672 | return -EINVAL; |
| 2673 | |
| 2674 | return 0; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2675 | } |
| 2676 | |
Marek Vasut | c27ea62 | 2015-07-17 03:16:45 +0200 | [diff] [blame] | 2677 | /** |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2678 | * rw_mgr_mem_calibrate_guaranteed_write() - Perform guaranteed write into the |
| 2679 | * device |
Marek Vasut | 6ca5b96 | 2015-07-18 02:46:56 +0200 | [diff] [blame] | 2680 | * @rw_group: Read/Write Group |
| 2681 | * @phase: DQ/DQS phase |
| 2682 | * |
| 2683 | * Because initially no communication ca be reliably performed with the memory |
| 2684 | * device, the sequencer uses a guaranteed write mechanism to write data into |
| 2685 | * the memory device. |
| 2686 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2687 | static int rw_mgr_mem_calibrate_guaranteed_write(struct socfpga_sdrseq *seq, |
| 2688 | const u32 rw_group, |
Marek Vasut | 6ca5b96 | 2015-07-18 02:46:56 +0200 | [diff] [blame] | 2689 | const u32 phase) |
| 2690 | { |
Marek Vasut | 6ca5b96 | 2015-07-18 02:46:56 +0200 | [diff] [blame] | 2691 | int ret; |
| 2692 | |
| 2693 | /* Set a particular DQ/DQS phase. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2694 | scc_mgr_set_dqdqs_output_phase_all_ranks(seq, rw_group, phase); |
Marek Vasut | 6ca5b96 | 2015-07-18 02:46:56 +0200 | [diff] [blame] | 2695 | |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2696 | debug_cond(DLEVEL >= 1, "%s:%d guaranteed write: g=%u p=%u\n", |
Marek Vasut | 6ca5b96 | 2015-07-18 02:46:56 +0200 | [diff] [blame] | 2697 | __func__, __LINE__, rw_group, phase); |
| 2698 | |
| 2699 | /* |
| 2700 | * Altera EMI_RM 2015.05.04 :: Figure 1-25 |
| 2701 | * Load up the patterns used by read calibration using the |
| 2702 | * current DQDQS phase. |
| 2703 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2704 | rw_mgr_mem_calibrate_read_load_patterns(seq, 0, 1); |
Marek Vasut | 6ca5b96 | 2015-07-18 02:46:56 +0200 | [diff] [blame] | 2705 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2706 | if (seq->gbl.phy_debug_mode_flags & PHY_DEBUG_DISABLE_GUARANTEED_READ) |
Marek Vasut | 6ca5b96 | 2015-07-18 02:46:56 +0200 | [diff] [blame] | 2707 | return 0; |
| 2708 | |
| 2709 | /* |
| 2710 | * Altera EMI_RM 2015.05.04 :: Figure 1-26 |
| 2711 | * Back-to-Back reads of the patterns used for calibration. |
| 2712 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2713 | ret = rw_mgr_mem_calibrate_read_test_patterns(seq, 0, rw_group, 1); |
Marek Vasut | 55c4d69 | 2015-07-18 03:55:07 +0200 | [diff] [blame] | 2714 | if (ret) |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2715 | debug_cond(DLEVEL >= 1, |
Marek Vasut | 6ca5b96 | 2015-07-18 02:46:56 +0200 | [diff] [blame] | 2716 | "%s:%d Guaranteed read test failed: g=%u p=%u\n", |
| 2717 | __func__, __LINE__, rw_group, phase); |
Marek Vasut | 55c4d69 | 2015-07-18 03:55:07 +0200 | [diff] [blame] | 2718 | return ret; |
Marek Vasut | 6ca5b96 | 2015-07-18 02:46:56 +0200 | [diff] [blame] | 2719 | } |
| 2720 | |
| 2721 | /** |
Marek Vasut | feb5e65 | 2015-07-18 02:57:32 +0200 | [diff] [blame] | 2722 | * rw_mgr_mem_calibrate_dqs_enable_calibration() - DQS Enable Calibration |
| 2723 | * @rw_group: Read/Write Group |
| 2724 | * @test_bgn: Rank at which the test begins |
| 2725 | * |
| 2726 | * DQS enable calibration ensures reliable capture of the DQ signal without |
| 2727 | * glitches on the DQS line. |
| 2728 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2729 | static int |
| 2730 | rw_mgr_mem_calibrate_dqs_enable_calibration(struct socfpga_sdrseq *seq, |
| 2731 | const u32 rw_group, |
| 2732 | const u32 test_bgn) |
Marek Vasut | feb5e65 | 2015-07-18 02:57:32 +0200 | [diff] [blame] | 2733 | { |
Marek Vasut | feb5e65 | 2015-07-18 02:57:32 +0200 | [diff] [blame] | 2734 | /* |
| 2735 | * Altera EMI_RM 2015.05.04 :: Figure 1-27 |
| 2736 | * DQS and DQS Eanble Signal Relationships. |
| 2737 | */ |
Marek Vasut | 3aa19dc | 2015-07-18 04:28:42 +0200 | [diff] [blame] | 2738 | |
| 2739 | /* We start at zero, so have one less dq to devide among */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2740 | const u32 delay_step = seq->iocfg->io_in_delay_max / |
| 2741 | (seq->rwcfg->mem_dq_per_read_dqs - 1); |
Marek Vasut | 28dbf12 | 2015-07-20 09:20:42 +0200 | [diff] [blame] | 2742 | int ret; |
Marek Vasut | 3aa19dc | 2015-07-18 04:28:42 +0200 | [diff] [blame] | 2743 | u32 i, p, d, r; |
| 2744 | |
| 2745 | debug("%s:%d (%u,%u)\n", __func__, __LINE__, rw_group, test_bgn); |
| 2746 | |
| 2747 | /* Try different dq_in_delays since the DQ path is shorter than DQS. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2748 | for (r = 0; r < seq->rwcfg->mem_number_of_ranks; |
Marek Vasut | 3aa19dc | 2015-07-18 04:28:42 +0200 | [diff] [blame] | 2749 | r += NUM_RANKS_PER_SHADOW_REG) { |
| 2750 | for (i = 0, p = test_bgn, d = 0; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2751 | i < seq->rwcfg->mem_dq_per_read_dqs; |
Marek Vasut | 3aa19dc | 2015-07-18 04:28:42 +0200 | [diff] [blame] | 2752 | i++, p++, d += delay_step) { |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2753 | debug_cond(DLEVEL >= 1, |
Marek Vasut | 3aa19dc | 2015-07-18 04:28:42 +0200 | [diff] [blame] | 2754 | "%s:%d: g=%u r=%u i=%u p=%u d=%u\n", |
| 2755 | __func__, __LINE__, rw_group, r, i, p, d); |
| 2756 | |
| 2757 | scc_mgr_set_dq_in_delay(p, d); |
| 2758 | scc_mgr_load_dq(p); |
| 2759 | } |
| 2760 | |
| 2761 | writel(0, &sdr_scc_mgr->update); |
| 2762 | } |
| 2763 | |
| 2764 | /* |
| 2765 | * Try rw_mgr_mem_calibrate_vfifo_find_dqs_en_phase across different |
| 2766 | * dq_in_delay values |
| 2767 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2768 | ret = rw_mgr_mem_calibrate_vfifo_find_dqs_en_phase(seq, rw_group); |
Marek Vasut | 3aa19dc | 2015-07-18 04:28:42 +0200 | [diff] [blame] | 2769 | |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2770 | debug_cond(DLEVEL >= 1, |
Vagrant Cascadian | a321d04 | 2021-12-21 13:07:01 -0800 | [diff] [blame] | 2771 | "%s:%d: g=%u found=%u; Resetting delay chain to zero\n", |
Marek Vasut | 28dbf12 | 2015-07-20 09:20:42 +0200 | [diff] [blame] | 2772 | __func__, __LINE__, rw_group, !ret); |
Marek Vasut | 3aa19dc | 2015-07-18 04:28:42 +0200 | [diff] [blame] | 2773 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2774 | for (r = 0; r < seq->rwcfg->mem_number_of_ranks; |
Marek Vasut | 3aa19dc | 2015-07-18 04:28:42 +0200 | [diff] [blame] | 2775 | r += NUM_RANKS_PER_SHADOW_REG) { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2776 | scc_mgr_apply_group_dq_in_delay(seq, test_bgn, 0); |
Marek Vasut | 3aa19dc | 2015-07-18 04:28:42 +0200 | [diff] [blame] | 2777 | writel(0, &sdr_scc_mgr->update); |
| 2778 | } |
| 2779 | |
Marek Vasut | 28dbf12 | 2015-07-20 09:20:42 +0200 | [diff] [blame] | 2780 | return ret; |
Marek Vasut | feb5e65 | 2015-07-18 02:57:32 +0200 | [diff] [blame] | 2781 | } |
| 2782 | |
| 2783 | /** |
Marek Vasut | 349ea3e | 2015-07-18 03:10:31 +0200 | [diff] [blame] | 2784 | * rw_mgr_mem_calibrate_dq_dqs_centering() - Centering DQ/DQS |
| 2785 | * @rw_group: Read/Write Group |
| 2786 | * @test_bgn: Rank at which the test begins |
| 2787 | * @use_read_test: Perform a read test |
| 2788 | * @update_fom: Update FOM |
| 2789 | * |
| 2790 | * The centerin DQ/DQS stage attempts to align DQ and DQS signals on reads |
| 2791 | * within a group. |
| 2792 | */ |
| 2793 | static int |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2794 | rw_mgr_mem_calibrate_dq_dqs_centering(struct socfpga_sdrseq *seq, |
| 2795 | const u32 rw_group, const u32 test_bgn, |
Marek Vasut | 349ea3e | 2015-07-18 03:10:31 +0200 | [diff] [blame] | 2796 | const int use_read_test, |
| 2797 | const int update_fom) |
| 2798 | |
| 2799 | { |
| 2800 | int ret, grp_calibrated; |
| 2801 | u32 rank_bgn, sr; |
| 2802 | |
| 2803 | /* |
| 2804 | * Altera EMI_RM 2015.05.04 :: Figure 1-28 |
| 2805 | * Read per-bit deskew can be done on a per shadow register basis. |
| 2806 | */ |
| 2807 | grp_calibrated = 1; |
| 2808 | for (rank_bgn = 0, sr = 0; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2809 | rank_bgn < seq->rwcfg->mem_number_of_ranks; |
Marek Vasut | 349ea3e | 2015-07-18 03:10:31 +0200 | [diff] [blame] | 2810 | rank_bgn += NUM_RANKS_PER_SHADOW_REG, sr++) { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2811 | ret = rw_mgr_mem_calibrate_vfifo_center(seq, rank_bgn, rw_group, |
Marek Vasut | dfed1e6 | 2015-07-18 20:42:27 +0200 | [diff] [blame] | 2812 | test_bgn, |
Marek Vasut | 349ea3e | 2015-07-18 03:10:31 +0200 | [diff] [blame] | 2813 | use_read_test, |
| 2814 | update_fom); |
Marek Vasut | d29f804 | 2015-07-18 20:44:28 +0200 | [diff] [blame] | 2815 | if (!ret) |
Marek Vasut | 349ea3e | 2015-07-18 03:10:31 +0200 | [diff] [blame] | 2816 | continue; |
| 2817 | |
| 2818 | grp_calibrated = 0; |
| 2819 | } |
| 2820 | |
| 2821 | if (!grp_calibrated) |
| 2822 | return -EIO; |
| 2823 | |
| 2824 | return 0; |
| 2825 | } |
| 2826 | |
| 2827 | /** |
Marek Vasut | c27ea62 | 2015-07-17 03:16:45 +0200 | [diff] [blame] | 2828 | * rw_mgr_mem_calibrate_vfifo() - Calibrate the read valid prediction FIFO |
| 2829 | * @rw_group: Read/Write Group |
| 2830 | * @test_bgn: Rank at which the test begins |
| 2831 | * |
| 2832 | * Stage 1: Calibrate the read valid prediction FIFO. |
| 2833 | * |
| 2834 | * This function implements UniPHY calibration Stage 1, as explained in |
| 2835 | * detail in Altera EMI_RM 2015.05.04 , "UniPHY Calibration Stages". |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2836 | * |
Marek Vasut | c27ea62 | 2015-07-17 03:16:45 +0200 | [diff] [blame] | 2837 | * - read valid prediction will consist of finding: |
| 2838 | * - DQS enable phase and DQS enable delay (DQS Enable Calibration) |
| 2839 | * - DQS input phase and DQS input delay (DQ/DQS Centering) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2840 | * - we also do a per-bit deskew on the DQ lines. |
| 2841 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2842 | static int rw_mgr_mem_calibrate_vfifo(struct socfpga_sdrseq *seq, |
| 2843 | const u32 rw_group, const u32 test_bgn) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2844 | { |
Marek Vasut | 8af9ca0 | 2015-08-02 19:42:26 +0200 | [diff] [blame] | 2845 | u32 p, d; |
| 2846 | u32 dtaps_per_ptap; |
| 2847 | u32 failed_substage; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2848 | |
Marek Vasut | 6ca5b96 | 2015-07-18 02:46:56 +0200 | [diff] [blame] | 2849 | int ret; |
| 2850 | |
Marek Vasut | e42fcea | 2015-07-17 04:24:18 +0200 | [diff] [blame] | 2851 | debug("%s:%d: %u %u\n", __func__, __LINE__, rw_group, test_bgn); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2852 | |
Marek Vasut | 912d43e | 2015-07-18 03:15:34 +0200 | [diff] [blame] | 2853 | /* Update info for sims */ |
| 2854 | reg_file_set_group(rw_group); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2855 | reg_file_set_stage(CAL_STAGE_VFIFO); |
Marek Vasut | 912d43e | 2015-07-18 03:15:34 +0200 | [diff] [blame] | 2856 | reg_file_set_sub_stage(CAL_SUBSTAGE_GUARANTEED_READ); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2857 | |
Marek Vasut | 912d43e | 2015-07-18 03:15:34 +0200 | [diff] [blame] | 2858 | failed_substage = CAL_SUBSTAGE_GUARANTEED_READ; |
| 2859 | |
| 2860 | /* USER Determine number of delay taps for each phase tap. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2861 | dtaps_per_ptap = DIV_ROUND_UP(seq->iocfg->delay_per_opa_tap, |
| 2862 | seq->iocfg->delay_per_dqs_en_dchain_tap) |
| 2863 | - 1; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2864 | |
Marek Vasut | f2a4bda | 2015-07-17 03:50:17 +0200 | [diff] [blame] | 2865 | for (d = 0; d <= dtaps_per_ptap; d += 2) { |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2866 | /* |
| 2867 | * In RLDRAMX we may be messing the delay of pins in |
Marek Vasut | e42fcea | 2015-07-17 04:24:18 +0200 | [diff] [blame] | 2868 | * the same write rw_group but outside of the current read |
| 2869 | * the rw_group, but that's ok because we haven't calibrated |
Marek Vasut | d7f4915 | 2015-07-17 03:44:26 +0200 | [diff] [blame] | 2870 | * output side yet. |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2871 | */ |
| 2872 | if (d > 0) { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2873 | scc_mgr_apply_group_all_out_delay_add_all_ranks(seq, |
| 2874 | rw_group, |
| 2875 | d); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2876 | } |
| 2877 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2878 | for (p = 0; p <= seq->iocfg->dqdqs_out_phase_max; p++) { |
Marek Vasut | 6ca5b96 | 2015-07-18 02:46:56 +0200 | [diff] [blame] | 2879 | /* 1) Guaranteed Write */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2880 | ret = rw_mgr_mem_calibrate_guaranteed_write(seq, |
| 2881 | rw_group, |
| 2882 | p); |
Marek Vasut | 6ca5b96 | 2015-07-18 02:46:56 +0200 | [diff] [blame] | 2883 | if (ret) |
| 2884 | break; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2885 | |
Marek Vasut | feb5e65 | 2015-07-18 02:57:32 +0200 | [diff] [blame] | 2886 | /* 2) DQS Enable Calibration */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2887 | ret = rw_mgr_mem_calibrate_dqs_enable_calibration(seq, |
| 2888 | rw_group, |
Marek Vasut | feb5e65 | 2015-07-18 02:57:32 +0200 | [diff] [blame] | 2889 | test_bgn); |
| 2890 | if (ret) { |
Marek Vasut | f2a4bda | 2015-07-17 03:50:17 +0200 | [diff] [blame] | 2891 | failed_substage = CAL_SUBSTAGE_DQS_EN_PHASE; |
| 2892 | continue; |
| 2893 | } |
| 2894 | |
Marek Vasut | 349ea3e | 2015-07-18 03:10:31 +0200 | [diff] [blame] | 2895 | /* 3) Centering DQ/DQS */ |
Marek Vasut | f2a4bda | 2015-07-17 03:50:17 +0200 | [diff] [blame] | 2896 | /* |
Marek Vasut | 349ea3e | 2015-07-18 03:10:31 +0200 | [diff] [blame] | 2897 | * If doing read after write calibration, do not update |
| 2898 | * FOM now. Do it then. |
Marek Vasut | f2a4bda | 2015-07-17 03:50:17 +0200 | [diff] [blame] | 2899 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2900 | ret = rw_mgr_mem_calibrate_dq_dqs_centering(seq, |
| 2901 | rw_group, |
| 2902 | test_bgn, |
| 2903 | 1, 0); |
Marek Vasut | 349ea3e | 2015-07-18 03:10:31 +0200 | [diff] [blame] | 2904 | if (ret) { |
Marek Vasut | f2a4bda | 2015-07-17 03:50:17 +0200 | [diff] [blame] | 2905 | failed_substage = CAL_SUBSTAGE_VFIFO_CENTER; |
Marek Vasut | 349ea3e | 2015-07-18 03:10:31 +0200 | [diff] [blame] | 2906 | continue; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2907 | } |
Marek Vasut | f2a4bda | 2015-07-17 03:50:17 +0200 | [diff] [blame] | 2908 | |
Marek Vasut | 349ea3e | 2015-07-18 03:10:31 +0200 | [diff] [blame] | 2909 | /* All done. */ |
| 2910 | goto cal_done_ok; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2911 | } |
| 2912 | } |
| 2913 | |
Marek Vasut | f2a4bda | 2015-07-17 03:50:17 +0200 | [diff] [blame] | 2914 | /* Calibration Stage 1 failed. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2915 | set_failing_group_stage(seq, rw_group, CAL_STAGE_VFIFO, |
| 2916 | failed_substage); |
Marek Vasut | f2a4bda | 2015-07-17 03:50:17 +0200 | [diff] [blame] | 2917 | return 0; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2918 | |
Marek Vasut | f2a4bda | 2015-07-17 03:50:17 +0200 | [diff] [blame] | 2919 | /* Calibration Stage 1 completed OK. */ |
| 2920 | cal_done_ok: |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2921 | /* |
| 2922 | * Reset the delay chains back to zero if they have moved > 1 |
| 2923 | * (check for > 1 because loop will increase d even when pass in |
| 2924 | * first case). |
| 2925 | */ |
| 2926 | if (d > 2) |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2927 | scc_mgr_zero_group(seq, rw_group, 1); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2928 | |
| 2929 | return 1; |
| 2930 | } |
| 2931 | |
Marek Vasut | 2da0257 | 2015-07-18 05:58:44 +0200 | [diff] [blame] | 2932 | /** |
| 2933 | * rw_mgr_mem_calibrate_vfifo_end() - DQ/DQS Centering. |
| 2934 | * @rw_group: Read/Write Group |
| 2935 | * @test_bgn: Rank at which the test begins |
| 2936 | * |
| 2937 | * Stage 3: DQ/DQS Centering. |
| 2938 | * |
| 2939 | * This function implements UniPHY calibration Stage 3, as explained in |
| 2940 | * detail in Altera EMI_RM 2015.05.04 , "UniPHY Calibration Stages". |
| 2941 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2942 | static int rw_mgr_mem_calibrate_vfifo_end(struct socfpga_sdrseq *seq, |
| 2943 | const u32 rw_group, |
Marek Vasut | 2da0257 | 2015-07-18 05:58:44 +0200 | [diff] [blame] | 2944 | const u32 test_bgn) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2945 | { |
Marek Vasut | 2da0257 | 2015-07-18 05:58:44 +0200 | [diff] [blame] | 2946 | int ret; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2947 | |
Marek Vasut | 2da0257 | 2015-07-18 05:58:44 +0200 | [diff] [blame] | 2948 | debug("%s:%d %u %u", __func__, __LINE__, rw_group, test_bgn); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2949 | |
Marek Vasut | 2da0257 | 2015-07-18 05:58:44 +0200 | [diff] [blame] | 2950 | /* Update info for sims. */ |
| 2951 | reg_file_set_group(rw_group); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2952 | reg_file_set_stage(CAL_STAGE_VFIFO_AFTER_WRITES); |
| 2953 | reg_file_set_sub_stage(CAL_SUBSTAGE_VFIFO_CENTER); |
| 2954 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2955 | ret = rw_mgr_mem_calibrate_dq_dqs_centering(seq, rw_group, test_bgn, 0, |
| 2956 | 1); |
Marek Vasut | 2da0257 | 2015-07-18 05:58:44 +0200 | [diff] [blame] | 2957 | if (ret) |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2958 | set_failing_group_stage(seq, rw_group, |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2959 | CAL_STAGE_VFIFO_AFTER_WRITES, |
| 2960 | CAL_SUBSTAGE_VFIFO_CENTER); |
Marek Vasut | 2da0257 | 2015-07-18 05:58:44 +0200 | [diff] [blame] | 2961 | return ret; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2962 | } |
| 2963 | |
Marek Vasut | a358127 | 2015-07-21 06:18:57 +0200 | [diff] [blame] | 2964 | /** |
| 2965 | * rw_mgr_mem_calibrate_lfifo() - Minimize latency |
| 2966 | * |
| 2967 | * Stage 4: Minimize latency. |
| 2968 | * |
| 2969 | * This function implements UniPHY calibration Stage 4, as explained in |
| 2970 | * detail in Altera EMI_RM 2015.05.04 , "UniPHY Calibration Stages". |
| 2971 | * Calibrate LFIFO to find smallest read latency. |
| 2972 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2973 | static u32 rw_mgr_mem_calibrate_lfifo(struct socfpga_sdrseq *seq) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2974 | { |
Marek Vasut | a358127 | 2015-07-21 06:18:57 +0200 | [diff] [blame] | 2975 | int found_one = 0; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2976 | |
| 2977 | debug("%s:%d\n", __func__, __LINE__); |
| 2978 | |
Marek Vasut | a358127 | 2015-07-21 06:18:57 +0200 | [diff] [blame] | 2979 | /* Update info for sims. */ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2980 | reg_file_set_stage(CAL_STAGE_LFIFO); |
| 2981 | reg_file_set_sub_stage(CAL_SUBSTAGE_READ_LATENCY); |
| 2982 | |
| 2983 | /* Load up the patterns used by read calibration for all ranks */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2984 | rw_mgr_mem_calibrate_read_load_patterns(seq, 0, 1); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2985 | |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2986 | do { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2987 | writel(seq->gbl.curr_read_lat, &phy_mgr_cfg->phy_rlat); |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 2988 | debug_cond(DLEVEL >= 2, "%s:%d lfifo: read_lat=%u", |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2989 | __func__, __LINE__, seq->gbl.curr_read_lat); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2990 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 2991 | if (!rw_mgr_mem_calibrate_read_test_all_ranks(seq, 0, |
| 2992 | NUM_READ_TESTS, |
Marek Vasut | a358127 | 2015-07-21 06:18:57 +0200 | [diff] [blame] | 2993 | PASS_ALL_BITS, 1)) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2994 | break; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 2995 | |
| 2996 | found_one = 1; |
Marek Vasut | a358127 | 2015-07-21 06:18:57 +0200 | [diff] [blame] | 2997 | /* |
| 2998 | * Reduce read latency and see if things are |
| 2999 | * working correctly. |
| 3000 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3001 | seq->gbl.curr_read_lat--; |
| 3002 | } while (seq->gbl.curr_read_lat > 0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3003 | |
Marek Vasut | a358127 | 2015-07-21 06:18:57 +0200 | [diff] [blame] | 3004 | /* Reset the fifos to get pointers to known state. */ |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 3005 | writel(0, &phy_mgr_cmd->fifo_reset); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3006 | |
| 3007 | if (found_one) { |
Marek Vasut | a358127 | 2015-07-21 06:18:57 +0200 | [diff] [blame] | 3008 | /* Add a fudge factor to the read latency that was determined */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3009 | seq->gbl.curr_read_lat += 2; |
| 3010 | writel(seq->gbl.curr_read_lat, &phy_mgr_cfg->phy_rlat); |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 3011 | debug_cond(DLEVEL >= 2, |
Marek Vasut | a358127 | 2015-07-21 06:18:57 +0200 | [diff] [blame] | 3012 | "%s:%d lfifo: success: using read_lat=%u\n", |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3013 | __func__, __LINE__, seq->gbl.curr_read_lat); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3014 | } else { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3015 | set_failing_group_stage(seq, 0xff, CAL_STAGE_LFIFO, |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3016 | CAL_SUBSTAGE_READ_LATENCY); |
| 3017 | |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 3018 | debug_cond(DLEVEL >= 2, |
Marek Vasut | a358127 | 2015-07-21 06:18:57 +0200 | [diff] [blame] | 3019 | "%s:%d lfifo: failed at initial read_lat=%u\n", |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3020 | __func__, __LINE__, seq->gbl.curr_read_lat); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3021 | } |
Marek Vasut | a358127 | 2015-07-21 06:18:57 +0200 | [diff] [blame] | 3022 | |
| 3023 | return found_one; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3024 | } |
| 3025 | |
Marek Vasut | 4e79b0a | 2015-07-21 05:26:58 +0200 | [diff] [blame] | 3026 | /** |
| 3027 | * search_window() - Search for the/part of the window with DM/DQS shift |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3028 | * @search_dm: If 1, search for the DM shift, if 0, search for DQS |
| 3029 | * shift |
Marek Vasut | 4e79b0a | 2015-07-21 05:26:58 +0200 | [diff] [blame] | 3030 | * @rank_bgn: Rank number |
| 3031 | * @write_group: Write Group |
| 3032 | * @bgn_curr: Current window begin |
| 3033 | * @end_curr: Current window end |
| 3034 | * @bgn_best: Current best window begin |
| 3035 | * @end_best: Current best window end |
| 3036 | * @win_best: Size of the best window |
| 3037 | * @new_dqs: New DQS value (only applicable if search_dm = 0). |
| 3038 | * |
| 3039 | * Search for the/part of the window with DM/DQS shift. |
| 3040 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3041 | static void search_window(struct socfpga_sdrseq *seq, |
| 3042 | const int search_dm, const u32 rank_bgn, |
| 3043 | const u32 write_group, int *bgn_curr, int *end_curr, |
| 3044 | int *bgn_best, int *end_best, int *win_best, |
| 3045 | int new_dqs) |
Marek Vasut | 4e79b0a | 2015-07-21 05:26:58 +0200 | [diff] [blame] | 3046 | { |
| 3047 | u32 bit_chk; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3048 | const int max = seq->iocfg->io_out1_delay_max - new_dqs; |
Marek Vasut | 4e79b0a | 2015-07-21 05:26:58 +0200 | [diff] [blame] | 3049 | int d, di; |
| 3050 | |
| 3051 | /* Search for the/part of the window with DM/DQS shift. */ |
| 3052 | for (di = max; di >= 0; di -= DELTA_D) { |
| 3053 | if (search_dm) { |
| 3054 | d = di; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3055 | scc_mgr_apply_group_dm_out1_delay(seq, d); |
Marek Vasut | 4e79b0a | 2015-07-21 05:26:58 +0200 | [diff] [blame] | 3056 | } else { |
| 3057 | /* For DQS, we go from 0...max */ |
| 3058 | d = max - di; |
| 3059 | /* |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 3060 | * Note: This only shifts DQS, so are we limiting |
| 3061 | * ourselves to width of DQ unnecessarily. |
Marek Vasut | 4e79b0a | 2015-07-21 05:26:58 +0200 | [diff] [blame] | 3062 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3063 | scc_mgr_apply_group_dqs_io_and_oct_out1(seq, |
| 3064 | write_group, |
Marek Vasut | 4e79b0a | 2015-07-21 05:26:58 +0200 | [diff] [blame] | 3065 | d + new_dqs); |
| 3066 | } |
| 3067 | |
| 3068 | writel(0, &sdr_scc_mgr->update); |
| 3069 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3070 | if (rw_mgr_mem_calibrate_write_test(seq, rank_bgn, write_group, |
| 3071 | 1, PASS_ALL_BITS, &bit_chk, |
Marek Vasut | 4e79b0a | 2015-07-21 05:26:58 +0200 | [diff] [blame] | 3072 | 0)) { |
| 3073 | /* Set current end of the window. */ |
| 3074 | *end_curr = search_dm ? -d : d; |
| 3075 | |
| 3076 | /* |
| 3077 | * If a starting edge of our window has not been seen |
| 3078 | * this is our current start of the DM window. |
| 3079 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3080 | if (*bgn_curr == seq->iocfg->io_out1_delay_max + 1) |
Marek Vasut | 4e79b0a | 2015-07-21 05:26:58 +0200 | [diff] [blame] | 3081 | *bgn_curr = search_dm ? -d : d; |
| 3082 | |
| 3083 | /* |
| 3084 | * If current window is bigger than best seen. |
| 3085 | * Set best seen to be current window. |
| 3086 | */ |
| 3087 | if ((*end_curr - *bgn_curr + 1) > *win_best) { |
| 3088 | *win_best = *end_curr - *bgn_curr + 1; |
| 3089 | *bgn_best = *bgn_curr; |
| 3090 | *end_best = *end_curr; |
| 3091 | } |
| 3092 | } else { |
| 3093 | /* We just saw a failing test. Reset temp edge. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3094 | *bgn_curr = seq->iocfg->io_out1_delay_max + 1; |
| 3095 | *end_curr = seq->iocfg->io_out1_delay_max + 1; |
Marek Vasut | 4e79b0a | 2015-07-21 05:26:58 +0200 | [diff] [blame] | 3096 | |
| 3097 | /* Early exit is only applicable to DQS. */ |
| 3098 | if (search_dm) |
| 3099 | continue; |
| 3100 | |
| 3101 | /* |
| 3102 | * Early exit optimization: if the remaining delay |
| 3103 | * chain space is less than already seen largest |
| 3104 | * window we can exit. |
| 3105 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3106 | if (*win_best - 1 > seq->iocfg->io_out1_delay_max |
| 3107 | - new_dqs - d) |
Marek Vasut | 4e79b0a | 2015-07-21 05:26:58 +0200 | [diff] [blame] | 3108 | break; |
| 3109 | } |
| 3110 | } |
| 3111 | } |
| 3112 | |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3113 | /* |
Marek Vasut | 2595b24 | 2015-07-21 05:33:49 +0200 | [diff] [blame] | 3114 | * rw_mgr_mem_calibrate_writes_center() - Center all windows |
| 3115 | * @rank_bgn: Rank number |
| 3116 | * @write_group: Write group |
| 3117 | * @test_bgn: Rank at which the test begins |
| 3118 | * |
| 3119 | * Center all windows. Do per-bit-deskew to possibly increase size of |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3120 | * certain windows. |
| 3121 | */ |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3122 | static int |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3123 | rw_mgr_mem_calibrate_writes_center(struct socfpga_sdrseq *seq, |
| 3124 | const u32 rank_bgn, const u32 write_group, |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3125 | const u32 test_bgn) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3126 | { |
Marek Vasut | 4e79b0a | 2015-07-21 05:26:58 +0200 | [diff] [blame] | 3127 | int i; |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3128 | u32 sticky_bit_chk; |
| 3129 | u32 min_index; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3130 | int left_edge[seq->rwcfg->mem_dq_per_write_dqs]; |
| 3131 | int right_edge[seq->rwcfg->mem_dq_per_write_dqs]; |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3132 | int mid; |
| 3133 | int mid_min, orig_mid_min; |
| 3134 | int new_dqs, start_dqs; |
| 3135 | int dq_margin, dqs_margin, dm_margin; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3136 | int bgn_curr = seq->iocfg->io_out1_delay_max + 1; |
| 3137 | int end_curr = seq->iocfg->io_out1_delay_max + 1; |
| 3138 | int bgn_best = seq->iocfg->io_out1_delay_max + 1; |
| 3139 | int end_best = seq->iocfg->io_out1_delay_max + 1; |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3140 | int win_best = 0; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3141 | |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 3142 | int ret; |
| 3143 | |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3144 | debug("%s:%d %u %u", __func__, __LINE__, write_group, test_bgn); |
| 3145 | |
| 3146 | dm_margin = 0; |
| 3147 | |
Marek Vasut | 1bb221e | 2015-07-21 05:29:05 +0200 | [diff] [blame] | 3148 | start_dqs = readl((SDR_PHYGRP_SCCGRP_ADDRESS | |
| 3149 | SCC_MGR_IO_OUT1_DELAY_OFFSET) + |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3150 | (seq->rwcfg->mem_dq_per_write_dqs << 2)); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3151 | |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3152 | /* Per-bit deskew. */ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3153 | |
| 3154 | /* |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3155 | * Set the left and right edge of each bit to an illegal value. |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3156 | * Use (seq->iocfg->io_out1_delay_max + 1) as an illegal value. |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3157 | */ |
| 3158 | sticky_bit_chk = 0; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3159 | for (i = 0; i < seq->rwcfg->mem_dq_per_write_dqs; i++) { |
| 3160 | left_edge[i] = seq->iocfg->io_out1_delay_max + 1; |
| 3161 | right_edge[i] = seq->iocfg->io_out1_delay_max + 1; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3162 | } |
| 3163 | |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3164 | /* Search for the left edge of the window for each bit. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3165 | search_left_edge(seq, 1, rank_bgn, write_group, 0, test_bgn, |
Marek Vasut | b69c247 | 2015-07-18 20:34:00 +0200 | [diff] [blame] | 3166 | &sticky_bit_chk, |
Marek Vasut | e624caf | 2015-07-13 02:38:15 +0200 | [diff] [blame] | 3167 | left_edge, right_edge, 0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3168 | |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3169 | /* Search for the right edge of the window for each bit. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3170 | ret = search_right_edge(seq, 1, rank_bgn, write_group, 0, |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 3171 | start_dqs, 0, |
Marek Vasut | b69c247 | 2015-07-18 20:34:00 +0200 | [diff] [blame] | 3172 | &sticky_bit_chk, |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 3173 | left_edge, right_edge, 0); |
| 3174 | if (ret) { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3175 | set_failing_group_stage(seq, test_bgn + ret - 1, |
| 3176 | CAL_STAGE_WRITES, |
Marek Vasut | b20a506 | 2015-07-13 02:11:02 +0200 | [diff] [blame] | 3177 | CAL_SUBSTAGE_WRITES_CENTER); |
Marek Vasut | fc2ec8f | 2015-07-21 05:32:49 +0200 | [diff] [blame] | 3178 | return -EINVAL; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3179 | } |
| 3180 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3181 | min_index = get_window_mid_index(seq, 1, left_edge, right_edge, |
| 3182 | &mid_min); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3183 | |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3184 | /* Determine the amount we can change DQS (which is -mid_min). */ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3185 | orig_mid_min = mid_min; |
| 3186 | new_dqs = start_dqs; |
| 3187 | mid_min = 0; |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 3188 | debug_cond(DLEVEL >= 1, |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3189 | "%s:%d write_center: start_dqs=%d new_dqs=%d mid_min=%d\n", |
| 3190 | __func__, __LINE__, start_dqs, new_dqs, mid_min); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3191 | |
Marek Vasut | 89feb50 | 2015-07-18 19:46:26 +0200 | [diff] [blame] | 3192 | /* Add delay to bring centre of all DQ windows to the same "level". */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3193 | center_dq_windows(seq, 1, left_edge, right_edge, mid_min, orig_mid_min, |
Marek Vasut | 89feb50 | 2015-07-18 19:46:26 +0200 | [diff] [blame] | 3194 | min_index, 0, &dq_margin, &dqs_margin); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3195 | |
| 3196 | /* Move DQS */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3197 | scc_mgr_apply_group_dqs_io_and_oct_out1(seq, write_group, new_dqs); |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 3198 | writel(0, &sdr_scc_mgr->update); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3199 | |
| 3200 | /* Centre DM */ |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 3201 | debug_cond(DLEVEL >= 2, "%s:%d write_center: DM\n", __func__, __LINE__); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3202 | |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3203 | /* Search for the/part of the window with DM shift. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3204 | search_window(seq, 1, rank_bgn, write_group, &bgn_curr, &end_curr, |
Marek Vasut | 4e79b0a | 2015-07-21 05:26:58 +0200 | [diff] [blame] | 3205 | &bgn_best, &end_best, &win_best, 0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3206 | |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3207 | /* Reset DM delay chains to 0. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3208 | scc_mgr_apply_group_dm_out1_delay(seq, 0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3209 | |
| 3210 | /* |
| 3211 | * Check to see if the current window nudges up aganist 0 delay. |
| 3212 | * If so we need to continue the search by shifting DQS otherwise DQS |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3213 | * search begins as a new search. |
| 3214 | */ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3215 | if (end_curr != 0) { |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3216 | bgn_curr = seq->iocfg->io_out1_delay_max + 1; |
| 3217 | end_curr = seq->iocfg->io_out1_delay_max + 1; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3218 | } |
| 3219 | |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3220 | /* Search for the/part of the window with DQS shifts. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3221 | search_window(seq, 0, rank_bgn, write_group, &bgn_curr, &end_curr, |
Marek Vasut | 4e79b0a | 2015-07-21 05:26:58 +0200 | [diff] [blame] | 3222 | &bgn_best, &end_best, &win_best, new_dqs); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3223 | |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3224 | /* Assign left and right edge for cal and reporting. */ |
| 3225 | left_edge[0] = -1 * bgn_best; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3226 | right_edge[0] = end_best; |
| 3227 | |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 3228 | debug_cond(DLEVEL >= 2, "%s:%d dm_calib: left=%d right=%d\n", |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3229 | __func__, __LINE__, left_edge[0], right_edge[0]); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3230 | |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3231 | /* Move DQS (back to orig). */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3232 | scc_mgr_apply_group_dqs_io_and_oct_out1(seq, write_group, new_dqs); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3233 | |
| 3234 | /* Move DM */ |
| 3235 | |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3236 | /* Find middle of window for the DM bit. */ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3237 | mid = (left_edge[0] - right_edge[0]) / 2; |
| 3238 | |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3239 | /* Only move right, since we are not moving DQS/DQ. */ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3240 | if (mid < 0) |
| 3241 | mid = 0; |
| 3242 | |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3243 | /* dm_marign should fail if we never find a window. */ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3244 | if (win_best == 0) |
| 3245 | dm_margin = -1; |
| 3246 | else |
| 3247 | dm_margin = left_edge[0] - mid; |
| 3248 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3249 | scc_mgr_apply_group_dm_out1_delay(seq, mid); |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 3250 | writel(0, &sdr_scc_mgr->update); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3251 | |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 3252 | debug_cond(DLEVEL >= 2, |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3253 | "%s:%d dm_calib: left=%d right=%d mid=%d dm_margin=%d\n", |
| 3254 | __func__, __LINE__, left_edge[0], right_edge[0], |
| 3255 | mid, dm_margin); |
| 3256 | /* Export values. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3257 | seq->gbl.fom_out += dq_margin + dqs_margin; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3258 | |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 3259 | debug_cond(DLEVEL >= 2, |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3260 | "%s:%d write_center: dq_margin=%d dqs_margin=%d dm_margin=%d\n", |
| 3261 | __func__, __LINE__, dq_margin, dqs_margin, dm_margin); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3262 | |
| 3263 | /* |
| 3264 | * Do not remove this line as it makes sure all of our |
| 3265 | * decisions have been applied. |
| 3266 | */ |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 3267 | writel(0, &sdr_scc_mgr->update); |
Marek Vasut | affbc89 | 2015-07-21 05:00:42 +0200 | [diff] [blame] | 3268 | |
Marek Vasut | fc2ec8f | 2015-07-21 05:32:49 +0200 | [diff] [blame] | 3269 | if ((dq_margin < 0) || (dqs_margin < 0) || (dm_margin < 0)) |
| 3270 | return -EINVAL; |
| 3271 | |
| 3272 | return 0; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3273 | } |
| 3274 | |
Marek Vasut | 4a78cc7 | 2015-07-18 07:23:25 +0200 | [diff] [blame] | 3275 | /** |
| 3276 | * rw_mgr_mem_calibrate_writes() - Write Calibration Part One |
| 3277 | * @rank_bgn: Rank number |
| 3278 | * @group: Read/Write Group |
| 3279 | * @test_bgn: Rank at which the test begins |
| 3280 | * |
| 3281 | * Stage 2: Write Calibration Part One. |
| 3282 | * |
| 3283 | * This function implements UniPHY calibration Stage 2, as explained in |
| 3284 | * detail in Altera EMI_RM 2015.05.04 , "UniPHY Calibration Stages". |
| 3285 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3286 | static int rw_mgr_mem_calibrate_writes(struct socfpga_sdrseq *seq, |
| 3287 | const u32 rank_bgn, const u32 group, |
Marek Vasut | 4a78cc7 | 2015-07-18 07:23:25 +0200 | [diff] [blame] | 3288 | const u32 test_bgn) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3289 | { |
Marek Vasut | 4a78cc7 | 2015-07-18 07:23:25 +0200 | [diff] [blame] | 3290 | int ret; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3291 | |
Marek Vasut | 4a78cc7 | 2015-07-18 07:23:25 +0200 | [diff] [blame] | 3292 | /* Update info for sims */ |
| 3293 | debug("%s:%d %u %u\n", __func__, __LINE__, group, test_bgn); |
| 3294 | |
| 3295 | reg_file_set_group(group); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3296 | reg_file_set_stage(CAL_STAGE_WRITES); |
| 3297 | reg_file_set_sub_stage(CAL_SUBSTAGE_WRITES_CENTER); |
| 3298 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3299 | ret = rw_mgr_mem_calibrate_writes_center(seq, rank_bgn, group, |
| 3300 | test_bgn); |
Marek Vasut | fc2ec8f | 2015-07-21 05:32:49 +0200 | [diff] [blame] | 3301 | if (ret) |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3302 | set_failing_group_stage(seq, group, CAL_STAGE_WRITES, |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3303 | CAL_SUBSTAGE_WRITES_CENTER); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3304 | |
Marek Vasut | fc2ec8f | 2015-07-21 05:32:49 +0200 | [diff] [blame] | 3305 | return ret; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3306 | } |
| 3307 | |
Marek Vasut | be333bc | 2015-07-20 07:33:33 +0200 | [diff] [blame] | 3308 | /** |
| 3309 | * mem_precharge_and_activate() - Precharge all banks and activate |
| 3310 | * |
| 3311 | * Precharge all banks and activate row 0 in bank "000..." and bank "111...". |
| 3312 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3313 | static void mem_precharge_and_activate(struct socfpga_sdrseq *seq) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3314 | { |
Marek Vasut | be333bc | 2015-07-20 07:33:33 +0200 | [diff] [blame] | 3315 | int r; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3316 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3317 | for (r = 0; r < seq->rwcfg->mem_number_of_ranks; r++) { |
Marek Vasut | be333bc | 2015-07-20 07:33:33 +0200 | [diff] [blame] | 3318 | /* Set rank. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3319 | set_rank_and_odt_mask(seq, r, RW_MGR_ODT_MODE_OFF); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3320 | |
Marek Vasut | be333bc | 2015-07-20 07:33:33 +0200 | [diff] [blame] | 3321 | /* Precharge all banks. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3322 | writel(seq->rwcfg->precharge_all, SDR_PHYGRP_RWMGRGRP_ADDRESS | |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 3323 | RW_MGR_RUN_SINGLE_GROUP_OFFSET); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3324 | |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 3325 | writel(0x0F, &sdr_rw_load_mgr_regs->load_cntr0); |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3326 | writel(seq->rwcfg->activate_0_and_1_wait1, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 3327 | &sdr_rw_load_jump_mgr_regs->load_jump_add0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3328 | |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 3329 | writel(0x0F, &sdr_rw_load_mgr_regs->load_cntr1); |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3330 | writel(seq->rwcfg->activate_0_and_1_wait2, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 3331 | &sdr_rw_load_jump_mgr_regs->load_jump_add1); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3332 | |
Marek Vasut | be333bc | 2015-07-20 07:33:33 +0200 | [diff] [blame] | 3333 | /* Activate rows. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3334 | writel(seq->rwcfg->activate_0_and_1, |
| 3335 | SDR_PHYGRP_RWMGRGRP_ADDRESS | |
| 3336 | RW_MGR_RUN_SINGLE_GROUP_OFFSET); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3337 | } |
| 3338 | } |
| 3339 | |
Marek Vasut | 0f0840d | 2015-07-17 01:57:41 +0200 | [diff] [blame] | 3340 | /** |
| 3341 | * mem_init_latency() - Configure memory RLAT and WLAT settings |
| 3342 | * |
| 3343 | * Configure memory RLAT and WLAT parameters. |
| 3344 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3345 | static void mem_init_latency(struct socfpga_sdrseq *seq) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3346 | { |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3347 | /* |
Marek Vasut | 0f0840d | 2015-07-17 01:57:41 +0200 | [diff] [blame] | 3348 | * For AV/CV, LFIFO is hardened and always runs at full rate |
| 3349 | * so max latency in AFI clocks, used here, is correspondingly |
| 3350 | * smaller. |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3351 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3352 | const u32 max_latency = (1 << seq->misccfg->max_latency_count_width) |
| 3353 | - 1; |
Marek Vasut | 0f0840d | 2015-07-17 01:57:41 +0200 | [diff] [blame] | 3354 | u32 rlat, wlat; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3355 | |
Marek Vasut | 0f0840d | 2015-07-17 01:57:41 +0200 | [diff] [blame] | 3356 | debug("%s:%d\n", __func__, __LINE__); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3357 | |
| 3358 | /* |
Marek Vasut | 0f0840d | 2015-07-17 01:57:41 +0200 | [diff] [blame] | 3359 | * Read in write latency. |
| 3360 | * WL for Hard PHY does not include additive latency. |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3361 | */ |
Marek Vasut | 0f0840d | 2015-07-17 01:57:41 +0200 | [diff] [blame] | 3362 | wlat = readl(&data_mgr->t_wl_add); |
| 3363 | wlat += readl(&data_mgr->mem_t_add); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3364 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3365 | seq->gbl.rw_wl_nop_cycles = wlat - 1; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3366 | |
Marek Vasut | 0f0840d | 2015-07-17 01:57:41 +0200 | [diff] [blame] | 3367 | /* Read in readl latency. */ |
| 3368 | rlat = readl(&data_mgr->t_rl_add); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3369 | |
Marek Vasut | 0f0840d | 2015-07-17 01:57:41 +0200 | [diff] [blame] | 3370 | /* Set a pretty high read latency initially. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3371 | seq->gbl.curr_read_lat = rlat + 16; |
| 3372 | if (seq->gbl.curr_read_lat > max_latency) |
| 3373 | seq->gbl.curr_read_lat = max_latency; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3374 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3375 | writel(seq->gbl.curr_read_lat, &phy_mgr_cfg->phy_rlat); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3376 | |
Marek Vasut | 0f0840d | 2015-07-17 01:57:41 +0200 | [diff] [blame] | 3377 | /* Advertise write latency. */ |
| 3378 | writel(wlat, &phy_mgr_cfg->afi_wlat); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3379 | } |
| 3380 | |
Marek Vasut | 60daef8 | 2015-07-26 10:54:15 +0200 | [diff] [blame] | 3381 | /** |
| 3382 | * @mem_skip_calibrate() - Set VFIFO and LFIFO to instant-on settings |
| 3383 | * |
| 3384 | * Set VFIFO and LFIFO to instant-on settings in skip calibration mode. |
| 3385 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3386 | static void mem_skip_calibrate(struct socfpga_sdrseq *seq) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3387 | { |
Marek Vasut | 8af9ca0 | 2015-08-02 19:42:26 +0200 | [diff] [blame] | 3388 | u32 vfifo_offset; |
| 3389 | u32 i, j, r; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3390 | |
| 3391 | debug("%s:%d\n", __func__, __LINE__); |
| 3392 | /* Need to update every shadow register set used by the interface */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3393 | for (r = 0; r < seq->rwcfg->mem_number_of_ranks; |
Marek Vasut | 60daef8 | 2015-07-26 10:54:15 +0200 | [diff] [blame] | 3394 | r += NUM_RANKS_PER_SHADOW_REG) { |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3395 | /* |
| 3396 | * Set output phase alignment settings appropriate for |
| 3397 | * skip calibration. |
| 3398 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3399 | for (i = 0; i < seq->rwcfg->mem_if_read_dqs_width; i++) { |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3400 | scc_mgr_set_dqs_en_phase(i, 0); |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3401 | if (seq->iocfg->dll_chain_length == 6) |
Marek Vasut | 7e8f8a7 | 2015-08-02 19:10:58 +0200 | [diff] [blame] | 3402 | scc_mgr_set_dqdqs_output_phase(i, 6); |
| 3403 | else |
| 3404 | scc_mgr_set_dqdqs_output_phase(i, 7); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3405 | /* |
| 3406 | * Case:33398 |
| 3407 | * |
| 3408 | * Write data arrives to the I/O two cycles before write |
| 3409 | * latency is reached (720 deg). |
| 3410 | * -> due to bit-slip in a/c bus |
| 3411 | * -> to allow board skew where dqs is longer than ck |
| 3412 | * -> how often can this happen!? |
| 3413 | * -> can claim back some ptaps for high freq |
| 3414 | * support if we can relax this, but i digress... |
| 3415 | * |
| 3416 | * The write_clk leads mem_ck by 90 deg |
| 3417 | * The minimum ptap of the OPA is 180 deg |
| 3418 | * Each ptap has (360 / IO_DLL_CHAIN_LENGH) deg of delay |
| 3419 | * The write_clk is always delayed by 2 ptaps |
| 3420 | * |
| 3421 | * Hence, to make DQS aligned to CK, we need to delay |
| 3422 | * DQS by: |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 3423 | * (720 - 90 - 180 - 2) * |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3424 | * (360 / seq->iocfg->dll_chain_length) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3425 | * |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3426 | * Dividing the above by |
| 3427 | (360 / seq->iocfg->dll_chain_length) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3428 | * gives us the number of ptaps, which simplies to: |
| 3429 | * |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3430 | * (1.25 * seq->iocfg->dll_chain_length - 2) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3431 | */ |
Marek Vasut | 60daef8 | 2015-07-26 10:54:15 +0200 | [diff] [blame] | 3432 | scc_mgr_set_dqdqs_output_phase(i, |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3433 | ((125 * seq->iocfg->dll_chain_length) |
| 3434 | / 100) - 2); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3435 | } |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 3436 | writel(0xff, &sdr_scc_mgr->dqs_ena); |
| 3437 | writel(0xff, &sdr_scc_mgr->dqs_io_ena); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3438 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3439 | for (i = 0; i < seq->rwcfg->mem_if_write_dqs_width; i++) { |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 3440 | writel(i, SDR_PHYGRP_SCCGRP_ADDRESS | |
| 3441 | SCC_MGR_GROUP_COUNTER_OFFSET); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3442 | } |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 3443 | writel(0xff, &sdr_scc_mgr->dq_ena); |
| 3444 | writel(0xff, &sdr_scc_mgr->dm_ena); |
| 3445 | writel(0, &sdr_scc_mgr->update); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3446 | } |
| 3447 | |
| 3448 | /* Compensate for simulation model behaviour */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3449 | for (i = 0; i < seq->rwcfg->mem_if_read_dqs_width; i++) { |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3450 | scc_mgr_set_dqs_bus_in_delay(i, 10); |
| 3451 | scc_mgr_load_dqs(i); |
| 3452 | } |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 3453 | writel(0, &sdr_scc_mgr->update); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3454 | |
| 3455 | /* |
| 3456 | * ArriaV has hard FIFOs that can only be initialized by incrementing |
| 3457 | * in sequencer. |
| 3458 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3459 | vfifo_offset = seq->misccfg->calib_vfifo_offset; |
Marek Vasut | 60daef8 | 2015-07-26 10:54:15 +0200 | [diff] [blame] | 3460 | for (j = 0; j < vfifo_offset; j++) |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 3461 | writel(0xff, &phy_mgr_cmd->inc_vfifo_hard_phy); |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 3462 | writel(0, &phy_mgr_cmd->fifo_reset); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3463 | |
| 3464 | /* |
Marek Vasut | 60daef8 | 2015-07-26 10:54:15 +0200 | [diff] [blame] | 3465 | * For Arria V and Cyclone V with hard LFIFO, we get the skip-cal |
| 3466 | * setting from generation-time constant. |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3467 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3468 | seq->gbl.curr_read_lat = seq->misccfg->calib_lfifo_offset; |
| 3469 | writel(seq->gbl.curr_read_lat, &phy_mgr_cfg->phy_rlat); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3470 | } |
| 3471 | |
Marek Vasut | d9fcf9a | 2015-07-20 04:34:51 +0200 | [diff] [blame] | 3472 | /** |
| 3473 | * mem_calibrate() - Memory calibration entry point. |
| 3474 | * |
| 3475 | * Perform memory calibration. |
| 3476 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3477 | static u32 mem_calibrate(struct socfpga_sdrseq *seq) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3478 | { |
Marek Vasut | 8af9ca0 | 2015-08-02 19:42:26 +0200 | [diff] [blame] | 3479 | u32 i; |
| 3480 | u32 rank_bgn, sr; |
| 3481 | u32 write_group, write_test_bgn; |
| 3482 | u32 read_group, read_test_bgn; |
| 3483 | u32 run_groups, current_run; |
| 3484 | u32 failing_groups = 0; |
| 3485 | u32 group_failed = 0; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3486 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3487 | const u32 rwdqs_ratio = seq->rwcfg->mem_if_read_dqs_width / |
| 3488 | seq->rwcfg->mem_if_write_dqs_width; |
Marek Vasut | d6f2879 | 2015-07-17 02:21:47 +0200 | [diff] [blame] | 3489 | |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3490 | debug("%s:%d\n", __func__, __LINE__); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3491 | |
Marek Vasut | 0f0840d | 2015-07-17 01:57:41 +0200 | [diff] [blame] | 3492 | /* Initialize the data settings */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3493 | seq->gbl.error_substage = CAL_SUBSTAGE_NIL; |
| 3494 | seq->gbl.error_stage = CAL_STAGE_NIL; |
| 3495 | seq->gbl.error_group = 0xff; |
| 3496 | seq->gbl.fom_in = 0; |
| 3497 | seq->gbl.fom_out = 0; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3498 | |
Marek Vasut | 0f0840d | 2015-07-17 01:57:41 +0200 | [diff] [blame] | 3499 | /* Initialize WLAT and RLAT. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3500 | mem_init_latency(seq); |
Marek Vasut | 0f0840d | 2015-07-17 01:57:41 +0200 | [diff] [blame] | 3501 | |
| 3502 | /* Initialize bit slips. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3503 | mem_precharge_and_activate(seq); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3504 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3505 | for (i = 0; i < seq->rwcfg->mem_if_read_dqs_width; i++) { |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 3506 | writel(i, SDR_PHYGRP_SCCGRP_ADDRESS | |
| 3507 | SCC_MGR_GROUP_COUNTER_OFFSET); |
Marek Vasut | d4d3de2 | 2015-07-19 01:34:43 +0200 | [diff] [blame] | 3508 | /* Only needed once to set all groups, pins, DQ, DQS, DM. */ |
| 3509 | if (i == 0) |
| 3510 | scc_mgr_set_hhp_extras(); |
| 3511 | |
Marek Vasut | 0341de4 | 2015-07-17 02:06:20 +0200 | [diff] [blame] | 3512 | scc_set_bypass_mode(i); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3513 | } |
| 3514 | |
Marek Vasut | b984ee8 | 2015-07-17 02:07:12 +0200 | [diff] [blame] | 3515 | /* Calibration is skipped. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3516 | if ((seq->dyn_calib_steps & CALIB_SKIP_ALL) == CALIB_SKIP_ALL) { |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3517 | /* |
| 3518 | * Set VFIFO and LFIFO to instant-on settings in skip |
| 3519 | * calibration mode. |
| 3520 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3521 | mem_skip_calibrate(seq); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3522 | |
Marek Vasut | b984ee8 | 2015-07-17 02:07:12 +0200 | [diff] [blame] | 3523 | /* |
| 3524 | * Do not remove this line as it makes sure all of our |
| 3525 | * decisions have been applied. |
| 3526 | */ |
| 3527 | writel(0, &sdr_scc_mgr->update); |
| 3528 | return 1; |
| 3529 | } |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3530 | |
Marek Vasut | b984ee8 | 2015-07-17 02:07:12 +0200 | [diff] [blame] | 3531 | /* Calibration is not skipped. */ |
| 3532 | for (i = 0; i < NUM_CALIB_REPEAT; i++) { |
| 3533 | /* |
| 3534 | * Zero all delay chain/phase settings for all |
| 3535 | * groups and all shadow register sets. |
| 3536 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3537 | scc_mgr_zero_all(seq); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3538 | |
Marek Vasut | eb98b38 | 2015-08-02 18:27:21 +0200 | [diff] [blame] | 3539 | run_groups = ~0; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3540 | |
Marek Vasut | b984ee8 | 2015-07-17 02:07:12 +0200 | [diff] [blame] | 3541 | for (write_group = 0, write_test_bgn = 0; write_group |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3542 | < seq->rwcfg->mem_if_write_dqs_width; write_group++, |
| 3543 | write_test_bgn += seq->rwcfg->mem_dq_per_write_dqs) { |
Marek Vasut | 0568f22 | 2015-07-17 02:50:56 +0200 | [diff] [blame] | 3544 | /* Initialize the group failure */ |
Marek Vasut | b984ee8 | 2015-07-17 02:07:12 +0200 | [diff] [blame] | 3545 | group_failed = 0; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3546 | |
Marek Vasut | b984ee8 | 2015-07-17 02:07:12 +0200 | [diff] [blame] | 3547 | current_run = run_groups & ((1 << |
| 3548 | RW_MGR_NUM_DQS_PER_WRITE_GROUP) - 1); |
| 3549 | run_groups = run_groups >> |
| 3550 | RW_MGR_NUM_DQS_PER_WRITE_GROUP; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3551 | |
Marek Vasut | b984ee8 | 2015-07-17 02:07:12 +0200 | [diff] [blame] | 3552 | if (current_run == 0) |
| 3553 | continue; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3554 | |
Marek Vasut | b984ee8 | 2015-07-17 02:07:12 +0200 | [diff] [blame] | 3555 | writel(write_group, SDR_PHYGRP_SCCGRP_ADDRESS | |
| 3556 | SCC_MGR_GROUP_COUNTER_OFFSET); |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3557 | scc_mgr_zero_group(seq, write_group, 0); |
Marek Vasut | b984ee8 | 2015-07-17 02:07:12 +0200 | [diff] [blame] | 3558 | |
Marek Vasut | d6f2879 | 2015-07-17 02:21:47 +0200 | [diff] [blame] | 3559 | for (read_group = write_group * rwdqs_ratio, |
| 3560 | read_test_bgn = 0; |
Marek Vasut | 0568f22 | 2015-07-17 02:50:56 +0200 | [diff] [blame] | 3561 | read_group < (write_group + 1) * rwdqs_ratio; |
Marek Vasut | d6f2879 | 2015-07-17 02:21:47 +0200 | [diff] [blame] | 3562 | read_group++, |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3563 | read_test_bgn += seq->rwcfg->mem_dq_per_read_dqs) { |
Marek Vasut | d6f2879 | 2015-07-17 02:21:47 +0200 | [diff] [blame] | 3564 | if (STATIC_CALIB_STEPS & CALIB_SKIP_VFIFO) |
| 3565 | continue; |
| 3566 | |
Marek Vasut | b984ee8 | 2015-07-17 02:07:12 +0200 | [diff] [blame] | 3567 | /* Calibrate the VFIFO */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3568 | if (rw_mgr_mem_calibrate_vfifo(seq, read_group, |
Marek Vasut | d6f2879 | 2015-07-17 02:21:47 +0200 | [diff] [blame] | 3569 | read_test_bgn)) |
| 3570 | continue; |
Marek Vasut | b984ee8 | 2015-07-17 02:07:12 +0200 | [diff] [blame] | 3571 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3572 | if (!(seq->gbl.phy_debug_mode_flags & |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 3573 | PHY_DEBUG_SWEEP_ALL_GROUPS)) |
Marek Vasut | d6f2879 | 2015-07-17 02:21:47 +0200 | [diff] [blame] | 3574 | return 0; |
Marek Vasut | 0568f22 | 2015-07-17 02:50:56 +0200 | [diff] [blame] | 3575 | |
| 3576 | /* The group failed, we're done. */ |
| 3577 | goto grp_failed; |
Marek Vasut | b984ee8 | 2015-07-17 02:07:12 +0200 | [diff] [blame] | 3578 | } |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3579 | |
Marek Vasut | b984ee8 | 2015-07-17 02:07:12 +0200 | [diff] [blame] | 3580 | /* Calibrate the output side */ |
Marek Vasut | 0568f22 | 2015-07-17 02:50:56 +0200 | [diff] [blame] | 3581 | for (rank_bgn = 0, sr = 0; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3582 | rank_bgn < seq->rwcfg->mem_number_of_ranks; |
Marek Vasut | 0568f22 | 2015-07-17 02:50:56 +0200 | [diff] [blame] | 3583 | rank_bgn += NUM_RANKS_PER_SHADOW_REG, sr++) { |
| 3584 | if (STATIC_CALIB_STEPS & CALIB_SKIP_WRITES) |
| 3585 | continue; |
Marek Vasut | f04045f | 2015-07-17 02:31:04 +0200 | [diff] [blame] | 3586 | |
Marek Vasut | 0568f22 | 2015-07-17 02:50:56 +0200 | [diff] [blame] | 3587 | /* Not needed in quick mode! */ |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 3588 | if (STATIC_CALIB_STEPS & |
| 3589 | CALIB_SKIP_DELAY_SWEEPS) |
Marek Vasut | 0568f22 | 2015-07-17 02:50:56 +0200 | [diff] [blame] | 3590 | continue; |
Marek Vasut | f04045f | 2015-07-17 02:31:04 +0200 | [diff] [blame] | 3591 | |
Marek Vasut | 0568f22 | 2015-07-17 02:50:56 +0200 | [diff] [blame] | 3592 | /* Calibrate WRITEs */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3593 | if (!rw_mgr_mem_calibrate_writes(seq, rank_bgn, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 3594 | write_group, |
| 3595 | write_test_bgn)) |
Marek Vasut | 0568f22 | 2015-07-17 02:50:56 +0200 | [diff] [blame] | 3596 | continue; |
Marek Vasut | f04045f | 2015-07-17 02:31:04 +0200 | [diff] [blame] | 3597 | |
Marek Vasut | 0568f22 | 2015-07-17 02:50:56 +0200 | [diff] [blame] | 3598 | group_failed = 1; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3599 | if (!(seq->gbl.phy_debug_mode_flags & |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 3600 | PHY_DEBUG_SWEEP_ALL_GROUPS)) |
Marek Vasut | 0568f22 | 2015-07-17 02:50:56 +0200 | [diff] [blame] | 3601 | return 0; |
Marek Vasut | b984ee8 | 2015-07-17 02:07:12 +0200 | [diff] [blame] | 3602 | } |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3603 | |
Marek Vasut | 0568f22 | 2015-07-17 02:50:56 +0200 | [diff] [blame] | 3604 | /* Some group failed, we're done. */ |
| 3605 | if (group_failed) |
| 3606 | goto grp_failed; |
Marek Vasut | 6db5573 | 2015-07-17 02:38:51 +0200 | [diff] [blame] | 3607 | |
Marek Vasut | 0568f22 | 2015-07-17 02:50:56 +0200 | [diff] [blame] | 3608 | for (read_group = write_group * rwdqs_ratio, |
| 3609 | read_test_bgn = 0; |
| 3610 | read_group < (write_group + 1) * rwdqs_ratio; |
| 3611 | read_group++, |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3612 | read_test_bgn += seq->rwcfg->mem_dq_per_read_dqs) { |
Marek Vasut | 0568f22 | 2015-07-17 02:50:56 +0200 | [diff] [blame] | 3613 | if (STATIC_CALIB_STEPS & CALIB_SKIP_WRITES) |
| 3614 | continue; |
| 3615 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3616 | if (!rw_mgr_mem_calibrate_vfifo_end(seq, |
| 3617 | read_group, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 3618 | read_test_bgn)) |
Marek Vasut | 0568f22 | 2015-07-17 02:50:56 +0200 | [diff] [blame] | 3619 | continue; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3620 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3621 | if (!(seq->gbl.phy_debug_mode_flags & |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 3622 | PHY_DEBUG_SWEEP_ALL_GROUPS)) |
Marek Vasut | 0568f22 | 2015-07-17 02:50:56 +0200 | [diff] [blame] | 3623 | return 0; |
| 3624 | |
| 3625 | /* The group failed, we're done. */ |
| 3626 | goto grp_failed; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3627 | } |
| 3628 | |
Marek Vasut | 0568f22 | 2015-07-17 02:50:56 +0200 | [diff] [blame] | 3629 | /* No group failed, continue as usual. */ |
| 3630 | continue; |
| 3631 | |
| 3632 | grp_failed: /* A group failed, increment the counter. */ |
| 3633 | failing_groups++; |
Marek Vasut | b984ee8 | 2015-07-17 02:07:12 +0200 | [diff] [blame] | 3634 | } |
| 3635 | |
| 3636 | /* |
| 3637 | * USER If there are any failing groups then report |
| 3638 | * the failure. |
| 3639 | */ |
| 3640 | if (failing_groups != 0) |
| 3641 | return 0; |
| 3642 | |
Marek Vasut | fc38d5c | 2015-07-17 02:40:21 +0200 | [diff] [blame] | 3643 | if (STATIC_CALIB_STEPS & CALIB_SKIP_LFIFO) |
| 3644 | continue; |
| 3645 | |
Marek Vasut | b984ee8 | 2015-07-17 02:07:12 +0200 | [diff] [blame] | 3646 | /* Calibrate the LFIFO */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3647 | if (!rw_mgr_mem_calibrate_lfifo(seq)) |
Marek Vasut | fc38d5c | 2015-07-17 02:40:21 +0200 | [diff] [blame] | 3648 | return 0; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3649 | } |
| 3650 | |
| 3651 | /* |
| 3652 | * Do not remove this line as it makes sure all of our decisions |
| 3653 | * have been applied. |
| 3654 | */ |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 3655 | writel(0, &sdr_scc_mgr->update); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3656 | return 1; |
| 3657 | } |
| 3658 | |
Marek Vasut | 092a1ef | 2015-07-17 01:20:21 +0200 | [diff] [blame] | 3659 | /** |
| 3660 | * run_mem_calibrate() - Perform memory calibration |
| 3661 | * |
| 3662 | * This function triggers the entire memory calibration procedure. |
| 3663 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3664 | static int run_mem_calibrate(struct socfpga_sdrseq *seq) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3665 | { |
Marek Vasut | 092a1ef | 2015-07-17 01:20:21 +0200 | [diff] [blame] | 3666 | int pass; |
Marek Vasut | 6946989 | 2016-04-05 23:41:56 +0200 | [diff] [blame] | 3667 | u32 ctrl_cfg; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3668 | |
| 3669 | debug("%s:%d\n", __func__, __LINE__); |
| 3670 | |
| 3671 | /* Reset pass/fail status shown on afi_cal_success/fail */ |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 3672 | writel(PHY_MGR_CAL_RESET, &phy_mgr_cfg->cal_status); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3673 | |
Marek Vasut | 092a1ef | 2015-07-17 01:20:21 +0200 | [diff] [blame] | 3674 | /* Stop tracking manager. */ |
Marek Vasut | 6946989 | 2016-04-05 23:41:56 +0200 | [diff] [blame] | 3675 | ctrl_cfg = readl(&sdr_ctrl->ctrl_cfg); |
| 3676 | writel(ctrl_cfg & ~SDR_CTRLGRP_CTRLCFG_DQSTRKEN_MASK, |
| 3677 | &sdr_ctrl->ctrl_cfg); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3678 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3679 | phy_mgr_initialize(seq); |
| 3680 | rw_mgr_mem_initialize(seq); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3681 | |
Marek Vasut | 092a1ef | 2015-07-17 01:20:21 +0200 | [diff] [blame] | 3682 | /* Perform the actual memory calibration. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3683 | pass = mem_calibrate(seq); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3684 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3685 | mem_precharge_and_activate(seq); |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 3686 | writel(0, &phy_mgr_cmd->fifo_reset); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3687 | |
Marek Vasut | 092a1ef | 2015-07-17 01:20:21 +0200 | [diff] [blame] | 3688 | /* Handoff. */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3689 | rw_mgr_mem_handoff(seq); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3690 | /* |
Marek Vasut | 092a1ef | 2015-07-17 01:20:21 +0200 | [diff] [blame] | 3691 | * In Hard PHY this is a 2-bit control: |
| 3692 | * 0: AFI Mux Select |
| 3693 | * 1: DDIO Mux Select |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3694 | */ |
Marek Vasut | 092a1ef | 2015-07-17 01:20:21 +0200 | [diff] [blame] | 3695 | writel(0x2, &phy_mgr_cfg->mux_sel); |
| 3696 | |
| 3697 | /* Start tracking manager. */ |
Marek Vasut | 6946989 | 2016-04-05 23:41:56 +0200 | [diff] [blame] | 3698 | writel(ctrl_cfg, &sdr_ctrl->ctrl_cfg); |
Marek Vasut | 092a1ef | 2015-07-17 01:20:21 +0200 | [diff] [blame] | 3699 | |
| 3700 | return pass; |
| 3701 | } |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3702 | |
Marek Vasut | 092a1ef | 2015-07-17 01:20:21 +0200 | [diff] [blame] | 3703 | /** |
| 3704 | * debug_mem_calibrate() - Report result of memory calibration |
| 3705 | * @pass: Value indicating whether calibration passed or failed |
| 3706 | * |
| 3707 | * This function reports the results of the memory calibration |
| 3708 | * and writes debug information into the register file. |
| 3709 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3710 | static void debug_mem_calibrate(struct socfpga_sdrseq *seq, int pass) |
Marek Vasut | 092a1ef | 2015-07-17 01:20:21 +0200 | [diff] [blame] | 3711 | { |
Marek Vasut | 8af9ca0 | 2015-08-02 19:42:26 +0200 | [diff] [blame] | 3712 | u32 debug_info; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3713 | |
| 3714 | if (pass) { |
Marek Vasut | ed6c1ab | 2021-09-14 05:20:19 +0200 | [diff] [blame] | 3715 | debug(KBUILD_BASENAME ": CALIBRATION PASSED\n"); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3716 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3717 | seq->gbl.fom_in /= 2; |
| 3718 | seq->gbl.fom_out /= 2; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3719 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3720 | if (seq->gbl.fom_in > 0xff) |
| 3721 | seq->gbl.fom_in = 0xff; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3722 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3723 | if (seq->gbl.fom_out > 0xff) |
| 3724 | seq->gbl.fom_out = 0xff; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3725 | |
| 3726 | /* Update the FOM in the register file */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3727 | debug_info = seq->gbl.fom_in; |
| 3728 | debug_info |= seq->gbl.fom_out << 8; |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 3729 | writel(debug_info, &sdr_reg_file->fom); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3730 | |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 3731 | writel(debug_info, &phy_mgr_cfg->cal_debug_info); |
| 3732 | writel(PHY_MGR_CAL_SUCCESS, &phy_mgr_cfg->cal_status); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3733 | } else { |
Marek Vasut | ed6c1ab | 2021-09-14 05:20:19 +0200 | [diff] [blame] | 3734 | debug(KBUILD_BASENAME ": CALIBRATION FAILED\n"); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3735 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3736 | debug_info = seq->gbl.error_stage; |
| 3737 | debug_info |= seq->gbl.error_substage << 8; |
| 3738 | debug_info |= seq->gbl.error_group << 16; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3739 | |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 3740 | writel(debug_info, &sdr_reg_file->failing_stage); |
| 3741 | writel(debug_info, &phy_mgr_cfg->cal_debug_info); |
| 3742 | writel(PHY_MGR_CAL_FAIL, &phy_mgr_cfg->cal_status); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3743 | |
| 3744 | /* Update the failing group/stage in the register file */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3745 | debug_info = seq->gbl.error_stage; |
| 3746 | debug_info |= seq->gbl.error_substage << 8; |
| 3747 | debug_info |= seq->gbl.error_group << 16; |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 3748 | writel(debug_info, &sdr_reg_file->failing_stage); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3749 | } |
| 3750 | |
Marek Vasut | ed6c1ab | 2021-09-14 05:20:19 +0200 | [diff] [blame] | 3751 | debug(KBUILD_BASENAME ": Calibration complete\n"); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3752 | } |
| 3753 | |
Marek Vasut | ea9771b | 2015-07-19 06:12:42 +0200 | [diff] [blame] | 3754 | /** |
| 3755 | * hc_initialize_rom_data() - Initialize ROM data |
| 3756 | * |
| 3757 | * Initialize ROM data. |
| 3758 | */ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3759 | static void hc_initialize_rom_data(void) |
| 3760 | { |
Marek Vasut | 3384e74 | 2015-08-02 17:15:19 +0200 | [diff] [blame] | 3761 | unsigned int nelem = 0; |
| 3762 | const u32 *rom_init; |
Marek Vasut | ea9771b | 2015-07-19 06:12:42 +0200 | [diff] [blame] | 3763 | u32 i, addr; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3764 | |
Marek Vasut | 3384e74 | 2015-08-02 17:15:19 +0200 | [diff] [blame] | 3765 | socfpga_get_seq_inst_init(&rom_init, &nelem); |
Marek Vasut | a334010 | 2015-07-12 19:03:33 +0200 | [diff] [blame] | 3766 | addr = SDR_PHYGRP_RWMGRGRP_ADDRESS | RW_MGR_INST_ROM_WRITE_OFFSET; |
Marek Vasut | 3384e74 | 2015-08-02 17:15:19 +0200 | [diff] [blame] | 3767 | for (i = 0; i < nelem; i++) |
| 3768 | writel(rom_init[i], addr + (i << 2)); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3769 | |
Marek Vasut | 3384e74 | 2015-08-02 17:15:19 +0200 | [diff] [blame] | 3770 | socfpga_get_seq_ac_init(&rom_init, &nelem); |
Marek Vasut | a334010 | 2015-07-12 19:03:33 +0200 | [diff] [blame] | 3771 | addr = SDR_PHYGRP_RWMGRGRP_ADDRESS | RW_MGR_AC_ROM_WRITE_OFFSET; |
Marek Vasut | 3384e74 | 2015-08-02 17:15:19 +0200 | [diff] [blame] | 3772 | for (i = 0; i < nelem; i++) |
| 3773 | writel(rom_init[i], addr + (i << 2)); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3774 | } |
| 3775 | |
Marek Vasut | a17ae0f | 2015-07-19 06:13:37 +0200 | [diff] [blame] | 3776 | /** |
| 3777 | * initialize_reg_file() - Initialize SDR register file |
| 3778 | * |
| 3779 | * Initialize SDR register file. |
| 3780 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3781 | static void initialize_reg_file(struct socfpga_sdrseq *seq) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3782 | { |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3783 | /* Initialize the register file with the correct data */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3784 | writel(seq->misccfg->reg_file_init_seq_signature, |
| 3785 | &sdr_reg_file->signature); |
Marek Vasut | b545096 | 2015-07-12 21:05:08 +0200 | [diff] [blame] | 3786 | writel(0, &sdr_reg_file->debug_data_addr); |
| 3787 | writel(0, &sdr_reg_file->cur_stage); |
| 3788 | writel(0, &sdr_reg_file->fom); |
| 3789 | writel(0, &sdr_reg_file->failing_stage); |
| 3790 | writel(0, &sdr_reg_file->debug1); |
| 3791 | writel(0, &sdr_reg_file->debug2); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3792 | } |
| 3793 | |
Marek Vasut | 0c9f3cb | 2015-07-19 06:14:04 +0200 | [diff] [blame] | 3794 | /** |
| 3795 | * initialize_hps_phy() - Initialize HPS PHY |
| 3796 | * |
| 3797 | * Initialize HPS PHY. |
| 3798 | */ |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3799 | static void initialize_hps_phy(void) |
| 3800 | { |
Marek Vasut | 8af9ca0 | 2015-08-02 19:42:26 +0200 | [diff] [blame] | 3801 | u32 reg; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3802 | /* |
| 3803 | * Tracking also gets configured here because it's in the |
| 3804 | * same register. |
| 3805 | */ |
Marek Vasut | 8af9ca0 | 2015-08-02 19:42:26 +0200 | [diff] [blame] | 3806 | u32 trk_sample_count = 7500; |
| 3807 | u32 trk_long_idle_sample_count = (10 << 16) | 100; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3808 | /* |
| 3809 | * Format is number of outer loops in the 16 MSB, sample |
| 3810 | * count in 16 LSB. |
| 3811 | */ |
| 3812 | |
| 3813 | reg = 0; |
| 3814 | reg |= SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_ACDELAYEN_SET(2); |
| 3815 | reg |= SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_DQDELAYEN_SET(1); |
| 3816 | reg |= SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_DQSDELAYEN_SET(1); |
| 3817 | reg |= SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_DQSLOGICDELAYEN_SET(1); |
| 3818 | reg |= SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_RESETDELAYEN_SET(0); |
| 3819 | reg |= SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_LPDDRDIS_SET(1); |
| 3820 | /* |
| 3821 | * This field selects the intrinsic latency to RDATA_EN/FULL path. |
| 3822 | * 00-bypass, 01- add 5 cycles, 10- add 10 cycles, 11- add 15 cycles. |
| 3823 | */ |
| 3824 | reg |= SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_ADDLATSEL_SET(0); |
| 3825 | reg |= SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_SAMPLECOUNT_19_0_SET( |
| 3826 | trk_sample_count); |
Marek Vasut | cd5d38e | 2015-07-12 20:49:39 +0200 | [diff] [blame] | 3827 | writel(reg, &sdr_ctrl->phy_ctrl0); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3828 | |
| 3829 | reg = 0; |
| 3830 | reg |= SDR_CTRLGRP_PHYCTRL_PHYCTRL_1_SAMPLECOUNT_31_20_SET( |
| 3831 | trk_sample_count >> |
| 3832 | SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_SAMPLECOUNT_19_0_WIDTH); |
| 3833 | reg |= SDR_CTRLGRP_PHYCTRL_PHYCTRL_1_LONGIDLESAMPLECOUNT_19_0_SET( |
| 3834 | trk_long_idle_sample_count); |
Marek Vasut | cd5d38e | 2015-07-12 20:49:39 +0200 | [diff] [blame] | 3835 | writel(reg, &sdr_ctrl->phy_ctrl1); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3836 | |
| 3837 | reg = 0; |
| 3838 | reg |= SDR_CTRLGRP_PHYCTRL_PHYCTRL_2_LONGIDLESAMPLECOUNT_31_20_SET( |
| 3839 | trk_long_idle_sample_count >> |
| 3840 | SDR_CTRLGRP_PHYCTRL_PHYCTRL_1_LONGIDLESAMPLECOUNT_19_0_WIDTH); |
Marek Vasut | cd5d38e | 2015-07-12 20:49:39 +0200 | [diff] [blame] | 3841 | writel(reg, &sdr_ctrl->phy_ctrl2); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3842 | } |
| 3843 | |
Marek Vasut | b0563cf | 2015-07-17 00:45:11 +0200 | [diff] [blame] | 3844 | /** |
| 3845 | * initialize_tracking() - Initialize tracking |
| 3846 | * |
| 3847 | * Initialize the register file with usable initial data. |
| 3848 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3849 | static void initialize_tracking(struct socfpga_sdrseq *seq) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3850 | { |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3851 | /* |
Marek Vasut | b0563cf | 2015-07-17 00:45:11 +0200 | [diff] [blame] | 3852 | * Initialize the register file with the correct data. |
| 3853 | * Compute usable version of value in case we skip full |
| 3854 | * computation later. |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3855 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3856 | writel(DIV_ROUND_UP(seq->iocfg->delay_per_opa_tap, |
| 3857 | seq->iocfg->delay_per_dchain_tap) - 1, |
Marek Vasut | b0563cf | 2015-07-17 00:45:11 +0200 | [diff] [blame] | 3858 | &sdr_reg_file->dtaps_per_ptap); |
| 3859 | |
| 3860 | /* trk_sample_count */ |
| 3861 | writel(7500, &sdr_reg_file->trk_sample_count); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3862 | |
Marek Vasut | b0563cf | 2015-07-17 00:45:11 +0200 | [diff] [blame] | 3863 | /* longidle outer loop [15:0] */ |
| 3864 | writel((10 << 16) | (100 << 0), &sdr_reg_file->trk_longidle); |
| 3865 | |
| 3866 | /* |
| 3867 | * longidle sample count [31:24] |
| 3868 | * trfc, worst case of 933Mhz 4Gb [23:16] |
| 3869 | * trcd, worst case [15:8] |
| 3870 | * vfifo wait [7:0] |
| 3871 | */ |
| 3872 | writel((243 << 24) | (14 << 16) | (10 << 8) | (4 << 0), |
| 3873 | &sdr_reg_file->delays); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3874 | |
Marek Vasut | b0563cf | 2015-07-17 00:45:11 +0200 | [diff] [blame] | 3875 | /* mux delay */ |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 3876 | if (dram_is_ddr(2)) { |
| 3877 | writel(0, &sdr_reg_file->trk_rw_mgr_addr); |
| 3878 | } else if (dram_is_ddr(3)) { |
| 3879 | writel((seq->rwcfg->idle << 24) | |
| 3880 | (seq->rwcfg->activate_1 << 16) | |
| 3881 | (seq->rwcfg->sgle_read << 8) | |
| 3882 | (seq->rwcfg->precharge_all << 0), |
| 3883 | &sdr_reg_file->trk_rw_mgr_addr); |
| 3884 | } |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3885 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3886 | writel(seq->rwcfg->mem_if_read_dqs_width, |
Marek Vasut | b0563cf | 2015-07-17 00:45:11 +0200 | [diff] [blame] | 3887 | &sdr_reg_file->trk_read_dqs_width); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3888 | |
Marek Vasut | b0563cf | 2015-07-17 00:45:11 +0200 | [diff] [blame] | 3889 | /* trefi [7:0] */ |
Marek Vasut | 6bccacf | 2019-10-18 00:22:31 +0200 | [diff] [blame] | 3890 | if (dram_is_ddr(2)) { |
| 3891 | writel(1000 << 0, &sdr_reg_file->trk_rfsh); |
| 3892 | } else if (dram_is_ddr(3)) { |
| 3893 | writel((seq->rwcfg->refresh_all << 24) | (1000 << 0), |
| 3894 | &sdr_reg_file->trk_rfsh); |
| 3895 | } |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3896 | } |
| 3897 | |
Simon Goldschmidt | 24910c3 | 2019-04-16 22:04:39 +0200 | [diff] [blame] | 3898 | int sdram_calibration_full(struct socfpga_sdr *sdr) |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3899 | { |
Marek Vasut | 8af9ca0 | 2015-08-02 19:42:26 +0200 | [diff] [blame] | 3900 | u32 pass; |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3901 | struct socfpga_sdrseq seq; |
Marek Vasut | 5da0f5b | 2015-07-17 01:05:36 +0200 | [diff] [blame] | 3902 | |
Simon Goldschmidt | 24910c3 | 2019-04-16 22:04:39 +0200 | [diff] [blame] | 3903 | /* |
| 3904 | * For size reasons, this file uses hard coded addresses. |
| 3905 | * Check if we are called with the correct address. |
| 3906 | */ |
| 3907 | if (sdr != (struct socfpga_sdr *)SOCFPGA_SDR_ADDRESS) |
| 3908 | return -ENODEV; |
| 3909 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3910 | memset(&seq, 0, sizeof(seq)); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3911 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3912 | seq.rwcfg = socfpga_get_sdram_rwmgr_config(); |
| 3913 | seq.iocfg = socfpga_get_sdram_io_config(); |
| 3914 | seq.misccfg = socfpga_get_sdram_misc_config(); |
Marek Vasut | 39b620e | 2015-08-02 18:12:08 +0200 | [diff] [blame] | 3915 | |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3916 | /* Set the calibration enabled by default */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3917 | seq.gbl.phy_debug_mode_flags |= PHY_DEBUG_ENABLE_CAL_RPT; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3918 | /* |
| 3919 | * Only sweep all groups (regardless of fail state) by default |
| 3920 | * Set enabled read test by default. |
| 3921 | */ |
| 3922 | #if DISABLE_GUARANTEED_READ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3923 | seq.gbl.phy_debug_mode_flags |= PHY_DEBUG_DISABLE_GUARANTEED_READ; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3924 | #endif |
| 3925 | /* Initialize the register file */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3926 | initialize_reg_file(&seq); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3927 | |
| 3928 | /* Initialize any PHY CSR */ |
| 3929 | initialize_hps_phy(); |
| 3930 | |
| 3931 | scc_mgr_initialize(); |
| 3932 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3933 | initialize_tracking(&seq); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3934 | |
Marek Vasut | ed6c1ab | 2021-09-14 05:20:19 +0200 | [diff] [blame] | 3935 | debug(KBUILD_BASENAME ": Preparing to start memory calibration\n"); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3936 | |
| 3937 | debug("%s:%d\n", __func__, __LINE__); |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 3938 | debug_cond(DLEVEL >= 1, |
Marek Vasut | 6283b4c | 2015-07-13 01:05:27 +0200 | [diff] [blame] | 3939 | "DDR3 FULL_RATE ranks=%u cs/dimm=%u dq/dqs=%u,%u vg/dqs=%u,%u ", |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3940 | seq.rwcfg->mem_number_of_ranks, |
| 3941 | seq.rwcfg->mem_number_of_cs_per_dimm, |
| 3942 | seq.rwcfg->mem_dq_per_read_dqs, |
| 3943 | seq.rwcfg->mem_dq_per_write_dqs, |
| 3944 | seq.rwcfg->mem_virtual_groups_per_read_dqs, |
| 3945 | seq.rwcfg->mem_virtual_groups_per_write_dqs); |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 3946 | debug_cond(DLEVEL >= 1, |
Marek Vasut | 6283b4c | 2015-07-13 01:05:27 +0200 | [diff] [blame] | 3947 | "dqs=%u,%u dq=%u dm=%u ptap_delay=%u dtap_delay=%u ", |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3948 | seq.rwcfg->mem_if_read_dqs_width, |
| 3949 | seq.rwcfg->mem_if_write_dqs_width, |
| 3950 | seq.rwcfg->mem_data_width, seq.rwcfg->mem_data_mask_width, |
| 3951 | seq.iocfg->delay_per_opa_tap, |
| 3952 | seq.iocfg->delay_per_dchain_tap); |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 3953 | debug_cond(DLEVEL >= 1, "dtap_dqsen_delay=%u, dll=%u", |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3954 | seq.iocfg->delay_per_dqs_en_dchain_tap, |
| 3955 | seq.iocfg->dll_chain_length); |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 3956 | debug_cond(DLEVEL >= 1, |
Marek Vasut | c85b9b3 | 2015-08-02 19:47:01 +0200 | [diff] [blame] | 3957 | "max values: en_p=%u dqdqs_p=%u en_d=%u dqs_in_d=%u ", |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3958 | seq.iocfg->dqs_en_phase_max, seq.iocfg->dqdqs_out_phase_max, |
| 3959 | seq.iocfg->dqs_en_delay_max, seq.iocfg->dqs_in_delay_max); |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 3960 | debug_cond(DLEVEL >= 1, "io_in_d=%u io_out1_d=%u io_out2_d=%u ", |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3961 | seq.iocfg->io_in_delay_max, seq.iocfg->io_out1_delay_max, |
| 3962 | seq.iocfg->io_out2_delay_max); |
Marek Vasut | 4df2d7b | 2016-04-04 21:21:05 +0200 | [diff] [blame] | 3963 | debug_cond(DLEVEL >= 1, "dqs_in_reserve=%u dqs_out_reserve=%u\n", |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3964 | seq.iocfg->dqs_in_reserve, seq.iocfg->dqs_out_reserve); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3965 | |
| 3966 | hc_initialize_rom_data(); |
| 3967 | |
| 3968 | /* update info for sims */ |
| 3969 | reg_file_set_stage(CAL_STAGE_NIL); |
| 3970 | reg_file_set_group(0); |
| 3971 | |
| 3972 | /* |
| 3973 | * Load global needed for those actions that require |
| 3974 | * some dynamic calibration support. |
| 3975 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3976 | seq.dyn_calib_steps = STATIC_CALIB_STEPS; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3977 | /* |
| 3978 | * Load global to allow dynamic selection of delay loop settings |
| 3979 | * based on calibration mode. |
| 3980 | */ |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3981 | if (!(seq.dyn_calib_steps & CALIB_SKIP_DELAY_LOOPS)) |
| 3982 | seq.skip_delay_mask = 0xff; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3983 | else |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3984 | seq.skip_delay_mask = 0x0; |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3985 | |
Simon Goldschmidt | 2be4a3e | 2019-07-11 21:18:12 +0200 | [diff] [blame] | 3986 | pass = run_mem_calibrate(&seq); |
| 3987 | debug_mem_calibrate(&seq, pass); |
Dinh Nguyen | 135cc7f | 2015-06-02 22:52:49 -0500 | [diff] [blame] | 3988 | return pass; |
| 3989 | } |