Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Provide dotg(4) - a driver for the Synposys DesignWare O...



details:   https://anonhg.NetBSD.org/src/rev/456154654e21
branches:  trunk
changeset: 783818:456154654e21
user:      skrll <skrll%NetBSD.org@localhost>
date:      Wed Jan 09 22:23:44 2013 +0000

description:
Provide dotg(4) - a driver for the Synposys DesignWare OTG USB IP found
in the RaspberryPI. The driver supports host mode and control, interrupt,
and bulk transfers only at this point.

Heavily based on the FreeBSD driver by Hans Petter Selasky.

Thanks to all who helped. Jared McNeill, Michael van Elst and other.

diffstat:

 sys/arch/arm/broadcom/bcm2835_dotg.c |   134 +
 sys/arch/arm/broadcom/bcm2835_obio.c |     6 +-
 sys/arch/arm/broadcom/files.bcm2835  |     6 +-
 sys/arch/evbarm/rpi/rpi_machdep.c    |     8 +-
 sys/conf/files                       |     7 +-
 sys/dev/usb/dwc_otg.c                |  4636 ++++++++++++++++++++++++++++++++++
 sys/dev/usb/dwc_otgreg.h             |   880 ++++++
 sys/dev/usb/dwc_otgvar.h             |   250 +
 8 files changed, 5920 insertions(+), 7 deletions(-)

diffs (truncated from 6017 to 300 lines):

diff -r dc3557acf0f4 -r 456154654e21 sys/arch/arm/broadcom/bcm2835_dotg.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_dotg.c      Wed Jan 09 22:23:44 2013 +0000
@@ -0,0 +1,134 @@
+/*     $NetBSD: bcm2835_dotg.c,v 1.1 2013/01/09 22:23:44 skrll Exp $   */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Nick Hudson
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_dotg.c,v 1.1 2013/01/09 22:23:44 skrll Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/bus.h>
+
+#include <arm/broadcom/bcm2835reg.h>
+#include <arm/broadcom/bcm_amba.h>
+
+#include <dev/usb/usb.h>
+#include <dev/usb/usbdi.h>
+#include <dev/usb/usbdivar.h>
+#include <dev/usb/usb_mem.h>
+
+#include <dev/usb/dwc_otgvar.h>
+
+struct bcmdotg_softc {
+       struct dwc_otg_softc    sc_dotg;
+
+       void                    *sc_ih;
+};
+
+static int bcmdotg_match(device_t, struct cfdata *, void *);
+static void bcmdotg_attach(device_t, device_t, void *);
+static void bcmdotg_deferred(device_t);
+
+CFATTACH_DECL_NEW(dotg_amba, sizeof(struct bcmdotg_softc),
+    bcmdotg_match, bcmdotg_attach, NULL, NULL);
+
+/* ARGSUSED */
+static int
+bcmdotg_match(device_t parent, struct cfdata *match, void *aux)
+{
+       struct amba_attach_args *aaa = aux;
+
+       if (strcmp(aaa->aaa_name, "dotg") != 0)
+               return 0;
+
+       return 1;
+}
+
+/* ARGSUSED */
+static void
+bcmdotg_attach(device_t parent, device_t self, void *aux)
+{
+       struct bcmdotg_softc *sc = device_private(self);
+       struct amba_attach_args *aaa = aux;
+       int error;
+
+       sc->sc_dotg.sc_dev = self;
+
+       sc->sc_dotg.sc_iot = aaa->aaa_iot;
+       sc->sc_dotg.sc_bus.dmatag = aaa->aaa_dmat;
+
+       error = bus_space_map(aaa->aaa_iot, aaa->aaa_addr, aaa->aaa_size, 0,
+           &sc->sc_dotg.sc_ioh);
+       if (error) {
+               aprint_error_dev(self,
+                   "can't map registers for %s: %d\n", aaa->aaa_name, error);
+               return;
+       }
+
+       aprint_naive(": USB controller\n");
+       aprint_normal(": USB controller\n");
+
+       sc->sc_ih = bcm2835_intr_establish(aaa->aaa_intr, IPL_USB,
+          dwc_otg_intr, &sc->sc_dotg);
+
+       if (sc->sc_ih == NULL) {
+               aprint_error_dev(self, "failed to establish interrupt %d\n",
+                    aaa->aaa_intr);
+               goto fail;
+       }
+       config_defer(self, bcmdotg_deferred);
+
+       return;
+
+fail:
+       if (sc->sc_ih) {
+               intr_disestablish(sc->sc_ih);
+               sc->sc_ih = NULL;
+       }
+       bus_space_unmap(sc->sc_dotg.sc_iot, sc->sc_dotg.sc_ioh, aaa->aaa_size);
+}
+
+static void
+bcmdotg_deferred(device_t self)
+{
+       struct bcmdotg_softc *sc = device_private(self);
+       int error;
+
+       error = dwc_otg_init(&sc->sc_dotg);
+       if (error != 0) {
+               aprint_error_dev(self, "couldn't initialize host, error=%d\n",
+                   error);
+               return;
+       }
+       sc->sc_dotg.sc_child = config_found(sc->sc_dotg.sc_dev, &sc->sc_dotg.sc_bus,
+           usbctlprint);
+}
+
diff -r dc3557acf0f4 -r 456154654e21 sys/arch/arm/broadcom/bcm2835_obio.c
--- a/sys/arch/arm/broadcom/bcm2835_obio.c      Wed Jan 09 22:03:49 2013 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_obio.c      Wed Jan 09 22:23:44 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bcm2835_obio.c,v 1.10 2013/01/08 23:51:33 jmcneill Exp $       */
+/*     $NetBSD: bcm2835_obio.c,v 1.11 2013/01/09 22:23:44 skrll Exp $  */
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_obio.c,v 1.10 2013/01/08 23:51:33 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_obio.c,v 1.11 2013/01/09 22:23:44 skrll Exp $");
 
 #include "locators.h"
 #include "obio.h"
@@ -119,7 +119,7 @@
                .ad_intr = BCM2835_INT_EMMC,
        },
        {
-               /* DOTG interface */
+               /* DesignWare_OTG USB controller */
                .ad_name = "dotg",
                .ad_addr = BCM2835_USB_BASE,
                .ad_size = BCM2835_USB_SIZE,
diff -r dc3557acf0f4 -r 456154654e21 sys/arch/arm/broadcom/files.bcm2835
--- a/sys/arch/arm/broadcom/files.bcm2835       Wed Jan 09 22:03:49 2013 +0000
+++ b/sys/arch/arm/broadcom/files.bcm2835       Wed Jan 09 22:23:44 2013 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.bcm2835,v 1.11 2013/01/08 23:52:48 jmcneill Exp $
+#      $NetBSD: files.bcm2835,v 1.12 2013/01/09 22:23:44 skrll Exp $
 #
 # Configuration info for Broadcom BCM2835 ARM Peripherals
 #
@@ -50,6 +50,10 @@
 attach sdhc at obio with bcmemmc
 file   arch/arm/broadcom/bcm2835_emmc.c        bcmemmc
 
+# USB (BCM2835_USB_BASE)
+attach dotg at obio with dotg_amba
+file   arch/arm/broadcom/bcm2835_dotg.c        dotg    needs-flag
+
 # GPIO misc. functions
 define bcm2835_gpio_subr
 file   arch/arm/broadcom/bcm2835_gpio_subr.c   bcm2835_gpio_subr
diff -r dc3557acf0f4 -r 456154654e21 sys/arch/evbarm/rpi/rpi_machdep.c
--- a/sys/arch/evbarm/rpi/rpi_machdep.c Wed Jan 09 22:03:49 2013 +0000
+++ b/sys/arch/evbarm/rpi/rpi_machdep.c Wed Jan 09 22:23:44 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rpi_machdep.c,v 1.22 2013/01/09 00:24:54 jmcneill Exp $        */
+/*     $NetBSD: rpi_machdep.c,v 1.23 2013/01/09 22:23:44 skrll Exp $   */
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -30,11 +30,12 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rpi_machdep.c,v 1.22 2013/01/09 00:24:54 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rpi_machdep.c,v 1.23 2013/01/09 22:23:44 skrll Exp $");
 
 #include "opt_evbarm_boardtype.h"
 
 #include "sdhc.h"
+#include "dotg.h"
 #include "bcmspi.h"
 #include "bsciic.h"
 #include "plcom.h"
@@ -352,6 +353,9 @@
 #if (NPLCOM > 0)
            (1 << VCPM_POWER_UART0) |
 #endif
+#if (NDOTG > 0)
+           (1 << VCPM_POWER_USB) | 
+#endif
 #if (NBSCIIC > 0)
            (1 << VCPM_POWER_I2C0) | (1 << VCPM_POWER_I2C1) | 
        /*  (1 << VCPM_POWER_I2C2) | */
diff -r dc3557acf0f4 -r 456154654e21 sys/conf/files
--- a/sys/conf/files    Wed Jan 09 22:03:49 2013 +0000
+++ b/sys/conf/files    Wed Jan 09 22:23:44 2013 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files,v 1.1061 2012/11/14 02:03:25 rkujawa Exp $
+#      $NetBSD: files,v 1.1062 2013/01/09 22:23:45 skrll Exp $
 #      @(#)files.newconf       7.5 (Berkeley) 5/10/93
 
 version        20100430
@@ -1208,6 +1208,11 @@
 device slhci: usbus, usbroothub
 file   dev/ic/sl811hs.c                slhci                   needs-flag
 
+# DesignWare OTG host controller
+#
+device dotg: usbus, usbroothub, usb_dma
+file   dev/usb/dwc_otg.c               dotg                    needs-flag
+
 # USB HID processing (as used by bluetooth and usb code)
 define hid
 file   dev/usb/hid.c                   hid
diff -r dc3557acf0f4 -r 456154654e21 sys/dev/usb/dwc_otg.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/usb/dwc_otg.c     Wed Jan 09 22:23:44 2013 +0000
@@ -0,0 +1,4636 @@
+/*     $NetBSD: dwc_otg.c,v 1.1 2013/01/09 22:23:44 skrll Exp $        */
+
+/*-
+ * Copyright (c) 2012 Hans Petter Selasky. All rights reserved.
+ * Copyright (c) 2010-2011 Aleksandr Rybalko. 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.
+ */
+
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Nick Hudson
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+



Home | Main Index | Thread Index | Old Index