kvm: x86: Make sync_page() flush remote TLBs once only
[linux/fpc-iii.git] / sound / soc / soc-devres.c
blob7ac745df1412689c6adf0bf246399870b79e44e7
1 /*
2 * soc-devres.c -- ALSA SoC Audio Layer devres functions
4 * Copyright (C) 2013 Linaro Ltd
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.
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <sound/soc.h>
15 #include <sound/dmaengine_pcm.h>
17 static void devm_component_release(struct device *dev, void *res)
19 snd_soc_unregister_component(*(struct device **)res);
22 /**
23 * devm_snd_soc_register_component - resource managed component registration
24 * @dev: Device used to manage component
25 * @cmpnt_drv: Component driver
26 * @dai_drv: DAI driver
27 * @num_dai: Number of DAIs to register
29 * Register a component with automatic unregistration when the device is
30 * unregistered.
32 int devm_snd_soc_register_component(struct device *dev,
33 const struct snd_soc_component_driver *cmpnt_drv,
34 struct snd_soc_dai_driver *dai_drv, int num_dai)
36 struct device **ptr;
37 int ret;
39 ptr = devres_alloc(devm_component_release, sizeof(*ptr), GFP_KERNEL);
40 if (!ptr)
41 return -ENOMEM;
43 ret = snd_soc_register_component(dev, cmpnt_drv, dai_drv, num_dai);
44 if (ret == 0) {
45 *ptr = dev;
46 devres_add(dev, ptr);
47 } else {
48 devres_free(ptr);
51 return ret;
53 EXPORT_SYMBOL_GPL(devm_snd_soc_register_component);
55 static void devm_card_release(struct device *dev, void *res)
57 snd_soc_unregister_card(*(struct snd_soc_card **)res);
60 /**
61 * devm_snd_soc_register_card - resource managed card registration
62 * @dev: Device used to manage card
63 * @card: Card to register
65 * Register a card with automatic unregistration when the device is
66 * unregistered.
68 int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card)
70 struct snd_soc_card **ptr;
71 int ret;
73 ptr = devres_alloc(devm_card_release, sizeof(*ptr), GFP_KERNEL);
74 if (!ptr)
75 return -ENOMEM;
77 ret = snd_soc_register_card(card);
78 if (ret == 0) {
79 *ptr = card;
80 devres_add(dev, ptr);
81 } else {
82 devres_free(ptr);
85 return ret;
87 EXPORT_SYMBOL_GPL(devm_snd_soc_register_card);
89 #ifdef CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM
91 static void devm_dmaengine_pcm_release(struct device *dev, void *res)
93 snd_dmaengine_pcm_unregister(*(struct device **)res);
96 /**
97 * devm_snd_dmaengine_pcm_register - resource managed dmaengine PCM registration
98 * @dev: The parent device for the PCM device
99 * @config: Platform specific PCM configuration
100 * @flags: Platform specific quirks
102 * Register a dmaengine based PCM device with automatic unregistration when the
103 * device is unregistered.
105 int devm_snd_dmaengine_pcm_register(struct device *dev,
106 const struct snd_dmaengine_pcm_config *config, unsigned int flags)
108 struct device **ptr;
109 int ret;
111 ptr = devres_alloc(devm_dmaengine_pcm_release, sizeof(*ptr), GFP_KERNEL);
112 if (!ptr)
113 return -ENOMEM;
115 ret = snd_dmaengine_pcm_register(dev, config, flags);
116 if (ret == 0) {
117 *ptr = dev;
118 devres_add(dev, ptr);
119 } else {
120 devres_free(ptr);
123 return ret;
125 EXPORT_SYMBOL_GPL(devm_snd_dmaengine_pcm_register);
127 #endif