evm.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Board specific initialization for J721E EVM
  4. *
  5. * Copyright (C) 2018-2019 Texas Instruments Incorporated - http://www.ti.com/
  6. * Lokesh Vutla <lokeshvutla@ti.com>
  7. *
  8. */
  9. #include <common.h>
  10. #include <env.h>
  11. #include <fdt_support.h>
  12. #include <image.h>
  13. #include <init.h>
  14. #include <log.h>
  15. #include <net.h>
  16. #include <asm/arch/sys_proto.h>
  17. #include <asm/arch/hardware.h>
  18. #include <asm/gpio.h>
  19. #include <asm/io.h>
  20. #include <spl.h>
  21. #include <asm/arch/sys_proto.h>
  22. #include <dm.h>
  23. #include <dm/uclass-internal.h>
  24. #include "../common/board_detect.h"
  25. #define board_is_j721e_som() (board_ti_k3_is("J721EX-PM1-SOM") || \
  26. board_ti_k3_is("J721EX-PM2-SOM"))
  27. #define board_is_j7200_som() board_ti_k3_is("J7200X-PM1-SOM")
  28. /* Max number of MAC addresses that are parsed/processed per daughter card */
  29. #define DAUGHTER_CARD_NO_OF_MAC_ADDR 8
  30. DECLARE_GLOBAL_DATA_PTR;
  31. int board_init(void)
  32. {
  33. return 0;
  34. }
  35. int dram_init(void)
  36. {
  37. #ifdef CONFIG_PHYS_64BIT
  38. gd->ram_size = 0x100000000;
  39. #else
  40. gd->ram_size = 0x80000000;
  41. #endif
  42. return 0;
  43. }
  44. ulong board_get_usable_ram_top(ulong total_size)
  45. {
  46. #ifdef CONFIG_PHYS_64BIT
  47. /* Limit RAM used by U-Boot to the DDR low region */
  48. if (gd->ram_top > 0x100000000)
  49. return 0x100000000;
  50. #endif
  51. return gd->ram_top;
  52. }
  53. int dram_init_banksize(void)
  54. {
  55. /* Bank 0 declares the memory available in the DDR low region */
  56. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  57. gd->bd->bi_dram[0].size = 0x80000000;
  58. gd->ram_size = 0x80000000;
  59. #ifdef CONFIG_PHYS_64BIT
  60. /* Bank 1 declares the memory available in the DDR high region */
  61. gd->bd->bi_dram[1].start = CONFIG_SYS_SDRAM_BASE1;
  62. gd->bd->bi_dram[1].size = 0x80000000;
  63. gd->ram_size = 0x100000000;
  64. #endif
  65. return 0;
  66. }
  67. #ifdef CONFIG_SPL_LOAD_FIT
  68. int board_fit_config_name_match(const char *name)
  69. {
  70. if (!strcmp(name, "k3-j721e-common-proc-board"))
  71. return 0;
  72. return -1;
  73. }
  74. #endif
  75. #if CONFIG_IS_ENABLED(DM_GPIO) && CONFIG_IS_ENABLED(OF_LIBFDT)
  76. /* Returns 1, if onboard mux is set to hyperflash */
  77. static void __maybe_unused detect_enable_hyperflash(void *blob)
  78. {
  79. struct gpio_desc desc = {0};
  80. if (dm_gpio_lookup_name("6", &desc))
  81. return;
  82. if (dm_gpio_request(&desc, "6"))
  83. return;
  84. if (dm_gpio_set_dir_flags(&desc, GPIOD_IS_IN))
  85. return;
  86. if (dm_gpio_get_value(&desc)) {
  87. int offset;
  88. do_fixup_by_compat(blob, "ti,am654-hbmc", "status",
  89. "okay", sizeof("okay"), 0);
  90. offset = fdt_node_offset_by_compatible(blob, -1,
  91. "ti,j721e-ospi");
  92. fdt_setprop(blob, offset, "status", "disabled",
  93. sizeof("disabled"));
  94. }
  95. }
  96. #endif
  97. #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_TARGET_J7200_A72_EVM)
  98. void spl_perform_fixups(struct spl_image_info *spl_image)
  99. {
  100. detect_enable_hyperflash(spl_image->fdt_addr);
  101. }
  102. #endif
  103. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  104. int ft_board_setup(void *blob, struct bd_info *bd)
  105. {
  106. int ret;
  107. ret = fdt_fixup_msmc_ram(blob, "/bus@100000", "sram@70000000");
  108. if (ret < 0)
  109. ret = fdt_fixup_msmc_ram(blob, "/interconnect@100000",
  110. "sram@70000000");
  111. if (ret)
  112. printf("%s: fixing up msmc ram failed %d\n", __func__, ret);
  113. detect_enable_hyperflash(blob);
  114. return ret;
  115. }
  116. #endif
  117. #ifdef CONFIG_TI_I2C_BOARD_DETECT
  118. int do_board_detect(void)
  119. {
  120. int ret;
  121. ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
  122. CONFIG_EEPROM_CHIP_ADDRESS);
  123. if (ret)
  124. pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
  125. CONFIG_EEPROM_CHIP_ADDRESS, ret);
  126. return ret;
  127. }
  128. int checkboard(void)
  129. {
  130. struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
  131. if (do_board_detect())
  132. /* EEPROM not populated */
  133. printf("Board: %s rev %s\n", "J721EX-PM1-SOM", "E2");
  134. else
  135. printf("Board: %s rev %s\n", ep->name, ep->version);
  136. return 0;
  137. }
  138. static void setup_board_eeprom_env(void)
  139. {
  140. char *name = "j721e";
  141. if (do_board_detect())
  142. goto invalid_eeprom;
  143. if (board_is_j721e_som())
  144. name = "j721e";
  145. else if (board_is_j7200_som())
  146. name = "j7200";
  147. else
  148. printf("Unidentified board claims %s in eeprom header\n",
  149. board_ti_get_name());
  150. invalid_eeprom:
  151. set_board_info_env_am6(name);
  152. }
  153. static void setup_serial(void)
  154. {
  155. struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
  156. unsigned long board_serial;
  157. char *endp;
  158. char serial_string[17] = { 0 };
  159. if (env_get("serial#"))
  160. return;
  161. board_serial = simple_strtoul(ep->serial, &endp, 16);
  162. if (*endp != '\0') {
  163. pr_err("Error: Can't set serial# to %s\n", ep->serial);
  164. return;
  165. }
  166. snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
  167. env_set("serial#", serial_string);
  168. }
  169. /*
  170. * Declaration of daughtercards to probe. Note that when adding more
  171. * cards they should be grouped by the 'i2c_addr' field to allow for a
  172. * more efficient probing process.
  173. */
  174. static const struct {
  175. u8 i2c_addr; /* I2C address of card EEPROM */
  176. char *card_name; /* EEPROM-programmed card name */
  177. char *dtbo_name; /* Device tree overlay to apply */
  178. u8 eth_offset; /* ethXaddr MAC address index offset */
  179. } ext_cards[] = {
  180. {
  181. 0x51,
  182. "J7X-BASE-CPB",
  183. "", /* No dtbo for this board */
  184. 0,
  185. },
  186. {
  187. 0x52,
  188. "J7X-INFOTAN-EXP",
  189. "", /* No dtbo for this board */
  190. 0,
  191. },
  192. {
  193. 0x52,
  194. "J7X-GESI-EXP",
  195. "", /* No dtbo for this board */
  196. 5, /* Start populating from eth5addr */
  197. },
  198. {
  199. 0x54,
  200. "J7X-VSC8514-ETH",
  201. "", /* No dtbo for this board */
  202. 1, /* Start populating from eth1addr */
  203. },
  204. };
  205. static bool daughter_card_detect_flags[ARRAY_SIZE(ext_cards)];
  206. const char *board_fit_get_additionnal_images(int index, const char *type)
  207. {
  208. int i, j;
  209. if (strcmp(type, FIT_FDT_PROP))
  210. return NULL;
  211. j = 0;
  212. for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
  213. if (daughter_card_detect_flags[i]) {
  214. if (j == index) {
  215. /*
  216. * Return dtbo name only if populated,
  217. * otherwise stop parsing here.
  218. */
  219. if (strlen(ext_cards[i].dtbo_name))
  220. return ext_cards[i].dtbo_name;
  221. else
  222. return NULL;
  223. };
  224. j++;
  225. }
  226. }
  227. return NULL;
  228. }
  229. static int probe_daughtercards(void)
  230. {
  231. char mac_addr[DAUGHTER_CARD_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
  232. bool eeprom_read_success;
  233. struct ti_am6_eeprom ep;
  234. u8 previous_i2c_addr;
  235. u8 mac_addr_cnt;
  236. int i;
  237. int ret;
  238. /* Mark previous I2C address variable as not populated */
  239. previous_i2c_addr = 0xff;
  240. /* No EEPROM data was read yet */
  241. eeprom_read_success = false;
  242. /* Iterate through list of daughtercards */
  243. for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
  244. /* Obtain card-specific I2C address */
  245. u8 i2c_addr = ext_cards[i].i2c_addr;
  246. /* Read card EEPROM if not already read previously */
  247. if (i2c_addr != previous_i2c_addr) {
  248. /* Store I2C address so we can avoid reading twice */
  249. previous_i2c_addr = i2c_addr;
  250. /* Get and parse the daughter card EEPROM record */
  251. ret = ti_i2c_eeprom_am6_get(CONFIG_EEPROM_BUS_ADDRESS,
  252. i2c_addr,
  253. &ep,
  254. (char **)mac_addr,
  255. DAUGHTER_CARD_NO_OF_MAC_ADDR,
  256. &mac_addr_cnt);
  257. if (ret) {
  258. debug("%s: No daughtercard EEPROM at 0x%02x found %d\n",
  259. __func__, i2c_addr, ret);
  260. eeprom_read_success = false;
  261. /* Skip to the next daughtercard to probe */
  262. continue;
  263. }
  264. /* EEPROM read successful, okay to further process. */
  265. eeprom_read_success = true;
  266. }
  267. /* Only continue processing if EEPROM data was read */
  268. if (!eeprom_read_success)
  269. continue;
  270. /* Only process the parsed data if we found a match */
  271. if (strncmp(ep.name, ext_cards[i].card_name, sizeof(ep.name)))
  272. continue;
  273. printf("Detected: %s rev %s\n", ep.name, ep.version);
  274. daughter_card_detect_flags[i] = true;
  275. #ifndef CONFIG_SPL_BUILD
  276. int j;
  277. /*
  278. * Populate any MAC addresses from daughtercard into the U-Boot
  279. * environment, starting with a card-specific offset so we can
  280. * have multiple ext_cards contribute to the MAC pool in a well-
  281. * defined manner.
  282. */
  283. for (j = 0; j < mac_addr_cnt; j++) {
  284. if (!is_valid_ethaddr((u8 *)mac_addr[j]))
  285. continue;
  286. eth_env_set_enetaddr_by_index("eth",
  287. ext_cards[i].eth_offset + j,
  288. (uchar *)mac_addr[j]);
  289. }
  290. #endif
  291. }
  292. #ifndef CONFIG_SPL_BUILD
  293. char name_overlays[1024] = { 0 };
  294. for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
  295. if (!daughter_card_detect_flags[i])
  296. continue;
  297. /* Skip if no overlays are to be added */
  298. if (!strlen(ext_cards[i].dtbo_name))
  299. continue;
  300. /*
  301. * Make sure we are not running out of buffer space by checking
  302. * if we can fit the new overlay, a trailing space to be used
  303. * as a separator, plus the terminating zero.
  304. */
  305. if (strlen(name_overlays) + strlen(ext_cards[i].dtbo_name) + 2 >
  306. sizeof(name_overlays))
  307. return -ENOMEM;
  308. /* Append to our list of overlays */
  309. strcat(name_overlays, ext_cards[i].dtbo_name);
  310. strcat(name_overlays, " ");
  311. }
  312. /* Apply device tree overlay(s) to the U-Boot environment, if any */
  313. if (strlen(name_overlays))
  314. return env_set("name_overlays", name_overlays);
  315. #endif
  316. return 0;
  317. }
  318. #endif
  319. int board_late_init(void)
  320. {
  321. if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) {
  322. setup_board_eeprom_env();
  323. setup_serial();
  324. /* Check for and probe any plugged-in daughtercards */
  325. probe_daughtercards();
  326. }
  327. return 0;
  328. }
  329. void spl_board_init(void)
  330. {
  331. #if defined(CONFIG_ESM_K3) || defined(CONFIG_ESM_PMIC)
  332. struct udevice *dev;
  333. int ret;
  334. #endif
  335. if ((IS_ENABLED(CONFIG_TARGET_J721E_A72_EVM) ||
  336. IS_ENABLED(CONFIG_TARGET_J7200_A72_EVM)) &&
  337. IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT))
  338. probe_daughtercards();
  339. #ifdef CONFIG_ESM_K3
  340. if (board_ti_k3_is("J721EX-PM2-SOM")) {
  341. ret = uclass_get_device_by_driver(UCLASS_MISC,
  342. DM_GET_DRIVER(k3_esm), &dev);
  343. if (ret)
  344. printf("ESM init failed: %d\n", ret);
  345. }
  346. #endif
  347. #ifdef CONFIG_ESM_PMIC
  348. if (board_ti_k3_is("J721EX-PM2-SOM")) {
  349. ret = uclass_get_device_by_driver(UCLASS_MISC,
  350. DM_GET_DRIVER(pmic_esm),
  351. &dev);
  352. if (ret)
  353. printf("ESM PMIC init failed: %d\n", ret);
  354. }
  355. #endif
  356. }