Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | /* |
| 3 | * Copyright 2022 Toradex |
| 4 | */ |
| 5 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 6 | #include <config.h> |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 7 | #include <asm/arch/clock.h> |
| 8 | #include <asm/arch/imx8mp_pins.h> |
| 9 | #include <asm/arch/sys_proto.h> |
| 10 | #include <asm-generic/gpio.h> |
| 11 | #include <asm/global_data.h> |
| 12 | #include <asm/mach-imx/gpio.h> |
| 13 | #include <asm/mach-imx/iomux-v3.h> |
| 14 | #include <errno.h> |
| 15 | #include <env.h> |
| 16 | #include <init.h> |
| 17 | #include <linux/delay.h> |
| 18 | #include <micrel.h> |
| 19 | #include <miiphy.h> |
| 20 | #include <netdev.h> |
| 21 | |
| 22 | #include "../common/tdx-cfg-block.h" |
| 23 | |
| 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
| 26 | #define UART_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_FSEL1) |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 27 | |
| 28 | /* Verdin UART_3, Console/Debug UART */ |
| 29 | static const iomux_v3_cfg_t uart_pads[] = { |
| 30 | MX8MP_PAD_UART3_RXD__UART3_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 31 | MX8MP_PAD_UART3_TXD__UART3_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 32 | }; |
| 33 | |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 34 | int board_early_init_f(void) |
| 35 | { |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 36 | imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads)); |
| 37 | |
| 38 | init_uart_clk(2); |
| 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | static void setup_fec(void) |
| 44 | { |
| 45 | struct iomuxc_gpr_base_regs *gpr = |
| 46 | (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR; |
| 47 | |
| 48 | /* Enable RGMII TX clk output */ |
| 49 | setbits_le32(&gpr->gpr[1], BIT(22)); |
| 50 | } |
| 51 | |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 52 | #if IS_ENABLED(CONFIG_NET) |
| 53 | int board_phy_config(struct phy_device *phydev) |
| 54 | { |
| 55 | if (phydev->drv->config) |
| 56 | phydev->drv->config(phydev); |
| 57 | return 0; |
| 58 | } |
| 59 | #endif |
| 60 | |
| 61 | int board_init(void) |
| 62 | { |
| 63 | int ret = 0; |
| 64 | |
| 65 | if (IS_ENABLED(CONFIG_FEC_MXC)) |
| 66 | setup_fec(); |
| 67 | |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 68 | return ret; |
| 69 | } |
| 70 | |
| 71 | static void select_dt_from_module_version(void) |
| 72 | { |
| 73 | char variant[32]; |
| 74 | char *env_variant = env_get("variant"); |
| 75 | int is_wifi = 0; |
| 76 | |
| 77 | if (IS_ENABLED(CONFIG_TDX_CFG_BLOCK)) { |
| 78 | /* |
| 79 | * If we have a valid config block and it says we are a module with |
| 80 | * Wi-Fi/Bluetooth make sure we use the -wifi device tree. |
| 81 | */ |
| 82 | is_wifi = (tdx_hw_tag.prodid == VERDIN_IMX8MPQ_WIFI_BT_IT) || |
| 83 | (tdx_hw_tag.prodid == VERDIN_IMX8MPQ_2GB_WIFI_BT_IT) || |
Emanuele Ghidoli | 898cdec | 2023-05-15 15:06:41 +0200 | [diff] [blame] | 84 | (tdx_hw_tag.prodid == VERDIN_IMX8MPQ_8GB_WIFI_BT) || |
| 85 | (tdx_hw_tag.prodid == VERDIN_IMX8MPQ_8GB_WIFI_BT_IT); |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | if (is_wifi) |
| 89 | strlcpy(&variant[0], "wifi", sizeof(variant)); |
| 90 | else |
| 91 | strlcpy(&variant[0], "nonwifi", sizeof(variant)); |
| 92 | |
| 93 | if (strcmp(variant, env_variant)) { |
| 94 | printf("Setting variant to %s\n", variant); |
| 95 | env_set("variant", variant); |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | |
| 99 | int board_late_init(void) |
| 100 | { |
| 101 | select_dt_from_module_version(); |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
Francesco Dolcini | 48ed57d | 2022-09-07 11:51:05 +0200 | [diff] [blame] | 106 | int board_phys_sdram_size(phys_size_t *size) |
| 107 | { |
| 108 | if (!size) |
| 109 | return -EINVAL; |
| 110 | |
| 111 | *size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE + PHYS_SDRAM_2_SIZE); |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 116 | #if IS_ENABLED(CONFIG_OF_LIBFDT) && IS_ENABLED(CONFIG_OF_BOARD_SETUP) |
| 117 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 118 | { |
Philippe Schenker | 1396e84 | 2022-08-29 19:59:53 +0200 | [diff] [blame] | 119 | return ft_common_board_setup(blob, bd); |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 120 | } |
| 121 | #endif |