1 From 1ab2bc7fb6de19bcf4da83f4f0f384d93db48711 Mon Sep 17 00:00:00 2001
2 From: Michael Zoran <mzoran@crowfest.net>
3 Date: Sat, 14 Jan 2017 21:33:51 -0800
4 Subject: [PATCH] ARM64/DWC_OTG: Port dwc_otg driver to ARM64
6 In ARM64, the FIQ mechanism used by this driver is not current
7 implemented. As a workaround, reqular IRQ is used instead
10 In a separate change, the IRQ-CPU mapping is round robined
11 on ARM64 to increase concurrency and allow multiple interrupts
12 to be serviced at a time. This reduces the need for FIQ.
16 This mechanism is most likely to break when multiple USB devices
17 are attached at the same time. So the system was tested under
22 1. USB Speakers playing back a FLAC audio through VLC
23 at 96KHz.(Higher then typically, but supported on my speakers).
25 2. sftp transferring large files through the buildin ethernet
26 connection which is connected through USB.
28 3. Keyboard and mouse attached and being used.
30 Although I do occasionally hear some glitches, the music seems to
33 Signed-off-by: Michael Zoran <mzoran@crowfest.net>
35 drivers/usb/host/dwc_otg/Makefile | 3 +
36 drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c | 17 +++++
37 drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h | 24 +++++++
38 drivers/usb/host/dwc_otg/dwc_otg_hcd.c | 4 ++
39 drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h | 4 ++
40 drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c | 3 +-
41 drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c | 72 ++++++++++++++++++++
42 drivers/usb/host/dwc_otg/dwc_otg_os_dep.h | 2 +
43 8 files changed, 128 insertions(+), 1 deletion(-)
45 --- a/drivers/usb/host/dwc_otg/Makefile
46 +++ b/drivers/usb/host/dwc_otg/Makefile
47 @@ -37,7 +37,10 @@ dwc_otg-objs += dwc_otg_pcd_linux.o dwc_
48 dwc_otg-objs += dwc_otg_hcd.o dwc_otg_hcd_linux.o dwc_otg_hcd_intr.o dwc_otg_hcd_queue.o dwc_otg_hcd_ddma.o
49 dwc_otg-objs += dwc_otg_adp.o
50 dwc_otg-objs += dwc_otg_fiq_fsm.o
51 +ifneq ($(CONFIG_ARM64),y)
52 dwc_otg-objs += dwc_otg_fiq_stub.o
56 dwc_otg-objs += dwc_otg_cfi.o
58 --- a/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c
59 +++ b/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c
60 @@ -74,6 +74,21 @@ void notrace _fiq_print(enum fiq_debug_l
67 +inline void fiq_fsm_spin_lock(fiq_lock_t *lock)
69 + spin_lock((spinlock_t *)lock);
72 +inline void fiq_fsm_spin_unlock(fiq_lock_t *lock)
74 + spin_unlock((spinlock_t *)lock);
80 * fiq_fsm_spin_lock() - ARMv6+ bare bones spinlock
81 * Must be called with local interrupts and FIQ disabled.
82 @@ -121,6 +136,8 @@ inline void fiq_fsm_spin_unlock(fiq_lock
83 inline void fiq_fsm_spin_unlock(fiq_lock_t *lock) { }
89 * fiq_fsm_restart_channel() - Poke channel enable bit for a split transaction
90 * @channel: channel to re-enable
91 --- a/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h
92 +++ b/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h
93 @@ -127,6 +127,12 @@ enum fiq_debug_level {
94 FIQDBG_PORTHUB = (1 << 3),
99 +typedef spinlock_t fiq_lock_t;
106 @@ -137,6 +143,8 @@ typedef struct {
114 extern void _fiq_print (enum fiq_debug_level dbg_lvl, volatile struct fiq_state *state, char *fmt, ...);
115 @@ -357,6 +365,22 @@ struct fiq_state {
116 struct fiq_channel_state channel[0];
121 +#ifdef local_fiq_enable
122 +#undef local_fiq_enable
125 +#ifdef local_fiq_disable
126 +#undef local_fiq_disable
129 +extern void local_fiq_enable(void);
131 +extern void local_fiq_disable(void);
135 extern void fiq_fsm_spin_lock(fiq_lock_t *lock);
137 extern void fiq_fsm_spin_unlock(fiq_lock_t *lock);
138 --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
139 +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
140 @@ -1014,6 +1014,10 @@ int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd
142 DWC_MEMSET(hcd->fiq_state, 0, (sizeof(struct fiq_state) + (sizeof(struct fiq_channel_state) * num_channels)));
145 + spin_lock_init(&hcd->fiq_state->lock);
148 for (i = 0; i < num_channels; i++) {
149 hcd->fiq_state->channel[i].fsm = FIQ_PASSTHROUGH;
151 --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h
152 +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h
153 @@ -116,7 +116,11 @@ extern int32_t dwc_otg_hcd_handle_intr(d
154 /** This function is used to handle the fast interrupt
158 +extern void dwc_otg_hcd_handle_fiq(void);
160 extern void __attribute__ ((naked)) dwc_otg_hcd_handle_fiq(void);
164 * Returns private data set by
165 --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
166 +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
168 #include "dwc_otg_regs.h"
170 #include <linux/jiffies.h>
176 extern bool microframe_schedule;
178 --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c
179 +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c
181 #include <linux/dma-mapping.h>
182 #include <linux/version.h>
187 #include <linux/usb.h>
188 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)
189 #include <../drivers/usb/core/hcd.h>
191 #include "dwc_otg_driver.h"
192 #include "dwc_otg_hcd.h"
194 +#ifndef __virt_to_bus
195 +#define __virt_to_bus __virt_to_phys
196 +#define __bus_to_virt __phys_to_virt
197 +#define __pfn_to_bus(x) __pfn_to_phys(x)
198 +#define __bus_to_pfn(x) __phys_to_pfn(x)
201 extern unsigned char _dwc_otg_fiq_stub, _dwc_otg_fiq_stub_end;
204 @@ -395,14 +404,49 @@ static struct dwc_otg_hcd_function_ops h
205 .get_b_hnp_enable = _get_b_hnp_enable,
210 +static int simfiq_irq = -1;
212 +void local_fiq_enable(void)
214 + if (simfiq_irq >= 0)
215 + enable_irq(simfiq_irq);
218 +void local_fiq_disable(void)
220 + if (simfiq_irq >= 0)
221 + disable_irq(simfiq_irq);
224 +irqreturn_t fiq_irq_handler(int irq, void *dev_id)
226 + dwc_otg_hcd_t *dwc_otg_hcd = (dwc_otg_hcd_t *)dev_id;
228 + if (fiq_fsm_enable)
229 + dwc_otg_fiq_fsm(dwc_otg_hcd->fiq_state, dwc_otg_hcd->core_if->core_params->host_channels);
231 + dwc_otg_fiq_nop(dwc_otg_hcd->fiq_state);
233 + return IRQ_HANDLED;
237 static struct fiq_handler fh = {
243 static void hcd_init_fiq(void *cookie)
245 dwc_otg_device_t *otg_dev = cookie;
246 dwc_otg_hcd_t *dwc_otg_hcd = otg_dev->hcd;
254 @@ -430,6 +474,7 @@ static void hcd_init_fiq(void *cookie)
256 // __show_regs(®s);
260 //Set the mphi periph to the required registers
261 dwc_otg_hcd->fiq_state->mphi_regs.base = otg_dev->os_dep.mphi_base;
262 @@ -448,6 +493,23 @@ static void hcd_init_fiq(void *cookie)
263 DWC_WARN("MPHI periph has NOT been enabled");
265 // Enable FIQ interrupt from USB peripheral
267 + irq = platform_get_irq(otg_dev->os_dep.platformdev, 1);
270 + DWC_ERROR("Can't get SIM-FIQ irq");
274 + retval = request_irq(irq, fiq_irq_handler, 0, "dwc_otg_sim-fiq", dwc_otg_hcd);
277 + DWC_ERROR("Unable to request SIM-FIQ irq\n");
283 #ifdef CONFIG_GENERIC_IRQ_MULTI_HANDLER
284 irq = platform_get_irq(otg_dev->os_dep.platformdev, 1);
286 @@ -464,6 +526,8 @@ static void hcd_init_fiq(void *cookie)
295 @@ -526,6 +590,13 @@ int hcd_init(dwc_bus_dev_t *_dev)
296 otg_dev->hcd = dwc_otg_hcd;
297 otg_dev->hcd->otg_dev = otg_dev;
300 + if (dwc_otg_hcd_init(dwc_otg_hcd, otg_dev->core_if))
304 + hcd_init_fiq(otg_dev);
306 if (dwc_otg_hcd_init(dwc_otg_hcd, otg_dev->core_if)) {
309 @@ -542,6 +613,7 @@ int hcd_init(dwc_bus_dev_t *_dev)
310 smp_call_function_single(0, hcd_init_fiq, otg_dev, 1);
315 hcd->self.otg_port = dwc_otg_hcd_otg_port(dwc_otg_hcd);
316 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33) //don't support for LM(with 2.6.20.1 kernel)
317 --- a/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h
318 +++ b/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h
321 #ifdef PLATFORM_INTERFACE
322 #include <linux/platform_device.h>
324 #include <asm/mach/map.h>
328 /** The OS page size */
329 #define DWC_OS_PAGE_SIZE PAGE_SIZE