Import upstream u-boot 1.1.4
[u-boot.git] / board / Marvell / include / core.h
1 /* Core.h - Basic core logic functions and definitions */
2
3 /* Copyright Galileo Technology. */
4
5 /*
6 DESCRIPTION
7 This header file contains simple read/write macros for addressing
8 the SDRAM, devices, GT`s internal registers and PCI (using the PCI`s address
9 space). The macros take care of Big/Little endian conversions.
10 */
11
12 #ifndef __INCcoreh
13 #define __INCcoreh
14
15 #include "mv_gen_reg.h"
16
17 extern unsigned int INTERNAL_REG_BASE_ADDR;
18
19 /****************************************/
20 /*          GENERAL Definitions                 */
21 /****************************************/
22
23 #define NO_BIT          0x00000000
24 #define BIT0            0x00000001
25 #define BIT1            0x00000002
26 #define BIT2            0x00000004
27 #define BIT3            0x00000008
28 #define BIT4            0x00000010
29 #define BIT5            0x00000020
30 #define BIT6            0x00000040
31 #define BIT7            0x00000080
32 #define BIT8            0x00000100
33 #define BIT9            0x00000200
34 #define BIT10           0x00000400
35 #define BIT11           0x00000800
36 #define BIT12           0x00001000
37 #define BIT13           0x00002000
38 #define BIT14           0x00004000
39 #define BIT15           0x00008000
40 #define BIT16           0x00010000
41 #define BIT17           0x00020000
42 #define BIT18           0x00040000
43 #define BIT19           0x00080000
44 #define BIT20           0x00100000
45 #define BIT21           0x00200000
46 #define BIT22           0x00400000
47 #define BIT23           0x00800000
48 #define BIT24           0x01000000
49 #define BIT25           0x02000000
50 #define BIT26           0x04000000
51 #define BIT27           0x08000000
52 #define BIT28           0x10000000
53 #define BIT29           0x20000000
54 #define BIT30           0x40000000
55 #define BIT31           0x80000000
56
57 #define _1K             0x00000400
58 #define _2K             0x00000800
59 #define _4K             0x00001000
60 #define _8K             0x00002000
61 #define _16K            0x00004000
62 #define _32K            0x00008000
63 #define _64K            0x00010000
64 #define _128K           0x00020000
65 #define _256K           0x00040000
66 #define _512K           0x00080000
67
68 #define _1M             0x00100000
69 #define _2M             0x00200000
70 #define _3M             0x00300000
71 #define _4M             0x00400000
72 #define _5M             0x00500000
73 #define _6M             0x00600000
74 #define _7M             0x00700000
75 #define _8M             0x00800000
76 #define _9M             0x00900000
77 #define _10M            0x00a00000
78 #define _11M            0x00b00000
79 #define _12M            0x00c00000
80 #define _13M            0x00d00000
81 #define _14M            0x00e00000
82 #define _15M            0x00f00000
83 #define _16M            0x01000000
84
85 #define _32M            0x02000000
86 #define _64M            0x04000000
87 #define _128M           0x08000000
88 #define _256M           0x10000000
89 #define _512M           0x20000000
90
91 #define _1G             0x40000000
92 #define _2G             0x80000000
93
94 typedef enum _bool{false,true} bool;
95
96 /* Little to Big endian conversion macros */
97
98 #ifdef LE /* Little Endian */
99 #define SHORT_SWAP(X) (X)
100 #define WORD_SWAP(X) (X)
101 #define LONG_SWAP(X) ((l64)(X))
102
103 #else    /* Big Endian */
104 #define SHORT_SWAP(X) ((X <<8 ) | (X >> 8))
105
106 #define WORD_SWAP(X) (((X)&0xff)<<24)+      \
107                     (((X)&0xff00)<<8)+      \
108                     (((X)&0xff0000)>>8)+    \
109                     (((X)&0xff000000)>>24)
110
111 #define LONG_SWAP(X) ( (l64) (((X)&0xffULL)<<56)+               \
112                             (((X)&0xff00ULL)<<40)+              \
113                             (((X)&0xff0000ULL)<<24)+            \
114                             (((X)&0xff000000ULL)<<8)+           \
115                             (((X)&0xff00000000ULL)>>8)+         \
116                             (((X)&0xff0000000000ULL)>>24)+      \
117                             (((X)&0xff000000000000ULL)>>40)+    \
118                             (((X)&0xff00000000000000ULL)>>56))
119
120 #endif
121
122 #ifndef NULL
123 #define NULL 0
124 #endif
125
126 /* Those two definitions were defined to be compatible with MIPS */
127 #define NONE_CACHEABLE          0x00000000
128 #define CACHEABLE                       0x00000000
129
130 /* 750 cache line */
131 #define CACHE_LINE_SIZE 32
132 #define CACHELINE_MASK_BITS (CACHE_LINE_SIZE - 1)
133 #define CACHELINE_ROUNDUP(A) (((A)+CACHELINE_MASK_BITS) & ~CACHELINE_MASK_BITS)
134
135 /* Read/Write to/from GT`s internal registers */
136 #define GT_REG_READ(offset, pData)                                          \
137 *pData = ( *((volatile unsigned int *)(NONE_CACHEABLE |                     \
138                 INTERNAL_REG_BASE_ADDR | (offset))) ) ;                                              \
139 *pData = WORD_SWAP(*pData)
140
141 #define GTREGREAD(offset)                                                   \
142          (WORD_SWAP( *((volatile unsigned int *)(NONE_CACHEABLE |            \
143                    INTERNAL_REG_BASE_ADDR | (offset))) ))
144
145 #define GT_REG_WRITE(offset, data)                                          \
146 *((unsigned int *)( INTERNAL_REG_BASE_ADDR | (offset))) =                   \
147                     WORD_SWAP(data)
148
149 /* Write 32/16/8 bit */
150 #define WRITE_CHAR(address, data)                                           \
151         *((unsigned char *)(address)) = data
152 #define WRITE_SHORT(address, data)                                          \
153         *((unsigned short *)(address)) = data
154 #define WRITE_WORD(address, data)                                           \
155         *((unsigned int *)(address)) = data
156
157 #define GT_WRITE_CHAR(address, data)     WRITE_CHAR(address, data)
158
159 /* Write 32/16/8 bit NonCacheable */
160 /*
161 #define GT_WRITE_CHAR(address, data)                                           \
162         (*((unsigned char *)NONE_CACHEABLE(address))) = data
163 #define GT_WRITE_SHORT(address, data)                                          \
164         (*((unsigned short *)NONE_CACHEABLE(address))) = data
165 #define GT_WRITE_WORD(address, data)                                           \
166         (*((unsigned int *)NONE_CACHEABLE(address))) = data
167 */
168  /*#define GT_WRITE_CHAR(address, data)   ((*((volatile unsigned char *)NONE_CACHEABLE((address)))) = ((unsigned char)(data)))1 */
169
170  /*#define GT_WRITE_SHORT(address, data)   ((*((volatile unsigned short *)NONE_CACHEABLE((address)))) = ((unsigned short)(data)))1 */
171
172  /*#define GT_WRITE_WORD(address, data)  ((*((volatile unsigned int *)NONE_CACHEABLE((address)))) = ((unsigned int)(data)))1 */
173
174
175 /* Read 32/16/8 bits - returns data in variable. */
176 #define READ_CHAR(address, pData)                                           \
177         *pData = *((volatile unsigned char *)(address))
178
179 #define READ_SHORT(address, pData)                                          \
180         *pData = *((volatile unsigned short *)(address))
181
182 #define READ_WORD(address, pData)                                           \
183         *pData = *((volatile unsigned int *)(address))
184
185 /* Read 32/16/8 bit - returns data direct. */
186 #define READCHAR(address)                                                   \
187         *((volatile unsigned char *)((address) | NONE_CACHEABLE))
188
189 #define READSHORT(address)                                                  \
190         *((volatile unsigned short *)((address) | NONE_CACHEABLE))
191
192 #define READWORD(address)                                                   \
193         *((volatile unsigned int *)((address) | NONE_CACHEABLE))
194
195 /* Those two Macros were defined to be compatible with MIPS */
196 #define VIRTUAL_TO_PHY(x)    (((unsigned int)x) & 0xffffffff)
197 #define PHY_TO_VIRTUAL(x)    (((unsigned int)x) | NONE_CACHEABLE)
198
199 /*  SET_REG_BITS(regOffset,bits) -
200    gets register offset and bits: a 32bit value. It set to logic '1' in the
201    internal register the bits which given as an input example:
202    SET_REG_BITS(0x840,BIT3 | BIT24 | BIT30) - set bits: 3,24 and 30 to logic
203    '1' in register 0x840 while the other bits stays as is. */
204 #define SET_REG_BITS(regOffset,bits) \
205         *(unsigned int*)(NONE_CACHEABLE | INTERNAL_REG_BASE_ADDR |  \
206         regOffset) |= (unsigned int)WORD_SWAP(bits)
207
208 /*  RESET_REG_BITS(regOffset,bits) -
209    gets register offset and bits: a 32bit value. It set to logic '0' in the
210    internal register the bits which given as an input example:
211    RESET_REG_BITS(0x840,BIT3 | BIT24 | BIT30) - set bits: 3,24 and 30 to logic
212    '0' in register 0x840 while the other bits stays as is. */
213 #define RESET_REG_BITS(regOffset,bits) \
214         *(unsigned int*)(NONE_CACHEABLE | INTERNAL_REG_BASE_ADDR   \
215         | regOffset) &= ~( (unsigned int)WORD_SWAP(bits) )
216 /* gets register offset and bits: a 32bit value. It set to logic '1' in the
217    internal register the bits which given as an input example:
218    GT_SET_REG_BITS(0x840,BIT3 | BIT24 | BIT30) - set bits: 3,24 and 30 to logic
219    '1' in register 0x840 while the other bits stays as is. */
220  /*#define GT_SET_REG_BITS(regOffset,bits)      ((*((volatile unsigned int*)(NONE_CACHEABLE(INTERNAL_REG_BASE_ADDR) | (regOffset)))) |= ((unsigned int)WORD_SWAP(bits)))1 */
221  /*#define GT_SET_REG_BITS(regOffset,bits) RESET_REG_BITS(regOffset,bits)1 */
222 #define GT_SET_REG_BITS(regOffset,bits) SET_REG_BITS(regOffset,bits)
223 /* gets register offset and bits: a 32bit value. It set to logic '0' in the
224    internal register the bits which given as an input example:
225    GT_RESET_REG_BITS(0x840,BIT3 | BIT24 | BIT30) - set bits: 3,24 and 30 to
226    logic '0' in register 0x840 while the other bits stays as is. */
227  /*#define GT_RESET_REG_BITS(regOffset,bits)    ((*((volatile unsigned int*)(NONE_CACHEABLE(INTERNAL_REG_BASE_ADDR) |  (regOffset)))) &= ~((unsigned int)WORD_SWAP(bits)))1 */
228 #define GT_RESET_REG_BITS(regOffset,bits) RESET_REG_BITS(regOffset,bits)
229
230
231 #define DEBUG_LED0_ON()        WRITE_CHAR(memoryGetDeviceBaseAddress(DEVICE1) | 0x8000,0)
232 #define DEBUG_LED1_ON()        WRITE_CHAR(memoryGetDeviceBaseAddress(DEVICE1) | 0xc000,0)
233 #define DEBUG_LED2_ON()        WRITE_CHAR(memoryGetDeviceBaseAddress(DEVICE1) | 0x10000,0)
234 #define DEBUG_LED0_OFF()      WRITE_CHAR(memoryGetDeviceBaseAddress(DEVICE1) | 0x14000,0)
235 #define DEBUG_LED1_OFF()      WRITE_CHAR(memoryGetDeviceBaseAddress(DEVICE1) | 0x18000,0)
236 #define DEBUG_LED2_OFF()      WRITE_CHAR(memoryGetDeviceBaseAddress(DEVICE1) | 0x1c000,0)
237
238 #endif /* __INCcoreh */