aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDimitris Papastamos <dp@opensource.wolfsonmicro.com>2011-01-12 05:38:58 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2011-01-12 09:55:23 -0500
commitaea170a099793abcd0e6de46b947458073204241 (patch)
tree187a6851f204b1dd0c98ccce0545248a25c90f24
parentd779fce5d79525d66269c8f6e430e1515d697f3d (diff)
ASoC: soc-cache: Add reg_size as a member to snd_soc_codec
Simplify the use of reg_size, by calculating it once and storing it in the codec structure for later reference. The value of reg_size is reg_cache_size * reg_word_size. 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>
-rw-r--r--include/sound/soc.h1
-rw-r--r--sound/soc/soc-cache.c26
-rw-r--r--sound/soc/soc-core.c1
3 files changed, 10 insertions, 18 deletions
diff --git a/include/sound/soc.h b/include/sound/soc.h
index c477058ff98a..d609232da82a 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -459,6 +459,7 @@ struct snd_soc_codec {
459 struct list_head card_list; 459 struct list_head card_list;
460 int num_dai; 460 int num_dai;
461 enum snd_soc_compress_type compress_type; 461 enum snd_soc_compress_type compress_type;
462 size_t reg_size; /* reg_cache_size * reg_word_size */
462 463
463 /* runtime */ 464 /* runtime */
464 struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */ 465 struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c
index 19b29fb3ca4b..b2e333f5a388 100644
--- a/sound/soc/soc-cache.c
+++ b/sound/soc/soc-cache.c
@@ -1100,34 +1100,28 @@ static inline int snd_soc_lzo_get_blkindex(struct snd_soc_codec *codec,
1100 unsigned int reg) 1100 unsigned int reg)
1101{ 1101{
1102 const struct snd_soc_codec_driver *codec_drv; 1102 const struct snd_soc_codec_driver *codec_drv;
1103 size_t reg_size;
1104 1103
1105 codec_drv = codec->driver; 1104 codec_drv = codec->driver;
1106 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
1107 return (reg * codec_drv->reg_word_size) / 1105 return (reg * codec_drv->reg_word_size) /
1108 DIV_ROUND_UP(reg_size, snd_soc_lzo_block_count()); 1106 DIV_ROUND_UP(codec->reg_size, snd_soc_lzo_block_count());
1109} 1107}
1110 1108
1111static inline int snd_soc_lzo_get_blkpos(struct snd_soc_codec *codec, 1109static inline int snd_soc_lzo_get_blkpos(struct snd_soc_codec *codec,
1112 unsigned int reg) 1110 unsigned int reg)
1113{ 1111{
1114 const struct snd_soc_codec_driver *codec_drv; 1112 const struct snd_soc_codec_driver *codec_drv;
1115 size_t reg_size;
1116 1113
1117 codec_drv = codec->driver; 1114 codec_drv = codec->driver;
1118 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size; 1115 return reg % (DIV_ROUND_UP(codec->reg_size, snd_soc_lzo_block_count()) /
1119 return reg % (DIV_ROUND_UP(reg_size, snd_soc_lzo_block_count()) /
1120 codec_drv->reg_word_size); 1116 codec_drv->reg_word_size);
1121} 1117}
1122 1118
1123static inline int snd_soc_lzo_get_blksize(struct snd_soc_codec *codec) 1119static inline int snd_soc_lzo_get_blksize(struct snd_soc_codec *codec)
1124{ 1120{
1125 const struct snd_soc_codec_driver *codec_drv; 1121 const struct snd_soc_codec_driver *codec_drv;
1126 size_t reg_size;
1127 1122
1128 codec_drv = codec->driver; 1123 codec_drv = codec->driver;
1129 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size; 1124 return DIV_ROUND_UP(codec->reg_size, snd_soc_lzo_block_count());
1130 return DIV_ROUND_UP(reg_size, snd_soc_lzo_block_count());
1131} 1125}
1132 1126
1133static int snd_soc_lzo_cache_sync(struct snd_soc_codec *codec) 1127static int snd_soc_lzo_cache_sync(struct snd_soc_codec *codec)
@@ -1287,7 +1281,7 @@ static int snd_soc_lzo_cache_exit(struct snd_soc_codec *codec)
1287static int snd_soc_lzo_cache_init(struct snd_soc_codec *codec) 1281static int snd_soc_lzo_cache_init(struct snd_soc_codec *codec)
1288{ 1282{
1289 struct snd_soc_lzo_ctx **lzo_blocks; 1283 struct snd_soc_lzo_ctx **lzo_blocks;
1290 size_t reg_size, bmp_size; 1284 size_t bmp_size;
1291 const struct snd_soc_codec_driver *codec_drv; 1285 const struct snd_soc_codec_driver *codec_drv;
1292 int ret, tofree, i, blksize, blkcount; 1286 int ret, tofree, i, blksize, blkcount;
1293 const char *p, *end; 1287 const char *p, *end;
@@ -1295,7 +1289,6 @@ static int snd_soc_lzo_cache_init(struct snd_soc_codec *codec)
1295 1289
1296 ret = 0; 1290 ret = 0;
1297 codec_drv = codec->driver; 1291 codec_drv = codec->driver;
1298 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
1299 1292
1300 /* 1293 /*
1301 * If we have not been given a default register cache 1294 * If we have not been given a default register cache
@@ -1307,8 +1300,7 @@ static int snd_soc_lzo_cache_init(struct snd_soc_codec *codec)
1307 tofree = 1; 1300 tofree = 1;
1308 1301
1309 if (!codec->reg_def_copy) { 1302 if (!codec->reg_def_copy) {
1310 codec->reg_def_copy = kzalloc(reg_size, 1303 codec->reg_def_copy = kzalloc(codec->reg_size, GFP_KERNEL);
1311 GFP_KERNEL);
1312 if (!codec->reg_def_copy) 1304 if (!codec->reg_def_copy)
1313 return -ENOMEM; 1305 return -ENOMEM;
1314 } 1306 }
@@ -1356,7 +1348,7 @@ static int snd_soc_lzo_cache_init(struct snd_soc_codec *codec)
1356 1348
1357 blksize = snd_soc_lzo_get_blksize(codec); 1349 blksize = snd_soc_lzo_get_blksize(codec);
1358 p = codec->reg_def_copy; 1350 p = codec->reg_def_copy;
1359 end = codec->reg_def_copy + reg_size; 1351 end = codec->reg_def_copy + codec->reg_size;
1360 /* compress the register map and fill the lzo blocks */ 1352 /* compress the register map and fill the lzo blocks */
1361 for (i = 0; i < blkcount; ++i, p += blksize) { 1353 for (i = 0; i < blkcount; ++i, p += blksize) {
1362 lzo_blocks[i]->src = p; 1354 lzo_blocks[i]->src = p;
@@ -1441,16 +1433,14 @@ static int snd_soc_flat_cache_exit(struct snd_soc_codec *codec)
1441static int snd_soc_flat_cache_init(struct snd_soc_codec *codec) 1433static int snd_soc_flat_cache_init(struct snd_soc_codec *codec)
1442{ 1434{
1443 const struct snd_soc_codec_driver *codec_drv; 1435 const struct snd_soc_codec_driver *codec_drv;
1444 size_t reg_size;
1445 1436
1446 codec_drv = codec->driver; 1437 codec_drv = codec->driver;
1447 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
1448 1438
1449 if (codec->reg_def_copy) 1439 if (codec->reg_def_copy)
1450 codec->reg_cache = kmemdup(codec->reg_def_copy, 1440 codec->reg_cache = kmemdup(codec->reg_def_copy,
1451 reg_size, GFP_KERNEL); 1441 codec->reg_size, GFP_KERNEL);
1452 else 1442 else
1453 codec->reg_cache = kzalloc(reg_size, GFP_KERNEL); 1443 codec->reg_cache = kzalloc(codec->reg_size, GFP_KERNEL);
1454 if (!codec->reg_cache) 1444 if (!codec->reg_cache)
1455 return -ENOMEM; 1445 return -ENOMEM;
1456 1446
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 04475c18003c..cbac50b69c39 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -3500,6 +3500,7 @@ int snd_soc_register_codec(struct device *dev,
3500 /* allocate CODEC register cache */ 3500 /* allocate CODEC register cache */
3501 if (codec_drv->reg_cache_size && codec_drv->reg_word_size) { 3501 if (codec_drv->reg_cache_size && codec_drv->reg_word_size) {
3502 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size; 3502 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
3503 codec->reg_size = reg_size;
3503 /* it is necessary to make a copy of the default register cache 3504 /* it is necessary to make a copy of the default register cache
3504 * because in the case of using a compression type that requires 3505 * because in the case of using a compression type that requires
3505 * the default register cache to be marked as __devinitconst the 3506 * the default register cache to be marked as __devinitconst the