1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2016 Texas Instruments, Inc.
7 #include <linux/libfdt.h>
8 #include <fdt_support.h>
11 #include <asm/omap_common.h>
12 #include <asm/arch-omap5/sys_proto.h>
14 #ifdef CONFIG_TI_SECURE_DEVICE
16 /* Give zero values if not already defined */
17 #ifndef TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ
18 #define TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ (0)
20 #ifndef CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ
21 #define CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ (0)
24 static u32 hs_irq_skip[] = {
25 8, /* Secure violation reporting interrupt */
26 15, /* One interrupt for SDMA by secure world */
27 118 /* One interrupt for Crypto DMA by secure world */
30 static int ft_hs_fixup_crossbar(void *fdt, bd_t *bd)
35 int len, i, old_cnt, new_cnt;
40 * Increase the size of the fdt
41 * so we have some breathing room
43 ret = fdt_increase_size(fdt, 512);
45 printf("Could not increase size of device tree: %s\n",
50 /* Reserve IRQs that are used/needed by secure world */
51 path = "/ocp/crossbar";
52 offs = fdt_path_offset(fdt, path);
54 debug("Node %s not found.\n", path);
58 /* Get current entries */
59 p_data = fdt_getprop(fdt, offs, "ti,irqs-skip", &len);
61 old_cnt = len / sizeof(u32);
65 new_cnt = sizeof(hs_irq_skip) /
66 sizeof(hs_irq_skip[0]);
68 /* Create new/updated skip list for HS parts */
69 temp = malloc(sizeof(u32) * (old_cnt + new_cnt));
70 for (i = 0; i < new_cnt; i++)
71 temp[i] = cpu_to_fdt32(hs_irq_skip[i]);
72 for (i = 0; i < old_cnt; i++)
73 temp[i + new_cnt] = p_data[i];
75 /* Blow away old data and set new data */
76 fdt_delprop(fdt, offs, "ti,irqs-skip");
77 ret = fdt_setprop(fdt, offs, "ti,irqs-skip",
79 (old_cnt + new_cnt) * sizeof(u32));
82 /* Check if the update worked */
84 printf("Could not add ti,irqs-skip property to node %s: %s\n",
85 path, fdt_strerror(ret));
92 #if ((TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ != 0) || \
93 (CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ != 0))
94 static int ft_hs_fixup_sram(void *fdt, bd_t *bd)
102 * Update SRAM reservations on secure devices. The OCMC RAM
103 * is always reserved for secure use from the start of that
106 path = "/ocp/ocmcram@40300000/sram-hs";
107 offs = fdt_path_offset(fdt, path);
109 debug("Node %s not found.\n", path);
113 /* relative start offset */
114 temp[0] = cpu_to_fdt32(0);
115 /* reservation size */
116 temp[1] = cpu_to_fdt32(max(TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ,
117 CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ));
118 fdt_delprop(fdt, offs, "reg");
119 ret = fdt_setprop(fdt, offs, "reg", temp, 2 * sizeof(u32));
121 printf("Could not add reg property to node %s: %s\n",
122 path, fdt_strerror(ret));
129 static int ft_hs_fixup_sram(void *fdt, bd_t *bd) { return 0; }
132 static void ft_hs_fixups(void *fdt, bd_t *bd)
134 /* Check we are running on an HS/EMU device type */
135 if (GP_DEVICE != get_device_type()) {
136 if ((ft_hs_fixup_crossbar(fdt, bd) == 0) &&
137 (ft_hs_disable_rng(fdt, bd) == 0) &&
138 (ft_hs_fixup_sram(fdt, bd) == 0) &&
139 (ft_hs_fixup_dram(fdt, bd) == 0) &&
140 (ft_hs_add_tee(fdt, bd) == 0))
143 printf("ERROR: Incorrect device type (GP) detected!");
145 /* Fixup failed or wrong device type */
149 static void ft_hs_fixups(void *fdt, bd_t *bd)
152 #endif /* #ifdef CONFIG_TI_SECURE_DEVICE */
154 #if defined(CONFIG_TARGET_DRA7XX_EVM) || defined(CONFIG_TARGET_AM57XX_EVM)
155 #define OPP_DSP_CLK_NUM 3
156 #define OPP_IVA_CLK_NUM 2
157 #define OPP_GPU_CLK_NUM 2
159 const char *dra7_opp_dsp_clk_names[OPP_DSP_CLK_NUM] = {
165 const char *dra7_opp_iva_clk_names[OPP_IVA_CLK_NUM] = {
170 const char *dra7_opp_gpu_clk_names[OPP_GPU_CLK_NUM] = {
175 /* DSPEVE voltage domain */
176 u32 dra7_opp_dsp_clk_rates[NUM_OPPS][OPP_DSP_CLK_NUM] = {
178 {600000000, 600000000, 400000000}, /* OPP_NOM */
179 {700000000, 700000000, 466666667}, /* OPP_OD */
180 {750000000, 750000000, 500000000}, /* OPP_HIGH */
183 /* IVA voltage domain */
184 u32 dra7_opp_iva_clk_rates[NUM_OPPS][OPP_IVA_CLK_NUM] = {
186 {1165000000, 388333334}, /* OPP_NOM */
187 {860000000, 430000000}, /* OPP_OD */
188 {1064000000, 532000000}, /* OPP_HIGH */
191 /* GPU voltage domain */
192 u32 dra7_opp_gpu_clk_rates[NUM_OPPS][OPP_GPU_CLK_NUM] = {
194 {1277000000, 425666667}, /* OPP_NOM */
195 {1000000000, 500000000}, /* OPP_OD */
196 {1064000000, 532000000}, /* OPP_HIGH */
199 static int ft_fixup_clocks(void *fdt, const char **names, u32 *rates, int num)
201 int offs, node_offs, ret, i;
204 offs = fdt_path_offset(fdt, "/ocp/l4@4a000000/cm_core_aon@5000/clocks");
206 debug("Could not find cm_core_aon clocks node path offset : %s\n",
211 for (i = 0; i < num; i++) {
212 node_offs = fdt_subnode_offset(fdt, offs, names[i]);
214 debug("Could not find clock sub-node %s: %s\n",
215 names[i], fdt_strerror(node_offs));
219 phandle = fdt_get_phandle(fdt, node_offs);
221 debug("Could not find phandle for clock %s\n",
226 ret = fdt_setprop_u32(fdt, node_offs, "assigned-clocks",
229 debug("Could not add assigned-clocks property to clock node %s: %s\n",
230 names[i], fdt_strerror(ret));
234 ret = fdt_setprop_u32(fdt, node_offs, "assigned-clock-rates",
237 debug("Could not add assigned-clock-rates property to clock node %s: %s\n",
238 names[i], fdt_strerror(ret));
246 static void ft_opp_clock_fixups(void *fdt, bd_t *bd)
248 const char **clk_names;
252 if (!is_dra72x() && !is_dra7xx())
255 /* fixup DSP clocks */
256 clk_names = dra7_opp_dsp_clk_names;
257 clk_rates = dra7_opp_dsp_clk_rates[get_voltrail_opp(VOLT_EVE)];
258 ret = ft_fixup_clocks(fdt, clk_names, clk_rates, OPP_DSP_CLK_NUM);
260 printf("ft_fixup_clocks failed for DSP voltage domain: %s\n",
265 /* fixup IVA clocks */
266 clk_names = dra7_opp_iva_clk_names;
267 clk_rates = dra7_opp_iva_clk_rates[get_voltrail_opp(VOLT_IVA)];
268 ret = ft_fixup_clocks(fdt, clk_names, clk_rates, OPP_IVA_CLK_NUM);
270 printf("ft_fixup_clocks failed for IVA voltage domain: %s\n",
275 /* fixup GPU clocks */
276 clk_names = dra7_opp_gpu_clk_names;
277 clk_rates = dra7_opp_gpu_clk_rates[get_voltrail_opp(VOLT_GPU)];
278 ret = ft_fixup_clocks(fdt, clk_names, clk_rates, OPP_GPU_CLK_NUM);
280 printf("ft_fixup_clocks failed for GPU voltage domain: %s\n",
286 static void ft_opp_clock_fixups(void *fdt, bd_t *bd) { }
287 #endif /* CONFIG_TARGET_DRA7XX_EVM || CONFIG_TARGET_AM57XX_EVM */
290 * Place for general cpu/SoC FDT fixups. Board specific
291 * fixups should remain in the board files which is where
292 * this function should be called from.
294 void ft_cpu_setup(void *fdt, bd_t *bd)
296 ft_hs_fixups(fdt, bd);
297 ft_opp_clock_fixups(fdt, bd);