xref: /utopia/UTPA2-700.0.x/modules/xc/utopia_adaption/xc/XC_AUTO_adp.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 
78 ////////////////////////////////////////////////////////////////////////////////
79 /// file    XC_AUTO_adp.c
80 /// @brief  Main API in XC library.
81 /// @author MStar Semiconductor Inc.
82 ////////////////////////////////////////////////////////////////////////////////
83 
84 #ifndef _XC_AUTO_ADP_C_
85 #define _XC_AUTO_ADP_C_
86 
87 //------------------------------------------------------------------------------
88 //  Include Files
89 //------------------------------------------------------------------------------
90 // Common Definition
91 #include <linux/kernel.h>
92 #include <linux/sched.h>
93 #include <linux/string.h>
94 #include <linux/slab.h>
95 #include "MsTypes.h"
96 #include "utopia.h"
97 #include "utopia_adp.h"
98 #include "MsOS.h"
99 
100 // Internal Definition
101 #include "drvXC_IOPort.h"
102 #include "apiXC.h"
103 #include "apiXC_Adc.h"
104 #include "apiXC_Auto.h"
105 #include "apiXC_Auto_v2.h"
106 #include "apiXC_v2.h"
107 #include "XC_AUTO_adp.h"
108 #include "XC_adp.h"
109 
110 //------------------------------------------------------------------------------
111 //  Driver Compiler Options
112 //------------------------------------------------------------------------------
113 
114 //------------------------------------------------------------------------------
115 //  Local Defines
116 //------------------------------------------------------------------------------
117 
118 //------------------------------------------------------------------------------
119 //  Local Structurs
120 //------------------------------------------------------------------------------
121 
122 //------------------------------------------------------------------------------
123 //  Global Variables
124 //------------------------------------------------------------------------------
125 //Function parameter
126 UADP_STRUCT_POINTER_TABLE spt_XC_AUTO_GEOMETRY[5];
127 UADP_STRUCT_POINTER_TABLE spt_XC_AUTO_GEOMETRY_EX[5];
128 UADP_STRUCT_POINTER_TABLE spt_XC_AUTO_STOPAUTOGEOMETRY[5];
129 UADP_STRUCT_POINTER_TABLE spt_XC_AUTO_GAINOFFSET[5];
130 UADP_STRUCT_POINTER_TABLE spt_XC_AUTO_GETHWFIXEDGAINOFFSET[5];
131 UADP_STRUCT_POINTER_TABLE spt_XC_AUTO_SETVALIDDATA[5];
132 UADP_STRUCT_POINTER_TABLE spt_XC_AUTO_AUTOOFFSET[5];
133 UADP_STRUCT_POINTER_TABLE spt_XC_AUTO_DETECTWIDTH[5];
134 UADP_STRUCT_POINTER_TABLE spt_XC_AUTO_SETCALIBRATIONMODE[5];
135 UADP_STRUCT_POINTER_TABLE spt_XC_AUTO_GETCALIBRATIONMODE[5];
136 
137 //Function parameter's pointer
138 UADP_STRUCT_POINTER_TABLE spt_XC_Auto_Signal_Info[5];
139 UADP_STRUCT_POINTER_TABLE spt_XC_Auto_Signal_Info_Ex[5];
140 UADP_STRUCT_POINTER_TABLE spt_XC_AUTOGainOffsetSetting[5];
141 //UADP_STRUCT_POINTER_TABLE spt_XC_Auto_Signal_Info_Ex[5];
142 UADP_STRUCT_POINTER_TABLE spt_XC_Auto_CalibrationMode[5];
143 
144 //------------------------------------------------------------------------------
145 //  Local Variables
146 //------------------------------------------------------------------------------
147 
148 //------------------------------------------------------------------------------
149 //  Debug Functions
150 //------------------------------------------------------------------------------
151 
152 //------------------------------------------------------------------------------
153 //  Local Functions
154 //------------------------------------------------------------------------------
155 
156 //------------------------------------------------------------------------------
157 //  Global Functions
158 //------------------------------------------------------------------------------
XC_AUTO_adp_Init(void)159 MS_U32 XC_AUTO_adp_Init(void)
160 {
161 
162 //set table
163     MS_U32 temp=0;
164 
165     //Function parameter
166     pstXC_AUTO_GEOMETRY              pXC_AUTO_GEOMETRY             = (pstXC_AUTO_GEOMETRY)temp;
167 	pstXC_AUTO_GEOMETRY_EX           pXC_AUTO_GEOMETRY_EX          = (pstXC_AUTO_GEOMETRY_EX)temp;
168 	//pstXC_AUTO_STOPAUTOGEOMETRY      pXC_AUTO_STOPAUTOGEOMETRY     = (pstXC_AUTO_STOPAUTOGEOMETRY)temp;
169 	pstXC_AUTO_GAINOFFSET            pXC_AUTO_GAINOFFSET           = (pstXC_AUTO_GAINOFFSET)temp;
170 	pstXC_AUTO_GETHWFIXEDGAINOFFSET  pXC_AUTO_GETHWFIXEDGAINOFFSET = (pstXC_AUTO_GETHWFIXEDGAINOFFSET)temp;
171 	//pstXC_AUTO_SETVALIDDATA          pXC_AUTO_SETVALIDDATA         = (pstXC_AUTO_SETVALIDDATA)temp;
172 	//pstXC_AUTO_AUTOOFFSET            pXC_AUTO_AUTOOFFSET           = (pstXC_AUTO_AUTOOFFSET)temp;
173 	pstXC_AUTO_DETECTWIDTH           pXC_AUTO_DETECTWIDTH          = (pstXC_AUTO_DETECTWIDTH)temp;
174 	//pstXC_AUTO_SETCALIBRATIONMODE    pXC_AUTO_SETCALIBRATIONMODE   = (pstXC_AUTO_SETCALIBRATIONMODE)temp;
175 	pstXC_AUTO_GETCALIBRATIONMODE    pXC_AUTO_GETCALIBRATIONMODE   = (pstXC_AUTO_GETCALIBRATIONMODE)temp;
176 
177 
178 	//Function parameter's pointer
179     //XC_Auto_Signal_Info*        pXC_Auto_Signal_Info     = (XC_Auto_Signal_Info*)temp;
180     //XC_Auto_Signal_Info_Ex*     pXC_Auto_Signal_Info_Ex  = (XC_Auto_Signal_Info_Ex*)temp;
181     //APIXC_AdcGainOffsetSetting* pXC_AdcGainOffsetSetting = (APIXC_AdcGainOffsetSetting*)temp;
182     //XC_Auto_CalibrationMode*    pXC_Auto_CalibrationMode = (XC_Auto_CalibrationMode*)temp;
183 
184     //Function parameter's pointer
185     UADPBypassSetSPT(&spt_XC_Auto_Signal_Info[0],UADP_SPT_SELF_SIZE,0, sizeof(XC_Auto_Signal_Info));
186     UADPBypassSetSPT(&spt_XC_Auto_Signal_Info[1],UADP_SPT_END , 0, 0);
187 
188     UADPBypassSetSPT(&spt_XC_Auto_Signal_Info_Ex[0],UADP_SPT_SELF_SIZE,0, sizeof(XC_Auto_Signal_Info_Ex));
189     UADPBypassSetSPT(&spt_XC_Auto_Signal_Info_Ex[1],UADP_SPT_END , 0, 0);
190 
191     UADPBypassSetSPT(&spt_XC_AUTOGainOffsetSetting[0],UADP_SPT_SELF_SIZE,0, sizeof(APIXC_AdcGainOffsetSetting));
192     UADPBypassSetSPT(&spt_XC_AUTOGainOffsetSetting[1],UADP_SPT_END , 0, 0);
193 
194     UADPBypassSetSPT(&spt_XC_Auto_CalibrationMode[0],UADP_SPT_SELF_SIZE,0, sizeof(XC_Auto_CalibrationMode));
195     UADPBypassSetSPT(&spt_XC_Auto_CalibrationMode[1],UADP_SPT_END , 0, 0);
196 
197     //Function parameter
198     UADPBypassSetSPT(&spt_XC_AUTO_GEOMETRY[0],UADP_SPT_SELF_SIZE,0, sizeof(stXC_AUTO_GEOMETRY));
199     UADPBypassSetSPT(&spt_XC_AUTO_GEOMETRY[1],UADP_SPT_POINTER_TO_NEXT,
200         ((unsigned long)(&(pXC_AUTO_GEOMETRY->ActiveInfo)) - (unsigned long)pXC_AUTO_GEOMETRY), (unsigned long)spt_XC_Auto_Signal_Info);
201     UADPBypassSetSPT(&spt_XC_AUTO_GEOMETRY[2],UADP_SPT_POINTER_TO_NEXT,
202         ((unsigned long)(&(pXC_AUTO_GEOMETRY->StandardInfo)) - (unsigned long)pXC_AUTO_GEOMETRY), (unsigned long)spt_XC_Auto_Signal_Info);
203     UADPBypassSetSPT(&spt_XC_AUTO_GEOMETRY[3],UADP_SPT_END , 0, 0);
204 
205     UADPBypassSetSPT(&spt_XC_AUTO_GEOMETRY_EX[0],UADP_SPT_SELF_SIZE,0, sizeof(stXC_AUTO_GEOMETRY_EX));
206     UADPBypassSetSPT(&spt_XC_AUTO_GEOMETRY_EX[1],UADP_SPT_POINTER_TO_NEXT,
207         ((unsigned long)(&(pXC_AUTO_GEOMETRY_EX->ActiveInfo)) - (unsigned long)pXC_AUTO_GEOMETRY_EX), (unsigned long)spt_XC_Auto_Signal_Info_Ex);
208     UADPBypassSetSPT(&spt_XC_AUTO_GEOMETRY_EX[2],UADP_SPT_POINTER_TO_NEXT,
209         ((unsigned long)(&(pXC_AUTO_GEOMETRY_EX->StandardInfo)) - (unsigned long)pXC_AUTO_GEOMETRY_EX), (unsigned long)spt_XC_Auto_Signal_Info_Ex);
210     UADPBypassSetSPT(&spt_XC_AUTO_GEOMETRY_EX[3],UADP_SPT_END , 0, 0);
211 
212     UADPBypassSetSPT(&spt_XC_AUTO_STOPAUTOGEOMETRY[0],UADP_SPT_SELF_SIZE,0, sizeof(stXC_AUTO_STOPAUTOGEOMETRY));
213     UADPBypassSetSPT(&spt_XC_AUTO_STOPAUTOGEOMETRY[1],UADP_SPT_END , 0, 0);
214 
215     UADPBypassSetSPT(&spt_XC_AUTO_GAINOFFSET[0],UADP_SPT_SELF_SIZE,0, sizeof(stXC_AUTO_GAINOFFSET));
216     UADPBypassSetSPT(&spt_XC_AUTO_GAINOFFSET[1],UADP_SPT_POINTER_TO_NEXT,
217         ((unsigned long)(&(pXC_AUTO_GAINOFFSET->pstADCSetting)) - (unsigned long)pXC_AUTO_GAINOFFSET), (unsigned long)spt_XC_AUTOGainOffsetSetting);
218     UADPBypassSetSPT(&spt_XC_AUTO_GAINOFFSET[2],UADP_SPT_END , 0, 0);
219 
220 	UADPBypassSetSPT(&spt_XC_AUTO_GETHWFIXEDGAINOFFSET[0],UADP_SPT_SELF_SIZE,0, sizeof(stXC_AUTO_GETHWFIXEDGAINOFFSET));
221 	UADPBypassSetSPT(&spt_XC_AUTO_GETHWFIXEDGAINOFFSET[1],UADP_SPT_POINTER_TO_NEXT,
222         ((unsigned long)(&(pXC_AUTO_GETHWFIXEDGAINOFFSET->pstADCSetting)) - (unsigned long)pXC_AUTO_GETHWFIXEDGAINOFFSET), (unsigned long)spt_XC_AUTOGainOffsetSetting);
223     UADPBypassSetSPT(&spt_XC_AUTO_GETHWFIXEDGAINOFFSET[2],UADP_SPT_END , 0, 0);
224 
225     UADPBypassSetSPT(&spt_XC_AUTO_SETVALIDDATA[0],UADP_SPT_SELF_SIZE,0, sizeof(stXC_AUTO_SETVALIDDATA));
226     UADPBypassSetSPT(&spt_XC_AUTO_SETVALIDDATA[1],UADP_SPT_END , 0, 0);
227 
228     UADPBypassSetSPT(&spt_XC_AUTO_AUTOOFFSET[0],UADP_SPT_SELF_SIZE,0, sizeof(stXC_AUTO_AUTOOFFSET));
229     UADPBypassSetSPT(&spt_XC_AUTO_AUTOOFFSET[1],UADP_SPT_END , 0, 0);
230 
231     UADPBypassSetSPT(&spt_XC_AUTO_DETECTWIDTH[0],UADP_SPT_SELF_SIZE,0, sizeof(stXC_AUTO_DETECTWIDTH));
232     UADPBypassSetSPT(&spt_XC_AUTO_DETECTWIDTH[1],UADP_SPT_POINTER_TO_NEXT,
233         ((unsigned long)(&(pXC_AUTO_DETECTWIDTH->pSignalInfo)) - (unsigned long)pXC_AUTO_DETECTWIDTH), (unsigned long)spt_XC_Auto_Signal_Info_Ex);
234     UADPBypassSetSPT(&spt_XC_AUTO_DETECTWIDTH[2],UADP_SPT_END , 0, 0);
235 
236     UADPBypassSetSPT(&spt_XC_AUTO_SETCALIBRATIONMODE[0],UADP_SPT_SELF_SIZE,0, sizeof(stXC_AUTO_SETCALIBRATIONMODE));
237     UADPBypassSetSPT(&spt_XC_AUTO_SETCALIBRATIONMODE[1],UADP_SPT_END , 0, 0);
238 
239     UADPBypassSetSPT(&spt_XC_AUTO_GETCALIBRATIONMODE[0],UADP_SPT_SELF_SIZE,0, sizeof(stXC_AUTO_GETCALIBRATIONMODE));
240     UADPBypassSetSPT(&spt_XC_AUTO_GETCALIBRATIONMODE[1],UADP_SPT_POINTER_TO_NEXT,
241         ((unsigned long)(&(pXC_AUTO_GETCALIBRATIONMODE->eMode)) - (unsigned long)pXC_AUTO_GETCALIBRATIONMODE), (unsigned long)spt_XC_Auto_CalibrationMode);
242     UADPBypassSetSPT(&spt_XC_AUTO_GETCALIBRATIONMODE[2],UADP_SPT_END , 0, 0);
243 
244 
245 
246     return 0;
247 
248 }
249 
XC_AUTO_adp_Ioctl(void * pInstanceTmp,MS_U32 u32Cmd,void * const pArgs)250 MS_U32 XC_AUTO_adp_Ioctl(void* pInstanceTmp, MS_U32 u32Cmd, void* const pArgs)
251 {
252     MS_U32 u32Ret;
253 	char buffer_arg[2];
254 
255     switch(u32Cmd)
256     {
257 
258         case E_XC_AUTO_CMD_GEOMETRY :
259         {
260             u32Ret = UADPBypassIoctl(pInstanceTmp,u32Cmd,pArgs,spt_XC_AUTO_GEOMETRY, spt_XC_AUTO_GEOMETRY,buffer_arg,sizeof(buffer_arg));
261             break;
262         }
263 
264         case E_XC_AUTO_CMD_GEOMETRY_EX:
265         {
266             u32Ret = UADPBypassIoctl(pInstanceTmp,u32Cmd,pArgs,spt_XC_AUTO_GEOMETRY_EX, spt_XC_AUTO_GEOMETRY_EX,buffer_arg,sizeof(buffer_arg));
267             break;
268         }
269 
270         case E_XC_AUTO_CMD_STOPAUTOGEOMETRY:
271         {
272             u32Ret = UADPBypassIoctl(pInstanceTmp,u32Cmd,pArgs,NULL, spt_XC_AUTO_STOPAUTOGEOMETRY,buffer_arg,sizeof(buffer_arg));
273             break;
274         }
275 
276         case E_XC_AUTO_CMD_GAINOFFSET:
277         {
278             u32Ret = UADPBypassIoctl(pInstanceTmp,u32Cmd,pArgs,spt_XC_AUTO_GAINOFFSET, spt_XC_AUTO_GAINOFFSET,buffer_arg,sizeof(buffer_arg));
279 		    break;
280         }
281 
282         case E_XC_AUTO_CMD_GETHWFIXEDGAINOFFSET:
283         {
284 			u32Ret = UADPBypassIoctl(pInstanceTmp,u32Cmd,pArgs,spt_XC_AUTO_GETHWFIXEDGAINOFFSET, spt_XC_AUTO_GETHWFIXEDGAINOFFSET,buffer_arg,sizeof(buffer_arg));
285 		    break;
286         }
287 
288         case E_XC_AUTO_CMD_SETVALIDDATA:
289         {
290 			u32Ret = UADPBypassIoctl(pInstanceTmp,u32Cmd,pArgs,spt_XC_AUTO_SETVALIDDATA,spt_XC_AUTO_SETVALIDDATA,buffer_arg,sizeof(buffer_arg));
291 		    break;
292         }
293 
294         case E_XC_AUTO_CMD_AUTOOFFSET:
295         {
296             u32Ret = UADPBypassIoctl(pInstanceTmp,u32Cmd,pArgs,spt_XC_AUTO_AUTOOFFSET,NULL,buffer_arg,sizeof(buffer_arg));
297             break;
298         }
299 
300         case E_XC_AUTO_CMD_DETECTWIDTH:
301         {
302             u32Ret = UADPBypassIoctl(pInstanceTmp,u32Cmd,pArgs,spt_XC_AUTO_DETECTWIDTH,spt_XC_AUTO_DETECTWIDTH,buffer_arg,sizeof(buffer_arg));
303             break;
304         }
305 
306         case E_XC_AUTO_CMD_SETCALIBRATIONMODE:
307         {
308             u32Ret = UADPBypassIoctl(pInstanceTmp,u32Cmd,pArgs,spt_XC_AUTO_SETCALIBRATIONMODE,spt_XC_AUTO_SETCALIBRATIONMODE,buffer_arg,sizeof(buffer_arg));
309 		    break;
310         }
311 
312         case E_XC_AUTO_CMD_GETCALIBRATIONMODE:
313         {
314             u32Ret = UADPBypassIoctl(pInstanceTmp,u32Cmd,pArgs,NULL,spt_XC_AUTO_GETCALIBRATIONMODE,buffer_arg,sizeof(buffer_arg));
315             break;
316         }
317 
318         case E_XC_AUTO_CMD_NONE:
319         case E_XC_AUTO_CMD_MAX:
320         default:
321             {
322                 printf("Command %ld is not existed\n",u32Cmd);
323                 u32Ret = UTOPIA_STATUS_ERR_INVALID_HANDLE;
324                 break;
325             }
326 
327     }
328 
329 	return u32Ret;
330    // return UtopiaIoctl(pModuleDDI->pInstant,u32Cmd,arg);
331 }
332 
333 #endif
334 
335 
336