xref: /openbmc/u-boot/board/freescale/imx8mq_evk/imx8mq_evk.c (revision 522e035441ca04d99de2fc13b614ad896691e9c9)
1*86ac7a9aSPeng Fan // SPDX-License-Identifier: GPL-2.0+
2*86ac7a9aSPeng Fan /*
3*86ac7a9aSPeng Fan  * Copyright 2018 NXP
4*86ac7a9aSPeng Fan  */
5*86ac7a9aSPeng Fan 
6*86ac7a9aSPeng Fan #include <common.h>
7*86ac7a9aSPeng Fan #include <malloc.h>
8*86ac7a9aSPeng Fan #include <errno.h>
9*86ac7a9aSPeng Fan #include <asm/io.h>
10*86ac7a9aSPeng Fan #include <miiphy.h>
11*86ac7a9aSPeng Fan #include <netdev.h>
12*86ac7a9aSPeng Fan #include <asm/mach-imx/iomux-v3.h>
13*86ac7a9aSPeng Fan #include <asm-generic/gpio.h>
14*86ac7a9aSPeng Fan #include <fsl_esdhc.h>
15*86ac7a9aSPeng Fan #include <mmc.h>
16*86ac7a9aSPeng Fan #include <asm/arch/imx8mq_pins.h>
17*86ac7a9aSPeng Fan #include <asm/arch/sys_proto.h>
18*86ac7a9aSPeng Fan #include <asm/mach-imx/gpio.h>
19*86ac7a9aSPeng Fan #include <asm/mach-imx/mxc_i2c.h>
20*86ac7a9aSPeng Fan #include <asm/arch/clock.h>
21*86ac7a9aSPeng Fan #include <spl.h>
22*86ac7a9aSPeng Fan #include <power/pmic.h>
23*86ac7a9aSPeng Fan #include <power/pfuze100_pmic.h>
24*86ac7a9aSPeng Fan #include "../common/pfuze.h"
25*86ac7a9aSPeng Fan 
26*86ac7a9aSPeng Fan DECLARE_GLOBAL_DATA_PTR;
27*86ac7a9aSPeng Fan 
28*86ac7a9aSPeng Fan #define UART_PAD_CTRL	(PAD_CTL_DSE6 | PAD_CTL_FSEL1)
29*86ac7a9aSPeng Fan 
30*86ac7a9aSPeng Fan #define WDOG_PAD_CTRL	(PAD_CTL_DSE6 | PAD_CTL_HYS | PAD_CTL_PUE)
31*86ac7a9aSPeng Fan 
32*86ac7a9aSPeng Fan static iomux_v3_cfg_t const wdog_pads[] = {
33*86ac7a9aSPeng Fan 	IMX8MQ_PAD_GPIO1_IO02__WDOG1_WDOG_B | MUX_PAD_CTRL(WDOG_PAD_CTRL),
34*86ac7a9aSPeng Fan };
35*86ac7a9aSPeng Fan 
36*86ac7a9aSPeng Fan static iomux_v3_cfg_t const uart_pads[] = {
37*86ac7a9aSPeng Fan 	IMX8MQ_PAD_UART1_RXD__UART1_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
38*86ac7a9aSPeng Fan 	IMX8MQ_PAD_UART1_TXD__UART1_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
39*86ac7a9aSPeng Fan };
40*86ac7a9aSPeng Fan 
board_early_init_f(void)41*86ac7a9aSPeng Fan int board_early_init_f(void)
42*86ac7a9aSPeng Fan {
43*86ac7a9aSPeng Fan 	struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
44*86ac7a9aSPeng Fan 
45*86ac7a9aSPeng Fan 	imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
46*86ac7a9aSPeng Fan 	set_wdog_reset(wdog);
47*86ac7a9aSPeng Fan 
48*86ac7a9aSPeng Fan 	imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads));
49*86ac7a9aSPeng Fan 
50*86ac7a9aSPeng Fan 	return 0;
51*86ac7a9aSPeng Fan }
52*86ac7a9aSPeng Fan 
dram_init(void)53*86ac7a9aSPeng Fan int dram_init(void)
54*86ac7a9aSPeng Fan {
55*86ac7a9aSPeng Fan 	/* rom_pointer[1] contains the size of TEE occupies */
56*86ac7a9aSPeng Fan 	if (rom_pointer[1])
57*86ac7a9aSPeng Fan 		gd->ram_size = PHYS_SDRAM_SIZE - rom_pointer[1];
58*86ac7a9aSPeng Fan 	else
59*86ac7a9aSPeng Fan 		gd->ram_size = PHYS_SDRAM_SIZE;
60*86ac7a9aSPeng Fan 
61*86ac7a9aSPeng Fan 	return 0;
62*86ac7a9aSPeng Fan }
63*86ac7a9aSPeng Fan 
64*86ac7a9aSPeng Fan #ifdef CONFIG_FEC_MXC
65*86ac7a9aSPeng Fan #define FEC_RST_PAD IMX_GPIO_NR(1, 9)
66*86ac7a9aSPeng Fan static iomux_v3_cfg_t const fec1_rst_pads[] = {
67*86ac7a9aSPeng Fan 	IMX8MQ_PAD_GPIO1_IO09__GPIO1_IO9 | MUX_PAD_CTRL(NO_PAD_CTRL),
68*86ac7a9aSPeng Fan };
69*86ac7a9aSPeng Fan 
setup_iomux_fec(void)70*86ac7a9aSPeng Fan static void setup_iomux_fec(void)
71*86ac7a9aSPeng Fan {
72*86ac7a9aSPeng Fan 	imx_iomux_v3_setup_multiple_pads(fec1_rst_pads,
73*86ac7a9aSPeng Fan 					 ARRAY_SIZE(fec1_rst_pads));
74*86ac7a9aSPeng Fan 
75*86ac7a9aSPeng Fan 	gpio_request(IMX_GPIO_NR(1, 9), "fec1_rst");
76*86ac7a9aSPeng Fan 	gpio_direction_output(IMX_GPIO_NR(1, 9), 0);
77*86ac7a9aSPeng Fan 	udelay(500);
78*86ac7a9aSPeng Fan 	gpio_direction_output(IMX_GPIO_NR(1, 9), 1);
79*86ac7a9aSPeng Fan }
80*86ac7a9aSPeng Fan 
setup_fec(void)81*86ac7a9aSPeng Fan static int setup_fec(void)
82*86ac7a9aSPeng Fan {
83*86ac7a9aSPeng Fan 	struct iomuxc_gpr_base_regs *gpr =
84*86ac7a9aSPeng Fan 		(struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
85*86ac7a9aSPeng Fan 
86*86ac7a9aSPeng Fan 	setup_iomux_fec();
87*86ac7a9aSPeng Fan 
88*86ac7a9aSPeng Fan 	/* Use 125M anatop REF_CLK1 for ENET1, not from external */
89*86ac7a9aSPeng Fan 	clrsetbits_le32(&gpr->gpr[1], BIT(13) | BIT(17), 0);
90*86ac7a9aSPeng Fan 	return set_clk_enet(ENET_125MHZ);
91*86ac7a9aSPeng Fan }
92*86ac7a9aSPeng Fan 
board_phy_config(struct phy_device * phydev)93*86ac7a9aSPeng Fan int board_phy_config(struct phy_device *phydev)
94*86ac7a9aSPeng Fan {
95*86ac7a9aSPeng Fan 	/* enable rgmii rxc skew and phy mode select to RGMII copper */
96*86ac7a9aSPeng Fan 	phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x1f);
97*86ac7a9aSPeng Fan 	phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x8);
98*86ac7a9aSPeng Fan 
99*86ac7a9aSPeng Fan 	phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x05);
100*86ac7a9aSPeng Fan 	phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100);
101*86ac7a9aSPeng Fan 
102*86ac7a9aSPeng Fan 	if (phydev->drv->config)
103*86ac7a9aSPeng Fan 		phydev->drv->config(phydev);
104*86ac7a9aSPeng Fan 	return 0;
105*86ac7a9aSPeng Fan }
106*86ac7a9aSPeng Fan #endif
107*86ac7a9aSPeng Fan 
board_init(void)108*86ac7a9aSPeng Fan int board_init(void)
109*86ac7a9aSPeng Fan {
110*86ac7a9aSPeng Fan #ifdef CONFIG_FEC_MXC
111*86ac7a9aSPeng Fan 	setup_fec();
112*86ac7a9aSPeng Fan #endif
113*86ac7a9aSPeng Fan 
114*86ac7a9aSPeng Fan 	return 0;
115*86ac7a9aSPeng Fan }
116*86ac7a9aSPeng Fan 
board_mmc_get_env_dev(int devno)117*86ac7a9aSPeng Fan int board_mmc_get_env_dev(int devno)
118*86ac7a9aSPeng Fan {
119*86ac7a9aSPeng Fan 	return devno;
120*86ac7a9aSPeng Fan }
121*86ac7a9aSPeng Fan 
board_late_init(void)122*86ac7a9aSPeng Fan int board_late_init(void)
123*86ac7a9aSPeng Fan {
124*86ac7a9aSPeng Fan #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
125*86ac7a9aSPeng Fan 	env_set("board_name", "EVK");
126*86ac7a9aSPeng Fan 	env_set("board_rev", "iMX8MQ");
127*86ac7a9aSPeng Fan #endif
128*86ac7a9aSPeng Fan 
129*86ac7a9aSPeng Fan 	return 0;
130*86ac7a9aSPeng Fan }
131