musb_core.c 60 KB

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