Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 12 Nov 2013 13:34:08 +0000 (UTC)
From:      Luiz Otavio O Souza <loos@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r258045 - head/sys/arm/broadcom/bcm2835
Message-ID:  <201311121334.rACDY89p051584@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201311121334.rACDY89p051584>