]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
usb: typec: tcpm/tcpci_maxim: fix irq wake usage
authorAndré Draszik <andre.draszik@linaro.org>
Mon, 7 Jul 2025 10:50:27 +0000 (11:50 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 15 Jul 2025 17:49:57 +0000 (19:49 +0200)
This driver calls enable_irq_wake() during probe() unconditionally, and
never issues the required corresponding disable_irq_wake() to disable
hardware interrupt wakeup signals.

Additionally, whether or not a device should wake-up the system is
meant to be a policy decision based on sysfs (.../power/wakeup) in the
first place.

Update the driver to use the standard approach to enable/disable IRQ
wake during the suspend/resume callbacks. This solves both issues
described above.

Signed-off-by: André Draszik <andre.draszik@linaro.org>
Reviewed-by: Badhri Jagan Sridharan <badhri@google.com>
Link: https://lore.kernel.org/r/20250707-max77759-irq-wake-v1-1-d367f633e4bc@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/typec/tcpm/tcpci_maxim_core.c

index b5a5ed40faea9cfcceef5550263968148646eb44..ff3604be79da73ca5acff7b5b2434c116ed12ef8 100644 (file)
@@ -421,21 +421,6 @@ static irqreturn_t max_tcpci_isr(int irq, void *dev_id)
        return IRQ_WAKE_THREAD;
 }
 
-static int max_tcpci_init_alert(struct max_tcpci_chip *chip, struct i2c_client *client)
-{
-       int ret;
-
-       ret = devm_request_threaded_irq(chip->dev, client->irq, max_tcpci_isr, max_tcpci_irq,
-                                       (IRQF_TRIGGER_LOW | IRQF_ONESHOT), dev_name(chip->dev),
-                                       chip);
-
-       if (ret < 0)
-               return ret;
-
-       enable_irq_wake(client->irq);
-       return 0;
-}
-
 static int max_tcpci_start_toggling(struct tcpci *tcpci, struct tcpci_data *tdata,
                                    enum typec_cc_status cc)
 {
@@ -532,7 +517,9 @@ static int max_tcpci_probe(struct i2c_client *client)
 
        chip->port = tcpci_get_tcpm_port(chip->tcpci);
 
-       ret = max_tcpci_init_alert(chip, client);
+       ret = devm_request_threaded_irq(&client->dev, client->irq, max_tcpci_isr, max_tcpci_irq,
+                                       (IRQF_TRIGGER_LOW | IRQF_ONESHOT), dev_name(chip->dev),
+                                       chip);
        if (ret < 0)
                return dev_err_probe(&client->dev, ret,
                                     "IRQ initialization failed\n");
@@ -544,6 +531,32 @@ static int max_tcpci_probe(struct i2c_client *client)
        return 0;
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int max_tcpci_resume(struct device *dev)
+{
+       struct i2c_client *client = to_i2c_client(dev);
+       int ret = 0;
+
+       if (client->irq && device_may_wakeup(dev))
+               ret = disable_irq_wake(client->irq);
+
+       return ret;
+}
+
+static int max_tcpci_suspend(struct device *dev)
+{
+       struct i2c_client *client = to_i2c_client(dev);
+       int ret = 0;
+
+       if (client->irq && device_may_wakeup(dev))
+               ret = enable_irq_wake(client->irq);
+
+       return ret;
+}
+#endif /* CONFIG_PM_SLEEP */
+
+static SIMPLE_DEV_PM_OPS(max_tcpci_pm_ops, max_tcpci_suspend, max_tcpci_resume);
+
 static const struct i2c_device_id max_tcpci_id[] = {
        { "maxtcpc" },
        { }
@@ -562,6 +575,7 @@ static struct i2c_driver max_tcpci_i2c_driver = {
        .driver = {
                .name = "maxtcpc",
                .of_match_table = of_match_ptr(max_tcpci_of_match),
+               .pm = &max_tcpci_pm_ops,
        },
        .probe = max_tcpci_probe,
        .id_table = max_tcpci_id,