aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2014-03-09 12:41:45 -0400
committerMark Brown <broonie@linaro.org>2014-03-10 08:17:53 -0400
commit32c9ba544b65991b14ede102928c552ed24d4827 (patch)
treefbce3db1fc890f4572be27d03b4e604eda908225
parenta707d030da09793956a339066f0c91deafef14a3 (diff)
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: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r--sound/soc/soc-core.c154
1 files changed, 42 insertions, 112 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 255eca9afc9b..c365be98b0c3 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -3906,100 +3906,47 @@ static inline char *fmt_multiple_name(struct device *dev,
3906} 3906}
3907 3907
3908/** 3908/**
3909 * snd_soc_register_dai - Register a DAI with the ASoC core 3909 * snd_soc_unregister_dai - Unregister DAIs from the ASoC core
3910 * 3910 *
3911 * @component: The component the DAIs are registered for 3911 * @component: The component for which the DAIs should be unregistered
3912 * @dai_drv: DAI driver to use for the DAIs
3913 */ 3912 */
3914static int snd_soc_register_dai(struct snd_soc_component *component, 3913static void snd_soc_unregister_dais(struct snd_soc_component *component)
3915 struct snd_soc_dai_driver *dai_drv)
3916{ 3914{
3917 struct device *dev = component->dev; 3915 struct snd_soc_dai *dai, *_dai;
3918 struct snd_soc_codec *codec;
3919 struct snd_soc_dai *dai;
3920
3921 dev_dbg(dev, "ASoC: dai register %s\n", dev_name(dev));
3922
3923 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
3924 if (dai == NULL)
3925 return -ENOMEM;
3926
3927 /* create DAI component name */
3928 dai->name = fmt_single_name(dev, &dai->id);
3929 if (dai->name == NULL) {
3930 kfree(dai);
3931 return -ENOMEM;
3932 }
3933
3934 dai->component = component;
3935 dai->dev = dev;
3936 dai->driver = dai_drv;
3937 dai->dapm.dev = dev;
3938 if (!dai->driver->ops)
3939 dai->driver->ops = &null_dai_ops;
3940 3916
3941 mutex_lock(&client_mutex); 3917 mutex_lock(&client_mutex);
3918 list_for_each_entry_safe(dai, _dai, &dai_list, list) {
3919 if (dai->dev != component->dev)
3920 continue;
3942 3921
3943 list_for_each_entry(codec, &codec_list, list) { 3922 list_del(&dai->list);
3944 if (codec->dev == dev) {
3945 dev_dbg(dev, "ASoC: Mapped DAI %s to CODEC %s\n",
3946 dai->name, codec->name);
3947 dai->codec = codec;
3948 break;
3949 }
3950 }
3951
3952 if (!dai->codec)
3953 dai->dapm.idle_bias_off = 1;
3954
3955 list_add(&dai->list, &dai_list);
3956
3957 mutex_unlock(&client_mutex);
3958
3959 dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name);
3960
3961 return 0;
3962}
3963
3964/**
3965 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
3966 *
3967 * @dai: DAI to unregister
3968 */
3969static void snd_soc_unregister_dai(struct device *dev)
3970{
3971 struct snd_soc_dai *dai;
3972 3923
3973 list_for_each_entry(dai, &dai_list, list) { 3924 dev_dbg(component->dev, "ASoC: Unregistered DAI '%s'\n",
3974 if (dev == dai->dev) 3925 dai->name);
3975 goto found; 3926 kfree(dai->name);
3927 kfree(dai);
3976 } 3928 }
3977 return;
3978
3979found:
3980 mutex_lock(&client_mutex);
3981 list_del(&dai->list);
3982 mutex_unlock(&client_mutex); 3929 mutex_unlock(&client_mutex);
3983
3984 dev_dbg(dev, "ASoC: Unregistered DAI '%s'\n", dai->name);
3985 kfree(dai->name);
3986 kfree(dai);
3987} 3930}
3988 3931
3989/** 3932/**
3990 * snd_soc_register_dais - Register multiple DAIs with the ASoC core 3933 * snd_soc_register_dais - Register a DAI with the ASoC core
3991 * 3934 *
3992 * @component: The component the DAIs are registered for 3935 * @component: The component the DAIs are registered for
3993 * @dai_drv: DAI driver to use for the DAIs 3936 * @dai_drv: DAI driver to use for the DAIs
3994 * @count: Number of DAIs 3937 * @count: Number of DAIs
3938 * @legacy_dai_naming: Use the legacy naming scheme and let the DAI inherit the
3939 * parent's name.
3995 */ 3940 */
3996static int snd_soc_register_dais(struct snd_soc_component *component, 3941static int snd_soc_register_dais(struct snd_soc_component *component,
3997 struct snd_soc_dai_driver *dai_drv, size_t count) 3942 struct snd_soc_dai_driver *dai_drv, size_t count,
3943 bool legacy_dai_naming)
3998{ 3944{
3999 struct device *dev = component->dev; 3945 struct device *dev = component->dev;
4000 struct snd_soc_codec *codec; 3946 struct snd_soc_codec *codec;
4001 struct snd_soc_dai *dai; 3947 struct snd_soc_dai *dai;
4002 int i, ret = 0; 3948 unsigned int i;
3949 int ret;
4003 3950
4004 dev_dbg(dev, "ASoC: dai register %s #%Zu\n", dev_name(dev), count); 3951 dev_dbg(dev, "ASoC: dai register %s #%Zu\n", dev_name(dev), count);
4005 3952
@@ -4011,21 +3958,32 @@ static int snd_soc_register_dais(struct snd_soc_component *component,
4011 goto err; 3958 goto err;
4012 } 3959 }
4013 3960
4014 /* create DAI component name */ 3961 /*
4015 dai->name = fmt_multiple_name(dev, &dai_drv[i]); 3962 * Back in the old days when we still had component-less DAIs,
3963 * instead of having a static name, component-less DAIs would
3964 * inherit the name of the parent device so it is possible to
3965 * register multiple instances of the DAI. We still need to keep
3966 * the same naming style even though those DAIs are not
3967 * component-less anymore.
3968 */
3969 if (count == 1 && legacy_dai_naming) {
3970 dai->name = fmt_single_name(dev, &dai->id);
3971 } else {
3972 dai->name = fmt_multiple_name(dev, &dai_drv[i]);
3973 if (dai_drv[i].id)
3974 dai->id = dai_drv[i].id;
3975 else
3976 dai->id = i;
3977 }
4016 if (dai->name == NULL) { 3978 if (dai->name == NULL) {
4017 kfree(dai); 3979 kfree(dai);
4018 ret = -EINVAL; 3980 ret = -ENOMEM;
4019 goto err; 3981 goto err;
4020 } 3982 }
4021 3983
4022 dai->component = component; 3984 dai->component = component;
4023 dai->dev = dev; 3985 dai->dev = dev;
4024 dai->driver = &dai_drv[i]; 3986 dai->driver = &dai_drv[i];
4025 if (dai->driver->id)
4026 dai->id = dai->driver->id;
4027 else
4028 dai->id = i;
4029 dai->dapm.dev = dev; 3987 dai->dapm.dev = dev;
4030 if (!dai->driver->ops) 3988 if (!dai->driver->ops)
4031 dai->driver->ops = &null_dai_ops; 3989 dai->driver->ops = &null_dai_ops;
@@ -4034,8 +3992,7 @@ static int snd_soc_register_dais(struct snd_soc_component *component,
4034 3992
4035 list_for_each_entry(codec, &codec_list, list) { 3993 list_for_each_entry(codec, &codec_list, list) {
4036 if (codec->dev == dev) { 3994 if (codec->dev == dev) {
4037 dev_dbg(dev, 3995 dev_dbg(dev, "ASoC: Mapped DAI %s to CODEC %s\n",
4038 "ASoC: Mapped DAI %s to CODEC %s\n",
4039 dai->name, codec->name); 3996 dai->name, codec->name);
4040 dai->codec = codec; 3997 dai->codec = codec;
4041 break; 3998 break;
@@ -4049,33 +4006,18 @@ static int snd_soc_register_dais(struct snd_soc_component *component,
4049 4006
4050 mutex_unlock(&client_mutex); 4007 mutex_unlock(&client_mutex);
4051 4008
4052 dev_dbg(dai->dev, "ASoC: Registered DAI '%s'\n", dai->name); 4009 dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name);
4053 } 4010 }
4054 4011
4055 return 0; 4012 return 0;
4056 4013
4057err: 4014err:
4058 for (i--; i >= 0; i--) 4015 snd_soc_unregister_dais(component);
4059 snd_soc_unregister_dai(dev);
4060 4016
4061 return ret; 4017 return ret;
4062} 4018}
4063 4019
4064/** 4020/**
4065 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
4066 *
4067 * @dai: Array of DAIs to unregister
4068 * @count: Number of DAIs
4069 */
4070static void snd_soc_unregister_dais(struct device *dev, size_t count)
4071{
4072 int i;
4073
4074 for (i = 0; i < count; i++)
4075 snd_soc_unregister_dai(dev);
4076}
4077
4078/**
4079 * snd_soc_register_component - Register a component with the ASoC core 4021 * snd_soc_register_component - Register a component with the ASoC core
4080 * 4022 *
4081 */ 4023 */
@@ -4106,19 +4048,7 @@ __snd_soc_register_component(struct device *dev,
4106 cmpnt->dai_drv = dai_drv; 4048 cmpnt->dai_drv = dai_drv;
4107 cmpnt->num_dai = num_dai; 4049 cmpnt->num_dai = num_dai;
4108 4050
4109 /* 4051 ret = snd_soc_register_dais(cmpnt, dai_drv, num_dai, allow_single_dai);
4110 * snd_soc_register_dai() uses fmt_single_name(), and
4111 * snd_soc_register_dais() uses fmt_multiple_name()
4112 * for dai->name which is used for name based matching
4113 *
4114 * this function is used from cpu/codec.
4115 * allow_single_dai flag can ignore "codec" driver reworking
4116 * since it had been used snd_soc_register_dais(),
4117 */
4118 if ((1 == num_dai) && allow_single_dai)
4119 ret = snd_soc_register_dai(cmpnt, dai_drv);
4120 else
4121 ret = snd_soc_register_dais(cmpnt, dai_drv, num_dai);
4122 if (ret < 0) { 4052 if (ret < 0) {
4123 dev_err(dev, "ASoC: Failed to regster DAIs: %d\n", ret); 4053 dev_err(dev, "ASoC: Failed to regster DAIs: %d\n", ret);
4124 goto error_component_name; 4054 goto error_component_name;
@@ -4173,7 +4103,7 @@ void snd_soc_unregister_component(struct device *dev)
4173 return; 4103 return;
4174 4104
4175found: 4105found:
4176 snd_soc_unregister_dais(dev, cmpnt->num_dai); 4106 snd_soc_unregister_dais(cmpnt);
4177 4107
4178 mutex_lock(&client_mutex); 4108 mutex_lock(&client_mutex);
4179 list_del(&cmpnt->list); 4109 list_del(&cmpnt->list);