public inbox for linux-clk@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] Convert clk-fixed into module platform driver
@ 2016-06-20 13:43 Ricardo Ribalda Delgado
  2016-06-20 13:43 ` [PATCH v2 1/3] clk: Add new function of_clk_is_provider() Ricardo Ribalda Delgado
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-06-20 13:43 UTC (permalink / raw)
  To: Stephen Boyd, Michael Turquette, s.hauer, jeremy.kerr, linux-clk,
	linux-kernel
  Cc: Ricardo Ribalda Delgado

When clock providers are added to the device tree after of_clk_init is called
they are not added to the clock provider list. This makes that drivers such
as i2c-xiic.c fail to init, as they may depend on the unadded clock provider.

We first introduce a new function clk.c that will check if a device_node is
already a clock provider or not.

Later we add two patches, one for clk-fixed-factor and another to
clk-fixed-rate that make us of that function and also convert both drivers
to module platform driver, but keeping all the previous functionality intact.

v2: Changes proposed by: Stephen Boyd <sboyd@codeaurora.org>
-Add error check
-CodeStyle on of_device_ide
-Use builtin_platform_driver()

Ricardo Ribalda Delgado (3):
  clk: Add new function of_clk_is_provider()
  clk: fixed-factor: Convert into a module platform driver
  clk: fixed-rate: Convert into a module platform driver

 drivers/clk/clk-fixed-factor.c | 75 +++++++++++++++++++++++++++++++++++++++---
 drivers/clk/clk-fixed-rate.c   | 71 ++++++++++++++++++++++++++++++++++++---
 drivers/clk/clk.c              | 20 +++++++++++
 include/linux/clk-provider.h   |  5 +++
 4 files changed, 162 insertions(+), 9 deletions(-)

-- 
2.8.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/3] clk: Add new function of_clk_is_provider()
  2016-06-20 13:43 [PATCH v2 0/3] Convert clk-fixed into module platform driver Ricardo Ribalda Delgado
@ 2016-06-20 13:43 ` Ricardo Ribalda Delgado
  2016-06-20 13:43 ` [PATCH v2 2/3] clk: fixed-factor: Convert into a module platform driver Ricardo Ribalda Delgado
  2016-06-20 13:43 ` [PATCH v2 3/3] clk: fixed-rate: " Ricardo Ribalda Delgado
  2 siblings, 0 replies; 4+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-06-20 13:43 UTC (permalink / raw)
  To: Stephen Boyd, Michael Turquette, s.hauer, jeremy.kerr, linux-clk,
	linux-kernel
  Cc: Ricardo Ribalda Delgado

of_clk_is_provider() checks if a device_node has already been added to
the clk provider list. This can be used to avoid adding the same clock
provider twice.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 drivers/clk/clk.c            | 20 ++++++++++++++++++++
 include/linux/clk-provider.h |  5 +++++
 2 files changed, 25 insertions(+)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index d584004f7af7..2423c6373906 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -3120,6 +3120,26 @@ __of_clk_get_hw_from_provider(struct of_clk_provider *provider,
 	return hw;
 }
 
+/**
+ * of_clk_is_provider() - Reports if a device node is already a clk provider
+ * @np: Device node pointer under test
+ */
+bool of_clk_is_provider(struct device_node *np)
+{
+	struct of_clk_provider *cp;
+
+	mutex_lock(&of_clk_mutex);
+	list_for_each_entry(cp, &of_clk_providers, link) {
+		if (cp->node == np) {
+			mutex_unlock(&of_clk_mutex);
+			return true;
+		}
+	}
+	mutex_unlock(&of_clk_mutex);
+	return false;
+}
+EXPORT_SYMBOL_GPL(of_clk_is_provider);
+
 struct clk *__of_clk_get_from_provider(struct of_phandle_args *clkspec,
 				       const char *dev_id, const char *con_id)
 {
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index fb39d5add173..a01b18797418 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -787,6 +787,7 @@ int of_clk_add_hw_provider(struct device_node *np,
 						 void *data),
 			   void *data);
 void of_clk_del_provider(struct device_node *np);
+bool of_clk_is_provider(struct device_node *np);
 struct clk *of_clk_src_simple_get(struct of_phandle_args *clkspec,
 				  void *data);
 struct clk_hw *of_clk_hw_simple_get(struct of_phandle_args *clkspec,
@@ -819,6 +820,10 @@ static inline int of_clk_add_hw_provider(struct device_node *np,
 	return 0;
 }
 static inline void of_clk_del_provider(struct device_node *np) {}
+static inline bool of_clk_is_provider(struct device_node *np)
+{
+	return false;
+}
 static inline struct clk *of_clk_src_simple_get(
 	struct of_phandle_args *clkspec, void *data)
 {
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/3] clk: fixed-factor: Convert into a module platform driver
  2016-06-20 13:43 [PATCH v2 0/3] Convert clk-fixed into module platform driver Ricardo Ribalda Delgado
  2016-06-20 13:43 ` [PATCH v2 1/3] clk: Add new function of_clk_is_provider() Ricardo Ribalda Delgado
@ 2016-06-20 13:43 ` Ricardo Ribalda Delgado
  2016-06-20 13:43 ` [PATCH v2 3/3] clk: fixed-rate: " Ricardo Ribalda Delgado
  2 siblings, 0 replies; 4+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-06-20 13:43 UTC (permalink / raw)
  To: Stephen Boyd, Michael Turquette, s.hauer, jeremy.kerr, linux-clk,
	linux-kernel
  Cc: Ricardo Ribalda Delgado

Adds support for fixed-factor clock providers which have not been
enabled via of_clk_init().

This is required by Device trees overlays that introduce clocks
providers.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
v2: Changes proposed by: Stephen Boyd <sboyd@codeaurora.org>
-Add error check
-CodeStyle on of_device_ide
-Use builtin_platform_driver()

 drivers/clk/clk-fixed-factor.c | 75 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 70 insertions(+), 5 deletions(-)

diff --git a/drivers/clk/clk-fixed-factor.c b/drivers/clk/clk-fixed-factor.c
index 75cd6c792cb8..73e7c1267bb6 100644
--- a/drivers/clk/clk-fixed-factor.c
+++ b/drivers/clk/clk-fixed-factor.c
@@ -12,6 +12,7 @@
 #include <linux/slab.h>
 #include <linux/err.h>
 #include <linux/of.h>
+#include <linux/platform_device.h>
 
 /*
  * DOC: basic fixed multiplier and divider clock that cannot gate
@@ -145,23 +146,24 @@ EXPORT_SYMBOL_GPL(clk_hw_unregister_fixed_factor);
 /**
  * of_fixed_factor_clk_setup() - Setup function for simple fixed factor clock
  */
-void __init of_fixed_factor_clk_setup(struct device_node *node)
+struct clk *_of_fixed_factor_clk_setup(struct device_node *node)
 {
 	struct clk *clk;
 	const char *clk_name = node->name;
 	const char *parent_name;
 	u32 div, mult;
+	int ret;
 
 	if (of_property_read_u32(node, "clock-div", &div)) {
 		pr_err("%s Fixed factor clock <%s> must have a clock-div property\n",
 			__func__, node->name);
-		return;
+		return ERR_PTR(-EIO);
 	}
 
 	if (of_property_read_u32(node, "clock-mult", &mult)) {
 		pr_err("%s Fixed factor clock <%s> must have a clock-mult property\n",
 			__func__, node->name);
-		return;
+		return ERR_PTR(-EIO);
 	}
 
 	of_property_read_string(node, "clock-output-names", &clk_name);
@@ -169,10 +171,73 @@ void __init of_fixed_factor_clk_setup(struct device_node *node)
 
 	clk = clk_register_fixed_factor(NULL, clk_name, parent_name, 0,
 					mult, div);
-	if (!IS_ERR(clk))
-		of_clk_add_provider(node, of_clk_src_simple_get, clk);
+	if (IS_ERR(clk))
+		return clk;
+
+	ret = of_clk_add_provider(node, of_clk_src_simple_get, clk);
+	if (ret) {
+		clk_unregister(clk);
+		return ERR_PTR(ret);
+	}
+
+	return clk;
+}
+
+void __init of_fixed_factor_clk_setup(struct device_node *node)
+{
+	_of_fixed_factor_clk_setup(node);
+	return;
 }
 EXPORT_SYMBOL_GPL(of_fixed_factor_clk_setup);
 CLK_OF_DECLARE(fixed_factor_clk, "fixed-factor-clock",
 		of_fixed_factor_clk_setup);
+
+static int of_fixed_factor_clk_remove(struct platform_device *pdev)
+{
+	struct clk *clk = platform_get_drvdata(pdev);
+
+	if (clk)
+		clk_unregister_fixed_factor(clk);
+
+	return 0;
+}
+
+static int of_fixed_factor_clk_probe(struct platform_device *pdev)
+{
+	struct clk *clk;
+
+	/*
+	 * Don't do anything if of_clk_init() has already
+	 * added this clock to the provider list
+	 */
+	if (of_clk_is_provider(pdev->dev.of_node))
+		return 0;
+
+	clk = _of_fixed_factor_clk_setup(pdev->dev.of_node);
+
+	if (IS_ERR(clk))
+		return PTR_ERR(clk);
+
+	platform_set_drvdata(pdev, clk);
+
+	return 0;
+}
+
+static const struct of_device_id of_fixed_factor_clk_ids[] = {
+	{ .compatible = "fixed-factor-clock" },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, of_fixed_factor_clk_ids);
+
+static struct platform_driver of_fixed_factor_clk_driver = {
+	.driver = {
+		.name = "of_fixed_factor_clk",
+		.of_match_table = of_fixed_factor_clk_ids,
+	},
+	.probe = of_fixed_factor_clk_probe,
+	.remove = of_fixed_factor_clk_remove,
+};
+
+builtin_platform_driver(of_fixed_factor_clk_driver);
+
 #endif
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 3/3] clk: fixed-rate: Convert into a module platform driver
  2016-06-20 13:43 [PATCH v2 0/3] Convert clk-fixed into module platform driver Ricardo Ribalda Delgado
  2016-06-20 13:43 ` [PATCH v2 1/3] clk: Add new function of_clk_is_provider() Ricardo Ribalda Delgado
  2016-06-20 13:43 ` [PATCH v2 2/3] clk: fixed-factor: Convert into a module platform driver Ricardo Ribalda Delgado
@ 2016-06-20 13:43 ` Ricardo Ribalda Delgado
  2 siblings, 0 replies; 4+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-06-20 13:43 UTC (permalink / raw)
  To: Stephen Boyd, Michael Turquette, s.hauer, jeremy.kerr, linux-clk,
	linux-kernel
  Cc: Ricardo Ribalda Delgado

Adds support for fixed-rate clock providers which have not been
enabled via of_clk_init().

This is required by Device trees overlays that introduce clocks
providers.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
v2: Changes proposed by: Stephen Boyd <sboyd@codeaurora.org>
-Add error check
-CodeStyle on of_device_ide
-Use builtin_platform_driver()
 drivers/clk/clk-fixed-rate.c | 71 +++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 67 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/clk-fixed-rate.c b/drivers/clk/clk-fixed-rate.c
index 8e4453eb54e8..eb51922f86f7 100644
--- a/drivers/clk/clk-fixed-rate.c
+++ b/drivers/clk/clk-fixed-rate.c
@@ -15,6 +15,7 @@
 #include <linux/io.h>
 #include <linux/err.h>
 #include <linux/of.h>
+#include <linux/platform_device.h>
 
 /*
  * DOC: basic fixed-rate clock that cannot gate
@@ -149,15 +150,16 @@ EXPORT_SYMBOL_GPL(clk_unregister_fixed_rate);
 /**
  * of_fixed_clk_setup() - Setup function for simple fixed rate clock
  */
-void of_fixed_clk_setup(struct device_node *node)
+struct clk *_of_fixed_clk_setup(struct device_node *node)
 {
 	struct clk *clk;
 	const char *clk_name = node->name;
 	u32 rate;
 	u32 accuracy = 0;
+	int ret;
 
 	if (of_property_read_u32(node, "clock-frequency", &rate))
-		return;
+		return ERR_PTR(-EIO);
 
 	of_property_read_u32(node, "clock-accuracy", &accuracy);
 
@@ -165,9 +167,70 @@ void of_fixed_clk_setup(struct device_node *node)
 
 	clk = clk_register_fixed_rate_with_accuracy(NULL, clk_name, NULL,
 						    0, rate, accuracy);
-	if (!IS_ERR(clk))
-		of_clk_add_provider(node, of_clk_src_simple_get, clk);
+	if (IS_ERR(clk))
+		return clk;
+
+	ret = of_clk_add_provider(node, of_clk_src_simple_get, clk);
+	if (ret) {
+		clk_unregister(clk);
+		return ERR_PTR(ret);
+	}
+
+	return clk;
+}
+
+void of_fixed_clk_setup(struct device_node *node)
+{
+	_of_fixed_clk_setup(node);
 }
 EXPORT_SYMBOL_GPL(of_fixed_clk_setup);
 CLK_OF_DECLARE(fixed_clk, "fixed-clock", of_fixed_clk_setup);
+
+static int of_fixed_clk_remove(struct platform_device *pdev)
+{
+	struct clk *clk = platform_get_drvdata(pdev);
+
+	if (clk)
+		clk_unregister_fixed_rate(clk);
+
+	return 0;
+}
+
+static int of_fixed_clk_probe(struct platform_device *pdev)
+{
+	struct clk *clk;
+
+	/*
+	 * Don't do anything if of_clk_init() has already
+	 * added this clock to the provider list
+	 */
+	if (of_clk_is_provider(pdev->dev.of_node))
+		return 0;
+
+	clk = _of_fixed_clk_setup(pdev->dev.of_node);
+
+	if (IS_ERR(clk))
+		return PTR_ERR(clk);
+
+	platform_set_drvdata(pdev, clk);
+
+	return 0;
+}
+
+static const struct of_device_id of_fixed_clk_ids[] = {
+	{ .compatible = "fixed-clock" },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, of_fixed_clk_ids);
+
+static struct platform_driver of_fixed_clk_driver = {
+	.driver = {
+		.name = "of_fixed_clk",
+		.of_match_table = of_fixed_clk_ids,
+	},
+	.probe = of_fixed_clk_probe,
+	.remove = of_fixed_clk_remove,
+};
+
+builtin_platform_driver(of_fixed_clk_driver);
 #endif
-- 
2.8.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-06-20 13:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-20 13:43 [PATCH v2 0/3] Convert clk-fixed into module platform driver Ricardo Ribalda Delgado
2016-06-20 13:43 ` [PATCH v2 1/3] clk: Add new function of_clk_is_provider() Ricardo Ribalda Delgado
2016-06-20 13:43 ` [PATCH v2 2/3] clk: fixed-factor: Convert into a module platform driver Ricardo Ribalda Delgado
2016-06-20 13:43 ` [PATCH v2 3/3] clk: fixed-rate: " Ricardo Ribalda Delgado

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox