1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018-2019 Toradex AG
7 #include <asm/global_data.h>
8 #include <linux/delay.h>
10 #include <asm/arch/clock.h>
11 #include <asm/arch/crm_regs.h>
12 #include <asm/arch/imx-regs.h>
13 #include <asm/arch-mx6/clock.h>
14 #include <asm/arch-mx6/imx-regs.h>
15 #include <asm/arch-mx6/mx6ull_pins.h>
16 #include <asm/arch/sys_proto.h>
18 #include <asm/mach-imx/boot_mode.h>
19 #include <asm/mach-imx/iomux-v3.h>
22 #include <dm/platform_data/serial_mxc.h>
24 #include <fdt_support.h>
25 #include <imx_thermal.h>
26 #include <jffs2/load_kernel.h>
27 #include <linux/sizes.h>
32 #include "../common/tdx-common.h"
33 #include "../common/tdx-cfg-block.h"
35 DECLARE_GLOBAL_DATA_PTR;
37 #define LCD_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_100K_UP | \
40 #define MX6_PAD_SNVS_PMIC_STBY_REQ_ADDR 0x2290040
42 #define NAND_PAD_CTRL (PAD_CTL_DSE_48ohm | PAD_CTL_SRE_SLOW | PAD_CTL_HYS)
44 #define NAND_PAD_READY0_CTRL (PAD_CTL_DSE_48ohm | PAD_CTL_PUS_22K_UP)
46 #define FLASH_DETECTION_CTRL (PAD_CTL_HYS | PAD_CTL_PUE)
47 #define FLASH_DET_GPIO IMX_GPIO_NR(4, 1)
48 static const iomux_v3_cfg_t flash_detection_pads[] = {
49 MX6_PAD_NAND_WE_B__GPIO4_IO01 | MUX_PAD_CTRL(FLASH_DETECTION_CTRL),
56 gd->ram_size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE);
61 #ifdef CONFIG_NAND_MXS
62 static void setup_gpmi_nand(void)
64 setup_gpmi_io_clk((MXC_CCM_CS2CDR_ENFC_CLK_PODF(0) |
65 MXC_CCM_CS2CDR_ENFC_CLK_PRED(3) |
66 MXC_CCM_CS2CDR_ENFC_CLK_SEL(3)));
68 #endif /* CONFIG_NAND_MXS */
71 static const iomux_v3_cfg_t backlight_pads[] = {
73 MX6_PAD_JTAG_TMS__GPIO1_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
74 /* Backlight PWM<A> (multiplexed pin) */
75 MX6_PAD_NAND_WP_B__GPIO4_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
78 #define GPIO_BL_ON IMX_GPIO_NR(1, 11)
79 #define GPIO_PWM_A IMX_GPIO_NR(4, 11)
81 static int setup_lcd(void)
83 imx_iomux_v3_setup_multiple_pads(backlight_pads, ARRAY_SIZE(backlight_pads));
86 gpio_request(GPIO_BL_ON, "BL_ON");
87 gpio_direction_output(GPIO_BL_ON, 1);
89 /* Set PWM<A> to full brightness (assuming inversed polarity) */
90 gpio_request(GPIO_PWM_A, "PWM<A>");
91 gpio_direction_output(GPIO_PWM_A, 0);
98 static int setup_fec(void)
100 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
104 * Use 50MHz anatop loopback REF_CLK2 for ENET2,
105 * clear gpr1[14], set gpr1[18].
107 clrsetbits_le32(&iomuxc_regs->gpr[1], IOMUX_GPR1_FEC2_MASK,
108 IOMUX_GPR1_FEC2_CLOCK_MUX1_SEL_MASK);
110 ret = enable_fec_anatop_clock(1, ENET_50MHZ);
118 #endif /* CONFIG_FEC_MXC */
122 /* address of boot parameters */
123 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
126 * Enable GPIO on NAND_WE_B/eMMC_RST with 100k pull-down. eMMC_RST
127 * is pulled high with 4.7k for eMMC devices. This allows to reliably
128 * detect eMMC/NAND flash
130 imx_iomux_v3_setup_multiple_pads(flash_detection_pads, ARRAY_SIZE(flash_detection_pads));
131 gpio_request(FLASH_DET_GPIO, "flash-detection-gpio");
132 is_emmc = gpio_get_value(FLASH_DET_GPIO);
133 gpio_free(FLASH_DET_GPIO);
135 #ifdef CONFIG_FEC_MXC
139 #ifdef CONFIG_NAND_MXS
145 #ifdef CONFIG_CMD_BMODE
147 static const struct boot_mode board_boot_modes[] = {
148 /* 4 bit bus width */
149 {"nand", MAKE_CFGVAL(0x40, 0x34, 0x00, 0x00)},
150 {"sd1", MAKE_CFGVAL(0x10, 0x10, 0x00, 0x00)},
155 int board_late_init(void)
157 #ifdef CONFIG_TDX_CFG_BLOCK
159 * If we have a valid config block and it says we are a module with
160 * Wi-Fi/Bluetooth make sure we use the -wifi device tree.
162 if (tdx_hw_tag.prodid == COLIBRI_IMX6ULL_WIFI_BT_IT ||
163 tdx_hw_tag.prodid == COLIBRI_IMX6ULL_WIFI_BT) {
164 env_set("variant", "-wifi");
167 env_set("variant", "-emmc");
169 env_set("variant", "");
173 env_set("variant", "-emmc");
175 env_set("variant", "");
179 * Disable output driver of PAD CCM_PMIC_STBY_REQ. This prevents the
180 * SOC to request for a lower voltage during sleep. This is necessary
181 * because the voltage is changing too slow for the SOC to wake up
184 __raw_writel(0x8080, MX6_PAD_SNVS_PMIC_STBY_REQ_ADDR);
186 #ifdef CONFIG_CMD_BMODE
187 add_board_boot_modes(board_boot_modes);
190 if (IS_ENABLED(CONFIG_USB) && is_boot_from_usb()) {
191 env_set("bootdelay", "0");
192 if (IS_ENABLED(CONFIG_CMD_USB_SDP)) {
193 printf("Serial Downloader recovery mode, using sdp command\n");
194 env_set("bootcmd", "sdp 0");
195 } else if (IS_ENABLED(CONFIG_CMD_FASTBOOT)) {
196 printf("Fastboot recovery mode, using fastboot command\n");
197 env_set("bootcmd", "fastboot usb 0");
201 #if defined(CONFIG_VIDEO)
210 printf("Model: Toradex Colibri iMX6ULL\n");
212 return tdx_checkboard();
215 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
216 int ft_board_setup(void *blob, struct bd_info *bd)
218 return ft_common_board_setup(blob, bd);
222 static struct mxc_serial_plat mxc_serial_plat = {
223 .reg = (struct mxc_uart *)UART1_BASE,
227 U_BOOT_DRVINFO(mxc_serial) = {
228 .name = "serial_mxc",
229 .plat = &mxc_serial_plat,