blob: 16566092bd846d18ab7d4e5f63b4dba77e3e0844 [file] [log] [blame]
Ying-Chun Liu (PaulLiu)728f1922022-02-08 09:22:38 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2019 NXP
4 * Copyright 2022 Linaro
5 */
6
7#include <common.h>
8#include <dwc3-uboot.h>
9#include <errno.h>
10#include <miiphy.h>
11#include <netdev.h>
12#include <spl.h>
13#include <usb.h>
14#include <asm/io.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>
25
26DECLARE_GLOBAL_DATA_PTR;
27
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)
30
31static 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),
34};
35
36static const iomux_v3_cfg_t wdog_pads[] = {
37 MX8MP_PAD_GPIO1_IO02__WDOG1_WDOG_B | MUX_PAD_CTRL(WDOG_PAD_CTRL),
38};
39
40#ifdef CONFIG_NAND_MXS
41static void setup_gpmi_nand(void)
42{
43 init_nand_clk();
44}
45#endif
46
47int board_early_init_f(void)
48{
49 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
50
51 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
52
53 set_wdog_reset(wdog);
54
55 imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads));
56
57 init_uart_clk(2);
58
59 return 0;
60}
61
62#ifdef CONFIG_OF_BOARD_SETUP
63int ft_board_setup(void *blob, struct bd_info *bd)
64{
65 return 0;
66}
67#endif
68
69#ifdef CONFIG_FEC_MXC
70#define FEC_RST_PAD IMX_GPIO_NR(4, 2)
71static const iomux_v3_cfg_t fec1_rst_pads[] = {
72 MX8MP_PAD_SAI1_RXD0__GPIO4_IO02 | MUX_PAD_CTRL(NO_PAD_CTRL),
73};
74
75static void setup_iomux_fec(void)
76{
77 imx_iomux_v3_setup_multiple_pads(fec1_rst_pads,
78 ARRAY_SIZE(fec1_rst_pads));
79
80 gpio_request(FEC_RST_PAD, "fec1_rst");
81 gpio_direction_output(FEC_RST_PAD, 0);
82 mdelay(15);
83 gpio_direction_output(FEC_RST_PAD, 1);
84 mdelay(100);
85}
86
87static int setup_fec(void)
88{
89 struct iomuxc_gpr_base_regs *gpr =
90 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
91
92 setup_iomux_fec();
93
94 /* Enable RGMII TX clk output */
95 setbits_le32(&gpr->gpr[1], BIT(22));
96
97 return 0;
98}
99#endif /* CONFIG_FEC_MXC */
100
101#ifdef CONFIG_DWC_ETH_QOS
102#define EQOS_RST_PAD IMX_GPIO_NR(4, 22)
103static const iomux_v3_cfg_t eqos_rst_pads[] = {
104 MX8MP_PAD_SAI2_RXC__GPIO4_IO22 | MUX_PAD_CTRL(NO_PAD_CTRL),
105};
106
107static void setup_iomux_eqos(void)
108{
109 imx_iomux_v3_setup_multiple_pads(eqos_rst_pads,
110 ARRAY_SIZE(eqos_rst_pads));
111
112 gpio_request(EQOS_RST_PAD, "eqos_rst");
113 gpio_direction_output(EQOS_RST_PAD, 0);
114 mdelay(15);
115 gpio_direction_output(EQOS_RST_PAD, 1);
116 mdelay(100);
117}
118
119static int setup_eqos(void)
120{
121 struct iomuxc_gpr_base_regs *gpr =
122 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
123
124 setup_iomux_eqos();
125
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));
130
131 return set_clk_eqos(ENET_125MHZ);
132}
133#endif /* CONFIG_DWC_ETH_QOS */
134
135int board_phy_config(struct phy_device *phydev)
136{
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);
141
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);
146
147 if (phydev->drv->config)
148 phydev->drv->config(phydev);
149 }
150
151 return 0;
152}
153
154#define DISPMIX 13
155#define MIPI 15
156
157#define WDOG_TRIG IMX_GPIO_NR(4, 20)
158
159static iomux_v3_cfg_t wdt_trig[] = {
160 MX8MP_PAD_SAI1_MCLK__GPIO4_IO20 | MUX_PAD_CTRL(NO_PAD_CTRL),
161};
162
163static void setup_iomux_wdt(void)
164{
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);
168}
169
170int board_init(void)
171{
172#ifdef CONFIG_FEC_MXC
173 setup_fec();
174#endif
175
176#ifdef CONFIG_DWC_ETH_QOS
177 /* clock, pin, gpr */
178 setup_eqos();
179#endif
180
181#ifdef CONFIG_NAND_MXS
182 setup_gpmi_nand();
183#endif
184
185 setup_iomux_wdt();
186
187 return 0;
188}
189
190int board_late_init(void)
191{
192 if (IS_ENABLED(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)) {
193 env_set("board_name", "RSB3720A1");
194 env_set("board_rev", "iMX8MP");
195 }
196
197 return 0;
198}
199
200#ifdef CONFIG_SPL_MMC_SUPPORT
201#define UBOOT_RAW_SECTOR_OFFSET 0x40
202unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc)
203{
204 u32 boot_dev = spl_boot_device();
205
206 switch (boot_dev) {
207 case BOOT_DEVICE_MMC2:
208 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR - UBOOT_RAW_SECTOR_OFFSET;
209 default:
210 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR;
211 }
212}
213#endif /* CONFIG_SPL_MMC_SUPPORT */