evm.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Board specific initialization for AM654 EVM
  4. *
  5. * Copyright (C) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/
  6. * Lokesh Vutla <lokeshvutla@ti.com>
  7. *
  8. */
  9. #include <common.h>
  10. #include <dm.h>
  11. #include <fdt_support.h>
  12. #include <image.h>
  13. #include <init.h>
  14. #include <net.h>
  15. #include <asm/arch/sys_proto.h>
  16. #include <asm/arch/hardware.h>
  17. #include <asm/gpio.h>
  18. #include <asm/io.h>
  19. #include <asm/omap_common.h>
  20. #include <env.h>
  21. #include <spl.h>
  22. #include <asm/arch/sys_proto.h>
  23. #include "../common/board_detect.h"
  24. #define board_is_am65x_base_board() board_ti_is("AM6-COMPROCEVM")
  25. /* Daughter card presence detection signals */
  26. enum {
  27. AM65X_EVM_APP_BRD_DET,
  28. AM65X_EVM_LCD_BRD_DET,
  29. AM65X_EVM_SERDES_BRD_DET,
  30. AM65X_EVM_HDMI_GPMC_BRD_DET,
  31. AM65X_EVM_BRD_DET_COUNT,
  32. };
  33. /* Max number of MAC addresses that are parsed/processed per daughter card */
  34. #define DAUGHTER_CARD_NO_OF_MAC_ADDR 8
  35. DECLARE_GLOBAL_DATA_PTR;
  36. int board_init(void)
  37. {
  38. return 0;
  39. }
  40. int dram_init(void)
  41. {
  42. #ifdef CONFIG_PHYS_64BIT
  43. gd->ram_size = 0x100000000;
  44. #else
  45. gd->ram_size = 0x80000000;
  46. #endif
  47. return 0;
  48. }
  49. ulong board_get_usable_ram_top(ulong total_size)
  50. {
  51. #ifdef CONFIG_PHYS_64BIT
  52. /* Limit RAM used by U-Boot to the DDR low region */
  53. if (gd->ram_top > 0x100000000)
  54. return 0x100000000;
  55. #endif
  56. return gd->ram_top;
  57. }
  58. int dram_init_banksize(void)
  59. {
  60. /* Bank 0 declares the memory available in the DDR low region */
  61. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  62. gd->bd->bi_dram[0].size = 0x80000000;
  63. gd->ram_size = 0x80000000;
  64. #ifdef CONFIG_PHYS_64BIT
  65. /* Bank 1 declares the memory available in the DDR high region */
  66. gd->bd->bi_dram[1].start = CONFIG_SYS_SDRAM_BASE1;
  67. gd->bd->bi_dram[1].size = 0x80000000;
  68. gd->ram_size = 0x100000000;
  69. #endif
  70. return 0;
  71. }
  72. #ifdef CONFIG_SPL_LOAD_FIT
  73. int board_fit_config_name_match(const char *name)
  74. {
  75. #ifdef CONFIG_TARGET_AM654_A53_EVM
  76. if (!strcmp(name, "k3-am654-base-board"))
  77. return 0;
  78. #endif
  79. return -1;
  80. }
  81. #endif
  82. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  83. int ft_board_setup(void *blob, struct bd_info *bd)
  84. {
  85. int ret;
  86. ret = fdt_fixup_msmc_ram(blob, "/bus@100000", "sram@70000000");
  87. if (ret < 0)
  88. ret = fdt_fixup_msmc_ram(blob, "/interconnect@100000",
  89. "sram@70000000");
  90. if (ret) {
  91. printf("%s: fixing up msmc ram failed %d\n", __func__, ret);
  92. return ret;
  93. }
  94. #if defined(CONFIG_TI_SECURE_DEVICE)
  95. /* Make Crypto HW reserved for secure world use */
  96. ret = fdt_disable_node(blob, "/bus@100000/crypto@4e00000");
  97. if (ret < 0)
  98. ret = fdt_disable_node(blob,
  99. "/interconnect@100000/crypto@4E00000");
  100. if (ret)
  101. printf("%s: disabling SA2UL failed %d\n", __func__, ret);
  102. #endif
  103. return 0;
  104. }
  105. #endif
  106. int do_board_detect(void)
  107. {
  108. int ret;
  109. ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
  110. CONFIG_EEPROM_CHIP_ADDRESS);
  111. if (ret)
  112. pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
  113. CONFIG_EEPROM_CHIP_ADDRESS, ret);
  114. return ret;
  115. }
  116. int checkboard(void)
  117. {
  118. struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
  119. if (do_board_detect())
  120. /* EEPROM not populated */
  121. printf("Board: %s rev %s\n", "AM6-COMPROCEVM", "E3");
  122. else
  123. printf("Board: %s rev %s\n", ep->name, ep->version);
  124. return 0;
  125. }
  126. static void setup_board_eeprom_env(void)
  127. {
  128. char *name = "am65x";
  129. if (do_board_detect())
  130. goto invalid_eeprom;
  131. if (board_is_am65x_base_board())
  132. name = "am65x";
  133. else
  134. printf("Unidentified board claims %s in eeprom header\n",
  135. board_ti_get_name());
  136. invalid_eeprom:
  137. set_board_info_env_am6(name);
  138. }
  139. static int init_daughtercard_det_gpio(char *gpio_name, struct gpio_desc *desc)
  140. {
  141. int ret;
  142. memset(desc, 0, sizeof(*desc));
  143. ret = dm_gpio_lookup_name(gpio_name, desc);
  144. if (ret < 0)
  145. return ret;
  146. /* Request GPIO, simply re-using the name as label */
  147. ret = dm_gpio_request(desc, gpio_name);
  148. if (ret < 0)
  149. return ret;
  150. return dm_gpio_set_dir_flags(desc, GPIOD_IS_IN);
  151. }
  152. static int probe_daughtercards(void)
  153. {
  154. struct ti_am6_eeprom ep;
  155. struct gpio_desc board_det_gpios[AM65X_EVM_BRD_DET_COUNT];
  156. char mac_addr[DAUGHTER_CARD_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
  157. u8 mac_addr_cnt;
  158. char name_overlays[1024] = { 0 };
  159. int i, j;
  160. int ret;
  161. /*
  162. * Daughter card presence detection signal name to GPIO (via I2C I/O
  163. * expander @ address 0x38) name and EEPROM I2C address mapping.
  164. */
  165. const struct {
  166. char *gpio_name;
  167. u8 i2c_addr;
  168. } slot_map[AM65X_EVM_BRD_DET_COUNT] = {
  169. { "gpio@38_0", 0x52, }, /* AM65X_EVM_APP_BRD_DET */
  170. { "gpio@38_1", 0x55, }, /* AM65X_EVM_LCD_BRD_DET */
  171. { "gpio@38_2", 0x54, }, /* AM65X_EVM_SERDES_BRD_DET */
  172. { "gpio@38_3", 0x53, }, /* AM65X_EVM_HDMI_GPMC_BRD_DET */
  173. };
  174. /* Declaration of daughtercards to probe */
  175. const struct {
  176. u8 slot_index; /* Slot the card is installed */
  177. char *card_name; /* EEPROM-programmed card name */
  178. char *dtbo_name; /* Device tree overlay to apply */
  179. u8 eth_offset; /* ethXaddr MAC address index offset */
  180. } cards[] = {
  181. {
  182. AM65X_EVM_APP_BRD_DET,
  183. "AM6-GPAPPEVM",
  184. "k3-am654-gp.dtbo",
  185. 0,
  186. },
  187. {
  188. AM65X_EVM_APP_BRD_DET,
  189. "AM6-IDKAPPEVM",
  190. "k3-am654-idk.dtbo",
  191. 3,
  192. },
  193. {
  194. AM65X_EVM_SERDES_BRD_DET,
  195. "SER-PCIE2LEVM",
  196. "k3-am654-pcie-usb2.dtbo",
  197. 0,
  198. },
  199. {
  200. AM65X_EVM_SERDES_BRD_DET,
  201. "SER-PCIEUSBEVM",
  202. "k3-am654-pcie-usb3.dtbo",
  203. 0,
  204. },
  205. {
  206. AM65X_EVM_LCD_BRD_DET,
  207. "OLDI-LCD1EVM",
  208. "k3-am654-evm-oldi-lcd1evm.dtbo",
  209. 0,
  210. },
  211. };
  212. /*
  213. * Initialize GPIO used for daughtercard slot presence detection and
  214. * keep the resulting handles in local array for easier access.
  215. */
  216. for (i = 0; i < AM65X_EVM_BRD_DET_COUNT; i++) {
  217. ret = init_daughtercard_det_gpio(slot_map[i].gpio_name,
  218. &board_det_gpios[i]);
  219. if (ret < 0)
  220. return ret;
  221. }
  222. for (i = 0; i < ARRAY_SIZE(cards); i++) {
  223. /* Obtain card-specific slot index and associated I2C address */
  224. u8 slot_index = cards[i].slot_index;
  225. u8 i2c_addr = slot_map[slot_index].i2c_addr;
  226. /*
  227. * The presence detection signal is active-low, hence skip
  228. * over this card slot if anything other than 0 is returned.
  229. */
  230. ret = dm_gpio_get_value(&board_det_gpios[slot_index]);
  231. if (ret < 0)
  232. return ret;
  233. else if (ret)
  234. continue;
  235. /* Get and parse the daughter card EEPROM record */
  236. ret = ti_i2c_eeprom_am6_get(CONFIG_EEPROM_BUS_ADDRESS, i2c_addr,
  237. &ep,
  238. (char **)mac_addr,
  239. DAUGHTER_CARD_NO_OF_MAC_ADDR,
  240. &mac_addr_cnt);
  241. if (ret) {
  242. pr_err("Reading daughtercard EEPROM at 0x%02x failed %d\n",
  243. i2c_addr, ret);
  244. /*
  245. * Even this is pretty serious let's just skip over
  246. * this particular daughtercard, rather than ending
  247. * the probing process altogether.
  248. */
  249. continue;
  250. }
  251. /* Only process the parsed data if we found a match */
  252. if (strncmp(ep.name, cards[i].card_name, sizeof(ep.name)))
  253. continue;
  254. printf("Detected: %s rev %s\n", ep.name, ep.version);
  255. /*
  256. * Populate any MAC addresses from daughtercard into the U-Boot
  257. * environment, starting with a card-specific offset so we can
  258. * have multiple cards contribute to the MAC pool in a well-
  259. * defined manner.
  260. */
  261. for (j = 0; j < mac_addr_cnt; j++) {
  262. if (!is_valid_ethaddr((u8 *)mac_addr[j]))
  263. continue;
  264. eth_env_set_enetaddr_by_index("eth",
  265. cards[i].eth_offset + j,
  266. (uchar *)mac_addr[j]);
  267. }
  268. /* Skip if no overlays are to be added */
  269. if (!strlen(cards[i].dtbo_name))
  270. continue;
  271. /*
  272. * Make sure we are not running out of buffer space by checking
  273. * if we can fit the new overlay, a trailing space to be used
  274. * as a separator, plus the terminating zero.
  275. */
  276. if (strlen(name_overlays) + strlen(cards[i].dtbo_name) + 2 >
  277. sizeof(name_overlays))
  278. return -ENOMEM;
  279. /* Append to our list of overlays */
  280. strcat(name_overlays, cards[i].dtbo_name);
  281. strcat(name_overlays, " ");
  282. }
  283. /* Apply device tree overlay(s) to the U-Boot environment, if any */
  284. if (strlen(name_overlays))
  285. return env_set("name_overlays", name_overlays);
  286. return 0;
  287. }
  288. int board_late_init(void)
  289. {
  290. struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
  291. setup_board_eeprom_env();
  292. /*
  293. * The first MAC address for ethernet a.k.a. ethernet0 comes from
  294. * efuse populated via the am654 gigabit eth switch subsystem driver.
  295. * All the other ones are populated via EEPROM, hence continue with
  296. * an index of 1.
  297. */
  298. board_ti_am6_set_ethaddr(1, ep->mac_addr_cnt);
  299. /* Check for and probe any plugged-in daughtercards */
  300. probe_daughtercards();
  301. return 0;
  302. }