blob: da081e30bec76ad67563742596e26a4064f5c40b [file] [log] [blame]
Marcel Ziswiler7ce134b72019-05-31 18:56:39 +03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2019 Toradex
4 */
5
6#include <common.h>
Simon Glass9a3b4ce2019-12-28 10:45:01 -07007#include <cpu_func.h>
Simon Glass52559322019-11-14 12:57:46 -07008#include <init.h>
Marcel Ziswiler7ce134b72019-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>
13#include <asm/arch/sci/sci.h>
14#include <asm/arch/sys_proto.h>
15#include <asm/gpio.h>
16#include <asm/io.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060017#include <env.h>
Marcel Ziswiler7ce134b72019-05-31 18:56:39 +030018#include <errno.h>
19#include <linux/libfdt.h>
20
21#include "../common/tdx-cfg-block.h"
22
23DECLARE_GLOBAL_DATA_PTR;
24
25#define UART_PAD_CTRL ((SC_PAD_CONFIG_OUT_IN << PADRING_CONFIG_SHIFT) | \
26 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
27 (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
28 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
29
30static iomux_cfg_t uart3_pads[] = {
31 SC_P_FLEXCAN2_RX | MUX_MODE_ALT(2) | MUX_PAD_CTRL(UART_PAD_CTRL),
32 SC_P_FLEXCAN2_TX | MUX_MODE_ALT(2) | MUX_PAD_CTRL(UART_PAD_CTRL),
33 /* Transceiver FORCEOFF# signal, mux to use pull-up */
34 SC_P_QSPI0B_DQS | MUX_MODE_ALT(4) | MUX_PAD_CTRL(UART_PAD_CTRL),
35};
36
37static void setup_iomux_uart(void)
38{
39 imx8_iomux_setup_multiple_pads(uart3_pads, ARRAY_SIZE(uart3_pads));
40}
41
Igor Opaniuk89f7d082020-10-22 11:21:43 +030042void board_mem_get_layout(u64 *phys_sdram_1_start,
43 u64 *phys_sdram_1_size,
44 u64 *phys_sdram_2_start,
45 u64 *phys_sdram_2_size)
46{
47 u32 is_dualx = 0, val = 0;
48 sc_err_t scierr = sc_misc_otp_fuse_read(-1, 6, &val);
49
50 if (scierr == SC_ERR_NONE) {
51 /* DX has two A35 cores disabled */
52 is_dualx = (val & 0xf) != 0x0;
53 }
54
55 *phys_sdram_1_start = PHYS_SDRAM_1;
56 if (is_dualx)
57 /* Our DX based SKUs only have 1 GB RAM */
58 *phys_sdram_1_size = SZ_1G;
59 else
60 *phys_sdram_1_size = PHYS_SDRAM_1_SIZE;
61 *phys_sdram_2_start = PHYS_SDRAM_2;
62 *phys_sdram_2_size = PHYS_SDRAM_2_SIZE;
63}
64
Marcel Ziswiler7ce134b72019-05-31 18:56:39 +030065int board_early_init_f(void)
66{
67 sc_pm_clock_rate_t rate;
68 sc_err_t err = 0;
69
70 /*
71 * This works around that having only UART3 up the baudrate is 1.2M
72 * instead of 115.2k. Set UART0 clock root to 80 MHz
73 */
74 rate = 80000000;
75 err = sc_pm_set_clock_rate(-1, SC_R_UART_0, SC_PM_CLK_PER, &rate);
76 if (err != SC_ERR_NONE)
77 return 0;
78
Anatolij Gustschin64b5f462019-06-12 13:35:25 +020079 /* Set UART3 clock root to 80 MHz and enable it */
80 rate = SC_80MHZ;
81 err = sc_pm_setup_uart(SC_R_UART_3, rate);
Marcel Ziswiler7ce134b72019-05-31 18:56:39 +030082 if (err != SC_ERR_NONE)
83 return 0;
84
85 setup_iomux_uart();
86
87 return 0;
88}
89
90#if IS_ENABLED(CONFIG_DM_GPIO)
91static void board_gpio_init(void)
92{
93 /* TODO */
94}
95#else
96static inline void board_gpio_init(void) {}
97#endif
98
99#if IS_ENABLED(CONFIG_FEC_MXC)
100#include <miiphy.h>
101
102int board_phy_config(struct phy_device *phydev)
103{
104 if (phydev->drv->config)
105 phydev->drv->config(phydev);
106
107 return 0;
108}
109#endif
110
Marcel Ziswiler7ce134b72019-05-31 18:56:39 +0300111int checkboard(void)
112{
113 puts("Model: Toradex Colibri iMX8X\n");
114
115 build_info();
116 print_bootinfo();
117
118 return 0;
119}
120
121int board_init(void)
122{
123 board_gpio_init();
124
125 return 0;
126}
127
Marcel Ziswiler7ce134b72019-05-31 18:56:39 +0300128/*
129 * Board specific reset that is system reset.
130 */
131void reset_cpu(ulong addr)
132{
133 /* TODO */
134}
135
136#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900137int ft_board_setup(void *blob, struct bd_info *bd)
Marcel Ziswiler7ce134b72019-05-31 18:56:39 +0300138{
139 return ft_common_board_setup(blob, bd);
140}
141#endif
142
143int board_mmc_get_env_dev(int devno)
144{
145 return devno;
146}
147
148int board_late_init(void)
149{
150#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
151/* TODO move to common */
152 env_set("board_name", "Colibri iMX8QXP");
153 env_set("board_rev", "v1.0");
154#endif
155
156 return 0;
157}