blob: c9513ddbc6897e8f56e8cca04a2e413284a490ec [file] [log] [blame]
Fabio Estevamdb1aa292021-05-28 10:26:57 -03001// SPDX-License-Identifier: GPL-2.0+
2// Copyright (C) 2021 Fabio Estevam <festevam@denx.de>
3
4#include <init.h>
5#include <net.h>
6#include <asm/arch/clock.h>
7#include <asm/arch/imx-regs.h>
8#include <asm/arch/mx7-pins.h>
9#include <asm/arch/sys_proto.h>
10#include <asm/global_data.h>
11#include <asm/gpio.h>
12#include <asm/mach-imx/hab.h>
13#include <asm/mach-imx/iomux-v3.h>
14#include <asm/io.h>
Fabio Estevamdb1aa292021-05-28 10:26:57 -030015#include <env.h>
Eduard Strehlau5fad5252023-04-26 13:04:57 -030016#include <env_internal.h>
Fabio Estevamdb1aa292021-05-28 10:26:57 -030017#include <asm/arch/crm_regs.h>
18#include <asm/setup.h>
19#include <asm/bootm.h>
Eduard Strehlaub2b64562023-04-26 13:04:54 -030020#include <mmc.h>
Fabio Estevamdb1aa292021-05-28 10:26:57 -030021
22DECLARE_GLOBAL_DATA_PTR;
23
24#define UART_PAD_CTRL (PAD_CTL_DSE_3P3V_49OHM | PAD_CTL_PUS_PU100KOHM | \
25 PAD_CTL_HYS)
26
27int dram_init(void)
28{
29 gd->ram_size = PHYS_SDRAM_SIZE;
30
31 return 0;
32}
33
34static iomux_v3_cfg_t const wdog_pads[] = {
35 MX7D_PAD_GPIO1_IO00__WDOG1_WDOG_B | MUX_PAD_CTRL(NO_PAD_CTRL),
36};
37
38static iomux_v3_cfg_t const uart1_pads[] = {
39 MX7D_PAD_UART1_TX_DATA__UART1_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
40 MX7D_PAD_UART1_RX_DATA__UART1_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
41};
42
43static void setup_iomux_uart(void)
44{
45 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
46};
47
48static int setup_fec(void)
49{
50 struct iomuxc_gpr_base_regs *const iomuxc_gpr_regs =
51 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
52 int ret;
53
54 /* Use 125M anatop REF_CLK1 for ENET1, clear gpr1[13], gpr1[17]*/
55 clrsetbits_le32(&iomuxc_gpr_regs->gpr[1],
56 (IOMUXC_GPR_GPR1_GPR_ENET1_TX_CLK_SEL_MASK |
57 IOMUXC_GPR_GPR1_GPR_ENET1_CLK_DIR_MASK), 0);
58
59 ret = set_clk_enet(ENET_125MHZ);
60 if (ret)
61 return ret;
62
63 return 0;
64}
65
66int board_early_init_f(void)
67{
68 setup_iomux_uart();
69 setup_fec();
70 return 0;
71}
72
73int board_init(void)
74{
75 /* address of boot parameters */
76 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
77
78 return 0;
79}
80
81int board_late_init(void)
82{
83 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
Fabio Estevam4de69782023-04-26 13:04:58 -030084 unsigned char eth1addr[6];
Fabio Estevamdb1aa292021-05-28 10:26:57 -030085
86 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
87
88 set_wdog_reset(wdog);
89
90 /*
91 * Do not assert internal WDOG_RESET_B_DEB(controlled by bit 4),
92 * since we use PMIC_PWRON to reset the board.
93 */
94 clrsetbits_le16(&wdog->wcr, 0, 0x10);
95
Fabio Estevam4de69782023-04-26 13:04:58 -030096 /* Get the second MAC address */
97 imx_get_mac_from_fuse(1, eth1addr);
98 if (!env_get("eth1addr") && is_valid_ethaddr(eth1addr))
99 eth_env_set_enetaddr("eth1addr", eth1addr);
100
Fabio Estevamdb1aa292021-05-28 10:26:57 -0300101 return 0;
102}
Eduard Strehlaub2b64562023-04-26 13:04:54 -0300103
Eduard Strehlau1913d142023-06-27 13:57:49 -0300104uint mmc_get_env_part(struct mmc *mmc)
Eduard Strehlaub2b64562023-04-26 13:04:54 -0300105{
106 uint part = EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config);
107
Tim Harveya4e78392024-05-31 08:36:33 -0700108 if (part == EMMC_BOOT_PART_USER)
109 part = EMMC_HWPART_DEFAULT;
Eduard Strehlaub2b64562023-04-26 13:04:54 -0300110 return part;
111}
Eduard Strehlau5fad5252023-04-26 13:04:57 -0300112