imx: imx8qxp: update fdt_file according to m4 state
[oweals/u-boot.git] / board / freescale / imx8qxp_mek / imx8qxp_mek.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2018 NXP
4  */
5
6 #include <common.h>
7 #include <cpu_func.h>
8 #include <env.h>
9 #include <errno.h>
10 #include <init.h>
11 #include <linux/libfdt.h>
12 #include <fsl_esdhc_imx.h>
13 #include <fdt_support.h>
14 #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>
19 #include <asm/arch/snvs_security_sc.h>
20 #include <asm/arch/iomux.h>
21 #include <asm/arch/sys_proto.h>
22
23 DECLARE_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
35 static 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
40 static void setup_iomux_uart(void)
41 {
42         imx8_iomux_setup_multiple_pads(uart0_pads, ARRAY_SIZE(uart0_pads));
43 }
44
45 int board_early_init_f(void)
46 {
47         sc_pm_clock_rate_t rate = SC_80MHZ;
48         int ret;
49
50         /* Set UART0 clock root to 80 MHz */
51         ret = sc_pm_setup_uart(SC_R_UART_0, rate);
52         if (ret)
53                 return ret;
54
55         setup_iomux_uart();
56
57         return 0;
58 }
59
60 #if CONFIG_IS_ENABLED(DM_GPIO)
61 static 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
80 static inline void board_gpio_init(void) {}
81 #endif
82
83 #if IS_ENABLED(CONFIG_FEC_MXC)
84 #include <miiphy.h>
85
86 int 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
101 int checkboard(void)
102 {
103         puts("Board: iMX8QXP MEK\n");
104
105         build_info();
106         print_bootinfo();
107
108         return 0;
109 }
110
111 int board_init(void)
112 {
113         board_gpio_init();
114
115 #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
124         return 0;
125 }
126
127 /*
128  * Board specific reset that is system reset.
129  */
130 void reset_cpu(ulong addr)
131 {
132         /* TODO */
133 }
134
135 #ifdef CONFIG_OF_BOARD_SETUP
136 int ft_board_setup(void *blob, bd_t *bd)
137 {
138         return 0;
139 }
140 #endif
141
142 int board_mmc_get_env_dev(int devno)
143 {
144         return devno;
145 }
146
147 int board_late_init(void)
148 {
149         char *fdt_file;
150         bool m4_booted;
151
152 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
153         env_set("board_name", "MEK");
154         env_set("board_rev", "iMX8QXP");
155 #endif
156
157         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
167         return 0;
168 }