From: Philippe Simons <simons.philippe@gmail.com>
To: Vinod Koul <vkoul@kernel.org>,
Kishon Vijay Abraham I <kishon@kernel.org>,
Chen-Yu Tsai <wens@csie.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>,
Philippe Simons <simons.philippe@gmail.com>,
linux-phy@lists.infradead.org (open list:GENERIC PHY FRAMEWORK),
linux-arm-kernel@lists.infradead.org (moderated
list:ARM/Allwinner sunXi SoC support),
linux-sunxi@lists.linux.dev (open list:ARM/Allwinner sunXi SoC
support), linux-kernel@vger.kernel.org (open list)
Subject: [RFC PATCH 1/3] phy: don't let controllers change vbus reg
Date: Sat, 18 Jan 2025 11:22:04 +0100 [thread overview]
Message-ID: <20250118102207.9339-1-simons.philippe@gmail.com> (raw)
Allwinners SoCs share phy0 between the MUSB controller and HCI controller.
If we let these controllers independently power on the vbus on that phy,
peripheral mode is dangerous because HCI never power down the phy, resulting
in 5v being applied against the host 5v.
Override power_on/off for phy0 in that case, and let regulator be enabled/disabled
based on id_det only.
Signed-off-by: Philippe Simons <simons.philippe@gmail.com>
---
drivers/phy/allwinner/phy-sun4i-usb.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c
index b0f19e950..24fbabe7a 100644
--- a/drivers/phy/allwinner/phy-sun4i-usb.c
+++ b/drivers/phy/allwinner/phy-sun4i-usb.c
@@ -465,6 +465,10 @@ static int sun4i_usb_phy_power_on(struct phy *_phy)
struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
int ret;
+ /* phy0 power is controlled by sun4i_usb_phy0_reroute and id_det state */
+ if (phy->index == 0 && data->cfg->phy0_dual_route)
+ return 0;
+
if (!phy->vbus || phy->regulator_on)
return 0;
@@ -493,6 +497,10 @@ static int sun4i_usb_phy_power_off(struct phy *_phy)
struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
+ /* phy0 power is controlled by sun4i_usb_phy0_reroute and id_det state */
+ if (phy->index == 0 && data->cfg->phy0_dual_route)
+ return 0;
+
if (!phy->vbus || !phy->regulator_on)
return 0;
@@ -573,9 +581,21 @@ static void sun4i_usb_phy0_reroute(struct sun4i_usb_phy_data *data, int id_det)
if (id_det == 0) {
/* Host mode. Route phy0 to EHCI/OHCI */
regval &= ~OTGCTL_ROUTE_MUSB;
+
+ /* Enable VBUS reg */
+ if (phy->vbus && !phy->regulator_on) {
+ regulator_enable(phy->vbus);
+ phy->regulator_on = true;
+ }
} else {
/* Peripheral mode. Route phy0 to MUSB */
regval |= OTGCTL_ROUTE_MUSB;
+
+ /* Disable VBUS reg */
+ if (phy->vbus && phy->regulator_on) {
+ regulator_disable(phy->vbus);
+ phy->regulator_on = false;
+ }
}
writel(regval, data->base + REG_PHY_OTGCTL);
}
@@ -603,6 +623,12 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
return;
}
+ /* Disable internal VBUS reg if there is an external VBUS */
+ if (vbus_det != 0 && phy->vbus && phy->regulator_on) {
+ regulator_disable(phy->vbus);
+ phy->regulator_on = false;
+ }
+
force_session_end = data->force_session_end;
data->force_session_end = false;
--
2.47.1
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
next reply other threads:[~2025-01-18 10:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-18 10:22 Philippe Simons [this message]
2025-01-18 10:22 ` [RFC PATCH 2/3] phy: override dr_mode for phy0 Philippe Simons
2025-02-20 20:33 ` Jernej Škrabec
2025-02-20 20:27 ` [RFC PATCH 1/3] phy: don't let controllers change vbus reg Jernej Škrabec
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=20250118102207.9339-1-simons.philippe@gmail.com \
--to=simons.philippe@gmail.com \
--cc=jernej.skrabec@gmail.com \
--cc=kishon@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=samuel@sholland.org \
--cc=vkoul@kernel.org \
--cc=wens@csie.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;
as well as URLs for NNTP newsgroup(s).