bios/sdram: iterate multiple time for write leveling and add vote to eliminate transc...
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Mon, 5 Nov 2018 17:44:28 +0000 (18:44 +0100)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Mon, 5 Nov 2018 17:44:28 +0000 (18:44 +0100)
litex/soc/software/bios/sdram.c

index 6344006b9c2eedd333deb5a0a48c18e6dc5e9d32..17474c1ac79de2fe3484e4411199e1a8d5ba5533 100644 (file)
@@ -229,7 +229,7 @@ void sdrwloff(void)
 
 int write_level(void)
 {
-       int i, j;
+       int i, j, k;
 
        int dq_address;
        unsigned char dq;
@@ -269,11 +269,22 @@ int write_level(void)
 #endif
                /* scan taps */
                for(j=0;j<err_ddrphy_wdly;j++) {
-                       ddrphy_wlevel_strobe_write(1);
-                       cdelay(10);
-                       dq = MMPTR(dq_address);
-                       printf("%d", dq != 0);
-                       taps_scan[j] = (dq != 0);
+                       int zero_count = 0;
+                       int one_count = 0;
+                       for (k=0; k<128; k++) {
+                               ddrphy_wlevel_strobe_write(1);
+                               cdelay(10);
+                               dq = MMPTR(dq_address);
+                               if (dq != 0)
+                                       one_count++;
+                               else
+                                       zero_count++;
+                       }
+                       if (one_count > zero_count)
+                               taps_scan[j] = 1;
+                       else
+                               taps_scan[j] = 0;
+                       printf("%d", taps_scan[j]);
                        ddrphy_wdly_dq_inc_write(1);
                        ddrphy_wdly_dqs_inc_write(1);
                        cdelay(10);