sl811-hcd.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836
  1. /*
  2. * SL811HS HCD (Host Controller Driver) for USB.
  3. *
  4. * Copyright (C) 2004 Psion Teklogix (for NetBook PRO)
  5. * Copyright (C) 2004-2005 David Brownell
  6. *
  7. * Periodic scheduling is based on Roman's OHCI code
  8. * Copyright (C) 1999 Roman Weissgaerber
  9. *
  10. * The SL811HS controller handles host side USB (like the SL11H, but with
  11. * another register set and SOF generation) as well as peripheral side USB
  12. * (like the SL811S). This driver version doesn't implement the Gadget API
  13. * for the peripheral role; or OTG (that'd need much external circuitry).
  14. *
  15. * For documentation, see the SL811HS spec and the "SL811HS Embedded Host"
  16. * document (providing significant pieces missing from that spec); plus
  17. * the SL811S spec if you want peripheral side info.
  18. */
  19. /*
  20. * Status: Passed basic stress testing, works with hubs, mice, keyboards,
  21. * and usb-storage.
  22. *
  23. * TODO:
  24. * - usb suspend/resume triggered by sl811 (with USB_SUSPEND)
  25. * - various issues noted in the code
  26. * - performance work; use both register banks; ...
  27. * - use urb->iso_frame_desc[] with ISO transfers
  28. */
  29. #undef VERBOSE
  30. #undef PACKET_TRACE
  31. #include <linux/module.h>
  32. #include <linux/moduleparam.h>
  33. #include <linux/kernel.h>
  34. #include <linux/delay.h>
  35. #include <linux/ioport.h>
  36. #include <linux/sched.h>
  37. #include <linux/slab.h>
  38. #include <linux/errno.h>
  39. #include <linux/init.h>
  40. #include <linux/timer.h>
  41. #include <linux/list.h>
  42. #include <linux/interrupt.h>
  43. #include <linux/usb.h>
  44. #include <linux/usb/sl811.h>
  45. #include <linux/platform_device.h>
  46. #include <asm/io.h>
  47. #include <asm/irq.h>
  48. #include <asm/system.h>
  49. #include <asm/byteorder.h>
  50. #include "../core/hcd.h"
  51. #include "sl811.h"
  52. MODULE_DESCRIPTION("SL811HS USB Host Controller Driver");
  53. MODULE_LICENSE("GPL");
  54. MODULE_ALIAS("platform:sl811-hcd");
  55. #define DRIVER_VERSION "19 May 2005"
  56. #ifndef DEBUG
  57. # define STUB_DEBUG_FILE
  58. #endif
  59. /* for now, use only one transfer register bank */
  60. #undef USE_B
  61. /* this doesn't understand urb->iso_frame_desc[], but if you had a driver
  62. * that just queued one ISO frame per URB then iso transfers "should" work
  63. * using the normal urb status fields.
  64. */
  65. #define DISABLE_ISO
  66. // #define QUIRK2
  67. #define QUIRK3
  68. static const char hcd_name[] = "sl811-hcd";
  69. /*-------------------------------------------------------------------------*/
  70. static void port_power(struct sl811 *sl811, int is_on)
  71. {
  72. struct usb_hcd *hcd = sl811_to_hcd(sl811);
  73. /* hub is inactive unless the port is powered */
  74. if (is_on) {
  75. if (sl811->port1 & (1 << USB_PORT_FEAT_POWER))
  76. return;
  77. sl811->port1 = (1 << USB_PORT_FEAT_POWER);
  78. sl811->irq_enable = SL11H_INTMASK_INSRMV;
  79. } else {
  80. sl811->port1 = 0;
  81. sl811->irq_enable = 0;
  82. hcd->state = HC_STATE_HALT;
  83. }
  84. sl811->ctrl1 = 0;
  85. sl811_write(sl811, SL11H_IRQ_ENABLE, 0);
  86. sl811_write(sl811, SL11H_IRQ_STATUS, ~0);
  87. if (sl811->board && sl811->board->port_power) {
  88. /* switch VBUS, at 500mA unless hub power budget gets set */
  89. DBG("power %s\n", is_on ? "on" : "off");
  90. sl811->board->port_power(hcd->self.controller, is_on);
  91. }
  92. /* reset as thoroughly as we can */
  93. if (sl811->board && sl811->board->reset)
  94. sl811->board->reset(hcd->self.controller);
  95. else {
  96. sl811_write(sl811, SL11H_CTLREG1, SL11H_CTL1MASK_SE0);
  97. mdelay(20);
  98. }
  99. sl811_write(sl811, SL11H_IRQ_ENABLE, 0);
  100. sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
  101. sl811_write(sl811, SL811HS_CTLREG2, SL811HS_CTL2_INIT);
  102. sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
  103. // if !is_on, put into lowpower mode now
  104. }
  105. /*-------------------------------------------------------------------------*/
  106. /* This is a PIO-only HCD. Queueing appends URBs to the endpoint's queue,
  107. * and may start I/O. Endpoint queues are scanned during completion irq
  108. * handlers (one per packet: ACK, NAK, faults, etc) and urb cancellation.
  109. *
  110. * Using an external DMA engine to copy a packet at a time could work,
  111. * though setup/teardown costs may be too big to make it worthwhile.
  112. */
  113. /* SETUP starts a new control request. Devices are not allowed to
  114. * STALL or NAK these; they must cancel any pending control requests.
  115. */
  116. static void setup_packet(
  117. struct sl811 *sl811,
  118. struct sl811h_ep *ep,
  119. struct urb *urb,
  120. u8 bank,
  121. u8 control
  122. )
  123. {
  124. u8 addr;
  125. u8 len;
  126. void __iomem *data_reg;
  127. addr = SL811HS_PACKET_BUF(bank == 0);
  128. len = sizeof(struct usb_ctrlrequest);
  129. data_reg = sl811->data_reg;
  130. sl811_write_buf(sl811, addr, urb->setup_packet, len);
  131. /* autoincrementing */
  132. sl811_write(sl811, bank + SL11H_BUFADDRREG, addr);
  133. writeb(len, data_reg);
  134. writeb(SL_SETUP /* | ep->epnum */, data_reg);
  135. writeb(usb_pipedevice(urb->pipe), data_reg);
  136. /* always OUT/data0 */ ;
  137. sl811_write(sl811, bank + SL11H_HOSTCTLREG,
  138. control | SL11H_HCTLMASK_OUT);
  139. ep->length = 0;
  140. PACKET("SETUP qh%p\n", ep);
  141. }
  142. /* STATUS finishes control requests, often after IN or OUT data packets */
  143. static void status_packet(
  144. struct sl811 *sl811,
  145. struct sl811h_ep *ep,
  146. struct urb *urb,
  147. u8 bank,
  148. u8 control
  149. )
  150. {
  151. int do_out;
  152. void __iomem *data_reg;
  153. do_out = urb->transfer_buffer_length && usb_pipein(urb->pipe);
  154. data_reg = sl811->data_reg;
  155. /* autoincrementing */
  156. sl811_write(sl811, bank + SL11H_BUFADDRREG, 0);
  157. writeb(0, data_reg);
  158. writeb((do_out ? SL_OUT : SL_IN) /* | ep->epnum */, data_reg);
  159. writeb(usb_pipedevice(urb->pipe), data_reg);
  160. /* always data1; sometimes IN */
  161. control |= SL11H_HCTLMASK_TOGGLE;
  162. if (do_out)
  163. control |= SL11H_HCTLMASK_OUT;
  164. sl811_write(sl811, bank + SL11H_HOSTCTLREG, control);
  165. ep->length = 0;
  166. PACKET("STATUS%s/%s qh%p\n", ep->nak_count ? "/retry" : "",
  167. do_out ? "out" : "in", ep);
  168. }
  169. /* IN packets can be used with any type of endpoint. here we just
  170. * start the transfer, data from the peripheral may arrive later.
  171. * urb->iso_frame_desc is currently ignored here...
  172. */
  173. static void in_packet(
  174. struct sl811 *sl811,
  175. struct sl811h_ep *ep,
  176. struct urb *urb,
  177. u8 bank,
  178. u8 control
  179. )
  180. {
  181. u8 addr;
  182. u8 len;
  183. void __iomem *data_reg;
  184. /* avoid losing data on overflow */
  185. len = ep->maxpacket;
  186. addr = SL811HS_PACKET_BUF(bank == 0);
  187. if (!(control & SL11H_HCTLMASK_ISOCH)
  188. && usb_gettoggle(urb->dev, ep->epnum, 0))
  189. control |= SL11H_HCTLMASK_TOGGLE;
  190. data_reg = sl811->data_reg;
  191. /* autoincrementing */
  192. sl811_write(sl811, bank + SL11H_BUFADDRREG, addr);
  193. writeb(len, data_reg);
  194. writeb(SL_IN | ep->epnum, data_reg);
  195. writeb(usb_pipedevice(urb->pipe), data_reg);
  196. sl811_write(sl811, bank + SL11H_HOSTCTLREG, control);
  197. ep->length = min_t(u32, len,
  198. urb->transfer_buffer_length - urb->actual_length);
  199. PACKET("IN%s/%d qh%p len%d\n", ep->nak_count ? "/retry" : "",
  200. !!usb_gettoggle(urb->dev, ep->epnum, 0), ep, len);
  201. }
  202. /* OUT packets can be used with any type of endpoint.
  203. * urb->iso_frame_desc is currently ignored here...
  204. */
  205. static void out_packet(
  206. struct sl811 *sl811,
  207. struct sl811h_ep *ep,
  208. struct urb *urb,
  209. u8 bank,
  210. u8 control
  211. )
  212. {
  213. void *buf;
  214. u8 addr;
  215. u8 len;
  216. void __iomem *data_reg;
  217. buf = urb->transfer_buffer + urb->actual_length;
  218. prefetch(buf);
  219. len = min_t(u32, ep->maxpacket,
  220. urb->transfer_buffer_length - urb->actual_length);
  221. if (!(control & SL11H_HCTLMASK_ISOCH)
  222. && usb_gettoggle(urb->dev, ep->epnum, 1))
  223. control |= SL11H_HCTLMASK_TOGGLE;
  224. addr = SL811HS_PACKET_BUF(bank == 0);
  225. data_reg = sl811->data_reg;
  226. sl811_write_buf(sl811, addr, buf, len);
  227. /* autoincrementing */
  228. sl811_write(sl811, bank + SL11H_BUFADDRREG, addr);
  229. writeb(len, data_reg);
  230. writeb(SL_OUT | ep->epnum, data_reg);
  231. writeb(usb_pipedevice(urb->pipe), data_reg);
  232. sl811_write(sl811, bank + SL11H_HOSTCTLREG,
  233. control | SL11H_HCTLMASK_OUT);
  234. ep->length = len;
  235. PACKET("OUT%s/%d qh%p len%d\n", ep->nak_count ? "/retry" : "",
  236. !!usb_gettoggle(urb->dev, ep->epnum, 1), ep, len);
  237. }
  238. /*-------------------------------------------------------------------------*/
  239. /* caller updates on-chip enables later */
  240. static inline void sofirq_on(struct sl811 *sl811)
  241. {
  242. if (sl811->irq_enable & SL11H_INTMASK_SOFINTR)
  243. return;
  244. VDBG("sof irq on\n");
  245. sl811->irq_enable |= SL11H_INTMASK_SOFINTR;
  246. }
  247. static inline void sofirq_off(struct sl811 *sl811)
  248. {
  249. if (!(sl811->irq_enable & SL11H_INTMASK_SOFINTR))
  250. return;
  251. VDBG("sof irq off\n");
  252. sl811->irq_enable &= ~SL11H_INTMASK_SOFINTR;
  253. }
  254. /*-------------------------------------------------------------------------*/
  255. /* pick the next endpoint for a transaction, and issue it.
  256. * frames start with periodic transfers (after whatever is pending
  257. * from the previous frame), and the rest of the time is async
  258. * transfers, scheduled round-robin.
  259. */
  260. static struct sl811h_ep *start(struct sl811 *sl811, u8 bank)
  261. {
  262. struct sl811h_ep *ep;
  263. struct urb *urb;
  264. int fclock;
  265. u8 control;
  266. /* use endpoint at schedule head */
  267. if (sl811->next_periodic) {
  268. ep = sl811->next_periodic;
  269. sl811->next_periodic = ep->next;
  270. } else {
  271. if (sl811->next_async)
  272. ep = sl811->next_async;
  273. else if (!list_empty(&sl811->async))
  274. ep = container_of(sl811->async.next,
  275. struct sl811h_ep, schedule);
  276. else {
  277. /* could set up the first fullspeed periodic
  278. * transfer for the next frame ...
  279. */
  280. return NULL;
  281. }
  282. #ifdef USE_B
  283. if ((bank && sl811->active_b == ep) || sl811->active_a == ep)
  284. return NULL;
  285. #endif
  286. if (ep->schedule.next == &sl811->async)
  287. sl811->next_async = NULL;
  288. else
  289. sl811->next_async = container_of(ep->schedule.next,
  290. struct sl811h_ep, schedule);
  291. }
  292. if (unlikely(list_empty(&ep->hep->urb_list))) {
  293. DBG("empty %p queue?\n", ep);
  294. return NULL;
  295. }
  296. urb = container_of(ep->hep->urb_list.next, struct urb, urb_list);
  297. control = ep->defctrl;
  298. /* if this frame doesn't have enough time left to transfer this
  299. * packet, wait till the next frame. too-simple algorithm...
  300. */
  301. fclock = sl811_read(sl811, SL11H_SOFTMRREG) << 6;
  302. fclock -= 100; /* setup takes not much time */
  303. if (urb->dev->speed == USB_SPEED_LOW) {
  304. if (control & SL11H_HCTLMASK_PREAMBLE) {
  305. /* also note erratum 1: some hubs won't work */
  306. fclock -= 800;
  307. }
  308. fclock -= ep->maxpacket << 8;
  309. /* erratum 2: AFTERSOF only works for fullspeed */
  310. if (fclock < 0) {
  311. if (ep->period)
  312. sl811->stat_overrun++;
  313. sofirq_on(sl811);
  314. return NULL;
  315. }
  316. } else {
  317. fclock -= 12000 / 19; /* 19 64byte packets/msec */
  318. if (fclock < 0) {
  319. if (ep->period)
  320. sl811->stat_overrun++;
  321. control |= SL11H_HCTLMASK_AFTERSOF;
  322. /* throttle bulk/control irq noise */
  323. } else if (ep->nak_count)
  324. control |= SL11H_HCTLMASK_AFTERSOF;
  325. }
  326. switch (ep->nextpid) {
  327. case USB_PID_IN:
  328. in_packet(sl811, ep, urb, bank, control);
  329. break;
  330. case USB_PID_OUT:
  331. out_packet(sl811, ep, urb, bank, control);
  332. break;
  333. case USB_PID_SETUP:
  334. setup_packet(sl811, ep, urb, bank, control);
  335. break;
  336. case USB_PID_ACK: /* for control status */
  337. status_packet(sl811, ep, urb, bank, control);
  338. break;
  339. default:
  340. DBG("bad ep%p pid %02x\n", ep, ep->nextpid);
  341. ep = NULL;
  342. }
  343. return ep;
  344. }
  345. #define MIN_JIFFIES ((msecs_to_jiffies(2) > 1) ? msecs_to_jiffies(2) : 2)
  346. static inline void start_transfer(struct sl811 *sl811)
  347. {
  348. if (sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND))
  349. return;
  350. if (sl811->active_a == NULL) {
  351. sl811->active_a = start(sl811, SL811_EP_A(SL811_HOST_BUF));
  352. if (sl811->active_a != NULL)
  353. sl811->jiffies_a = jiffies + MIN_JIFFIES;
  354. }
  355. #ifdef USE_B
  356. if (sl811->active_b == NULL) {
  357. sl811->active_b = start(sl811, SL811_EP_B(SL811_HOST_BUF));
  358. if (sl811->active_b != NULL)
  359. sl811->jiffies_b = jiffies + MIN_JIFFIES;
  360. }
  361. #endif
  362. }
  363. static void finish_request(
  364. struct sl811 *sl811,
  365. struct sl811h_ep *ep,
  366. struct urb *urb,
  367. int status
  368. ) __releases(sl811->lock) __acquires(sl811->lock)
  369. {
  370. unsigned i;
  371. if (usb_pipecontrol(urb->pipe))
  372. ep->nextpid = USB_PID_SETUP;
  373. usb_hcd_unlink_urb_from_ep(sl811_to_hcd(sl811), urb);
  374. spin_unlock(&sl811->lock);
  375. usb_hcd_giveback_urb(sl811_to_hcd(sl811), urb, status);
  376. spin_lock(&sl811->lock);
  377. /* leave active endpoints in the schedule */
  378. if (!list_empty(&ep->hep->urb_list))
  379. return;
  380. /* async deschedule? */
  381. if (!list_empty(&ep->schedule)) {
  382. list_del_init(&ep->schedule);
  383. if (ep == sl811->next_async)
  384. sl811->next_async = NULL;
  385. return;
  386. }
  387. /* periodic deschedule */
  388. DBG("deschedule qh%d/%p branch %d\n", ep->period, ep, ep->branch);
  389. for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
  390. struct sl811h_ep *temp;
  391. struct sl811h_ep **prev = &sl811->periodic[i];
  392. while (*prev && ((temp = *prev) != ep))
  393. prev = &temp->next;
  394. if (*prev)
  395. *prev = ep->next;
  396. sl811->load[i] -= ep->load;
  397. }
  398. ep->branch = PERIODIC_SIZE;
  399. sl811->periodic_count--;
  400. sl811_to_hcd(sl811)->self.bandwidth_allocated
  401. -= ep->load / ep->period;
  402. if (ep == sl811->next_periodic)
  403. sl811->next_periodic = ep->next;
  404. /* we might turn SOFs back on again for the async schedule */
  405. if (sl811->periodic_count == 0)
  406. sofirq_off(sl811);
  407. }
  408. static void
  409. done(struct sl811 *sl811, struct sl811h_ep *ep, u8 bank)
  410. {
  411. u8 status;
  412. struct urb *urb;
  413. int urbstat = -EINPROGRESS;
  414. if (unlikely(!ep))
  415. return;
  416. status = sl811_read(sl811, bank + SL11H_PKTSTATREG);
  417. urb = container_of(ep->hep->urb_list.next, struct urb, urb_list);
  418. /* we can safely ignore NAKs */
  419. if (status & SL11H_STATMASK_NAK) {
  420. // PACKET("...NAK_%02x qh%p\n", bank, ep);
  421. if (!ep->period)
  422. ep->nak_count++;
  423. ep->error_count = 0;
  424. /* ACK advances transfer, toggle, and maybe queue */
  425. } else if (status & SL11H_STATMASK_ACK) {
  426. struct usb_device *udev = urb->dev;
  427. int len;
  428. unsigned char *buf;
  429. /* urb->iso_frame_desc is currently ignored here... */
  430. ep->nak_count = ep->error_count = 0;
  431. switch (ep->nextpid) {
  432. case USB_PID_OUT:
  433. // PACKET("...ACK/out_%02x qh%p\n", bank, ep);
  434. urb->actual_length += ep->length;
  435. usb_dotoggle(udev, ep->epnum, 1);
  436. if (urb->actual_length
  437. == urb->transfer_buffer_length) {
  438. if (usb_pipecontrol(urb->pipe))
  439. ep->nextpid = USB_PID_ACK;
  440. /* some bulk protocols terminate OUT transfers
  441. * by a short packet, using ZLPs not padding.
  442. */
  443. else if (ep->length < ep->maxpacket
  444. || !(urb->transfer_flags
  445. & URB_ZERO_PACKET))
  446. urbstat = 0;
  447. }
  448. break;
  449. case USB_PID_IN:
  450. // PACKET("...ACK/in_%02x qh%p\n", bank, ep);
  451. buf = urb->transfer_buffer + urb->actual_length;
  452. prefetchw(buf);
  453. len = ep->maxpacket - sl811_read(sl811,
  454. bank + SL11H_XFERCNTREG);
  455. if (len > ep->length) {
  456. len = ep->length;
  457. urbstat = -EOVERFLOW;
  458. }
  459. urb->actual_length += len;
  460. sl811_read_buf(sl811, SL811HS_PACKET_BUF(bank == 0),
  461. buf, len);
  462. usb_dotoggle(udev, ep->epnum, 0);
  463. if (urbstat == -EINPROGRESS &&
  464. (len < ep->maxpacket ||
  465. urb->actual_length ==
  466. urb->transfer_buffer_length)) {
  467. if (usb_pipecontrol(urb->pipe))
  468. ep->nextpid = USB_PID_ACK;
  469. else
  470. urbstat = 0;
  471. }
  472. break;
  473. case USB_PID_SETUP:
  474. // PACKET("...ACK/setup_%02x qh%p\n", bank, ep);
  475. if (urb->transfer_buffer_length == urb->actual_length)
  476. ep->nextpid = USB_PID_ACK;
  477. else if (usb_pipeout(urb->pipe)) {
  478. usb_settoggle(udev, 0, 1, 1);
  479. ep->nextpid = USB_PID_OUT;
  480. } else {
  481. usb_settoggle(udev, 0, 0, 1);
  482. ep->nextpid = USB_PID_IN;
  483. }
  484. break;
  485. case USB_PID_ACK:
  486. // PACKET("...ACK/status_%02x qh%p\n", bank, ep);
  487. urbstat = 0;
  488. break;
  489. }
  490. /* STALL stops all transfers */
  491. } else if (status & SL11H_STATMASK_STALL) {
  492. PACKET("...STALL_%02x qh%p\n", bank, ep);
  493. ep->nak_count = ep->error_count = 0;
  494. urbstat = -EPIPE;
  495. /* error? retry, until "3 strikes" */
  496. } else if (++ep->error_count >= 3) {
  497. if (status & SL11H_STATMASK_TMOUT)
  498. urbstat = -ETIME;
  499. else if (status & SL11H_STATMASK_OVF)
  500. urbstat = -EOVERFLOW;
  501. else
  502. urbstat = -EPROTO;
  503. ep->error_count = 0;
  504. PACKET("...3STRIKES_%02x %02x qh%p stat %d\n",
  505. bank, status, ep, urbstat);
  506. }
  507. if (urbstat != -EINPROGRESS || urb->unlinked)
  508. finish_request(sl811, ep, urb, urbstat);
  509. }
  510. static inline u8 checkdone(struct sl811 *sl811)
  511. {
  512. u8 ctl;
  513. u8 irqstat = 0;
  514. if (sl811->active_a && time_before_eq(sl811->jiffies_a, jiffies)) {
  515. ctl = sl811_read(sl811, SL811_EP_A(SL11H_HOSTCTLREG));
  516. if (ctl & SL11H_HCTLMASK_ARM)
  517. sl811_write(sl811, SL811_EP_A(SL11H_HOSTCTLREG), 0);
  518. DBG("%s DONE_A: ctrl %02x sts %02x\n",
  519. (ctl & SL11H_HCTLMASK_ARM) ? "timeout" : "lost",
  520. ctl,
  521. sl811_read(sl811, SL811_EP_A(SL11H_PKTSTATREG)));
  522. irqstat |= SL11H_INTMASK_DONE_A;
  523. }
  524. #ifdef USE_B
  525. if (sl811->active_b && time_before_eq(sl811->jiffies_b, jiffies)) {
  526. ctl = sl811_read(sl811, SL811_EP_B(SL11H_HOSTCTLREG));
  527. if (ctl & SL11H_HCTLMASK_ARM)
  528. sl811_write(sl811, SL811_EP_B(SL11H_HOSTCTLREG), 0);
  529. DBG("%s DONE_B: ctrl %02x sts %02x\n",
  530. (ctl & SL11H_HCTLMASK_ARM) ? "timeout" : "lost",
  531. ctl,
  532. sl811_read(sl811, SL811_EP_B(SL11H_PKTSTATREG)));
  533. irqstat |= SL11H_INTMASK_DONE_A;
  534. }
  535. #endif
  536. return irqstat;
  537. }
  538. static irqreturn_t sl811h_irq(struct usb_hcd *hcd)
  539. {
  540. struct sl811 *sl811 = hcd_to_sl811(hcd);
  541. u8 irqstat;
  542. irqreturn_t ret = IRQ_NONE;
  543. unsigned retries = 5;
  544. spin_lock(&sl811->lock);
  545. retry:
  546. irqstat = sl811_read(sl811, SL11H_IRQ_STATUS) & ~SL11H_INTMASK_DP;
  547. if (irqstat) {
  548. sl811_write(sl811, SL11H_IRQ_STATUS, irqstat);
  549. irqstat &= sl811->irq_enable;
  550. }
  551. #ifdef QUIRK2
  552. /* this may no longer be necessary ... */
  553. if (irqstat == 0) {
  554. irqstat = checkdone(sl811);
  555. if (irqstat)
  556. sl811->stat_lost++;
  557. }
  558. #endif
  559. /* USB packets, not necessarily handled in the order they're
  560. * issued ... that's fine if they're different endpoints.
  561. */
  562. if (irqstat & SL11H_INTMASK_DONE_A) {
  563. done(sl811, sl811->active_a, SL811_EP_A(SL811_HOST_BUF));
  564. sl811->active_a = NULL;
  565. sl811->stat_a++;
  566. }
  567. #ifdef USE_B
  568. if (irqstat & SL11H_INTMASK_DONE_B) {
  569. done(sl811, sl811->active_b, SL811_EP_B(SL811_HOST_BUF));
  570. sl811->active_b = NULL;
  571. sl811->stat_b++;
  572. }
  573. #endif
  574. if (irqstat & SL11H_INTMASK_SOFINTR) {
  575. unsigned index;
  576. index = sl811->frame++ % (PERIODIC_SIZE - 1);
  577. sl811->stat_sof++;
  578. /* be graceful about almost-inevitable periodic schedule
  579. * overruns: continue the previous frame's transfers iff
  580. * this one has nothing scheduled.
  581. */
  582. if (sl811->next_periodic) {
  583. // ERR("overrun to slot %d\n", index);
  584. sl811->stat_overrun++;
  585. }
  586. if (sl811->periodic[index])
  587. sl811->next_periodic = sl811->periodic[index];
  588. }
  589. /* khubd manages debouncing and wakeup */
  590. if (irqstat & SL11H_INTMASK_INSRMV) {
  591. sl811->stat_insrmv++;
  592. /* most stats are reset for each VBUS session */
  593. sl811->stat_wake = 0;
  594. sl811->stat_sof = 0;
  595. sl811->stat_a = 0;
  596. sl811->stat_b = 0;
  597. sl811->stat_lost = 0;
  598. sl811->ctrl1 = 0;
  599. sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
  600. sl811->irq_enable = SL11H_INTMASK_INSRMV;
  601. sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
  602. /* usbcore nukes other pending transactions on disconnect */
  603. if (sl811->active_a) {
  604. sl811_write(sl811, SL811_EP_A(SL11H_HOSTCTLREG), 0);
  605. finish_request(sl811, sl811->active_a,
  606. container_of(sl811->active_a
  607. ->hep->urb_list.next,
  608. struct urb, urb_list),
  609. -ESHUTDOWN);
  610. sl811->active_a = NULL;
  611. }
  612. #ifdef USE_B
  613. if (sl811->active_b) {
  614. sl811_write(sl811, SL811_EP_B(SL11H_HOSTCTLREG), 0);
  615. finish_request(sl811, sl811->active_b,
  616. container_of(sl811->active_b
  617. ->hep->urb_list.next,
  618. struct urb, urb_list),
  619. NULL, -ESHUTDOWN);
  620. sl811->active_b = NULL;
  621. }
  622. #endif
  623. /* port status seems weird until after reset, so
  624. * force the reset and make khubd clean up later.
  625. */
  626. if (sl811->stat_insrmv & 1)
  627. sl811->port1 |= 1 << USB_PORT_FEAT_CONNECTION;
  628. else
  629. sl811->port1 &= ~(1 << USB_PORT_FEAT_CONNECTION);
  630. sl811->port1 |= 1 << USB_PORT_FEAT_C_CONNECTION;
  631. } else if (irqstat & SL11H_INTMASK_RD) {
  632. if (sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND)) {
  633. DBG("wakeup\n");
  634. sl811->port1 |= 1 << USB_PORT_FEAT_C_SUSPEND;
  635. sl811->stat_wake++;
  636. } else
  637. irqstat &= ~SL11H_INTMASK_RD;
  638. }
  639. if (irqstat) {
  640. if (sl811->port1 & (1 << USB_PORT_FEAT_ENABLE))
  641. start_transfer(sl811);
  642. ret = IRQ_HANDLED;
  643. if (retries--)
  644. goto retry;
  645. }
  646. if (sl811->periodic_count == 0 && list_empty(&sl811->async))
  647. sofirq_off(sl811);
  648. sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
  649. spin_unlock(&sl811->lock);
  650. return ret;
  651. }
  652. /*-------------------------------------------------------------------------*/
  653. /* usb 1.1 says max 90% of a frame is available for periodic transfers.
  654. * this driver doesn't promise that much since it's got to handle an
  655. * IRQ per packet; irq handling latencies also use up that time.
  656. *
  657. * NOTE: the periodic schedule is a sparse tree, with the load for
  658. * each branch minimized. see fig 3.5 in the OHCI spec for example.
  659. */
  660. #define MAX_PERIODIC_LOAD 500 /* out of 1000 usec */
  661. static int balance(struct sl811 *sl811, u16 period, u16 load)
  662. {
  663. int i, branch = -ENOSPC;
  664. /* search for the least loaded schedule branch of that period
  665. * which has enough bandwidth left unreserved.
  666. */
  667. for (i = 0; i < period ; i++) {
  668. if (branch < 0 || sl811->load[branch] > sl811->load[i]) {
  669. int j;
  670. for (j = i; j < PERIODIC_SIZE; j += period) {
  671. if ((sl811->load[j] + load)
  672. > MAX_PERIODIC_LOAD)
  673. break;
  674. }
  675. if (j < PERIODIC_SIZE)
  676. continue;
  677. branch = i;
  678. }
  679. }
  680. return branch;
  681. }
  682. /*-------------------------------------------------------------------------*/
  683. static int sl811h_urb_enqueue(
  684. struct usb_hcd *hcd,
  685. struct urb *urb,
  686. gfp_t mem_flags
  687. ) {
  688. struct sl811 *sl811 = hcd_to_sl811(hcd);
  689. struct usb_device *udev = urb->dev;
  690. unsigned int pipe = urb->pipe;
  691. int is_out = !usb_pipein(pipe);
  692. int type = usb_pipetype(pipe);
  693. int epnum = usb_pipeendpoint(pipe);
  694. struct sl811h_ep *ep = NULL;
  695. unsigned long flags;
  696. int i;
  697. int retval;
  698. struct usb_host_endpoint *hep = urb->ep;
  699. #ifdef DISABLE_ISO
  700. if (type == PIPE_ISOCHRONOUS)
  701. return -ENOSPC;
  702. #endif
  703. /* avoid all allocations within spinlocks */
  704. if (!hep->hcpriv)
  705. ep = kzalloc(sizeof *ep, mem_flags);
  706. spin_lock_irqsave(&sl811->lock, flags);
  707. /* don't submit to a dead or disabled port */
  708. if (!(sl811->port1 & (1 << USB_PORT_FEAT_ENABLE))
  709. || !HC_IS_RUNNING(hcd->state)) {
  710. retval = -ENODEV;
  711. kfree(ep);
  712. goto fail_not_linked;
  713. }
  714. retval = usb_hcd_link_urb_to_ep(hcd, urb);
  715. if (retval) {
  716. kfree(ep);
  717. goto fail_not_linked;
  718. }
  719. if (hep->hcpriv) {
  720. kfree(ep);
  721. ep = hep->hcpriv;
  722. } else if (!ep) {
  723. retval = -ENOMEM;
  724. goto fail;
  725. } else {
  726. INIT_LIST_HEAD(&ep->schedule);
  727. ep->udev = udev;
  728. ep->epnum = epnum;
  729. ep->maxpacket = usb_maxpacket(udev, urb->pipe, is_out);
  730. ep->defctrl = SL11H_HCTLMASK_ARM | SL11H_HCTLMASK_ENABLE;
  731. usb_settoggle(udev, epnum, is_out, 0);
  732. if (type == PIPE_CONTROL)
  733. ep->nextpid = USB_PID_SETUP;
  734. else if (is_out)
  735. ep->nextpid = USB_PID_OUT;
  736. else
  737. ep->nextpid = USB_PID_IN;
  738. if (ep->maxpacket > H_MAXPACKET) {
  739. /* iso packets up to 240 bytes could work... */
  740. DBG("dev %d ep%d maxpacket %d\n",
  741. udev->devnum, epnum, ep->maxpacket);
  742. retval = -EINVAL;
  743. goto fail;
  744. }
  745. if (udev->speed == USB_SPEED_LOW) {
  746. /* send preamble for external hub? */
  747. if (!(sl811->ctrl1 & SL11H_CTL1MASK_LSPD))
  748. ep->defctrl |= SL11H_HCTLMASK_PREAMBLE;
  749. }
  750. switch (type) {
  751. case PIPE_ISOCHRONOUS:
  752. case PIPE_INTERRUPT:
  753. if (urb->interval > PERIODIC_SIZE)
  754. urb->interval = PERIODIC_SIZE;
  755. ep->period = urb->interval;
  756. ep->branch = PERIODIC_SIZE;
  757. if (type == PIPE_ISOCHRONOUS)
  758. ep->defctrl |= SL11H_HCTLMASK_ISOCH;
  759. ep->load = usb_calc_bus_time(udev->speed, !is_out,
  760. (type == PIPE_ISOCHRONOUS),
  761. usb_maxpacket(udev, pipe, is_out))
  762. / 1000;
  763. break;
  764. }
  765. ep->hep = hep;
  766. hep->hcpriv = ep;
  767. }
  768. /* maybe put endpoint into schedule */
  769. switch (type) {
  770. case PIPE_CONTROL:
  771. case PIPE_BULK:
  772. if (list_empty(&ep->schedule))
  773. list_add_tail(&ep->schedule, &sl811->async);
  774. break;
  775. case PIPE_ISOCHRONOUS:
  776. case PIPE_INTERRUPT:
  777. urb->interval = ep->period;
  778. if (ep->branch < PERIODIC_SIZE) {
  779. /* NOTE: the phase is correct here, but the value
  780. * needs offsetting by the transfer queue depth.
  781. * All current drivers ignore start_frame, so this
  782. * is unlikely to ever matter...
  783. */
  784. urb->start_frame = (sl811->frame & (PERIODIC_SIZE - 1))
  785. + ep->branch;
  786. break;
  787. }
  788. retval = balance(sl811, ep->period, ep->load);
  789. if (retval < 0)
  790. goto fail;
  791. ep->branch = retval;
  792. retval = 0;
  793. urb->start_frame = (sl811->frame & (PERIODIC_SIZE - 1))
  794. + ep->branch;
  795. /* sort each schedule branch by period (slow before fast)
  796. * to share the faster parts of the tree without needing
  797. * dummy/placeholder nodes
  798. */
  799. DBG("schedule qh%d/%p branch %d\n", ep->period, ep, ep->branch);
  800. for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
  801. struct sl811h_ep **prev = &sl811->periodic[i];
  802. struct sl811h_ep *here = *prev;
  803. while (here && ep != here) {
  804. if (ep->period > here->period)
  805. break;
  806. prev = &here->next;
  807. here = *prev;
  808. }
  809. if (ep != here) {
  810. ep->next = here;
  811. *prev = ep;
  812. }
  813. sl811->load[i] += ep->load;
  814. }
  815. sl811->periodic_count++;
  816. hcd->self.bandwidth_allocated += ep->load / ep->period;
  817. sofirq_on(sl811);
  818. }
  819. urb->hcpriv = hep;
  820. start_transfer(sl811);
  821. sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
  822. fail:
  823. if (retval)
  824. usb_hcd_unlink_urb_from_ep(hcd, urb);
  825. fail_not_linked:
  826. spin_unlock_irqrestore(&sl811->lock, flags);
  827. return retval;
  828. }
  829. static int sl811h_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  830. {
  831. struct sl811 *sl811 = hcd_to_sl811(hcd);
  832. struct usb_host_endpoint *hep;
  833. unsigned long flags;
  834. struct sl811h_ep *ep;
  835. int retval;
  836. spin_lock_irqsave(&sl811->lock, flags);
  837. retval = usb_hcd_check_unlink_urb(hcd, urb, status);
  838. if (retval)
  839. goto fail;
  840. hep = urb->hcpriv;
  841. ep = hep->hcpriv;
  842. if (ep) {
  843. /* finish right away if this urb can't be active ...
  844. * note that some drivers wrongly expect delays
  845. */
  846. if (ep->hep->urb_list.next != &urb->urb_list) {
  847. /* not front of queue? never active */
  848. /* for active transfers, we expect an IRQ */
  849. } else if (sl811->active_a == ep) {
  850. if (time_before_eq(sl811->jiffies_a, jiffies)) {
  851. /* happens a lot with lowspeed?? */
  852. DBG("giveup on DONE_A: ctrl %02x sts %02x\n",
  853. sl811_read(sl811,
  854. SL811_EP_A(SL11H_HOSTCTLREG)),
  855. sl811_read(sl811,
  856. SL811_EP_A(SL11H_PKTSTATREG)));
  857. sl811_write(sl811, SL811_EP_A(SL11H_HOSTCTLREG),
  858. 0);
  859. sl811->active_a = NULL;
  860. } else
  861. urb = NULL;
  862. #ifdef USE_B
  863. } else if (sl811->active_b == ep) {
  864. if (time_before_eq(sl811->jiffies_a, jiffies)) {
  865. /* happens a lot with lowspeed?? */
  866. DBG("giveup on DONE_B: ctrl %02x sts %02x\n",
  867. sl811_read(sl811,
  868. SL811_EP_B(SL11H_HOSTCTLREG)),
  869. sl811_read(sl811,
  870. SL811_EP_B(SL11H_PKTSTATREG)));
  871. sl811_write(sl811, SL811_EP_B(SL11H_HOSTCTLREG),
  872. 0);
  873. sl811->active_b = NULL;
  874. } else
  875. urb = NULL;
  876. #endif
  877. } else {
  878. /* front of queue for inactive endpoint */
  879. }
  880. if (urb)
  881. finish_request(sl811, ep, urb, 0);
  882. else
  883. VDBG("dequeue, urb %p active %s; wait4irq\n", urb,
  884. (sl811->active_a == ep) ? "A" : "B");
  885. } else
  886. retval = -EINVAL;
  887. fail:
  888. spin_unlock_irqrestore(&sl811->lock, flags);
  889. return retval;
  890. }
  891. static void
  892. sl811h_endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *hep)
  893. {
  894. struct sl811h_ep *ep = hep->hcpriv;
  895. if (!ep)
  896. return;
  897. /* assume we'd just wait for the irq */
  898. if (!list_empty(&hep->urb_list))
  899. msleep(3);
  900. if (!list_empty(&hep->urb_list))
  901. WARNING("ep %p not empty?\n", ep);
  902. kfree(ep);
  903. hep->hcpriv = NULL;
  904. }
  905. static int
  906. sl811h_get_frame(struct usb_hcd *hcd)
  907. {
  908. struct sl811 *sl811 = hcd_to_sl811(hcd);
  909. /* wrong except while periodic transfers are scheduled;
  910. * never matches the on-the-wire frame;
  911. * subject to overruns.
  912. */
  913. return sl811->frame;
  914. }
  915. /*-------------------------------------------------------------------------*/
  916. /* the virtual root hub timer IRQ checks for hub status */
  917. static int
  918. sl811h_hub_status_data(struct usb_hcd *hcd, char *buf)
  919. {
  920. struct sl811 *sl811 = hcd_to_sl811(hcd);
  921. #ifdef QUIRK3
  922. unsigned long flags;
  923. /* non-SMP HACK: use root hub timer as i/o watchdog
  924. * this seems essential when SOF IRQs aren't in use...
  925. */
  926. local_irq_save(flags);
  927. if (!timer_pending(&sl811->timer)) {
  928. if (sl811h_irq( /* ~0, */ hcd) != IRQ_NONE)
  929. sl811->stat_lost++;
  930. }
  931. local_irq_restore(flags);
  932. #endif
  933. if (!(sl811->port1 & (0xffff << 16)))
  934. return 0;
  935. /* tell khubd port 1 changed */
  936. *buf = (1 << 1);
  937. return 1;
  938. }
  939. static void
  940. sl811h_hub_descriptor (
  941. struct sl811 *sl811,
  942. struct usb_hub_descriptor *desc
  943. ) {
  944. u16 temp = 0;
  945. desc->bDescriptorType = 0x29;
  946. desc->bHubContrCurrent = 0;
  947. desc->bNbrPorts = 1;
  948. desc->bDescLength = 9;
  949. /* per-port power switching (gang of one!), or none */
  950. desc->bPwrOn2PwrGood = 0;
  951. if (sl811->board && sl811->board->port_power) {
  952. desc->bPwrOn2PwrGood = sl811->board->potpg;
  953. if (!desc->bPwrOn2PwrGood)
  954. desc->bPwrOn2PwrGood = 10;
  955. temp = 0x0001;
  956. } else
  957. temp = 0x0002;
  958. /* no overcurrent errors detection/handling */
  959. temp |= 0x0010;
  960. desc->wHubCharacteristics = cpu_to_le16(temp);
  961. /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */
  962. desc->bitmap[0] = 0 << 1;
  963. desc->bitmap[1] = ~0;
  964. }
  965. static void
  966. sl811h_timer(unsigned long _sl811)
  967. {
  968. struct sl811 *sl811 = (void *) _sl811;
  969. unsigned long flags;
  970. u8 irqstat;
  971. u8 signaling = sl811->ctrl1 & SL11H_CTL1MASK_FORCE;
  972. const u32 mask = (1 << USB_PORT_FEAT_CONNECTION)
  973. | (1 << USB_PORT_FEAT_ENABLE)
  974. | (1 << USB_PORT_FEAT_LOWSPEED);
  975. spin_lock_irqsave(&sl811->lock, flags);
  976. /* stop special signaling */
  977. sl811->ctrl1 &= ~SL11H_CTL1MASK_FORCE;
  978. sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
  979. udelay(3);
  980. irqstat = sl811_read(sl811, SL11H_IRQ_STATUS);
  981. switch (signaling) {
  982. case SL11H_CTL1MASK_SE0:
  983. DBG("end reset\n");
  984. sl811->port1 = (1 << USB_PORT_FEAT_C_RESET)
  985. | (1 << USB_PORT_FEAT_POWER);
  986. sl811->ctrl1 = 0;
  987. /* don't wrongly ack RD */
  988. if (irqstat & SL11H_INTMASK_INSRMV)
  989. irqstat &= ~SL11H_INTMASK_RD;
  990. break;
  991. case SL11H_CTL1MASK_K:
  992. DBG("end resume\n");
  993. sl811->port1 &= ~(1 << USB_PORT_FEAT_SUSPEND);
  994. break;
  995. default:
  996. DBG("odd timer signaling: %02x\n", signaling);
  997. break;
  998. }
  999. sl811_write(sl811, SL11H_IRQ_STATUS, irqstat);
  1000. if (irqstat & SL11H_INTMASK_RD) {
  1001. /* usbcore nukes all pending transactions on disconnect */
  1002. if (sl811->port1 & (1 << USB_PORT_FEAT_CONNECTION))
  1003. sl811->port1 |= (1 << USB_PORT_FEAT_C_CONNECTION)
  1004. | (1 << USB_PORT_FEAT_C_ENABLE);
  1005. sl811->port1 &= ~mask;
  1006. sl811->irq_enable = SL11H_INTMASK_INSRMV;
  1007. } else {
  1008. sl811->port1 |= mask;
  1009. if (irqstat & SL11H_INTMASK_DP)
  1010. sl811->port1 &= ~(1 << USB_PORT_FEAT_LOWSPEED);
  1011. sl811->irq_enable = SL11H_INTMASK_INSRMV | SL11H_INTMASK_RD;
  1012. }
  1013. if (sl811->port1 & (1 << USB_PORT_FEAT_CONNECTION)) {
  1014. u8 ctrl2 = SL811HS_CTL2_INIT;
  1015. sl811->irq_enable |= SL11H_INTMASK_DONE_A;
  1016. #ifdef USE_B
  1017. sl811->irq_enable |= SL11H_INTMASK_DONE_B;
  1018. #endif
  1019. if (sl811->port1 & (1 << USB_PORT_FEAT_LOWSPEED)) {
  1020. sl811->ctrl1 |= SL11H_CTL1MASK_LSPD;
  1021. ctrl2 |= SL811HS_CTL2MASK_DSWAP;
  1022. }
  1023. /* start SOFs flowing, kickstarting with A registers */
  1024. sl811->ctrl1 |= SL11H_CTL1MASK_SOF_ENA;
  1025. sl811_write(sl811, SL11H_SOFLOWREG, 0xe0);
  1026. sl811_write(sl811, SL811HS_CTLREG2, ctrl2);
  1027. /* autoincrementing */
  1028. sl811_write(sl811, SL811_EP_A(SL11H_BUFLNTHREG), 0);
  1029. writeb(SL_SOF, sl811->data_reg);
  1030. writeb(0, sl811->data_reg);
  1031. sl811_write(sl811, SL811_EP_A(SL11H_HOSTCTLREG),
  1032. SL11H_HCTLMASK_ARM);
  1033. /* khubd provides debounce delay */
  1034. } else {
  1035. sl811->ctrl1 = 0;
  1036. }
  1037. sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
  1038. /* reenable irqs */
  1039. sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
  1040. spin_unlock_irqrestore(&sl811->lock, flags);
  1041. }
  1042. static int
  1043. sl811h_hub_control(
  1044. struct usb_hcd *hcd,
  1045. u16 typeReq,
  1046. u16 wValue,
  1047. u16 wIndex,
  1048. char *buf,
  1049. u16 wLength
  1050. ) {
  1051. struct sl811 *sl811 = hcd_to_sl811(hcd);
  1052. int retval = 0;
  1053. unsigned long flags;
  1054. spin_lock_irqsave(&sl811->lock, flags);
  1055. switch (typeReq) {
  1056. case ClearHubFeature:
  1057. case SetHubFeature:
  1058. switch (wValue) {
  1059. case C_HUB_OVER_CURRENT:
  1060. case C_HUB_LOCAL_POWER:
  1061. break;
  1062. default:
  1063. goto error;
  1064. }
  1065. break;
  1066. case ClearPortFeature:
  1067. if (wIndex != 1 || wLength != 0)
  1068. goto error;
  1069. switch (wValue) {
  1070. case USB_PORT_FEAT_ENABLE:
  1071. sl811->port1 &= (1 << USB_PORT_FEAT_POWER);
  1072. sl811->ctrl1 = 0;
  1073. sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
  1074. sl811->irq_enable = SL11H_INTMASK_INSRMV;
  1075. sl811_write(sl811, SL11H_IRQ_ENABLE,
  1076. sl811->irq_enable);
  1077. break;
  1078. case USB_PORT_FEAT_SUSPEND:
  1079. if (!(sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND)))
  1080. break;
  1081. /* 20 msec of resume/K signaling, other irqs blocked */
  1082. DBG("start resume...\n");
  1083. sl811->irq_enable = 0;
  1084. sl811_write(sl811, SL11H_IRQ_ENABLE,
  1085. sl811->irq_enable);
  1086. sl811->ctrl1 |= SL11H_CTL1MASK_K;
  1087. sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
  1088. mod_timer(&sl811->timer, jiffies
  1089. + msecs_to_jiffies(20));
  1090. break;
  1091. case USB_PORT_FEAT_POWER:
  1092. port_power(sl811, 0);
  1093. break;
  1094. case USB_PORT_FEAT_C_ENABLE:
  1095. case USB_PORT_FEAT_C_SUSPEND:
  1096. case USB_PORT_FEAT_C_CONNECTION:
  1097. case USB_PORT_FEAT_C_OVER_CURRENT:
  1098. case USB_PORT_FEAT_C_RESET:
  1099. break;
  1100. default:
  1101. goto error;
  1102. }
  1103. sl811->port1 &= ~(1 << wValue);
  1104. break;
  1105. case GetHubDescriptor:
  1106. sl811h_hub_descriptor(sl811, (struct usb_hub_descriptor *) buf);
  1107. break;
  1108. case GetHubStatus:
  1109. *(__le32 *) buf = cpu_to_le32(0);
  1110. break;
  1111. case GetPortStatus:
  1112. if (wIndex != 1)
  1113. goto error;
  1114. *(__le32 *) buf = cpu_to_le32(sl811->port1);
  1115. #ifndef VERBOSE
  1116. if (*(u16*)(buf+2)) /* only if wPortChange is interesting */
  1117. #endif
  1118. DBG("GetPortStatus %08x\n", sl811->port1);
  1119. break;
  1120. case SetPortFeature:
  1121. if (wIndex != 1 || wLength != 0)
  1122. goto error;
  1123. switch (wValue) {
  1124. case USB_PORT_FEAT_SUSPEND:
  1125. if (sl811->port1 & (1 << USB_PORT_FEAT_RESET))
  1126. goto error;
  1127. if (!(sl811->port1 & (1 << USB_PORT_FEAT_ENABLE)))
  1128. goto error;
  1129. DBG("suspend...\n");
  1130. sl811->ctrl1 &= ~SL11H_CTL1MASK_SOF_ENA;
  1131. sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
  1132. break;
  1133. case USB_PORT_FEAT_POWER:
  1134. port_power(sl811, 1);
  1135. break;
  1136. case USB_PORT_FEAT_RESET:
  1137. if (sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND))
  1138. goto error;
  1139. if (!(sl811->port1 & (1 << USB_PORT_FEAT_POWER)))
  1140. break;
  1141. /* 50 msec of reset/SE0 signaling, irqs blocked */
  1142. sl811->irq_enable = 0;
  1143. sl811_write(sl811, SL11H_IRQ_ENABLE,
  1144. sl811->irq_enable);
  1145. sl811->ctrl1 = SL11H_CTL1MASK_SE0;
  1146. sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
  1147. sl811->port1 |= (1 << USB_PORT_FEAT_RESET);
  1148. mod_timer(&sl811->timer, jiffies
  1149. + msecs_to_jiffies(50));
  1150. break;
  1151. default:
  1152. goto error;
  1153. }
  1154. sl811->port1 |= 1 << wValue;
  1155. break;
  1156. default:
  1157. error:
  1158. /* "protocol stall" on error */
  1159. retval = -EPIPE;
  1160. }
  1161. spin_unlock_irqrestore(&sl811->lock, flags);
  1162. return retval;
  1163. }
  1164. #ifdef CONFIG_PM
  1165. static int
  1166. sl811h_bus_suspend(struct usb_hcd *hcd)
  1167. {
  1168. // SOFs off
  1169. DBG("%s\n", __func__);
  1170. return 0;
  1171. }
  1172. static int
  1173. sl811h_bus_resume(struct usb_hcd *hcd)
  1174. {
  1175. // SOFs on
  1176. DBG("%s\n", __func__);
  1177. return 0;
  1178. }
  1179. #else
  1180. #define sl811h_bus_suspend NULL
  1181. #define sl811h_bus_resume NULL
  1182. #endif
  1183. /*-------------------------------------------------------------------------*/
  1184. #ifdef STUB_DEBUG_FILE
  1185. static inline void create_debug_file(struct sl811 *sl811) { }
  1186. static inline void remove_debug_file(struct sl811 *sl811) { }
  1187. #else
  1188. #include <linux/proc_fs.h>
  1189. #include <linux/seq_file.h>
  1190. static void dump_irq(struct seq_file *s, char *label, u8 mask)
  1191. {
  1192. seq_printf(s, "%s %02x%s%s%s%s%s%s\n", label, mask,
  1193. (mask & SL11H_INTMASK_DONE_A) ? " done_a" : "",
  1194. (mask & SL11H_INTMASK_DONE_B) ? " done_b" : "",
  1195. (mask & SL11H_INTMASK_SOFINTR) ? " sof" : "",
  1196. (mask & SL11H_INTMASK_INSRMV) ? " ins/rmv" : "",
  1197. (mask & SL11H_INTMASK_RD) ? " rd" : "",
  1198. (mask & SL11H_INTMASK_DP) ? " dp" : "");
  1199. }
  1200. static int proc_sl811h_show(struct seq_file *s, void *unused)
  1201. {
  1202. struct sl811 *sl811 = s->private;
  1203. struct sl811h_ep *ep;
  1204. unsigned i;
  1205. seq_printf(s, "%s\n%s version %s\nportstatus[1] = %08x\n",
  1206. sl811_to_hcd(sl811)->product_desc,
  1207. hcd_name, DRIVER_VERSION,
  1208. sl811->port1);
  1209. seq_printf(s, "insert/remove: %ld\n", sl811->stat_insrmv);
  1210. seq_printf(s, "current session: done_a %ld done_b %ld "
  1211. "wake %ld sof %ld overrun %ld lost %ld\n\n",
  1212. sl811->stat_a, sl811->stat_b,
  1213. sl811->stat_wake, sl811->stat_sof,
  1214. sl811->stat_overrun, sl811->stat_lost);
  1215. spin_lock_irq(&sl811->lock);
  1216. if (sl811->ctrl1 & SL11H_CTL1MASK_SUSPEND)
  1217. seq_printf(s, "(suspended)\n\n");
  1218. else {
  1219. u8 t = sl811_read(sl811, SL11H_CTLREG1);
  1220. seq_printf(s, "ctrl1 %02x%s%s%s%s\n", t,
  1221. (t & SL11H_CTL1MASK_SOF_ENA) ? " sofgen" : "",
  1222. ({char *s; switch (t & SL11H_CTL1MASK_FORCE) {
  1223. case SL11H_CTL1MASK_NORMAL: s = ""; break;
  1224. case SL11H_CTL1MASK_SE0: s = " se0/reset"; break;
  1225. case SL11H_CTL1MASK_K: s = " k/resume"; break;
  1226. default: s = "j"; break;
  1227. }; s; }),
  1228. (t & SL11H_CTL1MASK_LSPD) ? " lowspeed" : "",
  1229. (t & SL11H_CTL1MASK_SUSPEND) ? " suspend" : "");
  1230. dump_irq(s, "irq_enable",
  1231. sl811_read(sl811, SL11H_IRQ_ENABLE));
  1232. dump_irq(s, "irq_status",
  1233. sl811_read(sl811, SL11H_IRQ_STATUS));
  1234. seq_printf(s, "frame clocks remaining: %d\n",
  1235. sl811_read(sl811, SL11H_SOFTMRREG) << 6);
  1236. }
  1237. seq_printf(s, "A: qh%p ctl %02x sts %02x\n", sl811->active_a,
  1238. sl811_read(sl811, SL811_EP_A(SL11H_HOSTCTLREG)),
  1239. sl811_read(sl811, SL811_EP_A(SL11H_PKTSTATREG)));
  1240. seq_printf(s, "B: qh%p ctl %02x sts %02x\n", sl811->active_b,
  1241. sl811_read(sl811, SL811_EP_B(SL11H_HOSTCTLREG)),
  1242. sl811_read(sl811, SL811_EP_B(SL11H_PKTSTATREG)));
  1243. seq_printf(s, "\n");
  1244. list_for_each_entry (ep, &sl811->async, schedule) {
  1245. struct urb *urb;
  1246. seq_printf(s, "%s%sqh%p, ep%d%s, maxpacket %d"
  1247. " nak %d err %d\n",
  1248. (ep == sl811->active_a) ? "(A) " : "",
  1249. (ep == sl811->active_b) ? "(B) " : "",
  1250. ep, ep->epnum,
  1251. ({ char *s; switch (ep->nextpid) {
  1252. case USB_PID_IN: s = "in"; break;
  1253. case USB_PID_OUT: s = "out"; break;
  1254. case USB_PID_SETUP: s = "setup"; break;
  1255. case USB_PID_ACK: s = "status"; break;
  1256. default: s = "?"; break;
  1257. }; s;}),
  1258. ep->maxpacket,
  1259. ep->nak_count, ep->error_count);
  1260. list_for_each_entry (urb, &ep->hep->urb_list, urb_list) {
  1261. seq_printf(s, " urb%p, %d/%d\n", urb,
  1262. urb->actual_length,
  1263. urb->transfer_buffer_length);
  1264. }
  1265. }
  1266. if (!list_empty(&sl811->async))
  1267. seq_printf(s, "\n");
  1268. seq_printf(s, "periodic size= %d\n", PERIODIC_SIZE);
  1269. for (i = 0; i < PERIODIC_SIZE; i++) {
  1270. ep = sl811->periodic[i];
  1271. if (!ep)
  1272. continue;
  1273. seq_printf(s, "%2d [%3d]:\n", i, sl811->load[i]);
  1274. /* DUMB: prints shared entries multiple times */
  1275. do {
  1276. seq_printf(s,
  1277. " %s%sqh%d/%p (%sdev%d ep%d%s max %d) "
  1278. "err %d\n",
  1279. (ep == sl811->active_a) ? "(A) " : "",
  1280. (ep == sl811->active_b) ? "(B) " : "",
  1281. ep->period, ep,
  1282. (ep->udev->speed == USB_SPEED_FULL)
  1283. ? "" : "ls ",
  1284. ep->udev->devnum, ep->epnum,
  1285. (ep->epnum == 0) ? ""
  1286. : ((ep->nextpid == USB_PID_IN)
  1287. ? "in"
  1288. : "out"),
  1289. ep->maxpacket, ep->error_count);
  1290. ep = ep->next;
  1291. } while (ep);
  1292. }
  1293. spin_unlock_irq(&sl811->lock);
  1294. seq_printf(s, "\n");
  1295. return 0;
  1296. }
  1297. static int proc_sl811h_open(struct inode *inode, struct file *file)
  1298. {
  1299. return single_open(file, proc_sl811h_show, PDE(inode)->data);
  1300. }
  1301. static const struct file_operations proc_ops = {
  1302. .open = proc_sl811h_open,
  1303. .read = seq_read,
  1304. .llseek = seq_lseek,
  1305. .release = single_release,
  1306. };
  1307. /* expect just one sl811 per system */
  1308. static const char proc_filename[] = "driver/sl811h";
  1309. static void create_debug_file(struct sl811 *sl811)
  1310. {
  1311. sl811->pde = proc_create_data(proc_filename, 0, NULL, &proc_ops, sl811);
  1312. }
  1313. static void remove_debug_file(struct sl811 *sl811)
  1314. {
  1315. if (sl811->pde)
  1316. remove_proc_entry(proc_filename, NULL);
  1317. }
  1318. #endif
  1319. /*-------------------------------------------------------------------------*/
  1320. static void
  1321. sl811h_stop(struct usb_hcd *hcd)
  1322. {
  1323. struct sl811 *sl811 = hcd_to_sl811(hcd);
  1324. unsigned long flags;
  1325. del_timer_sync(&hcd->rh_timer);
  1326. spin_lock_irqsave(&sl811->lock, flags);
  1327. port_power(sl811, 0);
  1328. spin_unlock_irqrestore(&sl811->lock, flags);
  1329. }
  1330. static int
  1331. sl811h_start(struct usb_hcd *hcd)
  1332. {
  1333. struct sl811 *sl811 = hcd_to_sl811(hcd);
  1334. /* chip has been reset, VBUS power is off */
  1335. hcd->state = HC_STATE_RUNNING;
  1336. if (sl811->board) {
  1337. if (!device_can_wakeup(hcd->self.controller))
  1338. device_init_wakeup(hcd->self.controller,
  1339. sl811->board->can_wakeup);
  1340. hcd->power_budget = sl811->board->power * 2;
  1341. }
  1342. /* enable power and interrupts */
  1343. port_power(sl811, 1);
  1344. return 0;
  1345. }
  1346. /*-------------------------------------------------------------------------*/
  1347. static struct hc_driver sl811h_hc_driver = {
  1348. .description = hcd_name,
  1349. .hcd_priv_size = sizeof(struct sl811),
  1350. /*
  1351. * generic hardware linkage
  1352. */
  1353. .irq = sl811h_irq,
  1354. .flags = HCD_USB11 | HCD_MEMORY,
  1355. /* Basic lifecycle operations */
  1356. .start = sl811h_start,
  1357. .stop = sl811h_stop,
  1358. /*
  1359. * managing i/o requests and associated device resources
  1360. */
  1361. .urb_enqueue = sl811h_urb_enqueue,
  1362. .urb_dequeue = sl811h_urb_dequeue,
  1363. .endpoint_disable = sl811h_endpoint_disable,
  1364. /*
  1365. * periodic schedule support
  1366. */
  1367. .get_frame_number = sl811h_get_frame,
  1368. /*
  1369. * root hub support
  1370. */
  1371. .hub_status_data = sl811h_hub_status_data,
  1372. .hub_control = sl811h_hub_control,
  1373. .bus_suspend = sl811h_bus_suspend,
  1374. .bus_resume = sl811h_bus_resume,
  1375. };
  1376. /*-------------------------------------------------------------------------*/
  1377. static int __devexit
  1378. sl811h_remove(struct platform_device *dev)
  1379. {
  1380. struct usb_hcd *hcd = platform_get_drvdata(dev);
  1381. struct sl811 *sl811 = hcd_to_sl811(hcd);
  1382. struct resource *res;
  1383. remove_debug_file(sl811);
  1384. usb_remove_hcd(hcd);
  1385. /* some platforms may use IORESOURCE_IO */
  1386. res = platform_get_resource(dev, IORESOURCE_MEM, 1);
  1387. if (res)
  1388. iounmap(sl811->data_reg);
  1389. res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  1390. if (res)
  1391. iounmap(sl811->addr_reg);
  1392. usb_put_hcd(hcd);
  1393. return 0;
  1394. }
  1395. static int __devinit
  1396. sl811h_probe(struct platform_device *dev)
  1397. {
  1398. struct usb_hcd *hcd;
  1399. struct sl811 *sl811;
  1400. struct resource *addr, *data, *ires;
  1401. int irq;
  1402. void __iomem *addr_reg;
  1403. void __iomem *data_reg;
  1404. int retval;
  1405. u8 tmp, ioaddr = 0;
  1406. unsigned long irqflags;
  1407. /* basic sanity checks first. board-specific init logic should
  1408. * have initialized these three resources and probably board
  1409. * specific platform_data. we don't probe for IRQs, and do only
  1410. * minimal sanity checking.
  1411. */
  1412. ires = platform_get_resource(dev, IORESOURCE_IRQ, 0);
  1413. if (dev->num_resources < 3 || !ires)
  1414. return -ENODEV;
  1415. irq = ires->start;
  1416. irqflags = ires->flags & IRQF_TRIGGER_MASK;
  1417. /* refuse to confuse usbcore */
  1418. if (dev->dev.dma_mask) {
  1419. DBG("no we won't dma\n");
  1420. return -EINVAL;
  1421. }
  1422. /* the chip may be wired for either kind of addressing */
  1423. addr = platform_get_resource(dev, IORESOURCE_MEM, 0);
  1424. data = platform_get_resource(dev, IORESOURCE_MEM, 1);
  1425. retval = -EBUSY;
  1426. if (!addr || !data) {
  1427. addr = platform_get_resource(dev, IORESOURCE_IO, 0);
  1428. data = platform_get_resource(dev, IORESOURCE_IO, 1);
  1429. if (!addr || !data)
  1430. return -ENODEV;
  1431. ioaddr = 1;
  1432. /*
  1433. * NOTE: 64-bit resource->start is getting truncated
  1434. * to avoid compiler warning, assuming that ->start
  1435. * is always 32-bit for this case
  1436. */
  1437. addr_reg = (void __iomem *) (unsigned long) addr->start;
  1438. data_reg = (void __iomem *) (unsigned long) data->start;
  1439. } else {
  1440. addr_reg = ioremap(addr->start, 1);
  1441. if (addr_reg == NULL) {
  1442. retval = -ENOMEM;
  1443. goto err2;
  1444. }
  1445. data_reg = ioremap(data->start, 1);
  1446. if (data_reg == NULL) {
  1447. retval = -ENOMEM;
  1448. goto err4;
  1449. }
  1450. }
  1451. /* allocate and initialize hcd */
  1452. hcd = usb_create_hcd(&sl811h_hc_driver, &dev->dev, dev_name(&dev->dev));
  1453. if (!hcd) {
  1454. retval = -ENOMEM;
  1455. goto err5;
  1456. }
  1457. hcd->rsrc_start = addr->start;
  1458. sl811 = hcd_to_sl811(hcd);
  1459. spin_lock_init(&sl811->lock);
  1460. INIT_LIST_HEAD(&sl811->async);
  1461. sl811->board = dev->dev.platform_data;
  1462. init_timer(&sl811->timer);
  1463. sl811->timer.function = sl811h_timer;
  1464. sl811->timer.data = (unsigned long) sl811;
  1465. sl811->addr_reg = addr_reg;
  1466. sl811->data_reg = data_reg;
  1467. spin_lock_irq(&sl811->lock);
  1468. port_power(sl811, 0);
  1469. spin_unlock_irq(&sl811->lock);
  1470. msleep(200);
  1471. tmp = sl811_read(sl811, SL11H_HWREVREG);
  1472. switch (tmp >> 4) {
  1473. case 1:
  1474. hcd->product_desc = "SL811HS v1.2";
  1475. break;
  1476. case 2:
  1477. hcd->product_desc = "SL811HS v1.5";
  1478. break;
  1479. default:
  1480. /* reject case 0, SL11S is less functional */
  1481. DBG("chiprev %02x\n", tmp);
  1482. retval = -ENXIO;
  1483. goto err6;
  1484. }
  1485. /* The chip's IRQ is level triggered, active high. A requirement
  1486. * for platform device setup is to cope with things like signal
  1487. * inverters (e.g. CF is active low) or working only with edge
  1488. * triggers (e.g. most ARM CPUs). Initial driver stress testing
  1489. * was on a system with single edge triggering, so most sorts of
  1490. * triggering arrangement should work.
  1491. *
  1492. * Use resource IRQ flags if set by platform device setup.
  1493. */
  1494. irqflags |= IRQF_SHARED;
  1495. retval = usb_add_hcd(hcd, irq, IRQF_DISABLED | irqflags);
  1496. if (retval != 0)
  1497. goto err6;
  1498. create_debug_file(sl811);
  1499. return retval;
  1500. err6:
  1501. usb_put_hcd(hcd);
  1502. err5:
  1503. if (!ioaddr)
  1504. iounmap(data_reg);
  1505. err4:
  1506. if (!ioaddr)
  1507. iounmap(addr_reg);
  1508. err2:
  1509. DBG("init error, %d\n", retval);
  1510. return retval;
  1511. }
  1512. #ifdef CONFIG_PM
  1513. /* for this device there's no useful distinction between the controller
  1514. * and its root hub, except that the root hub only gets direct PM calls
  1515. * when CONFIG_USB_SUSPEND is enabled.
  1516. */
  1517. static int
  1518. sl811h_suspend(struct platform_device *dev, pm_message_t state)
  1519. {
  1520. struct usb_hcd *hcd = platform_get_drvdata(dev);
  1521. struct sl811 *sl811 = hcd_to_sl811(hcd);
  1522. int retval = 0;
  1523. switch (state.event) {
  1524. case PM_EVENT_FREEZE:
  1525. retval = sl811h_bus_suspend(hcd);
  1526. break;
  1527. case PM_EVENT_SUSPEND:
  1528. case PM_EVENT_HIBERNATE:
  1529. case PM_EVENT_PRETHAW: /* explicitly discard hw state */
  1530. port_power(sl811, 0);
  1531. break;
  1532. }
  1533. return retval;
  1534. }
  1535. static int
  1536. sl811h_resume(struct platform_device *dev)
  1537. {
  1538. struct usb_hcd *hcd = platform_get_drvdata(dev);
  1539. struct sl811 *sl811 = hcd_to_sl811(hcd);
  1540. /* with no "check to see if VBUS is still powered" board hook,
  1541. * let's assume it'd only be powered to enable remote wakeup.
  1542. */
  1543. if (!sl811->port1 || !device_can_wakeup(&hcd->self.root_hub->dev)) {
  1544. sl811->port1 = 0;
  1545. port_power(sl811, 1);
  1546. usb_root_hub_lost_power(hcd->self.root_hub);
  1547. return 0;
  1548. }
  1549. return sl811h_bus_resume(hcd);
  1550. }
  1551. #else
  1552. #define sl811h_suspend NULL
  1553. #define sl811h_resume NULL
  1554. #endif
  1555. /* this driver is exported so sl811_cs can depend on it */
  1556. struct platform_driver sl811h_driver = {
  1557. .probe = sl811h_probe,
  1558. .remove = __devexit_p(sl811h_remove),
  1559. .suspend = sl811h_suspend,
  1560. .resume = sl811h_resume,
  1561. .driver = {
  1562. .name = (char *) hcd_name,
  1563. .owner = THIS_MODULE,
  1564. },
  1565. };
  1566. EXPORT_SYMBOL(sl811h_driver);
  1567. /*-------------------------------------------------------------------------*/
  1568. static int __init sl811h_init(void)
  1569. {
  1570. if (usb_disabled())
  1571. return -ENODEV;
  1572. INFO("driver %s, %s\n", hcd_name, DRIVER_VERSION);
  1573. return platform_driver_register(&sl811h_driver);
  1574. }
  1575. module_init(sl811h_init);
  1576. static void __exit sl811h_cleanup(void)
  1577. {
  1578. platform_driver_unregister(&sl811h_driver);
  1579. }
  1580. module_exit(sl811h_cleanup);