blob: 72527f774ca93edc6cd62c9c9e3d265d7dd586e4 [file] [log] [blame]
Peng Fan203a2272019-03-05 02:32:49 +00001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2018 NXP
4 */
5
Simon Glassafb02152019-12-28 10:45:01 -07006#include <cpu_func.h>
Simon Glass5e6201b2019-08-01 09:46:51 -06007#include <env.h>
Peng Fan203a2272019-03-05 02:32:49 +00008#include <errno.h>
Simon Glassa7b51302019-11-14 12:57:46 -07009#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060010#include <asm/global_data.h>
Peng Fan203a2272019-03-05 02:32:49 +000011#include <linux/libfdt.h>
Alifer Moraesca43acf2020-01-16 12:43:07 -030012#include <fdt_support.h>
Peng Fan203a2272019-03-05 02:32:49 +000013#include <asm/io.h>
14#include <asm/gpio.h>
15#include <asm/arch/clock.h>
Peng Fan2e0644a2023-04-28 12:08:09 +080016#include <firmware/imx/sci/sci.h>
Peng Fan203a2272019-03-05 02:32:49 +000017#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 UART_PAD_CTRL ((SC_PAD_CONFIG_OUT_IN << 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
28static iomux_cfg_t uart0_pads[] = {
29 SC_P_UART0_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
30 SC_P_UART0_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
31};
32
33static void setup_iomux_uart(void)
34{
35 imx8_iomux_setup_multiple_pads(uart0_pads, ARRAY_SIZE(uart0_pads));
36}
37
38int board_early_init_f(void)
39{
Anatolij Gustschinef156d22019-06-12 13:35:25 +020040 sc_pm_clock_rate_t rate = SC_80MHZ;
Peng Fan203a2272019-03-05 02:32:49 +000041 int ret;
Peng Fan203a2272019-03-05 02:32:49 +000042
Anatolij Gustschinef156d22019-06-12 13:35:25 +020043 /* Set UART0 clock root to 80 MHz */
44 ret = sc_pm_setup_uart(SC_R_UART_0, rate);
Peng Fan203a2272019-03-05 02:32:49 +000045 if (ret)
46 return ret;
47
48 setup_iomux_uart();
49
50 sc_pm_set_resource_power_mode(-1, SC_R_GPIO_5, SC_PM_PW_MODE_ON);
51
52 return 0;
53}
54
Simon Glassfa4689a2019-12-06 21:41:35 -070055#if CONFIG_IS_ENABLED(DM_GPIO)
Peng Fan203a2272019-03-05 02:32:49 +000056static void board_gpio_init(void)
57{
58 /* TODO */
59}
60#else
61static inline void board_gpio_init(void) {}
62#endif
63
64#if IS_ENABLED(CONFIG_FEC_MXC)
65#include <miiphy.h>
66
67int board_phy_config(struct phy_device *phydev)
68{
69 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x1f);
70 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x8);
71
72 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x00);
73 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x82ee);
74 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x05);
75 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100);
76
77 if (phydev->drv->config)
78 phydev->drv->config(phydev);
79
80 return 0;
81}
82#endif
83
Peng Fan203a2272019-03-05 02:32:49 +000084int checkboard(void)
85{
86 puts("Board: iMX8QM MEK\n");
87
88 build_info();
89 print_bootinfo();
90
91 return 0;
92}
93
94int board_init(void)
95{
96 /* Power up base board */
97 sc_pm_set_resource_power_mode(-1, SC_R_BOARD_R1, SC_PM_PW_MODE_ON);
98
99 board_gpio_init();
100
101 return 0;
102}
103
Peng Fan203a2272019-03-05 02:32:49 +0000104#ifdef CONFIG_OF_BOARD_SETUP
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900105int ft_board_setup(void *blob, struct bd_info *bd)
Peng Fan203a2272019-03-05 02:32:49 +0000106{
107 return 0;
108}
109#endif
110
111int board_mmc_get_env_dev(int devno)
112{
113 return devno;
114}
115
116int board_late_init(void)
117{
Peng Fan88b119e2020-05-05 20:28:44 +0800118 char *fdt_file;
119 bool m4_booted;
120
Peng Fan203a2272019-03-05 02:32:49 +0000121#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
122 env_set("board_name", "MEK");
123 env_set("board_rev", "iMX8QM");
124#endif
125
Peng Fan88b119e2020-05-05 20:28:44 +0800126 fdt_file = env_get("fdt_file");
127 m4_booted = m4_parts_booted();
128
129 if (fdt_file && !strcmp(fdt_file, "undefined")) {
130 if (m4_booted)
131 env_set("fdt_file", "imx8qm-mek-rpmsg.dtb");
132 else
133 env_set("fdt_file", "imx8qm-mek.dtb");
134 }
135
Peng Fan203a2272019-03-05 02:32:49 +0000136 return 0;
137}