sl811-hcd.c 46 KB

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