[PATCH 4/5] Port am335x usb driver to RTEMS.

Sichen Zhao 1473996754 at qq.com
Fri Jun 23 13:33:49 UTC 2017


Now RTEMS can detect USB device on Beaglebone Black.
---
 freebsd/sys/arm/ti/am335x/am335x_musb.c        |  14 ++++
 freebsd/sys/arm/ti/am335x/am335x_prcm.c        |  18 +++++
 freebsd/sys/arm/ti/am335x/am335x_usbss.c       |  19 +++++
 freebsd/sys/arm/ti/ti_cpuid.h                  |  19 +++++
 freebsd/sys/arm/ti/ti_prcm.c                   |   2 +
 freebsd/sys/arm/ti/ti_scm.c                    |   9 +++
 libbsd.py                                      |  30 +++++++
 libbsd_waf.py                                  |   6 ++
 rtemsbsd/include/bsp/nexus-devices.h           |  12 +++
 rtemsbsd/include/machine/rtems-bsd-nexus-bus.h | 108 +++++++++++++++++++++++++
 10 files changed, 237 insertions(+)

diff --git a/freebsd/sys/arm/ti/am335x/am335x_musb.c b/freebsd/sys/arm/ti/am335x/am335x_musb.c
index 52d799c..fff217e 100644
--- a/freebsd/sys/arm/ti/am335x/am335x_musb.c
+++ b/freebsd/sys/arm/ti/am335x/am335x_musb.c
@@ -223,11 +223,13 @@ musbotg_wrapper_interrupt(void *arg)
 static int
 musbotg_probe(device_t dev)
 {
+#ifndef __rtems__
 	if (!ofw_bus_status_okay(dev))
 		return (ENXIO);
 
 	if (!ofw_bus_is_compatible(dev, "ti,musb-am33xx"))
 		return (ENXIO);
+#endif /* __rtems__ */
 
 	device_set_desc(dev, "TI AM33xx integrated USB OTG controller");
 
@@ -310,6 +312,7 @@ musbotg_attach(device_t dev)
 	}
 
 	sc->sc_otg.sc_platform_data = sc;
+#ifndef __rtems__
 	if (OF_getprop(ofw_bus_get_node(dev), "dr_mode", mode,
 	    sizeof(mode)) > 0) {
 		if (strcasecmp(mode, "host") == 0)
@@ -323,6 +326,13 @@ musbotg_attach(device_t dev)
 		else
 			sc->sc_otg.sc_mode = MUSB2_HOST_MODE;
 	}
+#else /* __rtems__ */
+	/* Beaglebone defaults: USB0 device, USB1 HOST. */
+	if (sc->sc_otg.sc_id == 0)
+		sc->sc_otg.sc_mode = MUSB2_DEVICE_MODE;
+	else
+		sc->sc_otg.sc_mode = MUSB2_HOST_MODE;
+#endif /* __rtems__ */
 
 	/*
 	 * software-controlled function
@@ -417,5 +427,9 @@ static driver_t musbotg_driver = {
 
 static devclass_t musbotg_devclass;
 
+#ifdef __rtems__
+DRIVER_MODULE(musbotg, nexus, musbotg_driver, musbotg_devclass, 0, 0);
+#else /* __rtems__ */
 DRIVER_MODULE(musbotg, usbss, musbotg_driver, musbotg_devclass, 0, 0);
+#endif /* __rtems__ */
 MODULE_DEPEND(musbotg, usbss, 1, 1, 1);
diff --git a/freebsd/sys/arm/ti/am335x/am335x_prcm.c b/freebsd/sys/arm/ti/am335x/am335x_prcm.c
index 1d10f7f..5ba452a 100644
--- a/freebsd/sys/arm/ti/am335x/am335x_prcm.c
+++ b/freebsd/sys/arm/ti/am335x/am335x_prcm.c
@@ -36,12 +36,18 @@ __FBSDID("$FreeBSD$");
 #include <sys/module.h>
 #include <sys/malloc.h>
 #include <sys/rman.h>
+#ifndef __rtems__
 #include <sys/timeet.h>
+#endif /* __rtems__ */
 #include <sys/timetc.h>
+#ifndef __rtems__
 #include <sys/watchdog.h>
+#endif /* __rtems__ */
 #include <machine/bus.h>
 #include <machine/cpu.h>
+#ifndef __rtems__
 #include <machine/intr.h>
+#endif /* __rtems__ */
 
 #include <arm/ti/tivar.h>
 #include <arm/ti/ti_scm.h>
@@ -409,6 +415,10 @@ static int
 am335x_prcm_probe(device_t dev)
 {
 
+#ifdef __rtems__
+	device_set_desc(dev, "AM335x Power and Clock Management");
+		return(BUS_PROBE_DEFAULT);
+#else /* __rtems__ */
 	if (!ofw_bus_status_okay(dev))
 		return (ENXIO);
 
@@ -418,6 +428,7 @@ am335x_prcm_probe(device_t dev)
 	}
 
 	return (ENXIO);
+#endif /* __rtems__ */
 }
 
 static int
@@ -438,7 +449,9 @@ am335x_prcm_attach(device_t dev)
 	sc->bsh = rman_get_bushandle(sc->res[0]);
 
 	am335x_prcm_sc = sc;
+#ifndef __rtems__
 	ti_cpu_reset = am335x_prcm_reset;
+#endif /* __rtems__ */
 
 	if (am335x_clk_get_sysclk_freq(NULL, &sysclk) != 0)
 		sysclk = 0;
@@ -467,8 +480,13 @@ static driver_t am335x_prcm_driver = {
 
 static devclass_t am335x_prcm_devclass;
 
+#ifdef __rtems__
+DRIVER_MODULE(am335x_prcm, nexus, am335x_prcm_driver,
+	am335x_prcm_devclass, 0, 0);
+#else /* __rtems__ */
 DRIVER_MODULE(am335x_prcm, simplebus, am335x_prcm_driver,
 	am335x_prcm_devclass, 0, 0);
+#endif /* __rtems__ */
 MODULE_VERSION(am335x_prcm, 1);
 MODULE_DEPEND(am335x_prcm, ti_scm, 1, 1, 1);
 
diff --git a/freebsd/sys/arm/ti/am335x/am335x_usbss.c b/freebsd/sys/arm/ti/am335x/am335x_usbss.c
index d7b43a2..9f8f912 100644
--- a/freebsd/sys/arm/ti/am335x/am335x_usbss.c
+++ b/freebsd/sys/arm/ti/am335x/am335x_usbss.c
@@ -116,11 +116,13 @@ static int
 usbss_probe(device_t dev)
 {
 
+#ifndef __rtems__
 	if (!ofw_bus_status_okay(dev))
 		return (ENXIO);
 
 	if (!ofw_bus_is_compatible(dev, "ti,am33xx-usb"))
 		return (ENXIO);
+#endif /* __rtems__ */
 
 	device_set_desc(dev, "TI AM33xx integrated USB OTG controller");
        
@@ -168,6 +170,7 @@ usbss_attach(device_t dev)
 	device_printf(dev, "TI AM335X USBSS v%d.%d.%d\n",
 	    (rev >> 8) & 7, (rev >> 6) & 3, rev & 63);
 
+#ifndef __rtems__
 	node = ofw_bus_get_node(dev);
 
 	if (node == -1) {
@@ -176,17 +179,20 @@ usbss_attach(device_t dev)
 	}
 
 	simplebus_init(dev, node);
+#endif /* __rtems__ */
 
 	/*
 	 * Allow devices to identify.
 	 */
 	bus_generic_probe(dev);
 
+#ifndef __rtems__
 	/*
 	 * Now walk the OFW tree and attach top-level devices.
 	 */
 	for (node = OF_child(node); node > 0; node = OF_peer(node))
 		simplebus_add_device(dev, node, 0, NULL, -1, NULL);
+#endif /* __rtems__ */
 
 	return (bus_generic_attach(dev));
 }
@@ -218,9 +224,22 @@ static device_method_t usbss_methods[] = {
 
 	DEVMETHOD_END
 };
+#ifdef __rtems__
+static driver_t usbss_driver = {
+	"usbss",
+	usbss_methods,
+	sizeof(struct usbss_softc),
+};
+#endif /* __rtems__ */
 
+#ifndef __rtems__
 DEFINE_CLASS_1(usbss, usbss_driver, usbss_methods,
     sizeof(struct usbss_softc), simplebus_driver);
+#endif /* __rtems__ */
 static devclass_t usbss_devclass;
+#ifdef __rtems__
+DRIVER_MODULE(usbss, nexus, usbss_driver, usbss_devclass, 0, 0);
+#else /* __rtems__ */
 DRIVER_MODULE(usbss, simplebus, usbss_driver, usbss_devclass, 0, 0);
+#endif /* __rtems__ */
 MODULE_DEPEND(usbss, usb, 1, 1, 1);
diff --git a/freebsd/sys/arm/ti/ti_cpuid.h b/freebsd/sys/arm/ti/ti_cpuid.h
index 715f080..213714b 100644
--- a/freebsd/sys/arm/ti/ti_cpuid.h
+++ b/freebsd/sys/arm/ti/ti_cpuid.h
@@ -29,6 +29,9 @@
 
 #ifndef _TI_CPUID_H_
 #define	_TI_CPUID_H_
+#ifdef __rtems__
+#include <bsp.h>
+#endif /* __rtems__ */
 
 #define	OMAP_MAKEREV(d, a, b, c) \
 	(uint32_t)(((d) << 16) | (((a) & 0xf) << 8) | (((b) & 0xf) << 4) | ((c) & 0xf))
@@ -70,7 +73,23 @@
 #define	CHIP_OMAP_4	0
 #define	CHIP_AM335X	1
 
+#ifdef __rtems__
+#ifdef IS_AM335X
+#define SOC_TI_AM335X
+#else
+#warning Unknown SOC.
+#endif
+
+#if defined(SOC_TI_AM335X)
+#define _ti_chip CHIP_AM335X
+#elif defined(SOC_OMAP4)
+#define _ti_chip CHIP_OMAP_4
+#else
+#define _ti_chip -1
+#endif
+#else /* __rtems__ */
 extern int _ti_chip;
+#endif /* __rtems__ */
 
 static __inline int ti_chip(void)
 {
diff --git a/freebsd/sys/arm/ti/ti_prcm.c b/freebsd/sys/arm/ti/ti_prcm.c
index b4dd03f..04b1b6b 100644
--- a/freebsd/sys/arm/ti/ti_prcm.c
+++ b/freebsd/sys/arm/ti/ti_prcm.c
@@ -55,7 +55,9 @@ __FBSDID("$FreeBSD$");
 
 #include <machine/bus.h>
 #include <machine/resource.h>
+#ifndef __rtems__
 #include <machine/intr.h>
+#endif /* __rtems__ */
 
 #include <arm/ti/ti_cpuid.h>
 #include <arm/ti/ti_prcm.h>
diff --git a/freebsd/sys/arm/ti/ti_scm.c b/freebsd/sys/arm/ti/ti_scm.c
index 2e54262..2ea9975 100644
--- a/freebsd/sys/arm/ti/ti_scm.c
+++ b/freebsd/sys/arm/ti/ti_scm.c
@@ -66,7 +66,9 @@ __FBSDID("$FreeBSD$");
 #include <dev/ofw/openfirm.h>
 #include <dev/ofw/ofw_bus.h>
 #include <dev/ofw/ofw_bus_subr.h>
+#ifndef __rtems__
 #include <dev/fdt/fdt_pinctrl.h>
+#endif /* __rtems__ */
 
 #include "ti_scm.h"
 
@@ -88,6 +90,7 @@ static struct ti_scm_softc *ti_scm_sc;
 static int
 ti_scm_probe(device_t dev)
 {
+#ifndef __rtems__
 	if (!ofw_bus_status_okay(dev))
 		return (ENXIO);
 
@@ -97,6 +100,7 @@ ti_scm_probe(device_t dev)
 	if (ti_scm_sc) {
 		return (EEXIST);
 	}
+#endif /* __rtems__ */
 
 	device_set_desc(dev, "TI Control Module");
 	return (BUS_PROBE_DEFAULT);
@@ -172,5 +176,10 @@ static driver_t ti_scm_driver = {
 
 static devclass_t ti_scm_devclass;
 
+#ifdef __rtems__
+EARLY_DRIVER_MODULE(ti_scm, nexus, ti_scm_driver, ti_scm_devclass, 0, 0,
+    BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);
+#else /* __rtems__ */
 EARLY_DRIVER_MODULE(ti_scm, simplebus, ti_scm_driver, ti_scm_devclass, 0, 0,
     BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);
+#endif /* __rtems__ */
diff --git a/libbsd.py b/libbsd.py
index e171a9d..c53d5a00 100644
--- a/libbsd.py
+++ b/libbsd.py
@@ -890,6 +890,35 @@ def dev_usb_storage_add_on(mm):
     return mod
 
 #
+# BBB USB
+#
+def dev_usb_controller_bbb(mm):
+    mod = builder.Module('dev_usb_controller_bbb')
+    mod.addDependency(mm['dev_usb'])
+    mod.addKernelSpaceHeaderFiles(
+        [
+            'sys/arm/ti/ti_cpuid.h',
+            'sys/arm/ti/ti_prcm.h',
+            'sys/arm/ti/ti_scm.h',
+            'sys/arm/ti/tivar.h',
+            'sys/arm/ti/am335x/am335x_scm.h',
+            'sys/dev/usb/controller/musb_otg.h',
+        ]
+    )
+    mod.addKernelSpaceSourceFiles(
+        [
+            'sys/arm/ti/ti_scm.c',
+            'sys/arm/ti/am335x/am335x_prcm.c',
+            'sys/arm/ti/am335x/am335x_usbss.c',
+            'sys/arm/ti/ti_prcm.c',
+            'sys/arm/ti/am335x/am335x_musb.c',
+            'sys/dev/usb/controller/musb_otg.c',
+        ],
+        mm.generator['source']()
+    )
+    return mod
+
+#
 # USB Template
 #
 def dev_usb_template(mm):
@@ -3195,6 +3224,7 @@ def sources(mm):
     mm.addModule(cam(mm))
     mm.addModule(dev_usb_storage(mm))
     #mm.addModule(dev_usb_storage_add_on(mm))
+    mm.addModule(dev_usb_controller_bbb(mm))
 
     #mm.addModule(dev_usb_template(mm))
 
diff --git a/libbsd_waf.py b/libbsd_waf.py
index 30765de..5d0d5d0 100644
--- a/libbsd_waf.py
+++ b/libbsd_waf.py
@@ -731,6 +731,11 @@ def build(bld):
 
     source = ['freebsd/sys/arm/lpc/if_lpe.c',
               'freebsd/sys/arm/lpc/lpc_pwr.c',
+              'freebsd/sys/arm/ti/am335x/am335x_musb.c',
+              'freebsd/sys/arm/ti/am335x/am335x_prcm.c',
+              'freebsd/sys/arm/ti/am335x/am335x_usbss.c',
+              'freebsd/sys/arm/ti/ti_prcm.c',
+              'freebsd/sys/arm/ti/ti_scm.c',
               'freebsd/sys/arm/xilinx/zy7_slcr.c',
               'freebsd/sys/cam/cam.c',
               'freebsd/sys/cam/scsi/scsi_all.c',
@@ -896,6 +901,7 @@ def build(bld):
               'freebsd/sys/dev/tsec/if_tsec_fdt.c',
               'freebsd/sys/dev/usb/controller/dwc_otg.c',
               'freebsd/sys/dev/usb/controller/ehci.c',
+              'freebsd/sys/dev/usb/controller/musb_otg.c',
               'freebsd/sys/dev/usb/controller/ohci.c',
               'freebsd/sys/dev/usb/controller/usb_controller.c',
               'freebsd/sys/dev/usb/input/atp.c',
diff --git a/rtemsbsd/include/bsp/nexus-devices.h b/rtemsbsd/include/bsp/nexus-devices.h
index 1fbf756..6fe4f7d 100644
--- a/rtemsbsd/include/bsp/nexus-devices.h
+++ b/rtemsbsd/include/bsp/nexus-devices.h
@@ -46,6 +46,18 @@
 
 RTEMS_BSD_DRIVER_SMC0(0x4e000000,  RVPBXA9_IRQ_ETHERNET);
 
+#elif defined(LIBBSP_ARM_BEAGLE_BSP_H)
+
+#include <bsp/irq.h>
+
+RTEMS_BSD_DRIVER_MUSB1(0x47401c00, 0x47401800, 0x13);
+RTEMS_BSD_DRIVER_MUSB0(0x47401400, 0x47401000, 0x12);
+RTEMS_BSD_DRIVER_USBSS(0x47400000);
+RTEMS_BSD_DRIVER_AM335x_PRCM(0x44e00000);
+RTEMS_BSD_DRIVER_TI_SCM(0x44e10000);
+
+RTEMS_BSD_DRIVER_USB;
+
 #elif defined(LIBBSP_ARM_LPC32XX_BSP_H)
 
 #include <bsp/irq.h>
diff --git a/rtemsbsd/include/machine/rtems-bsd-nexus-bus.h b/rtemsbsd/include/machine/rtems-bsd-nexus-bus.h
index 06048b7..fc15bab 100644
--- a/rtemsbsd/include/machine/rtems-bsd-nexus-bus.h
+++ b/rtemsbsd/include/machine/rtems-bsd-nexus-bus.h
@@ -40,6 +40,8 @@
  *   RTEMS_BSD_DRIVER_XILINX_ZYNQ_SLCR
  *   RTEMS_BSD_DRIVER_LPC32XX_PWR
  *   RTEMS_BSD_DRIVER_LPC32XX_TSC
+ *   RTEMS_BSD_DRIVER_TI_SCM
+ *   RTEMS_BSD_DRIVER_AM335x_PRCM
  *
  *  Buses:
  *   RTEMS_BSD_DRIVER_PC_LEGACY
@@ -53,6 +55,9 @@
  *   RTEMS_BSD_DRIVER_MMC
  *   RTEMS_BSD_DRIVER_USB
  *   RTEMS_BSD_DRIVER_USB_MASS
+ *   RTEMS_BSD_DRIVER_USBSS
+ *   RTEMS_BSD_DRIVER_MUSB0
+ *   RTEMS_BSD_DRIVER_MUSB1
  *
  *  Networking:
  *   RTEMS_BSD_DRIVER_SMC0
@@ -158,6 +163,40 @@ extern "C" {
                                   &lpc_tsc0_res[0])
 #endif /* RTEMS_BSD_DRIVER_LPC32XX_TSC */
 
+/*
+ * Ti SCM
+ */
+#if !defined(RTEMS_BSD_DRIVER_TI_SCM)
+  #define RTEMS_BSD_DRIVER_TI_SCM(_base)                            \
+    static const rtems_bsd_device_resource ti_scm_res[] = {         \
+      {                                                             \
+        .type = RTEMS_BSD_RES_MEMORY,                               \
+        .start_request = 0,                                         \
+        .start_actual = (_base)                                     \
+      }                                                             \
+    };                                                              \
+    RTEMS_BSD_DEFINE_NEXUS_DEVICE(ti_scm, 0,                        \
+                                  RTEMS_ARRAY_SIZE(ti_scm_res),     \
+                                  &ti_scm_res[0])
+#endif /* RTEMS_BSD_DRIVER_TI_SCM */
+
+/*
+ * AM335x PRCM
+ */
+#if !defined(RTEMS_BSD_DRIVER_AM335x_PRCM)
+  #define RTEMS_BSD_DRIVER_AM335x_PRCM(_base)                       \
+    static const rtems_bsd_device_resource am335x_prcm_res[] = {    \
+      {                                                             \
+        .type = RTEMS_BSD_RES_MEMORY,                               \
+        .start_request = 0,                                         \
+        .start_actual = (_base)                                     \
+      }                                                             \
+    };                                                              \
+    RTEMS_BSD_DEFINE_NEXUS_DEVICE(am335x_prcm, 0,                   \
+                                  RTEMS_ARRAY_SIZE(am335x_prcm_res),\
+                                  &am335x_prcm_res[0])
+#endif /* RTEMS_BSD_DRIVER_AM335x_PRCM */
+
 /**
  ** Physical Buses
  **/
@@ -255,6 +294,75 @@ extern "C" {
     SYSINIT_DRIVER_REFERENCE(umass, uhub)
 #endif /* RTEMS_BSD_DRIVER_USB_MASS */
 
+/*
+ * USBSS driver.
+ */
+#if !defined(RTEMS_BSD_DRIVER_USBSS)
+  #define RTEMS_BSD_DRIVER_USBSS(_base)                             \
+    static const rtems_bsd_device_resource usbss_res[] = {          \
+      {                                                             \
+        .type = RTEMS_BSD_RES_MEMORY,                               \
+        .start_request = 0,                                         \
+        .start_actual = (_base)                                     \
+      }                                                             \
+    };                                                              \
+    RTEMS_BSD_DEFINE_NEXUS_DEVICE(usbss, 0,                         \
+                                  RTEMS_ARRAY_SIZE(usbss_res),      \
+                                  &usbss_res[0])
+#endif /* RTEMS_BSD_DRIVER_USBSS */
+
+/*
+ * MUSB0 driver.
+ */
+#if !defined(RTEMS_BSD_DRIVER_MUSB0)
+  #define RTEMS_BSD_DRIVER_MUSB0(_base0, _base1, _irq)              \
+    static const rtems_bsd_device_resource musbotg0_res[] = {       \
+      {                                                             \
+        .type = RTEMS_BSD_RES_MEMORY,                               \
+        .start_request = 0,                                         \
+        .start_actual = (_base0)                                    \
+      }, {                                                          \
+        .type = RTEMS_BSD_RES_MEMORY,                               \
+        .start_request = 1,                                         \
+        .start_actual = (_base1)                                    \
+      }, {                                                          \
+        .type = RTEMS_BSD_RES_IRQ,                                  \
+        .start_request = 0,                                         \
+        .start_actual = (_irq)                                      \
+      }                                                             \
+                                                                    \
+    };                                                              \
+    RTEMS_BSD_DEFINE_NEXUS_DEVICE(musbotg, 0,                       \
+                                  RTEMS_ARRAY_SIZE(musbotg0_res),   \
+                                  &musbotg0_res[0])
+#endif /* RTEMS_BSD_DRIVER_MUSB0 */
+
+/*
+ * MUSB1 driver.
+ */
+#if !defined(RTEMS_BSD_DRIVER_MUSB1)
+  #define RTEMS_BSD_DRIVER_MUSB1(_base0, _base1, _irq)              \
+    static const rtems_bsd_device_resource musbotg1_res[] = {       \
+      {                                                             \
+        .type = RTEMS_BSD_RES_MEMORY,                               \
+        .start_request = 0,                                         \
+        .start_actual = (_base0)                                    \
+      }, {                                                          \
+        .type = RTEMS_BSD_RES_MEMORY,                               \
+        .start_request = 1,                                         \
+        .start_actual = (_base1)                                    \
+      }, {                                                          \
+        .type = RTEMS_BSD_RES_IRQ,                                  \
+        .start_request = 0,                                         \
+        .start_actual = (_irq)                                      \
+      }                                                             \
+                                                                    \
+    };                                                              \
+    RTEMS_BSD_DEFINE_NEXUS_DEVICE(musbotg, 1,                       \
+                                  RTEMS_ARRAY_SIZE(musbotg1_res),   \
+                                  &musbotg1_res[0])
+#endif /* RTEMS_BSD_DRIVER_MUSB1 */
+
 /**
  ** Networking
  **/
-- 
2.7.4






More information about the devel mailing list