Re: [PATCH v9 2/2] clk: Add gpio-enabled clock driver

From: Vyacheslav Yurkov

Date: Sat Nov 21 2026 - 06:55:00 EST


On 20.11.2026 17:07, Jerome Brunet wrote:

This comment has been carried since v5, where the reasoning was already
answered: returning an error from .prepare()/.enable() when the clock isn't
running is simply how a provider reports failure, not a workaround for the
framework. The claim is also wrong: the framework does call .is_prepared()
(clk_unprepare_unused_subtree(), clk_hw_is_prepared()). The rest describes return
conventions. Something like this would be enough:

/* The clock cannot be turned on, only waited for. */


Perhaps the claim is not clear enough then, the .is_prepared() is not called _before_ prepare. I didn't mean it's not called at all.

+static int clk_gpio_enabled_enable(struct clk_hw *hw)
+{
+ struct clk_gpio_enabled *clk = to_clk_gpio_enabled(hw);
+ int value = 0;
+
+ readx_poll_timeout_atomic(gpiod_get_value, clk->gpiod, value,
+ value != 0, 10, clk->timeout_us);

Same error handling as in the prepare variant above.

Also looking at it more closely, the binding allow 1ms max. It is lot of
time holding a spinlock without IRQ. If you don't stricly need this variant
please drop it for now.


+
+ device_property_read_u32(dev, "poll-timeout-us", &timeout_us);
+ if (timeout_us < GPIO_ENABLED_TIMEOUT_MIN ||
+ timeout_us > GPIO_ENABLED_TIMEOUT_MAX)
+ return dev_err_probe(dev, -EINVAL,
+ "poll-timeout-us is out of range [%u, %u]\n",
+ GPIO_ENABLED_TIMEOUT_MIN,
+ GPIO_ENABLED_TIMEOUT_MAX);
+ clk->timeout_us = timeout_us;
+
+ if (gpiod_cansleep(clk->gpiod))
+ ops = &clk_gpio_enabled_sleeping_ops;
+ else
+ ops = &clk_gpio_enabled_ops;

As I noted above, I prefer if you dropped the enabled variant that run with
irq off, unless you scrictly need it. Return -ENOTSUPP if the gpio can't sleep.

I would rather keep only 1 variant in general, because my GPIO controller can't sleep, but gpiod_get_value_cansleep works for both type of controllers.

Slava