blob: 48f793a4ce6199343084291a23a7269b698d7636 [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
Mike Frysingerdc6bc642009-11-11 19:08:33 -050028#include <asm/mem_map.h>
29
Mike Frysingerd4d77302008-02-04 19:26:55 -050030#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 Frysingerfdce83c2008-11-04 00:04:03 -050048#define L1_CACHE_SHIFT 5
49#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
50
Mike Frysingerd4d77302008-02-04 19:26:55 -050051#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 Frysinger40599232008-10-24 22:48:47 -040060extern u_long get_vco(void);
61extern u_long get_cclk(void);
Mike Frysingerd4d77302008-02-04 19:26:55 -050062extern u_long get_sclk(void);
63
Mike Frysingerf9481582009-11-12 18:42:53 -050064# define bfin_revid() (bfin_read_CHIPID() >> 28)
Mike Frysingerd4d77302008-02-04 19:26:55 -050065
Mike Frysinger909878f2009-07-09 01:15:05 -040066extern bool bfin_os_log_check(void);
67extern void bfin_os_log_dump(void);
68
Mike Frysingerd4d77302008-02-04 19:26:55 -050069extern void blackfin_icache_flush_range(const void *, const void *);
70extern void blackfin_dcache_flush_range(const void *, const void *);
Mike Frysingerfdce83c2008-11-04 00:04:03 -050071extern void blackfin_icache_dcache_flush_range(const void *, const void *);
Mike Frysinger05b75e42008-10-06 03:35:44 -040072extern void blackfin_dcache_flush_invalidate_range(const void *, const void *);
Mike Frysingerd4d77302008-02-04 19:26:55 -050073
Mike Frysingerb93c6862008-11-05 08:50:23 -050074/* 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 Frysingerd4d77302008-02-04 19:26:55 -050077 */
Mike Frysingerbbf4fbb2010-06-04 16:15:38 -040078# 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 Frysingerd4d77302008-02-04 19:26:55 -050087
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
96#define bfin_read8(addr) ({ \
97 uint8_t __v; \
98 __asm__ __volatile__( \
99 NOP_PAD_ANOMALY_05000198 \
100 "%0 = b[%1] (z);" \
101 : "=d" (__v) \
102 : "a" (addr) \
103 ); \
104 __v; })
105
106#define bfin_read16(addr) ({ \
107 uint16_t __v; \
108 __asm__ __volatile__( \
109 NOP_PAD_ANOMALY_05000198 \
110 "%0 = w[%1] (z);" \
111 : "=d" (__v) \
112 : "a" (addr) \
113 ); \
114 __v; })
115
116#define bfin_read32(addr) ({ \
117 uint32_t __v; \
118 __asm__ __volatile__( \
119 NOP_PAD_ANOMALY_05000198 \
120 "%0 = [%1];" \
121 : "=d" (__v) \
122 : "a" (addr) \
123 ); \
124 __v; })
125
126#define bfin_readPTR(addr) bfin_read32(addr)
127
128#define bfin_write8(addr, val) \
129 __asm__ __volatile__( \
130 NOP_PAD_ANOMALY_05000198 \
131 "b[%0] = %1;" \
132 : \
133 : "a" (addr), "d" (val) \
134 : "memory" \
135 )
136
137#define bfin_write16(addr, val) \
138 __asm__ __volatile__( \
139 NOP_PAD_ANOMALY_05000198 \
140 "w[%0] = %1;" \
141 : \
142 : "a" (addr), "d" (val) \
143 : "memory" \
144 )
145
146#define bfin_write32(addr, val) \
147 __asm__ __volatile__( \
148 NOP_PAD_ANOMALY_05000198 \
149 "[%0] = %1;" \
150 : \
151 : "a" (addr), "d" (val) \
152 : "memory" \
153 )
154
155#define bfin_writePTR(addr, val) bfin_write32(addr, val)
156
157/* SSYNC implementation for C file */
158static inline void SSYNC(void)
159{
160 int _tmp;
161 if (ANOMALY_05000312)
162 __asm__ __volatile__(
163 "cli %0;"
164 "nop;"
165 "nop;"
166 "ssync;"
167 "sti %0;"
168 : "=d" (_tmp)
169 );
170 else if (ANOMALY_05000244)
171 __asm__ __volatile__(
172 "nop;"
173 "nop;"
174 "nop;"
175 "ssync;"
176 );
177 else
178 __asm__ __volatile__("ssync;");
179}
180
181/* CSYNC implementation for C file */
182static inline void CSYNC(void)
183{
184 int _tmp;
185 if (ANOMALY_05000312)
186 __asm__ __volatile__(
187 "cli %0;"
188 "nop;"
189 "nop;"
190 "csync;"
191 "sti %0;"
192 : "=d" (_tmp)
193 );
194 else if (ANOMALY_05000244)
195 __asm__ __volatile__(
196 "nop;"
197 "nop;"
198 "nop;"
199 "csync;"
200 );
201 else
202 __asm__ __volatile__("csync;");
203}
204
205#else /* __ASSEMBLY__ */
206
207/* SSYNC & CSYNC implementations for assembly files */
208
209#define ssync(x) SSYNC(x)
210#define csync(x) CSYNC(x)
211
212#if ANOMALY_05000312
213#define SSYNC(scratch) cli scratch; nop; nop; SSYNC; sti scratch;
214#define CSYNC(scratch) cli scratch; nop; nop; CSYNC; sti scratch;
215
216#elif ANOMALY_05000244
217#define SSYNC(scratch) nop; nop; nop; SSYNC;
218#define CSYNC(scratch) nop; nop; nop; CSYNC;
219
220#else
221#define SSYNC(scratch) SSYNC;
222#define CSYNC(scratch) CSYNC;
223
224#endif /* ANOMALY_05000312 & ANOMALY_05000244 handling */
225
226#endif /* __ASSEMBLY__ */
227
228#endif