[PATCH v2 2/6] Ported driver bcm283x_dwcotg to RTEMS.
Deval Shah
deval.maker at gmail.com
Fri Aug 19 17:13:23 UTC 2016
---
freebsd/sys/arm/broadcom/bcm2835/bcm283x_dwc_fdt.c | 24 +++++++++++++++++
freebsd/sys/dev/usb/controller/dwc_otg_fdt.c | 10 ++++++++
libbsd.txt | 30 ++++++++++++++++++++++
rtemsbsd/include/machine/rtems-bsd-nexus-bus.h | 22 ++++++++++++++++
rtemsbsd/include/machine/rtems-bsd-sysinit.h | 3 +++
testsuite/usb01/usb-sysinit.h | 4 +++
6 files changed, 93 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..de73b57 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 /* __rtems__ */
+#include <bsp/mailbox.h>
+#include <bsp/vc.h>
+#endif /* __rtems__ */
static device_probe_t bcm283x_dwc_otg_probe;
static device_attach_t bcm283x_dwc_otg_attach;
@@ -60,11 +67,13 @@ 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 /* __rtems__ */
device_set_desc(dev, "DWC OTG 2.0 integrated USB controller (bcm283x)");
@@ -76,9 +85,19 @@ 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 /* __rtems__ */
+ 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 /* __rtems__ */
return (dwc_otg_attach(dev));
}
@@ -95,6 +114,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 /* __rtems__ */
+DRIVER_MODULE(bcm283x_dwcotg, nexus, bcm283x_dwc_otg_driver,
+ bcm283x_dwc_otg_devclass, 0, 0);
+#endif /* __rtems__ */
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..81d5078 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 /* __rtems__ */
#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 /* __rtems__ */
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 /* __rtems__ */
/* 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/libbsd.txt b/libbsd.txt
index d18f77b..80566e1 100644
--- a/libbsd.txt
+++ b/libbsd.txt
@@ -625,6 +625,36 @@ include a `__rtems__` in the guards to make searches easy, so use
* `#else /* __rtems__ */`, and
* `#endif /* __rtems__ */`.
+The guards must start at the begin of the line. Examples for wrong guards:
+
+-------------------------------------------------------------------------------
+static void
+guards_must_start_at_the_begin_of_the_line(int j)
+{
+
+ #ifdef __rtems__
+ return (j + 1);
+ #else /* __rtems__ */
+ return (j + 2);
+ #endif /* __rtems__ */
+}
+
+static void
+missing_rtems_comments_in_the_guards(int j)
+{
+
+#ifdef __rtems__
+ return (j + 3);
+#else
+ return (j + 4);
+#endif
+}
+-------------------------------------------------------------------------------
+
+Do not disable option header includes via guards. Instead, add an empty option
+header, e.g. `rtemsbsd/include/rtems/bsd/local/opt_xyz.h`. In general, provide
+empty header files and do not guard includes.
+
For new code use
http://www.freebsd.org/cgi/man.cgi?query=style&apropos=0&sektion=9&manpath=FreeBSD+9.2-RELEASE&arch=default&format=html[STYLE(9)].
Do not format original FreeBSD code.
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..c22bcf2 100644
--- a/testsuite/usb01/usb-sysinit.h
+++ b/testsuite/usb01/usb-sysinit.h
@@ -39,6 +39,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