xref: /utopia/UTPA2-700.0.x/modules/acp/api/acp/apiACP.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2006-2007 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // (��MStar Confidential Information��) by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94 
95 ///////////////////////////////////////////////////////////////////////////////////////////////////
96 ///
97 /// file   apiACP.c
98 /// @author MStar Semiconductor,Inc.
99 /// @brief  ACP Api
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101 
102 //-------------------------------------------------------------------------------------------------
103 //  Include Files
104 //-------------------------------------------------------------------------------------------------
105 
106 #include "MsCommon.h"
107 #include "MsVersion.h"
108 #include "MsOS.h"
109 
110 #include "apiACP.h"
111 #include "drvDAC.h"
112 #include "drvTVEncoder.h"
113 
114 #ifdef MSOS_TYPE_LINUX_KERNEL
115 #include <linux/string.h>
116 #else
117 #include <string.h>
118 #endif
119 
120 #include "utopia.h"
121 #include "utopia_dapi.h"
122 #include "apiACP_private.h"
123 #include "apiACP_v2.h"
124 
125 typedef struct
126 {
127     MS_U8   u8CPC[2];
128     MS_U8   u8CPS[34];
129 }MS_VE_MV_ByteInfo;
130 
131 typedef struct
132 {
133     //Versioning
134     MS_U32  u32VE_MV_BitControl_version;     ///<Version of current structure.
135     MS_U32  u32VE_MV_BitControl_Length;      ///<Length of this structure, u32VE_MV_BitControl_Length=sizeof(MS_VE_MV_BitControl)
136     //Data
137     MS_BOOL bIsYPbPr;
138     union
139     {
140         MS_U8              u8MV_ByteInfo[36];
141         MS_VE_MV_ByteInfo  MV_ByteInfo;
142     }__attribute__ ((__packed__)) ;
143 }MS_VE_MV_BitControl;
144 
145 VE_Result MDrv_VE_SetMV(MS_BOOL bEnble, MS_U32 eType);
146 VE_Result MDrv_VE_SetMV_BitControl(MS_BOOL bEnable, MS_VE_MV_BitControl MV_BitControl_Data);
147 VE_Result MDrv_VE_DCS_SetType(MS_BOOL bEnable, MS_U32 eType);
148 VE_Result MDrv_VE_DCS_SetActivationKey(MS_U8 *pu8ActivationKeyTbl, MS_U8 u8ActivationKeyTblSize);
149 //-------------------------------------------------------------------------------------------------
150 //  local data structures
151 //-------------------------------------------------------------------------------------------------
152 void* g_pACPInst;
153 
154 /*
155  * This Enum type was defined base on EncoderICTest_Forms Rev1_3_K2_0819a.doc, ROVI CONFIDENTIAL
156  * - PAL denotes signal standards PAL-B, -D, -G, -H, -I, -K, -L
157  * - NTSC TYPE 1/2/3 include NTSC-M, NTSC-J, PAL-M and NTSC-443
158  * - PAL TYPE 1/2/3 include PAL, PAL-N, PAL-Nc and SECAM
159  */
160 typedef enum
161 {
162     MS_ACP_CVBS_NTSC_TYPE1 = 0,         //NTSC, AGC only (Table2)
163     MS_ACP_CVBS_NTSC_TYPE2,             //NTSC, AGC + 2-line Colorstripe (Table2)
164     MS_ACP_CVBS_NTSC_TYPE3,             //NTSC, AGC + 4-line Colorstripe (Table2)
165     MS_ACP_CVBS_NTSC_TEST_N01,          //NTSC, RGB Copy Protect on (N01) (Table2)
166     MS_ACP_CVBS_NTSC_TEST_N02,          //NTSC, RGB Copy Protect on (N02) (Table2)
167     MS_ACP_CVBS_NTSC_TYPE2_TTX,         //NTSC, AGC + 2-line Colorstripe (Table2) with TTX compatibility
168     MS_ACP_CVBS_NTSC_TEST_N01_TTX,      //NTSC, RGB Copy Protect on (N01) (Table2) with TTX compatibility
169     MS_ACP_CVBS_PAL_TYPE1 = 0x10,       //PAL, Type1, BPP = 0x40 (Table2)
170     MS_ACP_CVBS_PAL_TYPE2,              //PAL, Type2, BPP = 0x60 (Table2)
171     MS_ACP_CVBS_PAL_TYPE3,              //PAL, Type3, BPP = 0x50 (Table2)
172     MS_ACP_CVBS_PAL_TEST_P01,           //PAL, RGB Copy Protect on (P01) (Table2)
173     MS_ACP_CVBS_PAL_TEST_P02,           //PAL, RGB Copy Protect on (P02) (Table2)
174     MS_ACP_CVBS_PAL_TYPE2_TTX,          //PAL, Type2, BPP = 0x60 (Table2) with TTX compatibility
175     MS_ACP_CVBS_PAL_TEST_P01_TTX,       //PAL, RGB Copy Protect on (P01) (Table2) with TTX compatibility
176     MS_ACP_COMPONENT_480I_TYPE2 = 0x20, //YPbPr, NTSC-Type2:700/300 Levels (Table4)
177     MS_ACP_COMPONENT_480I_TYPE3,        //YPbPr, NTSC-Type3:714/286 Levels (Table4)
178     MS_ACP_COMPONENT_480P_EIA_7701,     //YPbPr, 525P EIA-770.1 (Table6)
179     MS_ACP_COMPONENT_480P_EIA_7702,     //YPbPr, 525P EIA-770.2 (Table6)
180     MS_ACP_COMPONENT_576I_TEST_P01,     //YPbPr, Test P01 (Table8)
181     MS_ACP_COMPONENT_576I_TEST_P02,     //YPbPr, Test P02 (Table8)
182     MS_ACP_COMPONENT_576P,              //YPbPr, 625P (Table9)
183     MS_ACP_SVIDEO_NTSC_TYPE2 = 0x40,    //S-video, NTSC-Type2 (Table4)
184     MS_ACP_SVIDEO_NTSC_TYPE3,           //S-video, NTSC-Type3 (Table4)
185     MS_ACP_SVIDEO_PAL_TEST_P01,         //S-video, PAL Test P01 (Table8)
186     MS_ACP_SVIDEO_PAL_TEST_P02,         //S-video, PAL Test P02 (Table8)
187     MS_ACP_TYPE_MAX,
188 } MS_ACP_TYPE;
189 
190 /*
191  * This Enum type was defined base on DCS for composite (CVBS) and component outputs
192  */
193 typedef enum
194 {
195     MS_ACP_DCS_TYPE_MIN = 0,
196 
197     MS_ACP_DCS_CVBS_MIN = MS_ACP_DCS_TYPE_MIN,
198     MS_ACP_DCS_CVBS_NTSC = MS_ACP_DCS_CVBS_MIN,
199     MS_ACP_DCS_CVBS_PAL,
200     MS_ACP_DCS_CVBS_MAX = MS_ACP_DCS_CVBS_PAL,
201 
202     MS_ACP_DCS_COMPONENT_MIN = 0x10,
203     MS_ACP_DCS_COMPONENT_480I = MS_ACP_DCS_COMPONENT_MIN,
204     MS_ACP_DCS_COMPONENT_480P,
205     MS_ACP_DCS_COMPONENT_576I,
206     MS_ACP_DCS_COMPONENT_576P,
207     MS_ACP_DCS_COMPONENT_720P_24,
208     MS_ACP_DCS_COMPONENT_720P_25,
209     MS_ACP_DCS_COMPONENT_720P_30,
210     MS_ACP_DCS_COMPONENT_720P_50,
211     MS_ACP_DCS_COMPONENT_720P_60,
212     MS_ACP_DCS_COMPONENT_1080I_50,
213     MS_ACP_DCS_COMPONENT_1080I_60,
214     MS_ACP_DCS_COMPONENT_1080P_24,
215     MS_ACP_DCS_COMPONENT_1080P_25,
216     MS_ACP_DCS_COMPONENT_1080P_30,
217     MS_ACP_DCS_COMPONENT_1080P_50,
218     MS_ACP_DCS_COMPONENT_1080P_60,
219     MS_ACP_DCS_COMPONENT_MAX = MS_ACP_DCS_COMPONENT_1080P_60,
220 
221     MS_ACP_DCS_TYPE_MAX = MS_ACP_DCS_COMPONENT_MAX,
222 } MS_ACP_DCS_TYPE;
223 
224 //----------------------------------------------------------------
225 // MApi_ACP_SetProtection
226 // enable/disable protection for composite (CVBS) and component outputs
227 // @bEnabled: TRUE: enabled, FALSE: not enabled
228 // @bIsYPbPr: TRUE: component, FALSE: CVBS
229 // @u8Type: protection type
230 // @return ACP_Result
231 //----------------------------------------------------------------
MApi_ACP_SetProtection_U2(MS_BOOL bEnable,MS_BOOL bIsYPbPr,MS_U8 u8Type)232 ACP_Result MApi_ACP_SetProtection_U2(MS_BOOL bEnable, MS_BOOL bIsYPbPr, MS_U8 u8Type)
233 {
234     MS_S32 ret = 0;
235     MS_ACP_TYPE eType = (MS_ACP_TYPE)u8Type;
236     MS_VE_MV_TYPE eVeMVtype = MS_VE_MV_NTSC_START;
237 
238     if (bIsYPbPr)
239     {
240         // component protection, not implemented
241         printf("component Macrovision is not ready now! \n");
242         ret = E_ACP_FAIL;
243     }
244     else
245     {
246         // CVBS protection
247         eVeMVtype = (MS_VE_MV_TYPE)eType;
248         ret = MDrv_VE_SetMV(bEnable, eVeMVtype);
249         if (ret == E_VE_OK)
250         {
251             ret = E_ACP_OK;
252         }
253         else if (ret == E_VE_NOT_SUPPORT)
254         {
255             ret = E_ACP_NOT_SUPPORT;
256             if (bEnable)
257             {
258                 goto chip_not_support;
259             }
260         }
261         else
262         {
263             ret = E_ACP_FAIL;
264         }
265     }
266 
267     return (ACP_Result)ret;
268 
269 chip_not_support:
270     // disconnect output signals (CVBS and component) in this case
271     printf("chip-not-support error\n");
272     MDrv_DAC_Enable(FALSE, TRUE);
273     MDrv_DAC_Enable(FALSE, FALSE);
274     return (ACP_Result)ret;
275 }
276 
MApi_ACP_SetProtection(MS_BOOL bEnable,MS_BOOL bIsYPbPr,MS_U8 u8Type)277 ACP_Result MApi_ACP_SetProtection(MS_BOOL bEnable, MS_BOOL bIsYPbPr, MS_U8 u8Type)
278 {
279     if (g_pACPInst == NULL)
280     {
281         if(UtopiaOpen(MODULE_ACP, &g_pACPInst, 0, NULL) != UTOPIA_STATUS_SUCCESS)
282         {
283             printf("UtopiaOpen ACP failed\n");
284     		return FALSE;
285         }
286     }
287 
288     stACP_SET_PROTECTION ACPArgs;
289     ACPArgs.bEnable = bEnable;
290     ACPArgs.bIsYPbPr = bIsYPbPr;
291     ACPArgs.u8Type = u8Type;
292     ACPArgs.eReturnValue = E_ACP_FAIL;
293 
294     if(UtopiaIoctl(g_pACPInst, E_ACP_SET_PROTECTION, (void*)&ACPArgs) != UTOPIA_STATUS_SUCCESS)
295     {
296         printf("Obtain DAC engine fail\n");
297     }
298     return ACPArgs.eReturnValue;
299 }
300 
301 //----------------------------------------------------------------
302 // MApi_ACP_SetMV_BitControl
303 // enable/disable protection by Bit Control (CPC/CPS) for composite (CVBS) and component outputs
304 // @bEnabled: TRUE: enabled, FALSE: not enabled
305 // @MS_ACP_MV_BitControl: protection data structure
306 // @return ACP_Result
307 //----------------------------------------------------------------
MApi_ACP_SetMV_BitControl_U2(MS_BOOL bEnable,MS_ACP_MV_BitControl MV_BitControl_Data)308 ACP_Result MApi_ACP_SetMV_BitControl_U2(MS_BOOL bEnable, MS_ACP_MV_BitControl MV_BitControl_Data)
309 {
310     MS_S32 ret = 0;
311 
312     if (MV_BitControl_Data.bIsYPbPr)
313     {
314         // component protection, not implemented
315         printf("component Macrovision is not ready now! \n");
316         ret = E_ACP_FAIL;
317     }
318     else
319     {
320         // CVBS protection by Bit Control (CPC/CPS)
321         MS_VE_MV_BitControl VE_MV_BitControl;
322         memcpy(&VE_MV_BitControl, &MV_BitControl_Data, sizeof(MV_BitControl_Data));
323 
324         ret = MDrv_VE_SetMV_BitControl(bEnable, VE_MV_BitControl);
325         if (ret == E_VE_OK)
326         {
327             ret = E_ACP_OK;
328         }
329         else if (ret == E_VE_NOT_SUPPORT)
330         {
331             ret = E_ACP_NOT_SUPPORT;
332             if (bEnable)
333             {
334                 goto chip_not_support;
335             }
336         }
337         else
338         {
339             ret = E_ACP_FAIL;
340         }
341     }
342 
343     return (ACP_Result)ret;
344 
345 chip_not_support:
346     // disconnect output signals (CVBS and component) in this case
347     printf("chip-not-support error\n");
348     MDrv_DAC_Enable(FALSE, TRUE);
349     MDrv_DAC_Enable(FALSE, FALSE);
350     return (ACP_Result)ret;
351 }
352 
MApi_ACP_SetMV_BitControl(MS_BOOL bEnable,MS_ACP_MV_BitControl MV_BitControl_Data)353 ACP_Result MApi_ACP_SetMV_BitControl(MS_BOOL bEnable, MS_ACP_MV_BitControl MV_BitControl_Data)
354 {
355     if (g_pACPInst == NULL)
356     {
357         if(UtopiaOpen(MODULE_ACP, &g_pACPInst, 0, NULL) != UTOPIA_STATUS_SUCCESS)
358         {
359             printf("UtopiaOpen ACP failed\n");
360     		return FALSE;
361         }
362     }
363 
364     stACP_SET_MV_BITCONTROL ACPArgs;
365     ACPArgs.bEnable = bEnable;
366     memcpy(&ACPArgs.MV_BitControl_Data, &MV_BitControl_Data, sizeof(MS_ACP_MV_BitControl));
367     ACPArgs.eReturnValue = E_ACP_FAIL;
368 
369     if(UtopiaIoctl(g_pACPInst, E_ACP_SET_MV_BITCONTROL, (void*)&ACPArgs) != UTOPIA_STATUS_SUCCESS)
370     {
371         printf("Obtain DAC engine fail\n");
372     }
373     return ACPArgs.eReturnValue;
374 }
375 
376 //----------------------------------------------------------------
377 // MApi_DCS_SetProtection
378 // enable/disable DCS protection for composite (CVBS) and component outputs
379 // @bEnabled: TRUE: enabled, FALSE: not enabled
380 // @u8Type: protection type
381 // @return ACP_Result
382 //----------------------------------------------------------------
MApi_DCS_SetProtection_U2(MS_BOOL bEnable,MS_U8 u8Type)383 ACP_Result MApi_DCS_SetProtection_U2(MS_BOOL bEnable, MS_U8 u8Type)
384 {
385     MS_S32 s32Ret = FALSE;
386     MS_ACP_DCS_TYPE eType = (MS_ACP_DCS_TYPE)u8Type;
387 
388     s32Ret = MDrv_VE_DCS_SetType(bEnable, (MS_U32)eType);
389     if(s32Ret > E_VE_OK || s32Ret < E_VE_NOT_SUPPORT)
390     {
391         return E_ACP_FAIL;
392     }
393 
394     return (ACP_Result)s32Ret;
395 }
396 
MApi_DCS_SetProtection(MS_BOOL bEnable,MS_U8 u8Type)397 ACP_Result MApi_DCS_SetProtection(MS_BOOL bEnable, MS_U8 u8Type)
398 {
399     if (g_pACPInst == NULL)
400     {
401         if(UtopiaOpen(MODULE_ACP, &g_pACPInst, 0, NULL) != UTOPIA_STATUS_SUCCESS)
402         {
403             printf("UtopiaOpen ACP failed\n");
404     		return FALSE;
405         }
406     }
407 
408     stACP_DCS_PROTECTION ACPArgs;
409     ACPArgs.bEnable = bEnable;
410     ACPArgs.u8Type = u8Type;
411     ACPArgs.eReturnValue = E_ACP_FAIL;
412 
413     if(UtopiaIoctl(g_pACPInst, E_ACP_DCS_PROTECTION, (void*)&ACPArgs) != UTOPIA_STATUS_SUCCESS)
414     {
415         printf("Obtain DAC engine fail\n");
416     }
417     return ACPArgs.eReturnValue;
418 }
419 
420 //----------------------------------------------------------------
421 // MApi_DCS_SetActivationKey
422 // DCS protection Activation Key Setting By External
423 // @pu8ActivationKeyTbl: External Activation Key Table
424 // @u8ActivationKeyTblSize: External Activation Key Table Size
425 // @return ACP_Result
426 //----------------------------------------------------------------
MApi_DCS_SetActivationKey_U2(MS_U8 * pu8ActivationKeyTbl,MS_U8 u8ActivationKeyTblSize)427 ACP_Result MApi_DCS_SetActivationKey_U2(MS_U8 *pu8ActivationKeyTbl, MS_U8 u8ActivationKeyTblSize)
428 {
429     MS_S32 s32Ret = FALSE;
430 
431     s32Ret = MDrv_VE_DCS_SetActivationKey(pu8ActivationKeyTbl, u8ActivationKeyTblSize);
432     if(s32Ret > E_ACP_OK || s32Ret < E_ACP_NOT_SUPPORT)
433     {
434         return E_ACP_FAIL;
435     }
436 
437     return (ACP_Result)s32Ret;
438 }
439 
MApi_DCS_SetActivationKey(MS_U8 * pu8ActivationKeyTbl,MS_U8 u8ActivationKeyTblSize)440 ACP_Result MApi_DCS_SetActivationKey(MS_U8 *pu8ActivationKeyTbl, MS_U8 u8ActivationKeyTblSize)
441 {
442     if (g_pACPInst == NULL)
443     {
444         if(UtopiaOpen(MODULE_ACP, &g_pACPInst, 0, NULL) != UTOPIA_STATUS_SUCCESS)
445         {
446             printf("UtopiaOpen ACP failed\n");
447     		return FALSE;
448         }
449     }
450 
451     stACP_DCS_SETACTIVATIONKEY ACPArgs;
452     ACPArgs.pu8ActivationKeyTbl = pu8ActivationKeyTbl;
453     ACPArgs.u8ActivationKeyTblSize = u8ActivationKeyTblSize;
454     ACPArgs.eReturnValue = E_ACP_FAIL;
455 
456     if(UtopiaIoctl(g_pACPInst, E_ACP_DCS_SETACTIVATIONKEY, (void*)&ACPArgs) != UTOPIA_STATUS_SUCCESS)
457     {
458         printf("Obtain DAC engine fail\n");
459     }
460     return ACPArgs.eReturnValue;
461 }
462 
463