board: toradex: add apalis imx8qm 4gb wb it v1.0b module support
[platform/kernel/u-boot.git] / board / toradex / apalis-imx8 / apalis-imx8.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2019 Toradex
4  */
5
6 #include <common.h>
7
8 #include <asm/arch/clock.h>
9 #include <asm/arch/imx8-pins.h>
10 #include <asm/arch/iomux.h>
11 #include <asm/arch/sci/sci.h>
12 #include <asm/arch/sys_proto.h>
13 #include <asm/gpio.h>
14 #include <asm/io.h>
15 #include <environment.h>
16 #include <errno.h>
17 #include <linux/libfdt.h>
18
19 #include "../common/tdx-cfg-block.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 uart1_pads[] = {
29         SC_P_UART1_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
30         SC_P_UART1_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
31 };
32
33 static void setup_iomux_uart(void)
34 {
35         imx8_iomux_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
36 }
37
38 int board_early_init_f(void)
39 {
40         sc_pm_clock_rate_t rate;
41         sc_err_t err = 0;
42
43         /* Power up UART1 */
44         err = sc_pm_set_resource_power_mode(-1, SC_R_UART_1, SC_PM_PW_MODE_ON);
45         if (err != SC_ERR_NONE)
46                 return 0;
47
48         /* Set UART3 clock root to 80 MHz */
49         rate = 80000000;
50         err = sc_pm_set_clock_rate(-1, SC_R_UART_1, SC_PM_CLK_PER, &rate);
51         if (err != SC_ERR_NONE)
52                 return 0;
53
54         /* Enable UART1 clock root */
55         err = sc_pm_clock_enable(-1, SC_R_UART_1, SC_PM_CLK_PER, true, false);
56         if (err != SC_ERR_NONE)
57                 return 0;
58
59         setup_iomux_uart();
60
61         return 0;
62 }
63
64 #if IS_ENABLED(CONFIG_DM_GPIO)
65 static void board_gpio_init(void)
66 {
67         /* TODO */
68 }
69 #else
70 static inline void board_gpio_init(void) {}
71 #endif
72
73 #if IS_ENABLED(CONFIG_FEC_MXC)
74 #include <miiphy.h>
75
76 int board_phy_config(struct phy_device *phydev)
77 {
78         if (phydev->drv->config)
79                 phydev->drv->config(phydev);
80
81         return 0;
82 }
83 #endif
84
85 void build_info(void)
86 {
87         u32 sc_build = 0, sc_commit = 0;
88
89         /* Get SCFW build and commit id */
90         sc_misc_build_info(-1, &sc_build, &sc_commit);
91         if (!sc_build) {
92                 printf("SCFW does not support build info\n");
93                 sc_commit = 0; /* Display 0 if build info not supported */
94         }
95         printf("Build: SCFW %x\n", sc_commit);
96 }
97
98 int checkboard(void)
99 {
100         puts("Model: Toradex Apalis iMX8\n");
101
102         build_info();
103         print_bootinfo();
104
105         return 0;
106 }
107
108 int board_init(void)
109 {
110         board_gpio_init();
111
112         return 0;
113 }
114
115 void detail_board_ddr_info(void)
116 {
117         puts("\nDDR    ");
118 }
119
120 /*
121  * Board specific reset that is system reset.
122  */
123 void reset_cpu(ulong addr)
124 {
125         /* TODO */
126 }
127
128 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
129 int ft_board_setup(void *blob, bd_t *bd)
130 {
131         return ft_common_board_setup(blob, bd);
132 }
133 #endif
134
135 int board_mmc_get_env_dev(int devno)
136 {
137         return devno;
138 }
139
140 int board_late_init(void)
141 {
142 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
143 /* TODO move to common */
144         env_set("board_name", "Apalis iMX8QM");
145         env_set("board_rev", "v1.0");
146 #endif
147
148         return 0;
149 }