blob: be9f985f22f12428ce8a8135256284d7cae435f7 [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 &
Marek BehĂșn532b7192022-02-17 01:08:37 +0100183 (BYTE_SPLIT_OUT_MIX |
184 BYTE_HOMOGENEOUS_SPLIT_OUT)) {
Marek BehĂșn9e2a9472022-01-12 17:06:59 +0100185 if (cur_start_win[bit_id] >= 64)
186 cur_start_win[bit_id] -= 64;
187 else
188 cur_start_win[bit_id] = 0;
189 DEBUG_CENTRALIZATION_ENGINE
190 (DEBUG_LEVEL_INFO,
191 ("pattern %d IF %d pup %d bit %d subtract 64 adll from start\n",
192 pattern_id, if_id, bus_id, bit_id));
193 }
Stefan Roese5ffceb82015-03-26 15:36:56 +0100194 cur_end_win[bit_id] =
195 GET_TAP_RESULT(result
196 [HWS_HIGH2LOW]
197 [bit_id],
198 EDGE_1);
Marek BehĂșn9e2a9472022-01-12 17:06:59 +0100199 if (cur_end_win[bit_id] >= 64 &&
200 (current_byte_status &
Marek BehĂșn532b7192022-02-17 01:08:37 +0100201 (BYTE_SPLIT_OUT_MIX |
202 BYTE_HOMOGENEOUS_SPLIT_OUT))) {
Marek BehĂșn9e2a9472022-01-12 17:06:59 +0100203 cur_end_win[bit_id] -= 64;
204 DEBUG_CENTRALIZATION_ENGINE
205 (DEBUG_LEVEL_INFO,
206 ("pattern %d IF %d pup %d bit %d subtract 64 adll from end\n",
207 pattern_id, if_id, bus_id, bit_id));
208 }
209
Stefan Roese5ffceb82015-03-26 15:36:56 +0100210 /* window length */
211 current_window[bit_id] =
212 cur_end_win[bit_id] -
213 cur_start_win[bit_id] + 1;
214 DEBUG_CENTRALIZATION_ENGINE
215 (DEBUG_LEVEL_TRACE,
216 ("cs %x patern %d IF %d pup %d cur_start_win %d cur_end_win %d current_window %d\n",
217 effective_cs, pattern_id,
218 if_id, bus_id,
219 cur_start_win[bit_id],
220 cur_end_win[bit_id],
221 current_window[bit_id]));
222 }
223
224 if ((ddr3_tip_is_pup_lock
225 (result[HWS_LOW2HIGH], result_type)) &&
226 (ddr3_tip_is_pup_lock
227 (result[HWS_HIGH2LOW], result_type))) {
228 /* read result success */
229 DEBUG_CENTRALIZATION_ENGINE
230 (DEBUG_LEVEL_INFO,
231 ("Pup locked, pat %d IF %d pup %d\n",
232 pattern_id, if_id, bus_id));
233 } else {
234 /* read result failure */
235 DEBUG_CENTRALIZATION_ENGINE
236 (DEBUG_LEVEL_INFO,
237 ("fail Lock, pat %d IF %d pup %d\n",
238 pattern_id, if_id, bus_id));
239 if (centralization_state[if_id][bus_id]
240 == 1) {
241 /* continue with next pup */
242 DEBUG_CENTRALIZATION_ENGINE
243 (DEBUG_LEVEL_TRACE,
244 ("continue to next pup %d %d\n",
245 if_id, bus_id));
246 continue;
247 }
248
249 for (bit_id = 0;
250 bit_id < BUS_WIDTH_IN_BITS;
251 bit_id++) {
252 /*
253 * the next check is relevant
254 * only when using search
255 * machine 2 edges
256 */
257 if (cur_start_win[bit_id] > 0 &&
258 cur_end_win[bit_id] == 0) {
259 cur_end_win
260 [bit_id] =
261 max_win_size - 1;
262 DEBUG_CENTRALIZATION_ENGINE
263 (DEBUG_LEVEL_TRACE,
264 ("fail, IF %d pup %d bit %d fail #1\n",
265 if_id, bus_id,
266 bit_id));
267 /* the next bit */
268 continue;
269 } else {
270 centralization_state
271 [if_id][bus_id] = 1;
272 DEBUG_CENTRALIZATION_ENGINE
273 (DEBUG_LEVEL_TRACE,
274 ("fail, IF %d pup %d bit %d fail #2\n",
275 if_id, bus_id,
276 bit_id));
277 }
278 }
279
280 if (centralization_state[if_id][bus_id]
281 == 1) {
282 /* going to next pup */
283 continue;
284 }
285 } /*bit */
286
287 opt_window =
288 ddr3_tip_get_buf_min(current_window);
289 /* final pup window length */
290 final_pup_window[if_id][bus_id] =
291 ddr3_tip_get_buf_min(cur_end_win) -
292 ddr3_tip_get_buf_max(cur_start_win) +
293 1;
294 waste_window =
295 opt_window -
296 final_pup_window[if_id][bus_id];
297 start_window_skew =
298 ddr3_tip_get_buf_max(cur_start_win) -
299 ddr3_tip_get_buf_min(
300 cur_start_win);
301 end_window_skew =
302 ddr3_tip_get_buf_max(
303 cur_end_win) -
304 ddr3_tip_get_buf_min(
305 cur_end_win);
306 /* min/max updated with pattern change */
307 cur_end_win_min =
308 ddr3_tip_get_buf_min(
309 cur_end_win);
310 cur_start_win_max =
311 ddr3_tip_get_buf_max(
312 cur_start_win);
313 bus_end_window[mode][if_id][bus_id] =
314 GET_MIN(bus_end_window[mode][if_id]
315 [bus_id],
316 cur_end_win_min);
317 bus_start_window[mode][if_id][bus_id] =
318 GET_MAX(bus_start_window[mode][if_id]
319 [bus_id],
320 cur_start_win_max);
321 DEBUG_CENTRALIZATION_ENGINE(
322 DEBUG_LEVEL_INFO,
323 ("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",
324 pattern_id, if_id, bus_id, opt_window,
325 final_pup_window[if_id][bus_id],
326 waste_window, start_window_skew,
327 end_window_skew,
328 cur_start_win_max,
329 cur_end_win_min,
330 bus_start_window[mode][if_id][bus_id],
331 bus_end_window[mode][if_id][bus_id]));
332
333 /* check if window is valid */
334 if (ddr3_tip_centr_skip_min_win_check == 0) {
335 if ((VALIDATE_WIN_LENGTH
336 (bus_start_window[mode][if_id]
337 [bus_id],
338 bus_end_window[mode][if_id]
339 [bus_id],
340 max_win_size) == 1) ||
341 (IS_WINDOW_OUT_BOUNDARY
342 (bus_start_window[mode][if_id]
343 [bus_id],
344 bus_end_window[mode][if_id]
345 [bus_id],
346 max_win_size) == 1)) {
347 DEBUG_CENTRALIZATION_ENGINE
348 (DEBUG_LEVEL_INFO,
349 ("win valid, pat %d IF %d pup %d\n",
350 pattern_id, if_id,
351 bus_id));
352 /* window is valid */
353 } else {
354 DEBUG_CENTRALIZATION_ENGINE
355 (DEBUG_LEVEL_INFO,
356 ("fail win, pat %d IF %d pup %d bus_st_win %d bus_end_win %d\n",
357 pattern_id, if_id, bus_id,
358 bus_start_window[mode]
359 [if_id][bus_id],
360 bus_end_window[mode]
361 [if_id][bus_id]));
362 centralization_state[if_id]
363 [bus_id] = 1;
Chris Packham1a07d212018-05-10 13:28:29 +1200364 if (debug_mode == 0) {
365 flow_result[if_id] = TEST_FAILED;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100366 return MV_FAIL;
Chris Packham1a07d212018-05-10 13:28:29 +1200367 }
Stefan Roese5ffceb82015-03-26 15:36:56 +0100368 }
369 } /* ddr3_tip_centr_skip_min_win_check */
370 } /* pup */
371 } /* interface */
372 } /* pattern */
373
374 for (if_id = start_if; if_id <= end_if; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +1200375 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100376
377 is_if_fail = 0;
378 flow_result[if_id] = TEST_SUCCESS;
379
380 for (bus_id = 0;
Chris Packham1a07d212018-05-10 13:28:29 +1200381 bus_id <= (octets_per_if_num - 1); bus_id++) {
382 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100383
384 /* continue only if lock */
385 if (centralization_state[if_id][bus_id] != 1) {
386 if (ddr3_tip_centr_skip_min_win_check == 0) {
387 if ((bus_end_window
388 [mode][if_id][bus_id] ==
389 (max_win_size - 1)) &&
390 ((bus_end_window
391 [mode][if_id][bus_id] -
392 bus_start_window[mode][if_id]
393 [bus_id]) < MIN_WINDOW_SIZE) &&
394 ((bus_end_window[mode][if_id]
395 [bus_id] - bus_start_window
396 [mode][if_id][bus_id]) > 2)) {
397 /* prevent false lock */
398 /* TBD change to enum */
399 centralization_state
400 [if_id][bus_id] = 2;
401 }
402
403 if ((bus_end_window[mode][if_id][bus_id]
404 == 0) &&
405 ((bus_end_window[mode][if_id]
406 [bus_id] -
407 bus_start_window[mode][if_id]
408 [bus_id]) < MIN_WINDOW_SIZE) &&
409 ((bus_end_window[mode][if_id]
410 [bus_id] -
411 bus_start_window[mode][if_id]
412 [bus_id]) > 2))
413 /*prevent false lock */
414 centralization_state[if_id]
415 [bus_id] = 3;
416 }
417
418 if ((bus_end_window[mode][if_id][bus_id] >
419 (max_win_size - 1)) && direction ==
420 OPER_WRITE) {
421 DEBUG_CENTRALIZATION_ENGINE
422 (DEBUG_LEVEL_INFO,
423 ("Tx special pattern\n"));
424 cons_tap = 64;
425 }
426 }
427
428 /* check states */
429 if (centralization_state[if_id][bus_id] == 3) {
430 DEBUG_CENTRALIZATION_ENGINE(
431 DEBUG_LEVEL_INFO,
432 ("SSW - TBD IF %d pup %d\n",
433 if_id, bus_id));
434 lock_success = 1;
435 } else if (centralization_state[if_id][bus_id] == 2) {
436 DEBUG_CENTRALIZATION_ENGINE(
437 DEBUG_LEVEL_INFO,
438 ("SEW - TBD IF %d pup %d\n",
439 if_id, bus_id));
440 lock_success = 1;
441 } else if (centralization_state[if_id][bus_id] == 0) {
442 lock_success = 1;
443 } else {
444 DEBUG_CENTRALIZATION_ENGINE(
445 DEBUG_LEVEL_ERROR,
446 ("fail, IF %d pup %d\n",
447 if_id, bus_id));
448 lock_success = 0;
449 }
450
451 if (lock_success == 1) {
452 centralization_result[if_id][bus_id] =
453 (bus_end_window[mode][if_id][bus_id] +
454 bus_start_window[mode][if_id][bus_id])
455 / 2 - cons_tap;
456 DEBUG_CENTRALIZATION_ENGINE(
457 DEBUG_LEVEL_TRACE,
458 (" bus_id %d Res= %d\n", bus_id,
459 centralization_result[if_id][bus_id]));
460 /* copy results to registers */
461 pup_win_length =
462 bus_end_window[mode][if_id][bus_id] -
463 bus_start_window[mode][if_id][bus_id] +
464 1;
465
466 ddr3_tip_bus_read(dev_num, if_id,
467 ACCESS_TYPE_UNICAST, bus_id,
468 DDR_PHY_DATA,
Chris Packham1a07d212018-05-10 13:28:29 +1200469 RESULT_PHY_REG +
Stefan Roese5ffceb82015-03-26 15:36:56 +0100470 effective_cs, &reg);
471 reg = (reg & (~0x1f <<
472 ((mode == CENTRAL_TX) ?
Chris Packham1a07d212018-05-10 13:28:29 +1200473 (RESULT_PHY_TX_OFFS) :
474 (RESULT_PHY_RX_OFFS))))
Stefan Roese5ffceb82015-03-26 15:36:56 +0100475 | pup_win_length <<
476 ((mode == CENTRAL_TX) ?
Chris Packham1a07d212018-05-10 13:28:29 +1200477 (RESULT_PHY_TX_OFFS) :
478 (RESULT_PHY_RX_OFFS));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100479 CHECK_STATUS(ddr3_tip_bus_write
480 (dev_num, ACCESS_TYPE_UNICAST,
481 if_id, ACCESS_TYPE_UNICAST,
482 bus_id, DDR_PHY_DATA,
Chris Packham1a07d212018-05-10 13:28:29 +1200483 RESULT_PHY_REG +
Stefan Roese5ffceb82015-03-26 15:36:56 +0100484 effective_cs, reg));
485
486 /* offset per CS is calculated earlier */
487 CHECK_STATUS(
488 ddr3_tip_bus_write(dev_num,
489 ACCESS_TYPE_UNICAST,
490 if_id,
491 ACCESS_TYPE_UNICAST,
492 bus_id,
493 DDR_PHY_DATA,
494 reg_phy_off,
495 centralization_result
496 [if_id]
497 [bus_id]));
498 } else {
499 is_if_fail = 1;
500 }
501 }
502
503 if (is_if_fail == 1)
504 flow_result[if_id] = TEST_FAILED;
505 }
506
507 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
508 /* restore cs enable value */
Chris Packham1a07d212018-05-10 13:28:29 +1200509 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100510 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_UNICAST,
Chris Packham1a07d212018-05-10 13:28:29 +1200511 if_id, DUAL_DUNIT_CFG_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100512 cs_enable_reg_val[if_id],
513 MASK_ALL_BITS));
514 }
515
516 return is_if_fail;
517}
518
519/*
520 * Centralization Flow
521 */
522int ddr3_tip_special_rx(u32 dev_num)
523{
524 enum hws_training_ip_stat training_result[MAX_INTERFACE_NUM];
525 u32 if_id, pup_id, pattern_id, bit_id;
526 u8 cur_start_win[BUS_WIDTH_IN_BITS];
527 u8 cur_end_win[BUS_WIDTH_IN_BITS];
528 enum hws_training_result result_type = RESULT_PER_BIT;
529 enum hws_dir direction;
530 enum hws_search_dir search_dir_id;
531 u32 *result[HWS_SEARCH_DIR_LIMIT];
532 u32 max_win_size;
533 u8 cur_end_win_min, cur_start_win_max;
534 u32 cs_enable_reg_val[MAX_INTERFACE_NUM];
535 u32 temp = 0;
536 int pad_num = 0;
Chris Packham1a07d212018-05-10 13:28:29 +1200537 u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
538 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +0100539
Chris Packham1a07d212018-05-10 13:28:29 +1200540 if ((ddr3_tip_special_rx_run_once_flag & (1 << effective_cs)) == (1 << effective_cs))
Stefan Roese5ffceb82015-03-26 15:36:56 +0100541 return MV_OK;
542
Chris Packham1a07d212018-05-10 13:28:29 +1200543 ddr3_tip_special_rx_run_once_flag |= (1 << effective_cs);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100544
545 for (if_id = 0; if_id < MAX_INTERFACE_NUM; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +1200546 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100547 /* save current cs enable reg val */
548 CHECK_STATUS(ddr3_tip_if_read(dev_num, ACCESS_TYPE_UNICAST,
Chris Packham1a07d212018-05-10 13:28:29 +1200549 if_id, DUAL_DUNIT_CFG_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100550 cs_enable_reg_val,
551 MASK_ALL_BITS));
552 /* enable single cs */
553 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_UNICAST,
Chris Packham1a07d212018-05-10 13:28:29 +1200554 if_id, DUAL_DUNIT_CFG_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100555 (1 << 3), (1 << 3)));
556 }
557
558 max_win_size = MAX_WINDOW_SIZE_RX;
559 direction = OPER_READ;
Chris Packham1a07d212018-05-10 13:28:29 +1200560 pattern_id = PATTERN_FULL_SSO1;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100561
562 /* start flow */
563 ddr3_tip_ip_training_wrapper(dev_num, ACCESS_TYPE_MULTICAST,
564 PARAM_NOT_CARE, ACCESS_TYPE_MULTICAST,
565 PARAM_NOT_CARE, result_type,
566 HWS_CONTROL_ELEMENT_ADLL,
567 PARAM_NOT_CARE, direction,
568 tm->if_act_mask, 0x0,
569 max_win_size - 1, max_win_size - 1,
570 pattern_id, EDGE_FPF, CS_SINGLE,
571 PARAM_NOT_CARE, training_result);
572
573 for (if_id = start_if; if_id <= end_if; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +1200574 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100575 for (pup_id = 0;
Chris Packham1a07d212018-05-10 13:28:29 +1200576 pup_id <= octets_per_if_num; pup_id++) {
577 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, pup_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100578
579 for (search_dir_id = HWS_LOW2HIGH;
580 search_dir_id <= HWS_HIGH2LOW;
581 search_dir_id++) {
582 CHECK_STATUS(ddr3_tip_read_training_result
583 (dev_num, if_id,
584 ACCESS_TYPE_UNICAST, pup_id,
585 ALL_BITS_PER_PUP, search_dir_id,
586 direction, result_type,
587 TRAINING_LOAD_OPERATION_UNLOAD,
588 CS_SINGLE, &result[search_dir_id],
589 1, 0, 0));
590 DEBUG_CENTRALIZATION_ENGINE(DEBUG_LEVEL_INFO,
591 ("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",
592 pattern_id, if_id,
593 pup_id,
594 result
595 [search_dir_id][0],
596 result
597 [search_dir_id][1],
598 result
599 [search_dir_id][2],
600 result
601 [search_dir_id][3],
602 result
603 [search_dir_id][4],
604 result
605 [search_dir_id][5],
606 result
607 [search_dir_id][6],
608 result
609 [search_dir_id]
610 [7]));
611 }
612
613 for (bit_id = 0; bit_id < BUS_WIDTH_IN_BITS; bit_id++) {
614 /*
615 * check if this code is valid for 2 edge,
616 * probably not :(
617 */
618 cur_start_win[bit_id] =
619 GET_TAP_RESULT(result[HWS_LOW2HIGH]
620 [bit_id], EDGE_1);
621 cur_end_win[bit_id] =
622 GET_TAP_RESULT(result[HWS_HIGH2LOW]
623 [bit_id], EDGE_1);
624 }
625 if (!((ddr3_tip_is_pup_lock
626 (result[HWS_LOW2HIGH], result_type)) &&
627 (ddr3_tip_is_pup_lock
628 (result[HWS_HIGH2LOW], result_type)))) {
629 DEBUG_CENTRALIZATION_ENGINE(
630 DEBUG_LEVEL_ERROR,
631 ("Special: Pup lock fail, pat %d IF %d pup %d\n",
632 pattern_id, if_id, pup_id));
633 return MV_FAIL;
634 }
635
636 cur_end_win_min =
637 ddr3_tip_get_buf_min(cur_end_win);
638 cur_start_win_max =
639 ddr3_tip_get_buf_max(cur_start_win);
640
641 if (cur_start_win_max <= 1) { /* Align left */
642 for (bit_id = 0; bit_id < BUS_WIDTH_IN_BITS;
643 bit_id++) {
644 pad_num =
645 dq_map_table[bit_id +
646 pup_id *
647 BUS_WIDTH_IN_BITS +
648 if_id *
649 BUS_WIDTH_IN_BITS *
Chris Packham1a07d212018-05-10 13:28:29 +1200650 MAX_BUS_NUM];
Stefan Roese5ffceb82015-03-26 15:36:56 +0100651 CHECK_STATUS(ddr3_tip_bus_read
652 (dev_num, if_id,
653 ACCESS_TYPE_UNICAST,
654 pup_id, DDR_PHY_DATA,
Chris Packham1a07d212018-05-10 13:28:29 +1200655 PBS_RX_PHY_REG(effective_cs, pad_num),
Stefan Roese5ffceb82015-03-26 15:36:56 +0100656 &temp));
657 temp = (temp + 0xa > 31) ?
658 (31) : (temp + 0xa);
659 CHECK_STATUS(ddr3_tip_bus_write
660 (dev_num,
661 ACCESS_TYPE_UNICAST,
662 if_id,
663 ACCESS_TYPE_UNICAST,
664 pup_id, DDR_PHY_DATA,
Chris Packham1a07d212018-05-10 13:28:29 +1200665 PBS_RX_PHY_REG(effective_cs, pad_num),
Stefan Roese5ffceb82015-03-26 15:36:56 +0100666 temp));
667 }
668 DEBUG_CENTRALIZATION_ENGINE(
669 DEBUG_LEVEL_INFO,
670 ("Special: PBS:: I/F# %d , Bus# %d fix align to the Left\n",
671 if_id, pup_id));
672 }
673
674 if (cur_end_win_min > 30) { /* Align right */
675 CHECK_STATUS(ddr3_tip_bus_read
676 (dev_num, if_id,
677 ACCESS_TYPE_UNICAST, pup_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200678 DDR_PHY_DATA,
679 PBS_RX_PHY_REG(effective_cs, 4),
Stefan Roese5ffceb82015-03-26 15:36:56 +0100680 &temp));
681 temp += 0xa;
682 CHECK_STATUS(ddr3_tip_bus_write
683 (dev_num, ACCESS_TYPE_UNICAST,
684 if_id, ACCESS_TYPE_UNICAST,
685 pup_id, DDR_PHY_DATA,
Chris Packham1a07d212018-05-10 13:28:29 +1200686 PBS_RX_PHY_REG(effective_cs, 4),
687 temp));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100688 CHECK_STATUS(ddr3_tip_bus_read
689 (dev_num, if_id,
690 ACCESS_TYPE_UNICAST, pup_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200691 DDR_PHY_DATA,
692 PBS_RX_PHY_REG(effective_cs, 5),
Stefan Roese5ffceb82015-03-26 15:36:56 +0100693 &temp));
694 temp += 0xa;
695 CHECK_STATUS(ddr3_tip_bus_write
696 (dev_num, ACCESS_TYPE_UNICAST,
697 if_id, ACCESS_TYPE_UNICAST,
698 pup_id, DDR_PHY_DATA,
Chris Packham1a07d212018-05-10 13:28:29 +1200699 PBS_RX_PHY_REG(effective_cs, 5),
700 temp));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100701 DEBUG_CENTRALIZATION_ENGINE(
702 DEBUG_LEVEL_INFO,
703 ("Special: PBS:: I/F# %d , Bus# %d fix align to the right\n",
704 if_id, pup_id));
705 }
706
707 vref_window_size[if_id][pup_id] =
708 cur_end_win_min -
709 cur_start_win_max + 1;
710 DEBUG_CENTRALIZATION_ENGINE(
711 DEBUG_LEVEL_INFO,
712 ("Special: Winsize I/F# %d , Bus# %d is %d\n",
713 if_id, pup_id, vref_window_size
714 [if_id][pup_id]));
715 } /* pup */
716 } /* end of interface */
717
718 return MV_OK;
719}
720
721/*
722 * Print Centralization Result
723 */
724int ddr3_tip_print_centralization_result(u32 dev_num)
725{
726 u32 if_id = 0, bus_id = 0;
Chris Packham1a07d212018-05-10 13:28:29 +1200727 u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
728 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +0100729
Chris Packham4bf81db2018-12-03 14:26:49 +1300730 dev_num = dev_num;
731
Stefan Roese5ffceb82015-03-26 15:36:56 +0100732 printf("Centralization Results\n");
733 printf("I/F0 Result[0 - success 1-fail 2 - state_2 3 - state_3] ...\n");
734 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +1200735 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
736 for (bus_id = 0; bus_id < octets_per_if_num;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100737 bus_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +1200738 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100739 printf("%d ,\n", centralization_state[if_id][bus_id]);
740 }
741 }
742
743 return MV_OK;
744}