diff mbox

[2/3] clk: fixed-factor: Convert into a module platform driver

Message ID 1465381201-11537-3-git-send-email-ricardo.ribalda@gmail.com (mailing list archive)
State Superseded, archived
Delegated to: Stephen Boyd
Headers show

Commit Message

Ricardo Ribalda Delgado June 8, 2016, 10:20 a.m. UTC
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 | 66 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 63 insertions(+), 3 deletions(-)

Comments

Stephen Boyd June 16, 2016, 12:47 a.m. UTC | #1
On 06/08, Ricardo Ribalda Delgado wrote:
>  	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);
> @@ -171,8 +172,67 @@ void __init of_fixed_factor_clk_setup(struct device_node *node)
>  					mult, div);
>  	if (!IS_ERR(clk))
>  		of_clk_add_provider(node, of_clk_src_simple_get, clk);

What if this fails now?

> +
> +	return clk;
> +}
> +
[..]
> +
> +static const struct of_device_id of_fixed_factor_clk_ids[] = {
> +	{
> +		.compatible = "fixed-factor-clock",
> +	},
> +	{ },
> +};

Nitpick: Do it this way:

  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,
> +};
> +
> +module_platform_driver(of_fixed_factor_clk_driver);
> +

This should be builtin_platform_driver() because these are obj-y
right now.
diff mbox

Patch

diff --git a/drivers/clk/clk-fixed-factor.c b/drivers/clk/clk-fixed-factor.c
index 75cd6c792cb8..6dfce84ef10c 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,7 +146,7 @@  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;
@@ -155,13 +156,13 @@  void __init of_fixed_factor_clk_setup(struct device_node *node)
 	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);
@@ -171,8 +172,67 @@  void __init of_fixed_factor_clk_setup(struct device_node *node)
 					mult, div);
 	if (!IS_ERR(clk))
 		of_clk_add_provider(node, of_clk_src_simple_get, clk);
+
+	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,
+};
+
+module_platform_driver(of_fixed_factor_clk_driver);
+
 #endif