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