From 477d224921f70ca774891a11fd42ea46fa112110 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Mon, 2 Jul 2018 13:46:48 +0200 Subject: [PATCH] bios/sdram: check for optimal read window before doing read leveling, increment bitslip if not optimal. --- litex/soc/software/bios/sdram.c | 62 +++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/litex/soc/software/bios/sdram.c b/litex/soc/software/bios/sdram.c index 5e694240..b0e74161 100644 --- a/litex/soc/software/bios/sdram.c +++ b/litex/soc/software/bios/sdram.c @@ -336,6 +336,19 @@ static int write_level(int *delay, int *high_skew) #endif /* CSR_DDRPHY_WLEVEL_EN_ADDR */ +static void read_bitslip_inc(char m) +{ + ddrphy_dly_sel_write(1 << m); +#ifdef KUSDDRPHY + ddrphy_rdly_dq_bitslip_write(1); +#else + /* 7-series SERDES in DDR mode needs 3 pulses for 1 bitslip */ + ddrphy_rdly_dq_bitslip_write(1); + ddrphy_rdly_dq_bitslip_write(1); + ddrphy_rdly_dq_bitslip_write(1); +#endif +} + static void read_bitslip(int *delay, int *high_skew) { int bitslip_thr; @@ -352,28 +365,22 @@ static void read_bitslip(int *delay, int *high_skew) printf("Read bitslip: "); for(i=DFII_PIX_DATA_SIZE/2-1;i>=0;i--) if(delay[i] > bitslip_thr) { - ddrphy_dly_sel_write(1 << i); -#ifdef KUSDDRPHY - ddrphy_rdly_dq_bitslip_write(1); -#else - /* 7-series SERDES in DDR mode needs 3 pulses for 1 bitslip */ - ddrphy_rdly_dq_bitslip_write(1); - ddrphy_rdly_dq_bitslip_write(1); - ddrphy_rdly_dq_bitslip_write(1); -#endif + read_bitslip_inc(i); printf("%d ", i); } printf("\n"); } -static void read_delays_scan(void) +static int read_level_scan(int silent) { unsigned int prv; unsigned char prs[DFII_NPHASES*DFII_PIX_DATA_SIZE]; int p, i, j; int working; + int optimal; - printf("Read delays scan:\n"); + if (!silent) + printf("Read delays scan:\n"); /* Generate pseudo-random sequence */ prv = 42; @@ -399,8 +406,10 @@ static void read_delays_scan(void) /* Calibrate each DQ in turn */ sdram_dfii_pird_address_write(0); sdram_dfii_pird_baddress_write(0); + optimal = 1; for(i=DFII_PIX_DATA_SIZE/2-1;i>=0;i--) { - printf("m%d: ", (DFII_PIX_DATA_SIZE/2-i-1)); + if (!silent) + printf("m%d: ", (DFII_PIX_DATA_SIZE/2-i-1)); ddrphy_dly_sel_write(1 << (DFII_PIX_DATA_SIZE/2-i-1)); ddrphy_rdly_dq_rst_write(1); for(j=0; j