[PATCH 4/6] phy: allwinner: sun4i-usb: Add Allwinner A733 support

From
Alastair D'Silva <hidden>
Date
2026-11-27 10:08:43
Also in
linux-arm-kernel, linux-clk, linux-phy, linux-sunxi, linux-usb, lkml
Reply to
Alastair D'Silva, 2026-11-27
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 <redacted>
---
 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
Thread (8 messages) 8 messages, 2 authors, last reply 4d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help