blob: 6a07436059cd5ca4cd7da3ab3b197c97a4866e8b [file] [log] [blame]
Jagan Tekid0af73c2022-12-14 23:20:53 +05301/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright (C) 2020 Rockchip Electronics Co., Ltd
4 */
5
6#ifndef _ASM_ARCH_SDRAM_RK1126_H
7#define _ASM_ARCH_SDRAM_RK1126_H
8
9#include <asm/arch-rockchip/dram_spec_timing.h>
10#include <asm/arch-rockchip/sdram.h>
11#include <asm/arch-rockchip/sdram_common.h>
12#include <asm/arch-rockchip/sdram_msch.h>
13#include <asm/arch-rockchip/sdram_pctl_px30.h>
14#include <asm/arch-rockchip/sdram_phy_rv1126.h>
15
16#define AGINGX0_VAL (4)
17#define AGING_CPU_VAL (0xff)
18#define AGING_NPU_VAL (0xff)
19#define AGING_OTHER_VAL (0x33)
20
21#define PATTERN (0x5aa5f00f)
22
23#define PHY_DDR3_RON_DISABLE (0)
24#define PHY_DDR3_RON_455ohm (1)
25#define PHY_DDR3_RON_230ohm (2)
26#define PHY_DDR3_RON_153ohm (3)
27#define PHY_DDR3_RON_115ohm (4)
28#define PHY_DDR3_RON_91ohm (5)
29#define PHY_DDR3_RON_76ohm (6)
30#define PHY_DDR3_RON_65ohm (7)
31#define PHY_DDR3_RON_57ohm (16)
32#define PHY_DDR3_RON_51ohm (17)
33#define PHY_DDR3_RON_46ohm (18)
34#define PHY_DDR3_RON_41ohm (19)
35#define PHY_DDR3_RON_38ohm (20)
36#define PHY_DDR3_RON_35ohm (21)
37#define PHY_DDR3_RON_32ohm (22)
38#define PHY_DDR3_RON_30ohm (23)
39#define PHY_DDR3_RON_28ohm (24)
40#define PHY_DDR3_RON_27ohm (25)
41#define PHY_DDR3_RON_25ohm (26)
42#define PHY_DDR3_RON_24ohm (27)
43#define PHY_DDR3_RON_23ohm (28)
44#define PHY_DDR3_RON_22ohm (29)
45#define PHY_DDR3_RON_21ohm (30)
46#define PHY_DDR3_RON_20ohm (31)
47
48#define PHY_DDR3_RTT_DISABLE (0)
49#define PHY_DDR3_RTT_561ohm (1)
50#define PHY_DDR3_RTT_282ohm (2)
51#define PHY_DDR3_RTT_188ohm (3)
52#define PHY_DDR3_RTT_141ohm (4)
53#define PHY_DDR3_RTT_113ohm (5)
54#define PHY_DDR3_RTT_94ohm (6)
55#define PHY_DDR3_RTT_81ohm (7)
56#define PHY_DDR3_RTT_72ohm (16)
57#define PHY_DDR3_RTT_64ohm (17)
58#define PHY_DDR3_RTT_58ohm (18)
59#define PHY_DDR3_RTT_52ohm (19)
60#define PHY_DDR3_RTT_48ohm (20)
61#define PHY_DDR3_RTT_44ohm (21)
62#define PHY_DDR3_RTT_41ohm (22)
63#define PHY_DDR3_RTT_38ohm (23)
64#define PHY_DDR3_RTT_37ohm (24)
65#define PHY_DDR3_RTT_34ohm (25)
66#define PHY_DDR3_RTT_32ohm (26)
67#define PHY_DDR3_RTT_31ohm (27)
68#define PHY_DDR3_RTT_29ohm (28)
69#define PHY_DDR3_RTT_28ohm (29)
70#define PHY_DDR3_RTT_27ohm (30)
71#define PHY_DDR3_RTT_25ohm (31)
72
73#define PHY_DDR4_LPDDR3_RON_DISABLE (0)
74#define PHY_DDR4_LPDDR3_RON_482ohm (1)
75#define PHY_DDR4_LPDDR3_RON_244ohm (2)
76#define PHY_DDR4_LPDDR3_RON_162ohm (3)
77#define PHY_DDR4_LPDDR3_RON_122ohm (4)
78#define PHY_DDR4_LPDDR3_RON_97ohm (5)
79#define PHY_DDR4_LPDDR3_RON_81ohm (6)
80#define PHY_DDR4_LPDDR3_RON_69ohm (7)
81#define PHY_DDR4_LPDDR3_RON_61ohm (16)
82#define PHY_DDR4_LPDDR3_RON_54ohm (17)
83#define PHY_DDR4_LPDDR3_RON_48ohm (18)
84#define PHY_DDR4_LPDDR3_RON_44ohm (19)
85#define PHY_DDR4_LPDDR3_RON_40ohm (20)
86#define PHY_DDR4_LPDDR3_RON_37ohm (21)
87#define PHY_DDR4_LPDDR3_RON_34ohm (22)
88#define PHY_DDR4_LPDDR3_RON_32ohm (23)
89#define PHY_DDR4_LPDDR3_RON_30ohm (24)
90#define PHY_DDR4_LPDDR3_RON_28ohm (25)
91#define PHY_DDR4_LPDDR3_RON_27ohm (26)
92#define PHY_DDR4_LPDDR3_RON_25ohm (27)
93#define PHY_DDR4_LPDDR3_RON_24ohm (28)
94#define PHY_DDR4_LPDDR3_RON_23ohm (29)
95#define PHY_DDR4_LPDDR3_RON_22ohm (30)
96#define PHY_DDR4_LPDDR3_RON_21ohm (31)
97
98#define PHY_DDR4_LPDDR3_RTT_DISABLE (0)
99#define PHY_DDR4_LPDDR3_RTT_586ohm (1)
100#define PHY_DDR4_LPDDR3_RTT_294ohm (2)
101#define PHY_DDR4_LPDDR3_RTT_196ohm (3)
102#define PHY_DDR4_LPDDR3_RTT_148ohm (4)
103#define PHY_DDR4_LPDDR3_RTT_118ohm (5)
104#define PHY_DDR4_LPDDR3_RTT_99ohm (6)
105#define PHY_DDR4_LPDDR3_RTT_85ohm (7)
106#define PHY_DDR4_LPDDR3_RTT_76ohm (16)
107#define PHY_DDR4_LPDDR3_RTT_67ohm (17)
108#define PHY_DDR4_LPDDR3_RTT_60ohm (18)
109#define PHY_DDR4_LPDDR3_RTT_55ohm (19)
110#define PHY_DDR4_LPDDR3_RTT_50ohm (20)
111#define PHY_DDR4_LPDDR3_RTT_46ohm (21)
112#define PHY_DDR4_LPDDR3_RTT_43ohm (22)
113#define PHY_DDR4_LPDDR3_RTT_40ohm (23)
114#define PHY_DDR4_LPDDR3_RTT_38ohm (24)
115#define PHY_DDR4_LPDDR3_RTT_36ohm (25)
116#define PHY_DDR4_LPDDR3_RTT_34ohm (26)
117#define PHY_DDR4_LPDDR3_RTT_32ohm (27)
118#define PHY_DDR4_LPDDR3_RTT_31ohm (28)
119#define PHY_DDR4_LPDDR3_RTT_29ohm (29)
120#define PHY_DDR4_LPDDR3_RTT_28ohm (30)
121#define PHY_DDR4_LPDDR3_RTT_27ohm (31)
122
123#define PHY_LPDDR4_RON_DISABLE (0)
124#define PHY_LPDDR4_RON_501ohm (1)
125#define PHY_LPDDR4_RON_253ohm (2)
126#define PHY_LPDDR4_RON_168ohm (3)
127#define PHY_LPDDR4_RON_126ohm (4)
128#define PHY_LPDDR4_RON_101ohm (5)
129#define PHY_LPDDR4_RON_84ohm (6)
130#define PHY_LPDDR4_RON_72ohm (7)
131#define PHY_LPDDR4_RON_63ohm (16)
132#define PHY_LPDDR4_RON_56ohm (17)
133#define PHY_LPDDR4_RON_50ohm (18)
134#define PHY_LPDDR4_RON_46ohm (19)
135#define PHY_LPDDR4_RON_42ohm (20)
136#define PHY_LPDDR4_RON_38ohm (21)
137#define PHY_LPDDR4_RON_36ohm (22)
138#define PHY_LPDDR4_RON_33ohm (23)
139#define PHY_LPDDR4_RON_31ohm (24)
140#define PHY_LPDDR4_RON_29ohm (25)
141#define PHY_LPDDR4_RON_28ohm (26)
142#define PHY_LPDDR4_RON_26ohm (27)
143#define PHY_LPDDR4_RON_25ohm (28)
144#define PHY_LPDDR4_RON_24ohm (29)
145#define PHY_LPDDR4_RON_23ohm (30)
146#define PHY_LPDDR4_RON_22ohm (31)
147
148#define PHY_LPDDR4_RTT_DISABLE (0)
149#define PHY_LPDDR4_RTT_604ohm (1)
150#define PHY_LPDDR4_RTT_303ohm (2)
151#define PHY_LPDDR4_RTT_202ohm (3)
152#define PHY_LPDDR4_RTT_152ohm (4)
153#define PHY_LPDDR4_RTT_122ohm (5)
154#define PHY_LPDDR4_RTT_101ohm (6)
155#define PHY_LPDDR4_RTT_87ohm (7)
156#define PHY_LPDDR4_RTT_78ohm (16)
157#define PHY_LPDDR4_RTT_69ohm (17)
158#define PHY_LPDDR4_RTT_62ohm (18)
159#define PHY_LPDDR4_RTT_56ohm (19)
160#define PHY_LPDDR4_RTT_52ohm (20)
161#define PHY_LPDDR4_RTT_48ohm (21)
162#define PHY_LPDDR4_RTT_44ohm (22)
163#define PHY_LPDDR4_RTT_41ohm (23)
164#define PHY_LPDDR4_RTT_39ohm (24)
165#define PHY_LPDDR4_RTT_37ohm (25)
166#define PHY_LPDDR4_RTT_35ohm (26)
167#define PHY_LPDDR4_RTT_33ohm (27)
168#define PHY_LPDDR4_RTT_32ohm (28)
169#define PHY_LPDDR4_RTT_30ohm (29)
170#define PHY_LPDDR4_RTT_29ohm (30)
171#define PHY_LPDDR4_RTT_27ohm (31)
172
173#define ADD_CMD_CA (0x150)
174#define ADD_GROUP_CS0_A (0x170)
175#define ADD_GROUP_CS0_B (0x1d0)
176#define ADD_GROUP_CS1_A (0x1a0)
177#define ADD_GROUP_CS1_B (0x200)
178
179/* PMUGRF */
180#define PMUGRF_OS_REG0 (0x200)
181#define PMUGRF_OS_REG(n) (PMUGRF_OS_REG0 + (n) * 4)
182#define PMUGRF_CON_DDRPHY_BUFFEREN_MASK (0x3 << (12 + 16))
183#define PMUGRF_CON_DDRPHY_BUFFEREN_EN (0x1 << 12)
184#define PMUGRF_CON_DDRPHY_BUFFEREN_DIS (0x2 << 12)
185
186/* DDR GRF */
187#define DDR_GRF_CON(n) (0 + (n) * 4)
188#define DDR_GRF_STATUS_BASE (0X100)
189#define DDR_GRF_STATUS(n) (DDR_GRF_STATUS_BASE + (n) * 4)
190#define DDR_GRF_LP_CON (0x20)
191
192#define SPLIT_MODE_32_L16_VALID (0)
193#define SPLIT_MODE_32_H16_VALID (1)
194#define SPLIT_MODE_16_L8_VALID (2)
195#define SPLIT_MODE_16_H8_VALID (3)
196
197#define DDR_GRF_SPLIT_CON (0x10)
198#define SPLIT_MODE_MASK (0x3)
199#define SPLIT_MODE_OFFSET (9)
200#define SPLIT_BYPASS_MASK (1)
201#define SPLIT_BYPASS_OFFSET (8)
202#define SPLIT_SIZE_MASK (0xff)
203#define SPLIT_SIZE_OFFSET (0)
204
205/* SGRF SOC_CON13 */
206#define UPCTL2_ASRSTN_REQ(n) (((0x1 << 0) << 16) | ((n) << 0))
207#define UPCTL2_PSRSTN_REQ(n) (((0x1 << 1) << 16) | ((n) << 1))
208#define UPCTL2_SRSTN_REQ(n) (((0x1 << 2) << 16) | ((n) << 2))
209
210/* CRU define */
211/* CRU_PLL_CON0 */
212#define PB(n) ((0x1 << (15 + 16)) | ((n) << 15))
213#define POSTDIV1(n) ((0x7 << (12 + 16)) | ((n) << 12))
214#define FBDIV(n) ((0xFFF << 16) | (n))
215
216/* CRU_PLL_CON1 */
217#define RSTMODE(n) ((0x1 << (15 + 16)) | ((n) << 15))
218#define RST(n) ((0x1 << (14 + 16)) | ((n) << 14))
219#define PD(n) ((0x1 << (13 + 16)) | ((n) << 13))
220#define DSMPD(n) ((0x1 << (12 + 16)) | ((n) << 12))
221#define LOCK(n) (((n) >> 10) & 0x1)
222#define POSTDIV2(n) ((0x7 << (6 + 16)) | ((n) << 6))
223#define REFDIV(n) ((0x3F << 16) | (n))
224
225/* CRU_PLL_CON3 */
226#define SSMOD_SPREAD(n) ((0x1f << (8 + 16)) | ((n) << 8))
227#define SSMOD_DIVVAL(n) ((0xf << (4 + 16)) | ((n) << 4))
228#define SSMOD_DOWNSPREAD(n) ((0x1 << (3 + 16)) | ((n) << 3))
229#define SSMOD_RESET(n) ((0x1 << (2 + 16)) | ((n) << 2))
230#define SSMOD_DIS_SSCG(n) ((0x1 << (1 + 16)) | ((n) << 1))
231#define SSMOD_BP(n) ((0x1 << (0 + 16)) | ((n) << 0))
232
233/* CRU_MODE */
234#define CLOCK_FROM_XIN_OSC (0)
235#define CLOCK_FROM_PLL (1)
236#define CLOCK_FROM_RTC_32K (2)
237#define DPLL_MODE(n) ((0x3 << (2 + 16)) | ((n) << 2))
238
239/* CRU_SOFTRESET_CON1 */
240#define DDRPHY_PSRSTN_REQ(n) (((0x1 << 14) << 16) | ((n) << 14))
241#define DDRPHY_SRSTN_REQ(n) (((0x1 << 15) << 16) | ((n) << 15))
242/* CRU_CLKGATE_CON2 */
243#define DDR_MSCH_EN_MASK ((0x1 << 10) << 16)
244#define DDR_MSCH_EN_SHIFT (10)
245
246/* CRU register */
247#define CRU_PLL_CON(pll_id, n) ((pll_id) * 0x20 + (n) * 4)
248#define CRU_MODE (0xa0)
249#define CRU_GLB_CNT_TH (0xb0)
250#define CRU_CLKSEL_CON_BASE 0x100
251#define CRU_CLKSELS_CON(i) (CRU_CLKSEL_CON_BASE + ((i) * 4))
252#define CRU_CLKGATE_CON_BASE 0x230
253#define CRU_CLKGATE_CON(i) (CRU_CLKGATE_CON_BASE + ((i) * 4))
254#define CRU_CLKSFTRST_CON_BASE 0x300
255#define CRU_CLKSFTRST_CON(i) (CRU_CLKSFTRST_CON_BASE + ((i) * 4))
256
257/* SGRF_SOC_CON2 */
258#define MSCH_AXI_BYPASS_ALL_MASK (1)
259#define MSCH_AXI_BYPASS_ALL_SHIFT (15)
260
261/* SGRF_SOC_CON12 */
262#define CLK_DDR_UPCTL_EN_MASK ((0x1 << 2) << 16)
263#define CLK_DDR_UPCTL_EN_SHIFT (2)
264#define ACLK_DDR_UPCTL_EN_MASK ((0x1 << 0) << 16)
265#define ACLK_DDR_UPCTL_EN_SHIFT (0)
266
267/* DDRGRF DDR CON2 */
268#define DFI_FREQ_CHANGE_ACK BIT(10)
269/* DDRGRF status8 */
270#define DFI_FREQ_CHANGE_REQ BIT(19)
271
272struct rv1126_ddrgrf {
273 u32 ddr_grf_con[4];
274 u32 grf_ddrsplit_con;
275 u32 reserved1[(0x20 - 0x10) / 4 - 1];
276 u32 ddr_grf_lp_con;
277 u32 reserved2[(0x40 - 0x20) / 4 - 1];
278 u32 grf_ddrphy_con[6];
279 u32 reserved3[(0x100 - 0x54) / 4 - 1];
280 u32 ddr_grf_status[18];
281 u32 reserved4[(0x150 - 0x144) / 4 - 1];
282 u32 grf_ddrhold_status;
283 u32 reserved5[(0x160 - 0x150) / 4 - 1];
284 u32 grf_ddrphy_status[2];
285};
286
287struct rv1126_ddr_phy_regs {
288 u32 phy[8][2];
289};
290
291struct msch_regs {
292 u32 coreid;
293 u32 revisionid;
294 u32 deviceconf;
295 u32 devicesize;
296 u32 ddrtiminga0;
297 u32 ddrtimingb0;
298 u32 ddrtimingc0;
299 u32 devtodev0;
300 u32 reserved1[(0x110 - 0x20) / 4];
301 u32 ddrmode;
302 u32 ddr4timing;
303 u32 reserved2[(0x1000 - 0x118) / 4];
304 u32 agingx0;
305 u32 reserved3[(0x1040 - 0x1004) / 4];
306 u32 aging0;
307 u32 aging1;
308 u32 aging2;
309 u32 aging3;
310};
311
312struct sdram_msch_timings {
313 union noc_ddrtiminga0 ddrtiminga0;
314 union noc_ddrtimingb0 ddrtimingb0;
315 union noc_ddrtimingc0 ddrtimingc0;
316 union noc_devtodev_rv1126 devtodev0;
317 union noc_ddrmode ddrmode;
318 union noc_ddr4timing ddr4timing;
319 u32 agingx0;
320 u32 aging0;
321 u32 aging1;
322 u32 aging2;
323 u32 aging3;
324};
325
326struct rv1126_sdram_channel {
327 struct sdram_cap_info cap_info;
328 struct sdram_msch_timings noc_timings;
329};
330
331struct rv1126_sdram_params {
332 struct rv1126_sdram_channel ch;
333 struct sdram_base_params base;
334 struct ddr_pctl_regs pctl_regs;
335 struct rv1126_ddr_phy_regs phy_regs;
336};
337
338struct rv1126_fsp_param {
339 u32 flag;
340 u32 freq_mhz;
341
342 /* dram size */
343 u32 dq_odt;
344 u32 ca_odt;
345 u32 ds_pdds;
346 u32 vref_ca[2];
347 u32 vref_dq[2];
348
349 /* phy side */
350 u32 wr_dq_drv;
351 u32 wr_ca_drv;
352 u32 wr_ckcs_drv;
353 u32 rd_odt;
354 u32 rd_odt_up_en;
355 u32 rd_odt_down_en;
356 u32 vref_inner;
357 u32 vref_out;
358 u32 lp4_drv_pd_en;
359
360 struct sdram_msch_timings noc_timings;
361};
362
363#define MAX_IDX (4)
364#define FSP_FLAG (0xfead0001)
365#define SHARE_MEM_BASE (0x100000)
366/*
367 * Borrow share memory space to temporarily store FSP parame.
368 * In the stage of DDR init write FSP parame to this space.
369 * In the stage of trust init move FSP parame to SRAM space
370 * from share memory space.
371 */
372#define FSP_PARAM_STORE_ADDR (SHARE_MEM_BASE)
373
374/* store result of read and write training, for ddr_dq_eye tool in u-boot */
375#define RW_TRN_RESULT_ADDR (0x2000000 + 0x8000) /* 32M + 32k */
376#define PRINT_STEP 1
377
378#undef FSP_NUM
379#undef CS_NUM
380#undef BYTE_NUM
381
382#define FSP_NUM 4
383#define CS_NUM 2
384#define BYTE_NUM 4
385#define RD_DESKEW_NUM 64
386#define WR_DESKEW_NUM 64
387
388#define LP4_WIDTH_REF_MHZ_H 1056
389#define LP4_RD_WIDTH_REF_H 12
390#define LP4_WR_WIDTH_REF_H 13
391
392#define LP4_WIDTH_REF_MHZ_L 924
393#define LP4_RD_WIDTH_REF_L 15
394#define LP4_WR_WIDTH_REF_L 15
395
396#define DDR4_WIDTH_REF_MHZ_H 1056
397#define DDR4_RD_WIDTH_REF_H 13
398#define DDR4_WR_WIDTH_REF_H 9
399
400#define DDR4_WIDTH_REF_MHZ_L 924
401#define DDR4_RD_WIDTH_REF_L 15
402#define DDR4_WR_WIDTH_REF_L 11
403
404#define LP3_WIDTH_REF_MHZ_H 1056
405#define LP3_RD_WIDTH_REF_H 15
406#define LP3_WR_WIDTH_REF_H 13
407
408#define LP3_WIDTH_REF_MHZ_L 924
409#define LP3_RD_WIDTH_REF_L 16
410#define LP3_WR_WIDTH_REF_L 15
411
412#define DDR3_WIDTH_REF_MHZ_H 1056
413#define DDR3_RD_WIDTH_REF_H 14
414#define DDR3_WR_WIDTH_REF_H 14
415
416#define DDR3_WIDTH_REF_MHZ_L 924
417#define DDR3_RD_WIDTH_REF_L 17
418#define DDR3_WR_WIDTH_REF_L 17
419
420#endif /* _ASM_ARCH_SDRAM_RK1126_H */