1 From d0f04f1be88d3ad42f3c875f9ab45a1cdb2129bd Mon Sep 17 00:00:00 2001
2 From: Gordon Hollingworth <gordon@holliweb.co.uk>
3 Date: Thu, 4 Apr 2013 11:05:21 +0100
4 Subject: [PATCH 072/174] USB fix using a FIQ to implement split transactions
6 This commit adds a FIQ implementaion that schedules
7 the split transactions using a FIQ so we don't get
8 held off by the interrupt latency of Linux
10 .../usb/host/dwc_common_port/dwc_common_linux.c | 7 +-
11 drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c | 37 +-
12 drivers/usb/host/dwc_otg/dwc_otg_driver.c | 6 +-
13 drivers/usb/host/dwc_otg/dwc_otg_hcd.c | 125 ++++-
14 drivers/usb/host/dwc_otg/dwc_otg_hcd.h | 20 +-
15 drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c | 538 ++++++++++++++++++---
16 drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c | 18 +-
17 drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c | 31 +-
18 drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h | 26 +-
19 drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c | 2 +-
20 10 files changed, 696 insertions(+), 114 deletions(-)
22 --- a/drivers/usb/host/dwc_common_port/dwc_common_linux.c
23 +++ b/drivers/usb/host/dwc_common_port/dwc_common_linux.c
24 @@ -580,7 +580,12 @@ void DWC_WRITE_REG64(uint64_t volatile *
26 void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask)
28 + unsigned long flags;
30 + local_irq_save(flags);
31 + local_fiq_disable();
32 writel((readl(reg) & ~clear_mask) | set_mask, reg);
33 + local_irq_restore(flags);
37 @@ -1301,7 +1306,7 @@ EXPORT_SYMBOL(DWC_EXCEPTION);
38 EXPORT_SYMBOL(__DWC_DEBUG);
41 -EXPORT_SYMBOL(__DWC_DMA_ALLOC);
\r
42 +EXPORT_SYMBOL(__DWC_DMA_ALLOC);
43 EXPORT_SYMBOL(__DWC_DMA_ALLOC_ATOMIC);
44 EXPORT_SYMBOL(__DWC_DMA_FREE);
45 EXPORT_SYMBOL(__DWC_ALLOC);
46 --- a/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c
47 +++ b/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c
49 #include "dwc_otg_hcd.h"
50 #include "dwc_otg_mphi_fix.h"
52 -extern bool fiq_fix_enable;
55 inline const char *op_state_str(dwc_otg_core_if_t * core_if)
57 @@ -1321,7 +1319,7 @@ static int32_t dwc_otg_handle_lpm_intr(d
59 * This function returns the Core Interrupt register.
61 -static inline uint32_t dwc_otg_read_common_intr(dwc_otg_core_if_t * core_if)
62 +static inline uint32_t dwc_otg_read_common_intr(dwc_otg_core_if_t * core_if, gintmsk_data_t *reenable_gintmsk)
64 gahbcfg_data_t gahbcfg = {.d32 = 0 };
65 gintsts_data_t gintsts;
66 @@ -1338,19 +1336,33 @@ static inline uint32_t dwc_otg_read_comm
67 gintmsk_common.b.lpmtranrcvd = 1;
69 gintmsk_common.b.restoredone = 1;
70 - /** @todo: The port interrupt occurs while in device
71 - * mode. Added code to CIL to clear the interrupt for now!
73 - gintmsk_common.b.portintr = 1;
75 + if(dwc_otg_is_device_mode(core_if))
77 + /** @todo: The port interrupt occurs while in device
78 + * mode. Added code to CIL to clear the interrupt for now!
80 + gintmsk_common.b.portintr = 1;
82 gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
83 gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
85 + unsigned long flags;
87 + // Re-enable the saved interrupts
88 + local_irq_save(flags);
89 + local_fiq_disable();
90 + gintmsk.d32 |= gintmsk_common.d32;
91 + gintsts_saved.d32 &= ~gintmsk_common.d32;
92 + reenable_gintmsk->d32 = gintmsk.d32;
93 + local_irq_restore(flags);
96 gahbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
99 /* if any common interrupts set */
100 if (gintsts.d32 & gintmsk_common.d32) {
101 - DWC_DEBUGPL(DBG_ANY, "gintsts=%08x gintmsk=%08x\n",
102 + DWC_DEBUGPL(DBG_ANY, "common_intr: gintsts=%08x gintmsk=%08x\n",
103 gintsts.d32, gintmsk.d32);
106 @@ -1394,6 +1406,7 @@ int32_t dwc_otg_handle_common_intr(void
109 gintsts_data_t gintsts;
110 + gintmsk_data_t reenable_gintmsk;
111 gpwrdn_data_t gpwrdn = {.d32 = 0 };
112 dwc_otg_device_t *otg_dev = dev;
113 dwc_otg_core_if_t *core_if = otg_dev->core_if;
114 @@ -1415,7 +1428,7 @@ int32_t dwc_otg_handle_common_intr(void
117 if (core_if->hibernation_suspend <= 0) {
118 - gintsts.d32 = dwc_otg_read_common_intr(core_if);
119 + gintsts.d32 = dwc_otg_read_common_intr(core_if, &reenable_gintmsk);
121 if (gintsts.b.modemismatch) {
122 retval |= dwc_otg_handle_mode_mismatch_intr(core_if);
123 @@ -1512,8 +1525,12 @@ int32_t dwc_otg_handle_common_intr(void
124 gintsts.b.portintr = 1;
125 DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
127 + reenable_gintmsk.b.portintr = 1;
131 + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, reenable_gintmsk.d32);
134 DWC_DEBUGPL(DBG_ANY, "gpwrdn=%08x\n", gpwrdn.d32);
136 --- a/drivers/usb/host/dwc_otg/dwc_otg_driver.c
137 +++ b/drivers/usb/host/dwc_otg/dwc_otg_driver.c
138 @@ -242,7 +242,8 @@ static struct dwc_otg_driver_module_para
140 //Global variable to switch the fiq fix on or off (declared in bcm2708.c)
141 extern bool fiq_fix_enable;
143 +// Global variable to enable the split transaction fix
144 +bool fiq_split_enable = true;
145 //Global variable to switch the nak holdoff on or off
146 bool nak_holdoff_enable = true;
148 @@ -1090,6 +1091,7 @@ static int __init dwc_otg_driver_init(vo
150 printk(KERN_DEBUG "dwc_otg: FIQ %s\n", fiq_fix_enable ? "enabled":"disabled");
151 printk(KERN_DEBUG "dwc_otg: NAK holdoff %s\n", nak_holdoff_enable ? "enabled":"disabled");
152 + printk(KERN_DEBUG "dwc_otg: FIQ split fix %s\n", fiq_split_enable ? "enabled":"disabled");
154 error = driver_create_file(drv, &driver_attr_version);
156 @@ -1374,6 +1376,8 @@ module_param(fiq_fix_enable, bool, 0444)
157 MODULE_PARM_DESC(fiq_fix_enable, "Enable the fiq fix");
158 module_param(nak_holdoff_enable, bool, 0444);
159 MODULE_PARM_DESC(nak_holdoff_enable, "Enable the NAK holdoff");
160 +module_param(fiq_split_enable, bool, 0444);
161 +MODULE_PARM_DESC(fiq_split_enable, "Enable the FIQ fix on split transactions");
163 /** @page "Module Parameters"
165 --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
166 +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
169 #include "dwc_otg_hcd.h"
170 #include "dwc_otg_regs.h"
171 +#include "dwc_otg_mphi_fix.h"
173 extern bool microframe_schedule, nak_holdoff_enable;
175 @@ -581,6 +582,8 @@ int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_
177 dwc_otg_hc_halt(hcd->core_if, qh->channel,
178 DWC_OTG_HC_XFER_URB_DEQUEUE);
180 + dwc_otg_hcd_release_port(hcd, qh);
184 @@ -716,6 +719,8 @@ static void completion_tasklet_func(void
186 usb_hcd_giveback_urb(hcd->priv, urb, urb->status);
188 + fiq_print(FIQDBG_PORTHUB, "COMPLETE");
190 DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
192 DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
193 @@ -979,6 +984,10 @@ int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd
194 hcd->frame_list = NULL;
195 hcd->frame_list_dma = 0;
196 hcd->periodic_qh_count = 0;
198 + DWC_MEMSET(hcd->hub_port, 0, sizeof(hcd->hub_port));
199 + DWC_MEMSET(hcd->hub_port_alloc, -1, sizeof(hcd->hub_port_alloc));
204 @@ -1124,7 +1133,12 @@ static void assign_and_init_hc(dwc_otg_h
205 uint32_t hub_addr, port_addr;
207 hc->xact_pos = qtd->isoc_split_pos;
208 - hc->complete_split = qtd->complete_split;
209 + /* We don't need to do complete splits anymore */
210 + if(fiq_split_enable)
211 + hc->complete_split = qtd->complete_split = 0;
213 + hc->complete_split = qtd->complete_split;
215 hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &port_addr);
216 hc->hub_addr = (uint8_t) hub_addr;
217 hc->port_addr = (uint8_t) port_addr;
218 @@ -1271,6 +1285,62 @@ static void assign_and_init_hc(dwc_otg_h
223 +** Check the transaction to see if the port / hub has already been assigned for
224 +** a split transaction
226 +** Return 0 - Port is already in use
228 +int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh)
230 + uint32_t hub_addr, port_addr;
232 + if(!fiq_split_enable)
235 + hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
237 + if(hcd->hub_port[hub_addr] & (1 << port_addr))
239 + fiq_print(FIQDBG_PORTHUB, "H%dP%d:S%02d", hub_addr, port_addr, qh->skip_count);
243 + if(qh->skip_count > 40000)
245 + printk_once(KERN_ERR "Error: Having to skip port allocation");
246 + local_fiq_disable();
254 + qh->skip_count = 0;
255 + hcd->hub_port[hub_addr] |= 1 << port_addr;
256 + fiq_print(FIQDBG_PORTHUB, "H%dP%d:A %d", hub_addr, port_addr, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->pipe_info.ep_num);
257 + hcd->hub_port_alloc[hub_addr * 16 + port_addr] = dwc_otg_hcd_get_frame_number(hcd);
261 +void dwc_otg_hcd_release_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh)
263 + uint32_t hub_addr, port_addr;
265 + if(!fiq_split_enable)
268 + hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
270 + hcd->hub_port[hub_addr] &= ~(1 << port_addr);
271 + hcd->hub_port_alloc[hub_addr * 16 + port_addr] = -1;
273 + fiq_print(FIQDBG_PORTHUB, "H%dP%d:RO%d", hub_addr, port_addr, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->pipe_info.ep_num);
279 * This function selects transactions from the HCD transfer schedule and
280 * assigns them to available host channels. It is called from HCD interrupt
281 @@ -1304,11 +1374,22 @@ dwc_otg_transaction_type_e dwc_otg_hcd_s
283 while (qh_ptr != &hcd->periodic_sched_ready &&
284 !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
286 + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
288 + if(qh->do_split && dwc_otg_hcd_allocate_port(hcd, qh))
290 + qh_ptr = DWC_LIST_NEXT(qh_ptr);
291 + g_next_sched_frame = dwc_frame_num_inc(dwc_otg_hcd_get_frame_number(hcd), 1);
295 if (microframe_schedule) {
296 // Make sure we leave one channel for non periodic transactions.
297 DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
298 if (hcd->available_host_channels <= 1) {
299 DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
300 + if(qh->do_split) dwc_otg_hcd_release_port(hcd, qh);
303 hcd->available_host_channels--;
304 @@ -1329,8 +1410,6 @@ dwc_otg_transaction_type_e dwc_otg_hcd_s
305 DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
307 DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
309 - ret_val = DWC_OTG_TRANSACTION_PERIODIC;
313 @@ -1369,10 +1448,19 @@ dwc_otg_transaction_type_e dwc_otg_hcd_s
314 qh->nak_frame = 0xffff;
318 + if (qh->do_split && dwc_otg_hcd_allocate_port(hcd, qh))
320 + g_next_sched_frame = dwc_frame_num_inc(dwc_otg_hcd_get_frame_number(hcd), 1);
321 + qh_ptr = DWC_LIST_NEXT(qh_ptr);
325 if (microframe_schedule) {
326 DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
327 if (hcd->available_host_channels < 1) {
328 DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
329 + if(qh->do_split) dwc_otg_hcd_release_port(hcd, qh);
332 hcd->available_host_channels--;
333 @@ -1396,16 +1484,17 @@ dwc_otg_transaction_type_e dwc_otg_hcd_s
337 - if (ret_val == DWC_OTG_TRANSACTION_NONE) {
338 - ret_val = DWC_OTG_TRANSACTION_NON_PERIODIC;
340 - ret_val = DWC_OTG_TRANSACTION_ALL;
343 if (!microframe_schedule)
344 hcd->non_periodic_channels++;
347 + if(!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned))
348 + ret_val |= DWC_OTG_TRANSACTION_PERIODIC;
350 + if(!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active))
351 + ret_val |= DWC_OTG_TRANSACTION_NON_PERIODIC;
354 #ifdef DEBUG_HOST_CHANNELS
355 last_sel_trans_num_avail_hc_at_end = hcd->available_host_channels;
356 #endif /* DEBUG_HOST_CHANNELS */
357 @@ -1522,6 +1611,15 @@ static void process_periodic_channels(dw
359 qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
361 + // Do not send a split start transaction any later than frame .6
362 + // Note, we have to schedule a periodic in .5 to make it go in .6
363 + if(fiq_split_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
365 + qh_ptr = qh_ptr->next;
366 + g_next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
371 * Set a flag if we're queuing high-bandwidth in slave mode.
372 * The flag prevents any halts to get into the request queue in
373 @@ -1651,6 +1749,15 @@ static void process_non_periodic_channel
375 qh = DWC_LIST_ENTRY(hcd->non_periodic_qh_ptr, dwc_otg_qh_t,
378 + // Do not send a split start transaction any later than frame .5
379 + // non periodic transactions will start immediately in this uframe
380 + if(fiq_split_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
382 + g_next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
387 queue_transaction(hcd, qh->channel,
388 tx_status.b.nptxfspcavail);
389 --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd.h
390 +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd.h
391 @@ -168,10 +168,10 @@ typedef enum dwc_otg_control_phase {
393 /** Transaction types. */
394 typedef enum dwc_otg_transaction_type {
395 - DWC_OTG_TRANSACTION_NONE,
396 - DWC_OTG_TRANSACTION_PERIODIC,
397 - DWC_OTG_TRANSACTION_NON_PERIODIC,
398 - DWC_OTG_TRANSACTION_ALL
399 + DWC_OTG_TRANSACTION_NONE = 0,
400 + DWC_OTG_TRANSACTION_PERIODIC = 1,
401 + DWC_OTG_TRANSACTION_NON_PERIODIC = 2,
402 + DWC_OTG_TRANSACTION_ALL = DWC_OTG_TRANSACTION_PERIODIC + DWC_OTG_TRANSACTION_NON_PERIODIC
403 } dwc_otg_transaction_type_e;
406 @@ -370,6 +370,8 @@ typedef struct dwc_otg_qh {
409 uint16_t frame_usecs[8];
411 + uint32_t skip_count;
414 DWC_CIRCLEQ_HEAD(hc_list, dwc_hc);
415 @@ -574,6 +576,10 @@ struct dwc_otg_hcd {
417 uint32_t *frame_list;
419 + /** Hub - Port assignment */
421 + int hub_port_alloc[256];
423 /** Frame List DMA address */
424 dma_addr_t frame_list_dma;
426 @@ -604,12 +610,16 @@ extern dwc_otg_transaction_type_e dwc_ot
427 extern void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
428 dwc_otg_transaction_type_e tr_type);
430 +int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh);
431 +void dwc_otg_hcd_release_port(dwc_otg_hcd_t * dwc_otg_hcd, dwc_otg_qh_t *qh);
436 /** @name Interrupt Handler Functions */
438 extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
439 -extern int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * dwc_otg_hcd, int32_t);
440 +extern int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * dwc_otg_hcd);
441 extern int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t *
443 extern int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t *
444 --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
445 +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
448 #include <linux/jiffies.h>
449 #include <mach/hardware.h>
450 +#include <asm/fiq.h>
453 extern bool microframe_schedule;
454 @@ -52,21 +53,295 @@ extern bool microframe_schedule;
457 mphi_regs_t c_mphi_regs;
458 +volatile void *dwc_regs_base;
459 int fiq_done, int_done;
460 -int g_next_sched_frame, g_np_count, g_np_sent, g_work_expected;
461 -static int mphi_int_count = 0 ;
463 -extern bool fiq_fix_enable, nak_holdoff_enable;
464 +gintsts_data_t gintsts_saved = {.d32 = 0};
465 +hcint_data_t hcint_saved[MAX_EPS_CHANNELS];
466 +hcintmsk_data_t hcintmsk_saved[MAX_EPS_CHANNELS];
467 +int split_out_xfersize[MAX_EPS_CHANNELS];
468 +haint_data_t haint_saved;
470 +int g_next_sched_frame, g_np_count, g_np_sent;
471 +static int mphi_int_count = 0 ;
473 hcchar_data_t nak_hcchar;
474 hctsiz_data_t nak_hctsiz;
475 hcsplt_data_t nak_hcsplt;
478 +int complete_sched[MAX_EPS_CHANNELS] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
479 +int split_start_frame[MAX_EPS_CHANNELS];
480 +int queued_port[MAX_EPS_CHANNELS];
483 +char buffer[1000*16];
485 +void _fiq_print(FIQDBG_T dbg_lvl, char *fmt, ...)
487 + FIQDBG_T dbg_lvl_req = FIQDBG_PORTHUB;
490 + hfnum_data_t hfnum = { .d32 = FIQ_READ(dwc_regs_base + 0x408) };
491 + unsigned long flags;
493 + local_irq_save(flags);
494 + local_fiq_disable();
495 + if(dbg_lvl & dbg_lvl_req || dbg_lvl == FIQDBG_ERR)
497 + snprintf(text, 9, "%4d%d:%d ", hfnum.b.frnum/8, hfnum.b.frnum%8, 8 - hfnum.b.frrem/937);
498 + va_start(args, fmt);
499 + vsnprintf(text+8, 9, fmt, args);
502 + memcpy(buffer + wptr, text, 16);
503 + wptr = (wptr + 16) % sizeof(buffer);
505 + local_irq_restore(flags);
509 +void fiq_queue_request(int channel, int odd_frame)
511 + hcchar_data_t hcchar = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x0) };
512 + hcsplt_data_t hcsplt = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x4) };
513 + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x10) };
515 + if(hcsplt.b.spltena == 0)
517 + fiq_print(FIQDBG_ERR, "SPLTENA ");
521 + if(hcchar.b.epdir == 1)
523 + fiq_print(FIQDBG_SCHED, "IN Ch %d", channel);
527 + hctsiz.b.xfersize = 0;
528 + fiq_print(FIQDBG_SCHED, "OUT Ch %d", channel);
530 + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x10), hctsiz.d32);
532 + hcsplt.b.compsplt = 1;
533 + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x4), hcsplt.d32);
535 + // Send the Split complete
537 + hcchar.b.oddfrm = odd_frame ? 1 : 0;
539 + // Post this for transmit on the next frame for periodic or this frame for non-periodic
540 + fiq_print(FIQDBG_SCHED, "SND_%s", odd_frame ? "ODD " : "EVEN");
542 + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x0), hcchar.d32);
545 +static int last_sof = -1;
548 +** Function to handle the start of frame interrupt, choose whether we need to do anything and
549 +** therefore trigger the main interrupt
551 +** returns int != 0 - interrupt has been handled
555 +int fiq_sof_handle(hfnum_data_t hfnum)
560 + // Just check that once we're running we don't miss a SOF
561 + /*if(last_sof != -1 && (hfnum.b.frnum != ((last_sof + 1) & 0x3fff)))
563 + fiq_print(FIQDBG_ERR, "LASTSOF ");
564 + fiq_print(FIQDBG_ERR, "%4d%d ", last_sof / 8, last_sof & 7);
565 + fiq_print(FIQDBG_ERR, "%4d%d ", hfnum.b.frnum / 8, hfnum.b.frnum & 7);
569 + // Only start remembering the last sof when the interrupt has been
570 + // enabled (we don't check the mask to come in here...)
571 + if(last_sof != -1 || FIQ_READ(dwc_regs_base + 0x18) & (1<<3))
572 + last_sof = hfnum.b.frnum;
574 + for(i = 0; i < MAX_EPS_CHANNELS; i++)
576 + if(complete_sched[i] != -1)
578 + if(complete_sched[i] <= hfnum.b.frnum || (complete_sched[i] > 0x3f00 && hfnum.b.frnum < 0xf0))
580 + fiq_queue_request(i, hfnum.b.frnum & 1);
581 + complete_sched[i] = -1;
585 + if(complete_sched[i] != -1)
587 + // This is because we've seen a split complete occur with no start...
588 + // most likely because missed the complete 0x3fff frames ago!
590 + diff = (hfnum.b.frnum + 0x3fff - complete_sched[i]) & 0x3fff ;
591 + if(diff > 32 && diff < 0x3f00)
593 + fiq_print(FIQDBG_ERR, "SPLTMISS");
599 + if(g_np_count == g_np_sent && dwc_frame_num_gt(g_next_sched_frame, hfnum.b.frnum))
602 + * If np_count != np_sent that means we need to queue non-periodic (bulk) packets this packet
603 + * g_next_sched_frame is the next frame we have periodic packets for
605 + * if neither of these are required for this frame then just clear the interrupt
614 +int port_id(hcsplt_data_t hcsplt)
616 + return hcsplt.b.prtaddr + (hcsplt.b.hubaddr << 8);
619 +int fiq_hcintr_handle(int channel, hfnum_data_t hfnum)
621 + hcchar_data_t hcchar = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x0) };
622 + hcsplt_data_t hcsplt = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x4) };
623 + hcint_data_t hcint = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x8) };
624 + hcintmsk_data_t hcintmsk = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0xc) };
625 + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x10)};
627 + hcint_saved[channel].d32 |= hcint.d32;
628 + hcintmsk_saved[channel].d32 = hcintmsk.d32;
630 + if(hcsplt.b.spltena)
632 + fiq_print(FIQDBG_PORTHUB, "ph: %4x", port_id(hcsplt));
635 + fiq_print(FIQDBG_SCHED, "CH HLT %d", channel);
636 + fiq_print(FIQDBG_SCHED, "%08x", hcint_saved[channel]);
638 + if(hcint.b.stall || hcint.b.xacterr || hcint.b.bblerr || hcint.b.frmovrun || hcint.b.datatglerr)
640 + queued_port[channel] = 0;
641 + fiq_print(FIQDBG_ERR, "CHAN ERR");
643 + if(hcint.b.xfercomp)
645 + // Clear the port allocation and transmit anything also on this port
646 + queued_port[channel] = 0;
647 + fiq_print(FIQDBG_SCHED, "XFERCOMP");
651 + queued_port[channel] = 0;
652 + fiq_print(FIQDBG_SCHED, "NAK");
654 + if(hcint.b.ack && !hcsplt.b.compsplt)
658 + // Do not complete isochronous out transactions
659 + if(hcchar.b.eptype == 1 && hcchar.b.epdir == 0)
661 + queued_port[channel] = 0;
662 + fiq_print(FIQDBG_SCHED, "ISOC_OUT");
666 + // Make sure we check the port / hub combination that we sent this split on.
667 + // Do not queue a second request to the same port
668 + for(i = 0; i < MAX_EPS_CHANNELS; i++)
670 + if(port_id(hcsplt) == queued_port[i])
672 + fiq_print(FIQDBG_ERR, "PORTERR ");
677 + split_start_frame[channel] = (hfnum.b.frnum + 1) & ~7;
679 + // Note, the size of an OUT is in the start split phase, not
680 + // the complete split
681 + split_out_xfersize[channel] = hctsiz.b.xfersize;
683 + hcint_saved[channel].b.chhltd = 0;
684 + hcint_saved[channel].b.ack = 0;
686 + queued_port[channel] = port_id(hcsplt);
688 + if(hcchar.b.eptype & 1)
690 + // Send the periodic complete in the same oddness frame as the ACK went...
691 + fiq_queue_request(channel, !(hfnum.b.frnum & 1));
692 + // complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 1);
696 + // Schedule the split complete to occur later
697 + complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 2);
698 + fiq_print(FIQDBG_SCHED, "ACK%04d%d", complete_sched[channel]/8, complete_sched[channel]%8);
704 + fiq_print(FIQDBG_ERR, "NYETERR1");
706 + // Can transmit a split complete up to uframe .0 of the next frame
707 + if(hfnum.b.frnum <= dwc_frame_num_inc(split_start_frame[channel], 8))
709 + // Send it next frame
710 + if(hcchar.b.eptype & 1) // type 1 & 3 are interrupt & isoc
712 + fiq_print(FIQDBG_SCHED, "NYT:SEND");
713 + fiq_queue_request(channel, !(hfnum.b.frnum & 1));
717 + // Schedule non-periodic access for next frame (the odd-even bit doesn't effect NP)
718 + complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 1);
719 + fiq_print(FIQDBG_SCHED, "NYT%04d%d", complete_sched[channel]/8, complete_sched[channel]%8);
721 + hcint_saved[channel].b.chhltd = 0;
722 + hcint_saved[channel].b.nyet = 0;
726 + queued_port[channel] = 0;
727 + fiq_print(FIQDBG_ERR, "NYETERR2");
733 + // Clear the interrupt, this will also clear the HAINT bit
734 + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x8), hcint.d32);
735 + return hcint_saved[channel].d32 == 0;
738 +gintsts_data_t gintsts;
739 +gintmsk_data_t gintmsk;
740 +// triggered: The set of interrupts that were triggered
741 +// handled: The set of interrupts that have been handled (no IRQ is
743 +// keep: The set of interrupts we want to keep unmasked even though we
744 +// want to trigger an IRQ to handle it (SOF and HCINTR)
745 +gintsts_data_t triggered, handled, keep;
748 void __attribute__ ((naked)) dwc_otg_hcd_handle_fiq(void)
750 - gintsts_data_t gintsts;
751 - hfnum_data_t hfnum;
753 /* entry takes care to store registers we will be treading on here */
755 @@ -74,43 +349,112 @@ void __attribute__ ((naked)) dwc_otg_hcd
756 /* stash FIQ and normal regs */
757 "stmdb sp!, {r0-r12, lr};"
758 /* !! THIS SETS THE FRAME, adjust to > sizeof locals */
759 - "sub fp, ip, #256 ;"
760 + "sub fp, ip, #512 ;"
764 - gintsts.d32 = FIQ_READ_IO_ADDRESS(USB_BASE + 0x14) & FIQ_READ_IO_ADDRESS(USB_BASE + 0x18);
765 - hfnum.d32 = FIQ_READ_IO_ADDRESS(USB_BASE + 0x408);
768 + // Cannot put local variables at the beginning of the function
769 + // because otherwise 'C' will play with the stack pointer. any locals
770 + // need to be inside the following block
773 - if(gintsts.b.sofintr && g_np_count == g_np_sent && dwc_frame_num_gt(g_next_sched_frame, hfnum.b.frnum))
775 + gintsts.d32 = FIQ_READ(dwc_regs_base + 0x14);
776 + gintmsk.d32 = FIQ_READ(dwc_regs_base + 0x18);
777 + hfnum.d32 = FIQ_READ(dwc_regs_base + 0x408);
778 + triggered.d32 = gintsts.d32 & gintmsk.d32;
781 + fiq_print(FIQDBG_INT, "FIQ ");
782 + fiq_print(FIQDBG_INT, "%08x", gintsts.d32);
783 + fiq_print(FIQDBG_INT, "%08x", gintmsk.d32);
787 - * If np_count != np_sent that means we need to queue non-periodic (bulk) packets this packet
788 - * g_next_sched_frame is the next frame we have periodic packets for
790 - * if neither of these are required for this frame then just clear the interrupt
793 - gintsts.b.sofintr = 1;
794 - FIQ_WRITE_IO_ADDRESS((USB_BASE + 0x14), gintsts.d32);
796 + if((FIQ_READ(dwc_regs_base + 0x440) & 0xf) == 0x5)
798 + if(gintsts.b.sofintr)
800 + if(fiq_sof_handle(hfnum))
802 + handled.b.sofintr = 1; /* Handled in FIQ */
806 + /* Keer interrupt unmasked */
807 + keep.b.sofintr = 1;
810 + // Need to make sure the read and clearing of the SOF interrupt is as close as possible to avoid the possibility of missing
811 + // a start of frame interrupt
812 + gintsts_data_t gintsts = { .b.sofintr = 1 };
813 + FIQ_WRITE((dwc_regs_base + 0x14), gintsts.d32);
817 + if(fiq_split_enable && gintsts.b.hcintr)
820 + haint_data_t haint;
821 + haintmsk_data_t haintmsk;
823 + haint.d32 = FIQ_READ(dwc_regs_base + 0x414);
824 + haintmsk.d32 = FIQ_READ(dwc_regs_base + 0x418);
825 + haint.d32 &= haintmsk.d32;
826 + haint_saved.d32 |= haint.d32;
828 + fiq_print(FIQDBG_INT, "hcintr");
829 + fiq_print(FIQDBG_INT, "%08x", FIQ_READ(dwc_regs_base + 0x414));
831 + // Go through each channel that has an enabled interrupt
832 + for(i = 0; i < 16; i++)
833 + if((haint.d32 >> i) & 1)
834 + if(fiq_hcintr_handle(i, hfnum))
835 + haint_saved.d32 &= ~(1 << i); /* this was handled */
837 + /* If we've handled all host channel interrupts then don't trigger the interrupt */
838 + if(haint_saved.d32 == 0)
840 + handled.b.hcintr = 1;
844 + /* Make sure we keep the channel interrupt unmasked when triggering the IRQ */
848 - g_work_expected = 0;
850 + gintsts_data_t gintsts = { .b.hcintr = 1 };
852 + // Always clear the channel interrupt
853 + FIQ_WRITE((dwc_regs_base + 0x14), gintsts.d32);
864 + // Mask out the interrupts triggered - those handled - don't mask out the ones we want to keep
865 + gintmsk.d32 = keep.d32 | (gintmsk.d32 & ~(triggered.d32 & ~handled.d32));
866 + // Save those that were triggered but not handled
867 + gintsts_saved.d32 |= triggered.d32 & ~handled.d32;
868 + FIQ_WRITE(dwc_regs_base + 0x18, gintmsk.d32);
870 + // Clear and save any unhandled interrupts and trigger the interrupt
871 + if(gintsts_saved.d32)
873 - g_work_expected = 1;
874 /* To enable the MPHI interrupt (INT 32)
876 - FIQ_WRITE( c_mphi_regs.outdda, (int) dummy_send);
877 + FIQ_WRITE( c_mphi_regs.outdda, (int) dummy_send);
878 FIQ_WRITE( c_mphi_regs.outddb, (1 << 29));
881 - /* Clear the USB global interrupt so we don't just sit in the FIQ */
882 - FIQ_MODIFY_IO_ADDRESS((USB_BASE + 0x8),1,0);
890 /* exit back to normal mode restoring everything */
891 @@ -133,6 +477,7 @@ int32_t dwc_otg_hcd_handle_intr(dwc_otg_
893 dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
894 gintsts_data_t gintsts;
895 + gintmsk_data_t gintmsk;
899 @@ -140,6 +485,9 @@ int32_t dwc_otg_hcd_handle_intr(dwc_otg_
903 + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
904 + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
906 /* Exit from ISR if core is hibernated */
907 if (core_if->hibernation_suspend == 1) {
908 goto exit_handler_routine;
909 @@ -147,11 +495,18 @@ int32_t dwc_otg_hcd_handle_intr(dwc_otg_
910 DWC_SPINLOCK(dwc_otg_hcd->lock);
911 /* Check if HOST Mode */
912 if (dwc_otg_is_host_mode(core_if)) {
913 - gintsts.d32 = dwc_otg_read_core_intr(core_if);
914 + local_fiq_disable();
915 + gintmsk.d32 |= gintsts_saved.d32;
916 + gintsts.d32 |= gintsts_saved.d32;
917 + gintsts_saved.d32 = 0;
918 + local_fiq_enable();
920 goto exit_handler_routine;
922 + gintsts.d32 &= gintmsk.d32;
925 + // We should be OK doing this because the common interrupts should already have been serviced
926 /* Don't print debug message in the interrupt handler on SOF */
928 if (gintsts.d32 != DWC_SOF_INTR_MASK)
929 @@ -171,11 +526,12 @@ int32_t dwc_otg_hcd_handle_intr(dwc_otg_
930 if (gintsts.b.sofintr && g_np_count == g_np_sent && dwc_frame_num_gt(g_next_sched_frame, hfnum.b.frnum))
932 /* Note, we should never get here if the FIQ is doing it's job properly*/
933 - retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd, g_work_expected);
934 + retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
936 else if (gintsts.b.sofintr) {
937 - retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd, g_work_expected);
938 + retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
941 if (gintsts.b.rxstsqlvl) {
943 dwc_otg_hcd_handle_rx_status_q_level_intr
944 @@ -190,7 +546,10 @@ int32_t dwc_otg_hcd_handle_intr(dwc_otg_
945 /** @todo Implement i2cintr handler. */
947 if (gintsts.b.portintr) {
949 + gintmsk_data_t gintmsk = { .b.portintr = 1};
950 retval |= dwc_otg_hcd_handle_port_intr(dwc_otg_hcd);
951 + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
953 if (gintsts.b.hcintr) {
954 retval |= dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd);
955 @@ -227,26 +586,35 @@ exit_handler_routine:
959 - /* Clear the MPHI interrupt */
960 - DWC_WRITE_REG32(c_mphi_regs.intstat, (1<<16));
961 - if (mphi_int_count >= 60)
962 + local_fiq_disable();
963 + // Make sure that we don't clear the interrupt if we've still got pending work to do
964 + if(gintsts_saved.d32 == 0)
966 - DWC_WRITE_REG32(c_mphi_regs.ctrl, ((1<<31) + (1<<16)));
967 - while(!(DWC_READ_REG32(c_mphi_regs.ctrl) & (1 << 17)))
969 - DWC_WRITE_REG32(c_mphi_regs.ctrl, (1<<31));
970 - mphi_int_count = 0;
971 + /* Clear the MPHI interrupt */
972 + DWC_WRITE_REG32(c_mphi_regs.intstat, (1<<16));
973 + if (mphi_int_count >= 60)
975 + DWC_WRITE_REG32(c_mphi_regs.ctrl, ((1<<31) + (1<<16)));
976 + while(!(DWC_READ_REG32(c_mphi_regs.ctrl) & (1 << 17)))
978 + DWC_WRITE_REG32(c_mphi_regs.ctrl, (1<<31));
979 + mphi_int_count = 0;
985 + // Unmask handled interrupts
986 + FIQ_WRITE(dwc_regs_base + 0x18, gintmsk.d32);
987 + //DWC_MODIFY_REG32((uint32_t *)IO_ADDRESS(USB_BASE + 0x8), 0 , 1);
989 + local_fiq_enable();
991 if((jiffies / HZ) > last_time)
993 /* Once a second output the fiq and irq numbers, useful for debug */
994 last_time = jiffies / HZ;
995 DWC_DEBUGPL(DBG_USER, "int_done = %d fiq_done = %d\n", int_done, fiq_done);
998 - /* Re-Enable FIQ interrupt from USB peripheral */
999 - DWC_MODIFY_REG32((uint32_t *)IO_ADDRESS(USB_BASE + 0x8), 0 , 1);
1002 DWC_SPINUNLOCK(dwc_otg_hcd->lock);
1003 @@ -294,13 +662,12 @@ static inline void track_missed_sofs(uin
1004 * (micro)frame. Periodic transactions may be queued to the controller for the
1005 * next (micro)frame.
1007 -int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * hcd, int32_t work_expected)
1008 +int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * hcd)
1011 dwc_list_link_t *qh_entry;
1013 dwc_otg_transaction_type_e tr_type;
1014 - gintsts_data_t gintsts = {.d32 = 0 };
1015 int did_something = 0;
1016 int32_t next_sched_frame = -1;
1018 @@ -326,6 +693,7 @@ int32_t dwc_otg_hcd_handle_sof_intr(dwc_
1019 qh = DWC_LIST_ENTRY(qh_entry, dwc_otg_qh_t, qh_list_entry);
1020 qh_entry = qh_entry->next;
1021 if (dwc_frame_num_le(qh->sched_frame, hcd->frame_number)) {
1024 * Move QH to the ready list to be executed next
1026 @@ -351,15 +719,10 @@ int32_t dwc_otg_hcd_handle_sof_intr(dwc_
1027 dwc_otg_hcd_queue_transactions(hcd, tr_type);
1030 - if(work_expected && !did_something)
1031 - DWC_DEBUGPL(DBG_USER, "Nothing to do !! frame = %x, g_next_sched_frame = %x\n", (int) hfnum.b.frnum, g_next_sched_frame);
1032 - if(!work_expected && did_something)
1033 - DWC_DEBUGPL(DBG_USER, "Unexpected work done !! frame = %x, g_next_sched_frame = %x\n", (int) hfnum.b.frnum, g_next_sched_frame);
1036 /* Clear interrupt */
1037 - gintsts.b.sofintr = 1;
1038 - DWC_WRITE_REG32(&hcd->core_if->core_global_regs->gintsts, gintsts.d32);
1039 + //gintsts.b.sofintr = 1;
1040 + //DWC_WRITE_REG32(&hcd->core_if->core_global_regs->gintsts, gintsts.d32);
1044 @@ -643,6 +1006,15 @@ int32_t dwc_otg_hcd_handle_hc_intr(dwc_o
1046 haint.d32 = dwc_otg_read_host_all_channels_intr(dwc_otg_hcd->core_if);
1048 + // Overwrite with saved interrupts from fiq handler
1049 + if(fiq_split_enable)
1051 + local_fiq_disable();
1052 + haint.d32 = haint_saved.d32;
1053 + haint_saved.d32 = 0;
1054 + local_fiq_enable();
1057 for (i = 0; i < dwc_otg_hcd->core_if->core_params->host_channels; i++) {
1058 if (haint.b2.chint & (1 << i)) {
1059 retval |= dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd, i);
1060 @@ -683,7 +1055,10 @@ static uint32_t get_actual_xfer_length(d
1061 *short_read = (hctsiz.b.xfersize != 0);
1063 } else if (hc->qh->do_split) {
1064 - length = qtd->ssplit_out_xfer_count;
1065 + if(fiq_split_enable)
1066 + length = split_out_xfersize[hc->hc_num];
1068 + length = qtd->ssplit_out_xfer_count;
1070 length = hc->xfer_len;
1072 @@ -727,7 +1102,6 @@ static int update_urb_state_xfer_comp(dw
1073 DWC_OTG_HC_XFER_COMPLETE,
1077 /* non DWORD-aligned buffer case handling. */
1078 if (hc->align_buff && xfer_length && hc->ep_is_in) {
1079 dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
1080 @@ -930,6 +1304,9 @@ static void release_channel(dwc_otg_hcd_
1082 dwc_irqflags_t flags;
1083 dwc_spinlock_t *channel_lock = hcd->channel_lock;
1085 + int endp = qtd->urb ? qtd->urb->pipe_info.ep_num : 0;
1088 DWC_DEBUGPL(DBG_HCDV, " %s: channel %d, halt_status %d, xfer_len %d\n",
1089 __func__, hc->hc_num, halt_status, hc->xfer_len);
1090 @@ -1008,9 +1385,24 @@ cleanup:
1092 DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
1093 hcd->available_host_channels++;
1094 + fiq_print(FIQDBG_PORTHUB, "AHC = %d ", hcd->available_host_channels);
1095 DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
1098 + if(fiq_split_enable && hc->do_split)
1100 + if(!(hcd->hub_port[hc->hub_addr] & (1 << hc->port_addr)))
1102 + fiq_print(FIQDBG_ERR, "PRTNOTAL");
1106 + hcd->hub_port[hc->hub_addr] &= ~(1 << hc->port_addr);
1107 + hcd->hub_port_alloc[hc->hub_addr * 16 + hc->port_addr] = -1;
1109 + fiq_print(FIQDBG_PORTHUB, "H%dP%d:RR%d", hc->hub_addr, hc->port_addr, endp);
1112 /* Try to queue more transfers now that there's a free channel. */
1113 tr_type = dwc_otg_hcd_select_transactions(hcd);
1114 if (tr_type != DWC_OTG_TRANSACTION_NONE) {
1115 @@ -1633,8 +2025,10 @@ static int32_t handle_hc_nyet_intr(dwc_o
1116 hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
1117 int frnum = dwc_otg_hcd_get_frame_number(hcd);
1119 + // With the FIQ running we only ever see the failed NYET
1120 if (dwc_full_frame_num(frnum) !=
1121 - dwc_full_frame_num(hc->qh->sched_frame)) {
1122 + dwc_full_frame_num(hc->qh->sched_frame) ||
1123 + fiq_split_enable) {
1125 * No longer in the same full speed frame.
1126 * Treat this as a transaction error.
1127 @@ -2012,10 +2406,10 @@ static inline int halt_status_ok(dwc_otg
1128 static void handle_hc_chhltd_intr_dma(dwc_otg_hcd_t * hcd,
1130 dwc_otg_hc_regs_t * hc_regs,
1131 - dwc_otg_qtd_t * qtd)
1132 + dwc_otg_qtd_t * qtd,
1133 + hcint_data_t hcint,
1134 + hcintmsk_data_t hcintmsk)
1136 - hcint_data_t hcint;
1137 - hcintmsk_data_t hcintmsk;
1138 int out_nak_enh = 0;
1140 /* For core with OUT NAK enhancement, the flow for high-
1141 @@ -2047,8 +2441,11 @@ static void handle_hc_chhltd_intr_dma(dw
1144 /* Read the HCINTn register to determine the cause for the halt. */
1145 - hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
1146 - hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
1147 + if(!fiq_split_enable)
1149 + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
1150 + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
1153 if (hcint.b.xfercomp) {
1154 /** @todo This is here because of a possible hardware bug. Spec
1155 @@ -2161,13 +2558,15 @@ static void handle_hc_chhltd_intr_dma(dw
1156 static int32_t handle_hc_chhltd_intr(dwc_otg_hcd_t * hcd,
1158 dwc_otg_hc_regs_t * hc_regs,
1159 - dwc_otg_qtd_t * qtd)
1160 + dwc_otg_qtd_t * qtd,
1161 + hcint_data_t hcint,
1162 + hcintmsk_data_t hcintmsk)
1164 DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
1165 "Channel Halted--\n", hc->hc_num);
1167 if (hcd->core_if->dma_enable) {
1168 - handle_hc_chhltd_intr_dma(hcd, hc, hc_regs, qtd);
1169 + handle_hc_chhltd_intr_dma(hcd, hc, hc_regs, qtd, hcint, hcintmsk);
1172 if (!halt_status_ok(hcd, hc, hc_regs, qtd)) {
1173 @@ -2184,7 +2583,7 @@ static int32_t handle_hc_chhltd_intr(dwc
1174 int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd, uint32_t num)
1177 - hcint_data_t hcint;
1178 + hcint_data_t hcint, hcint_orig;
1179 hcintmsk_data_t hcintmsk;
1181 dwc_otg_hc_regs_t *hc_regs;
1182 @@ -2197,12 +2596,23 @@ int32_t dwc_otg_hcd_handle_hc_n_intr(dwc
1183 qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
1185 hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
1186 + hcint_orig = hcint;
1187 hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
1188 DWC_DEBUGPL(DBG_HCDV,
1189 " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
1190 hcint.d32, hcintmsk.d32, (hcint.d32 & hcintmsk.d32));
1191 hcint.d32 = hcint.d32 & hcintmsk.d32;
1193 + if(fiq_split_enable)
1195 + // replace with the saved interrupts from the fiq handler
1196 + local_fiq_disable();
1197 + hcint_orig.d32 = hcint_saved[num].d32;
1198 + hcint.d32 = hcint_orig.d32 & hcintmsk_saved[num].d32;
1199 + hcint_saved[num].d32 = 0;
1200 + local_fiq_enable();
1203 if (!dwc_otg_hcd->core_if->dma_enable) {
1204 if (hcint.b.chhltd && hcint.d32 != 0x2) {
1206 @@ -2220,7 +2630,7 @@ int32_t dwc_otg_hcd_handle_hc_n_intr(dwc
1209 if (hcint.b.chhltd) {
1210 - retval |= handle_hc_chhltd_intr(dwc_otg_hcd, hc, hc_regs, qtd);
1211 + retval |= handle_hc_chhltd_intr(dwc_otg_hcd, hc, hc_regs, qtd, hcint_orig, hcintmsk_saved[num]);
1213 if (hcint.b.ahberr) {
1214 retval |= handle_hc_ahberr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
1215 --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c
1216 +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c
1217 @@ -392,7 +392,11 @@ static struct dwc_otg_hcd_function_ops h
1218 static struct fiq_handler fh = {
1221 -static uint8_t fiqStack[1024];
1222 +struct fiq_stack_s {
1224 + uint8_t stack[2048];
1228 extern mphi_regs_t c_mphi_regs;
1230 @@ -434,9 +438,11 @@ int hcd_init(dwc_bus_dev_t *_dev)
1231 memset(®s,0,sizeof(regs));
1232 regs.ARM_r8 = (long)dwc_otg_hcd_handle_fiq;
1233 regs.ARM_r9 = (long)0;
1234 - regs.ARM_sp = (long)fiqStack + sizeof(fiqStack) - 4;
1235 + regs.ARM_sp = (long)fiq_stack.stack + sizeof(fiq_stack.stack) - 4;
1236 set_fiq_regs(®s);
1238 + fiq_stack.magic1 = 0xdeadbeef;
1239 + fiq_stack.magic2 = 0xaa995566;
1243 * Allocate memory for the base HCD plus the DWC OTG HCD.
1244 @@ -459,6 +465,8 @@ int hcd_init(dwc_bus_dev_t *_dev)
1248 + volatile extern void *dwc_regs_base;
1250 //Set the mphi periph to the required registers
1251 c_mphi_regs.base = otg_dev->os_dep.mphi_base;
1252 c_mphi_regs.ctrl = otg_dev->os_dep.mphi_base + 0x4c;
1253 @@ -466,6 +474,8 @@ int hcd_init(dwc_bus_dev_t *_dev)
1254 c_mphi_regs.outddb = otg_dev->os_dep.mphi_base + 0x2c;
1255 c_mphi_regs.intstat = otg_dev->os_dep.mphi_base + 0x50;
1257 + dwc_regs_base = otg_dev->os_dep.base;
1259 //Enable mphi peripheral
1260 writel((1<<31),c_mphi_regs.ctrl);
1262 @@ -839,6 +849,8 @@ static int dwc_otg_urb_dequeue(struct us
1263 usb_hcd_unlink_urb_from_ep(hcd, urb);
1265 DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
1268 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
1269 usb_hcd_giveback_urb(hcd, urb);
1271 --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c
1272 +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c
1275 #include "dwc_otg_hcd.h"
1276 #include "dwc_otg_regs.h"
1277 +#include "dwc_otg_mphi_fix.h"
1279 extern bool microframe_schedule;
1281 @@ -191,6 +192,7 @@ void qh_init(dwc_otg_hcd_t * hcd, dwc_ot
1282 dwc_otg_hcd_get_ep_num(&urb->pipe_info), hub_addr,
1285 + qh->skip_count = 0;
1288 if (qh->ep_type == UE_INTERRUPT || qh->ep_type == UE_ISOCHRONOUS) {
1289 @@ -737,6 +739,9 @@ void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t
1290 hcd->non_periodic_qh_ptr->next;
1292 DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
1294 + // If we've removed the last non-periodic entry then there are none left!
1295 + g_np_count = g_np_sent;
1297 deschedule_periodic(hcd, qh);
1298 hcd->periodic_qh_count--;
1299 @@ -766,21 +771,21 @@ void dwc_otg_hcd_qh_deactivate(dwc_otg_h
1301 if (dwc_qh_is_non_per(qh)) {
1303 - dwc_otg_qh_t *qh_tmp;
1304 - dwc_list_link_t *qh_list;
1305 - DWC_LIST_FOREACH(qh_list, &hcd->non_periodic_sched_inactive)
1307 - qh_tmp = DWC_LIST_ENTRY(qh_list, struct dwc_otg_qh, qh_list_entry);
1309 + dwc_otg_qh_t *qh_tmp;
1310 + dwc_list_link_t *qh_list;
1311 + DWC_LIST_FOREACH(qh_list, &hcd->non_periodic_sched_inactive)
1314 - * FIQ is being disabled because this one nevers gets a np_count increment
1315 - * This is still not absolutely correct, but it should fix itself with
1316 - * just an unnecessary extra interrupt
1318 - g_np_sent = g_np_count;
1319 + qh_tmp = DWC_LIST_ENTRY(qh_list, struct dwc_otg_qh, qh_list_entry);
1323 + * FIQ is being disabled because this one nevers gets a np_count increment
1324 + * This is still not absolutely correct, but it should fix itself with
1325 + * just an unnecessary extra interrupt
1327 + g_np_sent = g_np_count;
1333 dwc_otg_hcd_qh_remove(hcd, qh);
1334 --- a/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h
1335 +++ b/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h
1337 #ifndef __DWC_OTG_MPHI_FIX_H__
1338 #define __DWC_OTG_MPHI_FIX_H__
1340 -#define FIQ_WRITE_IO_ADDRESS(_addr_,_data_) *(volatile uint32_t *) IO_ADDRESS(_addr_) = _data_
1341 -#define FIQ_READ_IO_ADDRESS(_addr_) *(volatile uint32_t *) IO_ADDRESS(_addr_)
1342 -#define FIQ_MODIFY_IO_ADDRESS(_addr_,_clear_,_set_) FIQ_WRITE_IO_ADDRESS(_addr_ , (FIQ_READ_IO_ADDRESS(_addr_)&~_clear_)|_set_)
1343 -#define FIQ_WRITE(_addr_,_data_) *(volatile uint32_t *) _addr_ = _data_
1344 +#define FIQ_WRITE(_addr_,_data_) (*(volatile uint32_t *) (_addr_) = (_data_))
1345 +#define FIQ_READ(_addr_) (*(volatile uint32_t *) (_addr_))
1348 volatile void* base;
1349 @@ -12,13 +9,13 @@ typedef struct {
1350 volatile void* outdda;
1351 volatile void* outddb;
1352 volatile void* intstat;
1356 void dwc_debug_print_core_int_reg(gintsts_data_t gintsts, const char* function_name);
1357 void dwc_debug_core_int_mask(gintsts_data_t gintmsk, const char* function_name);
1358 void dwc_debug_otg_int(gotgint_data_t gotgint, const char* function_name);
1361 +extern gintsts_data_t gintsts_saved;
1364 #define DWC_DBG_PRINT_CORE_INT(_arg_) dwc_debug_print_core_int_reg(_arg_,__func__)
1365 @@ -30,7 +27,22 @@ void dwc_debug_otg_int(gotgint_data_t go
1366 #define DWC_DBG_PRINT_CORE_INT_MASK(_arg_)
1367 #define DWC_DBG_PRINT_OTG_INT(_arg_)
1372 + FIQDBG_SCHED = (1 << 0),
1373 + FIQDBG_INT = (1 << 1),
1374 + FIQDBG_ERR = (1 << 2),
1375 + FIQDBG_PORTHUB = (1 << 3),
1378 +void _fiq_print(FIQDBG_T dbg_lvl, char *fmt, ...);
1380 +#define fiq_print _fiq_print
1382 +#define fiq_print(x, y, ...)
1385 +extern bool fiq_fix_enable, nak_holdoff_enable, fiq_split_enable;
1388 --- a/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c
1389 +++ b/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c
1390 @@ -4276,7 +4276,7 @@ do { \
1391 && (pcd->ep0state == EP0_OUT_DATA_PHASE))
1392 status.d32 = core_if->dev_if->out_desc_addr->status.d32;
1393 if (pcd->ep0state == EP0_OUT_STATUS_PHASE)
1394 - status.d32 = status.d32 = core_if->dev_if->
1395 + status.d32 = core_if->dev_if->
1396 out_desc_addr->status.d32;