@@ -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
@@ -142,26 +143,35 @@ void clk_hw_unregister_fixed_factor(struct clk_hw *hw)
EXPORT_SYMBOL_GPL(clk_hw_unregister_fixed_factor);
#ifdef CONFIG_OF
+
+int of_fixed_factor_clk_remove(struct clk *clk)
+{
+ clk_unregister_fixed_factor(clk);
+
+ return 0;
+}
+
/**
* 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 +179,24 @@ 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 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);
+
+CLK_OF_DECLARE_DRIVER(fixed_factor_clk, "fixed-factor-clock",
+ _of_fixed_factor_clk_setup, of_fixed_factor_clk_remove);
#endif
@@ -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
@@ -146,18 +147,26 @@ void clk_unregister_fixed_rate(struct clk *clk)
EXPORT_SYMBOL_GPL(clk_unregister_fixed_rate);
#ifdef CONFIG_OF
+
+int of_fixed_clk_remove(struct clk *clk)
+{
+ clk_unregister_fixed_rate(clk);
+ return 0;
+}
+
/**
* 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 +174,24 @@ 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);
+
+CLK_OF_DECLARE_DRIVER(fixed_clk, "fixed-clock", _of_fixed_clk_setup,
+ of_fixed_clk_remove);
#endif
@@ -13,6 +13,7 @@
#include <linux/io.h>
#include <linux/of.h>
+#include <linux/stringify.h>
#ifdef CONFIG_COMMON_CLK
@@ -777,6 +778,55 @@ extern struct of_device_id __clk_of_table;
#define CLK_OF_DECLARE(name, compat, fn) OF_DECLARE_1(clk, name, compat, fn)
+#define CLK_OF_DECLARE_DRIVER(cname, compat, f_setup, f_remove) \
+ void cname##_init_clk_setup(struct device_node *node) \
+ { \
+ if (!f_setup(node)) \
+ of_node_set_flag(node, OF_POPULATED); \
+ } \
+ EXPORT_SYMBOL_GPL(cname##_init_clk_setup); \
+ CLK_OF_DECLARE(cname, compat, cname##_init_clk_setup); \
+ \
+ static int cname##_of_clk_remove(struct platform_device *pdev) \
+ { \
+ struct clk *clk = platform_get_drvdata(pdev); \
+ \
+ if (clk) \
+ return f_remove(clk); \
+ \
+ return 0; \
+ } \
+ \
+ static int cname##_of_clk_probe(struct platform_device *pdev) \
+ { \
+ struct clk *clk; \
+ \
+ clk = f_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 cname##_ids[] = { \
+ { .compatible = compat }, \
+ { }, \
+ }; \
+ MODULE_DEVICE_TABLE(of, cname##_ids); \
+ \
+ static struct platform_driver cname##_driver = { \
+ .driver = { \
+ .name = __stringify(cname), \
+ .of_match_table = cname##_ids, \
+ }, \
+ .probe = cname##_of_clk_probe, \
+ .remove = cname##_of_clk_remove, \
+ }; \
+ module_platform_driver(cname##_driver);
+
#ifdef CONFIG_OF
int of_clk_add_provider(struct device_node *np,
struct clk *(*clk_src_get)(struct of_phandle_args *args,