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