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 11/12] usb: dwc3: qcom: Flatten the Qualcomm dwc3 binding and implementation
Date: Mon, 16 Oct 2023 20:11:19 -0700	[thread overview]
Message-ID: <20231016-dwc3-refactor-v1-11-ab4a84165470@quicinc.com> (raw)
In-Reply-To: <20231016-dwc3-refactor-v1-0-ab4a84165470@quicinc.com>

The USB block found in most Qualcomm platforms is modelled as three
different independent device drivers, and represented in DeviceTree as
two layered nodes. But as shown by the already existing layering
violations in the Qualcomm glue driver they can not be operated
independently.

In the current model, the probing of the core is asynchronous, and in a
number of places there's risk that the driver dereferences NULL
pointers, as it peeks into the core's drvdata.

There is also no way, in the current design to make the core notify the
glue upon DRD mode changes. Among the past proposals have been attempts
to provide a callback registration API, but as there is no way to know
when the core is probed this doesn't work.

Based on the recent refactoring its now possible to instantiate the glue
and core from a single representation of the DWC3 IP-block. This will
also allow for the glue to pass a callback to be called for DRD mode
changes.

The only overlapping handling between the Qualcomm glue and the core is
the release of reset, which is left to the core to handle.

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

diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
index cf6c391ba498..3c9a2b5cd559 100644
--- a/drivers/usb/dwc3/dwc3-qcom.c
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -686,6 +686,16 @@ static int dwc3_qcom_probe_core(struct platform_device *pdev, struct dwc3_qcom *
 	return 0;
 }
 
+static bool dwc3_qcom_has_separate_dwc3_of_node(struct device *dev)
+{
+	struct device_node *np;
+
+	np = of_get_compatible_child(dev->of_node, "snps,dwc3");
+	of_node_put(np);
+
+	return !!np;
+}
+
 static int dwc3_qcom_of_register_core(struct platform_device *pdev)
 {
 	struct dwc3_qcom	*qcom = platform_get_drvdata(pdev);
@@ -795,11 +805,14 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 	int			ret, i;
 	bool			ignore_pipe_clk;
 	bool			wakeup_source;
+	bool			legacy_binding;
 
 	qcom = devm_kzalloc(&pdev->dev, sizeof(*qcom), GFP_KERNEL);
 	if (!qcom)
 		return -ENOMEM;
 
+	legacy_binding = dwc3_qcom_has_separate_dwc3_of_node(dev);
+
 	platform_set_drvdata(pdev, qcom);
 	qcom->dev = &pdev->dev;
 
@@ -823,24 +836,26 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 		}
 	}
 
-	qcom->resets = devm_reset_control_array_get_optional_exclusive(dev);
-	if (IS_ERR(qcom->resets)) {
-		return dev_err_probe(&pdev->dev, PTR_ERR(qcom->resets),
-				     "failed to get resets\n");
-	}
+	if (legacy_binding) {
+		qcom->resets = devm_reset_control_array_get_optional_exclusive(dev);
+		if (IS_ERR(qcom->resets)) {
+			return dev_err_probe(&pdev->dev, PTR_ERR(qcom->resets),
+					     "failed to get resets\n");
+		}
 
-	ret = reset_control_assert(qcom->resets);
-	if (ret) {
-		dev_err(&pdev->dev, "failed to assert resets, err=%d\n", ret);
-		return ret;
-	}
+		ret = reset_control_assert(qcom->resets);
+		if (ret) {
+			dev_err(&pdev->dev, "failed to assert resets, err=%d\n", ret);
+			return ret;
+		}
 
-	usleep_range(10, 1000);
+		usleep_range(10, 1000);
 
-	ret = reset_control_deassert(qcom->resets);
-	if (ret) {
-		dev_err(&pdev->dev, "failed to deassert resets, err=%d\n", ret);
-		goto reset_assert;
+		ret = reset_control_deassert(qcom->resets);
+		if (ret) {
+			dev_err(&pdev->dev, "failed to deassert resets, err=%d\n", ret);
+			goto reset_assert;
+		}
 	}
 
 	ret = dwc3_qcom_clk_init(qcom, of_clk_get_parent_count(np));
@@ -851,7 +866,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 
-	if (np) {
+	if (legacy_binding) {
 		parent_res = res;
 	} else {
 		memcpy(&local_res, res, sizeof(struct resource));
@@ -882,7 +897,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 	if (ignore_pipe_clk)
 		dwc3_qcom_select_utmi_clk(qcom);
 
-	if (np)
+	if (legacy_binding)
 		ret = dwc3_qcom_of_register_core(pdev);
 	else
 		ret = dwc3_qcom_probe_core(pdev, qcom);

-- 
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 ` [PATCH 07/12] usb: dwc3: qcom: Instantiate dwc3 core directly Bjorn Andersson
2023-11-22 12:23   ` 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 ` Bjorn Andersson [this message]
2024-01-10  3:13   ` [PATCH 11/12] usb: dwc3: qcom: Flatten the Qualcomm dwc3 binding and implementation 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-11-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).