1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2020 SiFive, Inc
6 * Pragnesh Patel <pragnesh.patel@sifive.com>
11 #include <linux/bitops.h>
13 /* Register offsets */
14 #define L2_CACHE_CONFIG 0x000
15 #define L2_CACHE_ENABLE 0x008
17 #define MASK_NUM_WAYS GENMASK(15, 8)
18 #define NUM_WAYS_SHIFT 8
20 DECLARE_GLOBAL_DATA_PTR;
22 int cache_enable_ways(void)
24 const void *blob = gd->fdt_blob;
25 int node = (-FDT_ERR_NOTFOUND);
32 node = fdt_node_offset_by_compatible(blob, -1,
33 "sifive,fu540-c000-ccache");
38 base = fdtdec_get_addr(blob, node, "reg");
39 if (base == FDT_ADDR_T_NONE)
40 return FDT_ADDR_T_NONE;
42 config = readl((volatile u32 *)base + L2_CACHE_CONFIG);
43 ways = (config & MASK_NUM_WAYS) >> NUM_WAYS_SHIFT;
45 enable = (volatile u32 *)(base + L2_CACHE_ENABLE);