isp1362-hcd.c 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883
  1. /*
  2. * ISP1362 HCD (Host Controller Driver) for USB.
  3. *
  4. * Copyright (C) 2005 Lothar Wassmann <LW@KARO-electronics.de>
  5. *
  6. * Derived from the SL811 HCD, rewritten for ISP116x.
  7. * Copyright (C) 2005 Olav Kongas <ok@artecdesign.ee>
  8. *
  9. * Portions:
  10. * Copyright (C) 2004 Psion Teklogix (for NetBook PRO)
  11. * Copyright (C) 2004 David Brownell
  12. */
  13. /*
  14. * The ISP1362 chip requires a large delay (300ns and 462ns) between
  15. * accesses to the address and data register.
  16. * The following timing options exist:
  17. *
  18. * 1. Configure your memory controller to add such delays if it can (the best)
  19. * 2. Implement platform-specific delay function possibly
  20. * combined with configuring the memory controller; see
  21. * include/linux/usb_isp1362.h for more info.
  22. * 3. Use ndelay (easiest, poorest).
  23. *
  24. * Use the corresponding macros USE_PLATFORM_DELAY and USE_NDELAY in the
  25. * platform specific section of isp1362.h to select the appropriate variant.
  26. *
  27. * Also note that according to the Philips "ISP1362 Errata" document
  28. * Rev 1.00 from 27 May data corruption may occur when the #WR signal
  29. * is reasserted (even with #CS deasserted) within 132ns after a
  30. * write cycle to any controller register. If the hardware doesn't
  31. * implement the recommended fix (gating the #WR with #CS) software
  32. * must ensure that no further write cycle (not necessarily to the chip!)
  33. * is issued by the CPU within this interval.
  34. * For PXA25x this can be ensured by using VLIO with the maximum
  35. * recovery time (MSCx = 0x7f8c) with a memory clock of 99.53 MHz.
  36. */
  37. #ifdef CONFIG_USB_DEBUG
  38. # define ISP1362_DEBUG
  39. #else
  40. # undef ISP1362_DEBUG
  41. #endif
  42. /*
  43. * The PXA255 UDC apparently doesn't handle GET_STATUS, GET_CONFIG and
  44. * GET_INTERFACE requests correctly when the SETUP and DATA stages of the
  45. * requests are carried out in separate frames. This will delay any SETUP
  46. * packets until the start of the next frame so that this situation is
  47. * unlikely to occur (and makes usbtest happy running with a PXA255 target
  48. * device).
  49. */
  50. #undef BUGGY_PXA2XX_UDC_USBTEST
  51. #undef PTD_TRACE
  52. #undef URB_TRACE
  53. #undef VERBOSE
  54. #undef REGISTERS
  55. /* This enables a memory test on the ISP1362 chip memory to make sure the
  56. * chip access timing is correct.
  57. */
  58. #undef CHIP_BUFFER_TEST
  59. #include <linux/module.h>
  60. #include <linux/moduleparam.h>
  61. #include <linux/kernel.h>
  62. #include <linux/delay.h>
  63. #include <linux/ioport.h>
  64. #include <linux/sched.h>
  65. #include <linux/slab.h>
  66. #include <linux/errno.h>
  67. #include <linux/init.h>
  68. #include <linux/list.h>
  69. #include <linux/interrupt.h>
  70. #include <linux/usb.h>
  71. #include <linux/usb/isp1362.h>
  72. #include <linux/usb/hcd.h>
  73. #include <linux/platform_device.h>
  74. #include <linux/pm.h>
  75. #include <linux/io.h>
  76. #include <linux/bitmap.h>
  77. #include <linux/prefetch.h>
  78. #include <asm/irq.h>
  79. #include <asm/system.h>
  80. #include <asm/byteorder.h>
  81. #include <asm/unaligned.h>
  82. static int dbg_level;
  83. #ifdef ISP1362_DEBUG
  84. module_param(dbg_level, int, 0644);
  85. #else
  86. module_param(dbg_level, int, 0);
  87. #define STUB_DEBUG_FILE
  88. #endif
  89. #include "../core/usb.h"
  90. #include "isp1362.h"
  91. #define DRIVER_VERSION "2005-04-04"
  92. #define DRIVER_DESC "ISP1362 USB Host Controller Driver"
  93. MODULE_DESCRIPTION(DRIVER_DESC);
  94. MODULE_LICENSE("GPL");
  95. static const char hcd_name[] = "isp1362-hcd";
  96. static void isp1362_hc_stop(struct usb_hcd *hcd);
  97. static int isp1362_hc_start(struct usb_hcd *hcd);
  98. /*-------------------------------------------------------------------------*/
  99. /*
  100. * When called from the interrupthandler only isp1362_hcd->irqenb is modified,
  101. * since the interrupt handler will write isp1362_hcd->irqenb to HCuPINT upon
  102. * completion.
  103. * We don't need a 'disable' counterpart, since interrupts will be disabled
  104. * only by the interrupt handler.
  105. */
  106. static inline void isp1362_enable_int(struct isp1362_hcd *isp1362_hcd, u16 mask)
  107. {
  108. if ((isp1362_hcd->irqenb | mask) == isp1362_hcd->irqenb)
  109. return;
  110. if (mask & ~isp1362_hcd->irqenb)
  111. isp1362_write_reg16(isp1362_hcd, HCuPINT, mask & ~isp1362_hcd->irqenb);
  112. isp1362_hcd->irqenb |= mask;
  113. if (isp1362_hcd->irq_active)
  114. return;
  115. isp1362_write_reg16(isp1362_hcd, HCuPINTENB, isp1362_hcd->irqenb);
  116. }
  117. /*-------------------------------------------------------------------------*/
  118. static inline struct isp1362_ep_queue *get_ptd_queue(struct isp1362_hcd *isp1362_hcd,
  119. u16 offset)
  120. {
  121. struct isp1362_ep_queue *epq = NULL;
  122. if (offset < isp1362_hcd->istl_queue[1].buf_start)
  123. epq = &isp1362_hcd->istl_queue[0];
  124. else if (offset < isp1362_hcd->intl_queue.buf_start)
  125. epq = &isp1362_hcd->istl_queue[1];
  126. else if (offset < isp1362_hcd->atl_queue.buf_start)
  127. epq = &isp1362_hcd->intl_queue;
  128. else if (offset < isp1362_hcd->atl_queue.buf_start +
  129. isp1362_hcd->atl_queue.buf_size)
  130. epq = &isp1362_hcd->atl_queue;
  131. if (epq)
  132. DBG(1, "%s: PTD $%04x is on %s queue\n", __func__, offset, epq->name);
  133. else
  134. pr_warning("%s: invalid PTD $%04x\n", __func__, offset);
  135. return epq;
  136. }
  137. static inline int get_ptd_offset(struct isp1362_ep_queue *epq, u8 index)
  138. {
  139. int offset;
  140. if (index * epq->blk_size > epq->buf_size) {
  141. pr_warning("%s: Bad %s index %d(%d)\n", __func__, epq->name, index,
  142. epq->buf_size / epq->blk_size);
  143. return -EINVAL;
  144. }
  145. offset = epq->buf_start + index * epq->blk_size;
  146. DBG(3, "%s: %s PTD[%02x] # %04x\n", __func__, epq->name, index, offset);
  147. return offset;
  148. }
  149. /*-------------------------------------------------------------------------*/
  150. static inline u16 max_transfer_size(struct isp1362_ep_queue *epq, size_t size,
  151. int mps)
  152. {
  153. u16 xfer_size = min_t(size_t, MAX_XFER_SIZE, size);
  154. xfer_size = min_t(size_t, xfer_size, epq->buf_avail * epq->blk_size - PTD_HEADER_SIZE);
  155. if (xfer_size < size && xfer_size % mps)
  156. xfer_size -= xfer_size % mps;
  157. return xfer_size;
  158. }
  159. static int claim_ptd_buffers(struct isp1362_ep_queue *epq,
  160. struct isp1362_ep *ep, u16 len)
  161. {
  162. int ptd_offset = -EINVAL;
  163. int num_ptds = ((len + PTD_HEADER_SIZE - 1) / epq->blk_size) + 1;
  164. int found;
  165. BUG_ON(len > epq->buf_size);
  166. if (!epq->buf_avail)
  167. return -ENOMEM;
  168. if (ep->num_ptds)
  169. pr_err("%s: %s len %d/%d num_ptds %d buf_map %08lx skip_map %08lx\n", __func__,
  170. epq->name, len, epq->blk_size, num_ptds, epq->buf_map, epq->skip_map);
  171. BUG_ON(ep->num_ptds != 0);
  172. found = bitmap_find_next_zero_area(&epq->buf_map, epq->buf_count, 0,
  173. num_ptds, 0);
  174. if (found >= epq->buf_count)
  175. return -EOVERFLOW;
  176. DBG(1, "%s: Found %d PTDs[%d] for %d/%d byte\n", __func__,
  177. num_ptds, found, len, (int)(epq->blk_size - PTD_HEADER_SIZE));
  178. ptd_offset = get_ptd_offset(epq, found);
  179. WARN_ON(ptd_offset < 0);
  180. ep->ptd_offset = ptd_offset;
  181. ep->num_ptds += num_ptds;
  182. epq->buf_avail -= num_ptds;
  183. BUG_ON(epq->buf_avail > epq->buf_count);
  184. ep->ptd_index = found;
  185. bitmap_set(&epq->buf_map, found, num_ptds);
  186. DBG(1, "%s: Done %s PTD[%d] $%04x, avail %d count %d claimed %d %08lx:%08lx\n",
  187. __func__, epq->name, ep->ptd_index, ep->ptd_offset,
  188. epq->buf_avail, epq->buf_count, num_ptds, epq->buf_map, epq->skip_map);
  189. return found;
  190. }
  191. static inline void release_ptd_buffers(struct isp1362_ep_queue *epq, struct isp1362_ep *ep)
  192. {
  193. int last = ep->ptd_index + ep->num_ptds;
  194. if (last > epq->buf_count)
  195. pr_err("%s: ep %p req %d len %d %s PTD[%d] $%04x num_ptds %d buf_count %d buf_avail %d buf_map %08lx skip_map %08lx\n",
  196. __func__, ep, ep->num_req, ep->length, epq->name, ep->ptd_index,
  197. ep->ptd_offset, ep->num_ptds, epq->buf_count, epq->buf_avail,
  198. epq->buf_map, epq->skip_map);
  199. BUG_ON(last > epq->buf_count);
  200. bitmap_clear(&epq->buf_map, ep->ptd_index, ep->num_ptds);
  201. bitmap_set(&epq->skip_map, ep->ptd_index, ep->num_ptds);
  202. epq->buf_avail += ep->num_ptds;
  203. epq->ptd_count--;
  204. BUG_ON(epq->buf_avail > epq->buf_count);
  205. BUG_ON(epq->ptd_count > epq->buf_count);
  206. DBG(1, "%s: Done %s PTDs $%04x released %d avail %d count %d\n",
  207. __func__, epq->name,
  208. ep->ptd_offset, ep->num_ptds, epq->buf_avail, epq->buf_count);
  209. DBG(1, "%s: buf_map %08lx skip_map %08lx\n", __func__,
  210. epq->buf_map, epq->skip_map);
  211. ep->num_ptds = 0;
  212. ep->ptd_offset = -EINVAL;
  213. ep->ptd_index = -EINVAL;
  214. }
  215. /*-------------------------------------------------------------------------*/
  216. /*
  217. Set up PTD's.
  218. */
  219. static void prepare_ptd(struct isp1362_hcd *isp1362_hcd, struct urb *urb,
  220. struct isp1362_ep *ep, struct isp1362_ep_queue *epq,
  221. u16 fno)
  222. {
  223. struct ptd *ptd;
  224. int toggle;
  225. int dir;
  226. u16 len;
  227. size_t buf_len = urb->transfer_buffer_length - urb->actual_length;
  228. DBG(3, "%s: %s ep %p\n", __func__, epq->name, ep);
  229. ptd = &ep->ptd;
  230. ep->data = (unsigned char *)urb->transfer_buffer + urb->actual_length;
  231. switch (ep->nextpid) {
  232. case USB_PID_IN:
  233. toggle = usb_gettoggle(urb->dev, ep->epnum, 0);
  234. dir = PTD_DIR_IN;
  235. if (usb_pipecontrol(urb->pipe)) {
  236. len = min_t(size_t, ep->maxpacket, buf_len);
  237. } else if (usb_pipeisoc(urb->pipe)) {
  238. len = min_t(size_t, urb->iso_frame_desc[fno].length, MAX_XFER_SIZE);
  239. ep->data = urb->transfer_buffer + urb->iso_frame_desc[fno].offset;
  240. } else
  241. len = max_transfer_size(epq, buf_len, ep->maxpacket);
  242. DBG(1, "%s: IN len %d/%d/%d from URB\n", __func__, len, ep->maxpacket,
  243. (int)buf_len);
  244. break;
  245. case USB_PID_OUT:
  246. toggle = usb_gettoggle(urb->dev, ep->epnum, 1);
  247. dir = PTD_DIR_OUT;
  248. if (usb_pipecontrol(urb->pipe))
  249. len = min_t(size_t, ep->maxpacket, buf_len);
  250. else if (usb_pipeisoc(urb->pipe))
  251. len = min_t(size_t, urb->iso_frame_desc[0].length, MAX_XFER_SIZE);
  252. else
  253. len = max_transfer_size(epq, buf_len, ep->maxpacket);
  254. if (len == 0)
  255. pr_info("%s: Sending ZERO packet: %d\n", __func__,
  256. urb->transfer_flags & URB_ZERO_PACKET);
  257. DBG(1, "%s: OUT len %d/%d/%d from URB\n", __func__, len, ep->maxpacket,
  258. (int)buf_len);
  259. break;
  260. case USB_PID_SETUP:
  261. toggle = 0;
  262. dir = PTD_DIR_SETUP;
  263. len = sizeof(struct usb_ctrlrequest);
  264. DBG(1, "%s: SETUP len %d\n", __func__, len);
  265. ep->data = urb->setup_packet;
  266. break;
  267. case USB_PID_ACK:
  268. toggle = 1;
  269. len = 0;
  270. dir = (urb->transfer_buffer_length && usb_pipein(urb->pipe)) ?
  271. PTD_DIR_OUT : PTD_DIR_IN;
  272. DBG(1, "%s: ACK len %d\n", __func__, len);
  273. break;
  274. default:
  275. toggle = dir = len = 0;
  276. pr_err("%s@%d: ep->nextpid %02x\n", __func__, __LINE__, ep->nextpid);
  277. BUG_ON(1);
  278. }
  279. ep->length = len;
  280. if (!len)
  281. ep->data = NULL;
  282. ptd->count = PTD_CC_MSK | PTD_ACTIVE_MSK | PTD_TOGGLE(toggle);
  283. ptd->mps = PTD_MPS(ep->maxpacket) | PTD_SPD(urb->dev->speed == USB_SPEED_LOW) |
  284. PTD_EP(ep->epnum);
  285. ptd->len = PTD_LEN(len) | PTD_DIR(dir);
  286. ptd->faddr = PTD_FA(usb_pipedevice(urb->pipe));
  287. if (usb_pipeint(urb->pipe)) {
  288. ptd->faddr |= PTD_SF_INT(ep->branch);
  289. ptd->faddr |= PTD_PR(ep->interval ? __ffs(ep->interval) : 0);
  290. }
  291. if (usb_pipeisoc(urb->pipe))
  292. ptd->faddr |= PTD_SF_ISO(fno);
  293. DBG(1, "%s: Finished\n", __func__);
  294. }
  295. static void isp1362_write_ptd(struct isp1362_hcd *isp1362_hcd, struct isp1362_ep *ep,
  296. struct isp1362_ep_queue *epq)
  297. {
  298. struct ptd *ptd = &ep->ptd;
  299. int len = PTD_GET_DIR(ptd) == PTD_DIR_IN ? 0 : ep->length;
  300. _BUG_ON(ep->ptd_offset < 0);
  301. prefetch(ptd);
  302. isp1362_write_buffer(isp1362_hcd, ptd, ep->ptd_offset, PTD_HEADER_SIZE);
  303. if (len)
  304. isp1362_write_buffer(isp1362_hcd, ep->data,
  305. ep->ptd_offset + PTD_HEADER_SIZE, len);
  306. dump_ptd(ptd);
  307. dump_ptd_out_data(ptd, ep->data);
  308. }
  309. static void isp1362_read_ptd(struct isp1362_hcd *isp1362_hcd, struct isp1362_ep *ep,
  310. struct isp1362_ep_queue *epq)
  311. {
  312. struct ptd *ptd = &ep->ptd;
  313. int act_len;
  314. WARN_ON(list_empty(&ep->active));
  315. BUG_ON(ep->ptd_offset < 0);
  316. list_del_init(&ep->active);
  317. DBG(1, "%s: ep %p removed from active list %p\n", __func__, ep, &epq->active);
  318. prefetchw(ptd);
  319. isp1362_read_buffer(isp1362_hcd, ptd, ep->ptd_offset, PTD_HEADER_SIZE);
  320. dump_ptd(ptd);
  321. act_len = PTD_GET_COUNT(ptd);
  322. if (PTD_GET_DIR(ptd) != PTD_DIR_IN || act_len == 0)
  323. return;
  324. if (act_len > ep->length)
  325. pr_err("%s: ep %p PTD $%04x act_len %d ep->length %d\n", __func__, ep,
  326. ep->ptd_offset, act_len, ep->length);
  327. BUG_ON(act_len > ep->length);
  328. /* Only transfer the amount of data that has actually been overwritten
  329. * in the chip buffer. We don't want any data that doesn't belong to the
  330. * transfer to leak out of the chip to the callers transfer buffer!
  331. */
  332. prefetchw(ep->data);
  333. isp1362_read_buffer(isp1362_hcd, ep->data,
  334. ep->ptd_offset + PTD_HEADER_SIZE, act_len);
  335. dump_ptd_in_data(ptd, ep->data);
  336. }
  337. /*
  338. * INT PTDs will stay in the chip until data is available.
  339. * This function will remove a PTD from the chip when the URB is dequeued.
  340. * Must be called with the spinlock held and IRQs disabled
  341. */
  342. static void remove_ptd(struct isp1362_hcd *isp1362_hcd, struct isp1362_ep *ep)
  343. {
  344. int index;
  345. struct isp1362_ep_queue *epq;
  346. DBG(1, "%s: ep %p PTD[%d] $%04x\n", __func__, ep, ep->ptd_index, ep->ptd_offset);
  347. BUG_ON(ep->ptd_offset < 0);
  348. epq = get_ptd_queue(isp1362_hcd, ep->ptd_offset);
  349. BUG_ON(!epq);
  350. /* put ep in remove_list for cleanup */
  351. WARN_ON(!list_empty(&ep->remove_list));
  352. list_add_tail(&ep->remove_list, &isp1362_hcd->remove_list);
  353. /* let SOF interrupt handle the cleanup */
  354. isp1362_enable_int(isp1362_hcd, HCuPINT_SOF);
  355. index = ep->ptd_index;
  356. if (index < 0)
  357. /* ISO queues don't have SKIP registers */
  358. return;
  359. DBG(1, "%s: Disabling PTD[%02x] $%04x %08lx|%08x\n", __func__,
  360. index, ep->ptd_offset, epq->skip_map, 1 << index);
  361. /* prevent further processing of PTD (will be effective after next SOF) */
  362. epq->skip_map |= 1 << index;
  363. if (epq == &isp1362_hcd->atl_queue) {
  364. DBG(2, "%s: ATLSKIP = %08x -> %08lx\n", __func__,
  365. isp1362_read_reg32(isp1362_hcd, HCATLSKIP), epq->skip_map);
  366. isp1362_write_reg32(isp1362_hcd, HCATLSKIP, epq->skip_map);
  367. if (~epq->skip_map == 0)
  368. isp1362_clr_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_ATL_ACTIVE);
  369. } else if (epq == &isp1362_hcd->intl_queue) {
  370. DBG(2, "%s: INTLSKIP = %08x -> %08lx\n", __func__,
  371. isp1362_read_reg32(isp1362_hcd, HCINTLSKIP), epq->skip_map);
  372. isp1362_write_reg32(isp1362_hcd, HCINTLSKIP, epq->skip_map);
  373. if (~epq->skip_map == 0)
  374. isp1362_clr_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_INTL_ACTIVE);
  375. }
  376. }
  377. /*
  378. Take done or failed requests out of schedule. Give back
  379. processed urbs.
  380. */
  381. static void finish_request(struct isp1362_hcd *isp1362_hcd, struct isp1362_ep *ep,
  382. struct urb *urb, int status)
  383. __releases(isp1362_hcd->lock)
  384. __acquires(isp1362_hcd->lock)
  385. {
  386. urb->hcpriv = NULL;
  387. ep->error_count = 0;
  388. if (usb_pipecontrol(urb->pipe))
  389. ep->nextpid = USB_PID_SETUP;
  390. URB_DBG("%s: req %d FA %d ep%d%s %s: len %d/%d %s stat %d\n", __func__,
  391. ep->num_req, usb_pipedevice(urb->pipe),
  392. usb_pipeendpoint(urb->pipe),
  393. !usb_pipein(urb->pipe) ? "out" : "in",
  394. usb_pipecontrol(urb->pipe) ? "ctrl" :
  395. usb_pipeint(urb->pipe) ? "int" :
  396. usb_pipebulk(urb->pipe) ? "bulk" :
  397. "iso",
  398. urb->actual_length, urb->transfer_buffer_length,
  399. !(urb->transfer_flags & URB_SHORT_NOT_OK) ?
  400. "short_ok" : "", urb->status);
  401. usb_hcd_unlink_urb_from_ep(isp1362_hcd_to_hcd(isp1362_hcd), urb);
  402. spin_unlock(&isp1362_hcd->lock);
  403. usb_hcd_giveback_urb(isp1362_hcd_to_hcd(isp1362_hcd), urb, status);
  404. spin_lock(&isp1362_hcd->lock);
  405. /* take idle endpoints out of the schedule right away */
  406. if (!list_empty(&ep->hep->urb_list))
  407. return;
  408. /* async deschedule */
  409. if (!list_empty(&ep->schedule)) {
  410. list_del_init(&ep->schedule);
  411. return;
  412. }
  413. if (ep->interval) {
  414. /* periodic deschedule */
  415. DBG(1, "deschedule qh%d/%p branch %d load %d bandwidth %d -> %d\n", ep->interval,
  416. ep, ep->branch, ep->load,
  417. isp1362_hcd->load[ep->branch],
  418. isp1362_hcd->load[ep->branch] - ep->load);
  419. isp1362_hcd->load[ep->branch] -= ep->load;
  420. ep->branch = PERIODIC_SIZE;
  421. }
  422. }
  423. /*
  424. * Analyze transfer results, handle partial transfers and errors
  425. */
  426. static void postproc_ep(struct isp1362_hcd *isp1362_hcd, struct isp1362_ep *ep)
  427. {
  428. struct urb *urb = get_urb(ep);
  429. struct usb_device *udev;
  430. struct ptd *ptd;
  431. int short_ok;
  432. u16 len;
  433. int urbstat = -EINPROGRESS;
  434. u8 cc;
  435. DBG(2, "%s: ep %p req %d\n", __func__, ep, ep->num_req);
  436. udev = urb->dev;
  437. ptd = &ep->ptd;
  438. cc = PTD_GET_CC(ptd);
  439. if (cc == PTD_NOTACCESSED) {
  440. pr_err("%s: req %d PTD %p Untouched by ISP1362\n", __func__,
  441. ep->num_req, ptd);
  442. cc = PTD_DEVNOTRESP;
  443. }
  444. short_ok = !(urb->transfer_flags & URB_SHORT_NOT_OK);
  445. len = urb->transfer_buffer_length - urb->actual_length;
  446. /* Data underrun is special. For allowed underrun
  447. we clear the error and continue as normal. For
  448. forbidden underrun we finish the DATA stage
  449. immediately while for control transfer,
  450. we do a STATUS stage.
  451. */
  452. if (cc == PTD_DATAUNDERRUN) {
  453. if (short_ok) {
  454. DBG(1, "%s: req %d Allowed data underrun short_%sok %d/%d/%d byte\n",
  455. __func__, ep->num_req, short_ok ? "" : "not_",
  456. PTD_GET_COUNT(ptd), ep->maxpacket, len);
  457. cc = PTD_CC_NOERROR;
  458. urbstat = 0;
  459. } else {
  460. DBG(1, "%s: req %d Data Underrun %s nextpid %02x short_%sok %d/%d/%d byte\n",
  461. __func__, ep->num_req,
  462. usb_pipein(urb->pipe) ? "IN" : "OUT", ep->nextpid,
  463. short_ok ? "" : "not_",
  464. PTD_GET_COUNT(ptd), ep->maxpacket, len);
  465. if (usb_pipecontrol(urb->pipe)) {
  466. ep->nextpid = USB_PID_ACK;
  467. /* save the data underrun error code for later and
  468. * proceed with the status stage
  469. */
  470. urb->actual_length += PTD_GET_COUNT(ptd);
  471. BUG_ON(urb->actual_length > urb->transfer_buffer_length);
  472. if (urb->status == -EINPROGRESS)
  473. urb->status = cc_to_error[PTD_DATAUNDERRUN];
  474. } else {
  475. usb_settoggle(udev, ep->epnum, ep->nextpid == USB_PID_OUT,
  476. PTD_GET_TOGGLE(ptd));
  477. urbstat = cc_to_error[PTD_DATAUNDERRUN];
  478. }
  479. goto out;
  480. }
  481. }
  482. if (cc != PTD_CC_NOERROR) {
  483. if (++ep->error_count >= 3 || cc == PTD_CC_STALL || cc == PTD_DATAOVERRUN) {
  484. urbstat = cc_to_error[cc];
  485. DBG(1, "%s: req %d nextpid %02x, status %d, error %d, error_count %d\n",
  486. __func__, ep->num_req, ep->nextpid, urbstat, cc,
  487. ep->error_count);
  488. }
  489. goto out;
  490. }
  491. switch (ep->nextpid) {
  492. case USB_PID_OUT:
  493. if (PTD_GET_COUNT(ptd) != ep->length)
  494. pr_err("%s: count=%d len=%d\n", __func__,
  495. PTD_GET_COUNT(ptd), ep->length);
  496. BUG_ON(PTD_GET_COUNT(ptd) != ep->length);
  497. urb->actual_length += ep->length;
  498. BUG_ON(urb->actual_length > urb->transfer_buffer_length);
  499. usb_settoggle(udev, ep->epnum, 1, PTD_GET_TOGGLE(ptd));
  500. if (urb->actual_length == urb->transfer_buffer_length) {
  501. DBG(3, "%s: req %d xfer complete %d/%d status %d -> 0\n", __func__,
  502. ep->num_req, len, ep->maxpacket, urbstat);
  503. if (usb_pipecontrol(urb->pipe)) {
  504. DBG(3, "%s: req %d %s Wait for ACK\n", __func__,
  505. ep->num_req,
  506. usb_pipein(urb->pipe) ? "IN" : "OUT");
  507. ep->nextpid = USB_PID_ACK;
  508. } else {
  509. if (len % ep->maxpacket ||
  510. !(urb->transfer_flags & URB_ZERO_PACKET)) {
  511. urbstat = 0;
  512. DBG(3, "%s: req %d URB %s status %d count %d/%d/%d\n",
  513. __func__, ep->num_req, usb_pipein(urb->pipe) ? "IN" : "OUT",
  514. urbstat, len, ep->maxpacket, urb->actual_length);
  515. }
  516. }
  517. }
  518. break;
  519. case USB_PID_IN:
  520. len = PTD_GET_COUNT(ptd);
  521. BUG_ON(len > ep->length);
  522. urb->actual_length += len;
  523. BUG_ON(urb->actual_length > urb->transfer_buffer_length);
  524. usb_settoggle(udev, ep->epnum, 0, PTD_GET_TOGGLE(ptd));
  525. /* if transfer completed or (allowed) data underrun */
  526. if ((urb->transfer_buffer_length == urb->actual_length) ||
  527. len % ep->maxpacket) {
  528. DBG(3, "%s: req %d xfer complete %d/%d status %d -> 0\n", __func__,
  529. ep->num_req, len, ep->maxpacket, urbstat);
  530. if (usb_pipecontrol(urb->pipe)) {
  531. DBG(3, "%s: req %d %s Wait for ACK\n", __func__,
  532. ep->num_req,
  533. usb_pipein(urb->pipe) ? "IN" : "OUT");
  534. ep->nextpid = USB_PID_ACK;
  535. } else {
  536. urbstat = 0;
  537. DBG(3, "%s: req %d URB %s status %d count %d/%d/%d\n",
  538. __func__, ep->num_req, usb_pipein(urb->pipe) ? "IN" : "OUT",
  539. urbstat, len, ep->maxpacket, urb->actual_length);
  540. }
  541. }
  542. break;
  543. case USB_PID_SETUP:
  544. if (urb->transfer_buffer_length == urb->actual_length) {
  545. ep->nextpid = USB_PID_ACK;
  546. } else if (usb_pipeout(urb->pipe)) {
  547. usb_settoggle(udev, 0, 1, 1);
  548. ep->nextpid = USB_PID_OUT;
  549. } else {
  550. usb_settoggle(udev, 0, 0, 1);
  551. ep->nextpid = USB_PID_IN;
  552. }
  553. break;
  554. case USB_PID_ACK:
  555. DBG(3, "%s: req %d got ACK %d -> 0\n", __func__, ep->num_req,
  556. urbstat);
  557. WARN_ON(urbstat != -EINPROGRESS);
  558. urbstat = 0;
  559. ep->nextpid = 0;
  560. break;
  561. default:
  562. BUG_ON(1);
  563. }
  564. out:
  565. if (urbstat != -EINPROGRESS) {
  566. DBG(2, "%s: Finishing ep %p req %d urb %p status %d\n", __func__,
  567. ep, ep->num_req, urb, urbstat);
  568. finish_request(isp1362_hcd, ep, urb, urbstat);
  569. }
  570. }
  571. static void finish_unlinks(struct isp1362_hcd *isp1362_hcd)
  572. {
  573. struct isp1362_ep *ep;
  574. struct isp1362_ep *tmp;
  575. list_for_each_entry_safe(ep, tmp, &isp1362_hcd->remove_list, remove_list) {
  576. struct isp1362_ep_queue *epq =
  577. get_ptd_queue(isp1362_hcd, ep->ptd_offset);
  578. int index = ep->ptd_index;
  579. BUG_ON(epq == NULL);
  580. if (index >= 0) {
  581. DBG(1, "%s: remove PTD[%d] $%04x\n", __func__, index, ep->ptd_offset);
  582. BUG_ON(ep->num_ptds == 0);
  583. release_ptd_buffers(epq, ep);
  584. }
  585. if (!list_empty(&ep->hep->urb_list)) {
  586. struct urb *urb = get_urb(ep);
  587. DBG(1, "%s: Finishing req %d ep %p from remove_list\n", __func__,
  588. ep->num_req, ep);
  589. finish_request(isp1362_hcd, ep, urb, -ESHUTDOWN);
  590. }
  591. WARN_ON(list_empty(&ep->active));
  592. if (!list_empty(&ep->active)) {
  593. list_del_init(&ep->active);
  594. DBG(1, "%s: ep %p removed from active list\n", __func__, ep);
  595. }
  596. list_del_init(&ep->remove_list);
  597. DBG(1, "%s: ep %p removed from remove_list\n", __func__, ep);
  598. }
  599. DBG(1, "%s: Done\n", __func__);
  600. }
  601. static inline void enable_atl_transfers(struct isp1362_hcd *isp1362_hcd, int count)
  602. {
  603. if (count > 0) {
  604. if (count < isp1362_hcd->atl_queue.ptd_count)
  605. isp1362_write_reg16(isp1362_hcd, HCATLDTC, count);
  606. isp1362_enable_int(isp1362_hcd, HCuPINT_ATL);
  607. isp1362_write_reg32(isp1362_hcd, HCATLSKIP, isp1362_hcd->atl_queue.skip_map);
  608. isp1362_set_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_ATL_ACTIVE);
  609. } else
  610. isp1362_enable_int(isp1362_hcd, HCuPINT_SOF);
  611. }
  612. static inline void enable_intl_transfers(struct isp1362_hcd *isp1362_hcd)
  613. {
  614. isp1362_enable_int(isp1362_hcd, HCuPINT_INTL);
  615. isp1362_set_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_INTL_ACTIVE);
  616. isp1362_write_reg32(isp1362_hcd, HCINTLSKIP, isp1362_hcd->intl_queue.skip_map);
  617. }
  618. static inline void enable_istl_transfers(struct isp1362_hcd *isp1362_hcd, int flip)
  619. {
  620. isp1362_enable_int(isp1362_hcd, flip ? HCuPINT_ISTL1 : HCuPINT_ISTL0);
  621. isp1362_set_mask16(isp1362_hcd, HCBUFSTAT, flip ?
  622. HCBUFSTAT_ISTL1_FULL : HCBUFSTAT_ISTL0_FULL);
  623. }
  624. static int submit_req(struct isp1362_hcd *isp1362_hcd, struct urb *urb,
  625. struct isp1362_ep *ep, struct isp1362_ep_queue *epq)
  626. {
  627. int index = epq->free_ptd;
  628. prepare_ptd(isp1362_hcd, urb, ep, epq, 0);
  629. index = claim_ptd_buffers(epq, ep, ep->length);
  630. if (index == -ENOMEM) {
  631. DBG(1, "%s: req %d No free %s PTD available: %d, %08lx:%08lx\n", __func__,
  632. ep->num_req, epq->name, ep->num_ptds, epq->buf_map, epq->skip_map);
  633. return index;
  634. } else if (index == -EOVERFLOW) {
  635. DBG(1, "%s: req %d Not enough space for %d byte %s PTD %d %08lx:%08lx\n",
  636. __func__, ep->num_req, ep->length, epq->name, ep->num_ptds,
  637. epq->buf_map, epq->skip_map);
  638. return index;
  639. } else
  640. BUG_ON(index < 0);
  641. list_add_tail(&ep->active, &epq->active);
  642. DBG(1, "%s: ep %p req %d len %d added to active list %p\n", __func__,
  643. ep, ep->num_req, ep->length, &epq->active);
  644. DBG(1, "%s: Submitting %s PTD $%04x for ep %p req %d\n", __func__, epq->name,
  645. ep->ptd_offset, ep, ep->num_req);
  646. isp1362_write_ptd(isp1362_hcd, ep, epq);
  647. __clear_bit(ep->ptd_index, &epq->skip_map);
  648. return 0;
  649. }
  650. static void start_atl_transfers(struct isp1362_hcd *isp1362_hcd)
  651. {
  652. int ptd_count = 0;
  653. struct isp1362_ep_queue *epq = &isp1362_hcd->atl_queue;
  654. struct isp1362_ep *ep;
  655. int defer = 0;
  656. if (atomic_read(&epq->finishing)) {
  657. DBG(1, "%s: finish_transfers is active for %s\n", __func__, epq->name);
  658. return;
  659. }
  660. list_for_each_entry(ep, &isp1362_hcd->async, schedule) {
  661. struct urb *urb = get_urb(ep);
  662. int ret;
  663. if (!list_empty(&ep->active)) {
  664. DBG(2, "%s: Skipping active %s ep %p\n", __func__, epq->name, ep);
  665. continue;
  666. }
  667. DBG(1, "%s: Processing %s ep %p req %d\n", __func__, epq->name,
  668. ep, ep->num_req);
  669. ret = submit_req(isp1362_hcd, urb, ep, epq);
  670. if (ret == -ENOMEM) {
  671. defer = 1;
  672. break;
  673. } else if (ret == -EOVERFLOW) {
  674. defer = 1;
  675. continue;
  676. }
  677. #ifdef BUGGY_PXA2XX_UDC_USBTEST
  678. defer = ep->nextpid == USB_PID_SETUP;
  679. #endif
  680. ptd_count++;
  681. }
  682. /* Avoid starving of endpoints */
  683. if (isp1362_hcd->async.next != isp1362_hcd->async.prev) {
  684. DBG(2, "%s: Cycling ASYNC schedule %d\n", __func__, ptd_count);
  685. list_move(&isp1362_hcd->async, isp1362_hcd->async.next);
  686. }
  687. if (ptd_count || defer)
  688. enable_atl_transfers(isp1362_hcd, defer ? 0 : ptd_count);
  689. epq->ptd_count += ptd_count;
  690. if (epq->ptd_count > epq->stat_maxptds) {
  691. epq->stat_maxptds = epq->ptd_count;
  692. DBG(0, "%s: max_ptds: %d\n", __func__, epq->stat_maxptds);
  693. }
  694. }
  695. static void start_intl_transfers(struct isp1362_hcd *isp1362_hcd)
  696. {
  697. int ptd_count = 0;
  698. struct isp1362_ep_queue *epq = &isp1362_hcd->intl_queue;
  699. struct isp1362_ep *ep;
  700. if (atomic_read(&epq->finishing)) {
  701. DBG(1, "%s: finish_transfers is active for %s\n", __func__, epq->name);
  702. return;
  703. }
  704. list_for_each_entry(ep, &isp1362_hcd->periodic, schedule) {
  705. struct urb *urb = get_urb(ep);
  706. int ret;
  707. if (!list_empty(&ep->active)) {
  708. DBG(1, "%s: Skipping active %s ep %p\n", __func__,
  709. epq->name, ep);
  710. continue;
  711. }
  712. DBG(1, "%s: Processing %s ep %p req %d\n", __func__,
  713. epq->name, ep, ep->num_req);
  714. ret = submit_req(isp1362_hcd, urb, ep, epq);
  715. if (ret == -ENOMEM)
  716. break;
  717. else if (ret == -EOVERFLOW)
  718. continue;
  719. ptd_count++;
  720. }
  721. if (ptd_count) {
  722. static int last_count;
  723. if (ptd_count != last_count) {
  724. DBG(0, "%s: ptd_count: %d\n", __func__, ptd_count);
  725. last_count = ptd_count;
  726. }
  727. enable_intl_transfers(isp1362_hcd);
  728. }
  729. epq->ptd_count += ptd_count;
  730. if (epq->ptd_count > epq->stat_maxptds)
  731. epq->stat_maxptds = epq->ptd_count;
  732. }
  733. static inline int next_ptd(struct isp1362_ep_queue *epq, struct isp1362_ep *ep)
  734. {
  735. u16 ptd_offset = ep->ptd_offset;
  736. int num_ptds = (ep->length + PTD_HEADER_SIZE + (epq->blk_size - 1)) / epq->blk_size;
  737. DBG(2, "%s: PTD offset $%04x + %04x => %d * %04x -> $%04x\n", __func__, ptd_offset,
  738. ep->length, num_ptds, epq->blk_size, ptd_offset + num_ptds * epq->blk_size);
  739. ptd_offset += num_ptds * epq->blk_size;
  740. if (ptd_offset < epq->buf_start + epq->buf_size)
  741. return ptd_offset;
  742. else
  743. return -ENOMEM;
  744. }
  745. static void start_iso_transfers(struct isp1362_hcd *isp1362_hcd)
  746. {
  747. int ptd_count = 0;
  748. int flip = isp1362_hcd->istl_flip;
  749. struct isp1362_ep_queue *epq;
  750. int ptd_offset;
  751. struct isp1362_ep *ep;
  752. struct isp1362_ep *tmp;
  753. u16 fno = isp1362_read_reg32(isp1362_hcd, HCFMNUM);
  754. fill2:
  755. epq = &isp1362_hcd->istl_queue[flip];
  756. if (atomic_read(&epq->finishing)) {
  757. DBG(1, "%s: finish_transfers is active for %s\n", __func__, epq->name);
  758. return;
  759. }
  760. if (!list_empty(&epq->active))
  761. return;
  762. ptd_offset = epq->buf_start;
  763. list_for_each_entry_safe(ep, tmp, &isp1362_hcd->isoc, schedule) {
  764. struct urb *urb = get_urb(ep);
  765. s16 diff = fno - (u16)urb->start_frame;
  766. DBG(1, "%s: Processing %s ep %p\n", __func__, epq->name, ep);
  767. if (diff > urb->number_of_packets) {
  768. /* time frame for this URB has elapsed */
  769. finish_request(isp1362_hcd, ep, urb, -EOVERFLOW);
  770. continue;
  771. } else if (diff < -1) {
  772. /* URB is not due in this frame or the next one.
  773. * Comparing with '-1' instead of '0' accounts for double
  774. * buffering in the ISP1362 which enables us to queue the PTD
  775. * one frame ahead of time
  776. */
  777. } else if (diff == -1) {
  778. /* submit PTD's that are due in the next frame */
  779. prepare_ptd(isp1362_hcd, urb, ep, epq, fno);
  780. if (ptd_offset + PTD_HEADER_SIZE + ep->length >
  781. epq->buf_start + epq->buf_size) {
  782. pr_err("%s: Not enough ISO buffer space for %d byte PTD\n",
  783. __func__, ep->length);
  784. continue;
  785. }
  786. ep->ptd_offset = ptd_offset;
  787. list_add_tail(&ep->active, &epq->active);
  788. ptd_offset = next_ptd(epq, ep);
  789. if (ptd_offset < 0) {
  790. pr_warning("%s: req %d No more %s PTD buffers available\n", __func__,
  791. ep->num_req, epq->name);
  792. break;
  793. }
  794. }
  795. }
  796. list_for_each_entry(ep, &epq->active, active) {
  797. if (epq->active.next == &ep->active)
  798. ep->ptd.mps |= PTD_LAST_MSK;
  799. isp1362_write_ptd(isp1362_hcd, ep, epq);
  800. ptd_count++;
  801. }
  802. if (ptd_count)
  803. enable_istl_transfers(isp1362_hcd, flip);
  804. epq->ptd_count += ptd_count;
  805. if (epq->ptd_count > epq->stat_maxptds)
  806. epq->stat_maxptds = epq->ptd_count;
  807. /* check, whether the second ISTL buffer may also be filled */
  808. if (!(isp1362_read_reg16(isp1362_hcd, HCBUFSTAT) &
  809. (flip ? HCBUFSTAT_ISTL0_FULL : HCBUFSTAT_ISTL1_FULL))) {
  810. fno++;
  811. ptd_count = 0;
  812. flip = 1 - flip;
  813. goto fill2;
  814. }
  815. }
  816. static void finish_transfers(struct isp1362_hcd *isp1362_hcd, unsigned long done_map,
  817. struct isp1362_ep_queue *epq)
  818. {
  819. struct isp1362_ep *ep;
  820. struct isp1362_ep *tmp;
  821. if (list_empty(&epq->active)) {
  822. DBG(1, "%s: Nothing to do for %s queue\n", __func__, epq->name);
  823. return;
  824. }
  825. DBG(1, "%s: Finishing %s transfers %08lx\n", __func__, epq->name, done_map);
  826. atomic_inc(&epq->finishing);
  827. list_for_each_entry_safe(ep, tmp, &epq->active, active) {
  828. int index = ep->ptd_index;
  829. DBG(1, "%s: Checking %s PTD[%02x] $%04x\n", __func__, epq->name,
  830. index, ep->ptd_offset);
  831. BUG_ON(index < 0);
  832. if (__test_and_clear_bit(index, &done_map)) {
  833. isp1362_read_ptd(isp1362_hcd, ep, epq);
  834. epq->free_ptd = index;
  835. BUG_ON(ep->num_ptds == 0);
  836. release_ptd_buffers(epq, ep);
  837. DBG(1, "%s: ep %p req %d removed from active list\n", __func__,
  838. ep, ep->num_req);
  839. if (!list_empty(&ep->remove_list)) {
  840. list_del_init(&ep->remove_list);
  841. DBG(1, "%s: ep %p removed from remove list\n", __func__, ep);
  842. }
  843. DBG(1, "%s: Postprocessing %s ep %p req %d\n", __func__, epq->name,
  844. ep, ep->num_req);
  845. postproc_ep(isp1362_hcd, ep);
  846. }
  847. if (!done_map)
  848. break;
  849. }
  850. if (done_map)
  851. pr_warning("%s: done_map not clear: %08lx:%08lx\n", __func__, done_map,
  852. epq->skip_map);
  853. atomic_dec(&epq->finishing);
  854. }
  855. static void finish_iso_transfers(struct isp1362_hcd *isp1362_hcd, struct isp1362_ep_queue *epq)
  856. {
  857. struct isp1362_ep *ep;
  858. struct isp1362_ep *tmp;
  859. if (list_empty(&epq->active)) {
  860. DBG(1, "%s: Nothing to do for %s queue\n", __func__, epq->name);
  861. return;
  862. }
  863. DBG(1, "%s: Finishing %s transfers\n", __func__, epq->name);
  864. atomic_inc(&epq->finishing);
  865. list_for_each_entry_safe(ep, tmp, &epq->active, active) {
  866. DBG(1, "%s: Checking PTD $%04x\n", __func__, ep->ptd_offset);
  867. isp1362_read_ptd(isp1362_hcd, ep, epq);
  868. DBG(1, "%s: Postprocessing %s ep %p\n", __func__, epq->name, ep);
  869. postproc_ep(isp1362_hcd, ep);
  870. }
  871. WARN_ON(epq->blk_size != 0);
  872. atomic_dec(&epq->finishing);
  873. }
  874. static irqreturn_t isp1362_irq(struct usb_hcd *hcd)
  875. {
  876. int handled = 0;
  877. struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
  878. u16 irqstat;
  879. u16 svc_mask;
  880. spin_lock(&isp1362_hcd->lock);
  881. BUG_ON(isp1362_hcd->irq_active++);
  882. isp1362_write_reg16(isp1362_hcd, HCuPINTENB, 0);
  883. irqstat = isp1362_read_reg16(isp1362_hcd, HCuPINT);
  884. DBG(3, "%s: got IRQ %04x:%04x\n", __func__, irqstat, isp1362_hcd->irqenb);
  885. /* only handle interrupts that are currently enabled */
  886. irqstat &= isp1362_hcd->irqenb;
  887. isp1362_write_reg16(isp1362_hcd, HCuPINT, irqstat);
  888. svc_mask = irqstat;
  889. if (irqstat & HCuPINT_SOF) {
  890. isp1362_hcd->irqenb &= ~HCuPINT_SOF;
  891. isp1362_hcd->irq_stat[ISP1362_INT_SOF]++;
  892. handled = 1;
  893. svc_mask &= ~HCuPINT_SOF;
  894. DBG(3, "%s: SOF\n", __func__);
  895. isp1362_hcd->fmindex = isp1362_read_reg32(isp1362_hcd, HCFMNUM);
  896. if (!list_empty(&isp1362_hcd->remove_list))
  897. finish_unlinks(isp1362_hcd);
  898. if (!list_empty(&isp1362_hcd->async) && !(irqstat & HCuPINT_ATL)) {
  899. if (list_empty(&isp1362_hcd->atl_queue.active)) {
  900. start_atl_transfers(isp1362_hcd);
  901. } else {
  902. isp1362_enable_int(isp1362_hcd, HCuPINT_ATL);
  903. isp1362_write_reg32(isp1362_hcd, HCATLSKIP,
  904. isp1362_hcd->atl_queue.skip_map);
  905. isp1362_set_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_ATL_ACTIVE);
  906. }
  907. }
  908. }
  909. if (irqstat & HCuPINT_ISTL0) {
  910. isp1362_hcd->irq_stat[ISP1362_INT_ISTL0]++;
  911. handled = 1;
  912. svc_mask &= ~HCuPINT_ISTL0;
  913. isp1362_clr_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_ISTL0_FULL);
  914. DBG(1, "%s: ISTL0\n", __func__);
  915. WARN_ON((int)!!isp1362_hcd->istl_flip);
  916. WARN_ON(isp1362_read_reg16(isp1362_hcd, HCBUFSTAT) &
  917. HCBUFSTAT_ISTL0_ACTIVE);
  918. WARN_ON(!(isp1362_read_reg16(isp1362_hcd, HCBUFSTAT) &
  919. HCBUFSTAT_ISTL0_DONE));
  920. isp1362_hcd->irqenb &= ~HCuPINT_ISTL0;
  921. }
  922. if (irqstat & HCuPINT_ISTL1) {
  923. isp1362_hcd->irq_stat[ISP1362_INT_ISTL1]++;
  924. handled = 1;
  925. svc_mask &= ~HCuPINT_ISTL1;
  926. isp1362_clr_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_ISTL1_FULL);
  927. DBG(1, "%s: ISTL1\n", __func__);
  928. WARN_ON(!(int)isp1362_hcd->istl_flip);
  929. WARN_ON(isp1362_read_reg16(isp1362_hcd, HCBUFSTAT) &
  930. HCBUFSTAT_ISTL1_ACTIVE);
  931. WARN_ON(!(isp1362_read_reg16(isp1362_hcd, HCBUFSTAT) &
  932. HCBUFSTAT_ISTL1_DONE));
  933. isp1362_hcd->irqenb &= ~HCuPINT_ISTL1;
  934. }
  935. if (irqstat & (HCuPINT_ISTL0 | HCuPINT_ISTL1)) {
  936. WARN_ON((irqstat & (HCuPINT_ISTL0 | HCuPINT_ISTL1)) ==
  937. (HCuPINT_ISTL0 | HCuPINT_ISTL1));
  938. finish_iso_transfers(isp1362_hcd,
  939. &isp1362_hcd->istl_queue[isp1362_hcd->istl_flip]);
  940. start_iso_transfers(isp1362_hcd);
  941. isp1362_hcd->istl_flip = 1 - isp1362_hcd->istl_flip;
  942. }
  943. if (irqstat & HCuPINT_INTL) {
  944. u32 done_map = isp1362_read_reg32(isp1362_hcd, HCINTLDONE);
  945. u32 skip_map = isp1362_read_reg32(isp1362_hcd, HCINTLSKIP);
  946. isp1362_hcd->irq_stat[ISP1362_INT_INTL]++;
  947. DBG(2, "%s: INTL\n", __func__);
  948. svc_mask &= ~HCuPINT_INTL;
  949. isp1362_write_reg32(isp1362_hcd, HCINTLSKIP, skip_map | done_map);
  950. if (~(done_map | skip_map) == 0)
  951. /* All PTDs are finished, disable INTL processing entirely */
  952. isp1362_clr_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_INTL_ACTIVE);
  953. handled = 1;
  954. WARN_ON(!done_map);
  955. if (done_map) {
  956. DBG(3, "%s: INTL done_map %08x\n", __func__, done_map);
  957. finish_transfers(isp1362_hcd, done_map, &isp1362_hcd->intl_queue);
  958. start_intl_transfers(isp1362_hcd);
  959. }
  960. }
  961. if (irqstat & HCuPINT_ATL) {
  962. u32 done_map = isp1362_read_reg32(isp1362_hcd, HCATLDONE);
  963. u32 skip_map = isp1362_read_reg32(isp1362_hcd, HCATLSKIP);
  964. isp1362_hcd->irq_stat[ISP1362_INT_ATL]++;
  965. DBG(2, "%s: ATL\n", __func__);
  966. svc_mask &= ~HCuPINT_ATL;
  967. isp1362_write_reg32(isp1362_hcd, HCATLSKIP, skip_map | done_map);
  968. if (~(done_map | skip_map) == 0)
  969. isp1362_clr_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_ATL_ACTIVE);
  970. if (done_map) {
  971. DBG(3, "%s: ATL done_map %08x\n", __func__, done_map);
  972. finish_transfers(isp1362_hcd, done_map, &isp1362_hcd->atl_queue);
  973. start_atl_transfers(isp1362_hcd);
  974. }
  975. handled = 1;
  976. }
  977. if (irqstat & HCuPINT_OPR) {
  978. u32 intstat = isp1362_read_reg32(isp1362_hcd, HCINTSTAT);
  979. isp1362_hcd->irq_stat[ISP1362_INT_OPR]++;
  980. svc_mask &= ~HCuPINT_OPR;
  981. DBG(2, "%s: OPR %08x:%08x\n", __func__, intstat, isp1362_hcd->intenb);
  982. intstat &= isp1362_hcd->intenb;
  983. if (intstat & OHCI_INTR_UE) {
  984. pr_err("Unrecoverable error\n");
  985. /* FIXME: do here reset or cleanup or whatever */
  986. }
  987. if (intstat & OHCI_INTR_RHSC) {
  988. isp1362_hcd->rhstatus = isp1362_read_reg32(isp1362_hcd, HCRHSTATUS);
  989. isp1362_hcd->rhport[0] = isp1362_read_reg32(isp1362_hcd, HCRHPORT1);
  990. isp1362_hcd->rhport[1] = isp1362_read_reg32(isp1362_hcd, HCRHPORT2);
  991. }
  992. if (intstat & OHCI_INTR_RD) {
  993. pr_info("%s: RESUME DETECTED\n", __func__);
  994. isp1362_show_reg(isp1362_hcd, HCCONTROL);
  995. usb_hcd_resume_root_hub(hcd);
  996. }
  997. isp1362_write_reg32(isp1362_hcd, HCINTSTAT, intstat);
  998. irqstat &= ~HCuPINT_OPR;
  999. handled = 1;
  1000. }
  1001. if (irqstat & HCuPINT_SUSP) {
  1002. isp1362_hcd->irq_stat[ISP1362_INT_SUSP]++;
  1003. handled = 1;
  1004. svc_mask &= ~HCuPINT_SUSP;
  1005. pr_info("%s: SUSPEND IRQ\n", __func__);
  1006. }
  1007. if (irqstat & HCuPINT_CLKRDY) {
  1008. isp1362_hcd->irq_stat[ISP1362_INT_CLKRDY]++;
  1009. handled = 1;
  1010. isp1362_hcd->irqenb &= ~HCuPINT_CLKRDY;
  1011. svc_mask &= ~HCuPINT_CLKRDY;
  1012. pr_info("%s: CLKRDY IRQ\n", __func__);
  1013. }
  1014. if (svc_mask)
  1015. pr_err("%s: Unserviced interrupt(s) %04x\n", __func__, svc_mask);
  1016. isp1362_write_reg16(isp1362_hcd, HCuPINTENB, isp1362_hcd->irqenb);
  1017. isp1362_hcd->irq_active--;
  1018. spin_unlock(&isp1362_hcd->lock);
  1019. return IRQ_RETVAL(handled);
  1020. }
  1021. /*-------------------------------------------------------------------------*/
  1022. #define MAX_PERIODIC_LOAD 900 /* out of 1000 usec */
  1023. static int balance(struct isp1362_hcd *isp1362_hcd, u16 interval, u16 load)
  1024. {
  1025. int i, branch = -ENOSPC;
  1026. /* search for the least loaded schedule branch of that interval
  1027. * which has enough bandwidth left unreserved.
  1028. */
  1029. for (i = 0; i < interval; i++) {
  1030. if (branch < 0 || isp1362_hcd->load[branch] > isp1362_hcd->load[i]) {
  1031. int j;
  1032. for (j = i; j < PERIODIC_SIZE; j += interval) {
  1033. if ((isp1362_hcd->load[j] + load) > MAX_PERIODIC_LOAD) {
  1034. pr_err("%s: new load %d load[%02x] %d max %d\n", __func__,
  1035. load, j, isp1362_hcd->load[j], MAX_PERIODIC_LOAD);
  1036. break;
  1037. }
  1038. }
  1039. if (j < PERIODIC_SIZE)
  1040. continue;
  1041. branch = i;
  1042. }
  1043. }
  1044. return branch;
  1045. }
  1046. /* NB! ALL the code above this point runs with isp1362_hcd->lock
  1047. held, irqs off
  1048. */
  1049. /*-------------------------------------------------------------------------*/
  1050. static int isp1362_urb_enqueue(struct usb_hcd *hcd,
  1051. struct urb *urb,
  1052. gfp_t mem_flags)
  1053. {
  1054. struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
  1055. struct usb_device *udev = urb->dev;
  1056. unsigned int pipe = urb->pipe;
  1057. int is_out = !usb_pipein(pipe);
  1058. int type = usb_pipetype(pipe);
  1059. int epnum = usb_pipeendpoint(pipe);
  1060. struct usb_host_endpoint *hep = urb->ep;
  1061. struct isp1362_ep *ep = NULL;
  1062. unsigned long flags;
  1063. int retval = 0;
  1064. DBG(3, "%s: urb %p\n", __func__, urb);
  1065. if (type == PIPE_ISOCHRONOUS) {
  1066. pr_err("Isochronous transfers not supported\n");
  1067. return -ENOSPC;
  1068. }
  1069. URB_DBG("%s: FA %d ep%d%s %s: len %d %s%s\n", __func__,
  1070. usb_pipedevice(pipe), epnum,
  1071. is_out ? "out" : "in",
  1072. usb_pipecontrol(pipe) ? "ctrl" :
  1073. usb_pipeint(pipe) ? "int" :
  1074. usb_pipebulk(pipe) ? "bulk" :
  1075. "iso",
  1076. urb->transfer_buffer_length,
  1077. (urb->transfer_flags & URB_ZERO_PACKET) ? "ZERO_PACKET " : "",
  1078. !(urb->transfer_flags & URB_SHORT_NOT_OK) ?
  1079. "short_ok" : "");
  1080. /* avoid all allocations within spinlocks: request or endpoint */
  1081. if (!hep->hcpriv) {
  1082. ep = kzalloc(sizeof *ep, mem_flags);
  1083. if (!ep)
  1084. return -ENOMEM;
  1085. }
  1086. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  1087. /* don't submit to a dead or disabled port */
  1088. if (!((isp1362_hcd->rhport[0] | isp1362_hcd->rhport[1]) &
  1089. USB_PORT_STAT_ENABLE) ||
  1090. !HC_IS_RUNNING(hcd->state)) {
  1091. kfree(ep);
  1092. retval = -ENODEV;
  1093. goto fail_not_linked;
  1094. }
  1095. retval = usb_hcd_link_urb_to_ep(hcd, urb);
  1096. if (retval) {
  1097. kfree(ep);
  1098. goto fail_not_linked;
  1099. }
  1100. if (hep->hcpriv) {
  1101. ep = hep->hcpriv;
  1102. } else {
  1103. INIT_LIST_HEAD(&ep->schedule);
  1104. INIT_LIST_HEAD(&ep->active);
  1105. INIT_LIST_HEAD(&ep->remove_list);
  1106. ep->udev = usb_get_dev(udev);
  1107. ep->hep = hep;
  1108. ep->epnum = epnum;
  1109. ep->maxpacket = usb_maxpacket(udev, urb->pipe, is_out);
  1110. ep->ptd_offset = -EINVAL;
  1111. ep->ptd_index = -EINVAL;
  1112. usb_settoggle(udev, epnum, is_out, 0);
  1113. if (type == PIPE_CONTROL)
  1114. ep->nextpid = USB_PID_SETUP;
  1115. else if (is_out)
  1116. ep->nextpid = USB_PID_OUT;
  1117. else
  1118. ep->nextpid = USB_PID_IN;
  1119. switch (type) {
  1120. case PIPE_ISOCHRONOUS:
  1121. case PIPE_INTERRUPT:
  1122. if (urb->interval > PERIODIC_SIZE)
  1123. urb->interval = PERIODIC_SIZE;
  1124. ep->interval = urb->interval;
  1125. ep->branch = PERIODIC_SIZE;
  1126. ep->load = usb_calc_bus_time(udev->speed, !is_out,
  1127. (type == PIPE_ISOCHRONOUS),
  1128. usb_maxpacket(udev, pipe, is_out)) / 1000;
  1129. break;
  1130. }
  1131. hep->hcpriv = ep;
  1132. }
  1133. ep->num_req = isp1362_hcd->req_serial++;
  1134. /* maybe put endpoint into schedule */
  1135. switch (type) {
  1136. case PIPE_CONTROL:
  1137. case PIPE_BULK:
  1138. if (list_empty(&ep->schedule)) {
  1139. DBG(1, "%s: Adding ep %p req %d to async schedule\n",
  1140. __func__, ep, ep->num_req);
  1141. list_add_tail(&ep->schedule, &isp1362_hcd->async);
  1142. }
  1143. break;
  1144. case PIPE_ISOCHRONOUS:
  1145. case PIPE_INTERRUPT:
  1146. urb->interval = ep->interval;
  1147. /* urb submitted for already existing EP */
  1148. if (ep->branch < PERIODIC_SIZE)
  1149. break;
  1150. retval = balance(isp1362_hcd, ep->interval, ep->load);
  1151. if (retval < 0) {
  1152. pr_err("%s: balance returned %d\n", __func__, retval);
  1153. goto fail;
  1154. }
  1155. ep->branch = retval;
  1156. retval = 0;
  1157. isp1362_hcd->fmindex = isp1362_read_reg32(isp1362_hcd, HCFMNUM);
  1158. DBG(1, "%s: Current frame %04x branch %02x start_frame %04x(%04x)\n",
  1159. __func__, isp1362_hcd->fmindex, ep->branch,
  1160. ((isp1362_hcd->fmindex + PERIODIC_SIZE - 1) &
  1161. ~(PERIODIC_SIZE - 1)) + ep->branch,
  1162. (isp1362_hcd->fmindex & (PERIODIC_SIZE - 1)) + ep->branch);
  1163. if (list_empty(&ep->schedule)) {
  1164. if (type == PIPE_ISOCHRONOUS) {
  1165. u16 frame = isp1362_hcd->fmindex;
  1166. frame += max_t(u16, 8, ep->interval);
  1167. frame &= ~(ep->interval - 1);
  1168. frame |= ep->branch;
  1169. if (frame_before(frame, isp1362_hcd->fmindex))
  1170. frame += ep->interval;
  1171. urb->start_frame = frame;
  1172. DBG(1, "%s: Adding ep %p to isoc schedule\n", __func__, ep);
  1173. list_add_tail(&ep->schedule, &isp1362_hcd->isoc);
  1174. } else {
  1175. DBG(1, "%s: Adding ep %p to periodic schedule\n", __func__, ep);
  1176. list_add_tail(&ep->schedule, &isp1362_hcd->periodic);
  1177. }
  1178. } else
  1179. DBG(1, "%s: ep %p already scheduled\n", __func__, ep);
  1180. DBG(2, "%s: load %d bandwidth %d -> %d\n", __func__,
  1181. ep->load / ep->interval, isp1362_hcd->load[ep->branch],
  1182. isp1362_hcd->load[ep->branch] + ep->load);
  1183. isp1362_hcd->load[ep->branch] += ep->load;
  1184. }
  1185. urb->hcpriv = hep;
  1186. ALIGNSTAT(isp1362_hcd, urb->transfer_buffer);
  1187. switch (type) {
  1188. case PIPE_CONTROL:
  1189. case PIPE_BULK:
  1190. start_atl_transfers(isp1362_hcd);
  1191. break;
  1192. case PIPE_INTERRUPT:
  1193. start_intl_transfers(isp1362_hcd);
  1194. break;
  1195. case PIPE_ISOCHRONOUS:
  1196. start_iso_transfers(isp1362_hcd);
  1197. break;
  1198. default:
  1199. BUG();
  1200. }
  1201. fail:
  1202. if (retval)
  1203. usb_hcd_unlink_urb_from_ep(hcd, urb);
  1204. fail_not_linked:
  1205. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  1206. if (retval)
  1207. DBG(0, "%s: urb %p failed with %d\n", __func__, urb, retval);
  1208. return retval;
  1209. }
  1210. static int isp1362_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  1211. {
  1212. struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
  1213. struct usb_host_endpoint *hep;
  1214. unsigned long flags;
  1215. struct isp1362_ep *ep;
  1216. int retval = 0;
  1217. DBG(3, "%s: urb %p\n", __func__, urb);
  1218. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  1219. retval = usb_hcd_check_unlink_urb(hcd, urb, status);
  1220. if (retval)
  1221. goto done;
  1222. hep = urb->hcpriv;
  1223. if (!hep) {
  1224. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  1225. return -EIDRM;
  1226. }
  1227. ep = hep->hcpriv;
  1228. if (ep) {
  1229. /* In front of queue? */
  1230. if (ep->hep->urb_list.next == &urb->urb_list) {
  1231. if (!list_empty(&ep->active)) {
  1232. DBG(1, "%s: urb %p ep %p req %d active PTD[%d] $%04x\n", __func__,
  1233. urb, ep, ep->num_req, ep->ptd_index, ep->ptd_offset);
  1234. /* disable processing and queue PTD for removal */
  1235. remove_ptd(isp1362_hcd, ep);
  1236. urb = NULL;
  1237. }
  1238. }
  1239. if (urb) {
  1240. DBG(1, "%s: Finishing ep %p req %d\n", __func__, ep,
  1241. ep->num_req);
  1242. finish_request(isp1362_hcd, ep, urb, status);
  1243. } else
  1244. DBG(1, "%s: urb %p active; wait4irq\n", __func__, urb);
  1245. } else {
  1246. pr_warning("%s: No EP in URB %p\n", __func__, urb);
  1247. retval = -EINVAL;
  1248. }
  1249. done:
  1250. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  1251. DBG(3, "%s: exit\n", __func__);
  1252. return retval;
  1253. }
  1254. static void isp1362_endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *hep)
  1255. {
  1256. struct isp1362_ep *ep = hep->hcpriv;
  1257. struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
  1258. unsigned long flags;
  1259. DBG(1, "%s: ep %p\n", __func__, ep);
  1260. if (!ep)
  1261. return;
  1262. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  1263. if (!list_empty(&hep->urb_list)) {
  1264. if (!list_empty(&ep->active) && list_empty(&ep->remove_list)) {
  1265. DBG(1, "%s: Removing ep %p req %d PTD[%d] $%04x\n", __func__,
  1266. ep, ep->num_req, ep->ptd_index, ep->ptd_offset);
  1267. remove_ptd(isp1362_hcd, ep);
  1268. pr_info("%s: Waiting for Interrupt to clean up\n", __func__);
  1269. }
  1270. }
  1271. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  1272. /* Wait for interrupt to clear out active list */
  1273. while (!list_empty(&ep->active))
  1274. msleep(1);
  1275. DBG(1, "%s: Freeing EP %p\n", __func__, ep);
  1276. usb_put_dev(ep->udev);
  1277. kfree(ep);
  1278. hep->hcpriv = NULL;
  1279. }
  1280. static int isp1362_get_frame(struct usb_hcd *hcd)
  1281. {
  1282. struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
  1283. u32 fmnum;
  1284. unsigned long flags;
  1285. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  1286. fmnum = isp1362_read_reg32(isp1362_hcd, HCFMNUM);
  1287. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  1288. return (int)fmnum;
  1289. }
  1290. /*-------------------------------------------------------------------------*/
  1291. /* Adapted from ohci-hub.c */
  1292. static int isp1362_hub_status_data(struct usb_hcd *hcd, char *buf)
  1293. {
  1294. struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
  1295. int ports, i, changed = 0;
  1296. unsigned long flags;
  1297. if (!HC_IS_RUNNING(hcd->state))
  1298. return -ESHUTDOWN;
  1299. /* Report no status change now, if we are scheduled to be
  1300. called later */
  1301. if (timer_pending(&hcd->rh_timer))
  1302. return 0;
  1303. ports = isp1362_hcd->rhdesca & RH_A_NDP;
  1304. BUG_ON(ports > 2);
  1305. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  1306. /* init status */
  1307. if (isp1362_hcd->rhstatus & (RH_HS_LPSC | RH_HS_OCIC))
  1308. buf[0] = changed = 1;
  1309. else
  1310. buf[0] = 0;
  1311. for (i = 0; i < ports; i++) {
  1312. u32 status = isp1362_hcd->rhport[i];
  1313. if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC |
  1314. RH_PS_OCIC | RH_PS_PRSC)) {
  1315. changed = 1;
  1316. buf[0] |= 1 << (i + 1);
  1317. continue;
  1318. }
  1319. if (!(status & RH_PS_CCS))
  1320. continue;
  1321. }
  1322. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  1323. return changed;
  1324. }
  1325. static void isp1362_hub_descriptor(struct isp1362_hcd *isp1362_hcd,
  1326. struct usb_hub_descriptor *desc)
  1327. {
  1328. u32 reg = isp1362_hcd->rhdesca;
  1329. DBG(3, "%s: enter\n", __func__);
  1330. desc->bDescriptorType = 0x29;
  1331. desc->bDescLength = 9;
  1332. desc->bHubContrCurrent = 0;
  1333. desc->bNbrPorts = reg & 0x3;
  1334. /* Power switching, device type, overcurrent. */
  1335. desc->wHubCharacteristics = cpu_to_le16((reg >> 8) & 0x1f);
  1336. DBG(0, "%s: hubcharacteristics = %02x\n", __func__, cpu_to_le16((reg >> 8) & 0x1f));
  1337. desc->bPwrOn2PwrGood = (reg >> 24) & 0xff;
  1338. /* ports removable, and legacy PortPwrCtrlMask */
  1339. desc->u.hs.DeviceRemovable[0] = desc->bNbrPorts == 1 ? 1 << 1 : 3 << 1;
  1340. desc->u.hs.DeviceRemovable[1] = ~0;
  1341. DBG(3, "%s: exit\n", __func__);
  1342. }
  1343. /* Adapted from ohci-hub.c */
  1344. static int isp1362_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
  1345. u16 wIndex, char *buf, u16 wLength)
  1346. {
  1347. struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
  1348. int retval = 0;
  1349. unsigned long flags;
  1350. unsigned long t1;
  1351. int ports = isp1362_hcd->rhdesca & RH_A_NDP;
  1352. u32 tmp = 0;
  1353. switch (typeReq) {
  1354. case ClearHubFeature:
  1355. DBG(0, "ClearHubFeature: ");
  1356. switch (wValue) {
  1357. case C_HUB_OVER_CURRENT:
  1358. _DBG(0, "C_HUB_OVER_CURRENT\n");
  1359. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  1360. isp1362_write_reg32(isp1362_hcd, HCRHSTATUS, RH_HS_OCIC);
  1361. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  1362. case C_HUB_LOCAL_POWER:
  1363. _DBG(0, "C_HUB_LOCAL_POWER\n");
  1364. break;
  1365. default:
  1366. goto error;
  1367. }
  1368. break;
  1369. case SetHubFeature:
  1370. DBG(0, "SetHubFeature: ");
  1371. switch (wValue) {
  1372. case C_HUB_OVER_CURRENT:
  1373. case C_HUB_LOCAL_POWER:
  1374. _DBG(0, "C_HUB_OVER_CURRENT or C_HUB_LOCAL_POWER\n");
  1375. break;
  1376. default:
  1377. goto error;
  1378. }
  1379. break;
  1380. case GetHubDescriptor:
  1381. DBG(0, "GetHubDescriptor\n");
  1382. isp1362_hub_descriptor(isp1362_hcd, (struct usb_hub_descriptor *)buf);
  1383. break;
  1384. case GetHubStatus:
  1385. DBG(0, "GetHubStatus\n");
  1386. put_unaligned(cpu_to_le32(0), (__le32 *) buf);
  1387. break;
  1388. case GetPortStatus:
  1389. #ifndef VERBOSE
  1390. DBG(0, "GetPortStatus\n");
  1391. #endif
  1392. if (!wIndex || wIndex > ports)
  1393. goto error;
  1394. tmp = isp1362_hcd->rhport[--wIndex];
  1395. put_unaligned(cpu_to_le32(tmp), (__le32 *) buf);
  1396. break;
  1397. case ClearPortFeature:
  1398. DBG(0, "ClearPortFeature: ");
  1399. if (!wIndex || wIndex > ports)
  1400. goto error;
  1401. wIndex--;
  1402. switch (wValue) {
  1403. case USB_PORT_FEAT_ENABLE:
  1404. _DBG(0, "USB_PORT_FEAT_ENABLE\n");
  1405. tmp = RH_PS_CCS;
  1406. break;
  1407. case USB_PORT_FEAT_C_ENABLE:
  1408. _DBG(0, "USB_PORT_FEAT_C_ENABLE\n");
  1409. tmp = RH_PS_PESC;
  1410. break;
  1411. case USB_PORT_FEAT_SUSPEND:
  1412. _DBG(0, "USB_PORT_FEAT_SUSPEND\n");
  1413. tmp = RH_PS_POCI;
  1414. break;
  1415. case USB_PORT_FEAT_C_SUSPEND:
  1416. _DBG(0, "USB_PORT_FEAT_C_SUSPEND\n");
  1417. tmp = RH_PS_PSSC;
  1418. break;
  1419. case USB_PORT_FEAT_POWER:
  1420. _DBG(0, "USB_PORT_FEAT_POWER\n");
  1421. tmp = RH_PS_LSDA;
  1422. break;
  1423. case USB_PORT_FEAT_C_CONNECTION:
  1424. _DBG(0, "USB_PORT_FEAT_C_CONNECTION\n");
  1425. tmp = RH_PS_CSC;
  1426. break;
  1427. case USB_PORT_FEAT_C_OVER_CURRENT:
  1428. _DBG(0, "USB_PORT_FEAT_C_OVER_CURRENT\n");
  1429. tmp = RH_PS_OCIC;
  1430. break;
  1431. case USB_PORT_FEAT_C_RESET:
  1432. _DBG(0, "USB_PORT_FEAT_C_RESET\n");
  1433. tmp = RH_PS_PRSC;
  1434. break;
  1435. default:
  1436. goto error;
  1437. }
  1438. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  1439. isp1362_write_reg32(isp1362_hcd, HCRHPORT1 + wIndex, tmp);
  1440. isp1362_hcd->rhport[wIndex] =
  1441. isp1362_read_reg32(isp1362_hcd, HCRHPORT1 + wIndex);
  1442. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  1443. break;
  1444. case SetPortFeature:
  1445. DBG(0, "SetPortFeature: ");
  1446. if (!wIndex || wIndex > ports)
  1447. goto error;
  1448. wIndex--;
  1449. switch (wValue) {
  1450. case USB_PORT_FEAT_SUSPEND:
  1451. _DBG(0, "USB_PORT_FEAT_SUSPEND\n");
  1452. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  1453. isp1362_write_reg32(isp1362_hcd, HCRHPORT1 + wIndex, RH_PS_PSS);
  1454. isp1362_hcd->rhport[wIndex] =
  1455. isp1362_read_reg32(isp1362_hcd, HCRHPORT1 + wIndex);
  1456. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  1457. break;
  1458. case USB_PORT_FEAT_POWER:
  1459. _DBG(0, "USB_PORT_FEAT_POWER\n");
  1460. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  1461. isp1362_write_reg32(isp1362_hcd, HCRHPORT1 + wIndex, RH_PS_PPS);
  1462. isp1362_hcd->rhport[wIndex] =
  1463. isp1362_read_reg32(isp1362_hcd, HCRHPORT1 + wIndex);
  1464. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  1465. break;
  1466. case USB_PORT_FEAT_RESET:
  1467. _DBG(0, "USB_PORT_FEAT_RESET\n");
  1468. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  1469. t1 = jiffies + msecs_to_jiffies(USB_RESET_WIDTH);
  1470. while (time_before(jiffies, t1)) {
  1471. /* spin until any current reset finishes */
  1472. for (;;) {
  1473. tmp = isp1362_read_reg32(isp1362_hcd, HCRHPORT1 + wIndex);
  1474. if (!(tmp & RH_PS_PRS))
  1475. break;
  1476. udelay(500);
  1477. }
  1478. if (!(tmp & RH_PS_CCS))
  1479. break;
  1480. /* Reset lasts 10ms (claims datasheet) */
  1481. isp1362_write_reg32(isp1362_hcd, HCRHPORT1 + wIndex, (RH_PS_PRS));
  1482. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  1483. msleep(10);
  1484. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  1485. }
  1486. isp1362_hcd->rhport[wIndex] = isp1362_read_reg32(isp1362_hcd,
  1487. HCRHPORT1 + wIndex);
  1488. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  1489. break;
  1490. default:
  1491. goto error;
  1492. }
  1493. break;
  1494. default:
  1495. error:
  1496. /* "protocol stall" on error */
  1497. _DBG(0, "PROTOCOL STALL\n");
  1498. retval = -EPIPE;
  1499. }
  1500. return retval;
  1501. }
  1502. #ifdef CONFIG_PM
  1503. static int isp1362_bus_suspend(struct usb_hcd *hcd)
  1504. {
  1505. int status = 0;
  1506. struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
  1507. unsigned long flags;
  1508. if (time_before(jiffies, isp1362_hcd->next_statechange))
  1509. msleep(5);
  1510. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  1511. isp1362_hcd->hc_control = isp1362_read_reg32(isp1362_hcd, HCCONTROL);
  1512. switch (isp1362_hcd->hc_control & OHCI_CTRL_HCFS) {
  1513. case OHCI_USB_RESUME:
  1514. DBG(0, "%s: resume/suspend?\n", __func__);
  1515. isp1362_hcd->hc_control &= ~OHCI_CTRL_HCFS;
  1516. isp1362_hcd->hc_control |= OHCI_USB_RESET;
  1517. isp1362_write_reg32(isp1362_hcd, HCCONTROL, isp1362_hcd->hc_control);
  1518. /* FALL THROUGH */
  1519. case OHCI_USB_RESET:
  1520. status = -EBUSY;
  1521. pr_warning("%s: needs reinit!\n", __func__);
  1522. goto done;
  1523. case OHCI_USB_SUSPEND:
  1524. pr_warning("%s: already suspended?\n", __func__);
  1525. goto done;
  1526. }
  1527. DBG(0, "%s: suspend root hub\n", __func__);
  1528. /* First stop any processing */
  1529. hcd->state = HC_STATE_QUIESCING;
  1530. if (!list_empty(&isp1362_hcd->atl_queue.active) ||
  1531. !list_empty(&isp1362_hcd->intl_queue.active) ||
  1532. !list_empty(&isp1362_hcd->istl_queue[0] .active) ||
  1533. !list_empty(&isp1362_hcd->istl_queue[1] .active)) {
  1534. int limit;
  1535. isp1362_write_reg32(isp1362_hcd, HCATLSKIP, ~0);
  1536. isp1362_write_reg32(isp1362_hcd, HCINTLSKIP, ~0);
  1537. isp1362_write_reg16(isp1362_hcd, HCBUFSTAT, 0);
  1538. isp1362_write_reg16(isp1362_hcd, HCuPINTENB, 0);
  1539. isp1362_write_reg32(isp1362_hcd, HCINTSTAT, OHCI_INTR_SF);
  1540. DBG(0, "%s: stopping schedules ...\n", __func__);
  1541. limit = 2000;
  1542. while (limit > 0) {
  1543. udelay(250);
  1544. limit -= 250;
  1545. if (isp1362_read_reg32(isp1362_hcd, HCINTSTAT) & OHCI_INTR_SF)
  1546. break;
  1547. }
  1548. mdelay(7);
  1549. if (isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_ATL) {
  1550. u32 done_map = isp1362_read_reg32(isp1362_hcd, HCATLDONE);
  1551. finish_transfers(isp1362_hcd, done_map, &isp1362_hcd->atl_queue);
  1552. }
  1553. if (isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_INTL) {
  1554. u32 done_map = isp1362_read_reg32(isp1362_hcd, HCINTLDONE);
  1555. finish_transfers(isp1362_hcd, done_map, &isp1362_hcd->intl_queue);
  1556. }
  1557. if (isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_ISTL0)
  1558. finish_iso_transfers(isp1362_hcd, &isp1362_hcd->istl_queue[0]);
  1559. if (isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_ISTL1)
  1560. finish_iso_transfers(isp1362_hcd, &isp1362_hcd->istl_queue[1]);
  1561. }
  1562. DBG(0, "%s: HCINTSTAT: %08x\n", __func__,
  1563. isp1362_read_reg32(isp1362_hcd, HCINTSTAT));
  1564. isp1362_write_reg32(isp1362_hcd, HCINTSTAT,
  1565. isp1362_read_reg32(isp1362_hcd, HCINTSTAT));
  1566. /* Suspend hub */
  1567. isp1362_hcd->hc_control = OHCI_USB_SUSPEND;
  1568. isp1362_show_reg(isp1362_hcd, HCCONTROL);
  1569. isp1362_write_reg32(isp1362_hcd, HCCONTROL, isp1362_hcd->hc_control);
  1570. isp1362_show_reg(isp1362_hcd, HCCONTROL);
  1571. #if 1
  1572. isp1362_hcd->hc_control = isp1362_read_reg32(isp1362_hcd, HCCONTROL);
  1573. if ((isp1362_hcd->hc_control & OHCI_CTRL_HCFS) != OHCI_USB_SUSPEND) {
  1574. pr_err("%s: controller won't suspend %08x\n", __func__,
  1575. isp1362_hcd->hc_control);
  1576. status = -EBUSY;
  1577. } else
  1578. #endif
  1579. {
  1580. /* no resumes until devices finish suspending */
  1581. isp1362_hcd->next_statechange = jiffies + msecs_to_jiffies(5);
  1582. }
  1583. done:
  1584. if (status == 0) {
  1585. hcd->state = HC_STATE_SUSPENDED;
  1586. DBG(0, "%s: HCD suspended: %08x\n", __func__,
  1587. isp1362_read_reg32(isp1362_hcd, HCCONTROL));
  1588. }
  1589. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  1590. return status;
  1591. }
  1592. static int isp1362_bus_resume(struct usb_hcd *hcd)
  1593. {
  1594. struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
  1595. u32 port;
  1596. unsigned long flags;
  1597. int status = -EINPROGRESS;
  1598. if (time_before(jiffies, isp1362_hcd->next_statechange))
  1599. msleep(5);
  1600. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  1601. isp1362_hcd->hc_control = isp1362_read_reg32(isp1362_hcd, HCCONTROL);
  1602. pr_info("%s: HCCONTROL: %08x\n", __func__, isp1362_hcd->hc_control);
  1603. if (hcd->state == HC_STATE_RESUMING) {
  1604. pr_warning("%s: duplicate resume\n", __func__);
  1605. status = 0;
  1606. } else
  1607. switch (isp1362_hcd->hc_control & OHCI_CTRL_HCFS) {
  1608. case OHCI_USB_SUSPEND:
  1609. DBG(0, "%s: resume root hub\n", __func__);
  1610. isp1362_hcd->hc_control &= ~OHCI_CTRL_HCFS;
  1611. isp1362_hcd->hc_control |= OHCI_USB_RESUME;
  1612. isp1362_write_reg32(isp1362_hcd, HCCONTROL, isp1362_hcd->hc_control);
  1613. break;
  1614. case OHCI_USB_RESUME:
  1615. /* HCFS changes sometime after INTR_RD */
  1616. DBG(0, "%s: remote wakeup\n", __func__);
  1617. break;
  1618. case OHCI_USB_OPER:
  1619. DBG(0, "%s: odd resume\n", __func__);
  1620. status = 0;
  1621. hcd->self.root_hub->dev.power.power_state = PMSG_ON;
  1622. break;
  1623. default: /* RESET, we lost power */
  1624. DBG(0, "%s: root hub hardware reset\n", __func__);
  1625. status = -EBUSY;
  1626. }
  1627. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  1628. if (status == -EBUSY) {
  1629. DBG(0, "%s: Restarting HC\n", __func__);
  1630. isp1362_hc_stop(hcd);
  1631. return isp1362_hc_start(hcd);
  1632. }
  1633. if (status != -EINPROGRESS)
  1634. return status;
  1635. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  1636. port = isp1362_read_reg32(isp1362_hcd, HCRHDESCA) & RH_A_NDP;
  1637. while (port--) {
  1638. u32 stat = isp1362_read_reg32(isp1362_hcd, HCRHPORT1 + port);
  1639. /* force global, not selective, resume */
  1640. if (!(stat & RH_PS_PSS)) {
  1641. DBG(0, "%s: Not Resuming RH port %d\n", __func__, port);
  1642. continue;
  1643. }
  1644. DBG(0, "%s: Resuming RH port %d\n", __func__, port);
  1645. isp1362_write_reg32(isp1362_hcd, HCRHPORT1 + port, RH_PS_POCI);
  1646. }
  1647. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  1648. /* Some controllers (lucent) need extra-long delays */
  1649. hcd->state = HC_STATE_RESUMING;
  1650. mdelay(20 /* usb 11.5.1.10 */ + 15);
  1651. isp1362_hcd->hc_control = OHCI_USB_OPER;
  1652. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  1653. isp1362_show_reg(isp1362_hcd, HCCONTROL);
  1654. isp1362_write_reg32(isp1362_hcd, HCCONTROL, isp1362_hcd->hc_control);
  1655. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  1656. /* TRSMRCY */
  1657. msleep(10);
  1658. /* keep it alive for ~5x suspend + resume costs */
  1659. isp1362_hcd->next_statechange = jiffies + msecs_to_jiffies(250);
  1660. hcd->self.root_hub->dev.power.power_state = PMSG_ON;
  1661. hcd->state = HC_STATE_RUNNING;
  1662. return 0;
  1663. }
  1664. #else
  1665. #define isp1362_bus_suspend NULL
  1666. #define isp1362_bus_resume NULL
  1667. #endif
  1668. /*-------------------------------------------------------------------------*/
  1669. #ifdef STUB_DEBUG_FILE
  1670. static inline void create_debug_file(struct isp1362_hcd *isp1362_hcd)
  1671. {
  1672. }
  1673. static inline void remove_debug_file(struct isp1362_hcd *isp1362_hcd)
  1674. {
  1675. }
  1676. #else
  1677. #include <linux/proc_fs.h>
  1678. #include <linux/seq_file.h>
  1679. static void dump_irq(struct seq_file *s, char *label, u16 mask)
  1680. {
  1681. seq_printf(s, "%-15s %04x%s%s%s%s%s%s\n", label, mask,
  1682. mask & HCuPINT_CLKRDY ? " clkrdy" : "",
  1683. mask & HCuPINT_SUSP ? " susp" : "",
  1684. mask & HCuPINT_OPR ? " opr" : "",
  1685. mask & HCuPINT_EOT ? " eot" : "",
  1686. mask & HCuPINT_ATL ? " atl" : "",
  1687. mask & HCuPINT_SOF ? " sof" : "");
  1688. }
  1689. static void dump_int(struct seq_file *s, char *label, u32 mask)
  1690. {
  1691. seq_printf(s, "%-15s %08x%s%s%s%s%s%s%s\n", label, mask,
  1692. mask & OHCI_INTR_MIE ? " MIE" : "",
  1693. mask & OHCI_INTR_RHSC ? " rhsc" : "",
  1694. mask & OHCI_INTR_FNO ? " fno" : "",
  1695. mask & OHCI_INTR_UE ? " ue" : "",
  1696. mask & OHCI_INTR_RD ? " rd" : "",
  1697. mask & OHCI_INTR_SF ? " sof" : "",
  1698. mask & OHCI_INTR_SO ? " so" : "");
  1699. }
  1700. static void dump_ctrl(struct seq_file *s, char *label, u32 mask)
  1701. {
  1702. seq_printf(s, "%-15s %08x%s%s%s\n", label, mask,
  1703. mask & OHCI_CTRL_RWC ? " rwc" : "",
  1704. mask & OHCI_CTRL_RWE ? " rwe" : "",
  1705. ({
  1706. char *hcfs;
  1707. switch (mask & OHCI_CTRL_HCFS) {
  1708. case OHCI_USB_OPER:
  1709. hcfs = " oper";
  1710. break;
  1711. case OHCI_USB_RESET:
  1712. hcfs = " reset";
  1713. break;
  1714. case OHCI_USB_RESUME:
  1715. hcfs = " resume";
  1716. break;
  1717. case OHCI_USB_SUSPEND:
  1718. hcfs = " suspend";
  1719. break;
  1720. default:
  1721. hcfs = " ?";
  1722. }
  1723. hcfs;
  1724. }));
  1725. }
  1726. static void dump_regs(struct seq_file *s, struct isp1362_hcd *isp1362_hcd)
  1727. {
  1728. seq_printf(s, "HCREVISION [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCREVISION),
  1729. isp1362_read_reg32(isp1362_hcd, HCREVISION));
  1730. seq_printf(s, "HCCONTROL [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCCONTROL),
  1731. isp1362_read_reg32(isp1362_hcd, HCCONTROL));
  1732. seq_printf(s, "HCCMDSTAT [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCCMDSTAT),
  1733. isp1362_read_reg32(isp1362_hcd, HCCMDSTAT));
  1734. seq_printf(s, "HCINTSTAT [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCINTSTAT),
  1735. isp1362_read_reg32(isp1362_hcd, HCINTSTAT));
  1736. seq_printf(s, "HCINTENB [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCINTENB),
  1737. isp1362_read_reg32(isp1362_hcd, HCINTENB));
  1738. seq_printf(s, "HCFMINTVL [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCFMINTVL),
  1739. isp1362_read_reg32(isp1362_hcd, HCFMINTVL));
  1740. seq_printf(s, "HCFMREM [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCFMREM),
  1741. isp1362_read_reg32(isp1362_hcd, HCFMREM));
  1742. seq_printf(s, "HCFMNUM [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCFMNUM),
  1743. isp1362_read_reg32(isp1362_hcd, HCFMNUM));
  1744. seq_printf(s, "HCLSTHRESH [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCLSTHRESH),
  1745. isp1362_read_reg32(isp1362_hcd, HCLSTHRESH));
  1746. seq_printf(s, "HCRHDESCA [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCRHDESCA),
  1747. isp1362_read_reg32(isp1362_hcd, HCRHDESCA));
  1748. seq_printf(s, "HCRHDESCB [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCRHDESCB),
  1749. isp1362_read_reg32(isp1362_hcd, HCRHDESCB));
  1750. seq_printf(s, "HCRHSTATUS [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCRHSTATUS),
  1751. isp1362_read_reg32(isp1362_hcd, HCRHSTATUS));
  1752. seq_printf(s, "HCRHPORT1 [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCRHPORT1),
  1753. isp1362_read_reg32(isp1362_hcd, HCRHPORT1));
  1754. seq_printf(s, "HCRHPORT2 [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCRHPORT2),
  1755. isp1362_read_reg32(isp1362_hcd, HCRHPORT2));
  1756. seq_printf(s, "\n");
  1757. seq_printf(s, "HCHWCFG [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCHWCFG),
  1758. isp1362_read_reg16(isp1362_hcd, HCHWCFG));
  1759. seq_printf(s, "HCDMACFG [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCDMACFG),
  1760. isp1362_read_reg16(isp1362_hcd, HCDMACFG));
  1761. seq_printf(s, "HCXFERCTR [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCXFERCTR),
  1762. isp1362_read_reg16(isp1362_hcd, HCXFERCTR));
  1763. seq_printf(s, "HCuPINT [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCuPINT),
  1764. isp1362_read_reg16(isp1362_hcd, HCuPINT));
  1765. seq_printf(s, "HCuPINTENB [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCuPINTENB),
  1766. isp1362_read_reg16(isp1362_hcd, HCuPINTENB));
  1767. seq_printf(s, "HCCHIPID [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCCHIPID),
  1768. isp1362_read_reg16(isp1362_hcd, HCCHIPID));
  1769. seq_printf(s, "HCSCRATCH [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCSCRATCH),
  1770. isp1362_read_reg16(isp1362_hcd, HCSCRATCH));
  1771. seq_printf(s, "HCBUFSTAT [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCBUFSTAT),
  1772. isp1362_read_reg16(isp1362_hcd, HCBUFSTAT));
  1773. seq_printf(s, "HCDIRADDR [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCDIRADDR),
  1774. isp1362_read_reg32(isp1362_hcd, HCDIRADDR));
  1775. #if 0
  1776. seq_printf(s, "HCDIRDATA [%02x] %04x\n", ISP1362_REG_NO(HCDIRDATA),
  1777. isp1362_read_reg16(isp1362_hcd, HCDIRDATA));
  1778. #endif
  1779. seq_printf(s, "HCISTLBUFSZ[%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCISTLBUFSZ),
  1780. isp1362_read_reg16(isp1362_hcd, HCISTLBUFSZ));
  1781. seq_printf(s, "HCISTLRATE [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCISTLRATE),
  1782. isp1362_read_reg16(isp1362_hcd, HCISTLRATE));
  1783. seq_printf(s, "\n");
  1784. seq_printf(s, "HCINTLBUFSZ[%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLBUFSZ),
  1785. isp1362_read_reg16(isp1362_hcd, HCINTLBUFSZ));
  1786. seq_printf(s, "HCINTLBLKSZ[%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLBLKSZ),
  1787. isp1362_read_reg16(isp1362_hcd, HCINTLBLKSZ));
  1788. seq_printf(s, "HCINTLDONE [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLDONE),
  1789. isp1362_read_reg32(isp1362_hcd, HCINTLDONE));
  1790. seq_printf(s, "HCINTLSKIP [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLSKIP),
  1791. isp1362_read_reg32(isp1362_hcd, HCINTLSKIP));
  1792. seq_printf(s, "HCINTLLAST [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLLAST),
  1793. isp1362_read_reg32(isp1362_hcd, HCINTLLAST));
  1794. seq_printf(s, "HCINTLCURR [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLCURR),
  1795. isp1362_read_reg16(isp1362_hcd, HCINTLCURR));
  1796. seq_printf(s, "\n");
  1797. seq_printf(s, "HCATLBUFSZ [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCATLBUFSZ),
  1798. isp1362_read_reg16(isp1362_hcd, HCATLBUFSZ));
  1799. seq_printf(s, "HCATLBLKSZ [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCATLBLKSZ),
  1800. isp1362_read_reg16(isp1362_hcd, HCATLBLKSZ));
  1801. #if 0
  1802. seq_printf(s, "HCATLDONE [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCATLDONE),
  1803. isp1362_read_reg32(isp1362_hcd, HCATLDONE));
  1804. #endif
  1805. seq_printf(s, "HCATLSKIP [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCATLSKIP),
  1806. isp1362_read_reg32(isp1362_hcd, HCATLSKIP));
  1807. seq_printf(s, "HCATLLAST [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCATLLAST),
  1808. isp1362_read_reg32(isp1362_hcd, HCATLLAST));
  1809. seq_printf(s, "HCATLCURR [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCATLCURR),
  1810. isp1362_read_reg16(isp1362_hcd, HCATLCURR));
  1811. seq_printf(s, "\n");
  1812. seq_printf(s, "HCATLDTC [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCATLDTC),
  1813. isp1362_read_reg16(isp1362_hcd, HCATLDTC));
  1814. seq_printf(s, "HCATLDTCTO [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCATLDTCTO),
  1815. isp1362_read_reg16(isp1362_hcd, HCATLDTCTO));
  1816. }
  1817. static int proc_isp1362_show(struct seq_file *s, void *unused)
  1818. {
  1819. struct isp1362_hcd *isp1362_hcd = s->private;
  1820. struct isp1362_ep *ep;
  1821. int i;
  1822. seq_printf(s, "%s\n%s version %s\n",
  1823. isp1362_hcd_to_hcd(isp1362_hcd)->product_desc, hcd_name, DRIVER_VERSION);
  1824. /* collect statistics to help estimate potential win for
  1825. * DMA engines that care about alignment (PXA)
  1826. */
  1827. seq_printf(s, "alignment: 16b/%ld 8b/%ld 4b/%ld 2b/%ld 1b/%ld\n",
  1828. isp1362_hcd->stat16, isp1362_hcd->stat8, isp1362_hcd->stat4,
  1829. isp1362_hcd->stat2, isp1362_hcd->stat1);
  1830. seq_printf(s, "max # ptds in ATL fifo: %d\n", isp1362_hcd->atl_queue.stat_maxptds);
  1831. seq_printf(s, "max # ptds in INTL fifo: %d\n", isp1362_hcd->intl_queue.stat_maxptds);
  1832. seq_printf(s, "max # ptds in ISTL fifo: %d\n",
  1833. max(isp1362_hcd->istl_queue[0] .stat_maxptds,
  1834. isp1362_hcd->istl_queue[1] .stat_maxptds));
  1835. /* FIXME: don't show the following in suspended state */
  1836. spin_lock_irq(&isp1362_hcd->lock);
  1837. dump_irq(s, "hc_irq_enable", isp1362_read_reg16(isp1362_hcd, HCuPINTENB));
  1838. dump_irq(s, "hc_irq_status", isp1362_read_reg16(isp1362_hcd, HCuPINT));
  1839. dump_int(s, "ohci_int_enable", isp1362_read_reg32(isp1362_hcd, HCINTENB));
  1840. dump_int(s, "ohci_int_status", isp1362_read_reg32(isp1362_hcd, HCINTSTAT));
  1841. dump_ctrl(s, "ohci_control", isp1362_read_reg32(isp1362_hcd, HCCONTROL));
  1842. for (i = 0; i < NUM_ISP1362_IRQS; i++)
  1843. if (isp1362_hcd->irq_stat[i])
  1844. seq_printf(s, "%-15s: %d\n",
  1845. ISP1362_INT_NAME(i), isp1362_hcd->irq_stat[i]);
  1846. dump_regs(s, isp1362_hcd);
  1847. list_for_each_entry(ep, &isp1362_hcd->async, schedule) {
  1848. struct urb *urb;
  1849. seq_printf(s, "%p, ep%d%s, maxpacket %d:\n", ep, ep->epnum,
  1850. ({
  1851. char *s;
  1852. switch (ep->nextpid) {
  1853. case USB_PID_IN:
  1854. s = "in";
  1855. break;
  1856. case USB_PID_OUT:
  1857. s = "out";
  1858. break;
  1859. case USB_PID_SETUP:
  1860. s = "setup";
  1861. break;
  1862. case USB_PID_ACK:
  1863. s = "status";
  1864. break;
  1865. default:
  1866. s = "?";
  1867. break;
  1868. };
  1869. s;}), ep->maxpacket) ;
  1870. list_for_each_entry(urb, &ep->hep->urb_list, urb_list) {
  1871. seq_printf(s, " urb%p, %d/%d\n", urb,
  1872. urb->actual_length,
  1873. urb->transfer_buffer_length);
  1874. }
  1875. }
  1876. if (!list_empty(&isp1362_hcd->async))
  1877. seq_printf(s, "\n");
  1878. dump_ptd_queue(&isp1362_hcd->atl_queue);
  1879. seq_printf(s, "periodic size= %d\n", PERIODIC_SIZE);
  1880. list_for_each_entry(ep, &isp1362_hcd->periodic, schedule) {
  1881. seq_printf(s, "branch:%2d load:%3d PTD[%d] $%04x:\n", ep->branch,
  1882. isp1362_hcd->load[ep->branch], ep->ptd_index, ep->ptd_offset);
  1883. seq_printf(s, " %d/%p (%sdev%d ep%d%s max %d)\n",
  1884. ep->interval, ep,
  1885. (ep->udev->speed == USB_SPEED_FULL) ? "" : "ls ",
  1886. ep->udev->devnum, ep->epnum,
  1887. (ep->epnum == 0) ? "" :
  1888. ((ep->nextpid == USB_PID_IN) ?
  1889. "in" : "out"), ep->maxpacket);
  1890. }
  1891. dump_ptd_queue(&isp1362_hcd->intl_queue);
  1892. seq_printf(s, "ISO:\n");
  1893. list_for_each_entry(ep, &isp1362_hcd->isoc, schedule) {
  1894. seq_printf(s, " %d/%p (%sdev%d ep%d%s max %d)\n",
  1895. ep->interval, ep,
  1896. (ep->udev->speed == USB_SPEED_FULL) ? "" : "ls ",
  1897. ep->udev->devnum, ep->epnum,
  1898. (ep->epnum == 0) ? "" :
  1899. ((ep->nextpid == USB_PID_IN) ?
  1900. "in" : "out"), ep->maxpacket);
  1901. }
  1902. spin_unlock_irq(&isp1362_hcd->lock);
  1903. seq_printf(s, "\n");
  1904. return 0;
  1905. }
  1906. static int proc_isp1362_open(struct inode *inode, struct file *file)
  1907. {
  1908. return single_open(file, proc_isp1362_show, PDE(inode)->data);
  1909. }
  1910. static const struct file_operations proc_ops = {
  1911. .open = proc_isp1362_open,
  1912. .read = seq_read,
  1913. .llseek = seq_lseek,
  1914. .release = single_release,
  1915. };
  1916. /* expect just one isp1362_hcd per system */
  1917. static const char proc_filename[] = "driver/isp1362";
  1918. static void create_debug_file(struct isp1362_hcd *isp1362_hcd)
  1919. {
  1920. struct proc_dir_entry *pde;
  1921. pde = create_proc_entry(proc_filename, 0, NULL);
  1922. if (pde == NULL) {
  1923. pr_warning("%s: Failed to create debug file '%s'\n", __func__, proc_filename);
  1924. return;
  1925. }
  1926. pde->proc_fops = &proc_ops;
  1927. pde->data = isp1362_hcd;
  1928. isp1362_hcd->pde = pde;
  1929. }
  1930. static void remove_debug_file(struct isp1362_hcd *isp1362_hcd)
  1931. {
  1932. if (isp1362_hcd->pde)
  1933. remove_proc_entry(proc_filename, NULL);
  1934. }
  1935. #endif
  1936. /*-------------------------------------------------------------------------*/
  1937. static void __isp1362_sw_reset(struct isp1362_hcd *isp1362_hcd)
  1938. {
  1939. int tmp = 20;
  1940. isp1362_write_reg16(isp1362_hcd, HCSWRES, HCSWRES_MAGIC);
  1941. isp1362_write_reg32(isp1362_hcd, HCCMDSTAT, OHCI_HCR);
  1942. while (--tmp) {
  1943. mdelay(1);
  1944. if (!(isp1362_read_reg32(isp1362_hcd, HCCMDSTAT) & OHCI_HCR))
  1945. break;
  1946. }
  1947. if (!tmp)
  1948. pr_err("Software reset timeout\n");
  1949. }
  1950. static void isp1362_sw_reset(struct isp1362_hcd *isp1362_hcd)
  1951. {
  1952. unsigned long flags;
  1953. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  1954. __isp1362_sw_reset(isp1362_hcd);
  1955. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  1956. }
  1957. static int isp1362_mem_config(struct usb_hcd *hcd)
  1958. {
  1959. struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
  1960. unsigned long flags;
  1961. u32 total;
  1962. u16 istl_size = ISP1362_ISTL_BUFSIZE;
  1963. u16 intl_blksize = ISP1362_INTL_BLKSIZE + PTD_HEADER_SIZE;
  1964. u16 intl_size = ISP1362_INTL_BUFFERS * intl_blksize;
  1965. u16 atl_blksize = ISP1362_ATL_BLKSIZE + PTD_HEADER_SIZE;
  1966. u16 atl_buffers = (ISP1362_BUF_SIZE - (istl_size + intl_size)) / atl_blksize;
  1967. u16 atl_size;
  1968. int i;
  1969. WARN_ON(istl_size & 3);
  1970. WARN_ON(atl_blksize & 3);
  1971. WARN_ON(intl_blksize & 3);
  1972. WARN_ON(atl_blksize < PTD_HEADER_SIZE);
  1973. WARN_ON(intl_blksize < PTD_HEADER_SIZE);
  1974. BUG_ON((unsigned)ISP1362_INTL_BUFFERS > 32);
  1975. if (atl_buffers > 32)
  1976. atl_buffers = 32;
  1977. atl_size = atl_buffers * atl_blksize;
  1978. total = atl_size + intl_size + istl_size;
  1979. dev_info(hcd->self.controller, "ISP1362 Memory usage:\n");
  1980. dev_info(hcd->self.controller, " ISTL: 2 * %4d: %4d @ $%04x:$%04x\n",
  1981. istl_size / 2, istl_size, 0, istl_size / 2);
  1982. dev_info(hcd->self.controller, " INTL: %4d * (%3zu+8): %4d @ $%04x\n",
  1983. ISP1362_INTL_BUFFERS, intl_blksize - PTD_HEADER_SIZE,
  1984. intl_size, istl_size);
  1985. dev_info(hcd->self.controller, " ATL : %4d * (%3zu+8): %4d @ $%04x\n",
  1986. atl_buffers, atl_blksize - PTD_HEADER_SIZE,
  1987. atl_size, istl_size + intl_size);
  1988. dev_info(hcd->self.controller, " USED/FREE: %4d %4d\n", total,
  1989. ISP1362_BUF_SIZE - total);
  1990. if (total > ISP1362_BUF_SIZE) {
  1991. dev_err(hcd->self.controller, "%s: Memory requested: %d, available %d\n",
  1992. __func__, total, ISP1362_BUF_SIZE);
  1993. return -ENOMEM;
  1994. }
  1995. total = istl_size + intl_size + atl_size;
  1996. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  1997. for (i = 0; i < 2; i++) {
  1998. isp1362_hcd->istl_queue[i].buf_start = i * istl_size / 2,
  1999. isp1362_hcd->istl_queue[i].buf_size = istl_size / 2;
  2000. isp1362_hcd->istl_queue[i].blk_size = 4;
  2001. INIT_LIST_HEAD(&isp1362_hcd->istl_queue[i].active);
  2002. snprintf(isp1362_hcd->istl_queue[i].name,
  2003. sizeof(isp1362_hcd->istl_queue[i].name), "ISTL%d", i);
  2004. DBG(3, "%s: %5s buf $%04x %d\n", __func__,
  2005. isp1362_hcd->istl_queue[i].name,
  2006. isp1362_hcd->istl_queue[i].buf_start,
  2007. isp1362_hcd->istl_queue[i].buf_size);
  2008. }
  2009. isp1362_write_reg16(isp1362_hcd, HCISTLBUFSZ, istl_size / 2);
  2010. isp1362_hcd->intl_queue.buf_start = istl_size;
  2011. isp1362_hcd->intl_queue.buf_size = intl_size;
  2012. isp1362_hcd->intl_queue.buf_count = ISP1362_INTL_BUFFERS;
  2013. isp1362_hcd->intl_queue.blk_size = intl_blksize;
  2014. isp1362_hcd->intl_queue.buf_avail = isp1362_hcd->intl_queue.buf_count;
  2015. isp1362_hcd->intl_queue.skip_map = ~0;
  2016. INIT_LIST_HEAD(&isp1362_hcd->intl_queue.active);
  2017. isp1362_write_reg16(isp1362_hcd, HCINTLBUFSZ,
  2018. isp1362_hcd->intl_queue.buf_size);
  2019. isp1362_write_reg16(isp1362_hcd, HCINTLBLKSZ,
  2020. isp1362_hcd->intl_queue.blk_size - PTD_HEADER_SIZE);
  2021. isp1362_write_reg32(isp1362_hcd, HCINTLSKIP, ~0);
  2022. isp1362_write_reg32(isp1362_hcd, HCINTLLAST,
  2023. 1 << (ISP1362_INTL_BUFFERS - 1));
  2024. isp1362_hcd->atl_queue.buf_start = istl_size + intl_size;
  2025. isp1362_hcd->atl_queue.buf_size = atl_size;
  2026. isp1362_hcd->atl_queue.buf_count = atl_buffers;
  2027. isp1362_hcd->atl_queue.blk_size = atl_blksize;
  2028. isp1362_hcd->atl_queue.buf_avail = isp1362_hcd->atl_queue.buf_count;
  2029. isp1362_hcd->atl_queue.skip_map = ~0;
  2030. INIT_LIST_HEAD(&isp1362_hcd->atl_queue.active);
  2031. isp1362_write_reg16(isp1362_hcd, HCATLBUFSZ,
  2032. isp1362_hcd->atl_queue.buf_size);
  2033. isp1362_write_reg16(isp1362_hcd, HCATLBLKSZ,
  2034. isp1362_hcd->atl_queue.blk_size - PTD_HEADER_SIZE);
  2035. isp1362_write_reg32(isp1362_hcd, HCATLSKIP, ~0);
  2036. isp1362_write_reg32(isp1362_hcd, HCATLLAST,
  2037. 1 << (atl_buffers - 1));
  2038. snprintf(isp1362_hcd->atl_queue.name,
  2039. sizeof(isp1362_hcd->atl_queue.name), "ATL");
  2040. snprintf(isp1362_hcd->intl_queue.name,
  2041. sizeof(isp1362_hcd->intl_queue.name), "INTL");
  2042. DBG(3, "%s: %5s buf $%04x %2d * %4d = %4d\n", __func__,
  2043. isp1362_hcd->intl_queue.name,
  2044. isp1362_hcd->intl_queue.buf_start,
  2045. ISP1362_INTL_BUFFERS, isp1362_hcd->intl_queue.blk_size,
  2046. isp1362_hcd->intl_queue.buf_size);
  2047. DBG(3, "%s: %5s buf $%04x %2d * %4d = %4d\n", __func__,
  2048. isp1362_hcd->atl_queue.name,
  2049. isp1362_hcd->atl_queue.buf_start,
  2050. atl_buffers, isp1362_hcd->atl_queue.blk_size,
  2051. isp1362_hcd->atl_queue.buf_size);
  2052. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  2053. return 0;
  2054. }
  2055. static int isp1362_hc_reset(struct usb_hcd *hcd)
  2056. {
  2057. int ret = 0;
  2058. struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
  2059. unsigned long t;
  2060. unsigned long timeout = 100;
  2061. unsigned long flags;
  2062. int clkrdy = 0;
  2063. pr_info("%s:\n", __func__);
  2064. if (isp1362_hcd->board && isp1362_hcd->board->reset) {
  2065. isp1362_hcd->board->reset(hcd->self.controller, 1);
  2066. msleep(20);
  2067. if (isp1362_hcd->board->clock)
  2068. isp1362_hcd->board->clock(hcd->self.controller, 1);
  2069. isp1362_hcd->board->reset(hcd->self.controller, 0);
  2070. } else
  2071. isp1362_sw_reset(isp1362_hcd);
  2072. /* chip has been reset. First we need to see a clock */
  2073. t = jiffies + msecs_to_jiffies(timeout);
  2074. while (!clkrdy && time_before_eq(jiffies, t)) {
  2075. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  2076. clkrdy = isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_CLKRDY;
  2077. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  2078. if (!clkrdy)
  2079. msleep(4);
  2080. }
  2081. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  2082. isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_CLKRDY);
  2083. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  2084. if (!clkrdy) {
  2085. pr_err("Clock not ready after %lums\n", timeout);
  2086. ret = -ENODEV;
  2087. }
  2088. return ret;
  2089. }
  2090. static void isp1362_hc_stop(struct usb_hcd *hcd)
  2091. {
  2092. struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
  2093. unsigned long flags;
  2094. u32 tmp;
  2095. pr_info("%s:\n", __func__);
  2096. del_timer_sync(&hcd->rh_timer);
  2097. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  2098. isp1362_write_reg16(isp1362_hcd, HCuPINTENB, 0);
  2099. /* Switch off power for all ports */
  2100. tmp = isp1362_read_reg32(isp1362_hcd, HCRHDESCA);
  2101. tmp &= ~(RH_A_NPS | RH_A_PSM);
  2102. isp1362_write_reg32(isp1362_hcd, HCRHDESCA, tmp);
  2103. isp1362_write_reg32(isp1362_hcd, HCRHSTATUS, RH_HS_LPS);
  2104. /* Reset the chip */
  2105. if (isp1362_hcd->board && isp1362_hcd->board->reset)
  2106. isp1362_hcd->board->reset(hcd->self.controller, 1);
  2107. else
  2108. __isp1362_sw_reset(isp1362_hcd);
  2109. if (isp1362_hcd->board && isp1362_hcd->board->clock)
  2110. isp1362_hcd->board->clock(hcd->self.controller, 0);
  2111. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  2112. }
  2113. #ifdef CHIP_BUFFER_TEST
  2114. static int isp1362_chip_test(struct isp1362_hcd *isp1362_hcd)
  2115. {
  2116. int ret = 0;
  2117. u16 *ref;
  2118. unsigned long flags;
  2119. ref = kmalloc(2 * ISP1362_BUF_SIZE, GFP_KERNEL);
  2120. if (ref) {
  2121. int offset;
  2122. u16 *tst = &ref[ISP1362_BUF_SIZE / 2];
  2123. for (offset = 0; offset < ISP1362_BUF_SIZE / 2; offset++) {
  2124. ref[offset] = ~offset;
  2125. tst[offset] = offset;
  2126. }
  2127. for (offset = 0; offset < 4; offset++) {
  2128. int j;
  2129. for (j = 0; j < 8; j++) {
  2130. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  2131. isp1362_write_buffer(isp1362_hcd, (u8 *)ref + offset, 0, j);
  2132. isp1362_read_buffer(isp1362_hcd, (u8 *)tst + offset, 0, j);
  2133. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  2134. if (memcmp(ref, tst, j)) {
  2135. ret = -ENODEV;
  2136. pr_err("%s: memory check with %d byte offset %d failed\n",
  2137. __func__, j, offset);
  2138. dump_data((u8 *)ref + offset, j);
  2139. dump_data((u8 *)tst + offset, j);
  2140. }
  2141. }
  2142. }
  2143. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  2144. isp1362_write_buffer(isp1362_hcd, ref, 0, ISP1362_BUF_SIZE);
  2145. isp1362_read_buffer(isp1362_hcd, tst, 0, ISP1362_BUF_SIZE);
  2146. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  2147. if (memcmp(ref, tst, ISP1362_BUF_SIZE)) {
  2148. ret = -ENODEV;
  2149. pr_err("%s: memory check failed\n", __func__);
  2150. dump_data((u8 *)tst, ISP1362_BUF_SIZE / 2);
  2151. }
  2152. for (offset = 0; offset < 256; offset++) {
  2153. int test_size = 0;
  2154. yield();
  2155. memset(tst, 0, ISP1362_BUF_SIZE);
  2156. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  2157. isp1362_write_buffer(isp1362_hcd, tst, 0, ISP1362_BUF_SIZE);
  2158. isp1362_read_buffer(isp1362_hcd, tst, 0, ISP1362_BUF_SIZE);
  2159. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  2160. if (memcmp(tst, tst + (ISP1362_BUF_SIZE / (2 * sizeof(*tst))),
  2161. ISP1362_BUF_SIZE / 2)) {
  2162. pr_err("%s: Failed to clear buffer\n", __func__);
  2163. dump_data((u8 *)tst, ISP1362_BUF_SIZE);
  2164. break;
  2165. }
  2166. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  2167. isp1362_write_buffer(isp1362_hcd, ref, offset * 2, PTD_HEADER_SIZE);
  2168. isp1362_write_buffer(isp1362_hcd, ref + PTD_HEADER_SIZE / sizeof(*ref),
  2169. offset * 2 + PTD_HEADER_SIZE, test_size);
  2170. isp1362_read_buffer(isp1362_hcd, tst, offset * 2,
  2171. PTD_HEADER_SIZE + test_size);
  2172. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  2173. if (memcmp(ref, tst, PTD_HEADER_SIZE + test_size)) {
  2174. dump_data(((u8 *)ref) + offset, PTD_HEADER_SIZE + test_size);
  2175. dump_data((u8 *)tst, PTD_HEADER_SIZE + test_size);
  2176. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  2177. isp1362_read_buffer(isp1362_hcd, tst, offset * 2,
  2178. PTD_HEADER_SIZE + test_size);
  2179. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  2180. if (memcmp(ref, tst, PTD_HEADER_SIZE + test_size)) {
  2181. ret = -ENODEV;
  2182. pr_err("%s: memory check with offset %02x failed\n",
  2183. __func__, offset);
  2184. break;
  2185. }
  2186. pr_warning("%s: memory check with offset %02x ok after second read\n",
  2187. __func__, offset);
  2188. }
  2189. }
  2190. kfree(ref);
  2191. }
  2192. return ret;
  2193. }
  2194. #endif
  2195. static int isp1362_hc_start(struct usb_hcd *hcd)
  2196. {
  2197. int ret;
  2198. struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
  2199. struct isp1362_platform_data *board = isp1362_hcd->board;
  2200. u16 hwcfg;
  2201. u16 chipid;
  2202. unsigned long flags;
  2203. pr_info("%s:\n", __func__);
  2204. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  2205. chipid = isp1362_read_reg16(isp1362_hcd, HCCHIPID);
  2206. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  2207. if ((chipid & HCCHIPID_MASK) != HCCHIPID_MAGIC) {
  2208. pr_err("%s: Invalid chip ID %04x\n", __func__, chipid);
  2209. return -ENODEV;
  2210. }
  2211. #ifdef CHIP_BUFFER_TEST
  2212. ret = isp1362_chip_test(isp1362_hcd);
  2213. if (ret)
  2214. return -ENODEV;
  2215. #endif
  2216. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  2217. /* clear interrupt status and disable all interrupt sources */
  2218. isp1362_write_reg16(isp1362_hcd, HCuPINT, 0xff);
  2219. isp1362_write_reg16(isp1362_hcd, HCuPINTENB, 0);
  2220. /* HW conf */
  2221. hwcfg = HCHWCFG_INT_ENABLE | HCHWCFG_DBWIDTH(1);
  2222. if (board->sel15Kres)
  2223. hwcfg |= HCHWCFG_PULLDOWN_DS2 |
  2224. ((MAX_ROOT_PORTS > 1) ? HCHWCFG_PULLDOWN_DS1 : 0);
  2225. if (board->clknotstop)
  2226. hwcfg |= HCHWCFG_CLKNOTSTOP;
  2227. if (board->oc_enable)
  2228. hwcfg |= HCHWCFG_ANALOG_OC;
  2229. if (board->int_act_high)
  2230. hwcfg |= HCHWCFG_INT_POL;
  2231. if (board->int_edge_triggered)
  2232. hwcfg |= HCHWCFG_INT_TRIGGER;
  2233. if (board->dreq_act_high)
  2234. hwcfg |= HCHWCFG_DREQ_POL;
  2235. if (board->dack_act_high)
  2236. hwcfg |= HCHWCFG_DACK_POL;
  2237. isp1362_write_reg16(isp1362_hcd, HCHWCFG, hwcfg);
  2238. isp1362_show_reg(isp1362_hcd, HCHWCFG);
  2239. isp1362_write_reg16(isp1362_hcd, HCDMACFG, 0);
  2240. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  2241. ret = isp1362_mem_config(hcd);
  2242. if (ret)
  2243. return ret;
  2244. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  2245. /* Root hub conf */
  2246. isp1362_hcd->rhdesca = 0;
  2247. if (board->no_power_switching)
  2248. isp1362_hcd->rhdesca |= RH_A_NPS;
  2249. if (board->power_switching_mode)
  2250. isp1362_hcd->rhdesca |= RH_A_PSM;
  2251. if (board->potpg)
  2252. isp1362_hcd->rhdesca |= (board->potpg << 24) & RH_A_POTPGT;
  2253. else
  2254. isp1362_hcd->rhdesca |= (25 << 24) & RH_A_POTPGT;
  2255. isp1362_write_reg32(isp1362_hcd, HCRHDESCA, isp1362_hcd->rhdesca & ~RH_A_OCPM);
  2256. isp1362_write_reg32(isp1362_hcd, HCRHDESCA, isp1362_hcd->rhdesca | RH_A_OCPM);
  2257. isp1362_hcd->rhdesca = isp1362_read_reg32(isp1362_hcd, HCRHDESCA);
  2258. isp1362_hcd->rhdescb = RH_B_PPCM;
  2259. isp1362_write_reg32(isp1362_hcd, HCRHDESCB, isp1362_hcd->rhdescb);
  2260. isp1362_hcd->rhdescb = isp1362_read_reg32(isp1362_hcd, HCRHDESCB);
  2261. isp1362_read_reg32(isp1362_hcd, HCFMINTVL);
  2262. isp1362_write_reg32(isp1362_hcd, HCFMINTVL, (FSMP(FI) << 16) | FI);
  2263. isp1362_write_reg32(isp1362_hcd, HCLSTHRESH, LSTHRESH);
  2264. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  2265. isp1362_hcd->hc_control = OHCI_USB_OPER;
  2266. hcd->state = HC_STATE_RUNNING;
  2267. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  2268. /* Set up interrupts */
  2269. isp1362_hcd->intenb = OHCI_INTR_MIE | OHCI_INTR_RHSC | OHCI_INTR_UE;
  2270. isp1362_hcd->intenb |= OHCI_INTR_RD;
  2271. isp1362_hcd->irqenb = HCuPINT_OPR | HCuPINT_SUSP;
  2272. isp1362_write_reg32(isp1362_hcd, HCINTENB, isp1362_hcd->intenb);
  2273. isp1362_write_reg16(isp1362_hcd, HCuPINTENB, isp1362_hcd->irqenb);
  2274. /* Go operational */
  2275. isp1362_write_reg32(isp1362_hcd, HCCONTROL, isp1362_hcd->hc_control);
  2276. /* enable global power */
  2277. isp1362_write_reg32(isp1362_hcd, HCRHSTATUS, RH_HS_LPSC | RH_HS_DRWE);
  2278. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  2279. return 0;
  2280. }
  2281. /*-------------------------------------------------------------------------*/
  2282. static struct hc_driver isp1362_hc_driver = {
  2283. .description = hcd_name,
  2284. .product_desc = "ISP1362 Host Controller",
  2285. .hcd_priv_size = sizeof(struct isp1362_hcd),
  2286. .irq = isp1362_irq,
  2287. .flags = HCD_USB11 | HCD_MEMORY,
  2288. .reset = isp1362_hc_reset,
  2289. .start = isp1362_hc_start,
  2290. .stop = isp1362_hc_stop,
  2291. .urb_enqueue = isp1362_urb_enqueue,
  2292. .urb_dequeue = isp1362_urb_dequeue,
  2293. .endpoint_disable = isp1362_endpoint_disable,
  2294. .get_frame_number = isp1362_get_frame,
  2295. .hub_status_data = isp1362_hub_status_data,
  2296. .hub_control = isp1362_hub_control,
  2297. .bus_suspend = isp1362_bus_suspend,
  2298. .bus_resume = isp1362_bus_resume,
  2299. };
  2300. /*-------------------------------------------------------------------------*/
  2301. static int __devexit isp1362_remove(struct platform_device *pdev)
  2302. {
  2303. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  2304. struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
  2305. struct resource *res;
  2306. remove_debug_file(isp1362_hcd);
  2307. DBG(0, "%s: Removing HCD\n", __func__);
  2308. usb_remove_hcd(hcd);
  2309. DBG(0, "%s: Unmapping data_reg @ %p\n", __func__,
  2310. isp1362_hcd->data_reg);
  2311. iounmap(isp1362_hcd->data_reg);
  2312. DBG(0, "%s: Unmapping addr_reg @ %p\n", __func__,
  2313. isp1362_hcd->addr_reg);
  2314. iounmap(isp1362_hcd->addr_reg);
  2315. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  2316. DBG(0, "%s: release mem_region: %08lx\n", __func__, (long unsigned int)res->start);
  2317. if (res)
  2318. release_mem_region(res->start, resource_size(res));
  2319. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  2320. DBG(0, "%s: release mem_region: %08lx\n", __func__, (long unsigned int)res->start);
  2321. if (res)
  2322. release_mem_region(res->start, resource_size(res));
  2323. DBG(0, "%s: put_hcd\n", __func__);
  2324. usb_put_hcd(hcd);
  2325. DBG(0, "%s: Done\n", __func__);
  2326. return 0;
  2327. }
  2328. static int __devinit isp1362_probe(struct platform_device *pdev)
  2329. {
  2330. struct usb_hcd *hcd;
  2331. struct isp1362_hcd *isp1362_hcd;
  2332. struct resource *addr, *data;
  2333. void __iomem *addr_reg;
  2334. void __iomem *data_reg;
  2335. int irq;
  2336. int retval = 0;
  2337. struct resource *irq_res;
  2338. unsigned int irq_flags = 0;
  2339. /* basic sanity checks first. board-specific init logic should
  2340. * have initialized this the three resources and probably board
  2341. * specific platform_data. we don't probe for IRQs, and do only
  2342. * minimal sanity checking.
  2343. */
  2344. if (pdev->num_resources < 3) {
  2345. retval = -ENODEV;
  2346. goto err1;
  2347. }
  2348. data = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  2349. addr = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  2350. irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  2351. if (!addr || !data || !irq_res) {
  2352. retval = -ENODEV;
  2353. goto err1;
  2354. }
  2355. irq = irq_res->start;
  2356. if (pdev->dev.dma_mask) {
  2357. DBG(1, "won't do DMA");
  2358. retval = -ENODEV;
  2359. goto err1;
  2360. }
  2361. if (!request_mem_region(addr->start, resource_size(addr), hcd_name)) {
  2362. retval = -EBUSY;
  2363. goto err1;
  2364. }
  2365. addr_reg = ioremap(addr->start, resource_size(addr));
  2366. if (addr_reg == NULL) {
  2367. retval = -ENOMEM;
  2368. goto err2;
  2369. }
  2370. if (!request_mem_region(data->start, resource_size(data), hcd_name)) {
  2371. retval = -EBUSY;
  2372. goto err3;
  2373. }
  2374. data_reg = ioremap(data->start, resource_size(data));
  2375. if (data_reg == NULL) {
  2376. retval = -ENOMEM;
  2377. goto err4;
  2378. }
  2379. /* allocate and initialize hcd */
  2380. hcd = usb_create_hcd(&isp1362_hc_driver, &pdev->dev, dev_name(&pdev->dev));
  2381. if (!hcd) {
  2382. retval = -ENOMEM;
  2383. goto err5;
  2384. }
  2385. hcd->rsrc_start = data->start;
  2386. isp1362_hcd = hcd_to_isp1362_hcd(hcd);
  2387. isp1362_hcd->data_reg = data_reg;
  2388. isp1362_hcd->addr_reg = addr_reg;
  2389. isp1362_hcd->next_statechange = jiffies;
  2390. spin_lock_init(&isp1362_hcd->lock);
  2391. INIT_LIST_HEAD(&isp1362_hcd->async);
  2392. INIT_LIST_HEAD(&isp1362_hcd->periodic);
  2393. INIT_LIST_HEAD(&isp1362_hcd->isoc);
  2394. INIT_LIST_HEAD(&isp1362_hcd->remove_list);
  2395. isp1362_hcd->board = pdev->dev.platform_data;
  2396. #if USE_PLATFORM_DELAY
  2397. if (!isp1362_hcd->board->delay) {
  2398. dev_err(hcd->self.controller, "No platform delay function given\n");
  2399. retval = -ENODEV;
  2400. goto err6;
  2401. }
  2402. #endif
  2403. if (irq_res->flags & IORESOURCE_IRQ_HIGHEDGE)
  2404. irq_flags |= IRQF_TRIGGER_RISING;
  2405. if (irq_res->flags & IORESOURCE_IRQ_LOWEDGE)
  2406. irq_flags |= IRQF_TRIGGER_FALLING;
  2407. if (irq_res->flags & IORESOURCE_IRQ_HIGHLEVEL)
  2408. irq_flags |= IRQF_TRIGGER_HIGH;
  2409. if (irq_res->flags & IORESOURCE_IRQ_LOWLEVEL)
  2410. irq_flags |= IRQF_TRIGGER_LOW;
  2411. retval = usb_add_hcd(hcd, irq, irq_flags | IRQF_DISABLED | IRQF_SHARED);
  2412. if (retval != 0)
  2413. goto err6;
  2414. pr_info("%s, irq %d\n", hcd->product_desc, irq);
  2415. create_debug_file(isp1362_hcd);
  2416. return 0;
  2417. err6:
  2418. DBG(0, "%s: Freeing dev %p\n", __func__, isp1362_hcd);
  2419. usb_put_hcd(hcd);
  2420. err5:
  2421. DBG(0, "%s: Unmapping data_reg @ %p\n", __func__, data_reg);
  2422. iounmap(data_reg);
  2423. err4:
  2424. DBG(0, "%s: Releasing mem region %08lx\n", __func__, (long unsigned int)data->start);
  2425. release_mem_region(data->start, resource_size(data));
  2426. err3:
  2427. DBG(0, "%s: Unmapping addr_reg @ %p\n", __func__, addr_reg);
  2428. iounmap(addr_reg);
  2429. err2:
  2430. DBG(0, "%s: Releasing mem region %08lx\n", __func__, (long unsigned int)addr->start);
  2431. release_mem_region(addr->start, resource_size(addr));
  2432. err1:
  2433. pr_err("%s: init error, %d\n", __func__, retval);
  2434. return retval;
  2435. }
  2436. #ifdef CONFIG_PM
  2437. static int isp1362_suspend(struct platform_device *pdev, pm_message_t state)
  2438. {
  2439. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  2440. struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
  2441. unsigned long flags;
  2442. int retval = 0;
  2443. DBG(0, "%s: Suspending device\n", __func__);
  2444. if (state.event == PM_EVENT_FREEZE) {
  2445. DBG(0, "%s: Suspending root hub\n", __func__);
  2446. retval = isp1362_bus_suspend(hcd);
  2447. } else {
  2448. DBG(0, "%s: Suspending RH ports\n", __func__);
  2449. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  2450. isp1362_write_reg32(isp1362_hcd, HCRHSTATUS, RH_HS_LPS);
  2451. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  2452. }
  2453. if (retval == 0)
  2454. pdev->dev.power.power_state = state;
  2455. return retval;
  2456. }
  2457. static int isp1362_resume(struct platform_device *pdev)
  2458. {
  2459. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  2460. struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
  2461. unsigned long flags;
  2462. DBG(0, "%s: Resuming\n", __func__);
  2463. if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
  2464. DBG(0, "%s: Resume RH ports\n", __func__);
  2465. spin_lock_irqsave(&isp1362_hcd->lock, flags);
  2466. isp1362_write_reg32(isp1362_hcd, HCRHSTATUS, RH_HS_LPSC);
  2467. spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
  2468. return 0;
  2469. }
  2470. pdev->dev.power.power_state = PMSG_ON;
  2471. return isp1362_bus_resume(isp1362_hcd_to_hcd(isp1362_hcd));
  2472. }
  2473. #else
  2474. #define isp1362_suspend NULL
  2475. #define isp1362_resume NULL
  2476. #endif
  2477. static struct platform_driver isp1362_driver = {
  2478. .probe = isp1362_probe,
  2479. .remove = __devexit_p(isp1362_remove),
  2480. .suspend = isp1362_suspend,
  2481. .resume = isp1362_resume,
  2482. .driver = {
  2483. .name = (char *)hcd_name,
  2484. .owner = THIS_MODULE,
  2485. },
  2486. };
  2487. /*-------------------------------------------------------------------------*/
  2488. static int __init isp1362_init(void)
  2489. {
  2490. if (usb_disabled())
  2491. return -ENODEV;
  2492. pr_info("driver %s, %s\n", hcd_name, DRIVER_VERSION);
  2493. return platform_driver_register(&isp1362_driver);
  2494. }
  2495. module_init(isp1362_init);
  2496. static void __exit isp1362_cleanup(void)
  2497. {
  2498. platform_driver_unregister(&isp1362_driver);
  2499. }
  2500. module_exit(isp1362_cleanup);