Skip to content

Commit 001dd84

Browse files
Sebastian Andrzej SiewiorFelipe Balbi
authored andcommitted
usb: musb: start musb on the udc side, too
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: <stable@vger.kernel.org> # v3.11 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>
1 parent b377216 commit 001dd84

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
@@ -921,6 +921,52 @@ static void musb_generic_disable(struct musb *musb)
921921

922922
}
923923

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

‎drivers/usb/musb/musb_core.h‎

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

505505
extern void musb_stop(struct musb *musb);
506+
extern void musb_start(struct musb *musb);
506507

507508
extern void musb_write_fifo(struct musb_hw_ep *ep, u16 len, const u8 *src);
508509
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
@@ -1858,6 +1858,8 @@ static int musb_gadget_start(struct usb_gadget *g,
18581858
musb->xceiv->state = OTG_STATE_B_IDLE;
18591859
spin_unlock_irqrestore(&musb->lock, flags);
18601860

1861+
musb_start(musb);
1862+
18611863
/* REVISIT: funcall to other code, which also
18621864
* handles power budgeting ... this way also
18631865
* 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)