Commit 522f88da authored by Mark Brown's avatar Mark Brown

ASoC: simple-card: sync support

Merge series from Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>:

We have simple-card / audio-graph / audio-graph2, basically these supports
same feature but is using different DT style.

Because we are using 3 drivers, some feature was added to one driver,
but other drivers doesn't have it. This patch set try to sync it on these
3 drivers.
parents 9d52d7ea c4cfe113
......@@ -197,7 +197,7 @@ int graph_util_is_ports0(struct device_node *port);
int graph_util_parse_dai(struct device *dev, struct device_node *ep,
struct snd_soc_dai_link_component *dlc, int *is_single_link);
int graph_util_parse_link_direction(struct device_node *np,
void graph_util_parse_link_direction(struct device_node *np,
bool *is_playback_only, bool *is_capture_only);
#ifdef DEBUG
......
......@@ -19,6 +19,18 @@
#define DPCM_SELECTABLE 1
#define ep_to_port(ep) of_get_parent(ep)
static struct device_node *port_to_ports(struct device_node *port)
{
struct device_node *ports = of_get_parent(port);
if (!of_node_name_eq(ports, "ports")) {
of_node_put(ports);
return NULL;
}
return ports;
}
static int graph_outdrv_event(struct snd_soc_dapm_widget *w,
struct snd_kcontrol *kcontrol,
int event)
......@@ -68,13 +80,12 @@ static void graph_parse_convert(struct device *dev,
struct simple_util_data *adata)
{
struct device_node *top = dev->of_node;
struct device_node *port = of_get_parent(ep);
struct device_node *ports = of_get_parent(port);
struct device_node *port = ep_to_port(ep);
struct device_node *ports = port_to_ports(port);
struct device_node *node = of_graph_get_port_parent(ep);
simple_util_parse_convert(top, NULL, adata);
if (of_node_name_eq(ports, "ports"))
simple_util_parse_convert(ports, NULL, adata);
simple_util_parse_convert(ports, NULL, adata);
simple_util_parse_convert(port, NULL, adata);
simple_util_parse_convert(ep, NULL, adata);
......@@ -83,30 +94,12 @@ static void graph_parse_convert(struct device *dev,
of_node_put(node);
}
static void graph_parse_mclk_fs(struct device_node *top,
struct device_node *ep,
struct simple_dai_props *props)
{
struct device_node *port = of_get_parent(ep);
struct device_node *ports = of_get_parent(port);
of_property_read_u32(top, "mclk-fs", &props->mclk_fs);
if (of_node_name_eq(ports, "ports"))
of_property_read_u32(ports, "mclk-fs", &props->mclk_fs);
of_property_read_u32(port, "mclk-fs", &props->mclk_fs);
of_property_read_u32(ep, "mclk-fs", &props->mclk_fs);
of_node_put(port);
of_node_put(ports);
}
static int graph_parse_node(struct simple_util_priv *priv,
struct device_node *ep,
struct link_info *li,
int *cpu)
{
struct device *dev = simple_priv_to_dev(priv);
struct device_node *top = dev->of_node;
struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link);
struct snd_soc_dai_link_component *dlc;
......@@ -121,8 +114,6 @@ static int graph_parse_node(struct simple_util_priv *priv,
dai = simple_props_to_dai_codec(dai_props, 0);
}
graph_parse_mclk_fs(top, ep, dai_props);
ret = graph_util_parse_dai(dev, ep, dlc, cpu);
if (ret < 0)
return ret;
......@@ -139,26 +130,57 @@ static int graph_parse_node(struct simple_util_priv *priv,
}
static int graph_link_init(struct simple_util_priv *priv,
struct device_node *cpu_ep,
struct device_node *codec_ep,
struct device_node *ep_cpu,
struct device_node *ep_codec,
struct link_info *li,
char *name)
{
struct device *dev = simple_priv_to_dev(priv);
struct device_node *top = dev->of_node;
struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link);
struct device_node *port_cpu = ep_to_port(ep_cpu);
struct device_node *port_codec = ep_to_port(ep_codec);
struct device_node *ports_cpu = port_to_ports(port_cpu);
struct device_node *ports_codec = port_to_ports(port_codec);
bool playback_only = 0, capture_only = 0;
int ret;
ret = simple_util_parse_daifmt(dev, cpu_ep, codec_ep,
ret = simple_util_parse_daifmt(dev, ep_cpu, ep_codec,
NULL, &dai_link->dai_fmt);
if (ret < 0)
return ret;
goto init_end;
graph_util_parse_link_direction(top, &playback_only, &capture_only);
graph_util_parse_link_direction(port_cpu, &playback_only, &capture_only);
graph_util_parse_link_direction(port_codec, &playback_only, &capture_only);
graph_util_parse_link_direction(ep_cpu, &playback_only, &capture_only);
graph_util_parse_link_direction(ep_codec, &playback_only, &capture_only);
of_property_read_u32(top, "mclk-fs", &dai_props->mclk_fs);
of_property_read_u32(ports_cpu, "mclk-fs", &dai_props->mclk_fs);
of_property_read_u32(ports_codec, "mclk-fs", &dai_props->mclk_fs);
of_property_read_u32(port_cpu, "mclk-fs", &dai_props->mclk_fs);
of_property_read_u32(port_codec, "mclk-fs", &dai_props->mclk_fs);
of_property_read_u32(ep_cpu, "mclk-fs", &dai_props->mclk_fs);
of_property_read_u32(ep_codec, "mclk-fs", &dai_props->mclk_fs);
dai_link->playback_only = playback_only;
dai_link->capture_only = capture_only;
dai_link->init = simple_util_dai_init;
dai_link->ops = &graph_ops;
if (priv->ops)
dai_link->ops = priv->ops;
return simple_util_set_dailink_name(dev, dai_link, name);
ret = simple_util_set_dailink_name(dev, dai_link, name);
init_end:
of_node_put(ports_cpu);
of_node_put(ports_codec);
of_node_put(port_cpu);
of_node_put(port_codec);
return ret;
}
static int graph_dai_link_of_dpcm(struct simple_util_priv *priv,
......@@ -231,14 +253,11 @@ static int graph_dai_link_of_dpcm(struct simple_util_priv *priv,
"be.%pOFP.%s", codecs->of_node, codecs->dai_name);
/* check "prefix" from top node */
port = of_get_parent(ep);
ports = of_get_parent(port);
snd_soc_of_parse_node_prefix(top, cconf, codecs->of_node,
"prefix");
if (of_node_name_eq(ports, "ports"))
snd_soc_of_parse_node_prefix(ports, cconf, codecs->of_node, "prefix");
snd_soc_of_parse_node_prefix(port, cconf, codecs->of_node,
"prefix");
port = ep_to_port(ep);
ports = port_to_ports(port);
snd_soc_of_parse_node_prefix(top, cconf, codecs->of_node, "prefix");
snd_soc_of_parse_node_prefix(ports, cconf, codecs->of_node, "prefix");
snd_soc_of_parse_node_prefix(port, cconf, codecs->of_node, "prefix");
of_node_put(ports);
of_node_put(port);
......@@ -350,7 +369,7 @@ static int __graph_for_each_link(struct simple_util_priv *priv,
/* get codec */
codec_ep = of_graph_get_remote_endpoint(cpu_ep);
codec_port = of_get_parent(codec_ep);
codec_port = ep_to_port(codec_ep);
/* get convert-xxx property */
memset(&adata, 0, sizeof(adata));
......
This diff is collapsed.
......@@ -60,6 +60,9 @@ void simple_util_parse_convert(struct device_node *np,
{
char prop[128];
if (!np)
return;
if (!prefix)
prefix = "";
......@@ -1140,22 +1143,16 @@ int graph_util_parse_dai(struct device *dev, struct device_node *ep,
}
EXPORT_SYMBOL_GPL(graph_util_parse_dai);
int graph_util_parse_link_direction(struct device_node *np,
void graph_util_parse_link_direction(struct device_node *np,
bool *playback_only, bool *capture_only)
{
bool is_playback_only = false;
bool is_capture_only = false;
is_playback_only = of_property_read_bool(np, "playback-only");
is_capture_only = of_property_read_bool(np, "capture-only");
if (is_playback_only && is_capture_only)
return -EINVAL;
*playback_only = is_playback_only;
*capture_only = is_capture_only;
bool is_playback_only = of_property_read_bool(np, "playback-only");
bool is_capture_only = of_property_read_bool(np, "capture-only");
return 0;
if (is_playback_only)
*playback_only = is_playback_only;
if (is_capture_only)
*capture_only = is_capture_only;
}
EXPORT_SYMBOL_GPL(graph_util_parse_link_direction);
......
......@@ -129,24 +129,6 @@ static void simple_parse_convert(struct device *dev,
of_node_put(node);
}
static void simple_parse_mclk_fs(struct device_node *top,
struct device_node *np,
struct simple_dai_props *props,
char *prefix)
{
struct device_node *node = of_get_parent(np);
char prop[128];
snprintf(prop, sizeof(prop), "%smclk-fs", PREFIX);
of_property_read_u32(top, prop, &props->mclk_fs);
snprintf(prop, sizeof(prop), "%smclk-fs", prefix);
of_property_read_u32(node, prop, &props->mclk_fs);
of_property_read_u32(np, prop, &props->mclk_fs);
of_node_put(node);
}
static int simple_parse_node(struct simple_util_priv *priv,
struct device_node *np,
struct link_info *li,
......@@ -154,7 +136,6 @@ static int simple_parse_node(struct simple_util_priv *priv,
int *cpu)
{
struct device *dev = simple_priv_to_dev(priv);
struct device_node *top = dev->of_node;
struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link);
struct snd_soc_dai_link_component *dlc;
......@@ -169,8 +150,6 @@ static int simple_parse_node(struct simple_util_priv *priv,
dai = simple_props_to_dai_codec(dai_props, 0);
}
simple_parse_mclk_fs(top, np, dai_props, prefix);
ret = simple_parse_dai(dev, np, dlc, cpu);
if (ret)
return ret;
......@@ -187,24 +166,49 @@ static int simple_parse_node(struct simple_util_priv *priv,
}
static int simple_link_init(struct simple_util_priv *priv,
struct device_node *node,
struct device_node *cpu,
struct device_node *codec,
struct link_info *li,
char *prefix, char *name)
{
struct device *dev = simple_priv_to_dev(priv);
struct device_node *top = dev->of_node;
struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link);
struct device_node *node = of_get_parent(cpu);
bool playback_only = 0, capture_only = 0;
int ret;
ret = simple_util_parse_daifmt(dev, node, codec,
prefix, &dai_link->dai_fmt);
if (ret < 0)
return 0;
goto init_end;
graph_util_parse_link_direction(top, &playback_only, &capture_only);
graph_util_parse_link_direction(node, &playback_only, &capture_only);
graph_util_parse_link_direction(cpu, &playback_only, &capture_only);
graph_util_parse_link_direction(codec, &playback_only, &capture_only);
of_property_read_u32(top, "mclk-fs", &dai_props->mclk_fs);
of_property_read_u32(top, PREFIX "mclk-fs", &dai_props->mclk_fs);
of_property_read_u32(node, "mclk-fs", &dai_props->mclk_fs);
of_property_read_u32(node, PREFIX "mclk-fs", &dai_props->mclk_fs);
of_property_read_u32(cpu, "mclk-fs", &dai_props->mclk_fs);
of_property_read_u32(cpu, PREFIX "mclk-fs", &dai_props->mclk_fs);
of_property_read_u32(codec, "mclk-fs", &dai_props->mclk_fs);
of_property_read_u32(codec, PREFIX "mclk-fs", &dai_props->mclk_fs);
dai_link->playback_only = playback_only;
dai_link->capture_only = capture_only;
dai_link->init = simple_util_dai_init;
dai_link->ops = &simple_ops;
return simple_util_set_dailink_name(dev, dai_link, name);
ret = simple_util_set_dailink_name(dev, dai_link, name);
init_end:
of_node_put(node);
return ret;
}
static int simple_dai_link_of_dpcm(struct simple_util_priv *priv,
......@@ -278,7 +282,7 @@ static int simple_dai_link_of_dpcm(struct simple_util_priv *priv,
snd_soc_dai_link_set_capabilities(dai_link);
ret = simple_link_init(priv, node, codec, li, prefix, dai_name);
ret = simple_link_init(priv, np, codec, li, prefix, dai_name);
out_put_node:
li->link++;
......@@ -336,7 +340,7 @@ static int simple_dai_link_of(struct simple_util_priv *priv,
simple_util_canonicalize_cpu(cpus, single_cpu);
simple_util_canonicalize_platform(platforms, cpus);
ret = simple_link_init(priv, node, codec, li, prefix, dai_name);
ret = simple_link_init(priv, cpu, codec, li, prefix, dai_name);
dai_link_of_err:
of_node_put(plat);
......
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