diff options
author | Svyatoslav Ryhel <clamor95@gmail.com> | 2024-01-10 18:09:56 +0200 |
---|---|---|
committer | Sean Anderson <seanga2@gmail.com> | 2024-01-29 22:35:34 -0500 |
commit | a8dc4965f09d28a59c156437673ddb66860c847e (patch) | |
tree | 291fa96c3ed6d8e22d0fe6df906007cd650f555d /drivers/clk | |
parent | 0bfbb830554feb32199ef143b82c7d400127b41d (diff) | |
download | u-boot-a8dc4965f09d28a59c156437673ddb66860c847e.zip u-boot-a8dc4965f09d28a59c156437673ddb66860c847e.tar.gz u-boot-a8dc4965f09d28a59c156437673ddb66860c847e.tar.bz2 |
clk: clk-gpio: add actual gated clock
Existing gpio-gate-clock driver acts like a simple GPIO switch without any
effect on gated clock. Add actual clock actions into enable/disable ops and
implement get_rate op by passing gated clock if it is enabled.
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
Reviewed-by: Sean Anderson <seanga2@gmail.com>
Link: https://lore.kernel.org/r/20240110160956.4476-2-clamor95@gmail.com
[ sorted includes ]
Signed-off-by: Sean Anderson <seanga2@gmail.com>
Diffstat (limited to 'drivers/clk')
-rw-r--r-- | drivers/clk/clk-gpio.c | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/drivers/clk/clk-gpio.c b/drivers/clk/clk-gpio.c index 26d795b..4ed1430 100644 --- a/drivers/clk/clk-gpio.c +++ b/drivers/clk/clk-gpio.c @@ -3,19 +3,23 @@ * Copyright (C) 2023 Marek Vasut <marek.vasut+renesas@mailbox.org> */ -#include <asm/gpio.h> -#include <common.h> +#include <clk.h> #include <clk-uclass.h> #include <dm.h> +#include <linux/clk-provider.h> + +#include <asm/gpio.h> struct clk_gpio_priv { - struct gpio_desc enable; + struct gpio_desc enable; /* GPIO, controlling the gate */ + struct clk *clk; /* Gated clock */ }; static int clk_gpio_enable(struct clk *clk) { struct clk_gpio_priv *priv = dev_get_priv(clk->dev); + clk_enable(priv->clk); dm_gpio_set_value(&priv->enable, 1); return 0; @@ -26,21 +30,45 @@ static int clk_gpio_disable(struct clk *clk) struct clk_gpio_priv *priv = dev_get_priv(clk->dev); dm_gpio_set_value(&priv->enable, 0); + clk_disable(priv->clk); return 0; } +static ulong clk_gpio_get_rate(struct clk *clk) +{ + struct clk_gpio_priv *priv = dev_get_priv(clk->dev); + + return clk_get_rate(priv->clk); +} + const struct clk_ops clk_gpio_ops = { .enable = clk_gpio_enable, .disable = clk_gpio_disable, + .get_rate = clk_gpio_get_rate, }; static int clk_gpio_probe(struct udevice *dev) { struct clk_gpio_priv *priv = dev_get_priv(dev); + int ret; + + priv->clk = devm_clk_get(dev, NULL); + if (IS_ERR(priv->clk)) { + log_debug("%s: Could not get gated clock: %ld\n", + __func__, PTR_ERR(priv->clk)); + return PTR_ERR(priv->clk); + } - return gpio_request_by_name(dev, "enable-gpios", 0, - &priv->enable, GPIOD_IS_OUT); + ret = gpio_request_by_name(dev, "enable-gpios", 0, + &priv->enable, GPIOD_IS_OUT); + if (ret) { + log_debug("%s: Could not decode enable-gpios (%d)\n", + __func__, ret); + return ret; + } + + return 0; } /* |