| .. | .. |
|---|
| 9 | 9 | #include <sound/soc.h> |
|---|
| 10 | 10 | #include <sound/dmaengine_pcm.h> |
|---|
| 11 | 11 | |
|---|
| 12 | +static void devm_dai_release(struct device *dev, void *res) |
|---|
| 13 | +{ |
|---|
| 14 | + snd_soc_unregister_dai(*(struct snd_soc_dai **)res); |
|---|
| 15 | +} |
|---|
| 16 | + |
|---|
| 17 | +/** |
|---|
| 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; |
|---|
| 24 | + */ |
|---|
| 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) |
|---|
| 29 | +{ |
|---|
| 30 | + struct snd_soc_dai **ptr; |
|---|
| 31 | + struct snd_soc_dai *dai; |
|---|
| 32 | + |
|---|
| 33 | + ptr = devres_alloc(devm_dai_release, sizeof(*ptr), GFP_KERNEL); |
|---|
| 34 | + if (!ptr) |
|---|
| 35 | + return NULL; |
|---|
| 36 | + |
|---|
| 37 | + dai = snd_soc_register_dai(component, dai_drv, legacy_dai_naming); |
|---|
| 38 | + if (dai) { |
|---|
| 39 | + *ptr = dai; |
|---|
| 40 | + devres_add(dev, ptr); |
|---|
| 41 | + } else { |
|---|
| 42 | + devres_free(ptr); |
|---|
| 43 | + } |
|---|
| 44 | + |
|---|
| 45 | + return dai; |
|---|
| 46 | +} |
|---|
| 47 | +EXPORT_SYMBOL_GPL(devm_snd_soc_register_dai); |
|---|
| 48 | + |
|---|
| 12 | 49 | static void devm_component_release(struct device *dev, void *res) |
|---|
| 13 | 50 | { |
|---|
| 14 | | - snd_soc_unregister_component(*(struct device **)res); |
|---|
| 51 | + const struct snd_soc_component_driver **cmpnt_drv = res; |
|---|
| 52 | + |
|---|
| 53 | + snd_soc_unregister_component_by_driver(dev, *cmpnt_drv); |
|---|
| 15 | 54 | } |
|---|
| 16 | 55 | |
|---|
| 17 | 56 | /** |
|---|
| .. | .. |
|---|
| 28 | 67 | const struct snd_soc_component_driver *cmpnt_drv, |
|---|
| 29 | 68 | struct snd_soc_dai_driver *dai_drv, int num_dai) |
|---|
| 30 | 69 | { |
|---|
| 31 | | - struct device **ptr; |
|---|
| 70 | + const struct snd_soc_component_driver **ptr; |
|---|
| 32 | 71 | int ret; |
|---|
| 33 | 72 | |
|---|
| 34 | 73 | ptr = devres_alloc(devm_component_release, sizeof(*ptr), GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 37 | 76 | |
|---|
| 38 | 77 | ret = snd_soc_register_component(dev, cmpnt_drv, dai_drv, num_dai); |
|---|
| 39 | 78 | if (ret == 0) { |
|---|
| 40 | | - *ptr = dev; |
|---|
| 79 | + *ptr = cmpnt_drv; |
|---|
| 41 | 80 | devres_add(dev, ptr); |
|---|
| 42 | 81 | } else { |
|---|
| 43 | 82 | devres_free(ptr); |
|---|