sl811-hcd.c 46 KB

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