[PATCH v2 1/2] usb: musb: dsps: implement vbus_status and set_vbus platform ops
From: Lucas Martins Alves
Date: Thu Jul 16 2026 - 11:11:21 EST
From: Lucas Martins Alves <lucas.alves@xxxxxxxxxxxxxxx>
The DSPS glue layer (used on TI AM335x SoCs) was missing implementations
for the vbus_status and set_vbus platform ops defined in struct
musb_platform_ops.
Add dsps_musb_vbus_status() to report VBUS presence by reading the VBUS
field of MUSB_DEVCTL, and dsps_musb_set_vbus() to drive the SESSION bit
on MUSB_DEVCTL, enabling or disabling the USB session. When disabling,
musb_root_disconnect() is called to properly tear down any active host
connection before clearing the session bit.
Register both callbacks in dsps_ops to allow the MUSB core to control
VBUS on AM335x-based platforms. This enables the USB core to perform a
VBUS power cycle as a recovery mechanism when a USB error condition is
detected, and also allows userspace to control VBUS state via the
standard USB sysfs interface.
Signed-off-by: Lucas Martins Alves <lucas.alves@xxxxxxxxxxxxxxx>
---
drivers/usb/musb/musb_dsps.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index e3935f18dd56..8e3ef32f615e 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -618,6 +618,34 @@ static int dsps_musb_recover(struct musb *musb)
return session_restart ? 0 : -EPIPE;
}
+static int dsps_musb_vbus_status(struct musb *musb)
+{
+ u8 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
+
+ return (devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS;
+}
+
+static void dsps_musb_set_vbus(struct musb *musb, int is_on)
+{
+ u8 devctl;
+
+ devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
+
+ if (is_on) {
+ musb->context.devctl |= MUSB_DEVCTL_SESSION;
+ } else {
+ /* Since we drop the session to turn off vbus, the connection cannot survive */
+ if( musb->port1_status & USB_PORT_STAT_CONNECTION )
+ musb->port1_status |= (USB_PORT_STAT_C_CONNECTION << 16);
+ musb->port1_status &= ~( USB_PORT_STAT_CONNECTION |
+ USB_PORT_STAT_HIGH_SPEED |
+ USB_PORT_STAT_LOW_SPEED );
+ devctl &= ~MUSB_DEVCTL_SESSION;
+ }
+
+ musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
+}
+
/* Similar to am35x, dm81xx support only 32-bit read operation */
static void dsps_read_fifo32(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
{
@@ -702,6 +730,8 @@ static struct musb_platform_ops dsps_ops = {
.set_mode = dsps_musb_set_mode,
.recover = dsps_musb_recover,
+ .vbus_status = dsps_musb_vbus_status,
+ .set_vbus = dsps_musb_set_vbus,
.clear_ep_rxintr = dsps_musb_clear_ep_rxintr,
};
--
2.53.0