mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/5] usb: dwc3: export dwc3_core_probe/dwc3_core_remove like Linux
Date: Mon,  5 Jan 2026 20:12:52 +0100	[thread overview]
Message-ID: <20260105191410.615318-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260105191410.615318-1-a.fatoum@pengutronix.de>

Traditionally, platforms-specific glue was abstracted as a separate
parent device tree node for the snps,dwc3 node. For some newer
integrations, this is no longer the case and there is only a single
(flattened) node. To prepare support for these drivers, export the probe
and remove functions with the Linux semantics.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/usb/dwc3/core.c | 78 ++++++++++++++++++++++++++++-------------
 drivers/usb/dwc3/glue.h | 49 ++++++++++++++++++++++++++
 2 files changed, 102 insertions(+), 25 deletions(-)
 create mode 100644 drivers/usb/dwc3/glue.h

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 7f2cb6c4a70a..472630c95392 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -17,6 +17,7 @@
 #include <linux/reset.h>
 #include <linux/usb/of.h>
 
+#include "glue.h"
 #include "core.h"
 #include "gadget.h"
 #include "io.h"
@@ -1402,41 +1403,43 @@ static void dwc3_check_params(struct dwc3 *dwc)
 	}
 }
 
-static int dwc3_probe(struct device *dev)
+int dwc3_core_probe(const struct dwc3_probe_data *data)
 {
-	struct dwc3		*dwc;
+	struct dwc3		*dwc = data->dwc;
+	struct device		*dev = dwc->dev;
+	struct resource		*res = data->res;
 	int			ret;
 
-	dwc = xzalloc(sizeof(*dwc));
 	dev->priv = dwc;
 
-	dwc->dev = dev;
-	dwc->regs = dev_get_mem_region(dwc->dev, 0) + DWC3_GLOBALS_REGS_START;
+	dwc->regs = IOMEM(res->start) + DWC3_GLOBALS_REGS_START;
 
 	dwc3_get_properties(dwc);
 
-	if (dev->of_node) {
-		ret = clk_bulk_get_all(dev, &dwc->clks);
-		if (ret < 0)
+	if (!data->ignore_clocks_and_resets) {
+		if (dev->of_node) {
+			ret = clk_bulk_get_all(dev, &dwc->clks);
+			if (ret < 0)
+				return ret;
+
+			dwc->num_clks = ret;
+		}
+
+		ret = clk_bulk_enable(dwc->num_clks, dwc->clks);
+		if (ret)
 			return ret;
 
-		dwc->num_clks = ret;
+		dwc->reset = reset_control_get(dev, NULL);
+		if (IS_ERR(dwc->reset)) {
+			dev_err(dev, "Failed to get reset control: %pe\n", dwc->reset);
+			return PTR_ERR(dwc->reset);
+		}
+
+		reset_control_assert(dwc->reset);
+		mdelay(1);
+		reset_control_deassert(dwc->reset);
 	}
 
-	ret = clk_bulk_enable(dwc->num_clks, dwc->clks);
-	if (ret)
-		return ret;
-
-	dwc->reset = reset_control_get(dev, NULL);
-	if (IS_ERR(dwc->reset)) {
-		dev_err(dev, "Failed to get reset control: %pe\n", dwc->reset);
-		return PTR_ERR(dwc->reset);
-	}
-
-	reset_control_assert(dwc->reset);
-	mdelay(1);
-	reset_control_deassert(dwc->reset);
-
 	if (!dwc3_core_is_valid(dwc)) {
 		dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n");
 		return -ENODEV;
@@ -1476,10 +1479,30 @@ static int dwc3_probe(struct device *dev)
 	return 0;
 }
 
-static void dwc3_remove(struct device *dev)
+static int dwc3_probe(struct device *dev)
 {
-	struct dwc3 *dwc = dev->priv;
+	struct dwc3_probe_data probe_data = {};
+	struct resource *res;
+	struct dwc3 *dwc;
 
+	res = dev_get_resource(dev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(dev, "missing memory resource\n");
+		return -ENODEV;
+	}
+
+	dwc = xzalloc(sizeof(*dwc));
+
+	dwc->dev = dev;
+
+	probe_data.dwc = dwc;
+	probe_data.res = res;
+
+	return dwc3_core_probe(&probe_data);
+}
+
+void dwc3_core_remove(struct dwc3 *dwc)
+{
 	dwc3_core_exit_mode(dwc);
 	dwc3_core_exit(dwc);
 	clk_bulk_put(dwc->num_clks, dwc->clks);
@@ -1487,6 +1510,11 @@ static void dwc3_remove(struct device *dev)
 	dwc3_free_scratch_buffers(dwc);
 }
 
+static void dwc3_remove(struct device *dev)
+{
+	dwc3_core_remove(dev->priv);
+}
+
 static const struct of_device_id of_dwc3_match[] = {
 	{
 		.compatible = "snps,dwc3",
diff --git a/drivers/usb/dwc3/glue.h b/drivers/usb/dwc3/glue.h
new file mode 100644
index 000000000000..05d6d2723d19
--- /dev/null
+++ b/drivers/usb/dwc3/glue.h
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * glue.h - DesignWare USB3 DRD glue header
+ */
+
+#ifndef __DRIVERS_USB_DWC3_GLUE_H
+#define __DRIVERS_USB_DWC3_GLUE_H
+
+#include <linux/types.h>
+#include "core.h"
+
+/**
+ * dwc3_probe_data: Initialization parameters passed to dwc3_core_probe()
+ * @dwc: Reference to dwc3 context structure
+ * @res: resource for the DWC3 core mmio region
+ * @ignore_clocks_and_resets: clocks and resets defined for the device should
+ *		be ignored by the DWC3 core, as they are managed by the glue
+ */
+struct dwc3_probe_data {
+	struct dwc3 *dwc;
+	struct resource *res;
+	bool ignore_clocks_and_resets;
+};
+
+/**
+ * dwc3_core_probe - Initialize the core dwc3 driver
+ * @data: Initialization and configuration parameters for the controller
+ *
+ * Initializes the DesignWare USB3 core driver by setting up resources,
+ * registering interrupts, performing hardware setup, and preparing
+ * the controller for operation in the appropriate mode (host, gadget,
+ * or OTG). This is the main initialization function called by glue
+ * layer drivers to set up the core controller.
+ *
+ * Return: 0 on success, negative error code on failure
+ */
+int dwc3_core_probe(const struct dwc3_probe_data *data);
+
+/**
+ * dwc3_core_remove - Deinitialize and remove the core dwc3 driver
+ * @dwc: Pointer to DWC3 controller context
+ *
+ * Cleans up resources and disables the dwc3 core driver. This should be called
+ * during driver removal or when the glue layer needs to shut down the
+ * controller completely.
+ */
+void dwc3_core_remove(struct dwc3 *dwc);
+
+#endif
-- 
2.47.3




  reply	other threads:[~2026-01-05 19:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-05 19:12 [PATCH 0/5] usb: dwc3: add fsl,ls1028a-dwc3 glue driver Ahmad Fatoum
2026-01-05 19:12 ` Ahmad Fatoum [this message]
2026-01-05 19:12 ` [PATCH 2/5] usb: dwc3: add support for Global SoC Bus Configuration Register Ahmad Fatoum
2026-01-05 19:12 ` [PATCH 3/5] clk: implement and use clk_bulk_get_all_enabled helper Ahmad Fatoum
2026-01-05 19:12 ` [PATCH 4/5] usb: dwc3: add DesignWare USB3 generic platform driver Ahmad Fatoum
2026-01-05 19:12 ` [PATCH 5/5] Revert "ARM64: dts: Layerscape: workaround v6.19-rc1 DT sync DWC3 breakage" Ahmad Fatoum
2026-01-06  8:12 ` [PATCH 0/5] usb: dwc3: add fsl,ls1028a-dwc3 glue driver Sascha Hauer

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=20260105191410.615318-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.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