xref: /utopia/UTPA2-700.0.x/modules/xc/hal/maldives/xc/mhal_dynamicscaling.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) 2008-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!¡L) 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 // Common Definition
96 #ifndef MHAL_DYNAMICSCALING_C
97 #define MHAL_DYNAMICSCALING_C
98 
99 #include "MsCommon.h"
100 #include "MsOS.h"
101 #include "mhal_xc_chip_config.h"
102 #include "utopia.h"
103 #include "utopia_dapi.h"
104 #include "halCHIP.h"
105 #include "drvXC_IOPort.h"
106 #include "xc_hwreg_utility2.h"
107 #include "hwreg_sc.h"
108 #include "apiXC.h"
109 #include "apiXC_Adc.h"
110 #include "apiXC_Auto.h"
111 #include "drv_sc_display.h"
112 #include "drv_sc_isr.h"
113 #include "apiXC_PCMonitor.h"
114 #include "apiXC_ModeParse.h"
115 #include "drvXC_HDMI_if.h"
116 #include "mvideo_context.h"
117 #include "drv_sc_ip.h"
118 #if (LD_ENABLE==1)
119 #include "mdrv_ld.h"
120 #include "mdrv_ldalgo.h"
121 #endif
122 #include "mdrv_sc_3d.h"
123 #include "drv_sc_menuload.h"
124 #include "drvXC_ADC_Internal.h"
125 #include "mhal_dynamicscaling.h"
126 #include "mhal_sc.h"
127 #if FRC_INSIDE
128 #include "mdrv_frc.h"
129 #include "mhal_frc.h"
130 #endif
131 #include "mhal_menuload.h"
132 #include "XC_private.h"
133 #include "apiXC_v2.h"
134 #define DS_DBG(x)   //x
135 #define SLZ_DBG(x)  //x
136 
137 #ifdef DEBUG
138 #if ABORT_ON_ASSERT_FAILURE
139 #undef assert
140 #define assert(x) if(!(x)) ABORT
141 #else /* ABORT_ON_ASSERT_FAILURE */
142 #include <assert.h>
143 #endif /* ABORT_ON_ASSERT_FAILURE */
144 #else  /* DEBUG */
145 #ifndef assert
146 #define assert(x)
147 #endif
148 #define DEBUG 0
149 #endif /* DEBUG */
150 
151 #if SUPPORT_SEAMLESS_ZAPPING
_Hal_SC_ResetDSCommand(void * pInstance,SCALER_WIN eWindow,MS_U8 u8DSIndex)152 static void _Hal_SC_ResetDSCommand(void *pInstance, SCALER_WIN eWindow, MS_U8 u8DSIndex)
153 {
154     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
155     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
156     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
157     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
158     MS_U32 u32IndexBase = pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr + (MS_U32)u8DSIndex * pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth * BYTE_PER_WORD;
159     MS_U32 *pu32Data = NULL;
160     int i = 0;
161     SLZ_DBG(printf("@@#@@[%s]pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr=%lx, pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth=%u\n",
162         __FUNCTION__,
163         pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr,
164         pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth));
165     SLZ_DBG(printf("@@#@@u32IndexBase=%lx\n",u32IndexBase));
166     for(i = 0; i < (pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth * BYTE_PER_WORD)/4; i++)
167     {
168         if(i % 8 < 4)
169         {
170             if(MAIN_WINDOW == eWindow)
171             {
172                 if(i % 4 < 2)
173                 {
174                     pu32Data = (MS_U32*)MsOS_PA2KSEG1(u32IndexBase + (i*4));
175                     if(0 == pu32Data)
176                     {
177                         printf("%s :pu32Data_1 = 0!,error!!!\n", __FUNCTION__);
178                         assert(pu32Data != 0);
179                     }
180                     *pu32Data = 0xFFFF0000;
181                 }
182             }
183             else //SUB_WINDOW == eWindow
184             {
185                 if(i % 4 >= 2)
186                 {
187                     pu32Data = (MS_U32*)MsOS_PA2KSEG1(u32IndexBase + (i*4));
188                     if(0 == pu32Data)
189                     {
190                         printf("%s :pu32Data_2 = 0!,error!!!\n", __FUNCTION__);
191                         assert(pu32Data != 0);
192                     }
193                     *pu32Data = 0xFFFF0000;
194                 }
195             }
196         }
197         else
198         {
199             if(MAIN_WINDOW == eWindow)
200             {
201                 if(i % 4 < 2)
202                 {
203                     pu32Data = (MS_U32*)MsOS_PA2KSEG1(u32IndexBase + (i*4));
204                     if(0 == pu32Data)
205                     {
206                         printf("%s :pu32Data_3 = 0!,error!!!\n", __FUNCTION__);
207                         assert(pu32Data != 0);
208                     }
209                     *pu32Data = 0xFFFF0000;//0;
210                 }
211             }
212             else //SUB_WINDOW == eWindow
213             {
214                 if(i % 4 >= 2)
215                 {
216                     pu32Data = (MS_U32*)MsOS_PA2KSEG1(u32IndexBase + (i*4));
217                     if(0 == pu32Data)
218                     {
219                         printf("%s :pu32Data_4 = 0!,error!!!\n", __FUNCTION__);
220                         assert(pu32Data != 0);
221                     }
222                     *pu32Data = 0xFFFF0000;
223                 }
224             }
225         }
226     }
227 }
228 
Hal_SC_WriteDSCommand(void * pInstance,SCALER_WIN eWindow,MS_U16 u16CmdRegAddr,MS_U16 u16CmdRegValue)229 void Hal_SC_WriteDSCommand(void *pInstance, SCALER_WIN eWindow, MS_U16 u16CmdRegAddr, MS_U16 u16CmdRegValue)
230 {
231     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
232     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
233     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
234     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
235 
236     MS_U32 u32Addr = pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr + pXCResourcePrivate->sthal_SC.u8SeamlessZappingNextIndex[eWindow] * pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth * BYTE_PER_WORD;
237     MS_U32 *pu32Data = NULL;
238     MS_U8 u8Count = pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth;
239     MS_U32 u32Command = 0;
240 
241     if(SUB_WINDOW == eWindow)
242     {
243         u32Addr += 8; // Move to OP sub command
244     }
245 
246     u32Command = u16CmdRegValue + ((u16CmdRegAddr & 0x00FF) << 15) + ((u16CmdRegAddr & 0xFF00) << 16);
247 
248     while(u8Count > 0)
249     {
250         pu32Data = (MS_U32*)MsOS_PA2KSEG1(u32Addr);
251         if(0 == pu32Data)
252         {
253             printf("%s :pu32Data = 0!,error!!!\n", __FUNCTION__);
254             assert(pu32Data != 0);
255         }
256         // Found null command
257         if(*pu32Data == 0xFFFF0000)
258         {
259             break;
260         }
261         // Found duplicated command
262         if(*pu32Data == u32Command)
263         {
264             DS_DBG(printf("Command duplicated\n"));
265             return;
266         }
267         u32Addr += BYTE_PER_WORD;
268         u8Count--;
269     }
270 
271     if(*pu32Data == 0xFFFF0000)
272     {
273         *pu32Data = u32Command;
274     }
275     else
276     {
277         printf("DS buffer is full for this index %u!\n", pXCResourcePrivate->sthal_SC.u8SeamlessZappingNextIndex[eWindow]);
278     }
279     //printf("@@[%s][%u]u16CmdRegAddr=%x, u16CmdRegValue=%x\n",__FUNCTION__, __LINE__, u16CmdRegAddr, u16CmdRegValue);
280 }
281 
Hal_SC_PrepareSeamlessZapping(void * pInstance,SCALER_WIN eWindow)282 void Hal_SC_PrepareSeamlessZapping(void *pInstance, SCALER_WIN eWindow )
283 {
284     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
285     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
286     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
287     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
288 
289     SLZ_DBG(printf("@@#@@1.[%s]@@FRZ=%x,pXCResourcePrivate->sthal_SC.u8SeamlessZappingCurIndex[MAIN_WINDOW]=%x, pXCResourcePrivate->sthal_SC.u8SeamlessZappingNextIndex[MAIN_WINDOW]=%x\n",
290         __FUNCTION__,
291         Hal_SC_get_freezeimg(MAIN_WINDOW),
292         pXCResourcePrivate->sthal_SC.u8SeamlessZappingCurIndex[MAIN_WINDOW],
293         pXCResourcePrivate->sthal_SC.u8SeamlessZappingNextIndex[MAIN_WINDOW]));
294 
295         /// Reset the DS Memory
296 
297         /// for 2nd Seamless Zapping operating
298         if(pXCResourcePrivate->sthal_SC.u8SeamlessZappingCurIndex[eWindow] == 0)
299         {
300             pXCResourcePrivate->sthal_SC.u8SeamlessZappingNextIndex[eWindow] = 1;
301         }
302         else
303         {
304             pXCResourcePrivate->sthal_SC.u8SeamlessZappingNextIndex[eWindow] = 0;
305         }
306         SLZ_DBG(printf("@@#@@2.[%s]@@FRZ=%x,pXCResourcePrivate->sthal_SC.u8SeamlessZappingCurIndex[MAIN_WINDOW]=%x, pXCResourcePrivate->sthal_SC.u8SeamlessZappingNextIndex[MAIN_WINDOW]=%x\n",
307             __FUNCTION__,
308             Hal_SC_get_freezeimg(MAIN_WINDOW),
309             pXCResourcePrivate->sthal_SC.u8SeamlessZappingCurIndex[MAIN_WINDOW],
310             pXCResourcePrivate->sthal_SC.u8SeamlessZappingNextIndex[MAIN_WINDOW]));
311 
312         {
313             MS_U8 u8index = 0;
314             for(u8index=0; u8index<(sizeof(pXCResourcePrivate->sthal_SC.u8SeamlessZappingNextIndex)/sizeof(pXCResourcePrivate->sthal_SC.u8SeamlessZappingNextIndex[0])); u8index++)
315             {
316                 _Hal_SC_ResetDSCommand(eWindow, u8index);
317             }
318         }
319  }
320 
321 #endif
322 
323 //clear DS Buffer
Hal_SC_ResetSWDSCommand(void * pInstance,SCALER_WIN eWindow,MS_U8 u8DSIndex)324 void Hal_SC_ResetSWDSCommand(void *pInstance,SCALER_WIN eWindow, MS_U8 u8DSIndex)
325 {
326 
327     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
328     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
329     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
330     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
331 
332 #if ENABLE_64BITS_SPREAD_MODE
333 
334     MS_PHY u32IndexBase = pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr;
335 
336     MS_U16 u16TotalCmdCnt = pXCResourcePrivate->sthal_SC.u32DynamicScalingBufSize/DS_CMD_LEN_64BITS/2; //need refine
337     MS_U16 i = 0;
338 
339     MS_U16 u16SWRstCmd_Pointer = (BYTE_PER_WORD*(pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth-1))/DS_CMD_LEN_64BITS;
340     MS_U64 *pu64Data = NULL;
341     MS_U32 ActiveSWClearEn = 0;
342     MS_U16 u16CmdCntPerIndex = pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth*(BYTE_PER_WORD/DS_CMD_LEN_64BITS);
343 
344     if((u16SWRstCmd_Pointer == 0 ) || (u16SWRstCmd_Pointer == 1))
345     {
346         printf("%s :u16SWRstCmd_Pointer <= 0,error!!!\n", __FUNCTION__);
347         MS_ASSERT(u16SWRstCmd_Pointer > 0);
348     }
349     else
350     {
351         MS_PHY u32IPBaseAddr = u32IndexBase;
352         for(i = 0; i < u16TotalCmdCnt; i++)
353         {
354             pu64Data  = (MS_U64*)MsOS_PA2KSEG1(u32IPBaseAddr + i*DS_CMD_LEN_64BITS);
355 
356             if((i%u16CmdCntPerIndex) == 0)
357             {
358                 //0xFFFF00098F97048F; //BK1F_17[10] : reg_ds_ipm_active_sel: 0:HW 1:SW
359 
360                 MS_U32 u32SW_Reset_Enable = 0;
361                 //ActiveSWClearEn enable in first DS IP command ;
362                 u32SW_Reset_Enable = 0x0400; // bit10: reg_ds_ipm_active_sel
363                 ActiveSWClearEn = SC_R2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_17_L, 0xFFFF);
364                 ActiveSWClearEn |= u32SW_Reset_Enable;
365 
366                 *pu64Data = Hal_SC_GenSpreadModeCmd(pInstance, REG_SC_BK1F_17_L, (MS_U16)(ActiveSWClearEn), 0xFFFF, DS_XC);
367             }
368             else if((i%u16CmdCntPerIndex) == u16SWRstCmd_Pointer)
369             {
370                 //toggle reg_ds_ipm_active_set in last DS IP command
371                 //0xFFFF00098F97058F;//BK1F_17[8] : reg_ds_ipm_active_set
372                 MS_U32 u32SW_Reset_IPM = 0;
373                 u32SW_Reset_IPM =  0x0100 ;//bit8 : reg_ds_ipm_active_set
374                 ActiveSWClearEn |= u32SW_Reset_IPM;
375 
376                 *pu64Data = Hal_SC_GenSpreadModeCmd(pInstance, REG_SC_BK1F_17_L, (MS_U16)(ActiveSWClearEn), 0xFFFF, DS_XC);
377             }
378             else
379             {
380                 *pu64Data = MS_DS_NULL_CMD_64BITS; //Dummy cmd BKFF_7F=0x0000
381             }
382         }
383 
384         MS_PHY u32OPBaseAddr = u32IndexBase + pXCResourcePrivate->sthal_SC.u32DynamicScalingBufSize/2;//need refine
385         for(i = 0; i < u16TotalCmdCnt; i++)
386         {
387             pu64Data  = (MS_U64*)MsOS_PA2KSEG1(u32OPBaseAddr + i*DS_CMD_LEN_64BITS);
388             *pu64Data = MS_DS_NULL_CMD_64BITS; //Dummy cmd BKFF_7F=0x0000
389         }
390     }
391 #else
392     MS_U32 u32IndexBase = pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr + (MS_U32)u8DSIndex * pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth * MS_MLOAD_MEM_BASE_UNIT;
393 
394     MS_U32 *pu32Data = NULL;
395     int i = 0;
396 
397     //XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] u32DSBaseAddr:%lx  u32IndexBase:%ld  u8DSIndexDepth:%d  \n",__func__,__LINE__,pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr,u32IndexBase,pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth);
398 
399     for(i = 0; i < (pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth * MS_MLOAD_MEM_BASE_UNIT)/4; i++) //need check
400     {
401         MS_U16 u16MemShift_SWReset = 0;
402 
403         u16MemShift_SWReset = ((pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth-1) * MS_MLOAD_MEM_BASE_UNIT)/4;
404 
405         if(i % 8 < 4)
406         {
407             if(MAIN_WINDOW == eWindow)
408             {
409                 if(i % 4 < 2)
410                 {
411                     pu32Data = (MS_U32*)MsOS_PA2KSEG1(u32IndexBase + (i*4));
412                     if(0 == pu32Data)
413                     {
414                         printf("%s :pu32Data_1 = 0!,error!!!\n", __FUNCTION__);
415                         assert(pu32Data != 0);
416                     }
417 
418                     if(((i % 4) == 1) && (i < 4))
419                     {
420                         *pu32Data = 0x1F17040F;
421                     }
422                     else if(((i % 4) == 1) && (i > u16MemShift_SWReset))
423                     {
424                         *pu32Data = 0x1F17050F;
425                     }
426                     else
427                     {
428                         *pu32Data = 0xFFFF0000;
429                     }
430                 }
431             }
432             else //SUB_WINDOW == eWindow
433             {
434                 if(i % 4 >= 2)
435                 {
436                     pu32Data = (MS_U32*)MsOS_PA2KSEG1(u32IndexBase + (i*4));
437                     if(0 == pu32Data)
438                     {
439                         printf("%s :pu32Data_2 = 0!,error!!!\n", __FUNCTION__);
440                         assert(pu32Data != 0);
441                     }
442                     *pu32Data = 0xFFFF0000;
443                 }
444             }
445         }
446         else
447         {
448             if(MAIN_WINDOW == eWindow)
449             {
450                 if(i % 4 < 2)
451                 {
452                     pu32Data = (MS_U32*)MsOS_PA2KSEG1(u32IndexBase + (i*4));
453                     if(0 == pu32Data)
454                     {
455                         printf("%s :pu32Data_3 = 0!,error!!!\n", __FUNCTION__);
456                         assert(pu32Data != 0);
457                     }
458 
459                     if(((i % 4) == 1) && (i < 4))
460                     {
461                         *pu32Data = 0x1F17040F;
462                     }
463                     else if(((i % 4) == 1) && (i > u16MemShift_SWReset))
464                     {
465                         *pu32Data = 0x1F17050F;
466                     }
467                     else
468                     {
469                         *pu32Data = 0xFFFF0000;//0;
470                     }
471                 }
472             }
473             else //SUB_WINDOW == eWindow
474             {
475                 if(i % 4 >= 2)
476                 {
477                     pu32Data = (MS_U32*)MsOS_PA2KSEG1(u32IndexBase + (i*4));
478                     if(0 == pu32Data)
479                     {
480                         printf("%s :pu32Data_4 = 0!,error!!!\n", __FUNCTION__);
481                         assert(pu32Data != 0);
482                     }
483                     *pu32Data = 0xFFFF0000;
484                 }
485             }
486         }
487     }
488 #endif
489 }
490 
Hal_SC_Add_NullCommand(void * pInstance,SCALER_WIN eWindow,ds_reg_ip_op_sel IPOP_Sel,XC_DS_CMDCNT * pstXC_DS_CmdCnt)491 void Hal_SC_Add_NullCommand(void *pInstance,SCALER_WIN eWindow,ds_reg_ip_op_sel IPOP_Sel,XC_DS_CMDCNT *pstXC_DS_CmdCnt)
492 {
493     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
494     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
495     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
496     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
497 
498     MS_U16 u16MaxCmdCnt = pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth * (Hal_XC_MLoad_Get_64Bits_MIU_Bus_Sel(pInstance) + 1); // It has four 64bit commands per MIU bus width
499     MS_U16 i = 0;
500 
501     if(eWindow == MAIN_WINDOW)
502     {
503         i = (IPOP_Sel == DS_IP) ? pstXC_DS_CmdCnt->u16CMDCNT_IPM : pstXC_DS_CmdCnt->u16CMDCNT_OPM;
504     }
505     else
506     {
507         i = (IPOP_Sel == DS_IP) ? pstXC_DS_CmdCnt->u16CMDCNT_IPS : pstXC_DS_CmdCnt->u16CMDCNT_OPS;
508     }
509 
510     while(i < u16MaxCmdCnt)
511     {
512         i++;
513         //Dummy cmd BKFF_7F=0x0000
514         Hal_SC_WriteSWDSCommand(pInstance, eWindow, REG_SC_BKFF_7F_L, 0x0000, IPOP_Sel, DS_XC, pstXC_DS_CmdCnt);
515     }
516 }
517 
518 
Hal_SC_WriteSWDSCommand(void * pInstance,SCALER_WIN eWindow,MS_U32 u32CmdRegAddr,MS_U16 u16CmdRegValue,ds_reg_ip_op_sel IPOP_Sel,ds_reg_source_sel Source_Select,XC_DS_CMDCNT * pstXC_DS_CmdCnt)519 void Hal_SC_WriteSWDSCommand(void *pInstance,SCALER_WIN eWindow, MS_U32 u32CmdRegAddr, MS_U16 u16CmdRegValue,ds_reg_ip_op_sel IPOP_Sel,ds_reg_source_sel Source_Select,XC_DS_CMDCNT *pstXC_DS_CmdCnt)
520 {
521     //XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
522     //UtopiaResourceGetPrivate(g_pXCResource[E_XC_POOL_ID_INTERNAL_VARIABLE],(void**)(&pXCResourcePrivate));
523 
524     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
525     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
526     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
527     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
528 
529 #if ENABLE_DS_4_BASEADDR_MODE
530     MS_PHY u32Addr = pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr + pXCResourcePrivate->sthal_SC.u8DynamicScalingCurrentIndex_Ring[eWindow] * pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth * MS_MLOAD_MEM_BASE_UNIT;
531     MS_PHY u32Addr_OPM = pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_OPM + pXCResourcePrivate->sthal_SC.u8DynamicScalingCurrentIndex_Ring[eWindow] * pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth * MS_MLOAD_MEM_BASE_UNIT;
532     MS_PHY u32Addr_IPS = pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_IPS + pXCResourcePrivate->sthal_SC.u8DynamicScalingCurrentIndex_Ring[eWindow] * pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth * MS_MLOAD_MEM_BASE_UNIT;
533     MS_PHY u32Addr_OPS = pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_OPS + pXCResourcePrivate->sthal_SC.u8DynamicScalingCurrentIndex_Ring[eWindow] * pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth * MS_MLOAD_MEM_BASE_UNIT;
534 #else
535     MS_PHY u32Addr = pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr + pXCResourcePrivate->sthal_SC.u8DynamicScalingCurrentIndex_Ring[eWindow] * pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth * MS_MLOAD_MEM_BASE_UNIT;
536 #endif
537 
538 
539 #if ENABLE_DS_4_BASEADDR_MODE
540 
541     MS_U64 *pu64Data = NULL;
542     MS_U64 u64CmdTemp = 0;
543     MS_U8  u8AddrTemp = 0;
544     MS_U16 u16BankTemp = 0;
545     MS_U16 u16DataTemp = 0;
546     MS_U16 u16MaskTemp = 0;
547     MS_U8 u8MaxCmdCnt = pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth * (Hal_XC_MLoad_Get_64Bits_MIU_Bus_Sel(pInstance) + 1);
548 
549 //===========================================================//
550 //  64bit command format (spread mode)
551 //  |-------------|-------------|----------------------------|-------------|
552 //  |    Bit-En   |    Unused   |    Addr(FULL RIU ADDR)     |     Data    |
553 //  |-------------|-------------|----------------------------|-------------|
554 //  |   [63:48]   |   [47:40]   |           [39:16]          |   [15:0]    |
555 //  |-------------|-------------|----------------------------|-------------|
556 
557 //Addr: FULL RIU ADDRESS !!!
558 
559 //For example:  Subbank:0x01            addr:0x40 Data:0x0001
560 //              Spread mode :  0x1301   addr:0x40 Data:0x0001
561 
562 //|----------------------------------------------------|
563 //|                      Bank             |    addr    |
564 //|----------------------------------------------------|
565 //|                     0x1301            |    0x40    |
566 //|----------------------------------------------------|
567 // FULL RIU ADDRESS: |0001 0011 0000 0001 |  100 0000  |
568 // FULL RIU ADDRESS:              0x0980C1
569 //===========================================================//
570 
571     if(Source_Select == DS_XC)
572     {
573         u16MaskTemp = 0xFFFF;
574         u16DataTemp = (SC_R2BYTE(psXCInstPri->u32DeviceID,u32CmdRegAddr) & ~0xFFFF) | (u16CmdRegValue & 0xFFFF);
575 
576         u8AddrTemp= (u32CmdRegAddr & 0x000000FF) >> 1;
577         u16BankTemp= 0x1300 | ((u32CmdRegAddr >> 8) & 0x000000FF); // 0x13XX xc sread mode address
578 
579         u64CmdTemp|= (MS_U64)u16DataTemp;
580         u64CmdTemp|= ((MS_U64)u8AddrTemp<<16);
581         u64CmdTemp|= ((MS_U64)u16BankTemp<<23);
582         u64CmdTemp|= ((MS_U64)u16MaskTemp<<48);
583 
584         if(IPOP_Sel == DS_IP)
585         {
586             if(eWindow == MAIN_WINDOW)
587             {
588                 MS_U32 u32MemShift_IPM;
589 
590                 if((MS_MLOAD_BUS_WIDTH == 16) && (BYTE_PER_WORD == 32))
591                 {
592                     //CMD in DRAM: with dummy command
593 
594                     // |------ 128 bit ------|
595                     // |  CMD0   |   CMD1    |
596                     // |  dummy  |   dummy   |
597                     // |  CMD2   |   CMD3    |
598                     // |  dummy  |   dummy   |
599                     if((pstXC_DS_CmdCnt->u16CMDCNT_IPM % 2) == 0)
600                     {
601                         u32MemShift_IPM = (pstXC_DS_CmdCnt->u16CMDCNT_IPM / 2) * MS_MLOAD_MEM_BASE_UNIT;
602                     }
603                     else
604                     {
605                         u32MemShift_IPM = (pstXC_DS_CmdCnt->u16CMDCNT_IPM / 2) * MS_MLOAD_MEM_BASE_UNIT  + DS_CMD_LEN_64BITS;
606                     }
607                 }
608                 else // ((MS_MLOAD_BUS_WIDTH == 16) && (BYTE_PER_WORD == 16))  or ((MS_MLOAD_BUS_WIDTH == 32) && (BYTE_PER_WORD == 32))
609                 {
610                     //CMD in DRAM:   no dummy command
611 
612                     // |------ 128 bit ------|
613                     // |  CMD0   |   CMD1    |
614                     // |  CMD2   |   CMD3    |
615                     // |  CMD4   |   CMD5    |
616                     // |  CMD6   |   CMD7    |
617 
618                     u32MemShift_IPM = pstXC_DS_CmdCnt->u16CMDCNT_IPM * DS_CMD_LEN_64BITS;
619                 }
620 
621                 //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);
622                 //u32Addr = u32Addr + DS_CMD_LEN_64BITS * pstXC_DS_CmdCnt->u16CMDCNT_IPM;
623                 u32Addr = u32Addr + u32MemShift_IPM;
624                 pu64Data = (MS_U64*)MsOS_PA2KSEG1(u32Addr);//IPM
625 
626                 if(pstXC_DS_CmdCnt->u16CMDCNT_IPM < u8MaxCmdCnt)
627                 {
628                     *pu64Data = u64CmdTemp;
629                     pstXC_DS_CmdCnt->u16CMDCNT_IPM++;
630                 }
631                 else
632                 {
633                     XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] IPM Command count overflow !!  u16CMDCNT_IPM:%d  Max command count: %d\n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_IPM,pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth);
634                 }
635             }
636             else//subwindow
637             {
638                 MS_U32 u32MemShift_IPS;
639 
640                 if((MS_MLOAD_BUS_WIDTH == 16) && (BYTE_PER_WORD == 32))
641                 {
642                     //CMD in DRAM: with dummy command
643 
644                     // |------ 128 bit ------|
645                     // |  CMD0   |   CMD1    |
646                     // |  dummy  |   dummy   |
647                     // |  CMD2   |   CMD3    |
648                     // |  dummy  |   dummy   |
649 
650                     if((pstXC_DS_CmdCnt->u16CMDCNT_IPS % 2) == 0)
651                     {
652                         u32MemShift_IPS = (pstXC_DS_CmdCnt->u16CMDCNT_IPS / 2) * MS_MLOAD_MEM_BASE_UNIT;
653                     }
654                     else
655                     {
656                         u32MemShift_IPS = (pstXC_DS_CmdCnt->u16CMDCNT_IPS / 2) * MS_MLOAD_MEM_BASE_UNIT  + DS_CMD_LEN_64BITS;
657                     }
658                 }
659                 else // ((MS_MLOAD_BUS_WIDTH == 16) && (BYTE_PER_WORD == 16))  or ((MS_MLOAD_BUS_WIDTH == 32) && (BYTE_PER_WORD == 32))
660                 {
661                     //CMD in DRAM:   no dummy command
662 
663                     // |------ 128 bit ------|
664                     // |  CMD0   |   CMD1    |
665                     // |  CMD2   |   CMD3    |
666                     // |  CMD4   |   CMD5    |
667                     // |  CMD6   |   CMD7    |
668 
669                     u32MemShift_IPS = pstXC_DS_CmdCnt->u16CMDCNT_IPS * DS_CMD_LEN_64BITS;
670                 }
671 
672                 //XC_PRINTF("[%s,%5d] [DS_IP(MVOP)]pstXC_DS_CmdCnt->u16CMDCNT_IPS:%d u32MemShift_IPS:%lx \n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_IPS,(MS_U32)u32MemShift_IPS);
673 
674                 u32Addr_IPS = u32Addr_IPS + u32MemShift_IPS;
675                 pu64Data = (MS_U64*)MsOS_PA2KSEG1(u32Addr_IPS); // IPS
676 
677                 if(pstXC_DS_CmdCnt->u16CMDCNT_IPS < u8MaxCmdCnt)
678                 {
679                     *pu64Data = u64CmdTemp;
680                     pstXC_DS_CmdCnt->u16CMDCNT_IPS++;
681                 }
682                 else
683                 {
684                     XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] IPS Command count overflow !!  u16CMDCNT_IPS:%d  Max command count: %d\n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_IPS,pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth);
685                 }
686             }
687         }
688         else//DS_OP
689         {
690             if(eWindow == MAIN_WINDOW)
691             {
692                 MS_U32 u32MemShift_OPM;
693 
694                 if((MS_MLOAD_BUS_WIDTH == 16) && (BYTE_PER_WORD == 32))
695                 {
696                     //CMD in DRAM: with dummy command
697 
698                     // |------ 128 bit ------|
699                     // |  CMD0   |   CMD1    |
700                     // |  dummy  |   dummy   |
701                     // |  CMD2   |   CMD3    |
702                     // |  dummy  |   dummy   |
703                     if((pstXC_DS_CmdCnt->u16CMDCNT_OPM % 2) == 0)
704                     {
705                         u32MemShift_OPM = (pstXC_DS_CmdCnt->u16CMDCNT_OPM / 2) * MS_MLOAD_MEM_BASE_UNIT;
706                     }
707                     else
708                     {
709                         u32MemShift_OPM = (pstXC_DS_CmdCnt->u16CMDCNT_OPM / 2) * MS_MLOAD_MEM_BASE_UNIT  + DS_CMD_LEN_64BITS;
710                     }
711                 }
712                 else // ((MS_MLOAD_BUS_WIDTH == 16) && (BYTE_PER_WORD == 16))  or ((MS_MLOAD_BUS_WIDTH == 32) && (BYTE_PER_WORD == 32))
713                 {
714                     //CMD in DRAM:   no dummy command
715 
716                     // |------ 128 bit ------|
717                     // |  CMD0   |   CMD1    |
718                     // |  CMD2   |   CMD3    |
719                     // |  CMD4   |   CMD5    |
720                     // |  CMD6   |   CMD7    |
721 
722                     u32MemShift_OPM = pstXC_DS_CmdCnt->u16CMDCNT_OPM * DS_CMD_LEN_64BITS;
723                 }
724                 //XC_PRINTF("[%s,%5d] [DS_OP]pstXC_DS_CmdCnt->u16CMDCNT_OPM:%d u32MemShift_OPM:%lx \n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_OPM,(MS_U32)u32MemShift_OPM);
725                 //u32Addr_OPM = u32Addr_OPM + DS_CMD_LEN_64BITS * pstXC_DS_CmdCnt->u16CMDCNT_OPM;
726                 u32Addr_OPM = u32Addr_OPM + u32MemShift_OPM;
727                 pu64Data = (MS_U64*)MsOS_PA2KSEG1(u32Addr_OPM);//OPM
728 
729                 //XC_PRINTF("[%s,%5d] u64CmdTemp:%llx  \n",__func__,__LINE__,u64CmdTemp);
730 
731                 if(pstXC_DS_CmdCnt->u16CMDCNT_OPM < u8MaxCmdCnt)
732                 {
733                     *pu64Data = u64CmdTemp;
734                     pstXC_DS_CmdCnt->u16CMDCNT_OPM++;
735                 }
736                 else
737                 {
738                     XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] OPM Command count overflow !!  u16CMDCNT_OPM:%d  Max command count: %d\n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_OPM,pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth);
739                 }
740             }
741             else
742             {
743                 MS_U32 u32MemShift_OPS;
744 
745                 if((MS_MLOAD_BUS_WIDTH == 16) && (BYTE_PER_WORD == 32))
746                 {
747                     //CMD in DRAM: with dummy command
748 
749                     // |------ 128 bit ------|
750                     // |  CMD0   |   CMD1    |
751                     // |  dummy  |   dummy   |
752                     // |  CMD2   |   CMD3    |
753                     // |  dummy  |   dummy   |
754 
755                     if((pstXC_DS_CmdCnt->u16CMDCNT_OPS % 2) == 0)
756                     {
757                         u32MemShift_OPS = (pstXC_DS_CmdCnt->u16CMDCNT_OPS / 2) * MS_MLOAD_MEM_BASE_UNIT;
758                     }
759                     else
760                     {
761                         u32MemShift_OPS = (pstXC_DS_CmdCnt->u16CMDCNT_OPS / 2) * MS_MLOAD_MEM_BASE_UNIT  + DS_CMD_LEN_64BITS;
762                     }
763                 }
764                 else // ((MS_MLOAD_BUS_WIDTH == 16) && (BYTE_PER_WORD == 16))  or ((MS_MLOAD_BUS_WIDTH == 32) && (BYTE_PER_WORD == 32))
765                 {
766                     //CMD in DRAM:   no dummy command
767 
768                     // |------ 128 bit ------|
769                     // |  CMD0   |   CMD1    |
770                     // |  CMD2   |   CMD3    |
771                     // |  CMD4   |   CMD5    |
772                     // |  CMD6   |   CMD7    |
773 
774                     u32MemShift_OPS = pstXC_DS_CmdCnt->u16CMDCNT_OPS * DS_CMD_LEN_64BITS;
775                 }
776 
777                 //XC_PRINTF("[%s,%5d] [DS_IP(MVOP)]pstXC_DS_CmdCnt->u16CMDCNT_IPS:%d u32MemShift_IPS:%lx \n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_OPS,(MS_U32)u32MemShift_OPS);
778 
779                 u32Addr_OPS = u32Addr_OPS + u32MemShift_OPS;
780                 pu64Data = (MS_U64*)MsOS_PA2KSEG1(u32Addr_OPS); // IPS
781 
782                 if(pstXC_DS_CmdCnt->u16CMDCNT_OPS < u8MaxCmdCnt)
783                 {
784                     *pu64Data = u64CmdTemp;
785                     pstXC_DS_CmdCnt->u16CMDCNT_OPS++;
786                 }
787                 else
788                 {
789                     XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] IPS Command count overflow !!  u16CMDCNT_IPS:%d  Max command count: %d\n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_OPS,pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth);
790                 }
791             }
792         }
793     }
794     else if(Source_Select == DS_MVOP)// only in IP cmd
795     {
796         if(IPOP_Sel == DS_IP)
797         {
798             u16DataTemp = u16CmdRegValue;
799             u8AddrTemp = (u32CmdRegAddr&0x000000FF);
800             u16BankTemp = (u32CmdRegAddr&0x00FFFF00) >> 8; //EX: mvop mainwinodw: 0x1014 mvop bank
801             u16MaskTemp = 0xFFFF;
802 
803             u64CmdTemp|= (MS_U64)u16DataTemp;
804             u64CmdTemp|= ((MS_U64)u8AddrTemp<<16) >> 1;
805             u64CmdTemp|= ((MS_U64)u16BankTemp<<23);
806             u64CmdTemp|= ((MS_U64)u16MaskTemp<<48);
807 
808             if(eWindow == MAIN_WINDOW)
809             {
810                 MS_U32 u32MemShift_IPM;
811 
812                 if((MS_MLOAD_BUS_WIDTH == 16) && (BYTE_PER_WORD == 32))
813                 {
814                     //CMD in DRAM: with dummy command
815 
816                     // |------ 128 bit ------|
817                     // |  CMD0   |   CMD1    |
818                     // |  dummy  |   dummy   |
819                     // |  CMD2   |   CMD3    |
820                     // |  dummy  |   dummy   |
821 
822                     if((pstXC_DS_CmdCnt->u16CMDCNT_IPM % 2) == 0)
823                     {
824                         u32MemShift_IPM = (pstXC_DS_CmdCnt->u16CMDCNT_IPM / 2) * MS_MLOAD_MEM_BASE_UNIT;
825                     }
826                     else
827                     {
828                         u32MemShift_IPM = (pstXC_DS_CmdCnt->u16CMDCNT_IPM / 2) * MS_MLOAD_MEM_BASE_UNIT  + DS_CMD_LEN_64BITS;
829                     }
830                 }
831                 else // ((MS_MLOAD_BUS_WIDTH == 16) && (BYTE_PER_WORD == 16))  or ((MS_MLOAD_BUS_WIDTH == 32) && (BYTE_PER_WORD == 32))
832                 {
833                     //CMD in DRAM:   no dummy command
834 
835                     // |------ 128 bit ------|
836                     // |  CMD0   |   CMD1    |
837                     // |  CMD2   |   CMD3    |
838                     // |  CMD4   |   CMD5    |
839                     // |  CMD6   |   CMD7    |
840 
841                     u32MemShift_IPM = pstXC_DS_CmdCnt->u16CMDCNT_IPM * DS_CMD_LEN_64BITS;
842                 }
843 
844                 //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);
845                 //u32Addr = u32Addr + DS_CMD_LEN_64BITS * pstXC_DS_CmdCnt->u16CMDCNT_IPM;
846                 u32Addr = u32Addr + u32MemShift_IPM;
847                 pu64Data = (MS_U64*)MsOS_PA2KSEG1(u32Addr);//IPM
848 
849                 if(pstXC_DS_CmdCnt->u16CMDCNT_IPM < u8MaxCmdCnt)
850                 {
851                     *pu64Data = u64CmdTemp;
852                     pstXC_DS_CmdCnt->u16CMDCNT_IPM++;
853                 }
854                 else
855                 {
856                     XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] Command count overflow !!  u16CMDCNT_IPM:%d  Max command count: %d\n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_IPM,pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth);
857                 }
858             }
859             else
860             {
861                 MS_U32 u32MemShift_IPS;
862 
863                 if((MS_MLOAD_BUS_WIDTH == 16) && (BYTE_PER_WORD == 32))
864                 {
865                     //CMD in DRAM: with dummy command
866 
867                     // |------ 128 bit ------|
868                     // |  CMD0   |   CMD1    |
869                     // |  dummy  |   dummy   |
870                     // |  CMD2   |   CMD3    |
871                     // |  dummy  |   dummy   |
872 
873                     if((pstXC_DS_CmdCnt->u16CMDCNT_IPS % 2) == 0)
874                     {
875                         u32MemShift_IPS = (pstXC_DS_CmdCnt->u16CMDCNT_IPS / 2) * MS_MLOAD_MEM_BASE_UNIT;
876                     }
877                     else
878                     {
879                         u32MemShift_IPS = (pstXC_DS_CmdCnt->u16CMDCNT_IPS / 2) * MS_MLOAD_MEM_BASE_UNIT  + DS_CMD_LEN_64BITS;
880                     }
881                 }
882                 else // ((MS_MLOAD_BUS_WIDTH == 16) && (BYTE_PER_WORD == 16))  or ((MS_MLOAD_BUS_WIDTH == 32) && (BYTE_PER_WORD == 32))
883                 {
884                     //CMD in DRAM:   no dummy command
885 
886                     // |------ 128 bit ------|
887                     // |  CMD0   |   CMD1    |
888                     // |  CMD2   |   CMD3    |
889                     // |  CMD4   |   CMD5    |
890                     // |  CMD6   |   CMD7    |
891 
892                     u32MemShift_IPS = pstXC_DS_CmdCnt->u16CMDCNT_IPS * DS_CMD_LEN_64BITS;
893                 }
894 
895                 //XC_PRINTF("[%s,%5d] [DS_IP(MVOP)]pstXC_DS_CmdCnt->u16CMDCNT_IPS:%d u32MemShift_IPS:%lx \n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_IPS,(MS_U32)u32MemShift_IPS);
896 
897                 u32Addr_IPS = u32Addr_IPS + u32MemShift_IPS;
898                 pu64Data = (MS_U64*)MsOS_PA2KSEG1(u32Addr_IPS); // IPS
899 
900                 if(pstXC_DS_CmdCnt->u16CMDCNT_IPS < u8MaxCmdCnt)
901                 {
902                     *pu64Data = u64CmdTemp;
903                     pstXC_DS_CmdCnt->u16CMDCNT_IPS++;
904                 }
905                 else
906                 {
907                     XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] IPS Command count overflow !!  u16CMDCNT_IPS:%d  Max command count: %d\n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_IPS,pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth);
908                 }
909             }
910         }
911         else
912         {
913             XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] MVOP is IP cmd not OP cmd !! \n",__func__,__LINE__);
914         }
915 
916     }
917     else if(Source_Select == DS_GOP)
918     {
919 
920     }
921     else
922     {
923         XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] Only can support XC/MVOP/GOP NOW !! \n",__func__,__LINE__);
924     }
925 
926 
927 #else
928     //=============================================//
929     //  32bit command format
930     //  |-------------|-------------|-------------|
931     //  |     Bank    |     Addr    |     Data    |
932     //  |-------------|-------------|-------------|
933     //  |   [31:24]   |   [23:16]   |    [15:0]   |
934     //  |-------------|-------------|-------------|
935 
936     //Bank: Subbank
937     //=============================================//
938     MS_U8 u8MaxCmdCnt = pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth;
939 
940     if (eWindow == SUB_WINDOW)
941     {
942         // (OP : IP : Unused : Unused) (4 byte : 4 byte : 4 byte : 4 byte) if MIU 128bit
943         // (OPmain : IPmain : OPsub : IPsub) (4 byte : 4 byte : 4 byte : 4 byte) if MIU 128bit
944         u32Addr += DS_OP_CMD_LEN+DS_IP_CMD_LEN;
945     }
946     //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);
947     //XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] u32Addr:%x  \n",__func__,__LINE__,(int)u32Addr);
948 
949     if(IPOP_Sel == DS_OP)
950     {
951         MS_U32 u32OPAddr = u32Addr;
952         MS_U32 *pu32Data = NULL;
953         //MS_U8 u8OPCount = pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth;
954         MS_U32 u32Command = 0;
955         MS_U32 u32MemShift_OPM = 0;
956         MS_U32 u32MemShift_OPS = 0;
957 
958         u32Command = u16CmdRegValue + ((u32CmdRegAddr & 0x00FF) << 15) + ((u32CmdRegAddr & 0xFF00) << 16);
959 
960         if (eWindow == MAIN_WINDOW)
961         {
962             u32MemShift_OPM = pstXC_DS_CmdCnt->u16CMDCNT_OPM * MS_MLOAD_MEM_BASE_UNIT;
963             u32OPAddr += u32MemShift_OPM;
964             pu32Data = (MS_U32*)MsOS_PA2KSEG1(u32OPAddr);
965             if(0 == pu32Data)
966             {
967                 printf("%s :pu32Data = 0!,error!!!\n", __FUNCTION__);
968 
969                 assert(pu32Data != 0);
970             }
971 
972             if(pstXC_DS_CmdCnt->u16CMDCNT_OPM < u8MaxCmdCnt)
973             {
974                 *pu32Data = u32Command;
975                 pstXC_DS_CmdCnt->u16CMDCNT_OPM++;
976             }
977             else
978             {
979                 XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] OPM Command count overflow !!  u16CMDCNT_OPM:%d  Max command count: %d\n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_OPM,pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth);
980             }
981         }
982         else
983         {
984             u32MemShift_OPS = pstXC_DS_CmdCnt->u16CMDCNT_OPS * MS_MLOAD_MEM_BASE_UNIT;
985             u32OPAddr += u32MemShift_OPS;
986             pu32Data = (MS_U32*)MsOS_PA2KSEG1(u32OPAddr);
987             if(0 == pu32Data)
988             {
989                 printf("%s :pu32Data = 0!,error!!!\n", __FUNCTION__);
990 
991                 assert(pu32Data != 0);
992             }
993 
994             if(pstXC_DS_CmdCnt->u16CMDCNT_OPS < u8MaxCmdCnt)
995             {
996                 *pu32Data = u32Command;
997                 pstXC_DS_CmdCnt->u16CMDCNT_OPS++;
998             }
999             else
1000             {
1001                 XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] OPS Command count overflow !!  u16CMDCNT_OPS:%d  Max command count: %d\n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_OPS,pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth);
1002             }
1003         }
1004     }
1005 
1006     else
1007     {
1008         // (OP : IP : Unused : Unused) (4 byte : 4 byte : 4 byte : 4 byte) if MIU 128bit
1009         // (OPmain : IPmain : OPsub : IPsub) (4 byte : 4 byte : 4 byte : 4 byte) if MIU 128bit
1010 
1011         MS_U32 u32IPAddr = u32Addr + DS_OP_CMD_LEN;
1012         MS_U32 *pu32Data = NULL;
1013         //MS_U8 u8IPCount = pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth;
1014         MS_U32 u32Command = 0;
1015         MS_U32 u32MemShift_IPM = 0;
1016         MS_U32 u32MemShift_IPS = 0;
1017 
1018         u32Command = u16CmdRegValue + ((u32CmdRegAddr & 0x00FF) << 15) + ((u32CmdRegAddr & 0xFF00) << 16);
1019 
1020         if(eWindow == MAIN_WINDOW)
1021         {
1022             u32MemShift_IPM = pstXC_DS_CmdCnt->u16CMDCNT_IPM * MS_MLOAD_MEM_BASE_UNIT;
1023             u32IPAddr += u32MemShift_IPM;
1024 
1025             pu32Data = (MS_U32*)MsOS_PA2KSEG1(u32IPAddr);
1026             if(0 == pu32Data)
1027             {
1028                 printf("%s :pu32Data = 0!,error!!!\n", __FUNCTION__);
1029 
1030                 assert(pu32Data != 0);
1031             }
1032 
1033             if(pstXC_DS_CmdCnt->u16CMDCNT_IPM < u8MaxCmdCnt)
1034             {
1035                 *pu32Data = u32Command;
1036                 pstXC_DS_CmdCnt->u16CMDCNT_IPM++;
1037             }
1038             else
1039             {
1040                 XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] IPM Command count overflow !!  u16CMDCNT_IPM:%d  Max command count: %d\n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_IPM,pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth);
1041             }
1042         }
1043         else
1044         {
1045             u32MemShift_IPS = pstXC_DS_CmdCnt->u16CMDCNT_IPS * MS_MLOAD_MEM_BASE_UNIT;
1046             u32IPAddr += u32MemShift_IPS;
1047 
1048             pu32Data = (MS_U32*)MsOS_PA2KSEG1(u32IPAddr);
1049             if(0 == pu32Data)
1050             {
1051                 printf("%s :pu32Data = 0!,error!!!\n", __FUNCTION__);
1052 
1053                 assert(pu32Data != 0);
1054             }
1055 
1056             if(pstXC_DS_CmdCnt->u16CMDCNT_IPS < u8MaxCmdCnt)
1057             {
1058                 *pu32Data = u32Command;
1059                 pstXC_DS_CmdCnt->u16CMDCNT_IPS++;
1060             }
1061             else
1062             {
1063                 XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] IPS Command count overflow !!  u16CMDCNT_IPS:%d  Max command count: %d\n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_IPS,pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth);
1064             }
1065         }
1066     }
1067 #endif
1068 }
1069 
Hal_SC_SetSeamlessZapping(void * pInstance,SCALER_WIN eWindow,MS_BOOL bEnable)1070 MS_BOOL Hal_SC_SetSeamlessZapping(void *pInstance, SCALER_WIN eWindow, MS_BOOL bEnable)
1071 {
1072 #if SUPPORT_SEAMLESS_ZAPPING
1073     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1074     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1075     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
1076     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
1077 #if 1 //the current Spec the Seamless Zapping is not supported to Sub win
1078     if(eWindow != MAIN_WINDOW)
1079     {
1080         pXCResourcePrivate->sthal_SC.bSeamlessZappingEnable[eWindow] = DISABLE;
1081         return FALSE;
1082     }
1083 #endif
1084     if(bEnable)
1085     {
1086         pXCResourcePrivate->sthal_SC.u8SeamlessZappingCurIndex[eWindow] = 0;
1087         pXCResourcePrivate->sthal_SC.u8SeamlessZappingNextIndex[eWindow] = 0;
1088         _Hal_SC_ResetDSCommand(eWindow, pXCResourcePrivate->sthal_SC.u8SeamlessZappingCurIndex[eWindow]);
1089     }
1090     else
1091     {
1092         MS_U8 u8index = 0;
1093         SLZ_DBG(printf("@@#@@DS for Seamless Zapping is OFF\n"));
1094         pXCResourcePrivate->sthal_SC.u8SeamlessZappingCurIndex[eWindow] = 0;
1095         pXCResourcePrivate->sthal_SC.u8SeamlessZappingNextIndex[eWindow] = 0;
1096 
1097         for(u8index=0; u8index<(sizeof(pXCResourcePrivate->sthal_SC.u8SeamlessZappingNextIndex)/sizeof(pXCResourcePrivate->sthal_SC.u8SeamlessZappingNextIndex[0])); u8index++)
1098         {
1099             _Hal_SC_ResetDSCommand(eWindow, u8index);
1100         }
1101     }
1102         SLZ_DBG(printf("@@#@@[%s]@@FRZ=%x, SZ =%x, pXCResourcePrivate->sthal_SC.u8SeamlessZappingCurIndex[MAIN_WINDOW]=%x, pXCResourcePrivate->sthal_SC.u8SeamlessZappingNextIndex[MAIN_WINDOW]=%x\n",
1103             __FUNCTION__, Hal_SC_get_freezeimg(MAIN_WINDOW), bEnable,
1104             pXCResourcePrivate->sthal_SC.u8SeamlessZappingCurIndex[MAIN_WINDOW],
1105             pXCResourcePrivate->sthal_SC.u8SeamlessZappingNextIndex[MAIN_WINDOW]));
1106 
1107     Hal_XC_MLoad_set_opm_lock(OPM_LOCK_INIT_STATE);
1108     MHal_XC_Set_DSForceIndex(pInstance, bEnable, pXCResourcePrivate->sthal_SC.u8SeamlessZappingCurIndex[eWindow], eWindow);
1109     pXCResourcePrivate->sthal_SC.bSeamlessZappingEnable[eWindow] = bEnable;
1110     return TRUE;
1111 #else
1112     return FALSE;
1113 #endif
1114 }
1115 
Hal_SC_GetSeamlessZappingStatus(void * pInstance,SCALER_WIN eWindow)1116 MS_BOOL Hal_SC_GetSeamlessZappingStatus(void *pInstance, SCALER_WIN eWindow)
1117 {
1118 #if SUPPORT_SEAMLESS_ZAPPING
1119     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1120     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1121     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
1122     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
1123     return pXCResourcePrivate->sthal_SC.bSeamlessZappingEnable[eWindow];
1124 #else
1125     return FALSE;
1126 #endif
1127 }
1128 
MHAL_SC_Set_DynamicScaling(void * pInstance,MS_U32 u32MemBaseAddr,MS_U8 u8MIU_Select,MS_U8 u8IdxDepth,MS_BOOL bOP_On,MS_BOOL bIPS_On,MS_BOOL bIPM_On,SCALER_WIN eWindow)1129 MS_BOOL MHAL_SC_Set_DynamicScaling(void *pInstance, MS_U32 u32MemBaseAddr, MS_U8 u8MIU_Select, MS_U8 u8IdxDepth, MS_BOOL bOP_On, MS_BOOL bIPS_On, MS_BOOL bIPM_On, SCALER_WIN eWindow)
1130 {
1131     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1132     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1133     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
1134     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
1135     MS_U32 u32Base = u32MemBaseAddr;// / BYTE_PER_WORD;
1136     MS_U16 u16OnOff = 0;
1137 
1138 #if SUPPORT_SEAMLESS_ZAPPING
1139     pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr = u32Base;
1140     if(bOP_On&&(!bIPS_On)&&(!bIPM_On))
1141     {
1142         u8IdxDepth*=2;
1143     }
1144     pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth = u8IdxDepth;
1145 #endif
1146     if( u32Base > HAL_MIU1_BASE)
1147     {
1148         u32Base = u32Base - HAL_MIU1_BASE;
1149     }
1150     u32Base = u32Base/BYTE_PER_WORD;
1151 
1152     // Restore current DNR setting
1153     MS_U16 bDNREnable = FALSE;
1154     if( SC_R2BYTEMSK(0, REG_SC_BK12_02_L, BIT(14)))
1155         bDNREnable = FALSE;
1156     else
1157         bDNREnable = TRUE;
1158 
1159     // RD's suggestion for DS hang issue , turn off DNR and WD before setting DS on.
1160     if(bOP_On || bIPM_On)
1161     {
1162         if(bDNREnable)
1163         {
1164             SC_W2BYTEMSK(0, REG_SC_BK12_02_L, BIT(14), BIT(14));
1165             SC_W2BYTEMSK(0, REG_SC_BK1F_05_L, 0, BIT(15)|BIT(14));
1166         }
1167         else
1168         {
1169             SC_W2BYTEMSK(0, REG_SC_BK1F_05_L ,0, BIT(15)| BIT(14));
1170         }
1171     }
1172 
1173 
1174     // disable DS before modifying DS configuration
1175     if (MDrv_XC_MLoad_GetStatus(pInstance) == E_MLOAD_ENABLED)
1176     {
1177         _MLOAD_ENTRY(pInstance);
1178         MDrv_XC_MLoad_WriteCmd(pInstance, REG_SC_BK1F_10_L, 0, 0x0E00);
1179         MDrv_XC_MLoad_Fire(pInstance, TRUE);
1180         _MLOAD_RETURN(pInstance);
1181     }
1182     else
1183     {
1184         SC_W2BYTEMSK(0, REG_SC_BK1F_10_L, 0, 0x0E00);
1185     }
1186 
1187     // enable/disable
1188     u16OnOff = SC_R2BYTE(0, REG_SC_BK1F_10_L) & 0x3000;
1189     u16OnOff |= ((bOP_On << 9) | (bIPS_On << 10) | (bIPM_On << 11));
1190 
1191     pXCResourcePrivate->sthal_SC.bDynamicScalingForceI[MAIN_WINDOW] = FALSE;
1192     pXCResourcePrivate->sthal_SC.bDynamicScalingForceI[SUB_WINDOW] = FALSE;
1193 
1194 #if ENABLE_DS_4_BASEADDR_MODE
1195 
1196 //===============================================================//
1197 //  old 32bit command in DRAM  (per 16 Byte)
1198 //  |-------------|-------------|-------------|-------------|
1199 //  | DS_OP(main) | DS_IP(main) |  DS_OP(sub) |  DS_IP(sub) |
1200 //  |-------------|-------------|-------------|-------------|
1201 //  |   4 byte    |   4 byte    |   4 byte    |   4 byte    |
1202 //  |-------------|-------------|-------------|-------------|
1203 
1204 //  new 64bit command in DRAM (per 16 Byte)
1205 //  |---------------------------|---------------------------|
1206 //  |        DS_IP(main)        |        DS_IP(main)        |
1207 //  |---------------------------|---------------------------|
1208 //  |          8 byte           |          8 byte           |
1209 //  |---------------------------|---------------------------|
1210 
1211 // For example: IPM command
1212 // For new 64bit command, it has two DS command per 16 byte.
1213 // Therefore,u8DynamicScalingIndexDepth is divided 2 in this case.
1214 //===============================================================//
1215     XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] bR_FBL:%d bFBL:%d  \n",__func__,__LINE__,gSrcInfo[MAIN_WINDOW].bR_FBL,gSrcInfo[MAIN_WINDOW].bFBL);
1216 
1217     pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth = u8IdxDepth;
1218 
1219     //pXCResourcePrivate->sthal_SC.u32DynamicScalingBufSize = BYTE_PER_WORD * u8IdxDepth * DS_MAX_INDEX;
1220     pXCResourcePrivate->sthal_SC.u32DynamicScalingBufSize = 0x4000;
1221 
1222     MS_U32 u32DSBufLen = pXCResourcePrivate->sthal_SC.u32DynamicScalingBufSize / 4;
1223 
1224     XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] u32DynamicScalingBufSize:%d u32DSBufLen:%d  \n",__func__,__LINE__,pXCResourcePrivate->sthal_SC.u32DynamicScalingBufSize,u32DSBufLen);
1225 
1226     if(eWindow == MAIN_WINDOW)
1227     {
1228         pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr = u32MemBaseAddr; //IPM
1229         pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_OPM = u32MemBaseAddr + u32DSBufLen*2;
1230         XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] u32DynamicScalingBaseAddr_IPM:%x  u32DynamicScalingBaseAddr_OPM:%x  \n",__func__,__LINE__,(int)pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr,(int)pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_OPM);
1231     }
1232 
1233     if(eWindow == SUB_WINDOW)
1234     {
1235         pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_IPS = u32MemBaseAddr + u32DSBufLen;
1236         pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_OPS = u32MemBaseAddr + u32DSBufLen*3;
1237         XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] u32DynamicScalingBaseAddr_IPS:%x  u32DynamicScalingBaseAddr_OPS:%x  \n",__func__,__LINE__,(int)pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_OPM,(int)pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_OPS);
1238     }
1239     Hal_XC_Enable_DS_4_Baseaddress_Mode(pInstance, TRUE);
1240 #else
1241     pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr = u32MemBaseAddr;
1242     pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth = DS_INDEX_DEPTH;
1243     pXCResourcePrivate->sthal_SC.u32DynamicScalingBufSize = BYTE_PER_WORD * pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth * DS_MAX_INDEX;
1244 #endif
1245 
1246 
1247 #if SUPPORT_SEAMLESS_ZAPPING
1248     //Befor DS On, Clean the DS memory
1249     if(u16OnOff & 0x0E00)
1250     {
1251         MS_U8 u8index = 0;
1252         //printf("@@#@@[%s][%d]DS Status=%x\n", __FUNCTION__, __LINE__, u16OnOff);
1253         for(u8index=0; u8index<(sizeof(pXCResourcePrivate->sthal_SC.u8SeamlessZappingNextIndex)/sizeof(pXCResourcePrivate->sthal_SC.u8SeamlessZappingNextIndex[0])); u8index++)
1254         {
1255             _Hal_SC_ResetDSCommand(pInstance, MAIN_WINDOW, u8index);
1256         }
1257     }
1258 #endif
1259 
1260 
1261     //Befor DS On, Clean the DS memory
1262     if(u16OnOff & 0x0E00)
1263     {
1264         XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] u8IdxDepth:%d DS_MAX_INDEX:%d BYTE_PER_WORD:%d  \n",__func__,__LINE__,u8IdxDepth,DS_MAX_INDEX,BYTE_PER_WORD);
1265 
1266         pXCResourcePrivate->sthal_SC.u8DynamicScalingCurrentIndex[eWindow] = 0;
1267         pXCResourcePrivate->sthal_SC.u8DynamicScalingNextIndex[eWindow] = 0;
1268         pXCResourcePrivate->sthal_SC.u8DynamicScalingCurrentIndex_Ring[eWindow] = 0;
1269 
1270     #if ENABLE_DS_4_BASEADDR_MODE
1271         Hal_SC_ResetSWDSCommand(pInstance,eWindow,0);
1272     #else
1273         MS_U8 u8index = 0;
1274 
1275         for(u8index=0; u8index < DS_MAX_INDEX; u8index++)
1276         {
1277             Hal_SC_ResetSWDSCommand(pInstance,eWindow, u8index);
1278         }
1279     #endif
1280     }
1281 
1282     if(u16OnOff & 0x0E00)
1283     {
1284         // ENABLE DS
1285         u16OnOff |= BIT(12);     // enable write register through RIU
1286         pXCResourcePrivate->sthal_SC.bDynamicScalingEnable = TRUE;
1287 
1288         // currently, these 3 will use same MIU
1289         u16OnOff |= ((u8MIU_Select & 0x01) << 13);                       // MIU select of OP
1290         u16OnOff |= ((u8MIU_Select & 0x01) << 14);                       // MIU select of IPS
1291         u16OnOff |= ((u8MIU_Select & 0x01) << 15);                       // MIU select of IPM
1292 
1293         // patch IP1F2_21[15:14] r/w bank
1294         if(FALSE == pXCResourcePrivate->sthal_SC.sbOldValueReaded)
1295         {
1296             pXCResourcePrivate->sthal_SC.su16OldValue = SC_R2BYTE(0, REG_SC_BK01_21_L);
1297             pXCResourcePrivate->sthal_SC.sbOldValueReaded = TRUE;
1298             SC_W2BYTEMSK(0, REG_SC_BK01_21_L, 0x4000, 0xC000);
1299         }
1300 
1301         Hal_XC_MLoad_set_opm_lock(pInstance, OPM_LOCK_DS);
1302 
1303         SC_W2BYTEMSK(0, REG_SC_BK1F_14_L, 0x0000, 0x0002);
1304 
1305         //For Maldives DS case 25-4R unmatch1, 3=0. need to disable power gating
1306         SC_W2BYTEMSK(0, REG_SC_BK00_03_L, 0, BIT(12)); // disable dynamic gating
1307     }
1308     else
1309     {
1310         pXCResourcePrivate->sthal_SC.bDynamicScalingEnable = FALSE;
1311         // DISABLE DS
1312         if(pXCResourcePrivate->sthal_SC.sbOldValueReaded)
1313         {
1314             SC_W2BYTE(0, REG_SC_BK01_21_L, pXCResourcePrivate->sthal_SC.su16OldValue);
1315             pXCResourcePrivate->sthal_SC.sbOldValueReaded = FALSE;
1316         }
1317         Hal_XC_MLoad_set_opm_lock(pInstance, OPM_LOCK_INIT_STATE);
1318 
1319         SC_W2BYTEMSK(0, REG_SC_BK1F_14_L, 0x0002, 0x0002);
1320         SC_W2BYTEMSK(0, REG_SC_BK00_03_L, BIT(12), BIT(12)); //enable dynamic gating
1321 
1322 #ifdef UFO_XC_SWDS_SW_FILM_ENABLE // ForceI SW film mode De interlace mode setting
1323         SC_W2BYTEMSK(0, REG_SC_BK0A_17_L, 0x0000, 0x0180); //Disable SW film
1324 #endif
1325     }
1326 
1327     // if disabled, need to set dynamic scaling ratio to 1:1
1328     if(!bOP_On)
1329     {
1330         SC_W4BYTE(0, REG_SC_BK23_1C_L, 0x00100000);
1331         SC_W4BYTE(0, REG_SC_BK23_1E_L, 0x00100000);
1332     }
1333 
1334     if(u16OnOff & 0x0E00)
1335     {
1336         if (FALSE == pXCResourcePrivate->sthal_SC.bTrig_pStored)
1337         {
1338             // set base address
1339             Hal_XC_Set_DS_BaseAddress(pInstance,u32MemBaseAddr);
1340 
1341             // set index depth
1342             Hal_XC_Set_DS_IndexDepth(pInstance);
1343             //enable ipm tune after DS when DS on
1344             MHAL_SC_Enable_IPMTuneAfterDS(pInstance,ENABLE);
1345 
1346 #if SUPPORT_SEAMLESS_ZAPPING
1347             // [DS New Mode] Set new command format (ips/ops/ipm/opm)
1348             SC_W2BYTEMSK(0, REG_SC_BK1F_14_L, 0x0008, 0x0008);
1349 #endif
1350             // MIU sel
1351             SC_W2BYTEMSK(0, REG_SC_BK1F_10_L, u16OnOff & 0xE000, 0xE000);
1352 
1353             // set DMA threthold, length, fixed value, no need to change
1354             SC_W2BYTEMSK(0, REG_SC_BK1F_10_L, 0x88, 0x00FF);
1355 
1356 #if 0//SUPPORT_SEAMLESS_ZAPPING  // for Sub
1357             // [DS New Mode] Set OP sub dynamic scaling
1358             SC_W2BYTEMSK(0, REG_SC_BK1F_14_L, 0x0800, 0xFF00); // Set OP main sub trig delay and trig select
1359             SC_W2BYTEMSK(0, REG_SC_BK1F_13_L, 0x0100, 0x0100); // Set OP sub index selection from sub
1360             SC_W2BYTEMSK(0, REG_SC_BK1F_14_L, (bOP_On << 4), 0x0010); // Enable/disable OP sub dynamic scaling
1361 #endif
1362             // store
1363             Hal_XC_MLoad_get_trig_p(pInstance, &pXCResourcePrivate->sthal_SC.u16OldTrain, &pXCResourcePrivate->sthal_SC.u16OldDisp);
1364             pXCResourcePrivate->sthal_SC.bTrig_pStored = TRUE;
1365 
1366             // set the trigger point from delayed line,  DS: 0x08, Train:0x14, Disp:0x18
1367             SC_W2BYTEMSK(0, REG_SC_BK20_21_L, 0x08, 0xFF);  // ds_trig_dly
1368 
1369             if (SC_R2BYTEMSK(0, REG_SC_BK0F_2A_L, BIT(5)|BIT(8)) == (BIT(5)|BIT(8)) ) //FIXME: I/P mode should all use (0x0A,0x0C), but need to do full test
1370             {
1371                 Hal_XC_MLoad_set_trig_p(pInstance,0x0A, 0x0C);//For I mode output
1372             }
1373             else
1374             {
1375                 Hal_XC_MLoad_set_trig_p(pInstance, 0x14, 0x18);
1376             }
1377 
1378             // set trigger source to trigger
1379             SC_W2BYTEMSK(0, REG_SC_BK20_19_L, 0x08B8, 0x08BC);
1380 
1381             //set the delay line cnt to vfde end
1382             SC_W2BYTEMSK(0, REG_SC_BK20_19_L, BIT(6), BIT(6)|BIT(0));
1383 #if ENABLE_64BITS_COMMAND
1384             Hal_XC_Enable_DS_64Bits_Command(pInstance,TRUE);
1385             #if ENABLE_64BITS_SPREAD_MODE
1386                 Hal_XC_Enable_DS_64Bits_Sread_Mode(pInstance,TRUE);
1387             #endif
1388             Hal_XC_Set_DS_64Bits_MIU_Bus_Sel(pInstance);
1389 #endif
1390         }
1391     }
1392     else
1393     {
1394         // restore
1395         if (pXCResourcePrivate->sthal_SC.bTrig_pStored)
1396         {
1397             pXCResourcePrivate->sthal_SC.bTrig_pStored = FALSE;
1398             Hal_XC_MLoad_set_trig_p(pInstance, pXCResourcePrivate->sthal_SC.u16OldTrain, pXCResourcePrivate->sthal_SC.u16OldDisp);
1399 
1400             //set the delay line cnt to V sync start
1401             SC_W2BYTEMSK(0, REG_SC_BK20_19_L, 0, BIT(6)|BIT(0));
1402             //disable ipm tune after DS when DS off
1403             MHAL_SC_Enable_IPMTuneAfterDS(pInstance,DISABLE);
1404         }
1405     }
1406 
1407     // set DS in IPS[10],ipm[11] On/Off
1408     if (MDrv_XC_MLoad_GetStatus(pInstance) == E_MLOAD_ENABLED)
1409     {
1410         _MLOAD_ENTRY(pInstance);
1411         MDrv_XC_MLoad_WriteCmd(pInstance, REG_SC_BK1F_10_L, u16OnOff & 0x1D00, 0x1D00);
1412         MDrv_XC_MLoad_Fire(pInstance, TRUE);
1413         _MLOAD_RETURN(pInstance);
1414     }
1415     else
1416     {
1417         SC_W2BYTEMSK(0, REG_SC_BK1F_10_L, u16OnOff & 0x1D00, 0x1D00);
1418     }
1419 
1420     // set DS in OP[9] On/Off
1421 #if SUPPORT_SEAMLESS_ZAPPING
1422 //printf("@@#@@[%s][%d]bSeamlessZappingEnable[MAIN_WINDOW]=%x\n", __FUNCTION__, __LINE__, pXCResourcePrivate->sthal_SC.bSeamlessZappingEnable[MAIN_WINDOW]);
1423     if(bOP_On&&(!bIPS_On)&&(!bIPM_On))
1424     {
1425         //  the SLZ control flow need DS init but the OP DS enable switch will control by the other code flow, disbale the OP DS first
1426         u16OnOff &= 0xFDFF;
1427     }
1428 #endif
1429 
1430     if (MDrv_XC_MLoad_GetStatus(pInstance) == E_MLOAD_ENABLED)
1431     {
1432         _MLOAD_ENTRY(pInstance);
1433         MDrv_XC_MLoad_WriteCmd(pInstance, REG_SC_BK1F_10_L, u16OnOff & 0x0200, 0x0200);
1434         MDrv_XC_MLoad_Fire(pInstance, TRUE);
1435         _MLOAD_RETURN(pInstance);
1436     }
1437     else
1438     {
1439         SC_W2BYTEMSK(0, REG_SC_BK1F_10_L, u16OnOff & 0x0200, 0x0200);
1440     }
1441 
1442     if(bOP_On || bIPM_On)
1443     {
1444      // RD's suggestion for DS hang issue , turn on DNR / WD after setting DS on.
1445         if(MDrv_XC_MLoad_GetStatus(pInstance) == E_MLOAD_ENABLED)
1446         {
1447             _MLOAD_ENTRY(pInstance);
1448             if(bDNREnable)
1449             {
1450                 MDrv_XC_MLoad_WriteCmd(pInstance, REG_SC_BK12_02_L, 0, BIT(14));
1451             }
1452             MDrv_XC_MLoad_WriteCmd(pInstance, REG_SC_BK1F_05_L, (BIT(15)|BIT(14)), BIT(15)|BIT(14));
1453             MDrv_XC_MLoad_Fire(pInstance, TRUE);
1454             _MLOAD_RETURN(pInstance);
1455         }
1456         else
1457         {
1458             if(bDNREnable)
1459             {
1460                 SC_W2BYTEMSK(0, REG_SC_BK12_02_L, 0, BIT(14)); // enable DNR
1461             }
1462             SC_W2BYTEMSK(0, REG_SC_BK1F_05_L,(BIT(15)|BIT(14)), BIT(15)|BIT(14)); //enable WD
1463         }
1464     }
1465 
1466     return TRUE;
1467 }
1468 
MHAL_SC_Set_DynamicScalingFlag(void * pInstance,MS_BOOL bEnable)1469 void MHAL_SC_Set_DynamicScalingFlag(void *pInstance, MS_BOOL bEnable)
1470 {
1471     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1472     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1473     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
1474     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
1475     pXCResourcePrivate->sthal_SC.bDynamicScalingEnable = bEnable;
1476 }
1477 
MHAL_SC_Get_DynamicScaling_Status(void * pInstance)1478 MS_BOOL MHAL_SC_Get_DynamicScaling_Status(void *pInstance)
1479 {
1480     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1481     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1482     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
1483     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
1484     return pXCResourcePrivate->sthal_SC.bDynamicScalingEnable;
1485 }
1486 
MHAL_SC_Enable_IPMTuneAfterDS(void * pInstance,MS_BOOL bEnable)1487 MS_BOOL MHAL_SC_Enable_IPMTuneAfterDS(void *pInstance, MS_BOOL bEnable)
1488 {
1489     if(bEnable)
1490         SC_W2BYTEMSK(0, REG_SC_BK12_06_L, BIT(7), BIT(7));
1491     else
1492         SC_W2BYTEMSK(0, REG_SC_BK12_06_L, 0, BIT(7));
1493 
1494     return TRUE;
1495 }
1496 
MHal_SC_DynamicScaling_SWReset(void)1497 void MHal_SC_DynamicScaling_SWReset(void)
1498 {
1499     SC_W2BYTEMSK(0, REG_SC_BK1F_13_L, 0x400, 0x400);
1500     SC_W2BYTEMSK(0, REG_SC_BK1F_13_L, 0x800, 0x800);
1501     SC_W2BYTEMSK(0, REG_SC_BK1F_13_L, 0x1000, 0x1000);
1502 
1503     SC_W2BYTEMSK(0, REG_SC_BK1F_13_L, 0x0, 0x1000);
1504     SC_W2BYTEMSK(0, REG_SC_BK1F_13_L, 0x0, 0x800);
1505     SC_W2BYTEMSK(0, REG_SC_BK1F_13_L, 0x0, 0x400);
1506 }
1507 
MHal_XC_Get_DSForceIndexSupported(void * pInstance,SCALER_WIN eWindow)1508 MS_BOOL MHal_XC_Get_DSForceIndexSupported(void *pInstance, SCALER_WIN eWindow)
1509 {
1510     if (eWindow >= MAX_WINDOW)
1511     {
1512         printf("[%s,%5d] maximum window exceeded",__FUNCTION__,__LINE__);
1513         return FALSE;
1514     }
1515 
1516     return TRUE;
1517 }
MHal_XC_Set_DSForceIndex(void * pInstance,MS_BOOL bEnable,MS_U8 u8Index,SCALER_WIN eWindow)1518 void MHal_XC_Set_DSForceIndex(void *pInstance, MS_BOOL bEnable, MS_U8 u8Index, SCALER_WIN eWindow)
1519 {
1520     if (eWindow >= MAX_WINDOW)
1521     {
1522         printf("[%s,%5d] maximum window exceeded",__FUNCTION__,__LINE__);
1523         return;
1524     }
1525 
1526     //printf("@@[%s][%d]bEnable=%u, u8Index=%u\n", __FUNCTION__, __LINE__, bEnable, u8Index);
1527     if (eWindow == MAIN_WINDOW)
1528     {
1529         // reg_idxg_force_en
1530         SC_W2BYTEMSK(0, REG_SC_BK1F_77_L, bEnable?BIT(2):0 , BIT(2));
1531         // reg_idxg_force_idx_f2
1532         SC_W2BYTEMSK(0, REG_SC_BK1F_76_L, (MS_U16)u8Index << 8 , 0xFF00);
1533     }
1534     else // eWindow == SUB_WINDOW
1535     {
1536         SC_W2BYTEMSK(0, REG_SC_BK1F_77_L, bEnable?BIT(10):0 , BIT(10));
1537         // reg_idxg_force_idx_f1
1538         SC_W2BYTEMSK(0, REG_SC_BK1F_75_L, (MS_U16)u8Index << 8 , 0xFF00);
1539     }
1540 }
1541 
MHal_XC_Set_DSIndexSourceSelect(void * pInstance,E_XC_DS_INDEX_SOURCE eDSIdxSrc,SCALER_WIN eWindow)1542 void MHal_XC_Set_DSIndexSourceSelect(void *pInstance, E_XC_DS_INDEX_SOURCE eDSIdxSrc, SCALER_WIN eWindow)
1543 {
1544     if (eWindow >= MAX_WINDOW)
1545     {
1546         printf("[%s,%5d] maximum window exceeded",__FUNCTION__,__LINE__);
1547         return;
1548     }
1549 
1550     if (eDSIdxSrc >= E_XC_DS_INDEX_MAX)
1551     {
1552         printf("[%s,%5d] Maximum index exceeded, the index is (%d)\n",__FUNCTION__,__LINE__,eDSIdxSrc);
1553         return;
1554     }
1555 
1556     //printf("@@[%s][%d]eDSIdxSrc=%u, eWindow=%u\n", __FUNCTION__, __LINE__, eDSIdxSrc, eWindow);
1557 
1558     if(eWindow == MAIN_WINDOW)
1559     {
1560         // reg_idxg_en_f2
1561         SC_W2BYTEMSK(0, REG_SC_BK1F_77_L, eDSIdxSrc, BIT(0));
1562     }
1563     else
1564     {
1565         // reg_idxg_en_f1
1566         SC_W2BYTEMSK(0, REG_SC_BK1F_77_L, eDSIdxSrc << 8, BIT(8));
1567     }
1568 }
1569 
Hal_XC_Enable_DS_64Bits_Command(void * pInstance,MS_BOOL bEn)1570 void Hal_XC_Enable_DS_64Bits_Command(void *pInstance,MS_BOOL bEn)
1571 {
1572     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1573     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1574 
1575     SC_W2BYTEMSK(psXCInstPri->u32DeviceID,REG_SC_BK1F_70_L, bEn?BIT(0):0x00, BIT(0));
1576 }
1577 
Hal_XC_Enable_DS_64Bits_Sread_Mode(void * pInstance,MS_BOOL bEn)1578 void Hal_XC_Enable_DS_64Bits_Sread_Mode(void *pInstance,MS_BOOL bEn)
1579 {
1580     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1581     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1582 
1583     SC_W2BYTEMSK(psXCInstPri->u32DeviceID,REG_SC_BK1F_70_L, bEn?BIT(15):0x00, BIT(15));
1584 }
1585 
Hal_XC_Enable_DS_4_Baseaddress_Mode(void * pInstance,MS_BOOL bEn)1586 void Hal_XC_Enable_DS_4_Baseaddress_Mode(void *pInstance,MS_BOOL bEn)
1587 {
1588     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1589     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1590 
1591     SC_W2BYTEMSK(psXCInstPri->u32DeviceID,REG_SC_BK1F_17_L, bEn?BIT(7):0x00, BIT(7));
1592 }
1593 
Hal_XC_Set_DS_64Bits_MIU_Bus_Sel(void * pInstance)1594 void Hal_XC_Set_DS_64Bits_MIU_Bus_Sel(void *pInstance)
1595 {
1596     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1597     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1598 
1599     MS_U16 u16sel = 0x00;
1600 
1601     if( MS_MLOAD_BUS_WIDTH == 8 )
1602     {
1603         u16sel = 0x00;
1604     }
1605     else if( MS_MLOAD_BUS_WIDTH == 16 )
1606     {
1607         u16sel = 0x01;
1608     }
1609     else if( MS_MLOAD_BUS_WIDTH == 32 )
1610     {
1611         u16sel = 0x3;
1612     }
1613     else
1614     {
1615         printf("MIU Bus not support !!!!!!!!!!!!!!!!!\n");
1616         u16sel = 0x00;
1617     }
1618 
1619     u16sel = (u16sel & 0x0003)<<14;
1620     SC_W2BYTEMSK(psXCInstPri->u32DeviceID,REG_SC_BK1F_13_L, u16sel, 0xC000);
1621 }
1622 
Hal_XC_Set_DS_BaseAddress(void * pInstance,MS_PHY u32Base)1623 void Hal_XC_Set_DS_BaseAddress(void *pInstance,MS_PHY u32Base)
1624 {
1625     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1626     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1627     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
1628     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
1629 
1630     if( u32Base > HAL_MIU1_BASE)
1631     {
1632         u32Base = u32Base - HAL_MIU1_BASE;
1633     }
1634 
1635     MS_U32 u32Base_OPM = 0;
1636     u32Base_OPM = pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_OPM;
1637 
1638     if( u32Base_OPM  > HAL_MIU1_BASE)
1639     {
1640         u32Base_OPM  = u32Base_OPM  - HAL_MIU1_BASE;
1641     }
1642 
1643     u32Base = u32Base/MS_MLOAD_MEM_BASE_UNIT;
1644 
1645     #if ENABLE_DS_4_BASEADDR_MODE
1646             // set IPM
1647             SC_W2BYTE(psXCInstPri->u32DeviceID, REG_SC_BK1F_11_L, u32Base & 0xFFFF);
1648             SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_12_L, (u32Base >> 16),0xFFFF);
1649 
1650             //set IPS
1651             SC_W2BYTE(psXCInstPri->u32DeviceID, REG_SC_BK1F_0C_L, (pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_IPS / MS_MLOAD_MEM_BASE_UNIT) & 0xFFFF);
1652             SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_0D_L, ((pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_IPS / MS_MLOAD_MEM_BASE_UNIT) >> 16),0xFFFF);
1653 
1654             if(!((gSrcInfo[MAIN_WINDOW].bR_FBL) || (gSrcInfo[MAIN_WINDOW].bFBL)))
1655             {
1656                 //set OPM
1657                 SC_W2BYTE(psXCInstPri->u32DeviceID, REG_SC_BK1F_0E_L, (u32Base_OPM / MS_MLOAD_MEM_BASE_UNIT) & 0xFFFF);
1658                 SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_0F_L, ((u32Base_OPM / MS_MLOAD_MEM_BASE_UNIT) >> 16),0xFFFF);
1659 
1660                 //set OPS
1661                 SC_W2BYTE(psXCInstPri->u32DeviceID, REG_SC_BK1F_60_L, (pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_OPS / MS_MLOAD_MEM_BASE_UNIT) & 0xFFFF);
1662                 SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_61_L, ((pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_OPS / MS_MLOAD_MEM_BASE_UNIT) >> 16),0xFFFF);
1663             }
1664     #else
1665             // set DS base address
1666             SC_W2BYTE(psXCInstPri->u32DeviceID, REG_SC_BK1F_11_L, u32Base & 0xFFFF);
1667             SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_12_L, (u32Base >> 16),0xFFFF);
1668     #endif
1669 
1670 }
1671 
Hal_XC_Set_DS_IndexDepth(void * pInstance)1672 void Hal_XC_Set_DS_IndexDepth(void *pInstance)
1673 {
1674     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1675     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1676     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
1677     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
1678 
1679     SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_13_L, pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth , 0x00FF);
1680 }
1681 
Hal_SC_GenSpreadModeCmd(void * pInstance,MS_U32 u32CmdRegAddr,MS_U16 u16CmdRegValue,MS_U16 u16Mask,ds_reg_source_sel eSourceSelect)1682 MS_U64 Hal_SC_GenSpreadModeCmd(void *pInstance, MS_U32 u32CmdRegAddr, MS_U16 u16CmdRegValue, MS_U16 u16Mask, ds_reg_source_sel eSourceSelect)
1683 {
1684     MS_U64 u64CmdTemp = 0;
1685     MS_U8  u8AddrTemp = 0;
1686     MS_U16 u16BankTemp = 0;
1687     MS_U16 u16DataTemp = 0;
1688 
1689     if(eSourceSelect == DS_XC)
1690     {
1691         u64CmdTemp = Hal_XC_MLoad_Gen_64bits_spreadMode(pInstance, u32CmdRegAddr, u16CmdRegValue, u16Mask);
1692     }
1693     else if(eSourceSelect == DS_MVOP)
1694     {
1695         u16DataTemp = u16CmdRegValue;
1696         u8AddrTemp = (u32CmdRegAddr&0x000000FF);
1697         u16BankTemp = (u32CmdRegAddr&0x00FFFF00) >> 8; //EX: mvop mainwinodw: 0x1014 mvop bank
1698         u64CmdTemp = Hal_XC_MLoad_Gen_64bits_spreadMode_NonXC(pInstance, u16BankTemp, u8AddrTemp, u16DataTemp, u16Mask);
1699     }
1700     else if(eSourceSelect == DS_GOP)
1701     {
1702         //TO DO
1703     }
1704     else
1705     {
1706         XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] Only can support XC/MVOP/GOP NOW !! \n",__func__,__LINE__);
1707     }
1708 
1709     return u64CmdTemp;
1710 }
1711 
Hal_XC_Is_SupportSWDS(void * pInstance)1712 MS_BOOL Hal_XC_Is_SupportSWDS(void *pInstance)
1713 {
1714     //Return true if sw code is support MCU mode DS
1715     return TRUE;
1716 }
1717 
MHal_XC_Set_DS_ForceI_DeInterlaceMode(void * pInstance,MS_BOOL bPmode,MS_BOOL bIsTopField,MS_U16 u16FrameRate,SCALER_WIN eWindow)1718 void MHal_XC_Set_DS_ForceI_DeInterlaceMode(void *pInstance, MS_BOOL bPmode,  MS_BOOL bIsTopField, MS_U16 u16FrameRate, SCALER_WIN eWindow)
1719 {
1720     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1721     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1722     if (eWindow >= MAX_WINDOW)
1723     {
1724         printf("[%s,%5d] maximum window exceeded",__FUNCTION__,__LINE__);
1725         return;
1726     }
1727     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
1728     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
1729 
1730     pXCResourcePrivate->sthal_SC.bDynamicScalingForceI[eWindow] = TRUE;
1731     pXCResourcePrivate->sthal_SC.bCurrentPmode[eWindow] = bPmode;
1732     pXCResourcePrivate->sthal_SC.bIsTopField[eWindow] = bIsTopField;
1733     pXCResourcePrivate->sthal_SC.u16CurrentFramerate[eWindow] = u16FrameRate;
1734 
1735     //Disable HW film22
1736     SC_W2BYTEMSK(psXCInstPri->u32DeviceID,REG_SC_BK0A_10_L, 0, BIT(14));
1737 
1738     //printf("\33[0;35m [SWDS] %s %d: , bPmode[%u],  bIsTopField[%u], u16FrameRate[%u], eWindow[%u]   \33[m \n", __FUNCTION__,  __LINE__,  bPmode,   bIsTopField,  u16FrameRate,  eWindow);
1739 }
1740 
1741 #endif // MHAL_DYNAMICSCALING_C
1742