mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michael Turquette <mturquette@baylibre.com>
To: linux-clk@vger.kernel.org
Cc: lee.jones@linaro.org, sboyd@codeaurora.org,
	maxime.ripard@free-electrons.com, maxime.coquelin@st.com,
	geert@linux-m68k.org, heiko@sntech.de, andre.przywara@arm.com,
	rklein@nvidia.com, linux-kernel@vger.kernel.org,
	Michael Turquette <mturquette@baylibre.com>
Subject: [PATCH v42 4/6] clk: per-user clk prepare & enable ref counts
Date: Thu, 11 Feb 2016 13:19:12 -0800	[thread overview]
Message-ID: <1455225554-13267-5-git-send-email-mturquette@baylibre.com> (raw)
In-Reply-To: <1455225554-13267-1-git-send-email-mturquette@baylibre.com>

This patch adds prepare and enable reference counts for the per-user
handles that clock consumers have for a clock node. This patch warns if
an imbalance occurs while trying to disable or unprepare a clock and
aborts, leaving the hardware unaffected.

Signed-off-by: Michael Turquette <mturquette@baylibre.com>
---
Changed in v2ish:
  * Fixed locking bug (Thanks Maxime!)

 drivers/clk/clk.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 5181a15..01183e3 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -85,6 +85,8 @@ struct clk {
 	unsigned long min_rate;
 	unsigned long max_rate;
 	struct hlist_node clks_node;
+	unsigned int enable_count;
+	unsigned int prepare_count;
 };
 
 /***           locking             ***/
@@ -609,7 +611,11 @@ void clk_unprepare(struct clk *clk)
 		return;
 
 	clk_prepare_lock();
+	if (WARN_ON(clk->prepare_count == 0))
+		goto out;
+	clk->prepare_count--;
 	clk_core_unprepare(clk->core);
+out:
 	clk_prepare_unlock();
 }
 EXPORT_SYMBOL_GPL(clk_unprepare);
@@ -666,6 +672,7 @@ int clk_prepare(struct clk *clk)
 		return 0;
 
 	clk_prepare_lock();
+	clk->prepare_count++;
 	ret = clk_core_prepare(clk->core);
 	clk_prepare_unlock();
 
@@ -719,7 +726,11 @@ void clk_disable(struct clk *clk)
 		return;
 
 	flags = clk_enable_lock();
+	if (WARN_ON(clk->enable_count == 0))
+		goto out;
+	clk->enable_count--;
 	clk_core_disable(clk->core);
+out:
 	clk_enable_unlock(flags);
 }
 EXPORT_SYMBOL_GPL(clk_disable);
@@ -781,6 +792,7 @@ int clk_enable(struct clk *clk)
 		return 0;
 
 	flags = clk_enable_lock();
+	clk->enable_count++;
 	ret = clk_core_enable(clk->core);
 	clk_enable_unlock(flags);
 
-- 
2.1.4

  parent reply	other threads:[~2016-02-11 21:20 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-11 21:19 [PATCH v42 0/6] critical clocks and handoff clocks Michael Turquette
2016-02-11 21:19 ` [PATCH v42 1/6] clk: Allow clocks to be marked as CRITICAL Michael Turquette
2016-02-12  8:03   ` Lee Jones
2016-02-13  1:14   ` Stephen Boyd
     [not found]     ` <20160215202734.2278.91610@quark.deferred.io>
2016-02-19  2:03       ` Stephen Boyd
2016-02-11 21:19 ` [PATCH v42 2/6] clk: WARN_ON about to disable a critical clock Michael Turquette
2016-02-13  1:14   ` Stephen Boyd
2016-02-11 21:19 ` [PATCH v42 3/6] clk: Provide OF helper to mark clocks as CRITICAL Michael Turquette
2016-02-12  8:02   ` Lee Jones
     [not found]     ` <20160330171542.23150.23031@quark.deferred.io>
2016-03-31  9:14       ` Lee Jones
2016-02-13  1:09   ` Stephen Boyd
2016-02-11 21:19 ` Michael Turquette [this message]
2016-02-13  1:16   ` [PATCH v42 4/6] clk: per-user clk prepare & enable ref counts Stephen Boyd
2016-02-11 21:19 ` [PATCH v42 5/6] clk: clk_put WARNs if user has not disabled clk Michael Turquette
2016-02-13  1:18   ` Stephen Boyd
2016-02-14 14:51     ` Geert Uytterhoeven
2016-02-11 21:19 ` [PATCH v42 6/6] clk: introduce CLK_ENABLE_HAND_OFF flag Michael Turquette
2016-02-12  8:06 ` [PATCH v42 0/6] critical clocks and handoff clocks Lee Jones

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=1455225554-13267-5-git-send-email-mturquette@baylibre.com \
    --to=mturquette@baylibre.com \
    --cc=andre.przywara@arm.com \
    --cc=geert@linux-m68k.org \
    --cc=heiko@sntech.de \
    --cc=lee.jones@linaro.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maxime.coquelin@st.com \
    --cc=maxime.ripard@free-electrons.com \
    --cc=rklein@nvidia.com \
    --cc=sboyd@codeaurora.org \
    /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

all inboxes | Powered by JetHome®