]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
ALSA: ASoC: Allow codecs to override register display
authorMark Brown <broonie@opensource.wolfsonmicro.com>
Tue, 29 Jul 2008 10:42:25 +0000 (11:42 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 29 Jul 2008 19:32:15 +0000 (21:32 +0200)
Some codecs have unusual features in their register maps such as very
large registers representing arrays of coefficients. Support these
codecs in the register cache sysfs file by allowing them to provide a
function register_display() overriding the default output for register
contents.

Also ensure that we don't overflow PAGE_SIZE while writing out the
register dump.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
include/sound/soc.h
sound/soc/soc-core.c

index 1890d87c52042adc4d375953195a350d20e198ea..2ce530efcf116b94f88f070957dbb627ffab32c3 100644 (file)
@@ -410,6 +410,8 @@ struct snd_soc_codec {
        void *control_data; /* codec control (i2c/3wire) data */
        unsigned int (*read)(struct snd_soc_codec *, unsigned int);
        int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
+       int (*display_register)(struct snd_soc_codec *, char *,
+                               size_t, unsigned int);
        hw_write_t hw_write;
        hw_read_t hw_read;
        void *reg_cache;
index 83f1190293a8287c2a516a81a07575dc7f4933c7..5d3bf731a4b221c10f5271f950e34b2e7a332de1 100644 (file)
@@ -970,9 +970,29 @@ static ssize_t codec_reg_show(struct device *dev,
                step = codec->reg_cache_step;
 
        count += sprintf(buf, "%s registers\n", codec->name);
-       for (i = 0; i < codec->reg_cache_size; i += step)
-               count += sprintf(buf + count, "%2x: %4x\n", i,
-                       codec->read(codec, i));
+       for (i = 0; i < codec->reg_cache_size; i += step) {
+               count += sprintf(buf + count, "%2x: ", i);
+               if (count >= PAGE_SIZE - 1)
+                       break;
+
+               if (codec->display_register)
+                       count += codec->display_register(codec, buf + count,
+                                                        PAGE_SIZE - count, i);
+               else
+                       count += snprintf(buf + count, PAGE_SIZE - count,
+                                         "%4x", codec->read(codec, i));
+
+               if (count >= PAGE_SIZE - 1)
+                       break;
+
+               count += snprintf(buf + count, PAGE_SIZE - count, "\n");
+               if (count >= PAGE_SIZE - 1)
+                       break;
+       }
+
+       /* Truncate count; min() would cause a warning */
+       if (count >= PAGE_SIZE)
+               count = PAGE_SIZE - 1;
 
        return count;
 }