[PATCH 2/4] Added USB roothub support for Raspberry Pi.

Deval Shah deval.maker at gmail.com
Fri Aug 19 08:46:51 UTC 2016


---
 freebsd/sys/arm/broadcom/bcm2835/bcm283x_dwc_fdt.c | 27 ++++++++++++++++++++++
 freebsd/sys/dev/usb/controller/dwc_otg_fdt.c       | 10 ++++++++
 rtemsbsd/include/bsp/nexus-devices.h               |  9 ++++++++
 rtemsbsd/include/machine/rtems-bsd-nexus-bus.h     | 22 ++++++++++++++++++
 rtemsbsd/include/machine/rtems-bsd-sysinit.h       |  3 +++
 testsuite/usb01/usb-sysinit.h                      |  6 +++++
 6 files changed, 77 insertions(+)

diff --git a/freebsd/sys/arm/broadcom/bcm2835/bcm283x_dwc_fdt.c b/freebsd/sys/arm/broadcom/bcm2835/bcm283x_dwc_fdt.c
index 1ab4d08..d57f691 100644
--- a/freebsd/sys/arm/broadcom/bcm2835/bcm283x_dwc_fdt.c
+++ b/freebsd/sys/arm/broadcom/bcm2835/bcm283x_dwc_fdt.c
@@ -37,7 +37,9 @@ __FBSDID("$FreeBSD$");
 #include <sys/condvar.h>
 #include <sys/module.h>
 
+#ifndef __rtems__
 #include <dev/ofw/ofw_bus_subr.h>
+#endif
 
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
@@ -51,7 +53,12 @@ __FBSDID("$FreeBSD$");
 #include <dev/usb/controller/dwc_otg.h>
 #include <dev/usb/controller/dwc_otg_fdt.h>
 
+#ifndef __rtems__
 #include <arm/broadcom/bcm2835/bcm2835_mbox_prop.h>
+#else
+#include <bsp/mailbox.h>
+#include <bsp/vc.h>
+#endif
 
 static device_probe_t bcm283x_dwc_otg_probe;
 static device_attach_t bcm283x_dwc_otg_attach;
@@ -60,12 +67,15 @@ static int
 bcm283x_dwc_otg_probe(device_t dev)
 {
 
+	#ifndef __rtems__
+
 	if (!ofw_bus_status_okay(dev))
 		return (ENXIO);
 
 	if (!ofw_bus_is_compatible(dev, "broadcom,bcm2835-usb"))
 		return (ENXIO);
 
+	#endif
 	device_set_desc(dev, "DWC OTG 2.0 integrated USB controller (bcm283x)");
 
 	return (BUS_PROBE_VENDOR);
@@ -76,9 +86,21 @@ bcm283x_dwc_otg_attach(device_t dev)
 {
 	int err;
 
+	#ifndef __rtems__
+
 	err = bcm2835_mbox_set_power_state(BCM2835_MBOX_POWER_ID_USB_HCD, TRUE);
 	if (err)
 		device_printf(dev, "failed to set power state, err=%d\n", err);
+	#else
+
+	bcm2835_set_power_state_entries power_state_usb;
+	power_state_usb.dev_id = bcm2835_mailbox_power_udid_usb_hcd;
+	power_state_usb.state = BCM2835_MAILBOX_SET_POWER_STATE_REQ_ON;
+	err = bcm2835_mailbox_set_power_state(&power_state_usb);
+	if (err) 
+		device_printf(dev, "failed to set power state, err=%d\n", err);
+
+	#endif
 
 	return (dwc_otg_attach(dev));
 }
@@ -95,6 +117,11 @@ static devclass_t bcm283x_dwc_otg_devclass;
 
 DEFINE_CLASS_1(bcm283x_dwcotg, bcm283x_dwc_otg_driver, bcm283x_dwc_otg_methods,
     sizeof(struct dwc_otg_fdt_softc), dwc_otg_driver);
+#ifndef __rtems__
 DRIVER_MODULE(bcm283x_dwcotg, simplebus, bcm283x_dwc_otg_driver,
     bcm283x_dwc_otg_devclass, 0, 0);
+#else
+DRIVER_MODULE(bcm283x_dwcotg, nexus, bcm283x_dwc_otg_driver,
+	bcm283x_dwc_otg_devclass, 0, 0);
+#endif
 MODULE_DEPEND(bcm283x_dwcotg, usb, 1, 1, 1);
diff --git a/freebsd/sys/dev/usb/controller/dwc_otg_fdt.c b/freebsd/sys/dev/usb/controller/dwc_otg_fdt.c
index 2b7a715..d400d52 100644
--- a/freebsd/sys/dev/usb/controller/dwc_otg_fdt.c
+++ b/freebsd/sys/dev/usb/controller/dwc_otg_fdt.c
@@ -39,9 +39,11 @@ __FBSDID("$FreeBSD$");
 #include <sys/mutex.h>
 #include <sys/rman.h>
 
+#ifndef __rtems__
 #include <dev/ofw/openfirm.h>
 #include <dev/ofw/ofw_bus.h>
 #include <dev/ofw/ofw_bus_subr.h>
+#endif
 
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
@@ -64,11 +66,13 @@ static int
 dwc_otg_probe(device_t dev)
 {
 
+	#ifndef __rtems__
 	if (!ofw_bus_status_okay(dev))
 		return (ENXIO);
 
 	if (!ofw_bus_is_compatible(dev, "synopsys,designware-hs-otg2"))
 		return (ENXIO);
+	#endif
 
 	device_set_desc(dev, "DWC OTG 2.0 integrated USB controller");
 
@@ -89,6 +93,7 @@ dwc_otg_attach(device_t dev)
 	sc->sc_otg.sc_bus.devices_max = DWC_OTG_MAX_DEVICES;
 	sc->sc_otg.sc_bus.dma_bits = 32;
 
+	#ifndef __rtems__
 	/* get USB mode, if any */
 	if (OF_getprop(ofw_bus_get_node(dev), "dr_mode",
 	    &usb_mode, sizeof(usb_mode)) > 0) {
@@ -105,6 +110,7 @@ dwc_otg_attach(device_t dev)
 			    usb_mode);
 		}
 	}
+	#endif
 
 	/* get all DMA memory */
 	if (usb_bus_mem_alloc_all(&sc->sc_otg.sc_bus,
@@ -218,5 +224,9 @@ driver_t dwc_otg_driver = {
 
 static devclass_t dwc_otg_devclass;
 
+#ifndef __rtems__
 DRIVER_MODULE(dwcotg, simplebus, dwc_otg_driver, dwc_otg_devclass, 0, 0);
+#else /* __rtems__ */
+DRIVER_MODULE(dwcotg, nexus, dwc_otg_driver, dwc_otg_devclass, 0, 0);
+#endif /* __rtems__ */
 MODULE_DEPEND(dwcotg, usb, 1, 1, 1);
diff --git a/rtemsbsd/include/bsp/nexus-devices.h b/rtemsbsd/include/bsp/nexus-devices.h
index 45beb30..ce9d45c 100644
--- a/rtemsbsd/include/bsp/nexus-devices.h
+++ b/rtemsbsd/include/bsp/nexus-devices.h
@@ -82,6 +82,15 @@ RTEMS_BSD_DRIVER_PCI_EM;
 RTEMS_BSD_DRIVER_PCI_RE;
 RTEMS_BSD_DRIVER_REPHY;
 
+#elif defined(LIBBSP_ARM_RASPBERRYPI_BSP_H)
+
+#include <bsp/irq.h>
+
+RTEMS_BSD_DRIVER_BCM283X_DWCOTG(BCM2835_USB_BASE, 
+			BCM2835_IRQ_ID_USB);
+RTEMS_BSD_DRIVER_USB;
+RTEMS_BSD_DRIVER_USB_MASS;
+
 #elif defined(LIBBSP_POWERPC_QORIQ_BSP_H)
 
 #if !QORIQ_CHIP_IS_T_VARIANT(QORIQ_CHIP_VARIANT)
diff --git a/rtemsbsd/include/machine/rtems-bsd-nexus-bus.h b/rtemsbsd/include/machine/rtems-bsd-nexus-bus.h
index 5a3458c..467ea7b 100644
--- a/rtemsbsd/include/machine/rtems-bsd-nexus-bus.h
+++ b/rtemsbsd/include/machine/rtems-bsd-nexus-bus.h
@@ -46,6 +46,7 @@
  *   RTEMS_BSD_DRIVER_DWCOTG0
  *   RTEMS_BSD_DRIVER_DWCOTG0_BASE_ADDR
  *    RTEMS_BSD_DRIVER_DWCOTG0_IRQ
+ *   RTEMS_BSD_DRIVER_BCM283X_DWCOTG
  *   RTEMS_BSD_DRIVER_DWC_MMC
  *   RTEMS_BSD_DRIVER_MMC
  *   RTEMS_BSD_DRIVER_USB
@@ -155,6 +156,27 @@ extern "C" {
 #endif /* RTEMS_BSD_DRIVER_DWCOTG0 */
 
 /*
+ * RaspberryPi OTG USB Controller.
+ */
+#if !defined(RTEMS_BSD_DRIVER_BCM283X_DWCOTG)
+  #define RTEMS_BSD_DRIVER_BCM283X_DWCOTG(_base, _irq)                  \
+    static const rtems_bsd_device_resource bcm283x_dwcotg_res[] = {     \
+      {                                                                 \
+        .type = RTEMS_BSD_RES_MEMORY,                                   \
+        .start_request = 0,                                             \
+        .start_actual = (_base)                                         \
+      }, {                                                              \
+        .type = RTEMS_BSD_RES_IRQ,                                      \
+        .start_request = 0,                                             \
+        .start_actual = (_irq)                                          \
+      }                                                                 \
+    };                                                                  \
+    RTEMS_BSD_DEFINE_NEXUS_DEVICE(bcm283x_dwcotg, 0,                    \
+                                  RTEMS_ARRAY_SIZE(bcm283x_dwcotg_res), \
+                                  &bcm283x_dwcotg_res[0])
+#endif /* RTEMS_BSD_DRIVER_BCM283X_DWCOTG */
+
+/*
  * Designware/Synopsys MMC.
  */
 #if !defined(RTEMS_BSD_DRIVER_DWC_MMC)
diff --git a/rtemsbsd/include/machine/rtems-bsd-sysinit.h b/rtemsbsd/include/machine/rtems-bsd-sysinit.h
index 2c892da..b72e564 100644
--- a/rtemsbsd/include/machine/rtems-bsd-sysinit.h
+++ b/rtemsbsd/include/machine/rtems-bsd-sysinit.h
@@ -55,6 +55,9 @@
 #define SYSINIT_NEED_USB_EHCI \
 	SYSINIT_DRIVER_REFERENCE(ehci, nexus); \
 	SYSINIT_DRIVER_REFERENCE(usbus, ehci)
+	
+#define SYSINIT_NEED_USB_BCM283x_DWC_OTG \
+	SYSINIT_DRIVER_REFERENCE(bcm283x_dwcotg, nexus);
 
 #define SYSINIT_NEED_USB_MASS_STORAGE \
 	SYSINIT_DRIVER_REFERENCE(umass, uhub)
diff --git a/testsuite/usb01/usb-sysinit.h b/testsuite/usb01/usb-sysinit.h
index eca10ed..a26dc53 100644
--- a/testsuite/usb01/usb-sysinit.h
+++ b/testsuite/usb01/usb-sysinit.h
@@ -30,6 +30,8 @@
 	#define NEED_USB_OHCI
 #elif defined(__GEN83xx_BSP_h) || defined(LIBBSP_POWERPC_QORIQ_BSP_H)
 	#define NEED_USB_EHCI
+#elif defined(LIBBSP_ARM_RASPBERRYPI_BSP_H)
+	#define NEED_USB_OTG
 #endif
 
 SYSINIT_NEED_USB_CORE;
@@ -39,6 +41,10 @@ SYSINIT_NEED_USB_CORE;
 #ifdef NEED_USB_EHCI
 	SYSINIT_NEED_USB_EHCI;
 #endif
+#ifdef NEED_USB_OTG
+	SYSINIT_NEED_USB_BCM283x_DWC_OTG;
+#endif
+
 SYSINIT_NEED_USB_MASS_STORAGE;
 
 #endif /* USB_SYSINIT_INIT */
-- 
2.7.4




More information about the devel mailing list