mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 04/14] clk: introduce clk_register()
Date: Tue, 18 May 2021 13:49:19 +0200	[thread overview]
Message-ID: <20210518114929.12964-5-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20210518114929.12964-1-s.hauer@pengutronix.de>

This introduces a clk_register() with the same semantics as in Linux.
This also adds a struct clk_init_data. With this it becomes easier to
port over new clock drivers from Linux.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/clk/clk.c   | 35 +++++++++++++++++++++++++++++++++++
 include/linux/clk.h |  2 ++
 2 files changed, 37 insertions(+)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 73682126bf..2ca6d6b483 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -345,6 +345,41 @@ out:
 	return ret;
 }
 
+struct clk *clk_register(struct device_d *dev, struct clk_hw *hw)
+{
+	struct clk *clk;
+	const struct clk_init_data *init = hw->init;
+	char **parent_names;
+	int i, ret;
+
+	if (!hw->init)
+		return ERR_PTR(-EINVAL);
+
+	clk = clk_hw_to_clk(hw);
+
+	clk->name = xstrdup(init->name);
+	clk->ops = init->ops;
+	clk->num_parents = init->num_parents;
+	parent_names = xzalloc(init->num_parents * sizeof(char *));
+
+	for (i = 0; i < init->num_parents; i++)
+		parent_names[i] = xstrdup(init->parent_names[i]);
+
+	clk->parent_names = (const char *const*)parent_names;
+
+	clk->flags = init->flags;
+
+	ret = bclk_register(clk);
+	if (ret) {
+		for (i = 0; i < init->num_parents; i++)
+			free(parent_names[i]);
+		free(parent_names);
+		return ERR_PTR(ret);
+	}
+
+	return clk;
+}
+
 int clk_is_enabled(struct clk *clk)
 {
 	int enabled;
diff --git a/include/linux/clk.h b/include/linux/clk.h
index 66ac6a9f14..654845023a 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -399,6 +399,7 @@ struct clk {
  */
 struct clk_hw {
 	struct clk clk;
+	const struct clk_init_data *init;
 };
 
 static inline struct clk *clk_hw_to_clk(struct clk_hw *hw)
@@ -547,6 +548,7 @@ int clk_parent_set_rate(struct clk_hw *hw, unsigned long rate,
 				unsigned long parent_rate);
 
 int bclk_register(struct clk *clk);
+struct clk *clk_register(struct device_d *dev, struct clk_hw *hw);
 
 struct clk *clk_lookup(const char *name);
 
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  parent reply	other threads:[~2021-05-18 11:52 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-18 11:49 [PATCH 00/14] clk updates Sascha Hauer
2021-05-18 11:49 ` [PATCH 01/14] clk: introduce clk init op Sascha Hauer
2021-05-18 11:57   ` Ahmad Fatoum
2021-05-18 11:49 ` [PATCH 02/14] clk: rename clk_register() to bclk_register() Sascha Hauer
2021-05-18 12:06   ` Ahmad Fatoum
2021-05-18 11:49 ` [PATCH 03/14] clk: introduce struct clk_hw Sascha Hauer
2021-05-18 12:17   ` Ahmad Fatoum
2021-05-19  6:55     ` Sascha Hauer
2021-05-18 11:49 ` Sascha Hauer [this message]
2021-05-18 12:21   ` [PATCH 04/14] clk: introduce clk_register() Ahmad Fatoum
2021-05-18 11:49 ` [PATCH 05/14] clk: divider: Add ro ops Sascha Hauer
2021-05-18 12:21   ` Ahmad Fatoum
2021-05-18 11:49 ` [PATCH 06/14] clk: mux: " Sascha Hauer
2021-05-18 11:49 ` [PATCH 07/14] clk: move fixed_factor to include/linux/clk.h Sascha Hauer
2021-05-18 11:49 ` [PATCH 08/14] Add rational_best_approximation() Sascha Hauer
2021-05-18 12:23   ` Ahmad Fatoum
2021-05-18 11:49 ` [PATCH 09/14] clk: Update fractional divider from Linux Sascha Hauer
2021-05-18 11:49 ` [PATCH 10/14] clk: Add lock to different clock types Sascha Hauer
2021-05-18 11:49 ` [PATCH 11/14] clk: Add Linux functions to register a divider Sascha Hauer
2021-05-18 11:49 ` [PATCH 12/14] clk: Add Linux functions to register a fixed factor clock Sascha Hauer
2021-05-18 11:49 ` [PATCH 13/14] clk: Add Linux functions to register a gate Sascha Hauer
2021-05-18 11:49 ` [PATCH 14/14] clk: Add Linux functions to register a mux Sascha Hauer

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=20210518114929.12964-5-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@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