summaryrefslogtreecommitdiff
path: root/arch/riscv/cpu/fu740/cache.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2021-05-31 10:19:14 -0400
committerTom Rini <trini@konsulko.com>2021-05-31 10:19:14 -0400
commitd8729a114e1e98806cffb87d2dca895f99a0170a (patch)
tree5a42400633c76de4ca80df0bb835fad0d181078a /arch/riscv/cpu/fu740/cache.c
parentfa68645b948969cd9d6f40d19323ebe7c998f419 (diff)
parentd7da718bd94943309a7f25f14e694226a45b2aef (diff)
Merge https://source.denx.de/u-boot/custodians/u-boot-riscv
- SiFive FU740 and Unmatched support
Diffstat (limited to 'arch/riscv/cpu/fu740/cache.c')
-rw-r--r--arch/riscv/cpu/fu740/cache.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/arch/riscv/cpu/fu740/cache.c b/arch/riscv/cpu/fu740/cache.c
new file mode 100644
index 00000000000..680955c9e32
--- /dev/null
+++ b/arch/riscv/cpu/fu740/cache.c
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020-2021 SiFive, Inc
+ *
+ * Authors:
+ * Pragnesh Patel <pragnesh.patel@sifive.com>
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include <linux/bitops.h>
+#include <asm/global_data.h>
+
+/* Register offsets */
+#define L2_CACHE_CONFIG 0x000
+#define L2_CACHE_ENABLE 0x008
+
+#define MASK_NUM_WAYS GENMASK(15, 8)
+#define NUM_WAYS_SHIFT 8
+
+DECLARE_GLOBAL_DATA_PTR;
+
+int cache_enable_ways(void)
+{
+ const void *blob = gd->fdt_blob;
+ int node;
+ fdt_addr_t base;
+ u32 config;
+ u32 ways;
+
+ volatile u32 *enable;
+
+ node = fdt_node_offset_by_compatible(blob, -1,
+ "sifive,fu740-c000-ccache");
+
+ if (node < 0)
+ return node;
+
+ base = fdtdec_get_addr_size_auto_parent(blob, 0, node, "reg", 0,
+ NULL, false);
+ if (base == FDT_ADDR_T_NONE)
+ return FDT_ADDR_T_NONE;
+
+ config = readl((volatile u32 *)base + L2_CACHE_CONFIG);
+ ways = (config & MASK_NUM_WAYS) >> NUM_WAYS_SHIFT;
+
+ enable = (volatile u32 *)(base + L2_CACHE_ENABLE);
+
+ /* memory barrier */
+ mb();
+ (*enable) = ways - 1;
+ /* memory barrier */
+ mb();
+ return 0;
+}