2009-07-05 20:24:50 +04:00
|
|
|
/*
|
|
|
|
* 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>
|
2011-09-22 17:34:58 +04:00
|
|
|
#include <linux/export.h>
|
2013-08-31 22:31:15 +04:00
|
|
|
#include <linux/slab.h>
|
2009-07-05 20:24:50 +04:00
|
|
|
|
2013-08-31 22:31:15 +04:00
|
|
|
int snd_soc_cache_init(struct snd_soc_codec *codec)
|
2010-11-11 13:04:57 +03:00
|
|
|
{
|
2013-08-31 22:31:13 +04:00
|
|
|
const struct snd_soc_codec_driver *codec_drv = codec->driver;
|
2013-08-31 22:31:14 +04:00
|
|
|
size_t reg_size;
|
|
|
|
|
|
|
|
reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
|
2013-08-31 22:31:13 +04:00
|
|
|
|
2014-05-19 12:32:09 +04:00
|
|
|
if (!reg_size)
|
2014-06-02 19:08:21 +04:00
|
|
|
return 0;
|
2014-05-19 12:32:09 +04:00
|
|
|
|
2013-08-31 22:31:15 +04:00
|
|
|
dev_dbg(codec->dev, "ASoC: Initializing cache for %s codec\n",
|
2014-06-16 20:13:02 +04:00
|
|
|
codec->component.name);
|
2013-08-31 22:31:15 +04:00
|
|
|
|
2013-08-31 22:31:13 +04:00
|
|
|
if (codec_drv->reg_cache_default)
|
|
|
|
codec->reg_cache = kmemdup(codec_drv->reg_cache_default,
|
2013-08-31 22:31:14 +04:00
|
|
|
reg_size, GFP_KERNEL);
|
2010-11-11 13:04:57 +03:00
|
|
|
else
|
2013-08-31 22:31:14 +04:00
|
|
|
codec->reg_cache = kzalloc(reg_size, GFP_KERNEL);
|
2010-11-11 13:04:57 +03:00
|
|
|
if (!codec->reg_cache)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE: keep in mind that this function might be called
|
|
|
|
* multiple times.
|
|
|
|
*/
|
|
|
|
int snd_soc_cache_exit(struct snd_soc_codec *codec)
|
|
|
|
{
|
2013-08-31 22:31:15 +04:00
|
|
|
dev_dbg(codec->dev, "ASoC: Destroying cache for %s codec\n",
|
2014-06-16 20:13:02 +04:00
|
|
|
codec->component.name);
|
2013-08-31 22:31:15 +04:00
|
|
|
kfree(codec->reg_cache);
|
|
|
|
codec->reg_cache = NULL;
|
|
|
|
return 0;
|
2010-11-11 13:04:57 +03:00
|
|
|
}
|