1 /* $NetBSD: imxgpiovar.h,v 1.3 2020/01/15 01:09:56 jmcneill Exp $ */ 2 /*- 3 * Copyright (c) 2007 The NetBSD Foundation, Inc. 4 * All rights reserved. 5 * 6 * This code is derived from software contributed to The NetBSD Foundation 7 * by Matt Thomas 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 29 */ 30 #ifndef _ARM_IMX_IMXGPIOVAR_H 31 #define _ARM_IMX_IMXGPIOVAR_H 32 33 #include <sys/gpio.h> 34 #include <dev/gpio/gpiovar.h> 35 36 #include <arm/imx/imxgpioreg.h> /* for GPIO_NPINS */ 37 38 struct imxgpio_softc { 39 struct pic_softc gpio_pic; 40 41 device_t gpio_dev; 42 bus_space_tag_t gpio_memt; 43 bus_space_handle_t gpio_memh; 44 45 void *gpio_is; 46 void *gpio_is_high; 47 48 int gpio_unit; 49 int gpio_irqbase; 50 uint32_t gpio_enable_mask; 51 uint32_t gpio_edge_mask; 52 uint32_t gpio_level_mask; 53 #if NGPIO > 0 54 struct gpio_chipset_tag gpio_chipset; 55 gpio_pin_t gpio_pins[32]; 56 #endif 57 58 kmutex_t gpio_lock; 59 }; 60 61 struct imxgpio_pin { 62 int pin_no; 63 u_int pin_flags; 64 bool pin_actlo; 65 }; 66 67 void imxgpio_attach_common(device_t); 68 /* defined imx[35]1_gpio.c */ 69 extern const int imxgpio_ngroups; 70 int imxgpio_match(device_t, cfdata_t, void *); 71 void imxgpio_attach(device_t, device_t, void *); 72 73 int imxgpio_pin_read(void *, int); 74 void imxgpio_pin_write(void *, int, int); 75 void imxgpio_pin_ctl(void *, int, int); 76 77 /* in-kernel GPIO access utility functions */ 78 void imxgpio_set_direction(u_int, int); 79 void imxgpio_data_write(u_int, u_int); 80 bool imxgpio_data_read(u_int); 81 82 #define GPIO_NO(group, pin) (((group) - 1) * GPIO_NPINS + (pin)) 83 #define GPIO_MODULE(pin) ((pin) / GPIO_NPINS) 84 85 #endif /* _ARM_IMX_IMXGPIOVAR_H */ 86