1/*- 2 * Copyright (c) 2009, Oleksandr Tymoshenko <gonzo@FreeBSD.org> 3 * Copyright (c) 2009, Luiz Otavio O Souza. 4 * Copyright (c) 2010, Andrew Thompson <thompsa@FreeBSD.org> 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 --- 18 unchanged lines hidden (view full) --- 27 * SUCH DAMAGE. 28 */ 29 30/* 31 * GPIO driver for Gateworks Avilia 32 */ 33 34#include <sys/cdefs.h> |
35__FBSDID("$FreeBSD: head/sys/arm/xscale/ixp425/avila_gpio.c 277996 2015-01-31 19:32:14Z loos $"); |
36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/bus.h> 40 41#include <sys/kernel.h> 42#include <sys/module.h> 43#include <sys/rman.h> 44#include <sys/lock.h> 45#include <sys/mutex.h> 46#include <sys/gpio.h> 47 48#include <machine/bus.h> 49#include <machine/resource.h> 50#include <arm/xscale/ixp425/ixp425reg.h> 51#include <arm/xscale/ixp425/ixp425var.h> |
52#include <dev/gpio/gpiobusvar.h> |
53 54#include "gpio_if.h" 55 56#define GPIO_SET_BITS(sc, reg, bits) \ 57 GPIO_CONF_WRITE_4(sc, reg, GPIO_CONF_READ_4(sc, (reg)) | (bits)) 58 59#define GPIO_CLEAR_BITS(sc, reg, bits) \ 60 GPIO_CONF_WRITE_4(sc, reg, GPIO_CONF_READ_4(sc, (reg)) & ~(bits)) 61 62struct avila_gpio_softc { 63 device_t sc_dev; |
64 device_t sc_busdev; |
65 bus_space_tag_t sc_iot; 66 bus_space_handle_t sc_gpio_ioh; 67 uint32_t sc_valid; 68 struct gpio_pin sc_pins[IXP4XX_GPIO_PINS]; 69}; 70 71struct avila_gpio_pin { 72 const char *name; --- 40 unchanged lines hidden (view full) --- 113 */ 114static int avila_gpio_probe(device_t dev); 115static int avila_gpio_attach(device_t dev); 116static int avila_gpio_detach(device_t dev); 117 118/* 119 * GPIO interface 120 */ |
121static device_t avila_gpio_get_bus(device_t); |
122static int avila_gpio_pin_max(device_t dev, int *maxpin); 123static int avila_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps); 124static int avila_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t 125 *flags); 126static int avila_gpio_pin_getname(device_t dev, uint32_t pin, char *name); 127static int avila_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags); 128static int avila_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value); 129static int avila_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val); --- 30 unchanged lines hidden (view full) --- 160 else { 161 pin->gp_flags |= GPIO_PIN_INPUT; 162 GPIO_SET_BITS(sc, IXP425_GPIO_GPOER, mask); 163 } 164 IXP4XX_GPIO_UNLOCK(); 165 } 166} 167 |
168static device_t 169avila_gpio_get_bus(device_t dev) 170{ 171 struct avila_gpio_softc *sc; 172 173 sc = device_get_softc(dev); 174 175 return (sc->sc_busdev); 176} 177 |
178static int 179avila_gpio_pin_max(device_t dev, int *maxpin) 180{ 181 182 *maxpin = IXP4XX_GPIO_PINS - 1; 183 return (0); 184} 185 --- 132 unchanged lines hidden (view full) --- 318 319 strncpy(sc->sc_pins[p->pin].gp_name, p->name, GPIOMAXNAME); 320 sc->sc_pins[p->pin].gp_pin = p->pin; 321 sc->sc_pins[p->pin].gp_caps = p->caps; 322 sc->sc_pins[p->pin].gp_flags = avila_gpio_pin_flags(sc, p->pin); 323 sc->sc_valid |= 1 << p->pin; 324 } 325 |
326 sc->sc_busdev = gpiobus_attach_bus(dev); 327 if (sc->sc_busdev == NULL) 328 return (ENXIO); |
329 |
330 return (0); |
331#undef N 332} 333 334static int 335avila_gpio_detach(device_t dev) 336{ 337 |
338 gpiobus_detach_bus(dev); |
339 340 return(0); 341} 342 343static device_method_t gpio_avila_methods[] = { 344 DEVMETHOD(device_probe, avila_gpio_probe), 345 DEVMETHOD(device_attach, avila_gpio_attach), 346 DEVMETHOD(device_detach, avila_gpio_detach), 347 348 /* GPIO protocol */ |
349 DEVMETHOD(gpio_get_bus, avila_gpio_get_bus), |
350 DEVMETHOD(gpio_pin_max, avila_gpio_pin_max), 351 DEVMETHOD(gpio_pin_getname, avila_gpio_pin_getname), 352 DEVMETHOD(gpio_pin_getflags, avila_gpio_pin_getflags), 353 DEVMETHOD(gpio_pin_getcaps, avila_gpio_pin_getcaps), 354 DEVMETHOD(gpio_pin_setflags, avila_gpio_pin_setflags), 355 DEVMETHOD(gpio_pin_get, avila_gpio_pin_get), 356 DEVMETHOD(gpio_pin_set, avila_gpio_pin_set), 357 DEVMETHOD(gpio_pin_toggle, avila_gpio_pin_toggle), --- 12 unchanged lines hidden --- |