blob: adb9556a021c89b9c37d081c6b6909e32338ee00 [file] [log] [blame]
Peng Fan702c6dc2018-10-18 14:28:37 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2018 NXP
4 */
5
Simon Glassafb02152019-12-28 10:45:01 -07006#include <cpu_func.h>
Simon Glass5e6201b2019-08-01 09:46:51 -06007#include <env.h>
Peng Fan702c6dc2018-10-18 14:28:37 +02008#include <errno.h>
Simon Glassa7b51302019-11-14 12:57:46 -07009#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060010#include <asm/global_data.h>
Simon Glassdbd79542020-05-10 11:40:11 -060011#include <linux/delay.h>
Peng Fan702c6dc2018-10-18 14:28:37 +020012#include <linux/libfdt.h>
Yangbo Lu73340382019-06-21 11:42:28 +080013#include <fsl_esdhc_imx.h>
Alifer Moraesc9c48d92020-01-16 12:43:06 -030014#include <fdt_support.h>
Peng Fan702c6dc2018-10-18 14:28:37 +020015#include <asm/io.h>
16#include <asm/gpio.h>
17#include <asm/arch/clock.h>
Peng Fan2e0644a2023-04-28 12:08:09 +080018#include <firmware/imx/sci/sci.h>
Peng Fan702c6dc2018-10-18 14:28:37 +020019#include <asm/arch/imx8-pins.h>
Franck LENORMANDd3b70ea2019-10-09 10:27:43 +020020#include <asm/arch/snvs_security_sc.h>
Peng Fan702c6dc2018-10-18 14:28:37 +020021#include <asm/arch/iomux.h>
22#include <asm/arch/sys_proto.h>
23
24DECLARE_GLOBAL_DATA_PTR;
25
26#define GPIO_PAD_CTRL ((SC_PAD_CONFIG_NORMAL << 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
31#define UART_PAD_CTRL ((SC_PAD_CONFIG_OUT_IN << PADRING_CONFIG_SHIFT) | \
32 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
33 (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
34 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
35
36static iomux_cfg_t uart0_pads[] = {
37 SC_P_UART0_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
38 SC_P_UART0_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
39};
40
41static void setup_iomux_uart(void)
42{
43 imx8_iomux_setup_multiple_pads(uart0_pads, ARRAY_SIZE(uart0_pads));
44}
45
46int board_early_init_f(void)
47{
Anatolij Gustschinef156d22019-06-12 13:35:25 +020048 sc_pm_clock_rate_t rate = SC_80MHZ;
Peng Fan702c6dc2018-10-18 14:28:37 +020049 int ret;
Peng Fan702c6dc2018-10-18 14:28:37 +020050
Anatolij Gustschinef156d22019-06-12 13:35:25 +020051 /* Set UART0 clock root to 80 MHz */
52 ret = sc_pm_setup_uart(SC_R_UART_0, rate);
Peng Fan702c6dc2018-10-18 14:28:37 +020053 if (ret)
54 return ret;
55
56 setup_iomux_uart();
57
58 return 0;
59}
60
Simon Glassfa4689a2019-12-06 21:41:35 -070061#if CONFIG_IS_ENABLED(DM_GPIO)
Peng Fan702c6dc2018-10-18 14:28:37 +020062static void board_gpio_init(void)
63{
64 struct gpio_desc desc;
65 int ret;
66
67 ret = dm_gpio_lookup_name("gpio@1a_3", &desc);
68 if (ret)
69 return;
70
71 ret = dm_gpio_request(&desc, "bb_per_rst_b");
72 if (ret)
73 return;
74
75 dm_gpio_set_dir_flags(&desc, GPIOD_IS_OUT);
76 dm_gpio_set_value(&desc, 0);
77 udelay(50);
78 dm_gpio_set_value(&desc, 1);
79}
80#else
81static inline void board_gpio_init(void) {}
82#endif
83
84#if IS_ENABLED(CONFIG_FEC_MXC)
85#include <miiphy.h>
86
87int board_phy_config(struct phy_device *phydev)
88{
89 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x1f);
90 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x8);
91
92 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x05);
93 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100);
94
95 if (phydev->drv->config)
96 phydev->drv->config(phydev);
97
98 return 0;
99}
100#endif
101
Peng Fan702c6dc2018-10-18 14:28:37 +0200102int checkboard(void)
103{
104 puts("Board: iMX8QXP MEK\n");
105
106 build_info();
107 print_bootinfo();
108
109 return 0;
110}
111
112int board_init(void)
113{
114 board_gpio_init();
115
Franck LENORMANDd3b70ea2019-10-09 10:27:43 +0200116#ifdef CONFIG_IMX_SNVS_SEC_SC_AUTO
117 {
118 int ret = snvs_security_sc_init();
119
120 if (ret)
121 return ret;
122 }
123#endif
124
Peng Fan702c6dc2018-10-18 14:28:37 +0200125 return 0;
126}
127
Peng Fan702c6dc2018-10-18 14:28:37 +0200128#ifdef CONFIG_OF_BOARD_SETUP
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900129int ft_board_setup(void *blob, struct bd_info *bd)
Peng Fan702c6dc2018-10-18 14:28:37 +0200130{
131 return 0;
132}
133#endif
134
135int board_mmc_get_env_dev(int devno)
136{
137 return devno;
138}
139
140int board_late_init(void)
141{
Peng Fane95219d2020-05-05 20:28:45 +0800142 char *fdt_file;
143 bool m4_booted;
144
Peng Fan702c6dc2018-10-18 14:28:37 +0200145#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
146 env_set("board_name", "MEK");
147 env_set("board_rev", "iMX8QXP");
148#endif
149
Peng Fane95219d2020-05-05 20:28:45 +0800150 fdt_file = env_get("fdt_file");
151 m4_booted = m4_parts_booted();
152
153 if (fdt_file && !strcmp(fdt_file, "undefined")) {
154 if (m4_booted)
155 env_set("fdt_file", "imx8qxp-mek-rpmsg.dtb");
156 else
157 env_set("fdt_file", "imx8qxp-mek.dtb");
158 }
159
Peng Fan702c6dc2018-10-18 14:28:37 +0200160 return 0;
161}