Commit 32c9ba54 authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Mark Brown

ASoC: Consolidate snd_soc_register_dai() and snd_soc_register_dais()

snd_soc_register_dais() has basically the same code as snd_soc_register_dai(),
but running in a loop. The only difference is that snd_soc_register_dai() calls
fmt_single_name() to generate the DAIs name and snd_soc_register_dais() calls
fmt_multiple_name(). This patch pushes the check in __snd_soc_register_component()
which decides whether to call snd_soc_register_dai() or snd_soc_register_dais()
to snd_soc_register_dais() to decide which naming scheme to use. This allows us
to remove snd_soc_register_dai().

The patch also updates snd_soc_register_dais() to unregister every DAI it finds
for the component rather than trying to unregister one DAI for each DAI that was
registered. Both have the same result since there won't be more DAIs than what
have been registered, but the former is easier to implement.
Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarMark Brown <broonie@linaro.org>
parent a707d030
...@@ -3906,100 +3906,47 @@ static inline char *fmt_multiple_name(struct device *dev, ...@@ -3906,100 +3906,47 @@ static inline char *fmt_multiple_name(struct device *dev,
} }
/** /**
* snd_soc_register_dai - Register a DAI with the ASoC core * snd_soc_unregister_dai - Unregister DAIs from the ASoC core
* *
* @component: The component the DAIs are registered for * @component: The component for which the DAIs should be unregistered
* @dai_drv: DAI driver to use for the DAIs
*/ */
static int snd_soc_register_dai(struct snd_soc_component *component, static void snd_soc_unregister_dais(struct snd_soc_component *component)
struct snd_soc_dai_driver *dai_drv)
{ {
struct device *dev = component->dev; struct snd_soc_dai *dai, *_dai;
struct snd_soc_codec *codec;
struct snd_soc_dai *dai;
dev_dbg(dev, "ASoC: dai register %s\n", dev_name(dev));
dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
if (dai == NULL)
return -ENOMEM;
/* create DAI component name */
dai->name = fmt_single_name(dev, &dai->id);
if (dai->name == NULL) {
kfree(dai);
return -ENOMEM;
}
dai->component = component;
dai->dev = dev;
dai->driver = dai_drv;
dai->dapm.dev = dev;
if (!dai->driver->ops)
dai->driver->ops = &null_dai_ops;
mutex_lock(&client_mutex); mutex_lock(&client_mutex);
list_for_each_entry_safe(dai, _dai, &dai_list, list) {
if (dai->dev != component->dev)
continue;
list_for_each_entry(codec, &codec_list, list) { list_del(&dai->list);
if (codec->dev == dev) {
dev_dbg(dev, "ASoC: Mapped DAI %s to CODEC %s\n",
dai->name, codec->name);
dai->codec = codec;
break;
}
}
if (!dai->codec)
dai->dapm.idle_bias_off = 1;
list_add(&dai->list, &dai_list);
mutex_unlock(&client_mutex);
dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name);
return 0;
}
/**
* snd_soc_unregister_dai - Unregister a DAI from the ASoC core
*
* @dai: DAI to unregister
*/
static void snd_soc_unregister_dai(struct device *dev)
{
struct snd_soc_dai *dai;
list_for_each_entry(dai, &dai_list, list) { dev_dbg(component->dev, "ASoC: Unregistered DAI '%s'\n",
if (dev == dai->dev) dai->name);
goto found; kfree(dai->name);
kfree(dai);
} }
return;
found:
mutex_lock(&client_mutex);
list_del(&dai->list);
mutex_unlock(&client_mutex); mutex_unlock(&client_mutex);
dev_dbg(dev, "ASoC: Unregistered DAI '%s'\n", dai->name);
kfree(dai->name);
kfree(dai);
} }
/** /**
* snd_soc_register_dais - Register multiple DAIs with the ASoC core * snd_soc_register_dais - Register a DAI with the ASoC core
* *
* @component: The component the DAIs are registered for * @component: The component the DAIs are registered for
* @dai_drv: DAI driver to use for the DAIs * @dai_drv: DAI driver to use for the DAIs
* @count: Number of 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, static int snd_soc_register_dais(struct snd_soc_component *component,
struct snd_soc_dai_driver *dai_drv, size_t count) struct snd_soc_dai_driver *dai_drv, size_t count,
bool legacy_dai_naming)
{ {
struct device *dev = component->dev; struct device *dev = component->dev;
struct snd_soc_codec *codec; struct snd_soc_codec *codec;
struct snd_soc_dai *dai; struct snd_soc_dai *dai;
int i, ret = 0; unsigned int i;
int ret;
dev_dbg(dev, "ASoC: dai register %s #%Zu\n", dev_name(dev), count); dev_dbg(dev, "ASoC: dai register %s #%Zu\n", dev_name(dev), count);
...@@ -4011,21 +3958,32 @@ static int snd_soc_register_dais(struct snd_soc_component *component, ...@@ -4011,21 +3958,32 @@ static int snd_soc_register_dais(struct snd_soc_component *component,
goto err; goto err;
} }
/* create DAI component name */ /*
dai->name = fmt_multiple_name(dev, &dai_drv[i]); * Back in the old days when we still had component-less DAIs,
* instead of having a static name, component-less DAIs would
* inherit the name of the parent device so it is possible to
* register multiple instances of the DAI. We still need to keep
* the same naming style even though those DAIs are not
* component-less anymore.
*/
if (count == 1 && legacy_dai_naming) {
dai->name = fmt_single_name(dev, &dai->id);
} else {
dai->name = fmt_multiple_name(dev, &dai_drv[i]);
if (dai_drv[i].id)
dai->id = dai_drv[i].id;
else
dai->id = i;
}
if (dai->name == NULL) { if (dai->name == NULL) {
kfree(dai); kfree(dai);
ret = -EINVAL; ret = -ENOMEM;
goto err; goto err;
} }
dai->component = component; dai->component = component;
dai->dev = dev; dai->dev = dev;
dai->driver = &dai_drv[i]; dai->driver = &dai_drv[i];
if (dai->driver->id)
dai->id = dai->driver->id;
else
dai->id = i;
dai->dapm.dev = dev; dai->dapm.dev = dev;
if (!dai->driver->ops) if (!dai->driver->ops)
dai->driver->ops = &null_dai_ops; dai->driver->ops = &null_dai_ops;
...@@ -4034,8 +3992,7 @@ static int snd_soc_register_dais(struct snd_soc_component *component, ...@@ -4034,8 +3992,7 @@ static int snd_soc_register_dais(struct snd_soc_component *component,
list_for_each_entry(codec, &codec_list, list) { list_for_each_entry(codec, &codec_list, list) {
if (codec->dev == dev) { if (codec->dev == dev) {
dev_dbg(dev, dev_dbg(dev, "ASoC: Mapped DAI %s to CODEC %s\n",
"ASoC: Mapped DAI %s to CODEC %s\n",
dai->name, codec->name); dai->name, codec->name);
dai->codec = codec; dai->codec = codec;
break; break;
...@@ -4049,32 +4006,17 @@ static int snd_soc_register_dais(struct snd_soc_component *component, ...@@ -4049,32 +4006,17 @@ static int snd_soc_register_dais(struct snd_soc_component *component,
mutex_unlock(&client_mutex); mutex_unlock(&client_mutex);
dev_dbg(dai->dev, "ASoC: Registered DAI '%s'\n", dai->name); dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name);
} }
return 0; return 0;
err: err:
for (i--; i >= 0; i--) snd_soc_unregister_dais(component);
snd_soc_unregister_dai(dev);
return ret; return ret;
} }
/**
* snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
*
* @dai: Array of DAIs to unregister
* @count: Number of DAIs
*/
static void snd_soc_unregister_dais(struct device *dev, size_t count)
{
int i;
for (i = 0; i < count; i++)
snd_soc_unregister_dai(dev);
}
/** /**
* snd_soc_register_component - Register a component with the ASoC core * snd_soc_register_component - Register a component with the ASoC core
* *
...@@ -4106,19 +4048,7 @@ __snd_soc_register_component(struct device *dev, ...@@ -4106,19 +4048,7 @@ __snd_soc_register_component(struct device *dev,
cmpnt->dai_drv = dai_drv; cmpnt->dai_drv = dai_drv;
cmpnt->num_dai = num_dai; cmpnt->num_dai = num_dai;
/* ret = snd_soc_register_dais(cmpnt, dai_drv, num_dai, allow_single_dai);
* snd_soc_register_dai() uses fmt_single_name(), and
* snd_soc_register_dais() uses fmt_multiple_name()
* for dai->name which is used for name based matching
*
* this function is used from cpu/codec.
* allow_single_dai flag can ignore "codec" driver reworking
* since it had been used snd_soc_register_dais(),
*/
if ((1 == num_dai) && allow_single_dai)
ret = snd_soc_register_dai(cmpnt, dai_drv);
else
ret = snd_soc_register_dais(cmpnt, dai_drv, num_dai);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "ASoC: Failed to regster DAIs: %d\n", ret); dev_err(dev, "ASoC: Failed to regster DAIs: %d\n", ret);
goto error_component_name; goto error_component_name;
...@@ -4173,7 +4103,7 @@ void snd_soc_unregister_component(struct device *dev) ...@@ -4173,7 +4103,7 @@ void snd_soc_unregister_component(struct device *dev)
return; return;
found: found:
snd_soc_unregister_dais(dev, cmpnt->num_dai); snd_soc_unregister_dais(cmpnt);
mutex_lock(&client_mutex); mutex_lock(&client_mutex);
list_del(&cmpnt->list); list_del(&cmpnt->list);
......
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