1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * (C) Copyright 2017 Rockchip Electronics Co., Ltd
5 #ifndef _ASM_ARCH_SDRAM_RK322X_H
6 #define _ASM_ARCH_SDRAM_RK322X_H
17 struct rk322x_sdram_channel {
19 * bit width in address, eg:
20 * 8 banks using 3 bit to address,
21 * 2 cs using 1 bit to address.
31 #if CONFIG_IS_ENABLED(OF_PLATDATA)
33 * For of-platdata, which would otherwise convert this into two
34 * byte-swapped integers. With a size of 9 bytes, this struct will
35 * appear in of-platdata as a byte array.
37 * If OF_PLATDATA enabled, need to add a dummy byte in dts.(i.e 0xff)
43 struct rk322x_ddr_pctl {
48 u32 reserved0[(0x40 - 0x10) / 4];
54 u32 reserved1[(0x60 - 0x54) / 4];
58 u32 reserved2[(0x7c - 0x6c) / 4];
75 u32 reserved4[(0xc0 - 0xb4) / 4];
112 u32 reserved5[(0x180 - 0x14c) / 4];
117 u32 reserved6[(0x200 - 0x190) / 4];
134 /* dfi control registers */
139 /* dfi write data registers */
142 u32 reserved7[(0x260 - 0x258) / 4];
145 u32 reserved8[(0x270 - 0x268) / 4];
157 u32 reserved10[(0x2ac - 0x29c) / 4];
162 u32 dfitrrdlvlgateen;
172 u32 reserved12[(0x2f0 - 0x2e4) / 4];
175 u32 reserved13[(0x300 - 0x2f4) / 4];
182 u32 dfitrwrlvldelay0;
183 u32 dfitrwrlvldelay1;
184 u32 dfitrwrlvldelay2;
185 u32 dfitrrdlvldelay0;
186 u32 dfitrrdlvldelay1;
187 u32 dfitrrdlvldelay2;
188 u32 dfitrrdlvlgatedelay0;
189 u32 dfitrrdlvlgatedelay1;
190 u32 dfitrrdlvlgatedelay2;
192 u32 reserved14[(0x3f8 - 0x340) / 4];
196 check_member(rk322x_ddr_pctl, iptr, 0x03fc);
198 struct rk322x_ddr_phy {
199 u32 ddrphy_reg[0x100];
202 struct rk322x_pctl_timing {
240 struct rk322x_phy_timing {
247 struct rk322x_msch_timings {
255 struct rk322x_service_sys {
266 struct rk322x_base_params {
267 struct rk322x_msch_timings noc_timing;
279 #define DFI_INIT_START BIT(0)
280 #define DFI_DATA_BYTE_DISABLE_EN BIT(2)
283 #define DFI_DRAM_CLK_SR_EN BIT(0)
284 #define DFI_DRAM_CLK_DPD_EN BIT(1)
287 #define DFI_PARITY_INTR_EN BIT(0)
288 #define DFI_PARITY_EN BIT(1)
291 #define TLP_RESP_TIME_SHIFT 16
292 #define LP_SR_EN BIT(8)
293 #define LP_PD_EN BIT(0)
295 /* PCT_DFITCTRLDELAY */
296 #define TCTRL_DELAY_TIME_SHIFT 0
298 /* PCT_DFITPHYWRDATA */
299 #define TPHY_WRDATA_TIME_SHIFT 0
301 /* PCT_DFITPHYRDLAT */
302 #define TPHY_RDLAT_TIME_SHIFT 0
304 /* PCT_DFITDRAMCLKDIS */
305 #define TDRAM_CLK_DIS_TIME_SHIFT 0
307 /* PCT_DFITDRAMCLKEN */
308 #define TDRAM_CLK_EN_TIME_SHIFT 0
311 #define RANK0_ODT_WRITE_SEL BIT(3)
312 #define RANK1_ODT_WRITE_SEL BIT(11)
314 /* PCTL_DFIODTCFG1 */
315 #define ODT_LEN_BL8_W_SHIFT 16
318 #define ACDLLCR_DLLDIS BIT(31)
319 #define ACDLLCR_DLLSRST BIT(30)
322 #define DXDLLCR_DLLDIS BIT(31)
323 #define DXDLLCR_DLLSRST BIT(30)
326 #define DLLGCR_SBIAS BIT(30)
329 #define DQSRTT BIT(9)
330 #define DQRTT BIT(10)
333 #define PIR_INIT BIT(0)
334 #define PIR_DLLSRST BIT(1)
335 #define PIR_DLLLOCK BIT(2)
336 #define PIR_ZCAL BIT(3)
337 #define PIR_ITMSRST BIT(4)
338 #define PIR_DRAMRST BIT(5)
339 #define PIR_DRAMINIT BIT(6)
340 #define PIR_QSTRN BIT(7)
341 #define PIR_RVTRN BIT(8)
342 #define PIR_ICPC BIT(16)
343 #define PIR_DLLBYP BIT(17)
344 #define PIR_CTLDINIT BIT(18)
345 #define PIR_CLRSR BIT(28)
346 #define PIR_LOCKBYP BIT(29)
347 #define PIR_ZCALBYP BIT(30)
348 #define PIR_INITBYP BIT(31)
351 #define PGCR_DFTLMT_SHIFT 3
352 #define PGCR_DFTCMP_SHIFT 2
353 #define PGCR_DQSCFG_SHIFT 1
354 #define PGCR_ITMDMD_SHIFT 0
357 #define PGSR_IDONE BIT(0)
358 #define PGSR_DLDONE BIT(1)
359 #define PGSR_ZCDONE BIT(2)
360 #define PGSR_DIDONE BIT(3)
361 #define PGSR_DTDONE BIT(4)
362 #define PGSR_DTERR BIT(5)
363 #define PGSR_DTIERR BIT(6)
364 #define PGSR_DFTERR BIT(7)
365 #define PGSR_RVERR BIT(8)
366 #define PGSR_RVEIRR BIT(9)
369 #define PRT_ITMSRST_SHIFT 18
370 #define PRT_DLLLOCK_SHIFT 6
371 #define PRT_DLLSRST_SHIFT 0
374 #define PRT_DINIT0_SHIFT 0
375 #define PRT_DINIT1_SHIFT 19
378 #define PRT_DINIT2_SHIFT 0
379 #define PRT_DINIT3_SHIFT 17
382 #define DDRMD_LPDDR 0
386 #define DDRMD_LPDDR2_LPDDR3 4
388 #define DDRMD_SHIFT 0
393 #define DQSNRES_MASK 0xf
394 #define DQSNRES_SHIFT 8
395 #define DQSRES_MASK 0xf
396 #define DQSRES_SHIFT 4
399 #define TDQSCKMAX_SHIFT 27
400 #define TDQSCKMAX_MASK 7
401 #define TDQSCK_SHIFT 24
402 #define TDQSCK_MASK 7
405 #define DQSGX_SHIFT 5
407 #define DQSGE_SHIFT 8
414 #define SLEEP_STATE 3
415 #define WAKEUP_STATE 4
418 #define LP_TRIG_SHIFT 4
419 #define LP_TRIG_MASK 7
420 #define PCTL_STAT_MASK 7
427 #define LOW_POWER_ENTRY_REQ 6
428 #define LOW_POWER_EXIT_REQ 7
431 #define PD_OUTPUT_SHIFT 0
432 #define PU_OUTPUT_SHIFT 5
433 #define PD_ONDIE_SHIFT 10
434 #define PU_ONDIE_SHIFT 15
435 #define ZDEN_SHIFT 28
438 #define SBIAS_BYPASS BIT(23)
441 #define MDDR_LPDDR2_CLK_STOP_IDLE_SHIFT 24
442 #define PD_IDLE_SHIFT 8
443 #define MDDR_EN (2 << 22)
444 #define LPDDR2_EN (3 << 22)
445 #define LPDDR3_EN (1 << 22)
446 #define DDR2_EN (0 << 5)
447 #define DDR3_EN (1 << 5)
448 #define LPDDR2_S2 (0 << 6)
449 #define LPDDR2_S4 (1 << 6)
450 #define MDDR_LPDDR2_BL_2 (0 << 20)
451 #define MDDR_LPDDR2_BL_4 (1 << 20)
452 #define MDDR_LPDDR2_BL_8 (2 << 20)
453 #define MDDR_LPDDR2_BL_16 (3 << 20)
454 #define DDR2_DDR3_BL_4 0
455 #define DDR2_DDR3_BL_8 1
456 #define TFAW_SHIFT 18
457 #define PD_EXIT_SLOW (0 << 17)
458 #define PD_EXIT_FAST (1 << 17)
459 #define PD_TYPE_SHIFT 16
460 #define BURSTLENGTH_SHIFT 20
463 #define POWER_UP_START BIT(0)
466 #define POWER_UP_DONE BIT(0)
481 #define BANK_ADDR_MASK 7
482 #define BANK_ADDR_SHIFT 17
483 #define CMD_ADDR_MASK 0x1fff
484 #define CMD_ADDR_SHIFT 4
486 #define LPDDR23_MA_SHIFT 4
487 #define LPDDR23_MA_MASK 0xff
488 #define LPDDR23_OP_SHIFT 12
489 #define LPDDR23_OP_MASK 0xff
491 #define START_CMD (1u << 31)
497 SOFT_DERESET_ANALOG = 1 << 2,
498 SOFT_DERESET_DIGITAL = 1 << 3,
499 SOFT_RESET_SHIFT = 2,
511 MEMORY_SELECT_DDR3 = 0 << 0,
512 MEMORY_SELECT_LPDDR3 = 2 << 0,
513 MEMORY_SELECT_LPDDR2 = 3 << 0,
514 DQS_SQU_CAL_SEL_CS0_CS1 = 0 << 4,
515 DQS_SQU_CAL_SEL_CS1 = 1 << 4,
516 DQS_SQU_CAL_SEL_CS0 = 2 << 4,
517 DQS_SQU_CAL_NORMAL_MODE = 0 << 1,
518 DQS_SQU_CAL_BYPASS_MODE = 1 << 1,
519 DQS_SQU_CAL_START = 1 << 0,
520 DQS_SQU_NO_CAL = 0 << 0,
523 /* CK pull up/down driver strength control */
525 PHY_RON_RTT_DISABLE = 0,
526 PHY_RON_RTT_451OHM = 1,
532 PHY_RON_RTT_64OHM = 7,
534 PHY_RON_RTT_56OHM = 16,
541 PHY_RON_RTT_30OHM = 23,
543 PHY_RON_RTT_28OHM = 24,
550 PHY_RON_RTT_19OHM = 31,
553 /* DQS squelch DLL delay */
555 DQS_DLL_NO_DELAY = 0,
566 #define GRF_DDR_16BIT_EN (((0x1 << 0) << 16) | (0x1 << 0))
567 #define GRF_DDR_32BIT_EN (((0x1 << 0) << 16) | (0x0 << 0))
568 #define GRF_MSCH_NOC_16BIT_EN (((0x1 << 7) << 16) | (0x1 << 7))
569 #define GRF_MSCH_NOC_32BIT_EN (((0x1 << 7) << 16) | (0x0 << 7))
571 #define GRF_DDRPHY_BUFFEREN_CORE_EN (((0x1 << 8) << 16) | (0x0 << 8))
572 #define GRF_DDRPHY_BUFFEREN_CORE_DIS (((0x1 << 8) << 16) | (0x1 << 8))
574 #define GRF_DDR3_EN (((0x1 << 6) << 16) | (0x1 << 6))
575 #define GRF_LPDDR2_3_EN (((0x1 << 6) << 16) | (0x0 << 6))
577 #define PHY_DRV_ODT_SET(n) (((n) << 4) | (n))
578 #define DDR3_DLL_RESET (1 << 8)
580 #endif /* _ASM_ARCH_SDRAM_RK322X_H */