clk: keystone: syscon-clk: Add support for audio refclk
TI's AM62 SoC can optionally provide two audio reference clocks (AUDIO_REFCLKx) to external peripherals. By default this reference clock is looped-back inside the SoC to a mux that goes to McASP AHCLK, but can optionally be enabled as an output to peripherals outside the SoC by setting a bit through CTRL_MMR registers. This bit only controls the direction of the clock, while the parent is a muxed input from sci-clk [1] which may be a configurable PLL or a master clock from one of the McASP instances. Link: http://downloads.ti.com/tisci/esd/latest/5_soc_doc/am62x/clocks.html#clocks-for-board0-device [1] Signed-off-by: Jai Luthra <j-luthra@ti.com> Link: https://lore.kernel.org/r/20230515-refclk-v3-2-37c0b550f406@ti.com Signed-off-by: Stephen Boyd <sboyd@kernel.org>
This commit is contained in:
parent
daecb57cc4
commit
6acab96ee3
1 changed files with 40 additions and 5 deletions
|
@ -4,10 +4,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <linux/clk-provider.h>
|
#include <linux/clk-provider.h>
|
||||||
|
#include <linux/kernel.h>
|
||||||
#include <linux/mfd/syscon.h>
|
#include <linux/mfd/syscon.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
#include <linux/regmap.h>
|
#include <linux/regmap.h>
|
||||||
|
#include <linux/slab.h>
|
||||||
|
|
||||||
struct ti_syscon_gate_clk_priv {
|
struct ti_syscon_gate_clk_priv {
|
||||||
struct clk_hw hw;
|
struct clk_hw hw;
|
||||||
|
@ -61,21 +63,31 @@ static const struct clk_ops ti_syscon_gate_clk_ops = {
|
||||||
|
|
||||||
static struct clk_hw
|
static struct clk_hw
|
||||||
*ti_syscon_gate_clk_register(struct device *dev, struct regmap *regmap,
|
*ti_syscon_gate_clk_register(struct device *dev, struct regmap *regmap,
|
||||||
|
const char *parent_name,
|
||||||
const struct ti_syscon_gate_clk_data *data)
|
const struct ti_syscon_gate_clk_data *data)
|
||||||
{
|
{
|
||||||
struct ti_syscon_gate_clk_priv *priv;
|
struct ti_syscon_gate_clk_priv *priv;
|
||||||
struct clk_init_data init;
|
struct clk_init_data init;
|
||||||
|
char *name = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
|
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
|
||||||
if (!priv)
|
if (!priv)
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
init.name = data->name;
|
|
||||||
init.ops = &ti_syscon_gate_clk_ops;
|
init.ops = &ti_syscon_gate_clk_ops;
|
||||||
init.parent_names = NULL;
|
if (parent_name) {
|
||||||
init.num_parents = 0;
|
name = kasprintf(GFP_KERNEL, "%s:%s", data->name, parent_name);
|
||||||
init.flags = 0;
|
init.name = name;
|
||||||
|
init.parent_names = &parent_name;
|
||||||
|
init.num_parents = 1;
|
||||||
|
init.flags = CLK_SET_RATE_PARENT;
|
||||||
|
} else {
|
||||||
|
init.name = data->name;
|
||||||
|
init.parent_names = NULL;
|
||||||
|
init.num_parents = 0;
|
||||||
|
init.flags = 0;
|
||||||
|
}
|
||||||
|
|
||||||
priv->regmap = regmap;
|
priv->regmap = regmap;
|
||||||
priv->reg = data->offset;
|
priv->reg = data->offset;
|
||||||
|
@ -83,6 +95,10 @@ static struct clk_hw
|
||||||
priv->hw.init = &init;
|
priv->hw.init = &init;
|
||||||
|
|
||||||
ret = devm_clk_hw_register(dev, &priv->hw);
|
ret = devm_clk_hw_register(dev, &priv->hw);
|
||||||
|
|
||||||
|
if (name)
|
||||||
|
kfree(init.name);
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
return ERR_PTR(ret);
|
return ERR_PTR(ret);
|
||||||
|
|
||||||
|
@ -94,8 +110,9 @@ static int ti_syscon_gate_clk_probe(struct platform_device *pdev)
|
||||||
const struct ti_syscon_gate_clk_data *data, *p;
|
const struct ti_syscon_gate_clk_data *data, *p;
|
||||||
struct clk_hw_onecell_data *hw_data;
|
struct clk_hw_onecell_data *hw_data;
|
||||||
struct device *dev = &pdev->dev;
|
struct device *dev = &pdev->dev;
|
||||||
|
int num_clks, num_parents, i;
|
||||||
|
const char *parent_name;
|
||||||
struct regmap *regmap;
|
struct regmap *regmap;
|
||||||
int num_clks, i;
|
|
||||||
|
|
||||||
data = device_get_match_data(dev);
|
data = device_get_match_data(dev);
|
||||||
if (!data)
|
if (!data)
|
||||||
|
@ -110,6 +127,13 @@ static int ti_syscon_gate_clk_probe(struct platform_device *pdev)
|
||||||
for (p = data; p->name; p++)
|
for (p = data; p->name; p++)
|
||||||
num_clks++;
|
num_clks++;
|
||||||
|
|
||||||
|
num_parents = of_clk_get_parent_count(dev->of_node);
|
||||||
|
if (of_device_is_compatible(dev->of_node, "ti,am62-audio-refclk") &&
|
||||||
|
num_parents == 0) {
|
||||||
|
return dev_err_probe(dev, -EINVAL,
|
||||||
|
"must specify a parent clock\n");
|
||||||
|
}
|
||||||
|
|
||||||
hw_data = devm_kzalloc(dev, struct_size(hw_data, hws, num_clks),
|
hw_data = devm_kzalloc(dev, struct_size(hw_data, hws, num_clks),
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!hw_data)
|
if (!hw_data)
|
||||||
|
@ -117,8 +141,10 @@ static int ti_syscon_gate_clk_probe(struct platform_device *pdev)
|
||||||
|
|
||||||
hw_data->num = num_clks;
|
hw_data->num = num_clks;
|
||||||
|
|
||||||
|
parent_name = of_clk_get_parent_name(dev->of_node, 0);
|
||||||
for (i = 0; i < num_clks; i++) {
|
for (i = 0; i < num_clks; i++) {
|
||||||
hw_data->hws[i] = ti_syscon_gate_clk_register(dev, regmap,
|
hw_data->hws[i] = ti_syscon_gate_clk_register(dev, regmap,
|
||||||
|
parent_name,
|
||||||
&data[i]);
|
&data[i]);
|
||||||
if (IS_ERR(hw_data->hws[i]))
|
if (IS_ERR(hw_data->hws[i]))
|
||||||
dev_warn(dev, "failed to register %s\n",
|
dev_warn(dev, "failed to register %s\n",
|
||||||
|
@ -166,6 +192,11 @@ static const struct ti_syscon_gate_clk_data am62_clk_data[] = {
|
||||||
{ /* Sentinel */ },
|
{ /* Sentinel */ },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const struct ti_syscon_gate_clk_data am62_audio_clk_data[] = {
|
||||||
|
TI_SYSCON_CLK_GATE("audio_refclk", 0x0, 15),
|
||||||
|
{ /* Sentinel */ },
|
||||||
|
};
|
||||||
|
|
||||||
static const struct of_device_id ti_syscon_gate_clk_ids[] = {
|
static const struct of_device_id ti_syscon_gate_clk_ids[] = {
|
||||||
{
|
{
|
||||||
.compatible = "ti,am654-ehrpwm-tbclk",
|
.compatible = "ti,am654-ehrpwm-tbclk",
|
||||||
|
@ -179,6 +210,10 @@ static const struct of_device_id ti_syscon_gate_clk_ids[] = {
|
||||||
.compatible = "ti,am62-epwm-tbclk",
|
.compatible = "ti,am62-epwm-tbclk",
|
||||||
.data = &am62_clk_data,
|
.data = &am62_clk_data,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.compatible = "ti,am62-audio-refclk",
|
||||||
|
.data = &am62_audio_clk_data,
|
||||||
|
},
|
||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
MODULE_DEVICE_TABLE(of, ti_syscon_gate_clk_ids);
|
MODULE_DEVICE_TABLE(of, ti_syscon_gate_clk_ids);
|
||||||
|
|
Loading…
Add table
Reference in a new issue