Commit | Line | Data |
---|---|---|
17a52fd6 MB |
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> | |
d81a6d71 | 15 | #include <linux/export.h> |
f90fb3f7 | 16 | #include <linux/slab.h> |
17a52fd6 | 17 | |
f90fb3f7 | 18 | int snd_soc_cache_init(struct snd_soc_codec *codec) |
7a30a3db | 19 | { |
b012aa61 | 20 | const struct snd_soc_codec_driver *codec_drv = codec->driver; |
a94ed234 LPC |
21 | size_t reg_size; |
22 | ||
23 | reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size; | |
b012aa61 | 24 | |
b59dce53 | 25 | if (!reg_size) |
b5fc40d3 | 26 | return 0; |
b59dce53 | 27 | |
f90fb3f7 | 28 | dev_dbg(codec->dev, "ASoC: Initializing cache for %s codec\n", |
f4333203 | 29 | codec->component.name); |
f90fb3f7 | 30 | |
b012aa61 LPC |
31 | if (codec_drv->reg_cache_default) |
32 | codec->reg_cache = kmemdup(codec_drv->reg_cache_default, | |
a94ed234 | 33 | reg_size, GFP_KERNEL); |
7a30a3db | 34 | else |
a94ed234 | 35 | codec->reg_cache = kzalloc(reg_size, GFP_KERNEL); |
7a30a3db DP |
36 | if (!codec->reg_cache) |
37 | return -ENOMEM; | |
38 | ||
39 | return 0; | |
40 | } | |
41 | ||
7a30a3db DP |
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 | { | |
f90fb3f7 | 48 | dev_dbg(codec->dev, "ASoC: Destroying cache for %s codec\n", |
f4333203 | 49 | codec->component.name); |
f90fb3f7 LPC |
50 | kfree(codec->reg_cache); |
51 | codec->reg_cache = NULL; | |
52 | return 0; | |
7a30a3db | 53 | } |