xref: /rk3399_rockchip-uboot/arch/arm/include/asm/arch-rockchip/sdram_rv1108.h (revision 355cdcf34508d6ed289df7581f2c562b32e87d25)
195b95808SZhihuan He /*
295b95808SZhihuan He  * Copyright (C) 2018 Rockchip Electronics Co., Ltd
395b95808SZhihuan He  * Author: Zhihuan He <huan.he@rock-chips.com>
495b95808SZhihuan He  * SPDX-License-Identifier:	GPL-2.0+
595b95808SZhihuan He  */
695b95808SZhihuan He 
795b95808SZhihuan He #ifndef _ASM_ARCH_SDRAM_RV1108_H
895b95808SZhihuan He #define _ASM_ARCH_SDRAM_RV1108_H
995b95808SZhihuan He 
1095b95808SZhihuan He #include <common.h>
1195b95808SZhihuan He #include <ram.h>
1295b95808SZhihuan He #include <asm/arch/cru_rv1108.h>
1395b95808SZhihuan He #include <asm/arch/grf_rv1108.h>
1495b95808SZhihuan He #include <asm/arch/pmu_rv1108.h>
1595b95808SZhihuan He #include <asm/arch/sdram_rv1108_pctl_phy.h>
1695b95808SZhihuan He 
1795b95808SZhihuan He #define SR_IDLE			3
1895b95808SZhihuan He #define PD_IDLE			64
1995b95808SZhihuan He #define SDRAM_BEGIN_ADDR	0x60000000
2095b95808SZhihuan He #define SDRAM_END_ADDR		0x80000000
2195b95808SZhihuan He #define PATTERN			(0x5aa5f00f)
2295b95808SZhihuan He 
2395b95808SZhihuan He struct rv1108_service_msch {
2495b95808SZhihuan He 	u32 id_coreid;
2595b95808SZhihuan He 	u32 id_revisionid;
2695b95808SZhihuan He 	u32 ddrconf;
2795b95808SZhihuan He 	u32 ddrtiming;
2895b95808SZhihuan He 	u32 ddrmode;
2995b95808SZhihuan He 	u32 readlatency;
3095b95808SZhihuan He 	u32 reserveds1[8];
3195b95808SZhihuan He 	u32 activate;
3295b95808SZhihuan He 	u32 devtodev;
3395b95808SZhihuan He };
3495b95808SZhihuan He 
3595b95808SZhihuan He enum {
3695b95808SZhihuan He 	/*memory scheduler ddrtiming*/
3795b95808SZhihuan He 	BWRATIO_HALF_BW				= 0x80000000,
3895b95808SZhihuan He 	BWRATIO_HALF_BW_DIS			= 0x0,
3995b95808SZhihuan He };
4095b95808SZhihuan He 
4195b95808SZhihuan He struct dram_info {
4295b95808SZhihuan He 	struct rv1108_cru *cru;
4395b95808SZhihuan He 	struct rv1108_grf *grf;
4495b95808SZhihuan He 	struct rv1108_pmu *pmu;
4595b95808SZhihuan He 	struct rv1108_pmu_grf *pmu_grf;
4695b95808SZhihuan He 	struct ddr_phy *phy;
4795b95808SZhihuan He 	struct ddr_pctl *pctl;
4895b95808SZhihuan He 	struct rv1108_service_msch *service_msch;
4995b95808SZhihuan He 	struct ram_info info;
5095b95808SZhihuan He };
5195b95808SZhihuan He 
5295b95808SZhihuan He struct sdram_params {
53*b86c816cSZhihuan He 	u32 ddr_2t_en;
54*b86c816cSZhihuan He 	struct ddr_config ddr_config_t;
5595b95808SZhihuan He 	struct pll_div dpll_init_cfg;
5695b95808SZhihuan He 	struct ddr_timing ddr_timing_t;
5795b95808SZhihuan He };
5895b95808SZhihuan He 
59*b86c816cSZhihuan He int check_rd_gate(struct dram_info *priv);
60*b86c816cSZhihuan He void enable_low_power(struct dram_info *priv,
61*b86c816cSZhihuan He 		      struct sdram_params *params_priv);
62*b86c816cSZhihuan He void ddr_msch_cfg(struct dram_info *priv,
63*b86c816cSZhihuan He 		  struct sdram_params *params_priv);
64*b86c816cSZhihuan He void ddr_msch_cfg_rbc(struct sdram_params *params_priv,
65*b86c816cSZhihuan He 		      struct dram_info *priv);
66*b86c816cSZhihuan He void ddr_msch_get_max_col(struct dram_info *priv,
67*b86c816cSZhihuan He 			  struct ddr_schedule *sch_priv);
68*b86c816cSZhihuan He void ddr_msch_get_max_row(struct dram_info *priv,
69*b86c816cSZhihuan He 			  struct ddr_schedule *sch_priv);
70*b86c816cSZhihuan He void ddr_phy_dqs_rx_dll_cfg(struct dram_info *priv, u32 freq);
71*b86c816cSZhihuan He void ddr_phy_skew_cfg(struct dram_info *priv);
7295b95808SZhihuan He void enable_ddr_io_ret(struct dram_info *priv);
73*b86c816cSZhihuan He void modify_data_training(struct dram_info *priv,
74*b86c816cSZhihuan He 			  struct sdram_params *params_priv);
75*b86c816cSZhihuan He void move_to_config_state(struct dram_info *priv);
76*b86c816cSZhihuan He void pctl_cfg_grf(struct dram_info *priv,
7795b95808SZhihuan He 		  struct sdram_params *params_priv);
7895b95808SZhihuan He void phy_pctrl_reset_cru(struct dram_info *priv);
79*b86c816cSZhihuan He void rkdclk_init(struct dram_info *priv,
80*b86c816cSZhihuan He 		 struct sdram_params *params_priv);
8195b95808SZhihuan He int rv1108_sdram_init(struct dram_info *sdram_priv,
8295b95808SZhihuan He 		      struct sdram_params *params_priv);
83*b86c816cSZhihuan He void set_bw_grf(struct dram_info *priv);
84*b86c816cSZhihuan He void set_ds_odt(struct dram_info *priv,
85*b86c816cSZhihuan He 		struct sdram_params *params_priv);
86*b86c816cSZhihuan He 
8795b95808SZhihuan He #endif
88