blob: 4e15834435797fef20fef8b728eb091d6b58fc47 [file] [log] [blame]
Mike Frysingerd4d77302008-02-04 19:26:55 -05001/*
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
Mike Frysingerfdce83c2008-11-04 00:04:03 -050046#define L1_CACHE_SHIFT 5
47#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
48
Mike Frysingerd4d77302008-02-04 19:26:55 -050049#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
Mike Frysinger40599232008-10-24 22:48:47 -040058extern u_long get_vco(void);
59extern u_long get_cclk(void);
Mike Frysingerd4d77302008-02-04 19:26:55 -050060extern u_long get_sclk(void);
61
62# define bfin_revid() (*pCHIPID >> 28)
63
64extern void blackfin_icache_flush_range(const void *, const void *);
65extern void blackfin_dcache_flush_range(const void *, const void *);
Mike Frysingerfdce83c2008-11-04 00:04:03 -050066extern void blackfin_icache_dcache_flush_range(const void *, const void *);
Mike Frysinger05b75e42008-10-06 03:35:44 -040067extern void blackfin_dcache_flush_invalidate_range(const void *, const void *);
Mike Frysingerd4d77302008-02-04 19:26:55 -050068
69/* Use DMA to move data from on chip to external memory. While this is
70 * required for only L1 instruction (it is not directly readable by the
71 * core via data loads), it isn't a huge performance issue for other
72 * regions (it's probably even faster than core load/stores). However,
73 * the DMA engine does not have access to the L1 scratchpad, and we
74 * cannot use DMA inside of the MMR space.
75 */
76# define addr_bfin_on_chip_mem(addr) \
77 (((unsigned long)(addr) >= 0xef000000 && (unsigned long)addr < SYSMMR_BASE) && \
78 !((unsigned long)(addr) >= L1_SRAM_SCRATCH && \
79 (unsigned long)(addr) < L1_SRAM_SCRATCH_END))
80
81# include <asm/system.h>
82
83#if ANOMALY_05000198
84# define NOP_PAD_ANOMALY_05000198 "nop;"
85#else
86# define NOP_PAD_ANOMALY_05000198
87#endif
88
89#define bfin_read8(addr) ({ \
90 uint8_t __v; \
91 __asm__ __volatile__( \
92 NOP_PAD_ANOMALY_05000198 \
93 "%0 = b[%1] (z);" \
94 : "=d" (__v) \
95 : "a" (addr) \
96 ); \
97 __v; })
98
99#define bfin_read16(addr) ({ \
100 uint16_t __v; \
101 __asm__ __volatile__( \
102 NOP_PAD_ANOMALY_05000198 \
103 "%0 = w[%1] (z);" \
104 : "=d" (__v) \
105 : "a" (addr) \
106 ); \
107 __v; })
108
109#define bfin_read32(addr) ({ \
110 uint32_t __v; \
111 __asm__ __volatile__( \
112 NOP_PAD_ANOMALY_05000198 \
113 "%0 = [%1];" \
114 : "=d" (__v) \
115 : "a" (addr) \
116 ); \
117 __v; })
118
119#define bfin_readPTR(addr) bfin_read32(addr)
120
121#define bfin_write8(addr, val) \
122 __asm__ __volatile__( \
123 NOP_PAD_ANOMALY_05000198 \
124 "b[%0] = %1;" \
125 : \
126 : "a" (addr), "d" (val) \
127 : "memory" \
128 )
129
130#define bfin_write16(addr, val) \
131 __asm__ __volatile__( \
132 NOP_PAD_ANOMALY_05000198 \
133 "w[%0] = %1;" \
134 : \
135 : "a" (addr), "d" (val) \
136 : "memory" \
137 )
138
139#define bfin_write32(addr, val) \
140 __asm__ __volatile__( \
141 NOP_PAD_ANOMALY_05000198 \
142 "[%0] = %1;" \
143 : \
144 : "a" (addr), "d" (val) \
145 : "memory" \
146 )
147
148#define bfin_writePTR(addr, val) bfin_write32(addr, val)
149
150/* SSYNC implementation for C file */
151static inline void SSYNC(void)
152{
153 int _tmp;
154 if (ANOMALY_05000312)
155 __asm__ __volatile__(
156 "cli %0;"
157 "nop;"
158 "nop;"
159 "ssync;"
160 "sti %0;"
161 : "=d" (_tmp)
162 );
163 else if (ANOMALY_05000244)
164 __asm__ __volatile__(
165 "nop;"
166 "nop;"
167 "nop;"
168 "ssync;"
169 );
170 else
171 __asm__ __volatile__("ssync;");
172}
173
174/* CSYNC implementation for C file */
175static inline void CSYNC(void)
176{
177 int _tmp;
178 if (ANOMALY_05000312)
179 __asm__ __volatile__(
180 "cli %0;"
181 "nop;"
182 "nop;"
183 "csync;"
184 "sti %0;"
185 : "=d" (_tmp)
186 );
187 else if (ANOMALY_05000244)
188 __asm__ __volatile__(
189 "nop;"
190 "nop;"
191 "nop;"
192 "csync;"
193 );
194 else
195 __asm__ __volatile__("csync;");
196}
197
198#else /* __ASSEMBLY__ */
199
200/* SSYNC & CSYNC implementations for assembly files */
201
202#define ssync(x) SSYNC(x)
203#define csync(x) CSYNC(x)
204
205#if ANOMALY_05000312
206#define SSYNC(scratch) cli scratch; nop; nop; SSYNC; sti scratch;
207#define CSYNC(scratch) cli scratch; nop; nop; CSYNC; sti scratch;
208
209#elif ANOMALY_05000244
210#define SSYNC(scratch) nop; nop; nop; SSYNC;
211#define CSYNC(scratch) nop; nop; nop; CSYNC;
212
213#else
214#define SSYNC(scratch) SSYNC;
215#define CSYNC(scratch) CSYNC;
216
217#endif /* ANOMALY_05000312 & ANOMALY_05000244 handling */
218
219#endif /* __ASSEMBLY__ */
220
221#endif