~ubuntu-branches/ubuntu/karmic/linux-mvl-dove/karmic-proposed

« back to all changes in this revision

Viewing changes to arch/arm/plat-orion/mv_hal_drivers/common/mvCommon.h

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Bader
  • Date: 2010-03-10 22:24:12 UTC
  • mto: (15.1.2 karmic-security)
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20100310222412-k86m3r53jw0je7x1
Tags: upstream-2.6.31
ImportĀ upstreamĀ versionĀ 2.6.31

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************************************************
2
 
Copyright (C) Marvell International Ltd. and its affiliates
3
 
 
4
 
This software file (the "File") is owned and distributed by Marvell 
5
 
International Ltd. and/or its affiliates ("Marvell") under the following
6
 
alternative licensing terms.  Once you have made an election to distribute the
7
 
File under one of the following license alternatives, please (i) delete this
8
 
introductory statement regarding license alternatives, (ii) delete the two
9
 
license alternatives that you have not elected to use and (iii) preserve the
10
 
Marvell copyright notice above.
11
 
 
12
 
********************************************************************************
13
 
Marvell Commercial License Option
14
 
 
15
 
If you received this File from Marvell and you have entered into a commercial
16
 
license agreement (a "Commercial License") with Marvell, the File is licensed
17
 
to you under the terms of the applicable Commercial License.
18
 
 
19
 
********************************************************************************
20
 
Marvell GPL License Option
21
 
 
22
 
If you received this File from Marvell, you may opt to use, redistribute and/or 
23
 
modify this File in accordance with the terms and conditions of the General 
24
 
Public License Version 2, June 1991 (the "GPL License"), a copy of which is 
25
 
available along with the File in the license.txt file or by writing to the Free 
26
 
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 or 
27
 
on the worldwide web at http://www.gnu.org/licenses/gpl.txt. 
28
 
 
29
 
THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE IMPLIED 
30
 
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY 
31
 
DISCLAIMED.  The GPL License provides additional details about this warranty 
32
 
disclaimer.
33
 
********************************************************************************
34
 
Marvell BSD License Option
35
 
 
36
 
If you received this File from Marvell, you may opt to use, redistribute and/or 
37
 
modify this File under the following licensing terms. 
38
 
Redistribution and use in source and binary forms, with or without modification, 
39
 
are permitted provided that the following conditions are met:
40
 
 
41
 
    *   Redistributions of source code must retain the above copyright notice,
42
 
            this list of conditions and the following disclaimer. 
43
 
 
44
 
    *   Redistributions in binary form must reproduce the above copyright
45
 
        notice, this list of conditions and the following disclaimer in the
46
 
        documentation and/or other materials provided with the distribution. 
47
 
 
48
 
    *   Neither the name of Marvell nor the names of its contributors may be 
49
 
        used to endorse or promote products derived from this software without 
50
 
        specific prior written permission. 
51
 
    
52
 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
53
 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
54
 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
55
 
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 
56
 
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
57
 
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
58
 
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
59
 
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
60
 
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
61
 
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62
 
 
63
 
*******************************************************************************/
64
 
 
65
 
 
66
 
 
67
 
#ifndef __INCmvCommonh
68
 
#define __INCmvCommonh
69
 
 
70
 
#include "mvTypes.h"
71
 
#include "mvDeviceId.h"
72
 
#ifndef MV_ASMLANGUAGE
73
 
#include "mv802_3.h"
74
 
#include "mvVideo.h"
75
 
#endif
76
 
 
77
 
/* Swap tool */
78
 
 
79
 
/* 16bit nibble swap. For example 0x1234 -> 0x2143                          */
80
 
#define MV_NIBBLE_SWAP_16BIT(X)    (((X&0xf) << 4) |     \
81
 
                                    ((X&0xf0) >> 4) |    \
82
 
                                    ((X&0xf00) << 4) |   \
83
 
                                    ((X&0xf000) >> 4))
84
 
        
85
 
/* 32bit nibble swap. For example 0x12345678 -> 0x21436587                  */
86
 
#define MV_NIBBLE_SWAP_32BIT(X)    (((X&0xf) << 4) |       \
87
 
                                    ((X&0xf0) >> 4) |      \
88
 
                                    ((X&0xf00) << 4) |     \
89
 
                                    ((X&0xf000) >> 4) |    \
90
 
                                    ((X&0xf0000) << 4) |   \
91
 
                                    ((X&0xf00000) >> 4) |  \
92
 
                                    ((X&0xf000000) << 4) | \
93
 
                                    ((X&0xf0000000) >> 4))
94
 
 
95
 
/* 16bit byte swap. For example 0x1122 -> 0x2211                            */
96
 
#define MV_BYTE_SWAP_16BIT(X) ((((X)&0xff)<<8) | (((X)&0xff00)>>8))
97
 
 
98
 
/* 32bit byte swap. For example 0x11223344 -> 0x44332211                    */
99
 
#define MV_BYTE_SWAP_32BIT(X) ((((X)&0xff)<<24) |                       \
100
 
                               (((X)&0xff00)<<8) |                      \
101
 
                               (((X)&0xff0000)>>8) |                    \
102
 
                               (((X)&0xff000000)>>24))
103
 
 
104
 
/* 64bit byte swap. For example 0x11223344.55667788 -> 0x88776655.44332211  */
105
 
#define MV_BYTE_SWAP_64BIT(X) ((l64) ((((X)&0xffULL)<<56) |             \
106
 
                                      (((X)&0xff00ULL)<<40) |           \
107
 
                                      (((X)&0xff0000ULL)<<24) |         \
108
 
                                      (((X)&0xff000000ULL)<<8) |        \
109
 
                                      (((X)&0xff00000000ULL)>>8) |      \
110
 
                                      (((X)&0xff0000000000ULL)>>24) |   \
111
 
                                      (((X)&0xff000000000000ULL)>>40) | \
112
 
                                      (((X)&0xff00000000000000ULL)>>56)))
113
 
 
114
 
/* Endianess macros.                                                        */
115
 
#if defined(MV_CPU_LE)
116
 
    #define MV_16BIT_LE(X)  (X) 
117
 
    #define MV_32BIT_LE(X)  (X)
118
 
    #define MV_64BIT_LE(X)  (X)
119
 
    #define MV_16BIT_BE(X)  MV_BYTE_SWAP_16BIT(X)
120
 
    #define MV_32BIT_BE(X)  MV_BYTE_SWAP_32BIT(X)
121
 
    #define MV_64BIT_BE(X)  MV_BYTE_SWAP_64BIT(X)
122
 
#elif defined(MV_CPU_BE)
123
 
    #define MV_16BIT_LE(X)  MV_BYTE_SWAP_16BIT(X) 
124
 
    #define MV_32BIT_LE(X)  MV_BYTE_SWAP_32BIT(X)
125
 
    #define MV_64BIT_LE(X)  MV_BYTE_SWAP_64BIT(X)
126
 
    #define MV_16BIT_BE(X)  (X)
127
 
    #define MV_32BIT_BE(X)  (X)
128
 
    #define MV_64BIT_BE(X)  (X)
129
 
#else
130
 
    #error "CPU endianess isn't defined!\n"
131
 
#endif 
132
 
 
133
 
 
134
 
/* Bit field definitions */
135
 
#define NO_BIT      0x00000000
136
 
 
137
 
/* avoid redefinition of bits */
138
 
#ifndef BIT0
139
 
 
140
 
#define BIT0        0x00000001
141
 
#define BIT1        0x00000002
142
 
#define BIT2        0x00000004
143
 
#define BIT3        0x00000008
144
 
#define BIT4        0x00000010
145
 
#define BIT5        0x00000020
146
 
#define BIT6        0x00000040
147
 
#define BIT7        0x00000080
148
 
#define BIT8        0x00000100
149
 
#define BIT9        0x00000200
150
 
#define BIT10       0x00000400
151
 
#define BIT11       0x00000800
152
 
#define BIT12       0x00001000
153
 
#define BIT13       0x00002000
154
 
#define BIT14       0x00004000
155
 
#define BIT15       0x00008000
156
 
#define BIT16       0x00010000
157
 
#define BIT17       0x00020000
158
 
#define BIT18       0x00040000
159
 
#define BIT19       0x00080000
160
 
#define BIT20       0x00100000
161
 
#define BIT21       0x00200000
162
 
#define BIT22       0x00400000
163
 
#define BIT23       0x00800000
164
 
#define BIT24       0x01000000
165
 
#define BIT25       0x02000000
166
 
#define BIT26       0x04000000
167
 
#define BIT27       0x08000000
168
 
#define BIT28       0x10000000
169
 
#define BIT29       0x20000000
170
 
#define BIT30       0x40000000
171
 
#define BIT31       0x80000000
172
 
 
173
 
#endif /* BIT0 */
174
 
/* Handy sizes */
175
 
#define _1K         0x00000400
176
 
#define _2K         0x00000800
177
 
#define _4K         0x00001000
178
 
#define _8K         0x00002000
179
 
#define _16K        0x00004000
180
 
#define _32K        0x00008000
181
 
#define _64K        0x00010000
182
 
#define _128K       0x00020000
183
 
#define _256K       0x00040000
184
 
#define _512K       0x00080000
185
 
 
186
 
#define _1M         0x00100000
187
 
#define _2M         0x00200000
188
 
#define _4M         0x00400000
189
 
#define _8M         0x00800000
190
 
#define _16M        0x01000000
191
 
#define _32M        0x02000000
192
 
#define _64M        0x04000000
193
 
#define _128M       0x08000000
194
 
#define _256M       0x10000000
195
 
#define _512M       0x20000000
196
 
 
197
 
#define _1G         0x40000000
198
 
#define _2G         0x80000000
199
 
 
200
 
/* Tclock and Sys clock define */
201
 
#define _100MHz     100000000
202
 
#define _125MHz     125000000
203
 
#define _133MHz     133333334
204
 
#define _150MHz     150000000
205
 
#define _160MHz     160000000
206
 
#define _166MHz     166666667
207
 
#define _175MHz     175000000
208
 
#define _178MHz     178000000
209
 
#define _183MHz     183333334
210
 
#define _187MHz     187000000
211
 
#define _192MHz     192000000
212
 
#define _194MHz     194000000
213
 
#define _200MHz     200000000
214
 
#define _233MHz     233333334
215
 
#define _250MHz     250000000
216
 
#define _266MHz     266666667
217
 
#define _300MHz     300000000
218
 
 
219
 
 
220
 
/* Supported clocks */
221
 
#define MV_BOARD_TCLK_100MHZ    100000000   
222
 
#define MV_BOARD_TCLK_125MHZ    125000000       
223
 
#define MV_BOARD_TCLK_133MHZ    133333333   
224
 
#define MV_BOARD_TCLK_150MHZ    150000000  
225
 
#define MV_BOARD_TCLK_166MHZ    166666667   
226
 
#define MV_BOARD_TCLK_200MHZ    200000000   
227
 
 
228
 
/* For better address window table readability */
229
 
#define EN                      MV_TRUE
230
 
#define DIS                     MV_FALSE
231
 
#define N_A                     -1                      /* Not applicable */
232
 
 
233
 
/* Cache configuration options for memory (DRAM, SRAM, ... ) */
234
 
 
235
 
/* Memory uncached, HW or SW cache coherency is not needed */
236
 
#define MV_UNCACHED             0   
237
 
/* Memory cached, HW cache coherency supported in WriteThrough mode */
238
 
#define MV_CACHE_COHER_HW_WT    1
239
 
/* Memory cached, HW cache coherency supported in WriteBack mode */
240
 
#define MV_CACHE_COHER_HW_WB    2
241
 
/* Memory cached, No HW cache coherency, Cache coherency must be in SW */
242
 
#define MV_CACHE_COHER_SW       3
243
 
 
244
 
               
245
 
/* Macro for testing aligment. Positive if number is NOT aligned   */
246
 
#define MV_IS_NOT_ALIGN(number, align)      ((number) & ((align) - 1))
247
 
 
248
 
/* Macro for alignment up. For example, MV_ALIGN_UP(0x0330, 0x20) = 0x0340   */
249
 
#define MV_ALIGN_UP(number, align)                                          \
250
 
(((number) & ((align) - 1)) ? (((number) + (align)) & ~((align)-1)) : (number))
251
 
 
252
 
/* Macro for alignment down. For example, MV_ALIGN_UP(0x0330, 0x20) = 0x0320 */
253
 
#define MV_ALIGN_DOWN(number, align) ((number) & ~((align)-1))
254
 
 
255
 
/* This macro returns absolute value                                        */
256
 
#define MV_ABS(number)  (((int)(number) < 0) ? -(int)(number) : (int)(number))
257
 
 
258
 
 
259
 
/* Bit fields manipulation macros                                           */
260
 
 
261
 
/* An integer word which its 'x' bit is set                                 */
262
 
#define MV_BIT_MASK(bitNum)         (1 << (bitNum) )     
263
 
 
264
 
/* Checks wheter bit 'x' in integer word is set                             */
265
 
#define MV_BIT_CHECK(word, bitNum)  ( (word) & MV_BIT_MASK(bitNum) )
266
 
 
267
 
/* Clear (reset) bit 'x' in integer word (RMW - Read-Modify-Write)          */
268
 
#define MV_BIT_CLEAR(word, bitNum)  ( (word) &= ~(MV_BIT_MASK(bitNum)) )
269
 
 
270
 
/* Set bit 'x' in integer word (RMW)                                        */
271
 
#define MV_BIT_SET(word, bitNum)    ( (word) |= MV_BIT_MASK(bitNum) )
272
 
 
273
 
/* Invert bit 'x' in integer word (RMW)                                     */
274
 
#define MV_BIT_INV(word, bitNum)    ( (word) ^= MV_BIT_MASK(bitNum) )
275
 
 
276
 
/* Get the min between 'a' or 'b'                                           */
277
 
#define MV_MIN(a,b)    (((a) < (b)) ? (a) : (b)) 
278
 
 
279
 
/* Get the max between 'a' or 'b'                                           */
280
 
#define MV_MAX(a,b)    (((a) < (b)) ? (b) : (a)) 
281
 
 
282
 
/* Temporary */
283
 
#define mvOsDivide(num, div)        \
284
 
({                                  \
285
 
    int i=0, rem=(num);             \
286
 
                                    \
287
 
    while(rem >= (div))             \
288
 
    {                               \
289
 
        rem -= (div);               \
290
 
        i++;                        \
291
 
    }                               \
292
 
    (i);                            \
293
 
})
294
 
 
295
 
/* Temporary */
296
 
#define mvOsReminder(num, div)      \
297
 
({                                  \
298
 
    int rem = (num);                \
299
 
                                    \
300
 
    while(rem >= (div))             \
301
 
        rem -= (div);               \
302
 
    (rem);                          \
303
 
})
304
 
 
305
 
#define MV_IP_QUAD(ipAddr)    ((ipAddr >> 24) & 0xFF), ((ipAddr >> 16) & 0xFF), \
306
 
                              ((ipAddr >> 8) & 0xFF), ((ipAddr >> 0) & 0xFF)
307
 
 
308
 
#define MV_IS_POWER_OF_2(num) ((num != 0) && ((num & (num - 1)) == 0))
309
 
 
310
 
#ifndef MV_ASMLANGUAGE
311
 
/* mvCommon API list */
312
 
 
313
 
MV_VOID     mvHexToBin(const char* pHexStr, MV_U8* pBin, int size);
314
 
void        mvAsciiToHex(const char* asciiStr, char* hexStr);
315
 
void        mvBinToHex(const MV_U8* bin, char* hexStr, int size);
316
 
void        mvBinToAscii(const MV_U8* bin, char* asciiStr, int size);
317
 
 
318
 
MV_STATUS mvMacStrToHex(const char* macStr, MV_U8* macHex);
319
 
MV_STATUS mvMacHexToStr(MV_U8* macHex, char* macStr);
320
 
void        mvSizePrint(MV_U32);
321
 
 
322
 
MV_U32 mvLog2(MV_U32 num);
323
 
 
324
 
MV_STATUS mvWinOverlapTest(MV_ADDR_WIN *pAddrWin1, MV_ADDR_WIN *pAddrWin2);
325
 
MV_STATUS mvWinWithinWinTest(MV_ADDR_WIN *pAddrWin1, MV_ADDR_WIN *pAddrWin2);
326
 
 
327
 
#endif /* MV_ASMLANGUAGE */
328
 
 
329
 
 
330
 
#endif  /* __INCmvCommonh */