Lines Matching +full:parent +full:- +full:clk

1 // SPDX-License-Identifier: GPL-2.0
3 * Kunit tests for clk framework
5 #include <linux/clk.h>
6 #include <linux/clk-provider.h>
7 #include <linux/clk/clk-conf.h>
12 #include "clk.h"
14 #include <kunit/clk.h>
39 return ctx->rate; in clk_dummy_recalc_rate()
56 if (req->max_rate < ULONG_MAX) in clk_dummy_maximize_rate()
57 req->rate = req->max_rate; in clk_dummy_maximize_rate()
69 if (req->min_rate > 0) in clk_dummy_minimize_rate()
70 req->rate = req->min_rate; in clk_dummy_minimize_rate()
82 ctx->rate = rate; in clk_dummy_set_rate()
89 return -EINVAL; in clk_dummy_single_set_parent()
122 * what all the parents can provide, it will return -EINVAL.
130 * between rates above the parent rate which would be rounded to
131 * what the parent can provide, but rates below will simply
151 return -EINVAL; in clk_multiple_parents_mux_set_parent()
153 ctx->current_parent = index; in clk_multiple_parents_mux_set_parent()
163 return ctx->current_parent; in clk_multiple_parents_mux_get_parent()
186 return -ENOMEM; in clk_test_init_with_ops()
187 ctx->rate = DUMMY_CLOCK_INIT_RATE; in clk_test_init_with_ops()
188 test->priv = ctx; in clk_test_init_with_ops()
192 ctx->hw.init = &init; in clk_test_init_with_ops()
194 ret = clk_hw_register(NULL, &ctx->hw); in clk_test_init_with_ops()
218 struct clk_dummy_context *ctx = test->priv; in clk_test_exit()
220 clk_hw_unregister(&ctx->hw); in clk_test_exit()
228 struct clk_dummy_context *ctx = test->priv; in clk_test_get_rate()
229 struct clk_hw *hw = &ctx->hw; in clk_test_get_rate()
230 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_test_get_rate() local
233 rate = clk_get_rate(clk); in clk_test_get_rate()
235 KUNIT_EXPECT_EQ(test, rate, ctx->rate); in clk_test_get_rate()
237 clk_put(clk); in clk_test_get_rate()
249 struct clk_dummy_context *ctx = test->priv; in clk_test_set_get_rate()
250 struct clk_hw *hw = &ctx->hw; in clk_test_set_get_rate()
251 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_test_set_get_rate() local
255 clk_set_rate(clk, DUMMY_CLOCK_RATE_1), in clk_test_set_get_rate()
258 rate = clk_get_rate(clk); in clk_test_set_get_rate()
262 clk_put(clk); in clk_test_set_get_rate()
274 struct clk_dummy_context *ctx = test->priv; in clk_test_set_set_get_rate()
275 struct clk_hw *hw = &ctx->hw; in clk_test_set_set_get_rate()
276 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_test_set_set_get_rate() local
280 clk_set_rate(clk, DUMMY_CLOCK_RATE_1), in clk_test_set_set_get_rate()
284 clk_set_rate(clk, DUMMY_CLOCK_RATE_2), in clk_test_set_set_get_rate()
287 rate = clk_get_rate(clk); in clk_test_set_set_get_rate()
291 clk_put(clk); in clk_test_set_set_get_rate()
300 struct clk_dummy_context *ctx = test->priv; in clk_test_round_set_get_rate()
301 struct clk_hw *hw = &ctx->hw; in clk_test_round_set_get_rate()
302 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_test_round_set_get_rate() local
306 rounded_rate = clk_round_rate(clk, DUMMY_CLOCK_RATE_1); in clk_test_round_set_get_rate()
311 clk_set_rate(clk, DUMMY_CLOCK_RATE_1), in clk_test_round_set_get_rate()
314 set_rate = clk_get_rate(clk); in clk_test_round_set_get_rate()
318 clk_put(clk); in clk_test_round_set_get_rate()
330 * Test suite for a basic rate clock, without any parent.
335 .name = "clk-test",
348 return -ENOMEM; in clk_uncached_test_init()
349 test->priv = ctx; in clk_uncached_test_init()
351 ctx->rate = DUMMY_CLOCK_INIT_RATE; in clk_uncached_test_init()
352 ctx->hw.init = CLK_HW_INIT_NO_PARENT("test-clk", in clk_uncached_test_init()
356 ret = clk_hw_register(NULL, &ctx->hw); in clk_uncached_test_init()
370 struct clk_dummy_context *ctx = test->priv; in clk_test_uncached_get_rate()
371 struct clk_hw *hw = &ctx->hw; in clk_test_uncached_get_rate()
372 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_test_uncached_get_rate() local
375 rate = clk_get_rate(clk); in clk_test_uncached_get_rate()
380 ctx->rate = DUMMY_CLOCK_RATE_1; in clk_test_uncached_get_rate()
381 rate = clk_get_rate(clk); in clk_test_uncached_get_rate()
385 clk_put(clk); in clk_test_uncached_get_rate()
394 struct clk_dummy_context *ctx = test->priv; in clk_test_uncached_set_range()
395 struct clk_hw *hw = &ctx->hw; in clk_test_uncached_set_range()
396 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_test_uncached_set_range() local
400 clk_set_rate_range(clk, in clk_test_uncached_set_range()
405 rate = clk_get_rate(clk); in clk_test_uncached_set_range()
410 clk_put(clk); in clk_test_uncached_set_range()
423 struct clk_dummy_context *ctx = test->priv; in clk_test_uncached_updated_rate_set_range()
424 struct clk_hw *hw = &ctx->hw; in clk_test_uncached_updated_rate_set_range()
425 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_test_uncached_updated_rate_set_range() local
429 ctx->rate = DUMMY_CLOCK_RATE_1 + 1000; in clk_test_uncached_updated_rate_set_range()
431 clk_set_rate_range(clk, in clk_test_uncached_updated_rate_set_range()
436 rate = clk_get_rate(clk); in clk_test_uncached_updated_rate_set_range()
440 clk_put(clk); in clk_test_uncached_updated_rate_set_range()
451 * Test suite for a basic, uncached, rate clock, without any parent.
456 .name = "clk-uncached-test",
466 const char *parents[2] = { "parent-0", "parent-1"}; in clk_multiple_parents_mux_test_init()
471 return -ENOMEM; in clk_multiple_parents_mux_test_init()
472 test->priv = ctx; in clk_multiple_parents_mux_test_init()
474 ctx->parents_ctx[0].hw.init = CLK_HW_INIT_NO_PARENT("parent-0", in clk_multiple_parents_mux_test_init()
477 ctx->parents_ctx[0].rate = DUMMY_CLOCK_RATE_1; in clk_multiple_parents_mux_test_init()
478 ret = clk_hw_register_kunit(test, NULL, &ctx->parents_ctx[0].hw); in clk_multiple_parents_mux_test_init()
482 ctx->parents_ctx[1].hw.init = CLK_HW_INIT_NO_PARENT("parent-1", in clk_multiple_parents_mux_test_init()
485 ctx->parents_ctx[1].rate = DUMMY_CLOCK_RATE_2; in clk_multiple_parents_mux_test_init()
486 ret = clk_hw_register_kunit(test, NULL, &ctx->parents_ctx[1].hw); in clk_multiple_parents_mux_test_init()
490 ctx->current_parent = 0; in clk_multiple_parents_mux_test_init()
491 ctx->hw.init = CLK_HW_INIT_PARENTS("test-mux", parents, in clk_multiple_parents_mux_test_init()
494 ret = clk_hw_register_kunit(test, NULL, &ctx->hw); in clk_multiple_parents_mux_test_init()
508 struct clk_multiple_parent_ctx *ctx = test->priv; in clk_test_multiple_parents_mux_get_parent()
509 struct clk_hw *hw = &ctx->hw; in clk_test_multiple_parents_mux_get_parent()
510 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_test_multiple_parents_mux_get_parent() local
511 struct clk *parent = clk_hw_get_clk(&ctx->parents_ctx[0].hw, NULL); in clk_test_multiple_parents_mux_get_parent() local
513 KUNIT_EXPECT_TRUE(test, clk_is_match(clk_get_parent(clk), parent)); in clk_test_multiple_parents_mux_get_parent()
515 clk_put(parent); in clk_test_multiple_parents_mux_get_parent()
516 clk_put(clk); in clk_test_multiple_parents_mux_get_parent()
526 struct clk_multiple_parent_ctx *ctx = test->priv; in clk_test_multiple_parents_mux_has_parent()
527 struct clk_hw *hw = &ctx->hw; in clk_test_multiple_parents_mux_has_parent()
528 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_test_multiple_parents_mux_has_parent() local
529 struct clk *parent; in clk_test_multiple_parents_mux_has_parent() local
531 parent = clk_hw_get_clk(&ctx->parents_ctx[0].hw, NULL); in clk_test_multiple_parents_mux_has_parent()
532 KUNIT_EXPECT_TRUE(test, clk_has_parent(clk, parent)); in clk_test_multiple_parents_mux_has_parent()
533 clk_put(parent); in clk_test_multiple_parents_mux_has_parent()
535 parent = clk_hw_get_clk(&ctx->parents_ctx[1].hw, NULL); in clk_test_multiple_parents_mux_has_parent()
536 KUNIT_EXPECT_TRUE(test, clk_has_parent(clk, parent)); in clk_test_multiple_parents_mux_has_parent()
537 clk_put(parent); in clk_test_multiple_parents_mux_has_parent()
539 clk_put(clk); in clk_test_multiple_parents_mux_has_parent()
544 * that clock and the parent is changed, its rate after the reparenting
554 struct clk_multiple_parent_ctx *ctx = test->priv; in clk_test_multiple_parents_mux_set_range_set_parent_get_rate()
555 struct clk_hw *hw = &ctx->hw; in clk_test_multiple_parents_mux_set_range_set_parent_get_rate()
556 struct clk *clk = clk_hw_get_clk_kunit(test, hw, NULL); in clk_test_multiple_parents_mux_set_range_set_parent_get_rate() local
557 struct clk *parent1, *parent2; in clk_test_multiple_parents_mux_set_range_set_parent_get_rate()
563 parent1 = clk_hw_get_clk_kunit(test, &ctx->parents_ctx[0].hw, NULL); in clk_test_multiple_parents_mux_set_range_set_parent_get_rate()
565 KUNIT_ASSERT_TRUE(test, clk_is_match(clk_get_parent(clk), parent1)); in clk_test_multiple_parents_mux_set_range_set_parent_get_rate()
567 parent2 = clk_hw_get_clk_kunit(test, &ctx->parents_ctx[1].hw, NULL); in clk_test_multiple_parents_mux_set_range_set_parent_get_rate()
576 ret = clk_set_rate_range(clk, in clk_test_multiple_parents_mux_set_range_set_parent_get_rate()
577 DUMMY_CLOCK_RATE_1 - 1000, in clk_test_multiple_parents_mux_set_range_set_parent_get_rate()
581 ret = clk_set_parent(clk, parent2); in clk_test_multiple_parents_mux_set_range_set_parent_get_rate()
584 rate = clk_get_rate(clk); in clk_test_multiple_parents_mux_set_range_set_parent_get_rate()
586 KUNIT_EXPECT_GE(test, rate, DUMMY_CLOCK_RATE_1 - 1000); in clk_test_multiple_parents_mux_set_range_set_parent_get_rate()
606 .name = "clk-multiple-parents-mux-test",
615 const char *parents[2] = { "missing-parent", "proper-parent"}; in clk_orphan_transparent_multiple_parent_mux_test_init()
620 return -ENOMEM; in clk_orphan_transparent_multiple_parent_mux_test_init()
621 test->priv = ctx; in clk_orphan_transparent_multiple_parent_mux_test_init()
623 ctx->parents_ctx[1].hw.init = CLK_HW_INIT_NO_PARENT("proper-parent", in clk_orphan_transparent_multiple_parent_mux_test_init()
626 ctx->parents_ctx[1].rate = DUMMY_CLOCK_INIT_RATE; in clk_orphan_transparent_multiple_parent_mux_test_init()
627 ret = clk_hw_register_kunit(test, NULL, &ctx->parents_ctx[1].hw); in clk_orphan_transparent_multiple_parent_mux_test_init()
631 ctx->hw.init = CLK_HW_INIT_PARENTS("test-orphan-mux", parents, in clk_orphan_transparent_multiple_parent_mux_test_init()
634 ret = clk_hw_register_kunit(test, NULL, &ctx->hw); in clk_orphan_transparent_multiple_parent_mux_test_init()
642 * Test that, for a mux whose current parent hasn't been registered yet and is
648 struct clk_multiple_parent_ctx *ctx = test->priv; in clk_test_orphan_transparent_multiple_parent_mux_get_parent()
649 struct clk_hw *hw = &ctx->hw; in clk_test_orphan_transparent_multiple_parent_mux_get_parent()
650 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_test_orphan_transparent_multiple_parent_mux_get_parent() local
652 KUNIT_EXPECT_PTR_EQ(test, clk_get_parent(clk), NULL); in clk_test_orphan_transparent_multiple_parent_mux_get_parent()
654 clk_put(clk); in clk_test_orphan_transparent_multiple_parent_mux_get_parent()
658 * Test that, for a mux whose current parent hasn't been registered yet,
659 * calling clk_set_parent() to a valid parent will properly update the
660 * mux parent and its orphan status.
665 struct clk_multiple_parent_ctx *ctx = test->priv; in clk_test_orphan_transparent_multiple_parent_mux_set_parent()
666 struct clk_hw *hw = &ctx->hw; in clk_test_orphan_transparent_multiple_parent_mux_set_parent()
667 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_test_orphan_transparent_multiple_parent_mux_set_parent() local
668 struct clk *parent, *new_parent; in clk_test_orphan_transparent_multiple_parent_mux_set_parent() local
671 parent = clk_hw_get_clk(&ctx->parents_ctx[1].hw, NULL); in clk_test_orphan_transparent_multiple_parent_mux_set_parent()
672 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent()
674 ret = clk_set_parent(clk, parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent()
677 new_parent = clk_get_parent(clk); in clk_test_orphan_transparent_multiple_parent_mux_set_parent()
678 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent()
679 KUNIT_EXPECT_TRUE(test, clk_is_match(parent, new_parent)); in clk_test_orphan_transparent_multiple_parent_mux_set_parent()
681 clk_put(parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent()
682 clk_put(clk); in clk_test_orphan_transparent_multiple_parent_mux_set_parent()
687 * parent, calling clk_drop_range() on the mux won't affect the parent
693 struct clk_multiple_parent_ctx *ctx = test->priv; in clk_test_orphan_transparent_multiple_parent_mux_set_parent_drop_range()
694 struct clk_hw *hw = &ctx->hw; in clk_test_orphan_transparent_multiple_parent_mux_set_parent_drop_range()
695 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_drop_range() local
696 struct clk *parent; in clk_test_orphan_transparent_multiple_parent_mux_set_parent_drop_range() local
700 parent = clk_hw_get_clk(&ctx->parents_ctx[1].hw, NULL); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_drop_range()
701 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_drop_range()
703 parent_rate = clk_get_rate(parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_drop_range()
706 ret = clk_set_parent(clk, parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_drop_range()
709 ret = clk_drop_range(clk); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_drop_range()
712 new_parent_rate = clk_get_rate(clk); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_drop_range()
716 clk_put(parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_drop_range()
717 clk_put(clk); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_drop_range()
722 * parent, the rate of the mux and its new parent are consistent.
727 struct clk_multiple_parent_ctx *ctx = test->priv; in clk_test_orphan_transparent_multiple_parent_mux_set_parent_get_rate()
728 struct clk_hw *hw = &ctx->hw; in clk_test_orphan_transparent_multiple_parent_mux_set_parent_get_rate()
729 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_get_rate() local
730 struct clk *parent; in clk_test_orphan_transparent_multiple_parent_mux_set_parent_get_rate() local
734 parent = clk_hw_get_clk(&ctx->parents_ctx[1].hw, NULL); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_get_rate()
735 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_get_rate()
737 parent_rate = clk_get_rate(parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_get_rate()
740 ret = clk_set_parent(clk, parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_get_rate()
743 rate = clk_get_rate(clk); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_get_rate()
747 clk_put(parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_get_rate()
748 clk_put(clk); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_get_rate()
753 * parent, calling clk_put() on the mux won't affect the parent rate.
758 struct clk_multiple_parent_ctx *ctx = test->priv; in clk_test_orphan_transparent_multiple_parent_mux_set_parent_put()
759 struct clk *clk, *parent; in clk_test_orphan_transparent_multiple_parent_mux_set_parent_put() local
763 parent = clk_hw_get_clk(&ctx->parents_ctx[1].hw, NULL); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_put()
764 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_put()
766 clk = clk_hw_get_clk(&ctx->hw, NULL); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_put()
767 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, clk); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_put()
769 parent_rate = clk_get_rate(parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_put()
772 ret = clk_set_parent(clk, parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_put()
775 clk_put(clk); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_put()
777 new_parent_rate = clk_get_rate(parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_put()
781 clk_put(parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_put()
786 * parent, calling clk_set_rate_range() will affect the parent state if
792 struct clk_multiple_parent_ctx *ctx = test->priv; in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_modified()
793 struct clk_hw *hw = &ctx->hw; in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_modified()
794 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_modified() local
795 struct clk *parent; in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_modified() local
799 parent = clk_hw_get_clk(&ctx->parents_ctx[1].hw, NULL); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_modified()
800 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_modified()
802 ret = clk_set_parent(clk, parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_modified()
805 ret = clk_set_rate_range(clk, DUMMY_CLOCK_RATE_1, DUMMY_CLOCK_RATE_2); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_modified()
808 rate = clk_get_rate(clk); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_modified()
813 clk_put(parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_modified()
814 clk_put(clk); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_modified()
819 * parent, calling clk_set_rate_range() won't affect the parent state if
825 struct clk_multiple_parent_ctx *ctx = test->priv; in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_untouched()
826 struct clk_hw *hw = &ctx->hw; in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_untouched()
827 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_untouched() local
828 struct clk *parent; in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_untouched() local
832 parent = clk_hw_get_clk(&ctx->parents_ctx[1].hw, NULL); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_untouched()
833 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_untouched()
835 parent_rate = clk_get_rate(parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_untouched()
838 ret = clk_set_parent(clk, parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_untouched()
841 ret = clk_set_rate_range(clk, in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_untouched()
842 DUMMY_CLOCK_INIT_RATE - 1000, in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_untouched()
846 new_parent_rate = clk_get_rate(parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_untouched()
850 clk_put(parent); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_untouched()
851 clk_put(clk); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_untouched()
855 * Test that, for a mux whose current parent hasn't been registered yet,
862 struct clk_multiple_parent_ctx *ctx = test->priv; in clk_test_orphan_transparent_multiple_parent_mux_set_range_round_rate()
863 struct clk_hw *hw = &ctx->hw; in clk_test_orphan_transparent_multiple_parent_mux_set_range_round_rate()
864 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_test_orphan_transparent_multiple_parent_mux_set_range_round_rate() local
868 ret = clk_set_rate_range(clk, DUMMY_CLOCK_RATE_1, DUMMY_CLOCK_RATE_2); in clk_test_orphan_transparent_multiple_parent_mux_set_range_round_rate()
871 rate = clk_round_rate(clk, DUMMY_CLOCK_RATE_1 - 1000); in clk_test_orphan_transparent_multiple_parent_mux_set_range_round_rate()
876 clk_put(clk); in clk_test_orphan_transparent_multiple_parent_mux_set_range_round_rate()
881 * then got switched to a valid parent, its rate is eventually within
891 struct clk_multiple_parent_ctx *ctx = test->priv; in clk_test_orphan_transparent_multiple_parent_mux_set_range_set_parent_get_rate()
892 struct clk_hw *hw = &ctx->hw; in clk_test_orphan_transparent_multiple_parent_mux_set_range_set_parent_get_rate()
893 struct clk *clk = clk_hw_get_clk_kunit(test, hw, NULL); in clk_test_orphan_transparent_multiple_parent_mux_set_range_set_parent_get_rate() local
894 struct clk *parent; in clk_test_orphan_transparent_multiple_parent_mux_set_range_set_parent_get_rate() local
902 parent = clk_hw_get_clk_kunit(test, &ctx->parents_ctx[1].hw, NULL); in clk_test_orphan_transparent_multiple_parent_mux_set_range_set_parent_get_rate()
903 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent); in clk_test_orphan_transparent_multiple_parent_mux_set_range_set_parent_get_rate()
905 ret = clk_set_parent(clk, parent); in clk_test_orphan_transparent_multiple_parent_mux_set_range_set_parent_get_rate()
908 rate = clk_get_rate(clk); in clk_test_orphan_transparent_multiple_parent_mux_set_range_set_parent_get_rate()
928 * Test suite for a basic mux clock with two parents. The default parent
929 * isn't registered, only the second parent is. By default, the clock
934 * parent.
937 .name = "clk-orphan-transparent-multiple-parent-mux-test",
954 return -ENOMEM; in clk_single_parent_mux_test_init()
955 test->priv = ctx; in clk_single_parent_mux_test_init()
957 ctx->parent_ctx.rate = DUMMY_CLOCK_INIT_RATE; in clk_single_parent_mux_test_init()
958 ctx->parent_ctx.hw.init = in clk_single_parent_mux_test_init()
959 CLK_HW_INIT_NO_PARENT("parent-clk", in clk_single_parent_mux_test_init()
963 ret = clk_hw_register_kunit(test, NULL, &ctx->parent_ctx.hw); in clk_single_parent_mux_test_init()
967 ctx->hw.init = CLK_HW_INIT("test-clk", "parent-clk", in clk_single_parent_mux_test_init()
971 ret = clk_hw_register_kunit(test, NULL, &ctx->hw); in clk_single_parent_mux_test_init()
981 struct clk_single_parent_ctx *ctx = test->priv; in clk_single_parent_mux_test_exit()
983 clk_hw_unregister(&ctx->hw); in clk_single_parent_mux_test_exit()
984 clk_hw_unregister(&ctx->parent_ctx.hw); in clk_single_parent_mux_test_exit()
988 * Test that for a clock with a single parent, clk_get_parent() actually
989 * returns the parent.
994 struct clk_single_parent_ctx *ctx = test->priv; in clk_test_single_parent_mux_get_parent()
995 struct clk_hw *hw = &ctx->hw; in clk_test_single_parent_mux_get_parent()
996 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_test_single_parent_mux_get_parent() local
997 struct clk *parent = clk_hw_get_clk(&ctx->parent_ctx.hw, NULL); in clk_test_single_parent_mux_get_parent() local
999 KUNIT_EXPECT_TRUE(test, clk_is_match(clk_get_parent(clk), parent)); in clk_test_single_parent_mux_get_parent()
1001 clk_put(parent); in clk_test_single_parent_mux_get_parent()
1002 clk_put(clk); in clk_test_single_parent_mux_get_parent()
1006 * Test that for a clock with a single parent, clk_has_parent() actually
1007 * reports it as a parent.
1012 struct clk_single_parent_ctx *ctx = test->priv; in clk_test_single_parent_mux_has_parent()
1013 struct clk_hw *hw = &ctx->hw; in clk_test_single_parent_mux_has_parent()
1014 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_test_single_parent_mux_has_parent() local
1015 struct clk *parent = clk_hw_get_clk(&ctx->parent_ctx.hw, NULL); in clk_test_single_parent_mux_has_parent() local
1017 KUNIT_EXPECT_TRUE(test, clk_has_parent(clk, parent)); in clk_test_single_parent_mux_has_parent()
1019 clk_put(parent); in clk_test_single_parent_mux_has_parent()
1020 clk_put(clk); in clk_test_single_parent_mux_has_parent()
1025 * parent, if we set disjoints range on the parent and then the child,
1035 struct clk_single_parent_ctx *ctx = test->priv; in clk_test_single_parent_mux_set_range_disjoint_child_last()
1036 struct clk_hw *hw = &ctx->hw; in clk_test_single_parent_mux_set_range_disjoint_child_last()
1037 struct clk *clk = clk_hw_get_clk_kunit(test, hw, NULL); in clk_test_single_parent_mux_set_range_disjoint_child_last() local
1038 struct clk *parent; in clk_test_single_parent_mux_set_range_disjoint_child_last() local
1043 parent = clk_get_parent(clk); in clk_test_single_parent_mux_set_range_disjoint_child_last()
1044 KUNIT_ASSERT_PTR_NE(test, parent, NULL); in clk_test_single_parent_mux_set_range_disjoint_child_last()
1046 ret = clk_set_rate_range(parent, 1000, 2000); in clk_test_single_parent_mux_set_range_disjoint_child_last()
1049 ret = clk_set_rate_range(clk, 3000, 4000); in clk_test_single_parent_mux_set_range_disjoint_child_last()
1055 * parent, if we set disjoints range on the child and then the parent,
1065 struct clk_single_parent_ctx *ctx = test->priv; in clk_test_single_parent_mux_set_range_disjoint_parent_last()
1066 struct clk_hw *hw = &ctx->hw; in clk_test_single_parent_mux_set_range_disjoint_parent_last()
1067 struct clk *clk = clk_hw_get_clk_kunit(test, hw, NULL); in clk_test_single_parent_mux_set_range_disjoint_parent_last() local
1068 struct clk *parent; in clk_test_single_parent_mux_set_range_disjoint_parent_last() local
1073 parent = clk_get_parent(clk); in clk_test_single_parent_mux_set_range_disjoint_parent_last()
1074 KUNIT_ASSERT_PTR_NE(test, parent, NULL); in clk_test_single_parent_mux_set_range_disjoint_parent_last()
1076 ret = clk_set_rate_range(clk, 1000, 2000); in clk_test_single_parent_mux_set_range_disjoint_parent_last()
1079 ret = clk_set_rate_range(parent, 3000, 4000); in clk_test_single_parent_mux_set_range_disjoint_parent_last()
1085 * parent, if we set a range on the parent and then call
1086 * clk_round_rate(), the boundaries of the parent are taken into
1092 struct clk_single_parent_ctx *ctx = test->priv; in clk_test_single_parent_mux_set_range_round_rate_parent_only()
1093 struct clk_hw *hw = &ctx->hw; in clk_test_single_parent_mux_set_range_round_rate_parent_only()
1094 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_test_single_parent_mux_set_range_round_rate_parent_only() local
1095 struct clk *parent; in clk_test_single_parent_mux_set_range_round_rate_parent_only() local
1099 parent = clk_get_parent(clk); in clk_test_single_parent_mux_set_range_round_rate_parent_only()
1100 KUNIT_ASSERT_PTR_NE(test, parent, NULL); in clk_test_single_parent_mux_set_range_round_rate_parent_only()
1102 ret = clk_set_rate_range(parent, DUMMY_CLOCK_RATE_1, DUMMY_CLOCK_RATE_2); in clk_test_single_parent_mux_set_range_round_rate_parent_only()
1105 rate = clk_round_rate(clk, DUMMY_CLOCK_RATE_1 - 1000); in clk_test_single_parent_mux_set_range_round_rate_parent_only()
1110 clk_put(clk); in clk_test_single_parent_mux_set_range_round_rate_parent_only()
1115 * parent, if we set a range on the parent and a more restrictive one on
1122 struct clk_single_parent_ctx *ctx = test->priv; in clk_test_single_parent_mux_set_range_round_rate_child_smaller()
1123 struct clk_hw *hw = &ctx->hw; in clk_test_single_parent_mux_set_range_round_rate_child_smaller()
1124 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_test_single_parent_mux_set_range_round_rate_child_smaller() local
1125 struct clk *parent; in clk_test_single_parent_mux_set_range_round_rate_child_smaller() local
1129 parent = clk_get_parent(clk); in clk_test_single_parent_mux_set_range_round_rate_child_smaller()
1130 KUNIT_ASSERT_PTR_NE(test, parent, NULL); in clk_test_single_parent_mux_set_range_round_rate_child_smaller()
1132 ret = clk_set_rate_range(parent, DUMMY_CLOCK_RATE_1, DUMMY_CLOCK_RATE_2); in clk_test_single_parent_mux_set_range_round_rate_child_smaller()
1135 ret = clk_set_rate_range(clk, DUMMY_CLOCK_RATE_1 + 1000, DUMMY_CLOCK_RATE_2 - 1000); in clk_test_single_parent_mux_set_range_round_rate_child_smaller()
1138 rate = clk_round_rate(clk, DUMMY_CLOCK_RATE_1 - 1000); in clk_test_single_parent_mux_set_range_round_rate_child_smaller()
1141 KUNIT_EXPECT_LE(test, rate, DUMMY_CLOCK_RATE_2 - 1000); in clk_test_single_parent_mux_set_range_round_rate_child_smaller()
1143 rate = clk_round_rate(clk, DUMMY_CLOCK_RATE_2 + 1000); in clk_test_single_parent_mux_set_range_round_rate_child_smaller()
1146 KUNIT_EXPECT_LE(test, rate, DUMMY_CLOCK_RATE_2 - 1000); in clk_test_single_parent_mux_set_range_round_rate_child_smaller()
1148 clk_put(clk); in clk_test_single_parent_mux_set_range_round_rate_child_smaller()
1153 * parent, if we set a range on the child and a more restrictive one on
1154 * the parent, and then call clk_round_rate(), the boundaries of the
1160 struct clk_single_parent_ctx *ctx = test->priv; in clk_test_single_parent_mux_set_range_round_rate_parent_smaller()
1161 struct clk_hw *hw = &ctx->hw; in clk_test_single_parent_mux_set_range_round_rate_parent_smaller()
1162 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_test_single_parent_mux_set_range_round_rate_parent_smaller() local
1163 struct clk *parent; in clk_test_single_parent_mux_set_range_round_rate_parent_smaller() local
1167 parent = clk_get_parent(clk); in clk_test_single_parent_mux_set_range_round_rate_parent_smaller()
1168 KUNIT_ASSERT_PTR_NE(test, parent, NULL); in clk_test_single_parent_mux_set_range_round_rate_parent_smaller()
1170 ret = clk_set_rate_range(parent, DUMMY_CLOCK_RATE_1 + 1000, DUMMY_CLOCK_RATE_2 - 1000); in clk_test_single_parent_mux_set_range_round_rate_parent_smaller()
1173 ret = clk_set_rate_range(clk, DUMMY_CLOCK_RATE_1, DUMMY_CLOCK_RATE_2); in clk_test_single_parent_mux_set_range_round_rate_parent_smaller()
1176 rate = clk_round_rate(clk, DUMMY_CLOCK_RATE_1 - 1000); in clk_test_single_parent_mux_set_range_round_rate_parent_smaller()
1179 KUNIT_EXPECT_LE(test, rate, DUMMY_CLOCK_RATE_2 - 1000); in clk_test_single_parent_mux_set_range_round_rate_parent_smaller()
1181 rate = clk_round_rate(clk, DUMMY_CLOCK_RATE_2 + 1000); in clk_test_single_parent_mux_set_range_round_rate_parent_smaller()
1184 KUNIT_EXPECT_LE(test, rate, DUMMY_CLOCK_RATE_2 - 1000); in clk_test_single_parent_mux_set_range_round_rate_parent_smaller()
1186 clk_put(clk); in clk_test_single_parent_mux_set_range_round_rate_parent_smaller()
1201 * Test suite for a basic mux clock with one parent, with
1205 * child and parent are sane and consistent.
1209 .name = "clk-single-parent-mux-test",
1223 return -ENOMEM; in clk_orphan_transparent_single_parent_mux_test_init()
1224 test->priv = ctx; in clk_orphan_transparent_single_parent_mux_test_init()
1231 ctx->hw.init = &init; in clk_orphan_transparent_single_parent_mux_test_init()
1233 ret = clk_hw_register(NULL, &ctx->hw); in clk_orphan_transparent_single_parent_mux_test_init()
1240 ctx->parent_ctx.hw.init = &init; in clk_orphan_transparent_single_parent_mux_test_init()
1241 ctx->parent_ctx.rate = DUMMY_CLOCK_INIT_RATE; in clk_orphan_transparent_single_parent_mux_test_init()
1243 ret = clk_hw_register(NULL, &ctx->parent_ctx.hw); in clk_orphan_transparent_single_parent_mux_test_init()
1251 * Test that a mux-only clock, with an initial rate within a range,
1255 * https://lore.kernel.org/linux-clk/7720158d-10a7-a17b-73a4-[email protected]/
1259 struct clk_single_parent_ctx *ctx = test->priv; in clk_test_orphan_transparent_parent_mux_set_range()
1260 struct clk_hw *hw = &ctx->hw; in clk_test_orphan_transparent_parent_mux_set_range()
1261 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_test_orphan_transparent_parent_mux_set_range() local
1264 rate = clk_get_rate(clk); in clk_test_orphan_transparent_parent_mux_set_range()
1268 clk_set_rate_range(clk, in clk_test_orphan_transparent_parent_mux_set_range()
1269 ctx->parent_ctx.rate - 1000, in clk_test_orphan_transparent_parent_mux_set_range()
1270 ctx->parent_ctx.rate + 1000), in clk_test_orphan_transparent_parent_mux_set_range()
1273 new_rate = clk_get_rate(clk); in clk_test_orphan_transparent_parent_mux_set_range()
1277 clk_put(clk); in clk_test_orphan_transparent_parent_mux_set_range()
1286 * Test suite for a basic mux clock with one parent. The parent is
1294 .name = "clk-orphan-transparent-single-parent-test",
1314 return -ENOMEM; in clk_orphan_two_level_root_last_test_init()
1315 test->priv = ctx; in clk_orphan_two_level_root_last_test_init()
1317 ctx->parent_ctx.hw.init = in clk_orphan_two_level_root_last_test_init()
1318 CLK_HW_INIT("intermediate-parent", in clk_orphan_two_level_root_last_test_init()
1319 "root-parent", in clk_orphan_two_level_root_last_test_init()
1322 ret = clk_hw_register(NULL, &ctx->parent_ctx.hw); in clk_orphan_two_level_root_last_test_init()
1326 ctx->hw.init = in clk_orphan_two_level_root_last_test_init()
1327 CLK_HW_INIT("test-clk", "intermediate-parent", in clk_orphan_two_level_root_last_test_init()
1330 ret = clk_hw_register(NULL, &ctx->hw); in clk_orphan_two_level_root_last_test_init()
1334 ctx->parent_parent_ctx.rate = DUMMY_CLOCK_INIT_RATE; in clk_orphan_two_level_root_last_test_init()
1335 ctx->parent_parent_ctx.hw.init = in clk_orphan_two_level_root_last_test_init()
1336 CLK_HW_INIT_NO_PARENT("root-parent", in clk_orphan_two_level_root_last_test_init()
1339 ret = clk_hw_register(NULL, &ctx->parent_parent_ctx.hw); in clk_orphan_two_level_root_last_test_init()
1349 struct clk_single_parent_two_lvl_ctx *ctx = test->priv; in clk_orphan_two_level_root_last_test_exit()
1351 clk_hw_unregister(&ctx->hw); in clk_orphan_two_level_root_last_test_exit()
1352 clk_hw_unregister(&ctx->parent_ctx.hw); in clk_orphan_two_level_root_last_test_exit()
1353 clk_hw_unregister(&ctx->parent_parent_ctx.hw); in clk_orphan_two_level_root_last_test_exit()
1357 * Test that, for a clock whose parent used to be orphan, clk_get_rate()
1363 struct clk_single_parent_two_lvl_ctx *ctx = test->priv; in clk_orphan_two_level_root_last_test_get_rate()
1364 struct clk_hw *hw = &ctx->hw; in clk_orphan_two_level_root_last_test_get_rate()
1365 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_orphan_two_level_root_last_test_get_rate() local
1368 rate = clk_get_rate(clk); in clk_orphan_two_level_root_last_test_get_rate()
1371 clk_put(clk); in clk_orphan_two_level_root_last_test_get_rate()
1375 * Test that, for a clock whose parent used to be orphan,
1380 * https://lore.kernel.org/linux-clk/366a0232-bb4a-c357-6aa8-[email protected]/
1385 struct clk_single_parent_two_lvl_ctx *ctx = test->priv; in clk_orphan_two_level_root_last_test_set_range()
1386 struct clk_hw *hw = &ctx->hw; in clk_orphan_two_level_root_last_test_set_range()
1387 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_orphan_two_level_root_last_test_set_range() local
1391 ret = clk_set_rate_range(clk, in clk_orphan_two_level_root_last_test_set_range()
1392 DUMMY_CLOCK_INIT_RATE - 1000, in clk_orphan_two_level_root_last_test_set_range()
1396 rate = clk_get_rate(clk); in clk_orphan_two_level_root_last_test_set_range()
1400 clk_put(clk); in clk_orphan_two_level_root_last_test_set_range()
1411 * Test suite for a basic, transparent, clock with a parent that is also
1412 * such a clock. The parent's parent is registered last, while the
1413 * parent and its child are registered in that order. The intermediate
1415 * clock itself will always have its parent and will never be
1416 * reparented. Indeed, it's only orphan because its parent is.
1420 * parent.
1424 .name = "clk-orphan-two-level-root-last-test",
1437 struct clk_dummy_context *ctx = test->priv; in clk_range_test_set_range()
1438 struct clk_hw *hw = &ctx->hw; in clk_range_test_set_range()
1439 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_range_test_set_range() local
1443 clk_set_rate_range(clk, in clk_range_test_set_range()
1448 rate = clk_get_rate(clk); in clk_range_test_set_range()
1453 clk_put(clk); in clk_range_test_set_range()
1462 struct clk_dummy_context *ctx = test->priv; in clk_range_test_set_range_invalid()
1463 struct clk_hw *hw = &ctx->hw; in clk_range_test_set_range_invalid()
1464 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_range_test_set_range_invalid() local
1467 clk_set_rate_range(clk, in clk_range_test_set_range_invalid()
1472 clk_put(clk); in clk_range_test_set_range_invalid()
1481 struct clk_dummy_context *ctx = test->priv; in clk_range_test_multiple_disjoints_range()
1482 struct clk_hw *hw = &ctx->hw; in clk_range_test_multiple_disjoints_range()
1483 struct clk *user1, *user2; in clk_range_test_multiple_disjoints_range()
1509 struct clk_dummy_context *ctx = test->priv; in clk_range_test_set_range_round_rate_lower()
1510 struct clk_hw *hw = &ctx->hw; in clk_range_test_set_range_round_rate_lower()
1511 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_range_test_set_range_round_rate_lower() local
1515 clk_set_rate_range(clk, in clk_range_test_set_range_round_rate_lower()
1520 rate = clk_round_rate(clk, DUMMY_CLOCK_RATE_1 - 1000); in clk_range_test_set_range_round_rate_lower()
1525 clk_put(clk); in clk_range_test_set_range_round_rate_lower()
1534 struct clk_dummy_context *ctx = test->priv; in clk_range_test_set_range_set_rate_lower()
1535 struct clk_hw *hw = &ctx->hw; in clk_range_test_set_range_set_rate_lower()
1536 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_range_test_set_range_set_rate_lower() local
1540 clk_set_rate_range(clk, in clk_range_test_set_range_set_rate_lower()
1546 clk_set_rate(clk, DUMMY_CLOCK_RATE_1 - 1000), in clk_range_test_set_range_set_rate_lower()
1549 rate = clk_get_rate(clk); in clk_range_test_set_range_set_rate_lower()
1554 clk_put(clk); in clk_range_test_set_range_set_rate_lower()
1565 struct clk_dummy_context *ctx = test->priv; in clk_range_test_set_range_set_round_rate_consistent_lower()
1566 struct clk_hw *hw = &ctx->hw; in clk_range_test_set_range_set_round_rate_consistent_lower()
1567 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_range_test_set_range_set_round_rate_consistent_lower() local
1571 clk_set_rate_range(clk, in clk_range_test_set_range_set_round_rate_consistent_lower()
1576 rounded = clk_round_rate(clk, DUMMY_CLOCK_RATE_1 - 1000); in clk_range_test_set_range_set_round_rate_consistent_lower()
1580 clk_set_rate(clk, DUMMY_CLOCK_RATE_1 - 1000), in clk_range_test_set_range_set_round_rate_consistent_lower()
1583 KUNIT_EXPECT_EQ(test, rounded, clk_get_rate(clk)); in clk_range_test_set_range_set_round_rate_consistent_lower()
1585 clk_put(clk); in clk_range_test_set_range_set_round_rate_consistent_lower()
1594 struct clk_dummy_context *ctx = test->priv; in clk_range_test_set_range_round_rate_higher()
1595 struct clk_hw *hw = &ctx->hw; in clk_range_test_set_range_round_rate_higher()
1596 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_range_test_set_range_round_rate_higher() local
1600 clk_set_rate_range(clk, in clk_range_test_set_range_round_rate_higher()
1605 rate = clk_round_rate(clk, DUMMY_CLOCK_RATE_2 + 1000); in clk_range_test_set_range_round_rate_higher()
1610 clk_put(clk); in clk_range_test_set_range_round_rate_higher()
1619 struct clk_dummy_context *ctx = test->priv; in clk_range_test_set_range_set_rate_higher()
1620 struct clk_hw *hw = &ctx->hw; in clk_range_test_set_range_set_rate_higher()
1621 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_range_test_set_range_set_rate_higher() local
1625 clk_set_rate_range(clk, in clk_range_test_set_range_set_rate_higher()
1631 clk_set_rate(clk, DUMMY_CLOCK_RATE_2 + 1000), in clk_range_test_set_range_set_rate_higher()
1634 rate = clk_get_rate(clk); in clk_range_test_set_range_set_rate_higher()
1639 clk_put(clk); in clk_range_test_set_range_set_rate_higher()
1650 struct clk_dummy_context *ctx = test->priv; in clk_range_test_set_range_set_round_rate_consistent_higher()
1651 struct clk_hw *hw = &ctx->hw; in clk_range_test_set_range_set_round_rate_consistent_higher()
1652 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_range_test_set_range_set_round_rate_consistent_higher() local
1656 clk_set_rate_range(clk, in clk_range_test_set_range_set_round_rate_consistent_higher()
1661 rounded = clk_round_rate(clk, DUMMY_CLOCK_RATE_2 + 1000); in clk_range_test_set_range_set_round_rate_consistent_higher()
1665 clk_set_rate(clk, DUMMY_CLOCK_RATE_2 + 1000), in clk_range_test_set_range_set_round_rate_consistent_higher()
1668 KUNIT_EXPECT_EQ(test, rounded, clk_get_rate(clk)); in clk_range_test_set_range_set_round_rate_consistent_higher()
1670 clk_put(clk); in clk_range_test_set_range_set_round_rate_consistent_higher()
1683 struct clk_dummy_context *ctx = test->priv; in clk_range_test_set_range_get_rate_raised()
1684 struct clk_hw *hw = &ctx->hw; in clk_range_test_set_range_get_rate_raised()
1685 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_range_test_set_range_get_rate_raised() local
1689 clk_set_rate(clk, DUMMY_CLOCK_RATE_1 - 1000), in clk_range_test_set_range_get_rate_raised()
1693 clk_set_rate_range(clk, in clk_range_test_set_range_get_rate_raised()
1698 rate = clk_get_rate(clk); in clk_range_test_set_range_get_rate_raised()
1702 clk_put(clk); in clk_range_test_set_range_get_rate_raised()
1715 struct clk_dummy_context *ctx = test->priv; in clk_range_test_set_range_get_rate_lowered()
1716 struct clk_hw *hw = &ctx->hw; in clk_range_test_set_range_get_rate_lowered()
1717 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_range_test_set_range_get_rate_lowered() local
1721 clk_set_rate(clk, DUMMY_CLOCK_RATE_2 + 1000), in clk_range_test_set_range_get_rate_lowered()
1725 clk_set_rate_range(clk, in clk_range_test_set_range_get_rate_lowered()
1730 rate = clk_get_rate(clk); in clk_range_test_set_range_get_rate_lowered()
1734 clk_put(clk); in clk_range_test_set_range_get_rate_lowered()
1753 * Test suite for a basic rate clock, without any parent.
1759 .name = "clk-range-test",
1775 struct clk_dummy_context *ctx = test->priv; in clk_range_test_set_range_rate_maximized()
1776 struct clk_hw *hw = &ctx->hw; in clk_range_test_set_range_rate_maximized()
1777 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_range_test_set_range_rate_maximized() local
1781 clk_set_rate(clk, DUMMY_CLOCK_RATE_2 + 1000), in clk_range_test_set_range_rate_maximized()
1785 clk_set_rate_range(clk, in clk_range_test_set_range_rate_maximized()
1790 rate = clk_get_rate(clk); in clk_range_test_set_range_rate_maximized()
1795 clk_set_rate_range(clk, in clk_range_test_set_range_rate_maximized()
1797 DUMMY_CLOCK_RATE_2 - 1000), in clk_range_test_set_range_rate_maximized()
1800 rate = clk_get_rate(clk); in clk_range_test_set_range_rate_maximized()
1802 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2 - 1000); in clk_range_test_set_range_rate_maximized()
1805 clk_set_rate_range(clk, in clk_range_test_set_range_rate_maximized()
1810 rate = clk_get_rate(clk); in clk_range_test_set_range_rate_maximized()
1814 clk_put(clk); in clk_range_test_set_range_rate_maximized()
1827 struct clk_dummy_context *ctx = test->priv; in clk_range_test_multiple_set_range_rate_maximized()
1828 struct clk_hw *hw = &ctx->hw; in clk_range_test_multiple_set_range_rate_maximized()
1829 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_range_test_multiple_set_range_rate_maximized() local
1830 struct clk *user1, *user2; in clk_range_test_multiple_set_range_rate_maximized()
1840 clk_set_rate(clk, DUMMY_CLOCK_RATE_2 + 1000), in clk_range_test_multiple_set_range_rate_maximized()
1849 rate = clk_get_rate(clk); in clk_range_test_multiple_set_range_rate_maximized()
1859 rate = clk_get_rate(clk); in clk_range_test_multiple_set_range_rate_maximized()
1867 rate = clk_get_rate(clk); in clk_range_test_multiple_set_range_rate_maximized()
1873 clk_put(clk); in clk_range_test_multiple_set_range_rate_maximized()
1886 struct clk_dummy_context *ctx = test->priv; in clk_range_test_multiple_set_range_rate_put_maximized()
1887 struct clk_hw *hw = &ctx->hw; in clk_range_test_multiple_set_range_rate_put_maximized()
1888 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_range_test_multiple_set_range_rate_put_maximized() local
1889 struct clk *user1, *user2; in clk_range_test_multiple_set_range_rate_put_maximized()
1899 clk_set_rate(clk, DUMMY_CLOCK_RATE_2 + 1000), in clk_range_test_multiple_set_range_rate_put_maximized()
1908 rate = clk_get_rate(clk); in clk_range_test_multiple_set_range_rate_put_maximized()
1918 rate = clk_get_rate(clk); in clk_range_test_multiple_set_range_rate_put_maximized()
1924 rate = clk_get_rate(clk); in clk_range_test_multiple_set_range_rate_put_maximized()
1929 clk_put(clk); in clk_range_test_multiple_set_range_rate_put_maximized()
1940 * Test suite for a basic rate clock, without any parent.
1947 .name = "clk-range-maximize-test",
1963 struct clk_dummy_context *ctx = test->priv; in clk_range_test_set_range_rate_minimized()
1964 struct clk_hw *hw = &ctx->hw; in clk_range_test_set_range_rate_minimized()
1965 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_range_test_set_range_rate_minimized() local
1969 clk_set_rate(clk, DUMMY_CLOCK_RATE_1 - 1000), in clk_range_test_set_range_rate_minimized()
1973 clk_set_rate_range(clk, in clk_range_test_set_range_rate_minimized()
1978 rate = clk_get_rate(clk); in clk_range_test_set_range_rate_minimized()
1983 clk_set_rate_range(clk, in clk_range_test_set_range_rate_minimized()
1988 rate = clk_get_rate(clk); in clk_range_test_set_range_rate_minimized()
1993 clk_set_rate_range(clk, in clk_range_test_set_range_rate_minimized()
1998 rate = clk_get_rate(clk); in clk_range_test_set_range_rate_minimized()
2002 clk_put(clk); in clk_range_test_set_range_rate_minimized()
2015 struct clk_dummy_context *ctx = test->priv; in clk_range_test_multiple_set_range_rate_minimized()
2016 struct clk_hw *hw = &ctx->hw; in clk_range_test_multiple_set_range_rate_minimized()
2017 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_range_test_multiple_set_range_rate_minimized() local
2018 struct clk *user1, *user2; in clk_range_test_multiple_set_range_rate_minimized()
2033 rate = clk_get_rate(clk); in clk_range_test_multiple_set_range_rate_minimized()
2043 rate = clk_get_rate(clk); in clk_range_test_multiple_set_range_rate_minimized()
2051 rate = clk_get_rate(clk); in clk_range_test_multiple_set_range_rate_minimized()
2057 clk_put(clk); in clk_range_test_multiple_set_range_rate_minimized()
2070 struct clk_dummy_context *ctx = test->priv; in clk_range_test_multiple_set_range_rate_put_minimized()
2071 struct clk_hw *hw = &ctx->hw; in clk_range_test_multiple_set_range_rate_put_minimized()
2072 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_range_test_multiple_set_range_rate_put_minimized() local
2073 struct clk *user1, *user2; in clk_range_test_multiple_set_range_rate_put_minimized()
2088 rate = clk_get_rate(clk); in clk_range_test_multiple_set_range_rate_put_minimized()
2098 rate = clk_get_rate(clk); in clk_range_test_multiple_set_range_rate_put_minimized()
2104 rate = clk_get_rate(clk); in clk_range_test_multiple_set_range_rate_put_minimized()
2109 clk_put(clk); in clk_range_test_multiple_set_range_rate_put_minimized()
2120 * Test suite for a basic rate clock, without any parent.
2127 .name = "clk-range-minimize-test",
2136 struct clk_hw parent; member
2145 struct clk_rate_request *parent_req = ctx->req; in clk_leaf_mux_determine_rate()
2147 clk_hw_forward_rate_request(hw, req, req->best_parent_hw, parent_req, req->rate); in clk_leaf_mux_determine_rate()
2148 ret = ctx->determine_rate_func(req->best_parent_hw, parent_req); in clk_leaf_mux_determine_rate()
2152 req->rate = parent_req->rate; in clk_leaf_mux_determine_rate()
2167 const char *top_parents[2] = { "parent-0", "parent-1" }; in clk_leaf_mux_set_rate_parent_test_init()
2172 return -ENOMEM; in clk_leaf_mux_set_rate_parent_test_init()
2173 test->priv = ctx; in clk_leaf_mux_set_rate_parent_test_init()
2175 ctx->mux_ctx.parents_ctx[0].hw.init = CLK_HW_INIT_NO_PARENT("parent-0", in clk_leaf_mux_set_rate_parent_test_init()
2178 ctx->mux_ctx.parents_ctx[0].rate = DUMMY_CLOCK_RATE_1; in clk_leaf_mux_set_rate_parent_test_init()
2179 ret = clk_hw_register(NULL, &ctx->mux_ctx.parents_ctx[0].hw); in clk_leaf_mux_set_rate_parent_test_init()
2183 ctx->mux_ctx.parents_ctx[1].hw.init = CLK_HW_INIT_NO_PARENT("parent-1", in clk_leaf_mux_set_rate_parent_test_init()
2186 ctx->mux_ctx.parents_ctx[1].rate = DUMMY_CLOCK_RATE_2; in clk_leaf_mux_set_rate_parent_test_init()
2187 ret = clk_hw_register(NULL, &ctx->mux_ctx.parents_ctx[1].hw); in clk_leaf_mux_set_rate_parent_test_init()
2191 ctx->mux_ctx.current_parent = 0; in clk_leaf_mux_set_rate_parent_test_init()
2192 ctx->mux_ctx.hw.init = CLK_HW_INIT_PARENTS("test-mux", top_parents, in clk_leaf_mux_set_rate_parent_test_init()
2195 ret = clk_hw_register(NULL, &ctx->mux_ctx.hw); in clk_leaf_mux_set_rate_parent_test_init()
2199 ctx->parent.init = CLK_HW_INIT_HW("test-parent", &ctx->mux_ctx.hw, in clk_leaf_mux_set_rate_parent_test_init()
2201 ret = clk_hw_register(NULL, &ctx->parent); in clk_leaf_mux_set_rate_parent_test_init()
2205 ctx->hw.init = CLK_HW_INIT_HW("test-clock", &ctx->parent, in clk_leaf_mux_set_rate_parent_test_init()
2208 ret = clk_hw_register(NULL, &ctx->hw); in clk_leaf_mux_set_rate_parent_test_init()
2217 struct clk_leaf_mux_ctx *ctx = test->priv; in clk_leaf_mux_set_rate_parent_test_exit()
2219 clk_hw_unregister(&ctx->hw); in clk_leaf_mux_set_rate_parent_test_exit()
2220 clk_hw_unregister(&ctx->parent); in clk_leaf_mux_set_rate_parent_test_exit()
2221 clk_hw_unregister(&ctx->mux_ctx.hw); in clk_leaf_mux_set_rate_parent_test_exit()
2222 clk_hw_unregister(&ctx->mux_ctx.parents_ctx[0].hw); in clk_leaf_mux_set_rate_parent_test_exit()
2223 clk_hw_unregister(&ctx->mux_ctx.parents_ctx[1].hw); in clk_leaf_mux_set_rate_parent_test_exit()
2235 strcpy(desc, t->desc); in clk_leaf_mux_set_rate_parent_determine_rate_test_case_to_desc()
2242 * Test that __clk_determine_rate() on the parent that can't
2244 * the best_parent_hw pointer pointing to the parent.
2251 * Test that __clk_mux_determine_rate() on the parent that
2254 * the parent.
2261 * Test that __clk_mux_determine_rate_closest() on the parent
2264 * the parent.
2271 * Test that clk_hw_determine_rate_no_reparent() on the parent
2274 * the parent.
2286 * Test that when a clk that can't change rate itself calls a function like in KUNIT_ARRAY_PARAM()
2287 * __clk_determine_rate() on its parent it doesn't get back a clk_rate_request in KUNIT_ARRAY_PARAM()
2289 * into the determine rate function. See commit 262ca38f4b6e ("clk: Stop in KUNIT_ARRAY_PARAM()
2290 * forwarding clk_rate_requests to the parent") for more background. in KUNIT_ARRAY_PARAM()
2294 struct clk_leaf_mux_ctx *ctx = test->priv; in KUNIT_ARRAY_PARAM()
2295 struct clk_hw *hw = &ctx->hw; in KUNIT_ARRAY_PARAM()
2296 struct clk *clk = clk_hw_get_clk(hw, NULL); in KUNIT_ARRAY_PARAM() local
2301 test_param = test->param_value; in KUNIT_ARRAY_PARAM()
2302 ctx->determine_rate_func = test_param->determine_rate_func; in KUNIT_ARRAY_PARAM()
2304 ctx->req = &req; in KUNIT_ARRAY_PARAM()
2305 rate = clk_get_rate(clk); in KUNIT_ARRAY_PARAM()
2307 KUNIT_ASSERT_EQ(test, DUMMY_CLOCK_RATE_2, clk_round_rate(clk, DUMMY_CLOCK_RATE_2)); in KUNIT_ARRAY_PARAM()
2311 KUNIT_EXPECT_PTR_EQ(test, req.best_parent_hw, &ctx->mux_ctx.hw); in KUNIT_ARRAY_PARAM()
2313 clk_put(clk); in KUNIT_ARRAY_PARAM()
2323 * Test suite for a clock whose parent is a pass-through clk whose parent is a
2324 * mux with multiple parents. The leaf and pass-through clocks have the
2326 * will then select which parent is the best fit for a given rate.
2332 .name = "clk-leaf-mux-set-rate-parent",
2347 struct clk *clk; member
2364 ctx->pre_rate_change.old_rate = clk_data->old_rate; in clk_mux_notifier_callback()
2365 ctx->pre_rate_change.new_rate = clk_data->new_rate; in clk_mux_notifier_callback()
2366 ctx->pre_rate_change.done = true; in clk_mux_notifier_callback()
2367 wake_up_interruptible(&ctx->pre_rate_change.wq); in clk_mux_notifier_callback()
2371 ctx->post_rate_change.old_rate = clk_data->old_rate; in clk_mux_notifier_callback()
2372 ctx->post_rate_change.new_rate = clk_data->new_rate; in clk_mux_notifier_callback()
2373 ctx->post_rate_change.done = true; in clk_mux_notifier_callback()
2374 wake_up_interruptible(&ctx->post_rate_change.wq); in clk_mux_notifier_callback()
2383 const char *top_parents[2] = { "parent-0", "parent-1" }; in clk_mux_notifier_test_init()
2388 return -ENOMEM; in clk_mux_notifier_test_init()
2389 test->priv = ctx; in clk_mux_notifier_test_init()
2390 ctx->clk_nb.notifier_call = clk_mux_notifier_callback; in clk_mux_notifier_test_init()
2391 init_waitqueue_head(&ctx->pre_rate_change.wq); in clk_mux_notifier_test_init()
2392 init_waitqueue_head(&ctx->post_rate_change.wq); in clk_mux_notifier_test_init()
2394 ctx->mux_ctx.parents_ctx[0].hw.init = CLK_HW_INIT_NO_PARENT("parent-0", in clk_mux_notifier_test_init()
2397 ctx->mux_ctx.parents_ctx[0].rate = DUMMY_CLOCK_RATE_1; in clk_mux_notifier_test_init()
2398 ret = clk_hw_register(NULL, &ctx->mux_ctx.parents_ctx[0].hw); in clk_mux_notifier_test_init()
2402 ctx->mux_ctx.parents_ctx[1].hw.init = CLK_HW_INIT_NO_PARENT("parent-1", in clk_mux_notifier_test_init()
2405 ctx->mux_ctx.parents_ctx[1].rate = DUMMY_CLOCK_RATE_2; in clk_mux_notifier_test_init()
2406 ret = clk_hw_register(NULL, &ctx->mux_ctx.parents_ctx[1].hw); in clk_mux_notifier_test_init()
2410 ctx->mux_ctx.current_parent = 0; in clk_mux_notifier_test_init()
2411 ctx->mux_ctx.hw.init = CLK_HW_INIT_PARENTS("test-mux", top_parents, in clk_mux_notifier_test_init()
2414 ret = clk_hw_register(NULL, &ctx->mux_ctx.hw); in clk_mux_notifier_test_init()
2418 ctx->clk = clk_hw_get_clk(&ctx->mux_ctx.hw, NULL); in clk_mux_notifier_test_init()
2419 ret = clk_notifier_register(ctx->clk, &ctx->clk_nb); in clk_mux_notifier_test_init()
2428 struct clk_mux_notifier_ctx *ctx = test->priv; in clk_mux_notifier_test_exit()
2429 struct clk *clk = ctx->clk; in clk_mux_notifier_test_exit() local
2431 clk_notifier_unregister(clk, &ctx->clk_nb); in clk_mux_notifier_test_exit()
2432 clk_put(clk); in clk_mux_notifier_test_exit()
2434 clk_hw_unregister(&ctx->mux_ctx.hw); in clk_mux_notifier_test_exit()
2435 clk_hw_unregister(&ctx->mux_ctx.parents_ctx[0].hw); in clk_mux_notifier_test_exit()
2436 clk_hw_unregister(&ctx->mux_ctx.parents_ctx[1].hw); in clk_mux_notifier_test_exit()
2441 * will notify us when we switch to another parent, and with the proper
2446 struct clk_mux_notifier_ctx *ctx = test->priv; in clk_mux_notifier_set_parent_test()
2447 struct clk_hw *hw = &ctx->mux_ctx.hw; in clk_mux_notifier_set_parent_test()
2448 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_mux_notifier_set_parent_test() local
2449 struct clk *new_parent = clk_hw_get_clk(&ctx->mux_ctx.parents_ctx[1].hw, NULL); in clk_mux_notifier_set_parent_test()
2452 ret = clk_set_parent(clk, new_parent); in clk_mux_notifier_set_parent_test()
2455 ret = wait_event_interruptible_timeout(ctx->pre_rate_change.wq, in clk_mux_notifier_set_parent_test()
2456 ctx->pre_rate_change.done, in clk_mux_notifier_set_parent_test()
2460 KUNIT_EXPECT_EQ(test, ctx->pre_rate_change.old_rate, DUMMY_CLOCK_RATE_1); in clk_mux_notifier_set_parent_test()
2461 KUNIT_EXPECT_EQ(test, ctx->pre_rate_change.new_rate, DUMMY_CLOCK_RATE_2); in clk_mux_notifier_set_parent_test()
2463 ret = wait_event_interruptible_timeout(ctx->post_rate_change.wq, in clk_mux_notifier_set_parent_test()
2464 ctx->post_rate_change.done, in clk_mux_notifier_set_parent_test()
2468 KUNIT_EXPECT_EQ(test, ctx->post_rate_change.old_rate, DUMMY_CLOCK_RATE_1); in clk_mux_notifier_set_parent_test()
2469 KUNIT_EXPECT_EQ(test, ctx->post_rate_change.new_rate, DUMMY_CLOCK_RATE_2); in clk_mux_notifier_set_parent_test()
2472 clk_put(clk); in clk_mux_notifier_set_parent_test()
2487 .name = "clk-mux-notifier",
2497 const char *parents[2] = { "parent-0", "parent-1"}; in clk_mux_no_reparent_test_init()
2502 return -ENOMEM; in clk_mux_no_reparent_test_init()
2503 test->priv = ctx; in clk_mux_no_reparent_test_init()
2505 ctx->parents_ctx[0].hw.init = CLK_HW_INIT_NO_PARENT("parent-0", in clk_mux_no_reparent_test_init()
2508 ctx->parents_ctx[0].rate = DUMMY_CLOCK_RATE_1; in clk_mux_no_reparent_test_init()
2509 ret = clk_hw_register(NULL, &ctx->parents_ctx[0].hw); in clk_mux_no_reparent_test_init()
2513 ctx->parents_ctx[1].hw.init = CLK_HW_INIT_NO_PARENT("parent-1", in clk_mux_no_reparent_test_init()
2516 ctx->parents_ctx[1].rate = DUMMY_CLOCK_RATE_2; in clk_mux_no_reparent_test_init()
2517 ret = clk_hw_register(NULL, &ctx->parents_ctx[1].hw); in clk_mux_no_reparent_test_init()
2521 ctx->current_parent = 0; in clk_mux_no_reparent_test_init()
2522 ctx->hw.init = CLK_HW_INIT_PARENTS("test-mux", parents, in clk_mux_no_reparent_test_init()
2525 ret = clk_hw_register(NULL, &ctx->hw); in clk_mux_no_reparent_test_init()
2535 struct clk_multiple_parent_ctx *ctx = test->priv; in clk_mux_no_reparent_test_exit()
2537 clk_hw_unregister(&ctx->hw); in clk_mux_no_reparent_test_exit()
2538 clk_hw_unregister(&ctx->parents_ctx[0].hw); in clk_mux_no_reparent_test_exit()
2539 clk_hw_unregister(&ctx->parents_ctx[1].hw); in clk_mux_no_reparent_test_exit()
2543 * Test that if the we have a mux that cannot change parent and we call
2545 * parent, it won't.
2549 struct clk_multiple_parent_ctx *ctx = test->priv; in clk_mux_no_reparent_round_rate()
2550 struct clk_hw *hw = &ctx->hw; in clk_mux_no_reparent_round_rate()
2551 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_mux_no_reparent_round_rate() local
2552 struct clk *other_parent, *parent; in clk_mux_no_reparent_round_rate() local
2557 parent = clk_get_parent(clk); in clk_mux_no_reparent_round_rate()
2558 KUNIT_ASSERT_PTR_NE(test, parent, NULL); in clk_mux_no_reparent_round_rate()
2560 parent_rate = clk_get_rate(parent); in clk_mux_no_reparent_round_rate()
2563 other_parent = clk_hw_get_clk(&ctx->parents_ctx[1].hw, NULL); in clk_mux_no_reparent_round_rate()
2565 KUNIT_ASSERT_FALSE(test, clk_is_match(parent, other_parent)); in clk_mux_no_reparent_round_rate()
2571 rounded_rate = clk_round_rate(clk, other_parent_rate); in clk_mux_no_reparent_round_rate()
2575 clk_put(clk); in clk_mux_no_reparent_round_rate()
2579 * Test that if the we have a mux that cannot change parent and we call
2581 * parent, it won't.
2585 struct clk_multiple_parent_ctx *ctx = test->priv; in clk_mux_no_reparent_set_rate()
2586 struct clk_hw *hw = &ctx->hw; in clk_mux_no_reparent_set_rate()
2587 struct clk *clk = clk_hw_get_clk(hw, NULL); in clk_mux_no_reparent_set_rate() local
2588 struct clk *other_parent, *parent; in clk_mux_no_reparent_set_rate() local
2594 parent = clk_get_parent(clk); in clk_mux_no_reparent_set_rate()
2595 KUNIT_ASSERT_PTR_NE(test, parent, NULL); in clk_mux_no_reparent_set_rate()
2597 parent_rate = clk_get_rate(parent); in clk_mux_no_reparent_set_rate()
2600 other_parent = clk_hw_get_clk(&ctx->parents_ctx[1].hw, NULL); in clk_mux_no_reparent_set_rate()
2602 KUNIT_ASSERT_FALSE(test, clk_is_match(parent, other_parent)); in clk_mux_no_reparent_set_rate()
2608 ret = clk_set_rate(clk, other_parent_rate); in clk_mux_no_reparent_set_rate()
2611 rate = clk_get_rate(clk); in clk_mux_no_reparent_set_rate()
2615 clk_put(clk); in clk_mux_no_reparent_set_rate()
2625 * Test suite for a clock mux that isn't allowed to change parent, using
2632 .name = "clk-mux-no-reparent",
2647 strcpy(desc, t->desc); in clk_register_clk_parent_data_test_case_to_desc()
2654 * Test that a clk registered with a struct device_node can
2655 * find a parent based on struct clk_parent_data::index.
2662 * Test that a clk registered with a struct device_node can
2663 * find a parent based on struct clk_parent_data::fwname.
2670 * Test that a clk registered with a struct device_node can
2671 * find a parent based on struct clk_parent_data::name.
2675 .pdata.index = -1,
2680 * Test that a clk registered with a struct device_node can
2681 * find a parent based on struct
2690 * Test that a clk registered with a struct device_node can
2691 * find a parent based on struct clk_parent_data::{index,name}.
2700 * Test that a clk registered with a struct device_node can
2701 * find a parent based on struct
2716 * struct clk_register_clk_parent_data_of_ctx - Context for clk_parent_data OF tests
2717 * @np: device node of clk under test
2718 * @hw: clk_hw for clk under test
2734 return -ENOMEM; in clk_register_clk_parent_data_of_test_init()
2735 test->priv = ctx; in clk_register_clk_parent_data_of_test_init()
2737 ctx->np = of_find_compatible_node(NULL, NULL, "test,clk-parent-data"); in clk_register_clk_parent_data_of_test_init()
2738 if (!ctx->np) in clk_register_clk_parent_data_of_test_init()
2739 return -ENODEV; in clk_register_clk_parent_data_of_test_init()
2741 of_node_put_kunit(test, ctx->np); in clk_register_clk_parent_data_of_test_init()
2747 * Test that a clk registered with a struct device_node can find a parent based on
2752 struct clk_register_clk_parent_data_of_ctx *ctx = test->priv; in clk_register_clk_parent_data_of_test()
2756 struct clk *expected_parent, *actual_parent; in clk_register_clk_parent_data_of_test()
2758 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->np); in clk_register_clk_parent_data_of_test()
2760 expected_parent = of_clk_get_kunit(test, ctx->np, 0); in clk_register_clk_parent_data_of_test()
2763 test_param = test->param_value; in clk_register_clk_parent_data_of_test()
2764 init.parent_data = &test_param->pdata; in clk_register_clk_parent_data_of_test()
2768 ctx->hw.init = &init; in clk_register_clk_parent_data_of_test()
2769 KUNIT_ASSERT_EQ(test, 0, of_clk_hw_register_kunit(test, ctx->np, &ctx->hw)); in clk_register_clk_parent_data_of_test()
2771 parent_hw = clk_hw_get_parent(&ctx->hw); in clk_register_clk_parent_data_of_test()
2797 * struct clk_register_clk_parent_data_device_ctx - Context for clk_parent_data device tests
2798 * @dev: device of clk under test
2799 * @hw: clk_hw for clk under test
2811 return container_of(to_platform_driver(pdev->dev.driver), in clk_register_clk_parent_data_driver_to_test_context()
2820 ctx->dev = &pdev->dev; in clk_register_clk_parent_data_device_probe()
2827 struct clk_register_clk_parent_data_device_ctx *ctx = test->priv; in clk_register_clk_parent_data_device_driver()
2829 { .compatible = "test,clk-parent-data" }, in clk_register_clk_parent_data_device_driver()
2833 ctx->pdrv.probe = clk_register_clk_parent_data_device_probe; in clk_register_clk_parent_data_device_driver()
2834 ctx->pdrv.driver.of_match_table = match_table; in clk_register_clk_parent_data_device_driver()
2835 ctx->pdrv.driver.name = __func__; in clk_register_clk_parent_data_device_driver()
2836 ctx->pdrv.driver.owner = THIS_MODULE; in clk_register_clk_parent_data_device_driver()
2838 KUNIT_ASSERT_EQ(test, 0, kunit_platform_driver_register(test, &ctx->pdrv)); in clk_register_clk_parent_data_device_driver()
2839 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->dev); in clk_register_clk_parent_data_device_driver()
2846 * Test that a clk registered with a struct device can find a
2847 * parent based on struct clk_parent_data::index.
2854 * Test that a clk registered with a struct device can find a
2855 * parent based on struct clk_parent_data::fwname.
2862 * Test that a clk registered with a struct device can find a
2863 * parent based on struct clk_parent_data::name.
2867 .pdata.index = -1,
2872 * Test that a clk registered with a struct device can find a
2873 * parent based on struct clk_parent_data::{fw_name,name}.
2881 * Test that a clk registered with a struct device can find a
2882 * parent based on struct clk_parent_data::{index,name}. Index
2891 * Test that a clk registered with a struct device can find a
2892 * parent based on struct clk_parent_data::{index,fwname,name}.
2907 * Test that a clk registered with a struct device can find a parent based on in KUNIT_ARRAY_PARAM()
2916 struct clk *expected_parent, *actual_parent; in KUNIT_ARRAY_PARAM()
2920 test->priv = ctx; in KUNIT_ARRAY_PARAM()
2924 expected_parent = clk_get_kunit(test, ctx->dev, "50"); in KUNIT_ARRAY_PARAM()
2927 test_param = test->param_value; in KUNIT_ARRAY_PARAM()
2928 init.parent_data = &test_param->pdata; in KUNIT_ARRAY_PARAM()
2932 ctx->hw.init = &init; in KUNIT_ARRAY_PARAM()
2933 KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, ctx->dev, &ctx->hw)); in KUNIT_ARRAY_PARAM()
2935 parent_hw = clk_hw_get_parent(&ctx->hw); in KUNIT_ARRAY_PARAM()
2948 * Test that a clk registered with a struct device can find a
2949 * parent based on struct clk_parent_data::hw.
2953 .pdata.index = -1,
2957 * Test that a clk registered with a struct device can find a
2958 * parent based on struct clk_parent_data::hw when
2966 * Test that a clk registered with a struct device can find a
2967 * parent based on struct clk_parent_data::hw when struct
2972 .pdata.index = -1,
2977 * Test that a clk registered with a struct device can find a
2978 * parent based on struct clk_parent_data::hw when struct
2987 * Test that a clk registered with a struct device can find a
2988 * parent based on struct clk_parent_data::hw when struct
2997 * Test that a clk registered with a struct device can find a
2998 * parent based on struct clk_parent_data::hw when
3014 * Test that a clk registered with a struct device can find a in KUNIT_ARRAY_PARAM()
3015 * parent based on struct clk_parent_data::hw. in KUNIT_ARRAY_PARAM()
3021 struct clk_dummy_context *parent; in KUNIT_ARRAY_PARAM() local
3028 test->priv = ctx; in KUNIT_ARRAY_PARAM()
3032 parent = kunit_kzalloc(test, sizeof(*parent), GFP_KERNEL); in KUNIT_ARRAY_PARAM()
3033 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent); in KUNIT_ARRAY_PARAM()
3035 parent_hw = &parent->hw; in KUNIT_ARRAY_PARAM()
3036 parent_hw->init = CLK_HW_INIT_NO_PARENT("parent-clk", in KUNIT_ARRAY_PARAM()
3039 KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, ctx->dev, parent_hw)); in KUNIT_ARRAY_PARAM()
3041 test_param = test->param_value; in KUNIT_ARRAY_PARAM()
3042 memcpy(&pdata, &test_param->pdata, sizeof(pdata)); in KUNIT_ARRAY_PARAM()
3048 ctx->hw.init = &init; in KUNIT_ARRAY_PARAM()
3049 KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, ctx->dev, &ctx->hw)); in KUNIT_ARRAY_PARAM()
3051 KUNIT_EXPECT_PTR_EQ(test, parent_hw, clk_hw_get_parent(&ctx->hw)); in KUNIT_ARRAY_PARAM()
3086 * struct clk_assigned_rates_test_param - Test parameters for clk_assigned_rates test
3090 * @rate0: Initial rate of first clk
3091 * @rate1: Initial rate of second clk
3117 ctx->hw.init = &init; in clk_assigned_rates_register_clk()
3118 ctx->rate = rate; in clk_assigned_rates_register_clk()
3120 KUNIT_ASSERT_EQ(test, 0, of_clk_hw_register_kunit(test, np, &ctx->hw)); in clk_assigned_rates_register_clk()
3121 KUNIT_ASSERT_EQ(test, ctx->rate, rate); in clk_assigned_rates_register_clk()
3128 * 2. Register the clk or clks to test
3129 * 3. Register the clk provider
3130 * 4. Apply clk defaults to the consumer device if this is a consumer test
3143 test_param = test->param_value; in clk_assigned_rates_test_init()
3146 test_param->overlay_begin, in clk_assigned_rates_test_init()
3147 test_param->overlay_end)); in clk_assigned_rates_test_init()
3151 test->priv = ctx; in clk_assigned_rates_test_init()
3154 np = of_find_compatible_node(NULL, NULL, "test,clk-assigned-rates")); in clk_assigned_rates_test_init()
3157 KUNIT_ASSERT_EQ(test, 0, of_property_read_u32(np, "#clock-cells", &clk_cells)); in clk_assigned_rates_test_init()
3158 /* Only support #clock-cells = <0> or <1> */ in clk_assigned_rates_test_init()
3161 clk_assigned_rates_register_clk(test, &ctx->clk0, np, in clk_assigned_rates_test_init()
3162 "test_assigned_rate0", test_param->rate0); in clk_assigned_rates_test_init()
3166 &ctx->clk0.hw)); in clk_assigned_rates_test_init()
3168 clk_assigned_rates_register_clk(test, &ctx->clk1, np, in clk_assigned_rates_test_init()
3169 "test_assigned_rate1", test_param->rate1); in clk_assigned_rates_test_init()
3173 data->num = 2; in clk_assigned_rates_test_init()
3174 data->hws[0] = &ctx->clk0.hw; in clk_assigned_rates_test_init()
3175 data->hws[1] = &ctx->clk1.hw; in clk_assigned_rates_test_init()
3182 if (test_param->consumer_test) { in clk_assigned_rates_test_init()
3184 consumer = of_find_compatible_node(NULL, NULL, "test,clk-consumer")); in clk_assigned_rates_test_init()
3195 struct clk_assigned_rates_context *ctx = test->priv; in clk_assigned_rates_assigns_one()
3197 KUNIT_EXPECT_EQ(test, ctx->clk0.rate, ASSIGNED_RATES_0_RATE); in clk_assigned_rates_assigns_one()
3202 struct clk_assigned_rates_context *ctx = test->priv; in clk_assigned_rates_assigns_multiple()
3204 KUNIT_EXPECT_EQ(test, ctx->clk0.rate, ASSIGNED_RATES_0_RATE); in clk_assigned_rates_assigns_multiple()
3205 KUNIT_EXPECT_EQ(test, ctx->clk1.rate, ASSIGNED_RATES_1_RATE); in clk_assigned_rates_assigns_multiple()
3210 struct clk_assigned_rates_context *ctx = test->priv; in clk_assigned_rates_skips()
3211 const struct clk_assigned_rates_test_param *test_param = test->param_value; in clk_assigned_rates_skips()
3213 KUNIT_EXPECT_NE(test, ctx->clk0.rate, ASSIGNED_RATES_0_RATE); in clk_assigned_rates_skips()
3214 KUNIT_EXPECT_EQ(test, ctx->clk0.rate, test_param->rate0); in clk_assigned_rates_skips()
3226 * Test that a single cell assigned-clock-rates property
3234 * Test that a single cell assigned-clock-rates property
3243 * Test that a single cell assigned-clock-rates-u64 property
3251 * Test that a single cell assigned-clock-rates-u64 property
3271 * Test that a multiple cell assigned-clock-rates property
3279 * Test that a multiple cell assigned-clock-rates property
3288 * Test that a single cell assigned-clock-rates-u64 property
3296 * Test that a multiple cell assigned-clock-rates-u64 property
3319 * Test that an assigned-clock-rates property without an assigned-clocks
3322 .desc = "provider missing assigned-clocks",
3328 * Test that an assigned-clock-rates property without an assigned-clocks
3331 .desc = "consumer missing assigned-clocks",
3338 * Test that an assigned-clock-rates property of zero doesn't
3341 .desc = "provider assigned-clock-rates of zero",
3347 * Test that an assigned-clock-rates property of zero doesn't
3350 .desc = "consumer assigned-clock-rates of zero",
3357 * Test that an assigned-clocks property with a null phandle
3360 .desc = "provider assigned-clocks null phandle",
3366 * Test that an assigned-clocks property with a null phandle
3369 .desc = "provider assigned-clocks null phandle",
3390 * Test suite for assigned-clock-rates{-u64} DT property.
3416 MODULE_DESCRIPTION("Kunit tests for clk framework");