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