Lines Matching +full:- +full:chn +full:- +full:disabled

1 // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
12 #include <dt-structs.h>
103 rk_clrsetreg(&cru->cru_softrst_con[5], in ddr_reset()
116 rk_clrsetreg(&cru->cru_softrst_con[5], in ddr_phy_ctl_reset()
128 clrbits_le32(&publ->acdllcr, ACDLLCR_DLLSRST); in phy_pctrl_reset()
130 clrbits_le32(&publ->datx8[i].dxdllcr, DXDLLCR_DLLSRST); in phy_pctrl_reset()
133 setbits_le32(&publ->acdllcr, ACDLLCR_DLLSRST); in phy_pctrl_reset()
135 setbits_le32(&publ->datx8[i].dxdllcr, DXDLLCR_DLLSRST); in phy_pctrl_reset()
151 clrbits_le32(&publ->dllgcr, SBIAS_BYPASS); in phy_dll_bypass_set()
153 setbits_le32(&publ->dllgcr, SBIAS_BYPASS); in phy_dll_bypass_set()
154 setbits_le32(&publ->acdllcr, ACDLLCR_DLLDIS); in phy_dll_bypass_set()
156 setbits_le32(&publ->datx8[i].dxdllcr, in phy_dll_bypass_set()
159 setbits_le32(&publ->pir, PIR_DLLBYP); in phy_dll_bypass_set()
161 clrbits_le32(&publ->dllgcr, SBIAS_BYPASS); in phy_dll_bypass_set()
162 clrbits_le32(&publ->acdllcr, ACDLLCR_DLLDIS); in phy_dll_bypass_set()
164 clrbits_le32(&publ->datx8[i].dxdllcr, in phy_dll_bypass_set()
168 clrbits_le32(&publ->pir, PIR_DLLBYP); in phy_dll_bypass_set()
174 writel(DFI_INIT_START, &pctl->dfistcfg0); in dfi_cfg()
176 &pctl->dfistcfg1); in dfi_cfg()
177 writel(DFI_PARITY_INTR_EN | DFI_PARITY_EN, &pctl->dfistcfg2); in dfi_cfg()
179 &pctl->dfilpcfg0); in dfi_cfg()
181 writel(2 << TCTRL_DELAY_TIME_SHIFT, &pctl->dfitctrldelay); in dfi_cfg()
182 writel(1 << TPHY_WRDATA_TIME_SHIFT, &pctl->dfitphywrdata); in dfi_cfg()
183 writel(0xf << TPHY_RDLAT_TIME_SHIFT, &pctl->dfitphyrdlat); in dfi_cfg()
184 writel(2 << TDRAM_CLK_DIS_TIME_SHIFT, &pctl->dfitdramclkdis); in dfi_cfg()
185 writel(2 << TDRAM_CLK_EN_TIME_SHIFT, &pctl->dfitdramclken); in dfi_cfg()
186 writel(1, &pctl->dfitphyupdtype0); in dfi_cfg()
190 &pctl->dfiodtcfg); in dfi_cfg()
192 writel(7 << ODT_LEN_BL8_W_SHIFT, &pctl->dfiodtcfg1); in dfi_cfg()
193 /* phyupd and ctrlupd disabled */ in dfi_cfg()
194 writel(0, &pctl->dfiupdcfg); in dfi_cfg()
204 rk_clrsetreg(&grf->ddrc_con0, 1 << DDR_16BIT_EN_SHIFT, val); in ddr_set_enable()
214 rk_clrsetreg(&grf->soc_con2, mask, val); in ddr_set_ddr3_mode()
223 rk_clrsetreg(&grf->soc_con2, mask, val); in ddr_rank_2_row15en()
230 copy_to_reg(&pctl->togcnt1u, &sdram_params->pctl_timing.togcnt1u, in pctl_cfg()
231 sizeof(sdram_params->pctl_timing)); in pctl_cfg()
232 switch (sdram_params->base.dramtype) { in pctl_cfg()
234 if (sdram_params->phy_timing.mr[1] & DDR3_DLL_DISABLE) { in pctl_cfg()
235 writel(sdram_params->pctl_timing.tcl - 3, in pctl_cfg()
236 &pctl->dfitrddataen); in pctl_cfg()
238 writel(sdram_params->pctl_timing.tcl - 2, in pctl_cfg()
239 &pctl->dfitrddataen); in pctl_cfg()
241 writel(sdram_params->pctl_timing.tcwl - 1, in pctl_cfg()
242 &pctl->dfitphywrlat); in pctl_cfg()
244 DDR2_DDR3_BL_8 | (6 - 4) << TFAW_SHIFT | PD_EXIT_SLOW | in pctl_cfg()
246 &pctl->mcfg); in pctl_cfg()
252 setbits_le32(&pctl->scfg, 1); in pctl_cfg()
258 struct rk3288_ddr_publ *publ = chan->publ; in phy_cfg()
259 struct rk3188_msch *msch = chan->msch; in phy_cfg()
260 uint ddr_freq_mhz = sdram_params->base.ddr_freq / 1000000; in phy_cfg()
266 copy_to_reg(&publ->dtpr[0], &sdram_params->phy_timing.dtpr0, in phy_cfg()
267 sizeof(sdram_params->phy_timing)); in phy_cfg()
268 writel(sdram_params->base.noc_timing, &msch->ddrtiming); in phy_cfg()
269 writel(0x3f, &msch->readlatency); in phy_cfg()
272 8 << PRT_ITMSRST_SHIFT, &publ->ptr[0]); in phy_cfg()
275 &publ->ptr[1]); in phy_cfg()
278 &publ->ptr[2]); in phy_cfg()
280 switch (sdram_params->base.dramtype) { in phy_cfg()
282 clrbits_le32(&publ->pgcr, 0x1f); in phy_cfg()
283 clrsetbits_le32(&publ->dcr, DDRMD_MASK << DDRMD_SHIFT, in phy_cfg()
287 if (sdram_params->base.odt) { in phy_cfg()
290 setbits_le32(&publ->datx8[i].dxgcr, DQSRTT | DQRTT); in phy_cfg()
294 clrbits_le32(&publ->datx8[i].dxgcr, DQSRTT | DQRTT); in phy_cfg()
300 setbits_le32(&publ->pir, PIR_INIT | PIR_DLLSRST in phy_init()
303 while ((readl(&publ->pgsr) & in phy_init()
312 writel((START_CMD | (rank << 20) | arg | cmd), &pctl->mcmd); in send_command()
314 while (readl(&pctl->mcmd) & START_CMD) in send_command()
328 setbits_le32(&publ->pir, in memory_init()
333 while ((readl(&publ->pgsr) & (PGSR_IDONE | PGSR_DLDONE)) in memory_init()
344 state = readl(&pctl->stat) & PCTL_STAT_MSK; in move_to_config_state()
348 writel(WAKEUP_STATE, &pctl->sctl); in move_to_config_state()
349 while ((readl(&pctl->stat) & PCTL_STAT_MSK) in move_to_config_state()
353 while ((readl(&publ->pgsr) & PGSR_DLDONE) in move_to_config_state()
364 writel(CFG_STATE, &pctl->sctl); in move_to_config_state()
365 while ((readl(&pctl->stat) & PCTL_STAT_MSK) != CONFIG) in move_to_config_state()
379 struct rk3288_ddr_pctl *pctl = chan->pctl; in set_bandwidth_ratio()
380 struct rk3288_ddr_publ *publ = chan->publ; in set_bandwidth_ratio()
381 struct rk3188_msch *msch = chan->msch; in set_bandwidth_ratio()
384 setbits_le32(&pctl->ppcfg, 1); in set_bandwidth_ratio()
386 setbits_le32(&msch->ddrtiming, 1 << 31); in set_bandwidth_ratio()
388 clrbits_le32(&publ->datx8[2].dxgcr, 1); in set_bandwidth_ratio()
389 clrbits_le32(&publ->datx8[3].dxgcr, 1); in set_bandwidth_ratio()
391 setbits_le32(&publ->datx8[2].dxdllcr, DXDLLCR_DLLDIS); in set_bandwidth_ratio()
392 setbits_le32(&publ->datx8[3].dxdllcr, DXDLLCR_DLLDIS); in set_bandwidth_ratio()
394 clrbits_le32(&pctl->ppcfg, 1); in set_bandwidth_ratio()
396 clrbits_le32(&msch->ddrtiming, 1 << 31); in set_bandwidth_ratio()
398 setbits_le32(&publ->datx8[2].dxgcr, 1); in set_bandwidth_ratio()
399 setbits_le32(&publ->datx8[3].dxgcr, 1); in set_bandwidth_ratio()
402 clrbits_le32(&publ->datx8[2].dxdllcr, DXDLLCR_DLLDIS); in set_bandwidth_ratio()
403 clrbits_le32(&publ->datx8[3].dxdllcr, DXDLLCR_DLLDIS); in set_bandwidth_ratio()
405 clrbits_le32(&publ->datx8[2].dxdllcr, DXDLLCR_DLLSRST); in set_bandwidth_ratio()
406 clrbits_le32(&publ->datx8[3].dxdllcr, DXDLLCR_DLLSRST); in set_bandwidth_ratio()
408 setbits_le32(&publ->datx8[2].dxdllcr, DXDLLCR_DLLSRST); in set_bandwidth_ratio()
409 setbits_le32(&publ->datx8[3].dxdllcr, DXDLLCR_DLLSRST); in set_bandwidth_ratio()
411 setbits_le32(&pctl->dfistcfg0, 1 << 2); in set_bandwidth_ratio()
422 struct rk3288_ddr_publ *publ = chan->publ; in data_training()
423 struct rk3288_ddr_pctl *pctl = chan->pctl; in data_training()
426 writel(0, &pctl->trefi); in data_training()
428 if (sdram_params->base.dramtype != LPDDR3) in data_training()
429 setbits_le32(&publ->pgcr, 1 << PGCR_DQSCFG_SHIFT); in data_training()
430 rank = sdram_params->ch[channel].rank | 1; in data_training()
436 setbits_le32(&publ->pir, PIR_CLRSR); in data_training()
439 setbits_le32(&publ->pir, in data_training()
444 while ((readl(&publ->datx8[0].dxgsr[0]) & rank) in data_training()
447 while ((readl(&publ->datx8[1].dxgsr[0]) & rank) in data_training()
450 if (!(readl(&pctl->ppcfg) & 1)) { in data_training()
451 while ((readl(&publ->datx8[2].dxgsr[0]) in data_training()
454 while ((readl(&publ->datx8[3].dxgsr[0]) in data_training()
458 if (readl(&publ->pgsr) & in data_training()
460 ret = -1; in data_training()
468 if (sdram_params->base.dramtype != LPDDR3) in data_training()
469 clrbits_le32(&publ->pgcr, 1 << PGCR_DQSCFG_SHIFT); in data_training()
472 writel(sdram_params->pctl_timing.trefi, &pctl->trefi); in data_training()
479 struct rk3288_ddr_publ *publ = chan->publ; in move_to_access_state()
480 struct rk3288_ddr_pctl *pctl = chan->pctl; in move_to_access_state()
484 state = readl(&pctl->stat) & PCTL_STAT_MSK; in move_to_access_state()
488 if (((readl(&pctl->stat) >> LP_TRIG_SHIFT) & in move_to_access_state()
492 writel(WAKEUP_STATE, &pctl->sctl); in move_to_access_state()
493 while ((readl(&pctl->stat) & PCTL_STAT_MSK) != ACCESS) in move_to_access_state()
496 while ((readl(&publ->pgsr) & PGSR_DLDONE) in move_to_access_state()
501 writel(CFG_STATE, &pctl->sctl); in move_to_access_state()
502 while ((readl(&pctl->stat) & PCTL_STAT_MSK) != CONFIG) in move_to_access_state()
506 writel(GO_STATE, &pctl->sctl); in move_to_access_state()
507 while ((readl(&pctl->stat) & PCTL_STAT_MSK) == CONFIG) in move_to_access_state()
521 struct rk3288_ddr_publ *publ = chan->publ; in dram_cfg_rbc()
523 if (sdram_params->ch[chnum].bk == 3) in dram_cfg_rbc()
524 clrsetbits_le32(&publ->dcr, PDQ_MASK << PDQ_SHIFT, in dram_cfg_rbc()
527 clrbits_le32(&publ->dcr, PDQ_MASK << PDQ_SHIFT); in dram_cfg_rbc()
529 writel(sdram_params->base.ddrconfig, &chan->msch->ddrconf); in dram_cfg_rbc()
538 sys_reg |= sdram_params->base.dramtype << SYS_REG_DDRTYPE_SHIFT; in dram_all_config()
539 sys_reg |= (sdram_params->num_channels - 1) << SYS_REG_NUM_CH_SHIFT; in dram_all_config()
540 for (chan = 0; chan < sdram_params->num_channels; chan++) { in dram_all_config()
542 &sdram_params->ch[chan]; in dram_all_config()
544 sys_reg |= info->row_3_4 << SYS_REG_ROW_3_4_SHIFT(chan); in dram_all_config()
546 sys_reg |= (info->rank - 1) << SYS_REG_RANK_SHIFT(chan); in dram_all_config()
547 sys_reg |= (info->col - 9) << SYS_REG_COL_SHIFT(chan); in dram_all_config()
548 sys_reg |= info->bk == 3 ? 0 : 1 << SYS_REG_BK_SHIFT(chan); in dram_all_config()
549 sys_reg |= (info->cs0_row - 13) << SYS_REG_CS0_ROW_SHIFT(chan); in dram_all_config()
550 sys_reg |= (info->cs1_row - 13) << SYS_REG_CS1_ROW_SHIFT(chan); in dram_all_config()
551 sys_reg |= (2 >> info->bw) << SYS_REG_BW_SHIFT(chan); in dram_all_config()
552 sys_reg |= (2 >> info->dbw) << SYS_REG_DBW_SHIFT(chan); in dram_all_config()
554 dram_cfg_rbc(&dram->chan[chan], chan, sdram_params); in dram_all_config()
556 if (sdram_params->ch[0].rank == 2) in dram_all_config()
557 ddr_rank_2_row15en(dram->grf, 0); in dram_all_config()
559 ddr_rank_2_row15en(dram->grf, 1); in dram_all_config()
561 writel(sys_reg, &dram->pmu->sys_reg[2]); in dram_all_config()
569 const struct chan_info *chan = &dram->chan[channel]; in sdram_rank_bw_detect()
570 struct rk3288_ddr_publ *publ = chan->publ; in sdram_rank_bw_detect()
572 ddr_rank_2_row15en(dram->grf, 0); in sdram_rank_bw_detect()
576 reg = readl(&publ->datx8[0].dxgsr[0]); in sdram_rank_bw_detect()
580 return -EIO; in sdram_rank_bw_detect()
585 sdram_params->ch[channel].rank = 1; in sdram_rank_bw_detect()
586 clrsetbits_le32(&publ->pgcr, 0xF << 18, in sdram_rank_bw_detect()
587 sdram_params->ch[channel].rank << 18); in sdram_rank_bw_detect()
590 reg = readl(&publ->datx8[2].dxgsr[0]); in sdram_rank_bw_detect()
592 sdram_params->ch[channel].bw = 1; in sdram_rank_bw_detect()
594 sdram_params->ch[channel].bw, in sdram_rank_bw_detect()
595 dram->grf); in sdram_rank_bw_detect()
600 sdram_params->ch[channel].dbw = sdram_params->ch[channel].bw; in sdram_rank_bw_detect()
604 if (sdram_params->base.dramtype == LPDDR3) { in sdram_rank_bw_detect()
605 ddr_phy_ctl_reset(dram->cru, channel, 1); in sdram_rank_bw_detect()
607 ddr_phy_ctl_reset(dram->cru, channel, 0); in sdram_rank_bw_detect()
611 return -EIO; in sdram_rank_bw_detect()
630 const struct chan_info *chan = &dram->chan[channel]; in sdram_col_row_detect()
631 struct rk3288_ddr_pctl *pctl = chan->pctl; in sdram_col_row_detect()
632 struct rk3288_ddr_publ *publ = chan->publ; in sdram_col_row_detect()
636 for (col = 11; col >= 9; col--) { in sdram_col_row_detect()
639 (1 << (col + sdram_params->ch[channel].bw - 1)); in sdram_col_row_detect()
647 ret = -EINVAL; in sdram_col_row_detect()
650 sdram_params->ch[channel].col = col; in sdram_col_row_detect()
653 ddr_rank_2_row15en(dram->grf, 1); in sdram_col_row_detect()
655 writel(1, &chan->msch->ddrconf); in sdram_col_row_detect()
658 for (row = 16; row >= 13; row--) { in sdram_col_row_detect()
660 addr = CONFIG_SYS_SDRAM_BASE + (1 << (row + 15 - 1)); in sdram_col_row_detect()
668 ret = -EINVAL; in sdram_col_row_detect()
670 sdram_params->ch[channel].cs1_row = row; in sdram_col_row_detect()
671 sdram_params->ch[channel].row_3_4 = 0; in sdram_col_row_detect()
672 debug("chn %d col %d, row %d\n", channel, col, row); in sdram_col_row_detect()
673 sdram_params->ch[channel].cs0_row = row; in sdram_col_row_detect()
684 row = sdram_params->ch[0].cs0_row; in sdram_get_niu_config()
691 tmp = sdram_params->ch[0].col - 9; in sdram_get_niu_config()
692 tmp -= (sdram_params->ch[0].bw == 2) ? 0 : 1; in sdram_get_niu_config()
693 tmp |= ((row - 13) << 4); in sdram_get_niu_config()
700 ret = -EINVAL; in sdram_get_niu_config()
703 sdram_params->base.ddrconfig = i; in sdram_get_niu_config()
716 if ((sdram_params->base.dramtype == DDR3 && in sdram_init()
717 sdram_params->base.ddr_freq > 800000000)) { in sdram_init()
719 return -E2BIG; in sdram_init()
722 ret = clk_set_rate(&dram->ddr_clk, sdram_params->base.ddr_freq); in sdram_init()
729 const struct chan_info *chan = &dram->chan[channel]; in sdram_init()
730 struct rk3288_ddr_pctl *pctl = chan->pctl; in sdram_init()
731 struct rk3288_ddr_publ *publ = chan->publ; in sdram_init()
733 phy_pctrl_reset(dram->cru, publ, channel); in sdram_init()
734 phy_dll_bypass_set(publ, sdram_params->base.ddr_freq); in sdram_init()
736 dfi_cfg(pctl, sdram_params->base.dramtype); in sdram_init()
738 pctl_cfg(channel, pctl, sdram_params, dram->grf); in sdram_init()
744 writel(POWER_UP_START, &pctl->powctl); in sdram_init()
745 while (!(readl(&pctl->powstat) & POWER_UP_DONE)) in sdram_init()
748 memory_init(publ, sdram_params->base.dramtype); in sdram_init()
752 sdram_params->ch[channel].bw = 2; in sdram_init()
754 sdram_params->ch[channel].bw, dram->grf); in sdram_init()
761 sdram_params->ch[channel].rank = 2, in sdram_init()
762 clrsetbits_le32(&publ->pgcr, 0xF << 18, in sdram_init()
763 (sdram_params->ch[channel].rank | 1) << 18); in sdram_init()
769 writel(zqcr, &publ->zq1cr[0]); in sdram_init()
770 writel(zqcr, &publ->zq0cr[0]); in sdram_init()
772 /* Detect the rank and bit-width with data-training */ in sdram_init()
773 writel(1, &chan->msch->ddrconf); in sdram_init()
776 if (sdram_params->base.dramtype == LPDDR3) { in sdram_init()
778 writel(0, &pctl->mrrcfg0); in sdram_init()
782 writel(4, &chan->msch->ddrconf); in sdram_init()
785 sdram_params->ch[channel].bk = 3; in sdram_init()
819 /* rk3188 supports only one-channel */ in rk3188_dmc_ofdata_to_platdata()
820 params->num_channels = 1; in rk3188_dmc_ofdata_to_platdata()
821 ret = dev_read_u32_array(dev, "rockchip,pctl-timing", in rk3188_dmc_ofdata_to_platdata()
822 (u32 *)&params->pctl_timing, in rk3188_dmc_ofdata_to_platdata()
823 sizeof(params->pctl_timing) / sizeof(u32)); in rk3188_dmc_ofdata_to_platdata()
825 printf("%s: Cannot read rockchip,pctl-timing\n", __func__); in rk3188_dmc_ofdata_to_platdata()
826 return -EINVAL; in rk3188_dmc_ofdata_to_platdata()
828 ret = dev_read_u32_array(dev, "rockchip,phy-timing", in rk3188_dmc_ofdata_to_platdata()
829 (u32 *)&params->phy_timing, in rk3188_dmc_ofdata_to_platdata()
830 sizeof(params->phy_timing) / sizeof(u32)); in rk3188_dmc_ofdata_to_platdata()
832 printf("%s: Cannot read rockchip,phy-timing\n", __func__); in rk3188_dmc_ofdata_to_platdata()
833 return -EINVAL; in rk3188_dmc_ofdata_to_platdata()
835 ret = dev_read_u32_array(dev, "rockchip,sdram-params", in rk3188_dmc_ofdata_to_platdata()
836 (u32 *)&params->base, in rk3188_dmc_ofdata_to_platdata()
837 sizeof(params->base) / sizeof(u32)); in rk3188_dmc_ofdata_to_platdata()
839 printf("%s: Cannot read rockchip,sdram-params\n", __func__); in rk3188_dmc_ofdata_to_platdata()
840 return -EINVAL; in rk3188_dmc_ofdata_to_platdata()
842 ret = regmap_init_mem(dev_ofnode(dev), &params->map); in rk3188_dmc_ofdata_to_platdata()
855 struct dtd_rockchip_rk3188_dmc *of_plat = &plat->of_plat; in conv_of_platdata()
858 memcpy(&plat->pctl_timing, of_plat->rockchip_pctl_timing, in conv_of_platdata()
859 sizeof(plat->pctl_timing)); in conv_of_platdata()
860 memcpy(&plat->phy_timing, of_plat->rockchip_phy_timing, in conv_of_platdata()
861 sizeof(plat->phy_timing)); in conv_of_platdata()
862 memcpy(&plat->base, of_plat->rockchip_sdram_params, sizeof(plat->base)); in conv_of_platdata()
863 /* rk3188 supports dual-channel, set default channel num to 2 */ in conv_of_platdata()
864 plat->num_channels = 1; in conv_of_platdata()
865 ret = regmap_init_mem_platdata(dev, of_plat->reg, in conv_of_platdata()
866 ARRAY_SIZE(of_plat->reg) / 2, in conv_of_platdata()
867 &plat->map); in conv_of_platdata()
885 priv->pmu = syscon_get_first_range(ROCKCHIP_SYSCON_PMU); in rk3188_dmc_probe()
896 priv->chan[0].msch = regmap_get_range(map, 0); in rk3188_dmc_probe()
898 priv->grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF); in rk3188_dmc_probe()
900 priv->chan[0].pctl = regmap_get_range(plat->map, 0); in rk3188_dmc_probe()
901 priv->chan[0].publ = regmap_get_range(plat->map, 1); in rk3188_dmc_probe()
906 priv->ddr_clk.id = CLK_DDR; in rk3188_dmc_probe()
907 ret = clk_request(dev_clk, &priv->ddr_clk); in rk3188_dmc_probe()
911 priv->cru = rockchip_get_cru(); in rk3188_dmc_probe()
912 if (IS_ERR(priv->cru)) in rk3188_dmc_probe()
913 return PTR_ERR(priv->cru); in rk3188_dmc_probe()
918 priv->info.base = CONFIG_SYS_SDRAM_BASE; in rk3188_dmc_probe()
919 priv->info.size = rockchip_sdram_size( in rk3188_dmc_probe()
920 (phys_addr_t)&priv->pmu->sys_reg[2]); in rk3188_dmc_probe()
930 *info = priv->info; in rk3188_dmc_get_info()
940 { .compatible = "rockchip,rk3188-dmc" },