[PATCH] [ALSA] Allow setting codec register with sys filesystem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxxxx>

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
-- 
1.5.4.3

_______________________________________________
Alsa-devel mailing list
Alsa-devel@xxxxxxxxxxxxxxxx
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux