blob: 57e5632fdb5b81fb3c9425e953c67f372777ae8b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenkabf7a7c2003-12-08 01:34:36 +00002/*
wdenke65527f2004-02-12 00:47:09 +00003 * (C) Copyright 2002
wdenkabf7a7c2003-12-08 01:34:36 +00004 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenkabf7a7c2003-12-08 01:34:36 +00005 */
6
7#include <common.h>
Simon Glass1d91ba72019-11-14 12:57:37 -07008#include <cpu_func.h>
TsiChung Liew0ee47d42010-03-11 22:12:53 -06009#include <asm/immap.h>
10#include <asm/cache.h>
wdenkabf7a7c2003-12-08 01:34:36 +000011
TsiChung Liew0ee47d42010-03-11 22:12:53 -060012volatile int *cf_icache_status = (int *)ICACHE_STATUS;
13volatile int *cf_dcache_status = (int *)DCACHE_STATUS;
14
15void flush_cache(ulong start_addr, ulong size)
wdenkabf7a7c2003-12-08 01:34:36 +000016{
wdenke65527f2004-02-12 00:47:09 +000017 /* Must be implemented for all M68k processors with copy-back data cache */
wdenkabf7a7c2003-12-08 01:34:36 +000018}
TsiChung Liew0ee47d42010-03-11 22:12:53 -060019
20int icache_status(void)
21{
22 return *cf_icache_status;
23}
24
25int dcache_status(void)
26{
27 return *cf_dcache_status;
28}
29
30void icache_enable(void)
31{
32 icache_invalid();
33
34 *cf_icache_status = 1;
35
Tom Rini364d0022023-01-10 11:19:45 -050036#if defined(CONFIG_CF_V4) || defined(CFG_CF_V4E)
Tom Rini6a5dccc2022-11-16 13:10:41 -050037 __asm__ __volatile__("movec %0, %%acr2"::"r"(CFG_SYS_CACHE_ACR2));
Tom Rini364d0022023-01-10 11:19:45 -050038 __asm__ __volatile__("movec %0, %%acr3"::"r"(CFG_SYS_CACHE_ACR3));
39#if defined(CFG_CF_V4E)
40 __asm__ __volatile__("movec %0, %%acr6"::"r"(CFG_SYS_CACHE_ACR6));
41 __asm__ __volatile__("movec %0, %%acr7"::"r"(CFG_SYS_CACHE_ACR7));
Angelo Dureghello8ddcf382017-05-31 21:32:48 +020042#endif
TsiChung Liew0ee47d42010-03-11 22:12:53 -060043#else
Tom Rini6a5dccc2022-11-16 13:10:41 -050044 __asm__ __volatile__("movec %0, %%acr0"::"r"(CFG_SYS_CACHE_ACR0));
45 __asm__ __volatile__("movec %0, %%acr1"::"r"(CFG_SYS_CACHE_ACR1));
TsiChung Liew0ee47d42010-03-11 22:12:53 -060046#endif
47
Tom Rini6a5dccc2022-11-16 13:10:41 -050048 __asm__ __volatile__("movec %0, %%cacr"::"r"(CFG_SYS_CACHE_ICACR));
TsiChung Liew0ee47d42010-03-11 22:12:53 -060049}
50
51void icache_disable(void)
52{
53 u32 temp = 0;
54
55 *cf_icache_status = 0;
56 icache_invalid();
57
Tom Rini364d0022023-01-10 11:19:45 -050058#if defined(CONFIG_CF_V4) || defined(CFG_CF_V4E)
TsiChung Liew0ee47d42010-03-11 22:12:53 -060059 __asm__ __volatile__("movec %0, %%acr2"::"r"(temp));
60 __asm__ __volatile__("movec %0, %%acr3"::"r"(temp));
Tom Rini364d0022023-01-10 11:19:45 -050061#if defined(CFG_CF_V4E)
TsiChung Liew0ee47d42010-03-11 22:12:53 -060062 __asm__ __volatile__("movec %0, %%acr6"::"r"(temp));
63 __asm__ __volatile__("movec %0, %%acr7"::"r"(temp));
Angelo Dureghello8ddcf382017-05-31 21:32:48 +020064#endif
TsiChung Liew0ee47d42010-03-11 22:12:53 -060065#else
66 __asm__ __volatile__("movec %0, %%acr0"::"r"(temp));
67 __asm__ __volatile__("movec %0, %%acr1"::"r"(temp));
TsiChung Liew0ee47d42010-03-11 22:12:53 -060068#endif
69}
70
71void icache_invalid(void)
72{
73 u32 temp;
74
Tom Rini6a5dccc2022-11-16 13:10:41 -050075 temp = CFG_SYS_ICACHE_INV;
TsiChung Liew0ee47d42010-03-11 22:12:53 -060076 if (*cf_icache_status)
Tom Rini6a5dccc2022-11-16 13:10:41 -050077 temp |= CFG_SYS_CACHE_ICACR;
TsiChung Liew0ee47d42010-03-11 22:12:53 -060078
79 __asm__ __volatile__("movec %0, %%cacr"::"r"(temp));
80}
81
82/*
Tom Rini7ab2f5f2021-05-14 21:34:10 -040083 * data cache only for ColdFire V4 such as MCF5445x
TsiChung Liew0ee47d42010-03-11 22:12:53 -060084 * the dcache will be dummy in ColdFire V2 and V3
85 */
86void dcache_enable(void)
87{
88 dcache_invalid();
89 *cf_dcache_status = 1;
90
Tom Rini364d0022023-01-10 11:19:45 -050091#if defined(CONFIG_CF_V4) || defined(CFG_CF_V4E)
Tom Rini6a5dccc2022-11-16 13:10:41 -050092 __asm__ __volatile__("movec %0, %%acr0"::"r"(CFG_SYS_CACHE_ACR0));
93 __asm__ __volatile__("movec %0, %%acr1"::"r"(CFG_SYS_CACHE_ACR1));
Tom Rini364d0022023-01-10 11:19:45 -050094#if defined(CFG_CF_V4E)
95 __asm__ __volatile__("movec %0, %%acr4"::"r"(CFG_SYS_CACHE_ACR4));
96 __asm__ __volatile__("movec %0, %%acr5"::"r"(CFG_SYS_CACHE_ACR5));
Angelo Dureghello8ddcf382017-05-31 21:32:48 +020097#endif
TsiChung Liew0ee47d42010-03-11 22:12:53 -060098#endif
99
Tom Rini6a5dccc2022-11-16 13:10:41 -0500100 __asm__ __volatile__("movec %0, %%cacr"::"r"(CFG_SYS_CACHE_DCACR));
TsiChung Liew0ee47d42010-03-11 22:12:53 -0600101}
102
103void dcache_disable(void)
104{
105 u32 temp = 0;
106
107 *cf_dcache_status = 0;
108 dcache_invalid();
109
110 __asm__ __volatile__("movec %0, %%cacr"::"r"(temp));
111
Tom Rini364d0022023-01-10 11:19:45 -0500112#if defined(CONFIG_CF_V4) || defined(CFG_CF_V4E)
TsiChung Liew0ee47d42010-03-11 22:12:53 -0600113 __asm__ __volatile__("movec %0, %%acr0"::"r"(temp));
114 __asm__ __volatile__("movec %0, %%acr1"::"r"(temp));
Tom Rini364d0022023-01-10 11:19:45 -0500115#if defined(CFG_CF_V4E)
TsiChung Liew0ee47d42010-03-11 22:12:53 -0600116 __asm__ __volatile__("movec %0, %%acr4"::"r"(temp));
117 __asm__ __volatile__("movec %0, %%acr5"::"r"(temp));
Angelo Dureghello8ddcf382017-05-31 21:32:48 +0200118#endif
TsiChung Liew0ee47d42010-03-11 22:12:53 -0600119#endif
120}
121
122void dcache_invalid(void)
123{
Tom Rini364d0022023-01-10 11:19:45 -0500124#if defined(CONFIG_CF_V4) || defined(CFG_CF_V4E)
TsiChung Liew0ee47d42010-03-11 22:12:53 -0600125 u32 temp;
126
Tom Rini6a5dccc2022-11-16 13:10:41 -0500127 temp = CFG_SYS_DCACHE_INV;
TsiChung Liew0ee47d42010-03-11 22:12:53 -0600128 if (*cf_dcache_status)
Tom Rini6a5dccc2022-11-16 13:10:41 -0500129 temp |= CFG_SYS_CACHE_DCACR;
TsiChung Liew0ee47d42010-03-11 22:12:53 -0600130 if (*cf_icache_status)
Tom Rini6a5dccc2022-11-16 13:10:41 -0500131 temp |= CFG_SYS_CACHE_ICACR;
TsiChung Liew0ee47d42010-03-11 22:12:53 -0600132
133 __asm__ __volatile__("movec %0, %%cacr"::"r"(temp));
134#endif
135}
Wu, Josh22f483c2015-07-27 11:40:15 +0800136
137__weak void invalidate_dcache_range(unsigned long start, unsigned long stop)
138{
139 /* An empty stub, real implementation should be in platform code */
140}
141__weak void flush_dcache_range(unsigned long start, unsigned long stop)
142{
143 /* An empty stub, real implementation should be in platform code */
144}