Skip to content

Commit 096f2a0

Browse files
mripardbebarino
authored andcommitted
clk: Update req_rate on __clk_recalc_rates()
Commit cb1b1dd ("clk: Set req_rate on reparenting") introduced a new function, clk_core_update_orphan_child_rates(), that updates the req_rate field on reparenting. It turns out that that function will interfere with the clock notifying done by __clk_recalc_rates(). This ends up reporting the new rate in both the old_rate and new_rate fields of struct clk_notifier_data. Since clk_core_update_orphan_child_rates() is basically __clk_recalc_rates() without the notifiers, and with the req_rate field update, we can drop clk_core_update_orphan_child_rates() entirely, and make __clk_recalc_rates() update req_rate. However, __clk_recalc_rates() is being called in several code paths: when retrieving a rate (most likely through clk_get_rate()), when changing parents (through clk_set_rate() or clk_hw_reparent()), or when updating the orphan status (through clk_core_reparent_orphans_nolock(), called at registration). Updating req_rate on reparenting or initialisation makes sense, but we shouldn't do it on clk_get_rate(). Thus an extra flag has been added to update or not req_rate depending on the context. Fixes: cb1b1dd ("clk: Set req_rate on reparenting") Link: https://lore.kernel.org/linux-clk/0acc7217-762c-7c0d-45a0-55c384824ce4@samsung.com/ Link: https://lore.kernel.org/linux-clk/Y0QNSx+ZgqKSvPOC@sirena.org.uk/ Reported-by: Marek Szyprowski <m.szyprowski@samsung.com> Reported-by: Mark Brown <broonie@kernel.org> Suggested-by: Stephen Boyd <sboyd@kernel.org> Signed-off-by: Maxime Ripard <maxime@cerno.tech> Link: https://lore.kernel.org/r/20221010-rpi-clk-fixes-again-v1-1-d87ba82ac404@cerno.tech Tested-by: Marek Szyprowski <m.szyprowski@samsung.com> Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent 433fb8a commit 096f2a0

File tree

1 file changed

+11
-28
lines changed

1 file changed

+11
-28
lines changed

drivers/clk/clk.c

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,7 @@ static unsigned long clk_recalc(struct clk_core *core,
17601760
/**
17611761
* __clk_recalc_rates
17621762
* @core: first clk in the subtree
1763+
* @update_req: Whether req_rate should be updated with the new rate
17631764
* @msg: notification type (see include/linux/clk.h)
17641765
*
17651766
* Walks the subtree of clks starting with clk and recalculates rates as it
@@ -1769,7 +1770,8 @@ static unsigned long clk_recalc(struct clk_core *core,
17691770
* clk_recalc_rates also propagates the POST_RATE_CHANGE notification,
17701771
* if necessary.
17711772
*/
1772-
static void __clk_recalc_rates(struct clk_core *core, unsigned long msg)
1773+
static void __clk_recalc_rates(struct clk_core *core, bool update_req,
1774+
unsigned long msg)
17731775
{
17741776
unsigned long old_rate;
17751777
unsigned long parent_rate = 0;
@@ -1783,6 +1785,8 @@ static void __clk_recalc_rates(struct clk_core *core, unsigned long msg)
17831785
parent_rate = core->parent->rate;
17841786

17851787
core->rate = clk_recalc(core, parent_rate);
1788+
if (update_req)
1789+
core->req_rate = core->rate;
17861790

17871791
/*
17881792
* ignore NOTIFY_STOP and NOTIFY_BAD return values for POST_RATE_CHANGE
@@ -1792,13 +1796,13 @@ static void __clk_recalc_rates(struct clk_core *core, unsigned long msg)
17921796
__clk_notify(core, msg, old_rate, core->rate);
17931797

17941798
hlist_for_each_entry(child, &core->children, child_node)
1795-
__clk_recalc_rates(child, msg);
1799+
__clk_recalc_rates(child, update_req, msg);
17961800
}
17971801

17981802
static unsigned long clk_core_get_rate_recalc(struct clk_core *core)
17991803
{
18001804
if (core && (core->flags & CLK_GET_RATE_NOCACHE))
1801-
__clk_recalc_rates(core, 0);
1805+
__clk_recalc_rates(core, false, 0);
18021806

18031807
return clk_core_get_rate_nolock(core);
18041808
}
@@ -1901,23 +1905,6 @@ static void clk_core_update_orphan_status(struct clk_core *core, bool is_orphan)
19011905
clk_core_update_orphan_status(child, is_orphan);
19021906
}
19031907

1904-
/*
1905-
* Update the orphan rate and req_rate of @core and all its children.
1906-
*/
1907-
static void clk_core_update_orphan_child_rates(struct clk_core *core)
1908-
{
1909-
struct clk_core *child;
1910-
unsigned long parent_rate = 0;
1911-
1912-
if (core->parent)
1913-
parent_rate = core->parent->rate;
1914-
1915-
core->rate = core->req_rate = clk_recalc(core, parent_rate);
1916-
1917-
hlist_for_each_entry(child, &core->children, child_node)
1918-
clk_core_update_orphan_child_rates(child);
1919-
}
1920-
19211908
static void clk_reparent(struct clk_core *core, struct clk_core *new_parent)
19221909
{
19231910
bool was_orphan = core->orphan;
@@ -1987,8 +1974,6 @@ static struct clk_core *__clk_set_parent_before(struct clk_core *core,
19871974
clk_reparent(core, parent);
19881975
clk_enable_unlock(flags);
19891976

1990-
clk_core_update_orphan_child_rates(core);
1991-
19921977
return old_parent;
19931978
}
19941979

@@ -2034,7 +2019,6 @@ static int __clk_set_parent(struct clk_core *core, struct clk_core *parent,
20342019
clk_reparent(core, old_parent);
20352020
clk_enable_unlock(flags);
20362021

2037-
clk_core_update_orphan_child_rates(core);
20382022
__clk_set_parent_after(core, old_parent, parent);
20392023

20402024
return ret;
@@ -2658,9 +2642,8 @@ static void clk_core_reparent(struct clk_core *core,
26582642
struct clk_core *new_parent)
26592643
{
26602644
clk_reparent(core, new_parent);
2661-
clk_core_update_orphan_child_rates(core);
26622645
__clk_recalc_accuracies(core);
2663-
__clk_recalc_rates(core, POST_RATE_CHANGE);
2646+
__clk_recalc_rates(core, true, POST_RATE_CHANGE);
26642647
}
26652648

26662649
void clk_hw_reparent(struct clk_hw *hw, struct clk_hw *new_parent)
@@ -2744,9 +2727,9 @@ static int clk_core_set_parent_nolock(struct clk_core *core,
27442727

27452728
/* propagate rate an accuracy recalculation accordingly */
27462729
if (ret) {
2747-
__clk_recalc_rates(core, ABORT_RATE_CHANGE);
2730+
__clk_recalc_rates(core, true, ABORT_RATE_CHANGE);
27482731
} else {
2749-
__clk_recalc_rates(core, POST_RATE_CHANGE);
2732+
__clk_recalc_rates(core, true, POST_RATE_CHANGE);
27502733
__clk_recalc_accuracies(core);
27512734
}
27522735

@@ -3643,7 +3626,7 @@ static void clk_core_reparent_orphans_nolock(void)
36433626
__clk_set_parent_before(orphan, parent);
36443627
__clk_set_parent_after(orphan, parent, NULL);
36453628
__clk_recalc_accuracies(orphan);
3646-
__clk_recalc_rates(orphan, 0);
3629+
__clk_recalc_rates(orphan, true, 0);
36473630

36483631
/*
36493632
* __clk_init_parent() will set the initial req_rate to

0 commit comments

Comments
 (0)