[alsa-devel] HDA model specification and a topic/hda bug?

Takashi Iwai tiwai at suse.de
Wed Dec 23 08:49:00 CET 2009


At Wed, 23 Dec 2009 16:21:34 +1100,
Paul "TBBle" Hampson wrote:
> 
> Hi,
> 
> I've a couple of questions. Firstly, I've been through "MORE NOTES ON
> HD-AUDIO DRIVER"
> and was able to use codecgraph and hda-analyzer to identify
> non-disabled speakers on my
> laptop (the laptop claims four speakers plus a subwoofer, Alsa's
> autodetect only enables the
> subwoofer for output) but I'm having trouble working out how to
> convert this knowledge into either
> changes to patch_realtek.c or even a patch file to feed the driver, so
> that it comes up correctly
> by default.
> 
> I do have a printout of the Intel HDA spec's codec layout chapter, but
> I haven't read it yet. I'm
> hoping not to have to, but I suspect I will.
> 
> Anyway, I've been tracking topic/hda from the Alsa git repository,
> hoping it'll magically fix my
> sound-card detection, but I'm having a problem with
> 5b0cb1d850c26893b1468b3a519433a1b7a176be
> (ALSA: hda - add more NID->Control mapping) which I believe is part of
> the 1.0.22 release.
> 
> For reference, it's an MSI GT725 laptop...
> 
> Basically, snd_hda_add_nids is being called with an array of three
> nids, the third of which is 0.
> 
> I've been throwing snd_kprintd statements at it, and it seems that I
> see input_mux->num_items
> as 3 (which I _think_ is correct, I have a buit-in microphone,
> microphone jack and line-in jack) but
> I only have two analog aud_in nodes (0x8 and 0x9, 0x7 is a vendor node).
> 
> >From the look of it, this call to snd_hda_add_nids is wrong:
> err = snd_hda_add_nids(codec, kctl, i, spec->capsrc_nids,
> spec->input_mux->num_items);
> it maybe should be
> err = snd_hda_add_nids(codec, kctl, i, spec->capsrc_nids, spec->num_adc_nids);
> if I'm understanding patch_alc882 correctly, although that looks wrong
> in pretty much every
> other use I can see.

Thanks for your report.

Well, your fix isn't really correct, but the code in the place is
indeed broken (also others too).

The below is a fix patch.  It's already applied to sound git tree
and the snapshot tarball.


thanks,

Takashi

---
From 21949f00a022e090a7e8bc9a01dfca88273c6146 Mon Sep 17 00:00:00 2001
From: Takashi Iwai <tiwai at suse.de>
Date: Wed, 23 Dec 2009 08:31:59 +0100
Subject: [PATCH] ALSA: hda - Fix NID association for capture mixers

Fix the wrong implementation of NID <-> kctl mapping for capture mixers
introduced by the ocmmit 5b0cb1d850c26893b1468b3a519433a1b7a176be.
So far, the driver returns an error at probe.

Signed-off-by: Takashi Iwai <tiwai at suse.de>
---
 sound/pci/hda/hda_codec.c     |   26 --------------------------
 sound/pci/hda/hda_local.h     |    2 --
 sound/pci/hda/patch_analog.c  |    3 +--
 sound/pci/hda/patch_cirrus.c  |   12 ++++++++----
 sound/pci/hda/patch_cmedia.c  |    3 +--
 sound/pci/hda/patch_realtek.c |    3 +--
 sound/pci/hda/patch_via.c     |    3 +--
 7 files changed, 12 insertions(+), 40 deletions(-)

diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index c848ec0..29c90d7 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -3537,32 +3537,6 @@ int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
 }
 EXPORT_SYMBOL_HDA(snd_hda_add_new_ctls);
 
-/**
- * snd_hda_add_nids - assign nids to controls from the array
- * @codec: the HDA codec
- * @kctl: struct snd_kcontrol
- * @index: index to kctl
- * @nids: the array of hda_nid_t
- * @size: count of hda_nid_t items
- *
- * This helper function assigns NIDs in the given array to a control element.
- *
- * Returns 0 if successful, or a negative error code.
- */
-int snd_hda_add_nids(struct hda_codec *codec, struct snd_kcontrol *kctl,
-		     unsigned int index, hda_nid_t *nids, unsigned int size)
-{
-	int err;
-
-	for ( ; size > 0; size--, nids++) {
-		err = snd_hda_add_nid(codec, kctl, index, *nids);
-		if (err < 0)
-			return err;
-	}
-	return 0;
-}
-EXPORT_SYMBOL_HDA(snd_hda_add_nids);
-
 #ifdef CONFIG_SND_HDA_POWER_SAVE
 static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
 				unsigned int power_state);
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index d505d05..7cee364 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -343,8 +343,6 @@ int snd_hda_check_board_codec_sid_config(struct hda_codec *codec,
                                const struct snd_pci_quirk *tbl);
 int snd_hda_add_new_ctls(struct hda_codec *codec,
 			 struct snd_kcontrol_new *knew);
-int snd_hda_add_nids(struct hda_codec *codec, struct snd_kcontrol *kctl,
-		     unsigned int index, hda_nid_t *nids, unsigned int size);
 
 /*
  * unsolicited event handler
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index 92b72d4..45ee352 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -244,8 +244,7 @@ static int ad198x_build_controls(struct hda_codec *codec)
 	if (!kctl)
 		kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
 	for (i = 0; kctl && i < kctl->count; i++) {
-		err = snd_hda_add_nids(codec, kctl, i, spec->capsrc_nids,
-				       spec->input_mux->num_items);
+		err = snd_hda_add_nid(codec, kctl, i, spec->capsrc_nids[i]);
 		if (err < 0)
 			return err;
 	}
diff --git a/sound/pci/hda/patch_cirrus.c b/sound/pci/hda/patch_cirrus.c
index 093cfbb..7de782a 100644
--- a/sound/pci/hda/patch_cirrus.c
+++ b/sound/pci/hda/patch_cirrus.c
@@ -753,6 +753,7 @@ static int build_input(struct hda_codec *codec)
 	spec->capture_bind[1] = make_bind_capture(codec, &snd_hda_bind_vol);
 	for (i = 0; i < 2; i++) {
 		struct snd_kcontrol *kctl;
+		int n;
 		if (!spec->capture_bind[i])
 			return -ENOMEM;
 		kctl = snd_ctl_new1(&cs_capture_ctls[i], codec);
@@ -762,10 +763,13 @@ static int build_input(struct hda_codec *codec)
 		err = snd_hda_ctl_add(codec, 0, kctl);
 		if (err < 0)
 			return err;
-		err = snd_hda_add_nids(codec, kctl, 0, spec->adc_nid,
-				       spec->num_inputs);
-		if (err < 0)
-			return err;
+		for (n = 0; n < AUTO_PIN_LAST; n++) {
+			if (!spec->adc_nid[n])
+				continue;
+			err = snd_hda_add_nid(codec, kctl, 0, spec->adc_nid[i]);
+			if (err < 0)
+				return err;
+		}
 	}
 	
 	if (spec->num_inputs > 1 && !spec->mic_detect) {
diff --git a/sound/pci/hda/patch_cmedia.c b/sound/pci/hda/patch_cmedia.c
index cc1c223..ff60908 100644
--- a/sound/pci/hda/patch_cmedia.c
+++ b/sound/pci/hda/patch_cmedia.c
@@ -345,8 +345,7 @@ static int cmi9880_build_controls(struct hda_codec *codec)
 	/* assign Capture Source enums to NID */
 	kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
 	for (i = 0; kctl && i < kctl->count; i++) {
-		err = snd_hda_add_nids(codec, kctl, i, spec->adc_nids,
-				       spec->input_mux->num_items);
+		err = snd_hda_add_nid(codec, kctl, i, spec->adc_nids[i]);
 		if (err < 0)
 			return err;
 	}
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index e7cdc6a..a451990 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -2551,8 +2551,7 @@ static int alc_build_controls(struct hda_codec *codec)
 		hda_nid_t *nids = spec->capsrc_nids;
 		if (!nids)
 			nids = spec->adc_nids;
-		err = snd_hda_add_nids(codec, kctl, i, nids,
-				       spec->input_mux->num_items);
+		err = snd_hda_add_nid(codec, kctl, i, nids[i]);
 		if (err < 0)
 			return err;
 	}
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index de4839e..9ddc373 100644
--- a/sound/pci/hda/patch_via.c
+++ b/sound/pci/hda/patch_via.c
@@ -1907,8 +1907,7 @@ static int via_build_controls(struct hda_codec *codec)
 	/* assign Capture Source enums to NID */
 	kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
 	for (i = 0; kctl && i < kctl->count; i++) {
-		err = snd_hda_add_nids(codec, kctl, i, spec->mux_nids,
-				       spec->input_mux->num_items);
+		err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
 		if (err < 0)
 			return err;
 	}
-- 
1.6.5.7



More information about the Alsa-devel mailing list