Skip to contentSkip to conversation

Fix clk-gpio driver

PATCH Superseded Svyatoslav Ryhel 3 participants 16 messages Dec 16, 2023 – Jan 10, 2024 Common clk

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 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 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 | 44 ++++++++++++++++++++++++++++++++++--------
 1 file changed, 36 insertions(+), 8 deletions(-)
Signature · 1 line
2.40.1
#1 lore raw

PATCH v2 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 | 44 ++++++++++++++++++++++++++++++++++--------
 1 file changed, 36 insertions(+), 8 deletions(-)
drivers/clk/clk-gpio.c +36 -8
index 26d795b978..72d9747a47 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)
+static int clk_gpio_of_to_plat(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;
 }
 
 /*
@@ -59,7 +87,7 @@ U_BOOT_DRIVER(gpio_gate_clock) = {
 	.name		= "gpio_clock",
 	.id		= UCLASS_CLK,
 	.of_match	= clk_gpio_match,
-	.probe		= clk_gpio_probe,
+	.of_to_plat	= clk_gpio_of_to_plat,
 	.priv_auto	= sizeof(struct clk_gpio_priv),
 	.ops		= &clk_gpio_ops,
 	.flags		= DM_FLAG_PRE_RELOC,
Signature · 1 line
2.40.1
#2 lore raw

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

Quoted 91 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 | 44 ++++++++++++++++++++++++++++++++++--------
  1 file changed, 36 insertions(+), 8 deletions(-)
drivers/clk/clk-gpio.c +35 -7
index 26d795b978..72d9747a47 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)
+static int clk_gpio_of_to_plat(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;
  }
 
  /*

drivers/clk/clk-gpio.c U_BOOT_DRIVER(gpio_gate_clock) = { · line 93

Quoted 8 lines
drivers/clk/clk-gpio.c +1 -1
@@ -59,7 +87,7 @@ U_BOOT_DRIVER(gpio_gate_clock) = {
  	.name		= "gpio_clock",
  	.id		= UCLASS_CLK,
  	.of_match	= clk_gpio_match,
-	.probe		= clk_gpio_probe,
+	.of_to_plat	= clk_gpio_of_to_plat,
  	.priv_auto	= sizeof(struct clk_gpio_priv),
  	.ops		= &clk_gpio_ops,
  	.flags		= DM_FLAG_PRE_RELOC,

+CC Marek

#3 lore raw

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

Quoted 70 lines · Sean Anderson
Quoted 69 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 | 44 ++++++++++++++++++++++++++++++++++--------

  1 file changed, 36 insertions(+), 8 deletions(-)
drivers/clk/clk-gpio.c +27 -7
index 26d795b978..72d9747a47 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)
+static int clk_gpio_of_to_plat(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,
Quoted 8 lines

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

Quoted 8 lines
drivers/clk/clk-gpio.c +8 -0
+                   &priv->enable, GPIOD_IS_OUT);
+    if (ret) {
+        log_debug("%s: Could not decode enable-gpios (%d)\n",
+              __func__, ret);
+        return ret;
+    }
+
+    return 0;

All this forwarding of clock enable/disable/get_rate for parent clock should already be done in clock core. If it is not, then it should be fixed in clock core.

#4 lore raw

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

сб, 16 груд. 2023 р. о 18:52 Marek Vasut <[email protected]> пише:

Quoted 78 lines · Sean Anderson
Quoted 76 lines · Svyatoslav Ryhel
Quoted 75 lines

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 | 44 ++++++++++++++++++++++++++++++++++--------
  1 file changed, 36 insertions(+), 8 deletions(-)
drivers/clk/clk-gpio.c +31 -7
index 26d795b978..72d9747a47 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)
+static int clk_gpio_of_to_plat(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);
Quoted 8 lines
Quoted 4 lines

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

Quoted 4 lines
drivers/clk/clk-gpio.c +4 -0
+        return ret;
+    }
+
+    return 0;

All this forwarding of clock enable/disable/get_rate for parent clock should already be done in clock core. If it is not, then it should be fixed in clock core.

It is not and this driver, as is, did not work on tegra since you messed up headers.

#5 lore raw

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

Quoted 88 lines · Svyatoslav Ryhel

сб, 16 груд. 2023 р. о 18:52 Marek Vasut <[email protected]> пише:

Quoted 78 lines · Sean Anderson
Quoted 76 lines · Svyatoslav Ryhel
Quoted 75 lines

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 | 44 ++++++++++++++++++++++++++++++++++--------
   1 file changed, 36 insertions(+), 8 deletions(-)
drivers/clk/clk-gpio.c +31 -7
index 26d795b978..72d9747a47 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)
+static int clk_gpio_of_to_plat(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);
Quoted 8 lines
Quoted 4 lines

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

Quoted 4 lines
drivers/clk/clk-gpio.c +4 -0
+        return ret;
+    }
+
+    return 0;

All this forwarding of clock enable/disable/get_rate for parent clock should already be done in clock core. If it is not, then it should be fixed in clock core.

Quoted 2 lines

It is not and this driver, as is, did not work on tegra since you messed up headers.

This is not constructive feedback. Skip the assignment of blame and instead explain what the problem with headers is, that is the relevant part and that is missing here.

#6 lore raw

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

In reply to Marek Vasut
Quoted 73 lines · Marek Vasut
Quoted 72 lines · Sean Anderson
Quoted 71 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 | 44 ++++++++++++++++++++++++++++++++++--------

  1 file changed, 36 insertions(+), 8 deletions(-)
drivers/clk/clk-gpio.c +29 -7
index 26d795b978..72d9747a47 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)
+static int clk_gpio_of_to_plat(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) {
Quoted 8 lines
Quoted 6 lines

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

Quoted 6 lines
drivers/clk/clk-gpio.c +6 -0
+        log_debug("%s: Could not decode enable-gpios (%d)\n",
+              __func__, ret);
+        return ret;
+    }
+
+    return 0;

All this forwarding of clock enable/disable/get_rate for parent clock should already be done in clock core. If it is not, then it should be fixed in clock core.

Only CCF forwards things. It's up to the driver to do it in the non-CCF case.

--Sean

#7 lore raw

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

Quoted 84 lines · Sean Anderson
Quoted 74 lines · Marek Vasut
Quoted 73 lines · Sean Anderson
Quoted 72 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 | 44
++++++++++++++++++++++++++++++++++--------

  1 file changed, 36 insertions(+), 8 deletions(-)
drivers/clk/clk-gpio.c +29 -7
index 26d795b978..72d9747a47 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)
+static int clk_gpio_of_to_plat(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) {
Quoted 8 lines
Quoted 6 lines

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

Quoted 6 lines
drivers/clk/clk-gpio.c +6 -0
+        log_debug("%s: Could not decode enable-gpios (%d)\n",
+              __func__, ret);
+        return ret;
+    }
+
+    return 0;

All this forwarding of clock enable/disable/get_rate for parent clock should already be done in clock core. If it is not, then it should be fixed in clock core.

Quoted 1 line

Only CCF forwards things. It's up to the driver to do it in the non-CCF case.

Shall we add dependency on CCF instead of duplicating code in drivers ?

#8 lore raw

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

Quoted 84 lines · Marek Vasut
Quoted 83 lines · Sean Anderson
Quoted 81 lines · Marek Vasut
Quoted 70 lines · Sean Anderson
Quoted 69 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 | 44 ++++++++++++++++++++++++++++++++++--------

  1 file changed, 36 insertions(+), 8 deletions(-)
drivers/clk/clk-gpio.c +27 -7
index 26d795b978..72d9747a47 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)
+static int clk_gpio_of_to_plat(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,
Quoted 8 lines

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

Quoted 8 lines
drivers/clk/clk-gpio.c +8 -0
+                   &priv->enable, GPIOD_IS_OUT);
+    if (ret) {
+        log_debug("%s: Could not decode enable-gpios (%d)\n",
+              __func__, ret);
+        return ret;
+    }
+
+    return 0;

All this forwarding of clock enable/disable/get_rate for parent clock should already be done in clock core. If it is not, then it should be fixed in clock core.

Quoted 3 lines
Quoted 1 line

Only CCF forwards things. It's up to the driver to do it in the non-CCF case.

Shall we add dependency on CCF instead of duplicating code in drivers ?

I'd rather not. This will be useful on non-CCF systems.

--Sean

#9 lore raw

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

Quoted 86 lines · Sean Anderson
Quoted 85 lines · Marek Vasut
Quoted 84 lines · Sean Anderson
Quoted 82 lines · Marek Vasut
Quoted 71 lines · Sean Anderson
Quoted 70 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 | 44
++++++++++++++++++++++++++++++++++--------

  1 file changed, 36 insertions(+), 8 deletions(-)
drivers/clk/clk-gpio.c +27 -7
index 26d795b978..72d9747a47 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)
+static int clk_gpio_of_to_plat(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,
Quoted 8 lines

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

Quoted 8 lines
drivers/clk/clk-gpio.c +8 -0
+                   &priv->enable, GPIOD_IS_OUT);
+    if (ret) {
+        log_debug("%s: Could not decode enable-gpios (%d)\n",
+              __func__, ret);
+        return ret;
+    }
+
+    return 0;

All this forwarding of clock enable/disable/get_rate for parent clock should already be done in clock core. If it is not, then it should be fixed in clock core.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Only CCF forwards things. It's up to the driver to do it in the non-CCF case.

Shall we add dependency on CCF instead of duplicating code in drivers ?

I'd rather not. This will be useful on non-CCF systems.

Then the forwarding functionality should be in the clock core, basically if a driver does not implement callback <something>, call parent clock callback <something>, and repeat until you reach the top of the clock tree. If you do reach the top, fail with some error code. Isn't that how clock enable already works anyway ?

#10 lore raw

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

Quoted 86 lines · Marek Vasut
Quoted 85 lines · Sean Anderson
Quoted 84 lines · Marek Vasut
Quoted 83 lines · Sean Anderson
Quoted 81 lines · Marek Vasut
Quoted 70 lines · Sean Anderson
Quoted 69 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 | 44 ++++++++++++++++++++++++++++++++++--------

  1 file changed, 36 insertions(+), 8 deletions(-)
drivers/clk/clk-gpio.c +27 -7
index 26d795b978..72d9747a47 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)
+static int clk_gpio_of_to_plat(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,
Quoted 8 lines

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

Quoted 8 lines
drivers/clk/clk-gpio.c +8 -0
+                   &priv->enable, GPIOD_IS_OUT);
+    if (ret) {
+        log_debug("%s: Could not decode enable-gpios (%d)\n",
+              __func__, ret);
+        return ret;
+    }
+
+    return 0;

All this forwarding of clock enable/disable/get_rate for parent clock should already be done in clock core. If it is not, then it should be fixed in clock core.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Only CCF forwards things. It's up to the driver to do it in the non-CCF case.

Shall we add dependency on CCF instead of duplicating code in drivers ?

I'd rather not. This will be useful on non-CCF systems.

Then the forwarding functionality should be in the clock core, basically if a driver does not implement callback <something>, call parent clock callback <something>, and repeat until you reach the top of the clock tree. If you do reach the top, fail with some error code. Isn't that how clock enable already works anyway ?

No. In the non-CCF case, we have no idea what the parent of any given clock is. So there's no framework we can provide.

Now, you might say "why not add a get_parent op?" Well, that will work fine for enabling things, but it is a bit hairy on the disable side. You really need to have refcounting to protect parent clocks (which can have many children). But we don't really have anywhere to store refcounts. struct clk has a member for it, but that's only because it's abused as private data by CCF. Non-CCF clocks have no clock subsystem data allocated at all. Another alternative is to just only disable the leaf node, which is what we currently do. That's OK I think.

But that solution requires some more-intensive effort which I don't want to impose on random contributors. So for the time being, all non-CCF clock drivers must handle enabling their own parent clocks.

--Sean

#11 lore raw

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

Quoted 91 lines · Sean Anderson
Quoted 90 lines · Marek Vasut
Quoted 89 lines · Sean Anderson
Quoted 88 lines · Marek Vasut
Quoted 86 lines · Sean Anderson
Quoted 75 lines · Marek Vasut
Quoted 74 lines · Sean Anderson
Quoted 73 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 | 44
++++++++++++++++++++++++++++++++++--------

  1 file changed, 36 insertions(+), 8 deletions(-)
drivers/clk/clk-gpio.c +6 -4
index 26d795b978..72d9747a47 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;

drivers/clk/clk-gpio.c +21 -3
@@ -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)
+static int clk_gpio_of_to_plat(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) {
Quoted 8 lines
Quoted 6 lines

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

Quoted 6 lines
drivers/clk/clk-gpio.c +6 -0
+        log_debug("%s: Could not decode enable-gpios (%d)\n",
+              __func__, ret);
+        return ret;
+    }
+
+    return 0;

All this forwarding of clock enable/disable/get_rate for parent clock should already be done in clock core. If it is not, then it should be fixed in clock core.

Only CCF forwards things. It's up to the driver to do it in the non-CCF case.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Shall we add dependency on CCF instead of duplicating code in drivers ?

I'd rather not. This will be useful on non-CCF systems.

Then the forwarding functionality should be in the clock core, basically if a driver does not implement callback <something>, call parent clock callback <something>, and repeat until you reach the top of the clock tree. If you do reach the top, fail with some error code. Isn't that how clock enable already works anyway ?

No. In the non-CCF case, we have no idea what the parent of any given clock is. So there's no framework we can provide.

Huh, but this driver is attempting to grab some sort of parent clock and enable them, so how does that work ?

Quoted 11 lines

Now, you might say "why not add a get_parent op?" Well, that will work fine for enabling things, but it is a bit hairy on the disable side. You really need to have refcounting to protect parent clocks (which can have many children). But we don't really have anywhere to store refcounts. struct clk has a member for it, but that's only because it's abused as private data by CCF. Non-CCF clocks have no clock subsystem data allocated at all. Another alternative is to just only disable the leaf node, which is what we currently do. That's OK I think.

But that solution requires some more-intensive effort which I don't want to impose on random contributors. So for the time being, all non-CCF clock drivers must handle enabling their own parent clocks.

So, in light of this, why not push for use of CCF as much as possible and deprecate the current non-CCF clock support ? It seems like the right thing to do, and avoids growing ad-hoc workarounds for missing core functionality in drivers, which I really want to avoid .

#12 lore raw

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

Quoted 92 lines · Marek Vasut
Quoted 91 lines · Sean Anderson
Quoted 90 lines · Marek Vasut
Quoted 89 lines · Sean Anderson
Quoted 87 lines · Marek Vasut
Quoted 83 lines · Sean Anderson
Quoted 73 lines · Marek Vasut
Quoted 72 lines · Sean Anderson
Quoted 71 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 | 44 ++++++++++++++++++++++++++++++++++--------

  1 file changed, 36 insertions(+), 8 deletions(-)
drivers/clk/clk-gpio.c +29 -7
index 26d795b978..72d9747a47 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)
+static int clk_gpio_of_to_plat(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) {
Quoted 8 lines
Quoted 6 lines

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

Quoted 6 lines
drivers/clk/clk-gpio.c +6 -0
+        log_debug("%s: Could not decode enable-gpios (%d)\n",
+              __func__, ret);
+        return ret;
+    }
+
+    return 0;

All this forwarding of clock enable/disable/get_rate for parent clock should already be done in clock core. If it is not, then it should be fixed in clock core.

Quoted 1 line

Only CCF forwards things. It's up to the driver to do it in the non-CCF case.

Shall we add dependency on CCF instead of duplicating code in drivers ?

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

I'd rather not. This will be useful on non-CCF systems.

Then the forwarding functionality should be in the clock core, basically if a driver does not implement callback <something>, call parent clock callback <something>, and repeat until you reach the top of the clock tree. If you do reach the top, fail with some error code. Isn't that how clock enable already works anyway ?

No. In the non-CCF case, we have no idea what the parent of any given clock is. So there's no framework we can provide.

Huh, but this driver is attempting to grab some sort of parent clock and enable them, so how does that work ?

The driver knows what its parent is, so it can enable it just fine.

Quoted 8 lines
Quoted 8 lines

Now, you might say "why not add a get_parent op?" Well, that will work fine for enabling things, but it is a bit hairy on the disable side. You really need to have refcounting to protect parent clocks (which can have many children). But we don't really have anywhere to store refcounts. struct clk has a member for it, but that's only because it's abused as private data by CCF. Non-CCF clocks have no clock subsystem data allocated at all. Another alternative is to just only disable the leaf node, which is what we currently do. That's OK I think.

Quoted 5 lines
Quoted 3 lines

But that solution requires some more-intensive effort which I don't want to impose on random contributors. So for the time being, all non-CCF clock drivers must handle enabling their own parent clocks.

So, in light of this, why not push for use of CCF as much as possible and deprecate the current non-CCF clock support ? It seems like the right thing to do, and avoids growing ad-hoc workarounds for missing core functionality in drivers, which I really want to avoid .

Because the CCF framework abuses struct clk for private data, uses strings everywhere, and dynamically allocates all its clocks (which are known at compile-time). You can easily save 4K (or more) by moving away from CCF, which can be especially important in SPL. It's a necessary evil because people want to copy their clock drivers straight from Linux, but IMO it is a step in the wrong direction right now. Especially due to the dynamic allocation and strings I think it is not fixable in the general sense. But the "core" also needs some refactoring (in particular to fix the abuse of struct clk).

Working on this has been on my TODO for a long time, but I have not gotten around to it.

--Sean

#13 lore raw

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

In reply to Sean Anderson
Quoted 49 lines · Sean Anderson
Quoted 48 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 | 44 ++++++++++++++++++++++++++++++++++--------

  1 file changed, 36 insertions(+), 8 deletions(-)
drivers/clk/clk-gpio.c +15 -4
index 26d795b978..72d9747a47 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);
+}
Quoted 8 lines

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

Quoted 8 lines
drivers/clk/clk-gpio.c +3 -1
+
   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)
+static int clk_gpio_of_to_plat(struct udevice *dev)

Same comment as the first time:

Why the conversion from probe to of_to_plat?

--Sean

Quoted 34 lines
Quoted 24 lines
drivers/clk/clk-gpio.c +17 -2
   {
       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;
   }
   /*

drivers/clk/clk-gpio.c U_BOOT_DRIVER(gpio_gate_clock) = { · line 93

Quoted 8 lines
drivers/clk/clk-gpio.c +1 -1
@@ -59,7 +87,7 @@ U_BOOT_DRIVER(gpio_gate_clock) = {
       .name        = "gpio_clock",
       .id        = UCLASS_CLK,
       .of_match    = clk_gpio_match,
-    .probe        = clk_gpio_probe,
+    .of_to_plat    = clk_gpio_of_to_plat,
       .priv_auto    = sizeof(struct clk_gpio_priv),
       .ops        = &clk_gpio_ops,
       .flags        = DM_FLAG_PRE_RELOC,

+CC Marek

author
#14 lore raw

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

10 січня 2024 р. 17:45:57 GMT+02:00, Sean Anderson <[email protected]> написав(-ла):

Quoted 61 lines · Sean Anderson
Quoted 49 lines · Svyatoslav Ryhel
Quoted 48 lines

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 | 44 ++++++++++++++++++++++++++++++++++--------

  1 file changed, 36 insertions(+), 8 deletions(-)
drivers/clk/clk-gpio.c +15 -4
index 26d795b978..72d9747a47 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);
+}
Quoted 8 lines

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

Quoted 8 lines
drivers/clk/clk-gpio.c +3 -1
+
   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)
+static int clk_gpio_of_to_plat(struct udevice *dev)

Same comment as the first time:

Quoted 2 lines

Why the conversion from probe to of_to_plat?

Same answer as the first time. You propose to spam commits for this small adjustment?

Quoted 37 lines

--Sean

Quoted 34 lines
Quoted 24 lines
drivers/clk/clk-gpio.c +17 -2
   {
       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;
   }
   /*

drivers/clk/clk-gpio.c U_BOOT_DRIVER(gpio_gate_clock) = { · line 93

Quoted 8 lines
drivers/clk/clk-gpio.c +1 -1
@@ -59,7 +87,7 @@ U_BOOT_DRIVER(gpio_gate_clock) = {
       .name        = "gpio_clock",
       .id        = UCLASS_CLK,
       .of_match    = clk_gpio_match,
-    .probe        = clk_gpio_probe,
+    .of_to_plat    = clk_gpio_of_to_plat,
       .priv_auto    = sizeof(struct clk_gpio_priv),
       .ops        = &clk_gpio_ops,
       .flags        = DM_FLAG_PRE_RELOC,

+CC Marek

#15 lore raw

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

Quoted 64 lines · Svyatoslav

10 січня 2024 р. 17:45:57 GMT+02:00, Sean Anderson <[email protected]> написав(-ла):

Quoted 61 lines · Sean Anderson
Quoted 49 lines · Svyatoslav Ryhel
Quoted 48 lines

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 | 44 ++++++++++++++++++++++++++++++++++--------
   1 file changed, 36 insertions(+), 8 deletions(-)
drivers/clk/clk-gpio.c +15 -4
index 26d795b978..72d9747a47 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);
+}
Quoted 8 lines

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

Quoted 8 lines
drivers/clk/clk-gpio.c +3 -1
+
   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)
+static int clk_gpio_of_to_plat(struct udevice *dev)

Same comment as the first time:

Quoted 4 lines
Quoted 2 lines

Why the conversion from probe to of_to_plat?

Same answer as the first time.

Last time you said

Quoted 6 lines
Quoted 6 lines

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

Quoted 3 lines
drivers/clk/clk-gpio.c +1 -1
-static int clk_gpio_probe(struct udevice *dev)
+static int clk_gpio_of_to_plat(struct udevice *dev)

This change should be a separate commit.

Quoted 7 lines

This actually should not be accepted first place

.of_to_plat - convert device tree data to plat
.probe - make a device ready for use

https://github.com/u-boot/u-boot/blob/master/doc/develop/driver-model/design.rst

and I thought "This actually should not be accepted first place" was referring to the conversion (i.e. that you would be removing it next time).

This sort of conversion should be mentioned in the commit message.

And the weird thing to me is that I would expect of_to_plat to fill in a platdata struct. If you are not doing that, why use this function?

Quoted 1 line

You propose to spam commits for this small adjustment?

Yes. One change per commit.

--Sean