aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Brown <broonie@linaro.org>2013-09-04 15:37:34 -0400
committerMark Brown <broonie@linaro.org>2013-09-16 19:49:57 -0400
commita0b03a616b08cf9d709812ff5cf7e9c0958d6807 (patch)
treea18ed8b96c3c6fb7c1e59639e6666f588fbd9beb
parent272b98c6455f00884f0350f775c5342358ebb73f (diff)
ASoC: core: Implement devm_snd_soc_register_component()
Since with the wider use of devres many drivers are now only calling snd_soc_unregister_component() in their remove functions providing a managed version will save a reasonable amount of code. Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r--include/sound/soc.h3
-rw-r--r--sound/soc/Makefile2
-rw-r--r--sound/soc/soc-devres.c52
3 files changed, 56 insertions, 1 deletions
diff --git a/include/sound/soc.h b/include/sound/soc.h
index d22cb0a06feb..b970f019b452 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -386,6 +386,9 @@ void snd_soc_unregister_codec(struct device *dev);
386int snd_soc_register_component(struct device *dev, 386int snd_soc_register_component(struct device *dev,
387 const struct snd_soc_component_driver *cmpnt_drv, 387 const struct snd_soc_component_driver *cmpnt_drv,
388 struct snd_soc_dai_driver *dai_drv, int num_dai); 388 struct snd_soc_dai_driver *dai_drv, int num_dai);
389int devm_snd_soc_register_component(struct device *dev,
390 const struct snd_soc_component_driver *cmpnt_drv,
391 struct snd_soc_dai_driver *dai_drv, int num_dai);
389void snd_soc_unregister_component(struct device *dev); 392void snd_soc_unregister_component(struct device *dev);
390int snd_soc_codec_volatile_register(struct snd_soc_codec *codec, 393int snd_soc_codec_volatile_register(struct snd_soc_codec *codec,
391 unsigned int reg); 394 unsigned int reg);
diff --git a/sound/soc/Makefile b/sound/soc/Makefile
index 61a64d281905..8b9e70105dd2 100644
--- a/sound/soc/Makefile
+++ b/sound/soc/Makefile
@@ -1,5 +1,5 @@
1snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-cache.o soc-utils.o 1snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-cache.o soc-utils.o
2snd-soc-core-objs += soc-pcm.o soc-compress.o soc-io.o 2snd-soc-core-objs += soc-pcm.o soc-compress.o soc-io.o soc-devres.o
3 3
4ifneq ($(CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM),) 4ifneq ($(CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM),)
5snd-soc-core-objs += soc-generic-dmaengine-pcm.o 5snd-soc-core-objs += soc-generic-dmaengine-pcm.o
diff --git a/sound/soc/soc-devres.c b/sound/soc/soc-devres.c
new file mode 100644
index 000000000000..13fe86f7c9a8
--- /dev/null
+++ b/sound/soc/soc-devres.c
@@ -0,0 +1,52 @@
1/*
2 * soc-devres.c -- ALSA SoC Audio Layer devres functions
3 *
4 * Copyright (C) 2013 Linaro Ltd
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 */
11
12#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <sound/soc.h>
15
16static void devm_component_release(struct device *dev, void *res)
17{
18 snd_soc_unregister_component(*(struct device **)res);
19}
20
21/**
22 * devm_snd_soc_register_component - resource managed component registration
23 * @dev: Device used to manage component
24 * @cmpnt_drv: Component driver
25 * @dai_drv: DAI driver
26 * @num_dai: Number of DAIs to register
27 *
28 * Register a component with automatic unregistration when the device is
29 * unregistered.
30 */
31int devm_snd_soc_register_component(struct device *dev,
32 const struct snd_soc_component_driver *cmpnt_drv,
33 struct snd_soc_dai_driver *dai_drv, int num_dai)
34{
35 struct device **ptr;
36 int ret;
37
38 ptr = devres_alloc(devm_component_release, sizeof(*ptr), GFP_KERNEL);
39 if (!ptr)
40 return -ENOMEM;
41
42 ret = snd_soc_register_component(dev, cmpnt_drv, dai_drv, num_dai);
43 if (ret == 0) {
44 *ptr = dev;
45 devres_add(dev, ptr);
46 } else {
47 devres_free(ptr);
48 }
49
50 return ret;
51}
52EXPORT_SYMBOL_GPL(devm_snd_soc_register_component);