software/liblitedram: seek for consecutive delay range when centering

On some boards, the working delay range found may be not so consecutive.
Considering this to be some inference, we should only count the biggest
consecutive delay range instead of just skip ahead for a fixed offset.

Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
This commit is contained in:
Icenowy Zheng 2022-11-09 17:47:58 +08:00
parent 4a740651f0
commit a7a520695e
1 changed files with 14 additions and 17 deletions

View File

@ -378,7 +378,7 @@ static void sdram_leveling_center_module(
int working; int working;
unsigned int errors; unsigned int errors;
int delay, delay_mid, delay_range; int delay, delay_mid, delay_range;
int delay_min = -1, delay_max = -1; int delay_min = -1, delay_max = -1, cur_delay_min = -1;
if (show_long) if (show_long)
printf("m%d: |", module); printf("m%d: |", module);
@ -406,20 +406,9 @@ static void sdram_leveling_center_module(
inc_delay(module); inc_delay(module);
} }
/* Get a bit further into the working zone */ delay_max = delay_min;
#if SDRAM_PHY_DELAYS > 32 cur_delay_min = delay_min;
#define SDRAM_PHY_DELAY_JUMP 16 /* Find largest working delay range */
#elif SDRAM_PHY_DELAYS > 8
#define SDRAM_PHY_DELAY_JUMP 4
#else
#define SDRAM_PHY_DELAY_JUMP 1
#endif
for(i=0;i<SDRAM_PHY_DELAY_JUMP;i++) {
delay += 1;
inc_delay(module);
}
/* Find largest working delay */
while(1) { while(1) {
errors = sdram_write_read_check_test_pattern(module, 42); errors = sdram_write_read_check_test_pattern(module, 42);
errors += sdram_write_read_check_test_pattern(module, 84); errors += sdram_write_read_check_test_pattern(module, 84);
@ -430,9 +419,17 @@ static void sdram_leveling_center_module(
#endif #endif
if (show) if (show)
print_scan_errors(errors); print_scan_errors(errors);
if(!working && delay_max < 0) {
if (working) {
int cur_delay_length = delay - cur_delay_min;
int best_delay_length = delay_max - delay_min;
if (cur_delay_length > best_delay_length) {
delay_min = cur_delay_min;
delay_max = delay; delay_max = delay;
} }
} else {
cur_delay_min = delay + 1;
}
delay++; delay++;
if(delay >= SDRAM_PHY_DELAYS) if(delay >= SDRAM_PHY_DELAYS)
break; break;