All of lore.kernel.org
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: David Henningsson <david.henningsson@canonical.com>
Cc: Takashi Iwai <tiwai@suse.de>,
	ALSA Development Mailing List <alsa-devel@alsa-project.org>
Subject: Re: Tests of the hda-jack branch
Date: Wed, 30 Nov 2011 07:38:37 +0100	[thread overview]
Message-ID: <4ED5CF6D.7050804@ladisch.de> (raw)
In-Reply-To: <4ED545E1.3040409@ladisch.de>

Clemens Ladisch wrote:
> David Henningsson wrote:
>> ... two patches - one adds a "device index" for mapping against pcm
>> devices on HDMI,
>
>> +	kctl->id.device = device;
>
> In the general case, there is not always a 1:1 mapping between jacks and
> PCM devices, so I fear that a jack belonging to device 0 cannot be
> distinguished from a jack that has no specific device.
>
> There is a convention that id.device is a valid PCM device number if and
> only if id.iface is IFACE_PCM.  However, it might be useful to map
> controls with IFACE_MIXER to PCM devices, so I'd propose a new TLV,

Er, the point was for the TLV to be optional; please ignore the previous
patch.  :)


--8<---------------------------------------------------------------->8--
ALSA: hda/jack: add PCM device TLV for jack controls

Allow to add a new TLV to jack kcontrols so that HDMI jacks can be
associated with the correct PCM devices.

Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
---
 include/sound/tlv.h        |    6 ++++++
 sound/pci/hda/hda_jack.c   |   12 ++++++++++--
 sound/pci/hda/hda_jack.h   |    3 ++-
 sound/pci/hda/patch_hdmi.c |    3 ++-
 4 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/include/sound/tlv.h b/include/sound/tlv.h
index 7067e2d..809b077 100644
--- a/include/sound/tlv.h
+++ b/include/sound/tlv.h
@@ -37,6 +37,7 @@
 #define SNDRV_CTL_TLVT_DB_RANGE 3	/* dB range container */
 #define SNDRV_CTL_TLVT_DB_MINMAX 4	/* dB scale with min/max */
 #define SNDRV_CTL_TLVT_DB_MINMAX_MUTE 5	/* dB scale with min/max with mute */
+#define SNDRV_CTL_TLVT_PCM_DEVICE 6	/* (jack) control maps to this device */

 #define TLV_DB_SCALE_MASK	0xffff
 #define TLV_DB_SCALE_MUTE	0x10000
@@ -73,4 +74,9 @@

 #define TLV_DB_GAIN_MUTE	-9999999

+#define TLV_PCM_DEVICE_NUMBER_ITEM(devno) \
+	SNDRV_CTL_TLVT_PCM_DEVICE, 1 * sizeof(unsigned int), (devno)
+#define DECLARE_TLV_PCM_DEVICE_NUMBER(name, devno) \
+	unsigned int name[] = { TLV_PCM_DEVICE_NUMBER_ITEM(devno) }
+
 #endif /* __SOUND_TLV_H */
diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c
index 3949015..848dd03 100644
--- a/sound/pci/hda/hda_jack.c
+++ b/sound/pci/hda/hda_jack.c
@@ -15,6 +15,7 @@
 #include <sound/core.h>
 #include <sound/control.h>
 #include <sound/jack.h>
+#include <sound/tlv.h>
 #include "hda_codec.h"
 #include "hda_local.h"
 #include "hda_jack.h"
@@ -210,7 +211,7 @@ EXPORT_SYMBOL_HDA(snd_hda_jack_report_sync);
  * will have the given name and index.
  */
 int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
-			  const char *name, int idx)
+			  const char *name, int idx, int device)
 {
 	struct hda_jack_tbl *jack;
 	struct snd_kcontrol *kctl;
@@ -223,6 +224,13 @@ int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
 	kctl = snd_kctl_jack_new(name, idx, codec);
 	if (!kctl)
 		return -ENOMEM;
+	if (device >= 0) {
+		jack->tlv[0] = SNDRV_CTL_TLVT_PCM_DEVICE;
+		jack->tlv[1] = 1 * sizeof(unsigned int);
+		jack->tlv[2] = device;
+		kctl->tlv.p = jack->tlv;
+		kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
+	}
 	if (snd_hda_ctl_add(codec, nid, kctl) < 0)
 		return -ENOMEM;
 	jack->kctl = kctl;
@@ -249,7 +257,7 @@ static int add_jack_kctl(struct hda_codec *codec, hda_nid_t nid,
 		return 0;

 	snd_hda_get_pin_label(codec, nid, cfg, name, sizeof(name), &idx);
-	err = snd_hda_jack_add_kctl(codec, nid, name, idx);
+	err = snd_hda_jack_add_kctl(codec, nid, name, idx, -1);
 	if (err < 0)
 		return err;
 	return snd_hda_jack_detect_enable(codec, nid, 0);
diff --git a/sound/pci/hda/hda_jack.h b/sound/pci/hda/hda_jack.h
index f8f97c7..a2e69c5 100644
--- a/sound/pci/hda/hda_jack.h
+++ b/sound/pci/hda/hda_jack.h
@@ -22,6 +22,7 @@ struct hda_jack_tbl {
 	unsigned int jack_detect:1;	/* capable of jack-detection? */
 	unsigned int jack_dirty:1;	/* needs to update? */
 	struct snd_kcontrol *kctl;	/* assigned kctl for jack-detection */
+	unsigned int tlv[3];
 #ifdef CONFIG_SND_HDA_INPUT_JACK
 	int type;
 	struct snd_jack *jack;
@@ -76,7 +77,7 @@ static inline bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid)
 }

 int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
-			  const char *name, int idx);
+			  const char *name, int idx, int device);
 int snd_hda_jack_add_kctls(struct hda_codec *codec,
 			   const struct auto_pin_cfg *cfg);

diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index bb8cfc6..9689c8d 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -1277,7 +1277,8 @@ static int generic_hdmi_build_controls(struct hda_codec *codec)
 		if (err < 0)
 			return err;
 		err = snd_hda_jack_add_kctl(codec, per_pin->pin_nid,
-					    "HDMI", pin_idx);
+					    "HDMI", pin_idx,
+					    spec->pcm_rec[pin_idx].device);
 		if (err < 0)
 			return err;
 	}

  parent reply	other threads:[~2011-11-30  6:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-29 19:43 Tests of the hda-jack branch David Henningsson
2011-11-29 20:03 ` Mark Brown
2011-11-30  6:41   ` Takashi Iwai
2011-11-30  9:26     ` Mark Brown
2011-11-29 20:51 ` Clemens Ladisch
2011-11-30  2:10   ` Raymond Yau
2011-11-30  6:38   ` Clemens Ladisch [this message]
2011-11-30  6:46   ` Takashi Iwai
2011-11-30  2:43 ` Raymond Yau
2011-11-30  8:05   ` David Henningsson
2011-11-30  6:31 ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4ED5CF6D.7050804@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=david.henningsson@canonical.com \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.