From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Holger Assmann <h.assmann@pengutronix.de>,
	Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] phy: freescale: imx8mq-usb: add support for 8MP/8MQ vbus-supply
Date: Mon,  3 Nov 2025 16:19:32 +0100	[thread overview]
Message-ID: <20251103151935.2368094-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20251103151935.2368094-1-a.fatoum@pengutronix.de>
The PHY device tree node may reference a regulator via vbus-supply that
needs to be switched by software.
Linux already supported this binding, so implement it for barebox as well.
Unlike the Linux driver, we do not treat a missing regulator as hard
error for backwards compatibility reasons. Instead, we just print a
warning and move along:
- If we have a driver, then on deep probe systems, this should always
  succeed anyway.
- If we do not have a driver and are on deep probe system, the VBUS is
  powered on already, then the warning can be suppressed by
  barebox,allow-dummy-supply in the provider node.
- If the user is not on a deep probe system, they should either patch
  out vbus-supply or enable deep probe.
Reported-by: Holger Assmann <h.assmann@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/phy/freescale/phy-fsl-imx8mq-usb.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
diff --git a/drivers/phy/freescale/phy-fsl-imx8mq-usb.c b/drivers/phy/freescale/phy-fsl-imx8mq-usb.c
index 1349ca922c70..414d21241496 100644
--- a/drivers/phy/freescale/phy-fsl-imx8mq-usb.c
+++ b/drivers/phy/freescale/phy-fsl-imx8mq-usb.c
@@ -5,6 +5,7 @@
 #include <driver.h>
 #include <errno.h>
 #include <init.h>
+#include <regulator.h>
 #include <io.h>
 #include <linux/bitfield.h>
 #include <linux/clk.h>
@@ -40,6 +41,7 @@ struct imx8mq_usb_phy {
 	struct phy *phy;
 	struct clk *clk;
 	void __iomem *base;
+	struct regulator *vbus;
 };
 
 static int imx8mq_usb_phy_init(struct phy *phy)
@@ -109,6 +111,11 @@ static int imx8mp_usb_phy_init(struct phy *phy)
 static int imx8mq_phy_power_on(struct phy *phy)
 {
 	struct imx8mq_usb_phy *imx_phy = phy_get_drvdata(phy);
+	int ret;
+
+	ret = regulator_enable(imx_phy->vbus);
+	if (ret)
+		return ret;
 
 	return clk_enable(imx_phy->clk);
 }
@@ -118,6 +125,7 @@ static int imx8mq_phy_power_off(struct phy *phy)
 	struct imx8mq_usb_phy *imx_phy = phy_get_drvdata(phy);
 
 	clk_disable(imx_phy->clk);
+	regulator_disable(imx_phy->vbus);
 
 	return 0;
 }
@@ -177,6 +185,12 @@ static int imx8mq_usb_phy_probe(struct device *dev)
 	if (IS_ERR(imx_phy->phy))
 		return PTR_ERR(imx_phy->phy);
 
+	imx_phy->vbus = regulator_get(dev, "vbus");
+	if (IS_ERR(imx_phy->vbus)) {
+		imx_phy->vbus = NULL;
+		dev_warn(dev, "Failed to get 'vbus' regulator (ignored).\n");
+	}
+
 	phy_set_drvdata(imx_phy->phy, imx_phy);
 
 	phy_provider = of_phy_provider_register(dev, imx8mq_usb_phy_xlate);
-- 
2.47.3
next prev parent reply	other threads:[~2025-11-03 15:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-03 15:19 [PATCH 1/2] usb: dwc3: port Linux i.MX8MP glue driver Ahmad Fatoum
2025-11-03 15:19 ` Ahmad Fatoum [this message]
2025-11-03 18:31 ` Thorsten Scherer
2025-11-04  8:33 ` Sascha Hauer
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=20251103151935.2368094-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=h.assmann@pengutronix.de \
    /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