blob: 8971a827df3ade5bfaafbd510f4c8d3e9c50f069 [file] [log] [blame]
Peng Fanc47e09d2019-12-30 17:46:21 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2019 NXP
4 */
5
6#include <common.h>
Simon Glassed38aef2020-05-10 11:40:03 -06007#include <env.h>
Peng Fanc47e09d2019-12-30 17:46:21 +08008#include <errno.h>
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Peng Fan4f0c97b2020-12-25 16:16:34 +080010#include <miiphy.h>
11#include <netdev.h>
12#include <linux/delay.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Peng Fanc47e09d2019-12-30 17:46:21 +080014#include <asm/mach-imx/iomux-v3.h>
15#include <asm-generic/gpio.h>
16#include <asm/arch/imx8mp_pins.h>
Peng Fan4f0c97b2020-12-25 16:16:34 +080017#include <asm/arch/clock.h>
Peng Fanc47e09d2019-12-30 17:46:21 +080018#include <asm/arch/sys_proto.h>
19#include <asm/mach-imx/gpio.h>
20
21DECLARE_GLOBAL_DATA_PTR;
22
Peng Fan4f0c97b2020-12-25 16:16:34 +080023static void setup_fec(void)
24{
25 struct iomuxc_gpr_base_regs *gpr =
26 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
27
28 /* Enable RGMII TX clk output */
29 setbits_le32(&gpr->gpr[1], BIT(22));
30}
31
Peng Fan4f0c97b2020-12-25 16:16:34 +080032static int setup_eqos(void)
33{
34 struct iomuxc_gpr_base_regs *gpr =
35 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
36
Peng Fan4f0c97b2020-12-25 16:16:34 +080037 /* set INTF as RGMII, enable RGMII TXC clock */
38 clrsetbits_le32(&gpr->gpr[1],
39 IOMUXC_GPR_GPR1_GPR_ENET_QOS_INTF_SEL_MASK, BIT(16));
40 setbits_le32(&gpr->gpr[1], BIT(19) | BIT(21));
41
42 return set_clk_eqos(ENET_125MHZ);
43}
44
45#if CONFIG_IS_ENABLED(NET)
46int board_phy_config(struct phy_device *phydev)
Peng Fanc47e09d2019-12-30 17:46:21 +080047{
Peng Fan4f0c97b2020-12-25 16:16:34 +080048 if (phydev->drv->config)
49 phydev->drv->config(phydev);
Peng Fanc47e09d2019-12-30 17:46:21 +080050 return 0;
51}
Peng Fan4f0c97b2020-12-25 16:16:34 +080052#endif
53
54int board_init(void)
55{
56 int ret = 0;
57
58 if (CONFIG_IS_ENABLED(FEC_MXC)) {
59 setup_fec();
Ye Li82da0f52021-08-16 18:44:29 +080060 }
Peng Fan4f0c97b2020-12-25 16:16:34 +080061
Ye Li82da0f52021-08-16 18:44:29 +080062 if (CONFIG_IS_ENABLED(DWC_ETH_QOS)) {
63 ret = setup_eqos();
Peng Fan4f0c97b2020-12-25 16:16:34 +080064 }
65
66 return ret;
67}
Peng Fanc47e09d2019-12-30 17:46:21 +080068
69int board_late_init(void)
70{
71#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
72 env_set("board_name", "EVK");
73 env_set("board_rev", "iMX8MP");
74#endif
75
76 return 0;
77}