82a79033af4913a3d6541d6315d0f7dffe78f0e7
[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 <errno.h>
8 #include <linux/libfdt.h>
9 #include <environment.h>
10 #include <fsl_esdhc_imx.h>
11 #include <asm/io.h>
12 #include <asm/gpio.h>
13 #include <asm/arch/clock.h>
14 #include <asm/arch/sci/sci.h>
15 #include <asm/arch/imx8-pins.h>
16 #include <asm/arch/iomux.h>
17 #include <asm/arch/sys_proto.h>
18
19 DECLARE_GLOBAL_DATA_PTR;
20
21 #define GPIO_PAD_CTRL   ((SC_PAD_CONFIG_NORMAL << PADRING_CONFIG_SHIFT) | \
22                          (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
23                          (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
24                          (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
25
26 #define UART_PAD_CTRL   ((SC_PAD_CONFIG_OUT_IN << 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 static iomux_cfg_t uart0_pads[] = {
32         SC_P_UART0_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
33         SC_P_UART0_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
34 };
35
36 static void setup_iomux_uart(void)
37 {
38         imx8_iomux_setup_multiple_pads(uart0_pads, ARRAY_SIZE(uart0_pads));
39 }
40
41 int board_early_init_f(void)
42 {
43         sc_pm_clock_rate_t rate = SC_80MHZ;
44         int ret;
45
46         /* Set UART0 clock root to 80 MHz */
47         ret = sc_pm_setup_uart(SC_R_UART_0, rate);
48         if (ret)
49                 return ret;
50
51         setup_iomux_uart();
52
53         return 0;
54 }
55
56 #if IS_ENABLED(CONFIG_DM_GPIO)
57 static void board_gpio_init(void)
58 {
59         struct gpio_desc desc;
60         int ret;
61
62         ret = dm_gpio_lookup_name("gpio@1a_3", &desc);
63         if (ret)
64                 return;
65
66         ret = dm_gpio_request(&desc, "bb_per_rst_b");
67         if (ret)
68                 return;
69
70         dm_gpio_set_dir_flags(&desc, GPIOD_IS_OUT);
71         dm_gpio_set_value(&desc, 0);
72         udelay(50);
73         dm_gpio_set_value(&desc, 1);
74 }
75 #else
76 static inline void board_gpio_init(void) {}
77 #endif
78
79 #if IS_ENABLED(CONFIG_FEC_MXC)
80 #include <miiphy.h>
81
82 int board_phy_config(struct phy_device *phydev)
83 {
84         phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x1f);
85         phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x8);
86
87         phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x05);
88         phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100);
89
90         if (phydev->drv->config)
91                 phydev->drv->config(phydev);
92
93         return 0;
94 }
95 #endif
96
97 void build_info(void)
98 {
99         u32 sc_build = 0, sc_commit = 0;
100
101         /* Get SCFW build and commit id */
102         sc_misc_build_info(-1, &sc_build, &sc_commit);
103         if (!sc_build) {
104                 printf("SCFW does not support build info\n");
105                 sc_commit = 0; /* Display 0 when the build info is not supported */
106         }
107         printf("Build: SCFW %x\n", sc_commit);
108 }
109
110 int checkboard(void)
111 {
112         puts("Board: iMX8QXP MEK\n");
113
114         build_info();
115         print_bootinfo();
116
117         return 0;
118 }
119
120 int board_init(void)
121 {
122         board_gpio_init();
123
124         return 0;
125 }
126
127 void detail_board_ddr_info(void)
128 {
129         puts("\nDDR    ");
130 }
131
132 /*
133  * Board specific reset that is system reset.
134  */
135 void reset_cpu(ulong addr)
136 {
137         /* TODO */
138 }
139
140 #ifdef CONFIG_OF_BOARD_SETUP
141 int ft_board_setup(void *blob, bd_t *bd)
142 {
143         return 0;
144 }
145 #endif
146
147 int board_mmc_get_env_dev(int devno)
148 {
149         return devno;
150 }
151
152 int board_late_init(void)
153 {
154 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
155         env_set("board_name", "MEK");
156         env_set("board_rev", "iMX8QXP");
157 #endif
158
159         return 0;
160 }