From fd9805111709be75f94d685fdbd6b1cc9735aeb0 Mon Sep 17 00:00:00 2001 From: Oleksandr Tymoshenko Date: Mon, 21 Nov 2016 19:43:01 +0000 Subject: [PATCH] [bytgpio] prepare bytgpio(4) for modularization - Add detach method - module should depend on gpiobus, not gpio --- sys/dev/gpio/bytgpio.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/sys/dev/gpio/bytgpio.c b/sys/dev/gpio/bytgpio.c index 76f29922fe1..2da58defffc 100644 --- a/sys/dev/gpio/bytgpio.c +++ b/sys/dev/gpio/bytgpio.c @@ -86,6 +86,7 @@ struct bytgpio_softc { static int bytgpio_probe(device_t dev); static int bytgpio_attach(device_t dev); +static int bytgpio_detach(device_t dev); #define SCORE_UID 1 #define SCORE_BANK_PREFIX "GPIO_S0_SC" @@ -567,6 +568,8 @@ bytgpio_attach(device_t dev) return (ENXIO); } + BYTGPIO_LOCK_INIT(sc); + switch (uid) { case SCORE_UID: sc->sc_npins = SCORE_PINS; @@ -599,8 +602,6 @@ bytgpio_attach(device_t dev) goto error; } - BYTGPIO_LOCK_INIT(sc); - for (pin = 0; pin < sc->sc_npins; pin++) { reg = BYGPIO_PIN_REGISTER(sc, pin, BYTGPIO_PCONF0); val = bytgpio_read_4(sc, reg); @@ -618,13 +619,39 @@ bytgpio_attach(device_t dev) return (0); error: + BYTGPIO_LOCK_DESTROY(sc); + return (ENXIO); } + +static int +bytgpio_detach(device_t dev) +{ + struct bytgpio_softc *sc; + + sc = device_get_softc(dev); + + if (sc->sc_busdev) + gpiobus_detach_bus(dev); + + BYTGPIO_LOCK_DESTROY(sc); + + if (sc->sc_pad_funcs) + free(sc->sc_pad_funcs, M_DEVBUF); + + if (sc->sc_mem_res != NULL) + bus_release_resource(dev, SYS_RES_MEMORY, + sc->sc_mem_rid, sc->sc_mem_res); + + return (0); +} + static device_method_t bytgpio_methods[] = { /* Device interface */ DEVMETHOD(device_probe, bytgpio_probe), DEVMETHOD(device_attach, bytgpio_attach), + DEVMETHOD(device_detach, bytgpio_detach), /* GPIO protocol */ DEVMETHOD(gpio_get_bus, bytgpio_get_bus), @@ -649,4 +676,4 @@ static driver_t bytgpio_driver = { static devclass_t bytgpio_devclass; DRIVER_MODULE(bytgpio, acpi, bytgpio_driver, bytgpio_devclass, 0, 0); MODULE_DEPEND(bytgpio, acpi, 1, 1, 1); -MODULE_DEPEND(bytgpio, gpio, 1, 1, 1); +MODULE_DEPEND(bytgpio, gpiobus, 1, 1, 1);