soc-cache.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * soc-cache.c -- ASoC register cache helpers
  3. *
  4. * Copyright 2009 Wolfson Microelectronics PLC.
  5. *
  6. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #include <sound/soc.h>
  14. #include <linux/export.h>
  15. #include <linux/slab.h>
  16. int snd_soc_cache_init(struct snd_soc_codec *codec)
  17. {
  18. const struct snd_soc_codec_driver *codec_drv = codec->driver;
  19. size_t reg_size;
  20. reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
  21. if (!reg_size)
  22. return 0;
  23. dev_dbg(codec->dev, "ASoC: Initializing cache for %s codec\n",
  24. codec->component.name);
  25. if (codec_drv->reg_cache_default)
  26. codec->reg_cache = kmemdup(codec_drv->reg_cache_default,
  27. reg_size, GFP_KERNEL);
  28. else
  29. codec->reg_cache = kzalloc(reg_size, GFP_KERNEL);
  30. if (!codec->reg_cache)
  31. return -ENOMEM;
  32. return 0;
  33. }
  34. /*
  35. * NOTE: keep in mind that this function might be called
  36. * multiple times.
  37. */
  38. int snd_soc_cache_exit(struct snd_soc_codec *codec)
  39. {
  40. dev_dbg(codec->dev, "ASoC: Destroying cache for %s codec\n",
  41. codec->component.name);
  42. kfree(codec->reg_cache);
  43. codec->reg_cache = NULL;
  44. return 0;
  45. }