[PATCH v4 68/68] clk: Forbid to register a mux without determine_rate

Maxime Ripard maxime at cerno.tech
Fri May 5 11:26:10 UTC 2023


The determine_rate hook allows to select the proper parent and its rate
for a given clock configuration. On another hand, set_parent is there to
change the parent of a mux.

Some clocks provide a set_parent hook but don't implement
determine_rate. In such a case, set_parent is pretty much useless since
the clock framework will always assume the current parent is to be used,
and we will thus never change it.

This situation can be solved in two ways:
  - either we don't need to change the parent, and we thus shouldn't
    implement set_parent;
  - or we don't want to change the parent, in this case we should set
    CLK_SET_RATE_NO_REPARENT;
  - or we're missing a determine_rate implementation.

The latter is probably just an oversight from the driver's author, and
we should thus raise their awareness about the fact that the current
state of the driver is confusing.

All the drivers in-tree have been converted by now, so let's prevent any
clock with set_parent but without determine_rate to register so that it
can't sneak in again in the future.

Cc: Abel Vesa <abelvesa at kernel.org>
Cc: Alessandro Zummo <a.zummo at towertech.it>
Cc: Alexandre Belloni <alexandre.belloni at bootlin.com>
Cc: Alexandre Torgue <alexandre.torgue at foss.st.com>
Cc: "Andreas Färber" <afaerber at suse.de>
Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno at collabora.com>
Cc: Baolin Wang <baolin.wang at linux.alibaba.com>
Cc: Charles Keepax <ckeepax at opensource.cirrus.com>
Cc: Chen-Yu Tsai <wens at csie.org>
Cc: Chen-Yu Tsai <wenst at chromium.org>
Cc: Chunyan Zhang <zhang.lyra at gmail.com>
Cc: Claudiu Beznea <claudiu.beznea at microchip.com>
Cc: Daniel Vetter <daniel at ffwll.ch>
Cc: David Airlie <airlied at gmail.com>
Cc: David Lechner <david at lechnology.com>
Cc: Dinh Nguyen <dinguyen at kernel.org>
Cc: Fabio Estevam <festevam at gmail.com>
Cc: Geert Uytterhoeven <geert+renesas at glider.be>
Cc: Jaroslav Kysela <perex at perex.cz>
Cc: Jernej Skrabec <jernej.skrabec at gmail.com>
Cc: Jonathan Hunter <jonathanh at nvidia.com>
Cc: Kishon Vijay Abraham I <kishon at kernel.org>
Cc: Liam Girdwood <lgirdwood at gmail.com>
Cc: Linus Walleij <linus.walleij at linaro.org>
Cc: Luca Ceresoli <luca.ceresoli at bootlin.com>
Cc: Manivannan Sadhasivam <mani at kernel.org>
Cc: Mark Brown <broonie at kernel.org>
Cc: Markus Schneider-Pargmann <msp at baylibre.com>
Cc: Max Filippov <jcmvbkbc at gmail.com>
Cc: Maxime Coquelin <mcoquelin.stm32 at gmail.com>
Cc: Mikko Perttunen <mperttunen at nvidia.com>
Cc: Miles Chen <miles.chen at mediatek.com>
Cc: Nicolas Ferre <nicolas.ferre at microchip.com>
Cc: Orson Zhai <orsonzhai at gmail.com>
Cc: Paul Cercueil <paul at crapouillou.net>
Cc: Peng Fan <peng.fan at nxp.com>
Cc: Peter De Schrijver <pdeschrijver at nvidia.com>
Cc: Prashant Gaikwad <pgaikwad at nvidia.com>
Cc: Richard Fitzgerald <rf at opensource.cirrus.com>
Cc: Samuel Holland <samuel at sholland.org>
Cc: Sascha Hauer <s.hauer at pengutronix.de>
Cc: Sekhar Nori <nsekhar at ti.com>
Cc: Shawn Guo <shawnguo at kernel.org>
Cc: Takashi Iwai <tiwai at suse.com>
Cc: Thierry Reding <thierry.reding at gmail.com>
Cc: Ulf Hansson <ulf.hansson at linaro.org>
Cc: Vinod Koul <vkoul at kernel.org>
Cc: dri-devel at lists.freedesktop.org
Cc: linux-actions at lists.infradead.org
Cc: linux-arm-kernel at lists.infradead.org
Cc: linux-mips at vger.kernel.org
Cc: linux-phy at lists.infradead.org
Cc: linux-renesas-soc at vger.kernel.org
Cc: linux-rtc at vger.kernel.org
Cc: linux-stm32 at st-md-mailman.stormreply.com
Cc: linux-sunxi at lists.linux.dev
Cc: linux-tegra at vger.kernel.org
Cc: NXP Linux Team <linux-imx at nxp.com>
Cc: patches at opensource.cirrus.com
Cc: Pengutronix Kernel Team <kernel at pengutronix.de>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno at collabora.com>
Signed-off-by: Maxime Ripard <maxime at cerno.tech>
---
 drivers/clk/clk.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index e4a1d5f9694c..c8f9227c29c9 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -3775,6 +3775,13 @@ static int __clk_core_init(struct clk_core *core)
 		goto out;
 	}
 
+	if (core->ops->set_parent && !core->ops->determine_rate) {
+		pr_err("%s: %s must implement .set_parent & .determine_rate\n",
+			__func__, core->name);
+		ret = -EINVAL;
+		goto out;
+	}
+
 	if (core->num_parents > 1 && !core->ops->get_parent) {
 		pr_err("%s: %s must implement .get_parent as it has multi parents\n",
 		       __func__, core->name);

-- 
2.40.0



More information about the dri-devel mailing list