]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - include/asm-blackfin/blackfin_local.h
imported Ka-Ro specific additions to U-Boot 2009.08 for TX28
[karo-tx-uboot.git] / include / asm-blackfin / blackfin_local.h
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
28 #define LO(con32) ((con32) & 0xFFFF)
29 #define lo(con32) ((con32) & 0xFFFF)
30 #define HI(con32) (((con32) >> 16) & 0xFFFF)
31 #define hi(con32) (((con32) >> 16) & 0xFFFF)
32
33 #define OFFSET_(x) (x & 0x0000FFFF)
34 #define MK_BMSK_(x) (1 << x)
35
36 /* Ideally this should be USEC not MSEC, but the USEC multiplication
37  * likes to overflow 32bit quantities which is all our assembler
38  * currently supports ;(
39  */
40 #define USEC_PER_MSEC 1000
41 #define MSEC_PER_SEC 1000
42 #define BFIN_SCLK (100000000)
43 #define SCLK_TO_MSEC(sclk) ((MSEC_PER_SEC * ((sclk) / USEC_PER_MSEC)) / (BFIN_SCLK / USEC_PER_MSEC))
44 #define MSEC_TO_SCLK(msec) ((((BFIN_SCLK / USEC_PER_MSEC) * (msec)) / MSEC_PER_SEC) * USEC_PER_MSEC)
45
46 #define L1_CACHE_SHIFT 5
47 #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
48
49 #include <asm/linkage.h>
50
51 #ifndef __ASSEMBLY__
52 # ifdef SHARED_RESOURCES
53 #  include <asm/shared_resources.h>
54 # endif
55
56 # include <linux/types.h>
57
58 extern u_long get_vco(void);
59 extern u_long get_cclk(void);
60 extern u_long get_sclk(void);
61
62 # define bfin_revid() (*pCHIPID >> 28)
63
64 extern bool bfin_os_log_check(void);
65 extern void bfin_os_log_dump(void);
66
67 extern void blackfin_icache_flush_range(const void *, const void *);
68 extern void blackfin_dcache_flush_range(const void *, const void *);
69 extern void blackfin_icache_dcache_flush_range(const void *, const void *);
70 extern void blackfin_dcache_flush_invalidate_range(const void *, const void *);
71
72 /* Use DMA to move data from on chip to external memory.  The L1 instruction
73  * regions can only be accessed via DMA, so if the address in question is in
74  * that region, make sure we attempt to DMA indirectly.
75  */
76 # define addr_bfin_on_chip_mem(addr) (((unsigned long)(addr) & 0xFFF00000) == 0xFFA00000)
77
78 # include <asm/system.h>
79
80 #if ANOMALY_05000198
81 # define NOP_PAD_ANOMALY_05000198 "nop;"
82 #else
83 # define NOP_PAD_ANOMALY_05000198
84 #endif
85
86 #define bfin_read8(addr) ({ \
87         uint8_t __v; \
88         __asm__ __volatile__( \
89                 NOP_PAD_ANOMALY_05000198 \
90                 "%0 = b[%1] (z);" \
91                 : "=d" (__v) \
92                 : "a" (addr) \
93         ); \
94         __v; })
95
96 #define bfin_read16(addr) ({ \
97         uint16_t __v; \
98         __asm__ __volatile__( \
99                 NOP_PAD_ANOMALY_05000198 \
100                 "%0 = w[%1] (z);" \
101                 : "=d" (__v) \
102                 : "a" (addr) \
103         ); \
104         __v; })
105
106 #define bfin_read32(addr) ({ \
107         uint32_t __v; \
108         __asm__ __volatile__( \
109                 NOP_PAD_ANOMALY_05000198 \
110                 "%0 = [%1];" \
111                 : "=d" (__v) \
112                 : "a" (addr) \
113         ); \
114         __v; })
115
116 #define bfin_readPTR(addr) bfin_read32(addr)
117
118 #define bfin_write8(addr, val) \
119         __asm__ __volatile__( \
120                 NOP_PAD_ANOMALY_05000198 \
121                 "b[%0] = %1;" \
122                 : \
123                 : "a" (addr), "d" (val) \
124                 : "memory" \
125         )
126
127 #define bfin_write16(addr, val) \
128         __asm__ __volatile__( \
129                 NOP_PAD_ANOMALY_05000198 \
130                 "w[%0] = %1;" \
131                 : \
132                 : "a" (addr), "d" (val) \
133                 : "memory" \
134         )
135
136 #define bfin_write32(addr, val) \
137         __asm__ __volatile__( \
138                 NOP_PAD_ANOMALY_05000198 \
139                 "[%0] = %1;" \
140                 : \
141                 : "a" (addr), "d" (val) \
142                 : "memory" \
143         )
144
145 #define bfin_writePTR(addr, val) bfin_write32(addr, val)
146
147 /* SSYNC implementation for C file */
148 static inline void SSYNC(void)
149 {
150         int _tmp;
151         if (ANOMALY_05000312)
152                 __asm__ __volatile__(
153                         "cli %0;"
154                         "nop;"
155                         "nop;"
156                         "ssync;"
157                         "sti %0;"
158                         : "=d" (_tmp)
159                 );
160         else if (ANOMALY_05000244)
161                 __asm__ __volatile__(
162                         "nop;"
163                         "nop;"
164                         "nop;"
165                         "ssync;"
166                 );
167         else
168                 __asm__ __volatile__("ssync;");
169 }
170
171 /* CSYNC implementation for C file */
172 static inline void CSYNC(void)
173 {
174         int _tmp;
175         if (ANOMALY_05000312)
176                 __asm__ __volatile__(
177                         "cli %0;"
178                         "nop;"
179                         "nop;"
180                         "csync;"
181                         "sti %0;"
182                         : "=d" (_tmp)
183                 );
184         else if (ANOMALY_05000244)
185                 __asm__ __volatile__(
186                         "nop;"
187                         "nop;"
188                         "nop;"
189                         "csync;"
190                 );
191         else
192                 __asm__ __volatile__("csync;");
193 }
194
195 #else  /* __ASSEMBLY__ */
196
197 /* SSYNC & CSYNC implementations for assembly files */
198
199 #define ssync(x) SSYNC(x)
200 #define csync(x) CSYNC(x)
201
202 #if ANOMALY_05000312
203 #define SSYNC(scratch) cli scratch; nop; nop; SSYNC; sti scratch;
204 #define CSYNC(scratch) cli scratch; nop; nop; CSYNC; sti scratch;
205
206 #elif ANOMALY_05000244
207 #define SSYNC(scratch) nop; nop; nop; SSYNC;
208 #define CSYNC(scratch) nop; nop; nop; CSYNC;
209
210 #else
211 #define SSYNC(scratch) SSYNC;
212 #define CSYNC(scratch) CSYNC;
213
214 #endif /* ANOMALY_05000312 & ANOMALY_05000244 handling */
215
216 #endif /* __ASSEMBLY__ */
217
218 #endif