Skip to content

Commit 6acab96

Browse files
jailuthrabebarino
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent daecb57 commit 6acab96

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

drivers/clk/keystone/syscon-clk.c

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
*/
55

66
#include <linux/clk-provider.h>
7+
#include <linux/kernel.h>
78
#include <linux/mfd/syscon.h>
89
#include <linux/module.h>
910
#include <linux/platform_device.h>
1011
#include <linux/regmap.h>
12+
#include <linux/slab.h>
1113

1214
struct ti_syscon_gate_clk_priv {
1315
struct clk_hw hw;
@@ -61,28 +63,42 @@ static const struct clk_ops ti_syscon_gate_clk_ops = {
6163

6264
static struct clk_hw
6365
*ti_syscon_gate_clk_register(struct device *dev, struct regmap *regmap,
66+
const char *parent_name,
6467
const struct ti_syscon_gate_clk_data *data)
6568
{
6669
struct ti_syscon_gate_clk_priv *priv;
6770
struct clk_init_data init;
71+
char *name = NULL;
6872
int ret;
6973

7074
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
7175
if (!priv)
7276
return ERR_PTR(-ENOMEM);
7377

74-
init.name = data->name;
7578
init.ops = &ti_syscon_gate_clk_ops;
76-
init.parent_names = NULL;
77-
init.num_parents = 0;
78-
init.flags = 0;
79+
if (parent_name) {
80+
name = kasprintf(GFP_KERNEL, "%s:%s", data->name, parent_name);
81+
init.name = name;
82+
init.parent_names = &parent_name;
83+
init.num_parents = 1;
84+
init.flags = CLK_SET_RATE_PARENT;
85+
} else {
86+
init.name = data->name;
87+
init.parent_names = NULL;
88+
init.num_parents = 0;
89+
init.flags = 0;
90+
}
7991

8092
priv->regmap = regmap;
8193
priv->reg = data->offset;
8294
priv->idx = BIT(data->bit_idx);
8395
priv->hw.init = &init;
8496

8597
ret = devm_clk_hw_register(dev, &priv->hw);
98+
99+
if (name)
100+
kfree(init.name);
101+
86102
if (ret)
87103
return ERR_PTR(ret);
88104

@@ -94,8 +110,9 @@ static int ti_syscon_gate_clk_probe(struct platform_device *pdev)
94110
const struct ti_syscon_gate_clk_data *data, *p;
95111
struct clk_hw_onecell_data *hw_data;
96112
struct device *dev = &pdev->dev;
113+
int num_clks, num_parents, i;
114+
const char *parent_name;
97115
struct regmap *regmap;
98-
int num_clks, i;
99116

100117
data = device_get_match_data(dev);
101118
if (!data)
@@ -110,15 +127,24 @@ static int ti_syscon_gate_clk_probe(struct platform_device *pdev)
110127
for (p = data; p->name; p++)
111128
num_clks++;
112129

130+
num_parents = of_clk_get_parent_count(dev->of_node);
131+
if (of_device_is_compatible(dev->of_node, "ti,am62-audio-refclk") &&
132+
num_parents == 0) {
133+
return dev_err_probe(dev, -EINVAL,
134+
"must specify a parent clock\n");
135+
}
136+
113137
hw_data = devm_kzalloc(dev, struct_size(hw_data, hws, num_clks),
114138
GFP_KERNEL);
115139
if (!hw_data)
116140
return -ENOMEM;
117141

118142
hw_data->num = num_clks;
119143

144+
parent_name = of_clk_get_parent_name(dev->of_node, 0);
120145
for (i = 0; i < num_clks; i++) {
121146
hw_data->hws[i] = ti_syscon_gate_clk_register(dev, regmap,
147+
parent_name,
122148
&data[i]);
123149
if (IS_ERR(hw_data->hws[i]))
124150
dev_warn(dev, "failed to register %s\n",
@@ -166,6 +192,11 @@ static const struct ti_syscon_gate_clk_data am62_clk_data[] = {
166192
{ /* Sentinel */ },
167193
};
168194

195+
static const struct ti_syscon_gate_clk_data am62_audio_clk_data[] = {
196+
TI_SYSCON_CLK_GATE("audio_refclk", 0x0, 15),
197+
{ /* Sentinel */ },
198+
};
199+
169200
static const struct of_device_id ti_syscon_gate_clk_ids[] = {
170201
{
171202
.compatible = "ti,am654-ehrpwm-tbclk",
@@ -179,6 +210,10 @@ static const struct of_device_id ti_syscon_gate_clk_ids[] = {
179210
.compatible = "ti,am62-epwm-tbclk",
180211
.data = &am62_clk_data,
181212
},
213+
{
214+
.compatible = "ti,am62-audio-refclk",
215+
.data = &am62_audio_clk_data,
216+
},
182217
{ }
183218
};
184219
MODULE_DEVICE_TABLE(of, ti_syscon_gate_clk_ids);

0 commit comments

Comments
 (0)