Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 1 | /* |
| 2 | * U-boot - blackfin_local.h |
| 3 | * |
| 4 | * Copyright (c) 2005-2007 Analog Devices Inc. |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
| 22 | * MA 02110-1301 USA |
| 23 | */ |
| 24 | |
| 25 | #ifndef __BLACKFIN_LOCAL_H__ |
| 26 | #define __BLACKFIN_LOCAL_H__ |
| 27 | |
Mike Frysinger | dc6bc64 | 2009-11-11 19:08:33 -0500 | [diff] [blame] | 28 | #include <asm/mem_map.h> |
| 29 | |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 30 | #define LO(con32) ((con32) & 0xFFFF) |
| 31 | #define lo(con32) ((con32) & 0xFFFF) |
| 32 | #define HI(con32) (((con32) >> 16) & 0xFFFF) |
| 33 | #define hi(con32) (((con32) >> 16) & 0xFFFF) |
| 34 | |
| 35 | #define OFFSET_(x) (x & 0x0000FFFF) |
| 36 | #define MK_BMSK_(x) (1 << x) |
| 37 | |
| 38 | /* Ideally this should be USEC not MSEC, but the USEC multiplication |
| 39 | * likes to overflow 32bit quantities which is all our assembler |
| 40 | * currently supports ;( |
| 41 | */ |
| 42 | #define USEC_PER_MSEC 1000 |
| 43 | #define MSEC_PER_SEC 1000 |
| 44 | #define BFIN_SCLK (100000000) |
| 45 | #define SCLK_TO_MSEC(sclk) ((MSEC_PER_SEC * ((sclk) / USEC_PER_MSEC)) / (BFIN_SCLK / USEC_PER_MSEC)) |
| 46 | #define MSEC_TO_SCLK(msec) ((((BFIN_SCLK / USEC_PER_MSEC) * (msec)) / MSEC_PER_SEC) * USEC_PER_MSEC) |
| 47 | |
Mike Frysinger | fdce83c | 2008-11-04 00:04:03 -0500 | [diff] [blame] | 48 | #define L1_CACHE_SHIFT 5 |
| 49 | #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT) |
| 50 | |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 51 | #include <asm/linkage.h> |
| 52 | |
| 53 | #ifndef __ASSEMBLY__ |
| 54 | # ifdef SHARED_RESOURCES |
| 55 | # include <asm/shared_resources.h> |
| 56 | # endif |
| 57 | |
| 58 | # include <linux/types.h> |
| 59 | |
Mike Frysinger | 4059923 | 2008-10-24 22:48:47 -0400 | [diff] [blame] | 60 | extern u_long get_vco(void); |
| 61 | extern u_long get_cclk(void); |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 62 | extern u_long get_sclk(void); |
| 63 | |
Mike Frysinger | f948158 | 2009-11-12 18:42:53 -0500 | [diff] [blame] | 64 | # define bfin_revid() (bfin_read_CHIPID() >> 28) |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 65 | |
Mike Frysinger | 909878f | 2009-07-09 01:15:05 -0400 | [diff] [blame] | 66 | extern bool bfin_os_log_check(void); |
| 67 | extern void bfin_os_log_dump(void); |
| 68 | |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 69 | extern void blackfin_icache_flush_range(const void *, const void *); |
| 70 | extern void blackfin_dcache_flush_range(const void *, const void *); |
Mike Frysinger | fdce83c | 2008-11-04 00:04:03 -0500 | [diff] [blame] | 71 | extern void blackfin_icache_dcache_flush_range(const void *, const void *); |
Mike Frysinger | 05b75e4 | 2008-10-06 03:35:44 -0400 | [diff] [blame] | 72 | extern void blackfin_dcache_flush_invalidate_range(const void *, const void *); |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 73 | |
Mike Frysinger | b93c686 | 2008-11-05 08:50:23 -0500 | [diff] [blame] | 74 | /* Use DMA to move data from on chip to external memory. The L1 instruction |
| 75 | * regions can only be accessed via DMA, so if the address in question is in |
| 76 | * that region, make sure we attempt to DMA indirectly. |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 77 | */ |
Mike Frysinger | bbf4fbb | 2010-06-04 16:15:38 -0400 | [diff] [blame] | 78 | # ifdef __ADSPBF561__ |
| 79 | /* Core B regions all need dma from Core A */ |
| 80 | # define addr_bfin_on_chip_mem(addr) \ |
| 81 | ((((unsigned long)(addr) & 0xFFF00000) == 0xFFA00000) || \ |
| 82 | (((unsigned long)(addr) & 0xFFC00000) == 0xFF400000)) |
| 83 | # else |
| 84 | # define addr_bfin_on_chip_mem(addr) \ |
| 85 | (((unsigned long)(addr) & 0xFFF00000) == 0xFFA00000) |
| 86 | # endif |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 87 | |
| 88 | # include <asm/system.h> |
| 89 | |
| 90 | #if ANOMALY_05000198 |
| 91 | # define NOP_PAD_ANOMALY_05000198 "nop;" |
| 92 | #else |
| 93 | # define NOP_PAD_ANOMALY_05000198 |
| 94 | #endif |
| 95 | |
Mike Frysinger | 7ed998f | 2011-05-14 10:20:25 -0400 | [diff] [blame] | 96 | #define _bfin_readX(addr, size, asm_size, asm_ext) ({ \ |
| 97 | u32 __v; \ |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 98 | __asm__ __volatile__( \ |
| 99 | NOP_PAD_ANOMALY_05000198 \ |
Mike Frysinger | 7ed998f | 2011-05-14 10:20:25 -0400 | [diff] [blame] | 100 | "%0 = " #asm_size "[%1]" #asm_ext ";" \ |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 101 | : "=d" (__v) \ |
| 102 | : "a" (addr) \ |
| 103 | ); \ |
| 104 | __v; }) |
Mike Frysinger | 7ed998f | 2011-05-14 10:20:25 -0400 | [diff] [blame] | 105 | #define _bfin_writeX(addr, val, size, asm_size) \ |
| 106 | __asm__ __volatile__( \ |
| 107 | NOP_PAD_ANOMALY_05000198 \ |
| 108 | #asm_size "[%0] = %1;" \ |
| 109 | : \ |
| 110 | : "a" (addr), "d" ((u##size)(val)) \ |
| 111 | : "memory" \ |
| 112 | ) |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 113 | |
Mike Frysinger | 7ed998f | 2011-05-14 10:20:25 -0400 | [diff] [blame] | 114 | #define bfin_read8(addr) _bfin_readX(addr, 8, b, (z)) |
| 115 | #define bfin_read16(addr) _bfin_readX(addr, 16, w, (z)) |
| 116 | #define bfin_read32(addr) _bfin_readX(addr, 32, , ) |
| 117 | #define bfin_write8(addr, val) _bfin_writeX(addr, val, 8, b) |
| 118 | #define bfin_write16(addr, val) _bfin_writeX(addr, val, 16, w) |
| 119 | #define bfin_write32(addr, val) _bfin_writeX(addr, val, 32, ) |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 120 | |
Mike Frysinger | 7ed998f | 2011-05-14 10:20:25 -0400 | [diff] [blame] | 121 | #define bfin_read(addr) \ |
| 122 | ({ \ |
| 123 | sizeof(*(addr)) == 1 ? bfin_read8(addr) : \ |
| 124 | sizeof(*(addr)) == 2 ? bfin_read16(addr) : \ |
| 125 | sizeof(*(addr)) == 4 ? bfin_read32(addr) : \ |
| 126 | ({ BUG(); 0; }); \ |
| 127 | }) |
| 128 | #define bfin_write(addr, val) \ |
| 129 | do { \ |
| 130 | switch (sizeof(*(addr))) { \ |
| 131 | case 1: bfin_write8(addr, val); break; \ |
| 132 | case 2: bfin_write16(addr, val); break; \ |
| 133 | case 4: bfin_write32(addr, val); break; \ |
| 134 | default: BUG(); \ |
| 135 | } \ |
| 136 | } while (0) |
| 137 | |
| 138 | #define bfin_write_or(addr, bits) \ |
| 139 | do { \ |
| 140 | typeof(addr) __addr = (addr); \ |
| 141 | bfin_write(__addr, bfin_read(__addr) | (bits)); \ |
| 142 | } while (0) |
| 143 | |
| 144 | #define bfin_write_and(addr, bits) \ |
| 145 | do { \ |
| 146 | typeof(addr) __addr = (addr); \ |
| 147 | bfin_write(__addr, bfin_read(__addr) & (bits)); \ |
| 148 | } while (0) |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 149 | |
| 150 | #define bfin_readPTR(addr) bfin_read32(addr) |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 151 | #define bfin_writePTR(addr, val) bfin_write32(addr, val) |
| 152 | |
| 153 | /* SSYNC implementation for C file */ |
| 154 | static inline void SSYNC(void) |
| 155 | { |
| 156 | int _tmp; |
| 157 | if (ANOMALY_05000312) |
| 158 | __asm__ __volatile__( |
| 159 | "cli %0;" |
| 160 | "nop;" |
| 161 | "nop;" |
| 162 | "ssync;" |
| 163 | "sti %0;" |
| 164 | : "=d" (_tmp) |
| 165 | ); |
| 166 | else if (ANOMALY_05000244) |
| 167 | __asm__ __volatile__( |
| 168 | "nop;" |
| 169 | "nop;" |
| 170 | "nop;" |
| 171 | "ssync;" |
| 172 | ); |
| 173 | else |
| 174 | __asm__ __volatile__("ssync;"); |
| 175 | } |
| 176 | |
| 177 | /* CSYNC implementation for C file */ |
| 178 | static inline void CSYNC(void) |
| 179 | { |
| 180 | int _tmp; |
| 181 | if (ANOMALY_05000312) |
| 182 | __asm__ __volatile__( |
| 183 | "cli %0;" |
| 184 | "nop;" |
| 185 | "nop;" |
| 186 | "csync;" |
| 187 | "sti %0;" |
| 188 | : "=d" (_tmp) |
| 189 | ); |
| 190 | else if (ANOMALY_05000244) |
| 191 | __asm__ __volatile__( |
| 192 | "nop;" |
| 193 | "nop;" |
| 194 | "nop;" |
| 195 | "csync;" |
| 196 | ); |
| 197 | else |
| 198 | __asm__ __volatile__("csync;"); |
| 199 | } |
| 200 | |
| 201 | #else /* __ASSEMBLY__ */ |
| 202 | |
| 203 | /* SSYNC & CSYNC implementations for assembly files */ |
| 204 | |
| 205 | #define ssync(x) SSYNC(x) |
| 206 | #define csync(x) CSYNC(x) |
| 207 | |
| 208 | #if ANOMALY_05000312 |
| 209 | #define SSYNC(scratch) cli scratch; nop; nop; SSYNC; sti scratch; |
| 210 | #define CSYNC(scratch) cli scratch; nop; nop; CSYNC; sti scratch; |
| 211 | |
| 212 | #elif ANOMALY_05000244 |
| 213 | #define SSYNC(scratch) nop; nop; nop; SSYNC; |
| 214 | #define CSYNC(scratch) nop; nop; nop; CSYNC; |
| 215 | |
| 216 | #else |
| 217 | #define SSYNC(scratch) SSYNC; |
| 218 | #define CSYNC(scratch) CSYNC; |
| 219 | |
| 220 | #endif /* ANOMALY_05000312 & ANOMALY_05000244 handling */ |
| 221 | |
| 222 | #endif /* __ASSEMBLY__ */ |
| 223 | |
| 224 | #endif |