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