summaryrefslogtreecommitdiff
path: root/board/toradex/smarc-imx8mp/smarc-imx8mp.c
blob: bbe371516cc6f136e1b7425b95e2a81700a3a12d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// SPDX-License-Identifier: GPL-2.0-or-later
/* Copyright (C) 2024 Toradex */

#include <init.h>
#include <asm/global_data.h>
#include <asm-generic/gpio.h>
#include <linux/errno.h>

#include "../common/tdx-cfg-block.h"

DECLARE_GLOBAL_DATA_PTR;

int board_init(void)
{
	return 0;
}

int board_phys_sdram_size(phys_size_t *size)
{
	if (!size)
		return -EINVAL;

	*size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE + PHYS_SDRAM_2_SIZE);

	return 0;
}

#if IS_ENABLED(CONFIG_OF_LIBFDT) && IS_ENABLED(CONFIG_OF_BOARD_SETUP)
static bool board_has_wifi(void)
{
	struct gpio_desc *desc;

	if (!gpio_hog_lookup_name("BT_UART_RXD_GPIO", &desc))
		return !!dm_gpio_get_value(desc);

	return true;
}

/*
 * Module variants with a Wi-Fi/Bluetooth module use UART3 for Bluetooth,
 * those without use UART3 as the SMARC SER3 UART.
 * Test for a Wi-Fi module and if none found reassign UART3 interface to
 * the SMARC SER3 pins.
 */
static void ft_board_assign_uart(void *blob)
{
	const char *uart_path = "/soc@0/bus@30800000/spba-bus@30800000/serial@30880000";
	const char *pinctrl_path = "/soc@0/bus@30000000/pinctrl@30330000/uart3grp";
	int pinctrl_offset;
	int uart_offset;
	int bt_offset;
	u32 phandle;

	if (board_has_wifi())
		return;

	uart_offset = fdt_path_offset(blob, uart_path);
	if (uart_offset < 0)
		return;

	fdt_delprop(blob, uart_offset, "uart-has-rtscts");
	bt_offset = fdt_subnode_offset(blob, uart_offset, "bluetooth");
	if (bt_offset < 0)
		return;

	fdt_del_node(blob, bt_offset);

	pinctrl_offset = fdt_path_offset(blob, pinctrl_path);
	if (pinctrl_offset < 0)
		return;

	phandle = fdt_get_phandle(blob, pinctrl_offset);
	if (phandle < 0)
		return;

	fdt_setprop_u32(blob, uart_offset, "pinctrl-0", phandle);
}

int ft_board_setup(void *blob, struct bd_info *bd)
{
	ft_board_assign_uart(blob);

	return ft_common_board_setup(blob, bd);
}
#endif