xref: /utopia/UTPA2-700.0.x/projects/tmplib/include/drvGPIO.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   drvGPIO.h
98 /// @brief  GPIO Driver Interface
99 /// @author MStar Semiconductor Inc.
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101 
102 /*!
103     \defgroup G_GPIO GPIO interface
104     \ingroup  G_PERIPHERAL
105 
106     \brief
107     GPIO (Generic Purpose Input/Output) is a generic pin on an integrated circuit, which can be programmed to be used to either
108     accept input or provide output to external devices depending on user desires and application requirements
109 
110     <b> Features </b>
111     - GPIO pin direction can be set by software
112     - User/Device can read value of GPIO register
113     - Support interrupt enable/disable mode
114     - Support diffrent power state of certain GPIO pin
115 
116     \defgroup G_GPIO_INIT Initialization Task relative
117     \ingroup  G_GPIO
118     \defgroup G_GPIO_COMMON Common Task relative
119     \ingroup  G_GPIO
120     \defgroup G_GPIO_CONTROL Control relative
121     \ingroup  G_GPIO
122     \defgroup G_GPIO_INT  Interrupt relative
123     \ingroup  G_GPIO
124     \defgroup G_GPIO_ToBeModified GPIO api to be modified
125     \ingroup  G_GPIO
126     \defgroup G_GPIO_ToBeRemove GPIO api to be removed
127     \ingroup  G_GPIO
128 */
129 
130 #ifndef __DRVGPIO_H__
131 #define __DRVGPIO_H__
132 
133 
134 #ifdef __cplusplus
135 extern "C"
136 {
137 #endif
138 
139 #include "MsTypes.h"
140 #include "MsDevice.h"
141 
142 #define MSIF_GPIO_LIB_CODE                     {'G','P','I','O'}    //Lib code
143 #define MSIF_GPIO_LIBVER                       {'0','3'}            //LIB version
144 #define MSIF_GPIO_BUILDNUM                     {'0','6'}            //Build Number
145 #define MSIF_GPIO_CHANGELIST                   {'0','0','5','5','7','0','9','3'} //P4 ChangeList Number
146 
147 #define GPIO_DRV_VERSION                /* Character String for DRV/API version             */  \
148     MSIF_TAG,                           /* 'MSIF'                                           */  \
149     MSIF_CLASS,                         /* '00'                                             */  \
150     MSIF_CUS,                           /* 0x0000                                           */  \
151     MSIF_MOD,                           /* 0x0000                                           */  \
152     MSIF_CHIP,                                                                                  \
153     MSIF_CPU,                                                                                   \
154     MSIF_GPIO_LIB_CODE,                        /* IP__                                             */  \
155     MSIF_GPIO_LIBVER,                          /* 0.0 ~ Z.Z                                        */  \
156     MSIF_GPIO_BUILDNUM,                        /* 00 ~ 99                                          */  \
157     MSIF_GPIO_CHANGELIST,                      /* CL#                                              */  \
158     MSIF_OS
159 
160 typedef enum _GPIO_DbgLv
161 {
162     E_GPIO_DBGLV_NONE,          //no debug message
163     E_GPIO_DBGLV_ERR_ONLY,      //show error only
164     E_GPIO_DBGLV_REG_DUMP,      //show error & reg dump
165     E_GPIO_DBGLV_INFO,          //show error & informaiton
166     E_GPIO_DBGLV_ALL            //show error, information & funciton name
167 }GPIO_DbgLv;
168 
169 typedef enum _GPIO_Result
170 {
171     E_GPIO_NOT_SUPPORT = -1,
172     E_GPIO_FAIL = 0,
173     E_GPIO_OK = 1
174 }GPIO_Result;
175 
176 typedef struct _GPIO_Info
177 {
178     MS_U32      u32GPIONum;
179     MS_U32      u32IOMap;
180     MS_U32      u32IOMap_PM;
181 }GPIO_Info;
182 
183 typedef struct _GPIO_Status
184 {
185     MS_U8   u8DbgLevel;
186     MS_BOOL bInit;
187 }GPIO_Status;
188 
189 typedef int MS_GPIO_NUM;        ///< GPIO handle, for default operations,
190 
191 //-------------------------------------------------------------------------------------------------
192 /// MOBF Encrypt
193 /// @ingroup G_GPIO_ToBeRemove
194 /// @param u32Key \b IN: Key
195 /// @param bEnable \b IN: TRUE/FLASE
196 /// @return DRVAESDMA_OK : Success
197 /// @return Others : Fail
198 //-------------------------------------------------------------------------------------------------
199 // MS_BOOL MDrv_GPIO_SetIOMapBase(void);
200 //-------------------------------------------------------------------------------------------------
201 /// MOBF Encrypt
202 /// @ingroup G_GPIO_COMMON
203 /// @param u32Key \b IN: Key
204 /// @param bEnable \b IN: TRUE/FLASE
205 /// @return DRVAESDMA_OK : Success
206 /// @return Others : Fail
207 //-------------------------------------------------------------------------------------------------
208 // GPIO_Result MDrv_GPIO_GetLibVer(const MSIF_Version **ppVersion);
209 //-------------------------------------------------------------------------------------------------
210 /// MOBF Encrypt
211 /// @ingroup G_GPIO_COMMON
212 /// @param u32Key \b IN: Key
213 /// @param bEnable \b IN: TRUE/FLASE
214 /// @return DRVAESDMA_OK : Success
215 /// @return Others : Fail
216 //-------------------------------------------------------------------------------------------------
217 // GPIO_Result MDrv_GPIO_SetDbgLevel(GPIO_DbgLv eLevel);
218 //-------------------------------------------------------------------------------------------------
219 /// MOBF Encrypt
220 /// @ingroup G_GPIO_COMMON
221 /// @param u32Key \b IN: Key
222 /// @param bEnable \b IN: TRUE/FLASE
223 /// @return DRVAESDMA_OK : Success
224 /// @return Others : Fail
225 //-------------------------------------------------------------------------------------------------
226 // const GPIO_Info* MDrv_GPIO_GetInfo(void);
227 //-------------------------------------------------------------------------------------------------
228 /// MOBF Encrypt
229 /// @ingroup G_GPIO_COMMON
230 /// @param u32Key \b IN: Key
231 /// @param bEnable \b IN: TRUE/FLASE
232 /// @return DRVAESDMA_OK : Success
233 /// @return Others : Fail
234 //-------------------------------------------------------------------------------------------------
235 // void MDrv_GPIO_GetStatus(GPIO_Status *pStatus);
236 
237 //-------------------------------------------------------------------------------------------------
238 /// MOBF Encrypt
239 /// @ingroup G_GPIO_INIT
240 /// @param u32Key \b IN: Key
241 /// @param bEnable \b IN: TRUE/FLASE
242 /// @return DRVAESDMA_OK : Success
243 /// @return Others : Fail
244 //-------------------------------------------------------------------------------------------------
245 void mdrv_gpio_init(void);
246 //-------------------------------------------------------------------------------------------------
247 /// MOBF Encrypt
248 /// @ingroup G_GPIO_CONTROL
249 /// @param u32Key \b IN: Key
250 /// @param bEnable \b IN: TRUE/FLASE
251 /// @return DRVAESDMA_OK : Success
252 /// @return Others : Fail
253 //-------------------------------------------------------------------------------------------------
254 void mdrv_gpio_set_high(MS_GPIO_NUM gpio);
255 //-------------------------------------------------------------------------------------------------
256 /// MOBF Encrypt
257 /// @ingroup G_GPIO_CONTROL
258 /// @param u32Key \b IN: Key
259 /// @param bEnable \b IN: TRUE/FLASE
260 /// @return DRVAESDMA_OK : Success
261 /// @return Others : Fail
262 //-------------------------------------------------------------------------------------------------
263 void mdrv_gpio_set_low(MS_GPIO_NUM gpio);
264 //-------------------------------------------------------------------------------------------------
265 /// MOBF Encrypt
266 /// @ingroup G_GPIO_CONTROL
267 /// @param u32Key \b IN: Key
268 /// @param bEnable \b IN: TRUE/FLASE
269 /// @return DRVAESDMA_OK : Success
270 /// @return Others : Fail
271 //-------------------------------------------------------------------------------------------------
272 void mdrv_gpio_set_input(MS_GPIO_NUM gpio);
273 //-------------------------------------------------------------------------------------------------
274 /// MOBF Encrypt
275 /// @ingroup G_GPIO_CONTROL
276 /// @param u32Key \b IN: Key
277 /// @param bEnable \b IN: TRUE/FLASE
278 /// @return DRVAESDMA_OK : Success
279 /// @return Others : Fail
280 //-------------------------------------------------------------------------------------------------
281 //void mdrv_gpio_set_output(MS_GPIO_NUM gpio);
282 //-------------------------------------------------------------------------------------------------
283 /// MOBF Encrypt
284 /// @ingroup G_GPIO_CONTROL
285 /// @param u32Key \b IN: Key
286 /// @param bEnable \b IN: TRUE/FLASE
287 /// @return DRVAESDMA_OK : Success
288 /// @return Others : Fail
289 //-------------------------------------------------------------------------------------------------
290 int mdrv_gpio_get_inout(MS_GPIO_NUM gpio);
291 //-------------------------------------------------------------------------------------------------
292 /// MOBF Encrypt
293 /// @ingroup G_GPIO_COMMON
294 /// @param u32Key \b IN: Key
295 /// @param bEnable \b IN: TRUE/FLASE
296 /// @return DRVAESDMA_OK : Success
297 /// @return Others : Fail
298 //-------------------------------------------------------------------------------------------------
299 int mdrv_gpio_get_level(MS_GPIO_NUM gpio);
300 
301 typedef enum _GPIO_Edge
302 {
303     E_GPIO_RISING_EDGE,
304     E_GPIO_FALLING_EDGE
305 } GPIO_Edge;
306 
307 /// Callback function which is called in GPIO ISR.
308 typedef void ( *GPIO_Callback ) (void);
309 
310 //-------------------------------------------------------------------------------------------------
311 /// MOBF Encrypt
312 /// @ingroup G_GPIO_INT
313 /// @param u32Key \b IN: Key
314 /// @param bEnable \b IN: TRUE/FLASE
315 /// @return DRVAESDMA_OK : Success
316 /// @return Others : Fail
317 //-------------------------------------------------------------------------------------------------
318 // GPIO_Result mdrv_gpio_attach_interrupt(MS_GPIO_NUM gpio_num,GPIO_Edge gpio_edge_type,GPIO_Callback pCallback);
319 //-------------------------------------------------------------------------------------------------
320 /// MOBF Encrypt
321 /// @ingroup G_GPIO_INT
322 /// @param u32Key \b IN: Key
323 /// @param bEnable \b IN: TRUE/FLASE
324 /// @return DRVAESDMA_OK : Success
325 /// @return Others : Fail
326 //-------------------------------------------------------------------------------------------------
327 // GPIO_Result mdrv_gpio_detach_interrupt(MS_GPIO_NUM gpio_num);
328 //-------------------------------------------------------------------------------------------------
329 /// MOBF Encrypt
330 /// @ingroup G_GPIO_INT
331 /// @param u32Key \b IN: Key
332 /// @param bEnable \b IN: TRUE/FLASE
333 /// @return DRVAESDMA_OK : Success
334 /// @return Others : Fail
335 //-------------------------------------------------------------------------------------------------
336 // void mdrv_gpio_interrupt_action(void);
337 //-------------------------------------------------------------------------------------------------
338 /// MOBF Encrypt
339 /// @ingroup G_GPIO_INT
340 /// @param u32Key \b IN: Key
341 /// @param bEnable \b IN: TRUE/FLASE
342 /// @return DRVAESDMA_OK : Success
343 /// @return Others : Fail
344 //-------------------------------------------------------------------------------------------------
345 // void mdrv_gpio_enable_interrupt_all(void);
346 //-------------------------------------------------------------------------------------------------
347 /// MOBF Encrypt
348 /// @ingroup G_GPIO_INT
349 /// @param u32Key \b IN: Key
350 /// @param bEnable \b IN: TRUE/FLASE
351 /// @return DRVAESDMA_OK : Success
352 /// @return Others : Fail
353 //-------------------------------------------------------------------------------------------------
354 // void mdrv_gpio_disable_interrupt_all(void);
355 //-------------------------------------------------------------------------------------------------
356 /// MOBF Encrypt
357 /// @ingroup G_GPIO_INT
358 /// @param u32Key \b IN: Key
359 /// @param bEnable \b IN: TRUE/FLASE
360 /// @return DRVAESDMA_OK : Success
361 /// @return Others : Fail
362 //-------------------------------------------------------------------------------------------------
363 // GPIO_Result mdrv_gpio_enable_interrupt(MS_GPIO_NUM gpio);
364 //-------------------------------------------------------------------------------------------------
365 /// MOBF Encrypt
366 /// @ingroup G_GPIO_INT
367 /// @param u32Key \b IN: Key
368 /// @param bEnable \b IN: TRUE/FLASE
369 /// @return DRVAESDMA_OK : Success
370 /// @return Others : Fail
371 //-------------------------------------------------------------------------------------------------
372 // GPIO_Result mdrv_gpio_disable_interrupt(MS_GPIO_NUM gpio);
373 
374 // control power state for fast booting
375 //-------------------------------------------------------------------------------------------------
376 /// MOBF Encrypt
377 /// @ingroup G_GPIO_COMMON
378 /// @param u32Key \b IN: Key
379 /// @param bEnable \b IN: TRUE/FLASE
380 /// @return DRVAESDMA_OK : Success
381 /// @return Others : Fail
382 //-------------------------------------------------------------------------------------------------
383 MS_U16 MDrv_GPIO_SetPowerState(EN_POWER_MODE u16PowerState);
384 
385 #ifdef __cplusplus
386 }
387 #endif
388 
389 #endif /* __DRVGPIO_H__ */
390 
391