sl811-hcd.c 46 KB

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