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 * - platform_device for addressing, irq, and platform_data
86 * - platform_data is mostly for board-specific informarion
87 * (plus recentrly, SOC or family details)
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>
100 #include <linux/io.h>
103 #include <mach/hardware.h>
104 #include <mach/memory.h>
105 #include <asm/mach-types.h>
108 #include "musb_core.h"
111 #ifdef CONFIG_ARCH_DAVINCI
115 #define TA_WAIT_BCON(m) max_t(int, (m)->a_wait_bcon, OTG_TIME_A_WAIT_BCON)
119 module_param_named(debug
, musb_debug
, uint
, S_IRUGO
| S_IWUSR
);
120 MODULE_PARM_DESC(debug
, "Debug message level. Default = 0");
122 #define DRIVER_AUTHOR "Mentor Graphics, Texas Instruments, Nokia"
123 #define DRIVER_DESC "Inventra Dual-Role USB Controller Driver"
125 #define MUSB_VERSION "6.0"
127 #define DRIVER_INFO DRIVER_DESC ", v" MUSB_VERSION
129 #define MUSB_DRIVER_NAME "musb_hdrc"
130 const char musb_driver_name
[] = MUSB_DRIVER_NAME
;
132 MODULE_DESCRIPTION(DRIVER_INFO
);
133 MODULE_AUTHOR(DRIVER_AUTHOR
);
134 MODULE_LICENSE("GPL");
135 MODULE_ALIAS("platform:" MUSB_DRIVER_NAME
);
138 /*-------------------------------------------------------------------------*/
140 static inline struct musb
*dev_to_musb(struct device
*dev
)
142 #ifdef CONFIG_USB_MUSB_HDRC_HCD
143 /* usbcore insists dev->driver_data is a "struct hcd *" */
144 return hcd_to_musb(dev_get_drvdata(dev
));
146 return dev_get_drvdata(dev
);
150 /*-------------------------------------------------------------------------*/
152 #ifndef CONFIG_BLACKFIN
153 static int musb_ulpi_read(struct otg_transceiver
*otg
, u32 offset
)
155 void __iomem
*addr
= otg
->io_priv
;
160 /* Make sure the transceiver is not in low power mode */
161 power
= musb_readb(addr
, MUSB_POWER
);
162 power
&= ~MUSB_POWER_SUSPENDM
;
163 musb_writeb(addr
, MUSB_POWER
, power
);
165 /* REVISIT: musbhdrc_ulpi_an.pdf recommends setting the
166 * ULPICarKitControlDisableUTMI after clearing POWER_SUSPENDM.
169 musb_writeb(addr
, MUSB_ULPI_REG_ADDR
, (u8
)offset
);
170 musb_writeb(addr
, MUSB_ULPI_REG_CONTROL
,
171 MUSB_ULPI_REG_REQ
| MUSB_ULPI_RDN_WR
);
173 while (!(musb_readb(addr
, MUSB_ULPI_REG_CONTROL
)
174 & MUSB_ULPI_REG_CMPLT
)) {
177 DBG(3, "ULPI read timed out\n");
182 r
= musb_readb(addr
, MUSB_ULPI_REG_CONTROL
);
183 r
&= ~MUSB_ULPI_REG_CMPLT
;
184 musb_writeb(addr
, MUSB_ULPI_REG_CONTROL
, r
);
186 return musb_readb(addr
, MUSB_ULPI_REG_DATA
);
189 static int musb_ulpi_write(struct otg_transceiver
*otg
,
190 u32 offset
, u32 data
)
192 void __iomem
*addr
= otg
->io_priv
;
197 /* Make sure the transceiver is not in low power mode */
198 power
= musb_readb(addr
, MUSB_POWER
);
199 power
&= ~MUSB_POWER_SUSPENDM
;
200 musb_writeb(addr
, MUSB_POWER
, power
);
202 musb_writeb(addr
, MUSB_ULPI_REG_ADDR
, (u8
)offset
);
203 musb_writeb(addr
, MUSB_ULPI_REG_DATA
, (u8
)data
);
204 musb_writeb(addr
, MUSB_ULPI_REG_CONTROL
, MUSB_ULPI_REG_REQ
);
206 while (!(musb_readb(addr
, MUSB_ULPI_REG_CONTROL
)
207 & MUSB_ULPI_REG_CMPLT
)) {
210 DBG(3, "ULPI write timed out\n");
215 r
= musb_readb(addr
, MUSB_ULPI_REG_CONTROL
);
216 r
&= ~MUSB_ULPI_REG_CMPLT
;
217 musb_writeb(addr
, MUSB_ULPI_REG_CONTROL
, r
);
222 #define musb_ulpi_read NULL
223 #define musb_ulpi_write NULL
226 static struct otg_io_access_ops musb_ulpi_access
= {
227 .read
= musb_ulpi_read
,
228 .write
= musb_ulpi_write
,
231 /*-------------------------------------------------------------------------*/
233 #if !defined(CONFIG_USB_TUSB6010) && !defined(CONFIG_BLACKFIN)
236 * Load an endpoint's FIFO
238 void musb_write_fifo(struct musb_hw_ep
*hw_ep
, u16 len
, const u8
*src
)
240 void __iomem
*fifo
= hw_ep
->fifo
;
244 DBG(4, "%cX ep%d fifo %p count %d buf %p\n",
245 'T', hw_ep
->epnum
, fifo
, len
, src
);
247 /* we can't assume unaligned reads work */
248 if (likely((0x01 & (unsigned long) src
) == 0)) {
251 /* best case is 32bit-aligned source address */
252 if ((0x02 & (unsigned long) src
) == 0) {
254 writesl(fifo
, src
+ index
, len
>> 2);
255 index
+= len
& ~0x03;
258 musb_writew(fifo
, 0, *(u16
*)&src
[index
]);
263 writesw(fifo
, src
+ index
, len
>> 1);
264 index
+= len
& ~0x01;
268 musb_writeb(fifo
, 0, src
[index
]);
271 writesb(fifo
, src
, len
);
276 * Unload an endpoint's FIFO
278 void musb_read_fifo(struct musb_hw_ep
*hw_ep
, u16 len
, u8
*dst
)
280 void __iomem
*fifo
= hw_ep
->fifo
;
282 DBG(4, "%cX ep%d fifo %p count %d buf %p\n",
283 'R', hw_ep
->epnum
, fifo
, len
, dst
);
285 /* we can't assume unaligned writes work */
286 if (likely((0x01 & (unsigned long) dst
) == 0)) {
289 /* best case is 32bit-aligned destination address */
290 if ((0x02 & (unsigned long) dst
) == 0) {
292 readsl(fifo
, dst
, len
>> 2);
296 *(u16
*)&dst
[index
] = musb_readw(fifo
, 0);
301 readsw(fifo
, dst
, len
>> 1);
306 dst
[index
] = musb_readb(fifo
, 0);
309 readsb(fifo
, dst
, len
);
313 #endif /* normal PIO */
316 /*-------------------------------------------------------------------------*/
318 /* for high speed test mode; see USB 2.0 spec 7.1.20 */
319 static const u8 musb_test_packet
[53] = {
320 /* implicit SYNC then DATA0 to start */
323 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
325 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
327 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee,
328 /* JJJJJJJKKKKKKK x8 */
329 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
331 0x7f, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd,
332 /* JKKKKKKK x10, JK */
333 0xfc, 0x7e, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0x7e
335 /* implicit CRC16 then EOP to end */
338 void musb_load_testpacket(struct musb
*musb
)
340 void __iomem
*regs
= musb
->endpoints
[0].regs
;
342 musb_ep_select(musb
->mregs
, 0);
343 musb_write_fifo(musb
->control_ep
,
344 sizeof(musb_test_packet
), musb_test_packet
);
345 musb_writew(regs
, MUSB_CSR0
, MUSB_CSR0_TXPKTRDY
);
348 /*-------------------------------------------------------------------------*/
350 const char *otg_state_string(struct musb
*musb
)
352 switch (musb
->xceiv
->state
) {
353 case OTG_STATE_A_IDLE
: return "a_idle";
354 case OTG_STATE_A_WAIT_VRISE
: return "a_wait_vrise";
355 case OTG_STATE_A_WAIT_BCON
: return "a_wait_bcon";
356 case OTG_STATE_A_HOST
: return "a_host";
357 case OTG_STATE_A_SUSPEND
: return "a_suspend";
358 case OTG_STATE_A_PERIPHERAL
: return "a_peripheral";
359 case OTG_STATE_A_WAIT_VFALL
: return "a_wait_vfall";
360 case OTG_STATE_A_VBUS_ERR
: return "a_vbus_err";
361 case OTG_STATE_B_IDLE
: return "b_idle";
362 case OTG_STATE_B_SRP_INIT
: return "b_srp_init";
363 case OTG_STATE_B_PERIPHERAL
: return "b_peripheral";
364 case OTG_STATE_B_WAIT_ACON
: return "b_wait_acon";
365 case OTG_STATE_B_HOST
: return "b_host";
366 default: return "UNDEFINED";
370 #ifdef CONFIG_USB_MUSB_OTG
373 * Handles OTG hnp timeouts, such as b_ase0_brst
375 void musb_otg_timer_func(unsigned long data
)
377 struct musb
*musb
= (struct musb
*)data
;
380 spin_lock_irqsave(&musb
->lock
, flags
);
381 switch (musb
->xceiv
->state
) {
382 case OTG_STATE_B_WAIT_ACON
:
383 DBG(1, "HNP: b_wait_acon timeout; back to b_peripheral\n");
384 musb_g_disconnect(musb
);
385 musb
->xceiv
->state
= OTG_STATE_B_PERIPHERAL
;
388 case OTG_STATE_A_SUSPEND
:
389 case OTG_STATE_A_WAIT_BCON
:
390 DBG(1, "HNP: %s timeout\n", otg_state_string(musb
));
391 musb_set_vbus(musb
, 0);
392 musb
->xceiv
->state
= OTG_STATE_A_WAIT_VFALL
;
395 DBG(1, "HNP: Unhandled mode %s\n", otg_state_string(musb
));
397 musb
->ignore_disconnect
= 0;
398 spin_unlock_irqrestore(&musb
->lock
, flags
);
402 * Stops the HNP transition. Caller must take care of locking.
404 void musb_hnp_stop(struct musb
*musb
)
406 struct usb_hcd
*hcd
= musb_to_hcd(musb
);
407 void __iomem
*mbase
= musb
->mregs
;
410 DBG(1, "HNP: stop from %s\n", otg_state_string(musb
));
412 switch (musb
->xceiv
->state
) {
413 case OTG_STATE_A_PERIPHERAL
:
414 musb_g_disconnect(musb
);
415 DBG(1, "HNP: back to %s\n", otg_state_string(musb
));
417 case OTG_STATE_B_HOST
:
418 DBG(1, "HNP: Disabling HR\n");
419 hcd
->self
.is_b_host
= 0;
420 musb
->xceiv
->state
= OTG_STATE_B_PERIPHERAL
;
422 reg
= musb_readb(mbase
, MUSB_POWER
);
423 reg
|= MUSB_POWER_SUSPENDM
;
424 musb_writeb(mbase
, MUSB_POWER
, reg
);
425 /* REVISIT: Start SESSION_REQUEST here? */
428 DBG(1, "HNP: Stopping in unknown state %s\n",
429 otg_state_string(musb
));
433 * When returning to A state after HNP, avoid hub_port_rebounce(),
434 * which cause occasional OPT A "Did not receive reset after connect"
437 musb
->port1_status
&= ~(USB_PORT_STAT_C_CONNECTION
<< 16);
443 * Interrupt Service Routine to record USB "global" interrupts.
444 * Since these do not happen often and signify things of
445 * paramount importance, it seems OK to check them individually;
446 * the order of the tests is specified in the manual
448 * @param musb instance pointer
449 * @param int_usb register contents
454 static irqreturn_t
musb_stage0_irq(struct musb
*musb
, u8 int_usb
,
457 irqreturn_t handled
= IRQ_NONE
;
459 DBG(3, "<== Power=%02x, DevCtl=%02x, int_usb=0x%x\n", power
, devctl
,
462 /* in host mode, the peripheral may issue remote wakeup.
463 * in peripheral mode, the host may resume the link.
464 * spurious RESUME irqs happen too, paired with SUSPEND.
466 if (int_usb
& MUSB_INTR_RESUME
) {
467 handled
= IRQ_HANDLED
;
468 DBG(3, "RESUME (%s)\n", otg_state_string(musb
));
470 if (devctl
& MUSB_DEVCTL_HM
) {
471 #ifdef CONFIG_USB_MUSB_HDRC_HCD
472 void __iomem
*mbase
= musb
->mregs
;
474 switch (musb
->xceiv
->state
) {
475 case OTG_STATE_A_SUSPEND
:
476 /* remote wakeup? later, GetPortStatus
477 * will stop RESUME signaling
480 if (power
& MUSB_POWER_SUSPENDM
) {
482 musb
->int_usb
&= ~MUSB_INTR_SUSPEND
;
483 DBG(2, "Spurious SUSPENDM\n");
487 power
&= ~MUSB_POWER_SUSPENDM
;
488 musb_writeb(mbase
, MUSB_POWER
,
489 power
| MUSB_POWER_RESUME
);
491 musb
->port1_status
|=
492 (USB_PORT_STAT_C_SUSPEND
<< 16)
493 | MUSB_PORT_STAT_RESUME
;
494 musb
->rh_timer
= jiffies
495 + msecs_to_jiffies(20);
497 musb
->xceiv
->state
= OTG_STATE_A_HOST
;
499 usb_hcd_resume_root_hub(musb_to_hcd(musb
));
501 case OTG_STATE_B_WAIT_ACON
:
502 musb
->xceiv
->state
= OTG_STATE_B_PERIPHERAL
;
507 WARNING("bogus %s RESUME (%s)\n",
509 otg_state_string(musb
));
513 switch (musb
->xceiv
->state
) {
514 #ifdef CONFIG_USB_MUSB_HDRC_HCD
515 case OTG_STATE_A_SUSPEND
:
516 /* possibly DISCONNECT is upcoming */
517 musb
->xceiv
->state
= OTG_STATE_A_HOST
;
518 usb_hcd_resume_root_hub(musb_to_hcd(musb
));
521 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
522 case OTG_STATE_B_WAIT_ACON
:
523 case OTG_STATE_B_PERIPHERAL
:
524 /* disconnect while suspended? we may
525 * not get a disconnect irq...
527 if ((devctl
& MUSB_DEVCTL_VBUS
)
528 != (3 << MUSB_DEVCTL_VBUS_SHIFT
)
530 musb
->int_usb
|= MUSB_INTR_DISCONNECT
;
531 musb
->int_usb
&= ~MUSB_INTR_SUSPEND
;
536 case OTG_STATE_B_IDLE
:
537 musb
->int_usb
&= ~MUSB_INTR_SUSPEND
;
541 WARNING("bogus %s RESUME (%s)\n",
543 otg_state_string(musb
));
548 #ifdef CONFIG_USB_MUSB_HDRC_HCD
549 /* see manual for the order of the tests */
550 if (int_usb
& MUSB_INTR_SESSREQ
) {
551 void __iomem
*mbase
= musb
->mregs
;
553 if (devctl
& MUSB_DEVCTL_BDEVICE
) {
554 DBG(3, "SessReq while on B state\n");
558 DBG(1, "SESSION_REQUEST (%s)\n", otg_state_string(musb
));
560 /* IRQ arrives from ID pin sense or (later, if VBUS power
561 * is removed) SRP. responses are time critical:
562 * - turn on VBUS (with silicon-specific mechanism)
563 * - go through A_WAIT_VRISE
564 * - ... to A_WAIT_BCON.
565 * a_wait_vrise_tmout triggers VBUS_ERROR transitions
567 musb_writeb(mbase
, MUSB_DEVCTL
, MUSB_DEVCTL_SESSION
);
568 musb
->ep0_stage
= MUSB_EP0_START
;
569 musb
->xceiv
->state
= OTG_STATE_A_IDLE
;
571 musb_set_vbus(musb
, 1);
573 handled
= IRQ_HANDLED
;
576 if (int_usb
& MUSB_INTR_VBUSERROR
) {
579 /* During connection as an A-Device, we may see a short
580 * current spikes causing voltage drop, because of cable
581 * and peripheral capacitance combined with vbus draw.
582 * (So: less common with truly self-powered devices, where
583 * vbus doesn't act like a power supply.)
585 * Such spikes are short; usually less than ~500 usec, max
586 * of ~2 msec. That is, they're not sustained overcurrent
587 * errors, though they're reported using VBUSERROR irqs.
589 * Workarounds: (a) hardware: use self powered devices.
590 * (b) software: ignore non-repeated VBUS errors.
592 * REVISIT: do delays from lots of DEBUG_KERNEL checks
593 * make trouble here, keeping VBUS < 4.4V ?
595 switch (musb
->xceiv
->state
) {
596 case OTG_STATE_A_HOST
:
597 /* recovery is dicey once we've gotten past the
598 * initial stages of enumeration, but if VBUS
599 * stayed ok at the other end of the link, and
600 * another reset is due (at least for high speed,
601 * to redo the chirp etc), it might work OK...
603 case OTG_STATE_A_WAIT_BCON
:
604 case OTG_STATE_A_WAIT_VRISE
:
605 if (musb
->vbuserr_retry
) {
606 void __iomem
*mbase
= musb
->mregs
;
608 musb
->vbuserr_retry
--;
610 devctl
|= MUSB_DEVCTL_SESSION
;
611 musb_writeb(mbase
, MUSB_DEVCTL
, devctl
);
613 musb
->port1_status
|=
614 USB_PORT_STAT_OVERCURRENT
615 | (USB_PORT_STAT_C_OVERCURRENT
<< 16);
622 DBG(1, "VBUS_ERROR in %s (%02x, %s), retry #%d, port1 %08x\n",
623 otg_state_string(musb
),
626 switch (devctl
& MUSB_DEVCTL_VBUS
) {
627 case 0 << MUSB_DEVCTL_VBUS_SHIFT
:
628 s
= "<SessEnd"; break;
629 case 1 << MUSB_DEVCTL_VBUS_SHIFT
:
630 s
= "<AValid"; break;
631 case 2 << MUSB_DEVCTL_VBUS_SHIFT
:
632 s
= "<VBusValid"; break;
633 /* case 3 << MUSB_DEVCTL_VBUS_SHIFT: */
637 VBUSERR_RETRY_COUNT
- musb
->vbuserr_retry
,
640 /* go through A_WAIT_VFALL then start a new session */
642 musb_set_vbus(musb
, 0);
643 handled
= IRQ_HANDLED
;
647 if (int_usb
& MUSB_INTR_SUSPEND
) {
648 DBG(1, "SUSPEND (%s) devctl %02x power %02x\n",
649 otg_state_string(musb
), devctl
, power
);
650 handled
= IRQ_HANDLED
;
652 switch (musb
->xceiv
->state
) {
653 #ifdef CONFIG_USB_MUSB_OTG
654 case OTG_STATE_A_PERIPHERAL
:
655 /* We also come here if the cable is removed, since
656 * this silicon doesn't report ID-no-longer-grounded.
658 * We depend on T(a_wait_bcon) to shut us down, and
659 * hope users don't do anything dicey during this
660 * undesired detour through A_WAIT_BCON.
663 usb_hcd_resume_root_hub(musb_to_hcd(musb
));
664 musb_root_disconnect(musb
);
665 musb_platform_try_idle(musb
, jiffies
666 + msecs_to_jiffies(musb
->a_wait_bcon
667 ? : OTG_TIME_A_WAIT_BCON
));
671 case OTG_STATE_B_IDLE
:
672 if (!musb
->is_active
)
674 case OTG_STATE_B_PERIPHERAL
:
675 musb_g_suspend(musb
);
676 musb
->is_active
= is_otg_enabled(musb
)
677 && musb
->xceiv
->gadget
->b_hnp_enable
;
678 if (musb
->is_active
) {
679 #ifdef CONFIG_USB_MUSB_OTG
680 musb
->xceiv
->state
= OTG_STATE_B_WAIT_ACON
;
681 DBG(1, "HNP: Setting timer for b_ase0_brst\n");
682 mod_timer(&musb
->otg_timer
, jiffies
684 OTG_TIME_B_ASE0_BRST
));
688 case OTG_STATE_A_WAIT_BCON
:
689 if (musb
->a_wait_bcon
!= 0)
690 musb_platform_try_idle(musb
, jiffies
691 + msecs_to_jiffies(musb
->a_wait_bcon
));
693 case OTG_STATE_A_HOST
:
694 musb
->xceiv
->state
= OTG_STATE_A_SUSPEND
;
695 musb
->is_active
= is_otg_enabled(musb
)
696 && musb
->xceiv
->host
->b_hnp_enable
;
698 case OTG_STATE_B_HOST
:
699 /* Transition to B_PERIPHERAL, see 6.8.2.6 p 44 */
700 DBG(1, "REVISIT: SUSPEND as B_HOST\n");
703 /* "should not happen" */
709 #ifdef CONFIG_USB_MUSB_HDRC_HCD
710 if (int_usb
& MUSB_INTR_CONNECT
) {
711 struct usb_hcd
*hcd
= musb_to_hcd(musb
);
713 handled
= IRQ_HANDLED
;
715 set_bit(HCD_FLAG_SAW_IRQ
, &hcd
->flags
);
717 musb
->ep0_stage
= MUSB_EP0_START
;
719 #ifdef CONFIG_USB_MUSB_OTG
720 /* flush endpoints when transitioning from Device Mode */
721 if (is_peripheral_active(musb
)) {
722 /* REVISIT HNP; just force disconnect */
724 musb_writew(musb
->mregs
, MUSB_INTRTXE
, musb
->epmask
);
725 musb_writew(musb
->mregs
, MUSB_INTRRXE
, musb
->epmask
& 0xfffe);
726 musb_writeb(musb
->mregs
, MUSB_INTRUSBE
, 0xf7);
728 musb
->port1_status
&= ~(USB_PORT_STAT_LOW_SPEED
729 |USB_PORT_STAT_HIGH_SPEED
730 |USB_PORT_STAT_ENABLE
732 musb
->port1_status
|= USB_PORT_STAT_CONNECTION
733 |(USB_PORT_STAT_C_CONNECTION
<< 16);
735 /* high vs full speed is just a guess until after reset */
736 if (devctl
& MUSB_DEVCTL_LSDEV
)
737 musb
->port1_status
|= USB_PORT_STAT_LOW_SPEED
;
739 /* indicate new connection to OTG machine */
740 switch (musb
->xceiv
->state
) {
741 case OTG_STATE_B_PERIPHERAL
:
742 if (int_usb
& MUSB_INTR_SUSPEND
) {
743 DBG(1, "HNP: SUSPEND+CONNECT, now b_host\n");
744 int_usb
&= ~MUSB_INTR_SUSPEND
;
747 DBG(1, "CONNECT as b_peripheral???\n");
749 case OTG_STATE_B_WAIT_ACON
:
750 DBG(1, "HNP: CONNECT, now b_host\n");
752 musb
->xceiv
->state
= OTG_STATE_B_HOST
;
753 hcd
->self
.is_b_host
= 1;
754 musb
->ignore_disconnect
= 0;
755 del_timer(&musb
->otg_timer
);
758 if ((devctl
& MUSB_DEVCTL_VBUS
)
759 == (3 << MUSB_DEVCTL_VBUS_SHIFT
)) {
760 musb
->xceiv
->state
= OTG_STATE_A_HOST
;
761 hcd
->self
.is_b_host
= 0;
766 /* poke the root hub */
769 usb_hcd_poll_rh_status(hcd
);
771 usb_hcd_resume_root_hub(hcd
);
773 DBG(1, "CONNECT (%s) devctl %02x\n",
774 otg_state_string(musb
), devctl
);
776 #endif /* CONFIG_USB_MUSB_HDRC_HCD */
778 if ((int_usb
& MUSB_INTR_DISCONNECT
) && !musb
->ignore_disconnect
) {
779 DBG(1, "DISCONNECT (%s) as %s, devctl %02x\n",
780 otg_state_string(musb
),
781 MUSB_MODE(musb
), devctl
);
782 handled
= IRQ_HANDLED
;
784 switch (musb
->xceiv
->state
) {
785 #ifdef CONFIG_USB_MUSB_HDRC_HCD
786 case OTG_STATE_A_HOST
:
787 case OTG_STATE_A_SUSPEND
:
788 usb_hcd_resume_root_hub(musb_to_hcd(musb
));
789 musb_root_disconnect(musb
);
790 if (musb
->a_wait_bcon
!= 0 && is_otg_enabled(musb
))
791 musb_platform_try_idle(musb
, jiffies
792 + msecs_to_jiffies(musb
->a_wait_bcon
));
795 #ifdef CONFIG_USB_MUSB_OTG
796 case OTG_STATE_B_HOST
:
797 /* REVISIT this behaves for "real disconnect"
798 * cases; make sure the other transitions from
799 * from B_HOST act right too. The B_HOST code
800 * in hnp_stop() is currently not used...
802 musb_root_disconnect(musb
);
803 musb_to_hcd(musb
)->self
.is_b_host
= 0;
804 musb
->xceiv
->state
= OTG_STATE_B_PERIPHERAL
;
806 musb_g_disconnect(musb
);
808 case OTG_STATE_A_PERIPHERAL
:
810 musb_root_disconnect(musb
);
812 case OTG_STATE_B_WAIT_ACON
:
815 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
816 case OTG_STATE_B_PERIPHERAL
:
817 case OTG_STATE_B_IDLE
:
818 musb_g_disconnect(musb
);
822 WARNING("unhandled DISCONNECT transition (%s)\n",
823 otg_state_string(musb
));
828 /* mentor saves a bit: bus reset and babble share the same irq.
829 * only host sees babble; only peripheral sees bus reset.
831 if (int_usb
& MUSB_INTR_RESET
) {
832 handled
= IRQ_HANDLED
;
833 if (is_host_capable() && (devctl
& MUSB_DEVCTL_HM
) != 0) {
835 * Looks like non-HS BABBLE can be ignored, but
836 * HS BABBLE is an error condition. For HS the solution
837 * is to avoid babble in the first place and fix what
838 * caused BABBLE. When HS BABBLE happens we can only
841 if (devctl
& (MUSB_DEVCTL_FSDEV
| MUSB_DEVCTL_LSDEV
))
842 DBG(1, "BABBLE devctl: %02x\n", devctl
);
844 ERR("Stopping host session -- babble\n");
845 musb_writeb(musb
->mregs
, MUSB_DEVCTL
, 0);
847 } else if (is_peripheral_capable()) {
848 DBG(1, "BUS RESET as %s\n", otg_state_string(musb
));
849 switch (musb
->xceiv
->state
) {
850 #ifdef CONFIG_USB_OTG
851 case OTG_STATE_A_SUSPEND
:
852 /* We need to ignore disconnect on suspend
853 * otherwise tusb 2.0 won't reconnect after a
854 * power cycle, which breaks otg compliance.
856 musb
->ignore_disconnect
= 1;
859 case OTG_STATE_A_WAIT_BCON
: /* OPT TD.4.7-900ms */
860 /* never use invalid T(a_wait_bcon) */
861 DBG(1, "HNP: in %s, %d msec timeout\n",
862 otg_state_string(musb
),
864 mod_timer(&musb
->otg_timer
, jiffies
865 + msecs_to_jiffies(TA_WAIT_BCON(musb
)));
867 case OTG_STATE_A_PERIPHERAL
:
868 musb
->ignore_disconnect
= 0;
869 del_timer(&musb
->otg_timer
);
872 case OTG_STATE_B_WAIT_ACON
:
873 DBG(1, "HNP: RESET (%s), to b_peripheral\n",
874 otg_state_string(musb
));
875 musb
->xceiv
->state
= OTG_STATE_B_PERIPHERAL
;
879 case OTG_STATE_B_IDLE
:
880 musb
->xceiv
->state
= OTG_STATE_B_PERIPHERAL
;
882 case OTG_STATE_B_PERIPHERAL
:
886 DBG(1, "Unhandled BUS RESET as %s\n",
887 otg_state_string(musb
));
893 /* REVISIT ... this would be for multiplexing periodic endpoints, or
894 * supporting transfer phasing to prevent exceeding ISO bandwidth
895 * limits of a given frame or microframe.
897 * It's not needed for peripheral side, which dedicates endpoints;
898 * though it _might_ use SOF irqs for other purposes.
900 * And it's not currently needed for host side, which also dedicates
901 * endpoints, relies on TX/RX interval registers, and isn't claimed
902 * to support ISO transfers yet.
904 if (int_usb
& MUSB_INTR_SOF
) {
905 void __iomem
*mbase
= musb
->mregs
;
906 struct musb_hw_ep
*ep
;
910 DBG(6, "START_OF_FRAME\n");
911 handled
= IRQ_HANDLED
;
913 /* start any periodic Tx transfers waiting for current frame */
914 frame
= musb_readw(mbase
, MUSB_FRAME
);
915 ep
= musb
->endpoints
;
916 for (epnum
= 1; (epnum
< musb
->nr_endpoints
)
917 && (musb
->epmask
>= (1 << epnum
));
920 * FIXME handle framecounter wraps (12 bits)
921 * eliminate duplicated StartUrb logic
923 if (ep
->dwWaitFrame
>= frame
) {
925 pr_debug("SOF --> periodic TX%s on %d\n",
926 ep
->tx_channel
? " DMA" : "",
929 musb_h_tx_start(musb
, epnum
);
931 cppi_hostdma_start(musb
, epnum
);
933 } /* end of for loop */
937 schedule_work(&musb
->irq_work
);
942 /*-------------------------------------------------------------------------*/
945 * Program the HDRC to start (enable interrupts, dma, etc.).
947 void musb_start(struct musb
*musb
)
949 void __iomem
*regs
= musb
->mregs
;
950 u8 devctl
= musb_readb(regs
, MUSB_DEVCTL
);
952 DBG(2, "<== devctl %02x\n", devctl
);
954 /* Set INT enable registers, enable interrupts */
955 musb_writew(regs
, MUSB_INTRTXE
, musb
->epmask
);
956 musb_writew(regs
, MUSB_INTRRXE
, musb
->epmask
& 0xfffe);
957 musb_writeb(regs
, MUSB_INTRUSBE
, 0xf7);
959 musb_writeb(regs
, MUSB_TESTMODE
, 0);
961 /* put into basic highspeed mode and start session */
962 musb_writeb(regs
, MUSB_POWER
, MUSB_POWER_ISOUPDATE
963 | MUSB_POWER_SOFTCONN
965 /* ENSUSPEND wedges tusb */
966 /* | MUSB_POWER_ENSUSPEND */
970 devctl
= musb_readb(regs
, MUSB_DEVCTL
);
971 devctl
&= ~MUSB_DEVCTL_SESSION
;
973 if (is_otg_enabled(musb
)) {
974 /* session started after:
975 * (a) ID-grounded irq, host mode;
976 * (b) vbus present/connect IRQ, peripheral mode;
977 * (c) peripheral initiates, using SRP
979 if ((devctl
& MUSB_DEVCTL_VBUS
) == MUSB_DEVCTL_VBUS
)
982 devctl
|= MUSB_DEVCTL_SESSION
;
984 } else if (is_host_enabled(musb
)) {
985 /* assume ID pin is hard-wired to ground */
986 devctl
|= MUSB_DEVCTL_SESSION
;
988 } else /* peripheral is enabled */ {
989 if ((devctl
& MUSB_DEVCTL_VBUS
) == MUSB_DEVCTL_VBUS
)
992 musb_platform_enable(musb
);
993 musb_writeb(regs
, MUSB_DEVCTL
, devctl
);
997 static void musb_generic_disable(struct musb
*musb
)
999 void __iomem
*mbase
= musb
->mregs
;
1002 /* disable interrupts */
1003 musb_writeb(mbase
, MUSB_INTRUSBE
, 0);
1004 musb_writew(mbase
, MUSB_INTRTXE
, 0);
1005 musb_writew(mbase
, MUSB_INTRRXE
, 0);
1008 musb_writeb(mbase
, MUSB_DEVCTL
, 0);
1010 /* flush pending interrupts */
1011 temp
= musb_readb(mbase
, MUSB_INTRUSB
);
1012 temp
= musb_readw(mbase
, MUSB_INTRTX
);
1013 temp
= musb_readw(mbase
, MUSB_INTRRX
);
1018 * Make the HDRC stop (disable interrupts, etc.);
1019 * reversible by musb_start
1020 * called on gadget driver unregister
1021 * with controller locked, irqs blocked
1022 * acts as a NOP unless some role activated the hardware
1024 void musb_stop(struct musb
*musb
)
1026 /* stop IRQs, timers, ... */
1027 musb_platform_disable(musb
);
1028 musb_generic_disable(musb
);
1029 DBG(3, "HDRC disabled\n");
1032 * - mark host and/or peripheral drivers unusable/inactive
1033 * - disable DMA (and enable it in HdrcStart)
1034 * - make sure we can musb_start() after musb_stop(); with
1035 * OTG mode, gadget driver module rmmod/modprobe cycles that
1038 musb_platform_try_idle(musb
, 0);
1041 static void musb_shutdown(struct platform_device
*pdev
)
1043 struct musb
*musb
= dev_to_musb(&pdev
->dev
);
1044 unsigned long flags
;
1046 spin_lock_irqsave(&musb
->lock
, flags
);
1047 musb_platform_disable(musb
);
1048 musb_generic_disable(musb
);
1050 clk_put(musb
->clock
);
1051 spin_unlock_irqrestore(&musb
->lock
, flags
);
1053 /* FIXME power down */
1057 /*-------------------------------------------------------------------------*/
1060 * The silicon either has hard-wired endpoint configurations, or else
1061 * "dynamic fifo" sizing. The driver has support for both, though at this
1062 * writing only the dynamic sizing is very well tested. Since we switched
1063 * away from compile-time hardware parameters, we can no longer rely on
1064 * dead code elimination to leave only the relevant one in the object file.
1066 * We don't currently use dynamic fifo setup capability to do anything
1067 * more than selecting one of a bunch of predefined configurations.
1069 #if defined(CONFIG_USB_TUSB6010) || \
1070 defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3) \
1071 || defined(CONFIG_ARCH_OMAP4)
1072 static ushort __initdata fifo_mode
= 4;
1074 static ushort __initdata fifo_mode
= 2;
1077 /* "modprobe ... fifo_mode=1" etc */
1078 module_param(fifo_mode
, ushort
, 0);
1079 MODULE_PARM_DESC(fifo_mode
, "initial endpoint configuration");
1082 * tables defining fifo_mode values. define more if you like.
1083 * for host side, make sure both halves of ep1 are set up.
1086 /* mode 0 - fits in 2KB */
1087 static struct musb_fifo_cfg __initdata mode_0_cfg
[] = {
1088 { .hw_ep_num
= 1, .style
= FIFO_TX
, .maxpacket
= 512, },
1089 { .hw_ep_num
= 1, .style
= FIFO_RX
, .maxpacket
= 512, },
1090 { .hw_ep_num
= 2, .style
= FIFO_RXTX
, .maxpacket
= 512, },
1091 { .hw_ep_num
= 3, .style
= FIFO_RXTX
, .maxpacket
= 256, },
1092 { .hw_ep_num
= 4, .style
= FIFO_RXTX
, .maxpacket
= 256, },
1095 /* mode 1 - fits in 4KB */
1096 static struct musb_fifo_cfg __initdata mode_1_cfg
[] = {
1097 { .hw_ep_num
= 1, .style
= FIFO_TX
, .maxpacket
= 512, .mode
= BUF_DOUBLE
, },
1098 { .hw_ep_num
= 1, .style
= FIFO_RX
, .maxpacket
= 512, .mode
= BUF_DOUBLE
, },
1099 { .hw_ep_num
= 2, .style
= FIFO_RXTX
, .maxpacket
= 512, .mode
= BUF_DOUBLE
, },
1100 { .hw_ep_num
= 3, .style
= FIFO_RXTX
, .maxpacket
= 256, },
1101 { .hw_ep_num
= 4, .style
= FIFO_RXTX
, .maxpacket
= 256, },
1104 /* mode 2 - fits in 4KB */
1105 static struct musb_fifo_cfg __initdata mode_2_cfg
[] = {
1106 { .hw_ep_num
= 1, .style
= FIFO_TX
, .maxpacket
= 512, },
1107 { .hw_ep_num
= 1, .style
= FIFO_RX
, .maxpacket
= 512, },
1108 { .hw_ep_num
= 2, .style
= FIFO_TX
, .maxpacket
= 512, },
1109 { .hw_ep_num
= 2, .style
= FIFO_RX
, .maxpacket
= 512, },
1110 { .hw_ep_num
= 3, .style
= FIFO_RXTX
, .maxpacket
= 256, },
1111 { .hw_ep_num
= 4, .style
= FIFO_RXTX
, .maxpacket
= 256, },
1114 /* mode 3 - fits in 4KB */
1115 static struct musb_fifo_cfg __initdata mode_3_cfg
[] = {
1116 { .hw_ep_num
= 1, .style
= FIFO_TX
, .maxpacket
= 512, .mode
= BUF_DOUBLE
, },
1117 { .hw_ep_num
= 1, .style
= FIFO_RX
, .maxpacket
= 512, .mode
= BUF_DOUBLE
, },
1118 { .hw_ep_num
= 2, .style
= FIFO_TX
, .maxpacket
= 512, },
1119 { .hw_ep_num
= 2, .style
= FIFO_RX
, .maxpacket
= 512, },
1120 { .hw_ep_num
= 3, .style
= FIFO_RXTX
, .maxpacket
= 256, },
1121 { .hw_ep_num
= 4, .style
= FIFO_RXTX
, .maxpacket
= 256, },
1124 /* mode 4 - fits in 16KB */
1125 static struct musb_fifo_cfg __initdata mode_4_cfg
[] = {
1126 { .hw_ep_num
= 1, .style
= FIFO_TX
, .maxpacket
= 512, },
1127 { .hw_ep_num
= 1, .style
= FIFO_RX
, .maxpacket
= 512, },
1128 { .hw_ep_num
= 2, .style
= FIFO_TX
, .maxpacket
= 512, },
1129 { .hw_ep_num
= 2, .style
= FIFO_RX
, .maxpacket
= 512, },
1130 { .hw_ep_num
= 3, .style
= FIFO_TX
, .maxpacket
= 512, },
1131 { .hw_ep_num
= 3, .style
= FIFO_RX
, .maxpacket
= 512, },
1132 { .hw_ep_num
= 4, .style
= FIFO_TX
, .maxpacket
= 512, },
1133 { .hw_ep_num
= 4, .style
= FIFO_RX
, .maxpacket
= 512, },
1134 { .hw_ep_num
= 5, .style
= FIFO_TX
, .maxpacket
= 512, },
1135 { .hw_ep_num
= 5, .style
= FIFO_RX
, .maxpacket
= 512, },
1136 { .hw_ep_num
= 6, .style
= FIFO_TX
, .maxpacket
= 512, },
1137 { .hw_ep_num
= 6, .style
= FIFO_RX
, .maxpacket
= 512, },
1138 { .hw_ep_num
= 7, .style
= FIFO_TX
, .maxpacket
= 512, },
1139 { .hw_ep_num
= 7, .style
= FIFO_RX
, .maxpacket
= 512, },
1140 { .hw_ep_num
= 8, .style
= FIFO_TX
, .maxpacket
= 512, },
1141 { .hw_ep_num
= 8, .style
= FIFO_RX
, .maxpacket
= 512, },
1142 { .hw_ep_num
= 9, .style
= FIFO_TX
, .maxpacket
= 512, },
1143 { .hw_ep_num
= 9, .style
= FIFO_RX
, .maxpacket
= 512, },
1144 { .hw_ep_num
= 10, .style
= FIFO_TX
, .maxpacket
= 256, },
1145 { .hw_ep_num
= 10, .style
= FIFO_RX
, .maxpacket
= 64, },
1146 { .hw_ep_num
= 11, .style
= FIFO_TX
, .maxpacket
= 256, },
1147 { .hw_ep_num
= 11, .style
= FIFO_RX
, .maxpacket
= 64, },
1148 { .hw_ep_num
= 12, .style
= FIFO_TX
, .maxpacket
= 256, },
1149 { .hw_ep_num
= 12, .style
= FIFO_RX
, .maxpacket
= 64, },
1150 { .hw_ep_num
= 13, .style
= FIFO_RXTX
, .maxpacket
= 4096, },
1151 { .hw_ep_num
= 14, .style
= FIFO_RXTX
, .maxpacket
= 1024, },
1152 { .hw_ep_num
= 15, .style
= FIFO_RXTX
, .maxpacket
= 1024, },
1155 /* mode 5 - fits in 8KB */
1156 static struct musb_fifo_cfg __initdata mode_5_cfg
[] = {
1157 { .hw_ep_num
= 1, .style
= FIFO_TX
, .maxpacket
= 512, },
1158 { .hw_ep_num
= 1, .style
= FIFO_RX
, .maxpacket
= 512, },
1159 { .hw_ep_num
= 2, .style
= FIFO_TX
, .maxpacket
= 512, },
1160 { .hw_ep_num
= 2, .style
= FIFO_RX
, .maxpacket
= 512, },
1161 { .hw_ep_num
= 3, .style
= FIFO_TX
, .maxpacket
= 512, },
1162 { .hw_ep_num
= 3, .style
= FIFO_RX
, .maxpacket
= 512, },
1163 { .hw_ep_num
= 4, .style
= FIFO_TX
, .maxpacket
= 512, },
1164 { .hw_ep_num
= 4, .style
= FIFO_RX
, .maxpacket
= 512, },
1165 { .hw_ep_num
= 5, .style
= FIFO_TX
, .maxpacket
= 512, },
1166 { .hw_ep_num
= 5, .style
= FIFO_RX
, .maxpacket
= 512, },
1167 { .hw_ep_num
= 6, .style
= FIFO_TX
, .maxpacket
= 32, },
1168 { .hw_ep_num
= 6, .style
= FIFO_RX
, .maxpacket
= 32, },
1169 { .hw_ep_num
= 7, .style
= FIFO_TX
, .maxpacket
= 32, },
1170 { .hw_ep_num
= 7, .style
= FIFO_RX
, .maxpacket
= 32, },
1171 { .hw_ep_num
= 8, .style
= FIFO_TX
, .maxpacket
= 32, },
1172 { .hw_ep_num
= 8, .style
= FIFO_RX
, .maxpacket
= 32, },
1173 { .hw_ep_num
= 9, .style
= FIFO_TX
, .maxpacket
= 32, },
1174 { .hw_ep_num
= 9, .style
= FIFO_RX
, .maxpacket
= 32, },
1175 { .hw_ep_num
= 10, .style
= FIFO_TX
, .maxpacket
= 32, },
1176 { .hw_ep_num
= 10, .style
= FIFO_RX
, .maxpacket
= 32, },
1177 { .hw_ep_num
= 11, .style
= FIFO_TX
, .maxpacket
= 32, },
1178 { .hw_ep_num
= 11, .style
= FIFO_RX
, .maxpacket
= 32, },
1179 { .hw_ep_num
= 12, .style
= FIFO_TX
, .maxpacket
= 32, },
1180 { .hw_ep_num
= 12, .style
= FIFO_RX
, .maxpacket
= 32, },
1181 { .hw_ep_num
= 13, .style
= FIFO_RXTX
, .maxpacket
= 512, },
1182 { .hw_ep_num
= 14, .style
= FIFO_RXTX
, .maxpacket
= 1024, },
1183 { .hw_ep_num
= 15, .style
= FIFO_RXTX
, .maxpacket
= 1024, },
1187 * configure a fifo; for non-shared endpoints, this may be called
1188 * once for a tx fifo and once for an rx fifo.
1190 * returns negative errno or offset for next fifo.
1193 fifo_setup(struct musb
*musb
, struct musb_hw_ep
*hw_ep
,
1194 const struct musb_fifo_cfg
*cfg
, u16 offset
)
1196 void __iomem
*mbase
= musb
->mregs
;
1198 u16 maxpacket
= cfg
->maxpacket
;
1199 u16 c_off
= offset
>> 3;
1202 /* expect hw_ep has already been zero-initialized */
1204 size
= ffs(max(maxpacket
, (u16
) 8)) - 1;
1205 maxpacket
= 1 << size
;
1208 if (cfg
->mode
== BUF_DOUBLE
) {
1209 if ((offset
+ (maxpacket
<< 1)) >
1210 (1 << (musb
->config
->ram_bits
+ 2)))
1212 c_size
|= MUSB_FIFOSZ_DPB
;
1214 if ((offset
+ maxpacket
) > (1 << (musb
->config
->ram_bits
+ 2)))
1218 /* configure the FIFO */
1219 musb_writeb(mbase
, MUSB_INDEX
, hw_ep
->epnum
);
1221 #ifdef CONFIG_USB_MUSB_HDRC_HCD
1222 /* EP0 reserved endpoint for control, bidirectional;
1223 * EP1 reserved for bulk, two unidirection halves.
1225 if (hw_ep
->epnum
== 1)
1226 musb
->bulk_ep
= hw_ep
;
1227 /* REVISIT error check: be sure ep0 can both rx and tx ... */
1229 switch (cfg
->style
) {
1231 musb_write_txfifosz(mbase
, c_size
);
1232 musb_write_txfifoadd(mbase
, c_off
);
1233 hw_ep
->tx_double_buffered
= !!(c_size
& MUSB_FIFOSZ_DPB
);
1234 hw_ep
->max_packet_sz_tx
= maxpacket
;
1237 musb_write_rxfifosz(mbase
, c_size
);
1238 musb_write_rxfifoadd(mbase
, c_off
);
1239 hw_ep
->rx_double_buffered
= !!(c_size
& MUSB_FIFOSZ_DPB
);
1240 hw_ep
->max_packet_sz_rx
= maxpacket
;
1243 musb_write_txfifosz(mbase
, c_size
);
1244 musb_write_txfifoadd(mbase
, c_off
);
1245 hw_ep
->rx_double_buffered
= !!(c_size
& MUSB_FIFOSZ_DPB
);
1246 hw_ep
->max_packet_sz_rx
= maxpacket
;
1248 musb_write_rxfifosz(mbase
, c_size
);
1249 musb_write_rxfifoadd(mbase
, c_off
);
1250 hw_ep
->tx_double_buffered
= hw_ep
->rx_double_buffered
;
1251 hw_ep
->max_packet_sz_tx
= maxpacket
;
1253 hw_ep
->is_shared_fifo
= true;
1257 /* NOTE rx and tx endpoint irqs aren't managed separately,
1258 * which happens to be ok
1260 musb
->epmask
|= (1 << hw_ep
->epnum
);
1262 return offset
+ (maxpacket
<< ((c_size
& MUSB_FIFOSZ_DPB
) ? 1 : 0));
1265 static struct musb_fifo_cfg __initdata ep0_cfg
= {
1266 .style
= FIFO_RXTX
, .maxpacket
= 64,
1269 static int __init
ep_config_from_table(struct musb
*musb
)
1271 const struct musb_fifo_cfg
*cfg
;
1274 struct musb_hw_ep
*hw_ep
= musb
->endpoints
;
1276 if (musb
->config
->fifo_cfg
) {
1277 cfg
= musb
->config
->fifo_cfg
;
1278 n
= musb
->config
->fifo_cfg_size
;
1282 switch (fifo_mode
) {
1288 n
= ARRAY_SIZE(mode_0_cfg
);
1292 n
= ARRAY_SIZE(mode_1_cfg
);
1296 n
= ARRAY_SIZE(mode_2_cfg
);
1300 n
= ARRAY_SIZE(mode_3_cfg
);
1304 n
= ARRAY_SIZE(mode_4_cfg
);
1308 n
= ARRAY_SIZE(mode_5_cfg
);
1312 printk(KERN_DEBUG
"%s: setup fifo_mode %d\n",
1313 musb_driver_name
, fifo_mode
);
1317 offset
= fifo_setup(musb
, hw_ep
, &ep0_cfg
, 0);
1318 /* assert(offset > 0) */
1320 /* NOTE: for RTL versions >= 1.400 EPINFO and RAMINFO would
1321 * be better than static musb->config->num_eps and DYN_FIFO_SIZE...
1324 for (i
= 0; i
< n
; i
++) {
1325 u8 epn
= cfg
->hw_ep_num
;
1327 if (epn
>= musb
->config
->num_eps
) {
1328 pr_debug("%s: invalid ep %d\n",
1329 musb_driver_name
, epn
);
1332 offset
= fifo_setup(musb
, hw_ep
+ epn
, cfg
++, offset
);
1334 pr_debug("%s: mem overrun, ep %d\n",
1335 musb_driver_name
, epn
);
1339 musb
->nr_endpoints
= max(epn
, musb
->nr_endpoints
);
1342 printk(KERN_DEBUG
"%s: %d/%d max ep, %d/%d memory\n",
1344 n
+ 1, musb
->config
->num_eps
* 2 - 1,
1345 offset
, (1 << (musb
->config
->ram_bits
+ 2)));
1347 #ifdef CONFIG_USB_MUSB_HDRC_HCD
1348 if (!musb
->bulk_ep
) {
1349 pr_debug("%s: missing bulk\n", musb_driver_name
);
1359 * ep_config_from_hw - when MUSB_C_DYNFIFO_DEF is false
1360 * @param musb the controller
1362 static int __init
ep_config_from_hw(struct musb
*musb
)
1365 struct musb_hw_ep
*hw_ep
;
1366 void *mbase
= musb
->mregs
;
1369 DBG(2, "<== static silicon ep config\n");
1371 /* FIXME pick up ep0 maxpacket size */
1373 for (epnum
= 1; epnum
< musb
->config
->num_eps
; epnum
++) {
1374 musb_ep_select(mbase
, epnum
);
1375 hw_ep
= musb
->endpoints
+ epnum
;
1377 ret
= musb_read_fifosize(musb
, hw_ep
, epnum
);
1381 /* FIXME set up hw_ep->{rx,tx}_double_buffered */
1383 #ifdef CONFIG_USB_MUSB_HDRC_HCD
1384 /* pick an RX/TX endpoint for bulk */
1385 if (hw_ep
->max_packet_sz_tx
< 512
1386 || hw_ep
->max_packet_sz_rx
< 512)
1389 /* REVISIT: this algorithm is lazy, we should at least
1390 * try to pick a double buffered endpoint.
1394 musb
->bulk_ep
= hw_ep
;
1398 #ifdef CONFIG_USB_MUSB_HDRC_HCD
1399 if (!musb
->bulk_ep
) {
1400 pr_debug("%s: missing bulk\n", musb_driver_name
);
1408 enum { MUSB_CONTROLLER_MHDRC
, MUSB_CONTROLLER_HDRC
, };
1410 /* Initialize MUSB (M)HDRC part of the USB hardware subsystem;
1411 * configure endpoints, or take their config from silicon
1413 static int __init
musb_core_init(u16 musb_type
, struct musb
*musb
)
1417 char aInfo
[90], aRevision
[32], aDate
[12];
1418 void __iomem
*mbase
= musb
->mregs
;
1422 /* log core options (read using indexed model) */
1423 reg
= musb_read_configdata(mbase
);
1425 strcpy(aInfo
, (reg
& MUSB_CONFIGDATA_UTMIDW
) ? "UTMI-16" : "UTMI-8");
1426 if (reg
& MUSB_CONFIGDATA_DYNFIFO
) {
1427 strcat(aInfo
, ", dyn FIFOs");
1428 musb
->dyn_fifo
= true;
1430 if (reg
& MUSB_CONFIGDATA_MPRXE
) {
1431 strcat(aInfo
, ", bulk combine");
1432 musb
->bulk_combine
= true;
1434 if (reg
& MUSB_CONFIGDATA_MPTXE
) {
1435 strcat(aInfo
, ", bulk split");
1436 musb
->bulk_split
= true;
1438 if (reg
& MUSB_CONFIGDATA_HBRXE
) {
1439 strcat(aInfo
, ", HB-ISO Rx");
1440 musb
->hb_iso_rx
= true;
1442 if (reg
& MUSB_CONFIGDATA_HBTXE
) {
1443 strcat(aInfo
, ", HB-ISO Tx");
1444 musb
->hb_iso_tx
= true;
1446 if (reg
& MUSB_CONFIGDATA_SOFTCONE
)
1447 strcat(aInfo
, ", SoftConn");
1449 printk(KERN_DEBUG
"%s: ConfigData=0x%02x (%s)\n",
1450 musb_driver_name
, reg
, aInfo
);
1453 if (MUSB_CONTROLLER_MHDRC
== musb_type
) {
1454 musb
->is_multipoint
= 1;
1457 musb
->is_multipoint
= 0;
1459 #ifdef CONFIG_USB_MUSB_HDRC_HCD
1460 #ifndef CONFIG_USB_OTG_BLACKLIST_HUB
1462 "%s: kernel must blacklist external hubs\n",
1468 /* log release info */
1469 musb
->hwvers
= musb_read_hwvers(mbase
);
1470 snprintf(aRevision
, 32, "%d.%d%s", MUSB_HWVERS_MAJOR(musb
->hwvers
),
1471 MUSB_HWVERS_MINOR(musb
->hwvers
),
1472 (musb
->hwvers
& MUSB_HWVERS_RC
) ? "RC" : "");
1473 printk(KERN_DEBUG
"%s: %sHDRC RTL version %s %s\n",
1474 musb_driver_name
, type
, aRevision
, aDate
);
1477 musb_configure_ep0(musb
);
1479 /* discover endpoint configuration */
1480 musb
->nr_endpoints
= 1;
1484 status
= ep_config_from_table(musb
);
1486 status
= ep_config_from_hw(musb
);
1491 /* finish init, and print endpoint config */
1492 for (i
= 0; i
< musb
->nr_endpoints
; i
++) {
1493 struct musb_hw_ep
*hw_ep
= musb
->endpoints
+ i
;
1495 hw_ep
->fifo
= MUSB_FIFO_OFFSET(i
) + mbase
;
1496 #ifdef CONFIG_USB_TUSB6010
1497 hw_ep
->fifo_async
= musb
->async
+ 0x400 + MUSB_FIFO_OFFSET(i
);
1498 hw_ep
->fifo_sync
= musb
->sync
+ 0x400 + MUSB_FIFO_OFFSET(i
);
1499 hw_ep
->fifo_sync_va
=
1500 musb
->sync_va
+ 0x400 + MUSB_FIFO_OFFSET(i
);
1503 hw_ep
->conf
= mbase
- 0x400 + TUSB_EP0_CONF
;
1505 hw_ep
->conf
= mbase
+ 0x400 + (((i
- 1) & 0xf) << 2);
1508 hw_ep
->regs
= MUSB_EP_OFFSET(i
, 0) + mbase
;
1509 #ifdef CONFIG_USB_MUSB_HDRC_HCD
1510 hw_ep
->target_regs
= musb_read_target_reg_base(i
, mbase
);
1511 hw_ep
->rx_reinit
= 1;
1512 hw_ep
->tx_reinit
= 1;
1515 if (hw_ep
->max_packet_sz_tx
) {
1517 "%s: hw_ep %d%s, %smax %d\n",
1518 musb_driver_name
, i
,
1519 hw_ep
->is_shared_fifo
? "shared" : "tx",
1520 hw_ep
->tx_double_buffered
1521 ? "doublebuffer, " : "",
1522 hw_ep
->max_packet_sz_tx
);
1524 if (hw_ep
->max_packet_sz_rx
&& !hw_ep
->is_shared_fifo
) {
1526 "%s: hw_ep %d%s, %smax %d\n",
1527 musb_driver_name
, i
,
1529 hw_ep
->rx_double_buffered
1530 ? "doublebuffer, " : "",
1531 hw_ep
->max_packet_sz_rx
);
1533 if (!(hw_ep
->max_packet_sz_tx
|| hw_ep
->max_packet_sz_rx
))
1534 DBG(1, "hw_ep %d not configured\n", i
);
1540 /*-------------------------------------------------------------------------*/
1542 #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3430) || \
1543 defined(CONFIG_ARCH_OMAP4)
1545 static irqreturn_t
generic_interrupt(int irq
, void *__hci
)
1547 unsigned long flags
;
1548 irqreturn_t retval
= IRQ_NONE
;
1549 struct musb
*musb
= __hci
;
1551 spin_lock_irqsave(&musb
->lock
, flags
);
1553 musb
->int_usb
= musb_readb(musb
->mregs
, MUSB_INTRUSB
);
1554 musb
->int_tx
= musb_readw(musb
->mregs
, MUSB_INTRTX
);
1555 musb
->int_rx
= musb_readw(musb
->mregs
, MUSB_INTRRX
);
1557 if (musb
->int_usb
|| musb
->int_tx
|| musb
->int_rx
)
1558 retval
= musb_interrupt(musb
);
1560 spin_unlock_irqrestore(&musb
->lock
, flags
);
1566 #define generic_interrupt NULL
1570 * handle all the irqs defined by the HDRC core. for now we expect: other
1571 * irq sources (phy, dma, etc) will be handled first, musb->int_* values
1572 * will be assigned, and the irq will already have been acked.
1574 * called in irq context with spinlock held, irqs blocked
1576 irqreturn_t
musb_interrupt(struct musb
*musb
)
1578 irqreturn_t retval
= IRQ_NONE
;
1583 devctl
= musb_readb(musb
->mregs
, MUSB_DEVCTL
);
1584 power
= musb_readb(musb
->mregs
, MUSB_POWER
);
1586 DBG(4, "** IRQ %s usb%04x tx%04x rx%04x\n",
1587 (devctl
& MUSB_DEVCTL_HM
) ? "host" : "peripheral",
1588 musb
->int_usb
, musb
->int_tx
, musb
->int_rx
);
1590 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
1591 if (is_otg_enabled(musb
) || is_peripheral_enabled(musb
))
1592 if (!musb
->gadget_driver
) {
1593 DBG(5, "No gadget driver loaded\n");
1598 /* the core can interrupt us for multiple reasons; docs have
1599 * a generic interrupt flowchart to follow
1602 retval
|= musb_stage0_irq(musb
, musb
->int_usb
,
1605 /* "stage 1" is handling endpoint irqs */
1607 /* handle endpoint 0 first */
1608 if (musb
->int_tx
& 1) {
1609 if (devctl
& MUSB_DEVCTL_HM
)
1610 retval
|= musb_h_ep0_irq(musb
);
1612 retval
|= musb_g_ep0_irq(musb
);
1615 /* RX on endpoints 1-15 */
1616 reg
= musb
->int_rx
>> 1;
1620 /* musb_ep_select(musb->mregs, ep_num); */
1621 /* REVISIT just retval = ep->rx_irq(...) */
1622 retval
= IRQ_HANDLED
;
1623 if (devctl
& MUSB_DEVCTL_HM
) {
1624 if (is_host_capable())
1625 musb_host_rx(musb
, ep_num
);
1627 if (is_peripheral_capable())
1628 musb_g_rx(musb
, ep_num
);
1636 /* TX on endpoints 1-15 */
1637 reg
= musb
->int_tx
>> 1;
1641 /* musb_ep_select(musb->mregs, ep_num); */
1642 /* REVISIT just retval |= ep->tx_irq(...) */
1643 retval
= IRQ_HANDLED
;
1644 if (devctl
& MUSB_DEVCTL_HM
) {
1645 if (is_host_capable())
1646 musb_host_tx(musb
, ep_num
);
1648 if (is_peripheral_capable())
1649 musb_g_tx(musb
, ep_num
);
1660 #ifndef CONFIG_MUSB_PIO_ONLY
1661 static int __initdata use_dma
= 1;
1663 /* "modprobe ... use_dma=0" etc */
1664 module_param(use_dma
, bool, 0);
1665 MODULE_PARM_DESC(use_dma
, "enable/disable use of DMA");
1667 void musb_dma_completion(struct musb
*musb
, u8 epnum
, u8 transmit
)
1669 u8 devctl
= musb_readb(musb
->mregs
, MUSB_DEVCTL
);
1671 /* called with controller lock already held */
1674 #ifndef CONFIG_USB_TUSB_OMAP_DMA
1675 if (!is_cppi_enabled()) {
1677 if (devctl
& MUSB_DEVCTL_HM
)
1678 musb_h_ep0_irq(musb
);
1680 musb_g_ep0_irq(musb
);
1684 /* endpoints 1..15 */
1686 if (devctl
& MUSB_DEVCTL_HM
) {
1687 if (is_host_capable())
1688 musb_host_tx(musb
, epnum
);
1690 if (is_peripheral_capable())
1691 musb_g_tx(musb
, epnum
);
1695 if (devctl
& MUSB_DEVCTL_HM
) {
1696 if (is_host_capable())
1697 musb_host_rx(musb
, epnum
);
1699 if (is_peripheral_capable())
1700 musb_g_rx(musb
, epnum
);
1710 /*-------------------------------------------------------------------------*/
1715 musb_mode_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1717 struct musb
*musb
= dev_to_musb(dev
);
1718 unsigned long flags
;
1721 spin_lock_irqsave(&musb
->lock
, flags
);
1722 ret
= sprintf(buf
, "%s\n", otg_state_string(musb
));
1723 spin_unlock_irqrestore(&musb
->lock
, flags
);
1729 musb_mode_store(struct device
*dev
, struct device_attribute
*attr
,
1730 const char *buf
, size_t n
)
1732 struct musb
*musb
= dev_to_musb(dev
);
1733 unsigned long flags
;
1736 spin_lock_irqsave(&musb
->lock
, flags
);
1737 if (sysfs_streq(buf
, "host"))
1738 status
= musb_platform_set_mode(musb
, MUSB_HOST
);
1739 else if (sysfs_streq(buf
, "peripheral"))
1740 status
= musb_platform_set_mode(musb
, MUSB_PERIPHERAL
);
1741 else if (sysfs_streq(buf
, "otg"))
1742 status
= musb_platform_set_mode(musb
, MUSB_OTG
);
1745 spin_unlock_irqrestore(&musb
->lock
, flags
);
1747 return (status
== 0) ? n
: status
;
1749 static DEVICE_ATTR(mode
, 0644, musb_mode_show
, musb_mode_store
);
1752 musb_vbus_store(struct device
*dev
, struct device_attribute
*attr
,
1753 const char *buf
, size_t n
)
1755 struct musb
*musb
= dev_to_musb(dev
);
1756 unsigned long flags
;
1759 if (sscanf(buf
, "%lu", &val
) < 1) {
1760 dev_err(dev
, "Invalid VBUS timeout ms value\n");
1764 spin_lock_irqsave(&musb
->lock
, flags
);
1765 /* force T(a_wait_bcon) to be zero/unlimited *OR* valid */
1766 musb
->a_wait_bcon
= val
? max_t(int, val
, OTG_TIME_A_WAIT_BCON
) : 0 ;
1767 if (musb
->xceiv
->state
== OTG_STATE_A_WAIT_BCON
)
1768 musb
->is_active
= 0;
1769 musb_platform_try_idle(musb
, jiffies
+ msecs_to_jiffies(val
));
1770 spin_unlock_irqrestore(&musb
->lock
, flags
);
1776 musb_vbus_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1778 struct musb
*musb
= dev_to_musb(dev
);
1779 unsigned long flags
;
1783 spin_lock_irqsave(&musb
->lock
, flags
);
1784 val
= musb
->a_wait_bcon
;
1785 /* FIXME get_vbus_status() is normally #defined as false...
1786 * and is effectively TUSB-specific.
1788 vbus
= musb_platform_get_vbus_status(musb
);
1789 spin_unlock_irqrestore(&musb
->lock
, flags
);
1791 return sprintf(buf
, "Vbus %s, timeout %lu msec\n",
1792 vbus
? "on" : "off", val
);
1794 static DEVICE_ATTR(vbus
, 0644, musb_vbus_show
, musb_vbus_store
);
1796 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
1798 /* Gadget drivers can't know that a host is connected so they might want
1799 * to start SRP, but users can. This allows userspace to trigger SRP.
1802 musb_srp_store(struct device
*dev
, struct device_attribute
*attr
,
1803 const char *buf
, size_t n
)
1805 struct musb
*musb
= dev_to_musb(dev
);
1808 if (sscanf(buf
, "%hu", &srp
) != 1
1810 dev_err(dev
, "SRP: Value must be 1\n");
1815 musb_g_wakeup(musb
);
1819 static DEVICE_ATTR(srp
, 0644, NULL
, musb_srp_store
);
1821 #endif /* CONFIG_USB_GADGET_MUSB_HDRC */
1823 static struct attribute
*musb_attributes
[] = {
1824 &dev_attr_mode
.attr
,
1825 &dev_attr_vbus
.attr
,
1826 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
1832 static const struct attribute_group musb_attr_group
= {
1833 .attrs
= musb_attributes
,
1838 /* Only used to provide driver mode change events */
1839 static void musb_irq_work(struct work_struct
*data
)
1841 struct musb
*musb
= container_of(data
, struct musb
, irq_work
);
1842 static int old_state
;
1844 if (musb
->xceiv
->state
!= old_state
) {
1845 old_state
= musb
->xceiv
->state
;
1846 sysfs_notify(&musb
->controller
->kobj
, NULL
, "mode");
1850 /* --------------------------------------------------------------------------
1854 static struct musb
*__init
1855 allocate_instance(struct device
*dev
,
1856 struct musb_hdrc_config
*config
, void __iomem
*mbase
)
1859 struct musb_hw_ep
*ep
;
1861 #ifdef CONFIG_USB_MUSB_HDRC_HCD
1862 struct usb_hcd
*hcd
;
1864 hcd
= usb_create_hcd(&musb_hc_driver
, dev
, dev_name(dev
));
1867 /* usbcore sets dev->driver_data to hcd, and sometimes uses that... */
1869 musb
= hcd_to_musb(hcd
);
1870 INIT_LIST_HEAD(&musb
->control
);
1871 INIT_LIST_HEAD(&musb
->in_bulk
);
1872 INIT_LIST_HEAD(&musb
->out_bulk
);
1874 hcd
->uses_new_polling
= 1;
1876 musb
->vbuserr_retry
= VBUSERR_RETRY_COUNT
;
1877 musb
->a_wait_bcon
= OTG_TIME_A_WAIT_BCON
;
1879 musb
= kzalloc(sizeof *musb
, GFP_KERNEL
);
1882 dev_set_drvdata(dev
, musb
);
1886 musb
->mregs
= mbase
;
1887 musb
->ctrl_base
= mbase
;
1888 musb
->nIrq
= -ENODEV
;
1889 musb
->config
= config
;
1890 BUG_ON(musb
->config
->num_eps
> MUSB_C_NUM_EPS
);
1891 for (epnum
= 0, ep
= musb
->endpoints
;
1892 epnum
< musb
->config
->num_eps
;
1898 musb
->controller
= dev
;
1902 static void musb_free(struct musb
*musb
)
1904 /* this has multiple entry modes. it handles fault cleanup after
1905 * probe(), where things may be partially set up, as well as rmmod
1906 * cleanup after everything's been de-activated.
1910 sysfs_remove_group(&musb
->controller
->kobj
, &musb_attr_group
);
1913 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
1914 musb_gadget_cleanup(musb
);
1917 if (musb
->nIrq
>= 0) {
1919 disable_irq_wake(musb
->nIrq
);
1920 free_irq(musb
->nIrq
, musb
);
1922 if (is_dma_capable() && musb
->dma_controller
) {
1923 struct dma_controller
*c
= musb
->dma_controller
;
1926 dma_controller_destroy(c
);
1929 #ifdef CONFIG_USB_MUSB_HDRC_HCD
1930 usb_put_hcd(musb_to_hcd(musb
));
1937 * Perform generic per-controller initialization.
1939 * @pDevice: the controller (already clocked, etc)
1941 * @mregs: virtual address of controller registers,
1942 * not yet corrected for platform-specific offsets
1945 musb_init_controller(struct device
*dev
, int nIrq
, void __iomem
*ctrl
)
1949 struct musb_hdrc_platform_data
*plat
= dev
->platform_data
;
1951 /* The driver might handle more features than the board; OK.
1952 * Fail when the board needs a feature that's not enabled.
1955 dev_dbg(dev
, "no platform_data?\n");
1960 switch (plat
->mode
) {
1962 #ifdef CONFIG_USB_MUSB_HDRC_HCD
1967 case MUSB_PERIPHERAL
:
1968 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
1974 #ifdef CONFIG_USB_MUSB_OTG
1980 dev_err(dev
, "incompatible Kconfig role setting\n");
1986 musb
= allocate_instance(dev
, plat
->config
, ctrl
);
1992 spin_lock_init(&musb
->lock
);
1993 musb
->board_mode
= plat
->mode
;
1994 musb
->board_set_power
= plat
->set_power
;
1995 musb
->set_clock
= plat
->set_clock
;
1996 musb
->min_power
= plat
->min_power
;
1998 /* Clock usage is chip-specific ... functional clock (DaVinci,
1999 * OMAP2430), or PHY ref (some TUSB6010 boards). All this core
2000 * code does is make sure a clock handle is available; platform
2001 * code manages it during start/stop and suspend/resume.
2004 musb
->clock
= clk_get(dev
, plat
->clock
);
2005 if (IS_ERR(musb
->clock
)) {
2006 status
= PTR_ERR(musb
->clock
);
2012 /* The musb_platform_init() call:
2013 * - adjusts musb->mregs and musb->isr if needed,
2014 * - may initialize an integrated tranceiver
2015 * - initializes musb->xceiv, usually by otg_get_transceiver()
2016 * - activates clocks.
2017 * - stops powering VBUS
2018 * - assigns musb->board_set_vbus if host mode is enabled
2020 * There are various transciever configurations. Blackfin,
2021 * DaVinci, TUSB60x0, and others integrate them. OMAP3 uses
2022 * external/discrete ones in various flavors (twl4030 family,
2023 * isp1504, non-OTG, etc) mostly hooking up through ULPI.
2025 musb
->isr
= generic_interrupt
;
2026 status
= musb_platform_init(musb
, plat
->board_data
);
2035 if (!musb
->xceiv
->io_ops
) {
2036 musb
->xceiv
->io_priv
= musb
->mregs
;
2037 musb
->xceiv
->io_ops
= &musb_ulpi_access
;
2040 #ifndef CONFIG_MUSB_PIO_ONLY
2041 if (use_dma
&& dev
->dma_mask
) {
2042 struct dma_controller
*c
;
2044 c
= dma_controller_create(musb
, musb
->mregs
);
2045 musb
->dma_controller
= c
;
2050 /* ideally this would be abstracted in platform setup */
2051 if (!is_dma_capable() || !musb
->dma_controller
)
2052 dev
->dma_mask
= NULL
;
2054 /* be sure interrupts are disabled before connecting ISR */
2055 musb_platform_disable(musb
);
2056 musb_generic_disable(musb
);
2058 /* setup musb parts of the core (especially endpoints) */
2059 status
= musb_core_init(plat
->config
->multipoint
2060 ? MUSB_CONTROLLER_MHDRC
2061 : MUSB_CONTROLLER_HDRC
, musb
);
2065 #ifdef CONFIG_USB_MUSB_OTG
2066 setup_timer(&musb
->otg_timer
, musb_otg_timer_func
, (unsigned long) musb
);
2069 /* Init IRQ workqueue before request_irq */
2070 INIT_WORK(&musb
->irq_work
, musb_irq_work
);
2072 /* attach to the IRQ */
2073 if (request_irq(nIrq
, musb
->isr
, 0, dev_name(dev
), musb
)) {
2074 dev_err(dev
, "request_irq %d failed!\n", nIrq
);
2079 /* FIXME this handles wakeup irqs wrong */
2080 if (enable_irq_wake(nIrq
) == 0) {
2082 device_init_wakeup(dev
, 1);
2087 /* host side needs more setup */
2088 if (is_host_enabled(musb
)) {
2089 struct usb_hcd
*hcd
= musb_to_hcd(musb
);
2091 otg_set_host(musb
->xceiv
, &hcd
->self
);
2093 if (is_otg_enabled(musb
))
2094 hcd
->self
.otg_port
= 1;
2095 musb
->xceiv
->host
= &hcd
->self
;
2096 hcd
->power_budget
= 2 * (plat
->power
? : 250);
2098 /* program PHY to use external vBus if required */
2099 if (plat
->extvbus
) {
2100 u8 busctl
= musb_read_ulpi_buscontrol(musb
->mregs
);
2101 busctl
|= MUSB_ULPI_USE_EXTVBUS
;
2102 musb_write_ulpi_buscontrol(musb
->mregs
, busctl
);
2106 /* For the host-only role, we can activate right away.
2107 * (We expect the ID pin to be forcibly grounded!!)
2108 * Otherwise, wait till the gadget driver hooks up.
2110 if (!is_otg_enabled(musb
) && is_host_enabled(musb
)) {
2111 MUSB_HST_MODE(musb
);
2112 musb
->xceiv
->default_a
= 1;
2113 musb
->xceiv
->state
= OTG_STATE_A_IDLE
;
2115 status
= usb_add_hcd(musb_to_hcd(musb
), -1, 0);
2117 DBG(1, "%s mode, status %d, devctl %02x %c\n",
2119 musb_readb(musb
->mregs
, MUSB_DEVCTL
),
2120 (musb_readb(musb
->mregs
, MUSB_DEVCTL
)
2121 & MUSB_DEVCTL_BDEVICE
2124 } else /* peripheral is enabled */ {
2125 MUSB_DEV_MODE(musb
);
2126 musb
->xceiv
->default_a
= 0;
2127 musb
->xceiv
->state
= OTG_STATE_B_IDLE
;
2129 status
= musb_gadget_setup(musb
);
2131 DBG(1, "%s mode, status %d, dev%02x\n",
2132 is_otg_enabled(musb
) ? "OTG" : "PERIPHERAL",
2134 musb_readb(musb
->mregs
, MUSB_DEVCTL
));
2140 status
= musb_init_debugfs(musb
);
2145 status
= sysfs_create_group(&musb
->controller
->kobj
, &musb_attr_group
);
2150 dev_info(dev
, "USB %s mode controller at %p using %s, IRQ %d\n",
2152 switch (musb
->board_mode
) {
2153 case MUSB_HOST
: s
= "Host"; break;
2154 case MUSB_PERIPHERAL
: s
= "Peripheral"; break;
2155 default: s
= "OTG"; break;
2158 (is_dma_capable() && musb
->dma_controller
)
2165 musb_exit_debugfs(musb
);
2168 if (!is_otg_enabled(musb
) && is_host_enabled(musb
))
2169 usb_remove_hcd(musb_to_hcd(musb
));
2171 musb_gadget_cleanup(musb
);
2175 device_init_wakeup(dev
, 0);
2176 musb_platform_exit(musb
);
2180 clk_put(musb
->clock
);
2183 dev_err(musb
->controller
,
2184 "musb_init_controller failed with status %d\n", status
);
2194 /*-------------------------------------------------------------------------*/
2196 /* all implementations (PCI bridge to FPGA, VLYNQ, etc) should just
2197 * bridge to a platform device; this driver then suffices.
2200 #ifndef CONFIG_MUSB_PIO_ONLY
2201 static u64
*orig_dma_mask
;
2204 static int __init
musb_probe(struct platform_device
*pdev
)
2206 struct device
*dev
= &pdev
->dev
;
2207 int irq
= platform_get_irq(pdev
, 0);
2209 struct resource
*iomem
;
2212 iomem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
2213 if (!iomem
|| irq
== 0)
2216 base
= ioremap(iomem
->start
, resource_size(iomem
));
2218 dev_err(dev
, "ioremap failed\n");
2222 #ifndef CONFIG_MUSB_PIO_ONLY
2223 /* clobbered by use_dma=n */
2224 orig_dma_mask
= dev
->dma_mask
;
2226 status
= musb_init_controller(dev
, irq
, base
);
2233 static int __exit
musb_remove(struct platform_device
*pdev
)
2235 struct musb
*musb
= dev_to_musb(&pdev
->dev
);
2236 void __iomem
*ctrl_base
= musb
->ctrl_base
;
2238 /* this gets called on rmmod.
2239 * - Host mode: host may still be active
2240 * - Peripheral mode: peripheral is deactivated (or never-activated)
2241 * - OTG mode: both roles are deactivated (or never-activated)
2243 musb_exit_debugfs(musb
);
2244 musb_shutdown(pdev
);
2245 #ifdef CONFIG_USB_MUSB_HDRC_HCD
2246 if (musb
->board_mode
== MUSB_HOST
)
2247 usb_remove_hcd(musb_to_hcd(musb
));
2249 musb_writeb(musb
->mregs
, MUSB_DEVCTL
, 0);
2250 musb_platform_exit(musb
);
2251 musb_writeb(musb
->mregs
, MUSB_DEVCTL
, 0);
2255 device_init_wakeup(&pdev
->dev
, 0);
2256 #ifndef CONFIG_MUSB_PIO_ONLY
2257 pdev
->dev
.dma_mask
= orig_dma_mask
;
2264 static struct musb_context_registers musb_context
;
2266 void musb_save_context(struct musb
*musb
)
2269 void __iomem
*musb_base
= musb
->mregs
;
2272 if (is_host_enabled(musb
)) {
2273 musb_context
.frame
= musb_readw(musb_base
, MUSB_FRAME
);
2274 musb_context
.testmode
= musb_readb(musb_base
, MUSB_TESTMODE
);
2275 musb_context
.busctl
= musb_read_ulpi_buscontrol(musb
->mregs
);
2277 musb_context
.power
= musb_readb(musb_base
, MUSB_POWER
);
2278 musb_context
.intrtxe
= musb_readw(musb_base
, MUSB_INTRTXE
);
2279 musb_context
.intrrxe
= musb_readw(musb_base
, MUSB_INTRRXE
);
2280 musb_context
.intrusbe
= musb_readb(musb_base
, MUSB_INTRUSBE
);
2281 musb_context
.index
= musb_readb(musb_base
, MUSB_INDEX
);
2282 musb_context
.devctl
= musb_readb(musb_base
, MUSB_DEVCTL
);
2284 for (i
= 0; i
< musb
->config
->num_eps
; ++i
) {
2285 epio
= musb
->endpoints
[i
].regs
;
2286 musb_context
.index_regs
[i
].txmaxp
=
2287 musb_readw(epio
, MUSB_TXMAXP
);
2288 musb_context
.index_regs
[i
].txcsr
=
2289 musb_readw(epio
, MUSB_TXCSR
);
2290 musb_context
.index_regs
[i
].rxmaxp
=
2291 musb_readw(epio
, MUSB_RXMAXP
);
2292 musb_context
.index_regs
[i
].rxcsr
=
2293 musb_readw(epio
, MUSB_RXCSR
);
2295 if (musb
->dyn_fifo
) {
2296 musb_context
.index_regs
[i
].txfifoadd
=
2297 musb_read_txfifoadd(musb_base
);
2298 musb_context
.index_regs
[i
].rxfifoadd
=
2299 musb_read_rxfifoadd(musb_base
);
2300 musb_context
.index_regs
[i
].txfifosz
=
2301 musb_read_txfifosz(musb_base
);
2302 musb_context
.index_regs
[i
].rxfifosz
=
2303 musb_read_rxfifosz(musb_base
);
2305 if (is_host_enabled(musb
)) {
2306 musb_context
.index_regs
[i
].txtype
=
2307 musb_readb(epio
, MUSB_TXTYPE
);
2308 musb_context
.index_regs
[i
].txinterval
=
2309 musb_readb(epio
, MUSB_TXINTERVAL
);
2310 musb_context
.index_regs
[i
].rxtype
=
2311 musb_readb(epio
, MUSB_RXTYPE
);
2312 musb_context
.index_regs
[i
].rxinterval
=
2313 musb_readb(epio
, MUSB_RXINTERVAL
);
2315 musb_context
.index_regs
[i
].txfunaddr
=
2316 musb_read_txfunaddr(musb_base
, i
);
2317 musb_context
.index_regs
[i
].txhubaddr
=
2318 musb_read_txhubaddr(musb_base
, i
);
2319 musb_context
.index_regs
[i
].txhubport
=
2320 musb_read_txhubport(musb_base
, i
);
2322 musb_context
.index_regs
[i
].rxfunaddr
=
2323 musb_read_rxfunaddr(musb_base
, i
);
2324 musb_context
.index_regs
[i
].rxhubaddr
=
2325 musb_read_rxhubaddr(musb_base
, i
);
2326 musb_context
.index_regs
[i
].rxhubport
=
2327 musb_read_rxhubport(musb_base
, i
);
2331 musb_platform_save_context(musb
, &musb_context
);
2334 void musb_restore_context(struct musb
*musb
)
2337 void __iomem
*musb_base
= musb
->mregs
;
2338 void __iomem
*ep_target_regs
;
2341 musb_platform_restore_context(musb
, &musb_context
);
2343 if (is_host_enabled(musb
)) {
2344 musb_writew(musb_base
, MUSB_FRAME
, musb_context
.frame
);
2345 musb_writeb(musb_base
, MUSB_TESTMODE
, musb_context
.testmode
);
2346 musb_write_ulpi_buscontrol(musb
->mregs
, musb_context
.busctl
);
2348 musb_writeb(musb_base
, MUSB_POWER
, musb_context
.power
);
2349 musb_writew(musb_base
, MUSB_INTRTXE
, musb_context
.intrtxe
);
2350 musb_writew(musb_base
, MUSB_INTRRXE
, musb_context
.intrrxe
);
2351 musb_writeb(musb_base
, MUSB_INTRUSBE
, musb_context
.intrusbe
);
2352 musb_writeb(musb_base
, MUSB_DEVCTL
, musb_context
.devctl
);
2354 for (i
= 0; i
< musb
->config
->num_eps
; ++i
) {
2355 epio
= musb
->endpoints
[i
].regs
;
2356 musb_writew(epio
, MUSB_TXMAXP
,
2357 musb_context
.index_regs
[i
].txmaxp
);
2358 musb_writew(epio
, MUSB_TXCSR
,
2359 musb_context
.index_regs
[i
].txcsr
);
2360 musb_writew(epio
, MUSB_RXMAXP
,
2361 musb_context
.index_regs
[i
].rxmaxp
);
2362 musb_writew(epio
, MUSB_RXCSR
,
2363 musb_context
.index_regs
[i
].rxcsr
);
2365 if (musb
->dyn_fifo
) {
2366 musb_write_txfifosz(musb_base
,
2367 musb_context
.index_regs
[i
].txfifosz
);
2368 musb_write_rxfifosz(musb_base
,
2369 musb_context
.index_regs
[i
].rxfifosz
);
2370 musb_write_txfifoadd(musb_base
,
2371 musb_context
.index_regs
[i
].txfifoadd
);
2372 musb_write_rxfifoadd(musb_base
,
2373 musb_context
.index_regs
[i
].rxfifoadd
);
2376 if (is_host_enabled(musb
)) {
2377 musb_writeb(epio
, MUSB_TXTYPE
,
2378 musb_context
.index_regs
[i
].txtype
);
2379 musb_writeb(epio
, MUSB_TXINTERVAL
,
2380 musb_context
.index_regs
[i
].txinterval
);
2381 musb_writeb(epio
, MUSB_RXTYPE
,
2382 musb_context
.index_regs
[i
].rxtype
);
2383 musb_writeb(epio
, MUSB_RXINTERVAL
,
2385 musb_context
.index_regs
[i
].rxinterval
);
2386 musb_write_txfunaddr(musb_base
, i
,
2387 musb_context
.index_regs
[i
].txfunaddr
);
2388 musb_write_txhubaddr(musb_base
, i
,
2389 musb_context
.index_regs
[i
].txhubaddr
);
2390 musb_write_txhubport(musb_base
, i
,
2391 musb_context
.index_regs
[i
].txhubport
);
2394 musb_read_target_reg_base(i
, musb_base
);
2396 musb_write_rxfunaddr(ep_target_regs
,
2397 musb_context
.index_regs
[i
].rxfunaddr
);
2398 musb_write_rxhubaddr(ep_target_regs
,
2399 musb_context
.index_regs
[i
].rxhubaddr
);
2400 musb_write_rxhubport(ep_target_regs
,
2401 musb_context
.index_regs
[i
].rxhubport
);
2406 static int musb_suspend(struct device
*dev
)
2408 struct platform_device
*pdev
= to_platform_device(dev
);
2409 unsigned long flags
;
2410 struct musb
*musb
= dev_to_musb(&pdev
->dev
);
2415 spin_lock_irqsave(&musb
->lock
, flags
);
2417 if (is_peripheral_active(musb
)) {
2418 /* FIXME force disconnect unless we know USB will wake
2419 * the system up quickly enough to respond ...
2421 } else if (is_host_active(musb
)) {
2422 /* we know all the children are suspended; sometimes
2423 * they will even be wakeup-enabled.
2427 musb_save_context(musb
);
2429 if (musb
->set_clock
)
2430 musb
->set_clock(musb
->clock
, 0);
2432 clk_disable(musb
->clock
);
2433 spin_unlock_irqrestore(&musb
->lock
, flags
);
2437 static int musb_resume_noirq(struct device
*dev
)
2439 struct platform_device
*pdev
= to_platform_device(dev
);
2440 struct musb
*musb
= dev_to_musb(&pdev
->dev
);
2445 if (musb
->set_clock
)
2446 musb
->set_clock(musb
->clock
, 1);
2448 clk_enable(musb
->clock
);
2450 musb_restore_context(musb
);
2452 /* for static cmos like DaVinci, register values were preserved
2453 * unless for some reason the whole soc powered down or the USB
2454 * module got reset through the PSC (vs just being disabled).
2459 static const struct dev_pm_ops musb_dev_pm_ops
= {
2460 .suspend
= musb_suspend
,
2461 .resume_noirq
= musb_resume_noirq
,
2464 #define MUSB_DEV_PM_OPS (&musb_dev_pm_ops)
2466 #define MUSB_DEV_PM_OPS NULL
2469 static struct platform_driver musb_driver
= {
2471 .name
= (char *)musb_driver_name
,
2472 .bus
= &platform_bus_type
,
2473 .owner
= THIS_MODULE
,
2474 .pm
= MUSB_DEV_PM_OPS
,
2476 .remove
= __exit_p(musb_remove
),
2477 .shutdown
= musb_shutdown
,
2480 /*-------------------------------------------------------------------------*/
2482 static int __init
musb_init(void)
2484 #ifdef CONFIG_USB_MUSB_HDRC_HCD
2489 pr_info("%s: version " MUSB_VERSION
", "
2490 #ifdef CONFIG_MUSB_PIO_ONLY
2492 #elif defined(CONFIG_USB_TI_CPPI_DMA)
2494 #elif defined(CONFIG_USB_INVENTRA_DMA)
2496 #elif defined(CONFIG_USB_TUSB_OMAP_DMA)
2502 #ifdef CONFIG_USB_MUSB_OTG
2503 "otg (peripheral+host)"
2504 #elif defined(CONFIG_USB_GADGET_MUSB_HDRC)
2506 #elif defined(CONFIG_USB_MUSB_HDRC_HCD)
2510 musb_driver_name
, musb_debug
);
2511 return platform_driver_probe(&musb_driver
, musb_probe
);
2514 /* make us init after usbcore and i2c (transceivers, regulators, etc)
2515 * and before usb gadget and host-side drivers start to register
2517 fs_initcall(musb_init
);
2519 static void __exit
musb_cleanup(void)
2521 platform_driver_unregister(&musb_driver
);
2523 module_exit(musb_cleanup
);