blob: 739d2e51554d5cbb7c45f61b23910ce42e8789c9 [file] [log] [blame]
Igor Opaniukc87397f2020-10-22 11:21:38 +03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2020 Toradex
4 */
5
6#include <common.h>
7#include <cpu_func.h>
8#include <init.h>
9
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>
17#include <env.h>
18#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 uart1_pads[] = {
31 SC_P_UART1_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
32 SC_P_UART1_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
33};
34
35static void setup_iomux_uart(void)
36{
37 imx8_iomux_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
38}
39
Igor Opaniuk96f21eb2020-10-22 11:21:42 +030040void board_mem_get_layout(u64 *phys_sdram_1_start,
41 u64 *phys_sdram_1_size,
42 u64 *phys_sdram_2_start,
43 u64 *phys_sdram_2_size)
44{
45 u32 is_dualx = 0, val = 0;
46 sc_err_t scierr = sc_misc_otp_fuse_read(-1, 6, &val);
47
48 if (scierr == SC_ERR_NONE) {
49 /* DX has two A35 cores disabled */
50 is_dualx = (val & 0xf) != 0x0;
51 }
52
53 *phys_sdram_1_start = PHYS_SDRAM_1;
54 if (is_dualx)
55 /* Our DX based SKUs only have 1 GB RAM */
56 *phys_sdram_1_size = SZ_1G;
57 else
58 *phys_sdram_1_size = PHYS_SDRAM_1_SIZE;
59 *phys_sdram_2_start = PHYS_SDRAM_2;
60 *phys_sdram_2_size = PHYS_SDRAM_2_SIZE;
61}
62
Igor Opaniukc87397f2020-10-22 11:21:38 +030063int board_early_init_f(void)
64{
65 sc_pm_clock_rate_t rate;
66 sc_err_t err = 0;
67
68 /*
69 * This works around that having only UART3 up the baudrate is 1.2M
70 * instead of 115.2k. Set UART0 clock root to 80 MHz
71 */
72 rate = 80000000;
73 err = sc_pm_set_clock_rate(-1, SC_R_UART_0, SC_PM_CLK_PER, &rate);
74 if (err != SC_ERR_NONE)
75 return 0;
76
77 /* Set UART3 clock root to 80 MHz and enable it */
78 rate = SC_80MHZ;
79 err = sc_pm_setup_uart(SC_R_UART_1, rate);
80 if (err != SC_ERR_NONE)
81 return 0;
82
83 setup_iomux_uart();
84
85 return 0;
86}
87
88#if IS_ENABLED(CONFIG_DM_GPIO)
89static void board_gpio_init(void)
90{
91 /* TODO */
92}
93#else
94static inline void board_gpio_init(void) {}
95#endif
96
97#if IS_ENABLED(CONFIG_FEC_MXC)
98#include <miiphy.h>
99
100int board_phy_config(struct phy_device *phydev)
101{
102 if (phydev->drv->config)
103 phydev->drv->config(phydev);
104
105 return 0;
106}
107#endif
108
109int checkboard(void)
110{
111 puts("Model: Toradex Apalis iMX8X\n");
112
113 build_info();
114 print_bootinfo();
115
116 return 0;
117}
118
119int board_init(void)
120{
121 board_gpio_init();
122
123 return 0;
124}
125
126/*
127 * Board specific reset that is system reset.
128 */
129void reset_cpu(ulong addr)
130{
131 /* TODO */
132}
133
134#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
135int ft_board_setup(void *blob, struct bd_info *bd)
136{
137 return ft_common_board_setup(blob, bd);
138}
139#endif
140
141int board_mmc_get_env_dev(int devno)
142{
143 return devno;
144}
145
146int board_late_init(void)
147{
148#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
149/* TODO move to common */
150 env_set("board_name", "Apalis iMX8X");
151#endif
152
153 return 0;
154}