xref: /utopia/UTPA2-700.0.x/mxlib/hal/mainz/regCHIP.h (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 
79 #ifndef _REG_SYSTEM_H_
80 #define _REG_SYSTEM_H_
81 
82 //-------------------------------------------------------------------------------------------------
83 //  Hardware Capability
84 //-------------------------------------------------------------------------------------------------
85 
86 //-------------------------------------------------------------------------------------------------
87 //  Macro and Define
88 //-------------------------------------------------------------------------------------------------
89 
90 #define REG_TOP_BASE                        (0x1F000000 + (0x101E00 << 1))
91 
92 //=============================================================================
93 // Register access
94 #define TOP_READ(addr)                      READ_WORD(REG_TOP_BASE + ((addr) << 2))
95 #define TOP_WRITE(addr, val)                WRITE_WORD((REG_TOP_BASE + ((addr) << 2)), (val))
96 
97 //=============================================================================
98 // Register access utility
99 #define TOP_OR(addr, val)                   TOP_WRITE(addr, TOP_READ(addr) | (val))
100 #define TOP_AND(addr, val)                  TOP_WRITE(addr, TOP_READ(addr) & (val))
101 #define TOP_XOR(addr, val)                  TOP_WRITE(addr, TOP_READ(addr) ^ (val))
102 
103 //=============================================================================
104 #define REG_TOP_DEVICE_ID                   0x0066
105 #define REG_TOP_CHIP_VERSION                0x0067
106 #define CHIP_VERSION_SHFT                   0
107 #define CHIP_VERSION_MASK                   BMASK(7:0)
108 #define CHIP_REVISION_SHFT                  8
109 #define CHIP_REVISION_MASK                  BMASK(15:8)
110 
111 //=============================================================================
112 #ifdef MCU_AEON
113     #define REG_IRQ_BASE                    (0xFA000000 + (0x101900 << 1))
114     #define REG_INT_BASE_ADDR               0x0060
115 #else
116     #define REG_IRQ_BASE                    (0x1f000000 + (0x101900 << 1))
117     #define REG_INT_BASE_ADDR               0x0020
118 #endif
119 
120     #define REG_FIQ_MASK_L                  (REG_INT_BASE_ADDR + 0x0004)
121     #define REG_FIQ_MASK_H                  (REG_INT_BASE_ADDR + 0x0005)
122     #define REG_FIQEXP_MASK_L               (REG_INT_BASE_ADDR + 0x0006)
123     #define REG_FIQEXP_MASK_H               (REG_INT_BASE_ADDR + 0x0007)
124 
125     #define REG_FIQ_CLEAR_L                 (REG_INT_BASE_ADDR + 0x000c)
126     #define REG_FIQ_CLEAR_H                 (REG_INT_BASE_ADDR + 0x000d)
127     #define REG_FIQEXP_CLEAR_L              (REG_INT_BASE_ADDR + 0x000e)
128     #define REG_FIQEXP_CLEAR_H              (REG_INT_BASE_ADDR + 0x000f)
129 
130     #define REG_FIQ_PENDING_L               (REG_INT_BASE_ADDR + 0x000c)
131     #define REG_FIQ_PENDING_H               (REG_INT_BASE_ADDR + 0x000d)
132     #define REG_FIQEXP_PENDING_L            (REG_INT_BASE_ADDR + 0x000e)
133     #define REG_FIQEXP_PENDING_H            (REG_INT_BASE_ADDR + 0x000f)
134 
135     #define REG_IRQ_MASK_L                  (REG_INT_BASE_ADDR + 0x0014)
136     #define REG_IRQ_MASK_H                  (REG_INT_BASE_ADDR + 0x0015)
137     #define REG_IRQEXP_MASK_L               (REG_INT_BASE_ADDR + 0x0016)
138     #define REG_IRQEXP_MASK_H               (REG_INT_BASE_ADDR + 0x0017)
139 
140     #define REG_IRQ_PENDING_L               (REG_INT_BASE_ADDR + 0x001c)
141     #define REG_IRQ_PENDING_H               (REG_INT_BASE_ADDR + 0x001d)
142     #define REG_IRQEXP_PENDING_L            (REG_INT_BASE_ADDR + 0x001e)
143     #define REG_IRQEXP_PENDING_H            (REG_INT_BASE_ADDR + 0x001f)
144 
145 //=============================================================================
146     #define IRQ_REG(addr)                   (*((volatile MS_U16*)(REG_IRQ_BASE + ((addr) << 2))))
147 
148     // REG_FIQ_MASK_L
149     //FIQ Low 16 bits
150     #define FIQL_MASK                       0xFFFF
151     #define FIQ_EXTIMER0                    (0x01 << (E_FIQ_00 - E_FIQL_START))
152     #define FIQ_EXTIMER1                    (0x01 << (E_FIQ_01 - E_FIQL_START))
153     #define FIQ_WDT                         (0x01 << (E_FIQ_02 - E_FIQL_START))
154 //  #define FIQ_RESERVED                    (0x01 << (E_FIQ_03 - E_FIQL_START))
155     #define FIQ_R2TOMCU_INT0                (0x01 << (E_FIQ_04 - E_FIQL_START))
156     #define FIQ_R2TOMCU_INT1                (0x01 << (E_FIQ_05 - E_FIQL_START))
157     #define FIQ_DSPTOMCU_INT0               (0x01 << (E_FIQ_06 - E_FIQL_START))
158     #define FIQ_DSPTOMCU_INT1               (0x01 << (E_FIQ_07 - E_FIQL_START))
159     #define FIQ_USB                         (0x01 << (E_FIQ_08 - E_FIQL_START))
160     #define FIQ_USC                         (0x01 << (E_FIQ_09 - E_FIQL_START))
161 //  #define FIQ_RESERVED                    (0x01 << (E_FIQ_10 - E_FIQL_START))
162     #define FIQ_HDMI_NON_PCM                (0x01 << (E_FIQ_11 - E_FIQL_START))
163     #define FIQ_SPDIF_IN_NON_PCM            (0x01 << (E_FIQ_12 - E_FIQL_START))
164     #define FIQ_EMAC                        (0x01 << (E_FIQ_13 - E_FIQL_START))
165     #define FIQ_SE_DSP2UP                   (0x01 << (E_FIQ_14 - E_FIQL_START))
166     #define FIQ_TSP2AEON                    (0x01 << (E_FIQ_15 - E_FIQL_START))
167 
168     // REG_FIQ_MASK_H
169     //FIQ High 16 bits
170     #define FIQH_MASK                       0xFFFF
171     #define FIQ_VIVALDI_STR                 (0x01 << (E_FIQ_16 - E_FIQH_START))
172     #define FIQ_VIVALDI_PTS                 (0x01 << (E_FIQ_17 - E_FIQH_START))
173     #define FIQ_DSP_MIU_PROT                (0x01 << (E_FIQ_18 - E_FIQH_START))
174     #define FIQ_XIU_TIMEOUT                 (0x01 << (E_FIQ_19 - E_FIQH_START))
175     #define FIQ_DMDMCU2HK                   (0x01 << (E_FIQ_20 - E_FIQH_START))
176     #define FIQ_VSYNC_VE4VBI                (0x01 << (E_FIQ_21 - E_FIQH_START))
177     #define FIQ_FIELD_VE4VBI                (0x01 << (E_FIQ_22 - E_FIQH_START))
178     #define FIQ_VDMCU2HK                    (0x01 << (E_FIQ_23 - E_FIQH_START))
179     #define FIQ_VE_DONE_TT                  (0x01 << (E_FIQ_24 - E_FIQH_START))
180     #define FIQ_UHC2                        (0x01 << (E_FIQ_25 - E_FIQH_START))
181     #define FIQ_U3_DPHY                     (0x01 << (E_FIQ_26 - E_FIQH_START))
182     #define FIQ_IR                          (0x01 << (E_FIQ_27 - E_FIQH_START))
183     #define FIQ_AFEC_VSYNC                  (0x01 << (E_FIQ_28 - E_FIQH_START))
184     #define FIQ_DEC_DSP2UP                  (0x01 << (E_FIQ_29 - E_FIQH_START))
185     #define FIQ_USB2                        (0x01 << (E_FIQ_30 - E_FIQH_START))
186     #define FIQ_DSP2MIPS                    (0x01 << (E_FIQ_31 - E_FIQH_START))
187 
188     #define FIQEXPL_MASK                    0xFFFF
189     #define FIQEXPL_IR_INT_RC               (0x01 << (E_FIQ_32 - E_FIQEXPL_START))
190     #define FIQEXPL_AU_DMA_BUF_INT          (0x01 << (E_FIQ_33 - E_FIQEXPL_START))
191     #define FIQEXPL_IR_IN                   (0x01 << (E_FIQ_34 - E_FIQEXPL_START))
192 //  #define FIQEXPL_RESERVED                (0x01 << (E_FIQ_35 - E_FIQH_START))
193     #define FIQEXPL_8051_TO_MIPS_VPE1       (0x01 << (E_FIQ_36 - E_FIQEXPL_START))
194     #define FIQEXPL_8051_TO_BEON            (0x01 << (E_FIQ_37 - E_FIQEXPL_START))
195     #define FIQEXPL_8051_TO_AEON            (0x01 << (E_FIQ_38 - E_FIQEXPL_START))
196     #define FIQEXPL_GPIO0                   (0x01 << (E_FIQ_39 - E_FIQEXPL_START))
197     #define FIQEXPL_AEON_TO_MIPS_VPE1       (0x01 << (E_FIQ_40 - E_FIQEXPL_START))
198     #define FIQEXPL_AEON_TO_BEON            (0x01 << (E_FIQ_41 - E_FIQEXPL_START))
199     #define FIQEXPL_AEON_TO_8051            (0x01 << (E_FIQ_42 - E_FIQEXPL_START))
200     #define FIQEXPL_GPIO1                   (0x01 << (E_FIQ_43 - E_FIQEXPL_START))
201     #define FIQEXPL_MIPS_VPE0_TO_MIPS_VPE1  (0x01 << (E_FIQ_44 - E_FIQEXPL_START))
202     #define FIQEXPL_TIMER2                  (0x01 << (E_FIQ_45 - E_FIQEXPL_START))
203     #define FIQEXPL_BEON_TO_8051            (0x01 << (E_FIQ_46 - E_FIQEXPL_START))
204     #define FIQEXPL_GPIO2                   (0x01 << (E_FIQ_47 - E_FIQEXPL_START))
205 
206     #define FIQEXPH_MASK                    0xFFFF
207 //  #define FIQEXPH_RESERVED                (0x01 << (E_FIQ_48 - E_FIQEXPH_START))
208     #define FIQEXPH_GPIO8                   (0x01 << (E_FIQ_49 - E_FIQEXPH_START))
209     #define FIQEXPH_GPIO9                   (0x01 << (E_FIQ_50 - E_FIQEXPH_START))
210     #define FIQEXPH_USB1                    (0x01 << (E_FIQ_51 - E_FIQEXPH_START))
211     #define FIQEXPH_UHC1                    (0x01 << (E_FIQ_52 - E_FIQEXPH_START))
212     #define FIQEXPH_LDM_DMA1                (0x01 << (E_FIQ_53 - E_FIQEXPH_START))
213     #define FIQEXPH_LDM_DMA0                (0x01 << (E_FIQ_54 - E_FIQEXPH_START))
214     #define FIQEXPH_GPIO3                   (0x01 << (E_FIQ_55 - E_FIQEXPH_START))
215     #define FIQEXPH_GPIO4                   (0x01 << (E_FIQ_56 - E_FIQEXPH_START))
216     #define FIQEXPH_GPIO5                   (0x01 << (E_FIQ_57 - E_FIQEXPH_START))
217     #define FIQEXPH_GPIO6                   (0x01 << (E_FIQ_58 - E_FIQEXPH_START))
218     #define FIQEXPH_PWM_RP_L                (0x01 << (E_FIQ_59 - E_FIQEXPH_START))
219     #define FIQEXPH_PWM_FP_L                (0x01 << (E_FIQ_60 - E_FIQEXPH_START))
220     #define FIQEXPH_PWM_RP_R                (0x01 << (E_FIQ_61 - E_FIQEXPH_START))
221     #define FIQEXPH_PWM_FP_R                (0x01 << (E_FIQ_62 - E_FIQEXPH_START))
222     #define FIQEXPH_GPIO7                   (0x01 << (E_FIQ_63 - E_FIQEXPH_START))
223 
224     // #define REG_IRQ_PENDING_L
225     #define IRQL_MASK                       0xFFFF
226     #define IRQ_UART0                       (0x01 << (E_IRQ_00 - E_IRQL_START))
227     #define IRQ_PMSLEEP                     (0x01 << (E_IRQ_01 - E_IRQL_START))
228     #define IRQ_USB2                        (0x01 << (E_IRQ_02 - E_IRQL_START))
229     #define IRQ_MVD                         (0x01 << (E_IRQ_03 - E_IRQL_START))
230     #define IRQ_PS                          (0x01 << (E_IRQ_04 - E_IRQL_START))
231     #define IRQ_NFIE                        (0x01 << (E_IRQ_05 - E_IRQL_START))
232     #define IRQ_USB                         (0x01 << (E_IRQ_06 - E_IRQL_START))
233     #define IRQ_UHC                         (0x01 << (E_IRQ_07 - E_IRQL_START))
234     #define IRQ_SDIO                        (0x01 << (E_IRQ_08 - E_IRQL_START))
235     #define IRQ_EMAC                        (0x01 << (E_IRQ_09 - E_IRQL_START))
236     #define IRQ_DISP                        (0x01 << (E_IRQ_10 - E_IRQL_START))
237     #define IRQ_G3D2MCU                     (0x01 << (E_IRQ_11 - E_IRQL_START))
238     #define IRQ_MIIC_INT2                   (0x01 << (E_IRQ_12 - E_IRQL_START))
239     #define IRQ_MIIC_INT1                   (0x01 << (E_IRQ_13 - E_IRQL_START))
240     #define IRQ_COMB                        (0x01 << (E_IRQ_14 - E_IRQL_START))
241     #define IRQ_EXT_GPIO0                   (0x01 << (E_IRQ_15 - E_IRQL_START))
242 
243     // #define REG_IRQ_PENDING_H
244     #define IRQH_MASK                       0xFFFF
245     #define IRQ_TSP2HK                      (0x01 << (E_IRQ_16 - E_IRQH_START))
246     #define IRQ_VE                          (0x01 << (E_IRQ_17 - E_IRQH_START))
247     #define IRQ_CIMAX2MCU                   (0x01 << (E_IRQ_18 - E_IRQH_START))
248     #define IRQ_DC                          (0x01 << (E_IRQ_19 - E_IRQH_START))
249     #define IRQ_GOP                         (0x01 << (E_IRQ_20 - E_IRQH_START))
250     #define IRQ_PCM                         (0x01 << (E_IRQ_21 - E_IRQH_START))
251     #define IRQ_MIIC_INT0                   (0x01 << (E_IRQ_22 - E_IRQH_START))
252     #define IRQ_MHL_CBUS_PM                 (0x01 << (E_IRQ_23 - E_IRQH_START))
253     #define IRQ_GPD                         (0x01 << (E_IRQ_24 - E_IRQH_START))
254     #define IRQ_MFE                         (0x01 << (E_IRQ_25 - E_IRQH_START))
255     #define IRQ_DDC2BI                      (0x01 << (E_IRQ_26 - E_IRQH_START))
256     #define IRQ_SMART                       (0x01 << (E_IRQ_27 - E_IRQH_START))
257     #define IRQ_UHC30                       (0x01 << (E_IRQ_28 - E_IRQH_START))
258     #define IRQ_MVD2MIPS                    (0x01 << (E_IRQ_29 - E_IRQH_START))
259     #define IRQ_ERROR_RESP                  (0x01 << (E_IRQ_30 - E_IRQH_START))
260     #define IRQ_ADCDVI2RIU                  (0x01 << (E_IRQ_31 - E_IRQH_START))
261 
262     #define IRQEXPL_MASK                    0xFFFF
263     #define IRQEXPL_SVD_HVD                 (0x01 << (E_IRQ_32 - E_IRQEXPL_START))
264     #define IRQEXPL_USB1                    (0x01 << (E_IRQ_33 - E_IRQEXPL_START))
265     #define IRQEXPL_UHC1                    (0x01 << (E_IRQ_34 - E_IRQEXPL_START))
266     #define IRQEXPL_MIU                     (0x01 << (E_IRQ_35 - E_IRQEXPL_START))
267     #define IRQEXPL_MIU_SECURITY            (0x01 << (E_IRQ_36 - E_IRQEXPL_START))
268     #define IRQEXPL_EXT_GPIO2               (0x01 << (E_IRQ_37 - E_IRQEXPL_START))
269     #define IRQEXPL_AEON2HI                 (0x01 << (E_IRQ_38 - E_IRQEXPL_START))
270     #define IRQEXPL_UART1                   (0x01 << (E_IRQ_39 - E_IRQEXPL_START))
271     #define IRQEXPL_PM                      (0x01 << (E_IRQ_40 - E_IRQEXPL_START))
272     #define IRQEXPL_EXT_GPIO3               (0x01 << (E_IRQ_41 - E_IRQEXPL_START))
273     #define IRQEXPL_DIPW                    (0x01 << (E_IRQ_42 - E_IRQEXPL_START))
274     #define IRQEXPL_EXT_GPIO4               (0x01 << (E_IRQ_43 - E_IRQEXPL_START))
275     #define IRQEXPL_EVD                     (0x01 << (E_IRQ_44 - E_IRQEXPL_START))
276     #define IRQEXPL_JPD                     (0x01 << (E_IRQ_45 - E_IRQEXPL_START))
277     #define IRQEXPL_MSPI1                   (0x01 << (E_IRQ_46 - E_IRQEXPL_START))
278     #define IRQEXPL_MSPI0                   (0x01 << (E_IRQ_47 - E_IRQEXPL_START))
279 
280     #define IRQEXPH_MASK                    0xFFFF
281     #define IRQEXPH_BDMA0                   (0x01 << (E_IRQ_48 - E_IRQEXPH_START))
282     #define IRQEXPH_BDMA1                   (0x01 << (E_IRQ_49 - E_IRQEXPH_START))
283     #define IRQEXPH_UART2MCU                (0x01 << (E_IRQ_50 - E_IRQEXPH_START))
284     #define IRQEXPH_URDMA2MCU               (0x01 << (E_IRQ_51 - E_IRQEXPH_START))
285     #define IRQEXPH_DVI_HDMI_HDCP           (0x01 << (E_IRQ_52 - E_IRQEXPH_START))
286     #define IRQEXPH_EXT_GPIO6               (0x01 << (E_IRQ_53 - E_IRQEXPH_START))
287     #define IRQEXPH_CEC                     (0x01 << (E_IRQ_54 - E_IRQEXPH_START))
288     #define IRQEXPH_HDCP_IIC                (0x01 << (E_IRQ_55 - E_IRQEXPH_START))
289     #define IRQEXPH_HDCP_X74                (0x01 << (E_IRQ_56 - E_IRQEXPH_START))
290     #define IRQEXPH_WADR_ERR                (0x01 << (E_IRQ_57 - E_IRQEXPH_START))
291     #define IRQEXPH_UHC2                    (0x01 << (E_IRQ_58 - E_IRQEXPH_START))
292     #define IRQEXPH_GE                      (0x01 << (E_IRQ_59 - E_IRQEXPH_START))
293     #define IRQEXPH_MIIC_DMA2               (0x01 << (E_IRQ_60 - E_IRQEXPH_START))
294     #define IRQEXPH_MIIC_DMA1               (0x01 << (E_IRQ_61 - E_IRQEXPH_START))
295     #define IRQEXPH_MIIC_DMA0               (0x01 << (E_IRQ_62 - E_IRQEXPH_START))
296     #define IRQEXPH_EXT_GPIO7               (0x01 << (E_IRQ_63 - E_IRQEXPH_START))
297 
298 //-------------------------------------------------------------------------------------------------
299 //  Type and Structure
300 //-------------------------------------------------------------------------------------------------
301 #define INTERFACE extern
302 
303 INTERFACE MS_U32    u32_ge0_mmio_base;
304 //extern MS_U32     u32_bdma_mmio_base;
305 //extern MS_U32     u32_scaler_mmio_base;
306 
307 //-------------------------------------------------------------------------------------------------
308 // Defines
309 //-------------------------------------------------------------------------------------------------
310 #define     REG_GE0_BASE    u32_ge0_mmio_base
311 //#define   REG_BDMA_BASE   u32_bdma_mmio_base
312 //#define   REG_SCALER_BASE u32_scaler_mmio_base
313 
314 //-------------------------------------------------------------------------------------------------
315 
316 // Macros
317 
318 //-------------------------------------------------------------------------------------------------
319 
320 #define MReg_Write2Byte(u32Base, u32Reg, u16Val)    \
321     do {((volatile MS_U16*)(u32Base))[((u32Reg))] = u16Val;} while(0)
322 
323 #define MReg_Read2Byte(u32Base, u32Reg)     \
324     ((volatile MS_U16*)(u32Base))[((u32Reg))]
325 
326 #define MReg_WriteByte(u32Base, u32Reg, u8Val)  \
327     do{((volatile MS_U8*)(u32Base))[((u32Reg) * 2) - ((u32Reg) & 1)] = u8Val;} while(0)
328 
329 #define MReg_ReadByte(u32Base, u32Reg)  \
330     ((volatile MS_U8*)(u32Base))[((u32Reg) * 2) - ((u32Reg) & 1)]
331 
332  #define MReg_Write3Byte(u32Base, u32Reg, u32Val)   \
333     do {    \
334         if ((u32Reg) & 0x01)    \
335         {   \
336             MReg_WriteByte(u32Base, u32Reg , u32Val);   \
337             MReg_Write2Byte(u32Base, (u32Reg + 1), ((u32Val) >> 8));    \
338         }   \
339         else    \
340         {   \
341             MReg_Write2Byte(u32Base, (u32Reg), u32Val);     \
342             MReg_WriteByte(u32Base, (u32Reg + 2),  ((u32Val) >> 16));   \
343         }   \
344     } while(0)
345 
346 #define MReg_Write4Byte(u32Base, u32Reg, u32Val)    \
347     do {    \
348         if ((u32Reg) & 0x01)    \
349         {   \
350             MReg_WriteByte(u32Base, u32Reg,  u32Val);   \
351             MReg_Write2Byte(u32Base, (u32Reg + 1), ((u32Val) >> 8));    \
352             MReg_WriteByte(u32Base, (u32Reg + 3), ((u32Val) >> 24));    \
353         }   \
354         else    \
355         {   \
356             MReg_Write2Byte(u32Base, u32Reg, u32Val);   \
357             MReg_Write2Byte(u32Base, (u32Reg + 2), ((u32Val) >> 16));   \
358         }   \
359     } while(0)
360 
361 #define MReg_WriteByteMask(u32Base, u32Reg, u8Val, u8Msk)   \
362     do {    \
363         MReg_WriteByte(u32Base, u32Reg, (MReg_ReadByte(u32Base, ((u32Reg))) & ~(u8Msk)) | ((u8Val) & (u8Msk))); \
364     } while(0)
365 
366 #define MReg_Write2ByteMask(u32Base, u32Reg, u16Val, u16Msk)    \
367     do {    \
368         if (((u32Reg) & 0x01))  \
369         {   \
370             MReg_WriteByteMask( u32Base, ((u32Reg) + 1) , (((u16Val) & 0xff00) >> 8) , (((u16Msk) & 0xff00) >> 8) );                                                                          \
371             MReg_WriteByteMask( u32Base, (u32Reg) , ((u16Val) & 0x00ff) , ((u16Msk) & 0x00ff));                                                                          \
372         }   \
373         else    \
374         {   \
375             MReg_Write2Byte(u32Base, u32Reg, (((u16Val) & (u16Msk)) | (MReg_Read2Byte(u32Base, u32Reg) & (~(u16Msk)))));                                                       \
376         }   \
377     } while(0)
378 
379 #endif // _REG_SYSTEM_H_
380 
381