simple changes to the stack
[ppcskel.git] / usb / host / ohci.c
1 /*
2        ppcskel - a Free Software replacement for the Nintendo/BroadOn bootloader.
3        ohci hardware support
4
5 Copyright (C) 2009     Bernhard Urban <lewurm@gmx.net>
6 Copyright (C) 2009     Sebastian Falbesoner <sebastian.falbesoner@gmail.com>
7
8 # This code is licensed to you under the terms of the GNU GPL, version 2;
9 # see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
10 */
11
12 #include "../../bootmii_ppc.h"
13 #include "../../hollywood.h"
14 #include "../../irq.h"
15 #include "../../string.h"
16 #include "../../malloc.h"
17 #include "ohci.h"
18 #include "host.h"
19 #include "../usbspec/usb11spec.h"
20
21 /* activate control_quirk (from MIKE) */
22 //#define _USE_C_Q
23
24 /* macro for accessing u32 variables that need to be in little endian byte order;
25  *
26  * whenever you read or write from an u32 field that the ohci host controller
27  * will read or write from too, use this macro for access!
28  */
29 #define LE(dword) (u32)( (((dword) & 0xFF000000) >> 24) | \
30                            (((dword) & 0x00FF0000) >> 8)  | \
31                            (((dword) & 0x0000FF00) << 8)  | \
32                            (((dword) & 0x000000FF) << 24) )
33
34 static struct general_td *allocate_general_td();
35 static void dbg_op_state();
36 static void configure_ports(u8 from_init);
37 static void setup_port(u32 reg, u8 from_init);
38
39 static struct ohci_hcca hcca_oh0;
40
41
42 #ifdef _USE_C_Q
43 static struct endpoint_descriptor *allocate_endpoint()
44 {
45         struct endpoint_descriptor *ep;
46         ep = (struct endpoint_descriptor *)memalign(16, sizeof(struct endpoint_descriptor));
47         memset(ep, 0, sizeof(struct endpoint_descriptor));
48         ep->flags = LE(OHCI_ENDPOINT_GENERAL_FORMAT);
49         ep->headp = ep->tailp = ep->nexted = LE(0);
50         return ep;
51 }
52 #endif
53
54 static struct general_td *allocate_general_td()
55 {
56         struct general_td *td;
57         td = (struct general_td *)memalign(16, sizeof(struct general_td));
58         memset(td, 0, sizeof(struct general_td));
59         td->flags = LE(0);
60         td->nexttd = LE(0);
61         td->cbp = td->be = LE(0);
62         return td;
63 }
64
65 #ifdef _USE_C_Q
66 static void control_quirk()
67 {
68         static struct endpoint_descriptor *ed = 0; /* empty ED */
69         static struct general_td *td = 0; /* dummy TD */
70         u32 head;
71         u32 current;
72         u32 status;
73
74         /*
75          * One time only.
76          * Allocate and keep a special empty ED with just a dummy TD.
77          */
78         if (!ed) {
79                 ed = allocate_endpoint();
80                 if (!ed)
81                         return;
82
83                 td = allocate_general_td(0);
84                 if (!td) {
85                         free(ed);
86                         ed = NULL;
87                         return;
88                 }
89
90                 ed->tailp = ed->headp = LE(virt_to_phys((void*) ((u32)td & OHCI_ENDPOINT_HEAD_MASK)));
91                 ed->flags |= LE(OHCI_ENDPOINT_DIRECTION_OUT);
92         }
93
94         /*
95          * The OHCI USB host controllers on the Nintendo Wii
96          * video game console stop working when new TDs are
97          * added to a scheduled control ED after a transfer has
98          * has taken place on it.
99          *
100          * Before scheduling any new control TD, we make the
101          * controller happy by always loading a special control ED
102          * with a single dummy TD and letting the controller attempt
103          * the transfer.
104          * The controller won't do anything with it, as the special
105          * ED has no TDs, but it will keep the controller from failing
106          * on the next transfer.
107          */
108         head = read32(OHCI0_HC_CTRL_HEAD_ED);
109         if (head) {
110                 printf("head: 0x%08X\n", head);
111                 /*
112                  * Load the special empty ED and tell the controller to
113                  * process the control list.
114                  */
115                 sync_after_write(ed, 16);
116                 sync_after_write(td, 16);
117                 write32(OHCI0_HC_CTRL_HEAD_ED, virt_to_phys(ed));
118
119                 status = read32(OHCI0_HC_CONTROL);
120                 set32(OHCI0_HC_CONTROL, OHCI_CTRL_CLE);
121                 write32(OHCI0_HC_COMMAND_STATUS, OHCI_CLF);
122
123                 /* spin until the controller is done with the control list */
124                 current = read32(OHCI0_HC_CTRL_CURRENT_ED);
125                 while(!current) {
126                         udelay(10);
127                         current = read32(OHCI0_HC_CTRL_CURRENT_ED);
128                 }
129
130                 printf("current: 0x%08X\n", current);
131                         
132                 /* restore the old control head and control settings */
133                 write32(OHCI0_HC_CONTROL, status);
134                 write32(OHCI0_HC_CTRL_HEAD_ED, head);
135         } else {
136                 printf("nohead!\n");
137         }
138 }
139 #endif
140
141
142 static void dbg_op_state() 
143 {
144         switch (read32(OHCI0_HC_CONTROL) & OHCI_CTRL_HCFS) {
145                 case OHCI_USB_SUSPEND:
146                         printf("ohci-- OHCI_USB_SUSPEND\n");
147                         break;
148                 case OHCI_USB_RESET:
149                         printf("ohci-- OHCI_USB_RESET\n");
150                         break;
151                 case OHCI_USB_OPER:
152                         printf("ohci-- OHCI_USB_OPER\n");
153                         break;
154                 case OHCI_USB_RESUME:
155                         printf("ohci-- OHCI_USB_RESUME\n");
156                         break;
157         }
158 }
159
160 static void dbg_td_flag(u32 flag)
161 {
162         printf("**************** dbg_td_flag: 0x%08X ***************\n", flag);
163         printf("CC: %X\tshould be 0, see page 32 (ohci spec)\n", (flag>>28)&0xf);
164         printf("EC: %X\tsee page 20 (ohci spec)\n", (flag>>26)&3);
165         printf(" T: %X\n", (flag>>24)&3);
166         printf("DI: %X\n", (flag>>21)&7);
167         printf("DP: %X\n", (flag>>19)&3);
168         printf(" R: %X\n", (flag>>18)&1);
169         printf("********************************************************\n");
170 }
171
172 static void general_td_fill(struct general_td *dest, const usb_transfer_descriptor *src)
173 {
174         if(src->actlen) {
175                 dest->cbp = LE(virt_to_phys(src->buffer));
176                 dest->be = LE(LE(dest->cbp) + src->actlen - 1);
177                 /* save virtual address here */
178                 dest->bufaddr = (u32) src->buffer;
179         }
180         else {
181                 dest->cbp = dest->be = LE(0);
182                 dest->bufaddr = 0;
183         }
184
185         dest->buflen = src->actlen;
186
187         dest->flags &= LE(~OHCI_TD_DIRECTION_PID_MASK);
188         switch(src->pid) {
189                 case USB_PID_SETUP:
190 #ifdef _DU_OHCI_Q
191                         printf("pid_setup\n");
192 #endif
193                         dest->flags |= LE(OHCI_TD_DIRECTION_PID_SETUP);
194                         dest->flags |= LE(OHCI_TD_TOGGLE_0);
195                         dest->flags |= LE(OHCI_TD_BUFFER_ROUNDING);
196                         break;
197                 case USB_PID_OUT:
198 #ifdef _DU_OHCI_Q
199                         printf("pid_out\n");
200 #endif
201                         dest->flags |= LE(OHCI_TD_DIRECTION_PID_OUT);
202                         dest->flags |= LE(OHCI_TD_BUFFER_ROUNDING);
203
204                         /*
205                          * TODO: just temporary solution! (consider it with len?)
206                          * there can be also regular PID_OUT pakets
207                          */
208                         dest->flags |= LE(OHCI_TD_TOGGLE_1);
209                         break;
210                 case USB_PID_IN:
211 #ifdef _DU_OHCI_Q
212                         printf("pid_in\n");
213 #endif
214                         dest->flags |= LE(OHCI_TD_DIRECTION_PID_IN);
215                         if(src->maxp > src->actlen) {
216                                 dest->flags |= LE(OHCI_TD_BUFFER_ROUNDING);
217 #ifdef _DU_OHCI_Q
218                                 printf("round buffer!\n");
219 #endif
220                         }
221                         /*
222                          * let the endpoint do the togglestuff!
223                          * TODO: just temporary solution!
224                          * there can be also inregular PID_IN pakets (@Status Stage)
225                          */
226                         dest->flags |= LE(OHCI_TD_TOGGLE_CARRY);
227                         break;
228         }
229         dest->flags |= LE(OHCI_TD_SET_DELAY_INTERRUPT(7));
230 }
231
232 #ifdef _DU_OHCI_F
233 static void dump_address(void *addr, u32 size, const char* str)
234 {
235         printf("%s hexdump (%d) @ 0x%08X:\n", str, size, addr);
236         hexdump(addr, size);
237 }
238 #endif
239
240 static struct endpoint_descriptor _edhead;
241 struct endpoint_descriptor *edhead = 0;
242 void hcdi_fire()
243 {
244 #ifdef _DU_OHCI_F
245         printf("<^>  <^>  <^> hcdi_fire(start)\n");
246 #endif
247
248         if(edhead == 0)
249                 return;
250
251 #ifdef _USE_C_Q
252         required? YES! :O ... erm... or no? :/ ... in fact I have no idea
253         control_quirk(); 
254 #endif
255
256         write32(OHCI0_HC_CTRL_HEAD_ED, virt_to_phys(edhead));
257
258         /* sync it all */
259         sync_after_write(edhead, sizeof(struct endpoint_descriptor));
260 #ifdef _DU_OHCI_F
261         dump_address(edhead, sizeof(struct endpoint_descriptor), "edhead(before)");
262 #endif
263
264         struct general_td *x = phys_to_virt(LE(edhead->headp) & OHCI_ENDPOINT_HEAD_MASK);
265         while(virt_to_phys(x)) {
266                 sync_after_write(x, sizeof(struct general_td));
267 #ifdef _DU_OHCI_F
268                 dump_address(x, sizeof(struct general_td), "x(before)");
269 #endif
270
271                 if(x->buflen > 0) {
272                         sync_after_write((void*) phys_to_virt(LE(x->cbp)), x->buflen);
273 #ifdef _DU_OHCI_F
274                         dump_address((void*) phys_to_virt(LE(x->cbp)), x->buflen, "x->cbp(before)");
275 #endif
276                 }
277                 x = phys_to_virt(LE(x->nexttd));
278         }
279
280         /* trigger control list */
281         set32(OHCI0_HC_CONTROL, OHCI_CTRL_CLE);
282         write32(OHCI0_HC_COMMAND_STATUS, OHCI_CLF);
283
284         struct general_td *n=0, *prev = 0, *next = 0;
285         /* poll until edhead->headp is null */
286         do {
287                 sync_before_read(edhead, sizeof(struct endpoint_descriptor));
288 #ifdef _DU_OHCI_F
289                 printf("edhead->headp: 0x%08X\n", LE(edhead->headp));
290                 udelay(10000);
291 #endif
292
293                 /* if halted, debug output plz. will break the transfer */
294                 if((LE(edhead->headp) & OHCI_ENDPOINT_HALTED)) {
295                         n = phys_to_virt(LE(edhead->headp)&~0xf);
296                         prev = phys_to_virt((u32)prev);
297 #ifdef _DU_OHCI_F
298                         printf("halted!\n");
299 #endif
300
301                         sync_before_read((void*) n, sizeof(struct general_td));
302 #ifdef _DU_OHCI_F
303                         printf("n: 0x%08X\n", n);
304                         dump_address(n, sizeof(struct general_td), "n(after)");
305 #endif
306                         if(n->buflen > 0) {
307                                 sync_before_read((void*) n->bufaddr, n->buflen);
308 #ifdef _DU_OHCI_F
309                                 dump_address((void*) n->bufaddr, n->buflen, "n->bufaddr(after)");
310 #endif
311                         }
312                         dbg_td_flag(LE(n->flags));
313
314                         sync_before_read((void*) prev, sizeof(struct general_td));
315 #ifdef _DU_OHCI_F
316                         printf("prev: 0x%08X\n", prev);
317                         dump_address(prev, sizeof(struct general_td), "prev(after)");
318 #endif
319                         if(prev->buflen >0) {
320                                 sync_before_read((void*) prev->bufaddr, prev->buflen);
321 #ifdef _DU_OHCI_F
322                                 dump_address((void*) prev->bufaddr, prev->buflen, "prev->bufaddr(after)");
323 #endif
324                         }
325 #ifdef _DU_OHCI_F
326                         dbg_td_flag(LE(prev->flags));
327                         printf("halted end!\n");
328 #endif
329                         return;
330                 }
331                 prev = (struct general_td*) (LE(edhead->headp)&~0xf);
332         } while(LE(edhead->headp)&~0xf);
333
334         n = phys_to_virt(read32(OHCI0_HC_DONE_HEAD) & ~1);
335 #ifdef _DU_OHCI_F
336         printf("hc_done_head: 0x%08X\n", read32(OHCI0_HC_DONE_HEAD));
337 #endif
338
339         prev = 0; next = 0;
340         /* reverse done queue */
341         while(virt_to_phys(n) && edhead->tdcount) {
342                 sync_before_read((void*) n, sizeof(struct general_td));
343 #ifdef _DU_OHCI_F
344                 printf("n: 0x%08X\n", n);
345                 printf("next: 0x%08X\n", next);
346                 printf("prev: 0x%08X\n", prev);
347 #endif
348
349                 next = n;
350                 n = (struct general_td*) phys_to_virt(LE(n->nexttd));
351                 next->nexttd = (u32) prev;
352                 prev = next;
353
354                 edhead->tdcount--;
355         }
356
357         n = next;
358         prev = 0;
359         while(virt_to_phys(n)) {
360 #ifdef _DU_OHCI_F
361                 dump_address(n, sizeof(struct general_td), "n(after)");
362 #endif
363                 if(n->buflen > 0) {
364                         sync_before_read((void*) n->bufaddr, n->buflen);
365 #ifdef _DU_OHCI_F
366                         dump_address((void*) n->bufaddr, n->buflen, "n->bufaddr(after)");
367 #endif
368                 }
369 #ifdef _DU_OHCI_F
370                 dbg_td_flag(LE(n->flags));
371 #endif
372                 prev = n;
373                 n = (struct general_td*) n->nexttd;
374                 free(prev);
375         }
376
377         hcca_oh0.done_head = 0;
378         sync_after_write(&hcca_oh0, sizeof(hcca_oh0));
379
380         write32(OHCI0_HC_CONTROL, read32(OHCI0_HC_CONTROL)&~OHCI_CTRL_CLE);
381
382         edhead = 0;
383
384 #ifdef _DU_OHCI_F
385         printf("<^>  <^>  <^> hcdi_fire(end)\n");
386 #endif
387 }
388
389 /**
390  * Enqueue a transfer descriptor.
391  */
392 u8 hcdi_enqueue(const usb_transfer_descriptor *td) {
393 #ifdef _DU_OHCI_Q
394         printf("*()*()*()*()*()*()*() hcdi_enqueue(start)\n");
395 #endif
396         if(!edhead) {
397                 edhead = &_edhead;
398                 memset(edhead, 0, sizeof(struct endpoint_descriptor));
399                 edhead->flags = LE(OHCI_ENDPOINT_GENERAL_FORMAT);
400                 edhead->headp = edhead->tailp = edhead->nexted = LE(0);
401                 edhead->flags |= LE(OHCI_ENDPOINT_LOW_SPEED |
402                                 OHCI_ENDPOINT_SET_DEVICE_ADDRESS(td->devaddress) |
403                                 OHCI_ENDPOINT_SET_ENDPOINT_NUMBER(td->endpoint) |
404                                 OHCI_ENDPOINT_SET_MAX_PACKET_SIZE(td->maxp));
405                 edhead->tdcount = 0;
406         }
407
408         struct general_td *tdhw = allocate_general_td();
409         general_td_fill(tdhw, td);
410         edhead->tdcount ++;
411
412         if(!edhead->headp) {
413                 /* first transfer */
414                 edhead->headp = LE(virt_to_phys((void*) ((u32)tdhw & OHCI_ENDPOINT_HEAD_MASK)));
415         }
416         else {
417                 /* headp in endpoint already exists
418                  * => go to list end
419                  */
420                 struct general_td *n = (struct general_td*) phys_to_virt(LE(edhead->headp) & OHCI_ENDPOINT_HEAD_MASK);
421                 while(LE(n->nexttd)) {
422                         n = phys_to_virt(LE(n->nexttd));
423                 }
424                 n->nexttd = LE(virt_to_phys((void*) ((u32)tdhw & OHCI_ENDPOINT_HEAD_MASK)));
425 #ifdef _DU_OHCI_Q
426                 printf("n: 0x%08X\n", n);
427                 printf("n->nexttd: 0x%08X\n", phys_to_virt(LE(n->nexttd)));
428 #endif
429         }
430
431 #ifdef _DU_OHCI_Q
432         printf("*()*()*()*()*()*()*() hcdi_enqueue(end)\n");
433 #endif
434         return 0;
435 }
436
437
438 /**
439  * Remove an transfer descriptor from transfer queue.
440  */
441 u8 hcdi_dequeue(usb_transfer_descriptor *td) {
442         return 0;
443 }
444
445 void hcdi_init() 
446 {
447         printf("ohci-- init\n");
448         dbg_op_state();
449
450         /* disable hc interrupts */
451         set32(OHCI0_HC_INT_DISABLE, OHCI_INTR_MIE);
452
453         /* save fmInterval and calculate FSMPS */
454 #define FSMP(fi) (0x7fff & ((6 * ((fi) - 210)) / 7))
455 #define FI 0x2edf /* 12000 bits per frame (-1) */
456         u32 fmint = read32(OHCI0_HC_FM_INTERVAL) & 0x3fff;
457         if(fmint != FI)
458                 printf("ohci-- fminterval delta: %d\n", fmint - FI);
459         fmint |= FSMP (fmint) << 16;
460
461         /* enable interrupts of both usb host controllers */
462         set32(EHCI_CTL, EHCI_CTL_OH0INTE | EHCI_CTL_OH1INTE | 0xe0000);
463
464         /* reset HC */
465         write32(OHCI0_HC_COMMAND_STATUS, OHCI_HCR);
466
467         /* wait max. 30us */
468         u32 ts = 30;
469         while ((read32(OHCI0_HC_COMMAND_STATUS) & OHCI_HCR) != 0) {
470                  if(--ts == 0) {
471                         printf("ohci-- FAILED");
472                         return;
473                  }
474                  udelay(1);
475         }
476
477         /* disable interrupts; 2ms timelimit here! 
478            now we're in the SUSPEND state ... must go OPERATIONAL
479            within 2msec else HC enters RESUME */
480
481         u32 cookie = irq_kill();
482
483         /* Tell the controller where the control and bulk lists are
484          * The lists are empty now. */
485         write32(OHCI0_HC_CTRL_HEAD_ED, 0);
486         write32(OHCI0_HC_BULK_HEAD_ED, 0);
487
488         /* set hcca adress */
489         sync_after_write(&hcca_oh0, 256);
490         write32(OHCI0_HC_HCCA, virt_to_phys(&hcca_oh0));
491
492         /* set periodicstart */
493 #define FIT (1<<31)
494         u32 fmInterval = read32(OHCI0_HC_FM_INTERVAL) &0x3fff;
495         u32 fit = read32(OHCI0_HC_FM_INTERVAL) & FIT;
496
497         write32(OHCI0_HC_FM_INTERVAL, fmint | (fit ^ FIT));
498         write32(OHCI0_HC_PERIODIC_START, ((9*fmInterval)/10)&0x3fff);
499
500         /* testing bla */
501         if ((read32(OHCI0_HC_FM_INTERVAL) & 0x3fff0000) == 0 || !read32(OHCI0_HC_PERIODIC_START)) {
502                 printf("ohci-- w00t, fail!! see ohci-hcd.c:669\n");
503         }
504         
505         /* start HC operations */
506         write32(OHCI0_HC_CONTROL, OHCI_CONTROL_INIT | OHCI_USB_OPER);
507
508         /* wake on ConnectStatusChange, matching external hubs */
509         write32(OHCI0_HC_RH_STATUS, /*RH_HS_DRWE |*/ RH_HS_LPSC);
510
511         /* Choose the interrupts we care about now, others later on demand */
512         write32(OHCI0_HC_INT_STATUS, ~0);
513         write32(OHCI0_HC_INT_ENABLE, OHCI_INTR_INIT);
514
515         //wtf?
516         wait_ms ((read32(OHCI0_HC_RH_DESCRIPTOR_A) >> 23) & 0x1fe);
517
518         configure_ports((u8)1);
519         irq_restore(cookie);
520
521         dbg_op_state();
522 }
523
524 static void configure_ports(u8 from_init)
525 {
526 #ifdef _DU_OHCI_RH
527         printf("OHCI0_HC_RH_DESCRIPTOR_A:\t0x%08X\n", read32(OHCI0_HC_RH_DESCRIPTOR_A));
528         printf("OHCI0_HC_RH_DESCRIPTOR_B:\t0x%08X\n", read32(OHCI0_HC_RH_DESCRIPTOR_B));
529         printf("OHCI0_HC_RH_STATUS:\t\t0x%08X\n", read32(OHCI0_HC_RH_STATUS));
530         printf("OHCI0_HC_RH_PORT_STATUS_1:\t0x%08X\n", read32(OHCI0_HC_RH_PORT_STATUS_1));
531         printf("OHCI0_HC_RH_PORT_STATUS_2:\t0x%08X\n", read32(OHCI0_HC_RH_PORT_STATUS_2));
532 #endif
533
534         setup_port(OHCI0_HC_RH_PORT_STATUS_1, from_init);
535         setup_port(OHCI0_HC_RH_PORT_STATUS_2, from_init);
536 #ifdef _DU_OHCI_RH
537         printf("configure_ports done\n");
538 #endif
539 }
540
541 static void setup_port(u32 reg, u8 from_init)
542 {
543         u32 port = read32(reg);
544         if((port & RH_PS_CCS) && ((port & RH_PS_CSC) || from_init)) {
545                 write32(reg, RH_PS_CSC);
546
547                 wait_ms(120);
548
549                 /* clear CSC flag, set PES and start port reset (PRS) */
550                 write32(reg, RH_PS_PES);
551                 while(!(read32(reg) & RH_PS_PES)) {
552 #ifdef _DU_OHCI_RH
553                         printf("fu\n");
554 #endif
555                         return;
556                 }
557
558                 write32(reg, RH_PS_PRS);
559
560                 /* spin until port reset is complete */
561                 while(!(read32(reg) & RH_PS_PRSC)); // hint: it may stuck here
562 #ifdef _DU_OHCI_RH
563                 printf("loop done\n");
564 #endif
565
566                 (void) usb_add_device();
567         }
568 }
569
570 void hcdi_irq()
571 {
572         /* read interrupt status */
573         u32 flags = read32(OHCI0_HC_INT_STATUS);
574
575         /* when all bits are set to 1 some problem occured */
576         if (flags == 0xffffffff) {
577                 printf("ohci-- Houston, we have a serious problem! :(\n");
578                 return;
579         }
580
581         /* only care about interrupts that are enabled */
582         flags &= read32(OHCI0_HC_INT_ENABLE);
583
584         /* nothing to do? */
585         if (flags == 0) {
586                 printf("OHCI Interrupt occured: but not for you! WTF?!\n");
587                 return;
588         }
589
590         printf("OHCI Interrupt occured: ");
591         /* UnrecoverableError */
592         if (flags & OHCI_INTR_UE) {
593                 printf("UnrecoverableError\n");
594                 /* TODO: well, I don't know... nothing,
595                  *       because it won't happen anyway? ;-) */
596         }
597
598         /* RootHubStatusChange */
599         if (flags & OHCI_INTR_RHSC) {
600                 printf("RootHubStatusChange\n");
601                 /* TODO: set some next_statechange variable... */
602                 configure_ports(0);
603                 write32(OHCI0_HC_INT_STATUS, OHCI_INTR_RD | OHCI_INTR_RHSC);
604         }
605         /* ResumeDetected */
606         else if (flags & OHCI_INTR_RD) {
607                 printf("ResumeDetected\n");
608                 write32(OHCI0_HC_INT_STATUS, OHCI_INTR_RD);
609                 /* TODO: figure out what the linux kernel does here... */
610         }
611
612         /* WritebackDoneHead */
613         if (flags & OHCI_INTR_WDH) {
614                 printf("WritebackDoneHead\n");
615                 /* basically the linux irq handler reverse TDs to their urbs
616                  * and set done_head to null.
617                  * since we are polling atm, just should do the latter task.
618                  * however, this won't work for now (i don't know why...)
619                  * TODO!
620                  */
621 #if 0
622                 sync_before_read(&hcca_oh0, 256);
623                 hcca_oh0.done_head = 0;
624                 sync_after_write(&hcca_oh0, 256);
625 #endif
626         }
627
628         /* TODO: handle any pending URB/ED unlinks... */
629
630 #define HC_IS_RUNNING() 1 /* dirty, i know... just a temporary solution */
631         if (HC_IS_RUNNING()) {
632                 write32(OHCI0_HC_INT_STATUS, flags);
633                 write32(OHCI0_HC_INT_ENABLE, OHCI_INTR_MIE);
634         }
635 }
636
637 void show_frame_no()
638 {
639         sync_before_read(&hcca_oh0, 256);
640         printf("***** frame_no: %d *****\n", LE(hcca_oh0.frame_no));
641 }