ASoC: audio-graph: Expose helpers from audio graph
This commit exposes following functions which can be used by a sound card driver based on generic audio graph driver. Idea is vendors can have a thin driver and re-use common stuff from audio graph driver. - graph_card_probe() - graph_parse_of() In doing so a new header file is added for above. The graph_probe() function is simplified by moving more common stuff to graph_parse_of(). Signed-off-by: Sameer Pujar <spujar@nvidia.com> Cc: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Link: https://lore.kernel.org/r/1604329814-24779-8-git-send-email-spujar@nvidia.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
d09c774f2f
commit
e32b100bc6
2 changed files with 66 additions and 45 deletions
16
include/sound/graph_card.h
Normal file
16
include/sound/graph_card.h
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
/* SPDX-License-Identifier: GPL-2.0
|
||||||
|
*
|
||||||
|
* ASoC audio graph card support
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __GRAPH_CARD_H
|
||||||
|
#define __GRAPH_CARD_H
|
||||||
|
|
||||||
|
#include <sound/simple_card_utils.h>
|
||||||
|
|
||||||
|
int graph_card_probe(struct snd_soc_card *card);
|
||||||
|
|
||||||
|
int graph_parse_of(struct asoc_simple_priv *priv, struct device *dev);
|
||||||
|
|
||||||
|
#endif /* __GRAPH_CARD_H */
|
|
@ -18,7 +18,7 @@
|
||||||
#include <linux/of_graph.h>
|
#include <linux/of_graph.h>
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
#include <linux/string.h>
|
#include <linux/string.h>
|
||||||
#include <sound/simple_card_utils.h>
|
#include <sound/graph_card.h>
|
||||||
|
|
||||||
#define DPCM_SELECTABLE 1
|
#define DPCM_SELECTABLE 1
|
||||||
|
|
||||||
|
@ -529,12 +529,34 @@ static int graph_for_each_link(struct asoc_simple_priv *priv,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int graph_parse_of(struct asoc_simple_priv *priv)
|
static void graph_get_dais_count(struct asoc_simple_priv *priv,
|
||||||
|
struct link_info *li);
|
||||||
|
|
||||||
|
int graph_parse_of(struct asoc_simple_priv *priv, struct device *dev)
|
||||||
{
|
{
|
||||||
struct snd_soc_card *card = simple_priv_to_card(priv);
|
struct snd_soc_card *card = simple_priv_to_card(priv);
|
||||||
struct link_info li;
|
struct link_info li;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
card->owner = THIS_MODULE;
|
||||||
|
card->dev = dev;
|
||||||
|
|
||||||
|
memset(&li, 0, sizeof(li));
|
||||||
|
graph_get_dais_count(priv, &li);
|
||||||
|
if (!li.link || !li.dais)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
ret = asoc_simple_init_priv(priv, &li);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
priv->pa_gpio = devm_gpiod_get_optional(dev, "pa", GPIOD_OUT_LOW);
|
||||||
|
if (IS_ERR(priv->pa_gpio)) {
|
||||||
|
ret = PTR_ERR(priv->pa_gpio);
|
||||||
|
dev_err(dev, "failed to get amplifier gpio: %d\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
ret = asoc_simple_parse_widgets(card, NULL);
|
ret = asoc_simple_parse_widgets(card, NULL);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -561,11 +583,32 @@ static int graph_parse_of(struct asoc_simple_priv *priv)
|
||||||
graph_dai_link_of,
|
graph_dai_link_of,
|
||||||
graph_dai_link_of_dpcm);
|
graph_dai_link_of_dpcm);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
return asoc_simple_parse_card_name(card, NULL);
|
ret = asoc_simple_parse_card_name(card, NULL);
|
||||||
|
if (ret < 0)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
snd_soc_card_set_drvdata(card, priv);
|
||||||
|
|
||||||
|
asoc_simple_debug_info(priv);
|
||||||
|
|
||||||
|
ret = devm_snd_soc_register_card(dev, card);
|
||||||
|
if (ret < 0)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
err:
|
||||||
|
asoc_simple_clean_reference(card);
|
||||||
|
|
||||||
|
if (ret != -EPROBE_DEFER)
|
||||||
|
dev_err(dev, "parse error %d\n", ret);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(graph_parse_of);
|
||||||
|
|
||||||
static int graph_count_noml(struct asoc_simple_priv *priv,
|
static int graph_count_noml(struct asoc_simple_priv *priv,
|
||||||
struct device_node *cpu_ep,
|
struct device_node *cpu_ep,
|
||||||
|
@ -662,7 +705,7 @@ static void graph_get_dais_count(struct asoc_simple_priv *priv,
|
||||||
li->link, li->dais, li->conf);
|
li->link, li->dais, li->conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int graph_card_probe(struct snd_soc_card *card)
|
int graph_card_probe(struct snd_soc_card *card)
|
||||||
{
|
{
|
||||||
struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(card);
|
struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(card);
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -677,14 +720,13 @@ static int graph_card_probe(struct snd_soc_card *card)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(graph_card_probe);
|
||||||
|
|
||||||
static int graph_probe(struct platform_device *pdev)
|
static int graph_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct asoc_simple_priv *priv;
|
struct asoc_simple_priv *priv;
|
||||||
struct device *dev = &pdev->dev;
|
struct device *dev = &pdev->dev;
|
||||||
struct snd_soc_card *card;
|
struct snd_soc_card *card;
|
||||||
struct link_info li;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Allocate the private data and the DAI link array */
|
/* Allocate the private data and the DAI link array */
|
||||||
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
|
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
|
||||||
|
@ -692,8 +734,6 @@ static int graph_probe(struct platform_device *pdev)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
card = simple_priv_to_card(priv);
|
card = simple_priv_to_card(priv);
|
||||||
card->owner = THIS_MODULE;
|
|
||||||
card->dev = dev;
|
|
||||||
card->dapm_widgets = graph_dapm_widgets;
|
card->dapm_widgets = graph_dapm_widgets;
|
||||||
card->num_dapm_widgets = ARRAY_SIZE(graph_dapm_widgets);
|
card->num_dapm_widgets = ARRAY_SIZE(graph_dapm_widgets);
|
||||||
card->probe = graph_card_probe;
|
card->probe = graph_card_probe;
|
||||||
|
@ -701,42 +741,7 @@ static int graph_probe(struct platform_device *pdev)
|
||||||
if (of_device_get_match_data(dev))
|
if (of_device_get_match_data(dev))
|
||||||
priv->dpcm_selectable = 1;
|
priv->dpcm_selectable = 1;
|
||||||
|
|
||||||
memset(&li, 0, sizeof(li));
|
return graph_parse_of(priv, dev);
|
||||||
graph_get_dais_count(priv, &li);
|
|
||||||
if (!li.link || !li.dais)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
ret = asoc_simple_init_priv(priv, &li);
|
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
priv->pa_gpio = devm_gpiod_get_optional(dev, "pa", GPIOD_OUT_LOW);
|
|
||||||
if (IS_ERR(priv->pa_gpio)) {
|
|
||||||
ret = PTR_ERR(priv->pa_gpio);
|
|
||||||
dev_err(dev, "failed to get amplifier gpio: %d\n", ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = graph_parse_of(priv);
|
|
||||||
if (ret < 0) {
|
|
||||||
if (ret != -EPROBE_DEFER)
|
|
||||||
dev_err(dev, "parse error %d\n", ret);
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
snd_soc_card_set_drvdata(card, priv);
|
|
||||||
|
|
||||||
asoc_simple_debug_info(priv);
|
|
||||||
|
|
||||||
ret = devm_snd_soc_register_card(dev, card);
|
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
err:
|
|
||||||
asoc_simple_clean_reference(card);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int graph_remove(struct platform_device *pdev)
|
static int graph_remove(struct platform_device *pdev)
|
||||||
|
|
Loading…
Add table
Reference in a new issue