blob: ab31dcb815130181fc8f3cf09c09cbbc3049e106 [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Mike Frysinger66c4cf42008-02-04 19:26:55 -05007 */
8
9#ifndef __BLACKFIN_LOCAL_H__
10#define __BLACKFIN_LOCAL_H__
11
Mike Frysinger937cdd62009-11-11 19:08:33 -050012#include <asm/mem_map.h>
13
Mike Frysinger66c4cf42008-02-04 19:26:55 -050014#define LO(con32) ((con32) & 0xFFFF)
15#define lo(con32) ((con32) & 0xFFFF)
16#define HI(con32) (((con32) >> 16) & 0xFFFF)
17#define hi(con32) (((con32) >> 16) & 0xFFFF)
18
19#define OFFSET_(x) (x & 0x0000FFFF)
20#define MK_BMSK_(x) (1 << x)
21
22/* Ideally this should be USEC not MSEC, but the USEC multiplication
23 * likes to overflow 32bit quantities which is all our assembler
24 * currently supports ;(
25 */
26#define USEC_PER_MSEC 1000
27#define MSEC_PER_SEC 1000
28#define BFIN_SCLK (100000000)
29#define SCLK_TO_MSEC(sclk) ((MSEC_PER_SEC * ((sclk) / USEC_PER_MSEC)) / (BFIN_SCLK / USEC_PER_MSEC))
30#define MSEC_TO_SCLK(msec) ((((BFIN_SCLK / USEC_PER_MSEC) * (msec)) / MSEC_PER_SEC) * USEC_PER_MSEC)
31
Mike Frysingereba7a042008-11-04 00:04:03 -050032#define L1_CACHE_SHIFT 5
33#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
34
Macpaul Lin32ff4082011-12-01 12:32:10 +080035#include <linux/linkage.h>
Mike Frysinger45e39892011-10-12 20:16:31 -040036#include <asm/cache.h>
Mike Frysinger66c4cf42008-02-04 19:26:55 -050037
38#ifndef __ASSEMBLY__
39# ifdef SHARED_RESOURCES
40# include <asm/shared_resources.h>
41# endif
42
43# include <linux/types.h>
44
Mike Frysinger9d93a622008-10-24 22:48:47 -040045extern u_long get_vco(void);
46extern u_long get_cclk(void);
Mike Frysinger66c4cf42008-02-04 19:26:55 -050047extern u_long get_sclk(void);
Bob Liu52a310c2012-08-16 11:10:41 +080048extern u_long get_sclk0(void);
49extern u_long get_sclk1(void);
50extern u_long get_dclk(void);
Mike Frysinger66c4cf42008-02-04 19:26:55 -050051
Mike Frysinger3b7ed5a2009-11-12 18:42:53 -050052# define bfin_revid() (bfin_read_CHIPID() >> 28)
Mike Frysinger66c4cf42008-02-04 19:26:55 -050053
Mike Frysinger08975892009-07-09 01:15:05 -040054extern bool bfin_os_log_check(void);
55extern void bfin_os_log_dump(void);
56
Mike Frysinger66c4cf42008-02-04 19:26:55 -050057extern void blackfin_icache_flush_range(const void *, const void *);
58extern void blackfin_dcache_flush_range(const void *, const void *);
Mike Frysingereba7a042008-11-04 00:04:03 -050059extern void blackfin_icache_dcache_flush_range(const void *, const void *);
Mike Frysinger343e9f72008-10-06 03:35:44 -040060extern void blackfin_dcache_flush_invalidate_range(const void *, const void *);
Mike Frysinger66c4cf42008-02-04 19:26:55 -050061
Mike Frysinger780b1092008-11-05 08:50:23 -050062/* Use DMA to move data from on chip to external memory. The L1 instruction
63 * regions can only be accessed via DMA, so if the address in question is in
64 * that region, make sure we attempt to DMA indirectly.
Mike Frysinger66c4cf42008-02-04 19:26:55 -050065 */
Mike Frysingercbe93b62010-06-04 16:15:38 -040066# ifdef __ADSPBF561__
67 /* Core B regions all need dma from Core A */
68# define addr_bfin_on_chip_mem(addr) \
69 ((((unsigned long)(addr) & 0xFFF00000) == 0xFFA00000) || \
70 (((unsigned long)(addr) & 0xFFC00000) == 0xFF400000))
71# else
72# define addr_bfin_on_chip_mem(addr) \
73 (((unsigned long)(addr) & 0xFFF00000) == 0xFFA00000)
74# endif
Mike Frysinger66c4cf42008-02-04 19:26:55 -050075
76# include <asm/system.h>
77
78#if ANOMALY_05000198
79# define NOP_PAD_ANOMALY_05000198 "nop;"
80#else
81# define NOP_PAD_ANOMALY_05000198
82#endif
83
Mike Frysinger2a9364b2011-05-14 10:20:25 -040084#define _bfin_readX(addr, size, asm_size, asm_ext) ({ \
85 u32 __v; \
Mike Frysinger66c4cf42008-02-04 19:26:55 -050086 __asm__ __volatile__( \
87 NOP_PAD_ANOMALY_05000198 \
Mike Frysinger2a9364b2011-05-14 10:20:25 -040088 "%0 = " #asm_size "[%1]" #asm_ext ";" \
Mike Frysinger66c4cf42008-02-04 19:26:55 -050089 : "=d" (__v) \
90 : "a" (addr) \
91 ); \
92 __v; })
Mike Frysinger2a9364b2011-05-14 10:20:25 -040093#define _bfin_writeX(addr, val, size, asm_size) \
Mike Frysinger66c4cf42008-02-04 19:26:55 -050094 __asm__ __volatile__( \
95 NOP_PAD_ANOMALY_05000198 \
Mike Frysinger2a9364b2011-05-14 10:20:25 -040096 #asm_size "[%0] = %1;" \
Mike Frysinger66c4cf42008-02-04 19:26:55 -050097 : \
Mike Frysinger2a9364b2011-05-14 10:20:25 -040098 : "a" (addr), "d" ((u##size)(val)) \
Mike Frysinger66c4cf42008-02-04 19:26:55 -050099 : "memory" \
100 )
101
Mike Frysinger2a9364b2011-05-14 10:20:25 -0400102#define bfin_read8(addr) _bfin_readX(addr, 8, b, (z))
103#define bfin_read16(addr) _bfin_readX(addr, 16, w, (z))
104#define bfin_read32(addr) _bfin_readX(addr, 32, , )
105#define bfin_write8(addr, val) _bfin_writeX(addr, val, 8, b)
106#define bfin_write16(addr, val) _bfin_writeX(addr, val, 16, w)
107#define bfin_write32(addr, val) _bfin_writeX(addr, val, 32, )
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500108
Mike Frysinger2a9364b2011-05-14 10:20:25 -0400109#define bfin_read(addr) \
110({ \
111 sizeof(*(addr)) == 1 ? bfin_read8(addr) : \
112 sizeof(*(addr)) == 2 ? bfin_read16(addr) : \
113 sizeof(*(addr)) == 4 ? bfin_read32(addr) : \
114 ({ BUG(); 0; }); \
115})
116#define bfin_write(addr, val) \
117do { \
118 switch (sizeof(*(addr))) { \
119 case 1: bfin_write8(addr, val); break; \
120 case 2: bfin_write16(addr, val); break; \
121 case 4: bfin_write32(addr, val); break; \
122 default: BUG(); \
123 } \
124} while (0)
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500125
Mike Frysinger2a9364b2011-05-14 10:20:25 -0400126#define bfin_write_or(addr, bits) \
127do { \
128 typeof(addr) __addr = (addr); \
129 bfin_write(__addr, bfin_read(__addr) | (bits)); \
130} while (0)
131
132#define bfin_write_and(addr, bits) \
133do { \
134 typeof(addr) __addr = (addr); \
135 bfin_write(__addr, bfin_read(__addr) & (bits)); \
136} while (0)
137
138#define bfin_readPTR(addr) bfin_read32(addr)
Mike Frysinger66c4cf42008-02-04 19:26:55 -0500139#define bfin_writePTR(addr, val) bfin_write32(addr, val)
140
141/* SSYNC implementation for C file */
142static inline void SSYNC(void)
143{
144 int _tmp;
145 if (ANOMALY_05000312)
146 __asm__ __volatile__(
147 "cli %0;"
148 "nop;"
149 "nop;"
150 "ssync;"
151 "sti %0;"
152 : "=d" (_tmp)
153 );
154 else if (ANOMALY_05000244)
155 __asm__ __volatile__(
156 "nop;"
157 "nop;"
158 "nop;"
159 "ssync;"
160 );
161 else
162 __asm__ __volatile__("ssync;");
163}
164
165/* CSYNC implementation for C file */
166static inline void CSYNC(void)
167{
168 int _tmp;
169 if (ANOMALY_05000312)
170 __asm__ __volatile__(
171 "cli %0;"
172 "nop;"
173 "nop;"
174 "csync;"
175 "sti %0;"
176 : "=d" (_tmp)
177 );
178 else if (ANOMALY_05000244)
179 __asm__ __volatile__(
180 "nop;"
181 "nop;"
182 "nop;"
183 "csync;"
184 );
185 else
186 __asm__ __volatile__("csync;");
187}
188
189#else /* __ASSEMBLY__ */
190
191/* SSYNC & CSYNC implementations for assembly files */
192
193#define ssync(x) SSYNC(x)
194#define csync(x) CSYNC(x)
195
196#if ANOMALY_05000312
197#define SSYNC(scratch) cli scratch; nop; nop; SSYNC; sti scratch;
198#define CSYNC(scratch) cli scratch; nop; nop; CSYNC; sti scratch;
199
200#elif ANOMALY_05000244
201#define SSYNC(scratch) nop; nop; nop; SSYNC;
202#define CSYNC(scratch) nop; nop; nop; CSYNC;
203
204#else
205#define SSYNC(scratch) SSYNC;
206#define CSYNC(scratch) CSYNC;
207
208#endif /* ANOMALY_05000312 & ANOMALY_05000244 handling */
209
210#endif /* __ASSEMBLY__ */
211
212#endif