Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Jan 2014 12:32:31 +0000 (UTC)
From:      Luiz Otavio O Souza <loos@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r261078 - in stable/10/sys: arm/broadcom/bcm2835 arm/conf boot/fdt/dts conf
Message-ID:  <201401231232.s0NCWV8L027563@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: loos
Date: Thu Jan 23 12:32:30 2014
New Revision: 261078
URL: http://svnweb.freebsd.org/changeset/base/261078

Log:
  MFC r256959:
  
    Add the Raspberry Pi BSC (I2C compliant) controller driver.
  
    Reviewed by:	rpaulo
  
  MFC r256961:
  
    Enable the build of OFW I2C bus for FDT systems.
  
  MFC r258045:
  
    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.
  
  MFC r259127:
  
    Bring the RPi I2C driver in line with ti_i2c.  Make it treat any slave
    address as a 7-bit address.
  
  Approved by:	adrian (mentor)

Added:
  stable/10/sys/arm/broadcom/bcm2835/bcm2835_bsc.c
     - copied, changed from r256959, head/sys/arm/broadcom/bcm2835/bcm2835_bsc.c
  stable/10/sys/arm/broadcom/bcm2835/bcm2835_bscreg.h
     - copied unchanged from r256959, head/sys/arm/broadcom/bcm2835/bcm2835_bscreg.h
  stable/10/sys/arm/broadcom/bcm2835/bcm2835_bscvar.h
     - copied, changed from r256959, head/sys/arm/broadcom/bcm2835/bcm2835_bscvar.h
Modified:
  stable/10/sys/arm/broadcom/bcm2835/files.bcm2835
  stable/10/sys/arm/conf/RPI-B
  stable/10/sys/boot/fdt/dts/bcm2835.dtsi
  stable/10/sys/conf/files
Directory Properties:
  stable/10/   (props changed)

Copied and modified: stable/10/sys/arm/broadcom/bcm2835/bcm2835_bsc.c (from r256959, head/sys/arm/broadcom/bcm2835/bcm2835_bsc.c)
==============================================================================
--- head/sys/arm/broadcom/bcm2835/bcm2835_bsc.c	Wed Oct 23 12:29:39 2013	(r256959, copy source)
+++ stable/10/sys/arm/broadcom/bcm2835/bcm2835_bsc.c	Thu Jan 23 12:32:30 2014	(r261078)
@@ -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);
@@ -399,7 +404,7 @@ bcm_bsc_transfer(device_t dev, struct ii
 	for (i = 0; i < nmsgs; i++) {
 
 		/* Write the slave address. */
-		BCM_BSC_WRITE(sc, BCM_BSC_SLAVE, (msgs[i].slave >> 1) & 0x7f);
+		BCM_BSC_WRITE(sc, BCM_BSC_SLAVE, msgs[i].slave);
 
 		/* Write the data length. */
 		BCM_BSC_WRITE(sc, BCM_BSC_DLEN, msgs[i].len);

Copied: stable/10/sys/arm/broadcom/bcm2835/bcm2835_bscreg.h (from r256959, head/sys/arm/broadcom/bcm2835/bcm2835_bscreg.h)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/10/sys/arm/broadcom/bcm2835/bcm2835_bscreg.h	Thu Jan 23 12:32:30 2014	(r261078, copy of r256959, head/sys/arm/broadcom/bcm2835/bcm2835_bscreg.h)
@@ -0,0 +1,61 @@
+/*-
+ * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org>
+ * Copyright (c) 2013 Luiz Otavio O Souza <loos@freebsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef	_BCM2835_BSCREG_H_
+#define	_BCM2835_BSCREG_H_
+
+#define	BCM_BSC_CORE_CLK	150000000U
+#define	BCM_BSC_CTRL		0x00
+#define	BCM_BSC_CTRL_I2CEN		(1 << 15)
+#define	BCM_BSC_CTRL_INTR		(1 << 10)
+#define	BCM_BSC_CTRL_INTT		(1 << 9)
+#define	BCM_BSC_CTRL_INTD		(1 << 8)
+#define	BCM_BSC_CTRL_ST			(1 << 7)
+#define	BCM_BSC_CTRL_CLEAR1		(1 << 5)
+#define	BCM_BSC_CTRL_CLEAR0		(1 << 4)
+#define	BCM_BSC_CTRL_READ		(1 << 0)
+#define	BCM_BSC_STATUS		0x04
+#define	BCM_BSC_STATUS_CLKT		(1 << 9)
+#define	BCM_BSC_STATUS_ERR		(1 << 8)
+#define	BCM_BSC_STATUS_RXF		(1 << 7)
+#define	BCM_BSC_STATUS_TXE		(1 << 6)
+#define	BCM_BSC_STATUS_RXD		(1 << 5)
+#define	BCM_BSC_STATUS_TXD		(1 << 4)
+#define	BCM_BSC_STATUS_RXR		(1 << 3)
+#define	BCM_BSC_STATUS_TXW		(1 << 2)
+#define	BCM_BSC_STATUS_DONE		(1 << 1)
+#define	BCM_BSC_STATUS_TA		(1 << 0)
+#define	BCM_BSC_DLEN		0x08
+#define	BCM_BSC_SLAVE		0x0c
+#define	BCM_BSC_DATA		0x10
+#define	BCM_BSC_CLOCK		0x14
+#define	BCM_BSC_DELAY		0x18
+#define	BCM_BSC_CLKT		0x1c
+
+#endif	/* _BCM2835_BSCREG_H_ */

Copied and modified: stable/10/sys/arm/broadcom/bcm2835/bcm2835_bscvar.h (from r256959, head/sys/arm/broadcom/bcm2835/bcm2835_bscvar.h)
==============================================================================
--- head/sys/arm/broadcom/bcm2835/bcm2835_bscvar.h	Wed Oct 23 12:29:39 2013	(r256959, copy source)
+++ stable/10/sys/arm/broadcom/bcm2835/bcm2835_bscvar.h	Thu Jan 23 12:32:30 2014	(r261078)
@@ -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 {

Modified: stable/10/sys/arm/broadcom/bcm2835/files.bcm2835
==============================================================================
--- stable/10/sys/arm/broadcom/bcm2835/files.bcm2835	Thu Jan 23 12:02:04 2014	(r261077)
+++ stable/10/sys/arm/broadcom/bcm2835/files.bcm2835	Thu Jan 23 12:32:30 2014	(r261078)
@@ -1,5 +1,6 @@
 # $FreeBSD$
 
+arm/broadcom/bcm2835/bcm2835_bsc.c		optional bcm2835_bsc
 arm/broadcom/bcm2835/bcm2835_dma.c		standard
 arm/broadcom/bcm2835/bcm2835_fb.c		optional sc
 arm/broadcom/bcm2835/bcm2835_gpio.c		optional gpio

Modified: stable/10/sys/arm/conf/RPI-B
==============================================================================
--- stable/10/sys/arm/conf/RPI-B	Thu Jan 23 12:02:04 2014	(r261077)
+++ stable/10/sys/arm/conf/RPI-B	Thu Jan 23 12:32:30 2014	(r261078)
@@ -79,6 +79,11 @@ device		mmcsd
 device		gpio
 device		gpioled
 
+# I2C
+device		iic
+device		iicbus
+device		bcm2835_bsc
+
 options 	KDB
 options 	DDB			#Enable the kernel debugger
 options 	INVARIANTS		#Enable calls of extra sanity checking

Modified: stable/10/sys/boot/fdt/dts/bcm2835.dtsi
==============================================================================
--- stable/10/sys/boot/fdt/dts/bcm2835.dtsi	Thu Jan 23 12:02:04 2014	(r261077)
+++ stable/10/sys/boot/fdt/dts/bcm2835.dtsi	Thu Jan 23 12:32:30 2014	(r261078)
@@ -396,6 +396,22 @@
 			};
 		};
 
+		bsc0 {
+			compatible = "broadcom,bcm2835-bsc",
+				     "broadcom,bcm2708-bsc";
+			reg = <0x205000 0x20>;
+			interrupts = <61>;
+			interrupt-parent = <&intc>;
+		};
+
+		bsc1 {
+			compatible = "broadcom,bcm2835-bsc",
+				     "broadcom,bcm2708-bsc";
+			reg = <0x804000 0x20>;
+			interrupts = <61>;
+			interrupt-parent = <&intc>;
+		};
+
 		spi0 {
 			compatible = "broadcom,bcm2835-spi",
 				     "broadcom,bcm2708-spi";

Modified: stable/10/sys/conf/files
==============================================================================
--- stable/10/sys/conf/files	Thu Jan 23 12:02:04 2014	(r261077)
+++ stable/10/sys/conf/files	Thu Jan 23 12:32:30 2014	(r261078)
@@ -1914,6 +1914,7 @@ dev/ofw/ofw_bus_if.m		optional fdt
 dev/ofw/ofw_bus_subr.c		optional fdt
 dev/ofw/ofw_fdt.c		optional fdt
 dev/ofw/ofw_if.m		optional fdt
+dev/ofw/ofw_iicbus.c		optional fdt iicbus
 dev/ofw/openfirm.c		optional fdt
 dev/ofw/openfirmio.c		optional fdt
 dev/patm/if_patm.c		optional patm pci



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