Blame view

sound/soc/soc-cache.c 1.33 KB
17a52fd60   Mark Brown   ASoC: Begin to fa...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  /*
   * soc-cache.c  --  ASoC register cache helpers
   *
   * Copyright 2009 Wolfson Microelectronics PLC.
   *
   * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
   *
   *  This program is free software; you can redistribute  it and/or modify it
   *  under  the terms of  the GNU General  Public License as published by the
   *  Free Software Foundation;  either version 2 of the  License, or (at your
   *  option) any later version.
   */
  
  #include <sound/soc.h>
d81a6d717   Paul Gortmaker   sound: Add export...
15
  #include <linux/export.h>
f90fb3f77   Lars-Peter Clausen   ASoC: Remove infr...
16
  #include <linux/slab.h>
17a52fd60   Mark Brown   ASoC: Begin to fa...
17

f90fb3f77   Lars-Peter Clausen   ASoC: Remove infr...
18
  int snd_soc_cache_init(struct snd_soc_codec *codec)
7a30a3db3   Dimitris Papastamos   ASoC: soc-cache: ...
19
  {
b012aa619   Lars-Peter Clausen   ASoC: Remove reg_...
20
  	const struct snd_soc_codec_driver *codec_drv = codec->driver;
a94ed2343   Lars-Peter Clausen   ASoC: Remove 'reg...
21
22
23
  	size_t reg_size;
  
  	reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
b012aa619   Lars-Peter Clausen   ASoC: Remove reg_...
24

b59dce53e   Xiubo Li   ASoC: cache: Fix ...
25
  	if (!reg_size)
b5fc40d3b   Mark Brown   ASoC: cache: Fix ...
26
  		return 0;
b59dce53e   Xiubo Li   ASoC: cache: Fix ...
27

f90fb3f77   Lars-Peter Clausen   ASoC: Remove infr...
28
29
  	dev_dbg(codec->dev, "ASoC: Initializing cache for %s codec
  ",
f4333203e   Lars-Peter Clausen   ASoC: Move name a...
30
  				codec->component.name);
f90fb3f77   Lars-Peter Clausen   ASoC: Remove infr...
31

b012aa619   Lars-Peter Clausen   ASoC: Remove reg_...
32
33
  	if (codec_drv->reg_cache_default)
  		codec->reg_cache = kmemdup(codec_drv->reg_cache_default,
a94ed2343   Lars-Peter Clausen   ASoC: Remove 'reg...
34
  					   reg_size, GFP_KERNEL);
7a30a3db3   Dimitris Papastamos   ASoC: soc-cache: ...
35
  	else
a94ed2343   Lars-Peter Clausen   ASoC: Remove 'reg...
36
  		codec->reg_cache = kzalloc(reg_size, GFP_KERNEL);
7a30a3db3   Dimitris Papastamos   ASoC: soc-cache: ...
37
38
39
40
41
  	if (!codec->reg_cache)
  		return -ENOMEM;
  
  	return 0;
  }
7a30a3db3   Dimitris Papastamos   ASoC: soc-cache: ...
42
43
44
45
46
47
  /*
   * NOTE: keep in mind that this function might be called
   * multiple times.
   */
  int snd_soc_cache_exit(struct snd_soc_codec *codec)
  {
f90fb3f77   Lars-Peter Clausen   ASoC: Remove infr...
48
49
  	dev_dbg(codec->dev, "ASoC: Destroying cache for %s codec
  ",
f4333203e   Lars-Peter Clausen   ASoC: Move name a...
50
  			codec->component.name);
f90fb3f77   Lars-Peter Clausen   ASoC: Remove infr...
51
52
53
  	kfree(codec->reg_cache);
  	codec->reg_cache = NULL;
  	return 0;
7a30a3db3   Dimitris Papastamos   ASoC: soc-cache: ...
54
  }