alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/6] ASoC: Add resource managed snd_dmaengine_pcm_register()
@ 2013-11-28  7:50 Lars-Peter Clausen
  2013-11-28  7:50 ` [PATCH 2/6] ASoC: bcm2835-i2s: Use devm_snd_dmaengine_pcm_register() Lars-Peter Clausen
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Lars-Peter Clausen @ 2013-11-28  7:50 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood
  Cc: Fabio Estevam, alsa-devel, Rajeev Kumar, Ryan Mallon, Timur Tabi,
	H Hartley Sweeten, Lars-Peter Clausen, Florian Meier,
	Markus Pargmann, Shawn Guo

For many drivers using the generic dmaengine PCM driver one of the few (or the
only) things left to do in the drivers remove function is to unregister the PCM
device. This patch adds a resource managed version of snd_dmaengine_pcm_register()
which makes it possible to simplify the remove function as well as the error
path in the probe function for those drivers.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>

---
Changes since v1:
	* Moved snd_dmaengine_pcm_register() to soc-devres.c
---
 include/sound/dmaengine_pcm.h |  4 ++++
 sound/soc/soc-devres.c        | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/include/sound/dmaengine_pcm.h b/include/sound/dmaengine_pcm.h
index 1501731..4ef986c 100644
--- a/include/sound/dmaengine_pcm.h
+++ b/include/sound/dmaengine_pcm.h
@@ -140,6 +140,10 @@ int snd_dmaengine_pcm_register(struct device *dev,
 	unsigned int flags);
 void snd_dmaengine_pcm_unregister(struct device *dev);
 
+int devm_snd_dmaengine_pcm_register(struct device *dev,
+	const struct snd_dmaengine_pcm_config *config,
+	unsigned int flags);
+
 int snd_dmaengine_pcm_prepare_slave_config(struct snd_pcm_substream *substream,
 	struct snd_pcm_hw_params *params,
 	struct dma_slave_config *slave_config);
diff --git a/sound/soc/soc-devres.c b/sound/soc/soc-devres.c
index b1d7322..9998619 100644
--- a/sound/soc/soc-devres.c
+++ b/sound/soc/soc-devres.c
@@ -12,6 +12,7 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <sound/soc.h>
+#include <sound/dmaengine_pcm.h>
 
 static void devm_component_release(struct device *dev, void *res)
 {
@@ -84,3 +85,43 @@ int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card)
 	return ret;
 }
 EXPORT_SYMBOL_GPL(devm_snd_soc_register_card);
+
+#ifdef CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM
+
+static void devm_dmaengine_pcm_release(struct device *dev, void *res)
+{
+	snd_dmaengine_pcm_unregister(*(struct device **)res);
+}
+
+/**
+ * devm_snd_dmaengine_pcm_register - resource managed dmaengine PCM registration
+ * @dev: The parent device for the PCM device
+ * @config: Platform specific PCM configuration
+ * @flags: Platform specific quirks
+ *
+ * Register a dmaengine based PCM device with automatic unregistration when the
+ * device is unregistered.
+ */
+int devm_snd_dmaengine_pcm_register(struct device *dev,
+	const struct snd_dmaengine_pcm_config *config, unsigned int flags)
+{
+	struct device **ptr;
+	int ret;
+
+	ptr = devres_alloc(devm_dmaengine_pcm_release, sizeof(*ptr), GFP_KERNEL);
+	if (!ptr)
+		return -ENOMEM;
+
+	ret = snd_dmaengine_pcm_register(dev, config, flags);
+	if (ret == 0) {
+		*ptr = dev;
+		devres_add(dev, ptr);
+	} else {
+		devres_free(ptr);
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(devm_snd_dmaengine_pcm_register);
+
+#endif
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread
* [PATCH 1/6] ASoC: Add resource managed snd_dmaengine_pcm_register()
@ 2013-11-24 13:20 Lars-Peter Clausen
  2013-11-24 13:20 ` [PATCH 3/6] ASoC: ep93xx: Use devm_snd_dmaengine_pcm_register() Lars-Peter Clausen
  0 siblings, 1 reply; 13+ messages in thread
From: Lars-Peter Clausen @ 2013-11-24 13:20 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood
  Cc: Fabio Estevam, alsa-devel, Rajeev Kumar, Ryan Mallon,
	Nicolas Ferre, Timur Tabi, H Hartley Sweeten, Lars-Peter Clausen,
	Bo Shen, Markus Pargmann, Shawn Guo

For many drivers using the generic dmaengine PCM driver one of the few (or the
only) things left to do in the drivers remove function is to unregister the PCM
device. This patch adds a resource managed version of snd_dmaengine_pcm_register()
which makes it possible to simplify the remove function as well as the error
path in the probe function for those drivers.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 include/sound/dmaengine_pcm.h         |  4 ++++
 sound/soc/soc-generic-dmaengine-pcm.c | 36 +++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/include/sound/dmaengine_pcm.h b/include/sound/dmaengine_pcm.h
index 1501731..4ef986c 100644
--- a/include/sound/dmaengine_pcm.h
+++ b/include/sound/dmaengine_pcm.h
@@ -140,6 +140,10 @@ int snd_dmaengine_pcm_register(struct device *dev,
 	unsigned int flags);
 void snd_dmaengine_pcm_unregister(struct device *dev);
 
+int devm_snd_dmaengine_pcm_register(struct device *dev,
+	const struct snd_dmaengine_pcm_config *config,
+	unsigned int flags);
+
 int snd_dmaengine_pcm_prepare_slave_config(struct snd_pcm_substream *substream,
 	struct snd_pcm_hw_params *params,
 	struct dma_slave_config *slave_config);
diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c
index cbc9c96..20690c0 100644
--- a/sound/soc/soc-generic-dmaengine-pcm.c
+++ b/sound/soc/soc-generic-dmaengine-pcm.c
@@ -366,4 +366,40 @@ void snd_dmaengine_pcm_unregister(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_unregister);
 
+static void devm_dmaengine_pcm_release(struct device *dev, void *res)
+{
+	snd_dmaengine_pcm_unregister(*(struct device **)res);
+}
+
+/**
+ * devm_snd_dmaengine_pcm_register - resource managed dmaengine PCM registration
+ * @dev: The parent device for the PCM device
+ * @config: Platform specific PCM configuration
+ * @flags: Platform specific quirks
+ *
+ * Register a dmaengine based PCM device with automatic unregistration when the
+ * device is unregistered.
+ */
+int devm_snd_dmaengine_pcm_register(struct device *dev,
+	const struct snd_dmaengine_pcm_config *config, unsigned int flags)
+{
+	struct device **ptr;
+	int ret;
+
+	ptr = devres_alloc(devm_dmaengine_pcm_release, sizeof(*ptr), GFP_KERNEL);
+	if (!ptr)
+		return -ENOMEM;
+
+	ret = snd_dmaengine_pcm_register(dev, config, flags);
+	if (ret == 0) {
+		*ptr = dev;
+		devres_add(dev, ptr);
+	} else {
+		devres_free(ptr);
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(devm_snd_dmaengine_pcm_register);
+
 MODULE_LICENSE("GPL");
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2013-12-02 11:50 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-28  7:50 [PATCH 1/6] ASoC: Add resource managed snd_dmaengine_pcm_register() Lars-Peter Clausen
2013-11-28  7:50 ` [PATCH 2/6] ASoC: bcm2835-i2s: Use devm_snd_dmaengine_pcm_register() Lars-Peter Clausen
2013-12-02 11:47   ` Mark Brown
2013-11-28  7:50 ` [PATCH 3/6] ASoC: ep93xx: " Lars-Peter Clausen
2013-12-02 11:48   ` Mark Brown
2013-11-28  7:50 ` [PATCH 4/6] ASoC: fsl: " Lars-Peter Clausen
2013-12-02 11:49   ` Mark Brown
2013-11-28  7:50 ` [PATCH 5/6] ASoC: spear: Use devm_snd_dmaengine_pcm_register Lars-Peter Clausen
2013-11-28 13:36   ` Mark Brown
2013-11-28  7:50 ` [PATCH 6/6] ASoC: mxs: Use devm_snd_dmaengine_pcm_register() Lars-Peter Clausen
2013-12-02 11:49   ` Mark Brown
2013-11-28 13:36 ` [PATCH 1/6] ASoC: Add resource managed snd_dmaengine_pcm_register() Mark Brown
  -- strict thread matches above, loose matches on Subject: below --
2013-11-24 13:20 Lars-Peter Clausen
2013-11-24 13:20 ` [PATCH 3/6] ASoC: ep93xx: Use devm_snd_dmaengine_pcm_register() Lars-Peter Clausen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).