blob: bbe371516cc6f136e1b7425b95e2a81700a3a12d [file] [log] [blame]
Vitor Soares987c7362025-04-07 14:04:36 +01001// SPDX-License-Identifier: GPL-2.0-or-later
2/* Copyright (C) 2024 Toradex */
3
4#include <init.h>
5#include <asm/global_data.h>
6#include <asm-generic/gpio.h>
7#include <linux/errno.h>
8
9#include "../common/tdx-cfg-block.h"
10
11DECLARE_GLOBAL_DATA_PTR;
12
13int board_init(void)
14{
15 return 0;
16}
17
18int board_phys_sdram_size(phys_size_t *size)
19{
20 if (!size)
21 return -EINVAL;
22
23 *size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE + PHYS_SDRAM_2_SIZE);
24
25 return 0;
26}
27
28#if IS_ENABLED(CONFIG_OF_LIBFDT) && IS_ENABLED(CONFIG_OF_BOARD_SETUP)
29static bool board_has_wifi(void)
30{
31 struct gpio_desc *desc;
32
33 if (!gpio_hog_lookup_name("BT_UART_RXD_GPIO", &desc))
34 return !!dm_gpio_get_value(desc);
35
36 return true;
37}
38
39/*
40 * Module variants with a Wi-Fi/Bluetooth module use UART3 for Bluetooth,
41 * those without use UART3 as the SMARC SER3 UART.
42 * Test for a Wi-Fi module and if none found reassign UART3 interface to
43 * the SMARC SER3 pins.
44 */
45static void ft_board_assign_uart(void *blob)
46{
47 const char *uart_path = "/soc@0/bus@30800000/spba-bus@30800000/serial@30880000";
48 const char *pinctrl_path = "/soc@0/bus@30000000/pinctrl@30330000/uart3grp";
49 int pinctrl_offset;
50 int uart_offset;
51 int bt_offset;
52 u32 phandle;
53
54 if (board_has_wifi())
55 return;
56
57 uart_offset = fdt_path_offset(blob, uart_path);
58 if (uart_offset < 0)
59 return;
60
61 fdt_delprop(blob, uart_offset, "uart-has-rtscts");
62 bt_offset = fdt_subnode_offset(blob, uart_offset, "bluetooth");
63 if (bt_offset < 0)
64 return;
65
66 fdt_del_node(blob, bt_offset);
67
68 pinctrl_offset = fdt_path_offset(blob, pinctrl_path);
69 if (pinctrl_offset < 0)
70 return;
71
72 phandle = fdt_get_phandle(blob, pinctrl_offset);
73 if (phandle < 0)
74 return;
75
76 fdt_setprop_u32(blob, uart_offset, "pinctrl-0", phandle);
77}
78
79int ft_board_setup(void *blob, struct bd_info *bd)
80{
81 ft_board_assign_uart(blob);
82
83 return ft_common_board_setup(blob, bd);
84}
85#endif