[PATCH 09/11] usb: host: xhci: Add W1C port change quirk for Allwinner A733
From: Alastair D'Silva
Date: Fri Nov 27 2026 - 02:34:00 EST
Allwinner A733 xHCI PORTSC change bits do not clear on write-1-to-clear
when a SuperSpeed device is active. Track cleared bits per port and
sync connection state when reading PORTSC. Use warm port reset on
SuperSpeed port reset.
Signed-off-by: Alastair D'Silva <alastair@xxxxxxxxxxx>
---
drivers/usb/host/xhci-hub.c | 53 +++++++++++++++++++++++++++++++++++-
drivers/usb/host/xhci-plat.c | 3 ++
drivers/usb/host/xhci.h | 2 ++
3 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 55430b673f1e..566cebbd0998 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -623,6 +623,9 @@ static void xhci_clear_port_change_bit(struct xhci_hcd *xhci, u16 wValue, struct
xhci_portsc_writel(port, portsc | status);
portsc = xhci_portsc_readl(port);
+ if (xhci->quirks & XHCI_W1C_PORT_CHANGE_QUIRK)
+ port->cleared_change_bits |= (portsc & status);
+
xhci_dbg(xhci, "clear port%d %s change, portsc: 0x%x\n",
port->hcd_portnum + 1, port_change_bit, portsc);
}
@@ -1122,6 +1125,33 @@ static void xhci_get_usb2_port_status(struct xhci_port *port, u32 *status,
}
}
+static u32 xhci_w1c_filter_portsc(struct xhci_hcd *xhci, struct xhci_port *port,
+ u32 portsc)
+{
+ u32 pls;
+
+ if (!(xhci->quirks & XHCI_W1C_PORT_CHANGE_QUIRK))
+ return portsc;
+
+ /*
+ * Stuck W1C bits prevent new Port Status Change Events after initial
+ * attach, so keep port->connected and port->link_inactive synced here.
+ */
+ pls = portsc & PORT_PLS_MASK;
+ if (!(portsc & PORT_RESET)) {
+ port->link_inactive = (pls == XDEV_INACTIVE);
+ port->connected = !!(portsc & PORT_CONNECT);
+ }
+
+ if (!(portsc & PORT_CONNECT) || pls == XDEV_RXDETECT ||
+ pls == XDEV_DISABLED || pls == XDEV_INACTIVE) {
+ port->cleared_change_bits = 0;
+ return portsc;
+ }
+
+ return portsc & ~port->cleared_change_bits;
+}
+
/*
* Converts a raw xHCI port status into the format that external USB 2.0 or USB
* 3.0 hubs use.
@@ -1138,12 +1168,15 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd, struct xhci_bus_state *bus_
__acquires(&xhci->lock)
{
u32 status = 0;
+ struct xhci_hcd *xhci = hcd_to_xhci(hcd);
struct xhci_hub *rhub;
struct xhci_port *port;
rhub = xhci_get_rhub(hcd);
port = rhub->ports[portnum];
+ portsc = xhci_w1c_filter_portsc(xhci, port, portsc);
+
/* common wPortChange bits */
if (portsc & PORT_CSC)
status |= USB_PORT_STAT_C_CONNECTION << 16;
@@ -1472,7 +1505,21 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
xhci_set_port_power(xhci, port, true, &flags);
break;
case USB_PORT_FEAT_RESET:
- portsc |= PORT_RESET;
+ if (xhci->quirks & XHCI_W1C_PORT_CHANGE_QUIRK) {
+ port->cleared_change_bits &= ~PORT_RC;
+ /*
+ * A733 SuperSpeed ports fail to re-enumerate
+ * after a hot reset; issue a warm reset.
+ */
+ if (hcd->speed >= HCD_USB3) {
+ port->cleared_change_bits &= ~PORT_WRC;
+ portsc |= PORT_WR;
+ } else {
+ portsc |= PORT_RESET;
+ }
+ } else {
+ portsc |= PORT_RESET;
+ }
xhci_portsc_writel(port, portsc);
portsc = xhci_portsc_readl(port);
@@ -1487,6 +1534,8 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
hcd->self.busnum, portnum + 1, portsc);
break;
case USB_PORT_FEAT_BH_PORT_RESET:
+ if (xhci->quirks & XHCI_W1C_PORT_CHANGE_QUIRK)
+ port->cleared_change_bits &= ~PORT_WRC;
portsc |= PORT_WR;
xhci_portsc_writel(port, portsc);
portsc = xhci_portsc_readl(port);
@@ -1667,6 +1716,8 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf)
}
trace_xhci_hub_status_data(ports[i], temp);
+ temp = xhci_w1c_filter_portsc(xhci, ports[i], temp);
+
if ((temp & mask) != 0 ||
(bus_state->port_c_suspend & 1 << i) ||
(ports[i]->resume_timestamp && time_after_eq(
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index 6fd595f81a30..a3307135b3ac 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -277,6 +277,9 @@ int xhci_plat_probe(struct platform_device *pdev, struct device *sysdev, const s
if (device_property_read_bool(tmpdev, "xhci-skip-phy-init-quirk"))
xhci->quirks |= XHCI_SKIP_PHY_INIT;
+ if (device_property_read_bool(tmpdev, "xhci-w1c-port-change-quirk"))
+ xhci->quirks |= XHCI_W1C_PORT_CHANGE_QUIRK;
+
device_property_read_u32(tmpdev, "imod-interval-ns",
&xhci->imod_interval);
device_property_read_u16(tmpdev, "num-hc-interrupters",
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 86a615c6fd2b..70135907e4c0 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1491,6 +1491,7 @@ struct xhci_port {
int slot_id;
struct completion rexit_done;
struct completion u3exit_done;
+ u32 cleared_change_bits;
};
struct xhci_hub {
@@ -1652,6 +1653,7 @@ struct xhci_hcd {
#define XHCI_CDNS_SCTX_QUIRK BIT_ULL(48)
#define XHCI_ETRON_HOST BIT_ULL(49)
#define XHCI_LIMIT_ENDPOINT_INTERVAL_9 BIT_ULL(50)
+#define XHCI_W1C_PORT_CHANGE_QUIRK BIT_ULL(51)
unsigned int num_active_eps;
unsigned int limit_active_eps;
--
2.53.0