From owner-svn-src-all@FreeBSD.ORG Wed Aug 20 17:39:53 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C453D287; Wed, 20 Aug 2014 17:39:53 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::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 96DD23BEC; Wed, 20 Aug 2014 17:39:53 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7KHdrZI024257; Wed, 20 Aug 2014 17:39:53 GMT (envelope-from loos@FreeBSD.org) Received: (from loos@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s7KHdrYT024256; Wed, 20 Aug 2014 17:39:53 GMT (envelope-from loos@FreeBSD.org) Message-Id: <201408201739.s7KHdrYT024256@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: loos set sender to loos@FreeBSD.org using -f From: Luiz Otavio O Souza Date: Wed, 20 Aug 2014 17:39:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r270236 - stable/10/sys/dev/gpio X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Aug 2014 17:39:53 -0000 Author: loos Date: Wed Aug 20 17:39:53 2014 New Revision: 270236 URL: http://svnweb.freebsd.org/changeset/base/270236 Log: MFC r266922: Add a bounds verification to the SCL and SDA pin values. At attach, print the SCL and SDA pin numbers. Remove a stray blank line. Remove the GPIOBUS locking from gpioiic_reset(), it is already called with this lock held. This fixes a crash when you try to scan the iicbus with i2c(8). Modified: stable/10/sys/dev/gpio/gpioiic.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/gpio/gpioiic.c ============================================================================== --- stable/10/sys/dev/gpio/gpioiic.c Wed Aug 20 17:33:32 2014 (r270235) +++ stable/10/sys/dev/gpio/gpioiic.c Wed Aug 20 17:39:53 2014 (r270236) @@ -46,6 +46,8 @@ __FBSDID("$FreeBSD$"); #include #endif +#include + #include #include @@ -74,7 +76,6 @@ static int gpioiic_getsda(device_t); static int gpioiic_getscl(device_t); static int gpioiic_reset(device_t, u_char, u_char, u_char *); - static int gpioiic_probe(device_t dev) { @@ -91,13 +92,15 @@ gpioiic_probe(device_t dev) static int gpioiic_attach(device_t dev) { - struct gpioiic_softc *sc = device_get_softc(dev); device_t bitbang; #ifdef FDT phandle_t node; pcell_t pin; #endif + struct gpiobus_ivar *devi; + struct gpioiic_softc *sc; + sc = device_get_softc(dev); sc->sc_dev = dev; sc->sc_busdev = device_get_parent(dev); if (resource_int_value(device_get_name(dev), @@ -116,6 +119,15 @@ gpioiic_attach(device_t dev) sc->sda_pin = (int)pin; #endif + if (sc->scl_pin < 0 || sc->scl_pin > 1) + sc->scl_pin = SCL_PIN_DEFAULT; + if (sc->sda_pin < 0 || sc->sda_pin > 1) + sc->sda_pin = SDA_PIN_DEFAULT; + + devi = GPIOBUS_IVAR(dev); + device_printf(dev, "SCL pin: %d, SDA pin: %d\n", + devi->pins[sc->scl_pin], devi->pins[sc->sda_pin]); + /* add generic bit-banging code */ bitbang = device_add_child(dev, "iicbb", -1); device_probe_and_attach(bitbang); @@ -221,16 +233,11 @@ gpioiic_getsda(device_t dev) static int gpioiic_reset(device_t dev, u_char speed, u_char addr, u_char *oldaddr) { - struct gpioiic_softc *sc = device_get_softc(dev); - - GPIOBUS_LOCK_BUS(sc->sc_busdev); - GPIOBUS_ACQUIRE_BUS(sc->sc_busdev, sc->sc_dev); + struct gpioiic_softc *sc; + sc = device_get_softc(dev); gpioiic_reset_bus(sc->sc_dev); - GPIOBUS_RELEASE_BUS(sc->sc_busdev, sc->sc_dev); - GPIOBUS_UNLOCK_BUS(sc->sc_busdev); - return (IIC_ENOADDR); }