usb: musb: use is_host_active() to distinguish between host and gadget mode
On AM33xx platforms, unplugging a device in the middle of an active transfer leads to a drop of MUSB_DEVCTL_HM in MUSB_DEVCTL before the system is informed about a disconnect. This consequently makes the musb core call the gadget code to handle the interrupt request, which then crashes the kernel because the relevant pointers haven't been set up for gadget mode. To fix this, use is_host_active() rather than (devctl & MUSB_DEVCTL_HM) in musb_interrupt() and musb_dma_completion() to detect whether the controller is in host or peripheral mode. This information is provided by the driver logic and does not rely on register contents. Signed-off-by: Daniel Mack <zonque@gmail.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
This commit is contained in:
parent
9c547699cc
commit
c03da38d5d
|
@ -1517,7 +1517,7 @@ irqreturn_t musb_interrupt(struct musb *musb)
|
||||||
devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
|
devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
|
||||||
|
|
||||||
dev_dbg(musb->controller, "** IRQ %s usb%04x tx%04x rx%04x\n",
|
dev_dbg(musb->controller, "** IRQ %s usb%04x tx%04x rx%04x\n",
|
||||||
(devctl & MUSB_DEVCTL_HM) ? "host" : "peripheral",
|
is_host_active(musb) ? "host" : "peripheral",
|
||||||
musb->int_usb, musb->int_tx, musb->int_rx);
|
musb->int_usb, musb->int_tx, musb->int_rx);
|
||||||
|
|
||||||
/* the core can interrupt us for multiple reasons; docs have
|
/* the core can interrupt us for multiple reasons; docs have
|
||||||
|
@ -1531,7 +1531,7 @@ irqreturn_t musb_interrupt(struct musb *musb)
|
||||||
|
|
||||||
/* handle endpoint 0 first */
|
/* handle endpoint 0 first */
|
||||||
if (musb->int_tx & 1) {
|
if (musb->int_tx & 1) {
|
||||||
if (devctl & MUSB_DEVCTL_HM)
|
if (is_host_active(musb))
|
||||||
retval |= musb_h_ep0_irq(musb);
|
retval |= musb_h_ep0_irq(musb);
|
||||||
else
|
else
|
||||||
retval |= musb_g_ep0_irq(musb);
|
retval |= musb_g_ep0_irq(musb);
|
||||||
|
@ -1545,7 +1545,7 @@ irqreturn_t musb_interrupt(struct musb *musb)
|
||||||
/* musb_ep_select(musb->mregs, ep_num); */
|
/* musb_ep_select(musb->mregs, ep_num); */
|
||||||
/* REVISIT just retval = ep->rx_irq(...) */
|
/* REVISIT just retval = ep->rx_irq(...) */
|
||||||
retval = IRQ_HANDLED;
|
retval = IRQ_HANDLED;
|
||||||
if (devctl & MUSB_DEVCTL_HM)
|
if (is_host_active(musb))
|
||||||
musb_host_rx(musb, ep_num);
|
musb_host_rx(musb, ep_num);
|
||||||
else
|
else
|
||||||
musb_g_rx(musb, ep_num);
|
musb_g_rx(musb, ep_num);
|
||||||
|
@ -1563,7 +1563,7 @@ irqreturn_t musb_interrupt(struct musb *musb)
|
||||||
/* musb_ep_select(musb->mregs, ep_num); */
|
/* musb_ep_select(musb->mregs, ep_num); */
|
||||||
/* REVISIT just retval |= ep->tx_irq(...) */
|
/* REVISIT just retval |= ep->tx_irq(...) */
|
||||||
retval = IRQ_HANDLED;
|
retval = IRQ_HANDLED;
|
||||||
if (devctl & MUSB_DEVCTL_HM)
|
if (is_host_active(musb))
|
||||||
musb_host_tx(musb, ep_num);
|
musb_host_tx(musb, ep_num);
|
||||||
else
|
else
|
||||||
musb_g_tx(musb, ep_num);
|
musb_g_tx(musb, ep_num);
|
||||||
|
@ -1585,15 +1585,13 @@ MODULE_PARM_DESC(use_dma, "enable/disable use of DMA");
|
||||||
|
|
||||||
void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit)
|
void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit)
|
||||||
{
|
{
|
||||||
u8 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
|
|
||||||
|
|
||||||
/* called with controller lock already held */
|
/* called with controller lock already held */
|
||||||
|
|
||||||
if (!epnum) {
|
if (!epnum) {
|
||||||
#ifndef CONFIG_USB_TUSB_OMAP_DMA
|
#ifndef CONFIG_USB_TUSB_OMAP_DMA
|
||||||
if (!is_cppi_enabled()) {
|
if (!is_cppi_enabled()) {
|
||||||
/* endpoint 0 */
|
/* endpoint 0 */
|
||||||
if (devctl & MUSB_DEVCTL_HM)
|
if (is_host_active(musb))
|
||||||
musb_h_ep0_irq(musb);
|
musb_h_ep0_irq(musb);
|
||||||
else
|
else
|
||||||
musb_g_ep0_irq(musb);
|
musb_g_ep0_irq(musb);
|
||||||
|
@ -1602,13 +1600,13 @@ void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit)
|
||||||
} else {
|
} else {
|
||||||
/* endpoints 1..15 */
|
/* endpoints 1..15 */
|
||||||
if (transmit) {
|
if (transmit) {
|
||||||
if (devctl & MUSB_DEVCTL_HM)
|
if (is_host_active(musb))
|
||||||
musb_host_tx(musb, epnum);
|
musb_host_tx(musb, epnum);
|
||||||
else
|
else
|
||||||
musb_g_tx(musb, epnum);
|
musb_g_tx(musb, epnum);
|
||||||
} else {
|
} else {
|
||||||
/* receive */
|
/* receive */
|
||||||
if (devctl & MUSB_DEVCTL_HM)
|
if (is_host_active(musb))
|
||||||
musb_host_rx(musb, epnum);
|
musb_host_rx(musb, epnum);
|
||||||
else
|
else
|
||||||
musb_g_rx(musb, epnum);
|
musb_g_rx(musb, epnum);
|
||||||
|
|
Loading…
Reference in New Issue