evm.c 10 KB

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