au1x00_usb_ohci.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725
  1. /*
  2. * URB OHCI HCD (Host Controller Driver) for USB on the AU1x00.
  3. *
  4. * (C) Copyright 2003
  5. * Gary Jennejohn, DENX Software Engineering <garyj@denx.de>
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. *
  25. * Note: Part of this code has been derived from linux
  26. *
  27. */
  28. /*
  29. * IMPORTANT NOTES
  30. * 1 - this driver is intended for use with USB Mass Storage Devices
  31. * (BBB) ONLY. There is NO support for Interrupt or Isochronous pipes!
  32. */
  33. #include <config.h>
  34. #ifdef CONFIG_USB_OHCI
  35. /* #include <pci.h> no PCI on the AU1x00 */
  36. #include <common.h>
  37. #include <malloc.h>
  38. #include <asm/io.h>
  39. #include <asm/au1x00.h>
  40. #include <usb.h>
  41. #include "au1x00_usb_ohci.h"
  42. #define OHCI_USE_NPS /* force NoPowerSwitching mode */
  43. #define OHCI_VERBOSE_DEBUG /* not always helpful */
  44. #define OHCI_FILL_TRACE
  45. #define USBH_ENABLE_BE (1<<0)
  46. #define USBH_ENABLE_C (1<<1)
  47. #define USBH_ENABLE_E (1<<2)
  48. #define USBH_ENABLE_CE (1<<3)
  49. #define USBH_ENABLE_RD (1<<4)
  50. #ifdef __LITTLE_ENDIAN
  51. #define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C)
  52. #else
  53. #define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C | USBH_ENABLE_BE)
  54. #endif
  55. /* For initializing controller (mask in an HCFS mode too) */
  56. #define OHCI_CONTROL_INIT \
  57. (OHCI_CTRL_CBSR & 0x3) | OHCI_CTRL_IE | OHCI_CTRL_PLE
  58. #undef readl
  59. #undef writel
  60. #define readl(a) au_readl((long)(a))
  61. #define writel(v,a) au_writel((v),(int)(a))
  62. #define min_t(type,x,y) ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
  63. #define DEBUG
  64. #ifdef DEBUG
  65. #define dbg(format, arg...) printf("DEBUG: " format "\n", ## arg)
  66. #else
  67. #define dbg(format, arg...) do {} while(0)
  68. #endif /* DEBUG */
  69. #define err(format, arg...) printf("ERROR: " format "\n", ## arg)
  70. #define SHOW_INFO
  71. #ifdef SHOW_INFO
  72. #define info(format, arg...) printf("INFO: " format "\n", ## arg)
  73. #else
  74. #define info(format, arg...) do {} while(0)
  75. #endif
  76. #define m16_swap(x) swap_16(x)
  77. #define m32_swap(x) swap_32(x)
  78. /* global ohci_t */
  79. static ohci_t gohci;
  80. /* this must be aligned to a 256 byte boundary */
  81. struct ohci_hcca ghcca[1];
  82. /* a pointer to the aligned storage */
  83. struct ohci_hcca *phcca;
  84. /* this allocates EDs for all possible endpoints */
  85. struct ohci_device ohci_dev;
  86. /* urb_priv */
  87. urb_priv_t urb_priv;
  88. /* RHSC flag */
  89. int got_rhsc;
  90. /* device which was disconnected */
  91. struct usb_device *devgone;
  92. /*-------------------------------------------------------------------------*/
  93. /* AMD-756 (D2 rev) reports corrupt register contents in some cases.
  94. * The erratum (#4) description is incorrect. AMD's workaround waits
  95. * till some bits (mostly reserved) are clear; ok for all revs.
  96. */
  97. #define OHCI_QUIRK_AMD756 0xabcd
  98. #define read_roothub(hc, register, mask) ({ \
  99. u32 temp = readl (&hc->regs->roothub.register); \
  100. if (hc->flags & OHCI_QUIRK_AMD756) \
  101. while (temp & mask) \
  102. temp = readl (&hc->regs->roothub.register); \
  103. temp; })
  104. static u32 roothub_a (struct ohci *hc)
  105. { return read_roothub (hc, a, 0xfc0fe000); }
  106. static inline u32 roothub_b (struct ohci *hc)
  107. { return readl (&hc->regs->roothub.b); }
  108. static inline u32 roothub_status (struct ohci *hc)
  109. { return readl (&hc->regs->roothub.status); }
  110. static u32 roothub_portstatus (struct ohci *hc, int i)
  111. { return read_roothub (hc, portstatus [i], 0xffe0fce0); }
  112. /* forward declaration */
  113. static int hc_interrupt (void);
  114. static void
  115. td_submit_job (struct usb_device * dev, unsigned long pipe, void * buffer,
  116. int transfer_len, struct devrequest * setup, urb_priv_t * urb, int interval);
  117. /*-------------------------------------------------------------------------*
  118. * URB support functions
  119. *-------------------------------------------------------------------------*/
  120. /* free HCD-private data associated with this URB */
  121. static void urb_free_priv (urb_priv_t * urb)
  122. {
  123. int i;
  124. int last;
  125. struct td * td;
  126. last = urb->length - 1;
  127. if (last >= 0) {
  128. for (i = 0; i <= last; i++) {
  129. td = urb->td[i];
  130. if (td) {
  131. td->usb_dev = NULL;
  132. urb->td[i] = NULL;
  133. }
  134. }
  135. }
  136. }
  137. /*-------------------------------------------------------------------------*/
  138. #ifdef DEBUG
  139. static int sohci_get_current_frame_number (struct usb_device * dev);
  140. /* debug| print the main components of an URB
  141. * small: 0) header + data packets 1) just header */
  142. static void pkt_print (struct usb_device * dev, unsigned long pipe, void * buffer,
  143. int transfer_len, struct devrequest * setup, char * str, int small)
  144. {
  145. urb_priv_t * purb = &urb_priv;
  146. dbg("%s URB:[%4x] dev:%2d,ep:%2d-%c,type:%s,len:%d/%d stat:%#lx",
  147. str,
  148. sohci_get_current_frame_number (dev),
  149. usb_pipedevice (pipe),
  150. usb_pipeendpoint (pipe),
  151. usb_pipeout (pipe)? 'O': 'I',
  152. usb_pipetype (pipe) < 2? (usb_pipeint (pipe)? "INTR": "ISOC"):
  153. (usb_pipecontrol (pipe)? "CTRL": "BULK"),
  154. purb->actual_length,
  155. transfer_len, dev->status);
  156. #ifdef OHCI_VERBOSE_DEBUG
  157. if (!small) {
  158. int i, len;
  159. if (usb_pipecontrol (pipe)) {
  160. printf (__FILE__ ": cmd(8):");
  161. for (i = 0; i < 8 ; i++)
  162. printf (" %02x", ((__u8 *) setup) [i]);
  163. printf ("\n");
  164. }
  165. if (transfer_len > 0 && buffer) {
  166. printf (__FILE__ ": data(%d/%d):",
  167. purb->actual_length,
  168. transfer_len);
  169. len = usb_pipeout (pipe)?
  170. transfer_len: purb->actual_length;
  171. for (i = 0; i < 16 && i < len; i++)
  172. printf (" %02x", ((__u8 *) buffer) [i]);
  173. printf ("%s\n", i < len? "...": "");
  174. }
  175. }
  176. #endif
  177. }
  178. /* just for debugging; prints non-empty branches of the int ed tree inclusive iso eds*/
  179. void ep_print_int_eds (ohci_t *ohci, char * str) {
  180. int i, j;
  181. __u32 * ed_p;
  182. for (i= 0; i < 32; i++) {
  183. j = 5;
  184. ed_p = &(ohci->hcca->int_table [i]);
  185. if (*ed_p == 0)
  186. continue;
  187. printf (__FILE__ ": %s branch int %2d(%2x):", str, i, i);
  188. while (*ed_p != 0 && j--) {
  189. ed_t *ed = (ed_t *)m32_swap(ed_p);
  190. printf (" ed: %4x;", ed->hwINFO);
  191. ed_p = &ed->hwNextED;
  192. }
  193. printf ("\n");
  194. }
  195. }
  196. static void ohci_dump_intr_mask (char *label, __u32 mask)
  197. {
  198. dbg ("%s: 0x%08x%s%s%s%s%s%s%s%s%s",
  199. label,
  200. mask,
  201. (mask & OHCI_INTR_MIE) ? " MIE" : "",
  202. (mask & OHCI_INTR_OC) ? " OC" : "",
  203. (mask & OHCI_INTR_RHSC) ? " RHSC" : "",
  204. (mask & OHCI_INTR_FNO) ? " FNO" : "",
  205. (mask & OHCI_INTR_UE) ? " UE" : "",
  206. (mask & OHCI_INTR_RD) ? " RD" : "",
  207. (mask & OHCI_INTR_SF) ? " SF" : "",
  208. (mask & OHCI_INTR_WDH) ? " WDH" : "",
  209. (mask & OHCI_INTR_SO) ? " SO" : ""
  210. );
  211. }
  212. static void maybe_print_eds (char *label, __u32 value)
  213. {
  214. ed_t *edp = (ed_t *)value;
  215. if (value) {
  216. dbg ("%s %08x", label, value);
  217. dbg ("%08x", edp->hwINFO);
  218. dbg ("%08x", edp->hwTailP);
  219. dbg ("%08x", edp->hwHeadP);
  220. dbg ("%08x", edp->hwNextED);
  221. }
  222. }
  223. static char * hcfs2string (int state)
  224. {
  225. switch (state) {
  226. case OHCI_USB_RESET: return "reset";
  227. case OHCI_USB_RESUME: return "resume";
  228. case OHCI_USB_OPER: return "operational";
  229. case OHCI_USB_SUSPEND: return "suspend";
  230. }
  231. return "?";
  232. }
  233. /* dump control and status registers */
  234. static void ohci_dump_status (ohci_t *controller)
  235. {
  236. struct ohci_regs *regs = controller->regs;
  237. __u32 temp;
  238. temp = readl (&regs->revision) & 0xff;
  239. if (temp != 0x10)
  240. dbg ("spec %d.%d", (temp >> 4), (temp & 0x0f));
  241. temp = readl (&regs->control);
  242. dbg ("control: 0x%08x%s%s%s HCFS=%s%s%s%s%s CBSR=%d", temp,
  243. (temp & OHCI_CTRL_RWE) ? " RWE" : "",
  244. (temp & OHCI_CTRL_RWC) ? " RWC" : "",
  245. (temp & OHCI_CTRL_IR) ? " IR" : "",
  246. hcfs2string (temp & OHCI_CTRL_HCFS),
  247. (temp & OHCI_CTRL_BLE) ? " BLE" : "",
  248. (temp & OHCI_CTRL_CLE) ? " CLE" : "",
  249. (temp & OHCI_CTRL_IE) ? " IE" : "",
  250. (temp & OHCI_CTRL_PLE) ? " PLE" : "",
  251. temp & OHCI_CTRL_CBSR
  252. );
  253. temp = readl (&regs->cmdstatus);
  254. dbg ("cmdstatus: 0x%08x SOC=%d%s%s%s%s", temp,
  255. (temp & OHCI_SOC) >> 16,
  256. (temp & OHCI_OCR) ? " OCR" : "",
  257. (temp & OHCI_BLF) ? " BLF" : "",
  258. (temp & OHCI_CLF) ? " CLF" : "",
  259. (temp & OHCI_HCR) ? " HCR" : ""
  260. );
  261. ohci_dump_intr_mask ("intrstatus", readl (&regs->intrstatus));
  262. ohci_dump_intr_mask ("intrenable", readl (&regs->intrenable));
  263. maybe_print_eds ("ed_periodcurrent", readl (&regs->ed_periodcurrent));
  264. maybe_print_eds ("ed_controlhead", readl (&regs->ed_controlhead));
  265. maybe_print_eds ("ed_controlcurrent", readl (&regs->ed_controlcurrent));
  266. maybe_print_eds ("ed_bulkhead", readl (&regs->ed_bulkhead));
  267. maybe_print_eds ("ed_bulkcurrent", readl (&regs->ed_bulkcurrent));
  268. maybe_print_eds ("donehead", readl (&regs->donehead));
  269. }
  270. static void ohci_dump_roothub (ohci_t *controller, int verbose)
  271. {
  272. __u32 temp, ndp, i;
  273. temp = roothub_a (controller);
  274. ndp = (temp & RH_A_NDP);
  275. if (verbose) {
  276. dbg ("roothub.a: %08x POTPGT=%d%s%s%s%s%s NDP=%d", temp,
  277. ((temp & RH_A_POTPGT) >> 24) & 0xff,
  278. (temp & RH_A_NOCP) ? " NOCP" : "",
  279. (temp & RH_A_OCPM) ? " OCPM" : "",
  280. (temp & RH_A_DT) ? " DT" : "",
  281. (temp & RH_A_NPS) ? " NPS" : "",
  282. (temp & RH_A_PSM) ? " PSM" : "",
  283. ndp
  284. );
  285. temp = roothub_b (controller);
  286. dbg ("roothub.b: %08x PPCM=%04x DR=%04x",
  287. temp,
  288. (temp & RH_B_PPCM) >> 16,
  289. (temp & RH_B_DR)
  290. );
  291. temp = roothub_status (controller);
  292. dbg ("roothub.status: %08x%s%s%s%s%s%s",
  293. temp,
  294. (temp & RH_HS_CRWE) ? " CRWE" : "",
  295. (temp & RH_HS_OCIC) ? " OCIC" : "",
  296. (temp & RH_HS_LPSC) ? " LPSC" : "",
  297. (temp & RH_HS_DRWE) ? " DRWE" : "",
  298. (temp & RH_HS_OCI) ? " OCI" : "",
  299. (temp & RH_HS_LPS) ? " LPS" : ""
  300. );
  301. }
  302. for (i = 0; i < ndp; i++) {
  303. temp = roothub_portstatus (controller, i);
  304. dbg ("roothub.portstatus [%d] = 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s",
  305. i,
  306. temp,
  307. (temp & RH_PS_PRSC) ? " PRSC" : "",
  308. (temp & RH_PS_OCIC) ? " OCIC" : "",
  309. (temp & RH_PS_PSSC) ? " PSSC" : "",
  310. (temp & RH_PS_PESC) ? " PESC" : "",
  311. (temp & RH_PS_CSC) ? " CSC" : "",
  312. (temp & RH_PS_LSDA) ? " LSDA" : "",
  313. (temp & RH_PS_PPS) ? " PPS" : "",
  314. (temp & RH_PS_PRS) ? " PRS" : "",
  315. (temp & RH_PS_POCI) ? " POCI" : "",
  316. (temp & RH_PS_PSS) ? " PSS" : "",
  317. (temp & RH_PS_PES) ? " PES" : "",
  318. (temp & RH_PS_CCS) ? " CCS" : ""
  319. );
  320. }
  321. }
  322. static void ohci_dump (ohci_t *controller, int verbose)
  323. {
  324. dbg ("OHCI controller usb-%s state", controller->slot_name);
  325. /* dumps some of the state we know about */
  326. ohci_dump_status (controller);
  327. if (verbose)
  328. ep_print_int_eds (controller, "hcca");
  329. dbg ("hcca frame #%04x", controller->hcca->frame_no);
  330. ohci_dump_roothub (controller, 1);
  331. }
  332. #endif /* DEBUG */
  333. /*-------------------------------------------------------------------------*
  334. * Interface functions (URB)
  335. *-------------------------------------------------------------------------*/
  336. /* get a transfer request */
  337. int sohci_submit_job(struct usb_device *dev, unsigned long pipe, void *buffer,
  338. int transfer_len, struct devrequest *setup, int interval)
  339. {
  340. ohci_t *ohci;
  341. ed_t * ed;
  342. urb_priv_t *purb_priv;
  343. int i, size = 0;
  344. ohci = &gohci;
  345. /* when controller's hung, permit only roothub cleanup attempts
  346. * such as powering down ports */
  347. if (ohci->disabled) {
  348. err("sohci_submit_job: EPIPE");
  349. return -1;
  350. }
  351. /* every endpoint has a ed, locate and fill it */
  352. if (!(ed = ep_add_ed (dev, pipe))) {
  353. err("sohci_submit_job: ENOMEM");
  354. return -1;
  355. }
  356. /* for the private part of the URB we need the number of TDs (size) */
  357. switch (usb_pipetype (pipe)) {
  358. case PIPE_BULK: /* one TD for every 4096 Byte */
  359. size = (transfer_len - 1) / 4096 + 1;
  360. break;
  361. case PIPE_CONTROL: /* 1 TD for setup, 1 for ACK and 1 for every 4096 B */
  362. size = (transfer_len == 0)? 2:
  363. (transfer_len - 1) / 4096 + 3;
  364. break;
  365. }
  366. if (size >= (N_URB_TD - 1)) {
  367. err("need %d TDs, only have %d", size, N_URB_TD);
  368. return -1;
  369. }
  370. purb_priv = &urb_priv;
  371. purb_priv->pipe = pipe;
  372. /* fill the private part of the URB */
  373. purb_priv->length = size;
  374. purb_priv->ed = ed;
  375. purb_priv->actual_length = 0;
  376. /* allocate the TDs */
  377. /* note that td[0] was allocated in ep_add_ed */
  378. for (i = 0; i < size; i++) {
  379. purb_priv->td[i] = td_alloc (dev);
  380. if (!purb_priv->td[i]) {
  381. purb_priv->length = i;
  382. urb_free_priv (purb_priv);
  383. err("sohci_submit_job: ENOMEM");
  384. return -1;
  385. }
  386. }
  387. if (ed->state == ED_NEW || (ed->state & ED_DEL)) {
  388. urb_free_priv (purb_priv);
  389. err("sohci_submit_job: EINVAL");
  390. return -1;
  391. }
  392. /* link the ed into a chain if is not already */
  393. if (ed->state != ED_OPER)
  394. ep_link (ohci, ed);
  395. /* fill the TDs and link it to the ed */
  396. td_submit_job(dev, pipe, buffer, transfer_len, setup, purb_priv, interval);
  397. return 0;
  398. }
  399. /*-------------------------------------------------------------------------*/
  400. #ifdef DEBUG
  401. /* tell us the current USB frame number */
  402. static int sohci_get_current_frame_number (struct usb_device *usb_dev)
  403. {
  404. ohci_t *ohci = &gohci;
  405. return m16_swap (ohci->hcca->frame_no);
  406. }
  407. #endif
  408. /*-------------------------------------------------------------------------*
  409. * ED handling functions
  410. *-------------------------------------------------------------------------*/
  411. /* link an ed into one of the HC chains */
  412. static int ep_link (ohci_t *ohci, ed_t *edi)
  413. {
  414. volatile ed_t *ed = edi;
  415. ed->state = ED_OPER;
  416. switch (ed->type) {
  417. case PIPE_CONTROL:
  418. ed->hwNextED = 0;
  419. if (ohci->ed_controltail == NULL) {
  420. writel ((long)ed, &ohci->regs->ed_controlhead);
  421. } else {
  422. ohci->ed_controltail->hwNextED = m32_swap (ed);
  423. }
  424. ed->ed_prev = ohci->ed_controltail;
  425. if (!ohci->ed_controltail && !ohci->ed_rm_list[0] &&
  426. !ohci->ed_rm_list[1] && !ohci->sleeping) {
  427. ohci->hc_control |= OHCI_CTRL_CLE;
  428. writel (ohci->hc_control, &ohci->regs->control);
  429. }
  430. ohci->ed_controltail = edi;
  431. break;
  432. case PIPE_BULK:
  433. ed->hwNextED = 0;
  434. if (ohci->ed_bulktail == NULL) {
  435. writel ((long)ed, &ohci->regs->ed_bulkhead);
  436. } else {
  437. ohci->ed_bulktail->hwNextED = m32_swap (ed);
  438. }
  439. ed->ed_prev = ohci->ed_bulktail;
  440. if (!ohci->ed_bulktail && !ohci->ed_rm_list[0] &&
  441. !ohci->ed_rm_list[1] && !ohci->sleeping) {
  442. ohci->hc_control |= OHCI_CTRL_BLE;
  443. writel (ohci->hc_control, &ohci->regs->control);
  444. }
  445. ohci->ed_bulktail = edi;
  446. break;
  447. }
  448. return 0;
  449. }
  450. /*-------------------------------------------------------------------------*/
  451. /* unlink an ed from one of the HC chains.
  452. * just the link to the ed is unlinked.
  453. * the link from the ed still points to another operational ed or 0
  454. * so the HC can eventually finish the processing of the unlinked ed */
  455. static int ep_unlink (ohci_t *ohci, ed_t *ed)
  456. {
  457. ed->hwINFO |= m32_swap (OHCI_ED_SKIP);
  458. switch (ed->type) {
  459. case PIPE_CONTROL:
  460. if (ed->ed_prev == NULL) {
  461. if (!ed->hwNextED) {
  462. ohci->hc_control &= ~OHCI_CTRL_CLE;
  463. writel (ohci->hc_control, &ohci->regs->control);
  464. }
  465. writel (m32_swap (*((__u32 *)&ed->hwNextED)), &ohci->regs->ed_controlhead);
  466. } else {
  467. ed->ed_prev->hwNextED = ed->hwNextED;
  468. }
  469. if (ohci->ed_controltail == ed) {
  470. ohci->ed_controltail = ed->ed_prev;
  471. } else {
  472. ((ed_t *)m32_swap (*((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
  473. }
  474. break;
  475. case PIPE_BULK:
  476. if (ed->ed_prev == NULL) {
  477. if (!ed->hwNextED) {
  478. ohci->hc_control &= ~OHCI_CTRL_BLE;
  479. writel (ohci->hc_control, &ohci->regs->control);
  480. }
  481. writel (m32_swap (*((__u32 *)&ed->hwNextED)), &ohci->regs->ed_bulkhead);
  482. } else {
  483. ed->ed_prev->hwNextED = ed->hwNextED;
  484. }
  485. if (ohci->ed_bulktail == ed) {
  486. ohci->ed_bulktail = ed->ed_prev;
  487. } else {
  488. ((ed_t *)m32_swap (*((__u32 *)&ed->hwNextED)))->ed_prev = ed->ed_prev;
  489. }
  490. break;
  491. }
  492. ed->state = ED_UNLINK;
  493. return 0;
  494. }
  495. /*-------------------------------------------------------------------------*/
  496. /* add/reinit an endpoint; this should be done once at the usb_set_configuration command,
  497. * but the USB stack is a little bit stateless so we do it at every transaction
  498. * if the state of the ed is ED_NEW then a dummy td is added and the state is changed to ED_UNLINK
  499. * in all other cases the state is left unchanged
  500. * the ed info fields are setted anyway even though most of them should not change */
  501. static ed_t * ep_add_ed (struct usb_device *usb_dev, unsigned long pipe)
  502. {
  503. td_t *td;
  504. ed_t *ed_ret;
  505. volatile ed_t *ed;
  506. ed = ed_ret = &ohci_dev.ed[(usb_pipeendpoint (pipe) << 1) |
  507. (usb_pipecontrol (pipe)? 0: usb_pipeout (pipe))];
  508. if ((ed->state & ED_DEL) || (ed->state & ED_URB_DEL)) {
  509. err("ep_add_ed: pending delete");
  510. /* pending delete request */
  511. return NULL;
  512. }
  513. if (ed->state == ED_NEW) {
  514. ed->hwINFO = m32_swap (OHCI_ED_SKIP); /* skip ed */
  515. /* dummy td; end of td list for ed */
  516. td = td_alloc (usb_dev);
  517. ed->hwTailP = m32_swap (td);
  518. ed->hwHeadP = ed->hwTailP;
  519. ed->state = ED_UNLINK;
  520. ed->type = usb_pipetype (pipe);
  521. ohci_dev.ed_cnt++;
  522. }
  523. ed->hwINFO = m32_swap (usb_pipedevice (pipe)
  524. | usb_pipeendpoint (pipe) << 7
  525. | (usb_pipeisoc (pipe)? 0x8000: 0)
  526. | (usb_pipecontrol (pipe)? 0: (usb_pipeout (pipe)? 0x800: 0x1000))
  527. | usb_pipeslow (pipe) << 13
  528. | usb_maxpacket (usb_dev, pipe) << 16);
  529. return ed_ret;
  530. }
  531. /*-------------------------------------------------------------------------*
  532. * TD handling functions
  533. *-------------------------------------------------------------------------*/
  534. /* enqueue next TD for this URB (OHCI spec 5.2.8.2) */
  535. static void td_fill (ohci_t *ohci, unsigned int info,
  536. void *data, int len,
  537. struct usb_device *dev, int index, urb_priv_t *urb_priv)
  538. {
  539. volatile td_t *td, *td_pt;
  540. #ifdef OHCI_FILL_TRACE
  541. int i;
  542. #endif
  543. if (index > urb_priv->length) {
  544. err("index > length");
  545. return;
  546. }
  547. /* use this td as the next dummy */
  548. td_pt = urb_priv->td [index];
  549. td_pt->hwNextTD = 0;
  550. /* fill the old dummy TD */
  551. td = urb_priv->td [index] = (td_t *)(m32_swap (urb_priv->ed->hwTailP) & ~0xf);
  552. td->ed = urb_priv->ed;
  553. td->next_dl_td = NULL;
  554. td->index = index;
  555. td->data = (__u32)data;
  556. #ifdef OHCI_FILL_TRACE
  557. if (1 || (usb_pipebulk(urb_priv->pipe) &&
  558. usb_pipeout(urb_priv->pipe))) {
  559. for (i = 0; i < len; i++)
  560. printf("td->data[%d] %#2x\n",i, ((unsigned char *)(td->data+0x80000000))[i]);
  561. }
  562. #endif
  563. if (!len)
  564. data = 0;
  565. td->hwINFO = m32_swap (info);
  566. td->hwCBP = m32_swap (data);
  567. if (data)
  568. td->hwBE = m32_swap (data + len - 1);
  569. else
  570. td->hwBE = 0;
  571. td->hwNextTD = m32_swap (td_pt);
  572. td->hwPSW [0] = m16_swap (((__u32)data & 0x0FFF) | 0xE000);
  573. /* append to queue */
  574. td->ed->hwTailP = td->hwNextTD;
  575. }
  576. /*-------------------------------------------------------------------------*/
  577. /* prepare all TDs of a transfer */
  578. #define kseg_to_phys(x) ((void *)((__u32)(x) - 0x80000000))
  579. static void td_submit_job (struct usb_device *dev, unsigned long pipe, void *buffer,
  580. int transfer_len, struct devrequest *setup, urb_priv_t *urb, int interval)
  581. {
  582. ohci_t *ohci = &gohci;
  583. int data_len = transfer_len;
  584. void *data;
  585. int cnt = 0;
  586. __u32 info = 0;
  587. unsigned int toggle = 0;
  588. /* OHCI handles the DATA-toggles itself, we just use the USB-toggle bits for reseting */
  589. if(usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe))) {
  590. toggle = TD_T_TOGGLE;
  591. } else {
  592. toggle = TD_T_DATA0;
  593. usb_settoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe), 1);
  594. }
  595. urb->td_cnt = 0;
  596. if (data_len)
  597. data = kseg_to_phys(buffer);
  598. else
  599. data = 0;
  600. switch (usb_pipetype (pipe)) {
  601. case PIPE_BULK:
  602. info = usb_pipeout (pipe)?
  603. TD_CC | TD_DP_OUT : TD_CC | TD_DP_IN ;
  604. while(data_len > 4096) {
  605. td_fill (ohci, info | (cnt? TD_T_TOGGLE:toggle), data, 4096, dev, cnt, urb);
  606. data += 4096; data_len -= 4096; cnt++;
  607. }
  608. info = usb_pipeout (pipe)?
  609. TD_CC | TD_DP_OUT : TD_CC | TD_R | TD_DP_IN ;
  610. td_fill (ohci, info | (cnt? TD_T_TOGGLE:toggle), data, data_len, dev, cnt, urb);
  611. cnt++;
  612. if (!ohci->sleeping)
  613. writel (OHCI_BLF, &ohci->regs->cmdstatus); /* start bulk list */
  614. break;
  615. case PIPE_CONTROL:
  616. info = TD_CC | TD_DP_SETUP | TD_T_DATA0;
  617. td_fill (ohci, info, kseg_to_phys(setup), 8, dev, cnt++, urb);
  618. if (data_len > 0) {
  619. info = usb_pipeout (pipe)?
  620. TD_CC | TD_R | TD_DP_OUT | TD_T_DATA1 : TD_CC | TD_R | TD_DP_IN | TD_T_DATA1;
  621. /* NOTE: mishandles transfers >8K, some >4K */
  622. td_fill (ohci, info, data, data_len, dev, cnt++, urb);
  623. }
  624. info = usb_pipeout (pipe)?
  625. TD_CC | TD_DP_IN | TD_T_DATA1: TD_CC | TD_DP_OUT | TD_T_DATA1;
  626. td_fill (ohci, info, data, 0, dev, cnt++, urb);
  627. if (!ohci->sleeping)
  628. writel (OHCI_CLF, &ohci->regs->cmdstatus); /* start Control list */
  629. break;
  630. }
  631. if (urb->length != cnt)
  632. dbg("TD LENGTH %d != CNT %d", urb->length, cnt);
  633. }
  634. /*-------------------------------------------------------------------------*
  635. * Done List handling functions
  636. *-------------------------------------------------------------------------*/
  637. /* calculate the transfer length and update the urb */
  638. static void dl_transfer_length(td_t * td)
  639. {
  640. __u32 tdINFO, tdBE, tdCBP;
  641. urb_priv_t *lurb_priv = &urb_priv;
  642. tdINFO = m32_swap (td->hwINFO);
  643. tdBE = m32_swap (td->hwBE);
  644. tdCBP = m32_swap (td->hwCBP);
  645. if (!(usb_pipecontrol(lurb_priv->pipe) &&
  646. ((td->index == 0) || (td->index == lurb_priv->length - 1)))) {
  647. if (tdBE != 0) {
  648. if (td->hwCBP == 0)
  649. lurb_priv->actual_length += tdBE - td->data + 1;
  650. else
  651. lurb_priv->actual_length += tdCBP - td->data;
  652. }
  653. }
  654. }
  655. /*-------------------------------------------------------------------------*/
  656. /* replies to the request have to be on a FIFO basis so
  657. * we reverse the reversed done-list */
  658. static td_t * dl_reverse_done_list (ohci_t *ohci)
  659. {
  660. __u32 td_list_hc;
  661. td_t *td_rev = NULL;
  662. td_t *td_list = NULL;
  663. urb_priv_t *lurb_priv = NULL;
  664. td_list_hc = m32_swap (ohci->hcca->done_head) & 0xfffffff0;
  665. ohci->hcca->done_head = 0;
  666. while (td_list_hc) {
  667. td_list = (td_t *)td_list_hc;
  668. if (TD_CC_GET (m32_swap (td_list->hwINFO))) {
  669. lurb_priv = &urb_priv;
  670. dbg(" USB-error/status: %x : %p",
  671. TD_CC_GET (m32_swap (td_list->hwINFO)), td_list);
  672. if (td_list->ed->hwHeadP & m32_swap (0x1)) {
  673. if (lurb_priv && ((td_list->index + 1) < lurb_priv->length)) {
  674. td_list->ed->hwHeadP =
  675. (lurb_priv->td[lurb_priv->length - 1]->hwNextTD & m32_swap (0xfffffff0)) |
  676. (td_list->ed->hwHeadP & m32_swap (0x2));
  677. lurb_priv->td_cnt += lurb_priv->length - td_list->index - 1;
  678. } else
  679. td_list->ed->hwHeadP &= m32_swap (0xfffffff2);
  680. }
  681. }
  682. td_list->next_dl_td = td_rev;
  683. td_rev = td_list;
  684. td_list_hc = m32_swap (td_list->hwNextTD) & 0xfffffff0;
  685. }
  686. return td_list;
  687. }
  688. /*-------------------------------------------------------------------------*/
  689. /* td done list */
  690. static int dl_done_list (ohci_t *ohci, td_t *td_list)
  691. {
  692. td_t *td_list_next = NULL;
  693. ed_t *ed;
  694. int cc = 0;
  695. int stat = 0;
  696. /* urb_t *urb; */
  697. urb_priv_t *lurb_priv;
  698. __u32 tdINFO, edHeadP, edTailP;
  699. while (td_list) {
  700. td_list_next = td_list->next_dl_td;
  701. lurb_priv = &urb_priv;
  702. tdINFO = m32_swap (td_list->hwINFO);
  703. ed = td_list->ed;
  704. dl_transfer_length(td_list);
  705. /* error code of transfer */
  706. cc = TD_CC_GET (tdINFO);
  707. if (cc != 0) {
  708. dbg("ConditionCode %#x", cc);
  709. stat = cc_to_error[cc];
  710. }
  711. if (ed->state != ED_NEW) {
  712. edHeadP = m32_swap (ed->hwHeadP) & 0xfffffff0;
  713. edTailP = m32_swap (ed->hwTailP);
  714. /* unlink eds if they are not busy */
  715. if ((edHeadP == edTailP) && (ed->state == ED_OPER))
  716. ep_unlink (ohci, ed);
  717. }
  718. td_list = td_list_next;
  719. }
  720. return stat;
  721. }
  722. /*-------------------------------------------------------------------------*
  723. * Virtual Root Hub
  724. *-------------------------------------------------------------------------*/
  725. /* Device descriptor */
  726. static __u8 root_hub_dev_des[] =
  727. {
  728. 0x12, /* __u8 bLength; */
  729. 0x01, /* __u8 bDescriptorType; Device */
  730. 0x10, /* __u16 bcdUSB; v1.1 */
  731. 0x01,
  732. 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
  733. 0x00, /* __u8 bDeviceSubClass; */
  734. 0x00, /* __u8 bDeviceProtocol; */
  735. 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
  736. 0x00, /* __u16 idVendor; */
  737. 0x00,
  738. 0x00, /* __u16 idProduct; */
  739. 0x00,
  740. 0x00, /* __u16 bcdDevice; */
  741. 0x00,
  742. 0x00, /* __u8 iManufacturer; */
  743. 0x01, /* __u8 iProduct; */
  744. 0x00, /* __u8 iSerialNumber; */
  745. 0x01 /* __u8 bNumConfigurations; */
  746. };
  747. /* Configuration descriptor */
  748. static __u8 root_hub_config_des[] =
  749. {
  750. 0x09, /* __u8 bLength; */
  751. 0x02, /* __u8 bDescriptorType; Configuration */
  752. 0x19, /* __u16 wTotalLength; */
  753. 0x00,
  754. 0x01, /* __u8 bNumInterfaces; */
  755. 0x01, /* __u8 bConfigurationValue; */
  756. 0x00, /* __u8 iConfiguration; */
  757. 0x40, /* __u8 bmAttributes;
  758. Bit 7: Bus-powered, 6: Self-powered, 5 Remote-wakwup, 4..0: resvd */
  759. 0x00, /* __u8 MaxPower; */
  760. /* interface */
  761. 0x09, /* __u8 if_bLength; */
  762. 0x04, /* __u8 if_bDescriptorType; Interface */
  763. 0x00, /* __u8 if_bInterfaceNumber; */
  764. 0x00, /* __u8 if_bAlternateSetting; */
  765. 0x01, /* __u8 if_bNumEndpoints; */
  766. 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
  767. 0x00, /* __u8 if_bInterfaceSubClass; */
  768. 0x00, /* __u8 if_bInterfaceProtocol; */
  769. 0x00, /* __u8 if_iInterface; */
  770. /* endpoint */
  771. 0x07, /* __u8 ep_bLength; */
  772. 0x05, /* __u8 ep_bDescriptorType; Endpoint */
  773. 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
  774. 0x03, /* __u8 ep_bmAttributes; Interrupt */
  775. 0x02, /* __u16 ep_wMaxPacketSize; ((MAX_ROOT_PORTS + 1) / 8 */
  776. 0x00,
  777. 0xff /* __u8 ep_bInterval; 255 ms */
  778. };
  779. static unsigned char root_hub_str_index0[] =
  780. {
  781. 0x04, /* __u8 bLength; */
  782. 0x03, /* __u8 bDescriptorType; String-descriptor */
  783. 0x09, /* __u8 lang ID */
  784. 0x04, /* __u8 lang ID */
  785. };
  786. static unsigned char root_hub_str_index1[] =
  787. {
  788. 28, /* __u8 bLength; */
  789. 0x03, /* __u8 bDescriptorType; String-descriptor */
  790. 'O', /* __u8 Unicode */
  791. 0, /* __u8 Unicode */
  792. 'H', /* __u8 Unicode */
  793. 0, /* __u8 Unicode */
  794. 'C', /* __u8 Unicode */
  795. 0, /* __u8 Unicode */
  796. 'I', /* __u8 Unicode */
  797. 0, /* __u8 Unicode */
  798. ' ', /* __u8 Unicode */
  799. 0, /* __u8 Unicode */
  800. 'R', /* __u8 Unicode */
  801. 0, /* __u8 Unicode */
  802. 'o', /* __u8 Unicode */
  803. 0, /* __u8 Unicode */
  804. 'o', /* __u8 Unicode */
  805. 0, /* __u8 Unicode */
  806. 't', /* __u8 Unicode */
  807. 0, /* __u8 Unicode */
  808. ' ', /* __u8 Unicode */
  809. 0, /* __u8 Unicode */
  810. 'H', /* __u8 Unicode */
  811. 0, /* __u8 Unicode */
  812. 'u', /* __u8 Unicode */
  813. 0, /* __u8 Unicode */
  814. 'b', /* __u8 Unicode */
  815. 0, /* __u8 Unicode */
  816. };
  817. /* Hub class-specific descriptor is constructed dynamically */
  818. /*-------------------------------------------------------------------------*/
  819. #define OK(x) len = (x); break
  820. #ifdef DEBUG
  821. #define WR_RH_STAT(x) {info("WR:status %#8x", (x));writel((x), &gohci.regs->roothub.status);}
  822. #define WR_RH_PORTSTAT(x) {info("WR:portstatus[%d] %#8x", wIndex-1, (x));writel((x), &gohci.regs->roothub.portstatus[wIndex-1]);}
  823. #else
  824. #define WR_RH_STAT(x) writel((x), &gohci.regs->roothub.status)
  825. #define WR_RH_PORTSTAT(x) writel((x), &gohci.regs->roothub.portstatus[wIndex-1])
  826. #endif
  827. #define RD_RH_STAT roothub_status(&gohci)
  828. #define RD_RH_PORTSTAT roothub_portstatus(&gohci,wIndex-1)
  829. /* request to virtual root hub */
  830. int rh_check_port_status(ohci_t *controller)
  831. {
  832. __u32 temp, ndp, i;
  833. int res;
  834. res = -1;
  835. temp = roothub_a (controller);
  836. ndp = (temp & RH_A_NDP);
  837. for (i = 0; i < ndp; i++) {
  838. temp = roothub_portstatus (controller, i);
  839. /* check for a device disconnect */
  840. if (((temp & (RH_PS_PESC | RH_PS_CSC)) ==
  841. (RH_PS_PESC | RH_PS_CSC)) &&
  842. ((temp & RH_PS_CCS) == 0)) {
  843. res = i;
  844. break;
  845. }
  846. }
  847. return res;
  848. }
  849. static int ohci_submit_rh_msg(struct usb_device *dev, unsigned long pipe,
  850. void *buffer, int transfer_len, struct devrequest *cmd)
  851. {
  852. void * data = buffer;
  853. int leni = transfer_len;
  854. int len = 0;
  855. int stat = 0;
  856. __u32 datab[4];
  857. __u8 *data_buf = (__u8 *)datab;
  858. __u16 bmRType_bReq;
  859. __u16 wValue;
  860. __u16 wIndex;
  861. __u16 wLength;
  862. #ifdef DEBUG
  863. urb_priv.actual_length = 0;
  864. pkt_print(dev, pipe, buffer, transfer_len, cmd, "SUB(rh)", usb_pipein(pipe));
  865. #else
  866. wait_ms(1);
  867. #endif
  868. if (usb_pipeint(pipe)) {
  869. info("Root-Hub submit IRQ: NOT implemented");
  870. return 0;
  871. }
  872. bmRType_bReq = cmd->requesttype | (cmd->request << 8);
  873. wValue = m16_swap (cmd->value);
  874. wIndex = m16_swap (cmd->index);
  875. wLength = m16_swap (cmd->length);
  876. info("Root-Hub: adr: %2x cmd(%1x): %08x %04x %04x %04x",
  877. dev->devnum, 8, bmRType_bReq, wValue, wIndex, wLength);
  878. switch (bmRType_bReq) {
  879. /* Request Destination:
  880. without flags: Device,
  881. RH_INTERFACE: interface,
  882. RH_ENDPOINT: endpoint,
  883. RH_CLASS means HUB here,
  884. RH_OTHER | RH_CLASS almost ever means HUB_PORT here
  885. */
  886. case RH_GET_STATUS:
  887. *(__u16 *) data_buf = m16_swap (1); OK (2);
  888. case RH_GET_STATUS | RH_INTERFACE:
  889. *(__u16 *) data_buf = m16_swap (0); OK (2);
  890. case RH_GET_STATUS | RH_ENDPOINT:
  891. *(__u16 *) data_buf = m16_swap (0); OK (2);
  892. case RH_GET_STATUS | RH_CLASS:
  893. *(__u32 *) data_buf = m32_swap (
  894. RD_RH_STAT & ~(RH_HS_CRWE | RH_HS_DRWE));
  895. OK (4);
  896. case RH_GET_STATUS | RH_OTHER | RH_CLASS:
  897. *(__u32 *) data_buf = m32_swap (RD_RH_PORTSTAT); OK (4);
  898. case RH_CLEAR_FEATURE | RH_ENDPOINT:
  899. switch (wValue) {
  900. case (RH_ENDPOINT_STALL): OK (0);
  901. }
  902. break;
  903. case RH_CLEAR_FEATURE | RH_CLASS:
  904. switch (wValue) {
  905. case RH_C_HUB_LOCAL_POWER:
  906. OK(0);
  907. case (RH_C_HUB_OVER_CURRENT):
  908. WR_RH_STAT(RH_HS_OCIC); OK (0);
  909. }
  910. break;
  911. case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
  912. switch (wValue) {
  913. case (RH_PORT_ENABLE):
  914. WR_RH_PORTSTAT (RH_PS_CCS ); OK (0);
  915. case (RH_PORT_SUSPEND):
  916. WR_RH_PORTSTAT (RH_PS_POCI); OK (0);
  917. case (RH_PORT_POWER):
  918. WR_RH_PORTSTAT (RH_PS_LSDA); OK (0);
  919. case (RH_C_PORT_CONNECTION):
  920. WR_RH_PORTSTAT (RH_PS_CSC ); OK (0);
  921. case (RH_C_PORT_ENABLE):
  922. WR_RH_PORTSTAT (RH_PS_PESC); OK (0);
  923. case (RH_C_PORT_SUSPEND):
  924. WR_RH_PORTSTAT (RH_PS_PSSC); OK (0);
  925. case (RH_C_PORT_OVER_CURRENT):
  926. WR_RH_PORTSTAT (RH_PS_OCIC); OK (0);
  927. case (RH_C_PORT_RESET):
  928. WR_RH_PORTSTAT (RH_PS_PRSC); OK (0);
  929. }
  930. break;
  931. case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
  932. switch (wValue) {
  933. case (RH_PORT_SUSPEND):
  934. WR_RH_PORTSTAT (RH_PS_PSS ); OK (0);
  935. case (RH_PORT_RESET): /* BUG IN HUP CODE *********/
  936. if (RD_RH_PORTSTAT & RH_PS_CCS)
  937. WR_RH_PORTSTAT (RH_PS_PRS);
  938. OK (0);
  939. case (RH_PORT_POWER):
  940. WR_RH_PORTSTAT (RH_PS_PPS ); OK (0);
  941. case (RH_PORT_ENABLE): /* BUG IN HUP CODE *********/
  942. if (RD_RH_PORTSTAT & RH_PS_CCS)
  943. WR_RH_PORTSTAT (RH_PS_PES );
  944. OK (0);
  945. }
  946. break;
  947. case RH_SET_ADDRESS: gohci.rh.devnum = wValue; OK(0);
  948. case RH_GET_DESCRIPTOR:
  949. switch ((wValue & 0xff00) >> 8) {
  950. case (0x01): /* device descriptor */
  951. len = min_t(unsigned int,
  952. leni,
  953. min_t(unsigned int,
  954. sizeof (root_hub_dev_des),
  955. wLength));
  956. data_buf = root_hub_dev_des; OK(len);
  957. case (0x02): /* configuration descriptor */
  958. len = min_t(unsigned int,
  959. leni,
  960. min_t(unsigned int,
  961. sizeof (root_hub_config_des),
  962. wLength));
  963. data_buf = root_hub_config_des; OK(len);
  964. case (0x03): /* string descriptors */
  965. if(wValue==0x0300) {
  966. len = min_t(unsigned int,
  967. leni,
  968. min_t(unsigned int,
  969. sizeof (root_hub_str_index0),
  970. wLength));
  971. data_buf = root_hub_str_index0;
  972. OK(len);
  973. }
  974. if(wValue==0x0301) {
  975. len = min_t(unsigned int,
  976. leni,
  977. min_t(unsigned int,
  978. sizeof (root_hub_str_index1),
  979. wLength));
  980. data_buf = root_hub_str_index1;
  981. OK(len);
  982. }
  983. default:
  984. stat = USB_ST_STALLED;
  985. }
  986. break;
  987. case RH_GET_DESCRIPTOR | RH_CLASS:
  988. {
  989. __u32 temp = roothub_a (&gohci);
  990. data_buf [0] = 9; /* min length; */
  991. data_buf [1] = 0x29;
  992. data_buf [2] = temp & RH_A_NDP;
  993. data_buf [3] = 0;
  994. if (temp & RH_A_PSM) /* per-port power switching? */
  995. data_buf [3] |= 0x1;
  996. if (temp & RH_A_NOCP) /* no overcurrent reporting? */
  997. data_buf [3] |= 0x10;
  998. else if (temp & RH_A_OCPM) /* per-port overcurrent reporting? */
  999. data_buf [3] |= 0x8;
  1000. /* corresponds to data_buf[4-7] */
  1001. datab [1] = 0;
  1002. data_buf [5] = (temp & RH_A_POTPGT) >> 24;
  1003. temp = roothub_b (&gohci);
  1004. data_buf [7] = temp & RH_B_DR;
  1005. if (data_buf [2] < 7) {
  1006. data_buf [8] = 0xff;
  1007. } else {
  1008. data_buf [0] += 2;
  1009. data_buf [8] = (temp & RH_B_DR) >> 8;
  1010. data_buf [10] = data_buf [9] = 0xff;
  1011. }
  1012. len = min_t(unsigned int, leni,
  1013. min_t(unsigned int, data_buf [0], wLength));
  1014. OK (len);
  1015. }
  1016. case RH_GET_CONFIGURATION: *(__u8 *) data_buf = 0x01; OK (1);
  1017. case RH_SET_CONFIGURATION: WR_RH_STAT (0x10000); OK (0);
  1018. default:
  1019. dbg ("unsupported root hub command");
  1020. stat = USB_ST_STALLED;
  1021. }
  1022. #ifdef DEBUG
  1023. ohci_dump_roothub (&gohci, 1);
  1024. #else
  1025. wait_ms(1);
  1026. #endif
  1027. len = min_t(int, len, leni);
  1028. if (data != data_buf)
  1029. memcpy (data, data_buf, len);
  1030. dev->act_len = len;
  1031. dev->status = stat;
  1032. #ifdef DEBUG
  1033. if (transfer_len)
  1034. urb_priv.actual_length = transfer_len;
  1035. pkt_print(dev, pipe, buffer, transfer_len, cmd, "RET(rh)", 0/*usb_pipein(pipe)*/);
  1036. #else
  1037. wait_ms(1);
  1038. #endif
  1039. return stat;
  1040. }
  1041. /*-------------------------------------------------------------------------*/
  1042. /* common code for handling submit messages - used for all but root hub */
  1043. /* accesses. */
  1044. int submit_common_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
  1045. int transfer_len, struct devrequest *setup, int interval)
  1046. {
  1047. int stat = 0;
  1048. int maxsize = usb_maxpacket(dev, pipe);
  1049. int timeout;
  1050. /* device pulled? Shortcut the action. */
  1051. if (devgone == dev) {
  1052. dev->status = USB_ST_CRC_ERR;
  1053. return 0;
  1054. }
  1055. #ifdef DEBUG
  1056. urb_priv.actual_length = 0;
  1057. pkt_print(dev, pipe, buffer, transfer_len, setup, "SUB", usb_pipein(pipe));
  1058. #else
  1059. wait_ms(1);
  1060. #endif
  1061. if (!maxsize) {
  1062. err("submit_common_message: pipesize for pipe %lx is zero",
  1063. pipe);
  1064. return -1;
  1065. }
  1066. if (sohci_submit_job(dev, pipe, buffer, transfer_len, setup, interval) < 0) {
  1067. err("sohci_submit_job failed");
  1068. return -1;
  1069. }
  1070. wait_ms(10);
  1071. /* ohci_dump_status(&gohci); */
  1072. /* allow more time for a BULK device to react - some are slow */
  1073. #define BULK_TO 5000 /* timeout in milliseconds */
  1074. if (usb_pipebulk(pipe))
  1075. timeout = BULK_TO;
  1076. else
  1077. timeout = 100;
  1078. timeout *= 4;
  1079. /* wait for it to complete */
  1080. for (;;) {
  1081. /* check whether the controller is done */
  1082. stat = hc_interrupt();
  1083. if (stat < 0) {
  1084. stat = USB_ST_CRC_ERR;
  1085. break;
  1086. }
  1087. if (stat >= 0 && stat != 0xff) {
  1088. /* 0xff is returned for an SF-interrupt */
  1089. break;
  1090. }
  1091. if (--timeout) {
  1092. udelay(250); /* wait_ms(1); */
  1093. } else {
  1094. err("CTL:TIMEOUT ");
  1095. stat = USB_ST_CRC_ERR;
  1096. break;
  1097. }
  1098. }
  1099. /* we got an Root Hub Status Change interrupt */
  1100. if (got_rhsc) {
  1101. #ifdef DEBUG
  1102. ohci_dump_roothub (&gohci, 1);
  1103. #endif
  1104. got_rhsc = 0;
  1105. /* abuse timeout */
  1106. timeout = rh_check_port_status(&gohci);
  1107. if (timeout >= 0) {
  1108. #if 0 /* this does nothing useful, but leave it here in case that changes */
  1109. /* the called routine adds 1 to the passed value */
  1110. usb_hub_port_connect_change(gohci.rh.dev, timeout - 1);
  1111. #endif
  1112. /*
  1113. * XXX
  1114. * This is potentially dangerous because it assumes
  1115. * that only one device is ever plugged in!
  1116. */
  1117. devgone = dev;
  1118. }
  1119. }
  1120. dev->status = stat;
  1121. dev->act_len = transfer_len;
  1122. #ifdef DEBUG
  1123. pkt_print(dev, pipe, buffer, transfer_len, setup, "RET(ctlr)", usb_pipein(pipe));
  1124. #else
  1125. wait_ms(1);
  1126. #endif
  1127. /* free TDs in urb_priv */
  1128. urb_free_priv (&urb_priv);
  1129. return 0;
  1130. }
  1131. /* submit routines called from usb.c */
  1132. int submit_bulk_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
  1133. int transfer_len)
  1134. {
  1135. info("submit_bulk_msg");
  1136. return submit_common_msg(dev, pipe, buffer, transfer_len, NULL, 0);
  1137. }
  1138. int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
  1139. int transfer_len, struct devrequest *setup)
  1140. {
  1141. int maxsize = usb_maxpacket(dev, pipe);
  1142. info("submit_control_msg");
  1143. #ifdef DEBUG
  1144. urb_priv.actual_length = 0;
  1145. pkt_print(dev, pipe, buffer, transfer_len, setup, "SUB", usb_pipein(pipe));
  1146. #else
  1147. wait_ms(1);
  1148. #endif
  1149. if (!maxsize) {
  1150. err("submit_control_message: pipesize for pipe %lx is zero",
  1151. pipe);
  1152. return -1;
  1153. }
  1154. if (((pipe >> 8) & 0x7f) == gohci.rh.devnum) {
  1155. gohci.rh.dev = dev;
  1156. /* root hub - redirect */
  1157. return ohci_submit_rh_msg(dev, pipe, buffer, transfer_len,
  1158. setup);
  1159. }
  1160. return submit_common_msg(dev, pipe, buffer, transfer_len, setup, 0);
  1161. }
  1162. int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
  1163. int transfer_len, int interval)
  1164. {
  1165. info("submit_int_msg");
  1166. return -1;
  1167. }
  1168. /*-------------------------------------------------------------------------*
  1169. * HC functions
  1170. *-------------------------------------------------------------------------*/
  1171. /* reset the HC and BUS */
  1172. static int hc_reset (ohci_t *ohci)
  1173. {
  1174. int timeout = 30;
  1175. int smm_timeout = 50; /* 0,5 sec */
  1176. if (readl (&ohci->regs->control) & OHCI_CTRL_IR) { /* SMM owns the HC */
  1177. writel (OHCI_OCR, &ohci->regs->cmdstatus); /* request ownership */
  1178. info("USB HC TakeOver from SMM");
  1179. while (readl (&ohci->regs->control) & OHCI_CTRL_IR) {
  1180. wait_ms (10);
  1181. if (--smm_timeout == 0) {
  1182. err("USB HC TakeOver failed!");
  1183. return -1;
  1184. }
  1185. }
  1186. }
  1187. /* Disable HC interrupts */
  1188. writel (OHCI_INTR_MIE, &ohci->regs->intrdisable);
  1189. dbg("USB HC reset_hc usb-%s: ctrl = 0x%X ;",
  1190. ohci->slot_name,
  1191. readl (&ohci->regs->control));
  1192. /* Reset USB (needed by some controllers) */
  1193. writel (0, &ohci->regs->control);
  1194. /* HC Reset requires max 10 us delay */
  1195. writel (OHCI_HCR, &ohci->regs->cmdstatus);
  1196. while ((readl (&ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
  1197. if (--timeout == 0) {
  1198. err("USB HC reset timed out!");
  1199. return -1;
  1200. }
  1201. udelay (1);
  1202. }
  1203. return 0;
  1204. }
  1205. /*-------------------------------------------------------------------------*/
  1206. /* Start an OHCI controller, set the BUS operational
  1207. * enable interrupts
  1208. * connect the virtual root hub */
  1209. static int hc_start (ohci_t * ohci)
  1210. {
  1211. __u32 mask;
  1212. unsigned int fminterval;
  1213. ohci->disabled = 1;
  1214. /* Tell the controller where the control and bulk lists are
  1215. * The lists are empty now. */
  1216. writel (0, &ohci->regs->ed_controlhead);
  1217. writel (0, &ohci->regs->ed_bulkhead);
  1218. writel ((__u32)ohci->hcca, &ohci->regs->hcca); /* a reset clears this */
  1219. fminterval = 0x2edf;
  1220. writel ((fminterval * 9) / 10, &ohci->regs->periodicstart);
  1221. fminterval |= ((((fminterval - 210) * 6) / 7) << 16);
  1222. writel (fminterval, &ohci->regs->fminterval);
  1223. writel (0x628, &ohci->regs->lsthresh);
  1224. /* start controller operations */
  1225. ohci->hc_control = OHCI_CONTROL_INIT | OHCI_USB_OPER;
  1226. ohci->disabled = 0;
  1227. writel (ohci->hc_control, &ohci->regs->control);
  1228. /* disable all interrupts */
  1229. mask = (OHCI_INTR_SO | OHCI_INTR_WDH | OHCI_INTR_SF | OHCI_INTR_RD |
  1230. OHCI_INTR_UE | OHCI_INTR_FNO | OHCI_INTR_RHSC |
  1231. OHCI_INTR_OC | OHCI_INTR_MIE);
  1232. writel (mask, &ohci->regs->intrdisable);
  1233. /* clear all interrupts */
  1234. mask &= ~OHCI_INTR_MIE;
  1235. writel (mask, &ohci->regs->intrstatus);
  1236. /* Choose the interrupts we care about now - but w/o MIE */
  1237. mask = OHCI_INTR_RHSC | OHCI_INTR_UE | OHCI_INTR_WDH | OHCI_INTR_SO;
  1238. writel (mask, &ohci->regs->intrenable);
  1239. #ifdef OHCI_USE_NPS
  1240. /* required for AMD-756 and some Mac platforms */
  1241. writel ((roothub_a (ohci) | RH_A_NPS) & ~RH_A_PSM,
  1242. &ohci->regs->roothub.a);
  1243. writel (RH_HS_LPSC, &ohci->regs->roothub.status);
  1244. #endif /* OHCI_USE_NPS */
  1245. /* POTPGT delay is bits 24-31, in 2 ms units. */
  1246. mdelay ((roothub_a (ohci) >> 23) & 0x1fe);
  1247. /* connect the virtual root hub */
  1248. ohci->rh.devnum = 0;
  1249. return 0;
  1250. }
  1251. /*-------------------------------------------------------------------------*/
  1252. /* an interrupt happens */
  1253. static int
  1254. hc_interrupt (void)
  1255. {
  1256. ohci_t *ohci = &gohci;
  1257. struct ohci_regs *regs = ohci->regs;
  1258. int ints;
  1259. int stat = -1;
  1260. if ((ohci->hcca->done_head != 0) && !(m32_swap (ohci->hcca->done_head) & 0x01)) {
  1261. ints = OHCI_INTR_WDH;
  1262. } else {
  1263. ints = readl (&regs->intrstatus);
  1264. }
  1265. /* dbg("Interrupt: %x frame: %x", ints, le16_to_cpu (ohci->hcca->frame_no)); */
  1266. if (ints & OHCI_INTR_RHSC) {
  1267. got_rhsc = 1;
  1268. }
  1269. if (ints & OHCI_INTR_UE) {
  1270. ohci->disabled++;
  1271. err ("OHCI Unrecoverable Error, controller usb-%s disabled",
  1272. ohci->slot_name);
  1273. /* e.g. due to PCI Master/Target Abort */
  1274. #ifdef DEBUG
  1275. ohci_dump (ohci, 1);
  1276. #else
  1277. wait_ms(1);
  1278. #endif
  1279. /* FIXME: be optimistic, hope that bug won't repeat often. */
  1280. /* Make some non-interrupt context restart the controller. */
  1281. /* Count and limit the retries though; either hardware or */
  1282. /* software errors can go forever... */
  1283. hc_reset (ohci);
  1284. return -1;
  1285. }
  1286. if (ints & OHCI_INTR_WDH) {
  1287. wait_ms(1);
  1288. writel (OHCI_INTR_WDH, &regs->intrdisable);
  1289. stat = dl_done_list (&gohci, dl_reverse_done_list (&gohci));
  1290. writel (OHCI_INTR_WDH, &regs->intrenable);
  1291. }
  1292. if (ints & OHCI_INTR_SO) {
  1293. dbg("USB Schedule overrun\n");
  1294. writel (OHCI_INTR_SO, &regs->intrenable);
  1295. stat = -1;
  1296. }
  1297. /* FIXME: this assumes SOF (1/ms) interrupts don't get lost... */
  1298. if (ints & OHCI_INTR_SF) {
  1299. unsigned int frame = m16_swap (ohci->hcca->frame_no) & 1;
  1300. wait_ms(1);
  1301. writel (OHCI_INTR_SF, &regs->intrdisable);
  1302. if (ohci->ed_rm_list[frame] != NULL)
  1303. writel (OHCI_INTR_SF, &regs->intrenable);
  1304. stat = 0xff;
  1305. }
  1306. writel (ints, &regs->intrstatus);
  1307. return stat;
  1308. }
  1309. /*-------------------------------------------------------------------------*/
  1310. /*-------------------------------------------------------------------------*/
  1311. /* De-allocate all resources.. */
  1312. static void hc_release_ohci (ohci_t *ohci)
  1313. {
  1314. dbg ("USB HC release ohci usb-%s", ohci->slot_name);
  1315. if (!ohci->disabled)
  1316. hc_reset (ohci);
  1317. }
  1318. /*-------------------------------------------------------------------------*/
  1319. #define __read_32bit_c0_register(source, sel) \
  1320. ({ int __res; \
  1321. if (sel == 0) \
  1322. __asm__ __volatile__( \
  1323. "mfc0\t%0, " #source "\n\t" \
  1324. : "=r" (__res)); \
  1325. else \
  1326. __asm__ __volatile__( \
  1327. ".set\tmips32\n\t" \
  1328. "mfc0\t%0, " #source ", " #sel "\n\t" \
  1329. ".set\tmips0\n\t" \
  1330. : "=r" (__res)); \
  1331. __res; \
  1332. })
  1333. #define read_c0_prid() __read_32bit_c0_register($15, 0)
  1334. /*
  1335. * low level initalisation routine, called from usb.c
  1336. */
  1337. static char ohci_inited = 0;
  1338. int usb_lowlevel_init(void)
  1339. {
  1340. u32 pin_func;
  1341. u32 sys_freqctrl, sys_clksrc;
  1342. u32 prid = read_c0_prid();
  1343. dbg("in usb_lowlevel_init\n");
  1344. /* zero and disable FREQ2 */
  1345. sys_freqctrl = au_readl(SYS_FREQCTRL0);
  1346. sys_freqctrl &= ~0xFFF00000;
  1347. au_writel(sys_freqctrl, SYS_FREQCTRL0);
  1348. /* zero and disable USBH/USBD clocks */
  1349. sys_clksrc = au_readl(SYS_CLKSRC);
  1350. sys_clksrc &= ~0x00007FE0;
  1351. au_writel(sys_clksrc, SYS_CLKSRC);
  1352. sys_freqctrl = au_readl(SYS_FREQCTRL0);
  1353. sys_freqctrl &= ~0xFFF00000;
  1354. sys_clksrc = au_readl(SYS_CLKSRC);
  1355. sys_clksrc &= ~0x00007FE0;
  1356. switch (prid & 0x000000FF) {
  1357. case 0x00: /* DA */
  1358. case 0x01: /* HA */
  1359. case 0x02: /* HB */
  1360. /* CPU core freq to 48MHz to slow it way down... */
  1361. au_writel(4, SYS_CPUPLL);
  1362. /*
  1363. * Setup 48MHz FREQ2 from CPUPLL for USB Host
  1364. */
  1365. /* FRDIV2=3 -> div by 8 of 384MHz -> 48MHz */
  1366. sys_freqctrl |= ((3<<22) | (1<<21) | (0<<20));
  1367. au_writel(sys_freqctrl, SYS_FREQCTRL0);
  1368. /* CPU core freq to 384MHz */
  1369. au_writel(0x20, SYS_CPUPLL);
  1370. printf("Au1000: 48MHz OHCI workaround enabled\n");
  1371. break;
  1372. default: /* HC and newer */
  1373. /* FREQ2 = aux/2 = 48 MHz */
  1374. sys_freqctrl |= ((0<<22) | (1<<21) | (1<<20));
  1375. au_writel(sys_freqctrl, SYS_FREQCTRL0);
  1376. break;
  1377. }
  1378. /*
  1379. * Route 48MHz FREQ2 into USB Host and/or Device
  1380. */
  1381. sys_clksrc |= ((4<<12) | (0<<11) | (0<<10));
  1382. au_writel(sys_clksrc, SYS_CLKSRC);
  1383. /* configure pins GPIO[14:9] as GPIO */
  1384. pin_func = au_readl(SYS_PINFUNC) & (u32)(~0x8080);
  1385. au_writel(pin_func, SYS_PINFUNC);
  1386. au_writel(0x2800, SYS_TRIOUTCLR);
  1387. au_writel(0x0030, SYS_OUTPUTCLR);
  1388. dbg("OHCI board setup complete\n");
  1389. /* enable host controller */
  1390. au_writel(USBH_ENABLE_CE, USB_HOST_CONFIG);
  1391. udelay(1000);
  1392. au_writel(USBH_ENABLE_INIT, USB_HOST_CONFIG);
  1393. udelay(1000);
  1394. /* wait for reset complete (read register twice; see au1500 errata) */
  1395. while (au_readl(USB_HOST_CONFIG),
  1396. !(au_readl(USB_HOST_CONFIG) & USBH_ENABLE_RD))
  1397. udelay(1000);
  1398. dbg("OHCI clock running\n");
  1399. memset (&gohci, 0, sizeof (ohci_t));
  1400. memset (&urb_priv, 0, sizeof (urb_priv_t));
  1401. /* align the storage */
  1402. if ((__u32)&ghcca[0] & 0xff) {
  1403. err("HCCA not aligned!!");
  1404. return -1;
  1405. }
  1406. phcca = &ghcca[0];
  1407. info("aligned ghcca %p", phcca);
  1408. memset(&ohci_dev, 0, sizeof(struct ohci_device));
  1409. if ((__u32)&ohci_dev.ed[0] & 0x7) {
  1410. err("EDs not aligned!!");
  1411. return -1;
  1412. }
  1413. memset(gtd, 0, sizeof(td_t) * (NUM_TD + 1));
  1414. if ((__u32)gtd & 0x7) {
  1415. err("TDs not aligned!!");
  1416. return -1;
  1417. }
  1418. ptd = gtd;
  1419. gohci.hcca = phcca;
  1420. memset (phcca, 0, sizeof (struct ohci_hcca));
  1421. gohci.disabled = 1;
  1422. gohci.sleeping = 0;
  1423. gohci.irq = -1;
  1424. gohci.regs = (struct ohci_regs *)(USB_OHCI_BASE | 0xA0000000);
  1425. gohci.flags = 0;
  1426. gohci.slot_name = "au1x00";
  1427. dbg("OHCI revision: 0x%08x\n"
  1428. " RH: a: 0x%08x b: 0x%08x\n",
  1429. readl(&gohci.regs->revision),
  1430. readl(&gohci.regs->roothub.a), readl(&gohci.regs->roothub.b));
  1431. if (hc_reset (&gohci) < 0)
  1432. goto errout;
  1433. /* FIXME this is a second HC reset; why?? */
  1434. writel (gohci.hc_control = OHCI_USB_RESET, &gohci.regs->control);
  1435. wait_ms (10);
  1436. if (hc_start (&gohci) < 0)
  1437. goto errout;
  1438. #ifdef DEBUG
  1439. ohci_dump (&gohci, 1);
  1440. #else
  1441. wait_ms(1);
  1442. #endif
  1443. ohci_inited = 1;
  1444. return 0;
  1445. errout:
  1446. err("OHCI initialization error\n");
  1447. hc_release_ohci (&gohci);
  1448. /* Initialization failed */
  1449. au_writel(readl(USB_HOST_CONFIG) & ~USBH_ENABLE_CE, USB_HOST_CONFIG);
  1450. return -1;
  1451. }
  1452. int usb_lowlevel_stop(void)
  1453. {
  1454. /* this gets called really early - before the controller has */
  1455. /* even been initialized! */
  1456. if (!ohci_inited)
  1457. return 0;
  1458. /* TODO release any interrupts, etc. */
  1459. /* call hc_release_ohci() here ? */
  1460. hc_reset (&gohci);
  1461. /* may not want to do this */
  1462. /* Disable clock */
  1463. au_writel(readl(USB_HOST_CONFIG) & ~USBH_ENABLE_CE, USB_HOST_CONFIG);
  1464. return 0;
  1465. }
  1466. #endif /* CONFIG_USB_OHCI */