From: Florent Kermarrec Date: Mon, 1 Oct 2018 13:38:19 +0000 (+0200) Subject: bios/sdram: rewrite write_leveling (simplify and improve robustness) X-Git-Tag: 24jan2021_ls180~1575 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6e327cda2697d37b23f607a5a7712363dc60857a;p=litex.git bios/sdram: rewrite write_leveling (simplify and improve robustness) --- diff --git a/litex/soc/software/bios/sdram.c b/litex/soc/software/bios/sdram.c index 443245ee..ff9009c9 100644 --- a/litex/soc/software/bios/sdram.c +++ b/litex/soc/software/bios/sdram.c @@ -225,12 +225,28 @@ void sdrwloff(void) ddrphy_wlevel_en_write(0); } -static void write_level_scan(void) +int write_level(void) { int i, j; + int dq_address; unsigned char dq; + int err_ddrphy_wdly; + + unsigned char taps_scan[ERR_DDRPHY_DELAY]; + + int one_window_active; + int one_window_start; + int one_window_len; + int best_one_window_len; + + int delays[DFII_PIX_DATA_SIZE/2]; + + int ok; + + err_ddrphy_wdly = ERR_DDRPHY_DELAY - ddrphy_half_sys8x_taps_read(); + printf("Write leveling scan:\n"); sdrwlon(); @@ -238,94 +254,72 @@ static void write_level_scan(void) for(i=0;i best_one_window_len) { + delays[i] = one_window_start; + best_one_window_len = one_window_len; + } + one_window_active = 0; + } + } else { + if (taps_scan[j]) { + one_window_active = 1; + one_window_start = j; + } + } + } - sdrwlon(); - cdelay(100); - for(i=0;i= err_ddrphy_wdly) - break; - ddrphy_wdly_dq_inc_write(1); - ddrphy_wdly_dqs_inc_write(1); - ddrphy_wlevel_strobe_write(1); - cdelay(10); - dq = MMPTR(dq_address); - } -#else - high_skew[i] = 0; -#endif - } else - high_skew[i] = 0; - - while(dq == 0) { - delay[i]++; - if(delay[i] >= err_ddrphy_wdly) - break; + for(j=0; j=0;i--) { - printf("%2d%c ", delay[i], high_skew[i] ? '*' : ' '); - if(delay[i] >= err_ddrphy_wdly) + printf("%2d ", delays[i]); + if(delays[i] < 0) ok = 0; } @@ -352,28 +346,6 @@ static void read_bitslip_inc(char m) #endif } -static void read_bitslip(int *delay, int *high_skew) -{ - int bitslip_thr; - int i; - - bitslip_thr = 0x7fffffff; - for(i=0;i=0;i--) - if(delay[i] > bitslip_thr) { - read_bitslip_inc(i); - printf("%d ", i); - } - printf("\n"); -} - static int read_level_scan(int silent) { unsigned int prv; @@ -721,8 +693,6 @@ int memtest(void) #ifdef CSR_DDRPHY_BASE int sdrlevel(int silent) { - int delay[DFII_PIX_DATA_SIZE/2]; - int high_skew[DFII_PIX_DATA_SIZE/2]; int i, j; int bitslip; int score; @@ -737,16 +707,11 @@ int sdrlevel(int silent) ddrphy_rdly_dq_bitslip_rst_write(1); } -#ifndef CSR_DDRPHY_WLEVEL_EN_ADDR - for(i=0; i