JZ4740 USB Device Controller is not OTG compatible and does not have DEVCTL
register in silicon.

During ethernet-over-usb transactions, on reset, musb driver tries to
read from DEVCTL and consequently sets device as host (A-Device)
instead of peripheral (B-Device), which makes it a composite device to
the USB gadget driver.
This induces a kernel panic during power down where the USB gadget
driver does a null pointer dereference when trying to access the
composite device configuration.

On reset, do not rely on DEVCTL value for setting gadget peripheral
mode: hardcode it instead to B-Device.

Signed-off-by: Apelete Seketeli <[email protected]>
---
 drivers/usb/musb/musb_gadget.c |    9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 32fb057..b4bea7a 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -2119,6 +2119,14 @@ __acquires(musb->lock)
        /* Normal reset, as B-Device;
         * or else after HNP, as A-Device
         */
+#if defined(CONFIG_USB_MUSB_JZ4740) || defined(CONFIG_USB_MUSB_JZ4740_MODULE)
+       /* JZ4740 UDC Controller is not OTG compatible and does not
+        * have DEVCTL register in silicon: do not rely on devctl for
+        * setting peripheral mode.
+        */
+       musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
+       musb->g.is_a_peripheral = 0;
+#else
        if (devctl & MUSB_DEVCTL_BDEVICE) {
                musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
                musb->g.is_a_peripheral = 0;
@@ -2126,6 +2134,7 @@ __acquires(musb->lock)
                musb->xceiv->state = OTG_STATE_A_PERIPHERAL;
                musb->g.is_a_peripheral = 1;
        }
+#endif
 
        /* start with default limits on VBUS power draw */
        (void) musb_gadget_vbus_draw(&musb->g, 8);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to