1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2020 SiFive, Inc
6 * Pragnesh Patel <pragnesh.patel@sifive.com>
10 #include <asm/global_data.h>
12 #include <linux/bitops.h>
14 /* Register offsets */
15 #define L2_CACHE_CONFIG 0x000
16 #define L2_CACHE_ENABLE 0x008
18 #define MASK_NUM_WAYS GENMASK(15, 8)
19 #define NUM_WAYS_SHIFT 8
21 DECLARE_GLOBAL_DATA_PTR;
23 int cache_enable_ways(void)
25 const void *blob = gd->fdt_blob;
33 node = fdt_node_offset_by_compatible(blob, -1,
34 "sifive,fu540-c000-ccache");
39 base = fdtdec_get_addr_size_auto_parent(blob, 0, node, "reg", 0,
41 if (base == FDT_ADDR_T_NONE)
42 return FDT_ADDR_T_NONE;
44 config = readl((volatile u32 *)base + L2_CACHE_CONFIG);
45 ways = (config & MASK_NUM_WAYS) >> NUM_WAYS_SHIFT;
47 enable = (volatile u32 *)(base + L2_CACHE_ENABLE);