[PATCH v2 0/7] clk: Add support for clock nexus

0 views
Skip to first unread message

Miquel Raynal (Schneider Electric)

unread,
Jul 10, 2026, 2:22:17 PMJul 10
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric), Herve Codina
Adding support for clock nexus had some prerequisites requested by
Stephen, such as adding new selftests, the initial discussions come from:

Link: https://lore.kernel.org/linux-clk/20260129201003.288...@bootlin.com/

Then there has been a bigger series (including patches for other
subsystems) to show the big picture, but let's split again and focus on
one subsystem at a time:

Changes in v2:
- Collected tags.
- Rebased on top of v7.2-rc1
- Exported (test) clock symbols using the _IF_KUNIT() variant, and
imported the NS in the test file.
- Fixed a leaking node reported by Brian in the tests. Also used
existing helpers to simplify the test implementation as he wisely
suggested.
- Reworded the nexus node binding description as suggested by Stephen.
- Dropped redundant and non restraining properties from the Nexus
node as suggested by Rob.
- Assigned clock/clock-rate properties now traverse Nexus nodes.
- Rename helpers following Stephen proposals.
- Rework tests following Stephen hints.
- Link to v1: https://lore.kernel.org/r/20260327-schneider-v7-0-rc...@bootlin.com

Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
---
Miquel Raynal (Schneider Electric) (7):
dt-bindings: clock: Introduce nexus nodes
clk: tests: Add clk_parse_clkspec() Kunit testing
clk: tests: Add Kunit testing for of_clk_get_parent_name()
clk: Improve a couple of comments
clk: Use the generic OF phandle parsing in only one place
clk: Add support for clock nexus dt bindings
clk: tests: Add Kunit testing for nexus nodes

.../bindings/clock/clock-nexus-node.yaml | 30 +++++
drivers/clk/Makefile | 1 +
drivers/clk/clk-conf.c | 12 +-
drivers/clk/clk.c | 13 +-
drivers/clk/clk_kunit_helpers.c | 31 +++++
drivers/clk/clk_test.c | 146 +++++++++++++++++++++
drivers/clk/kunit_clk_parse_clkspec.dtso | 31 +++++
include/kunit/clk.h | 2 +
8 files changed, 254 insertions(+), 12 deletions(-)
---
base-commit: 7f26e010764df304602f33912a0550dcf46e72c2
change-id: 20260710-schneider-v7-2-rc1-eip201-upstream-a470e5eab92d

Best regards,
--
Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>

Miquel Raynal (Schneider Electric)

unread,
Jul 10, 2026, 2:22:19 PMJul 10
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric)
Hardware containers can just decouple external resources like clock
without any more control. Nexus nodes already exist for PWM and GPIOs,
add a binding to allow them for clocks as well.

No examples are given, the file is litteraly a copy-paste from Hervé
Codina's work on PWM Nexus nodes, hence we just point to the examples
there which already illustrate very clearly the concept of the various
properties.

Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
---
.../bindings/clock/clock-nexus-node.yaml | 30 ++++++++++++++++++++++
1 file changed, 30 insertions(+)

diff --git a/Documentation/devicetree/bindings/clock/clock-nexus-node.yaml b/Documentation/devicetree/bindings/clock/clock-nexus-node.yaml
new file mode 100644
index 000000000000..ff3283bd5fb1
--- /dev/null
+++ b/Documentation/devicetree/bindings/clock/clock-nexus-node.yaml
@@ -0,0 +1,30 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/clock/clock-nexus-node.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Clock Nexus
+
+description: >
+ A nexus node allows to remap a clock specifier list in a consumer node
+ through a container or a connector node in a generic way. With this
+ remapping, the consumer node needs to know only about the nexus
+ node. Resources behind the nexus node are decoupled by the nexus node
+ itself.
+
+maintainers:
+ - Miquel Raynal <miquel...@bootlin.com>
+
+select: true
+
+properties:
+ clock-map:
+ $ref: /schemas/types.yaml#/definitions/uint32-matrix
+
+dependentRequired:
+ clock-map: ['#clock-cells']
+
+additionalProperties: true
+
+# See the original pwm-nexus-node.yaml description for examples

--
2.54.0

Miquel Raynal (Schneider Electric)

unread,
Jul 10, 2026, 2:22:21 PMJul 10
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric)
Create a new set of kunit tests to make sure clk_parse_clkspec() is
working as expected. We currently verify if we get a proper device when
using indexes and names. If we make an out of bounds request we expect
an error.

For testing purposes, we must ensure of_clk_get_hw()'s symbol is
exported.

Suggested-by: Stephen Boyd <sb...@kernel.org>
Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
---
drivers/clk/Makefile | 1 +
drivers/clk/clk.c | 2 +
drivers/clk/clk_test.c | 117 +++++++++++++++++++++++++++++++
drivers/clk/kunit_clk_parse_clkspec.dtso | 21 ++++++
4 files changed, 141 insertions(+)

diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index cc108a75a900..035b984db70d 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -19,6 +19,7 @@ clk-test-y := clk_test.o \
kunit_clk_assigned_rates_zero.dtbo.o \
kunit_clk_assigned_rates_zero_consumer.dtbo.o \
kunit_clk_hw_get_dev_of_node.dtbo.o \
+ kunit_clk_parse_clkspec.dtbo.o \
kunit_clk_parent_data_test.dtbo.o
obj-$(CONFIG_COMMON_CLK) += clk-divider.o
obj-$(CONFIG_COMMON_CLK) += clk-fixed-factor.o
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 048adfa86a5d..08874cf9b561 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -24,6 +24,7 @@
#include <linux/spinlock.h>
#include <linux/string.h>
#include <linux/stringhash.h>
+#include <kunit/visibility.h>

#include "clk.h"

@@ -5300,6 +5301,7 @@ struct clk_hw *of_clk_get_hw(struct device_node *np, int index,

return hw;
}
+EXPORT_SYMBOL_IF_KUNIT(of_clk_get_hw);

static struct clk *__of_clk_get(struct device_node *np,
int index, const char *dev_id,
diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c
index b1961daac5e2..fddb2bb9618f 100644
--- a/drivers/clk/clk_test.c
+++ b/drivers/clk/clk_test.c
@@ -3541,10 +3541,126 @@ static struct kunit_suite clk_hw_get_dev_of_node_test_suite = {
.test_cases = clk_hw_get_dev_of_node_test_cases,
};

+static const struct clk_init_data clk_parse_clkspec_1_init_data = {
+ .name = "clk_parse_clkspec_1",
+ .ops = &empty_clk_ops,
+};
+
+static const struct clk_init_data clk_parse_clkspec_2_init_data = {
+ .name = "clk_parse_clkspec_2",
+ .ops = &empty_clk_ops,
+};
+
+struct clk_parse_clkspec_ctx {
+ struct device_node *cons_np;
+};
+
+static int clk_parse_clkspec_init(struct kunit *test)
+{
+ struct device_node *prov1_np, *prov2_np;
+ struct clk_parse_clkspec_ctx *ctx;
+ struct clk_hw *hw1, *hw2;
+
+ ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx);
+ test->priv = ctx;
+
+ KUNIT_ASSERT_EQ(test, 0, of_overlay_apply_kunit(test, kunit_clk_parse_clkspec));
+
+ /* Register provider 1 */
+ hw1 = kunit_kzalloc(test, sizeof(*hw1), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw1);
+ hw1->init = &clk_parse_clkspec_1_init_data;
+
+ prov1_np = of_find_compatible_node(NULL, NULL, "test,clock-provider1");
+ KUNIT_ASSERT_NOT_NULL(test, prov1_np);
+
+ KUNIT_ASSERT_EQ(test, 0, of_clk_hw_register_kunit(test, prov1_np, hw1));
+ of_clk_add_hw_provider_kunit(test, prov1_np, of_clk_hw_simple_get, hw1);
+ of_node_put(prov1_np);
+
+ /* Register provider 2 */
+ hw2 = kunit_kzalloc(test, sizeof(*hw2), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw2);
+ hw2->init = &clk_parse_clkspec_2_init_data;
+
+ prov2_np = of_find_compatible_node(NULL, NULL, "test,clock-provider2");
+ KUNIT_ASSERT_NOT_NULL(test, prov2_np);
+
+ KUNIT_ASSERT_EQ(test, 0, of_clk_hw_register_kunit(test, prov2_np, hw2));
+ of_clk_add_hw_provider_kunit(test, prov2_np, of_clk_hw_simple_get, hw2);
+ of_node_put(prov2_np);
+
+ ctx->cons_np = of_find_compatible_node(NULL, NULL, "test,clock-consumer");
+ KUNIT_ASSERT_NOT_NULL(test, ctx->cons_np);
+
+ return 0;
+}
+
+static void clk_parse_clkspec_exit(struct kunit *test)
+{
+ struct clk_parse_clkspec_ctx *ctx = test->priv;
+
+ of_node_put(ctx->cons_np);
+}
+
+/* Test DT phandle lookups using correct index or name succeed */
+static void clk_parse_clkspec_with_correct_index_and_name(struct kunit *test)
+{
+ struct clk_parse_clkspec_ctx *ctx = test->priv;
+ struct clk_hw *hw1, *hw2, *hw3, *hw4;
+
+ /* Get clocks by index */
+ hw1 = of_clk_get_hw(ctx->cons_np, 0, NULL);
+ KUNIT_EXPECT_NOT_ERR_OR_NULL(test, hw1);
+
+ hw2 = of_clk_get_hw(ctx->cons_np, 1, NULL);
+ KUNIT_EXPECT_NOT_ERR_OR_NULL(test, hw2);
+ KUNIT_EXPECT_PTR_NE(test, hw1, hw2);
+
+ /* Get clocks by name */
+ hw3 = of_clk_get_hw(ctx->cons_np, 0, "first_clock");
+ KUNIT_EXPECT_NOT_ERR_OR_NULL(test, hw3);
+ KUNIT_EXPECT_PTR_EQ(test, hw1, hw3);
+
+ hw4 = of_clk_get_hw(ctx->cons_np, 0, "second_clock");
+ KUNIT_EXPECT_NOT_ERR_OR_NULL(test, hw4);
+ KUNIT_EXPECT_PTR_EQ(test, hw2, hw4);
+}
+
+/* Test DT phandle lookups using wrong index or name fail */
+static void clk_parse_clkspec_with_incorrect_index_and_name(struct kunit *test)
+{
+ struct clk_parse_clkspec_ctx *ctx = test->priv;
+ struct clk_hw *hw;
+
+ /* Get clock by index */
+ hw = of_clk_get_hw(ctx->cons_np, 2, NULL);
+ KUNIT_EXPECT_TRUE(test, IS_ERR(hw));
+
+ /* Get clock by name */
+ hw = of_clk_get_hw(ctx->cons_np, 0, "third_clock");
+ KUNIT_EXPECT_TRUE(test, IS_ERR(hw));
+}
+
+static struct kunit_case clk_parse_clkspec_test_cases[] = {
+ KUNIT_CASE(clk_parse_clkspec_with_correct_index_and_name),
+ KUNIT_CASE(clk_parse_clkspec_with_incorrect_index_and_name),
+ {}
+};
+
+/* Test suite to verify clk_parse_clkspec() */
+static struct kunit_suite clk_parse_clkspec_test_suite = {
+ .name = "clk_parse_clkspec",
+ .init = clk_parse_clkspec_init,
+ .exit = clk_parse_clkspec_exit,
+ .test_cases = clk_parse_clkspec_test_cases,
+};

kunit_test_suites(
&clk_assigned_rates_suite,
&clk_hw_get_dev_of_node_test_suite,
+ &clk_parse_clkspec_test_suite,
&clk_leaf_mux_set_rate_parent_test_suite,
&clk_test_suite,
&clk_multiple_parents_mux_test_suite,
@@ -3562,4 +3678,5 @@ kunit_test_suites(
&clk_uncached_test_suite,
);
MODULE_DESCRIPTION("Kunit tests for clk framework");
+MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
MODULE_LICENSE("GPL v2");
diff --git a/drivers/clk/kunit_clk_parse_clkspec.dtso b/drivers/clk/kunit_clk_parse_clkspec.dtso
new file mode 100644
index 000000000000..c93feb93e101
--- /dev/null
+++ b/drivers/clk/kunit_clk_parse_clkspec.dtso
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0
+/dts-v1/;
+/plugin/;
+
+&{/} {
+ kunit_clock_provider1: kunit-clock-provider1 {
+ compatible = "test,clock-provider1";
+ #clock-cells = <1>;
+ };
+
+ kunit_clock_provider2: kunit-clock-provider2 {
+ compatible = "test,clock-provider2";
+ #clock-cells = <1>;
+ };
+
+ kunit-clock-consumer {
+ compatible = "test,clock-consumer";
+ clocks = <&kunit_clock_provider1 0>, <&kunit_clock_provider2 0>;
+ clock-names = "first_clock", "second_clock";
+ };
+};

--
2.54.0

Miquel Raynal (Schneider Electric)

unread,
Jul 10, 2026, 2:22:25 PMJul 10
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric)
Make sure this helper is never broken, especially since we will soon
make some changes in it.

Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
---
drivers/clk/clk_test.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c
index fddb2bb9618f..5f3ffda033c3 100644
--- a/drivers/clk/clk_test.c
+++ b/drivers/clk/clk_test.c
@@ -3643,9 +3643,23 @@ static void clk_parse_clkspec_with_incorrect_index_and_name(struct kunit *test)
KUNIT_EXPECT_TRUE(test, IS_ERR(hw));
}

+/*
+ * Verify that of_clk_get_parent_name() returns the correct clock name when
+ * looking up by index through the consumer's clocks property.
+ */
+static void of_clk_get_parent_name_gets_parent_name(struct kunit *test)
+{
+ struct clk_parse_clkspec_ctx *ctx = test->priv;
+ const char *expected_name = "clk_parse_clkspec_1";
+
+ KUNIT_EXPECT_STREQ(test, expected_name,
+ of_clk_get_parent_name(ctx->cons_np, 0));
+}
+
static struct kunit_case clk_parse_clkspec_test_cases[] = {
KUNIT_CASE(clk_parse_clkspec_with_correct_index_and_name),
KUNIT_CASE(clk_parse_clkspec_with_incorrect_index_and_name),
+ KUNIT_CASE(of_clk_get_parent_name_gets_parent_name),
{}
};


--
2.54.0

Miquel Raynal (Schneider Electric)

unread,
Jul 10, 2026, 2:22:26 PMJul 10
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric)
Avoid mentioning the function names directly in the comments, it makes
them easily out of sync with the rest of the code. Use a more generic
wording.

Suggested-by: Stephen Boyd <sb...@kernel.org>
Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
Reviewed-by: Brian Masney <bma...@redhat.com>
---
drivers/clk/clk.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 08874cf9b561..7d63d81ebc09 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -5202,7 +5202,7 @@ static int of_parse_clkspec(const struct device_node *np, int index,
/*
* For named clocks, first look up the name in the
* "clock-names" property. If it cannot be found, then index
- * will be an error code and of_parse_phandle_with_args() will
+ * will be an error code and the OF phandle parser will
* return -EINVAL.
*/
if (name)
@@ -5275,7 +5275,7 @@ of_clk_get_hw_from_clkspec(struct of_phandle_args *clkspec)
*
* This function looks up a struct clk from the registered list of clock
* providers, an input is a clock specifier data structure as returned
- * from the of_parse_phandle_with_args() function call.
+ * from the OF phandle parser.
*/
struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec)
{

--
2.54.0

Miquel Raynal (Schneider Electric)

unread,
Jul 10, 2026, 2:22:30 PMJul 10
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric)
There should be one single entry in the OF world, so that the way we
parse the DT is always the same. make sure this is the case by avoid
calling of_parse_phandle_with_args() from of_clk_get_parent_name(). This
is even more relevant as we currently fail to parse clock-ranges. As a
result, it seems to be safer to directly call of_parse_clkspec() there.

Suggested-by: Stephen Boyd <sb...@kernel.org>
Fixes: 4472287a3b2f5 ("clk: Introduce of_clk_get_hw_from_clkspec()")
Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
Reviewed-by: Brian Masney <bma...@redhat.com>
---
drivers/clk/clk.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 7d63d81ebc09..dad4bac10ad4 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -5364,8 +5364,7 @@ const char *of_clk_get_parent_name(const struct device_node *np, int index)
int count;
struct clk *clk;

- rc = of_parse_phandle_with_args(np, "clocks", "#clock-cells", index,
- &clkspec);
+ rc = of_parse_clkspec(np, index, NULL, &clkspec);
if (rc)
return NULL;


--
2.54.0

Miquel Raynal (Schneider Electric)

unread,
Jul 10, 2026, 2:22:33 PMJul 10
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric), Herve Codina
A nexus node is some kind of parent device abstracting the outer
connections. They are particularly useful for describing connectors-like
interfaces but not only. Certain IP blocks will typically include inner
blocks and distribute resources to them.

In the case of clocks, there is already the concept of clock controller,
but this usually indicates some kind of control over the said clock,
ie. gate or rate control. When there is none of this, an existing
approach is to reference the upper clock, which is wrong from a hardware
point of view.

Nexus nodes are already part of the device-tree specification and clocks
are already mentioned:
https://github.com/devicetree-org/devicetree-specification/blob/v0.4/source/chapter2-devicetree-basics.rst#nexus-nodes-and-specifier-mapping

Following the introductions of nexus nodes support for interrupts, gpios
and pwms, here is the same logic applied again to the clk subsystem,
just by transitioning from of_parse_phandle_with_args() to
of_parse_phandle_with_args_map():

* Nexus OF support:
commit bd6f2fd5a1d5 ("of: Support parsing phandle argument lists through a nexus node")
* GPIO adoption:
commit c11e6f0f04db ("gpio: Support gpio nexus dt bindings")
* PWM adoption:
commit e71e46a6f19c ("pwm: Add support for pwm nexus dt bindings")

Only expected Nexus property:
- clock-map: maps inner clocks to inlet clocks
(the other properties have been judged not relevant for clocks)

Here is an example:

Example:
soc_clk: clock-controller {
#clock-cells = <1>;
};

container: container {
#clock-cells = <1>;
clock-map = <0 &soc_clk 2>,
<1 &soc_clk 6>;

child-device {
clocks = <&container 1>;
/* This is equivalent to <&soc_clk 6> */
};
};

The child device does not need to know about the outer implementation,
and only knows about what the nexus provides. The nexus acts as a
pass-through, with no extra control.

Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
Reviewed-by: Herve Codina <herve....@bootlin.com>
Reviewed-by: Brian Masney <bma...@redhat.com>
---
drivers/clk/clk-conf.c | 12 ++++++------
drivers/clk/clk.c | 4 ++--
2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/clk/clk-conf.c b/drivers/clk/clk-conf.c
index 303a0bb26e54..5380d43b56a4 100644
--- a/drivers/clk/clk-conf.c
+++ b/drivers/clk/clk-conf.c
@@ -25,8 +25,8 @@ static int __set_clk_parents(struct device_node *node, bool clk_supplier)
node);

for (index = 0; index < num_parents; index++) {
- rc = of_parse_phandle_with_args(node, "assigned-clock-parents",
- "#clock-cells", index, &clkspec);
+ rc = of_parse_phandle_with_args_map(node, "assigned-clock-parents",
+ "clock", index, &clkspec);
if (rc < 0) {
/* skip empty (null) phandles */
if (rc == -ENOENT)
@@ -47,8 +47,8 @@ static int __set_clk_parents(struct device_node *node, bool clk_supplier)
return PTR_ERR(pclk);
}

- rc = of_parse_phandle_with_args(node, "assigned-clocks",
- "#clock-cells", index, &clkspec);
+ rc = of_parse_phandle_with_args_map(node, "assigned-clocks",
+ "clock", index, &clkspec);
if (rc < 0)
goto err;
if (clkspec.np == node && !clk_supplier) {
@@ -121,8 +121,8 @@ static int __set_clk_rates(struct device_node *node, bool clk_supplier)
rate = rates[index];

if (rate) {
- rc = of_parse_phandle_with_args(node, "assigned-clocks",
- "#clock-cells", index, &clkspec);
+ rc = of_parse_phandle_with_args_map(node, "assigned-clocks",
+ "clock", index, &clkspec);
if (rc < 0) {
/* skip empty (null) phandles */
if (rc == -ENOENT)
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index dad4bac10ad4..73ddd9a6aa2e 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -5207,8 +5207,8 @@ static int of_parse_clkspec(const struct device_node *np, int index,
*/
if (name)
index = of_property_match_string(np, "clock-names", name);
- ret = of_parse_phandle_with_args(np, "clocks", "#clock-cells",
- index, out_args);
+ ret = of_parse_phandle_with_args_map(np, "clocks", "clock",
+ index, out_args);
if (!ret)
break;
if (name && index >= 0)

--
2.54.0

Miquel Raynal (Schneider Electric)

unread,
Jul 10, 2026, 2:22:35 PMJul 10
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric)
Add a nexus node with a child requesting a mapped clock in the fake DT
overlay to verify that the parsing is also correctly working.

Suggested-by: Stephen Boyd <sb...@kernel.org>
Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
---
drivers/clk/clk_kunit_helpers.c | 31 +++++++++++++++++++++++++++++++
drivers/clk/clk_test.c | 15 +++++++++++++++
drivers/clk/kunit_clk_parse_clkspec.dtso | 10 ++++++++++
include/kunit/clk.h | 2 ++
4 files changed, 58 insertions(+)

diff --git a/drivers/clk/clk_kunit_helpers.c b/drivers/clk/clk_kunit_helpers.c
index 68a28e70bb61..151f62ab57c1 100644
--- a/drivers/clk/clk_kunit_helpers.c
+++ b/drivers/clk/clk_kunit_helpers.c
@@ -233,5 +233,36 @@ int of_clk_add_hw_provider_kunit(struct kunit *test, struct device_node *np,
}
EXPORT_SYMBOL_GPL(of_clk_add_hw_provider_kunit);

+KUNIT_DEFINE_ACTION_WRAPPER(of_node_put_wrapper, of_node_put, struct device_node *);
+
+/**
+ * of_find_node_by_name_kunit() - Test managed of_find_node_by_name()
+ * @test: The test context
+ * @from: Parent device node to start searching from, or NULL to search from root
+ * @name: The name string to match against
+ *
+ * Just like of_find_node_by_name(), except the device_noded is managed by
+ * the test case and is automatically put after the test case concludes.
+ *
+ * Return: the device_node on success or a negative errno value on failure.
+ */
+struct device_node *of_find_node_by_name_kunit(struct kunit *test, struct device_node *from,
+ const char *name)
+{
+ struct device_node *np;
+ int ret;
+
+ np = of_find_node_by_name(from, name);
+ if (!np)
+ return NULL;
+
+ ret = kunit_add_action_or_reset(test, of_node_put_wrapper, np);
+ if (ret)
+ return ERR_PTR(ret);
+
+ return np;
+}
+EXPORT_SYMBOL_GPL(of_find_node_by_name_kunit);
+
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("KUnit helpers for clk providers and consumers");
diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c
index 5f3ffda033c3..bebfd928ab36 100644
--- a/drivers/clk/clk_test.c
+++ b/drivers/clk/clk_test.c
@@ -3656,10 +3656,25 @@ static void of_clk_get_parent_name_gets_parent_name(struct kunit *test)
of_clk_get_parent_name(ctx->cons_np, 0));
}

+static void of_clk_get_hw_maps_thru_nexus(struct kunit *test)
+{
+ struct clk_parse_clkspec_ctx *ctx = test->priv;
+ struct clk_hw *expected;
+ struct device_node *np;
+
+ np = of_find_node_by_name_kunit(test, NULL, "kunit-clock-nexus-child");
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, np);
+ expected = of_clk_get_hw(ctx->cons_np, 1, NULL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, expected);
+
+ KUNIT_EXPECT_PTR_EQ(test, expected, of_clk_get_hw(np, 0, NULL));
+}
+
static struct kunit_case clk_parse_clkspec_test_cases[] = {
KUNIT_CASE(clk_parse_clkspec_with_correct_index_and_name),
KUNIT_CASE(clk_parse_clkspec_with_incorrect_index_and_name),
KUNIT_CASE(of_clk_get_parent_name_gets_parent_name),
+ KUNIT_CASE(of_clk_get_hw_maps_thru_nexus),
{}
};

diff --git a/drivers/clk/kunit_clk_parse_clkspec.dtso b/drivers/clk/kunit_clk_parse_clkspec.dtso
index c93feb93e101..a4115216d2aa 100644
--- a/drivers/clk/kunit_clk_parse_clkspec.dtso
+++ b/drivers/clk/kunit_clk_parse_clkspec.dtso
@@ -18,4 +18,14 @@ kunit-clock-consumer {
clocks = <&kunit_clock_provider1 0>, <&kunit_clock_provider2 0>;
clock-names = "first_clock", "second_clock";
};
+
+ kunit_clock_nexus: kunit-clock-nexus {
+ clocks = <&kunit_clock_provider2 0>;
+ clock-map = <&kunit_clock_provider2 0>;
+ #clock-cells = <0>;
+
+ kunit-clock-nexus-child {
+ clocks = <&kunit_clock_nexus>;
+ };
+ };
};
diff --git a/include/kunit/clk.h b/include/kunit/clk.h
index f226044cc78d..ab24f7747516 100644
--- a/include/kunit/clk.h
+++ b/include/kunit/clk.h
@@ -29,5 +29,7 @@ int of_clk_hw_register_kunit(struct kunit *test, struct device_node *node,
int of_clk_add_hw_provider_kunit(struct kunit *test, struct device_node *np,
struct clk_hw *(*get)(struct of_phandle_args *clkspec, void *data),
void *data);
+struct device_node *of_find_node_by_name_kunit(struct kunit *test, struct device_node *from,
+ const char *name);

#endif

--
2.54.0

Wolfram Sang

unread,
Jul 12, 2026, 4:18:50 AMJul 12
to Miquel Raynal (Schneider Electric), Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Herve Codina
Hi Miquel,

> Then there has been a bigger series (including patches for other
> subsystems) to show the big picture, but let's split again and focus on
> one subsystem at a time:

This is a good idea IMO. Sadly, for this series, I won't have time for
review. If you have a branch available for testing, I could provide
test-tags, though.

Happy hacking,

Wolfram

signature.asc

Miquel Raynal

unread,
Jul 15, 2026, 8:55:23 AM (11 days ago) Jul 15
to Wolfram Sang, Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Herve Codina
Hello Wolfram,
We are working on adding the two other crypto algorithms in. I believe
the crypto stuff is worth testing for you as it is the one showing proof
that all the drivers work on RZN1 hardware. When we send this out we
will include a link in the cover letter with a branch to test,
connecting the clock, irqchip an crypto changes together. Don't hesitate
to remind us for that testing branch if we forget to include it!

Thanks,
Miquèl

Wolfram Sang

unread,
Jul 15, 2026, 9:59:08 AM (11 days ago) Jul 15
to Miquel Raynal, Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Herve Codina
Hi Miquel,

> that all the drivers work on RZN1 hardware. When we send this out we
> will include a link in the cover letter with a branch to test,
> connecting the clock, irqchip an crypto changes together. Don't hesitate
> to remind us for that testing branch if we forget to include it!

Will surely do. Sounds awesome, thank you! Bonus points if you could
also shorty summarize how you tested all the stuff then.

Looking forward to it,

Wolfram

signature.asc

Miquel Raynal

unread,
Jul 15, 2026, 10:43:35 AM (11 days ago) Jul 15
to Wolfram Sang, Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Herve Codina
So far I just enabled all the crypto selftests (CONFIG_CRYPTO_SELFTESTS,
CONFIG_CRYPTO_SELFTESTS_FULL). Given the amount of errors I got during
my first iterations, it seemed pretty complete :-)

Thanks,
Miquèl

Miquel Raynal (Schneider Electric)

unread,
Jul 16, 2026, 6:44:50 AM (11 days ago) Jul 16
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric), Herve Codina
Adding support for clock nexus had some prerequisites requested by
Stephen, such as adding new selftests, the initial discussions come
from:

Link: https://lore.kernel.org/linux-clk/20260129201003.288...@bootlin.com/

Changes in v3:
- Prevent out-of-bounds clock-ranges fallback in of_parse_clkspec()
- tests: Check of_clk_add_hw_provider_kunit() return value and fix node
ref leaks
- Link to v2: https://lore.kernel.org/r/20260710-schneider-v7-2-rc1-ei...@bootlin.com

Changes in v2:
- Collected tags.
- Rebased on top of v7.2-rc1
- Exported (test) clock symbols using the _IF_KUNIT() variant, and
imported the NS in the test file.
- Fixed a leaking node reported by Brian in the tests. Also used
existing helpers to simplify the test implementation as he wisely
suggested.
- Reworded the nexus node binding description as suggested by Stephen.
- Dropped redundant and non restraining properties from the Nexus
node as suggested by Rob.
- Assigned clock/clock-rate properties now traverse Nexus nodes.
- Rename helpers following Stephen proposals.
- Rework tests following Stephen hints.
- Link to v1: https://lore.kernel.org/r/20260327-schneider-v7-0-rc...@bootlin.com

Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
---
Miquel Raynal (Schneider Electric) (7):
dt-bindings: clock: Introduce nexus nodes
clk: tests: Add clk_parse_clkspec() Kunit testing
clk: tests: Add Kunit testing for of_clk_get_parent_name()
clk: Improve a couple of comments
clk: Use the generic OF phandle parsing in only one place
clk: Add support for clock nexus dt bindings
clk: tests: Add Kunit testing for nexus nodes

.../bindings/clock/clock-nexus-node.yaml | 30 +++++
drivers/clk/Makefile | 1 +
drivers/clk/clk-conf.c | 12 +-
drivers/clk/clk.c | 15 ++-
drivers/clk/clk_kunit_helpers.c | 31 +++++
drivers/clk/clk_test.c | 139 +++++++++++++++++++++
drivers/clk/kunit_clk_parse_clkspec.dtso | 31 +++++
include/kunit/clk.h | 2 +
8 files changed, 249 insertions(+), 12 deletions(-)
---
base-commit: 7f26e010764df304602f33912a0550dcf46e72c2
change-id: 20260710-schneider-v7-2-rc1-eip201-upstream-a470e5eab92d

Best regards,
--

Miquel Raynal (Schneider Electric)

unread,
Jul 16, 2026, 6:44:51 AM (11 days ago) Jul 16
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric)
Hardware containers can just decouple external resources like clock
without any more control. Nexus nodes already exist for PWM and GPIOs,
add a binding to allow them for clocks as well.

No examples are given, the file is litteraly a copy-paste from Hervé
Codina's work on PWM Nexus nodes, hence we just point to the examples
there which already illustrate very clearly the concept of the various
properties.

Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
---
.../bindings/clock/clock-nexus-node.yaml | 30 ++++++++++++++++++++++
1 file changed, 30 insertions(+)

diff --git a/Documentation/devicetree/bindings/clock/clock-nexus-node.yaml b/Documentation/devicetree/bindings/clock/clock-nexus-node.yaml
new file mode 100644

Miquel Raynal (Schneider Electric)

unread,
Jul 16, 2026, 6:44:53 AM (11 days ago) Jul 16
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric)
Create a new set of kunit tests to make sure clk_parse_clkspec() is
working as expected. We currently verify if we get a proper device when
using indexes and names. If we make an out of bounds request we expect
an error.

For testing purposes, we must ensure of_clk_get_hw()'s symbol is
exported.

Suggested-by: Stephen Boyd <sb...@kernel.org>
Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
---
drivers/clk/Makefile | 1 +
drivers/clk/clk.c | 2 +
drivers/clk/clk_test.c | 110 +++++++++++++++++++++++++++++++
drivers/clk/kunit_clk_parse_clkspec.dtso | 21 ++++++
4 files changed, 134 insertions(+)

diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index cc108a75a900..035b984db70d 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -19,6 +19,7 @@ clk-test-y := clk_test.o \
kunit_clk_assigned_rates_zero.dtbo.o \
kunit_clk_assigned_rates_zero_consumer.dtbo.o \
kunit_clk_hw_get_dev_of_node.dtbo.o \
+ kunit_clk_parse_clkspec.dtbo.o \
kunit_clk_parent_data_test.dtbo.o
obj-$(CONFIG_COMMON_CLK) += clk-divider.o
obj-$(CONFIG_COMMON_CLK) += clk-fixed-factor.o
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 048adfa86a5d..08874cf9b561 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -24,6 +24,7 @@
#include <linux/spinlock.h>
#include <linux/string.h>
#include <linux/stringhash.h>
+#include <kunit/visibility.h>

#include "clk.h"

@@ -5300,6 +5301,7 @@ struct clk_hw *of_clk_get_hw(struct device_node *np, int index,

return hw;
}
+EXPORT_SYMBOL_IF_KUNIT(of_clk_get_hw);

static struct clk *__of_clk_get(struct device_node *np,
int index, const char *dev_id,
diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c
index b1961daac5e2..f47f81b7d72a 100644
--- a/drivers/clk/clk_test.c
+++ b/drivers/clk/clk_test.c
@@ -3541,10 +3541,119 @@ static struct kunit_suite clk_hw_get_dev_of_node_test_suite = {
.test_cases = clk_hw_get_dev_of_node_test_cases,
};

+static const struct clk_init_data clk_parse_clkspec_1_init_data = {
+ .name = "clk_parse_clkspec_1",
+ .ops = &empty_clk_ops,
+};
+
+static const struct clk_init_data clk_parse_clkspec_2_init_data = {
+ .name = "clk_parse_clkspec_2",
+ .ops = &empty_clk_ops,
+};
+
+struct clk_parse_clkspec_ctx {
+ struct device_node *cons_np;
+};
+
+static int clk_parse_clkspec_init(struct kunit *test)
+{
+ struct device_node *prov1_np, *prov2_np;
+ struct clk_parse_clkspec_ctx *ctx;
+ struct clk_hw *hw1, *hw2;
+
+ ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx);
+ test->priv = ctx;
+
+ KUNIT_ASSERT_EQ(test, 0, of_overlay_apply_kunit(test, kunit_clk_parse_clkspec));
+
+ /* Register provider 1 */
+ hw1 = kunit_kzalloc(test, sizeof(*hw1), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw1);
+ hw1->init = &clk_parse_clkspec_1_init_data;
+
+ prov1_np = of_find_compatible_node(NULL, NULL, "test,clock-provider1");
+ KUNIT_ASSERT_NOT_NULL(test, prov1_np);
+ of_node_put_kunit(test, prov1_np);
+
+ KUNIT_ASSERT_EQ(test, 0, of_clk_hw_register_kunit(test, prov1_np, hw1));
+ KUNIT_ASSERT_EQ(test, 0, of_clk_add_hw_provider_kunit(test, prov1_np, of_clk_hw_simple_get, hw1));
+
+ /* Register provider 2 */
+ hw2 = kunit_kzalloc(test, sizeof(*hw2), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw2);
+ hw2->init = &clk_parse_clkspec_2_init_data;
+
+ prov2_np = of_find_compatible_node(NULL, NULL, "test,clock-provider2");
+ KUNIT_ASSERT_NOT_NULL(test, prov2_np);
+ of_node_put_kunit(test, prov2_np);
+
+ KUNIT_ASSERT_EQ(test, 0, of_clk_hw_register_kunit(test, prov2_np, hw2));
+ KUNIT_ASSERT_EQ(test, 0, of_clk_add_hw_provider_kunit(test, prov2_np, of_clk_hw_simple_get, hw2));
+
+ ctx->cons_np = of_find_compatible_node(NULL, NULL, "test,clock-consumer");
+ KUNIT_ASSERT_NOT_NULL(test, ctx->cons_np);
+ of_node_put_kunit(test, ctx->cons_np);
+
+ return 0;
+}
+
+/* Test DT phandle lookups using correct index or name succeed */
+static void clk_parse_clkspec_with_correct_index_and_name(struct kunit *test)
+{
+ struct clk_parse_clkspec_ctx *ctx = test->priv;
+ struct clk_hw *hw1, *hw2, *hw3, *hw4;
+
+ /* Get clocks by index */
+ hw1 = of_clk_get_hw(ctx->cons_np, 0, NULL);
+ KUNIT_EXPECT_NOT_ERR_OR_NULL(test, hw1);
+
+ hw2 = of_clk_get_hw(ctx->cons_np, 1, NULL);
+ KUNIT_EXPECT_NOT_ERR_OR_NULL(test, hw2);
+ KUNIT_EXPECT_PTR_NE(test, hw1, hw2);
+
+ /* Get clocks by name */
+ hw3 = of_clk_get_hw(ctx->cons_np, 0, "first_clock");
+ KUNIT_EXPECT_NOT_ERR_OR_NULL(test, hw3);
+ KUNIT_EXPECT_PTR_EQ(test, hw1, hw3);
+
+ hw4 = of_clk_get_hw(ctx->cons_np, 0, "second_clock");
+ KUNIT_EXPECT_NOT_ERR_OR_NULL(test, hw4);
+ KUNIT_EXPECT_PTR_EQ(test, hw2, hw4);
+}
+
+/* Test DT phandle lookups using wrong index or name fail */
+static void clk_parse_clkspec_with_incorrect_index_and_name(struct kunit *test)
+{
+ struct clk_parse_clkspec_ctx *ctx = test->priv;
+ struct clk_hw *hw;
+
+ /* Get clock by index */
+ hw = of_clk_get_hw(ctx->cons_np, 2, NULL);
+ KUNIT_EXPECT_TRUE(test, IS_ERR(hw));
+
+ /* Get clock by name */
+ hw = of_clk_get_hw(ctx->cons_np, 0, "third_clock");
+ KUNIT_EXPECT_TRUE(test, IS_ERR(hw));
+}
+
+static struct kunit_case clk_parse_clkspec_test_cases[] = {
+ KUNIT_CASE(clk_parse_clkspec_with_correct_index_and_name),
+ KUNIT_CASE(clk_parse_clkspec_with_incorrect_index_and_name),
+ {}
+};
+
+/* Test suite to verify clk_parse_clkspec() */
+static struct kunit_suite clk_parse_clkspec_test_suite = {
+ .name = "clk_parse_clkspec",
+ .init = clk_parse_clkspec_init,
+ .test_cases = clk_parse_clkspec_test_cases,
+};

kunit_test_suites(
&clk_assigned_rates_suite,
&clk_hw_get_dev_of_node_test_suite,
+ &clk_parse_clkspec_test_suite,
&clk_leaf_mux_set_rate_parent_test_suite,
&clk_test_suite,
&clk_multiple_parents_mux_test_suite,
@@ -3562,4 +3671,5 @@ kunit_test_suites(
&clk_uncached_test_suite,
);
MODULE_DESCRIPTION("Kunit tests for clk framework");
+MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
MODULE_LICENSE("GPL v2");
diff --git a/drivers/clk/kunit_clk_parse_clkspec.dtso b/drivers/clk/kunit_clk_parse_clkspec.dtso
new file mode 100644
index 000000000000..c93feb93e101
--- /dev/null
+++ b/drivers/clk/kunit_clk_parse_clkspec.dtso
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0
+/dts-v1/;
+/plugin/;
+
+&{/} {
+ kunit_clock_provider1: kunit-clock-provider1 {
+ compatible = "test,clock-provider1";
+ #clock-cells = <1>;
+ };
+
+ kunit_clock_provider2: kunit-clock-provider2 {
+ compatible = "test,clock-provider2";
+ #clock-cells = <1>;
+ };
+
+ kunit-clock-consumer {
+ compatible = "test,clock-consumer";
+ clocks = <&kunit_clock_provider1 0>, <&kunit_clock_provider2 0>;
+ clock-names = "first_clock", "second_clock";
+ };
+};

--
2.54.0

Miquel Raynal (Schneider Electric)

unread,
Jul 16, 2026, 6:44:54 AM (11 days ago) Jul 16
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric)
Make sure this helper is never broken, especially since we will soon
make some changes in it.

Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
---
drivers/clk/clk_test.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c
index f47f81b7d72a..4084559e157d 100644
--- a/drivers/clk/clk_test.c
+++ b/drivers/clk/clk_test.c
@@ -3637,9 +3637,23 @@ static void clk_parse_clkspec_with_incorrect_index_and_name(struct kunit *test)
KUNIT_EXPECT_TRUE(test, IS_ERR(hw));
}

+/*
+ * Verify that of_clk_get_parent_name() returns the correct clock name when
+ * looking up by index through the consumer's clocks property.
+ */
+static void of_clk_get_parent_name_gets_parent_name(struct kunit *test)
+{
+ struct clk_parse_clkspec_ctx *ctx = test->priv;
+ const char *expected_name = "clk_parse_clkspec_1";
+
+ KUNIT_EXPECT_STREQ(test, expected_name,
+ of_clk_get_parent_name(ctx->cons_np, 0));
+}
+
static struct kunit_case clk_parse_clkspec_test_cases[] = {
KUNIT_CASE(clk_parse_clkspec_with_correct_index_and_name),
KUNIT_CASE(clk_parse_clkspec_with_incorrect_index_and_name),
+ KUNIT_CASE(of_clk_get_parent_name_gets_parent_name),
{}
};


--
2.54.0

Miquel Raynal (Schneider Electric)

unread,
Jul 16, 2026, 6:44:56 AM (11 days ago) Jul 16
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric)
Avoid mentioning the function names directly in the comments, it makes
them easily out of sync with the rest of the code. Use a more generic
wording.

Suggested-by: Stephen Boyd <sb...@kernel.org>
Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
Reviewed-by: Brian Masney <bma...@redhat.com>
---
drivers/clk/clk.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 08874cf9b561..7d63d81ebc09 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c

Miquel Raynal (Schneider Electric)

unread,
Jul 16, 2026, 6:44:57 AM (11 days ago) Jul 16
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric)
There should be one single entry in the OF world, so that the way we
parse the DT is always the same. make sure this is the case by avoid
calling of_parse_phandle_with_args() from of_clk_get_parent_name(). This
is even more relevant as we currently fail to parse clock-ranges. As a
result, it seems to be safer to directly call of_parse_clkspec() there,
but doing so implies that we do not try the "clock-ranges" path if we
already found a "clocks" property..

Suggested-by: Stephen Boyd <sb...@kernel.org>
Fixes: 4472287a3b2f5 ("clk: Introduce of_clk_get_hw_from_clkspec()")
Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
Reviewed-by: Brian Masney <bma...@redhat.com>
---
drivers/clk/clk.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 7d63d81ebc09..45f5d7a4ccc1 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -5219,6 +5219,8 @@ static int of_parse_clkspec(const struct device_node *np, int index,
* has a "clock-ranges" property, then we can try one of its
* clocks.
*/
+ if (of_property_present(np, "clocks"))
+ break;
np = np->parent;
if (np && !of_property_present(np, "clock-ranges"))
break;
@@ -5364,8 +5366,7 @@ const char *of_clk_get_parent_name(const struct device_node *np, int index)

Miquel Raynal (Schneider Electric)

unread,
Jul 16, 2026, 6:45:00 AM (11 days ago) Jul 16
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric), Herve Codina
Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
Reviewed-by: Herve Codina <herve....@bootlin.com>
Reviewed-by: Brian Masney <bma...@redhat.com>
---
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 45f5d7a4ccc1..6acf042673c3 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c

Miquel Raynal (Schneider Electric)

unread,
Jul 16, 2026, 6:45:01 AM (11 days ago) Jul 16
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric)
Add a nexus node with a child requesting a mapped clock in the fake DT
overlay to verify that the parsing is also correctly working.

Suggested-by: Stephen Boyd <sb...@kernel.org>
Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
---
diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c
index 4084559e157d..0c2f1efdaa8e 100644
--- a/drivers/clk/clk_test.c
+++ b/drivers/clk/clk_test.c
@@ -3650,10 +3650,25 @@ static void of_clk_get_parent_name_gets_parent_name(struct kunit *test)
of_clk_get_parent_name(ctx->cons_np, 0));
}

+static void of_clk_get_hw_maps_thru_nexus(struct kunit *test)
+{
+ struct clk_parse_clkspec_ctx *ctx = test->priv;
+ struct clk_hw *expected;
+ struct device_node *np;
+
+ np = of_find_node_by_name_kunit(test, NULL, "kunit-clock-nexus-child");
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, np);
+ expected = of_clk_get_hw(ctx->cons_np, 1, NULL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, expected);
+
+ KUNIT_EXPECT_PTR_EQ(test, expected, of_clk_get_hw(np, 0, NULL));
+}
+
static struct kunit_case clk_parse_clkspec_test_cases[] = {
KUNIT_CASE(clk_parse_clkspec_with_correct_index_and_name),
KUNIT_CASE(clk_parse_clkspec_with_incorrect_index_and_name),
KUNIT_CASE(of_clk_get_parent_name_gets_parent_name),
+ KUNIT_CASE(of_clk_get_hw_maps_thru_nexus),
{}
};

diff --git a/drivers/clk/kunit_clk_parse_clkspec.dtso b/drivers/clk/kunit_clk_parse_clkspec.dtso
index c93feb93e101..a4115216d2aa 100644
--- a/drivers/clk/kunit_clk_parse_clkspec.dtso
+++ b/drivers/clk/kunit_clk_parse_clkspec.dtso
@@ -18,4 +18,14 @@ kunit-clock-consumer {
clocks = <&kunit_clock_provider1 0>, <&kunit_clock_provider2 0>;
clock-names = "first_clock", "second_clock";
};
+

Miquel Raynal (Schneider Electric)

unread,
Jul 17, 2026, 11:59:33 AM (9 days ago) Jul 17
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric), Herve Codina
Adding support for clock nexus had some prerequisites requested by
Stephen, such as adding new selftests, the initial discussions come
from:

Link: https://lore.kernel.org/linux-clk/20260129201003.288...@bootlin.com/

Changes in v4:
- Fixed the kernel doc of of_find_node_by_name_kunit() which was lacking
the fact that it could return NULL upon lookup failure. Also improved
the commit message by mentioning the addition of that helper.
- All other Sashiko reports have either been disregarded because they
were way too unrelated or just not relevant enough in my opinion.
- Link to v3: https://lore.kernel.org/r/20260716-schneider-v7-2-rc1-ei...@bootlin.com

Changes in v3:
- Prevent out-of-bounds clock-ranges fallback in of_parse_clkspec()
- tests: Check of_clk_add_hw_provider_kunit() return value and fix node
ref leaks
- Link to v2: https://lore.kernel.org/r/20260710-schneider-v7-2-rc1-ei...@bootlin.com

Changes in v2:
- Collected tags.
- Rebased on top of v7.2-rc1
- Exported (test) clock symbols using the _IF_KUNIT() variant, and
imported the NS in the test file.
- Fixed a leaking node reported by Brian in the tests. Also used
existing helpers to simplify the test implementation as he wisely
suggested.
- Reworded the nexus node binding description as suggested by Stephen.
- Dropped redundant and non restraining properties from the Nexus
node as suggested by Rob.
- Assigned clock/clock-rate properties now traverse Nexus nodes.
- Rename helpers following Stephen proposals.
- Rework tests following Stephen hints.
- Link to v1: https://lore.kernel.org/r/20260327-schneider-v7-0-rc...@bootlin.com

Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
---
Miquel Raynal (Schneider Electric) (7):
dt-bindings: clock: Introduce nexus nodes
clk: tests: Add clk_parse_clkspec() Kunit testing
clk: tests: Add Kunit testing for of_clk_get_parent_name()
clk: Improve a couple of comments
clk: Use the generic OF phandle parsing in only one place
clk: Add support for clock nexus dt bindings
clk: tests: Add Kunit testing for nexus nodes

.../bindings/clock/clock-nexus-node.yaml | 30 +++++
drivers/clk/Makefile | 1 +
drivers/clk/clk-conf.c | 12 +-
drivers/clk/clk.c | 15 ++-
drivers/clk/clk_kunit_helpers.c | 31 +++++
drivers/clk/clk_test.c | 139 +++++++++++++++++++++
drivers/clk/kunit_clk_parse_clkspec.dtso | 31 +++++
include/kunit/clk.h | 2 +
8 files changed, 249 insertions(+), 12 deletions(-)
---
base-commit: 7f26e010764df304602f33912a0550dcf46e72c2
change-id: 20260710-schneider-v7-2-rc1-eip201-upstream-a470e5eab92d

Best regards,
--

Miquel Raynal (Schneider Electric)

unread,
Jul 17, 2026, 11:59:35 AM (9 days ago) Jul 17
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric)
Hardware containers can just decouple external resources like clock
without any more control. Nexus nodes already exist for PWM and GPIOs,
add a binding to allow them for clocks as well.

No examples are given, the file is litteraly a copy-paste from Hervé
Codina's work on PWM Nexus nodes, hence we just point to the examples
there which already illustrate very clearly the concept of the various
properties.

Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
---
.../bindings/clock/clock-nexus-node.yaml | 30 ++++++++++++++++++++++
1 file changed, 30 insertions(+)

diff --git a/Documentation/devicetree/bindings/clock/clock-nexus-node.yaml b/Documentation/devicetree/bindings/clock/clock-nexus-node.yaml
new file mode 100644

Miquel Raynal (Schneider Electric)

unread,
Jul 17, 2026, 11:59:37 AM (9 days ago) Jul 17
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric)
Create a new set of kunit tests to make sure clk_parse_clkspec() is
working as expected. We currently verify if we get a proper device when
using indexes and names. If we make an out of bounds request we expect
an error.

For testing purposes, we must ensure of_clk_get_hw()'s symbol is
exported.

Suggested-by: Stephen Boyd <sb...@kernel.org>
Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
---
drivers/clk/Makefile | 1 +
drivers/clk/clk.c | 2 +
drivers/clk/clk_test.c | 110 +++++++++++++++++++++++++++++++
drivers/clk/kunit_clk_parse_clkspec.dtso | 21 ++++++
4 files changed, 134 insertions(+)

diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index cc108a75a900..035b984db70d 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -19,6 +19,7 @@ clk-test-y := clk_test.o \
kunit_clk_assigned_rates_zero.dtbo.o \
kunit_clk_assigned_rates_zero_consumer.dtbo.o \
kunit_clk_hw_get_dev_of_node.dtbo.o \
+ kunit_clk_parse_clkspec.dtbo.o \
kunit_clk_parent_data_test.dtbo.o
obj-$(CONFIG_COMMON_CLK) += clk-divider.o
obj-$(CONFIG_COMMON_CLK) += clk-fixed-factor.o
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 048adfa86a5d..08874cf9b561 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -24,6 +24,7 @@
#include <linux/spinlock.h>
#include <linux/string.h>
#include <linux/stringhash.h>
+#include <kunit/visibility.h>

#include "clk.h"

@@ -5300,6 +5301,7 @@ struct clk_hw *of_clk_get_hw(struct device_node *np, int index,

return hw;
}
+EXPORT_SYMBOL_IF_KUNIT(of_clk_get_hw);

static struct clk *__of_clk_get(struct device_node *np,
int index, const char *dev_id,
diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c
index b1961daac5e2..f47f81b7d72a 100644
--- a/drivers/clk/clk_test.c
+++ b/drivers/clk/clk_test.c
@@ -3541,10 +3541,119 @@ static struct kunit_suite clk_hw_get_dev_of_node_test_suite = {
.test_cases = clk_hw_get_dev_of_node_test_cases,
};

+static const struct clk_init_data clk_parse_clkspec_1_init_data = {
+ .name = "clk_parse_clkspec_1",
+ .ops = &empty_clk_ops,
+};
+
+static const struct clk_init_data clk_parse_clkspec_2_init_data = {
+ .name = "clk_parse_clkspec_2",
+ .ops = &empty_clk_ops,
+};
+
+struct clk_parse_clkspec_ctx {
+ struct device_node *cons_np;
+};
+
+static int clk_parse_clkspec_init(struct kunit *test)
+{
+static void clk_parse_clkspec_with_correct_index_and_name(struct kunit *test)
+{
+ struct clk_parse_clkspec_ctx *ctx = test->priv;
+ struct clk_hw *hw1, *hw2, *hw3, *hw4;
+
+ /* Get clocks by index */
+ hw1 = of_clk_get_hw(ctx->cons_np, 0, NULL);
+ KUNIT_EXPECT_NOT_ERR_OR_NULL(test, hw1);
+
+ hw2 = of_clk_get_hw(ctx->cons_np, 1, NULL);
+ KUNIT_EXPECT_NOT_ERR_OR_NULL(test, hw2);
+ KUNIT_EXPECT_PTR_NE(test, hw1, hw2);
+
+ /* Get clocks by name */
+ hw3 = of_clk_get_hw(ctx->cons_np, 0, "first_clock");
+ KUNIT_EXPECT_NOT_ERR_OR_NULL(test, hw3);
+ KUNIT_EXPECT_PTR_EQ(test, hw1, hw3);
+
+ hw4 = of_clk_get_hw(ctx->cons_np, 0, "second_clock");
+ KUNIT_EXPECT_NOT_ERR_OR_NULL(test, hw4);
+ KUNIT_EXPECT_PTR_EQ(test, hw2, hw4);
+}
+
+/* Test DT phandle lookups using wrong index or name fail */
+static void clk_parse_clkspec_with_incorrect_index_and_name(struct kunit *test)
+{
+ struct clk_parse_clkspec_ctx *ctx = test->priv;
new file mode 100644
index 000000000000..c93feb93e101
--- /dev/null
+++ b/drivers/clk/kunit_clk_parse_clkspec.dtso
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0
+/dts-v1/;
+/plugin/;
+
+&{/} {
+ kunit_clock_provider1: kunit-clock-provider1 {
+ compatible = "test,clock-provider1";
+ #clock-cells = <1>;
+ };
+
+ kunit_clock_provider2: kunit-clock-provider2 {
+ compatible = "test,clock-provider2";
+ #clock-cells = <1>;
+ };
+
+ kunit-clock-consumer {
+ compatible = "test,clock-consumer";
+ clocks = <&kunit_clock_provider1 0>, <&kunit_clock_provider2 0>;
+ clock-names = "first_clock", "second_clock";
+ };
+};

--
2.54.0

Miquel Raynal (Schneider Electric)

unread,
Jul 17, 2026, 11:59:39 AM (9 days ago) Jul 17
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric)
Make sure this helper is never broken, especially since we will soon
make some changes in it.

Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
---
drivers/clk/clk_test.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c
index f47f81b7d72a..4084559e157d 100644
--- a/drivers/clk/clk_test.c
+++ b/drivers/clk/clk_test.c
@@ -3637,9 +3637,23 @@ static void clk_parse_clkspec_with_incorrect_index_and_name(struct kunit *test)
KUNIT_EXPECT_TRUE(test, IS_ERR(hw));
}

+/*
+ * Verify that of_clk_get_parent_name() returns the correct clock name when
+ * looking up by index through the consumer's clocks property.
+ */
+static void of_clk_get_parent_name_gets_parent_name(struct kunit *test)
+{
+ struct clk_parse_clkspec_ctx *ctx = test->priv;
+ const char *expected_name = "clk_parse_clkspec_1";
+
+ KUNIT_EXPECT_STREQ(test, expected_name,
+ of_clk_get_parent_name(ctx->cons_np, 0));
+}
+
static struct kunit_case clk_parse_clkspec_test_cases[] = {
KUNIT_CASE(clk_parse_clkspec_with_correct_index_and_name),
KUNIT_CASE(clk_parse_clkspec_with_incorrect_index_and_name),
+ KUNIT_CASE(of_clk_get_parent_name_gets_parent_name),
{}
};


--
2.54.0

Miquel Raynal (Schneider Electric)

unread,
Jul 17, 2026, 11:59:42 AM (9 days ago) Jul 17
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric)
Avoid mentioning the function names directly in the comments, it makes
them easily out of sync with the rest of the code. Use a more generic
wording.

Suggested-by: Stephen Boyd <sb...@kernel.org>
Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
Reviewed-by: Brian Masney <bma...@redhat.com>
---
drivers/clk/clk.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 08874cf9b561..7d63d81ebc09 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c

Miquel Raynal (Schneider Electric)

unread,
Jul 17, 2026, 11:59:44 AM (9 days ago) Jul 17
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric)
There should be one single entry in the OF world, so that the way we
parse the DT is always the same. make sure this is the case by avoid
calling of_parse_phandle_with_args() from of_clk_get_parent_name(). This
is even more relevant as we currently fail to parse clock-ranges. As a
result, it seems to be safer to directly call of_parse_clkspec() there,
but doing so implies that we do not try the "clock-ranges" path if we
already found a "clocks" property..

Suggested-by: Stephen Boyd <sb...@kernel.org>
Fixes: 4472287a3b2f5 ("clk: Introduce of_clk_get_hw_from_clkspec()")
Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
Reviewed-by: Brian Masney <bma...@redhat.com>
---
drivers/clk/clk.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 7d63d81ebc09..45f5d7a4ccc1 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c

Miquel Raynal (Schneider Electric)

unread,
Jul 17, 2026, 11:59:45 AM (9 days ago) Jul 17
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric), Herve Codina
Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
Reviewed-by: Herve Codina <herve....@bootlin.com>
Reviewed-by: Brian Masney <bma...@redhat.com>
---
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 45f5d7a4ccc1..6acf042673c3 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c

Miquel Raynal (Schneider Electric)

unread,
Jul 17, 2026, 11:59:48 AM (9 days ago) Jul 17
to Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Miquel Raynal (Schneider Electric)
Add a nexus node with a child requesting a mapped clock in the fake DT
overlay to verify that the parsing is also correctly working.

Create an of_find_node_by_name() like kunit helper to garbage collect the
node automatically in case of failed assertion.

Suggested-by: Stephen Boyd <sb...@kernel.org>
Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
---
drivers/clk/clk_kunit_helpers.c | 31 +++++++++++++++++++++++++++++++
drivers/clk/clk_test.c | 15 +++++++++++++++
drivers/clk/kunit_clk_parse_clkspec.dtso | 10 ++++++++++
include/kunit/clk.h | 2 ++
4 files changed, 58 insertions(+)

diff --git a/drivers/clk/clk_kunit_helpers.c b/drivers/clk/clk_kunit_helpers.c
index 68a28e70bb61..daaf1cf1546c 100644
--- a/drivers/clk/clk_kunit_helpers.c
+++ b/drivers/clk/clk_kunit_helpers.c
@@ -233,5 +233,36 @@ int of_clk_add_hw_provider_kunit(struct kunit *test, struct device_node *np,
}
EXPORT_SYMBOL_GPL(of_clk_add_hw_provider_kunit);

+KUNIT_DEFINE_ACTION_WRAPPER(of_node_put_wrapper, of_node_put, struct device_node *);
+
+/**
+ * of_find_node_by_name_kunit() - Test managed of_find_node_by_name()
+ * @test: The test context
+ * @from: Parent device node to start searching from, or NULL to search from root
+ * @name: The name string to match against
+ *
+ * Just like of_find_node_by_name(), except the device_noded is managed by
+ * the test case and is automatically put after the test case concludes.
+ *
+ * Return: the device_node on success, NULL if not found, or a negative errno value on failure.
+ */
+struct device_node *of_find_node_by_name_kunit(struct kunit *test, struct device_node *from,
+ const char *name)
+{
+ struct device_node *np;
+ int ret;
+
+ np = of_find_node_by_name(from, name);
+ if (!np)
+ return NULL;
+
+ ret = kunit_add_action_or_reset(test, of_node_put_wrapper, np);
+ if (ret)
+ return ERR_PTR(ret);
+
+ return np;
+}
+EXPORT_SYMBOL_GPL(of_find_node_by_name_kunit);
+
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("KUnit helpers for clk providers and consumers");
diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c
index 4084559e157d..0c2f1efdaa8e 100644
--- a/drivers/clk/clk_test.c
+++ b/drivers/clk/clk_test.c
@@ -3650,10 +3650,25 @@ static void of_clk_get_parent_name_gets_parent_name(struct kunit *test)
of_clk_get_parent_name(ctx->cons_np, 0));
}

+static void of_clk_get_hw_maps_thru_nexus(struct kunit *test)
+{
+ struct clk_parse_clkspec_ctx *ctx = test->priv;
+ struct clk_hw *expected;
+ struct device_node *np;
+
+ np = of_find_node_by_name_kunit(test, NULL, "kunit-clock-nexus-child");
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, np);
+ expected = of_clk_get_hw(ctx->cons_np, 1, NULL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, expected);
+
+ KUNIT_EXPECT_PTR_EQ(test, expected, of_clk_get_hw(np, 0, NULL));
+}
+
static struct kunit_case clk_parse_clkspec_test_cases[] = {
KUNIT_CASE(clk_parse_clkspec_with_correct_index_and_name),
KUNIT_CASE(clk_parse_clkspec_with_incorrect_index_and_name),
KUNIT_CASE(of_clk_get_parent_name_gets_parent_name),
+ KUNIT_CASE(of_clk_get_hw_maps_thru_nexus),
{}
};

diff --git a/drivers/clk/kunit_clk_parse_clkspec.dtso b/drivers/clk/kunit_clk_parse_clkspec.dtso
index c93feb93e101..a4115216d2aa 100644
--- a/drivers/clk/kunit_clk_parse_clkspec.dtso
+++ b/drivers/clk/kunit_clk_parse_clkspec.dtso
@@ -18,4 +18,14 @@ kunit-clock-consumer {
clocks = <&kunit_clock_provider1 0>, <&kunit_clock_provider2 0>;
clock-names = "first_clock", "second_clock";
};
+

Brian Masney

unread,
Jul 21, 2026, 6:28:01 PM (5 days ago) Jul 21
to Miquel Raynal (Schneider Electric), Michael Turquette, Stephen Boyd, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com
On Fri, Jul 17, 2026 at 05:59:18PM +0200, Miquel Raynal (Schneider Electric) wrote:
> Create a new set of kunit tests to make sure clk_parse_clkspec() is
> working as expected. We currently verify if we get a proper device when
> using indexes and names. If we make an out of bounds request we expect
> an error.
>
> For testing purposes, we must ensure of_clk_get_hw()'s symbol is
> exported.
>
> Suggested-by: Stephen Boyd <sb...@kernel.org>
> Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>

Reviewed-by: Brian Masney <bma...@redhat.com>

Brian Masney

unread,
Jul 21, 2026, 6:28:47 PM (5 days ago) Jul 21
to Miquel Raynal (Schneider Electric), Michael Turquette, Stephen Boyd, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com
On Fri, Jul 17, 2026 at 05:59:19PM +0200, Miquel Raynal (Schneider Electric) wrote:
> Make sure this helper is never broken, especially since we will soon
> make some changes in it.
>
> Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>

Reviewed-by: Brian Masney <bma...@redhat.com>

Brian Masney

unread,
Jul 21, 2026, 6:32:46 PM (5 days ago) Jul 21
to Miquel Raynal (Schneider Electric), Michael Turquette, Stephen Boyd, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com
Should this be prefixed with clk_ since this is in clk_kunit_helpers.c?

Other than this, the whole series looks reasonable to me. I'm curious
though to get Stephen's feedback about this series.

Brian

Rob Herring (Arm)

unread,
Jul 22, 2026, 3:34:19 PM (4 days ago) Jul 22
to Miquel Raynal (Schneider Electric), Brian Masney, Michael Turquette, David Gow, Wolfram Sang, Brendan Higgins, Thomas Petazzoni, kuni...@googlegroups.com, Rae Moar, linux-k...@vger.kernel.org, Stephen Boyd, Krzysztof Kozlowski, linux-...@vger.kernel.org, devic...@vger.kernel.org, linu...@vger.kernel.org, Pascal EBERHARD, Conor Dooley

On Fri, 17 Jul 2026 17:59:17 +0200, Miquel Raynal (Schneider Electric) wrote:
> Hardware containers can just decouple external resources like clock
> without any more control. Nexus nodes already exist for PWM and GPIOs,
> add a binding to allow them for clocks as well.
>
> No examples are given, the file is litteraly a copy-paste from Hervé
> Codina's work on PWM Nexus nodes, hence we just point to the examples
> there which already illustrate very clearly the concept of the various
> properties.
>
> Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
> ---
> .../bindings/clock/clock-nexus-node.yaml | 30 ++++++++++++++++++++++
> 1 file changed, 30 insertions(+)
>

Reviewed-by: Rob Herring (Arm) <ro...@kernel.org>

Frank Li

unread,
Jul 24, 2026, 2:14:59 PM (2 days ago) Jul 24
to Miquel Raynal (Schneider Electric), Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com
On Fri, Jul 17, 2026 at 05:59:17PM +0200, Miquel Raynal (Schneider Electric) wrote:
> Hardware containers can just decouple external resources like clock
> without any more control. Nexus nodes already exist for PWM and GPIOs,
> add a binding to allow them for clocks as well.
>
> No examples are given, the file is litteraly a copy-paste from Hervé
> Codina's work on PWM Nexus nodes, hence we just point to the examples
> there which already illustrate very clearly the concept of the various
> properties.
>
> Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
> ---

Reviewed-by: Frank Li <Fran...@nxp.com>

Frank Li

unread,
Jul 24, 2026, 2:16:47 PM (2 days ago) Jul 24
to Miquel Raynal (Schneider Electric), Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com
On Fri, Jul 17, 2026 at 05:59:18PM +0200, Miquel Raynal (Schneider Electric) wrote:
> Create a new set of kunit tests to make sure clk_parse_clkspec() is
> working as expected. We currently verify if we get a proper device when
> using indexes and names. If we make an out of bounds request we expect
> an error.
>
> For testing purposes, we must ensure of_clk_get_hw()'s symbol is
> exported.
>
> Suggested-by: Stephen Boyd <sb...@kernel.org>
> Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
> ---

Reviewed-by: Frank Li <Fran...@nxp.com>

Frank Li

unread,
Jul 24, 2026, 2:19:42 PM (2 days ago) Jul 24
to Miquel Raynal (Schneider Electric), Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com
On Fri, Jul 17, 2026 at 05:59:19PM +0200, Miquel Raynal (Schneider Electric) wrote:
> Make sure this helper is never broken, especially since we will soon
> make some changes in it.

Nit: Ensure this helper remains correct before making upcoming changes to it.

Reviewed-by: Frank Li <Fran...@nxp.com>

Frank Li

unread,
Jul 24, 2026, 2:27:04 PM (2 days ago) Jul 24
to Miquel Raynal (Schneider Electric), Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Herve Codina
On Fri, Jul 17, 2026 at 05:59:16PM +0200, Miquel Raynal (Schneider Electric) wrote:
> Adding support for clock nexus had some prerequisites requested by
> Stephen, such as adding new selftests, the initial discussions come
> from:

Please add me to CC list at the next version. we are waiting for this patch
set.

Frank

Frank Li

unread,
Jul 24, 2026, 2:30:39 PM (2 days ago) Jul 24
to Miquel Raynal (Schneider Electric), Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, Herve Codina
Reviewed-by: Frank Li <Fran...@nxp.com>

Frank Li

unread,
Jul 24, 2026, 2:32:02 PM (2 days ago) Jul 24
to Miquel Raynal (Schneider Electric), Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com
On Fri, Jul 17, 2026 at 05:59:23PM +0200, Miquel Raynal (Schneider Electric) wrote:
> Add a nexus node with a child requesting a mapped clock in the fake DT
> overlay to verify that the parsing is also correctly working.
>
> Create an of_find_node_by_name() like kunit helper to garbage collect the
> node automatically in case of failed assertion.
>
> Suggested-by: Stephen Boyd <sb...@kernel.org>
> Signed-off-by: Miquel Raynal (Schneider Electric) <miquel...@bootlin.com>
> ---

Reviewed-by: Frank Li <Fran...@nxp.com>

Frank Li

unread,
Jul 24, 2026, 2:35:54 PM (2 days ago) Jul 24
to Miquel Raynal (Schneider Electric), Michael Turquette, Stephen Boyd, Brian Masney, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Brendan Higgins, David Gow, Rae Moar, Thomas Petazzoni, Pascal EBERHARD, Wolfram Sang, linu...@vger.kernel.org, devic...@vger.kernel.org, linux-...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com
On Fri, Jul 17, 2026 at 05:59:21PM +0200, Miquel Raynal (Schneider Electric) wrote:
> There should be one single entry in the OF world, so that the way we
> parse the DT is always the same. make sure this is the case by avoid
> calling of_parse_phandle_with_args() from of_clk_get_parent_name(). This
> is even more relevant as we currently fail to parse clock-ranges. As a
> result, it seems to be safer to directly call of_parse_clkspec() there,
> but doing so implies that we do not try the "clock-ranges" path if we
> already found a "clocks" property..

Sorry, I can't understand well what commit said.

Replaces the use of of_parse_phandle_with_args() with
of_parse_clkspec() inside of_clk_get_parent_name(). It also modifies
of_parse_clkspec() to stop traversing up the device tree if a "clocks"
property is found.

Is AI's words what you means?

Frank
Reply all
Reply to author
Forward
0 new messages