Commit b6b640c0 authored by Martin Hundebøll's avatar Martin Hundebøll Committed by Marc Kleine-Budde

can: tcan4x5x: support resuming from rx interrupt signal

Implement the "wakeup-source" device tree property, so the chip is left
running when suspending, and its rx interrupt is used as a wakeup source
to resume operation.
Signed-off-by: default avatarMartin Hundebøll <martin@geanix.com>
Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent 4a94d7e3
...@@ -411,7 +411,7 @@ static int tcan4x5x_can_probe(struct spi_device *spi) ...@@ -411,7 +411,7 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
priv->spi = spi; priv->spi = spi;
mcan_class->pm_clock_support = 0; mcan_class->pm_clock_support = 0;
mcan_class->pm_wake_source = 0; mcan_class->pm_wake_source = device_property_read_bool(&spi->dev, "wakeup-source");
mcan_class->can.clock.freq = freq; mcan_class->can.clock.freq = freq;
mcan_class->dev = &spi->dev; mcan_class->dev = &spi->dev;
mcan_class->ops = &tcan4x5x_ops; mcan_class->ops = &tcan4x5x_ops;
...@@ -460,6 +460,9 @@ static int tcan4x5x_can_probe(struct spi_device *spi) ...@@ -460,6 +460,9 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
goto out_power; goto out_power;
} }
if (mcan_class->pm_wake_source)
device_init_wakeup(&spi->dev, true);
ret = m_can_class_register(mcan_class); ret = m_can_class_register(mcan_class);
if (ret) { if (ret) {
dev_err(&spi->dev, "Failed registering m_can device %pe\n", dev_err(&spi->dev, "Failed registering m_can device %pe\n",
...@@ -488,6 +491,29 @@ static void tcan4x5x_can_remove(struct spi_device *spi) ...@@ -488,6 +491,29 @@ static void tcan4x5x_can_remove(struct spi_device *spi)
m_can_class_free_dev(priv->cdev.net); m_can_class_free_dev(priv->cdev.net);
} }
static int __maybe_unused tcan4x5x_suspend(struct device *dev)
{
struct m_can_classdev *cdev = dev_get_drvdata(dev);
struct spi_device *spi = to_spi_device(dev);
if (cdev->pm_wake_source)
enable_irq_wake(spi->irq);
return m_can_class_suspend(dev);
}
static int __maybe_unused tcan4x5x_resume(struct device *dev)
{
struct m_can_classdev *cdev = dev_get_drvdata(dev);
struct spi_device *spi = to_spi_device(dev);
int ret = m_can_class_resume(dev);
if (cdev->pm_wake_source)
disable_irq_wake(spi->irq);
return ret;
}
static const struct of_device_id tcan4x5x_of_match[] = { static const struct of_device_id tcan4x5x_of_match[] = {
{ {
.compatible = "ti,tcan4x5x", .compatible = "ti,tcan4x5x",
...@@ -506,11 +532,15 @@ static const struct spi_device_id tcan4x5x_id_table[] = { ...@@ -506,11 +532,15 @@ static const struct spi_device_id tcan4x5x_id_table[] = {
}; };
MODULE_DEVICE_TABLE(spi, tcan4x5x_id_table); MODULE_DEVICE_TABLE(spi, tcan4x5x_id_table);
static const struct dev_pm_ops tcan4x5x_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(tcan4x5x_suspend, tcan4x5x_resume)
};
static struct spi_driver tcan4x5x_can_driver = { static struct spi_driver tcan4x5x_can_driver = {
.driver = { .driver = {
.name = KBUILD_MODNAME, .name = KBUILD_MODNAME,
.of_match_table = tcan4x5x_of_match, .of_match_table = tcan4x5x_of_match,
.pm = NULL, .pm = &tcan4x5x_pm_ops,
}, },
.id_table = tcan4x5x_id_table, .id_table = tcan4x5x_id_table,
.probe = tcan4x5x_can_probe, .probe = tcan4x5x_can_probe,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment