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