isp116x-hcd.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851
  1. /*
  2. * ISP116x HCD (Host Controller Driver) for USB.
  3. *
  4. * Derived from the SL811 HCD, rewritten for ISP116x.
  5. * Copyright (C) 2005 Olav Kongas <ok@artecdesign.ee>
  6. *
  7. * Portions:
  8. * Copyright (C) 2004 Psion Teklogix (for NetBook PRO)
  9. * Copyright (C) 2004 David Brownell
  10. *
  11. * Periodic scheduling is based on Roman's OHCI code
  12. * Copyright (C) 1999 Roman Weissgaerber
  13. *
  14. */
  15. /*
  16. * The driver basically works. A number of people have used it with a range
  17. * of devices.
  18. *
  19. * The driver passes all usbtests 1-14.
  20. *
  21. * Suspending/resuming of root hub via sysfs works. Remote wakeup works too.
  22. * And suspending/resuming of platform device works too. Suspend/resume
  23. * via HCD operations vector is not implemented.
  24. *
  25. * Iso transfer support is not implemented. Adding this would include
  26. * implementing recovery from the failure to service the processed ITL
  27. * fifo ram in time, which will involve chip reset.
  28. *
  29. * TODO:
  30. + More testing of suspend/resume.
  31. */
  32. /*
  33. ISP116x chips require certain delays between accesses to its
  34. registers. The following timing options exist.
  35. 1. Configure your memory controller (the best)
  36. 2. Implement platform-specific delay function possibly
  37. combined with configuring the memory controller; see
  38. include/linux/usb-isp116x.h for more info. Some broken
  39. memory controllers line LH7A400 SMC need this. Also,
  40. uncomment for that to work the following
  41. USE_PLATFORM_DELAY macro.
  42. 3. Use ndelay (easiest, poorest). For that, uncomment
  43. the following USE_NDELAY macro.
  44. */
  45. #define USE_PLATFORM_DELAY
  46. //#define USE_NDELAY
  47. //#define DEBUG
  48. //#define VERBOSE
  49. /* Transfer descriptors. See dump_ptd() for printout format */
  50. //#define PTD_TRACE
  51. /* enqueuing/finishing log of urbs */
  52. //#define URB_TRACE
  53. #include <linux/config.h>
  54. #include <linux/module.h>
  55. #include <linux/moduleparam.h>
  56. #include <linux/kernel.h>
  57. #include <linux/delay.h>
  58. #include <linux/ioport.h>
  59. #include <linux/sched.h>
  60. #include <linux/slab.h>
  61. #include <linux/smp_lock.h>
  62. #include <linux/errno.h>
  63. #include <linux/init.h>
  64. #include <linux/list.h>
  65. #include <linux/interrupt.h>
  66. #include <linux/usb.h>
  67. #include <linux/usb_isp116x.h>
  68. #include <asm/io.h>
  69. #include <asm/irq.h>
  70. #include <asm/system.h>
  71. #include <asm/byteorder.h>
  72. #ifndef DEBUG
  73. # define STUB_DEBUG_FILE
  74. #endif
  75. #include "../core/hcd.h"
  76. #include "isp116x.h"
  77. #define DRIVER_VERSION "05 Aug 2005"
  78. #define DRIVER_DESC "ISP116x USB Host Controller Driver"
  79. MODULE_DESCRIPTION(DRIVER_DESC);
  80. MODULE_LICENSE("GPL");
  81. static const char hcd_name[] = "isp116x-hcd";
  82. /*-----------------------------------------------------------------*/
  83. /*
  84. Write len bytes to fifo, pad till 32-bit boundary
  85. */
  86. static void write_ptddata_to_fifo(struct isp116x *isp116x, void *buf, int len)
  87. {
  88. u8 *dp = (u8 *) buf;
  89. u16 *dp2 = (u16 *) buf;
  90. u16 w;
  91. int quot = len % 4;
  92. if ((unsigned long)dp2 & 1) {
  93. /* not aligned */
  94. for (; len > 1; len -= 2) {
  95. w = *dp++;
  96. w |= *dp++ << 8;
  97. isp116x_raw_write_data16(isp116x, w);
  98. }
  99. if (len)
  100. isp116x_write_data16(isp116x, (u16) * dp);
  101. } else {
  102. /* aligned */
  103. for (; len > 1; len -= 2)
  104. isp116x_raw_write_data16(isp116x, *dp2++);
  105. if (len)
  106. isp116x_write_data16(isp116x, 0xff & *((u8 *) dp2));
  107. }
  108. if (quot == 1 || quot == 2)
  109. isp116x_raw_write_data16(isp116x, 0);
  110. }
  111. /*
  112. Read len bytes from fifo and then read till 32-bit boundary.
  113. */
  114. static void read_ptddata_from_fifo(struct isp116x *isp116x, void *buf, int len)
  115. {
  116. u8 *dp = (u8 *) buf;
  117. u16 *dp2 = (u16 *) buf;
  118. u16 w;
  119. int quot = len % 4;
  120. if ((unsigned long)dp2 & 1) {
  121. /* not aligned */
  122. for (; len > 1; len -= 2) {
  123. w = isp116x_raw_read_data16(isp116x);
  124. *dp++ = w & 0xff;
  125. *dp++ = (w >> 8) & 0xff;
  126. }
  127. if (len)
  128. *dp = 0xff & isp116x_read_data16(isp116x);
  129. } else {
  130. /* aligned */
  131. for (; len > 1; len -= 2)
  132. *dp2++ = isp116x_raw_read_data16(isp116x);
  133. if (len)
  134. *(u8 *) dp2 = 0xff & isp116x_read_data16(isp116x);
  135. }
  136. if (quot == 1 || quot == 2)
  137. isp116x_raw_read_data16(isp116x);
  138. }
  139. /*
  140. Write ptd's and data for scheduled transfers into
  141. the fifo ram. Fifo must be empty and ready.
  142. */
  143. static void pack_fifo(struct isp116x *isp116x)
  144. {
  145. struct isp116x_ep *ep;
  146. struct ptd *ptd;
  147. int buflen = isp116x->atl_last_dir == PTD_DIR_IN
  148. ? isp116x->atl_bufshrt : isp116x->atl_buflen;
  149. int ptd_count = 0;
  150. isp116x_write_reg16(isp116x, HCuPINT, HCuPINT_AIIEOT);
  151. isp116x_write_reg16(isp116x, HCXFERCTR, buflen);
  152. isp116x_write_addr(isp116x, HCATLPORT | ISP116x_WRITE_OFFSET);
  153. for (ep = isp116x->atl_active; ep; ep = ep->active) {
  154. ++ptd_count;
  155. ptd = &ep->ptd;
  156. dump_ptd(ptd);
  157. dump_ptd_out_data(ptd, ep->data);
  158. isp116x_write_data16(isp116x, ptd->count);
  159. isp116x_write_data16(isp116x, ptd->mps);
  160. isp116x_write_data16(isp116x, ptd->len);
  161. isp116x_write_data16(isp116x, ptd->faddr);
  162. buflen -= sizeof(struct ptd);
  163. /* Skip writing data for last IN PTD */
  164. if (ep->active || (isp116x->atl_last_dir != PTD_DIR_IN)) {
  165. write_ptddata_to_fifo(isp116x, ep->data, ep->length);
  166. buflen -= ALIGN(ep->length, 4);
  167. }
  168. }
  169. BUG_ON(buflen);
  170. }
  171. /*
  172. Read the processed ptd's and data from fifo ram back to
  173. URBs' buffers. Fifo must be full and done
  174. */
  175. static void unpack_fifo(struct isp116x *isp116x)
  176. {
  177. struct isp116x_ep *ep;
  178. struct ptd *ptd;
  179. int buflen = isp116x->atl_last_dir == PTD_DIR_IN
  180. ? isp116x->atl_buflen : isp116x->atl_bufshrt;
  181. isp116x_write_reg16(isp116x, HCuPINT, HCuPINT_AIIEOT);
  182. isp116x_write_reg16(isp116x, HCXFERCTR, buflen);
  183. isp116x_write_addr(isp116x, HCATLPORT);
  184. for (ep = isp116x->atl_active; ep; ep = ep->active) {
  185. ptd = &ep->ptd;
  186. ptd->count = isp116x_read_data16(isp116x);
  187. ptd->mps = isp116x_read_data16(isp116x);
  188. ptd->len = isp116x_read_data16(isp116x);
  189. ptd->faddr = isp116x_read_data16(isp116x);
  190. buflen -= sizeof(struct ptd);
  191. /* Skip reading data for last Setup or Out PTD */
  192. if (ep->active || (isp116x->atl_last_dir == PTD_DIR_IN)) {
  193. read_ptddata_from_fifo(isp116x, ep->data, ep->length);
  194. buflen -= ALIGN(ep->length, 4);
  195. }
  196. dump_ptd(ptd);
  197. dump_ptd_in_data(ptd, ep->data);
  198. }
  199. BUG_ON(buflen);
  200. }
  201. /*---------------------------------------------------------------*/
  202. /*
  203. Set up PTD's.
  204. */
  205. static void preproc_atl_queue(struct isp116x *isp116x)
  206. {
  207. struct isp116x_ep *ep;
  208. struct urb *urb;
  209. struct ptd *ptd;
  210. u16 len;
  211. for (ep = isp116x->atl_active; ep; ep = ep->active) {
  212. u16 toggle = 0, dir = PTD_DIR_SETUP;
  213. BUG_ON(list_empty(&ep->hep->urb_list));
  214. urb = container_of(ep->hep->urb_list.next,
  215. struct urb, urb_list);
  216. ptd = &ep->ptd;
  217. len = ep->length;
  218. spin_lock(&urb->lock);
  219. ep->data = (unsigned char *)urb->transfer_buffer
  220. + urb->actual_length;
  221. switch (ep->nextpid) {
  222. case USB_PID_IN:
  223. toggle = usb_gettoggle(urb->dev, ep->epnum, 0);
  224. dir = PTD_DIR_IN;
  225. break;
  226. case USB_PID_OUT:
  227. toggle = usb_gettoggle(urb->dev, ep->epnum, 1);
  228. dir = PTD_DIR_OUT;
  229. break;
  230. case USB_PID_SETUP:
  231. len = sizeof(struct usb_ctrlrequest);
  232. ep->data = urb->setup_packet;
  233. break;
  234. case USB_PID_ACK:
  235. toggle = 1;
  236. len = 0;
  237. dir = (urb->transfer_buffer_length
  238. && usb_pipein(urb->pipe))
  239. ? PTD_DIR_OUT : PTD_DIR_IN;
  240. break;
  241. default:
  242. ERR("%s %d: ep->nextpid %d\n", __func__, __LINE__,
  243. ep->nextpid);
  244. BUG();
  245. }
  246. ptd->count = PTD_CC_MSK | PTD_ACTIVE_MSK | PTD_TOGGLE(toggle);
  247. ptd->mps = PTD_MPS(ep->maxpacket)
  248. | PTD_SPD(urb->dev->speed == USB_SPEED_LOW)
  249. | PTD_EP(ep->epnum);
  250. ptd->len = PTD_LEN(len) | PTD_DIR(dir);
  251. ptd->faddr = PTD_FA(usb_pipedevice(urb->pipe));
  252. spin_unlock(&urb->lock);
  253. if (!ep->active) {
  254. ptd->mps |= PTD_LAST_MSK;
  255. isp116x->atl_last_dir = dir;
  256. }
  257. isp116x->atl_bufshrt = sizeof(struct ptd) + isp116x->atl_buflen;
  258. isp116x->atl_buflen = isp116x->atl_bufshrt + ALIGN(len, 4);
  259. }
  260. }
  261. /*
  262. Analyze transfer results, handle partial transfers and errors
  263. */
  264. static void postproc_atl_queue(struct isp116x *isp116x)
  265. {
  266. struct isp116x_ep *ep;
  267. struct urb *urb;
  268. struct usb_device *udev;
  269. struct ptd *ptd;
  270. int short_not_ok;
  271. u8 cc;
  272. for (ep = isp116x->atl_active; ep; ep = ep->active) {
  273. BUG_ON(list_empty(&ep->hep->urb_list));
  274. urb =
  275. container_of(ep->hep->urb_list.next, struct urb, urb_list);
  276. udev = urb->dev;
  277. ptd = &ep->ptd;
  278. cc = PTD_GET_CC(ptd);
  279. spin_lock(&urb->lock);
  280. short_not_ok = 1;
  281. /* Data underrun is special. For allowed underrun
  282. we clear the error and continue as normal. For
  283. forbidden underrun we finish the DATA stage
  284. immediately while for control transfer,
  285. we do a STATUS stage. */
  286. if (cc == TD_DATAUNDERRUN) {
  287. if (!(urb->transfer_flags & URB_SHORT_NOT_OK)) {
  288. DBG("Allowed data underrun\n");
  289. cc = TD_CC_NOERROR;
  290. short_not_ok = 0;
  291. } else {
  292. ep->error_count = 1;
  293. if (usb_pipecontrol(urb->pipe))
  294. ep->nextpid = USB_PID_ACK;
  295. else
  296. usb_settoggle(udev, ep->epnum,
  297. ep->nextpid ==
  298. USB_PID_OUT,
  299. PTD_GET_TOGGLE(ptd) ^ 1);
  300. urb->status = cc_to_error[TD_DATAUNDERRUN];
  301. spin_unlock(&urb->lock);
  302. continue;
  303. }
  304. }
  305. /* Keep underrun error through the STATUS stage */
  306. if (urb->status == cc_to_error[TD_DATAUNDERRUN])
  307. cc = TD_DATAUNDERRUN;
  308. if (cc != TD_CC_NOERROR && cc != TD_NOTACCESSED
  309. && (++ep->error_count >= 3 || cc == TD_CC_STALL
  310. || cc == TD_DATAOVERRUN)) {
  311. if (urb->status == -EINPROGRESS)
  312. urb->status = cc_to_error[cc];
  313. if (ep->nextpid == USB_PID_ACK)
  314. ep->nextpid = 0;
  315. spin_unlock(&urb->lock);
  316. continue;
  317. }
  318. /* According to usb spec, zero-length Int transfer signals
  319. finishing of the urb. Hey, does this apply only
  320. for IN endpoints? */
  321. if (usb_pipeint(urb->pipe) && !PTD_GET_LEN(ptd)) {
  322. if (urb->status == -EINPROGRESS)
  323. urb->status = 0;
  324. spin_unlock(&urb->lock);
  325. continue;
  326. }
  327. /* Relax after previously failed, but later succeeded
  328. or correctly NAK'ed retransmission attempt */
  329. if (ep->error_count
  330. && (cc == TD_CC_NOERROR || cc == TD_NOTACCESSED))
  331. ep->error_count = 0;
  332. /* Take into account idiosyncracies of the isp116x chip
  333. regarding toggle bit for failed transfers */
  334. if (ep->nextpid == USB_PID_OUT)
  335. usb_settoggle(udev, ep->epnum, 1, PTD_GET_TOGGLE(ptd)
  336. ^ (ep->error_count > 0));
  337. else if (ep->nextpid == USB_PID_IN)
  338. usb_settoggle(udev, ep->epnum, 0, PTD_GET_TOGGLE(ptd)
  339. ^ (ep->error_count > 0));
  340. switch (ep->nextpid) {
  341. case USB_PID_IN:
  342. case USB_PID_OUT:
  343. urb->actual_length += PTD_GET_COUNT(ptd);
  344. if (PTD_GET_ACTIVE(ptd)
  345. || (cc != TD_CC_NOERROR && cc < 0x0E))
  346. break;
  347. if (urb->transfer_buffer_length != urb->actual_length) {
  348. if (short_not_ok)
  349. break;
  350. } else {
  351. if (urb->transfer_flags & URB_ZERO_PACKET
  352. && ep->nextpid == USB_PID_OUT
  353. && !(PTD_GET_COUNT(ptd) % ep->maxpacket)) {
  354. DBG("Zero packet requested\n");
  355. break;
  356. }
  357. }
  358. /* All data for this URB is transferred, let's finish */
  359. if (usb_pipecontrol(urb->pipe))
  360. ep->nextpid = USB_PID_ACK;
  361. else if (urb->status == -EINPROGRESS)
  362. urb->status = 0;
  363. break;
  364. case USB_PID_SETUP:
  365. if (PTD_GET_ACTIVE(ptd)
  366. || (cc != TD_CC_NOERROR && cc < 0x0E))
  367. break;
  368. if (urb->transfer_buffer_length == urb->actual_length)
  369. ep->nextpid = USB_PID_ACK;
  370. else if (usb_pipeout(urb->pipe)) {
  371. usb_settoggle(udev, 0, 1, 1);
  372. ep->nextpid = USB_PID_OUT;
  373. } else {
  374. usb_settoggle(udev, 0, 0, 1);
  375. ep->nextpid = USB_PID_IN;
  376. }
  377. break;
  378. case USB_PID_ACK:
  379. if (PTD_GET_ACTIVE(ptd)
  380. || (cc != TD_CC_NOERROR && cc < 0x0E))
  381. break;
  382. if (urb->status == -EINPROGRESS)
  383. urb->status = 0;
  384. ep->nextpid = 0;
  385. break;
  386. default:
  387. BUG_ON(1);
  388. }
  389. spin_unlock(&urb->lock);
  390. }
  391. }
  392. /*
  393. Take done or failed requests out of schedule. Give back
  394. processed urbs.
  395. */
  396. static void finish_request(struct isp116x *isp116x, struct isp116x_ep *ep,
  397. struct urb *urb, struct pt_regs *regs)
  398. __releases(isp116x->lock) __acquires(isp116x->lock)
  399. {
  400. unsigned i;
  401. urb->hcpriv = NULL;
  402. ep->error_count = 0;
  403. if (usb_pipecontrol(urb->pipe))
  404. ep->nextpid = USB_PID_SETUP;
  405. urb_dbg(urb, "Finish");
  406. spin_unlock(&isp116x->lock);
  407. usb_hcd_giveback_urb(isp116x_to_hcd(isp116x), urb, regs);
  408. spin_lock(&isp116x->lock);
  409. /* take idle endpoints out of the schedule */
  410. if (!list_empty(&ep->hep->urb_list))
  411. return;
  412. /* async deschedule */
  413. if (!list_empty(&ep->schedule)) {
  414. list_del_init(&ep->schedule);
  415. return;
  416. }
  417. /* periodic deschedule */
  418. DBG("deschedule qh%d/%p branch %d\n", ep->period, ep, ep->branch);
  419. for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
  420. struct isp116x_ep *temp;
  421. struct isp116x_ep **prev = &isp116x->periodic[i];
  422. while (*prev && ((temp = *prev) != ep))
  423. prev = &temp->next;
  424. if (*prev)
  425. *prev = ep->next;
  426. isp116x->load[i] -= ep->load;
  427. }
  428. ep->branch = PERIODIC_SIZE;
  429. isp116x_to_hcd(isp116x)->self.bandwidth_allocated -=
  430. ep->load / ep->period;
  431. /* switch irq type? */
  432. if (!--isp116x->periodic_count) {
  433. isp116x->irqenb &= ~HCuPINT_SOF;
  434. isp116x->irqenb |= HCuPINT_ATL;
  435. }
  436. }
  437. /*
  438. Scan transfer lists, schedule transfers, send data off
  439. to chip.
  440. */
  441. static void start_atl_transfers(struct isp116x *isp116x)
  442. {
  443. struct isp116x_ep *last_ep = NULL, *ep;
  444. struct urb *urb;
  445. u16 load = 0;
  446. int len, index, speed, byte_time;
  447. if (atomic_read(&isp116x->atl_finishing))
  448. return;
  449. if (!HC_IS_RUNNING(isp116x_to_hcd(isp116x)->state))
  450. return;
  451. /* FIFO not empty? */
  452. if (isp116x_read_reg16(isp116x, HCBUFSTAT) & HCBUFSTAT_ATL_FULL)
  453. return;
  454. isp116x->atl_active = NULL;
  455. isp116x->atl_buflen = isp116x->atl_bufshrt = 0;
  456. /* Schedule int transfers */
  457. if (isp116x->periodic_count) {
  458. isp116x->fmindex = index =
  459. (isp116x->fmindex + 1) & (PERIODIC_SIZE - 1);
  460. if ((load = isp116x->load[index])) {
  461. /* Bring all int transfers for this frame
  462. into the active queue */
  463. isp116x->atl_active = last_ep =
  464. isp116x->periodic[index];
  465. while (last_ep->next)
  466. last_ep = (last_ep->active = last_ep->next);
  467. last_ep->active = NULL;
  468. }
  469. }
  470. /* Schedule control/bulk transfers */
  471. list_for_each_entry(ep, &isp116x->async, schedule) {
  472. urb = container_of(ep->hep->urb_list.next,
  473. struct urb, urb_list);
  474. speed = urb->dev->speed;
  475. byte_time = speed == USB_SPEED_LOW
  476. ? BYTE_TIME_LOWSPEED : BYTE_TIME_FULLSPEED;
  477. if (ep->nextpid == USB_PID_SETUP) {
  478. len = sizeof(struct usb_ctrlrequest);
  479. } else if (ep->nextpid == USB_PID_ACK) {
  480. len = 0;
  481. } else {
  482. /* Find current free length ... */
  483. len = (MAX_LOAD_LIMIT - load) / byte_time;
  484. /* ... then limit it to configured max size ... */
  485. len = min(len, speed == USB_SPEED_LOW ?
  486. MAX_TRANSFER_SIZE_LOWSPEED :
  487. MAX_TRANSFER_SIZE_FULLSPEED);
  488. /* ... and finally cut to the multiple of MaxPacketSize,
  489. or to the real length if there's enough room. */
  490. if (len <
  491. (urb->transfer_buffer_length -
  492. urb->actual_length)) {
  493. len -= len % ep->maxpacket;
  494. if (!len)
  495. continue;
  496. } else
  497. len = urb->transfer_buffer_length -
  498. urb->actual_length;
  499. BUG_ON(len < 0);
  500. }
  501. load += len * byte_time;
  502. if (load > MAX_LOAD_LIMIT)
  503. break;
  504. ep->active = NULL;
  505. ep->length = len;
  506. if (last_ep)
  507. last_ep->active = ep;
  508. else
  509. isp116x->atl_active = ep;
  510. last_ep = ep;
  511. }
  512. /* Avoid starving of endpoints */
  513. if ((&isp116x->async)->next != (&isp116x->async)->prev)
  514. list_move(&isp116x->async, (&isp116x->async)->next);
  515. if (isp116x->atl_active) {
  516. preproc_atl_queue(isp116x);
  517. pack_fifo(isp116x);
  518. }
  519. }
  520. /*
  521. Finish the processed transfers
  522. */
  523. static void finish_atl_transfers(struct isp116x *isp116x, struct pt_regs *regs)
  524. {
  525. struct isp116x_ep *ep;
  526. struct urb *urb;
  527. if (!isp116x->atl_active)
  528. return;
  529. /* Fifo not ready? */
  530. if (!(isp116x_read_reg16(isp116x, HCBUFSTAT) & HCBUFSTAT_ATL_DONE))
  531. return;
  532. atomic_inc(&isp116x->atl_finishing);
  533. unpack_fifo(isp116x);
  534. postproc_atl_queue(isp116x);
  535. for (ep = isp116x->atl_active; ep; ep = ep->active) {
  536. urb =
  537. container_of(ep->hep->urb_list.next, struct urb, urb_list);
  538. /* USB_PID_ACK check here avoids finishing of
  539. control transfers, for which TD_DATAUNDERRUN
  540. occured, while URB_SHORT_NOT_OK was set */
  541. if (urb && urb->status != -EINPROGRESS
  542. && ep->nextpid != USB_PID_ACK)
  543. finish_request(isp116x, ep, urb, regs);
  544. }
  545. atomic_dec(&isp116x->atl_finishing);
  546. }
  547. static irqreturn_t isp116x_irq(struct usb_hcd *hcd, struct pt_regs *regs)
  548. {
  549. struct isp116x *isp116x = hcd_to_isp116x(hcd);
  550. u16 irqstat;
  551. irqreturn_t ret = IRQ_NONE;
  552. spin_lock(&isp116x->lock);
  553. isp116x_write_reg16(isp116x, HCuPINTENB, 0);
  554. irqstat = isp116x_read_reg16(isp116x, HCuPINT);
  555. isp116x_write_reg16(isp116x, HCuPINT, irqstat);
  556. if (irqstat & (HCuPINT_ATL | HCuPINT_SOF)) {
  557. ret = IRQ_HANDLED;
  558. finish_atl_transfers(isp116x, regs);
  559. }
  560. if (irqstat & HCuPINT_OPR) {
  561. u32 intstat = isp116x_read_reg32(isp116x, HCINTSTAT);
  562. isp116x_write_reg32(isp116x, HCINTSTAT, intstat);
  563. if (intstat & HCINT_UE) {
  564. ERR("Unrecoverable error\n");
  565. /* What should we do here? Reset? */
  566. }
  567. if (intstat & HCINT_RHSC)
  568. /* When root hub or any of its ports is going
  569. to come out of suspend, it may take more
  570. than 10ms for status bits to stabilize. */
  571. mod_timer(&hcd->rh_timer, jiffies
  572. + msecs_to_jiffies(20) + 1);
  573. if (intstat & HCINT_RD) {
  574. DBG("---- remote wakeup\n");
  575. schedule_work(&isp116x->rh_resume);
  576. ret = IRQ_HANDLED;
  577. }
  578. irqstat &= ~HCuPINT_OPR;
  579. ret = IRQ_HANDLED;
  580. }
  581. if (irqstat & (HCuPINT_ATL | HCuPINT_SOF)) {
  582. start_atl_transfers(isp116x);
  583. }
  584. isp116x_write_reg16(isp116x, HCuPINTENB, isp116x->irqenb);
  585. spin_unlock(&isp116x->lock);
  586. return ret;
  587. }
  588. /*-----------------------------------------------------------------*/
  589. /* usb 1.1 says max 90% of a frame is available for periodic transfers.
  590. * this driver doesn't promise that much since it's got to handle an
  591. * IRQ per packet; irq handling latencies also use up that time.
  592. */
  593. /* out of 1000 us */
  594. #define MAX_PERIODIC_LOAD 600
  595. static int balance(struct isp116x *isp116x, u16 period, u16 load)
  596. {
  597. int i, branch = -ENOSPC;
  598. /* search for the least loaded schedule branch of that period
  599. which has enough bandwidth left unreserved. */
  600. for (i = 0; i < period; i++) {
  601. if (branch < 0 || isp116x->load[branch] > isp116x->load[i]) {
  602. int j;
  603. for (j = i; j < PERIODIC_SIZE; j += period) {
  604. if ((isp116x->load[j] + load)
  605. > MAX_PERIODIC_LOAD)
  606. break;
  607. }
  608. if (j < PERIODIC_SIZE)
  609. continue;
  610. branch = i;
  611. }
  612. }
  613. return branch;
  614. }
  615. /* NB! ALL the code above this point runs with isp116x->lock
  616. held, irqs off
  617. */
  618. /*-----------------------------------------------------------------*/
  619. static int isp116x_urb_enqueue(struct usb_hcd *hcd,
  620. struct usb_host_endpoint *hep, struct urb *urb,
  621. unsigned mem_flags)
  622. {
  623. struct isp116x *isp116x = hcd_to_isp116x(hcd);
  624. struct usb_device *udev = urb->dev;
  625. unsigned int pipe = urb->pipe;
  626. int is_out = !usb_pipein(pipe);
  627. int type = usb_pipetype(pipe);
  628. int epnum = usb_pipeendpoint(pipe);
  629. struct isp116x_ep *ep = NULL;
  630. unsigned long flags;
  631. int i;
  632. int ret = 0;
  633. urb_dbg(urb, "Enqueue");
  634. if (type == PIPE_ISOCHRONOUS) {
  635. ERR("Isochronous transfers not supported\n");
  636. urb_dbg(urb, "Refused to enqueue");
  637. return -ENXIO;
  638. }
  639. /* avoid all allocations within spinlocks: request or endpoint */
  640. if (!hep->hcpriv) {
  641. ep = kzalloc(sizeof *ep, mem_flags);
  642. if (!ep)
  643. return -ENOMEM;
  644. }
  645. spin_lock_irqsave(&isp116x->lock, flags);
  646. if (!HC_IS_RUNNING(hcd->state)) {
  647. ret = -ENODEV;
  648. goto fail;
  649. }
  650. if (hep->hcpriv)
  651. ep = hep->hcpriv;
  652. else {
  653. INIT_LIST_HEAD(&ep->schedule);
  654. ep->udev = usb_get_dev(udev);
  655. ep->epnum = epnum;
  656. ep->maxpacket = usb_maxpacket(udev, urb->pipe, is_out);
  657. usb_settoggle(udev, epnum, is_out, 0);
  658. if (type == PIPE_CONTROL) {
  659. ep->nextpid = USB_PID_SETUP;
  660. } else if (is_out) {
  661. ep->nextpid = USB_PID_OUT;
  662. } else {
  663. ep->nextpid = USB_PID_IN;
  664. }
  665. if (urb->interval) {
  666. /*
  667. With INT URBs submitted, the driver works with SOF
  668. interrupt enabled and ATL interrupt disabled. After
  669. the PTDs are written to fifo ram, the chip starts
  670. fifo processing and usb transfers after the next
  671. SOF and continues until the transfers are finished
  672. (succeeded or failed) or the frame ends. Therefore,
  673. the transfers occur only in every second frame,
  674. while fifo reading/writing and data processing
  675. occur in every other second frame. */
  676. if (urb->interval < 2)
  677. urb->interval = 2;
  678. if (urb->interval > 2 * PERIODIC_SIZE)
  679. urb->interval = 2 * PERIODIC_SIZE;
  680. ep->period = urb->interval >> 1;
  681. ep->branch = PERIODIC_SIZE;
  682. ep->load = usb_calc_bus_time(udev->speed,
  683. !is_out,
  684. (type == PIPE_ISOCHRONOUS),
  685. usb_maxpacket(udev, pipe,
  686. is_out)) /
  687. 1000;
  688. }
  689. hep->hcpriv = ep;
  690. ep->hep = hep;
  691. }
  692. /* maybe put endpoint into schedule */
  693. switch (type) {
  694. case PIPE_CONTROL:
  695. case PIPE_BULK:
  696. if (list_empty(&ep->schedule))
  697. list_add_tail(&ep->schedule, &isp116x->async);
  698. break;
  699. case PIPE_INTERRUPT:
  700. urb->interval = ep->period;
  701. ep->length = min((int)ep->maxpacket,
  702. urb->transfer_buffer_length);
  703. /* urb submitted for already existing endpoint */
  704. if (ep->branch < PERIODIC_SIZE)
  705. break;
  706. ret = ep->branch = balance(isp116x, ep->period, ep->load);
  707. if (ret < 0)
  708. goto fail;
  709. ret = 0;
  710. urb->start_frame = (isp116x->fmindex & (PERIODIC_SIZE - 1))
  711. + ep->branch;
  712. /* sort each schedule branch by period (slow before fast)
  713. to share the faster parts of the tree without needing
  714. dummy/placeholder nodes */
  715. DBG("schedule qh%d/%p branch %d\n", ep->period, ep, ep->branch);
  716. for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
  717. struct isp116x_ep **prev = &isp116x->periodic[i];
  718. struct isp116x_ep *here = *prev;
  719. while (here && ep != here) {
  720. if (ep->period > here->period)
  721. break;
  722. prev = &here->next;
  723. here = *prev;
  724. }
  725. if (ep != here) {
  726. ep->next = here;
  727. *prev = ep;
  728. }
  729. isp116x->load[i] += ep->load;
  730. }
  731. hcd->self.bandwidth_allocated += ep->load / ep->period;
  732. /* switch over to SOFint */
  733. if (!isp116x->periodic_count++) {
  734. isp116x->irqenb &= ~HCuPINT_ATL;
  735. isp116x->irqenb |= HCuPINT_SOF;
  736. isp116x_write_reg16(isp116x, HCuPINTENB,
  737. isp116x->irqenb);
  738. }
  739. }
  740. /* in case of unlink-during-submit */
  741. spin_lock(&urb->lock);
  742. if (urb->status != -EINPROGRESS) {
  743. spin_unlock(&urb->lock);
  744. finish_request(isp116x, ep, urb, NULL);
  745. ret = 0;
  746. goto fail;
  747. }
  748. urb->hcpriv = hep;
  749. spin_unlock(&urb->lock);
  750. start_atl_transfers(isp116x);
  751. fail:
  752. spin_unlock_irqrestore(&isp116x->lock, flags);
  753. return ret;
  754. }
  755. /*
  756. Dequeue URBs.
  757. */
  758. static int isp116x_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
  759. {
  760. struct isp116x *isp116x = hcd_to_isp116x(hcd);
  761. struct usb_host_endpoint *hep;
  762. struct isp116x_ep *ep, *ep_act;
  763. unsigned long flags;
  764. spin_lock_irqsave(&isp116x->lock, flags);
  765. hep = urb->hcpriv;
  766. /* URB already unlinked (or never linked)? */
  767. if (!hep) {
  768. spin_unlock_irqrestore(&isp116x->lock, flags);
  769. return 0;
  770. }
  771. ep = hep->hcpriv;
  772. WARN_ON(hep != ep->hep);
  773. /* In front of queue? */
  774. if (ep->hep->urb_list.next == &urb->urb_list)
  775. /* active? */
  776. for (ep_act = isp116x->atl_active; ep_act;
  777. ep_act = ep_act->active)
  778. if (ep_act == ep) {
  779. VDBG("dequeue, urb %p active; wait for irq\n",
  780. urb);
  781. urb = NULL;
  782. break;
  783. }
  784. if (urb)
  785. finish_request(isp116x, ep, urb, NULL);
  786. spin_unlock_irqrestore(&isp116x->lock, flags);
  787. return 0;
  788. }
  789. static void isp116x_endpoint_disable(struct usb_hcd *hcd,
  790. struct usb_host_endpoint *hep)
  791. {
  792. int i;
  793. struct isp116x_ep *ep = hep->hcpriv;;
  794. if (!ep)
  795. return;
  796. /* assume we'd just wait for the irq */
  797. for (i = 0; i < 100 && !list_empty(&hep->urb_list); i++)
  798. msleep(3);
  799. if (!list_empty(&hep->urb_list))
  800. WARN("ep %p not empty?\n", ep);
  801. usb_put_dev(ep->udev);
  802. kfree(ep);
  803. hep->hcpriv = NULL;
  804. }
  805. static int isp116x_get_frame(struct usb_hcd *hcd)
  806. {
  807. struct isp116x *isp116x = hcd_to_isp116x(hcd);
  808. u32 fmnum;
  809. unsigned long flags;
  810. spin_lock_irqsave(&isp116x->lock, flags);
  811. fmnum = isp116x_read_reg32(isp116x, HCFMNUM);
  812. spin_unlock_irqrestore(&isp116x->lock, flags);
  813. return (int)fmnum;
  814. }
  815. /*----------------------------------------------------------------*/
  816. /*
  817. Adapted from ohci-hub.c. Currently we don't support autosuspend.
  818. */
  819. static int isp116x_hub_status_data(struct usb_hcd *hcd, char *buf)
  820. {
  821. struct isp116x *isp116x = hcd_to_isp116x(hcd);
  822. int ports, i, changed = 0;
  823. unsigned long flags;
  824. if (!HC_IS_RUNNING(hcd->state))
  825. return -ESHUTDOWN;
  826. /* Report no status change now, if we are scheduled to be
  827. called later */
  828. if (timer_pending(&hcd->rh_timer))
  829. return 0;
  830. ports = isp116x->rhdesca & RH_A_NDP;
  831. spin_lock_irqsave(&isp116x->lock, flags);
  832. isp116x->rhstatus = isp116x_read_reg32(isp116x, HCRHSTATUS);
  833. if (isp116x->rhstatus & (RH_HS_LPSC | RH_HS_OCIC))
  834. buf[0] = changed = 1;
  835. else
  836. buf[0] = 0;
  837. for (i = 0; i < ports; i++) {
  838. u32 status = isp116x->rhport[i] =
  839. isp116x_read_reg32(isp116x, i ? HCRHPORT2 : HCRHPORT1);
  840. if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC
  841. | RH_PS_OCIC | RH_PS_PRSC)) {
  842. changed = 1;
  843. buf[0] |= 1 << (i + 1);
  844. continue;
  845. }
  846. }
  847. spin_unlock_irqrestore(&isp116x->lock, flags);
  848. return changed;
  849. }
  850. static void isp116x_hub_descriptor(struct isp116x *isp116x,
  851. struct usb_hub_descriptor *desc)
  852. {
  853. u32 reg = isp116x->rhdesca;
  854. desc->bDescriptorType = 0x29;
  855. desc->bDescLength = 9;
  856. desc->bHubContrCurrent = 0;
  857. desc->bNbrPorts = (u8) (reg & 0x3);
  858. /* Power switching, device type, overcurrent. */
  859. desc->wHubCharacteristics =
  860. (__force __u16) cpu_to_le16((u16) ((reg >> 8) & 0x1f));
  861. desc->bPwrOn2PwrGood = (u8) ((reg >> 24) & 0xff);
  862. /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */
  863. desc->bitmap[0] = desc->bNbrPorts == 1 ? 1 << 1 : 3 << 1;
  864. desc->bitmap[1] = ~0;
  865. }
  866. /* Perform reset of a given port.
  867. It would be great to just start the reset and let the
  868. USB core to clear the reset in due time. However,
  869. root hub ports should be reset for at least 50 ms, while
  870. our chip stays in reset for about 10 ms. I.e., we must
  871. repeatedly reset it ourself here.
  872. */
  873. static inline void root_port_reset(struct isp116x *isp116x, unsigned port)
  874. {
  875. u32 tmp;
  876. unsigned long flags, t;
  877. /* Root hub reset should be 50 ms, but some devices
  878. want it even longer. */
  879. t = jiffies + msecs_to_jiffies(100);
  880. while (time_before(jiffies, t)) {
  881. spin_lock_irqsave(&isp116x->lock, flags);
  882. /* spin until any current reset finishes */
  883. for (;;) {
  884. tmp = isp116x_read_reg32(isp116x, port ?
  885. HCRHPORT2 : HCRHPORT1);
  886. if (!(tmp & RH_PS_PRS))
  887. break;
  888. udelay(500);
  889. }
  890. /* Don't reset a disconnected port */
  891. if (!(tmp & RH_PS_CCS)) {
  892. spin_unlock_irqrestore(&isp116x->lock, flags);
  893. break;
  894. }
  895. /* Reset lasts 10ms (claims datasheet) */
  896. isp116x_write_reg32(isp116x, port ? HCRHPORT2 :
  897. HCRHPORT1, (RH_PS_PRS));
  898. spin_unlock_irqrestore(&isp116x->lock, flags);
  899. msleep(10);
  900. }
  901. }
  902. /* Adapted from ohci-hub.c */
  903. static int isp116x_hub_control(struct usb_hcd *hcd,
  904. u16 typeReq,
  905. u16 wValue, u16 wIndex, char *buf, u16 wLength)
  906. {
  907. struct isp116x *isp116x = hcd_to_isp116x(hcd);
  908. int ret = 0;
  909. unsigned long flags;
  910. int ports = isp116x->rhdesca & RH_A_NDP;
  911. u32 tmp = 0;
  912. switch (typeReq) {
  913. case ClearHubFeature:
  914. DBG("ClearHubFeature: ");
  915. switch (wValue) {
  916. case C_HUB_OVER_CURRENT:
  917. DBG("C_HUB_OVER_CURRENT\n");
  918. spin_lock_irqsave(&isp116x->lock, flags);
  919. isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_OCIC);
  920. spin_unlock_irqrestore(&isp116x->lock, flags);
  921. case C_HUB_LOCAL_POWER:
  922. DBG("C_HUB_LOCAL_POWER\n");
  923. break;
  924. default:
  925. goto error;
  926. }
  927. break;
  928. case SetHubFeature:
  929. DBG("SetHubFeature: ");
  930. switch (wValue) {
  931. case C_HUB_OVER_CURRENT:
  932. case C_HUB_LOCAL_POWER:
  933. DBG("C_HUB_OVER_CURRENT or C_HUB_LOCAL_POWER\n");
  934. break;
  935. default:
  936. goto error;
  937. }
  938. break;
  939. case GetHubDescriptor:
  940. DBG("GetHubDescriptor\n");
  941. isp116x_hub_descriptor(isp116x,
  942. (struct usb_hub_descriptor *)buf);
  943. break;
  944. case GetHubStatus:
  945. DBG("GetHubStatus\n");
  946. *(__le32 *) buf = 0;
  947. break;
  948. case GetPortStatus:
  949. DBG("GetPortStatus\n");
  950. if (!wIndex || wIndex > ports)
  951. goto error;
  952. tmp = isp116x->rhport[--wIndex];
  953. *(__le32 *) buf = cpu_to_le32(tmp);
  954. DBG("GetPortStatus: port[%d] %08x\n", wIndex + 1, tmp);
  955. break;
  956. case ClearPortFeature:
  957. DBG("ClearPortFeature: ");
  958. if (!wIndex || wIndex > ports)
  959. goto error;
  960. wIndex--;
  961. switch (wValue) {
  962. case USB_PORT_FEAT_ENABLE:
  963. DBG("USB_PORT_FEAT_ENABLE\n");
  964. tmp = RH_PS_CCS;
  965. break;
  966. case USB_PORT_FEAT_C_ENABLE:
  967. DBG("USB_PORT_FEAT_C_ENABLE\n");
  968. tmp = RH_PS_PESC;
  969. break;
  970. case USB_PORT_FEAT_SUSPEND:
  971. DBG("USB_PORT_FEAT_SUSPEND\n");
  972. tmp = RH_PS_POCI;
  973. break;
  974. case USB_PORT_FEAT_C_SUSPEND:
  975. DBG("USB_PORT_FEAT_C_SUSPEND\n");
  976. tmp = RH_PS_PSSC;
  977. break;
  978. case USB_PORT_FEAT_POWER:
  979. DBG("USB_PORT_FEAT_POWER\n");
  980. tmp = RH_PS_LSDA;
  981. break;
  982. case USB_PORT_FEAT_C_CONNECTION:
  983. DBG("USB_PORT_FEAT_C_CONNECTION\n");
  984. tmp = RH_PS_CSC;
  985. break;
  986. case USB_PORT_FEAT_C_OVER_CURRENT:
  987. DBG("USB_PORT_FEAT_C_OVER_CURRENT\n");
  988. tmp = RH_PS_OCIC;
  989. break;
  990. case USB_PORT_FEAT_C_RESET:
  991. DBG("USB_PORT_FEAT_C_RESET\n");
  992. tmp = RH_PS_PRSC;
  993. break;
  994. default:
  995. goto error;
  996. }
  997. spin_lock_irqsave(&isp116x->lock, flags);
  998. isp116x_write_reg32(isp116x, wIndex
  999. ? HCRHPORT2 : HCRHPORT1, tmp);
  1000. isp116x->rhport[wIndex] =
  1001. isp116x_read_reg32(isp116x, wIndex ? HCRHPORT2 : HCRHPORT1);
  1002. spin_unlock_irqrestore(&isp116x->lock, flags);
  1003. break;
  1004. case SetPortFeature:
  1005. DBG("SetPortFeature: ");
  1006. if (!wIndex || wIndex > ports)
  1007. goto error;
  1008. wIndex--;
  1009. switch (wValue) {
  1010. case USB_PORT_FEAT_SUSPEND:
  1011. DBG("USB_PORT_FEAT_SUSPEND\n");
  1012. spin_lock_irqsave(&isp116x->lock, flags);
  1013. isp116x_write_reg32(isp116x, wIndex
  1014. ? HCRHPORT2 : HCRHPORT1, RH_PS_PSS);
  1015. break;
  1016. case USB_PORT_FEAT_POWER:
  1017. DBG("USB_PORT_FEAT_POWER\n");
  1018. spin_lock_irqsave(&isp116x->lock, flags);
  1019. isp116x_write_reg32(isp116x, wIndex
  1020. ? HCRHPORT2 : HCRHPORT1, RH_PS_PPS);
  1021. break;
  1022. case USB_PORT_FEAT_RESET:
  1023. DBG("USB_PORT_FEAT_RESET\n");
  1024. root_port_reset(isp116x, wIndex);
  1025. spin_lock_irqsave(&isp116x->lock, flags);
  1026. break;
  1027. default:
  1028. goto error;
  1029. }
  1030. isp116x->rhport[wIndex] =
  1031. isp116x_read_reg32(isp116x, wIndex ? HCRHPORT2 : HCRHPORT1);
  1032. spin_unlock_irqrestore(&isp116x->lock, flags);
  1033. break;
  1034. default:
  1035. error:
  1036. /* "protocol stall" on error */
  1037. DBG("PROTOCOL STALL\n");
  1038. ret = -EPIPE;
  1039. }
  1040. return ret;
  1041. }
  1042. #ifdef CONFIG_PM
  1043. static int isp116x_hub_suspend(struct usb_hcd *hcd)
  1044. {
  1045. struct isp116x *isp116x = hcd_to_isp116x(hcd);
  1046. unsigned long flags;
  1047. u32 val;
  1048. int ret = 0;
  1049. spin_lock_irqsave(&isp116x->lock, flags);
  1050. val = isp116x_read_reg32(isp116x, HCCONTROL);
  1051. switch (val & HCCONTROL_HCFS) {
  1052. case HCCONTROL_USB_OPER:
  1053. hcd->state = HC_STATE_QUIESCING;
  1054. val &= (~HCCONTROL_HCFS & ~HCCONTROL_RWE);
  1055. val |= HCCONTROL_USB_SUSPEND;
  1056. if (hcd->remote_wakeup)
  1057. val |= HCCONTROL_RWE;
  1058. /* Wait for usb transfers to finish */
  1059. mdelay(2);
  1060. isp116x_write_reg32(isp116x, HCCONTROL, val);
  1061. hcd->state = HC_STATE_SUSPENDED;
  1062. /* Wait for devices to suspend */
  1063. mdelay(5);
  1064. case HCCONTROL_USB_SUSPEND:
  1065. break;
  1066. case HCCONTROL_USB_RESUME:
  1067. isp116x_write_reg32(isp116x, HCCONTROL,
  1068. (val & ~HCCONTROL_HCFS) |
  1069. HCCONTROL_USB_RESET);
  1070. case HCCONTROL_USB_RESET:
  1071. ret = -EBUSY;
  1072. break;
  1073. default:
  1074. ret = -EINVAL;
  1075. }
  1076. spin_unlock_irqrestore(&isp116x->lock, flags);
  1077. return ret;
  1078. }
  1079. static int isp116x_hub_resume(struct usb_hcd *hcd)
  1080. {
  1081. struct isp116x *isp116x = hcd_to_isp116x(hcd);
  1082. u32 val;
  1083. int ret = -EINPROGRESS;
  1084. msleep(5);
  1085. spin_lock_irq(&isp116x->lock);
  1086. val = isp116x_read_reg32(isp116x, HCCONTROL);
  1087. switch (val & HCCONTROL_HCFS) {
  1088. case HCCONTROL_USB_SUSPEND:
  1089. val &= ~HCCONTROL_HCFS;
  1090. val |= HCCONTROL_USB_RESUME;
  1091. isp116x_write_reg32(isp116x, HCCONTROL, val);
  1092. case HCCONTROL_USB_RESUME:
  1093. break;
  1094. case HCCONTROL_USB_OPER:
  1095. /* Without setting power_state here the
  1096. SUSPENDED state won't be removed from
  1097. sysfs/usbN/power.state as a response to remote
  1098. wakeup. Maybe in the future. */
  1099. hcd->self.root_hub->dev.power.power_state = PMSG_ON;
  1100. ret = 0;
  1101. break;
  1102. default:
  1103. ret = -EBUSY;
  1104. }
  1105. if (ret != -EINPROGRESS) {
  1106. spin_unlock_irq(&isp116x->lock);
  1107. return ret;
  1108. }
  1109. val = isp116x->rhdesca & RH_A_NDP;
  1110. while (val--) {
  1111. u32 stat =
  1112. isp116x_read_reg32(isp116x, val ? HCRHPORT2 : HCRHPORT1);
  1113. /* force global, not selective, resume */
  1114. if (!(stat & RH_PS_PSS))
  1115. continue;
  1116. DBG("%s: Resuming port %d\n", __func__, val);
  1117. isp116x_write_reg32(isp116x, RH_PS_POCI, val
  1118. ? HCRHPORT2 : HCRHPORT1);
  1119. }
  1120. spin_unlock_irq(&isp116x->lock);
  1121. hcd->state = HC_STATE_RESUMING;
  1122. mdelay(20);
  1123. /* Go operational */
  1124. spin_lock_irq(&isp116x->lock);
  1125. val = isp116x_read_reg32(isp116x, HCCONTROL);
  1126. isp116x_write_reg32(isp116x, HCCONTROL,
  1127. (val & ~HCCONTROL_HCFS) | HCCONTROL_USB_OPER);
  1128. spin_unlock_irq(&isp116x->lock);
  1129. /* see analogous comment above */
  1130. hcd->self.root_hub->dev.power.power_state = PMSG_ON;
  1131. hcd->state = HC_STATE_RUNNING;
  1132. return 0;
  1133. }
  1134. static void isp116x_rh_resume(void *_hcd)
  1135. {
  1136. struct usb_hcd *hcd = _hcd;
  1137. usb_resume_device(hcd->self.root_hub);
  1138. }
  1139. #else
  1140. #define isp116x_hub_suspend NULL
  1141. #define isp116x_hub_resume NULL
  1142. static void isp116x_rh_resume(void *_hcd)
  1143. {
  1144. }
  1145. #endif
  1146. /*-----------------------------------------------------------------*/
  1147. #ifdef STUB_DEBUG_FILE
  1148. static inline void create_debug_file(struct isp116x *isp116x)
  1149. {
  1150. }
  1151. static inline void remove_debug_file(struct isp116x *isp116x)
  1152. {
  1153. }
  1154. #else
  1155. #include <linux/proc_fs.h>
  1156. #include <linux/seq_file.h>
  1157. static void dump_irq(struct seq_file *s, char *label, u16 mask)
  1158. {
  1159. seq_printf(s, "%s %04x%s%s%s%s%s%s\n", label, mask,
  1160. mask & HCuPINT_CLKRDY ? " clkrdy" : "",
  1161. mask & HCuPINT_SUSP ? " susp" : "",
  1162. mask & HCuPINT_OPR ? " opr" : "",
  1163. mask & HCuPINT_AIIEOT ? " eot" : "",
  1164. mask & HCuPINT_ATL ? " atl" : "",
  1165. mask & HCuPINT_SOF ? " sof" : "");
  1166. }
  1167. static void dump_int(struct seq_file *s, char *label, u32 mask)
  1168. {
  1169. seq_printf(s, "%s %08x%s%s%s%s%s%s%s\n", label, mask,
  1170. mask & HCINT_MIE ? " MIE" : "",
  1171. mask & HCINT_RHSC ? " rhsc" : "",
  1172. mask & HCINT_FNO ? " fno" : "",
  1173. mask & HCINT_UE ? " ue" : "",
  1174. mask & HCINT_RD ? " rd" : "",
  1175. mask & HCINT_SF ? " sof" : "", mask & HCINT_SO ? " so" : "");
  1176. }
  1177. static int proc_isp116x_show(struct seq_file *s, void *unused)
  1178. {
  1179. struct isp116x *isp116x = s->private;
  1180. struct isp116x_ep *ep;
  1181. struct urb *urb;
  1182. unsigned i;
  1183. char *str;
  1184. seq_printf(s, "%s\n%s version %s\n",
  1185. isp116x_to_hcd(isp116x)->product_desc, hcd_name,
  1186. DRIVER_VERSION);
  1187. if (HC_IS_SUSPENDED(isp116x_to_hcd(isp116x)->state)) {
  1188. seq_printf(s, "HCD is suspended\n");
  1189. return 0;
  1190. }
  1191. if (!HC_IS_RUNNING(isp116x_to_hcd(isp116x)->state)) {
  1192. seq_printf(s, "HCD not running\n");
  1193. return 0;
  1194. }
  1195. spin_lock_irq(&isp116x->lock);
  1196. dump_irq(s, "hc_irq_enable", isp116x_read_reg16(isp116x, HCuPINTENB));
  1197. dump_irq(s, "hc_irq_status", isp116x_read_reg16(isp116x, HCuPINT));
  1198. dump_int(s, "hc_int_enable", isp116x_read_reg32(isp116x, HCINTENB));
  1199. dump_int(s, "hc_int_status", isp116x_read_reg32(isp116x, HCINTSTAT));
  1200. list_for_each_entry(ep, &isp116x->async, schedule) {
  1201. switch (ep->nextpid) {
  1202. case USB_PID_IN:
  1203. str = "in";
  1204. break;
  1205. case USB_PID_OUT:
  1206. str = "out";
  1207. break;
  1208. case USB_PID_SETUP:
  1209. str = "setup";
  1210. break;
  1211. case USB_PID_ACK:
  1212. str = "status";
  1213. break;
  1214. default:
  1215. str = "?";
  1216. break;
  1217. };
  1218. seq_printf(s, "%p, ep%d%s, maxpacket %d:\n", ep,
  1219. ep->epnum, str, ep->maxpacket);
  1220. list_for_each_entry(urb, &ep->hep->urb_list, urb_list) {
  1221. seq_printf(s, " urb%p, %d/%d\n", urb,
  1222. urb->actual_length,
  1223. urb->transfer_buffer_length);
  1224. }
  1225. }
  1226. if (!list_empty(&isp116x->async))
  1227. seq_printf(s, "\n");
  1228. seq_printf(s, "periodic size= %d\n", PERIODIC_SIZE);
  1229. for (i = 0; i < PERIODIC_SIZE; i++) {
  1230. ep = isp116x->periodic[i];
  1231. if (!ep)
  1232. continue;
  1233. seq_printf(s, "%2d [%3d]:\n", i, isp116x->load[i]);
  1234. /* DUMB: prints shared entries multiple times */
  1235. do {
  1236. seq_printf(s, " %d/%p (%sdev%d ep%d%s max %d)\n",
  1237. ep->period, ep,
  1238. (ep->udev->speed ==
  1239. USB_SPEED_FULL) ? "" : "ls ",
  1240. ep->udev->devnum, ep->epnum,
  1241. (ep->epnum ==
  1242. 0) ? "" : ((ep->nextpid ==
  1243. USB_PID_IN) ? "in" : "out"),
  1244. ep->maxpacket);
  1245. ep = ep->next;
  1246. } while (ep);
  1247. }
  1248. spin_unlock_irq(&isp116x->lock);
  1249. seq_printf(s, "\n");
  1250. return 0;
  1251. }
  1252. static int proc_isp116x_open(struct inode *inode, struct file *file)
  1253. {
  1254. return single_open(file, proc_isp116x_show, PDE(inode)->data);
  1255. }
  1256. static struct file_operations proc_ops = {
  1257. .open = proc_isp116x_open,
  1258. .read = seq_read,
  1259. .llseek = seq_lseek,
  1260. .release = single_release,
  1261. };
  1262. /* expect just one isp116x per system */
  1263. static const char proc_filename[] = "driver/isp116x";
  1264. static void create_debug_file(struct isp116x *isp116x)
  1265. {
  1266. struct proc_dir_entry *pde;
  1267. pde = create_proc_entry(proc_filename, 0, NULL);
  1268. if (pde == NULL)
  1269. return;
  1270. pde->proc_fops = &proc_ops;
  1271. pde->data = isp116x;
  1272. isp116x->pde = pde;
  1273. }
  1274. static void remove_debug_file(struct isp116x *isp116x)
  1275. {
  1276. if (isp116x->pde)
  1277. remove_proc_entry(proc_filename, NULL);
  1278. }
  1279. #endif
  1280. /*-----------------------------------------------------------------*/
  1281. /*
  1282. Software reset - can be called from any contect.
  1283. */
  1284. static int isp116x_sw_reset(struct isp116x *isp116x)
  1285. {
  1286. int retries = 15;
  1287. unsigned long flags;
  1288. int ret = 0;
  1289. spin_lock_irqsave(&isp116x->lock, flags);
  1290. isp116x_write_reg16(isp116x, HCSWRES, HCSWRES_MAGIC);
  1291. isp116x_write_reg32(isp116x, HCCMDSTAT, HCCMDSTAT_HCR);
  1292. while (--retries) {
  1293. /* It usually resets within 1 ms */
  1294. mdelay(1);
  1295. if (!(isp116x_read_reg32(isp116x, HCCMDSTAT) & HCCMDSTAT_HCR))
  1296. break;
  1297. }
  1298. if (!retries) {
  1299. ERR("Software reset timeout\n");
  1300. ret = -ETIME;
  1301. }
  1302. spin_unlock_irqrestore(&isp116x->lock, flags);
  1303. return ret;
  1304. }
  1305. static int isp116x_reset(struct usb_hcd *hcd)
  1306. {
  1307. struct isp116x *isp116x = hcd_to_isp116x(hcd);
  1308. unsigned long t;
  1309. u16 clkrdy = 0;
  1310. int ret = 0, timeout = 15 /* ms */ ;
  1311. ret = isp116x_sw_reset(isp116x);
  1312. if (ret)
  1313. return ret;
  1314. t = jiffies + msecs_to_jiffies(timeout);
  1315. while (time_before_eq(jiffies, t)) {
  1316. msleep(4);
  1317. spin_lock_irq(&isp116x->lock);
  1318. clkrdy = isp116x_read_reg16(isp116x, HCuPINT) & HCuPINT_CLKRDY;
  1319. spin_unlock_irq(&isp116x->lock);
  1320. if (clkrdy)
  1321. break;
  1322. }
  1323. if (!clkrdy) {
  1324. ERR("Clock not ready after 20ms\n");
  1325. /* After sw_reset the clock won't report to be ready, if
  1326. H_WAKEUP pin is high. */
  1327. ERR("Please make sure that the H_WAKEUP pin is pulled low!\n");
  1328. ret = -ENODEV;
  1329. }
  1330. return ret;
  1331. }
  1332. static void isp116x_stop(struct usb_hcd *hcd)
  1333. {
  1334. struct isp116x *isp116x = hcd_to_isp116x(hcd);
  1335. unsigned long flags;
  1336. u32 val;
  1337. spin_lock_irqsave(&isp116x->lock, flags);
  1338. isp116x_write_reg16(isp116x, HCuPINTENB, 0);
  1339. /* Switch off ports' power, some devices don't come up
  1340. after next 'insmod' without this */
  1341. val = isp116x_read_reg32(isp116x, HCRHDESCA);
  1342. val &= ~(RH_A_NPS | RH_A_PSM);
  1343. isp116x_write_reg32(isp116x, HCRHDESCA, val);
  1344. isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_LPS);
  1345. spin_unlock_irqrestore(&isp116x->lock, flags);
  1346. isp116x_sw_reset(isp116x);
  1347. }
  1348. /*
  1349. Configure the chip. The chip must be successfully reset by now.
  1350. */
  1351. static int isp116x_start(struct usb_hcd *hcd)
  1352. {
  1353. struct isp116x *isp116x = hcd_to_isp116x(hcd);
  1354. struct isp116x_platform_data *board = isp116x->board;
  1355. u32 val;
  1356. unsigned long flags;
  1357. spin_lock_irqsave(&isp116x->lock, flags);
  1358. /* clear interrupt status and disable all interrupt sources */
  1359. isp116x_write_reg16(isp116x, HCuPINT, 0xff);
  1360. isp116x_write_reg16(isp116x, HCuPINTENB, 0);
  1361. val = isp116x_read_reg16(isp116x, HCCHIPID);
  1362. if ((val & HCCHIPID_MASK) != HCCHIPID_MAGIC) {
  1363. ERR("Invalid chip ID %04x\n", val);
  1364. spin_unlock_irqrestore(&isp116x->lock, flags);
  1365. return -ENODEV;
  1366. }
  1367. /* To be removed in future */
  1368. hcd->uses_new_polling = 1;
  1369. isp116x_write_reg16(isp116x, HCITLBUFLEN, ISP116x_ITL_BUFSIZE);
  1370. isp116x_write_reg16(isp116x, HCATLBUFLEN, ISP116x_ATL_BUFSIZE);
  1371. /* ----- HW conf */
  1372. val = HCHWCFG_INT_ENABLE | HCHWCFG_DBWIDTH(1);
  1373. if (board->sel15Kres)
  1374. val |= HCHWCFG_15KRSEL;
  1375. /* Remote wakeup won't work without working clock */
  1376. if (board->remote_wakeup_enable)
  1377. val |= HCHWCFG_CLKNOTSTOP;
  1378. if (board->oc_enable)
  1379. val |= HCHWCFG_ANALOG_OC;
  1380. if (board->int_act_high)
  1381. val |= HCHWCFG_INT_POL;
  1382. if (board->int_edge_triggered)
  1383. val |= HCHWCFG_INT_TRIGGER;
  1384. isp116x_write_reg16(isp116x, HCHWCFG, val);
  1385. /* ----- Root hub conf */
  1386. val = (25 << 24) & RH_A_POTPGT;
  1387. /* AN10003_1.pdf recommends RH_A_NPS (no power switching) to
  1388. be always set. Yet, instead, we request individual port
  1389. power switching. */
  1390. val |= RH_A_PSM;
  1391. /* Report overcurrent per port */
  1392. val |= RH_A_OCPM;
  1393. isp116x_write_reg32(isp116x, HCRHDESCA, val);
  1394. isp116x->rhdesca = isp116x_read_reg32(isp116x, HCRHDESCA);
  1395. val = RH_B_PPCM;
  1396. isp116x_write_reg32(isp116x, HCRHDESCB, val);
  1397. isp116x->rhdescb = isp116x_read_reg32(isp116x, HCRHDESCB);
  1398. val = 0;
  1399. if (board->remote_wakeup_enable) {
  1400. hcd->can_wakeup = 1;
  1401. val |= RH_HS_DRWE;
  1402. }
  1403. isp116x_write_reg32(isp116x, HCRHSTATUS, val);
  1404. isp116x->rhstatus = isp116x_read_reg32(isp116x, HCRHSTATUS);
  1405. isp116x_write_reg32(isp116x, HCFMINTVL, 0x27782edf);
  1406. hcd->state = HC_STATE_RUNNING;
  1407. /* Set up interrupts */
  1408. isp116x->intenb = HCINT_MIE | HCINT_RHSC | HCINT_UE;
  1409. if (board->remote_wakeup_enable)
  1410. isp116x->intenb |= HCINT_RD;
  1411. isp116x->irqenb = HCuPINT_ATL | HCuPINT_OPR; /* | HCuPINT_SUSP; */
  1412. isp116x_write_reg32(isp116x, HCINTENB, isp116x->intenb);
  1413. isp116x_write_reg16(isp116x, HCuPINTENB, isp116x->irqenb);
  1414. /* Go operational */
  1415. val = HCCONTROL_USB_OPER;
  1416. if (board->remote_wakeup_enable)
  1417. val |= HCCONTROL_RWE;
  1418. isp116x_write_reg32(isp116x, HCCONTROL, val);
  1419. /* Disable ports to avoid race in device enumeration */
  1420. isp116x_write_reg32(isp116x, HCRHPORT1, RH_PS_CCS);
  1421. isp116x_write_reg32(isp116x, HCRHPORT2, RH_PS_CCS);
  1422. isp116x_show_regs(isp116x);
  1423. spin_unlock_irqrestore(&isp116x->lock, flags);
  1424. return 0;
  1425. }
  1426. /*-----------------------------------------------------------------*/
  1427. static struct hc_driver isp116x_hc_driver = {
  1428. .description = hcd_name,
  1429. .product_desc = "ISP116x Host Controller",
  1430. .hcd_priv_size = sizeof(struct isp116x),
  1431. .irq = isp116x_irq,
  1432. .flags = HCD_USB11,
  1433. .reset = isp116x_reset,
  1434. .start = isp116x_start,
  1435. .stop = isp116x_stop,
  1436. .urb_enqueue = isp116x_urb_enqueue,
  1437. .urb_dequeue = isp116x_urb_dequeue,
  1438. .endpoint_disable = isp116x_endpoint_disable,
  1439. .get_frame_number = isp116x_get_frame,
  1440. .hub_status_data = isp116x_hub_status_data,
  1441. .hub_control = isp116x_hub_control,
  1442. .hub_suspend = isp116x_hub_suspend,
  1443. .hub_resume = isp116x_hub_resume,
  1444. };
  1445. /*----------------------------------------------------------------*/
  1446. static int __init_or_module isp116x_remove(struct device *dev)
  1447. {
  1448. struct usb_hcd *hcd = dev_get_drvdata(dev);
  1449. struct isp116x *isp116x;
  1450. struct platform_device *pdev;
  1451. struct resource *res;
  1452. if (!hcd)
  1453. return 0;
  1454. isp116x = hcd_to_isp116x(hcd);
  1455. pdev = container_of(dev, struct platform_device, dev);
  1456. remove_debug_file(isp116x);
  1457. usb_remove_hcd(hcd);
  1458. iounmap(isp116x->data_reg);
  1459. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  1460. release_mem_region(res->start, 2);
  1461. iounmap(isp116x->addr_reg);
  1462. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1463. release_mem_region(res->start, 2);
  1464. usb_put_hcd(hcd);
  1465. return 0;
  1466. }
  1467. #define resource_len(r) (((r)->end - (r)->start) + 1)
  1468. static int __init isp116x_probe(struct device *dev)
  1469. {
  1470. struct usb_hcd *hcd;
  1471. struct isp116x *isp116x;
  1472. struct platform_device *pdev;
  1473. struct resource *addr, *data;
  1474. void __iomem *addr_reg;
  1475. void __iomem *data_reg;
  1476. int irq;
  1477. int ret = 0;
  1478. pdev = container_of(dev, struct platform_device, dev);
  1479. if (pdev->num_resources < 3) {
  1480. ret = -ENODEV;
  1481. goto err1;
  1482. }
  1483. data = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1484. addr = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  1485. irq = platform_get_irq(pdev, 0);
  1486. if (!addr || !data || irq < 0) {
  1487. ret = -ENODEV;
  1488. goto err1;
  1489. }
  1490. if (dev->dma_mask) {
  1491. DBG("DMA not supported\n");
  1492. ret = -EINVAL;
  1493. goto err1;
  1494. }
  1495. if (!request_mem_region(addr->start, 2, hcd_name)) {
  1496. ret = -EBUSY;
  1497. goto err1;
  1498. }
  1499. addr_reg = ioremap(addr->start, resource_len(addr));
  1500. if (addr_reg == NULL) {
  1501. ret = -ENOMEM;
  1502. goto err2;
  1503. }
  1504. if (!request_mem_region(data->start, 2, hcd_name)) {
  1505. ret = -EBUSY;
  1506. goto err3;
  1507. }
  1508. data_reg = ioremap(data->start, resource_len(data));
  1509. if (data_reg == NULL) {
  1510. ret = -ENOMEM;
  1511. goto err4;
  1512. }
  1513. /* allocate and initialize hcd */
  1514. hcd = usb_create_hcd(&isp116x_hc_driver, dev, dev->bus_id);
  1515. if (!hcd) {
  1516. ret = -ENOMEM;
  1517. goto err5;
  1518. }
  1519. /* this rsrc_start is bogus */
  1520. hcd->rsrc_start = addr->start;
  1521. isp116x = hcd_to_isp116x(hcd);
  1522. isp116x->data_reg = data_reg;
  1523. isp116x->addr_reg = addr_reg;
  1524. spin_lock_init(&isp116x->lock);
  1525. INIT_LIST_HEAD(&isp116x->async);
  1526. INIT_WORK(&isp116x->rh_resume, isp116x_rh_resume, hcd);
  1527. isp116x->board = dev->platform_data;
  1528. if (!isp116x->board) {
  1529. ERR("Platform data structure not initialized\n");
  1530. ret = -ENODEV;
  1531. goto err6;
  1532. }
  1533. if (isp116x_check_platform_delay(isp116x)) {
  1534. ERR("USE_PLATFORM_DELAY defined, but delay function not "
  1535. "implemented.\n");
  1536. ERR("See comments in drivers/usb/host/isp116x-hcd.c\n");
  1537. ret = -ENODEV;
  1538. goto err6;
  1539. }
  1540. ret = usb_add_hcd(hcd, irq, SA_INTERRUPT);
  1541. if (ret != 0)
  1542. goto err6;
  1543. create_debug_file(isp116x);
  1544. return 0;
  1545. err6:
  1546. usb_put_hcd(hcd);
  1547. err5:
  1548. iounmap(data_reg);
  1549. err4:
  1550. release_mem_region(data->start, 2);
  1551. err3:
  1552. iounmap(addr_reg);
  1553. err2:
  1554. release_mem_region(addr->start, 2);
  1555. err1:
  1556. ERR("init error, %d\n", ret);
  1557. return ret;
  1558. }
  1559. #ifdef CONFIG_PM
  1560. /*
  1561. Suspend of platform device
  1562. */
  1563. static int isp116x_suspend(struct device *dev, pm_message_t state, u32 phase)
  1564. {
  1565. int ret = 0;
  1566. struct usb_hcd *hcd = dev_get_drvdata(dev);
  1567. VDBG("%s: state %x, phase %x\n", __func__, state, phase);
  1568. if (phase != SUSPEND_DISABLE && phase != SUSPEND_POWER_DOWN)
  1569. return 0;
  1570. ret = usb_suspend_device(hcd->self.root_hub, state);
  1571. if (!ret) {
  1572. dev->power.power_state = state;
  1573. INFO("%s suspended\n", hcd_name);
  1574. } else
  1575. ERR("%s suspend failed\n", hcd_name);
  1576. return ret;
  1577. }
  1578. /*
  1579. Resume platform device
  1580. */
  1581. static int isp116x_resume(struct device *dev, u32 phase)
  1582. {
  1583. int ret = 0;
  1584. struct usb_hcd *hcd = dev_get_drvdata(dev);
  1585. VDBG("%s: state %x, phase %x\n", __func__, dev->power.power_state,
  1586. phase);
  1587. if (phase != RESUME_POWER_ON)
  1588. return 0;
  1589. ret = usb_resume_device(hcd->self.root_hub);
  1590. if (!ret) {
  1591. dev->power.power_state = PMSG_ON;
  1592. VDBG("%s resumed\n", (char *)hcd_name);
  1593. }
  1594. return ret;
  1595. }
  1596. #else
  1597. #define isp116x_suspend NULL
  1598. #define isp116x_resume NULL
  1599. #endif
  1600. static struct device_driver isp116x_driver = {
  1601. .name = (char *)hcd_name,
  1602. .bus = &platform_bus_type,
  1603. .probe = isp116x_probe,
  1604. .remove = isp116x_remove,
  1605. .suspend = isp116x_suspend,
  1606. .resume = isp116x_resume,
  1607. };
  1608. /*-----------------------------------------------------------------*/
  1609. static int __init isp116x_init(void)
  1610. {
  1611. if (usb_disabled())
  1612. return -ENODEV;
  1613. INFO("driver %s, %s\n", hcd_name, DRIVER_VERSION);
  1614. return driver_register(&isp116x_driver);
  1615. }
  1616. module_init(isp116x_init);
  1617. static void __exit isp116x_cleanup(void)
  1618. {
  1619. driver_unregister(&isp116x_driver);
  1620. }
  1621. module_exit(isp116x_cleanup);