blob: e16a771e3ec16c22928de5b3141c878e297a60b8 [file] [log] [blame]
Marcel Ziswiler36a439d2022-02-07 11:54:13 +01001// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright 2022 Toradex
4 */
5
6#include <common.h>
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
24DECLARE_GLOBAL_DATA_PTR;
25
26#define UART_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_FSEL1)
Marcel Ziswiler36a439d2022-02-07 11:54:13 +010027
28/* Verdin UART_3, Console/Debug UART */
29static 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 Ziswiler36a439d2022-02-07 11:54:13 +010034int board_early_init_f(void)
35{
Marcel Ziswiler36a439d2022-02-07 11:54:13 +010036 imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads));
37
38 init_uart_clk(2);
39
40 return 0;
41}
42
43static 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 Ziswiler36a439d2022-02-07 11:54:13 +010052#if IS_ENABLED(CONFIG_NET)
53int 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
61int board_init(void)
62{
63 int ret = 0;
64
65 if (IS_ENABLED(CONFIG_FEC_MXC))
66 setup_fec();
67
Marcel Ziswiler36a439d2022-02-07 11:54:13 +010068 return ret;
69}
70
71static 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 Ghidoli898cdec2023-05-15 15:06:41 +020084 (tdx_hw_tag.prodid == VERDIN_IMX8MPQ_8GB_WIFI_BT) ||
85 (tdx_hw_tag.prodid == VERDIN_IMX8MPQ_8GB_WIFI_BT_IT);
Marcel Ziswiler36a439d2022-02-07 11:54:13 +010086 }
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 Ziswiler36a439d2022-02-07 11:54:13 +010096 }
97}
98
99int board_late_init(void)
100{
101 select_dt_from_module_version();
102
103 return 0;
104}
105
Francesco Dolcini48ed57d2022-09-07 11:51:05 +0200106int 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 Ziswiler36a439d2022-02-07 11:54:13 +0100116#if IS_ENABLED(CONFIG_OF_LIBFDT) && IS_ENABLED(CONFIG_OF_BOARD_SETUP)
117int ft_board_setup(void *blob, struct bd_info *bd)
118{
Philippe Schenker1396e842022-08-29 19:59:53 +0200119 return ft_common_board_setup(blob, bd);
Marcel Ziswiler36a439d2022-02-07 11:54:13 +0100120}
121#endif