1. 程式人生 > >DDR(五)DDR2初始化順序

DDR(五)DDR2初始化順序

現在網上的S5PV210的u-boot原始碼中關於記憶體的初始化過程,基本上我沒有找到任何資料有過分析DDR2的記憶體初始化程式碼的。在看u-boot的這段程式碼時,也徘徊了很久,不知道如下手,很多文章或資料都將這一段分析過程有意無意的隱藏掉了,最多也只是提一下說參考裸板的程式碼,在找不到任何資料的情況下,我只能依靠晶片手冊上,三星在記憶體控制器這一章,寫的關於DDR2的初始化順序的28個步驟來一條一條去讀去看,在安靜下來看了晶片手冊以後,我發現三星給的裸板的DDR初始化程式碼和晶片手冊上的初始化步驟完全一致,有的時候,最好的資料其實就在手邊,只是我一直在想著找捷徑,學習哪有那麼多捷徑?


現在開始關注一下晶片手冊上關於DDR2的初始化流程,P598頁:

1.檢視晶片手冊DDR2的初始化順序
Initialization sequence for DDR2 memory type
1.  To provide stable power for controller and memory device, the controller must assert and hold CKE to a logic low level. Then apply stable clock. Note: XDDR2SEL should be High level to hold CKE to low.
2. Set the PhyControl0.ctrl_start_point and PhyControl0.ctrl_incbit-fields to correct value according to clock frequency. Set the PhyControl0.ctrl_dll_onbit-field to ‘1’ to turn on the PHY DLL.
3. DQS Cleaning: Set the PhyControl1.ctrl_shiftc and PhyControl1.ctrl_offsetcbit-fields to correct value according to clock frequency and memory tAC parameters.
4. Set the PhyControl0.ctrl_start bit-field to ‘1’.  
5. Set the ConControl. At this moment, an auto refresh counter should be off.  
6. Set the MemControl. At this moment, all power down modes should be off.
7. Set the MemConfig0 register. If there are two external memory chips, set the MemConfig1 register.
8. Set the PrechConfigand PwrdnConfigregisters.
9. Set the TimingAref, TimingRow, TimingDataand TimingPower registers according to memory AC parameters.
10. If QoS scheme is required, set the QosControl0~15and QosConfig0~15registers.
11. Wait for thePhyStatus0.ctrl_lockedbit-fields to change to ‘1’. Check whether PHY DLL is locked.
12. PHY DLL compensates the changes of delay amountcaused by Process, Voltage and Temperature (PVT) variation during memory operation. Therefore, PHY DLL should not be off for reliable operation. It can be off except runs at low frequency. If off mode is used, set thePhyControl0.ctrl_forcebit-field to correct value according to thePhyStatus0.ctrl_lock_value[9:2]bit-field to fix delay amount. Clear the PhyControl0.ctrl_dll_on bit-field to turn off PHY DLL.
13. Confirm whether stable clock is issued minimum 200us after power on
14. Issue a NOPcommand using the DirectCmdregister to assert and to hold CKE to a logic high level.
15. Wait for minimum 400ns.
16. Issue a PALL command using the DirectCmd register.
17. Issue an EMRS2 command using the DirectCmd register to program the operating parameters.
18. Issue an EMRS3 command using the DirectCmd register to program the operating parameters.
19. Issue an EMRS command using the DirectCmd register to enable the memory DLLs.
20. Issue a MRS command using the DirectCmd register to reset the memory DLL.
21. Issue a PALL command using the DirectCmd register.
22. Issue two Auto Refreshcommands using the DirectCmd register.
23. Issue a MRS command using the DirectCmd register to program the operating parameters without resetting the memory DLL.
24. Wait for minimum 200 clock cycles.
25. Issue an EMRS command using the DirectCmd register to program the operating parameters. If OCD calibration is not used, issue an EMRS command to set OCD Calibration Default. After that, issue an EMRS command to exit OCD Calibration Mode and to program the operating parameters.
26. If there are two external memory chips, perform steps 14~25 for chip1 memory device.
27. Set the ConControlto turn on an auto refresh counter.
28. If power down modes is required, set the MemControl registers.

譯文如下:
1. 提供穩壓電源給記憶體控制器和記憶體晶片,記憶體控制器必須保持CLE在低電平,此時就會提供穩壓電源。注:當CKE引腳為低電平時,XDDR2SEL應該處於高電平
2. 依照時鐘頻率正確配置PhyControl0.ctrl_start_point和PhyControl0.ctrl_incbit-fields的值。配置的PhyControl0.ctrl_dll_on值為'1'以開啟PHY DLL。
3. DQS Cleaning:依照時鐘頻率和記憶體的tAC引數正確設定PhyControl1.ctrl_shiftc and PhyControl1.ctrl_offsetcbit-fields位的值。
4. 配置PhyControl0.ctrl_start位的值為'1'
5. 配置ConControl,與此同時,auto refresh自動重新整理計數器應該關閉
6. 配置MemControl,與此同時,所有的power down(休眠模式)應該閉關
7. 配置MemConfig0暫存器。如果有兩組記憶體晶片(比如有8片DDR,這8片DDR是分別掛在Memory Port1和Memory Port2上),再配置MemConfig1暫存器。
8. 配置PrechConfig和PwrdnConfig暫存器
9. 依照記憶體的tAC引數配置TimingAref, TimingRow, TimingData和TimingPower暫存器
10. 如果需要QoS標準,配置QosControl0~15和QosConfig0~15r暫存器
11. 等待PhyStatus0.ctrl_locked位變為'1'。檢查是否PHY DLL是否已鎖
12. PHY DLL補償在記憶體操作時由PVT(Process, Voltage and Temperature,處理器、電壓和溫度)變化引起的延遲量。但是,PHY DLL不能因某些可靠的記憶體操作而切斷,除非是工作在低頻率下。如果關閉PHY DLL,依照PhyStatus0.ctrl_lock_value[9:2]位的值正確配置PhyControl0.ctrl_force位的值來彌補延遲量(fix delay amount)。清除PhyControl0.ctrl_dll_on位的值來關閉PHY DLL。
13. 上電後,確定最小值為200us的穩定時鐘是否發出
14. 使用DirectCmd暫存器發出一個NOP命令,保證CKE引腳為高電平
15. 等最小400ns
16. 使用DirectCmd暫存器發出一個PALL命令
17. 使用DirectCmd暫存器發出一個EMRS2命令,program操作引數
18. 使用DirectCmd暫存器發出一個EMRS3命令,program操作引數
19. 使用DirectCmd暫存器發出一個EMRS命令來使能記憶體DLLs
20. 使用DirectCmd暫存器發出一個MRS命令,重啟記憶體DLL
21. 使用DirectCmd暫存器發出一個PALL命令
22. 使用DirectCmd暫存器發出兩個Auto Refresh(自動重新整理)命令
23. 使用DirectCmd暫存器發出一個MRS命令,program操作引數,不要重啟記憶體DLL
24. 等待最小200時鐘週期
25. 使用DirectCmd暫存器發出一個EMRS命令給程式的執行引數。如果OCD校正(Off-Chip Driver,片外驅動調校)沒有使用,改善一個EMRS命令去設定OCD校準的預設值。在此之後,傳送一個EMRS指令去退出OCD校準模式,繼續program操作引數
26. 如果有兩組DDR晶片,重複14-25步配置chip1的記憶體,剛剛配置的是chip0,也就是第一組記憶體晶片
27. 配置ConControlto來開啟自動重新整理計數器
28. 如果需要power down(休眠)模式,配置MemControl暫存器.


知道了上面的這些初始化步驟,現在再去看三星給的裸板程式碼中關於SDRAM的BL1的程式碼,就比較清楚了。