From owner-svn-src-all@FreeBSD.ORG Tue Nov 12 13:34:08 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id AC892194; Tue, 12 Nov 2013 13:34:08 +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)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 8E1C32C6A; Tue, 12 Nov 2013 13:34:08 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rACDY8Q9051586; Tue, 12 Nov 2013 13:34:08 GMT (envelope-from loos@svn.freebsd.org) Received: (from loos@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id rACDY89p051584; Tue, 12 Nov 2013 13:34:08 GMT (envelope-from loos@svn.freebsd.org) Message-Id: <201311121334.rACDY89p051584@svn.freebsd.org> From: Luiz Otavio O Souza Date: Tue, 12 Nov 2013 13:34:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r258045 - head/sys/arm/broadcom/bcm2835 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.16 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: Tue, 12 Nov 2013 13:34:08 -0000 Author: loos Date: Tue Nov 12 13:34:07 2013 New Revision: 258045 URL: http://svnweb.freebsd.org/changeset/base/258045 Log: As all the IIC controllers on system uses the same 'iichb' prefix we cannot rely only on checking the device unit to indentify the BSC unit we are attaching to. Make use of the device base address to identify our BSC unit. Approved by: adrian (mentor) Modified: head/sys/arm/broadcom/bcm2835/bcm2835_bsc.c head/sys/arm/broadcom/bcm2835/bcm2835_bscvar.h Modified: head/sys/arm/broadcom/bcm2835/bcm2835_bsc.c ============================================================================== --- head/sys/arm/broadcom/bcm2835/bcm2835_bsc.c Tue Nov 12 12:44:59 2013 (r258044) +++ head/sys/arm/broadcom/bcm2835/bcm2835_bsc.c Tue Nov 12 13:34:07 2013 (r258045) @@ -234,31 +234,13 @@ static int bcm_bsc_attach(device_t dev) { struct bcm_bsc_softc *sc; + unsigned long start; device_t gpio; - int rid; - - if (device_get_unit(dev) > 1) { - device_printf(dev, "only bsc0 and bsc1 are supported\n"); - return (ENXIO); - } + int i, rid; sc = device_get_softc(dev); sc->sc_dev = dev; - /* - * Configure the GPIO pins to ALT0 function to enable BSC control - * over the pins. - */ - gpio = devclass_get_device(devclass_find("gpio"), 0); - if (!gpio) { - device_printf(dev, "cannot find gpio0\n"); - return (ENXIO); - } - bcm_gpio_set_alternate(gpio, bcm_bsc_pins[device_get_unit(dev)].sda, - BCM_GPIO_ALT0); - bcm_gpio_set_alternate(gpio, bcm_bsc_pins[device_get_unit(dev)].scl, - BCM_GPIO_ALT0); - rid = 0; sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); @@ -270,6 +252,29 @@ bcm_bsc_attach(device_t dev) sc->sc_bst = rman_get_bustag(sc->sc_mem_res); sc->sc_bsh = rman_get_bushandle(sc->sc_mem_res); + /* Check the unit we are attaching by its base address. */ + start = rman_get_start(sc->sc_mem_res); + for (i = 0; i < nitems(bcm_bsc_pins); i++) { + if (bcm_bsc_pins[i].start == start) + break; + } + if (i == nitems(bcm_bsc_pins)) { + device_printf(dev, "only bsc0 and bsc1 are supported\n"); + return (ENXIO); + } + + /* + * Configure the GPIO pins to ALT0 function to enable BSC control + * over the pins. + */ + gpio = devclass_get_device(devclass_find("gpio"), 0); + if (!gpio) { + device_printf(dev, "cannot find gpio0\n"); + return (ENXIO); + } + bcm_gpio_set_alternate(gpio, bcm_bsc_pins[i].sda, BCM_GPIO_ALT0); + bcm_gpio_set_alternate(gpio, bcm_bsc_pins[i].scl, BCM_GPIO_ALT0); + rid = 0; sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE | RF_SHAREABLE); Modified: head/sys/arm/broadcom/bcm2835/bcm2835_bscvar.h ============================================================================== --- head/sys/arm/broadcom/bcm2835/bcm2835_bscvar.h Tue Nov 12 12:44:59 2013 (r258044) +++ head/sys/arm/broadcom/bcm2835/bcm2835_bscvar.h Tue Nov 12 13:34:07 2013 (r258045) @@ -33,9 +33,10 @@ struct { uint32_t sda; uint32_t scl; + unsigned long start; } bcm_bsc_pins[] = { - { 0, 1 }, /* BSC0 GPIO pins. */ - { 2, 3 } /* BSC1 GPIO pins. */ + { 0, 1, 0x20205000 }, /* BSC0 GPIO pins and base address. */ + { 2, 3, 0x20804000 } /* BSC1 GPIO pins and base address. */ }; struct bcm_bsc_softc {