soc-cache.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. }