musb_core.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257
  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 informarion
  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/init.h>
  94. #include <linux/list.h>
  95. #include <linux/kobject.h>
  96. #include <linux/platform_device.h>
  97. #include <linux/io.h>
  98. #ifdef CONFIG_ARM
  99. #include <mach/hardware.h>
  100. #include <mach/memory.h>
  101. #include <asm/mach-types.h>
  102. #endif
  103. #include "musb_core.h"
  104. #ifdef CONFIG_ARCH_DAVINCI
  105. #include "davinci.h"
  106. #endif
  107. #define TA_WAIT_BCON(m) max_t(int, (m)->a_wait_bcon, OTG_TIME_A_WAIT_BCON)
  108. unsigned musb_debug;
  109. module_param_named(debug, musb_debug, uint, S_IRUGO | S_IWUSR);
  110. MODULE_PARM_DESC(debug, "Debug message level. Default = 0");
  111. #define DRIVER_AUTHOR "Mentor Graphics, Texas Instruments, Nokia"
  112. #define DRIVER_DESC "Inventra Dual-Role USB Controller Driver"
  113. #define MUSB_VERSION "6.0"
  114. #define DRIVER_INFO DRIVER_DESC ", v" MUSB_VERSION
  115. #define MUSB_DRIVER_NAME "musb_hdrc"
  116. const char musb_driver_name[] = MUSB_DRIVER_NAME;
  117. MODULE_DESCRIPTION(DRIVER_INFO);
  118. MODULE_AUTHOR(DRIVER_AUTHOR);
  119. MODULE_LICENSE("GPL");
  120. MODULE_ALIAS("platform:" MUSB_DRIVER_NAME);
  121. /*-------------------------------------------------------------------------*/
  122. static inline struct musb *dev_to_musb(struct device *dev)
  123. {
  124. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  125. /* usbcore insists dev->driver_data is a "struct hcd *" */
  126. return hcd_to_musb(dev_get_drvdata(dev));
  127. #else
  128. return dev_get_drvdata(dev);
  129. #endif
  130. }
  131. /*-------------------------------------------------------------------------*/
  132. #if !defined(CONFIG_USB_TUSB6010) && !defined(CONFIG_BLACKFIN)
  133. /*
  134. * Load an endpoint's FIFO
  135. */
  136. void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src)
  137. {
  138. void __iomem *fifo = hw_ep->fifo;
  139. prefetch((u8 *)src);
  140. DBG(4, "%cX ep%d fifo %p count %d buf %p\n",
  141. 'T', hw_ep->epnum, fifo, len, src);
  142. /* we can't assume unaligned reads work */
  143. if (likely((0x01 & (unsigned long) src) == 0)) {
  144. u16 index = 0;
  145. /* best case is 32bit-aligned source address */
  146. if ((0x02 & (unsigned long) src) == 0) {
  147. if (len >= 4) {
  148. writesl(fifo, src + index, len >> 2);
  149. index += len & ~0x03;
  150. }
  151. if (len & 0x02) {
  152. musb_writew(fifo, 0, *(u16 *)&src[index]);
  153. index += 2;
  154. }
  155. } else {
  156. if (len >= 2) {
  157. writesw(fifo, src + index, len >> 1);
  158. index += len & ~0x01;
  159. }
  160. }
  161. if (len & 0x01)
  162. musb_writeb(fifo, 0, src[index]);
  163. } else {
  164. /* byte aligned */
  165. writesb(fifo, src, len);
  166. }
  167. }
  168. /*
  169. * Unload an endpoint's FIFO
  170. */
  171. void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
  172. {
  173. void __iomem *fifo = hw_ep->fifo;
  174. DBG(4, "%cX ep%d fifo %p count %d buf %p\n",
  175. 'R', hw_ep->epnum, fifo, len, dst);
  176. /* we can't assume unaligned writes work */
  177. if (likely((0x01 & (unsigned long) dst) == 0)) {
  178. u16 index = 0;
  179. /* best case is 32bit-aligned destination address */
  180. if ((0x02 & (unsigned long) dst) == 0) {
  181. if (len >= 4) {
  182. readsl(fifo, dst, len >> 2);
  183. index = len & ~0x03;
  184. }
  185. if (len & 0x02) {
  186. *(u16 *)&dst[index] = musb_readw(fifo, 0);
  187. index += 2;
  188. }
  189. } else {
  190. if (len >= 2) {
  191. readsw(fifo, dst, len >> 1);
  192. index = len & ~0x01;
  193. }
  194. }
  195. if (len & 0x01)
  196. dst[index] = musb_readb(fifo, 0);
  197. } else {
  198. /* byte aligned */
  199. readsb(fifo, dst, len);
  200. }
  201. }
  202. #endif /* normal PIO */
  203. /*-------------------------------------------------------------------------*/
  204. /* for high speed test mode; see USB 2.0 spec 7.1.20 */
  205. static const u8 musb_test_packet[53] = {
  206. /* implicit SYNC then DATA0 to start */
  207. /* JKJKJKJK x9 */
  208. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  209. /* JJKKJJKK x8 */
  210. 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
  211. /* JJJJKKKK x8 */
  212. 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee,
  213. /* JJJJJJJKKKKKKK x8 */
  214. 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  215. /* JJJJJJJK x8 */
  216. 0x7f, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd,
  217. /* JKKKKKKK x10, JK */
  218. 0xfc, 0x7e, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0x7e
  219. /* implicit CRC16 then EOP to end */
  220. };
  221. void musb_load_testpacket(struct musb *musb)
  222. {
  223. void __iomem *regs = musb->endpoints[0].regs;
  224. musb_ep_select(musb->mregs, 0);
  225. musb_write_fifo(musb->control_ep,
  226. sizeof(musb_test_packet), musb_test_packet);
  227. musb_writew(regs, MUSB_CSR0, MUSB_CSR0_TXPKTRDY);
  228. }
  229. /*-------------------------------------------------------------------------*/
  230. const char *otg_state_string(struct musb *musb)
  231. {
  232. switch (musb->xceiv->state) {
  233. case OTG_STATE_A_IDLE: return "a_idle";
  234. case OTG_STATE_A_WAIT_VRISE: return "a_wait_vrise";
  235. case OTG_STATE_A_WAIT_BCON: return "a_wait_bcon";
  236. case OTG_STATE_A_HOST: return "a_host";
  237. case OTG_STATE_A_SUSPEND: return "a_suspend";
  238. case OTG_STATE_A_PERIPHERAL: return "a_peripheral";
  239. case OTG_STATE_A_WAIT_VFALL: return "a_wait_vfall";
  240. case OTG_STATE_A_VBUS_ERR: return "a_vbus_err";
  241. case OTG_STATE_B_IDLE: return "b_idle";
  242. case OTG_STATE_B_SRP_INIT: return "b_srp_init";
  243. case OTG_STATE_B_PERIPHERAL: return "b_peripheral";
  244. case OTG_STATE_B_WAIT_ACON: return "b_wait_acon";
  245. case OTG_STATE_B_HOST: return "b_host";
  246. default: return "UNDEFINED";
  247. }
  248. }
  249. #ifdef CONFIG_USB_MUSB_OTG
  250. /*
  251. * Handles OTG hnp timeouts, such as b_ase0_brst
  252. */
  253. void musb_otg_timer_func(unsigned long data)
  254. {
  255. struct musb *musb = (struct musb *)data;
  256. unsigned long flags;
  257. spin_lock_irqsave(&musb->lock, flags);
  258. switch (musb->xceiv->state) {
  259. case OTG_STATE_B_WAIT_ACON:
  260. DBG(1, "HNP: b_wait_acon timeout; back to b_peripheral\n");
  261. musb_g_disconnect(musb);
  262. musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
  263. musb->is_active = 0;
  264. break;
  265. case OTG_STATE_A_WAIT_BCON:
  266. DBG(1, "HNP: a_wait_bcon timeout; back to a_host\n");
  267. musb_hnp_stop(musb);
  268. break;
  269. default:
  270. DBG(1, "HNP: Unhandled mode %s\n", otg_state_string(musb));
  271. }
  272. musb->ignore_disconnect = 0;
  273. spin_unlock_irqrestore(&musb->lock, flags);
  274. }
  275. /*
  276. * Stops the HNP transition. Caller must take care of locking.
  277. */
  278. void musb_hnp_stop(struct musb *musb)
  279. {
  280. struct usb_hcd *hcd = musb_to_hcd(musb);
  281. void __iomem *mbase = musb->mregs;
  282. u8 reg;
  283. switch (musb->xceiv->state) {
  284. case OTG_STATE_A_PERIPHERAL:
  285. case OTG_STATE_A_WAIT_VFALL:
  286. case OTG_STATE_A_WAIT_BCON:
  287. DBG(1, "HNP: Switching back to A-host\n");
  288. musb_g_disconnect(musb);
  289. musb->xceiv->state = OTG_STATE_A_IDLE;
  290. MUSB_HST_MODE(musb);
  291. musb->is_active = 0;
  292. break;
  293. case OTG_STATE_B_HOST:
  294. DBG(1, "HNP: Disabling HR\n");
  295. hcd->self.is_b_host = 0;
  296. musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
  297. MUSB_DEV_MODE(musb);
  298. reg = musb_readb(mbase, MUSB_POWER);
  299. reg |= MUSB_POWER_SUSPENDM;
  300. musb_writeb(mbase, MUSB_POWER, reg);
  301. /* REVISIT: Start SESSION_REQUEST here? */
  302. break;
  303. default:
  304. DBG(1, "HNP: Stopping in unknown state %s\n",
  305. otg_state_string(musb));
  306. }
  307. /*
  308. * When returning to A state after HNP, avoid hub_port_rebounce(),
  309. * which cause occasional OPT A "Did not receive reset after connect"
  310. * errors.
  311. */
  312. musb->port1_status &=
  313. ~(1 << USB_PORT_FEAT_C_CONNECTION);
  314. }
  315. #endif
  316. /*
  317. * Interrupt Service Routine to record USB "global" interrupts.
  318. * Since these do not happen often and signify things of
  319. * paramount importance, it seems OK to check them individually;
  320. * the order of the tests is specified in the manual
  321. *
  322. * @param musb instance pointer
  323. * @param int_usb register contents
  324. * @param devctl
  325. * @param power
  326. */
  327. #define STAGE0_MASK (MUSB_INTR_RESUME | MUSB_INTR_SESSREQ \
  328. | MUSB_INTR_VBUSERROR | MUSB_INTR_CONNECT \
  329. | MUSB_INTR_RESET)
  330. static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
  331. u8 devctl, u8 power)
  332. {
  333. irqreturn_t handled = IRQ_NONE;
  334. void __iomem *mbase = musb->mregs;
  335. DBG(3, "<== Power=%02x, DevCtl=%02x, int_usb=0x%x\n", power, devctl,
  336. int_usb);
  337. /* in host mode, the peripheral may issue remote wakeup.
  338. * in peripheral mode, the host may resume the link.
  339. * spurious RESUME irqs happen too, paired with SUSPEND.
  340. */
  341. if (int_usb & MUSB_INTR_RESUME) {
  342. handled = IRQ_HANDLED;
  343. DBG(3, "RESUME (%s)\n", otg_state_string(musb));
  344. if (devctl & MUSB_DEVCTL_HM) {
  345. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  346. switch (musb->xceiv->state) {
  347. case OTG_STATE_A_SUSPEND:
  348. /* remote wakeup? later, GetPortStatus
  349. * will stop RESUME signaling
  350. */
  351. if (power & MUSB_POWER_SUSPENDM) {
  352. /* spurious */
  353. musb->int_usb &= ~MUSB_INTR_SUSPEND;
  354. DBG(2, "Spurious SUSPENDM\n");
  355. break;
  356. }
  357. power &= ~MUSB_POWER_SUSPENDM;
  358. musb_writeb(mbase, MUSB_POWER,
  359. power | MUSB_POWER_RESUME);
  360. musb->port1_status |=
  361. (USB_PORT_STAT_C_SUSPEND << 16)
  362. | MUSB_PORT_STAT_RESUME;
  363. musb->rh_timer = jiffies
  364. + msecs_to_jiffies(20);
  365. musb->xceiv->state = OTG_STATE_A_HOST;
  366. musb->is_active = 1;
  367. usb_hcd_resume_root_hub(musb_to_hcd(musb));
  368. break;
  369. case OTG_STATE_B_WAIT_ACON:
  370. musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
  371. musb->is_active = 1;
  372. MUSB_DEV_MODE(musb);
  373. break;
  374. default:
  375. WARNING("bogus %s RESUME (%s)\n",
  376. "host",
  377. otg_state_string(musb));
  378. }
  379. #endif
  380. } else {
  381. switch (musb->xceiv->state) {
  382. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  383. case OTG_STATE_A_SUSPEND:
  384. /* possibly DISCONNECT is upcoming */
  385. musb->xceiv->state = OTG_STATE_A_HOST;
  386. usb_hcd_resume_root_hub(musb_to_hcd(musb));
  387. break;
  388. #endif
  389. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  390. case OTG_STATE_B_WAIT_ACON:
  391. case OTG_STATE_B_PERIPHERAL:
  392. /* disconnect while suspended? we may
  393. * not get a disconnect irq...
  394. */
  395. if ((devctl & MUSB_DEVCTL_VBUS)
  396. != (3 << MUSB_DEVCTL_VBUS_SHIFT)
  397. ) {
  398. musb->int_usb |= MUSB_INTR_DISCONNECT;
  399. musb->int_usb &= ~MUSB_INTR_SUSPEND;
  400. break;
  401. }
  402. musb_g_resume(musb);
  403. break;
  404. case OTG_STATE_B_IDLE:
  405. musb->int_usb &= ~MUSB_INTR_SUSPEND;
  406. break;
  407. #endif
  408. default:
  409. WARNING("bogus %s RESUME (%s)\n",
  410. "peripheral",
  411. otg_state_string(musb));
  412. }
  413. }
  414. }
  415. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  416. /* see manual for the order of the tests */
  417. if (int_usb & MUSB_INTR_SESSREQ) {
  418. DBG(1, "SESSION_REQUEST (%s)\n", otg_state_string(musb));
  419. /* IRQ arrives from ID pin sense or (later, if VBUS power
  420. * is removed) SRP. responses are time critical:
  421. * - turn on VBUS (with silicon-specific mechanism)
  422. * - go through A_WAIT_VRISE
  423. * - ... to A_WAIT_BCON.
  424. * a_wait_vrise_tmout triggers VBUS_ERROR transitions
  425. */
  426. musb_writeb(mbase, MUSB_DEVCTL, MUSB_DEVCTL_SESSION);
  427. musb->ep0_stage = MUSB_EP0_START;
  428. musb->xceiv->state = OTG_STATE_A_IDLE;
  429. MUSB_HST_MODE(musb);
  430. musb_set_vbus(musb, 1);
  431. handled = IRQ_HANDLED;
  432. }
  433. if (int_usb & MUSB_INTR_VBUSERROR) {
  434. int ignore = 0;
  435. /* During connection as an A-Device, we may see a short
  436. * current spikes causing voltage drop, because of cable
  437. * and peripheral capacitance combined with vbus draw.
  438. * (So: less common with truly self-powered devices, where
  439. * vbus doesn't act like a power supply.)
  440. *
  441. * Such spikes are short; usually less than ~500 usec, max
  442. * of ~2 msec. That is, they're not sustained overcurrent
  443. * errors, though they're reported using VBUSERROR irqs.
  444. *
  445. * Workarounds: (a) hardware: use self powered devices.
  446. * (b) software: ignore non-repeated VBUS errors.
  447. *
  448. * REVISIT: do delays from lots of DEBUG_KERNEL checks
  449. * make trouble here, keeping VBUS < 4.4V ?
  450. */
  451. switch (musb->xceiv->state) {
  452. case OTG_STATE_A_HOST:
  453. /* recovery is dicey once we've gotten past the
  454. * initial stages of enumeration, but if VBUS
  455. * stayed ok at the other end of the link, and
  456. * another reset is due (at least for high speed,
  457. * to redo the chirp etc), it might work OK...
  458. */
  459. case OTG_STATE_A_WAIT_BCON:
  460. case OTG_STATE_A_WAIT_VRISE:
  461. if (musb->vbuserr_retry) {
  462. musb->vbuserr_retry--;
  463. ignore = 1;
  464. devctl |= MUSB_DEVCTL_SESSION;
  465. musb_writeb(mbase, MUSB_DEVCTL, devctl);
  466. } else {
  467. musb->port1_status |=
  468. (1 << USB_PORT_FEAT_OVER_CURRENT)
  469. | (1 << USB_PORT_FEAT_C_OVER_CURRENT);
  470. }
  471. break;
  472. default:
  473. break;
  474. }
  475. DBG(1, "VBUS_ERROR in %s (%02x, %s), retry #%d, port1 %08x\n",
  476. otg_state_string(musb),
  477. devctl,
  478. ({ char *s;
  479. switch (devctl & MUSB_DEVCTL_VBUS) {
  480. case 0 << MUSB_DEVCTL_VBUS_SHIFT:
  481. s = "<SessEnd"; break;
  482. case 1 << MUSB_DEVCTL_VBUS_SHIFT:
  483. s = "<AValid"; break;
  484. case 2 << MUSB_DEVCTL_VBUS_SHIFT:
  485. s = "<VBusValid"; break;
  486. /* case 3 << MUSB_DEVCTL_VBUS_SHIFT: */
  487. default:
  488. s = "VALID"; break;
  489. }; s; }),
  490. VBUSERR_RETRY_COUNT - musb->vbuserr_retry,
  491. musb->port1_status);
  492. /* go through A_WAIT_VFALL then start a new session */
  493. if (!ignore)
  494. musb_set_vbus(musb, 0);
  495. handled = IRQ_HANDLED;
  496. }
  497. if (int_usb & MUSB_INTR_CONNECT) {
  498. struct usb_hcd *hcd = musb_to_hcd(musb);
  499. handled = IRQ_HANDLED;
  500. musb->is_active = 1;
  501. set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
  502. musb->ep0_stage = MUSB_EP0_START;
  503. #ifdef CONFIG_USB_MUSB_OTG
  504. /* flush endpoints when transitioning from Device Mode */
  505. if (is_peripheral_active(musb)) {
  506. /* REVISIT HNP; just force disconnect */
  507. }
  508. musb_writew(mbase, MUSB_INTRTXE, musb->epmask);
  509. musb_writew(mbase, MUSB_INTRRXE, musb->epmask & 0xfffe);
  510. musb_writeb(mbase, MUSB_INTRUSBE, 0xf7);
  511. #endif
  512. musb->port1_status &= ~(USB_PORT_STAT_LOW_SPEED
  513. |USB_PORT_STAT_HIGH_SPEED
  514. |USB_PORT_STAT_ENABLE
  515. );
  516. musb->port1_status |= USB_PORT_STAT_CONNECTION
  517. |(USB_PORT_STAT_C_CONNECTION << 16);
  518. /* high vs full speed is just a guess until after reset */
  519. if (devctl & MUSB_DEVCTL_LSDEV)
  520. musb->port1_status |= USB_PORT_STAT_LOW_SPEED;
  521. if (hcd->status_urb)
  522. usb_hcd_poll_rh_status(hcd);
  523. else
  524. usb_hcd_resume_root_hub(hcd);
  525. MUSB_HST_MODE(musb);
  526. /* indicate new connection to OTG machine */
  527. switch (musb->xceiv->state) {
  528. case OTG_STATE_B_PERIPHERAL:
  529. if (int_usb & MUSB_INTR_SUSPEND) {
  530. DBG(1, "HNP: SUSPEND+CONNECT, now b_host\n");
  531. musb->xceiv->state = OTG_STATE_B_HOST;
  532. hcd->self.is_b_host = 1;
  533. int_usb &= ~MUSB_INTR_SUSPEND;
  534. } else
  535. DBG(1, "CONNECT as b_peripheral???\n");
  536. break;
  537. case OTG_STATE_B_WAIT_ACON:
  538. DBG(1, "HNP: Waiting to switch to b_host state\n");
  539. musb->xceiv->state = OTG_STATE_B_HOST;
  540. hcd->self.is_b_host = 1;
  541. break;
  542. default:
  543. if ((devctl & MUSB_DEVCTL_VBUS)
  544. == (3 << MUSB_DEVCTL_VBUS_SHIFT)) {
  545. musb->xceiv->state = OTG_STATE_A_HOST;
  546. hcd->self.is_b_host = 0;
  547. }
  548. break;
  549. }
  550. DBG(1, "CONNECT (%s) devctl %02x\n",
  551. otg_state_string(musb), devctl);
  552. }
  553. #endif /* CONFIG_USB_MUSB_HDRC_HCD */
  554. /* mentor saves a bit: bus reset and babble share the same irq.
  555. * only host sees babble; only peripheral sees bus reset.
  556. */
  557. if (int_usb & MUSB_INTR_RESET) {
  558. if (is_host_capable() && (devctl & MUSB_DEVCTL_HM) != 0) {
  559. /*
  560. * Looks like non-HS BABBLE can be ignored, but
  561. * HS BABBLE is an error condition. For HS the solution
  562. * is to avoid babble in the first place and fix what
  563. * caused BABBLE. When HS BABBLE happens we can only
  564. * stop the session.
  565. */
  566. if (devctl & (MUSB_DEVCTL_FSDEV | MUSB_DEVCTL_LSDEV))
  567. DBG(1, "BABBLE devctl: %02x\n", devctl);
  568. else {
  569. ERR("Stopping host session -- babble\n");
  570. musb_writeb(mbase, MUSB_DEVCTL, 0);
  571. }
  572. } else if (is_peripheral_capable()) {
  573. DBG(1, "BUS RESET as %s\n", otg_state_string(musb));
  574. switch (musb->xceiv->state) {
  575. #ifdef CONFIG_USB_OTG
  576. case OTG_STATE_A_SUSPEND:
  577. /* We need to ignore disconnect on suspend
  578. * otherwise tusb 2.0 won't reconnect after a
  579. * power cycle, which breaks otg compliance.
  580. */
  581. musb->ignore_disconnect = 1;
  582. musb_g_reset(musb);
  583. /* FALLTHROUGH */
  584. case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */
  585. /* never use invalid T(a_wait_bcon) */
  586. DBG(1, "HNP: in %s, %d msec timeout\n",
  587. otg_state_string(musb),
  588. TA_WAIT_BCON(musb));
  589. mod_timer(&musb->otg_timer, jiffies
  590. + msecs_to_jiffies(TA_WAIT_BCON(musb)));
  591. break;
  592. case OTG_STATE_A_PERIPHERAL:
  593. musb_hnp_stop(musb);
  594. break;
  595. case OTG_STATE_B_WAIT_ACON:
  596. DBG(1, "HNP: RESET (%s), to b_peripheral\n",
  597. otg_state_string(musb));
  598. musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
  599. musb_g_reset(musb);
  600. break;
  601. #endif
  602. case OTG_STATE_B_IDLE:
  603. musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
  604. /* FALLTHROUGH */
  605. case OTG_STATE_B_PERIPHERAL:
  606. musb_g_reset(musb);
  607. break;
  608. default:
  609. DBG(1, "Unhandled BUS RESET as %s\n",
  610. otg_state_string(musb));
  611. }
  612. }
  613. handled = IRQ_HANDLED;
  614. }
  615. schedule_work(&musb->irq_work);
  616. return handled;
  617. }
  618. /*
  619. * Interrupt Service Routine to record USB "global" interrupts.
  620. * Since these do not happen often and signify things of
  621. * paramount importance, it seems OK to check them individually;
  622. * the order of the tests is specified in the manual
  623. *
  624. * @param musb instance pointer
  625. * @param int_usb register contents
  626. * @param devctl
  627. * @param power
  628. */
  629. static irqreturn_t musb_stage2_irq(struct musb *musb, u8 int_usb,
  630. u8 devctl, u8 power)
  631. {
  632. irqreturn_t handled = IRQ_NONE;
  633. #if 0
  634. /* REVISIT ... this would be for multiplexing periodic endpoints, or
  635. * supporting transfer phasing to prevent exceeding ISO bandwidth
  636. * limits of a given frame or microframe.
  637. *
  638. * It's not needed for peripheral side, which dedicates endpoints;
  639. * though it _might_ use SOF irqs for other purposes.
  640. *
  641. * And it's not currently needed for host side, which also dedicates
  642. * endpoints, relies on TX/RX interval registers, and isn't claimed
  643. * to support ISO transfers yet.
  644. */
  645. if (int_usb & MUSB_INTR_SOF) {
  646. void __iomem *mbase = musb->mregs;
  647. struct musb_hw_ep *ep;
  648. u8 epnum;
  649. u16 frame;
  650. DBG(6, "START_OF_FRAME\n");
  651. handled = IRQ_HANDLED;
  652. /* start any periodic Tx transfers waiting for current frame */
  653. frame = musb_readw(mbase, MUSB_FRAME);
  654. ep = musb->endpoints;
  655. for (epnum = 1; (epnum < musb->nr_endpoints)
  656. && (musb->epmask >= (1 << epnum));
  657. epnum++, ep++) {
  658. /*
  659. * FIXME handle framecounter wraps (12 bits)
  660. * eliminate duplicated StartUrb logic
  661. */
  662. if (ep->dwWaitFrame >= frame) {
  663. ep->dwWaitFrame = 0;
  664. pr_debug("SOF --> periodic TX%s on %d\n",
  665. ep->tx_channel ? " DMA" : "",
  666. epnum);
  667. if (!ep->tx_channel)
  668. musb_h_tx_start(musb, epnum);
  669. else
  670. cppi_hostdma_start(musb, epnum);
  671. }
  672. } /* end of for loop */
  673. }
  674. #endif
  675. if ((int_usb & MUSB_INTR_DISCONNECT) && !musb->ignore_disconnect) {
  676. DBG(1, "DISCONNECT (%s) as %s, devctl %02x\n",
  677. otg_state_string(musb),
  678. MUSB_MODE(musb), devctl);
  679. handled = IRQ_HANDLED;
  680. switch (musb->xceiv->state) {
  681. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  682. case OTG_STATE_A_HOST:
  683. case OTG_STATE_A_SUSPEND:
  684. usb_hcd_resume_root_hub(musb_to_hcd(musb));
  685. musb_root_disconnect(musb);
  686. if (musb->a_wait_bcon != 0 && is_otg_enabled(musb))
  687. musb_platform_try_idle(musb, jiffies
  688. + msecs_to_jiffies(musb->a_wait_bcon));
  689. break;
  690. #endif /* HOST */
  691. #ifdef CONFIG_USB_MUSB_OTG
  692. case OTG_STATE_B_HOST:
  693. musb_hnp_stop(musb);
  694. break;
  695. case OTG_STATE_A_PERIPHERAL:
  696. musb_hnp_stop(musb);
  697. musb_root_disconnect(musb);
  698. /* FALLTHROUGH */
  699. case OTG_STATE_B_WAIT_ACON:
  700. /* FALLTHROUGH */
  701. #endif /* OTG */
  702. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  703. case OTG_STATE_B_PERIPHERAL:
  704. case OTG_STATE_B_IDLE:
  705. musb_g_disconnect(musb);
  706. break;
  707. #endif /* GADGET */
  708. default:
  709. WARNING("unhandled DISCONNECT transition (%s)\n",
  710. otg_state_string(musb));
  711. break;
  712. }
  713. schedule_work(&musb->irq_work);
  714. }
  715. if (int_usb & MUSB_INTR_SUSPEND) {
  716. DBG(1, "SUSPEND (%s) devctl %02x power %02x\n",
  717. otg_state_string(musb), devctl, power);
  718. handled = IRQ_HANDLED;
  719. switch (musb->xceiv->state) {
  720. #ifdef CONFIG_USB_MUSB_OTG
  721. case OTG_STATE_A_PERIPHERAL:
  722. /*
  723. * We cannot stop HNP here, devctl BDEVICE might be
  724. * still set.
  725. */
  726. break;
  727. #endif
  728. case OTG_STATE_B_PERIPHERAL:
  729. musb_g_suspend(musb);
  730. musb->is_active = is_otg_enabled(musb)
  731. && musb->xceiv->gadget->b_hnp_enable;
  732. if (musb->is_active) {
  733. #ifdef CONFIG_USB_MUSB_OTG
  734. musb->xceiv->state = OTG_STATE_B_WAIT_ACON;
  735. DBG(1, "HNP: Setting timer for b_ase0_brst\n");
  736. mod_timer(&musb->otg_timer, jiffies
  737. + msecs_to_jiffies(
  738. OTG_TIME_B_ASE0_BRST));
  739. #endif
  740. }
  741. break;
  742. case OTG_STATE_A_WAIT_BCON:
  743. if (musb->a_wait_bcon != 0)
  744. musb_platform_try_idle(musb, jiffies
  745. + msecs_to_jiffies(musb->a_wait_bcon));
  746. break;
  747. case OTG_STATE_A_HOST:
  748. musb->xceiv->state = OTG_STATE_A_SUSPEND;
  749. musb->is_active = is_otg_enabled(musb)
  750. && musb->xceiv->host->b_hnp_enable;
  751. break;
  752. case OTG_STATE_B_HOST:
  753. /* Transition to B_PERIPHERAL, see 6.8.2.6 p 44 */
  754. DBG(1, "REVISIT: SUSPEND as B_HOST\n");
  755. break;
  756. default:
  757. /* "should not happen" */
  758. musb->is_active = 0;
  759. break;
  760. }
  761. schedule_work(&musb->irq_work);
  762. }
  763. return handled;
  764. }
  765. /*-------------------------------------------------------------------------*/
  766. /*
  767. * Program the HDRC to start (enable interrupts, dma, etc.).
  768. */
  769. void musb_start(struct musb *musb)
  770. {
  771. void __iomem *regs = musb->mregs;
  772. u8 devctl = musb_readb(regs, MUSB_DEVCTL);
  773. DBG(2, "<== devctl %02x\n", devctl);
  774. /* Set INT enable registers, enable interrupts */
  775. musb_writew(regs, MUSB_INTRTXE, musb->epmask);
  776. musb_writew(regs, MUSB_INTRRXE, musb->epmask & 0xfffe);
  777. musb_writeb(regs, MUSB_INTRUSBE, 0xf7);
  778. musb_writeb(regs, MUSB_TESTMODE, 0);
  779. /* put into basic highspeed mode and start session */
  780. musb_writeb(regs, MUSB_POWER, MUSB_POWER_ISOUPDATE
  781. | MUSB_POWER_SOFTCONN
  782. | MUSB_POWER_HSENAB
  783. /* ENSUSPEND wedges tusb */
  784. /* | MUSB_POWER_ENSUSPEND */
  785. );
  786. musb->is_active = 0;
  787. devctl = musb_readb(regs, MUSB_DEVCTL);
  788. devctl &= ~MUSB_DEVCTL_SESSION;
  789. if (is_otg_enabled(musb)) {
  790. /* session started after:
  791. * (a) ID-grounded irq, host mode;
  792. * (b) vbus present/connect IRQ, peripheral mode;
  793. * (c) peripheral initiates, using SRP
  794. */
  795. if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS)
  796. musb->is_active = 1;
  797. else
  798. devctl |= MUSB_DEVCTL_SESSION;
  799. } else if (is_host_enabled(musb)) {
  800. /* assume ID pin is hard-wired to ground */
  801. devctl |= MUSB_DEVCTL_SESSION;
  802. } else /* peripheral is enabled */ {
  803. if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS)
  804. musb->is_active = 1;
  805. }
  806. musb_platform_enable(musb);
  807. musb_writeb(regs, MUSB_DEVCTL, devctl);
  808. }
  809. static void musb_generic_disable(struct musb *musb)
  810. {
  811. void __iomem *mbase = musb->mregs;
  812. u16 temp;
  813. /* disable interrupts */
  814. musb_writeb(mbase, MUSB_INTRUSBE, 0);
  815. musb_writew(mbase, MUSB_INTRTXE, 0);
  816. musb_writew(mbase, MUSB_INTRRXE, 0);
  817. /* off */
  818. musb_writeb(mbase, MUSB_DEVCTL, 0);
  819. /* flush pending interrupts */
  820. temp = musb_readb(mbase, MUSB_INTRUSB);
  821. temp = musb_readw(mbase, MUSB_INTRTX);
  822. temp = musb_readw(mbase, MUSB_INTRRX);
  823. }
  824. /*
  825. * Make the HDRC stop (disable interrupts, etc.);
  826. * reversible by musb_start
  827. * called on gadget driver unregister
  828. * with controller locked, irqs blocked
  829. * acts as a NOP unless some role activated the hardware
  830. */
  831. void musb_stop(struct musb *musb)
  832. {
  833. /* stop IRQs, timers, ... */
  834. musb_platform_disable(musb);
  835. musb_generic_disable(musb);
  836. DBG(3, "HDRC disabled\n");
  837. /* FIXME
  838. * - mark host and/or peripheral drivers unusable/inactive
  839. * - disable DMA (and enable it in HdrcStart)
  840. * - make sure we can musb_start() after musb_stop(); with
  841. * OTG mode, gadget driver module rmmod/modprobe cycles that
  842. * - ...
  843. */
  844. musb_platform_try_idle(musb, 0);
  845. }
  846. static void musb_shutdown(struct platform_device *pdev)
  847. {
  848. struct musb *musb = dev_to_musb(&pdev->dev);
  849. unsigned long flags;
  850. spin_lock_irqsave(&musb->lock, flags);
  851. musb_platform_disable(musb);
  852. musb_generic_disable(musb);
  853. if (musb->clock) {
  854. clk_put(musb->clock);
  855. musb->clock = NULL;
  856. }
  857. spin_unlock_irqrestore(&musb->lock, flags);
  858. /* FIXME power down */
  859. }
  860. /*-------------------------------------------------------------------------*/
  861. /*
  862. * The silicon either has hard-wired endpoint configurations, or else
  863. * "dynamic fifo" sizing. The driver has support for both, though at this
  864. * writing only the dynamic sizing is very well tested. Since we switched
  865. * away from compile-time hardware parameters, we can no longer rely on
  866. * dead code elimination to leave only the relevant one in the object file.
  867. *
  868. * We don't currently use dynamic fifo setup capability to do anything
  869. * more than selecting one of a bunch of predefined configurations.
  870. */
  871. #if defined(CONFIG_USB_TUSB6010) || \
  872. defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP34XX)
  873. static ushort __initdata fifo_mode = 4;
  874. #else
  875. static ushort __initdata fifo_mode = 2;
  876. #endif
  877. /* "modprobe ... fifo_mode=1" etc */
  878. module_param(fifo_mode, ushort, 0);
  879. MODULE_PARM_DESC(fifo_mode, "initial endpoint configuration");
  880. enum fifo_style { FIFO_RXTX, FIFO_TX, FIFO_RX } __attribute__ ((packed));
  881. enum buf_mode { BUF_SINGLE, BUF_DOUBLE } __attribute__ ((packed));
  882. struct fifo_cfg {
  883. u8 hw_ep_num;
  884. enum fifo_style style;
  885. enum buf_mode mode;
  886. u16 maxpacket;
  887. };
  888. /*
  889. * tables defining fifo_mode values. define more if you like.
  890. * for host side, make sure both halves of ep1 are set up.
  891. */
  892. /* mode 0 - fits in 2KB */
  893. static struct fifo_cfg __initdata mode_0_cfg[] = {
  894. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
  895. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
  896. { .hw_ep_num = 2, .style = FIFO_RXTX, .maxpacket = 512, },
  897. { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
  898. { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
  899. };
  900. /* mode 1 - fits in 4KB */
  901. static struct fifo_cfg __initdata mode_1_cfg[] = {
  902. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  903. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  904. { .hw_ep_num = 2, .style = FIFO_RXTX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  905. { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
  906. { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
  907. };
  908. /* mode 2 - fits in 4KB */
  909. static struct fifo_cfg __initdata mode_2_cfg[] = {
  910. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
  911. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
  912. { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
  913. { .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
  914. { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
  915. { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
  916. };
  917. /* mode 3 - fits in 4KB */
  918. static struct fifo_cfg __initdata mode_3_cfg[] = {
  919. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  920. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, .mode = BUF_DOUBLE, },
  921. { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
  922. { .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
  923. { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
  924. { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
  925. };
  926. /* mode 4 - fits in 16KB */
  927. static struct fifo_cfg __initdata mode_4_cfg[] = {
  928. { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
  929. { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
  930. { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
  931. { .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
  932. { .hw_ep_num = 3, .style = FIFO_TX, .maxpacket = 512, },
  933. { .hw_ep_num = 3, .style = FIFO_RX, .maxpacket = 512, },
  934. { .hw_ep_num = 4, .style = FIFO_TX, .maxpacket = 512, },
  935. { .hw_ep_num = 4, .style = FIFO_RX, .maxpacket = 512, },
  936. { .hw_ep_num = 5, .style = FIFO_TX, .maxpacket = 512, },
  937. { .hw_ep_num = 5, .style = FIFO_RX, .maxpacket = 512, },
  938. { .hw_ep_num = 6, .style = FIFO_TX, .maxpacket = 512, },
  939. { .hw_ep_num = 6, .style = FIFO_RX, .maxpacket = 512, },
  940. { .hw_ep_num = 7, .style = FIFO_TX, .maxpacket = 512, },
  941. { .hw_ep_num = 7, .style = FIFO_RX, .maxpacket = 512, },
  942. { .hw_ep_num = 8, .style = FIFO_TX, .maxpacket = 512, },
  943. { .hw_ep_num = 8, .style = FIFO_RX, .maxpacket = 512, },
  944. { .hw_ep_num = 9, .style = FIFO_TX, .maxpacket = 512, },
  945. { .hw_ep_num = 9, .style = FIFO_RX, .maxpacket = 512, },
  946. { .hw_ep_num = 10, .style = FIFO_TX, .maxpacket = 512, },
  947. { .hw_ep_num = 10, .style = FIFO_RX, .maxpacket = 512, },
  948. { .hw_ep_num = 11, .style = FIFO_TX, .maxpacket = 512, },
  949. { .hw_ep_num = 11, .style = FIFO_RX, .maxpacket = 512, },
  950. { .hw_ep_num = 12, .style = FIFO_TX, .maxpacket = 512, },
  951. { .hw_ep_num = 12, .style = FIFO_RX, .maxpacket = 512, },
  952. { .hw_ep_num = 13, .style = FIFO_TX, .maxpacket = 512, },
  953. { .hw_ep_num = 13, .style = FIFO_RX, .maxpacket = 512, },
  954. { .hw_ep_num = 14, .style = FIFO_RXTX, .maxpacket = 1024, },
  955. { .hw_ep_num = 15, .style = FIFO_RXTX, .maxpacket = 1024, },
  956. };
  957. /*
  958. * configure a fifo; for non-shared endpoints, this may be called
  959. * once for a tx fifo and once for an rx fifo.
  960. *
  961. * returns negative errno or offset for next fifo.
  962. */
  963. static int __init
  964. fifo_setup(struct musb *musb, struct musb_hw_ep *hw_ep,
  965. const struct fifo_cfg *cfg, u16 offset)
  966. {
  967. void __iomem *mbase = musb->mregs;
  968. int size = 0;
  969. u16 maxpacket = cfg->maxpacket;
  970. u16 c_off = offset >> 3;
  971. u8 c_size;
  972. /* expect hw_ep has already been zero-initialized */
  973. size = ffs(max(maxpacket, (u16) 8)) - 1;
  974. maxpacket = 1 << size;
  975. c_size = size - 3;
  976. if (cfg->mode == BUF_DOUBLE) {
  977. if ((offset + (maxpacket << 1)) >
  978. (1 << (musb->config->ram_bits + 2)))
  979. return -EMSGSIZE;
  980. c_size |= MUSB_FIFOSZ_DPB;
  981. } else {
  982. if ((offset + maxpacket) > (1 << (musb->config->ram_bits + 2)))
  983. return -EMSGSIZE;
  984. }
  985. /* configure the FIFO */
  986. musb_writeb(mbase, MUSB_INDEX, hw_ep->epnum);
  987. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  988. /* EP0 reserved endpoint for control, bidirectional;
  989. * EP1 reserved for bulk, two unidirection halves.
  990. */
  991. if (hw_ep->epnum == 1)
  992. musb->bulk_ep = hw_ep;
  993. /* REVISIT error check: be sure ep0 can both rx and tx ... */
  994. #endif
  995. switch (cfg->style) {
  996. case FIFO_TX:
  997. musb_write_txfifosz(mbase, c_size);
  998. musb_write_txfifoadd(mbase, c_off);
  999. hw_ep->tx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
  1000. hw_ep->max_packet_sz_tx = maxpacket;
  1001. break;
  1002. case FIFO_RX:
  1003. musb_write_rxfifosz(mbase, c_size);
  1004. musb_write_rxfifoadd(mbase, c_off);
  1005. hw_ep->rx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
  1006. hw_ep->max_packet_sz_rx = maxpacket;
  1007. break;
  1008. case FIFO_RXTX:
  1009. musb_write_txfifosz(mbase, c_size);
  1010. musb_write_txfifoadd(mbase, c_off);
  1011. hw_ep->rx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
  1012. hw_ep->max_packet_sz_rx = maxpacket;
  1013. musb_write_rxfifosz(mbase, c_size);
  1014. musb_write_rxfifoadd(mbase, c_off);
  1015. hw_ep->tx_double_buffered = hw_ep->rx_double_buffered;
  1016. hw_ep->max_packet_sz_tx = maxpacket;
  1017. hw_ep->is_shared_fifo = true;
  1018. break;
  1019. }
  1020. /* NOTE rx and tx endpoint irqs aren't managed separately,
  1021. * which happens to be ok
  1022. */
  1023. musb->epmask |= (1 << hw_ep->epnum);
  1024. return offset + (maxpacket << ((c_size & MUSB_FIFOSZ_DPB) ? 1 : 0));
  1025. }
  1026. static struct fifo_cfg __initdata ep0_cfg = {
  1027. .style = FIFO_RXTX, .maxpacket = 64,
  1028. };
  1029. static int __init ep_config_from_table(struct musb *musb)
  1030. {
  1031. const struct fifo_cfg *cfg;
  1032. unsigned i, n;
  1033. int offset;
  1034. struct musb_hw_ep *hw_ep = musb->endpoints;
  1035. switch (fifo_mode) {
  1036. default:
  1037. fifo_mode = 0;
  1038. /* FALLTHROUGH */
  1039. case 0:
  1040. cfg = mode_0_cfg;
  1041. n = ARRAY_SIZE(mode_0_cfg);
  1042. break;
  1043. case 1:
  1044. cfg = mode_1_cfg;
  1045. n = ARRAY_SIZE(mode_1_cfg);
  1046. break;
  1047. case 2:
  1048. cfg = mode_2_cfg;
  1049. n = ARRAY_SIZE(mode_2_cfg);
  1050. break;
  1051. case 3:
  1052. cfg = mode_3_cfg;
  1053. n = ARRAY_SIZE(mode_3_cfg);
  1054. break;
  1055. case 4:
  1056. cfg = mode_4_cfg;
  1057. n = ARRAY_SIZE(mode_4_cfg);
  1058. break;
  1059. }
  1060. printk(KERN_DEBUG "%s: setup fifo_mode %d\n",
  1061. musb_driver_name, fifo_mode);
  1062. offset = fifo_setup(musb, hw_ep, &ep0_cfg, 0);
  1063. /* assert(offset > 0) */
  1064. /* NOTE: for RTL versions >= 1.400 EPINFO and RAMINFO would
  1065. * be better than static musb->config->num_eps and DYN_FIFO_SIZE...
  1066. */
  1067. for (i = 0; i < n; i++) {
  1068. u8 epn = cfg->hw_ep_num;
  1069. if (epn >= musb->config->num_eps) {
  1070. pr_debug("%s: invalid ep %d\n",
  1071. musb_driver_name, epn);
  1072. return -EINVAL;
  1073. }
  1074. offset = fifo_setup(musb, hw_ep + epn, cfg++, offset);
  1075. if (offset < 0) {
  1076. pr_debug("%s: mem overrun, ep %d\n",
  1077. musb_driver_name, epn);
  1078. return -EINVAL;
  1079. }
  1080. epn++;
  1081. musb->nr_endpoints = max(epn, musb->nr_endpoints);
  1082. }
  1083. printk(KERN_DEBUG "%s: %d/%d max ep, %d/%d memory\n",
  1084. musb_driver_name,
  1085. n + 1, musb->config->num_eps * 2 - 1,
  1086. offset, (1 << (musb->config->ram_bits + 2)));
  1087. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1088. if (!musb->bulk_ep) {
  1089. pr_debug("%s: missing bulk\n", musb_driver_name);
  1090. return -EINVAL;
  1091. }
  1092. #endif
  1093. return 0;
  1094. }
  1095. /*
  1096. * ep_config_from_hw - when MUSB_C_DYNFIFO_DEF is false
  1097. * @param musb the controller
  1098. */
  1099. static int __init ep_config_from_hw(struct musb *musb)
  1100. {
  1101. u8 epnum = 0;
  1102. struct musb_hw_ep *hw_ep;
  1103. void *mbase = musb->mregs;
  1104. int ret = 0;
  1105. DBG(2, "<== static silicon ep config\n");
  1106. /* FIXME pick up ep0 maxpacket size */
  1107. for (epnum = 1; epnum < musb->config->num_eps; epnum++) {
  1108. musb_ep_select(mbase, epnum);
  1109. hw_ep = musb->endpoints + epnum;
  1110. ret = musb_read_fifosize(musb, hw_ep, epnum);
  1111. if (ret < 0)
  1112. break;
  1113. /* FIXME set up hw_ep->{rx,tx}_double_buffered */
  1114. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1115. /* pick an RX/TX endpoint for bulk */
  1116. if (hw_ep->max_packet_sz_tx < 512
  1117. || hw_ep->max_packet_sz_rx < 512)
  1118. continue;
  1119. /* REVISIT: this algorithm is lazy, we should at least
  1120. * try to pick a double buffered endpoint.
  1121. */
  1122. if (musb->bulk_ep)
  1123. continue;
  1124. musb->bulk_ep = hw_ep;
  1125. #endif
  1126. }
  1127. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1128. if (!musb->bulk_ep) {
  1129. pr_debug("%s: missing bulk\n", musb_driver_name);
  1130. return -EINVAL;
  1131. }
  1132. #endif
  1133. return 0;
  1134. }
  1135. enum { MUSB_CONTROLLER_MHDRC, MUSB_CONTROLLER_HDRC, };
  1136. /* Initialize MUSB (M)HDRC part of the USB hardware subsystem;
  1137. * configure endpoints, or take their config from silicon
  1138. */
  1139. static int __init musb_core_init(u16 musb_type, struct musb *musb)
  1140. {
  1141. #ifdef MUSB_AHB_ID
  1142. u32 data;
  1143. #endif
  1144. u8 reg;
  1145. char *type;
  1146. u16 hwvers, rev_major, rev_minor;
  1147. char aInfo[78], aRevision[32], aDate[12];
  1148. void __iomem *mbase = musb->mregs;
  1149. int status = 0;
  1150. int i;
  1151. /* log core options (read using indexed model) */
  1152. musb_ep_select(mbase, 0);
  1153. reg = musb_read_configdata(mbase);
  1154. strcpy(aInfo, (reg & MUSB_CONFIGDATA_UTMIDW) ? "UTMI-16" : "UTMI-8");
  1155. if (reg & MUSB_CONFIGDATA_DYNFIFO)
  1156. strcat(aInfo, ", dyn FIFOs");
  1157. if (reg & MUSB_CONFIGDATA_MPRXE) {
  1158. strcat(aInfo, ", bulk combine");
  1159. #ifdef C_MP_RX
  1160. musb->bulk_combine = true;
  1161. #else
  1162. strcat(aInfo, " (X)"); /* no driver support */
  1163. #endif
  1164. }
  1165. if (reg & MUSB_CONFIGDATA_MPTXE) {
  1166. strcat(aInfo, ", bulk split");
  1167. #ifdef C_MP_TX
  1168. musb->bulk_split = true;
  1169. #else
  1170. strcat(aInfo, " (X)"); /* no driver support */
  1171. #endif
  1172. }
  1173. if (reg & MUSB_CONFIGDATA_HBRXE) {
  1174. strcat(aInfo, ", HB-ISO Rx");
  1175. strcat(aInfo, " (X)"); /* no driver support */
  1176. }
  1177. if (reg & MUSB_CONFIGDATA_HBTXE) {
  1178. strcat(aInfo, ", HB-ISO Tx");
  1179. strcat(aInfo, " (X)"); /* no driver support */
  1180. }
  1181. if (reg & MUSB_CONFIGDATA_SOFTCONE)
  1182. strcat(aInfo, ", SoftConn");
  1183. printk(KERN_DEBUG "%s: ConfigData=0x%02x (%s)\n",
  1184. musb_driver_name, reg, aInfo);
  1185. #ifdef MUSB_AHB_ID
  1186. data = musb_readl(mbase, 0x404);
  1187. sprintf(aDate, "%04d-%02x-%02x", (data & 0xffff),
  1188. (data >> 16) & 0xff, (data >> 24) & 0xff);
  1189. /* FIXME ID2 and ID3 are unused */
  1190. data = musb_readl(mbase, 0x408);
  1191. printk(KERN_DEBUG "ID2=%lx\n", (long unsigned)data);
  1192. data = musb_readl(mbase, 0x40c);
  1193. printk(KERN_DEBUG "ID3=%lx\n", (long unsigned)data);
  1194. reg = musb_readb(mbase, 0x400);
  1195. musb_type = ('M' == reg) ? MUSB_CONTROLLER_MHDRC : MUSB_CONTROLLER_HDRC;
  1196. #else
  1197. aDate[0] = 0;
  1198. #endif
  1199. if (MUSB_CONTROLLER_MHDRC == musb_type) {
  1200. musb->is_multipoint = 1;
  1201. type = "M";
  1202. } else {
  1203. musb->is_multipoint = 0;
  1204. type = "";
  1205. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1206. #ifndef CONFIG_USB_OTG_BLACKLIST_HUB
  1207. printk(KERN_ERR
  1208. "%s: kernel must blacklist external hubs\n",
  1209. musb_driver_name);
  1210. #endif
  1211. #endif
  1212. }
  1213. /* log release info */
  1214. hwvers = musb_read_hwvers(mbase);
  1215. rev_major = (hwvers >> 10) & 0x1f;
  1216. rev_minor = hwvers & 0x3ff;
  1217. snprintf(aRevision, 32, "%d.%d%s", rev_major,
  1218. rev_minor, (hwvers & 0x8000) ? "RC" : "");
  1219. printk(KERN_DEBUG "%s: %sHDRC RTL version %s %s\n",
  1220. musb_driver_name, type, aRevision, aDate);
  1221. /* configure ep0 */
  1222. musb_configure_ep0(musb);
  1223. /* discover endpoint configuration */
  1224. musb->nr_endpoints = 1;
  1225. musb->epmask = 1;
  1226. if (reg & MUSB_CONFIGDATA_DYNFIFO) {
  1227. if (musb->config->dyn_fifo)
  1228. status = ep_config_from_table(musb);
  1229. else {
  1230. ERR("reconfigure software for Dynamic FIFOs\n");
  1231. status = -ENODEV;
  1232. }
  1233. } else {
  1234. if (!musb->config->dyn_fifo)
  1235. status = ep_config_from_hw(musb);
  1236. else {
  1237. ERR("reconfigure software for static FIFOs\n");
  1238. return -ENODEV;
  1239. }
  1240. }
  1241. if (status < 0)
  1242. return status;
  1243. /* finish init, and print endpoint config */
  1244. for (i = 0; i < musb->nr_endpoints; i++) {
  1245. struct musb_hw_ep *hw_ep = musb->endpoints + i;
  1246. hw_ep->fifo = MUSB_FIFO_OFFSET(i) + mbase;
  1247. #ifdef CONFIG_USB_TUSB6010
  1248. hw_ep->fifo_async = musb->async + 0x400 + MUSB_FIFO_OFFSET(i);
  1249. hw_ep->fifo_sync = musb->sync + 0x400 + MUSB_FIFO_OFFSET(i);
  1250. hw_ep->fifo_sync_va =
  1251. musb->sync_va + 0x400 + MUSB_FIFO_OFFSET(i);
  1252. if (i == 0)
  1253. hw_ep->conf = mbase - 0x400 + TUSB_EP0_CONF;
  1254. else
  1255. hw_ep->conf = mbase + 0x400 + (((i - 1) & 0xf) << 2);
  1256. #endif
  1257. hw_ep->regs = MUSB_EP_OFFSET(i, 0) + mbase;
  1258. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1259. hw_ep->target_regs = musb_read_target_reg_base(i, mbase);
  1260. hw_ep->rx_reinit = 1;
  1261. hw_ep->tx_reinit = 1;
  1262. #endif
  1263. if (hw_ep->max_packet_sz_tx) {
  1264. printk(KERN_DEBUG
  1265. "%s: hw_ep %d%s, %smax %d\n",
  1266. musb_driver_name, i,
  1267. hw_ep->is_shared_fifo ? "shared" : "tx",
  1268. hw_ep->tx_double_buffered
  1269. ? "doublebuffer, " : "",
  1270. hw_ep->max_packet_sz_tx);
  1271. }
  1272. if (hw_ep->max_packet_sz_rx && !hw_ep->is_shared_fifo) {
  1273. printk(KERN_DEBUG
  1274. "%s: hw_ep %d%s, %smax %d\n",
  1275. musb_driver_name, i,
  1276. "rx",
  1277. hw_ep->rx_double_buffered
  1278. ? "doublebuffer, " : "",
  1279. hw_ep->max_packet_sz_rx);
  1280. }
  1281. if (!(hw_ep->max_packet_sz_tx || hw_ep->max_packet_sz_rx))
  1282. DBG(1, "hw_ep %d not configured\n", i);
  1283. }
  1284. return 0;
  1285. }
  1286. /*-------------------------------------------------------------------------*/
  1287. #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3430)
  1288. static irqreturn_t generic_interrupt(int irq, void *__hci)
  1289. {
  1290. unsigned long flags;
  1291. irqreturn_t retval = IRQ_NONE;
  1292. struct musb *musb = __hci;
  1293. spin_lock_irqsave(&musb->lock, flags);
  1294. musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB);
  1295. musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX);
  1296. musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX);
  1297. if (musb->int_usb || musb->int_tx || musb->int_rx)
  1298. retval = musb_interrupt(musb);
  1299. spin_unlock_irqrestore(&musb->lock, flags);
  1300. return retval;
  1301. }
  1302. #else
  1303. #define generic_interrupt NULL
  1304. #endif
  1305. /*
  1306. * handle all the irqs defined by the HDRC core. for now we expect: other
  1307. * irq sources (phy, dma, etc) will be handled first, musb->int_* values
  1308. * will be assigned, and the irq will already have been acked.
  1309. *
  1310. * called in irq context with spinlock held, irqs blocked
  1311. */
  1312. irqreturn_t musb_interrupt(struct musb *musb)
  1313. {
  1314. irqreturn_t retval = IRQ_NONE;
  1315. u8 devctl, power;
  1316. int ep_num;
  1317. u32 reg;
  1318. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  1319. power = musb_readb(musb->mregs, MUSB_POWER);
  1320. DBG(4, "** IRQ %s usb%04x tx%04x rx%04x\n",
  1321. (devctl & MUSB_DEVCTL_HM) ? "host" : "peripheral",
  1322. musb->int_usb, musb->int_tx, musb->int_rx);
  1323. /* the core can interrupt us for multiple reasons; docs have
  1324. * a generic interrupt flowchart to follow
  1325. */
  1326. if (musb->int_usb & STAGE0_MASK)
  1327. retval |= musb_stage0_irq(musb, musb->int_usb,
  1328. devctl, power);
  1329. /* "stage 1" is handling endpoint irqs */
  1330. /* handle endpoint 0 first */
  1331. if (musb->int_tx & 1) {
  1332. if (devctl & MUSB_DEVCTL_HM)
  1333. retval |= musb_h_ep0_irq(musb);
  1334. else
  1335. retval |= musb_g_ep0_irq(musb);
  1336. }
  1337. /* RX on endpoints 1-15 */
  1338. reg = musb->int_rx >> 1;
  1339. ep_num = 1;
  1340. while (reg) {
  1341. if (reg & 1) {
  1342. /* musb_ep_select(musb->mregs, ep_num); */
  1343. /* REVISIT just retval = ep->rx_irq(...) */
  1344. retval = IRQ_HANDLED;
  1345. if (devctl & MUSB_DEVCTL_HM) {
  1346. if (is_host_capable())
  1347. musb_host_rx(musb, ep_num);
  1348. } else {
  1349. if (is_peripheral_capable())
  1350. musb_g_rx(musb, ep_num);
  1351. }
  1352. }
  1353. reg >>= 1;
  1354. ep_num++;
  1355. }
  1356. /* TX on endpoints 1-15 */
  1357. reg = musb->int_tx >> 1;
  1358. ep_num = 1;
  1359. while (reg) {
  1360. if (reg & 1) {
  1361. /* musb_ep_select(musb->mregs, ep_num); */
  1362. /* REVISIT just retval |= ep->tx_irq(...) */
  1363. retval = IRQ_HANDLED;
  1364. if (devctl & MUSB_DEVCTL_HM) {
  1365. if (is_host_capable())
  1366. musb_host_tx(musb, ep_num);
  1367. } else {
  1368. if (is_peripheral_capable())
  1369. musb_g_tx(musb, ep_num);
  1370. }
  1371. }
  1372. reg >>= 1;
  1373. ep_num++;
  1374. }
  1375. /* finish handling "global" interrupts after handling fifos */
  1376. if (musb->int_usb)
  1377. retval |= musb_stage2_irq(musb,
  1378. musb->int_usb, devctl, power);
  1379. return retval;
  1380. }
  1381. #ifndef CONFIG_MUSB_PIO_ONLY
  1382. static int __initdata use_dma = 1;
  1383. /* "modprobe ... use_dma=0" etc */
  1384. module_param(use_dma, bool, 0);
  1385. MODULE_PARM_DESC(use_dma, "enable/disable use of DMA");
  1386. void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit)
  1387. {
  1388. u8 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  1389. /* called with controller lock already held */
  1390. if (!epnum) {
  1391. #ifndef CONFIG_USB_TUSB_OMAP_DMA
  1392. if (!is_cppi_enabled()) {
  1393. /* endpoint 0 */
  1394. if (devctl & MUSB_DEVCTL_HM)
  1395. musb_h_ep0_irq(musb);
  1396. else
  1397. musb_g_ep0_irq(musb);
  1398. }
  1399. #endif
  1400. } else {
  1401. /* endpoints 1..15 */
  1402. if (transmit) {
  1403. if (devctl & MUSB_DEVCTL_HM) {
  1404. if (is_host_capable())
  1405. musb_host_tx(musb, epnum);
  1406. } else {
  1407. if (is_peripheral_capable())
  1408. musb_g_tx(musb, epnum);
  1409. }
  1410. } else {
  1411. /* receive */
  1412. if (devctl & MUSB_DEVCTL_HM) {
  1413. if (is_host_capable())
  1414. musb_host_rx(musb, epnum);
  1415. } else {
  1416. if (is_peripheral_capable())
  1417. musb_g_rx(musb, epnum);
  1418. }
  1419. }
  1420. }
  1421. }
  1422. #else
  1423. #define use_dma 0
  1424. #endif
  1425. /*-------------------------------------------------------------------------*/
  1426. #ifdef CONFIG_SYSFS
  1427. static ssize_t
  1428. musb_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
  1429. {
  1430. struct musb *musb = dev_to_musb(dev);
  1431. unsigned long flags;
  1432. int ret = -EINVAL;
  1433. spin_lock_irqsave(&musb->lock, flags);
  1434. ret = sprintf(buf, "%s\n", otg_state_string(musb));
  1435. spin_unlock_irqrestore(&musb->lock, flags);
  1436. return ret;
  1437. }
  1438. static ssize_t
  1439. musb_mode_store(struct device *dev, struct device_attribute *attr,
  1440. const char *buf, size_t n)
  1441. {
  1442. struct musb *musb = dev_to_musb(dev);
  1443. unsigned long flags;
  1444. int status;
  1445. spin_lock_irqsave(&musb->lock, flags);
  1446. if (sysfs_streq(buf, "host"))
  1447. status = musb_platform_set_mode(musb, MUSB_HOST);
  1448. else if (sysfs_streq(buf, "peripheral"))
  1449. status = musb_platform_set_mode(musb, MUSB_PERIPHERAL);
  1450. else if (sysfs_streq(buf, "otg"))
  1451. status = musb_platform_set_mode(musb, MUSB_OTG);
  1452. else
  1453. status = -EINVAL;
  1454. spin_unlock_irqrestore(&musb->lock, flags);
  1455. return (status == 0) ? n : status;
  1456. }
  1457. static DEVICE_ATTR(mode, 0644, musb_mode_show, musb_mode_store);
  1458. static ssize_t
  1459. musb_vbus_store(struct device *dev, struct device_attribute *attr,
  1460. const char *buf, size_t n)
  1461. {
  1462. struct musb *musb = dev_to_musb(dev);
  1463. unsigned long flags;
  1464. unsigned long val;
  1465. if (sscanf(buf, "%lu", &val) < 1) {
  1466. printk(KERN_ERR "Invalid VBUS timeout ms value\n");
  1467. return -EINVAL;
  1468. }
  1469. spin_lock_irqsave(&musb->lock, flags);
  1470. /* force T(a_wait_bcon) to be zero/unlimited *OR* valid */
  1471. musb->a_wait_bcon = val ? max_t(int, val, OTG_TIME_A_WAIT_BCON) : 0 ;
  1472. if (musb->xceiv->state == OTG_STATE_A_WAIT_BCON)
  1473. musb->is_active = 0;
  1474. musb_platform_try_idle(musb, jiffies + msecs_to_jiffies(val));
  1475. spin_unlock_irqrestore(&musb->lock, flags);
  1476. return n;
  1477. }
  1478. static ssize_t
  1479. musb_vbus_show(struct device *dev, struct device_attribute *attr, char *buf)
  1480. {
  1481. struct musb *musb = dev_to_musb(dev);
  1482. unsigned long flags;
  1483. unsigned long val;
  1484. int vbus;
  1485. spin_lock_irqsave(&musb->lock, flags);
  1486. val = musb->a_wait_bcon;
  1487. /* FIXME get_vbus_status() is normally #defined as false...
  1488. * and is effectively TUSB-specific.
  1489. */
  1490. vbus = musb_platform_get_vbus_status(musb);
  1491. spin_unlock_irqrestore(&musb->lock, flags);
  1492. return sprintf(buf, "Vbus %s, timeout %lu msec\n",
  1493. vbus ? "on" : "off", val);
  1494. }
  1495. static DEVICE_ATTR(vbus, 0644, musb_vbus_show, musb_vbus_store);
  1496. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  1497. /* Gadget drivers can't know that a host is connected so they might want
  1498. * to start SRP, but users can. This allows userspace to trigger SRP.
  1499. */
  1500. static ssize_t
  1501. musb_srp_store(struct device *dev, struct device_attribute *attr,
  1502. const char *buf, size_t n)
  1503. {
  1504. struct musb *musb = dev_to_musb(dev);
  1505. unsigned short srp;
  1506. if (sscanf(buf, "%hu", &srp) != 1
  1507. || (srp != 1)) {
  1508. printk(KERN_ERR "SRP: Value must be 1\n");
  1509. return -EINVAL;
  1510. }
  1511. if (srp == 1)
  1512. musb_g_wakeup(musb);
  1513. return n;
  1514. }
  1515. static DEVICE_ATTR(srp, 0644, NULL, musb_srp_store);
  1516. #endif /* CONFIG_USB_GADGET_MUSB_HDRC */
  1517. #endif /* sysfs */
  1518. /* Only used to provide driver mode change events */
  1519. static void musb_irq_work(struct work_struct *data)
  1520. {
  1521. struct musb *musb = container_of(data, struct musb, irq_work);
  1522. static int old_state;
  1523. if (musb->xceiv->state != old_state) {
  1524. old_state = musb->xceiv->state;
  1525. sysfs_notify(&musb->controller->kobj, NULL, "mode");
  1526. }
  1527. }
  1528. /* --------------------------------------------------------------------------
  1529. * Init support
  1530. */
  1531. static struct musb *__init
  1532. allocate_instance(struct device *dev,
  1533. struct musb_hdrc_config *config, void __iomem *mbase)
  1534. {
  1535. struct musb *musb;
  1536. struct musb_hw_ep *ep;
  1537. int epnum;
  1538. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1539. struct usb_hcd *hcd;
  1540. hcd = usb_create_hcd(&musb_hc_driver, dev, dev_name(dev));
  1541. if (!hcd)
  1542. return NULL;
  1543. /* usbcore sets dev->driver_data to hcd, and sometimes uses that... */
  1544. musb = hcd_to_musb(hcd);
  1545. INIT_LIST_HEAD(&musb->control);
  1546. INIT_LIST_HEAD(&musb->in_bulk);
  1547. INIT_LIST_HEAD(&musb->out_bulk);
  1548. hcd->uses_new_polling = 1;
  1549. musb->vbuserr_retry = VBUSERR_RETRY_COUNT;
  1550. musb->a_wait_bcon = OTG_TIME_A_WAIT_BCON;
  1551. #else
  1552. musb = kzalloc(sizeof *musb, GFP_KERNEL);
  1553. if (!musb)
  1554. return NULL;
  1555. dev_set_drvdata(dev, musb);
  1556. #endif
  1557. musb->mregs = mbase;
  1558. musb->ctrl_base = mbase;
  1559. musb->nIrq = -ENODEV;
  1560. musb->config = config;
  1561. BUG_ON(musb->config->num_eps > MUSB_C_NUM_EPS);
  1562. for (epnum = 0, ep = musb->endpoints;
  1563. epnum < musb->config->num_eps;
  1564. epnum++, ep++) {
  1565. ep->musb = musb;
  1566. ep->epnum = epnum;
  1567. }
  1568. musb->controller = dev;
  1569. return musb;
  1570. }
  1571. static void musb_free(struct musb *musb)
  1572. {
  1573. /* this has multiple entry modes. it handles fault cleanup after
  1574. * probe(), where things may be partially set up, as well as rmmod
  1575. * cleanup after everything's been de-activated.
  1576. */
  1577. #ifdef CONFIG_SYSFS
  1578. device_remove_file(musb->controller, &dev_attr_mode);
  1579. device_remove_file(musb->controller, &dev_attr_vbus);
  1580. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  1581. device_remove_file(musb->controller, &dev_attr_srp);
  1582. #endif
  1583. #endif
  1584. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  1585. musb_gadget_cleanup(musb);
  1586. #endif
  1587. if (musb->nIrq >= 0) {
  1588. if (musb->irq_wake)
  1589. disable_irq_wake(musb->nIrq);
  1590. free_irq(musb->nIrq, musb);
  1591. }
  1592. if (is_dma_capable() && musb->dma_controller) {
  1593. struct dma_controller *c = musb->dma_controller;
  1594. (void) c->stop(c);
  1595. dma_controller_destroy(c);
  1596. }
  1597. musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
  1598. musb_platform_exit(musb);
  1599. musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
  1600. if (musb->clock) {
  1601. clk_disable(musb->clock);
  1602. clk_put(musb->clock);
  1603. }
  1604. #ifdef CONFIG_USB_MUSB_OTG
  1605. put_device(musb->xceiv->dev);
  1606. #endif
  1607. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1608. usb_put_hcd(musb_to_hcd(musb));
  1609. #else
  1610. kfree(musb);
  1611. #endif
  1612. }
  1613. /*
  1614. * Perform generic per-controller initialization.
  1615. *
  1616. * @pDevice: the controller (already clocked, etc)
  1617. * @nIrq: irq
  1618. * @mregs: virtual address of controller registers,
  1619. * not yet corrected for platform-specific offsets
  1620. */
  1621. static int __init
  1622. musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
  1623. {
  1624. int status;
  1625. struct musb *musb;
  1626. struct musb_hdrc_platform_data *plat = dev->platform_data;
  1627. /* The driver might handle more features than the board; OK.
  1628. * Fail when the board needs a feature that's not enabled.
  1629. */
  1630. if (!plat) {
  1631. dev_dbg(dev, "no platform_data?\n");
  1632. return -ENODEV;
  1633. }
  1634. switch (plat->mode) {
  1635. case MUSB_HOST:
  1636. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1637. break;
  1638. #else
  1639. goto bad_config;
  1640. #endif
  1641. case MUSB_PERIPHERAL:
  1642. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  1643. break;
  1644. #else
  1645. goto bad_config;
  1646. #endif
  1647. case MUSB_OTG:
  1648. #ifdef CONFIG_USB_MUSB_OTG
  1649. break;
  1650. #else
  1651. bad_config:
  1652. #endif
  1653. default:
  1654. dev_err(dev, "incompatible Kconfig role setting\n");
  1655. return -EINVAL;
  1656. }
  1657. /* allocate */
  1658. musb = allocate_instance(dev, plat->config, ctrl);
  1659. if (!musb)
  1660. return -ENOMEM;
  1661. spin_lock_init(&musb->lock);
  1662. musb->board_mode = plat->mode;
  1663. musb->board_set_power = plat->set_power;
  1664. musb->set_clock = plat->set_clock;
  1665. musb->min_power = plat->min_power;
  1666. /* Clock usage is chip-specific ... functional clock (DaVinci,
  1667. * OMAP2430), or PHY ref (some TUSB6010 boards). All this core
  1668. * code does is make sure a clock handle is available; platform
  1669. * code manages it during start/stop and suspend/resume.
  1670. */
  1671. if (plat->clock) {
  1672. musb->clock = clk_get(dev, plat->clock);
  1673. if (IS_ERR(musb->clock)) {
  1674. status = PTR_ERR(musb->clock);
  1675. musb->clock = NULL;
  1676. goto fail;
  1677. }
  1678. }
  1679. /* The musb_platform_init() call:
  1680. * - adjusts musb->mregs and musb->isr if needed,
  1681. * - may initialize an integrated tranceiver
  1682. * - initializes musb->xceiv, usually by otg_get_transceiver()
  1683. * - activates clocks.
  1684. * - stops powering VBUS
  1685. * - assigns musb->board_set_vbus if host mode is enabled
  1686. *
  1687. * There are various transciever configurations. Blackfin,
  1688. * DaVinci, TUSB60x0, and others integrate them. OMAP3 uses
  1689. * external/discrete ones in various flavors (twl4030 family,
  1690. * isp1504, non-OTG, etc) mostly hooking up through ULPI.
  1691. */
  1692. musb->isr = generic_interrupt;
  1693. status = musb_platform_init(musb);
  1694. if (status < 0)
  1695. goto fail;
  1696. if (!musb->isr) {
  1697. status = -ENODEV;
  1698. goto fail2;
  1699. }
  1700. #ifndef CONFIG_MUSB_PIO_ONLY
  1701. if (use_dma && dev->dma_mask) {
  1702. struct dma_controller *c;
  1703. c = dma_controller_create(musb, musb->mregs);
  1704. musb->dma_controller = c;
  1705. if (c)
  1706. (void) c->start(c);
  1707. }
  1708. #endif
  1709. /* ideally this would be abstracted in platform setup */
  1710. if (!is_dma_capable() || !musb->dma_controller)
  1711. dev->dma_mask = NULL;
  1712. /* be sure interrupts are disabled before connecting ISR */
  1713. musb_platform_disable(musb);
  1714. musb_generic_disable(musb);
  1715. /* setup musb parts of the core (especially endpoints) */
  1716. status = musb_core_init(plat->config->multipoint
  1717. ? MUSB_CONTROLLER_MHDRC
  1718. : MUSB_CONTROLLER_HDRC, musb);
  1719. if (status < 0)
  1720. goto fail2;
  1721. #ifdef CONFIG_USB_OTG
  1722. setup_timer(&musb->otg_timer, musb_otg_timer_func, (unsigned long) musb);
  1723. #endif
  1724. /* Init IRQ workqueue before request_irq */
  1725. INIT_WORK(&musb->irq_work, musb_irq_work);
  1726. /* attach to the IRQ */
  1727. if (request_irq(nIrq, musb->isr, 0, dev_name(dev), musb)) {
  1728. dev_err(dev, "request_irq %d failed!\n", nIrq);
  1729. status = -ENODEV;
  1730. goto fail2;
  1731. }
  1732. musb->nIrq = nIrq;
  1733. /* FIXME this handles wakeup irqs wrong */
  1734. if (enable_irq_wake(nIrq) == 0) {
  1735. musb->irq_wake = 1;
  1736. device_init_wakeup(dev, 1);
  1737. } else {
  1738. musb->irq_wake = 0;
  1739. }
  1740. pr_info("%s: USB %s mode controller at %p using %s, IRQ %d\n",
  1741. musb_driver_name,
  1742. ({char *s;
  1743. switch (musb->board_mode) {
  1744. case MUSB_HOST: s = "Host"; break;
  1745. case MUSB_PERIPHERAL: s = "Peripheral"; break;
  1746. default: s = "OTG"; break;
  1747. }; s; }),
  1748. ctrl,
  1749. (is_dma_capable() && musb->dma_controller)
  1750. ? "DMA" : "PIO",
  1751. musb->nIrq);
  1752. /* host side needs more setup */
  1753. if (is_host_enabled(musb)) {
  1754. struct usb_hcd *hcd = musb_to_hcd(musb);
  1755. otg_set_host(musb->xceiv, &hcd->self);
  1756. if (is_otg_enabled(musb))
  1757. hcd->self.otg_port = 1;
  1758. musb->xceiv->host = &hcd->self;
  1759. hcd->power_budget = 2 * (plat->power ? : 250);
  1760. }
  1761. /* For the host-only role, we can activate right away.
  1762. * (We expect the ID pin to be forcibly grounded!!)
  1763. * Otherwise, wait till the gadget driver hooks up.
  1764. */
  1765. if (!is_otg_enabled(musb) && is_host_enabled(musb)) {
  1766. MUSB_HST_MODE(musb);
  1767. musb->xceiv->default_a = 1;
  1768. musb->xceiv->state = OTG_STATE_A_IDLE;
  1769. status = usb_add_hcd(musb_to_hcd(musb), -1, 0);
  1770. if (status)
  1771. goto fail;
  1772. DBG(1, "%s mode, status %d, devctl %02x %c\n",
  1773. "HOST", status,
  1774. musb_readb(musb->mregs, MUSB_DEVCTL),
  1775. (musb_readb(musb->mregs, MUSB_DEVCTL)
  1776. & MUSB_DEVCTL_BDEVICE
  1777. ? 'B' : 'A'));
  1778. } else /* peripheral is enabled */ {
  1779. MUSB_DEV_MODE(musb);
  1780. musb->xceiv->default_a = 0;
  1781. musb->xceiv->state = OTG_STATE_B_IDLE;
  1782. status = musb_gadget_setup(musb);
  1783. if (status)
  1784. goto fail;
  1785. DBG(1, "%s mode, status %d, dev%02x\n",
  1786. is_otg_enabled(musb) ? "OTG" : "PERIPHERAL",
  1787. status,
  1788. musb_readb(musb->mregs, MUSB_DEVCTL));
  1789. }
  1790. #ifdef CONFIG_SYSFS
  1791. status = device_create_file(dev, &dev_attr_mode);
  1792. status = device_create_file(dev, &dev_attr_vbus);
  1793. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  1794. status = device_create_file(dev, &dev_attr_srp);
  1795. #endif /* CONFIG_USB_GADGET_MUSB_HDRC */
  1796. status = 0;
  1797. #endif
  1798. if (status)
  1799. goto fail2;
  1800. return 0;
  1801. fail2:
  1802. #ifdef CONFIG_SYSFS
  1803. device_remove_file(musb->controller, &dev_attr_mode);
  1804. device_remove_file(musb->controller, &dev_attr_vbus);
  1805. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  1806. device_remove_file(musb->controller, &dev_attr_srp);
  1807. #endif
  1808. #endif
  1809. musb_platform_exit(musb);
  1810. fail:
  1811. dev_err(musb->controller,
  1812. "musb_init_controller failed with status %d\n", status);
  1813. if (musb->clock)
  1814. clk_put(musb->clock);
  1815. device_init_wakeup(dev, 0);
  1816. musb_free(musb);
  1817. return status;
  1818. }
  1819. /*-------------------------------------------------------------------------*/
  1820. /* all implementations (PCI bridge to FPGA, VLYNQ, etc) should just
  1821. * bridge to a platform device; this driver then suffices.
  1822. */
  1823. #ifndef CONFIG_MUSB_PIO_ONLY
  1824. static u64 *orig_dma_mask;
  1825. #endif
  1826. static int __init musb_probe(struct platform_device *pdev)
  1827. {
  1828. struct device *dev = &pdev->dev;
  1829. int irq = platform_get_irq(pdev, 0);
  1830. struct resource *iomem;
  1831. void __iomem *base;
  1832. iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1833. if (!iomem || irq == 0)
  1834. return -ENODEV;
  1835. base = ioremap(iomem->start, iomem->end - iomem->start + 1);
  1836. if (!base) {
  1837. dev_err(dev, "ioremap failed\n");
  1838. return -ENOMEM;
  1839. }
  1840. #ifndef CONFIG_MUSB_PIO_ONLY
  1841. /* clobbered by use_dma=n */
  1842. orig_dma_mask = dev->dma_mask;
  1843. #endif
  1844. return musb_init_controller(dev, irq, base);
  1845. }
  1846. static int __devexit musb_remove(struct platform_device *pdev)
  1847. {
  1848. struct musb *musb = dev_to_musb(&pdev->dev);
  1849. void __iomem *ctrl_base = musb->ctrl_base;
  1850. /* this gets called on rmmod.
  1851. * - Host mode: host may still be active
  1852. * - Peripheral mode: peripheral is deactivated (or never-activated)
  1853. * - OTG mode: both roles are deactivated (or never-activated)
  1854. */
  1855. musb_shutdown(pdev);
  1856. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1857. if (musb->board_mode == MUSB_HOST)
  1858. usb_remove_hcd(musb_to_hcd(musb));
  1859. #endif
  1860. musb_free(musb);
  1861. iounmap(ctrl_base);
  1862. device_init_wakeup(&pdev->dev, 0);
  1863. #ifndef CONFIG_MUSB_PIO_ONLY
  1864. pdev->dev.dma_mask = orig_dma_mask;
  1865. #endif
  1866. return 0;
  1867. }
  1868. #ifdef CONFIG_PM
  1869. static int musb_suspend(struct platform_device *pdev, pm_message_t message)
  1870. {
  1871. unsigned long flags;
  1872. struct musb *musb = dev_to_musb(&pdev->dev);
  1873. if (!musb->clock)
  1874. return 0;
  1875. spin_lock_irqsave(&musb->lock, flags);
  1876. if (is_peripheral_active(musb)) {
  1877. /* FIXME force disconnect unless we know USB will wake
  1878. * the system up quickly enough to respond ...
  1879. */
  1880. } else if (is_host_active(musb)) {
  1881. /* we know all the children are suspended; sometimes
  1882. * they will even be wakeup-enabled.
  1883. */
  1884. }
  1885. if (musb->set_clock)
  1886. musb->set_clock(musb->clock, 0);
  1887. else
  1888. clk_disable(musb->clock);
  1889. spin_unlock_irqrestore(&musb->lock, flags);
  1890. return 0;
  1891. }
  1892. static int musb_resume_early(struct platform_device *pdev)
  1893. {
  1894. struct musb *musb = dev_to_musb(&pdev->dev);
  1895. if (!musb->clock)
  1896. return 0;
  1897. if (musb->set_clock)
  1898. musb->set_clock(musb->clock, 1);
  1899. else
  1900. clk_enable(musb->clock);
  1901. /* for static cmos like DaVinci, register values were preserved
  1902. * unless for some reason the whole soc powered down or the USB
  1903. * module got reset through the PSC (vs just being disabled).
  1904. */
  1905. return 0;
  1906. }
  1907. #else
  1908. #define musb_suspend NULL
  1909. #define musb_resume_early NULL
  1910. #endif
  1911. static struct platform_driver musb_driver = {
  1912. .driver = {
  1913. .name = (char *)musb_driver_name,
  1914. .bus = &platform_bus_type,
  1915. .owner = THIS_MODULE,
  1916. },
  1917. .remove = __devexit_p(musb_remove),
  1918. .shutdown = musb_shutdown,
  1919. .suspend = musb_suspend,
  1920. .resume_early = musb_resume_early,
  1921. };
  1922. /*-------------------------------------------------------------------------*/
  1923. static int __init musb_init(void)
  1924. {
  1925. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  1926. if (usb_disabled())
  1927. return 0;
  1928. #endif
  1929. pr_info("%s: version " MUSB_VERSION ", "
  1930. #ifdef CONFIG_MUSB_PIO_ONLY
  1931. "pio"
  1932. #elif defined(CONFIG_USB_TI_CPPI_DMA)
  1933. "cppi-dma"
  1934. #elif defined(CONFIG_USB_INVENTRA_DMA)
  1935. "musb-dma"
  1936. #elif defined(CONFIG_USB_TUSB_OMAP_DMA)
  1937. "tusb-omap-dma"
  1938. #else
  1939. "?dma?"
  1940. #endif
  1941. ", "
  1942. #ifdef CONFIG_USB_MUSB_OTG
  1943. "otg (peripheral+host)"
  1944. #elif defined(CONFIG_USB_GADGET_MUSB_HDRC)
  1945. "peripheral"
  1946. #elif defined(CONFIG_USB_MUSB_HDRC_HCD)
  1947. "host"
  1948. #endif
  1949. ", debug=%d\n",
  1950. musb_driver_name, musb_debug);
  1951. return platform_driver_probe(&musb_driver, musb_probe);
  1952. }
  1953. /* make us init after usbcore and i2c (transceivers, regulators, etc)
  1954. * and before usb gadget and host-side drivers start to register
  1955. */
  1956. fs_initcall(musb_init);
  1957. static void __exit musb_cleanup(void)
  1958. {
  1959. platform_driver_unregister(&musb_driver);
  1960. }
  1961. module_exit(musb_cleanup);