aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sound/soc/soc-core.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 3feddd91b973..205cbd7b149f 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -69,10 +69,32 @@ static int pmdown_time = 5000;
69module_param(pmdown_time, int, 0); 69module_param(pmdown_time, int, 0);
70MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)"); 70MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
71 71
72/* returns the minimum number of bytes needed to represent
73 * a particular given value */
74static int min_bytes_needed(unsigned long val)
75{
76 int c = 0;
77 int i;
78
79 for (i = (sizeof val * 8) - 1; i >= 0; --i, ++c)
80 if (val & (1UL << i))
81 break;
82 c = (sizeof val * 8) - c;
83 if (!c || (c % 8))
84 c = (c + 8) / 8;
85 else
86 c /= 8;
87 return c;
88}
89
72/* codec register dump */ 90/* codec register dump */
73static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf) 91static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf)
74{ 92{
75 int ret, i, step = 1, count = 0; 93 int ret, i, step = 1, count = 0;
94 int wordsize, regsize;
95
96 wordsize = codec->driver->reg_word_size * 2;
97 regsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
76 98
77 if (!codec->driver->reg_cache_size) 99 if (!codec->driver->reg_cache_size)
78 return 0; 100 return 0;
@@ -80,12 +102,11 @@ static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf)
80 if (codec->driver->reg_cache_step) 102 if (codec->driver->reg_cache_step)
81 step = codec->driver->reg_cache_step; 103 step = codec->driver->reg_cache_step;
82 104
83 count += sprintf(buf, "%s registers\n", codec->name);
84 for (i = 0; i < codec->driver->reg_cache_size; i += step) { 105 for (i = 0; i < codec->driver->reg_cache_size; i += step) {
85 if (codec->readable_register && !codec->readable_register(codec, i)) 106 if (codec->readable_register && !codec->readable_register(codec, i))
86 continue; 107 continue;
87 108
88 count += sprintf(buf + count, "%2x: ", i); 109 count += sprintf(buf + count, "%.*x: ", regsize, i);
89 if (count >= PAGE_SIZE - 1) 110 if (count >= PAGE_SIZE - 1)
90 break; 111 break;
91 112
@@ -101,7 +122,7 @@ static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf)
101 if (ret >= 0) 122 if (ret >= 0)
102 count += snprintf(buf + count, 123 count += snprintf(buf + count,
103 PAGE_SIZE - count, 124 PAGE_SIZE - count,
104 "%4x", ret); 125 "%.*x", wordsize, ret);
105 else 126 else
106 count += snprintf(buf + count, 127 count += snprintf(buf + count,
107 PAGE_SIZE - count, 128 PAGE_SIZE - count,