aboutsummaryrefslogtreecommitdiff
path: root/sys/arm/freescale
diff options
context:
space:
mode:
authorIan Lepore <ian@FreeBSD.org>2018-02-18 02:01:41 +0000
committerIan Lepore <ian@FreeBSD.org>2018-02-18 02:01:41 +0000
commitb107b904a6b856a62433c0baf3b160f22d9d8b19 (patch)
tree01e0b408730377cbea4e4ad3dd7204053ab73cc5 /sys/arm/freescale
parent6c5aa8d10e7f468474eb9bbefa498e20b1adc0ca (diff)
downloadsrc-b107b904a6b856a62433c0baf3b160f22d9d8b19.tar.gz
src-b107b904a6b856a62433c0baf3b160f22d9d8b19.zip
Add a detach method so that this can be a kldunload-friendly module.
Notes
Notes: svn path=/head/; revision=329506
Diffstat (limited to 'sys/arm/freescale')
-rw-r--r--sys/arm/freescale/imx/imx_i2c.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/sys/arm/freescale/imx/imx_i2c.c b/sys/arm/freescale/imx/imx_i2c.c
index 3b6d4aadb227..dfbe267dac19 100644
--- a/sys/arm/freescale/imx/imx_i2c.c
+++ b/sys/arm/freescale/imx/imx_i2c.c
@@ -154,6 +154,7 @@ struct i2c_softc {
static phandle_t i2c_get_node(device_t, device_t);
static int i2c_probe(device_t);
static int i2c_attach(device_t);
+static int i2c_detach(device_t);
static int i2c_repeated_start(device_t, u_char, int);
static int i2c_start(device_t, u_char, int);
@@ -165,6 +166,7 @@ static int i2c_write(device_t, const char *, int, int *, int);
static device_method_t i2c_methods[] = {
DEVMETHOD(device_probe, i2c_probe),
DEVMETHOD(device_attach, i2c_attach),
+ DEVMETHOD(device_detach, i2c_detach),
/* OFW methods */
DEVMETHOD(ofw_bus_get_node, i2c_get_node),
@@ -449,6 +451,28 @@ no_recovery:
}
static int
+i2c_detach(device_t dev)
+{
+ struct i2c_softc *sc;
+ int error;
+
+ sc = device_get_softc(dev);
+
+ if ((error = bus_generic_detach(sc->dev)) != 0) {
+ device_printf(sc->dev, "cannot detach child devices\n");
+ return (error);
+ }
+
+ if (sc->iicbus != NULL)
+ device_delete_child(dev, sc->iicbus);
+
+ if (sc->res != NULL)
+ bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->res);
+
+ return (0);
+}
+
+static int
i2c_repeated_start(device_t dev, u_char slave, int timeout)
{
struct i2c_softc *sc;