From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 07/13] clk: add struct clk_init_data::parent_hws
Date: Mon, 27 Nov 2023 07:49:41 +0100 [thread overview]
Message-ID: <20231127064947.2207726-8-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20231127064947.2207726-1-a.fatoum@pengutronix.de>
For cases where all clock parents are internal to the clock controller,
parent_hws allows specifying direct pointers to the clk_hw structures
instead of globally unique names. Add support for this to barebox to be
used by the incoming STM32MP13 clock driver.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/clk/clk.c | 59 ++++++++++++++++++++++++++++++++++-----------
include/linux/clk.h | 3 +++
2 files changed, 48 insertions(+), 14 deletions(-)
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index acd90e6e5889..4130f413a36d 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -431,7 +431,7 @@ int clk_get_phase(struct clk *clk)
return ret;
}
-int bclk_register(struct clk *clk)
+static int __bclk_register(struct clk *clk)
{
struct clk_hw *hw = clk_to_clk_hw(clk);
struct clk *c;
@@ -445,8 +445,6 @@ int bclk_register(struct clk *clk)
}
}
- clk->parents = xzalloc(sizeof(struct clk *) * clk->num_parents);
-
list_add_tail(&clk->list, &clks);
if (clk->ops->init) {
@@ -461,7 +459,19 @@ int bclk_register(struct clk *clk)
return 0;
out:
list_del(&clk->list);
- free(clk->parents);
+
+ return ret;
+}
+
+int bclk_register(struct clk *clk)
+{
+ int ret;
+
+ clk->parents = xzalloc(sizeof(struct clk *) * clk->num_parents);
+
+ ret = __bclk_register(clk);
+ if (ret)
+ free(clk->parents);
return ret;
}
@@ -470,7 +480,7 @@ struct clk *clk_register(struct device *dev, struct clk_hw *hw)
{
struct clk *clk;
const struct clk_init_data *init = hw->init;
- char **parent_names;
+ char **parent_names = NULL;
int i, ret;
if (!hw->init)
@@ -483,20 +493,32 @@ struct clk *clk_register(struct device *dev, struct clk_hw *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->parents = xzalloc(sizeof(struct clk *) * clk->num_parents);
- clk->parent_names = (const char *const*)parent_names;
+ if (init->parent_names) {
+ 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;
+
+ } else {
+ for (i = 0; i < init->num_parents; i++)
+ clk->parents[i] = clk_hw_to_clk(init->parent_hws[i]);
+ }
clk->flags = init->flags;
- ret = bclk_register(clk);
+ ret = __bclk_register(clk);
if (ret) {
- for (i = 0; i < init->num_parents; i++)
- free(parent_names[i]);
- free(parent_names);
+ if (parent_names) {
+ for (i = 0; i < init->num_parents; i++)
+ free(parent_names[i]);
+ free(parent_names);
+ }
+ free(clk->parents);
return ERR_PTR(ret);
}
@@ -997,6 +1019,15 @@ static const char *clk_hw_stat(struct clk *clk)
return "unknown";
}
+static const char *clk_parent_name_by_index(struct clk *clk, u8 idx)
+{
+ if (clk->parent_names)
+ return clk->parent_names[idx];
+ if (clk->parents[idx])
+ return clk->parents[idx]->name;
+ return "unknown";
+}
+
static void dump_one(struct clk *clk, int verbose, int indent)
{
int enabled = clk_is_enabled(clk);
@@ -1021,7 +1052,7 @@ static void dump_one(struct clk *clk, int verbose, int indent)
int i;
printf("%*s`---- possible parents: ", indent * 4, "");
for (i = 0; i < clk->num_parents; i++)
- printf("%s ", clk->parent_names[i]);
+ printf("%s ", clk_parent_name_by_index(clk, i));
printf("\n");
}
}
diff --git a/include/linux/clk.h b/include/linux/clk.h
index 6a33f28ee60a..28ed2d2bfd66 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -329,6 +329,8 @@ struct clk_ops {
* @name: clock name
* @ops: operations this clock supports
* @parent_names: array of string names for all possible parents
+ * @parent_hws: array of pointers to all possible parents (when all parents
+ * are internal to the clk controller)
* @num_parents: number of possible parents
* @flags: framework-level hints and quirks
*/
@@ -336,6 +338,7 @@ struct clk_init_data {
const char *name;
const struct clk_ops *ops;
const char * const *parent_names;
+ const struct clk_hw **parent_hws;
unsigned int num_parents;
unsigned long flags;
};
--
2.39.2
next prev parent reply other threads:[~2023-11-27 6:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-27 6:49 [PATCH 00/13] ARM: stm32mp: add full STM32MP13 support with OP-TEE Ahmad Fatoum
2023-11-27 6:49 ` [PATCH 01/13] clk: stm32mp1: build only when STM32MP15 support is enabled Ahmad Fatoum
2023-11-27 6:49 ` [PATCH 02/13] clk: factor out clk_hw_get_parent_index Ahmad Fatoum
2023-11-27 6:49 ` [PATCH 03/13] include: add initial <linux/clk-provider.h> Ahmad Fatoum
2023-11-27 6:49 ` [PATCH 04/13] clk: divider: implement CLK_DIVIDER_ALLOW_ZERO Ahmad Fatoum
2023-11-27 6:49 ` [PATCH 05/13] clk: divider: implement divider_[ro_]round_rate_parent Ahmad Fatoum
2023-11-27 6:49 ` [PATCH 06/13] clk: implement clk clk_hw_get_parent_by_index Ahmad Fatoum
2023-11-27 6:49 ` Ahmad Fatoum [this message]
2023-11-27 6:49 ` [PATCH 08/13] clk: implement clk_hw_reparent Ahmad Fatoum
2023-11-27 6:49 ` [PATCH 09/13] clk: add STM32MP13 clock and reset drivers Ahmad Fatoum
2023-11-27 6:49 ` [PATCH 10/13] pinctrl: stm32: match st,stm32mp135-pinctrl DT compatible Ahmad Fatoum
2023-11-27 6:49 ` [PATCH 11/13] aiodev: stm32: add STM32MP13x support Ahmad Fatoum
2023-11-27 6:49 ` [PATCH 12/13] ARM: stm32mp: 135-DK: enable environment, bbu handler and deep probe Ahmad Fatoum
2023-11-27 6:49 ` [PATCH 13/13] ARM: stm32mp: remove STM32MP13 .stm32 image Ahmad Fatoum
2023-12-05 7:35 ` [PATCH 00/13] ARM: stm32mp: add full STM32MP13 support with OP-TEE 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=20231127064947.2207726-8-a.fatoum@pengutronix.de \
--to=a.fatoum@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