coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
dmc_init_ddr3.c
Go to the documentation of this file.
1 /* DDR3 mem setup file for EXYNOS5 based board */
2 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 
4 #include <device/mmio.h>
5 #include <delay.h>
6 #include <soc/clk.h>
7 #include <soc/dmc.h>
8 #include <soc/power.h>
9 #include <soc/setup.h>
10 
11 #define TIMEOUT 10000
12 
13 /* 'reset' field is currently ignored. */
14 
15 int ddr3_mem_ctrl_init(struct mem_timings *mem, int interleave_size, int reset)
16 {
17  u32 val, nLockR, nLockW_phy0, nLockW_phy1;
18  int i, chip;
19 
20  /* Enable PAUSE for DREX */
22 
23  /* Enable BYPASS mode */
25 
26  write32(&exynos_clock->clk_src_cdrex, MUX_BPLL_SEL_FOUTBPLL);
27  do {
28  val = read32(&exynos_clock->clk_mux_stat_cdrex);
29  val &= BPLL_SEL_MASK;
30  } while (val != FOUTBPLL);
31 
33 
34  /* Specify the DDR memory type as DDR3 */
39 
44 
45  /* Set Read Latency and Burst Length for PHY0 and PHY1 */
50 
55 
60 
61  /* Set Driver strength for CK, CKE, CS & CA to 0x7
62  * Set Driver strength for Data Slice 0~3 to 0x6
63  */
64  val = (0x7 << CA_CK_DRVR_DS_OFFSET) | (0x7 << CA_CKE_DRVR_DS_OFFSET) |
65  (0x7 << CA_CS_DRVR_DS_OFFSET) | (0x7 << CA_ADR_DRVR_DS_OFFSET);
66  val |= (0x7 << DA_3_DS_OFFSET) | (0x7 << DA_2_DS_OFFSET) |
67  (0x7 << DA_1_DS_OFFSET) | (0x7 << DA_0_DS_OFFSET);
70 
71  /* ZQ Calibration */
74 
77 
78  /* DQ Signal */
80  val |= mem->phy0_pulld_dqs;
83  val |= mem->phy1_pulld_dqs;
85 
89 
96 
97  do {
99  } while ((val & DFI_INIT_COMPLETE) != DFI_INIT_COMPLETE);
100  do {
102  } while ((val & DFI_INIT_COMPLETE) != DFI_INIT_COMPLETE);
103 
106 
109 
110  /* MEMBASECONFIG0 (CS0) */
113 
114  /* MEMBASECONFIG1 (CS1) */
115  if (mem->chips_per_channel == 2) {
118  }
119 
120  /* Memory Channel Interleaving Size
121  * Exynos5420 Channel interleaving = 128 bytes
122  */
123  /* MEMCONFIG0/1 */
128 
129  /* Precharge Configuration */
134 
135  /* TimingRow, TimingData, TimingPower and Timingref
136  * values as per Memory AC parameters
137  */
146 
147  if (reset) {
148  /* Send NOP, MRS and ZQINIT commands.
149  * Sending MRS command will reset the DRAM. We should not be
150  * resetting the DRAM after resume, this will lead to memory
151  * corruption as DRAM content is lost after DRAM reset.
152  */
155  } else {
156  u32 ret;
157 
158  /*
159  * During Suspend-Resume & S/W-Reset, as soon as PMU releases
160  * pad retention, CKE goes high. This causes memory contents
161  * not to be retained during DRAM initialization. Therefore,
162  * there is a new control register(0x100431e8[28]) which lets us
163  * release pad retention and retain the memory content until the
164  * initialization is complete.
165  */
168  do {
170  } while (ret != 0x1);
171 
172  /*
173  * CKE PAD retention disables DRAM self-refresh mode.
174  * Send auto refresh command for DRAM refresh.
175  */
176  for (i = 0; i < 128; i++) {
177  for (chip = 0; chip < mem->chips_to_configure; chip++) {
184  }
185  }
186  }
187 
188  if (mem->gate_leveling_enable) {
189 
192 
195 
197  val |= INIT_DESKEW_EN;
200 
204 
208 
210  nLockW_phy0 = (nLockR & CTRL_LOCK_COARSE_MASK) >> 2;
212  nLockR &= ~CTRL_DLL_ON;
213  nLockR |= nLockW_phy0;
215 
217  nLockW_phy1 = (nLockR & CTRL_LOCK_COARSE_MASK) >> 2;
219  nLockR &= ~CTRL_DLL_ON;
220  nLockR |= nLockW_phy1;
222 
223  val = (0x3 << DIRECT_CMD_BANK_SHIFT) | 0x4;
224  for (chip = 0; chip < mem->chips_to_configure; chip++) {
229  }
230 
233 
236 
240 
244 
246  i = TIMEOUT;
248  != RDLVL_COMPLETE_CHO) && (i > 0)) {
249  /*
250  * TODO(waihong): Comment on how long this take to
251  * timeout
252  */
253  udelay(1);
254  i--;
255  }
256  if (!i)
259 
261  i = TIMEOUT;
263  != RDLVL_COMPLETE_CHO) && (i > 0)) {
264  /*
265  * TODO(waihong): Comment on how long this take to
266  * timeout
267  */
268  udelay(1);
269  i--;
270  }
271  if (!i)
274 
277 
278  val = (0x3 << DIRECT_CMD_BANK_SHIFT);
279  for (chip = 0; chip < mem->chips_to_configure; chip++) {
284  }
285 
286  /* Common Settings for Leveling */
288  write32(&exynos_phy0_control->phy_con12, (val + nLockW_phy0));
289  write32(&exynos_phy1_control->phy_con12, (val + nLockW_phy1));
290 
293  }
294 
295  /* Send PALL command */
298 
301 
302  /*
303  * Set DMC Concontrol: Enable auto-refresh counter, provide
304  * read data fetch cycles and enable DREX auto set powerdown
305  * for input buffer of I/O in none read memory state.
306  */
315 
316  /* Enable Clock Gating Control for DMC
317  * this saves around 25 mw dmc power as compared to the power
318  * consumption without these bits enabled
319  */
322 
323  return 0;
324 }
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint32_t read32(const void *addr)
Definition: mmio.h:22
void update_reset_dll(struct exynos5_dmc *dmc, enum ddr_mode mode)
Definition: dmc_common.c:72
void dmc_config_mrs(struct mem_timings *mem, struct exynos5_dmc *dmc)
Definition: dmc_common.c:92
int dmc_config_zq(struct mem_timings *mem, struct exynos5_phy_control *phy0_ctrl, struct exynos5_phy_control *phy1_ctrl)
Definition: dmc_common.c:14
void dmc_config_prech(struct mem_timings *mem, struct exynos5_dmc *dmc)
Definition: dmc_common.c:139
int ddr3_mem_ctrl_init(struct mem_timings *mem, unsigned long mem_iv_size, int mem_reset)
Definition: dmc_init_ddr3.c:25
static struct exynos5_clock *const exynos_clock
Definition: clk.h:446
static struct exynos5_phy_control *const exynos_phy0_control
Definition: dmc.h:155
static struct exynos5_phy_control *const exynos_phy1_control
Definition: dmc.h:157
#define PHY_CON42_CTRL_RDLAT_SHIFT
Definition: dmc.h:242
#define PHY_CON0_CTRL_DDR_MODE_SHIFT
Definition: dmc.h:214
#define CONCONTROL_AREF_EN_SHIFT
Definition: dmc.h:202
#define PRECHCONFIG_TP_CNT_SHIFT
Definition: dmc.h:205
#define CONCONTROL_DFI_INIT_START_SHIFT
Definition: dmc.h:199
#define PHY_CON42_CTRL_BSTLEN_SHIFT
Definition: dmc.h:239
#define CONCONTROL_RD_FETCH_SHIFT
Definition: dmc.h:200
#define INIT_DESKEW_EN
Definition: setup.h:623
#define RDLVL_GATE_EN
Definition: setup.h:624
#define CTRL_SHGATE
Definition: setup.h:617
#define MEM_TERM_EN
Definition: setup.h:645
#define CTRL_GATEDURADJ_MASK
Definition: setup.h:620
#define CA_ADR_DRVR_DS_OFFSET
Definition: setup.h:656
#define CTRL_RDLVL_GATE_DISABLE
Definition: setup.h:634
#define ZQ_CLK_DIV_EN
Definition: setup.h:629
#define CA_CKE_DRVR_DS_OFFSET
Definition: setup.h:654
#define P0_CMD_EN
Definition: setup.h:615
#define CA_CS_DRVR_DS_OFFSET
Definition: setup.h:655
#define CTRL_RDLVL_GATE_ENABLE
Definition: setup.h:633
#define DIRECT_CMD_CHIP_SHIFT
Definition: setup.h:641
#define CA_CK_DRVR_DS_OFFSET
Definition: setup.h:653
#define PHY_CON2_RESET_VAL
Definition: setup.h:622
#define PHY_TERM_EN
Definition: setup.h:646
@ SETUP_ERR_RDLV_COMPLETE_TIMEOUT
Definition: setup.h:666
@ SETUP_ERR_ZQ_CALIBRATION_FAILURE
Definition: setup.h:667
#define RDLVL_COMPLETE_CHO
Definition: setup.h:118
#define PHY_CON0_RESET_VAL
Definition: setup.h:614
#define TIMEOUT
Definition: dmc_init_ddr3.c:11
#define PAD_RETENTION_DRAM_COREBLK_VAL
Definition: dmc.h:8
#define PHY_CON0_CTRL_DDR_MODE_MASK
Definition: dmc.h:26
static struct exynos5_tzasc *const exynos_tzasc1
Definition: dmc.h:263
static struct exynos5_tzasc *const exynos_tzasc0
Definition: dmc.h:261
static struct exynos5_dmc *const exynos_drex0
Definition: dmc.h:196
static struct exynos5_dmc *const exynos_drex1
Definition: dmc.h:197
#define ENABLE_BIT
Definition: setup.h:15
#define FOUTBPLL
Definition: setup.h:194
#define PHY_CON12_RESET_VAL
Definition: setup.h:638
#define DA_1_DS_OFFSET
Definition: setup.h:781
#define RDLVL_PASS_ADJ_OFFSET
Definition: setup.h:619
#define DIRECT_CMD_REFA
Definition: setup.h:696
#define DMC_CONCONTROL_IO_PD_CON(x)
Definition: setup.h:158
#define BYPASS_EN
Definition: setup.h:633
#define DLL_DESKEW_EN
Definition: setup.h:625
#define DA_3_DS_OFFSET
Definition: setup.h:779
#define DA_2_DS_OFFSET
Definition: setup.h:780
#define DA_0_DS_OFFSET
Definition: setup.h:782
#define T_WRDATA_EN_MASK
Definition: setup.h:721
#define MUX_BPLL_SEL_FOUTBPLL
Definition: setup.h:192
#define BPLL_SEL_MASK
Definition: setup.h:193
#define DIRECT_CMD_BANK_SHIFT
Definition: setup.h:695
#define CTRL_DLL_ON
Definition: setup.h:641
#define DFI_INIT_COMPLETE
Definition: setup.h:755
#define DMC_INTERNAL_CG
Definition: setup.h:765
#define T_WRDATA_EN_DDR3
Definition: setup.h:719
#define T_WRDATA_EN_OFFSET
Definition: setup.h:720
#define RDLVL_PASS_ADJ_VAL
Definition: setup.h:618
#define CTRL_LOCK_COARSE_MASK
Definition: setup.h:643
static struct tpm_chip chip
Definition: tis.c:17
#define setbits32(addr, set)
Definition: mmio.h:21
#define clrbits32(addr, clear)
Definition: mmio.h:26
#define DFI_INIT_START
Definition: sdram.c:231
static struct exynos5_power *const exynos_power
Definition: power.h:52
uint32_t u32
Definition: stdint.h:51
unsigned int bpll_con1
Definition: clk.h:417
unsigned int timingrow
Definition: dmc.h:22
uint32_t prechconfig0
Definition: dmc.h:68
unsigned int timingdata
Definition: dmc.h:23
unsigned int directcmd
Definition: dmc.h:15
unsigned int timingpower
Definition: dmc.h:24
unsigned int memcontrol
Definition: dmc.h:12
unsigned int phycontrol0
Definition: dmc.h:17
unsigned int concontrol
Definition: dmc.h:11
unsigned int phystatus
Definition: dmc.h:25
unsigned int rdlvl_config
Definition: dmc.h:66
unsigned int timingref
Definition: dmc.h:21
uint32_t cgcontrol
Definition: dmc.h:65
unsigned int phy_con14
Definition: dmc.h:122
unsigned int phy_con13
Definition: dmc.h:121
unsigned int phy_con2
Definition: dmc.h:110
unsigned int phy_con12
Definition: dmc.h:120
unsigned int phy_con0
Definition: dmc.h:108
unsigned int phy_con42
Definition: dmc.h:151
unsigned int phy_con1
Definition: dmc.h:109
unsigned int phy_con39
Definition: dmc.h:148
unsigned int phy_con26
Definition: dmc.h:135
unsigned int phy_con16
Definition: dmc.h:124
uint32_t padret_dram_cblk_opt
Definition: power.h:59
uint32_t padret_dram_status
Definition: power.h:55
uint32_t memconfig1
Definition: dmc.h:258
uint32_t memconfig0
Definition: dmc.h:257
uint32_t membaseconfig0
Definition: dmc.h:254
uint32_t membaseconfig1
Definition: dmc.h:255
unsigned int membaseconfig0
Definition: dmc.h:317
uint8_t dfi_init_start
Definition: dmc.h:305
unsigned int membaseconfig1
Definition: dmc.h:318
uint8_t gate_leveling_enable
Definition: dmc.h:329
unsigned int prechconfig_tp_cnt
Definition: dmc.h:319
unsigned int memcontrol
Definition: dmc.h:314
uint8_t phy0_pulld_dqs
Definition: dmc.h:289
uint8_t ctrl_rdlat
Definition: dmc.h:300
uint8_t ctrl_bstlen
Definition: dmc.h:301
unsigned int memconfig
Definition: dmc.h:315
uint8_t aref_en
Definition: dmc.h:306
uint8_t chips_per_channel
Definition: dmc.h:325
unsigned int timing_power
Definition: dmc.h:280
enum ddr_mode mem_type
Definition: dmc.h:248
unsigned int timing_data
Definition: dmc.h:279
uint8_t chips_to_configure
Definition: dmc.h:326
uint8_t phy1_pulld_dqs
Definition: dmc.h:290
unsigned int timing_ref
Definition: dmc.h:277
uint8_t rd_fetch
Definition: dmc.h:308
unsigned int concontrol
Definition: dmc.h:322
unsigned int timing_row
Definition: dmc.h:278
u8 val
Definition: sys.c:300
static void __noreturn reset(void)
void udelay(uint32_t us)
Definition: udelay.c:15