<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/drivers/clk/clk_test.c, branch v6.6.148</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v6.6.148</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v6.6.148'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2023-06-09T01:39:25+00:00</updated>
<entry>
<title>clk: test: Add a determine_rate hook</title>
<updated>2023-06-09T01:39:25+00:00</updated>
<author>
<name>Maxime Ripard</name>
<email>maxime@cerno.tech</email>
</author>
<published>2023-05-05T11:25:09+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=aebddfe2dfaf1100cfdeb56783384868786bca05'/>
<id>urn:sha1:aebddfe2dfaf1100cfdeb56783384868786bca05</id>
<content type='text'>
The single parent clock in our kunit tests implements a mux with a
set_parent hook, but doesn't provide a determine_rate implementation.

This is not entirely unexpected, since its whole purpose it to have a
single parent. When determine_rate is missing, and since
CLK_SET_RATE_PARENT is set for all its instances, the default behaviour
of the framework will be to forward it to the current parent.

This is totally fine as far as the tests are concerned, but we'll start
to mandate a determine_rate implementation when set_parent is set, so
let's fill it with __clk_mux_determine_rate() which will have the same
behavior.

Signed-off-by: Maxime Ripard &lt;maxime@cerno.tech&gt;
Link: https://lore.kernel.org/r/20221018-clk-range-checks-fixes-v4-7-971d5077e7d2@cerno.tech
Signed-off-by: Stephen Boyd &lt;sboyd@kernel.org&gt;
</content>
</entry>
<entry>
<title>clk: Introduce clk_hw_determine_rate_no_reparent()</title>
<updated>2023-06-09T01:39:25+00:00</updated>
<author>
<name>Stephen Boyd</name>
<email>sboyd@kernel.org</email>
</author>
<published>2023-05-05T11:25:06+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=33b70fbc4f815f0acb327fa506c988ef25cd943d'/>
<id>urn:sha1:33b70fbc4f815f0acb327fa506c988ef25cd943d</id>
<content type='text'>
Some clock drivers do not want to allow any reparenting on a given
clock, but usually do so by not providing any determine_rate
implementation.

Whenever we call clk_round_rate() or clk_set_rate(), this leads to
clk_core_can_round() returning false and thus the rest of the function
either forwarding the rate request to its current parent if
CLK_SET_RATE_PARENT is set, or just returning the current clock rate.

This behaviour happens implicitly, and as we move forward to making a
determine_rate implementation required for muxes, we need some way to
explicitly opt-in for that behaviour.

Fortunately, this is exactly what the clk_core_determine_rate_no_reparent()
function is doing, so we can simply make it available to drivers.

Cc: Abel Vesa &lt;abelvesa@kernel.org&gt;
Cc: Alessandro Zummo &lt;a.zummo@towertech.it&gt;
Cc: Alexandre Belloni &lt;alexandre.belloni@bootlin.com&gt;
Cc: Alexandre Torgue &lt;alexandre.torgue@foss.st.com&gt;
Cc: "Andreas Färber" &lt;afaerber@suse.de&gt;
Cc: AngeloGioacchino Del Regno &lt;angelogioacchino.delregno@collabora.com&gt;
Cc: Baolin Wang &lt;baolin.wang@linux.alibaba.com&gt;
Cc: Charles Keepax &lt;ckeepax@opensource.cirrus.com&gt;
Cc: Chen-Yu Tsai &lt;wens@csie.org&gt;
Cc: Chen-Yu Tsai &lt;wenst@chromium.org&gt;
Cc: Chunyan Zhang &lt;zhang.lyra@gmail.com&gt;
Cc: Claudiu Beznea &lt;claudiu.beznea@microchip.com&gt;
Cc: Daniel Vetter &lt;daniel@ffwll.ch&gt;
Cc: David Airlie &lt;airlied@gmail.com&gt;
Cc: David Lechner &lt;david@lechnology.com&gt;
Cc: Dinh Nguyen &lt;dinguyen@kernel.org&gt;
Cc: Fabio Estevam &lt;festevam@gmail.com&gt;
Cc: Geert Uytterhoeven &lt;geert+renesas@glider.be&gt;
Cc: Jaroslav Kysela &lt;perex@perex.cz&gt;
Cc: Jernej Skrabec &lt;jernej.skrabec@gmail.com&gt;
Cc: Jonathan Hunter &lt;jonathanh@nvidia.com&gt;
Cc: Kishon Vijay Abraham I &lt;kishon@kernel.org&gt;
Cc: Liam Girdwood &lt;lgirdwood@gmail.com&gt;
Cc: Linus Walleij &lt;linus.walleij@linaro.org&gt;
Cc: Luca Ceresoli &lt;luca.ceresoli@bootlin.com&gt;
Cc: Manivannan Sadhasivam &lt;mani@kernel.org&gt;
Cc: Mark Brown &lt;broonie@kernel.org&gt;
Cc: Markus Schneider-Pargmann &lt;msp@baylibre.com&gt;
Cc: Max Filippov &lt;jcmvbkbc@gmail.com&gt;
Cc: Maxime Coquelin &lt;mcoquelin.stm32@gmail.com&gt;
Cc: Mikko Perttunen &lt;mperttunen@nvidia.com&gt;
Cc: Miles Chen &lt;miles.chen@mediatek.com&gt;
Cc: Nicolas Ferre &lt;nicolas.ferre@microchip.com&gt;
Cc: Orson Zhai &lt;orsonzhai@gmail.com&gt;
Cc: Paul Cercueil &lt;paul@crapouillou.net&gt;
Cc: Peng Fan &lt;peng.fan@nxp.com&gt;
Cc: Peter De Schrijver &lt;pdeschrijver@nvidia.com&gt;
Cc: Prashant Gaikwad &lt;pgaikwad@nvidia.com&gt;
Cc: Richard Fitzgerald &lt;rf@opensource.cirrus.com&gt;
Cc: Samuel Holland &lt;samuel@sholland.org&gt;
Cc: Sascha Hauer &lt;s.hauer@pengutronix.de&gt;
Cc: Sekhar Nori &lt;nsekhar@ti.com&gt;
Cc: Shawn Guo &lt;shawnguo@kernel.org&gt;
Cc: Takashi Iwai &lt;tiwai@suse.com&gt;
Cc: Thierry Reding &lt;thierry.reding@gmail.com&gt;
Cc: Ulf Hansson &lt;ulf.hansson@linaro.org&gt;
Cc: Vinod Koul &lt;vkoul@kernel.org&gt;
Cc: dri-devel@lists.freedesktop.org
Cc: linux-actions@lists.infradead.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-mips@vger.kernel.org
Cc: linux-phy@lists.infradead.org
Cc: linux-renesas-soc@vger.kernel.org
Cc: linux-rtc@vger.kernel.org
Cc: linux-stm32@st-md-mailman.stormreply.com
Cc: linux-sunxi@lists.linux.dev
Cc: linux-tegra@vger.kernel.org
Cc: NXP Linux Team &lt;linux-imx@nxp.com&gt;
Cc: patches@opensource.cirrus.com
Cc: Pengutronix Kernel Team &lt;kernel@pengutronix.de&gt;
Signed-off-by: Stephen Boyd &lt;sboyd@kernel.org&gt;
Signed-off-by: Maxime Ripard &lt;maxime@cerno.tech&gt;
Link: https://lore.kernel.org/r/20221018-clk-range-checks-fixes-v4-4-971d5077e7d2@cerno.tech
| Reported-by: kernel test robot &lt;lkp@intel.com&gt;:
</content>
</entry>
<entry>
<title>clk: test: Fix type sign of rounded rate variables</title>
<updated>2023-06-09T01:01:05+00:00</updated>
<author>
<name>Maxime Ripard</name>
<email>maxime@cerno.tech</email>
</author>
<published>2023-05-05T11:25:04+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=9633b4c17b734de8308461182facc931042824b7'/>
<id>urn:sha1:9633b4c17b734de8308461182facc931042824b7</id>
<content type='text'>
clk_round_rate() may return a negative error code, but most of the
variables we defined to store its returned value are unsigned.

This obviously leads to issues on error.

Signed-off-by: Maxime Ripard &lt;maxime@cerno.tech&gt;
Link: https://lore.kernel.org/r/20221018-clk-range-checks-fixes-v4-2-971d5077e7d2@cerno.tech
Signed-off-by: Stephen Boyd &lt;sboyd@kernel.org&gt;
</content>
</entry>
<entry>
<title>clk: tests: Add tests for notifiers</title>
<updated>2022-10-11T03:37:50+00:00</updated>
<author>
<name>Maxime Ripard</name>
<email>maxime@cerno.tech</email>
</author>
<published>2022-10-10T14:47:39+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=589a2004881f0941ca46146a5de68b3666d1d54a'/>
<id>urn:sha1:589a2004881f0941ca46146a5de68b3666d1d54a</id>
<content type='text'>
We're recently encountered a regression due to the rates reported
through the clk_notifier_data being off when changing parents.

Let's add a test suite and a test to make sure that we do get notified
and with the proper rates.

Suggested-by: Stephen Boyd &lt;sboyd@kernel.org&gt;
Signed-off-by: Maxime Ripard &lt;maxime@cerno.tech&gt;
Link: https://lore.kernel.org/r/20221010-rpi-clk-fixes-again-v1-2-d87ba82ac404@cerno.tech
Tested-by: Marek Szyprowski &lt;m.szyprowski@samsung.com&gt;
Signed-off-by: Stephen Boyd &lt;sboyd@kernel.org&gt;
</content>
</entry>
<entry>
<title>clk: tests: Add missing test case for ranges</title>
<updated>2022-09-15T16:32:34+00:00</updated>
<author>
<name>Maxime Ripard</name>
<email>maxime@cerno.tech</email>
</author>
<published>2022-08-16T11:25:30+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=433fb8a611ca2a32112668225beabda2302c9634'/>
<id>urn:sha1:433fb8a611ca2a32112668225beabda2302c9634</id>
<content type='text'>
Let's add a test on the rate range after a reparenting. This fails for
now, but it's worth having it to document the corner cases we don't
support yet.

Signed-off-by: Maxime Ripard &lt;maxime@cerno.tech&gt;
Link: https://lore.kernel.org/r/20220816112530.1837489-26-maxime@cerno.tech
Tested-by: Naresh Kamboju &lt;naresh.kamboju@linaro.org&gt;
Tested-by: Linux Kernel Functional Testing &lt;lkft@linaro.org&gt;
Signed-off-by: Stephen Boyd &lt;sboyd@kernel.org&gt;
</content>
</entry>
<entry>
<title>clk: Stop forwarding clk_rate_requests to the parent</title>
<updated>2022-09-15T16:32:11+00:00</updated>
<author>
<name>Maxime Ripard</name>
<email>maxime@cerno.tech</email>
</author>
<published>2022-08-16T11:25:26+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=262ca38f4b6eb418b20b8e1d6d8495c6a98727c1'/>
<id>urn:sha1:262ca38f4b6eb418b20b8e1d6d8495c6a98727c1</id>
<content type='text'>
If the clock cannot modify its rate and has CLK_SET_RATE_PARENT,
clk_mux_determine_rate_flags(), clk_core_round_rate_nolock() and a
number of drivers will forward the clk_rate_request to the parent clock.

clk_core_round_rate_nolock() will pass the pointer directly, which means
that we pass a clk_rate_request to the parent that has the rate,
min_rate and max_rate of the child, and the best_parent_rate and
best_parent_hw fields will be relative to the child as well, so will
point to our current clock and its rate. The most common case for
CLK_SET_RATE_PARENT is that the child and parent clock rates will be
equal, so the rate field isn't a worry, but the other fields are.

Similarly, if the parent clock driver ever modifies the best_parent_rate
or best_parent_hw, this will be applied to the child once the call to
clk_core_round_rate_nolock() is done. best_parent_hw is probably not
going to be a valid parent, and best_parent_rate might lead to a parent
rate change different to the one that was initially computed.

clk_mux_determine_rate_flags() and the affected drivers will copy the
request before forwarding it to the parents, so they won't be affected
by the latter issue, but the former is still going to be there and will
lead to erroneous data and context being passed to the various clock
drivers in the same sub-tree.

Let's create two new functions, clk_core_forward_rate_req() and
clk_hw_forward_rate_request() for the framework and the clock providers
that will copy a request from a child clock and update the context to
match the parent's. We also update the relevant call sites in the
framework and drivers to use that new function.

Let's also add a test to make sure we avoid regressions there.

Tested-by: Alexander Stein &lt;alexander.stein@ew.tq-group.com&gt; # imx8mp
Tested-by: Marek Szyprowski &lt;m.szyprowski@samsung.com&gt; # exynos4210, meson g12b
Signed-off-by: Maxime Ripard &lt;maxime@cerno.tech&gt;
Link: https://lore.kernel.org/r/20220816112530.1837489-22-maxime@cerno.tech
Tested-by: Linux Kernel Functional Testing &lt;lkft@linaro.org&gt;
Tested-by: Naresh Kamboju &lt;naresh.kamboju@linaro.org&gt;
Signed-off-by: Stephen Boyd &lt;sboyd@kernel.org&gt;
</content>
</entry>
<entry>
<title>clk: Introduce clk_core_has_parent()</title>
<updated>2022-09-15T16:31:58+00:00</updated>
<author>
<name>Maxime Ripard</name>
<email>maxime@cerno.tech</email>
</author>
<published>2022-08-16T11:25:24+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=1234a2c40b8cf16041fb9acd730160e6c5b4ba13'/>
<id>urn:sha1:1234a2c40b8cf16041fb9acd730160e6c5b4ba13</id>
<content type='text'>
We will need to know if a clk_core pointer has a given parent in other
functions, so let's create a clk_core_has_parent() function that
clk_has_parent() will call into.

For good measure, let's add some unit tests as well to make sure it
works properly.

Tested-by: Alexander Stein &lt;alexander.stein@ew.tq-group.com&gt; # imx8mp
Tested-by: Marek Szyprowski &lt;m.szyprowski@samsung.com&gt; # exynos4210, meson g12b
Signed-off-by: Maxime Ripard &lt;maxime@cerno.tech&gt;
Link: https://lore.kernel.org/r/20220816112530.1837489-20-maxime@cerno.tech
Tested-by: Linux Kernel Functional Testing &lt;lkft@linaro.org&gt;
Tested-by: Naresh Kamboju &lt;naresh.kamboju@linaro.org&gt;
[sboyd@kernel.org: Move tmp declaration, fix conditional to check for
current parent]
Signed-off-by: Stephen Boyd &lt;sboyd@kernel.org&gt;
</content>
</entry>
<entry>
<title>clk: Set req_rate on reparenting</title>
<updated>2022-09-15T16:31:09+00:00</updated>
<author>
<name>Maxime Ripard</name>
<email>maxime@cerno.tech</email>
</author>
<published>2022-08-16T11:25:18+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=cb1b1dd96241f37ea41d241946d5153c48141cd5'/>
<id>urn:sha1:cb1b1dd96241f37ea41d241946d5153c48141cd5</id>
<content type='text'>
If a non-rate clock started by default with a parent that never
registered, core-&gt;req_rate will be 0. The expectation is that whenever
the parent will be registered, req_rate will be updated with the new
value that has just been computed.

However, if that clock is a mux, clk_set_parent() can also make that
clock no longer orphan. In this case however, we never update req_rate.

The natural solution to this would be to update core-&gt;rate and
core-&gt;req_rate in clk_reparent() by calling clk_recalc().

However, this doesn't work in all cases. Indeed, clk_recalc() is called
by __clk_set_parent_before(), __clk_set_parent() and
clk_core_reparent(). Both __clk_set_parent_before() and __clk_set_parent
will call clk_recalc() with the enable_lock taken through a call to
clk_enable_lock(), the underlying locking primitive being a spinlock.

clk_recalc() calls the backing driver .recalc_rate hook, and that
implementation might sleep if the underlying device uses a bus with
accesses that might sleep, such as i2c.

In such a situation, we would end up sleeping while holding a spinlock,
and thus in an atomic section.

In order to work around this, we can move the core-&gt;rate and
core-&gt;req_rate update to the clk_recalc() calling sites, after the
enable_lock has been released if it was taken.

The only situation that could still be problematic is the
clk_core_reparent() -&gt; clk_reparent() case that doesn't have any
locking. clk_core_reparent() is itself called by clk_hw_reparent(),
which is then called by 4 drivers:

  * clk-stm32mp1.c, stm32/clk-stm32-core.c and tegra/clk-tegra210-emc.c
    use it in their set_parent implementation. The set_parent hook is
    only called by __clk_set_parent() and clk_change_rate(), both of
    them calling it without the enable_lock taken.

  * clk/tegra/clk-tegra124-emc.c calls it as part of its set_rate
    implementation. set_rate is only called by clk_change_rate(), again
    without the enable_lock taken.

In both cases we can't end up in a situation where the clk_hw_reparent()
caller would hold a spinlock, so it seems like this is a good
workaround.

Let's also add some unit tests to make sure we cover the original bug.

Tested-by: Alexander Stein &lt;alexander.stein@ew.tq-group.com&gt; # imx8mp
Tested-by: Marek Szyprowski &lt;m.szyprowski@samsung.com&gt; # exynos4210, meson g12b
Signed-off-by: Maxime Ripard &lt;maxime@cerno.tech&gt;
Link: https://lore.kernel.org/r/20220816112530.1837489-14-maxime@cerno.tech
Tested-by: Linux Kernel Functional Testing &lt;lkft@linaro.org&gt;
Tested-by: Naresh Kamboju &lt;naresh.kamboju@linaro.org&gt;
Signed-off-by: Stephen Boyd &lt;sboyd@kernel.org&gt;
</content>
</entry>
<entry>
<title>clk: Take into account uncached clocks in clk_set_rate_range()</title>
<updated>2022-09-15T16:31:05+00:00</updated>
<author>
<name>Maxime Ripard</name>
<email>maxime@cerno.tech</email>
</author>
<published>2022-08-16T11:25:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=3afb07231d603d51dca6a5d5e16d9d8f422f9b5f'/>
<id>urn:sha1:3afb07231d603d51dca6a5d5e16d9d8f422f9b5f</id>
<content type='text'>
clk_set_rate_range() will use the last requested rate for the clock when
it calls into the driver set_rate hook.

However, if CLK_GET_RATE_NOCACHE is set on that clock, the last
requested rate might not be matching the current rate of the clock. In
such a case, let's read out the rate from the hardware and use that in
our set_rate instead.

Tested-by: Alexander Stein &lt;alexander.stein@ew.tq-group.com&gt; # imx8mp
Tested-by: Marek Szyprowski &lt;m.szyprowski@samsung.com&gt; # exynos4210, meson g12b
Signed-off-by: Maxime Ripard &lt;maxime@cerno.tech&gt;
Link: https://lore.kernel.org/r/20220816112530.1837489-13-maxime@cerno.tech
Tested-by: Linux Kernel Functional Testing &lt;lkft@linaro.org&gt;
Tested-by: Naresh Kamboju &lt;naresh.kamboju@linaro.org&gt;
Signed-off-by: Stephen Boyd &lt;sboyd@kernel.org&gt;
</content>
</entry>
<entry>
<title>clk: tests: Add some tests for orphan with multiple parents</title>
<updated>2022-09-15T16:31:01+00:00</updated>
<author>
<name>Maxime Ripard</name>
<email>maxime@cerno.tech</email>
</author>
<published>2022-08-16T11:25:16+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=2e9cad1abc7149c5e6aeee7e76a6c363d392da8b'/>
<id>urn:sha1:2e9cad1abc7149c5e6aeee7e76a6c363d392da8b</id>
<content type='text'>
Let's leverage the dummy mux with multiple parents we have to create a
mux whose default parent will never be registered, and thus will always
be orphan by default.

We can then create some tests to make sure that the clock API behaves
properly in such a case, and that the transition to a non-orphan clock
when we change the parent is done properly.

Tested-by: Alexander Stein &lt;alexander.stein@ew.tq-group.com&gt; # imx8mp
Tested-by: Marek Szyprowski &lt;m.szyprowski@samsung.com&gt; # exynos4210, meson g12b
Signed-off-by: Maxime Ripard &lt;maxime@cerno.tech&gt;
Link: https://lore.kernel.org/r/20220816112530.1837489-12-maxime@cerno.tech
Tested-by: Linux Kernel Functional Testing &lt;lkft@linaro.org&gt;
Tested-by: Naresh Kamboju &lt;naresh.kamboju@linaro.org&gt;
Signed-off-by: Stephen Boyd &lt;sboyd@kernel.org&gt;
</content>
</entry>
</feed>
