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