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 typedef enum _GPIO_Attribute 192 { 193 E_GPIO_ATTRI_USER_DRV , 194 E_GPIO_ATTRI_KERNEL_DRV , 195 E_GPIO_ATTRI_UNKNOWN 196 }GPIO_Attribute; 197 198 199 //------------------------------------------------------------------------------------------------- 200 /// MOBF Encrypt 201 /// @ingroup G_GPIO_ToBeRemove 202 /// @param u32Key \b IN: Key 203 /// @param bEnable \b IN: TRUE/FLASE 204 /// @return DRVAESDMA_OK : Success 205 /// @return Others : Fail 206 //------------------------------------------------------------------------------------------------- 207 MS_BOOL MDrv_GPIO_SetIOMapBase(void); 208 //------------------------------------------------------------------------------------------------- 209 /// MOBF Encrypt 210 /// @ingroup G_GPIO_COMMON 211 /// @param u32Key \b IN: Key 212 /// @param bEnable \b IN: TRUE/FLASE 213 /// @return DRVAESDMA_OK : Success 214 /// @return Others : Fail 215 //------------------------------------------------------------------------------------------------- 216 GPIO_Result MDrv_GPIO_GetLibVer(const MSIF_Version **ppVersion); 217 //------------------------------------------------------------------------------------------------- 218 /// MOBF Encrypt 219 /// @ingroup G_GPIO_COMMON 220 /// @param u32Key \b IN: Key 221 /// @param bEnable \b IN: TRUE/FLASE 222 /// @return DRVAESDMA_OK : Success 223 /// @return Others : Fail 224 //------------------------------------------------------------------------------------------------- 225 GPIO_Result MDrv_GPIO_SetDbgLevel(GPIO_DbgLv eLevel); 226 //------------------------------------------------------------------------------------------------- 227 /// MOBF Encrypt 228 /// @ingroup G_GPIO_COMMON 229 /// @param u32Key \b IN: Key 230 /// @param bEnable \b IN: TRUE/FLASE 231 /// @return DRVAESDMA_OK : Success 232 /// @return Others : Fail 233 //------------------------------------------------------------------------------------------------- 234 const GPIO_Info* MDrv_GPIO_GetInfo(void); 235 //------------------------------------------------------------------------------------------------- 236 /// MOBF Encrypt 237 /// @ingroup G_GPIO_COMMON 238 /// @param u32Key \b IN: Key 239 /// @param bEnable \b IN: TRUE/FLASE 240 /// @return DRVAESDMA_OK : Success 241 /// @return Others : Fail 242 //------------------------------------------------------------------------------------------------- 243 void MDrv_GPIO_GetStatus(GPIO_Status *pStatus); 244 245 //------------------------------------------------------------------------------------------------- 246 /// MOBF Encrypt 247 /// @ingroup G_GPIO_INIT 248 /// @param u32Key \b IN: Key 249 /// @param bEnable \b IN: TRUE/FLASE 250 /// @return DRVAESDMA_OK : Success 251 /// @return Others : Fail 252 //------------------------------------------------------------------------------------------------- 253 void mdrv_gpio_init(void); 254 //------------------------------------------------------------------------------------------------- 255 /// MOBF Encrypt 256 /// @ingroup G_GPIO_CONTROL 257 /// @param u32Key \b IN: Key 258 /// @param bEnable \b IN: TRUE/FLASE 259 /// @return DRVAESDMA_OK : Success 260 /// @return Others : Fail 261 //------------------------------------------------------------------------------------------------- 262 void mdrv_gpio_set_high(MS_GPIO_NUM gpio); 263 //------------------------------------------------------------------------------------------------- 264 /// MOBF Encrypt 265 /// @ingroup G_GPIO_CONTROL 266 /// @param u32Key \b IN: Key 267 /// @param bEnable \b IN: TRUE/FLASE 268 /// @return DRVAESDMA_OK : Success 269 /// @return Others : Fail 270 //------------------------------------------------------------------------------------------------- 271 void mdrv_gpio_set_low(MS_GPIO_NUM gpio); 272 //------------------------------------------------------------------------------------------------- 273 /// MOBF Encrypt 274 /// @ingroup G_GPIO_CONTROL 275 /// @param u32Key \b IN: Key 276 /// @param bEnable \b IN: TRUE/FLASE 277 /// @return DRVAESDMA_OK : Success 278 /// @return Others : Fail 279 //------------------------------------------------------------------------------------------------- 280 void mdrv_gpio_set_input(MS_GPIO_NUM gpio); 281 //------------------------------------------------------------------------------------------------- 282 /// MOBF Encrypt 283 /// @ingroup G_GPIO_CONTROL 284 /// @param u32Key \b IN: Key 285 /// @param bEnable \b IN: TRUE/FLASE 286 /// @return DRVAESDMA_OK : Success 287 /// @return Others : Fail 288 //------------------------------------------------------------------------------------------------- 289 //void mdrv_gpio_set_output(MS_GPIO_NUM gpio); 290 //------------------------------------------------------------------------------------------------- 291 /// MOBF Encrypt 292 /// @ingroup G_GPIO_CONTROL 293 /// @param u32Key \b IN: Key 294 /// @param bEnable \b IN: TRUE/FLASE 295 /// @return DRVAESDMA_OK : Success 296 /// @return Others : Fail 297 //------------------------------------------------------------------------------------------------- 298 int mdrv_gpio_get_inout(MS_GPIO_NUM gpio); 299 //------------------------------------------------------------------------------------------------- 300 /// MOBF Encrypt 301 /// @ingroup G_GPIO_COMMON 302 /// @param u32Key \b IN: Key 303 /// @param bEnable \b IN: TRUE/FLASE 304 /// @return DRVAESDMA_OK : Success 305 /// @return Others : Fail 306 //------------------------------------------------------------------------------------------------- 307 int mdrv_gpio_get_level(MS_GPIO_NUM gpio); 308 309 typedef enum _GPIO_Edge 310 { 311 E_GPIO_RISING_EDGE, 312 E_GPIO_FALLING_EDGE 313 } GPIO_Edge; 314 315 /// Callback function which is called in GPIO ISR. 316 typedef void ( *GPIO_Callback ) (void); 317 318 //------------------------------------------------------------------------------------------------- 319 /// MOBF Encrypt 320 /// @ingroup G_GPIO_INT 321 /// @param u32Key \b IN: Key 322 /// @param bEnable \b IN: TRUE/FLASE 323 /// @return DRVAESDMA_OK : Success 324 /// @return Others : Fail 325 //------------------------------------------------------------------------------------------------- 326 GPIO_Result mdrv_gpio_attach_interrupt(MS_GPIO_NUM gpio_num,GPIO_Edge gpio_edge_type,GPIO_Callback pCallback); 327 //------------------------------------------------------------------------------------------------- 328 /// MOBF Encrypt 329 /// @ingroup G_GPIO_INT 330 /// @param u32Key \b IN: Key 331 /// @param bEnable \b IN: TRUE/FLASE 332 /// @return DRVAESDMA_OK : Success 333 /// @return Others : Fail 334 //------------------------------------------------------------------------------------------------- 335 GPIO_Result mdrv_gpio_detach_interrupt(MS_GPIO_NUM gpio_num); 336 //------------------------------------------------------------------------------------------------- 337 /// MOBF Encrypt 338 /// @ingroup G_GPIO_INT 339 /// @param u32Key \b IN: Key 340 /// @param bEnable \b IN: TRUE/FLASE 341 /// @return DRVAESDMA_OK : Success 342 /// @return Others : Fail 343 //------------------------------------------------------------------------------------------------- 344 void mdrv_gpio_interrupt_action(void); 345 //------------------------------------------------------------------------------------------------- 346 /// MOBF Encrypt 347 /// @ingroup G_GPIO_INT 348 /// @param u32Key \b IN: Key 349 /// @param bEnable \b IN: TRUE/FLASE 350 /// @return DRVAESDMA_OK : Success 351 /// @return Others : Fail 352 //------------------------------------------------------------------------------------------------- 353 void mdrv_gpio_enable_interrupt_all(void); 354 //------------------------------------------------------------------------------------------------- 355 /// MOBF Encrypt 356 /// @ingroup G_GPIO_INT 357 /// @param u32Key \b IN: Key 358 /// @param bEnable \b IN: TRUE/FLASE 359 /// @return DRVAESDMA_OK : Success 360 /// @return Others : Fail 361 //------------------------------------------------------------------------------------------------- 362 void mdrv_gpio_disable_interrupt_all(void); 363 //------------------------------------------------------------------------------------------------- 364 /// MOBF Encrypt 365 /// @ingroup G_GPIO_INT 366 /// @param u32Key \b IN: Key 367 /// @param bEnable \b IN: TRUE/FLASE 368 /// @return DRVAESDMA_OK : Success 369 /// @return Others : Fail 370 //------------------------------------------------------------------------------------------------- 371 GPIO_Result mdrv_gpio_enable_interrupt(MS_GPIO_NUM gpio); 372 //------------------------------------------------------------------------------------------------- 373 /// MOBF Encrypt 374 /// @ingroup G_GPIO_INT 375 /// @param u32Key \b IN: Key 376 /// @param bEnable \b IN: TRUE/FLASE 377 /// @return DRVAESDMA_OK : Success 378 /// @return Others : Fail 379 //------------------------------------------------------------------------------------------------- 380 GPIO_Result mdrv_gpio_disable_interrupt(MS_GPIO_NUM gpio); 381 382 // control power state for fast booting 383 //------------------------------------------------------------------------------------------------- 384 /// MOBF Encrypt 385 /// @ingroup G_GPIO_COMMON 386 /// @param u32Key \b IN: Key 387 /// @param bEnable \b IN: TRUE/FLASE 388 /// @return DRVAESDMA_OK : Success 389 /// @return Others : Fail 390 //------------------------------------------------------------------------------------------------- 391 MS_U16 MDrv_GPIO_SetPowerState(EN_POWER_MODE u16PowerState); 392 393 #ifdef __cplusplus 394 } 395 #endif 396 397 #endif /* __DRVGPIO_H__ */ 398 399