colibri-imx6ull.c 4.9 KB

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