Commit 24033573 authored by Marc Kleine-Budde's avatar Marc Kleine-Budde

Merge patch series "can: tcan4x5x: support resume upon rx can frame"

Martin Hundebøll <martin@geanix.com> says:

This is the third iteration of the previous submitted patches [0] and
[1].

This revision replaces the "wake_source" function parameters to a flag
in the class device structure, and adds a patch to document the
"wakeup-source" device tree property.

Also, the previous revisions forgot to mention that the patches are
based on Markus' coalescing patches [2]. Those implements caching of
the enabled interrupts, which is handy when restoring the set of
interrupts in the resume path.

[0] https://lore.kernel.org/linux-can/20230912093807.1383720-1-martin@geanix.com
[1] https://lore.kernel.org/linux-can/20230919122841.3803289-1-martin@geanix.com
[2] https://lore.kernel.org/linux-can/20230929141304.3934380-1-msp@baylibre.com

Link: https://lore.kernel.org/all/20231113131452.214961-1-martin@geanix.comSigned-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parents e517293f b6b640c0
...@@ -28,6 +28,8 @@ Optional properties: ...@@ -28,6 +28,8 @@ Optional properties:
available with tcan4552/4553. available with tcan4552/4553.
- device-wake-gpios: Wake up GPIO to wake up the TCAN device. Not - device-wake-gpios: Wake up GPIO to wake up the TCAN device. Not
available with tcan4552/4553. available with tcan4552/4553.
- wakeup-source: Leave the chip running when suspended, and configure
the RX interrupt to wake up the device.
Example: Example:
tcan4x5x: tcan4x5x@0 { tcan4x5x: tcan4x5x@0 {
...@@ -42,4 +44,5 @@ tcan4x5x: tcan4x5x@0 { ...@@ -42,4 +44,5 @@ tcan4x5x: tcan4x5x@0 {
device-state-gpios = <&gpio3 21 GPIO_ACTIVE_HIGH>; device-state-gpios = <&gpio3 21 GPIO_ACTIVE_HIGH>;
device-wake-gpios = <&gpio1 15 GPIO_ACTIVE_HIGH>; device-wake-gpios = <&gpio1 15 GPIO_ACTIVE_HIGH>;
reset-gpios = <&gpio1 27 GPIO_ACTIVE_HIGH>; reset-gpios = <&gpio1 27 GPIO_ACTIVE_HIGH>;
wakeup-source;
}; };
...@@ -2382,7 +2382,15 @@ int m_can_class_suspend(struct device *dev) ...@@ -2382,7 +2382,15 @@ int m_can_class_suspend(struct device *dev)
if (netif_running(ndev)) { if (netif_running(ndev)) {
netif_stop_queue(ndev); netif_stop_queue(ndev);
netif_device_detach(ndev); netif_device_detach(ndev);
m_can_stop(ndev);
/* leave the chip running with rx interrupt enabled if it is
* used as a wake-up source.
*/
if (cdev->pm_wake_source)
m_can_write(cdev, M_CAN_IE, IR_RF0N);
else
m_can_stop(ndev);
m_can_clk_stop(cdev); m_can_clk_stop(cdev);
} }
...@@ -2409,11 +2417,15 @@ int m_can_class_resume(struct device *dev) ...@@ -2409,11 +2417,15 @@ int m_can_class_resume(struct device *dev)
ret = m_can_clk_start(cdev); ret = m_can_clk_start(cdev);
if (ret) if (ret)
return ret; return ret;
ret = m_can_start(ndev);
if (ret) {
m_can_clk_stop(cdev);
return ret; if (cdev->pm_wake_source) {
m_can_write(cdev, M_CAN_IE, cdev->active_interrupts);
} else {
ret = m_can_start(ndev);
if (ret) {
m_can_clk_stop(cdev);
return ret;
}
} }
netif_device_attach(ndev); netif_device_attach(ndev);
......
...@@ -97,6 +97,7 @@ struct m_can_classdev { ...@@ -97,6 +97,7 @@ struct m_can_classdev {
u32 irqstatus; u32 irqstatus;
int pm_clock_support; int pm_clock_support;
int pm_wake_source;
int is_peripheral; int is_peripheral;
// Cached M_CAN_IE register content // Cached M_CAN_IE register content
......
...@@ -125,6 +125,7 @@ static int m_can_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) ...@@ -125,6 +125,7 @@ static int m_can_pci_probe(struct pci_dev *pci, const struct pci_device_id *id)
mcan_class->dev = &pci->dev; mcan_class->dev = &pci->dev;
mcan_class->net->irq = pci_irq_vector(pci, 0); mcan_class->net->irq = pci_irq_vector(pci, 0);
mcan_class->pm_clock_support = 1; mcan_class->pm_clock_support = 1;
mcan_class->pm_wake_source = 0;
mcan_class->can.clock.freq = id->driver_data; mcan_class->can.clock.freq = id->driver_data;
mcan_class->ops = &m_can_pci_ops; mcan_class->ops = &m_can_pci_ops;
......
...@@ -139,6 +139,7 @@ static int m_can_plat_probe(struct platform_device *pdev) ...@@ -139,6 +139,7 @@ static int m_can_plat_probe(struct platform_device *pdev)
mcan_class->net->irq = irq; mcan_class->net->irq = irq;
mcan_class->pm_clock_support = 1; mcan_class->pm_clock_support = 1;
mcan_class->pm_wake_source = 0;
mcan_class->can.clock.freq = clk_get_rate(mcan_class->cclk); mcan_class->can.clock.freq = clk_get_rate(mcan_class->cclk);
mcan_class->dev = &pdev->dev; mcan_class->dev = &pdev->dev;
mcan_class->transceiver = transceiver; mcan_class->transceiver = transceiver;
......
...@@ -411,6 +411,7 @@ static int tcan4x5x_can_probe(struct spi_device *spi) ...@@ -411,6 +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 = 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;
...@@ -459,6 +460,9 @@ static int tcan4x5x_can_probe(struct spi_device *spi) ...@@ -459,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",
...@@ -487,6 +491,29 @@ static void tcan4x5x_can_remove(struct spi_device *spi) ...@@ -487,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",
...@@ -505,11 +532,15 @@ static const struct spi_device_id tcan4x5x_id_table[] = { ...@@ -505,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