xref: /utopia/UTPA2-700.0.x/projects/tmplib/include/apiDAC.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   apiDAC.h
98 /// @brief  DAC Interface
99 /// @author MStar Semiconductor Inc.
100 //  CL162321++:
101 //   update HDGen table. tPanelDACOUT480I_60 output for U4
102 //  CL 216439++:
103 //   Adds DACOUT_1080P_24, DACOUT_1080P_25, DACOUT_1080P_30.
104 //  CL 223188++:
105 //   i. Modify HDGEN settings in "U4_DAC_Driver.xls" for HDMITx 480i/576i/1080i
106 //   ii. Add CLKGEN1 setting in halClkSel.c for HDMITx 1080i
107 ///////////////////////////////////////////////////////////////////////////////////////////////////
108 /*! \defgroup MISC HDMI modules
109 
110 
111  * \defgroup DAC DAC interface (apiDAC.h)
112  * \ingroup MISC
113 
114   DAC(digital-to-analog converter,DAC):Convert digital signal to analog signal, ex:YPbPr for HD,CVBS、S-Video、SCART-RGB for SD
115 
116   \image html apiDAC_pic1.png
117 
118   <b>Operation Flow</b>
119  -# MApi_DAC_Init(void)
120     - A) Get PM address – register head
121     - B) Set DAC address
122     - C) DAC init
123  -# MApi_DAC_Enable(MS_BOOL bEnable, MS_BOOL bIsYPbPr)
124     - Enable DAC
125     - Select HD or SD DAC
126  -# MApi_DAC_SetOutputSwapSel(E_DAC_SWAP_SEL enSwap,MS_BOOL bIsYPbPr)
127     - Swap type
128     - Select swap HD or SD DAC
129  -# MApi_DAC_SetOutputLevel(E_DAC_MAX_OUTPUT_LEVEL enLevel, MS_BOOL bIsYPbPr)
130     - Level type
131     - Set Level type to HD or SD DAC
132  -# MApi_DAC_SetQuartOutput (MS_BOOL bEnable, MS_BOOL bIsYPbPr)
133  -# MApi_DAC_SetIHalfOutput (MS_BOOL bEnable,MS_BOOL bIsYPbPr)
134     - To save power
135 
136 */
137 #ifndef _API_DAC_H_
138 #define _API_DAC_H_
139 
140 #ifdef __cplusplus
141 extern "C" {
142 #endif
143 
144 //-------------------------------------------------------------------------------------------------
145 //  Macro and Define
146 //-------------------------------------------------------------------------------------------------
147 // library information
148 #define MSIF_DAC_LIB_CODE               {'D','A','C','_'}
149 #define MSIF_DAC_LIBVER                 {'0','0'}
150 #define MSIF_DAC_BUILDNUM               {'2','7'}
151 #define MSIF_DAC_CHANGELIST             {'0','0','6','5','8','6','0','4'}
152 
153 #define DAC_API_VERSION                 /* Character String for DRV/API version             */  \
154     MSIF_TAG,                           /* 'MSIF'    */  \
155     MSIF_CLASS,                         /* '00'      */  \
156     MSIF_CUS,                           /* 0x0000    */  \
157     MSIF_MOD,                           /* 0x0000    */  \
158     MSIF_CHIP,                                           \
159     MSIF_CPU,                                            \
160     MSIF_DAC_LIB_CODE  ,                /* IP__      */  \
161     MSIF_DAC_LIBVER    ,                /* 0.0 ~ Z.Z */  \
162     MSIF_DAC_BUILDNUM  ,                /* 00 ~ 99   */  \
163     MSIF_DAC_CHANGELIST,                /* CL#       */  \
164     MSIF_OS
165 
166 //-------------------------------------------------------------------------------------------------
167 //  Type and Structure
168 //-------------------------------------------------------------------------------------------------
169 /// Define return value of MApi_DAC
170 typedef enum
171 {
172     E_APIDAC_FAIL = 0,
173     E_APIDAC_OK = 1,
174     E_APIDAC_GET_BASEADDR_FAIL,            ///< get base address failed when initialize panel driver
175     E_APIDAC_OBTAIN_MUTEX_FAIL,            ///< obtain mutex timeout when calling this function
176 } APIDAC_Result;
177 
178 /// Define output video timing
179 /// Shall align to E_DAC_PANEL_INDEX.
180 typedef enum
181 {
182     E_RES_720x480I_60Hz = 0,
183     E_RES_720x480P_60Hz,
184     E_RES_720x576I_50Hz,
185     E_RES_720x576P_50Hz,
186     E_RES_1280x720P_50Hz,
187     E_RES_1280x720P_60Hz,
188     E_RES_1920x1080I_50Hz,
189     E_RES_1920x1080I_60Hz,
190     E_RES_1920x1080P_50Hz,
191     E_RES_1920x1080P_60Hz,
192     E_RES_1920x1080P_30Hz,
193     E_RES_1920x1080P_25Hz,
194     E_RES_1920x1080P_24Hz,
195     E_RES_640x480P_60Hz,
196     E_RES_1920x2205P_24Hz,
197     E_RES_1280x1470P_50Hz,
198     E_RES_1280x1470P_60Hz,
199     E_RES_3840x2160P_24Hz,
200     E_RES_3840x2160P_25Hz,
201     E_RES_3840x2160P_30Hz,
202     E_RES_3840x2160P_50Hz,
203     E_RES_3840x2160P_60Hz,
204     E_RES_4096x2160P_24Hz,
205     E_RES_4096x2160P_25Hz,
206     E_RES_4096x2160P_30Hz,
207     E_RES_4096x2160P_50Hz,
208     E_RES_4096x2160P_60Hz,
209     E_RES_VGA_START = 0x40,      ///< Resolution for VGA output
210     E_RES_VGA640x480P_60Hz = E_RES_VGA_START,
211     E_RES_TTL_START = 0xC0,      ///< Resolution for TTL output(will not coexist with VGA).
212     E_RES_TTL480X272P_60Hz = E_RES_TTL_START,
213 } E_OUTPUT_VIDEO_TIMING_TYPE;
214 
215 /// Define the color depth of output
216 typedef enum
217 {
218     E_COLOR_8_BIT,
219     E_COLOR_10_BIT,
220     E_COLOR_12_BIT,
221 }E_OUTPUT_BIT_TYPE;
222 
223 typedef enum
224 {
225     E_DAC_TO_HDGEN = 0,     //HD Gen output
226     E_DAC_TO_VE = 1,        //VE output (CVBS + S-Video)
227     E_DAC_TO_VE_YPBPR =3    //VE output (Y/Pb/Pr)
228 } E_DAC_OUTPUT_TYPE;
229 
230 typedef enum
231 {
232     E_DAC_R_G_B = 0,
233     E_DAC_R_B_G = 1,
234     E_DAC_G_R_B = 2,
235     E_DAC_B_G_R = 4,
236     E_DAC_G_B_R = 5,
237     E_DAC_B_R_G = 6,
238     E_DAC_R_R_R = 7,
239 } E_DAC_SWAP_SEL;
240 
241 typedef enum
242 {
243     E_DAC_OUTPUT_LEVEL_HIGH = 0,  //1.3V for CVBS + S-Video
244     E_DAC_OUTPUT_LEVEL_LOW = 1    //1.0V for YPbPr
245 } E_DAC_MAX_OUTPUT_LEVEL;
246 
247 typedef enum
248 {
249     E_DAC_SD_OFF =0,
250     E_DAC_SD_X = 1,
251     E_DAC_SD_Y = 2,
252     E_DAC_SD_XY = 3,
253     E_DAC_SD_C = 4,
254     E_DAC_SD_XC = 5,
255     E_DAC_SD_YC = 6,
256     E_DAC_SD_XYC = 7,
257 }E_DAC_SD_ENABLE_CTRL;
258 
259 typedef enum
260 {
261     E_DAC_HD_OFF =0,
262     E_DAC_HD_R = 1,
263     E_DAC_HD_G = 2,
264     E_DAC_HD_RG = 3,
265     E_DAC_HD_B = 4,
266     E_DAC_HD_RB = 5,
267     E_DAC_HD_GB = 6,
268     E_DAC_HD_RGB = 7,
269 
270 }E_DAC_HD_ENABLE_CTRL;
271 
272 typedef enum
273 {
274     E_DAC_DETECT_PLUGIN,       //Detect  Plug_IN
275     E_DAC_DETECT_PLUGOUT,     // Detect Plug_OUT
276 }E_DAC_DETECT_TYPE;
277 
278 typedef enum
279 {
280     E_DAC_DETECT_HD,       //Detect  Plug_IN
281     E_DAC_DETECT_SD,     // Detect Plug_OUT
282 }E_DAC_DETECT;
283 
284 typedef struct
285 {
286     MS_U32 u32Type;
287 }APIDAC_OUTPUT_TYPE;
288 
289 typedef struct
290 {
291     APIDAC_OUTPUT_TYPE eSupportOutputType;   ///< Gamma type supported by apiPNL
292 } DAC_ApiInfo;
293 
294 typedef struct
295 {
296     MS_BOOL bDac_Initialized;       ///< DAC initialized or not
297     MS_BOOL bDac_VE_enabled;        ///< DAC CVBS/S-Video enabled or not
298     MS_BOOL bDac_YPbPr_enabled;     ///< DAC YPbPr enabled or not
299 } DAC_ApiStatus;
300 
301 //-------------------------------------------------------------------------------------------------
302 //  Function and Variable
303 //-------------------------------------------------------------------------------------------------
304 
305 /******************************************************************************/
306 /*                     Variable                                            */
307 /* ****************************************************************************/
308 /**
309 *
310 *  The global interface for panel manipulation.
311 *
312 *  @attention <b>Call "MApi_DAC_Init()" first before using this obj</b>
313 */
314 
315 //-------------------------------------------------------------------------------------------------
316 /// Get version (without Mutex protect)
317 /// @param  ppVersion                 \b OUT: Version information of DAC lib.
318 /// @return @ref APIDAC_Result
319 //-------------------------------------------------------------------------------------------------
320 // APIDAC_Result MApi_DAC_GetLibVer(const MSIF_Version **ppVersion);
321 
322 //-------------------------------------------------------------------------------------------------
323 /// Get DAC driver info
324 /// @return the pointer to DAC_ApiInfo structure
325 //-------------------------------------------------------------------------------------------------
326 // const DAC_ApiInfo * MApi_DAC_GetInfo(void);
327 
328 //-------------------------------------------------------------------------------------------------
329 /// Get DAC status
330 /// @param  pDacStatus                \b OUT: the pointer to DAC_ApiStatus structure
331 /// @return @ref MS_BOOL
332 //-------------------------------------------------------------------------------------------------
333 // MS_BOOL MApi_DAC_GetStatus(DAC_ApiStatus *pDacStatus);
334 
335 //-------------------------------------------------------------------------------------------------
336 /// Set DAC debug level
337 /// @param  pDacStatus                \b IN: debug level
338 /// @return @ref MS_BOOL
339 //-------------------------------------------------------------------------------------------------
340 // MS_BOOL MApi_DAC_SetDbgLevel(MS_U16 u16DbgSwitch);
341 
342 //-------------------------------------------------------------------------------------------------
343 /// DAC Initialization
344 /// @return @ref MS_BOOL
345 //-------------------------------------------------------------------------------------------------
346 MS_BOOL MApi_DAC_Init(void);
347 
348 //-------------------------------------------------------------------------------------------------
349 /// DAC configuration enable
350 // @param  bEnable                 \b IN: Enable or Disable DAC
351 // @param  bIsYPbPr                \b IN: The DAC output signal type: YPbPr or CVBS/S-VIDEO
352 //-------------------------------------------------------------------------------------------------
353 void MApi_DAC_Enable(MS_BOOL bEnable, MS_BOOL bIsYPbPr);
354 
355 //-------------------------------------------------------------------------------------------------
356 /// Set DAC clock inv
357 // @param  bEnable                 \b IN: Enable or Disable clock INV
358 // @param  bIsYPbPr                \b IN: The DAC output signal type: YPbPr or CVBS/S-VIDEO
359 //-------------------------------------------------------------------------------------------------
360 void MApi_DAC_SetClkInv(MS_BOOL bEnable, MS_BOOL bIsYPbPr);
361 
362 //-------------------------------------------------------------------------------------------------
363 /// Set DAC output timing for hdgen(YPbPr)
364 // @param  eTiming                   \b IN: The output timing type for YPbPr
365 //-------------------------------------------------------------------------------------------------
366 void MApi_DAC_SetYPbPrOutputTiming(E_OUTPUT_VIDEO_TIMING_TYPE eTiming);
367 
368 //-------------------------------------------------------------------------------------------------
369 /// Set DAC output sourcec
370 // @param  enOutputType         \b IN: The output source type
371 // @param  bIsYPbPr                \b IN: The DAC output signal type: YPbPr or CVBS/S-VIDEO
372 //-------------------------------------------------------------------------------------------------
373 void MApi_DAC_SetOutputSource(E_DAC_OUTPUT_TYPE enOutputType, MS_BOOL bIsYPbPr);
374 
375 //-------------------------------------------------------------------------------------------------
376 /// Set DAC output Voltage
377 // @param  enLevel                  \b IN: The output maximun output Voltage
378 // @param  bIsYPbPr                \b IN: The DAC output signal type: YPbPr or CVBS/S-VIDEO
379 //-------------------------------------------------------------------------------------------------
380 void MApi_DAC_SetOutputLevel(E_DAC_MAX_OUTPUT_LEVEL enLevel, MS_BOOL bIsYPbPr);
381 
382 //-------------------------------------------------------------------------------------------------
383 /// Set DAC Swap three output
384 // @param  enSwap                 \b IN: swap three output (RGB/XYC)
385 // @param  bIsYPbPr                \b IN: The DAC output signal type: YPbPr or CVBS/S-VIDEO
386 //-------------------------------------------------------------------------------------------------
387 void MApi_DAC_SetOutputSwapSel(E_DAC_SWAP_SEL enSwap,MS_BOOL bIsYPbPr);
388 
389 //-------------------------------------------------------------------------------------------------
390 /// Control DAC SD output En/Disable
391 // @param  enBit                \b IN: XYC
392 //-------------------------------------------------------------------------------------------------
393 void MApi_DAC_OnOffSD(E_DAC_SD_ENABLE_CTRL enBit);
394 
395 //-------------------------------------------------------------------------------------------------
396 /// Control DAC HD output En/Disable
397 // @param  enBit                \b IN: RGB
398 //-------------------------------------------------------------------------------------------------
399 void MApi_DAC_OnOffHD(E_DAC_HD_ENABLE_CTRL enBit);
400 
401 //-------------------------------------------------------------------------------------------------
402 /// Set common clock mux for DAC & HDMITx
403 // @param  eTiming                   \b IN: The output timing type
404 // @param  ebits                     \b IN: The output bit type
405 //-------------------------------------------------------------------------------------------------
406 // void MApi_DAC_ClkSel(E_OUTPUT_VIDEO_TIMING_TYPE eTiming, E_OUTPUT_BIT_TYPE ebits);
407 
408 void MApi_DAC_DumpTable(MS_U8 *pDACTable, MS_U8 u8DACtype);
409 
410 // void MApi_DAC_Exit(void);
411 
412 //----------------------------------------------------------------
413 // DAC - set half output current
414 // @return none
415 //----------------------------------------------------------------
416 void MApi_DAC_SetIHalfOutput(MS_BOOL bEnable, MS_BOOL bIsYPbPr);
417 
418 //----------------------------------------------------------------
419 // DAC - set quart output current
420 // @return none
421 //----------------------------------------------------------------
422 void MApi_DAC_SetQuartOutput(MS_BOOL bEnable,MS_BOOL bIsYPbPr);
423 
424 //----------------------------------------------------------------
425 // DAC - SetDacState
426 // When DAC is already enabled in the MBoot, we can use this function to
427 // mark the DAC init state as "enabled".
428 // @bInited: TRUE: enabled, FALSE: not enabled
429 // @bIsYPbPr: TRUE: HD, FALSE: SD
430 // @return none
431 //----------------------------------------------------------------
432 void MApi_DAC_SetDacState(MS_BOOL bEnabled, MS_BOOL bIsYPbPr);
433 
434 //----------------------------------------------------------------
435 // MApi_DAC_HotPlugDetect - Get DAC HotPlug state
436 // @param: SelDAC: DAC_DETECT_HD, DAC_DETECT_SD
437 // @param: DetectType: DAC_DETECT_PLUGIN, DAC_DETECT_PLUGOUT
438 // @param: bIsSignIn: Report signal is in/out
439 // @return: TRUE is working successful
440 //----------------------------------------------------------------
441 // MS_BOOL MApi_DAC_HotPlugDetect(E_DAC_DETECT SelDAC,E_DAC_DETECT_TYPE DetectType, MS_BOOL *State);
442 
443 #ifdef __cplusplus
444 }
445 #endif
446 
447 #endif
448 
449