1 /* 2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, 5 * are permitted provided that the following conditions are met: 6 * 7 * 1. Redistributions of source code must retain the above copyright notice, this list of 8 * conditions and the following disclaimer. 9 * 10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 * of conditions and the following disclaimer in the documentation and/or other materials 12 * provided with the distribution. 13 * 14 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 15 * to endorse or promote products derived from this software without specific prior written 16 * permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef GPIO_USER_H 32 #define GPIO_USER_H 33 #include "fcntl.h" 34 #include "hdf_base.h" 35 #include "sys/ioctl.h" 36 37 #define PL061_GPIO_USER_SUPPORT 38 39 int32_t GpioAddVfs(uint16_t bitNum); 40 void GpioRemoveVfs(void); 41 42 typedef void (*irqFunc)(unsigned int irq, void *data); 43 44 typedef struct GpioBitInfo { 45 unsigned int groupnumber; 46 unsigned int bitnumber; 47 48 unsigned char value; 49 #define GPIO_VALUE_HIGH 1 50 #define GPIO_VALUE_LOW 0 51 unsigned char direction; 52 #define GPIO_DIRECTION_IN 0 53 #define GPIO_DIRECTION_IN_OUT 1 54 55 unsigned char irqStatus; 56 unsigned char irqEnable; 57 #define GPIO_IRQ_ENABLE 1 58 #define GPIO_IRQ_DISABLE 0 59 irqFunc irqHandler; 60 unsigned int irqType; 61 #define IRQ_TYPE_NONE 0x00000000 62 #define IRQ_TYPE_EDGE_RISING 0x00000001 63 #define IRQ_TYPE_EDGE_FALLING 0x00000002 64 #define IRQ_TYPE_EDGE_BOTH (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING) 65 #define IRQ_TYPE_LEVEL_HIGH 0x00000004 66 #define IRQ_TYPE_LEVEL_LOW 0x00000008 67 #define IRQ_TYPE_LEVEL_MASK (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH) 68 void *data; 69 } gpio_groupbit_info; 70 71 #define GPIO_SET_DIR _IOWR('w', 4, gpio_groupbit_info) 72 #define GPIO_GET_DIR _IOWR('r', 5, gpio_groupbit_info) 73 #define GPIO_READ_BIT _IOWR('r', 6, gpio_groupbit_info) 74 #define GPIO_WRITE_BIT _IOWR('w', 7, gpio_groupbit_info) 75 76 #endif 77