From 3d5bc29dd10c5cbd08c2a633b41db7be47849db0 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Fri, 9 Oct 2020 19:13:10 +0200 Subject: [PATCH] software/liblitedram: add initial write latency calibration. --- litex/soc/software/liblitedram/sdram.c | 97 +++++++++++++++++++------- 1 file changed, 72 insertions(+), 25 deletions(-) diff --git a/litex/soc/software/liblitedram/sdram.c b/litex/soc/software/liblitedram/sdram.c index 2a9e850a7..d75d67f52 100644 --- a/litex/soc/software/liblitedram/sdram.c +++ b/litex/soc/software/liblitedram/sdram.c @@ -519,24 +519,6 @@ int sdram_write_leveling(void) int cdly_range_start; int cdly_range_end; int cdly_range_step; - int i, j; - - - /* Configure write bitslips */ - for (i=0; i<16; i++) { - /* sel module */ - ddrphy_dly_sel_write(1 << i); - /* rst bitslip */ - ddrphy_wdly_dq_bitslip_rst_write(1); - /* set bitslip */ - if (_sdram_write_leveling_bitslips[i] >= 0) { - for (j=0; j<_sdram_write_leveling_bitslips[i]; j++) { - ddrphy_wdly_dq_bitslip_write(1); - } - } - /* unsel module */ - ddrphy_dly_sel_write(0); - } if (_sdram_write_leveling_cmd_scan) { printf(" Cmd/Clk scan:\n"); @@ -721,7 +703,7 @@ static int sdram_write_read_check_test_pattern(int module, unsigned int seed) { return 1; } -static int sdram_read_leveling_scan_module(int module, int bitslip) +static int sdram_read_leveling_scan_module(int module, int bitslip, int show) { int i; int score; @@ -731,22 +713,24 @@ static int sdram_read_leveling_scan_module(int module, int bitslip) /* Check test pattern for each delay value */ score = 0; - printf(" m%d, b%d: |", module, bitslip); + if (show) + printf(" m%d, b%d: |", module, bitslip); sdram_read_leveling_rst_delay(module); for(i=0;i 32 - show = (i%16 == 0); + _show = (i%16 == 0) & show; #endif working = sdram_write_read_check_test_pattern(module, 42); working &= sdram_write_read_check_test_pattern(module, 43); - if (show) + if (_show) printf("%d", working); score += working; sdram_read_leveling_inc_delay(module); } - printf("| "); + if (show) + printf("| "); /* Precharge */ sdram_precharge_test_row(); @@ -839,7 +823,7 @@ void sdram_read_leveling(void) best_bitslip = 0; for(bitslip=0; bitslip best_score) { @@ -865,6 +849,66 @@ void sdram_read_leveling(void) } } +/*-----------------------------------------------------------------------*/ +/* Write latency calibration */ +/*-----------------------------------------------------------------------*/ + +static void sdram_write_latency_calibration(void) { + int i; + int module; + int bitslip; + int score; + int best_score; + int best_bitslip; + + for(module=0; module best_score) { + best_bitslip = bitslip; + best_score = score; + } + } + + if (_sdram_write_leveling_bitslips[module] < 0) + bitslip = best_bitslip; + else + bitslip = _sdram_write_leveling_bitslips[module]; + printf("m%d:%d ", module, bitslip); + + /* Select best write window */ + ddrphy_dly_sel_write(1 << module); + /* rst bitslip */ + ddrphy_wdly_dq_bitslip_rst_write(1); + for (i=0; i