Skip to contentSkip to conversation

DEV: CLK: add function to check the using clock name of driver.

PATCH In review Hao Zhang 2 participants 2 messages Nov 25, 2018 – Nov 26, 2018

Subsystems (3)
lore
Share & tools
lore

Hao Zhang

author
#0 lore raw

PATCH v3 4/6 DEV: CLK: add function to check the using clock name of driver.

In some situation we want to check clock whether is we want and after the driver been probed use to change different clock source.

---
 drivers/clk/clk.c            | 6 ++++++
 include/linux/clk-provider.h | 1 +
 2 files changed, 7 insertions(+)
drivers/clk/clk.c +6 -0
index d31055a..3d2c2cd 100644
@@ -3466,6 +3466,12 @@ static int devm_clk_hw_match(struct device *dev, void *res, void *data)
 	return hw == data;
 }
 
+bool devm_clk_name_match(struct clk *clk, const char *string)
+{
+	return match_string(&clk->con_id, 1, string) == 0;
+}
+EXPORT_SYMBOL_GPL(devm_clk_name_match);
+
 /**
  * devm_clk_unregister - resource managed clk_unregister()
  * @clk: clock to unregister
include/linux/clk-provider.h +1 -0
index 08b1aa7..5cd2eed 100644
@@ -764,6 +764,7 @@ struct clk *devm_clk_register(struct device *dev, struct clk_hw *hw);
 int __must_check clk_hw_register(struct device *dev, struct clk_hw *hw);
 int __must_check devm_clk_hw_register(struct device *dev, struct clk_hw *hw);
 
+bool devm_clk_name_match(struct clk *clk, const char *string);
 void clk_unregister(struct clk *clk);
 void devm_clk_unregister(struct device *dev, struct clk *clk);
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 8 lines · Hao Zhang

In some situation we want to check clock whether is we want and after the driver been probed use to change different clock source.

---
 drivers/clk/clk.c            | 6 ++++++
 include/linux/clk-provider.h | 1 +
 2 files changed, 7 insertions(+)

This doesn't seem right. If you're going to change to to a different clock source anyway, why would you even want to know what it was set before that? Isn't that completely irrelevant?

But if you really need this, perhaps a combination of clk_get() and clk_is_match() would be a better approach? Perhaps best to let Mike and Stephen share their feelings about this kind of API.

drivers/clk/clk.c static int devm_clk_hw_match(struct device *dev, void *res, void *data) · line 3473

Quoted 13 lines
drivers/clk/clk.c +5 -0
index d31055a..3d2c2cd 100644
@@ -3466,6 +3466,12 @@ static int devm_clk_hw_match(struct device *dev, void *res, void *data)
 	return hw == data;
 }
 
+bool devm_clk_name_match(struct clk *clk, const char *string)
+{
+	return match_string(&clk->con_id, 1, string) == 0;
+}
+EXPORT_SYMBOL_GPL(devm_clk_name_match);

Also, there's nothing about this that would be device-managed, so the devm_ prefix on the function name is misleading.

Quoted 8 lines
drivers/clk/clk.c +0 -0
 /**
  * devm_clk_unregister - resource managed clk_unregister()
  * @clk: clock to unregister
include/linux/clk-provider.h +0 -0
index 08b1aa7..5cd2eed 100644

include/linux/clk-provider.h struct clk *devm_clk_register(struct device *dev, struct clk_hw *hw); · line 769

Quoted 6 lines
include/linux/clk-provider.h +1 -0
@@ -764,6 +764,7 @@ struct clk *devm_clk_register(struct device *dev, struct clk_hw *hw);
 int __must_check clk_hw_register(struct device *dev, struct clk_hw *hw);
 int __must_check devm_clk_hw_register(struct device *dev, struct clk_hw *hw);
 
+bool devm_clk_name_match(struct clk *clk, const char *string);
 void clk_unregister(struct clk *clk);
 void devm_clk_unregister(struct device *dev, struct clk *clk);

You use this from clock consumers, so clk-provider.h is not the right place for it. Also, you'll want to add a dummy implementation for the case where CONFIG_COMMON_CLK is not set.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20181126/5b082cc3/attachment.sig>