xref: /openbmc/u-boot/arch/arm/include/asm/emif.h (revision 8a8af8a2fd5cbe98b5680ba6822fe38686b6bdb6)
1bb772a59SSricharan /*
2bb772a59SSricharan  * OMAP44xx EMIF header
3bb772a59SSricharan  *
4bb772a59SSricharan  * Copyright (C) 2009-2010 Texas Instruments, Inc.
5bb772a59SSricharan  *
6bb772a59SSricharan  * Aneesh V <aneesh@ti.com>
7bb772a59SSricharan  *
8bb772a59SSricharan  * This program is free software; you can redistribute it and/or modify
9bb772a59SSricharan  * it under the terms of the GNU General Public License version 2 as
10bb772a59SSricharan  * published by the Free Software Foundation.
11bb772a59SSricharan  */
12bb772a59SSricharan 
13bb772a59SSricharan #ifndef _EMIF_H_
14bb772a59SSricharan #define _EMIF_H_
15bb772a59SSricharan #include <asm/types.h>
16bb772a59SSricharan #include <common.h>
17d3daba10SLokesh Vutla #include <asm/io.h>
18bb772a59SSricharan 
19bb772a59SSricharan /* Base address */
20*8a8af8a2SLokesh Vutla #ifndef EMIF1_BASE
21bb772a59SSricharan #define EMIF1_BASE				0x4c000000
22*8a8af8a2SLokesh Vutla #endif
23bb772a59SSricharan #define EMIF2_BASE				0x4d000000
24bb772a59SSricharan 
25d3daba10SLokesh Vutla #define EMIF_4D					0x4
26d3daba10SLokesh Vutla #define EMIF_4D5				0x5
27d3daba10SLokesh Vutla 
28fda35eb9STom Rini /* Registers shifts, masks and values */
29bb772a59SSricharan 
30bb772a59SSricharan /* EMIF_MOD_ID_REV */
31bb772a59SSricharan #define EMIF_REG_SCHEME_SHIFT			30
32bb772a59SSricharan #define EMIF_REG_SCHEME_MASK			(0x3 << 30)
33bb772a59SSricharan #define EMIF_REG_MODULE_ID_SHIFT			16
34bb772a59SSricharan #define EMIF_REG_MODULE_ID_MASK			(0xfff << 16)
35bb772a59SSricharan #define EMIF_REG_RTL_VERSION_SHIFT			11
36bb772a59SSricharan #define EMIF_REG_RTL_VERSION_MASK			(0x1f << 11)
37bb772a59SSricharan #define EMIF_REG_MAJOR_REVISION_SHIFT		8
38bb772a59SSricharan #define EMIF_REG_MAJOR_REVISION_MASK		(0x7 << 8)
39bb772a59SSricharan #define EMIF_REG_MINOR_REVISION_SHIFT		0
40bb772a59SSricharan #define EMIF_REG_MINOR_REVISION_MASK		(0x3f << 0)
41bb772a59SSricharan 
42bb772a59SSricharan /* STATUS */
43bb772a59SSricharan #define EMIF_REG_BE_SHIFT				31
44bb772a59SSricharan #define EMIF_REG_BE_MASK				(1 << 31)
45bb772a59SSricharan #define EMIF_REG_DUAL_CLK_MODE_SHIFT		30
46bb772a59SSricharan #define EMIF_REG_DUAL_CLK_MODE_MASK			(1 << 30)
47bb772a59SSricharan #define EMIF_REG_FAST_INIT_SHIFT			29
48bb772a59SSricharan #define EMIF_REG_FAST_INIT_MASK			(1 << 29)
496213db78SLokesh Vutla #define EMIF_REG_LEVLING_TO_SHIFT		4
506213db78SLokesh Vutla #define EMIF_REG_LEVELING_TO_MASK		(7 << 4)
51bb772a59SSricharan #define EMIF_REG_PHY_DLL_READY_SHIFT		2
52bb772a59SSricharan #define EMIF_REG_PHY_DLL_READY_MASK			(1 << 2)
53bb772a59SSricharan 
54bb772a59SSricharan /* SDRAM_CONFIG */
55bb772a59SSricharan #define EMIF_REG_SDRAM_TYPE_SHIFT			29
56bb772a59SSricharan #define EMIF_REG_SDRAM_TYPE_MASK			(0x7 << 29)
57fda35eb9STom Rini #define EMIF_REG_SDRAM_TYPE_DDR1			0
58fda35eb9STom Rini #define EMIF_REG_SDRAM_TYPE_LPDDR1			1
59fda35eb9STom Rini #define EMIF_REG_SDRAM_TYPE_DDR2			2
60fda35eb9STom Rini #define EMIF_REG_SDRAM_TYPE_DDR3			3
61fda35eb9STom Rini #define EMIF_REG_SDRAM_TYPE_LPDDR2_S4			4
62fda35eb9STom Rini #define EMIF_REG_SDRAM_TYPE_LPDDR2_S2			5
63bb772a59SSricharan #define EMIF_REG_IBANK_POS_SHIFT			27
64bb772a59SSricharan #define EMIF_REG_IBANK_POS_MASK			(0x3 << 27)
65bb772a59SSricharan #define EMIF_REG_DDR_TERM_SHIFT			24
66bb772a59SSricharan #define EMIF_REG_DDR_TERM_MASK			(0x7 << 24)
67bb772a59SSricharan #define EMIF_REG_DDR2_DDQS_SHIFT			23
68bb772a59SSricharan #define EMIF_REG_DDR2_DDQS_MASK			(1 << 23)
69bb772a59SSricharan #define EMIF_REG_DYN_ODT_SHIFT			21
70bb772a59SSricharan #define EMIF_REG_DYN_ODT_MASK			(0x3 << 21)
71bb772a59SSricharan #define EMIF_REG_DDR_DISABLE_DLL_SHIFT		20
72bb772a59SSricharan #define EMIF_REG_DDR_DISABLE_DLL_MASK		(1 << 20)
73bb772a59SSricharan #define EMIF_REG_SDRAM_DRIVE_SHIFT			18
74bb772a59SSricharan #define EMIF_REG_SDRAM_DRIVE_MASK			(0x3 << 18)
75bb772a59SSricharan #define EMIF_REG_CWL_SHIFT				16
76bb772a59SSricharan #define EMIF_REG_CWL_MASK				(0x3 << 16)
77bb772a59SSricharan #define EMIF_REG_NARROW_MODE_SHIFT			14
78bb772a59SSricharan #define EMIF_REG_NARROW_MODE_MASK			(0x3 << 14)
79bb772a59SSricharan #define EMIF_REG_CL_SHIFT				10
80bb772a59SSricharan #define EMIF_REG_CL_MASK				(0xf << 10)
81bb772a59SSricharan #define EMIF_REG_ROWSIZE_SHIFT			7
82bb772a59SSricharan #define EMIF_REG_ROWSIZE_MASK			(0x7 << 7)
83bb772a59SSricharan #define EMIF_REG_IBANK_SHIFT			4
84bb772a59SSricharan #define EMIF_REG_IBANK_MASK				(0x7 << 4)
85bb772a59SSricharan #define EMIF_REG_EBANK_SHIFT			3
86bb772a59SSricharan #define EMIF_REG_EBANK_MASK				(1 << 3)
87bb772a59SSricharan #define EMIF_REG_PAGESIZE_SHIFT			0
88bb772a59SSricharan #define EMIF_REG_PAGESIZE_MASK			(0x7 << 0)
89bb772a59SSricharan 
90bb772a59SSricharan /* SDRAM_CONFIG_2 */
91bb772a59SSricharan #define EMIF_REG_CS1NVMEN_SHIFT			30
92bb772a59SSricharan #define EMIF_REG_CS1NVMEN_MASK			(1 << 30)
93bb772a59SSricharan #define EMIF_REG_EBANK_POS_SHIFT			27
94bb772a59SSricharan #define EMIF_REG_EBANK_POS_MASK			(1 << 27)
95bb772a59SSricharan #define EMIF_REG_RDBNUM_SHIFT			4
96bb772a59SSricharan #define EMIF_REG_RDBNUM_MASK			(0x3 << 4)
97bb772a59SSricharan #define EMIF_REG_RDBSIZE_SHIFT			0
98bb772a59SSricharan #define EMIF_REG_RDBSIZE_MASK			(0x7 << 0)
99bb772a59SSricharan 
100bb772a59SSricharan /* SDRAM_REF_CTRL */
101bb772a59SSricharan #define EMIF_REG_INITREF_DIS_SHIFT			31
102bb772a59SSricharan #define EMIF_REG_INITREF_DIS_MASK			(1 << 31)
103bb772a59SSricharan #define EMIF_REG_SRT_SHIFT				29
104bb772a59SSricharan #define EMIF_REG_SRT_MASK				(1 << 29)
105bb772a59SSricharan #define EMIF_REG_ASR_SHIFT				28
106bb772a59SSricharan #define EMIF_REG_ASR_MASK				(1 << 28)
107bb772a59SSricharan #define EMIF_REG_PASR_SHIFT				24
108bb772a59SSricharan #define EMIF_REG_PASR_MASK				(0x7 << 24)
109bb772a59SSricharan #define EMIF_REG_REFRESH_RATE_SHIFT			0
110bb772a59SSricharan #define EMIF_REG_REFRESH_RATE_MASK			(0xffff << 0)
111bb772a59SSricharan 
112bb772a59SSricharan /* SDRAM_REF_CTRL_SHDW */
113bb772a59SSricharan #define EMIF_REG_REFRESH_RATE_SHDW_SHIFT		0
114bb772a59SSricharan #define EMIF_REG_REFRESH_RATE_SHDW_MASK		(0xffff << 0)
115bb772a59SSricharan 
116bb772a59SSricharan /* SDRAM_TIM_1 */
117bb772a59SSricharan #define EMIF_REG_T_RP_SHIFT				25
118bb772a59SSricharan #define EMIF_REG_T_RP_MASK				(0xf << 25)
119bb772a59SSricharan #define EMIF_REG_T_RCD_SHIFT			21
120bb772a59SSricharan #define EMIF_REG_T_RCD_MASK				(0xf << 21)
121bb772a59SSricharan #define EMIF_REG_T_WR_SHIFT				17
122bb772a59SSricharan #define EMIF_REG_T_WR_MASK				(0xf << 17)
123bb772a59SSricharan #define EMIF_REG_T_RAS_SHIFT			12
124bb772a59SSricharan #define EMIF_REG_T_RAS_MASK				(0x1f << 12)
125bb772a59SSricharan #define EMIF_REG_T_RC_SHIFT				6
126bb772a59SSricharan #define EMIF_REG_T_RC_MASK				(0x3f << 6)
127bb772a59SSricharan #define EMIF_REG_T_RRD_SHIFT			3
128bb772a59SSricharan #define EMIF_REG_T_RRD_MASK				(0x7 << 3)
129bb772a59SSricharan #define EMIF_REG_T_WTR_SHIFT			0
130bb772a59SSricharan #define EMIF_REG_T_WTR_MASK				(0x7 << 0)
131bb772a59SSricharan 
132bb772a59SSricharan /* SDRAM_TIM_1_SHDW */
133bb772a59SSricharan #define EMIF_REG_T_RP_SHDW_SHIFT			25
134bb772a59SSricharan #define EMIF_REG_T_RP_SHDW_MASK			(0xf << 25)
135bb772a59SSricharan #define EMIF_REG_T_RCD_SHDW_SHIFT			21
136bb772a59SSricharan #define EMIF_REG_T_RCD_SHDW_MASK			(0xf << 21)
137bb772a59SSricharan #define EMIF_REG_T_WR_SHDW_SHIFT			17
138bb772a59SSricharan #define EMIF_REG_T_WR_SHDW_MASK			(0xf << 17)
139bb772a59SSricharan #define EMIF_REG_T_RAS_SHDW_SHIFT			12
140bb772a59SSricharan #define EMIF_REG_T_RAS_SHDW_MASK			(0x1f << 12)
141bb772a59SSricharan #define EMIF_REG_T_RC_SHDW_SHIFT			6
142bb772a59SSricharan #define EMIF_REG_T_RC_SHDW_MASK			(0x3f << 6)
143bb772a59SSricharan #define EMIF_REG_T_RRD_SHDW_SHIFT			3
144bb772a59SSricharan #define EMIF_REG_T_RRD_SHDW_MASK			(0x7 << 3)
145bb772a59SSricharan #define EMIF_REG_T_WTR_SHDW_SHIFT			0
146bb772a59SSricharan #define EMIF_REG_T_WTR_SHDW_MASK			(0x7 << 0)
147bb772a59SSricharan 
148bb772a59SSricharan /* SDRAM_TIM_2 */
149bb772a59SSricharan #define EMIF_REG_T_XP_SHIFT				28
150bb772a59SSricharan #define EMIF_REG_T_XP_MASK				(0x7 << 28)
151bb772a59SSricharan #define EMIF_REG_T_ODT_SHIFT			25
152bb772a59SSricharan #define EMIF_REG_T_ODT_MASK				(0x7 << 25)
153bb772a59SSricharan #define EMIF_REG_T_XSNR_SHIFT			16
154bb772a59SSricharan #define EMIF_REG_T_XSNR_MASK			(0x1ff << 16)
155bb772a59SSricharan #define EMIF_REG_T_XSRD_SHIFT			6
156bb772a59SSricharan #define EMIF_REG_T_XSRD_MASK			(0x3ff << 6)
157bb772a59SSricharan #define EMIF_REG_T_RTP_SHIFT			3
158bb772a59SSricharan #define EMIF_REG_T_RTP_MASK				(0x7 << 3)
159bb772a59SSricharan #define EMIF_REG_T_CKE_SHIFT			0
160bb772a59SSricharan #define EMIF_REG_T_CKE_MASK				(0x7 << 0)
161bb772a59SSricharan 
162bb772a59SSricharan /* SDRAM_TIM_2_SHDW */
163bb772a59SSricharan #define EMIF_REG_T_XP_SHDW_SHIFT			28
164bb772a59SSricharan #define EMIF_REG_T_XP_SHDW_MASK			(0x7 << 28)
165bb772a59SSricharan #define EMIF_REG_T_ODT_SHDW_SHIFT			25
166bb772a59SSricharan #define EMIF_REG_T_ODT_SHDW_MASK			(0x7 << 25)
167bb772a59SSricharan #define EMIF_REG_T_XSNR_SHDW_SHIFT			16
168bb772a59SSricharan #define EMIF_REG_T_XSNR_SHDW_MASK			(0x1ff << 16)
169bb772a59SSricharan #define EMIF_REG_T_XSRD_SHDW_SHIFT			6
170bb772a59SSricharan #define EMIF_REG_T_XSRD_SHDW_MASK			(0x3ff << 6)
171bb772a59SSricharan #define EMIF_REG_T_RTP_SHDW_SHIFT			3
172bb772a59SSricharan #define EMIF_REG_T_RTP_SHDW_MASK			(0x7 << 3)
173bb772a59SSricharan #define EMIF_REG_T_CKE_SHDW_SHIFT			0
174bb772a59SSricharan #define EMIF_REG_T_CKE_SHDW_MASK			(0x7 << 0)
175bb772a59SSricharan 
176bb772a59SSricharan /* SDRAM_TIM_3 */
177bb772a59SSricharan #define EMIF_REG_T_CKESR_SHIFT			21
178bb772a59SSricharan #define EMIF_REG_T_CKESR_MASK			(0x7 << 21)
179bb772a59SSricharan #define EMIF_REG_ZQ_ZQCS_SHIFT			15
180bb772a59SSricharan #define EMIF_REG_ZQ_ZQCS_MASK			(0x3f << 15)
181bb772a59SSricharan #define EMIF_REG_T_TDQSCKMAX_SHIFT			13
182bb772a59SSricharan #define EMIF_REG_T_TDQSCKMAX_MASK			(0x3 << 13)
183bb772a59SSricharan #define EMIF_REG_T_RFC_SHIFT			4
184bb772a59SSricharan #define EMIF_REG_T_RFC_MASK				(0x1ff << 4)
185bb772a59SSricharan #define EMIF_REG_T_RAS_MAX_SHIFT			0
186bb772a59SSricharan #define EMIF_REG_T_RAS_MAX_MASK			(0xf << 0)
187bb772a59SSricharan 
188bb772a59SSricharan /* SDRAM_TIM_3_SHDW */
189bb772a59SSricharan #define EMIF_REG_T_CKESR_SHDW_SHIFT			21
190bb772a59SSricharan #define EMIF_REG_T_CKESR_SHDW_MASK			(0x7 << 21)
191bb772a59SSricharan #define EMIF_REG_ZQ_ZQCS_SHDW_SHIFT			15
192bb772a59SSricharan #define EMIF_REG_ZQ_ZQCS_SHDW_MASK			(0x3f << 15)
193bb772a59SSricharan #define EMIF_REG_T_TDQSCKMAX_SHDW_SHIFT		13
194bb772a59SSricharan #define EMIF_REG_T_TDQSCKMAX_SHDW_MASK		(0x3 << 13)
195bb772a59SSricharan #define EMIF_REG_T_RFC_SHDW_SHIFT			4
196bb772a59SSricharan #define EMIF_REG_T_RFC_SHDW_MASK			(0x1ff << 4)
197bb772a59SSricharan #define EMIF_REG_T_RAS_MAX_SHDW_SHIFT		0
198bb772a59SSricharan #define EMIF_REG_T_RAS_MAX_SHDW_MASK		(0xf << 0)
199bb772a59SSricharan 
200bb772a59SSricharan /* LPDDR2_NVM_TIM */
201bb772a59SSricharan #define EMIF_REG_NVM_T_XP_SHIFT			28
202bb772a59SSricharan #define EMIF_REG_NVM_T_XP_MASK			(0x7 << 28)
203bb772a59SSricharan #define EMIF_REG_NVM_T_WTR_SHIFT			24
204bb772a59SSricharan #define EMIF_REG_NVM_T_WTR_MASK			(0x7 << 24)
205bb772a59SSricharan #define EMIF_REG_NVM_T_RP_SHIFT			20
206bb772a59SSricharan #define EMIF_REG_NVM_T_RP_MASK			(0xf << 20)
207bb772a59SSricharan #define EMIF_REG_NVM_T_WRA_SHIFT			16
208bb772a59SSricharan #define EMIF_REG_NVM_T_WRA_MASK			(0xf << 16)
209bb772a59SSricharan #define EMIF_REG_NVM_T_RRD_SHIFT			8
210bb772a59SSricharan #define EMIF_REG_NVM_T_RRD_MASK			(0xff << 8)
211bb772a59SSricharan #define EMIF_REG_NVM_T_RCDMIN_SHIFT			0
212bb772a59SSricharan #define EMIF_REG_NVM_T_RCDMIN_MASK			(0xff << 0)
213bb772a59SSricharan 
214bb772a59SSricharan /* LPDDR2_NVM_TIM_SHDW */
215bb772a59SSricharan #define EMIF_REG_NVM_T_XP_SHDW_SHIFT		28
216bb772a59SSricharan #define EMIF_REG_NVM_T_XP_SHDW_MASK			(0x7 << 28)
217bb772a59SSricharan #define EMIF_REG_NVM_T_WTR_SHDW_SHIFT		24
218bb772a59SSricharan #define EMIF_REG_NVM_T_WTR_SHDW_MASK		(0x7 << 24)
219bb772a59SSricharan #define EMIF_REG_NVM_T_RP_SHDW_SHIFT		20
220bb772a59SSricharan #define EMIF_REG_NVM_T_RP_SHDW_MASK			(0xf << 20)
221bb772a59SSricharan #define EMIF_REG_NVM_T_WRA_SHDW_SHIFT		16
222bb772a59SSricharan #define EMIF_REG_NVM_T_WRA_SHDW_MASK		(0xf << 16)
223bb772a59SSricharan #define EMIF_REG_NVM_T_RRD_SHDW_SHIFT		8
224bb772a59SSricharan #define EMIF_REG_NVM_T_RRD_SHDW_MASK		(0xff << 8)
225bb772a59SSricharan #define EMIF_REG_NVM_T_RCDMIN_SHDW_SHIFT		0
226bb772a59SSricharan #define EMIF_REG_NVM_T_RCDMIN_SHDW_MASK		(0xff << 0)
227bb772a59SSricharan 
228bb772a59SSricharan /* PWR_MGMT_CTRL */
229bb772a59SSricharan #define EMIF_REG_IDLEMODE_SHIFT			30
230bb772a59SSricharan #define EMIF_REG_IDLEMODE_MASK			(0x3 << 30)
231bb772a59SSricharan #define EMIF_REG_PD_TIM_SHIFT			12
232bb772a59SSricharan #define EMIF_REG_PD_TIM_MASK			(0xf << 12)
233bb772a59SSricharan #define EMIF_REG_DPD_EN_SHIFT			11
234bb772a59SSricharan #define EMIF_REG_DPD_EN_MASK			(1 << 11)
235bb772a59SSricharan #define EMIF_REG_LP_MODE_SHIFT			8
236bb772a59SSricharan #define EMIF_REG_LP_MODE_MASK			(0x7 << 8)
237bb772a59SSricharan #define EMIF_REG_SR_TIM_SHIFT			4
238bb772a59SSricharan #define EMIF_REG_SR_TIM_MASK			(0xf << 4)
239bb772a59SSricharan #define EMIF_REG_CS_TIM_SHIFT			0
240bb772a59SSricharan #define EMIF_REG_CS_TIM_MASK			(0xf << 0)
241bb772a59SSricharan 
242bb772a59SSricharan /* PWR_MGMT_CTRL_SHDW */
243aaec4487SSRICHARAN R #define EMIF_REG_PD_TIM_SHDW_SHIFT			12
244aaec4487SSRICHARAN R #define EMIF_REG_PD_TIM_SHDW_MASK			(0xf << 12)
245bb772a59SSricharan #define EMIF_REG_SR_TIM_SHDW_SHIFT			4
246bb772a59SSricharan #define EMIF_REG_SR_TIM_SHDW_MASK			(0xf << 4)
247bb772a59SSricharan #define EMIF_REG_CS_TIM_SHDW_SHIFT			0
248bb772a59SSricharan #define EMIF_REG_CS_TIM_SHDW_MASK			(0xf << 0)
249bb772a59SSricharan 
250bb772a59SSricharan /* LPDDR2_MODE_REG_DATA */
251bb772a59SSricharan #define EMIF_REG_VALUE_0_SHIFT			0
252bb772a59SSricharan #define EMIF_REG_VALUE_0_MASK			(0x7f << 0)
253bb772a59SSricharan 
254bb772a59SSricharan /* LPDDR2_MODE_REG_CFG */
255bb772a59SSricharan #define EMIF_REG_CS_SHIFT				31
256bb772a59SSricharan #define EMIF_REG_CS_MASK				(1 << 31)
257bb772a59SSricharan #define EMIF_REG_REFRESH_EN_SHIFT			30
258bb772a59SSricharan #define EMIF_REG_REFRESH_EN_MASK			(1 << 30)
259bb772a59SSricharan #define EMIF_REG_ADDRESS_SHIFT			0
260bb772a59SSricharan #define EMIF_REG_ADDRESS_MASK			(0xff << 0)
261bb772a59SSricharan 
262bb772a59SSricharan /* OCP_CONFIG */
263bb772a59SSricharan #define EMIF_REG_SYS_THRESH_MAX_SHIFT		24
264bb772a59SSricharan #define EMIF_REG_SYS_THRESH_MAX_MASK		(0xf << 24)
265bb772a59SSricharan #define EMIF_REG_MPU_THRESH_MAX_SHIFT		20
266bb772a59SSricharan #define EMIF_REG_MPU_THRESH_MAX_MASK		(0xf << 20)
267bb772a59SSricharan #define EMIF_REG_LL_THRESH_MAX_SHIFT		16
268bb772a59SSricharan #define EMIF_REG_LL_THRESH_MAX_MASK			(0xf << 16)
269bb772a59SSricharan #define EMIF_REG_PR_OLD_COUNT_SHIFT			0
270bb772a59SSricharan #define EMIF_REG_PR_OLD_COUNT_MASK			(0xff << 0)
271bb772a59SSricharan 
272bb772a59SSricharan /* OCP_CFG_VAL_1 */
273bb772a59SSricharan #define EMIF_REG_SYS_BUS_WIDTH_SHIFT		30
274bb772a59SSricharan #define EMIF_REG_SYS_BUS_WIDTH_MASK			(0x3 << 30)
275bb772a59SSricharan #define EMIF_REG_LL_BUS_WIDTH_SHIFT			28
276bb772a59SSricharan #define EMIF_REG_LL_BUS_WIDTH_MASK			(0x3 << 28)
277bb772a59SSricharan #define EMIF_REG_WR_FIFO_DEPTH_SHIFT		8
278bb772a59SSricharan #define EMIF_REG_WR_FIFO_DEPTH_MASK			(0xff << 8)
279bb772a59SSricharan #define EMIF_REG_CMD_FIFO_DEPTH_SHIFT		0
280bb772a59SSricharan #define EMIF_REG_CMD_FIFO_DEPTH_MASK		(0xff << 0)
281bb772a59SSricharan 
282bb772a59SSricharan /* OCP_CFG_VAL_2 */
283bb772a59SSricharan #define EMIF_REG_RREG_FIFO_DEPTH_SHIFT		16
284bb772a59SSricharan #define EMIF_REG_RREG_FIFO_DEPTH_MASK		(0xff << 16)
285bb772a59SSricharan #define EMIF_REG_RSD_FIFO_DEPTH_SHIFT		8
286bb772a59SSricharan #define EMIF_REG_RSD_FIFO_DEPTH_MASK		(0xff << 8)
287bb772a59SSricharan #define EMIF_REG_RCMD_FIFO_DEPTH_SHIFT		0
288bb772a59SSricharan #define EMIF_REG_RCMD_FIFO_DEPTH_MASK		(0xff << 0)
289bb772a59SSricharan 
290bb772a59SSricharan /* IODFT_TLGC */
291bb772a59SSricharan #define EMIF_REG_TLEC_SHIFT				16
292bb772a59SSricharan #define EMIF_REG_TLEC_MASK				(0xffff << 16)
293bb772a59SSricharan #define EMIF_REG_MT_SHIFT				14
294bb772a59SSricharan #define EMIF_REG_MT_MASK				(1 << 14)
295bb772a59SSricharan #define EMIF_REG_ACT_CAP_EN_SHIFT			13
296bb772a59SSricharan #define EMIF_REG_ACT_CAP_EN_MASK			(1 << 13)
297bb772a59SSricharan #define EMIF_REG_OPG_LD_SHIFT			12
298bb772a59SSricharan #define EMIF_REG_OPG_LD_MASK			(1 << 12)
299bb772a59SSricharan #define EMIF_REG_RESET_PHY_SHIFT			10
300bb772a59SSricharan #define EMIF_REG_RESET_PHY_MASK			(1 << 10)
301bb772a59SSricharan #define EMIF_REG_MMS_SHIFT				8
302bb772a59SSricharan #define EMIF_REG_MMS_MASK				(1 << 8)
303bb772a59SSricharan #define EMIF_REG_MC_SHIFT				4
304bb772a59SSricharan #define EMIF_REG_MC_MASK				(0x3 << 4)
305bb772a59SSricharan #define EMIF_REG_PC_SHIFT				1
306bb772a59SSricharan #define EMIF_REG_PC_MASK				(0x7 << 1)
307bb772a59SSricharan #define EMIF_REG_TM_SHIFT				0
308bb772a59SSricharan #define EMIF_REG_TM_MASK				(1 << 0)
309bb772a59SSricharan 
310bb772a59SSricharan /* IODFT_CTRL_MISR_RSLT */
311bb772a59SSricharan #define EMIF_REG_DQM_TLMR_SHIFT			16
312bb772a59SSricharan #define EMIF_REG_DQM_TLMR_MASK			(0x3ff << 16)
313bb772a59SSricharan #define EMIF_REG_CTL_TLMR_SHIFT			0
314bb772a59SSricharan #define EMIF_REG_CTL_TLMR_MASK			(0x7ff << 0)
315bb772a59SSricharan 
316bb772a59SSricharan /* IODFT_ADDR_MISR_RSLT */
317bb772a59SSricharan #define EMIF_REG_ADDR_TLMR_SHIFT			0
318bb772a59SSricharan #define EMIF_REG_ADDR_TLMR_MASK			(0x1fffff << 0)
319bb772a59SSricharan 
320bb772a59SSricharan /* IODFT_DATA_MISR_RSLT_1 */
321bb772a59SSricharan #define EMIF_REG_DATA_TLMR_31_0_SHIFT		0
322bb772a59SSricharan #define EMIF_REG_DATA_TLMR_31_0_MASK		(0xffffffff << 0)
323bb772a59SSricharan 
324bb772a59SSricharan /* IODFT_DATA_MISR_RSLT_2 */
325bb772a59SSricharan #define EMIF_REG_DATA_TLMR_63_32_SHIFT		0
326bb772a59SSricharan #define EMIF_REG_DATA_TLMR_63_32_MASK		(0xffffffff << 0)
327bb772a59SSricharan 
328bb772a59SSricharan /* IODFT_DATA_MISR_RSLT_3 */
329bb772a59SSricharan #define EMIF_REG_DATA_TLMR_66_64_SHIFT		0
330bb772a59SSricharan #define EMIF_REG_DATA_TLMR_66_64_MASK		(0x7 << 0)
331bb772a59SSricharan 
332bb772a59SSricharan /* PERF_CNT_1 */
333bb772a59SSricharan #define EMIF_REG_COUNTER1_SHIFT			0
334bb772a59SSricharan #define EMIF_REG_COUNTER1_MASK			(0xffffffff << 0)
335bb772a59SSricharan 
336bb772a59SSricharan /* PERF_CNT_2 */
337bb772a59SSricharan #define EMIF_REG_COUNTER2_SHIFT			0
338bb772a59SSricharan #define EMIF_REG_COUNTER2_MASK			(0xffffffff << 0)
339bb772a59SSricharan 
340bb772a59SSricharan /* PERF_CNT_CFG */
341bb772a59SSricharan #define EMIF_REG_CNTR2_MCONNID_EN_SHIFT		31
342bb772a59SSricharan #define EMIF_REG_CNTR2_MCONNID_EN_MASK		(1 << 31)
343bb772a59SSricharan #define EMIF_REG_CNTR2_REGION_EN_SHIFT		30
344bb772a59SSricharan #define EMIF_REG_CNTR2_REGION_EN_MASK		(1 << 30)
345bb772a59SSricharan #define EMIF_REG_CNTR2_CFG_SHIFT			16
346bb772a59SSricharan #define EMIF_REG_CNTR2_CFG_MASK			(0xf << 16)
347bb772a59SSricharan #define EMIF_REG_CNTR1_MCONNID_EN_SHIFT		15
348bb772a59SSricharan #define EMIF_REG_CNTR1_MCONNID_EN_MASK		(1 << 15)
349bb772a59SSricharan #define EMIF_REG_CNTR1_REGION_EN_SHIFT		14
350bb772a59SSricharan #define EMIF_REG_CNTR1_REGION_EN_MASK		(1 << 14)
351bb772a59SSricharan #define EMIF_REG_CNTR1_CFG_SHIFT			0
352bb772a59SSricharan #define EMIF_REG_CNTR1_CFG_MASK			(0xf << 0)
353bb772a59SSricharan 
354bb772a59SSricharan /* PERF_CNT_SEL */
355bb772a59SSricharan #define EMIF_REG_MCONNID2_SHIFT			24
356bb772a59SSricharan #define EMIF_REG_MCONNID2_MASK			(0xff << 24)
357bb772a59SSricharan #define EMIF_REG_REGION_SEL2_SHIFT			16
358bb772a59SSricharan #define EMIF_REG_REGION_SEL2_MASK			(0x3 << 16)
359bb772a59SSricharan #define EMIF_REG_MCONNID1_SHIFT			8
360bb772a59SSricharan #define EMIF_REG_MCONNID1_MASK			(0xff << 8)
361bb772a59SSricharan #define EMIF_REG_REGION_SEL1_SHIFT			0
362bb772a59SSricharan #define EMIF_REG_REGION_SEL1_MASK			(0x3 << 0)
363bb772a59SSricharan 
364bb772a59SSricharan /* PERF_CNT_TIM */
365bb772a59SSricharan #define EMIF_REG_TOTAL_TIME_SHIFT			0
366bb772a59SSricharan #define EMIF_REG_TOTAL_TIME_MASK			(0xffffffff << 0)
367bb772a59SSricharan 
368bb772a59SSricharan /* READ_IDLE_CTRL */
369bb772a59SSricharan #define EMIF_REG_READ_IDLE_LEN_SHIFT		16
370bb772a59SSricharan #define EMIF_REG_READ_IDLE_LEN_MASK			(0xf << 16)
371bb772a59SSricharan #define EMIF_REG_READ_IDLE_INTERVAL_SHIFT		0
372bb772a59SSricharan #define EMIF_REG_READ_IDLE_INTERVAL_MASK		(0x1ff << 0)
373bb772a59SSricharan 
374bb772a59SSricharan /* READ_IDLE_CTRL_SHDW */
375bb772a59SSricharan #define EMIF_REG_READ_IDLE_LEN_SHDW_SHIFT		16
376bb772a59SSricharan #define EMIF_REG_READ_IDLE_LEN_SHDW_MASK		(0xf << 16)
377bb772a59SSricharan #define EMIF_REG_READ_IDLE_INTERVAL_SHDW_SHIFT	0
378bb772a59SSricharan #define EMIF_REG_READ_IDLE_INTERVAL_SHDW_MASK	(0x1ff << 0)
379bb772a59SSricharan 
380bb772a59SSricharan /* IRQ_EOI */
381bb772a59SSricharan #define EMIF_REG_EOI_SHIFT				0
382bb772a59SSricharan #define EMIF_REG_EOI_MASK				(1 << 0)
383bb772a59SSricharan 
384bb772a59SSricharan /* IRQSTATUS_RAW_SYS */
385bb772a59SSricharan #define EMIF_REG_DNV_SYS_SHIFT			2
386bb772a59SSricharan #define EMIF_REG_DNV_SYS_MASK			(1 << 2)
387bb772a59SSricharan #define EMIF_REG_TA_SYS_SHIFT			1
388bb772a59SSricharan #define EMIF_REG_TA_SYS_MASK			(1 << 1)
389bb772a59SSricharan #define EMIF_REG_ERR_SYS_SHIFT			0
390bb772a59SSricharan #define EMIF_REG_ERR_SYS_MASK			(1 << 0)
391bb772a59SSricharan 
392bb772a59SSricharan /* IRQSTATUS_RAW_LL */
393bb772a59SSricharan #define EMIF_REG_DNV_LL_SHIFT			2
394bb772a59SSricharan #define EMIF_REG_DNV_LL_MASK			(1 << 2)
395bb772a59SSricharan #define EMIF_REG_TA_LL_SHIFT			1
396bb772a59SSricharan #define EMIF_REG_TA_LL_MASK				(1 << 1)
397bb772a59SSricharan #define EMIF_REG_ERR_LL_SHIFT			0
398bb772a59SSricharan #define EMIF_REG_ERR_LL_MASK			(1 << 0)
399bb772a59SSricharan 
400bb772a59SSricharan /* IRQSTATUS_SYS */
401bb772a59SSricharan 
402bb772a59SSricharan /* IRQSTATUS_LL */
403bb772a59SSricharan 
404bb772a59SSricharan /* IRQENABLE_SET_SYS */
405bb772a59SSricharan #define EMIF_REG_EN_DNV_SYS_SHIFT			2
406bb772a59SSricharan #define EMIF_REG_EN_DNV_SYS_MASK			(1 << 2)
407bb772a59SSricharan #define EMIF_REG_EN_TA_SYS_SHIFT			1
408bb772a59SSricharan #define EMIF_REG_EN_TA_SYS_MASK			(1 << 1)
409bb772a59SSricharan #define EMIF_REG_EN_ERR_SYS_SHIFT			0
410bb772a59SSricharan #define EMIF_REG_EN_ERR_SYS_MASK			(1 << 0)
411bb772a59SSricharan 
412bb772a59SSricharan /* IRQENABLE_SET_LL */
413bb772a59SSricharan #define EMIF_REG_EN_DNV_LL_SHIFT			2
414bb772a59SSricharan #define EMIF_REG_EN_DNV_LL_MASK			(1 << 2)
415bb772a59SSricharan #define EMIF_REG_EN_TA_LL_SHIFT			1
416bb772a59SSricharan #define EMIF_REG_EN_TA_LL_MASK			(1 << 1)
417bb772a59SSricharan #define EMIF_REG_EN_ERR_LL_SHIFT			0
418bb772a59SSricharan #define EMIF_REG_EN_ERR_LL_MASK			(1 << 0)
419bb772a59SSricharan 
420bb772a59SSricharan /* IRQENABLE_CLR_SYS */
421bb772a59SSricharan 
422bb772a59SSricharan /* IRQENABLE_CLR_LL */
423bb772a59SSricharan 
424bb772a59SSricharan /* ZQ_CONFIG */
425bb772a59SSricharan #define EMIF_REG_ZQ_CS1EN_SHIFT			31
426bb772a59SSricharan #define EMIF_REG_ZQ_CS1EN_MASK			(1 << 31)
427bb772a59SSricharan #define EMIF_REG_ZQ_CS0EN_SHIFT			30
428bb772a59SSricharan #define EMIF_REG_ZQ_CS0EN_MASK			(1 << 30)
429bb772a59SSricharan #define EMIF_REG_ZQ_DUALCALEN_SHIFT			29
430bb772a59SSricharan #define EMIF_REG_ZQ_DUALCALEN_MASK			(1 << 29)
431bb772a59SSricharan #define EMIF_REG_ZQ_SFEXITEN_SHIFT			28
432bb772a59SSricharan #define EMIF_REG_ZQ_SFEXITEN_MASK			(1 << 28)
433bb772a59SSricharan #define EMIF_REG_ZQ_ZQINIT_MULT_SHIFT		18
434bb772a59SSricharan #define EMIF_REG_ZQ_ZQINIT_MULT_MASK		(0x3 << 18)
435bb772a59SSricharan #define EMIF_REG_ZQ_ZQCL_MULT_SHIFT			16
436bb772a59SSricharan #define EMIF_REG_ZQ_ZQCL_MULT_MASK			(0x3 << 16)
437bb772a59SSricharan #define EMIF_REG_ZQ_REFINTERVAL_SHIFT		0
438bb772a59SSricharan #define EMIF_REG_ZQ_REFINTERVAL_MASK		(0xffff << 0)
439bb772a59SSricharan 
440bb772a59SSricharan /* TEMP_ALERT_CONFIG */
441bb772a59SSricharan #define EMIF_REG_TA_CS1EN_SHIFT			31
442bb772a59SSricharan #define EMIF_REG_TA_CS1EN_MASK			(1 << 31)
443bb772a59SSricharan #define EMIF_REG_TA_CS0EN_SHIFT			30
444bb772a59SSricharan #define EMIF_REG_TA_CS0EN_MASK			(1 << 30)
445bb772a59SSricharan #define EMIF_REG_TA_SFEXITEN_SHIFT			28
446bb772a59SSricharan #define EMIF_REG_TA_SFEXITEN_MASK			(1 << 28)
447bb772a59SSricharan #define EMIF_REG_TA_DEVWDT_SHIFT			26
448bb772a59SSricharan #define EMIF_REG_TA_DEVWDT_MASK			(0x3 << 26)
449bb772a59SSricharan #define EMIF_REG_TA_DEVCNT_SHIFT			24
450bb772a59SSricharan #define EMIF_REG_TA_DEVCNT_MASK			(0x3 << 24)
451bb772a59SSricharan #define EMIF_REG_TA_REFINTERVAL_SHIFT		0
452bb772a59SSricharan #define EMIF_REG_TA_REFINTERVAL_MASK		(0x3fffff << 0)
453bb772a59SSricharan 
454bb772a59SSricharan /* OCP_ERR_LOG */
455bb772a59SSricharan #define EMIF_REG_MADDRSPACE_SHIFT			14
456bb772a59SSricharan #define EMIF_REG_MADDRSPACE_MASK			(0x3 << 14)
457bb772a59SSricharan #define EMIF_REG_MBURSTSEQ_SHIFT			11
458bb772a59SSricharan #define EMIF_REG_MBURSTSEQ_MASK			(0x7 << 11)
459bb772a59SSricharan #define EMIF_REG_MCMD_SHIFT				8
460bb772a59SSricharan #define EMIF_REG_MCMD_MASK				(0x7 << 8)
461bb772a59SSricharan #define EMIF_REG_MCONNID_SHIFT			0
462bb772a59SSricharan #define EMIF_REG_MCONNID_MASK			(0xff << 0)
463bb772a59SSricharan 
464bb772a59SSricharan /* DDR_PHY_CTRL_1 */
465bb772a59SSricharan #define EMIF_REG_DDR_PHY_CTRL_1_SHIFT		4
466bb772a59SSricharan #define EMIF_REG_DDR_PHY_CTRL_1_MASK		(0xfffffff << 4)
467bb772a59SSricharan #define EMIF_REG_READ_LATENCY_SHIFT			0
468bb772a59SSricharan #define EMIF_REG_READ_LATENCY_MASK			(0xf << 0)
469bb772a59SSricharan #define EMIF_REG_DLL_SLAVE_DLY_CTRL_SHIFT		4
470bb772a59SSricharan #define EMIF_REG_DLL_SLAVE_DLY_CTRL_MASK		(0xFF << 4)
471bb772a59SSricharan #define EMIF_EMIF_DDR_PHY_CTRL_1_BASE_VAL_SHIFT	12
472bb772a59SSricharan #define EMIF_EMIF_DDR_PHY_CTRL_1_BASE_VAL_MASK	(0xFFFFF << 12)
473bb772a59SSricharan 
474bb772a59SSricharan /* DDR_PHY_CTRL_1_SHDW */
475bb772a59SSricharan #define EMIF_REG_DDR_PHY_CTRL_1_SHDW_SHIFT		4
476bb772a59SSricharan #define EMIF_REG_DDR_PHY_CTRL_1_SHDW_MASK		(0xfffffff << 4)
477bb772a59SSricharan #define EMIF_REG_READ_LATENCY_SHDW_SHIFT		0
478bb772a59SSricharan #define EMIF_REG_READ_LATENCY_SHDW_MASK		(0xf << 0)
479bb772a59SSricharan #define EMIF_REG_DLL_SLAVE_DLY_CTRL_SHDW_SHIFT	4
480bb772a59SSricharan #define EMIF_REG_DLL_SLAVE_DLY_CTRL_SHDW_MASK	(0xFF << 4)
481bb772a59SSricharan #define EMIF_EMIF_DDR_PHY_CTRL_1_BASE_VAL_SHDW_SHIFT 12
482bb772a59SSricharan #define EMIF_EMIF_DDR_PHY_CTRL_1_BASE_VAL_SHDW_MASK	(0xFFFFF << 12)
483e3ce3aa1SLokesh Vutla #define EMIF_DDR_PHY_CTRL_1_WRLVL_MASK_SHIFT		25
484e3ce3aa1SLokesh Vutla #define EMIF_DDR_PHY_CTRL_1_WRLVL_MASK_MASK		(1 << 25)
485e3ce3aa1SLokesh Vutla #define EMIF_DDR_PHY_CTRL_1_RDLVLGATE_MASK_SHIFT	26
486e3ce3aa1SLokesh Vutla #define EMIF_DDR_PHY_CTRL_1_RDLVLGATE_MASK_MASK		(1 << 26)
487e3ce3aa1SLokesh Vutla #define EMIF_DDR_PHY_CTRL_1_RDLVL_MASK_SHIFT		27
488e3ce3aa1SLokesh Vutla #define EMIF_DDR_PHY_CTRL_1_RDLVL_MASK_MASK		(1 << 27)
489bb772a59SSricharan 
490bb772a59SSricharan /* DDR_PHY_CTRL_2 */
491bb772a59SSricharan #define EMIF_REG_DDR_PHY_CTRL_2_SHIFT		0
492bb772a59SSricharan #define EMIF_REG_DDR_PHY_CTRL_2_MASK		(0xffffffff << 0)
493bb772a59SSricharan 
494784ab7c5SLokesh Vutla /*EMIF_READ_WRITE_LEVELING_CONTROL*/
495784ab7c5SLokesh Vutla #define EMIF_REG_RDWRLVLFULL_START_SHIFT	31
496784ab7c5SLokesh Vutla #define EMIF_REG_RDWRLVLFULL_START_MASK		(1 << 31)
497784ab7c5SLokesh Vutla #define EMIF_REG_RDWRLVLINC_PRE_SHIFT		24
498784ab7c5SLokesh Vutla #define EMIF_REG_RDWRLVLINC_PRE_MASK		(0x7F << 24)
499784ab7c5SLokesh Vutla #define EMIF_REG_RDLVLINC_INT_SHIFT		16
500784ab7c5SLokesh Vutla #define EMIF_REG_RDLVLINC_INT_MASK		(0xFF << 16)
501784ab7c5SLokesh Vutla #define EMIF_REG_RDLVLGATEINC_INT_SHIFT		8
502784ab7c5SLokesh Vutla #define EMIF_REG_RDLVLGATEINC_INT_MASK		(0xFF << 8)
503784ab7c5SLokesh Vutla #define EMIF_REG_WRLVLINC_INT_SHIFT		0
504784ab7c5SLokesh Vutla #define EMIF_REG_WRLVLINC_INT_MASK		(0xFF << 0)
505784ab7c5SLokesh Vutla 
506784ab7c5SLokesh Vutla /*EMIF_READ_WRITE_LEVELING_RAMP_CONTROL*/
507784ab7c5SLokesh Vutla #define EMIF_REG_RDWRLVL_EN_SHIFT		31
508784ab7c5SLokesh Vutla #define EMIF_REG_RDWRLVL_EN_MASK		(1 << 31)
509784ab7c5SLokesh Vutla #define EMIF_REG_RDWRLVLINC_RMP_PRE_SHIFT	24
510784ab7c5SLokesh Vutla #define EMIF_REG_RDWRLVLINC_RMP_PRE_MASK	(0x7F << 24)
511784ab7c5SLokesh Vutla #define EMIF_REG_RDLVLINC_RMP_INT_SHIFT		16
512784ab7c5SLokesh Vutla #define EMIF_REG_RDLVLINC_RMP_INT_MASK		(0xFF << 16)
513784ab7c5SLokesh Vutla #define EMIF_REG_RDLVLGATEINC_RMP_INT_SHIFT	8
514784ab7c5SLokesh Vutla #define EMIF_REG_RDLVLGATEINC_RMP_INT_MASK	(0xFF << 8)
515784ab7c5SLokesh Vutla #define EMIF_REG_WRLVLINC_RMP_INT_SHIFT		0
516784ab7c5SLokesh Vutla #define EMIF_REG_WRLVLINC_RMP_INT_MASK		(0xFF << 0)
517784ab7c5SLokesh Vutla 
518784ab7c5SLokesh Vutla /*EMIF_READ_WRITE_LEVELING_RAMP_WINDOW*/
519784ab7c5SLokesh Vutla #define EMIF_REG_RDWRLVLINC_RMP_WIN_SHIFT	0
520784ab7c5SLokesh Vutla #define EMIF_REG_RDWRLVLINC_RMP_WIN_MASK	(0x1FFF << 0)
521784ab7c5SLokesh Vutla 
5226213db78SLokesh Vutla /* EMIF_PHY_CTRL_36 */
5236213db78SLokesh Vutla #define EMIF_REG_PHY_FIFO_WE_IN_MISALINED_CLR	(1 << 8)
5246213db78SLokesh Vutla 
5256213db78SLokesh Vutla #define PHY_RDDQS_RATIO_REGS		5
5266213db78SLokesh Vutla #define PHY_FIFO_WE_SLAVE_RATIO_REGS	5
5276213db78SLokesh Vutla #define PHY_REG_WR_DQ_SLAVE_RATIO_REGS	10
5286213db78SLokesh Vutla 
529784ab7c5SLokesh Vutla /*Leveling Fields */
530784ab7c5SLokesh Vutla #define DDR3_WR_LVL_INT		0x73
531784ab7c5SLokesh Vutla #define DDR3_RD_LVL_INT		0x33
532784ab7c5SLokesh Vutla #define DDR3_RD_LVL_GATE_INT	0x59
533784ab7c5SLokesh Vutla #define RD_RW_LVL_INC_PRE	0x0
534784ab7c5SLokesh Vutla #define DDR3_FULL_LVL		(1 << EMIF_REG_RDWRLVL_EN_SHIFT)
535784ab7c5SLokesh Vutla 
536784ab7c5SLokesh Vutla #define DDR3_INC_LVL	((DDR3_WR_LVL_INT << EMIF_REG_WRLVLINC_INT_SHIFT)   \
537784ab7c5SLokesh Vutla 		| (DDR3_RD_LVL_GATE_INT << EMIF_REG_RDLVLGATEINC_INT_SHIFT) \
538784ab7c5SLokesh Vutla 		| (DDR3_RD_LVL_INT << EMIF_REG_RDLVLINC_RMP_INT_SHIFT)      \
539784ab7c5SLokesh Vutla 		| (RD_RW_LVL_INC_PRE << EMIF_REG_RDWRLVLINC_RMP_PRE_SHIFT))
540784ab7c5SLokesh Vutla 
541784ab7c5SLokesh Vutla #define SDRAM_CONFIG_EXT_RD_LVL_11_SAMPLES	0x0000C1A7
542784ab7c5SLokesh Vutla #define SDRAM_CONFIG_EXT_RD_LVL_4_SAMPLES	0x000001A7
5439100edecSLokesh Vutla #define SDRAM_CONFIG_EXT_RD_LVL_11_SAMPLES_ES2 0x0000C1C7
544784ab7c5SLokesh Vutla 
545bb772a59SSricharan /* DMM */
546bb772a59SSricharan #define DMM_BASE			0x4E000040
547bb772a59SSricharan 
548bb772a59SSricharan /* Memory Adapter */
549bb772a59SSricharan #define MA_BASE				0x482AF040
55029c20ba2SLokesh Vutla #define MA_PRIORITY			0x482A2000
55129c20ba2SLokesh Vutla #define MA_HIMEM_INTERLEAVE_UN_SHIFT	8
55229c20ba2SLokesh Vutla #define MA_HIMEM_INTERLEAVE_UN_MASK	(1 << 8)
553bb772a59SSricharan 
554bb772a59SSricharan /* DMM_LISA_MAP */
555bb772a59SSricharan #define EMIF_SYS_ADDR_SHIFT		24
556bb772a59SSricharan #define EMIF_SYS_ADDR_MASK		(0xff << 24)
557bb772a59SSricharan #define EMIF_SYS_SIZE_SHIFT		20
558bb772a59SSricharan #define EMIF_SYS_SIZE_MASK		(0x7 << 20)
559bb772a59SSricharan #define EMIF_SDRC_INTL_SHIFT	18
560bb772a59SSricharan #define EMIF_SDRC_INTL_MASK		(0x3 << 18)
561bb772a59SSricharan #define EMIF_SDRC_ADDRSPC_SHIFT	16
562bb772a59SSricharan #define EMIF_SDRC_ADDRSPC_MASK	(0x3 << 16)
563bb772a59SSricharan #define EMIF_SDRC_MAP_SHIFT		8
564bb772a59SSricharan #define EMIF_SDRC_MAP_MASK		(0x3 << 8)
565bb772a59SSricharan #define EMIF_SDRC_ADDR_SHIFT	0
566bb772a59SSricharan #define EMIF_SDRC_ADDR_MASK		(0xff << 0)
567bb772a59SSricharan 
568bb772a59SSricharan /* DMM_LISA_MAP fields */
569bb772a59SSricharan #define DMM_SDRC_MAP_UNMAPPED		0
570bb772a59SSricharan #define DMM_SDRC_MAP_EMIF1_ONLY		1
571bb772a59SSricharan #define DMM_SDRC_MAP_EMIF2_ONLY		2
572bb772a59SSricharan #define DMM_SDRC_MAP_EMIF1_AND_EMIF2	3
573bb772a59SSricharan 
574bb772a59SSricharan #define DMM_SDRC_INTL_NONE		0
575bb772a59SSricharan #define DMM_SDRC_INTL_128B		1
576bb772a59SSricharan #define DMM_SDRC_INTL_256B		2
577bb772a59SSricharan #define DMM_SDRC_INTL_512		3
578bb772a59SSricharan 
579bb772a59SSricharan #define DMM_SDRC_ADDR_SPC_SDRAM		0
580bb772a59SSricharan #define DMM_SDRC_ADDR_SPC_NVM		1
581bb772a59SSricharan #define DMM_SDRC_ADDR_SPC_INVALID	2
582bb772a59SSricharan 
583bb772a59SSricharan #define DMM_LISA_MAP_INTERLEAVED_BASE_VAL		(\
584bb772a59SSricharan 	(DMM_SDRC_MAP_EMIF1_AND_EMIF2 << EMIF_SDRC_MAP_SHIFT) |\
585bb772a59SSricharan 	(DMM_SDRC_ADDR_SPC_SDRAM << EMIF_SDRC_ADDRSPC_SHIFT) |\
586bb772a59SSricharan 	(DMM_SDRC_INTL_128B << EMIF_SDRC_INTL_SHIFT) |\
587bb772a59SSricharan 	(CONFIG_SYS_SDRAM_BASE << EMIF_SYS_ADDR_SHIFT))
588bb772a59SSricharan 
589bb772a59SSricharan #define DMM_LISA_MAP_EMIF1_ONLY_BASE_VAL	(\
590bb772a59SSricharan 	(DMM_SDRC_MAP_EMIF1_ONLY << EMIF_SDRC_MAP_SHIFT)|\
591bb772a59SSricharan 	(DMM_SDRC_ADDR_SPC_SDRAM << EMIF_SDRC_ADDRSPC_SHIFT)|\
592bb772a59SSricharan 	(DMM_SDRC_INTL_NONE << EMIF_SDRC_INTL_SHIFT))
593bb772a59SSricharan 
594bb772a59SSricharan #define DMM_LISA_MAP_EMIF2_ONLY_BASE_VAL	(\
595bb772a59SSricharan 	(DMM_SDRC_MAP_EMIF2_ONLY << EMIF_SDRC_MAP_SHIFT)|\
596bb772a59SSricharan 	(DMM_SDRC_ADDR_SPC_SDRAM << EMIF_SDRC_ADDRSPC_SHIFT)|\
597bb772a59SSricharan 	(DMM_SDRC_INTL_NONE << EMIF_SDRC_INTL_SHIFT))
598bb772a59SSricharan 
599bb772a59SSricharan /* Trap for invalid TILER PAT entries */
600bb772a59SSricharan #define DMM_LISA_MAP_0_INVAL_ADDR_TRAP		(\
601bb772a59SSricharan 	(0  << EMIF_SDRC_ADDR_SHIFT) |\
602bb772a59SSricharan 	(DMM_SDRC_MAP_EMIF1_ONLY << EMIF_SDRC_MAP_SHIFT)|\
603bb772a59SSricharan 	(DMM_SDRC_ADDR_SPC_INVALID << EMIF_SDRC_ADDRSPC_SHIFT)|\
604bb772a59SSricharan 	(DMM_SDRC_INTL_NONE << EMIF_SDRC_INTL_SHIFT)|\
605bb772a59SSricharan 	(0xFF << EMIF_SYS_ADDR_SHIFT))
606bb772a59SSricharan 
607f4010734SSRICHARAN R #define EMIF_EXT_PHY_CTRL_TIMING_REG	0x5
608bb772a59SSricharan 
609650fda93SLokesh Vutla /* EMIF ECC CTRL reg */
610650fda93SLokesh Vutla #define EMIF_ECC_CTRL_REG_ECC_EN_SHIFT			31
611650fda93SLokesh Vutla #define EMIF_ECC_CTRL_REG_ECC_EN_MASK			(1 << 31)
612650fda93SLokesh Vutla #define EMIF_ECC_CTRL_REG_ECC_ADDR_RGN_PROT_SHIFT	30
613650fda93SLokesh Vutla #define EMIF_ECC_CTRL_REG_ECC_ADDR_RGN_PROT_MASK	(1 << 30)
614650fda93SLokesh Vutla #define EMIF_ECC_CTRL_REG_ECC_VERIFY_DIS_SHIFT		29
615650fda93SLokesh Vutla #define EMIF_ECC_CTRL_REG_ECC_VERIFY_DIS_MASK		(1 << 29)
616650fda93SLokesh Vutla #define EMIF_ECC_REG_RMW_EN_SHIFT			28
617650fda93SLokesh Vutla #define EMIF_ECC_REG_RMW_EN_MASK			(1 << 28)
618650fda93SLokesh Vutla #define EMIF_ECC_REG_ECC_ADDR_RGN_2_EN_SHIFT		1
619650fda93SLokesh Vutla #define EMIF_ECC_REG_ECC_ADDR_RGN_2_EN_MASK		(1 << 1)
620650fda93SLokesh Vutla #define EMIF_ECC_REG_ECC_ADDR_RGN_1_EN_SHIFT		0
621650fda93SLokesh Vutla #define EMIF_ECC_REG_ECC_ADDR_RGN_1_EN_MASK		(1 << 0)
622650fda93SLokesh Vutla 
623650fda93SLokesh Vutla /* EMIF ECC ADDRESS RANGE */
624650fda93SLokesh Vutla #define EMIF_ECC_REG_ECC_END_ADDR_SHIFT			16
625650fda93SLokesh Vutla #define EMIF_ECC_REG_ECC_END_ADDR_MASK			(0xffff << 16)
626650fda93SLokesh Vutla #define EMIF_ECC_REG_ECC_START_ADDR_SHIFT		0
627650fda93SLokesh Vutla #define EMIF_ECC_REG_ECC_START_ADDR_MASK		(0xffff << 0)
628650fda93SLokesh Vutla 
629650fda93SLokesh Vutla /* EMIF_SYSTEM_OCP_INTERRUPT_RAW_STATUS */
630650fda93SLokesh Vutla #define EMIF_INT_ONEBIT_ECC_ERR_SYS_SHIFT		5
631650fda93SLokesh Vutla #define EMIF_INT_ONEBIT_ECC_ERR_SYS_MASK		(1 << 5)
632650fda93SLokesh Vutla #define EMIF_INT_TWOBIT_ECC_ERR_SYS_SHIFT		4
633650fda93SLokesh Vutla #define EMIF_INT_TWOBIT_ECC_ERR_SYS_MASK		(1 << 4)
634650fda93SLokesh Vutla #define EMIF_INT_WR_ECC_ERR_SYS_SHIFT			3
635650fda93SLokesh Vutla #define EMIF_INT_WR_ECC_ERR_SYS_MASK			(1 << 3)
636650fda93SLokesh Vutla 
637bb772a59SSricharan /* Reg mapping structure */
638bb772a59SSricharan struct emif_reg_struct {
639bb772a59SSricharan 	u32 emif_mod_id_rev;
640bb772a59SSricharan 	u32 emif_status;
641bb772a59SSricharan 	u32 emif_sdram_config;
642bb772a59SSricharan 	u32 emif_lpddr2_nvm_config;
643bb772a59SSricharan 	u32 emif_sdram_ref_ctrl;
644bb772a59SSricharan 	u32 emif_sdram_ref_ctrl_shdw;
645bb772a59SSricharan 	u32 emif_sdram_tim_1;
646bb772a59SSricharan 	u32 emif_sdram_tim_1_shdw;
647bb772a59SSricharan 	u32 emif_sdram_tim_2;
648bb772a59SSricharan 	u32 emif_sdram_tim_2_shdw;
649bb772a59SSricharan 	u32 emif_sdram_tim_3;
650bb772a59SSricharan 	u32 emif_sdram_tim_3_shdw;
651bb772a59SSricharan 	u32 emif_lpddr2_nvm_tim;
652bb772a59SSricharan 	u32 emif_lpddr2_nvm_tim_shdw;
653bb772a59SSricharan 	u32 emif_pwr_mgmt_ctrl;
654bb772a59SSricharan 	u32 emif_pwr_mgmt_ctrl_shdw;
655bb772a59SSricharan 	u32 emif_lpddr2_mode_reg_data;
656bb772a59SSricharan 	u32 padding1[1];
657bb772a59SSricharan 	u32 emif_lpddr2_mode_reg_data_es2;
658bb772a59SSricharan 	u32 padding11[1];
659bb772a59SSricharan 	u32 emif_lpddr2_mode_reg_cfg;
660bb772a59SSricharan 	u32 emif_l3_config;
661bb772a59SSricharan 	u32 emif_l3_cfg_val_1;
662bb772a59SSricharan 	u32 emif_l3_cfg_val_2;
663bb772a59SSricharan 	u32 emif_iodft_tlgc;
664bb772a59SSricharan 	u32 padding2[7];
665bb772a59SSricharan 	u32 emif_perf_cnt_1;
666bb772a59SSricharan 	u32 emif_perf_cnt_2;
667bb772a59SSricharan 	u32 emif_perf_cnt_cfg;
668bb772a59SSricharan 	u32 emif_perf_cnt_sel;
669bb772a59SSricharan 	u32 emif_perf_cnt_tim;
670bb772a59SSricharan 	u32 padding3;
671bb772a59SSricharan 	u32 emif_read_idlectrl;
672bb772a59SSricharan 	u32 emif_read_idlectrl_shdw;
673bb772a59SSricharan 	u32 padding4;
674bb772a59SSricharan 	u32 emif_irqstatus_raw_sys;
675bb772a59SSricharan 	u32 emif_irqstatus_raw_ll;
676bb772a59SSricharan 	u32 emif_irqstatus_sys;
677bb772a59SSricharan 	u32 emif_irqstatus_ll;
678bb772a59SSricharan 	u32 emif_irqenable_set_sys;
679bb772a59SSricharan 	u32 emif_irqenable_set_ll;
680bb772a59SSricharan 	u32 emif_irqenable_clr_sys;
681bb772a59SSricharan 	u32 emif_irqenable_clr_ll;
682bb772a59SSricharan 	u32 padding5;
683bb772a59SSricharan 	u32 emif_zq_config;
684bb772a59SSricharan 	u32 emif_temp_alert_config;
685bb772a59SSricharan 	u32 emif_l3_err_log;
686f4010734SSRICHARAN R 	u32 emif_rd_wr_lvl_rmp_win;
687f4010734SSRICHARAN R 	u32 emif_rd_wr_lvl_rmp_ctl;
688f4010734SSRICHARAN R 	u32 emif_rd_wr_lvl_ctl;
689f4010734SSRICHARAN R 	u32 padding6[1];
690bb772a59SSricharan 	u32 emif_ddr_phy_ctrl_1;
691bb772a59SSricharan 	u32 emif_ddr_phy_ctrl_1_shdw;
692bb772a59SSricharan 	u32 emif_ddr_phy_ctrl_2;
6938038b497SCooper Jr., Franklin 	u32 padding7[4];
6948038b497SCooper Jr., Franklin 	u32 emif_prio_class_serv_map;
6958038b497SCooper Jr., Franklin 	u32 emif_connect_id_serv_1_map;
6968038b497SCooper Jr., Franklin 	u32 emif_connect_id_serv_2_map;
697e18cd3d7SLokesh Vutla 	u32 padding8;
698e18cd3d7SLokesh Vutla 	u32 emif_ecc_ctrl_reg;
699e18cd3d7SLokesh Vutla 	u32 emif_ecc_address_range_1;
700e18cd3d7SLokesh Vutla 	u32 emif_ecc_address_range_2;
701e18cd3d7SLokesh Vutla 	u32 padding8_1;
702f4010734SSRICHARAN R 	u32 emif_rd_wr_exec_thresh;
7038038b497SCooper Jr., Franklin 	u32 emif_cos_config;
704e18cd3d7SLokesh Vutla #if defined(CONFIG_DRA7XX) || defined(CONFIG_ARCH_KEYSTONE)
705e18cd3d7SLokesh Vutla 	u32 padding9[2];
706e18cd3d7SLokesh Vutla 	u32 emif_1b_ecc_err_cnt;
707e18cd3d7SLokesh Vutla 	u32 emif_1b_ecc_err_thrush;
708e18cd3d7SLokesh Vutla 	u32 emif_1b_ecc_err_dist_1;
709e18cd3d7SLokesh Vutla 	u32 emif_1b_ecc_err_addr_log;
710e18cd3d7SLokesh Vutla 	u32 emif_2b_ecc_err_addr_log;
711e18cd3d7SLokesh Vutla 	u32 emif_ddr_phy_status[28];
712e18cd3d7SLokesh Vutla 	u32 padding10[19];
713e18cd3d7SLokesh Vutla #else
7148038b497SCooper Jr., Franklin 	u32 padding9[6];
715fc46bae2SJames Doublesin 	u32 emif_ddr_phy_status[28];
716fc46bae2SJames Doublesin 	u32 padding10[20];
717e18cd3d7SLokesh Vutla #endif
718f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_1;
719f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_1_shdw;
720f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_2;
721f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_2_shdw;
722f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_3;
723f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_3_shdw;
724f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_4;
725f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_4_shdw;
726f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_5;
727f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_5_shdw;
728f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_6;
729f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_6_shdw;
730f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_7;
731f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_7_shdw;
732f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_8;
733f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_8_shdw;
734f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_9;
735f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_9_shdw;
736f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_10;
737f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_10_shdw;
738f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_11;
739f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_11_shdw;
740f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_12;
741f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_12_shdw;
742f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_13;
743f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_13_shdw;
744f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_14;
745f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_14_shdw;
746f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_15;
747f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_15_shdw;
748f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_16;
749f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_16_shdw;
750f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_17;
751f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_17_shdw;
752f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_18;
753f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_18_shdw;
754f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_19;
755f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_19_shdw;
756f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_20;
757f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_20_shdw;
758f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_21;
759f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_21_shdw;
760f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_22;
761f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_22_shdw;
762f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_23;
763f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_23_shdw;
764f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_24;
765f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_24_shdw;
766fc46bae2SJames Doublesin 	u32 emif_ddr_ext_phy_ctrl_25;
767fc46bae2SJames Doublesin 	u32 emif_ddr_ext_phy_ctrl_25_shdw;
768fc46bae2SJames Doublesin 	u32 emif_ddr_ext_phy_ctrl_26;
769fc46bae2SJames Doublesin 	u32 emif_ddr_ext_phy_ctrl_26_shdw;
770fc46bae2SJames Doublesin 	u32 emif_ddr_ext_phy_ctrl_27;
771fc46bae2SJames Doublesin 	u32 emif_ddr_ext_phy_ctrl_27_shdw;
772fc46bae2SJames Doublesin 	u32 emif_ddr_ext_phy_ctrl_28;
773fc46bae2SJames Doublesin 	u32 emif_ddr_ext_phy_ctrl_28_shdw;
774fc46bae2SJames Doublesin 	u32 emif_ddr_ext_phy_ctrl_29;
775fc46bae2SJames Doublesin 	u32 emif_ddr_ext_phy_ctrl_29_shdw;
776fc46bae2SJames Doublesin 	u32 emif_ddr_ext_phy_ctrl_30;
777fc46bae2SJames Doublesin 	u32 emif_ddr_ext_phy_ctrl_30_shdw;
778fc46bae2SJames Doublesin 	u32 emif_ddr_ext_phy_ctrl_31;
779fc46bae2SJames Doublesin 	u32 emif_ddr_ext_phy_ctrl_31_shdw;
780fc46bae2SJames Doublesin 	u32 emif_ddr_ext_phy_ctrl_32;
781fc46bae2SJames Doublesin 	u32 emif_ddr_ext_phy_ctrl_32_shdw;
782fc46bae2SJames Doublesin 	u32 emif_ddr_ext_phy_ctrl_33;
783fc46bae2SJames Doublesin 	u32 emif_ddr_ext_phy_ctrl_33_shdw;
784fc46bae2SJames Doublesin 	u32 emif_ddr_ext_phy_ctrl_34;
785fc46bae2SJames Doublesin 	u32 emif_ddr_ext_phy_ctrl_34_shdw;
786fc46bae2SJames Doublesin 	u32 emif_ddr_ext_phy_ctrl_35;
787fc46bae2SJames Doublesin 	u32 emif_ddr_ext_phy_ctrl_35_shdw;
788fc46bae2SJames Doublesin 	union {
789fc46bae2SJames Doublesin 		u32 emif_ddr_ext_phy_ctrl_36;
7906c70935dSSRICHARAN R 		u32 emif_ddr_fifo_misaligned_clear_1;
791fc46bae2SJames Doublesin 	};
792fc46bae2SJames Doublesin 	union {
793fc46bae2SJames Doublesin 		u32 emif_ddr_ext_phy_ctrl_36_shdw;
7946c70935dSSRICHARAN R 		u32 emif_ddr_fifo_misaligned_clear_2;
795bb772a59SSricharan 	};
796fc46bae2SJames Doublesin };
797bb772a59SSricharan 
798bb772a59SSricharan struct dmm_lisa_map_regs {
799bb772a59SSricharan 	u32 dmm_lisa_map_0;
800bb772a59SSricharan 	u32 dmm_lisa_map_1;
801bb772a59SSricharan 	u32 dmm_lisa_map_2;
802bb772a59SSricharan 	u32 dmm_lisa_map_3;
8037831419dSLokesh Vutla 	u8 is_ma_present;
804bb772a59SSricharan };
805bb772a59SSricharan 
806bb772a59SSricharan #define CS0	0
807bb772a59SSricharan #define CS1	1
808bb772a59SSricharan /* The maximum frequency at which the LPDDR2 interface can operate in Hz*/
809bb772a59SSricharan #define MAX_LPDDR2_FREQ	400000000	/* 400 MHz */
810bb772a59SSricharan 
811bb772a59SSricharan /*
812bb772a59SSricharan  * The period of DDR clk is represented as numerator and denominator for
813bb772a59SSricharan  * better accuracy in integer based calculations. However, if the numerator
814bb772a59SSricharan  * and denominator are very huge there may be chances of overflow in
815bb772a59SSricharan  * calculations. So, as a trade-off keep denominator(and consequently
816bb772a59SSricharan  * numerator) within a limit sacrificing some accuracy - but not much
817bb772a59SSricharan  * If denominator and numerator are already small (such as at 400 MHz)
818bb772a59SSricharan  * no adjustment is needed
819bb772a59SSricharan  */
820bb772a59SSricharan #define EMIF_PERIOD_DEN_LIMIT	1000
821bb772a59SSricharan /*
822bb772a59SSricharan  * Maximum number of different frequencies supported by EMIF driver
823bb772a59SSricharan  * Determines the number of entries in the pointer array for register
824bb772a59SSricharan  * cache
825bb772a59SSricharan  */
826bb772a59SSricharan #define EMIF_MAX_NUM_FREQUENCIES	6
827bb772a59SSricharan /*
828bb772a59SSricharan  * Indices into the Addressing Table array.
829bb772a59SSricharan  * One entry each for all the different types of devices with different
830bb772a59SSricharan  * addressing schemes
831bb772a59SSricharan  */
832bb772a59SSricharan #define ADDR_TABLE_INDEX64M	0
833bb772a59SSricharan #define ADDR_TABLE_INDEX128M	1
834bb772a59SSricharan #define ADDR_TABLE_INDEX256M	2
835bb772a59SSricharan #define ADDR_TABLE_INDEX512M	3
836bb772a59SSricharan #define ADDR_TABLE_INDEX1GS4	4
837bb772a59SSricharan #define ADDR_TABLE_INDEX2GS4	5
838bb772a59SSricharan #define ADDR_TABLE_INDEX4G	6
839bb772a59SSricharan #define ADDR_TABLE_INDEX8G	7
840bb772a59SSricharan #define ADDR_TABLE_INDEX1GS2	8
841bb772a59SSricharan #define ADDR_TABLE_INDEX2GS2	9
842bb772a59SSricharan #define ADDR_TABLE_INDEXMAX	10
843bb772a59SSricharan 
844bb772a59SSricharan /* Number of Row bits */
845bb772a59SSricharan #define ROW_9  0
846bb772a59SSricharan #define ROW_10 1
847bb772a59SSricharan #define ROW_11 2
848bb772a59SSricharan #define ROW_12 3
849bb772a59SSricharan #define ROW_13 4
850bb772a59SSricharan #define ROW_14 5
851bb772a59SSricharan #define ROW_15 6
852bb772a59SSricharan #define ROW_16 7
853bb772a59SSricharan 
854bb772a59SSricharan /* Number of Column bits */
855bb772a59SSricharan #define COL_8   0
856bb772a59SSricharan #define COL_9   1
857bb772a59SSricharan #define COL_10  2
858bb772a59SSricharan #define COL_11  3
859bb772a59SSricharan #define COL_7   4 /*Not supported by OMAP included for completeness */
860bb772a59SSricharan 
861bb772a59SSricharan /* Number of Banks*/
862bb772a59SSricharan #define BANKS1 0
863bb772a59SSricharan #define BANKS2 1
864bb772a59SSricharan #define BANKS4 2
865bb772a59SSricharan #define BANKS8 3
866bb772a59SSricharan 
867bb772a59SSricharan /* Refresh rate in micro seconds x 10 */
868bb772a59SSricharan #define T_REFI_15_6	156
869bb772a59SSricharan #define T_REFI_7_8	78
870bb772a59SSricharan #define T_REFI_3_9	39
871bb772a59SSricharan 
872bb772a59SSricharan #define EBANK_CS1_DIS	0
873bb772a59SSricharan #define EBANK_CS1_EN	1
874bb772a59SSricharan 
875bb772a59SSricharan /* Read Latency used by the device at reset */
876bb772a59SSricharan #define RL_BOOT		3
877bb772a59SSricharan /* Read Latency for the highest frequency you want to use */
878bb772a59SSricharan #ifdef CONFIG_OMAP54XX
879bb772a59SSricharan #define RL_FINAL	8
880bb772a59SSricharan #else
881bb772a59SSricharan #define RL_FINAL	6
882bb772a59SSricharan #endif
883bb772a59SSricharan 
884bb772a59SSricharan 
885bb772a59SSricharan /* Interleaving policies at EMIF level- between banks and Chip Selects */
886bb772a59SSricharan #define EMIF_INTERLEAVING_POLICY_MAX_INTERLEAVING	0
887bb772a59SSricharan #define EMIF_INTERLEAVING_POLICY_NO_BANK_INTERLEAVING	3
888bb772a59SSricharan 
889bb772a59SSricharan /*
890bb772a59SSricharan  * Interleaving policy to be used
891bb772a59SSricharan  * Currently set to MAX interleaving for better performance
892bb772a59SSricharan  */
893bb772a59SSricharan #define EMIF_INTERLEAVING_POLICY EMIF_INTERLEAVING_POLICY_MAX_INTERLEAVING
894bb772a59SSricharan 
895bb772a59SSricharan /* State of the core voltage:
896bb772a59SSricharan  * This is important for some parameters such as read idle control and
897bb772a59SSricharan  * ZQ calibration timings. Timings are much stricter when voltage ramp
898bb772a59SSricharan  * is happening compared to when the voltage is stable.
899bb772a59SSricharan  * We need to calculate two sets of values for these parameters and use
900bb772a59SSricharan  * them accordingly
901bb772a59SSricharan  */
902bb772a59SSricharan #define LPDDR2_VOLTAGE_STABLE	0
903bb772a59SSricharan #define LPDDR2_VOLTAGE_RAMPING	1
904bb772a59SSricharan 
905bb772a59SSricharan /* Length of the forced read idle period in terms of cycles */
906bb772a59SSricharan #define EMIF_REG_READ_IDLE_LEN_VAL	5
907bb772a59SSricharan 
908bb772a59SSricharan /* Interval between forced 'read idles' */
909bb772a59SSricharan /* To be used when voltage is changed for DPS/DVFS - 1us */
910bb772a59SSricharan #define READ_IDLE_INTERVAL_DVFS		(1*1000)
911bb772a59SSricharan /*
912bb772a59SSricharan  * To be used when voltage is not scaled except by Smart Reflex
913bb772a59SSricharan  * 50us - or maximum value will do
914bb772a59SSricharan  */
915bb772a59SSricharan #define READ_IDLE_INTERVAL_NORMAL	(50*1000)
916bb772a59SSricharan 
917bb772a59SSricharan 
918bb772a59SSricharan /*
919bb772a59SSricharan  * Unless voltage is changing due to DVFS one ZQCS command every 50ms should
920bb772a59SSricharan  * be enough. This shoule be enough also in the case when voltage is changing
921bb772a59SSricharan  * due to smart-reflex.
922bb772a59SSricharan  */
923bb772a59SSricharan #define EMIF_ZQCS_INTERVAL_NORMAL_IN_US	(50*1000)
924bb772a59SSricharan /*
925bb772a59SSricharan  * If voltage is changing due to DVFS ZQCS should be performed more
926bb772a59SSricharan  * often(every 50us)
927bb772a59SSricharan  */
928bb772a59SSricharan #define EMIF_ZQCS_INTERVAL_DVFS_IN_US	50
929bb772a59SSricharan 
930bb772a59SSricharan /* The interval between ZQCL commands as a multiple of ZQCS interval */
931bb772a59SSricharan #define REG_ZQ_ZQCL_MULT		4
932bb772a59SSricharan /* The interval between ZQINIT commands as a multiple of ZQCL interval */
933bb772a59SSricharan #define REG_ZQ_ZQINIT_MULT		3
934bb772a59SSricharan /* Enable ZQ Calibration on exiting Self-refresh */
935bb772a59SSricharan #define REG_ZQ_SFEXITEN_ENABLE		1
936bb772a59SSricharan /*
937bb772a59SSricharan  * ZQ Calibration simultaneously on both chip-selects:
938bb772a59SSricharan  * Needs one calibration resistor per CS
939bb772a59SSricharan  * None of the boards that we know of have this capability
940bb772a59SSricharan  * So disabled by default
941bb772a59SSricharan  */
942bb772a59SSricharan #define REG_ZQ_DUALCALEN_DISABLE	0
943bb772a59SSricharan /*
944bb772a59SSricharan  * Enable ZQ Calibration by default on CS0. If we are asked to program
945bb772a59SSricharan  * the EMIF there will be something connected to CS0 for sure
946bb772a59SSricharan  */
947bb772a59SSricharan #define REG_ZQ_CS0EN_ENABLE		1
948bb772a59SSricharan 
949bb772a59SSricharan /* EMIF_PWR_MGMT_CTRL register */
950bb772a59SSricharan /* Low power modes */
951bb772a59SSricharan #define LP_MODE_DISABLE		0
952bb772a59SSricharan #define LP_MODE_CLOCK_STOP	1
953bb772a59SSricharan #define LP_MODE_SELF_REFRESH	2
954bb772a59SSricharan #define LP_MODE_PWR_DN		3
955bb772a59SSricharan 
956bb772a59SSricharan /* REG_DPD_EN */
957bb772a59SSricharan #define DPD_DISABLE	0
958bb772a59SSricharan #define DPD_ENABLE	1
959bb772a59SSricharan 
960bb772a59SSricharan /* Maximum delay before Low Power Modes */
961f4010734SSRICHARAN R #define REG_CS_TIM		0x0
9623eb80d10SNishanth Menon #define REG_SR_TIM		0xF
9633eb80d10SNishanth Menon #define REG_PD_TIM		0xF
96492b0482cSSricharan R 
965bb772a59SSricharan 
966bb772a59SSricharan /* EMIF_PWR_MGMT_CTRL register */
967bb772a59SSricharan #define EMIF_PWR_MGMT_CTRL (\
968bb772a59SSricharan 	((REG_CS_TIM << EMIF_REG_CS_TIM_SHIFT) & EMIF_REG_CS_TIM_MASK)|\
969bb772a59SSricharan 	((REG_SR_TIM << EMIF_REG_SR_TIM_SHIFT) & EMIF_REG_SR_TIM_MASK)|\
970bb772a59SSricharan 	((REG_PD_TIM << EMIF_REG_PD_TIM_SHIFT) & EMIF_REG_PD_TIM_MASK)|\
9713eb80d10SNishanth Menon 	((LP_MODE_SELF_REFRESH << EMIF_REG_LP_MODE_SHIFT)\
972bb772a59SSricharan 			& EMIF_REG_LP_MODE_MASK) |\
973bb772a59SSricharan 	((DPD_DISABLE << EMIF_REG_DPD_EN_SHIFT)\
974bb772a59SSricharan 			& EMIF_REG_DPD_EN_MASK))\
975bb772a59SSricharan 
976bb772a59SSricharan #define EMIF_PWR_MGMT_CTRL_SHDW (\
977bb772a59SSricharan 	((REG_CS_TIM << EMIF_REG_CS_TIM_SHDW_SHIFT)\
978bb772a59SSricharan 			& EMIF_REG_CS_TIM_SHDW_MASK) |\
979bb772a59SSricharan 	((REG_SR_TIM << EMIF_REG_SR_TIM_SHDW_SHIFT)\
980bb772a59SSricharan 			& EMIF_REG_SR_TIM_SHDW_MASK) |\
981bb772a59SSricharan 	((REG_PD_TIM << EMIF_REG_PD_TIM_SHDW_SHIFT)\
982bb772a59SSricharan 			& EMIF_REG_PD_TIM_SHDW_MASK))
983bb772a59SSricharan 
984bb772a59SSricharan /* EMIF_L3_CONFIG register value */
985bb772a59SSricharan #define EMIF_L3_CONFIG_VAL_SYS_10_LL_0	0x0A0000FF
986bb772a59SSricharan #define EMIF_L3_CONFIG_VAL_SYS_10_MPU_3_LL_0	0x0A300000
987f4010734SSRICHARAN R #define EMIF_L3_CONFIG_VAL_SYS_10_MPU_5_LL_0	0x0A500000
988bb772a59SSricharan 
989bb772a59SSricharan /*
990bb772a59SSricharan  * Value of bits 12:31 of DDR_PHY_CTRL_1 register:
991bb772a59SSricharan  * All these fields have magic values dependent on frequency and
992bb772a59SSricharan  * determined by PHY and DLL integration with EMIF. Setting the magic
993bb772a59SSricharan  * values suggested by hw team.
994bb772a59SSricharan  */
995bb772a59SSricharan #define EMIF_DDR_PHY_CTRL_1_BASE_VAL			0x049FF
996bb772a59SSricharan #define EMIF_DLL_SLAVE_DLY_CTRL_400_MHZ			0x41
997bb772a59SSricharan #define EMIF_DLL_SLAVE_DLY_CTRL_200_MHZ			0x80
998bb772a59SSricharan #define EMIF_DLL_SLAVE_DLY_CTRL_100_MHZ_AND_LESS	0xFF
999bb772a59SSricharan 
1000bb772a59SSricharan /*
1001bb772a59SSricharan * MR1 value:
1002bb772a59SSricharan * Burst length	: 8
1003bb772a59SSricharan * Burst type	: sequential
1004bb772a59SSricharan * Wrap		: enabled
1005bb772a59SSricharan * nWR		: 3(default). EMIF does not do pre-charge.
1006bb772a59SSricharan *		: So nWR is don't care
1007bb772a59SSricharan */
1008bb772a59SSricharan #define MR1_BL_8_BT_SEQ_WRAP_EN_NWR_3	0x23
1009f4010734SSRICHARAN R #define MR1_BL_8_BT_SEQ_WRAP_EN_NWR_8	0xc3
1010bb772a59SSricharan 
1011bb772a59SSricharan /* MR2 */
1012bb772a59SSricharan #define MR2_RL3_WL1			1
1013bb772a59SSricharan #define MR2_RL4_WL2			2
1014bb772a59SSricharan #define MR2_RL5_WL2			3
1015bb772a59SSricharan #define MR2_RL6_WL3			4
1016bb772a59SSricharan 
1017bb772a59SSricharan /* MR10: ZQ calibration codes */
1018bb772a59SSricharan #define MR10_ZQ_ZQCS		0x56
1019bb772a59SSricharan #define MR10_ZQ_ZQCL		0xAB
1020bb772a59SSricharan #define MR10_ZQ_ZQINIT		0xFF
1021bb772a59SSricharan #define MR10_ZQ_ZQRESET		0xC3
1022bb772a59SSricharan 
1023bb772a59SSricharan /* TEMP_ALERT_CONFIG */
1024bb772a59SSricharan #define TEMP_ALERT_POLL_INTERVAL_MS	360 /* for temp gradient - 5 C/s */
1025bb772a59SSricharan #define TEMP_ALERT_CONFIG_DEVCT_1	0
1026bb772a59SSricharan #define TEMP_ALERT_CONFIG_DEVWDT_32	2
1027bb772a59SSricharan 
1028bb772a59SSricharan /* MR16 value: refresh full array(no partial array self refresh) */
1029bb772a59SSricharan #define MR16_REF_FULL_ARRAY	0
1030bb772a59SSricharan 
1031bb772a59SSricharan /*
1032bb772a59SSricharan  * Maximum number of entries we keep in our array of timing tables
1033bb772a59SSricharan  * We need not keep all the speed bins supported by the device
1034bb772a59SSricharan  * We need to keep timing tables for only the speed bins that we
1035bb772a59SSricharan  * are interested in
1036bb772a59SSricharan  */
1037bb772a59SSricharan #define MAX_NUM_SPEEDBINS	4
1038bb772a59SSricharan 
1039bb772a59SSricharan /* LPDDR2 Densities */
1040bb772a59SSricharan #define LPDDR2_DENSITY_64Mb	0
1041bb772a59SSricharan #define LPDDR2_DENSITY_128Mb	1
1042bb772a59SSricharan #define LPDDR2_DENSITY_256Mb	2
1043bb772a59SSricharan #define LPDDR2_DENSITY_512Mb	3
1044bb772a59SSricharan #define LPDDR2_DENSITY_1Gb	4
1045bb772a59SSricharan #define LPDDR2_DENSITY_2Gb	5
1046bb772a59SSricharan #define LPDDR2_DENSITY_4Gb	6
1047bb772a59SSricharan #define LPDDR2_DENSITY_8Gb	7
1048bb772a59SSricharan #define LPDDR2_DENSITY_16Gb	8
1049bb772a59SSricharan #define LPDDR2_DENSITY_32Gb	9
1050bb772a59SSricharan 
1051bb772a59SSricharan /* LPDDR2 type */
1052bb772a59SSricharan #define	LPDDR2_TYPE_S4	0
1053bb772a59SSricharan #define	LPDDR2_TYPE_S2	1
1054bb772a59SSricharan #define	LPDDR2_TYPE_NVM	2
1055bb772a59SSricharan 
1056bb772a59SSricharan /* LPDDR2 IO width */
1057bb772a59SSricharan #define	LPDDR2_IO_WIDTH_32	0
1058bb772a59SSricharan #define	LPDDR2_IO_WIDTH_16	1
1059bb772a59SSricharan #define	LPDDR2_IO_WIDTH_8	2
1060bb772a59SSricharan 
1061bb772a59SSricharan /* Mode register numbers */
1062bb772a59SSricharan #define LPDDR2_MR0	0
1063bb772a59SSricharan #define LPDDR2_MR1	1
1064bb772a59SSricharan #define LPDDR2_MR2	2
1065bb772a59SSricharan #define LPDDR2_MR3	3
1066bb772a59SSricharan #define LPDDR2_MR4	4
1067bb772a59SSricharan #define LPDDR2_MR5	5
1068bb772a59SSricharan #define LPDDR2_MR6	6
1069bb772a59SSricharan #define LPDDR2_MR7	7
1070bb772a59SSricharan #define LPDDR2_MR8	8
1071bb772a59SSricharan #define LPDDR2_MR9	9
1072bb772a59SSricharan #define LPDDR2_MR10	10
1073bb772a59SSricharan #define LPDDR2_MR11	11
1074bb772a59SSricharan #define LPDDR2_MR16	16
1075bb772a59SSricharan #define LPDDR2_MR17	17
1076bb772a59SSricharan #define LPDDR2_MR18	18
1077bb772a59SSricharan 
1078bb772a59SSricharan /* MR0 */
1079bb772a59SSricharan #define LPDDR2_MR0_DAI_SHIFT	0
1080bb772a59SSricharan #define LPDDR2_MR0_DAI_MASK	1
1081bb772a59SSricharan #define LPDDR2_MR0_DI_SHIFT	1
1082bb772a59SSricharan #define LPDDR2_MR0_DI_MASK	(1 << 1)
1083bb772a59SSricharan #define LPDDR2_MR0_DNVI_SHIFT	2
1084bb772a59SSricharan #define LPDDR2_MR0_DNVI_MASK	(1 << 2)
1085bb772a59SSricharan 
1086bb772a59SSricharan /* MR4 */
1087bb772a59SSricharan #define MR4_SDRAM_REF_RATE_SHIFT	0
1088bb772a59SSricharan #define MR4_SDRAM_REF_RATE_MASK		7
1089bb772a59SSricharan #define MR4_TUF_SHIFT			7
1090bb772a59SSricharan #define MR4_TUF_MASK			(1 << 7)
1091bb772a59SSricharan 
1092bb772a59SSricharan /* MR4 SDRAM Refresh Rate field values */
1093bb772a59SSricharan #define SDRAM_TEMP_LESS_LOW_SHUTDOWN			0x0
1094bb772a59SSricharan #define SDRAM_TEMP_LESS_4X_REFRESH_AND_TIMINGS		0x1
1095bb772a59SSricharan #define SDRAM_TEMP_LESS_2X_REFRESH_AND_TIMINGS		0x2
1096bb772a59SSricharan #define SDRAM_TEMP_NOMINAL				0x3
1097bb772a59SSricharan #define SDRAM_TEMP_RESERVED_4				0x4
1098bb772a59SSricharan #define SDRAM_TEMP_HIGH_DERATE_REFRESH			0x5
1099bb772a59SSricharan #define SDRAM_TEMP_HIGH_DERATE_REFRESH_AND_TIMINGS	0x6
1100bb772a59SSricharan #define SDRAM_TEMP_VERY_HIGH_SHUTDOWN			0x7
1101bb772a59SSricharan 
1102bb772a59SSricharan #define LPDDR2_MANUFACTURER_SAMSUNG	1
1103bb772a59SSricharan #define LPDDR2_MANUFACTURER_QIMONDA	2
1104bb772a59SSricharan #define LPDDR2_MANUFACTURER_ELPIDA	3
1105bb772a59SSricharan #define LPDDR2_MANUFACTURER_ETRON	4
1106bb772a59SSricharan #define LPDDR2_MANUFACTURER_NANYA	5
1107bb772a59SSricharan #define LPDDR2_MANUFACTURER_HYNIX	6
1108bb772a59SSricharan #define LPDDR2_MANUFACTURER_MOSEL	7
1109bb772a59SSricharan #define LPDDR2_MANUFACTURER_WINBOND	8
1110bb772a59SSricharan #define LPDDR2_MANUFACTURER_ESMT	9
1111bb772a59SSricharan #define LPDDR2_MANUFACTURER_SPANSION 11
1112bb772a59SSricharan #define LPDDR2_MANUFACTURER_SST		12
1113bb772a59SSricharan #define LPDDR2_MANUFACTURER_ZMOS	13
1114bb772a59SSricharan #define LPDDR2_MANUFACTURER_INTEL	14
1115bb772a59SSricharan #define LPDDR2_MANUFACTURER_NUMONYX	254
1116bb772a59SSricharan #define LPDDR2_MANUFACTURER_MICRON	255
1117bb772a59SSricharan 
1118bb772a59SSricharan /* MR8 register fields */
1119bb772a59SSricharan #define MR8_TYPE_SHIFT		0x0
1120bb772a59SSricharan #define MR8_TYPE_MASK		0x3
1121bb772a59SSricharan #define MR8_DENSITY_SHIFT	0x2
1122bb772a59SSricharan #define MR8_DENSITY_MASK	(0xF << 0x2)
1123bb772a59SSricharan #define MR8_IO_WIDTH_SHIFT	0x6
1124bb772a59SSricharan #define MR8_IO_WIDTH_MASK	(0x3 << 0x6)
1125bb772a59SSricharan 
11269ca8bfeaSLokesh Vutla /* SDRAM TYPE */
11279ca8bfeaSLokesh Vutla #define EMIF_SDRAM_TYPE_DDR2	0x2
11289ca8bfeaSLokesh Vutla #define EMIF_SDRAM_TYPE_DDR3	0x3
11299ca8bfeaSLokesh Vutla #define EMIF_SDRAM_TYPE_LPDDR2	0x4
11309ca8bfeaSLokesh Vutla 
1131bb772a59SSricharan struct lpddr2_addressing {
1132bb772a59SSricharan 	u8	num_banks;
1133bb772a59SSricharan 	u8	t_REFI_us_x10;
1134bb772a59SSricharan 	u8	row_sz[2]; /* One entry each for x32 and x16 */
1135bb772a59SSricharan 	u8	col_sz[2]; /* One entry each for x32 and x16 */
1136bb772a59SSricharan };
1137bb772a59SSricharan 
1138bb772a59SSricharan /* Structure for timings from the DDR datasheet */
1139bb772a59SSricharan struct lpddr2_ac_timings {
1140bb772a59SSricharan 	u32 max_freq;
1141bb772a59SSricharan 	u8 RL;
1142bb772a59SSricharan 	u8 tRPab;
1143bb772a59SSricharan 	u8 tRCD;
1144bb772a59SSricharan 	u8 tWR;
1145bb772a59SSricharan 	u8 tRASmin;
1146bb772a59SSricharan 	u8 tRRD;
1147bb772a59SSricharan 	u8 tWTRx2;
1148bb772a59SSricharan 	u8 tXSR;
1149bb772a59SSricharan 	u8 tXPx2;
1150bb772a59SSricharan 	u8 tRFCab;
1151bb772a59SSricharan 	u8 tRTPx2;
1152bb772a59SSricharan 	u8 tCKE;
1153bb772a59SSricharan 	u8 tCKESR;
1154bb772a59SSricharan 	u8 tZQCS;
1155bb772a59SSricharan 	u32 tZQCL;
1156bb772a59SSricharan 	u32 tZQINIT;
1157bb772a59SSricharan 	u8 tDQSCKMAXx2;
1158bb772a59SSricharan 	u8 tRASmax;
1159bb772a59SSricharan 	u8 tFAW;
1160bb772a59SSricharan 
1161bb772a59SSricharan };
1162bb772a59SSricharan 
1163bb772a59SSricharan /*
1164bb772a59SSricharan  * Min tCK values for some of the parameters:
1165bb772a59SSricharan  * If the calculated clock cycles for the respective parameter is
1166bb772a59SSricharan  * less than the corresponding min tCK value, we need to set the min
1167bb772a59SSricharan  * tCK value. This may happen at lower frequencies.
1168bb772a59SSricharan  */
1169bb772a59SSricharan struct lpddr2_min_tck {
1170bb772a59SSricharan 	u32 tRL;
1171bb772a59SSricharan 	u32 tRP_AB;
1172bb772a59SSricharan 	u32 tRCD;
1173bb772a59SSricharan 	u32 tWR;
1174bb772a59SSricharan 	u32 tRAS_MIN;
1175bb772a59SSricharan 	u32 tRRD;
1176bb772a59SSricharan 	u32 tWTR;
1177bb772a59SSricharan 	u32 tXP;
1178bb772a59SSricharan 	u32 tRTP;
1179bb772a59SSricharan 	u8  tCKE;
1180bb772a59SSricharan 	u32 tCKESR;
1181bb772a59SSricharan 	u32 tFAW;
1182bb772a59SSricharan };
1183bb772a59SSricharan 
1184bb772a59SSricharan struct lpddr2_device_details {
1185bb772a59SSricharan 	u8	type;
1186bb772a59SSricharan 	u8	density;
1187bb772a59SSricharan 	u8	io_width;
1188bb772a59SSricharan 	u8	manufacturer;
1189bb772a59SSricharan };
1190bb772a59SSricharan 
1191bb772a59SSricharan struct lpddr2_device_timings {
1192bb772a59SSricharan 	const struct lpddr2_ac_timings **ac_timings;
1193bb772a59SSricharan 	const struct lpddr2_min_tck *min_tck;
1194bb772a59SSricharan };
1195bb772a59SSricharan 
1196bb772a59SSricharan /* Details of the devices connected to each chip-select of an EMIF instance */
1197bb772a59SSricharan struct emif_device_details {
1198bb772a59SSricharan 	const struct lpddr2_device_details *cs0_device_details;
1199bb772a59SSricharan 	const struct lpddr2_device_details *cs1_device_details;
1200bb772a59SSricharan 	const struct lpddr2_device_timings *cs0_device_timings;
1201bb772a59SSricharan 	const struct lpddr2_device_timings *cs1_device_timings;
1202bb772a59SSricharan };
1203bb772a59SSricharan 
1204bb772a59SSricharan /*
1205bb772a59SSricharan  * Structure containing shadow of important registers in EMIF
1206bb772a59SSricharan  * The calculation function fills in this structure to be later used for
1207bb772a59SSricharan  * initialization and DVFS
1208bb772a59SSricharan  */
1209bb772a59SSricharan struct emif_regs {
1210bb772a59SSricharan 	u32 freq;
1211bb772a59SSricharan 	u32 sdram_config_init;
1212bb772a59SSricharan 	u32 sdram_config;
121392b0482cSSricharan R 	u32 sdram_config2;
1214bb772a59SSricharan 	u32 ref_ctrl;
1215802bb57aSLokesh Vutla 	u32 ref_ctrl_final;
1216bb772a59SSricharan 	u32 sdram_tim1;
1217bb772a59SSricharan 	u32 sdram_tim2;
1218bb772a59SSricharan 	u32 sdram_tim3;
12198c17cbdfSJyri Sarha 	u32 ocp_config;
1220bb772a59SSricharan 	u32 read_idle_ctrl;
1221bb772a59SSricharan 	u32 zq_config;
1222bb772a59SSricharan 	u32 temp_alert_config;
1223bb772a59SSricharan 	u32 emif_ddr_phy_ctlr_1_init;
1224bb772a59SSricharan 	u32 emif_ddr_phy_ctlr_1;
1225f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_1;
1226f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_2;
1227f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_3;
1228f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_4;
1229f4010734SSRICHARAN R 	u32 emif_ddr_ext_phy_ctrl_5;
123043037d76SLokesh Vutla 	u32 emif_rd_wr_lvl_rmp_win;
123143037d76SLokesh Vutla 	u32 emif_rd_wr_lvl_rmp_ctl;
123243037d76SLokesh Vutla 	u32 emif_rd_wr_lvl_ctl;
123343037d76SLokesh Vutla 	u32 emif_rd_wr_exec_thresh;
12348038b497SCooper Jr., Franklin 	u32 emif_prio_class_serv_map;
12358038b497SCooper Jr., Franklin 	u32 emif_connect_id_serv_1_map;
12368038b497SCooper Jr., Franklin 	u32 emif_connect_id_serv_2_map;
12378038b497SCooper Jr., Franklin 	u32 emif_cos_config;
1238650fda93SLokesh Vutla 	u32 emif_ecc_ctrl_reg;
1239650fda93SLokesh Vutla 	u32 emif_ecc_address_range_1;
1240650fda93SLokesh Vutla 	u32 emif_ecc_address_range_2;
1241bb772a59SSricharan };
1242bb772a59SSricharan 
1243e05a4f1fSLokesh Vutla struct lpddr2_mr_regs {
1244e05a4f1fSLokesh Vutla 	s8 mr1;
1245e05a4f1fSLokesh Vutla 	s8 mr2;
1246e05a4f1fSLokesh Vutla 	s8 mr3;
1247e05a4f1fSLokesh Vutla 	s8 mr10;
1248e05a4f1fSLokesh Vutla 	s8 mr16;
1249e05a4f1fSLokesh Vutla };
1250e05a4f1fSLokesh Vutla 
125154d022e7SSRICHARAN R struct read_write_regs {
125254d022e7SSRICHARAN R 	u32 read_reg;
125354d022e7SSRICHARAN R 	u32 write_reg;
125454d022e7SSRICHARAN R };
125554d022e7SSRICHARAN R 
get_emif_rev(u32 base)1256d3daba10SLokesh Vutla static inline u32 get_emif_rev(u32 base)
1257d3daba10SLokesh Vutla {
1258d3daba10SLokesh Vutla 	struct emif_reg_struct *emif = (struct emif_reg_struct *)base;
1259d3daba10SLokesh Vutla 
1260d3daba10SLokesh Vutla 	return (readl(&emif->emif_mod_id_rev) & EMIF_REG_MAJOR_REVISION_MASK)
1261d3daba10SLokesh Vutla 		>> EMIF_REG_MAJOR_REVISION_SHIFT;
1262d3daba10SLokesh Vutla }
1263d3daba10SLokesh Vutla 
1264b5e01eecSLokesh Vutla /*
1265b5e01eecSLokesh Vutla  * Get SDRAM type connected to EMIF.
1266b5e01eecSLokesh Vutla  * Assuming similar SDRAM parts are connected to both EMIF's
1267b5e01eecSLokesh Vutla  * which is typically the case. So it is sufficient to get
1268b5e01eecSLokesh Vutla  * SDRAM type from EMIF1.
1269b5e01eecSLokesh Vutla  */
emif_sdram_type(u32 sdram_config)12707c352cd3STom Rini static inline u32 emif_sdram_type(u32 sdram_config)
1271b5e01eecSLokesh Vutla {
12727c352cd3STom Rini 	return (sdram_config & EMIF_REG_SDRAM_TYPE_MASK)
12737c352cd3STom Rini 	       >> EMIF_REG_SDRAM_TYPE_SHIFT;
1274b5e01eecSLokesh Vutla }
1275b5e01eecSLokesh Vutla 
1276bb772a59SSricharan /* assert macros */
1277bb772a59SSricharan #if defined(DEBUG)
1278bb772a59SSricharan #define emif_assert(c)	({ if (!(c)) for (;;); })
1279bb772a59SSricharan #else
1280bb772a59SSricharan #define emif_assert(c)	({ if (0) hang(); })
1281bb772a59SSricharan #endif
1282bb772a59SSricharan 
1283bb772a59SSricharan #ifdef CONFIG_SYS_EMIF_PRECALCULATED_TIMING_REGS
1284bb772a59SSricharan void emif_get_reg_dump(u32 emif_nr, const struct emif_regs **regs);
1285bb772a59SSricharan void emif_get_dmm_regs(const struct dmm_lisa_map_regs **dmm_lisa_regs);
1286bb772a59SSricharan #else
1287bb772a59SSricharan struct lpddr2_device_details *emif_get_device_details(u32 emif_nr, u8 cs,
1288bb772a59SSricharan 			struct lpddr2_device_details *lpddr2_dev_details);
1289bb772a59SSricharan void emif_get_device_timings(u32 emif_nr,
1290bb772a59SSricharan 		const struct lpddr2_device_timings **cs0_device_timings,
1291bb772a59SSricharan 		const struct lpddr2_device_timings **cs1_device_timings);
1292bb772a59SSricharan #endif
1293bb772a59SSricharan 
129425476382SSRICHARAN R void do_ext_phy_settings(u32 base, const struct emif_regs *regs);
1295e05a4f1fSLokesh Vutla void get_lpddr2_mr_regs(const struct lpddr2_mr_regs **regs);
129625476382SSRICHARAN R 
1297bb772a59SSricharan #ifndef CONFIG_SYS_EMIF_PRECALCULATED_TIMING_REGS
1298bb772a59SSricharan extern u32 *const T_num;
1299bb772a59SSricharan extern u32 *const T_den;
1300bb772a59SSricharan #endif
1301bb772a59SSricharan 
1302784ab7c5SLokesh Vutla void config_data_eye_leveling_samples(u32 emif_base);
130354d022e7SSRICHARAN R const struct read_write_regs *get_bug_regs(u32 *iterations);
1304bb772a59SSricharan #endif
1305