0001
0002
0003
0004
0005
0006
0007 #include <linux/module.h>
0008 #include <linux/moduleparam.h>
0009 #include <sound/soc.h>
0010 #include <sound/dmaengine_pcm.h>
0011
0012 static void devm_dai_release(struct device *dev, void *res)
0013 {
0014 snd_soc_unregister_dai(*(struct snd_soc_dai **)res);
0015 }
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 struct snd_soc_dai *devm_snd_soc_register_dai(struct device *dev,
0026 struct snd_soc_component *component,
0027 struct snd_soc_dai_driver *dai_drv,
0028 bool legacy_dai_naming)
0029 {
0030 struct snd_soc_dai **ptr;
0031 struct snd_soc_dai *dai;
0032
0033 ptr = devres_alloc(devm_dai_release, sizeof(*ptr), GFP_KERNEL);
0034 if (!ptr)
0035 return NULL;
0036
0037 dai = snd_soc_register_dai(component, dai_drv, legacy_dai_naming);
0038 if (dai) {
0039 *ptr = dai;
0040 devres_add(dev, ptr);
0041 } else {
0042 devres_free(ptr);
0043 }
0044
0045 return dai;
0046 }
0047 EXPORT_SYMBOL_GPL(devm_snd_soc_register_dai);
0048
0049 static void devm_component_release(struct device *dev, void *res)
0050 {
0051 const struct snd_soc_component_driver **cmpnt_drv = res;
0052
0053 snd_soc_unregister_component_by_driver(dev, *cmpnt_drv);
0054 }
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066 int devm_snd_soc_register_component(struct device *dev,
0067 const struct snd_soc_component_driver *cmpnt_drv,
0068 struct snd_soc_dai_driver *dai_drv, int num_dai)
0069 {
0070 const struct snd_soc_component_driver **ptr;
0071 int ret;
0072
0073 ptr = devres_alloc(devm_component_release, sizeof(*ptr), GFP_KERNEL);
0074 if (!ptr)
0075 return -ENOMEM;
0076
0077 ret = snd_soc_register_component(dev, cmpnt_drv, dai_drv, num_dai);
0078 if (ret == 0) {
0079 *ptr = cmpnt_drv;
0080 devres_add(dev, ptr);
0081 } else {
0082 devres_free(ptr);
0083 }
0084
0085 return ret;
0086 }
0087 EXPORT_SYMBOL_GPL(devm_snd_soc_register_component);
0088
0089 static void devm_card_release(struct device *dev, void *res)
0090 {
0091 snd_soc_unregister_card(*(struct snd_soc_card **)res);
0092 }
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102 int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card)
0103 {
0104 struct snd_soc_card **ptr;
0105 int ret;
0106
0107 ptr = devres_alloc(devm_card_release, sizeof(*ptr), GFP_KERNEL);
0108 if (!ptr)
0109 return -ENOMEM;
0110
0111 ret = snd_soc_register_card(card);
0112 if (ret == 0) {
0113 *ptr = card;
0114 devres_add(dev, ptr);
0115 } else {
0116 devres_free(ptr);
0117 }
0118
0119 return ret;
0120 }
0121 EXPORT_SYMBOL_GPL(devm_snd_soc_register_card);
0122
0123 #ifdef CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM
0124
0125 static void devm_dmaengine_pcm_release(struct device *dev, void *res)
0126 {
0127 snd_dmaengine_pcm_unregister(*(struct device **)res);
0128 }
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139 int devm_snd_dmaengine_pcm_register(struct device *dev,
0140 const struct snd_dmaengine_pcm_config *config, unsigned int flags)
0141 {
0142 struct device **ptr;
0143 int ret;
0144
0145 ptr = devres_alloc(devm_dmaengine_pcm_release, sizeof(*ptr), GFP_KERNEL);
0146 if (!ptr)
0147 return -ENOMEM;
0148
0149 ret = snd_dmaengine_pcm_register(dev, config, flags);
0150 if (ret == 0) {
0151 *ptr = dev;
0152 devres_add(dev, ptr);
0153 } else {
0154 devres_free(ptr);
0155 }
0156
0157 return ret;
0158 }
0159 EXPORT_SYMBOL_GPL(devm_snd_dmaengine_pcm_register);
0160
0161 #endif