xref: /utopia/UTPA2-700.0.x/modules/xc/drv/xc/mdrv_sc_pip.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") 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 // [mhal_sc.c]
96 // Date: 20081203
97 // Descriptions: Add a new layer for HW setting
98 //==============================================================================
99 #define  MDRV_PIP_C
100 
101 #include "mhal_xc_chip_config.h"
102 #include "xc_hwreg_utility2.h"
103 #include "utopia.h"
104 #include "utopia_dapi.h"
105 
106 #include "drvXC_IOPort.h"
107 #include "apiXC.h"
108 #include "apiXC_Adc.h"
109 #include "apiXC_Auto.h"
110 #include "drv_sc_display.h"
111 #include "drv_sc_isr.h"
112 #include "apiXC_PCMonitor.h"
113 #include "apiXC_ModeParse.h"
114 #include "drvXC_HDMI_if.h"
115 #include "mvideo_context.h"
116 #include "drv_sc_ip.h"
117 #if (LD_ENABLE==1)
118 #include "mdrv_ld.h"
119 #include "mdrv_ldalgo.h"
120 #endif
121 #include "mdrv_sc_3d.h"
122 #include "drv_sc_menuload.h"
123 #include "drvXC_ADC_Internal.h"
124 #include "mhal_sc.h"
125 #if FRC_INSIDE
126 #include "mdrv_frc.h"
127 #include "mhal_frc.h"
128 #endif
129 #include "XC_private.h"
130 #include "apiXC_v2.h"
131 #include "mhal_pip.h"
132 #include "mdrv_sc_3d.h"
133 #include "drv_sc_scaling.h"
134 
135 #ifndef UNUSED
136 #define UNUSED(x) ((x)=(x))
137 #endif
138 
MDrv_XC_SetMWEStatus(void * pInstance,MS_BOOL bMWEStatus)139 void MDrv_XC_SetMWEStatus(void *pInstance, MS_BOOL bMWEStatus)
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     pXCResourcePrivate->bXCMWEStatus = bMWEStatus;
146 }
147 
MDrv_XC_GetMWEStatus(void * pInstance)148 MS_BOOL MDrv_XC_GetMWEStatus(void *pInstance)
149 {
150     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
151     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
152     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
153     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
154 
155     return pXCResourcePrivate->bXCMWEStatus;
156 }
157 //-------------------------------------------------------------------------------------------------
158 /// Control the output window(Main/Sub) on or off, no mutex protect
159 /// @param  bEnable                \b IN: bEnable =1, Turn on the window; bEnable =0, Turn off the window
160 /// @param  eWindow              \b IN: eWindow =0, for MAIN; eWindow =1, for SUB;
161 //-------------------------------------------------------------------------------------------------
MDrv_XC_EnableWindow(void * pInstance,MS_BOOL bEnable,SCALER_WIN eWindow)162 void MDrv_XC_EnableWindow(void *pInstance, MS_BOOL bEnable, SCALER_WIN eWindow)
163 {
164 #ifdef MSOS_TYPE_LINUX_KERNEL
165     /*
166     ** Save setwindow info for str
167     */
168     void *pModule;
169     UtopiaInstanceGetModule(pInstance, &pModule);
170     XC_REGS_SAVE_AREA *pXCResourceStr = NULL;
171     UtopiaModuleGetSTRPrivate(pModule, (void**)&pXCResourceStr);
172     pXCResourceStr->bPIP_enable = TRUE;
173 #endif
174 #if (HW_DESIGN_4K2K_VER < 4)
175 #if(HW_DESIGN_4K2K_VER !=7)
176     MS_WINDOW_TYPE stDispWin;
177 #endif
178 #endif
179     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
180     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
181     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
182     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
183 
184 #if (HW_DESIGN_4K2K_VER < 4)
185 #if(HW_DESIGN_4K2K_VER !=7)
186     if((eWindow == SUB_WINDOW) && (bEnable == FALSE))
187     {
188         stDispWin.x = pXCResourcePrivate->stdrvXC_MVideo_Context.g_XC_InitData.stPanelInfo.u16HStart;
189         stDispWin.width   = pXCResourcePrivate->stdrvXC_MVideo_Context.g_XC_InitData.stPanelInfo.u16Width - 1;
190         stDispWin.y = pXCResourcePrivate->stdrvXC_MVideo_Context.g_XC_InitData.stPanelInfo.u16VStart;
191         stDispWin.height   = pXCResourcePrivate->stdrvXC_MVideo_Context.g_XC_InitData.stPanelInfo.u16Height - 1;
192         printf("(x,y,w.h)=(%d,%d,%d,%d)\n", stDispWin.x, stDispWin.y, stDispWin.width, stDispWin.height);
193         if (MDrv_XC_MLoad_GetStatus(pInstance) == E_MLOAD_ENABLED)
194         {
195             Hal_SC_Sub_SetDisplayWindow_burst(pInstance, &stDispWin);
196 
197             //this part was originally inside Hal_SC_Sub_SetDisplayWindow_burst(), it is moved out because
198             //if we let REG_SC_BK20_10_L[1] to enable with other register settings in the same menuload fire
199             //it will produce a rectangular horizontal noise. so we move outside to let those register settings
200             //to be set first then let REG_SC_BK20_10_L[1] on.
201 
202             //MDrv_XC_MLoad_WriteCmd(pInstance, REG_SC_BK20_10_L, (TRUE<<1), BIT(1));
203             //MDrv_XC_MLoad_Fire(pInstance, TRUE);
204         }
205         else
206         {
207             MDrv_XC_wait_output_vsync(pInstance, 2, 200, MAIN_WINDOW);
208             Hal_SC_Sub_SetDisplayWindow(pInstance, &stDispWin);
209         }
210     }
211 #endif
212 #endif
213 
214 #ifdef CONFIG_MSTAR_SRAMPD
215         if (bEnable)
216         {
217             Hal_SC_Sub_SRAM_PowerDown_Control(pInstance,bEnable);
218         }
219 #endif
220 
221     if (MDrv_XC_MLoad_GetStatus(pInstance) == E_MLOAD_ENABLED)
222     {
223         Hal_SC_enable_window_burst(pInstance, bEnable, eWindow);
224     }
225     else
226     {
227         MDrv_XC_wait_output_vsync(pInstance, 2, 200, eWindow);
228         Hal_SC_enable_window(pInstance, bEnable, eWindow);
229     }
230 
231 #ifdef CONFIG_MSTAR_SRAMPD
232     if (!bEnable)
233     {
234         Hal_SC_Sub_SRAM_PowerDown_Control(pInstance,bEnable);
235     }
236 #endif
237 
238 #if(HW_DESIGN_4K2K_VER !=7)
239     if((!bEnable) && (eWindow == SUB_WINDOW))
240     {
241         MDrv_XC_init_fbn_win(pInstance, eWindow);
242     }
243 #endif
244 }
245 
246 //-------------------------------------------------------------------------------------------------
247 /// Control the output window(Main/Sub) on or off, for api with mutex protect
248 /// @param  bEnable                \b IN: bEnable =1, Turn on the window; bEnable =0, Turn off the window
249 /// @param  eWindow              \b IN: eWindow =0, for MAIN; eWindow =1, for SUB;
250 //-------------------------------------------------------------------------------------------------
MApi_XC_EnableWindow_U2(void * pInstance,MS_BOOL bEnable,SCALER_WIN eWindow)251 void MApi_XC_EnableWindow_U2(void* pInstance, MS_BOOL bEnable, SCALER_WIN eWindow)
252 {
253     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
254     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
255     _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR);
256     _XC_ENTRY(pInstance);
257     MDrv_XC_EnableWindow(pInstance, bEnable, eWindow);
258     _XC_RETURN(pInstance);
259     _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
260 }
261 
MApi_XC_EnableWindow(MS_BOOL bEnable,SCALER_WIN eWindow)262 void MApi_XC_EnableWindow(MS_BOOL bEnable, SCALER_WIN eWindow)
263 {
264     if (pu32XCInst == NULL)
265     {
266         printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
267         return;
268     }
269 
270     stXC_SET_WINDOW_ENABLE XCArgs;
271     XCArgs.bEnable = bEnable;
272     XCArgs.eWindow = eWindow;
273 
274     if(UtopiaIoctl(pu32XCInst, E_XC_CMD_SET_WINDOW_ENABLE, (void*)&XCArgs) != UTOPIA_STATUS_SUCCESS)
275     {
276         printf("Obtain XC engine fail\n");
277         return;
278     }
279     else
280     {
281         return;
282     }
283 }
284 
285 //-------------------------------------------------------------------------------------------------
286 /// Control the main window on or off
287 /// @param  bEnable                \b IN: bEnable =1, Turn on the window; bEnable =0, Turn off the window
288 //-------------------------------------------------------------------------------------------------
MApi_XC_EnableMainWindow_U2(void * pInstance,MS_BOOL bEnable)289 void MApi_XC_EnableMainWindow_U2(void* pInstance, MS_BOOL bEnable)
290 {
291     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
292     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
293     _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR);
294     _XC_ENTRY(pInstance);
295     MDrv_XC_EnableWindow(pInstance, bEnable, MAIN_WINDOW);
296     _XC_RETURN(pInstance);
297     _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
298 }
299 
MApi_XC_EnableMainWindow(MS_BOOL bEnable)300 void MApi_XC_EnableMainWindow(MS_BOOL bEnable)
301 {
302     if (pu32XCInst == NULL)
303     {
304         printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
305         return;
306     }
307 
308     stXC_SET_MAINWINDOW_ENABLE XCArgs;
309     XCArgs.bEnable = bEnable;
310 
311     if(UtopiaIoctl(pu32XCInst, E_XC_CMD_SET_MAINWINDOW_ENABLE, (void*)&XCArgs) != UTOPIA_STATUS_SUCCESS)
312     {
313         printf("Obtain XC engine fail\n");
314         return;
315     }
316     else
317     {
318         return;
319     }
320 }
321 
322 //-------------------------------------------------------------------------------------------------
323 /// Enable sub window and control the window size
324 /// @param  *pstDispWin                \b IN: Window type
325 //-------------------------------------------------------------------------------------------------
MApi_XC_EnableSubWindow_U2(void * pInstance,MS_WINDOW_TYPE * pstDispWin)326 void MApi_XC_EnableSubWindow_U2(void* pInstance, MS_WINDOW_TYPE *pstDispWin)
327 {
328 #ifndef DISABLE_PIP_FUNCTION
329     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
330     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
331     _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR);
332     XC_RESOURCE_PRIVATE* pXCResourcePrivate = NULL;
333     MS_WINDOW_TYPE stDispWin;
334     UtopiaResourceGetPrivate(g_pXCResource[_XC_SELECT_INTERNAL_VARIABLE(psXCInstPri->u32DeviceID)],(void**)(&pXCResourcePrivate));
335 
336     _XC_ENTRY(pInstance);
337 #if PIP_PATCH_USING_SC1_MAIN_AS_SC0_SUB
338     if((MDrv_XC_GetMWEStatus(pInstance) && IsVMirrorMode(SUB_WINDOW)) || (!MDrv_XC_GetMWEStatus(pInstance) && IsVMirrorMode(MAIN_WINDOW)))
339 #else
340     if(IsVMirrorMode(SUB_WINDOW))
341 #endif
342     {
343         if( pXCResourcePrivate->stdrvXC_MVideo_Context.g_XC_InitData.stPanelInfo.u16Width > ( pstDispWin->x + pstDispWin->width ) )
344         {
345             pstDispWin->x = pXCResourcePrivate->stdrvXC_MVideo_Context.g_XC_InitData.stPanelInfo.u16Width - ( pstDispWin->x + pstDispWin->width );
346         }
347         else
348         {
349             pstDispWin->x = 0;
350         }
351 
352         if( pXCResourcePrivate->stdrvXC_MVideo_Context.g_XC_InitData.stPanelInfo.u16Height > ( pstDispWin->y + pstDispWin->height ) )
353         {
354             pstDispWin->y = pXCResourcePrivate->stdrvXC_MVideo_Context.g_XC_InitData.stPanelInfo.u16Height - ( pstDispWin->y + pstDispWin->height );
355         }
356         else
357         {
358             pstDispWin->y = 0;
359         }
360     }
361 
362     stDispWin.x = pstDispWin->x;
363     stDispWin.y = pstDispWin->y;
364     stDispWin.width = pstDispWin->width;
365     stDispWin.height = pstDispWin->height;
366 
367     if(MDrv_XC_Is2K2KToFrc(pInstance))
368     {
369         stDispWin.x = stDispWin.x/2;
370         stDispWin.width = stDispWin.width/2;
371     }
372 
373 
374     XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW, "%s %d: Disp x=%u,y=%u,width=%u,height=%u\n", __FUNCTION__, __LINE__, stDispWin.x,stDispWin.y,stDispWin.width,stDispWin.height);
375 
376     stDispWin.x += pXCResourcePrivate->stdrvXC_MVideo_Context.g_XC_InitData.stPanelInfo.u16HStart;
377     stDispWin.y += pXCResourcePrivate->stdrvXC_MVideo_Context.g_XC_InitData.stPanelInfo.u16VStart;
378 
379     if (MDrv_XC_MLoad_GetStatus(pInstance) == E_MLOAD_ENABLED)
380     {
381         Hal_SC_Sub_SetDisplayWindow_burst(pInstance, &stDispWin);
382 
383         //this part was originally inside Hal_SC_Sub_SetDisplayWindow_burst(), it is moved out because
384         //if we let REG_SC_BK20_10_L[1] to enable with other register settings in the same menuload fire
385         //it will produce a rectangular horizontal noise. so we move outside to let those register settings
386         //to be set first then let REG_SC_BK20_10_L[1] on.
387 
388         //MDrv_XC_MLoad_WriteCmd(pInstance, REG_SC_BK20_10_L, (TRUE<<1), BIT(1));
389         //MDrv_XC_MLoad_Fire(pInstance, TRUE);
390     }
391     else
392     {
393         MDrv_XC_wait_output_vsync(pInstance, 2, 200, MAIN_WINDOW);
394         Hal_SC_Sub_SetDisplayWindow(pInstance, &stDispWin);
395     }
396     MDrv_XC_EnableCLK_for_SUB(pInstance,TRUE);
397 #if (PIP_PATCH_USING_SC1_MAIN_AS_SC0_SUB == 0)
398     MDrv_XC_EnableWindow(pInstance, TRUE,SUB_WINDOW);
399 #else
400     if(MDrv_XC_GetMWEStatus(pInstance))
401     {
402         MDrv_XC_EnableWindow(pInstance, TRUE,SUB_WINDOW);
403     }
404     else
405     {
406         MDrv_XC_EnableWindow(pInstance, TRUE,MAIN_WINDOW);
407     }
408 #endif
409     _XC_RETURN(pInstance);
410     _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
411 #else
412     UNUSED(pstDispWin);
413 #endif
414 }
415 
MApi_XC_EnableSubWindow(MS_WINDOW_TYPE * pstDispWin)416 void MApi_XC_EnableSubWindow(MS_WINDOW_TYPE *pstDispWin)
417 {
418     if (pu32XCInst == NULL)
419     {
420         printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
421         return;
422     }
423 
424     stXC_SET_SUBWINDOW_ENABLE XCArgs;
425     XCArgs.pstDispWin = pstDispWin;
426 
427     if(UtopiaIoctl(pu32XCInst, E_XC_CMD_SET_SUBWINDOW_ENABLE, (void*)&XCArgs) != UTOPIA_STATUS_SUCCESS)
428     {
429         printf("Obtain XC engine fail\n");
430         return;
431     }
432     else
433     {
434         return;
435     }
436 }
437 
438 //-------------------------------------------------------------------------------------------------
439 /// Disable sub window
440 /// @param  void                \b IN: none
441 //-------------------------------------------------------------------------------------------------
MApi_XC_DisableSubWindow_U2(void * pInstance)442 void MApi_XC_DisableSubWindow_U2(void* pInstance)
443 {
444 #ifndef DISABLE_PIP_FUNCTION
445     _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR);
446     _XC_ENTRY(pInstance);
447 #if (PIP_PATCH_USING_SC1_MAIN_AS_SC0_SUB == 0)
448     MDrv_XC_EnableWindow(pInstance, FALSE, SUB_WINDOW);
449 #else
450     if(!MDrv_XC_GetMWEStatus(pInstance))
451     {
452         MDrv_XC_EnableWindow(pInstance, FALSE, MAIN_WINDOW);
453     }
454     else
455     {
456         MDrv_XC_EnableWindow(pInstance, FALSE, SUB_WINDOW);
457     }
458 #endif
459     // For 3D case: When Sub Window is disabled, the CLK for sub also need to turn off
460     MDrv_XC_EnableCLK_for_SUB(pInstance, FALSE);
461 
462     _XC_RETURN(pInstance);
463     _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
464 #endif
465 }
466 
MApi_XC_DisableSubWindow(void)467 void MApi_XC_DisableSubWindow(void)
468 {
469     if (pu32XCInst == NULL)
470     {
471         printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
472         return;
473     }
474 
475     if(UtopiaIoctl(pu32XCInst, E_XC_CMD_SET_SUBWINDOW_DISABLE, NULL) != UTOPIA_STATUS_SUCCESS)
476     {
477         printf("Obtain XC engine fail\n");
478         return;
479     }
480     else
481     {
482         return;
483     }
484 }
485 
486 //-------------------------------------------------------------------------------------------------
487 /// Is sub window enable?
488 /// @return @ref MS_BOOL
489 //-------------------------------------------------------------------------------------------------
MApi_XC_Is_SubWindowEanble_U2(void * pInstance)490 MS_BOOL MApi_XC_Is_SubWindowEanble_U2(void* pInstance)
491 {
492     MS_BOOL bRet = FALSE;
493 #ifndef DISABLE_PIP_FUNCTION
494     _XC_ENTRY(pInstance);
495      bRet = MDrv_XC_Is_SubWindowEanble(pInstance);
496     _XC_RETURN(pInstance);
497 #endif
498     return bRet;
499 }
500 
MApi_XC_Is_SubWindowEanble(void)501 MS_BOOL MApi_XC_Is_SubWindowEanble(void)
502 {
503     if (pu32XCInst == NULL)
504     {
505         printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
506         return FALSE;
507     }
508 
509     stXC_CHECK_SUBWINDOW_ENABLE XCArgs;
510     XCArgs.bReturnValue = FALSE;
511 
512     if(UtopiaIoctl(pu32XCInst, E_XC_CMD_CHECK_SUBWINDOW_ENABLE, (void*)&XCArgs) != UTOPIA_STATUS_SUCCESS)
513     {
514         printf("Obtain XC engine fail\n");
515         return FALSE;
516     }
517     else
518     {
519         return XCArgs.bReturnValue;
520     }
521 }
522 
523 //-------------------------------------------------------------------------------------------------
524 /// Set Border format
525 /// @param  u8WidthIn                \b IN: In-box width
526 /// @param  u8WidthOut               \b IN: Out-box width
527 /// @param  u8color                  \b IN: border color
528 /// @param  eWindow                  \b IN: which window we are going to set
529 //-------------------------------------------------------------------------------------------------
MApi_XC_SetBorderFormat_U2(void * pInstance,MS_U8 u8Left,MS_U8 u8Right,MS_U8 u8Up,MS_U8 u8Down,MS_U8 u8color,SCALER_WIN eWindow)530 void MApi_XC_SetBorderFormat_U2( void* pInstance, MS_U8 u8Left, MS_U8 u8Right, MS_U8 u8Up, MS_U8 u8Down, MS_U8 u8color, SCALER_WIN eWindow )
531 {
532 #ifndef DISABLE_PIP_FUNCTION
533 
534     _XC_ENTRY(pInstance);
535     Hal_SC_set_border_format(pInstance, u8Left, u8Right, u8Up, u8Down, u8color, eWindow );
536     _XC_RETURN(pInstance);
537 #else
538     UNUSED(u8Left);
539     UNUSED(u8Right);
540     UNUSED(u8Up);
541     UNUSED(u8Down);
542     UNUSED(u8color);
543     UNUSED(eWindow);
544 #endif
545 }
546 
MApi_XC_SetBorderFormat(MS_U8 u8Left,MS_U8 u8Right,MS_U8 u8Up,MS_U8 u8Down,MS_U8 u8color,SCALER_WIN eWindow)547 void MApi_XC_SetBorderFormat( MS_U8 u8Left, MS_U8 u8Right, MS_U8 u8Up, MS_U8 u8Down, MS_U8 u8color, SCALER_WIN eWindow )
548 {
549     if (pu32XCInst == NULL)
550     {
551         printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
552         return;
553     }
554 
555     stXC_SET_BORDER_FORMAT XCArgs;
556     XCArgs.u8Left = u8Left;
557     XCArgs.u8Right = u8Right;
558     XCArgs.u8Up = u8Up;
559     XCArgs.u8Down = u8Down;
560     XCArgs.u8color = u8color;
561     XCArgs.eWindow = eWindow;
562 
563     if(UtopiaIoctl(pu32XCInst, E_XC_CMD_SET_BORDER_FORMAT, (void*)&XCArgs) != UTOPIA_STATUS_SUCCESS)
564     {
565         printf("Obtain XC engine fail\n");
566         return;
567     }
568     else
569     {
570         return;
571     }
572 }
573 
574 //-------------------------------------------------------------------------------------------------
575 /// enable or disable Border
576 /// @param  bEnable                  \b IN: Enable or Disable
577 /// @param  eWindow                  \b IN: which window we are going to set
578 //-------------------------------------------------------------------------------------------------
MApi_XC_EnableBorder_U2(void * pInstance,MS_BOOL bEnable,SCALER_WIN eWindow)579 void MApi_XC_EnableBorder_U2( void* pInstance, MS_BOOL bEnable, SCALER_WIN eWindow )
580 {
581 #ifndef DISABLE_PIP_FUNCTION
582 
583     _XC_ENTRY(pInstance);
584     Hal_SC_border_enable(pInstance, bEnable, eWindow);
585     _XC_RETURN(pInstance);
586 #else
587     UNUSED(bEnable);
588     UNUSED(eWindow);
589 #endif
590 }
591 
MApi_XC_EnableBorder(MS_BOOL bEnable,SCALER_WIN eWindow)592 void MApi_XC_EnableBorder( MS_BOOL bEnable, SCALER_WIN eWindow )
593 {
594     if (pu32XCInst == NULL)
595     {
596         printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
597         return;
598     }
599 
600     stXC_SET_BORDER_ENABLE XCArgs;
601     XCArgs.bEnable = bEnable;
602     XCArgs.eWindow = eWindow;
603 
604     if(UtopiaIoctl(pu32XCInst, E_XC_CMD_SET_BORDER_ENABLE, (void*)&XCArgs) != UTOPIA_STATUS_SUCCESS)
605     {
606         printf("Obtain XC engine fail\n");
607         return;
608     }
609     else
610     {
611         return;
612     }
613 }
614 
615 //-------------------------------------------------------------------------------------------------
616 /// Set Z-order main window first or not
617 /// @param  bMainFirst               \b IN: TRUE: Main window first; FALSE: Sub window first
618 //-------------------------------------------------------------------------------------------------
MApi_XC_ZorderMainWindowFirst_U2(void * pInstance,MS_BOOL bMainFirst)619 void MApi_XC_ZorderMainWindowFirst_U2(void* pInstance, MS_BOOL bMainFirst)
620 {
621 #ifndef DISABLE_PIP_FUNCTION
622 
623     MS_XC_DST_DispInfo stBottomWin;
624     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
625     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
626     _XC_SEMAPHORE_ENTRY(pInstance,E_XC_ID_VAR);
627     _XC_ENTRY(pInstance);
628     // Get bottom window info.
629     MApi_XC_GetDstInfo_IP1(pInstance, &stBottomWin, sizeof(MS_XC_DST_DispInfo), bMainFirst ? SUB_WINDOW : MAIN_WINDOW);
630 
631     if (MDrv_XC_MLoad_GetStatus(pInstance) == E_MLOAD_ENABLED)
632     {
633         Hal_SC_set_Zorder_main_first_burst(pInstance, bMainFirst);
634         Hal_SC_set_Zextra_y_half_burst(pInstance, stBottomWin.bInterlaceMode);
635         //printf("shawn (1) MApi_XC_ZorderMainWindowFirst(bMainTop(%d)) \r\n", bMainFirst);
636     }
637     else
638     {
639         Hal_SC_set_Zorder_main_first(pInstance, bMainFirst);
640         Hal_SC_set_Zextra_y_half(pInstance, stBottomWin.bInterlaceMode);
641         //printf("shawn (2) MApi_XC_ZorderMainWindowFirst(bMainTop(%d)) \r\n", bMainFirst);
642     }
643 
644     //Fill the line buffer in vertical blanking for the window on top
645     if(bMainFirst)
646     {
647         MDrv_XC_FilLineBuffer(pInstance, ENABLE, MAIN_WINDOW);
648         MDrv_XC_FilLineBuffer(pInstance, DISABLE, SUB_WINDOW);
649     }
650     else
651     {
652         MDrv_XC_FilLineBuffer(pInstance, DISABLE, MAIN_WINDOW);
653         MDrv_XC_FilLineBuffer(pInstance, ENABLE, SUB_WINDOW);
654     }
655 
656     _XC_RETURN(pInstance);
657     _XC_SEMAPHORE_RETURN(pInstance,E_XC_ID_VAR);
658 #else
659     UNUSED(bMainFirst);
660 #endif
661 }
662 
MApi_XC_ZorderMainWindowFirst(MS_BOOL bMainFirst)663 void MApi_XC_ZorderMainWindowFirst(MS_BOOL bMainFirst)
664 {
665     if (pu32XCInst == NULL)
666     {
667         printf("[%s,%5d]No instance existed, please get an instance by calling MApi_XC_Init() first\n",__FUNCTION__,__LINE__);
668         return;
669     }
670 
671     stXC_SET_ZORDER_MAINWINDOW_FIRST XCArgs;
672     XCArgs.bMainFirst = bMainFirst;
673 
674     if(UtopiaIoctl(pu32XCInst, E_XC_CMD_SET_ZORDER_MAINWINDOW_FIRST, (void*)&XCArgs) != UTOPIA_STATUS_SUCCESS)
675     {
676         printf("Obtain XC engine fail\n");
677         return;
678     }
679     else
680     {
681         return;
682     }
683 }
684 
685 //-------------------------------------------------------------------------------------------------
686 /// enable or disable Subwindow FRC
687 /// @param  bEnable                  \b IN: Enable or Disable FRC.
688 /// @param  u8Threashold             \b IN: 0~7: ignore frames number before buffer being Read. larger
689 ///                                              number means ingnore more. 0~7:1, 2, 4, 8, 16, 32, 64, 128
690 //-------------------------------------------------------------------------------------------------
MApi_XC_SetPIP_FRC(void * pInstance,MS_BOOL enable,MS_U8 u8IgonreLinesNum)691 void MApi_XC_SetPIP_FRC(void *pInstance, MS_BOOL enable, MS_U8 u8IgonreLinesNum)
692 {
693 #ifndef DISABLE_PIP_FUNCTION
694 
695     _XC_ENTRY(pInstance);
696 
697     Hal_SC_SetPIP_FRC(pInstance, enable, u8IgonreLinesNum);
698 
699     _XC_RETURN(pInstance);
700 #else
701     UNUSED(enable);
702     UNUSED(u8IgonreLinesNum);
703 #endif
704 }
705 
MDrv_XC_EnableCLK_for_SUB(void * pInstance,MS_BOOL bEnable)706 void MDrv_XC_EnableCLK_for_SUB(void *pInstance, MS_BOOL bEnable)
707 {
708 #ifndef DISABLE_PIP_FUNCTION
709 
710 #if (HW_DESIGN_4K2K_VER == 7)
711     //Start: It needs to avoid to set SC1 sub win setting, because XC1 does not sub win
712     XC_INSTANCE_PRIVATE *psXCInstPri = NULL;
713     UtopiaInstanceGetPrivate(pInstance, (void**)&psXCInstPri);
714 
715     if(psXCInstPri->u32DeviceID == E_XC_DEVICE0)
716     {
717 #endif
718 
719     // Enable sub window clock
720     if(bEnable)
721     {
722         // Enable FIClk1
723         MDrv_WriteRegBit(REG_CKG_FICLK_F1, DISABLE, CKG_FICLK_F1_INVERT);               // Not Invert
724         MDrv_WriteRegBit(REG_CKG_FICLK_F1, DISABLE, CKG_FICLK_F1_GATED);                // Enable clock
725 
726         // Enable IDClk1
727         MDrv_WriteRegBit(REG_CKG_IDCLK1, DISABLE, CKG_IDCLK1_INVERT);                   // Not Invert
728         MDrv_WriteRegBit(REG_CKG_IDCLK1, DISABLE, CKG_IDCLK1_GATED);                    // Enable clock
729 
730 #ifdef K3_U2
731         // Enable SIDClk1
732         MDrv_WriteRegBit(REG_CKG_SIDCLK1, DISABLE, CKG_SIDCLK1_INVERT);
733         MDrv_WriteRegBit(REG_CKG_SIDCLK1, DISABLE, CKG_SIDCLK1_GATED);
734 #endif
735     }
736     else
737     {
738         // Disable FIClk1
739         MDrv_WriteRegBit(REG_CKG_FICLK_F1, ENABLE, CKG_FICLK_F1_INVERT);               // Not Invert
740         MDrv_WriteRegBit(REG_CKG_FICLK_F1, ENABLE, CKG_FICLK_F1_GATED);                // Enable clock
741 
742         // Disable IDClk1
743         MDrv_WriteRegBit(REG_CKG_IDCLK1, ENABLE, CKG_IDCLK1_INVERT);                   // Not Invert
744         MDrv_WriteRegBit(REG_CKG_IDCLK1, ENABLE, CKG_IDCLK1_GATED);                    // Enable clock
745 
746 #ifdef K3_U2
747         // Disable SIDClk1
748         MDrv_WriteRegBit(REG_CKG_SIDCLK1, ENABLE, CKG_SIDCLK1_INVERT);
749         MDrv_WriteRegBit(REG_CKG_SIDCLK1, ENABLE, CKG_SIDCLK1_GATED);
750 #endif
751     }
752 
753 #if (HW_DESIGN_4K2K_VER == 7)
754     //End: It needs to avoid to set SC1 sub win setting, because XC1 does not sub win
755     }
756     else
757     {
758         XC_LOG_TRACE(XC_DBGLEVEL_SETWINDOW, "%s %d: MDrv_XC_EnableCLK_for_SUB: Device ID %u not supporting sub window\n", __FUNCTION__, __LINE__, psXCInstPri->u32DeviceID);
759     }
760 #endif
761 
762 #ifdef CONFIG_MSTAR_SRAMPD
763     Hal_SC_EnableCLK_for_SUB(pInstance, bEnable);
764 #endif
765 
766 #else
767     UNUSED(bEnable);
768 #endif
769 }
770 
MDrv_XC_Enable_Extra_Request(void * pInstance,MS_BOOL bEnable)771 void MDrv_XC_Enable_Extra_Request(void *pInstance, MS_BOOL bEnable)
772 {
773     // HW PIP architeucture
774     // Becasue BK3_02[7] and BK20_11[15] can not enable toghter, otherwise garbage will be showed,
775     // With HW auto no signal, BK3_02[7] will be enabled by HW
776     // so, we need to set BK20_11[15] to 0 before no signal, ex. source switch case, need to disable extra request engine
777     // Then we need to restore extra request engine after input source is stable
778 #ifndef DISABLE_PIP_FUNCTION
779     Hal_SC_enable_extra_request(pInstance, bEnable);
780 #endif
781 }
782 
783 //-------------------------------------------------------------------------------------------------
784 /// Set Line Buffer merge address (This value is depend on line buffer size of main window)
785 //-------------------------------------------------------------------------------------------------
MDrv_SC_Set_LB_MergeAddress(void * pInstance)786 void MDrv_SC_Set_LB_MergeAddress(void *pInstance)
787 {
788     HAL_SC_Set_LB_MergeAddress(pInstance);
789 }
790 
791 #undef  MDRV_PIP_C
792