blob: 2a71e7b92de425b4759f07b29d833049d38e008b [file] [log] [blame]
Marcel Ziswiler99d768b2019-05-31 18:56:39 +03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2019 Toradex
4 */
5
Simon Glassafb02152019-12-28 10:45:01 -07006#include <cpu_func.h>
Simon Glassa7b51302019-11-14 12:57:46 -07007#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06008#include <asm/global_data.h>
Marcel Ziswiler99d768b2019-05-31 18:56:39 +03009
10#include <asm/arch/clock.h>
11#include <asm/arch/imx8-pins.h>
12#include <asm/arch/iomux.h>
Peng Fan2e0644a2023-04-28 12:08:09 +080013#include <firmware/imx/sci/sci.h>
Andrejs Cainikovs4a5a9e92023-04-03 13:14:26 +020014#include <asm/arch/snvs_security_sc.h>
Marcel Ziswiler99d768b2019-05-31 18:56:39 +030015#include <asm/arch/sys_proto.h>
16#include <asm/gpio.h>
17#include <asm/io.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060018#include <env.h>
Marcel Ziswiler99d768b2019-05-31 18:56:39 +030019#include <errno.h>
20#include <linux/libfdt.h>
21
22#include "../common/tdx-cfg-block.h"
23
24DECLARE_GLOBAL_DATA_PTR;
25
26#define UART_PAD_CTRL ((SC_PAD_CONFIG_OUT_IN << PADRING_CONFIG_SHIFT) | \
27 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
28 (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
29 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
30
31static iomux_cfg_t uart3_pads[] = {
32 SC_P_FLEXCAN2_RX | MUX_MODE_ALT(2) | MUX_PAD_CTRL(UART_PAD_CTRL),
33 SC_P_FLEXCAN2_TX | MUX_MODE_ALT(2) | MUX_PAD_CTRL(UART_PAD_CTRL),
34 /* Transceiver FORCEOFF# signal, mux to use pull-up */
35 SC_P_QSPI0B_DQS | MUX_MODE_ALT(4) | MUX_PAD_CTRL(UART_PAD_CTRL),
36};
37
38static void setup_iomux_uart(void)
39{
40 imx8_iomux_setup_multiple_pads(uart3_pads, ARRAY_SIZE(uart3_pads));
41}
42
Max Krummenacher88c70712023-03-03 14:26:32 +010043static int is_imx8dx(void)
Igor Opaniukdcc63c12020-10-22 11:21:43 +030044{
Max Krummenacher88c70712023-03-03 14:26:32 +010045 u32 val = 0;
Peng Fanbffd4dc2023-06-15 18:09:00 +080046 int sc_err = sc_misc_otp_fuse_read(-1, 6, &val);
Igor Opaniukdcc63c12020-10-22 11:21:43 +030047
Fabio Estevame4339b82024-03-12 21:36:41 -030048 if (!sc_err) {
Igor Opaniukdcc63c12020-10-22 11:21:43 +030049 /* DX has two A35 cores disabled */
Max Krummenacher88c70712023-03-03 14:26:32 +010050 return (val & 0xf) != 0x0;
Igor Opaniukdcc63c12020-10-22 11:21:43 +030051 }
Max Krummenacher88c70712023-03-03 14:26:32 +010052 return false;
53}
Igor Opaniukdcc63c12020-10-22 11:21:43 +030054
Max Krummenacher88c70712023-03-03 14:26:32 +010055void board_mem_get_layout(u64 *phys_sdram_1_start,
56 u64 *phys_sdram_1_size,
57 u64 *phys_sdram_2_start,
58 u64 *phys_sdram_2_size)
59{
Igor Opaniukdcc63c12020-10-22 11:21:43 +030060 *phys_sdram_1_start = PHYS_SDRAM_1;
Max Krummenacher88c70712023-03-03 14:26:32 +010061 if (is_imx8dx())
Igor Opaniukdcc63c12020-10-22 11:21:43 +030062 /* Our DX based SKUs only have 1 GB RAM */
63 *phys_sdram_1_size = SZ_1G;
64 else
65 *phys_sdram_1_size = PHYS_SDRAM_1_SIZE;
66 *phys_sdram_2_start = PHYS_SDRAM_2;
67 *phys_sdram_2_size = PHYS_SDRAM_2_SIZE;
68}
69
Marcel Ziswiler99d768b2019-05-31 18:56:39 +030070int board_early_init_f(void)
71{
72 sc_pm_clock_rate_t rate;
Peng Fanbffd4dc2023-06-15 18:09:00 +080073 int err;
Marcel Ziswiler99d768b2019-05-31 18:56:39 +030074
75 /*
76 * This works around that having only UART3 up the baudrate is 1.2M
77 * instead of 115.2k. Set UART0 clock root to 80 MHz
78 */
79 rate = 80000000;
80 err = sc_pm_set_clock_rate(-1, SC_R_UART_0, SC_PM_CLK_PER, &rate);
Peng Fanbffd4dc2023-06-15 18:09:00 +080081 if (err)
Marcel Ziswiler99d768b2019-05-31 18:56:39 +030082 return 0;
83
Anatolij Gustschinef156d22019-06-12 13:35:25 +020084 /* Set UART3 clock root to 80 MHz and enable it */
85 rate = SC_80MHZ;
86 err = sc_pm_setup_uart(SC_R_UART_3, rate);
Peng Fanbffd4dc2023-06-15 18:09:00 +080087 if (err)
Marcel Ziswiler99d768b2019-05-31 18:56:39 +030088 return 0;
89
90 setup_iomux_uart();
91
92 return 0;
93}
94
Marcel Ziswiler99d768b2019-05-31 18:56:39 +030095#if IS_ENABLED(CONFIG_FEC_MXC)
96#include <miiphy.h>
97
98int board_phy_config(struct phy_device *phydev)
99{
100 if (phydev->drv->config)
101 phydev->drv->config(phydev);
102
103 return 0;
104}
105#endif
106
Andrejs Cainikovsa4d81542023-03-03 14:26:33 +0100107static void select_dt_from_module_version(void)
108{
109 /*
110 * The dtb filename is constructed from ${soc}-colibri-${fdt_board}.dtb.
111 * Set soc depending on the used SoC.
112 */
113 if (is_imx8dx())
114 env_set("soc", "imx8dx");
115 else
116 env_set("soc", "imx8qxp");
117}
118
Marcel Ziswiler99d768b2019-05-31 18:56:39 +0300119int board_init(void)
120{
Andrejs Cainikovs4a5a9e92023-04-03 13:14:26 +0200121 if (IS_ENABLED(CONFIG_IMX_SNVS_SEC_SC_AUTO)) {
122 int ret = snvs_security_sc_init();
123
124 if (ret)
125 return ret;
126 }
127
Marcel Ziswiler99d768b2019-05-31 18:56:39 +0300128 return 0;
129}
130
Marcel Ziswiler99d768b2019-05-31 18:56:39 +0300131#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900132int ft_board_setup(void *blob, struct bd_info *bd)
Marcel Ziswiler99d768b2019-05-31 18:56:39 +0300133{
134 return ft_common_board_setup(blob, bd);
135}
136#endif
137
138int board_mmc_get_env_dev(int devno)
139{
140 return devno;
141}
142
143int board_late_init(void)
144{
145#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
146/* TODO move to common */
147 env_set("board_name", "Colibri iMX8QXP");
148 env_set("board_rev", "v1.0");
149#endif
150
Andrejs Cainikovsaa390ed2023-04-03 13:14:25 +0200151 build_info();
152
Andrejs Cainikovsa4d81542023-03-03 14:26:33 +0100153 select_dt_from_module_version();
154
Marcel Ziswiler99d768b2019-05-31 18:56:39 +0300155 return 0;
156}