xea.c 4.0 KB

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