musb_core.c 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809
  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 = 960, },
  1015. { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 1024, },
  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. if (musb->io.quirks & MUSB_G_NO_SKB_RESERVE)
  1925. musb->g.quirk_avoids_skb_reserve = 1;
  1926. /* At least tusb6010 has its own offsets */
  1927. if (musb->ops->ep_offset)
  1928. musb->io.ep_offset = musb->ops->ep_offset;
  1929. if (musb->ops->ep_select)
  1930. musb->io.ep_select = musb->ops->ep_select;
  1931. if (musb->ops->fifo_mode)
  1932. fifo_mode = musb->ops->fifo_mode;
  1933. else
  1934. fifo_mode = 4;
  1935. if (musb->ops->fifo_offset)
  1936. musb->io.fifo_offset = musb->ops->fifo_offset;
  1937. else
  1938. musb->io.fifo_offset = musb_default_fifo_offset;
  1939. if (musb->ops->busctl_offset)
  1940. musb->io.busctl_offset = musb->ops->busctl_offset;
  1941. else
  1942. musb->io.busctl_offset = musb_default_busctl_offset;
  1943. if (musb->ops->readb)
  1944. musb_readb = musb->ops->readb;
  1945. if (musb->ops->writeb)
  1946. musb_writeb = musb->ops->writeb;
  1947. if (musb->ops->readw)
  1948. musb_readw = musb->ops->readw;
  1949. if (musb->ops->writew)
  1950. musb_writew = musb->ops->writew;
  1951. if (musb->ops->readl)
  1952. musb_readl = musb->ops->readl;
  1953. if (musb->ops->writel)
  1954. musb_writel = musb->ops->writel;
  1955. #ifndef CONFIG_MUSB_PIO_ONLY
  1956. if (!musb->ops->dma_init || !musb->ops->dma_exit) {
  1957. dev_err(dev, "DMA controller not set\n");
  1958. status = -ENODEV;
  1959. goto fail2;
  1960. }
  1961. musb_dma_controller_create = musb->ops->dma_init;
  1962. musb_dma_controller_destroy = musb->ops->dma_exit;
  1963. #endif
  1964. if (musb->ops->read_fifo)
  1965. musb->io.read_fifo = musb->ops->read_fifo;
  1966. else
  1967. musb->io.read_fifo = musb_default_read_fifo;
  1968. if (musb->ops->write_fifo)
  1969. musb->io.write_fifo = musb->ops->write_fifo;
  1970. else
  1971. musb->io.write_fifo = musb_default_write_fifo;
  1972. if (!musb->xceiv->io_ops) {
  1973. musb->xceiv->io_dev = musb->controller;
  1974. musb->xceiv->io_priv = musb->mregs;
  1975. musb->xceiv->io_ops = &musb_ulpi_access;
  1976. }
  1977. if (musb->ops->phy_callback)
  1978. musb_phy_callback = musb->ops->phy_callback;
  1979. /*
  1980. * We need musb_read/write functions initialized for PM.
  1981. * Note that at least 2430 glue needs autosuspend delay
  1982. * somewhere above 300 ms for the hardware to idle properly
  1983. * after disconnecting the cable in host mode. Let's use
  1984. * 500 ms for some margin.
  1985. */
  1986. pm_runtime_use_autosuspend(musb->controller);
  1987. pm_runtime_set_autosuspend_delay(musb->controller, 500);
  1988. pm_runtime_enable(musb->controller);
  1989. pm_runtime_get_sync(musb->controller);
  1990. status = usb_phy_init(musb->xceiv);
  1991. if (status < 0)
  1992. goto err_usb_phy_init;
  1993. if (use_dma && dev->dma_mask) {
  1994. musb->dma_controller =
  1995. musb_dma_controller_create(musb, musb->mregs);
  1996. if (IS_ERR(musb->dma_controller)) {
  1997. status = PTR_ERR(musb->dma_controller);
  1998. goto fail2_5;
  1999. }
  2000. }
  2001. /* be sure interrupts are disabled before connecting ISR */
  2002. musb_platform_disable(musb);
  2003. musb_disable_interrupts(musb);
  2004. musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
  2005. /* Init IRQ workqueue before request_irq */
  2006. INIT_DELAYED_WORK(&musb->irq_work, musb_irq_work);
  2007. INIT_DELAYED_WORK(&musb->deassert_reset_work, musb_deassert_reset);
  2008. INIT_DELAYED_WORK(&musb->finish_resume_work, musb_host_finish_resume);
  2009. /* setup musb parts of the core (especially endpoints) */
  2010. status = musb_core_init(plat->config->multipoint
  2011. ? MUSB_CONTROLLER_MHDRC
  2012. : MUSB_CONTROLLER_HDRC, musb);
  2013. if (status < 0)
  2014. goto fail3;
  2015. setup_timer(&musb->otg_timer, musb_otg_timer_func, (unsigned long) musb);
  2016. /* attach to the IRQ */
  2017. if (request_irq(nIrq, musb->isr, IRQF_SHARED, dev_name(dev), musb)) {
  2018. dev_err(dev, "request_irq %d failed!\n", nIrq);
  2019. status = -ENODEV;
  2020. goto fail3;
  2021. }
  2022. musb->nIrq = nIrq;
  2023. /* FIXME this handles wakeup irqs wrong */
  2024. if (enable_irq_wake(nIrq) == 0) {
  2025. musb->irq_wake = 1;
  2026. device_init_wakeup(dev, 1);
  2027. } else {
  2028. musb->irq_wake = 0;
  2029. }
  2030. /* program PHY to use external vBus if required */
  2031. if (plat->extvbus) {
  2032. u8 busctl = musb_read_ulpi_buscontrol(musb->mregs);
  2033. busctl |= MUSB_ULPI_USE_EXTVBUS;
  2034. musb_write_ulpi_buscontrol(musb->mregs, busctl);
  2035. }
  2036. if (musb->xceiv->otg->default_a) {
  2037. MUSB_HST_MODE(musb);
  2038. musb->xceiv->otg->state = OTG_STATE_A_IDLE;
  2039. } else {
  2040. MUSB_DEV_MODE(musb);
  2041. musb->xceiv->otg->state = OTG_STATE_B_IDLE;
  2042. }
  2043. switch (musb->port_mode) {
  2044. case MUSB_PORT_MODE_HOST:
  2045. status = musb_host_setup(musb, plat->power);
  2046. if (status < 0)
  2047. goto fail3;
  2048. status = musb_platform_set_mode(musb, MUSB_HOST);
  2049. break;
  2050. case MUSB_PORT_MODE_GADGET:
  2051. status = musb_gadget_setup(musb);
  2052. if (status < 0)
  2053. goto fail3;
  2054. status = musb_platform_set_mode(musb, MUSB_PERIPHERAL);
  2055. break;
  2056. case MUSB_PORT_MODE_DUAL_ROLE:
  2057. status = musb_host_setup(musb, plat->power);
  2058. if (status < 0)
  2059. goto fail3;
  2060. status = musb_gadget_setup(musb);
  2061. if (status) {
  2062. musb_host_cleanup(musb);
  2063. goto fail3;
  2064. }
  2065. status = musb_platform_set_mode(musb, MUSB_OTG);
  2066. break;
  2067. default:
  2068. dev_err(dev, "unsupported port mode %d\n", musb->port_mode);
  2069. break;
  2070. }
  2071. if (status < 0)
  2072. goto fail3;
  2073. status = musb_init_debugfs(musb);
  2074. if (status < 0)
  2075. goto fail4;
  2076. status = sysfs_create_group(&musb->controller->kobj, &musb_attr_group);
  2077. if (status)
  2078. goto fail5;
  2079. musb->is_initialized = 1;
  2080. pm_runtime_mark_last_busy(musb->controller);
  2081. pm_runtime_put_autosuspend(musb->controller);
  2082. return 0;
  2083. fail5:
  2084. musb_exit_debugfs(musb);
  2085. fail4:
  2086. musb_gadget_cleanup(musb);
  2087. musb_host_cleanup(musb);
  2088. fail3:
  2089. cancel_delayed_work_sync(&musb->irq_work);
  2090. cancel_delayed_work_sync(&musb->finish_resume_work);
  2091. cancel_delayed_work_sync(&musb->deassert_reset_work);
  2092. if (musb->dma_controller)
  2093. musb_dma_controller_destroy(musb->dma_controller);
  2094. fail2_5:
  2095. usb_phy_shutdown(musb->xceiv);
  2096. err_usb_phy_init:
  2097. pm_runtime_dont_use_autosuspend(musb->controller);
  2098. pm_runtime_put_sync(musb->controller);
  2099. pm_runtime_disable(musb->controller);
  2100. fail2:
  2101. if (musb->irq_wake)
  2102. device_init_wakeup(dev, 0);
  2103. musb_platform_exit(musb);
  2104. fail1:
  2105. if (status != -EPROBE_DEFER)
  2106. dev_err(musb->controller,
  2107. "%s failed with status %d\n", __func__, status);
  2108. musb_free(musb);
  2109. fail0:
  2110. return status;
  2111. }
  2112. /*-------------------------------------------------------------------------*/
  2113. /* all implementations (PCI bridge to FPGA, VLYNQ, etc) should just
  2114. * bridge to a platform device; this driver then suffices.
  2115. */
  2116. static int musb_probe(struct platform_device *pdev)
  2117. {
  2118. struct device *dev = &pdev->dev;
  2119. int irq = platform_get_irq_byname(pdev, "mc");
  2120. struct resource *iomem;
  2121. void __iomem *base;
  2122. if (irq <= 0)
  2123. return -ENODEV;
  2124. iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  2125. base = devm_ioremap_resource(dev, iomem);
  2126. if (IS_ERR(base))
  2127. return PTR_ERR(base);
  2128. return musb_init_controller(dev, irq, base);
  2129. }
  2130. static int musb_remove(struct platform_device *pdev)
  2131. {
  2132. struct device *dev = &pdev->dev;
  2133. struct musb *musb = dev_to_musb(dev);
  2134. unsigned long flags;
  2135. /* this gets called on rmmod.
  2136. * - Host mode: host may still be active
  2137. * - Peripheral mode: peripheral is deactivated (or never-activated)
  2138. * - OTG mode: both roles are deactivated (or never-activated)
  2139. */
  2140. musb_exit_debugfs(musb);
  2141. cancel_delayed_work_sync(&musb->irq_work);
  2142. cancel_delayed_work_sync(&musb->finish_resume_work);
  2143. cancel_delayed_work_sync(&musb->deassert_reset_work);
  2144. pm_runtime_get_sync(musb->controller);
  2145. musb_host_cleanup(musb);
  2146. musb_gadget_cleanup(musb);
  2147. musb_platform_disable(musb);
  2148. spin_lock_irqsave(&musb->lock, flags);
  2149. musb_disable_interrupts(musb);
  2150. musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
  2151. spin_unlock_irqrestore(&musb->lock, flags);
  2152. pm_runtime_dont_use_autosuspend(musb->controller);
  2153. pm_runtime_put_sync(musb->controller);
  2154. pm_runtime_disable(musb->controller);
  2155. musb_platform_exit(musb);
  2156. musb_phy_callback = NULL;
  2157. if (musb->dma_controller)
  2158. musb_dma_controller_destroy(musb->dma_controller);
  2159. usb_phy_shutdown(musb->xceiv);
  2160. musb_free(musb);
  2161. device_init_wakeup(dev, 0);
  2162. return 0;
  2163. }
  2164. #ifdef CONFIG_PM
  2165. static void musb_save_context(struct musb *musb)
  2166. {
  2167. int i;
  2168. void __iomem *musb_base = musb->mregs;
  2169. void __iomem *epio;
  2170. musb->context.frame = musb_readw(musb_base, MUSB_FRAME);
  2171. musb->context.testmode = musb_readb(musb_base, MUSB_TESTMODE);
  2172. musb->context.busctl = musb_read_ulpi_buscontrol(musb->mregs);
  2173. musb->context.power = musb_readb(musb_base, MUSB_POWER);
  2174. musb->context.intrusbe = musb_readb(musb_base, MUSB_INTRUSBE);
  2175. musb->context.index = musb_readb(musb_base, MUSB_INDEX);
  2176. musb->context.devctl = musb_readb(musb_base, MUSB_DEVCTL);
  2177. for (i = 0; i < musb->config->num_eps; ++i) {
  2178. struct musb_hw_ep *hw_ep;
  2179. hw_ep = &musb->endpoints[i];
  2180. if (!hw_ep)
  2181. continue;
  2182. epio = hw_ep->regs;
  2183. if (!epio)
  2184. continue;
  2185. musb_writeb(musb_base, MUSB_INDEX, i);
  2186. musb->context.index_regs[i].txmaxp =
  2187. musb_readw(epio, MUSB_TXMAXP);
  2188. musb->context.index_regs[i].txcsr =
  2189. musb_readw(epio, MUSB_TXCSR);
  2190. musb->context.index_regs[i].rxmaxp =
  2191. musb_readw(epio, MUSB_RXMAXP);
  2192. musb->context.index_regs[i].rxcsr =
  2193. musb_readw(epio, MUSB_RXCSR);
  2194. if (musb->dyn_fifo) {
  2195. musb->context.index_regs[i].txfifoadd =
  2196. musb_read_txfifoadd(musb_base);
  2197. musb->context.index_regs[i].rxfifoadd =
  2198. musb_read_rxfifoadd(musb_base);
  2199. musb->context.index_regs[i].txfifosz =
  2200. musb_read_txfifosz(musb_base);
  2201. musb->context.index_regs[i].rxfifosz =
  2202. musb_read_rxfifosz(musb_base);
  2203. }
  2204. musb->context.index_regs[i].txtype =
  2205. musb_readb(epio, MUSB_TXTYPE);
  2206. musb->context.index_regs[i].txinterval =
  2207. musb_readb(epio, MUSB_TXINTERVAL);
  2208. musb->context.index_regs[i].rxtype =
  2209. musb_readb(epio, MUSB_RXTYPE);
  2210. musb->context.index_regs[i].rxinterval =
  2211. musb_readb(epio, MUSB_RXINTERVAL);
  2212. musb->context.index_regs[i].txfunaddr =
  2213. musb_read_txfunaddr(musb, i);
  2214. musb->context.index_regs[i].txhubaddr =
  2215. musb_read_txhubaddr(musb, i);
  2216. musb->context.index_regs[i].txhubport =
  2217. musb_read_txhubport(musb, i);
  2218. musb->context.index_regs[i].rxfunaddr =
  2219. musb_read_rxfunaddr(musb, i);
  2220. musb->context.index_regs[i].rxhubaddr =
  2221. musb_read_rxhubaddr(musb, i);
  2222. musb->context.index_regs[i].rxhubport =
  2223. musb_read_rxhubport(musb, i);
  2224. }
  2225. }
  2226. static void musb_restore_context(struct musb *musb)
  2227. {
  2228. int i;
  2229. void __iomem *musb_base = musb->mregs;
  2230. void __iomem *epio;
  2231. u8 power;
  2232. musb_writew(musb_base, MUSB_FRAME, musb->context.frame);
  2233. musb_writeb(musb_base, MUSB_TESTMODE, musb->context.testmode);
  2234. musb_write_ulpi_buscontrol(musb->mregs, musb->context.busctl);
  2235. /* Don't affect SUSPENDM/RESUME bits in POWER reg */
  2236. power = musb_readb(musb_base, MUSB_POWER);
  2237. power &= MUSB_POWER_SUSPENDM | MUSB_POWER_RESUME;
  2238. musb->context.power &= ~(MUSB_POWER_SUSPENDM | MUSB_POWER_RESUME);
  2239. power |= musb->context.power;
  2240. musb_writeb(musb_base, MUSB_POWER, power);
  2241. musb_writew(musb_base, MUSB_INTRTXE, musb->intrtxe);
  2242. musb_writew(musb_base, MUSB_INTRRXE, musb->intrrxe);
  2243. musb_writeb(musb_base, MUSB_INTRUSBE, musb->context.intrusbe);
  2244. if (musb->context.devctl & MUSB_DEVCTL_SESSION)
  2245. musb_writeb(musb_base, MUSB_DEVCTL, musb->context.devctl);
  2246. for (i = 0; i < musb->config->num_eps; ++i) {
  2247. struct musb_hw_ep *hw_ep;
  2248. hw_ep = &musb->endpoints[i];
  2249. if (!hw_ep)
  2250. continue;
  2251. epio = hw_ep->regs;
  2252. if (!epio)
  2253. continue;
  2254. musb_writeb(musb_base, MUSB_INDEX, i);
  2255. musb_writew(epio, MUSB_TXMAXP,
  2256. musb->context.index_regs[i].txmaxp);
  2257. musb_writew(epio, MUSB_TXCSR,
  2258. musb->context.index_regs[i].txcsr);
  2259. musb_writew(epio, MUSB_RXMAXP,
  2260. musb->context.index_regs[i].rxmaxp);
  2261. musb_writew(epio, MUSB_RXCSR,
  2262. musb->context.index_regs[i].rxcsr);
  2263. if (musb->dyn_fifo) {
  2264. musb_write_txfifosz(musb_base,
  2265. musb->context.index_regs[i].txfifosz);
  2266. musb_write_rxfifosz(musb_base,
  2267. musb->context.index_regs[i].rxfifosz);
  2268. musb_write_txfifoadd(musb_base,
  2269. musb->context.index_regs[i].txfifoadd);
  2270. musb_write_rxfifoadd(musb_base,
  2271. musb->context.index_regs[i].rxfifoadd);
  2272. }
  2273. musb_writeb(epio, MUSB_TXTYPE,
  2274. musb->context.index_regs[i].txtype);
  2275. musb_writeb(epio, MUSB_TXINTERVAL,
  2276. musb->context.index_regs[i].txinterval);
  2277. musb_writeb(epio, MUSB_RXTYPE,
  2278. musb->context.index_regs[i].rxtype);
  2279. musb_writeb(epio, MUSB_RXINTERVAL,
  2280. musb->context.index_regs[i].rxinterval);
  2281. musb_write_txfunaddr(musb, i,
  2282. musb->context.index_regs[i].txfunaddr);
  2283. musb_write_txhubaddr(musb, i,
  2284. musb->context.index_regs[i].txhubaddr);
  2285. musb_write_txhubport(musb, i,
  2286. musb->context.index_regs[i].txhubport);
  2287. musb_write_rxfunaddr(musb, i,
  2288. musb->context.index_regs[i].rxfunaddr);
  2289. musb_write_rxhubaddr(musb, i,
  2290. musb->context.index_regs[i].rxhubaddr);
  2291. musb_write_rxhubport(musb, i,
  2292. musb->context.index_regs[i].rxhubport);
  2293. }
  2294. musb_writeb(musb_base, MUSB_INDEX, musb->context.index);
  2295. }
  2296. static int musb_suspend(struct device *dev)
  2297. {
  2298. struct musb *musb = dev_to_musb(dev);
  2299. unsigned long flags;
  2300. int ret;
  2301. ret = pm_runtime_get_sync(dev);
  2302. if (ret < 0) {
  2303. pm_runtime_put_noidle(dev);
  2304. return ret;
  2305. }
  2306. musb_platform_disable(musb);
  2307. musb_disable_interrupts(musb);
  2308. if (!(musb->io.quirks & MUSB_PRESERVE_SESSION))
  2309. musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
  2310. WARN_ON(!list_empty(&musb->pending_list));
  2311. spin_lock_irqsave(&musb->lock, flags);
  2312. if (is_peripheral_active(musb)) {
  2313. /* FIXME force disconnect unless we know USB will wake
  2314. * the system up quickly enough to respond ...
  2315. */
  2316. } else if (is_host_active(musb)) {
  2317. /* we know all the children are suspended; sometimes
  2318. * they will even be wakeup-enabled.
  2319. */
  2320. }
  2321. musb_save_context(musb);
  2322. spin_unlock_irqrestore(&musb->lock, flags);
  2323. return 0;
  2324. }
  2325. static int musb_resume(struct device *dev)
  2326. {
  2327. struct musb *musb = dev_to_musb(dev);
  2328. unsigned long flags;
  2329. int error;
  2330. u8 devctl;
  2331. u8 mask;
  2332. /*
  2333. * For static cmos like DaVinci, register values were preserved
  2334. * unless for some reason the whole soc powered down or the USB
  2335. * module got reset through the PSC (vs just being disabled).
  2336. *
  2337. * For the DSPS glue layer though, a full register restore has to
  2338. * be done. As it shouldn't harm other platforms, we do it
  2339. * unconditionally.
  2340. */
  2341. musb_restore_context(musb);
  2342. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  2343. mask = MUSB_DEVCTL_BDEVICE | MUSB_DEVCTL_FSDEV | MUSB_DEVCTL_LSDEV;
  2344. if ((devctl & mask) != (musb->context.devctl & mask))
  2345. musb->port1_status = 0;
  2346. musb_start(musb);
  2347. spin_lock_irqsave(&musb->lock, flags);
  2348. error = musb_run_resume_work(musb);
  2349. if (error)
  2350. dev_err(musb->controller, "resume work failed with %i\n",
  2351. error);
  2352. spin_unlock_irqrestore(&musb->lock, flags);
  2353. pm_runtime_mark_last_busy(dev);
  2354. pm_runtime_put_autosuspend(dev);
  2355. return 0;
  2356. }
  2357. static int musb_runtime_suspend(struct device *dev)
  2358. {
  2359. struct musb *musb = dev_to_musb(dev);
  2360. musb_save_context(musb);
  2361. musb->is_runtime_suspended = 1;
  2362. return 0;
  2363. }
  2364. static int musb_runtime_resume(struct device *dev)
  2365. {
  2366. struct musb *musb = dev_to_musb(dev);
  2367. unsigned long flags;
  2368. int error;
  2369. /*
  2370. * When pm_runtime_get_sync called for the first time in driver
  2371. * init, some of the structure is still not initialized which is
  2372. * used in restore function. But clock needs to be
  2373. * enabled before any register access, so
  2374. * pm_runtime_get_sync has to be called.
  2375. * Also context restore without save does not make
  2376. * any sense
  2377. */
  2378. if (!musb->is_initialized)
  2379. return 0;
  2380. musb_restore_context(musb);
  2381. spin_lock_irqsave(&musb->lock, flags);
  2382. error = musb_run_resume_work(musb);
  2383. if (error)
  2384. dev_err(musb->controller, "resume work failed with %i\n",
  2385. error);
  2386. musb->is_runtime_suspended = 0;
  2387. spin_unlock_irqrestore(&musb->lock, flags);
  2388. return 0;
  2389. }
  2390. static const struct dev_pm_ops musb_dev_pm_ops = {
  2391. .suspend = musb_suspend,
  2392. .resume = musb_resume,
  2393. .runtime_suspend = musb_runtime_suspend,
  2394. .runtime_resume = musb_runtime_resume,
  2395. };
  2396. #define MUSB_DEV_PM_OPS (&musb_dev_pm_ops)
  2397. #else
  2398. #define MUSB_DEV_PM_OPS NULL
  2399. #endif
  2400. static struct platform_driver musb_driver = {
  2401. .driver = {
  2402. .name = (char *)musb_driver_name,
  2403. .bus = &platform_bus_type,
  2404. .pm = MUSB_DEV_PM_OPS,
  2405. },
  2406. .probe = musb_probe,
  2407. .remove = musb_remove,
  2408. };
  2409. module_platform_driver(musb_driver);