Skip to contentSkip to conversation

ALSA: hda: Conexant: Allow different output types to share DAC

PATCH In review David Henningsson 2 participants 5 messages Aug 25, 2011 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: hda: Conexant: Allow different output types to share DAC

[PATCH] ALSA: hda: Conexant: Allow different output types to share DAC

Headphones has stopped working for the original reported (a regression compared to 2.6.38). This is because Speaker and Headphones share the same DAC, in which case no Headphones volume control was created. This patch fixes so that both Speaker and Headphones volume controls are created in such scenario.

Link to codec-proc: https://launchpadlibrarian.net/76215662/Card0.Codecs.codec.0.txt

Signature · 2 lines
David Henningsson, Canonical Ltd.
http://launchpad.net/~diwic
Quoted 1 line

From 95ca8a0cd32ad781c54a349c5ce84a9119668f9c Mon Sep 17 00:00:00 2001

From: David Henningsson <[email protected]>
Date: Thu, 25 Aug 2011 13:16:02 +0200
Subject: [PATCH] ALSA: hda: Conexant: Allow different output types to share DAC

Headphones has stopped working for the original reported (a regression compared to 2.6.38). This is because Speaker and Headphones share the same DAC, in which case no Headphones volume control was created. This patch fixes so that both Speaker and Headphones volume controls are created in such scenario.

---
 sound/pci/hda/patch_conexant.c |   40 ++++++++++++++++++++++------------------
 1 files changed, 22 insertions(+), 18 deletions(-)
sound/pci/hda/patch_conexant.c +22 -18
index 197ad93..a29b88d 100644
@@ -3327,22 +3327,23 @@ static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
 }
 
 /* fill pin_dac_pair list from the pin and dac list */
-static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
+static void fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
 			      int num_pins, hda_nid_t *dacs, int *rest,
-			      struct pin_dac_pair *filled, int type)
+			      struct pin_dac_pair *filled, int *saved_nums, 
+			      int type)
 {
 	int i, nums;
 
-	nums = 0;
+	nums = *saved_nums;
 	for (i = 0; i < num_pins; i++) {
 		filled[nums].pin = pins[i];
 		filled[nums].type = type;
 		filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
-		if (!filled[nums].dac && i > 0 && filled[0].dac)
+		if (!filled[nums].dac && filled[0].dac)
 			filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
 		nums++;
 	}
-	return nums;
+	*saved_nums = nums;
 }
 
 /* parse analog output paths */
@@ -3355,15 +3356,16 @@ static void cx_auto_parse_output(struct hda_codec *codec)
 
 	rest = fill_cx_auto_dacs(codec, dacs);
 	/* parse all analog output pins */
-	nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
-				  dacs, &rest, spec->dac_info,
-				  AUTO_PIN_LINE_OUT);
-	nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
-				  dacs, &rest, spec->dac_info + nums,
-				  AUTO_PIN_HP_OUT);
-	nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
-				  dacs, &rest, spec->dac_info + nums,
-				  AUTO_PIN_SPEAKER_OUT);
+	nums = 0;
+	fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
+			  dacs, &rest, spec->dac_info, &nums,
+			  AUTO_PIN_LINE_OUT);
+	fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
+			  dacs, &rest, spec->dac_info, &nums,
+			  AUTO_PIN_HP_OUT);
+	fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
+			  dacs, &rest, spec->dac_info, &nums,
+			  AUTO_PIN_SPEAKER_OUT);
 	spec->dac_info_filled = nums;
 	/* fill multiout struct */
 	for (i = 0; i < nums; i++) {
@@ -4130,9 +4132,11 @@ static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
 			     hda_nid_t pin, const char *name, int idx)
 {
 	unsigned int caps;
-	caps = query_amp_caps(codec, dac, HDA_OUTPUT);
-	if (caps & AC_AMPCAP_NUM_STEPS)
-		return cx_auto_add_pb_volume(codec, dac, name, idx);
+	if (!(dac & DAC_SLAVE_FLAG)) {
+		caps = query_amp_caps(codec, dac, HDA_OUTPUT);
+		if (caps & AC_AMPCAP_NUM_STEPS)
+			return cx_auto_add_pb_volume(codec, dac, name, idx);
+	}
 	caps = query_amp_caps(codec, pin, HDA_OUTPUT);
 	if (caps & AC_AMPCAP_NUM_STEPS)
 		return cx_auto_add_pb_volume(codec, pin, name, idx);
@@ -4155,7 +4159,7 @@ static int cx_auto_build_output_controls(struct hda_codec *codec)
 		const char *label;
 		int idx, type;
 		hda_nid_t dac = spec->dac_info[i].dac;
-		if (!dac || (dac & DAC_SLAVE_FLAG))
+		if (!dac)
 			continue;
 		type = spec->dac_info[i].type;
 		if (type == AUTO_PIN_LINE_OUT)
Signature · 1 line
1.7.4.1
#1 lore raw

At Thu, 25 Aug 2011 13:26:26 +0200,

Quoted 34 lines · David Henningsson
Quoted 2 lines

From 95ca8a0cd32ad781c54a349c5ce84a9119668f9c Mon Sep 17 00:00:00 2001

From: David Henningsson <[email protected]>
Date: Thu, 25 Aug 2011 13:16:02 +0200
Subject: [PATCH] ALSA: hda: Conexant: Allow different output types to share DAC

Headphones has stopped working for the original reported (a regression compared to 2.6.38). This is because Speaker and Headphones share the same DAC, in which case no Headphones volume control was created. This patch fixes so that both Speaker and Headphones volume controls are created in such scenario.

---
 sound/pci/hda/patch_conexant.c |   40 ++++++++++++++++++++++------------------
 1 files changed, 22 insertions(+), 18 deletions(-)
sound/pci/hda/patch_conexant.c +3 -2
index 197ad93..a29b88d 100644
@@ -3327,22 +3327,23 @@ static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
 }
 
 /* fill pin_dac_pair list from the pin and dac list */
-static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
+static void fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
 			      int num_pins, hda_nid_t *dacs, int *rest,
-			      struct pin_dac_pair *filled, int type)
+			      struct pin_dac_pair *filled, int *saved_nums, 
+			      int type)
 {
 	int i, nums;

sound/pci/hda/patch_conexant.c static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs) · line 3343

Quoted 10 lines
sound/pci/hda/patch_conexant.c +2 -2
 
-	nums = 0;
+	nums = *saved_nums;
 	for (i = 0; i < num_pins; i++) {
 		filled[nums].pin = pins[i];
 		filled[nums].type = type;
 		filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
-		if (!filled[nums].dac && i > 0 && filled[0].dac)
+		if (!filled[nums].dac && filled[0].dac)
 			filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;

It should try the first DAC of the same type at first, not always to filled[0].

Quoted 49 lines
sound/pci/hda/patch_conexant.c +16 -13
 		nums++;
 	}
-	return nums;
+	*saved_nums = nums;
 }
 
 /* parse analog output paths */
@@ -3355,15 +3356,16 @@ static void cx_auto_parse_output(struct hda_codec *codec)
 
 	rest = fill_cx_auto_dacs(codec, dacs);
 	/* parse all analog output pins */
-	nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
-				  dacs, &rest, spec->dac_info,
-				  AUTO_PIN_LINE_OUT);
-	nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
-				  dacs, &rest, spec->dac_info + nums,
-				  AUTO_PIN_HP_OUT);
-	nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
-				  dacs, &rest, spec->dac_info + nums,
-				  AUTO_PIN_SPEAKER_OUT);
+	nums = 0;
+	fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
+			  dacs, &rest, spec->dac_info, &nums,
+			  AUTO_PIN_LINE_OUT);
+	fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
+			  dacs, &rest, spec->dac_info, &nums,
+			  AUTO_PIN_HP_OUT);
+	fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
+			  dacs, &rest, spec->dac_info, &nums,
+			  AUTO_PIN_SPEAKER_OUT);
 	spec->dac_info_filled = nums;
 	/* fill multiout struct */
 	for (i = 0; i < nums; i++) {
@@ -4130,9 +4132,11 @@ static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
 			     hda_nid_t pin, const char *name, int idx)
 {
 	unsigned int caps;
-	caps = query_amp_caps(codec, dac, HDA_OUTPUT);
-	if (caps & AC_AMPCAP_NUM_STEPS)
-		return cx_auto_add_pb_volume(codec, dac, name, idx);
+	if (!(dac & DAC_SLAVE_FLAG)) {
+		caps = query_amp_caps(codec, dac, HDA_OUTPUT);
+		if (caps & AC_AMPCAP_NUM_STEPS)
+			return cx_auto_add_pb_volume(codec, dac, name, idx);
+	}
 	caps = query_amp_caps(codec, pin, HDA_OUTPUT);
 	if (caps & AC_AMPCAP_NUM_STEPS)
 		return cx_auto_add_pb_volume(codec, pin, name, idx);

sound/pci/hda/patch_conexant.c static int cx_auto_build_output_controls(struct hda_codec *codec) · line 4163

Quoted 6 lines
sound/pci/hda/patch_conexant.c +1 -1
@@ -4155,7 +4159,7 @@ static int cx_auto_build_output_controls(struct hda_codec *codec)
 		const char *label;
 		int idx, type;
 		hda_nid_t dac = spec->dac_info[i].dac;
-		if (!dac || (dac & DAC_SLAVE_FLAG))
+		if (!dac)
 			continue;

With the fix like the above, the whole NULL-dac check should be skipped, too.

How about the revised patch below?

thanks,

Takashi

---

sound/pci/hda/patch_conexant.c +20 -15
index 5616444..8ac5134 100644
@@ -3372,17 +3372,21 @@ static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
 /* fill pin_dac_pair list from the pin and dac list */
 static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
 			      int num_pins, hda_nid_t *dacs, int *rest,
-			      struct pin_dac_pair *filled, int type)
+			      struct pin_dac_pair *filled, int nums,
+			      int type)
 {
-	int i, nums;
+	int i, start = nums;
 
-	nums = 0;
 	for (i = 0; i < num_pins; i++) {
 		filled[nums].pin = pins[i];
 		filled[nums].type = type;
 		filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
-		if (!filled[nums].dac && i > 0 && filled[0].dac)
-			filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
+		if (!filled[nums].dac) {
+			if (i > 0 && filled[start].dac)
+				filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG;
+			else if (filled[0].dac)
+				filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
+		}
 		nums++;
 	}
 	return nums;
@@ -3398,14 +3402,15 @@ static void cx_auto_parse_output(struct hda_codec *codec)
 
 	rest = fill_cx_auto_dacs(codec, dacs);
 	/* parse all analog output pins */
+	nums = 0;
 	nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
-				  dacs, &rest, spec->dac_info,
+				  dacs, &rest, spec->dac_info, nums,
 				  AUTO_PIN_LINE_OUT);
-	nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
-				  dacs, &rest, spec->dac_info + nums,
+	nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
+				  dacs, &rest, spec->dac_info, nums,
 				  AUTO_PIN_HP_OUT);
-	nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
-				  dacs, &rest, spec->dac_info + nums,
+	nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
+				  dacs, &rest, spec->dac_info, nums,
 				  AUTO_PIN_SPEAKER_OUT);
 	spec->dac_info_filled = nums;
 	/* fill multiout struct */
@@ -4173,9 +4178,11 @@ static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
 			     hda_nid_t pin, const char *name, int idx)
 {
 	unsigned int caps;
-	caps = query_amp_caps(codec, dac, HDA_OUTPUT);
-	if (caps & AC_AMPCAP_NUM_STEPS)
-		return cx_auto_add_pb_volume(codec, dac, name, idx);
+	if (dac && !(dac & DAC_SLAVE_FLAG)) {
+		caps = query_amp_caps(codec, dac, HDA_OUTPUT);
+		if (caps & AC_AMPCAP_NUM_STEPS)
+			return cx_auto_add_pb_volume(codec, dac, name, idx);
+	}
 	caps = query_amp_caps(codec, pin, HDA_OUTPUT);
 	if (caps & AC_AMPCAP_NUM_STEPS)
 		return cx_auto_add_pb_volume(codec, pin, name, idx);
@@ -4198,8 +4205,6 @@ static int cx_auto_build_output_controls(struct hda_codec *codec)
 		const char *label;
 		int idx, type;
 		hda_nid_t dac = spec->dac_info[i].dac;
-		if (!dac || (dac & DAC_SLAVE_FLAG))
-			continue;
 		type = spec->dac_info[i].type;
 		if (type == AUTO_PIN_LINE_OUT)
 			type = spec->autocfg.line_out_type;
#2 lore raw

At Thu, 25 Aug 2011 14:03:24 +0200,

Quoted 111 lines · Takashi Iwai

At Thu, 25 Aug 2011 13:26:26 +0200,

Quoted 34 lines · David Henningsson
Quoted 2 lines

From 95ca8a0cd32ad781c54a349c5ce84a9119668f9c Mon Sep 17 00:00:00 2001

From: David Henningsson <[email protected]>
Date: Thu, 25 Aug 2011 13:16:02 +0200
Subject: [PATCH] ALSA: hda: Conexant: Allow different output types to share DAC

Headphones has stopped working for the original reported (a regression compared to 2.6.38). This is because Speaker and Headphones share the same DAC, in which case no Headphones volume control was created. This patch fixes so that both Speaker and Headphones volume controls are created in such scenario.

---
 sound/pci/hda/patch_conexant.c |   40 ++++++++++++++++++++++------------------
 1 files changed, 22 insertions(+), 18 deletions(-)
sound/pci/hda/patch_conexant.c +3 -2
index 197ad93..a29b88d 100644
@@ -3327,22 +3327,23 @@ static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
 }
 
 /* fill pin_dac_pair list from the pin and dac list */
-static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
+static void fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
 			      int num_pins, hda_nid_t *dacs, int *rest,
-			      struct pin_dac_pair *filled, int type)
+			      struct pin_dac_pair *filled, int *saved_nums, 
+			      int type)
 {
 	int i, nums;

sound/pci/hda/patch_conexant.c static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs) · line 3343

Quoted 10 lines
sound/pci/hda/patch_conexant.c +2 -2
 
-	nums = 0;
+	nums = *saved_nums;
 	for (i = 0; i < num_pins; i++) {
 		filled[nums].pin = pins[i];
 		filled[nums].type = type;
 		filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
-		if (!filled[nums].dac && i > 0 && filled[0].dac)
+		if (!filled[nums].dac && filled[0].dac)
 			filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;

It should try the first DAC of the same type at first, not always to filled[0].

Quoted 49 lines
sound/pci/hda/patch_conexant.c +16 -13
 		nums++;
 	}
-	return nums;
+	*saved_nums = nums;
 }
 
 /* parse analog output paths */
@@ -3355,15 +3356,16 @@ static void cx_auto_parse_output(struct hda_codec *codec)
 
 	rest = fill_cx_auto_dacs(codec, dacs);
 	/* parse all analog output pins */
-	nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
-				  dacs, &rest, spec->dac_info,
-				  AUTO_PIN_LINE_OUT);
-	nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
-				  dacs, &rest, spec->dac_info + nums,
-				  AUTO_PIN_HP_OUT);
-	nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
-				  dacs, &rest, spec->dac_info + nums,
-				  AUTO_PIN_SPEAKER_OUT);
+	nums = 0;
+	fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
+			  dacs, &rest, spec->dac_info, &nums,
+			  AUTO_PIN_LINE_OUT);
+	fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
+			  dacs, &rest, spec->dac_info, &nums,
+			  AUTO_PIN_HP_OUT);
+	fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
+			  dacs, &rest, spec->dac_info, &nums,
+			  AUTO_PIN_SPEAKER_OUT);
 	spec->dac_info_filled = nums;
 	/* fill multiout struct */
 	for (i = 0; i < nums; i++) {
@@ -4130,9 +4132,11 @@ static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
 			     hda_nid_t pin, const char *name, int idx)
 {
 	unsigned int caps;
-	caps = query_amp_caps(codec, dac, HDA_OUTPUT);
-	if (caps & AC_AMPCAP_NUM_STEPS)
-		return cx_auto_add_pb_volume(codec, dac, name, idx);
+	if (!(dac & DAC_SLAVE_FLAG)) {
+		caps = query_amp_caps(codec, dac, HDA_OUTPUT);
+		if (caps & AC_AMPCAP_NUM_STEPS)
+			return cx_auto_add_pb_volume(codec, dac, name, idx);
+	}
 	caps = query_amp_caps(codec, pin, HDA_OUTPUT);
 	if (caps & AC_AMPCAP_NUM_STEPS)
 		return cx_auto_add_pb_volume(codec, pin, name, idx);

sound/pci/hda/patch_conexant.c static int cx_auto_build_output_controls(struct hda_codec *codec) · line 4163

Quoted 6 lines
sound/pci/hda/patch_conexant.c +1 -1
@@ -4155,7 +4159,7 @@ static int cx_auto_build_output_controls(struct hda_codec *codec)
 		const char *label;
 		int idx, type;
 		hda_nid_t dac = spec->dac_info[i].dac;
-		if (!dac || (dac & DAC_SLAVE_FLAG))
+		if (!dac)
 			continue;

With the fix like the above, the whole NULL-dac check should be skipped, too.

Quoted 1 line

How about the revised patch below?

We should also check the connectivity to the tested DAC. Please check this revised version.

thanks,

Takashi

---

sound/pci/hda/patch_conexant.c +29 -15
index 5616444..e5b06dd 100644
@@ -3369,20 +3369,33 @@ static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
 	return nums;
 }
 
+/* if the pin has a connection with the given DAC, return it as a slave DAC */
+static hda_nid_t get_slave_dac(struct hda_codec *codec, hda_nid_t pin,
+			       hda_nid_t dac)
+{
+	if (get_connection_index(codec, pin, dac) >= 0)
+		return dac | DAC_SLAVE_FLAG;
+	return 0;
+}
+
 /* fill pin_dac_pair list from the pin and dac list */
 static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
 			      int num_pins, hda_nid_t *dacs, int *rest,
-			      struct pin_dac_pair *filled, int type)
+			      struct pin_dac_pair *filled, int nums,
+			      int type)
 {
-	int i, nums;
+	int i, start = nums;
 
-	nums = 0;
 	for (i = 0; i < num_pins; i++) {
 		filled[nums].pin = pins[i];
 		filled[nums].type = type;
 		filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
-		if (!filled[nums].dac && i > 0 && filled[0].dac)
-			filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
+		if (!filled[nums].dac && i > 0 && filled[start].dac)
+			filled[nums].dac = get_slave_dac(codec, pins[i],
+							 filled[start].dac);
+		if (!filled[nums].dac && filled[0].dac)
+			filled[nums].dac = get_slave_dac(codec, pins[i],
+							 filled[0].dac);
 		nums++;
 	}
 	return nums;
@@ -3398,14 +3411,15 @@ static void cx_auto_parse_output(struct hda_codec *codec)
 
 	rest = fill_cx_auto_dacs(codec, dacs);
 	/* parse all analog output pins */
+	nums = 0;
 	nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
-				  dacs, &rest, spec->dac_info,
+				  dacs, &rest, spec->dac_info, nums,
 				  AUTO_PIN_LINE_OUT);
-	nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
-				  dacs, &rest, spec->dac_info + nums,
+	nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
+				  dacs, &rest, spec->dac_info, nums,
 				  AUTO_PIN_HP_OUT);
-	nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
-				  dacs, &rest, spec->dac_info + nums,
+	nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
+				  dacs, &rest, spec->dac_info, nums,
 				  AUTO_PIN_SPEAKER_OUT);
 	spec->dac_info_filled = nums;
 	/* fill multiout struct */
@@ -4173,9 +4187,11 @@ static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
 			     hda_nid_t pin, const char *name, int idx)
 {
 	unsigned int caps;
-	caps = query_amp_caps(codec, dac, HDA_OUTPUT);
-	if (caps & AC_AMPCAP_NUM_STEPS)
-		return cx_auto_add_pb_volume(codec, dac, name, idx);
+	if (dac && !(dac & DAC_SLAVE_FLAG)) {
+		caps = query_amp_caps(codec, dac, HDA_OUTPUT);
+		if (caps & AC_AMPCAP_NUM_STEPS)
+			return cx_auto_add_pb_volume(codec, dac, name, idx);
+	}
 	caps = query_amp_caps(codec, pin, HDA_OUTPUT);
 	if (caps & AC_AMPCAP_NUM_STEPS)
 		return cx_auto_add_pb_volume(codec, pin, name, idx);
@@ -4198,8 +4214,6 @@ static int cx_auto_build_output_controls(struct hda_codec *codec)
 		const char *label;
 		int idx, type;
 		hda_nid_t dac = spec->dac_info[i].dac;
-		if (!dac || (dac & DAC_SLAVE_FLAG))
-			continue;
 		type = spec->dac_info[i].type;
 		if (type == AUTO_PIN_LINE_OUT)
 			type = spec->autocfg.line_out_type;
#3 lore raw
In reply to Takashi Iwai
Quoted 37 lines · Takashi Iwai

At Thu, 25 Aug 2011 13:26:26 +0200,

Quoted 35 lines · David Henningsson
Quoted 2 lines

From 95ca8a0cd32ad781c54a349c5ce84a9119668f9c Mon Sep 17 00:00:00 2001

From: David Henningsson<[email protected]>
Date: Thu, 25 Aug 2011 13:16:02 +0200
Subject: [PATCH] ALSA: hda: Conexant: Allow different output types to share DAC

Headphones has stopped working for the original reported (a regression compared to 2.6.38). This is because Speaker and Headphones share the same DAC, in which case no Headphones volume control was created. This patch fixes so that both Speaker and Headphones volume controls are created in such scenario.

---
  sound/pci/hda/patch_conexant.c |   40 ++++++++++++++++++++++------------------
  1 files changed, 22 insertions(+), 18 deletions(-)
sound/pci/hda/patch_conexant.c +3 -2
index 197ad93..a29b88d 100644
@@ -3327,22 +3327,23 @@ static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
  }
 
  /* fill pin_dac_pair list from the pin and dac list */
-static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
+static void fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
  			      int num_pins, hda_nid_t *dacs, int *rest,
-			      struct pin_dac_pair *filled, int type)
+			      struct pin_dac_pair *filled, int *saved_nums,
+			      int type)
  {
  	int i, nums;
 
Quoted 12 lines

sound/pci/hda/patch_conexant.c static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs) · line 3343

Quoted 9 lines
sound/pci/hda/patch_conexant.c +2 -2
-	nums = 0;
+	nums = *saved_nums;
  	for (i = 0; i<  num_pins; i++) {
  		filled[nums].pin = pins[i];
  		filled[nums].type = type;
  		filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
-		if (!filled[nums].dac&&  i>  0&&  filled[0].dac)
+		if (!filled[nums].dac&&  filled[0].dac)
  			filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;

It should try the first DAC of the same type at first, not always to filled[0].

Ok, fair point. I'm attaching a revised patch that also checks that the DAC is actually reachable, which should be even better.

Quoted 10 lines

sound/pci/hda/patch_conexant.c static int cx_auto_build_output_controls(struct hda_codec *codec) · line 4163

Quoted 7 lines
sound/pci/hda/patch_conexant.c +1 -1
@@ -4155,7 +4159,7 @@ static int cx_auto_build_output_controls(struct hda_codec *codec)
  		const char *label;
  		int idx, type;
  		hda_nid_t dac = spec->dac_info[i].dac;
-		if (!dac || (dac&  DAC_SLAVE_FLAG))
+		if (!dac)
  			continue;

With the fix like the above, the whole NULL-dac check should be skipped, too.

Since NULL-dac is essentially an error, this is more a matter of taste IMO.

Quoted 1 line

How about the revised patch below?

Took some of it into the attached version of the patch.

Signature · 2 lines
David Henningsson, Canonical Ltd.
http://launchpad.net/~diwic
Quoted 1 line

From 1947cd5075a43edb1901c3fc9e97ba77d4c7cca9 Mon Sep 17 00:00:00 2001

From: David Henningsson <[email protected]>
Date: Thu, 25 Aug 2011 13:16:02 +0200
Subject: [PATCH] ALSA: hda: Conexant: Allow different output types to share DAC

Headphones has stopped working for the original reported (a regression compared to 2.6.38). This is because Speaker and Headphones share the same DAC, in which case no Headphones volume control was created. This patch fixes so that both Speaker and Headphones volume controls are created in such scenario.

---
 sound/pci/hda/patch_conexant.c |   46 +++++++++++++++++++++++----------------
 1 files changed, 27 insertions(+), 19 deletions(-)
sound/pci/hda/patch_conexant.c +27 -19
index 197ad93..aa0e4b9 100644
@@ -3329,18 +3329,26 @@ static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
 /* fill pin_dac_pair list from the pin and dac list */
 static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
 			      int num_pins, hda_nid_t *dacs, int *rest,
-			      struct pin_dac_pair *filled, int type)
+			      struct pin_dac_pair *filled, int nums, 
+			      int type)
 {
-	int i, nums;
+	int i, start = nums;
 
-	nums = 0;
-	for (i = 0; i < num_pins; i++) {
+	for (i = 0; i < num_pins; i++, nums++) {
 		filled[nums].pin = pins[i];
 		filled[nums].type = type;
 		filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
-		if (!filled[nums].dac && i > 0 && filled[0].dac)
+		if (filled[nums].dac) 
+			continue;
+		if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) {
+			filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG;
+			continue;
+		}
+		if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) {
 			filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
-		nums++;
+			continue;
+		}
+		snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]);
 	}
 	return nums;
 }
@@ -3356,14 +3364,14 @@ static void cx_auto_parse_output(struct hda_codec *codec)
 	rest = fill_cx_auto_dacs(codec, dacs);
 	/* parse all analog output pins */
 	nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
-				  dacs, &rest, spec->dac_info,
-				  AUTO_PIN_LINE_OUT);
-	nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
-				  dacs, &rest, spec->dac_info + nums,
-				  AUTO_PIN_HP_OUT);
-	nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
-				  dacs, &rest, spec->dac_info + nums,
-				  AUTO_PIN_SPEAKER_OUT);
+			  dacs, &rest, spec->dac_info, 0,
+			  AUTO_PIN_LINE_OUT);
+	nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
+			  dacs, &rest, spec->dac_info, nums,
+			  AUTO_PIN_HP_OUT);
+	nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
+			  dacs, &rest, spec->dac_info, nums,
+			  AUTO_PIN_SPEAKER_OUT);
 	spec->dac_info_filled = nums;
 	/* fill multiout struct */
 	for (i = 0; i < nums; i++) {
@@ -4130,9 +4138,11 @@ static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
 			     hda_nid_t pin, const char *name, int idx)
 {
 	unsigned int caps;
-	caps = query_amp_caps(codec, dac, HDA_OUTPUT);
-	if (caps & AC_AMPCAP_NUM_STEPS)
-		return cx_auto_add_pb_volume(codec, dac, name, idx);
+	if (dac && !(dac & DAC_SLAVE_FLAG)) {
+		caps = query_amp_caps(codec, dac, HDA_OUTPUT);
+		if (caps & AC_AMPCAP_NUM_STEPS)
+			return cx_auto_add_pb_volume(codec, dac, name, idx);
+	}
 	caps = query_amp_caps(codec, pin, HDA_OUTPUT);
 	if (caps & AC_AMPCAP_NUM_STEPS)
 		return cx_auto_add_pb_volume(codec, pin, name, idx);
@@ -4155,8 +4165,6 @@ static int cx_auto_build_output_controls(struct hda_codec *codec)
 		const char *label;
 		int idx, type;
 		hda_nid_t dac = spec->dac_info[i].dac;
-		if (!dac || (dac & DAC_SLAVE_FLAG))
-			continue;
 		type = spec->dac_info[i].type;
 		if (type == AUTO_PIN_LINE_OUT)
 			type = spec->autocfg.line_out_type;
Signature · 1 line
1.7.4.1
#4 lore raw

At Thu, 25 Aug 2011 15:01:32 +0200,

Quoted 52 lines · David Henningsson
Quoted 37 lines · Takashi Iwai

At Thu, 25 Aug 2011 13:26:26 +0200,

Quoted 35 lines · David Henningsson
Quoted 2 lines

From 95ca8a0cd32ad781c54a349c5ce84a9119668f9c Mon Sep 17 00:00:00 2001

From: David Henningsson<[email protected]>
Date: Thu, 25 Aug 2011 13:16:02 +0200
Subject: [PATCH] ALSA: hda: Conexant: Allow different output types to share DAC

Headphones has stopped working for the original reported (a regression compared to 2.6.38). This is because Speaker and Headphones share the same DAC, in which case no Headphones volume control was created. This patch fixes so that both Speaker and Headphones volume controls are created in such scenario.

---
  sound/pci/hda/patch_conexant.c |   40 ++++++++++++++++++++++------------------
  1 files changed, 22 insertions(+), 18 deletions(-)
sound/pci/hda/patch_conexant.c +3 -2
index 197ad93..a29b88d 100644
@@ -3327,22 +3327,23 @@ static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
  }
 
  /* fill pin_dac_pair list from the pin and dac list */
-static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
+static void fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
  			      int num_pins, hda_nid_t *dacs, int *rest,
-			      struct pin_dac_pair *filled, int type)
+			      struct pin_dac_pair *filled, int *saved_nums,
+			      int type)
  {
  	int i, nums;
 
Quoted 12 lines

sound/pci/hda/patch_conexant.c static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs) · line 3348

Quoted 9 lines
sound/pci/hda/patch_conexant.c +2 -2
-	nums = 0;
+	nums = *saved_nums;
  	for (i = 0; i<  num_pins; i++) {
  		filled[nums].pin = pins[i];
  		filled[nums].type = type;
  		filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
-		if (!filled[nums].dac&&  i>  0&&  filled[0].dac)
+		if (!filled[nums].dac&&  filled[0].dac)
  			filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;

It should try the first DAC of the same type at first, not always to filled[0].

Quoted 2 lines

Ok, fair point. I'm attaching a revised patch that also checks that the DAC is actually reachable, which should be even better.

Heh, I also changed it a few minutes ago.

Quoted 11 lines
Quoted 10 lines

sound/pci/hda/patch_conexant.c static int cx_auto_build_output_controls(struct hda_codec *codec) · line 4163

Quoted 7 lines
sound/pci/hda/patch_conexant.c +1 -1
@@ -4155,7 +4159,7 @@ static int cx_auto_build_output_controls(struct hda_codec *codec)
  		const char *label;
  		int idx, type;
  		hda_nid_t dac = spec->dac_info[i].dac;
-		if (!dac || (dac&  DAC_SLAVE_FLAG))
+		if (!dac)
  			continue;

With the fix like the above, the whole NULL-dac check should be skipped, too.

Quoted 1 line

Since NULL-dac is essentially an error, this is more a matter of taste IMO.

Yeah, but we can simplify to a single check :)

Quoted 3 lines
Quoted 1 line

How about the revised patch below?

Took some of it into the attached version of the patch.

OK, I'm going to apply it.

thanks,

Takashi