1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2016 Texas Instruments, Inc.
9 #include <linux/libfdt.h>
10 #include <fdt_support.h>
13 #include <asm/omap_common.h>
14 #include <asm/arch-omap5/sys_proto.h>
16 #ifdef CONFIG_TI_SECURE_DEVICE
18 /* Give zero values if not already defined */
19 #ifndef TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ
20 #define TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ (0)
22 #ifndef CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ
23 #define CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ (0)
26 static u32 hs_irq_skip[] = {
27 8, /* Secure violation reporting interrupt */
28 15, /* One interrupt for SDMA by secure world */
29 118 /* One interrupt for Crypto DMA by secure world */
32 static int ft_hs_fixup_crossbar(void *fdt, bd_t *bd)
37 int len, i, old_cnt, new_cnt;
42 * Increase the size of the fdt
43 * so we have some breathing room
45 ret = fdt_increase_size(fdt, 512);
47 printf("Could not increase size of device tree: %s\n",
52 /* Reserve IRQs that are used/needed by secure world */
53 path = "/ocp/crossbar";
54 offs = fdt_path_offset(fdt, path);
56 debug("Node %s not found.\n", path);
60 /* Get current entries */
61 p_data = fdt_getprop(fdt, offs, "ti,irqs-skip", &len);
63 old_cnt = len / sizeof(u32);
67 new_cnt = sizeof(hs_irq_skip) /
68 sizeof(hs_irq_skip[0]);
70 /* Create new/updated skip list for HS parts */
71 temp = malloc(sizeof(u32) * (old_cnt + new_cnt));
72 for (i = 0; i < new_cnt; i++)
73 temp[i] = cpu_to_fdt32(hs_irq_skip[i]);
74 for (i = 0; i < old_cnt; i++)
75 temp[i + new_cnt] = p_data[i];
77 /* Blow away old data and set new data */
78 fdt_delprop(fdt, offs, "ti,irqs-skip");
79 ret = fdt_setprop(fdt, offs, "ti,irqs-skip",
81 (old_cnt + new_cnt) * sizeof(u32));
84 /* Check if the update worked */
86 printf("Could not add ti,irqs-skip property to node %s: %s\n",
87 path, fdt_strerror(ret));
94 #if ((TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ != 0) || \
95 (CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ != 0))
96 static int ft_hs_fixup_sram(void *fdt, bd_t *bd)
104 * Update SRAM reservations on secure devices. The OCMC RAM
105 * is always reserved for secure use from the start of that
108 path = "/ocp/ocmcram@40300000/sram-hs";
109 offs = fdt_path_offset(fdt, path);
111 debug("Node %s not found.\n", path);
115 /* relative start offset */
116 temp[0] = cpu_to_fdt32(0);
117 /* reservation size */
118 temp[1] = cpu_to_fdt32(max(TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ,
119 CONFIG_SECURE_RUNTIME_RESV_SRAM_SZ));
120 fdt_delprop(fdt, offs, "reg");
121 ret = fdt_setprop(fdt, offs, "reg", temp, 2 * sizeof(u32));
123 printf("Could not add reg property to node %s: %s\n",
124 path, fdt_strerror(ret));
131 static int ft_hs_fixup_sram(void *fdt, bd_t *bd) { return 0; }
134 static void ft_hs_fixups(void *fdt, bd_t *bd)
136 /* Check we are running on an HS/EMU device type */
137 if (GP_DEVICE != get_device_type()) {
138 if ((ft_hs_fixup_crossbar(fdt, bd) == 0) &&
139 (ft_hs_disable_rng(fdt, bd) == 0) &&
140 (ft_hs_fixup_sram(fdt, bd) == 0) &&
141 (ft_hs_fixup_dram(fdt, bd) == 0) &&
142 (ft_hs_add_tee(fdt, bd) == 0))
145 printf("ERROR: Incorrect device type (GP) detected!");
147 /* Fixup failed or wrong device type */
151 static void ft_hs_fixups(void *fdt, bd_t *bd)
154 #endif /* #ifdef CONFIG_TI_SECURE_DEVICE */
156 #if defined(CONFIG_TARGET_DRA7XX_EVM) || defined(CONFIG_TARGET_AM57XX_EVM)
157 #define OPP_DSP_CLK_NUM 3
158 #define OPP_IVA_CLK_NUM 2
159 #define OPP_GPU_CLK_NUM 2
161 const char *dra7_opp_dsp_clk_names[OPP_DSP_CLK_NUM] = {
167 const char *dra7_opp_iva_clk_names[OPP_IVA_CLK_NUM] = {
172 const char *dra7_opp_gpu_clk_names[OPP_GPU_CLK_NUM] = {
177 /* DSPEVE voltage domain */
178 u32 dra7_opp_dsp_clk_rates[NUM_OPPS][OPP_DSP_CLK_NUM] = {
180 {600000000, 600000000, 400000000}, /* OPP_NOM */
181 {700000000, 700000000, 466666667}, /* OPP_OD */
182 {750000000, 750000000, 500000000}, /* OPP_HIGH */
185 /* DSP clock rates on DRA76x ACD-package based SoCs */
186 u32 dra76_opp_dsp_clk_rates[NUM_OPPS][OPP_DSP_CLK_NUM] = {
188 {600000000, 600000000, 400000000}, /* OPP_NOM */
189 {700000000, 700000000, 466666667}, /* OPP_OD */
190 {850000000, 850000000, 566666667}, /* OPP_HIGH */
193 /* IVA voltage domain */
194 u32 dra7_opp_iva_clk_rates[NUM_OPPS][OPP_IVA_CLK_NUM] = {
196 {1165000000, 388333334}, /* OPP_NOM */
197 {860000000, 430000000}, /* OPP_OD */
198 {1064000000, 532000000}, /* OPP_HIGH */
201 /* GPU voltage domain */
202 u32 dra7_opp_gpu_clk_rates[NUM_OPPS][OPP_GPU_CLK_NUM] = {
204 {1277000000, 425666667}, /* OPP_NOM */
205 {1000000000, 500000000}, /* OPP_OD */
206 {1064000000, 532000000}, /* OPP_HIGH */
209 static int ft_fixup_clocks(void *fdt, const char **names, u32 *rates, int num)
211 int offs, node_offs, ret, i;
214 offs = fdt_path_offset(fdt, "/ocp/interconnect@4a000000/segment@0/target-module@5000/cm_core_aon@0/clocks");
216 offs = fdt_path_offset(fdt, "/ocp/l4@4a000000/cm_core_aon@5000/clocks");
218 debug("Could not find cm_core_aon clocks node path offset : %s\n",
223 for (i = 0; i < num; i++) {
224 node_offs = fdt_subnode_offset(fdt, offs, names[i]);
226 debug("Could not find clock sub-node %s: %s\n",
227 names[i], fdt_strerror(node_offs));
231 phandle = fdt_get_phandle(fdt, node_offs);
233 debug("Could not find phandle for clock %s\n",
238 ret = fdt_setprop_u32(fdt, node_offs, "assigned-clocks",
241 debug("Could not add assigned-clocks property to clock node %s: %s\n",
242 names[i], fdt_strerror(ret));
246 ret = fdt_setprop_u32(fdt, node_offs, "assigned-clock-rates",
249 debug("Could not add assigned-clock-rates property to clock node %s: %s\n",
250 names[i], fdt_strerror(ret));
258 static void ft_opp_clock_fixups(void *fdt, bd_t *bd)
260 const char **clk_names;
264 if (!is_dra72x() && !is_dra7xx())
267 /* fixup DSP clocks */
268 clk_names = dra7_opp_dsp_clk_names;
269 clk_rates = dra7_opp_dsp_clk_rates[get_voltrail_opp(VOLT_EVE)];
270 /* adjust for higher OPP_HIGH clock rate on DRA76xP/DRA77xP SoCs */
272 clk_rates = dra76_opp_dsp_clk_rates[get_voltrail_opp(VOLT_EVE)];
274 ret = ft_fixup_clocks(fdt, clk_names, clk_rates, OPP_DSP_CLK_NUM);
276 printf("ft_fixup_clocks failed for DSP voltage domain: %s\n",
281 /* fixup IVA clocks */
282 clk_names = dra7_opp_iva_clk_names;
283 clk_rates = dra7_opp_iva_clk_rates[get_voltrail_opp(VOLT_IVA)];
284 ret = ft_fixup_clocks(fdt, clk_names, clk_rates, OPP_IVA_CLK_NUM);
286 printf("ft_fixup_clocks failed for IVA voltage domain: %s\n",
291 /* fixup GPU clocks */
292 clk_names = dra7_opp_gpu_clk_names;
293 clk_rates = dra7_opp_gpu_clk_rates[get_voltrail_opp(VOLT_GPU)];
294 ret = ft_fixup_clocks(fdt, clk_names, clk_rates, OPP_GPU_CLK_NUM);
296 printf("ft_fixup_clocks failed for GPU voltage domain: %s\n",
302 static void ft_opp_clock_fixups(void *fdt, bd_t *bd) { }
303 #endif /* CONFIG_TARGET_DRA7XX_EVM || CONFIG_TARGET_AM57XX_EVM */
306 * Place for general cpu/SoC FDT fixups. Board specific
307 * fixups should remain in the board files which is where
308 * this function should be called from.
310 void ft_cpu_setup(void *fdt, bd_t *bd)
312 ft_hs_fixups(fdt, bd);
313 ft_opp_clock_fixups(fdt, bd);