blob: cc3a662415564a0604a65e3cd25f1e8985eafa49 [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
Ying-Chun Liu (PaulLiu)728f1922022-02-08 09:22:38 +08007#include <dwc3-uboot.h>
Sughosh Ganuccb36462022-04-15 11:29:34 +05308#include <efi.h>
9#include <efi_loader.h>
Ying-Chun Liu (PaulLiu)728f1922022-02-08 09:22:38 +080010#include <errno.h>
11#include <miiphy.h>
12#include <netdev.h>
13#include <spl.h>
14#include <usb.h>
15#include <asm/io.h>
16#include <asm/mach-imx/iomux-v3.h>
17#include <asm-generic/gpio.h>
18#include <asm/arch/imx8mp_pins.h>
19#include <asm/arch/sys_proto.h>
20#include <asm/mach-imx/gpio.h>
21#include <asm/mach-imx/mxc_i2c.h>
22#include <asm/arch/clock.h>
23#include <asm/mach-imx/dma.h>
24#include <linux/delay.h>
Sughosh Ganuccb36462022-04-15 11:29:34 +053025#include <linux/kernel.h>
Ying-Chun Liu (PaulLiu)728f1922022-02-08 09:22:38 +080026#include <power/pmic.h>
27
28DECLARE_GLOBAL_DATA_PTR;
29
Ying-Chun Liu (PaulLiu)728f1922022-02-08 09:22:38 +080030#ifdef CONFIG_NAND_MXS
31static void setup_gpmi_nand(void)
32{
33 init_nand_clk();
34}
35#endif
36
Simon Glassb8196212023-02-05 15:39:42 -070037#if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)
Sughosh Ganuccb36462022-04-15 11:29:34 +053038struct efi_fw_image fw_images[] = {
39#if defined(CONFIG_TARGET_IMX8MP_RSB3720A1_4G)
40 {
41 .image_type_id = IMX8MP_RSB3720A1_4G_FIT_IMAGE_GUID,
42 .fw_name = u"IMX8MP-RSB3720-FIT",
43 .image_index = 1,
44 },
45#elif defined(CONFIG_TARGET_IMX8MP_RSB3720A1_6G)
46 {
47 .image_type_id = IMX8MP_RSB3720A1_6G_FIT_IMAGE_GUID,
48 .fw_name = u"IMX8MP-RSB3720-FIT",
49 .image_index = 1,
50 },
51#endif
52};
53
54struct efi_capsule_update_info update_info = {
55 .dfu_string = "mmc 2=flash-bin raw 0 0x1B00 mmcpart 1",
Masahisa Kojima5d2438b2023-06-07 14:41:51 +090056 .num_images = ARRAY_SIZE(fw_images),
Sughosh Ganuccb36462022-04-15 11:29:34 +053057 .images = fw_images,
58};
59
Sughosh Ganuccb36462022-04-15 11:29:34 +053060#endif /* EFI_HAVE_CAPSULE_SUPPORT */
61
Ying-Chun Liu (PaulLiu)728f1922022-02-08 09:22:38 +080062int board_early_init_f(void)
63{
Ying-Chun Liu (PaulLiu)728f1922022-02-08 09:22:38 +080064 init_uart_clk(2);
65
66 return 0;
67}
68
69#ifdef CONFIG_OF_BOARD_SETUP
70int ft_board_setup(void *blob, struct bd_info *bd)
71{
72 return 0;
73}
74#endif
75
76#ifdef CONFIG_FEC_MXC
77#define FEC_RST_PAD IMX_GPIO_NR(4, 2)
78static const iomux_v3_cfg_t fec1_rst_pads[] = {
79 MX8MP_PAD_SAI1_RXD0__GPIO4_IO02 | MUX_PAD_CTRL(NO_PAD_CTRL),
80};
81
82static void setup_iomux_fec(void)
83{
84 imx_iomux_v3_setup_multiple_pads(fec1_rst_pads,
85 ARRAY_SIZE(fec1_rst_pads));
86
87 gpio_request(FEC_RST_PAD, "fec1_rst");
88 gpio_direction_output(FEC_RST_PAD, 0);
89 mdelay(15);
90 gpio_direction_output(FEC_RST_PAD, 1);
91 mdelay(100);
92}
93
94static int setup_fec(void)
95{
96 struct iomuxc_gpr_base_regs *gpr =
97 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
98
99 setup_iomux_fec();
100
101 /* Enable RGMII TX clk output */
102 setbits_le32(&gpr->gpr[1], BIT(22));
103
104 return 0;
105}
106#endif /* CONFIG_FEC_MXC */
107
108#ifdef CONFIG_DWC_ETH_QOS
109#define EQOS_RST_PAD IMX_GPIO_NR(4, 22)
110static const iomux_v3_cfg_t eqos_rst_pads[] = {
111 MX8MP_PAD_SAI2_RXC__GPIO4_IO22 | MUX_PAD_CTRL(NO_PAD_CTRL),
112};
113
Marek Vasut77126102023-03-06 15:53:53 +0100114static void setup_eqos(void)
Ying-Chun Liu (PaulLiu)728f1922022-02-08 09:22:38 +0800115{
116 imx_iomux_v3_setup_multiple_pads(eqos_rst_pads,
117 ARRAY_SIZE(eqos_rst_pads));
118
119 gpio_request(EQOS_RST_PAD, "eqos_rst");
120 gpio_direction_output(EQOS_RST_PAD, 0);
121 mdelay(15);
122 gpio_direction_output(EQOS_RST_PAD, 1);
123 mdelay(100);
124}
Ying-Chun Liu (PaulLiu)728f1922022-02-08 09:22:38 +0800125#endif /* CONFIG_DWC_ETH_QOS */
126
127int board_phy_config(struct phy_device *phydev)
128{
129 if (IS_ENABLED(CONFIG_FEC_MXC) || IS_ENABLED(CONFIG_DWC_ETH_QOS)) {
130 /* enable rgmii rxc skew and phy mode select to RGMII copper */
131 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x1f);
132 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x8);
133
134 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x00);
135 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x82ee);
136 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x05);
137 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100);
138
139 if (phydev->drv->config)
140 phydev->drv->config(phydev);
141 }
142
143 return 0;
144}
145
146#define DISPMIX 13
147#define MIPI 15
148
149#define WDOG_TRIG IMX_GPIO_NR(4, 20)
150
151static iomux_v3_cfg_t wdt_trig[] = {
152 MX8MP_PAD_SAI1_MCLK__GPIO4_IO20 | MUX_PAD_CTRL(NO_PAD_CTRL),
153};
154
155static void setup_iomux_wdt(void)
156{
157 imx_iomux_v3_setup_multiple_pads(wdt_trig, ARRAY_SIZE(wdt_trig));
158 gpio_request(WDOG_TRIG, "wdt_trig");
159 gpio_direction_output(WDOG_TRIG, 1);
160}
161
162int board_init(void)
163{
164#ifdef CONFIG_FEC_MXC
165 setup_fec();
166#endif
167
168#ifdef CONFIG_DWC_ETH_QOS
169 /* clock, pin, gpr */
170 setup_eqos();
171#endif
172
173#ifdef CONFIG_NAND_MXS
174 setup_gpmi_nand();
175#endif
176
177 setup_iomux_wdt();
178
179 return 0;
180}
181
182int board_late_init(void)
183{
184 if (IS_ENABLED(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)) {
185 env_set("board_name", "RSB3720A1");
186 env_set("board_rev", "iMX8MP");
187 }
188
189 return 0;
190}
191
Quentin Schulzc6685b22022-07-12 17:44:21 +0200192#ifdef CONFIG_SPL_MMC
Ying-Chun Liu (PaulLiu)728f1922022-02-08 09:22:38 +0800193#define UBOOT_RAW_SECTOR_OFFSET 0x40
Marek Vasutf9a921e2023-10-16 18:16:12 +0200194unsigned long board_spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
Tom Rinia3a142c2023-03-09 11:22:08 -0500195 unsigned long raw_sector)
Ying-Chun Liu (PaulLiu)728f1922022-02-08 09:22:38 +0800196{
197 u32 boot_dev = spl_boot_device();
198
199 switch (boot_dev) {
200 case BOOT_DEVICE_MMC2:
201 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR - UBOOT_RAW_SECTOR_OFFSET;
202 default:
203 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR;
204 }
205}
Quentin Schulzc6685b22022-07-12 17:44:21 +0200206#endif /* CONFIG_SPL_MMC */