sl811-hcd.c 45 KB

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