sl811-hcd.c 46 KB

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