sl811-hcd.c 46 KB

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