public inbox for linux-can@vger.kernel.org
 help / color / mirror / Atom feed
From: "Eric Bénard" <eric@eukrea.com>
To: linux-can@vger.kernel.org
Cc: "Sascha Hauer" <kernel@pengutronix.de>,
	"Marc Kleine-Budde" <mkl@pengutronix.de>,
	"Wolfgang Grandegger" <wg@grandegger.com>,
	"Eric Bénard" <eric@eukrea.com>
Subject: [PATCH] can: flexcan: add PM support
Date: Tue,  8 May 2012 17:12:17 +0200	[thread overview]
Message-ID: <1336489937-29645-1-git-send-email-eric@eukrea.com> (raw)

tested on an i.MX257

Signed-off-by: Eric Bénard <eric@eukrea.com>
---
 drivers/net/can/flexcan.c |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 1efb083..0d058b0 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -1050,6 +1050,42 @@ static struct of_device_id flexcan_of_match[] = {
 	{},
 };
 
+#ifdef CONFIG_PM
+static int flexcan_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	struct net_device *dev = platform_get_drvdata(pdev);
+	struct flexcan_priv *priv = netdev_priv(dev);
+
+	flexcan_chip_disable(priv);
+
+	if (netif_running(dev)) {
+		netif_stop_queue(dev);
+		netif_device_detach(dev);
+	}
+	priv->can.state = CAN_STATE_SLEEPING;
+
+	return 0;
+}
+
+static int flexcan_resume(struct platform_device *pdev)
+{
+	struct net_device *dev = platform_get_drvdata(pdev);
+	struct flexcan_priv *priv = netdev_priv(dev);
+
+	priv->can.state = CAN_STATE_ERROR_ACTIVE;
+	if (netif_running(dev)) {
+		netif_device_attach(dev);
+		netif_start_queue(dev);
+	}
+	flexcan_chip_enable(priv);
+
+	return 0;
+}
+#else
+#define flexcan_suspend NULL
+#define flexcan_resume NULL
+#endif
+
 static struct platform_driver flexcan_driver = {
 	.driver = {
 		.name = DRV_NAME,
@@ -1058,6 +1094,8 @@ static struct platform_driver flexcan_driver = {
 	},
 	.probe = flexcan_probe,
 	.remove = __devexit_p(flexcan_remove),
+	.suspend = flexcan_suspend,
+	.resume = flexcan_resume,
 };
 
 module_platform_driver(flexcan_driver);
-- 
1.7.7.6


             reply	other threads:[~2012-05-08 15:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-08 15:12 Eric Bénard [this message]
2012-05-08 15:18 ` [PATCH] can: flexcan: add PM support Marc Kleine-Budde
2012-05-08 15:30   ` Eric Bénard
2012-05-08 15:46     ` Marc Kleine-Budde
2012-05-08 17:14       ` Eric Bénard
2012-05-08 17:38         ` Oliver Hartkopp
2012-05-08 18:02           ` Eric Bénard
2012-05-08 18:34           ` Marc Kleine-Budde
2012-05-09  8:16             ` Kurt Van Dijck
2012-05-09 14:35               ` Oliver Hartkopp
2012-05-09 14:53                 ` [PATCH] can: trx support Kurt Van Dijck
2012-05-08 19:09 ` [PATCH] can: flexcan: add PM support Marc Kleine-Budde

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1336489937-29645-1-git-send-email-eric@eukrea.com \
    --to=eric@eukrea.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-can@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=wg@grandegger.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox