aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>2013-09-04 22:39:03 -0400
committerMark Brown <broonie@linaro.org>2013-09-17 08:07:13 -0400
commitd191bd8de8c61619563f2b19f1fdcc0944ff1a72 (patch)
treebc77d6f8573b03f9f2e938d22bc2d6f3ec0b4f86
parent272b98c6455f00884f0350f775c5342358ebb73f (diff)
ASoC: snd_soc_codec includes snd_soc_component
Codec includes component by this patch, and component moved to upside of codec to avoid extra declaration. Codec dai will be registered via component by this patch. Current component register function is used for cpu, and it is using dai/dais functions properly to keep existing cpu dai name. And now, it will be used from codec also. But codec driver had been used dais function only even though it was single dai. This patch adds new flag which can selects dai/dais function on component register function to keep existing codec dai name. Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r--include/sound/soc.h33
-rw-r--r--sound/soc/soc-core.c202
2 files changed, 131 insertions, 104 deletions
diff --git a/include/sound/soc.h b/include/sound/soc.h
index d22cb0a06feb..9a81e2e7d661 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -670,6 +670,21 @@ struct snd_soc_cache_ops {
670 int (*sync)(struct snd_soc_codec *codec); 670 int (*sync)(struct snd_soc_codec *codec);
671}; 671};
672 672
673/* component interface */
674struct snd_soc_component_driver {
675 const char *name;
676};
677
678struct snd_soc_component {
679 const char *name;
680 int id;
681 int num_dai;
682 struct device *dev;
683 struct list_head list;
684
685 const struct snd_soc_component_driver *driver;
686};
687
673/* SoC Audio Codec device */ 688/* SoC Audio Codec device */
674struct snd_soc_codec { 689struct snd_soc_codec {
675 const char *name; 690 const char *name;
@@ -715,6 +730,9 @@ struct snd_soc_codec {
715 struct mutex cache_rw_mutex; 730 struct mutex cache_rw_mutex;
716 int val_bytes; 731 int val_bytes;
717 732
733 /* component */
734 struct snd_soc_component component;
735
718 /* dapm */ 736 /* dapm */
719 struct snd_soc_dapm_context dapm; 737 struct snd_soc_dapm_context dapm;
720 unsigned int ignore_pmdown_time:1; /* pmdown_time is ignored at stop */ 738 unsigned int ignore_pmdown_time:1; /* pmdown_time is ignored at stop */
@@ -733,6 +751,7 @@ struct snd_soc_codec_driver {
733 int (*remove)(struct snd_soc_codec *); 751 int (*remove)(struct snd_soc_codec *);
734 int (*suspend)(struct snd_soc_codec *); 752 int (*suspend)(struct snd_soc_codec *);
735 int (*resume)(struct snd_soc_codec *); 753 int (*resume)(struct snd_soc_codec *);
754 struct snd_soc_component_driver component_driver;
736 755
737 /* Default control and setup, added after probe() is run */ 756 /* Default control and setup, added after probe() is run */
738 const struct snd_kcontrol_new *controls; 757 const struct snd_kcontrol_new *controls;
@@ -849,20 +868,6 @@ struct snd_soc_platform {
849#endif 868#endif
850}; 869};
851 870
852struct snd_soc_component_driver {
853 const char *name;
854};
855
856struct snd_soc_component {
857 const char *name;
858 int id;
859 int num_dai;
860 struct device *dev;
861 struct list_head list;
862
863 const struct snd_soc_component_driver *driver;
864};
865
866struct snd_soc_dai_link { 871struct snd_soc_dai_link {
867 /* config - must be set by machine driver */ 872 /* config - must be set by machine driver */
868 const char *name; /* Codec name */ 873 const char *name; /* Codec name */
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 4d0561312f3b..014ac10267da 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -4021,6 +4021,112 @@ static void snd_soc_unregister_dais(struct device *dev, size_t count)
4021} 4021}
4022 4022
4023/** 4023/**
4024 * snd_soc_register_component - Register a component with the ASoC core
4025 *
4026 */
4027static int
4028__snd_soc_register_component(struct device *dev,
4029 struct snd_soc_component *cmpnt,
4030 const struct snd_soc_component_driver *cmpnt_drv,
4031 struct snd_soc_dai_driver *dai_drv,
4032 int num_dai, bool allow_single_dai)
4033{
4034 int ret;
4035
4036 dev_dbg(dev, "component register %s\n", dev_name(dev));
4037
4038 if (!cmpnt) {
4039 dev_err(dev, "ASoC: Failed to connecting component\n");
4040 return -ENOMEM;
4041 }
4042
4043 cmpnt->name = fmt_single_name(dev, &cmpnt->id);
4044 if (!cmpnt->name) {
4045 dev_err(dev, "ASoC: Failed to simplifying name\n");
4046 return -ENOMEM;
4047 }
4048
4049 cmpnt->dev = dev;
4050 cmpnt->driver = cmpnt_drv;
4051 cmpnt->num_dai = num_dai;
4052
4053 /*
4054 * snd_soc_register_dai() uses fmt_single_name(), and
4055 * snd_soc_register_dais() uses fmt_multiple_name()
4056 * for dai->name which is used for name based matching
4057 *
4058 * this function is used from cpu/codec.
4059 * allow_single_dai flag can ignore "codec" driver reworking
4060 * since it had been used snd_soc_register_dais(),
4061 */
4062 if ((1 == num_dai) && allow_single_dai)
4063 ret = snd_soc_register_dai(dev, dai_drv);
4064 else
4065 ret = snd_soc_register_dais(dev, dai_drv, num_dai);
4066 if (ret < 0) {
4067 dev_err(dev, "ASoC: Failed to regster DAIs: %d\n", ret);
4068 goto error_component_name;
4069 }
4070
4071 mutex_lock(&client_mutex);
4072 list_add(&cmpnt->list, &component_list);
4073 mutex_unlock(&client_mutex);
4074
4075 dev_dbg(cmpnt->dev, "ASoC: Registered component '%s'\n", cmpnt->name);
4076
4077 return ret;
4078
4079error_component_name:
4080 kfree(cmpnt->name);
4081
4082 return ret;
4083}
4084
4085int snd_soc_register_component(struct device *dev,
4086 const struct snd_soc_component_driver *cmpnt_drv,
4087 struct snd_soc_dai_driver *dai_drv,
4088 int num_dai)
4089{
4090 struct snd_soc_component *cmpnt;
4091
4092 cmpnt = devm_kzalloc(dev, sizeof(*cmpnt), GFP_KERNEL);
4093 if (!cmpnt) {
4094 dev_err(dev, "ASoC: Failed to allocate memory\n");
4095 return -ENOMEM;
4096 }
4097
4098 return __snd_soc_register_component(dev, cmpnt, cmpnt_drv,
4099 dai_drv, num_dai, true);
4100}
4101EXPORT_SYMBOL_GPL(snd_soc_register_component);
4102
4103/**
4104 * snd_soc_unregister_component - Unregister a component from the ASoC core
4105 *
4106 */
4107void snd_soc_unregister_component(struct device *dev)
4108{
4109 struct snd_soc_component *cmpnt;
4110
4111 list_for_each_entry(cmpnt, &component_list, list) {
4112 if (dev == cmpnt->dev)
4113 goto found;
4114 }
4115 return;
4116
4117found:
4118 snd_soc_unregister_dais(dev, cmpnt->num_dai);
4119
4120 mutex_lock(&client_mutex);
4121 list_del(&cmpnt->list);
4122 mutex_unlock(&client_mutex);
4123
4124 dev_dbg(dev, "ASoC: Unregistered component '%s'\n", cmpnt->name);
4125 kfree(cmpnt->name);
4126}
4127EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
4128
4129/**
4024 * snd_soc_add_platform - Add a platform to the ASoC core 4130 * snd_soc_add_platform - Add a platform to the ASoC core
4025 * @dev: The parent device for the platform 4131 * @dev: The parent device for the platform
4026 * @platform: The platform to add 4132 * @platform: The platform to add
@@ -4242,10 +4348,12 @@ int snd_soc_register_codec(struct device *dev,
4242 list_add(&codec->list, &codec_list); 4348 list_add(&codec->list, &codec_list);
4243 mutex_unlock(&client_mutex); 4349 mutex_unlock(&client_mutex);
4244 4350
4245 /* register any DAIs */ 4351 /* register component */
4246 ret = snd_soc_register_dais(dev, dai_drv, num_dai); 4352 ret = __snd_soc_register_component(dev, &codec->component,
4353 &codec_drv->component_driver,
4354 dai_drv, num_dai, false);
4247 if (ret < 0) { 4355 if (ret < 0) {
4248 dev_err(codec->dev, "ASoC: Failed to regster DAIs: %d\n", ret); 4356 dev_err(codec->dev, "ASoC: Failed to regster component: %d\n", ret);
4249 goto fail_codec_name; 4357 goto fail_codec_name;
4250 } 4358 }
4251 4359
@@ -4280,7 +4388,7 @@ void snd_soc_unregister_codec(struct device *dev)
4280 return; 4388 return;
4281 4389
4282found: 4390found:
4283 snd_soc_unregister_dais(dev, codec->num_dai); 4391 snd_soc_unregister_component(dev);
4284 4392
4285 mutex_lock(&client_mutex); 4393 mutex_lock(&client_mutex);
4286 list_del(&codec->list); 4394 list_del(&codec->list);
@@ -4295,92 +4403,6 @@ found:
4295} 4403}
4296EXPORT_SYMBOL_GPL(snd_soc_unregister_codec); 4404EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
4297 4405
4298
4299/**
4300 * snd_soc_register_component - Register a component with the ASoC core
4301 *
4302 */
4303int snd_soc_register_component(struct device *dev,
4304 const struct snd_soc_component_driver *cmpnt_drv,
4305 struct snd_soc_dai_driver *dai_drv,
4306 int num_dai)
4307{
4308 struct snd_soc_component *cmpnt;
4309 int ret;
4310
4311 dev_dbg(dev, "component register %s\n", dev_name(dev));
4312
4313 cmpnt = devm_kzalloc(dev, sizeof(*cmpnt), GFP_KERNEL);
4314 if (!cmpnt) {
4315 dev_err(dev, "ASoC: Failed to allocate memory\n");
4316 return -ENOMEM;
4317 }
4318
4319 cmpnt->name = fmt_single_name(dev, &cmpnt->id);
4320 if (!cmpnt->name) {
4321 dev_err(dev, "ASoC: Failed to simplifying name\n");
4322 return -ENOMEM;
4323 }
4324
4325 cmpnt->dev = dev;
4326 cmpnt->driver = cmpnt_drv;
4327 cmpnt->num_dai = num_dai;
4328
4329 /*
4330 * snd_soc_register_dai() uses fmt_single_name(), and
4331 * snd_soc_register_dais() uses fmt_multiple_name()
4332 * for dai->name which is used for name based matching
4333 */
4334 if (1 == num_dai)
4335 ret = snd_soc_register_dai(dev, dai_drv);
4336 else
4337 ret = snd_soc_register_dais(dev, dai_drv, num_dai);
4338 if (ret < 0) {
4339 dev_err(dev, "ASoC: Failed to regster DAIs: %d\n", ret);
4340 goto error_component_name;
4341 }
4342
4343 mutex_lock(&client_mutex);
4344 list_add(&cmpnt->list, &component_list);
4345 mutex_unlock(&client_mutex);
4346
4347 dev_dbg(cmpnt->dev, "ASoC: Registered component '%s'\n", cmpnt->name);
4348
4349 return ret;
4350
4351error_component_name:
4352 kfree(cmpnt->name);
4353
4354 return ret;
4355}
4356EXPORT_SYMBOL_GPL(snd_soc_register_component);
4357
4358/**
4359 * snd_soc_unregister_component - Unregister a component from the ASoC core
4360 *
4361 */
4362void snd_soc_unregister_component(struct device *dev)
4363{
4364 struct snd_soc_component *cmpnt;
4365
4366 list_for_each_entry(cmpnt, &component_list, list) {
4367 if (dev == cmpnt->dev)
4368 goto found;
4369 }
4370 return;
4371
4372found:
4373 snd_soc_unregister_dais(dev, cmpnt->num_dai);
4374
4375 mutex_lock(&client_mutex);
4376 list_del(&cmpnt->list);
4377 mutex_unlock(&client_mutex);
4378
4379 dev_dbg(dev, "ASoC: Unregistered component '%s'\n", cmpnt->name);
4380 kfree(cmpnt->name);
4381}
4382EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
4383
4384/* Retrieve a card's name from device tree */ 4406/* Retrieve a card's name from device tree */
4385int snd_soc_of_parse_card_name(struct snd_soc_card *card, 4407int snd_soc_of_parse_card_name(struct snd_soc_card *card,
4386 const char *propname) 4408 const char *propname)