From 9d2b50b448f7efd8b3891a2e8f52440794ed2958 Mon Sep 17 00:00:00 2001 From: Bryan O'Donoghue 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 --- 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