blob: 9fdbeac82fd3f1cd02f121cb23cd275d18ad4b3b [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefano Babicfb8cac92018-01-03 16:11:56 +01002/*
3 * Copyright (C) 2016 Stefano Babic <sbabic@denx.de>
Stefano Babicfb8cac92018-01-03 16:11:56 +01004 */
5
Simon Glassc3dc39a2020-05-10 11:39:55 -06006#include <common.h>
Simon Glass09140112020-05-10 11:40:03 -06007#include <command.h>
Simon Glass691d7192020-05-10 11:40:02 -06008#include <init.h>
Simon Glass90526e92020-05-10 11:39:56 -06009#include <net.h>
Stefano Babicfb8cac92018-01-03 16:11:56 +010010#include <asm/arch/clock.h>
11#include <asm/arch/imx-regs.h>
12#include <asm/arch/iomux.h>
13#include <asm/arch/mx6-pins.h>
Simon Glassc05ed002020-05-10 11:40:11 -060014#include <linux/delay.h>
Stefano Babicfb8cac92018-01-03 16:11:56 +010015#include <linux/errno.h>
16#include <asm/gpio.h>
17#include <asm/mach-imx/iomux-v3.h>
18#include <asm/mach-imx/video.h>
19#include <mmc.h>
Yangbo Lue37ac712019-06-21 11:42:28 +080020#include <fsl_esdhc_imx.h>
Stefano Babicfb8cac92018-01-03 16:11:56 +010021#include <asm/arch/crm_regs.h>
22#include <asm/io.h>
23#include <asm/arch/sys_proto.h>
24#include <spl.h>
25#include <netdev.h>
26#include <miiphy.h>
27#include <micrel.h>
28
29#include <common.h>
30#include <malloc.h>
31#include <fuse.h>
32
33DECLARE_GLOBAL_DATA_PTR;
34
35#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
36 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
37 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
38
39#define USDHC_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
40 PAD_CTL_PUS_22K_UP | PAD_CTL_SPEED_LOW | \
41 PAD_CTL_DSE_80ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
42
43#define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
44 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
45 PAD_CTL_ODE | PAD_CTL_SRE_FAST)
46
47#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
48 PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
49
50static iomux_v3_cfg_t const uart1_pads[] = {
51 IOMUX_PADS(PAD_CSI0_DAT10__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
52 IOMUX_PADS(PAD_CSI0_DAT11__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
53};
54
55static iomux_v3_cfg_t const gpios_pads[] = {
56 IOMUX_PADS(PAD_EIM_A24__GPIO5_IO04 | MUX_PAD_CTRL(NO_PAD_CTRL)),
57};
58
59static iomux_v3_cfg_t const usdhc2_pads[] = {
60 IOMUX_PADS(PAD_SD2_CLK__SD2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
61 IOMUX_PADS(PAD_SD2_CMD__SD2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
62 IOMUX_PADS(PAD_SD2_DAT0__SD2_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
63 IOMUX_PADS(PAD_SD2_DAT1__SD2_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
64 IOMUX_PADS(PAD_SD2_DAT2__SD2_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
65 IOMUX_PADS(PAD_SD2_DAT3__SD2_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
66 IOMUX_PADS(PAD_NANDF_D0__GPIO2_IO00 | MUX_PAD_CTRL(NO_PAD_CTRL)),/* CD */
67};
68
69static iomux_v3_cfg_t const enet_pads[] = {
70 IOMUX_PADS(PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL)),
71 IOMUX_PADS(PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
72 IOMUX_PADS(PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
73 IOMUX_PADS(PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
74 IOMUX_PADS(PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
75 IOMUX_PADS(PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
76 IOMUX_PADS(PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
77 IOMUX_PADS(PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
78 IOMUX_PADS(PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
79 IOMUX_PADS(PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
80 IOMUX_PADS(PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
81 IOMUX_PADS(PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
82 IOMUX_PADS(PAD_ENET_REF_CLK__ENET_TX_CLK |
83 MUX_PAD_CTRL(ENET_PAD_CTRL)),
84 IOMUX_PADS(PAD_RGMII_TX_CTL__RGMII_TX_CTL |
85 MUX_PAD_CTRL(ENET_PAD_CTRL)),
86 IOMUX_PADS(PAD_RGMII_RX_CTL__RGMII_RX_CTL |
87 MUX_PAD_CTRL(ENET_PAD_CTRL)),
88 IOMUX_PADS(PAD_ENET_CRS_DV__GPIO1_IO25 | MUX_PAD_CTRL(NO_PAD_CTRL)),
89};
90
91iomux_v3_cfg_t const enet_pads1[] = {
92 /* pin 35 - 1 (PHY_AD2) on reset */
93 IOMUX_PADS(PAD_RGMII_RXC__GPIO6_IO30 | MUX_PAD_CTRL(NO_PAD_CTRL)),
94 /* pin 32 - 1 - (MODE0) all */
95 IOMUX_PADS(PAD_RGMII_RD0__GPIO6_IO25 | MUX_PAD_CTRL(NO_PAD_CTRL)),
96 /* pin 31 - 1 - (MODE1) all */
97 IOMUX_PADS(PAD_RGMII_RD1__GPIO6_IO27 | MUX_PAD_CTRL(NO_PAD_CTRL)),
98 /* pin 28 - 1 - (MODE2) all */
99 IOMUX_PADS(PAD_RGMII_RD2__GPIO6_IO28 | MUX_PAD_CTRL(NO_PAD_CTRL)),
100 /* pin 27 - 1 - (MODE3) all */
101 IOMUX_PADS(PAD_RGMII_RD3__GPIO6_IO29 | MUX_PAD_CTRL(NO_PAD_CTRL)),
102 /* pin 33 - 1 - (CLK125_EN) 125Mhz clockout enabled */
103 IOMUX_PADS(PAD_RGMII_RX_CTL__GPIO6_IO24 | MUX_PAD_CTRL(NO_PAD_CTRL)),
104 /* pin 42 PHY nRST */
105 IOMUX_PADS(PAD_ENET_CRS_DV__GPIO1_IO25 | MUX_PAD_CTRL(NO_PAD_CTRL)),
106};
107
108static int mx6_rgmii_rework(struct phy_device *phydev)
109{
110
111 /* min rx data delay */
112 ksz9021_phy_extended_write(phydev, MII_KSZ9021_EXT_RGMII_RX_DATA_SKEW,
113 0x0);
114 /* min tx data delay */
115 ksz9021_phy_extended_write(phydev, MII_KSZ9021_EXT_RGMII_TX_DATA_SKEW,
116 0x0);
117 /* max rx/tx clock delay, min rx/tx control */
118 ksz9021_phy_extended_write(phydev, MII_KSZ9021_EXT_RGMII_CLOCK_SKEW,
119 0xf0f0);
120
121 return 0;
122}
123
124int board_phy_config(struct phy_device *phydev)
125{
126 mx6_rgmii_rework(phydev);
127
128 if (phydev->drv->config)
129 return phydev->drv->config(phydev);
130
131 return 0;
132}
133
134#define ENET_NRST IMX_GPIO_NR(1, 25)
135
136void setup_iomux_enet(void)
137{
138 SETUP_IOMUX_PADS(enet_pads);
139
140}
141
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900142int board_eth_init(struct bd_info *bis)
Stefano Babicfb8cac92018-01-03 16:11:56 +0100143{
144 uint32_t base = IMX_FEC_BASE;
145 struct mii_dev *bus = NULL;
146 struct phy_device *phydev = NULL;
147 int ret;
148
149 setup_iomux_enet();
150
151 bus = fec_get_miibus(base, -1);
152 if (!bus)
153 return -EINVAL;
154 /* scan phy */
155 phydev = phy_find_by_mask(bus, (0xf << CONFIG_FEC_MXC_PHYADDR),
156 PHY_INTERFACE_MODE_RGMII);
157
158 if (!phydev) {
159 ret = -EINVAL;
160 goto free_bus;
161 }
162 ret = fec_probe(bis, -1, base, bus, phydev);
163 if (ret)
164 goto free_phydev;
165
166 return 0;
167
168free_phydev:
169 free(phydev);
170free_bus:
171 free(bus);
172 return ret;
173}
174
175int board_early_init_f(void)
176{
177 SETUP_IOMUX_PADS(uart1_pads);
178
179 return 0;
180}
181
182int board_init(void)
183{
184 /* Address of boot parameters */
185 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
186
187 /* Take in reset the ATMega processor */
188 SETUP_IOMUX_PADS(gpios_pads);
189 gpio_direction_output(IMX_GPIO_NR(5, 4), 0);
190
191 return 0;
192}
193
194int dram_init(void)
195{
196 gd->ram_size = imx_ddr_size();
197
198 return 0;
199}
200
201struct fsl_esdhc_cfg usdhc_cfg[1] = {
202 {USDHC2_BASE_ADDR, 0},
203};
204
205#define USDHC2_CD_GPIO IMX_GPIO_NR(2, 0)
206int board_mmc_getcd(struct mmc *mmc)
207{
208 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
209 int ret = 0;
210
211 if (cfg->esdhc_base == USDHC2_BASE_ADDR)
212 ret = 1;
213
214 return ret;
215}
216
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900217int board_mmc_init(struct bd_info *bis)
Stefano Babicfb8cac92018-01-03 16:11:56 +0100218{
219 int ret;
220
221 SETUP_IOMUX_PADS(usdhc2_pads);
222 gpio_direction_input(USDHC2_CD_GPIO);
223 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
224 usdhc_cfg[0].max_bus_width = 4;
225
226 ret = fsl_esdhc_initialize(bis, &usdhc_cfg[0]);
227 if (ret) {
228 printf("Warning: failed to initialize mmc dev \n");
229 return ret;
230 }
231
232 return 0;
233}
234
235#if defined(CONFIG_SPL_BUILD)
236#include <asm/arch/mx6-ddr.h>
237
238/*
239 * Driving strength:
240 * 0x30 == 40 Ohm
241 * 0x28 == 48 Ohm
242 */
243#define IMX6SDL_DRIVE_STRENGTH 0x230
244
245
246/* configure MX6SOLO/DUALLITE mmdc DDR io registers */
247struct mx6sdl_iomux_ddr_regs mx6sdl_ddr_ioregs = {
248 .dram_sdclk_0 = IMX6SDL_DRIVE_STRENGTH,
249 .dram_sdclk_1 = IMX6SDL_DRIVE_STRENGTH,
250 .dram_cas = IMX6SDL_DRIVE_STRENGTH,
251 .dram_ras = IMX6SDL_DRIVE_STRENGTH,
252 .dram_reset = IMX6SDL_DRIVE_STRENGTH,
253 .dram_sdcke0 = IMX6SDL_DRIVE_STRENGTH,
254 .dram_sdcke1 = IMX6SDL_DRIVE_STRENGTH,
255 .dram_sdba2 = 0x00000000,
256 .dram_sdodt0 = IMX6SDL_DRIVE_STRENGTH,
257 .dram_sdodt1 = IMX6SDL_DRIVE_STRENGTH,
258 .dram_sdqs0 = IMX6SDL_DRIVE_STRENGTH,
259 .dram_sdqs1 = IMX6SDL_DRIVE_STRENGTH,
260 .dram_sdqs2 = IMX6SDL_DRIVE_STRENGTH,
261 .dram_sdqs3 = IMX6SDL_DRIVE_STRENGTH,
262 .dram_sdqs4 = IMX6SDL_DRIVE_STRENGTH,
263 .dram_sdqs5 = IMX6SDL_DRIVE_STRENGTH,
264 .dram_sdqs6 = IMX6SDL_DRIVE_STRENGTH,
265 .dram_sdqs7 = IMX6SDL_DRIVE_STRENGTH,
266 .dram_dqm0 = IMX6SDL_DRIVE_STRENGTH,
267 .dram_dqm1 = IMX6SDL_DRIVE_STRENGTH,
268 .dram_dqm2 = IMX6SDL_DRIVE_STRENGTH,
269 .dram_dqm3 = IMX6SDL_DRIVE_STRENGTH,
270 .dram_dqm4 = IMX6SDL_DRIVE_STRENGTH,
271 .dram_dqm5 = IMX6SDL_DRIVE_STRENGTH,
272 .dram_dqm6 = IMX6SDL_DRIVE_STRENGTH,
273 .dram_dqm7 = IMX6SDL_DRIVE_STRENGTH,
274};
275
276/* configure MX6SOLO/DUALLITE mmdc GRP io registers */
277struct mx6sdl_iomux_grp_regs mx6sdl_grp_ioregs = {
278 .grp_ddr_type = 0x000c0000,
279 .grp_ddrmode_ctl = 0x00020000,
280 .grp_ddrpke = 0x00000000,
281 .grp_addds = IMX6SDL_DRIVE_STRENGTH,
282 .grp_ctlds = IMX6SDL_DRIVE_STRENGTH,
283 .grp_ddrmode = 0x00020000,
284 .grp_b0ds = IMX6SDL_DRIVE_STRENGTH,
285 .grp_b1ds = IMX6SDL_DRIVE_STRENGTH,
286 .grp_b2ds = IMX6SDL_DRIVE_STRENGTH,
287 .grp_b3ds = IMX6SDL_DRIVE_STRENGTH,
288 .grp_b4ds = IMX6SDL_DRIVE_STRENGTH,
289 .grp_b5ds = IMX6SDL_DRIVE_STRENGTH,
290 .grp_b6ds = IMX6SDL_DRIVE_STRENGTH,
291 .grp_b7ds = IMX6SDL_DRIVE_STRENGTH,
292};
293
294/* MT41K128M16JT-125 */
295static struct mx6_ddr3_cfg mt41k128m16jt_125 = {
296 /* quad = 1066, duallite = 800 */
297 .mem_speed = 1066,
298 .density = 2,
299 .width = 16,
300 .banks = 8,
301 .rowaddr = 14,
302 .coladdr = 10,
303 .pagesz = 2,
304 .trcd = 1375,
305 .trcmin = 4875,
306 .trasmin = 3500,
307 .SRT = 0,
308};
309
310static struct mx6_mmdc_calibration mx6dl_1g_mmdc_calib = {
311 .p0_mpwldectrl0 = 0x0043004E,
312 .p0_mpwldectrl1 = 0x003D003F,
313 .p1_mpwldectrl0 = 0x00230021,
314 .p1_mpwldectrl1 = 0x0028003E,
315 .p0_mpdgctrl0 = 0x42580250,
316 .p0_mpdgctrl1 = 0x0238023C,
317 .p1_mpdgctrl0 = 0x422C0238,
318 .p1_mpdgctrl1 = 0x02180228,
319 .p0_mprddlctl = 0x44464A46,
320 .p1_mprddlctl = 0x44464A42,
321 .p0_mpwrdlctl = 0x36343236,
322 .p1_mpwrdlctl = 0x36343230,
323};
324
325/* DDR 64bit 1GB */
326static struct mx6_ddr_sysinfo mem_qdl = {
327 .dsize = 2,
328 .cs1_mirror = 0,
329 /* config for full 4GB range so that get_mem_size() works */
330 .cs_density = 32,
331 .ncs = 1,
332 .bi_on = 1,
333 .rtt_nom = 1,
334 .rtt_wr = 1,
335 .ralat = 5,
336 .walat = 0,
337 .mif3_mode = 3,
338 .rst_to_cke = 0x23,
339 .sde_to_rst = 0x10,
340 .refsel = 1, /* Refresh cycles at 32KHz */
341 .refr = 7, /* 8 refresh commands per refresh cycle */
342};
343
344static void ccgr_init(void)
345{
346 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
347
348 /* set the default clock gate to save power */
349 writel(0x00C03F3F, &ccm->CCGR0);
350 writel(0x0030FC03, &ccm->CCGR1);
351 writel(0x0FFFC000, &ccm->CCGR2);
352 writel(0x3FF00000, &ccm->CCGR3);
353 writel(0x00FFF300, &ccm->CCGR4);
354 writel(0xFFFFFFFF, &ccm->CCGR5);
355 writel(0x000003FF, &ccm->CCGR6);
356}
357
358static void spl_dram_init(void)
359{
360 if (is_cpu_type(MXC_CPU_MX6DL)) {
361 mt41k128m16jt_125.mem_speed = 800;
362 mem_qdl.rtt_nom = 1;
363 mem_qdl.rtt_wr = 1;
364
365 mx6sdl_dram_iocfg(64, &mx6sdl_ddr_ioregs, &mx6sdl_grp_ioregs);
366 mx6_dram_cfg(&mem_qdl, &mx6dl_1g_mmdc_calib, &mt41k128m16jt_125);
367 } else {
368 printf("Wrong CPU for this board\n");
369 return;
370 }
371
372 udelay(100);
373
374#ifdef CONFIG_MX6_DDRCAL
375
376 /* Perform DDR DRAM calibration */
377 mmdc_do_write_level_calibration(&mem_qdl);
378 mmdc_do_dqs_calibration(&mem_qdl);
379#endif
380}
381
382static void check_bootcfg(void)
383{
384 u32 val5, val6;
385
386 fuse_sense(0, 5, &val5);
387 fuse_sense(0, 6, &val6);
388 /* Check if boot from MMC */
389 if (val6 & 0x10) {
390 puts("BT_FUSE_SEL already fused, will do nothing\n");
391 return;
392 }
393 fuse_prog(0, 5, 0x00000840);
394 /* BT_FUSE_SEL */
395 fuse_prog(0, 6, 0x00000010);
396
397 do_reset(NULL, 0, 0, NULL);
398}
399
400void board_init_f(ulong dummy)
401{
402 ccgr_init();
403
404 /* setup AIPS and disable watchdog */
405 arch_cpu_init();
406
407 gpr_init();
408
409 /* iomux */
410 board_early_init_f();
411
412 /* setup GP timer */
413 timer_init();
414
415 /* UART clocks enabled and gd valid - init serial console */
416 preloader_console_init();
417
418 /* DDR initialization */
419 spl_dram_init();
420
421 /* Set fuses for new boards and reboot if not set */
422 check_bootcfg();
423
424 /* Clear the BSS. */
425 memset(__bss_start, 0, __bss_end - __bss_start);
426
427 /* load/boot image from boot device */
428 board_init_r(NULL, 0);
429}
430#endif