|
|
@@ -272,9 +272,10 @@ int DDR_Init(void)
|
|
|
unsigned int tCKE = ((MAX(3,DDR_CALC(5))/2)+1);
|
|
|
unsigned int tXS = DDR_CALC_EXACT_VALUE(110+10)/32;
|
|
|
// unsigned int twr2pre = 15;
|
|
|
- unsigned int count=0;
|
|
|
+ int retries = 10;
|
|
|
+ int timeout;
|
|
|
+
|
|
|
restart:
|
|
|
- count = 3;
|
|
|
if (WR < 6)
|
|
|
WR = 6;
|
|
|
else if (WR == 9)
|
|
|
@@ -288,10 +289,10 @@ restart:
|
|
|
|
|
|
#if 1
|
|
|
rval = readl(0x50000060);
|
|
|
- rval &= ~((1 << 21));
|
|
|
+ rval &= ~((3 << 20));
|
|
|
writel(rval, 0x50000060);
|
|
|
TIMER_Mdelay(1);
|
|
|
- rval |= (1 << 21);
|
|
|
+ rval |= (3 << 20);
|
|
|
writel(rval, 0x50000060);
|
|
|
TIMER_Mdelay(1);
|
|
|
#endif
|
|
|
@@ -427,7 +428,8 @@ restart:
|
|
|
TIMER_Udelay(100);
|
|
|
|
|
|
// ApbWriteFun(0x51500068, 0x9F0035c7); //DTCR,Data Training Configuration Register
|
|
|
- ApbWriteFun(ddrsphy_dtcr_addr, 0x914075c7); //DTCR,Data Training Configuration Register
|
|
|
+ //ApbWriteFun(ddrsphy_dtcr_addr, 0x914075c7); //DTCR,Data Training Configuration Register
|
|
|
+ ApbWriteFun(ddrsphy_dtcr_addr, 0x914035c7); //DTCR,Data Training Configuration Register
|
|
|
//ApbWriteFun(0x51500068, 0x914075c7); //DTCR,Data Training Configuration Register
|
|
|
//phy parameters
|
|
|
// ApbWriteFun(0x51500040, 0xF000645F); //DSGCR,DDR System General Configuration Register,rr_mode=0, dqs gate extension
|
|
|
@@ -567,15 +569,23 @@ restart:
|
|
|
// printf("ddrsphy_dtpr2_addr:tXS 0x%x,tXP 0x%x,tCKE 0x%x\n", max(5, DDR_CALC(110 + 10)),max(3, DDR_CALC(6)),max(3, DDR_CALC(5)));
|
|
|
|
|
|
// step 4
|
|
|
- while (count--) {
|
|
|
- tmp = 0x33 ;//[0-INIT]£¬[1-ZCAL][4-PLLINIT][5-DCAL]
|
|
|
- ApbWriteFun(ddrsphy_pir_addr, tmp);
|
|
|
+ ApbWriteFun(ddrsphy_pir_addr, 0x33); //[0-INIT]£¬[1-ZCAL][4-PLLINIT][5-DCAL]
|
|
|
+
|
|
|
+ timeout = 100;
|
|
|
+ while (timeout--) {
|
|
|
+ TIMER_Udelay(20);
|
|
|
rdata = *((volatile unsigned int *)(ddrsphy_pgsr0_addr));
|
|
|
if ((rdata & 0x0F) == 0xf)
|
|
|
break;
|
|
|
}
|
|
|
- if (count == 0)
|
|
|
+ if (timeout < 0 && retries--) {
|
|
|
+ printf("DDR_Init step4 timeout, retry...\n");
|
|
|
goto restart;
|
|
|
+ }
|
|
|
+ if (retries < 0) {
|
|
|
+ printf("DDR_Init step4 fail!\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
|
|
|
// rdata = *((volatile unsigned int *)(ddrsphy_zq0sr0_addr));
|
|
|
// printf("ddrsphy_zq0sr0_addr:0x%x\n",rdata );
|
|
|
@@ -727,11 +737,21 @@ restart:
|
|
|
//12:8 dfi_t_dram_clk_disable
|
|
|
ApbWriteFun_qussi(ddrs_dfitmg1_addr, 0x01010202);
|
|
|
|
|
|
- while (1) {
|
|
|
+ timeout = 100;
|
|
|
+ while (timeout--) {
|
|
|
+ TIMER_Udelay(20);
|
|
|
rdata = *((volatile unsigned int *)(ddrs_stat_addr));
|
|
|
if ((rdata & 0x03) == 0x01)
|
|
|
break;
|
|
|
}
|
|
|
+ if (timeout < 0 && retries--) {
|
|
|
+ printf("DDR_Init step10 timeout, retry...\n");
|
|
|
+ goto restart;
|
|
|
+ }
|
|
|
+ if (retries < 0) {
|
|
|
+ printf("DDR_Init step10 fail!\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
|
|
|
// step 11
|
|
|
// ApbWriteFun(ddrs_swctl_addr, 0x0);
|
|
|
@@ -834,20 +854,26 @@ restart:
|
|
|
TIMER_Mdelay(3);
|
|
|
// step 16
|
|
|
|
|
|
- u32 timerout_ms = TIMER_GetMicrosec(0) / 1000;
|
|
|
- while (1) {
|
|
|
+ timeout = 100;
|
|
|
+ while (timeout--) {
|
|
|
+ TIMER_Udelay(20);
|
|
|
rdata = *((volatile unsigned int *)(ddrsphy_pgsr0_addr));
|
|
|
//PrintVariableValueHex("ddrsphy_pgsr0_addr : ", rdata);
|
|
|
- if ((rdata & 0xFFF) == 0xFFF)
|
|
|
+ if (rdata == 0x90000fff)
|
|
|
break;
|
|
|
-
|
|
|
- if (TIMER_GetMicrosec(0) / 1000 - timerout_ms > 50) {
|
|
|
- printf("ddr init timeout.\n");
|
|
|
- return -1;
|
|
|
- }
|
|
|
}
|
|
|
+ if (timeout < 0 && retries--) {
|
|
|
+ printf("DDR_Init step16 timeout, retry...\n");
|
|
|
+ goto restart;
|
|
|
+ }
|
|
|
+ if (retries < 0) {
|
|
|
+ printf("DDR_Init step16 fail!\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
ApbWriteFun_qussi(ddrs_rfshctl3_addr, 0x0);
|
|
|
ApbWriteFun(ddrs_swctlstatic_addr, 0x0);
|
|
|
+
|
|
|
return 0;
|
|
|
}
|
|
|
|