* [PATCH v12 1/2] dt-bindings: clock: Add gpio-enabled-clock
2026-11-30 8:15 [PATCH v12 0/2] A proposal to add a gpio-enabled clock driver Vyacheslav Yurkov via B4 Relay
@ 2026-11-30 8:15 ` Vyacheslav Yurkov via B4 Relay
2026-11-30 8:25 ` sashiko-bot
2026-11-30 8:15 ` [PATCH v12 2/2] clk: gpio: Add driver for GPIO-signalled clocks Vyacheslav Yurkov via B4 Relay
2026-11-30 9:41 ` [PATCH v12 0/2] A proposal to add a gpio-enabled clock driver Jerome Brunet
2 siblings, 1 reply; 6+ messages in thread
From: Vyacheslav Yurkov via B4 Relay @ 2026-11-30 8:15 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Brian Masney, Brian Masney, Jerome Brunet,
Jyri Sarha
Cc: linux-kernel, linux-clk, devicetree, Vyacheslav Yurkov,
Vyacheslav Yurkov
From: Vyacheslav Yurkov <V.Yurkov.EXT@bruker.com>
Some clocks are switched on and off by hardware outside software
control, which reports through a GPIO whether the clock is currently
running. Software cannot enable such a clock, but its consumers must
not use it before the GPIO indicates that it is running.
Add a binding for a clock that passes its parent clock through
unchanged and is considered enabled only while a GPIO signal is
asserted. The parent clock determines the rate. The status GPIO is
given by enabled-gpios, and poll-timeout-us bounds how long a consumer
waits for the clock to become available.
Signed-off-by: Vyacheslav Yurkov <V.Yurkov.EXT@bruker.com>
---
Our use case: peripheral clocks generated by FPGA PLLs, with the
PLL-lock signals routed to GPIOs of the SoC.
---
.../bindings/clock/gpio-enabled-clock.yaml | 53 ++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/Documentation/devicetree/bindings/clock/gpio-enabled-clock.yaml b/Documentation/devicetree/bindings/clock/gpio-enabled-clock.yaml
new file mode 100644
index 000000000000..0eb028130929
--- /dev/null
+++ b/Documentation/devicetree/bindings/clock/gpio-enabled-clock.yaml
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/clock/gpio-enabled-clock.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: GPIO Enabled Clock
+
+maintainers:
+ - Vyacheslav Yurkov <V.Yurkov.EXT@bruker.com>
+
+properties:
+ compatible:
+ const: gpio-enabled-clock
+
+ clocks:
+ maxItems: 1
+
+ "#clock-cells":
+ const: 0
+
+ clock-output-names:
+ maxItems: 1
+
+ enabled-gpios:
+ description: GPIO that indicates whether the clock is enabled or disabled.
+ maxItems: 1
+
+ poll-timeout-us:
+ description: Maximum time to wait for the enabled GPIO to be asserted.
+
+required:
+ - compatible
+ - "#clock-cells"
+ - clocks
+ - clock-output-names
+ - enabled-gpios
+ - poll-timeout-us
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/gpio/gpio.h>
+
+ clock {
+ compatible = "gpio-enabled-clock";
+ #clock-cells = <0>;
+ clocks = <&pll>;
+ clock-output-names = "gpio-enabled-clock";
+ enabled-gpios = <&gpio0 4 GPIO_ACTIVE_HIGH>;
+ poll-timeout-us = <20>;
+ };
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v12 2/2] clk: gpio: Add driver for GPIO-signalled clocks
2026-11-30 8:15 [PATCH v12 0/2] A proposal to add a gpio-enabled clock driver Vyacheslav Yurkov via B4 Relay
2026-11-30 8:15 ` [PATCH v12 1/2] dt-bindings: clock: Add gpio-enabled-clock Vyacheslav Yurkov via B4 Relay
@ 2026-11-30 8:15 ` Vyacheslav Yurkov via B4 Relay
2026-11-30 9:41 ` [PATCH v12 0/2] A proposal to add a gpio-enabled clock driver Jerome Brunet
2 siblings, 0 replies; 6+ messages in thread
From: Vyacheslav Yurkov via B4 Relay @ 2026-11-30 8:15 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Brian Masney, Brian Masney, Jerome Brunet,
Jyri Sarha
Cc: linux-kernel, linux-clk, devicetree, Vyacheslav Yurkov,
Vyacheslav Yurkov
From: Vyacheslav Yurkov <V.Yurkov.EXT@bruker.com>
Some clocks are not under CPU control: they are generated and enabled
by external hardware, which only reports through a GPIO whether the
clock is running. There is currently no way to describe such a clock,
so consumers either initialize too early or rely on ad-hoc delays.
Add a "gpio-enabled-clock" provider for this case. Its prepare
callback polls the GPIO until it is asserted or a timeout expires, so
a consumer's clk_prepare_enable() succeeds only once the clock is
actually running, and fails otherwise. is_prepared reports the
current state of the GPIO.
Signed-off-by: Vyacheslav Yurkov <V.Yurkov.EXT@bruker.com>
---
Our use case: peripheral clocks generated by FPGA PLLs, with the
PLL-lock signals routed to GPIOs of the SoC.
---
drivers/clk/clk-gpio.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 99 insertions(+)
diff --git a/drivers/clk/clk-gpio.c b/drivers/clk/clk-gpio.c
index df0856a39c8d..6ed2b1890c9a 100644
--- a/drivers/clk/clk-gpio.c
+++ b/drivers/clk/clk-gpio.c
@@ -15,6 +15,7 @@
#include <linux/gpio/consumer.h>
#include <linux/err.h>
#include <linux/device.h>
+#include <linux/iopoll.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/regulator/consumer.h>
@@ -241,6 +242,104 @@ static struct platform_driver gpio_clk_driver = {
};
builtin_platform_driver(gpio_clk_driver);
+/**
+ * struct clk_gpio_enabled - gpio enabled clock
+ *
+ * @hw: handle between common and hardware-specific interfaces
+ * @gpiod: gpio descriptor
+ * @timeout_us: timeout that is used to get a GPIO value
+ *
+ * Clock whose status is determined by a GPIO signal.
+ *
+ * Implements .prepare and .is_prepared
+ */
+struct clk_gpio_enabled {
+ struct clk_hw hw;
+ struct gpio_desc *gpiod;
+ u32 timeout_us;
+};
+
+#define to_clk_gpio_enabled(_hw) container_of(_hw, struct clk_gpio_enabled, hw)
+
+static int clk_gpio_enabled_is_prepared(struct clk_hw *hw)
+{
+ struct clk_gpio_enabled *clk = to_clk_gpio_enabled(hw);
+
+ return gpiod_get_value_cansleep(clk->gpiod) > 0;
+}
+
+/* The clock cannot be turned on, only waited for. */
+static int clk_gpio_enabled_prepare(struct clk_hw *hw)
+{
+ struct clk_gpio_enabled *clk = to_clk_gpio_enabled(hw);
+ int value, ret;
+
+ ret = readx_poll_timeout(gpiod_get_value_cansleep, clk->gpiod, value,
+ value != 0, max(clk->timeout_us / 10, 10U),
+ clk->timeout_us);
+ if (ret)
+ return ret;
+
+ return value < 0 ? value : 0;
+}
+
+static const struct clk_ops clk_gpio_enabled_ops = {
+ .prepare = clk_gpio_enabled_prepare,
+ .is_prepared = clk_gpio_enabled_is_prepared,
+};
+
+static int gpio_enabled_clk_driver_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct clk_gpio_enabled *clk;
+ const char *clk_name;
+ const struct clk_parent_data gpio_parent_data[] = {
+ { .index = 0 },
+ };
+ int ret;
+
+ clk = devm_kzalloc_obj(dev, *clk);
+ if (!clk)
+ return -ENOMEM;
+
+ clk->gpiod = devm_gpiod_get(dev, "enabled", GPIOD_IN);
+ if (IS_ERR(clk->gpiod))
+ return dev_err_probe(dev, PTR_ERR(clk->gpiod),
+ "can't get enabled GPIO property\n");
+
+ ret = device_property_read_string(dev, "clock-output-names", &clk_name);
+ if (ret)
+ return dev_err_probe(dev, ret, "missing clock-output-names\n");
+
+ ret = device_property_read_u32(dev, "poll-timeout-us", &clk->timeout_us);
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to read poll-timeout-us\n");
+
+ clk->hw.init = CLK_HW_INIT_PARENTS_DATA(clk_name, gpio_parent_data,
+ &clk_gpio_enabled_ops, CLK_SET_RATE_PARENT);
+
+ ret = devm_clk_hw_register(dev, &clk->hw);
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "failed to register clock\n");
+
+ return devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, &clk->hw);
+}
+
+static const struct of_device_id gpio_enabled_clk_match_table[] = {
+ { .compatible = "gpio-enabled-clock" },
+ { }
+};
+
+static struct platform_driver gpio_enabled_clk_driver = {
+ .probe = gpio_enabled_clk_driver_probe,
+ .driver = {
+ .name = "gpio-enabled-clk",
+ .of_match_table = gpio_enabled_clk_match_table,
+ },
+};
+builtin_platform_driver(gpio_enabled_clk_driver);
+
/**
* DOC: gated fixed clock, controlled with a gpio output and a regulator
* Traits of this clock:
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v12 0/2] A proposal to add a gpio-enabled clock driver.
2026-11-30 8:15 [PATCH v12 0/2] A proposal to add a gpio-enabled clock driver Vyacheslav Yurkov via B4 Relay
2026-11-30 8:15 ` [PATCH v12 1/2] dt-bindings: clock: Add gpio-enabled-clock Vyacheslav Yurkov via B4 Relay
2026-11-30 8:15 ` [PATCH v12 2/2] clk: gpio: Add driver for GPIO-signalled clocks Vyacheslav Yurkov via B4 Relay
@ 2026-11-30 9:41 ` Jerome Brunet
2026-11-30 9:49 ` Vyacheslav Yurkov
2 siblings, 1 reply; 6+ messages in thread
From: Jerome Brunet @ 2026-11-30 9:41 UTC (permalink / raw)
To: Vyacheslav Yurkov
Cc: Michael Turquette, Stephen Boyd, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Brian Masney, Brian Masney, Jerome Brunet,
Jyri Sarha, linux-kernel, linux-clk, devicetree,
Vyacheslav Yurkov, Jerome Brunet
> A gpio-enabled clock represents an input clock, which state is determined
> by a GPIO signal. It's similar to a gated-fixed-clock, but GPIO direction
> is inverted. Consumers can use the output clock to wait until the clock
> is ready and only then initialize / access dependent peripherals.
>
> The usage example for such a driver is when peripherals depend on PLLs in
> a FPGA, which can't be directly accessed by the CPU, but need a GPIO pin
> to check whether clock is actually usable. E.g. some of the IPs might not
> have a proper split between registers and IP core, which means that if an
> external clock and/or PLL lock is missing and one tries to access the
> registers, the response never comes, thus the CPU stalls.
>
> Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
> Signed-off-by: Vyacheslav Yurkov <V.Yurkov.EXT@bruker.com>
> ---
> Changes in v12:
> - Use new devm_kzalloc_obj() API
> - Make poll-timeout-us mandatory, use polling inteval as a max of 1/10 of
> the specified timeout or 10us.
What is the reason for this change ?
> - Remove range check from the driver
> - Link to v11: https://lore.kernel.org/r/20261121-feature-clock-guard-v11-0-00c633a667a2@bruker.com
>
I had also asked to wait for the DT guys review before reposting
--
Jerome
^ permalink raw reply [flat|nested] 6+ messages in thread