2 * soc-cache.c -- ASoC register cache helpers
4 * Copyright 2009 Wolfson Microelectronics PLC.
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
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.
14 #include <sound/soc.h>
15 #include <linux/export.h>
16 #include <linux/slab.h>
18 int snd_soc_cache_init(struct snd_soc_codec *codec)
20 const struct snd_soc_codec_driver *codec_drv = codec->driver;
23 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
28 dev_dbg(codec->dev, "ASoC: Initializing cache for %s codec\n",
29 codec->component.name);
31 if (codec_drv->reg_cache_default)
32 codec->reg_cache = kmemdup(codec_drv->reg_cache_default,
33 reg_size, GFP_KERNEL);
35 codec->reg_cache = kzalloc(reg_size, GFP_KERNEL);
36 if (!codec->reg_cache)
43 * NOTE: keep in mind that this function might be called
46 int snd_soc_cache_exit(struct snd_soc_codec *codec)
48 dev_dbg(codec->dev, "ASoC: Destroying cache for %s codec\n",
49 codec->component.name);
50 kfree(codec->reg_cache);
51 codec->reg_cache = NULL;