3491adc8ce5cb9e294c6c6f60f5f279dae4769d1
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.15 / 950-0867-clk-tests-Add-missing-test-case-for-ranges.patch
1 From d75b267a431f5afd20cfea90021bb63cc8ecfc6b Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Fri, 15 Apr 2022 15:00:44 +0200
4 Subject: [PATCH] clk: tests: Add missing test case for ranges
5
6 Let's add a test on the rate range after a reparenting. This fails for
7 now, but it's worth having it to document the corner cases we don't
8 support yet.
9
10 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
11 ---
12 drivers/clk/clk_test.c | 52 ++++++++++++++++++++++++++++++++++++++++++
13 1 file changed, 52 insertions(+)
14
15 --- a/drivers/clk/clk_test.c
16 +++ b/drivers/clk/clk_test.c
17 @@ -488,9 +488,61 @@ clk_test_multiple_parents_mux_has_parent
18 KUNIT_EXPECT_TRUE(test, clk_has_parent(clk, ctx->parents_ctx[1].hw.clk));
19 }
20
21 +/*
22 + * Test that for a clock with a multiple parents, if we set a range on
23 + * that clock and the parent is changed, its rate after the reparenting
24 + * is still within the range we asked for.
25 + *
26 + * FIXME: clk_set_parent() only does the reparenting but doesn't
27 + * reevaluate whether the new clock rate is within its boundaries or
28 + * not.
29 + */
30 +static void
31 +clk_test_multiple_parents_mux_set_range_set_parent_get_rate(struct kunit *test)
32 +{
33 + struct clk_multiple_parent_ctx *ctx = test->priv;
34 + struct clk_hw *hw = &ctx->hw;
35 + struct clk *clk = hw->clk;
36 + struct clk *parent1, *parent2;
37 + unsigned long rate;
38 + int ret;
39 +
40 + kunit_skip(test, "This needs to be fixed in the core.");
41 +
42 + parent1 = clk_hw_get_clk(&ctx->parents_ctx[0].hw, NULL);
43 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent1);
44 + KUNIT_ASSERT_TRUE(test, clk_is_match(clk_get_parent(clk), parent1));
45 +
46 + parent2 = clk_hw_get_clk(&ctx->parents_ctx[1].hw, NULL);
47 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent2);
48 +
49 + ret = clk_set_rate(parent1, DUMMY_CLOCK_RATE_1);
50 + KUNIT_ASSERT_EQ(test, ret, 0);
51 +
52 + ret = clk_set_rate(parent2, DUMMY_CLOCK_RATE_2);
53 + KUNIT_ASSERT_EQ(test, ret, 0);
54 +
55 + ret = clk_set_rate_range(clk,
56 + DUMMY_CLOCK_RATE_1 - 1000,
57 + DUMMY_CLOCK_RATE_1 + 1000);
58 + KUNIT_ASSERT_EQ(test, ret, 0);
59 +
60 + ret = clk_set_parent(clk, parent2);
61 + KUNIT_ASSERT_EQ(test, ret, 0);
62 +
63 + rate = clk_get_rate(clk);
64 + KUNIT_ASSERT_GT(test, rate, 0);
65 + KUNIT_EXPECT_GE(test, rate, DUMMY_CLOCK_RATE_1 - 1000);
66 + KUNIT_EXPECT_LE(test, rate, DUMMY_CLOCK_RATE_1 + 1000);
67 +
68 + clk_put(parent2);
69 + clk_put(parent1);
70 +}
71 +
72 static struct kunit_case clk_multiple_parents_mux_test_cases[] = {
73 KUNIT_CASE(clk_test_multiple_parents_mux_get_parent),
74 KUNIT_CASE(clk_test_multiple_parents_mux_has_parent),
75 + KUNIT_CASE(clk_test_multiple_parents_mux_set_range_set_parent_get_rate),
76 {}
77 };
78