blob: 345191b31c29b521d3786e54f3822211c2ca6029 [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>
Tom Riniabb9a042024-05-18 20:20:43 -060015#include <common.h>
Fabio Estevamdb1aa292021-05-28 10:26:57 -030016#include <env.h>
Eduard Strehlau5fad5252023-04-26 13:04:57 -030017#include <env_internal.h>
Fabio Estevamdb1aa292021-05-28 10:26:57 -030018#include <asm/arch/crm_regs.h>
19#include <asm/setup.h>
20#include <asm/bootm.h>
Eduard Strehlaub2b64562023-04-26 13:04:54 -030021#include <mmc.h>
Fabio Estevamdb1aa292021-05-28 10:26:57 -030022
23DECLARE_GLOBAL_DATA_PTR;
24
25#define UART_PAD_CTRL (PAD_CTL_DSE_3P3V_49OHM | PAD_CTL_PUS_PU100KOHM | \
26 PAD_CTL_HYS)
27
28int dram_init(void)
29{
30 gd->ram_size = PHYS_SDRAM_SIZE;
31
32 return 0;
33}
34
35static iomux_v3_cfg_t const wdog_pads[] = {
36 MX7D_PAD_GPIO1_IO00__WDOG1_WDOG_B | MUX_PAD_CTRL(NO_PAD_CTRL),
37};
38
39static iomux_v3_cfg_t const uart1_pads[] = {
40 MX7D_PAD_UART1_TX_DATA__UART1_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
41 MX7D_PAD_UART1_RX_DATA__UART1_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
42};
43
44static void setup_iomux_uart(void)
45{
46 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
47};
48
49static int setup_fec(void)
50{
51 struct iomuxc_gpr_base_regs *const iomuxc_gpr_regs =
52 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
53 int ret;
54
55 /* Use 125M anatop REF_CLK1 for ENET1, clear gpr1[13], gpr1[17]*/
56 clrsetbits_le32(&iomuxc_gpr_regs->gpr[1],
57 (IOMUXC_GPR_GPR1_GPR_ENET1_TX_CLK_SEL_MASK |
58 IOMUXC_GPR_GPR1_GPR_ENET1_CLK_DIR_MASK), 0);
59
60 ret = set_clk_enet(ENET_125MHZ);
61 if (ret)
62 return ret;
63
64 return 0;
65}
66
67int board_early_init_f(void)
68{
69 setup_iomux_uart();
70 setup_fec();
71 return 0;
72}
73
74int board_init(void)
75{
76 /* address of boot parameters */
77 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
78
79 return 0;
80}
81
82int board_late_init(void)
83{
84 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
Fabio Estevam4de69782023-04-26 13:04:58 -030085 unsigned char eth1addr[6];
Fabio Estevamdb1aa292021-05-28 10:26:57 -030086
87 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
88
89 set_wdog_reset(wdog);
90
91 /*
92 * Do not assert internal WDOG_RESET_B_DEB(controlled by bit 4),
93 * since we use PMIC_PWRON to reset the board.
94 */
95 clrsetbits_le16(&wdog->wcr, 0, 0x10);
96
Fabio Estevam4de69782023-04-26 13:04:58 -030097 /* Get the second MAC address */
98 imx_get_mac_from_fuse(1, eth1addr);
99 if (!env_get("eth1addr") && is_valid_ethaddr(eth1addr))
100 eth_env_set_enetaddr("eth1addr", eth1addr);
101
Fabio Estevamdb1aa292021-05-28 10:26:57 -0300102 return 0;
103}
Eduard Strehlaub2b64562023-04-26 13:04:54 -0300104
Eduard Strehlau1913d142023-06-27 13:57:49 -0300105uint mmc_get_env_part(struct mmc *mmc)
Eduard Strehlaub2b64562023-04-26 13:04:54 -0300106{
107 uint part = EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config);
108
109 if (part == 7)
110 part = 0;
111 return part;
112}
Eduard Strehlau5fad5252023-04-26 13:04:57 -0300113