1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2022 NXP
4  */
5 
6 #include <common.h>
7 #include <env.h>
8 #include <init.h>
9 #include <miiphy.h>
10 #include <netdev.h>
11 #include <asm/global_data.h>
12 #include <asm/arch-imx9/ccm_regs.h>
13 #include <asm/arch/sys_proto.h>
14 #include <asm/arch-imx9/imx93_pins.h>
15 #include <asm/arch/clock.h>
16 #include <power/pmic.h>
17 #include <dm/device.h>
18 #include <dm/uclass.h>
19 #include <usb.h>
20 #include <dwc3-uboot.h>
21 
22 DECLARE_GLOBAL_DATA_PTR;
23 
24 #define UART_PAD_CTRL	(PAD_CTL_DSE(6) | PAD_CTL_FSEL2)
25 #define WDOG_PAD_CTRL	(PAD_CTL_DSE(6) | PAD_CTL_ODE | PAD_CTL_PUE | PAD_CTL_PE)
26 
27 static iomux_v3_cfg_t const uart_pads[] = {
28 	MX93_PAD_UART1_RXD__LPUART1_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
29 	MX93_PAD_UART1_TXD__LPUART1_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
30 };
31 
board_early_init_f(void)32 int board_early_init_f(void)
33 {
34 	imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads));
35 
36 	init_uart_clk(LPUART1_CLK_ROOT);
37 
38 	return 0;
39 }
40 
setup_fec(void)41 static int setup_fec(void)
42 {
43 	return set_clk_enet(ENET_125MHZ);
44 }
45 
board_phy_config(struct phy_device * phydev)46 int board_phy_config(struct phy_device *phydev)
47 {
48 	if (phydev->drv->config)
49 		phydev->drv->config(phydev);
50 
51 	return 0;
52 }
53 
setup_eqos(void)54 static int setup_eqos(void)
55 {
56 	struct blk_ctrl_wakeupmix_regs *bctrl =
57 		(struct blk_ctrl_wakeupmix_regs *)BLK_CTRL_WAKEUPMIX_BASE_ADDR;
58 
59 	/* set INTF as RGMII, enable RGMII TXC clock */
60 	clrsetbits_le32(&bctrl->eqos_gpr,
61 			BCTRL_GPR_ENET_QOS_INTF_MODE_MASK,
62 			BCTRL_GPR_ENET_QOS_INTF_SEL_RGMII | BCTRL_GPR_ENET_QOS_CLK_GEN_EN);
63 
64 	return set_clk_eqos(ENET_125MHZ);
65 }
66 
board_init(void)67 int board_init(void)
68 {
69 	if (IS_ENABLED(CONFIG_FEC_MXC))
70 		setup_fec();
71 
72 	if (IS_ENABLED(CONFIG_DWC_ETH_QOS))
73 		setup_eqos();
74 
75 	return 0;
76 }
77 
board_late_init(void)78 int board_late_init(void)
79 {
80 #ifdef CONFIG_ENV_IS_IN_MMC
81 	board_late_mmc_env_init();
82 #endif
83 
84 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
85 	env_set("board_name", "11X11_EVK");
86 	env_set("board_rev", "iMX93");
87 #endif
88 	return 0;
89 }
90