Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 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> |
Paul Gortmaker | d81a6d7 | 2011-09-22 09:34:58 -0400 | [diff] [blame] | 15 | #include <linux/export.h> |
Lars-Peter Clausen | f90fb3f | 2013-08-31 20:31:15 +0200 | [diff] [blame] | 16 | #include <linux/slab.h> |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 17 | |
Lars-Peter Clausen | f90fb3f | 2013-08-31 20:31:15 +0200 | [diff] [blame] | 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 | |
Xiubo Li | b59dce5 | 2014-05-19 16:32:09 +0800 | [diff] [blame] | 25 | if (!reg_size) |
Mark Brown | b5fc40d | 2014-06-02 16:08:21 +0100 | [diff] [blame] | 26 | return 0; |
Xiubo Li | b59dce5 | 2014-05-19 16:32:09 +0800 | [diff] [blame] | 27 | |
Lars-Peter Clausen | f90fb3f | 2013-08-31 20:31:15 +0200 | [diff] [blame] | 28 | dev_dbg(codec->dev, "ASoC: Initializing cache for %s codec\n", |
Lars-Peter Clausen | f433320 | 2014-06-16 18:13:02 +0200 | [diff] [blame] | 29 | codec->component.name); |
Lars-Peter Clausen | f90fb3f | 2013-08-31 20:31:15 +0200 | [diff] [blame] | 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", |
Lars-Peter Clausen | f433320 | 2014-06-16 18:13:02 +0200 | [diff] [blame] | 49 | codec->component.name); |
Lars-Peter Clausen | f90fb3f | 2013-08-31 20:31:15 +0200 | [diff] [blame] | 50 | kfree(codec->reg_cache); |
| 51 | codec->reg_cache = NULL; |
| 52 | return 0; |
| 53 | } |