1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright 2017-2018 NXP
4 * Copyright (C) 2019 Oliver Graute <oliver.graute@kococonnector.com>
5 */
6
7 #include <cpu_func.h>
8 #include <env.h>
9 #include <errno.h>
10 #include <init.h>
11 #include <asm/global_data.h>
12 #include <linux/delay.h>
13 #include <linux/libfdt.h>
14 #include <asm/io.h>
15 #include <asm/gpio.h>
16 #include <asm/arch/clock.h>
17 #include <firmware/imx/sci/sci.h>
18 #include <asm/arch/imx8-pins.h>
19 #include <asm/arch/iomux.h>
20 #include <asm/arch/sys_proto.h>
21
22 DECLARE_GLOBAL_DATA_PTR;
23
24 #define UART_PAD_CTRL ((SC_PAD_CONFIG_OUT_IN << PADRING_CONFIG_SHIFT) | \
25 (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
26 (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
27 (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
28
29 static iomux_cfg_t uart0_pads[] = {
30 SC_P_UART0_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
31 SC_P_UART0_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
32 };
33
setup_iomux_uart(void)34 static void setup_iomux_uart(void)
35 {
36 imx8_iomux_setup_multiple_pads(uart0_pads, ARRAY_SIZE(uart0_pads));
37 }
38
board_early_init_f(void)39 int board_early_init_f(void)
40 {
41 sc_pm_clock_rate_t rate = SC_80MHZ;
42 int ret;
43
44 /* Set UART0 clock root to 80 MHz */
45 ret = sc_pm_setup_uart(SC_R_UART_0, rate);
46 if (ret)
47 return ret;
48
49 setup_iomux_uart();
50
51 /* This is needed to because Kernel do not Power Up DC_0 */
52 sc_pm_set_resource_power_mode(-1, SC_R_DC_0, SC_PM_PW_MODE_ON);
53 sc_pm_set_resource_power_mode(-1, SC_R_GPIO_5, SC_PM_PW_MODE_ON);
54
55 return 0;
56 }
57
58 #if IS_ENABLED(CONFIG_FEC_MXC)
59 #include <miiphy.h>
60
board_phy_config(struct phy_device * phydev)61 int board_phy_config(struct phy_device *phydev)
62 {
63 #ifdef CONFIG_FEC_ENABLE_MAX7322
64 u8 value;
65
66 /* This is needed to drive the pads to 1.8V instead of 1.5V */
67 i2c_set_bus_num(CONFIG_MAX7322_I2C_BUS);
68
69 if (!i2c_probe(CONFIG_MAX7322_I2C_ADDR)) {
70 /* Write 0x1 to enable O0 output, this device has no addr */
71 /* hence addr length is 0 */
72 value = 0x1;
73 if (dm_i2c_write(CONFIG_MAX7322_I2C_ADDR, 0, 0, &value, 1))
74 printf("MAX7322 write failed\n");
75 } else {
76 printf("MAX7322 Not found\n");
77 }
78 mdelay(1);
79 #endif
80
81 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x1f);
82 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x8);
83
84 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x00);
85 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x82ee);
86 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x05);
87 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100);
88
89 if (phydev->drv->config)
90 phydev->drv->config(phydev);
91
92 return 0;
93 }
94 #endif
95
checkboard(void)96 int checkboard(void)
97 {
98 puts("Board: ROM-7720-A1 4GB\n");
99
100 build_info();
101 print_bootinfo();
102
103 return 0;
104 }
105
board_init(void)106 int board_init(void)
107 {
108 /* Power up base board */
109 sc_pm_set_resource_power_mode(-1, SC_R_BOARD_R1, SC_PM_PW_MODE_ON);
110
111 return 0;
112 }
113
board_mmc_get_env_dev(int devno)114 int board_mmc_get_env_dev(int devno)
115 {
116 return devno;
117 }
118
board_late_init(void)119 int board_late_init(void)
120 {
121 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
122 env_set("board_name", "ROM-7720-A1");
123 env_set("board_rev", "iMX8QM");
124 #endif
125
126 env_set("sec_boot", "no");
127 #ifdef CONFIG_AHAB_BOOT
128 env_set("sec_boot", "yes");
129 #endif
130
131 return 0;
132 }
133