1 // SPDX-License-Identifier: GPL-2.0+
3 // soc-devres.c -- ALSA SoC Audio Layer devres functions
5 // Copyright (C) 2013 Linaro Ltd
7 #include <linux/module.h>
8 #include <linux/moduleparam.h>
10 #include <sound/dmaengine_pcm.h>
12 static void devm_dai_release(struct device *dev, void *res)
14 snd_soc_unregister_dai(*(struct snd_soc_dai **)res);
18 * devm_snd_soc_register_dai - resource-managed dai registration
19 * @dev: Device used to manage component
20 * @component: The component the DAIs are registered for
21 * @dai_drv: DAI driver to use for the DAI
22 * @legacy_dai_naming: if %true, use legacy single-name format;
23 * if %false, use multiple-name format;
25 struct snd_soc_dai *devm_snd_soc_register_dai(struct device *dev,
26 struct snd_soc_component *component,
27 struct snd_soc_dai_driver *dai_drv,
28 bool legacy_dai_naming)
30 struct snd_soc_dai **ptr;
31 struct snd_soc_dai *dai;
33 ptr = devres_alloc(devm_dai_release, sizeof(*ptr), GFP_KERNEL);
37 dai = snd_soc_register_dai(component, dai_drv, legacy_dai_naming);
47 EXPORT_SYMBOL_GPL(devm_snd_soc_register_dai);
49 static void devm_component_release(struct device *dev, void *res)
51 const struct snd_soc_component_driver **cmpnt_drv = res;
53 snd_soc_unregister_component_by_driver(dev, *cmpnt_drv);
57 * devm_snd_soc_register_component - resource managed component registration
58 * @dev: Device used to manage component
59 * @cmpnt_drv: Component driver
60 * @dai_drv: DAI driver
61 * @num_dai: Number of DAIs to register
63 * Register a component with automatic unregistration when the device is
66 int devm_snd_soc_register_component(struct device *dev,
67 const struct snd_soc_component_driver *cmpnt_drv,
68 struct snd_soc_dai_driver *dai_drv, int num_dai)
70 const struct snd_soc_component_driver **ptr;
73 ptr = devres_alloc(devm_component_release, sizeof(*ptr), GFP_KERNEL);
77 ret = snd_soc_register_component(dev, cmpnt_drv, dai_drv, num_dai);
87 EXPORT_SYMBOL_GPL(devm_snd_soc_register_component);
89 static void devm_card_release(struct device *dev, void *res)
91 snd_soc_unregister_card(*(struct snd_soc_card **)res);
95 * devm_snd_soc_register_card - resource managed card registration
96 * @dev: Device used to manage card
97 * @card: Card to register
99 * Register a card with automatic unregistration when the device is
102 int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card)
104 struct snd_soc_card **ptr;
107 ptr = devres_alloc(devm_card_release, sizeof(*ptr), GFP_KERNEL);
111 ret = snd_soc_register_card(card);
114 devres_add(dev, ptr);
121 EXPORT_SYMBOL_GPL(devm_snd_soc_register_card);
123 #ifdef CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM
125 static void devm_dmaengine_pcm_release(struct device *dev, void *res)
127 snd_dmaengine_pcm_unregister(*(struct device **)res);
131 * devm_snd_dmaengine_pcm_register - resource managed dmaengine PCM registration
132 * @dev: The parent device for the PCM device
133 * @config: Platform specific PCM configuration
134 * @flags: Platform specific quirks
136 * Register a dmaengine based PCM device with automatic unregistration when the
137 * device is unregistered.
139 int devm_snd_dmaengine_pcm_register(struct device *dev,
140 const struct snd_dmaengine_pcm_config *config, unsigned int flags)
145 ptr = devres_alloc(devm_dmaengine_pcm_release, sizeof(*ptr), GFP_KERNEL);
149 ret = snd_dmaengine_pcm_register(dev, config, flags);
152 devres_add(dev, ptr);
159 EXPORT_SYMBOL_GPL(devm_snd_dmaengine_pcm_register);