7 #include <soc/dramc_register.h>
8 #include <soc/dramc_pi_api.h>
25 switch (impcal_stage) {
38 clrsetbits32(&
ch[0].phy.shu[0].ca_cmd[11], 0x3f << 8, vref_sel << 8);
44 u32 broadcast_bak, impcal_bak, imp_cal_result;
45 u32 DRVP_result = 0xff, ODTN_result = 0xff, DRVN_result = 0x9;
52 write32(&
ch[chn].phy.misc_spm_ctrl2, 0x0);
53 write32(&
ch[chn].phy.misc_spm_ctrl0, 0x0);
57 impcal_bak =
read32(&
ch[0].ao.impcal);
68 clrbits32(&
ch[0].ao.shu[0].impcal1, 0x1f << 4 | 0x1f << 11);
71 for (
u8 impx_drv = 0; impx_drv < 32; impx_drv++) {
72 impx_drv = (impx_drv == 16) ? 29 : impx_drv;
75 0x1f << 4, impx_drv << 4);
77 imp_cal_result = (
read32(&
ch[0].phy_nao.misc_phy_rgs_cmd) >>
80 impx_drv, imp_cal_result);
82 if (imp_cal_result == 1 && DRVP_result == 0xff) {
83 DRVP_result = impx_drv;
84 dramc_dbg(
"1. OCD DRVP calibration OK! DRVP=%d\n",
99 for (
u8 impx_drv = 0; impx_drv < 32; impx_drv++) {
100 impx_drv = (impx_drv == 16) ? 29 : impx_drv;
103 0x1f << 11, impx_drv << 11);
105 imp_cal_result = (
read32(&
ch[0].phy_nao.misc_phy_rgs_cmd) >>
108 impx_drv, imp_cal_result);
110 if (imp_cal_result == 0 && ODTN_result == 0xff) {
111 ODTN_result = impx_drv;
112 dramc_dbg(
"3. OCD ODTN calibration OK! ODTN=%d\n",
120 dramc_dbg(
"impedance: term=%d, DRVP=%d, DRVN=%d, ODTN=%d\n",
121 term, DRVP_result, DRVN_result, ODTN_result);
122 u32 *imp = impedance->
data[term];
124 imp[0] = DRVP_result;
125 imp[1] = ODTN_result;
129 imp[0] = (DRVP_result <= 3) ? (DRVP_result * 3) : DRVP_result;
130 imp[1] = (DRVN_result <= 3) ? (DRVN_result * 3) : DRVN_result;
132 imp[3] = (ODTN_result <= 3) ? (ODTN_result * 3) : ODTN_result;
143 u32 sw_impedance[2][4] = {0};
148 for (
u8 term = 0; term < 2; term++)
149 for (
u8 i = 0; i < 4; i++)
150 sw_impedance[term][i] = impedance->
data[term][i];
156 clrsetbits32(&
ch[0].ao.shu[0].drving[0], (0x1f << 5) | (0x1f << 0),
157 (sw_impedance[dq_term][0] << 5) |
158 (sw_impedance[dq_term][1] << 0));
160 (0x1f << 25) | (0x1f << 20) | (1 << 31),
161 (sw_impedance[dq_term][0] << 25) |
162 (sw_impedance[dq_term][1] << 20) | (!dq_term << 31));
163 clrsetbits32(&
ch[0].ao.shu[0].drving[2], (0x1f << 5) | (0x1f << 0),
164 (sw_impedance[dq_term][2] << 5) |
165 (sw_impedance[dq_term][3] << 0));
166 clrsetbits32(&
ch[0].ao.shu[0].drving[3], (0x1f << 25) | (0x1f << 20),
167 (sw_impedance[dq_term][2] << 25) |
168 (sw_impedance[dq_term][3] << 20));
171 for (
u8 i = 0; i <= 2; i += 2) {
173 (0x1f << 25) | (0x1f << 20),
174 (sw_impedance[dq_term][i] << 25) |
175 (sw_impedance[dq_term][i + 1] << 20));
177 (0x1f << 15) | (0x1f << 10),
178 (sw_impedance[dq_term][i] << 15) |
179 (sw_impedance[dq_term][i + 1] << 10));
183 for (
u8 i = 1; i <= 3; i += 2) {
185 (0x1f << 15) | (0x1f << 10),
186 (sw_impedance[ca_term][i - 1] << 15) |
187 (sw_impedance[ca_term][i] << 10));
189 (0x1f << 5) | (0x1f << 0),
190 (sw_impedance[ca_term][i - 1] << 5) |
191 (sw_impedance[ca_term][i] << 0));
195 sw_impedance[ca_term][0] << 17);
197 sw_impedance[ca_term][1] << 22);
200 SHU1_CA_CMD3_RG_TX_ARCMD_PU_PRE, 1);
202 SHU1_CA_CMD0_RG_TX_ARCLK_DRVN_PRE, 0);
212 u8 shu_lev = (
read32(&
ch[0].ao.shustatus) >> 1) & 0x3;
215 (0xffff << 16) | (0x1 << 0),
216 (0xb16 << 16) | (0x1 << 0));
226 shu_lev = (shu_lev == 1) ? 2 : 1;
229 0x3 << 2, shu_lev << 2);
241 write32(&
ch[chn].phy.misc_cg_ctrl1, 0xffffffff);
244 for (
size_t r = 0; r < 2; r++)
245 for (
size_t b = 0; b < 2; b++)
246 clrbits32(&
ch[chn].phy.r[r].b[b].rxdvs[2], 3 << 30);
251 for (
size_t r = 0; r < 2; r++)
252 for (
size_t b = 0; b < 2; b++) {
253 clrbits32(&
ch[chn].phy.r[r].b[b].rxdvs[2], 1 << 29);
255 (0x3f << 0) | (0x3f << 8) |
256 (0x7f << 16) | (0x7f << 24),
257 (0x0 << 0) | (0x3f << 8) |
258 (0x0 << 16) | (0x7f << 24));
260 (0xffff << 16) | (0xffff << 0),
261 (0x2 << 16) | (0x2 << 0));
265 (0x3 << 26) | (0x3 << 24) |
266 (0x3 << 18) | (0x3 << 16));
271 (0x1 << 29) | (0xf << 4) | (0x1 << 0),
272 (0x1 << 29) | (0x0 << 4) | (0x1 << 0));
274 (0x1 << 29) | (0xf << 4) | (0x1 << 0),
275 (0x1 << 29) | (0x0 << 4) | (0x1 << 0));
277 for (
u8 b = 0; b < 2; b++)
279 (0x7 << 28) | (0x7 << 24),
280 (0x1 << 28) | (0x0 << 24));
281 clrbits32(&
ch[chn].phy.ca_cmd[10], (0x7 << 28) | (0x7 << 24));
282 for (
u8 b = 0; b < 2; b++)
285 setbits32(&
ch[chn].phy.b0_rxdvs[0], (0x1 << 28) | (0x1 << 31));
286 setbits32(&
ch[chn].phy.b1_rxdvs[0], (0x1 << 28) | (0x1 << 31));
288 for (
u8 b = 0; b < 2; b++)
290 (0x3 << 30) | (0x1 << 28) | (0x1 << 23),
291 (0x2 << 30) | (0x1 << 28) | (0x1 << 23));
298 (0x1 << 21) | (0x3 << 15) | (0x1f << 8) | (0x1 << 4),
299 (0x3 << 26) | (0x1 << 0));
301 (0xffff << 16) | (0x1 << 8) | (0x1 << 6),
302 (0x1 << 16) | (0x1 << 8) | (0x1 << 6));
305 (0x1 << 24) | (0x1f << 11) | (0xf << 0),
306 (0x1 << 24) | (0x0 << 11) | (0x0 << 0));
316 (0x7 << 22) | (0x3 << 14) | (0x1 << 19) | (0x1 << 21));
317 setbits32(&
ch[chn].ao.stbcal, (0x1 << 20) | (0x3 << 28));
327 setbits32(&
ch[chn].ao.impcal, (0x1 << 31) | (0x1 << 29) |
328 (0x1 << 26) | (0x1 << 17) | (0x7 << 11));
335 setbits32(&
ch[chn].ao.refctrl0, (0x1 << 2) | (0x1 << 3));
340 for (
u8 b = 0; b < 2; b++) {
341 clrbits32(&
ch[chn].phy.b[b].dll_fine_tune[2], 0x3fffff << 10);
342 write32(&
ch[chn].phy.b[b].dll_fine_tune[3], 0x2e800);
345 0x3fffff << 10, 0x2 << 10);
346 write32(&
ch[chn].phy.ca_dll_fine_tune[3],
354 for (
size_t r = 0; r < 2; r++)
355 for (
size_t i = 0; i < 4; i++)
356 write32(&
ch[chn].ao.rk[r].dummy_rd_wdata[i],
360 for (
size_t r = 0; r < 2; r++) {
362 (0x1ffff << 0) | (0x7ff << 17) | (0xf << 28),
363 (0xffff << 0) | (0x3f0 << 17));
364 clrbits32(&
ch[chn].ao.rk[r].dummy_rd_bk, 0x7 << 0);
367 clrbits32(&
ch[chn].ao.dummy_rd, 0x1 << 25 | 0x1 << 20);
372 clrsetbits32(&
ch[chn].ao.rkcfg, (0x1 << 15) | (0x1 << 12), 0x1 << 2);
374 (0x1 << 1) | (0xf << 8) | (0x7 << 13),
375 (0x4 << 8) | (0x2 << 13));
379 (0x1 << 29) | (0x1 << 31));
400 (0x7 << 0) | (0x1 << 26) | (0x1 << 30) | (0x1 << 31),
401 (0x7 << 0) | (0x1 << 30) | (0x1 << 31));
426 (0x3 << 4) | (0x3 << 8) | (0x1 << 28));
441 (0x1 << 1) | (0x3 << 13));
445 write32(&
ch[0].phy.misc_spm_ctrl0, 0xfbffefff);
446 write32(&
ch[1].phy.misc_spm_ctrl0, 0xfbffefff);
447 write32(&
ch[0].phy.misc_spm_ctrl2, 0xffffffef);
448 write32(&
ch[1].phy.misc_spm_ctrl2, 0x7fffffef);
456 setbits32(&
ch[chn].ao.hw_mrr_fun, (0x1 << 0) | (0x1 << 11));
462 clrbits32(&
ch[chn].ao.rstmask, (0x1 << 25) | (0x1 << 28));
470 clrbits32(&
ch[chn].ao.refctrl1, (0x1 << 6) | (0x3 << 2));
478 (0x1 << 0) | (0x1 << 2) | (0x1 << 4) | (0x1 << 5) | (0x1 << 6) |
479 (0xf << 8) | (0x7f << 12) | (0x1 << 19) | (0x1 << 21),
480 (0x1 << 0) | (0x0 << 2) | (0x0 << 4) | (0x1 << 5) | (0x0 << 6) |
481 (0x8 << 8) | (0x3 << 12) | (0x1 << 19) | (0x0 << 21));
static void write32(void *addr, uint32_t val)
static uint32_t read32(const void *addr)
static struct sdram_info params
#define dramc_dbg(_x_...)
#define setbits32(addr, set)
#define SET32_BITFIELDS(addr,...)
#define clrsetbits32(addr, clear, set)
#define clrbits32(addr, clear)
void dramc_runtime_config(u32 channel, const struct mt8173_sdram_params *sdram_params)
static struct dramc_channel const ch[2]
static struct mtk_spm_regs *const mtk_spm
static void dramc_pa_improve(u8 chn)
static void dramc_hw_dqs_gating_tracking(u8 chn)
static void dramc_sw_imp_cal_vref_sel(u8 term_option, u8 impcal_stage)
static void dramc_set_CKE_2_rank_independent(u8 chn)
static void dramc_phy_low_power_enable(u8 chn)
static void dramc_rx_input_delay_tracking(u8 chn)
void dramc_sw_impedance_cal(const struct sdram_params *params, u8 term, struct dram_impedance *impedance)
static void transfer_pll_to_spm_control(void)
static void dramc_impedance_tracking_enable(void)
static void dramc_hw_gating_init(u8 chn)
static void dramc_dummy_read_for_tracking_enable(u8 chn, u32 rk_num)
static void dramc_enable_dramc_dcm(void)
void dramc_sw_impedance_save_reg(u8 freq_group, const struct dram_impedance *impedance)
void dramc_hw_dqsosc(u8 chn, u32 rk_num)
void dramc_dqs_precalculation_preset(void)
void dramc_hw_gating_onoff(u8 chn, bool on)
void dramc_enable_phy_dcm(u8 chn, bool en)
void enable_emi_dcm(void)
u32 dramc_get_broadcast(void)
void dramc_set_broadcast(u32 onoff)
#define IMP_DRVN_LP4X_UNTERM_VREF_SEL
#define IMP_DRVP_LP4X_UNTERM_VREF_SEL
#define IMP_LP4X_TERM_VREF_SEL
#define DRAMC_BROADCAST_OFF
#define DRAMC_BROADCAST_ON
#define IMP_TRACK_LP4X_UNTERM_VREF_SEL
u32 dramc_dpy_clk_sw_con_sel
u32 dramc_dpy_clk_sw_con2
u32 dramc_dpy_clk_sw_con_sel2
Defines the SDRAM parameter structure.