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> |
Marcel Ziswiler | 05959fc | 2019-04-09 17:24:14 +0200 | [diff] [blame^] | 6 | |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 7 | #include <asm/arch/clock.h> |
| 8 | #include <asm/arch/crm_regs.h> |
| 9 | #include <asm/arch/imx-regs.h> |
| 10 | #include <asm/arch-mx6/clock.h> |
| 11 | #include <asm/arch-mx6/imx-regs.h> |
| 12 | #include <asm/arch-mx6/mx6ull_pins.h> |
| 13 | #include <asm/arch/sys_proto.h> |
| 14 | #include <asm/gpio.h> |
| 15 | #include <asm/mach-imx/boot_mode.h> |
| 16 | #include <asm/mach-imx/iomux-v3.h> |
| 17 | #include <asm/io.h> |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 18 | #include <dm.h> |
| 19 | #include <dm/platform_data/serial_mxc.h> |
| 20 | #include <fdt_support.h> |
| 21 | #include <fsl_esdhc.h> |
| 22 | #include <imx_thermal.h> |
| 23 | #include <jffs2/load_kernel.h> |
| 24 | #include <linux/sizes.h> |
| 25 | #include <mmc.h> |
| 26 | #include <miiphy.h> |
| 27 | #include <mtd_node.h> |
| 28 | #include <netdev.h> |
| 29 | #include <usb.h> |
| 30 | #include <usb/ehci-ci.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 USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \ |
| 38 | PAD_CTL_SPEED_LOW | PAD_CTL_DSE_40ohm | \ |
| 39 | PAD_CTL_SRE_FAST | PAD_CTL_HYS) |
| 40 | |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 41 | #define LCD_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_100K_UP | \ |
| 42 | PAD_CTL_DSE_48ohm) |
| 43 | |
Philippe Schenker | de51f53 | 2019-04-09 17:24:12 +0200 | [diff] [blame] | 44 | #define MX6_PAD_SNVS_PMIC_STBY_REQ_ADDR 0x2290040 |
| 45 | |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 46 | #define NAND_PAD_CTRL (PAD_CTL_DSE_48ohm | PAD_CTL_SRE_SLOW | PAD_CTL_HYS) |
| 47 | |
| 48 | #define NAND_PAD_READY0_CTRL (PAD_CTL_DSE_48ohm | PAD_CTL_PUS_22K_UP) |
| 49 | |
| 50 | #define USB_CDET_GPIO IMX_GPIO_NR(7, 14) |
| 51 | |
| 52 | int dram_init(void) |
| 53 | { |
| 54 | gd->ram_size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE); |
| 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 59 | #ifdef CONFIG_FSL_ESDHC |
| 60 | static iomux_v3_cfg_t const usdhc1_pads[] = { |
| 61 | MX6_PAD_SD1_CLK__USDHC1_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 62 | MX6_PAD_SD1_CMD__USDHC1_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 63 | MX6_PAD_SD1_DATA0__USDHC1_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 64 | MX6_PAD_SD1_DATA1__USDHC1_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 65 | MX6_PAD_SD1_DATA2__USDHC1_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 66 | MX6_PAD_SD1_DATA3__USDHC1_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 67 | |
| 68 | MX6_PAD_SNVS_TAMPER0__GPIO5_IO00 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 69 | }; |
| 70 | #endif |
| 71 | |
| 72 | static iomux_v3_cfg_t const usb_cdet_pads[] = { |
| 73 | MX6_PAD_SNVS_TAMPER2__GPIO5_IO02 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 74 | }; |
| 75 | |
| 76 | #ifdef CONFIG_NAND_MXS |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 77 | static void setup_gpmi_nand(void) |
| 78 | { |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 79 | setup_gpmi_io_clk((3 << MXC_CCM_CSCDR1_BCH_PODF_OFFSET) | |
| 80 | (3 << MXC_CCM_CSCDR1_GPMI_PODF_OFFSET)); |
| 81 | } |
Marcel Ziswiler | 05959fc | 2019-04-09 17:24:14 +0200 | [diff] [blame^] | 82 | #endif /* CONFIG_NAND_MXS */ |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 83 | |
| 84 | #ifdef CONFIG_VIDEO_MXS |
| 85 | static iomux_v3_cfg_t const lcd_pads[] = { |
| 86 | MX6_PAD_LCD_CLK__LCDIF_CLK | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 87 | MX6_PAD_LCD_ENABLE__LCDIF_ENABLE | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 88 | MX6_PAD_LCD_HSYNC__LCDIF_HSYNC | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 89 | MX6_PAD_LCD_CLK__LCDIF_CLK | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 90 | MX6_PAD_LCD_DATA00__LCDIF_DATA00 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 91 | MX6_PAD_LCD_DATA01__LCDIF_DATA01 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 92 | MX6_PAD_LCD_DATA02__LCDIF_DATA02 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 93 | MX6_PAD_LCD_DATA03__LCDIF_DATA03 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 94 | MX6_PAD_LCD_DATA04__LCDIF_DATA04 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 95 | MX6_PAD_LCD_DATA05__LCDIF_DATA05 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 96 | MX6_PAD_LCD_DATA06__LCDIF_DATA06 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 97 | MX6_PAD_LCD_DATA07__LCDIF_DATA07 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 98 | MX6_PAD_LCD_DATA08__LCDIF_DATA08 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 99 | MX6_PAD_LCD_DATA09__LCDIF_DATA09 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 100 | MX6_PAD_LCD_DATA10__LCDIF_DATA10 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 101 | MX6_PAD_LCD_DATA11__LCDIF_DATA11 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 102 | MX6_PAD_LCD_DATA12__LCDIF_DATA12 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 103 | MX6_PAD_LCD_DATA13__LCDIF_DATA13 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 104 | MX6_PAD_LCD_DATA14__LCDIF_DATA14 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 105 | MX6_PAD_LCD_DATA15__LCDIF_DATA15 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 106 | MX6_PAD_LCD_DATA16__LCDIF_DATA16 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 107 | MX6_PAD_LCD_DATA17__LCDIF_DATA17 | MUX_PAD_CTRL(LCD_PAD_CTRL), |
| 108 | }; |
| 109 | |
| 110 | static iomux_v3_cfg_t const backlight_pads[] = { |
| 111 | /* Backlight On */ |
| 112 | MX6_PAD_JTAG_TMS__GPIO1_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 113 | /* Backlight PWM<A> (multiplexed pin) */ |
| 114 | MX6_PAD_NAND_WP_B__GPIO4_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 115 | }; |
| 116 | |
| 117 | #define GPIO_BL_ON IMX_GPIO_NR(1, 11) |
| 118 | #define GPIO_PWM_A IMX_GPIO_NR(4, 11) |
| 119 | |
| 120 | static int setup_lcd(void) |
| 121 | { |
| 122 | imx_iomux_v3_setup_multiple_pads(lcd_pads, ARRAY_SIZE(lcd_pads)); |
| 123 | |
| 124 | imx_iomux_v3_setup_multiple_pads(backlight_pads, ARRAY_SIZE(backlight_pads)); |
| 125 | |
| 126 | /* Set BL_ON */ |
| 127 | gpio_request(GPIO_BL_ON, "BL_ON"); |
| 128 | gpio_direction_output(GPIO_BL_ON, 1); |
| 129 | |
| 130 | /* Set PWM<A> to full brightness (assuming inversed polarity) */ |
| 131 | gpio_request(GPIO_PWM_A, "PWM<A>"); |
| 132 | gpio_direction_output(GPIO_PWM_A, 0); |
| 133 | |
| 134 | return 0; |
| 135 | } |
| 136 | #endif |
| 137 | |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 138 | #ifdef CONFIG_FSL_ESDHC |
| 139 | |
| 140 | #define USDHC1_CD_GPIO IMX_GPIO_NR(5, 0) |
| 141 | |
| 142 | static struct fsl_esdhc_cfg usdhc_cfg[] = { |
| 143 | {USDHC1_BASE_ADDR, 0, 4}, |
| 144 | }; |
| 145 | |
| 146 | int board_mmc_getcd(struct mmc *mmc) |
| 147 | { |
| 148 | struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv; |
| 149 | int ret = 0; |
| 150 | |
| 151 | switch (cfg->esdhc_base) { |
| 152 | case USDHC1_BASE_ADDR: |
| 153 | ret = !gpio_get_value(USDHC1_CD_GPIO); |
| 154 | break; |
| 155 | } |
| 156 | |
| 157 | return ret; |
| 158 | } |
| 159 | |
| 160 | int board_mmc_init(bd_t *bis) |
| 161 | { |
| 162 | int i, ret; |
| 163 | |
| 164 | /* USDHC1 is mmc0 */ |
| 165 | for (i = 0; i < CONFIG_SYS_FSL_USDHC_NUM; i++) { |
| 166 | switch (i) { |
| 167 | case 0: |
| 168 | imx_iomux_v3_setup_multiple_pads(usdhc1_pads, |
| 169 | ARRAY_SIZE(usdhc1_pads)); |
| 170 | gpio_request(USDHC1_CD_GPIO, "usdhc1_cd"); |
| 171 | gpio_direction_input(USDHC1_CD_GPIO); |
| 172 | usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK); |
| 173 | break; |
| 174 | default: |
| 175 | printf("Warning: you configured more USDHC controllers" |
| 176 | "(%d) than supported by the board\n", i + 1); |
| 177 | return -EINVAL; |
| 178 | } |
| 179 | |
| 180 | ret = fsl_esdhc_initialize(bis, &usdhc_cfg[i]); |
| 181 | if (ret) |
| 182 | return ret; |
| 183 | } |
| 184 | |
| 185 | return 0; |
| 186 | } |
| 187 | #endif |
| 188 | |
| 189 | #ifdef CONFIG_FEC_MXC |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 190 | static int setup_fec(void) |
| 191 | { |
| 192 | struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR; |
| 193 | int ret; |
| 194 | |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 195 | /* provide the PHY clock from the i.MX 6 */ |
| 196 | ret = enable_fec_anatop_clock(1, ENET_50MHZ); |
| 197 | if (ret) |
| 198 | return ret; |
| 199 | |
Marcel Ziswiler | 05959fc | 2019-04-09 17:24:14 +0200 | [diff] [blame^] | 200 | /* Use 50M anatop REF_CLK and output it on ENET2_TX_CLK */ |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 201 | clrsetbits_le32(&iomuxc_regs->gpr[1], |
| 202 | IOMUX_GPR1_FEC2_CLOCK_MUX2_SEL_MASK, |
| 203 | IOMUX_GPR1_FEC2_CLOCK_MUX1_SEL_MASK); |
| 204 | |
Marcel Ziswiler | 561d137 | 2019-04-09 17:24:11 +0200 | [diff] [blame] | 205 | /* give new Ethernet PHY power save mode circuitry time to settle */ |
| 206 | mdelay(300); |
| 207 | |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | int board_phy_config(struct phy_device *phydev) |
| 212 | { |
| 213 | if (phydev->drv->config) |
| 214 | phydev->drv->config(phydev); |
| 215 | return 0; |
| 216 | } |
Marcel Ziswiler | 05959fc | 2019-04-09 17:24:14 +0200 | [diff] [blame^] | 217 | #endif /* CONFIG_FEC_MXC */ |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 218 | |
| 219 | int board_init(void) |
| 220 | { |
| 221 | /* address of boot parameters */ |
| 222 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 223 | |
| 224 | #ifdef CONFIG_FEC_MXC |
| 225 | setup_fec(); |
| 226 | #endif |
| 227 | |
| 228 | #ifdef CONFIG_NAND_MXS |
| 229 | setup_gpmi_nand(); |
| 230 | #endif |
| 231 | |
| 232 | #ifdef CONFIG_VIDEO_MXS |
| 233 | setup_lcd(); |
| 234 | #endif |
| 235 | |
| 236 | #ifdef CONFIG_USB_EHCI_MX6 |
| 237 | imx_iomux_v3_setup_multiple_pads(usb_cdet_pads, ARRAY_SIZE(usb_cdet_pads)); |
| 238 | gpio_request(USB_CDET_GPIO, "usb-cdet-gpio"); |
| 239 | #endif |
| 240 | |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | #ifdef CONFIG_CMD_BMODE |
| 245 | /* TODO */ |
| 246 | static const struct boot_mode board_boot_modes[] = { |
| 247 | /* 4 bit bus width */ |
| 248 | {"nand", MAKE_CFGVAL(0x40, 0x34, 0x00, 0x00)}, |
| 249 | {"sd1", MAKE_CFGVAL(0x10, 0x10, 0x00, 0x00)}, |
| 250 | {NULL, 0}, |
| 251 | }; |
| 252 | #endif |
| 253 | |
| 254 | int board_late_init(void) |
| 255 | { |
Stefan Agner | bf1f289 | 2019-04-09 17:24:09 +0200 | [diff] [blame] | 256 | #ifdef CONFIG_TDX_CFG_BLOCK |
| 257 | /* |
| 258 | * If we have a valid config block and it says we are a module with |
| 259 | * Wi-Fi/Bluetooth make sure we use the -wifi device tree. |
| 260 | */ |
| 261 | if (tdx_hw_tag.prodid == COLIBRI_IMX6ULL_WIFI_BT_IT || |
| 262 | tdx_hw_tag.prodid == COLIBRI_IMX6ULL_WIFI_BT) |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 263 | env_set("variant", "-wifi"); |
Stefan Agner | bf1f289 | 2019-04-09 17:24:09 +0200 | [diff] [blame] | 264 | #endif |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 265 | |
Philippe Schenker | de51f53 | 2019-04-09 17:24:12 +0200 | [diff] [blame] | 266 | /* |
| 267 | * Disable output driver of PAD CCM_PMIC_STBY_REQ. This prevents the |
| 268 | * SOC to request for a lower voltage during sleep. This is necessary |
| 269 | * because the voltage is changing too slow for the SOC to wake up |
| 270 | * properly. |
| 271 | */ |
| 272 | __raw_writel(0x8080, MX6_PAD_SNVS_PMIC_STBY_REQ_ADDR); |
| 273 | |
Stefan Agner | 7b85234 | 2018-05-30 19:01:48 +0200 | [diff] [blame] | 274 | #ifdef CONFIG_CMD_BMODE |
| 275 | add_board_boot_modes(board_boot_modes); |
| 276 | #endif |
| 277 | |
| 278 | #ifdef CONFIG_CMD_USB_SDP |
| 279 | if (is_boot_from_usb()) { |
| 280 | printf("Serial Downloader recovery mode, using sdp command\n"); |
| 281 | env_set("bootdelay", "0"); |
| 282 | env_set("bootcmd", "sdp 0"); |
| 283 | } |
| 284 | #endif /* CONFIG_CMD_USB_SDP */ |
| 285 | |
| 286 | return 0; |
| 287 | } |
| 288 | |
| 289 | int checkboard(void) |
| 290 | { |
| 291 | printf("Model: Toradex Colibri iMX6ULL\n"); |
| 292 | |
| 293 | return 0; |
| 294 | } |
| 295 | |
| 296 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
| 297 | int ft_board_setup(void *blob, bd_t *bd) |
| 298 | { |
| 299 | #if defined(CONFIG_FDT_FIXUP_PARTITIONS) |
| 300 | static struct node_info nodes[] = { |
| 301 | { "fsl,imx6ull-gpmi-nand", MTD_DEV_TYPE_NAND, }, |
| 302 | { "fsl,imx6q-gpmi-nand", MTD_DEV_TYPE_NAND, }, |
| 303 | }; |
| 304 | |
| 305 | /* Update partition nodes using info from mtdparts env var */ |
| 306 | puts(" Updating MTD partitions...\n"); |
| 307 | fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes)); |
| 308 | #endif |
| 309 | |
| 310 | return ft_common_board_setup(blob, bd); |
| 311 | } |
| 312 | #endif |
| 313 | |
| 314 | #ifdef CONFIG_USB_EHCI_MX6 |
| 315 | static iomux_v3_cfg_t const usb_otg2_pads[] = { |
| 316 | MX6_PAD_GPIO1_IO02__GPIO1_IO02 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 317 | }; |
| 318 | |
| 319 | int board_ehci_hcd_init(int port) |
| 320 | { |
| 321 | switch (port) { |
| 322 | case 0: |
| 323 | break; |
| 324 | case 1: |
| 325 | imx_iomux_v3_setup_multiple_pads(usb_otg2_pads, |
| 326 | ARRAY_SIZE(usb_otg2_pads)); |
| 327 | break; |
| 328 | default: |
| 329 | return -EINVAL; |
| 330 | } |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | int board_usb_phy_mode(int port) |
| 335 | { |
| 336 | switch (port) { |
| 337 | case 0: |
| 338 | if (gpio_get_value(USB_CDET_GPIO)) |
| 339 | return USB_INIT_DEVICE; |
| 340 | else |
| 341 | return USB_INIT_HOST; |
| 342 | case 1: |
| 343 | default: |
| 344 | return USB_INIT_HOST; |
| 345 | } |
| 346 | } |
| 347 | #endif |
| 348 | |
| 349 | static struct mxc_serial_platdata mxc_serial_plat = { |
| 350 | .reg = (struct mxc_uart *)UART1_BASE, |
| 351 | .use_dte = 1, |
| 352 | }; |
| 353 | |
| 354 | U_BOOT_DEVICE(mxc_serial) = { |
| 355 | .name = "serial_mxc", |
| 356 | .platdata = &mxc_serial_plat, |
| 357 | }; |