@@ -610,48 +610,240 @@ enum ifc_amask_sizes {
610610
611611/* DDR4 - 2GB */
612612/* 1600 MT/s (64-bit, CL=12, ECC on) */
613+
614+ /* SA[0-15]: 0000: Starting address for chip select (bank)n
615+ * EA[16-31]: 007F: Ending address for chip select (bank)n
616+ */
613617#define DDR_CS0_BNDS_VAL 0x0000007F
614618#define DDR_CS1_BNDS_VAL 0x008000BF
615619#define DDR_CS2_BNDS_VAL 0x0100013F
616620#define DDR_CS3_BNDS_VAL 0x0140017F
617- #define DDR_CS0_CONFIG_VAL 0x80010312
621+
622+ /* 15=row bits, 10 column bits, 1 bank group bit, 2 logical bank bits, ODT only during writes */
623+ /* CS_EN [0]: 1 Chip select n enable
624+ * AP_EN [8]: 1 Chip select nauto-precharge enable
625+ * ODT_RD_CFG [9-11]: ODT for reads configuration
626+ * ODT_WR_CFG [13-15]: ODT for writes configuration
627+ * BA_BITS_CS [16-17]: Number of bank bits for SDRAM on chip selectn
628+ * ROW_BITS_CS[21-23]: Number of row bits for SDRAM on chip selectn
629+ * BG_BITS_CS [26-27]: Number of bank group bits for SDRAM on chip selectn
630+ * COL_BITS_CS[29-31]: Number of column bits for SDRAM on chip selectn
631+ */
632+ #define DDR_CS0_CONFIG_VAL 0x80810312 /* was 0x80010312 */
618633#define DDR_CS1_CONFIG_VAL 0x00000202
619634#define DDR_CS2_CONFIG_VAL 0x00000202
620635#define DDR_CS3_CONFIG_VAL 0x00010202
636+
637+ /* PASR_DEC[0]: Partial array decoding
638+ * PASR_CFG[5-7]: Partial array self refresh config
639+ */
621640#define DDR_CS_CONFIG_2_VAL 0x00000000
622641
642+ /* RWT [0-1]: 10: 2 clocks: Read-to-write turnaround (tRTW)
643+ * WRT [2-3]: 00: 0 clocks: Write-to-read turnaround
644+ * RRT [4-5]: 00: 0 clocks: Read-to-read turnaround
645+ * WWT [6-7]: 00: 0 clocks: Write-to-write turnaround
646+ * ACT_PD_EXIT [8-11]: 0101: 5 clocks: Active powerdown exit timing (tXP)
647+ * PRE_PD_EXIT [12-15]: 0100: 4 clocks: Precharge powerdown exit timing (tXP)
648+ * EXT_PRE_PD_EXIT[16-17]: 01: 16 clocks: Extended precharge powerdown exit timing (tXP)
649+ * MRS_CYC [27-31]: 01100: 12 clocks: Mode register set cycle time (tMRD, tMOD)
650+ */
623651#define DDR_TIMING_CFG_0_VAL 0x8055000C
624- #define DDR_TIMING_CFG_1_VAL 0x2E268E44
625- #define DDR_TIMING_CFG_2_VAL 0x0049111C
626- #define DDR_TIMING_CFG_3_VAL 0x114C1000
627652
628- #define DDR_TIMING_CFG_4_VAL 0x00220001
653+ /* PRETOACT [0-3]: 0011: 3 clocks: Precharge-to-activate interval (tRP)
654+ * ACTTOPRE [4-7]: 1110: 14 clocks (30 total): Activate to precharge interval (tRAS)
655+ * ACTTORW [8-11]: 0010: 2 clocks (18 total): Activate to read/write interval for SDRAM (tRCD)
656+ * CASLAT [12-14]: 011: 4 clocks: MCAS_B latency from READ command
657+ * REFREC [16-19]: 1100: 12 clocks (240+12+8 total): Refresh recovery time (tRFC)
658+ * WRREC [20-23]: 1110: 14 clocks: Last data to precharge minimum interval (tWR)
659+ * ACTTOACT [24-27]: 0100: 4 clocks: Activate-to-activate interval (tRRD)
660+ * WRTORD [28-31]: 0100: 4 clocks: Last write data pair to read command issue interval (tWTR)
661+ */
662+ #define DDR_TIMING_CFG_1_VAL 0x3E26CE44 /* was 0x2E268E44 */
663+
664+ /* ADD_LAT [0-3]: 0000: 0 clocks Additive latency
665+ * WR_LAT [9-12]: 1001: 9 clocks Write latency
666+ * EXT_WR_LAT [13]: 0: 0 clocks Extended Write Latency (1=16 clocks)
667+ * RD_TO_PRE [15-18]: 1000: 8 clocks Read to precharge (tRTP).
668+ * WR_DATA_DELAY [19-22]: 1000: 1 clock delay Write command to write data strobe timing adjustment.
669+ * CKE_PLS [23-25]: 100: 4 clocks Minimum CKE pulse width (tCKE).
670+ * FOUR_ACT [26-31]: 011100: 28 Window for four activates (tFAW).
671+ */
672+ #define DDR_TIMING_CFG_2_VAL 0x0049111C /* tried 0x00491124 */
673+
674+ /* EXT_PRETOACT [3]: 1: 16 clocks: Extended precharge-to-activate interval (0=0, 1=16 clocks)
675+ * EXT_ACTTOPRE [6-7]: 01: 16 clocks: Extended Activate to precharge interval (tRAS)
676+ * EXT_ACTTORW [9]: 1: 16 clocks: Extended activate to read/write interval for SDRAM (tRCD) (ACTTORW[5])
677+ * EXT_REFREC [10-15]: 001111: 240 Extended refresh recovery time (tRFC).
678+ * EXT_CASLAT [18-19]: 01: 8 clocks Extended MCAS_B latency from READ command
679+ * EXT_ADD_LAT [21]: 0: 0 clocks Extended Additive Latency
680+ * EXT_WRREC [23]: 1: 16 clocks Extended last data to precharge minimum interval (tWR)
681+ * CNTL_ADJ [29-31]: 000: MODTn, MCSn_B, and MCKEn will be launched aligned with the other DRAM address and control signals.
682+ */
683+ #define DDR_TIMING_CFG_3_VAL 0x114F1100 /* was 0x114C1000 */
684+
685+ /* RWT [0-3]: 0000: 0 clocks: Read-to-write turnaround for same chip select.
686+ * WRT [4-7]: 0000: 0 clocks: Write-to-read turnaround for same chip select
687+ * RRT [8-11]: 0010: 2 clocks: Read-to-read turnaround for same chip select
688+ * WWT [12-15]: 0010: 2 clocks: Write-to-write turnaround for same chip select.
689+ * EXT_RWT [16-17]: 00: Extended read-to-write turnaround (tRTW)
690+ * EXT_WRT [19]: 0: Extended write-to-read turnaround
691+ * EXT_RRT [21]: 0: Extended read-to-read turnaround
692+ * EXT_WWT [23]: 0: Extended write-to-write turnaround
693+ * EXT_REFINT [27]: 0: Refresh interval (0=0,1=65,536 clocks)
694+ * DLL_LOCK [30-31]: 10: 1024 clocks: DDR SDRAM DLL Lock Time (0=200, 1=512, 2=1024 clocks)
695+ */
696+ #define DDR_TIMING_CFG_4_VAL 0x00220002 /* was 0x00220001 */
697+
698+ /* RODT_ON [3-7]: 0101: 4 clocks: Read to ODT on (0=CASLAT-WR_LAT, 1=0, 2=1, 12=11 clocks)
699+ * RODT_OFF [9-11]: 100: 4 clocks: Read to ODT off (0=4, 1=1, 7=7 clocks)
700+ * WODT_ON [15-19]: 00001: 1 clock: Write to ODT off (1=0, 2=1, 6=5 clocks)
701+ * WODT_OFF [21-23]: 100: 4 clocks: Write to ODT off (0=4, 1=1, 7=7 clocks)
702+ */
629703#define DDR_TIMING_CFG_5_VAL 0x05401400
704+
705+ #define DDR_TIMING_CFG_6_VAL 0x00000000
706+
707+ /* CKE_RST [2-3]: 00: 200 clocks: CKE reset time (tXPR) (0=200, 1=256, 2=512, 3=1024 clocks)
708+ * CKSRE [4-7]: 0000: 15 clocks: Valid clock after Self Refresh entry (tCKSRE) (0=15, 1=6, )
709+ * CKSRX [8-11]: 0000: 15 clocks: Valid clock after Self Refresh exit (tCKSRX)
710+ * PAR_LAT [12-15]: 0000: 0 clocks
711+ * CS_TO_CMD [24-27]: 0000: 0 clocks: Chip select to command latency
712+ */
713+ #define DDR_TIMING_CFG_7_VAL 0x00000000 /* tried 0x00050000 */
714+
715+ /* RWT_BG [0-3]: 0000: Read-to-write turnaround for same chip select and same bank group
716+ * WRT_BG [4-7]: 0011: Write-to-read turnaround for same chip select and same bank group
717+ * RRT_BG [8-11]: 0001: Read-to-read turnaround for same chip select and same bank group
718+ * WWT_BG [12-15]: 0001: Write-to-write turnaround for same chip select and same bank group
719+ * ACTTOACT_BG [16-19]: 0101: Activate-to-activate interval for the same bank group(tRRD_L).
720+ * WRTORD_BG [20-23]: 1000: Last write data pair to read command issue interval for the same bank group(tWTR_L)
721+ * PRE_ALL_REC [27-31]: 00000: Precharge all-to-activate interval
722+ */
630723#define DDR_TIMING_CFG_8_VAL 0x03115800
631724
725+ /* MR1 | MR0
726+ * MR0 0x0215
727+ * | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
728+ * [ WR/RTP ] [ CL3-1 ][BT][CL0][ BL ]
729+ * Burst Length (BL) = 01: 00 (fixed 8), 01 (on the fly), 02 (fixed 4)
730+ * Burst Type (BT) = 0 (nibble sequential), 1 (interleave)
731+ * CAS Latency (CL):
732+ * 00000 (9 clocks)
733+ * 00001 (10 clocks)
734+ * 00010 (11 clocks)
735+ * 00011 (12 clocks) (original)
736+ * 00100 (13 clocks)
737+ * 00101 (14 clocks)
738+ * 00110 (15 clocks)
739+ * 00111 (16 clocks)
740+ * 10111 (32 clocks)
741+ * WRITE recovery (WR)/READ-to-PRECHARGE(RTP):
742+ * 0000 (10/5 clocks)
743+ * 0001 (12/6 clocks) (original)
744+ * 0010 (14/7 clocks)
745+ * 0011 (16/8 clocks)
746+ * 0100 (18/9 clocks)
747+ * 0101 (20/10 clocks)
748+ * 0110 (24/12 clocks)
749+ * 0111 (22/11 clocks)
750+ * 1000 (26/13 clocks)
751+ * 1001 (28/14 clocks)
752+ *
753+ * MR1 0x0101
754+ * | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
755+ * [TDQS][ RTT_NOM ][Wlev] [ AL ][ ODI ][DLL]
756+ * DLL=1, RTT_NOM=001 (RZQ/4 60ohm), ODI=00 (RZQ/7 34ohm)
757+ */
632758#define DDR_SDRAM_MODE_VAL 0x01010215
759+
760+ /* MR2 | MR3
761+ * MR2
762+ * | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
763+ * [ RTT_WR ] [ CWL ]
764+ *
765+ * MR3
766+ * | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
767+ * [ WR_CMD_LAT]
768+ */
633769#define DDR_SDRAM_MODE_2_VAL 0x00000000
634- #define DDR_SDRAM_MODE_9_VAL 0x00000500 /* Extended SDRAM mode 5 */
635- #define DDR_SDRAM_MODE_10_VAL 0x04000000 /* Extended SDRAM mode 7 */
770+
771+ /* Not applicable (reuse other MRs) */
636772#define DDR_SDRAM_MODE_3_8_VAL 0x00000000
773+
774+ /* MR4 | MR5
775+ * MR4: 0x0100
776+ * MR5: 0x013F: RTT_PARK=000 disabled, CA Parity Latency=010 (5 clocks) */
777+ #define DDR_SDRAM_MODE_9_VAL 0x00000500
778+
779+ /* MR6 | MR7:
780+ * MR7: CCD_L 010=6 clocks, VREF Range 1 */
781+ #define DDR_SDRAM_MODE_10_VAL 0x04000000
782+
637783#define DDR_SDRAM_MD_CNTL_VAL 0x03001000
638784
639785#define DDR_SDRAM_CFG_VAL 0xE5200000 /* DDR4 w/ECC */
786+
787+ /* ODT_CFG [9-10]: 10: Assert ODT to internal IOs only
788+ * NUM_PR [16-19]: 00001: 1 refresh
789+ * OBC_CFG [25]: 1: On-the-fly Burst Chop mode will be used
790+ * D_INIT [27]: 1: The memory controller will initialize memory once it is enabled
791+ */
640792#define DDR_SDRAM_CFG_2_VAL 0x00401050
641793
642- #define DDR_SDRAM_INTERVAL_VAL 0x18600618
794+ /* REF_MODE[22-23]: Refresh Mode */
795+ #define DDR_SDRAM_CFG_3_VAL 0x00000000
796+
797+ /* REFINT [0-15]: 6240: Refresh interval 12480=0x30C0
798+ * BSTOPRE [18-31]: 1560: Precharge interval
799+ */
800+ #define DDR_SDRAM_INTERVAL_VAL 0x18600000 /* was 0x18600618 */
801+
643802#define DDR_DATA_INIT_VAL 0xDEADBEEF
644- #define DDR_SDRAM_CLK_CNTL_VAL 0x02400000
803+
804+ /* CLK_ADJUST[5-9]: applied cycle after address/command
805+ * 00000 = aligned
806+ * 00001 = 1/16
807+ * 00100 = 1/4
808+ * 00110 = 3/8
809+ * 01001 = 9/16
810+ * 01000 = 1/2 (configured)
811+ * 01010 = 5/8
812+ * 10000 = 1
813+ */
814+ #define DDR_SDRAM_CLK_CNTL_VAL 0x02000000 /* was 0x02400000 */
815+
816+ /* ZQ_EN */
645817#define DDR_ZQ_CNTL_VAL 0x8A090705
646818
819+ /* WRLVL_EN [0]: 1: Write Leveling Enable
820+ * WRLVL_MRD [5-7]: 110 0x6: 64 clocks
821+ * WRLVL_ODTEN[9-11]: 111 0x7: 128 clocks ODT delay after margining mode is programmed (tWL_ODTEN).
822+ * WRLVL_DQSEN[13-15]: 101 0x5: 32 clocks DQS/DQS_B delay after margining mode is programmed (tWL_DQSEN).
823+ * WRLVL_SMPL [16-19]: 1111 0xF: 15 clocks Write leveling sample time
824+ * WRLVL_WLR [21-23]: 110 0x6: 64 clocks Write leveling repetition time.
825+ * WRLVL_START[27-31]: 1000 0x8: 3/4 clocks Write leveling start time for DQS[0].
826+ */
647827#define DDR_WRLVL_CNTL_VAL 0x8675F606
828+ /* WRLVL_START_1 [3-7]: 3/4 Write leveling start time for DQS[1]
829+ * WRLVL_START_2[11-15]: 7/8 Write leveling start time for DQS[2]
830+ * WRLVL_START_3[19-23]: 7/8 Write leveling start time for DQS[3]
831+ * WRLVL_START_4[27-31]: 9/8 Write leveling start time for DQS[4]
832+ */
648833#define DDR_WRLVL_CNTL_2_VAL 0x06070709
834+ /* WRLVL_START_5 [3-7]: 9/8 Write leveling start time for DQS[5]
835+ * WRLVL_START_6[11-15]: 9/8 Write leveling start time for DQS[6]
836+ * WRLVL_START_7[19-23]: 9/8 Write leveling start time for DQS[7]
837+ * WRLVL_START_8[27-31]: 1 Write leveling start time for DQS[8]
838+ */
649839#define DDR_WRLVL_CNTL_3_VAL 0x09090908
650840
651841#define DDR_SDRAM_RCW_1_VAL 0x00000000
652842#define DDR_SDRAM_RCW_2_VAL 0x00000000
653843
654- #define DDR_DDRCDR_1_VAL 0x80080000
844+
845+ /* DHC_EN[0]=1, ODT[12-13]=120 Ohms, VREF_OVRD 37% */
846+ #define DDR_DDRCDR_1_VAL 0x80000000 /* was 0x80080000 */
655847#define DDR_DDRCDR_2_VAL 0x00000000
656848
657849#define DDR_ERR_INT_EN_VAL 0x0000001D
@@ -1153,10 +1345,12 @@ static void hal_ddr_init(void)
11531345 set32 (DDR_TIMING_CFG_2 , DDR_TIMING_CFG_2_VAL );
11541346 set32 (DDR_TIMING_CFG_4 , DDR_TIMING_CFG_4_VAL );
11551347 set32 (DDR_TIMING_CFG_5 , DDR_TIMING_CFG_5_VAL );
1348+ set32 (DDR_TIMING_CFG_6 , DDR_TIMING_CFG_6_VAL );
1349+ set32 (DDR_TIMING_CFG_7 , DDR_TIMING_CFG_7_VAL );
11561350 set32 (DDR_TIMING_CFG_8 , DDR_TIMING_CFG_8_VAL );
11571351
11581352 set32 (DDR_ZQ_CNTL , DDR_ZQ_CNTL_VAL );
1159- set32 (DDR_SDRAM_CFG_3 , 0 );
1353+ set32 (DDR_SDRAM_CFG_3 , DDR_SDRAM_CFG_3_VAL );
11601354
11611355 /* DDR SDRAM mode configuration */
11621356 set32 (DDR_SDRAM_MODE , DDR_SDRAM_MODE_VAL );
0 commit comments