evm.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Board specific initialization for AM642 EVM
  4. *
  5. * Copyright (C) 2020-2021 Texas Instruments Incorporated - https://www.ti.com/
  6. * Keerthy <j-keerthy@ti.com>
  7. *
  8. */
  9. #include <common.h>
  10. #include <asm/io.h>
  11. #include <spl.h>
  12. #include <fdt_support.h>
  13. #include <asm/arch/hardware.h>
  14. #include <asm/arch/sys_proto.h>
  15. #include <env.h>
  16. #include "../common/board_detect.h"
  17. #define board_is_am64x_gpevm() board_ti_k3_is("AM64-GPEVM")
  18. #define board_is_am64x_skevm() board_ti_k3_is("AM64-SKEVM")
  19. DECLARE_GLOBAL_DATA_PTR;
  20. int board_init(void)
  21. {
  22. return 0;
  23. }
  24. int dram_init(void)
  25. {
  26. gd->ram_size = 0x80000000;
  27. return 0;
  28. }
  29. int dram_init_banksize(void)
  30. {
  31. /* Bank 0 declares the memory available in the DDR low region */
  32. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  33. gd->bd->bi_dram[0].size = 0x80000000;
  34. gd->ram_size = 0x80000000;
  35. return 0;
  36. }
  37. #if defined(CONFIG_SPL_LOAD_FIT)
  38. int board_fit_config_name_match(const char *name)
  39. {
  40. bool eeprom_read = board_ti_was_eeprom_read();
  41. if (!eeprom_read || board_is_am64x_gpevm()) {
  42. if (!strcmp(name, "k3-am642-r5-evm") || !strcmp(name, "k3-am642-evm"))
  43. return 0;
  44. } else if (board_is_am64x_skevm()) {
  45. if (!strcmp(name, "k3-am642-r5-sk") || !strcmp(name, "k3-am642-sk"))
  46. return 0;
  47. }
  48. return -1;
  49. }
  50. #endif
  51. #if defined(CONFIG_SPL_BUILD) && CONFIG_IS_ENABLED(USB_STORAGE)
  52. static int fixup_usb_boot(const void *fdt_blob)
  53. {
  54. int ret = 0;
  55. switch (spl_boot_device()) {
  56. case BOOT_DEVICE_USB:
  57. /*
  58. * If the boot mode is host, fixup the dr_mode to host
  59. * before cdns3 bind takes place
  60. */
  61. ret = fdt_find_and_setprop((void *)fdt_blob,
  62. "/bus@f4000/cdns-usb@f900000/usb@f400000",
  63. "dr_mode", "host", 5, 0);
  64. if (ret)
  65. printf("%s: fdt_find_and_setprop() failed:%d\n",
  66. __func__, ret);
  67. fallthrough;
  68. default:
  69. break;
  70. }
  71. return ret;
  72. }
  73. void spl_perform_fixups(struct spl_image_info *spl_image)
  74. {
  75. fixup_usb_boot(spl_image->fdt_addr);
  76. }
  77. #endif
  78. #ifdef CONFIG_TI_I2C_BOARD_DETECT
  79. int do_board_detect(void)
  80. {
  81. int ret;
  82. ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
  83. CONFIG_EEPROM_CHIP_ADDRESS);
  84. if (ret) {
  85. printf("EEPROM not available at 0x%02x, trying to read at 0x%02x\n",
  86. CONFIG_EEPROM_CHIP_ADDRESS, CONFIG_EEPROM_CHIP_ADDRESS + 1);
  87. ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
  88. CONFIG_EEPROM_CHIP_ADDRESS + 1);
  89. if (ret)
  90. pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
  91. CONFIG_EEPROM_CHIP_ADDRESS + 1, ret);
  92. }
  93. return ret;
  94. }
  95. int checkboard(void)
  96. {
  97. struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
  98. if (!do_board_detect())
  99. printf("Board: %s rev %s\n", ep->name, ep->version);
  100. return 0;
  101. }
  102. #ifdef CONFIG_BOARD_LATE_INIT
  103. static void setup_board_eeprom_env(void)
  104. {
  105. char *name = "am64x_gpevm";
  106. if (do_board_detect())
  107. goto invalid_eeprom;
  108. if (board_is_am64x_gpevm())
  109. name = "am64x_gpevm";
  110. else if (board_is_am64x_skevm())
  111. name = "am64x_skevm";
  112. else
  113. printf("Unidentified board claims %s in eeprom header\n",
  114. board_ti_get_name());
  115. invalid_eeprom:
  116. set_board_info_env_am6(name);
  117. }
  118. static void setup_serial(void)
  119. {
  120. struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
  121. unsigned long board_serial;
  122. char *endp;
  123. char serial_string[17] = { 0 };
  124. if (env_get("serial#"))
  125. return;
  126. board_serial = hextoul(ep->serial, &endp);
  127. if (*endp != '\0') {
  128. pr_err("Error: Can't set serial# to %s\n", ep->serial);
  129. return;
  130. }
  131. snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
  132. env_set("serial#", serial_string);
  133. }
  134. #endif
  135. #endif
  136. #ifdef CONFIG_BOARD_LATE_INIT
  137. int board_late_init(void)
  138. {
  139. if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) {
  140. struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
  141. setup_board_eeprom_env();
  142. setup_serial();
  143. /*
  144. * The first MAC address for ethernet a.k.a. ethernet0 comes from
  145. * efuse populated via the am654 gigabit eth switch subsystem driver.
  146. * All the other ones are populated via EEPROM, hence continue with
  147. * an index of 1.
  148. */
  149. board_ti_am6_set_ethaddr(1, ep->mac_addr_cnt);
  150. }
  151. return 0;
  152. }
  153. #endif
  154. #define CTRLMMR_USB0_PHY_CTRL 0x43004008
  155. #define CORE_VOLTAGE 0x80000000
  156. #ifdef CONFIG_SPL_BOARD_INIT
  157. void spl_board_init(void)
  158. {
  159. u32 val;
  160. /* Set USB PHY core voltage to 0.85V */
  161. val = readl(CTRLMMR_USB0_PHY_CTRL);
  162. val &= ~(CORE_VOLTAGE);
  163. writel(val, CTRLMMR_USB0_PHY_CTRL);
  164. }
  165. #endif