All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Brown <broonie@opensource.wolfsonmicro.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: alsa-devel@alsa-project.org,
	Mark Brown <broonie@opensource.wolfsonmicro.com>
Subject: [PATCH 04/14] ASoC: Allow codecs to override register display
Date: Tue, 29 Jul 2008 11:42:25 +0100	[thread overview]
Message-ID: <1217328155-30158-4-git-send-email-broonie@opensource.wolfsonmicro.com> (raw)
In-Reply-To: <1217328155-30158-3-git-send-email-broonie@opensource.wolfsonmicro.com>

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>
---
 include/sound/soc.h  |    2 ++
 sound/soc/soc-core.c |   26 +++++++++++++++++++++++---
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index 1890d87..2ce530e 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -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;
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 83f1190..5d3bf73 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -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;
 }
-- 
1.5.6.3

  reply	other threads:[~2008-07-29 10:42 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-29 10:42 [PATCH 01/14] ASoC: Update Poodle to current ASoC API Mark Brown
2008-07-29 10:42 ` [PATCH 02/14] ASoC: Export dapm_reg_event() fully Mark Brown
2008-07-29 10:42   ` [PATCH 03/14] ASoC: Permit simultaneous compilation of both PXA AC97 drivers Mark Brown
2008-07-29 10:42     ` Mark Brown [this message]
2008-07-29 10:42       ` [PATCH 05/14] ASoC: Convert bitfields in ASoC into full int width Mark Brown
2008-07-29 10:42         ` [PATCH 06/14] ASoC: Rename mask to max to reflect usage Mark Brown
2008-07-29 10:42           ` [PATCH 07/14] ASoC: Add OpenFirmware helper for matching bus and codec drivers Mark Brown
2008-07-29 10:42             ` [PATCH 08/14] ASoC: Make OpenFirmware helper include file conditional Mark Brown
2008-07-29 10:42               ` [PATCH 09/14] ASoC: Add mpc5200-psc I2S driver Mark Brown
2008-07-29 10:42                 ` [PATCH 10/14] ASoC: Add Texas Instruments TLV320AIC26 codec driver Mark Brown
2008-07-29 10:42                   ` [PATCH 11/14] ASoC: Export DAI and codec for TLV320AIC26 Mark Brown
2008-07-29 10:42                     ` [PATCH 12/14] ASoC: Staticise keyclick dev_attr in tlv320aic26 Mark Brown
2008-07-29 10:42                       ` [PATCH 13/14] ASoC: AD1980 audio codec driver Mark Brown
2008-07-29 10:42                         ` [PATCH 14/14] ASoC: Add all CODECs Kconfig option Mark Brown
2008-07-29 13:49         ` [PATCH 05/14] ASoC: Convert bitfields in ASoC into full int width Jon Smirl
2008-07-29 13:56           ` Mark Brown
2008-07-29 14:06             ` Jon Smirl
2008-07-29 14:11               ` Takashi Iwai
2008-07-29 13:59           ` Takashi Iwai
2008-08-01  1:41       ` [PATCH 04/14] ASoC: Allow codecs to override register display Jon Smirl
2008-08-01  9:42         ` Takashi Iwai
2008-08-01 10:00           ` Mark Brown
2008-08-01 14:50             ` Jon Smirl
2008-08-01 15:23               ` Takashi Iwai
2008-08-01 15:35                 ` Mark Brown
2008-08-01 15:49                   ` Takashi Iwai
2008-08-01 16:13                     ` Jon Smirl
2008-08-01 16:16                       ` Mark Brown
2008-08-01 16:27                         ` Jon Smirl
2008-08-01 16:40                           ` Mark Brown
2008-08-01 16:35                         ` Takashi Iwai
2008-08-01 17:18                           ` Mark Brown
2008-08-01 17:37                             ` Jon Smirl
2008-08-01 18:10                               ` Mark Brown
2008-07-29 13:36 ` [PATCH 01/14] ASoC: Update Poodle to current ASoC API Takashi Iwai
2008-07-29 13:47   ` Mark Brown
2008-07-29 14:01     ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1217328155-30158-4-git-send-email-broonie@opensource.wolfsonmicro.com \
    --to=broonie@opensource.wolfsonmicro.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.