1 /******************************************************************************
3 * Copyright (C) 2002 - 2014 Xilinx, Inc. All rights reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
31 ******************************************************************************/
32 /*****************************************************************************/
36 * This file contains the software API definition of the Xilinx General Purpose
37 * I/O (XGpio) device driver.
39 * The Xilinx GPIO controller is a soft IP core designed for Xilinx FPGAs and
40 * contains the following general features:
41 * - Support for up to 32 I/O discretes for each channel (64 bits total).
42 * - Each of the discretes can be configured for input or output.
43 * - Configurable support for dual channels and interrupt generation.
45 * The driver provides interrupt management functions. Implementation of
46 * interrupt handlers is left to the user. Refer to the provided interrupt
47 * example in the examples directory for details.
49 * This driver is intended to be RTOS and processor independent. Any needs for
50 * dynamic memory management, threads or thread mutual exclusion, virtual
51 * memory, or cache control must be satisfied by the layer above this driver.
53 * <b>Initialization & Configuration</b>
55 * The XGpio_Config structure is used by the driver to configure itself. This
56 * configuration structure is typically created by the tool-chain based on HW
59 * To support multiple runtime loading and initialization strategies employed
60 * by various operating systems, the driver instance can be initialized in one
61 * of the following ways:
63 * - XGpio_Initialize(InstancePtr, DeviceId) - The driver looks up its own
64 * configuration structure created by the tool-chain based on an ID provided
67 * - XGpio_CfgInitialize(InstancePtr, CfgPtr, EffectiveAddr) - Uses a
68 * configuration structure provided by the caller. If running in a system
69 * with address translation, the provided virtual memory base address
70 * replaces the physical address present in the configuration structure.
74 * This API utilizes 32 bit I/O to the GPIO registers. With less than 32 bits,
75 * the unused bits from registers are read as zero and written as don't cares.
78 * MODIFICATION HISTORY:
80 * Ver Who Date Changes
81 * ----- ---- -------- -----------------------------------------------
82 * 1.00a rmm 03/13/02 First release
83 * 2.00a jhl 11/26/03 Added support for dual channels and interrupts
84 * 2.01a jvb 12/14/05 I separated dependency on the static config table and
85 * xparameters.h from the driver initialization by moving
86 * _Initialize and _LookupConfig to _sinit.c. I also added
87 * the new _CfgInitialize routine.
88 * 2.11a mta 03/21/07 Updated to new coding style, added GetDataDirection
89 * 2.12a sv 11/21/07 Updated driver to support access through DCR bus
90 * 2.12a sv 06/05/08 Updated driver to fix the XGpio_InterruptDisable function
91 * to properly update the Interrupt Enable register
92 * 2.13a sdm 08/22/08 Removed support for static interrupt handlers from the MDD
94 * 3.00a sv 11/21/09 Updated to use HAL Processor APIs.
95 * Renamed the macros XGpio_mWriteReg to XGpio_WriteReg and
96 * XGpio_mReadReg to XGpio_ReadReg. Removed the macros
97 * XGpio_mSetDataDirection, XGpio_mGetDataReg and
98 * XGpio_mSetDataReg. Users should use XGpio_WriteReg and
99 * XGpio_ReadReg to achieve the same functionality.
100 * 3.01a bss 04/18/13 Updated driver tcl to generate Canonical params in
101 * xparameters.h. CR#698589
102 * 4.0 adk 19/12/13 Updated as per the New Tcl API's
104 *****************************************************************************/
106 #ifndef XGPIO_H /* prevent circular inclusions */
107 #define XGPIO_H /* by using protection macros */
113 /***************************** Include Files ********************************/
115 #include "xil_types.h"
116 #include "xil_assert.h"
120 /************************** Constant Definitions ****************************/
122 /**************************** Type Definitions ******************************/
125 * This typedef contains configuration information for the device.
128 u16 DeviceId; /* Unique ID of device */
129 u32 BaseAddress; /* Device base address */
130 int InterruptPresent; /* Are interrupts supported in h/w */
131 int IsDual; /* Are 2 channels supported in h/w */
135 * The XGpio driver instance data. The user is required to allocate a
136 * variable of this type for every GPIO device in the system. A pointer
137 * to a variable of this type is then passed to the driver API functions.
140 u32 BaseAddress; /* Device base address */
141 u32 IsReady; /* Device is initialized and ready */
142 int InterruptPresent; /* Are interrupts supported in h/w */
143 int IsDual; /* Are 2 channels supported in h/w */
146 /***************** Macros (Inline Functions) Definitions ********************/
149 /************************** Function Prototypes *****************************/
152 * Initialization functions in xgpio_sinit.c
154 int XGpio_Initialize(XGpio *InstancePtr, u16 DeviceId);
155 XGpio_Config *XGpio_LookupConfig(u16 DeviceId);
158 * API Basic functions implemented in xgpio.c
160 int XGpio_CfgInitialize(XGpio *InstancePtr, XGpio_Config * Config,
162 void XGpio_SetDataDirection(XGpio *InstancePtr, unsigned Channel,
164 u32 XGpio_GetDataDirection(XGpio *InstancePtr, unsigned Channel);
165 u32 XGpio_DiscreteRead(XGpio *InstancePtr, unsigned Channel);
166 void XGpio_DiscreteWrite(XGpio *InstancePtr, unsigned Channel, u32 Mask);
170 * API Functions implemented in xgpio_extra.c
172 void XGpio_DiscreteSet(XGpio *InstancePtr, unsigned Channel, u32 Mask);
173 void XGpio_DiscreteClear(XGpio *InstancePtr, unsigned Channel, u32 Mask);
176 * API Functions implemented in xgpio_selftest.c
178 int XGpio_SelfTest(XGpio *InstancePtr);
181 * API Functions implemented in xgpio_intr.c
183 void XGpio_InterruptGlobalEnable(XGpio *InstancePtr);
184 void XGpio_InterruptGlobalDisable(XGpio *InstancePtr);
185 void XGpio_InterruptEnable(XGpio *InstancePtr, u32 Mask);
186 void XGpio_InterruptDisable(XGpio *InstancePtr, u32 Mask);
187 void XGpio_InterruptClear(XGpio *InstancePtr, u32 Mask);
188 u32 XGpio_InterruptGetEnabled(XGpio *InstancePtr);
189 u32 XGpio_InterruptGetStatus(XGpio *InstancePtr);
195 #endif /* end of protection macro */