blob: 0fc4ef6c0076c6e39406310f95cc93945d967854 [file] [log] [blame]
Pragnesh Patel8a521282020-05-29 12:14:51 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2020 SiFive, Inc
4 *
5 * Authors:
6 * Pragnesh Patel <pragnesh.patel@sifive.com>
7 */
8
9#include <common.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060010#include <asm/global_data.h>
Pragnesh Patel8a521282020-05-29 12:14:51 +053011#include <asm/io.h>
12#include <linux/bitops.h>
13
14/* Register offsets */
15#define L2_CACHE_CONFIG 0x000
16#define L2_CACHE_ENABLE 0x008
17
18#define MASK_NUM_WAYS GENMASK(15, 8)
19#define NUM_WAYS_SHIFT 8
20
21DECLARE_GLOBAL_DATA_PTR;
22
23int cache_enable_ways(void)
24{
25 const void *blob = gd->fdt_blob;
Heinrich Schuchardt03de50e2020-08-03 23:09:49 +020026 int node;
Pragnesh Patel8a521282020-05-29 12:14:51 +053027 fdt_addr_t base;
28 u32 config;
29 u32 ways;
30
31 volatile u32 *enable;
32
33 node = fdt_node_offset_by_compatible(blob, -1,
34 "sifive,fu540-c000-ccache");
35
36 if (node < 0)
37 return node;
38
Bin Meng54bcf262020-08-18 01:09:20 -070039 base = fdtdec_get_addr_size_auto_parent(blob, 0, node, "reg", 0,
40 NULL, false);
Pragnesh Patel8a521282020-05-29 12:14:51 +053041 if (base == FDT_ADDR_T_NONE)
42 return FDT_ADDR_T_NONE;
43
44 config = readl((volatile u32 *)base + L2_CACHE_CONFIG);
45 ways = (config & MASK_NUM_WAYS) >> NUM_WAYS_SHIFT;
46
47 enable = (volatile u32 *)(base + L2_CACHE_ENABLE);
48
49 /* memory barrier */
50 mb();
51 (*enable) = ways - 1;
52 /* memory barrier */
53 mb();
54 return 0;
55}