xref: /utopia/UTPA2-700.0.x/modules/msos/hal/messi/mmio/halMMIO.c (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 ///////////////////////////////////////////////////////////////////////////////////////////////////
80 ///
81 /// file    halMMIO.c
82 /// @brief  memory map io (MMIO) HAL
83 /// @author MStar Semiconductor Inc.
84 ///////////////////////////////////////////////////////////////////////////////////////////////////
85 
86 //-------------------------------------------------------------------------------------------------
87 //  Include Files
88 //-------------------------------------------------------------------------------------------------
89 
90 #include "MsCommon.h"
91 #include "halMMIO.h"
92 #include "drvMMIO.h"
93 
94 // for getting mapped IO base from DRV
95 extern MS_VIRT  _virtPM_Bank;
96 extern MS_U32   _u32PM_Bank_SIZE;
97 extern MS_VIRT  _virtNonPM_Bank;
98 extern MS_U32   _u32NonPM_Bank_SIZE;
99 
100 //-------------------------------------------------------------------------------------------------
101 //  Driver Compiler Options
102 //-------------------------------------------------------------------------------------------------
103 
104 //--------------------------------------------------------------------------------------------------
105 //  Global Variables
106 //--------------------------------------------------------------------------------------------------
107 MS_VIRT         virt_ge0_mmio_base;
108 
109 
110 //-------------------------------------------------------------------------------------------------
111 //  Local Defines
112 //-------------------------------------------------------------------------------------------------
113 #ifdef MSOS_TYPE_LINUX
114 
115 #define HAL_MMIO_PM_BASE                0x1f000000UL
116 #define HAL_MMIO_PM_SIZE                0x00300000UL
117 #define HAL_MMIO_NONPM_BASE             0x1f200000UL
118 #define HAL_MMIO_NONPM_SIZE             0x00100000UL
119 #define HAL_MMIO_FLASH_BASE0            0x14000000UL
120 #define HAL_MMIO_FLASH_SIZE0            0x01000000UL
121 
122 #else
123 
124 #if defined(MCU_AEON)
125 #define HAL_MMIO_PM_BASE                0xFA000000UL
126 #define HAL_MMIO_PM_SIZE                0x00300000UL
127 #define HAL_MMIO_NONPM_BASE             0xFA200000UL
128 #define HAL_MMIO_NONPM_SIZE             0x00100000UL
129 #define HAL_MMIO_FLASH_BASE0            0xA1000000UL // non-cache // 0xA1000000 for cache
130 #define HAL_MMIO_FLASH_SIZE0            0x01000000UL
131 
132 #elif defined(__mips__)
133 #define HAL_MMIO_PM_BASE                0xbf000000UL
134 #define HAL_MMIO_PM_SIZE                0x00300000UL
135 #define HAL_MMIO_NONPM_BASE             0xbf200000UL
136 #define HAL_MMIO_NONPM_SIZE             0x00100000UL
137 #define HAL_MMIO_FLASH_BASE0            0xb4000000UL
138 #define HAL_MMIO_FLASH_SIZE0            0x01000000UL
139 
140 #elif defined(__aarch64__) || defined(__arm__)
141 #define HAL_MMIO_PM_BASE                0x1f000000UL
142 #define HAL_MMIO_PM_SIZE                0x00300000UL
143 #define HAL_MMIO_NONPM_BASE             0x1f200000UL
144 #define HAL_MMIO_NONPM_SIZE             0x00100000UL
145 #define HAL_MMIO_FLASH_BASE0            0x14000000UL
146 #define HAL_MMIO_FLASH_SIZE0            0x01000000UL
147 
148 #else
149 #error  "Invalid MCU Type";
150 #endif
151 
152 #endif  //MSOS_TYPE_LINUX
153 
154 //-------------------------------------------------------------------------------------------------
155 //  Local Structurs
156 //-------------------------------------------------------------------------------------------------
157 
158 //-------------------------------------------------------------------------------------------------
159 //  Global Variables
160 //-------------------------------------------------------------------------------------------------
161 
162 //-------------------------------------------------------------------------------------------------
163 //  Local Variables
164 //-------------------------------------------------------------------------------------------------
165 
166 //-------------------------------------------------------------------------------------------------
167 //  Debug Functions
168 //-------------------------------------------------------------------------------------------------
169 
170 //-------------------------------------------------------------------------------------------------
171 //  Local Functions
172 //-------------------------------------------------------------------------------------------------
173 
174 //-------------------------------------------------------------------------------------------------
175 //  Global Functions
176 //-------------------------------------------------------------------------------------------------
HAL_MMIO_GetType(MS_U32 u32Module)177 MS_U16  HAL_MMIO_GetType(MS_U32 u32Module)
178 {
179     MS_U16  wMmioBankType = 0xFFFF;
180 
181     switch (u32Module)
182     {
183         //HAL_MMIO_PM_BANK
184         case MS_MODULE_PM:
185         case MS_MODULE_IR:
186         case MS_MODULE_ISP:
187         case MS_MODULE_PWS:
188             wMmioBankType = DRV_MMIO_PM_BANK;
189             break;
190 
191         //HAL_MMIO_NONPM_BANK
192         case MS_MODULE_HW:
193         case MS_MODULE_CHIPTOP:
194         case MS_MODULE_MIU:
195         case MS_MODULE_ACE:
196         case MS_MODULE_AUDIO:
197         case MS_MODULE_AVD:
198         case MS_MODULE_BDMA:
199         case MS_MODULE_DLC:
200         case MS_MODULE_DMD:
201         case MS_MODULE_GE:
202         case MS_MODULE_GOP:
203         case MS_MODULE_GPIO:
204         case MS_MODULE_HVD:
205         case MS_MODULE_HWI2C:
206         case MS_MODULE_IRQ:
207         case MS_MODULE_JPD:
208         case MS_MODULE_MBX:
209         case MS_MODULE_MFE:
210         case MS_MODULE_MHEG5:
211         case MS_MODULE_MVD:
212         case MS_MODULE_MVOP:
213         case MS_MODULE_RVD:
214         case MS_MODULE_TSP:
215         case MS_MODULE_UART:
216         case MS_MODULE_VPU:
217         case MS_MODULE_XC:
218         case MS_MODULE_PCMCIA:
219         case MS_MODULE_PFSH:
220         case MS_MODULE_PNL:
221         case MS_MODULE_PWM:
222         case MS_MODULE_SEM:
223         case MS_MODULE_VBI:
224         case MS_MODULE_VIF:
225         case MS_MODULE_DIP:
226         case MS_MODULE_MPIF:
227         case MS_MODULE_MMFILEIN:
228         case MS_MODULE_GPD:
229         case MS_MODULE_TSO:
230         case MS_MODULE_CMDQ:
231             wMmioBankType = DRV_MMIO_NONPM_BANK;
232             break;
233 
234         case MS_MODULE_SC:
235             wMmioBankType = DRV_MMIO_SC_BANK;
236             break;
237 
238          //HAL_MMIO_FLASH_BANK0
239         case MS_MODULE_FLASH:
240             wMmioBankType = DRV_MMIO_FLASH_BANK0;
241             break;
242 
243         default:
244             wMmioBankType = 0xFFFF;
245             break;
246 
247     }
248 
249     return wMmioBankType;
250 }
251 
252 
HAL_MMIO_GetBase(MS_PHY * virtBaseAddr,MS_PHY * pu32BaseSize,MS_U32 u32BankType)253 MS_BOOL HAL_MMIO_GetBase(MS_PHY* virtBaseAddr, MS_PHY* pu32BaseSize, MS_U32 u32BankType)
254 {
255     MS_BOOL bRet = TRUE;
256 
257     *virtBaseAddr = 0;
258     *pu32BaseSize = 0;
259     switch (u32BankType)
260     {
261         case DRV_MMIO_PM_BANK:
262             *virtBaseAddr = (MS_PHY) HAL_MMIO_PM_BASE;
263             *pu32BaseSize = (MS_PHY) HAL_MMIO_PM_SIZE;
264             break;
265 
266         case DRV_MMIO_NONPM_BANK:
267             *virtBaseAddr = (MS_PHY) HAL_MMIO_NONPM_BASE;
268             *pu32BaseSize = (MS_PHY) HAL_MMIO_NONPM_SIZE;
269             break;
270 
271         case DRV_MMIO_FLASH_BANK0:
272             *virtBaseAddr = (MS_PHY) HAL_MMIO_FLASH_BASE0;
273             *pu32BaseSize = (MS_PHY) HAL_MMIO_FLASH_SIZE0;
274             break;
275 
276         case DRV_MMIO_FRC_BANK:
277             break;
278 
279         default:
280 //          MS_ASSERT(0);
281             bRet = FALSE;
282             break;
283     }
284 
285     return bRet;
286 }
287 
288 
289 // @NOTE: Only run after MMIO_Init
HAL_MMIO_GetIPBase(MS_VIRT * virtBaseAddr,MS_U16 u16BankType)290 MS_BOOL HAL_MMIO_GetIPBase(MS_VIRT *virtBaseAddr, MS_U16 u16BankType)
291 {
292     *virtBaseAddr = 0;
293 
294     // if MMIO_Init is not yet initialized.
295     if((_u32PM_Bank_SIZE == 0x0) || (_u32NonPM_Bank_SIZE == 0x0))
296     {
297         return FALSE;
298     }
299 
300     switch (u16BankType)
301     {
302         case DRV_MMIO_SC_BANK:
303             *virtBaseAddr =_virtNonPM_Bank  + 0x00005200; // 0xBF220C00, 0xBF220C80
304             break;
305 
306         default:
307             return FALSE;
308     }
309 
310     return TRUE;
311 }
312 
313 #if defined(__aarch64__) || defined(__arm__)
314 #ifndef MSOS_TYPE_LINUX
_chip_flush_miu_pipe(void)315 static void _chip_flush_miu_pipe(void)
316 {
317     unsigned int    dwReadData = 0;
318 
319      //toggle the flush miu pipe fire bit
320     *(volatile unsigned int *)(HAL_MMIO_PM_BASE + (0x10188A << 1)) &= ~(0x0001);
321     *(volatile unsigned int *)(HAL_MMIO_PM_BASE + (0x10188A << 1)) |= 0x0001;
322 
323     do
324     {
325         dwReadData = *(volatile unsigned int *)(HAL_MMIO_PM_BASE+ (0x1018A0 << 1));
326         dwReadData &= BIT(12);  //Check Status of Flush Pipe Finish
327 
328     } while(dwReadData == 0);
329 }
330 #endif
331 #endif
332 
HAL_MMIO_FlushMemory(void)333 void HAL_MMIO_FlushMemory(void)
334 {
335 #if defined(__aarch64__) || defined(__arm__)
336 #ifndef MSOS_TYPE_LINUX
337     _chip_flush_miu_pipe();
338 #endif
339 #endif
340 }
341 
HAL_MMIO_ReadMemory(void)342 void HAL_MMIO_ReadMemory(void)
343 {
344 #if defined(__aarch64__) || defined(__arm__)
345 #ifndef MSOS_TYPE_LINUX
346     _chip_flush_miu_pipe();
347 #endif
348 #endif
349 }
350 
351 
352