Lines Matching +full:set +full:- +full:rate +full:- +full:parent
1 // SPDX-License-Identifier: GPL-2.0
6 #include <linux/clk-provider.h>
7 #include <linux/clk/clk-conf.h>
30 unsigned long rate; member
39 return ctx->rate; in clk_dummy_recalc_rate()
45 /* Just return the same rate without modifying it */ in clk_dummy_determine_rate()
53 * If there's a maximum set, always run the clock at the maximum in clk_dummy_maximize_rate()
56 if (req->max_rate < ULONG_MAX) in clk_dummy_maximize_rate()
57 req->rate = req->max_rate; in clk_dummy_maximize_rate()
66 * If there's a minimum set, always run the clock at the minimum in clk_dummy_minimize_rate()
69 if (req->min_rate > 0) in clk_dummy_minimize_rate()
70 req->rate = req->min_rate; in clk_dummy_minimize_rate()
76 unsigned long rate, in clk_dummy_set_rate() argument
82 ctx->rate = rate; in clk_dummy_set_rate()
89 return -EINVAL; in clk_dummy_single_set_parent()
121 * clk_round_rate() or clk_set_rate() with a rate lower than
122 * what all the parents can provide, it will return -EINVAL.
125 * behaviour to always pick up the closest rate higher than the
126 * requested rate. If we get something lower, it thus considers
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()
224 * Test that the actual rate matches what is returned by clk_get_rate()
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()
231 unsigned long rate; in clk_test_get_rate() local
233 rate = clk_get_rate(clk); in clk_test_get_rate()
234 KUNIT_ASSERT_GT(test, rate, 0); in clk_test_get_rate()
235 KUNIT_EXPECT_EQ(test, rate, ctx->rate); in clk_test_get_rate()
241 * Test that, after a call to clk_set_rate(), the rate returned by
245 * modify the requested rate, which is our case in clk_dummy_rate_ops.
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()
252 unsigned long rate; in clk_test_set_get_rate() local
258 rate = clk_get_rate(clk); in clk_test_set_get_rate()
259 KUNIT_ASSERT_GT(test, rate, 0); in clk_test_set_get_rate()
260 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1); in clk_test_set_get_rate()
266 * Test that, after several calls to clk_set_rate(), the rate returned
270 * modify the requested rate, which is our case in clk_dummy_rate_ops.
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()
277 unsigned long rate; in clk_test_set_set_get_rate() local
287 rate = clk_get_rate(clk); in clk_test_set_set_get_rate()
288 KUNIT_ASSERT_GT(test, rate, 0); in clk_test_set_set_get_rate()
289 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2); 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()
330 * Test suite for a basic rate clock, without any parent.
332 * These tests exercise the rate API with simple scenarios
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()
365 * the rate and clk_get_rate() will return the underlying clock rate
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()
373 unsigned long rate; in clk_test_uncached_get_rate() local
375 rate = clk_get_rate(clk); in clk_test_uncached_get_rate()
376 KUNIT_ASSERT_GT(test, rate, 0); in clk_test_uncached_get_rate()
377 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_INIT_RATE); in clk_test_uncached_get_rate()
379 /* We change the rate behind the clock framework's back */ 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()
382 KUNIT_ASSERT_GT(test, rate, 0); in clk_test_uncached_get_rate()
383 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1); in clk_test_uncached_get_rate()
390 * properly if the rate hasn't changed.
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()
397 unsigned long rate; in clk_test_uncached_set_range() local
405 rate = clk_get_rate(clk); in clk_test_uncached_set_range()
406 KUNIT_ASSERT_GT(test, rate, 0); in clk_test_uncached_set_range()
407 KUNIT_EXPECT_GE(test, rate, DUMMY_CLOCK_RATE_1); in clk_test_uncached_set_range()
408 KUNIT_EXPECT_LE(test, rate, DUMMY_CLOCK_RATE_2); in clk_test_uncached_set_range()
415 * properly if the rate has changed in hardware.
417 * In this case, it means that if the rate wasn't initially in the range
418 * we're trying to set, but got changed at some point into the range
419 * without the kernel knowing about it, its rate shouldn't be affected.
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()
426 unsigned long rate; in clk_test_uncached_updated_rate_set_range() local
428 /* We change the rate behind the clock framework's back */ in clk_test_uncached_updated_rate_set_range()
429 ctx->rate = DUMMY_CLOCK_RATE_1 + 1000; in clk_test_uncached_updated_rate_set_range()
436 rate = clk_get_rate(clk); in clk_test_uncached_updated_rate_set_range()
437 KUNIT_ASSERT_GT(test, rate, 0); in clk_test_uncached_updated_rate_set_range()
438 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1 + 1000); in clk_test_uncached_updated_rate_set_range()
451 * Test suite for a basic, uncached, rate clock, without any parent.
453 * These tests exercise the rate API with simple scenarios
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()
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()
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()
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()
543 * Test that for a clock with a multiple parents, if we set a range on
544 * that clock and the parent is changed, its rate after the reparenting
548 * reevaluate whether the new clock rate is within its boundaries or
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()
558 unsigned long rate; in clk_test_multiple_parents_mux_set_range_set_parent_get_rate() local
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()
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()
577 DUMMY_CLOCK_RATE_1 - 1000, 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()
585 KUNIT_ASSERT_GT(test, rate, 0); 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()
587 KUNIT_EXPECT_LE(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()
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()
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()
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()
687 * parent, calling clk_drop_range() on the mux won't affect the parent
688 * rate.
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()
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()
716 clk_put(parent); 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()
730 struct clk *parent; in clk_test_orphan_transparent_multiple_parent_mux_set_parent_get_rate() local
731 unsigned long parent_rate, rate; 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()
744 KUNIT_ASSERT_GT(test, rate, 0); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_get_rate()
745 KUNIT_EXPECT_EQ(test, parent_rate, rate); 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()
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()
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()
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
787 * its rate is out of range.
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()
795 struct clk *parent; in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_modified() local
796 unsigned long rate; 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()
808 rate = clk_get_rate(clk); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_modified()
809 KUNIT_ASSERT_GT(test, rate, 0); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_modified()
810 KUNIT_EXPECT_GE(test, rate, DUMMY_CLOCK_RATE_1); in clk_test_orphan_transparent_multiple_parent_mux_set_parent_set_range_modified()
811 KUNIT_EXPECT_LE(test, rate, DUMMY_CLOCK_RATE_2); 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()
819 * parent, calling clk_set_rate_range() won't affect the parent state if
820 * its rate is within range.
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()
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()
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()
855 * Test that, for a mux whose current parent hasn't been registered yet,
857 * account when rounding a rate.
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()
865 long rate; in clk_test_orphan_transparent_multiple_parent_mux_set_range_round_rate() local
871 rate = clk_round_rate(clk, DUMMY_CLOCK_RATE_1 - 1000); in clk_test_orphan_transparent_multiple_parent_mux_set_range_round_rate()
872 KUNIT_ASSERT_GT(test, rate, 0); in clk_test_orphan_transparent_multiple_parent_mux_set_range_round_rate()
873 KUNIT_EXPECT_GE(test, rate, DUMMY_CLOCK_RATE_1); in clk_test_orphan_transparent_multiple_parent_mux_set_range_round_rate()
874 KUNIT_EXPECT_LE(test, rate, DUMMY_CLOCK_RATE_2); in clk_test_orphan_transparent_multiple_parent_mux_set_range_round_rate()
880 * Test that, for a mux that started orphan, was assigned and rate and
881 * then got switched to a valid parent, its rate is eventually within
884 * FIXME: Even though we update the rate as part of clk_set_parent(), we
885 * don't evaluate whether that new rate is within range and needs to be
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()
894 struct clk *parent; in clk_test_orphan_transparent_multiple_parent_mux_set_range_set_parent_get_rate() local
895 unsigned long rate; 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()
909 KUNIT_ASSERT_GT(test, rate, 0); in clk_test_orphan_transparent_multiple_parent_mux_set_range_set_parent_get_rate()
910 KUNIT_EXPECT_GE(test, rate, DUMMY_CLOCK_RATE_1); in clk_test_orphan_transparent_multiple_parent_mux_set_range_set_parent_get_rate()
911 KUNIT_EXPECT_LE(test, rate, DUMMY_CLOCK_RATE_2); 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()
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()
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()
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()
1024 * Test that for a clock that can't modify its rate and with a single
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()
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()
1054 * Test that for a clock that can't modify its rate and with a single
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()
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()
1079 ret = clk_set_rate_range(parent, 3000, 4000); in clk_test_single_parent_mux_set_range_disjoint_parent_last()
1084 * Test that for a clock that can't modify its rate and with a single
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()
1095 struct clk *parent; in clk_test_single_parent_mux_set_range_round_rate_parent_only() local
1096 long rate; 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()
1106 KUNIT_ASSERT_GT(test, rate, 0); in clk_test_single_parent_mux_set_range_round_rate_parent_only()
1107 KUNIT_EXPECT_GE(test, rate, DUMMY_CLOCK_RATE_1); in clk_test_single_parent_mux_set_range_round_rate_parent_only()
1108 KUNIT_EXPECT_LE(test, rate, DUMMY_CLOCK_RATE_2); in clk_test_single_parent_mux_set_range_round_rate_parent_only()
1114 * Test that for a clock that can't modify its rate and with a single
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()
1125 struct clk *parent; in clk_test_single_parent_mux_set_range_round_rate_child_smaller() local
1126 long rate; 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()
1139 KUNIT_ASSERT_GT(test, rate, 0); in clk_test_single_parent_mux_set_range_round_rate_child_smaller()
1140 KUNIT_EXPECT_GE(test, rate, 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()
1144 KUNIT_ASSERT_GT(test, rate, 0); in clk_test_single_parent_mux_set_range_round_rate_child_smaller()
1145 KUNIT_EXPECT_GE(test, rate, DUMMY_CLOCK_RATE_1 + 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()
1152 * Test that for a clock that can't modify its rate and with a single
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()
1163 struct clk *parent; in clk_test_single_parent_mux_set_range_round_rate_parent_smaller() local
1164 long rate; 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()
1176 rate = clk_round_rate(clk, DUMMY_CLOCK_RATE_1 - 1000); in clk_test_single_parent_mux_set_range_round_rate_parent_smaller()
1177 KUNIT_ASSERT_GT(test, rate, 0); in clk_test_single_parent_mux_set_range_round_rate_parent_smaller()
1178 KUNIT_EXPECT_GE(test, rate, 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()
1182 KUNIT_ASSERT_GT(test, rate, 0); in clk_test_single_parent_mux_set_range_round_rate_parent_smaller()
1183 KUNIT_EXPECT_GE(test, rate, DUMMY_CLOCK_RATE_1 + 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()
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,
1252 * will still have the same rate after the range has been enforced.
1255 * https://lore.kernel.org/linux-clk/7720158d-10a7-a17b-73a4-a8615c9c6d5c@collabora.com/
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()
1262 unsigned long rate, new_rate; 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()
1265 KUNIT_ASSERT_GT(test, rate, 0); 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()
1275 KUNIT_EXPECT_EQ(test, rate, new_rate); 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()
1358 * will return the proper 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()
1366 unsigned long rate; 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()
1369 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_INIT_RATE); in clk_orphan_two_level_root_last_test_get_rate()
1375 * Test that, for a clock whose parent used to be orphan,
1376 * clk_set_rate_range() won't affect its rate if it is already within
1380 * https://lore.kernel.org/linux-clk/366a0232-bb4a-c357-6aa8-636e398e05eb@samsung.com/
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()
1388 unsigned long rate; in clk_orphan_two_level_root_last_test_set_range() local
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()
1397 KUNIT_ASSERT_GT(test, rate, 0); in clk_orphan_two_level_root_last_test_set_range()
1398 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_INIT_RATE); 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",
1432 * and that it will make sure the rate of the clock is within the
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()
1440 unsigned long rate; in clk_range_test_set_range() local
1448 rate = clk_get_rate(clk); in clk_range_test_set_range()
1449 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_set_range()
1450 KUNIT_EXPECT_GE(test, rate, DUMMY_CLOCK_RATE_1); in clk_range_test_set_range()
1451 KUNIT_EXPECT_LE(test, rate, DUMMY_CLOCK_RATE_2); in clk_range_test_set_range()
1457 * Test that calling clk_set_rate_range with a minimum rate higher than
1458 * the maximum rate returns an error.
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()
1476 * Test that users can't set multiple, disjoints, range that would be
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()
1504 * Test that if our clock has some boundaries and we try to round a rate
1505 * lower than the minimum, the returned rate will be within 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()
1512 long rate; in clk_range_test_set_range_round_rate_lower() local
1520 rate = clk_round_rate(clk, DUMMY_CLOCK_RATE_1 - 1000); in clk_range_test_set_range_round_rate_lower()
1521 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_set_range_round_rate_lower()
1522 KUNIT_EXPECT_GE(test, rate, DUMMY_CLOCK_RATE_1); in clk_range_test_set_range_round_rate_lower()
1523 KUNIT_EXPECT_LE(test, rate, DUMMY_CLOCK_RATE_2); in clk_range_test_set_range_round_rate_lower()
1529 * Test that if our clock has some boundaries and we try to set a rate
1530 * higher than the maximum, the new rate will be within range.
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()
1537 unsigned long rate; in clk_range_test_set_range_set_rate_lower() local
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()
1550 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_set_range_set_rate_lower()
1551 KUNIT_EXPECT_GE(test, rate, DUMMY_CLOCK_RATE_1); in clk_range_test_set_range_set_rate_lower()
1552 KUNIT_EXPECT_LE(test, rate, DUMMY_CLOCK_RATE_2); in clk_range_test_set_range_set_rate_lower()
1559 * set a rate lower than the minimum, the rate returned by
1560 * clk_round_rate() will be consistent with the new rate set by
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()
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()
1589 * Test that if our clock has some boundaries and we try to round a rate
1590 * higher than the maximum, the returned rate will be within range.
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()
1597 long rate; in clk_range_test_set_range_round_rate_higher() local
1605 rate = clk_round_rate(clk, DUMMY_CLOCK_RATE_2 + 1000); in clk_range_test_set_range_round_rate_higher()
1606 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_set_range_round_rate_higher()
1607 KUNIT_EXPECT_GE(test, rate, DUMMY_CLOCK_RATE_1); in clk_range_test_set_range_round_rate_higher()
1608 KUNIT_EXPECT_LE(test, rate, DUMMY_CLOCK_RATE_2); in clk_range_test_set_range_round_rate_higher()
1614 * Test that if our clock has some boundaries and we try to set a rate
1615 * higher than the maximum, the new rate will be within range.
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()
1622 unsigned long rate; in clk_range_test_set_range_set_rate_higher() local
1634 rate = clk_get_rate(clk); in clk_range_test_set_range_set_rate_higher()
1635 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_set_range_set_rate_higher()
1636 KUNIT_EXPECT_GE(test, rate, DUMMY_CLOCK_RATE_1); in clk_range_test_set_range_set_rate_higher()
1637 KUNIT_EXPECT_LE(test, rate, DUMMY_CLOCK_RATE_2); in clk_range_test_set_range_set_rate_higher()
1644 * set a rate higher than the maximum, the rate returned by
1645 * clk_round_rate() will be consistent with the new rate set by
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()
1674 * Test that if our clock has a rate lower than the minimum set by a
1675 * call to clk_set_rate_range(), the rate will be raised to match the
1679 * modify the requested rate, which is our case in clk_dummy_rate_ops.
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()
1686 unsigned long rate; 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()
1698 rate = clk_get_rate(clk); in clk_range_test_set_range_get_rate_raised()
1699 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_set_range_get_rate_raised()
1700 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1); in clk_range_test_set_range_get_rate_raised()
1706 * Test that if our clock has a rate higher than the maximum set by a
1707 * call to clk_set_rate_range(), the rate will be lowered to match the
1711 * modify the requested rate, which is our case in clk_dummy_rate_ops.
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()
1718 unsigned long rate; in clk_range_test_set_range_get_rate_lowered() local
1730 rate = clk_get_rate(clk); in clk_range_test_set_range_get_rate_lowered()
1731 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_set_range_get_rate_lowered()
1732 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2); in clk_range_test_set_range_get_rate_lowered()
1753 * Test suite for a basic rate clock, without any parent.
1755 * These tests exercise the rate range API: clk_set_rate_range(),
1759 .name = "clk-range-test",
1767 * clk_set_rate_range(), the core will reevaluate whether a new rate is
1770 * With clk_dummy_maximize_rate_ops, this means that the rate will
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()
1778 unsigned long rate; in clk_range_test_set_range_rate_maximized() local
1790 rate = clk_get_rate(clk); in clk_range_test_set_range_rate_maximized()
1791 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_set_range_rate_maximized()
1792 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2); 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()
1801 KUNIT_ASSERT_GT(test, rate, 0); 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()
1810 rate = clk_get_rate(clk); in clk_range_test_set_range_rate_maximized()
1811 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_set_range_rate_maximized()
1812 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2); in clk_range_test_set_range_rate_maximized()
1820 * whether a new rate is needed each and every time.
1822 * With clk_dummy_maximize_rate_ops, this means that the rate will
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()
1831 unsigned long rate; in clk_range_test_multiple_set_range_rate_maximized() local
1849 rate = clk_get_rate(clk); in clk_range_test_multiple_set_range_rate_maximized()
1850 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_multiple_set_range_rate_maximized()
1851 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2); in clk_range_test_multiple_set_range_rate_maximized()
1859 rate = clk_get_rate(clk); in clk_range_test_multiple_set_range_rate_maximized()
1860 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_multiple_set_range_rate_maximized()
1861 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1); in clk_range_test_multiple_set_range_rate_maximized()
1867 rate = clk_get_rate(clk); in clk_range_test_multiple_set_range_rate_maximized()
1868 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_multiple_set_range_rate_maximized()
1869 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2); in clk_range_test_multiple_set_range_rate_maximized()
1879 * whether a new rate is needed, including when a user drop its clock.
1881 * With clk_dummy_maximize_rate_ops, this means that the rate will
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()
1890 unsigned long rate; in clk_range_test_multiple_set_range_rate_put_maximized() local
1908 rate = clk_get_rate(clk); in clk_range_test_multiple_set_range_rate_put_maximized()
1909 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_multiple_set_range_rate_put_maximized()
1910 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2); 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()
1919 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_multiple_set_range_rate_put_maximized()
1920 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1); 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()
1925 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_multiple_set_range_rate_put_maximized()
1926 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2); in clk_range_test_multiple_set_range_rate_put_maximized()
1940 * Test suite for a basic rate clock, without any parent.
1942 * These tests exercise the rate range API: clk_set_rate_range(),
1944 * driver that will always try to run at the highest possible rate.
1947 .name = "clk-range-maximize-test",
1955 * clk_set_rate_range(), the core will reevaluate whether a new rate is
1958 * With clk_dummy_minimize_rate_ops, this means that the rate will
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()
1966 unsigned long rate; 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()
1978 rate = clk_get_rate(clk); in clk_range_test_set_range_rate_minimized()
1979 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_set_range_rate_minimized()
1980 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1); in clk_range_test_set_range_rate_minimized()
1988 rate = clk_get_rate(clk); in clk_range_test_set_range_rate_minimized()
1989 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_set_range_rate_minimized()
1990 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1 + 1000); in clk_range_test_set_range_rate_minimized()
1998 rate = clk_get_rate(clk); in clk_range_test_set_range_rate_minimized()
1999 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_set_range_rate_minimized()
2000 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1); in clk_range_test_set_range_rate_minimized()
2008 * whether a new rate is needed each and every time.
2010 * With clk_dummy_minimize_rate_ops, this means that the rate will
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()
2019 unsigned long rate; in clk_range_test_multiple_set_range_rate_minimized() local
2033 rate = clk_get_rate(clk); in clk_range_test_multiple_set_range_rate_minimized()
2034 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_multiple_set_range_rate_minimized()
2035 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1); in clk_range_test_multiple_set_range_rate_minimized()
2043 rate = clk_get_rate(clk); in clk_range_test_multiple_set_range_rate_minimized()
2044 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_multiple_set_range_rate_minimized()
2045 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2); in clk_range_test_multiple_set_range_rate_minimized()
2051 rate = clk_get_rate(clk); in clk_range_test_multiple_set_range_rate_minimized()
2052 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_multiple_set_range_rate_minimized()
2053 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1); in clk_range_test_multiple_set_range_rate_minimized()
2063 * whether a new rate is needed, including when a user drop its clock.
2065 * With clk_dummy_minimize_rate_ops, this means that the rate will
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()
2074 unsigned long rate; in clk_range_test_multiple_set_range_rate_put_minimized() local
2088 rate = clk_get_rate(clk); in clk_range_test_multiple_set_range_rate_put_minimized()
2089 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_multiple_set_range_rate_put_minimized()
2090 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1); 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()
2099 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_multiple_set_range_rate_put_minimized()
2100 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2); 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()
2105 KUNIT_ASSERT_GT(test, rate, 0); in clk_range_test_multiple_set_range_rate_put_minimized()
2106 KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1); in clk_range_test_multiple_set_range_rate_put_minimized()
2120 * Test suite for a basic rate clock, without any parent.
2122 * These tests exercise the rate range API: clk_set_rate_range(),
2124 * driver that will always try to run at the lowest possible rate.
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
2243 * change rate doesn't return a clk_rate_request structure with
2244 * the best_parent_hw pointer pointing to the parent.
2251 * Test that __clk_mux_determine_rate() on the parent that
2252 * can't change rate doesn't return a clk_rate_request
2254 * the parent.
2261 * Test that __clk_mux_determine_rate_closest() on the parent
2262 * that can't change rate doesn't return a clk_rate_request
2264 * the parent.
2271 * Test that clk_hw_determine_rate_no_reparent() on the parent
2272 * that can't change rate doesn't return a clk_rate_request
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()
2298 unsigned long rate; 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()
2306 KUNIT_ASSERT_EQ(test, rate, DUMMY_CLOCK_RATE_1); in KUNIT_ARRAY_PARAM()
2309 KUNIT_EXPECT_EQ(test, req.rate, 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()
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
2325 * CLK_SET_RATE_PARENT flag, and will forward rate requests to the mux, which
2326 * will then select which parent is the best fit for a given rate.
2332 .name = "clk-leaf-mux-set-rate-parent",
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()
2431 clk_notifier_unregister(clk, &ctx->clk_nb); 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()
2449 struct clk *new_parent = clk_hw_get_clk(&ctx->mux_ctx.parents_ctx[1].hw, NULL); 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()
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
2544 * clk_round_rate() on it with a rate that should cause it to change
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()
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()
2579 * Test that if the we have a mux that cannot change parent and we call
2580 * clk_set_rate() on it with a rate that should cause it to change
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()
2588 struct clk *other_parent, *parent; in clk_mux_no_reparent_set_rate() local
2591 unsigned long rate; 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()
2611 rate = clk_get_rate(clk); in clk_mux_no_reparent_set_rate()
2612 KUNIT_ASSERT_GT(test, rate, 0); in clk_mux_no_reparent_set_rate()
2613 KUNIT_EXPECT_EQ(test, rate, parent_rate); 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()
2655 * find a parent based on struct clk_parent_data::index.
2663 * find a parent based on struct clk_parent_data::fwname.
2671 * find a parent based on struct clk_parent_data::name.
2675 .pdata.index = -1,
2681 * find a parent based on struct
2691 * find a parent based on struct clk_parent_data::{index,name}.
2701 * find a parent based on struct
2716 * struct clk_register_clk_parent_data_of_ctx - Context for clk_parent_data OF tests
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
2748 * struct clk_parent_data when the hw member isn't set.
2752 struct clk_register_clk_parent_data_of_ctx *ctx = test->priv; 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
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()
2847 * parent based on struct clk_parent_data::index.
2855 * parent based on struct clk_parent_data::fwname.
2863 * parent based on struct clk_parent_data::name.
2867 .pdata.index = -1,
2873 * parent based on struct clk_parent_data::{fw_name,name}.
2882 * parent based on struct clk_parent_data::{index,name}. Index
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()
2908 * struct clk_parent_data when the hw member isn't set. 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()
2949 * parent based on struct clk_parent_data::hw.
2953 .pdata.index = -1,
2958 * parent based on struct clk_parent_data::hw when
2959 * struct clk_parent_data::fw_name is set.
2967 * parent based on struct clk_parent_data::hw when struct
2968 * clk_parent_data::name is set.
2972 .pdata.index = -1,
2978 * parent based on struct clk_parent_data::hw when struct
2979 * clk_parent_data::{fw_name,name} are set.
2988 * parent based on struct clk_parent_data::hw when struct
2989 * clk_parent_data::index is set. The hw pointer takes
2998 * parent based on struct clk_parent_data::hw when
2999 * struct clk_parent_data::{index,fwname,name} are set.
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
3111 unsigned long rate) in clk_assigned_rates_register_clk() argument
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()
3132 * The tests will set different test_param values to test different scenarios
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()
3222 /* Test cases that assign one rate */
3226 * Test that a single cell assigned-clock-rates property
3227 * assigns the rate when the property is in the provider.
3234 * Test that a single cell assigned-clock-rates property
3235 * assigns the rate when the property is in the consumer.
3243 * Test that a single cell assigned-clock-rates-u64 property
3244 * assigns the rate when the property is in the provider.
3251 * Test that a single cell assigned-clock-rates-u64 property
3252 * assigns the rate when the property is in the consumer.
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
3289 * assigns the rate when the property is in the provider.
3296 * Test that a multiple cell assigned-clock-rates-u64 property
3315 /* Test cases that skip changing the rate due to malformed DT */
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
3339 * set a rate when the property is in the provider.
3341 .desc = "provider assigned-clock-rates of zero",
3347 * Test that an assigned-clock-rates property of zero doesn't
3348 * set a rate when the property is in the consumer.
3350 .desc = "consumer assigned-clock-rates of zero",
3357 * Test that an assigned-clocks property with a null phandle
3358 * doesn't set a rate when the property is in the provider.
3360 .desc = "provider assigned-clocks null phandle",
3366 * Test that an assigned-clocks property with a null phandle
3367 * doesn't set a rate when the property is in the consumer.
3369 .desc = "provider assigned-clocks null phandle",
3390 * Test suite for assigned-clock-rates{-u64} DT property.