From 75cb8ba8a4c3b5f2a5bd7195ef3d61089151a6f5 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Wed, 21 Apr 2021 01:47:02 +0100 Subject: FiiO M3K/X1000: add USB support This only required a minor patch to the usb-designware driver due to DMA requiring physical addresses -- on the X1000, these differ from virtual addresses so we have to do the usual conversion. Both the mass storage and HID drivers work, but there are a few issues so this can't be considered 100% stable yet. - Mass storage might not be detected properly on insertion, and USB has to be replugged before it shows up - HID driver may occasionally panic or hang the machine Change-Id: Ia3ce7591d5928ec7cbca7953abfef01bdbd873ef --- firmware/drivers/usb-designware.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'firmware/drivers/usb-designware.c') diff --git a/firmware/drivers/usb-designware.c b/firmware/drivers/usb-designware.c index 24c6055434..375fd8be74 100644 --- a/firmware/drivers/usb-designware.c +++ b/firmware/drivers/usb-designware.c @@ -53,6 +53,15 @@ #define COMMIT_DCACHE_RANGE(b,s) commit_dcache_range(b,s) #endif +/* On some platforms, virtual addresses must be mangled to + * get a physical address for DMA + */ +#if CONFIG_CPU == X1000 +# define DMA_ADDR2PHYS(x) PHYSADDR(x) +#else +# define DMA_ADDR2PHYS(x) x +#endif + #ifndef USB_DW_TOUTCAL #define USB_DW_TOUTCAL 0 #endif @@ -449,7 +458,7 @@ static void usb_dw_nptx_unqueue(int epnum) dw_ep->addr -= (bytesinfifo + 3) >> 2; #else (void) bytesinfifo; - DWC_DIEPDMA(ep) = (uint32_t)(dw_ep->addr) + sentbytes; + DWC_DIEPDMA(ep) = DMA_ADDR2PHYS((uint32_t)(dw_ep->addr) + sentbytes); #endif DWC_DIEPTSIZ(ep) = PKTCNT(packetsleft) | (dw_ep->size - sentbytes); @@ -676,7 +685,7 @@ static void usb_dw_start_xfer(int epnum, /* Set up data source */ dw_ep->addr = (uint32_t*)buf; #ifndef USB_DW_ARCH_SLAVE - DWC_EPDMA(epnum, epdir) = (uint32_t)buf; + DWC_EPDMA(epnum, epdir) = DMA_ADDR2PHYS((uint32_t)buf); #endif if (epdir == USB_DW_EPDIR_IN) -- cgit v1.2.3