blob: 521df40466f99004bb25c88e88ae43fbfa48d344 [file] [log] [blame]
Zong Li43a21832021-09-01 15:01:39 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2021 SiFive
4 */
5
6#include <common.h>
7#include <cache.h>
8#include <dm.h>
9#include <asm/io.h>
10#include <dm/device.h>
11#include <linux/bitfield.h>
12
13#define SIFIVE_CCACHE_CONFIG 0x000
14#define SIFIVE_CCACHE_CONFIG_WAYS GENMASK(15, 8)
15
16#define SIFIVE_CCACHE_WAY_ENABLE 0x008
17
18struct sifive_ccache {
19 void __iomem *base;
20};
21
22static int sifive_ccache_enable(struct udevice *dev)
23{
24 struct sifive_ccache *priv = dev_get_priv(dev);
25 u32 config;
26 u32 ways;
27
28 /* Enable all ways of composable cache */
29 config = readl(priv->base + SIFIVE_CCACHE_CONFIG);
30 ways = FIELD_GET(SIFIVE_CCACHE_CONFIG_WAYS, config);
31
32 writel(ways - 1, priv->base + SIFIVE_CCACHE_WAY_ENABLE);
33
34 return 0;
35}
36
37static int sifive_ccache_get_info(struct udevice *dev, struct cache_info *info)
38{
39 struct sifive_ccache *priv = dev_get_priv(dev);
40
Bin Meng2fb91a22021-09-12 11:15:08 +080041 info->base = (uintptr_t)priv->base;
Zong Li43a21832021-09-01 15:01:39 +080042
43 return 0;
44}
45
46static const struct cache_ops sifive_ccache_ops = {
47 .enable = sifive_ccache_enable,
48 .get_info = sifive_ccache_get_info,
49};
50
51static int sifive_ccache_probe(struct udevice *dev)
52{
53 struct sifive_ccache *priv = dev_get_priv(dev);
54
55 priv->base = dev_read_addr_ptr(dev);
56 if (!priv->base)
57 return -EINVAL;
58
59 return 0;
60}
61
62static const struct udevice_id sifive_ccache_ids[] = {
63 { .compatible = "sifive,fu540-c000-ccache" },
64 { .compatible = "sifive,fu740-c000-ccache" },
Yanhong Wang22c24022023-03-29 11:42:09 +080065 { .compatible = "sifive,ccache0" },
Zong Li43a21832021-09-01 15:01:39 +080066 {}
67};
68
69U_BOOT_DRIVER(sifive_ccache) = {
70 .name = "sifive_ccache",
71 .id = UCLASS_CACHE,
72 .of_match = sifive_ccache_ids,
73 .probe = sifive_ccache_probe,
74 .priv_auto = sizeof(struct sifive_ccache),
75 .ops = &sifive_ccache_ops,
76};