1 // SPDX-License-Identifier: GPL-2.0+
3 * K3: Common Architecture initialization
5 * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
6 * Lokesh Vutla <lokeshvutla@ti.com>
13 #include <remoteproc.h>
14 #include <linux/soc/ti/ti_sci_protocol.h>
15 #include <fdt_support.h>
16 #include <asm/arch/sys_proto.h>
17 #include <asm/hardware.h>
20 struct ti_sci_handle *get_ti_sci_handle(void)
25 ret = uclass_get_device_by_driver(UCLASS_FIRMWARE,
26 DM_GET_DRIVER(ti_sci), &dev);
28 panic("Failed to get SYSFW (%d)\n", ret);
30 return (struct ti_sci_handle *)ti_sci_get_handle_from_sysfw(dev);
33 DECLARE_GLOBAL_DATA_PTR;
35 #ifdef CONFIG_K3_EARLY_CONS
36 int early_console_init(void)
41 gd->baudrate = CONFIG_BAUDRATE;
43 ret = uclass_get_device_by_seq(UCLASS_SERIAL, CONFIG_K3_EARLY_CONS_IDX,
46 printf("Error getting serial dev for early console! (%d)\n",
51 gd->cur_serial_dev = dev;
52 gd->flags |= GD_FLG_SERIAL_READY;
59 #ifdef CONFIG_SYS_K3_SPL_ATF
60 void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
62 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
65 /* Release all the exclusive devices held by SPL before starting ATF */
66 ti_sci->ops.dev_ops.release_exclusive_devices(ti_sci);
69 * It is assumed that remoteproc device 1 is the corresponding
70 * Cortex-A core which runs ATF. Make sure DT reflects the same.
72 ret = rproc_dev_init(1);
74 panic("%s: ATF failed to initialize on rproc (%d)\n", __func__,
77 ret = rproc_load(1, spl_image->entry_point, 0x200);
79 panic("%s: ATF failed to load on rproc (%d)\n", __func__, ret);
81 /* Add an extra newline to differentiate the ATF logs from SPL */
82 printf("Starting ATF on ARM64 core...\n\n");
86 panic("%s: ATF failed to start on rproc (%d)\n", __func__, ret);
88 debug("Releasing resources...\n");
89 release_resources_for_core_shutdown();
91 debug("Finalizing core shutdown...\n");
97 #if defined(CONFIG_OF_LIBFDT)
98 int fdt_fixup_msmc_ram(void *blob, char *parent_path, char *node_name)
100 u64 msmc_start = 0, msmc_end = 0, msmc_size, reg[2];
101 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
102 int ret, node, subnode, len, prev_node;
103 u32 range[4], addr, size;
104 const fdt32_t *sub_reg;
106 ti_sci->ops.core_ops.query_msmc(ti_sci, &msmc_start, &msmc_end);
107 msmc_size = msmc_end - msmc_start + 1;
108 debug("%s: msmc_start = 0x%llx, msmc_size = 0x%llx\n", __func__,
109 msmc_start, msmc_size);
111 /* find or create "msmc_sram node */
112 ret = fdt_path_offset(blob, parent_path);
116 node = fdt_find_or_add_subnode(blob, ret, node_name);
120 ret = fdt_setprop_string(blob, node, "compatible", "mmio-sram");
124 reg[0] = cpu_to_fdt64(msmc_start);
125 reg[1] = cpu_to_fdt64(msmc_size);
126 ret = fdt_setprop(blob, node, "reg", reg, sizeof(reg));
130 fdt_setprop_cell(blob, node, "#address-cells", 1);
131 fdt_setprop_cell(blob, node, "#size-cells", 1);
134 range[1] = cpu_to_fdt32(msmc_start >> 32);
135 range[2] = cpu_to_fdt32(msmc_start & 0xffffffff);
136 range[3] = cpu_to_fdt32(msmc_size);
137 ret = fdt_setprop(blob, node, "ranges", range, sizeof(range));
141 subnode = fdt_first_subnode(blob, node);
144 /* Look for invalid subnodes and delete them */
145 while (subnode >= 0) {
146 sub_reg = fdt_getprop(blob, subnode, "reg", &len);
147 addr = fdt_read_number(sub_reg, 1);
149 size = fdt_read_number(sub_reg, 1);
150 debug("%s: subnode = %d, addr = 0x%x. size = 0x%x\n", __func__,
151 subnode, addr, size);
152 if (addr + size > msmc_size ||
153 !strncmp(fdt_get_name(blob, subnode, &len), "sysfw", 5) ||
154 !strncmp(fdt_get_name(blob, subnode, &len), "l3cache", 7)) {
155 fdt_del_node(blob, subnode);
156 debug("%s: deleting subnode %d\n", __func__, subnode);
158 subnode = fdt_first_subnode(blob, node);
160 subnode = fdt_next_subnode(blob, prev_node);
163 subnode = fdt_next_subnode(blob, prev_node);
170 int fdt_disable_node(void *blob, char *node_path)
175 offs = fdt_path_offset(blob, node_path);
177 debug("Node %s not found.\n", node_path);
180 ret = fdt_setprop_string(blob, offs, "status", "disabled");
182 printf("Could not add status property to node %s: %s\n",
183 node_path, fdt_strerror(ret));
191 #ifndef CONFIG_SYSRESET
192 void reset_cpu(ulong ignored)
197 #if defined(CONFIG_DISPLAY_CPUINFO)
198 int print_cpuinfo(void)
203 soc = (readl(CTRLMMR_WKUP_JTAG_DEVICE_ID) &
204 DEVICE_ID_FAMILY_MASK) >> DEVICE_ID_FAMILY_SHIFT;
205 rev = (readl(CTRLMMR_WKUP_JTAG_ID) &
206 JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT;
217 name = "Unknown Silicon";
220 printf("%s PG ", name);
229 name = "Unknown Revision";
231 printf("%s\n", name);
238 void board_prep_linux(bootm_headers_t *images)
240 debug("Linux kernel Image start = 0x%lx end = 0x%lx\n",
241 images->os.start, images->os.end);
242 __asm_flush_dcache_range(images->os.start,
243 ROUND(images->os.end,
244 CONFIG_SYS_CACHELINE_SIZE));
248 #ifdef CONFIG_CPU_V7R
249 void disable_linefill_optimization(void)
254 * On K3 devices there are 2 conditions where R5F can deadlock:
255 * 1.When software is performing series of store operations to
256 * cacheable write back/write allocate memory region and later
257 * on software execute barrier operation (DSB or DMB). R5F may
258 * hang at the barrier instruction.
259 * 2.When software is performing a mix of load and store operations
260 * within a tight loop and store operations are all writing to
261 * cacheable write back/write allocates memory regions, R5F may
262 * hang at one of the load instruction.
264 * To avoid the above two conditions disable linefill optimization
267 asm("mrc p15, 0, %0, c1, c0, 1" : "=r" (actlr));
268 actlr |= (1 << 13); /* Set DLFO bit */
269 asm("mcr p15, 0, %0, c1, c0, 1" : : "r" (actlr));