software/liblitedram/write_leveling: revert ideal_delay to 0, ensure write delay is set just before 0 to 1 transition.

This commit is contained in:
Florent Kermarrec 2020-12-09 19:51:19 +01:00
parent 5ebea9434b
commit cd80c87f1a
1 changed files with 12 additions and 1 deletions

View File

@ -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;