bcm27xx: add support for linux v5.15
[openwrt/staging/chunkeey.git] / target / linux / bcm27xx / patches-5.15 / 950-0854-clk-Introduce-clk_core_has_parent.patch
1 From ca0a8c7c024409a0c83afdab7e436348d1a7390f Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Thu, 7 Apr 2022 14:11:37 +0200
4 Subject: [PATCH] clk: Introduce clk_core_has_parent()
5
6 We will need to know if a clk_core pointer has a given parent in other
7 functions, so let's create a clk_core_has_parent() function that
8 clk_has_parent() will call into.
9
10 For good measure, let's add some unit tests as well to make sure it
11 works properly.
12
13 Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com> # imx8mp
14 Tested-by: Marek Szyprowski <m.szyprowski@samsung.com> # exynos4210, meson g12b
15 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
16 ---
17 drivers/clk/clk.c | 36 +++++++++++++++++++++---------------
18 drivers/clk/clk_test.c | 32 ++++++++++++++++++++++++++++++++
19 2 files changed, 53 insertions(+), 15 deletions(-)
20
21 --- a/drivers/clk/clk.c
22 +++ b/drivers/clk/clk.c
23 @@ -545,6 +545,26 @@ static bool mux_is_better_rate(unsigned
24 static int clk_core_round_rate_nolock(struct clk_core *core,
25 struct clk_rate_request *req);
26
27 +static bool clk_core_has_parent(struct clk_core *core, struct clk_core *parent)
28 +{
29 + unsigned int i;
30 +
31 + /* Optimize for the case where the parent is already the parent. */
32 + if (core == parent)
33 + return true;
34 +
35 + for (i = 0; i < core->num_parents; i++) {
36 + struct clk_core *tmp = clk_core_get_parent_by_index(core, i);
37 + if (!tmp)
38 + continue;
39 +
40 + if (tmp == parent)
41 + return true;
42 + }
43 +
44 + return false;
45 +}
46 +
47 int clk_mux_determine_rate_flags(struct clk_hw *hw,
48 struct clk_rate_request *req,
49 unsigned long flags)
50 @@ -2569,25 +2589,11 @@ void clk_hw_reparent(struct clk_hw *hw,
51 */
52 bool clk_has_parent(struct clk *clk, struct clk *parent)
53 {
54 - struct clk_core *core, *parent_core;
55 - int i;
56 -
57 /* NULL clocks should be nops, so return success if either is NULL. */
58 if (!clk || !parent)
59 return true;
60
61 - core = clk->core;
62 - parent_core = parent->core;
63 -
64 - /* Optimize for the case where the parent is already the parent. */
65 - if (core->parent == parent_core)
66 - return true;
67 -
68 - for (i = 0; i < core->num_parents; i++)
69 - if (!strcmp(core->parents[i].name, parent_core->name))
70 - return true;
71 -
72 - return false;
73 + return clk_core_has_parent(clk->core, parent->core);
74 }
75 EXPORT_SYMBOL_GPL(clk_has_parent);
76
77 --- a/drivers/clk/clk_test.c
78 +++ b/drivers/clk/clk_test.c
79 @@ -473,8 +473,24 @@ clk_test_multiple_parents_mux_get_parent
80 KUNIT_EXPECT_TRUE(test, clk_is_match(parent, ctx->parents_ctx[0].hw.clk));
81 }
82
83 +/*
84 + * Test that for a clock with a multiple parents, clk_has_parent()
85 + * actually reports all of them as parents.
86 + */
87 +static void
88 +clk_test_multiple_parents_mux_has_parent(struct kunit *test)
89 +{
90 + struct clk_multiple_parent_ctx *ctx = test->priv;
91 + struct clk_hw *hw = &ctx->hw;
92 + struct clk *clk = hw->clk;
93 +
94 + KUNIT_EXPECT_TRUE(test, clk_has_parent(clk, ctx->parents_ctx[0].hw.clk));
95 + KUNIT_EXPECT_TRUE(test, clk_has_parent(clk, ctx->parents_ctx[1].hw.clk));
96 +}
97 +
98 static struct kunit_case clk_multiple_parents_mux_test_cases[] = {
99 KUNIT_CASE(clk_test_multiple_parents_mux_get_parent),
100 + KUNIT_CASE(clk_test_multiple_parents_mux_has_parent),
101 {}
102 };
103
104 @@ -907,6 +923,21 @@ clk_test_single_parent_mux_get_parent(st
105 }
106
107 /*
108 + * Test that for a clock with a single parent, clk_has_parent() actually
109 + * reports it as a parent.
110 + */
111 +static void
112 +clk_test_single_parent_mux_has_parent(struct kunit *test)
113 +{
114 + struct clk_single_parent_ctx *ctx = test->priv;
115 + struct clk_hw *hw = &ctx->hw;
116 + struct clk *clk = hw->clk;
117 + struct clk *parent = ctx->parent_ctx.hw.clk;
118 +
119 + KUNIT_EXPECT_TRUE(test, clk_has_parent(clk, parent));
120 +}
121 +
122 +/*
123 * Test that for a clock that can't modify its rate and with a single
124 * parent, if we set disjoints range on the parent and then the child,
125 * the second will return an error.
126 @@ -1004,6 +1035,7 @@ clk_test_single_parent_mux_set_range_rou
127
128 static struct kunit_case clk_single_parent_mux_test_cases[] = {
129 KUNIT_CASE(clk_test_single_parent_mux_get_parent),
130 + KUNIT_CASE(clk_test_single_parent_mux_has_parent),
131 KUNIT_CASE(clk_test_single_parent_mux_set_range_disjoint_child_last),
132 KUNIT_CASE(clk_test_single_parent_mux_set_range_disjoint_parent_last),
133 KUNIT_CASE(clk_test_single_parent_mux_set_range_round_rate_child_smaller),