+#include <linux/usb/ulpi.h>
+
+static void musb_vbus_workaround_work(struct work_struct *work)
+{
+ struct musb *musb = container_of(work, struct musb, vbus_workaround_work.work);
+ u8 devctl;
+ int ret;
+
+ if (musb_ulpi_access.write == NULL)
+ return;
+
+ pm_runtime_get_sync(musb->controller);
+
+ devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
+
+ /*
+ * I don't really know why but VBUS sometimes gets stuck and
+ * causes session to never end. It would look like some pullup
+ * is enabled when it shouldn't be on certain PHY states.
+ * Turning on pulldowns magically drains VBUS to zero and allows
+ * session to end, so let's do that here.
+ *
+ * XXX: probably better check VBUS on TWL?
+ * beagle sometimes has session bit set but no VBUS on twl?
+ */
+ if ((musb->xceiv->state == OTG_STATE_B_PERIPHERAL ||
+ musb->xceiv->state == OTG_STATE_B_IDLE) &&
+ (devctl & MUSB_DEVCTL_VBUS) != (3 << MUSB_DEVCTL_VBUS_SHIFT) &&
+ (devctl & MUSB_DEVCTL_VBUS) != (0 << MUSB_DEVCTL_VBUS_SHIFT)) {
+ dev_dbg(musb->controller, "VBUS workaround..\n");
+ ret = musb_ulpi_access.write(musb->xceiv, ULPI_SET(ULPI_OTG_CTRL),
+ ULPI_OTG_CTRL_DM_PULLDOWN | ULPI_OTG_CTRL_DP_PULLDOWN);
+ //if (ret)
+ // dev_err(musb->controller, "VBUS workaround error\n");
+ }
+
+ pm_runtime_put(musb->controller);
+}
+