Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Marcel Ziswiler | 05959fc | 2019-04-09 17:24:14 +0200 | [diff] [blame] | 3 | * Copyright (C) 2018-2019 Toradex AG |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 4 | */ |
| 5 | #include <common.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 6 | #include <init.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 7 | #include <asm/global_data.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 8 | #include <linux/delay.h> |
Marcel Ziswiler | 05959fc | 2019-04-09 17:24:14 +0200 | [diff] [blame] | 9 | |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 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> |
| 17 | #include <asm/gpio.h> |
| 18 | #include <asm/mach-imx/boot_mode.h> |
| 19 | #include <asm/mach-imx/iomux-v3.h> |
| 20 | #include <asm/io.h> |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 21 | #include <dm.h> |
| 22 | #include <dm/platform_data/serial_mxc.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 23 | #include <env.h> |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 24 | #include <fdt_support.h> |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 25 | #include <imx_thermal.h> |
| 26 | #include <jffs2/load_kernel.h> |
| 27 | #include <linux/sizes.h> |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 28 | #include <miiphy.h> |
| 29 | #include <mtd_node.h> |
| 30 | #include <netdev.h> |
Marcel Ziswiler | 05959fc | 2019-04-09 17:24:14 +0200 | [diff] [blame] | 31 | |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 32 | #include "../common/tdx-common.h" |
Stefan Agner | bf1f289 | 2019-04-09 17:24:09 +0200 | [diff] [blame] | 33 | #include "../common/tdx-cfg-block.h" |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 34 | |
| 35 | DECLARE_GLOBAL_DATA_PTR; |
| 36 | |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 37 | #define LCD_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_100K_UP | \ |
| 38 | PAD_CTL_DSE_48ohm) |
| 39 | |
Philippe Schenker | de51f53 | 2019-04-09 17:24:12 +0200 | [diff] [blame] | 40 | #define MX6_PAD_SNVS_PMIC_STBY_REQ_ADDR 0x2290040 |
| 41 | |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 42 | #define NAND_PAD_CTRL (PAD_CTL_DSE_48ohm | PAD_CTL_SRE_SLOW | PAD_CTL_HYS) |
| 43 | |
| 44 | #define NAND_PAD_READY0_CTRL (PAD_CTL_DSE_48ohm | PAD_CTL_PUS_22K_UP) |
| 45 | |
Max Krummenacher | 1f6668a | 2021-10-06 18:55:36 +0200 | [diff] [blame] | 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), |
| 50 | }; |
| 51 | |
| 52 | static bool is_emmc; |
| 53 | |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 54 | int dram_init(void) |
| 55 | { |
| 56 | gd->ram_size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE); |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 61 | #ifdef CONFIG_NAND_MXS |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 62 | static void setup_gpmi_nand(void) |
| 63 | { |
Philippe Schenker | 873b954 | 2021-10-15 10:25:51 +0200 | [diff] [blame] | 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))); |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 67 | } |
Marcel Ziswiler | 05959fc | 2019-04-09 17:24:14 +0200 | [diff] [blame] | 68 | #endif /* CONFIG_NAND_MXS */ |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 69 | |
Simon Glass | 52cb504 | 2022-10-18 07:46:31 -0600 | [diff] [blame] | 70 | #ifdef CONFIG_VIDEO |
Max Krummenacher | 1f6668a | 2021-10-06 18:55:36 +0200 | [diff] [blame] | 71 | static const iomux_v3_cfg_t backlight_pads[] = { |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 72 | /* Backlight On */ |
| 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), |
| 76 | }; |
| 77 | |
| 78 | #define GPIO_BL_ON IMX_GPIO_NR(1, 11) |
| 79 | #define GPIO_PWM_A IMX_GPIO_NR(4, 11) |
| 80 | |
| 81 | static int setup_lcd(void) |
| 82 | { |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 83 | imx_iomux_v3_setup_multiple_pads(backlight_pads, ARRAY_SIZE(backlight_pads)); |
| 84 | |
| 85 | /* Set BL_ON */ |
| 86 | gpio_request(GPIO_BL_ON, "BL_ON"); |
| 87 | gpio_direction_output(GPIO_BL_ON, 1); |
| 88 | |
| 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); |
| 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | #endif |
| 96 | |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 97 | #ifdef CONFIG_FEC_MXC |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 98 | static int setup_fec(void) |
| 99 | { |
| 100 | struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR; |
| 101 | int ret; |
| 102 | |
Philippe Schenker | c0f1526 | 2022-04-08 10:07:11 +0200 | [diff] [blame] | 103 | /* |
| 104 | * Use 50MHz anatop loopback REF_CLK2 for ENET2, |
| 105 | * clear gpr1[14], set gpr1[18]. |
| 106 | */ |
| 107 | clrsetbits_le32(&iomuxc_regs->gpr[1], IOMUX_GPR1_FEC2_MASK, |
| 108 | IOMUX_GPR1_FEC2_CLOCK_MUX1_SEL_MASK); |
| 109 | |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 110 | ret = enable_fec_anatop_clock(1, ENET_50MHZ); |
| 111 | if (ret) |
| 112 | return ret; |
| 113 | |
Philippe Schenker | c0f1526 | 2022-04-08 10:07:11 +0200 | [diff] [blame] | 114 | enable_enet_clk(1); |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 115 | |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 116 | return 0; |
| 117 | } |
Marcel Ziswiler | 05959fc | 2019-04-09 17:24:14 +0200 | [diff] [blame] | 118 | #endif /* CONFIG_FEC_MXC */ |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 119 | |
| 120 | int board_init(void) |
| 121 | { |
| 122 | /* address of boot parameters */ |
| 123 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 124 | |
Max Krummenacher | 1f6668a | 2021-10-06 18:55:36 +0200 | [diff] [blame] | 125 | /* |
| 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 |
| 129 | */ |
| 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); |
| 134 | |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 135 | #ifdef CONFIG_FEC_MXC |
| 136 | setup_fec(); |
| 137 | #endif |
| 138 | |
| 139 | #ifdef CONFIG_NAND_MXS |
| 140 | setup_gpmi_nand(); |
| 141 | #endif |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | #ifdef CONFIG_CMD_BMODE |
| 146 | /* TODO */ |
| 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)}, |
| 151 | {NULL, 0}, |
| 152 | }; |
| 153 | #endif |
| 154 | |
| 155 | int board_late_init(void) |
| 156 | { |
Stefan Agner | bf1f289 | 2019-04-09 17:24:09 +0200 | [diff] [blame] | 157 | #ifdef CONFIG_TDX_CFG_BLOCK |
| 158 | /* |
| 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. |
| 161 | */ |
| 162 | if (tdx_hw_tag.prodid == COLIBRI_IMX6ULL_WIFI_BT_IT || |
Max Krummenacher | 1f6668a | 2021-10-06 18:55:36 +0200 | [diff] [blame] | 163 | tdx_hw_tag.prodid == COLIBRI_IMX6ULL_WIFI_BT) { |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 164 | env_set("variant", "-wifi"); |
Max Krummenacher | 1f6668a | 2021-10-06 18:55:36 +0200 | [diff] [blame] | 165 | } else { |
| 166 | if (is_emmc) |
| 167 | env_set("variant", "-emmc"); |
Philippe Schenker | 76d31f5 | 2022-04-08 10:07:08 +0200 | [diff] [blame] | 168 | else |
| 169 | env_set("variant", ""); |
Max Krummenacher | 1f6668a | 2021-10-06 18:55:36 +0200 | [diff] [blame] | 170 | } |
| 171 | #else |
| 172 | if (is_emmc) |
| 173 | env_set("variant", "-emmc"); |
Philippe Schenker | 76d31f5 | 2022-04-08 10:07:08 +0200 | [diff] [blame] | 174 | else |
| 175 | env_set("variant", ""); |
Stefan Agner | bf1f289 | 2019-04-09 17:24:09 +0200 | [diff] [blame] | 176 | #endif |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 177 | |
Philippe Schenker | de51f53 | 2019-04-09 17:24:12 +0200 | [diff] [blame] | 178 | /* |
| 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 |
| 182 | * properly. |
| 183 | */ |
| 184 | __raw_writel(0x8080, MX6_PAD_SNVS_PMIC_STBY_REQ_ADDR); |
| 185 | |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 186 | #ifdef CONFIG_CMD_BMODE |
| 187 | add_board_boot_modes(board_boot_modes); |
| 188 | #endif |
| 189 | |
| 190 | #ifdef CONFIG_CMD_USB_SDP |
| 191 | if (is_boot_from_usb()) { |
| 192 | printf("Serial Downloader recovery mode, using sdp command\n"); |
| 193 | env_set("bootdelay", "0"); |
| 194 | env_set("bootcmd", "sdp 0"); |
| 195 | } |
| 196 | #endif /* CONFIG_CMD_USB_SDP */ |
| 197 | |
Simon Glass | 52cb504 | 2022-10-18 07:46:31 -0600 | [diff] [blame] | 198 | #if defined(CONFIG_VIDEO) |
Igor Opaniuk | c803856 | 2020-07-15 13:31:03 +0300 | [diff] [blame] | 199 | setup_lcd(); |
Igor Opaniuk | c803856 | 2020-07-15 13:31:03 +0300 | [diff] [blame] | 200 | #endif |
| 201 | |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | int checkboard(void) |
| 206 | { |
| 207 | printf("Model: Toradex Colibri iMX6ULL\n"); |
| 208 | |
Simon Glass | d44a110 | 2023-11-12 19:58:25 -0700 | [diff] [blame^] | 209 | return tdx_checkboard(); |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 213 | int ft_board_setup(void *blob, struct bd_info *bd) |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 214 | { |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 215 | return ft_common_board_setup(blob, bd); |
| 216 | } |
| 217 | #endif |
| 218 | |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 219 | static struct mxc_serial_plat mxc_serial_plat = { |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 220 | .reg = (struct mxc_uart *)UART1_BASE, |
| 221 | .use_dte = 1, |
| 222 | }; |
| 223 | |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 224 | U_BOOT_DRVINFO(mxc_serial) = { |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 225 | .name = "serial_mxc", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 226 | .plat = &mxc_serial_plat, |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 227 | }; |