blob: 42308b6965dfbae7a0d0532006dfc824f5c8a789 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Stefan Roese5ffceb82015-03-26 15:36:56 +01002/*
3 * Copyright (C) Marvell International Ltd. and its affiliates
Stefan Roese5ffceb82015-03-26 15:36:56 +01004 */
5
Stefan Roese5ffceb82015-03-26 15:36:56 +01006#include "ddr3_init.h"
Chris Packham4bf81db2018-12-03 14:26:49 +13007#include "mv_ddr_regs.h"
Stefan Roese5ffceb82015-03-26 15:36:56 +01008
9#define VALIDATE_WIN_LENGTH(e1, e2, maxsize) \
10 (((e2) + 1 > (e1) + (u8)MIN_WINDOW_SIZE) && \
11 ((e2) + 1 < (e1) + (u8)maxsize))
12#define IS_WINDOW_OUT_BOUNDARY(e1, e2, maxsize) \
13 (((e1) == 0 && (e2) != 0) || \
14 ((e1) != (maxsize - 1) && (e2) == (maxsize - 1)))
15#define CENTRAL_TX 0
16#define CENTRAL_RX 1
17#define NUM_OF_CENTRAL_TYPES 2
18
19u32 start_pattern = PATTERN_KILLER_DQ0, end_pattern = PATTERN_KILLER_DQ7;
Chris Packham1a07d212018-05-10 13:28:29 +120020
Stefan Roese5ffceb82015-03-26 15:36:56 +010021u32 start_if = 0, end_if = (MAX_INTERFACE_NUM - 1);
22u8 bus_end_window[NUM_OF_CENTRAL_TYPES][MAX_INTERFACE_NUM][MAX_BUS_NUM];
23u8 bus_start_window[NUM_OF_CENTRAL_TYPES][MAX_INTERFACE_NUM][MAX_BUS_NUM];
24u8 centralization_state[MAX_INTERFACE_NUM][MAX_BUS_NUM];
25static u8 ddr3_tip_special_rx_run_once_flag;
26
27static int ddr3_tip_centralization(u32 dev_num, u32 mode);
28
29/*
30 * Centralization RX Flow
31 */
32int ddr3_tip_centralization_rx(u32 dev_num)
33{
34 CHECK_STATUS(ddr3_tip_special_rx(dev_num));
35 CHECK_STATUS(ddr3_tip_centralization(dev_num, CENTRAL_RX));
36
37 return MV_OK;
38}
39
40/*
41 * Centralization TX Flow
42 */
43int ddr3_tip_centralization_tx(u32 dev_num)
44{
45 CHECK_STATUS(ddr3_tip_centralization(dev_num, CENTRAL_TX));
46
47 return MV_OK;
48}
49
50/*
51 * Centralization Flow
52 */
53static int ddr3_tip_centralization(u32 dev_num, u32 mode)
54{
55 enum hws_training_ip_stat training_result[MAX_INTERFACE_NUM];
56 u32 if_id, pattern_id, bit_id;
57 u8 bus_id;
Marek BehĂșn9e2a9472022-01-12 17:06:59 +010058 u8 current_byte_status;
Stefan Roese5ffceb82015-03-26 15:36:56 +010059 u8 cur_start_win[BUS_WIDTH_IN_BITS];
60 u8 centralization_result[MAX_INTERFACE_NUM][BUS_WIDTH_IN_BITS];
61 u8 cur_end_win[BUS_WIDTH_IN_BITS];
62 u8 current_window[BUS_WIDTH_IN_BITS];
63 u8 opt_window, waste_window, start_window_skew, end_window_skew;
64 u8 final_pup_window[MAX_INTERFACE_NUM][BUS_WIDTH_IN_BITS];
Chris Packham1a07d212018-05-10 13:28:29 +120065 u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
66 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +010067 enum hws_training_result result_type = RESULT_PER_BIT;
68 enum hws_dir direction;
69 u32 *result[HWS_SEARCH_DIR_LIMIT];
70 u32 reg_phy_off, reg;
71 u8 max_win_size;
72 int lock_success = 1;
73 u8 cur_end_win_min, cur_start_win_max;
74 u32 cs_enable_reg_val[MAX_INTERFACE_NUM];
75 int is_if_fail = 0;
76 enum hws_result *flow_result = ddr3_tip_get_result_ptr(training_stage);
77 u32 pup_win_length = 0;
78 enum hws_search_dir search_dir_id;
79 u8 cons_tap = (mode == CENTRAL_TX) ? (64) : (0);
80
81 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +120082 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +010083 /* save current cs enable reg val */
84 CHECK_STATUS(ddr3_tip_if_read
85 (dev_num, ACCESS_TYPE_UNICAST, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +120086 DUAL_DUNIT_CFG_REG, cs_enable_reg_val, MASK_ALL_BITS));
Stefan Roese5ffceb82015-03-26 15:36:56 +010087 /* enable single cs */
88 CHECK_STATUS(ddr3_tip_if_write
89 (dev_num, ACCESS_TYPE_UNICAST, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +120090 DUAL_DUNIT_CFG_REG, (1 << 3), (1 << 3)));
Stefan Roese5ffceb82015-03-26 15:36:56 +010091 }
92
93 if (mode == CENTRAL_TX) {
94 max_win_size = MAX_WINDOW_SIZE_TX;
Chris Packham1a07d212018-05-10 13:28:29 +120095 reg_phy_off = CTX_PHY_REG(effective_cs);
Stefan Roese5ffceb82015-03-26 15:36:56 +010096 direction = OPER_WRITE;
97 } else {
98 max_win_size = MAX_WINDOW_SIZE_RX;
Chris Packham1a07d212018-05-10 13:28:29 +120099 reg_phy_off = CRX_PHY_REG(effective_cs);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100100 direction = OPER_READ;
101 }
102
103 /* DB initialization */
104 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +1200105 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100106 for (bus_id = 0;
Chris Packham1a07d212018-05-10 13:28:29 +1200107 bus_id < octets_per_if_num; bus_id++) {
108 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100109 centralization_state[if_id][bus_id] = 0;
110 bus_end_window[mode][if_id][bus_id] =
111 (max_win_size - 1) + cons_tap;
112 bus_start_window[mode][if_id][bus_id] = 0;
113 centralization_result[if_id][bus_id] = 0;
114 }
115 }
116
117 /* start flow */
118 for (pattern_id = start_pattern; pattern_id <= end_pattern;
119 pattern_id++) {
120 ddr3_tip_ip_training_wrapper(dev_num, ACCESS_TYPE_MULTICAST,
121 PARAM_NOT_CARE,
122 ACCESS_TYPE_MULTICAST,
123 PARAM_NOT_CARE, result_type,
124 HWS_CONTROL_ELEMENT_ADLL,
125 PARAM_NOT_CARE, direction,
126 tm->
127 if_act_mask, 0x0,
128 max_win_size - 1,
129 max_win_size - 1,
130 pattern_id, EDGE_FPF, CS_SINGLE,
131 PARAM_NOT_CARE, training_result);
132
133 for (if_id = start_if; if_id <= end_if; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +1200134 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100135 for (bus_id = 0;
Chris Packham1a07d212018-05-10 13:28:29 +1200136 bus_id <= octets_per_if_num - 1;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100137 bus_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +1200138 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100139
140 for (search_dir_id = HWS_LOW2HIGH;
141 search_dir_id <= HWS_HIGH2LOW;
142 search_dir_id++) {
143 CHECK_STATUS
144 (ddr3_tip_read_training_result
145 (dev_num, if_id,
146 ACCESS_TYPE_UNICAST, bus_id,
147 ALL_BITS_PER_PUP,
148 search_dir_id,
149 direction, result_type,
150 TRAINING_LOAD_OPERATION_UNLOAD,
151 CS_SINGLE,
152 &result[search_dir_id],
153 1, 0, 0));
154 DEBUG_CENTRALIZATION_ENGINE
155 (DEBUG_LEVEL_INFO,
156 ("%s pat %d IF %d pup %d Regs: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
157 ((mode ==
158 CENTRAL_TX) ? "TX" : "RX"),
159 pattern_id, if_id, bus_id,
160 result[search_dir_id][0],
161 result[search_dir_id][1],
162 result[search_dir_id][2],
163 result[search_dir_id][3],
164 result[search_dir_id][4],
165 result[search_dir_id][5],
166 result[search_dir_id][6],
167 result[search_dir_id][7]));
168 }
169
Marek BehĂșn9e2a9472022-01-12 17:06:59 +0100170 current_byte_status =
171 mv_ddr_tip_sub_phy_byte_status_get(if_id,
172 bus_id);
173
Stefan Roese5ffceb82015-03-26 15:36:56 +0100174 for (bit_id = 0; bit_id < BUS_WIDTH_IN_BITS;
175 bit_id++) {
176 /* check if this code is valid for 2 edge, probably not :( */
177 cur_start_win[bit_id] =
178 GET_TAP_RESULT(result
179 [HWS_LOW2HIGH]
180 [bit_id],
181 EDGE_1);
Marek BehĂșn9e2a9472022-01-12 17:06:59 +0100182 if (current_byte_status &
183 BYTE_SPLIT_OUT_MIX) {
184 if (cur_start_win[bit_id] >= 64)
185 cur_start_win[bit_id] -= 64;
186 else
187 cur_start_win[bit_id] = 0;
188 DEBUG_CENTRALIZATION_ENGINE
189 (DEBUG_LEVEL_INFO,
190 ("pattern %d IF %d pup %d bit %d subtract 64 adll from start\n",
191 pattern_id, if_id, bus_id, bit_id));
192 }
Stefan Roese5ffceb82015-03-26 15:36:56 +0100193 cur_end_win[bit_id] =
194 GET_TAP_RESULT(result
195 [HWS_HIGH2LOW]
196 [bit_id],
197 EDGE_1);
Marek BehĂșn9e2a9472022-01-12 17:06:59 +0100198 if (cur_end_win[bit_id] >= 64 &&
199 (current_byte_status &
200 BYTE_SPLIT_OUT_MIX)) {
201 cur_end_win[bit_id] -= 64;
202 DEBUG_CENTRALIZATION_ENGINE
203 (DEBUG_LEVEL_INFO,
204 ("pattern %d IF %d pup %d bit %d subtract 64 adll from end\n",
205 pattern_id, if_id, bus_id, bit_id));
206 }
207
Stefan Roese5ffceb82015-03-26 15:36:56 +0100208 /* window length */
209 current_window[bit_id] =
210 cur_end_win[bit_id] -
211 cur_start_win[bit_id] + 1;
212 DEBUG_CENTRALIZATION_ENGINE
213 (DEBUG_LEVEL_TRACE,
214 ("cs %x patern %d IF %d pup %d cur_start_win %d cur_end_win %d current_window %d\n",
215 effective_cs, pattern_id,
216 if_id, bus_id,
217 cur_start_win[bit_id],
218 cur_end_win[bit_id],
219 current_window[bit_id]));
220 }
221
222 if ((ddr3_tip_is_pup_lock
223 (result[HWS_LOW2HIGH], result_type)) &&
224 (ddr3_tip_is_pup_lock
225 (result[HWS_HIGH2LOW], result_type))) {
226 /* read result success */
227 DEBUG_CENTRALIZATION_ENGINE
228 (DEBUG_LEVEL_INFO,
229 ("Pup locked, pat %d IF %d pup %d\n",
230 pattern_id, if_id, bus_id));
231 } else {
232 /* read result failure */
233 DEBUG_CENTRALIZATION_ENGINE
234 (DEBUG_LEVEL_INFO,
235 ("fail Lock, pat %d IF %d pup %d\n",
236 pattern_id, if_id, bus_id));
237 if (centralization_state[if_id][bus_id]
238 == 1) {
239 /* continue with next pup */
240 DEBUG_CENTRALIZATION_ENGINE
241 (DEBUG_LEVEL_TRACE,
242 ("continue to next pup %d %d\n",
243 if_id, bus_id));
244 continue;
245 }
246
247 for (bit_id = 0;
248 bit_id < BUS_WIDTH_IN_BITS;
249 bit_id++) {
250 /*
251 * the next check is relevant
252 * only when using search
253 * machine 2 edges
254 */
255 if (cur_start_win[bit_id] > 0 &&
256 cur_end_win[bit_id] == 0) {
257 cur_end_win
258 [bit_id] =
259 max_win_size - 1;
260 DEBUG_CENTRALIZATION_ENGINE
261 (DEBUG_LEVEL_TRACE,
262 ("fail, IF %d pup %d bit %d fail #1\n",
263 if_id, bus_id,
264 bit_id));
265 /* the next bit */
266 continue;
267 } else {
268 centralization_state
269 [if_id][bus_id] = 1;
270 DEBUG_CENTRALIZATION_ENGINE
271 (DEBUG_LEVEL_TRACE,
272 ("fail, IF %d pup %d bit %d fail #2\n",
273 if_id, bus_id,
274 bit_id));
275 }
276 }
277
278 if (centralization_state[if_id][bus_id]
279 == 1) {
280 /* going to next pup */
281 continue;
282 }
283 } /*bit */
284
285 opt_window =
286 ddr3_tip_get_buf_min(current_window);
287 /* final pup window length */
288 final_pup_window[if_id][bus_id] =
289 ddr3_tip_get_buf_min(cur_end_win) -
290 ddr3_tip_get_buf_max(cur_start_win) +
291 1;
292 waste_window =
293 opt_window -
294 final_pup_window[if_id][bus_id];
295 start_window_skew =
296 ddr3_tip_get_buf_max(cur_start_win) -
297 ddr3_tip_get_buf_min(
298 cur_start_win);
299 end_window_skew =
300 ddr3_tip_get_buf_max(
301 cur_end_win) -
302 ddr3_tip_get_buf_min(
303 cur_end_win);
304 /* min/max updated with pattern change */
305 cur_end_win_min =
306 ddr3_tip_get_buf_min(
307 cur_end_win);
308 cur_start_win_max =
309 ddr3_tip_get_buf_max(
310 cur_start_win);
311 bus_end_window[mode][if_id][bus_id] =
312 GET_MIN(bus_end_window[mode][if_id]
313 [bus_id],
314 cur_end_win_min);
315 bus_start_window[mode][if_id][bus_id] =
316 GET_MAX(bus_start_window[mode][if_id]
317 [bus_id],
318 cur_start_win_max);
319 DEBUG_CENTRALIZATION_ENGINE(
320 DEBUG_LEVEL_INFO,
321 ("pat %d IF %d pup %d opt_win %d final_win %d waste_win %d st_win_skew %d end_win_skew %d cur_st_win_max %d cur_end_win_min %d bus_st_win %d bus_end_win %d\n",
322 pattern_id, if_id, bus_id, opt_window,
323 final_pup_window[if_id][bus_id],
324 waste_window, start_window_skew,
325 end_window_skew,
326 cur_start_win_max,
327 cur_end_win_min,
328 bus_start_window[mode][if_id][bus_id],
329 bus_end_window[mode][if_id][bus_id]));
330
331 /* check if window is valid */
332 if (ddr3_tip_centr_skip_min_win_check == 0) {
333 if ((VALIDATE_WIN_LENGTH
334 (bus_start_window[mode][if_id]
335 [bus_id],
336 bus_end_window[mode][if_id]
337 [bus_id],
338 max_win_size) == 1) ||
339 (IS_WINDOW_OUT_BOUNDARY
340 (bus_start_window[mode][if_id]
341 [bus_id],
342 bus_end_window[mode][if_id]
343 [bus_id],
344 max_win_size) == 1)) {
345 DEBUG_CENTRALIZATION_ENGINE
346 (DEBUG_LEVEL_INFO,
347 ("win valid, pat %d IF %d pup %d\n",
348 pattern_id, if_id,
349 bus_id));
350 /* window is valid */
351 } else {
352 DEBUG_CENTRALIZATION_ENGINE
353 (DEBUG_LEVEL_INFO,
354 ("fail win, pat %d IF %d pup %d bus_st_win %d bus_end_win %d\n",
355 pattern_id, if_id, bus_id,
356 bus_start_window[mode]
357 [if_id][bus_id],
358 bus_end_window[mode]
359 [if_id][bus_id]));
360 centralization_state[if_id]
361 [bus_id] = 1;
Chris Packham1a07d212018-05-10 13:28:29 +1200362 if (debug_mode == 0) {
363 flow_result[if_id] = TEST_FAILED;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100364 return MV_FAIL;
Chris Packham1a07d212018-05-10 13:28:29 +1200365 }
Stefan Roese5ffceb82015-03-26 15:36:56 +0100366 }
367 } /* ddr3_tip_centr_skip_min_win_check */
368 } /* pup */
369 } /* interface */
370 } /* pattern */
371
372 for (if_id = start_if; if_id <= end_if; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +1200373 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100374
375 is_if_fail = 0;
376 flow_result[if_id] = TEST_SUCCESS;
377
378 for (bus_id = 0;
Chris Packham1a07d212018-05-10 13:28:29 +1200379 bus_id <= (octets_per_if_num - 1); bus_id++) {
380 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100381
382 /* continue only if lock */
383 if (centralization_state[if_id][bus_id] != 1) {
384 if (ddr3_tip_centr_skip_min_win_check == 0) {
385 if ((bus_end_window
386 [mode][if_id][bus_id] ==
387 (max_win_size - 1)) &&
388 ((bus_end_window
389 [mode][if_id][bus_id] -
390 bus_start_window[mode][if_id]
391 [bus_id]) < MIN_WINDOW_SIZE) &&
392 ((bus_end_window[mode][if_id]
393 [bus_id] - bus_start_window
394 [mode][if_id][bus_id]) > 2)) {
395 /* prevent false lock */
396 /* TBD change to enum */
397 centralization_state
398 [if_id][bus_id] = 2;
399 }
400
401 if ((bus_end_window[mode][if_id][bus_id]
402 == 0) &&
403 ((bus_end_window[mode][if_id]
404 [bus_id] -
405 bus_start_window[mode][if_id]
406 [bus_id]) < MIN_WINDOW_SIZE) &&
407 ((bus_end_window[mode][if_id]
408 [bus_id] -
409 bus_start_window[mode][if_id]
410 [bus_id]) > 2))
411 /*prevent false lock */
412 centralization_state[if_id]
413 [bus_id] = 3;
414 }
415
416 if ((bus_end_window[mode][if_id][bus_id] >
417 (max_win_size - 1)) && direction ==
418 OPER_WRITE) {
419 DEBUG_CENTRALIZATION_ENGINE
420 (DEBUG_LEVEL_INFO,
421 ("Tx special pattern\n"));
422 cons_tap = 64;
423 }
424 }
425
426 /* check states */
427 if (centralization_state[if_id][bus_id] == 3) {
428 DEBUG_CENTRALIZATION_ENGINE(
429 DEBUG_LEVEL_INFO,
430 ("SSW - TBD IF %d pup %d\n",
431 if_id, bus_id));
432 lock_success = 1;
433 } else if (centralization_state[if_id][bus_id] == 2) {
434 DEBUG_CENTRALIZATION_ENGINE(
435 DEBUG_LEVEL_INFO,
436 ("SEW - TBD IF %d pup %d\n",
437 if_id, bus_id));
438 lock_success = 1;
439 } else if (centralization_state[if_id][bus_id] == 0) {
440 lock_success = 1;
441 } else {
442 DEBUG_CENTRALIZATION_ENGINE(
443 DEBUG_LEVEL_ERROR,
444 ("fail, IF %d pup %d\n",
445 if_id, bus_id));
446 lock_success = 0;
447 }
448
449 if (lock_success == 1) {
450 centralization_result[if_id][bus_id] =
451 (bus_end_window[mode][if_id][bus_id] +
452 bus_start_window[mode][if_id][bus_id])
453 / 2 - cons_tap;
454 DEBUG_CENTRALIZATION_ENGINE(
455 DEBUG_LEVEL_TRACE,
456 (" bus_id %d Res= %d\n", bus_id,
457 centralization_result[if_id][bus_id]));
458 /* copy results to registers */
459 pup_win_length =
460 bus_end_window[mode][if_id][bus_id] -
461 bus_start_window[mode][if_id][bus_id] +
462 1;
463
464 ddr3_tip_bus_read(dev_num, if_id,
465 ACCESS_TYPE_UNICAST, bus_id,
466 DDR_PHY_DATA,
Chris Packham1a07d212018-05-10 13:28:29 +1200467 RESULT_PHY_REG +
Stefan Roese5ffceb82015-03-26 15:36:56 +0100468 effective_cs, &reg);
469 reg = (reg & (~0x1f <<
470 ((mode == CENTRAL_TX) ?
Chris Packham1a07d212018-05-10 13:28:29 +1200471 (RESULT_PHY_TX_OFFS) :
472 (RESULT_PHY_RX_OFFS))))
Stefan Roese5ffceb82015-03-26 15:36:56 +0100473 | pup_win_length <<
474 ((mode == CENTRAL_TX) ?
Chris Packham1a07d212018-05-10 13:28:29 +1200475 (RESULT_PHY_TX_OFFS) :
476 (RESULT_PHY_RX_OFFS));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100477 CHECK_STATUS(ddr3_tip_bus_write
478 (dev_num, ACCESS_TYPE_UNICAST,
479 if_id, ACCESS_TYPE_UNICAST,
480 bus_id, DDR_PHY_DATA,
Chris Packham1a07d212018-05-10 13:28:29 +1200481 RESULT_PHY_REG +
Stefan Roese5ffceb82015-03-26 15:36:56 +0100482 effective_cs, reg));
483
484 /* offset per CS is calculated earlier */
485 CHECK_STATUS(
486 ddr3_tip_bus_write(dev_num,
487 ACCESS_TYPE_UNICAST,
488 if_id,
489 ACCESS_TYPE_UNICAST,
490 bus_id,
491 DDR_PHY_DATA,
492 reg_phy_off,
493 centralization_result
494 [if_id]
495 [bus_id]));
496 } else {
497 is_if_fail = 1;
498 }
499 }
500
501 if (is_if_fail == 1)
502 flow_result[if_id] = TEST_FAILED;
503 }
504
505 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
506 /* restore cs enable value */
Chris Packham1a07d212018-05-10 13:28:29 +1200507 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100508 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_UNICAST,
Chris Packham1a07d212018-05-10 13:28:29 +1200509 if_id, DUAL_DUNIT_CFG_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100510 cs_enable_reg_val[if_id],
511 MASK_ALL_BITS));
512 }
513
514 return is_if_fail;
515}
516
517/*
518 * Centralization Flow
519 */
520int ddr3_tip_special_rx(u32 dev_num)
521{
522 enum hws_training_ip_stat training_result[MAX_INTERFACE_NUM];
523 u32 if_id, pup_id, pattern_id, bit_id;
524 u8 cur_start_win[BUS_WIDTH_IN_BITS];
525 u8 cur_end_win[BUS_WIDTH_IN_BITS];
526 enum hws_training_result result_type = RESULT_PER_BIT;
527 enum hws_dir direction;
528 enum hws_search_dir search_dir_id;
529 u32 *result[HWS_SEARCH_DIR_LIMIT];
530 u32 max_win_size;
531 u8 cur_end_win_min, cur_start_win_max;
532 u32 cs_enable_reg_val[MAX_INTERFACE_NUM];
533 u32 temp = 0;
534 int pad_num = 0;
Chris Packham1a07d212018-05-10 13:28:29 +1200535 u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
536 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +0100537
Chris Packham1a07d212018-05-10 13:28:29 +1200538 if ((ddr3_tip_special_rx_run_once_flag & (1 << effective_cs)) == (1 << effective_cs))
Stefan Roese5ffceb82015-03-26 15:36:56 +0100539 return MV_OK;
540
Chris Packham1a07d212018-05-10 13:28:29 +1200541 ddr3_tip_special_rx_run_once_flag |= (1 << effective_cs);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100542
543 for (if_id = 0; if_id < MAX_INTERFACE_NUM; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +1200544 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100545 /* save current cs enable reg val */
546 CHECK_STATUS(ddr3_tip_if_read(dev_num, ACCESS_TYPE_UNICAST,
Chris Packham1a07d212018-05-10 13:28:29 +1200547 if_id, DUAL_DUNIT_CFG_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100548 cs_enable_reg_val,
549 MASK_ALL_BITS));
550 /* enable single cs */
551 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_UNICAST,
Chris Packham1a07d212018-05-10 13:28:29 +1200552 if_id, DUAL_DUNIT_CFG_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100553 (1 << 3), (1 << 3)));
554 }
555
556 max_win_size = MAX_WINDOW_SIZE_RX;
557 direction = OPER_READ;
Chris Packham1a07d212018-05-10 13:28:29 +1200558 pattern_id = PATTERN_FULL_SSO1;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100559
560 /* start flow */
561 ddr3_tip_ip_training_wrapper(dev_num, ACCESS_TYPE_MULTICAST,
562 PARAM_NOT_CARE, ACCESS_TYPE_MULTICAST,
563 PARAM_NOT_CARE, result_type,
564 HWS_CONTROL_ELEMENT_ADLL,
565 PARAM_NOT_CARE, direction,
566 tm->if_act_mask, 0x0,
567 max_win_size - 1, max_win_size - 1,
568 pattern_id, EDGE_FPF, CS_SINGLE,
569 PARAM_NOT_CARE, training_result);
570
571 for (if_id = start_if; if_id <= end_if; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +1200572 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100573 for (pup_id = 0;
Chris Packham1a07d212018-05-10 13:28:29 +1200574 pup_id <= octets_per_if_num; pup_id++) {
575 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, pup_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100576
577 for (search_dir_id = HWS_LOW2HIGH;
578 search_dir_id <= HWS_HIGH2LOW;
579 search_dir_id++) {
580 CHECK_STATUS(ddr3_tip_read_training_result
581 (dev_num, if_id,
582 ACCESS_TYPE_UNICAST, pup_id,
583 ALL_BITS_PER_PUP, search_dir_id,
584 direction, result_type,
585 TRAINING_LOAD_OPERATION_UNLOAD,
586 CS_SINGLE, &result[search_dir_id],
587 1, 0, 0));
588 DEBUG_CENTRALIZATION_ENGINE(DEBUG_LEVEL_INFO,
589 ("Special: pat %d IF %d pup %d Regs: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
590 pattern_id, if_id,
591 pup_id,
592 result
593 [search_dir_id][0],
594 result
595 [search_dir_id][1],
596 result
597 [search_dir_id][2],
598 result
599 [search_dir_id][3],
600 result
601 [search_dir_id][4],
602 result
603 [search_dir_id][5],
604 result
605 [search_dir_id][6],
606 result
607 [search_dir_id]
608 [7]));
609 }
610
611 for (bit_id = 0; bit_id < BUS_WIDTH_IN_BITS; bit_id++) {
612 /*
613 * check if this code is valid for 2 edge,
614 * probably not :(
615 */
616 cur_start_win[bit_id] =
617 GET_TAP_RESULT(result[HWS_LOW2HIGH]
618 [bit_id], EDGE_1);
619 cur_end_win[bit_id] =
620 GET_TAP_RESULT(result[HWS_HIGH2LOW]
621 [bit_id], EDGE_1);
622 }
623 if (!((ddr3_tip_is_pup_lock
624 (result[HWS_LOW2HIGH], result_type)) &&
625 (ddr3_tip_is_pup_lock
626 (result[HWS_HIGH2LOW], result_type)))) {
627 DEBUG_CENTRALIZATION_ENGINE(
628 DEBUG_LEVEL_ERROR,
629 ("Special: Pup lock fail, pat %d IF %d pup %d\n",
630 pattern_id, if_id, pup_id));
631 return MV_FAIL;
632 }
633
634 cur_end_win_min =
635 ddr3_tip_get_buf_min(cur_end_win);
636 cur_start_win_max =
637 ddr3_tip_get_buf_max(cur_start_win);
638
639 if (cur_start_win_max <= 1) { /* Align left */
640 for (bit_id = 0; bit_id < BUS_WIDTH_IN_BITS;
641 bit_id++) {
642 pad_num =
643 dq_map_table[bit_id +
644 pup_id *
645 BUS_WIDTH_IN_BITS +
646 if_id *
647 BUS_WIDTH_IN_BITS *
Chris Packham1a07d212018-05-10 13:28:29 +1200648 MAX_BUS_NUM];
Stefan Roese5ffceb82015-03-26 15:36:56 +0100649 CHECK_STATUS(ddr3_tip_bus_read
650 (dev_num, if_id,
651 ACCESS_TYPE_UNICAST,
652 pup_id, DDR_PHY_DATA,
Chris Packham1a07d212018-05-10 13:28:29 +1200653 PBS_RX_PHY_REG(effective_cs, pad_num),
Stefan Roese5ffceb82015-03-26 15:36:56 +0100654 &temp));
655 temp = (temp + 0xa > 31) ?
656 (31) : (temp + 0xa);
657 CHECK_STATUS(ddr3_tip_bus_write
658 (dev_num,
659 ACCESS_TYPE_UNICAST,
660 if_id,
661 ACCESS_TYPE_UNICAST,
662 pup_id, DDR_PHY_DATA,
Chris Packham1a07d212018-05-10 13:28:29 +1200663 PBS_RX_PHY_REG(effective_cs, pad_num),
Stefan Roese5ffceb82015-03-26 15:36:56 +0100664 temp));
665 }
666 DEBUG_CENTRALIZATION_ENGINE(
667 DEBUG_LEVEL_INFO,
668 ("Special: PBS:: I/F# %d , Bus# %d fix align to the Left\n",
669 if_id, pup_id));
670 }
671
672 if (cur_end_win_min > 30) { /* Align right */
673 CHECK_STATUS(ddr3_tip_bus_read
674 (dev_num, if_id,
675 ACCESS_TYPE_UNICAST, pup_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200676 DDR_PHY_DATA,
677 PBS_RX_PHY_REG(effective_cs, 4),
Stefan Roese5ffceb82015-03-26 15:36:56 +0100678 &temp));
679 temp += 0xa;
680 CHECK_STATUS(ddr3_tip_bus_write
681 (dev_num, ACCESS_TYPE_UNICAST,
682 if_id, ACCESS_TYPE_UNICAST,
683 pup_id, DDR_PHY_DATA,
Chris Packham1a07d212018-05-10 13:28:29 +1200684 PBS_RX_PHY_REG(effective_cs, 4),
685 temp));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100686 CHECK_STATUS(ddr3_tip_bus_read
687 (dev_num, if_id,
688 ACCESS_TYPE_UNICAST, pup_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200689 DDR_PHY_DATA,
690 PBS_RX_PHY_REG(effective_cs, 5),
Stefan Roese5ffceb82015-03-26 15:36:56 +0100691 &temp));
692 temp += 0xa;
693 CHECK_STATUS(ddr3_tip_bus_write
694 (dev_num, ACCESS_TYPE_UNICAST,
695 if_id, ACCESS_TYPE_UNICAST,
696 pup_id, DDR_PHY_DATA,
Chris Packham1a07d212018-05-10 13:28:29 +1200697 PBS_RX_PHY_REG(effective_cs, 5),
698 temp));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100699 DEBUG_CENTRALIZATION_ENGINE(
700 DEBUG_LEVEL_INFO,
701 ("Special: PBS:: I/F# %d , Bus# %d fix align to the right\n",
702 if_id, pup_id));
703 }
704
705 vref_window_size[if_id][pup_id] =
706 cur_end_win_min -
707 cur_start_win_max + 1;
708 DEBUG_CENTRALIZATION_ENGINE(
709 DEBUG_LEVEL_INFO,
710 ("Special: Winsize I/F# %d , Bus# %d is %d\n",
711 if_id, pup_id, vref_window_size
712 [if_id][pup_id]));
713 } /* pup */
714 } /* end of interface */
715
716 return MV_OK;
717}
718
719/*
720 * Print Centralization Result
721 */
722int ddr3_tip_print_centralization_result(u32 dev_num)
723{
724 u32 if_id = 0, bus_id = 0;
Chris Packham1a07d212018-05-10 13:28:29 +1200725 u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
726 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +0100727
Chris Packham4bf81db2018-12-03 14:26:49 +1300728 dev_num = dev_num;
729
Stefan Roese5ffceb82015-03-26 15:36:56 +0100730 printf("Centralization Results\n");
731 printf("I/F0 Result[0 - success 1-fail 2 - state_2 3 - state_3] ...\n");
732 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +1200733 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
734 for (bus_id = 0; bus_id < octets_per_if_num;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100735 bus_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +1200736 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100737 printf("%d ,\n", centralization_state[if_id][bus_id]);
738 }
739 }
740
741 return MV_OK;
742}