sl811-hcd.c 46 KB

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