Emanuele Ghidoli | d7e0b07 | 2023-07-14 17:23:10 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | /* |
| 3 | * Copyright 2023 Toradex - https://www.toradex.com/ |
| 4 | */ |
| 5 | |
| 6 | #include <asm/hardware.h> |
| 7 | #include "common_fdt.h" |
| 8 | #include <fdt_support.h> |
| 9 | |
| 10 | static void fdt_fixup_cores_nodes_am625(void *blob, int core_nr) |
| 11 | { |
| 12 | char node_path[32]; |
| 13 | |
| 14 | if (core_nr < 1) |
| 15 | return; |
| 16 | |
| 17 | for (; core_nr < 4; core_nr++) { |
| 18 | snprintf(node_path, sizeof(node_path), "/cpus/cpu@%d", core_nr); |
| 19 | fdt_del_node_path(blob, node_path); |
| 20 | snprintf(node_path, sizeof(node_path), "/cpus/cpu-map/cluster0/core%d", core_nr); |
| 21 | fdt_del_node_path(blob, node_path); |
| 22 | snprintf(node_path, sizeof(node_path), "/bus@f0000/watchdog@e0%d0000", core_nr); |
| 23 | fdt_del_node_path(blob, node_path); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | static void fdt_fixup_gpu_nodes_am625(void *blob, int has_gpu) |
| 28 | { |
| 29 | if (!has_gpu) { |
| 30 | fdt_del_node_path(blob, "/bus@f0000/gpu@fd00000"); |
| 31 | fdt_del_node_path(blob, "/bus@f0000/watchdog@e0f0000"); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | static void fdt_fixup_pru_node_am625(void *blob, int has_pru) |
| 36 | { |
| 37 | if (!has_pru) |
| 38 | fdt_del_node_path(blob, "/bus@f0000/pruss@30040000"); |
| 39 | } |
| 40 | |
| 41 | static int k3_get_core_nr(void) |
| 42 | { |
| 43 | u32 full_devid = readl(CTRLMMR_WKUP_JTAG_DEVICE_ID); |
| 44 | |
| 45 | return (full_devid & JTAG_DEV_CORE_NR_MASK) >> JTAG_DEV_CORE_NR_SHIFT; |
| 46 | } |
| 47 | |
| 48 | static int k3_has_pru(void) |
| 49 | { |
| 50 | u32 full_devid = readl(CTRLMMR_WKUP_JTAG_DEVICE_ID); |
| 51 | u32 feature_mask = (full_devid & JTAG_DEV_FEATURES_MASK) >> |
| 52 | JTAG_DEV_FEATURES_SHIFT; |
| 53 | |
| 54 | return !(feature_mask & JTAG_DEV_FEATURE_NO_PRU); |
| 55 | } |
| 56 | |
| 57 | static int k3_has_gpu(void) |
| 58 | { |
| 59 | u32 full_devid = readl(CTRLMMR_WKUP_JTAG_DEVICE_ID); |
| 60 | |
| 61 | return (full_devid & JTAG_DEV_GPU_MASK) >> JTAG_DEV_GPU_SHIFT; |
| 62 | } |
| 63 | |
| 64 | int ft_system_setup(void *blob, struct bd_info *bd) |
| 65 | { |
| 66 | fdt_fixup_cores_nodes_am625(blob, k3_get_core_nr()); |
| 67 | fdt_fixup_gpu_nodes_am625(blob, k3_has_gpu()); |
| 68 | fdt_fixup_pru_node_am625(blob, k3_has_pru()); |
| 69 | |
| 70 | return 0; |
| 71 | } |