sl811-hcd.c 46 KB

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