Thread (8 messages) 8 messages, 3 authors, 2025-12-16
STALE216d
Revisions (2)
  1. v1 [diff vs current]
  2. v2 current

[PATCH v2 4/4] usb: dwc3: Add support for Agilex5 in dwc3-generic-platform driver

From: adrianhoyin.ng@altera.com
Date: 2025-12-09 06:28:06
Also in: linux-usb, lkml
Subsystem: designware usb3 drd ip driver, the rest, usb subsystem · Maintainers: Thinh Nguyen, Linus Torvalds, Greg Kroah-Hartman

From: Adrian Ng Ho Yin <adrianhoyin.ng@altera.com>

Adds support for Agilex5 in the dwc3-generic-platform driver. Extends
generic driver to support configurable driver data to enable dwc3 core
property configuration from glue driver.

Agilex5 DWC3 wrapper has a 40-bit DMA address bus limitation. When SMMU
is enabled, using the default 64-bit DMA mask can cause DMA addresses to
be truncated, leading to translation faults.

This patch adds a `dma_addressable_bits` field in struct dwc3, allowing
the glue driver to set a 40-bit DMA mask during probe.

Signed-off-by: Adrian Ng Ho Yin <adrianhoyin.ng@altera.com>
---
 drivers/usb/dwc3/core.c              |  6 +++++-
 drivers/usb/dwc3/core.h              |  5 +++++
 drivers/usb/dwc3/dwc3-generic-plat.c | 20 +++++++++++++++++++-
 3 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index ae140c356295..1fca55637844 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -2243,7 +2243,11 @@ int dwc3_core_probe(const struct dwc3_probe_data *data)
 
 	if (!dwc->sysdev_is_parent &&
 	    DWC3_GHWPARAMS0_AWIDTH(dwc->hwparams.hwparams0) == 64) {
-		ret = dma_set_mask_and_coherent(dwc->sysdev, DMA_BIT_MASK(64));
+		if (!dwc->dma_addressable_bits)
+			dwc->dma_addressable_bits = 64;
+
+		ret = dma_set_mask_and_coherent(dwc->sysdev,
+						DMA_BIT_MASK(dwc->dma_addressable_bits));
 		if (ret)
 			goto err_disable_clks;
 	}
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index a5fc92c4ffa3..a09800fe6577 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -1180,6 +1180,10 @@ struct dwc3_glue_ops {
  * @wakeup_pending_funcs: Indicates whether any interface has requested for
  *			 function wakeup in bitmap format where bit position
  *			 represents interface_id.
+ * @dma_addressable_bits: The number of address bits the device can drive on
+ *			the DMA bus. The driver uses this value to program DMA masks and
+ *			ensure DMA buffers are allocated within the devices reachable
+ *			address space.
  */
 struct dwc3 {
 	struct work_struct	drd_work;
@@ -1414,6 +1418,7 @@ struct dwc3 {
 	struct dentry		*debug_root;
 	u32			gsbuscfg0_reqinfo;
 	u32			wakeup_pending_funcs;
+	u32			dma_addressable_bits;
 };
 
 #define INCRX_BURST_MODE 0
diff --git a/drivers/usb/dwc3/dwc3-generic-plat.c b/drivers/usb/dwc3/dwc3-generic-plat.c
index d96b20570002..e9650df6cf81 100644
--- a/drivers/usb/dwc3/dwc3-generic-plat.c
+++ b/drivers/usb/dwc3/dwc3-generic-plat.c
@@ -20,6 +20,11 @@ struct dwc3_generic {
 	struct reset_control	*resets;
 };
 
+struct dwc3_generic_config {
+	u32 flags;
+};
+
+#define DWC3_HAS_40BIT_DMA_QUIRK BIT(0)
 #define to_dwc3_generic(d) container_of((d), struct dwc3_generic, dwc)
 
 static void dwc3_generic_reset_control_assert(void *data)
@@ -34,6 +39,7 @@ static int dwc3_generic_probe(struct platform_device *pdev)
 	struct dwc3_generic *dwc3g;
 	struct resource *res;
 	int ret;
+	const struct dwc3_generic_config *drvdata;
 
 	dwc3g = devm_kzalloc(dev, sizeof(*dwc3g), GFP_KERNEL);
 	if (!dwc3g)
@@ -70,6 +76,10 @@ static int dwc3_generic_probe(struct platform_device *pdev)
 	if (ret < 0)
 		return dev_err_probe(dev, ret, "failed to get clocks\n");
 
+	drvdata = device_get_match_data(dev);
+	if (drvdata && (drvdata->flags & DWC3_HAS_40BIT_DMA_QUIRK))
+		dwc3g->dwc.dma_addressable_bits = 40;
+
 	dwc3g->num_clocks = ret;
 	dwc3g->dwc.dev = dev;
 	probe_data.dwc = &dwc3g->dwc;
@@ -145,8 +155,16 @@ static const struct dev_pm_ops dwc3_generic_dev_pm_ops = {
 		       dwc3_generic_runtime_idle)
 };
 
+static const struct dwc3_generic_config agilex5_config = {
+	.flags = DWC3_HAS_40BIT_DMA_QUIRK,
+};
+
 static const struct of_device_id dwc3_generic_of_match[] = {
-	{ .compatible = "spacemit,k1-dwc3", },
+	{	.compatible = "spacemit,k1-dwc3", },
+	{
+		.compatible = "altr,agilex5-dwc3",
+		.data = &agilex5_config,
+	},
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, dwc3_generic_of_match);
-- 
2.49.GIT
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help