blob: 49d0c9ec3aabc2a2ccc480da356a37c000ae061d [file] [log] [blame]
Mike Frysinger66c4cf42008-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 Frysinger937cdd62009-11-11 19:08:33 -050028#include <asm/mem_map.h>
29
Mike Frysinger66c4cf42008-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 Frysingereba7a042008-11-04 00:04:03 -050048#define L1_CACHE_SHIFT 5
49#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
50
Macpaul Lin32ff4082011-12-01 12:32:10 +080051#include <linux/linkage.h>
Mike Frysinger45e39892011-10-12 20:16:31 -040052#include <asm/cache.h>
Mike Frysinger66c4cf42008-02-04 19:26:55 -050053
54#ifndef __ASSEMBLY__
55# ifdef SHARED_RESOURCES
56# include <asm/shared_resources.h>
57# endif
58
59# include <linux/types.h>
60
Mike Frysinger9d93a622008-10-24 22:48:47 -040061extern u_long get_vco(void);
62extern u_long get_cclk(void);
Mike Frysinger66c4cf42008-02-04 19:26:55 -050063extern u_long get_sclk(void);
64
Mike Frysinger3b7ed5a2009-11-12 18:42:53 -050065# define bfin_revid() (bfin_read_CHIPID() >> 28)
Mike Frysinger66c4cf42008-02-04 19:26:55 -050066
Mike Frysinger08975892009-07-09 01:15:05 -040067extern bool bfin_os_log_check(void);
68extern void bfin_os_log_dump(void);
69
Mike Frysinger66c4cf42008-02-04 19:26:55 -050070extern void blackfin_icache_flush_range(const void *, const void *);
71extern void blackfin_dcache_flush_range(const void *, const void *);
Mike Frysingereba7a042008-11-04 00:04:03 -050072extern void blackfin_icache_dcache_flush_range(const void *, const void *);
Mike Frysinger343e9f72008-10-06 03:35:44 -040073extern void blackfin_dcache_flush_invalidate_range(const void *, const void *);
Mike Frysinger66c4cf42008-02-04 19:26:55 -050074
Mike Frysinger780b1092008-11-05 08:50:23 -050075/* Use DMA to move data from on chip to external memory. The L1 instruction
76 * regions can only be accessed via DMA, so if the address in question is in
77 * that region, make sure we attempt to DMA indirectly.
Mike Frysinger66c4cf42008-02-04 19:26:55 -050078 */
Mike Frysingercbe93b62010-06-04 16:15:38 -040079# ifdef __ADSPBF561__
80 /* Core B regions all need dma from Core A */
81# define addr_bfin_on_chip_mem(addr) \
82 ((((unsigned long)(addr) & 0xFFF00000) == 0xFFA00000) || \
83 (((unsigned long)(addr) & 0xFFC00000) == 0xFF400000))
84# else
85# define addr_bfin_on_chip_mem(addr) \
86 (((unsigned long)(addr) & 0xFFF00000) == 0xFFA00000)
87# endif
Mike Frysinger66c4cf42008-02-04 19:26:55 -050088
89# include <asm/system.h>
90
91#if ANOMALY_05000198
92# define NOP_PAD_ANOMALY_05000198 "nop;"
93#else
94# define NOP_PAD_ANOMALY_05000198
95#endif
96
Mike Frysinger2a9364b2011-05-14 10:20:25 -040097#define _bfin_readX(addr, size, asm_size, asm_ext) ({ \
98 u32 __v; \
Mike Frysinger66c4cf42008-02-04 19:26:55 -050099 __asm__ __volatile__( \
100 NOP_PAD_ANOMALY_05000198 \
Mike Frysinger2a9364b2011-05-14 10:20:25 -0400101 "%0 = " #asm_size "[%1]" #asm_ext ";" \
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500102 : "=d" (__v) \
103 : "a" (addr) \
104 ); \
105 __v; })
Mike Frysinger2a9364b2011-05-14 10:20:25 -0400106#define _bfin_writeX(addr, val, size, asm_size) \
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500107 __asm__ __volatile__( \
108 NOP_PAD_ANOMALY_05000198 \
Mike Frysinger2a9364b2011-05-14 10:20:25 -0400109 #asm_size "[%0] = %1;" \
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500110 : \
Mike Frysinger2a9364b2011-05-14 10:20:25 -0400111 : "a" (addr), "d" ((u##size)(val)) \
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500112 : "memory" \
113 )
114
Mike Frysinger2a9364b2011-05-14 10:20:25 -0400115#define bfin_read8(addr) _bfin_readX(addr, 8, b, (z))
116#define bfin_read16(addr) _bfin_readX(addr, 16, w, (z))
117#define bfin_read32(addr) _bfin_readX(addr, 32, , )
118#define bfin_write8(addr, val) _bfin_writeX(addr, val, 8, b)
119#define bfin_write16(addr, val) _bfin_writeX(addr, val, 16, w)
120#define bfin_write32(addr, val) _bfin_writeX(addr, val, 32, )
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500121
Mike Frysinger2a9364b2011-05-14 10:20:25 -0400122#define bfin_read(addr) \
123({ \
124 sizeof(*(addr)) == 1 ? bfin_read8(addr) : \
125 sizeof(*(addr)) == 2 ? bfin_read16(addr) : \
126 sizeof(*(addr)) == 4 ? bfin_read32(addr) : \
127 ({ BUG(); 0; }); \
128})
129#define bfin_write(addr, val) \
130do { \
131 switch (sizeof(*(addr))) { \
132 case 1: bfin_write8(addr, val); break; \
133 case 2: bfin_write16(addr, val); break; \
134 case 4: bfin_write32(addr, val); break; \
135 default: BUG(); \
136 } \
137} while (0)
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500138
Mike Frysinger2a9364b2011-05-14 10:20:25 -0400139#define bfin_write_or(addr, bits) \
140do { \
141 typeof(addr) __addr = (addr); \
142 bfin_write(__addr, bfin_read(__addr) | (bits)); \
143} while (0)
144
145#define bfin_write_and(addr, bits) \
146do { \
147 typeof(addr) __addr = (addr); \
148 bfin_write(__addr, bfin_read(__addr) & (bits)); \
149} while (0)
150
151#define bfin_readPTR(addr) bfin_read32(addr)
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500152#define bfin_writePTR(addr, val) bfin_write32(addr, val)
153
154/* SSYNC implementation for C file */
155static inline void SSYNC(void)
156{
157 int _tmp;
158 if (ANOMALY_05000312)
159 __asm__ __volatile__(
160 "cli %0;"
161 "nop;"
162 "nop;"
163 "ssync;"
164 "sti %0;"
165 : "=d" (_tmp)
166 );
167 else if (ANOMALY_05000244)
168 __asm__ __volatile__(
169 "nop;"
170 "nop;"
171 "nop;"
172 "ssync;"
173 );
174 else
175 __asm__ __volatile__("ssync;");
176}
177
178/* CSYNC implementation for C file */
179static inline void CSYNC(void)
180{
181 int _tmp;
182 if (ANOMALY_05000312)
183 __asm__ __volatile__(
184 "cli %0;"
185 "nop;"
186 "nop;"
187 "csync;"
188 "sti %0;"
189 : "=d" (_tmp)
190 );
191 else if (ANOMALY_05000244)
192 __asm__ __volatile__(
193 "nop;"
194 "nop;"
195 "nop;"
196 "csync;"
197 );
198 else
199 __asm__ __volatile__("csync;");
200}
201
202#else /* __ASSEMBLY__ */
203
204/* SSYNC & CSYNC implementations for assembly files */
205
206#define ssync(x) SSYNC(x)
207#define csync(x) CSYNC(x)
208
209#if ANOMALY_05000312
210#define SSYNC(scratch) cli scratch; nop; nop; SSYNC; sti scratch;
211#define CSYNC(scratch) cli scratch; nop; nop; CSYNC; sti scratch;
212
213#elif ANOMALY_05000244
214#define SSYNC(scratch) nop; nop; nop; SSYNC;
215#define CSYNC(scratch) nop; nop; nop; CSYNC;
216
217#else
218#define SSYNC(scratch) SSYNC;
219#define CSYNC(scratch) CSYNC;
220
221#endif /* ANOMALY_05000312 & ANOMALY_05000244 handling */
222
223#endif /* __ASSEMBLY__ */
224
225#endif