From 39d859b9f942750a6eb58883d651c4f27bb0c4d2 Mon Sep 17 00:00:00 2001 From: Li Jun Date: Wed, 9 Jan 2019 14:52:14 +0530 Subject: [PATCH] MLK-17217 usb: typec: tcpci: system wakeup source support As GPIO normally can be system wakeup source, so enable typec events as system wakeup source if user requested. Acked-by: Peter Chen Signed-off-by: Li Jun Vipul: Fixes for 4.19 kernel. Signed-off-by: Vipul Kumar --- drivers/usb/typec/tcpci.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/usb/typec/tcpci.c b/drivers/usb/typec/tcpci.c index 36017a5a0caf..dd81f3867ca1 100644 --- a/drivers/usb/typec/tcpci.c +++ b/drivers/usb/typec/tcpci.c @@ -25,6 +25,7 @@ struct tcpci { struct device *dev; + struct i2c_client *client; struct extcon_dev *edev; struct tcpm_port *port; @@ -778,6 +779,8 @@ static int tcpci_probe(struct i2c_client *client, if (!chip) return -ENOMEM; + chip->tcpci->client = client; + chip->data.regmap = devm_regmap_init_i2c(client, &tcpci_regmap_config); if (IS_ERR(chip->data.regmap)) return PTR_ERR(chip->data.regmap); @@ -799,6 +802,8 @@ static int tcpci_probe(struct i2c_client *client, if (err < 0) goto err1; + device_set_wakeup_capable(chip->tcpci->dev, true); + return 0; err1: tcpci_unregister_port(chip->tcpci); @@ -814,6 +819,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 }, { } @@ -831,6 +860,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, -- 2.17.1