wdenk | 4e5ca3e | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 1 | /* |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 2 | * (C) Copyright 2002 |
wdenk | 4e5ca3e | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
TsiChung Liew | dd9f054 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 25 | #include <asm/immap.h> |
| 26 | #include <asm/cache.h> |
wdenk | 4e5ca3e | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 27 | |
TsiChung Liew | dd9f054 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 28 | volatile int *cf_icache_status = (int *)ICACHE_STATUS; |
| 29 | volatile int *cf_dcache_status = (int *)DCACHE_STATUS; |
| 30 | |
| 31 | void flush_cache(ulong start_addr, ulong size) |
wdenk | 4e5ca3e | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 32 | { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 33 | /* Must be implemented for all M68k processors with copy-back data cache */ |
wdenk | 4e5ca3e | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 34 | } |
TsiChung Liew | dd9f054 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 35 | |
| 36 | int icache_status(void) |
| 37 | { |
| 38 | return *cf_icache_status; |
| 39 | } |
| 40 | |
| 41 | int dcache_status(void) |
| 42 | { |
| 43 | return *cf_dcache_status; |
| 44 | } |
| 45 | |
| 46 | void icache_enable(void) |
| 47 | { |
| 48 | icache_invalid(); |
| 49 | |
| 50 | *cf_icache_status = 1; |
| 51 | |
| 52 | #ifdef CONFIG_CF_V4 |
| 53 | __asm__ __volatile__("movec %0, %%acr2"::"r"(CONFIG_SYS_CACHE_ACR2)); |
| 54 | __asm__ __volatile__("movec %0, %%acr3"::"r"(CONFIG_SYS_CACHE_ACR3)); |
| 55 | #elif defined(CONFIG_CF_V4e) |
| 56 | __asm__ __volatile__("movec %0, %%acr6"::"r"(CONFIG_SYS_CACHE_ACR6)); |
| 57 | __asm__ __volatile__("movec %0, %%acr7"::"r"(CONFIG_SYS_CACHE_ACR7)); |
| 58 | #else |
| 59 | __asm__ __volatile__("movec %0, %%acr0"::"r"(CONFIG_SYS_CACHE_ACR0)); |
| 60 | __asm__ __volatile__("movec %0, %%acr1"::"r"(CONFIG_SYS_CACHE_ACR1)); |
| 61 | #endif |
| 62 | |
| 63 | __asm__ __volatile__("movec %0, %%cacr"::"r"(CONFIG_SYS_CACHE_ICACR)); |
| 64 | } |
| 65 | |
| 66 | void icache_disable(void) |
| 67 | { |
| 68 | u32 temp = 0; |
| 69 | |
| 70 | *cf_icache_status = 0; |
| 71 | icache_invalid(); |
| 72 | |
| 73 | #ifdef CONFIG_CF_V4 |
| 74 | __asm__ __volatile__("movec %0, %%acr2"::"r"(temp)); |
| 75 | __asm__ __volatile__("movec %0, %%acr3"::"r"(temp)); |
| 76 | #elif defined(CONFIG_CF_V4e) |
| 77 | __asm__ __volatile__("movec %0, %%acr6"::"r"(temp)); |
| 78 | __asm__ __volatile__("movec %0, %%acr7"::"r"(temp)); |
| 79 | #else |
| 80 | __asm__ __volatile__("movec %0, %%acr0"::"r"(temp)); |
| 81 | __asm__ __volatile__("movec %0, %%acr1"::"r"(temp)); |
| 82 | |
| 83 | #endif |
| 84 | } |
| 85 | |
| 86 | void icache_invalid(void) |
| 87 | { |
| 88 | u32 temp; |
| 89 | |
| 90 | temp = CONFIG_SYS_ICACHE_INV; |
| 91 | if (*cf_icache_status) |
| 92 | temp |= CONFIG_SYS_CACHE_ICACR; |
| 93 | |
| 94 | __asm__ __volatile__("movec %0, %%cacr"::"r"(temp)); |
| 95 | } |
| 96 | |
| 97 | /* |
| 98 | * data cache only for ColdFire V4 such as MCF547x_8x, MCF5445x |
| 99 | * the dcache will be dummy in ColdFire V2 and V3 |
| 100 | */ |
| 101 | void dcache_enable(void) |
| 102 | { |
| 103 | dcache_invalid(); |
| 104 | *cf_dcache_status = 1; |
| 105 | |
| 106 | #ifdef CONFIG_CF_V4 |
| 107 | __asm__ __volatile__("movec %0, %%acr0"::"r"(CONFIG_SYS_CACHE_ACR0)); |
| 108 | __asm__ __volatile__("movec %0, %%acr1"::"r"(CONFIG_SYS_CACHE_ACR1)); |
| 109 | #elif defined(CONFIG_CF_V4e) |
| 110 | __asm__ __volatile__("movec %0, %%acr4"::"r"(CONFIG_SYS_CACHE_ACR4)); |
| 111 | __asm__ __volatile__("movec %0, %%acr5"::"r"(CONFIG_SYS_CACHE_ACR5)); |
| 112 | |
| 113 | #endif |
| 114 | |
| 115 | __asm__ __volatile__("movec %0, %%cacr"::"r"(CONFIG_SYS_CACHE_DCACR)); |
| 116 | } |
| 117 | |
| 118 | void dcache_disable(void) |
| 119 | { |
| 120 | u32 temp = 0; |
| 121 | |
| 122 | *cf_dcache_status = 0; |
| 123 | dcache_invalid(); |
| 124 | |
| 125 | __asm__ __volatile__("movec %0, %%cacr"::"r"(temp)); |
| 126 | |
| 127 | #ifdef CONFIG_CF_V4 |
| 128 | __asm__ __volatile__("movec %0, %%acr0"::"r"(temp)); |
| 129 | __asm__ __volatile__("movec %0, %%acr1"::"r"(temp)); |
| 130 | #elif defined(CONFIG_CF_V4e) |
| 131 | __asm__ __volatile__("movec %0, %%acr4"::"r"(temp)); |
| 132 | __asm__ __volatile__("movec %0, %%acr5"::"r"(temp)); |
| 133 | |
| 134 | #endif |
| 135 | } |
| 136 | |
| 137 | void dcache_invalid(void) |
| 138 | { |
| 139 | #ifdef CONFIG_CF_V4 |
| 140 | u32 temp; |
| 141 | |
| 142 | temp = CONFIG_SYS_DCACHE_INV; |
| 143 | if (*cf_dcache_status) |
| 144 | temp |= CONFIG_SYS_CACHE_DCACR; |
| 145 | if (*cf_icache_status) |
| 146 | temp |= CONFIG_SYS_CACHE_ICACR; |
| 147 | |
| 148 | __asm__ __volatile__("movec %0, %%cacr"::"r"(temp)); |
| 149 | #endif |
| 150 | } |