musb_core.c 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808
  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->need_finish_resume = 1;
  506. musb->xceiv->otg->state = OTG_STATE_A_HOST;
  507. musb->is_active = 1;
  508. musb_host_resume_root_hub(musb);
  509. break;
  510. case OTG_STATE_B_WAIT_ACON:
  511. musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
  512. musb->is_active = 1;
  513. MUSB_DEV_MODE(musb);
  514. break;
  515. default:
  516. WARNING("bogus %s RESUME (%s)\n",
  517. "host",
  518. usb_otg_state_string(musb->xceiv->otg->state));
  519. }
  520. } else {
  521. switch (musb->xceiv->otg->state) {
  522. case OTG_STATE_A_SUSPEND:
  523. /* possibly DISCONNECT is upcoming */
  524. musb->xceiv->otg->state = OTG_STATE_A_HOST;
  525. musb_host_resume_root_hub(musb);
  526. break;
  527. case OTG_STATE_B_WAIT_ACON:
  528. case OTG_STATE_B_PERIPHERAL:
  529. /* disconnect while suspended? we may
  530. * not get a disconnect irq...
  531. */
  532. if ((devctl & MUSB_DEVCTL_VBUS)
  533. != (3 << MUSB_DEVCTL_VBUS_SHIFT)
  534. ) {
  535. musb->int_usb |= MUSB_INTR_DISCONNECT;
  536. musb->int_usb &= ~MUSB_INTR_SUSPEND;
  537. break;
  538. }
  539. musb_g_resume(musb);
  540. break;
  541. case OTG_STATE_B_IDLE:
  542. musb->int_usb &= ~MUSB_INTR_SUSPEND;
  543. break;
  544. default:
  545. WARNING("bogus %s RESUME (%s)\n",
  546. "peripheral",
  547. usb_otg_state_string(musb->xceiv->otg->state));
  548. }
  549. }
  550. }
  551. /* see manual for the order of the tests */
  552. if (int_usb & MUSB_INTR_SESSREQ) {
  553. void __iomem *mbase = musb->mregs;
  554. if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS
  555. && (devctl & MUSB_DEVCTL_BDEVICE)) {
  556. musb_dbg(musb, "SessReq while on B state");
  557. return IRQ_HANDLED;
  558. }
  559. musb_dbg(musb, "SESSION_REQUEST (%s)",
  560. usb_otg_state_string(musb->xceiv->otg->state));
  561. /* IRQ arrives from ID pin sense or (later, if VBUS power
  562. * is removed) SRP. responses are time critical:
  563. * - turn on VBUS (with silicon-specific mechanism)
  564. * - go through A_WAIT_VRISE
  565. * - ... to A_WAIT_BCON.
  566. * a_wait_vrise_tmout triggers VBUS_ERROR transitions
  567. */
  568. musb_writeb(mbase, MUSB_DEVCTL, MUSB_DEVCTL_SESSION);
  569. musb->ep0_stage = MUSB_EP0_START;
  570. musb->xceiv->otg->state = OTG_STATE_A_IDLE;
  571. MUSB_HST_MODE(musb);
  572. musb_platform_set_vbus(musb, 1);
  573. handled = IRQ_HANDLED;
  574. }
  575. if (int_usb & MUSB_INTR_VBUSERROR) {
  576. int ignore = 0;
  577. /* During connection as an A-Device, we may see a short
  578. * current spikes causing voltage drop, because of cable
  579. * and peripheral capacitance combined with vbus draw.
  580. * (So: less common with truly self-powered devices, where
  581. * vbus doesn't act like a power supply.)
  582. *
  583. * Such spikes are short; usually less than ~500 usec, max
  584. * of ~2 msec. That is, they're not sustained overcurrent
  585. * errors, though they're reported using VBUSERROR irqs.
  586. *
  587. * Workarounds: (a) hardware: use self powered devices.
  588. * (b) software: ignore non-repeated VBUS errors.
  589. *
  590. * REVISIT: do delays from lots of DEBUG_KERNEL checks
  591. * make trouble here, keeping VBUS < 4.4V ?
  592. */
  593. switch (musb->xceiv->otg->state) {
  594. case OTG_STATE_A_HOST:
  595. /* recovery is dicey once we've gotten past the
  596. * initial stages of enumeration, but if VBUS
  597. * stayed ok at the other end of the link, and
  598. * another reset is due (at least for high speed,
  599. * to redo the chirp etc), it might work OK...
  600. */
  601. case OTG_STATE_A_WAIT_BCON:
  602. case OTG_STATE_A_WAIT_VRISE:
  603. if (musb->vbuserr_retry) {
  604. void __iomem *mbase = musb->mregs;
  605. musb->vbuserr_retry--;
  606. ignore = 1;
  607. devctl |= MUSB_DEVCTL_SESSION;
  608. musb_writeb(mbase, MUSB_DEVCTL, devctl);
  609. } else {
  610. musb->port1_status |=
  611. USB_PORT_STAT_OVERCURRENT
  612. | (USB_PORT_STAT_C_OVERCURRENT << 16);
  613. }
  614. break;
  615. default:
  616. break;
  617. }
  618. dev_printk(ignore ? KERN_DEBUG : KERN_ERR, musb->controller,
  619. "VBUS_ERROR in %s (%02x, %s), retry #%d, port1 %08x\n",
  620. usb_otg_state_string(musb->xceiv->otg->state),
  621. devctl,
  622. ({ char *s;
  623. switch (devctl & MUSB_DEVCTL_VBUS) {
  624. case 0 << MUSB_DEVCTL_VBUS_SHIFT:
  625. s = "<SessEnd"; break;
  626. case 1 << MUSB_DEVCTL_VBUS_SHIFT:
  627. s = "<AValid"; break;
  628. case 2 << MUSB_DEVCTL_VBUS_SHIFT:
  629. s = "<VBusValid"; break;
  630. /* case 3 << MUSB_DEVCTL_VBUS_SHIFT: */
  631. default:
  632. s = "VALID"; break;
  633. } s; }),
  634. VBUSERR_RETRY_COUNT - musb->vbuserr_retry,
  635. musb->port1_status);
  636. /* go through A_WAIT_VFALL then start a new session */
  637. if (!ignore)
  638. musb_platform_set_vbus(musb, 0);
  639. handled = IRQ_HANDLED;
  640. }
  641. if (int_usb & MUSB_INTR_SUSPEND) {
  642. musb_dbg(musb, "SUSPEND (%s) devctl %02x",
  643. usb_otg_state_string(musb->xceiv->otg->state), devctl);
  644. handled = IRQ_HANDLED;
  645. switch (musb->xceiv->otg->state) {
  646. case OTG_STATE_A_PERIPHERAL:
  647. /* We also come here if the cable is removed, since
  648. * this silicon doesn't report ID-no-longer-grounded.
  649. *
  650. * We depend on T(a_wait_bcon) to shut us down, and
  651. * hope users don't do anything dicey during this
  652. * undesired detour through A_WAIT_BCON.
  653. */
  654. musb_hnp_stop(musb);
  655. musb_host_resume_root_hub(musb);
  656. musb_root_disconnect(musb);
  657. musb_platform_try_idle(musb, jiffies
  658. + msecs_to_jiffies(musb->a_wait_bcon
  659. ? : OTG_TIME_A_WAIT_BCON));
  660. break;
  661. case OTG_STATE_B_IDLE:
  662. if (!musb->is_active)
  663. break;
  664. case OTG_STATE_B_PERIPHERAL:
  665. musb_g_suspend(musb);
  666. musb->is_active = musb->g.b_hnp_enable;
  667. if (musb->is_active) {
  668. musb->xceiv->otg->state = OTG_STATE_B_WAIT_ACON;
  669. musb_dbg(musb, "HNP: Setting timer for b_ase0_brst");
  670. mod_timer(&musb->otg_timer, jiffies
  671. + msecs_to_jiffies(
  672. OTG_TIME_B_ASE0_BRST));
  673. }
  674. break;
  675. case OTG_STATE_A_WAIT_BCON:
  676. if (musb->a_wait_bcon != 0)
  677. musb_platform_try_idle(musb, jiffies
  678. + msecs_to_jiffies(musb->a_wait_bcon));
  679. break;
  680. case OTG_STATE_A_HOST:
  681. musb->xceiv->otg->state = OTG_STATE_A_SUSPEND;
  682. musb->is_active = musb->hcd->self.b_hnp_enable;
  683. break;
  684. case OTG_STATE_B_HOST:
  685. /* Transition to B_PERIPHERAL, see 6.8.2.6 p 44 */
  686. musb_dbg(musb, "REVISIT: SUSPEND as B_HOST");
  687. break;
  688. default:
  689. /* "should not happen" */
  690. musb->is_active = 0;
  691. break;
  692. }
  693. }
  694. if (int_usb & MUSB_INTR_CONNECT) {
  695. struct usb_hcd *hcd = musb->hcd;
  696. handled = IRQ_HANDLED;
  697. musb->is_active = 1;
  698. musb->ep0_stage = MUSB_EP0_START;
  699. musb->intrtxe = musb->epmask;
  700. musb_writew(musb->mregs, MUSB_INTRTXE, musb->intrtxe);
  701. musb->intrrxe = musb->epmask & 0xfffe;
  702. musb_writew(musb->mregs, MUSB_INTRRXE, musb->intrrxe);
  703. musb_writeb(musb->mregs, MUSB_INTRUSBE, 0xf7);
  704. musb->port1_status &= ~(USB_PORT_STAT_LOW_SPEED
  705. |USB_PORT_STAT_HIGH_SPEED
  706. |USB_PORT_STAT_ENABLE
  707. );
  708. musb->port1_status |= USB_PORT_STAT_CONNECTION
  709. |(USB_PORT_STAT_C_CONNECTION << 16);
  710. /* high vs full speed is just a guess until after reset */
  711. if (devctl & MUSB_DEVCTL_LSDEV)
  712. musb->port1_status |= USB_PORT_STAT_LOW_SPEED;
  713. /* indicate new connection to OTG machine */
  714. switch (musb->xceiv->otg->state) {
  715. case OTG_STATE_B_PERIPHERAL:
  716. if (int_usb & MUSB_INTR_SUSPEND) {
  717. musb_dbg(musb, "HNP: SUSPEND+CONNECT, now b_host");
  718. int_usb &= ~MUSB_INTR_SUSPEND;
  719. goto b_host;
  720. } else
  721. musb_dbg(musb, "CONNECT as b_peripheral???");
  722. break;
  723. case OTG_STATE_B_WAIT_ACON:
  724. musb_dbg(musb, "HNP: CONNECT, now b_host");
  725. b_host:
  726. musb->xceiv->otg->state = OTG_STATE_B_HOST;
  727. if (musb->hcd)
  728. musb->hcd->self.is_b_host = 1;
  729. del_timer(&musb->otg_timer);
  730. break;
  731. default:
  732. if ((devctl & MUSB_DEVCTL_VBUS)
  733. == (3 << MUSB_DEVCTL_VBUS_SHIFT)) {
  734. musb->xceiv->otg->state = OTG_STATE_A_HOST;
  735. if (hcd)
  736. hcd->self.is_b_host = 0;
  737. }
  738. break;
  739. }
  740. musb_host_poke_root_hub(musb);
  741. musb_dbg(musb, "CONNECT (%s) devctl %02x",
  742. usb_otg_state_string(musb->xceiv->otg->state), devctl);
  743. }
  744. if (int_usb & MUSB_INTR_DISCONNECT) {
  745. musb_dbg(musb, "DISCONNECT (%s) as %s, devctl %02x",
  746. usb_otg_state_string(musb->xceiv->otg->state),
  747. MUSB_MODE(musb), devctl);
  748. handled = IRQ_HANDLED;
  749. switch (musb->xceiv->otg->state) {
  750. case OTG_STATE_A_HOST:
  751. case OTG_STATE_A_SUSPEND:
  752. musb_host_resume_root_hub(musb);
  753. musb_root_disconnect(musb);
  754. if (musb->a_wait_bcon != 0)
  755. musb_platform_try_idle(musb, jiffies
  756. + msecs_to_jiffies(musb->a_wait_bcon));
  757. break;
  758. case OTG_STATE_B_HOST:
  759. /* REVISIT this behaves for "real disconnect"
  760. * cases; make sure the other transitions from
  761. * from B_HOST act right too. The B_HOST code
  762. * in hnp_stop() is currently not used...
  763. */
  764. musb_root_disconnect(musb);
  765. if (musb->hcd)
  766. musb->hcd->self.is_b_host = 0;
  767. musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
  768. MUSB_DEV_MODE(musb);
  769. musb_g_disconnect(musb);
  770. break;
  771. case OTG_STATE_A_PERIPHERAL:
  772. musb_hnp_stop(musb);
  773. musb_root_disconnect(musb);
  774. /* FALLTHROUGH */
  775. case OTG_STATE_B_WAIT_ACON:
  776. /* FALLTHROUGH */
  777. case OTG_STATE_B_PERIPHERAL:
  778. case OTG_STATE_B_IDLE:
  779. musb_g_disconnect(musb);
  780. break;
  781. default:
  782. WARNING("unhandled DISCONNECT transition (%s)\n",
  783. usb_otg_state_string(musb->xceiv->otg->state));
  784. break;
  785. }
  786. }
  787. /* mentor saves a bit: bus reset and babble share the same irq.
  788. * only host sees babble; only peripheral sees bus reset.
  789. */
  790. if (int_usb & MUSB_INTR_RESET) {
  791. handled = IRQ_HANDLED;
  792. if (devctl & MUSB_DEVCTL_HM) {
  793. /*
  794. * When BABBLE happens what we can depends on which
  795. * platform MUSB is running, because some platforms
  796. * implemented proprietary means for 'recovering' from
  797. * Babble conditions. One such platform is AM335x. In
  798. * most cases, however, the only thing we can do is
  799. * drop the session.
  800. */
  801. dev_err(musb->controller, "Babble\n");
  802. if (is_host_active(musb))
  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. static void musb_generic_disable(struct musb *musb)
  913. {
  914. void __iomem *mbase = musb->mregs;
  915. musb_disable_interrupts(musb);
  916. /* off */
  917. musb_writeb(mbase, MUSB_DEVCTL, 0);
  918. }
  919. /*
  920. * Program the HDRC to start (enable interrupts, dma, etc.).
  921. */
  922. void musb_start(struct musb *musb)
  923. {
  924. void __iomem *regs = musb->mregs;
  925. u8 devctl = musb_readb(regs, MUSB_DEVCTL);
  926. u8 power;
  927. musb_dbg(musb, "<== devctl %02x", devctl);
  928. musb_enable_interrupts(musb);
  929. musb_writeb(regs, MUSB_TESTMODE, 0);
  930. power = MUSB_POWER_ISOUPDATE;
  931. /*
  932. * treating UNKNOWN as unspecified maximum speed, in which case
  933. * we will default to high-speed.
  934. */
  935. if (musb->config->maximum_speed == USB_SPEED_HIGH ||
  936. musb->config->maximum_speed == USB_SPEED_UNKNOWN)
  937. power |= MUSB_POWER_HSENAB;
  938. musb_writeb(regs, MUSB_POWER, power);
  939. musb->is_active = 0;
  940. devctl = musb_readb(regs, MUSB_DEVCTL);
  941. devctl &= ~MUSB_DEVCTL_SESSION;
  942. /* session started after:
  943. * (a) ID-grounded irq, host mode;
  944. * (b) vbus present/connect IRQ, peripheral mode;
  945. * (c) peripheral initiates, using SRP
  946. */
  947. if (musb->port_mode != MUSB_PORT_MODE_HOST &&
  948. musb->xceiv->otg->state != OTG_STATE_A_WAIT_BCON &&
  949. (devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) {
  950. musb->is_active = 1;
  951. } else {
  952. devctl |= MUSB_DEVCTL_SESSION;
  953. }
  954. musb_platform_enable(musb);
  955. musb_writeb(regs, MUSB_DEVCTL, devctl);
  956. }
  957. /*
  958. * Make the HDRC stop (disable interrupts, etc.);
  959. * reversible by musb_start
  960. * called on gadget driver unregister
  961. * with controller locked, irqs blocked
  962. * acts as a NOP unless some role activated the hardware
  963. */
  964. void musb_stop(struct musb *musb)
  965. {
  966. /* stop IRQs, timers, ... */
  967. musb_platform_disable(musb);
  968. musb_generic_disable(musb);
  969. musb_dbg(musb, "HDRC disabled");
  970. /* FIXME
  971. * - mark host and/or peripheral drivers unusable/inactive
  972. * - disable DMA (and enable it in HdrcStart)
  973. * - make sure we can musb_start() after musb_stop(); with
  974. * OTG mode, gadget driver module rmmod/modprobe cycles that
  975. * - ...
  976. */
  977. musb_platform_try_idle(musb, 0);
  978. }
  979. /*-------------------------------------------------------------------------*/
  980. /*
  981. * The silicon either has hard-wired endpoint configurations, or else
  982. * "dynamic fifo" sizing. The driver has support for both, though at this
  983. * writing only the dynamic sizing is very well tested. Since we switched
  984. * away from compile-time hardware parameters, we can no longer rely on
  985. * dead code elimination to leave only the relevant one in the object file.
  986. *
  987. * We don't currently use dynamic fifo setup capability to do anything
  988. * more than selecting one of a bunch of predefined configurations.
  989. */
  990. static ushort fifo_mode;
  991. /* "modprobe ... fifo_mode=1" etc */
  992. module_param(fifo_mode, ushort, 0);
  993. MODULE_PARM_DESC(fifo_mode, "initial endpoint configuration");
  994. /*
  995. * tables defining fifo_mode values. define more if you like.
  996. * for host side, make sure both halves of ep1 are set up.
  997. */
  998. /* mode 0 - fits in 2KB */
  999. static struct musb_fifo_cfg mode_0_cfg[] = {
  1000. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
  1001. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
  1002. { .hw_ep_num = 2, .style = FIFO_RXTX, .maxpacket = 512, },
  1003. { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
  1004. { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
  1005. };
  1006. /* mode 1 - fits in 4KB */
  1007. static struct musb_fifo_cfg mode_1_cfg[] = {
  1008. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  1009. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  1010. { .hw_ep_num = 2, .style = FIFO_RXTX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  1011. { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
  1012. { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
  1013. };
  1014. /* mode 2 - fits in 4KB */
  1015. static struct musb_fifo_cfg mode_2_cfg[] = {
  1016. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
  1017. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
  1018. { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
  1019. { .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
  1020. { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
  1021. { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
  1022. };
  1023. /* mode 3 - fits in 4KB */
  1024. static struct musb_fifo_cfg mode_3_cfg[] = {
  1025. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  1026. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  1027. { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
  1028. { .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
  1029. { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
  1030. { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
  1031. };
  1032. /* mode 4 - fits in 16KB */
  1033. static struct musb_fifo_cfg mode_4_cfg[] = {
  1034. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
  1035. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
  1036. { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
  1037. { .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
  1038. { .hw_ep_num = 3, .style = FIFO_TX, .maxpacket = 512, },
  1039. { .hw_ep_num = 3, .style = FIFO_RX, .maxpacket = 512, },
  1040. { .hw_ep_num = 4, .style = FIFO_TX, .maxpacket = 512, },
  1041. { .hw_ep_num = 4, .style = FIFO_RX, .maxpacket = 512, },
  1042. { .hw_ep_num = 5, .style = FIFO_TX, .maxpacket = 512, },
  1043. { .hw_ep_num = 5, .style = FIFO_RX, .maxpacket = 512, },
  1044. { .hw_ep_num = 6, .style = FIFO_TX, .maxpacket = 512, },
  1045. { .hw_ep_num = 6, .style = FIFO_RX, .maxpacket = 512, },
  1046. { .hw_ep_num = 7, .style = FIFO_TX, .maxpacket = 512, },
  1047. { .hw_ep_num = 7, .style = FIFO_RX, .maxpacket = 512, },
  1048. { .hw_ep_num = 8, .style = FIFO_TX, .maxpacket = 512, },
  1049. { .hw_ep_num = 8, .style = FIFO_RX, .maxpacket = 512, },
  1050. { .hw_ep_num = 9, .style = FIFO_TX, .maxpacket = 512, },
  1051. { .hw_ep_num = 9, .style = FIFO_RX, .maxpacket = 512, },
  1052. { .hw_ep_num = 10, .style = FIFO_TX, .maxpacket = 256, },
  1053. { .hw_ep_num = 10, .style = FIFO_RX, .maxpacket = 64, },
  1054. { .hw_ep_num = 11, .style = FIFO_TX, .maxpacket = 256, },
  1055. { .hw_ep_num = 11, .style = FIFO_RX, .maxpacket = 64, },
  1056. { .hw_ep_num = 12, .style = FIFO_TX, .maxpacket = 256, },
  1057. { .hw_ep_num = 12, .style = FIFO_RX, .maxpacket = 64, },
  1058. { .hw_ep_num = 13, .style = FIFO_RXTX, .maxpacket = 4096, },
  1059. { .hw_ep_num = 14, .style = FIFO_RXTX, .maxpacket = 1024, },
  1060. { .hw_ep_num = 15, .style = FIFO_RXTX, .maxpacket = 1024, },
  1061. };
  1062. /* mode 5 - fits in 8KB */
  1063. static struct musb_fifo_cfg mode_5_cfg[] = {
  1064. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
  1065. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
  1066. { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
  1067. { .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
  1068. { .hw_ep_num = 3, .style = FIFO_TX, .maxpacket = 512, },
  1069. { .hw_ep_num = 3, .style = FIFO_RX, .maxpacket = 512, },
  1070. { .hw_ep_num = 4, .style = FIFO_TX, .maxpacket = 512, },
  1071. { .hw_ep_num = 4, .style = FIFO_RX, .maxpacket = 512, },
  1072. { .hw_ep_num = 5, .style = FIFO_TX, .maxpacket = 512, },
  1073. { .hw_ep_num = 5, .style = FIFO_RX, .maxpacket = 512, },
  1074. { .hw_ep_num = 6, .style = FIFO_TX, .maxpacket = 32, },
  1075. { .hw_ep_num = 6, .style = FIFO_RX, .maxpacket = 32, },
  1076. { .hw_ep_num = 7, .style = FIFO_TX, .maxpacket = 32, },
  1077. { .hw_ep_num = 7, .style = FIFO_RX, .maxpacket = 32, },
  1078. { .hw_ep_num = 8, .style = FIFO_TX, .maxpacket = 32, },
  1079. { .hw_ep_num = 8, .style = FIFO_RX, .maxpacket = 32, },
  1080. { .hw_ep_num = 9, .style = FIFO_TX, .maxpacket = 32, },
  1081. { .hw_ep_num = 9, .style = FIFO_RX, .maxpacket = 32, },
  1082. { .hw_ep_num = 10, .style = FIFO_TX, .maxpacket = 32, },
  1083. { .hw_ep_num = 10, .style = FIFO_RX, .maxpacket = 32, },
  1084. { .hw_ep_num = 11, .style = FIFO_TX, .maxpacket = 32, },
  1085. { .hw_ep_num = 11, .style = FIFO_RX, .maxpacket = 32, },
  1086. { .hw_ep_num = 12, .style = FIFO_TX, .maxpacket = 32, },
  1087. { .hw_ep_num = 12, .style = FIFO_RX, .maxpacket = 32, },
  1088. { .hw_ep_num = 13, .style = FIFO_RXTX, .maxpacket = 512, },
  1089. { .hw_ep_num = 14, .style = FIFO_RXTX, .maxpacket = 1024, },
  1090. { .hw_ep_num = 15, .style = FIFO_RXTX, .maxpacket = 1024, },
  1091. };
  1092. /*
  1093. * configure a fifo; for non-shared endpoints, this may be called
  1094. * once for a tx fifo and once for an rx fifo.
  1095. *
  1096. * returns negative errno or offset for next fifo.
  1097. */
  1098. static int
  1099. fifo_setup(struct musb *musb, struct musb_hw_ep *hw_ep,
  1100. const struct musb_fifo_cfg *cfg, u16 offset)
  1101. {
  1102. void __iomem *mbase = musb->mregs;
  1103. int size = 0;
  1104. u16 maxpacket = cfg->maxpacket;
  1105. u16 c_off = offset >> 3;
  1106. u8 c_size;
  1107. /* expect hw_ep has already been zero-initialized */
  1108. size = ffs(max(maxpacket, (u16) 8)) - 1;
  1109. maxpacket = 1 << size;
  1110. c_size = size - 3;
  1111. if (cfg->mode == BUF_DOUBLE) {
  1112. if ((offset + (maxpacket << 1)) >
  1113. (1 << (musb->config->ram_bits + 2)))
  1114. return -EMSGSIZE;
  1115. c_size |= MUSB_FIFOSZ_DPB;
  1116. } else {
  1117. if ((offset + maxpacket) > (1 << (musb->config->ram_bits + 2)))
  1118. return -EMSGSIZE;
  1119. }
  1120. /* configure the FIFO */
  1121. musb_writeb(mbase, MUSB_INDEX, hw_ep->epnum);
  1122. /* EP0 reserved endpoint for control, bidirectional;
  1123. * EP1 reserved for bulk, two unidirectional halves.
  1124. */
  1125. if (hw_ep->epnum == 1)
  1126. musb->bulk_ep = hw_ep;
  1127. /* REVISIT error check: be sure ep0 can both rx and tx ... */
  1128. switch (cfg->style) {
  1129. case FIFO_TX:
  1130. musb_write_txfifosz(mbase, c_size);
  1131. musb_write_txfifoadd(mbase, c_off);
  1132. hw_ep->tx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
  1133. hw_ep->max_packet_sz_tx = maxpacket;
  1134. break;
  1135. case FIFO_RX:
  1136. musb_write_rxfifosz(mbase, c_size);
  1137. musb_write_rxfifoadd(mbase, c_off);
  1138. hw_ep->rx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
  1139. hw_ep->max_packet_sz_rx = maxpacket;
  1140. break;
  1141. case FIFO_RXTX:
  1142. musb_write_txfifosz(mbase, c_size);
  1143. musb_write_txfifoadd(mbase, c_off);
  1144. hw_ep->rx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
  1145. hw_ep->max_packet_sz_rx = maxpacket;
  1146. musb_write_rxfifosz(mbase, c_size);
  1147. musb_write_rxfifoadd(mbase, c_off);
  1148. hw_ep->tx_double_buffered = hw_ep->rx_double_buffered;
  1149. hw_ep->max_packet_sz_tx = maxpacket;
  1150. hw_ep->is_shared_fifo = true;
  1151. break;
  1152. }
  1153. /* NOTE rx and tx endpoint irqs aren't managed separately,
  1154. * which happens to be ok
  1155. */
  1156. musb->epmask |= (1 << hw_ep->epnum);
  1157. return offset + (maxpacket << ((c_size & MUSB_FIFOSZ_DPB) ? 1 : 0));
  1158. }
  1159. static struct musb_fifo_cfg ep0_cfg = {
  1160. .style = FIFO_RXTX, .maxpacket = 64,
  1161. };
  1162. static int ep_config_from_table(struct musb *musb)
  1163. {
  1164. const struct musb_fifo_cfg *cfg;
  1165. unsigned i, n;
  1166. int offset;
  1167. struct musb_hw_ep *hw_ep = musb->endpoints;
  1168. if (musb->config->fifo_cfg) {
  1169. cfg = musb->config->fifo_cfg;
  1170. n = musb->config->fifo_cfg_size;
  1171. goto done;
  1172. }
  1173. switch (fifo_mode) {
  1174. default:
  1175. fifo_mode = 0;
  1176. /* FALLTHROUGH */
  1177. case 0:
  1178. cfg = mode_0_cfg;
  1179. n = ARRAY_SIZE(mode_0_cfg);
  1180. break;
  1181. case 1:
  1182. cfg = mode_1_cfg;
  1183. n = ARRAY_SIZE(mode_1_cfg);
  1184. break;
  1185. case 2:
  1186. cfg = mode_2_cfg;
  1187. n = ARRAY_SIZE(mode_2_cfg);
  1188. break;
  1189. case 3:
  1190. cfg = mode_3_cfg;
  1191. n = ARRAY_SIZE(mode_3_cfg);
  1192. break;
  1193. case 4:
  1194. cfg = mode_4_cfg;
  1195. n = ARRAY_SIZE(mode_4_cfg);
  1196. break;
  1197. case 5:
  1198. cfg = mode_5_cfg;
  1199. n = ARRAY_SIZE(mode_5_cfg);
  1200. break;
  1201. }
  1202. pr_debug("%s: setup fifo_mode %d\n", musb_driver_name, fifo_mode);
  1203. done:
  1204. offset = fifo_setup(musb, hw_ep, &ep0_cfg, 0);
  1205. /* assert(offset > 0) */
  1206. /* NOTE: for RTL versions >= 1.400 EPINFO and RAMINFO would
  1207. * be better than static musb->config->num_eps and DYN_FIFO_SIZE...
  1208. */
  1209. for (i = 0; i < n; i++) {
  1210. u8 epn = cfg->hw_ep_num;
  1211. if (epn >= musb->config->num_eps) {
  1212. pr_debug("%s: invalid ep %d\n",
  1213. musb_driver_name, epn);
  1214. return -EINVAL;
  1215. }
  1216. offset = fifo_setup(musb, hw_ep + epn, cfg++, offset);
  1217. if (offset < 0) {
  1218. pr_debug("%s: mem overrun, ep %d\n",
  1219. musb_driver_name, epn);
  1220. return offset;
  1221. }
  1222. epn++;
  1223. musb->nr_endpoints = max(epn, musb->nr_endpoints);
  1224. }
  1225. pr_debug("%s: %d/%d max ep, %d/%d memory\n",
  1226. musb_driver_name,
  1227. n + 1, musb->config->num_eps * 2 - 1,
  1228. offset, (1 << (musb->config->ram_bits + 2)));
  1229. if (!musb->bulk_ep) {
  1230. pr_debug("%s: missing bulk\n", musb_driver_name);
  1231. return -EINVAL;
  1232. }
  1233. return 0;
  1234. }
  1235. /*
  1236. * ep_config_from_hw - when MUSB_C_DYNFIFO_DEF is false
  1237. * @param musb the controller
  1238. */
  1239. static int ep_config_from_hw(struct musb *musb)
  1240. {
  1241. u8 epnum = 0;
  1242. struct musb_hw_ep *hw_ep;
  1243. void __iomem *mbase = musb->mregs;
  1244. int ret = 0;
  1245. musb_dbg(musb, "<== static silicon ep config");
  1246. /* FIXME pick up ep0 maxpacket size */
  1247. for (epnum = 1; epnum < musb->config->num_eps; epnum++) {
  1248. musb_ep_select(mbase, epnum);
  1249. hw_ep = musb->endpoints + epnum;
  1250. ret = musb_read_fifosize(musb, hw_ep, epnum);
  1251. if (ret < 0)
  1252. break;
  1253. /* FIXME set up hw_ep->{rx,tx}_double_buffered */
  1254. /* pick an RX/TX endpoint for bulk */
  1255. if (hw_ep->max_packet_sz_tx < 512
  1256. || hw_ep->max_packet_sz_rx < 512)
  1257. continue;
  1258. /* REVISIT: this algorithm is lazy, we should at least
  1259. * try to pick a double buffered endpoint.
  1260. */
  1261. if (musb->bulk_ep)
  1262. continue;
  1263. musb->bulk_ep = hw_ep;
  1264. }
  1265. if (!musb->bulk_ep) {
  1266. pr_debug("%s: missing bulk\n", musb_driver_name);
  1267. return -EINVAL;
  1268. }
  1269. return 0;
  1270. }
  1271. enum { MUSB_CONTROLLER_MHDRC, MUSB_CONTROLLER_HDRC, };
  1272. /* Initialize MUSB (M)HDRC part of the USB hardware subsystem;
  1273. * configure endpoints, or take their config from silicon
  1274. */
  1275. static int musb_core_init(u16 musb_type, struct musb *musb)
  1276. {
  1277. u8 reg;
  1278. char *type;
  1279. char aInfo[90];
  1280. void __iomem *mbase = musb->mregs;
  1281. int status = 0;
  1282. int i;
  1283. /* log core options (read using indexed model) */
  1284. reg = musb_read_configdata(mbase);
  1285. strcpy(aInfo, (reg & MUSB_CONFIGDATA_UTMIDW) ? "UTMI-16" : "UTMI-8");
  1286. if (reg & MUSB_CONFIGDATA_DYNFIFO) {
  1287. strcat(aInfo, ", dyn FIFOs");
  1288. musb->dyn_fifo = true;
  1289. }
  1290. if (reg & MUSB_CONFIGDATA_MPRXE) {
  1291. strcat(aInfo, ", bulk combine");
  1292. musb->bulk_combine = true;
  1293. }
  1294. if (reg & MUSB_CONFIGDATA_MPTXE) {
  1295. strcat(aInfo, ", bulk split");
  1296. musb->bulk_split = true;
  1297. }
  1298. if (reg & MUSB_CONFIGDATA_HBRXE) {
  1299. strcat(aInfo, ", HB-ISO Rx");
  1300. musb->hb_iso_rx = true;
  1301. }
  1302. if (reg & MUSB_CONFIGDATA_HBTXE) {
  1303. strcat(aInfo, ", HB-ISO Tx");
  1304. musb->hb_iso_tx = true;
  1305. }
  1306. if (reg & MUSB_CONFIGDATA_SOFTCONE)
  1307. strcat(aInfo, ", SoftConn");
  1308. pr_debug("%s: ConfigData=0x%02x (%s)\n", musb_driver_name, reg, aInfo);
  1309. if (MUSB_CONTROLLER_MHDRC == musb_type) {
  1310. musb->is_multipoint = 1;
  1311. type = "M";
  1312. } else {
  1313. musb->is_multipoint = 0;
  1314. type = "";
  1315. #ifndef CONFIG_USB_OTG_BLACKLIST_HUB
  1316. pr_err("%s: kernel must blacklist external hubs\n",
  1317. musb_driver_name);
  1318. #endif
  1319. }
  1320. /* log release info */
  1321. musb->hwvers = musb_read_hwvers(mbase);
  1322. pr_debug("%s: %sHDRC RTL version %d.%d%s\n",
  1323. musb_driver_name, type, MUSB_HWVERS_MAJOR(musb->hwvers),
  1324. MUSB_HWVERS_MINOR(musb->hwvers),
  1325. (musb->hwvers & MUSB_HWVERS_RC) ? "RC" : "");
  1326. /* configure ep0 */
  1327. musb_configure_ep0(musb);
  1328. /* discover endpoint configuration */
  1329. musb->nr_endpoints = 1;
  1330. musb->epmask = 1;
  1331. if (musb->dyn_fifo)
  1332. status = ep_config_from_table(musb);
  1333. else
  1334. status = ep_config_from_hw(musb);
  1335. if (status < 0)
  1336. return status;
  1337. /* finish init, and print endpoint config */
  1338. for (i = 0; i < musb->nr_endpoints; i++) {
  1339. struct musb_hw_ep *hw_ep = musb->endpoints + i;
  1340. hw_ep->fifo = musb->io.fifo_offset(i) + mbase;
  1341. #if IS_ENABLED(CONFIG_USB_MUSB_TUSB6010)
  1342. if (musb->io.quirks & MUSB_IN_TUSB) {
  1343. hw_ep->fifo_async = musb->async + 0x400 +
  1344. musb->io.fifo_offset(i);
  1345. hw_ep->fifo_sync = musb->sync + 0x400 +
  1346. musb->io.fifo_offset(i);
  1347. hw_ep->fifo_sync_va =
  1348. musb->sync_va + 0x400 + musb->io.fifo_offset(i);
  1349. if (i == 0)
  1350. hw_ep->conf = mbase - 0x400 + TUSB_EP0_CONF;
  1351. else
  1352. hw_ep->conf = mbase + 0x400 +
  1353. (((i - 1) & 0xf) << 2);
  1354. }
  1355. #endif
  1356. hw_ep->regs = musb->io.ep_offset(i, 0) + mbase;
  1357. hw_ep->rx_reinit = 1;
  1358. hw_ep->tx_reinit = 1;
  1359. if (hw_ep->max_packet_sz_tx) {
  1360. musb_dbg(musb, "%s: hw_ep %d%s, %smax %d",
  1361. musb_driver_name, i,
  1362. hw_ep->is_shared_fifo ? "shared" : "tx",
  1363. hw_ep->tx_double_buffered
  1364. ? "doublebuffer, " : "",
  1365. hw_ep->max_packet_sz_tx);
  1366. }
  1367. if (hw_ep->max_packet_sz_rx && !hw_ep->is_shared_fifo) {
  1368. musb_dbg(musb, "%s: hw_ep %d%s, %smax %d",
  1369. musb_driver_name, i,
  1370. "rx",
  1371. hw_ep->rx_double_buffered
  1372. ? "doublebuffer, " : "",
  1373. hw_ep->max_packet_sz_rx);
  1374. }
  1375. if (!(hw_ep->max_packet_sz_tx || hw_ep->max_packet_sz_rx))
  1376. musb_dbg(musb, "hw_ep %d not configured", i);
  1377. }
  1378. return 0;
  1379. }
  1380. /*-------------------------------------------------------------------------*/
  1381. /*
  1382. * handle all the irqs defined by the HDRC core. for now we expect: other
  1383. * irq sources (phy, dma, etc) will be handled first, musb->int_* values
  1384. * will be assigned, and the irq will already have been acked.
  1385. *
  1386. * called in irq context with spinlock held, irqs blocked
  1387. */
  1388. irqreturn_t musb_interrupt(struct musb *musb)
  1389. {
  1390. irqreturn_t retval = IRQ_NONE;
  1391. unsigned long status;
  1392. unsigned long epnum;
  1393. u8 devctl;
  1394. if (!musb->int_usb && !musb->int_tx && !musb->int_rx)
  1395. return IRQ_NONE;
  1396. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  1397. trace_musb_isr(musb);
  1398. /**
  1399. * According to Mentor Graphics' documentation, flowchart on page 98,
  1400. * IRQ should be handled as follows:
  1401. *
  1402. * . Resume IRQ
  1403. * . Session Request IRQ
  1404. * . VBUS Error IRQ
  1405. * . Suspend IRQ
  1406. * . Connect IRQ
  1407. * . Disconnect IRQ
  1408. * . Reset/Babble IRQ
  1409. * . SOF IRQ (we're not using this one)
  1410. * . Endpoint 0 IRQ
  1411. * . TX Endpoints
  1412. * . RX Endpoints
  1413. *
  1414. * We will be following that flowchart in order to avoid any problems
  1415. * that might arise with internal Finite State Machine.
  1416. */
  1417. if (musb->int_usb)
  1418. retval |= musb_stage0_irq(musb, musb->int_usb, devctl);
  1419. if (musb->int_tx & 1) {
  1420. if (is_host_active(musb))
  1421. retval |= musb_h_ep0_irq(musb);
  1422. else
  1423. retval |= musb_g_ep0_irq(musb);
  1424. /* we have just handled endpoint 0 IRQ, clear it */
  1425. musb->int_tx &= ~BIT(0);
  1426. }
  1427. status = musb->int_tx;
  1428. for_each_set_bit(epnum, &status, 16) {
  1429. retval = IRQ_HANDLED;
  1430. if (is_host_active(musb))
  1431. musb_host_tx(musb, epnum);
  1432. else
  1433. musb_g_tx(musb, epnum);
  1434. }
  1435. status = musb->int_rx;
  1436. for_each_set_bit(epnum, &status, 16) {
  1437. retval = IRQ_HANDLED;
  1438. if (is_host_active(musb))
  1439. musb_host_rx(musb, epnum);
  1440. else
  1441. musb_g_rx(musb, epnum);
  1442. }
  1443. return retval;
  1444. }
  1445. EXPORT_SYMBOL_GPL(musb_interrupt);
  1446. #ifndef CONFIG_MUSB_PIO_ONLY
  1447. static bool use_dma = 1;
  1448. /* "modprobe ... use_dma=0" etc */
  1449. module_param(use_dma, bool, 0644);
  1450. MODULE_PARM_DESC(use_dma, "enable/disable use of DMA");
  1451. void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit)
  1452. {
  1453. /* called with controller lock already held */
  1454. if (!epnum) {
  1455. if (!is_cppi_enabled(musb)) {
  1456. /* endpoint 0 */
  1457. if (is_host_active(musb))
  1458. musb_h_ep0_irq(musb);
  1459. else
  1460. musb_g_ep0_irq(musb);
  1461. }
  1462. } else {
  1463. /* endpoints 1..15 */
  1464. if (transmit) {
  1465. if (is_host_active(musb))
  1466. musb_host_tx(musb, epnum);
  1467. else
  1468. musb_g_tx(musb, epnum);
  1469. } else {
  1470. /* receive */
  1471. if (is_host_active(musb))
  1472. musb_host_rx(musb, epnum);
  1473. else
  1474. musb_g_rx(musb, epnum);
  1475. }
  1476. }
  1477. }
  1478. EXPORT_SYMBOL_GPL(musb_dma_completion);
  1479. #else
  1480. #define use_dma 0
  1481. #endif
  1482. static int (*musb_phy_callback)(enum musb_vbus_id_status status);
  1483. /*
  1484. * musb_mailbox - optional phy notifier function
  1485. * @status phy state change
  1486. *
  1487. * Optionally gets called from the USB PHY. Note that the USB PHY must be
  1488. * disabled at the point the phy_callback is registered or unregistered.
  1489. */
  1490. int musb_mailbox(enum musb_vbus_id_status status)
  1491. {
  1492. if (musb_phy_callback)
  1493. return musb_phy_callback(status);
  1494. return -ENODEV;
  1495. };
  1496. EXPORT_SYMBOL_GPL(musb_mailbox);
  1497. /*-------------------------------------------------------------------------*/
  1498. static ssize_t
  1499. musb_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
  1500. {
  1501. struct musb *musb = dev_to_musb(dev);
  1502. unsigned long flags;
  1503. int ret = -EINVAL;
  1504. spin_lock_irqsave(&musb->lock, flags);
  1505. ret = sprintf(buf, "%s\n", usb_otg_state_string(musb->xceiv->otg->state));
  1506. spin_unlock_irqrestore(&musb->lock, flags);
  1507. return ret;
  1508. }
  1509. static ssize_t
  1510. musb_mode_store(struct device *dev, struct device_attribute *attr,
  1511. const char *buf, size_t n)
  1512. {
  1513. struct musb *musb = dev_to_musb(dev);
  1514. unsigned long flags;
  1515. int status;
  1516. spin_lock_irqsave(&musb->lock, flags);
  1517. if (sysfs_streq(buf, "host"))
  1518. status = musb_platform_set_mode(musb, MUSB_HOST);
  1519. else if (sysfs_streq(buf, "peripheral"))
  1520. status = musb_platform_set_mode(musb, MUSB_PERIPHERAL);
  1521. else if (sysfs_streq(buf, "otg"))
  1522. status = musb_platform_set_mode(musb, MUSB_OTG);
  1523. else
  1524. status = -EINVAL;
  1525. spin_unlock_irqrestore(&musb->lock, flags);
  1526. return (status == 0) ? n : status;
  1527. }
  1528. static DEVICE_ATTR(mode, 0644, musb_mode_show, musb_mode_store);
  1529. static ssize_t
  1530. musb_vbus_store(struct device *dev, struct device_attribute *attr,
  1531. const char *buf, size_t n)
  1532. {
  1533. struct musb *musb = dev_to_musb(dev);
  1534. unsigned long flags;
  1535. unsigned long val;
  1536. if (sscanf(buf, "%lu", &val) < 1) {
  1537. dev_err(dev, "Invalid VBUS timeout ms value\n");
  1538. return -EINVAL;
  1539. }
  1540. spin_lock_irqsave(&musb->lock, flags);
  1541. /* force T(a_wait_bcon) to be zero/unlimited *OR* valid */
  1542. musb->a_wait_bcon = val ? max_t(int, val, OTG_TIME_A_WAIT_BCON) : 0 ;
  1543. if (musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON)
  1544. musb->is_active = 0;
  1545. musb_platform_try_idle(musb, jiffies + msecs_to_jiffies(val));
  1546. spin_unlock_irqrestore(&musb->lock, flags);
  1547. return n;
  1548. }
  1549. static ssize_t
  1550. musb_vbus_show(struct device *dev, struct device_attribute *attr, char *buf)
  1551. {
  1552. struct musb *musb = dev_to_musb(dev);
  1553. unsigned long flags;
  1554. unsigned long val;
  1555. int vbus;
  1556. u8 devctl;
  1557. spin_lock_irqsave(&musb->lock, flags);
  1558. val = musb->a_wait_bcon;
  1559. vbus = musb_platform_get_vbus_status(musb);
  1560. if (vbus < 0) {
  1561. /* Use default MUSB method by means of DEVCTL register */
  1562. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  1563. if ((devctl & MUSB_DEVCTL_VBUS)
  1564. == (3 << MUSB_DEVCTL_VBUS_SHIFT))
  1565. vbus = 1;
  1566. else
  1567. vbus = 0;
  1568. }
  1569. spin_unlock_irqrestore(&musb->lock, flags);
  1570. return sprintf(buf, "Vbus %s, timeout %lu msec\n",
  1571. vbus ? "on" : "off", val);
  1572. }
  1573. static DEVICE_ATTR(vbus, 0644, musb_vbus_show, musb_vbus_store);
  1574. /* Gadget drivers can't know that a host is connected so they might want
  1575. * to start SRP, but users can. This allows userspace to trigger SRP.
  1576. */
  1577. static ssize_t
  1578. musb_srp_store(struct device *dev, struct device_attribute *attr,
  1579. const char *buf, size_t n)
  1580. {
  1581. struct musb *musb = dev_to_musb(dev);
  1582. unsigned short srp;
  1583. if (sscanf(buf, "%hu", &srp) != 1
  1584. || (srp != 1)) {
  1585. dev_err(dev, "SRP: Value must be 1\n");
  1586. return -EINVAL;
  1587. }
  1588. if (srp == 1)
  1589. musb_g_wakeup(musb);
  1590. return n;
  1591. }
  1592. static DEVICE_ATTR(srp, 0644, NULL, musb_srp_store);
  1593. static struct attribute *musb_attributes[] = {
  1594. &dev_attr_mode.attr,
  1595. &dev_attr_vbus.attr,
  1596. &dev_attr_srp.attr,
  1597. NULL
  1598. };
  1599. static const struct attribute_group musb_attr_group = {
  1600. .attrs = musb_attributes,
  1601. };
  1602. #define MUSB_QUIRK_B_INVALID_VBUS_91 (MUSB_DEVCTL_BDEVICE | \
  1603. (2 << MUSB_DEVCTL_VBUS_SHIFT) | \
  1604. MUSB_DEVCTL_SESSION)
  1605. #define MUSB_QUIRK_A_DISCONNECT_19 ((3 << MUSB_DEVCTL_VBUS_SHIFT) | \
  1606. MUSB_DEVCTL_SESSION)
  1607. /*
  1608. * Check the musb devctl session bit to determine if we want to
  1609. * allow PM runtime for the device. In general, we want to keep things
  1610. * active when the session bit is set except after host disconnect.
  1611. *
  1612. * Only called from musb_irq_work. If this ever needs to get called
  1613. * elsewhere, proper locking must be implemented for musb->session.
  1614. */
  1615. static void musb_pm_runtime_check_session(struct musb *musb)
  1616. {
  1617. u8 devctl, s;
  1618. int error;
  1619. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  1620. /* Handle session status quirks first */
  1621. s = MUSB_DEVCTL_FSDEV | MUSB_DEVCTL_LSDEV |
  1622. MUSB_DEVCTL_HR;
  1623. switch (devctl & ~s) {
  1624. case MUSB_QUIRK_B_INVALID_VBUS_91:
  1625. if (musb->quirk_retries--) {
  1626. musb_dbg(musb,
  1627. "Poll devctl on invalid vbus, assume no session");
  1628. schedule_delayed_work(&musb->irq_work,
  1629. msecs_to_jiffies(1000));
  1630. return;
  1631. }
  1632. case MUSB_QUIRK_A_DISCONNECT_19:
  1633. if (musb->quirk_retries--) {
  1634. musb_dbg(musb,
  1635. "Poll devctl on possible host mode disconnect");
  1636. schedule_delayed_work(&musb->irq_work,
  1637. msecs_to_jiffies(1000));
  1638. return;
  1639. }
  1640. if (!musb->session)
  1641. break;
  1642. musb_dbg(musb, "Allow PM on possible host mode disconnect");
  1643. pm_runtime_mark_last_busy(musb->controller);
  1644. pm_runtime_put_autosuspend(musb->controller);
  1645. musb->session = false;
  1646. return;
  1647. default:
  1648. break;
  1649. }
  1650. /* No need to do anything if session has not changed */
  1651. s = devctl & MUSB_DEVCTL_SESSION;
  1652. if (s == musb->session)
  1653. return;
  1654. /* Block PM or allow PM? */
  1655. if (s) {
  1656. musb_dbg(musb, "Block PM on active session: %02x", devctl);
  1657. error = pm_runtime_get_sync(musb->controller);
  1658. if (error < 0)
  1659. dev_err(musb->controller, "Could not enable: %i\n",
  1660. error);
  1661. musb->quirk_retries = 3;
  1662. } else {
  1663. musb_dbg(musb, "Allow PM with no session: %02x", devctl);
  1664. pm_runtime_mark_last_busy(musb->controller);
  1665. pm_runtime_put_autosuspend(musb->controller);
  1666. }
  1667. musb->session = s;
  1668. }
  1669. /* Only used to provide driver mode change events */
  1670. static void musb_irq_work(struct work_struct *data)
  1671. {
  1672. struct musb *musb = container_of(data, struct musb, irq_work.work);
  1673. musb_pm_runtime_check_session(musb);
  1674. if (musb->xceiv->otg->state != musb->xceiv_old_state) {
  1675. musb->xceiv_old_state = musb->xceiv->otg->state;
  1676. sysfs_notify(&musb->controller->kobj, NULL, "mode");
  1677. }
  1678. }
  1679. static void musb_recover_from_babble(struct musb *musb)
  1680. {
  1681. int ret;
  1682. u8 devctl;
  1683. musb_disable_interrupts(musb);
  1684. /*
  1685. * wait at least 320 cycles of 60MHz clock. That's 5.3us, we will give
  1686. * it some slack and wait for 10us.
  1687. */
  1688. udelay(10);
  1689. ret = musb_platform_recover(musb);
  1690. if (ret) {
  1691. musb_enable_interrupts(musb);
  1692. return;
  1693. }
  1694. /* drop session bit */
  1695. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  1696. devctl &= ~MUSB_DEVCTL_SESSION;
  1697. musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
  1698. /* tell usbcore about it */
  1699. musb_root_disconnect(musb);
  1700. /*
  1701. * When a babble condition occurs, the musb controller
  1702. * removes the session bit and the endpoint config is lost.
  1703. */
  1704. if (musb->dyn_fifo)
  1705. ret = ep_config_from_table(musb);
  1706. else
  1707. ret = ep_config_from_hw(musb);
  1708. /* restart session */
  1709. if (ret == 0)
  1710. musb_start(musb);
  1711. }
  1712. /* --------------------------------------------------------------------------
  1713. * Init support
  1714. */
  1715. static struct musb *allocate_instance(struct device *dev,
  1716. const struct musb_hdrc_config *config, void __iomem *mbase)
  1717. {
  1718. struct musb *musb;
  1719. struct musb_hw_ep *ep;
  1720. int epnum;
  1721. int ret;
  1722. musb = devm_kzalloc(dev, sizeof(*musb), GFP_KERNEL);
  1723. if (!musb)
  1724. return NULL;
  1725. INIT_LIST_HEAD(&musb->control);
  1726. INIT_LIST_HEAD(&musb->in_bulk);
  1727. INIT_LIST_HEAD(&musb->out_bulk);
  1728. INIT_LIST_HEAD(&musb->pending_list);
  1729. musb->vbuserr_retry = VBUSERR_RETRY_COUNT;
  1730. musb->a_wait_bcon = OTG_TIME_A_WAIT_BCON;
  1731. musb->mregs = mbase;
  1732. musb->ctrl_base = mbase;
  1733. musb->nIrq = -ENODEV;
  1734. musb->config = config;
  1735. BUG_ON(musb->config->num_eps > MUSB_C_NUM_EPS);
  1736. for (epnum = 0, ep = musb->endpoints;
  1737. epnum < musb->config->num_eps;
  1738. epnum++, ep++) {
  1739. ep->musb = musb;
  1740. ep->epnum = epnum;
  1741. }
  1742. musb->controller = dev;
  1743. ret = musb_host_alloc(musb);
  1744. if (ret < 0)
  1745. goto err_free;
  1746. dev_set_drvdata(dev, musb);
  1747. return musb;
  1748. err_free:
  1749. return NULL;
  1750. }
  1751. static void musb_free(struct musb *musb)
  1752. {
  1753. /* this has multiple entry modes. it handles fault cleanup after
  1754. * probe(), where things may be partially set up, as well as rmmod
  1755. * cleanup after everything's been de-activated.
  1756. */
  1757. #ifdef CONFIG_SYSFS
  1758. sysfs_remove_group(&musb->controller->kobj, &musb_attr_group);
  1759. #endif
  1760. if (musb->nIrq >= 0) {
  1761. if (musb->irq_wake)
  1762. disable_irq_wake(musb->nIrq);
  1763. free_irq(musb->nIrq, musb);
  1764. }
  1765. musb_host_free(musb);
  1766. }
  1767. struct musb_pending_work {
  1768. int (*callback)(struct musb *musb, void *data);
  1769. void *data;
  1770. struct list_head node;
  1771. };
  1772. #ifdef CONFIG_PM
  1773. /*
  1774. * Called from musb_runtime_resume(), musb_resume(), and
  1775. * musb_queue_resume_work(). Callers must take musb->lock.
  1776. */
  1777. static int musb_run_resume_work(struct musb *musb)
  1778. {
  1779. struct musb_pending_work *w, *_w;
  1780. unsigned long flags;
  1781. int error = 0;
  1782. spin_lock_irqsave(&musb->list_lock, flags);
  1783. list_for_each_entry_safe(w, _w, &musb->pending_list, node) {
  1784. if (w->callback) {
  1785. error = w->callback(musb, w->data);
  1786. if (error < 0) {
  1787. dev_err(musb->controller,
  1788. "resume callback %p failed: %i\n",
  1789. w->callback, error);
  1790. }
  1791. }
  1792. list_del(&w->node);
  1793. devm_kfree(musb->controller, w);
  1794. }
  1795. spin_unlock_irqrestore(&musb->list_lock, flags);
  1796. return error;
  1797. }
  1798. #endif
  1799. /*
  1800. * Called to run work if device is active or else queue the work to happen
  1801. * on resume. Caller must take musb->lock and must hold an RPM reference.
  1802. *
  1803. * Note that we cowardly refuse queuing work after musb PM runtime
  1804. * resume is done calling musb_run_resume_work() and return -EINPROGRESS
  1805. * instead.
  1806. */
  1807. int musb_queue_resume_work(struct musb *musb,
  1808. int (*callback)(struct musb *musb, void *data),
  1809. void *data)
  1810. {
  1811. struct musb_pending_work *w;
  1812. unsigned long flags;
  1813. int error;
  1814. if (WARN_ON(!callback))
  1815. return -EINVAL;
  1816. if (pm_runtime_active(musb->controller))
  1817. return callback(musb, data);
  1818. w = devm_kzalloc(musb->controller, sizeof(*w), GFP_ATOMIC);
  1819. if (!w)
  1820. return -ENOMEM;
  1821. w->callback = callback;
  1822. w->data = data;
  1823. spin_lock_irqsave(&musb->list_lock, flags);
  1824. if (musb->is_runtime_suspended) {
  1825. list_add_tail(&w->node, &musb->pending_list);
  1826. error = 0;
  1827. } else {
  1828. dev_err(musb->controller, "could not add resume work %p\n",
  1829. callback);
  1830. devm_kfree(musb->controller, w);
  1831. error = -EINPROGRESS;
  1832. }
  1833. spin_unlock_irqrestore(&musb->list_lock, flags);
  1834. return error;
  1835. }
  1836. EXPORT_SYMBOL_GPL(musb_queue_resume_work);
  1837. static void musb_deassert_reset(struct work_struct *work)
  1838. {
  1839. struct musb *musb;
  1840. unsigned long flags;
  1841. musb = container_of(work, struct musb, deassert_reset_work.work);
  1842. spin_lock_irqsave(&musb->lock, flags);
  1843. if (musb->port1_status & USB_PORT_STAT_RESET)
  1844. musb_port_reset(musb, false);
  1845. spin_unlock_irqrestore(&musb->lock, flags);
  1846. }
  1847. /*
  1848. * Perform generic per-controller initialization.
  1849. *
  1850. * @dev: the controller (already clocked, etc)
  1851. * @nIrq: IRQ number
  1852. * @ctrl: virtual address of controller registers,
  1853. * not yet corrected for platform-specific offsets
  1854. */
  1855. static int
  1856. musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
  1857. {
  1858. int status;
  1859. struct musb *musb;
  1860. struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
  1861. /* The driver might handle more features than the board; OK.
  1862. * Fail when the board needs a feature that's not enabled.
  1863. */
  1864. if (!plat) {
  1865. dev_err(dev, "no platform_data?\n");
  1866. status = -ENODEV;
  1867. goto fail0;
  1868. }
  1869. /* allocate */
  1870. musb = allocate_instance(dev, plat->config, ctrl);
  1871. if (!musb) {
  1872. status = -ENOMEM;
  1873. goto fail0;
  1874. }
  1875. spin_lock_init(&musb->lock);
  1876. spin_lock_init(&musb->list_lock);
  1877. musb->board_set_power = plat->set_power;
  1878. musb->min_power = plat->min_power;
  1879. musb->ops = plat->platform_ops;
  1880. musb->port_mode = plat->mode;
  1881. /*
  1882. * Initialize the default IO functions. At least omap2430 needs
  1883. * these early. We initialize the platform specific IO functions
  1884. * later on.
  1885. */
  1886. musb_readb = musb_default_readb;
  1887. musb_writeb = musb_default_writeb;
  1888. musb_readw = musb_default_readw;
  1889. musb_writew = musb_default_writew;
  1890. musb_readl = musb_default_readl;
  1891. musb_writel = musb_default_writel;
  1892. /* The musb_platform_init() call:
  1893. * - adjusts musb->mregs
  1894. * - sets the musb->isr
  1895. * - may initialize an integrated transceiver
  1896. * - initializes musb->xceiv, usually by otg_get_phy()
  1897. * - stops powering VBUS
  1898. *
  1899. * There are various transceiver configurations. Blackfin,
  1900. * DaVinci, TUSB60x0, and others integrate them. OMAP3 uses
  1901. * external/discrete ones in various flavors (twl4030 family,
  1902. * isp1504, non-OTG, etc) mostly hooking up through ULPI.
  1903. */
  1904. status = musb_platform_init(musb);
  1905. if (status < 0)
  1906. goto fail1;
  1907. if (!musb->isr) {
  1908. status = -ENODEV;
  1909. goto fail2;
  1910. }
  1911. if (musb->ops->quirks)
  1912. musb->io.quirks = musb->ops->quirks;
  1913. /* Most devices use indexed offset or flat offset */
  1914. if (musb->io.quirks & MUSB_INDEXED_EP) {
  1915. musb->io.ep_offset = musb_indexed_ep_offset;
  1916. musb->io.ep_select = musb_indexed_ep_select;
  1917. } else {
  1918. musb->io.ep_offset = musb_flat_ep_offset;
  1919. musb->io.ep_select = musb_flat_ep_select;
  1920. }
  1921. /* At least tusb6010 has its own offsets */
  1922. if (musb->ops->ep_offset)
  1923. musb->io.ep_offset = musb->ops->ep_offset;
  1924. if (musb->ops->ep_select)
  1925. musb->io.ep_select = musb->ops->ep_select;
  1926. if (musb->ops->fifo_mode)
  1927. fifo_mode = musb->ops->fifo_mode;
  1928. else
  1929. fifo_mode = 4;
  1930. if (musb->ops->fifo_offset)
  1931. musb->io.fifo_offset = musb->ops->fifo_offset;
  1932. else
  1933. musb->io.fifo_offset = musb_default_fifo_offset;
  1934. if (musb->ops->busctl_offset)
  1935. musb->io.busctl_offset = musb->ops->busctl_offset;
  1936. else
  1937. musb->io.busctl_offset = musb_default_busctl_offset;
  1938. if (musb->ops->readb)
  1939. musb_readb = musb->ops->readb;
  1940. if (musb->ops->writeb)
  1941. musb_writeb = musb->ops->writeb;
  1942. if (musb->ops->readw)
  1943. musb_readw = musb->ops->readw;
  1944. if (musb->ops->writew)
  1945. musb_writew = musb->ops->writew;
  1946. if (musb->ops->readl)
  1947. musb_readl = musb->ops->readl;
  1948. if (musb->ops->writel)
  1949. musb_writel = musb->ops->writel;
  1950. #ifndef CONFIG_MUSB_PIO_ONLY
  1951. if (!musb->ops->dma_init || !musb->ops->dma_exit) {
  1952. dev_err(dev, "DMA controller not set\n");
  1953. status = -ENODEV;
  1954. goto fail2;
  1955. }
  1956. musb_dma_controller_create = musb->ops->dma_init;
  1957. musb_dma_controller_destroy = musb->ops->dma_exit;
  1958. #endif
  1959. if (musb->ops->read_fifo)
  1960. musb->io.read_fifo = musb->ops->read_fifo;
  1961. else
  1962. musb->io.read_fifo = musb_default_read_fifo;
  1963. if (musb->ops->write_fifo)
  1964. musb->io.write_fifo = musb->ops->write_fifo;
  1965. else
  1966. musb->io.write_fifo = musb_default_write_fifo;
  1967. if (!musb->xceiv->io_ops) {
  1968. musb->xceiv->io_dev = musb->controller;
  1969. musb->xceiv->io_priv = musb->mregs;
  1970. musb->xceiv->io_ops = &musb_ulpi_access;
  1971. }
  1972. if (musb->ops->phy_callback)
  1973. musb_phy_callback = musb->ops->phy_callback;
  1974. /*
  1975. * We need musb_read/write functions initialized for PM.
  1976. * Note that at least 2430 glue needs autosuspend delay
  1977. * somewhere above 300 ms for the hardware to idle properly
  1978. * after disconnecting the cable in host mode. Let's use
  1979. * 500 ms for some margin.
  1980. */
  1981. pm_runtime_use_autosuspend(musb->controller);
  1982. pm_runtime_set_autosuspend_delay(musb->controller, 500);
  1983. pm_runtime_enable(musb->controller);
  1984. pm_runtime_get_sync(musb->controller);
  1985. status = usb_phy_init(musb->xceiv);
  1986. if (status < 0)
  1987. goto err_usb_phy_init;
  1988. if (use_dma && dev->dma_mask) {
  1989. musb->dma_controller =
  1990. musb_dma_controller_create(musb, musb->mregs);
  1991. if (IS_ERR(musb->dma_controller)) {
  1992. status = PTR_ERR(musb->dma_controller);
  1993. goto fail2_5;
  1994. }
  1995. }
  1996. /* be sure interrupts are disabled before connecting ISR */
  1997. musb_platform_disable(musb);
  1998. musb_generic_disable(musb);
  1999. /* Init IRQ workqueue before request_irq */
  2000. INIT_DELAYED_WORK(&musb->irq_work, musb_irq_work);
  2001. INIT_DELAYED_WORK(&musb->deassert_reset_work, musb_deassert_reset);
  2002. INIT_DELAYED_WORK(&musb->finish_resume_work, musb_host_finish_resume);
  2003. /* setup musb parts of the core (especially endpoints) */
  2004. status = musb_core_init(plat->config->multipoint
  2005. ? MUSB_CONTROLLER_MHDRC
  2006. : MUSB_CONTROLLER_HDRC, musb);
  2007. if (status < 0)
  2008. goto fail3;
  2009. setup_timer(&musb->otg_timer, musb_otg_timer_func, (unsigned long) musb);
  2010. /* attach to the IRQ */
  2011. if (request_irq(nIrq, musb->isr, 0, dev_name(dev), musb)) {
  2012. dev_err(dev, "request_irq %d failed!\n", nIrq);
  2013. status = -ENODEV;
  2014. goto fail3;
  2015. }
  2016. musb->nIrq = nIrq;
  2017. /* FIXME this handles wakeup irqs wrong */
  2018. if (enable_irq_wake(nIrq) == 0) {
  2019. musb->irq_wake = 1;
  2020. device_init_wakeup(dev, 1);
  2021. } else {
  2022. musb->irq_wake = 0;
  2023. }
  2024. /* program PHY to use external vBus if required */
  2025. if (plat->extvbus) {
  2026. u8 busctl = musb_read_ulpi_buscontrol(musb->mregs);
  2027. busctl |= MUSB_ULPI_USE_EXTVBUS;
  2028. musb_write_ulpi_buscontrol(musb->mregs, busctl);
  2029. }
  2030. if (musb->xceiv->otg->default_a) {
  2031. MUSB_HST_MODE(musb);
  2032. musb->xceiv->otg->state = OTG_STATE_A_IDLE;
  2033. } else {
  2034. MUSB_DEV_MODE(musb);
  2035. musb->xceiv->otg->state = OTG_STATE_B_IDLE;
  2036. }
  2037. switch (musb->port_mode) {
  2038. case MUSB_PORT_MODE_HOST:
  2039. status = musb_host_setup(musb, plat->power);
  2040. if (status < 0)
  2041. goto fail3;
  2042. status = musb_platform_set_mode(musb, MUSB_HOST);
  2043. break;
  2044. case MUSB_PORT_MODE_GADGET:
  2045. status = musb_gadget_setup(musb);
  2046. if (status < 0)
  2047. goto fail3;
  2048. status = musb_platform_set_mode(musb, MUSB_PERIPHERAL);
  2049. break;
  2050. case MUSB_PORT_MODE_DUAL_ROLE:
  2051. status = musb_host_setup(musb, plat->power);
  2052. if (status < 0)
  2053. goto fail3;
  2054. status = musb_gadget_setup(musb);
  2055. if (status) {
  2056. musb_host_cleanup(musb);
  2057. goto fail3;
  2058. }
  2059. status = musb_platform_set_mode(musb, MUSB_OTG);
  2060. break;
  2061. default:
  2062. dev_err(dev, "unsupported port mode %d\n", musb->port_mode);
  2063. break;
  2064. }
  2065. if (status < 0)
  2066. goto fail3;
  2067. status = musb_init_debugfs(musb);
  2068. if (status < 0)
  2069. goto fail4;
  2070. status = sysfs_create_group(&musb->controller->kobj, &musb_attr_group);
  2071. if (status)
  2072. goto fail5;
  2073. musb->is_initialized = 1;
  2074. pm_runtime_mark_last_busy(musb->controller);
  2075. pm_runtime_put_autosuspend(musb->controller);
  2076. return 0;
  2077. fail5:
  2078. musb_exit_debugfs(musb);
  2079. fail4:
  2080. musb_gadget_cleanup(musb);
  2081. musb_host_cleanup(musb);
  2082. fail3:
  2083. cancel_delayed_work_sync(&musb->irq_work);
  2084. cancel_delayed_work_sync(&musb->finish_resume_work);
  2085. cancel_delayed_work_sync(&musb->deassert_reset_work);
  2086. if (musb->dma_controller)
  2087. musb_dma_controller_destroy(musb->dma_controller);
  2088. fail2_5:
  2089. usb_phy_shutdown(musb->xceiv);
  2090. err_usb_phy_init:
  2091. pm_runtime_dont_use_autosuspend(musb->controller);
  2092. pm_runtime_put_sync(musb->controller);
  2093. pm_runtime_disable(musb->controller);
  2094. fail2:
  2095. if (musb->irq_wake)
  2096. device_init_wakeup(dev, 0);
  2097. musb_platform_exit(musb);
  2098. fail1:
  2099. if (status != -EPROBE_DEFER)
  2100. dev_err(musb->controller,
  2101. "%s failed with status %d\n", __func__, status);
  2102. musb_free(musb);
  2103. fail0:
  2104. return status;
  2105. }
  2106. /*-------------------------------------------------------------------------*/
  2107. /* all implementations (PCI bridge to FPGA, VLYNQ, etc) should just
  2108. * bridge to a platform device; this driver then suffices.
  2109. */
  2110. static int musb_probe(struct platform_device *pdev)
  2111. {
  2112. struct device *dev = &pdev->dev;
  2113. int irq = platform_get_irq_byname(pdev, "mc");
  2114. struct resource *iomem;
  2115. void __iomem *base;
  2116. if (irq <= 0)
  2117. return -ENODEV;
  2118. iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  2119. base = devm_ioremap_resource(dev, iomem);
  2120. if (IS_ERR(base))
  2121. return PTR_ERR(base);
  2122. return musb_init_controller(dev, irq, base);
  2123. }
  2124. static int musb_remove(struct platform_device *pdev)
  2125. {
  2126. struct device *dev = &pdev->dev;
  2127. struct musb *musb = dev_to_musb(dev);
  2128. unsigned long flags;
  2129. /* this gets called on rmmod.
  2130. * - Host mode: host may still be active
  2131. * - Peripheral mode: peripheral is deactivated (or never-activated)
  2132. * - OTG mode: both roles are deactivated (or never-activated)
  2133. */
  2134. musb_exit_debugfs(musb);
  2135. cancel_delayed_work_sync(&musb->irq_work);
  2136. cancel_delayed_work_sync(&musb->finish_resume_work);
  2137. cancel_delayed_work_sync(&musb->deassert_reset_work);
  2138. pm_runtime_get_sync(musb->controller);
  2139. musb_host_cleanup(musb);
  2140. musb_gadget_cleanup(musb);
  2141. spin_lock_irqsave(&musb->lock, flags);
  2142. musb_platform_disable(musb);
  2143. musb_generic_disable(musb);
  2144. spin_unlock_irqrestore(&musb->lock, flags);
  2145. musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
  2146. pm_runtime_dont_use_autosuspend(musb->controller);
  2147. pm_runtime_put_sync(musb->controller);
  2148. pm_runtime_disable(musb->controller);
  2149. musb_platform_exit(musb);
  2150. musb_phy_callback = NULL;
  2151. if (musb->dma_controller)
  2152. musb_dma_controller_destroy(musb->dma_controller);
  2153. usb_phy_shutdown(musb->xceiv);
  2154. musb_free(musb);
  2155. device_init_wakeup(dev, 0);
  2156. return 0;
  2157. }
  2158. #ifdef CONFIG_PM
  2159. static void musb_save_context(struct musb *musb)
  2160. {
  2161. int i;
  2162. void __iomem *musb_base = musb->mregs;
  2163. void __iomem *epio;
  2164. musb->context.frame = musb_readw(musb_base, MUSB_FRAME);
  2165. musb->context.testmode = musb_readb(musb_base, MUSB_TESTMODE);
  2166. musb->context.busctl = musb_read_ulpi_buscontrol(musb->mregs);
  2167. musb->context.power = musb_readb(musb_base, MUSB_POWER);
  2168. musb->context.intrusbe = musb_readb(musb_base, MUSB_INTRUSBE);
  2169. musb->context.index = musb_readb(musb_base, MUSB_INDEX);
  2170. musb->context.devctl = musb_readb(musb_base, MUSB_DEVCTL);
  2171. for (i = 0; i < musb->config->num_eps; ++i) {
  2172. struct musb_hw_ep *hw_ep;
  2173. hw_ep = &musb->endpoints[i];
  2174. if (!hw_ep)
  2175. continue;
  2176. epio = hw_ep->regs;
  2177. if (!epio)
  2178. continue;
  2179. musb_writeb(musb_base, MUSB_INDEX, i);
  2180. musb->context.index_regs[i].txmaxp =
  2181. musb_readw(epio, MUSB_TXMAXP);
  2182. musb->context.index_regs[i].txcsr =
  2183. musb_readw(epio, MUSB_TXCSR);
  2184. musb->context.index_regs[i].rxmaxp =
  2185. musb_readw(epio, MUSB_RXMAXP);
  2186. musb->context.index_regs[i].rxcsr =
  2187. musb_readw(epio, MUSB_RXCSR);
  2188. if (musb->dyn_fifo) {
  2189. musb->context.index_regs[i].txfifoadd =
  2190. musb_read_txfifoadd(musb_base);
  2191. musb->context.index_regs[i].rxfifoadd =
  2192. musb_read_rxfifoadd(musb_base);
  2193. musb->context.index_regs[i].txfifosz =
  2194. musb_read_txfifosz(musb_base);
  2195. musb->context.index_regs[i].rxfifosz =
  2196. musb_read_rxfifosz(musb_base);
  2197. }
  2198. musb->context.index_regs[i].txtype =
  2199. musb_readb(epio, MUSB_TXTYPE);
  2200. musb->context.index_regs[i].txinterval =
  2201. musb_readb(epio, MUSB_TXINTERVAL);
  2202. musb->context.index_regs[i].rxtype =
  2203. musb_readb(epio, MUSB_RXTYPE);
  2204. musb->context.index_regs[i].rxinterval =
  2205. musb_readb(epio, MUSB_RXINTERVAL);
  2206. musb->context.index_regs[i].txfunaddr =
  2207. musb_read_txfunaddr(musb, i);
  2208. musb->context.index_regs[i].txhubaddr =
  2209. musb_read_txhubaddr(musb, i);
  2210. musb->context.index_regs[i].txhubport =
  2211. musb_read_txhubport(musb, i);
  2212. musb->context.index_regs[i].rxfunaddr =
  2213. musb_read_rxfunaddr(musb, i);
  2214. musb->context.index_regs[i].rxhubaddr =
  2215. musb_read_rxhubaddr(musb, i);
  2216. musb->context.index_regs[i].rxhubport =
  2217. musb_read_rxhubport(musb, i);
  2218. }
  2219. }
  2220. static void musb_restore_context(struct musb *musb)
  2221. {
  2222. int i;
  2223. void __iomem *musb_base = musb->mregs;
  2224. void __iomem *epio;
  2225. u8 power;
  2226. musb_writew(musb_base, MUSB_FRAME, musb->context.frame);
  2227. musb_writeb(musb_base, MUSB_TESTMODE, musb->context.testmode);
  2228. musb_write_ulpi_buscontrol(musb->mregs, musb->context.busctl);
  2229. /* Don't affect SUSPENDM/RESUME bits in POWER reg */
  2230. power = musb_readb(musb_base, MUSB_POWER);
  2231. power &= MUSB_POWER_SUSPENDM | MUSB_POWER_RESUME;
  2232. musb->context.power &= ~(MUSB_POWER_SUSPENDM | MUSB_POWER_RESUME);
  2233. power |= musb->context.power;
  2234. musb_writeb(musb_base, MUSB_POWER, power);
  2235. musb_writew(musb_base, MUSB_INTRTXE, musb->intrtxe);
  2236. musb_writew(musb_base, MUSB_INTRRXE, musb->intrrxe);
  2237. musb_writeb(musb_base, MUSB_INTRUSBE, musb->context.intrusbe);
  2238. if (musb->context.devctl & MUSB_DEVCTL_SESSION)
  2239. musb_writeb(musb_base, MUSB_DEVCTL, musb->context.devctl);
  2240. for (i = 0; i < musb->config->num_eps; ++i) {
  2241. struct musb_hw_ep *hw_ep;
  2242. hw_ep = &musb->endpoints[i];
  2243. if (!hw_ep)
  2244. continue;
  2245. epio = hw_ep->regs;
  2246. if (!epio)
  2247. continue;
  2248. musb_writeb(musb_base, MUSB_INDEX, i);
  2249. musb_writew(epio, MUSB_TXMAXP,
  2250. musb->context.index_regs[i].txmaxp);
  2251. musb_writew(epio, MUSB_TXCSR,
  2252. musb->context.index_regs[i].txcsr);
  2253. musb_writew(epio, MUSB_RXMAXP,
  2254. musb->context.index_regs[i].rxmaxp);
  2255. musb_writew(epio, MUSB_RXCSR,
  2256. musb->context.index_regs[i].rxcsr);
  2257. if (musb->dyn_fifo) {
  2258. musb_write_txfifosz(musb_base,
  2259. musb->context.index_regs[i].txfifosz);
  2260. musb_write_rxfifosz(musb_base,
  2261. musb->context.index_regs[i].rxfifosz);
  2262. musb_write_txfifoadd(musb_base,
  2263. musb->context.index_regs[i].txfifoadd);
  2264. musb_write_rxfifoadd(musb_base,
  2265. musb->context.index_regs[i].rxfifoadd);
  2266. }
  2267. musb_writeb(epio, MUSB_TXTYPE,
  2268. musb->context.index_regs[i].txtype);
  2269. musb_writeb(epio, MUSB_TXINTERVAL,
  2270. musb->context.index_regs[i].txinterval);
  2271. musb_writeb(epio, MUSB_RXTYPE,
  2272. musb->context.index_regs[i].rxtype);
  2273. musb_writeb(epio, MUSB_RXINTERVAL,
  2274. musb->context.index_regs[i].rxinterval);
  2275. musb_write_txfunaddr(musb, i,
  2276. musb->context.index_regs[i].txfunaddr);
  2277. musb_write_txhubaddr(musb, i,
  2278. musb->context.index_regs[i].txhubaddr);
  2279. musb_write_txhubport(musb, i,
  2280. musb->context.index_regs[i].txhubport);
  2281. musb_write_rxfunaddr(musb, i,
  2282. musb->context.index_regs[i].rxfunaddr);
  2283. musb_write_rxhubaddr(musb, i,
  2284. musb->context.index_regs[i].rxhubaddr);
  2285. musb_write_rxhubport(musb, i,
  2286. musb->context.index_regs[i].rxhubport);
  2287. }
  2288. musb_writeb(musb_base, MUSB_INDEX, musb->context.index);
  2289. }
  2290. static int musb_suspend(struct device *dev)
  2291. {
  2292. struct musb *musb = dev_to_musb(dev);
  2293. unsigned long flags;
  2294. musb_platform_disable(musb);
  2295. musb_generic_disable(musb);
  2296. WARN_ON(!list_empty(&musb->pending_list));
  2297. spin_lock_irqsave(&musb->lock, flags);
  2298. if (is_peripheral_active(musb)) {
  2299. /* FIXME force disconnect unless we know USB will wake
  2300. * the system up quickly enough to respond ...
  2301. */
  2302. } else if (is_host_active(musb)) {
  2303. /* we know all the children are suspended; sometimes
  2304. * they will even be wakeup-enabled.
  2305. */
  2306. }
  2307. musb_save_context(musb);
  2308. spin_unlock_irqrestore(&musb->lock, flags);
  2309. return 0;
  2310. }
  2311. static int musb_resume(struct device *dev)
  2312. {
  2313. struct musb *musb = dev_to_musb(dev);
  2314. unsigned long flags;
  2315. int error;
  2316. u8 devctl;
  2317. u8 mask;
  2318. /*
  2319. * For static cmos like DaVinci, register values were preserved
  2320. * unless for some reason the whole soc powered down or the USB
  2321. * module got reset through the PSC (vs just being disabled).
  2322. *
  2323. * For the DSPS glue layer though, a full register restore has to
  2324. * be done. As it shouldn't harm other platforms, we do it
  2325. * unconditionally.
  2326. */
  2327. musb_restore_context(musb);
  2328. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  2329. mask = MUSB_DEVCTL_BDEVICE | MUSB_DEVCTL_FSDEV | MUSB_DEVCTL_LSDEV;
  2330. if ((devctl & mask) != (musb->context.devctl & mask))
  2331. musb->port1_status = 0;
  2332. if (musb->need_finish_resume) {
  2333. musb->need_finish_resume = 0;
  2334. schedule_delayed_work(&musb->finish_resume_work,
  2335. msecs_to_jiffies(USB_RESUME_TIMEOUT));
  2336. }
  2337. /*
  2338. * The USB HUB code expects the device to be in RPM_ACTIVE once it came
  2339. * out of suspend
  2340. */
  2341. pm_runtime_disable(dev);
  2342. pm_runtime_set_active(dev);
  2343. pm_runtime_enable(dev);
  2344. musb_start(musb);
  2345. spin_lock_irqsave(&musb->lock, flags);
  2346. error = musb_run_resume_work(musb);
  2347. if (error)
  2348. dev_err(musb->controller, "resume work failed with %i\n",
  2349. error);
  2350. spin_unlock_irqrestore(&musb->lock, flags);
  2351. return 0;
  2352. }
  2353. static int musb_runtime_suspend(struct device *dev)
  2354. {
  2355. struct musb *musb = dev_to_musb(dev);
  2356. musb_save_context(musb);
  2357. musb->is_runtime_suspended = 1;
  2358. return 0;
  2359. }
  2360. static int musb_runtime_resume(struct device *dev)
  2361. {
  2362. struct musb *musb = dev_to_musb(dev);
  2363. unsigned long flags;
  2364. int error;
  2365. /*
  2366. * When pm_runtime_get_sync called for the first time in driver
  2367. * init, some of the structure is still not initialized which is
  2368. * used in restore function. But clock needs to be
  2369. * enabled before any register access, so
  2370. * pm_runtime_get_sync has to be called.
  2371. * Also context restore without save does not make
  2372. * any sense
  2373. */
  2374. if (!musb->is_initialized)
  2375. return 0;
  2376. musb_restore_context(musb);
  2377. if (musb->need_finish_resume) {
  2378. musb->need_finish_resume = 0;
  2379. schedule_delayed_work(&musb->finish_resume_work,
  2380. msecs_to_jiffies(USB_RESUME_TIMEOUT));
  2381. }
  2382. spin_lock_irqsave(&musb->lock, flags);
  2383. error = musb_run_resume_work(musb);
  2384. if (error)
  2385. dev_err(musb->controller, "resume work failed with %i\n",
  2386. error);
  2387. musb->is_runtime_suspended = 0;
  2388. spin_unlock_irqrestore(&musb->lock, flags);
  2389. return 0;
  2390. }
  2391. static const struct dev_pm_ops musb_dev_pm_ops = {
  2392. .suspend = musb_suspend,
  2393. .resume = musb_resume,
  2394. .runtime_suspend = musb_runtime_suspend,
  2395. .runtime_resume = musb_runtime_resume,
  2396. };
  2397. #define MUSB_DEV_PM_OPS (&musb_dev_pm_ops)
  2398. #else
  2399. #define MUSB_DEV_PM_OPS NULL
  2400. #endif
  2401. static struct platform_driver musb_driver = {
  2402. .driver = {
  2403. .name = (char *)musb_driver_name,
  2404. .bus = &platform_bus_type,
  2405. .pm = MUSB_DEV_PM_OPS,
  2406. },
  2407. .probe = musb_probe,
  2408. .remove = musb_remove,
  2409. };
  2410. module_platform_driver(musb_driver);