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