blob: a9ea172a66a700c36fbbf02484ed00ae5ec03f81 [file] [log] [blame]
Kuninori Morimoto9e140352018-07-02 06:23:45 +00001// SPDX-License-Identifier: GPL-2.0+
2//
3// soc-devres.c -- ALSA SoC Audio Layer devres functions
4//
5// Copyright (C) 2013 Linaro Ltd
Mark Browna0b03a62013-09-04 20:37:34 +01006
7#include <linux/module.h>
8#include <linux/moduleparam.h>
9#include <sound/soc.h>
Lars-Peter Clausen21585ee2013-11-28 08:50:32 +010010#include <sound/dmaengine_pcm.h>
Mark Browna0b03a62013-09-04 20:37:34 +010011
12static void devm_component_release(struct device *dev, void *res)
13{
14 snd_soc_unregister_component(*(struct device **)res);
15}
16
17/**
18 * devm_snd_soc_register_component - resource managed component registration
19 * @dev: Device used to manage component
20 * @cmpnt_drv: Component driver
21 * @dai_drv: DAI driver
22 * @num_dai: Number of DAIs to register
23 *
24 * Register a component with automatic unregistration when the device is
25 * unregistered.
26 */
27int devm_snd_soc_register_component(struct device *dev,
28 const struct snd_soc_component_driver *cmpnt_drv,
29 struct snd_soc_dai_driver *dai_drv, int num_dai)
30{
31 struct device **ptr;
32 int ret;
33
34 ptr = devres_alloc(devm_component_release, sizeof(*ptr), GFP_KERNEL);
35 if (!ptr)
36 return -ENOMEM;
37
38 ret = snd_soc_register_component(dev, cmpnt_drv, dai_drv, num_dai);
39 if (ret == 0) {
40 *ptr = dev;
41 devres_add(dev, ptr);
42 } else {
43 devres_free(ptr);
44 }
45
46 return ret;
47}
48EXPORT_SYMBOL_GPL(devm_snd_soc_register_component);
Mark Brown0e4ff5c2013-09-16 18:02:05 +010049
50static void devm_card_release(struct device *dev, void *res)
51{
52 snd_soc_unregister_card(*(struct snd_soc_card **)res);
53}
54
55/**
56 * devm_snd_soc_register_card - resource managed card registration
57 * @dev: Device used to manage card
58 * @card: Card to register
59 *
60 * Register a card with automatic unregistration when the device is
61 * unregistered.
62 */
63int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card)
64{
Shawn Guoebff6542013-12-02 13:26:50 +080065 struct snd_soc_card **ptr;
Mark Brown0e4ff5c2013-09-16 18:02:05 +010066 int ret;
67
68 ptr = devres_alloc(devm_card_release, sizeof(*ptr), GFP_KERNEL);
69 if (!ptr)
70 return -ENOMEM;
71
72 ret = snd_soc_register_card(card);
73 if (ret == 0) {
Shawn Guoebff6542013-12-02 13:26:50 +080074 *ptr = card;
Mark Brown0e4ff5c2013-09-16 18:02:05 +010075 devres_add(dev, ptr);
76 } else {
77 devres_free(ptr);
78 }
79
80 return ret;
81}
82EXPORT_SYMBOL_GPL(devm_snd_soc_register_card);
Lars-Peter Clausen21585ee2013-11-28 08:50:32 +010083
84#ifdef CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM
85
86static void devm_dmaengine_pcm_release(struct device *dev, void *res)
87{
88 snd_dmaengine_pcm_unregister(*(struct device **)res);
89}
90
91/**
92 * devm_snd_dmaengine_pcm_register - resource managed dmaengine PCM registration
93 * @dev: The parent device for the PCM device
94 * @config: Platform specific PCM configuration
95 * @flags: Platform specific quirks
96 *
97 * Register a dmaengine based PCM device with automatic unregistration when the
98 * device is unregistered.
99 */
100int devm_snd_dmaengine_pcm_register(struct device *dev,
101 const struct snd_dmaengine_pcm_config *config, unsigned int flags)
102{
103 struct device **ptr;
104 int ret;
105
106 ptr = devres_alloc(devm_dmaengine_pcm_release, sizeof(*ptr), GFP_KERNEL);
107 if (!ptr)
108 return -ENOMEM;
109
110 ret = snd_dmaengine_pcm_register(dev, config, flags);
111 if (ret == 0) {
112 *ptr = dev;
113 devres_add(dev, ptr);
114 } else {
115 devres_free(ptr);
116 }
117
118 return ret;
119}
120EXPORT_SYMBOL_GPL(devm_snd_dmaengine_pcm_register);
121
122#endif