musb_core.c 61 KB

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