Commit 5e4fb372 authored by Mengdong Lin's avatar Mengdong Lin Committed by Mark Brown

ASoC: Define soc_add_dai() to add a DAI to a component

Define soc_add_dai() as a wrapper to add a single DAI to a component.
It can be reused to register a DAI dynamically by topology.
Signed-off-by: default avatarMengdong Lin <mengdong.lin@linux.intel.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 61b0088b
...@@ -2744,36 +2744,19 @@ static void snd_soc_unregister_dais(struct snd_soc_component *component) ...@@ -2744,36 +2744,19 @@ static void snd_soc_unregister_dais(struct snd_soc_component *component)
} }
} }
/** /* Create a DAI and add it to the component's DAI list */
* snd_soc_register_dais - Register a DAI with the ASoC core static struct snd_soc_dai *soc_add_dai(struct snd_soc_component *component,
* struct snd_soc_dai_driver *dai_drv,
* @component: The component the DAIs are registered for
* @dai_drv: DAI driver to use for the DAIs
* @count: Number of DAIs
* @legacy_dai_naming: Use the legacy naming scheme and let the DAI inherit the
* parent's name.
*/
static int snd_soc_register_dais(struct snd_soc_component *component,
struct snd_soc_dai_driver *dai_drv, size_t count,
bool legacy_dai_naming) bool legacy_dai_naming)
{ {
struct device *dev = component->dev; struct device *dev = component->dev;
struct snd_soc_dai *dai; struct snd_soc_dai *dai;
unsigned int i;
int ret;
dev_dbg(dev, "ASoC: dai register %s #%Zu\n", dev_name(dev), count); dev_dbg(dev, "ASoC: dynamically register DAI %s\n", dev_name(dev));
component->dai_drv = dai_drv;
component->num_dai = count;
for (i = 0; i < count; i++) {
dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL); dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
if (dai == NULL) { if (dai == NULL)
ret = -ENOMEM; return NULL;
goto err;
}
/* /*
* Back in the old days when we still had component-less DAIs, * Back in the old days when we still had component-less DAIs,
...@@ -2783,31 +2766,64 @@ static int snd_soc_register_dais(struct snd_soc_component *component, ...@@ -2783,31 +2766,64 @@ static int snd_soc_register_dais(struct snd_soc_component *component,
* the same naming style even though those DAIs are not * the same naming style even though those DAIs are not
* component-less anymore. * component-less anymore.
*/ */
if (count == 1 && legacy_dai_naming && if (legacy_dai_naming &&
(dai_drv[i].id == 0 || dai_drv[i].name == NULL)) { (dai_drv->id == 0 || dai_drv->name == NULL)) {
dai->name = fmt_single_name(dev, &dai->id); dai->name = fmt_single_name(dev, &dai->id);
} else { } else {
dai->name = fmt_multiple_name(dev, &dai_drv[i]); dai->name = fmt_multiple_name(dev, dai_drv);
if (dai_drv[i].id) if (dai_drv->id)
dai->id = dai_drv[i].id; dai->id = dai_drv->id;
else else
dai->id = i; dai->id = component->num_dai;
} }
if (dai->name == NULL) { if (dai->name == NULL) {
kfree(dai); kfree(dai);
ret = -ENOMEM; return NULL;
goto err;
} }
dai->component = component; dai->component = component;
dai->dev = dev; dai->dev = dev;
dai->driver = &dai_drv[i]; dai->driver = dai_drv;
if (!dai->driver->ops) if (!dai->driver->ops)
dai->driver->ops = &null_dai_ops; dai->driver->ops = &null_dai_ops;
list_add(&dai->list, &component->dai_list); list_add(&dai->list, &component->dai_list);
component->num_dai++;
dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name); dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name);
return dai;
}
/**
* snd_soc_register_dais - Register a DAI with the ASoC core
*
* @component: The component the DAIs are registered for
* @dai_drv: DAI driver to use for the DAIs
* @count: Number of DAIs
* @legacy_dai_naming: Use the legacy naming scheme and let the DAI inherit the
* parent's name.
*/
static int snd_soc_register_dais(struct snd_soc_component *component,
struct snd_soc_dai_driver *dai_drv, size_t count,
bool legacy_dai_naming)
{
struct device *dev = component->dev;
struct snd_soc_dai *dai;
unsigned int i;
int ret;
dev_dbg(dev, "ASoC: dai register %s #%Zu\n", dev_name(dev), count);
component->dai_drv = dai_drv;
for (i = 0; i < count; i++) {
dai = soc_add_dai(component, dai_drv + i,
count == 1 && legacy_dai_naming);
if (dai == NULL) {
ret = -ENOMEM;
goto err;
}
} }
return 0; return 0;
......
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