au1x00_usb_ohci.c 45 KB

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