colibri-imx6ull.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2018-2019 Toradex AG
  4. */
  5. #include <common.h>
  6. #include <init.h>
  7. #include <asm/global_data.h>
  8. #include <linux/delay.h>
  9. #include <asm/arch/clock.h>
  10. #include <asm/arch/crm_regs.h>
  11. #include <asm/arch/imx-regs.h>
  12. #include <asm/arch-mx6/clock.h>
  13. #include <asm/arch-mx6/imx-regs.h>
  14. #include <asm/arch-mx6/mx6ull_pins.h>
  15. #include <asm/arch/sys_proto.h>
  16. #include <asm/gpio.h>
  17. #include <asm/mach-imx/boot_mode.h>
  18. #include <asm/mach-imx/iomux-v3.h>
  19. #include <asm/io.h>
  20. #include <dm.h>
  21. #include <dm/platform_data/serial_mxc.h>
  22. #include <env.h>
  23. #include <fdt_support.h>
  24. #include <imx_thermal.h>
  25. #include <jffs2/load_kernel.h>
  26. #include <linux/sizes.h>
  27. #include <miiphy.h>
  28. #include <mtd_node.h>
  29. #include <netdev.h>
  30. #include "../common/tdx-common.h"
  31. #include "../common/tdx-cfg-block.h"
  32. DECLARE_GLOBAL_DATA_PTR;
  33. #define LCD_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_100K_UP | \
  34. PAD_CTL_DSE_48ohm)
  35. #define MX6_PAD_SNVS_PMIC_STBY_REQ_ADDR 0x2290040
  36. #define NAND_PAD_CTRL (PAD_CTL_DSE_48ohm | PAD_CTL_SRE_SLOW | PAD_CTL_HYS)
  37. #define NAND_PAD_READY0_CTRL (PAD_CTL_DSE_48ohm | PAD_CTL_PUS_22K_UP)
  38. int dram_init(void)
  39. {
  40. gd->ram_size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE);
  41. return 0;
  42. }
  43. #ifdef CONFIG_NAND_MXS
  44. static void setup_gpmi_nand(void)
  45. {
  46. setup_gpmi_io_clk((3 << MXC_CCM_CSCDR1_BCH_PODF_OFFSET) |
  47. (3 << MXC_CCM_CSCDR1_GPMI_PODF_OFFSET));
  48. }
  49. #endif /* CONFIG_NAND_MXS */
  50. #ifdef CONFIG_DM_VIDEO
  51. static iomux_v3_cfg_t const backlight_pads[] = {
  52. /* Backlight On */
  53. MX6_PAD_JTAG_TMS__GPIO1_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
  54. /* Backlight PWM<A> (multiplexed pin) */
  55. MX6_PAD_NAND_WP_B__GPIO4_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
  56. };
  57. #define GPIO_BL_ON IMX_GPIO_NR(1, 11)
  58. #define GPIO_PWM_A IMX_GPIO_NR(4, 11)
  59. static int setup_lcd(void)
  60. {
  61. imx_iomux_v3_setup_multiple_pads(backlight_pads, ARRAY_SIZE(backlight_pads));
  62. /* Set BL_ON */
  63. gpio_request(GPIO_BL_ON, "BL_ON");
  64. gpio_direction_output(GPIO_BL_ON, 1);
  65. /* Set PWM<A> to full brightness (assuming inversed polarity) */
  66. gpio_request(GPIO_PWM_A, "PWM<A>");
  67. gpio_direction_output(GPIO_PWM_A, 0);
  68. return 0;
  69. }
  70. #endif
  71. #ifdef CONFIG_FEC_MXC
  72. static int setup_fec(void)
  73. {
  74. struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
  75. int ret;
  76. /* provide the PHY clock from the i.MX 6 */
  77. ret = enable_fec_anatop_clock(1, ENET_50MHZ);
  78. if (ret)
  79. return ret;
  80. /* Use 50M anatop REF_CLK and output it on ENET2_TX_CLK */
  81. clrsetbits_le32(&iomuxc_regs->gpr[1],
  82. IOMUX_GPR1_FEC2_CLOCK_MUX2_SEL_MASK,
  83. IOMUX_GPR1_FEC2_CLOCK_MUX1_SEL_MASK);
  84. /* give new Ethernet PHY power save mode circuitry time to settle */
  85. mdelay(300);
  86. return 0;
  87. }
  88. int board_phy_config(struct phy_device *phydev)
  89. {
  90. if (phydev->drv->config)
  91. phydev->drv->config(phydev);
  92. return 0;
  93. }
  94. #endif /* CONFIG_FEC_MXC */
  95. int board_init(void)
  96. {
  97. /* address of boot parameters */
  98. gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  99. #ifdef CONFIG_FEC_MXC
  100. setup_fec();
  101. #endif
  102. #ifdef CONFIG_NAND_MXS
  103. setup_gpmi_nand();
  104. #endif
  105. return 0;
  106. }
  107. #ifdef CONFIG_CMD_BMODE
  108. /* TODO */
  109. static const struct boot_mode board_boot_modes[] = {
  110. /* 4 bit bus width */
  111. {"nand", MAKE_CFGVAL(0x40, 0x34, 0x00, 0x00)},
  112. {"sd1", MAKE_CFGVAL(0x10, 0x10, 0x00, 0x00)},
  113. {NULL, 0},
  114. };
  115. #endif
  116. int board_late_init(void)
  117. {
  118. #ifdef CONFIG_TDX_CFG_BLOCK
  119. /*
  120. * If we have a valid config block and it says we are a module with
  121. * Wi-Fi/Bluetooth make sure we use the -wifi device tree.
  122. */
  123. if (tdx_hw_tag.prodid == COLIBRI_IMX6ULL_WIFI_BT_IT ||
  124. tdx_hw_tag.prodid == COLIBRI_IMX6ULL_WIFI_BT)
  125. env_set("variant", "-wifi");
  126. #endif
  127. /*
  128. * Disable output driver of PAD CCM_PMIC_STBY_REQ. This prevents the
  129. * SOC to request for a lower voltage during sleep. This is necessary
  130. * because the voltage is changing too slow for the SOC to wake up
  131. * properly.
  132. */
  133. __raw_writel(0x8080, MX6_PAD_SNVS_PMIC_STBY_REQ_ADDR);
  134. #ifdef CONFIG_CMD_BMODE
  135. add_board_boot_modes(board_boot_modes);
  136. #endif
  137. #ifdef CONFIG_CMD_USB_SDP
  138. if (is_boot_from_usb()) {
  139. printf("Serial Downloader recovery mode, using sdp command\n");
  140. env_set("bootdelay", "0");
  141. env_set("bootcmd", "sdp 0");
  142. }
  143. #endif /* CONFIG_CMD_USB_SDP */
  144. #if defined(CONFIG_DM_VIDEO)
  145. setup_lcd();
  146. #endif
  147. return 0;
  148. }
  149. int checkboard(void)
  150. {
  151. printf("Model: Toradex Colibri iMX6ULL\n");
  152. return 0;
  153. }
  154. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  155. int ft_board_setup(void *blob, struct bd_info *bd)
  156. {
  157. #if defined(CONFIG_FDT_FIXUP_PARTITIONS)
  158. static struct node_info nodes[] = {
  159. { "fsl,imx6ull-gpmi-nand", MTD_DEV_TYPE_NAND, },
  160. { "fsl,imx6q-gpmi-nand", MTD_DEV_TYPE_NAND, },
  161. };
  162. /* Update partition nodes using info from mtdparts env var */
  163. puts(" Updating MTD partitions...\n");
  164. fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
  165. #endif
  166. return ft_common_board_setup(blob, bd);
  167. }
  168. #endif
  169. static struct mxc_serial_plat mxc_serial_plat = {
  170. .reg = (struct mxc_uart *)UART1_BASE,
  171. .use_dte = 1,
  172. };
  173. U_BOOT_DRVINFO(mxc_serial) = {
  174. .name = "serial_mxc",
  175. .plat = &mxc_serial_plat,
  176. };