* [PATCH 0/2] clk: add a clk_hw helpers to get the clock device or device_node
@ 2025-04-17 13:44 Jerome Brunet
2025-04-17 13:44 ` [PATCH 1/2] " Jerome Brunet
` (3 more replies)
0 siblings, 4 replies; 11+ messages in thread
From: Jerome Brunet @ 2025-04-17 13:44 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd; +Cc: linux-clk, linux-kernel, Jerome Brunet
This patchset adds helpers to get the device or device_node associated with
clk_hw. This can be used by clock drivers to access various device related
functionality. The 2nd changes adds kunit test coverage for the new helpers
This patchset is the v4 of the series previously sent here [1], with the
amlogic patches dropped for now. I'll resume the work on the amlogic
changes when the helpers are available in CCF core.
Added tests run example:
KTAP version 1
# Subtest: clk_hw_register_get_dev_of_node_test_suite
# module: clk_test
1..2
KTAP version 1
# Subtest: clk_hw_register_get_dev_test
ok 1 clock with device reference
ok 2 clock missing device reference
# clk_hw_register_get_dev_test: pass:2 fail:0 skip:0 total:2
ok 1 clk_hw_register_get_dev_test
KTAP version 1
# Subtest: clk_hw_register_get_of_node_test
ok 1 clock with device reference
ok 2 clock missing device reference
# clk_hw_register_get_of_node_test: pass:2 fail:0 skip:0 total:2
ok 2 clk_hw_register_get_of_node_test
# clk_hw_register_get_dev_of_node_test_suite: pass:2 fail:0 skip:0 total:2
# Totals: pass:4 fail:0 skip:0 total:4
ok 17 clk_hw_register_get_dev_of_node_test_suite
KTAP version 1
# Subtest: of_clk_hw_register_get_dev_of_node_test_suite
# module: clk_test
1..2
KTAP version 1
# Subtest: of_clk_hw_register_get_dev_test
ok 1 clock with of_node reference
ok 2 clock missing of_node reference
# of_clk_hw_register_get_dev_test: pass:2 fail:0 skip:0 total:2
ok 1 of_clk_hw_register_get_dev_test
KTAP version 1
# Subtest: of_clk_hw_register_get_of_node_test
ok 1 clock with of_node reference
ok 2 clock missing of_node reference
# of_clk_hw_register_get_of_node_test: pass:2 fail:0 skip:0 total:2
ok 2 of_clk_hw_register_get_of_node_test
# of_clk_hw_register_get_dev_of_node_test_suite: pass:2 fail:0 skip:0 total:2
# Totals: pass:4 fail:0 skip:0 total:4
[1]: https://lore.kernel.org/linux-clk/20250120-amlogic-clk-drop-clk-regmap-tables-v3-0-126244146947@baylibre.com
Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
---
Jerome Brunet (2):
clk: add a clk_hw helpers to get the clock device or device_node
clk: tests: add clk_hw_get_dev() and clk_hw_get_of_node() tests
drivers/clk/Makefile | 1 +
drivers/clk/clk.c | 12 ++
drivers/clk/clk_test.c | 215 ++++++++++++++++++++++++--
drivers/clk/kunit_clk_hw_get_dev_of_node.dtso | 10 ++
include/linux/clk-provider.h | 26 ++++
5 files changed, 247 insertions(+), 17 deletions(-)
---
base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8
change-id: 20250415-clk-hw-get-helpers-c2344d404f3c
Best regards,
--
Jerome
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/2] clk: add a clk_hw helpers to get the clock device or device_node
2025-04-17 13:44 [PATCH 0/2] clk: add a clk_hw helpers to get the clock device or device_node Jerome Brunet
@ 2025-04-17 13:44 ` Jerome Brunet
2025-05-05 9:33 ` Jerome Brunet
` (2 more replies)
2025-04-17 13:44 ` [PATCH 2/2] clk: tests: add clk_hw_get_dev() and clk_hw_get_of_node() tests Jerome Brunet
` (2 subsequent siblings)
3 siblings, 3 replies; 11+ messages in thread
From: Jerome Brunet @ 2025-04-17 13:44 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd; +Cc: linux-clk, linux-kernel, Jerome Brunet
Add helpers to get the device or device_node associated with clk_hw.
This can be used by clock drivers to access various device related
functionality such as devres, dev_ prints, etc ...
Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
---
drivers/clk/clk.c | 12 ++++++++++++
include/linux/clk-provider.h | 26 ++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 0565c87656cf5c557d8259c71b5d2971a7ac87e8..b821b2cdb155331c85fafbd2fac8ab3703a08e4d 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -365,6 +365,18 @@ const char *clk_hw_get_name(const struct clk_hw *hw)
}
EXPORT_SYMBOL_GPL(clk_hw_get_name);
+struct device *clk_hw_get_dev(const struct clk_hw *hw)
+{
+ return hw->core->dev;
+}
+EXPORT_SYMBOL_GPL(clk_hw_get_dev);
+
+struct device_node *clk_hw_get_of_node(const struct clk_hw *hw)
+{
+ return hw->core->of_node;
+}
+EXPORT_SYMBOL_GPL(clk_hw_get_of_node);
+
struct clk_hw *__clk_get_hw(struct clk *clk)
{
return !clk ? NULL : clk->core->hw;
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index 2e6e603b749342931c0d0693c3e72b62c000791b..630705a47129453c241f1b1755f2c2f2a7ed8f77 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -1360,6 +1360,32 @@ void clk_hw_unregister(struct clk_hw *hw);
/* helper functions */
const char *__clk_get_name(const struct clk *clk);
const char *clk_hw_get_name(const struct clk_hw *hw);
+
+/**
+ * clk_hw_get_dev() - get device from an hardware clock.
+ * @hw: the clk_hw pointer to get the struct device from
+ *
+ * This is a helper to get the struct device associated with a hardware
+ * clock. Some clock controllers, such as the one registered with
+ * CLK_OF_DECLARE(), may have not provided a device pointer while
+ * registering the clock.
+ *
+ * Return: the struct device associated with the clock, or NULL if there
+ * is none.
+ */
+struct device *clk_hw_get_dev(const struct clk_hw *hw);
+
+/**
+ * clk_hw_get_of_node() - get device_node from a hardware clock.
+ * @hw: the clk_hw pointer to get the struct device_node from
+ *
+ * This is a helper to get the struct device_node associated with a
+ * hardware clock.
+ *
+ * Return: the struct device_node associated with the clock, or NULL
+ * if there is none.
+ */
+struct device_node *clk_hw_get_of_node(const struct clk_hw *hw);
#ifdef CONFIG_COMMON_CLK
struct clk_hw *__clk_get_hw(struct clk *clk);
#else
--
2.47.2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/2] clk: tests: add clk_hw_get_dev() and clk_hw_get_of_node() tests
2025-04-17 13:44 [PATCH 0/2] clk: add a clk_hw helpers to get the clock device or device_node Jerome Brunet
2025-04-17 13:44 ` [PATCH 1/2] " Jerome Brunet
@ 2025-04-17 13:44 ` Jerome Brunet
2025-06-02 17:06 ` Brian Masney
2025-06-20 7:18 ` Stephen Boyd
2025-06-02 11:59 ` [PATCH 0/2] clk: add a clk_hw helpers to get the clock device or device_node Jerome Brunet
2025-06-20 7:20 ` Stephen Boyd
3 siblings, 2 replies; 11+ messages in thread
From: Jerome Brunet @ 2025-04-17 13:44 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd; +Cc: linux-clk, linux-kernel, Jerome Brunet
Add kunit test suites clk_hw_get_dev() and clk_hw_get_of_node()
for clocks registered with clk_hw_register() and of_clk_hw_register()
Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
---
drivers/clk/Makefile | 1 +
drivers/clk/clk_test.c | 215 ++++++++++++++++++++++++--
drivers/clk/kunit_clk_hw_get_dev_of_node.dtso | 10 ++
3 files changed, 209 insertions(+), 17 deletions(-)
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index bf4bd45adc3a0ed8c9dc699c76f303dc91b524c4..7a4af86072179dcd6bcdb93860eeb4d28779377f 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -18,6 +18,7 @@ clk-test-y := clk_test.o \
kunit_clk_assigned_rates_without_consumer.dtbo.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_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_test.c b/drivers/clk/clk_test.c
index f08feeaa3750bc86859294650de298762dea690a..3dcf7f0747aad9b93c41632db68ecb9b141e7daf 100644
--- a/drivers/clk/clk_test.c
+++ b/drivers/clk/clk_test.c
@@ -2794,43 +2794,40 @@ static struct kunit_suite clk_register_clk_parent_data_of_suite = {
};
/**
- * struct clk_register_clk_parent_data_device_ctx - Context for clk_parent_data device tests
+ * struct clk_register_device_ctx - Context for clock device tests
* @dev: device of clk under test
* @hw: clk_hw for clk under test
* @pdrv: driver to attach to find @dev
*/
-struct clk_register_clk_parent_data_device_ctx {
+struct clk_register_device_ctx {
struct device *dev;
struct clk_hw hw;
struct platform_driver pdrv;
};
-static inline struct clk_register_clk_parent_data_device_ctx *
-clk_register_clk_parent_data_driver_to_test_context(struct platform_device *pdev)
+static inline struct clk_register_device_ctx *
+clk_register_device_to_test_context(struct platform_device *pdev)
{
return container_of(to_platform_driver(pdev->dev.driver),
- struct clk_register_clk_parent_data_device_ctx, pdrv);
+ struct clk_register_device_ctx, pdrv);
}
-static int clk_register_clk_parent_data_device_probe(struct platform_device *pdev)
+static int clk_register_device_probe(struct platform_device *pdev)
{
- struct clk_register_clk_parent_data_device_ctx *ctx;
+ struct clk_register_device_ctx *ctx;
- ctx = clk_register_clk_parent_data_driver_to_test_context(pdev);
+ ctx = clk_register_device_to_test_context(pdev);
ctx->dev = &pdev->dev;
return 0;
}
-static void clk_register_clk_parent_data_device_driver(struct kunit *test)
+static void clk_register_of_device_driver(struct kunit *test,
+ const struct of_device_id *match_table)
{
- struct clk_register_clk_parent_data_device_ctx *ctx = test->priv;
- static const struct of_device_id match_table[] = {
- { .compatible = "test,clk-parent-data" },
- { }
- };
+ struct clk_register_device_ctx *ctx = test->priv;
- ctx->pdrv.probe = clk_register_clk_parent_data_device_probe;
+ ctx->pdrv.probe = clk_register_device_probe;
ctx->pdrv.driver.of_match_table = match_table;
ctx->pdrv.driver.name = __func__;
ctx->pdrv.driver.owner = THIS_MODULE;
@@ -2839,6 +2836,16 @@ static void clk_register_clk_parent_data_device_driver(struct kunit *test)
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->dev);
}
+static void clk_register_clk_parent_data_device_driver(struct kunit *test)
+{
+ static const struct of_device_id match_table[] = {
+ { .compatible = "test,clk-parent-data" },
+ { }
+ };
+
+ clk_register_of_device_driver(test, match_table);
+}
+
static const struct clk_register_clk_parent_data_test_case
clk_register_clk_parent_data_device_cases[] = {
{
@@ -2909,7 +2916,7 @@ KUNIT_ARRAY_PARAM(clk_register_clk_parent_data_device_test,
*/
static void clk_register_clk_parent_data_device_test(struct kunit *test)
{
- struct clk_register_clk_parent_data_device_ctx *ctx;
+ struct clk_register_device_ctx *ctx;
const struct clk_register_clk_parent_data_test_case *test_param;
struct clk_hw *parent_hw;
struct clk_init_data init = { };
@@ -3016,7 +3023,7 @@ KUNIT_ARRAY_PARAM(clk_register_clk_parent_data_device_hw_test,
*/
static void clk_register_clk_parent_data_device_hw_test(struct kunit *test)
{
- struct clk_register_clk_parent_data_device_ctx *ctx;
+ struct clk_register_device_ctx *ctx;
const struct clk_register_clk_parent_data_test_case *test_param;
struct clk_dummy_context *parent;
struct clk_hw *parent_hw;
@@ -3395,6 +3402,178 @@ static struct kunit_suite clk_assigned_rates_suite = {
.init = clk_assigned_rates_test_init,
};
+/*
+ * struct clk_hw_get_dev_of_node_test_param - Test parameters clk_hw_get_dev/of_node tests
+ * @desc: Test description
+ * @has_ref: whether or not to pass the device/of_node to the register function
+ */
+struct clk_hw_get_dev_of_node_test_param {
+ const char *desc;
+ bool has_ref;
+};
+
+static const struct clk_hw_get_dev_of_node_test_param
+clk_hw_get_dev_test_params[] = {
+ {
+ .desc = "clock with device reference",
+ .has_ref = true,
+ }, {
+ .desc = "clock missing device reference",
+ .has_ref = false,
+ },
+};
+KUNIT_ARRAY_PARAM_DESC(clk_hw_get_dev, clk_hw_get_dev_test_params, desc)
+
+static const struct clk_init_data clk_hw_get_dev_of_node_init_data = {
+ .name = "clk_hw_get_dev_of_node",
+ .ops = &empty_clk_ops,
+};
+
+static void clk_hw_register_get_dev_test(struct kunit *test)
+{
+ const struct clk_hw_get_dev_of_node_test_param *test_param = test->param_value;
+ struct clk_register_device_ctx *ctx = test->priv;
+ struct device *dev = test_param->has_ref ? ctx->dev : NULL;
+
+ KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, dev, &ctx->hw));
+
+ KUNIT_EXPECT_PTR_EQ(test, dev, clk_hw_get_dev(&ctx->hw));
+}
+
+static void clk_hw_register_get_of_node_test(struct kunit *test)
+{
+ const struct clk_hw_get_dev_of_node_test_param *test_param = test->param_value;
+ struct clk_register_device_ctx *ctx = test->priv;
+ struct device *dev = test_param->has_ref ? ctx->dev : NULL;
+ struct device_node *np = NULL;
+
+ if (dev) {
+ np = dev_of_node(dev);
+
+ if (!np)
+ np = dev_of_node(dev->parent);
+ }
+
+ KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, dev, &ctx->hw));
+
+ KUNIT_EXPECT_PTR_EQ(test, np, clk_hw_get_of_node(&ctx->hw));
+}
+
+static int clk_hw_register_get_dev_of_node_test_init(struct kunit *test)
+{
+ struct clk_register_device_ctx *ctx;
+ static const struct of_device_id match_table[] = {
+ { .compatible = "test,clk-hw-get-dev-of-node" },
+ { }
+ };
+
+ KUNIT_ASSERT_EQ(test, 0,
+ of_overlay_apply_kunit(test, kunit_clk_hw_get_dev_of_node));
+
+ ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx);
+ test->priv = ctx;
+
+ clk_register_of_device_driver(test, match_table);
+ ctx->hw.init = &clk_hw_get_dev_of_node_init_data;
+
+ return 0;
+}
+
+static struct kunit_case clk_hw_register_get_dev_of_node_test_cases[] = {
+ KUNIT_CASE_PARAM(clk_hw_register_get_dev_test,
+ clk_hw_get_dev_gen_params),
+ KUNIT_CASE_PARAM(clk_hw_register_get_of_node_test,
+ clk_hw_get_dev_gen_params),
+ {}
+};
+
+/*
+ * Test suite to verify clk_hw_get_dev() and clk_hw_get_of_node() with
+ * registered through clk_hw_register()
+ */
+static struct kunit_suite clk_hw_register_get_dev_of_node_test_suite = {
+ .name = "clk_hw_register_get_dev_of_node_test_suite",
+ .init = clk_hw_register_get_dev_of_node_test_init,
+ .test_cases = clk_hw_register_get_dev_of_node_test_cases,
+};
+
+struct of_clk_register_ctx {
+ struct device_node *np;
+ struct clk_hw hw;
+};
+
+static const struct clk_hw_get_dev_of_node_test_param
+clk_hw_get_of_node_test_params[] = {
+ {
+ .desc = "clock with of_node reference",
+ .has_ref = true,
+ }, {
+ .desc = "clock missing of_node reference",
+ .has_ref = false,
+ },
+};
+KUNIT_ARRAY_PARAM_DESC(clk_hw_get_of_node, clk_hw_get_of_node_test_params, desc)
+
+static void of_clk_hw_register_get_dev_test(struct kunit *test)
+{
+ const struct clk_hw_get_dev_of_node_test_param *test_param = test->param_value;
+ struct of_clk_register_ctx *ctx = test->priv;
+ struct device_node *np = test_param->has_ref ? ctx->np : NULL;
+
+ KUNIT_ASSERT_EQ(test, 0, of_clk_hw_register_kunit(test, np, &ctx->hw));
+
+ KUNIT_EXPECT_PTR_EQ(test, NULL, clk_hw_get_dev(&ctx->hw));
+}
+
+static void of_clk_hw_register_get_of_node_test(struct kunit *test)
+{
+ const struct clk_hw_get_dev_of_node_test_param *test_param = test->param_value;
+ struct of_clk_register_ctx *ctx = test->priv;
+ struct device_node *np = test_param->has_ref ? ctx->np : NULL;
+
+ KUNIT_ASSERT_EQ(test, 0, of_clk_hw_register_kunit(test, np, &ctx->hw));
+
+ KUNIT_EXPECT_PTR_EQ(test, np, clk_hw_get_of_node(&ctx->hw));
+}
+
+static int of_clk_hw_register_get_dev_of_node_test_init(struct kunit *test)
+{
+ struct of_clk_register_ctx *ctx;
+
+ KUNIT_ASSERT_EQ(test, 0,
+ of_overlay_apply_kunit(test, kunit_clk_hw_get_dev_of_node));
+
+ ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx);
+ test->priv = ctx;
+
+ ctx->np = of_find_compatible_node(NULL, NULL, "test,clk-hw-get-dev-of-node");
+ of_node_put_kunit(test, ctx->np);
+
+ ctx->hw.init = &clk_hw_get_dev_of_node_init_data;
+
+ return 0;
+}
+
+static struct kunit_case of_clk_hw_register_get_dev_of_node_test_cases[] = {
+ KUNIT_CASE_PARAM(of_clk_hw_register_get_dev_test,
+ clk_hw_get_of_node_gen_params),
+ KUNIT_CASE_PARAM(of_clk_hw_register_get_of_node_test,
+ clk_hw_get_of_node_gen_params),
+ {}
+};
+
+/*
+ * Test suite to verify clk_hw_get_dev() and clk_hw_get_of_node() with
+ * registered through of_clk_hw_register()
+ */
+static struct kunit_suite of_clk_hw_register_get_dev_of_node_test_suite = {
+ .name = "of_clk_hw_register_get_dev_of_node_test_suite",
+ .init = of_clk_hw_register_get_dev_of_node_test_init,
+ .test_cases = of_clk_hw_register_get_dev_of_node_test_cases,
+};
+
kunit_test_suites(
&clk_assigned_rates_suite,
&clk_leaf_mux_set_rate_parent_test_suite,
@@ -3412,6 +3591,8 @@ kunit_test_suites(
&clk_register_clk_parent_data_device_suite,
&clk_single_parent_mux_test_suite,
&clk_uncached_test_suite,
+ &clk_hw_register_get_dev_of_node_test_suite,
+ &of_clk_hw_register_get_dev_of_node_test_suite,
);
MODULE_DESCRIPTION("Kunit tests for clk framework");
MODULE_LICENSE("GPL v2");
diff --git a/drivers/clk/kunit_clk_hw_get_dev_of_node.dtso b/drivers/clk/kunit_clk_hw_get_dev_of_node.dtso
new file mode 100644
index 0000000000000000000000000000000000000000..760717da32359e85d946c53e47e72994b1d51417
--- /dev/null
+++ b/drivers/clk/kunit_clk_hw_get_dev_of_node.dtso
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0
+/dts-v1/;
+/plugin/;
+
+&{/} {
+ kunit-clock-controller {
+ compatible = "test,clk-hw-get-dev-of-node";
+ #clock-cells = <0>;
+ };
+};
--
2.47.2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] clk: add a clk_hw helpers to get the clock device or device_node
2025-04-17 13:44 ` [PATCH 1/2] " Jerome Brunet
@ 2025-05-05 9:33 ` Jerome Brunet
2025-06-02 16:42 ` Brian Masney
2025-06-20 7:18 ` Stephen Boyd
2 siblings, 0 replies; 11+ messages in thread
From: Jerome Brunet @ 2025-05-05 9:33 UTC (permalink / raw)
To: Michael Turquette; +Cc: Stephen Boyd, linux-clk, linux-kernel
On Thu 17 Apr 2025 at 15:44, Jerome Brunet <jbrunet@baylibre.com> wrote:
> Add helpers to get the device or device_node associated with clk_hw.
>
> This can be used by clock drivers to access various device related
> functionality such as devres, dev_ prints, etc ...
>
> Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
> ---
Hello Stephen,
If possible, could you take that change in so can move on with rework
I'm trying do in amlogic clocks, while we refine the test part ? (if
another round is needed for that)
Cheers
> drivers/clk/clk.c | 12 ++++++++++++
> include/linux/clk-provider.h | 26 ++++++++++++++++++++++++++
> 2 files changed, 38 insertions(+)
>
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index 0565c87656cf5c557d8259c71b5d2971a7ac87e8..b821b2cdb155331c85fafbd2fac8ab3703a08e4d 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -365,6 +365,18 @@ const char *clk_hw_get_name(const struct clk_hw *hw)
> }
> EXPORT_SYMBOL_GPL(clk_hw_get_name);
>
> +struct device *clk_hw_get_dev(const struct clk_hw *hw)
> +{
> + return hw->core->dev;
> +}
> +EXPORT_SYMBOL_GPL(clk_hw_get_dev);
> +
> +struct device_node *clk_hw_get_of_node(const struct clk_hw *hw)
> +{
> + return hw->core->of_node;
> +}
> +EXPORT_SYMBOL_GPL(clk_hw_get_of_node);
> +
> struct clk_hw *__clk_get_hw(struct clk *clk)
> {
> return !clk ? NULL : clk->core->hw;
> diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
> index 2e6e603b749342931c0d0693c3e72b62c000791b..630705a47129453c241f1b1755f2c2f2a7ed8f77 100644
> --- a/include/linux/clk-provider.h
> +++ b/include/linux/clk-provider.h
> @@ -1360,6 +1360,32 @@ void clk_hw_unregister(struct clk_hw *hw);
> /* helper functions */
> const char *__clk_get_name(const struct clk *clk);
> const char *clk_hw_get_name(const struct clk_hw *hw);
> +
> +/**
> + * clk_hw_get_dev() - get device from an hardware clock.
> + * @hw: the clk_hw pointer to get the struct device from
> + *
> + * This is a helper to get the struct device associated with a hardware
> + * clock. Some clock controllers, such as the one registered with
> + * CLK_OF_DECLARE(), may have not provided a device pointer while
> + * registering the clock.
> + *
> + * Return: the struct device associated with the clock, or NULL if there
> + * is none.
> + */
> +struct device *clk_hw_get_dev(const struct clk_hw *hw);
> +
> +/**
> + * clk_hw_get_of_node() - get device_node from a hardware clock.
> + * @hw: the clk_hw pointer to get the struct device_node from
> + *
> + * This is a helper to get the struct device_node associated with a
> + * hardware clock.
> + *
> + * Return: the struct device_node associated with the clock, or NULL
> + * if there is none.
> + */
> +struct device_node *clk_hw_get_of_node(const struct clk_hw *hw);
> #ifdef CONFIG_COMMON_CLK
> struct clk_hw *__clk_get_hw(struct clk *clk);
> #else
--
Jerome
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/2] clk: add a clk_hw helpers to get the clock device or device_node
2025-04-17 13:44 [PATCH 0/2] clk: add a clk_hw helpers to get the clock device or device_node Jerome Brunet
2025-04-17 13:44 ` [PATCH 1/2] " Jerome Brunet
2025-04-17 13:44 ` [PATCH 2/2] clk: tests: add clk_hw_get_dev() and clk_hw_get_of_node() tests Jerome Brunet
@ 2025-06-02 11:59 ` Jerome Brunet
2025-06-20 7:20 ` Stephen Boyd
3 siblings, 0 replies; 11+ messages in thread
From: Jerome Brunet @ 2025-06-02 11:59 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd; +Cc: linux-clk, linux-kernel
On Thu 17 Apr 2025 at 15:44, Jerome Brunet <jbrunet@baylibre.com> wrote:
> This patchset adds helpers to get the device or device_node associated with
> clk_hw. This can be used by clock drivers to access various device related
> functionality. The 2nd changes adds kunit test coverage for the new helpers
>
> This patchset is the v4 of the series previously sent here [1], with the
> amlogic patches dropped for now. I'll resume the work on the amlogic
> changes when the helpers are available in CCF core.
Hi Stephen,
Gentle reminder.
We have been stuck on this for a few months now. Could please take patch
#1 at least. There is a significant amount queued on this on and it
would really help.
Thanks
>
> Added tests run example:
> KTAP version 1
> # Subtest: clk_hw_register_get_dev_of_node_test_suite
> # module: clk_test
> 1..2
> KTAP version 1
> # Subtest: clk_hw_register_get_dev_test
> ok 1 clock with device reference
> ok 2 clock missing device reference
> # clk_hw_register_get_dev_test: pass:2 fail:0 skip:0 total:2
> ok 1 clk_hw_register_get_dev_test
> KTAP version 1
> # Subtest: clk_hw_register_get_of_node_test
> ok 1 clock with device reference
> ok 2 clock missing device reference
> # clk_hw_register_get_of_node_test: pass:2 fail:0 skip:0 total:2
> ok 2 clk_hw_register_get_of_node_test
> # clk_hw_register_get_dev_of_node_test_suite: pass:2 fail:0 skip:0 total:2
> # Totals: pass:4 fail:0 skip:0 total:4
> ok 17 clk_hw_register_get_dev_of_node_test_suite
> KTAP version 1
> # Subtest: of_clk_hw_register_get_dev_of_node_test_suite
> # module: clk_test
> 1..2
> KTAP version 1
> # Subtest: of_clk_hw_register_get_dev_test
> ok 1 clock with of_node reference
> ok 2 clock missing of_node reference
> # of_clk_hw_register_get_dev_test: pass:2 fail:0 skip:0 total:2
> ok 1 of_clk_hw_register_get_dev_test
> KTAP version 1
> # Subtest: of_clk_hw_register_get_of_node_test
> ok 1 clock with of_node reference
> ok 2 clock missing of_node reference
> # of_clk_hw_register_get_of_node_test: pass:2 fail:0 skip:0 total:2
> ok 2 of_clk_hw_register_get_of_node_test
> # of_clk_hw_register_get_dev_of_node_test_suite: pass:2 fail:0 skip:0 total:2
> # Totals: pass:4 fail:0 skip:0 total:4
>
> [1]: https://lore.kernel.org/linux-clk/20250120-amlogic-clk-drop-clk-regmap-tables-v3-0-126244146947@baylibre.com
>
> Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
> ---
> Jerome Brunet (2):
> clk: add a clk_hw helpers to get the clock device or device_node
> clk: tests: add clk_hw_get_dev() and clk_hw_get_of_node() tests
>
> drivers/clk/Makefile | 1 +
> drivers/clk/clk.c | 12 ++
> drivers/clk/clk_test.c | 215 ++++++++++++++++++++++++--
> drivers/clk/kunit_clk_hw_get_dev_of_node.dtso | 10 ++
> include/linux/clk-provider.h | 26 ++++
> 5 files changed, 247 insertions(+), 17 deletions(-)
> ---
> base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8
> change-id: 20250415-clk-hw-get-helpers-c2344d404f3c
>
> Best regards,
--
Jerome
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] clk: add a clk_hw helpers to get the clock device or device_node
2025-04-17 13:44 ` [PATCH 1/2] " Jerome Brunet
2025-05-05 9:33 ` Jerome Brunet
@ 2025-06-02 16:42 ` Brian Masney
2025-06-20 7:18 ` Stephen Boyd
2 siblings, 0 replies; 11+ messages in thread
From: Brian Masney @ 2025-06-02 16:42 UTC (permalink / raw)
To: Jerome Brunet; +Cc: Michael Turquette, Stephen Boyd, linux-clk, linux-kernel
On Thu, Apr 17, 2025 at 03:44:22PM +0200, Jerome Brunet wrote:
> Add helpers to get the device or device_node associated with clk_hw.
>
> This can be used by clock drivers to access various device related
> functionality such as devres, dev_ prints, etc ...
>
> Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
Reviewed-by: Brian Masney <bmasney@redhat.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] clk: tests: add clk_hw_get_dev() and clk_hw_get_of_node() tests
2025-04-17 13:44 ` [PATCH 2/2] clk: tests: add clk_hw_get_dev() and clk_hw_get_of_node() tests Jerome Brunet
@ 2025-06-02 17:06 ` Brian Masney
2025-06-20 7:18 ` Stephen Boyd
1 sibling, 0 replies; 11+ messages in thread
From: Brian Masney @ 2025-06-02 17:06 UTC (permalink / raw)
To: Jerome Brunet; +Cc: Michael Turquette, Stephen Boyd, linux-clk, linux-kernel
On Thu, Apr 17, 2025 at 03:44:23PM +0200, Jerome Brunet wrote:
> Add kunit test suites clk_hw_get_dev() and clk_hw_get_of_node()
> for clocks registered with clk_hw_register() and of_clk_hw_register()
>
> Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
Reviewed-by: Brian Masney <bmasney@redhat.com>
I also ran the tests with no issues.
Just a few minor nits below if you happen to spin a v2.
> @@ -3016,7 +3023,7 @@ KUNIT_ARRAY_PARAM(clk_register_clk_parent_data_device_hw_test,
> */
> static void clk_register_clk_parent_data_device_hw_test(struct kunit *test)
> {
> - struct clk_register_clk_parent_data_device_ctx *ctx;
> + struct clk_register_device_ctx *ctx;
> const struct clk_register_clk_parent_data_test_case *test_param;
> struct clk_dummy_context *parent;
> struct clk_hw *parent_hw;
Put in reverse Christmas tree where possible.
> +static void clk_hw_register_get_of_node_test(struct kunit *test)
> +{
> + const struct clk_hw_get_dev_of_node_test_param *test_param = test->param_value;
> + struct clk_register_device_ctx *ctx = test->priv;
> + struct device *dev = test_param->has_ref ? ctx->dev : NULL;
> + struct device_node *np = NULL;
> +
> + if (dev) {
> + np = dev_of_node(dev);
> +
> + if (!np)
> + np = dev_of_node(dev->parent);
Remove newline before the if().
Brian
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] clk: add a clk_hw helpers to get the clock device or device_node
2025-04-17 13:44 ` [PATCH 1/2] " Jerome Brunet
2025-05-05 9:33 ` Jerome Brunet
2025-06-02 16:42 ` Brian Masney
@ 2025-06-20 7:18 ` Stephen Boyd
2 siblings, 0 replies; 11+ messages in thread
From: Stephen Boyd @ 2025-06-20 7:18 UTC (permalink / raw)
To: Jerome Brunet, Michael Turquette; +Cc: linux-clk, linux-kernel, Jerome Brunet
Quoting Jerome Brunet (2025-04-17 06:44:22)
> Add helpers to get the device or device_node associated with clk_hw.
>
> This can be used by clock drivers to access various device related
> functionality such as devres, dev_ prints, etc ...
>
> Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
> ---
Applied to clk-next
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] clk: tests: add clk_hw_get_dev() and clk_hw_get_of_node() tests
2025-04-17 13:44 ` [PATCH 2/2] clk: tests: add clk_hw_get_dev() and clk_hw_get_of_node() tests Jerome Brunet
2025-06-02 17:06 ` Brian Masney
@ 2025-06-20 7:18 ` Stephen Boyd
1 sibling, 0 replies; 11+ messages in thread
From: Stephen Boyd @ 2025-06-20 7:18 UTC (permalink / raw)
To: Jerome Brunet, Michael Turquette; +Cc: linux-clk, linux-kernel, Jerome Brunet
Quoting Jerome Brunet (2025-04-17 06:44:23)
> Add kunit test suites clk_hw_get_dev() and clk_hw_get_of_node()
> for clocks registered with clk_hw_register() and of_clk_hw_register()
>
> Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
> ---
Applied to clk-next
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/2] clk: add a clk_hw helpers to get the clock device or device_node
2025-04-17 13:44 [PATCH 0/2] clk: add a clk_hw helpers to get the clock device or device_node Jerome Brunet
` (2 preceding siblings ...)
2025-06-02 11:59 ` [PATCH 0/2] clk: add a clk_hw helpers to get the clock device or device_node Jerome Brunet
@ 2025-06-20 7:20 ` Stephen Boyd
2025-06-23 8:34 ` Jerome Brunet
3 siblings, 1 reply; 11+ messages in thread
From: Stephen Boyd @ 2025-06-20 7:20 UTC (permalink / raw)
To: Jerome Brunet, Michael Turquette; +Cc: linux-clk, linux-kernel, Jerome Brunet
Quoting Jerome Brunet (2025-04-17 06:44:21)
> This patchset adds helpers to get the device or device_node associated with
> clk_hw. This can be used by clock drivers to access various device related
> functionality. The 2nd changes adds kunit test coverage for the new helpers
>
I've pushed this to clk-hw-device, splitting the test patch into two and
reworking it. Let me know if you see anything off.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/2] clk: add a clk_hw helpers to get the clock device or device_node
2025-06-20 7:20 ` Stephen Boyd
@ 2025-06-23 8:34 ` Jerome Brunet
0 siblings, 0 replies; 11+ messages in thread
From: Jerome Brunet @ 2025-06-23 8:34 UTC (permalink / raw)
To: Stephen Boyd; +Cc: Michael Turquette, linux-clk, linux-kernel
On Fri 20 Jun 2025 at 00:20, Stephen Boyd <sboyd@kernel.org> wrote:
> Quoting Jerome Brunet (2025-04-17 06:44:21)
>> This patchset adds helpers to get the device or device_node associated with
>> clk_hw. This can be used by clock drivers to access various device related
>> functionality. The 2nd changes adds kunit test coverage for the new helpers
>>
>
> I've pushed this to clk-hw-device, splitting the test patch into two and
> reworking it. Let me know if you see anything off.
Thanks a lot Stephen !
You could keep the authorship of the 2nd patch I think, it is more a
rewrite than a rework. Either way, it is fine by me. Thanks again.
--
Jerome
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2025-06-23 8:34 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-17 13:44 [PATCH 0/2] clk: add a clk_hw helpers to get the clock device or device_node Jerome Brunet
2025-04-17 13:44 ` [PATCH 1/2] " Jerome Brunet
2025-05-05 9:33 ` Jerome Brunet
2025-06-02 16:42 ` Brian Masney
2025-06-20 7:18 ` Stephen Boyd
2025-04-17 13:44 ` [PATCH 2/2] clk: tests: add clk_hw_get_dev() and clk_hw_get_of_node() tests Jerome Brunet
2025-06-02 17:06 ` Brian Masney
2025-06-20 7:18 ` Stephen Boyd
2025-06-02 11:59 ` [PATCH 0/2] clk: add a clk_hw helpers to get the clock device or device_node Jerome Brunet
2025-06-20 7:20 ` Stephen Boyd
2025-06-23 8:34 ` Jerome Brunet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox