writeback: Fix performance regression in wb_over_bg_thresh()
[deliverable/linux.git] / sound / soc / soc-cache.c
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
14 #include <sound/soc.h>
15 #include <linux/export.h>
16 #include <linux/slab.h>
17
18 int snd_soc_cache_init(struct snd_soc_codec *codec)
19 {
20 const struct snd_soc_codec_driver *codec_drv = codec->driver;
21 size_t reg_size;
22
23 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
24
25 if (!reg_size)
26 return 0;
27
28 dev_dbg(codec->dev, "ASoC: Initializing cache for %s codec\n",
29 codec->component.name);
30
31 if (codec_drv->reg_cache_default)
32 codec->reg_cache = kmemdup(codec_drv->reg_cache_default,
33 reg_size, GFP_KERNEL);
34 else
35 codec->reg_cache = kzalloc(reg_size, GFP_KERNEL);
36 if (!codec->reg_cache)
37 return -ENOMEM;
38
39 return 0;
40 }
41
42 /*
43 * NOTE: keep in mind that this function might be called
44 * multiple times.
45 */
46 int snd_soc_cache_exit(struct snd_soc_codec *codec)
47 {
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;
52 return 0;
53 }
This page took 0.030323 seconds and 5 git commands to generate.