xref: /utopia/UTPA2-700.0.x/modules/dms/hal/k6lite/dms/halDMS.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 // Copyright (c) 2006-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // (��MStar Confidential Information��) by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94 
95 ///////////////////////////////////////////////////////////////////////////////////////////////////
96 ///
97 /// file    halDMS.c
98 /// @author MStar Semiconductor Inc.
99 /// @brief  DMS Utility HAL
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101 #define  HAL_DMS_C
102 
103 //-------------------------------------------------------------------------------------------------
104 //  Include Files
105 //-------------------------------------------------------------------------------------------------
106 // Common Definition
107 #ifdef MSOS_TYPE_LINUX_KERNEL
108 #include <linux/string.h>
109 #else
110 #include <stdlib.h>
111 #include <string.h>
112 #include <unistd.h>
113 #endif
114 
115 #include "MsCommon.h"
116 #include "MsVersion.h"
117 #include "drvMMIO.h"
118 //#include "apiDMS_Type.h"
119 #include "drvDMS.h"
120 #include "halDMS.h"
121 #include "UFO.h"
122 #include "apiPNL.h"
123 
124 #include "utopia.h"
125 #include "utopia_dapi.h"
126 #include "apiDMS_private.h"
127 
128 #ifndef ANDROID
129 #define DMS_PRINTF printf
130 #else
131 #include <sys/mman.h>
132 #include <cutils/ashmem.h>
133 #include <cutils/log.h>
134 
135 #define DMS_PRINTF ALOGD
136 #endif
137 
138 //-------------------------------------------------------------------------------------------------
139 //  Driver Compiler Options
140 //-------------------------------------------------------------------------------------------------
141 
142 //-------------------------------------------------------------------------------------------------
143 //  Local Defines
144 //-------------------------------------------------------------------------------------------------
145 #define REG_MEMSYNC_BLACK_MODE               (0x117E)
146 #define BIT_MEMSYNC_PIXEL_MASK_EN            (0x100)
147 #define BIT_MEMSYNC_MOTION_RATIO_MASK_EN     (0x200)
148 #define BIT_MEMSYNC_RESET                    (0x400)
149 #define BIT_MEMSYNC_DELAY_ONE_FRAME          (0x800)
150 #define BIT_MEMSYNC_DOTLINE                  (0x1000)
_DMS_XC_SetVideoMute_AutoSync(MS_BOOL bEnable)151 static MS_BOOL _DMS_XC_SetVideoMute_AutoSync(MS_BOOL bEnable)
152 {
153     MS_U16 u16MemSyncMask = BIT_MEMSYNC_DELAY_ONE_FRAME|BIT_MEMSYNC_MOTION_RATIO_MASK_EN|BIT_MEMSYNC_PIXEL_MASK_EN;
154     if(MApi_XC_IsCurrentFrameBufferLessMode() ||
155         MApi_XC_IsCurrentRequest_FrameBufferLessMode())
156     {
157         u16MemSyncMask &= ~BIT_MEMSYNC_PIXEL_MASK_EN;
158     }
159 
160     if(bEnable == TRUE)
161     {
162         u16MemSyncMask |= BIT_MEMSYNC_RESET;
163         MApi_XC_GenerateBlackVideo(bEnable, MAIN_WINDOW);
164         MApi_XC_W2BYTEMSK(REG_MEMSYNC_BLACK_MODE, u16MemSyncMask, BIT_MEMSYNC_DOTLINE|BIT_MEMSYNC_DELAY_ONE_FRAME|BIT_MEMSYNC_RESET|BIT_MEMSYNC_MOTION_RATIO_MASK_EN|BIT_MEMSYNC_PIXEL_MASK_EN);
165         MApi_XC_Mux_OnOffPeriodicHandler(INPUT_SOURCE_DTV, DISABLE);
166     }
167     else
168     {
169         MApi_XC_W2BYTEMSK(REG_MEMSYNC_BLACK_MODE, u16MemSyncMask, BIT_MEMSYNC_DOTLINE|BIT_MEMSYNC_DELAY_ONE_FRAME|BIT_MEMSYNC_RESET|BIT_MEMSYNC_MOTION_RATIO_MASK_EN|BIT_MEMSYNC_PIXEL_MASK_EN);
170         MApi_XC_WaitOutputVSync(5, 100, MAIN_WINDOW);
171         MApi_XC_GenerateBlackVideo(bEnable, MAIN_WINDOW);
172         MApi_XC_Mux_OnOffPeriodicHandler(INPUT_SOURCE_DTV, ENABLE);
173     }
174     return TRUE;
175 }
176 
Hal_DMS_XC_SetMute(void * pInstance,MS_BOOL bEnable)177 MS_BOOL Hal_DMS_XC_SetMute(void* pInstance, MS_BOOL bEnable)
178 {
179     MS_BOOL bRet = FALSE;
180     MApi_XC_SkipWaitVsync(MAIN_WINDOW,TRUE);
181     bRet = _DMS_XC_SetVideoMute_AutoSync(bEnable);
182     MApi_XC_SkipWaitVsync(MAIN_WINDOW,FALSE);
183     return bRet;
184 }
185 
186 #define H_PostScalingRatio(Input, Output)          ((MS_U32)( ((MS_U64)(Input)) * 2097152ul / (Output) + 1 )/2)
187 #define V_PostScalingRatio(Input, Output)          ((MS_U32)( ((MS_U64)(Input) * 2097152ul) / Output + 1) / 2)
188 #define DMS_DS_DEPTH 0x8
189 #define DMS_DS_SET_COUNT 0x6
190 #define ALL_IP_COMMAND 0
191 extern void* g_pDMSRes;
192 
HAL_DMS_XC_DSSetConfig(void * pInstance)193 MS_BOOL HAL_DMS_XC_DSSetConfig(void* pInstance)
194 {
195     DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
196     UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
197     memset(&pDMSResPri->stHalDMS.stDMS_DSSWDB, 0 , sizeof(pDMSResPri->stHalDMS.stDMS_DSSWDB));
198     pDMSResPri->stHalDMS.phyDSAddr = MApi_XC_R4BYTE(0x1F22);
199     pDMSResPri->stHalDMS.phyDSAddr *= 0x20;
200     printf("Get DS Addr 0x%llx\n",pDMSResPri->stHalDMS.phyDSAddr);
201     // SC0_MCU_DS_AVAILABLE
202     //Set DS is out of DMS
203     #if 0
204     XC_DynamicScaling_Info stDSInfo;
205     stDSInfo.u32DS_Info_BaseAddr = gphy_DSAddr;
206     stDSInfo.bOP_DS_On           = 0;
207     stDSInfo.u8DS_Index_Depth    = DMS_DS_DEPTH;
208     stDSInfo.bOP_DS_On           = TRUE;
209     stDSInfo.bIPS_DS_On          = FALSE;
210     stDSInfo.bIPM_DS_On          = TRUE;
211     MApi_XC_SetDynamicScaling(&stDSInfo,sizeof(stDSInfo),MAIN_WINDOW);
212     #endif
213     #if ALL_IP_COMMAND
214     MApi_XC_W2BYTEMSK(0x1F26,0x10,0xFF);
215     #else
216     //MApi_XC_W2BYTEMSK(0x2032,0x0,0x300);
217     #endif
218     return TRUE;
219 }
220 
221 #define DS_CMD_LEN_64BITS                   8
222 #define BYTE_PER_WORD           (32)  // MIU 128: 16Byte/W, MIU 256: 32Byte/W
223 #define OP_BASE_OFFSET (2 * DMS_DS_SET_COUNT * DMS_DS_DEPTH * BYTE_PER_WORD)
Hal_DMS_ResetSWDSCommand(void * pInstance,MS_U8 u8DSIndex)224 void Hal_DMS_ResetSWDSCommand(void* pInstance, MS_U8 u8DSIndex)
225 {
226     DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
227     UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
228 
229 #if ALL_IP_COMMAND
230     MS_PHY u32IndexBase = pDMSResPri->stHalDMS.phyDSAddr + u8DSIndex * DMS_DS_DEPTH * 2 * BYTE_PER_WORD;
231 #else
232     MS_PHY u32IndexBase = pDMSResPri->stHalDMS.phyDSAddr + u8DSIndex * DMS_DS_DEPTH * BYTE_PER_WORD;
233     MS_PHY u32IndexBase_OP = u32IndexBase + OP_BASE_OFFSET;
234 #endif
235 
236     MS_U16 u16TotalCmdCnt = DMS_DS_DEPTH;
237     MS_U16 i = 0;
238 
239     MS_U64 *pu64Data = NULL;
240     u16TotalCmdCnt *= 2;
241     u16TotalCmdCnt *= 2;
242 
243     for(i = 0; i < u16TotalCmdCnt; i++)
244     {
245         pu64Data  = (MS_U64*)MsOS_PA2KSEG1(u32IndexBase + i*DS_CMD_LEN_64BITS);
246         *pu64Data = 0x00000009FFFF0000;
247     }
248 #if (ALL_IP_COMMAND == 0)
249     for(i = 0; i < u16TotalCmdCnt; i++)
250     {
251         pu64Data  = (MS_U64*)MsOS_PA2KSEG1(u32IndexBase_OP + i*DS_CMD_LEN_64BITS);
252         *pu64Data = 0x00000009FFFF0000;
253     }
254 #endif
255 }
256 
Hal_DMS_WriteSWDSCommand(void * pInstance,SCALER_WIN eWindow,MS_U32 u32CmdRegAddr,MS_U16 u16CmdRegValue,DMS_ds_reg_ip_op_sel IPOP_Sel,DMS_ds_reg_source_sel Source_Select,DMS_DS_CMDCNT * pstXC_DS_CmdCnt)257 void Hal_DMS_WriteSWDSCommand(void* pInstance, SCALER_WIN eWindow, MS_U32 u32CmdRegAddr, MS_U16 u16CmdRegValue, DMS_ds_reg_ip_op_sel IPOP_Sel, DMS_ds_reg_source_sel Source_Select, DMS_DS_CMDCNT *pstXC_DS_CmdCnt)
258 {
259     DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
260     UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
261 
262     if(pstXC_DS_CmdCnt->u16CMDCNT_IPM == 0 && pstXC_DS_CmdCnt->u16CMDCNT_OPM == 0)
263     {
264         Hal_DMS_ResetSWDSCommand(pInstance, pDMSResPri->stHalDMS.u8DSIndex);
265     }
266 #if ALL_IP_COMMAND
267     MS_PHY u32Addr = pDMSResPri->stHalDMS.phyDSAddr + pDMSResPri->stHalDMS.u8DSIndex * DMS_DS_DEPTH * 2 * BYTE_PER_WORD;
268 #else
269     MS_PHY u32Addr = pDMSResPri->stHalDMS.phyDSAddr + pDMSResPri->stHalDMS.u8DSIndex * DMS_DS_DEPTH * BYTE_PER_WORD;
270 #endif
271 
272     //XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] u32DynamicScalingBaseAddr:%x  CurIdx:%d  IdxDepth:%d  BYTE_PER_WORD:%d  \n",__func__,__LINE__,(int)pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr,(int)pXCResourcePrivate->sthal_SC.u8DynamicScalingCurrentIndex[eWindow],(int)pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth,(int)BYTE_PER_WORD);
273     //XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] u32Addr:%x  \n",__func__,__LINE__,(int)u32Addr);
274 
275     MS_U64 *pu64Data = NULL;
276     MS_U64 u64CmdTemp = 0;
277     MS_U8  u8AddrTemp = 0;
278     MS_U16 u16BankTemp = 0;
279     MS_U16 u16DataTemp = 0;
280     MS_U16 u16MaskTemp = 0;
281     MS_U8 u8MaxCmdCnt = DMS_DS_DEPTH * 2;
282 #if ALL_IP_COMMAND
283     u8MaxCmdCnt *= 2;
284 #endif
285 
286     if(Source_Select == DMS_DS_XC)
287     {
288         u16MaskTemp = 0xFFFF;
289         u16DataTemp = u16CmdRegValue;
290 
291         u8AddrTemp= (u32CmdRegAddr & 0x000000FF) >> 1;
292         u16BankTemp= 0x1300 | ((u32CmdRegAddr >> 8) & 0x000000FF); // 0x13XX xc sread mode address
293 
294         u64CmdTemp|= (MS_U64)u16DataTemp;
295         u64CmdTemp|= ((MS_U64)u8AddrTemp<<16);
296         u64CmdTemp|= ((MS_U64)u16BankTemp<<23);
297         u64CmdTemp|= ((MS_U64)u16MaskTemp<<48);
298 
299         if(IPOP_Sel == DS_IP)
300         {
301             if(eWindow == MAIN_WINDOW)
302             {
303                 MS_U32 u32MemShift_IPM;
304 
305                 if((pstXC_DS_CmdCnt->u16CMDCNT_IPM % 2) == 0)
306                 {
307                     u32MemShift_IPM = (pstXC_DS_CmdCnt->u16CMDCNT_IPM / 2) * BYTE_PER_WORD;
308                 }
309                 else
310                 {
311                     u32MemShift_IPM = (pstXC_DS_CmdCnt->u16CMDCNT_IPM / 2) * BYTE_PER_WORD  + DS_CMD_LEN_64BITS;
312                 }
313                 //XC_PRINTF("[%s,%5d] [DS_IP]pstXC_DS_CmdCnt->u16CMDCNT_IPM:%d u32MemShift_IPM:%lx \n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_IPM,(MS_U32)u32MemShift_IPM);
314                 //u32Addr = u32Addr + DS_CMD_LEN_64BITS * pstXC_DS_CmdCnt->u16CMDCNT_IPM;
315                 u32Addr = u32Addr + u32MemShift_IPM;
316                 if(0)//u32Addr == 0x11956200)
317                 {
318                     printf("[%s] addr 0x%llx, 0x%llx\n",__FUNCTION__,*((MS_U64*)MsOS_PA2KSEG1(0x11956200)),u64CmdTemp);
319                 }
320 
321                 pu64Data = (MS_U64*)MsOS_PA2KSEG1(u32Addr);//IPM
322 
323                 if(pstXC_DS_CmdCnt->u16CMDCNT_IPM < u8MaxCmdCnt)
324                 {
325                     *pu64Data = u64CmdTemp;
326                     pstXC_DS_CmdCnt->u16CMDCNT_IPM++;
327                 }
328                 else
329                 {
330                     printf("[%s,%5d] [DS] IPM Command count overflow !!  u16CMDCNT_IPM:%d  Max command count: %d\n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_IPM,DMS_DS_DEPTH * 2);
331                 }
332             }
333         }
334         else
335         {
336             if(eWindow == MAIN_WINDOW)
337             {
338                 MS_U32 u32MemShift_OPM;
339 
340                 if((pstXC_DS_CmdCnt->u16CMDCNT_OPM % 2) == 0)
341                 {
342                     u32MemShift_OPM = (pstXC_DS_CmdCnt->u16CMDCNT_OPM / 2) * BYTE_PER_WORD;
343                 }
344                 else
345                 {
346                     u32MemShift_OPM = (pstXC_DS_CmdCnt->u16CMDCNT_OPM / 2) * BYTE_PER_WORD  + DS_CMD_LEN_64BITS;
347                 }
348                 //XC_PRINTF("[%s,%5d] [DS_IP]pstXC_DS_CmdCnt->u16CMDCNT_IPM:%d u32MemShift_IPM:%lx \n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_IPM,(MS_U32)u32MemShift_IPM);
349                 //u32Addr = u32Addr + DS_CMD_LEN_64BITS * pstXC_DS_CmdCnt->u16CMDCNT_IPM;
350                 u32Addr = u32Addr + u32MemShift_OPM + OP_BASE_OFFSET;
351                 pu64Data = (MS_U64*)MsOS_PA2KSEG1(u32Addr);//IPM
352 
353                 if(pstXC_DS_CmdCnt->u16CMDCNT_OPM < u8MaxCmdCnt)
354                 {
355                     *pu64Data = u64CmdTemp;
356                     pstXC_DS_CmdCnt->u16CMDCNT_OPM++;
357                 }
358                 else
359                 {
360                     printf("[%s,%5d] [DS] OPM Command count overflow !!  u16CMDCNT_OPM:%d  Max command count: %d\n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_OPM,DMS_DS_DEPTH * 2);
361                 }
362             }
363         }
364     }
365     else if(Source_Select == DMS_DS_MVOP)// only in IP cmd
366     {
367         u16DataTemp = u16CmdRegValue;
368         u8AddrTemp = (u32CmdRegAddr&0x000000FF);
369         u16BankTemp = (u32CmdRegAddr&0x00FFFF00) >> 8; //EX: mvop mainwinodw: 0x1014 mvop bank
370         u16MaskTemp = 0xFFFF;
371 
372         u64CmdTemp|= (MS_U64)u16DataTemp;
373         u64CmdTemp|= ((MS_U64)u8AddrTemp<<16);
374         u64CmdTemp|= ((MS_U64)u16BankTemp<<23);
375         u64CmdTemp|= ((MS_U64)u16MaskTemp<<48);
376 
377         if(eWindow == MAIN_WINDOW)
378         {
379             MS_U32 u32MemShift_IPM;
380 
381             if((pstXC_DS_CmdCnt->u16CMDCNT_IPM % 2) == 0)
382             {
383                 u32MemShift_IPM = (pstXC_DS_CmdCnt->u16CMDCNT_IPM / 2) * BYTE_PER_WORD;
384             }
385             else
386             {
387                 u32MemShift_IPM = (pstXC_DS_CmdCnt->u16CMDCNT_IPM / 2) * BYTE_PER_WORD  + DS_CMD_LEN_64BITS;
388             }
389             //XC_PRINTF("[%s,%5d] [DS_IP(MVOP)]pstXC_DS_CmdCnt->u16CMDCNT_IPM:%d u32MemShift_IPM:%lx \n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_IPM,(MS_U32)u32MemShift_IPM);
390             //u32Addr = u32Addr + DS_CMD_LEN_64BITS * pstXC_DS_CmdCnt->u16CMDCNT_IPM;
391             u32Addr = u32Addr + u32MemShift_IPM;
392             pu64Data = (MS_U64*)MsOS_PA2KSEG1(u32Addr);//IPM
393 
394             if(pstXC_DS_CmdCnt->u16CMDCNT_IPM < u8MaxCmdCnt)
395             {
396                 *pu64Data = u64CmdTemp;
397                 pstXC_DS_CmdCnt->u16CMDCNT_IPM++;
398             }
399             else
400             {
401                 printf("[%s,%5d] [DS] Command count overflow !!  u16CMDCNT_IPM:%d  Max command count: %d\n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_IPM,DMS_DS_DEPTH * 2);
402             }
403         }
404     }
405     else
406     {
407         printf("[%s,%5d] [DS] Only can support XC/MVOP/GOP NOW !! \n",__func__,__LINE__);
408     }
409 
410 }
411 
Hal_DMS_Add_NullCommand(void * pInstance,SCALER_WIN eWindow,DMS_ds_reg_ip_op_sel IPOP_Sel,DMS_DS_CMDCNT * pstXC_DS_CmdCnt)412 void Hal_DMS_Add_NullCommand(void* pInstance, SCALER_WIN eWindow, DMS_ds_reg_ip_op_sel IPOP_Sel, DMS_DS_CMDCNT *pstXC_DS_CmdCnt)
413 {
414     DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
415     UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
416 
417     MS_U16 u16MaxCmdCnt = DMS_DS_DEPTH * 2; // It has two 64bit commands per MIU bus width
418     MS_U64 *pu64Data = NULL;
419     MS_U16 i;
420 #if ALL_IP_COMMAND
421     u16MaxCmdCnt *= 2;
422 #endif
423 
424     if(eWindow == MAIN_WINDOW)
425     {
426         if(IPOP_Sel == DS_IP)
427         {
428             for(i=pstXC_DS_CmdCnt->u16CMDCNT_IPM;i<u16MaxCmdCnt;i++)
429             {
430                 MS_PHY u32IndexBase= (pDMSResPri->stHalDMS.phyDSAddr +
431                     (MS_U32)pDMSResPri->stHalDMS.u8DSIndex * u16MaxCmdCnt * BYTE_PER_WORD +
432                     (i / 2) * BYTE_PER_WORD + (i % 2) * DS_CMD_LEN_64BITS);
433                 pu64Data  = (MS_U64*)MsOS_PA2KSEG1(u32IndexBase);
434                 *pu64Data = 0x00000009FFFF0000;
435             }
436         }
437 #if (ALL_IP_COMMAND == 0)
438         else
439         {
440             for(i=pstXC_DS_CmdCnt->u16CMDCNT_OPM;i<u16MaxCmdCnt;i++)
441             {
442                 MS_PHY u32IndexBase= (pDMSResPri->stHalDMS.phyDSAddr + OP_BASE_OFFSET +
443                     (MS_U32)pDMSResPri->stHalDMS.u8DSIndex * u16MaxCmdCnt * BYTE_PER_WORD +
444                     (i / 2) * BYTE_PER_WORD + (i % 2) * DS_CMD_LEN_64BITS);
445                 pu64Data  = (MS_U64*)MsOS_PA2KSEG1(u32IndexBase);
446                 *pu64Data = 0x00000009FFFF0000;
447             }
448         }
449 #endif
450     }
451 }
452 
HAL_DMS_XC_DSSetWin(void * pInstance,MS_WINDOW_TYPE * stMVOPCropWindow,const XC_SETWIN_INFO * stXCSetWinInfo,MS_U32 u32FlowFlag)453 MS_BOOL HAL_DMS_XC_DSSetWin(void* pInstance, MS_WINDOW_TYPE* stMVOPCropWindow, const XC_SETWIN_INFO* stXCSetWinInfo, MS_U32 u32FlowFlag)
454 {
455     DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
456     UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
457 
458     MS_U32 u32HRatio = 0;
459     MS_U32 u32VRatio = 0;
460     //printf("[%s] Post: %d -> %d, %d -> %d, flow %d\n",__FUNCTION__,stXCSetWinInfo->u16HCusScalingSrc,stXCSetWinInfo->u16HCusScalingDst,
461     //    stXCSetWinInfo->u16VCusScalingSrc,stXCSetWinInfo->u16VCusScalingDst,u32FlowFlag);
462 
463     if(stXCSetWinInfo->u16HCusScalingSrc != stXCSetWinInfo->u16HCusScalingDst)
464     {
465         u32HRatio = H_PostScalingRatio(stXCSetWinInfo->u16HCusScalingSrc, stXCSetWinInfo->u16HCusScalingDst);
466         u32HRatio &= 0x0FFFFFF;
467         u32HRatio |= 0x1000000;
468     }
469 
470     if(stXCSetWinInfo->u16VCusScalingSrc != stXCSetWinInfo->u16VCusScalingDst)
471     {
472         u32VRatio = V_PostScalingRatio(stXCSetWinInfo->u16VCusScalingSrc, stXCSetWinInfo->u16VCusScalingDst);
473         u32VRatio &= 0x00FFFFFF;
474         u32VRatio |= 0x81000000;
475     }
476 
477     pDMSResPri->stHalDMS.stDMS_DSSWDB.u32FlowFlag = u32FlowFlag;
478     pDMSResPri->stHalDMS.stDMS_DSSWDB.u32HPostRatio = u32HRatio;
479     pDMSResPri->stHalDMS.stDMS_DSSWDB.u32VPostRatio = u32VRatio;
480 
481     if(1)//u32FlowFlag == 1)
482     {
483         //from DIP need display window
484         pDMSResPri->stHalDMS.stDMS_DSSWDB.u16H_Start = g_IPanel.HStart() + stXCSetWinInfo->stDispWin.x;
485         pDMSResPri->stHalDMS.stDMS_DSSWDB.u16H_End   = pDMSResPri->stHalDMS.stDMS_DSSWDB.u16H_Start + stXCSetWinInfo->stDispWin.width - 1;
486         pDMSResPri->stHalDMS.stDMS_DSSWDB.u16V_Start = stXCSetWinInfo->stDispWin.y;
487         pDMSResPri->stHalDMS.stDMS_DSSWDB.u16V_End   = pDMSResPri->stHalDMS.stDMS_DSSWDB.u16V_Start + stXCSetWinInfo->stDispWin.height - 1;
488     }
489 
490     pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.x = stMVOPCropWindow->x;
491     pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.y = stMVOPCropWindow->y;
492     pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.width = stMVOPCropWindow->width;
493     pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.height = stMVOPCropWindow->height;
494     //printf("[%s] MVOP: %d %d, %d %d\n",__FUNCTION__,gDMS_DSSWDB.stMVOPCropWindow.x,gDMS_DSSWDB.stMVOPCropWindow.y,gDMS_DSSWDB.stMVOPCropWindow.width,gDMS_DSSWDB.stMVOPCropWindow.height);
495     //printf("[%s] Disp: %d %d, %d %d\n",__FUNCTION__,gDMS_DSSWDB.u16H_Start,gDMS_DSSWDB.u16H_End,gDMS_DSSWDB.u16V_Start,gDMS_DSSWDB.u16V_End);
496     //printf("[%s] H:0x%x , V:0x%x\n",__FUNCTION__,gDMS_DSSWDB.u32HPostRatio,gDMS_DSSWDB.u32VPostRatio);
497 
498     return TRUE;
499 }
500 
HAL_DMS_XC_DSSetMVOPPitch(void * pInstance,MS_U16 u16Pitch)501 MS_BOOL HAL_DMS_XC_DSSetMVOPPitch(void* pInstance, MS_U16 u16Pitch)
502 {
503     DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
504     UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
505 
506     pDMSResPri->stHalDMS.stDMS_DSSWDB.u16MVOP_Pitch = u16Pitch;
507     printf("[%s] Pitch: %d\n",__FUNCTION__,pDMSResPri->stHalDMS.stDMS_DSSWDB.u16MVOP_Pitch);
508     return TRUE;
509 }
510 
HAL_DMS_XC_DSSetMVOPAddr(void * pInstance,MS_PHY phyLumaAddr,MS_PHY phyChromaAddr,MS_BOOL b422Pack)511 MS_BOOL HAL_DMS_XC_DSSetMVOPAddr(void* pInstance, MS_PHY phyLumaAddr, MS_PHY phyChromaAddr, MS_BOOL b422Pack)
512 {
513     DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
514     UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
515 
516     pDMSResPri->stHalDMS.stDMS_DSSWDB.bMVOP_422Pack = b422Pack;
517     pDMSResPri->stHalDMS.stDMS_DSSWDB.phyMVOP_LumaAddr = phyLumaAddr;
518     pDMSResPri->stHalDMS.stDMS_DSSWDB.phyMVOP_ChromaAddr = phyChromaAddr;
519     return TRUE;
520 }
521 
522 #define MI_FLOW_PATCH 1
523 extern MS_U16 gDMSMVOPForceLookVDEC;
HAL_DMS_XC_DSFire(void * pInstance)524 MS_BOOL HAL_DMS_XC_DSFire(void* pInstance)
525 {
526     DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
527     UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
528 
529 #if (ALL_IP_COMMAND == 0)
530     if(MApi_XC_R2BYTEMSK(0x0006,0x1000))
531     {
532         MApi_XC_W2BYTEMSK(0x0006,0,0x1000);
533     }
534 #endif
535 
536 #if MI_FLOW_PATCH
537 //This Patch for FBL W/R diff need to be 0
538     if(MApi_XC_R2BYTEMSK(0x120E,0xF000))
539     {
540         MApi_XC_W2BYTEMSK(0x120E,0,0xF000);
541     }
542 //This Patch for FBL W/R must disable
543     if(MApi_XC_R2BYTEMSK(0x120E,0x0003) != 3)
544     {
545         MApi_XC_W2BYTEMSK(0x120E,0x0003,0x0003);
546     }
547 //This Patch for FBL DataFormat can not set
548     if(MApi_XC_R2BYTEMSK(0x1202,0x2F00))
549     {
550         MApi_XC_W2BYTEMSK(0x1202,0,0x2F00);
551     }
552 //This Patch for FBL do not need miu write size protect
553     if(MApi_XC_R2BYTEMSK(0x1230,0x8000))
554     {
555         MApi_XC_W2BYTEMSK(0x1230,0,0x8000);
556     }
557 
558 #endif
559 
560     DMS_DS_CMDCNT STXC_DS_CMDCNT;
561     STXC_DS_CMDCNT.u16CMDCNT_IPM =0;
562     STXC_DS_CMDCNT.u16CMDCNT_IPS =0;
563     STXC_DS_CMDCNT.u16CMDCNT_OPM =0;
564     STXC_DS_CMDCNT.u16CMDCNT_OPS =0;
565     //printf("[%s] MVOP: %d %d, %d %d\n",__FUNCTION__,gDMS_DSSWDB.stMVOPCropWindow.x,gDMS_DSSWDB.stMVOPCropWindow.y,gDMS_DSSWDB.stMVOPCropWindow.width,gDMS_DSSWDB.stMVOPCropWindow.height);
566     //printf("[%s] Disp: %d %d, %d %d\n",__FUNCTION__,gDMS_DSSWDB.u16H_Start,gDMS_DSSWDB.u16H_End,gDMS_DSSWDB.u16V_Start,gDMS_DSSWDB.u16V_End);
567     //printf("[%s] Pitch: %d\n",__FUNCTION__,gDMS_DSSWDB.u16MVOP_Pitch);
568     //printf("[%s] H:0x%x , V:0x%x\n",__FUNCTION__,gDMS_DSSWDB.u32HPostRatio,gDMS_DSSWDB.u32VPostRatio);
569 
570 #if ALL_IP_COMMAND
571     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x1010, pDMSResPri->stHalDMS.stDMS_DSSWDB.u16H_Start, DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
572     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x1012, pDMSResPri->stHalDMS.stDMS_DSSWDB.u16H_End, DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
573     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x1014, pDMSResPri->stHalDMS.stDMS_DSSWDB.u16V_Start, DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
574     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x1016, pDMSResPri->stHalDMS.stDMS_DSSWDB.u16V_End, DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
575 
576     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x230E, pDMSResPri->stHalDMS.stDMS_DSSWDB.u32HPostRatio & 0xFFFF          , DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
577     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x2310, (pDMSResPri->stHalDMS.stDMS_DSSWDB.u32HPostRatio >> 16) & 0xFFFF  , DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
578     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x2312, pDMSResPri->stHalDMS.stDMS_DSSWDB.u32VPostRatio & 0xFFFF          , DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
579     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x2314, (pDMSResPri->stHalDMS.stDMS_DSSWDB.u32VPostRatio >> 16) & 0xFFFF  , DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
580 
581     //Disable pre scaling for pre scaling be set out of DMS
582     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x0210, 0 , DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
583     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x0212, 0 , DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
584     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x0208, 0 , DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
585     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x020A, 0 , DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
586 
587     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x202A, pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.height & 0x0FFF  , DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
588 
589 #else
590     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x1010, pDMSResPri->stHalDMS.stDMS_DSSWDB.u16H_Start, DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
591     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x1012, pDMSResPri->stHalDMS.stDMS_DSSWDB.u16H_End, DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
592     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x1014, pDMSResPri->stHalDMS.stDMS_DSSWDB.u16V_Start, DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
593     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x1016, pDMSResPri->stHalDMS.stDMS_DSSWDB.u16V_End, DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
594 
595     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x230E, pDMSResPri->stHalDMS.stDMS_DSSWDB.u32HPostRatio & 0xFFFF          , DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
596     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x2310, (pDMSResPri->stHalDMS.stDMS_DSSWDB.u32HPostRatio >> 16) & 0xFFFF  , DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
597     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x2312, pDMSResPri->stHalDMS.stDMS_DSSWDB.u32VPostRatio & 0xFFFF          , DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
598     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x2314, (pDMSResPri->stHalDMS.stDMS_DSSWDB.u32VPostRatio >> 16) & 0xFFFF  , DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
599 
600     //Disable pre scaling for pre scaling be set out of DMS
601     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x0210, 0 , DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
602     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x0212, 0 , DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
603     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x0208, 0 , DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
604     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x020A, 0 , DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
605 
606     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x202A, pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.height & 0x0FFF  , DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
607 #if MI_FLOW_PATCH
608 //This Patch for keep ipm/opm fetch to max size
609     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x121E, 0x1000 , DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
610     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x122E, 0x1000 , DS_OP, DMS_DS_XC, &STXC_DS_CMDCNT);
611 #endif
612 
613 #endif
614 
615     MS_U16 u16MVOPForceWrite = MApi_XC_ReadByte(0x10144E);
616     u16MVOPForceWrite |= 0x10;
617     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101427, u16MVOPForceWrite    , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
618     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101440, pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.x  , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
619     if(pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.y == 0)
620     {
621         Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101441, (pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.y | 0xE000), DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
622     }
623     else
624     {
625         Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101441, (pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.y | 0xA000), DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
626     }
627     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101442, pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.width    , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
628     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101443, pDMSResPri->stHalDMS.stDMS_DSSWDB.stMVOPCropWindow.height   , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
629 
630     if(1)//gDMS_DSSWDB.u32FlowFlag == 1)
631     {
632         MS_PHY phyAddr = pDMSResPri->stHalDMS.stDMS_DSSWDB.phyMVOP_LumaAddr >> 3;
633         Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101421, phyAddr & 0xFFFF           , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
634         Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101422, (phyAddr >> 16) & 0x1FFF  , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
635         if(pDMSResPri->stHalDMS.stDMS_DSSWDB.bMVOP_422Pack)
636         {
637             phyAddr = pDMSResPri->stHalDMS.stDMS_DSSWDB.phyMVOP_LumaAddr + 16;
638         }
639         else
640         {
641             phyAddr = pDMSResPri->stHalDMS.stDMS_DSSWDB.phyMVOP_ChromaAddr;
642         }
643         phyAddr = phyAddr >> 3;
644         Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101423, phyAddr & 0xFFFF           , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
645         Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101424, (phyAddr >> 16) & 0x1FFF  , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
646     }
647 
648 //Pitch & Tile
649     MS_U8 u8MVOPCtrl0_H = MApi_XC_ReadByte(0x101441);
650     MS_U8 u8MVOPCtrl0_L = MApi_XC_ReadByte(0x101440);
651     MS_U8 u8MVOPPitch_L = MApi_XC_ReadByte(0x101430);
652     u8MVOPPitch_L = (u8MVOPPitch_L & (0xFF - 0x03)) | ((pDMSResPri->stHalDMS.stDMS_DSSWDB.u16MVOP_Pitch >> 8) & 0x03);
653     u8MVOPCtrl0_H = (pDMSResPri->stHalDMS.stDMS_DSSWDB.u16MVOP_Pitch & 0xFF);
654     if(pDMSResPri->stHalDMS.stDMS_DSSWDB.u32FlowFlag == 1)
655     {
656         //DIP
657         u8MVOPCtrl0_L = (u8MVOPCtrl0_L | 0xB0);
658     }
659     else if(pDMSResPri->stHalDMS.stDMS_DSSWDB.u32FlowFlag == 2)
660     {
661         //VDEC
662         u8MVOPCtrl0_L = (u8MVOPCtrl0_L & (0xFF - 0xB0));
663     }
664 
665     MS_U16 u16MVOPCtrl0 = u8MVOPCtrl0_H;
666     u16MVOPCtrl0 = ((u16MVOPCtrl0 << 8) | u8MVOPCtrl0_L);
667     if((gDMSMVOPForceLookVDEC == 1))
668     {
669         Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101418, 0 , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
670         Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101420, 0xF006 , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
671     }
672     else
673     {
674         Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101418, u8MVOPPitch_L , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
675         Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101420, u16MVOPCtrl0 , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
676     }
677 
678     u16MVOPForceWrite &= ~0x10;
679     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x101427, u16MVOPForceWrite    , DS_IP, DMS_DS_MVOP, &STXC_DS_CMDCNT);
680 
681     MS_U32 ActiveSWClearEn = 0;
682     ActiveSWClearEn = MApi_XC_R2BYTE(0x1F2E);
683     ActiveSWClearEn |= 0x0010;//u32SW_Reset_IPM;
684     Hal_DMS_WriteSWDSCommand(pInstance, MAIN_WINDOW, 0x1F2E, ActiveSWClearEn  , DS_IP, DMS_DS_XC, &STXC_DS_CMDCNT);
685 
686     Hal_DMS_Add_NullCommand(pInstance, MAIN_WINDOW, DS_IP,&STXC_DS_CMDCNT);
687     Hal_DMS_Add_NullCommand(pInstance, MAIN_WINDOW, DS_OP,&STXC_DS_CMDCNT);
688 
689 #if ALL_IP_COMMAND
690     if(STXC_DS_CMDCNT.u16CMDCNT_IPM > DMS_DS_DEPTH*4)
691 #else
692     if(STXC_DS_CMDCNT.u16CMDCNT_IPM > DMS_DS_DEPTH*2)
693 #endif
694     {
695         printf("\033[1;31m[%s][%d] error, IPM DS Command conut %d > Max_size %d\033[0m\n",__FUNCTION__,__LINE__,STXC_DS_CMDCNT.u16CMDCNT_IPM,DMS_DS_DEPTH*2);
696     }
697     if(STXC_DS_CMDCNT.u16CMDCNT_OPM > DMS_DS_DEPTH*2)
698     {
699         printf("\033[1;31m[%s][%d] error, OPM DS Command conut %d > Max_size %d\033[0m\n",__FUNCTION__,__LINE__,STXC_DS_CMDCNT.u16CMDCNT_OPM,DMS_DS_DEPTH*2);
700     }
701 
702     MApi_XC_Set_DSForceIndex(TRUE,pDMSResPri->stHalDMS.u8DSIndex,MAIN_WINDOW);
703     if(pDMSResPri->stHalDMS.u8DSIndex == 0)
704     {
705         pDMSResPri->stHalDMS.u8DSIndex = 1;
706     }
707     else
708     {
709         pDMSResPri->stHalDMS.u8DSIndex = 0;
710     }
711     return TRUE;
712 }
713 
714 
715 #include "drvCMAPool.h"
716 #include "msos/linux/mdrv_cma_pool_st.h"
717 
718 #define DMS_CMA_4MB 0x0400000
719 #define DMS_CMA_8MB 0x0800000
720 #define DMS_CMA_16MB 0x1000000
721 #define DMS_CMA_24MB 0x1800000
722 #define DMS_CMA_32MB 0x2000000
723 #define DMS_CMA_48MB 0x3000000
724 
HAL_DMS_Release_CMA(void * pInstance,EN_DMS_MEMORY_TYPE enMemType,MS_U32 u32CMAHeapID)725 MS_BOOL HAL_DMS_Release_CMA(void* pInstance, EN_DMS_MEMORY_TYPE enMemType, MS_U32 u32CMAHeapID)
726 {
727     return FALSE;
728 }
729 
HAL_DMS_Setup_CMA(void * pInstance,EN_DMS_MEMORY_TYPE enMemType,MS_U32 u32CMAHeapID)730 MS_BOOL HAL_DMS_Setup_CMA(void* pInstance, EN_DMS_MEMORY_TYPE enMemType, MS_U32 u32CMAHeapID)
731 {
732     MS_U32 u32GetCMABufferSize = 0;
733     switch(enMemType)
734     {
735         case E_DMS_MEMORY_TYPE_GOP_DISPLAY:
736         {
737 #if (DMS_DIP_Support_HVSP == 0)
738             u32GetCMABufferSize = DMS_CMA_48MB;
739 #else
740             u32GetCMABufferSize = DMS_CMA_32MB;
741 #endif
742             break;
743         }
744         case E_DMS_MEMORY_TYPE_FREEZE:
745         {
746             u32GetCMABufferSize = DMS_CMA_4MB;
747             break;
748         }
749         case E_DMS_MEMORY_TYPE_MVOP_DISPLAY:
750         {
751             u32GetCMABufferSize = DMS_CMA_24MB;
752             break;
753         }
754         default:
755         {
756             DMS_PRINTF("\033[1;31m[%s][%d] unuse mem type %d set CMA\033[0m\n",__FUNCTION__,__LINE__,enMemType);
757             break;
758         }
759     }
760     if(u32GetCMABufferSize == 0)
761     {
762         DMS_PRINTF("\033[1;31m[%s][%d] CMA buffer size = 0\033[0m\n",__FUNCTION__,__LINE__);
763         return FALSE;
764     }
765 
766     struct CMA_Pool_Alloc_Param CMA_Pool_GetMem;
767     CMA_Pool_GetMem.pool_handle_id = u32CMAHeapID;
768     CMA_Pool_GetMem.offset_in_pool = 0;
769     CMA_Pool_GetMem.flags = CMA_FLAG_VIRT_ADDR;
770     CMA_Pool_GetMem.length = u32GetCMABufferSize;
771 
772     if (MApi_CMA_Pool_GetMem(&CMA_Pool_GetMem) == FALSE)
773     {
774         DMS_PRINTF("\033[1;31m Function = %s, Line = %d, MApi_CMA_Pool_GetMem() fail!!! (Type %d, HeapID %d, Size 0x%x)\033[m\n", __PRETTY_FUNCTION__, __LINE__,
775             enMemType,u32CMAHeapID,u32GetCMABufferSize);
776         return FALSE;
777     }
778 
779     return TRUE;
780 }
781 
782 
783 
784