blob: 1577cd6ba767762dd302fa4e3ab3c1ec3d2397cd [file] [log] [blame]
Peng Fan702c6dc2018-10-18 14:28:37 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2018 NXP
4 */
5
6#include <common.h>
Simon Glass1f911d42019-12-28 10:45:01 -07007#include <cpu_func.h>
Simon Glass5e6201b2019-08-01 09:46:51 -06008#include <env.h>
Peng Fan702c6dc2018-10-18 14:28:37 +02009#include <errno.h>
Simon Glassa7b51302019-11-14 12:57:46 -070010#include <init.h>
Peng Fan702c6dc2018-10-18 14:28:37 +020011#include <linux/libfdt.h>
Yangbo Lu73340382019-06-21 11:42:28 +080012#include <fsl_esdhc_imx.h>
Peng Fan702c6dc2018-10-18 14:28:37 +020013#include <asm/io.h>
14#include <asm/gpio.h>
15#include <asm/arch/clock.h>
16#include <asm/arch/sci/sci.h>
17#include <asm/arch/imx8-pins.h>
18#include <asm/arch/iomux.h>
19#include <asm/arch/sys_proto.h>
20
21DECLARE_GLOBAL_DATA_PTR;
22
23#define GPIO_PAD_CTRL ((SC_PAD_CONFIG_NORMAL << PADRING_CONFIG_SHIFT) | \
24 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
25 (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
26 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
27
28#define UART_PAD_CTRL ((SC_PAD_CONFIG_OUT_IN << PADRING_CONFIG_SHIFT) | \
29 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
30 (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
31 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
32
33static iomux_cfg_t uart0_pads[] = {
34 SC_P_UART0_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
35 SC_P_UART0_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
36};
37
38static void setup_iomux_uart(void)
39{
40 imx8_iomux_setup_multiple_pads(uart0_pads, ARRAY_SIZE(uart0_pads));
41}
42
43int board_early_init_f(void)
44{
Anatolij Gustschinef156d22019-06-12 13:35:25 +020045 sc_pm_clock_rate_t rate = SC_80MHZ;
Peng Fan702c6dc2018-10-18 14:28:37 +020046 int ret;
Peng Fan702c6dc2018-10-18 14:28:37 +020047
Anatolij Gustschinef156d22019-06-12 13:35:25 +020048 /* Set UART0 clock root to 80 MHz */
49 ret = sc_pm_setup_uart(SC_R_UART_0, rate);
Peng Fan702c6dc2018-10-18 14:28:37 +020050 if (ret)
51 return ret;
52
53 setup_iomux_uart();
54
55 return 0;
56}
57
Simon Glassfa4689a2019-12-06 21:41:35 -070058#if CONFIG_IS_ENABLED(DM_GPIO)
Peng Fan702c6dc2018-10-18 14:28:37 +020059static void board_gpio_init(void)
60{
61 struct gpio_desc desc;
62 int ret;
63
64 ret = dm_gpio_lookup_name("gpio@1a_3", &desc);
65 if (ret)
66 return;
67
68 ret = dm_gpio_request(&desc, "bb_per_rst_b");
69 if (ret)
70 return;
71
72 dm_gpio_set_dir_flags(&desc, GPIOD_IS_OUT);
73 dm_gpio_set_value(&desc, 0);
74 udelay(50);
75 dm_gpio_set_value(&desc, 1);
76}
77#else
78static inline void board_gpio_init(void) {}
79#endif
80
81#if IS_ENABLED(CONFIG_FEC_MXC)
82#include <miiphy.h>
83
84int board_phy_config(struct phy_device *phydev)
85{
86 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x1f);
87 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x8);
88
89 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x05);
90 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100);
91
92 if (phydev->drv->config)
93 phydev->drv->config(phydev);
94
95 return 0;
96}
97#endif
98
Peng Fan702c6dc2018-10-18 14:28:37 +020099int checkboard(void)
100{
101 puts("Board: iMX8QXP MEK\n");
102
103 build_info();
104 print_bootinfo();
105
106 return 0;
107}
108
109int board_init(void)
110{
111 board_gpio_init();
112
113 return 0;
114}
115
116void detail_board_ddr_info(void)
117{
118 puts("\nDDR ");
119}
120
121/*
122 * Board specific reset that is system reset.
123 */
124void reset_cpu(ulong addr)
125{
126 /* TODO */
127}
128
129#ifdef CONFIG_OF_BOARD_SETUP
130int ft_board_setup(void *blob, bd_t *bd)
131{
132 return 0;
133}
134#endif
135
136int board_mmc_get_env_dev(int devno)
137{
138 return devno;
139}
140
141int board_late_init(void)
142{
143#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
144 env_set("board_name", "MEK");
145 env_set("board_rev", "iMX8QXP");
146#endif
147
148 return 0;
149}