sl811-hcd.c 46 KB

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