Commit 971451b3 authored by Ricardo Ribalda Delgado's avatar Ricardo Ribalda Delgado Committed by Stephen Boyd

clk: fixed-factor: Convert into a module platform driver

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: default avatarRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>
[sboyd@codeaurora.org: Make new private function static, don't
check clk for NULL when unregistering in driver remove]
Signed-off-by: default avatarStephen Boyd <sboyd@codeaurora.org>
parent 989eafd0
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/platform_device.h>
/* /*
* DOC: basic fixed multiplier and divider clock that cannot gate * DOC: basic fixed multiplier and divider clock that cannot gate
...@@ -147,27 +148,25 @@ static const struct of_device_id set_rate_parent_matches[] = { ...@@ -147,27 +148,25 @@ static const struct of_device_id set_rate_parent_matches[] = {
{ /* Sentinel */ }, { /* Sentinel */ },
}; };
/** static struct clk *_of_fixed_factor_clk_setup(struct device_node *node)
* 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 *clk; struct clk *clk;
const char *clk_name = node->name; const char *clk_name = node->name;
const char *parent_name; const char *parent_name;
unsigned long flags = 0; unsigned long flags = 0;
u32 div, mult; u32 div, mult;
int ret;
if (of_property_read_u32(node, "clock-div", &div)) { if (of_property_read_u32(node, "clock-div", &div)) {
pr_err("%s Fixed factor clock <%s> must have a clock-div property\n", pr_err("%s Fixed factor clock <%s> must have a clock-div property\n",
__func__, node->name); __func__, node->name);
return; return ERR_PTR(-EIO);
} }
if (of_property_read_u32(node, "clock-mult", &mult)) { if (of_property_read_u32(node, "clock-mult", &mult)) {
pr_err("%s Fixed factor clock <%s> must have a clock-mult property\n", pr_err("%s Fixed factor clock <%s> must have a clock-mult property\n",
__func__, node->name); __func__, node->name);
return; return ERR_PTR(-EIO);
} }
of_property_read_string(node, "clock-output-names", &clk_name); of_property_read_string(node, "clock-output-names", &clk_name);
...@@ -178,10 +177,68 @@ void __init of_fixed_factor_clk_setup(struct device_node *node) ...@@ -178,10 +177,68 @@ void __init of_fixed_factor_clk_setup(struct device_node *node)
clk = clk_register_fixed_factor(NULL, clk_name, parent_name, flags, clk = clk_register_fixed_factor(NULL, clk_name, parent_name, flags,
mult, div); mult, div);
if (!IS_ERR(clk)) if (IS_ERR(clk))
of_clk_add_provider(node, of_clk_src_simple_get, 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;
}
/**
* of_fixed_factor_clk_setup() - Setup function for simple fixed factor clock
*/
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); EXPORT_SYMBOL_GPL(of_fixed_factor_clk_setup);
CLK_OF_DECLARE(fixed_factor_clk, "fixed-factor-clock", CLK_OF_DECLARE(fixed_factor_clk, "fixed-factor-clock",
of_fixed_factor_clk_setup); of_fixed_factor_clk_setup);
static int of_fixed_factor_clk_remove(struct platform_device *pdev)
{
struct clk *clk = platform_get_drvdata(pdev);
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 #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment