c9b9b2547ea66df34281b30048f9a9a160d62410
[oweals/u-boot.git] / board / freescale / imx8qm_mek / imx8qm_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/libfdt.h>
12 #include <fdt_support.h>
13 #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
21 DECLARE_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
28 static 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
33 static void setup_iomux_uart(void)
34 {
35         imx8_iomux_setup_multiple_pads(uart0_pads, ARRAY_SIZE(uart0_pads));
36 }
37
38 int board_early_init_f(void)
39 {
40         sc_pm_clock_rate_t rate = SC_80MHZ;
41         int ret;
42
43         /* Set UART0 clock root to 80 MHz */
44         ret = sc_pm_setup_uart(SC_R_UART_0, rate);
45         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
55 #if CONFIG_IS_ENABLED(DM_GPIO)
56 static void board_gpio_init(void)
57 {
58         /* TODO */
59 }
60 #else
61 static inline void board_gpio_init(void) {}
62 #endif
63
64 #if IS_ENABLED(CONFIG_FEC_MXC)
65 #include <miiphy.h>
66
67 int 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
84 int checkboard(void)
85 {
86         puts("Board: iMX8QM MEK\n");
87
88         build_info();
89         print_bootinfo();
90
91         return 0;
92 }
93
94 int 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
104 /*
105  * Board specific reset that is system reset.
106  */
107 void reset_cpu(ulong addr)
108 {
109         /* TODO */
110 }
111
112 #ifdef CONFIG_OF_BOARD_SETUP
113 int ft_board_setup(void *blob, bd_t *bd)
114 {
115         return 0;
116 }
117 #endif
118
119 int board_mmc_get_env_dev(int devno)
120 {
121         return devno;
122 }
123
124 int board_late_init(void)
125 {
126 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
127         env_set("board_name", "MEK");
128         env_set("board_rev", "iMX8QM");
129 #endif
130
131         return 0;
132 }