* [PATCH] ASoC: Allow codecs to override register display
@ 2008-07-18 10:57 Mark Brown
2008-07-18 15:23 ` Jon Smirl
0 siblings, 1 reply; 4+ messages in thread
From: Mark Brown @ 2008-07-18 10:57 UTC (permalink / raw)
To: Takashi Iwai; +Cc: alsa-devel, Mark Brown
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.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
include/sound/soc.h | 1 +
sound/soc/soc-core.c | 14 ++++++++++----
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/include/sound/soc.h b/include/sound/soc.h
index 1890d87..8b1a3e7 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -410,6 +410,7 @@ 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 *, 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..49532d9 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -970,10 +970,16 @@ 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 (codec->display_register)
+ count += codec->display_register(codec,
+ buf + count, i);
+ else
+ count += sprintf(buf + count, "%4x",
+ codec->read(codec, i));
+ count += sprintf(buf + count, "\n");
+ }
return count;
}
static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
--
1.5.6.3
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] ASoC: Allow codecs to override register display
2008-07-18 10:57 [PATCH] ASoC: Allow codecs to override register display Mark Brown
@ 2008-07-18 15:23 ` Jon Smirl
2008-07-18 15:32 ` Takashi Iwai
0 siblings, 1 reply; 4+ messages in thread
From: Jon Smirl @ 2008-07-18 15:23 UTC (permalink / raw)
To: Mark Brown; +Cc: Takashi Iwai, alsa-devel
On 7/18/08, Mark Brown <broonie@opensource.wolfsonmicro.com> wrote:
> 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.
My address space is sparse like Grant's. How about display_register()
returning -1 to skip the register address. The part printing the
address would need to be suppressed too.
count += sprintf(buf + count, "%2x: ", i);
Alternatively you could just make the entire codec_reg_show() overridable.
Might want to add another parameter for cached/uncached. Then we could
make a debug option to add the non-cached display.
This loop needs to be protected to not write over the sysfs limit of
PAGE_SIZE in the result. I think you will corrupt memory if PAGE_SIZE
is exceeded.
> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
> ---
> include/sound/soc.h | 1 +
> sound/soc/soc-core.c | 14 ++++++++++----
> 2 files changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/include/sound/soc.h b/include/sound/soc.h
> index 1890d87..8b1a3e7 100644
> --- a/include/sound/soc.h
> +++ b/include/sound/soc.h
> @@ -410,6 +410,7 @@ 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 *, 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..49532d9 100644
> --- a/sound/soc/soc-core.c
> +++ b/sound/soc/soc-core.c
> @@ -970,10 +970,16 @@ 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 (codec->display_register)
> + count += codec->display_register(codec,
> + buf + count, i);
> + else
> + count += sprintf(buf + count, "%4x",
> + codec->read(codec, i));
> + count += sprintf(buf + count, "\n");
> + }
> return count;
> }
> static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
>
> --
> 1.5.6.3
>
>
--
Jon Smirl
jonsmirl@gmail.com
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] ASoC: Allow codecs to override register display
2008-07-18 15:23 ` Jon Smirl
@ 2008-07-18 15:32 ` Takashi Iwai
2008-07-18 20:38 ` Mark Brown
0 siblings, 1 reply; 4+ messages in thread
From: Takashi Iwai @ 2008-07-18 15:32 UTC (permalink / raw)
To: Jon Smirl; +Cc: alsa-devel, Mark Brown
At Fri, 18 Jul 2008 11:23:09 -0400,
Jon Smirl wrote:
>
> On 7/18/08, Mark Brown <broonie@opensource.wolfsonmicro.com> wrote:
> > 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.
>
> My address space is sparse like Grant's. How about display_register()
> returning -1 to skip the register address. The part printing the
> address would need to be suppressed too.
> count += sprintf(buf + count, "%2x: ", i);
>
> Alternatively you could just make the entire codec_reg_show() overridable.
Yes, I agree. For non-standard register maps, provide its own
codec_reg_show().
> Might want to add another parameter for cached/uncached. Then we could
> make a debug option to add the non-cached display.
That makes sense, too.
> This loop needs to be protected to not write over the sysfs limit of
> PAGE_SIZE in the result. I think you will corrupt memory if PAGE_SIZE
> is exceeded.
Right. So far, it's been OK since the number of registers is
relatively small.
Takashi
> > Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
> > ---
> > include/sound/soc.h | 1 +
> > sound/soc/soc-core.c | 14 ++++++++++----
> > 2 files changed, 11 insertions(+), 4 deletions(-)
> >
> > diff --git a/include/sound/soc.h b/include/sound/soc.h
> > index 1890d87..8b1a3e7 100644
> > --- a/include/sound/soc.h
> > +++ b/include/sound/soc.h
> > @@ -410,6 +410,7 @@ 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 *, 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..49532d9 100644
> > --- a/sound/soc/soc-core.c
> > +++ b/sound/soc/soc-core.c
> > @@ -970,10 +970,16 @@ 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 (codec->display_register)
> > + count += codec->display_register(codec,
> > + buf + count, i);
> > + else
> > + count += sprintf(buf + count, "%4x",
> > + codec->read(codec, i));
> > + count += sprintf(buf + count, "\n");
> > + }
> > return count;
> > }
> > static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
> >
> > --
> > 1.5.6.3
> >
> >
>
>
> --
> Jon Smirl
> jonsmirl@gmail.com
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] ASoC: Allow codecs to override register display
2008-07-18 15:32 ` Takashi Iwai
@ 2008-07-18 20:38 ` Mark Brown
0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2008-07-18 20:38 UTC (permalink / raw)
To: Takashi Iwai; +Cc: alsa-devel
On Fri, Jul 18, 2008 at 05:32:50PM +0200, Takashi Iwai wrote:
> Jon Smirl wrote:
> > My address space is sparse like Grant's. How about display_register()
> > returning -1 to skip the register address. The part printing the
> > address would need to be suppressed too.
> > count += sprintf(buf + count, "%2x: ", i);
If we want to do sparse register maps I'd really much rather we did it
by providing the core with explicit information about it and providing
guarantees that only specified registers will be read rather than by
adding it separately to each interface. This would make review easier
and makes it easier to add new features like...
> > This loop needs to be protected to not write over the sysfs limit of
> > Alternatively you could just make the entire codec_reg_show() overridable.
> Yes, I agree. For non-standard register maps, provide its own
> codec_reg_show().
I'd really like a way to just display the value of a register anyway for
some other work I've been thinking of.
One of the issues that users run into is that it can be difficult to go
from the datasheet to the ALSA controls and back again, especially on
more complex chips. The scenario API is one part of dealing with this
but that doesn't help the people doing the initial system setup and
generatig the scenarios. They could be helped by exporting more
information to user space about the mappings and the register values
seem like they could be a useful part of that. It's likely that at
least some of this will done by user space but even then it still
becomes more important to keep the format of the sysfs files regular.
Right now I'm not working on this since we've been focused on the v2
merge.
The underlying thing here is that the more code we keep in the core the
easier it is to maintain the subsystem and the less redundant code we
have in individual drivers.
> > Might want to add another parameter for cached/uncached. Then we could
> > make a debug option to add the non-cached display.
> That makes sense, too.
I've considered doing that myself - I'd say just via a second sysfs file
that's always there, there doesn't seem much win from making it a debug
only option and it'd be a pain to have to enable it when you do need it.
This would need to be optional (conditional on having a hardware read
function, I imagine) since a lot of devices don't actually provide any
register read capability in hardware so couldn't support it.
> > PAGE_SIZE in the result. I think you will corrupt memory if PAGE_SIZE
> > is exceeded.
> Right. So far, it's been OK since the number of registers is
> relatively small.
This is a good point, and will likely be an issue for some of the debug
interfaces I have been considering. A separate patch, though...
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-07-18 20:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-18 10:57 [PATCH] ASoC: Allow codecs to override register display Mark Brown
2008-07-18 15:23 ` Jon Smirl
2008-07-18 15:32 ` Takashi Iwai
2008-07-18 20:38 ` Mark Brown
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.