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, like in the incomplete patch below.
Regards, Clemens
--- 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 (or other control?) maps to this device */
#define _TLV_ITEM(type, ...) \ (type), _TLV_LENGTH(__VA_ARGS__), __VA_ARGS__ @@ -81,4 +82,9 @@
#define TLV_DB_GAIN_MUTE -9999999
+#define TLB_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 */ --- 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,11 @@ 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; + 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->access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; if (snd_hda_ctl_add(codec, nid, kctl) < 0) return -ENOMEM; jack->kctl = kctl; @@ -249,7 +255,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, 0); if (err < 0) return err; return snd_hda_jack_detect_enable(codec, nid, 0); --- 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);