From: Alastair D'Silva <alastair@d-silva.org>
To: Vinod Koul <vkoul@kernel.org>,
Neil Armstrong <neil.armstrong@linaro.org>,
Manivannan Sadhasivam <mani@kernel.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Stephen Boyd <sboyd@kernel.org>, Chen-Yu Tsai <wens@kernel.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>
Cc: Maxime Ripard <mripard@kernel.org>,
Andre Przywara <andre.przywara@arm.com>,
Brian Masney <bmasney+clk@redhat.com>,
Jerome Brunet <jbrunet+clk@baylibre.com>,
Junhui Liu <junhui.liu@pigmoral.tech>,
linux-phy@lists.infradead.org, devicetree@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-sunxi@lists.linux.dev, linux-usb@vger.kernel.org,
linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
Alastair D'Silva <alastair@d-silva.org>
Subject: [PATCH 4/6] phy: allwinner: sun4i-usb: Add Allwinner A733 support
Date: Fri, 27 Nov 2026 21:08:06 +1100 [thread overview]
Message-ID: <20261127100808.2292229-5-alastair@d-silva.org> (raw)
In-Reply-To: <20261127100808.2292229-1-alastair@d-silva.org>
Add support for the Allwinner A733 (sun60i-a733) USB 2.0 PHY.
Enable the PHY register bus clock (bus) during PHY init, and keep PHY0 out
of reset and SIDDQ while any PHY is active.
Signed-off-by: Alastair D'Silva <alastair@d-silva.org>
---
drivers/phy/allwinner/phy-sun4i-usb.c | 119 +++++++++++++++++++-------
1 file changed, 88 insertions(+), 31 deletions(-)
diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c
index f26eed0db17e..e1f20d00d593 100644
--- a/drivers/phy/allwinner/phy-sun4i-usb.c
+++ b/drivers/phy/allwinner/phy-sun4i-usb.c
@@ -102,7 +102,9 @@ struct sun4i_usb_phy_cfg {
u32 hci_phy_ctl_clear;
u8 phyctl_offset;
bool dedicated_clocks;
+ bool has_bus_clk;
bool phy0_dual_route;
+ bool needs_phy0_siddq;
bool needs_phy2_siddq;
bool siddq_in_base;
bool poll_vbusen;
@@ -111,9 +113,11 @@ struct sun4i_usb_phy_cfg {
struct sun4i_usb_phy_data {
void __iomem *base;
+ struct clk *bus_clk;
const struct sun4i_usb_phy_cfg *cfg;
enum usb_dr_mode dr_mode;
spinlock_t reg_lock; /* guard access to phyctl reg */
+ unsigned int phy0_siddq_users;
int num_phys;
struct sun4i_usb_phy {
struct phy *phy;
@@ -257,24 +261,39 @@ static int sun4i_usb_phy_init(struct phy *_phy)
{
struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
+ unsigned long flags;
int ret;
u32 val;
- ret = clk_prepare_enable(phy->clk);
+ ret = clk_prepare_enable(data->bus_clk);
if (ret)
return ret;
+ ret = clk_prepare_enable(phy->clk);
+ if (ret)
+ goto err_disable_bus_clk;
+
ret = clk_prepare_enable(phy->clk2);
- if (ret) {
- clk_disable_unprepare(phy->clk);
- return ret;
- }
+ if (ret)
+ goto err_disable_clk;
ret = reset_control_deassert(phy->reset);
- if (ret) {
- clk_disable_unprepare(phy->clk2);
- clk_disable_unprepare(phy->clk);
- return ret;
+ if (ret)
+ goto err_disable_clk2;
+
+ /* Some PHYs on some SoCs need the help of PHY0 to work. */
+ if (data->cfg->needs_phy0_siddq && phy->index != 0) {
+ struct sun4i_usb_phy *phy0 = &data->phys[0];
+
+ ret = clk_prepare_enable(phy0->clk);
+ if (ret)
+ goto err_assert_reset;
+
+ ret = reset_control_deassert(phy0->reset);
+ if (ret) {
+ clk_disable_unprepare(phy0->clk);
+ goto err_assert_reset;
+ }
}
/* Some PHYs on some SoCs need the help of PHY2 to work. */
@@ -282,20 +301,13 @@ static int sun4i_usb_phy_init(struct phy *_phy)
struct sun4i_usb_phy *phy2 = &data->phys[2];
ret = clk_prepare_enable(phy2->clk);
- if (ret) {
- reset_control_assert(phy->reset);
- clk_disable_unprepare(phy->clk2);
- clk_disable_unprepare(phy->clk);
- return ret;
- }
+ if (ret)
+ goto err_assert_reset;
ret = reset_control_deassert(phy2->reset);
if (ret) {
clk_disable_unprepare(phy2->clk);
- reset_control_assert(phy->reset);
- clk_disable_unprepare(phy->clk2);
- clk_disable_unprepare(phy->clk);
- return ret;
+ goto err_assert_reset;
}
/*
@@ -306,10 +318,7 @@ static int sun4i_usb_phy_init(struct phy *_phy)
if (ret) {
reset_control_assert(phy2->reset);
clk_disable_unprepare(phy2->clk);
- reset_control_assert(phy->reset);
- clk_disable_unprepare(phy->clk2);
- clk_disable_unprepare(phy->clk);
- return ret;
+ goto err_assert_reset;
}
if (phy2->pmu && data->cfg->hci_phy_ctl_clear) {
@@ -328,11 +337,16 @@ static int sun4i_usb_phy_init(struct phy *_phy)
}
if (data->cfg->siddq_in_base) {
- if (phy->index == 0) {
+ if (phy->index == 0 || data->cfg->needs_phy0_siddq) {
+ spin_lock_irqsave(&data->reg_lock, flags);
val = readl(data->base + data->cfg->phyctl_offset);
- val |= PHY_CTL_VBUSVLDEXT;
+ if (phy->index == 0)
+ val |= PHY_CTL_VBUSVLDEXT;
val &= ~PHY_CTL_SIDDQ;
writel(val, data->base + data->cfg->phyctl_offset);
+ if (data->cfg->needs_phy0_siddq)
+ data->phy0_siddq_users++;
+ spin_unlock_irqrestore(&data->reg_lock, flags);
}
} else {
/* Enable USB 45 Ohm resistor calibration */
@@ -363,27 +377,48 @@ static int sun4i_usb_phy_init(struct phy *_phy)
}
return 0;
+
+err_assert_reset:
+ reset_control_assert(phy->reset);
+err_disable_clk2:
+ clk_disable_unprepare(phy->clk2);
+err_disable_clk:
+ clk_disable_unprepare(phy->clk);
+err_disable_bus_clk:
+ clk_disable_unprepare(data->bus_clk);
+ return ret;
}
static int sun4i_usb_phy_exit(struct phy *_phy)
{
struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
+ unsigned long flags;
- if (phy->index == 0) {
- if (data->cfg->siddq_in_base) {
- void __iomem *phyctl = data->base +
- data->cfg->phyctl_offset;
+ if (data->cfg->siddq_in_base &&
+ (phy->index == 0 || data->cfg->needs_phy0_siddq)) {
+ void __iomem *phyctl = data->base + data->cfg->phyctl_offset;
+ spin_lock_irqsave(&data->reg_lock, flags);
+ if (!data->cfg->needs_phy0_siddq || --data->phy0_siddq_users == 0)
writel(readl(phyctl) | PHY_CTL_SIDDQ, phyctl);
- }
+ spin_unlock_irqrestore(&data->reg_lock, flags);
+ }
+ if (phy->index == 0) {
/* Disable pull-ups */
sun4i_usb_phy0_update_iscr(_phy, ISCR_DPDM_PULLUP_EN, 0);
sun4i_usb_phy0_update_iscr(_phy, ISCR_ID_PULLUP_EN, 0);
data->phy0_init = false;
}
+ if (data->cfg->needs_phy0_siddq && phy->index != 0) {
+ struct sun4i_usb_phy *phy0 = &data->phys[0];
+
+ reset_control_assert(phy0->reset);
+ clk_disable_unprepare(phy0->clk);
+ }
+
if (data->cfg->needs_phy2_siddq && phy->index != 2) {
struct sun4i_usb_phy *phy2 = &data->phys[2];
@@ -395,6 +430,7 @@ static int sun4i_usb_phy_exit(struct phy *_phy)
reset_control_assert(phy->reset);
clk_disable_unprepare(phy->clk2);
clk_disable_unprepare(phy->clk);
+ clk_disable_unprepare(data->bus_clk);
return 0;
}
@@ -739,6 +775,13 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
if (IS_ERR(data->base))
return PTR_ERR(data->base);
+ if (data->cfg->has_bus_clk) {
+ data->bus_clk = devm_clk_get(dev, "bus");
+ if (IS_ERR(data->bus_clk))
+ return dev_err_probe(dev, PTR_ERR(data->bus_clk),
+ "failed to get bus clock\n");
+ }
+
data->id_det_gpio = devm_gpiod_get_optional(dev, "usb0_id_det",
GPIOD_IN);
if (IS_ERR(data->id_det_gpio)) {
@@ -787,7 +830,10 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
continue;
snprintf(name, sizeof(name), "usb%d_reset", i);
- phy->reset = devm_reset_control_get(dev, name);
+ if (i == 0 && data->cfg->needs_phy0_siddq)
+ phy->reset = devm_reset_control_get_shared(dev, name);
+ else
+ phy->reset = devm_reset_control_get(dev, name);
if (IS_ERR(phy->reset)) {
if (PTR_ERR(phy->reset) == -ENOENT)
break;
@@ -1013,6 +1059,16 @@ static const struct sun4i_usb_phy_cfg sun50i_h616_cfg = {
.siddq_in_base = true,
};
+static const struct sun4i_usb_phy_cfg sun60i_a733_cfg = {
+ .phyctl_offset = REG_PHYCTL_A33,
+ .dedicated_clocks = true,
+ .has_bus_clk = true,
+ .hci_phy_ctl_clear = PHY_CTL_SIDDQ,
+ .phy0_dual_route = true,
+ .needs_phy0_siddq = true,
+ .siddq_in_base = true,
+};
+
static const struct of_device_id sun4i_usb_phy_of_match[] = {
{ .compatible = "allwinner,sun4i-a10-usb-phy", .data = &sun4i_a10_cfg },
{ .compatible = "allwinner,sun5i-a13-usb-phy", .data = &sun5i_a13_cfg },
@@ -1029,6 +1085,7 @@ static const struct of_device_id sun4i_usb_phy_of_match[] = {
.data = &sun50i_a64_cfg},
{ .compatible = "allwinner,sun50i-h6-usb-phy", .data = &sun50i_h6_cfg },
{ .compatible = "allwinner,sun50i-h616-usb-phy", .data = &sun50i_h616_cfg },
+ { .compatible = "allwinner,sun60i-a733-usb-phy", .data = &sun60i_a733_cfg },
{ .compatible = "allwinner,suniv-f1c100s-usb-phy",
.data = &suniv_f1c100s_cfg },
{ },
--
2.53.0
next prev parent reply other threads:[~2026-11-27 10:08 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 10:08 [PATCH 0/6] Add Allwinner A733 USB 2.0 host support Alastair D'Silva
2026-11-27 10:08 ` [PATCH 1/6] dt-bindings: phy: allwinner,sun50i-a64-usb-phy: Add Allwinner A733 Alastair D'Silva
2026-11-27 10:08 ` [PATCH 2/6] dt-bindings: usb: generic-{ehci,ohci}: " Alastair D'Silva
2026-11-27 10:08 ` [PATCH 3/6] clk: sunxi-ng: a733: Mark mbus-msi-lite2 clock as critical Alastair D'Silva
2026-11-28 15:00 ` Daniel Golle
2026-11-27 10:08 ` Alastair D'Silva [this message]
2026-11-27 10:08 ` [PATCH 5/6] arm64: dts: allwinner: sun60i-a733: Add USB 2.0 host nodes Alastair D'Silva
2026-11-27 10:08 ` [PATCH 6/6] arm64: dts: allwinner: sun60i-a733-orangepi-4-pro: Enable USB 2.0 host Alastair D'Silva
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=20261127100808.2292229-5-alastair@d-silva.org \
--to=alastair@d-silva.org \
--cc=andre.przywara@arm.com \
--cc=bmasney+clk@redhat.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=jbrunet+clk@baylibre.com \
--cc=jernej.skrabec@gmail.com \
--cc=junhui.liu@pigmoral.tech \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=linux-usb@vger.kernel.org \
--cc=mani@kernel.org \
--cc=mripard@kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=robh@kernel.org \
--cc=samuel@sholland.org \
--cc=sboyd@kernel.org \
--cc=vkoul@kernel.org \
--cc=wens@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
all inboxes | Powered by JetHome®