Fabio Estevam | db1aa29 | 2021-05-28 10:26:57 -0300 | [diff] [blame] | 1 | // 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 Estevam | db1aa29 | 2021-05-28 10:26:57 -0300 | [diff] [blame] | 15 | #include <env.h> |
Eduard Strehlau | 5fad525 | 2023-04-26 13:04:57 -0300 | [diff] [blame] | 16 | #include <env_internal.h> |
Fabio Estevam | db1aa29 | 2021-05-28 10:26:57 -0300 | [diff] [blame] | 17 | #include <asm/arch/crm_regs.h> |
| 18 | #include <asm/setup.h> |
| 19 | #include <asm/bootm.h> |
Eduard Strehlau | b2b6456 | 2023-04-26 13:04:54 -0300 | [diff] [blame] | 20 | #include <mmc.h> |
Fabio Estevam | db1aa29 | 2021-05-28 10:26:57 -0300 | [diff] [blame] | 21 | |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
| 24 | #define UART_PAD_CTRL (PAD_CTL_DSE_3P3V_49OHM | PAD_CTL_PUS_PU100KOHM | \ |
| 25 | PAD_CTL_HYS) |
| 26 | |
| 27 | int dram_init(void) |
| 28 | { |
| 29 | gd->ram_size = PHYS_SDRAM_SIZE; |
| 30 | |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | static iomux_v3_cfg_t const wdog_pads[] = { |
| 35 | MX7D_PAD_GPIO1_IO00__WDOG1_WDOG_B | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 36 | }; |
| 37 | |
| 38 | static 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 | |
| 43 | static void setup_iomux_uart(void) |
| 44 | { |
| 45 | imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads)); |
| 46 | }; |
| 47 | |
| 48 | static 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 | |
| 66 | int board_early_init_f(void) |
| 67 | { |
| 68 | setup_iomux_uart(); |
| 69 | setup_fec(); |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | int board_init(void) |
| 74 | { |
| 75 | /* address of boot parameters */ |
| 76 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | int board_late_init(void) |
| 82 | { |
| 83 | struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR; |
Fabio Estevam | 4de6978 | 2023-04-26 13:04:58 -0300 | [diff] [blame] | 84 | unsigned char eth1addr[6]; |
Fabio Estevam | db1aa29 | 2021-05-28 10:26:57 -0300 | [diff] [blame] | 85 | |
| 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 Estevam | 4de6978 | 2023-04-26 13:04:58 -0300 | [diff] [blame] | 96 | /* 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 Estevam | db1aa29 | 2021-05-28 10:26:57 -0300 | [diff] [blame] | 101 | return 0; |
| 102 | } |
Eduard Strehlau | b2b6456 | 2023-04-26 13:04:54 -0300 | [diff] [blame] | 103 | |
Eduard Strehlau | 1913d14 | 2023-06-27 13:57:49 -0300 | [diff] [blame] | 104 | uint mmc_get_env_part(struct mmc *mmc) |
Eduard Strehlau | b2b6456 | 2023-04-26 13:04:54 -0300 | [diff] [blame] | 105 | { |
| 106 | uint part = EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config); |
| 107 | |
Tim Harvey | a4e7839 | 2024-05-31 08:36:33 -0700 | [diff] [blame] | 108 | if (part == EMMC_BOOT_PART_USER) |
| 109 | part = EMMC_HWPART_DEFAULT; |
Eduard Strehlau | b2b6456 | 2023-04-26 13:04:54 -0300 | [diff] [blame] | 110 | return part; |
| 111 | } |
Eduard Strehlau | 5fad525 | 2023-04-26 13:04:57 -0300 | [diff] [blame] | 112 | |