From owner-svn-src-all@freebsd.org Sun May 22 03:34:20 2016 Return-Path: Delivered-To: svn-src-all@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 16C20B3BB25; Sun, 22 May 2016 03:34:20 +0000 (UTC) (envelope-from loos@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 B51A614FF; Sun, 22 May 2016 03:34:19 +0000 (UTC) (envelope-from loos@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4M3YI2u008753; Sun, 22 May 2016 03:34:18 GMT (envelope-from loos@FreeBSD.org) Received: (from loos@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4M3YIgG008752; Sun, 22 May 2016 03:34:18 GMT (envelope-from loos@FreeBSD.org) Message-Id: <201605220334.u4M3YIgG008752@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: loos set sender to loos@FreeBSD.org using -f From: Luiz Otavio O Souza Date: Sun, 22 May 2016 03:34:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r300391 - head/sys/dev/gpio X-SVN-Group: head 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.22 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: Sun, 22 May 2016 03:34:20 -0000 Author: loos Date: Sun May 22 03:34:18 2016 New Revision: 300391 URL: https://svnweb.freebsd.org/changeset/base/300391 Log: Use a better prefix for defines, return BUS_PROBE_DEFAULT for probe routine. Refuse to attach if the number of given pins is not enough for our needs. Modified: head/sys/dev/gpio/gpioiic.c Modified: head/sys/dev/gpio/gpioiic.c ============================================================================== --- head/sys/dev/gpio/gpioiic.c Sun May 22 03:12:49 2016 (r300390) +++ head/sys/dev/gpio/gpioiic.c Sun May 22 03:34:18 2016 (r300391) @@ -53,8 +53,9 @@ __FBSDID("$FreeBSD$"); #include "iicbb_if.h" -#define SCL_PIN_DEFAULT 0 /* default index of SCL pin on gpiobus */ -#define SDA_PIN_DEFAULT 1 +#define GPIOIIC_SCL_DFLT 0 +#define GPIOIIC_SDA_DFLT 1 +#define GPIOIIC_MIN_PINS 2 struct gpioiic_softc { @@ -79,14 +80,24 @@ static int gpioiic_reset(device_t, u_cha static int gpioiic_probe(device_t dev) { + struct gpiobus_ivar *devi; #ifdef FDT + if (!ofw_bus_status_okay(dev)) + return (ENXIO); if (!ofw_bus_is_compatible(dev, "gpioiic")) return (ENXIO); #endif + devi = GPIOBUS_IVAR(dev); + if (devi->npins < GPIOIIC_MIN_PINS) { + device_printf(dev, + "gpioiic needs at least %d GPIO pins (only %d given).\n", + GPIOIIC_MIN_PINS, devi->npins); + return (ENXIO); + } device_set_desc(dev, "GPIO I2C bit-banging driver"); - return (0); + return (BUS_PROBE_DEFAULT); } static int @@ -105,10 +116,10 @@ gpioiic_attach(device_t dev) sc->sc_busdev = device_get_parent(dev); if (resource_int_value(device_get_name(dev), device_get_unit(dev), "scl", &sc->scl_pin)) - sc->scl_pin = SCL_PIN_DEFAULT; + sc->scl_pin = GPIOIIC_SCL_DFLT; if (resource_int_value(device_get_name(dev), device_get_unit(dev), "sda", &sc->sda_pin)) - sc->sda_pin = SDA_PIN_DEFAULT; + sc->sda_pin = GPIOIIC_SDA_DFLT; #ifdef FDT if ((node = ofw_bus_get_node(dev)) == -1) @@ -120,9 +131,9 @@ gpioiic_attach(device_t dev) #endif if (sc->scl_pin < 0 || sc->scl_pin > 1) - sc->scl_pin = SCL_PIN_DEFAULT; + sc->scl_pin = GPIOIIC_SCL_DFLT; if (sc->sda_pin < 0 || sc->sda_pin > 1) - sc->sda_pin = SDA_PIN_DEFAULT; + sc->sda_pin = GPIOIIC_SDA_DFLT; devi = GPIOBUS_IVAR(dev); device_printf(dev, "SCL pin: %d, SDA pin: %d\n",