xref: /utopia/UTPA2-700.0.x/modules/vif/drv/vif/drvVIF.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 #ifndef _DRVVIF_C_
95 #define _DRVVIF_C_
96 
97 //-------------------------------------------------------------------------------------------------
98 //  Include Files
99 //-------------------------------------------------------------------------------------------------
100 #ifdef MSOS_TYPE_LINUX_KERNEL
101 #include <linux/string.h>
102 #else
103 #include <string.h>
104 #endif
105 //#include "MsVersion.h"
106 #include "MsCommon.h"
107 //#include "halVIF.h"
108 //#include "halVIF_Customer.h"
109 //#include "regVIF.h"
110 #include "drvVIF.h"
111 #include "drvVIF_v2.h"
112 #include "../../utopia_core/utopia.h"
113 
114 //-------------------------------------------------------------------------------------------------
115 //  Global variables
116 //-------------------------------------------------------------------------------------------------
117 
118 void* ppVIFInstant = NULL;
119 static MS_U32 u32VIFopen = 0;
120 
121 //-------------------------------------------------------------------------------------------------
122 //  Global VIF functions
123 //-------------------------------------------------------------------------------------------------
124 
DRV_VIF_WriteByte(U32 u32Reg,U8 u8Val)125 void DRV_VIF_WriteByte(U32 u32Reg, U8 u8Val )
126 {
127     VIF_SETREGVALUE SetRegInfo = {0};
128 
129     SetRegInfo.u32Addr = u32Reg;
130     SetRegInfo.u8Value = u8Val;
131 
132     if(u32VIFopen == 1)
133         UtopiaIoctl(ppVIFInstant, Drv_CMD_VIF_WriteByte, &SetRegInfo);
134     else
135         printf("\r\n ======== DRV_VIF_WriteByte/VIF Open Fail %x =========", (WORD)u32VIFopen);
136 }
137 
DRV_VIF_ReadByte(U32 u32Reg)138 U8 DRV_VIF_ReadByte(U32 u32Reg )
139 {
140     VIF_SETREGVALUE SetRegInfo = {0};
141 
142     SetRegInfo.u32Addr = u32Reg;
143     SetRegInfo.u8Value = 0;
144 
145     if(u32VIFopen == 1)
146     {
147         UtopiaIoctl(ppVIFInstant, Drv_CMD_VIF_ReadByte, &SetRegInfo);
148         return SetRegInfo.u8Value;
149     }
150     else
151     {
152         printf("\r\n ======== DRV_VIF_ReadByte/VIF Open Fail %x =========", (WORD)u32VIFopen);
153         return 0;
154     }
155 }
156 
DRV_VIF_Version(void)157 void DRV_VIF_Version(void)
158 {
159     if(u32VIFopen == 1)
160         UtopiaIoctl(ppVIFInstant, Drv_CMD_VIF_Version, NULL);
161     else
162         printf("\r\n ======== DRV_VIF_Version/VIF Open Fail %x =========", (WORD)u32VIFopen);
163 }
164 
DRV_VIF_Read_CR_FOE(void)165 U8 DRV_VIF_Read_CR_FOE(void)
166 {
167     VIF_COPYTOUSER CopyToUser = {0};
168 
169     if(u32VIFopen == 1)
170     {
171         UtopiaIoctl(ppVIFInstant, Drv_CMD_VIF_Read_CR_FOE, &CopyToUser);
172         return CopyToUser.u8Value;
173     }
174     else
175     {
176         printf("\r\n ======== DRV_VIF_Read_CR_FOE/VIF Open Fail %x =========", (WORD)u32VIFopen);
177         return 0;
178     }
179 }
180 
DRV_VIF_Read_CR_LOCK_STATUS(void)181 U8 DRV_VIF_Read_CR_LOCK_STATUS(void)
182 {
183     VIF_COPYTOUSER CopyToUser = {0};
184 
185     if(u32VIFopen == 1)
186     {
187         UtopiaIoctl(ppVIFInstant, Drv_CMD_VIF_Read_CR_LOCK_STATUS, &CopyToUser);
188         return CopyToUser.u8Value;
189     }
190     else
191     {
192         printf("\r\n ======== DRV_VIF_Read_CR_LOCK_STATUS/VIF Open Fail %x =========", (WORD)u32VIFopen);
193         return 0;
194     }
195 }
196 
DRV_VIF_SetClock(BOOL bEnable)197 void DRV_VIF_SetClock(BOOL bEnable)
198 {
199     if(u32VIFopen == 1)
200         UtopiaIoctl(ppVIFInstant, Drv_CMD_VIF_SetClock, &bEnable);
201     else
202         printf("\r\n ======== DRV_VIF_SetClock/VIF Open Fail %x =========", (WORD)u32VIFopen);
203 }
204 
DRV_VIF_Init(VIFInitialIn * pVIF_InitData,DWORD u32InitDataLen)205 void DRV_VIF_Init(VIFInitialIn * pVIF_InitData, DWORD u32InitDataLen)
206 {
207     eVIF_INIT _eVIF_Init = {0};
208 
209     _eVIF_Init.pVIF_InitData = pVIF_InitData;
210     _eVIF_Init.u32InitDataLen = u32InitDataLen;
211 
212     //printf("\r\n ========= DRV_VIF_Init =========== \n");
213 
214     void* pAttribte = NULL;
215     if(u32VIFopen == 0)  // First time open
216     {
217         //if(UtopiaOpen(MODULE_VIF |KERNEL_MODE, &ppVIFInstant, 0, pAttribte) == UTOPIA_STATUS_SUCCESS)
218         if(UtopiaOpen(MODULE_VIF, &ppVIFInstant, 0, pAttribte) == UTOPIA_STATUS_SUCCESS)
219         {
220             u32VIFopen = 1;
221 
222             UtopiaIoctl(ppVIFInstant, Drv_CMD_VIF_Init, &_eVIF_Init);
223 
224             //printf("\r\n ======== DRV_VIF_Init/VIF Open Successful %x =========", (WORD)u32VIFopen);
225         }
226         else
227             printf("\r\n ======== DRV_VIF_Init/VIF Open Fail %x =========", (WORD)u32VIFopen);
228     }
229     else
230         UtopiaIoctl(ppVIFInstant, Drv_CMD_VIF_Reset, NULL);
231 }
232 
DRV_VIF_Exit(void)233 void DRV_VIF_Exit(void)
234 {
235     //printf("\r\n ========== DRV_VIF_Exit ========== \n");
236 
237     if(u32VIFopen == 1)
238     {
239         u32VIFopen = 0;
240 
241         UtopiaIoctl(ppVIFInstant, Drv_CMD_VIF_Exit, NULL);
242     }
243     else
244         printf("\r\n ======== DRV_VIF_Exit/VIF Open Fail %x =========", (WORD)u32VIFopen);
245 }
246 
DRV_VIF_Reset(void)247 void DRV_VIF_Reset(void)
248 {
249     //printf("\r\n ========== DRV_VIF_Reset ========== \n");
250 
251     if(u32VIFopen == 1)
252         UtopiaIoctl(ppVIFInstant, Drv_CMD_VIF_Reset, NULL);
253     else
254         printf("\r\n ======== DRV_VIF_Reset/VIF Open Fail %x =========", (WORD)u32VIFopen);
255 }
256 
DRV_VIF_Handler(BOOL bAutoScan)257 void DRV_VIF_Handler(BOOL bAutoScan)
258 {
259     if(u32VIFopen == 1)
260         UtopiaIoctl(ppVIFInstant, Drv_CMD_VIF_Handler, &bAutoScan);
261     else
262         printf("\r\n ======== DRV_VIF_Handler/VIF Open Fail %x =========", (WORD)u32VIFopen);
263 }
264 
DRV_VIF_SetSoundSystem(VIFSoundSystem ucSoundSystem)265 void DRV_VIF_SetSoundSystem(VIFSoundSystem ucSoundSystem)
266 {
267     //printf("\r\n ========= DRV_VIF_SetSoundSystem ========== \n");
268 
269     if(u32VIFopen == 1)
270         UtopiaIoctl(ppVIFInstant, Drv_CMD_VIF_SetSoundSystem, &ucSoundSystem);
271     else
272         printf("\r\n ======== DRV_VIF_SetSoundSystem/VIF Open Fail %x =========", (WORD)u32VIFopen);
273 }
274 
DRV_VIF_SetIfFreq(IfFrequencyType u16IfFreq)275 void DRV_VIF_SetIfFreq(IfFrequencyType u16IfFreq)
276 {
277     //printf("\r\n ========= DRV_VIF_SetIfFreq =========== \n");
278 
279     if(u32VIFopen == 1)
280         UtopiaIoctl(ppVIFInstant, Drv_CMD_VIF_SetIfFreq, &u16IfFreq);
281     else
282         printf("\r\n ======== DRV_VIF_SetIfFreq/VIF Open Fail %x =========", (WORD)u32VIFopen);
283 }
284 
DRV_VIF_BypassDBBAudioFilter(BOOL bEnable)285 void DRV_VIF_BypassDBBAudioFilter(BOOL bEnable)
286 {
287     if(u32VIFopen == 1)
288         UtopiaIoctl(ppVIFInstant, Drv_CMD_VIF_BypassDBBAudioFilter, &bEnable);
289     else
290         printf("\r\n ======== DRV_VIF_BypassDBBAudioFilter/VIF Open Fail %x =========", (WORD)u32VIFopen);
291 }
292 
DRV_VIF_SetFreqBand(FrequencyBand u8FreqBand)293 void DRV_VIF_SetFreqBand(FrequencyBand u8FreqBand)
294 {
295     //printf("\r\n ========= DRV_VIF_SetFreqBand =========== \n");
296 
297     if(u32VIFopen == 1)
298         UtopiaIoctl(ppVIFInstant, Drv_CMD_VIF_SetFreqBand, &u8FreqBand);
299     else
300         printf("\r\n ======== DRV_VIF_SetFreqBand/VIF Open Fail %x =========", (WORD)u32VIFopen);
301 }
302 
DRV_VIF_GetInputLevelIndicator(void)303 BOOL DRV_VIF_GetInputLevelIndicator(void)
304 {
305     VIF_COPYTOUSER CopyToUser = {0};
306 
307     //printf("\r\n ========= DRV_VIF_GetInputLevelIndicator =========== \n");
308 
309     if(u32VIFopen == 1)
310     {
311         UtopiaIoctl(ppVIFInstant, Drv_CMD_VIF_GetInputLevelIndicator, &CopyToUser);
312         return CopyToUser.bEnable;
313     }
314     else
315     {
316         printf("\r\n ======== DRV_VIF_GetInputLevelIndicator/VIF Open Fail %x =========", (WORD)u32VIFopen);
317         return FALSE;
318     }
319 }
320 
DRV_VIF_SetParameter(VIF_PARA_GROUP paraGroup,void * pVIF_Para,DWORD u32DataLen)321 BOOL DRV_VIF_SetParameter(VIF_PARA_GROUP paraGroup, void * pVIF_Para, DWORD u32DataLen)
322 {
323     //printf("\r\n =========== DRV_VIF_SetParameter =========== \n");
324 
325     VIF_SETPARA SetParaInfo = {0};
326 
327     SetParaInfo.ParaGroup = paraGroup;
328     SetParaInfo.pVIF_Para = pVIF_Para;
329     SetParaInfo.u32DataLen = u32DataLen;
330     SetParaInfo.bRet = 0;
331 
332     if(u32VIFopen == 1)
333     {
334         UtopiaIoctl(ppVIFInstant, Drv_CMD_VIF_SetParameter, &SetParaInfo);
335         return SetParaInfo.bRet;
336     }
337     else
338     {
339         printf("\r\n ======== DRV_VIF_SetParameter/VIF Open Fail %x =========", (WORD)u32VIFopen);
340         return FALSE;
341     }
342 }
343 
DRV_VIF_ShiftClk(BYTE VifShiftClk)344 void DRV_VIF_ShiftClk(BYTE VifShiftClk)
345 {
346      //printf("\r\n =========== DRV_VIF_ShiftClk =========== \n");
347 
348     if(u32VIFopen == 1)
349         UtopiaIoctl(ppVIFInstant, Drv_CMD_VIF_ShiftClk, &VifShiftClk);
350     else
351         printf("\r\n ======== DRV_VIF_ShiftClk/VIF Open Fail %x =========", (WORD)u32VIFopen);
352 }
353 
MDrv_VIF_SetPowerState(EN_POWER_MODE u16PowerState)354 MS_U32 MDrv_VIF_SetPowerState(EN_POWER_MODE u16PowerState)
355 {
356     VIF_COPYTOUSER CopyToUser = {0};
357     MS_U32 u32Ret = 0;
358 
359     CopyToUser.u16PowerState = u16PowerState;
360     CopyToUser.u32Value = 0;
361 
362     if(u32VIFopen == 1)
363     {
364         UtopiaIoctl(ppVIFInstant, Drv_CMD_VIF_SetPowerState, &CopyToUser);
365 
366         u32Ret = CopyToUser.u32Value;
367 
368         if(u32Ret == 0)
369             return UTOPIA_STATUS_SUCCESS;
370         else
371             return UTOPIA_STATUS_FAIL;
372     }
373     else
374     {
375         printf("\r\n ======== MDrv_VIF_SetPowerState/VIF Open Fail %x =========", (WORD)u32VIFopen);
376         return UTOPIA_STATUS_FAIL;
377     }
378 }
379 
380 #endif //_DRVVIF_C_
381 
382