1 /* SPDX-License-Identifier: GPL-2.0-only */
3 /* Mem setup common file for different types of DDR present on SMDK5250 boards.
6 #include <device/mmio.h>
10 #include <soc/setup.h>
12 #define ZQ_INIT_TIMEOUT 10000
14 int dmc_config_zq(struct mem_timings
*mem
,
15 struct exynos5_phy_control
*phy0_ctrl
,
16 struct exynos5_phy_control
*phy1_ctrl
)
18 unsigned long val
= 0;
23 * Select Driver Strength,
24 * long calibration for manual calibration
26 val
= PHY_CON16_RESET_VAL
;
27 val
|= mem
->zq_mode_dds
<< PHY_CON16_ZQ_MODE_DDS_SHIFT
;
28 val
|= mem
->zq_mode_term
<< PHY_CON16_ZQ_MODE_TERM_SHIFT
;
30 write32(&phy0_ctrl
->phy_con16
, val
);
31 write32(&phy1_ctrl
->phy_con16
, val
);
33 /* Disable termination */
34 if (mem
->zq_mode_noterm
)
35 val
|= PHY_CON16_ZQ_MODE_NOTERM_MASK
;
36 write32(&phy0_ctrl
->phy_con16
, val
);
37 write32(&phy1_ctrl
->phy_con16
, val
);
39 /* ZQ_MANUAL_START: Enable */
41 write32(&phy0_ctrl
->phy_con16
, val
);
42 write32(&phy1_ctrl
->phy_con16
, val
);
44 /* ZQ_MANUAL_START: Disable */
45 val
&= ~ZQ_MANUAL_STR
;
48 * Since we are manually calibrating the ZQ values,
49 * we are looping for the ZQ_init to complete.
52 while ((read32(&phy0_ctrl
->phy_con17
) & ZQ_DONE
) != ZQ_DONE
&& i
> 0) {
58 write32(&phy0_ctrl
->phy_con16
, val
);
61 while ((read32(&phy1_ctrl
->phy_con17
) & ZQ_DONE
) != ZQ_DONE
&& i
> 0) {
67 write32(&phy1_ctrl
->phy_con16
, val
);
72 void update_reset_dll(struct exynos5_dmc
*dmc
, enum ddr_mode mode
)
76 if (mode
== DDR_MODE_DDR3
) {
77 val
= MEM_TERM_EN
| PHY_TERM_EN
| DMC_CTRL_SHGATE
;
78 write32(&dmc
->phycontrol0
, val
);
81 /* Update DLL Information: Force DLL Resynchronization */
82 val
= read32(&dmc
->phycontrol0
);
84 write32(&dmc
->phycontrol0
, val
);
86 /* Reset Force DLL Resynchronization */
87 val
= read32(&dmc
->phycontrol0
);
89 write32(&dmc
->phycontrol0
, val
);
92 void dmc_config_mrs(struct mem_timings
*mem
, struct exynos5_dmc
*dmc
)
96 for (channel
= 0; channel
< mem
->dmc_channels
; channel
++) {
99 mask
= channel
<< DIRECT_CMD_CHANNEL_SHIFT
;
100 for (chip
= 0; chip
< mem
->chips_to_configure
; chip
++) {
103 mask
|= chip
<< DIRECT_CMD_CHIP_SHIFT
;
105 /* Sending NOP command */
106 write32(&dmc
->directcmd
, DIRECT_CMD_NOP
| mask
);
109 * TODO(alim.akhtar@samsung.com): Do we need these
110 * delays? This one and the next were not there for
115 /* Sending EMRS/MRS commands */
116 for (i
= 0; i
< MEM_TIMINGS_MSR_COUNT
; i
++) {
117 write32(&dmc
->directcmd
,
118 mem
->direct_cmd_msr
[i
] | mask
);
122 if (mem
->send_zq_init
) {
123 /* Sending ZQINIT command */
124 write32(&dmc
->directcmd
,
125 DIRECT_CMD_ZQINIT
| mask
);
127 * FIXME: This was originally sdelay(10000)
128 * in the imported u-boot code. That may have
129 * been meant to be sdelay(0x10000) since that
130 * was used elsewhere in this function. Either
131 * way seems to work, though.
139 void dmc_config_prech(struct mem_timings
*mem
, struct exynos5_dmc
*dmc
)
143 for (channel
= 0; channel
< mem
->dmc_channels
; channel
++) {
146 mask
= channel
<< DIRECT_CMD_CHANNEL_SHIFT
;
147 for (chip
= 0; chip
< mem
->chips_per_channel
; chip
++) {
148 mask
|= chip
<< DIRECT_CMD_CHIP_SHIFT
;
150 /* PALL (all banks precharge) CMD */
151 write32(&dmc
->directcmd
, DIRECT_CMD_PALL
| mask
);
157 void dmc_config_memory(struct mem_timings
*mem
, struct exynos5_dmc
*dmc
)
159 write32(&dmc
->memconfig0
, mem
->memconfig
);
160 write32(&dmc
->memconfig1
, mem
->memconfig
);
161 write32(&dmc
->membaseconfig0
, DMC_MEMBASECONFIG0_VAL
);
162 write32(&dmc
->membaseconfig1
, DMC_MEMBASECONFIG1_VAL
);