blob: adeee676434ca9faf679a1edbb1d4f46b6ac441f [file] [log] [blame]
Marcel Ziswiler99d768b2019-05-31 18:56:39 +03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2019 Toradex
4 */
5
6#include <common.h>
Simon Glassa7b51302019-11-14 12:57:46 -07007#include <init.h>
Marcel Ziswiler99d768b2019-05-31 18:56:39 +03008
9#include <asm/arch/clock.h>
10#include <asm/arch/imx8-pins.h>
11#include <asm/arch/iomux.h>
12#include <asm/arch/sci/sci.h>
13#include <asm/arch/sys_proto.h>
14#include <asm/gpio.h>
15#include <asm/io.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060016#include <env.h>
Marcel Ziswiler99d768b2019-05-31 18:56:39 +030017#include <errno.h>
18#include <linux/libfdt.h>
19
20#include "../common/tdx-cfg-block.h"
21
22DECLARE_GLOBAL_DATA_PTR;
23
24#define UART_PAD_CTRL ((SC_PAD_CONFIG_OUT_IN << PADRING_CONFIG_SHIFT) | \
25 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
26 (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
27 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
28
29static iomux_cfg_t uart3_pads[] = {
30 SC_P_FLEXCAN2_RX | MUX_MODE_ALT(2) | MUX_PAD_CTRL(UART_PAD_CTRL),
31 SC_P_FLEXCAN2_TX | MUX_MODE_ALT(2) | MUX_PAD_CTRL(UART_PAD_CTRL),
32 /* Transceiver FORCEOFF# signal, mux to use pull-up */
33 SC_P_QSPI0B_DQS | MUX_MODE_ALT(4) | MUX_PAD_CTRL(UART_PAD_CTRL),
34};
35
36static void setup_iomux_uart(void)
37{
38 imx8_iomux_setup_multiple_pads(uart3_pads, ARRAY_SIZE(uart3_pads));
39}
40
41int board_early_init_f(void)
42{
43 sc_pm_clock_rate_t rate;
44 sc_err_t err = 0;
45
46 /*
47 * This works around that having only UART3 up the baudrate is 1.2M
48 * instead of 115.2k. Set UART0 clock root to 80 MHz
49 */
50 rate = 80000000;
51 err = sc_pm_set_clock_rate(-1, SC_R_UART_0, SC_PM_CLK_PER, &rate);
52 if (err != SC_ERR_NONE)
53 return 0;
54
Anatolij Gustschinef156d22019-06-12 13:35:25 +020055 /* Set UART3 clock root to 80 MHz and enable it */
56 rate = SC_80MHZ;
57 err = sc_pm_setup_uart(SC_R_UART_3, rate);
Marcel Ziswiler99d768b2019-05-31 18:56:39 +030058 if (err != SC_ERR_NONE)
59 return 0;
60
61 setup_iomux_uart();
62
63 return 0;
64}
65
66#if IS_ENABLED(CONFIG_DM_GPIO)
67static void board_gpio_init(void)
68{
69 /* TODO */
70}
71#else
72static inline void board_gpio_init(void) {}
73#endif
74
75#if IS_ENABLED(CONFIG_FEC_MXC)
76#include <miiphy.h>
77
78int board_phy_config(struct phy_device *phydev)
79{
80 if (phydev->drv->config)
81 phydev->drv->config(phydev);
82
83 return 0;
84}
85#endif
86
Marcel Ziswiler99d768b2019-05-31 18:56:39 +030087int checkboard(void)
88{
89 puts("Model: Toradex Colibri iMX8X\n");
90
91 build_info();
92 print_bootinfo();
93
94 return 0;
95}
96
97int board_init(void)
98{
99 board_gpio_init();
100
101 return 0;
102}
103
104void detail_board_ddr_info(void)
105{
106 puts("\nDDR ");
107}
108
109/*
110 * Board specific reset that is system reset.
111 */
112void reset_cpu(ulong addr)
113{
114 /* TODO */
115}
116
117#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
118int ft_board_setup(void *blob, bd_t *bd)
119{
120 return ft_common_board_setup(blob, bd);
121}
122#endif
123
124int board_mmc_get_env_dev(int devno)
125{
126 return devno;
127}
128
129int board_late_init(void)
130{
131#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
132/* TODO move to common */
133 env_set("board_name", "Colibri iMX8QXP");
134 env_set("board_rev", "v1.0");
135#endif
136
137 return 0;
138}