aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2014-03-18 04:02:12 -0400
committerMark Brown <broonie@linaro.org>2014-04-14 12:22:44 -0400
commitb37f1d123c69c0d7730704d65b83eaac780c0e3b (patch)
treef7e175bec547275fa4785efaea33690df97d472f
parent98e639fb8a3ed1bf2bd512626c3cfc2992a57113 (diff)
ASoC: Let snd_soc_platform subclass snd_soc_component
There is an increasing amount of code that is very similar between platforms, CODECS and other components. Making platforms a component will allow us to share this code. For now the patch just adds component and component_driver fields to the platform and platform_driver structs and registers the platform as a component. Followup patches will be used to consolidate code between the different types of components. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r--include/sound/soc.h16
-rw-r--r--sound/soc/soc-core.c14
2 files changed, 30 insertions, 0 deletions
diff --git a/include/sound/soc.h b/include/sound/soc.h
index f8a79c17628e..94a2dc20ad6e 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -778,6 +778,7 @@ struct snd_soc_platform_driver {
778 int (*remove)(struct snd_soc_platform *); 778 int (*remove)(struct snd_soc_platform *);
779 int (*suspend)(struct snd_soc_dai *dai); 779 int (*suspend)(struct snd_soc_dai *dai);
780 int (*resume)(struct snd_soc_dai *dai); 780 int (*resume)(struct snd_soc_dai *dai);
781 struct snd_soc_component_driver component_driver;
781 782
782 /* pcm creation and destruction */ 783 /* pcm creation and destruction */
783 int (*pcm_new)(struct snd_soc_pcm_runtime *); 784 int (*pcm_new)(struct snd_soc_pcm_runtime *);
@@ -831,6 +832,8 @@ struct snd_soc_platform {
831 struct list_head list; 832 struct list_head list;
832 struct list_head card_list; 833 struct list_head card_list;
833 834
835 struct snd_soc_component component;
836
834 struct snd_soc_dapm_context dapm; 837 struct snd_soc_dapm_context dapm;
835 838
836#ifdef CONFIG_DEBUG_FS 839#ifdef CONFIG_DEBUG_FS
@@ -1107,6 +1110,19 @@ static inline struct snd_soc_codec *snd_soc_component_to_codec(
1107 return container_of(component, struct snd_soc_codec, component); 1110 return container_of(component, struct snd_soc_codec, component);
1108} 1111}
1109 1112
1113/**
1114 * snd_soc_component_to_platform() - Casts a component to the platform it is embedded in
1115 * @component: The component to cast to a platform
1116 *
1117 * This function must only be used on components that are known to be platforms.
1118 * Otherwise the behavior is undefined.
1119 */
1120static inline struct snd_soc_platform *snd_soc_component_to_platform(
1121 struct snd_soc_component *component)
1122{
1123 return container_of(component, struct snd_soc_platform, component);
1124}
1125
1110/* codec IO */ 1126/* codec IO */
1111unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg); 1127unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg);
1112unsigned int snd_soc_write(struct snd_soc_codec *codec, 1128unsigned int snd_soc_write(struct snd_soc_codec *codec,
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 3314efb365e3..a95c7e524dfc 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -3921,6 +3921,8 @@ EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
3921int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform, 3921int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform,
3922 const struct snd_soc_platform_driver *platform_drv) 3922 const struct snd_soc_platform_driver *platform_drv)
3923{ 3923{
3924 int ret;
3925
3924 /* create platform component name */ 3926 /* create platform component name */
3925 platform->name = fmt_single_name(dev, &platform->id); 3927 platform->name = fmt_single_name(dev, &platform->id);
3926 if (platform->name == NULL) 3928 if (platform->name == NULL)
@@ -3933,6 +3935,16 @@ int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform,
3933 platform->dapm.stream_event = platform_drv->stream_event; 3935 platform->dapm.stream_event = platform_drv->stream_event;
3934 mutex_init(&platform->mutex); 3936 mutex_init(&platform->mutex);
3935 3937
3938 /* register component */
3939 ret = __snd_soc_register_component(dev, &platform->component,
3940 &platform_drv->component_driver,
3941 NULL, NULL, 0, false);
3942 if (ret < 0) {
3943 dev_err(platform->component.dev,
3944 "ASoC: Failed to register component: %d\n", ret);
3945 return ret;
3946 }
3947
3936 mutex_lock(&client_mutex); 3948 mutex_lock(&client_mutex);
3937 list_add(&platform->list, &platform_list); 3949 list_add(&platform->list, &platform_list);
3938 mutex_unlock(&client_mutex); 3950 mutex_unlock(&client_mutex);
@@ -3974,6 +3986,8 @@ EXPORT_SYMBOL_GPL(snd_soc_register_platform);
3974 */ 3986 */
3975void snd_soc_remove_platform(struct snd_soc_platform *platform) 3987void snd_soc_remove_platform(struct snd_soc_platform *platform)
3976{ 3988{
3989 snd_soc_unregister_component(platform->dev);
3990
3977 mutex_lock(&client_mutex); 3991 mutex_lock(&client_mutex);
3978 list_del(&platform->list); 3992 list_del(&platform->list);
3979 mutex_unlock(&client_mutex); 3993 mutex_unlock(&client_mutex);