[alsa-devel] [PATCH] [ALSA] Allow setting codec register with sys filesystem
i.e. echo 6 59 >/sys/devices/platform/soc-audio.0/codec_reg will set register 0x06 to a value of 0x59
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index ad38113..df23b23 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1002,7 +1002,33 @@ static ssize_t codec_reg_show(struct device *dev,
return count; } -static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL); + +static ssize_t codec_reg_write(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + char *start = (char *)buf; + unsigned long reg, value; + int step = 1; + struct snd_soc_device *devdata = dev_get_drvdata(dev); + struct snd_soc_codec *codec = devdata->codec; + + if (codec->reg_cache_step) + step = codec->reg_cache_step; + + while (*start == ' ') + start++; + reg = simple_strtoul(start, &start, 16); + if ((reg >= codec->reg_cache_size) || (reg % step)) + return -EINVAL; + while (*start == ' ') + start++; + if (strict_strtoul(start, 16, &value)) + return -EINVAL; + codec->write(codec, reg, value); + return start - buf; +} + +static DEVICE_ATTR(codec_reg, 0644, codec_reg_show, codec_reg_write);
/** * snd_soc_new_ac97_codec - initailise AC97 device
On Sat, Oct 04, 2008 at 04:54:09PM -0700, Troy Kisky wrote:
i.e. echo 6 59 >/sys/devices/platform/soc-audio.0/codec_reg will set register 0x06 to a value of 0x59
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com
I'd probably take a patch to do this in debugfs but I don't think it is appropriate to do this in sysfs. Writing to the registers outside the control of the drivers can seriously interfere with their operation and confuse user space - it's something you can get away with if you know what you're doing but it's not something that should be available as a standard, advertised interface. There's also the possibility of the driver trampling over any settings made with this interface which wouldn't be helpful either.
At Mon, 6 Oct 2008 10:58:57 +0100, Mark Brown wrote:
On Sat, Oct 04, 2008 at 04:54:09PM -0700, Troy Kisky wrote:
i.e. echo 6 59 >/sys/devices/platform/soc-audio.0/codec_reg will set register 0x06 to a value of 0x59
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com
I'd probably take a patch to do this in debugfs but I don't think it is appropriate to do this in sysfs. Writing to the registers outside the control of the drivers can seriously interfere with their operation and confuse user space - it's something you can get away with if you know what you're doing but it's not something that should be available as a standard, advertised interface. There's also the possibility of the driver trampling over any settings made with this interface which wouldn't be helpful either.
Putting into debugfs sounds like a saner option, as this is only for debugging.
OTOH, symmetrical read/write operations also good. Will be the sysfs register show op moved to debugfs, too?
thanks,
Takashi
On Mon, Oct 06, 2008 at 12:03:32PM +0200, Takashi Iwai wrote:
OTOH, symmetrical read/write operations also good. Will be the sysfs register show op moved to debugfs, too?
I'd rather that were available all the time since it's so useful.
Adding a read interface in debugfs would certainly be sensible, though - I have in the past considered adding a much more detailed readback interface to debugfs which would not only dump the registers but also provide some decode information (eg, reporting the mapping to controls for the standard ASoC widgets). Not something I have the time to do in the immediate future, though.
participants (3)
-
Mark Brown
-
Takashi Iwai
-
Troy Kisky