Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2019 NXP |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 7 | #include <env.h> |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 8 | #include <errno.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 9 | #include <init.h> |
Peng Fan | 4f0c97b | 2020-12-25 16:16:34 +0800 | [diff] [blame] | 10 | #include <miiphy.h> |
| 11 | #include <netdev.h> |
| 12 | #include <linux/delay.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 14 | #include <asm/mach-imx/iomux-v3.h> |
| 15 | #include <asm-generic/gpio.h> |
| 16 | #include <asm/arch/imx8mp_pins.h> |
Peng Fan | 4f0c97b | 2020-12-25 16:16:34 +0800 | [diff] [blame] | 17 | #include <asm/arch/clock.h> |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 18 | #include <asm/arch/sys_proto.h> |
| 19 | #include <asm/mach-imx/gpio.h> |
| 20 | |
| 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
| 23 | #define UART_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_FSEL1) |
| 24 | #define WDOG_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_ODE | PAD_CTL_PUE | PAD_CTL_PE) |
| 25 | |
| 26 | static iomux_v3_cfg_t const uart_pads[] = { |
| 27 | MX8MP_PAD_UART2_RXD__UART2_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 28 | MX8MP_PAD_UART2_TXD__UART2_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 29 | }; |
| 30 | |
| 31 | static iomux_v3_cfg_t const wdog_pads[] = { |
| 32 | MX8MP_PAD_GPIO1_IO02__WDOG1_WDOG_B | MUX_PAD_CTRL(WDOG_PAD_CTRL), |
| 33 | }; |
| 34 | |
| 35 | int board_early_init_f(void) |
| 36 | { |
| 37 | struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR; |
| 38 | |
| 39 | imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads)); |
| 40 | |
| 41 | set_wdog_reset(wdog); |
| 42 | |
| 43 | imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads)); |
| 44 | |
| 45 | return 0; |
| 46 | } |
| 47 | |
Peng Fan | 4f0c97b | 2020-12-25 16:16:34 +0800 | [diff] [blame] | 48 | static void setup_fec(void) |
| 49 | { |
| 50 | struct iomuxc_gpr_base_regs *gpr = |
| 51 | (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR; |
| 52 | |
| 53 | /* Enable RGMII TX clk output */ |
| 54 | setbits_le32(&gpr->gpr[1], BIT(22)); |
| 55 | } |
| 56 | |
Peng Fan | 4f0c97b | 2020-12-25 16:16:34 +0800 | [diff] [blame] | 57 | static int setup_eqos(void) |
| 58 | { |
| 59 | struct iomuxc_gpr_base_regs *gpr = |
| 60 | (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR; |
| 61 | |
Peng Fan | 4f0c97b | 2020-12-25 16:16:34 +0800 | [diff] [blame] | 62 | /* set INTF as RGMII, enable RGMII TXC clock */ |
| 63 | clrsetbits_le32(&gpr->gpr[1], |
| 64 | IOMUXC_GPR_GPR1_GPR_ENET_QOS_INTF_SEL_MASK, BIT(16)); |
| 65 | setbits_le32(&gpr->gpr[1], BIT(19) | BIT(21)); |
| 66 | |
| 67 | return set_clk_eqos(ENET_125MHZ); |
| 68 | } |
| 69 | |
| 70 | #if CONFIG_IS_ENABLED(NET) |
| 71 | int board_phy_config(struct phy_device *phydev) |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 72 | { |
Peng Fan | 4f0c97b | 2020-12-25 16:16:34 +0800 | [diff] [blame] | 73 | if (phydev->drv->config) |
| 74 | phydev->drv->config(phydev); |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 75 | return 0; |
| 76 | } |
Peng Fan | 4f0c97b | 2020-12-25 16:16:34 +0800 | [diff] [blame] | 77 | #endif |
| 78 | |
| 79 | int board_init(void) |
| 80 | { |
| 81 | int ret = 0; |
| 82 | |
| 83 | if (CONFIG_IS_ENABLED(FEC_MXC)) { |
| 84 | setup_fec(); |
Ye Li | 82da0f5 | 2021-08-16 18:44:29 +0800 | [diff] [blame] | 85 | } |
Peng Fan | 4f0c97b | 2020-12-25 16:16:34 +0800 | [diff] [blame] | 86 | |
Ye Li | 82da0f5 | 2021-08-16 18:44:29 +0800 | [diff] [blame] | 87 | if (CONFIG_IS_ENABLED(DWC_ETH_QOS)) { |
| 88 | ret = setup_eqos(); |
Peng Fan | 4f0c97b | 2020-12-25 16:16:34 +0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | return ret; |
| 92 | } |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 93 | |
| 94 | int board_late_init(void) |
| 95 | { |
| 96 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
| 97 | env_set("board_name", "EVK"); |
| 98 | env_set("board_rev", "iMX8MP"); |
| 99 | #endif |
| 100 | |
| 101 | return 0; |
| 102 | } |