Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: dwc3: qcom: Implement glue callbacks to facilitate runtime suspend

On Qualcomm DWC3 dual-role controllers, the conndone/disconnect events in
device mode are generated by controller when software writes to QSCRATCH
registers in Qualcomm Glue layer rather than the vbus line being routed to
dwc3 core IP for it to recognize and generate these events.

UTMI_OTG_VBUS_VALID bit of QSCRATCH_HS_PHY_CTRL register needs to be set
to generate a connection done event and to be cleared for the controller to
generate a disconnect event during cable removal. When the disconnect is
not generated upon cable removal, the "connected" flag of dwc3 is left
marked as "true" and it blocks suspend routines and for that to happen upon
cable removal, the cable disconnect notification coming in via set_role
call need to be provided to the Qualcomm glue layer as well.

Currently, the way DWC3 core and Qualcomm legacy glue driver are designed,
there is no mechanism through which the DWC3 core can notify the Qualcomm
glue layer of any role changes which it receives via role switch. To
register these glue callbacks at probe time, for enabling core to notify
glue layer, the legacy Qualcomm driver has no way to find out when the
child driver probe was successful since it does not check for the same
during of_platform_populate.

Hence implement the following glue callbacks for flattened Qualcomm glue
driver:

1. set_role: To pass role switching information from drd layer to glue.
This information is needed to identify NONE/DEVICE mode switch and modify
QSCRATCH to generate connect-done event on device mode entry and disconnect
event on cable removal in device mode.

2. run_stop: When booting up in device mode, if autouspend is enabled and
userspace doesn't write UDC on boot, controller enters autosuspend. After
this, if the userspace writes to UDC in the future, run_stop notifier is
required to enable UTMI_OTG_VBUS_VALID of QSCRATCH so that connect done
event is generated after run_stop(1) is done to finish enumeration.

Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Signed-off-by: Krishna Kurapati <krishna.kurapati@oss.qualcomm.com>
Link: https://lore.kernel.org/r/20250907181412.2174616-3-krishna.kurapati@oss.qualcomm.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Krishna Kurapati and committed by
Greg Kroah-Hartman
21188e8d 643df901

+68 -10
+68 -10
drivers/usb/dwc3/dwc3-qcom.c
··· 83 83 bool pm_suspended; 84 84 struct icc_path *icc_path_ddr; 85 85 struct icc_path *icc_path_apps; 86 + 87 + enum usb_role current_role; 86 88 }; 87 89 88 90 #define to_dwc3_qcom(d) container_of((d), struct dwc3_qcom, dwc) ··· 113 111 readl(base + offset); 114 112 } 115 113 116 - /* 117 - * TODO: Make the in-core role switching code invoke dwc3_qcom_vbus_override_enable(), 118 - * validate that the in-core extcon support is functional 119 - */ 120 114 static void dwc3_qcom_vbus_override_enable(struct dwc3_qcom *qcom, bool enable) 121 115 { 122 116 if (enable) { ··· 558 560 return 0; 559 561 } 560 562 563 + static void dwc3_qcom_set_role_notifier(struct dwc3 *dwc, enum usb_role next_role) 564 + { 565 + struct dwc3_qcom *qcom = to_dwc3_qcom(dwc); 566 + 567 + if (qcom->current_role == next_role) 568 + return; 569 + 570 + if (pm_runtime_resume_and_get(qcom->dev)) { 571 + dev_dbg(qcom->dev, "Failed to resume device\n"); 572 + return; 573 + } 574 + 575 + if (qcom->current_role == USB_ROLE_DEVICE) 576 + dwc3_qcom_vbus_override_enable(qcom, false); 577 + else if (qcom->current_role != USB_ROLE_DEVICE) 578 + dwc3_qcom_vbus_override_enable(qcom, true); 579 + 580 + pm_runtime_mark_last_busy(qcom->dev); 581 + pm_runtime_put_sync(qcom->dev); 582 + 583 + /* 584 + * Current role changes via usb_role_switch_set_role callback protected 585 + * internally by mutex lock. 586 + */ 587 + qcom->current_role = next_role; 588 + } 589 + 590 + static void dwc3_qcom_run_stop_notifier(struct dwc3 *dwc, bool is_on) 591 + { 592 + struct dwc3_qcom *qcom = to_dwc3_qcom(dwc); 593 + 594 + /* 595 + * When autosuspend is enabled and controller goes to suspend 596 + * after removing UDC from userspace, the next UDC write needs 597 + * setting of QSCRATCH VBUS_VALID to "1" to generate a connect 598 + * done event. 599 + */ 600 + if (!is_on) 601 + return; 602 + 603 + dwc3_qcom_vbus_override_enable(qcom, true); 604 + pm_runtime_mark_last_busy(qcom->dev); 605 + } 606 + 607 + struct dwc3_glue_ops dwc3_qcom_glue_ops = { 608 + .pre_set_role = dwc3_qcom_set_role_notifier, 609 + .pre_run_stop = dwc3_qcom_run_stop_notifier, 610 + }; 611 + 561 612 static int dwc3_qcom_probe(struct platform_device *pdev) 562 613 { 563 614 struct dwc3_probe_data probe_data = {}; ··· 683 636 if (ignore_pipe_clk) 684 637 dwc3_qcom_select_utmi_clk(qcom); 685 638 639 + qcom->mode = usb_get_dr_mode(dev); 640 + 641 + if (qcom->mode == USB_DR_MODE_HOST) { 642 + qcom->current_role = USB_ROLE_HOST; 643 + } else if (qcom->mode == USB_DR_MODE_PERIPHERAL) { 644 + qcom->current_role = USB_ROLE_DEVICE; 645 + dwc3_qcom_vbus_override_enable(qcom, true); 646 + } else { 647 + if ((device_property_read_bool(dev, "usb-role-switch")) && 648 + (usb_get_role_switch_default_mode(dev) == USB_DR_MODE_HOST)) 649 + qcom->current_role = USB_ROLE_HOST; 650 + else 651 + qcom->current_role = USB_ROLE_DEVICE; 652 + } 653 + 654 + qcom->dwc.glue_ops = &dwc3_qcom_glue_ops; 655 + 686 656 qcom->dwc.dev = dev; 687 657 probe_data.dwc = &qcom->dwc; 688 658 probe_data.res = &res; ··· 713 649 ret = dwc3_qcom_interconnect_init(qcom); 714 650 if (ret) 715 651 goto remove_core; 716 - 717 - qcom->mode = usb_get_dr_mode(dev); 718 - 719 - /* enable vbus override for device mode */ 720 - if (qcom->mode != USB_DR_MODE_HOST) 721 - dwc3_qcom_vbus_override_enable(qcom, true); 722 652 723 653 wakeup_source = of_property_read_bool(dev->of_node, "wakeup-source"); 724 654 device_init_wakeup(&pdev->dev, wakeup_source);