Allow setting codec register with sys filesystem
PATCH 1/1 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
sound/soc/soc-core.c +27 -1
@@ -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
Signature · 1 line
1.5.4.3
Quoted 4 lines · Troy Kisky
i.e. echo 6 59 >/sys/devices/platform/soc-audio.0/codec_reg will set register
0x06to a value of0x59Signed-off-by Troy Kisky <[email protected]>
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,
Quoted 7 lines · Mark Brown
Quoted 4 lines · Troy Kisky
i.e. echo 6 59 >/sys/devices/platform/soc-audio.0/codec_reg will set register
0x06to a value of0x59Signed-off-by Troy Kisky <[email protected]>
Quoted 8 lines
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
Quoted 2 lines · Takashi Iwai
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.