Commit f03566d0 authored by Jerome Brunet's avatar Jerome Brunet Committed by Neil Armstrong

clk: meson: axg-audio: use the clk input helper function

Rework the axg audio clock controller to use the new clk-input helper
function.
Signed-off-by: default avatarJerome Brunet <jbrunet@baylibre.com>
Reviewed-by: default avatarNeil Armstrong <narmstrong@baylibre.com>
Signed-off-by: default avatarNeil Armstrong <narmstrong@baylibre.com>
[narmstrong: fixed pclk input clock name to axg_audio_pclk]
Link: http://lkml.kernel.org/r/20181204165819.21541-3-jbrunet@baylibre.com
parent e456e6a1
...@@ -631,22 +631,23 @@ static struct clk_regmap *const axg_audio_clk_regmaps[] = { ...@@ -631,22 +631,23 @@ static struct clk_regmap *const axg_audio_clk_regmaps[] = {
&axg_tdmout_c_lrclk, &axg_tdmout_c_lrclk,
}; };
static struct clk *devm_clk_get_enable(struct device *dev, char *id) static int devm_clk_get_enable(struct device *dev, char *id)
{ {
struct clk *clk; struct clk *clk;
int ret; int ret;
clk = devm_clk_get(dev, id); clk = devm_clk_get(dev, id);
if (IS_ERR(clk)) { if (IS_ERR(clk)) {
if (PTR_ERR(clk) != -EPROBE_DEFER) ret = PTR_ERR(clk);
if (ret != -EPROBE_DEFER)
dev_err(dev, "failed to get %s", id); dev_err(dev, "failed to get %s", id);
return clk; return ret;
} }
ret = clk_prepare_enable(clk); ret = clk_prepare_enable(clk);
if (ret) { if (ret) {
dev_err(dev, "failed to enable %s", id); dev_err(dev, "failed to enable %s", id);
return ERR_PTR(ret); return ret;
} }
ret = devm_add_action_or_reset(dev, ret = devm_add_action_or_reset(dev,
...@@ -654,74 +655,40 @@ static struct clk *devm_clk_get_enable(struct device *dev, char *id) ...@@ -654,74 +655,40 @@ static struct clk *devm_clk_get_enable(struct device *dev, char *id)
clk); clk);
if (ret) { if (ret) {
dev_err(dev, "failed to add reset action on %s", id); dev_err(dev, "failed to add reset action on %s", id);
return ERR_PTR(ret); return ret;
} }
return clk; return 0;
}
static const struct clk_ops axg_clk_no_ops = {};
static struct clk_hw *axg_clk_hw_register_bypass(struct device *dev,
const char *name,
const char *parent_name)
{
struct clk_hw *hw;
struct clk_init_data init;
char *clk_name;
int ret;
hw = devm_kzalloc(dev, sizeof(*hw), GFP_KERNEL);
if (!hw)
return ERR_PTR(-ENOMEM);
clk_name = kasprintf(GFP_KERNEL, "axg_%s", name);
if (!clk_name)
return ERR_PTR(-ENOMEM);
init.name = clk_name;
init.ops = &axg_clk_no_ops;
init.flags = 0;
init.parent_names = parent_name ? &parent_name : NULL;
init.num_parents = parent_name ? 1 : 0;
hw->init = &init;
ret = devm_clk_hw_register(dev, hw);
kfree(clk_name);
return ret ? ERR_PTR(ret) : hw;
} }
static int axg_register_clk_hw_input(struct device *dev, static int axg_register_clk_hw_input(struct device *dev,
const char *name, const char *name,
unsigned int clkid) unsigned int clkid)
{ {
struct clk *parent_clk = devm_clk_get(dev, name); char *clk_name;
struct clk_hw *hw = NULL; struct clk_hw *hw;
int err = 0;
if (IS_ERR(parent_clk)) { clk_name = kasprintf(GFP_KERNEL, "axg_%s", name);
int err = PTR_ERR(parent_clk); if (!clk_name)
return -ENOMEM;
hw = meson_clk_hw_register_input(dev, name, clk_name, 0);
if (IS_ERR(hw)) {
/* It is ok if an input clock is missing */ /* It is ok if an input clock is missing */
if (err == -ENOENT) { if (PTR_ERR(hw) == -ENOENT) {
dev_dbg(dev, "%s not provided", name); dev_dbg(dev, "%s not provided", name);
} else { } else {
err = PTR_ERR(hw);
if (err != -EPROBE_DEFER) if (err != -EPROBE_DEFER)
dev_err(dev, "failed to get %s clock", name); dev_err(dev, "failed to get %s clock", name);
return err;
} }
} else { } else {
hw = axg_clk_hw_register_bypass(dev, name, axg_audio_hw_onecell_data.hws[clkid] = hw;
__clk_get_name(parent_clk));
}
if (IS_ERR(hw)) {
dev_err(dev, "failed to register %s clock", name);
return PTR_ERR(hw);
} }
axg_audio_hw_onecell_data.hws[clkid] = hw; kfree(clk_name);
return 0; return err;
} }
static int axg_register_clk_hw_inputs(struct device *dev, static int axg_register_clk_hw_inputs(struct device *dev,
...@@ -759,7 +726,6 @@ static int axg_audio_clkc_probe(struct platform_device *pdev) ...@@ -759,7 +726,6 @@ static int axg_audio_clkc_probe(struct platform_device *pdev)
struct regmap *map; struct regmap *map;
struct resource *res; struct resource *res;
void __iomem *regs; void __iomem *regs;
struct clk *clk;
struct clk_hw *hw; struct clk_hw *hw;
int ret, i; int ret, i;
...@@ -775,9 +741,9 @@ static int axg_audio_clkc_probe(struct platform_device *pdev) ...@@ -775,9 +741,9 @@ static int axg_audio_clkc_probe(struct platform_device *pdev)
} }
/* Get the mandatory peripheral clock */ /* Get the mandatory peripheral clock */
clk = devm_clk_get_enable(dev, "pclk"); ret = devm_clk_get_enable(dev, "pclk");
if (IS_ERR(clk)) if (ret)
return PTR_ERR(clk); return ret;
ret = device_reset(dev); ret = device_reset(dev);
if (ret) { if (ret) {
...@@ -786,8 +752,7 @@ static int axg_audio_clkc_probe(struct platform_device *pdev) ...@@ -786,8 +752,7 @@ static int axg_audio_clkc_probe(struct platform_device *pdev)
} }
/* Register the peripheral input clock */ /* Register the peripheral input clock */
hw = axg_clk_hw_register_bypass(dev, "audio_pclk", hw = meson_clk_hw_register_input(dev, "pclk", "axg_audio_pclk", 0);
__clk_get_name(clk));
if (IS_ERR(hw)) if (IS_ERR(hw))
return PTR_ERR(hw); return PTR_ERR(hw);
......
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