From owner-svn-src-stable@freebsd.org Fri Sep 22 15:53:24 2017 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2855FE02F59; Fri, 22 Sep 2017 15:53:24 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 042B871DC0; Fri, 22 Sep 2017 15:53:23 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8MFrNkV024285; Fri, 22 Sep 2017 15:53:23 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8MFrM6J024277; Fri, 22 Sep 2017 15:53:22 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201709221553.v8MFrM6J024277@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Fri, 22 Sep 2017 15:53:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323931 - in stable/11/sys: arm/at91 arm/broadcom/bcm2835 arm/freescale/imx arm/ti dev/glxiic dev/iicbus modules/i2c modules/i2c/icee X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/11/sys: arm/at91 arm/broadcom/bcm2835 arm/freescale/imx arm/ti dev/glxiic dev/iicbus modules/i2c modules/i2c/icee X-SVN-Commit-Revision: 323931 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Sep 2017 15:53:24 -0000 Author: ian Date: Fri Sep 22 15:53:22 2017 New Revision: 323931 URL: https://svnweb.freebsd.org/changeset/base/323931 Log: MFC r323474, r323553, r323691 r323474: Add a default implementation that returns ENODEV for start, repeat_start, stop, read, and write methods. Some controllers don't implement these individual operations and have only a transfer method. In that case, we should return an indication that the device is present but doesn't support the method, as opposed to the kobj default error ENXIO which makes it look like the whole device is missing. Userland tools such as i2c(8) can use the differing return values to switch between the two different i2c IO mechanisms. r323553: 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. r323691: Give icee(4) a detach() method so it can be used as a module. Add a module makefile for it. Added: stable/11/sys/modules/i2c/icee/ - copied from r323691, head/sys/modules/i2c/icee/ Modified: stable/11/sys/arm/at91/at91_twi.c stable/11/sys/arm/broadcom/bcm2835/bcm2835_bsc.c stable/11/sys/arm/freescale/imx/imx_i2c.c stable/11/sys/arm/ti/ti_i2c.c stable/11/sys/dev/glxiic/glxiic.c stable/11/sys/dev/iicbus/icee.c stable/11/sys/dev/iicbus/iicbus_if.m stable/11/sys/modules/i2c/Makefile Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/arm/at91/at91_twi.c ============================================================================== --- stable/11/sys/arm/at91/at91_twi.c Fri Sep 22 15:47:35 2017 (r323930) +++ stable/11/sys/arm/at91/at91_twi.c Fri Sep 22 15:53:22 2017 (r323931) @@ -161,8 +161,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: stable/11/sys/arm/broadcom/bcm2835/bcm2835_bsc.c ============================================================================== --- stable/11/sys/arm/broadcom/bcm2835/bcm2835_bsc.c Fri Sep 22 15:47:35 2017 (r323930) +++ stable/11/sys/arm/broadcom/bcm2835/bcm2835_bsc.c Fri Sep 22 15:53:22 2017 (r323931) @@ -308,7 +308,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: stable/11/sys/arm/freescale/imx/imx_i2c.c ============================================================================== --- stable/11/sys/arm/freescale/imx/imx_i2c.c Fri Sep 22 15:47:35 2017 (r323930) +++ stable/11/sys/arm/freescale/imx/imx_i2c.c Fri Sep 22 15:53:22 2017 (r323931) @@ -444,7 +444,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: stable/11/sys/arm/ti/ti_i2c.c ============================================================================== --- stable/11/sys/arm/ti/ti_i2c.c Fri Sep 22 15:47:35 2017 (r323930) +++ stable/11/sys/arm/ti/ti_i2c.c Fri Sep 22 15:53:22 2017 (r323931) @@ -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 @@ -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: stable/11/sys/dev/glxiic/glxiic.c ============================================================================== --- stable/11/sys/dev/glxiic/glxiic.c Fri Sep 22 15:47:35 2017 (r323930) +++ stable/11/sys/dev/glxiic/glxiic.c Fri Sep 22 15:53:22 2017 (r323931) @@ -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); Modified: stable/11/sys/dev/iicbus/icee.c ============================================================================== --- stable/11/sys/dev/iicbus/icee.c Fri Sep 22 15:47:35 2017 (r323930) +++ stable/11/sys/dev/iicbus/icee.c Fri Sep 22 15:53:22 2017 (r323931) @@ -206,17 +206,34 @@ icee_attach(device_t dev) return (0); } +static int +icee_detach(device_t dev) +{ + struct icee_softc *sc = device_get_softc(dev); + + destroy_dev(sc->cdev); + return (0); +} + static int icee_open(struct cdev *dev, int oflags, int devtype, struct thread *td) { + struct icee_softc *sc; + sc = CDEV2SOFTC(dev); + if (device_get_state(sc->dev) < DS_BUSY) + device_busy(sc->dev); + return (0); } static int icee_close(struct cdev *dev, int fflag, int devtype, struct thread *td) { + struct icee_softc *sc; + sc = CDEV2SOFTC(dev); + device_unbusy(sc->dev); return (0); } @@ -345,6 +362,7 @@ icee_write(struct cdev *dev, struct uio *uio, int iofl static device_method_t icee_methods[] = { DEVMETHOD(device_probe, icee_probe), DEVMETHOD(device_attach, icee_attach), + DEVMETHOD(device_detach, icee_detach), DEVMETHOD_END }; Modified: stable/11/sys/dev/iicbus/iicbus_if.m ============================================================================== --- stable/11/sys/dev/iicbus/iicbus_if.m Fri Sep 22 15:47:35 2017 (r323930) +++ stable/11/sys/dev/iicbus/iicbus_if.m Fri Sep 22 15:53:22 2017 (r323931) @@ -32,6 +32,12 @@ INTERFACE iicbus; CODE { + static int iicbus_nosupport(void) + { + + return (ENODEV); + } + static u_int iicbus_default_frequency(device_t bus, u_char speed) { @@ -69,7 +75,7 @@ METHOD int repeated_start { device_t dev; u_char slave; int timeout; -}; +} DEFAULT iicbus_nosupport; # # Send START condition @@ -78,14 +84,14 @@ METHOD int start { device_t dev; u_char slave; int timeout; -}; +} DEFAULT iicbus_nosupport; # # Send STOP condition # METHOD int stop { device_t dev; -}; +} DEFAULT iicbus_nosupport; # # Read from I2C bus @@ -97,7 +103,7 @@ METHOD int read { int *bytes; int last; int delay; -}; +} DEFAULT iicbus_nosupport; # # Write to the I2C bus @@ -108,7 +114,7 @@ METHOD int write { int len; int *bytes; int timeout; -}; +} DEFAULT iicbus_nosupport; # # Reset I2C bus Modified: stable/11/sys/modules/i2c/Makefile ============================================================================== --- stable/11/sys/modules/i2c/Makefile Fri Sep 22 15:47:35 2017 (r323930) +++ stable/11/sys/modules/i2c/Makefile Fri Sep 22 15:53:22 2017 (r323931) @@ -6,6 +6,7 @@ SUBDIR = \ ds1307 \ ds13rtc \ ds3231 \ + icee \ if_ic \ iic \ iicbb \