musb_core.c 76 KB

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