blob: 4b3c59f7eef438634166411a0cdf09eff23673bb [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Sébastien Szymanskia7762e42017-03-07 14:33:25 +01002/*
Sébastien Szymanski1f29ce52018-04-17 17:29:31 +02003 * Copyright (C) 2018 Armadeus Systems
Sébastien Szymanskia7762e42017-03-07 14:33:25 +01004 */
5
Simon Glassa7b51302019-11-14 12:57:46 -07006#include <init.h>
Sébastien Szymanskia7762e42017-03-07 14:33:25 +01007#include <asm/arch/clock.h>
8#include <asm/arch/crm_regs.h>
9#include <asm/arch/imx-regs.h>
Sébastien Szymanskia7762e42017-03-07 14:33:25 +010010#include <asm/arch/sys_proto.h>
Sébastien Szymanskia7762e42017-03-07 14:33:25 +010011#include <asm/io.h>
12#include <common.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060013#include <env.h>
Sébastien Szymanskia7762e42017-03-07 14:33:25 +010014
15DECLARE_GLOBAL_DATA_PTR;
16
17#ifdef CONFIG_FEC_MXC
18#include <miiphy.h>
19
Sébastien Szymanskia7762e42017-03-07 14:33:25 +010020int board_phy_config(struct phy_device *phydev)
21{
22 phy_write(phydev, MDIO_DEVAD_NONE, 0x1f, 0x8190);
23
24 if (phydev->drv->config)
25 phydev->drv->config(phydev);
26
27 return 0;
28}
29
Sébastien Szymanski5444fdf2019-10-21 15:33:02 +020030static int setup_fec(void)
Sébastien Szymanskia7762e42017-03-07 14:33:25 +010031{
32 struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
Sébastien Szymanskia7762e42017-03-07 14:33:25 +010033
34 /* Use 50M anatop loopback REF_CLK1 for ENET1,
35 * clear gpr1[13], set gpr1[17] */
36 clrsetbits_le32(&iomuxc_regs->gpr[1], IOMUX_GPR1_FEC1_MASK,
37 IOMUX_GPR1_FEC1_CLOCK_MUX1_SEL_MASK);
38
Sébastien Szymanski5444fdf2019-10-21 15:33:02 +020039 return enable_fec_anatop_clock(0, ENET_50MHZ);
Sébastien Szymanskia7762e42017-03-07 14:33:25 +010040}
41#endif /* CONFIG_FEC_MXC */
42
43int board_init(void)
44{
45 /* Address of boot parameters */
46 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
47
Sébastien Szymanski5444fdf2019-10-21 15:33:02 +020048#ifdef CONFIG_FEC_MXC
49 setup_fec();
50#endif
51
Sébastien Szymanskia7762e42017-03-07 14:33:25 +010052 return 0;
53}
54
55int __weak opos6ul_board_late_init(void)
56{
57 return 0;
58}
59
60int board_late_init(void)
61{
62 struct src *psrc = (struct src *)SRC_BASE_ADDR;
63 unsigned reg = readl(&psrc->sbmr2);
64
65 /* In bootstrap don't use the env vars */
66 if (((reg & 0x3000000) >> 24) == 0x1) {
Simon Glass97385862019-08-01 09:47:00 -060067 env_set_default(NULL, 0);
Simon Glass6a38e412017-08-03 12:22:09 -060068 env_set("preboot", "");
Sébastien Szymanskia7762e42017-03-07 14:33:25 +010069 }
70
71 return opos6ul_board_late_init();
72}
73
Sébastien Szymanskia7762e42017-03-07 14:33:25 +010074int dram_init(void)
75{
76 gd->ram_size = imx_ddr_size();
77
78 return 0;
79}
80
81#ifdef CONFIG_SPL_BUILD
82#include <asm/arch/mx6-ddr.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090083#include <linux/libfdt.h>
Sébastien Szymanskia7762e42017-03-07 14:33:25 +010084#include <spl.h>
85
Sébastien Szymanskia7762e42017-03-07 14:33:25 +010086static struct mx6ul_iomux_grp_regs mx6_grp_ioregs = {
87 .grp_addds = 0x00000030,
88 .grp_ddrmode_ctl = 0x00020000,
89 .grp_b0ds = 0x00000030,
90 .grp_ctlds = 0x00000030,
91 .grp_b1ds = 0x00000030,
92 .grp_ddrpke = 0x00000000,
93 .grp_ddrmode = 0x00020000,
94 .grp_ddr_type = 0x000c0000,
95};
96
97static struct mx6ul_iomux_ddr_regs mx6_ddr_ioregs = {
98 .dram_dqm0 = 0x00000030,
99 .dram_dqm1 = 0x00000030,
100 .dram_ras = 0x00000030,
101 .dram_cas = 0x00000030,
102 .dram_odt0 = 0x00000030,
103 .dram_odt1 = 0x00000030,
104 .dram_sdba2 = 0x00000000,
105 .dram_sdclk_0 = 0x00000008,
106 .dram_sdqs0 = 0x00000038,
107 .dram_sdqs1 = 0x00000030,
108 .dram_reset = 0x00000030,
109};
110
111static struct mx6_mmdc_calibration mx6_mmcd_calib = {
112 .p0_mpwldectrl0 = 0x00070007,
113 .p0_mpdgctrl0 = 0x41490145,
114 .p0_mprddlctl = 0x40404546,
115 .p0_mpwrdlctl = 0x4040524D,
116};
117
118struct mx6_ddr_sysinfo ddr_sysinfo = {
119 .dsize = 0,
120 .cs_density = 20,
121 .ncs = 1,
122 .cs1_mirror = 0,
123 .rtt_wr = 2,
124 .rtt_nom = 1, /* RTT_Nom = RZQ/2 */
125 .walat = 1, /* Write additional latency */
126 .ralat = 5, /* Read additional latency */
127 .mif3_mode = 3, /* Command prediction working mode */
128 .bi_on = 1, /* Bank interleaving enabled */
129 .sde_to_rst = 0x10, /* 14 cycles, 200us (JEDEC default) */
130 .rst_to_cke = 0x23, /* 33 cycles, 500us (JEDEC default) */
131 .ddr_type = DDR_TYPE_DDR3,
Sébastien Szymanski943d8b52019-05-14 13:33:46 +0200132 .refsel = 1, /* Refresh cycles at 32KHz */
133 .refr = 7, /* 8 refreshes commands per refresh cycle */
Sébastien Szymanskia7762e42017-03-07 14:33:25 +0100134};
135
136static struct mx6_ddr3_cfg mem_ddr = {
137 .mem_speed = 800,
138 .density = 2,
139 .width = 16,
140 .banks = 8,
141 .rowaddr = 14,
142 .coladdr = 10,
143 .pagesz = 2,
144 .trcd = 1500,
145 .trcmin = 5250,
146 .trasmin = 3750,
147};
148
Sébastien Szymanski016f0052018-04-17 17:29:32 +0200149void board_boot_order(u32 *spl_boot_list)
150{
151 unsigned int bmode = readl(&src_base->sbmr2);
152
153 if (((bmode >> 24) & 0x03) == 0x01) /* Serial Downloader */
154 spl_boot_list[0] = BOOT_DEVICE_UART;
155 else
156 spl_boot_list[0] = spl_boot_device();
157}
158
Sébastien Szymanskia7762e42017-03-07 14:33:25 +0100159static void ccgr_init(void)
160{
161 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
162
163 writel(0xFFFFFFFF, &ccm->CCGR0);
164 writel(0xFFFFFFFF, &ccm->CCGR1);
165 writel(0xFFFFFFFF, &ccm->CCGR2);
166 writel(0xFFFFFFFF, &ccm->CCGR3);
167 writel(0xFFFFFFFF, &ccm->CCGR4);
168 writel(0xFFFFFFFF, &ccm->CCGR5);
169 writel(0xFFFFFFFF, &ccm->CCGR6);
170 writel(0xFFFFFFFF, &ccm->CCGR7);
171}
172
173static void spl_dram_init(void)
174{
175 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
176 struct fuse_bank *bank = &ocotp->bank[4];
177 struct fuse_bank4_regs *fuse =
178 (struct fuse_bank4_regs *)bank->fuse_regs;
179 int reg = readl(&fuse->gp1);
180
181 /* 512MB of RAM */
182 if (reg & 0x1) {
183 mem_ddr.density = 4;
184 mem_ddr.rowaddr = 15;
185 mem_ddr.trcd = 1375;
186 mem_ddr.trcmin = 4875;
187 mem_ddr.trasmin = 3500;
188 }
189
190 mx6ul_dram_iocfg(mem_ddr.width, &mx6_ddr_ioregs, &mx6_grp_ioregs);
191 mx6_dram_cfg(&ddr_sysinfo, &mx6_mmcd_calib, &mem_ddr);
192}
193
Sébastien Szymanski1f29ce52018-04-17 17:29:31 +0200194void spl_board_init(void)
195{
196 preloader_console_init();
197}
198
Sébastien Szymanskia7762e42017-03-07 14:33:25 +0100199void board_init_f(ulong dummy)
200{
201 ccgr_init();
202
203 /* setup AIPS and disable watchdog */
204 arch_cpu_init();
205
206 /* setup GP timer */
207 timer_init();
208
Sébastien Szymanskia7762e42017-03-07 14:33:25 +0100209 /* DDR initialization */
210 spl_dram_init();
211}
212#endif /* CONFIG_SPL_BUILD */