soc-devres.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * soc-devres.c -- ALSA SoC Audio Layer devres functions
  3. *
  4. * Copyright (C) 2013 Linaro Ltd
  5. *
  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.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/moduleparam.h>
  13. #include <sound/soc.h>
  14. static void devm_component_release(struct device *dev, void *res)
  15. {
  16. snd_soc_unregister_component(*(struct device **)res);
  17. }
  18. /**
  19. * devm_snd_soc_register_component - resource managed component registration
  20. * @dev: Device used to manage component
  21. * @cmpnt_drv: Component driver
  22. * @dai_drv: DAI driver
  23. * @num_dai: Number of DAIs to register
  24. *
  25. * Register a component with automatic unregistration when the device is
  26. * unregistered.
  27. */
  28. int devm_snd_soc_register_component(struct device *dev,
  29. const struct snd_soc_component_driver *cmpnt_drv,
  30. struct snd_soc_dai_driver *dai_drv, int num_dai)
  31. {
  32. struct device **ptr;
  33. int ret;
  34. ptr = devres_alloc(devm_component_release, sizeof(*ptr), GFP_KERNEL);
  35. if (!ptr)
  36. return -ENOMEM;
  37. ret = snd_soc_register_component(dev, cmpnt_drv, dai_drv, num_dai);
  38. if (ret == 0) {
  39. *ptr = dev;
  40. devres_add(dev, ptr);
  41. } else {
  42. devres_free(ptr);
  43. }
  44. return ret;
  45. }
  46. EXPORT_SYMBOL_GPL(devm_snd_soc_register_component);
  47. static void devm_card_release(struct device *dev, void *res)
  48. {
  49. snd_soc_unregister_card(*(struct snd_soc_card **)res);
  50. }
  51. /**
  52. * devm_snd_soc_register_card - resource managed card registration
  53. * @dev: Device used to manage card
  54. * @card: Card to register
  55. *
  56. * Register a card with automatic unregistration when the device is
  57. * unregistered.
  58. */
  59. int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card)
  60. {
  61. struct snd_soc_card **ptr;
  62. int ret;
  63. ptr = devres_alloc(devm_card_release, sizeof(*ptr), GFP_KERNEL);
  64. if (!ptr)
  65. return -ENOMEM;
  66. ret = snd_soc_register_card(card);
  67. if (ret == 0) {
  68. *ptr = card;
  69. devres_add(dev, ptr);
  70. } else {
  71. devres_free(ptr);
  72. }
  73. return ret;
  74. }
  75. EXPORT_SYMBOL_GPL(devm_snd_soc_register_card);