Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 23 Jun 2019 15:58:46 +0000 (UTC)
From:      Ian Lepore <ian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r349311 - in stable/12/sys: arm/freescale/imx dev/iicbus
Message-ID:  <201906231558.x5NFwkYf055773@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ian
Date: Sun Jun 23 15:58:46 2019
New Revision: 349311
URL: https://svnweb.freebsd.org/changeset/base/349311

Log:
  MFC r348123, r348164, r348166
  
  r348123:
  Add pnp info to the imx_i2c driver.
  
  r348164:
  Mark i2c slave devices busy while they own the bus.
  
  Many i2c slave drivers are in modules that can be unloaded.  If they detach
  while IO is in progress the bus would be hung forever.  Conversely,
  lower-layer drivers (iicbus and the hardware driver) also live in modules
  and other kinds of bad things happen if they get detached while IO is in
  progress.  Because device_busy() propagates up to parents, marking the slave
  device busy while it owns the bus solves both kinds of problems that come
  with detaching i2c devices while IO is in progress.
  
  r348166:
  Release the bus-recovery gpio pins in detach(), so that unload then
  reload of the module works without "pin already allocated" errors.

Modified:
  stable/12/sys/arm/freescale/imx/imx_i2c.c
  stable/12/sys/dev/iicbus/iiconf.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/arm/freescale/imx/imx_i2c.c
==============================================================================
--- stable/12/sys/arm/freescale/imx/imx_i2c.c	Sun Jun 23 15:55:41 2019	(r349310)
+++ stable/12/sys/arm/freescale/imx/imx_i2c.c	Sun Jun 23 15:58:46 2019	(r349311)
@@ -194,6 +194,7 @@ DRIVER_MODULE(imx_i2c, simplebus, i2c_driver, i2c_devc
 DRIVER_MODULE(ofw_iicbus, imx_i2c, ofw_iicbus_driver, ofw_iicbus_devclass, 0, 0);
 MODULE_DEPEND(imx_i2c, iicbus, 1, 1, 1);
 MODULE_DEPEND(imx_i2c, ofw_iicbus, 1, 1, 1);
+SIMPLEBUS_PNP_INFO(compat_data);
 
 static phandle_t
 i2c_get_node(device_t bus, device_t dev)
@@ -467,6 +468,10 @@ i2c_detach(device_t dev)
 
 	if (sc->iicbus != NULL)
 		device_delete_child(dev, sc->iicbus);
+
+	/* Release bus-recover pins; gpio_pin_release() handles NULL args. */
+	gpio_pin_release(sc->rb_sclpin);
+	gpio_pin_release(sc->rb_sdapin);
 
 	if (sc->res != NULL)
 		bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->res);

Modified: stable/12/sys/dev/iicbus/iiconf.c
==============================================================================
--- stable/12/sys/dev/iicbus/iiconf.c	Sun Jun 23 15:55:41 2019	(r349310)
+++ stable/12/sys/dev/iicbus/iiconf.c	Sun Jun 23 15:58:46 2019	(r349311)
@@ -128,6 +128,12 @@ iicbus_request_bus(device_t bus, device_t dev, int how
 		++sc->owncount;
 		if (sc->owner == NULL) {
 			sc->owner = dev;
+			/*
+			 * Mark the device busy while it owns the bus, to
+			 * prevent detaching the device, bus, or hardware
+			 * controller, until ownership is relinquished.
+			 */
+			device_busy(dev);
 			/* 
 			 * Drop the lock around the call to the bus driver, it
 			 * should be allowed to sleep in the IIC_WAIT case.
@@ -177,6 +183,7 @@ iicbus_release_bus(device_t bus, device_t dev)
 		IICBUS_LOCK(sc);
 		sc->owner = NULL;
 		wakeup_one(sc);
+		device_unbusy(dev);
 	}
 	IICBUS_UNLOCK(sc);
 	return (0);



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