evm.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 <asm/arch/hardware.h>
  13. #include <asm/arch/sys_proto.h>
  14. #include <env.h>
  15. #include "../common/board_detect.h"
  16. #define board_is_am64x_gpevm() board_ti_k3_is("AM64-GPEVM")
  17. #define board_is_am64x_skevm() board_ti_k3_is("AM64-SKEVM")
  18. DECLARE_GLOBAL_DATA_PTR;
  19. int board_init(void)
  20. {
  21. return 0;
  22. }
  23. int dram_init(void)
  24. {
  25. gd->ram_size = 0x80000000;
  26. return 0;
  27. }
  28. int dram_init_banksize(void)
  29. {
  30. /* Bank 0 declares the memory available in the DDR low region */
  31. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  32. gd->bd->bi_dram[0].size = 0x80000000;
  33. gd->ram_size = 0x80000000;
  34. return 0;
  35. }
  36. #if defined(CONFIG_SPL_LOAD_FIT)
  37. int board_fit_config_name_match(const char *name)
  38. {
  39. bool eeprom_read = board_ti_was_eeprom_read();
  40. if (!eeprom_read || board_is_am64x_gpevm()) {
  41. if (!strcmp(name, "k3-am642-r5-evm") || !strcmp(name, "k3-am642-evm"))
  42. return 0;
  43. } else if (board_is_am64x_skevm()) {
  44. if (!strcmp(name, "k3-am642-r5-sk") || !strcmp(name, "k3-am642-sk"))
  45. return 0;
  46. }
  47. return -1;
  48. }
  49. #endif
  50. #ifdef CONFIG_TI_I2C_BOARD_DETECT
  51. int do_board_detect(void)
  52. {
  53. int ret;
  54. ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
  55. CONFIG_EEPROM_CHIP_ADDRESS);
  56. if (ret) {
  57. printf("EEPROM not available at 0x%02x, trying to read at 0x%02x\n",
  58. CONFIG_EEPROM_CHIP_ADDRESS, CONFIG_EEPROM_CHIP_ADDRESS + 1);
  59. ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
  60. CONFIG_EEPROM_CHIP_ADDRESS + 1);
  61. if (ret)
  62. pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
  63. CONFIG_EEPROM_CHIP_ADDRESS + 1, ret);
  64. }
  65. return ret;
  66. }
  67. int checkboard(void)
  68. {
  69. struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
  70. if (!do_board_detect())
  71. printf("Board: %s rev %s\n", ep->name, ep->version);
  72. return 0;
  73. }
  74. #ifdef CONFIG_BOARD_LATE_INIT
  75. static void setup_board_eeprom_env(void)
  76. {
  77. char *name = "am64x_gpevm";
  78. if (do_board_detect())
  79. goto invalid_eeprom;
  80. if (board_is_am64x_gpevm())
  81. name = "am64x_gpevm";
  82. else if (board_is_am64x_skevm())
  83. name = "am64x_skevm";
  84. else
  85. printf("Unidentified board claims %s in eeprom header\n",
  86. board_ti_get_name());
  87. invalid_eeprom:
  88. set_board_info_env_am6(name);
  89. }
  90. static void setup_serial(void)
  91. {
  92. struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
  93. unsigned long board_serial;
  94. char *endp;
  95. char serial_string[17] = { 0 };
  96. if (env_get("serial#"))
  97. return;
  98. board_serial = hextoul(ep->serial, &endp);
  99. if (*endp != '\0') {
  100. pr_err("Error: Can't set serial# to %s\n", ep->serial);
  101. return;
  102. }
  103. snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
  104. env_set("serial#", serial_string);
  105. }
  106. #endif
  107. #endif
  108. #ifdef CONFIG_BOARD_LATE_INIT
  109. int board_late_init(void)
  110. {
  111. if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) {
  112. struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
  113. setup_board_eeprom_env();
  114. setup_serial();
  115. /*
  116. * The first MAC address for ethernet a.k.a. ethernet0 comes from
  117. * efuse populated via the am654 gigabit eth switch subsystem driver.
  118. * All the other ones are populated via EEPROM, hence continue with
  119. * an index of 1.
  120. */
  121. board_ti_am6_set_ethaddr(1, ep->mac_addr_cnt);
  122. }
  123. return 0;
  124. }
  125. #endif
  126. #define CTRLMMR_USB0_PHY_CTRL 0x43004008
  127. #define CORE_VOLTAGE 0x80000000
  128. #ifdef CONFIG_SPL_BOARD_INIT
  129. void spl_board_init(void)
  130. {
  131. u32 val;
  132. /* Set USB PHY core voltage to 0.85V */
  133. val = readl(CTRLMMR_USB0_PHY_CTRL);
  134. val &= ~(CORE_VOLTAGE);
  135. writel(val, CTRLMMR_USB0_PHY_CTRL);
  136. }
  137. #endif