Skip to contentSkip to conversation

Allow setting codec register with debugfs filesystem

PATCH In review Troy Kisky 2 participants 2 messages Oct 7, 2008

Subsystems (2)
lore
Share & tools
lore

Troy Kisky

author
#0 lore raw

PATCH 1/1 Allow setting codec register with debugfs filesystem

i.e. echo 6 59 >/sys/kernel/debug/soc-audio.0/codec_reg will set register 0x06 to a value of 0x59

include/sound/soc.h +4 -0
index a1e0357..f5a6dbb 100644
@@ -516,6 +516,10 @@ struct snd_soc_device {
 	struct delayed_work delayed_work;
 	struct work_struct deferred_resume_work;
 	void *codec_data;
+#ifdef CONFIG_SND_SOC_DEBUG_FS
+	struct dentry	*debugfs_root;
+	struct dentry	*debugfs_codec_reg;
+#endif
 };
 
 /* runtime channel data */
sound/soc/Kconfig +8 -0
index 4dfda66..aad7e0b 100644
@@ -22,6 +22,14 @@ if SND_SOC
 config SND_SOC_AC97_BUS
 	bool
 
+config SND_SOC_DEBUG_FS
+	boolean "changing codec registers through debugfs (DEVELOPMENT)"
+	depends on DEBUG_FS
+	help
+	   The ability to directly write codec registers through
+	   /sys/kernel/debug/xx/codec_reg is useful when developing
+	   a new codec.
+
 # All the supported Soc's
 source "sound/soc/at32/Kconfig"
 source "sound/soc/at91/Kconfig"
sound/soc/soc-core.c +108 -3

138 lines not on this page · raw message

Signature · 1 line
1.5.4.3
#1 lore raw

On Tue, Oct 07, 2008 at 02:03:55PM -0700, Troy Kisky wrote:

Thanks for this - looks good. A few comments below, nitpicks rather than anything substantial.

include/sound/soc.h struct snd_soc_device { · line 522

Quoted 4 lines
include/sound/soc.h +4 -0
+#ifdef CONFIG_SND_SOC_DEBUG_FS
+	struct dentry	*debugfs_root;
+	struct dentry	*debugfs_codec_reg;
+#endif

It would be better to just make this conditional on debugfs support - this isn't sufficiently high cost to make the additional complexity worthwhile. This is the general idiom for debugfs.

sound/soc/soc-core.c static ssize_t codec_reg_show(struct device *dev, · line 1022

Quoted 4 lines
sound/soc/soc-core.c +4 -0
+static ssize_t code_reg_read_file(struct file *file, char __user *user_buf,
+			       size_t count, loff_t *ppos)
+{
+	ssize_t res;

ret would be more consistent with the rest of ASoC (told you I was picking nits).

sound/soc/soc-core.c static ssize_t codec_reg_show(struct device *dev, · line 1024

Quoted 2 lines
sound/soc/soc-core.c +2 -0
+	struct snd_soc_device *devdata = file->private_data;
+	char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);

It should check for out of memory here. If we ever get codecs with enormous register maps we'll need to worry about PAGE_SIZE but that's an issue for sysfs too and not an issue currently.

sound/soc/soc-core.c static ssize_t codec_reg_show(struct device *dev, · line 1075

Quoted 6 lines
sound/soc/soc-core.c +6 -0
+static void soc_init_debugfs(struct snd_soc_device *socdev)
+{
+	struct dentry *root, *debugfs_codec_reg;
+	root = debugfs_create_dir(dev_name(socdev->dev), NULL);
+	if (IS_ERR(root) || !root)
+		goto exit1;

There's an existing debugfs file (the DAPM pop time configuration) which I'd expect to be handled by this function - it should probably be renamed to something like soc_init_codec_debugfs().

The directory should probably be a subdirectory of that created by DAPM, or you could just put the codec register file in that directly until we support two codecs (which will needs updates to the sysfs code anyway).

sound/soc/soc-core.c static ssize_t codec_reg_show(struct device *dev, · line 1093

Quoted 11 lines
sound/soc/soc-core.c +9 -0
+	debugfs_codec_reg = debugfs_create_file("codec_reg", 0644,
+			root, socdev, &codec_reg_fops);
+	if (!debugfs_codec_reg)
+		goto exit2;
 
+
+	socdev->debugfs_root = root;
 
+static void soc_cleanup_debugfs(struct snd_soc_device *socdev)
+{
+	debugfs_remove(socdev->debugfs_codec_reg);

debugfs directory removal is recursive so no need to do this (or remember the file) unless you put it in the directory with the DAPM file.