xref: /utopia/UTPA2-700.0.x/modules/xc/hal/k6lite/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 
135 #define DS_DBG(x)   //x
136 #define SLZ_DBG(x)  //x
137 
138 //clear DS Buffer
Hal_SC_ResetSWDSCommand(void * pInstance,SCALER_WIN eWindow,MS_U8 u8DSIndex)139 void Hal_SC_ResetSWDSCommand(void *pInstance,SCALER_WIN eWindow, MS_U8 u8DSIndex)
140 {
141     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
142     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
143     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
144     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
145 
146 #if ENABLE_64BITS_SPREAD_MODE
147 
148     MS_PHY u32IndexBase = pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr;
149 
150     MS_U16 u16TotalCmdCnt = pXCResourcePrivate->sthal_SC.u32DynamicScalingBufSize/DS_CMD_LEN_64BITS;
151     MS_U16 i = 0;
152 
153     MS_U64 *pu64Data = NULL;
154     u16TotalCmdCnt /= 2;
155 
156     for(i = 0; i < u16TotalCmdCnt; i++)
157     {
158         pu64Data  = (MS_U64*)MsOS_PA2KSEG1(u32IndexBase + i*DS_CMD_LEN_64BITS);
159         *pu64Data = 0x00000009FFFF0000;
160     }
161 
162     u32IndexBase = pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_OPM;
163     for(i = 0; i < u16TotalCmdCnt; i++)
164     {
165         pu64Data  = (MS_U64*)MsOS_PA2KSEG1(u32IndexBase + i*DS_CMD_LEN_64BITS);
166         *pu64Data = 0x00000009FFFF0000;
167     }
168 
169 #else
170     MS_PHY u32IndexBase = pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr + (MS_U32)u8DSIndex * pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth * MS_MLOAD_MEM_BASE_UNIT;
171 
172     MS_U32 *pu32Data = NULL;
173     int i = 0;
174 
175     //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);
176 
177     for(i = 0; i < (pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth * MS_MLOAD_MEM_BASE_UNIT)/4; i++) //need check
178     {
179         if(i % 8 < 4)
180         {
181             if(MAIN_WINDOW == eWindow)
182             {
183                 if(i % 4 < 2)
184                 {
185                     pu32Data = (MS_U32*)MsOS_PA2KSEG1(u32IndexBase + (i*4));
186                     if(0 == pu32Data)
187                     {
188                         printf("%s :pu32Data_1 = 0!,error!!!\n", __FUNCTION__);
189                         assert(pu32Data != 0);
190                     }
191                     *pu32Data = 0xFFFF0000;
192                 }
193             }
194             else //SUB_WINDOW == eWindow
195             {
196                 if(i % 4 >= 2)
197                 {
198                     pu32Data = (MS_U32*)MsOS_PA2KSEG1(u32IndexBase + (i*4));
199                     if(0 == pu32Data)
200                     {
201                         printf("%s :pu32Data_2 = 0!,error!!!\n", __FUNCTION__);
202                         assert(pu32Data != 0);
203                     }
204                     *pu32Data = 0xFFFF0000;
205                 }
206             }
207         }
208         else
209         {
210             if(MAIN_WINDOW == eWindow)
211             {
212                 if(i % 4 < 2)
213                 {
214                     pu32Data = (MS_U32*)MsOS_PA2KSEG1(u32IndexBase + (i*4));
215                     if(0 == pu32Data)
216                     {
217                         printf("%s :pu32Data_3 = 0!,error!!!\n", __FUNCTION__);
218                         assert(pu32Data != 0);
219                     }
220                     *pu32Data = 0xFFFF0000;//0;
221 
222                     //printf("[szuhua] [%s,%5d] [IP] 0xFFFF0000 \n",__func__,__LINE__);
223                 }
224             }
225             else //SUB_WINDOW == eWindow
226             {
227                 if(i % 4 >= 2)
228                 {
229                     pu32Data = (MS_U32*)MsOS_PA2KSEG1(u32IndexBase + (i*4));
230                     if(0 == pu32Data)
231                     {
232                         printf("%s :pu32Data_4 = 0!,error!!!\n", __FUNCTION__);
233                         assert(pu32Data != 0);
234                     }
235                     *pu32Data = 0xFFFF0000;
236                 }
237             }
238         }
239     }
240 #endif
241 }
242 
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)243 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)
244 {
245     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
246     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
247     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
248     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
249 
250 #if ENABLE_DS_4_BASEADDR_MODE
251     MS_PHY u32Addr = pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr + pXCResourcePrivate->sthal_SC.u8DynamicScalingCurrentIndex_Ring[eWindow] * pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth * MS_MLOAD_MEM_BASE_UNIT;
252     MS_PHY u32Addr_OPM = pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_OPM + pXCResourcePrivate->sthal_SC.u8DynamicScalingCurrentIndex_Ring[eWindow] * pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth * MS_MLOAD_MEM_BASE_UNIT;
253     MS_PHY u32Addr_IPS = pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_IPS + pXCResourcePrivate->sthal_SC.u8DynamicScalingCurrentIndex_Ring[eWindow] * pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth * MS_MLOAD_MEM_BASE_UNIT;
254     MS_PHY u32Addr_OPS = pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_OPS + pXCResourcePrivate->sthal_SC.u8DynamicScalingCurrentIndex_Ring[eWindow] * pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth * MS_MLOAD_MEM_BASE_UNIT;
255 #else
256     MS_PHY u32Addr = pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr + pXCResourcePrivate->sthal_SC.u8DynamicScalingCurrentIndex_Ring[eWindow] * pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth * MS_MLOAD_MEM_BASE_UNIT;
257 #endif
258 
259     //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);
260     //XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] u32Addr:%x  \n",__func__,__LINE__,(int)u32Addr);
261 
262 #if ENABLE_DS_4_BASEADDR_MODE
263 
264     MS_U64 *pu64Data = NULL;
265     MS_U64 u64CmdTemp = 0;
266     MS_U8  u8AddrTemp = 0;
267     MS_U16 u16BankTemp = 0;
268     MS_U16 u16DataTemp = 0;
269     MS_U16 u16MaskTemp = 0;
270     MS_U8 u8MaxCmdCnt = pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth * 2;
271 
272 
273 //===========================================================//
274 //  64bit command format (spread mode)
275 //  |-------------|-------------|----------------------------|-------------|
276 //  |    Bit-En   |    Unused   |    Addr(FULL RIU ADDR)     |     Data    |
277 //  |-------------|-------------|----------------------------|-------------|
278 //  |   [63:48]   |   [47:40]   |           [39:16]          |   [15:0]    |
279 //  |-------------|-------------|----------------------------|-------------|
280 
281 //Addr: FULL RIU ADDRESS !!!
282 
283 //For example:  Subbank:0x01            addr:0x40 Data:0x0001
284 //              Spread mode :  0x1301   addr:0x40 Data:0x0001
285 
286 //|----------------------------------------------------|
287 //|                      Bank             |    addr    |
288 //|----------------------------------------------------|
289 //|                     0x1301            |    0x40    |
290 //|----------------------------------------------------|
291 // FULL RIU ADDRESS: |0001 0011 0000 0001 |  100 0000  |
292 // FULL RIU ADDRESS:              0x0980C1
293 //===========================================================//
294 
295     if(Source_Select == DS_XC)
296     {
297         u16MaskTemp = 0xFFFF;
298         u16DataTemp = u16CmdRegValue;
299 
300         u8AddrTemp= (u32CmdRegAddr & 0x000000FF) >> 1;
301         u16BankTemp= 0x1300 | ((u32CmdRegAddr >> 8) & 0x000000FF); // 0x13XX xc sread mode address
302 
303         u64CmdTemp|= (MS_U64)u16DataTemp;
304         u64CmdTemp|= ((MS_U64)u8AddrTemp<<16);
305         u64CmdTemp|= ((MS_U64)u16BankTemp<<23);
306         u64CmdTemp|= ((MS_U64)u16MaskTemp<<48);
307 
308         if(IPOP_Sel == DS_IP)
309         {
310             if(eWindow == MAIN_WINDOW)
311             {
312                 MS_U32 u32MemShift_IPM;
313 
314                 if((pstXC_DS_CmdCnt->u16CMDCNT_IPM % 2) == 0)
315                 {
316                     u32MemShift_IPM = (pstXC_DS_CmdCnt->u16CMDCNT_IPM / 2) * MS_MLOAD_MEM_BASE_UNIT;
317                 }
318                 else
319                 {
320                     u32MemShift_IPM = (pstXC_DS_CmdCnt->u16CMDCNT_IPM / 2) * MS_MLOAD_MEM_BASE_UNIT  + DS_CMD_LEN_64BITS;
321                 }
322                 //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);
323                 //u32Addr = u32Addr + DS_CMD_LEN_64BITS * pstXC_DS_CmdCnt->u16CMDCNT_IPM;
324                 u32Addr = u32Addr + u32MemShift_IPM;
325                 pu64Data = (MS_U64*)MsOS_PA2KSEG1(u32Addr);//IPM
326 
327                 if(pstXC_DS_CmdCnt->u16CMDCNT_IPM < u8MaxCmdCnt)
328                 {
329                     *pu64Data = u64CmdTemp;
330                     pstXC_DS_CmdCnt->u16CMDCNT_IPM++;
331                 }
332                 else
333                 {
334                     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);
335                 }
336             }
337             else//subwindow
338             {
339                 u32Addr_IPS = u32Addr_IPS + DS_CMD_LEN_64BITS * pstXC_DS_CmdCnt->u16CMDCNT_IPS;
340                 pu64Data = (MS_U64*)MsOS_PA2KSEG1(u32Addr_IPS); // IPS
341 
342                 if(pstXC_DS_CmdCnt->u16CMDCNT_IPS < u8MaxCmdCnt)
343                 {
344                     *pu64Data = u64CmdTemp;
345                     pstXC_DS_CmdCnt->u16CMDCNT_IPS++;
346                 }
347                 else
348                 {
349                     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);
350                 }
351             }
352         }
353         else//DS_OP
354         {
355             if(eWindow == MAIN_WINDOW)
356             {
357                 MS_U32 u32MemShift_OPM;
358 
359                 if((pstXC_DS_CmdCnt->u16CMDCNT_OPM % 2) == 0)
360                 {
361                     u32MemShift_OPM = (pstXC_DS_CmdCnt->u16CMDCNT_OPM / 2) * MS_MLOAD_MEM_BASE_UNIT;
362                 }
363                 else
364                 {
365                     u32MemShift_OPM = (pstXC_DS_CmdCnt->u16CMDCNT_OPM / 2) * MS_MLOAD_MEM_BASE_UNIT  + DS_CMD_LEN_64BITS;
366                 }
367                 //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);
368                 //u32Addr_OPM = u32Addr_OPM + DS_CMD_LEN_64BITS * pstXC_DS_CmdCnt->u16CMDCNT_OPM;
369                 u32Addr_OPM = u32Addr_OPM + u32MemShift_OPM;
370                 pu64Data = (MS_U64*)MsOS_PA2KSEG1(u32Addr_OPM);//OPM
371 
372                 //XC_PRINTF("[%s,%5d] u64CmdTemp:%llx  \n",__func__,__LINE__,u64CmdTemp);
373 
374                 if(pstXC_DS_CmdCnt->u16CMDCNT_OPM < u8MaxCmdCnt)
375                 {
376                     *pu64Data = u64CmdTemp;
377                     pstXC_DS_CmdCnt->u16CMDCNT_OPM++;
378                 }
379                 else
380                 {
381                     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);
382                 }
383             }
384             else
385             {
386                 u32Addr_OPS = u32Addr_OPS + DS_CMD_LEN_64BITS * pstXC_DS_CmdCnt->u16CMDCNT_OPS;
387                 pu64Data = (MS_U64*)MsOS_PA2KSEG1(u32Addr_OPS); // OPS
388 
389                 if(pstXC_DS_CmdCnt->u16CMDCNT_OPS < u8MaxCmdCnt)
390                 {
391                     *pu64Data = u64CmdTemp;
392                     pstXC_DS_CmdCnt->u16CMDCNT_OPS++;
393                 }
394                 else
395                 {
396                     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);
397                 }
398             }
399         }
400     }
401     else if(Source_Select == DS_MVOP)// only in IP cmd
402     {
403         if(IPOP_Sel == DS_IP)
404         {
405             u16DataTemp = u16CmdRegValue;
406             u8AddrTemp = (u32CmdRegAddr&0x000000FF);
407             u16BankTemp = (u32CmdRegAddr&0x00FFFF00) >> 8; //EX: mvop mainwinodw: 0x1014 mvop bank
408             u16MaskTemp = 0xFFFF;
409 
410             u64CmdTemp|= (MS_U64)u16DataTemp;
411             u64CmdTemp|= ((MS_U64)u8AddrTemp<<16);
412             u64CmdTemp|= ((MS_U64)u16BankTemp<<23);
413             u64CmdTemp|= ((MS_U64)u16MaskTemp<<48);
414 
415             if(eWindow == MAIN_WINDOW)
416             {
417                 MS_U32 u32MemShift_IPM;
418 
419                 if((pstXC_DS_CmdCnt->u16CMDCNT_IPM % 2) == 0)
420                 {
421                     u32MemShift_IPM = (pstXC_DS_CmdCnt->u16CMDCNT_IPM / 2) * MS_MLOAD_MEM_BASE_UNIT;
422                 }
423                 else
424                 {
425                     u32MemShift_IPM = (pstXC_DS_CmdCnt->u16CMDCNT_IPM / 2) * MS_MLOAD_MEM_BASE_UNIT  + DS_CMD_LEN_64BITS;
426                 }
427                 //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);
428                 //u32Addr = u32Addr + DS_CMD_LEN_64BITS * pstXC_DS_CmdCnt->u16CMDCNT_IPM;
429                 u32Addr = u32Addr + u32MemShift_IPM;
430                 pu64Data = (MS_U64*)MsOS_PA2KSEG1(u32Addr);//IPM
431 
432                 if(pstXC_DS_CmdCnt->u16CMDCNT_IPM < u8MaxCmdCnt)
433                 {
434                     *pu64Data = u64CmdTemp;
435                     pstXC_DS_CmdCnt->u16CMDCNT_IPM++;
436                 }
437                 else
438                 {
439                     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);
440                 }
441             }
442             else
443             {
444                 pu64Data = (MS_U64*)MsOS_PA2KSEG1(u32Addr_IPS);//IPS
445 
446                 if(pstXC_DS_CmdCnt->u16CMDCNT_IPS < u8MaxCmdCnt)
447                 {
448                     *pu64Data = u64CmdTemp;
449                     pstXC_DS_CmdCnt->u16CMDCNT_IPS++;
450                 }
451                 else
452                 {
453                     XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] Command count overflow !!  u16CMDCNT_IPS:%d  Max command count: %d\n",__func__,__LINE__,pstXC_DS_CmdCnt->u16CMDCNT_IPS,pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth);
454                 }
455             }
456         }
457         else
458         {
459             XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] MVOP is IP cmd not OP cmd !! \n",__func__,__LINE__);
460         }
461 
462     }
463     else if(Source_Select == DS_GOP)
464     {
465 
466     }
467     else
468     {
469         XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] Only can support XC/MVOP/GOP NOW !! \n",__func__,__LINE__);
470     }
471 
472 #else
473 
474 //=============================================//
475 //  32bit command format
476 //  |-------------|-------------|-------------|
477 //  |     Bank    |     Addr    |     Data    |
478 //  |-------------|-------------|-------------|
479 //  |   [31:24]   |   [23:16]   |    [15:0]   |
480 //  |-------------|-------------|-------------|
481 
482 //Bank: Subbank
483 //=============================================//
484 
485     if(IPOP_Sel == DS_OP)
486     {
487         MS_PHY u32OPAddr = u32Addr;
488         MS_U32 *pu32Data = NULL;
489         MS_U8 u8OPCount = pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth;
490        // MS_U8 u8OPCount = IdxDepth;
491         MS_PHY u32Command = 0;
492 
493         u32Command = u16CmdRegValue + ((u32CmdRegAddr & 0x00FF) << 15) + ((u32CmdRegAddr & 0xFF00) << 16);
494 
495         while(u8OPCount > 0)
496         {
497             pu32Data = (MS_U32*)MsOS_PA2KSEG1(u32OPAddr);
498             if(0 == pu32Data)
499             {
500                 printf("%s :pu32Data = 0!,error!!!\n", __FUNCTION__);
501 
502                 assert(pu32Data != 0);
503             }
504             // Found null command
505             if((MS_U32)(*pu32Data) == 0xFFFF0000)
506             {
507                 break;
508             }
509             // Found duplicated command
510             if((MS_U32)(*pu32Data) == u32Command)
511             {
512                 //SC_DBG(printf("Command duplicated\n"));
513 
514                 return;
515             }
516             u32OPAddr += MS_MLOAD_MEM_BASE_UNIT;
517             u8OPCount--;
518         }
519 
520         if((MS_U32)(*pu32Data) == 0xFFFF0000)
521         {
522             *pu32Data = u32Command;
523         }
524         else
525         {
526            printf("DS OP command buffer is full for this index %u!\n", pXCResourcePrivate->sthal_SC.u8DynamicScalingCurrentIndex[eWindow]);
527         }
528     //printf("@@[%s][%u]u16CmdRegAddr=%x, u16CmdRegValue=%x\n",__FUNCTION__, __LINE__, u16CmdRegAddr, u16CmdRegValue);
529     }
530 
531     else
532     {
533         // (OP : IP : Unused : Unused) (4 byte : 4 byte : 4 byte : 4 byte) if MIU 128bit
534         // (OPmain : IPmain : OPsub : IPsub) (4 byte : 4 byte : 4 byte : 4 byte) if MIU 128bit
535 
536         MS_PHY u32IPAddr = u32Addr + DS_OP_CMD_LEN;
537         MS_U32 *pu32Data = NULL;
538         MS_U8 u8IPCount = pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth;
539         //MS_U8 u8IPCount = IdxDepth;
540         MS_PHY u32Command = 0;
541 
542         u32Command = u16CmdRegValue + ((u32CmdRegAddr & 0x00FF) << 15) + ((u32CmdRegAddr & 0xFF00) << 16);
543 
544         while(u8IPCount > 0)
545         {
546             pu32Data = (MS_U32*)MsOS_PA2KSEG1(u32IPAddr);
547             if(0 == pu32Data)
548             {
549                 printf("%s :pu32Data = 0!,error!!!\n", __FUNCTION__);
550 
551                 assert(pu32Data != 0);
552             }
553             // Found null command
554             if((MS_U32)(*pu32Data) == 0xFFFF0000)
555             {
556                 break;
557             }
558             // Found duplicated command
559             if((MS_U32)(*pu32Data) == u32Command)
560             {
561                 return;
562             }
563             u32IPAddr += MS_MLOAD_MEM_BASE_UNIT;
564             u8IPCount--;
565         }
566 
567         if((MS_U32)(*pu32Data) == 0xFFFF0000)
568         {
569             *pu32Data = u32Command;
570         }
571         else
572         {
573            printf("DS IP command buffer is full for this index %u!\n", pXCResourcePrivate->sthal_SC.u8DynamicScalingCurrentIndex[eWindow]);
574         }
575     //printf("@@[%s][%u]u16CmdRegAddr=%x, u16CmdRegValue=%x\n",__FUNCTION__, __LINE__, u16CmdRegAddr, u16CmdRegValue);
576     }
577 #endif
578 }
579 
Hal_SC_Add_NullCommand(void * pInstance,SCALER_WIN eWindow,ds_reg_ip_op_sel IPOP_Sel,XC_DS_CMDCNT * pstXC_DS_CmdCnt)580 void Hal_SC_Add_NullCommand(void *pInstance,SCALER_WIN eWindow,ds_reg_ip_op_sel IPOP_Sel,XC_DS_CMDCNT *pstXC_DS_CmdCnt)
581 {
582     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
583     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
584     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
585     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
586 
587     MS_U16 u16MaxCmdCnt = pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth * 2; // It has two 64bit commands per MIU bus width
588     MS_U64 *pu64Data = NULL;
589     MS_U16 i;
590 
591     if(eWindow == MAIN_WINDOW)
592     {
593         if(IPOP_Sel == DS_IP)
594         {
595             for(i=pstXC_DS_CmdCnt->u16CMDCNT_IPM;i<u16MaxCmdCnt;i++)
596             {
597                 //Offset is u16MaxCmdCnt * 2 * one_ds_command_byte
598                 //because of depth * 2 = MaxCount, offset is depth * 4 (one depth can contain 4 ds commands (two of them are dummy command))
599                 MS_PHY u32IndexBase= (pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr +
600                     (MS_U32)pXCResourcePrivate->sthal_SC.u8DynamicScalingNextIndex[eWindow] * u16MaxCmdCnt * 2 * DS_CMD_LEN_64BITS +
601                     (i / 2) * BYTE_PER_WORD + (i % 2) * DS_CMD_LEN_64BITS);
602                 pu64Data  = (MS_U64*)MsOS_PA2KSEG1(u32IndexBase);
603                 *pu64Data = 0x00000009FFFF0000;
604             }
605         }
606         else
607         {
608             for(i=pstXC_DS_CmdCnt->u16CMDCNT_OPM;i<u16MaxCmdCnt;i++)
609             {
610                 MS_PHY u32IndexBase= (pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_OPM +
611                     (MS_U32)pXCResourcePrivate->sthal_SC.u8DynamicScalingNextIndex[eWindow] * u16MaxCmdCnt * 2 * DS_CMD_LEN_64BITS +
612                     (i / 2) * BYTE_PER_WORD + (i % 2) * DS_CMD_LEN_64BITS);
613                 pu64Data  = (MS_U64*)MsOS_PA2KSEG1(u32IndexBase);
614                 *pu64Data = 0x00000009FFFF0000;
615             }
616         }
617     }
618     else
619     {
620         if(IPOP_Sel == DS_IP)
621         {
622             for(i=pstXC_DS_CmdCnt->u16CMDCNT_IPS;i<u16MaxCmdCnt;i++)
623             {
624                 MS_PHY u32IndexBase= (pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_IPS +
625                     (MS_U32)pXCResourcePrivate->sthal_SC.u8DynamicScalingNextIndex[eWindow] * u16MaxCmdCnt * 2 * DS_CMD_LEN_64BITS +
626                     (i / 2) * BYTE_PER_WORD + (i % 2) * DS_CMD_LEN_64BITS);
627                 pu64Data  = (MS_U64*)MsOS_PA2KSEG1(u32IndexBase);
628                 *pu64Data = 0x00000009FFFF0000;
629             }
630         }
631         else
632         {
633             for(i=pstXC_DS_CmdCnt->u16CMDCNT_OPS;i<u16MaxCmdCnt;i++)
634             {
635                 MS_PHY u32IndexBase= (pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_OPS +
636                     (MS_U32)pXCResourcePrivate->sthal_SC.u8DynamicScalingNextIndex[eWindow] * u16MaxCmdCnt * 2 * DS_CMD_LEN_64BITS +
637                     (i / 2) * BYTE_PER_WORD + (i % 2) * DS_CMD_LEN_64BITS);
638                 pu64Data  = (MS_U64*)MsOS_PA2KSEG1(u32IndexBase);
639                 *pu64Data = 0x00000009FFFF0000;
640             }
641         }
642     }
643 }
644 
MHAL_SC_Set_DynamicScaling(void * pInstance,MS_PHY u32MemBaseAddr,MS_U8 u8MIU_Select,MS_U8 u8IdxDepth,MS_BOOL bOP_On,MS_BOOL bIPS_On,MS_BOOL bIPM_On,SCALER_WIN eWindow)645 MS_BOOL MHAL_SC_Set_DynamicScaling(void *pInstance,MS_PHY u32MemBaseAddr, MS_U8 u8MIU_Select, MS_U8 u8IdxDepth, MS_BOOL bOP_On, MS_BOOL bIPS_On, MS_BOOL bIPM_On,SCALER_WIN eWindow)
646 {
647     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
648     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
649     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
650     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
651     MS_U16 u16OnOff = 0;
652     MS_U16 u16MIU_Sel_bit1 = 0;
653 
654     XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] u8MIU_Select:%d  \n",__func__,__LINE__,u8MIU_Select);
655     XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] bOP_On:%d  bIPS_On:%d bIPM_On:%d  \n",__func__,__LINE__,bOP_On,bIPS_On,bIPM_On);
656 
657     // disable DS before modifying DS configuration
658     if (MDrv_XC_MLoad_GetStatus(pInstance) == E_MLOAD_ENABLED)
659     {
660         _MLOAD_ENTRY(pInstance);
661         MDrv_XC_MLoad_WriteCmd(pInstance, REG_SC_BK1F_10_L, 0, 0x0E00);
662         MDrv_XC_MLoad_Fire(pInstance, TRUE);
663         _MLOAD_RETURN(pInstance);
664     }
665     else
666     {
667         SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_10_L, 0, 0x0E00);
668     }
669 
670     // enable/disable
671     // we only memorize riu enable bit because mload and ds shares the same riu enable bit
672     u16OnOff = SC_R2BYTE(psXCInstPri->u32DeviceID, REG_SC_BK1F_10_L) & 0x1000;
673 
674     u16OnOff |= ((bOP_On << 9) | (bIPS_On << 10) | (bIPM_On << 11));
675 
676 #if ENABLE_DS_4_BASEADDR_MODE
677 
678 //===============================================================//
679 //  old 32bit command in DRAM  (per 16 Byte)
680 //  |-------------|-------------|-------------|-------------|
681 //  | DS_OP(main) | DS_IP(main) |  DS_OP(sub) |  DS_IP(sub) |
682 //  |-------------|-------------|-------------|-------------|
683 //  |   4 byte    |   4 byte    |   4 byte    |   4 byte    |
684 //  |-------------|-------------|-------------|-------------|
685 
686 //  new 64bit command in DRAM (per 16 Byte)
687 //  |---------------------------|---------------------------|
688 //  |        DS_IP(main)        |        DS_IP(main)        |
689 //  |---------------------------|---------------------------|
690 //  |          8 byte           |          8 byte           |
691 //  |---------------------------|---------------------------|
692 
693 // For example: IPM command
694 // For new 64bit command, it has two DS command per 16 byte.
695 // Therefore,u8DynamicScalingIndexDepth is divided 2 in this case.
696 //===============================================================//
697     pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth = u8IdxDepth / 2 / (MS_MLOAD_MEM_BASE_UNIT/MS_MLOAD_BUS_WIDTH);
698     pXCResourcePrivate->sthal_SC.u32DynamicScalingBufSize = BYTE_PER_WORD * u8IdxDepth * DS_MAX_INDEX;
699     //for FRC DS need enlarge DRAM size from 3K to 6K (After FW release CL#1342372)
700 
701     MS_U32 u32DSBufLen = pXCResourcePrivate->sthal_SC.u32DynamicScalingBufSize / 4;
702 
703     XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] u32DynamicScalingBufSize:%d u32DSBufLen:%d  \n",__func__,__LINE__,pXCResourcePrivate->sthal_SC.u32DynamicScalingBufSize,u32DSBufLen);
704 
705     if(eWindow == MAIN_WINDOW)
706     {
707         pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr = u32MemBaseAddr; //IPM
708         pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_OPM = u32MemBaseAddr + u32DSBufLen*2;
709         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);
710     }
711 
712     if(eWindow == SUB_WINDOW)
713     {
714         pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_IPS = u32MemBaseAddr + u32DSBufLen;
715         pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_OPS = u32MemBaseAddr + u32DSBufLen*3;
716         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);
717     }
718     Hal_XC_Enable_DS_4_Baseaddress_Mode(pInstance, TRUE);
719 #else
720     pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr = u32MemBaseAddr;
721     pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth = u8IdxDepth; //MaxDepth(IP/OP)
722     pXCResourcePrivate->sthal_SC.u32DynamicScalingBufSize = BYTE_PER_WORD * u8IdxDepth * DS_MAX_INDEX;
723 #endif
724 
725     XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW,"[%s,%5d] [DS] u32DynamicScalingBaseAddr:%x  u8DynamicScalingIndexDepth:%d u32DynamicScalingBufSize:%d   \n",__func__,__LINE__,(int)pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr,(int)pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth,pXCResourcePrivate->sthal_SC.u32DynamicScalingBufSize);
726 
727     //Befor DS On, Clean the DS memory
728     if(u16OnOff & 0x0E00)
729     {
730         if( (pXCResourcePrivate->stdrvXC_3D.ePreInputMode == E_XC_3D_INPUT_MODE_NONE) && (pXCResourcePrivate->stdrvXC_3D.ePreOutputMode == E_XC_3D_OUTPUT_MODE_NONE)
731         && (pXCResourcePrivate->stdrvXC_3D._eInput3DMode[MAIN_WINDOW] == E_XC_3D_INPUT_MODE_NONE) && (pXCResourcePrivate->stdrvXC_3D._eOutput3DMode == E_XC_3D_OUTPUT_MODE_NONE) ) //mantis:0740226
732         {
733             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);
734 
735             pXCResourcePrivate->sthal_SC.u8DynamicScalingCurrentIndex[eWindow] = 0;
736             pXCResourcePrivate->sthal_SC.u8DynamicScalingNextIndex[eWindow] = 0;
737             pXCResourcePrivate->sthal_SC.u8DynamicScalingCurrentIndex_Ring[eWindow] = 0;
738 
739 #if ENABLE_DS_4_BASEADDR_MODE
740             Hal_SC_ResetSWDSCommand(pInstance,eWindow,0);
741 #else
742             MS_U8 u8index = 0;
743 
744             for(u8index=0; u8index < DS_MAX_INDEX; u8index++)
745             {
746                 Hal_SC_ResetSWDSCommand(pInstance,eWindow, u8index);
747             }
748 #endif
749         }
750     }
751 
752     if(u16OnOff & 0x0E00)
753     {
754         // ENABLE DS
755         u16OnOff |= BIT(12);     // enable write register through RIU
756         pXCResourcePrivate->sthal_SC.bDynamicScalingEnable = TRUE;
757 
758         // currently, these 3 will use same MIU
759         u16OnOff |= ((u8MIU_Select & 0x01) << 13);                       // MIU select of OP
760         u16OnOff |= ((u8MIU_Select & 0x01) << 14);                       // MIU select of IPS
761         u16OnOff |= ((u8MIU_Select & 0x01) << 15);                       // MIU select of IPM
762 
763         u16MIU_Sel_bit1 |= ((u8MIU_Select & 0x02) << 12);                // MIU select of OP
764         u16MIU_Sel_bit1 |= ((u8MIU_Select & 0x02) << 13);                // MIU select of IPS
765         u16MIU_Sel_bit1 |= ((u8MIU_Select & 0x02) << 14);                // MIU select of IPM
766 
767         // patch IP1F2_21[15:14] r/w bank
768 
769         //if(pXCResourcePrivate->sthal_SC.sbOldValueReaded == FALSE)
770         //{
771         //	pXCResourcePrivate->sthal_SC.su16OldValue = SC_R2BYTE(psXCInstPri->u32DeviceID, REG_SC_BK01_21_L);
772         //	pXCResourcePrivate->sthal_SC.sbOldValueReaded = TRUE;
773         //}
774         //SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK01_21_L, 0x4000, 0xC000);
775 
776         Hal_XC_MLoad_set_opm_lock(pInstance, OPM_LOCK_DS);
777 
778         // ENABLE DS Read/Write Handshaking
779         SC_W2BYTEMSK(0, REG_SC_BK23_5F_L, 0x03, 0x03);
780     }
781     else
782     {
783         pXCResourcePrivate->sthal_SC.bDynamicScalingEnable = FALSE;
784         // DISABLE DS
785         //if(pXCResourcePrivate->sthal_SC.sbOldValueReaded)
786         //{
787         //    SC_W2BYTE(psXCInstPri->u32DeviceID, REG_SC_BK01_21_L, pXCResourcePrivate->sthal_SC.su16OldValue);
788         //    pXCResourcePrivate->sthal_SC.sbOldValueReaded = FALSE;
789         //}
790         Hal_XC_MLoad_set_opm_lock(pInstance, OPM_LOCK_INIT_STATE);
791         // DISABLE DS Read/Write Handshaking
792         SC_W2BYTEMSK(0, REG_SC_BK23_5F_L, 0x00, 0x03);
793     }
794 
795     // if disabled, need to set dynamic scaling ratio to 1:1
796     if(!bOP_On)
797     {
798         SC_W4BYTE(psXCInstPri->u32DeviceID, REG_SC_BK23_1C_L, 0x00100000);
799         SC_W4BYTE(psXCInstPri->u32DeviceID, REG_SC_BK23_1E_L, 0x00100000);
800     }
801 
802     if(u16OnOff & 0x0E00)
803     {
804         //for now, we do not need to change trigger point setting
805         Hal_XC_Set_DS_BaseAddress(pInstance,u32MemBaseAddr);
806         Hal_XC_Set_DS_IndexDepth(pInstance);
807         Hal_XC_Set_DS_MIU_Sel(pInstance,u16OnOff,u16MIU_Sel_bit1);
808 
809         // set DMA threthold, length, fixed value, no need to change
810         SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_10_L, 0x88, 0x00FF);
811 
812         // store
813         Hal_XC_MLoad_get_trig_p(pInstance, &pXCResourcePrivate->sthal_SC.u16OldValue[E_STORE_VALUE_AUTO_TUNE_AREA_TRIG], &pXCResourcePrivate->sthal_SC.u16OldValue[E_STORE_VALUE_DISP_AREA_TRIG]);
814         pXCResourcePrivate->sthal_SC.bTrig_pStored = TRUE;
815 
816         // set the trigger point from delayed line,  DS: 0x08, Train:0x14, Disp:0x18
817         //SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK20_21_L, 0x08, 0xFF);  // ds_trig_dly
818         //Hal_XC_MLoad_set_trig_p(pInstance, 0x14, 0x18);
819         //Hal_XC_MLoad_set_trig_p(pInstance, 0x0A, 0x18);
820 
821         //add
822         //SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK10_5D_L, 0x0828, 0xFFFF);
823 
824         // set trigger source to trigger
825         //SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK20_19_L, 0x08B8, 0x08BC);
826 
827         //set the delay line cnt to vfde end
828         //SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK20_19_L, BIT(6), BIT(6)|BIT(0));
829 
830 #if ENABLE_64BITS_COMMAND
831         Hal_XC_Enable_DS_64Bits_Command(pInstance,TRUE);
832         if(ENABLE_64BITS_SPREAD_MODE)
833         {
834             Hal_XC_Enable_DS_64Bits_Sread_Mode(pInstance,TRUE);
835         }
836         Hal_XC_Set_DS_64Bits_MIU_Bus_Sel(pInstance);
837 #endif
838     }
839 
840     // set DS in IPS[10],ipm[11] On/Off
841     if (MDrv_XC_MLoad_GetStatus(pInstance) == E_MLOAD_ENABLED)
842     {
843         _MLOAD_ENTRY(pInstance);
844         MDrv_XC_MLoad_WriteCmd(pInstance, REG_SC_BK1F_10_L, u16OnOff & 0x1D00, 0x1D00);
845         MDrv_XC_MLoad_WriteCmd(pInstance, REG_SC_BK1F_17_L, (bIPM_On)? 0x400 : 0x0, 0x400);
846         MDrv_XC_MLoad_WriteCmd(pInstance, REG_SC_BK1F_17_L, 0x10, 0x10);
847         MDrv_XC_MLoad_Fire(pInstance, TRUE);
848         _MLOAD_RETURN(pInstance);
849     }
850     else
851     {
852         SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_10_L, u16OnOff & 0x1D00, 0x1D00);
853         SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_17_L, (bIPM_On)? 0x400 : 0x0, 0x400);
854         SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_17_L, 0x10, 0x10);
855     }
856 
857     // set DS in OP[9] On/Off
858     if (MDrv_XC_MLoad_GetStatus(pInstance) == E_MLOAD_ENABLED)
859     {
860         _MLOAD_ENTRY(pInstance);
861         MDrv_XC_MLoad_WriteCmd(pInstance, REG_SC_BK1F_10_L, u16OnOff & 0x0200, 0x0200);
862         MDrv_XC_MLoad_Fire(pInstance, TRUE);
863         _MLOAD_RETURN(pInstance);
864     }
865     else
866     {
867         SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_10_L, u16OnOff & 0x0200, 0x0200);
868     }
869     // set mload timing
870     if(u16OnOff & 0x0E00)
871     {
872         SC_W2BYTE(0, REG_SC_BK20_19_L, 0x33F8);
873     }
874     else
875     {
876         SC_W2BYTE(0, REG_SC_BK20_19_L, 0x30F8);
877     }
878 
879     return TRUE;
880 }
881 
MHAL_SC_Set_DynamicScalingFlag(void * pInstance,MS_BOOL bEnable)882 void MHAL_SC_Set_DynamicScalingFlag(void *pInstance, MS_BOOL bEnable)
883 {
884     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
885     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
886     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
887     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
888     pXCResourcePrivate->sthal_SC.bDynamicScalingEnable = bEnable;
889 }
890 
MHAL_SC_Get_DynamicScaling_Status(void * pInstance)891 MS_BOOL MHAL_SC_Get_DynamicScaling_Status(void *pInstance)
892 {
893     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
894     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
895     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
896     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
897     return pXCResourcePrivate->sthal_SC.bDynamicScalingEnable;
898 }
899 
MHAL_SC_Enable_IPMTuneAfterDS(void * pInstance,MS_BOOL bEnable)900 MS_BOOL MHAL_SC_Enable_IPMTuneAfterDS(void *pInstance, MS_BOOL bEnable)
901 {
902     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
903     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
904 
905     // ENABLE IPM TUNE AFTER DS
906     SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK12_06_L, BIT(7), BIT(7));
907 
908     // Clear DS active pulse every vsync
909     SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_17_L, BIT(6), BIT(6));
910 
911     //
912     SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_17_L, BIT(14), BIT(14));
913     return TRUE;
914 }
915 
MHal_SC_DynamicScaling_SWReset(void * pInstance)916 void MHal_SC_DynamicScaling_SWReset(void *pInstance)
917 {
918     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
919     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
920 
921     SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_13_L, 0x400, 0x400);
922     SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_13_L, 0x800, 0x800);
923     SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_13_L, 0x1000, 0x1000);
924 
925     SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_13_L, 0x0, 0x1000);
926     SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_13_L, 0x0, 0x800);
927     SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_13_L, 0x0, 0x400);
928 }
929 
MHal_XC_Get_DSForceIndexSupported(void * pInstance,SCALER_WIN eWindow)930 MS_BOOL MHal_XC_Get_DSForceIndexSupported(void *pInstance, SCALER_WIN eWindow)
931 {
932     if (eWindow >= MAX_WINDOW)
933     {
934         printf("[%s,%5d] maximum window exceeded",__FUNCTION__,__LINE__);
935         return FALSE;
936     }
937 
938     return TRUE;
939 }
940 
MHal_XC_Set_DSForceIndex(void * pInstance,MS_BOOL bEnable,MS_U8 u8Index,SCALER_WIN eWindow)941 void MHal_XC_Set_DSForceIndex(void *pInstance, MS_BOOL bEnable, MS_U8 u8Index, SCALER_WIN eWindow)
942 {
943     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
944     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
945     if (eWindow >= MAX_WINDOW)
946     {
947         printf("[%s,%5d] maximum window exceeded",__FUNCTION__,__LINE__);
948         return;
949     }
950 
951     if (eWindow == MAIN_WINDOW)
952     {
953         // reg_idxg_force_en
954         SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_77_L, bEnable?BIT(0):0 , BIT(0));
955         // reg_idxg_force_en
956         SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_77_L, bEnable?BIT(2):0 , BIT(2));
957         // reg_idxg_force_idx_f2
958         SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_76_L, (MS_U16)u8Index << 8 , 0xFF00);
959     }
960     else // eWindow == SUB_WINDOW
961     {
962         // reg_idxg_force_en
963         SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_77_L, bEnable?BIT(8):0 , BIT(8));
964 
965         SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_77_L, bEnable?BIT(10):0 , BIT(10));
966         // reg_idxg_force_idx_f1
967         SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_75_L, (MS_U16)u8Index << 8 , 0xFF00);
968     }
969 }
970 
MHal_XC_Set_DSIndexSourceSelect(void * pInstance,E_XC_DS_INDEX_SOURCE eDSIdxSrc,SCALER_WIN eWindow)971 void MHal_XC_Set_DSIndexSourceSelect(void *pInstance, E_XC_DS_INDEX_SOURCE eDSIdxSrc, SCALER_WIN eWindow)
972 {
973     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
974     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
975     if (eWindow >= MAX_WINDOW)
976     {
977         printf("[%s,%5d] maximum window exceeded",__FUNCTION__,__LINE__);
978         return;
979     }
980 
981     if (eDSIdxSrc >= E_XC_DS_INDEX_MAX)
982     {
983         printf("[%s,%5d] Maximum index exceeded, the index is (%d)\n",__FUNCTION__,__LINE__,eDSIdxSrc);
984         return;
985     }
986 
987     if(eWindow == MAIN_WINDOW)
988     {
989         // reg_idxg_en_f2
990         SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_77_L, eDSIdxSrc, BIT(0));
991     }
992     else
993     {
994         // reg_idxg_en_f1
995         SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_77_L, eDSIdxSrc << 8, BIT(8));
996     }
997 }
998 
Hal_XC_Enable_DS_64Bits_Command(void * pInstance,MS_BOOL bEn)999 void Hal_XC_Enable_DS_64Bits_Command(void *pInstance,MS_BOOL bEn)
1000 {
1001     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1002     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1003 
1004     SC_W2BYTEMSK(psXCInstPri->u32DeviceID,REG_SC_BK1F_70_L, bEn?BIT(0):0x00, BIT(0));
1005 }
1006 
Hal_XC_Enable_DS_64Bits_Sread_Mode(void * pInstance,MS_BOOL bEn)1007 void Hal_XC_Enable_DS_64Bits_Sread_Mode(void *pInstance,MS_BOOL bEn)
1008 {
1009     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1010     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1011 
1012     SC_W2BYTEMSK(psXCInstPri->u32DeviceID,REG_SC_BK1F_70_L, bEn?BIT(15):0x00, BIT(15));
1013 }
1014 
Hal_XC_Enable_DS_4_Baseaddress_Mode(void * pInstance,MS_BOOL bEn)1015 void Hal_XC_Enable_DS_4_Baseaddress_Mode(void *pInstance,MS_BOOL bEn)
1016 {
1017     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1018     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1019 
1020     SC_W2BYTEMSK(psXCInstPri->u32DeviceID,REG_SC_BK1F_17_L, bEn?BIT(7):0x00, BIT(7));
1021 }
1022 
Hal_XC_Set_DS_64Bits_MIU_Bus_Sel(void * pInstance)1023 void Hal_XC_Set_DS_64Bits_MIU_Bus_Sel(void *pInstance)
1024 {
1025     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1026     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1027 
1028     MS_U16 u16sel = 0x00;
1029 
1030     if( MS_MLOAD_BUS_WIDTH == 8 )
1031     {
1032         u16sel = 0x00;
1033     }
1034     else if( MS_MLOAD_BUS_WIDTH == 16 )
1035     {
1036         u16sel = 0x01;
1037     }
1038     else if( MS_MLOAD_BUS_WIDTH == 32 )
1039     {
1040         u16sel = 0x3;
1041     }
1042     else
1043     {
1044         printf("MIU Bus not support !!!!!!!!!!!!!!!!!\n");
1045         u16sel = 0x00;
1046     }
1047 
1048     u16sel = (u16sel & 0x0003)<<14;
1049     SC_W2BYTEMSK(psXCInstPri->u32DeviceID,REG_SC_BK1F_13_L, u16sel, 0xC000);
1050 }
1051 
Hal_XC_Set_DS_BaseAddress(void * pInstance,MS_PHY u32Base)1052 void Hal_XC_Set_DS_BaseAddress(void *pInstance,MS_PHY u32Base)
1053 {
1054     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1055     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1056     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
1057     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
1058 
1059     if( u32Base > HAL_MIU1_BASE)
1060     {
1061         u32Base = u32Base - HAL_MIU1_BASE;
1062     }
1063     u32Base = u32Base/MS_MLOAD_MEM_BASE_UNIT;
1064 
1065     #if ENABLE_DS_4_BASEADDR_MODE
1066             // set IPM
1067             SC_W2BYTE(psXCInstPri->u32DeviceID, REG_SC_BK1F_11_L, u32Base & 0xFFFF);
1068             SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_12_L, (u32Base >> 16),0x03FF);
1069 
1070             //set OPM
1071             SC_W2BYTE(psXCInstPri->u32DeviceID, REG_SC_BK1F_0E_L, (pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_OPM / MS_MLOAD_MEM_BASE_UNIT) & 0xFFFF);
1072             SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_0F_L, ((pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_OPM / MS_MLOAD_MEM_BASE_UNIT) >> 16),0x03FF);
1073 
1074             //set IPS
1075             SC_W2BYTE(psXCInstPri->u32DeviceID, REG_SC_BK1F_0C_L, (pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_IPS / MS_MLOAD_MEM_BASE_UNIT) & 0xFFFF);
1076             SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_0D_L, ((pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_IPS / MS_MLOAD_MEM_BASE_UNIT) >> 16),0x03FF);
1077 
1078             //set OPS
1079             SC_W2BYTE(psXCInstPri->u32DeviceID, REG_SC_BK1F_60_L, (pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_OPS / MS_MLOAD_MEM_BASE_UNIT) & 0xFFFF);
1080             SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_61_L, ((pXCResourcePrivate->sthal_SC.u32DynamicScalingBaseAddr_OPS / MS_MLOAD_MEM_BASE_UNIT) >> 16),0x03FF);
1081     #else
1082             // set DS base address
1083             SC_W2BYTE(psXCInstPri->u32DeviceID, REG_SC_BK1F_11_L, u32Base & 0xFFFF);
1084             SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_12_L, (u32Base >> 16),0x03FF);
1085     #endif
1086 
1087 }
1088 
Hal_XC_Set_DS_IndexDepth(void * pInstance)1089 void Hal_XC_Set_DS_IndexDepth(void *pInstance)
1090 {
1091     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1092     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1093     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
1094     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
1095 
1096     SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_13_L, pXCResourcePrivate->sthal_SC.u8DynamicScalingIndexDepth , 0x00FF);
1097 }
1098 
Hal_XC_Set_DS_MIU_Sel(void * pInstance,MS_U16 u16DSOnOff,MS_U16 u16DS_MIU_Sel_bit1)1099 void Hal_XC_Set_DS_MIU_Sel(void *pInstance,MS_U16 u16DSOnOff,MS_U16 u16DS_MIU_Sel_bit1)
1100 {
1101     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
1102     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
1103 
1104     SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_10_L, u16DSOnOff & 0xE000, 0xE000);
1105     SC_W2BYTEMSK(psXCInstPri->u32DeviceID, REG_SC_BK1F_71_L, u16DS_MIU_Sel_bit1 & 0xE000, 0xE000);
1106 }
1107 
1108 #endif // MHAL_DYNAMICSCALING_C
1109