Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1437172 > unrolled thread

[PATCH v5 0/8] clk: Don't duplicate initialization on platform_dev

Started byRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>
First post2016-07-05 18:30 +0200
Last post2016-07-05 18:30 +0200
Articles 4 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH v5 0/8] clk: Don't duplicate initialization on platform_dev Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> - 2016-07-05 18:30 +0200
    [PATCH v5 5/8] clk: sunxi: Use new macro CLK_OF_DECLARE_DRIVER Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> - 2016-07-05 18:30 +0200
    [PATCH v5 7/8] clk: fixed-factor: Convert into a module platform driver Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> - 2016-07-05 18:30 +0200
    [PATCH v5 4/8] clk: sunxi: mod0: Use new macro CLK_OF_DECLARE_DRIVER Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> - 2016-07-05 18:30 +0200

#1437172 — [PATCH v5 0/8] clk: Don't duplicate initialization on platform_dev

FromRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Date2016-07-05 18:30 +0200
Subject[PATCH v5 0/8] clk: Don't duplicate initialization on platform_dev
Message-ID<rRBou-5cR-13@gated-at.bofh.it>
Clock providers can be probed as a normal platform device, or via
of_clk_init() before the rest of the platform devices are initialized
using the CLK_OF_DECLARE() macro.

If a driver required both initialization methodologies, the core would call
both probe/init functions.

This changeset prevent the dual initialization using the OF_POPULATE flag.

It also creates a new macro, CLK_OF_DECLARE_DRIVER, used by drivers that
require double initialization.

Finally, it adds module platform driver initialization to fixed-factor
and fixed-rate, enabling its use in dt overlays.

The order of the patches allows future bisects of the change. This explains
why  Avoid double initialization of clocks() is done almost at the end.

v5: Changes proposed by: Stephen Boyd <sboyd@codeaurora.org>
-Create CLK_OF_DECLARE_DRIVER() macro
-use it in clk-artpec6, sunxi,nxp

v4: Huge MACRO(), not posted to the list

v3: Use OF_POPULATE flag inside fixed-rate and fixed-factor

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

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.

Ricardo Ribalda Delgado (8):
  clk: core: New macro CLK_OF_DECLARE_DRIVER
  clk: axis: Use new macro CLK_OF_DECLARE_DRIVER
  clk: npx: Use new macro CLK_OF_DECLARE_DRIVER
  clk: sunxi: mod0: Use new macro CLK_OF_DECLARE_DRIVER
  clk: sunxi: apb0: Use new macro CLK_OF_DECLARE_DRIVER
  clk: core: Avoid double initialization of clocks
  clk: fixed-factor: Convert into a module platform driver
  clk: fixed-rate: Convert into a module platform driver

 drivers/clk/axis/clk-artpec6.c     |  4 +--
 drivers/clk/clk-fixed-factor.c     | 72 +++++++++++++++++++++++++++++++++++---
 drivers/clk/clk-fixed-rate.c       | 69 +++++++++++++++++++++++++++++++++---
 drivers/clk/clk.c                  |  4 +++
 drivers/clk/nxp/clk-lpc18xx-creg.c |  3 +-
 drivers/clk/sunxi/clk-mod0.c       |  3 +-
 drivers/clk/sunxi/clk-sun8i-apb0.c |  4 +--
 include/linux/clk-provider.h       | 12 +++++++
 8 files changed, 156 insertions(+), 15 deletions(-)

-- 
2.8.1

[toc] | [next] | [standalone]


#1437173 — [PATCH v5 5/8] clk: sunxi: Use new macro CLK_OF_DECLARE_DRIVER

FromRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Date2016-07-05 18:30 +0200
Subject[PATCH v5 5/8] clk: sunxi: Use new macro CLK_OF_DECLARE_DRIVER
Message-ID<rRBov-5cR-51@gated-at.bofh.it>
In reply to#1437172
This driver initializes a clock provider via sun8i_a23_apb0_setup
and then continues the initialization on sun8i_a23_apb0_clk_probe.

Use the new macro to notify the clk subsystem about this behaviour.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 drivers/clk/sunxi/clk-sun8i-apb0.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/sunxi/clk-sun8i-apb0.c b/drivers/clk/sunxi/clk-sun8i-apb0.c
index 2ea61debffc1..b6be5d2d9440 100644
--- a/drivers/clk/sunxi/clk-sun8i-apb0.c
+++ b/drivers/clk/sunxi/clk-sun8i-apb0.c
@@ -82,8 +82,8 @@ err_unmap:
 	of_address_to_resource(node, 0, &res);
 	release_mem_region(res.start, resource_size(&res));
 }
-CLK_OF_DECLARE(sun8i_a23_apb0, "allwinner,sun8i-a23-apb0-clk",
-	       sun8i_a23_apb0_setup);
+CLK_OF_DECLARE_DRIVER(sun8i_a23_apb0, "allwinner,sun8i-a23-apb0-clk",
+		      sun8i_a23_apb0_setup);
 
 static int sun8i_a23_apb0_clk_probe(struct platform_device *pdev)
 {
-- 
2.8.1

[toc] | [prev] | [next] | [standalone]


#1437177 — [PATCH v5 7/8] clk: fixed-factor: Convert into a module platform driver

FromRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Date2016-07-05 18:30 +0200
Subject[PATCH v5 7/8] clk: fixed-factor: Convert into a module platform driver
Message-ID<rRBov-5cR-43@gated-at.bofh.it>
In reply to#1437172
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>
---
 drivers/clk/clk-fixed-factor.c | 72 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 67 insertions(+), 5 deletions(-)

diff --git a/drivers/clk/clk-fixed-factor.c b/drivers/clk/clk-fixed-factor.c
index 4db3be214077..3fc14d425fba 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
@@ -150,24 +151,25 @@ static const struct of_device_id set_rate_parent_matches[] = {
 /**
  * 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;
 	unsigned long flags = 0;
 	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);
@@ -178,10 +180,70 @@ void __init of_fixed_factor_clk_setup(struct device_node *node)
 
 	clk = clk_register_fixed_factor(NULL, clk_name, parent_name, flags,
 					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);
 }
 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;
+
+	/*
+	 * This function is not executed when of_fixed_factor_clk_setup
+	 * succeeded.
+	 */
+
+	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

[toc] | [prev] | [next] | [standalone]


#1437179 — [PATCH v5 4/8] clk: sunxi: mod0: Use new macro CLK_OF_DECLARE_DRIVER

FromRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Date2016-07-05 18:30 +0200
Subject[PATCH v5 4/8] clk: sunxi: mod0: Use new macro CLK_OF_DECLARE_DRIVER
Message-ID<rRBov-5cR-49@gated-at.bofh.it>
In reply to#1437172
This driver initializes a clock provider via sun4i_a10_mod0_setup
and then continues the initialization on sun4i_a10_mod0_clk_probe.

Use the new macro to notify the clk subsystem about this behaviour.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 drivers/clk/sunxi/clk-mod0.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/sunxi/clk-mod0.c b/drivers/clk/sunxi/clk-mod0.c
index b38d71cec74c..e54266cc1c51 100644
--- a/drivers/clk/sunxi/clk-mod0.c
+++ b/drivers/clk/sunxi/clk-mod0.c
@@ -91,7 +91,8 @@ static void __init sun4i_a10_mod0_setup(struct device_node *node)
 	sunxi_factors_register(node, &sun4i_a10_mod0_data,
 			       &sun4i_a10_mod0_lock, reg);
 }
-CLK_OF_DECLARE(sun4i_a10_mod0, "allwinner,sun4i-a10-mod0-clk", sun4i_a10_mod0_setup);
+CLK_OF_DECLARE_DRIVER(sun4i_a10_mod0, "allwinner,sun4i-a10-mod0-clk",
+		      sun4i_a10_mod0_setup);
 
 static int sun4i_a10_mod0_clk_probe(struct platform_device *pdev)
 {
-- 
2.8.1

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web