clk: Update req_rate on __clk_recalc_rates()

Commit cb1b1dd96241 ("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: cb1b1dd96241 ("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>

authored by Maxime Ripard and committed by Stephen Boyd 096f2a0c 433fb8a6

+11 -28
+11 -28
drivers/clk/clk.c
··· 1760 1760 /** 1761 1761 * __clk_recalc_rates 1762 1762 * @core: first clk in the subtree 1763 + * @update_req: Whether req_rate should be updated with the new rate 1763 1764 * @msg: notification type (see include/linux/clk.h) 1764 1765 * 1765 1766 * Walks the subtree of clks starting with clk and recalculates rates as it ··· 1770 1769 * clk_recalc_rates also propagates the POST_RATE_CHANGE notification, 1771 1770 * if necessary. 1772 1771 */ 1773 - static void __clk_recalc_rates(struct clk_core *core, unsigned long msg) 1772 + static void __clk_recalc_rates(struct clk_core *core, bool update_req, 1773 + unsigned long msg) 1774 1774 { 1775 1775 unsigned long old_rate; 1776 1776 unsigned long parent_rate = 0; ··· 1785 1783 parent_rate = core->parent->rate; 1786 1784 1787 1785 core->rate = clk_recalc(core, parent_rate); 1786 + if (update_req) 1787 + core->req_rate = core->rate; 1788 1788 1789 1789 /* 1790 1790 * ignore NOTIFY_STOP and NOTIFY_BAD return values for POST_RATE_CHANGE ··· 1796 1792 __clk_notify(core, msg, old_rate, core->rate); 1797 1793 1798 1794 hlist_for_each_entry(child, &core->children, child_node) 1799 - __clk_recalc_rates(child, msg); 1795 + __clk_recalc_rates(child, update_req, msg); 1800 1796 } 1801 1797 1802 1798 static unsigned long clk_core_get_rate_recalc(struct clk_core *core) 1803 1799 { 1804 1800 if (core && (core->flags & CLK_GET_RATE_NOCACHE)) 1805 - __clk_recalc_rates(core, 0); 1801 + __clk_recalc_rates(core, false, 0); 1806 1802 1807 1803 return clk_core_get_rate_nolock(core); 1808 1804 } ··· 1905 1901 clk_core_update_orphan_status(child, is_orphan); 1906 1902 } 1907 1903 1908 - /* 1909 - * Update the orphan rate and req_rate of @core and all its children. 1910 - */ 1911 - static void clk_core_update_orphan_child_rates(struct clk_core *core) 1912 - { 1913 - struct clk_core *child; 1914 - unsigned long parent_rate = 0; 1915 - 1916 - if (core->parent) 1917 - parent_rate = core->parent->rate; 1918 - 1919 - core->rate = core->req_rate = clk_recalc(core, parent_rate); 1920 - 1921 - hlist_for_each_entry(child, &core->children, child_node) 1922 - clk_core_update_orphan_child_rates(child); 1923 - } 1924 - 1925 1904 static void clk_reparent(struct clk_core *core, struct clk_core *new_parent) 1926 1905 { 1927 1906 bool was_orphan = core->orphan; ··· 1974 1987 clk_reparent(core, parent); 1975 1988 clk_enable_unlock(flags); 1976 1989 1977 - clk_core_update_orphan_child_rates(core); 1978 - 1979 1990 return old_parent; 1980 1991 } 1981 1992 ··· 2019 2034 clk_reparent(core, old_parent); 2020 2035 clk_enable_unlock(flags); 2021 2036 2022 - clk_core_update_orphan_child_rates(core); 2023 2037 __clk_set_parent_after(core, old_parent, parent); 2024 2038 2025 2039 return ret; ··· 2642 2658 struct clk_core *new_parent) 2643 2659 { 2644 2660 clk_reparent(core, new_parent); 2645 - clk_core_update_orphan_child_rates(core); 2646 2661 __clk_recalc_accuracies(core); 2647 - __clk_recalc_rates(core, POST_RATE_CHANGE); 2662 + __clk_recalc_rates(core, true, POST_RATE_CHANGE); 2648 2663 } 2649 2664 2650 2665 void clk_hw_reparent(struct clk_hw *hw, struct clk_hw *new_parent) ··· 2727 2744 2728 2745 /* propagate rate an accuracy recalculation accordingly */ 2729 2746 if (ret) { 2730 - __clk_recalc_rates(core, ABORT_RATE_CHANGE); 2747 + __clk_recalc_rates(core, true, ABORT_RATE_CHANGE); 2731 2748 } else { 2732 - __clk_recalc_rates(core, POST_RATE_CHANGE); 2749 + __clk_recalc_rates(core, true, POST_RATE_CHANGE); 2733 2750 __clk_recalc_accuracies(core); 2734 2751 } 2735 2752 ··· 3626 3643 __clk_set_parent_before(orphan, parent); 3627 3644 __clk_set_parent_after(orphan, parent, NULL); 3628 3645 __clk_recalc_accuracies(orphan); 3629 - __clk_recalc_rates(orphan, 0); 3646 + __clk_recalc_rates(orphan, true, 0); 3630 3647 3631 3648 /* 3632 3649 * __clk_init_parent() will set the initial req_rate to