xea.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * XEA iMX28 board
  4. *
  5. * Copyright (C) 2019 DENX Software Engineering
  6. * Lukasz Majewski, DENX Software Engineering, lukma@denx.de
  7. *
  8. * Copyright (C) 2018 DENX Software Engineering
  9. * Måns Rullgård, DENX Software Engineering, mans@mansr.com
  10. *
  11. * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
  12. * on behalf of DENX Software Engineering GmbH
  13. *
  14. */
  15. #include <common.h>
  16. #include <fdt_support.h>
  17. #include <init.h>
  18. #include <log.h>
  19. #include <net.h>
  20. #include <asm/gpio.h>
  21. #include <asm/io.h>
  22. #include <asm/arch/imx-regs.h>
  23. #include <asm/arch/iomux-mx28.h>
  24. #include <asm/arch/clock.h>
  25. #include <asm/arch/sys_proto.h>
  26. #include <linux/delay.h>
  27. #include <linux/mii.h>
  28. #include <miiphy.h>
  29. #include <netdev.h>
  30. #include <errno.h>
  31. #include <usb.h>
  32. #include <serial.h>
  33. #ifdef CONFIG_SPL_BUILD
  34. #include <spl.h>
  35. #endif
  36. DECLARE_GLOBAL_DATA_PTR;
  37. /*
  38. * Functions
  39. */
  40. static void init_clocks(void)
  41. {
  42. /* IO0 clock at 480MHz */
  43. mxs_set_ioclk(MXC_IOCLK0, 480000);
  44. /* IO1 clock at 480MHz */
  45. mxs_set_ioclk(MXC_IOCLK1, 480000);
  46. /* SSP0 clock at 96MHz */
  47. mxs_set_sspclk(MXC_SSPCLK0, 96000, 0);
  48. /* SSP2 clock at 160MHz */
  49. mxs_set_sspclk(MXC_SSPCLK2, 160000, 0);
  50. /* SSP3 clock at 96MHz */
  51. mxs_set_sspclk(MXC_SSPCLK3, 96000, 0);
  52. }
  53. #ifdef CONFIG_SPL_BUILD
  54. void board_init_f(ulong arg)
  55. {
  56. init_clocks();
  57. preloader_console_init();
  58. }
  59. static int boot_tiva0, boot_tiva1;
  60. /* Check if TIVAs request booting via U-Boot proper */
  61. void spl_board_init(void)
  62. {
  63. struct gpio_desc btiva0, btiva1, en_3_3v;
  64. int ret;
  65. /*
  66. * Setup GPIO0_0 (TIVA power enable pin) to be output high
  67. * to allow TIVA startup.
  68. */
  69. ret = dm_gpio_lookup_name("GPIO0_0", &en_3_3v);
  70. if (ret)
  71. printf("Cannot get GPIO0_0\n");
  72. ret = dm_gpio_request(&en_3_3v, "pwr_3_3v");
  73. if (ret)
  74. printf("Cannot request GPIO0_0\n");
  75. /* Set GPIO0_0 to HIGH */
  76. dm_gpio_set_dir_flags(&en_3_3v, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
  77. ret = dm_gpio_lookup_name("GPIO0_23", &btiva0);
  78. if (ret)
  79. printf("Cannot get GPIO0_23\n");
  80. ret = dm_gpio_lookup_name("GPIO0_25", &btiva1);
  81. if (ret)
  82. printf("Cannot get GPIO0_25\n");
  83. ret = dm_gpio_request(&btiva0, "boot-tiva0");
  84. if (ret)
  85. printf("Cannot request GPIO0_23\n");
  86. ret = dm_gpio_request(&btiva1, "boot-tiva1");
  87. if (ret)
  88. printf("Cannot request GPIO0_25\n");
  89. dm_gpio_set_dir_flags(&btiva0, GPIOD_IS_IN);
  90. dm_gpio_set_dir_flags(&btiva1, GPIOD_IS_IN);
  91. udelay(1000);
  92. boot_tiva0 = dm_gpio_get_value(&btiva0);
  93. boot_tiva1 = dm_gpio_get_value(&btiva1);
  94. }
  95. void board_boot_order(u32 *spl_boot_list)
  96. {
  97. spl_boot_list[0] = BOOT_DEVICE_MMC1;
  98. spl_boot_list[1] = BOOT_DEVICE_SPI;
  99. spl_boot_list[2] = BOOT_DEVICE_UART;
  100. }
  101. int spl_start_uboot(void)
  102. {
  103. /* break into full u-boot on 'c' */
  104. if (serial_tstc() && serial_getc() == 'c')
  105. return 1;
  106. debug("%s: btiva0: %d btiva1: %d\n", __func__, boot_tiva0, boot_tiva1);
  107. return !boot_tiva0 || !boot_tiva1;
  108. }
  109. #else
  110. int board_early_init_f(void)
  111. {
  112. init_clocks();
  113. return 0;
  114. }
  115. int board_init(void)
  116. {
  117. struct gpio_desc phy_rst;
  118. int ret;
  119. /* Address of boot parameters */
  120. gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
  121. cpu_eth_init(NULL);
  122. /* PHY INT#/PWDN# */
  123. ret = dm_gpio_lookup_name("GPIO4_13", &phy_rst);
  124. if (ret) {
  125. printf("Cannot get GPIO4_13\n");
  126. return ret;
  127. }
  128. ret = dm_gpio_request(&phy_rst, "phy-rst");
  129. if (ret) {
  130. printf("Cannot request GPIO4_13\n");
  131. return ret;
  132. }
  133. dm_gpio_set_dir_flags(&phy_rst, GPIOD_IS_IN);
  134. udelay(1000);
  135. return 0;
  136. }
  137. int dram_init(void)
  138. {
  139. return mxs_dram_init();
  140. }
  141. #ifdef CONFIG_OF_BOARD_SETUP
  142. static int fdt_fixup_l2switch(void *blob)
  143. {
  144. u8 ethaddr[6];
  145. int ret;
  146. if (eth_env_get_enetaddr("ethaddr", ethaddr)) {
  147. ret = fdt_find_and_setprop(blob,
  148. "/ahb@80080000/switch@800f0000",
  149. "local-mac-address", ethaddr, 6, 1);
  150. if (ret < 0)
  151. printf("%s: can't find usbether@1 node: %d\n",
  152. __func__, ret);
  153. }
  154. return 0;
  155. }
  156. int ft_board_setup(void *blob, struct bd_info *bd)
  157. {
  158. /*
  159. * i.MX28 L2 switch needs manual update (fixup) of eth MAC address
  160. * (in 'local-mac-address' property) as it uses "switch@800f0000"
  161. * node, not set by default FIT image handling code in
  162. * "ethernet@800f0000"
  163. */
  164. fdt_fixup_l2switch(blob);
  165. return 0;
  166. }
  167. #endif
  168. #endif /* CONFIG_SPL_BUILD */