blob: dc9ffaabf205aacb7f41a0b9ba6a89a0899d850e [file] [log] [blame]
Peng Fan702c6dc2018-10-18 14:28:37 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2018 NXP
4 */
5
6#include <common.h>
Simon Glassafb02152019-12-28 10:45:01 -07007#include <cpu_func.h>
Simon Glass5e6201b2019-08-01 09:46:51 -06008#include <env.h>
Peng Fan702c6dc2018-10-18 14:28:37 +02009#include <errno.h>
Simon Glassa7b51302019-11-14 12:57:46 -070010#include <init.h>
Peng Fan702c6dc2018-10-18 14:28:37 +020011#include <linux/libfdt.h>
Yangbo Lu73340382019-06-21 11:42:28 +080012#include <fsl_esdhc_imx.h>
Alifer Moraesc9c48d92020-01-16 12:43:06 -030013#include <fdt_support.h>
Peng Fan702c6dc2018-10-18 14:28:37 +020014#include <asm/io.h>
15#include <asm/gpio.h>
16#include <asm/arch/clock.h>
17#include <asm/arch/sci/sci.h>
18#include <asm/arch/imx8-pins.h>
Franck LENORMANDd3b70ea2019-10-09 10:27:43 +020019#include <asm/arch/snvs_security_sc.h>
Peng Fan702c6dc2018-10-18 14:28:37 +020020#include <asm/arch/iomux.h>
21#include <asm/arch/sys_proto.h>
22
23DECLARE_GLOBAL_DATA_PTR;
24
25#define GPIO_PAD_CTRL ((SC_PAD_CONFIG_NORMAL << 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
30#define UART_PAD_CTRL ((SC_PAD_CONFIG_OUT_IN << PADRING_CONFIG_SHIFT) | \
31 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
32 (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
33 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
34
35static iomux_cfg_t uart0_pads[] = {
36 SC_P_UART0_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
37 SC_P_UART0_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
38};
39
40static void setup_iomux_uart(void)
41{
42 imx8_iomux_setup_multiple_pads(uart0_pads, ARRAY_SIZE(uart0_pads));
43}
44
45int board_early_init_f(void)
46{
Anatolij Gustschinef156d22019-06-12 13:35:25 +020047 sc_pm_clock_rate_t rate = SC_80MHZ;
Peng Fan702c6dc2018-10-18 14:28:37 +020048 int ret;
Peng Fan702c6dc2018-10-18 14:28:37 +020049
Anatolij Gustschinef156d22019-06-12 13:35:25 +020050 /* Set UART0 clock root to 80 MHz */
51 ret = sc_pm_setup_uart(SC_R_UART_0, rate);
Peng Fan702c6dc2018-10-18 14:28:37 +020052 if (ret)
53 return ret;
54
55 setup_iomux_uart();
56
57 return 0;
58}
59
Simon Glassfa4689a2019-12-06 21:41:35 -070060#if CONFIG_IS_ENABLED(DM_GPIO)
Peng Fan702c6dc2018-10-18 14:28:37 +020061static void board_gpio_init(void)
62{
63 struct gpio_desc desc;
64 int ret;
65
66 ret = dm_gpio_lookup_name("gpio@1a_3", &desc);
67 if (ret)
68 return;
69
70 ret = dm_gpio_request(&desc, "bb_per_rst_b");
71 if (ret)
72 return;
73
74 dm_gpio_set_dir_flags(&desc, GPIOD_IS_OUT);
75 dm_gpio_set_value(&desc, 0);
76 udelay(50);
77 dm_gpio_set_value(&desc, 1);
78}
79#else
80static inline void board_gpio_init(void) {}
81#endif
82
83#if IS_ENABLED(CONFIG_FEC_MXC)
84#include <miiphy.h>
85
86int board_phy_config(struct phy_device *phydev)
87{
88 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x1f);
89 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x8);
90
91 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x05);
92 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100);
93
94 if (phydev->drv->config)
95 phydev->drv->config(phydev);
96
97 return 0;
98}
99#endif
100
Peng Fan702c6dc2018-10-18 14:28:37 +0200101int checkboard(void)
102{
103 puts("Board: iMX8QXP MEK\n");
104
105 build_info();
106 print_bootinfo();
107
108 return 0;
109}
110
111int board_init(void)
112{
113 board_gpio_init();
114
Franck LENORMANDd3b70ea2019-10-09 10:27:43 +0200115#ifdef CONFIG_IMX_SNVS_SEC_SC_AUTO
116 {
117 int ret = snvs_security_sc_init();
118
119 if (ret)
120 return ret;
121 }
122#endif
123
Peng Fan702c6dc2018-10-18 14:28:37 +0200124 return 0;
125}
126
Peng Fan702c6dc2018-10-18 14:28:37 +0200127/*
128 * Board specific reset that is system reset.
129 */
130void reset_cpu(ulong addr)
131{
132 /* TODO */
133}
134
135#ifdef CONFIG_OF_BOARD_SETUP
136int ft_board_setup(void *blob, bd_t *bd)
137{
138 return 0;
139}
140#endif
141
142int board_mmc_get_env_dev(int devno)
143{
144 return devno;
145}
146
147int board_late_init(void)
148{
Peng Fane95219d2020-05-05 20:28:45 +0800149 char *fdt_file;
150 bool m4_booted;
151
Peng Fan702c6dc2018-10-18 14:28:37 +0200152#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
153 env_set("board_name", "MEK");
154 env_set("board_rev", "iMX8QXP");
155#endif
156
Peng Fane95219d2020-05-05 20:28:45 +0800157 fdt_file = env_get("fdt_file");
158 m4_booted = m4_parts_booted();
159
160 if (fdt_file && !strcmp(fdt_file, "undefined")) {
161 if (m4_booted)
162 env_set("fdt_file", "imx8qxp-mek-rpmsg.dtb");
163 else
164 env_set("fdt_file", "imx8qxp-mek.dtb");
165 }
166
Peng Fan702c6dc2018-10-18 14:28:37 +0200167 return 0;
168}