Commit db402e005a7db7c60811deb199e0df3eec479601

Authored by Alexander Stein
Committed by Tom Rini
1 parent 4342557fad

dwc2: Add dcache support

This adds dcache support for dwc2. The DMA buffers must be DMA aligned and
is flushed for outgoing transactions before starting transfer. For
ingoing transactions it is invalidated after the transfer has finished.

Signed-off-by: Alexander Stein <alexanders83@web.de>
Acked-by: Stephen Warren <swarren@wwwdotorg.org>
[trini: Update to apply again on top of DM patches]
Signed-off-by: Tom Rini <trini@konsulko.com>

Showing 1 changed file with 17 additions and 7 deletions Side-by-side Diff

drivers/usb/host/dwc2.c
... ... @@ -27,8 +27,8 @@
27 27  
28 28 struct dwc2_priv {
29 29 #ifdef CONFIG_DM_USB
30   - uint8_t aligned_buffer[DWC2_DATA_BUF_SIZE] __aligned(8);
31   - uint8_t status_buffer[DWC2_STATUS_BUF_SIZE] __aligned(8);
  30 + uint8_t aligned_buffer[DWC2_DATA_BUF_SIZE] __aligned(ARCH_DMA_MINALIGN);
  31 + uint8_t status_buffer[DWC2_STATUS_BUF_SIZE] __aligned(ARCH_DMA_MINALIGN);
32 32 #else
33 33 uint8_t *aligned_buffer;
34 34 uint8_t *status_buffer;
... ... @@ -39,9 +39,11 @@
39 39 };
40 40  
41 41 #ifndef CONFIG_DM_USB
42   -/* We need doubleword-aligned buffers for DMA transfers */
43   -DEFINE_ALIGN_BUFFER(uint8_t, aligned_buffer_addr, DWC2_DATA_BUF_SIZE, 8);
44   -DEFINE_ALIGN_BUFFER(uint8_t, status_buffer_addr, DWC2_STATUS_BUF_SIZE, 8);
  42 +/* We need cacheline-aligned buffers for DMA transfers and dcache support */
  43 +DEFINE_ALIGN_BUFFER(uint8_t, aligned_buffer_addr, DWC2_DATA_BUF_SIZE,
  44 + ARCH_DMA_MINALIGN);
  45 +DEFINE_ALIGN_BUFFER(uint8_t, status_buffer_addr, DWC2_STATUS_BUF_SIZE,
  46 + ARCH_DMA_MINALIGN);
45 47  
46 48 static struct dwc2_priv local;
47 49 #endif
... ... @@ -821,8 +823,11 @@
821 823 &hc_regs->hctsiz);
822 824  
823 825 if (!in) {
824   - memcpy(priv->aligned_buffer, (char *)buffer + done,
825   - len);
  826 + memcpy(priv->aligned_buffer, (char *)buffer + done, len);
  827 +
  828 + flush_dcache_range((unsigned long)priv->aligned_buffer,
  829 + (unsigned long)((void *)priv->aligned_buffer +
  830 + roundup(len, ARCH_DMA_MINALIGN)));
826 831 }
827 832  
828 833 writel(phys_to_bus((unsigned long)priv->aligned_buffer),
... ... @@ -840,6 +845,11 @@
840 845  
841 846 if (in) {
842 847 xfer_len -= sub;
  848 +
  849 + invalidate_dcache_range((unsigned long)priv->aligned_buffer,
  850 + (unsigned long)((void *)priv->aligned_buffer +
  851 + roundup(xfer_len, ARCH_DMA_MINALIGN)));
  852 +
843 853 memcpy(buffer + done, priv->aligned_buffer, xfer_len);
844 854 if (sub)
845 855 stop_transfer = 1;