1 // SPDX-License-Identifier: GPL-2.0+
4 * Copyright 2022 Linaro
8 #include <dwc3-uboot.h>
15 #include <asm/mach-imx/iomux-v3.h>
16 #include <asm-generic/gpio.h>
17 #include <asm/arch/imx8mp_pins.h>
18 #include <asm/arch/sys_proto.h>
19 #include <asm/mach-imx/gpio.h>
20 #include <asm/mach-imx/mxc_i2c.h>
21 #include <asm/arch/clock.h>
22 #include <asm/mach-imx/dma.h>
23 #include <linux/delay.h>
24 #include <power/pmic.h>
26 DECLARE_GLOBAL_DATA_PTR;
28 #define UART_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_FSEL1)
29 #define WDOG_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_ODE | PAD_CTL_PUE | PAD_CTL_PE)
31 static const iomux_v3_cfg_t uart_pads[] = {
32 MX8MP_PAD_ECSPI1_SCLK__UART3_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
33 MX8MP_PAD_ECSPI1_MOSI__UART3_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
36 static const iomux_v3_cfg_t wdog_pads[] = {
37 MX8MP_PAD_GPIO1_IO02__WDOG1_WDOG_B | MUX_PAD_CTRL(WDOG_PAD_CTRL),
40 #ifdef CONFIG_NAND_MXS
41 static void setup_gpmi_nand(void)
47 int board_early_init_f(void)
49 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
51 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
55 imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads));
62 #ifdef CONFIG_OF_BOARD_SETUP
63 int ft_board_setup(void *blob, struct bd_info *bd)
70 #define FEC_RST_PAD IMX_GPIO_NR(4, 2)
71 static const iomux_v3_cfg_t fec1_rst_pads[] = {
72 MX8MP_PAD_SAI1_RXD0__GPIO4_IO02 | MUX_PAD_CTRL(NO_PAD_CTRL),
75 static void setup_iomux_fec(void)
77 imx_iomux_v3_setup_multiple_pads(fec1_rst_pads,
78 ARRAY_SIZE(fec1_rst_pads));
80 gpio_request(FEC_RST_PAD, "fec1_rst");
81 gpio_direction_output(FEC_RST_PAD, 0);
83 gpio_direction_output(FEC_RST_PAD, 1);
87 static int setup_fec(void)
89 struct iomuxc_gpr_base_regs *gpr =
90 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
94 /* Enable RGMII TX clk output */
95 setbits_le32(&gpr->gpr[1], BIT(22));
99 #endif /* CONFIG_FEC_MXC */
101 #ifdef CONFIG_DWC_ETH_QOS
102 #define EQOS_RST_PAD IMX_GPIO_NR(4, 22)
103 static const iomux_v3_cfg_t eqos_rst_pads[] = {
104 MX8MP_PAD_SAI2_RXC__GPIO4_IO22 | MUX_PAD_CTRL(NO_PAD_CTRL),
107 static void setup_iomux_eqos(void)
109 imx_iomux_v3_setup_multiple_pads(eqos_rst_pads,
110 ARRAY_SIZE(eqos_rst_pads));
112 gpio_request(EQOS_RST_PAD, "eqos_rst");
113 gpio_direction_output(EQOS_RST_PAD, 0);
115 gpio_direction_output(EQOS_RST_PAD, 1);
119 static int setup_eqos(void)
121 struct iomuxc_gpr_base_regs *gpr =
122 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
126 /* set INTF as RGMII, enable RGMII TXC clock */
127 clrsetbits_le32(&gpr->gpr[1],
128 IOMUXC_GPR_GPR1_GPR_ENET_QOS_INTF_SEL_MASK, BIT(16));
129 setbits_le32(&gpr->gpr[1], BIT(19) | BIT(21));
131 return set_clk_eqos(ENET_125MHZ);
133 #endif /* CONFIG_DWC_ETH_QOS */
135 int board_phy_config(struct phy_device *phydev)
137 if (IS_ENABLED(CONFIG_FEC_MXC) || IS_ENABLED(CONFIG_DWC_ETH_QOS)) {
138 /* enable rgmii rxc skew and phy mode select to RGMII copper */
139 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x1f);
140 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x8);
142 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x00);
143 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x82ee);
144 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x05);
145 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100);
147 if (phydev->drv->config)
148 phydev->drv->config(phydev);
157 #define WDOG_TRIG IMX_GPIO_NR(4, 20)
159 static iomux_v3_cfg_t wdt_trig[] = {
160 MX8MP_PAD_SAI1_MCLK__GPIO4_IO20 | MUX_PAD_CTRL(NO_PAD_CTRL),
163 static void setup_iomux_wdt(void)
165 imx_iomux_v3_setup_multiple_pads(wdt_trig, ARRAY_SIZE(wdt_trig));
166 gpio_request(WDOG_TRIG, "wdt_trig");
167 gpio_direction_output(WDOG_TRIG, 1);
172 #ifdef CONFIG_FEC_MXC
176 #ifdef CONFIG_DWC_ETH_QOS
177 /* clock, pin, gpr */
181 #ifdef CONFIG_NAND_MXS
190 int board_late_init(void)
192 if (IS_ENABLED(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)) {
193 env_set("board_name", "RSB3720A1");
194 env_set("board_rev", "iMX8MP");
200 #ifdef CONFIG_SPL_MMC_SUPPORT
201 #define UBOOT_RAW_SECTOR_OFFSET 0x40
202 unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc)
204 u32 boot_dev = spl_boot_device();
207 case BOOT_DEVICE_MMC2:
208 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR - UBOOT_RAW_SECTOR_OFFSET;
210 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR;
213 #endif /* CONFIG_SPL_MMC_SUPPORT */