common: Drop linux/delay.h from common header
[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/delay.h>
12 #include <linux/libfdt.h>
13 #include <fsl_esdhc_imx.h>
14 #include <fdt_support.h>
15 #include <asm/io.h>
16 #include <asm/gpio.h>
17 #include <asm/arch/clock.h>
18 #include <asm/arch/sci/sci.h>
19 #include <asm/arch/imx8-pins.h>
20 #include <asm/arch/snvs_security_sc.h>
21 #include <asm/arch/iomux.h>
22 #include <asm/arch/sys_proto.h>
23
24 DECLARE_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
36 static 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
41 static void setup_iomux_uart(void)
42 {
43         imx8_iomux_setup_multiple_pads(uart0_pads, ARRAY_SIZE(uart0_pads));
44 }
45
46 int board_early_init_f(void)
47 {
48         sc_pm_clock_rate_t rate = SC_80MHZ;
49         int ret;
50
51         /* Set UART0 clock root to 80 MHz */
52         ret = sc_pm_setup_uart(SC_R_UART_0, rate);
53         if (ret)
54                 return ret;
55
56         setup_iomux_uart();
57
58         return 0;
59 }
60
61 #if CONFIG_IS_ENABLED(DM_GPIO)
62 static 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
81 static inline void board_gpio_init(void) {}
82 #endif
83
84 #if IS_ENABLED(CONFIG_FEC_MXC)
85 #include <miiphy.h>
86
87 int 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
102 int checkboard(void)
103 {
104         puts("Board: iMX8QXP MEK\n");
105
106         build_info();
107         print_bootinfo();
108
109         return 0;
110 }
111
112 int board_init(void)
113 {
114         board_gpio_init();
115
116 #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
125         return 0;
126 }
127
128 /*
129  * Board specific reset that is system reset.
130  */
131 void reset_cpu(ulong addr)
132 {
133         /* TODO */
134 }
135
136 #ifdef CONFIG_OF_BOARD_SETUP
137 int ft_board_setup(void *blob, bd_t *bd)
138 {
139         return 0;
140 }
141 #endif
142
143 int board_mmc_get_env_dev(int devno)
144 {
145         return devno;
146 }
147
148 int board_late_init(void)
149 {
150         char *fdt_file;
151         bool m4_booted;
152
153 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
154         env_set("board_name", "MEK");
155         env_set("board_rev", "iMX8QXP");
156 #endif
157
158         fdt_file = env_get("fdt_file");
159         m4_booted = m4_parts_booted();
160
161         if (fdt_file && !strcmp(fdt_file, "undefined")) {
162                 if (m4_booted)
163                         env_set("fdt_file", "imx8qxp-mek-rpmsg.dtb");
164                 else
165                         env_set("fdt_file", "imx8qxp-mek.dtb");
166         }
167
168         return 0;
169 }