From patchwork Fri May 5 11:46:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 98619 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp77636qge; Fri, 5 May 2017 04:49:00 -0700 (PDT) X-Received: by 10.98.65.69 with SMTP id o66mr16210654pfa.221.1493984940663; Fri, 05 May 2017 04:49:00 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q11si1640195pgc.299.2017.05.05.04.49.00; Fri, 05 May 2017 04:49:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752183AbdEELsi (ORCPT + 25 others); Fri, 5 May 2017 07:48:38 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:57628 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751180AbdEELsg (ORCPT ); Fri, 5 May 2017 07:48:36 -0400 Received: by mail.free-electrons.com (Postfix, from userid 110) id 748B7212E0; Fri, 5 May 2017 13:48:34 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost.localdomain (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 35162212DF; Fri, 5 May 2017 13:48:34 +0200 (CEST) From: Quentin Schulz To: wg@grandegger.com, mkl@pengutronix.de, mario.huettel@gmx.net, socketcan@hartkopp.net Cc: Quentin Schulz , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, alexandre.belloni@free-electrons.com, thomas.petazzoni@free-electrons.com Subject: [PATCH v3 2/2] can: m_can: add deep Suspend/Resume support Date: Fri, 5 May 2017 13:46:46 +0200 Message-Id: <20170505114646.1278-2-quentin.schulz@free-electrons.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170505114646.1278-1-quentin.schulz@free-electrons.com> References: <20170505114646.1278-1-quentin.schulz@free-electrons.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds Power Management deep Suspend/Resume support for Bosch M_CAN chip. When entering deep sleep, the clocks are gated, the interrupts are disabled. When resuming from deep sleep, the chip needs to be reinitialized, the clocks ungated and the interrupts enabled. Signed-off-by: Quentin Schulz --- v3: - do not close/reopen the can interface (which was previously done when calling m_can_close), basically do the same routine as in probe but it does not close/open the can device, - update commit log, v2: - fix erroneous commit log, drivers/net/can/m_can/m_can.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) -- 2.11.0 diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 3f0445440146..0a06690febe2 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -1672,10 +1672,9 @@ static __maybe_unused int m_can_suspend(struct device *dev) if (netif_running(ndev)) { netif_stop_queue(ndev); netif_device_detach(ndev); + m_can_stop(ndev); } - /* TODO: enter low power */ - priv->can.state = CAN_STATE_SLEEPING; return 0; @@ -1686,11 +1685,23 @@ static __maybe_unused int m_can_resume(struct device *dev) struct net_device *ndev = dev_get_drvdata(dev); struct m_can_priv *priv = netdev_priv(ndev); - /* TODO: exit low power */ + m_can_init_ram(priv); priv->can.state = CAN_STATE_ERROR_ACTIVE; if (netif_running(ndev)) { + int ret = clk_prepare_enable(priv->hclk); + + if (ret) + return ret; + + ret = clk_prepare_enable(priv->cclk); + if (ret) { + clk_disable_unprepare(priv->hclk); + return ret; + } + + m_can_start(ndev); netif_device_attach(ndev); netif_start_queue(ndev); }