xref: /utopia/UTPA2-700.0.x/projects/tmplib/include/drvSAR.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) 2009-2010 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   drvSAR.h
98 /// @brief  SAR Driver Interface
99 /// @author MStar Semiconductor Inc.
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101 
102 /*! \defgroup G_SAR SAR interface
103    *  \ingroup  G_PERIPHERAL
104 
105    \brief
106 
107    Successive Approximation Register controller
108 
109    <b>Features</b>
110 
111     - Keypa
112     - SCART control signal detection
113     - RF AGC level detection
114     - GPIO
115 
116     <b>Successive approximation ADC Diagram</b> \n
117      \image html drvSAR_pic.png
118 
119      \defgroup G_SAR_INIT Initialization Task relative
120      \ingroup  G_SAR
121      \defgroup G_SAR_COMMON Common Task relative
122      \ingroup  G_SAR
123      \defgroup G_SAR_CONTROL Control relative
124      \ingroup  G_SAR
125      *\defgroup G_SAR_OTHER  other relative
126      *\ingroup  G_SAR
127      *\defgroup G_SAR_ToBeModified SAR api to be modified
128      *\ingroup  G_SAR
129      \defgroup G_SAR_ToBeRemove SAR api to be removed
130      \ingroup  G_SAR
131 */
132 
133 #ifndef _DRV_SAR_H_
134 #define _DRV_SAR_H_
135 
136 
137 #ifdef __cplusplus
138 extern "C"
139 {
140 #endif
141 
142 #include "MsTypes.h"
143 #include "MsDevice.h"
144 //-------------------------------------------------------------------------------------------------
145 //  Driver Capability
146 //-------------------------------------------------------------------------------------------------
147 
148 
149 //-------------------------------------------------------------------------------------------------
150 //  Macro and Define
151 //-------------------------------------------------------------------------------------------------
152 /// define SAR library version
153 #define MSIF_SAR_LIB_CODE               {'S','A','R','_'}
154 #define MSIF_SAR_LIBVER                 {'0','3'}
155 #define MSIF_SAR_BUILDNUM               {'0','9'}
156 #define MSIF_SAR_CHANGELIST             {'0','0','4','3','3','2','5','1'}
157 
158 #define SAR_DRV_VERSION                 /* Character String for DRV/API version  */  \
159     MSIF_TAG,                           /* 'MSIF' */  \
160     MSIF_CLASS,                         /* '00' */  \
161     MSIF_CUS,                           /* 0x0000 */  \
162     MSIF_MOD,                           /* 0x0000 */  \
163     MSIF_CHIP,                                       \
164     MSIF_CPU,                                        \
165     MSIF_SAR_LIB_CODE,                  /* IP__ */  \
166     MSIF_SAR_LIBVER,                    /* 0.0 ~ Z.Z */  \
167     MSIF_SAR_BUILDNUM,                  /* 00 ~ 99 */  \
168     MSIF_SAR_CHANGELIST,                /* CL# */  \
169     MSIF_OS
170 
171 /// SAR driver
172 #define SAR_VERSION_STRING_MAX      33
173 #define SAR_DUMMY_KEY               0xFF
174 #define SAR_DUMMY_STATUS            0x00
175 #define SAR_VERSION            0x00000001
176 
177 //-------------------------------------------------------------------------------------------------
178 //  Type and Structure
179 //-------------------------------------------------------------------------------------------------
180 //##################################
181 //
182 //  Access SAR settings by using Mailbox
183 //  sent commands to PM
184 //
185 //##################################
186 /// define SAR driver info
187 typedef struct __attribute__((aligned (4096)))
188 {
189     MS_U8 u8TrigMode : 1;  /// SAR trigger mode. 0: edge trigger, 1: level trigger
190     MS_U8 u8OprMode : 1;   /// SAR operation mode. 0: one-shot, 1: free run
191     MS_U8 u8CfgdChs : 3;   /// SAR configured channels
192     MS_U8 u8Reserved : 3;  /// reserved for future
193 }SAR_DrvInfo;
194 
195 /// define SAR channel bound
196 typedef struct
197 {
198     MS_U8 u8UpBnd;  ///upper bound
199     MS_U8 u8LoBnd;  ///low bound
200 } SAR_BndCfg;
201 
202 /// define SAR parameter configuration
203 typedef struct __attribute__((aligned (4096)))
204 {
205     MS_U8 u8SARChID;          /// SAR channel ID: from 0
206     MS_U8 u8UpBnd;            ///upper bound
207     MS_U8 u8LoBnd;            ///low bound
208     MS_U8 u8KeyLevelNum;      /// SAR key level number
209     MS_U8 u8KeyThreshold[8];  /// SAR key thresholds
210     MS_U8 u8KeyCode[8];       /// SAR key code
211 } SAR_RegCfg;
212 
213 /// emurate SAR fucntion return result
214 typedef enum
215 {
216     /// SAR result for failure
217     E_SAR_FAIL =0,
218     /// SAR result for OK
219     E_SAR_OK = 1,
220 
221 } SAR_Result;
222 
223 /// emurate SAR Level for 2.2V or 3.3V
224 typedef enum
225 {
226     /// SAR result for failure
227     E_SAR_20V =0,
228     /// SAR result for OK
229     E_SAR_33V = 1,
230 
231 } SAR_LEVEL;
232 
233 
234 /// emurate SAR status
235 typedef enum
236 {
237     /// SAR Driver Status: Initialization OK
238     E_SAR_INIT_OK = (1<<0),
239     /// SAR Driver Status: Callback installed
240     E_SAR_INST_CLBK = (1<<1),
241     /// SAR Driver Status: Get key code
242     E_SAR_KEY_CODE = (1<<2),
243     /// SAR Driver Status: SAR is enabled
244     E_SAR_ENABLE = (1<<3),
245     /// SAR Driver Status: Maximum status
246     E_SAR_MAX_STATUS = 255
247 } SAR_Status;
248 
249 //-------------------------------
250 // Mailbox Class : SAR
251 //-------------------------------
252 /// emurate SAR mailbox commands from cpu to mcu51
253 typedef enum
254 {
255     /// mbx command for initialization
256     E_SAR_CPUTo51_CMD_INIT=0x00,
257     /// mbx command for configuration
258     E_SAR_CPUTo51_CMD_CONFIG,
259     /// mbx command for key code
260     E_SAR_CPUTo51_CMD_KEYCODE,
261     /// mbx command for set callback
262     E_SAR_CPUTo51_CMD_SETCLBK,
263     /// mbx command for library version
264     E_SAR_CPUTo51_CMD_LIBVER,
265     /// mbx command for status
266     E_SAR_CPUTo51_CMD_STATUS,
267     /// mbx command for enable
268     E_SAR_CPUTo51_CMD_ENABLE,
269     /// mbx command for driver info
270     E_SAR_CPUTo51_CMD_INFO,
271 } SAR_CPUTo51CmdIdx;
272 
273 /// emurate SAR mailbox commands ack from mcu51 to cpu
274 typedef enum
275 {
276     //(1) Acknowledge from MCU51
277     /// ack mbx command for initialization
278     E_SAR_51ToCPU_CMD_ACK_INIT=0x00,
279     /// ack mbx command for configuration
280     E_SAR_51ToCPU_CMD_ACK_CONFIG,
281     /// ack mbx command for key code
282     E_SAR_51ToCPU_CMD_ACK_KEYCODE,
283     /// ack mbx command for set callback
284     E_SAR_51ToCPU_CMD_ACK_SETCLBK,
285     /// ack mbx command for library version
286     E_SAR_51ToCPU_CMD_ACK_LIBVER,
287     ///ack mbx command for status
288     E_SAR_51ToCPU_CMD_ACK_STATUS,
289     ///ack mbx command for enable
290     E_SAR_51ToCPU_CMD_ACK_ENABLE,
291     ///ack mbx command for driver info
292     E_SAR_51ToCPU_CMD_ACK_INFO,
293 
294     //(2) Notification from MCU51
295     ///notification mbx command for key code
296     E_SAR_51ToCPU_CMD_KEYCODE,
297 
298 } SAR_51ToCPUCmdIdx;
299 
300 /// emurate ack flags
301 typedef enum
302 {
303     /// ack flag for null
304     E_SAR_ACKFLG_NULL         = 0,
305     /// ack flag for wait initialization
306     E_SAR_ACKFLG_WAIT_INIT    = (1<<0),
307     /// ack flag for wait configuration
308     E_SAR_ACKFLG_WAIT_CONFIG  = (1<<1),
309     /// ack flag for wait key code
310     E_SAR_ACKFLG_WAIT_KEYCODE = (1<<2),
311     /// ack flag for wait set callback
312     E_SAR_ACKFLG_WAIT_SETCLBK = (1<<3),
313     /// ack flag for wait library version
314     E_SAR_ACKFLG_WAIT_LIBVER  = (1<<4),
315     /// ack flag for wait status
316     E_SAR_ACKFLG_WAIT_STATUS  = (1<<5),
317     /// ack flag for wait enable
318     E_SAR_ACKFLG_WAIT_ENABLE  = (1<<6),
319     /// ack flag for wait driver info
320     E_SAR_ACKFLG_WAIT_INFO    = (1<<7),
321 } SAR_AckFlags;
322 
323 /// Callback function which is called in SAR ISR.
324 typedef void ( *SAR_Callback ) (MS_U8 u8Key, MS_U8 u8RepeatFlag);
325 
326 ///Define SAR debug level
327 typedef enum _SAR_DbgLvl
328 {
329     E_SAR_DBGLVL_NONE = 0,      /// no debug message
330     E_SAR_DBGLVL_WARNING,       /// show warning only
331     E_SAR_DBGLVL_ERROR,         /// show error only
332     E_SAR_DBGLVL_INFO,          /// show error & informaiton
333     E_SAR_DBGLVL_ALL,           /// show error, information & funciton name
334 }SAR_DbgLvl;
335 
336 
337 
338 //##################################
339 //
340 //  Access SAR settings directly by RIU without
341 //  using Mailbox sent commands to PM
342 //
343 //##################################
344 /// emurate SAR Kpd fucntion return result
345 typedef enum
346 {
347     /// SAR result for failure
348     E_SAR_KPD_FAIL =0,
349     /// SAR result for OK
350     E_SAR_KPD_OK = 1,
351 
352 } SAR_KpdResult;
353 
354 /// define SAR Kpd Bounds
355 typedef struct
356 {
357     MS_U8 u8UpBnd;   //upper bound
358     MS_U8 u8LoBnd;  //low bound
359 } SAR_KpdBndCfg;
360 
361 /// define SAR Kpd Configuration
362 typedef struct
363 {
364     MS_U8 u8SARChID;
365     SAR_KpdBndCfg tSARChBnd;
366     MS_U8 u8KeyLevelNum;
367     MS_U8 u8KeyThreshold[8];
368     MS_U8 u8KeyCode[8];
369 } SAR_KpdRegCfg;
370 
371 /// define SAR driver info
372 typedef struct
373 {
374     MS_U8 u8TrigMode : 1; /// SAR trigger mode. 0: edge trigger, 1: level trigger
375     MS_U8 u8SingleChEn : 1; /// SAR single channel enable
376     MS_U8 u8DigitOprMode : 1; /// SAR operation mode. 0: one-shot, 1: free run
377     MS_U8 u8AtopFreerun : 1; /// SAR atop freerun mode. 0: controlled by digital, 1: free run
378     MS_U8 u8DigitPwrDn : 1; /// SAR digital power down
379     MS_U8 u8AtopPwrDn : 1; /// SAR atop power down
380     MS_U8 u8HighChEn : 1; /// SAR high channel enable
381     MS_U8 u8InterruptEn : 1; /// SAR interrupt enable
382 
383     MS_U8 u8ConfigUsedChs : 3; /// SAR configured channels
384     MS_U8 u8MaxKpdSuppChs : 3; /// SAR IP max keypad channels supported
385     MS_U8 u8Reserved: 2;///RFU1
386     MS_U8 u8MaxKpdAvlbChs : 3; /// SAR driver max keypad channels provided
387     MS_U8 u8MaxKpdAvlbLvls: 5; // /SAR driver max keypad channel levels provided
388 } SAR_KpdDrvInfo;
389 
390 /// emurate SAR status
391 typedef enum
392 {
393     E_SAR_KPD_INVALID=0,
394     /// SAR Driver Status: Initialization OK
395     E_SAR_KPD_INIT_OK = (1<<0),
396     /// SAR Driver Status: Not Supported
397     E_SAR_KPD_NOT_SUP = (1<<1),
398     /// SAR Driver Status: Maximum status
399     E_SAR_KPD_MAX_STATUS = 255
400 } SAR_KpdStatus;
401 
402 
403 ///Define SAR debug level
404 typedef enum
405 {
406     E_SAR_KPD_DBGLVL_NONE = 0,      /// no debug message
407     E_SAR_KPD_DBGLVL_WARNING,       /// show warning only
408     E_SAR_KPD_DBGLVL_ERROR,         /// show error only
409     E_SAR_KPD_DBGLVL_INFO,          /// show error & informaiton
410     E_SAR_KPD_DBGLVL_ALL,           /// show error, information & funciton name
411 }SAR_KpdDbgLvl;
412 
413 //##################
414 //
415 //   For SAR ADC functions
416 //
417 //##################
418 /// emurate SAR ADC fucntion return result
419 typedef enum
420 {
421     /// SAR result for failure
422     E_SAR_ADC_FAIL =0,
423     /// SAR result for OK
424     E_SAR_ADC_OK = 1,
425 
426 } SAR_AdcResult;
427 
428 ///Define SAR ADC debug level
429 typedef enum
430 {
431     E_SAR_ADC_DBGLVL_NONE = 0,      /// no debug message
432     E_SAR_ADC_DBGLVL_WARNING,       /// show warning only
433     E_SAR_ADC_DBGLVL_ERROR,         /// show error only
434     E_SAR_ADC_DBGLVL_INFO,          /// show error & informaiton
435     E_SAR_ADC_DBGLVL_ALL,           /// show error, information & funciton name
436 }SAR_AdcDbgLvl;
437 
438 ///Define RGB HSync ADC channel
439 typedef enum
440 {
441     E_SAR_ADC_HSYNC_CH0 = 0,  /// ADC HSync channel 0
442     E_SAR_ADC_HSYNC_CH1,      /// ADC HSync channel 1
443     E_SAR_ADC_HSYNC_CH2,      /// ADC HSync channel 2
444     E_SAR_ADC_HSYNC_CH3,      /// ADC HSync channel 3
445     E_SAR_ADC_HSYNC_CHMAX,    /// ADC HSync channel max
446 }SAR_AdcHSyncCh;
447 
448 //##################
449 //
450 //   For SAR GPIO functions
451 //
452 //##################
453 /// emurate SAR GPIO fucntion return result
454 typedef enum
455 {
456     /// SAR result for failure
457     E_SAR_GPIO_FAIL =0,
458     /// SAR result for OK
459     E_SAR_GPIO_OK = 1,
460 
461 } SAR_GpioResult;
462 
463 ///Define SAR GPIO debug level
464 typedef enum
465 {
466     E_SAR_GPIO_DBGLVL_NONE = 0,      /// no debug message
467     E_SAR_GPIO_DBGLVL_WARNING,       /// show warning only
468     E_SAR_GPIO_DBGLVL_ERROR,         /// show error only
469     E_SAR_GPIO_DBGLVL_INFO,          /// show error & informaiton
470     E_SAR_GPIO_DBGLVL_ALL,           /// show error, information & funciton name
471 }SAR_GpioDbgLvl;
472 
473 //Define SAR GetKey Value Struct  ==========
474 typedef struct _SAR_KeyValue_Data_Member
475 {
476     MS_U8 u8Channel;
477     MS_U8 u8Key;
478     MS_U8 u8Repeat;
479 }SAR_KeyValue_Data_Member;
480 
481 typedef union
482 {
483     SAR_KeyValue_Data_Member sData[16];
484 } SAR_KeyValue_Data;
485 
486 typedef struct _SAR_KeyValue
487 {
488     MS_U32 u32Version;
489     SAR_KeyValue_Data unSarKeyData;
490     MS_U32 u32Num; //u32Num indicate number of current  really getting SAR key
491 }SAR_KeyValue;
492 //===============================
493 
494 //-------------------------------------------------------------------------------------------------
495 //  Function and Variable
496 //-------------------------------------------------------------------------------------------------
497 //##################################
498 //
499 //  Access SAR settings by using Mailbox
500 //  sent commands to PM
501 //
502 //##################################
503 //-------------------------------------------------------------------------------------------------
504 /// SAR Iinitialized function before using SAR to receive keys. (This sends command to PM51 using mailbox.)
505 /// @ingroup G_SAR_INIT
506 /// @return E_SAR_OK: Success
507 /// @return E_SAR_FAIL or other values: Failure
508 //-------------------------------------------------------------------------------------------------
509 SAR_Result MDrv_SAR_Init(void);
510 
511 
512 //-------------------------------------------------------------------------------------------------
513 /// SAR parameter configuration function. (This sends command to PM51 using mailbox.)
514 /// @ingroup G_SAR_COMMON
515 /// @param pSARRegCfg \b IN: pointer to the SAR configuration structure.
516 /// @return E_SAR_OK: Success
517 /// @return E_SAR_FAIL or other values: Failure
518 //-------------------------------------------------------------------------------------------------
519 SAR_Result MDrv_SAR_Config(SAR_RegCfg *pSARRegCfg);
520 
521 
522 //-------------------------------------------------------------------------------------------------
523 /// SAR get key code function. (This sends command to PM51 using mailbox.)
524 /// @ingroup G_SAR_COMMON
525 /// @param pu8Key \b OUT: Get SAR key code
526 /// @param pu8Repeat \b OUT: Get SAR key repeat status
527 /// @return E_SAR_OK: Success
528 /// @return E_SAR_FAIL or other values: Failure
529 //-------------------------------------------------------------------------------------------------
530 SAR_Result MDrv_SAR_GetKeyCode(MS_U8 *pu8Key, MS_U8 *pu8Repeat);
531 
532 
533 //-------------------------------------------------------------------------------------------------
534 /// Set SAR callback function when receive SAR key. Support only one callback. If call it twice,
535 /// the first callback does not be called. (This sends command to PM51 using mailbox.)
536 /// Note: The callback runs at interrupt mode.
537 /// @ingroup G_SAR_COMMON
538 /// @param pCallback \b IN: Set the callback function when generate SAR interrupt.
539 /// @return E_SAR_OK: Success
540 /// @return E_SAR_FAIL or other values: Failure
541 //-------------------------------------------------------------------------------------------------
542 SAR_Result MDrv_SAR_SetCallback(SAR_Callback pCallback);
543 
544 
545 //-------------------------------------------------------------------------------------------------
546 /// Get SAR callback function which receive SAR key.
547 /// @ingroup G_SAR_COMMON
548 /// @return the callback function when generate SAR interrupt
549 //-------------------------------------------------------------------------------------------------
550 // SAR_Callback MDrv_SAR_GetCallback(void);
551 
552 
553 //-------------------------------------------------------------------------------------------------
554 /// Get SAR library version function.
555 /// @ingroup G_SAR_COMMON
556 /// @param ppVersion \b OUT: pointer to library structure
557 /// @return E_SAR_OK: Success
558 /// @return E_SAR_FAIL or other values: Failure
559 //-------------------------------------------------------------------------------------------------
560 // SAR_Result MDrv_SAR_GetLibVer(const MSIF_Version **ppVersion);
561 
562 
563 //-------------------------------------------------------------------------------------------------
564 /// Get SAR status function. (This sends command to PM51 using mailbox.)
565 /// @ingroup G_SAR_COMMON
566 /// @param pu8SARStatus \b OUT: pointer to status structure
567 /// @return E_SAR_OK: Success
568 /// @return E_SAR_FAIL or other values: Failure
569 //-------------------------------------------------------------------------------------------------
570 // SAR_Result MDrv_SAR_GetStatus(MS_U8 *pu8SARStatus);
571 
572 
573 //-------------------------------------------------------------------------------------------------
574 /// Set SAR enable function. (This sends command to PM51 using mailbox.)
575 /// @ingroup G_SAR_COMMON
576 /// @param bEnable \b IN: TRUE: enable SAR, FALSE: disable SAR
577 /// @return E_SAR_OK: Success
578 /// @return E_SAR_FAIL or other values: Failure
579 //-------------------------------------------------------------------------------------------------
580 SAR_Result MDrv_SAR_Enable(MS_BOOL bEnable);
581 
582 
583 //-------------------------------------------------------------------------------------------------
584 /// Get SAR driver information function. (This sends command to PM51 using mailbox.)
585 /// @ingroup G_SAR_COMMON
586 /// @return @ref SAR_DrvInfo structure
587 //-------------------------------------------------------------------------------------------------
588 // const SAR_DrvInfo* MDrv_SAR_GetInfo(void);
589 
590 //-------------------------------------------------------------------------------------------------
591 /// Set SAR debug function level.
592 /// @ingroup G_SAR_COMMON
593 /// @param eLevel \b IN: E_SAR_DBGLVL_NONE/E_SAR_DBGLVL_WARNING/E_SAR_DBGLVL_ERROR/E_SAR_DBGLVL_INFO/E_SAR_DBGLVL_ALL
594 /// @return E_SAR_OK: Success
595 /// @return E_SAR_FAIL or other values: Failure
596 //-------------------------------------------------------------------------------------------------
597 SAR_Result MDrv_SAR_SetDbgLevel(SAR_DbgLvl eLevel);
598 
599 
600 
601 //##################################
602 //
603 //  Access SAR settings directly by RIU without
604 //  using Mailbox sent commands to PM
605 //
606 //##################################
607 //-------------------------------------------------------------------------------------------------
608 /// Set SAR Keypad initialized function.
609 /// @ingroup G_SAR_INIT
610 /// @param None:
611 /// @return E_SAR_KPD_OK: Success
612 /// @return E_SAR_KPD_FAIL or other values: Failure
613 //-------------------------------------------------------------------------------------------------
614 SAR_KpdResult MDrv_SAR_Kpd_Init(void);
615 
616 //-------------------------------------------------------------------------------------------------
617 /// Set SAR Keypad channel information function.
618 /// @ingroup G_SAR_COMMON
619 /// @param sarChInfo: sar channel info pointer
620 /// @return E_SAR_KPD_OK: Success
621 /// @return E_SAR_KPD_FAIL or other values: Failure
622 //-------------------------------------------------------------------------------------------------
623 SAR_KpdResult MDrv_SAR_Kpd_SetChInfo(SAR_KpdRegCfg *sarChInfo);
624 
625 //-------------------------------------------------------------------------------------------------
626 /// Get SAR Keypad key code function.
627 /// @ingroup G_SAR_COMMON
628 /// @param pu8Key: key code pointer
629 /// @param pu8Repeat: key repeat pointer
630 /// @return E_SAR_KPD_OK: Success
631 /// @return E_SAR_KPD_FAIL or other values: Failure
632 //-------------------------------------------------------------------------------------------------
633 SAR_KpdResult MDrv_SAR_Kpd_GetKeyCode(MS_U8 *pu8Key, MS_U8 *pu8Repeat);
634 
635 //-------------------------------------------------------------------------------------------------
636 /// Get SAR Multi-Keypad key code function with every SAR channel
637 /// @ingroup G_SAR_COMMON
638 /// @param SAR_KeyValue: key code struct pointer
639 /// @param u32Size: Struct Size
640 /// @return E_SAR_KPD_OK: Success
641 /// @return E_SAR_KPD_FAIL or other values: Failure
642 //-------------------------------------------------------------------------------------------------
643 // SAR_KpdResult MDrv_SAR_Kpd_GetMultiKeyCode(SAR_KeyValue *sSarKey, MS_U32 u32Size);
644 
645 //-------------------------------------------------------------------------------------------------
646 /// Get SAR current status function.
647 /// @ingroup G_SAR_COMMON
648 /// @param None:
649 /// @return E_SAR_KPD_INIT_OK: Init OK
650 /// @return others: other status
651 //-------------------------------------------------------------------------------------------------
652 SAR_KpdStatus MDrv_SAR_Kpd_GetStatus(void);
653 
654 //-------------------------------------------------------------------------------------------------
655 /// Get SAR Keypad driver information function.
656 /// @ingroup G_SAR_COMMON
657 /// @return @ref SAR_KpdDrvInfo structure
658 //-------------------------------------------------------------------------------------------------
659 const SAR_KpdDrvInfo* MDrv_SAR_Kpd_GetInfo(void);
660 
661 //-------------------------------------------------------------------------------------------------
662 /// Set SAR Keypad debug function level.
663 /// @ingroup G_SAR_COMMON
664 /// @param eLevel \b IN: E_SAR_KPD_DBGLVL_NONE/E_SAR_KPD_DBGLVL_WARNING/E_SAR_KPD_DBGLVL_ERROR/E_SAR_KPD_DBGLVL_INFO/E_SAR_KPD_DBGLVL_ALL
665 /// @return E_SAR_KPD_OK: Success
666 /// @return E_SAR_KPD_FAIL or other values: Failure
667 //-------------------------------------------------------------------------------------------------
668 // SAR_KpdResult MDrv_SAR_Kpd_SetDbgLevel(SAR_KpdDbgLvl eLevel);
669 
670 //-------------------------------------------------------------------------------------------------
671 /// Set SAR as ADC channel.
672 /// @ingroup G_SAR_COMMON
673 /// @param u8Channel: sar ADC channel 0~7
674 /// @param bEnable: 1: configured as ADC, 0: configured as GPIO input
675 /// @return E_SAR_ADC_OK: Success
676 /// @return E_SAR_ADC_FAIL or other values: Failure
677 //-------------------------------------------------------------------------------------------------
678 SAR_AdcResult MDrv_SAR_Adc_Config(MS_U8 u8Channel,MS_BOOL bEnable);
679 
680 //-------------------------------------------------------------------------------------------------
681 /// Get ADC value function for each SAR channel.
682 /// @ingroup G_SAR_COMMON
683 /// @param u8Channel: sar ADC channel 0~7
684 /// @return MS_U8: ADC value
685 //-------------------------------------------------------------------------------------------------
686 MS_U8 MDrv_SAR_Adc_GetValue(MS_U8 u8Channel);
687 
688 //-------------------------------------------------------------------------------------------------
689 /// Set SAR High channel function for RGB HSync application
690 /// @ingroup G_SAR_COMMON
691 /// @param bEnable: 1: enable high channel, 0: disable high channel
692 /// @return E_SAR_ADC_OK: Success
693 /// @return E_SAR_ADC_FAIL or other values: Failure
694 //-------------------------------------------------------------------------------------------------
695 SAR_AdcResult MDrv_SAR_Adc_SetHSyncChEn(MS_BOOL bEnable);
696 
697 //-------------------------------------------------------------------------------------------------
698 /// Switch RGB HSync MUX to direct signal to SAR High channel
699 /// @ingroup G_SAR_COMMON
700 /// @param u8HsynCh: HSync channel: 0, 1, 2, 3
701 /// @return E_SAR_ADC_OK: Success
702 /// @return E_SAR_ADC_FAIL or other values: Failure
703 //-------------------------------------------------------------------------------------------------
704 SAR_AdcResult MDrv_SAR_Adc_SetHSyncCh(SAR_AdcHSyncCh eHSyncCh);
705 
706 //-------------------------------------------------------------------------------------------------
707 /// Set SAR ADC debug function level.
708 /// @ingroup G_SAR_COMMON
709 /// @param eLevel \b IN: E_SAR_ADC_DBGLVL_NONE/E_SAR_ADC_DBGLVL_WARNING/E_SAR_ADC_DBGLVL_ERROR/E_SAR_ADC_DBGLVL_INFO/E_SAR_ADC_DBGLVL_ALL
710 /// @return E_SAR_ADC_OK: Success
711 /// @return E_SAR_ADC_FAIL or other values: Failure
712 //-------------------------------------------------------------------------------------------------
713 // SAR_AdcResult MDrv_SAR_Adc_SetDbgLevel(SAR_AdcDbgLvl eLevel);
714 
715 //-------------------------------------------------------------------------------------------------
716 /// Set SAR as GPIO channel.
717 /// @ingroup G_SAR_COMMON
718 /// @param u8Channel: sar GPIO channel 0~7
719 /// @param u8InOut: 1: Input, 0:output
720 /// @return E_SAR_GPIO_OK: Success
721 /// @return E_SAR_GPIO_FAIL or other values: Failure
722 //-------------------------------------------------------------------------------------------------
723 SAR_GpioResult MDrv_SAR_Gpio_CfgDir(MS_U8 u8Channel,MS_BOOL u8InOut);
724 
725 //-------------------------------------------------------------------------------------------------
726 /// Set SAR GPIO channel High/Low
727 /// @ingroup G_SAR_CONTROL
728 /// @param u8Channel: sar GPIO channel 0~7
729 /// @param bHighLow: 1: High, 0:low
730 /// @return E_SAR_GPIO_OK: Success
731 /// @return E_SAR_GPIO_FAIL or other values: Failure
732 //-------------------------------------------------------------------------------------------------
733 SAR_GpioResult MDrv_SAR_Gpio_SetOutput(MS_U8 u8Channel,MS_BOOL bHighLow);
734 
735 //-------------------------------------------------------------------------------------------------
736 /// Get SAR GPIO channel High/Low
737 /// @ingroup G_SAR_COMMON
738 /// @param u8Channel: sar GPIO channel 0~7
739 /// @param pbResult: pointer to get Input level
740 /// @return E_SAR_GPIO_OK: Success
741 /// @return E_SAR_GPIO_FAIL or other values: Failure
742 //-------------------------------------------------------------------------------------------------
743 SAR_GpioResult MDrv_SAR_Gpio_GetInput(MS_U8 u8Channel, MS_BOOL* pbResult);
744 
745 //-------------------------------------------------------------------------------------------------
746 /// Set SAR GPIO debug function level.
747 /// @ingroup G_SAR_COMMON
748 /// @param eLevel \b IN: E_SAR_GPIO_DBGLVL_NONE/E_SAR_GPIO_DBGLVL_WARNING/E_SAR_GPIO_DBGLVL_ERROR/E_SAR_GPIO_DBGLVL_INFO/E_SAR_GPIO_DBGLVL_ALL
749 /// @return E_SAR_GPIO_OK: Success
750 /// @return E_SAR_GPIO_FAIL or other values: Failure
751 //-------------------------------------------------------------------------------------------------
752 // SAR_GpioResult MDrv_SAR_Gpio_SetDbgLevel(SAR_GpioDbgLvl eLevel);
753 
754 //-------------------------------------------------------------------------------------------------
755 /// Set SAR Interrupt mask
756 /// @ingroup G_SAR_COMMON
757 /// @param u8Channel: sar GPIO channel 0~7
758 /// @param bEnable:  1: enable interrupt, 0: disable interrupt
759 /// @return E_SAR_GPIO_OK: Success
760 /// @return E_SAR_GPIO_FAIL or other values: Failure
761 //-------------------------------------------------------------------------------------------------
762 SAR_GpioResult MDrv_SAR_CfgInterrupt(MS_U8 u8Channel, MS_BOOL bEnable);
763 
764 //-------------------------------------------------------------------------------------------------
765 /// Set SAR Interrupt wakeup
766 /// @ingroup G_SAR_COMMON
767 /// @param bEnable:  1: enable interrupt, 0: disable interrupt
768 /// @return E_SAR_GPIO_OK: Success
769 /// @return E_SAR_GPIO_FAIL or other values: Failure
770 //-------------------------------------------------------------------------------------------------
771 SAR_GpioResult MDrv_SAR_CfgPMWakeup(MS_BOOL bEnable);
772 
773 //-------------------------------------------------------------------------------------------------
774 /// Set SAR Clear Interrupt Status
775 /// @ingroup G_SAR_CONTROL
776 /// @param u8Channel: sar GPIO channel 0~7
777 /// @return E_SAR_GPIO_OK: Success
778 /// @return E_SAR_GPIO_FAIL or other values: Failure
779 //-------------------------------------------------------------------------------------------------
780 void MDrv_SAR_ClearInterrupt(MS_U8 u8Channel);
781 
782 //-------------------------------------------------------------------------------------------------
783 /// Get SAR Status
784 /// @ingroup G_SAR_COMMON
785 /// @param u8Channel: sar GPIO channel 0~7
786 /// @return E_SAR_GPIO_OK: trigger interrupt
787 /// @return E_SAR_GPIO_FAIL or interrrupt do not trigger
788 //-------------------------------------------------------------------------------------------------
789 SAR_GpioResult MDrv_SAR_GetInterruptStatus(MS_U8 u8Channel);
790 
791 //-------------------------------------------------------------------------------------------------
792 /// MOBF Encrypt
793 /// @ingroup G_SAR_ToBeRemove
794 /// @param u32Key \b IN: Key
795 /// @param bEnable \b IN: TRUE/FLASE
796 /// @return DRVAESDMA_OK : Success
797 /// @return Others : Fail
798 //-------------------------------------------------------------------------------------------------
799 SAR_KpdResult MDrv_SAR_Kpd_MMIO_Init(void);
800 
801 //-------------------------------------------------------------------------------------------------
802 /// MOBF Encrypt
803 /// @ingroup G_SAR_COMMON
804 /// @param u32Key \b IN: Key
805 /// @param bEnable \b IN: TRUE/FLASE
806 /// @return DRVAESDMA_OK : Success
807 /// @return Others : Fail
808 //-------------------------------------------------------------------------------------------------
809 // SAR_KpdResult MDrv_SAR_Kpd_CfgChannelBound(MS_U8 u8Channel, MS_U16 u16Upper, MS_U16 u16Lower);
810 
811 //-------------------------------------------------------------------------------------------------
812 /// Set SAR 2.0V / 3.3V Level
813 /// @ingroup G_SAR_COMMON
814 /// @param eSarLevel:  E_SAR_33V: 3.3V, E_SAR_20V: 2.0V
815 /// @return Void
816 /// @return Void
817 //-------------------------------------------------------------------------------------------------
818 void MDrv_SAR_SetLevel(SAR_LEVEL eSarLevel);
819 
820 
821 //--------------------------------------------------------------------------------------------------
822 // Utopia2.0 will call this function to register SAR module
823 //--------------------------------------------------------------------------------------------------
824 
825 // void SARRegisterToUtopia(FUtopiaOpen ModuleType);
826 //-------------------------------------------------------------------------------------------------
827 /// MOBF Encrypt
828 /// @ingroup G_SAR_ToBeRemove
829 /// @param u32Key \b IN: Key
830 /// @param bEnable \b IN: TRUE/FLASE
831 /// @return DRVAESDMA_OK : Success
832 /// @return Others : Fail
833 //-------------------------------------------------------------------------------------------------
834 MS_U32 SAROpen(void** pInstance, MS_U32 u32ModuleVersion, void* pAttribute);
835 //-------------------------------------------------------------------------------------------------
836 /// MOBF Encrypt
837 /// @ingroup G_SAR_ToBeRemove
838 /// @param u32Key \b IN: Key
839 /// @param bEnable \b IN: TRUE/FLASE
840 /// @return DRVAESDMA_OK : Success
841 /// @return Others : Fail
842 //-------------------------------------------------------------------------------------------------
843 // MS_U32 SARClose(void* pInstance);
844 //-------------------------------------------------------------------------------------------------
845 /// MOBF Encrypt
846 /// @ingroup G_SAR_ToBeRemove
847 /// @param u32Key \b IN: Key
848 /// @param bEnable \b IN: TRUE/FLASE
849 /// @return DRVAESDMA_OK : Success
850 /// @return Others : Fail
851 //-------------------------------------------------------------------------------------------------
852 // MS_U32 SARIoctl(void* pInstance, MS_U32 u32Cmd, void *pArgs);
853 
854 MS_U32 MDrv_SAR_SetPowerState(EN_POWER_MODE u16PowerState);
855 
856 
857 
858 
859 typedef enum {
860     MDrv_CMD_Kpd_GetKeyCode,
861 } eSARIoctlOpt;
862 
863 
864 
865 
866 
867 
868 
869 typedef struct _SAR_Kpd_GetKeyCode_PARAM
870 {
871    MS_U8 *pu8Key;
872    MS_U8 *pu8Repeat;
873 } SAR_Kpd_GetKeyCode_PARAM;
874 
875 
876 
877 
878 typedef SAR_KpdResult (*IOCTL_SAR_Kpd_GetKeyCode)(MS_U8 *pu8Key, MS_U8 *pu8Repeat);
879 
880 
881 typedef struct _SAR_INSTANT_PRIVATE
882 {
883 
884     IOCTL_SAR_Kpd_GetKeyCode fpSARKpdGetKeyCode;
885 
886 }SAR_INSTANT_PRIVATE;
887 
888 
889 //SAR_Private
890 typedef struct _SAR_RESOURCE_PRIVATE
891 {
892     MS_U32 Dummy;
893 }SAR_RESOURCE_PRIVATE;
894 
895 
896 #ifdef __cplusplus
897 }
898 #endif
899 
900 
901 #endif // _DRV_SAR_H_
902 
903