coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
emi.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <device/mmio.h>
4 #include <console/console.h>
5 #include <soc/addressmap.h>
6 #include <soc/dramc_common.h>
7 #include <soc/dramc_register.h>
8 #include <soc/dramc_pi_api.h>
9 #include <soc/dramc_soc.h>
10 #include <soc/mt6391.h>
11 #include <soc/pmic_wrap.h>
12 #include <soc/pll.h>
13 #include <soc/infracfg.h>
14 #include <soc/pericfg.h>
15 
16 struct emi_regs *emi_regs = (void *)EMI_BASE;
17 
18 static void dram_vcore_adjust(void)
19 {
20  /* options: Vcore_HV_LPPDR3/Vcore_NV_LPPDR3/Vcore_LV_LPPDR3 */
23 }
24 
25 static void dram_vmem_adjust(void)
26 {
27  /* options: Vmem_HV_LPPDR3/Vmem_NV_LPPDR3/Vmem_LV_LPPDR3 */
30 }
31 
32 static void emi_init(const struct mt8173_sdram_params *sdram_params)
33 {
34  /* EMI setting initialization */
35  write32(&emi_regs->emi_conf, sdram_params->emi_set.conf);
36  write32(&emi_regs->emi_conm, sdram_params->emi_set.conm_1);
37  write32(&emi_regs->emi_arbi, sdram_params->emi_set.arbi);
38  write32(&emi_regs->emi_arba, sdram_params->emi_set.arba);
39  write32(&emi_regs->emi_arbc, sdram_params->emi_set.arbc);
40  write32(&emi_regs->emi_arbd, sdram_params->emi_set.arbd);
41  write32(&emi_regs->emi_arbe, sdram_params->emi_set.arbe);
42  write32(&emi_regs->emi_arbf, sdram_params->emi_set.arbf);
43  write32(&emi_regs->emi_arbg, sdram_params->emi_set.arbg);
44  write32(&emi_regs->emi_arbj, sdram_params->emi_set.arbj);
45  write32(&emi_regs->emi_cona, sdram_params->emi_set.cona);
46  write32(&emi_regs->emi_testd, sdram_params->emi_set.testd);
47  write32(&emi_regs->emi_bmen, sdram_params->emi_set.bmen);
48  write32(&emi_regs->emi_conb, sdram_params->emi_set.conb);
49  write32(&emi_regs->emi_conc, sdram_params->emi_set.conc);
50  write32(&emi_regs->emi_cond, sdram_params->emi_set.cond);
51  write32(&emi_regs->emi_cone, sdram_params->emi_set.cone);
52  write32(&emi_regs->emi_cong, sdram_params->emi_set.cong);
53  write32(&emi_regs->emi_conh, sdram_params->emi_set.conh);
54  write32(&emi_regs->emi_slct, sdram_params->emi_set.slct_1);
55  write32(&emi_regs->emi_mdct, sdram_params->emi_set.mdct_1);
56  write32(&emi_regs->emi_arbk, sdram_params->emi_set.arbk);
57  write32(&emi_regs->emi_testc, sdram_params->emi_set.testc);
58  write32(&emi_regs->emi_mdct, sdram_params->emi_set.mdct_2);
59  write32(&emi_regs->emi_testb, sdram_params->emi_set.testb);
60  write32(&emi_regs->emi_slct, sdram_params->emi_set.slct_2);
61  write32(&emi_regs->emi_conm, sdram_params->emi_set.conm_2);
62  write32(&emi_regs->emi_test0, sdram_params->emi_set.test0);
63  write32(&emi_regs->emi_test1, sdram_params->emi_set.test1);
64 }
65 
66 static void do_calib(const struct mt8173_sdram_params *sdram_params)
67 {
68  u32 channel;
69 
72 
73  /* SPM_CONTROL_AFTERK */
75 
76  /* do dram calibration for channel A and B */
77  for (channel = 0; channel < CHANNEL_NUM; channel++) {
78  ca_training(channel, sdram_params);
79  write_leveling(channel, sdram_params);
80 
81  /* rx gating and datlat for single or dual rank */
82  if (is_dual_rank(channel, sdram_params)) {
85  } else {
86  rx_dqs_gating_cal(channel, 0, sdram_params);
87  rx_datlat_cal(channel, 0, sdram_params);
88  }
89 
90  clk_duty_cal(channel);
91  /* rx window perbit calibration */
92  perbit_window_cal(channel, RX_WIN);
93  /* tx window perbit calibration */
94  perbit_window_cal(channel, TX_WIN);
95 
98  }
99 
100  /* SPM_CONTROL_AFTERK */
102 }
103 
104 static void init_dram(const struct mt8173_sdram_params *sdram_params)
105 {
107 
110 
111  div2_phase_sync();
112 
115 }
116 
117 size_t sdram_size(void)
118 {
120  u32 bit_counter = 0;
121 
122  /* check if dual channel */
123  if (value & CONA_DUAL_CH_EN)
124  bit_counter++;
125 
126  /* check if 32bit, 32 = 2^5*/
127  if (value & CONA_32BIT_EN)
128  bit_counter += 5;
129  else
130  bit_counter += 4;
131 
132  /* check column address */
133  /* 00 is 9 bits, 01 is 10 bits, 10 is 11 bits */
134  bit_counter += ((value & COL_ADDR_BITS_MASK) >> COL_ADDR_BITS_SHIFT) +
135  9;
136 
137  /* check if row address */
138  /* 00 is 13 bits, 01 is 14 bits, 10 is 15bits, 11 is 16 bits */
139  bit_counter += ((value & ROW_ADDR_BITS_MASK) >> ROW_ADDR_BITS_SHIFT) +
140  13;
141 
142  /* check if dual rank */
143  if (value & CONA_DUAL_RANK_EN)
144  bit_counter++;
145 
146  /* add bank address bit, LPDDR3 is 8 banks =2^3 */
147  bit_counter += 3;
148 
149  /* transform bits to bytes */
150  return ((size_t)1 << (bit_counter - 3));
151 }
152 
153 static void init_4GB_mode(void)
154 {
155  if (sdram_size() == (size_t)4 * GiB) {
158  } else {
161  }
162 }
163 
165 {
166  /* voltage info */
169 
170  if (sdram_params->type != TYPE_LPDDR3) {
171  die("The DRAM type is not supported");
172  }
173 
176  init_4GB_mode();
177 }
pte_t value
Definition: mmu.c:91
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint32_t read32(const void *addr)
Definition: mmio.h:22
#define GiB
Definition: helpers.h:77
void __noreturn die(const char *fmt,...)
Definition: die.c:17
#define setbits32(addr, set)
Definition: mmio.h:21
#define clrbits32(addr, clear)
Definition: mmio.h:26
@ PMIC_RG_VCORE_CON10
Definition: mt6391.h:105
@ PMIC_RG_VDRM_CON10
Definition: mt6391.h:131
@ PMIC_RG_VCORE_CON9
Definition: mt6391.h:104
@ PMIC_RG_VDRM_CON9
Definition: mt6391.h:130
void transfer_to_reg_control(void)
void dramc_init(u32 channel, const struct mt8173_sdram_params *sdram_params)
void dramc_pre_init(u32 channel, const struct mt8173_sdram_params *sdram_params)
u8 is_dual_rank(u32 channel, const struct mt8173_sdram_params *sdram_params)
void div2_phase_sync(void)
void transfer_to_spm_control(void)
void dramc_runtime_config(u32 channel, const struct mt8173_sdram_params *sdram_params)
void sw_impedance_cal(u32 channel, const struct mt8173_sdram_params *sdram_params)
void ca_training(u32 channel, const struct mt8173_sdram_params *sdram_params)
void dual_rank_rx_dqs_gating_cal(u32 channel, const struct mt8173_sdram_params *sdram_params)
void rx_dqs_gating_cal(u32 channel, u8 rank, const struct mt8173_sdram_params *sdram_params)
void dual_rank_rx_datlat_cal(u32 channel, const struct mt8173_sdram_params *sdram_params)
void perbit_window_cal(u32 channel, u8 type)
void write_leveling(u32 channel, const struct mt8173_sdram_params *sdram_params)
void dramc_rankinctl_config(u32 channel, const struct mt8173_sdram_params *sdram_params)
u8 rx_datlat_cal(u32 channel, u8 rank, const struct mt8173_sdram_params *sdram_params)
void clk_duty_cal(u32 channel)
static void dram_vmem_adjust(void)
Definition: emi.c:25
size_t sdram_size(void)
Definition: emi.c:117
static void init_dram(const struct mt8173_sdram_params *sdram_params)
Definition: emi.c:104
static void dram_vcore_adjust(void)
Definition: emi.c:18
static void emi_init(const struct mt8173_sdram_params *sdram_params)
Definition: emi.c:32
static void do_calib(const struct mt8173_sdram_params *sdram_params)
Definition: emi.c:66
void mt_set_emi(const struct mt8173_sdram_params *sdram_params)
Definition: emi.c:164
static void init_4GB_mode(void)
Definition: emi.c:153
@ RX_WIN
Definition: dramc_pi_api.h:28
@ TX_WIN
Definition: dramc_pi_api.h:29
@ CHANNEL_A
Definition: dramc_soc.h:7
@ CHANNEL_NUM
Definition: dramc_soc.h:9
@ CHANNEL_B
Definition: dramc_soc.h:8
@ Vcore_NV_LPPDR3
Definition: emi.h:42
@ TYPE_LPDDR3
Definition: emi.h:15
@ COL_ADDR_BITS_SHIFT
Definition: emi.h:120
@ COL_ADDR_BITS_MASK
Definition: emi.h:121
@ ROW_ADDR_BITS_SHIFT
Definition: emi.h:122
@ CONA_32BIT_EN
Definition: emi.h:118
@ ROW_ADDR_BITS_MASK
Definition: emi.h:123
@ CONA_DUAL_CH_EN
Definition: emi.h:117
@ CONA_DUAL_RANK_EN
Definition: emi.h:119
@ Vmem_NV_LPDDR3
Definition: emi.h:27
@ DDR_4GB_SUPPORT_EN
Definition: infracfg.h:109
static struct mt8173_infracfg_regs *const mt8173_infracfg
Definition: infracfg.h:100
static struct mt8173_pericfg_regs *const mt8173_pericfg
Definition: pericfg.h:68
@ PERISYS_4G_SUPPORT
Definition: pericfg.h:84
static void pwrap_write_field(u16 reg, u16 val, u16 mask, u16 shift)
@ EMI_BASE
Definition: addressmap.h:28
uint32_t u32
Definition: stdint.h:51
uint32_t emi_testc
uint32_t emi_slct
uint32_t emi_cone
uint32_t emi_conc
uint32_t emi_conb
uint32_t emi_conf
uint32_t emi_testb
uint32_t emi_arbi
uint32_t emi_arbe
uint32_t emi_arbk
uint32_t emi_mdct
uint32_t emi_cond
uint32_t emi_conh
uint32_t emi_arba
uint32_t emi_test0
uint32_t emi_test1
uint32_t emi_cona
uint32_t emi_arbf
uint32_t emi_cong
uint32_t emi_arbg
uint32_t emi_arbc
uint32_t emi_arbj
uint32_t emi_testd
uint32_t emi_arbd
uint32_t emi_bmen
uint32_t emi_conm
Defines the SDRAM parameter structure.
Definition: emi.h:15