1/*- 2 * Copyright (c) 2013 Ganbold Tsagaankhuu <ganbold@freebsd.org> 3 * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org> 4 * Copyright (c) 2012 Luiz Otavio O Souza. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 13 unchanged lines hidden (view full) --- 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 */ 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: head/sys/arm/allwinner/a10_gpio.c 277996 2015-01-31 19:32:14Z loos $"); |
31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/bus.h> 35 36#include <sys/kernel.h> 37#include <sys/module.h> 38#include <sys/rman.h> --- 4 unchanged lines hidden (view full) --- 43#include <machine/bus.h> 44#include <machine/cpu.h> 45#include <machine/cpufunc.h> 46#include <machine/resource.h> 47#include <machine/fdt.h> 48#include <machine/intr.h> 49 50#include <dev/fdt/fdt_common.h> |
51#include <dev/gpio/gpiobusvar.h> |
52#include <dev/ofw/ofw_bus.h> 53#include <dev/ofw/ofw_bus_subr.h> 54 55#include "gpio_if.h" 56#include "a10_gpio.h" 57 58/* 59 * A10 have 9 banks of gpio. --- 11 unchanged lines hidden (view full) --- 71#define A10_GPIO_PULLUP 1 72#define A10_GPIO_PULLDOWN 2 73 74#define A10_GPIO_INPUT 0 75#define A10_GPIO_OUTPUT 1 76 77struct a10_gpio_softc { 78 device_t sc_dev; |
79 device_t sc_busdev; |
80 struct mtx sc_mtx; 81 struct resource * sc_mem_res; 82 struct resource * sc_irq_res; 83 bus_space_tag_t sc_bst; 84 bus_space_handle_t sc_bsh; 85 void * sc_intrhand; 86 int sc_gpio_npins; 87 struct gpio_pin sc_gpio_pins[A10_GPIO_PINS]; --- 126 unchanged lines hidden (view full) --- 214 a10_gpio_set_pud(sc, pin->gp_pin, A10_GPIO_PULLDOWN); 215 } 216 } else 217 a10_gpio_set_pud(sc, pin->gp_pin, A10_GPIO_NONE); 218 219 A10_GPIO_UNLOCK(sc); 220} 221 |
222static device_t 223a10_gpio_get_bus(device_t dev) 224{ 225 struct a10_gpio_softc *sc; 226 227 sc = device_get_softc(dev); 228 229 return (sc->sc_busdev); 230} 231 |
232static int 233a10_gpio_pin_max(device_t dev, int *maxpin) 234{ 235 236 *maxpin = A10_GPIO_PINS - 1; 237 return (0); 238} 239 --- 225 unchanged lines hidden (view full) --- 465 snprintf(sc->sc_gpio_pins[i].gp_name, GPIOMAXNAME, 466 "pin %d", i); 467 func = a10_gpio_get_function(sc, i); 468 sc->sc_gpio_pins[i].gp_pin = i; 469 sc->sc_gpio_pins[i].gp_caps = A10_GPIO_DEFAULT_CAPS; 470 sc->sc_gpio_pins[i].gp_flags = a10_gpio_func_flag(func); 471 } 472 sc->sc_gpio_npins = i; |
473 a10_gpio_sc = sc; |
474 sc->sc_busdev = gpiobus_attach_bus(dev); 475 if (sc->sc_busdev == NULL) 476 goto fail; |
477 |
478 return (0); |
479 480fail: 481 if (sc->sc_irq_res) 482 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq_res); 483 if (sc->sc_mem_res) 484 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res); 485 mtx_destroy(&sc->sc_mtx); 486 --- 9 unchanged lines hidden (view full) --- 496 497static device_method_t a10_gpio_methods[] = { 498 /* Device interface */ 499 DEVMETHOD(device_probe, a10_gpio_probe), 500 DEVMETHOD(device_attach, a10_gpio_attach), 501 DEVMETHOD(device_detach, a10_gpio_detach), 502 503 /* GPIO protocol */ |
504 DEVMETHOD(gpio_get_bus, a10_gpio_get_bus), |
505 DEVMETHOD(gpio_pin_max, a10_gpio_pin_max), 506 DEVMETHOD(gpio_pin_getname, a10_gpio_pin_getname), 507 DEVMETHOD(gpio_pin_getflags, a10_gpio_pin_getflags), 508 DEVMETHOD(gpio_pin_getcaps, a10_gpio_pin_getcaps), 509 DEVMETHOD(gpio_pin_setflags, a10_gpio_pin_setflags), 510 DEVMETHOD(gpio_pin_get, a10_gpio_pin_get), 511 DEVMETHOD(gpio_pin_set, a10_gpio_pin_set), 512 DEVMETHOD(gpio_pin_toggle, a10_gpio_pin_toggle), --- 29 unchanged lines hidden --- |