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 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef __BLACKFIN_LOCAL_H__ |
| 10 | #define __BLACKFIN_LOCAL_H__ |
| 11 | |
Mike Frysinger | dc6bc64 | 2009-11-11 19:08:33 -0500 | [diff] [blame] | 12 | #include <asm/mem_map.h> |
| 13 | |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 14 | #define LO(con32) ((con32) & 0xFFFF) |
| 15 | #define lo(con32) ((con32) & 0xFFFF) |
| 16 | #define HI(con32) (((con32) >> 16) & 0xFFFF) |
| 17 | #define hi(con32) (((con32) >> 16) & 0xFFFF) |
| 18 | |
| 19 | #define OFFSET_(x) (x & 0x0000FFFF) |
| 20 | #define MK_BMSK_(x) (1 << x) |
| 21 | |
| 22 | /* Ideally this should be USEC not MSEC, but the USEC multiplication |
| 23 | * likes to overflow 32bit quantities which is all our assembler |
| 24 | * currently supports ;( |
| 25 | */ |
| 26 | #define USEC_PER_MSEC 1000 |
| 27 | #define MSEC_PER_SEC 1000 |
| 28 | #define BFIN_SCLK (100000000) |
| 29 | #define SCLK_TO_MSEC(sclk) ((MSEC_PER_SEC * ((sclk) / USEC_PER_MSEC)) / (BFIN_SCLK / USEC_PER_MSEC)) |
| 30 | #define MSEC_TO_SCLK(msec) ((((BFIN_SCLK / USEC_PER_MSEC) * (msec)) / MSEC_PER_SEC) * USEC_PER_MSEC) |
| 31 | |
Mike Frysinger | fdce83c | 2008-11-04 00:04:03 -0500 | [diff] [blame] | 32 | #define L1_CACHE_SHIFT 5 |
| 33 | #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT) |
| 34 | |
Macpaul Lin | 273d11e | 2011-12-01 12:32:10 +0800 | [diff] [blame] | 35 | #include <linux/linkage.h> |
Mike Frysinger | 8e5c1ed | 2011-10-12 20:16:31 -0400 | [diff] [blame] | 36 | #include <asm/cache.h> |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 37 | |
| 38 | #ifndef __ASSEMBLY__ |
| 39 | # ifdef SHARED_RESOURCES |
| 40 | # include <asm/shared_resources.h> |
| 41 | # endif |
| 42 | |
| 43 | # include <linux/types.h> |
| 44 | |
Mike Frysinger | 4059923 | 2008-10-24 22:48:47 -0400 | [diff] [blame] | 45 | extern u_long get_vco(void); |
| 46 | extern u_long get_cclk(void); |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 47 | extern u_long get_sclk(void); |
Bob Liu | 3ead92c | 2012-08-16 11:10:41 +0800 | [diff] [blame] | 48 | extern u_long get_sclk0(void); |
| 49 | extern u_long get_sclk1(void); |
| 50 | extern u_long get_dclk(void); |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 51 | |
Mike Frysinger | f948158 | 2009-11-12 18:42:53 -0500 | [diff] [blame] | 52 | # define bfin_revid() (bfin_read_CHIPID() >> 28) |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 53 | |
Wolfgang Denk | a5750b8 | 2013-11-19 08:01:44 +0100 | [diff] [blame] | 54 | extern int bfin_os_log_check(void); |
Mike Frysinger | 909878f | 2009-07-09 01:15:05 -0400 | [diff] [blame] | 55 | extern void bfin_os_log_dump(void); |
| 56 | |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 57 | extern void blackfin_icache_flush_range(const void *, const void *); |
| 58 | extern void blackfin_dcache_flush_range(const void *, const void *); |
Mike Frysinger | fdce83c | 2008-11-04 00:04:03 -0500 | [diff] [blame] | 59 | extern void blackfin_icache_dcache_flush_range(const void *, const void *); |
Mike Frysinger | 05b75e4 | 2008-10-06 03:35:44 -0400 | [diff] [blame] | 60 | extern void blackfin_dcache_flush_invalidate_range(const void *, const void *); |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 61 | |
Mike Frysinger | b93c686 | 2008-11-05 08:50:23 -0500 | [diff] [blame] | 62 | /* Use DMA to move data from on chip to external memory. The L1 instruction |
| 63 | * regions can only be accessed via DMA, so if the address in question is in |
| 64 | * that region, make sure we attempt to DMA indirectly. |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 65 | */ |
Mike Frysinger | bbf4fbb | 2010-06-04 16:15:38 -0400 | [diff] [blame] | 66 | # ifdef __ADSPBF561__ |
| 67 | /* Core B regions all need dma from Core A */ |
| 68 | # define addr_bfin_on_chip_mem(addr) \ |
| 69 | ((((unsigned long)(addr) & 0xFFF00000) == 0xFFA00000) || \ |
| 70 | (((unsigned long)(addr) & 0xFFC00000) == 0xFF400000)) |
| 71 | # else |
| 72 | # define addr_bfin_on_chip_mem(addr) \ |
| 73 | (((unsigned long)(addr) & 0xFFF00000) == 0xFFA00000) |
| 74 | # endif |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 75 | |
| 76 | # include <asm/system.h> |
| 77 | |
| 78 | #if ANOMALY_05000198 |
| 79 | # define NOP_PAD_ANOMALY_05000198 "nop;" |
| 80 | #else |
| 81 | # define NOP_PAD_ANOMALY_05000198 |
| 82 | #endif |
| 83 | |
Sonic Zhang | ecf9ce2 | 2013-12-09 14:55:21 +0800 | [diff] [blame] | 84 | #define BFIN_BUG() while (1) asm volatile("emuexcpt;"); |
| 85 | |
Mike Frysinger | 7ed998f | 2011-05-14 10:20:25 -0400 | [diff] [blame] | 86 | #define _bfin_readX(addr, size, asm_size, asm_ext) ({ \ |
| 87 | u32 __v; \ |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 88 | __asm__ __volatile__( \ |
| 89 | NOP_PAD_ANOMALY_05000198 \ |
Mike Frysinger | 7ed998f | 2011-05-14 10:20:25 -0400 | [diff] [blame] | 90 | "%0 = " #asm_size "[%1]" #asm_ext ";" \ |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 91 | : "=d" (__v) \ |
| 92 | : "a" (addr) \ |
| 93 | ); \ |
| 94 | __v; }) |
Mike Frysinger | 7ed998f | 2011-05-14 10:20:25 -0400 | [diff] [blame] | 95 | #define _bfin_writeX(addr, val, size, asm_size) \ |
| 96 | __asm__ __volatile__( \ |
| 97 | NOP_PAD_ANOMALY_05000198 \ |
| 98 | #asm_size "[%0] = %1;" \ |
| 99 | : \ |
| 100 | : "a" (addr), "d" ((u##size)(val)) \ |
| 101 | : "memory" \ |
| 102 | ) |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 103 | |
Mike Frysinger | 7ed998f | 2011-05-14 10:20:25 -0400 | [diff] [blame] | 104 | #define bfin_read8(addr) _bfin_readX(addr, 8, b, (z)) |
| 105 | #define bfin_read16(addr) _bfin_readX(addr, 16, w, (z)) |
| 106 | #define bfin_read32(addr) _bfin_readX(addr, 32, , ) |
| 107 | #define bfin_write8(addr, val) _bfin_writeX(addr, val, 8, b) |
| 108 | #define bfin_write16(addr, val) _bfin_writeX(addr, val, 16, w) |
| 109 | #define bfin_write32(addr, val) _bfin_writeX(addr, val, 32, ) |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 110 | |
Mike Frysinger | 7ed998f | 2011-05-14 10:20:25 -0400 | [diff] [blame] | 111 | #define bfin_read(addr) \ |
| 112 | ({ \ |
| 113 | sizeof(*(addr)) == 1 ? bfin_read8(addr) : \ |
| 114 | sizeof(*(addr)) == 2 ? bfin_read16(addr) : \ |
| 115 | sizeof(*(addr)) == 4 ? bfin_read32(addr) : \ |
Sonic Zhang | ecf9ce2 | 2013-12-09 14:55:21 +0800 | [diff] [blame] | 116 | ({ BFIN_BUG(); 0; }); \ |
Mike Frysinger | 7ed998f | 2011-05-14 10:20:25 -0400 | [diff] [blame] | 117 | }) |
| 118 | #define bfin_write(addr, val) \ |
| 119 | do { \ |
| 120 | switch (sizeof(*(addr))) { \ |
| 121 | case 1: bfin_write8(addr, val); break; \ |
| 122 | case 2: bfin_write16(addr, val); break; \ |
| 123 | case 4: bfin_write32(addr, val); break; \ |
Sonic Zhang | ecf9ce2 | 2013-12-09 14:55:21 +0800 | [diff] [blame] | 124 | default: \ |
| 125 | BFIN_BUG(); \ |
Mike Frysinger | 7ed998f | 2011-05-14 10:20:25 -0400 | [diff] [blame] | 126 | } \ |
| 127 | } while (0) |
| 128 | |
| 129 | #define bfin_write_or(addr, bits) \ |
| 130 | do { \ |
| 131 | typeof(addr) __addr = (addr); \ |
| 132 | bfin_write(__addr, bfin_read(__addr) | (bits)); \ |
| 133 | } while (0) |
| 134 | |
| 135 | #define bfin_write_and(addr, bits) \ |
| 136 | do { \ |
| 137 | typeof(addr) __addr = (addr); \ |
| 138 | bfin_write(__addr, bfin_read(__addr) & (bits)); \ |
| 139 | } while (0) |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 140 | |
| 141 | #define bfin_readPTR(addr) bfin_read32(addr) |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 142 | #define bfin_writePTR(addr, val) bfin_write32(addr, val) |
| 143 | |
| 144 | /* SSYNC implementation for C file */ |
| 145 | static inline void SSYNC(void) |
| 146 | { |
| 147 | int _tmp; |
| 148 | if (ANOMALY_05000312) |
| 149 | __asm__ __volatile__( |
| 150 | "cli %0;" |
| 151 | "nop;" |
| 152 | "nop;" |
| 153 | "ssync;" |
| 154 | "sti %0;" |
| 155 | : "=d" (_tmp) |
| 156 | ); |
| 157 | else if (ANOMALY_05000244) |
| 158 | __asm__ __volatile__( |
| 159 | "nop;" |
| 160 | "nop;" |
| 161 | "nop;" |
| 162 | "ssync;" |
| 163 | ); |
| 164 | else |
| 165 | __asm__ __volatile__("ssync;"); |
| 166 | } |
| 167 | |
| 168 | /* CSYNC implementation for C file */ |
| 169 | static inline void CSYNC(void) |
| 170 | { |
| 171 | int _tmp; |
| 172 | if (ANOMALY_05000312) |
| 173 | __asm__ __volatile__( |
| 174 | "cli %0;" |
| 175 | "nop;" |
| 176 | "nop;" |
| 177 | "csync;" |
| 178 | "sti %0;" |
| 179 | : "=d" (_tmp) |
| 180 | ); |
| 181 | else if (ANOMALY_05000244) |
| 182 | __asm__ __volatile__( |
| 183 | "nop;" |
| 184 | "nop;" |
| 185 | "nop;" |
| 186 | "csync;" |
| 187 | ); |
| 188 | else |
| 189 | __asm__ __volatile__("csync;"); |
| 190 | } |
| 191 | |
| 192 | #else /* __ASSEMBLY__ */ |
| 193 | |
| 194 | /* SSYNC & CSYNC implementations for assembly files */ |
| 195 | |
| 196 | #define ssync(x) SSYNC(x) |
| 197 | #define csync(x) CSYNC(x) |
| 198 | |
| 199 | #if ANOMALY_05000312 |
| 200 | #define SSYNC(scratch) cli scratch; nop; nop; SSYNC; sti scratch; |
| 201 | #define CSYNC(scratch) cli scratch; nop; nop; CSYNC; sti scratch; |
| 202 | |
| 203 | #elif ANOMALY_05000244 |
| 204 | #define SSYNC(scratch) nop; nop; nop; SSYNC; |
| 205 | #define CSYNC(scratch) nop; nop; nop; CSYNC; |
| 206 | |
| 207 | #else |
| 208 | #define SSYNC(scratch) SSYNC; |
| 209 | #define CSYNC(scratch) CSYNC; |
| 210 | |
| 211 | #endif /* ANOMALY_05000312 & ANOMALY_05000244 handling */ |
| 212 | |
| 213 | #endif /* __ASSEMBLY__ */ |
| 214 | |
| 215 | #endif |