aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-cache.c
diff options
context:
space:
mode:
authorDimitris Papastamos <dp@opensource.wolfsonmicro.com>2011-01-13 07:20:36 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2011-01-13 09:17:32 -0500
commit066d16c3e8194677a9aaeb06a45e4014387d16f1 (patch)
treefbdd51ab4478d56fdba8d3c30a381c248a5a3718 /sound/soc/soc-cache.c
parent3e8e2cc45c9d6b5c1265838a8cff701815321dbc (diff)
ASoC: soc-cache: Add support for default readable()/volatile() functions
For common scenarios, device drivers can provide a table of all the registers that are at least either readable/writable/volatile. The idea is that if a register lookup fails, all of its read/write/vol members will be zero and will be treated as default. This also reduces the size of the register access array. Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> Acked-by: Liam Girdwood <lrg@slimlogic.co.uk> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/soc-cache.c')
-rw-r--r--sound/soc/soc-cache.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c
index 1a36b36c5baa..d97a59f6a249 100644
--- a/sound/soc/soc-cache.c
+++ b/sound/soc/soc-cache.c
@@ -1603,3 +1603,52 @@ int snd_soc_cache_sync(struct snd_soc_codec *codec)
1603 return -EINVAL; 1603 return -EINVAL;
1604} 1604}
1605EXPORT_SYMBOL_GPL(snd_soc_cache_sync); 1605EXPORT_SYMBOL_GPL(snd_soc_cache_sync);
1606
1607static int snd_soc_get_reg_access_index(struct snd_soc_codec *codec,
1608 unsigned int reg)
1609{
1610 const struct snd_soc_codec_driver *codec_drv;
1611 unsigned int min, max, index;
1612
1613 codec_drv = codec->driver;
1614 min = 0;
1615 max = codec_drv->reg_access_size - 1;
1616 do {
1617 index = (min + max) / 2;
1618 if (codec_drv->reg_access_default[index].reg == reg)
1619 return index;
1620 if (codec_drv->reg_access_default[index].reg < reg)
1621 min = index + 1;
1622 else
1623 max = index;
1624 } while (min <= max);
1625 return -1;
1626}
1627
1628int snd_soc_default_volatile_register(struct snd_soc_codec *codec,
1629 unsigned int reg)
1630{
1631 int index;
1632
1633 if (reg >= codec->driver->reg_cache_size)
1634 return 1;
1635 index = snd_soc_get_reg_access_index(codec, reg);
1636 if (index < 0)
1637 return 0;
1638 return codec->driver->reg_access_default[index].vol;
1639}
1640EXPORT_SYMBOL_GPL(snd_soc_default_volatile_register);
1641
1642int snd_soc_default_readable_register(struct snd_soc_codec *codec,
1643 unsigned int reg)
1644{
1645 int index;
1646
1647 if (reg >= codec->driver->reg_cache_size)
1648 return 1;
1649 index = snd_soc_get_reg_access_index(codec, reg);
1650 if (index < 0)
1651 return 0;
1652 return codec->driver->reg_access_default[index].read;
1653}
1654EXPORT_SYMBOL_GPL(snd_soc_default_readable_register);