MLK-17217 staging: typec: tcpci: system wakeup source support
authorLi Jun <jun.li@nxp.com>
Thu, 14 Dec 2017 17:03:32 +0000 (01:03 +0800)
committerNitin Garg <nitin.garg@nxp.com>
Tue, 20 Mar 2018 19:51:32 +0000 (14:51 -0500)
As GPIO normally can be system wakeup source, so enable typec events
as system wakeup source if user requested.

Acked-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
drivers/staging/typec/tcpci.c

index 1a31a5e..05c8e2b 100644 (file)
@@ -824,6 +824,8 @@ static int tcpci_probe(struct i2c_client *client,
        if (err < 0)
                goto err1;
 
+       device_set_wakeup_capable(tcpci->dev, true);
+
        return 0;
 err1:
        tcpm_unregister_port(tcpci->port);
@@ -839,6 +841,30 @@ static int tcpci_remove(struct i2c_client *client)
        return 0;
 }
 
+static int tcpci_suspend(struct device *dev)
+{
+       struct tcpci *tcpci = dev_get_drvdata(dev);
+
+       if (device_may_wakeup(dev))
+               enable_irq_wake(tcpci->client->irq);
+
+       return 0;
+}
+
+static int tcpci_resume(struct device *dev)
+{
+       struct tcpci *tcpci = dev_get_drvdata(dev);
+
+       if (device_may_wakeup(dev))
+               disable_irq_wake(tcpci->client->irq);
+
+       return 0;
+}
+
+static const struct dev_pm_ops tcpci_pm_ops = {
+       SET_SYSTEM_SLEEP_PM_OPS(tcpci_suspend, tcpci_resume)
+};
+
 static const struct i2c_device_id tcpci_id[] = {
        { "tcpci", 0 },
        { }
@@ -856,6 +882,7 @@ MODULE_DEVICE_TABLE(of, tcpci_of_match);
 static struct i2c_driver tcpci_i2c_driver = {
        .driver = {
                .name = "tcpci",
+               .pm = &tcpci_pm_ops,
                .of_match_table = of_match_ptr(tcpci_of_match),
        },
        .probe = tcpci_probe,