sl811-hcd.c 46 KB

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