Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * K3: Common Architecture initialization |
| 4 | * |
Nishanth Menon | eaa39c6 | 2023-11-01 15:56:03 -0500 | [diff] [blame] | 5 | * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com/ |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 6 | * Lokesh Vutla <lokeshvutla@ti.com> |
| 7 | */ |
| 8 | |
Tom Rini | b7f7046 | 2023-12-14 13:16:45 -0500 | [diff] [blame] | 9 | #include <config.h> |
Simon Glass | afb0215 | 2019-12-28 10:45:01 -0700 | [diff] [blame] | 10 | #include <cpu_func.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 11 | #include <image.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 12 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 14 | #include <spl.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 15 | #include <asm/global_data.h> |
Simon Glass | bdd5f81 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 16 | #include <linux/printk.h> |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 17 | #include "common.h" |
| 18 | #include <dm.h> |
| 19 | #include <remoteproc.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 20 | #include <asm/cache.h> |
Lokesh Vutla | 28cd824 | 2019-03-08 11:47:33 +0530 | [diff] [blame] | 21 | #include <linux/soc/ti/ti_sci_protocol.h> |
Lokesh Vutla | 16cf5d2 | 2019-03-08 11:47:34 +0530 | [diff] [blame] | 22 | #include <fdt_support.h> |
Lokesh Vutla | a04cf3b | 2019-09-27 13:32:11 +0530 | [diff] [blame] | 23 | #include <asm/hardware.h> |
| 24 | #include <asm/io.h> |
Keerthy | 7007adc | 2020-02-12 13:55:04 +0530 | [diff] [blame] | 25 | #include <fs_loader.h> |
| 26 | #include <fs.h> |
Vitor Soares | a7e364b | 2024-03-28 10:05:48 +0000 | [diff] [blame] | 27 | #include <efi_loader.h> |
Keerthy | 7007adc | 2020-02-12 13:55:04 +0530 | [diff] [blame] | 28 | #include <env.h> |
| 29 | #include <elf.h> |
Dave Gerlach | c74227f | 2020-07-15 23:40:04 -0500 | [diff] [blame] | 30 | #include <soc.h> |
Prasanth Babu Mantena | 871bde2 | 2024-10-09 20:27:00 +0530 | [diff] [blame] | 31 | #include <dm/uclass-internal.h> |
| 32 | #include <dm/device-internal.h> |
Lokesh Vutla | 28cd824 | 2019-03-08 11:47:33 +0530 | [diff] [blame] | 33 | |
Beleswar Padhi | 5fe164f | 2025-06-09 13:44:27 +0530 | [diff] [blame^] | 34 | #define PROC_BOOT_CTRL_FLAG_R5_CORE_HALT 0x00000001 |
| 35 | #define PROC_BOOT_STATUS_FLAG_R5_WFI 0x00000002 |
| 36 | #define PROC_ID_MCU_R5FSS0_CORE1 0x02 |
| 37 | #define PROC_BOOT_CFG_FLAG_R5_LOCKSTEP 0x00000100 |
| 38 | |
Aradhya Bhatia | 5b09538 | 2024-02-12 15:36:35 +0530 | [diff] [blame] | 39 | #include <asm/arch/k3-qos.h> |
| 40 | |
Lokesh Vutla | 28cd824 | 2019-03-08 11:47:33 +0530 | [diff] [blame] | 41 | struct ti_sci_handle *get_ti_sci_handle(void) |
| 42 | { |
| 43 | struct udevice *dev; |
| 44 | int ret; |
| 45 | |
Lokesh Vutla | 00a1513 | 2019-09-27 13:32:15 +0530 | [diff] [blame] | 46 | ret = uclass_get_device_by_driver(UCLASS_FIRMWARE, |
Simon Glass | 65130cd | 2020-12-28 20:34:56 -0700 | [diff] [blame] | 47 | DM_DRIVER_GET(ti_sci), &dev); |
Lokesh Vutla | 28cd824 | 2019-03-08 11:47:33 +0530 | [diff] [blame] | 48 | if (ret) |
| 49 | panic("Failed to get SYSFW (%d)\n", ret); |
| 50 | |
| 51 | return (struct ti_sci_handle *)ti_sci_get_handle_from_sysfw(dev); |
| 52 | } |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 53 | |
Lokesh Vutla | 5fafe44 | 2020-03-10 16:50:58 +0530 | [diff] [blame] | 54 | void k3_sysfw_print_ver(void) |
| 55 | { |
| 56 | struct ti_sci_handle *ti_sci = get_ti_sci_handle(); |
| 57 | char fw_desc[sizeof(ti_sci->version.firmware_description) + 1]; |
| 58 | |
| 59 | /* |
| 60 | * Output System Firmware version info. Note that since the |
| 61 | * 'firmware_description' field is not guaranteed to be zero- |
| 62 | * terminated we manually add a \0 terminator if needed. Further |
| 63 | * note that we intentionally no longer rely on the extended |
| 64 | * printf() formatter '%.*s' to not having to require a more |
| 65 | * full-featured printf() implementation. |
| 66 | */ |
| 67 | strncpy(fw_desc, ti_sci->version.firmware_description, |
| 68 | sizeof(ti_sci->version.firmware_description)); |
| 69 | fw_desc[sizeof(fw_desc) - 1] = '\0'; |
| 70 | |
| 71 | printf("SYSFW ABI: %d.%d (firmware rev 0x%04x '%s')\n", |
| 72 | ti_sci->version.abi_major, ti_sci->version.abi_minor, |
| 73 | ti_sci->version.firmware_revision, fw_desc); |
| 74 | } |
| 75 | |
Matthias Schiffer | 0262dcd | 2023-09-27 15:43:14 +0200 | [diff] [blame] | 76 | void mmr_unlock(uintptr_t base, u32 partition) |
Lokesh Vutla | ff7ab09 | 2020-08-05 22:44:17 +0530 | [diff] [blame] | 77 | { |
| 78 | /* Translate the base address */ |
Matthias Schiffer | 0262dcd | 2023-09-27 15:43:14 +0200 | [diff] [blame] | 79 | uintptr_t part_base = base + partition * CTRL_MMR0_PARTITION_SIZE; |
Lokesh Vutla | ff7ab09 | 2020-08-05 22:44:17 +0530 | [diff] [blame] | 80 | |
| 81 | /* Unlock the requested partition if locked using two-step sequence */ |
| 82 | writel(CTRLMMR_LOCK_KICK0_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK0); |
| 83 | writel(CTRLMMR_LOCK_KICK1_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK1); |
| 84 | } |
| 85 | |
Lokesh Vutla | 8be6bbf | 2020-08-05 22:44:23 +0530 | [diff] [blame] | 86 | bool is_rom_loaded_sysfw(struct rom_extended_boot_data *data) |
| 87 | { |
| 88 | if (strncmp(data->header, K3_ROM_BOOT_HEADER_MAGIC, 7)) |
| 89 | return false; |
| 90 | |
| 91 | return data->num_components > 1; |
| 92 | } |
| 93 | |
Andreas Dannenberg | d13ec8c | 2019-08-15 15:55:28 -0500 | [diff] [blame] | 94 | DECLARE_GLOBAL_DATA_PTR; |
| 95 | |
| 96 | #ifdef CONFIG_K3_EARLY_CONS |
| 97 | int early_console_init(void) |
| 98 | { |
| 99 | struct udevice *dev; |
| 100 | int ret; |
| 101 | |
| 102 | gd->baudrate = CONFIG_BAUDRATE; |
| 103 | |
| 104 | ret = uclass_get_device_by_seq(UCLASS_SERIAL, CONFIG_K3_EARLY_CONS_IDX, |
| 105 | &dev); |
| 106 | if (ret) { |
| 107 | printf("Error getting serial dev for early console! (%d)\n", |
| 108 | ret); |
| 109 | return ret; |
| 110 | } |
| 111 | |
| 112 | gd->cur_serial_dev = dev; |
| 113 | gd->flags |= GD_FLG_SERIAL_READY; |
Simon Glass | d4b0fdb | 2024-08-21 10:19:04 -0600 | [diff] [blame] | 114 | gd->flags |= GD_FLG_HAVE_CONSOLE; |
Andreas Dannenberg | d13ec8c | 2019-08-15 15:55:28 -0500 | [diff] [blame] | 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | #endif |
| 119 | |
Andrew Davis | ef880db | 2024-02-01 18:24:45 -0600 | [diff] [blame] | 120 | #if CONFIG_IS_ENABLED(FIT_IMAGE_POST_PROCESS) && !IS_ENABLED(CONFIG_SYS_K3_SPL_ATF) |
Tero Kristo | 738c590 | 2021-06-11 11:45:19 +0300 | [diff] [blame] | 121 | void board_fit_image_post_process(const void *fit, int node, void **p_image, |
| 122 | size_t *p_size) |
| 123 | { |
Andrew Davis | ef880db | 2024-02-01 18:24:45 -0600 | [diff] [blame] | 124 | ti_secure_image_check_binary(p_image, p_size); |
| 125 | ti_secure_image_post_process(p_image, p_size); |
Tero Kristo | 738c590 | 2021-06-11 11:45:19 +0300 | [diff] [blame] | 126 | } |
| 127 | #endif |
| 128 | |
Lokesh Vutla | a228532 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 129 | #ifndef CONFIG_SYSRESET |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 130 | void reset_cpu(void) |
Lokesh Vutla | a228532 | 2019-06-13 10:29:42 +0530 | [diff] [blame] | 131 | { |
| 132 | } |
| 133 | #endif |
Lokesh Vutla | a04cf3b | 2019-09-27 13:32:11 +0530 | [diff] [blame] | 134 | |
Andrew Davis | f8c9836 | 2022-07-15 11:34:32 -0500 | [diff] [blame] | 135 | enum k3_device_type get_device_type(void) |
| 136 | { |
| 137 | u32 sys_status = readl(K3_SEC_MGR_SYS_STATUS); |
| 138 | |
| 139 | u32 sys_dev_type = (sys_status & SYS_STATUS_DEV_TYPE_MASK) >> |
| 140 | SYS_STATUS_DEV_TYPE_SHIFT; |
| 141 | |
| 142 | u32 sys_sub_type = (sys_status & SYS_STATUS_SUB_TYPE_MASK) >> |
| 143 | SYS_STATUS_SUB_TYPE_SHIFT; |
| 144 | |
| 145 | switch (sys_dev_type) { |
| 146 | case SYS_STATUS_DEV_TYPE_GP: |
| 147 | return K3_DEVICE_TYPE_GP; |
| 148 | case SYS_STATUS_DEV_TYPE_TEST: |
| 149 | return K3_DEVICE_TYPE_TEST; |
| 150 | case SYS_STATUS_DEV_TYPE_EMU: |
| 151 | return K3_DEVICE_TYPE_EMU; |
| 152 | case SYS_STATUS_DEV_TYPE_HS: |
| 153 | if (sys_sub_type == SYS_STATUS_SUB_TYPE_VAL_FS) |
| 154 | return K3_DEVICE_TYPE_HS_FS; |
| 155 | else |
| 156 | return K3_DEVICE_TYPE_HS_SE; |
| 157 | default: |
| 158 | return K3_DEVICE_TYPE_BAD; |
| 159 | } |
| 160 | } |
| 161 | |
Lokesh Vutla | a04cf3b | 2019-09-27 13:32:11 +0530 | [diff] [blame] | 162 | #if defined(CONFIG_DISPLAY_CPUINFO) |
Andrew Davis | f8c9836 | 2022-07-15 11:34:32 -0500 | [diff] [blame] | 163 | static const char *get_device_type_name(void) |
| 164 | { |
| 165 | enum k3_device_type type = get_device_type(); |
| 166 | |
| 167 | switch (type) { |
| 168 | case K3_DEVICE_TYPE_GP: |
| 169 | return "GP"; |
| 170 | case K3_DEVICE_TYPE_TEST: |
| 171 | return "TEST"; |
| 172 | case K3_DEVICE_TYPE_EMU: |
| 173 | return "EMU"; |
| 174 | case K3_DEVICE_TYPE_HS_FS: |
| 175 | return "HS-FS"; |
| 176 | case K3_DEVICE_TYPE_HS_SE: |
| 177 | return "HS-SE"; |
| 178 | default: |
| 179 | return "BAD"; |
| 180 | } |
| 181 | } |
| 182 | |
Lokesh Vutla | a04cf3b | 2019-09-27 13:32:11 +0530 | [diff] [blame] | 183 | int print_cpuinfo(void) |
| 184 | { |
Dave Gerlach | c74227f | 2020-07-15 23:40:04 -0500 | [diff] [blame] | 185 | struct udevice *soc; |
| 186 | char name[64]; |
| 187 | int ret; |
Dave Gerlach | 3373ee0 | 2020-07-15 23:40:04 -0500 | [diff] [blame] | 188 | |
Tom Rini | 5a9ecb2 | 2020-07-24 08:42:06 -0400 | [diff] [blame] | 189 | printf("SoC: "); |
Dave Gerlach | 3373ee0 | 2020-07-15 23:40:04 -0500 | [diff] [blame] | 190 | |
Dave Gerlach | c74227f | 2020-07-15 23:40:04 -0500 | [diff] [blame] | 191 | ret = soc_get(&soc); |
| 192 | if (ret) { |
| 193 | printf("UNKNOWN\n"); |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | ret = soc_get_family(soc, name, 64); |
| 198 | if (!ret) { |
| 199 | printf("%s ", name); |
| 200 | } |
| 201 | |
| 202 | ret = soc_get_revision(soc, name, 64); |
| 203 | if (!ret) { |
Andrew Davis | f8c9836 | 2022-07-15 11:34:32 -0500 | [diff] [blame] | 204 | printf("%s ", name); |
Dave Gerlach | c74227f | 2020-07-15 23:40:04 -0500 | [diff] [blame] | 205 | } |
Lokesh Vutla | a04cf3b | 2019-09-27 13:32:11 +0530 | [diff] [blame] | 206 | |
Andrew Davis | f8c9836 | 2022-07-15 11:34:32 -0500 | [diff] [blame] | 207 | printf("%s\n", get_device_type_name()); |
| 208 | |
Lokesh Vutla | a04cf3b | 2019-09-27 13:32:11 +0530 | [diff] [blame] | 209 | return 0; |
| 210 | } |
| 211 | #endif |
Lokesh Vutla | 362beda | 2019-10-07 13:52:17 +0530 | [diff] [blame] | 212 | |
| 213 | #ifdef CONFIG_ARM64 |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 214 | void board_prep_linux(struct bootm_headers *images) |
Lokesh Vutla | 362beda | 2019-10-07 13:52:17 +0530 | [diff] [blame] | 215 | { |
| 216 | debug("Linux kernel Image start = 0x%lx end = 0x%lx\n", |
| 217 | images->os.start, images->os.end); |
| 218 | __asm_flush_dcache_range(images->os.start, |
| 219 | ROUND(images->os.end, |
| 220 | CONFIG_SYS_CACHELINE_SIZE)); |
| 221 | } |
| 222 | #endif |
Lokesh Vutla | 5fbd6fe | 2019-12-31 15:49:55 +0530 | [diff] [blame] | 223 | |
Joao Paulo Goncalves | fc3557f | 2023-11-13 16:07:21 -0300 | [diff] [blame] | 224 | void spl_enable_cache(void) |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 225 | { |
| 226 | #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) |
Devarsh Thakkar | 3a7a44d | 2023-12-05 21:25:17 +0530 | [diff] [blame] | 227 | gd->ram_top = CFG_SYS_SDRAM_BASE; |
| 228 | int ret = 0; |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 229 | |
Georgi Vlaev | a5076cd | 2022-06-14 17:45:30 +0300 | [diff] [blame] | 230 | dram_init(); |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 231 | |
| 232 | /* reserve TLB table */ |
| 233 | gd->arch.tlb_size = PGTABLE_SIZE; |
| 234 | |
Devarsh Thakkar | 3a7a44d | 2023-12-05 21:25:17 +0530 | [diff] [blame] | 235 | gd->ram_top += get_effective_memsize(); |
Devarsh Thakkar | 3a7a44d | 2023-12-05 21:25:17 +0530 | [diff] [blame] | 236 | gd->relocaddr = gd->ram_top; |
| 237 | |
| 238 | ret = spl_reserve_video_from_ram_top(); |
| 239 | if (ret) |
| 240 | panic("Failed to reserve framebuffer memory (%d)\n", ret); |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 241 | |
Devarsh Thakkar | 3a7a44d | 2023-12-05 21:25:17 +0530 | [diff] [blame] | 242 | gd->arch.tlb_addr = gd->relocaddr - gd->arch.tlb_size; |
Nikhil M Jain | 3683681 | 2023-07-18 14:27:28 +0530 | [diff] [blame] | 243 | gd->arch.tlb_addr &= ~(0x10000 - 1); |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 244 | debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr, |
| 245 | gd->arch.tlb_addr + gd->arch.tlb_size); |
Nikhil M Jain | 3683681 | 2023-07-18 14:27:28 +0530 | [diff] [blame] | 246 | gd->relocaddr = gd->arch.tlb_addr; |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 247 | |
Joao Paulo Goncalves | fc3557f | 2023-11-13 16:07:21 -0300 | [diff] [blame] | 248 | enable_caches(); |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 249 | #endif |
| 250 | } |
| 251 | |
Prasanth Babu Mantena | 871bde2 | 2024-10-09 20:27:00 +0530 | [diff] [blame] | 252 | static __maybe_unused void k3_dma_remove(void) |
| 253 | { |
| 254 | struct udevice *dev; |
| 255 | int rc; |
| 256 | |
| 257 | rc = uclass_find_device(UCLASS_DMA, 0, &dev); |
| 258 | if (!rc && dev) { |
| 259 | rc = device_remove(dev, DM_REMOVE_NORMAL); |
| 260 | if (rc) |
| 261 | pr_warn("Cannot remove dma device '%s' (err=%d)\n", |
| 262 | dev->name, rc); |
| 263 | } else |
| 264 | pr_warn("DMA Device not found (err=%d)\n", rc); |
| 265 | } |
| 266 | |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 267 | void spl_board_prepare_for_boot(void) |
| 268 | { |
Prasanth Babu Mantena | 871bde2 | 2024-10-09 20:27:00 +0530 | [diff] [blame] | 269 | #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 270 | dcache_disable(); |
Prasanth Babu Mantena | 871bde2 | 2024-10-09 20:27:00 +0530 | [diff] [blame] | 271 | #endif |
| 272 | #if IS_ENABLED(CONFIG_SPL_DMA) && IS_ENABLED(CONFIG_SPL_DM_DEVICE_REMOVE) |
| 273 | k3_dma_remove(); |
| 274 | #endif |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 275 | } |
| 276 | |
Prasanth Babu Mantena | 871bde2 | 2024-10-09 20:27:00 +0530 | [diff] [blame] | 277 | #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) |
Patrick Delaunay | 35c949c | 2020-07-07 14:25:15 +0200 | [diff] [blame] | 278 | void spl_board_prepare_for_linux(void) |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 279 | { |
| 280 | dcache_disable(); |
| 281 | } |
| 282 | #endif |
Vignesh Raghavendra | 030f405 | 2021-12-24 12:55:29 +0530 | [diff] [blame] | 283 | |
| 284 | int misc_init_r(void) |
| 285 | { |
| 286 | if (IS_ENABLED(CONFIG_TI_AM65_CPSW_NUSS)) { |
| 287 | struct udevice *dev; |
| 288 | int ret; |
| 289 | |
| 290 | ret = uclass_get_device_by_driver(UCLASS_MISC, |
| 291 | DM_DRIVER_GET(am65_cpsw_nuss), |
| 292 | &dev); |
| 293 | if (ret) |
| 294 | printf("Failed to probe am65_cpsw_nuss driver\n"); |
| 295 | } |
| 296 | |
MD Danish Anwar | dd18b89 | 2024-04-04 12:38:02 +0530 | [diff] [blame] | 297 | if (IS_ENABLED(CONFIG_TI_ICSSG_PRUETH)) { |
| 298 | struct udevice *dev; |
| 299 | int ret; |
| 300 | |
| 301 | ret = uclass_get_device_by_driver(UCLASS_MISC, |
| 302 | DM_DRIVER_GET(prueth), |
| 303 | &dev); |
| 304 | if (ret) |
| 305 | printf("Failed to probe prueth driver\n"); |
| 306 | } |
| 307 | |
Vignesh Raghavendra | ae17d36 | 2023-04-20 21:42:21 +0530 | [diff] [blame] | 308 | /* Default FIT boot on HS-SE devices */ |
Manorit Chawdhry | f6f1d9b | 2024-05-21 16:26:48 +0530 | [diff] [blame] | 309 | if (get_device_type() == K3_DEVICE_TYPE_HS_SE) { |
Andrew Davis | f1d7205 | 2022-10-07 11:27:46 -0500 | [diff] [blame] | 310 | env_set("boot_fit", "1"); |
Manorit Chawdhry | f6f1d9b | 2024-05-21 16:26:48 +0530 | [diff] [blame] | 311 | env_set("secure_rprocs", "1"); |
| 312 | } |
Andrew Davis | f1d7205 | 2022-10-07 11:27:46 -0500 | [diff] [blame] | 313 | |
Vignesh Raghavendra | 030f405 | 2021-12-24 12:55:29 +0530 | [diff] [blame] | 314 | return 0; |
| 315 | } |
Andrew Davis | 2dde9a7 | 2023-04-06 11:38:17 -0500 | [diff] [blame] | 316 | |
| 317 | /** |
| 318 | * do_board_detect() - Detect board description |
| 319 | * |
| 320 | * Function to detect board description. This is expected to be |
| 321 | * overridden in the SoC family board file where desired. |
| 322 | */ |
| 323 | void __weak do_board_detect(void) |
| 324 | { |
| 325 | } |
Aradhya Bhatia | 5b09538 | 2024-02-12 15:36:35 +0530 | [diff] [blame] | 326 | |
| 327 | #if (IS_ENABLED(CONFIG_K3_QOS)) |
| 328 | void setup_qos(void) |
| 329 | { |
| 330 | u32 i; |
| 331 | |
| 332 | for (i = 0; i < qos_count; i++) |
| 333 | writel(qos_data[i].val, (uintptr_t)qos_data[i].reg); |
Lokesh Vutla | 5d83fd2 | 2018-11-02 19:51:05 +0530 | [diff] [blame] | 334 | } |
Aradhya Bhatia | 5b09538 | 2024-02-12 15:36:35 +0530 | [diff] [blame] | 335 | #endif |
Beleswar Padhi | 5fe164f | 2025-06-09 13:44:27 +0530 | [diff] [blame^] | 336 | |
| 337 | int __maybe_unused shutdown_mcu_r5_core1(void) |
| 338 | { |
| 339 | struct ti_sci_handle *ti_sci = get_ti_sci_handle(); |
| 340 | struct ti_sci_dev_ops *dev_ops = &ti_sci->ops.dev_ops; |
| 341 | struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops; |
| 342 | u32 dev_id_mcu_r5_core1 = put_core_ids[0]; |
| 343 | u64 boot_vector; |
| 344 | u32 cfg, ctrl, sts, halted; |
| 345 | int cluster_mode_lockstep, ret; |
| 346 | bool r_state = false, c_state = false; |
| 347 | |
| 348 | ret = proc_ops->proc_request(ti_sci, PROC_ID_MCU_R5FSS0_CORE1); |
| 349 | if (ret) { |
| 350 | printf("Unable to request processor control for MCU1_1 core, %d\n", |
| 351 | ret); |
| 352 | return ret; |
| 353 | } |
| 354 | |
| 355 | ret = dev_ops->is_on(ti_sci, dev_id_mcu_r5_core1, &r_state, &c_state); |
| 356 | if (ret) { |
| 357 | printf("Unable to get device status for MCU1_1 core, %d\n", ret); |
| 358 | return ret; |
| 359 | } |
| 360 | |
| 361 | ret = proc_ops->get_proc_boot_status(ti_sci, PROC_ID_MCU_R5FSS0_CORE1, |
| 362 | &boot_vector, &cfg, &ctrl, &sts); |
| 363 | if (ret) { |
| 364 | printf("Unable to get Processor boot status for MCU1_1 core, %d\n", |
| 365 | ret); |
| 366 | goto release_proc_ctrl; |
| 367 | } |
| 368 | |
| 369 | halted = !!(sts & PROC_BOOT_STATUS_FLAG_R5_WFI); |
| 370 | cluster_mode_lockstep = !!(cfg & PROC_BOOT_CFG_FLAG_R5_LOCKSTEP); |
| 371 | |
| 372 | /* |
| 373 | * Shutdown MCU R5F Core 1 only if: |
| 374 | * - cluster is booted in SplitMode |
| 375 | * - core is powered on |
| 376 | * - core is in WFI (halted) |
| 377 | */ |
| 378 | if (cluster_mode_lockstep || !c_state || !halted) { |
| 379 | ret = -EINVAL; |
| 380 | goto release_proc_ctrl; |
| 381 | } |
| 382 | |
| 383 | ret = proc_ops->set_proc_boot_ctrl(ti_sci, PROC_ID_MCU_R5FSS0_CORE1, |
| 384 | PROC_BOOT_CTRL_FLAG_R5_CORE_HALT, 0); |
| 385 | if (ret) { |
| 386 | printf("Unable to Halt MCU1_1 core, %d\n", ret); |
| 387 | goto release_proc_ctrl; |
| 388 | } |
| 389 | |
| 390 | ret = dev_ops->put_device(ti_sci, dev_id_mcu_r5_core1); |
| 391 | if (ret) { |
| 392 | printf("Unable to assert reset on MCU1_1 core, %d\n", ret); |
| 393 | return ret; |
| 394 | } |
| 395 | |
| 396 | release_proc_ctrl: |
| 397 | proc_ops->proc_release(ti_sci, PROC_ID_MCU_R5FSS0_CORE1); |
| 398 | return ret; |
| 399 | } |