Skip to content

Commit a368a29

Browse files
Sebastian Andrzej Siewiorgregkh
authored andcommitted
usb: musb: start musb on the udc side, too
commit 001dd84 upstream. I have am335x-evm with one port running in OTG mode. Since commit fe4cb09 ("usb: musb: gadget: remove hcd initialization") the loaded gadget does non pop up on the host. All I see is |usb 4-5: new high-speed USB device number 52 using ehci-pci |usb 4-5: device descriptor read/64, error -110 Since a later commit 2cc65fe ("usb: musb: add musb_host_setup() and musb_host_cleanup()) the gadget shows up on the host again but only in OTG mode (because we have the host init code running). It does not work in device only mode. If running in OTG mode and the gadget is removed and added back (rmmod followed by modprobe of a gadget) then the same error is pops up on the host side. This patch ensures that the gadget side also executes musb_start() which puts the chip in "connect accept" mode. With this change the device works in OTG & device mode and the gadget can be added & removed multiple times. A device (if musb is in OTG mode acting as a host) is only recognized if it is attached during module load (musb_hdrc module). After the device unplugged and plugged again the host does not recognize it. We get a buch of errors if musb running in OTG mode, attached to a host and no gadget is loaded. Bah. This is one step forward. Host & device only mode should work. I will look at OTG later. I looked at this before commit fe4cb09 and OTG wasn't working there perfectly so I am not sure that it is a regression :) Cc: Daniel Mack <zonque@gmail.com> Cc: Peter Korsgaard <jacmet@sunsite.dk> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 39773be commit a368a29

4 files changed

Lines changed: 49 additions & 46 deletions

File tree

‎drivers/usb/musb/musb_core.c‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,52 @@ static void musb_generic_disable(struct musb *musb)
922922

923923
}
924924

925+
/*
926+
* Program the HDRC to start (enable interrupts, dma, etc.).
927+
*/
928+
void musb_start(struct musb *musb)
929+
{
930+
void __iomem *regs = musb->mregs;
931+
u8 devctl = musb_readb(regs, MUSB_DEVCTL);
932+
933+
dev_dbg(musb->controller, "<== devctl %02x\n", devctl);
934+
935+
/* Set INT enable registers, enable interrupts */
936+
musb->intrtxe = musb->epmask;
937+
musb_writew(regs, MUSB_INTRTXE, musb->intrtxe);
938+
musb->intrrxe = musb->epmask & 0xfffe;
939+
musb_writew(regs, MUSB_INTRRXE, musb->intrrxe);
940+
musb_writeb(regs, MUSB_INTRUSBE, 0xf7);
941+
942+
musb_writeb(regs, MUSB_TESTMODE, 0);
943+
944+
/* put into basic highspeed mode and start session */
945+
musb_writeb(regs, MUSB_POWER, MUSB_POWER_ISOUPDATE
946+
| MUSB_POWER_HSENAB
947+
/* ENSUSPEND wedges tusb */
948+
/* | MUSB_POWER_ENSUSPEND */
949+
);
950+
951+
musb->is_active = 0;
952+
devctl = musb_readb(regs, MUSB_DEVCTL);
953+
devctl &= ~MUSB_DEVCTL_SESSION;
954+
955+
/* session started after:
956+
* (a) ID-grounded irq, host mode;
957+
* (b) vbus present/connect IRQ, peripheral mode;
958+
* (c) peripheral initiates, using SRP
959+
*/
960+
if (musb->port_mode != MUSB_PORT_MODE_HOST &&
961+
(devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) {
962+
musb->is_active = 1;
963+
} else {
964+
devctl |= MUSB_DEVCTL_SESSION;
965+
}
966+
967+
musb_platform_enable(musb);
968+
musb_writeb(regs, MUSB_DEVCTL, devctl);
969+
}
970+
925971
/*
926972
* Make the HDRC stop (disable interrupts, etc.);
927973
* reversible by musb_start

‎drivers/usb/musb/musb_core.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ static inline void musb_configure_ep0(struct musb *musb)
511511
extern const char musb_driver_name[];
512512

513513
extern void musb_stop(struct musb *musb);
514+
extern void musb_start(struct musb *musb);
514515

515516
extern void musb_write_fifo(struct musb_hw_ep *ep, u16 len, const u8 *src);
516517
extern void musb_read_fifo(struct musb_hw_ep *ep, u16 len, u8 *dst);

‎drivers/usb/musb/musb_gadget.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,6 +1842,8 @@ static int musb_gadget_start(struct usb_gadget *g,
18421842
musb->xceiv->state = OTG_STATE_B_IDLE;
18431843
spin_unlock_irqrestore(&musb->lock, flags);
18441844

1845+
musb_start(musb);
1846+
18451847
/* REVISIT: funcall to other code, which also
18461848
* handles power budgeting ... this way also
18471849
* ensures HdrcStart is indirectly called.

‎drivers/usb/musb/musb_virthub.c‎

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -44,52 +44,6 @@
4444

4545
#include "musb_core.h"
4646

47-
/*
48-
* Program the HDRC to start (enable interrupts, dma, etc.).
49-
*/
50-
static void musb_start(struct musb *musb)
51-
{
52-
void __iomem *regs = musb->mregs;
53-
u8 devctl = musb_readb(regs, MUSB_DEVCTL);
54-
55-
dev_dbg(musb->controller, "<== devctl %02x\n", devctl);
56-
57-
/* Set INT enable registers, enable interrupts */
58-
musb->intrtxe = musb->epmask;
59-
musb_writew(regs, MUSB_INTRTXE, musb->intrtxe);
60-
musb->intrrxe = musb->epmask & 0xfffe;
61-
musb_writew(regs, MUSB_INTRRXE, musb->intrrxe);
62-
musb_writeb(regs, MUSB_INTRUSBE, 0xf7);
63-
64-
musb_writeb(regs, MUSB_TESTMODE, 0);
65-
66-
/* put into basic highspeed mode and start session */
67-
musb_writeb(regs, MUSB_POWER, MUSB_POWER_ISOUPDATE
68-
| MUSB_POWER_HSENAB
69-
/* ENSUSPEND wedges tusb */
70-
/* | MUSB_POWER_ENSUSPEND */
71-
);
72-
73-
musb->is_active = 0;
74-
devctl = musb_readb(regs, MUSB_DEVCTL);
75-
devctl &= ~MUSB_DEVCTL_SESSION;
76-
77-
/* session started after:
78-
* (a) ID-grounded irq, host mode;
79-
* (b) vbus present/connect IRQ, peripheral mode;
80-
* (c) peripheral initiates, using SRP
81-
*/
82-
if (musb->port_mode != MUSB_PORT_MODE_HOST &&
83-
(devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) {
84-
musb->is_active = 1;
85-
} else {
86-
devctl |= MUSB_DEVCTL_SESSION;
87-
}
88-
89-
musb_platform_enable(musb);
90-
musb_writeb(regs, MUSB_DEVCTL, devctl);
91-
}
92-
9347
static void musb_port_suspend(struct musb *musb, bool do_suspend)
9448
{
9549
struct usb_otg *otg = musb->xceiv->otg;

0 commit comments

Comments
 (0)