musb_core.c 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814
  1. /*
  2. * MUSB OTG driver core code
  3. *
  4. * Copyright 2005 Mentor Graphics Corporation
  5. * Copyright (C) 2005-2006 by Texas Instruments
  6. * Copyright (C) 2006-2007 Nokia Corporation
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  23. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  24. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  25. * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  27. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  28. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  29. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  31. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. */
  34. /*
  35. * Inventra (Multipoint) Dual-Role Controller Driver for Linux.
  36. *
  37. * This consists of a Host Controller Driver (HCD) and a peripheral
  38. * controller driver implementing the "Gadget" API; OTG support is
  39. * in the works. These are normal Linux-USB controller drivers which
  40. * use IRQs and have no dedicated thread.
  41. *
  42. * This version of the driver has only been used with products from
  43. * Texas Instruments. Those products integrate the Inventra logic
  44. * with other DMA, IRQ, and bus modules, as well as other logic that
  45. * needs to be reflected in this driver.
  46. *
  47. *
  48. * NOTE: the original Mentor code here was pretty much a collection
  49. * of mechanisms that don't seem to have been fully integrated/working
  50. * for *any* Linux kernel version. This version aims at Linux 2.6.now,
  51. * Key open issues include:
  52. *
  53. * - Lack of host-side transaction scheduling, for all transfer types.
  54. * The hardware doesn't do it; instead, software must.
  55. *
  56. * This is not an issue for OTG devices that don't support external
  57. * hubs, but for more "normal" USB hosts it's a user issue that the
  58. * "multipoint" support doesn't scale in the expected ways. That
  59. * includes DaVinci EVM in a common non-OTG mode.
  60. *
  61. * * Control and bulk use dedicated endpoints, and there's as
  62. * yet no mechanism to either (a) reclaim the hardware when
  63. * peripherals are NAKing, which gets complicated with bulk
  64. * endpoints, or (b) use more than a single bulk endpoint in
  65. * each direction.
  66. *
  67. * RESULT: one device may be perceived as blocking another one.
  68. *
  69. * * Interrupt and isochronous will dynamically allocate endpoint
  70. * hardware, but (a) there's no record keeping for bandwidth;
  71. * (b) in the common case that few endpoints are available, there
  72. * is no mechanism to reuse endpoints to talk to multiple devices.
  73. *
  74. * RESULT: At one extreme, bandwidth can be overcommitted in
  75. * some hardware configurations, no faults will be reported.
  76. * At the other extreme, the bandwidth capabilities which do
  77. * exist tend to be severely undercommitted. You can't yet hook
  78. * up both a keyboard and a mouse to an external USB hub.
  79. */
  80. /*
  81. * This gets many kinds of configuration information:
  82. * - Kconfig for everything user-configurable
  83. * - platform_device for addressing, irq, and platform_data
  84. * - platform_data is mostly for board-specific information
  85. * (plus recentrly, SOC or family details)
  86. *
  87. * Most of the conditional compilation will (someday) vanish.
  88. */
  89. #include <linux/module.h>
  90. #include <linux/kernel.h>
  91. #include <linux/sched.h>
  92. #include <linux/slab.h>
  93. #include <linux/list.h>
  94. #include <linux/kobject.h>
  95. #include <linux/prefetch.h>
  96. #include <linux/platform_device.h>
  97. #include <linux/io.h>
  98. #include <linux/dma-mapping.h>
  99. #include <linux/usb.h>
  100. #include <linux/usb/of.h>
  101. #include "musb_core.h"
  102. #include "musb_trace.h"
  103. #define TA_WAIT_BCON(m) max_t(int, (m)->a_wait_bcon, OTG_TIME_A_WAIT_BCON)
  104. #define DRIVER_AUTHOR "Mentor Graphics, Texas Instruments, Nokia"
  105. #define DRIVER_DESC "Inventra Dual-Role USB Controller Driver"
  106. #define MUSB_VERSION "6.0"
  107. #define DRIVER_INFO DRIVER_DESC ", v" MUSB_VERSION
  108. #define MUSB_DRIVER_NAME "musb-hdrc"
  109. const char musb_driver_name[] = MUSB_DRIVER_NAME;
  110. MODULE_DESCRIPTION(DRIVER_INFO);
  111. MODULE_AUTHOR(DRIVER_AUTHOR);
  112. MODULE_LICENSE("GPL");
  113. MODULE_ALIAS("platform:" MUSB_DRIVER_NAME);
  114. /*-------------------------------------------------------------------------*/
  115. static inline struct musb *dev_to_musb(struct device *dev)
  116. {
  117. return dev_get_drvdata(dev);
  118. }
  119. enum musb_mode musb_get_mode(struct device *dev)
  120. {
  121. enum usb_dr_mode mode;
  122. mode = usb_get_dr_mode(dev);
  123. switch (mode) {
  124. case USB_DR_MODE_HOST:
  125. return MUSB_HOST;
  126. case USB_DR_MODE_PERIPHERAL:
  127. return MUSB_PERIPHERAL;
  128. case USB_DR_MODE_OTG:
  129. case USB_DR_MODE_UNKNOWN:
  130. default:
  131. return MUSB_OTG;
  132. }
  133. }
  134. EXPORT_SYMBOL_GPL(musb_get_mode);
  135. /*-------------------------------------------------------------------------*/
  136. #ifndef CONFIG_BLACKFIN
  137. static int musb_ulpi_read(struct usb_phy *phy, u32 reg)
  138. {
  139. void __iomem *addr = phy->io_priv;
  140. int i = 0;
  141. u8 r;
  142. u8 power;
  143. int ret;
  144. pm_runtime_get_sync(phy->io_dev);
  145. /* Make sure the transceiver is not in low power mode */
  146. power = musb_readb(addr, MUSB_POWER);
  147. power &= ~MUSB_POWER_SUSPENDM;
  148. musb_writeb(addr, MUSB_POWER, power);
  149. /* REVISIT: musbhdrc_ulpi_an.pdf recommends setting the
  150. * ULPICarKitControlDisableUTMI after clearing POWER_SUSPENDM.
  151. */
  152. musb_writeb(addr, MUSB_ULPI_REG_ADDR, (u8)reg);
  153. musb_writeb(addr, MUSB_ULPI_REG_CONTROL,
  154. MUSB_ULPI_REG_REQ | MUSB_ULPI_RDN_WR);
  155. while (!(musb_readb(addr, MUSB_ULPI_REG_CONTROL)
  156. & MUSB_ULPI_REG_CMPLT)) {
  157. i++;
  158. if (i == 10000) {
  159. ret = -ETIMEDOUT;
  160. goto out;
  161. }
  162. }
  163. r = musb_readb(addr, MUSB_ULPI_REG_CONTROL);
  164. r &= ~MUSB_ULPI_REG_CMPLT;
  165. musb_writeb(addr, MUSB_ULPI_REG_CONTROL, r);
  166. ret = musb_readb(addr, MUSB_ULPI_REG_DATA);
  167. out:
  168. pm_runtime_put(phy->io_dev);
  169. return ret;
  170. }
  171. static int musb_ulpi_write(struct usb_phy *phy, u32 val, u32 reg)
  172. {
  173. void __iomem *addr = phy->io_priv;
  174. int i = 0;
  175. u8 r = 0;
  176. u8 power;
  177. int ret = 0;
  178. pm_runtime_get_sync(phy->io_dev);
  179. /* Make sure the transceiver is not in low power mode */
  180. power = musb_readb(addr, MUSB_POWER);
  181. power &= ~MUSB_POWER_SUSPENDM;
  182. musb_writeb(addr, MUSB_POWER, power);
  183. musb_writeb(addr, MUSB_ULPI_REG_ADDR, (u8)reg);
  184. musb_writeb(addr, MUSB_ULPI_REG_DATA, (u8)val);
  185. musb_writeb(addr, MUSB_ULPI_REG_CONTROL, MUSB_ULPI_REG_REQ);
  186. while (!(musb_readb(addr, MUSB_ULPI_REG_CONTROL)
  187. & MUSB_ULPI_REG_CMPLT)) {
  188. i++;
  189. if (i == 10000) {
  190. ret = -ETIMEDOUT;
  191. goto out;
  192. }
  193. }
  194. r = musb_readb(addr, MUSB_ULPI_REG_CONTROL);
  195. r &= ~MUSB_ULPI_REG_CMPLT;
  196. musb_writeb(addr, MUSB_ULPI_REG_CONTROL, r);
  197. out:
  198. pm_runtime_put(phy->io_dev);
  199. return ret;
  200. }
  201. #else
  202. #define musb_ulpi_read NULL
  203. #define musb_ulpi_write NULL
  204. #endif
  205. static struct usb_phy_io_ops musb_ulpi_access = {
  206. .read = musb_ulpi_read,
  207. .write = musb_ulpi_write,
  208. };
  209. /*-------------------------------------------------------------------------*/
  210. static u32 musb_default_fifo_offset(u8 epnum)
  211. {
  212. return 0x20 + (epnum * 4);
  213. }
  214. /* "flat" mapping: each endpoint has its own i/o address */
  215. static void musb_flat_ep_select(void __iomem *mbase, u8 epnum)
  216. {
  217. }
  218. static u32 musb_flat_ep_offset(u8 epnum, u16 offset)
  219. {
  220. return 0x100 + (0x10 * epnum) + offset;
  221. }
  222. /* "indexed" mapping: INDEX register controls register bank select */
  223. static void musb_indexed_ep_select(void __iomem *mbase, u8 epnum)
  224. {
  225. musb_writeb(mbase, MUSB_INDEX, epnum);
  226. }
  227. static u32 musb_indexed_ep_offset(u8 epnum, u16 offset)
  228. {
  229. return 0x10 + offset;
  230. }
  231. static u32 musb_default_busctl_offset(u8 epnum, u16 offset)
  232. {
  233. return 0x80 + (0x08 * epnum) + offset;
  234. }
  235. static u8 musb_default_readb(const void __iomem *addr, unsigned offset)
  236. {
  237. u8 data = __raw_readb(addr + offset);
  238. trace_musb_readb(__builtin_return_address(0), addr, offset, data);
  239. return data;
  240. }
  241. static void musb_default_writeb(void __iomem *addr, unsigned offset, u8 data)
  242. {
  243. trace_musb_writeb(__builtin_return_address(0), addr, offset, data);
  244. __raw_writeb(data, addr + offset);
  245. }
  246. static u16 musb_default_readw(const void __iomem *addr, unsigned offset)
  247. {
  248. u16 data = __raw_readw(addr + offset);
  249. trace_musb_readw(__builtin_return_address(0), addr, offset, data);
  250. return data;
  251. }
  252. static void musb_default_writew(void __iomem *addr, unsigned offset, u16 data)
  253. {
  254. trace_musb_writew(__builtin_return_address(0), addr, offset, data);
  255. __raw_writew(data, addr + offset);
  256. }
  257. static u32 musb_default_readl(const void __iomem *addr, unsigned offset)
  258. {
  259. u32 data = __raw_readl(addr + offset);
  260. trace_musb_readl(__builtin_return_address(0), addr, offset, data);
  261. return data;
  262. }
  263. static void musb_default_writel(void __iomem *addr, unsigned offset, u32 data)
  264. {
  265. trace_musb_writel(__builtin_return_address(0), addr, offset, data);
  266. __raw_writel(data, addr + offset);
  267. }
  268. /*
  269. * Load an endpoint's FIFO
  270. */
  271. static void musb_default_write_fifo(struct musb_hw_ep *hw_ep, u16 len,
  272. const u8 *src)
  273. {
  274. struct musb *musb = hw_ep->musb;
  275. void __iomem *fifo = hw_ep->fifo;
  276. if (unlikely(len == 0))
  277. return;
  278. prefetch((u8 *)src);
  279. dev_dbg(musb->controller, "%cX ep%d fifo %p count %d buf %p\n",
  280. 'T', hw_ep->epnum, fifo, len, src);
  281. /* we can't assume unaligned reads work */
  282. if (likely((0x01 & (unsigned long) src) == 0)) {
  283. u16 index = 0;
  284. /* best case is 32bit-aligned source address */
  285. if ((0x02 & (unsigned long) src) == 0) {
  286. if (len >= 4) {
  287. iowrite32_rep(fifo, src + index, len >> 2);
  288. index += len & ~0x03;
  289. }
  290. if (len & 0x02) {
  291. __raw_writew(*(u16 *)&src[index], fifo);
  292. index += 2;
  293. }
  294. } else {
  295. if (len >= 2) {
  296. iowrite16_rep(fifo, src + index, len >> 1);
  297. index += len & ~0x01;
  298. }
  299. }
  300. if (len & 0x01)
  301. __raw_writeb(src[index], fifo);
  302. } else {
  303. /* byte aligned */
  304. iowrite8_rep(fifo, src, len);
  305. }
  306. }
  307. /*
  308. * Unload an endpoint's FIFO
  309. */
  310. static void musb_default_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
  311. {
  312. struct musb *musb = hw_ep->musb;
  313. void __iomem *fifo = hw_ep->fifo;
  314. if (unlikely(len == 0))
  315. return;
  316. dev_dbg(musb->controller, "%cX ep%d fifo %p count %d buf %p\n",
  317. 'R', hw_ep->epnum, fifo, len, dst);
  318. /* we can't assume unaligned writes work */
  319. if (likely((0x01 & (unsigned long) dst) == 0)) {
  320. u16 index = 0;
  321. /* best case is 32bit-aligned destination address */
  322. if ((0x02 & (unsigned long) dst) == 0) {
  323. if (len >= 4) {
  324. ioread32_rep(fifo, dst, len >> 2);
  325. index = len & ~0x03;
  326. }
  327. if (len & 0x02) {
  328. *(u16 *)&dst[index] = __raw_readw(fifo);
  329. index += 2;
  330. }
  331. } else {
  332. if (len >= 2) {
  333. ioread16_rep(fifo, dst, len >> 1);
  334. index = len & ~0x01;
  335. }
  336. }
  337. if (len & 0x01)
  338. dst[index] = __raw_readb(fifo);
  339. } else {
  340. /* byte aligned */
  341. ioread8_rep(fifo, dst, len);
  342. }
  343. }
  344. /*
  345. * Old style IO functions
  346. */
  347. u8 (*musb_readb)(const void __iomem *addr, unsigned offset);
  348. EXPORT_SYMBOL_GPL(musb_readb);
  349. void (*musb_writeb)(void __iomem *addr, unsigned offset, u8 data);
  350. EXPORT_SYMBOL_GPL(musb_writeb);
  351. u16 (*musb_readw)(const void __iomem *addr, unsigned offset);
  352. EXPORT_SYMBOL_GPL(musb_readw);
  353. void (*musb_writew)(void __iomem *addr, unsigned offset, u16 data);
  354. EXPORT_SYMBOL_GPL(musb_writew);
  355. u32 (*musb_readl)(const void __iomem *addr, unsigned offset);
  356. EXPORT_SYMBOL_GPL(musb_readl);
  357. void (*musb_writel)(void __iomem *addr, unsigned offset, u32 data);
  358. EXPORT_SYMBOL_GPL(musb_writel);
  359. #ifndef CONFIG_MUSB_PIO_ONLY
  360. struct dma_controller *
  361. (*musb_dma_controller_create)(struct musb *musb, void __iomem *base);
  362. EXPORT_SYMBOL(musb_dma_controller_create);
  363. void (*musb_dma_controller_destroy)(struct dma_controller *c);
  364. EXPORT_SYMBOL(musb_dma_controller_destroy);
  365. #endif
  366. /*
  367. * New style IO functions
  368. */
  369. void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
  370. {
  371. return hw_ep->musb->io.read_fifo(hw_ep, len, dst);
  372. }
  373. void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src)
  374. {
  375. return hw_ep->musb->io.write_fifo(hw_ep, len, src);
  376. }
  377. /*-------------------------------------------------------------------------*/
  378. /* for high speed test mode; see USB 2.0 spec 7.1.20 */
  379. static const u8 musb_test_packet[53] = {
  380. /* implicit SYNC then DATA0 to start */
  381. /* JKJKJKJK x9 */
  382. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  383. /* JJKKJJKK x8 */
  384. 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
  385. /* JJJJKKKK x8 */
  386. 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee,
  387. /* JJJJJJJKKKKKKK x8 */
  388. 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  389. /* JJJJJJJK x8 */
  390. 0x7f, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd,
  391. /* JKKKKKKK x10, JK */
  392. 0xfc, 0x7e, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0x7e
  393. /* implicit CRC16 then EOP to end */
  394. };
  395. void musb_load_testpacket(struct musb *musb)
  396. {
  397. void __iomem *regs = musb->endpoints[0].regs;
  398. musb_ep_select(musb->mregs, 0);
  399. musb_write_fifo(musb->control_ep,
  400. sizeof(musb_test_packet), musb_test_packet);
  401. musb_writew(regs, MUSB_CSR0, MUSB_CSR0_TXPKTRDY);
  402. }
  403. /*-------------------------------------------------------------------------*/
  404. /*
  405. * Handles OTG hnp timeouts, such as b_ase0_brst
  406. */
  407. static void musb_otg_timer_func(unsigned long data)
  408. {
  409. struct musb *musb = (struct musb *)data;
  410. unsigned long flags;
  411. spin_lock_irqsave(&musb->lock, flags);
  412. switch (musb->xceiv->otg->state) {
  413. case OTG_STATE_B_WAIT_ACON:
  414. musb_dbg(musb,
  415. "HNP: b_wait_acon timeout; back to b_peripheral");
  416. musb_g_disconnect(musb);
  417. musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
  418. musb->is_active = 0;
  419. break;
  420. case OTG_STATE_A_SUSPEND:
  421. case OTG_STATE_A_WAIT_BCON:
  422. musb_dbg(musb, "HNP: %s timeout",
  423. usb_otg_state_string(musb->xceiv->otg->state));
  424. musb_platform_set_vbus(musb, 0);
  425. musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL;
  426. break;
  427. default:
  428. musb_dbg(musb, "HNP: Unhandled mode %s",
  429. usb_otg_state_string(musb->xceiv->otg->state));
  430. }
  431. spin_unlock_irqrestore(&musb->lock, flags);
  432. }
  433. /*
  434. * Stops the HNP transition. Caller must take care of locking.
  435. */
  436. void musb_hnp_stop(struct musb *musb)
  437. {
  438. struct usb_hcd *hcd = musb->hcd;
  439. void __iomem *mbase = musb->mregs;
  440. u8 reg;
  441. musb_dbg(musb, "HNP: stop from %s",
  442. usb_otg_state_string(musb->xceiv->otg->state));
  443. switch (musb->xceiv->otg->state) {
  444. case OTG_STATE_A_PERIPHERAL:
  445. musb_g_disconnect(musb);
  446. musb_dbg(musb, "HNP: back to %s",
  447. usb_otg_state_string(musb->xceiv->otg->state));
  448. break;
  449. case OTG_STATE_B_HOST:
  450. musb_dbg(musb, "HNP: Disabling HR");
  451. if (hcd)
  452. hcd->self.is_b_host = 0;
  453. musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
  454. MUSB_DEV_MODE(musb);
  455. reg = musb_readb(mbase, MUSB_POWER);
  456. reg |= MUSB_POWER_SUSPENDM;
  457. musb_writeb(mbase, MUSB_POWER, reg);
  458. /* REVISIT: Start SESSION_REQUEST here? */
  459. break;
  460. default:
  461. musb_dbg(musb, "HNP: Stopping in unknown state %s",
  462. usb_otg_state_string(musb->xceiv->otg->state));
  463. }
  464. /*
  465. * When returning to A state after HNP, avoid hub_port_rebounce(),
  466. * which cause occasional OPT A "Did not receive reset after connect"
  467. * errors.
  468. */
  469. musb->port1_status &= ~(USB_PORT_STAT_C_CONNECTION << 16);
  470. }
  471. static void musb_recover_from_babble(struct musb *musb);
  472. /*
  473. * Interrupt Service Routine to record USB "global" interrupts.
  474. * Since these do not happen often and signify things of
  475. * paramount importance, it seems OK to check them individually;
  476. * the order of the tests is specified in the manual
  477. *
  478. * @param musb instance pointer
  479. * @param int_usb register contents
  480. * @param devctl
  481. * @param power
  482. */
  483. static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
  484. u8 devctl)
  485. {
  486. irqreturn_t handled = IRQ_NONE;
  487. musb_dbg(musb, "<== DevCtl=%02x, int_usb=0x%x", devctl, int_usb);
  488. /* in host mode, the peripheral may issue remote wakeup.
  489. * in peripheral mode, the host may resume the link.
  490. * spurious RESUME irqs happen too, paired with SUSPEND.
  491. */
  492. if (int_usb & MUSB_INTR_RESUME) {
  493. handled = IRQ_HANDLED;
  494. musb_dbg(musb, "RESUME (%s)",
  495. usb_otg_state_string(musb->xceiv->otg->state));
  496. if (devctl & MUSB_DEVCTL_HM) {
  497. switch (musb->xceiv->otg->state) {
  498. case OTG_STATE_A_SUSPEND:
  499. /* remote wakeup? */
  500. musb->port1_status |=
  501. (USB_PORT_STAT_C_SUSPEND << 16)
  502. | MUSB_PORT_STAT_RESUME;
  503. musb->rh_timer = jiffies
  504. + msecs_to_jiffies(USB_RESUME_TIMEOUT);
  505. musb->xceiv->otg->state = OTG_STATE_A_HOST;
  506. musb->is_active = 1;
  507. musb_host_resume_root_hub(musb);
  508. schedule_delayed_work(&musb->finish_resume_work,
  509. msecs_to_jiffies(USB_RESUME_TIMEOUT));
  510. break;
  511. case OTG_STATE_B_WAIT_ACON:
  512. musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
  513. musb->is_active = 1;
  514. MUSB_DEV_MODE(musb);
  515. break;
  516. default:
  517. WARNING("bogus %s RESUME (%s)\n",
  518. "host",
  519. usb_otg_state_string(musb->xceiv->otg->state));
  520. }
  521. } else {
  522. switch (musb->xceiv->otg->state) {
  523. case OTG_STATE_A_SUSPEND:
  524. /* possibly DISCONNECT is upcoming */
  525. musb->xceiv->otg->state = OTG_STATE_A_HOST;
  526. musb_host_resume_root_hub(musb);
  527. break;
  528. case OTG_STATE_B_WAIT_ACON:
  529. case OTG_STATE_B_PERIPHERAL:
  530. /* disconnect while suspended? we may
  531. * not get a disconnect irq...
  532. */
  533. if ((devctl & MUSB_DEVCTL_VBUS)
  534. != (3 << MUSB_DEVCTL_VBUS_SHIFT)
  535. ) {
  536. musb->int_usb |= MUSB_INTR_DISCONNECT;
  537. musb->int_usb &= ~MUSB_INTR_SUSPEND;
  538. break;
  539. }
  540. musb_g_resume(musb);
  541. break;
  542. case OTG_STATE_B_IDLE:
  543. musb->int_usb &= ~MUSB_INTR_SUSPEND;
  544. break;
  545. default:
  546. WARNING("bogus %s RESUME (%s)\n",
  547. "peripheral",
  548. usb_otg_state_string(musb->xceiv->otg->state));
  549. }
  550. }
  551. }
  552. /* see manual for the order of the tests */
  553. if (int_usb & MUSB_INTR_SESSREQ) {
  554. void __iomem *mbase = musb->mregs;
  555. if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS
  556. && (devctl & MUSB_DEVCTL_BDEVICE)) {
  557. musb_dbg(musb, "SessReq while on B state");
  558. return IRQ_HANDLED;
  559. }
  560. musb_dbg(musb, "SESSION_REQUEST (%s)",
  561. usb_otg_state_string(musb->xceiv->otg->state));
  562. /* IRQ arrives from ID pin sense or (later, if VBUS power
  563. * is removed) SRP. responses are time critical:
  564. * - turn on VBUS (with silicon-specific mechanism)
  565. * - go through A_WAIT_VRISE
  566. * - ... to A_WAIT_BCON.
  567. * a_wait_vrise_tmout triggers VBUS_ERROR transitions
  568. */
  569. musb_writeb(mbase, MUSB_DEVCTL, MUSB_DEVCTL_SESSION);
  570. musb->ep0_stage = MUSB_EP0_START;
  571. musb->xceiv->otg->state = OTG_STATE_A_IDLE;
  572. MUSB_HST_MODE(musb);
  573. musb_platform_set_vbus(musb, 1);
  574. handled = IRQ_HANDLED;
  575. }
  576. if (int_usb & MUSB_INTR_VBUSERROR) {
  577. int ignore = 0;
  578. /* During connection as an A-Device, we may see a short
  579. * current spikes causing voltage drop, because of cable
  580. * and peripheral capacitance combined with vbus draw.
  581. * (So: less common with truly self-powered devices, where
  582. * vbus doesn't act like a power supply.)
  583. *
  584. * Such spikes are short; usually less than ~500 usec, max
  585. * of ~2 msec. That is, they're not sustained overcurrent
  586. * errors, though they're reported using VBUSERROR irqs.
  587. *
  588. * Workarounds: (a) hardware: use self powered devices.
  589. * (b) software: ignore non-repeated VBUS errors.
  590. *
  591. * REVISIT: do delays from lots of DEBUG_KERNEL checks
  592. * make trouble here, keeping VBUS < 4.4V ?
  593. */
  594. switch (musb->xceiv->otg->state) {
  595. case OTG_STATE_A_HOST:
  596. /* recovery is dicey once we've gotten past the
  597. * initial stages of enumeration, but if VBUS
  598. * stayed ok at the other end of the link, and
  599. * another reset is due (at least for high speed,
  600. * to redo the chirp etc), it might work OK...
  601. */
  602. case OTG_STATE_A_WAIT_BCON:
  603. case OTG_STATE_A_WAIT_VRISE:
  604. if (musb->vbuserr_retry) {
  605. void __iomem *mbase = musb->mregs;
  606. musb->vbuserr_retry--;
  607. ignore = 1;
  608. devctl |= MUSB_DEVCTL_SESSION;
  609. musb_writeb(mbase, MUSB_DEVCTL, devctl);
  610. } else {
  611. musb->port1_status |=
  612. USB_PORT_STAT_OVERCURRENT
  613. | (USB_PORT_STAT_C_OVERCURRENT << 16);
  614. }
  615. break;
  616. default:
  617. break;
  618. }
  619. dev_printk(ignore ? KERN_DEBUG : KERN_ERR, musb->controller,
  620. "VBUS_ERROR in %s (%02x, %s), retry #%d, port1 %08x\n",
  621. usb_otg_state_string(musb->xceiv->otg->state),
  622. devctl,
  623. ({ char *s;
  624. switch (devctl & MUSB_DEVCTL_VBUS) {
  625. case 0 << MUSB_DEVCTL_VBUS_SHIFT:
  626. s = "<SessEnd"; break;
  627. case 1 << MUSB_DEVCTL_VBUS_SHIFT:
  628. s = "<AValid"; break;
  629. case 2 << MUSB_DEVCTL_VBUS_SHIFT:
  630. s = "<VBusValid"; break;
  631. /* case 3 << MUSB_DEVCTL_VBUS_SHIFT: */
  632. default:
  633. s = "VALID"; break;
  634. } s; }),
  635. VBUSERR_RETRY_COUNT - musb->vbuserr_retry,
  636. musb->port1_status);
  637. /* go through A_WAIT_VFALL then start a new session */
  638. if (!ignore)
  639. musb_platform_set_vbus(musb, 0);
  640. handled = IRQ_HANDLED;
  641. }
  642. if (int_usb & MUSB_INTR_SUSPEND) {
  643. musb_dbg(musb, "SUSPEND (%s) devctl %02x",
  644. usb_otg_state_string(musb->xceiv->otg->state), devctl);
  645. handled = IRQ_HANDLED;
  646. switch (musb->xceiv->otg->state) {
  647. case OTG_STATE_A_PERIPHERAL:
  648. /* We also come here if the cable is removed, since
  649. * this silicon doesn't report ID-no-longer-grounded.
  650. *
  651. * We depend on T(a_wait_bcon) to shut us down, and
  652. * hope users don't do anything dicey during this
  653. * undesired detour through A_WAIT_BCON.
  654. */
  655. musb_hnp_stop(musb);
  656. musb_host_resume_root_hub(musb);
  657. musb_root_disconnect(musb);
  658. musb_platform_try_idle(musb, jiffies
  659. + msecs_to_jiffies(musb->a_wait_bcon
  660. ? : OTG_TIME_A_WAIT_BCON));
  661. break;
  662. case OTG_STATE_B_IDLE:
  663. if (!musb->is_active)
  664. break;
  665. case OTG_STATE_B_PERIPHERAL:
  666. musb_g_suspend(musb);
  667. musb->is_active = musb->g.b_hnp_enable;
  668. if (musb->is_active) {
  669. musb->xceiv->otg->state = OTG_STATE_B_WAIT_ACON;
  670. musb_dbg(musb, "HNP: Setting timer for b_ase0_brst");
  671. mod_timer(&musb->otg_timer, jiffies
  672. + msecs_to_jiffies(
  673. OTG_TIME_B_ASE0_BRST));
  674. }
  675. break;
  676. case OTG_STATE_A_WAIT_BCON:
  677. if (musb->a_wait_bcon != 0)
  678. musb_platform_try_idle(musb, jiffies
  679. + msecs_to_jiffies(musb->a_wait_bcon));
  680. break;
  681. case OTG_STATE_A_HOST:
  682. musb->xceiv->otg->state = OTG_STATE_A_SUSPEND;
  683. musb->is_active = musb->hcd->self.b_hnp_enable;
  684. break;
  685. case OTG_STATE_B_HOST:
  686. /* Transition to B_PERIPHERAL, see 6.8.2.6 p 44 */
  687. musb_dbg(musb, "REVISIT: SUSPEND as B_HOST");
  688. break;
  689. default:
  690. /* "should not happen" */
  691. musb->is_active = 0;
  692. break;
  693. }
  694. }
  695. if (int_usb & MUSB_INTR_CONNECT) {
  696. struct usb_hcd *hcd = musb->hcd;
  697. handled = IRQ_HANDLED;
  698. musb->is_active = 1;
  699. musb->ep0_stage = MUSB_EP0_START;
  700. musb->intrtxe = musb->epmask;
  701. musb_writew(musb->mregs, MUSB_INTRTXE, musb->intrtxe);
  702. musb->intrrxe = musb->epmask & 0xfffe;
  703. musb_writew(musb->mregs, MUSB_INTRRXE, musb->intrrxe);
  704. musb_writeb(musb->mregs, MUSB_INTRUSBE, 0xf7);
  705. musb->port1_status &= ~(USB_PORT_STAT_LOW_SPEED
  706. |USB_PORT_STAT_HIGH_SPEED
  707. |USB_PORT_STAT_ENABLE
  708. );
  709. musb->port1_status |= USB_PORT_STAT_CONNECTION
  710. |(USB_PORT_STAT_C_CONNECTION << 16);
  711. /* high vs full speed is just a guess until after reset */
  712. if (devctl & MUSB_DEVCTL_LSDEV)
  713. musb->port1_status |= USB_PORT_STAT_LOW_SPEED;
  714. /* indicate new connection to OTG machine */
  715. switch (musb->xceiv->otg->state) {
  716. case OTG_STATE_B_PERIPHERAL:
  717. if (int_usb & MUSB_INTR_SUSPEND) {
  718. musb_dbg(musb, "HNP: SUSPEND+CONNECT, now b_host");
  719. int_usb &= ~MUSB_INTR_SUSPEND;
  720. goto b_host;
  721. } else
  722. musb_dbg(musb, "CONNECT as b_peripheral???");
  723. break;
  724. case OTG_STATE_B_WAIT_ACON:
  725. musb_dbg(musb, "HNP: CONNECT, now b_host");
  726. b_host:
  727. musb->xceiv->otg->state = OTG_STATE_B_HOST;
  728. if (musb->hcd)
  729. musb->hcd->self.is_b_host = 1;
  730. del_timer(&musb->otg_timer);
  731. break;
  732. default:
  733. if ((devctl & MUSB_DEVCTL_VBUS)
  734. == (3 << MUSB_DEVCTL_VBUS_SHIFT)) {
  735. musb->xceiv->otg->state = OTG_STATE_A_HOST;
  736. if (hcd)
  737. hcd->self.is_b_host = 0;
  738. }
  739. break;
  740. }
  741. musb_host_poke_root_hub(musb);
  742. musb_dbg(musb, "CONNECT (%s) devctl %02x",
  743. usb_otg_state_string(musb->xceiv->otg->state), devctl);
  744. }
  745. if (int_usb & MUSB_INTR_DISCONNECT) {
  746. musb_dbg(musb, "DISCONNECT (%s) as %s, devctl %02x",
  747. usb_otg_state_string(musb->xceiv->otg->state),
  748. MUSB_MODE(musb), devctl);
  749. handled = IRQ_HANDLED;
  750. switch (musb->xceiv->otg->state) {
  751. case OTG_STATE_A_HOST:
  752. case OTG_STATE_A_SUSPEND:
  753. musb_host_resume_root_hub(musb);
  754. musb_root_disconnect(musb);
  755. if (musb->a_wait_bcon != 0)
  756. musb_platform_try_idle(musb, jiffies
  757. + msecs_to_jiffies(musb->a_wait_bcon));
  758. break;
  759. case OTG_STATE_B_HOST:
  760. /* REVISIT this behaves for "real disconnect"
  761. * cases; make sure the other transitions from
  762. * from B_HOST act right too. The B_HOST code
  763. * in hnp_stop() is currently not used...
  764. */
  765. musb_root_disconnect(musb);
  766. if (musb->hcd)
  767. musb->hcd->self.is_b_host = 0;
  768. musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
  769. MUSB_DEV_MODE(musb);
  770. musb_g_disconnect(musb);
  771. break;
  772. case OTG_STATE_A_PERIPHERAL:
  773. musb_hnp_stop(musb);
  774. musb_root_disconnect(musb);
  775. /* FALLTHROUGH */
  776. case OTG_STATE_B_WAIT_ACON:
  777. /* FALLTHROUGH */
  778. case OTG_STATE_B_PERIPHERAL:
  779. case OTG_STATE_B_IDLE:
  780. musb_g_disconnect(musb);
  781. break;
  782. default:
  783. WARNING("unhandled DISCONNECT transition (%s)\n",
  784. usb_otg_state_string(musb->xceiv->otg->state));
  785. break;
  786. }
  787. }
  788. /* mentor saves a bit: bus reset and babble share the same irq.
  789. * only host sees babble; only peripheral sees bus reset.
  790. */
  791. if (int_usb & MUSB_INTR_RESET) {
  792. handled = IRQ_HANDLED;
  793. if (is_host_active(musb)) {
  794. /*
  795. * When BABBLE happens what we can depends on which
  796. * platform MUSB is running, because some platforms
  797. * implemented proprietary means for 'recovering' from
  798. * Babble conditions. One such platform is AM335x. In
  799. * most cases, however, the only thing we can do is
  800. * drop the session.
  801. */
  802. dev_err(musb->controller, "Babble\n");
  803. musb_recover_from_babble(musb);
  804. } else {
  805. musb_dbg(musb, "BUS RESET as %s",
  806. usb_otg_state_string(musb->xceiv->otg->state));
  807. switch (musb->xceiv->otg->state) {
  808. case OTG_STATE_A_SUSPEND:
  809. musb_g_reset(musb);
  810. /* FALLTHROUGH */
  811. case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */
  812. /* never use invalid T(a_wait_bcon) */
  813. musb_dbg(musb, "HNP: in %s, %d msec timeout",
  814. usb_otg_state_string(musb->xceiv->otg->state),
  815. TA_WAIT_BCON(musb));
  816. mod_timer(&musb->otg_timer, jiffies
  817. + msecs_to_jiffies(TA_WAIT_BCON(musb)));
  818. break;
  819. case OTG_STATE_A_PERIPHERAL:
  820. del_timer(&musb->otg_timer);
  821. musb_g_reset(musb);
  822. break;
  823. case OTG_STATE_B_WAIT_ACON:
  824. musb_dbg(musb, "HNP: RESET (%s), to b_peripheral",
  825. usb_otg_state_string(musb->xceiv->otg->state));
  826. musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
  827. musb_g_reset(musb);
  828. break;
  829. case OTG_STATE_B_IDLE:
  830. musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
  831. /* FALLTHROUGH */
  832. case OTG_STATE_B_PERIPHERAL:
  833. musb_g_reset(musb);
  834. break;
  835. default:
  836. musb_dbg(musb, "Unhandled BUS RESET as %s",
  837. usb_otg_state_string(musb->xceiv->otg->state));
  838. }
  839. }
  840. }
  841. #if 0
  842. /* REVISIT ... this would be for multiplexing periodic endpoints, or
  843. * supporting transfer phasing to prevent exceeding ISO bandwidth
  844. * limits of a given frame or microframe.
  845. *
  846. * It's not needed for peripheral side, which dedicates endpoints;
  847. * though it _might_ use SOF irqs for other purposes.
  848. *
  849. * And it's not currently needed for host side, which also dedicates
  850. * endpoints, relies on TX/RX interval registers, and isn't claimed
  851. * to support ISO transfers yet.
  852. */
  853. if (int_usb & MUSB_INTR_SOF) {
  854. void __iomem *mbase = musb->mregs;
  855. struct musb_hw_ep *ep;
  856. u8 epnum;
  857. u16 frame;
  858. dev_dbg(musb->controller, "START_OF_FRAME\n");
  859. handled = IRQ_HANDLED;
  860. /* start any periodic Tx transfers waiting for current frame */
  861. frame = musb_readw(mbase, MUSB_FRAME);
  862. ep = musb->endpoints;
  863. for (epnum = 1; (epnum < musb->nr_endpoints)
  864. && (musb->epmask >= (1 << epnum));
  865. epnum++, ep++) {
  866. /*
  867. * FIXME handle framecounter wraps (12 bits)
  868. * eliminate duplicated StartUrb logic
  869. */
  870. if (ep->dwWaitFrame >= frame) {
  871. ep->dwWaitFrame = 0;
  872. pr_debug("SOF --> periodic TX%s on %d\n",
  873. ep->tx_channel ? " DMA" : "",
  874. epnum);
  875. if (!ep->tx_channel)
  876. musb_h_tx_start(musb, epnum);
  877. else
  878. cppi_hostdma_start(musb, epnum);
  879. }
  880. } /* end of for loop */
  881. }
  882. #endif
  883. schedule_delayed_work(&musb->irq_work, 0);
  884. return handled;
  885. }
  886. /*-------------------------------------------------------------------------*/
  887. static void musb_disable_interrupts(struct musb *musb)
  888. {
  889. void __iomem *mbase = musb->mregs;
  890. u16 temp;
  891. /* disable interrupts */
  892. musb_writeb(mbase, MUSB_INTRUSBE, 0);
  893. musb->intrtxe = 0;
  894. musb_writew(mbase, MUSB_INTRTXE, 0);
  895. musb->intrrxe = 0;
  896. musb_writew(mbase, MUSB_INTRRXE, 0);
  897. /* flush pending interrupts */
  898. temp = musb_readb(mbase, MUSB_INTRUSB);
  899. temp = musb_readw(mbase, MUSB_INTRTX);
  900. temp = musb_readw(mbase, MUSB_INTRRX);
  901. }
  902. static void musb_enable_interrupts(struct musb *musb)
  903. {
  904. void __iomem *regs = musb->mregs;
  905. /* Set INT enable registers, enable interrupts */
  906. musb->intrtxe = musb->epmask;
  907. musb_writew(regs, MUSB_INTRTXE, musb->intrtxe);
  908. musb->intrrxe = musb->epmask & 0xfffe;
  909. musb_writew(regs, MUSB_INTRRXE, musb->intrrxe);
  910. musb_writeb(regs, MUSB_INTRUSBE, 0xf7);
  911. }
  912. /*
  913. * Program the HDRC to start (enable interrupts, dma, etc.).
  914. */
  915. void musb_start(struct musb *musb)
  916. {
  917. void __iomem *regs = musb->mregs;
  918. u8 devctl = musb_readb(regs, MUSB_DEVCTL);
  919. u8 power;
  920. musb_dbg(musb, "<== devctl %02x", devctl);
  921. musb_enable_interrupts(musb);
  922. musb_writeb(regs, MUSB_TESTMODE, 0);
  923. power = MUSB_POWER_ISOUPDATE;
  924. /*
  925. * treating UNKNOWN as unspecified maximum speed, in which case
  926. * we will default to high-speed.
  927. */
  928. if (musb->config->maximum_speed == USB_SPEED_HIGH ||
  929. musb->config->maximum_speed == USB_SPEED_UNKNOWN)
  930. power |= MUSB_POWER_HSENAB;
  931. musb_writeb(regs, MUSB_POWER, power);
  932. musb->is_active = 0;
  933. devctl = musb_readb(regs, MUSB_DEVCTL);
  934. devctl &= ~MUSB_DEVCTL_SESSION;
  935. /* session started after:
  936. * (a) ID-grounded irq, host mode;
  937. * (b) vbus present/connect IRQ, peripheral mode;
  938. * (c) peripheral initiates, using SRP
  939. */
  940. if (musb->port_mode != MUSB_PORT_MODE_HOST &&
  941. musb->xceiv->otg->state != OTG_STATE_A_WAIT_BCON &&
  942. (devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) {
  943. musb->is_active = 1;
  944. } else {
  945. devctl |= MUSB_DEVCTL_SESSION;
  946. }
  947. musb_platform_enable(musb);
  948. musb_writeb(regs, MUSB_DEVCTL, devctl);
  949. }
  950. /*
  951. * Make the HDRC stop (disable interrupts, etc.);
  952. * reversible by musb_start
  953. * called on gadget driver unregister
  954. * with controller locked, irqs blocked
  955. * acts as a NOP unless some role activated the hardware
  956. */
  957. void musb_stop(struct musb *musb)
  958. {
  959. /* stop IRQs, timers, ... */
  960. musb_platform_disable(musb);
  961. musb_disable_interrupts(musb);
  962. musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
  963. /* FIXME
  964. * - mark host and/or peripheral drivers unusable/inactive
  965. * - disable DMA (and enable it in HdrcStart)
  966. * - make sure we can musb_start() after musb_stop(); with
  967. * OTG mode, gadget driver module rmmod/modprobe cycles that
  968. * - ...
  969. */
  970. musb_platform_try_idle(musb, 0);
  971. }
  972. /*-------------------------------------------------------------------------*/
  973. /*
  974. * The silicon either has hard-wired endpoint configurations, or else
  975. * "dynamic fifo" sizing. The driver has support for both, though at this
  976. * writing only the dynamic sizing is very well tested. Since we switched
  977. * away from compile-time hardware parameters, we can no longer rely on
  978. * dead code elimination to leave only the relevant one in the object file.
  979. *
  980. * We don't currently use dynamic fifo setup capability to do anything
  981. * more than selecting one of a bunch of predefined configurations.
  982. */
  983. static ushort fifo_mode;
  984. /* "modprobe ... fifo_mode=1" etc */
  985. module_param(fifo_mode, ushort, 0);
  986. MODULE_PARM_DESC(fifo_mode, "initial endpoint configuration");
  987. /*
  988. * tables defining fifo_mode values. define more if you like.
  989. * for host side, make sure both halves of ep1 are set up.
  990. */
  991. /* mode 0 - fits in 2KB */
  992. static struct musb_fifo_cfg mode_0_cfg[] = {
  993. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
  994. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
  995. { .hw_ep_num = 2, .style = FIFO_RXTX, .maxpacket = 512, },
  996. { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
  997. { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
  998. };
  999. /* mode 1 - fits in 4KB */
  1000. static struct musb_fifo_cfg mode_1_cfg[] = {
  1001. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  1002. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  1003. { .hw_ep_num = 2, .style = FIFO_RXTX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  1004. { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
  1005. { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
  1006. };
  1007. /* mode 2 - fits in 4KB */
  1008. static struct musb_fifo_cfg mode_2_cfg[] = {
  1009. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
  1010. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
  1011. { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
  1012. { .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
  1013. { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 960, },
  1014. { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 1024, },
  1015. };
  1016. /* mode 3 - fits in 4KB */
  1017. static struct musb_fifo_cfg mode_3_cfg[] = {
  1018. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  1019. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  1020. { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
  1021. { .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
  1022. { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
  1023. { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
  1024. };
  1025. /* mode 4 - fits in 16KB */
  1026. static struct musb_fifo_cfg mode_4_cfg[] = {
  1027. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
  1028. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
  1029. { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
  1030. { .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
  1031. { .hw_ep_num = 3, .style = FIFO_TX, .maxpacket = 512, },
  1032. { .hw_ep_num = 3, .style = FIFO_RX, .maxpacket = 512, },
  1033. { .hw_ep_num = 4, .style = FIFO_TX, .maxpacket = 512, },
  1034. { .hw_ep_num = 4, .style = FIFO_RX, .maxpacket = 512, },
  1035. { .hw_ep_num = 5, .style = FIFO_TX, .maxpacket = 512, },
  1036. { .hw_ep_num = 5, .style = FIFO_RX, .maxpacket = 512, },
  1037. { .hw_ep_num = 6, .style = FIFO_TX, .maxpacket = 512, },
  1038. { .hw_ep_num = 6, .style = FIFO_RX, .maxpacket = 512, },
  1039. { .hw_ep_num = 7, .style = FIFO_TX, .maxpacket = 512, },
  1040. { .hw_ep_num = 7, .style = FIFO_RX, .maxpacket = 512, },
  1041. { .hw_ep_num = 8, .style = FIFO_TX, .maxpacket = 512, },
  1042. { .hw_ep_num = 8, .style = FIFO_RX, .maxpacket = 512, },
  1043. { .hw_ep_num = 9, .style = FIFO_TX, .maxpacket = 512, },
  1044. { .hw_ep_num = 9, .style = FIFO_RX, .maxpacket = 512, },
  1045. { .hw_ep_num = 10, .style = FIFO_TX, .maxpacket = 256, },
  1046. { .hw_ep_num = 10, .style = FIFO_RX, .maxpacket = 64, },
  1047. { .hw_ep_num = 11, .style = FIFO_TX, .maxpacket = 256, },
  1048. { .hw_ep_num = 11, .style = FIFO_RX, .maxpacket = 64, },
  1049. { .hw_ep_num = 12, .style = FIFO_TX, .maxpacket = 256, },
  1050. { .hw_ep_num = 12, .style = FIFO_RX, .maxpacket = 64, },
  1051. { .hw_ep_num = 13, .style = FIFO_RXTX, .maxpacket = 4096, },
  1052. { .hw_ep_num = 14, .style = FIFO_RXTX, .maxpacket = 1024, },
  1053. { .hw_ep_num = 15, .style = FIFO_RXTX, .maxpacket = 1024, },
  1054. };
  1055. /* mode 5 - fits in 8KB */
  1056. static struct musb_fifo_cfg mode_5_cfg[] = {
  1057. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
  1058. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
  1059. { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
  1060. { .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
  1061. { .hw_ep_num = 3, .style = FIFO_TX, .maxpacket = 512, },
  1062. { .hw_ep_num = 3, .style = FIFO_RX, .maxpacket = 512, },
  1063. { .hw_ep_num = 4, .style = FIFO_TX, .maxpacket = 512, },
  1064. { .hw_ep_num = 4, .style = FIFO_RX, .maxpacket = 512, },
  1065. { .hw_ep_num = 5, .style = FIFO_TX, .maxpacket = 512, },
  1066. { .hw_ep_num = 5, .style = FIFO_RX, .maxpacket = 512, },
  1067. { .hw_ep_num = 6, .style = FIFO_TX, .maxpacket = 32, },
  1068. { .hw_ep_num = 6, .style = FIFO_RX, .maxpacket = 32, },
  1069. { .hw_ep_num = 7, .style = FIFO_TX, .maxpacket = 32, },
  1070. { .hw_ep_num = 7, .style = FIFO_RX, .maxpacket = 32, },
  1071. { .hw_ep_num = 8, .style = FIFO_TX, .maxpacket = 32, },
  1072. { .hw_ep_num = 8, .style = FIFO_RX, .maxpacket = 32, },
  1073. { .hw_ep_num = 9, .style = FIFO_TX, .maxpacket = 32, },
  1074. { .hw_ep_num = 9, .style = FIFO_RX, .maxpacket = 32, },
  1075. { .hw_ep_num = 10, .style = FIFO_TX, .maxpacket = 32, },
  1076. { .hw_ep_num = 10, .style = FIFO_RX, .maxpacket = 32, },
  1077. { .hw_ep_num = 11, .style = FIFO_TX, .maxpacket = 32, },
  1078. { .hw_ep_num = 11, .style = FIFO_RX, .maxpacket = 32, },
  1079. { .hw_ep_num = 12, .style = FIFO_TX, .maxpacket = 32, },
  1080. { .hw_ep_num = 12, .style = FIFO_RX, .maxpacket = 32, },
  1081. { .hw_ep_num = 13, .style = FIFO_RXTX, .maxpacket = 512, },
  1082. { .hw_ep_num = 14, .style = FIFO_RXTX, .maxpacket = 1024, },
  1083. { .hw_ep_num = 15, .style = FIFO_RXTX, .maxpacket = 1024, },
  1084. };
  1085. /*
  1086. * configure a fifo; for non-shared endpoints, this may be called
  1087. * once for a tx fifo and once for an rx fifo.
  1088. *
  1089. * returns negative errno or offset for next fifo.
  1090. */
  1091. static int
  1092. fifo_setup(struct musb *musb, struct musb_hw_ep *hw_ep,
  1093. const struct musb_fifo_cfg *cfg, u16 offset)
  1094. {
  1095. void __iomem *mbase = musb->mregs;
  1096. int size = 0;
  1097. u16 maxpacket = cfg->maxpacket;
  1098. u16 c_off = offset >> 3;
  1099. u8 c_size;
  1100. /* expect hw_ep has already been zero-initialized */
  1101. size = ffs(max(maxpacket, (u16) 8)) - 1;
  1102. maxpacket = 1 << size;
  1103. c_size = size - 3;
  1104. if (cfg->mode == BUF_DOUBLE) {
  1105. if ((offset + (maxpacket << 1)) >
  1106. (1 << (musb->config->ram_bits + 2)))
  1107. return -EMSGSIZE;
  1108. c_size |= MUSB_FIFOSZ_DPB;
  1109. } else {
  1110. if ((offset + maxpacket) > (1 << (musb->config->ram_bits + 2)))
  1111. return -EMSGSIZE;
  1112. }
  1113. /* configure the FIFO */
  1114. musb_writeb(mbase, MUSB_INDEX, hw_ep->epnum);
  1115. /* EP0 reserved endpoint for control, bidirectional;
  1116. * EP1 reserved for bulk, two unidirectional halves.
  1117. */
  1118. if (hw_ep->epnum == 1)
  1119. musb->bulk_ep = hw_ep;
  1120. /* REVISIT error check: be sure ep0 can both rx and tx ... */
  1121. switch (cfg->style) {
  1122. case FIFO_TX:
  1123. musb_write_txfifosz(mbase, c_size);
  1124. musb_write_txfifoadd(mbase, c_off);
  1125. hw_ep->tx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
  1126. hw_ep->max_packet_sz_tx = maxpacket;
  1127. break;
  1128. case FIFO_RX:
  1129. musb_write_rxfifosz(mbase, c_size);
  1130. musb_write_rxfifoadd(mbase, c_off);
  1131. hw_ep->rx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
  1132. hw_ep->max_packet_sz_rx = maxpacket;
  1133. break;
  1134. case FIFO_RXTX:
  1135. musb_write_txfifosz(mbase, c_size);
  1136. musb_write_txfifoadd(mbase, c_off);
  1137. hw_ep->rx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
  1138. hw_ep->max_packet_sz_rx = maxpacket;
  1139. musb_write_rxfifosz(mbase, c_size);
  1140. musb_write_rxfifoadd(mbase, c_off);
  1141. hw_ep->tx_double_buffered = hw_ep->rx_double_buffered;
  1142. hw_ep->max_packet_sz_tx = maxpacket;
  1143. hw_ep->is_shared_fifo = true;
  1144. break;
  1145. }
  1146. /* NOTE rx and tx endpoint irqs aren't managed separately,
  1147. * which happens to be ok
  1148. */
  1149. musb->epmask |= (1 << hw_ep->epnum);
  1150. return offset + (maxpacket << ((c_size & MUSB_FIFOSZ_DPB) ? 1 : 0));
  1151. }
  1152. static struct musb_fifo_cfg ep0_cfg = {
  1153. .style = FIFO_RXTX, .maxpacket = 64,
  1154. };
  1155. static int ep_config_from_table(struct musb *musb)
  1156. {
  1157. const struct musb_fifo_cfg *cfg;
  1158. unsigned i, n;
  1159. int offset;
  1160. struct musb_hw_ep *hw_ep = musb->endpoints;
  1161. if (musb->config->fifo_cfg) {
  1162. cfg = musb->config->fifo_cfg;
  1163. n = musb->config->fifo_cfg_size;
  1164. goto done;
  1165. }
  1166. switch (fifo_mode) {
  1167. default:
  1168. fifo_mode = 0;
  1169. /* FALLTHROUGH */
  1170. case 0:
  1171. cfg = mode_0_cfg;
  1172. n = ARRAY_SIZE(mode_0_cfg);
  1173. break;
  1174. case 1:
  1175. cfg = mode_1_cfg;
  1176. n = ARRAY_SIZE(mode_1_cfg);
  1177. break;
  1178. case 2:
  1179. cfg = mode_2_cfg;
  1180. n = ARRAY_SIZE(mode_2_cfg);
  1181. break;
  1182. case 3:
  1183. cfg = mode_3_cfg;
  1184. n = ARRAY_SIZE(mode_3_cfg);
  1185. break;
  1186. case 4:
  1187. cfg = mode_4_cfg;
  1188. n = ARRAY_SIZE(mode_4_cfg);
  1189. break;
  1190. case 5:
  1191. cfg = mode_5_cfg;
  1192. n = ARRAY_SIZE(mode_5_cfg);
  1193. break;
  1194. }
  1195. pr_debug("%s: setup fifo_mode %d\n", musb_driver_name, fifo_mode);
  1196. done:
  1197. offset = fifo_setup(musb, hw_ep, &ep0_cfg, 0);
  1198. /* assert(offset > 0) */
  1199. /* NOTE: for RTL versions >= 1.400 EPINFO and RAMINFO would
  1200. * be better than static musb->config->num_eps and DYN_FIFO_SIZE...
  1201. */
  1202. for (i = 0; i < n; i++) {
  1203. u8 epn = cfg->hw_ep_num;
  1204. if (epn >= musb->config->num_eps) {
  1205. pr_debug("%s: invalid ep %d\n",
  1206. musb_driver_name, epn);
  1207. return -EINVAL;
  1208. }
  1209. offset = fifo_setup(musb, hw_ep + epn, cfg++, offset);
  1210. if (offset < 0) {
  1211. pr_debug("%s: mem overrun, ep %d\n",
  1212. musb_driver_name, epn);
  1213. return offset;
  1214. }
  1215. epn++;
  1216. musb->nr_endpoints = max(epn, musb->nr_endpoints);
  1217. }
  1218. pr_debug("%s: %d/%d max ep, %d/%d memory\n",
  1219. musb_driver_name,
  1220. n + 1, musb->config->num_eps * 2 - 1,
  1221. offset, (1 << (musb->config->ram_bits + 2)));
  1222. if (!musb->bulk_ep) {
  1223. pr_debug("%s: missing bulk\n", musb_driver_name);
  1224. return -EINVAL;
  1225. }
  1226. return 0;
  1227. }
  1228. /*
  1229. * ep_config_from_hw - when MUSB_C_DYNFIFO_DEF is false
  1230. * @param musb the controller
  1231. */
  1232. static int ep_config_from_hw(struct musb *musb)
  1233. {
  1234. u8 epnum = 0;
  1235. struct musb_hw_ep *hw_ep;
  1236. void __iomem *mbase = musb->mregs;
  1237. int ret = 0;
  1238. musb_dbg(musb, "<== static silicon ep config");
  1239. /* FIXME pick up ep0 maxpacket size */
  1240. for (epnum = 1; epnum < musb->config->num_eps; epnum++) {
  1241. musb_ep_select(mbase, epnum);
  1242. hw_ep = musb->endpoints + epnum;
  1243. ret = musb_read_fifosize(musb, hw_ep, epnum);
  1244. if (ret < 0)
  1245. break;
  1246. /* FIXME set up hw_ep->{rx,tx}_double_buffered */
  1247. /* pick an RX/TX endpoint for bulk */
  1248. if (hw_ep->max_packet_sz_tx < 512
  1249. || hw_ep->max_packet_sz_rx < 512)
  1250. continue;
  1251. /* REVISIT: this algorithm is lazy, we should at least
  1252. * try to pick a double buffered endpoint.
  1253. */
  1254. if (musb->bulk_ep)
  1255. continue;
  1256. musb->bulk_ep = hw_ep;
  1257. }
  1258. if (!musb->bulk_ep) {
  1259. pr_debug("%s: missing bulk\n", musb_driver_name);
  1260. return -EINVAL;
  1261. }
  1262. return 0;
  1263. }
  1264. enum { MUSB_CONTROLLER_MHDRC, MUSB_CONTROLLER_HDRC, };
  1265. /* Initialize MUSB (M)HDRC part of the USB hardware subsystem;
  1266. * configure endpoints, or take their config from silicon
  1267. */
  1268. static int musb_core_init(u16 musb_type, struct musb *musb)
  1269. {
  1270. u8 reg;
  1271. char *type;
  1272. char aInfo[90];
  1273. void __iomem *mbase = musb->mregs;
  1274. int status = 0;
  1275. int i;
  1276. /* log core options (read using indexed model) */
  1277. reg = musb_read_configdata(mbase);
  1278. strcpy(aInfo, (reg & MUSB_CONFIGDATA_UTMIDW) ? "UTMI-16" : "UTMI-8");
  1279. if (reg & MUSB_CONFIGDATA_DYNFIFO) {
  1280. strcat(aInfo, ", dyn FIFOs");
  1281. musb->dyn_fifo = true;
  1282. }
  1283. if (reg & MUSB_CONFIGDATA_MPRXE) {
  1284. strcat(aInfo, ", bulk combine");
  1285. musb->bulk_combine = true;
  1286. }
  1287. if (reg & MUSB_CONFIGDATA_MPTXE) {
  1288. strcat(aInfo, ", bulk split");
  1289. musb->bulk_split = true;
  1290. }
  1291. if (reg & MUSB_CONFIGDATA_HBRXE) {
  1292. strcat(aInfo, ", HB-ISO Rx");
  1293. musb->hb_iso_rx = true;
  1294. }
  1295. if (reg & MUSB_CONFIGDATA_HBTXE) {
  1296. strcat(aInfo, ", HB-ISO Tx");
  1297. musb->hb_iso_tx = true;
  1298. }
  1299. if (reg & MUSB_CONFIGDATA_SOFTCONE)
  1300. strcat(aInfo, ", SoftConn");
  1301. pr_debug("%s: ConfigData=0x%02x (%s)\n", musb_driver_name, reg, aInfo);
  1302. if (MUSB_CONTROLLER_MHDRC == musb_type) {
  1303. musb->is_multipoint = 1;
  1304. type = "M";
  1305. } else {
  1306. musb->is_multipoint = 0;
  1307. type = "";
  1308. #ifndef CONFIG_USB_OTG_BLACKLIST_HUB
  1309. pr_err("%s: kernel must blacklist external hubs\n",
  1310. musb_driver_name);
  1311. #endif
  1312. }
  1313. /* log release info */
  1314. musb->hwvers = musb_read_hwvers(mbase);
  1315. pr_debug("%s: %sHDRC RTL version %d.%d%s\n",
  1316. musb_driver_name, type, MUSB_HWVERS_MAJOR(musb->hwvers),
  1317. MUSB_HWVERS_MINOR(musb->hwvers),
  1318. (musb->hwvers & MUSB_HWVERS_RC) ? "RC" : "");
  1319. /* configure ep0 */
  1320. musb_configure_ep0(musb);
  1321. /* discover endpoint configuration */
  1322. musb->nr_endpoints = 1;
  1323. musb->epmask = 1;
  1324. if (musb->dyn_fifo)
  1325. status = ep_config_from_table(musb);
  1326. else
  1327. status = ep_config_from_hw(musb);
  1328. if (status < 0)
  1329. return status;
  1330. /* finish init, and print endpoint config */
  1331. for (i = 0; i < musb->nr_endpoints; i++) {
  1332. struct musb_hw_ep *hw_ep = musb->endpoints + i;
  1333. hw_ep->fifo = musb->io.fifo_offset(i) + mbase;
  1334. #if IS_ENABLED(CONFIG_USB_MUSB_TUSB6010)
  1335. if (musb->io.quirks & MUSB_IN_TUSB) {
  1336. hw_ep->fifo_async = musb->async + 0x400 +
  1337. musb->io.fifo_offset(i);
  1338. hw_ep->fifo_sync = musb->sync + 0x400 +
  1339. musb->io.fifo_offset(i);
  1340. hw_ep->fifo_sync_va =
  1341. musb->sync_va + 0x400 + musb->io.fifo_offset(i);
  1342. if (i == 0)
  1343. hw_ep->conf = mbase - 0x400 + TUSB_EP0_CONF;
  1344. else
  1345. hw_ep->conf = mbase + 0x400 +
  1346. (((i - 1) & 0xf) << 2);
  1347. }
  1348. #endif
  1349. hw_ep->regs = musb->io.ep_offset(i, 0) + mbase;
  1350. hw_ep->rx_reinit = 1;
  1351. hw_ep->tx_reinit = 1;
  1352. if (hw_ep->max_packet_sz_tx) {
  1353. musb_dbg(musb, "%s: hw_ep %d%s, %smax %d",
  1354. musb_driver_name, i,
  1355. hw_ep->is_shared_fifo ? "shared" : "tx",
  1356. hw_ep->tx_double_buffered
  1357. ? "doublebuffer, " : "",
  1358. hw_ep->max_packet_sz_tx);
  1359. }
  1360. if (hw_ep->max_packet_sz_rx && !hw_ep->is_shared_fifo) {
  1361. musb_dbg(musb, "%s: hw_ep %d%s, %smax %d",
  1362. musb_driver_name, i,
  1363. "rx",
  1364. hw_ep->rx_double_buffered
  1365. ? "doublebuffer, " : "",
  1366. hw_ep->max_packet_sz_rx);
  1367. }
  1368. if (!(hw_ep->max_packet_sz_tx || hw_ep->max_packet_sz_rx))
  1369. musb_dbg(musb, "hw_ep %d not configured", i);
  1370. }
  1371. return 0;
  1372. }
  1373. /*-------------------------------------------------------------------------*/
  1374. /*
  1375. * handle all the irqs defined by the HDRC core. for now we expect: other
  1376. * irq sources (phy, dma, etc) will be handled first, musb->int_* values
  1377. * will be assigned, and the irq will already have been acked.
  1378. *
  1379. * called in irq context with spinlock held, irqs blocked
  1380. */
  1381. irqreturn_t musb_interrupt(struct musb *musb)
  1382. {
  1383. irqreturn_t retval = IRQ_NONE;
  1384. unsigned long status;
  1385. unsigned long epnum;
  1386. u8 devctl;
  1387. if (!musb->int_usb && !musb->int_tx && !musb->int_rx)
  1388. return IRQ_NONE;
  1389. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  1390. trace_musb_isr(musb);
  1391. /**
  1392. * According to Mentor Graphics' documentation, flowchart on page 98,
  1393. * IRQ should be handled as follows:
  1394. *
  1395. * . Resume IRQ
  1396. * . Session Request IRQ
  1397. * . VBUS Error IRQ
  1398. * . Suspend IRQ
  1399. * . Connect IRQ
  1400. * . Disconnect IRQ
  1401. * . Reset/Babble IRQ
  1402. * . SOF IRQ (we're not using this one)
  1403. * . Endpoint 0 IRQ
  1404. * . TX Endpoints
  1405. * . RX Endpoints
  1406. *
  1407. * We will be following that flowchart in order to avoid any problems
  1408. * that might arise with internal Finite State Machine.
  1409. */
  1410. if (musb->int_usb)
  1411. retval |= musb_stage0_irq(musb, musb->int_usb, devctl);
  1412. if (musb->int_tx & 1) {
  1413. if (is_host_active(musb))
  1414. retval |= musb_h_ep0_irq(musb);
  1415. else
  1416. retval |= musb_g_ep0_irq(musb);
  1417. /* we have just handled endpoint 0 IRQ, clear it */
  1418. musb->int_tx &= ~BIT(0);
  1419. }
  1420. status = musb->int_tx;
  1421. for_each_set_bit(epnum, &status, 16) {
  1422. retval = IRQ_HANDLED;
  1423. if (is_host_active(musb))
  1424. musb_host_tx(musb, epnum);
  1425. else
  1426. musb_g_tx(musb, epnum);
  1427. }
  1428. status = musb->int_rx;
  1429. for_each_set_bit(epnum, &status, 16) {
  1430. retval = IRQ_HANDLED;
  1431. if (is_host_active(musb))
  1432. musb_host_rx(musb, epnum);
  1433. else
  1434. musb_g_rx(musb, epnum);
  1435. }
  1436. return retval;
  1437. }
  1438. EXPORT_SYMBOL_GPL(musb_interrupt);
  1439. #ifndef CONFIG_MUSB_PIO_ONLY
  1440. static bool use_dma = 1;
  1441. /* "modprobe ... use_dma=0" etc */
  1442. module_param(use_dma, bool, 0644);
  1443. MODULE_PARM_DESC(use_dma, "enable/disable use of DMA");
  1444. void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit)
  1445. {
  1446. /* called with controller lock already held */
  1447. if (!epnum) {
  1448. if (!is_cppi_enabled(musb)) {
  1449. /* endpoint 0 */
  1450. if (is_host_active(musb))
  1451. musb_h_ep0_irq(musb);
  1452. else
  1453. musb_g_ep0_irq(musb);
  1454. }
  1455. } else {
  1456. /* endpoints 1..15 */
  1457. if (transmit) {
  1458. if (is_host_active(musb))
  1459. musb_host_tx(musb, epnum);
  1460. else
  1461. musb_g_tx(musb, epnum);
  1462. } else {
  1463. /* receive */
  1464. if (is_host_active(musb))
  1465. musb_host_rx(musb, epnum);
  1466. else
  1467. musb_g_rx(musb, epnum);
  1468. }
  1469. }
  1470. }
  1471. EXPORT_SYMBOL_GPL(musb_dma_completion);
  1472. #else
  1473. #define use_dma 0
  1474. #endif
  1475. static int (*musb_phy_callback)(enum musb_vbus_id_status status);
  1476. /*
  1477. * musb_mailbox - optional phy notifier function
  1478. * @status phy state change
  1479. *
  1480. * Optionally gets called from the USB PHY. Note that the USB PHY must be
  1481. * disabled at the point the phy_callback is registered or unregistered.
  1482. */
  1483. int musb_mailbox(enum musb_vbus_id_status status)
  1484. {
  1485. if (musb_phy_callback)
  1486. return musb_phy_callback(status);
  1487. return -ENODEV;
  1488. };
  1489. EXPORT_SYMBOL_GPL(musb_mailbox);
  1490. /*-------------------------------------------------------------------------*/
  1491. static ssize_t
  1492. musb_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
  1493. {
  1494. struct musb *musb = dev_to_musb(dev);
  1495. unsigned long flags;
  1496. int ret = -EINVAL;
  1497. spin_lock_irqsave(&musb->lock, flags);
  1498. ret = sprintf(buf, "%s\n", usb_otg_state_string(musb->xceiv->otg->state));
  1499. spin_unlock_irqrestore(&musb->lock, flags);
  1500. return ret;
  1501. }
  1502. static ssize_t
  1503. musb_mode_store(struct device *dev, struct device_attribute *attr,
  1504. const char *buf, size_t n)
  1505. {
  1506. struct musb *musb = dev_to_musb(dev);
  1507. unsigned long flags;
  1508. int status;
  1509. spin_lock_irqsave(&musb->lock, flags);
  1510. if (sysfs_streq(buf, "host"))
  1511. status = musb_platform_set_mode(musb, MUSB_HOST);
  1512. else if (sysfs_streq(buf, "peripheral"))
  1513. status = musb_platform_set_mode(musb, MUSB_PERIPHERAL);
  1514. else if (sysfs_streq(buf, "otg"))
  1515. status = musb_platform_set_mode(musb, MUSB_OTG);
  1516. else
  1517. status = -EINVAL;
  1518. spin_unlock_irqrestore(&musb->lock, flags);
  1519. return (status == 0) ? n : status;
  1520. }
  1521. static DEVICE_ATTR(mode, 0644, musb_mode_show, musb_mode_store);
  1522. static ssize_t
  1523. musb_vbus_store(struct device *dev, struct device_attribute *attr,
  1524. const char *buf, size_t n)
  1525. {
  1526. struct musb *musb = dev_to_musb(dev);
  1527. unsigned long flags;
  1528. unsigned long val;
  1529. if (sscanf(buf, "%lu", &val) < 1) {
  1530. dev_err(dev, "Invalid VBUS timeout ms value\n");
  1531. return -EINVAL;
  1532. }
  1533. spin_lock_irqsave(&musb->lock, flags);
  1534. /* force T(a_wait_bcon) to be zero/unlimited *OR* valid */
  1535. musb->a_wait_bcon = val ? max_t(int, val, OTG_TIME_A_WAIT_BCON) : 0 ;
  1536. if (musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON)
  1537. musb->is_active = 0;
  1538. musb_platform_try_idle(musb, jiffies + msecs_to_jiffies(val));
  1539. spin_unlock_irqrestore(&musb->lock, flags);
  1540. return n;
  1541. }
  1542. static ssize_t
  1543. musb_vbus_show(struct device *dev, struct device_attribute *attr, char *buf)
  1544. {
  1545. struct musb *musb = dev_to_musb(dev);
  1546. unsigned long flags;
  1547. unsigned long val;
  1548. int vbus;
  1549. u8 devctl;
  1550. spin_lock_irqsave(&musb->lock, flags);
  1551. val = musb->a_wait_bcon;
  1552. vbus = musb_platform_get_vbus_status(musb);
  1553. if (vbus < 0) {
  1554. /* Use default MUSB method by means of DEVCTL register */
  1555. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  1556. if ((devctl & MUSB_DEVCTL_VBUS)
  1557. == (3 << MUSB_DEVCTL_VBUS_SHIFT))
  1558. vbus = 1;
  1559. else
  1560. vbus = 0;
  1561. }
  1562. spin_unlock_irqrestore(&musb->lock, flags);
  1563. return sprintf(buf, "Vbus %s, timeout %lu msec\n",
  1564. vbus ? "on" : "off", val);
  1565. }
  1566. static DEVICE_ATTR(vbus, 0644, musb_vbus_show, musb_vbus_store);
  1567. /* Gadget drivers can't know that a host is connected so they might want
  1568. * to start SRP, but users can. This allows userspace to trigger SRP.
  1569. */
  1570. static ssize_t
  1571. musb_srp_store(struct device *dev, struct device_attribute *attr,
  1572. const char *buf, size_t n)
  1573. {
  1574. struct musb *musb = dev_to_musb(dev);
  1575. unsigned short srp;
  1576. if (sscanf(buf, "%hu", &srp) != 1
  1577. || (srp != 1)) {
  1578. dev_err(dev, "SRP: Value must be 1\n");
  1579. return -EINVAL;
  1580. }
  1581. if (srp == 1)
  1582. musb_g_wakeup(musb);
  1583. return n;
  1584. }
  1585. static DEVICE_ATTR(srp, 0644, NULL, musb_srp_store);
  1586. static struct attribute *musb_attributes[] = {
  1587. &dev_attr_mode.attr,
  1588. &dev_attr_vbus.attr,
  1589. &dev_attr_srp.attr,
  1590. NULL
  1591. };
  1592. static const struct attribute_group musb_attr_group = {
  1593. .attrs = musb_attributes,
  1594. };
  1595. #define MUSB_QUIRK_B_INVALID_VBUS_91 (MUSB_DEVCTL_BDEVICE | \
  1596. (2 << MUSB_DEVCTL_VBUS_SHIFT) | \
  1597. MUSB_DEVCTL_SESSION)
  1598. #define MUSB_QUIRK_A_DISCONNECT_19 ((3 << MUSB_DEVCTL_VBUS_SHIFT) | \
  1599. MUSB_DEVCTL_SESSION)
  1600. /*
  1601. * Check the musb devctl session bit to determine if we want to
  1602. * allow PM runtime for the device. In general, we want to keep things
  1603. * active when the session bit is set except after host disconnect.
  1604. *
  1605. * Only called from musb_irq_work. If this ever needs to get called
  1606. * elsewhere, proper locking must be implemented for musb->session.
  1607. */
  1608. static void musb_pm_runtime_check_session(struct musb *musb)
  1609. {
  1610. u8 devctl, s;
  1611. int error;
  1612. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  1613. /* Handle session status quirks first */
  1614. s = MUSB_DEVCTL_FSDEV | MUSB_DEVCTL_LSDEV |
  1615. MUSB_DEVCTL_HR;
  1616. switch (devctl & ~s) {
  1617. case MUSB_QUIRK_B_INVALID_VBUS_91:
  1618. if (musb->quirk_retries && !musb->flush_irq_work) {
  1619. musb_dbg(musb,
  1620. "Poll devctl on invalid vbus, assume no session");
  1621. schedule_delayed_work(&musb->irq_work,
  1622. msecs_to_jiffies(1000));
  1623. musb->quirk_retries--;
  1624. return;
  1625. }
  1626. /* fall through */
  1627. case MUSB_QUIRK_A_DISCONNECT_19:
  1628. if (musb->quirk_retries && !musb->flush_irq_work) {
  1629. musb_dbg(musb,
  1630. "Poll devctl on possible host mode disconnect");
  1631. schedule_delayed_work(&musb->irq_work,
  1632. msecs_to_jiffies(1000));
  1633. musb->quirk_retries--;
  1634. return;
  1635. }
  1636. if (!musb->session)
  1637. break;
  1638. musb_dbg(musb, "Allow PM on possible host mode disconnect");
  1639. pm_runtime_mark_last_busy(musb->controller);
  1640. pm_runtime_put_autosuspend(musb->controller);
  1641. musb->session = false;
  1642. return;
  1643. default:
  1644. break;
  1645. }
  1646. /* No need to do anything if session has not changed */
  1647. s = devctl & MUSB_DEVCTL_SESSION;
  1648. if (s == musb->session)
  1649. return;
  1650. /* Block PM or allow PM? */
  1651. if (s) {
  1652. musb_dbg(musb, "Block PM on active session: %02x", devctl);
  1653. error = pm_runtime_get_sync(musb->controller);
  1654. if (error < 0)
  1655. dev_err(musb->controller, "Could not enable: %i\n",
  1656. error);
  1657. musb->quirk_retries = 3;
  1658. } else {
  1659. musb_dbg(musb, "Allow PM with no session: %02x", devctl);
  1660. pm_runtime_mark_last_busy(musb->controller);
  1661. pm_runtime_put_autosuspend(musb->controller);
  1662. }
  1663. musb->session = s;
  1664. }
  1665. /* Only used to provide driver mode change events */
  1666. static void musb_irq_work(struct work_struct *data)
  1667. {
  1668. struct musb *musb = container_of(data, struct musb, irq_work.work);
  1669. int error;
  1670. error = pm_runtime_get_sync(musb->controller);
  1671. if (error < 0) {
  1672. dev_err(musb->controller, "Could not enable: %i\n", error);
  1673. return;
  1674. }
  1675. musb_pm_runtime_check_session(musb);
  1676. if (musb->xceiv->otg->state != musb->xceiv_old_state) {
  1677. musb->xceiv_old_state = musb->xceiv->otg->state;
  1678. sysfs_notify(&musb->controller->kobj, NULL, "mode");
  1679. }
  1680. pm_runtime_mark_last_busy(musb->controller);
  1681. pm_runtime_put_autosuspend(musb->controller);
  1682. }
  1683. static void musb_recover_from_babble(struct musb *musb)
  1684. {
  1685. int ret;
  1686. u8 devctl;
  1687. musb_disable_interrupts(musb);
  1688. /*
  1689. * wait at least 320 cycles of 60MHz clock. That's 5.3us, we will give
  1690. * it some slack and wait for 10us.
  1691. */
  1692. udelay(10);
  1693. ret = musb_platform_recover(musb);
  1694. if (ret) {
  1695. musb_enable_interrupts(musb);
  1696. return;
  1697. }
  1698. /* drop session bit */
  1699. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  1700. devctl &= ~MUSB_DEVCTL_SESSION;
  1701. musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
  1702. /* tell usbcore about it */
  1703. musb_root_disconnect(musb);
  1704. /*
  1705. * When a babble condition occurs, the musb controller
  1706. * removes the session bit and the endpoint config is lost.
  1707. */
  1708. if (musb->dyn_fifo)
  1709. ret = ep_config_from_table(musb);
  1710. else
  1711. ret = ep_config_from_hw(musb);
  1712. /* restart session */
  1713. if (ret == 0)
  1714. musb_start(musb);
  1715. }
  1716. /* --------------------------------------------------------------------------
  1717. * Init support
  1718. */
  1719. static struct musb *allocate_instance(struct device *dev,
  1720. const struct musb_hdrc_config *config, void __iomem *mbase)
  1721. {
  1722. struct musb *musb;
  1723. struct musb_hw_ep *ep;
  1724. int epnum;
  1725. int ret;
  1726. musb = devm_kzalloc(dev, sizeof(*musb), GFP_KERNEL);
  1727. if (!musb)
  1728. return NULL;
  1729. INIT_LIST_HEAD(&musb->control);
  1730. INIT_LIST_HEAD(&musb->in_bulk);
  1731. INIT_LIST_HEAD(&musb->out_bulk);
  1732. INIT_LIST_HEAD(&musb->pending_list);
  1733. musb->vbuserr_retry = VBUSERR_RETRY_COUNT;
  1734. musb->a_wait_bcon = OTG_TIME_A_WAIT_BCON;
  1735. musb->mregs = mbase;
  1736. musb->ctrl_base = mbase;
  1737. musb->nIrq = -ENODEV;
  1738. musb->config = config;
  1739. BUG_ON(musb->config->num_eps > MUSB_C_NUM_EPS);
  1740. for (epnum = 0, ep = musb->endpoints;
  1741. epnum < musb->config->num_eps;
  1742. epnum++, ep++) {
  1743. ep->musb = musb;
  1744. ep->epnum = epnum;
  1745. }
  1746. musb->controller = dev;
  1747. ret = musb_host_alloc(musb);
  1748. if (ret < 0)
  1749. goto err_free;
  1750. dev_set_drvdata(dev, musb);
  1751. return musb;
  1752. err_free:
  1753. return NULL;
  1754. }
  1755. static void musb_free(struct musb *musb)
  1756. {
  1757. /* this has multiple entry modes. it handles fault cleanup after
  1758. * probe(), where things may be partially set up, as well as rmmod
  1759. * cleanup after everything's been de-activated.
  1760. */
  1761. #ifdef CONFIG_SYSFS
  1762. sysfs_remove_group(&musb->controller->kobj, &musb_attr_group);
  1763. #endif
  1764. if (musb->nIrq >= 0) {
  1765. if (musb->irq_wake)
  1766. disable_irq_wake(musb->nIrq);
  1767. free_irq(musb->nIrq, musb);
  1768. }
  1769. musb_host_free(musb);
  1770. }
  1771. struct musb_pending_work {
  1772. int (*callback)(struct musb *musb, void *data);
  1773. void *data;
  1774. struct list_head node;
  1775. };
  1776. #ifdef CONFIG_PM
  1777. /*
  1778. * Called from musb_runtime_resume(), musb_resume(), and
  1779. * musb_queue_resume_work(). Callers must take musb->lock.
  1780. */
  1781. static int musb_run_resume_work(struct musb *musb)
  1782. {
  1783. struct musb_pending_work *w, *_w;
  1784. unsigned long flags;
  1785. int error = 0;
  1786. spin_lock_irqsave(&musb->list_lock, flags);
  1787. list_for_each_entry_safe(w, _w, &musb->pending_list, node) {
  1788. if (w->callback) {
  1789. error = w->callback(musb, w->data);
  1790. if (error < 0) {
  1791. dev_err(musb->controller,
  1792. "resume callback %p failed: %i\n",
  1793. w->callback, error);
  1794. }
  1795. }
  1796. list_del(&w->node);
  1797. devm_kfree(musb->controller, w);
  1798. }
  1799. spin_unlock_irqrestore(&musb->list_lock, flags);
  1800. return error;
  1801. }
  1802. #endif
  1803. /*
  1804. * Called to run work if device is active or else queue the work to happen
  1805. * on resume. Caller must take musb->lock and must hold an RPM reference.
  1806. *
  1807. * Note that we cowardly refuse queuing work after musb PM runtime
  1808. * resume is done calling musb_run_resume_work() and return -EINPROGRESS
  1809. * instead.
  1810. */
  1811. int musb_queue_resume_work(struct musb *musb,
  1812. int (*callback)(struct musb *musb, void *data),
  1813. void *data)
  1814. {
  1815. struct musb_pending_work *w;
  1816. unsigned long flags;
  1817. int error;
  1818. if (WARN_ON(!callback))
  1819. return -EINVAL;
  1820. if (pm_runtime_active(musb->controller))
  1821. return callback(musb, data);
  1822. w = devm_kzalloc(musb->controller, sizeof(*w), GFP_ATOMIC);
  1823. if (!w)
  1824. return -ENOMEM;
  1825. w->callback = callback;
  1826. w->data = data;
  1827. spin_lock_irqsave(&musb->list_lock, flags);
  1828. if (musb->is_runtime_suspended) {
  1829. list_add_tail(&w->node, &musb->pending_list);
  1830. error = 0;
  1831. } else {
  1832. dev_err(musb->controller, "could not add resume work %p\n",
  1833. callback);
  1834. devm_kfree(musb->controller, w);
  1835. error = -EINPROGRESS;
  1836. }
  1837. spin_unlock_irqrestore(&musb->list_lock, flags);
  1838. return error;
  1839. }
  1840. EXPORT_SYMBOL_GPL(musb_queue_resume_work);
  1841. static void musb_deassert_reset(struct work_struct *work)
  1842. {
  1843. struct musb *musb;
  1844. unsigned long flags;
  1845. musb = container_of(work, struct musb, deassert_reset_work.work);
  1846. spin_lock_irqsave(&musb->lock, flags);
  1847. if (musb->port1_status & USB_PORT_STAT_RESET)
  1848. musb_port_reset(musb, false);
  1849. spin_unlock_irqrestore(&musb->lock, flags);
  1850. }
  1851. /*
  1852. * Perform generic per-controller initialization.
  1853. *
  1854. * @dev: the controller (already clocked, etc)
  1855. * @nIrq: IRQ number
  1856. * @ctrl: virtual address of controller registers,
  1857. * not yet corrected for platform-specific offsets
  1858. */
  1859. static int
  1860. musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
  1861. {
  1862. int status;
  1863. struct musb *musb;
  1864. struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
  1865. /* The driver might handle more features than the board; OK.
  1866. * Fail when the board needs a feature that's not enabled.
  1867. */
  1868. if (!plat) {
  1869. dev_err(dev, "no platform_data?\n");
  1870. status = -ENODEV;
  1871. goto fail0;
  1872. }
  1873. /* allocate */
  1874. musb = allocate_instance(dev, plat->config, ctrl);
  1875. if (!musb) {
  1876. status = -ENOMEM;
  1877. goto fail0;
  1878. }
  1879. spin_lock_init(&musb->lock);
  1880. spin_lock_init(&musb->list_lock);
  1881. musb->board_set_power = plat->set_power;
  1882. musb->min_power = plat->min_power;
  1883. musb->ops = plat->platform_ops;
  1884. musb->port_mode = plat->mode;
  1885. /*
  1886. * Initialize the default IO functions. At least omap2430 needs
  1887. * these early. We initialize the platform specific IO functions
  1888. * later on.
  1889. */
  1890. musb_readb = musb_default_readb;
  1891. musb_writeb = musb_default_writeb;
  1892. musb_readw = musb_default_readw;
  1893. musb_writew = musb_default_writew;
  1894. musb_readl = musb_default_readl;
  1895. musb_writel = musb_default_writel;
  1896. /* The musb_platform_init() call:
  1897. * - adjusts musb->mregs
  1898. * - sets the musb->isr
  1899. * - may initialize an integrated transceiver
  1900. * - initializes musb->xceiv, usually by otg_get_phy()
  1901. * - stops powering VBUS
  1902. *
  1903. * There are various transceiver configurations. Blackfin,
  1904. * DaVinci, TUSB60x0, and others integrate them. OMAP3 uses
  1905. * external/discrete ones in various flavors (twl4030 family,
  1906. * isp1504, non-OTG, etc) mostly hooking up through ULPI.
  1907. */
  1908. status = musb_platform_init(musb);
  1909. if (status < 0)
  1910. goto fail1;
  1911. if (!musb->isr) {
  1912. status = -ENODEV;
  1913. goto fail2;
  1914. }
  1915. if (musb->ops->quirks)
  1916. musb->io.quirks = musb->ops->quirks;
  1917. /* Most devices use indexed offset or flat offset */
  1918. if (musb->io.quirks & MUSB_INDEXED_EP) {
  1919. musb->io.ep_offset = musb_indexed_ep_offset;
  1920. musb->io.ep_select = musb_indexed_ep_select;
  1921. } else {
  1922. musb->io.ep_offset = musb_flat_ep_offset;
  1923. musb->io.ep_select = musb_flat_ep_select;
  1924. }
  1925. if (musb->io.quirks & MUSB_G_NO_SKB_RESERVE)
  1926. musb->g.quirk_avoids_skb_reserve = 1;
  1927. /* At least tusb6010 has its own offsets */
  1928. if (musb->ops->ep_offset)
  1929. musb->io.ep_offset = musb->ops->ep_offset;
  1930. if (musb->ops->ep_select)
  1931. musb->io.ep_select = musb->ops->ep_select;
  1932. if (musb->ops->fifo_mode)
  1933. fifo_mode = musb->ops->fifo_mode;
  1934. else
  1935. fifo_mode = 4;
  1936. if (musb->ops->fifo_offset)
  1937. musb->io.fifo_offset = musb->ops->fifo_offset;
  1938. else
  1939. musb->io.fifo_offset = musb_default_fifo_offset;
  1940. if (musb->ops->busctl_offset)
  1941. musb->io.busctl_offset = musb->ops->busctl_offset;
  1942. else
  1943. musb->io.busctl_offset = musb_default_busctl_offset;
  1944. if (musb->ops->readb)
  1945. musb_readb = musb->ops->readb;
  1946. if (musb->ops->writeb)
  1947. musb_writeb = musb->ops->writeb;
  1948. if (musb->ops->readw)
  1949. musb_readw = musb->ops->readw;
  1950. if (musb->ops->writew)
  1951. musb_writew = musb->ops->writew;
  1952. if (musb->ops->readl)
  1953. musb_readl = musb->ops->readl;
  1954. if (musb->ops->writel)
  1955. musb_writel = musb->ops->writel;
  1956. #ifndef CONFIG_MUSB_PIO_ONLY
  1957. if (!musb->ops->dma_init || !musb->ops->dma_exit) {
  1958. dev_err(dev, "DMA controller not set\n");
  1959. status = -ENODEV;
  1960. goto fail2;
  1961. }
  1962. musb_dma_controller_create = musb->ops->dma_init;
  1963. musb_dma_controller_destroy = musb->ops->dma_exit;
  1964. #endif
  1965. if (musb->ops->read_fifo)
  1966. musb->io.read_fifo = musb->ops->read_fifo;
  1967. else
  1968. musb->io.read_fifo = musb_default_read_fifo;
  1969. if (musb->ops->write_fifo)
  1970. musb->io.write_fifo = musb->ops->write_fifo;
  1971. else
  1972. musb->io.write_fifo = musb_default_write_fifo;
  1973. if (!musb->xceiv->io_ops) {
  1974. musb->xceiv->io_dev = musb->controller;
  1975. musb->xceiv->io_priv = musb->mregs;
  1976. musb->xceiv->io_ops = &musb_ulpi_access;
  1977. }
  1978. if (musb->ops->phy_callback)
  1979. musb_phy_callback = musb->ops->phy_callback;
  1980. /*
  1981. * We need musb_read/write functions initialized for PM.
  1982. * Note that at least 2430 glue needs autosuspend delay
  1983. * somewhere above 300 ms for the hardware to idle properly
  1984. * after disconnecting the cable in host mode. Let's use
  1985. * 500 ms for some margin.
  1986. */
  1987. pm_runtime_use_autosuspend(musb->controller);
  1988. pm_runtime_set_autosuspend_delay(musb->controller, 500);
  1989. pm_runtime_enable(musb->controller);
  1990. pm_runtime_get_sync(musb->controller);
  1991. status = usb_phy_init(musb->xceiv);
  1992. if (status < 0)
  1993. goto err_usb_phy_init;
  1994. if (use_dma && dev->dma_mask) {
  1995. musb->dma_controller =
  1996. musb_dma_controller_create(musb, musb->mregs);
  1997. if (IS_ERR(musb->dma_controller)) {
  1998. status = PTR_ERR(musb->dma_controller);
  1999. goto fail2_5;
  2000. }
  2001. }
  2002. /* be sure interrupts are disabled before connecting ISR */
  2003. musb_platform_disable(musb);
  2004. musb_disable_interrupts(musb);
  2005. musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
  2006. /* Init IRQ workqueue before request_irq */
  2007. INIT_DELAYED_WORK(&musb->irq_work, musb_irq_work);
  2008. INIT_DELAYED_WORK(&musb->deassert_reset_work, musb_deassert_reset);
  2009. INIT_DELAYED_WORK(&musb->finish_resume_work, musb_host_finish_resume);
  2010. /* setup musb parts of the core (especially endpoints) */
  2011. status = musb_core_init(plat->config->multipoint
  2012. ? MUSB_CONTROLLER_MHDRC
  2013. : MUSB_CONTROLLER_HDRC, musb);
  2014. if (status < 0)
  2015. goto fail3;
  2016. setup_timer(&musb->otg_timer, musb_otg_timer_func, (unsigned long) musb);
  2017. /* attach to the IRQ */
  2018. if (request_irq(nIrq, musb->isr, IRQF_SHARED, dev_name(dev), musb)) {
  2019. dev_err(dev, "request_irq %d failed!\n", nIrq);
  2020. status = -ENODEV;
  2021. goto fail3;
  2022. }
  2023. musb->nIrq = nIrq;
  2024. /* FIXME this handles wakeup irqs wrong */
  2025. if (enable_irq_wake(nIrq) == 0) {
  2026. musb->irq_wake = 1;
  2027. device_init_wakeup(dev, 1);
  2028. } else {
  2029. musb->irq_wake = 0;
  2030. }
  2031. /* program PHY to use external vBus if required */
  2032. if (plat->extvbus) {
  2033. u8 busctl = musb_read_ulpi_buscontrol(musb->mregs);
  2034. busctl |= MUSB_ULPI_USE_EXTVBUS;
  2035. musb_write_ulpi_buscontrol(musb->mregs, busctl);
  2036. }
  2037. if (musb->xceiv->otg->default_a) {
  2038. MUSB_HST_MODE(musb);
  2039. musb->xceiv->otg->state = OTG_STATE_A_IDLE;
  2040. } else {
  2041. MUSB_DEV_MODE(musb);
  2042. musb->xceiv->otg->state = OTG_STATE_B_IDLE;
  2043. }
  2044. switch (musb->port_mode) {
  2045. case MUSB_PORT_MODE_HOST:
  2046. status = musb_host_setup(musb, plat->power);
  2047. if (status < 0)
  2048. goto fail3;
  2049. status = musb_platform_set_mode(musb, MUSB_HOST);
  2050. break;
  2051. case MUSB_PORT_MODE_GADGET:
  2052. status = musb_gadget_setup(musb);
  2053. if (status < 0)
  2054. goto fail3;
  2055. status = musb_platform_set_mode(musb, MUSB_PERIPHERAL);
  2056. break;
  2057. case MUSB_PORT_MODE_DUAL_ROLE:
  2058. status = musb_host_setup(musb, plat->power);
  2059. if (status < 0)
  2060. goto fail3;
  2061. status = musb_gadget_setup(musb);
  2062. if (status) {
  2063. musb_host_cleanup(musb);
  2064. goto fail3;
  2065. }
  2066. status = musb_platform_set_mode(musb, MUSB_OTG);
  2067. break;
  2068. default:
  2069. dev_err(dev, "unsupported port mode %d\n", musb->port_mode);
  2070. break;
  2071. }
  2072. if (status < 0)
  2073. goto fail3;
  2074. status = musb_init_debugfs(musb);
  2075. if (status < 0)
  2076. goto fail4;
  2077. status = sysfs_create_group(&musb->controller->kobj, &musb_attr_group);
  2078. if (status)
  2079. goto fail5;
  2080. musb->is_initialized = 1;
  2081. pm_runtime_mark_last_busy(musb->controller);
  2082. pm_runtime_put_autosuspend(musb->controller);
  2083. return 0;
  2084. fail5:
  2085. musb_exit_debugfs(musb);
  2086. fail4:
  2087. musb_gadget_cleanup(musb);
  2088. musb_host_cleanup(musb);
  2089. fail3:
  2090. cancel_delayed_work_sync(&musb->irq_work);
  2091. cancel_delayed_work_sync(&musb->finish_resume_work);
  2092. cancel_delayed_work_sync(&musb->deassert_reset_work);
  2093. if (musb->dma_controller)
  2094. musb_dma_controller_destroy(musb->dma_controller);
  2095. fail2_5:
  2096. usb_phy_shutdown(musb->xceiv);
  2097. err_usb_phy_init:
  2098. pm_runtime_dont_use_autosuspend(musb->controller);
  2099. pm_runtime_put_sync(musb->controller);
  2100. pm_runtime_disable(musb->controller);
  2101. fail2:
  2102. if (musb->irq_wake)
  2103. device_init_wakeup(dev, 0);
  2104. musb_platform_exit(musb);
  2105. fail1:
  2106. if (status != -EPROBE_DEFER)
  2107. dev_err(musb->controller,
  2108. "%s failed with status %d\n", __func__, status);
  2109. musb_free(musb);
  2110. fail0:
  2111. return status;
  2112. }
  2113. /*-------------------------------------------------------------------------*/
  2114. /* all implementations (PCI bridge to FPGA, VLYNQ, etc) should just
  2115. * bridge to a platform device; this driver then suffices.
  2116. */
  2117. static int musb_probe(struct platform_device *pdev)
  2118. {
  2119. struct device *dev = &pdev->dev;
  2120. int irq = platform_get_irq_byname(pdev, "mc");
  2121. struct resource *iomem;
  2122. void __iomem *base;
  2123. if (irq <= 0)
  2124. return -ENODEV;
  2125. iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  2126. base = devm_ioremap_resource(dev, iomem);
  2127. if (IS_ERR(base))
  2128. return PTR_ERR(base);
  2129. return musb_init_controller(dev, irq, base);
  2130. }
  2131. static int musb_remove(struct platform_device *pdev)
  2132. {
  2133. struct device *dev = &pdev->dev;
  2134. struct musb *musb = dev_to_musb(dev);
  2135. unsigned long flags;
  2136. /* this gets called on rmmod.
  2137. * - Host mode: host may still be active
  2138. * - Peripheral mode: peripheral is deactivated (or never-activated)
  2139. * - OTG mode: both roles are deactivated (or never-activated)
  2140. */
  2141. musb_exit_debugfs(musb);
  2142. cancel_delayed_work_sync(&musb->irq_work);
  2143. cancel_delayed_work_sync(&musb->finish_resume_work);
  2144. cancel_delayed_work_sync(&musb->deassert_reset_work);
  2145. pm_runtime_get_sync(musb->controller);
  2146. musb_host_cleanup(musb);
  2147. musb_gadget_cleanup(musb);
  2148. musb_platform_disable(musb);
  2149. spin_lock_irqsave(&musb->lock, flags);
  2150. musb_disable_interrupts(musb);
  2151. musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
  2152. spin_unlock_irqrestore(&musb->lock, flags);
  2153. pm_runtime_dont_use_autosuspend(musb->controller);
  2154. pm_runtime_put_sync(musb->controller);
  2155. pm_runtime_disable(musb->controller);
  2156. musb_platform_exit(musb);
  2157. musb_phy_callback = NULL;
  2158. if (musb->dma_controller)
  2159. musb_dma_controller_destroy(musb->dma_controller);
  2160. usb_phy_shutdown(musb->xceiv);
  2161. musb_free(musb);
  2162. device_init_wakeup(dev, 0);
  2163. return 0;
  2164. }
  2165. #ifdef CONFIG_PM
  2166. static void musb_save_context(struct musb *musb)
  2167. {
  2168. int i;
  2169. void __iomem *musb_base = musb->mregs;
  2170. void __iomem *epio;
  2171. musb->context.frame = musb_readw(musb_base, MUSB_FRAME);
  2172. musb->context.testmode = musb_readb(musb_base, MUSB_TESTMODE);
  2173. musb->context.busctl = musb_read_ulpi_buscontrol(musb->mregs);
  2174. musb->context.power = musb_readb(musb_base, MUSB_POWER);
  2175. musb->context.intrusbe = musb_readb(musb_base, MUSB_INTRUSBE);
  2176. musb->context.index = musb_readb(musb_base, MUSB_INDEX);
  2177. musb->context.devctl = musb_readb(musb_base, MUSB_DEVCTL);
  2178. for (i = 0; i < musb->config->num_eps; ++i) {
  2179. struct musb_hw_ep *hw_ep;
  2180. hw_ep = &musb->endpoints[i];
  2181. if (!hw_ep)
  2182. continue;
  2183. epio = hw_ep->regs;
  2184. if (!epio)
  2185. continue;
  2186. musb_writeb(musb_base, MUSB_INDEX, i);
  2187. musb->context.index_regs[i].txmaxp =
  2188. musb_readw(epio, MUSB_TXMAXP);
  2189. musb->context.index_regs[i].txcsr =
  2190. musb_readw(epio, MUSB_TXCSR);
  2191. musb->context.index_regs[i].rxmaxp =
  2192. musb_readw(epio, MUSB_RXMAXP);
  2193. musb->context.index_regs[i].rxcsr =
  2194. musb_readw(epio, MUSB_RXCSR);
  2195. if (musb->dyn_fifo) {
  2196. musb->context.index_regs[i].txfifoadd =
  2197. musb_read_txfifoadd(musb_base);
  2198. musb->context.index_regs[i].rxfifoadd =
  2199. musb_read_rxfifoadd(musb_base);
  2200. musb->context.index_regs[i].txfifosz =
  2201. musb_read_txfifosz(musb_base);
  2202. musb->context.index_regs[i].rxfifosz =
  2203. musb_read_rxfifosz(musb_base);
  2204. }
  2205. musb->context.index_regs[i].txtype =
  2206. musb_readb(epio, MUSB_TXTYPE);
  2207. musb->context.index_regs[i].txinterval =
  2208. musb_readb(epio, MUSB_TXINTERVAL);
  2209. musb->context.index_regs[i].rxtype =
  2210. musb_readb(epio, MUSB_RXTYPE);
  2211. musb->context.index_regs[i].rxinterval =
  2212. musb_readb(epio, MUSB_RXINTERVAL);
  2213. musb->context.index_regs[i].txfunaddr =
  2214. musb_read_txfunaddr(musb, i);
  2215. musb->context.index_regs[i].txhubaddr =
  2216. musb_read_txhubaddr(musb, i);
  2217. musb->context.index_regs[i].txhubport =
  2218. musb_read_txhubport(musb, i);
  2219. musb->context.index_regs[i].rxfunaddr =
  2220. musb_read_rxfunaddr(musb, i);
  2221. musb->context.index_regs[i].rxhubaddr =
  2222. musb_read_rxhubaddr(musb, i);
  2223. musb->context.index_regs[i].rxhubport =
  2224. musb_read_rxhubport(musb, i);
  2225. }
  2226. }
  2227. static void musb_restore_context(struct musb *musb)
  2228. {
  2229. int i;
  2230. void __iomem *musb_base = musb->mregs;
  2231. void __iomem *epio;
  2232. u8 power;
  2233. musb_writew(musb_base, MUSB_FRAME, musb->context.frame);
  2234. musb_writeb(musb_base, MUSB_TESTMODE, musb->context.testmode);
  2235. musb_write_ulpi_buscontrol(musb->mregs, musb->context.busctl);
  2236. /* Don't affect SUSPENDM/RESUME bits in POWER reg */
  2237. power = musb_readb(musb_base, MUSB_POWER);
  2238. power &= MUSB_POWER_SUSPENDM | MUSB_POWER_RESUME;
  2239. musb->context.power &= ~(MUSB_POWER_SUSPENDM | MUSB_POWER_RESUME);
  2240. power |= musb->context.power;
  2241. musb_writeb(musb_base, MUSB_POWER, power);
  2242. musb_writew(musb_base, MUSB_INTRTXE, musb->intrtxe);
  2243. musb_writew(musb_base, MUSB_INTRRXE, musb->intrrxe);
  2244. musb_writeb(musb_base, MUSB_INTRUSBE, musb->context.intrusbe);
  2245. if (musb->context.devctl & MUSB_DEVCTL_SESSION)
  2246. musb_writeb(musb_base, MUSB_DEVCTL, musb->context.devctl);
  2247. for (i = 0; i < musb->config->num_eps; ++i) {
  2248. struct musb_hw_ep *hw_ep;
  2249. hw_ep = &musb->endpoints[i];
  2250. if (!hw_ep)
  2251. continue;
  2252. epio = hw_ep->regs;
  2253. if (!epio)
  2254. continue;
  2255. musb_writeb(musb_base, MUSB_INDEX, i);
  2256. musb_writew(epio, MUSB_TXMAXP,
  2257. musb->context.index_regs[i].txmaxp);
  2258. musb_writew(epio, MUSB_TXCSR,
  2259. musb->context.index_regs[i].txcsr);
  2260. musb_writew(epio, MUSB_RXMAXP,
  2261. musb->context.index_regs[i].rxmaxp);
  2262. musb_writew(epio, MUSB_RXCSR,
  2263. musb->context.index_regs[i].rxcsr);
  2264. if (musb->dyn_fifo) {
  2265. musb_write_txfifosz(musb_base,
  2266. musb->context.index_regs[i].txfifosz);
  2267. musb_write_rxfifosz(musb_base,
  2268. musb->context.index_regs[i].rxfifosz);
  2269. musb_write_txfifoadd(musb_base,
  2270. musb->context.index_regs[i].txfifoadd);
  2271. musb_write_rxfifoadd(musb_base,
  2272. musb->context.index_regs[i].rxfifoadd);
  2273. }
  2274. musb_writeb(epio, MUSB_TXTYPE,
  2275. musb->context.index_regs[i].txtype);
  2276. musb_writeb(epio, MUSB_TXINTERVAL,
  2277. musb->context.index_regs[i].txinterval);
  2278. musb_writeb(epio, MUSB_RXTYPE,
  2279. musb->context.index_regs[i].rxtype);
  2280. musb_writeb(epio, MUSB_RXINTERVAL,
  2281. musb->context.index_regs[i].rxinterval);
  2282. musb_write_txfunaddr(musb, i,
  2283. musb->context.index_regs[i].txfunaddr);
  2284. musb_write_txhubaddr(musb, i,
  2285. musb->context.index_regs[i].txhubaddr);
  2286. musb_write_txhubport(musb, i,
  2287. musb->context.index_regs[i].txhubport);
  2288. musb_write_rxfunaddr(musb, i,
  2289. musb->context.index_regs[i].rxfunaddr);
  2290. musb_write_rxhubaddr(musb, i,
  2291. musb->context.index_regs[i].rxhubaddr);
  2292. musb_write_rxhubport(musb, i,
  2293. musb->context.index_regs[i].rxhubport);
  2294. }
  2295. musb_writeb(musb_base, MUSB_INDEX, musb->context.index);
  2296. }
  2297. static int musb_suspend(struct device *dev)
  2298. {
  2299. struct musb *musb = dev_to_musb(dev);
  2300. unsigned long flags;
  2301. int ret;
  2302. ret = pm_runtime_get_sync(dev);
  2303. if (ret < 0) {
  2304. pm_runtime_put_noidle(dev);
  2305. return ret;
  2306. }
  2307. musb_platform_disable(musb);
  2308. musb_disable_interrupts(musb);
  2309. musb->flush_irq_work = true;
  2310. while (flush_delayed_work(&musb->irq_work))
  2311. ;
  2312. musb->flush_irq_work = false;
  2313. if (!(musb->io.quirks & MUSB_PRESERVE_SESSION))
  2314. musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
  2315. WARN_ON(!list_empty(&musb->pending_list));
  2316. spin_lock_irqsave(&musb->lock, flags);
  2317. if (is_peripheral_active(musb)) {
  2318. /* FIXME force disconnect unless we know USB will wake
  2319. * the system up quickly enough to respond ...
  2320. */
  2321. } else if (is_host_active(musb)) {
  2322. /* we know all the children are suspended; sometimes
  2323. * they will even be wakeup-enabled.
  2324. */
  2325. }
  2326. musb_save_context(musb);
  2327. spin_unlock_irqrestore(&musb->lock, flags);
  2328. return 0;
  2329. }
  2330. static int musb_resume(struct device *dev)
  2331. {
  2332. struct musb *musb = dev_to_musb(dev);
  2333. unsigned long flags;
  2334. int error;
  2335. u8 devctl;
  2336. u8 mask;
  2337. /*
  2338. * For static cmos like DaVinci, register values were preserved
  2339. * unless for some reason the whole soc powered down or the USB
  2340. * module got reset through the PSC (vs just being disabled).
  2341. *
  2342. * For the DSPS glue layer though, a full register restore has to
  2343. * be done. As it shouldn't harm other platforms, we do it
  2344. * unconditionally.
  2345. */
  2346. musb_restore_context(musb);
  2347. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  2348. mask = MUSB_DEVCTL_BDEVICE | MUSB_DEVCTL_FSDEV | MUSB_DEVCTL_LSDEV;
  2349. if ((devctl & mask) != (musb->context.devctl & mask))
  2350. musb->port1_status = 0;
  2351. musb_start(musb);
  2352. spin_lock_irqsave(&musb->lock, flags);
  2353. error = musb_run_resume_work(musb);
  2354. if (error)
  2355. dev_err(musb->controller, "resume work failed with %i\n",
  2356. error);
  2357. spin_unlock_irqrestore(&musb->lock, flags);
  2358. pm_runtime_mark_last_busy(dev);
  2359. pm_runtime_put_autosuspend(dev);
  2360. return 0;
  2361. }
  2362. static int musb_runtime_suspend(struct device *dev)
  2363. {
  2364. struct musb *musb = dev_to_musb(dev);
  2365. musb_save_context(musb);
  2366. musb->is_runtime_suspended = 1;
  2367. return 0;
  2368. }
  2369. static int musb_runtime_resume(struct device *dev)
  2370. {
  2371. struct musb *musb = dev_to_musb(dev);
  2372. unsigned long flags;
  2373. int error;
  2374. /*
  2375. * When pm_runtime_get_sync called for the first time in driver
  2376. * init, some of the structure is still not initialized which is
  2377. * used in restore function. But clock needs to be
  2378. * enabled before any register access, so
  2379. * pm_runtime_get_sync has to be called.
  2380. * Also context restore without save does not make
  2381. * any sense
  2382. */
  2383. if (!musb->is_initialized)
  2384. return 0;
  2385. musb_restore_context(musb);
  2386. spin_lock_irqsave(&musb->lock, flags);
  2387. error = musb_run_resume_work(musb);
  2388. if (error)
  2389. dev_err(musb->controller, "resume work failed with %i\n",
  2390. error);
  2391. musb->is_runtime_suspended = 0;
  2392. spin_unlock_irqrestore(&musb->lock, flags);
  2393. return 0;
  2394. }
  2395. static const struct dev_pm_ops musb_dev_pm_ops = {
  2396. .suspend = musb_suspend,
  2397. .resume = musb_resume,
  2398. .runtime_suspend = musb_runtime_suspend,
  2399. .runtime_resume = musb_runtime_resume,
  2400. };
  2401. #define MUSB_DEV_PM_OPS (&musb_dev_pm_ops)
  2402. #else
  2403. #define MUSB_DEV_PM_OPS NULL
  2404. #endif
  2405. static struct platform_driver musb_driver = {
  2406. .driver = {
  2407. .name = (char *)musb_driver_name,
  2408. .bus = &platform_bus_type,
  2409. .pm = MUSB_DEV_PM_OPS,
  2410. },
  2411. .probe = musb_probe,
  2412. .remove = musb_remove,
  2413. };
  2414. module_platform_driver(musb_driver);