2 * MUSB OTG driver core code
4 * Copyright 2005 Mentor Graphics Corporation
5 * Copyright (C) 2005-2006 by Texas Instruments
6 * Copyright (C) 2006-2007 Nokia Corporation
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.
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.
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
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.
36 * Inventra (Multipoint) Dual-Role Controller Driver for Linux.
38 * This consists of a Host Controller Driver (HCD) and a peripheral
39 * controller driver implementing the "Gadget" API; OTG support is
40 * in the works. These are normal Linux-USB controller drivers which
41 * use IRQs and have no dedicated thread.
43 * This version of the driver has only been used with products from
44 * Texas Instruments. Those products integrate the Inventra logic
45 * with other DMA, IRQ, and bus modules, as well as other logic that
46 * needs to be reflected in this driver.
49 * NOTE: the original Mentor code here was pretty much a collection
50 * of mechanisms that don't seem to have been fully integrated/working
51 * for *any* Linux kernel version. This version aims at Linux 2.6.now,
52 * Key open issues include:
54 * - Lack of host-side transaction scheduling, for all transfer types.
55 * The hardware doesn't do it; instead, software must.
57 * This is not an issue for OTG devices that don't support external
58 * hubs, but for more "normal" USB hosts it's a user issue that the
59 * "multipoint" support doesn't scale in the expected ways. That
60 * includes DaVinci EVM in a common non-OTG mode.
62 * * Control and bulk use dedicated endpoints, and there's as
63 * yet no mechanism to either (a) reclaim the hardware when
64 * peripherals are NAKing, which gets complicated with bulk
65 * endpoints, or (b) use more than a single bulk endpoint in
68 * RESULT: one device may be perceived as blocking another one.
70 * * Interrupt and isochronous will dynamically allocate endpoint
71 * hardware, but (a) there's no record keeping for bandwidth;
72 * (b) in the common case that few endpoints are available, there
73 * is no mechanism to reuse endpoints to talk to multiple devices.
75 * RESULT: At one extreme, bandwidth can be overcommitted in
76 * some hardware configurations, no faults will be reported.
77 * At the other extreme, the bandwidth capabilities which do
78 * exist tend to be severely undercommitted. You can't yet hook
79 * up both a keyboard and a mouse to an external USB hub.
83 * This gets many kinds of configuration information:
84 * - Kconfig for everything user-configurable
85 * - <asm/arch/hdrc_cnf.h> for SOC or family details
86 * - platform_device for addressing, irq, and platform_data
87 * - platform_data is mostly for board-specific informarion
89 * Most of the conditional compilation will (someday) vanish.
92 #include <linux/module.h>
93 #include <linux/kernel.h>
94 #include <linux/sched.h>
95 #include <linux/slab.h>
96 #include <linux/init.h>
97 #include <linux/list.h>
98 #include <linux/kobject.h>
99 #include <linux/platform_device.h>
104 #include <asm/arch/hardware.h>
105 #include <asm/arch/memory.h>
106 #include <asm/mach-types.h>
109 #include "musb_core.h"
112 #ifdef CONFIG_ARCH_DAVINCI
119 unsigned debug = MUSB_DEBUG;
120 module_param(debug, uint, 0);
121 MODULE_PARM_DESC(debug, "initial debug message level");
123 #define MUSB_VERSION_SUFFIX "/dbg"
126 const char *otg_state_string(struct musb *musb)
130 snprintf(buf, sizeof buf, "otg-%d", musb->xceiv.state);
135 #define DRIVER_AUTHOR "Mentor Graphics, Texas Instruments, Nokia"
136 #define DRIVER_DESC "Inventra Dual-Role USB Controller Driver"
138 #define MUSB_VERSION_BASE "6.0"
140 #ifndef MUSB_VERSION_SUFFIX
141 #define MUSB_VERSION_SUFFIX ""
143 #define MUSB_VERSION MUSB_VERSION_BASE MUSB_VERSION_SUFFIX
145 #define DRIVER_INFO DRIVER_DESC ", v" MUSB_VERSION
147 const char musb_driver_name[] = "musb_hdrc";
149 MODULE_DESCRIPTION(DRIVER_INFO);
150 MODULE_AUTHOR(DRIVER_AUTHOR);
151 MODULE_LICENSE("GPL");
154 /*-------------------------------------------------------------------------*/
156 static inline struct musb *dev_to_musb(struct device *dev)
158 #ifdef CONFIG_USB_MUSB_HDRC_HCD
159 /* usbcore insists dev->driver_data is a "struct hcd *" */
160 return hcd_to_musb(dev_get_drvdata(dev));
162 return dev_get_drvdata(dev);
166 /*-------------------------------------------------------------------------*/
168 #ifndef CONFIG_USB_TUSB6010
170 * Load an endpoint's FIFO
172 void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src)
174 void __iomem *fifo = hw_ep->fifo;
178 DBG(4, "%cX ep%d fifo %p count %d buf %p\n",
179 'T', hw_ep->epnum, fifo, len, src);
181 /* we can't assume unaligned reads work */
182 if (likely((0x01 & (unsigned long) src) == 0)) {
185 /* best case is 32bit-aligned source address */
186 if ((0x02 & (unsigned long) src) == 0) {
188 writesl(fifo, src + index, len >> 2);
189 index += len & ~0x03;
192 musb_writew(fifo, 0, *(u16*)&src[index]);
197 writesw(fifo, src + index, len >> 1);
198 index += len & ~0x01;
202 musb_writeb(fifo, 0, src[index]);
205 writesb(fifo, src, len);
210 * Unload an endpoint's FIFO
212 void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
214 void __iomem *fifo = hw_ep->fifo;
216 DBG(4, "%cX ep%d fifo %p count %d buf %p\n",
217 'R', hw_ep->epnum, fifo, len, dst);
219 /* we can't assume unaligned writes work */
220 if (likely((0x01 & (unsigned long) dst) == 0)) {
223 /* best case is 32bit-aligned destination address */
224 if ((0x02 & (unsigned long) dst) == 0) {
226 readsl(fifo, dst, len >> 2);
230 *(u16*)&dst[index] = musb_readw(fifo, 0);
235 readsw(fifo, dst, len >> 1);
240 dst[index] = musb_readb(fifo, 0);
243 readsb(fifo, dst, len);
247 #endif /* normal PIO */
250 /*-------------------------------------------------------------------------*/
252 /* for high speed test mode; see USB 2.0 spec 7.1.20 */
253 static const u8 musb_test_packet[53] = {
254 /* implicit SYNC then DATA0 to start */
257 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
259 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
261 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee,
262 /* JJJJJJJKKKKKKK x8 */
263 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
265 0x7f, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd,
266 /* JKKKKKKK x10, JK */
267 0xfc, 0x7e, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0x7e
269 /* implicit CRC16 then EOP to end */
272 void musb_load_testpacket(struct musb *musb)
274 void __iomem *regs = musb->endpoints[0].regs;
276 musb_ep_select(musb->mregs, 0);
277 musb_write_fifo(musb->control_ep,
278 sizeof(musb_test_packet), musb_test_packet);
279 musb_writew(regs, MUSB_CSR0, MUSB_CSR0_TXPKTRDY);
282 /*-------------------------------------------------------------------------*/
284 #ifdef CONFIG_USB_MUSB_OTG
287 * See also USB_OTG_1-3.pdf 6.6.5 Timers
288 * REVISIT: Are the other timers done in the hardware?
290 #define TB_ASE0_BRST 100 /* Min 3.125 ms */
293 * Handles OTG hnp timeouts, such as b_ase0_brst
295 void musb_otg_timer_func(unsigned long data)
297 struct musb *musb = (struct musb *)data;
300 spin_lock_irqsave(&musb->lock, flags);
301 if (musb->xceiv.state == OTG_STATE_B_WAIT_ACON) {
302 DBG(1, "HNP: B_WAIT_ACON timeout; back to B_PERIPHERAL\n");
303 musb_g_disconnect(musb);
304 musb->xceiv.state = OTG_STATE_B_PERIPHERAL;
307 spin_unlock_irqrestore(&musb->lock, flags);
310 static DEFINE_TIMER(musb_otg_timer, musb_otg_timer_func, 0, 0);
313 * Stops the B-device HNP state. Caller must take care of locking.
315 void musb_hnp_stop(struct musb *musb)
317 struct usb_hcd *hcd = musb_to_hcd(musb);
318 void __iomem *mbase = musb->mregs;
321 switch (musb->xceiv.state) {
322 case OTG_STATE_A_PERIPHERAL:
323 case OTG_STATE_A_WAIT_VFALL:
324 case OTG_STATE_A_WAIT_BCON:
325 DBG(1, "HNP: Switching back to A-host\n");
326 musb_g_disconnect(musb);
327 musb->xceiv.state = OTG_STATE_A_IDLE;
331 case OTG_STATE_B_HOST:
332 DBG(1, "HNP: Disabling HR\n");
333 hcd->self.is_b_host = 0;
334 musb->xceiv.state = OTG_STATE_B_PERIPHERAL;
336 reg = musb_readb(mbase, MUSB_POWER);
337 reg |= MUSB_POWER_SUSPENDM;
338 musb_writeb(mbase, MUSB_POWER, reg);
339 /* REVISIT: Start SESSION_REQUEST here? */
342 DBG(1, "HNP: Stopping in unknown state %s\n",
343 otg_state_string(musb));
347 * When returning to A state after HNP, avoid hub_port_rebounce(),
348 * which cause occasional OPT A "Did not receive reset after connect"
351 musb->port1_status &=
352 ~(1 << USB_PORT_FEAT_C_CONNECTION);
358 * Interrupt Service Routine to record USB "global" interrupts.
359 * Since these do not happen often and signify things of
360 * paramount importance, it seems OK to check them individually;
361 * the order of the tests is specified in the manual
363 * @param musb instance pointer
364 * @param int_usb register contents
369 #define STAGE0_MASK (MUSB_INTR_RESUME | MUSB_INTR_SESSREQ \
370 | MUSB_INTR_VBUSERROR | MUSB_INTR_CONNECT \
373 static irqreturn_t musb_stage0_irq(struct musb * musb, u8 int_usb,
376 irqreturn_t handled = IRQ_NONE;
377 void __iomem *mbase = musb->mregs;
379 DBG(3, "<== Power=%02x, DevCtl=%02x, int_usb=0x%x\n", power, devctl,
382 /* in host mode, the peripheral may issue remote wakeup.
383 * in peripheral mode, the host may resume the link.
384 * spurious RESUME irqs happen too, paired with SUSPEND.
386 if (int_usb & MUSB_INTR_RESUME) {
387 handled = IRQ_HANDLED;
388 DBG(3, "RESUME (%s)\n", otg_state_string(musb));
390 if (devctl & MUSB_DEVCTL_HM) {
391 #ifdef CONFIG_USB_MUSB_HDRC_HCD
392 switch (musb->xceiv.state) {
393 case OTG_STATE_A_SUSPEND:
394 /* remote wakeup? later, GetPortStatus
395 * will stop RESUME signaling
398 if (power & MUSB_POWER_SUSPENDM) {
400 musb->int_usb &= ~MUSB_INTR_SUSPEND;
401 DBG(2, "Spurious SUSPENDM\n");
405 power &= ~MUSB_POWER_SUSPENDM;
406 musb_writeb(mbase, MUSB_POWER,
407 power | MUSB_POWER_RESUME);
409 musb->port1_status |=
410 (USB_PORT_STAT_C_SUSPEND << 16)
411 | MUSB_PORT_STAT_RESUME;
412 musb->rh_timer = jiffies
413 + msecs_to_jiffies(20);
415 musb->xceiv.state = OTG_STATE_A_HOST;
417 usb_hcd_resume_root_hub(musb_to_hcd(musb));
419 case OTG_STATE_B_WAIT_ACON:
420 musb->xceiv.state = OTG_STATE_B_PERIPHERAL;
425 WARN("bogus %s RESUME (%s)\n",
427 otg_state_string(musb));
431 switch (musb->xceiv.state) {
432 #ifdef CONFIG_USB_MUSB_HDRC_HCD
433 case OTG_STATE_A_SUSPEND:
434 /* possibly DISCONNECT is upcoming */
435 musb->xceiv.state = OTG_STATE_A_HOST;
436 usb_hcd_resume_root_hub(musb_to_hcd(musb));
439 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
440 case OTG_STATE_B_WAIT_ACON:
441 case OTG_STATE_B_PERIPHERAL:
442 /* disconnect while suspended? we may
443 * not get a disconnect irq...
445 if ((devctl & MUSB_DEVCTL_VBUS)
446 != (3 << MUSB_DEVCTL_VBUS_SHIFT)
448 musb->int_usb |= MUSB_INTR_DISCONNECT;
449 musb->int_usb &= ~MUSB_INTR_SUSPEND;
454 case OTG_STATE_B_IDLE:
455 musb->int_usb &= ~MUSB_INTR_SUSPEND;
459 WARN("bogus %s RESUME (%s)\n",
461 otg_state_string(musb));
466 #ifdef CONFIG_USB_MUSB_HDRC_HCD
467 /* see manual for the order of the tests */
468 if (int_usb & MUSB_INTR_SESSREQ) {
469 DBG(1, "SESSION_REQUEST (%s)\n", otg_state_string(musb));
471 /* IRQ arrives from ID pin sense or (later, if VBUS power
472 * is removed) SRP. responses are time critical:
473 * - turn on VBUS (with silicon-specific mechanism)
474 * - go through A_WAIT_VRISE
475 * - ... to A_WAIT_BCON.
476 * a_wait_vrise_tmout triggers VBUS_ERROR transitions
478 musb_writeb(mbase, MUSB_DEVCTL, MUSB_DEVCTL_SESSION);
479 musb->ep0_stage = MUSB_EP0_START;
480 musb->xceiv.state = OTG_STATE_A_IDLE;
482 musb_set_vbus(musb, 1);
484 handled = IRQ_HANDLED;
487 if (int_usb & MUSB_INTR_VBUSERROR) {
490 /* During connection as an A-Device, we may see a short
491 * current spikes causing voltage drop, because of cable
492 * and peripheral capacitance combined with vbus draw.
493 * (So: less common with truly self-powered devices, where
494 * vbus doesn't act like a power supply.)
496 * Such spikes are short; usually less than ~500 usec, max
497 * of ~2 msec. That is, they're not sustained overcurrent
498 * errors, though they're reported using VBUSERROR irqs.
500 * Workarounds: (a) hardware: use self powered devices.
501 * (b) software: ignore non-repeated VBUS errors.
503 * REVISIT: do delays from lots of DEBUG_KERNEL checks
504 * make trouble here, keeping VBUS < 4.4V ?
506 switch (musb->xceiv.state) {
507 case OTG_STATE_A_HOST:
508 /* recovery is dicey once we've gotten past the
509 * initial stages of enumeration, but if VBUS
510 * stayed ok at the other end of the link, and
511 * another reset is due (at least for high speed,
512 * to redo the chirp etc), it might work OK...
514 case OTG_STATE_A_WAIT_BCON:
515 case OTG_STATE_A_WAIT_VRISE:
516 if (musb->vbuserr_retry) {
517 musb->vbuserr_retry--;
519 devctl |= MUSB_DEVCTL_SESSION;
520 musb_writeb(mbase, MUSB_DEVCTL, devctl);
522 musb->port1_status |=
523 (1 << USB_PORT_FEAT_OVER_CURRENT)
524 | (1 << USB_PORT_FEAT_C_OVER_CURRENT);
531 DBG(1, "VBUS_ERROR in %s (%02x, %s), retry #%d, port1 %08x\n",
532 otg_state_string(musb),
535 switch (devctl & MUSB_DEVCTL_VBUS) {
536 case 0 << MUSB_DEVCTL_VBUS_SHIFT:
537 s = "<SessEnd"; break;
538 case 1 << MUSB_DEVCTL_VBUS_SHIFT:
539 s = "<AValid"; break;
540 case 2 << MUSB_DEVCTL_VBUS_SHIFT:
541 s = "<VBusValid"; break;
542 /* case 3 << MUSB_DEVCTL_VBUS_SHIFT: */
546 VBUSERR_RETRY_COUNT - musb->vbuserr_retry,
549 /* go through A_WAIT_VFALL then start a new session */
551 musb_set_vbus(musb, 0);
552 handled = IRQ_HANDLED;
555 if (int_usb & MUSB_INTR_CONNECT) {
556 struct usb_hcd *hcd = musb_to_hcd(musb);
558 handled = IRQ_HANDLED;
560 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
562 musb->ep0_stage = MUSB_EP0_START;
564 #ifdef CONFIG_USB_MUSB_OTG
565 /* flush endpoints when transitioning from Device Mode */
566 if (is_peripheral_active(musb)) {
567 /* REVISIT HNP; just force disconnect */
569 musb_writew(mbase, MUSB_INTRTXE, musb->epmask);
570 musb_writew(mbase, MUSB_INTRRXE, musb->epmask & 0xfffe);
571 musb_writeb(mbase, MUSB_INTRUSBE, 0xf7);
573 musb->port1_status &= ~(USB_PORT_STAT_LOW_SPEED
574 |USB_PORT_STAT_HIGH_SPEED
575 |USB_PORT_STAT_ENABLE
577 musb->port1_status |= USB_PORT_STAT_CONNECTION
578 |(USB_PORT_STAT_C_CONNECTION << 16);
580 /* high vs full speed is just a guess until after reset */
581 if (devctl & MUSB_DEVCTL_LSDEV)
582 musb->port1_status |= USB_PORT_STAT_LOW_SPEED;
585 usb_hcd_poll_rh_status(hcd);
587 usb_hcd_resume_root_hub(hcd);
591 /* indicate new connection to OTG machine */
592 switch (musb->xceiv.state) {
593 case OTG_STATE_B_PERIPHERAL:
594 if (int_usb & MUSB_INTR_SUSPEND) {
595 DBG(1, "HNP: SUSPEND+CONNECT, now b_host\n");
596 musb->xceiv.state = OTG_STATE_B_HOST;
597 hcd->self.is_b_host = 1;
598 int_usb &= ~MUSB_INTR_SUSPEND;
600 DBG(1, "CONNECT as b_peripheral???\n");
602 case OTG_STATE_B_WAIT_ACON:
603 DBG(1, "HNP: Waiting to switch to b_host state\n");
604 musb->xceiv.state = OTG_STATE_B_HOST;
605 hcd->self.is_b_host = 1;
608 if ((devctl & MUSB_DEVCTL_VBUS)
609 == (3 << MUSB_DEVCTL_VBUS_SHIFT)) {
610 musb->xceiv.state = OTG_STATE_A_HOST;
611 hcd->self.is_b_host = 0;
615 DBG(1, "CONNECT (%s) devctl %02x\n",
616 otg_state_string(musb), devctl);
618 #endif /* CONFIG_USB_MUSB_HDRC_HCD */
620 /* mentor saves a bit: bus reset and babble share the same irq.
621 * only host sees babble; only peripheral sees bus reset.
623 if (int_usb & MUSB_INTR_RESET) {
624 if (is_host_capable() && (devctl & MUSB_DEVCTL_HM) != 0) {
626 * Looks like non-HS BABBLE can be ignored, but
627 * HS BABBLE is an error condition. For HS the solution
628 * is to avoid babble in the first place and fix what
629 * caused BABBLE. When HS BABBLE happens we can only
632 if (devctl & (MUSB_DEVCTL_FSDEV | MUSB_DEVCTL_LSDEV))
633 DBG(1, "BABBLE devctl: %02x\n", devctl);
635 ERR("Stopping host session -- babble\n");
636 musb_writeb(mbase, MUSB_DEVCTL, 0);
638 } else if (is_peripheral_capable()) {
639 DBG(1, "BUS RESET as %s\n", otg_state_string(musb));
640 switch (musb->xceiv.state) {
641 case OTG_STATE_A_PERIPHERAL:
642 case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */
645 case OTG_STATE_B_PERIPHERAL:
649 DBG(1, "Unhandled BUS RESET as %s\n",
650 otg_state_string(musb));
652 schedule_work(&musb->irq_work);
655 handled = IRQ_HANDLED;
662 * Interrupt Service Routine to record USB "global" interrupts.
663 * Since these do not happen often and signify things of
664 * paramount importance, it seems OK to check them individually;
665 * the order of the tests is specified in the manual
667 * @param musb instance pointer
668 * @param int_usb register contents
672 static irqreturn_t musb_stage2_irq(struct musb * musb, u8 int_usb,
675 irqreturn_t handled = IRQ_NONE;
678 /* REVISIT ... this would be for multiplexing periodic endpoints, or
679 * supporting transfer phasing to prevent exceeding ISO bandwidth
680 * limits of a given frame or microframe.
682 * It's not needed for peripheral side, which dedicates endpoints;
683 * though it _might_ use SOF irqs for other purposes.
685 * And it's not currently needed for host side, which also dedicates
686 * endpoints, relies on TX/RX interval registers, and isn't claimed
687 * to support ISO transfers yet.
689 if (int_usb & MUSB_INTR_SOF) {
690 void __iomem *mbase = musb->mregs;
691 struct musb_hw_ep *ep;
695 DBG(6, "START_OF_FRAME\n");
696 handled = IRQ_HANDLED;
698 /* start any periodic Tx transfers waiting for current frame */
699 frame = musb_readw(mbase, MUSB_FRAME);
700 ep = musb->endpoints;
701 for (epnum = 1; (epnum < musb->nr_endpoints)
702 && (musb->epmask >= (1 << epnum));
705 * FIXME handle framecounter wraps (12 bits)
706 * eliminate duplicated StartUrb logic
708 if (ep->dwWaitFrame >= frame) {
710 printk("SOF --> periodic TX%s on %d\n",
711 ep->tx_channel ? " DMA" : "",
714 musb_h_tx_start(musb, epnum);
716 cppi_hostdma_start(musb, epnum);
718 } /* end of for loop */
722 if ((int_usb & MUSB_INTR_DISCONNECT) && !musb->ignore_disconnect) {
723 DBG(1, "DISCONNECT (%s) as %s, devctl %02x\n",
724 otg_state_string(musb),
725 MUSB_MODE(musb), devctl);
726 handled = IRQ_HANDLED;
728 switch (musb->xceiv.state) {
729 #ifdef CONFIG_USB_MUSB_HDRC_HCD
730 case OTG_STATE_A_HOST:
731 case OTG_STATE_A_SUSPEND:
732 musb_root_disconnect(musb);
733 if (musb->a_wait_bcon != 0)
734 musb_platform_try_idle(musb, jiffies
735 + msecs_to_jiffies(musb->a_wait_bcon));
738 #ifdef CONFIG_USB_MUSB_OTG
739 case OTG_STATE_B_HOST:
742 case OTG_STATE_A_PERIPHERAL:
744 musb_root_disconnect(musb);
746 case OTG_STATE_B_WAIT_ACON:
749 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
750 case OTG_STATE_B_PERIPHERAL:
751 case OTG_STATE_B_IDLE:
752 musb_g_disconnect(musb);
756 WARN("unhandled DISCONNECT transition (%s)\n",
757 otg_state_string(musb));
761 schedule_work(&musb->irq_work);
764 if (int_usb & MUSB_INTR_SUSPEND) {
765 DBG(1, "SUSPEND (%s) devctl %02x power %02x\n",
766 otg_state_string(musb), devctl, power);
767 handled = IRQ_HANDLED;
769 switch (musb->xceiv.state) {
770 #ifdef CONFIG_USB_MUSB_OTG
771 case OTG_STATE_A_PERIPHERAL:
773 * We cannot stop HNP here, devctl BDEVICE might be
778 case OTG_STATE_B_PERIPHERAL:
779 musb_g_suspend(musb);
780 musb->is_active = is_otg_enabled(musb)
781 && musb->xceiv.gadget->b_hnp_enable;
782 if (musb->is_active) {
783 musb->xceiv.state = OTG_STATE_B_WAIT_ACON;
784 #ifdef CONFIG_USB_MUSB_OTG
785 DBG(1, "HNP: Setting timer for b_ase0_brst\n");
786 musb_otg_timer.data = (unsigned long)musb;
787 mod_timer(&musb_otg_timer, jiffies
788 + msecs_to_jiffies(TB_ASE0_BRST));
792 case OTG_STATE_A_WAIT_BCON:
793 if (musb->a_wait_bcon != 0)
794 musb_platform_try_idle(musb, jiffies
795 + msecs_to_jiffies(musb->a_wait_bcon));
797 case OTG_STATE_A_HOST:
798 musb->xceiv.state = OTG_STATE_A_SUSPEND;
799 musb->is_active = is_otg_enabled(musb)
800 && musb->xceiv.host->b_hnp_enable;
802 case OTG_STATE_B_HOST:
803 /* Transition to B_PERIPHERAL, see 6.8.2.6 p 44 */
804 DBG(1, "REVISIT: SUSPEND as B_HOST\n");
807 /* "should not happen" */
817 /*-------------------------------------------------------------------------*/
820 * Program the HDRC to start (enable interrupts, dma, etc.).
822 void musb_start(struct musb *musb)
824 void __iomem *regs = musb->mregs;
825 u8 devctl = musb_readb(regs, MUSB_DEVCTL);
827 DBG(2, "<== devctl %02x\n", devctl);
829 /* Set INT enable registers, enable interrupts */
830 musb_writew(regs, MUSB_INTRTXE, musb->epmask);
831 musb_writew(regs, MUSB_INTRRXE, musb->epmask & 0xfffe);
832 musb_writeb(regs, MUSB_INTRUSBE, 0xf7);
834 musb_writeb(regs, MUSB_TESTMODE, 0);
836 /* put into basic highspeed mode and start session */
837 musb_writeb(regs, MUSB_POWER, MUSB_POWER_ISOUPDATE
838 | MUSB_POWER_SOFTCONN
840 /* ENSUSPEND wedges tusb */
841 /* | MUSB_POWER_ENSUSPEND */
845 devctl = musb_readb(regs, MUSB_DEVCTL);
846 devctl &= ~MUSB_DEVCTL_SESSION;
848 if (is_otg_enabled(musb)) {
849 /* session started after:
850 * (a) ID-grounded irq, host mode;
851 * (b) vbus present/connect IRQ, peripheral mode;
852 * (c) peripheral initiates, using SRP
854 if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS)
857 devctl |= MUSB_DEVCTL_SESSION;
859 } else if (is_host_enabled(musb)) {
860 /* assume ID pin is hard-wired to ground */
861 devctl |= MUSB_DEVCTL_SESSION;
863 } else /* peripheral is enabled */ {
864 if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS)
867 musb_platform_enable(musb);
868 musb_writeb(regs, MUSB_DEVCTL, devctl);
872 static void musb_generic_disable(struct musb *musb)
874 void __iomem *mbase = musb->mregs;
877 /* disable interrupts */
878 musb_writeb(mbase, MUSB_INTRUSBE, 0);
879 musb_writew(mbase, MUSB_INTRTXE, 0);
880 musb_writew(mbase, MUSB_INTRRXE, 0);
883 musb_writeb(mbase, MUSB_DEVCTL, 0);
885 /* flush pending interrupts */
886 temp = musb_readb(mbase, MUSB_INTRUSB);
887 temp = musb_readw(mbase, MUSB_INTRTX);
888 temp = musb_readw(mbase, MUSB_INTRRX);
893 * Make the HDRC stop (disable interrupts, etc.);
894 * reversible by musb_start
895 * called on gadget driver unregister
896 * with controller locked, irqs blocked
897 * acts as a NOP unless some role activated the hardware
899 void musb_stop(struct musb *musb)
901 /* stop IRQs, timers, ... */
902 musb_platform_disable(musb);
903 musb_generic_disable(musb);
904 DBG(3, "HDRC disabled\n");
907 * - mark host and/or peripheral drivers unusable/inactive
908 * - disable DMA (and enable it in HdrcStart)
909 * - make sure we can musb_start() after musb_stop(); with
910 * OTG mode, gadget driver module rmmod/modprobe cycles that
913 musb_platform_try_idle(musb, 0);
916 static void musb_shutdown(struct platform_device *pdev)
918 struct musb *musb = dev_to_musb(&pdev->dev);
921 spin_lock_irqsave(&musb->lock, flags);
922 musb_platform_disable(musb);
923 musb_generic_disable(musb);
925 clk_put(musb->clock);
928 spin_unlock_irqrestore(&musb->lock, flags);
930 /* FIXME power down */
934 /*-------------------------------------------------------------------------*/
937 * The silicon either has hard-wired endpoint configurations, or else
938 * "dynamic fifo" sizing. The driver has support for both, though at this
939 * writing only the dynamic sizing is very well tested. We use normal
940 * idioms to so both modes are compile-tested, but dead code elimination
941 * leaves only the relevant one in the object file.
943 * We don't currently use dynamic fifo setup capability to do anything
944 * more than selecting one of a bunch of predefined configurations.
946 #ifdef MUSB_C_DYNFIFO_DEF
947 #define can_dynfifo() 1
949 #define can_dynfifo() 0
952 #ifdef CONFIG_USB_TUSB6010
953 static ushort __initdata fifo_mode = 4;
955 static ushort __initdata fifo_mode = 2;
958 /* "modprobe ... fifo_mode=1" etc */
959 module_param(fifo_mode, ushort, 0);
960 MODULE_PARM_DESC(fifo_mode, "initial endpoint configuration");
963 #define DYN_FIFO_SIZE (1<<(MUSB_C_RAM_BITS+2))
965 enum fifo_style { FIFO_RXTX, FIFO_TX, FIFO_RX } __attribute__ ((packed));
966 enum buf_mode { BUF_SINGLE, BUF_DOUBLE } __attribute__ ((packed));
970 enum fifo_style style;
976 * tables defining fifo_mode values. define more if you like.
977 * for host side, make sure both halves of ep1 are set up.
980 /* mode 0 - fits in 2KB */
981 static struct fifo_cfg __initdata mode_0_cfg[] = {
982 { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
983 { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
984 { .hw_ep_num = 2, .style = FIFO_RXTX, .maxpacket = 512, },
985 { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
986 { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
989 /* mode 1 - fits in 4KB */
990 static struct fifo_cfg __initdata mode_1_cfg[] = {
991 { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, .mode = BUF_DOUBLE, },
992 { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, .mode = BUF_DOUBLE, },
993 { .hw_ep_num = 2, .style = FIFO_RXTX, .maxpacket = 512, .mode = BUF_DOUBLE, },
994 { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
995 { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
998 /* mode 2 - fits in 4KB */
999 static struct fifo_cfg __initdata mode_2_cfg[] = {
1000 { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
1001 { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
1002 { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
1003 { .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
1004 { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
1005 { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
1008 /* mode 3 - fits in 4KB */
1009 static struct fifo_cfg __initdata mode_3_cfg[] = {
1010 { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, .mode = BUF_DOUBLE, },
1011 { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, .mode = BUF_DOUBLE, },
1012 { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
1013 { .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
1014 { .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
1015 { .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
1018 /* mode 4 - fits in 16KB */
1019 static struct fifo_cfg __initdata mode_4_cfg[] = {
1020 { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
1021 { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
1022 { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
1023 { .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
1024 { .hw_ep_num = 3, .style = FIFO_TX, .maxpacket = 512, },
1025 { .hw_ep_num = 3, .style = FIFO_RX, .maxpacket = 512, },
1026 { .hw_ep_num = 4, .style = FIFO_TX, .maxpacket = 512, },
1027 { .hw_ep_num = 4, .style = FIFO_RX, .maxpacket = 512, },
1028 { .hw_ep_num = 5, .style = FIFO_TX, .maxpacket = 512, },
1029 { .hw_ep_num = 5, .style = FIFO_RX, .maxpacket = 512, },
1030 { .hw_ep_num = 6, .style = FIFO_TX, .maxpacket = 512, },
1031 { .hw_ep_num = 6, .style = FIFO_RX, .maxpacket = 512, },
1032 { .hw_ep_num = 7, .style = FIFO_TX, .maxpacket = 512, },
1033 { .hw_ep_num = 7, .style = FIFO_RX, .maxpacket = 512, },
1034 { .hw_ep_num = 8, .style = FIFO_TX, .maxpacket = 512, },
1035 { .hw_ep_num = 8, .style = FIFO_RX, .maxpacket = 512, },
1036 { .hw_ep_num = 9, .style = FIFO_TX, .maxpacket = 512, },
1037 { .hw_ep_num = 9, .style = FIFO_RX, .maxpacket = 512, },
1038 { .hw_ep_num = 10, .style = FIFO_TX, .maxpacket = 512, },
1039 { .hw_ep_num = 10, .style = FIFO_RX, .maxpacket = 512, },
1040 { .hw_ep_num = 11, .style = FIFO_TX, .maxpacket = 512, },
1041 { .hw_ep_num = 11, .style = FIFO_RX, .maxpacket = 512, },
1042 { .hw_ep_num = 12, .style = FIFO_TX, .maxpacket = 512, },
1043 { .hw_ep_num = 12, .style = FIFO_RX, .maxpacket = 512, },
1044 { .hw_ep_num = 13, .style = FIFO_TX, .maxpacket = 512, },
1045 { .hw_ep_num = 13, .style = FIFO_RX, .maxpacket = 512, },
1046 { .hw_ep_num = 14, .style = FIFO_RXTX, .maxpacket = 1024, },
1047 { .hw_ep_num = 15, .style = FIFO_RXTX, .maxpacket = 1024, },
1052 * configure a fifo; for non-shared endpoints, this may be called
1053 * once for a tx fifo and once for an rx fifo.
1055 * returns negative errno or offset for next fifo.
1058 fifo_setup(struct musb *musb, struct musb_hw_ep *hw_ep,
1059 const struct fifo_cfg *cfg, u16 offset)
1061 void __iomem *mbase = musb->mregs;
1063 u16 maxpacket = cfg->maxpacket;
1064 u16 c_off = offset >> 3;
1067 /* expect hw_ep has already been zero-initialized */
1069 size = ffs(max(maxpacket, (u16) 8)) - 1;
1070 maxpacket = 1 << size;
1073 if (cfg->mode == BUF_DOUBLE) {
1074 if ((offset + (maxpacket << 1)) > DYN_FIFO_SIZE)
1076 c_size |= MUSB_FIFOSZ_DPB;
1078 if ((offset + maxpacket) > DYN_FIFO_SIZE)
1082 /* configure the FIFO */
1083 musb_writeb(mbase, MUSB_INDEX, hw_ep->epnum);
1085 #ifdef CONFIG_USB_MUSB_HDRC_HCD
1086 /* EP0 reserved endpoint for control, bidirectional;
1087 * EP1 reserved for bulk, two unidirection halves.
1089 if (hw_ep->epnum == 1)
1090 musb->bulk_ep = hw_ep;
1091 /* REVISIT error check: be sure ep0 can both rx and tx ... */
1093 switch (cfg->style) {
1095 musb_writeb(mbase, MUSB_TXFIFOSZ, c_size);
1096 musb_writew(mbase, MUSB_TXFIFOADD, c_off);
1097 hw_ep->tx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
1098 hw_ep->max_packet_sz_tx = maxpacket;
1101 musb_writeb(mbase, MUSB_RXFIFOSZ, c_size);
1102 musb_writew(mbase, MUSB_RXFIFOADD, c_off);
1103 hw_ep->rx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
1104 hw_ep->max_packet_sz_rx = maxpacket;
1107 musb_writeb(mbase, MUSB_TXFIFOSZ, c_size);
1108 musb_writew(mbase, MUSB_TXFIFOADD, c_off);
1109 hw_ep->rx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
1110 hw_ep->max_packet_sz_rx = maxpacket;
1112 musb_writeb(mbase, MUSB_RXFIFOSZ, c_size);
1113 musb_writew(mbase, MUSB_RXFIFOADD, c_off);
1114 hw_ep->tx_double_buffered = hw_ep->rx_double_buffered;
1115 hw_ep->max_packet_sz_tx = maxpacket;
1117 hw_ep->is_shared_fifo = true;
1121 /* NOTE rx and tx endpoint irqs aren't managed separately,
1122 * which happens to be ok
1124 musb->epmask |= (1 << hw_ep->epnum);
1126 return offset + (maxpacket << ((c_size & MUSB_FIFOSZ_DPB) ? 1 : 0));
1129 static struct fifo_cfg __initdata ep0_cfg = {
1130 .style = FIFO_RXTX, .maxpacket = 64,
1133 static int __init ep_config_from_table(struct musb *musb)
1135 const struct fifo_cfg *cfg;
1138 struct musb_hw_ep *hw_ep = musb->endpoints;
1140 switch (fifo_mode) {
1146 n = ARRAY_SIZE(mode_0_cfg);
1150 n = ARRAY_SIZE(mode_1_cfg);
1154 n = ARRAY_SIZE(mode_2_cfg);
1158 n = ARRAY_SIZE(mode_3_cfg);
1162 n = ARRAY_SIZE(mode_4_cfg);
1166 printk(KERN_DEBUG "%s: setup fifo_mode %d\n",
1167 musb_driver_name, fifo_mode);
1170 offset = fifo_setup(musb, hw_ep, &ep0_cfg, 0);
1171 /* assert(offset > 0) */
1173 /* NOTE: for RTL versions >= 1.400 EPINFO and RAMINFO would
1174 * be better than static MUSB_C_NUM_EPS and DYN_FIFO_SIZE...
1177 for (i = 0; i < n; i++) {
1178 u8 epn = cfg->hw_ep_num;
1180 if (epn >= MUSB_C_NUM_EPS) {
1181 pr_debug( "%s: invalid ep %d\n",
1182 musb_driver_name, epn);
1185 offset = fifo_setup(musb, hw_ep + epn, cfg++, offset);
1187 pr_debug( "%s: mem overrun, ep %d\n",
1188 musb_driver_name, epn);
1192 musb->nr_endpoints = max(epn, musb->nr_endpoints);
1195 printk(KERN_DEBUG "%s: %d/%d max ep, %d/%d memory\n",
1197 n + 1, MUSB_C_NUM_EPS * 2 - 1,
1198 offset, DYN_FIFO_SIZE);
1200 #ifdef CONFIG_USB_MUSB_HDRC_HCD
1201 if (!musb->bulk_ep) {
1202 pr_debug( "%s: missing bulk\n", musb_driver_name);
1212 * ep_config_from_hw - when MUSB_C_DYNFIFO_DEF is false
1213 * @param musb the controller
1215 static int __init ep_config_from_hw(struct musb *musb)
1218 struct musb_hw_ep *hw_ep;
1219 void *mbase = musb->mregs;
1221 DBG(2, "<== static silicon ep config\n");
1223 /* FIXME pick up ep0 maxpacket size */
1225 for (epnum = 1; epnum < MUSB_C_NUM_EPS; epnum++) {
1226 musb_ep_select(mbase, epnum);
1227 hw_ep = musb->endpoints + epnum;
1229 /* read from core using indexed model */
1230 reg = musb_readb(hw_ep->regs, 0x10 + MUSB_FIFOSIZE);
1232 /* 0's returned when no more endpoints */
1235 musb->nr_endpoints++;
1236 musb->epmask |= (1 << epnum);
1238 hw_ep->max_packet_sz_tx = 1 << (reg & 0x0f);
1240 /* shared TX/RX FIFO? */
1241 if ((reg & 0xf0) == 0xf0) {
1242 hw_ep->max_packet_sz_rx = hw_ep->max_packet_sz_tx;
1243 hw_ep->is_shared_fifo = true;
1246 hw_ep->max_packet_sz_rx = 1 << ((reg & 0xf0) >> 4);
1247 hw_ep->is_shared_fifo = false;
1250 /* FIXME set up hw_ep->{rx,tx}_double_buffered */
1252 #ifdef CONFIG_USB_MUSB_HDRC_HCD
1253 /* pick an RX/TX endpoint for bulk */
1254 if (hw_ep->max_packet_sz_tx < 512
1255 || hw_ep->max_packet_sz_rx < 512)
1258 /* REVISIT: this algorithm is lazy, we should at least
1259 * try to pick a double buffered endpoint.
1263 musb->bulk_ep = hw_ep;
1267 #ifdef CONFIG_USB_MUSB_HDRC_HCD
1268 if (!musb->bulk_ep) {
1269 pr_debug( "%s: missing bulk\n", musb_driver_name);
1277 enum { MUSB_CONTROLLER_MHDRC, MUSB_CONTROLLER_HDRC, };
1279 /* Initialize MUSB (M)HDRC part of the USB hardware subsystem;
1280 * configure endpoints, or take their config from silicon
1282 static int __init musb_core_init(u16 musb_type, struct musb *musb)
1289 u16 hwvers, rev_major, rev_minor;
1290 char aInfo[78], aRevision[32], aDate[12];
1291 void __iomem *mbase = musb->mregs;
1295 /* log core options (read using indexed model) */
1296 musb_ep_select(mbase, 0);
1297 reg = musb_readb(mbase, 0x10 + MUSB_CONFIGDATA);
1299 strcpy(aInfo, (reg & MUSB_CONFIGDATA_UTMIDW) ? "UTMI-16" : "UTMI-8");
1300 if (reg & MUSB_CONFIGDATA_DYNFIFO) {
1301 strcat(aInfo, ", dyn FIFOs");
1303 if (reg & MUSB_CONFIGDATA_MPRXE) {
1304 strcat(aInfo, ", bulk combine");
1306 musb->bulk_combine = true;
1308 strcat(aInfo, " (X)"); /* no driver support */
1311 if (reg & MUSB_CONFIGDATA_MPTXE) {
1312 strcat(aInfo, ", bulk split");
1314 musb->bulk_split = true;
1316 strcat(aInfo, " (X)"); /* no driver support */
1319 if (reg & MUSB_CONFIGDATA_HBRXE) {
1320 strcat(aInfo, ", HB-ISO Rx");
1321 strcat(aInfo, " (X)"); /* no driver support */
1323 if (reg & MUSB_CONFIGDATA_HBTXE) {
1324 strcat(aInfo, ", HB-ISO Tx");
1325 strcat(aInfo, " (X)"); /* no driver support */
1327 if (reg & MUSB_CONFIGDATA_SOFTCONE) {
1328 strcat(aInfo, ", SoftConn");
1331 printk(KERN_DEBUG "%s: ConfigData=0x%02x (%s)\n",
1332 musb_driver_name, reg, aInfo);
1335 data = musb_readl(mbase, 0x404);
1336 sprintf(aDate, "%04d-%02x-%02x", (data & 0xffff),
1337 (data >> 16) & 0xff, (data >> 24) & 0xff);
1338 /* FIXME ID2 and ID3 are unused */
1339 data = musb_readl(mbase, 0x408);
1340 printk("ID2=%lx\n", (long unsigned)data);
1341 data = musb_readl(mbase, 0x40c);
1342 printk("ID3=%lx\n", (long unsigned)data);
1343 reg = musb_readb(mbase, 0x400);
1344 musb_type = ('M' == reg) ? MUSB_CONTROLLER_MHDRC : MUSB_CONTROLLER_HDRC;
1348 if (MUSB_CONTROLLER_MHDRC == musb_type) {
1349 musb->is_multipoint = 1;
1352 musb->is_multipoint = 0;
1354 #ifdef CONFIG_USB_MUSB_HDRC_HCD
1355 #ifndef CONFIG_USB_OTG_BLACKLIST_HUB
1357 "%s: kernel must blacklist external hubs\n",
1363 /* log release info */
1364 hwvers = musb_readw(mbase, MUSB_HWVERS);
1365 rev_major = (hwvers >> 10) & 0x1f;
1366 rev_minor = hwvers & 0x3ff;
1367 snprintf(aRevision, 32, "%d.%d%s", rev_major,
1368 rev_minor, (hwvers & 0x8000) ? "RC" : "");
1369 printk(KERN_DEBUG "%s: %sHDRC RTL version %s %s\n",
1370 musb_driver_name, type, aRevision, aDate);
1373 musb->endpoints[0].max_packet_sz_tx = MUSB_EP0_FIFOSIZE;
1374 musb->endpoints[0].max_packet_sz_rx = MUSB_EP0_FIFOSIZE;
1376 /* discover endpoint configuration */
1377 musb->nr_endpoints = 1;
1380 if (reg & MUSB_CONFIGDATA_DYNFIFO) {
1382 status = ep_config_from_table(musb);
1384 ERR("reconfigure software for Dynamic FIFOs\n");
1389 status = ep_config_from_hw(musb);
1391 ERR("reconfigure software for static FIFOs\n");
1399 /* finish init, and print endpoint config */
1400 for (i = 0; i < musb->nr_endpoints; i++) {
1401 struct musb_hw_ep *hw_ep = musb->endpoints + i;
1403 hw_ep->fifo = MUSB_FIFO_OFFSET(i) + mbase;
1404 #ifdef CONFIG_USB_TUSB6010
1405 hw_ep->fifo_async = musb->async + 0x400 + MUSB_FIFO_OFFSET(i);
1406 hw_ep->fifo_sync = musb->sync + 0x400 + MUSB_FIFO_OFFSET(i);
1407 hw_ep->fifo_sync_va =
1408 musb->sync_va + 0x400 + MUSB_FIFO_OFFSET(i);
1411 hw_ep->conf = mbase - 0x400 + TUSB_EP0_CONF;
1413 hw_ep->conf = mbase + 0x400 + (((i - 1) & 0xf) << 2);
1416 hw_ep->regs = MUSB_EP_OFFSET(i, 0) + mbase;
1417 #ifdef CONFIG_USB_MUSB_HDRC_HCD
1418 hw_ep->target_regs = MUSB_BUSCTL_OFFSET(i, 0) + mbase;
1419 hw_ep->rx_reinit = 1;
1420 hw_ep->tx_reinit = 1;
1423 if (hw_ep->max_packet_sz_tx) {
1425 "%s: hw_ep %d%s, %smax %d\n",
1426 musb_driver_name, i,
1427 hw_ep->is_shared_fifo ? "shared" : "tx",
1428 hw_ep->tx_double_buffered
1429 ? "doublebuffer, " : "",
1430 hw_ep->max_packet_sz_tx);
1432 if (hw_ep->max_packet_sz_rx && !hw_ep->is_shared_fifo) {
1434 "%s: hw_ep %d%s, %smax %d\n",
1435 musb_driver_name, i,
1437 hw_ep->rx_double_buffered
1438 ? "doublebuffer, " : "",
1439 hw_ep->max_packet_sz_rx);
1441 if (!(hw_ep->max_packet_sz_tx || hw_ep->max_packet_sz_rx))
1442 DBG(1, "hw_ep %d not configured\n", i);
1448 /*-------------------------------------------------------------------------*/
1450 #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3430)
1452 static irqreturn_t generic_interrupt(int irq, void *__hci)
1454 unsigned long flags;
1455 irqreturn_t retval = IRQ_NONE;
1456 struct musb *musb = __hci;
1458 spin_lock_irqsave(&musb->lock, flags);
1460 musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB);
1461 musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX);
1462 musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX);
1464 if (musb->int_usb || musb->int_tx || musb->int_rx)
1465 retval = musb_interrupt(musb);
1467 spin_unlock_irqrestore(&musb->lock, flags);
1469 /* REVISIT we sometimes get spurious IRQs on g_ep0
1472 if (retval != IRQ_HANDLED)
1473 DBG(5, "spurious?\n");
1479 #define generic_interrupt NULL
1483 * handle all the irqs defined by the HDRC core. for now we expect: other
1484 * irq sources (phy, dma, etc) will be handled first, musb->int_* values
1485 * will be assigned, and the irq will already have been acked.
1487 * called in irq context with spinlock held, irqs blocked
1489 irqreturn_t musb_interrupt(struct musb *musb)
1491 irqreturn_t retval = IRQ_NONE;
1496 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
1497 power = musb_readb(musb->mregs, MUSB_POWER);
1499 DBG(4, "** IRQ %s usb%04x tx%04x rx%04x\n",
1500 (devctl & MUSB_DEVCTL_HM) ? "host" : "peripheral",
1501 musb->int_usb, musb->int_tx, musb->int_rx);
1503 /* the core can interrupt us for multiple reasons; docs have
1504 * a generic interrupt flowchart to follow
1506 if (musb->int_usb & STAGE0_MASK)
1507 retval |= musb_stage0_irq(musb, musb->int_usb,
1510 /* "stage 1" is handling endpoint irqs */
1512 /* handle endpoint 0 first */
1513 if (musb->int_tx & 1) {
1514 if (devctl & MUSB_DEVCTL_HM)
1515 retval |= musb_h_ep0_irq(musb);
1517 retval |= musb_g_ep0_irq(musb);
1520 /* RX on endpoints 1-15 */
1521 reg = musb->int_rx >> 1;
1525 /* musb_ep_select(musb->mregs, ep_num); */
1526 /* REVISIT just retval = ep->rx_irq(...) */
1527 retval = IRQ_HANDLED;
1528 if (devctl & MUSB_DEVCTL_HM) {
1529 if (is_host_capable())
1530 musb_host_rx(musb, ep_num);
1532 if (is_peripheral_capable())
1533 musb_g_rx(musb, ep_num);
1541 /* TX on endpoints 1-15 */
1542 reg = musb->int_tx >> 1;
1546 /* musb_ep_select(musb->mregs, ep_num); */
1547 /* REVISIT just retval |= ep->tx_irq(...) */
1548 retval = IRQ_HANDLED;
1549 if (devctl & MUSB_DEVCTL_HM) {
1550 if (is_host_capable())
1551 musb_host_tx(musb, ep_num);
1553 if (is_peripheral_capable())
1554 musb_g_tx(musb, ep_num);
1561 /* finish handling "global" interrupts after handling fifos */
1563 retval |= musb_stage2_irq(musb,
1564 musb->int_usb, devctl, power);
1570 #ifndef CONFIG_MUSB_PIO_ONLY
1571 static int __initdata use_dma = 1;
1573 /* "modprobe ... use_dma=0" etc */
1574 module_param(use_dma, bool, 0);
1575 MODULE_PARM_DESC(use_dma, "enable/disable use of DMA");
1577 void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit)
1579 u8 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
1581 /* called with controller lock already held */
1584 #ifndef CONFIG_USB_TUSB_OMAP_DMA
1585 if (!is_cppi_enabled()) {
1587 if (devctl & MUSB_DEVCTL_HM)
1588 musb_h_ep0_irq(musb);
1590 musb_g_ep0_irq(musb);
1594 /* endpoints 1..15 */
1596 if (devctl & MUSB_DEVCTL_HM) {
1597 if (is_host_capable())
1598 musb_host_tx(musb, epnum);
1600 if (is_peripheral_capable())
1601 musb_g_tx(musb, epnum);
1605 if (devctl & MUSB_DEVCTL_HM) {
1606 if (is_host_capable())
1607 musb_host_rx(musb, epnum);
1609 if (is_peripheral_capable())
1610 musb_g_rx(musb, epnum);
1620 /*-------------------------------------------------------------------------*/
1625 musb_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
1627 struct musb *musb = dev_to_musb(dev);
1628 unsigned long flags;
1631 spin_lock_irqsave(&musb->lock, flags);
1632 ret = sprintf(buf, "%s\n", otg_state_string(musb));
1633 spin_unlock_irqrestore(&musb->lock, flags);
1639 musb_mode_store(struct device *dev, struct device_attribute *attr,
1640 const char *buf, size_t n)
1642 struct musb *musb = dev_to_musb(dev);
1643 unsigned long flags;
1645 spin_lock_irqsave(&musb->lock, flags);
1646 if (!strncmp(buf, "host", 4))
1647 musb_platform_set_mode(musb, MUSB_HOST);
1648 if (!strncmp(buf, "peripheral", 10))
1649 musb_platform_set_mode(musb, MUSB_PERIPHERAL);
1650 if (!strncmp(buf, "otg", 3))
1651 musb_platform_set_mode(musb, MUSB_OTG);
1652 spin_unlock_irqrestore(&musb->lock, flags);
1656 static DEVICE_ATTR(mode, 0644, musb_mode_show, musb_mode_store);
1659 musb_cable_show(struct device *dev, struct device_attribute *attr, char *buf)
1661 struct musb *musb = dev_to_musb(dev);
1662 char *v1= "", *v2 = "?";
1663 unsigned long flags;
1666 spin_lock_irqsave(&musb->lock, flags);
1667 #if defined(CONFIG_USB_TUSB6010) && !defined(CONFIG_USB_MUSB_OTG)
1668 /* REVISIT: connect-A != connect-B ... */
1669 vbus = musb_platform_get_vbus_status(musb);
1673 v2 = "disconnected";
1675 /* NOTE: board-specific issues, like too-big capacitors keeping
1676 * VBUS high for a long time after power has been removed, can
1677 * cause temporary false indications of a connection.
1679 vbus = musb_readb(musb->mregs, MUSB_DEVCTL);
1681 /* REVISIT retest on real OTG hardware */
1682 switch (musb->board_mode) {
1686 case MUSB_PERIPHERAL:
1691 v2 = (vbus & MUSB_DEVCTL_BDEVICE) ? "B" : "A";
1694 } else /* VBUS level below A-Valid */
1695 v2 = "disconnected";
1697 musb_platform_try_idle(musb, 0);
1698 spin_unlock_irqrestore(&musb->lock, flags);
1700 return sprintf(buf, "%s%s\n", v1, v2);
1702 static DEVICE_ATTR(cable, S_IRUGO, musb_cable_show, NULL);
1705 musb_vbus_store(struct device *dev, struct device_attribute *attr,
1706 const char *buf, size_t n)
1708 struct musb *musb = dev_to_musb(dev);
1709 unsigned long flags;
1712 spin_lock_irqsave(&musb->lock, flags);
1713 if (sscanf(buf, "%lu", &val) < 1) {
1714 printk(KERN_ERR "Invalid VBUS timeout ms value\n");
1717 musb->a_wait_bcon = val;
1718 if (musb->xceiv.state == OTG_STATE_A_WAIT_BCON)
1719 musb->is_active = 0;
1720 musb_platform_try_idle(musb, jiffies + msecs_to_jiffies(val));
1721 spin_unlock_irqrestore(&musb->lock, flags);
1727 musb_vbus_show(struct device *dev, struct device_attribute *attr, char *buf)
1729 struct musb *musb = dev_to_musb(dev);
1730 unsigned long flags;
1733 spin_lock_irqsave(&musb->lock, flags);
1734 val = musb->a_wait_bcon;
1735 spin_unlock_irqrestore(&musb->lock, flags);
1737 return sprintf(buf, "%lu\n", val);
1739 static DEVICE_ATTR(vbus, 0644, musb_vbus_show, musb_vbus_store);
1741 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
1743 /* Gadget drivers can't know that a host is connected so they might want
1744 * to start SRP, but users can. This allows userspace to trigger SRP.
1747 musb_srp_store(struct device *dev, struct device_attribute *attr,
1748 const char *buf, size_t n)
1750 struct musb *musb=dev_to_musb(dev);
1753 if (sscanf(buf, "%hu", &srp) != 1
1755 printk (KERN_ERR "SRP: Value must be 1\n");
1760 musb_g_wakeup(musb);
1764 static DEVICE_ATTR(srp, 0644, NULL, musb_srp_store);
1766 #endif /* CONFIG_USB_GADGET_MUSB_HDRC */
1770 /* Only used to provide driver mode change events */
1771 static void musb_irq_work(struct work_struct *data)
1773 struct musb *musb = container_of(data, struct musb, irq_work);
1774 static int old_state;
1776 if (musb->xceiv.state != old_state) {
1777 old_state = musb->xceiv.state;
1778 sysfs_notify(&musb->controller->kobj, NULL, "cable");
1779 sysfs_notify(&musb->controller->kobj, NULL, "mode");
1783 /* --------------------------------------------------------------------------
1787 static struct musb *__init
1788 allocate_instance(struct device *dev, void __iomem *mbase)
1791 struct musb_hw_ep *ep;
1793 #ifdef CONFIG_USB_MUSB_HDRC_HCD
1794 struct usb_hcd *hcd;
1796 hcd = usb_create_hcd(&musb_hc_driver, dev, dev->bus_id);
1799 /* usbcore sets dev->driver_data to hcd, and sometimes uses that... */
1801 musb = hcd_to_musb(hcd);
1802 INIT_LIST_HEAD(&musb->control);
1803 INIT_LIST_HEAD(&musb->in_bulk);
1804 INIT_LIST_HEAD(&musb->out_bulk);
1806 hcd->uses_new_polling = 1;
1808 musb->vbuserr_retry = VBUSERR_RETRY_COUNT;
1810 musb = kzalloc(sizeof *musb, GFP_KERNEL);
1813 dev_set_drvdata(dev, musb);
1817 musb->mregs = mbase;
1818 musb->ctrl_base = mbase;
1819 musb->nIrq = -ENODEV;
1820 for (epnum = 0, ep = musb->endpoints;
1821 epnum < MUSB_C_NUM_EPS;
1828 #ifdef CONFIG_USB_MUSB_OTG
1829 otg_set_transceiver(&musb->xceiv);
1831 musb->controller = dev;
1835 static void musb_free(struct musb *musb)
1837 /* this has multiple entry modes. it handles fault cleanup after
1838 * probe(), where things may be partially set up, as well as rmmod
1839 * cleanup after everything's been de-activated.
1843 device_remove_file(musb->controller, &dev_attr_mode);
1844 device_remove_file(musb->controller, &dev_attr_cable);
1845 device_remove_file(musb->controller, &dev_attr_vbus);
1846 #ifdef CONFIG_USB_MUSB_OTG
1847 device_remove_file(musb->controller, &dev_attr_srp);
1851 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
1852 musb_gadget_cleanup(musb);
1855 if (musb->nIrq >= 0) {
1856 disable_irq_wake(musb->nIrq);
1857 free_irq(musb->nIrq, musb);
1859 if (is_dma_capable() && musb->dma_controller) {
1860 struct dma_controller *c = musb->dma_controller;
1862 (void) c->stop(c->private_data);
1863 dma_controller_destroy(c);
1866 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
1867 musb_platform_exit(musb);
1868 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
1871 clk_disable(musb->clock);
1872 clk_put(musb->clock);
1875 #ifdef CONFIG_USB_MUSB_OTG
1876 put_device(musb->xceiv.dev);
1879 #ifdef CONFIG_USB_MUSB_HDRC_HCD
1880 usb_put_hcd(musb_to_hcd(musb));
1887 * Perform generic per-controller initialization.
1889 * @pDevice: the controller (already clocked, etc)
1891 * @mregs: virtual address of controller registers,
1892 * not yet corrected for platform-specific offsets
1895 musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1899 struct musb_hdrc_platform_data *plat = dev->platform_data;
1901 /* The driver might handle more features than the board; OK.
1902 * Fail when the board needs a feature that's not enabled.
1905 dev_dbg(dev, "no platform_data?\n");
1908 switch (plat->mode) {
1910 #ifdef CONFIG_USB_MUSB_HDRC_HCD
1915 case MUSB_PERIPHERAL:
1916 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
1922 #ifdef CONFIG_USB_MUSB_OTG
1928 dev_err(dev, "incompatible Kconfig role setting\n");
1933 musb = allocate_instance(dev, ctrl);
1937 spin_lock_init(&musb->lock);
1938 musb->board_mode = plat->mode;
1939 musb->board_set_power = plat->set_power;
1940 musb->set_clock = plat->set_clock;
1941 musb->min_power = plat->min_power;
1943 /* Clock usage is chip-specific ... functional clock (DaVinci,
1944 * OMAP2430), or PHY ref (some TUSB6010 boards). All this core
1945 * code does is make sure a clock handle is available; platform
1946 * code manages it during start/stop and suspend/resume.
1949 musb->clock = clk_get(dev, plat->clock);
1950 if (IS_ERR(musb->clock)) {
1951 status = PTR_ERR(musb->clock);
1957 /* assume vbus is off */
1959 /* platform adjusts musb->mregs and musb->isr if needed,
1960 * and activates clocks
1962 musb->isr = generic_interrupt;
1963 status = musb_platform_init(musb);
1972 #ifndef CONFIG_MUSB_PIO_ONLY
1973 if (use_dma && dev->dma_mask) {
1974 struct dma_controller *c;
1976 c = dma_controller_create(musb, musb->mregs);
1977 musb->dma_controller = c;
1979 (void) c->start(c->private_data);
1982 /* ideally this would be abstracted in platform setup */
1983 if (!is_dma_capable() || !musb->dma_controller)
1984 dev->dma_mask = NULL;
1986 /* be sure interrupts are disabled before connecting ISR */
1987 musb_platform_disable(musb);
1988 musb_generic_disable(musb);
1990 /* setup musb parts of the core (especially endpoints) */
1991 status = musb_core_init(plat->multipoint
1992 ? MUSB_CONTROLLER_MHDRC
1993 : MUSB_CONTROLLER_HDRC, musb);
1997 /* attach to the IRQ */
1998 if (request_irq (nIrq, musb->isr, 0, dev->bus_id, musb)) {
1999 dev_err(dev, "request_irq %d failed!\n", nIrq);
2004 /* FIXME this handles wakeup irqs wrong */
2005 if (enable_irq_wake(nIrq) == 0)
2006 device_init_wakeup(dev, 1);
2008 pr_info("%s: USB %s mode controller at %p using %s, IRQ %d\n",
2011 switch (musb->board_mode) {
2012 case MUSB_HOST: s = "Host"; break;
2013 case MUSB_PERIPHERAL: s = "Peripheral"; break;
2014 default: s = "OTG"; break;
2017 (is_dma_capable() && musb->dma_controller)
2021 #ifdef CONFIG_USB_MUSB_HDRC_HCD
2022 /* host side needs more setup, except for no-host modes */
2023 if (musb->board_mode != MUSB_PERIPHERAL) {
2024 struct usb_hcd *hcd = musb_to_hcd(musb);
2026 if (musb->board_mode == MUSB_OTG)
2027 hcd->self.otg_port = 1;
2028 musb->xceiv.host = &hcd->self;
2029 hcd->power_budget = 2 * (plat->power ? : 250);
2031 #endif /* CONFIG_USB_MUSB_HDRC_HCD */
2033 /* For the host-only role, we can activate right away.
2034 * (We expect the ID pin to be forcibly grounded!!)
2035 * Otherwise, wait till the gadget driver hooks up.
2037 if (!is_otg_enabled(musb) && is_host_enabled(musb)) {
2038 MUSB_HST_MODE(musb);
2039 musb->xceiv.default_a = 1;
2040 musb->xceiv.state = OTG_STATE_A_IDLE;
2042 status = usb_add_hcd(musb_to_hcd(musb), -1, 0);
2044 DBG(1, "%s mode, status %d, devctl %02x %c\n",
2046 musb_readb(musb->mregs, MUSB_DEVCTL),
2047 (musb_readb(musb->mregs, MUSB_DEVCTL)
2048 & MUSB_DEVCTL_BDEVICE
2051 } else /* peripheral is enabled */ {
2052 MUSB_DEV_MODE(musb);
2053 musb->xceiv.default_a = 0;
2054 musb->xceiv.state = OTG_STATE_B_IDLE;
2056 status = musb_gadget_setup(musb);
2058 DBG(1, "%s mode, status %d, dev%02x\n",
2059 is_otg_enabled(musb) ? "OTG" : "PERIPHERAL",
2061 musb_readb(musb->mregs, MUSB_DEVCTL));
2066 musb_debug_create("driver/musb_hdrc", musb);
2070 clk_put(musb->clock);
2071 device_init_wakeup(dev, 0);
2076 INIT_WORK(&musb->irq_work, musb_irq_work);
2079 status = device_create_file(dev, &dev_attr_mode);
2080 status = device_create_file(dev, &dev_attr_cable);
2081 status = device_create_file(dev, &dev_attr_vbus);
2082 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
2083 status = device_create_file(dev, &dev_attr_srp);
2084 #endif /* CONFIG_USB_GADGET_MUSB_HDRC */
2091 musb_platform_exit(musb);
2095 /*-------------------------------------------------------------------------*/
2097 /* all implementations (PCI bridge to FPGA, VLYNQ, etc) should just
2098 * bridge to a platform device; this driver then suffices.
2101 #ifndef CONFIG_MUSB_PIO_ONLY
2102 static u64 *orig_dma_mask;
2105 static int __init musb_probe(struct platform_device *pdev)
2107 struct device *dev = &pdev->dev;
2108 int irq = platform_get_irq(pdev, 0);
2109 struct resource *iomem;
2112 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2113 if (!iomem || irq == 0)
2116 base = ioremap(iomem->start, iomem->end - iomem->start + 1);
2118 dev_err(dev, "ioremap failed\n");
2122 #ifndef CONFIG_MUSB_PIO_ONLY
2123 /* clobbered by use_dma=n */
2124 orig_dma_mask = dev->dma_mask;
2126 return musb_init_controller(dev, irq, base);
2129 static int __devexit musb_remove(struct platform_device *pdev)
2131 struct musb *musb = dev_to_musb(&pdev->dev);
2132 void __iomem *ctrl_base = musb->ctrl_base;
2134 /* this gets called on rmmod.
2135 * - Host mode: host may still be active
2136 * - Peripheral mode: peripheral is deactivated (or never-activated)
2137 * - OTG mode: both roles are deactivated (or never-activated)
2139 musb_shutdown(pdev);
2140 musb_debug_delete("driver/musb_hdrc", musb);
2141 #ifdef CONFIG_USB_MUSB_HDRC_HCD
2142 if (musb->board_mode == MUSB_HOST)
2143 usb_remove_hcd(musb_to_hcd(musb));
2147 device_init_wakeup(&pdev->dev, 0);
2148 #ifndef CONFIG_MUSB_PIO_ONLY
2149 pdev->dev.dma_mask = orig_dma_mask;
2156 static int musb_suspend(struct platform_device *pdev, pm_message_t message)
2158 unsigned long flags;
2159 struct musb *musb = dev_to_musb(&pdev->dev);
2164 spin_lock_irqsave(&musb->lock, flags);
2166 if (is_peripheral_active(musb)) {
2167 /* FIXME force disconnect unless we know USB will wake
2168 * the system up quickly enough to respond ...
2170 } else if (is_host_active(musb)) {
2171 /* we know all the children are suspended; sometimes
2172 * they will even be wakeup-enabled.
2176 if (musb->set_clock)
2177 musb->set_clock(musb->clock, 0);
2179 clk_disable(musb->clock);
2180 spin_unlock_irqrestore(&musb->lock, flags);
2184 static int musb_resume(struct platform_device *pdev)
2186 unsigned long flags;
2187 struct musb *musb = dev_to_musb(&pdev->dev);
2192 spin_lock_irqsave(&musb->lock, flags);
2194 if (musb->set_clock)
2195 musb->set_clock(musb->clock, 1);
2197 clk_enable(musb->clock);
2199 /* for static cmos like DaVinci, register values were preserved
2200 * unless for some reason the whole soc powered down and we're
2201 * not treating that as a whole-system restart (e.g. swsusp)
2203 spin_unlock_irqrestore(&musb->lock, flags);
2208 #define musb_suspend NULL
2209 #define musb_resume NULL
2212 static struct platform_driver musb_driver = {
2214 .name = (char *)musb_driver_name,
2215 .bus = &platform_bus_type,
2216 .owner = THIS_MODULE,
2218 .remove = __devexit_p(musb_remove),
2219 .shutdown = musb_shutdown,
2220 .suspend = musb_suspend,
2221 .resume = musb_resume,
2224 /*-------------------------------------------------------------------------*/
2226 static int __init musb_init(void)
2228 #ifdef CONFIG_USB_MUSB_HDRC_HCD
2233 pr_info("%s: version " MUSB_VERSION ", "
2234 #ifdef CONFIG_MUSB_PIO_ONLY
2236 #elif defined(CONFIG_USB_TI_CPPI_DMA)
2238 #elif defined(CONFIG_USB_INVENTRA_DMA)
2240 #elif defined(CONFIG_USB_TUSB_OMAP_DMA)
2246 #ifdef CONFIG_USB_MUSB_OTG
2247 "otg (peripheral+host)"
2248 #elif defined(CONFIG_USB_GADGET_MUSB_HDRC)
2250 #elif defined(CONFIG_USB_MUSB_HDRC_HCD)
2254 musb_driver_name, debug);
2255 return platform_driver_probe(&musb_driver, musb_probe);
2258 /* make us init after usbcore and before usb
2259 * gadget and host-side drivers start to register
2261 subsys_initcall(musb_init);
2263 static void __exit musb_cleanup(void)
2265 platform_driver_unregister(&musb_driver);
2267 module_exit(musb_cleanup);