Linux-Clk Archive on lore.kernel.org
 help / color / Atom feed
From: Jerome Brunet <jbrunet@baylibre.com>
To: Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>
Cc: Jerome Brunet <jbrunet@baylibre.com>,
	Kevin Hilman <khilman@baylibre.com>,
	linux-clk@vger.kernel.org
Subject: [PATCH RFC 5/5] clk: meson: sclk-div: use runtime data
Date: Wed, 28 Aug 2019 12:20:12 +0200
Message-ID: <20190828102012.4493-6-jbrunet@baylibre.com> (raw)
In-Reply-To: <20190828102012.4493-1-jbrunet@baylibre.com>

Remove the sclk-div runtime data from the clock description structure
and use the per clock placeholder to save the these runtime data.

Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
---
 drivers/clk/meson/sclk-div.c | 68 ++++++++++++++++++++++++++----------
 drivers/clk/meson/sclk-div.h |  2 --
 2 files changed, 49 insertions(+), 21 deletions(-)

diff --git a/drivers/clk/meson/sclk-div.c b/drivers/clk/meson/sclk-div.c
index 76d31c0a3342..32d488086437 100644
--- a/drivers/clk/meson/sclk-div.c
+++ b/drivers/clk/meson/sclk-div.c
@@ -18,10 +18,16 @@
 
 #include <linux/clk-provider.h>
 #include <linux/module.h>
+#include <linux/slab.h>
 
 #include "clk-regmap.h"
 #include "sclk-div.h"
 
+struct sclk_div_runtime {
+	unsigned int div;
+	struct clk_duty duty;
+};
+
 static inline struct meson_sclk_div_data *
 meson_sclk_div_data(struct clk_regmap *clk)
 {
@@ -109,11 +115,12 @@ static long sclk_div_round_rate(struct clk_hw *hw, unsigned long rate,
 }
 
 static void sclk_apply_ratio(struct clk_regmap *clk,
-			     struct meson_sclk_div_data *sclk)
+			     struct meson_sclk_div_data *sclk,
+			     struct sclk_div_runtime *runtime)
 {
-	unsigned int hi = DIV_ROUND_CLOSEST(sclk->cached_div *
-					    sclk->cached_duty.num,
-					    sclk->cached_duty.den);
+	unsigned int hi = DIV_ROUND_CLOSEST(runtime->div *
+					    runtime->duty.num,
+					    runtime->duty.den);
 
 	if (hi)
 		hi -= 1;
@@ -126,10 +133,12 @@ static int sclk_div_set_duty_cycle(struct clk_hw *hw,
 {
 	struct clk_regmap *clk = to_clk_regmap(hw);
 	struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk);
+	struct sclk_div_runtime *runtime =
+		(struct sclk_div_runtime *) clk_hw_get_data(hw);
 
 	if (MESON_PARM_APPLICABLE(&sclk->hi)) {
-		memcpy(&sclk->cached_duty, duty, sizeof(*duty));
-		sclk_apply_ratio(clk, sclk);
+		memcpy(&runtime->duty, duty, sizeof(*duty));
+		sclk_apply_ratio(clk, sclk, runtime);
 	}
 
 	return 0;
@@ -140,6 +149,8 @@ static int sclk_div_get_duty_cycle(struct clk_hw *hw,
 {
 	struct clk_regmap *clk = to_clk_regmap(hw);
 	struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk);
+	struct sclk_div_runtime *runtime =
+		(struct sclk_div_runtime *) clk_hw_get_data(hw);
 	int hi;
 
 	if (!MESON_PARM_APPLICABLE(&sclk->hi)) {
@@ -150,17 +161,18 @@ static int sclk_div_get_duty_cycle(struct clk_hw *hw,
 
 	hi = meson_parm_read(clk->map, &sclk->hi);
 	duty->num = hi + 1;
-	duty->den = sclk->cached_div;
+	duty->den = runtime->div;
 	return 0;
 }
 
 static void sclk_apply_divider(struct clk_regmap *clk,
-			       struct meson_sclk_div_data *sclk)
+			       struct meson_sclk_div_data *sclk,
+			       struct sclk_div_runtime *runtime)
 {
 	if (MESON_PARM_APPLICABLE(&sclk->hi))
-		sclk_apply_ratio(clk, sclk);
+		sclk_apply_ratio(clk, sclk, runtime);
 
-	meson_parm_write(clk->map, &sclk->div, sclk->cached_div - 1);
+	meson_parm_write(clk->map, &sclk->div, runtime->div - 1);
 }
 
 static int sclk_div_set_rate(struct clk_hw *hw, unsigned long rate,
@@ -168,12 +180,14 @@ static int sclk_div_set_rate(struct clk_hw *hw, unsigned long rate,
 {
 	struct clk_regmap *clk = to_clk_regmap(hw);
 	struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk);
+	struct sclk_div_runtime *runtime =
+		(struct sclk_div_runtime *) clk_hw_get_data(hw);
 	unsigned long maxdiv = sclk_div_maxdiv(sclk);
 
-	sclk->cached_div = sclk_div_getdiv(hw, rate, prate, maxdiv);
+	runtime->div = sclk_div_getdiv(hw, rate, prate, maxdiv);
 
 	if (clk_hw_is_enabled(hw))
-		sclk_apply_divider(clk, sclk);
+		sclk_apply_divider(clk, sclk, runtime);
 
 	return 0;
 }
@@ -181,18 +195,20 @@ static int sclk_div_set_rate(struct clk_hw *hw, unsigned long rate,
 static unsigned long sclk_div_recalc_rate(struct clk_hw *hw,
 					  unsigned long prate)
 {
-	struct clk_regmap *clk = to_clk_regmap(hw);
-	struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk);
+	struct sclk_div_runtime *runtime =
+		(struct sclk_div_runtime *) clk_hw_get_data(hw);
 
-	return DIV_ROUND_UP_ULL((u64)prate, sclk->cached_div);
+	return DIV_ROUND_UP_ULL((u64)prate, runtime->div);
 }
 
 static int sclk_div_enable(struct clk_hw *hw)
 {
 	struct clk_regmap *clk = to_clk_regmap(hw);
 	struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk);
+	struct sclk_div_runtime *runtime =
+		(struct sclk_div_runtime *) clk_hw_get_data(hw);
 
-	sclk_apply_divider(clk, sclk);
+	sclk_apply_divider(clk, sclk, runtime);
 
 	return 0;
 }
@@ -220,21 +236,34 @@ static int sclk_div_init(struct clk_hw *hw)
 {
 	struct clk_regmap *clk = to_clk_regmap(hw);
 	struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk);
+	struct sclk_div_runtime *runtime;
 	unsigned int val;
 
+	runtime = kzalloc(sizeof(*runtime), GFP_KERNEL);
+	if (!runtime)
+		return -ENOMEM;
+
 	val = meson_parm_read(clk->map, &sclk->div);
 
 	/* if the divider is initially disabled, assume max */
 	if (!val)
-		sclk->cached_div = sclk_div_maxdiv(sclk);
+		runtime->div = sclk_div_maxdiv(sclk);
 	else
-		sclk->cached_div = val + 1;
+		runtime->div = val + 1;
 
-	sclk_div_get_duty_cycle(hw, &sclk->cached_duty);
+	sclk_div_get_duty_cycle(hw, &runtime->duty);
 
 	return 0;
 }
 
+static void sclk_div_terminate(struct clk_hw *hw)
+{
+	struct sclk_div_runtime *runtime =
+		(struct sclk_div_runtime *) clk_hw_get_data(hw);
+
+	kfree(runtime);
+}
+
 const struct clk_ops meson_sclk_div_ops = {
 	.recalc_rate	= sclk_div_recalc_rate,
 	.round_rate	= sclk_div_round_rate,
@@ -245,6 +274,7 @@ const struct clk_ops meson_sclk_div_ops = {
 	.get_duty_cycle	= sclk_div_get_duty_cycle,
 	.set_duty_cycle = sclk_div_set_duty_cycle,
 	.init		= sclk_div_init,
+	.terminate	= sclk_div_terminate,
 };
 EXPORT_SYMBOL_GPL(meson_sclk_div_ops);
 
diff --git a/drivers/clk/meson/sclk-div.h b/drivers/clk/meson/sclk-div.h
index b64b2a32005f..d03bbd78f47b 100644
--- a/drivers/clk/meson/sclk-div.h
+++ b/drivers/clk/meson/sclk-div.h
@@ -13,8 +13,6 @@
 struct meson_sclk_div_data {
 	struct parm div;
 	struct parm hi;
-	unsigned int cached_div;
-	struct clk_duty cached_duty;
 };
 
 extern const struct clk_ops meson_sclk_div_ops;
-- 
2.21.0


      parent reply index

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-28 10:20 [PATCH RFC 0/5] clk: let clock claim resources Jerome Brunet
2019-08-28 10:20 ` [PATCH RFC 1/5] clk: actually call the clock init before any other callback of the clock Jerome Brunet
2019-08-28 10:20 ` [PATCH RFC 2/5] clk: let init callback return an error code Jerome Brunet
2019-08-28 10:20 ` [PATCH RFC 3/5] clk: add terminate callback to clk_ops Jerome Brunet
2019-08-28 10:20 ` [PATCH RFC 4/5] clk: add placeholder for clock internal data Jerome Brunet
2019-08-28 22:15   ` Stephen Boyd
2019-08-29  7:20     ` Jerome Brunet
2019-08-29 17:17       ` Stephen Boyd
2019-08-30 14:06         ` Jerome Brunet
2019-09-04 22:52           ` Stephen Boyd
2019-08-28 10:20 ` Jerome Brunet [this message]

Reply instructions:

You may reply publically 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=20190828102012.4493-6-jbrunet@baylibre.com \
    --to=jbrunet@baylibre.com \
    --cc=khilman@baylibre.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=sboyd@kernel.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

Linux-Clk Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-clk/0 linux-clk/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-clk linux-clk/ https://lore.kernel.org/linux-clk \
		linux-clk@vger.kernel.org
	public-inbox-index linux-clk

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-clk


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git