sl811-hcd.c 46 KB

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