fdt.c 7.4 KB

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