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