[PATCH RFC 2/2] usb: dwc3: qcom: Vote ICC DDR bandwidth based on connected device speed
From: Krishna Kurapati
Date: Mon Nov 30 2026 - 12:41:49 EST
In host mode the actual transfer speed is not known at probe time. The
DDR interconnect bandwidth has historically been voted at the maximum
(SuperSpeed) value unconditionally, wasting power when only a
Full/High-Speed device is attached.
Add a USB notifier that fires on USB_DEVICE_ADD / USB_DEVICE_REMOVE for
devices directly attached to the DWC3 root hub. On addition, inspect
all USB 3.x root-hub ports via xhci_portsc_readl(). If at least one
SuperSpeed connection is active, vote SS bandwidth, otherwise vote HS
bandwidth. On removal, drop the vote back to the idle/unknown level.
The notifier is registered when the role transitions to host (or already
is host at probe) and unregistered when the role leaves host or the
device is removed.
Signed-off-by: Krishna Kurapati <krishna.kurapati@xxxxxxxxxxxxxxxx>
---
drivers/usb/dwc3/dwc3-qcom.c | 88 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 87 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
index 52ec7a0709ef..fdec21b30420 100644
--- a/drivers/usb/dwc3/dwc3-qcom.c
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -21,6 +21,9 @@
#include <linux/usb.h>
#include "core.h"
#include "glue.h"
+#include "../host/xhci.h"
+#include "../host/xhci-port.h"
+#include "../host/xhci-caps.h"
/* USB QSCRATCH Hardware registers */
#define QSCRATCH_HS_PHY_CTRL 0x10
@@ -86,6 +89,7 @@ struct dwc3_qcom {
enum usb_role current_role;
bool has_eusb2_phy;
+ struct notifier_block host_nb;
};
#define to_dwc3_qcom(d) container_of((d), struct dwc3_qcom, dwc)
@@ -597,6 +601,74 @@ static int dwc3_qcom_setup_irq(struct dwc3_qcom *qcom, struct platform_device *p
return 0;
}
+static bool dwc3_qcom_is_ss_rhport_connected(struct dwc3_qcom *qcom)
+{
+ struct dwc3 *dwc = &qcom->dwc;
+ struct xhci_hcd *xhci;
+ struct usb_hcd *hcd;
+ unsigned int i;
+ u32 portsc;
+
+ if (!dwc->xhci)
+ return false;
+
+ hcd = platform_get_drvdata(dwc->xhci);
+ xhci = hcd_to_xhci(hcd);
+
+ for (i = 0; i < xhci->usb3_rhub.num_ports; i++) {
+ portsc = xhci_portsc_readl(xhci->usb3_rhub.ports[i]);
+ if ((portsc & PORT_CONNECT) && DEV_SUPERSPEED_ANY(portsc))
+ return true;
+ }
+
+ return false;
+}
+
+static int dwc3_qcom_host_notifier(struct notifier_block *nb,
+ unsigned long event, void *ptr)
+{
+ struct dwc3_qcom *qcom = container_of(nb, struct dwc3_qcom, host_nb);
+ struct dwc3 *dwc = &qcom->dwc;
+ struct usb_device *udev = ptr;
+ struct usb_bus *ubus = ptr;
+
+ if (!dwc || !dwc->xhci)
+ return NOTIFY_DONE;
+
+ if (event == USB_DEVICE_ADD || event == USB_DEVICE_REMOVE)
+ ubus = udev->bus;
+
+ if (strcmp(dev_name(ubus->sysdev), dev_name(dwc->sysdev)) != 0)
+ return NOTIFY_DONE;
+
+ if (event != USB_DEVICE_ADD && event != USB_DEVICE_REMOVE)
+ return NOTIFY_DONE;
+
+ /*
+ * For direct-attach devices, new udev is direct child of root hub
+ * i.e. dwc -> xhci -> root_hub -> udev
+ * root_hub's udev->parent==NULL, so traverse struct device hierarchy
+ */
+ if (udev->parent && !udev->parent->parent &&
+ udev->dev.parent->parent == &dwc->xhci->dev) {
+ if (event == USB_DEVICE_ADD) {
+ if (!dwc3_qcom_is_ss_rhport_connected(qcom)) {
+ dwc3_qcom_interconnect_set_ddr_bw(qcom,
+ USB_SPEED_HIGH);
+
+ } else {
+ dwc3_qcom_interconnect_set_ddr_bw(qcom,
+ USB_SPEED_SUPER);
+ }
+ } else {
+ dwc3_qcom_interconnect_set_ddr_bw(qcom,
+ USB_SPEED_UNKNOWN);
+ }
+ }
+
+ return NOTIFY_DONE;
+}
+
static void dwc3_qcom_set_role_notifier(struct dwc3 *dwc, enum usb_role next_role)
{
struct dwc3_qcom *qcom = to_dwc3_qcom(dwc);
@@ -617,6 +689,13 @@ static void dwc3_qcom_set_role_notifier(struct dwc3 *dwc, enum usb_role next_rol
pm_runtime_mark_last_busy(qcom->dev);
pm_runtime_put_sync(qcom->dev);
+ if (next_role == USB_ROLE_HOST) {
+ qcom->host_nb.notifier_call = dwc3_qcom_host_notifier;
+ usb_register_notify(&qcom->host_nb);
+ } else if (qcom->current_role == USB_ROLE_HOST) {
+ usb_unregister_notify(&qcom->host_nb);
+ }
+
/*
* Current role changes via usb_role_switch_set_role callback protected
* internally by mutex lock.
@@ -749,8 +828,12 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
qcom->current_role = USB_ROLE_DEVICE;
}
- qcom->dwc.glue_ops = &dwc3_qcom_glue_ops;
+ if (qcom->current_role == USB_ROLE_HOST) {
+ qcom->host_nb.notifier_call = dwc3_qcom_host_notifier;
+ usb_register_notify(&qcom->host_nb);
+ }
+ qcom->dwc.glue_ops = &dwc3_qcom_glue_ops;
qcom->dwc.dev = dev;
probe_data.dwc = &qcom->dwc;
probe_data.res = &res;
@@ -789,6 +872,9 @@ static void dwc3_qcom_remove(struct platform_device *pdev)
if (pm_runtime_resume_and_get(qcom->dev) < 0)
return;
+ if (qcom->current_role == USB_ROLE_HOST)
+ usb_unregister_notify(&qcom->host_nb);
+
dwc3_core_remove(&qcom->dwc);
clk_bulk_disable_unprepare(qcom->num_clocks, qcom->clks);
dwc3_qcom_interconnect_exit(qcom);
--
2.34.1