fdt.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. /*
  2. * Copyright 2016 Texas Instruments, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <libfdt.h>
  8. #include <fdt_support.h>
  9. #include <malloc.h>
  10. #include <asm/omap_common.h>
  11. #include <asm/arch-omap5/sys_proto.h>
  12. #ifdef CONFIG_TI_SECURE_DEVICE
  13. /* Give zero values if not already defined */
  14. #ifndef TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ
  15. #define TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ (0)
  16. #endif
  17. #ifndef CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ
  18. #define CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ (0)
  19. #endif
  20. static u32 hs_irq_skip[] = {
  21. 8, /* Secure violation reporting interrupt */
  22. 15, /* One interrupt for SDMA by secure world */
  23. 118 /* One interrupt for Crypto DMA by secure world */
  24. };
  25. static int ft_hs_fixup_crossbar(void *fdt, bd_t *bd)
  26. {
  27. const char *path;
  28. int offs;
  29. int ret;
  30. int len, i, old_cnt, new_cnt;
  31. u32 *temp;
  32. const u32 *p_data;
  33. /*
  34. * Increase the size of the fdt
  35. * so we have some breathing room
  36. */
  37. ret = fdt_increase_size(fdt, 512);
  38. if (ret < 0) {
  39. printf("Could not increase size of device tree: %s\n",
  40. fdt_strerror(ret));
  41. return ret;
  42. }
  43. /* Reserve IRQs that are used/needed by secure world */
  44. path = "/ocp/crossbar";
  45. offs = fdt_path_offset(fdt, path);
  46. if (offs < 0) {
  47. debug("Node %s not found.\n", path);
  48. return 0;
  49. }
  50. /* Get current entries */
  51. p_data = fdt_getprop(fdt, offs, "ti,irqs-skip", &len);
  52. if (p_data)
  53. old_cnt = len / sizeof(u32);
  54. else
  55. old_cnt = 0;
  56. new_cnt = sizeof(hs_irq_skip) /
  57. sizeof(hs_irq_skip[0]);
  58. /* Create new/updated skip list for HS parts */
  59. temp = malloc(sizeof(u32) * (old_cnt + new_cnt));
  60. for (i = 0; i < new_cnt; i++)
  61. temp[i] = cpu_to_fdt32(hs_irq_skip[i]);
  62. for (i = 0; i < old_cnt; i++)
  63. temp[i + new_cnt] = p_data[i];
  64. /* Blow away old data and set new data */
  65. fdt_delprop(fdt, offs, "ti,irqs-skip");
  66. ret = fdt_setprop(fdt, offs, "ti,irqs-skip",
  67. temp,
  68. (old_cnt + new_cnt) * sizeof(u32));
  69. free(temp);
  70. /* Check if the update worked */
  71. if (ret < 0) {
  72. printf("Could not add ti,irqs-skip property to node %s: %s\n",
  73. path, fdt_strerror(ret));
  74. return ret;
  75. }
  76. return 0;
  77. }
  78. #if ((TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ != 0) || \
  79. (CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ != 0))
  80. static int ft_hs_fixup_sram(void *fdt, bd_t *bd)
  81. {
  82. const char *path;
  83. int offs;
  84. int ret;
  85. u32 temp[2];
  86. /*
  87. * Update SRAM reservations on secure devices. The OCMC RAM
  88. * is always reserved for secure use from the start of that
  89. * memory region
  90. */
  91. path = "/ocp/ocmcram@40300000/sram-hs";
  92. offs = fdt_path_offset(fdt, path);
  93. if (offs < 0) {
  94. debug("Node %s not found.\n", path);
  95. return 0;
  96. }
  97. /* relative start offset */
  98. temp[0] = cpu_to_fdt32(0);
  99. /* reservation size */
  100. temp[1] = cpu_to_fdt32(max(TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ,
  101. CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ));
  102. fdt_delprop(fdt, offs, "reg");
  103. ret = fdt_setprop(fdt, offs, "reg", temp, 2 * sizeof(u32));
  104. if (ret < 0) {
  105. printf("Could not add reg property to node %s: %s\n",
  106. path, fdt_strerror(ret));
  107. return ret;
  108. }
  109. return 0;
  110. }
  111. #else
  112. static int ft_hs_fixup_sram(void *fdt, bd_t *bd) { return 0; }
  113. #endif
  114. static void ft_hs_fixups(void *fdt, bd_t *bd)
  115. {
  116. /* Check we are running on an HS/EMU device type */
  117. if (GP_DEVICE != get_device_type()) {
  118. if ((ft_hs_fixup_crossbar(fdt, bd) == 0) &&
  119. (ft_hs_disable_rng(fdt, bd) == 0) &&
  120. (ft_hs_fixup_sram(fdt, bd) == 0) &&
  121. (ft_hs_fixup_dram(fdt, bd) == 0) &&
  122. (ft_hs_add_tee(fdt, bd) == 0))
  123. return;
  124. } else {
  125. printf("ERROR: Incorrect device type (GP) detected!");
  126. }
  127. /* Fixup failed or wrong device type */
  128. hang();
  129. }
  130. #else
  131. static void ft_hs_fixups(void *fdt, bd_t *bd)
  132. {
  133. }
  134. #endif /* #ifdef CONFIG_TI_SECURE_DEVICE */
  135. #if defined(CONFIG_TARGET_DRA7XX_EVM) || defined(CONFIG_TARGET_AM57XX_EVM)
  136. #define OPP_DSP_CLK_NUM 3
  137. #define OPP_IVA_CLK_NUM 2
  138. #define OPP_GPU_CLK_NUM 2
  139. const char *dra7_opp_dsp_clk_names[OPP_DSP_CLK_NUM] = {
  140. "dpll_dsp_ck",
  141. "dpll_dsp_m2_ck",
  142. "dpll_dsp_m3x2_ck",
  143. };
  144. const char *dra7_opp_iva_clk_names[OPP_IVA_CLK_NUM] = {
  145. "dpll_iva_ck",
  146. "dpll_iva_m2_ck",
  147. };
  148. const char *dra7_opp_gpu_clk_names[OPP_GPU_CLK_NUM] = {
  149. "dpll_gpu_ck",
  150. "dpll_gpu_m2_ck",
  151. };
  152. /* DSPEVE voltage domain */
  153. u32 dra7_opp_dsp_clk_rates[NUM_OPPS][OPP_DSP_CLK_NUM] = {
  154. {}, /*OPP_LOW */
  155. {600000000, 600000000, 400000000}, /* OPP_NOM */
  156. {700000000, 700000000, 466666667}, /* OPP_OD */
  157. {750000000, 750000000, 500000000}, /* OPP_HIGH */
  158. };
  159. /* IVA voltage domain */
  160. u32 dra7_opp_iva_clk_rates[NUM_OPPS][OPP_IVA_CLK_NUM] = {
  161. {}, /* OPP_LOW */
  162. {1165000000, 388333334}, /* OPP_NOM */
  163. {860000000, 430000000}, /* OPP_OD */
  164. {1064000000, 532000000}, /* OPP_HIGH */
  165. };
  166. /* GPU voltage domain */
  167. u32 dra7_opp_gpu_clk_rates[NUM_OPPS][OPP_GPU_CLK_NUM] = {
  168. {}, /* OPP_LOW */
  169. {1277000000, 425666667}, /* OPP_NOM */
  170. {1000000000, 500000000}, /* OPP_OD */
  171. {1064000000, 532000000}, /* OPP_HIGH */
  172. };
  173. static int ft_fixup_clocks(void *fdt, const char **names, u32 *rates, int num)
  174. {
  175. int offs, node_offs, ret, i;
  176. uint32_t phandle;
  177. offs = fdt_path_offset(fdt, "/ocp/l4@4a000000/cm_core_aon@5000/clocks");
  178. if (offs < 0) {
  179. debug("Could not find cm_core_aon clocks node path offset : %s\n",
  180. fdt_strerror(offs));
  181. return offs;
  182. }
  183. for (i = 0; i < num; i++) {
  184. node_offs = fdt_subnode_offset(fdt, offs, names[i]);
  185. if (node_offs < 0) {
  186. debug("Could not find clock sub-node %s: %s\n",
  187. names[i], fdt_strerror(node_offs));
  188. return offs;
  189. }
  190. phandle = fdt_get_phandle(fdt, node_offs);
  191. if (!phandle) {
  192. debug("Could not find phandle for clock %s\n",
  193. names[i]);
  194. return -1;
  195. }
  196. ret = fdt_setprop_u32(fdt, node_offs, "assigned-clocks",
  197. phandle);
  198. if (ret < 0) {
  199. debug("Could not add assigned-clocks property to clock node %s: %s\n",
  200. names[i], fdt_strerror(ret));
  201. return ret;
  202. }
  203. ret = fdt_setprop_u32(fdt, node_offs, "assigned-clock-rates",
  204. rates[i]);
  205. if (ret < 0) {
  206. debug("Could not add assigned-clock-rates property to clock node %s: %s\n",
  207. names[i], fdt_strerror(ret));
  208. return ret;
  209. }
  210. }
  211. return 0;
  212. }
  213. static void ft_opp_clock_fixups(void *fdt, bd_t *bd)
  214. {
  215. const char **clk_names;
  216. u32 *clk_rates;
  217. int ret;
  218. if (!is_dra72x() && !is_dra7xx())
  219. return;
  220. /* fixup DSP clocks */
  221. clk_names = dra7_opp_dsp_clk_names;
  222. clk_rates = dra7_opp_dsp_clk_rates[get_voltrail_opp(VOLT_EVE)];
  223. ret = ft_fixup_clocks(fdt, clk_names, clk_rates, OPP_DSP_CLK_NUM);
  224. if (ret) {
  225. printf("ft_fixup_clocks failed for DSP voltage domain: %s\n",
  226. fdt_strerror(ret));
  227. return;
  228. }
  229. /* fixup IVA clocks */
  230. clk_names = dra7_opp_iva_clk_names;
  231. clk_rates = dra7_opp_iva_clk_rates[get_voltrail_opp(VOLT_IVA)];
  232. ret = ft_fixup_clocks(fdt, clk_names, clk_rates, OPP_IVA_CLK_NUM);
  233. if (ret) {
  234. printf("ft_fixup_clocks failed for IVA voltage domain: %s\n",
  235. fdt_strerror(ret));
  236. return;
  237. }
  238. /* fixup GPU clocks */
  239. clk_names = dra7_opp_gpu_clk_names;
  240. clk_rates = dra7_opp_gpu_clk_rates[get_voltrail_opp(VOLT_GPU)];
  241. ret = ft_fixup_clocks(fdt, clk_names, clk_rates, OPP_GPU_CLK_NUM);
  242. if (ret) {
  243. printf("ft_fixup_clocks failed for GPU voltage domain: %s\n",
  244. fdt_strerror(ret));
  245. return;
  246. }
  247. }
  248. #else
  249. static void ft_opp_clock_fixups(void *fdt, bd_t *bd) { }
  250. #endif /* CONFIG_TARGET_DRA7XX_EVM || CONFIG_TARGET_AM57XX_EVM */
  251. /*
  252. * Place for general cpu/SoC FDT fixups. Board specific
  253. * fixups should remain in the board files which is where
  254. * this function should be called from.
  255. */
  256. void ft_cpu_setup(void *fdt, bd_t *bd)
  257. {
  258. ft_hs_fixups(fdt, bd);
  259. ft_opp_clock_fixups(fdt, bd);
  260. }
  261. int ft_dra7x_enable_nand(void *blob, bd_t *bd)
  262. {
  263. const void *model;
  264. char *path;
  265. int ret, offs;
  266. path = "/";
  267. offs = fdt_path_offset(blob, path);
  268. if (offs < 0)
  269. goto fdt_error;
  270. model = fdt_getprop(blob, offs, "model", NULL);
  271. if (!model)
  272. goto fdt_error;
  273. /* Remove additional nodes specific to DRA71 LCD DT */
  274. if (!strcmp(model, "TI DRA71 EVM-LCD-AUO-Display")) {
  275. /* Prevent I2C GPIO expander from causing the
  276. * on board mux to reenable vout3 and disable
  277. * the required NAND pins.
  278. */
  279. path = "/ocp/i2c@48070000/gpio@21/p0";
  280. offs = fdt_path_offset(blob, path);
  281. if (offs < 0)
  282. goto fdt_error;
  283. ret = fdt_delprop(blob, offs, "gpio-hog");
  284. if (ret < 0)
  285. goto fdt_error;
  286. ret = fdt_delprop(blob, offs, "gpios");
  287. if (ret < 0)
  288. goto fdt_error;
  289. path = "/ocp/i2c@48070000/gpio@21/p7";
  290. offs = fdt_path_offset(blob, path);
  291. if (offs < 0)
  292. goto fdt_error;
  293. ret = fdt_delprop(blob, offs, "gpio-hog");
  294. if (ret < 0)
  295. goto fdt_error;
  296. ret = fdt_delprop(blob, offs, "gpios");
  297. if (ret < 0)
  298. goto fdt_error;
  299. /* Disable Touchscreen */
  300. path = "/ocp/i2c@48070000/goodix-gt9271@14";
  301. offs = fdt_path_offset(blob, path);
  302. if (offs < 0)
  303. goto fdt_error;
  304. ret = fdt_setprop_string(blob, offs, "status", "disabled");
  305. if (ret < 0)
  306. goto fdt_error;
  307. /* Disable LCD node */
  308. path = "/display";
  309. offs = fdt_path_offset(blob, path);
  310. if (offs < 0)
  311. goto fdt_error;
  312. ret = fdt_setprop_string(blob, offs, "status", "disabled");
  313. if (ret < 0)
  314. goto fdt_error;
  315. /* Disable Backlight node */
  316. path = "/backlight";
  317. offs = fdt_path_offset(blob, path);
  318. if (offs < 0)
  319. goto fdt_error;
  320. ret = fdt_setprop_string(blob, offs, "status", "disabled");
  321. if (ret < 0)
  322. goto fdt_error;
  323. }
  324. path = "/ocp/gpmc";
  325. offs = fdt_path_offset(blob, path);
  326. if (offs < 0)
  327. goto fdt_error;
  328. ret = fdt_setprop_string(blob, offs, "status", "okay");
  329. if (ret < 0)
  330. goto fdt_error;
  331. return 0;
  332. fdt_error:
  333. return -1;
  334. }