[alsa-devel] [PATCH] ALSA: hda/jack - Also add jack kctls for Conexant codecs

Takashi Iwai tiwai at suse.de
Wed Dec 21 15:42:17 CET 2011


At Tue, 20 Dec 2011 23:58:13 +0000,
Mark Brown wrote:
> 
> On Tue, Dec 20, 2011 at 03:32:21PM +0100, Takashi Iwai wrote:
> > David Henningsson wrote:
> 
> > > Also it would be nice to see this merged, soon it might be too late for 3.3?
> 
> > OK, let's merge it.  The things are still local to hda-intel, so we
> > can fix pending issues and rewrite with a more generic framework later
> > for unified jack-handling stuff.
> 
> I was rather expecting that the patches would be posted to the list for
> review at some point (though I may have missed them as not having
> generic support is really disappointing).

Err, sorry, I thought I have posted some in RFC, but wasn't there.
The essential patch for the common helper is attached below.

>  We should at least verify
> that the userspace interface isn't going to cause problems for non-HDA
> systems.

Well, the kctl-jack part itself can't break anything right now since
it's used only in HD-audio.  If others will use, this will be a pure
addition, so it won't break except for possibly different ctl numids.

The question toward the integration with the input-jack stuff is still
open.  In the HD-audio case, input-jack functions are merged into the
kctl-jack helpers.  But for others, it doesn't have to be so.

One remaining obstacle for this integration is that the input-jack
provides multiple key bits per jack entry while this doesn't exist in
the kctl notification.  With kctl, the notifier says just that the 
value was changed.  Then the user-space can query the current value
(not necessarily a boolean but can be an integer or else), but the
value isn't passed in the notification itself.  So, it's a different
design. 


thanks,

Takashi

---
From: Takashi Iwai <tiwai at suse.de>
Subject: [PATCH] ALSA: Introduce common helper functions for jack-detection
 control

Now move the helper function for creating and reporting the jack-detection
to the common place.  The driver that needs this functionality should
select CONFIG_SND_KCTL_JACK kconfig.

Signed-off-by: Takashi Iwai <tiwai at suse.de>
---
diff --git a/include/sound/control.h b/include/sound/control.h
index 1a94a21..b2796e8 100644
--- a/include/sound/control.h
+++ b/include/sound/control.h
@@ -227,4 +227,12 @@ snd_ctl_add_slave_uncached(struct snd_kcontrol *master,
 	return _snd_ctl_add_slave(master, slave, SND_CTL_SLAVE_NEED_UPDATE);
 }
 
+/*
+ * Helper functions for jack-detection controls
+ */
+struct snd_kcontrol *
+snd_kctl_jack_new(const char *name, int idx, void *private_data);
+void snd_kctl_jack_report(struct snd_card *card,
+			  struct snd_kcontrol *kctl, bool status);
+
 #endif	/* __SOUND_CONTROL_H */
diff --git a/sound/core/Kconfig b/sound/core/Kconfig
index 475455c..66f287f 100644
--- a/sound/core/Kconfig
+++ b/sound/core/Kconfig
@@ -207,6 +207,9 @@ config SND_PCM_XRUN_DEBUG
 config SND_VMASTER
 	bool
 
+config SND_KCTL_JACK
+	bool
+
 config SND_DMA_SGBUF
 	def_bool y
 	depends on X86
diff --git a/sound/core/Makefile b/sound/core/Makefile
index 350a08d..b4637c3 100644
--- a/sound/core/Makefile
+++ b/sound/core/Makefile
@@ -7,6 +7,7 @@ snd-y     := sound.o init.o memory.o info.o control.o misc.o device.o
 snd-$(CONFIG_ISA_DMA_API) += isadma.o
 snd-$(CONFIG_SND_OSSEMUL) += sound_oss.o info_oss.o
 snd-$(CONFIG_SND_VMASTER) += vmaster.o
+snd-$(CONFIG_SND_KCTL_JACK) += ctljack.o
 snd-$(CONFIG_SND_JACK)	  += jack.o
 
 snd-pcm-objs := pcm.o pcm_native.o pcm_lib.o pcm_timer.o pcm_misc.o \
diff --git a/sound/core/ctljack.c b/sound/core/ctljack.c
new file mode 100644
index 0000000..af0e78a
--- /dev/null
+++ b/sound/core/ctljack.c
@@ -0,0 +1,55 @@
+/*
+ * Helper functions for jack-detection kcontrols
+ *
+ * Copyright (c) 2011 Takashi Iwai <tiwai at suse.de>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ */
+
+#include <linux/kernel.h>
+#include <sound/core.h>
+#include <sound/control.h>
+
+#define jack_detect_kctl_info	snd_ctl_boolean_mono_info
+
+static int jack_detect_kctl_get(struct snd_kcontrol *kcontrol,
+				struct snd_ctl_elem_value *ucontrol)
+{
+	ucontrol->value.integer.value[0] = kcontrol->private_value;
+	return 0;
+}
+
+static struct snd_kcontrol_new jack_detect_kctl = {
+	/* name is filled later */
+	.iface = SNDRV_CTL_ELEM_IFACE_CARD,
+	.access = SNDRV_CTL_ELEM_ACCESS_READ,
+	.info = jack_detect_kctl_info,
+	.get = jack_detect_kctl_get,
+};
+
+struct snd_kcontrol *
+snd_kctl_jack_new(const char *name, int idx, void *private_data)
+{
+	struct snd_kcontrol *kctl;
+	kctl = snd_ctl_new1(&jack_detect_kctl, private_data);
+	if (!kctl)
+		return NULL;
+	snprintf(kctl->id.name, sizeof(kctl->id.name), "%s Jack", name);
+	kctl->id.index = idx;
+	kctl->private_value = 0;
+	return kctl;
+}
+EXPORT_SYMBOL_GPL(snd_kctl_jack_new);
+
+void snd_kctl_jack_report(struct snd_card *card,
+			  struct snd_kcontrol *kctl, bool status)
+{
+	if (kctl->private_value == status)
+		return;
+	kctl->private_value = status;
+	snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
+}
+EXPORT_SYMBOL_GPL(snd_kctl_jack_report);


More information about the Alsa-devel mailing list