From patchwork Fri May 5 13:50:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 98637 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp133383qge; Fri, 5 May 2017 06:51:03 -0700 (PDT) X-Received: by 10.98.152.65 with SMTP id q62mr7881619pfd.256.1493992263699; Fri, 05 May 2017 06:51:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1493992263; cv=none; d=google.com; s=arc-20160816; b=tXX1mpnV4GqN/VCo4wvxFfWwz6N6KYW1Y0z6TgBBtztx1WpQY9Wo+kc1R6/vEUB3To wfoOG7PcPU5+TU9Y6WN3CDVVyekz2lhmkCHQo1wEnhasN7ZGS5krOwwNs16qmaRRbRiL eXfJAGEGl/e3tqW4rWuvinq1EH5ZUxyNxeUc2ndncrZptzarkgAmqIHQhZwniHChQ1eT A0ZmxC97htlMxZPwTQfZhVfrH+Ez0S/6oqFW5O/w9TaajAmwTeXaQf7uR6nN96Fy6XLb H7UQc4waVJSiitIUwBzCbbOTMABGHokgTfGZ+znT77y6n9Zy2NjTbSbDVfMas4MnniKl EAyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=yjtFrFwJGkEXM5Ib3LON0/kcd3exB5K+3arJbS3Oo1Q=; b=Injeq8vHpPZGZ2FN6iN2ReUnrTD8QZkjeYvnOrWhP729oPsYYZtmqkwh3HUCIc1qKG 3EgiDqQxPtm48aiWXf4OkP7t+BeBP71DDolJb0i4kp3jNk2yoQHQxIxnVj0kBoYUPFqe WwFCLBBhe75d+fKIJPbLD2A/TsRZiqdY4+rvBl9kymh8A2yWWs0Kl6v0Snl3Yus01U9A m/hRXJY12BZToLs5ehbXHJG9iPnyQ+qxSs4hVSNqT/QaPSIh9bORloppQEdajt/oMZ7v 9AZWTxSqTpkUNjTrgwLaAnep+yYDSLISBX8pekoZBe5E/Dvhvzc3GpIMVPBOmVWrrS+Y iP3Q== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b12si5826158plm.77.2017.05.05.06.51.03; Fri, 05 May 2017 06:51:03 -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 S1754870AbdEENus (ORCPT + 25 others); Fri, 5 May 2017 09:50:48 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:59982 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752699AbdEENuo (ORCPT ); Fri, 5 May 2017 09:50:44 -0400 Received: by mail.free-electrons.com (Postfix, from userid 110) id 71B0E212E7; Fri, 5 May 2017 15:50:42 +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 33CD8207E1; Fri, 5 May 2017 15:50:42 +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 v4 3/4] can: m_can: factorize clock gating and ungating Date: Fri, 5 May 2017 15:50:32 +0200 Message-Id: <20170505135033.8349-3-quentin.schulz@free-electrons.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170505135033.8349-1-quentin.schulz@free-electrons.com> References: <20170505135033.8349-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 creates a function to ungate M_CAN clocks and another to gate the same clocks, then swaps all gating/ungating code with their respective function. Signed-off-by: Quentin Schulz --- added in v4 drivers/net/can/m_can/m_can.c | 45 +++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 19 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 6115dede671e..653b304d7091 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -621,10 +621,8 @@ static int __m_can_get_berr_counter(const struct net_device *dev, return 0; } -static int m_can_get_berr_counter(const struct net_device *dev, - struct can_berr_counter *bec) +static int m_can_clk_start(struct m_can_priv *priv) { - struct m_can_priv *priv = netdev_priv(dev); int err; err = clk_prepare_enable(priv->hclk); @@ -632,15 +630,31 @@ static int m_can_get_berr_counter(const struct net_device *dev, return err; err = clk_prepare_enable(priv->cclk); - if (err) { + if (err) clk_disable_unprepare(priv->hclk); - return err; - } - __m_can_get_berr_counter(dev, bec); + return err; +} +static void m_can_clk_stop(struct m_can_priv *priv) +{ clk_disable_unprepare(priv->cclk); clk_disable_unprepare(priv->hclk); +} + +static int m_can_get_berr_counter(const struct net_device *dev, + struct can_berr_counter *bec) +{ + struct m_can_priv *priv = netdev_priv(dev); + int err; + + err = m_can_clk_start(priv); + if (err) + return err; + + __m_can_get_berr_counter(dev, bec); + + m_can_clk_stop(priv); return 0; } @@ -1276,19 +1290,15 @@ static int m_can_open(struct net_device *dev) struct m_can_priv *priv = netdev_priv(dev); int err; - err = clk_prepare_enable(priv->hclk); + err = m_can_clk_start(priv); if (err) return err; - err = clk_prepare_enable(priv->cclk); - if (err) - goto exit_disable_hclk; - /* open the can device */ err = open_candev(dev); if (err) { netdev_err(dev, "failed to open can device\n"); - goto exit_disable_cclk; + goto exit_disable_clks; } /* register interrupt handler */ @@ -1310,10 +1320,8 @@ static int m_can_open(struct net_device *dev) exit_irq_fail: close_candev(dev); -exit_disable_cclk: - clk_disable_unprepare(priv->cclk); -exit_disable_hclk: - clk_disable_unprepare(priv->hclk); +exit_disable_clks: + m_can_clk_stop(priv); return err; } @@ -1335,8 +1343,7 @@ static int m_can_close(struct net_device *dev) netif_stop_queue(dev); napi_disable(&priv->napi); m_can_stop(dev); - clk_disable_unprepare(priv->hclk); - clk_disable_unprepare(priv->cclk); + m_can_clk_stop(priv); free_irq(dev->irq, dev); close_candev(dev); can_led_event(dev, CAN_LED_EVENT_STOP);