Skip to contentSkip to conversation

Fix clk-gpio driver

PATCH Applied Svyatoslav Ryhel 2 participants 4 messages Jan 10, 2024 – Jan 30, 2024 Common clk

lore
Share & tools
lore
#0 lore raw

v3 cover Fix clk-gpio driver

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.

Testing current driver implementation shows that it is not fully capable and lacks gated clock manipulations.

---
Changes from v2
- restored probe

Changes from v1
- added comments for priv struct members
- return gatet clock rate unconditionally
- switch log_err > log_debug on of_to_plat
---

Svyatoslav Ryhel (1):
clk: clk-gpio: add actual gated clock

 drivers/clk/clk-gpio.c | 40 ++++++++++++++++++++++++++++++++++------
 1 file changed, 34 insertions(+), 6 deletions(-)
Signature · 1 line
2.40.1
#1 lore raw

PATCH v3 1/1 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.

---
 drivers/clk/clk-gpio.c | 40 ++++++++++++++++++++++++++++++++++------
 1 file changed, 34 insertions(+), 6 deletions(-)
drivers/clk/clk-gpio.c +34 -6
index 26d795b978..d2dd8070fa 100644
@@ -3,19 +3,23 @@
  * Copyright (C) 2023 Marek Vasut <[email protected]>
  */
 
-#include <asm/gpio.h>
-#include <common.h>
-#include <clk-uclass.h>
+#include <clk.h>
 #include <dm.h>
+#include <clk-uclass.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;
 
-	return gpio_request_by_name(dev, "enable-gpios", 0,
-				    &priv->enable, GPIOD_IS_OUT);
+	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);
+	}
+
+	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;
 }
 
 /*
Signature · 1 line
2.40.1
Reviewed-by on v3 1/1
#2 lore raw

Re: [PATCH v3 1/1] clk: clk-gpio: add actual gated clock

Quoted 14 lines · Svyatoslav Ryhel

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.

---
  drivers/clk/clk-gpio.c | 40 ++++++++++++++++++++++++++++++++++------
  1 file changed, 34 insertions(+), 6 deletions(-)
drivers/clk/clk-gpio.c +0 -0
index 26d795b978..d2dd8070fa 100644

drivers/clk/clk-gpio.c line 8

Quoted 9 lines
drivers/clk/clk-gpio.c +2 -3
@@ -3,19 +3,23 @@
   * Copyright (C) 2023 Marek Vasut <[email protected]>
   */
 
-#include <asm/gpio.h>
-#include <common.h>
-#include <clk-uclass.h>
+#include <clk.h>
  #include <dm.h>
+#include <clk-uclass.h>

this is out of order, but I will fix it when applying

Quoted 56 lines
drivers/clk/clk-gpio.c +25 -3
+#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;
 
-	return gpio_request_by_name(dev, "enable-gpios", 0,
-				    &priv->enable, GPIOD_IS_OUT);
+	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);
+	}
+
+	ret = gpio_request_by_name(dev, "enable-gpios", 0,
+				   &priv->enable, GPIOD_IS_OUT);

drivers/clk/clk-gpio.c static int clk_gpio_disable(struct clk *clk) · line 74

Quoted 10 lines
drivers/clk/clk-gpio.c +7 -0
+	if (ret) {
+		log_debug("%s: Could not decode enable-gpios (%d)\n",
+			  __func__, ret);
+		return ret;
+	}
+
+	return 0;
  }
 
  /*
#3 lore raw
In reply to Svyatoslav Ryhel
Quoted 8 lines · Svyatoslav Ryhel

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.

Testing current driver implementation shows that it is not fully capable and lacks gated clock manipulations.

[...]

Applied, thanks!

[1/1] clk: clk-gpio: add actual gated clock

      https://source.denx.de/u-boot/custodians/u-boot-clk/-/commit/a8dc4965f09d

Best regards,

Signature · 1 line
Sean Anderson <[email protected]>