Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:42

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*  GPIO Library interface
0004  *
0005  *  COPYRIGHT (c) 2009.
0006  *  Cobham Gaisler AB.
0007  *
0008  * Redistribution and use in source and binary forms, with or without
0009  * modification, are permitted provided that the following conditions
0010  * are met:
0011  * 1. Redistributions of source code must retain the above copyright
0012  *    notice, this list of conditions and the following disclaimer.
0013  * 2. Redistributions in binary form must reproduce the above copyright
0014  *    notice, this list of conditions and the following disclaimer in the
0015  *    documentation and/or other materials provided with the distribution.
0016  *
0017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0027  * POSSIBILITY OF SUCH DAMAGE.
0028  */
0029 
0030 #ifndef __GPIOLIB_H__
0031 #define __GPIOLIB_H__
0032 
0033 #ifdef __cplusplus
0034 extern "C" {
0035 #endif
0036 
0037 /* GPIO Config of one GPIO port */
0038 struct gpiolib_config {
0039     char        mask;       /* 0=Masked/1=Unmasked IRQ */
0040     char        irq_level;  /* Edge or Level triggered IRQ */
0041     char        irq_polarity;   /* Polarity of IRQ */
0042 };
0043 
0044 #define GPIOLIB_IRQ_EDGE 0
0045 #define GPIOLIB_IRQ_LEVEL 1
0046 
0047 #define GPIOLIB_IRQ_POL_LOW 0
0048 #define GPIOLIB_IRQ_POL_HIGH 1
0049 
0050 /* Libarary initialize function must be called befor any other */
0051 extern int gpiolib_initialize(void);
0052 
0053 /*** User Interface ***/
0054 
0055 extern void *gpiolib_open(int port);
0056 extern void *gpiolib_open_by_name(char *devName);
0057 extern void gpiolib_close(void *handle);
0058 
0059 /* Show the current status one or all GPIO ports in the system. 
0060  * Int port is port nunber, if port = -1 selects all ports.
0061  * 
0062  * If port != -1, handle is used to get port.
0063  * If port != -1, handle == NULL, then port is used as port number
0064  */
0065 extern void gpiolib_show(int port, void *handle);
0066 
0067 extern int gpiolib_set_config(void *handle, struct gpiolib_config *cfg);
0068 extern int gpiolib_set(void *handle, int dir, int val);
0069 extern int gpiolib_get(void *handle, int *inval);
0070 extern int gpiolib_irq_clear(void *handle);
0071 extern int gpiolib_irq_enable(void *handle);
0072 extern int gpiolib_irq_disable(void *handle);
0073 extern int gpiolib_irq_mask(void *handle);
0074 extern int gpiolib_irq_unmask(void *handle);
0075 extern int gpiolib_irq_force(void *handle);
0076 extern int gpiolib_irq_register(void *handle, void *func, void *arg);
0077 
0078 /*** Driver Interface ***/
0079 
0080 struct gpiolib_info {
0081     char        devName[80];
0082 };
0083 
0084 struct gpiolib_drv_ops {
0085     int     (*config)(void *handle, struct gpiolib_config *cfg);
0086     int     (*get)(void *handle, int *val);
0087     int     (*irq_opts)(void *handle, unsigned int options);
0088     int     (*irq_register)(void *handle, void *func, void *arg);
0089     int     (*open)(void *handle);
0090     int     (*set)(void *handle, int dir, int outval);
0091     int     (*show)(void *handle);
0092     int     (*get_info)(void *handle, struct gpiolib_info *pinfo);
0093 };
0094 
0095 #define GPIOLIB_IRQ_ENABLE  0x01
0096 #define GPIOLIB_IRQ_DISABLE 0x02
0097 #define GPIOLIB_IRQ_CLEAR   0x04
0098 #define GPIOLIB_IRQ_FORCE   0x08
0099 #define GPIOLIB_IRQ_MASK    0x10
0100 #define GPIOLIB_IRQ_UNMASK  0x20
0101 
0102 struct gpiolib_drv {
0103     struct gpiolib_drv_ops  *ops;
0104 };
0105 
0106 /* Register a GPIO port */
0107 extern int gpiolib_drv_register(struct gpiolib_drv *drv, void *handle);
0108 
0109 #ifdef __cplusplus
0110 }
0111 #endif
0112 
0113 #endif