diff --git a/litex/soc/software/liblitedram/sdram.c b/litex/soc/software/liblitedram/sdram.c index 5cf6cb387..2a9e850a7 100644 --- a/litex/soc/software/liblitedram/sdram.c +++ b/litex/soc/software/liblitedram/sdram.c @@ -1,5 +1,5 @@ -// This file is Copyright (c) 2013-2014 Sebastien Bourdeauducq // This file is Copyright (c) 2013-2020 Florent Kermarrec +// This file is Copyright (c) 2013-2014 Sebastien Bourdeauducq // This file is Copyright (c) 2018 Chris Ballance // This file is Copyright (c) 2018 Dolu1990 // This file is Copyright (c) 2019 Gabriel L. Somlo @@ -657,65 +657,90 @@ static void sdram_read_leveling_inc_bitslip(char m) ddrphy_dly_sel_write(0); } -static int sdram_read_leveling_scan_module(int module, int bitslip) -{ - unsigned int prv; - unsigned char prs[SDRAM_PHY_PHASES][DFII_PIX_DATA_BYTES]; - unsigned char tst[DFII_PIX_DATA_BYTES]; - int p, i; - int score; - - /* Generate pseudo-random sequence */ - prv = 42; - for(p=0;p> module) & 0x1) != 1) + return 0; +#endif + + return 1; +} + +static int sdram_read_leveling_scan_module(int module, int bitslip) +{ + int i; + int score; + + /* Activate */ + sdram_activate_test_row(); + + /* Check test pattern for each delay value */ + score = 0; printf(" m%d, b%d: |", module, bitslip); sdram_read_leveling_rst_delay(module); for(i=0;i 32 show = (i%16 == 0); #endif -#ifdef SDRAM_PHY_ECP5DDRPHY - ddrphy_burstdet_clr_write(1); -#endif - command_prd(DFII_COMMAND_CAS|DFII_COMMAND_CS|DFII_COMMAND_RDDATA); - cdelay(15); - for(p=0;p> module) & 0x1) != 1) - working = 0; -#endif + working = sdram_write_read_check_test_pattern(module, 42); + working &= sdram_write_read_check_test_pattern(module, 43); if (show) printf("%d", working); score += working; @@ -724,72 +749,28 @@ static int sdram_read_leveling_scan_module(int module, int bitslip) printf("| "); /* Precharge */ - sdram_dfii_pi0_address_write(0); - sdram_dfii_pi0_baddress_write(0); - command_p0(DFII_COMMAND_RAS|DFII_COMMAND_WE|DFII_COMMAND_CS); - cdelay(15); + sdram_precharge_test_row(); return score; } static void sdram_read_leveling_module(int module) { - unsigned int prv; - unsigned char prs[SDRAM_PHY_PHASES][DFII_PIX_DATA_BYTES]; - unsigned char tst[DFII_PIX_DATA_BYTES]; - int p, i; + int i; int working; int delay, delay_min, delay_max; printf("delays: "); - /* Generate pseudo-random sequence */ - prv = 42; - for(p=0;p> module) & 0x1) != 1) - working = 0; -#endif + working = sdram_write_read_check_test_pattern(module, 42); + working &= sdram_write_read_check_test_pattern(module, 43); if(working) break; delay++; @@ -812,24 +793,8 @@ static void sdram_read_leveling_module(int module) /* Find largest working delay */ while(1) { -#ifdef SDRAM_PHY_ECP5DDRPHY - ddrphy_burstdet_clr_write(1); -#endif - command_prd(DFII_COMMAND_CAS|DFII_COMMAND_CS|DFII_COMMAND_RDDATA); - cdelay(15); - working = 1; - for(p=0;p> module) & 0x1) != 1) - working = 0; -#endif + working = sdram_write_read_check_test_pattern(module, 42); + working &= sdram_write_read_check_test_pattern(module, 43); if(!working) break; delay++; @@ -850,10 +815,7 @@ static void sdram_read_leveling_module(int module) sdram_read_leveling_inc_delay(module); /* Precharge */ - sdram_dfii_pi0_address_write(0); - sdram_dfii_pi0_baddress_write(0); - command_p0(DFII_COMMAND_RAS|DFII_COMMAND_WE|DFII_COMMAND_CS); - cdelay(15); + sdram_precharge_test_row(); } #endif /* CSR_DDRPHY_BASE */ @@ -872,11 +834,11 @@ void sdram_read_leveling(void) int best_bitslip; for(module=0; module