From: Sebastian Huber <sebastian.hu...@embedded-brains.de>

Update #3869.
---
 freebsd/sys/arm/freescale/imx/imx6_usbphy.c | 11 ++++++
 freebsd/sys/dev/usb/controller/ehci_imx.c   | 12 +++++++
 freebsd/sys/dev/usb/usb_busdma.c            | 54 +++++++++++++++++++++++++++++
 libbsd.py                                   |  4 +++
 rtemsbsd/include/bsp/nexus-devices.h        |  5 +++
 5 files changed, 86 insertions(+)

diff --git a/freebsd/sys/arm/freescale/imx/imx6_usbphy.c 
b/freebsd/sys/arm/freescale/imx/imx6_usbphy.c
index 8f47507b..ad545601 100644
--- a/freebsd/sys/arm/freescale/imx/imx6_usbphy.c
+++ b/freebsd/sys/arm/freescale/imx/imx6_usbphy.c
@@ -91,6 +91,17 @@ usbphy_detach(device_t dev)
        return (0);
 }
 
+#ifdef __rtems__
+#define BUS_SPACE_PHYSADDR(res, offs) \
+       ((u_int)(rman_get_start(res)+(offs)))
+
+void
+imx6_anatop_write_4(bus_size_t offset, uint32_t value)
+{
+
+       bus_space_write_4(0, 0x20c8000, offset, value);
+}
+#endif /* __rtems__ */
 static int
 usbphy_attach(device_t dev)
 {
diff --git a/freebsd/sys/dev/usb/controller/ehci_imx.c 
b/freebsd/sys/dev/usb/controller/ehci_imx.c
index a872fb62..d158df1d 100644
--- a/freebsd/sys/dev/usb/controller/ehci_imx.c
+++ b/freebsd/sys/dev/usb/controller/ehci_imx.c
@@ -303,6 +303,16 @@ imx_ehci_probe(device_t dev)
                return (ENXIO);
 
        if (ofw_bus_search_compatible(dev, compat_data)->ocd_data != 0) {
+#ifdef __rtems__
+               char dr_mode[24];
+
+               if (OF_getprop(ofw_bus_get_node(dev), "dr_mode",
+                   &dr_mode, sizeof(dr_mode)) > 0 &&
+                   strcasecmp(dr_mode, "host") != 0) {
+                       return (ENXIO);
+               }
+#endif /* __rtems__ */
+
                device_set_desc(dev, "Freescale i.MX integrated USB 
controller");
                return (BUS_PROBE_DEFAULT);
        }
@@ -437,8 +447,10 @@ imx_ehci_attach(device_t dev)
                goto out;
        }
 
+#ifndef __rtems__
        /* Turn on clocks. */
        imx_ccm_usb_enable(dev);
+#endif /* __rtems__ */
 
        /* Disable overcurrent detection, if configured to do so. */
        if (OF_hasprop(ofw_bus_get_node(sc->dev), "disable-over-current"))
diff --git a/freebsd/sys/dev/usb/usb_busdma.c b/freebsd/sys/dev/usb/usb_busdma.c
index 9a70c687..c8000170 100644
--- a/freebsd/sys/dev/usb/usb_busdma.c
+++ b/freebsd/sys/dev/usb/usb_busdma.c
@@ -78,6 +78,52 @@ static void  usb_pc_common_mem_cb(void *, bus_dma_segment_t 
*, int, int,
                    uint8_t);
 #endif
 
+#ifdef __rtems__
+#include <bsp.h>
+#if defined(LIBBSP_ARM_IMX_BSP_H)
+#define NEED_MISSALIGNED_COPY
+#endif
+
+#ifdef NEED_MISSALIGNED_COPY
+/*
+ * Note: This functions are used instead of memcpy for regions where a
+ * misaligned access is not allowed (e.g. peripheral memory).
+ */
+static void misaligned_do_copy(
+  uint8_t *dst,
+  const uint8_t *src,
+  size_t n,
+  bool aligned
+)
+{
+  if (aligned) {
+    while (n > 3) {
+      *(uint32_t *)dst = *(uint32_t *)src;
+      dst += 4;
+      src += 4;
+      n -= 4;
+    }
+  }
+
+  while (n > 0) {
+    *dst = *src;
+    ++dst;
+    ++src;
+    --n;
+  }
+}
+
+void misaligned_copy_to_io(void *dst, const void *src, size_t n)
+{
+  misaligned_do_copy(dst, src, n, ((uintptr_t)dst) % 4 == 0);
+}
+
+void misaligned_copy_from_io(void *dst, const void *src, size_t n)
+{
+  misaligned_do_copy(dst, src, n, ((uintptr_t)src) % 4 == 0);
+}
+#endif
+#endif /* __rtems__ */
 /*------------------------------------------------------------------------*
  *  usbd_get_page - lookup DMA-able memory for the given offset
  *
@@ -182,7 +228,11 @@ usbd_copy_in(struct usb_page_cache *cache, usb_frlength_t 
offset,
                if (buf_res.length > len) {
                        buf_res.length = len;
                }
+#if defined(__rtems__) && defined(NEED_MISSALIGNED_COPY)
+               misaligned_copy_to_io(buf_res.buffer, ptr, buf_res.length);
+#else /* __rtems__ */
                memcpy(buf_res.buffer, ptr, buf_res.length);
+#endif /* __rtems__ */
 
                offset += buf_res.length;
                len -= buf_res.length;
@@ -302,7 +352,11 @@ usbd_copy_out(struct usb_page_cache *cache, usb_frlength_t 
offset,
                if (res.length > len) {
                        res.length = len;
                }
+#if defined(__rtems__) && defined(NEED_MISSALIGNED_COPY)
+               misaligned_copy_from_io(ptr, res.buffer, res.length);
+#else /* __rtems__ */
                memcpy(ptr, res.buffer, res.length);
+#endif /* __rtems__ */
 
                offset += res.length;
                len -= res.length;
diff --git a/libbsd.py b/libbsd.py
index 6eaca5ad..ed6493b2 100644
--- a/libbsd.py
+++ b/libbsd.py
@@ -5018,6 +5018,8 @@ class imx(builder.Module):
         mm = self.manager
         self.addKernelSpaceHeaderFiles(
             [
+                'sys/arm/freescale/imx/imx6_anatopreg.h',
+                'sys/arm/freescale/imx/imx6_anatopvar.h',
                 'sys/arm/freescale/imx/imx6_ccmreg.h',
                 'sys/arm/freescale/imx/imx6_machdep.h',
                 'sys/arm/freescale/imx/imx_machdep.h',
@@ -5026,6 +5028,8 @@ class imx(builder.Module):
         self.addKernelSpaceSourceFiles(
             [
                 'sys/arm/freescale/imx/imx6_ccm.c',
+                'sys/arm/freescale/imx/imx6_usbphy.c',
+                'sys/dev/usb/controller/ehci_imx.c',
             ],
             mm.generator['source']()
         )
diff --git a/rtemsbsd/include/bsp/nexus-devices.h 
b/rtemsbsd/include/bsp/nexus-devices.h
index 0a210bd9..d2ceab8e 100644
--- a/rtemsbsd/include/bsp/nexus-devices.h
+++ b/rtemsbsd/include/bsp/nexus-devices.h
@@ -128,6 +128,11 @@ RTEMS_BSD_DEFINE_NEXUS_DEVICE(ofwbus, 0, 0, NULL);
 SYSINIT_DRIVER_REFERENCE(simplebus, ofwbus);
 
 SYSINIT_DRIVER_REFERENCE(ccm, simplebus);
+SYSINIT_DRIVER_REFERENCE(ehci, simplebus);
+SYSINIT_DRIVER_REFERENCE(usbphy, simplebus);
+SYSINIT_DRIVER_REFERENCE(usbus, ehci);
+RTEMS_BSD_DRIVER_USB;
+RTEMS_BSD_DRIVER_USB_MASS;
 
 SYSINIT_DRIVER_REFERENCE(ffec, simplebus);
 SYSINIT_DRIVER_REFERENCE(ukphy, miibus);
-- 
2.16.4

_______________________________________________
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Reply via email to