2 * U-boot - blackfin_local.h
4 * Copyright (c) 2005-2007 Analog Devices Inc.
6 * See file CREDITS for list of people who contributed to this
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.
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.
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,
25 #ifndef __BLACKFIN_LOCAL_H__
26 #define __BLACKFIN_LOCAL_H__
28 #include <asm/mem_map.h>
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)
35 #define OFFSET_(x) (x & 0x0000FFFF)
36 #define MK_BMSK_(x) (1 << x)
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 ;(
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)
48 #define L1_CACHE_SHIFT 5
49 #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
51 #include <linux/linkage.h>
52 #include <asm/cache.h>
55 # ifdef SHARED_RESOURCES
56 # include <asm/shared_resources.h>
59 # include <linux/types.h>
61 extern u_long get_vco(void);
62 extern u_long get_cclk(void);
63 extern u_long get_sclk(void);
64 extern u_long get_sclk0(void);
65 extern u_long get_sclk1(void);
66 extern u_long get_dclk(void);
68 # define bfin_revid() (bfin_read_CHIPID() >> 28)
70 extern bool bfin_os_log_check(void);
71 extern void bfin_os_log_dump(void);
73 extern void blackfin_icache_flush_range(const void *, const void *);
74 extern void blackfin_dcache_flush_range(const void *, const void *);
75 extern void blackfin_icache_dcache_flush_range(const void *, const void *);
76 extern void blackfin_dcache_flush_invalidate_range(const void *, const void *);
78 /* Use DMA to move data from on chip to external memory. The L1 instruction
79 * regions can only be accessed via DMA, so if the address in question is in
80 * that region, make sure we attempt to DMA indirectly.
83 /* Core B regions all need dma from Core A */
84 # define addr_bfin_on_chip_mem(addr) \
85 ((((unsigned long)(addr) & 0xFFF00000) == 0xFFA00000) || \
86 (((unsigned long)(addr) & 0xFFC00000) == 0xFF400000))
88 # define addr_bfin_on_chip_mem(addr) \
89 (((unsigned long)(addr) & 0xFFF00000) == 0xFFA00000)
92 # include <asm/system.h>
95 # define NOP_PAD_ANOMALY_05000198 "nop;"
97 # define NOP_PAD_ANOMALY_05000198
100 #define _bfin_readX(addr, size, asm_size, asm_ext) ({ \
102 __asm__ __volatile__( \
103 NOP_PAD_ANOMALY_05000198 \
104 "%0 = " #asm_size "[%1]" #asm_ext ";" \
109 #define _bfin_writeX(addr, val, size, asm_size) \
110 __asm__ __volatile__( \
111 NOP_PAD_ANOMALY_05000198 \
112 #asm_size "[%0] = %1;" \
114 : "a" (addr), "d" ((u##size)(val)) \
118 #define bfin_read8(addr) _bfin_readX(addr, 8, b, (z))
119 #define bfin_read16(addr) _bfin_readX(addr, 16, w, (z))
120 #define bfin_read32(addr) _bfin_readX(addr, 32, , )
121 #define bfin_write8(addr, val) _bfin_writeX(addr, val, 8, b)
122 #define bfin_write16(addr, val) _bfin_writeX(addr, val, 16, w)
123 #define bfin_write32(addr, val) _bfin_writeX(addr, val, 32, )
125 #define bfin_read(addr) \
127 sizeof(*(addr)) == 1 ? bfin_read8(addr) : \
128 sizeof(*(addr)) == 2 ? bfin_read16(addr) : \
129 sizeof(*(addr)) == 4 ? bfin_read32(addr) : \
132 #define bfin_write(addr, val) \
134 switch (sizeof(*(addr))) { \
135 case 1: bfin_write8(addr, val); break; \
136 case 2: bfin_write16(addr, val); break; \
137 case 4: bfin_write32(addr, val); break; \
142 #define bfin_write_or(addr, bits) \
144 typeof(addr) __addr = (addr); \
145 bfin_write(__addr, bfin_read(__addr) | (bits)); \
148 #define bfin_write_and(addr, bits) \
150 typeof(addr) __addr = (addr); \
151 bfin_write(__addr, bfin_read(__addr) & (bits)); \
154 #define bfin_readPTR(addr) bfin_read32(addr)
155 #define bfin_writePTR(addr, val) bfin_write32(addr, val)
157 /* SSYNC implementation for C file */
158 static inline void SSYNC(void)
161 if (ANOMALY_05000312)
162 __asm__ __volatile__(
170 else if (ANOMALY_05000244)
171 __asm__ __volatile__(
178 __asm__ __volatile__("ssync;");
181 /* CSYNC implementation for C file */
182 static inline void CSYNC(void)
185 if (ANOMALY_05000312)
186 __asm__ __volatile__(
194 else if (ANOMALY_05000244)
195 __asm__ __volatile__(
202 __asm__ __volatile__("csync;");
205 #else /* __ASSEMBLY__ */
207 /* SSYNC & CSYNC implementations for assembly files */
209 #define ssync(x) SSYNC(x)
210 #define csync(x) CSYNC(x)
213 #define SSYNC(scratch) cli scratch; nop; nop; SSYNC; sti scratch;
214 #define CSYNC(scratch) cli scratch; nop; nop; CSYNC; sti scratch;
216 #elif ANOMALY_05000244
217 #define SSYNC(scratch) nop; nop; nop; SSYNC;
218 #define CSYNC(scratch) nop; nop; nop; CSYNC;
221 #define SSYNC(scratch) SSYNC;
222 #define CSYNC(scratch) CSYNC;
224 #endif /* ANOMALY_05000312 & ANOMALY_05000244 handling */
226 #endif /* __ASSEMBLY__ */