xref: /utopia/UTPA2-700.0.x/mxlib/include/apiXC_Adc.h (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 ///////////////////////////////////////////////////////////////////////////////////////////////////
96 ///
97 /// @file   apiXC_Adc.h
98 /// @brief  MStar ADC API
99 /// @author MStar Semiconductor Inc.
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101 
102 
103 /*! \defgroup Video Video modules
104 
105  * \defgroup XC_SRC XC_SRC modules
106  *  \ingroup Video
107 
108 	ADC is used to control ADC relative setting for YPbPr, VGA, SCART, AV, SV, ATV.\n
109 	For more information,see \link ADC ADC interface (apiXC_ADC.h)  \endlink
110 
111  *  \defgroup ADC ADC interface (apiXC_ADC.h)
112  *  \ingroup XC_SRC
113 
114     ADC is used to control ADC relative setting for YPbPr, VGA, SCART, AV, SV, ATV, including
115     - CVBS out setting
116     - Control ADC PC clock
117     - Control ADC phase
118     - Control SoG level
119     - Control ADC gain and offset
120     - ADC efuse setting( bandgap and iDac)
121     - ADC calibration
122     - Control PIPE delay
123     - Control ADC clamp delay
124 
125     <b> Operation Code Flow: </b> \n
126     check flow chart directly.
127     \image html ADC.png
128 
129  *  \defgroup ADC_FEATURE ADC feature operation
130  *  \ingroup ADC
131 
132  *! \defgroup ADC_INFO ADC Infomation pool
133  *  \ingroup ADC
134 
135  *! \defgroup ADC_ToBeModified ADC api to be modified
136  *  \ingroup ADC
137 
138  *! \defgroup ADC_ToBeRemove ADC api to be removed
139  *  \ingroup ADC
140  */
141 
142 #ifndef _API_XC_ADC_H_
143 #define _API_XC_ADC_H_
144 
145 #ifdef __cplusplus
146 extern "C"
147 {
148 #endif
149 
150 //-------------------------------------------------------------------------------------------------
151 //  Macro and Define
152 //-------------------------------------------------------------------------------------------------
153 
154 //-------------------------------------------------------------------------------------------------
155 //  Type and Structure
156 //-------------------------------------------------------------------------------------------------
157 
158 /// Struct for store ADC Gain and Offset
159 typedef struct DLL_PACKED
160 {
161     MS_U16 u16RedGain;      ///< ADC red gain
162     MS_U16 u16GreenGain;    ///< ADC green gain
163     MS_U16 u16BlueGain;     ///< ADC blue gain
164     MS_U16 u16RedOffset;    ///< ADC red offset
165     MS_U16 u16GreenOffset;  ///< ADC green offset
166     MS_U16 u16BlueOffset;   ///< ADC blue offset
167 } APIXC_AdcGainOffsetSetting;
168 
169 /// ADC output internal voltage type
170 typedef enum
171 {
172     E_ADC_Internal_0V,      ///< Output   0V
173     E_ADC_Internal_0_1V,    ///< Output 0.1V
174     E_ADC_Internal_0_6V,    ///< Output 0.6V
175     E_ADC_Internal_None,    ///< OFF
176 }ADC_Internal_Voltage;
177 
178 /// ADC output Clock type
179 typedef enum
180 {
181     E_ADC_Gen_480P_Clk,     ///< ADC output 480P
182     E_ADC_Gen_720P_Clk,     ///< ADC output 720P
183     E_ADC_Gen_1080P_Clk,    ///< ADC output 1080P
184 }ADC_Gen_Clock_Type;
185 
186 /// ADC V Clamping type
187 typedef enum
188 {
189     E_ADC_VClamp_0_85V,     ///< Clamp to 0.85V
190     E_ADC_VClamp_0_9V,      ///< Clamp to 0.9V
191     E_ADC_VClamp_0_95V,     ///< Clamp to 0.95V
192     E_ADC_VClamp_1_0V,      ///< Clamp to 1.0V
193     E_ADC_VClamp_1_05V,     ///< Clamp to 1.05V
194     E_ADC_VClamp_1_2V,      ///< Clamp to 1.2V
195     E_ADC_VClamp_1_5V,      ///< Clamp to 1.5V
196 }ADC_VClamp_Level_Type;
197 
198 /// Update Gain / Offset for specific channel. This is used in MApi_XC_ADC_SetGain or MApi_XC_ADC_SetOffset
199 typedef enum
200 {
201     ADC_CHR = 0,    ///< Channel R
202     ADC_CHG,        ///< Channel G
203     ADC_CHB,        ///< Channel B
204     ADC_ALL,        ///< All Channel
205 }ADC_CHANNEL_t;
206 
207 /// Software reset for ADCDVIPLL block
208 typedef enum
209 {
210     REST_ATOP        = _BIT(7),     ///< Reset ATOP
211     REST_HDMI        = _BIT(6),
212     REST_HDCP        = _BIT(5),
213     REST_DVI         = _BIT(4),
214     REST_PLL_DIG_B   = _BIT(3),
215     REST_ADC_DIG_B   = _BIT(2),
216     REST_PLL_DIG_A   = _BIT(1),
217     REST_ADC_DIG_A   = _BIT(0),
218     REST_PLL         = ( REST_PLL_DIG_B | REST_PLL_DIG_A ), ///< Reset PLL
219     REST_ADC         = ( REST_ADC_DIG_B | REST_ADC_DIG_A ), ///< Reset All ADC
220 } ADC_RESET;
221 
222 typedef enum
223 {
224     E_ADC_IDAC_FULL_MODE,
225     E_ADC_IDAC_HALF_MODE,
226     E_ADC_IDAC_QUART_MODE,
227     E_ADC_IDAC_MODE_MAX,
228 } ADC_DacCurrentMode_t;
229 
230 //-------------------------------------------------------------------------------------------------
231 //  Function and Variable
232 //-------------------------------------------------------------------------------------------------
233 //------------------------------------------------------------------------------
234 //------------------------------------------------------------------------------
235 /// Enable and Disable CVBS out. This will setup ADC part for CVBS out (monitor out).
236 /// @ingroup ADC_FEATURE
237 /// @param bEnable \b IN Enable CVBS Out
238 /// @param enInputPortType \b IN The source need to monitor out.
239 /// @param isDigitalSource \b IN Tell the driver current source is digital source or not. (ex. If internal VIF used in ATV, it will be digital source)
240 //------------------------------------------------------------------------------
241 void    MApi_XC_ADC_SetCVBSOut(MS_BOOL bEnable, E_DEST_TYPE enOutputType , INPUT_SOURCE_TYPE_t enInputPortType, MS_BOOL isDigitalSource);
242 //------------------------------------------------------------------------------
243 /// Check the CVBS out enable status.
244 /// @ingroup ADC_INFO
245 /// @param bEnable \b IN Enable CVBS Out
246 /// @return @ref MS_BOOL
247 //------------------------------------------------------------------------------
248 MS_BOOL MApi_XC_ADC_IsCVBSOutEnabled(E_DEST_TYPE enOutputType);
249 
250 //------------------------------------------------------------------------------
251 /// Set ADC Sample clock
252 /// @ingroup ADC_FEATURE
253 /// @param u16Value \b IN value need to be set.
254 //------------------------------------------------------------------------------
255 void    MApi_XC_ADC_SetPcClock(MS_U16 u16Clock);
256 
257 //------------------------------------------------------------------------------
258 /// Set ADC Phase, pls use MApi_XC_ADC_SetPhaseEx instead
259 /// @ingroup ADC_ToBeRemove
260 /// @param u8Value \b IN The adc phase need to be update
261 //------------------------------------------------------------------------------
262 void    MApi_XC_ADC_SetPhase(MS_U8 u8Value);
263 
264 //------------------------------------------------------------------------------
265 /// Set ADC Phase for extend bit
266 /// @ingroup ADC_ToBeModified
267 /// @param u16Value \b IN The adc phase need to be update
268 //------------------------------------------------------------------------------
269 void    MApi_XC_ADC_SetPhaseEx(MS_U16 u16Value);
270 
271 //------------------------------------------------------------------------------
272 /// Get current ADC Phase set
273 /// @ingroup ADC_INFO
274 /// @return @ref MS_U16  \b Current Phase
275 //------------------------------------------------------------------------------
276 MS_U16     MApi_XC_ADC_GetPhaseRange( void );
277 
278 //------------------------------------------------------------------------------
279 /// Get current ADC Phase set
280 /// @ingroup ADC_ToBeRemove
281 /// @return @ref MS_U8  \b Current Phase
282 //------------------------------------------------------------------------------
283 MS_U8    MApi_XC_ADC_GetPhase( void );
284 
285 //------------------------------------------------------------------------------
286 /// Get current ADC Phase set for extend bit
287 /// @ingroup ADC_ToBeModified
288 /// @return @ref MS_U16  \b Current Phase
289 //------------------------------------------------------------------------------
290 MS_U16   MApi_XC_ADC_GetPhaseEx( void );
291 
292 //------------------------------------------------------------------------------
293 /// Get the status for Scart RGB
294 /// @ingroup ADC_INFO
295 /// @return @ref MS_BOOL
296 //------------------------------------------------------------------------------
297 MS_BOOL MApi_XC_ADC_IsScartRGB(void);
298 
299 //------------------------------------------------------------------------------
300 /// Get the status for PC clock
301 /// @ingroup ADC_INFO
302 /// @return @ref MS_U16
303 //------------------------------------------------------------------------------
304 MS_U16  MApi_XC_ADC_GetPcClock(void );
305 
306 //------------------------------------------------------------------------------
307 ///Get SOG level range
308 /// @ingroup ADC_INFO
309 ///@param u32Min \b OUT: min of SOG level
310 ///@param u32Max \b OUT: max of SOG level
311 ///@param u32Recommend_value \b OUT: recommend value
312 //------------------------------------------------------------------------------
313 void    MApi_XC_ADC_GetSoGLevelRange(MS_U32 *u32min, MS_U32 *u32max, MS_U32 *u32Recommend_value);
314 
315 //------------------------------------------------------------------------------
316 ///Set SOG level
317 /// @ingroup ADC_FEATURE
318 ///@param u32Min \b IN: set SOG level
319 //------------------------------------------------------------------------------
320 void    MApi_XC_ADC_SetSoGLevel(MS_U32 u32Value);
321 
322 // power
323 //------------------------------------------------------------------------------
324 /// Turn off ADC
325 /// @ingroup ADC_FEATURE
326 //------------------------------------------------------------------------------
327 void    MApi_XC_ADC_PowerOff(void);
328 
329 // ADC calibration
330 //------------------------------------------------------------------------------
331 /// Get ADC Default gain / offset by referring input structure.
332 /// @ingroup ADC_INFO
333 /// @param eSource \b IN The input source
334 /// @param pstADCSetting \b IN gain / offset need to be set
335 //------------------------------------------------------------------------------
336 void MApi_XC_ADC_GetDefaultGainOffset(INPUT_SOURCE_TYPE_t eSource , APIXC_AdcGainOffsetSetting* pstADCSetting);
337 
338 //------------------------------------------------------------------------------
339 /// get maximal value of offset
340 /// @ingroup ADC_INFO
341 /// @param
342 /// @return maximal value of offset
343 //------------------------------------------------------------------------------
344 MS_U16 MApi_XC_ADC_GetMaximalOffsetValue(void);
345 
346 //------------------------------------------------------------------------------
347 /// get maximal value of gain
348 /// @ingroup ADC_INFO
349 /// @param
350 /// @return @ref MS_U16  \b maximal value of gain
351 //------------------------------------------------------------------------------
352 MS_U16  MApi_XC_ADC_GetMaximalGainValue(void);
353 
354 //------------------------------------------------------------------------------
355 /// get center value of gain
356 /// @ingroup ADC_INFO
357 /// @param
358 /// @return @ref MS_U16  \b return center value of gain
359 //------------------------------------------------------------------------------
360 MS_U16 MApi_XC_ADC_GetCenterGain(void);
361 
362 //------------------------------------------------------------------------------
363 /// get center value of offset
364 /// @ingroup ADC_INFO
365 /// @param
366 /// @return @ref MS_U16  \b return center value of offset
367 //------------------------------------------------------------------------------
368 MS_U16 MApi_XC_ADC_GetCenterOffset(void);
369 
370 // Set Gain & Offset
371 // u8Color is one of ADC_CHANNEL_t.
372 //------------------------------------------------------------------------------
373 /// Set Gain value
374 /// @ingroup ADC_FEATURE
375 /// @param u8color \b IN The channel type need to be set
376 /// @param u16value \b IN The value need to be set.
377 //------------------------------------------------------------------------------
378 void MApi_XC_ADC_SetGain(MS_U8 u8Color, MS_U16 u16Value);
379 
380 //------------------------------------------------------------------------------
381 /// Set offset value
382 /// @ingroup ADC_FEATURE
383 /// @param u8color \b IN The channel type need to be set
384 /// @param u16value \b IN The value need to be set.
385 //------------------------------------------------------------------------------
386 void MApi_XC_ADC_SetOffset(MS_U8 u8Color, MS_U16 u16Value);
387 
388 //------------------------------------------------------------------------------
389 /// Set ADC gain / offset by referring input structure.
390 /// @ingroup ADC_FEATURE
391 /// @param pstADCSetting \b IN gain / offset need to be set
392 //------------------------------------------------------------------------------
393 void MApi_XC_ADC_AdjustGainOffset(APIXC_AdcGainOffsetSetting* pstADCSetting);
394 
395 //------------------------------------------------------------------------------
396 /// Set ADC Internal calibration. (need to be set during set mode)
397 /// @ingroup ADC_FEATURE
398 /// @param enInputSourceType \b IN current input source.
399 //------------------------------------------------------------------------------
400 void MApi_XC_ADC_Source_Calibrate(INPUT_SOURCE_TYPE_t enInputSourceType);
401 
402 //------------------------------------------------------------------------------
403 ///Set SOG level
404 /// @ingroup ADC_FEATURE
405 ///@param u32Min \b IN: set SOG calibration
406 //------------------------------------------------------------------------------
407 void MApi_XC_ADC_SetSoGCal(void);
408 
409 //------------------------------------------------------------------------------
410 //Set SCART RGB PIPE Delay
411 /// @ingroup ADC_FEATURE
412 ///@param u8Value \b IN: set PIP Delay
413 //------------------------------------------------------------------------------
414 void MApi_XC_ADC_SetRGB_PIPE_Delay(MS_U8 u8Value);
415 
416 //------------------------------------------------------------------------------
417 //Set Scart RGB Sync on green clamp delay and duration value
418 /// @ingroup ADC_FEATURE
419 ///@param u16Clpdly \b IN: set clamp Delay
420 ///@param u16Caldur \b IN: set clamp duration
421 //------------------------------------------------------------------------------
422 void MApi_XC_ADC_ScartRGB_SOG_ClampDelay(MS_U16 u16Clpdly, MS_U16 u16Caldur);
423 
424 //------------------------------------------------------------------------------
425 //Enable Loose LPF
426 /// @ingroup ADC_FEATURE
427 ///@param benable \b IN: Enable Loose LPF
428 //------------------------------------------------------------------------------
429 void MApi_XC_ADC_Set_YPbPrLooseLPF(MS_BOOL benable);
430 
431 //------------------------------------------------------------------------------
432 ///Set SOG BW
433 /// @ingroup ADC_FEATURE
434 ///@param u16value \b IN: set SOG BW
435 //------------------------------------------------------------------------------
436 void MApi_XC_ADC_Set_SOGBW(MS_U16 u16value);
437 
438 //------------------------------------------------------------------------------
439 // Set Clamp Duration
440 /// @ingroup ADC_FEATURE
441 ///@param u16Caldur \b IN: set clamp duration
442 //------------------------------------------------------------------------------
443 void MApi_XC_ADC_SetClampDuration(MS_U16 u16Value);
444 
445 //------------------------------------------------------------------------------
446 ///Enable HW calibration, will load hw adc table when changing source
447 /// @ingroup ADC_FEATURE
448 ///@param bEnable \b IN: enable hw calibration
449 /// @return @ref MS_BOOL  \b return the status
450 //------------------------------------------------------------------------------
451 MS_BOOL MApi_XC_ADC_EnableHWCalibration(MS_BOOL bEnable);
452 
453 //------------------------------------------------------------------------------
454 ///This function set CVBS Out IDAC curret mode.
455 /// @ingroup ADC_FEATURE
456 ///@param stMode \b IDAC current mode.
457 /// @return @ref MS_BOOL  \b return the status
458 //------------------------------------------------------------------------------
459 MS_BOOL MApi_XC_ADC_SetIdacCurrentMode(ADC_DacCurrentMode_t eMode);
460 
461 //------------------------------------------------------------------------------
462 ///This function get CVBS Out IDAC current mode.
463 /// @ingroup ADC_INFO
464 ///@return IDAC current mode.
465 //------------------------------------------------------------------------------
466 ADC_DacCurrentMode_t MApi_XC_ADC_GetIdacCurrentMode(void);
467 
468 #ifdef __cplusplus
469 }
470 #endif
471 
472 #endif  // _API_XC_ADC_H_
473 
474