On suspend, dwc3_qcom_enable_wakeup_irq() sets the DP and DM high-speed PHY interrupts to a single edge, chosen from the speed of the attached device. The IRQ mapping outlives the driver, so after an unbind the mapping keeps that single-edge type. On the next probe the interrupt is looked up again from the device tree, which describes it as IRQ_TYPE_EDGE_BOTH. The lookup fails with a trigger type mismatch against the existing mapping. Because the wake interrupts are optional, probe still succeeds, but without the DP/DM wake handlers, and USB wakeup is lost until the next boot. Record the trigger type of each DP/DM interrupt when it is requested and restore it from a devres action. The action is registered after the interrupts, so it runs while the driver still owns them. Unmapped interrupts, unspecified types and types that already match are left alone. Seen on a Microsoft Surface Laptop 7 (x1e80100-microsoft-romulus15) on a 7.3 kernel: after unbinding and rebinding a controller the dp_hs_phy_irq and dm_hs_phy_irq handlers were absent from /proc/interrupts. With this change they return on every rebind. Fixes: 6895ea55c385 ("usb: dwc3: qcom: Configure wakeup interrupts during suspend") Cc: stable@vger.kernel.org Signed-off-by: Felipe Infante de Castro --- Changes in v3: - Renamed the new fields to dp_hs_phy_irq_type and dm_hs_phy_irq_type, to match the existing dp_hs_phy_irq and dm_hs_phy_irq (Peter Chen). - Added Cc: stable (Peter Chen). - Sent inline; v1 and v2 went out as attachments. Changes in v2: - Resent with an empty mail body. - Added the Fixes tag suggested by the Sashiko review. drivers/usb/dwc3/dwc3-qcom.c | 38 +++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index a260841..548d69b 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -65,6 +65,8 @@ struct dwc3_qcom_port { int dp_hs_phy_irq; int dm_hs_phy_irq; int ss_phy_irq; + unsigned int dp_hs_phy_irq_type; + unsigned int dm_hs_phy_irq_type; enum usb_device_speed usb2_speed; }; @@ -473,6 +475,7 @@ static int dwc3_qcom_setup_port_irq(struct dwc3_qcom *qcom, if (ret) return ret; qcom->ports[port_index].dp_hs_phy_irq = irq; + qcom->ports[port_index].dp_hs_phy_irq_type = irq_get_trigger_type(irq); } if (is_multiport) @@ -488,6 +491,7 @@ static int dwc3_qcom_setup_port_irq(struct dwc3_qcom *qcom, if (ret) return ret; qcom->ports[port_index].dm_hs_phy_irq = irq; + qcom->ports[port_index].dm_hs_phy_irq_type = irq_get_trigger_type(irq); } if (is_multiport) @@ -540,6 +544,38 @@ static int dwc3_qcom_find_num_ports(struct platform_device *pdev) return DWC3_QCOM_MAX_PORTS; } +static void dwc3_qcom_restore_irq_type(struct device *dev, int irq, unsigned int type) +{ + int ret; + + if (!irq || !type || irq_get_trigger_type(irq) == type) + return; + + ret = irq_set_irq_type(irq, type); + if (ret) + dev_warn(dev, "failed to restore IRQ %d trigger type %#x: %d\n", + irq, type, ret); +} + +static void dwc3_qcom_restore_wake_irq_types(void *data) +{ + struct dwc3_qcom *qcom = data; + int i; + + /* + * The IRQ mappings survive unbind. Put their firmware triggers back + * before devres frees the handlers or the next probe can lose them. + */ + for (i = 0; i < qcom->num_ports; i++) { + struct dwc3_qcom_port *port = &qcom->ports[i]; + + dwc3_qcom_restore_irq_type(qcom->dev, port->dp_hs_phy_irq, + port->dp_hs_phy_irq_type); + dwc3_qcom_restore_irq_type(qcom->dev, port->dm_hs_phy_irq, + port->dm_hs_phy_irq_type); + } +} + static int dwc3_qcom_setup_irq(struct dwc3_qcom *qcom, struct platform_device *pdev) { bool is_multiport; @@ -555,7 +591,7 @@ static int dwc3_qcom_setup_irq(struct dwc3_qcom *qcom, struct platform_device *p return ret; } - return 0; + return devm_add_action_or_reset(qcom->dev, dwc3_qcom_restore_wake_irq_types, qcom); } static void dwc3_qcom_set_role_notifier(struct dwc3 *dwc, enum usb_role next_role) -- 2.56.1