blob: 1c0c3772a115c19a0cf23a8ae64774d2153fe2ea [file] [log] [blame]
Rick Chen842d5802018-11-07 09:34:06 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2017 Andes Technology Corporation
4 * Rick Chen, Andes Technology Corporation <rick@andestech.com>
5 */
6
7#include <common.h>
Simon Glass1d91ba72019-11-14 12:57:37 -07008#include <cpu_func.h>
Rick Chen05a684e2019-08-28 18:46:09 +08009#include <dm.h>
Simon Glass274e0b02020-05-10 11:39:56 -060010#include <asm/cache.h>
Rick Chen05a684e2019-08-28 18:46:09 +080011#include <dm/uclass-internal.h>
12#include <cache.h>
Rick Chen49cb7062019-08-28 18:46:11 +080013#include <asm/csr.h>
14
15#ifdef CONFIG_RISCV_NDS_CACHE
Pragnesh Pateld12b55b2020-03-14 19:12:28 +053016#if CONFIG_IS_ENABLED(RISCV_MMODE)
Rick Chen49cb7062019-08-28 18:46:11 +080017/* mcctlcommand */
18#define CCTL_REG_MCCTLCOMMAND_NUM 0x7cc
19
20/* D-cache operation */
21#define CCTL_L1D_WBINVAL_ALL 6
22#endif
Rick Chen883275d2019-11-14 13:52:25 +080023#endif
24
25#ifdef CONFIG_V5L2_CACHE
26static void _cache_enable(void)
27{
28 struct udevice *dev = NULL;
29
30 uclass_find_first_device(UCLASS_CACHE, &dev);
31
32 if (dev)
33 cache_enable(dev);
34}
35
36static void _cache_disable(void)
37{
38 struct udevice *dev = NULL;
39
40 uclass_find_first_device(UCLASS_CACHE, &dev);
41
42 if (dev)
43 cache_disable(dev);
44}
45#endif
Rick Chen842d5802018-11-07 09:34:06 +080046
Lukas Auer6280e322019-01-04 01:37:29 +010047void flush_dcache_all(void)
48{
Rick Chen883275d2019-11-14 13:52:25 +080049#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Rick Chen49cb7062019-08-28 18:46:11 +080050#ifdef CONFIG_RISCV_NDS_CACHE
Pragnesh Pateld12b55b2020-03-14 19:12:28 +053051#if CONFIG_IS_ENABLED(RISCV_MMODE)
Rick Chen49cb7062019-08-28 18:46:11 +080052 csr_write(CCTL_REG_MCCTLCOMMAND_NUM, CCTL_L1D_WBINVAL_ALL);
53#endif
Rick Chen883275d2019-11-14 13:52:25 +080054#endif
55#endif
Lukas Auer6280e322019-01-04 01:37:29 +010056}
57
58void flush_dcache_range(unsigned long start, unsigned long end)
59{
60 flush_dcache_all();
61}
62
63void invalidate_dcache_range(unsigned long start, unsigned long end)
64{
65 flush_dcache_all();
66}
67
Rick Chen842d5802018-11-07 09:34:06 +080068void icache_enable(void)
69{
Rick Chen842d5802018-11-07 09:34:06 +080070}
71
72void icache_disable(void)
73{
Rick Chen842d5802018-11-07 09:34:06 +080074}
75
76void dcache_enable(void)
77{
Rick Chen842d5802018-11-07 09:34:06 +080078}
79
80void dcache_disable(void)
81{
Rick Chen842d5802018-11-07 09:34:06 +080082}
83
84int icache_status(void)
85{
Leo Yu-Chi Liang816979a2023-02-06 16:10:44 +080086 return 0;
Rick Chen842d5802018-11-07 09:34:06 +080087}
88
89int dcache_status(void)
90{
Leo Yu-Chi Liang816979a2023-02-06 16:10:44 +080091 return 0;
Rick Chen842d5802018-11-07 09:34:06 +080092}