usbehciomap.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * OMAP3-specific code for
  3. * USB Enhanced Host Controller Interface (EHCI) driver
  4. * High speed USB 2.0.
  5. */
  6. #include "u.h"
  7. #include "../port/lib.h"
  8. #include "mem.h"
  9. #include "dat.h"
  10. #include "fns.h"
  11. #include "io.h"
  12. #include "../port/error.h"
  13. #include "../port/usb.h"
  14. #include "usbehci.h"
  15. static Ctlr* ctlrs[Nhcis];
  16. static void
  17. ehcireset(Ctlr *ctlr)
  18. {
  19. Eopio *opio;
  20. int i;
  21. ilock(ctlr);
  22. dprint("ehci %#p reset\n", ctlr->capio);
  23. opio = ctlr->opio;
  24. /*
  25. * Turn off legacy mode. Some controllers won't
  26. * interrupt us as expected otherwise.
  27. */
  28. ehcirun(ctlr, 0);
  29. /* clear high 32 bits of address signals if it's 64 bits capable.
  30. * This is probably not needed but it does not hurt and others do it.
  31. */
  32. if((ctlr->capio->capparms & C64) != 0){
  33. dprint("ehci: 64 bits\n");
  34. opio->seg = 0;
  35. }
  36. if(ehcidebugcapio != ctlr->capio){
  37. opio->cmd |= Chcreset; /* controller reset */
  38. coherence();
  39. for(i = 0; i < 100; i++){
  40. if((opio->cmd & Chcreset) == 0)
  41. break;
  42. delay(1);
  43. }
  44. if(i == 100)
  45. print("ehci %#p controller reset timed out\n", ctlr->capio);
  46. }
  47. /* requesting more interrupts per µframe may miss interrupts */
  48. opio->cmd |= Citc8; /* 1 intr. per ms */
  49. coherence();
  50. switch(opio->cmd & Cflsmask){
  51. case Cfls1024:
  52. ctlr->nframes = 1024;
  53. break;
  54. case Cfls512:
  55. ctlr->nframes = 512;
  56. break;
  57. case Cfls256:
  58. ctlr->nframes = 256;
  59. break;
  60. default:
  61. panic("ehci: unknown fls %ld", opio->cmd & Cflsmask);
  62. }
  63. coherence();
  64. dprint("ehci: %d frames\n", ctlr->nframes);
  65. iunlock(ctlr);
  66. }
  67. static void
  68. setdebug(Hci*, int d)
  69. {
  70. ehcidebug = d;
  71. }
  72. static void
  73. shutdown(Hci *hp)
  74. {
  75. int i;
  76. Ctlr *ctlr;
  77. Eopio *opio;
  78. ctlr = hp->aux;
  79. ilock(ctlr);
  80. opio = ctlr->opio;
  81. opio->cmd |= Chcreset; /* controller reset */
  82. coherence();
  83. for(i = 0; i < 100; i++){
  84. if((opio->cmd & Chcreset) == 0)
  85. break;
  86. delay(1);
  87. }
  88. if(i >= 100)
  89. print("ehci %#p controller reset timed out\n", ctlr->capio);
  90. delay(100);
  91. ehcirun(ctlr, 0);
  92. opio->frbase = 0;
  93. coherence();
  94. iunlock(ctlr);
  95. }
  96. /*
  97. * omap3-specific ehci code
  98. */
  99. enum {
  100. /* opio->insn[5] bits */
  101. Control = 1<<31, /* set to start access, cleared when done */
  102. Write = 2<<22,
  103. Read = 3<<22,
  104. Portsh = 24,
  105. Regaddrsh = 16, /* 0x2f means use extended reg addr */
  106. Eregaddrsh = 8,
  107. /* phy reg addresses */
  108. Funcctlreg = 4,
  109. Ifcctlreg = 7,
  110. Phystppullupoff = 0x90, /* on is 0x10 */
  111. Phyrstport2 = 147, /* gpio # */
  112. };
  113. static void
  114. wrulpi(Eopio *opio, int port, int reg, uchar data)
  115. {
  116. opio->insn[5] = Control | port << Portsh | Write | reg << Regaddrsh |
  117. data;
  118. coherence();
  119. /*
  120. * this seems contrary to the skimpy documentation in the manual
  121. * but inverting the test hangs forever.
  122. */
  123. while (!(opio->insn[5] & Control))
  124. ;
  125. }
  126. static int
  127. reset(Hci *hp)
  128. {
  129. Ctlr *ctlr;
  130. Ecapio *capio;
  131. Eopio *opio;
  132. Uhh *uhh;
  133. static int beenhere;
  134. if (beenhere)
  135. return -1;
  136. beenhere = 1;
  137. if(getconf("*nousbehci") != nil || probeaddr(PHYSEHCI) < 0)
  138. return -1;
  139. ctlr = mallocz(sizeof(Ctlr), 1);
  140. /*
  141. * don't bother with vmap; i/o space is all mapped anyway,
  142. * and a size less than 1MB will blow an assertion in mmukmap.
  143. */
  144. ctlr->capio = capio = (Ecapio *)PHYSEHCI;
  145. // ctlr->capio = capio = vmap(PHYSEHCI, 1024);
  146. ctlr->opio = opio = (Eopio*)((uintptr)capio + (capio->cap & 0xff));
  147. hp->aux = ctlr;
  148. hp->port = (uintptr)ctlr->capio;
  149. hp->irq = 77;
  150. hp->nports = capio->parms & Cnports;
  151. ddprint("echi: %s, ncc %lud npcc %lud\n",
  152. capio->parms & 0x10000 ? "leds" : "no leds",
  153. (capio->parms >> 12) & 0xf, (capio->parms >> 8) & 0xf);
  154. ddprint("ehci: routing %s, %sport power ctl, %d ports\n",
  155. capio->parms & 0x40 ? "explicit" : "automatic",
  156. capio->parms & 0x10 ? "" : "no ", hp->nports);
  157. ehcireset(ctlr);
  158. ehcimeminit(ctlr);
  159. /* omap35-specific set up */
  160. /* bit 5 `must be set to 1 for proper behavior', spruf98d §23.2.6.7.17 */
  161. opio->insn[4] |= 1<<5;
  162. coherence();
  163. /* insn[5] is for both utmi and ulpi, depending on hostconfig mode */
  164. uhh = (Uhh *)PHYSUHH;
  165. if (uhh->hostconfig & P1ulpi_bypass) { /* utmi port 1 active */
  166. /* not doing this */
  167. iprint("usbehci: bypassing ulpi on port 1!\n");
  168. opio->insn[5] &= ~(MASK(4) << 13);
  169. opio->insn[5] |= 1 << 13; /* select port 1 */
  170. coherence();
  171. } else { /* ulpi port 1 active */
  172. /* TODO may need to reset gpio port2 here */
  173. /* disable integrated stp pull-up resistor */
  174. wrulpi(opio, 1, Ifcctlreg, Phystppullupoff);
  175. /* force phy to `high-speed' */
  176. wrulpi(opio, 1, Funcctlreg, 0x40);
  177. }
  178. /*
  179. * Linkage to the generic HCI driver.
  180. */
  181. ehcilinkage(hp);
  182. hp->shutdown = shutdown;
  183. hp->debug = setdebug;
  184. intrenable(78, hp->interrupt, hp, UNKNOWN, "usbtll");
  185. intrenable(92, hp->interrupt, hp, UNKNOWN, "usb otg");
  186. intrenable(93, hp->interrupt, hp, UNKNOWN, "usb otg dma");
  187. return 0;
  188. }
  189. void
  190. usbehcilink(void)
  191. {
  192. addhcitype("ehci", reset);
  193. }