devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bjorn Andersson <quic_bjorande@quicinc.com>
To: Bjorn Andersson <andersson@kernel.org>,
	Konrad Dybcio <konrad.dybcio@linaro.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Wesley Cheng <quic_wcheng@quicinc.com>,
	Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Felipe Balbi <balbi@kernel.org>,
	Philipp Zabel <p.zabel@pengutronix.de>
Cc: <linux-arm-msm@vger.kernel.org>, <linux-usb@vger.kernel.org>,
	<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Johan Hovold <johan@kernel.org>,
	Krishna Kurapati PSSNV <quic_kriskura@quicinc.com>,
	"Bjorn Andersson" <quic_bjorande@quicinc.com>
Subject: [PATCH 07/12] usb: dwc3: qcom: Instantiate dwc3 core directly
Date: Mon, 16 Oct 2023 20:11:15 -0700	[thread overview]
Message-ID: <20231016-dwc3-refactor-v1-7-ab4a84165470@quicinc.com> (raw)
In-Reply-To: <20231016-dwc3-refactor-v1-0-ab4a84165470@quicinc.com>

The Qualcomm DWC3 glue builds up a platform_device programmatically in
order to probe the DWC3 core when running off ACPI data. But with the
newly introduced support for instantiating the core directly from the
glue, this code can be replaced with a single function call.

Signed-off-by: Bjorn Andersson <quic_bjorande@quicinc.com>
---
 drivers/usb/dwc3/dwc3-qcom.c | 85 ++++++++------------------------------------
 1 file changed, 15 insertions(+), 70 deletions(-)

diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
index 901e5050363b..cc0fe010ee8c 100644
--- a/drivers/usb/dwc3/dwc3-qcom.c
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -56,7 +56,6 @@
 struct dwc3_acpi_pdata {
 	u32			qscratch_base_offset;
 	u32			qscratch_base_size;
-	u32			dwc3_core_base_size;
 	int			hs_phy_irq_index;
 	int			dp_hs_phy_irq_index;
 	int			dm_hs_phy_irq_index;
@@ -676,75 +675,17 @@ static const struct software_node dwc3_qcom_swnode = {
 	.properties = dwc3_qcom_acpi_properties,
 };
 
-static int dwc3_qcom_acpi_register_core(struct platform_device *pdev)
+static int dwc3_qcom_probe_core(struct platform_device *pdev, struct dwc3_qcom *qcom)
 {
-	struct dwc3_qcom	*qcom = platform_get_drvdata(pdev);
-	struct device		*dev = &pdev->dev;
-	struct resource		*res, *child_res = NULL;
-	int			irq;
-	int			ret;
-
-	qcom->dwc_dev = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
-	if (!qcom->dwc_dev)
-		return -ENOMEM;
-
-	qcom->dwc_dev->dev.parent = dev;
-	qcom->dwc_dev->dev.type = dev->type;
-	qcom->dwc_dev->dev.dma_mask = dev->dma_mask;
-	qcom->dwc_dev->dev.dma_parms = dev->dma_parms;
-	qcom->dwc_dev->dev.coherent_dma_mask = dev->coherent_dma_mask;
-
-	child_res = kcalloc(2, sizeof(*child_res), GFP_KERNEL);
-	if (!child_res) {
-		platform_device_put(qcom->dwc_dev);
-		return -ENOMEM;
-	}
-
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res) {
-		dev_err(&pdev->dev, "failed to get memory resource\n");
-		ret = -ENODEV;
-		goto out;
-	}
-
-	child_res[0].flags = res->flags;
-	child_res[0].start = res->start;
-	child_res[0].end = child_res[0].start +
-		qcom->acpi_pdata->dwc3_core_base_size;
-
-	irq = platform_get_irq(pdev, 0);
-	if (irq < 0) {
-		ret = irq;
-		goto out;
-	}
-	child_res[1].flags = IORESOURCE_IRQ;
-	child_res[1].start = child_res[1].end = irq;
+	struct dwc3 *dwc;
 
-	ret = platform_device_add_resources(qcom->dwc_dev, child_res, 2);
-	if (ret) {
-		dev_err(&pdev->dev, "failed to add resources\n");
-		goto out;
-	}
+	dwc = dwc3_probe(pdev);
+	if (IS_ERR(dwc))
+		return PTR_ERR(dwc);
 
-	ret = device_add_software_node(&qcom->dwc_dev->dev, &dwc3_qcom_swnode);
-	if (ret < 0) {
-		dev_err(&pdev->dev, "failed to add properties\n");
-		goto out;
-	}
+	qcom->dwc = dwc;
 
-	ret = platform_device_add(qcom->dwc_dev);
-	if (ret) {
-		dev_err(&pdev->dev, "failed to add device\n");
-		device_remove_software_node(&qcom->dwc_dev->dev);
-		goto out;
-	}
-	kfree(child_res);
 	return 0;
-
-out:
-	platform_device_put(qcom->dwc_dev);
-	kfree(child_res);
-	return ret;
 }
 
 static int dwc3_qcom_of_register_core(struct platform_device *pdev)
@@ -871,6 +812,12 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 			return -EINVAL;
 		}
 
+		ret = device_add_software_node(&pdev->dev, &dwc3_qcom_swnode);
+		if (ret < 0) {
+			dev_err(&pdev->dev, "failed to add properties\n");
+			return ret;
+		}
+
 		if (qcom->acpi_pdata->is_urs) {
 			ret = dwc3_qcom_acpi_merge_urs_resources(pdev);
 			if (ret < 0)
@@ -942,7 +889,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 	if (np)
 		ret = dwc3_qcom_of_register_core(pdev);
 	else
-		ret = dwc3_qcom_acpi_register_core(pdev);
+		ret = dwc3_qcom_probe_core(pdev, qcom);
 
 	if (ret) {
 		dev_err(dev, "failed to register DWC3 Core, err=%d\n", ret);
@@ -986,10 +933,10 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 interconnect_exit:
 	dwc3_qcom_interconnect_exit(qcom);
 depopulate:
-	if (np)
+	if (qcom->dwc_dev)
 		of_platform_depopulate(&pdev->dev);
 	else
-		platform_device_put(pdev);
+		dwc3_remove(qcom->dwc);
 clk_disable:
 	for (i = qcom->num_clocks - 1; i >= 0; i--) {
 		clk_disable_unprepare(qcom->clks[i]);
@@ -1128,7 +1075,6 @@ MODULE_DEVICE_TABLE(of, dwc3_qcom_of_match);
 static const struct dwc3_acpi_pdata sdm845_acpi_pdata = {
 	.qscratch_base_offset = SDM845_QSCRATCH_BASE_OFFSET,
 	.qscratch_base_size = SDM845_QSCRATCH_SIZE,
-	.dwc3_core_base_size = SDM845_DWC3_CORE_SIZE,
 	.hs_phy_irq_index = 1,
 	.dp_hs_phy_irq_index = 4,
 	.dm_hs_phy_irq_index = 3,
@@ -1138,7 +1084,6 @@ static const struct dwc3_acpi_pdata sdm845_acpi_pdata = {
 static const struct dwc3_acpi_pdata sdm845_acpi_urs_pdata = {
 	.qscratch_base_offset = SDM845_QSCRATCH_BASE_OFFSET,
 	.qscratch_base_size = SDM845_QSCRATCH_SIZE,
-	.dwc3_core_base_size = SDM845_DWC3_CORE_SIZE,
 	.hs_phy_irq_index = 1,
 	.dp_hs_phy_irq_index = 4,
 	.dm_hs_phy_irq_index = 3,

-- 
2.25.1


  parent reply	other threads:[~2023-10-17  3:11 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-17  3:11 [PATCH 00/12] usb: dwc3: qcom: Flatten dwc3 structure Bjorn Andersson
2023-10-17  3:11 ` [PATCH 01/12] dt-bindings: usb: qcom,dwc3: Add qcom,sc8180x-dwc3 Bjorn Andersson
2023-10-17  6:03   ` Krzysztof Kozlowski
2023-10-17  3:11 ` [PATCH 02/12] usb: dwc3: qcom: Rename dwc3 platform_device reference Bjorn Andersson
2023-10-17 16:08   ` Konrad Dybcio
2023-11-22  9:58   ` Johan Hovold
2023-10-17  3:11 ` [PATCH 03/12] usb: dwc3: qcom: Merge resources from urs_usb device Bjorn Andersson
2023-10-20  6:02   ` kernel test robot
2023-11-22 10:24   ` Johan Hovold
2024-01-08 16:25     ` Bjorn Andersson
2023-10-17  3:11 ` [PATCH 04/12] usb: dwc3: Expose core driver as library Bjorn Andersson
2023-10-20 22:18   ` Thinh Nguyen
2023-11-22 11:57   ` Johan Hovold
2024-01-08 16:42     ` Bjorn Andersson
2023-10-17  3:11 ` [PATCH 05/12] usb: dwc3: Override end of dwc3 memory resource Bjorn Andersson
2023-10-17 16:14   ` Konrad Dybcio
2023-10-20 22:07   ` Thinh Nguyen
2023-10-17  3:11 ` [PATCH 06/12] usb: dwc3: qcom: Add dwc3 core reference in driver state Bjorn Andersson
2023-11-22 12:18   ` Johan Hovold
2024-01-08 18:02     ` Bjorn Andersson
2023-10-17  3:11 ` Bjorn Andersson [this message]
2023-11-22 12:23   ` [PATCH 07/12] usb: dwc3: qcom: Instantiate dwc3 core directly Johan Hovold
2024-01-10  3:16   ` Krishna Kurapati PSSNV
2023-10-17  3:11 ` [PATCH 08/12] usb: dwc3: qcom: Inline the qscratch constants Bjorn Andersson
2023-10-17 16:18   ` Konrad Dybcio
2023-10-17  3:11 ` [PATCH 09/12] dt-bindings: usb: qcom,dwc3: Rename to "glue" Bjorn Andersson
2023-10-17  6:05   ` Krzysztof Kozlowski
2023-11-22 12:25   ` Johan Hovold
2023-10-17  3:11 ` [PATCH 10/12] dt-bindings: usb: qcom,dwc3: Introduce flattened qcom,dwc3 binding Bjorn Andersson
2023-10-17  6:11   ` Krzysztof Kozlowski
2023-10-17 22:54     ` Bjorn Andersson
2023-10-18  6:00       ` Krzysztof Kozlowski
2023-10-17 18:31   ` Rob Herring
2023-10-17 21:02     ` Bjorn Andersson
2023-11-22 12:40   ` Johan Hovold
2023-10-17  3:11 ` [PATCH 11/12] usb: dwc3: qcom: Flatten the Qualcomm dwc3 binding and implementation Bjorn Andersson
2024-01-10  3:13   ` Krishna Kurapati PSSNV
2024-01-10 19:23     ` Bjorn Andersson
2023-10-17  3:11 ` [PATCH 12/12] arm64: dts: qcom: sc8180x: flatten usb_sec node Bjorn Andersson
2023-10-20 22:04 ` [PATCH 00/12] usb: dwc3: qcom: Flatten dwc3 structure Thinh Nguyen
2023-11-22  9:48 ` Johan Hovold
2024-01-08 16:46   ` Bjorn Andersson

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=20231016-dwc3-refactor-v1-7-ab4a84165470@quicinc.com \
    --to=quic_bjorande@quicinc.com \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=andersson@kernel.org \
    --cc=balbi@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan@kernel.org \
    --cc=konrad.dybcio@linaro.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=quic_kriskura@quicinc.com \
    --cc=quic_wcheng@quicinc.com \
    --cc=robh+dt@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;
as well as URLs for NNTP newsgroup(s).