mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lucas Martins Alves <lucas.alves@lumal21.com.br>
To: "b-liu@ti.com" <b-liu@ti.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Lucas Martins Alves <lucas.alves@lumal21.com.br>,
	Bin Liu <b-liu@ti.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Lucas Martins Alves <lucas.alves@lumal21.com.br>
Subject: [PATCH v6] usb: musb: dsps: implement vbus_status and set_vbus platform ops
Date: Fri, 17 Jul 2026 19:44:53 +0000	[thread overview]
Message-ID: <20260717194449.317520-1-lucas.alves@lumal21.com.br> (raw)

From: Lucas Martins Alves <lucas.alves@lumal21.com.br>

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.

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@lumal21.com.br>
---
v1 -> v2:
- Remove the unintended musb context changes introduced in the first patch.
v2 -> v3:
- Corrects the text in the patch description.
v3 -> v4:
- Remove improperly attached patch file.
v4 -> v5:
- Re-send patch v4 in a new thread.
v5 -> v6:
- Corrects the history of the patch that was removed in v5.
---
 drivers/usb/musb/musb_dsps.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index e3935f18dd56..efd1f0dbb926 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -618,6 +618,29 @@ 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) {
+		devctl |= MUSB_DEVCTL_SESSION;
+	} else {
+		musb_root_disconnect(musb);
+		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 +725,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


                 reply	other threads:[~2026-07-17 19:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260717194449.317520-1-lucas.alves@lumal21.com.br \
    --to=lucas.alves@lumal21.com.br \
    --cc=b-liu@ti.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox