tizen 2.4 release
[profile/mobile/platform/kernel/u-boot-tm1.git] / arch / arm / include / asm / arch-tiger / chip_drv_common_io.h
1 /******************************************************************************
2  ** File Name:    chip_drv_common_io.h                                        *
3  ** Author:       Steve.Zhan                                                  *
4  ** DATE:         06/05/2010                                                  *
5  ** Copyright:    2010 Spreatrum, Incoporated. All Rights Reserved.           *
6  ** Description:                                                              *
7  ******************************************************************************/
8 /******************************************************************************
9  **                   Edit    History                                         *
10  **---------------------------------------------------------------------------*
11  ** DATE                NAME            DESCRIPTION                           *
12  **  06/05/2010          Steve.Zhan       Create.                             *
13  ******************************************************************************/
14 #ifndef _CHIP_DRV_COMMON_IO_H_
15 #define _CHIP_DRV_COMMON_IO_H_
16 /*----------------------------------------------------------------------------*
17  **                         Dependencies                                      *
18  **------------------------------------------------------------------------- */
19
20 /**---------------------------------------------------------------------------*
21  **                             Compiler Flag                                 *
22  **--------------------------------------------------------------------------*/
23 #ifdef   __cplusplus
24 extern   "C"
25 {
26 #endif
27 /**---------------------------------------------------------------------------*
28 **                               Micro Define                                **
29 **---------------------------------------------------------------------------*/
30 typedef uint32  DRV_WORD;
31 typedef uint8   DRV_BYTE;
32 typedef uint16  DRV_WORD16;
33 typedef uint32  DRV_WORD32;
34 typedef uint64  DRV_WORD64;
35 typedef uint32  DRV_ADDRWORD;
36 #define drv_count32 long
37
38
39 //Bit def
40 #ifndef BIT_0
41 #define BIT_0               0x00000001
42 #define BIT_1               0x00000002
43 #define BIT_2               0x00000004
44 #define BIT_3               0x00000008
45 #define BIT_4               0x00000010
46 #define BIT_5               0x00000020
47 #define BIT_6               0x00000040
48 #define BIT_7               0x00000080
49 #define BIT_8               0x00000100
50 #define BIT_9               0x00000200
51 #define BIT_10              0x00000400
52 #define BIT_11              0x00000800
53 #define BIT_12              0x00001000
54 #define BIT_13              0x00002000
55 #define BIT_14              0x00004000
56 #define BIT_15              0x00008000
57 #define BIT_16              0x00010000
58 #define BIT_17              0x00020000
59 #define BIT_18              0x00040000
60 #define BIT_19              0x00080000
61 #define BIT_20              0x00100000
62 #define BIT_21              0x00200000
63 #define BIT_22              0x00400000
64 #define BIT_23              0x00800000
65 #define BIT_24              0x01000000
66 #define BIT_25              0x02000000
67 #define BIT_26              0x04000000
68 #define BIT_27              0x08000000
69 #define BIT_28              0x10000000
70 #define BIT_29              0x20000000
71 #define BIT_30              0x40000000
72 #define BIT_31              0x80000000
73 #endif
74 #define BIT_(__n)       (1<<(__n))
75 #define MASK_(__n,__w)  (((1<<(__w))-1)<<(__n))
76 #define VALUE_(__n,__v) ((__v)<<(__n))
77
78 //
79 typedef uint32 ChipRegT;
80 //#define REG32(ChipReg)        ( *((volatile ChipRegT*) (ChipReg)))
81 #define REG32(x)                                    (*((volatile uint32 *)(x)))
82
83 typedef uint16 ChipRegT16;
84 #define REG16(ChipReg)        ( *((volatile ChipRegT16*) (ChipReg)))
85
86 #define REG8(ChipReg)  ( *((volatile uint8*) (ChipReg)))
87 #define CHIP_REG_OR(reg_addr, value)    (*(volatile uint32 *)(reg_addr) |= (uint32)(value))
88 #define CHIP_REG_AND(reg_addr, value)   (*(volatile uint32 *)(reg_addr) &= (uint32)(value))
89 #define CHIP_REG_GET(reg_addr)          (*(volatile uint32 *)(reg_addr))
90 #define CHIP_REG_SET(reg_addr, value)   (*(volatile uint32 *)(reg_addr)  = (uint32)(value))
91 #define SET_BIT(reg,bit)    ((reg) |= (1<<(bit)))
92 #define CLR_BIT(reg,bit)    ((reg) &= ~(1<<(bit)))
93 #define TST_BIT(a,b)        (((a)>>(b))&1)
94 #define XOR_BIT(a,b)        ((a) ^= (1<<(b)))
95
96 #undef  ARR_SIZE
97 #define ARR_SIZE(x)   (sizeof(x) / sizeof(x[0]) )
98
99 #undef  MIN
100 #define MIN(x,y)      (((x) < (y)) ? (x): (y))
101 #undef  MAX
102 #define MAX(x,y)      (((x) > (y)) ? (x): (y))
103
104 #undef  ABS
105 #define ABS(x)        (((x) < (0)) ? (-x):(x))
106
107 #define SWAP16(X)    ( ((X & 0xFF00) >> 8) | ((X & 0x00FF) << 8) )
108 #define SWAP32(X)    (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
109 #define SWAP_AB(type,a,b) { type tmp; tmp=a; a=b; b=tmp; }
110
111 //
112
113 //Debug info Function and MacroS.
114
115 #if 1
116 #define CHIP_DRV_ASSERT SCI_ASSERT
117 #define CHIP_DRV_PASSERT SCI_PASSERT
118 #else
119 #define CHIP_DRV_ASSERT NULL
120 #define CHIP_DRV_PASSERT NULL
121 #endif
122 //
123 #ifndef DRV_LSBFIRST
124 #define DRV_LSBFIRST 1234
125 #define DRV_MSBFIRST 4321
126 #define DRV_BYTEORDER           DRV_MSBFIRST    // Big endian
127 #endif
128
129 #define DRV_MACRO_START do {
130 #define DRV_MACRO_END   } while (0)
131
132 #define DRV_EMPTY_STATEMENT DRV_MACRO_START DRV_MACRO_END
133
134 #define DRV_UNUSED_PARAM( _type_, _name_ ) DRV_MACRO_START      \
135     _type_ __tmp1 = (_name_);                                     \
136     _type_ __tmp2 = __tmp1;                                       \
137     __tmp1 = __tmp2;                                              \
138     DRV_MACRO_END
139
140
141
142 #ifndef HAL_IO_MACROS_DEFINED
143
144 //-----------------------------------------------------------------------------
145 // BYTE Register access.
146 // Individual and vectorized access to 8 bit registers.
147
148 // Little-endian version or big-endian version that doesn't need address munging
149 #if (DRV_BYTEORDER == DRV_LSBFIRST) || defined(HAL_IO_MACROS_NO_ADDRESS_MUNGING)
150
151 #define HAL_READ_UINT8( _register_, _value_ ) \
152     ((_value_) = *((volatile DRV_BYTE *)(_register_)))
153
154 #define HAL_WRITE_UINT8( _register_, _value_ ) \
155     (*((volatile DRV_BYTE *)(_register_)) = (_value_))
156
157 #define HAL_READ_UINT8_VECTOR( _register_, _buf_, _count_, _step_ )     \
158     DRV_MACRO_START                                                     \
159     drv_count32 _i_,_j_;                                                \
160     for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_))     \
161         (_buf_)[_i_] = ((volatile DRV_BYTE *)(_register_))[_j_];        \
162     DRV_MACRO_END
163
164 #define HAL_WRITE_UINT8_VECTOR( _register_, _buf_, _count_, _step_ )    \
165     DRV_MACRO_START                                                     \
166     drv_count32 _i_,_j_;                                                \
167     for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_))     \
168         ((volatile DRV_BYTE *)(_register_))[_j_] = (_buf_)[_i_];        \
169     DRV_MACRO_END
170
171 #define HAL_READ_UINT8_STRING( _register_, _buf_, _count_ )             \
172     DRV_MACRO_START                                                     \
173     drv_count32 _i_;                                                    \
174     for( _i_ = 0; _i_ < (_count_); _i_++)                               \
175         (_buf_)[_i_] = ((volatile DRV_BYTE *)(_register_))[_i_];        \
176     DRV_MACRO_END
177
178 #define HAL_WRITE_UINT8_STRING( _register_, _buf_, _count_ )            \
179     DRV_MACRO_START                                                     \
180     drv_count32 _i_;                                                    \
181     for( _i_ = 0; _i_ < (_count_); _i_++)                               \
182         ((volatile DRV_BYTE *)(_register_)) = (_buf_)[_i_];             \
183     DRV_MACRO_END
184
185 #else // Big-endian version
186
187 #define HAL_READ_UINT8( _register_, _value_ ) \
188     ((_value_) = *((volatile DRV_BYTE *)((DRV_ADDRWORD)(_register_)^3)))
189
190 #define HAL_WRITE_UINT8( _register_, _value_ ) \
191     (*((volatile DRV_BYTE *)((DRV_ADDRWORD)(_register_)^3)) = (_value_))
192
193 #define HAL_READ_UINT8_VECTOR( _register_, _buf_, _count_, _step_ )     \
194     DRV_MACRO_START                                                     \
195     drv_count32 _i_,_j_;                                                \
196     volatile DRV_BYTE* _r_ = ((DRV_ADDRWORD)(_register_)^3);            \
197     for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_))     \
198         (_buf_)[_i_] = _r_[_j_];                                        \
199     DRV_MACRO_END
200
201 #define HAL_WRITE_UINT8_VECTOR( _register_, _buf_, _count_, _step_ )    \
202     DRV_MACRO_START                                                     \
203     drv_count32 _i_,_j_;                                                \
204     volatile DRV_BYTE* _r_ = ((DRV_ADDRWORD)(_register_)^3);            \
205     for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_))     \
206         _r_[_j_] = (_buf_)[_i_];                                        \
207     DRV_MACRO_END
208
209 #define HAL_READ_UINT8_STRING( _register_, _buf_, _count_ )             \
210     DRV_MACRO_START                                                     \
211     drv_count32 _i_;                                                    \
212     volatile DRV_BYTE* _r_ = ((DRV_ADDRWORD)(_register_)^3);            \
213     for( _i_ = 0; _i_ < (_count_); _i_++;                               \
214             (_buf_)[_i_] = _r_[_i_];                                        \
215             DRV_MACRO_END
216
217 #define HAL_WRITE_UINT8_STRING( _register_, _buf_, _count_ )            \
218     DRV_MACRO_START                                                     \
219     drv_count32 _i_;                                                    \
220     volatile DRV_BYTE* _r_ = ((DRV_ADDRWORD)(_register_)^3);            \
221     for( _i_ = 0; _i_ < (_count_); _i_++)                               \
222         _r_[_i_] = (_buf_)[_i_];                                        \
223     DRV_MACRO_END
224
225 #endif // Big-endian
226
227 //-----------------------------------------------------------------------------
228 // 16 bit access.
229 // Individual and vectorized access to 16 bit registers.
230
231 // Little-endian version or big-endian version that doesn't need address munging
232 #if (DRV_BYTEORDER == DRV_LSBFIRST) || defined(HAL_IO_MACROS_NO_ADDRESS_MUNGING)
233
234 #define HAL_READ_UINT16( _register_, _value_ ) \
235     ((_value_) = *((volatile DRV_WORD16 *)(_register_)))
236
237 #define HAL_WRITE_UINT16( _register_, _value_ ) \
238     (*((volatile DRV_WORD16 *)(_register_)) = (_value_))
239
240 #define HAL_READ_UINT16_VECTOR( _register_, _buf_, _count_, _step_ )    \
241     DRV_MACRO_START                                                     \
242     drv_count32 _i_,_j_;                                                \
243     for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_))     \
244         (_buf_)[_i_] = ((volatile DRV_WORD16 *)(_register_))[_j_];      \
245     DRV_MACRO_END
246
247 #define HAL_WRITE_UINT16_VECTOR( _register_, _buf_, _count_, _step_ )   \
248     DRV_MACRO_START                                                     \
249     drv_count32 _i_,_j_;                                                \
250     for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_))     \
251         ((volatile DRV_WORD16 *)(_register_))[_j_] = (_buf_)[_i_];      \
252     DRV_MACRO_END
253
254 #define HAL_READ_UINT16_STRING( _register_, _buf_, _count_)             \
255     DRV_MACRO_START                                                     \
256     drv_count32 _i_;                                                    \
257     for( _i_ = 0; _i_ < (_count_); _i_++)                               \
258         (_buf_)[_i_] = ((volatile DRV_WORD16 *)(_register_))[_i_];      \
259     DRV_MACRO_END
260
261 #define HAL_WRITE_UINT16_STRING( _register_, _buf_, _count_)            \
262     DRV_MACRO_START                                                     \
263     drv_count32 _i_;                                                    \
264     for( _i_ = 0; _i_ < (_count_); _i_++)                               \
265         ((volatile DRV_WORD16 *)(_register_))[_i_] = (_buf_)[_i_];      \
266     DRV_MACRO_END
267
268
269 #else // Big-endian version
270
271 #define HAL_READ_UINT16( _register_, _value_ ) \
272     ((_value_) = *((volatile DRV_WORD16 *)((DRV_ADDRWORD)(_register_)^3)))
273
274 #define HAL_WRITE_UINT16( _register_, _value_ ) \
275     (*((volatile DRV_WORD16 *)((DRV_ADDRWORD)(_register_)^3)) = (_value_))
276
277 #define HAL_READ_UINT16_VECTOR( _register_, _buf_, _count_, _step_ )    \
278     DRV_MACRO_START                                                     \
279     drv_count32 _i_,_j_;                                                \
280     volatile DRV_WORD16* _r_ = ((DRV_ADDRWORD)(_register_)^3);          \
281     for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_))     \
282         (_buf_)[_i_] = _r_[_j_];                                        \
283     DRV_MACRO_END
284
285 #define HAL_WRITE_UINT16_VECTOR( _register_, _buf_, _count_, _step_ )   \
286     DRV_MACRO_START                                                     \
287     drv_count32 _i_,_j_;                                                \
288     volatile DRV_WORD16* _r_ = ((DRV_ADDRWORD)(_register_)^3);          \
289     for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_))     \
290         _r_[_j_] = (_buf_)[_i_];                                        \
291     DRV_MACRO_END
292
293 #define HAL_READ_UINT16_STRING( _register_, _buf_, _count_)             \
294     DRV_MACRO_START                                                     \
295     drv_count32 _i_;                                                    \
296     volatile DRV_WORD16* _r_ = ((DRV_ADDRWORD)(_register_)^3);          \
297     for( _i_ = 0 = 0; _i_ < (_count_); _i_++)                           \
298         (_buf_)[_i_] = _r_[_i_];                                        \
299     DRV_MACRO_END
300
301 #define HAL_WRITE_UINT16_STRING( _register_, _buf_, _count_)            \
302     DRV_MACRO_START                                                     \
303     drv_count32 _i_;                                                    \
304     volatile DRV_WORD16* _r_ = ((DRV_ADDRWORD)(_register_)^3);          \
305     for( _i_ = 0 = 0; _i_ < (_count_); _i_++)                           \
306         _r_[_i_] = (_buf_)[_i_];                                        \
307     DRV_MACRO_END
308
309
310 #endif // Big-endian
311
312 //-----------------------------------------------------------------------------
313 // 32 bit access.
314 // Individual and vectorized access to 32 bit registers.
315
316 // Note: same macros for little- and big-endian systems.
317
318 #define HAL_READ_UINT32( _register_, _value_ ) \
319     ((_value_) = *((volatile DRV_WORD32 *)(_register_)))
320
321 #define HAL_WRITE_UINT32( _register_, _value_ ) \
322     (*((volatile DRV_WORD32 *)(_register_)) = (_value_))
323
324 #define HAL_READ_UINT32_VECTOR( _register_, _buf_, _count_, _step_ )    \
325     DRV_MACRO_START                                                     \
326     drv_count32 _i_,_j_;                                                \
327     for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_))     \
328         (_buf_)[_i_] = ((volatile DRV_WORD32 *)(_register_))[_j_];      \
329     DRV_MACRO_END
330
331 #define HAL_WRITE_UINT32_VECTOR( _register_, _buf_, _count_, _step_ )   \
332     DRV_MACRO_START                                                     \
333     drv_count32 _i_,_j_;                                                \
334     for( _i_ = 0, _j_ = 0; _i_ < (_count_); _i_++, _j_ += (_step_))     \
335         ((volatile DRV_WORD32 *)(_register_))[_j_] = (_buf_)[_i_];      \
336     DRV_MACRO_END
337
338 #define HAL_READ_UINT32_STRING( _register_, _buf_, _count_)             \
339     DRV_MACRO_START                                                     \
340     drv_count32 _i_;                                                    \
341     for( _i_ = 0; _i_ < (_count_); _i_++)                               \
342         (_buf_)[_i_] = ((volatile DRV_WORD32 *)(_register_))[_i_];      \
343     DRV_MACRO_END
344
345 #define HAL_WRITE_UINT32_STRING( _register_, _buf_, _count_)            \
346     DRV_MACRO_START                                                     \
347     drv_count32 _i_;                                                    \
348     for( _i_ = 0; _i_ < (_count_); _i_++)                               \
349         ((volatile DRV_WORD32 *)(_register_))[_i_] = (_buf_)[_i_];      \
350     DRV_MACRO_END
351
352
353 #define HAL_IO_MACROS_DEFINED
354
355 #endif // !HAL_IO_MACROS_DEFINED
356
357
358 /**----------------------------------------------------------------------------*
359 **                         Local Function Prototype                           **
360 **----------------------------------------------------------------------------*/
361
362 /**----------------------------------------------------------------------------*
363 **                           Function Prototype                               **
364 **----------------------------------------------------------------------------*/
365
366
367 /**----------------------------------------------------------------------------*
368 **                         Compiler Flag                                      **
369 **----------------------------------------------------------------------------*/
370 #ifdef   __cplusplus
371 }
372 #endif
373 /**---------------------------------------------------------------------------*/
374 #endif
375 // End
376