summaryrefslogtreecommitdiffstats
path: root/sys/arm/xscale
diff options
context:
space:
mode:
authorloos <loos@FreeBSD.org>2015-01-31 19:32:14 +0000
committerloos <loos@FreeBSD.org>2015-01-31 19:32:14 +0000
commit5e1a5939929b3ae8ec6f7e44ddd1b51b3c542cc6 (patch)
tree4edc5f6a6f697cb6c391fc6f0800ce835ba4024d /sys/arm/xscale
parent92c5395dfebe86676461d4e940ccf2b4249770e5 (diff)
downloadFreeBSD-src-5e1a5939929b3ae8ec6f7e44ddd1b51b3c542cc6.zip
FreeBSD-src-5e1a5939929b3ae8ec6f7e44ddd1b51b3c542cc6.tar.gz
Implement GPIO_GET_BUS() method for all GPIO drivers.
Add helper routines to deal with attach and detach of gpiobus and gpioc devices that are common to all drivers.
Diffstat (limited to 'sys/arm/xscale')
-rw-r--r--sys/arm/xscale/ixp425/avila_gpio.c23
-rw-r--r--sys/arm/xscale/ixp425/cambria_gpio.c26
2 files changed, 40 insertions, 9 deletions
diff --git a/sys/arm/xscale/ixp425/avila_gpio.c b/sys/arm/xscale/ixp425/avila_gpio.c
index 6d92e08..d14d9c2 100644
--- a/sys/arm/xscale/ixp425/avila_gpio.c
+++ b/sys/arm/xscale/ixp425/avila_gpio.c
@@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$");
#include <machine/resource.h>
#include <arm/xscale/ixp425/ixp425reg.h>
#include <arm/xscale/ixp425/ixp425var.h>
+#include <dev/gpio/gpiobusvar.h>
#include "gpio_if.h"
@@ -60,6 +61,7 @@ __FBSDID("$FreeBSD$");
struct avila_gpio_softc {
device_t sc_dev;
+ device_t sc_busdev;
bus_space_tag_t sc_iot;
bus_space_handle_t sc_gpio_ioh;
uint32_t sc_valid;
@@ -116,6 +118,7 @@ static int avila_gpio_detach(device_t dev);
/*
* GPIO interface
*/
+static device_t avila_gpio_get_bus(device_t);
static int avila_gpio_pin_max(device_t dev, int *maxpin);
static int avila_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps);
static int avila_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t
@@ -162,6 +165,16 @@ avila_gpio_pin_configure(struct avila_gpio_softc *sc, struct gpio_pin *pin,
}
}
+static device_t
+avila_gpio_get_bus(device_t dev)
+{
+ struct avila_gpio_softc *sc;
+
+ sc = device_get_softc(dev);
+
+ return (sc->sc_busdev);
+}
+
static int
avila_gpio_pin_max(device_t dev, int *maxpin)
{
@@ -310,10 +323,11 @@ avila_gpio_attach(device_t dev)
sc->sc_valid |= 1 << p->pin;
}
- device_add_child(dev, "gpioc", -1);
- device_add_child(dev, "gpiobus", -1);
+ sc->sc_busdev = gpiobus_attach_bus(dev);
+ if (sc->sc_busdev == NULL)
+ return (ENXIO);
- return (bus_generic_attach(dev));
+ return (0);
#undef N
}
@@ -321,7 +335,7 @@ static int
avila_gpio_detach(device_t dev)
{
- bus_generic_detach(dev);
+ gpiobus_detach_bus(dev);
return(0);
}
@@ -332,6 +346,7 @@ static device_method_t gpio_avila_methods[] = {
DEVMETHOD(device_detach, avila_gpio_detach),
/* GPIO protocol */
+ DEVMETHOD(gpio_get_bus, avila_gpio_get_bus),
DEVMETHOD(gpio_pin_max, avila_gpio_pin_max),
DEVMETHOD(gpio_pin_getname, avila_gpio_pin_getname),
DEVMETHOD(gpio_pin_getflags, avila_gpio_pin_getflags),
diff --git a/sys/arm/xscale/ixp425/cambria_gpio.c b/sys/arm/xscale/ixp425/cambria_gpio.c
index 16c3489..aa3947b 100644
--- a/sys/arm/xscale/ixp425/cambria_gpio.c
+++ b/sys/arm/xscale/ixp425/cambria_gpio.c
@@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$");
#include <arm/xscale/ixp425/ixp425var.h>
#include <arm/xscale/ixp425/ixdp425reg.h>
+#include <dev/gpio/gpiobusvar.h>
#include <dev/iicbus/iiconf.h>
#include <dev/iicbus/iicbus.h>
@@ -79,6 +80,7 @@ __FBSDID("$FreeBSD$");
#define GPIO_PINS 5
struct cambria_gpio_softc {
device_t sc_dev;
+ device_t sc_busdev;
bus_space_tag_t sc_iot;
bus_space_handle_t sc_gpio_ioh;
struct mtx sc_mtx;
@@ -119,6 +121,7 @@ static int cambria_gpio_detach(device_t dev);
/*
* GPIO interface
*/
+static device_t cambria_gpio_get_bus(device_t);
static int cambria_gpio_pin_max(device_t dev, int *maxpin);
static int cambria_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps);
static int cambria_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t
@@ -261,6 +264,16 @@ cambria_gpio_write(struct cambria_gpio_softc *sc)
return (0);
}
+static device_t
+cambria_gpio_get_bus(device_t dev)
+{
+ struct cambria_gpio_softc *sc;
+
+ sc = device_get_softc(dev);
+
+ return (sc->sc_busdev);
+}
+
static int
cambria_gpio_pin_max(device_t dev, int *maxpin)
{
@@ -438,10 +451,13 @@ cambria_gpio_attach(device_t dev)
cambria_gpio_pin_setflags(dev, pin, p->flags);
}
- device_add_child(dev, "gpioc", -1);
- device_add_child(dev, "gpiobus", -1);
+ sc->sc_busdev = gpiobus_attach_bus(dev);
+ if (sc->sc_busdev == NULL) {
+ mtx_destroy(&sc->sc_mtx);
+ return (ENXIO);
+ }
- return (bus_generic_attach(dev));
+ return (0);
}
static int
@@ -451,8 +467,7 @@ cambria_gpio_detach(device_t dev)
KASSERT(mtx_initialized(&sc->sc_mtx), ("gpio mutex not initialized"));
- bus_generic_detach(dev);
-
+ gpiobus_detach_bus(dev);
mtx_destroy(&sc->sc_mtx);
return(0);
@@ -464,6 +479,7 @@ static device_method_t cambria_gpio_methods[] = {
DEVMETHOD(device_detach, cambria_gpio_detach),
/* GPIO protocol */
+ DEVMETHOD(gpio_get_bus, cambria_gpio_get_bus),
DEVMETHOD(gpio_pin_max, cambria_gpio_pin_max),
DEVMETHOD(gpio_pin_getname, cambria_gpio_pin_getname),
DEVMETHOD(gpio_pin_getflags, cambria_gpio_pin_getflags),
OpenPOWER on IntegriCloud