1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2021 SiFive
10 #include <dm/device.h>
11 #include <linux/bitfield.h>
13 #define SIFIVE_CCACHE_CONFIG 0x000
14 #define SIFIVE_CCACHE_CONFIG_WAYS GENMASK(15, 8)
16 #define SIFIVE_CCACHE_WAY_ENABLE 0x008
18 struct sifive_ccache {
22 static int sifive_ccache_enable(struct udevice *dev)
24 struct sifive_ccache *priv = dev_get_priv(dev);
28 /* Enable all ways of composable cache */
29 config = readl(priv->base + SIFIVE_CCACHE_CONFIG);
30 ways = FIELD_GET(SIFIVE_CCACHE_CONFIG_WAYS, config);
32 writel(ways - 1, priv->base + SIFIVE_CCACHE_WAY_ENABLE);
37 static int sifive_ccache_get_info(struct udevice *dev, struct cache_info *info)
39 struct sifive_ccache *priv = dev_get_priv(dev);
41 info->base = (uintptr_t)priv->base;
46 static const struct cache_ops sifive_ccache_ops = {
47 .enable = sifive_ccache_enable,
48 .get_info = sifive_ccache_get_info,
51 static int sifive_ccache_probe(struct udevice *dev)
53 struct sifive_ccache *priv = dev_get_priv(dev);
55 priv->base = dev_read_addr_ptr(dev);
62 static const struct udevice_id sifive_ccache_ids[] = {
63 { .compatible = "sifive,fu540-c000-ccache" },
64 { .compatible = "sifive,fu740-c000-ccache" },
65 { .compatible = "sifive,ccache0" },
69 U_BOOT_DRIVER(sifive_ccache) = {
70 .name = "sifive_ccache",
72 .of_match = sifive_ccache_ids,
73 .probe = sifive_ccache_probe,
74 .priv_auto = sizeof(struct sifive_ccache),
75 .ops = &sifive_ccache_ops,