Merge git://git.infradead.org/mtd-2.6
[pandora-kernel.git] / sound / soc / soc-cache.c
index ff2bc8b..8c2a21a 100644 (file)
@@ -85,7 +85,7 @@ static int snd_soc_4_12_spi_write(void *control_data, const char *data,
        msg[1] = data[0];
 
        spi_message_init(&m);
-       memset(&t, 0, (sizeof t));
+       memset(&t, 0, sizeof t);
 
        t.tx_buf = &msg[0];
        t.len = len;
@@ -166,7 +166,7 @@ static int snd_soc_7_9_spi_write(void *control_data, const char *data,
        msg[1] = data[1];
 
        spi_message_init(&m);
-       memset(&t, 0, (sizeof t));
+       memset(&t, 0, sizeof t);
 
        t.tx_buf = &msg[0];
        t.len = len;
@@ -246,7 +246,7 @@ static int snd_soc_8_8_spi_write(void *control_data, const char *data,
        msg[1] = data[1];
 
        spi_message_init(&m);
-       memset(&t, 0, (sizeof t));
+       memset(&t, 0, sizeof t);
 
        t.tx_buf = &msg[0];
        t.len = len;
@@ -326,7 +326,7 @@ static int snd_soc_8_16_spi_write(void *control_data, const char *data,
        msg[2] = data[2];
 
        spi_message_init(&m);
-       memset(&t, 0, (sizeof t));
+       memset(&t, 0, sizeof t);
 
        t.tx_buf = &msg[0];
        t.len = len;
@@ -513,7 +513,7 @@ static int snd_soc_16_8_spi_write(void *control_data, const char *data,
        msg[2] = data[2];
 
        spi_message_init(&m);
-       memset(&t, 0, (sizeof t));
+       memset(&t, 0, sizeof t);
 
        t.tx_buf = &msg[0];
        t.len = len;
@@ -633,7 +633,7 @@ static int snd_soc_16_16_spi_write(void *control_data, const char *data,
        msg[3] = data[3];
 
        spi_message_init(&m);
-       memset(&t, 0, (sizeof t));
+       memset(&t, 0, sizeof t);
 
        t.tx_buf = &msg[0];
        t.len = len;
@@ -988,6 +988,7 @@ static int snd_soc_rbtree_cache_init(struct snd_soc_codec *codec)
        return 0;
 }
 
+#ifdef CONFIG_SND_SOC_CACHE_LZO
 struct snd_soc_lzo_ctx {
        void *wmem;
        void *dst;
@@ -1342,7 +1343,7 @@ static int snd_soc_lzo_cache_init(struct snd_soc_codec *codec)
         * that register.
         */
        bmp_size = codec_drv->reg_cache_size;
-       sync_bmp = kmalloc(BITS_TO_LONGS(bmp_size) * sizeof (long),
+       sync_bmp = kmalloc(BITS_TO_LONGS(bmp_size) * sizeof(long),
                           GFP_KERNEL);
        if (!sync_bmp) {
                ret = -ENOMEM;
@@ -1360,7 +1361,7 @@ static int snd_soc_lzo_cache_init(struct snd_soc_codec *codec)
                        goto err;
                }
                lzo_blocks[i]->sync_bmp = sync_bmp;
-               lzo_blocks[i]->sync_bmp_nbits = reg_size;
+               lzo_blocks[i]->sync_bmp_nbits = bmp_size;
                /* alloc the working space for the compressed block */
                ret = snd_soc_lzo_prepare(lzo_blocks[i]);
                if (ret < 0)
@@ -1399,6 +1400,7 @@ err_tofree:
        }
        return ret;
 }
+#endif
 
 static int snd_soc_flat_cache_sync(struct snd_soc_codec *codec)
 {
@@ -1531,24 +1533,30 @@ static int snd_soc_flat_cache_init(struct snd_soc_codec *codec)
 
 /* an array of all supported compression types */
 static const struct snd_soc_cache_ops cache_types[] = {
+       /* Flat *must* be the first entry for fallback */
        {
                .id = SND_SOC_FLAT_COMPRESSION,
+               .name = "flat",
                .init = snd_soc_flat_cache_init,
                .exit = snd_soc_flat_cache_exit,
                .read = snd_soc_flat_cache_read,
                .write = snd_soc_flat_cache_write,
                .sync = snd_soc_flat_cache_sync
        },
+#ifdef CONFIG_SND_SOC_CACHE_LZO
        {
                .id = SND_SOC_LZO_COMPRESSION,
+               .name = "LZO",
                .init = snd_soc_lzo_cache_init,
                .exit = snd_soc_lzo_cache_exit,
                .read = snd_soc_lzo_cache_read,
                .write = snd_soc_lzo_cache_write,
                .sync = snd_soc_lzo_cache_sync
        },
+#endif
        {
                .id = SND_SOC_RBTREE_COMPRESSION,
+               .name = "rbtree",
                .init = snd_soc_rbtree_cache_init,
                .exit = snd_soc_rbtree_cache_exit,
                .read = snd_soc_rbtree_cache_read,
@@ -1564,17 +1572,23 @@ int snd_soc_cache_init(struct snd_soc_codec *codec)
        for (i = 0; i < ARRAY_SIZE(cache_types); ++i)
                if (cache_types[i].id == codec->compress_type)
                        break;
+
+       /* Fall back to flat compression */
        if (i == ARRAY_SIZE(cache_types)) {
-               dev_err(codec->dev, "Could not match compress type: %d\n",
-                       codec->compress_type);
-               return -EINVAL;
+               dev_warn(codec->dev, "Could not match compress type: %d\n",
+                        codec->compress_type);
+               i = 0;
        }
 
        mutex_init(&codec->cache_rw_mutex);
        codec->cache_ops = &cache_types[i];
 
-       if (codec->cache_ops->init)
+       if (codec->cache_ops->init) {
+               if (codec->cache_ops->name)
+                       dev_dbg(codec->dev, "Initializing %s cache for %s codec\n",
+                               codec->cache_ops->name, codec->name);
                return codec->cache_ops->init(codec);
+       }
        return -EINVAL;
 }
 
@@ -1584,8 +1598,12 @@ int snd_soc_cache_init(struct snd_soc_codec *codec)
  */
 int snd_soc_cache_exit(struct snd_soc_codec *codec)
 {
-       if (codec->cache_ops && codec->cache_ops->exit)
+       if (codec->cache_ops && codec->cache_ops->exit) {
+               if (codec->cache_ops->name)
+                       dev_dbg(codec->dev, "Destroying %s cache for %s codec\n",
+                               codec->cache_ops->name, codec->name);
                return codec->cache_ops->exit(codec);
+       }
        return -EINVAL;
 }
 
@@ -1657,6 +1675,9 @@ int snd_soc_cache_sync(struct snd_soc_codec *codec)
        }
 
        if (codec->cache_ops && codec->cache_ops->sync) {
+               if (codec->cache_ops->name)
+                       dev_dbg(codec->dev, "Syncing %s cache for %s codec\n",
+                               codec->cache_ops->name, codec->name);
                ret = codec->cache_ops->sync(codec);
                if (!ret)
                        codec->cache_sync = 0;