sl811-hcd.c 46 KB

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