linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: bilhuang@nvidia.com (Bill Huang)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC 1/1] clk: Add notifier support in clk_prepare_enable/clk_disable_unprepare
Date: Tue, 12 Mar 2013 05:37:41 -0700	[thread overview]
Message-ID: <1363091861-21534-1-git-send-email-bilhuang@nvidia.com> (raw)

Add the below four notifier events so drivers which are interested in
knowing the clock status can act accordingly. This is extremely useful
in some of the DVFS (Dynamic Voltage Frequency Scaling) design.

PRE_CLK_ENABLE
POST_CLK_ENABLE
PRE_CLK_DISABLE
POST_CLK_DISABLE

Signed-off-by: Bill Huang <bilhuang@nvidia.com>
---
 drivers/clk/clk.c   |   58 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/clk.h |   40 ++++++++++++++++++++---------------
 2 files changed, 81 insertions(+), 17 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index ed87b24..720a16a 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -1104,6 +1104,64 @@ struct clk *clk_get_parent(struct clk *clk)
 }
 EXPORT_SYMBOL_GPL(clk_get_parent);
 
+/**
+ * clk_prepare_enable - call clk_enable in non-atomic context.
+ * @clk: the clk to enable
+ *
+ * Send PRE_CLK_ENABLE/POST_CLK_ENABLE before/after calling
+ * clk_enalbe respectively
+ *
+ * Return success (0) or errno.
+ */
+int clk_prepare_enable(struct clk *clk)
+{
+	int ret;
+
+	mutex_lock(&prepare_lock);
+	ret = __clk_prepare(clk);
+	if (ret)
+		return ret;
+
+	if (clk->notifier_count)
+		__clk_notify(clk, PRE_CLK_ENABLE, clk->rate, clk->rate);
+
+	ret = clk_enable(clk);
+	if (ret)
+		__clk_unprepare(clk);
+
+	if (clk->notifier_count)
+		__clk_notify(clk, POST_CLK_ENABLE, clk->rate, clk->rate);
+
+	mutex_unlock(&prepare_lock);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(clk_prepare_enable);
+
+/**
+ * clk_disable_unprepare - call clk_disable in non-atomic context.
+ * @clk: the clk to enable
+ *
+ * Send PRE_CLK_DISABLE/POST_CLK_DISABLE before/after calling
+ * clk_disalbe respectively
+ */
+void clk_disable_unprepare(struct clk *clk)
+{
+	mutex_lock(&prepare_lock);
+
+	if (clk->notifier_count)
+		__clk_notify(clk, PRE_CLK_DISABLE, clk->rate, clk->rate);
+
+	clk_disable(clk);
+	__clk_unprepare(clk);
+
+	if (clk->notifier_count)
+		__clk_notify(clk, POST_CLK_DISABLE, clk->rate, clk->rate);
+
+	mutex_unlock(&prepare_lock);
+}
+EXPORT_SYMBOL_GPL(clk_disable_unprepare);
+
 /*
  * .get_parent is mandatory for clocks with multiple possible parents.  It is
  * optional for single-parent clocks.  Always call .get_parent if it is
diff --git a/include/linux/clk.h b/include/linux/clk.h
index b3ac22d..4bbe1903 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -43,6 +43,10 @@ struct clk;
 #define PRE_RATE_CHANGE			BIT(0)
 #define POST_RATE_CHANGE		BIT(1)
 #define ABORT_RATE_CHANGE		BIT(2)
+#define PRE_CLK_ENABLE			BIT(3)
+#define POST_CLK_ENABLE			BIT(4)
+#define PRE_CLK_DISABLE			BIT(5)
+#define POST_CLK_DISABLE		BIT(6)
 
 /**
  * struct clk_notifier - associate a clk with a notifier
@@ -276,6 +280,20 @@ struct clk *clk_get_parent(struct clk *clk);
  */
 struct clk *clk_get_sys(const char *dev_id, const char *con_id);
 
+/**
+ * clk_prepare_enable - helps cases using clk_enable in non-atomic context.
+ * @clk: clock source
+ *
+ * Return success (0) or nagative errno.
+ */
+int clk_prepare_enable(struct clk *clk);
+
+/**
+ * clk_disable_unprepare - helps cases using clk_disable in non-atomic context.
+ * @clk: clock source
+ */
+void clk_disable_unprepare(struct clk *clk);
+
 #else /* !CONFIG_HAVE_CLK */
 
 static inline struct clk *clk_get(struct device *dev, const char *id)
@@ -324,30 +342,18 @@ static inline struct clk *clk_get_parent(struct clk *clk)
 	return NULL;
 }
 
-#endif
-
-/* clk_prepare_enable helps cases using clk_enable in non-atomic context. */
 static inline int clk_prepare_enable(struct clk *clk)
 {
-	int ret;
-
-	ret = clk_prepare(clk);
-	if (ret)
-		return ret;
-	ret = clk_enable(clk);
-	if (ret)
-		clk_unprepare(clk);
-
-	return ret;
+	return 0;
 }
 
-/* clk_disable_unprepare helps cases using clk_disable in non-atomic context. */
-static inline void clk_disable_unprepare(struct clk *clk)
+static inline int clk_disable_unprepare(struct clk *clk)
 {
-	clk_disable(clk);
-	clk_unprepare(clk);
+	return 0;
 }
 
+#endif
+
 /**
  * clk_add_alias - add a new clock alias
  * @alias: name for clock alias
-- 
1.7.9.5

             reply	other threads:[~2013-03-12 12:37 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-12 12:37 Bill Huang [this message]
2013-03-12 13:40 ` [RFC 1/1] clk: Add notifier support in clk_prepare_enable/clk_disable_unprepare Russell King - ARM Linux
2013-03-13  1:47   ` Bill Huang
2013-03-13  4:42     ` Stephen Warren
2013-03-13  5:08       ` Bill Huang
2013-03-13  5:24         ` Stephen Warren
2013-03-13  5:40           ` Bill Huang
2013-03-13 18:10             ` Stephen Warren
2013-03-14  2:15               ` Bill Huang
2013-03-14  9:21                 ` Peter De Schrijver
2013-03-14  9:28                   ` Bill Huang
2013-03-14 17:54                     ` Stephen Warren
2013-03-15  1:20                       ` Bill Huang
2013-03-15  5:22                         ` Stephen Warren
2013-03-15  5:48                           ` Bill Huang
2013-03-15  9:39                           ` Peter De Schrijver
2013-03-15 10:08                             ` Ulf Hansson
2013-03-15 12:06                               ` Bill Huang
2013-03-15 12:33                                 ` Ulf Hansson
2013-03-15 19:38                                   ` Stephen Warren
2013-03-16  1:54                                     ` Bill Huang
2013-03-18 10:36                                     ` Ulf Hansson
2013-03-21 22:28                                       ` Mike Turquette
2013-03-16  2:23                                   ` Bill Huang
2013-03-15 17:12                           ` Russell King - ARM Linux
2013-03-15 17:09             ` Russell King - ARM Linux
2013-03-16  2:25               ` Bill Huang
2013-03-15 16:59       ` Russell King - ARM Linux
2013-03-15 16:57     ` Russell King - ARM Linux
2013-03-15 18:44       ` Nicolas Pitre

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=1363091861-21534-1-git-send-email-bilhuang@nvidia.com \
    --to=bilhuang@nvidia.com \
    --cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).