From: Jon Hunter <jonathanh@nvidia.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Thierry Reding <thierry.reding@kernel.org>,
"Nagarjuna Kristam" <nkristam@nvidia.com>,
JC Kuo <jckuo@nvidia.com>,
Mathias Nyman <mathias.nyman@intel.com>
Cc: Thierry Reding <thierry.reding@gmail.com>,
<linux-usb@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-tegra@vger.kernel.org>,
Thierry Reding <treding@nvidia.com>,
Wayne Chang <waynec@nvidia.com>,
Jon Hunter <jonathanh@nvidia.com>
Subject: [PATCH v2 09/12] usb: gadget: tegra-xudc: Add support for Tegra238
Date: Mon, 16 Nov 2026 15:24:06 +0000 [thread overview]
Message-ID: <20261116-tegra-usb-v2-9-42efc03a9700@nvidia.com> (raw)
In-Reply-To: <20261116-tegra-usb-v2-0-42efc03a9700@nvidia.com>
Add XUDC support for the Tegra238 SoC which is similar to Tegra234 XUDC
but only supports 3 PHYs compared to the 4 PHYs on the Tegra234.
Unlike other Tegra devices, Tegra238 does not have powergates for the
USB device and Superspeed controllers, so it only needs reset management
for these controllers. Add a 'has_powergates' variable to the SoC data
to select between power domains and reset controls. Acquire xusb_dev
exclusively and xusb_ss shared because the latter is also used by the
host controller.
Handle the resets independently. During suspend and removal, assert DEV
before SS and attempt both assertions without rollback. Always release
the shared SS vote even if DEV assertion fails, so subsequent activation
does not accumulate unmatched deassert votes. Log assertion failures and
retain best-effort teardown behavior.
During activation, deassert DEV before SS and unwind failed deassertions.
Shared reset deassertion increments its count even on provider failure,
so balance a failed SS deassertion before reasserting DEV and disabling
clocks and regulators.
Rename tegra_xudc_powergate and tegra_xudc_unpowergate to
tegra_xudc_deactivate and tegra_xudc_activate because Tegra238 does not
use powergates.
Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
---
drivers/usb/gadget/udc/tegra-xudc.c | 118 +++++++++++++++++++++++++++++++-----
1 file changed, 103 insertions(+), 15 deletions(-)
diff --git a/drivers/usb/gadget/udc/tegra-xudc.c b/drivers/usb/gadget/udc/tegra-xudc.c
index 43a1940ed88a..3d7254d6ebcd 100644
--- a/drivers/usb/gadget/udc/tegra-xudc.c
+++ b/drivers/usb/gadget/udc/tegra-xudc.c
@@ -501,6 +501,9 @@ struct tegra_xudc {
struct clk_bulk_data *clks;
+ struct reset_control *dev_rst;
+ struct reset_control *ss_rst;
+
bool device_mode;
bool current_device_mode;
struct work_struct usb_role_sw_work;
@@ -556,6 +559,7 @@ struct tegra_xudc_soc {
bool port_reset_quirk;
bool port_speed_quirk;
bool has_ipfs;
+ bool has_powergates;
};
static inline u32 fpci_readl(struct tegra_xudc *xudc, unsigned int offset)
@@ -3649,6 +3653,7 @@ static struct tegra_xudc_soc tegra210_xudc_soc_data = {
.port_reset_quirk = true,
.port_speed_quirk = false,
.has_ipfs = true,
+ .has_powergates = true,
};
static struct tegra_xudc_soc tegra186_xudc_soc_data = {
@@ -3663,6 +3668,7 @@ static struct tegra_xudc_soc tegra186_xudc_soc_data = {
.port_reset_quirk = false,
.port_speed_quirk = false,
.has_ipfs = false,
+ .has_powergates = true,
};
static struct tegra_xudc_soc tegra194_xudc_soc_data = {
@@ -3677,6 +3683,7 @@ static struct tegra_xudc_soc tegra194_xudc_soc_data = {
.port_reset_quirk = false,
.port_speed_quirk = true,
.has_ipfs = false,
+ .has_powergates = true,
};
static struct tegra_xudc_soc tegra234_xudc_soc_data = {
@@ -3690,6 +3697,21 @@ static struct tegra_xudc_soc tegra234_xudc_soc_data = {
.pls_quirk = false,
.port_reset_quirk = false,
.has_ipfs = false,
+ .has_powergates = true,
+};
+
+static struct tegra_xudc_soc tegra238_xudc_soc_data = {
+ .clock_names = tegra186_xudc_clock_names,
+ .num_clks = ARRAY_SIZE(tegra186_xudc_clock_names),
+ .num_phys = 3,
+ .u1_enable = true,
+ .u2_enable = true,
+ .lpm_enable = true,
+ .invalid_seq_num = false,
+ .pls_quirk = false,
+ .port_reset_quirk = false,
+ .has_ipfs = false,
+ .has_powergates = false,
};
static const struct of_device_id tegra_xudc_of_match[] = {
@@ -3709,6 +3731,10 @@ static const struct of_device_id tegra_xudc_of_match[] = {
.compatible = "nvidia,tegra234-xudc",
.data = &tegra234_xudc_soc_data
},
+ {
+ .compatible = "nvidia,tegra238-xudc",
+ .data = &tegra238_xudc_soc_data
+ },
{ }
};
MODULE_DEVICE_TABLE(of, tegra_xudc_of_match);
@@ -3849,9 +3875,25 @@ static int tegra_xudc_probe(struct platform_device *pdev)
if (err)
goto disable_regulator;
- err = tegra_xudc_powerdomain_init(xudc);
- if (err)
- goto put_powerdomains;
+ if (xudc->soc->has_powergates) {
+ err = tegra_xudc_powerdomain_init(xudc);
+ if (err)
+ goto put_powerdomains;
+ } else {
+ xudc->dev_rst = devm_reset_control_get_exclusive(xudc->dev, "xusb_dev");
+ if (IS_ERR(xudc->dev_rst)) {
+ err = PTR_ERR(xudc->dev_rst);
+ dev_err(xudc->dev, "failed to get xusb_dev reset: %d\n", err);
+ goto disable_regulator;
+ }
+
+ xudc->ss_rst = devm_reset_control_get_shared(xudc->dev, "xusb_ss");
+ if (IS_ERR(xudc->ss_rst)) {
+ err = PTR_ERR(xudc->ss_rst);
+ dev_err(xudc->dev, "failed to get xusb_ss reset: %d\n", err);
+ goto disable_regulator;
+ }
+ }
err = tegra_xudc_phy_init(xudc);
if (err)
@@ -3916,6 +3958,23 @@ static int tegra_xudc_probe(struct platform_device *pdev)
return err;
}
+static void tegra_xudc_assert_resets(struct tegra_xudc *xudc)
+{
+ int err;
+
+ err = reset_control_assert(xudc->dev_rst);
+ if (err)
+ dev_err(xudc->dev, "failed to assert device reset: %d\n", err);
+
+ /*
+ * Release the shared SS reset vote even if the device reset fails,
+ * otherwise the next activation adds an unbalanced deassert vote.
+ */
+ err = reset_control_assert(xudc->ss_rst);
+ if (err)
+ dev_err(xudc->dev, "failed to assert SS reset: %d\n", err);
+}
+
static void tegra_xudc_remove(struct platform_device *pdev)
{
struct tegra_xudc *xudc = platform_get_drvdata(pdev);
@@ -3931,7 +3990,10 @@ static void tegra_xudc_remove(struct platform_device *pdev)
tegra_xudc_free_eps(xudc);
tegra_xudc_free_event_ring(xudc);
- tegra_xudc_powerdomain_remove(xudc);
+ if (xudc->soc->has_powergates)
+ tegra_xudc_powerdomain_remove(xudc);
+ else
+ tegra_xudc_assert_resets(xudc);
regulator_bulk_disable(xudc->soc->num_supplies, xudc->supplies);
@@ -3948,12 +4010,12 @@ static void tegra_xudc_remove(struct platform_device *pdev)
tegra_xusb_padctl_put(xudc->padctl);
}
-static int __maybe_unused tegra_xudc_powergate(struct tegra_xudc *xudc)
+static int __maybe_unused tegra_xudc_deactivate(struct tegra_xudc *xudc)
{
unsigned long flags;
u32 val;
- dev_dbg(xudc->dev, "entering ELPG\n");
+ dev_dbg(xudc->dev, "entering %s\n", __func__);
spin_lock_irqsave(&xudc->lock, flags);
@@ -3972,16 +4034,19 @@ static int __maybe_unused tegra_xudc_powergate(struct tegra_xudc *xudc)
regulator_bulk_disable(xudc->soc->num_supplies, xudc->supplies);
- dev_dbg(xudc->dev, "entering ELPG done\n");
+ if (!xudc->soc->has_powergates)
+ tegra_xudc_assert_resets(xudc);
+
+ dev_dbg(xudc->dev, "exiting %s\n", __func__);
return 0;
}
-static int __maybe_unused tegra_xudc_unpowergate(struct tegra_xudc *xudc)
+static int __maybe_unused tegra_xudc_activate(struct tegra_xudc *xudc)
{
unsigned long flags;
int err;
- dev_dbg(xudc->dev, "exiting ELPG\n");
+ dev_dbg(xudc->dev, "entering %s\n", __func__);
err = regulator_bulk_enable(xudc->soc->num_supplies,
xudc->supplies);
@@ -3990,7 +4055,21 @@ static int __maybe_unused tegra_xudc_unpowergate(struct tegra_xudc *xudc)
err = clk_bulk_prepare_enable(xudc->soc->num_clks, xudc->clks);
if (err < 0)
- return err;
+ goto err_clocks;
+
+ if (!xudc->soc->has_powergates) {
+ err = reset_control_deassert(xudc->dev_rst);
+ if (err) {
+ dev_err(xudc->dev, "failed to deassert device reset: %d\n", err);
+ goto assert_dev;
+ }
+
+ err = reset_control_deassert(xudc->ss_rst);
+ if (err) {
+ dev_err(xudc->dev, "failed to deassert SS reset: %d\n", err);
+ goto assert_ss;
+ }
+ }
tegra_xudc_fpci_ipfs_init(xudc);
@@ -4007,8 +4086,17 @@ static int __maybe_unused tegra_xudc_unpowergate(struct tegra_xudc *xudc)
xudc->powergated = false;
spin_unlock_irqrestore(&xudc->lock, flags);
- dev_dbg(xudc->dev, "exiting ELPG done\n");
+ dev_dbg(xudc->dev, "exiting %s\n", __func__);
return 0;
+
+assert_ss:
+ reset_control_assert(xudc->ss_rst);
+assert_dev:
+ reset_control_assert(xudc->dev_rst);
+ clk_bulk_disable_unprepare(xudc->soc->num_clks, xudc->clks);
+err_clocks:
+ regulator_bulk_disable(xudc->soc->num_supplies, xudc->supplies);
+ return err;
}
static int __maybe_unused tegra_xudc_suspend(struct device *dev)
@@ -4025,7 +4113,7 @@ static int __maybe_unused tegra_xudc_suspend(struct device *dev)
if (!pm_runtime_status_suspended(dev)) {
/* Forcibly disconnect before powergating. */
tegra_xudc_device_mode_off(xudc);
- tegra_xudc_powergate(xudc);
+ tegra_xudc_deactivate(xudc);
}
pm_runtime_disable(dev);
@@ -4040,7 +4128,7 @@ static int __maybe_unused tegra_xudc_resume(struct device *dev)
int err;
if (!pm_runtime_status_suspended(dev)) {
- err = tegra_xudc_unpowergate(xudc);
+ err = tegra_xudc_activate(xudc);
if (err < 0)
return err;
}
@@ -4060,14 +4148,14 @@ static int __maybe_unused tegra_xudc_runtime_suspend(struct device *dev)
{
struct tegra_xudc *xudc = dev_get_drvdata(dev);
- return tegra_xudc_powergate(xudc);
+ return tegra_xudc_deactivate(xudc);
}
static int __maybe_unused tegra_xudc_runtime_resume(struct device *dev)
{
struct tegra_xudc *xudc = dev_get_drvdata(dev);
- return tegra_xudc_unpowergate(xudc);
+ return tegra_xudc_activate(xudc);
}
static const struct dev_pm_ops tegra_xudc_pm_ops = {
--
2.43.0
next prev parent reply other threads:[~2026-11-16 15:25 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 15:23 [PATCH v2 00/12] usb: Add support for Tegra238 and device support for Tegra264 Jon Hunter
2026-11-16 15:23 ` [PATCH v2 01/12] dt-bindings: usb: tegra234-xusb: Add required properties Jon Hunter
2026-11-16 15:23 ` [PATCH v2 02/12] dt-bindings: usb: Add Tegra238 XUSB host controller support Jon Hunter
2026-11-16 15:38 ` sashiko-bot
2026-11-16 15:24 ` [PATCH v2 03/12] dt-bindings: usb: tegra-xudc: Add Tegra238 XUDC support Jon Hunter
2026-11-16 15:24 ` [PATCH v2 04/12] dt-bindings: usb: tegra-xudc: Add Tegra264 " Jon Hunter
2026-11-16 15:24 ` [PATCH v2 05/12] usb: xhci: tegra: Fix missing semi-colon Jon Hunter
2026-11-16 15:24 ` [PATCH v2 06/12] usb: xhci: tegra: Add support for Tegra238 Jon Hunter
2026-11-16 15:24 ` [PATCH v2 07/12] usb: gadget: tegra-xudc: Fix CNT65 configuration Jon Hunter
2026-11-16 15:24 ` [PATCH v2 08/12] usb: gadget: tegra-xudc: Preserve runtime PM across system suspend Jon Hunter
2026-11-16 15:24 ` Jon Hunter [this message]
2026-11-16 15:54 ` [PATCH v2 09/12] usb: gadget: tegra-xudc: Add support for Tegra238 sashiko-bot
2026-11-16 15:24 ` [PATCH v2 10/12] usb: gadget: tegra-xudc: Add SSPX register offset to SoC data Jon Hunter
2026-11-16 15:24 ` [PATCH v2 11/12] usb: gadget: tegra-xudc: Add default settings " Jon Hunter
2026-11-16 15:24 ` [PATCH v2 12/12] usb: gadget: tegra-xudc: Add support for Tegra264 Jon Hunter
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=20261116-tegra-usb-v2-9-42efc03a9700@nvidia.com \
--to=jonathanh@nvidia.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=jckuo@nvidia.com \
--cc=krzk+dt@kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@intel.com \
--cc=nkristam@nvidia.com \
--cc=robh@kernel.org \
--cc=thierry.reding@gmail.com \
--cc=thierry.reding@kernel.org \
--cc=treding@nvidia.com \
--cc=waynec@nvidia.com \
/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