blob: 2f49ce86816fb78ddb00be08ace8c5d6affc01b9 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +09002/*
Vladimir Zapolskiyf34743c2016-11-28 00:15:18 +02003 * (C) Copyright 2016 Vladimir Zapolskiy <vz@mleia.com>
4 * (C) Copyright 2007 Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +09005 */
6
7#include <common.h>
8#include <command.h>
Simon Glass1d91ba72019-11-14 12:57:37 -07009#include <cpu_func.h>
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090010#include <asm/io.h>
Vladimir Zapolskiy57e56ef2016-11-28 00:15:16 +020011#include <asm/processor.h>
12#include <asm/system.h>
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090013
14#define CACHE_VALID 1
15#define CACHE_UPDATED 2
16
17static inline void cache_wback_all(void)
18{
19 unsigned long addr, data, i, j;
20
Vladimir Zapolskiye8529962016-11-28 00:15:17 +020021 for (i = 0; i < CACHE_OC_NUM_ENTRIES; i++) {
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090022 for (j = 0; j < CACHE_OC_NUM_WAYS; j++) {
Vladimir Zapolskiye8529962016-11-28 00:15:17 +020023 addr = CACHE_OC_ADDRESS_ARRAY
24 | (j << CACHE_OC_WAY_SHIFT)
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090025 | (i << CACHE_OC_ENTRY_SHIFT);
Wolfgang Denka1be4762008-05-20 16:00:29 +020026 data = inl(addr);
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090027 if (data & CACHE_UPDATED) {
28 data &= ~CACHE_UPDATED;
29 outl(data, addr);
30 }
31 }
32 }
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090033}
34
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090035#define CACHE_ENABLE 0
36#define CACHE_DISABLE 1
37
Vladimir Zapolskiyf34743c2016-11-28 00:15:18 +020038static int cache_control(unsigned int cmd)
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090039{
40 unsigned long ccr;
41
42 jump_to_P2();
43 ccr = inl(CCR);
44
45 if (ccr & CCR_CACHE_ENABLE)
46 cache_wback_all();
47
48 if (cmd == CACHE_DISABLE)
49 outl(CCR_CACHE_STOP, CCR);
50 else
51 outl(CCR_CACHE_INIT, CCR);
52 back_to_P1();
53
54 return 0;
55}
Mike Frysingerb99910e2011-10-27 04:59:59 -040056
Nobuhiro Iwamatsu5b96baf2013-08-22 08:43:47 +090057void flush_dcache_range(unsigned long start, unsigned long end)
Mike Frysingerb99910e2011-10-27 04:59:59 -040058{
59 u32 v;
60
61 start &= ~(L1_CACHE_BYTES - 1);
62 for (v = start; v < end; v += L1_CACHE_BYTES) {
Vladimir Zapolskiy7a22f7a2016-11-28 00:15:13 +020063 asm volatile ("ocbp %0" : /* no output */
Mike Frysingerb99910e2011-10-27 04:59:59 -040064 : "m" (__m(v)));
65 }
66}
67
Nobuhiro Iwamatsu5b96baf2013-08-22 08:43:47 +090068void invalidate_dcache_range(unsigned long start, unsigned long end)
Mike Frysingerb99910e2011-10-27 04:59:59 -040069{
70 u32 v;
71
72 start &= ~(L1_CACHE_BYTES - 1);
73 for (v = start; v < end; v += L1_CACHE_BYTES) {
74 asm volatile ("ocbi %0" : /* no output */
75 : "m" (__m(v)));
76 }
77}
Vladimir Zapolskiyf34743c2016-11-28 00:15:18 +020078
79void flush_cache(unsigned long addr, unsigned long size)
80{
81 flush_dcache_range(addr , addr + size);
82}
83
84void icache_enable(void)
85{
86 cache_control(CACHE_ENABLE);
87}
88
89void icache_disable(void)
90{
91 cache_control(CACHE_DISABLE);
92}
93
94int icache_status(void)
95{
96 return 0;
97}
98
99void dcache_enable(void)
100{
101}
102
103void dcache_disable(void)
104{
105}
106
107int dcache_status(void)
108{
109 return 0;
110}