From cd80c87f1a63e6caab74d41dca29b26ec5cafca0 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Wed, 9 Dec 2020 19:51:19 +0100 Subject: [PATCH] software/liblitedram/write_leveling: revert ideal_delay to 0, ensure write delay is set just before 0 to 1 transition. --- litex/soc/software/liblitedram/sdram.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/litex/soc/software/liblitedram/sdram.c b/litex/soc/software/liblitedram/sdram.c index 8415d21f2..f15579197 100644 --- a/litex/soc/software/liblitedram/sdram.c +++ b/litex/soc/software/liblitedram/sdram.c @@ -26,6 +26,13 @@ #ifdef CSR_SDRAM_BASE +/*-----------------------------------------------------------------------*/ +/* Helpers */ +/*-----------------------------------------------------------------------*/ + +#define max(x, y) (((x) > (y)) ? (x) : (y)) +#define min(x, y) (((x) < (y)) ? (x) : (y)) + __attribute__((unused)) static void cdelay(int i) { #ifndef CONFIG_SIM_DISABLE_DELAYS @@ -452,6 +459,10 @@ static int sdram_write_leveling_scan(int *delays, int loops, int show) } /* Succeed only if the start of a 1s window has been found */ } else if (one_window_best_count > 0 && one_window_best_start > 0) { +#if SDRAM_PHY_DELAYS > 32 + /* Ensure write delay is just before transition */ + one_window_start -= min(one_window_start, 16); +#endif delays[i] = one_window_best_start; /* Configure write delay */ @@ -507,7 +518,7 @@ static void sdram_write_leveling_find_cmd_delay(unsigned int *best_error, int *b delay_mean /= SDRAM_PHY_MODULES; /* We want it to be at the start */ - int ideal_delay = 4*SDRAM_PHY_DELAYS/32; + int ideal_delay = 0; int error = ideal_delay - delay_mean; if (error < 0) error *= -1;