svn commit: r323553 - in head/sys: arm/at91 arm/broadcom/bcm2835 arm/freescale/imx arm/ti dev/glxiic

Ian Lepore ian at FreeBSD.org
Wed Sep 13 16:54:29 UTC 2017


Author: ian
Date: Wed Sep 13 16:54:27 2017
New Revision: 323553
URL: https://svnweb.freebsd.org/changeset/base/323553

Log:
  Defer attaching and probing iicbus and its children until interrupts are
  available, in i2c controller drivers that require interrupts for transfers.
  
  This is the result of auditing all 22 existing drivers that attach iicbus.
  These drivers were the only ones remaining that require interrupts and were
  not using config_intrhook to defer attachment.  That has led, over the
  years, to various i2c slave device drivers needing to use config_intrhook
  themselves rather than performing bus transactions in their probe() and
  attach() methods, just in case they were attached too early.

Modified:
  head/sys/arm/at91/at91_twi.c
  head/sys/arm/broadcom/bcm2835/bcm2835_bsc.c
  head/sys/arm/freescale/imx/imx_i2c.c
  head/sys/arm/ti/ti_i2c.c
  head/sys/dev/glxiic/glxiic.c

Modified: head/sys/arm/at91/at91_twi.c
==============================================================================
--- head/sys/arm/at91/at91_twi.c	Wed Sep 13 16:47:23 2017	(r323552)
+++ head/sys/arm/at91/at91_twi.c	Wed Sep 13 16:54:27 2017	(r323553)
@@ -160,8 +160,8 @@ at91_twi_attach(device_t dev)
 
 	if ((sc->iicbus = device_add_child(dev, "iicbus", -1)) == NULL)
 		device_printf(dev, "could not allocate iicbus instance\n");
-	/* probe and attach the iicbus */
-	bus_generic_attach(dev);
+	/* Probe and attach the iicbus when interrupts are available. */
+	config_intrhook_oneshot((ich_func_t)bus_generic_attach, dev);
 out:
 	if (err)
 		at91_twi_deactivate(dev);

Modified: head/sys/arm/broadcom/bcm2835/bcm2835_bsc.c
==============================================================================
--- head/sys/arm/broadcom/bcm2835/bcm2835_bsc.c	Wed Sep 13 16:47:23 2017	(r323552)
+++ head/sys/arm/broadcom/bcm2835/bcm2835_bsc.c	Wed Sep 13 16:54:27 2017	(r323553)
@@ -309,7 +309,10 @@ bcm_bsc_attach(device_t dev)
 		return (ENXIO);
 	}
 
-	return (bus_generic_attach(dev));
+	/* Probe and attach the iicbus when interrupts are available. */
+	config_intrhook_oneshot((ich_func_t)bus_generic_attach, dev);
+
+	return (0);
 }
 
 static int

Modified: head/sys/arm/freescale/imx/imx_i2c.c
==============================================================================
--- head/sys/arm/freescale/imx/imx_i2c.c	Wed Sep 13 16:47:23 2017	(r323552)
+++ head/sys/arm/freescale/imx/imx_i2c.c	Wed Sep 13 16:54:27 2017	(r323553)
@@ -443,7 +443,8 @@ no_recovery:
 
 	/* We don't do a hardware reset here because iicbus_attach() does it. */
 
-	bus_generic_attach(dev);
+	/* Probe and attach the iicbus when interrupts are available. */
+	config_intrhook_oneshot((ich_func_t)bus_generic_attach, dev);
 	return (0);
 }
 

Modified: head/sys/arm/ti/ti_i2c.c
==============================================================================
--- head/sys/arm/ti/ti_i2c.c	Wed Sep 13 16:47:23 2017	(r323552)
+++ head/sys/arm/ti/ti_i2c.c	Wed Sep 13 16:54:27 2017	(r323553)
@@ -37,11 +37,6 @@
  * incorporate that sometime in the future.  The idea being that for transaction
  * larger than a certain size the DMA engine is used, for anything less the
  * normal interrupt/fifo driven option is used.
- *
- *
- * WARNING: This driver uses mtx_sleep and interrupts to perform transactions,
- * which means you can't do a transaction during startup before the interrupts
- * have been enabled.  Hint - the freebsd function config_intrhook_establish().
  */
 
 #include <sys/cdefs.h>
@@ -909,8 +904,8 @@ ti_i2c_attach(device_t dev)
 		goto out;
 	}
 
-	/* Probe and attach the iicbus */
-	bus_generic_attach(dev);
+	/* Probe and attach the iicbus when interrupts are available. */
+	config_intrhook_oneshot((ich_func_t)bus_generic_attach, dev);
 
 out:
 	if (err) {

Modified: head/sys/dev/glxiic/glxiic.c
==============================================================================
--- head/sys/dev/glxiic/glxiic.c	Wed Sep 13 16:47:23 2017	(r323552)
+++ head/sys/dev/glxiic/glxiic.c	Wed Sep 13 16:54:27 2017	(r323553)
@@ -408,11 +408,10 @@ glxiic_attach(device_t dev)
 	glxiic_gpio_enable(sc);
 	glxiic_smb_enable(sc, IIC_FASTEST, 0);
 
-	error = bus_generic_attach(dev);
-	if (error != 0) {
-		device_printf(dev, "Could not probe and attach children\n");
-		error = ENXIO;
-	}
+	/* Probe and attach the iicbus when interrupts are available. */
+	config_intrhook_oneshot((ich_func_t)bus_generic_attach, dev);
+	error = 0;
+
 out:
 	if (error != 0) {
 		callout_drain(&sc->callout);


More information about the svn-src-all mailing list