* [PATCH v2 1/2] of: property: add of_property_for_each_u64
2024-07-29 2:30 [PATCH v2 0/2] clk: add assigned-clock-rates-u64 Peng Fan (OSS)
@ 2024-07-29 2:30 ` Peng Fan (OSS)
2024-07-29 12:32 ` Luca Ceresoli
2024-07-29 2:30 ` [PATCH v2 2/2] clk: clk-conf: support assigned-clock-rates-u64 Peng Fan (OSS)
1 sibling, 1 reply; 5+ messages in thread
From: Peng Fan (OSS) @ 2024-07-29 2:30 UTC (permalink / raw)
To: Rob Herring, Saravana Kannan, Michael Turquette, Stephen Boyd,
Luca Ceresoli
Cc: devicetree, linux-kernel, linux-clk, Peng Fan
From: Peng Fan <peng.fan@nxp.com>
Preparing for assigned-clock-rates-u64 support, add function
of_property_for_each_u64 to iterate each u64 value
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
drivers/of/property.c | 23 +++++++++++++++++++++++
include/linux/of.h | 23 +++++++++++++++++++++++
2 files changed, 46 insertions(+)
diff --git a/drivers/of/property.c b/drivers/of/property.c
index 164d77cb9445..f70fd8deb9cd 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -548,6 +548,29 @@ const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur,
}
EXPORT_SYMBOL_GPL(of_prop_next_u32);
+const __be64 *of_prop_next_u64(struct property *prop, const __be64 *cur,
+ u64 *pu)
+{
+ const void *curv = cur;
+
+ if (!prop)
+ return NULL;
+
+ if (!cur) {
+ curv = prop->value;
+ goto out_val;
+ }
+
+ curv += sizeof(*cur);
+ if (curv >= prop->value + prop->length)
+ return NULL;
+
+out_val:
+ *pu = be64_to_cpup(curv);
+ return curv;
+}
+EXPORT_SYMBOL_GPL(of_prop_next_u64);
+
const char *of_prop_next_string(struct property *prop, const char *cur)
{
const void *curv = cur;
diff --git a/include/linux/of.h b/include/linux/of.h
index 85b60ac9eec5..de481a4bdad0 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -437,6 +437,16 @@ extern int of_detach_node(struct device_node *);
*/
const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur,
u32 *pu);
+
+/*
+ * u64 u;
+ *
+ * of_property_for_each_u64(np, "propname", u)
+ * printk("U64 value: %llx\n", u);
+ */
+const __be64 *of_prop_next_u64(struct property *prop, const __be64 *cur,
+ u64 *pu);
+
/*
* struct property *prop;
* const char *s;
@@ -832,6 +842,12 @@ static inline const __be32 *of_prop_next_u32(struct property *prop,
return NULL;
}
+static inline const __be64 *of_prop_next_u64(struct property *prop,
+ const __be64 *cur, u64 *pu)
+{
+ return NULL;
+}
+
static inline const char *of_prop_next_string(struct property *prop,
const char *cur)
{
@@ -1436,6 +1452,13 @@ static inline int of_property_read_s32(const struct device_node *np,
_it.item; \
_it.item = of_prop_next_u32(_it.prop, _it.item, &u))
+#define of_property_for_each_u64(np, propname, u) \
+ for (struct {struct property *prop; const __be64 *item; } _it = \
+ {of_find_property(np, propname, NULL), \
+ of_prop_next_u64(_it.prop, NULL, &u)}; \
+ _it.item; \
+ _it.item = of_prop_next_u64(_it.prop, _it.item, &u))
+
#define of_property_for_each_string(np, propname, prop, s) \
for (prop = of_find_property(np, propname, NULL), \
s = of_prop_next_string(prop, NULL); \
--
2.37.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v2 2/2] clk: clk-conf: support assigned-clock-rates-u64
2024-07-29 2:30 [PATCH v2 0/2] clk: add assigned-clock-rates-u64 Peng Fan (OSS)
2024-07-29 2:30 ` [PATCH v2 1/2] of: property: add of_property_for_each_u64 Peng Fan (OSS)
@ 2024-07-29 2:30 ` Peng Fan (OSS)
2024-07-30 0:22 ` Stephen Boyd
1 sibling, 1 reply; 5+ messages in thread
From: Peng Fan (OSS) @ 2024-07-29 2:30 UTC (permalink / raw)
To: Rob Herring, Saravana Kannan, Michael Turquette, Stephen Boyd,
Luca Ceresoli
Cc: devicetree, linux-kernel, linux-clk, Peng Fan
From: Peng Fan <peng.fan@nxp.com>
i.MX95 System Management Control Firmware(SCMI) manages the clock
function, it exposes PLL VCO which could support up to 5GHz rate that
exceeds UINT32_MAX. So add assigned-clock-rates-u64 support
to set rate that exceeds UINT32_MAX.
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
drivers/clk/clk-conf.c | 104 ++++++++++++++++++++++++++++++++++---------------
1 file changed, 73 insertions(+), 31 deletions(-)
diff --git a/drivers/clk/clk-conf.c b/drivers/clk/clk-conf.c
index 058420562020..37b72600b296 100644
--- a/drivers/clk/clk-conf.c
+++ b/drivers/clk/clk-conf.c
@@ -78,47 +78,89 @@ static int __set_clk_parents(struct device_node *node, bool clk_supplier)
return rc;
}
-static int __set_clk_rates(struct device_node *node, bool clk_supplier)
+static int __set_clk_rate(struct device_node *node, bool clk_supplier, int index,
+ unsigned long rate)
{
struct of_phandle_args clkspec;
- int rc, index = 0;
struct clk *clk;
- u32 rate;
+ int rc;
- of_property_for_each_u32(node, "assigned-clock-rates", rate) {
- if (rate) {
- rc = of_parse_phandle_with_args(node, "assigned-clocks",
+ rc = of_parse_phandle_with_args(node, "assigned-clocks",
"#clock-cells", index, &clkspec);
- if (rc < 0) {
- /* skip empty (null) phandles */
- if (rc == -ENOENT)
- continue;
- else
- return rc;
- }
- if (clkspec.np == node && !clk_supplier) {
- of_node_put(clkspec.np);
- return 0;
- }
+ if (rc < 0)
+ return rc;
- clk = of_clk_get_from_provider(&clkspec);
- of_node_put(clkspec.np);
- if (IS_ERR(clk)) {
- if (PTR_ERR(clk) != -EPROBE_DEFER)
- pr_warn("clk: couldn't get clock %d for %pOF\n",
- index, node);
- return PTR_ERR(clk);
+ if (clkspec.np == node && !clk_supplier) {
+ of_node_put(clkspec.np);
+ return 1;
+ }
+
+ clk = of_clk_get_from_provider(&clkspec);
+ of_node_put(clkspec.np);
+ if (IS_ERR(clk)) {
+ if (PTR_ERR(clk) != -EPROBE_DEFER)
+ pr_warn("clk: couldn't get clock %d for %pOF\n",
+ index, node);
+ return PTR_ERR(clk);
+ }
+
+ rc = clk_set_rate(clk, rate);
+ if (rc < 0)
+ pr_err("clk: couldn't set %s clk rate to %lu (%d), current rate: %lu\n",
+ __clk_get_name(clk), rate, rc, clk_get_rate(clk));
+ clk_put(clk);
+
+ return 0;
+}
+
+static int __set_clk_rates(struct device_node *node, bool clk_supplier)
+{
+ int rc, index = 0;
+ u64 rate;
+ u32 rate_32;
+ bool is_rate_32 = false;
+
+ if (!of_find_property(node, "assigned-clock-rates-u64", NULL))
+ is_rate_32 = true;
+
+ if (is_rate_32) {
+ of_property_for_each_u32(node, "assigned-clock-rates", rate_32) {
+ if (rate_32) {
+ rc = __set_clk_rate(node, clk_supplier, index, rate_32);
+
+ if (rc == 1 && !clk_supplier)
+ return 0;
+
+ if (rc < 0) {
+ /* skip empty (null) phandles */
+ if (rc == -ENOENT)
+ continue;
+ else
+ return rc;
+ }
}
+ index++;
+ }
+ } else {
+ of_property_for_each_u64(node, "assigned-clock-rates-u64", rate) {
+ if (rate) {
+ rc = __set_clk_rate(node, clk_supplier, index, rate);
- rc = clk_set_rate(clk, rate);
- if (rc < 0)
- pr_err("clk: couldn't set %s clk rate to %u (%d), current rate: %lu\n",
- __clk_get_name(clk), rate, rc,
- clk_get_rate(clk));
- clk_put(clk);
+ if (rc == 1 && !clk_supplier)
+ return 0;
+
+ if (rc < 0) {
+ /* skip empty (null) phandles */
+ if (rc == -ENOENT)
+ continue;
+ else
+ return rc;
+ }
+ }
+ index++;
}
- index++;
}
+
return 0;
}
--
2.37.1
^ permalink raw reply related [flat|nested] 5+ messages in thread