1 // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
3 * Copyright (C) 2019, STMicroelectronics - All Rights Reserved
13 #include <linux/bitops.h>
14 #include <linux/delay.h>
15 #include <linux/iopoll.h>
17 #include "stm32mp1_ddr_regs.h"
18 #include "stm32mp1_ddr.h"
19 #include "stm32mp1_tests.h"
21 #define MAX_DQS_PHASE_IDX _144deg
22 #define MAX_DQS_UNIT_IDX 7
26 /* Number of bytes used in this SW. ( min 1--> max 4). */
39 /* BIST Result struct */
41 /* Overall test result:
42 * 0 Fail (any bit failed) ,
43 * 1 Success (All bits success)
46 /* 1: true, all fail / 0: False, not all bits fail */
48 bool bit_i_test_result[8]; /* 0 fail / 1 success */
51 /* a struct that defines tuning parameters of a byte. */
52 struct tuning_position {
53 u8 phase; /* DQS phase */
54 u8 unit; /* DQS unit delay */
55 u32 bits_delay; /* Bits deskew in this byte */
58 /* 36deg, 54deg, 72deg, 90deg, 108deg, 126deg, 144deg */
59 const u8 dx_dll_phase[7] = {3, 2, 1, 0, 14, 13, 12};
61 static u8 BIST_error_max = 1;
62 static u32 BIST_seed = 0x1234ABCD;
64 static u8 get_nb_bytes(struct stm32mp1_ddrctl *ctl)
66 u32 data_bus = readl(&ctl->mstr) & DDRCTRL_MSTR_DATA_BUS_WIDTH_MASK;
67 u8 nb_bytes = NUM_BYTES;
70 case DDRCTRL_MSTR_DATA_BUS_WIDTH_HALF:
73 case DDRCTRL_MSTR_DATA_BUS_WIDTH_QUARTER:
83 static u8 get_nb_bank(struct stm32mp1_ddrctl *ctl)
85 /* Count bank address bits */
89 reg = readl(&ctl->addrmap1);
90 /* addrmap1.addrmap_bank_b1 */
91 val = (reg & GENMASK(5, 0)) >> 0;
94 /* addrmap1.addrmap_bank_b2 */
95 val = (reg & GENMASK(13, 8)) >> 8;
98 /* addrmap1.addrmap_bank_b3 */
99 val = (reg & GENMASK(21, 16)) >> 16;
106 static u8 get_nb_col(struct stm32mp1_ddrctl *ctl)
111 /* Count column address bits, start at 2 for b0 and b1 (fixed) */
114 reg = readl(&ctl->addrmap2);
115 /* addrmap2.addrmap_col_b2 */
116 val = (reg & GENMASK(3, 0)) >> 0;
119 /* addrmap2.addrmap_col_b3 */
120 val = (reg & GENMASK(11, 8)) >> 8;
123 /* addrmap2.addrmap_col_b4 */
124 val = (reg & GENMASK(19, 16)) >> 16;
127 /* addrmap2.addrmap_col_b5 */
128 val = (reg & GENMASK(27, 24)) >> 24;
132 reg = readl(&ctl->addrmap3);
133 /* addrmap3.addrmap_col_b6 */
134 val = (reg & GENMASK(3, 0)) >> 0;
137 /* addrmap3.addrmap_col_b7 */
138 val = (reg & GENMASK(11, 8)) >> 8;
141 /* addrmap3.addrmap_col_b8 */
142 val = (reg & GENMASK(19, 16)) >> 16;
145 /* addrmap3.addrmap_col_b9 */
146 val = (reg & GENMASK(27, 24)) >> 24;
150 reg = readl(&ctl->addrmap4);
151 /* addrmap4.addrmap_col_b10 */
152 val = (reg & GENMASK(3, 0)) >> 0;
155 /* addrmap4.addrmap_col_b11 */
156 val = (reg & GENMASK(11, 8)) >> 8;
163 static u8 get_nb_row(struct stm32mp1_ddrctl *ctl)
165 /* Count row address bits */
169 reg = readl(&ctl->addrmap5);
170 /* addrmap5.addrmap_row_b0 */
171 val = (reg & GENMASK(3, 0)) >> 0;
174 /* addrmap5.addrmap_row_b1 */
175 val = (reg & GENMASK(11, 8)) >> 8;
178 /* addrmap5.addrmap_row_b2_10 */
179 val = (reg & GENMASK(19, 16)) >> 16;
183 printf("warning: addrmap5.addrmap_row_b2_10 not supported\n");
184 /* addrmap5.addrmap_row_b11 */
185 val = (reg & GENMASK(27, 24)) >> 24;
189 reg = readl(&ctl->addrmap6);
190 /* addrmap6.addrmap_row_b12 */
191 val = (reg & GENMASK(3, 0)) >> 0;
194 /* addrmap6.addrmap_row_b13 */
195 val = (reg & GENMASK(11, 8)) >> 8;
198 /* addrmap6.addrmap_row_b14 */
199 val = (reg & GENMASK(19, 16)) >> 16;
202 /* addrmap6.addrmap_row_b15 */
203 val = (reg & GENMASK(27, 24)) >> 24;
210 static void itm_soft_reset(struct stm32mp1_ddrphy *phy)
212 stm32mp1_ddrphy_init(phy, DDRPHYC_PIR_ITMSRST);
215 /* Read DQ unit delay register and provides the retrieved value for DQS
216 * We are assuming that we have the same delay when clocking
217 * by DQS and when clocking by DQSN
219 static u8 DQ_unit_index(struct stm32mp1_ddrphy *phy, u8 byte, u8 bit)
222 u32 addr = DXNDQTR(phy, byte);
224 /* We are assuming that we have the same delay when clocking by DQS
225 * and when clocking by DQSN : use only the low bits
227 index = (readl(addr) >> DDRPHYC_DXNDQTR_DQDLY_SHIFT(bit))
228 & DDRPHYC_DXNDQTR_DQDLY_LOW_MASK;
230 pr_debug("%s: [%x]: %x => DQ unit index = %x\n",
231 __func__, addr, readl(addr), index);
236 /* Sets the DQS phase delay for a byte lane.
237 *phase delay is specified by giving the index of the desired delay
238 * in the dx_dll_phase array.
240 static void DQS_phase_delay(struct stm32mp1_ddrphy *phy, u8 byte, u8 phase_idx)
244 /* Write DXNDLLCR.SDPHASE = dx_dll_phase(phase_index); */
245 sdphase_val = dx_dll_phase[phase_idx];
246 clrsetbits_le32(DXNDLLCR(phy, byte),
247 DDRPHYC_DXNDLLCR_SDPHASE_MASK,
248 sdphase_val << DDRPHYC_DXNDLLCR_SDPHASE_SHIFT);
251 /* Sets the DQS unit delay for a byte lane.
252 * unit delay is specified by giving the index of the desired delay
253 * for dgsdly and dqsndly (same value).
255 static void DQS_unit_delay(struct stm32mp1_ddrphy *phy,
256 u8 byte, u8 unit_dly_idx)
258 /* Write the same value in DXNDQSTR.DQSDLY and DXNDQSTR.DQSNDLY */
259 clrsetbits_le32(DXNDQSTR(phy, byte),
260 DDRPHYC_DXNDQSTR_DQSDLY_MASK |
261 DDRPHYC_DXNDQSTR_DQSNDLY_MASK,
262 (unit_dly_idx << DDRPHYC_DXNDQSTR_DQSDLY_SHIFT) |
263 (unit_dly_idx << DDRPHYC_DXNDQSTR_DQSNDLY_SHIFT));
265 /* After changing this value, an ITM soft reset (PIR.ITMSRST=1,
266 * plus PIR.INIT=1) must be issued.
268 stm32mp1_ddrphy_init(phy, DDRPHYC_PIR_ITMSRST);
271 /* Sets the DQ unit delay for a bit line in particular byte lane.
272 * unit delay is specified by giving the desired delay
274 static void set_DQ_unit_delay(struct stm32mp1_ddrphy *phy,
278 u8 dq_bit_delay_val = dq_delay_index | (dq_delay_index << 2);
280 /* same value on delay for clock DQ an DQS_b */
281 clrsetbits_le32(DXNDQTR(phy, byte),
282 DDRPHYC_DXNDQTR_DQDLY_MASK
283 << DDRPHYC_DXNDQTR_DQDLY_SHIFT(bit),
284 dq_bit_delay_val << DDRPHYC_DXNDQTR_DQDLY_SHIFT(bit));
287 static void set_r0dgsl_delay(struct stm32mp1_ddrphy *phy,
288 u8 byte, u8 r0dgsl_idx)
290 clrsetbits_le32(DXNDQSTR(phy, byte),
291 DDRPHYC_DXNDQSTR_R0DGSL_MASK,
292 r0dgsl_idx << DDRPHYC_DXNDQSTR_R0DGSL_SHIFT);
295 static void set_r0dgps_delay(struct stm32mp1_ddrphy *phy,
296 u8 byte, u8 r0dgps_idx)
298 clrsetbits_le32(DXNDQSTR(phy, byte),
299 DDRPHYC_DXNDQSTR_R0DGPS_MASK,
300 r0dgps_idx << DDRPHYC_DXNDQSTR_R0DGPS_SHIFT);
303 /* Basic BIST configuration for data lane tests. */
304 static void config_BIST(struct stm32mp1_ddrctl *ctl,
305 struct stm32mp1_ddrphy *phy)
307 u8 nb_bank = get_nb_bank(ctl);
308 u8 nb_row = get_nb_row(ctl);
309 u8 nb_col = get_nb_col(ctl);
311 /* Selects the SDRAM bank address to be used during BIST. */
313 /* Selects the SDRAM row address to be used during BIST. */
315 /* Selects the SDRAM column address to be used during BIST. */
317 /* Selects the value by which the SDRAM address is incremented
318 * for each write/read access.
320 u32 bainc = 0x00000008;
321 /* Specifies the maximum SDRAM rank to be used during BIST.
322 * The default value is set to maximum ranks minus 1.
323 * must be 0 with single rank
326 /* Selects the SDRAM rank to be used during BIST.
327 * must be 0 with single rank
331 /* Specifies the maximum SDRAM bank address to be used during
332 * BIST before the address & increments to the next rank.
334 u32 bmbank = (1 << nb_bank) - 1;
335 /* Specifies the maximum SDRAM row address to be used during
336 * BIST before the address & increments to the next bank.
338 u32 bmrow = (1 << nb_row) - 1;
339 /* Specifies the maximum SDRAM column address to be used during
340 * BIST before the address & increments to the next row.
342 u32 bmcol = (1 << nb_col) - 1;
344 u32 bmode_conf = 0x00000001; /* DRam mode */
345 u32 bdxen_conf = 0x00000001; /* BIST on Data byte */
346 u32 bdpat_conf = 0x00000002; /* Select LFSR pattern */
348 /*Setup BIST for DRAM mode, and LFSR-random data pattern.*/
349 /*Write BISTRR.BMODE = 1?b1;*/
350 /*Write BISTRR.BDXEN = 1?b1;*/
351 /*Write BISTRR.BDPAT = 2?b10;*/
354 writel(0x3, &phy->bistrr);
356 writel((bmode_conf << 3) | (bdxen_conf << 14) | (bdpat_conf << 17),
359 /*Setup BIST Word Count*/
360 /*Write BISTWCR.BWCNT = 16?b0008;*/
361 writel(0x00000200, &phy->bistwcr); /* A multiple of BL/2 */
363 writel(bcol | (brow << 12) | (bbank << 28), &phy->bistar0);
364 writel(brank | (bmrank << 2) | (bainc << 4), &phy->bistar1);
365 writel(bmcol | (bmrow << 12) | (bmbank << 28), &phy->bistar2);
368 /* Select the Byte lane to be tested by BIST. */
369 static void BIST_datx8_sel(struct stm32mp1_ddrphy *phy, u8 datx8)
371 clrsetbits_le32(&phy->bistrr,
372 DDRPHYC_BISTRR_BDXSEL_MASK,
373 datx8 << DDRPHYC_BISTRR_BDXSEL_SHIFT);
375 /*(For example, selecting Byte Lane 3, BISTRR.BDXSEL = 4?b0011)*/
376 /* Write BISTRR.BDXSEL = datx8; */
379 /* Perform BIST Write_Read test on a byte lane and return test result. */
380 static void BIST_test(struct stm32mp1_ddrphy *phy, u8 byte,
381 struct BIST_result *bist)
383 bool result = true; /* BIST_SUCCESS */
389 bist->test_result = true;
394 /*Perform BIST Reset*/
395 /* Write BISTRR.BINST = 3?b011; */
396 clrsetbits_le32(&phy->bistrr,
401 /* Write BISTLSR.SEED = 32'h1234ABCD; */
403 writel(BIST_seed, &phy->bistlsr);
405 writel(rand(), &phy->bistlsr);
407 /* some delay to reset BIST */
411 clrsetbits_le32(&phy->bistrr,
414 /* Write BISTRR.BINST = 3?b001; */
416 /* poll on BISTGSR.BDONE and wait max 1000 us */
417 ret = readl_poll_timeout(&phy->bistgsr, val,
418 val & DDRPHYC_BISTGSR_BDDONE, 1000);
421 printf("warning: BIST timeout\n");
422 result = false; /* BIST_FAIL; */
423 /*Perform BIST Stop */
424 clrsetbits_le32(&phy->bistrr, 0x00000007, 0x00000002);
426 /*Check if received correct number of words*/
427 /* if (Read BISTWCSR.DXWCNT = Read BISTWCR.BWCNT) */
428 if (((readl(&phy->bistwcsr)) >> DDRPHYC_BISTWCSR_DXWCNT_SHIFT)
429 == readl(&phy->bistwcr)) {
430 /*Determine if there is a data comparison error*/
431 /* if (Read BISTGSR.BDXERR = 1?b0) */
432 if (readl(&phy->bistgsr) & DDRPHYC_BISTGSR_BDXERR)
433 result = false; /* BIST_FAIL; */
435 result = true; /* BIST_SUCCESS; */
437 result = false; /* BIST_FAIL; */
441 /* loop while success */
443 if (result && cnt != 1000)
449 if (error < BIST_error_max) {
452 bist->test_result = true;
454 bist->test_result = false;
458 /* After running the deskew algo, this function applies the new DQ delays
459 * by reading them from the array "deskew_delay"and writing in PHY registers.
460 * The bits that are not deskewed parfectly (too much skew on them,
461 * or data eye very wide) are marked in the array deskew_non_converge.
463 static void apply_deskew_results(struct stm32mp1_ddrphy *phy, u8 byte,
464 u8 deskew_delay[NUM_BYTES][8],
465 u8 deskew_non_converge[NUM_BYTES][8])
470 for (bit_i = 0; bit_i < 8; bit_i++) {
471 set_DQ_unit_delay(phy, byte, bit_i, deskew_delay[byte][bit_i]);
472 index = DQ_unit_index(phy, byte, bit_i);
473 pr_debug("Byte %d ; bit %d : The new DQ delay (%d) index=%d [delta=%d, 3 is the default]",
474 byte, bit_i, deskew_delay[byte][bit_i],
476 printf("Byte %d, bit %d, DQ delay = %d",
477 byte, bit_i, deskew_delay[byte][bit_i]);
478 if (deskew_non_converge[byte][bit_i] == 1)
479 pr_debug(" - not converged : still more skew");
484 /* DQ Bit de-skew algorithm.
485 * Deskews data lines as much as possible.
486 * 1. Add delay to DQS line until finding the failure
487 * (normally a hold time violation)
488 * 2. Reduce DQS line by small steps until finding the very first time
489 * we go back to "Pass" condition.
490 * 3. For each DQ line, Reduce DQ delay until finding the very first failure
491 * (normally a hold time fail)
492 * 4. When all bits are at their first failure delay, we can consider them
494 * Handle conrer situation (Can't find Pass-fail, or fail-pass transitions
496 * TODO Provide a return Status. Improve doc
498 static enum test_result bit_deskew(struct stm32mp1_ddrctl *ctl,
499 struct stm32mp1_ddrphy *phy, char *string)
501 /* New DQ delay value (index), set during Deskew algo */
502 u8 deskew_delay[NUM_BYTES][8];
503 /*If there is still skew on a bit, mark this bit. */
504 u8 deskew_non_converge[NUM_BYTES][8];
505 struct BIST_result result;
506 s8 dqs_unit_delay_index = 0;
510 s8 bit_i_delay_index = 0;
512 struct tuning_position last_right_ok;
516 u8 nb_bytes = get_nb_bytes(ctl);
517 /* u8 last_pass_dqs_unit = 0; */
519 memset(deskew_delay, 0, sizeof(deskew_delay));
520 memset(deskew_non_converge, 0, sizeof(deskew_non_converge));
522 /*Disable DQS Drift Compensation*/
523 clrbits_le32(&phy->pgcr, DDRPHYC_PGCR_DFTCMP);
524 /*Disable all bytes*/
525 /* Disable automatic power down of DLL and IOs when disabling
526 * a byte (To avoid having to add programming and delay
527 * for a DLL re-lock when later re-enabling a disabled Byte Lane)
529 clrbits_le32(&phy->pgcr, DDRPHYC_PGCR_PDDISDX);
531 /* Disable all data bytes */
532 clrbits_le32(&phy->dx0gcr, DDRPHYC_DXNGCR_DXEN);
533 clrbits_le32(&phy->dx1gcr, DDRPHYC_DXNGCR_DXEN);
534 clrbits_le32(&phy->dx2gcr, DDRPHYC_DXNGCR_DXEN);
535 clrbits_le32(&phy->dx3gcr, DDRPHYC_DXNGCR_DXEN);
537 /* Config the BIST block */
538 config_BIST(ctl, phy);
539 pr_debug("BIST Config done.\n");
541 /* Train each byte */
542 for (datx8 = 0; datx8 < nb_bytes; datx8++) {
544 sprintf(string, "interrupted at byte %d/%d, error=%d",
545 datx8 + 1, nb_bytes, error);
548 pr_debug("\n======================\n");
549 pr_debug("Start deskew byte %d .\n", datx8);
550 pr_debug("======================\n");
551 /* Enable Byte (DXNGCR, bit DXEN) */
552 setbits_le32(DXNGCR(phy, datx8), DDRPHYC_DXNGCR_DXEN);
554 /* Select the byte lane for comparison of read data */
555 BIST_datx8_sel(phy, datx8);
557 /* Set all DQDLYn to maximum value. All bits within the byte
558 * will be delayed with DQSTR = 2 instead of max = 3
559 * to avoid inter bits fail influence
561 writel(0xAAAAAAAA, DXNDQTR(phy, datx8));
563 /* Set the DQS phase delay to 90 DEG (default).
564 * What is defined here is the index of the desired config
565 * in the PHASE array.
569 /* Set DQS unit delay to the max value. */
570 dqs_unit_delay_index = MAX_DQS_UNIT_IDX;
571 DQS_unit_delay(phy, datx8, dqs_unit_delay_index);
572 DQS_phase_delay(phy, datx8, phase_idx);
574 /* Issue a DLL soft reset */
575 clrbits_le32(DXNDLLCR(phy, datx8), DDRPHYC_DXNDLLCR_DLLSRST);
576 setbits_le32(DXNDLLCR(phy, datx8), DDRPHYC_DXNDLLCR_DLLSRST);
578 /* Test this typical init condition */
579 BIST_test(phy, datx8, &result);
580 success = result.test_result;
582 /* If the test pass in this typical condition,
583 * start the algo with it.
584 * Else, look for Pass init condition
587 pr_debug("Fail at init condtion. Let's look for a good init condition.\n");
588 success = 0; /* init */
589 /* Make sure we start with a PASS condition before
590 * looking for a fail condition.
591 * Find the first PASS PHASE condition
594 /* escape if we find a PASS */
595 pr_debug("increase Phase idx\n");
596 while (!success && (phase_idx <= MAX_DQS_PHASE_IDX)) {
597 DQS_phase_delay(phy, datx8, phase_idx);
598 BIST_test(phy, datx8, &result);
599 success = result.test_result;
602 /* if ended with success
603 * ==>> Restore the fist success condition
606 phase_idx--; /* because it ended with ++ */
609 sprintf(string, "interrupted at byte %d/%d, error=%d",
610 datx8 + 1, nb_bytes, error);
613 /* We couldn't find a successful condition, its seems
614 * we have hold violation, lets try reduce DQS_unit Delay
617 /* We couldn't find a successful condition, its seems
618 * we have hold violation, lets try reduce DQS_unit
621 pr_debug("Still fail. Try decrease DQS Unit delay\n");
624 dqs_unit_delay_index = 0;
625 DQS_phase_delay(phy, datx8, phase_idx);
627 /* escape if we find a PASS */
629 (dqs_unit_delay_index <=
631 DQS_unit_delay(phy, datx8,
632 dqs_unit_delay_index);
633 BIST_test(phy, datx8, &result);
634 success = result.test_result;
635 dqs_unit_delay_index++;
638 /* Restore the first success condition*/
639 dqs_unit_delay_index--;
640 /* last_pass_dqs_unit = dqs_unit_delay_index;*/
641 DQS_unit_delay(phy, datx8,
642 dqs_unit_delay_index);
644 /* No need to continue,
645 * there is no pass region.
651 /* There is an initial PASS condition
652 * Look for the first failing condition by PHASE stepping.
653 * This part of the algo can finish without converging.
656 printf("Result: Failed ");
657 printf("[Cannot Deskew lines, ");
658 printf("there is no PASS region]\n");
663 sprintf(string, "interrupted at byte %d/%d, error=%d",
664 datx8 + 1, nb_bytes, error);
668 pr_debug("there is a pass region for phase idx %d\n",
670 pr_debug("Step1: Find the first failing condition\n");
671 /* Look for the first failing condition by PHASE stepping.
672 * This part of the algo can finish without converging.
675 /* escape if we find a fail (hold time violation)
676 * condition at any bit or if out of delay range.
678 while (success && (phase_idx <= MAX_DQS_PHASE_IDX)) {
679 DQS_phase_delay(phy, datx8, phase_idx);
680 BIST_test(phy, datx8, &result);
681 success = result.test_result;
685 sprintf(string, "interrupted at byte %d/%d, error=%d",
686 datx8 + 1, nb_bytes, error);
690 /* if the loop ended with a failing condition at any bit,
691 * lets look for the first previous success condition by unit
692 * stepping (minimal delay)
695 pr_debug("Fail region (PHASE) found phase idx %d\n",
697 pr_debug("Let's look for first success by DQS Unit steps\n");
698 /* This part, the algo always converge */
701 /* escape if we find a success condition
702 * or if out of delay range.
704 while (!success && dqs_unit_delay_index >= 0) {
705 DQS_unit_delay(phy, datx8,
706 dqs_unit_delay_index);
707 BIST_test(phy, datx8, &result);
708 success = result.test_result;
709 dqs_unit_delay_index--;
711 /* if the loop ended with a success condition,
712 * the last delay Right OK (before hold violation)
713 * condition is then defined as following:
716 /* Hold the dely parameters of the the last
717 * delay Right OK condition.
718 * -1 to get back to current condition
720 last_right_ok.phase = phase_idx;
721 /*+1 to get back to current condition */
722 last_right_ok.unit = dqs_unit_delay_index + 1;
723 last_right_ok.bits_delay = 0xFFFFFFFF;
724 pr_debug("Found %d\n", dqs_unit_delay_index);
726 /* the last OK condition is then with the
727 * previous phase_idx.
728 * -2 instead of -1 because at the last
729 * iteration of the while(),
730 * we incremented phase_idx
732 last_right_ok.phase = phase_idx - 1;
733 /* Nominal+1. Because we want the previous
734 * delay after reducing the phase delay.
736 last_right_ok.unit = 1;
737 last_right_ok.bits_delay = 0xFFFFFFFF;
738 pr_debug("Not Found : try previous phase %d\n",
741 DQS_phase_delay(phy, datx8, phase_idx - 1);
742 dqs_unit_delay_index = 0;
745 (dqs_unit_delay_index <
747 DQS_unit_delay(phy, datx8,
748 dqs_unit_delay_index);
749 BIST_test(phy, datx8, &result);
750 success = result.test_result;
751 dqs_unit_delay_index++;
752 pr_debug("dqs_unit_delay_index = %d, result = %d\n",
753 dqs_unit_delay_index, success);
758 dqs_unit_delay_index - 1;
760 last_right_ok.unit = 0;
761 pr_debug("ERROR: failed region not FOUND");
765 /* we can't find a failing condition at all bits
766 * ==> Just hold the last test condition
767 * (the max DQS delay)
768 * which is the most likely,
769 * the closest to a hold violation
770 * If we can't find a Fail condition after
771 * the Pass region, stick at this position
772 * In order to have max chances to find a fail
773 * when reducing DQ delays.
775 last_right_ok.phase = MAX_DQS_PHASE_IDX;
776 last_right_ok.unit = MAX_DQS_UNIT_IDX;
777 last_right_ok.bits_delay = 0xFFFFFFFF;
778 pr_debug("Can't find the a fail condition\n");
782 * if we arrive at this stage, it means that we found the last
783 * Right OK condition (by tweeking the DQS delay). Or we simply
784 * pushed DQS delay to the max
785 * This means that by reducing the delay on some DQ bits,
786 * we should find a failing condition.
788 printf("Byte %d, DQS unit = %d, phase = %d\n",
789 datx8, last_right_ok.unit, last_right_ok.phase);
790 pr_debug("Step2, unit = %d, phase = %d, bits delay=%x\n",
791 last_right_ok.unit, last_right_ok.phase,
792 last_right_ok.bits_delay);
794 /* Restore the last_right_ok condtion. */
795 DQS_unit_delay(phy, datx8, last_right_ok.unit);
796 DQS_phase_delay(phy, datx8, last_right_ok.phase);
797 writel(last_right_ok.bits_delay, DXNDQTR(phy, datx8));
800 * reduce delay on each bit, and perform a write/read test
801 * and stop at the very first time it fails.
802 * the goal is the find the first failing condition
804 * When we achieve this condition< for all the bits,
805 * we are sure they are aligned (+/- step resolution)
808 for (bit_i = 0; bit_i < 8; bit_i++) {
811 "interrupted at byte %d/%d, error=%d",
812 datx8 + 1, nb_bytes, error);
815 pr_debug("deskewing bit %d:\n", bit_i);
816 success = 1; /* init */
817 /* Set all DQDLYn to maximum value.
818 * Only bit_i will be down-delayed
819 * ==> if we have a fail, it will be definitely
822 writel(0xFFFFFFFF, DXNDQTR(phy, datx8));
823 /* Arriving at this stage,
824 * we have a success condition with delay = 3;
826 bit_i_delay_index = 3;
828 /* escape if bit delay is out of range or
831 while ((bit_i_delay_index >= 0) && success) {
832 set_DQ_unit_delay(phy, datx8,
835 BIST_test(phy, datx8, &result);
836 success = result.test_result;
840 /* if escape with a fail condition
841 * ==> save this position for bit_i
844 /* save the delay position.
845 * Add 1 because the while loop ended with a --,
846 * and that we need to hold the last success
849 deskew_delay[datx8][bit_i] =
850 bit_i_delay_index + 2;
851 if (deskew_delay[datx8][bit_i] > 3)
852 deskew_delay[datx8][bit_i] = 3;
854 /* A flag that states we found at least a fail
858 pr_debug("Fail found on bit %d, for delay = %d => deskew[%d][%d] = %d\n",
859 bit_i, bit_i_delay_index + 1,
861 deskew_delay[datx8][bit_i]);
863 /* if we can find a success condition by
864 * back-delaying this bit, just set the delay
865 * to 0 (the best deskew
866 * possible) and mark the bit.
868 deskew_delay[datx8][bit_i] = 0;
869 /* set a flag that will be used later
872 deskew_non_converge[datx8][bit_i] = 1;
873 pr_debug("Fail not found on bit %d => deskew[%d][%d] = %d\n",
875 deskew_delay[datx8][bit_i]);
878 pr_debug("**********byte %d tuning complete************\n",
880 /* If we can't find any failure by back delaying DQ lines,
881 * hold the default values
884 for (bit_i = 0; bit_i < 8; bit_i++)
885 deskew_delay[datx8][bit_i] = 0;
886 pr_debug("The Deskew algorithm can't converge, there is too much margin in your design. Good job!\n");
889 apply_deskew_results(phy, datx8, deskew_delay,
890 deskew_non_converge);
891 /* Restore nominal value for DQS delay */
892 DQS_phase_delay(phy, datx8, 3);
893 DQS_unit_delay(phy, datx8, 3);
894 /* disable byte after byte bits deskew */
895 clrbits_le32(DXNGCR(phy, datx8), DDRPHYC_DXNGCR_DXEN);
896 } /* end of byte deskew */
898 /* re-enable all data bytes */
899 setbits_le32(&phy->dx0gcr, DDRPHYC_DXNGCR_DXEN);
900 setbits_le32(&phy->dx1gcr, DDRPHYC_DXNGCR_DXEN);
901 setbits_le32(&phy->dx2gcr, DDRPHYC_DXNGCR_DXEN);
902 setbits_le32(&phy->dx3gcr, DDRPHYC_DXNGCR_DXEN);
905 sprintf(string, "error = %d", error);
912 /* Trim DQS timings and set it in the centre of data eye.
913 * Look for a PPPPF region, then look for a FPPP region and finally select
914 * the mid of the FPPPPPF region
916 static enum test_result eye_training(struct stm32mp1_ddrctl *ctl,
917 struct stm32mp1_ddrphy *phy, char *string)
919 /*Stores the DQS trim values (PHASE index, unit index) */
920 u8 eye_training_val[NUM_BYTES][2];
922 struct BIST_result result;
923 s8 dqs_unit_delay_index = 0;
925 s8 dqs_unit_delay_index_pass = 0;
926 s8 phase_idx_pass = 0;
928 u8 left_phase_bound_found, right_phase_bound_found;
929 u8 left_unit_bound_found, right_unit_bound_found;
930 u8 left_bound_found, right_bound_found;
931 struct tuning_position left_bound, right_bound;
933 u8 nb_bytes = get_nb_bytes(ctl);
935 /*Disable DQS Drift Compensation*/
936 clrbits_le32(&phy->pgcr, DDRPHYC_PGCR_DFTCMP);
937 /*Disable all bytes*/
938 /* Disable automatic power down of DLL and IOs when disabling a byte
939 * (To avoid having to add programming and delay
940 * for a DLL re-lock when later re-enabling a disabled Byte Lane)
942 clrbits_le32(&phy->pgcr, DDRPHYC_PGCR_PDDISDX);
944 /*Disable all data bytes */
945 clrbits_le32(&phy->dx0gcr, DDRPHYC_DXNGCR_DXEN);
946 clrbits_le32(&phy->dx1gcr, DDRPHYC_DXNGCR_DXEN);
947 clrbits_le32(&phy->dx2gcr, DDRPHYC_DXNGCR_DXEN);
948 clrbits_le32(&phy->dx3gcr, DDRPHYC_DXNGCR_DXEN);
950 /* Config the BIST block */
951 config_BIST(ctl, phy);
953 for (byte = 0; byte < nb_bytes; byte++) {
955 sprintf(string, "interrupted at byte %d/%d, error=%d",
956 byte + 1, nb_bytes, error);
959 right_bound.phase = 0;
960 right_bound.unit = 0;
962 left_bound.phase = 0;
965 left_phase_bound_found = 0;
966 right_phase_bound_found = 0;
968 left_unit_bound_found = 0;
969 right_unit_bound_found = 0;
971 left_bound_found = 0;
972 right_bound_found = 0;
974 /* Enable Byte (DXNGCR, bit DXEN) */
975 setbits_le32(DXNGCR(phy, byte), DDRPHYC_DXNGCR_DXEN);
977 /* Select the byte lane for comparison of read data */
978 BIST_datx8_sel(phy, byte);
980 /* Set DQS phase delay to the nominal value. */
982 phase_idx_pass = phase_idx;
984 /* Set DQS unit delay to the nominal value. */
985 dqs_unit_delay_index = 3;
986 dqs_unit_delay_index_pass = dqs_unit_delay_index;
989 pr_debug("STEP0: Find Init delay\n");
990 /* STEP0: Find Init delay: a delay that put the system
991 * in a "Pass" condition then (TODO) update
992 * dqs_unit_delay_index_pass & phase_idx_pass
994 DQS_unit_delay(phy, byte, dqs_unit_delay_index);
995 DQS_phase_delay(phy, byte, phase_idx);
996 BIST_test(phy, byte, &result);
997 success = result.test_result;
998 /* If we have a fail in the nominal condition */
1000 /* Look at the left */
1001 while (phase_idx >= 0 && !success) {
1003 DQS_phase_delay(phy, byte, phase_idx);
1004 BIST_test(phy, byte, &result);
1005 success = result.test_result;
1009 /* if we can't find pass condition,
1010 * then look at the right
1013 while (phase_idx <= MAX_DQS_PHASE_IDX &&
1016 DQS_phase_delay(phy, byte,
1018 BIST_test(phy, byte, &result);
1019 success = result.test_result;
1022 /* save the pass condition */
1024 phase_idx_pass = phase_idx;
1026 printf("Result: Failed ");
1027 printf("[Cannot DQS timings, ");
1028 printf("there is no PASS region]\n");
1034 sprintf(string, "interrupted at byte %d/%d, error=%d",
1035 byte + 1, nb_bytes, error);
1038 pr_debug("STEP1: Find LEFT PHASE DQS Bound\n");
1039 /* STEP1: Find LEFT PHASE DQS Bound */
1040 while ((phase_idx >= 0) &&
1041 (phase_idx <= MAX_DQS_PHASE_IDX) &&
1042 !left_phase_bound_found) {
1043 DQS_unit_delay(phy, byte,
1044 dqs_unit_delay_index);
1045 DQS_phase_delay(phy, byte,
1047 BIST_test(phy, byte, &result);
1048 success = result.test_result;
1050 /*TODO: Manage the case were at the beginning
1051 * there is already a fail
1054 /* the last pass condition */
1055 left_bound.phase = ++phase_idx;
1056 left_phase_bound_found = 1;
1057 } else if (success) {
1061 if (!left_phase_bound_found) {
1062 left_bound.phase = 0;
1065 /* If not found, lets take 0 */
1068 sprintf(string, "interrupted at byte %d/%d, error=%d",
1069 byte + 1, nb_bytes, error);
1072 pr_debug("STEP2: Find UNIT left bound\n");
1073 /* STEP2: Find UNIT left bound */
1074 while ((dqs_unit_delay_index >= 0) &&
1075 !left_unit_bound_found) {
1076 DQS_unit_delay(phy, byte,
1077 dqs_unit_delay_index);
1078 DQS_phase_delay(phy, byte, phase_idx);
1079 BIST_test(phy, byte, &result);
1080 success = result.test_result;
1083 ++dqs_unit_delay_index;
1084 left_unit_bound_found = 1;
1085 left_bound_found = 1;
1086 } else if (success) {
1087 dqs_unit_delay_index--;
1091 /* If not found, lets take 0 */
1092 if (!left_unit_bound_found)
1093 left_bound.unit = 0;
1096 sprintf(string, "interrupted at byte %d/%d, error=%d",
1097 byte + 1, nb_bytes, error);
1100 pr_debug("STEP3: Find PHase right bound\n");
1101 /* STEP3: Find PHase right bound, start with "pass"
1105 /* Set DQS phase delay to the pass value. */
1106 phase_idx = phase_idx_pass;
1108 /* Set DQS unit delay to the pass value. */
1109 dqs_unit_delay_index = dqs_unit_delay_index_pass;
1111 while ((phase_idx <= MAX_DQS_PHASE_IDX) &&
1112 !right_phase_bound_found) {
1113 DQS_unit_delay(phy, byte,
1114 dqs_unit_delay_index);
1115 DQS_phase_delay(phy, byte, phase_idx);
1116 BIST_test(phy, byte, &result);
1117 success = result.test_result;
1119 /* the last pass condition */
1120 right_bound.phase = --phase_idx;
1121 right_phase_bound_found = 1;
1122 } else if (success) {
1127 /* If not found, lets take the max value */
1128 if (!right_phase_bound_found) {
1129 right_bound.phase = MAX_DQS_PHASE_IDX;
1130 phase_idx = MAX_DQS_PHASE_IDX;
1134 sprintf(string, "interrupted at byte %d/%d, error=%d",
1135 byte + 1, nb_bytes, error);
1138 pr_debug("STEP4: Find UNIT right bound\n");
1139 /* STEP4: Find UNIT right bound */
1140 while ((dqs_unit_delay_index <= MAX_DQS_UNIT_IDX) &&
1141 !right_unit_bound_found) {
1142 DQS_unit_delay(phy, byte,
1143 dqs_unit_delay_index);
1144 DQS_phase_delay(phy, byte, phase_idx);
1145 BIST_test(phy, byte, &result);
1146 success = result.test_result;
1149 --dqs_unit_delay_index;
1150 right_unit_bound_found = 1;
1151 right_bound_found = 1;
1152 } else if (success) {
1153 dqs_unit_delay_index++;
1156 /* If not found, lets take the max value */
1157 if (!right_unit_bound_found)
1158 right_bound.unit = MAX_DQS_UNIT_IDX;
1160 /* If we found a regular FAil Pass FAil pattern
1162 * OR PPPPPFF Or FFPPPPP
1165 if (left_bound_found || right_bound_found) {
1166 eye_training_val[byte][0] = (right_bound.phase +
1167 left_bound.phase) / 2;
1168 eye_training_val[byte][1] = (right_bound.unit +
1169 left_bound.unit) / 2;
1171 /* If we already lost 1/2PHASE Tuning,
1172 * let's try to recover by ++ on unit
1174 if (((right_bound.phase + left_bound.phase) % 2 == 1) &&
1175 eye_training_val[byte][1] != MAX_DQS_UNIT_IDX)
1176 eye_training_val[byte][1]++;
1177 pr_debug("** found phase : %d - %d & unit %d - %d\n",
1178 right_bound.phase, left_bound.phase,
1179 right_bound.unit, left_bound.unit);
1180 pr_debug("** calculating mid region: phase: %d unit: %d (nominal is 3)\n",
1181 eye_training_val[byte][0],
1182 eye_training_val[byte][1]);
1184 /* PPPPPPPPPP, we're already good.
1185 * Set nominal values.
1187 eye_training_val[byte][0] = 3;
1188 eye_training_val[byte][1] = 3;
1190 DQS_phase_delay(phy, byte, eye_training_val[byte][0]);
1191 DQS_unit_delay(phy, byte, eye_training_val[byte][1]);
1193 printf("Byte %d, DQS unit = %d, phase = %d\n",
1195 eye_training_val[byte][1],
1196 eye_training_val[byte][0]);
1200 sprintf(string, "error = %d", error);
1207 static void display_reg_results(struct stm32mp1_ddrphy *phy, u8 byte)
1211 printf("Byte %d Dekew result, bit0 delay, bit1 delay...bit8 delay\n ",
1214 for (i = 0; i < 8; i++)
1215 printf("%d ", DQ_unit_index(phy, byte, i));
1218 printf("dxndllcr: [%08x] val:%08x\n",
1219 DXNDLLCR(phy, byte),
1220 readl(DXNDLLCR(phy, byte)));
1221 printf("dxnqdstr: [%08x] val:%08x\n",
1222 DXNDQSTR(phy, byte),
1223 readl(DXNDQSTR(phy, byte)));
1224 printf("dxndqtr: [%08x] val:%08x\n",
1226 readl(DXNDQTR(phy, byte)));
1229 /* analyse the dgs gating log table, and determine the midpoint.*/
1230 static u8 set_midpoint_read_dqs_gating(struct stm32mp1_ddrphy *phy, u8 byte,
1231 u8 dqs_gating[NUM_BYTES]
1235 /* stores the dqs gate values (gsl index, gps index) */
1236 u8 dqs_gate_values[NUM_BYTES][2];
1237 u8 gsl_idx, gps_idx = 0;
1238 u8 left_bound_idx[2] = {0, 0};
1239 u8 right_bound_idx[2] = {0, 0};
1240 u8 left_bound_found = 0;
1241 u8 right_bound_found = 0;
1242 u8 intermittent = 0;
1245 for (gsl_idx = 0; gsl_idx <= MAX_GSL_IDX; gsl_idx++) {
1246 for (gps_idx = 0; gps_idx <= MAX_GPS_IDX; gps_idx++) {
1247 value = dqs_gating[byte][gsl_idx][gps_idx];
1248 if (value == 1 && left_bound_found == 0) {
1249 left_bound_idx[0] = gsl_idx;
1250 left_bound_idx[1] = gps_idx;
1251 left_bound_found = 1;
1252 } else if (value == 0 &&
1253 left_bound_found == 1 &&
1254 !right_bound_found) {
1256 right_bound_idx[0] = gsl_idx - 1;
1257 right_bound_idx[1] = MAX_GPS_IDX;
1259 right_bound_idx[0] = gsl_idx;
1260 right_bound_idx[1] = gps_idx - 1;
1262 right_bound_found = 1;
1263 } else if (value == 1 &&
1264 right_bound_found == 1) {
1270 /* if only ppppppp is found, there is no mid region. */
1271 if (left_bound_idx[0] == 0 && left_bound_idx[1] == 0 &&
1272 right_bound_idx[0] == 0 && right_bound_idx[1] == 0)
1275 /*if we found a regular fail pass fail pattern ffppppppff
1276 * or pppppff or ffppppp
1278 if (!intermittent) {
1279 /*if we found a regular fail pass fail pattern ffppppppff
1280 * or pppppff or ffppppp
1282 if (left_bound_found || right_bound_found) {
1283 pr_debug("idx0(%d): %d %d idx1(%d) : %d %d\n",
1285 right_bound_idx[0], left_bound_idx[0],
1287 right_bound_idx[1], left_bound_idx[1]);
1288 dqs_gate_values[byte][0] =
1289 (right_bound_idx[0] + left_bound_idx[0]) / 2;
1290 dqs_gate_values[byte][1] =
1291 (right_bound_idx[1] + left_bound_idx[1]) / 2;
1292 /* if we already lost 1/2gsl tuning,
1293 * let's try to recover by ++ on gps
1295 if (((right_bound_idx[0] +
1296 left_bound_idx[0]) % 2 == 1) &&
1297 dqs_gate_values[byte][1] != MAX_GPS_IDX)
1298 dqs_gate_values[byte][1]++;
1299 /* if we already lost 1/2gsl tuning and gps is on max*/
1300 else if (((right_bound_idx[0] +
1301 left_bound_idx[0]) % 2 == 1) &&
1302 dqs_gate_values[byte][1] == MAX_GPS_IDX) {
1303 dqs_gate_values[byte][1] = 0;
1304 dqs_gate_values[byte][0]++;
1306 /* if we have gsl left and write limit too close
1309 if (((right_bound_idx[0] - left_bound_idx[0]) == 1)) {
1310 dqs_gate_values[byte][1] = (left_bound_idx[1] +
1311 right_bound_idx[1] +
1313 if (dqs_gate_values[byte][1] >= 4) {
1314 dqs_gate_values[byte][0] =
1316 dqs_gate_values[byte][1] -= 4;
1318 dqs_gate_values[byte][0] =
1322 pr_debug("*******calculating mid region: system latency: %d phase: %d********\n",
1323 dqs_gate_values[byte][0],
1324 dqs_gate_values[byte][1]);
1325 pr_debug("*******the nominal values were system latency: 0 phase: 2*******\n");
1328 /* if intermitant, restore defaut values */
1329 pr_debug("dqs gating:no regular fail/pass/fail found. defaults values restored.\n");
1330 dqs_gate_values[byte][0] = 0;
1331 dqs_gate_values[byte][1] = 2;
1333 set_r0dgsl_delay(phy, byte, dqs_gate_values[byte][0]);
1334 set_r0dgps_delay(phy, byte, dqs_gate_values[byte][1]);
1335 printf("Byte %d, R0DGSL = %d, R0DGPS = %d\n",
1336 byte, dqs_gate_values[byte][0], dqs_gate_values[byte][1]);
1338 /* return 0 if intermittent or if both left_bound
1339 * and right_bound are not found
1341 return !(intermittent || (left_bound_found && right_bound_found));
1344 static enum test_result read_dqs_gating(struct stm32mp1_ddrctl *ctl,
1345 struct stm32mp1_ddrphy *phy,
1348 /* stores the log of pass/fail */
1349 u8 dqs_gating[NUM_BYTES][MAX_GSL_IDX + 1][MAX_GPS_IDX + 1];
1350 u8 byte, gsl_idx, gps_idx = 0;
1351 struct BIST_result result;
1353 u8 nb_bytes = get_nb_bytes(ctl);
1355 memset(dqs_gating, 0x0, sizeof(dqs_gating));
1357 /*disable dqs drift compensation*/
1358 clrbits_le32(&phy->pgcr, DDRPHYC_PGCR_DFTCMP);
1359 /*disable all bytes*/
1360 /* disable automatic power down of dll and ios when disabling a byte
1361 * (to avoid having to add programming and delay
1362 * for a dll re-lock when later re-enabling a disabled byte lane)
1364 clrbits_le32(&phy->pgcr, DDRPHYC_PGCR_PDDISDX);
1366 /* disable all data bytes */
1367 clrbits_le32(&phy->dx0gcr, DDRPHYC_DXNGCR_DXEN);
1368 clrbits_le32(&phy->dx1gcr, DDRPHYC_DXNGCR_DXEN);
1369 clrbits_le32(&phy->dx2gcr, DDRPHYC_DXNGCR_DXEN);
1370 clrbits_le32(&phy->dx3gcr, DDRPHYC_DXNGCR_DXEN);
1372 /* config the bist block */
1373 config_BIST(ctl, phy);
1375 for (byte = 0; byte < nb_bytes; byte++) {
1377 sprintf(string, "interrupted at byte %d/%d",
1378 byte + 1, nb_bytes);
1381 /* enable byte x (dxngcr, bit dxen) */
1382 setbits_le32(DXNGCR(phy, byte), DDRPHYC_DXNGCR_DXEN);
1384 /* select the byte lane for comparison of read data */
1385 BIST_datx8_sel(phy, byte);
1386 for (gsl_idx = 0; gsl_idx <= MAX_GSL_IDX; gsl_idx++) {
1387 for (gps_idx = 0; gps_idx <= MAX_GPS_IDX; gps_idx++) {
1390 "interrupted at byte %d/%d",
1391 byte + 1, nb_bytes);
1394 /* write cfg to dxndqstr */
1395 set_r0dgsl_delay(phy, byte, gsl_idx);
1396 set_r0dgps_delay(phy, byte, gps_idx);
1398 BIST_test(phy, byte, &result);
1399 success = result.test_result;
1401 dqs_gating[byte][gsl_idx][gps_idx] = 1;
1402 itm_soft_reset(phy);
1405 set_midpoint_read_dqs_gating(phy, byte, dqs_gating);
1411 /* re-enable drift compensation */
1412 /* setbits_le32(&phy->pgcr, DDRPHYC_PGCR_DFTCMP); */
1416 /****************************************************************
1418 ****************************************************************
1420 static enum test_result do_read_dqs_gating(struct stm32mp1_ddrctl *ctl,
1421 struct stm32mp1_ddrphy *phy,
1422 char *string, int argc,
1425 u32 rfshctl3 = readl(&ctl->rfshctl3);
1426 u32 pwrctl = readl(&ctl->pwrctl);
1427 u32 derateen = readl(&ctl->derateen);
1428 enum test_result res;
1430 writel(0x0, &ctl->derateen);
1431 stm32mp1_refresh_disable(ctl);
1433 res = read_dqs_gating(ctl, phy, string);
1435 stm32mp1_refresh_restore(ctl, rfshctl3, pwrctl);
1436 writel(derateen, &ctl->derateen);
1441 static enum test_result do_bit_deskew(struct stm32mp1_ddrctl *ctl,
1442 struct stm32mp1_ddrphy *phy,
1443 char *string, int argc, char *argv[])
1445 u32 rfshctl3 = readl(&ctl->rfshctl3);
1446 u32 pwrctl = readl(&ctl->pwrctl);
1447 u32 derateen = readl(&ctl->derateen);
1448 enum test_result res;
1450 writel(0x0, &ctl->derateen);
1451 stm32mp1_refresh_disable(ctl);
1453 res = bit_deskew(ctl, phy, string);
1455 stm32mp1_refresh_restore(ctl, rfshctl3, pwrctl);
1456 writel(derateen, &ctl->derateen);
1461 static enum test_result do_eye_training(struct stm32mp1_ddrctl *ctl,
1462 struct stm32mp1_ddrphy *phy,
1463 char *string, int argc, char *argv[])
1465 u32 rfshctl3 = readl(&ctl->rfshctl3);
1466 u32 pwrctl = readl(&ctl->pwrctl);
1467 u32 derateen = readl(&ctl->derateen);
1468 enum test_result res;
1470 writel(0x0, &ctl->derateen);
1471 stm32mp1_refresh_disable(ctl);
1473 res = eye_training(ctl, phy, string);
1475 stm32mp1_refresh_restore(ctl, rfshctl3, pwrctl);
1476 writel(derateen, &ctl->derateen);
1481 static enum test_result do_display(struct stm32mp1_ddrctl *ctl,
1482 struct stm32mp1_ddrphy *phy,
1483 char *string, int argc, char *argv[])
1486 u8 nb_bytes = get_nb_bytes(ctl);
1488 for (byte = 0; byte < nb_bytes; byte++)
1489 display_reg_results(phy, byte);
1494 static enum test_result do_bist_config(struct stm32mp1_ddrctl *ctl,
1495 struct stm32mp1_ddrphy *phy,
1496 char *string, int argc, char *argv[])
1498 unsigned long value;
1501 if (strict_strtoul(argv[0], 0, &value) < 0) {
1502 sprintf(string, "invalid nbErr %s", argv[0]);
1505 BIST_error_max = value;
1508 if (strict_strtoul(argv[1], 0, &value) < 0) {
1509 sprintf(string, "invalid Seed %s", argv[1]);
1514 printf("Bist.nbErr = %d\n", BIST_error_max);
1516 printf("Bist.Seed = 0x%x\n", BIST_seed);
1518 printf("Bist.Seed = random\n");
1523 /****************************************************************
1525 ****************************************************************
1528 const struct test_desc tuning[] = {
1529 {do_read_dqs_gating, "Read DQS gating",
1530 "software read DQS Gating", "", 0 },
1531 {do_bit_deskew, "Bit de-skew", "", "", 0 },
1532 {do_eye_training, "Eye Training", "or DQS training", "", 0 },
1533 {do_display, "Display registers", "", "", 0 },
1534 {do_bist_config, "Bist config", "[nbErr] [seed]",
1535 "configure Bist test", 2},
1538 const int tuning_nb = ARRAY_SIZE(tuning);