Skip to contentSkip to conversation

clk: A few bugfixes/enhancements for CCF

PATCH Superseded Yang Xiwen 1 participant 6 messages Aug 8, 2023 Common clk

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yang Xiwen

author
#0 lore raw

cover clk: A few bugfixes/enhancements for CCF

They are found during my development for HiSilicon clock driver. Details are in commit logs.

---
Yang Xiwen (5):
clk: export clk_register_mux_table()
clk: call log_debug() instead to avoid console log printing
clk: also handle ENOENT in *_optional functions
clk: promote clk_dev_ops to linux/clk-provider.h
clk: ccf: call clock provided ops directly for endisable()

 drivers/clk/clk-uclass.c     |  5 -----
 drivers/clk/clk.c            | 16 +++++++++++++---
 include/clk.h                |  8 +++++---
 include/linux/clk-provider.h | 11 +++++++++++
 4 files changed, 29 insertions(+), 11 deletions(-)

---
base-commit: 580eb31199be8a822e62f20965854a242f895d03
change-id: 20230807-clk-fix-17e895f79817

Best regards,

Signature · 1 line
Yang Xiwen <[email protected]>
author
#1 lore raw

PATCH 1/5 clk: export clk_register_mux_table()

It's already implemented in clk-mux.c, export it in the header file.

---
 include/linux/clk-provider.h | 6 ++++++
 1 file changed, 6 insertions(+)
include/linux/clk-provider.h +6 -0
index b8acacd49e..801404480b 100644
@@ -247,6 +247,12 @@ struct clk *clk_register_mux(struct device *dev, const char *name,
 		void __iomem *reg, u8 shift, u8 width,
 		u8 clk_mux_flags);
 
+struct clk *clk_register_mux_table(struct device *dev, const char *name,
+				   const char * const *parent_names, u8 num_parents,
+				   unsigned long flags,
+				   void __iomem *reg, u8 shift, u32 mask,
+				   u8 clk_mux_flags, u32 *table);
+
 struct clk *clk_register_fixed_rate(struct device *dev, const char *name,
 				    ulong rate);
 
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 2/5 clk: call log_debug() instead to avoid console log printing

In reply to Yang Xiwen

it's a very common case to register a clock without a parent, such as clk_register_fixed_rate(). Replace log_error() with log_debug() to avoid useless console log if not debugging.

---
 drivers/clk/clk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/clk.c +2 -2
index a5a3461b66..a38daaac0c 100644
@@ -24,8 +24,8 @@ int clk_register(struct clk *clk, const char *drv_name,
 
 	ret = uclass_get_device_by_name(UCLASS_CLK, parent_name, &parent);
 	if (ret) {
-		log_err("%s: failed to get %s device (parent of %s)\n",
-			__func__, parent_name, name);
+		log_debug("%s: failed to get %s device (parent of %s)\n",
+			  __func__, parent_name, name);
 	} else {
 		log_debug("%s: name: %s parent: %s [0x%p]\n", __func__, name,
 			  parent->name, parent);
Signature · 1 line
2.34.1
author
#3 lore raw

PATCH 3/5 clk: also handle ENOENT in *_optional functions

In reply to Yang Xiwen

If the device does not specify any clocks in device tree, these functions will return PTR_ERR(-ENOENT). This is not the intended behavior and does not comply with linux kernel CCF. Fix that by returning NULL under such circumstances instead.

---
 include/clk.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
include/clk.h +5 -3
index d91285235f..f95da0838d 100644
@@ -223,9 +223,11 @@ struct clk *devm_clk_get(struct udevice *dev, const char *id);
 static inline struct clk *devm_clk_get_optional(struct udevice *dev,
 						const char *id)
 {
+	int ret;
 	struct clk *clk = devm_clk_get(dev, id);
 
-	if (PTR_ERR(clk) == -ENODATA)
+	ret = PTR_ERR(clk);
+	if (ret == -ENODATA || ret == -ENOENT)
 		return NULL;
 
 	return clk;
@@ -335,7 +337,7 @@ static inline int clk_get_by_name_optional(struct udevice *dev,
 	int ret;
 
 	ret = clk_get_by_name(dev, name, clk);
-	if (ret == -ENODATA)
+	if (ret == -ENODATA || ret == -ENOENT)
 		return 0;
 
 	return ret;
@@ -359,7 +361,7 @@ static inline int clk_get_by_name_nodev_optional(ofnode node, const char *name,
 	int ret;
 
 	ret = clk_get_by_name_nodev(node, name, clk);
-	if (ret == -ENODATA)
+	if (ret == -ENODATA || ret == -ENOENT)
 		return 0;
 
 	return ret;
Signature · 1 line
2.34.1
author
#4 lore raw

PATCH 4/5 clk: promote clk_dev_ops to linux/clk-provider.h

In reply to Yang Xiwen

So that it can be used by others.

---
 drivers/clk/clk-uclass.c     | 5 -----
 include/linux/clk-provider.h | 5 +++++
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/clk/clk-uclass.c +0 -5
index dc3e9d6a26..5cc80e5e39 100644
@@ -25,11 +25,6 @@
 #include <linux/clk-provider.h>
 #include <linux/err.h>
 
-static inline const struct clk_ops *clk_dev_ops(struct udevice *dev)
-{
-	return (const struct clk_ops *)dev->driver->ops;
-}
-
 struct clk *dev_get_clk_ptr(struct udevice *dev)
 {
 	return (struct clk *)dev_get_uclass_priv(dev);
include/linux/clk-provider.h +5 -0
index 801404480b..dfafb4cc9d 100644
@@ -21,6 +21,11 @@ static inline void clk_dm(ulong id, struct clk *clk)
 		clk->id = id;
 }
 
+static inline const struct clk_ops *clk_dev_ops(struct udevice *dev)
+{
+	return (const struct clk_ops *)dev->driver->ops;
+}
+
 /*
  * flags used across common struct clk.  these flags should only affect the
  * top-level framework.  custom flags for dealing with hardware specifics
Signature · 1 line
2.34.1
author
#5 lore raw

PATCH 5/5 clk: ccf: call clock provided ops directly for endisable()

In reply to Yang Xiwen

Calling into CCF framework will cause a clock being enabled twice instead of once (clk->enable_count becomes 2 rather than 1), thus making it hard to disable (needs to call clk_disable() twice).
Fix that by calling clock provided ops directly.

---
 drivers/clk/clk.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/clk/clk.c +11 -1
index a38daaac0c..00d082c46f 100644
@@ -14,6 +14,7 @@
 #include <dm/uclass.h>
 #include <dm/lists.h>
 #include <dm/device-internal.h>
+#include <linux/clk-provider.h>
 
 int clk_register(struct clk *clk, const char *drv_name,
 		 const char *name, const char *parent_name)
@@ -115,11 +116,20 @@ int ccf_clk_set_parent(struct clk *clk, struct clk *parent)
 static int ccf_clk_endisable(struct clk *clk, bool enable)
 {
 	struct clk *c;
+	const struct clk_ops *ops;
 	int err = clk_get_by_id(clk->id, &c);
 
 	if (err)
 		return err;
-	return enable ? clk_enable(c) : clk_disable(c);
+	else
+		ops = clk_dev_ops(c->dev);
+
+	if (enable && ops->enable)
+		return ops->enable(c);
+	else if (!enable && ops->disable)
+		return ops->disable(c);
+
+	return -ENOSYS;
 }
 
 int ccf_clk_enable(struct clk *clk)
Signature · 1 line
2.34.1