Skip to contentSkip to conversation

ALSA : hda - not use assigned converters for all unused pins

RFC PATCH Superseded [email protected] 2 participants 5 messages Sep 16, 2013 – Sep 20, 2013 Sound

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 ALSA : hda - not use assigned converters for all unused pins

From: Mengdong Lin <[email protected]>

BIOS can mark a pin as "no physical connection" if the port is used by an integrated display which is not audio capable. And audio driver will overlook such pins.

On Haswell, such a disconneted pin will keep muted and connected to the 1st converter by default. But if the 1st convertor is assigned to a connected pin for audio streaming. The muted disconnected pin can make the connected pin no sound output.

So this patch avoids using assigned converters for all unused pins for Haswell, including the disconected pins.

sound/pci/hda/patch_hdmi.c +20 -15
index 3d8cd044..4960695 100644
@@ -1152,29 +1152,34 @@ static void haswell_config_cvts(struct hda_codec *codec,
 			int pin_id, int mux_id)
 {
 	struct hdmi_spec *spec = codec->spec;
-	struct hdmi_spec_per_pin *per_pin;
-	int pin_idx, mux_idx;
+	hda_nid_t  pin_nid;
+	int pin_idx, cvt_idx;
 	int curr;
-	int err;
-
-	for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
-		per_pin = get_pin(spec, pin_idx);
+	struct hdmi_spec_per_cvt *per_cvt;
 
+	/* configure all 3 pins, including "no physical connection" ones */
+	for (pin_nid = 5; pin_nid < 8; pin_nid++) {
+		pin_idx = pin_nid_to_pin_index(spec, pin_nid);
 		if (pin_idx == pin_id)
 			continue;
 
-		curr = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
+		curr = snd_hda_codec_read(codec, pin_nid, 0,
 					  AC_VERB_GET_CONNECT_SEL, 0);
+		if (curr != mux_id)
+			continue;
+
+		for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
+			per_cvt = get_cvt(spec, cvt_idx);
 
-		/* Choose another unused converter */
-		if (curr == mux_id) {
-			err = hdmi_choose_cvt(codec, pin_idx, NULL, &mux_idx);
-			if (err < 0)
-				return;
-			snd_printdd("HDMI: choose converter %d for pin %d\n", mux_idx, pin_idx);
-			snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
+			/* Must not already be assigned */
+			if (!per_cvt->assigned) {
+				snd_printdd("choose converter %d for pin %d\n",
+					cvt_idx, pin_idx);
+				snd_hda_codec_write_cache(codec, pin_nid, 0,
 					    AC_VERB_SET_CONNECT_SEL,
-					    mux_idx);
+					    cvt_idx);
+				break;
+			}
 		}
 	}
 }
Signature · 1 line
1.8.1.2
#1 lore raw
Quoted 6 lines · On 09/16/2013 04:40 AM, [email protected] wrote:

From: Mengdong Lin <[email protected]>

BIOS can mark a pin as "no physical connection" if the port is used by an integrated display which is not audio capable. And audio driver will overlook such pins.

Quoted 7 lines

On Haswell, such a disconneted pin will keep muted and connected to the 1st converter by default. But if the 1st convertor is assigned to a connected pin for audio streaming. The muted disconnected pin can make the connected pin no sound output.

So this patch avoids using assigned converters for all unused pins for Haswell, including the disconected pins.

Thanks for the patch!

Quoted 14 lines
sound/pci/hda/patch_hdmi.c +1 -2
index 3d8cd044..4960695 100644
@@ -1152,29 +1152,34 @@ static void haswell_config_cvts(struct hda_codec *codec,
 			int pin_id, int mux_id)
 {
 	struct hdmi_spec *spec = codec->spec;
-	struct hdmi_spec_per_pin *per_pin;
-	int pin_idx, mux_idx;
+	hda_nid_t  pin_nid;

sound/pci/hda/patch_hdmi.c static void haswell_config_cvts(struct hda_codec *codec, · line 1161

Quoted 10 lines
sound/pci/hda/patch_hdmi.c +4 -4
+	int pin_idx, cvt_idx;
 	int curr;
-	int err;
-
-	for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
-		per_pin = get_pin(spec, pin_idx);
+	struct hdmi_spec_per_cvt *per_cvt;
 
+	/* configure all 3 pins, including "no physical connection" ones */
+	for (pin_nid = 5; pin_nid < 8; pin_nid++) {

It might not be so future proof to hard code nid IDs here (even if it should be safe right now?). Perhaps more elegant to go through the entire codec->nids array like being done here:

http://lxr.linux.no/linux+*/sound/pci/hda/hda_auto_parser.c#L188

The nid's wcaps is cached so it does not mean additional reads from the codec.

Quoted 34 lines
sound/pci/hda/patch_hdmi.c +15 -9
+		pin_idx = pin_nid_to_pin_index(spec, pin_nid);
 		if (pin_idx == pin_id)
 			continue;
 
-		curr = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
+		curr = snd_hda_codec_read(codec, pin_nid, 0,
 					  AC_VERB_GET_CONNECT_SEL, 0);
+		if (curr != mux_id)
+			continue;
+
+		for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
+			per_cvt = get_cvt(spec, cvt_idx);
 
-		/* Choose another unused converter */
-		if (curr == mux_id) {
-			err = hdmi_choose_cvt(codec, pin_idx, NULL, &mux_idx);
-			if (err < 0)
-				return;
-			snd_printdd("HDMI: choose converter %d for pin %d\n", mux_idx, pin_idx);
-			snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
+			/* Must not already be assigned */
+			if (!per_cvt->assigned) {
+				snd_printdd("choose converter %d for pin %d\n",
+					cvt_idx, pin_idx);
+				snd_hda_codec_write_cache(codec, pin_nid, 0,
 					    AC_VERB_SET_CONNECT_SEL,
-					    mux_idx);
+					    cvt_idx);
+				break;
+			}
 		}
 	}
 }
Signature · 2 lines
David Henningsson, Canonical Ltd.
https://launchpad.net/~diwic
#2 lore raw

Hi David,

Sorry, I missed your mail. Please see comments below ...

Quoted 31 lines

-----Original Message-----
From: David Henningsson [mailto:[email protected]]
Sent: Tuesday, September 17, 2013 6:40 AM

sound/pci/hda/patch_hdmi.c static void haswell_config_cvts(struct

Quoted 5 lines
sound/pci/hda/patch_hdmi.c +0 -0
index 3d8cd044..4960695 100644
@@ -1152,29 +1152,34 @@ static void haswell_config_cvts(struct

hda_codec *codec,

Quoted 6 lines
sound/pci/hda/patch_hdmi.c +1 -2
 			int pin_id, int mux_id)
 {
 	struct hdmi_spec *spec = codec->spec;
-	struct hdmi_spec_per_pin *per_pin;
-	int pin_idx, mux_idx;
+	hda_nid_t  pin_nid;

sound/pci/hda/patch_hdmi.c static void haswell_config_cvts(struct hda_codec *codec, · line 1161

Quoted 10 lines
sound/pci/hda/patch_hdmi.c +4 -4
+	int pin_idx, cvt_idx;
 	int curr;
-	int err;
-
-	for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
-		per_pin = get_pin(spec, pin_idx);
+	struct hdmi_spec_per_cvt *per_cvt;
 
+	/* configure all 3 pins, including "no physical connection" ones */
+	for (pin_nid = 5; pin_nid < 8; pin_nid++) {

It might not be so future proof to hard code nid IDs here (even if it should be safe right now?). Perhaps more elegant to go through the entire codec->nids array like being done here:

Quoted 3 lines

http://lxr.linux.no/linux+*/sound/pci/hda/hda_auto_parser.c#L188

The nid's wcaps is cached so it does not mean additional reads from the codec.

Xingchao defined haswell_config_cvts() to configure converters on codec->pins before.
But codec->pins does not include the pins programmed by BIOS as "No physical connections" (like port B in the OEM machine). So I change the code from using codec->pins to hard coded NIDs. It's not graceful and the NIDs may change in the future.

There is another option to change add_pin() to not overlook such "no connection" pins for Haswell. But there would be a side effect: the 1st pin can be "no connection" and then the following function will be affected:
- simple_playback_build_pcms()
- simple_playback_init()
Both of them assume the 1st pin is valid and use get_pin(spec, 0) to operates on the 1st pin.
And in addition, I don't want more PCM and controls to be created on the "No connection" pins.
So finally I gave up to change add_pin() but just modify haswell_config_cvts().

Thanks
Mengdong

#3 lore raw
Quoted 37 lines · Mengdong

Hi David,

Sorry, I missed your mail. Please see comments below ...

Quoted 33 lines

-----Original Message-----
From: David Henningsson [mailto:[email protected]]
Sent: Tuesday, September 17, 2013 6:40 AM

sound/pci/hda/patch_hdmi.c static void haswell_config_cvts(struct

Quoted 5 lines
sound/pci/hda/patch_hdmi.c +0 -0
index 3d8cd044..4960695 100644
@@ -1152,29 +1152,34 @@ static void haswell_config_cvts(struct

hda_codec *codec,

Quoted 6 lines
sound/pci/hda/patch_hdmi.c +1 -2
 			int pin_id, int mux_id)
 {
 	struct hdmi_spec *spec = codec->spec;
-	struct hdmi_spec_per_pin *per_pin;
-	int pin_idx, mux_idx;
+	hda_nid_t  pin_nid;

sound/pci/hda/patch_hdmi.c static void haswell_config_cvts(struct hda_codec *codec, · line 1161

Quoted 10 lines
sound/pci/hda/patch_hdmi.c +4 -4
+	int pin_idx, cvt_idx;
 	int curr;
-	int err;
-
-	for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
-		per_pin = get_pin(spec, pin_idx);
+	struct hdmi_spec_per_cvt *per_cvt;
 
+	/* configure all 3 pins, including "no physical connection" ones */
+	for (pin_nid = 5; pin_nid < 8; pin_nid++) {

It might not be so future proof to hard code nid IDs here (even if it should be safe right now?). Perhaps more elegant to go through the entire codec->nids array like being done here:

http://lxr.linux.no/linux+*/sound/pci/hda/hda_auto_parser.c#L188

Quoted 7 lines
Quoted 1 line

The nid's wcaps is cached so it does not mean additional reads from the codec.

Xingchao defined haswell_config_cvts() to configure converters on codec->pins before.
But codec->pins does not include the pins programmed by BIOS as "No physical connections" (like port B in the OEM machine). So I change the code from using codec->pins to hard coded NIDs. It's not graceful and the NIDs may change in the future.

There is another option to change add_pin() to not overlook such "no connection" pins for Haswell.

I was suggesting to do something like this in haswell_config_cvts:

	int end_nid = codec->start_nid + codec->num_nodes;
	for (nid = codec->start_nid; nid < end_nid; nid++) {
		unsigned int wid_caps = get_wcaps(codec, nid);
		if (get_wcaps_type(wid_caps) != AC_WID_PIN)
			continue;
                /* etc */
Signature · 2 lines
David Henningsson, Canonical Ltd.
https://launchpad.net/~diwic
#4 lore raw
Quoted 59 lines

-----Original Message-----
From: David Henningsson [mailto:[email protected]]
Sent: Friday, September 20, 2013 5:32 PM
To: Lin, Mengdong
Cc: [email protected]; [email protected]
Subject: Re: [alsa-devel] [RFC PATCH] ALSA : hda - not use assigned converters for all unused pins

Quoted 38 lines · Mengdong

Hi David,

Sorry, I missed your mail. Please see comments below ...

Quoted 34 lines

-----Original Message-----
From: David Henningsson [mailto:[email protected]]
Sent: Tuesday, September 17, 2013 6:40 AM

sound/pci/hda/patch_hdmi.c static void haswell_config_cvts(struct

Quoted 5 lines
sound/pci/hda/patch_hdmi.c +0 -0
index 3d8cd044..4960695 100644
@@ -1152,29 +1152,34 @@ static void haswell_config_cvts(struct

hda_codec *codec,

Quoted 6 lines
sound/pci/hda/patch_hdmi.c +1 -2
 			int pin_id, int mux_id)
 {
 	struct hdmi_spec *spec = codec->spec;
-	struct hdmi_spec_per_pin *per_pin;
-	int pin_idx, mux_idx;
+	hda_nid_t  pin_nid;

sound/pci/hda/patch_hdmi.c static void haswell_config_cvts(struct hda_codec *codec, · line 1161

Quoted 10 lines
sound/pci/hda/patch_hdmi.c +4 -4
+	int pin_idx, cvt_idx;
 	int curr;
-	int err;
-
-	for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
-		per_pin = get_pin(spec, pin_idx);
+	struct hdmi_spec_per_cvt *per_cvt;
 
+	/* configure all 3 pins, including "no physical connection" ones */
+	for (pin_nid = 5; pin_nid < 8; pin_nid++) {

It might not be so future proof to hard code nid IDs here (even if it should be safe right now?). Perhaps more elegant to go through the entire codec->nids array like being done here:

http://lxr.linux.no/linux+*/sound/pci/hda/hda_auto_parser.c#L188

The nid's wcaps is cached so it does not mean additional reads from the

codec.

Quoted 2 lines

Xingchao defined haswell_config_cvts() to configure converters on

codec->pins before.

Quoted 1 line

But codec->pins does not include the pins programmed by BIOS as "No

physical connections" (like port B in the OEM machine).

Quoted 1 line

So I change the code from using codec->pins to hard coded NIDs. It's not

graceful and the NIDs may change in the future.

Quoted 2 lines

There is another option to change add_pin() to not overlook such "no

connection" pins for Haswell.

Quoted 10 lines

I was suggesting to do something like this in haswell_config_cvts:

	int end_nid = codec->start_nid + codec->num_nodes;
	for (nid = codec->start_nid; nid < end_nid; nid++) {
		unsigned int wid_caps = get_wcaps(codec, nid);
		if (get_wcaps_type(wid_caps) != AC_WID_PIN)
			continue;
                /* etc */

Yes, this's elegant. I misunderstood your point in the afternoon. I'll revise the patch as you suggested on Sunday, now out of office on holiday.

Thanks
Mengdong