linux-arm-msm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
To: Bjorn Andersson <bjorn.andersson@linaro.org>,
	Jack Pham <jackp@codeaurora.org>
Cc: balbi@kernel.org, gregkh@linuxfoundation.org, agross@kernel.org,
	linux-usb@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	wcheng@codeaurora.org
Subject: Re: [PATCH 1/2] usb: dwc3: dwc3-qcom: Find USB connector and register role switch
Date: Wed, 30 Jun 2021 03:21:46 +0100	[thread overview]
Message-ID: <d8902c0d-ae51-644d-f33b-19f452308097@linaro.org> (raw)
In-Reply-To: <0f112cf5-1f71-f189-5a3a-2ff4dbcaa8e8@linaro.org>

[-- Attachment #1: Type: text/plain, Size: 1001 bytes --]

On 29/06/2021 22:57, Bryan O'Donoghue wrote:
> On 29/06/2021 21:30, Bjorn Andersson wrote:
>> I liked this, and it worked when I tested it, but iirc it suffered from
>> the problem that the core's probe may or may not have finished
>> successfully at the time that of_platform_populate() returns.
>>
>> But fixing this problem would save us quite a bit of headache.
> 
> OK.
> 
> I will take a look at resurrecting the old patches either fixing the 
> probe order - or perhaps using something like Wesley's role-switch to 
> have dwc3 core optionally trigger dwc3-qcom
> 
> Binding tcpm into &usb_1_dwc3 instead of &usb_1
> 
> ---
> bod

So here's a potential way forward. Not technically breaking my "no 
patches at 3am rule"

Basically we can fix the probe order problem if we have dwc3 drd call 
into dwc3-qcom.

In order to make that not be a problem for all non qcom platforms - use 
a function with weak binding in drd - which a wrapper - in this case the 
qcom wrapper can over ride..

---
bod

[-- Attachment #2: 0001-usb-dwc3-Add-support-for-a-role-switch-notifier.patch --]
[-- Type: text/x-patch, Size: 2623 bytes --]

From 329ffacea542163fe7ac798b77db7cb3599a65ac Mon Sep 17 00:00:00 2001
From: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Date: Wed, 11 Mar 2020 19:15:00 +0000
Subject: [PATCH 1/2] usb: dwc3: Add support for a role-switch notifier

Role-switching is a 1:1 mapping between a producer and a consumer. For DWC3
we have some vendor specific wrappers, notably the qcom wrapper that want
to toggle some PHY related bits on a USB role switch.

This patch adds a role-switch notifier to the dwc3 drd code. When the USB
role-switch set() routine runs, the notifier will fire passing the notified
mode to the consumer, thus allowing vendor specific fix-ups to toggle from
the role-switching events.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
---
 drivers/usb/dwc3/core.h | 8 ++++++++
 drivers/usb/dwc3/drd.c  | 5 +++++
 2 files changed, 13 insertions(+)

diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index dccdf13b5f9e..7f81ee3a9657 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -995,6 +995,7 @@ struct dwc3_scratchpad_array {
  * @role_sw: usb_role_switch handle
  * @role_switch_default_mode: default operation mode of controller while
  *			usb role is USB_ROLE_NONE.
+ * @role_sw_nl: role switch notifier list
  * @usb_psy: pointer to power supply interface.
  * @usb2_phy: pointer to USB2 PHY
  * @usb3_phy: pointer to USB3 PHY
@@ -1136,6 +1137,7 @@ struct dwc3 {
 	struct notifier_block	edev_nb;
 	enum usb_phy_interface	hsphy_mode;
 	struct usb_role_switch	*role_sw;
+	struct raw_notifier_head role_sw_nl;
 	enum usb_dr_mode	role_switch_default_mode;
 
 	struct power_supply	*usb_psy;
@@ -1586,4 +1588,10 @@ static inline void dwc3_ulpi_exit(struct dwc3 *dwc)
 { }
 #endif
 
+#if IS_ENABLED(CONFIG_USB_ROLE_SWITCH)
+void __weak
+dwc3_set_parent_role_switch_notifier(struct device *parent,
+				     struct raw_notifier_head *role_sw_nl) {}
+#endif
+
 #endif /* __DRIVERS_USB_DWC3_CORE_H */
diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c
index 8fcbac10510c..7ae09730a319 100644
--- a/drivers/usb/dwc3/drd.c
+++ b/drivers/usb/dwc3/drd.c
@@ -507,6 +507,8 @@ static int dwc3_usb_role_switch_set(struct usb_role_switch *sw,
 	}
 
 	dwc3_set_mode(dwc, mode);
+	raw_notifier_call_chain(&dwc->role_sw_nl, mode, NULL);
+
 	return 0;
 }
 
@@ -563,6 +565,9 @@ static int dwc3_setup_role_switch(struct dwc3 *dwc)
 	if (IS_ERR(dwc->role_sw))
 		return PTR_ERR(dwc->role_sw);
 
+	RAW_INIT_NOTIFIER_HEAD(&dwc->role_sw_nl);
+	dwc3_set_parent_role_switch_notifier(dwc->dev->parent,
+					     &dwc->role_sw_nl);
 	dwc3_set_mode(dwc, mode);
 	return 0;
 }
-- 
2.30.1


[-- Attachment #3: 0002-usb-dwc3-qcom-Implement-VBUS-role-switch-notifier-ho.patch --]
[-- Type: text/x-patch, Size: 2417 bytes --]

From 9d2b50b448f7efd8b3891a2e8f52440794ed2958 Mon Sep 17 00:00:00 2001
From: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Date: Wed, 30 Jun 2021 03:10:49 +0100
Subject: [PATCH 2/2] usb: dwc3: qcom: Implement VBUS role-switch notifier
 hooks

Implement dwc3_set_parent_role_switch_notifier() in dwc3-qcom allowing the
core drd code to call into the parent device when it has successfully setup
all necessary role-switching logic.

The qcom-dwc3 binding reuses the existing VBUS notifier for extcon
receiving notifications from the role-switch layer instead of extcon.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
---
 drivers/usb/dwc3/dwc3-qcom.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
index 49e6ca94486d..1b5aa345d025 100644
--- a/drivers/usb/dwc3/dwc3-qcom.c
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -81,6 +81,7 @@ struct dwc3_qcom {
 	struct extcon_dev	*host_edev;
 	struct notifier_block	vbus_nb;
 	struct notifier_block	host_nb;
+	struct raw_notifier_head *role_sw_nl;
 
 	const struct dwc3_acpi_pdata *acpi_pdata;
 
@@ -154,6 +155,20 @@ static int dwc3_qcom_host_notifier(struct notifier_block *nb,
 	return NOTIFY_DONE;
 }
 
+#if IS_ENABLED(CONFIG_USB_ROLE_SWITCH)
+void dwc3_set_parent_role_switch_notifier(struct device *dev,
+					  struct raw_notifier_head *role_sw_nl)
+{
+	struct platform_device *pdev = container_of(dev,
+						    struct platform_device, dev);
+	struct dwc3_qcom *qcom = platform_get_drvdata(pdev);
+
+	qcom->vbus_nb.notifier_call = dwc3_qcom_vbus_notifier;
+	if (!raw_notifier_chain_register(role_sw_nl, &qcom->vbus_nb))
+		qcom->role_sw_nl = role_sw_nl;
+}
+#endif
+
 static int dwc3_qcom_register_extcon(struct dwc3_qcom *qcom)
 {
 	struct device		*dev = qcom->dev;
@@ -829,6 +844,8 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 interconnect_exit:
 	dwc3_qcom_interconnect_exit(qcom);
 depopulate:
+	if (qcom->role_sw_nl)
+		raw_notifier_chain_unregister(qcom->role_sw_nl, &qcom->vbus_nb);
 	if (np)
 		of_platform_depopulate(&pdev->dev);
 	else
@@ -850,6 +867,9 @@ static int dwc3_qcom_remove(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	int i;
 
+	if (qcom->role_sw_nl)
+		raw_notifier_chain_unregister(qcom->role_sw_nl, &qcom->vbus_nb);
+
 	device_remove_software_node(&qcom->dwc3->dev);
 	of_platform_depopulate(dev);
 
-- 
2.30.1


  reply	other threads:[~2021-06-30  2:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-29 14:44 [PATCH 0/2] dwc3-qcom: Prepare the ground for pm8150b tcpm Bryan O'Donoghue
2021-06-29 14:44 ` [PATCH 1/2] usb: dwc3: dwc3-qcom: Find USB connector and register role switch Bryan O'Donoghue
2021-06-29 15:48   ` Bjorn Andersson
2021-06-29 19:23     ` Bryan O'Donoghue
2021-06-29 20:02       ` Jack Pham
2021-06-29 20:16         ` Bryan O'Donoghue
2021-06-29 20:30         ` Bjorn Andersson
2021-06-29 21:57           ` Bryan O'Donoghue
2021-06-30  2:21             ` Bryan O'Donoghue [this message]
2021-07-01  1:12               ` Jack Pham
2021-07-01  2:08                 ` Bryan O'Donoghue
2021-06-29 20:18       ` Bjorn Andersson
2021-06-29 14:44 ` [PATCH 2/2] usb: dwc3: dwc3-qcom: Fix typo in the dwc3 vbus override API Bryan O'Donoghue
2021-06-29 15:51   ` 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=d8902c0d-ae51-644d-f33b-19f452308097@linaro.org \
    --to=bryan.odonoghue@linaro.org \
    --cc=agross@kernel.org \
    --cc=balbi@kernel.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jackp@codeaurora.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=wcheng@codeaurora.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).