Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Nov 2016 19:43:01 +0000 (UTC)
From:      Oleksandr Tymoshenko <gonzo@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r308940 - head/sys/dev/gpio
Message-ID:  <201611211943.uALJh1px022382@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: gonzo
Date: Mon Nov 21 19:43:01 2016
New Revision: 308940
URL: https://svnweb.freebsd.org/changeset/base/308940

Log:
  [bytgpio] prepare bytgpio(4) for modularization
  
  - Add detach method
  - module should depend on gpiobus, not gpio

Modified:
  head/sys/dev/gpio/bytgpio.c

Modified: head/sys/dev/gpio/bytgpio.c
==============================================================================
--- head/sys/dev/gpio/bytgpio.c	Mon Nov 21 19:38:57 2016	(r308939)
+++ head/sys/dev/gpio/bytgpio.c	Mon Nov 21 19:43:01 2016	(r308940)
@@ -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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201611211943.uALJh1px022382>